++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);
|
std::ifstream input(pos.str(), std::fstream::binary);
|
||||||
|
|
||||||
if (input.fail()) {
|
if (input.fail()) {
|
||||||
OpenSimplexNoise::Noise simplex = OpenSimplexNoise::Noise(PERLIN_SEED);
|
OpenSimplexNoise::Noise simplex = OpenSimplexNoise::Noise(SEED);
|
||||||
m_blocks.Reset(BTYPE_AIR);
|
m_blocks.Reset(BTYPE_AIR);
|
||||||
|
|
||||||
for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // Montagnes
|
for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // Montagnes
|
||||||
for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) {
|
for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) {
|
||||||
float xnoiz, ynoiz;
|
float xnoiz, ynoiz;
|
||||||
xnoiz = (double)(ix + x * CHUNK_SIZE_X) / 256.;
|
xnoiz = (double)(ix + x * CHUNK_SIZE_X) / 1024.;
|
||||||
ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / 256.;
|
ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / 1024.;
|
||||||
float height = (simplex.eval(xnoiz, ynoiz)) * 60.f + 5.f;
|
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)
|
for (int iy = 0; iy <= (int)height % CHUNK_SIZE_Y; ++iy)
|
||||||
SetBlock(ix, iy, iz, BTYPE_METAL, nullptr);
|
SetBlock(ix, iy, iz, BTYPE_METAL, nullptr);
|
||||||
}
|
}
|
||||||
for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // Collines
|
for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // Collines
|
||||||
for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) {
|
for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) {
|
||||||
float xnoiz, ynoiz;
|
float xnoiz, ynoiz;
|
||||||
xnoiz = (double)(ix + x * CHUNK_SIZE_X) / 64.;
|
xnoiz = (double)(ix + x * CHUNK_SIZE_X) / 512.;
|
||||||
ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / 64.;
|
ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / 512.;
|
||||||
float height = simplex.eval(xnoiz, ynoiz) * 5.f + 24.f;
|
float height = simplex.eval(xnoiz, ynoiz) * 50.f;// +1.f;
|
||||||
for (int iy = 0; iy <= (int)height % CHUNK_SIZE_Y; ++iy) {
|
for (int iy = 0; iy <= (int)height % CHUNK_SIZE_Y; ++iy) {
|
||||||
if (GetBlock(ix, iy, iz) == BTYPE_AIR)
|
if (GetBlock(ix, iy, iz) == BTYPE_AIR)
|
||||||
SetBlock(ix, iy, iz, BTYPE_GRASS, nullptr);
|
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 ix = 0; ix < CHUNK_SIZE_X; ++ix) // "Lacs"
|
||||||
for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) {
|
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)
|
if (GetBlock(ix, iy, iz) == BTYPE_AIR)
|
||||||
SetBlock(ix, iy, iz, BTYPE_ICE, nullptr);
|
SetBlock(ix, iy, iz, BTYPE_ICE, nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // "Arbres"
|
//for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // "Arbres"
|
||||||
for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) {
|
// for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) {
|
||||||
float xnoiz, ynoiz;
|
// float xnoiz, ynoiz;
|
||||||
xnoiz = (double)(iz * CHUNK_SIZE_Y + x * CHUNK_SIZE_X) / 256.;
|
// xnoiz = (double)(iz * CHUNK_SIZE_Y + x * CHUNK_SIZE_X) / 256.;
|
||||||
ynoiz = (double)(ix * CHUNK_SIZE_Y + y * CHUNK_SIZE_Z) / 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;
|
// 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)
|
// for (int iy = 0; iy < CHUNK_SIZE_Y - 10; ++iy)
|
||||||
if (GetBlock(ix, iy, iz) == BTYPE_AIR)
|
// if (GetBlock(ix, iy, iz) == BTYPE_AIR)
|
||||||
if (GetBlock(ix, iy - 1, iz) == BTYPE_GRASS)
|
// if (GetBlock(ix, iy - 1, iz) == BTYPE_GRASS)
|
||||||
if (tree) {
|
// if (tree) {
|
||||||
for (int i = 0; i < (int)(abs(simplex.eval(xnoiz, ynoiz) * 65)) % 42 + 1; ++i)
|
// for (int i = 0; i < (int)(abs(simplex.eval(xnoiz, ynoiz) * 4)) % 42 + 1; ++i)
|
||||||
SetBlock(ix, iy + i, iz, BTYPE_DIRT, nullptr);
|
// SetBlock(ix, iy + i, iz, BTYPE_DIRT, nullptr);
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
input.seekg(0, std::ios_base::end);
|
input.seekg(0, std::ios_base::end);
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
#include "array2d.h"
|
#include "array2d.h"
|
||||||
#include "vertexbuffer.h"
|
#include "vertexbuffer.h"
|
||||||
#include "blockinfo.h"
|
#include "blockinfo.h"
|
||||||
#include "perlin.h"
|
|
||||||
#include "opensimplex.h"
|
#include "opensimplex.h"
|
||||||
|
|
||||||
class World;
|
class World;
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
#define CHUNK_SIZE_Y 128
|
#define CHUNK_SIZE_Y 128
|
||||||
#define CHUNK_SIZE_Z 16
|
#define CHUNK_SIZE_Z 16
|
||||||
#define MAX_SELECTION_DISTANCE 5
|
#define MAX_SELECTION_DISTANCE 5
|
||||||
#define PERLIN_SEED 12345
|
#define SEED 12345
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
#define WORLD_SIZE_X 64
|
#define WORLD_SIZE_X 64
|
||||||
@ -44,10 +44,10 @@
|
|||||||
#define FRAMES_DELETE_CHUNKS 1
|
#define FRAMES_DELETE_CHUNKS 1
|
||||||
|
|
||||||
#define THREADS_GENERATE_CHUNKS 12
|
#define THREADS_GENERATE_CHUNKS 12
|
||||||
#define THREADS_UPDATE_CHUNKS 8
|
#define THREADS_UPDATE_CHUNKS 5
|
||||||
#define THREADS_DELETE_CHUNKS 10
|
#define THREADS_DELETE_CHUNKS 2
|
||||||
|
|
||||||
#define VIEW_DISTANCE 512
|
#define VIEW_DISTANCE 1024
|
||||||
#define TEXTURE_SIZE 512
|
#define TEXTURE_SIZE 512
|
||||||
#define MAX_BULLETS 512
|
#define MAX_BULLETS 512
|
||||||
#endif
|
#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; }
|
int Engine::GetFps(float elapsedTime) const { return 1 / elapsedTime; }
|
||||||
|
|
||||||
void Engine::Render(float elapsedTime) {
|
void Engine::Render(float elapsedTime) {
|
||||||
static float gameTime = elapsedTime;
|
//static float gameTime = elapsedTime;
|
||||||
static float pollTime = 0;
|
static float pollTime = 0;
|
||||||
static float bulletTime = 0;
|
static float bulletTime = 0;
|
||||||
static BlockType bloc = 1;
|
static BlockType bloc = 1;
|
||||||
|
|
||||||
if (elapsedTime > 0.1f) return;
|
if (elapsedTime > 0.1f) return;
|
||||||
|
|
||||||
gameTime += elapsedTime;
|
//gameTime += elapsedTime;
|
||||||
pollTime += elapsedTime;
|
pollTime += elapsedTime;
|
||||||
|
|
||||||
Transformation all;
|
Transformation all;
|
||||||
Transformation skybox;
|
Transformation skybox;
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||||
|
|
||||||
// Transformations initiales
|
// Transformations initiales
|
||||||
@ -208,7 +207,7 @@ void Engine::Render(float elapsedTime) {
|
|||||||
if (bulletTime < 0.f) bulletTime = 0.f;
|
if (bulletTime < 0.f) bulletTime = 0.f;
|
||||||
|
|
||||||
if (pollTime >= .005f) {
|
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
|
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)
|
// son vecteur de vélocité (pour l'effet Doppler)
|
||||||
pollTime = 0;
|
pollTime = 0;
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
#include "blockinfo.h"
|
#include "blockinfo.h"
|
||||||
#include "array2d.h"
|
#include "array2d.h"
|
||||||
#include "world.h"
|
#include "world.h"
|
||||||
#include "perlin.h"
|
|
||||||
#include "bullet.h"
|
#include "bullet.h"
|
||||||
|
|
||||||
class Engine : public OpenglContext {
|
class Engine : public OpenglContext {
|
||||||
@ -47,7 +46,6 @@ private:
|
|||||||
TextureAtlas m_textureAtlas = TextureAtlas(BTYPE_LAST);
|
TextureAtlas m_textureAtlas = TextureAtlas(BTYPE_LAST);
|
||||||
|
|
||||||
World m_world = World();
|
World m_world = World();
|
||||||
Perlin m_perlin = Perlin(8,45.f,7.f,12345);
|
|
||||||
|
|
||||||
Texture m_textureSkybox;
|
Texture m_textureSkybox;
|
||||||
Texture m_textureFont;
|
Texture m_textureFont;
|
||||||
|
@ -4,6 +4,6 @@
|
|||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
Engine engine;
|
Engine engine;
|
||||||
engine.SetMaxFps(60);
|
engine.SetMaxFps(10000);
|
||||||
engine.Start("Syndicat Quebecois de la Construction Simulator 2021", 1920, 1080, true);
|
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;
|
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 irrklang::ISound* step; // Pour les sons de pas.
|
||||||
static float timing = 0.f;
|
static float timing = 0.f;
|
||||||
/* Gestion de collisions */
|
/* Gestion de collisions */
|
||||||
BlockType bt1, bt2, bt3;
|
BlockType bt1, bt2, bt3;
|
||||||
|
|
||||||
bt1 = world.BlockAt(GetPosition().x, GetPosition().y + input.y, 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);
|
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);
|
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) {
|
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;
|
if (bt1 == BTYPE_AIR) m_position.y = (int)m_position.y + .7f;
|
||||||
m_velocity.y = input.y = 0;
|
m_velocity.y = input.y = 0;
|
||||||
m_airborne = false;
|
m_airborne = false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (abs(m_velocity.y) < 1.1f) m_velocity.y += input.y - 1.1f * elapsedTime;
|
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);
|
bt3 = world->BlockAt(GetPosition().x, GetPosition().y + m_velocity.y - 1.7f, GetPosition().z);
|
||||||
bt1 = world.BlockAt(GetPosition().x, GetPosition().y + .3f, GetPosition().z);
|
bt1 = world->BlockAt(GetPosition().x, GetPosition().y + .3f, GetPosition().z);
|
||||||
if (bt3 != BTYPE_AIR) {
|
if (bt3 != BTYPE_AIR) {
|
||||||
m_velocity.y = 0;
|
m_velocity.y = 0;
|
||||||
if (timing == 0.f) {
|
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 -= elapsedTime;
|
||||||
if (timing < 0.f) timing = 0.f;
|
if (timing < 0.f) timing = 0.f;
|
||||||
|
|
||||||
bt1 = world.BlockAt(GetPosition().x + input.x, GetPosition().y, 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);
|
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);
|
bt3 = world->BlockAt(GetPosition().x + input.x, GetPosition().y - 1.7f, GetPosition().z);
|
||||||
if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) {
|
if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) {
|
||||||
input.x = m_velocity.x = 0;
|
input.x = m_velocity.x = 0;
|
||||||
m_velocity.z *= .5f;
|
m_velocity.z *= .5f;
|
||||||
}
|
}
|
||||||
|
|
||||||
bt1 = world.BlockAt(GetPosition().x, GetPosition().y, 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);
|
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);
|
bt3 = world->BlockAt(GetPosition().x, GetPosition().y - 1.7f, GetPosition().z + input.z);
|
||||||
if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) {
|
if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) {
|
||||||
input.z = m_velocity.z = 0;
|
input.z = m_velocity.z = 0;
|
||||||
m_velocity.x *= .5f;
|
m_velocity.x *= .5f;
|
||||||
|
@ -13,7 +13,7 @@ public:
|
|||||||
void TurnLeftRight(float value);
|
void TurnLeftRight(float value);
|
||||||
void TurnTopBottom(float value);
|
void TurnTopBottom(float value);
|
||||||
Vector3f GetInput(bool front, bool back, bool left, bool right, bool jump, bool dash, float elapsedTime);
|
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;
|
void ApplyTransformation(Transformation& transformation, bool rel = true) const;
|
||||||
|
|
||||||
Vector3f GetPosition() 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]) {
|
void World::UpdateWorld(Player& player, BlockInfo* blockinfo[BTYPE_LAST]) {
|
||||||
int cx = player.GetPosition().x;
|
int cx = player.GetPosition().x;
|
||||||
int cy = player.GetPosition().z;
|
int cy = player.GetPosition().z;
|
||||||
static int frameGenerate = 0;
|
static int frameGenerate = 1;
|
||||||
static int frameUpdate = 0;
|
static int frameUpdate = 2;
|
||||||
static int frameDelete = 0;
|
static int frameDelete = 3;
|
||||||
int side = 0;
|
int side = 0;
|
||||||
int threads = 0;
|
int threads = 0;
|
||||||
std::future<Chunk*> genThList[THREADS_GENERATE_CHUNKS];
|
std::future<Chunk*> genThList[THREADS_GENERATE_CHUNKS];
|
||||||
|
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