++Performance;
This commit is contained in:
parent
16a67035d0
commit
5c30cdf26d
@ -7,24 +7,33 @@ Chunk::Chunk(unsigned int x, unsigned int y) : m_posX(x), m_posY(y) {
|
||||
std::ifstream input(pos.str(), std::fstream::binary);
|
||||
|
||||
if (input.fail()) {
|
||||
OpenSimplexNoise::Noise simplex = OpenSimplexNoise::Noise(PERLIN_SEED);
|
||||
OpenSimplexNoise::Noise simplex = OpenSimplexNoise::Noise(SEED);
|
||||
m_blocks.Reset(BTYPE_AIR);
|
||||
|
||||
for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // Montagnes
|
||||
for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) {
|
||||
float xnoiz, ynoiz;
|
||||
xnoiz = (double)(ix + x * CHUNK_SIZE_X) / 256.;
|
||||
ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / 256.;
|
||||
float height = (simplex.eval(xnoiz, ynoiz)) * 60.f + 5.f;
|
||||
xnoiz = (double)(ix + x * CHUNK_SIZE_X) / 1024.;
|
||||
ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / 1024.;
|
||||
double height = 0;
|
||||
for (int x = 0; x < 39; ++x) {
|
||||
height += simplex.eval(xnoiz, ynoiz);
|
||||
height *= .79;
|
||||
xnoiz *= 1.139;
|
||||
ynoiz *= 1.139;
|
||||
}
|
||||
height = height * 2000. * simplex.eval((double)(ix + x * CHUNK_SIZE_X) / 512., (double)(iz + y * CHUNK_SIZE_Z) / 512.);
|
||||
height /= (CHUNK_SIZE_Y / 1.9);
|
||||
height += 15.;
|
||||
for (int iy = 0; iy <= (int)height % CHUNK_SIZE_Y; ++iy)
|
||||
SetBlock(ix, iy, iz, BTYPE_METAL, nullptr);
|
||||
}
|
||||
for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // Collines
|
||||
for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) {
|
||||
float xnoiz, ynoiz;
|
||||
xnoiz = (double)(ix + x * CHUNK_SIZE_X) / 64.;
|
||||
ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / 64.;
|
||||
float height = simplex.eval(xnoiz, ynoiz) * 5.f + 24.f;
|
||||
xnoiz = (double)(ix + x * CHUNK_SIZE_X) / 512.;
|
||||
ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / 512.;
|
||||
float height = simplex.eval(xnoiz, ynoiz) * 50.f;// +1.f;
|
||||
for (int iy = 0; iy <= (int)height % CHUNK_SIZE_Y; ++iy) {
|
||||
if (GetBlock(ix, iy, iz) == BTYPE_AIR)
|
||||
SetBlock(ix, iy, iz, BTYPE_GRASS, nullptr);
|
||||
@ -32,26 +41,26 @@ Chunk::Chunk(unsigned int x, unsigned int y) : m_posX(x), m_posY(y) {
|
||||
}
|
||||
for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // "Lacs"
|
||||
for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) {
|
||||
for (int iy = 0; iy < 16; ++iy) {
|
||||
for (int iy = 0; iy < 13; ++iy) {
|
||||
if (GetBlock(ix, iy, iz) == BTYPE_AIR)
|
||||
SetBlock(ix, iy, iz, BTYPE_ICE, nullptr);
|
||||
}
|
||||
}
|
||||
for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // "Arbres"
|
||||
for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) {
|
||||
float xnoiz, ynoiz;
|
||||
xnoiz = (double)(iz * CHUNK_SIZE_Y + x * CHUNK_SIZE_X) / 256.;
|
||||
ynoiz = (double)(ix * CHUNK_SIZE_Y + y * CHUNK_SIZE_Z) / 256.;
|
||||
bool tree = (int)(abs(simplex.eval(xnoiz, ynoiz)) * 17933.f) % CHUNK_SIZE_Y > 126 ? true : false;
|
||||
for (int iy = 0; iy < CHUNK_SIZE_Y - 10; ++iy)
|
||||
if (GetBlock(ix, iy, iz) == BTYPE_AIR)
|
||||
if (GetBlock(ix, iy - 1, iz) == BTYPE_GRASS)
|
||||
if (tree) {
|
||||
for (int i = 0; i < (int)(abs(simplex.eval(xnoiz, ynoiz) * 65)) % 42 + 1; ++i)
|
||||
SetBlock(ix, iy + i, iz, BTYPE_DIRT, nullptr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
//for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // "Arbres"
|
||||
// for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) {
|
||||
// float xnoiz, ynoiz;
|
||||
// xnoiz = (double)(iz * CHUNK_SIZE_Y + x * CHUNK_SIZE_X) / 256.;
|
||||
// ynoiz = (double)(ix * CHUNK_SIZE_Y + y * CHUNK_SIZE_Z) / 256.;
|
||||
// bool tree = (int)(abs(simplex.eval(xnoiz, ynoiz)) * 17933.f) % CHUNK_SIZE_Y > 126 ? true : false;
|
||||
// for (int iy = 0; iy < CHUNK_SIZE_Y - 10; ++iy)
|
||||
// if (GetBlock(ix, iy, iz) == BTYPE_AIR)
|
||||
// if (GetBlock(ix, iy - 1, iz) == BTYPE_GRASS)
|
||||
// if (tree) {
|
||||
// for (int i = 0; i < (int)(abs(simplex.eval(xnoiz, ynoiz) * 4)) % 42 + 1; ++i)
|
||||
// SetBlock(ix, iy + i, iz, BTYPE_DIRT, nullptr);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
else {
|
||||
input.seekg(0, std::ios_base::end);
|
||||
|
@ -5,7 +5,6 @@
|
||||
#include "array2d.h"
|
||||
#include "vertexbuffer.h"
|
||||
#include "blockinfo.h"
|
||||
#include "perlin.h"
|
||||
#include "opensimplex.h"
|
||||
|
||||
class World;
|
||||
|
@ -16,7 +16,7 @@
|
||||
#define CHUNK_SIZE_Y 128
|
||||
#define CHUNK_SIZE_Z 16
|
||||
#define MAX_SELECTION_DISTANCE 5
|
||||
#define PERLIN_SEED 12345
|
||||
#define SEED 12345
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define WORLD_SIZE_X 64
|
||||
@ -44,10 +44,10 @@
|
||||
#define FRAMES_DELETE_CHUNKS 1
|
||||
|
||||
#define THREADS_GENERATE_CHUNKS 12
|
||||
#define THREADS_UPDATE_CHUNKS 8
|
||||
#define THREADS_DELETE_CHUNKS 10
|
||||
#define THREADS_UPDATE_CHUNKS 5
|
||||
#define THREADS_DELETE_CHUNKS 2
|
||||
|
||||
#define VIEW_DISTANCE 512
|
||||
#define VIEW_DISTANCE 1024
|
||||
#define TEXTURE_SIZE 512
|
||||
#define MAX_BULLETS 512
|
||||
#endif
|
||||
|
@ -185,19 +185,18 @@ void Engine::PrintText(unsigned int x, unsigned int y, const std::string& t) {
|
||||
int Engine::GetFps(float elapsedTime) const { return 1 / elapsedTime; }
|
||||
|
||||
void Engine::Render(float elapsedTime) {
|
||||
static float gameTime = elapsedTime;
|
||||
//static float gameTime = elapsedTime;
|
||||
static float pollTime = 0;
|
||||
static float bulletTime = 0;
|
||||
static BlockType bloc = 1;
|
||||
|
||||
if (elapsedTime > 0.1f) return;
|
||||
|
||||
gameTime += elapsedTime;
|
||||
//gameTime += elapsedTime;
|
||||
pollTime += elapsedTime;
|
||||
|
||||
Transformation all;
|
||||
Transformation skybox;
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
|
||||
// Transformations initiales
|
||||
@ -208,7 +207,7 @@ void Engine::Render(float elapsedTime) {
|
||||
if (bulletTime < 0.f) bulletTime = 0.f;
|
||||
|
||||
if (pollTime >= .005f) {
|
||||
m_player.ApplyPhysics(m_player.GetInput(m_keyW, m_keyS, m_keyA, m_keyD, m_keySpace, (bloc == BTYPE_LAST && bulletTime <= 0.f && m_mouseL), elapsedTime), m_world, elapsedTime, &m_audio);
|
||||
m_player.ApplyPhysics(m_player.GetInput(m_keyW, m_keyS, m_keyA, m_keyD, m_keySpace, (bloc == BTYPE_LAST && bulletTime <= 0.f && m_mouseL), elapsedTime), &m_world, elapsedTime, &m_audio);
|
||||
m_audio.Update3DAudio(m_player.GetPOV(), m_player.GetDirection(), m_player.GetVelocity()); // Ajustement du positionnement 3D avec les coordonnées du joueur et
|
||||
// son vecteur de vélocité (pour l'effet Doppler)
|
||||
pollTime = 0;
|
||||
|
@ -13,7 +13,6 @@
|
||||
#include "blockinfo.h"
|
||||
#include "array2d.h"
|
||||
#include "world.h"
|
||||
#include "perlin.h"
|
||||
#include "bullet.h"
|
||||
|
||||
class Engine : public OpenglContext {
|
||||
@ -47,7 +46,6 @@ private:
|
||||
TextureAtlas m_textureAtlas = TextureAtlas(BTYPE_LAST);
|
||||
|
||||
World m_world = World();
|
||||
Perlin m_perlin = Perlin(8,45.f,7.f,12345);
|
||||
|
||||
Texture m_textureSkybox;
|
||||
Texture m_textureFont;
|
||||
|
@ -4,6 +4,6 @@
|
||||
|
||||
int main() {
|
||||
Engine engine;
|
||||
engine.SetMaxFps(60);
|
||||
engine.SetMaxFps(10000);
|
||||
engine.Start("Syndicat Quebecois de la Construction Simulator 2021", 1920, 1080, true);
|
||||
}
|
||||
|
@ -64,25 +64,25 @@ Vector3f Player::GetInput(bool front, bool back, bool left, bool right, bool jum
|
||||
return delta;
|
||||
}
|
||||
|
||||
void Player::ApplyPhysics(Vector3f input, World world, float elapsedTime, Audio* audio) {
|
||||
void Player::ApplyPhysics(Vector3f input, World* world, float elapsedTime, Audio* audio) {
|
||||
static irrklang::ISound* step; // Pour les sons de pas.
|
||||
static float timing = 0.f;
|
||||
/* Gestion de collisions */
|
||||
BlockType bt1, bt2, bt3;
|
||||
|
||||
bt1 = world.BlockAt(GetPosition().x, GetPosition().y + input.y, GetPosition().z);
|
||||
bt2 = world.BlockAt(GetPosition().x, GetPosition().y + input.y - 0.9f, GetPosition().z);
|
||||
bt3 = world.BlockAt(GetPosition().x, GetPosition().y + input.y - 1.7f, GetPosition().z);
|
||||
bt1 = world->BlockAt(GetPosition().x, GetPosition().y + input.y, GetPosition().z);
|
||||
bt2 = world->BlockAt(GetPosition().x, GetPosition().y + input.y - 0.9f, GetPosition().z);
|
||||
bt3 = world->BlockAt(GetPosition().x, GetPosition().y + input.y - 1.7f, GetPosition().z);
|
||||
if ((bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) && m_position.y < 129.7f) {
|
||||
bt1 = world.BlockAt(GetPosition().x, GetPosition().y + .3f, GetPosition().z);
|
||||
bt1 = world->BlockAt(GetPosition().x, GetPosition().y + .3f, GetPosition().z);
|
||||
if (bt1 == BTYPE_AIR) m_position.y = (int)m_position.y + .7f;
|
||||
m_velocity.y = input.y = 0;
|
||||
m_airborne = false;
|
||||
}
|
||||
else {
|
||||
if (abs(m_velocity.y) < 1.1f) m_velocity.y += input.y - 1.1f * elapsedTime;
|
||||
bt3 = world.BlockAt(GetPosition().x, GetPosition().y + m_velocity.y - 1.7f, GetPosition().z);
|
||||
bt1 = world.BlockAt(GetPosition().x, GetPosition().y + .3f, GetPosition().z);
|
||||
bt3 = world->BlockAt(GetPosition().x, GetPosition().y + m_velocity.y - 1.7f, GetPosition().z);
|
||||
bt1 = world->BlockAt(GetPosition().x, GetPosition().y + .3f, GetPosition().z);
|
||||
if (bt3 != BTYPE_AIR) {
|
||||
m_velocity.y = 0;
|
||||
if (timing == 0.f) {
|
||||
@ -100,17 +100,17 @@ void Player::ApplyPhysics(Vector3f input, World world, float elapsedTime, Audio*
|
||||
if (timing > 0.f) timing -= elapsedTime;
|
||||
if (timing < 0.f) timing = 0.f;
|
||||
|
||||
bt1 = world.BlockAt(GetPosition().x + input.x, GetPosition().y, GetPosition().z);
|
||||
bt2 = world.BlockAt(GetPosition().x + input.x, GetPosition().y - 0.9f, GetPosition().z);
|
||||
bt3 = world.BlockAt(GetPosition().x + input.x, GetPosition().y - 1.7f, GetPosition().z);
|
||||
bt1 = world->BlockAt(GetPosition().x + input.x, GetPosition().y, GetPosition().z);
|
||||
bt2 = world->BlockAt(GetPosition().x + input.x, GetPosition().y - 0.9f, GetPosition().z);
|
||||
bt3 = world->BlockAt(GetPosition().x + input.x, GetPosition().y - 1.7f, GetPosition().z);
|
||||
if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) {
|
||||
input.x = m_velocity.x = 0;
|
||||
m_velocity.z *= .5f;
|
||||
}
|
||||
|
||||
bt1 = world.BlockAt(GetPosition().x, GetPosition().y, GetPosition().z + input.z);
|
||||
bt2 = world.BlockAt(GetPosition().x, GetPosition().y - 0.9f, GetPosition().z + input.z);
|
||||
bt3 = world.BlockAt(GetPosition().x, GetPosition().y - 1.7f, GetPosition().z + input.z);
|
||||
bt1 = world->BlockAt(GetPosition().x, GetPosition().y, GetPosition().z + input.z);
|
||||
bt2 = world->BlockAt(GetPosition().x, GetPosition().y - 0.9f, GetPosition().z + input.z);
|
||||
bt3 = world->BlockAt(GetPosition().x, GetPosition().y - 1.7f, GetPosition().z + input.z);
|
||||
if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) {
|
||||
input.z = m_velocity.z = 0;
|
||||
m_velocity.x *= .5f;
|
||||
|
@ -13,7 +13,7 @@ public:
|
||||
void TurnLeftRight(float value);
|
||||
void TurnTopBottom(float value);
|
||||
Vector3f GetInput(bool front, bool back, bool left, bool right, bool jump, bool dash, float elapsedTime);
|
||||
void ApplyPhysics(Vector3f input, World world, float elapsedTime, Audio* audio);
|
||||
void ApplyPhysics(Vector3f input, World* world, float elapsedTime, Audio* audio);
|
||||
void ApplyTransformation(Transformation& transformation, bool rel = true) const;
|
||||
|
||||
Vector3f GetPosition() const;
|
||||
|
@ -304,9 +304,9 @@ void World::RenderWorld(int& rendercount, Player& player, Transformation& world,
|
||||
void World::UpdateWorld(Player& player, BlockInfo* blockinfo[BTYPE_LAST]) {
|
||||
int cx = player.GetPosition().x;
|
||||
int cy = player.GetPosition().z;
|
||||
static int frameGenerate = 0;
|
||||
static int frameUpdate = 0;
|
||||
static int frameDelete = 0;
|
||||
static int frameGenerate = 1;
|
||||
static int frameUpdate = 2;
|
||||
static int frameDelete = 3;
|
||||
int side = 0;
|
||||
int threads = 0;
|
||||
std::future<Chunk*> genThList[THREADS_GENERATE_CHUNKS];
|
||||
@ -316,7 +316,7 @@ void World::UpdateWorld(Player& player, BlockInfo* blockinfo[BTYPE_LAST]) {
|
||||
if (frameGenerate > 0) --frameGenerate;
|
||||
if (frameUpdate > 0) --frameUpdate;
|
||||
if (frameDelete > 0) --frameDelete;
|
||||
|
||||
|
||||
if (!frameGenerate)
|
||||
while (side * CHUNK_SIZE_X <= VIEW_DISTANCE * 2 + CHUNK_SIZE_X) {
|
||||
int tx = -side, ty = -side;
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user