diff --git a/game/src/chunk/chunk.h b/game/src/chunk/chunk.h index ffa359d..c1beba0 100644 --- a/game/src/chunk/chunk.h +++ b/game/src/chunk/chunk.h @@ -8,11 +8,6 @@ #include "../util.h" -#define CHUNK_DIM 32 -#define CHUNK_SIZE (CHUNK_DIM*CHUNK_DIM) - -#define INDEX(x, z) (CHUNK_DIM * (z) + (x)) - typedef struct Chunk { float *heightmap; diff --git a/game/src/chunk/chunkmesh.h b/game/src/chunk/chunkmesh.h index fa1a610..d9a9b46 100644 --- a/game/src/chunk/chunkmesh.h +++ b/game/src/chunk/chunkmesh.h @@ -5,11 +5,6 @@ #include "chunk.h" -#define TERRAIN_TEXTURES 5 -#define CHUNKMESH_DIM (CHUNK_DIM+1) -#define CHUNKMESH_SIZE (CHUNKMESH_DIM*CHUNKMESH_DIM) -#define CMINDEX(x, z) (CHUNKMESH_DIM * (z) + (x)) - typedef struct ChunkMesh { unsigned int pbo; @@ -18,7 +13,6 @@ typedef struct ChunkMesh unsigned int ebo; } ChunkMesh; - ChunkMesh *ChunkMesh_build (Chunk *chunk, Chunk *nr, Chunk *nd, Chunk *nc); void ChunkMesh_bind (ChunkMesh *mesh); void ChunkMesh_render (ChunkMesh *mesh, gboolean wireframe); diff --git a/game/src/entity/entity.c b/game/src/entity/entity.c index 9bf33ad..508e9a1 100644 --- a/game/src/entity/entity.c +++ b/game/src/entity/entity.c @@ -26,7 +26,7 @@ Entity_render (Entity *entity, vec3 camera_position, mat4 view, vec4 frustum_pla /* Why an int, why int division? It's simply much faster than floating point operations. No need to have super accurate cull distance anyway, and might as well save a lot when rendering entities. */ - unsigned int cull_dist = (render_distance * 16 * entity->cull_distance) / 100; + unsigned int cull_dist = (render_distance * CHUNK_DIM * entity->cull_distance) / 100; /* Underneath is the slowest (for the CPU) part of the entity render process. Moving the camera positions from memory into some registers. Thus the entity rendering function optimization is diff --git a/game/src/entity/entity.h b/game/src/entity/entity.h index e69efa1..5be36be 100644 --- a/game/src/entity/entity.h +++ b/game/src/entity/entity.h @@ -3,11 +3,14 @@ #include #include +#include "../util.h" #include "../gvar.h" #include "../gl/mesh_globals.h" #include "../gl/program.h" #include "../gl/texture.h" +struct World; /* Forward declaration. */ + typedef struct Entity { enum { MESH_QUAD1, MESH_QUAD2, MESH_QUAD_X } mesh_type; @@ -21,7 +24,7 @@ typedef struct Entity gboolean wavy; void *userdata; - void (*on_tick) (struct Entity *self); + void (*on_tick) (struct Entity *self, struct World *world); vec3 position; vec3 rotation; diff --git a/game/src/stage/stage_ingame.c b/game/src/stage/stage_ingame.c index 39111f4..35d1bbc 100644 --- a/game/src/stage/stage_ingame.c +++ b/game/src/stage/stage_ingame.c @@ -3,8 +3,8 @@ extern SDL_Window *sdl_window; static Profiler profiler = { 0 }; -static const int profiler_check_freq_s = 10; +static const int profiler_check_freq_s = 10; static const int render_frame_budget_us = 16666; static const int render_distance_min = 2; static const int render_distance_max = 12; @@ -158,6 +158,15 @@ _freelook_camera (SDL_Event *event, void *userdata) return TRUE; } +void +_temporary_player_tick (Entity *self, World *world) +{ + if (!FLAG_GET ("flight_enabled")) + { + self->position[1] = World_get_height_at (world, self->position[0], self->position[2]); + } +} + GameStage * stage_ingame_new () { @@ -198,6 +207,7 @@ stage_ingame_new () player_entity = Entity_new (); player_entity->visible = false; + player_entity->on_tick = _temporary_player_tick; glm_vec3_copy ((vec3) { 1.0, 1.8, 1.0 }, player_entity->scale); /* player_entity->on_tick = character_on_tick; */ World_add_Entity (self->world, player_entity); diff --git a/game/src/util.h b/game/src/util.h index 9c90c2a..f8a7a7f 100644 --- a/game/src/util.h +++ b/game/src/util.h @@ -3,6 +3,15 @@ #define GAME_NAME "Wschód" #define GAME_VERSION "0.3" +#define CHUNK_DIM 32 +#define CHUNK_SIZE (CHUNK_DIM*CHUNK_DIM) +#define INDEX(x, z) (CHUNK_DIM * (z) + (x)) + +#define TERRAIN_TEXTURES 5 +#define CHUNKMESH_DIM (CHUNK_DIM+1) +#define CHUNKMESH_SIZE (CHUNKMESH_DIM*CHUNKMESH_DIM) +#define CMINDEX(x, z) (CHUNKMESH_DIM * (z) + (x)) + #define UNUSED(...) (UNUSED_1 (__VA_ARGS__, 0)) #define UNUSED_1(arg, ...) (void) arg, UNUSED_2 (__VA_ARGS__, 0) #define UNUSED_2(arg, ...) (void) arg, UNUSED_3 (__VA_ARGS__, 0) diff --git a/game/src/world.c b/game/src/world.c index 3ba36fd..7690916 100644 --- a/game/src/world.c +++ b/game/src/world.c @@ -80,7 +80,7 @@ World_update (World *w, vec3 position) if (e->on_tick) { - e->on_tick (e); + e->on_tick (e, w); } } }