Done. But very slow performances...
This commit is contained in:
parent
e78e587024
commit
6520176a66
@ -27,16 +27,16 @@
|
|||||||
#define APP_LABEL "KubKraft"
|
#define APP_LABEL "KubKraft"
|
||||||
|
|
||||||
#define DIST_NEAR 0.1
|
#define DIST_NEAR 0.1
|
||||||
#define DIST_FAR (12 * (CHUNK_WIDTH + CHUNK_HEIGHT) / 2)
|
#define DIST_FAR (12 * (CHUNK_WIDTH + CHUNK_DEPTH) / 2)
|
||||||
|
|
||||||
#define CHUNK_WIDTH 16
|
#define CHUNK_WIDTH 16
|
||||||
#define CHUNK_DEPTH 16
|
#define CHUNK_DEPTH 16
|
||||||
#define CHUNK_HEIGHT 256
|
#define CHUNK_HEIGHT 128
|
||||||
|
|
||||||
#define MAP_POS(x, y, z) ((x) + ((y) * Game::mapWidth) + ((z) * Game::mapWidth * Game::mapDepth))
|
#define MAP_POS(x, y, z) ((x) + ((y) * Game::mapWidth) + ((z) * Game::mapWidth * Game::mapDepth))
|
||||||
#define _MAP_POS(x, y, z) ((x) + ((y) * m_width) + ((z) * m_width * m_depth))
|
#define _MAP_POS(x, y, z) ((x) + ((y) * m_width) + ((z) * m_width * m_depth))
|
||||||
#define CHUNK_POS(x, y) ((x) + ((y) * (m_width / CHUNK_WIDTH)))
|
#define CHUNK_POS(x, y) ((x) + ((y) * (m_width / CHUNK_WIDTH)))
|
||||||
#define CUBE_POS(x, y, z) (((x) - m_x) + (((y) - m_y) * CHUNK_WIDTH) + ((z) * CHUNK_WIDTH * CHUNK_HEIGHT))
|
#define CUBE_POS(x, y, z) (((x) - m_x) + (((y) - m_y) * CHUNK_WIDTH) + ((z) * CHUNK_WIDTH * CHUNK_DEPTH))
|
||||||
|
|
||||||
#define PLAYER_HEIGHT 1.8
|
#define PLAYER_HEIGHT 1.8
|
||||||
#define MOVEMENT_SPEED 3.5
|
#define MOVEMENT_SPEED 3.5
|
||||||
|
@ -42,8 +42,8 @@ using namespace std;
|
|||||||
Player *Game::player;
|
Player *Game::player;
|
||||||
Map *Game::map;
|
Map *Game::map;
|
||||||
|
|
||||||
unsigned int Game::mapWidth = 4 * CHUNK_WIDTH;
|
unsigned int Game::mapWidth = 16 * CHUNK_WIDTH;
|
||||||
unsigned int Game::mapDepth = 4 * CHUNK_DEPTH;
|
unsigned int Game::mapDepth = 16 * CHUNK_DEPTH;
|
||||||
unsigned int Game::mapHeight = CHUNK_HEIGHT;
|
unsigned int Game::mapHeight = CHUNK_HEIGHT;
|
||||||
|
|
||||||
Game::Game() {
|
Game::Game() {
|
||||||
@ -58,7 +58,7 @@ Game::~Game() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Game::exec() {
|
void Game::exec() {
|
||||||
//lockMouse();
|
lockMouse();
|
||||||
|
|
||||||
m_cont = true;
|
m_cont = true;
|
||||||
m_paused = false;
|
m_paused = false;
|
||||||
|
@ -55,7 +55,7 @@ void initOpenGL() {
|
|||||||
glEnable(GL_ALPHA_TEST);
|
glEnable(GL_ALPHA_TEST);
|
||||||
|
|
||||||
glFogi(GL_FOG_MODE, GL_LINEAR);
|
glFogi(GL_FOG_MODE, GL_LINEAR);
|
||||||
glFogf(GL_FOG_START, DIST_FAR - (4 * (CHUNK_WIDTH + CHUNK_HEIGHT) / 2));
|
glFogf(GL_FOG_START, DIST_FAR - (4 * (CHUNK_WIDTH + CHUNK_DEPTH) / 2));
|
||||||
glFogf(GL_FOG_END, DIST_FAR);
|
glFogf(GL_FOG_END, DIST_FAR);
|
||||||
glHint(GL_FOG_HINT, GL_DONT_CARE);
|
glHint(GL_FOG_HINT, GL_DONT_CARE);
|
||||||
GLfloat fog_c[] = {0.5f, 0.5f, 0.5f, 1.0f};
|
GLfloat fog_c[] = {0.5f, 0.5f, 0.5f, 1.0f};
|
||||||
@ -73,7 +73,7 @@ void initOpenGL() {
|
|||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
// Visible area definition
|
// Visible area definition
|
||||||
gluPerspective(WIN_FOV, (GLdouble)WIN_WIDTH / (GLdouble)WIN_HEIGHT, DIST_NEAR, DIST_FAR - (2 * (CHUNK_WIDTH + CHUNK_HEIGHT) / 2));
|
gluPerspective(WIN_FOV, (GLdouble)WIN_WIDTH / (GLdouble)WIN_HEIGHT, DIST_NEAR, DIST_FAR - (2 * (CHUNK_WIDTH + CHUNK_DEPTH) / 2));
|
||||||
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
@ -74,7 +74,7 @@ Map::Map(u16 width, u16 depth, u16 height) {
|
|||||||
|
|
||||||
float perlin = snoise2((float)x * 0.01, (float)y * 0.01); // 0.035
|
float perlin = snoise2((float)x * 0.01, (float)y * 0.01); // 0.035
|
||||||
|
|
||||||
int heightValue = int(perlin * float(m_height / 2));
|
int heightValue = int(perlin * 16 + float(m_height / 2));
|
||||||
|
|
||||||
for(int zz = 0 ; zz < heightValue ; zz++) {
|
for(int zz = 0 ; zz < heightValue ; zz++) {
|
||||||
float cavePerlin = snoise3(x * 0.1, y * 0.1, zz * 0.1) * 2;
|
float cavePerlin = snoise3(x * 0.1, y * 0.1, zz * 0.1) * 2;
|
||||||
@ -159,7 +159,7 @@ Map::Map(u16 width, u16 depth, u16 height) {
|
|||||||
currentChunk = m_chunks[pos];
|
currentChunk = m_chunks[pos];
|
||||||
}
|
}
|
||||||
|
|
||||||
m_chunks[pos]->refreshVBO();
|
//m_chunks[pos]->refreshVBO(); find where it's done
|
||||||
cout << "Chunks loaded: " << pos+1 << endl;
|
cout << "Chunks loaded: " << pos+1 << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -278,14 +278,14 @@ int cubeInFrustum(float x, float y, float z, float size) {
|
|||||||
|
|
||||||
for(p = 0 ; p < 6 ; p++) {
|
for(p = 0 ; p < 6 ; p++) {
|
||||||
c = 0;
|
c = 0;
|
||||||
if((frustum[p][0] * (x - size) + frustum[p][1] * (y - size) + frustum[p][2] * (z - size) + frustum[p][3] > 0)
|
if((frustum[p][0] * (x - size) + frustum[p][1] * (y - size) + frustum[p][2] * (z - CHUNK_HEIGHT / 2) + frustum[p][3] > 0)
|
||||||
|| (frustum[p][0] * (x + size) + frustum[p][1] * (y - size) + frustum[p][2] * (z - size) + frustum[p][3] > 0)
|
|| (frustum[p][0] * (x + size) + frustum[p][1] * (y - size) + frustum[p][2] * (z - CHUNK_HEIGHT / 2) + frustum[p][3] > 0)
|
||||||
|| (frustum[p][0] * (x - size) + frustum[p][1] * (y + size) + frustum[p][2] * (z - size) + frustum[p][3] > 0)
|
|| (frustum[p][0] * (x - size) + frustum[p][1] * (y + size) + frustum[p][2] * (z - CHUNK_HEIGHT / 2) + frustum[p][3] > 0)
|
||||||
|| (frustum[p][0] * (x + size) + frustum[p][1] * (y + size) + frustum[p][2] * (z - size) + frustum[p][3] > 0)
|
|| (frustum[p][0] * (x + size) + frustum[p][1] * (y + size) + frustum[p][2] * (z - CHUNK_HEIGHT / 2) + frustum[p][3] > 0)
|
||||||
|| (frustum[p][0] * (x - size) + frustum[p][1] * (y - size) + frustum[p][2] * (z + size) + frustum[p][3] > 0)
|
|| (frustum[p][0] * (x - size) + frustum[p][1] * (y - size) + frustum[p][2] * (z + CHUNK_HEIGHT / 2) + frustum[p][3] > 0)
|
||||||
|| (frustum[p][0] * (x + size) + frustum[p][1] * (y - size) + frustum[p][2] * (z + size) + frustum[p][3] > 0)
|
|| (frustum[p][0] * (x + size) + frustum[p][1] * (y - size) + frustum[p][2] * (z + CHUNK_HEIGHT / 2) + frustum[p][3] > 0)
|
||||||
|| (frustum[p][0] * (x - size) + frustum[p][1] * (y + size) + frustum[p][2] * (z + size) + frustum[p][3] > 0)
|
|| (frustum[p][0] * (x - size) + frustum[p][1] * (y + size) + frustum[p][2] * (z + CHUNK_HEIGHT / 2) + frustum[p][3] > 0)
|
||||||
|| (frustum[p][0] * (x + size) + frustum[p][1] * (y + size) + frustum[p][2] * (z + size) + frustum[p][3] > 0))
|
|| (frustum[p][0] * (x + size) + frustum[p][1] * (y + size) + frustum[p][2] * (z + CHUNK_HEIGHT / 2) + frustum[p][3] > 0))
|
||||||
c++;
|
c++;
|
||||||
if(c == 0) return 0;
|
if(c == 0) return 0;
|
||||||
else if(c == 8) c2++;
|
else if(c == 8) c2++;
|
||||||
@ -334,8 +334,8 @@ void Map::render() {
|
|||||||
|
|
||||||
pos = CHUNK_POS(x, y);
|
pos = CHUNK_POS(x, y);
|
||||||
|
|
||||||
//if(cubeInFrustum(m_chunks[pos]->x() + CHUNK_WIDTH / 2, m_chunks[pos]->y() + CHUNK_DEPTH / 2, CHUNK_HEIGHT / 2, (CHUNK_WIDTH + CHUNK_DEPTH) / 4) < 1)
|
if(cubeInFrustum(m_chunks[pos]->x() + CHUNK_WIDTH / 2, m_chunks[pos]->y() + CHUNK_DEPTH / 2, CHUNK_HEIGHT / 2, (CHUNK_WIDTH + CHUNK_DEPTH) / 4) < 1)
|
||||||
// continue;
|
continue;
|
||||||
|
|
||||||
if(!m_chunks[pos]->loaded()) m_chunks[pos]->refreshVBO();
|
if(!m_chunks[pos]->loaded()) m_chunks[pos]->refreshVBO();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user