improve debug ground rendering

isolation_bkp/dynres
Dominik Madarász 2021-05-08 17:42:47 +02:00
parent b4bc76719f
commit 489b75d9c1
8 changed files with 37 additions and 40 deletions

View File

@ -174,6 +174,6 @@ void game_render() {
platform_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); pkt_send_keystate_send(active_viewer->view_id, x, y, use, sprint);
} }

View File

@ -5,11 +5,12 @@
#include "game.h" #include "game.h"
#include "entity_view.h" #include "entity_view.h"
#include "camera.h" #include "camera.h"
#include "math.h"
const uint16_t screenWidth = 1600; const uint16_t screenWidth = 1600;
const uint16_t screenHeight = 900; const uint16_t screenHeight = 900;
#define GFX_WORLD_SCALE 20.0 #define GFX_WORLD_SCALE 20.0f
static Camera2D render_camera; static Camera2D render_camera;
@ -75,7 +76,7 @@ void platform_input() {
// NOTE(zaklaus): keystate handling // NOTE(zaklaus): keystate handling
{ {
double x=0.0, y=0.0; float x=0.0f, y=0.0f;
uint8_t use, sprint; uint8_t use, sprint;
if (IsKeyDown(KEY_RIGHT) || IsKeyDown(KEY_D)) x += 1.0f; if (IsKeyDown(KEY_RIGHT) || IsKeyDown(KEY_D)) x += 1.0f;
if (IsKeyDown(KEY_LEFT) || IsKeyDown(KEY_A)) x -= 1.0f; if (IsKeyDown(KEY_LEFT) || IsKeyDown(KEY_A)) x -= 1.0f;
@ -90,8 +91,8 @@ void platform_input() {
Vector2 mouse_pos = GetMousePosition(); Vector2 mouse_pos = GetMousePosition();
mouse_pos.x /= screenWidth; mouse_pos.x /= screenWidth;
mouse_pos.y /= screenHeight; mouse_pos.y /= screenHeight;
x = mouse_pos.x-0.5; x = mouse_pos.x-0.5f;
y = mouse_pos.y-0.5; y = mouse_pos.y-0.5f;
} }
@ -143,31 +144,27 @@ void display_conn_status() {
} }
void DEBUG_draw_ground(uint64_t key, entity_view data) { 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) { switch (data.kind) {
case EKIND_CHUNK: { case EKIND_CHUNK: {
DrawRectangleEco(x+offset, y+offset, size-offset, size-offset, LIME); world_view *view = game_world_view_get_active();
for (uint16_t i = 0; i < view->chunk_size*view->chunk_size; i++) { int32_t size = view->chunk_size * view->block_size;
int32_t bx = i % view->block_size * block_size + x + offset; float block_size = view->block_size*0.70f;
int32_t by = i / view->block_size * block_size + y + offset; int16_t chunk_size = view->chunk_size;
DrawRectangleEco(bx+block_offset-half_block_size, int16_t offset = 5;
by+block_offset-half_block_size, float block_spacing = (float)block_size * (size/(float)(chunk_size*block_size));
block_size-block_offset, float block_offset = size - block_spacing*chunk_size;
block_size-block_offset,
GREEN); 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; }break;
default: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) { void DEBUG_draw_entities(uint64_t key, entity_view data) {
world_view *view = game_world_view_get_active(); world_view *view = game_world_view_get_active();
uint16_t size = 4; 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 font_spacing = 1.1f;
float title_bg_offset = 4; float title_bg_offset = 4;
float fixed_title_offset = 2; float fixed_title_offset = 2;

View File

@ -15,8 +15,8 @@ typedef enum {
typedef struct entity_view { typedef struct entity_view {
entity_kind kind; entity_kind kind;
double x; float x;
double y; float y;
} entity_view; } entity_view;
ZPL_TABLE_DECLARE(, entity_view_tbl, entity_view_tbl_, entity_view); ZPL_TABLE_DECLARE(, entity_view_tbl, entity_view_tbl_, entity_view);

View File

@ -20,4 +20,4 @@ void game_world_view_set_active(world_view *view);
void game_world_view_cycle_active(uint8_t dir); void game_world_view_cycle_active(uint8_t dir);
//~ NOTE(zaklaus): viewer -> host actions //~ NOTE(zaklaus): viewer -> host actions
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);

View File

@ -12,8 +12,8 @@ pkt_desc pkt_send_keystate_desc[] = {
}; };
size_t pkt_send_keystate_send(uint16_t view_id, size_t pkt_send_keystate_send(uint16_t view_id,
double x, float x,
double y, float y,
uint8_t use, uint8_t use,
uint8_t sprint) { uint8_t sprint) {
pkt_send_keystate table = { .x = x, .y = y, .use = use, .sprint = sprint }; pkt_send_keystate table = { .x = x, .y = y, .use = use, .sprint = sprint };

View File

@ -3,14 +3,14 @@
#include "packet_utils.h" #include "packet_utils.h"
typedef struct { typedef struct {
double x; float x;
double y; float y;
uint8_t use; uint8_t use;
uint8_t sprint; uint8_t sprint;
} pkt_send_keystate; } pkt_send_keystate;
size_t pkt_send_keystate_send(uint16_t view_id, size_t pkt_send_keystate_send(uint16_t view_id,
double x, float x,
double y, float y,
uint8_t use, uint8_t use,
uint8_t sprint); uint8_t sprint);
size_t pkt_send_keystate_encode(pkt_send_keystate *table); size_t pkt_send_keystate_encode(pkt_send_keystate *table);

View File

@ -3,8 +3,8 @@
#include "flecs/flecs_meta.h" #include "flecs/flecs_meta.h"
ECS_STRUCT(Input, { ECS_STRUCT(Input, {
double x; float x;
double y; float y;
uint8_t use; uint8_t use;
uint8_t sprint; uint8_t sprint;
}); });

View File

@ -3,8 +3,8 @@
#include "flecs/flecs_meta.h" #include "flecs/flecs_meta.h"
ECS_STRUCT(Vector2D, { ECS_STRUCT(Vector2D, {
double x; float x;
double y; float y;
}); });
ECS_STRUCT(Chunk, { ECS_STRUCT(Chunk, {