diff --git a/code/game/src/renderer_bridge.c b/code/game/src/renderer_bridge.c index 531bfb7..64611cc 100644 --- a/code/game/src/renderer_bridge.c +++ b/code/game/src/renderer_bridge.c @@ -1,9 +1,8 @@ #include "debug_draw.h" -#include "renderer_3d.c" -#include "renderer_v0.c" #if GFX_KIND == 0 || !defined(GFX_KIND) // NOTE(zaklaus): renderer_v0 +#include "renderer_v0.c" #define renderer_init renderer_init_v0 #define renderer_shutdown renderer_shutdown_v0 #define renderer_draw renderer_draw_v0 @@ -11,12 +10,15 @@ void renderer_switch(int kind) {} #elif GFX_KIND == 1 // NOTE(zaklaus): renderer_3d +#include "renderer_3d.c" #define renderer_init renderer_init_3d #define renderer_shutdown renderer_shutdown_3d #define renderer_draw renderer_draw_3d #define renderer_debug_draw renderer_debug_draw_3d void renderer_switch(int kind) {} #elif GFX_KIND == 2 +#include "renderer_3d.c" +#include "renderer_v0.c" // NOTE(zaklaus): hybrid mode static int gfx_kind = 0; // 2d -- 0, 3d -- 1 diff --git a/code/game/src/world/blocks.c b/code/game/src/world/blocks.c index b109081..4364161 100644 --- a/code/game/src/world/blocks.c +++ b/code/game/src/world/blocks.c @@ -25,6 +25,7 @@ typedef struct { char symbol; float drag; float friction; + float bounce; // NOTE(zaklaus): viewer data Texture2D img; @@ -87,6 +88,10 @@ float blocks_get_friction(uint8_t id) { return blocks[id].friction; } +float blocks_get_bounce(uint8_t id) { + return blocks[id].bounce; +} + void *blocks_get_img(uint8_t id) { return (void*)&blocks[id].img; } diff --git a/code/game/src/world/blocks.h b/code/game/src/world/blocks.h index 730539f..9dd0bee 100644 --- a/code/game/src/world/blocks.h +++ b/code/game/src/world/blocks.h @@ -22,6 +22,7 @@ uint32_t blocks_get_biome(uint8_t id); uint32_t blocks_get_kind(uint8_t id); float blocks_get_drag(uint8_t id); float blocks_get_friction(uint8_t id); +float blocks_get_bounce(uint8_t id); // NOTE(zaklaus): viewer-related functions void *blocks_get_img(uint8_t id); diff --git a/code/game/src/world/blocks_list.c b/code/game/src/world/blocks_list.c index ee65f0d..25d74cf 100644 --- a/code/game/src/world/blocks_list.c +++ b/code/game/src/world/blocks_list.c @@ -3,7 +3,7 @@ static block blocks[] = { {.name = "base-ground", .flags = 0, .kind = BLOCK_KIND_GROUND, .biome = 0, .symbol = '.', .drag = 1.0f, .friction = 1.0f }, {.name = "base-dirt", .flags = 0, .kind = BLOCK_KIND_DIRT, .biome = 0, .symbol = ',', .drag = 2.1f , .friction = 1.0f }, - {.name = "base-wall", .flags = BLOCK_FLAG_COLLISION, .kind = BLOCK_KIND_WALL, .biome = 0, .symbol = '#', .drag = 1.0f , .friction = 1.0f }, + {.name = "base-wall", .flags = BLOCK_FLAG_COLLISION, .kind = BLOCK_KIND_WALL, .biome = 0, .symbol = '#', .drag = 1.0f , .friction = 1.0f, .bounce = 2.0f }, {.name = "base-hill", .flags = BLOCK_FLAG_COLLISION, .kind = BLOCK_KIND_HILL, .biome = 0, .symbol = '^', .drag = 1.0f , .friction = 1.0f }, {.name = "base-hill-snow", .flags = BLOCK_FLAG_COLLISION, .kind = BLOCK_KIND_HILL_SNOW, .biome = 0, .symbol = '*', .drag = 1.0f , .friction = 1.0f }, {.name = "base-water", .flags = 0, .kind = BLOCK_KIND_WATER, .biome = 0, .symbol = '~', .drag = 0.11f , .friction = 1.0f }, diff --git a/code/modules/modules/systems.c b/code/modules/modules/systems.c index 2e21cd6..9ee0fbc 100644 --- a/code/modules/modules/systems.c +++ b/code/modules/modules/systems.c @@ -10,12 +10,16 @@ #define PHY_BLOCK_COLLISION 1 #define PHY_WALK_DRAG 0.12 #define PHY_LOOKAHEAD(x) (zpl_sign(x)*16.0f) -#define PHY_CORRECTION(x) ((zpl_max(0.0f, (WORLD_BLOCK_SIZE/2.0f) - zpl_abs(x))*zpl_sign(x)))*(WORLD_BLOCK_SIZE/2.0f) #include "source/system_onfoot.c" #include "source/system_demo.c" #include "source/system_vehicle.c" +inline float physics_correction(float x, float vx, float bounce) { + float r = (((zpl_max(0.0f, (WORLD_BLOCK_SIZE/2.0f) - zpl_abs(x))*zpl_sign(x)))*(WORLD_BLOCK_SIZE/2.0f)); + return r + (-vx*bounce); +} + void IntegratePositions(ecs_iter_t *it) { profile(PROF_INTEGRATE_POS) { Position *p = ecs_column(it, Position, 1); @@ -34,8 +38,9 @@ void IntegratePositions(ecs_iter_t *it) { { world_block_lookup lookup = world_block_from_realpos(p[i].x+PHY_LOOKAHEAD(v[i].x), p[i].y); uint32_t flags = blocks_get_flags(lookup.block_id); + float bounce = blocks_get_bounce(lookup.block_id); if (flags & BLOCK_FLAG_COLLISION) { - v[i].x = PHY_CORRECTION(lookup.ox); + v[i].x = physics_correction(lookup.ox, v[i].x, bounce); } } @@ -43,8 +48,9 @@ void IntegratePositions(ecs_iter_t *it) { { world_block_lookup lookup = world_block_from_realpos(p[i].x, p[i].y+PHY_LOOKAHEAD(v[i].y)); uint32_t flags = blocks_get_flags(lookup.block_id); + float bounce = blocks_get_bounce(lookup.block_id); if (flags & BLOCK_FLAG_COLLISION) { - v[i].y = PHY_CORRECTION(lookup.oy); + v[i].y = physics_correction(lookup.oy, v[i].y, bounce); } } #endif diff --git a/code/modules/source/system_onfoot.c b/code/modules/source/system_onfoot.c index 0a48ea7..fad65e7 100644 --- a/code/modules/source/system_onfoot.c +++ b/code/modules/source/system_onfoot.c @@ -1,5 +1,5 @@ #define PLR_MOVE_SPEED 30.0 -#define PLR_MOVE_SPEED_MULT 4.0 +#define PLR_MOVE_SPEED_MULT 1.5 void MovementImpulse(ecs_iter_t *it) { Input *in = ecs_column(it, Input, 1);