From 489b75d9c1bcafa26ea36b8c344c414886375b38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Sat, 8 May 2021 17:42:47 +0200 Subject: [PATCH] improve debug ground rendering --- code/apps/client/source/game.c | 2 +- code/apps/client/source/platform_raylib.c | 49 +++++++++++------------ code/common/entity_view.h | 4 +- code/common/game.h | 2 +- code/common/packets/pkt_send_keystate.c | 4 +- code/common/packets/pkt_send_keystate.h | 8 ++-- code/modules/modules/controllers.h | 4 +- code/modules/modules/general.h | 4 +- 8 files changed, 37 insertions(+), 40 deletions(-) diff --git a/code/apps/client/source/game.c b/code/apps/client/source/game.c index a4e4407..f7477f5 100644 --- a/code/apps/client/source/game.c +++ b/code/apps/client/source/game.c @@ -174,6 +174,6 @@ void game_render() { platform_render(); } -void game_action_send_keystate(double x, double y, uint8_t use, uint8_t sprint) { +void game_action_send_keystate(float x, float y, uint8_t use, uint8_t sprint) { pkt_send_keystate_send(active_viewer->view_id, x, y, use, sprint); } \ No newline at end of file diff --git a/code/apps/client/source/platform_raylib.c b/code/apps/client/source/platform_raylib.c index 80f2b5b..689419f 100644 --- a/code/apps/client/source/platform_raylib.c +++ b/code/apps/client/source/platform_raylib.c @@ -5,11 +5,12 @@ #include "game.h" #include "entity_view.h" #include "camera.h" +#include "math.h" const uint16_t screenWidth = 1600; const uint16_t screenHeight = 900; -#define GFX_WORLD_SCALE 20.0 +#define GFX_WORLD_SCALE 20.0f static Camera2D render_camera; @@ -75,7 +76,7 @@ void platform_input() { // NOTE(zaklaus): keystate handling { - double x=0.0, y=0.0; + float x=0.0f, y=0.0f; uint8_t use, sprint; if (IsKeyDown(KEY_RIGHT) || IsKeyDown(KEY_D)) x += 1.0f; if (IsKeyDown(KEY_LEFT) || IsKeyDown(KEY_A)) x -= 1.0f; @@ -90,8 +91,8 @@ void platform_input() { Vector2 mouse_pos = GetMousePosition(); mouse_pos.x /= screenWidth; mouse_pos.y /= screenHeight; - x = mouse_pos.x-0.5; - y = mouse_pos.y-0.5; + x = mouse_pos.x-0.5f; + y = mouse_pos.y-0.5f; } @@ -143,31 +144,27 @@ void display_conn_status() { } void DEBUG_draw_ground(uint64_t key, entity_view data) { - world_view *view = game_world_view_get_active(); - - int32_t x = data.x * view->chunk_size * view->block_size; - int32_t y = data.y * view->chunk_size * view->block_size; - - int32_t size = view->chunk_size * view->block_size; - int16_t block_size = view->block_size; - int32_t half_block_size = block_size/2; - int16_t offset = 10; - int16_t block_offset = 1; - switch (data.kind) { case EKIND_CHUNK: { - DrawRectangleEco(x+offset, y+offset, size-offset, size-offset, LIME); - for (uint16_t i = 0; i < view->chunk_size*view->chunk_size; i++) { - int32_t bx = i % view->block_size * block_size + x + offset; - int32_t by = i / view->block_size * block_size + y + offset; - DrawRectangleEco(bx+block_offset-half_block_size, - by+block_offset-half_block_size, - block_size-block_offset, - block_size-block_offset, - GREEN); + world_view *view = game_world_view_get_active(); + int32_t size = view->chunk_size * view->block_size; + float block_size = view->block_size*0.70f; + int16_t chunk_size = view->chunk_size; + int16_t offset = 5; + float block_spacing = (float)block_size * (size/(float)(chunk_size*block_size)); + float block_offset = size - block_spacing*chunk_size; + + double x = data.x * size + offset; + double y = data.y * size + offset; + DrawRectangleEco((int)x, (int)y, size-offset, size-offset, LIME); + + for (uint16_t i = 0; i < chunk_size*chunk_size; i++) { + int32_t bx = (float)(i % chunk_size) * block_spacing + (int16_t)x + block_offset; + int32_t by = (float)(i / chunk_size) * block_spacing + (int16_t)y + block_offset; + DrawRectangleEco(bx, by, block_size, block_size, GREEN); } - DrawTextEco(TextFormat("%.01f %.01f", data.x, data.y), x+5, y+5, 65 , BLACK, 0.0); + DrawTextEco(TextFormat("%.01f %.01f", data.x, data.y), (int16_t)x+15, (int16_t)y+15, 65 , BLACK, 0.0); }break; default:break; @@ -179,7 +176,7 @@ static inline float lerp(float a, float b, float t) { return a * (1.0f - t) + b void DEBUG_draw_entities(uint64_t key, entity_view data) { world_view *view = game_world_view_get_active(); uint16_t size = 4; - uint16_t font_size = (uint16_t)lerp(4, 32, 0.5f / GFX_WORLD_SCALE/render_camera.zoom); + uint16_t font_size = (uint16_t)lerp(4.0f, 32.0f, 0.5f / GFX_WORLD_SCALE/(float)render_camera.zoom); float font_spacing = 1.1f; float title_bg_offset = 4; float fixed_title_offset = 2; diff --git a/code/common/entity_view.h b/code/common/entity_view.h index 3271d6a..e27145d 100644 --- a/code/common/entity_view.h +++ b/code/common/entity_view.h @@ -15,8 +15,8 @@ typedef enum { typedef struct entity_view { entity_kind kind; - double x; - double y; + float x; + float y; } entity_view; ZPL_TABLE_DECLARE(, entity_view_tbl, entity_view_tbl_, entity_view); diff --git a/code/common/game.h b/code/common/game.h index bed44c7..2bf0de0 100644 --- a/code/common/game.h +++ b/code/common/game.h @@ -20,4 +20,4 @@ void game_world_view_set_active(world_view *view); void game_world_view_cycle_active(uint8_t dir); //~ NOTE(zaklaus): viewer -> host actions -void game_action_send_keystate(double x, double y, uint8_t use, uint8_t sprint); \ No newline at end of file +void game_action_send_keystate(float x, float y, uint8_t use, uint8_t sprint); \ No newline at end of file diff --git a/code/common/packets/pkt_send_keystate.c b/code/common/packets/pkt_send_keystate.c index c0a98fc..cd97f03 100644 --- a/code/common/packets/pkt_send_keystate.c +++ b/code/common/packets/pkt_send_keystate.c @@ -12,8 +12,8 @@ pkt_desc pkt_send_keystate_desc[] = { }; size_t pkt_send_keystate_send(uint16_t view_id, - double x, - double y, + float x, + float y, uint8_t use, uint8_t sprint) { pkt_send_keystate table = { .x = x, .y = y, .use = use, .sprint = sprint }; diff --git a/code/common/packets/pkt_send_keystate.h b/code/common/packets/pkt_send_keystate.h index bef51f0..257ba1f 100644 --- a/code/common/packets/pkt_send_keystate.h +++ b/code/common/packets/pkt_send_keystate.h @@ -3,14 +3,14 @@ #include "packet_utils.h" typedef struct { - double x; - double y; + float x; + float y; uint8_t use; uint8_t sprint; } pkt_send_keystate; size_t pkt_send_keystate_send(uint16_t view_id, - double x, - double y, + float x, + float y, uint8_t use, uint8_t sprint); size_t pkt_send_keystate_encode(pkt_send_keystate *table); diff --git a/code/modules/modules/controllers.h b/code/modules/modules/controllers.h index 2974da3..001042f 100644 --- a/code/modules/modules/controllers.h +++ b/code/modules/modules/controllers.h @@ -3,8 +3,8 @@ #include "flecs/flecs_meta.h" ECS_STRUCT(Input, { - double x; - double y; + float x; + float y; uint8_t use; uint8_t sprint; }); diff --git a/code/modules/modules/general.h b/code/modules/modules/general.h index b57ad26..0365fdd 100644 --- a/code/modules/modules/general.h +++ b/code/modules/modules/general.h @@ -3,8 +3,8 @@ #include "flecs/flecs_meta.h" ECS_STRUCT(Vector2D, { - double x; - double y; + float x; + float y; }); ECS_STRUCT(Chunk, {