rework world scaling + flecs dash on/off switch
parent
9719d19aea
commit
ad4167b4f7
|
@ -94,7 +94,7 @@ void flecs_dash_init() {
|
|||
ecs_set_target_fps(world_ecs(), 60);
|
||||
}
|
||||
|
||||
void game_init(int8_t play_mode, uint32_t num_viewers, int32_t seed, uint16_t block_size, uint16_t chunk_size, uint16_t world_size) {
|
||||
void game_init(int8_t play_mode, uint32_t num_viewers, int32_t seed, uint16_t block_size, uint16_t chunk_size, uint16_t world_size, int8_t is_dash_enabled) {
|
||||
is_viewer_only = play_mode;
|
||||
platform_init();
|
||||
world_viewers_init(num_viewers);
|
||||
|
@ -109,7 +109,7 @@ void game_init(int8_t play_mode, uint32_t num_viewers, int32_t seed, uint16_t bl
|
|||
stdcpp_set_os_api();
|
||||
world_setup_pkt_handlers(pkt_reader, sp_pkt_writer);
|
||||
world_init(seed, block_size, chunk_size, world_size);
|
||||
flecs_dash_init();
|
||||
if (is_dash_enabled) flecs_dash_init();
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < num_viewers; i++) {
|
||||
|
|
|
@ -18,6 +18,7 @@ int main(int argc, char** argv)
|
|||
zpl_opts_add(&opts, "v", "viewer-only", "run viewer-only client", ZPL_OPTS_FLAG);
|
||||
zpl_opts_add(&opts, "c", "viewer-count", "number of viewers (detachable clients)", ZPL_OPTS_INT);
|
||||
zpl_opts_add(&opts, "p", "preview-map", "draw world preview", ZPL_OPTS_FLAG);
|
||||
zpl_opts_add(&opts, "dd", "disable-dash", "disables flecs dash", ZPL_OPTS_FLAG);
|
||||
zpl_opts_add(&opts, "s", "seed", "world seed", ZPL_OPTS_INT);
|
||||
zpl_opts_add(&opts, "r", "random-seed", "generate random world seed", ZPL_OPTS_FLAG);
|
||||
zpl_opts_add(&opts, "bs", "block-size", "amount of units within a block (single axis)", ZPL_OPTS_INT);
|
||||
|
@ -33,6 +34,7 @@ int main(int argc, char** argv)
|
|||
}
|
||||
|
||||
int8_t is_viewer_only = zpl_opts_has_arg(&opts, "viewer-only");
|
||||
int8_t is_dash_enabled = !zpl_opts_has_arg(&opts, "disable-dash");
|
||||
int32_t seed = zpl_opts_integer(&opts, "seed", DEFAULT_WORLD_SEED);
|
||||
uint16_t num_viewers = zpl_opts_integer(&opts, "viewer-count", 1);
|
||||
uint16_t block_size = zpl_opts_integer(&opts, "block-size", DEFAULT_BLOCK_SIZE);
|
||||
|
@ -52,7 +54,7 @@ int main(int argc, char** argv)
|
|||
}
|
||||
|
||||
sighandler_register();
|
||||
game_init(is_viewer_only, num_viewers, seed, block_size, chunk_size, world_size);
|
||||
game_init(is_viewer_only, num_viewers, seed, block_size, chunk_size, world_size, is_dash_enabled);
|
||||
|
||||
while (game_is_running()) {
|
||||
game_input();
|
||||
|
|
|
@ -9,17 +9,19 @@
|
|||
const uint16_t screenWidth = 1600;
|
||||
const uint16_t screenHeight = 900;
|
||||
|
||||
#define GFX_WORLD_SCALE 20.0
|
||||
|
||||
static Camera2D render_camera;
|
||||
|
||||
void DrawTextEco(const char *text, int posX, int posY, int fontSize, Color color, float spacing) {
|
||||
// Check if default font has been loaded
|
||||
if (GetFontDefault().texture.id != 0) {
|
||||
Vector2 position = { (float)posX, (float)posY };
|
||||
Vector2 position = { (float)posX * GFX_WORLD_SCALE, (float)posY * GFX_WORLD_SCALE };
|
||||
|
||||
int defaultFontSize = 10; // Default Font chars height in pixel
|
||||
int new_spacing = spacing == 0.0f ? fontSize/defaultFontSize : spacing;
|
||||
|
||||
DrawTextEx(GetFontDefault(), text, position, (float)fontSize, (float)new_spacing, color);
|
||||
DrawTextEx(GetFontDefault(), text, position, (float)fontSize * GFX_WORLD_SCALE, (float)new_spacing * GFX_WORLD_SCALE, color);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,6 +38,14 @@ int MeasureTextEco(const char *text, int fontSize, float spacing) {
|
|||
|
||||
return (int)vec.x;
|
||||
}
|
||||
void DrawCircleEco(int centerX, int centerY, float radius, Color color)
|
||||
{
|
||||
DrawCircleV((Vector2){ (float)centerX * GFX_WORLD_SCALE, (float)centerY * GFX_WORLD_SCALE }, radius * GFX_WORLD_SCALE, color);
|
||||
}
|
||||
void DrawRectangleEco(int posX, int posY, int width, int height, Color color)
|
||||
{
|
||||
DrawRectangleV((Vector2){ (float)posX * GFX_WORLD_SCALE, (float)posY * GFX_WORLD_SCALE }, (Vector2){ (float)width * GFX_WORLD_SCALE, (float)height * GFX_WORLD_SCALE }, color);
|
||||
}
|
||||
|
||||
|
||||
void platform_init() {
|
||||
|
@ -45,7 +55,7 @@ void platform_init() {
|
|||
render_camera.target = (Vector2){0.0f,0.0f};
|
||||
render_camera.offset = (Vector2){screenWidth/2.0f, screenHeight/2.0f};
|
||||
render_camera.rotation = 0.0f;
|
||||
render_camera.zoom = 8.0f;
|
||||
render_camera.zoom = 4.0f/GFX_WORLD_SCALE;
|
||||
}
|
||||
|
||||
void platform_shutdown() {
|
||||
|
@ -60,7 +70,7 @@ void platform_input() {
|
|||
float mouse_z = GetMouseWheelMove();
|
||||
|
||||
if (mouse_z != 0.0f) {
|
||||
render_camera.zoom = zpl_clamp(render_camera.zoom+mouse_z*0.04f, 0.01f, 16.0f);
|
||||
render_camera.zoom = zpl_clamp(render_camera.zoom+mouse_z*0.04f, 0.2f/GFX_WORLD_SCALE, 320.0f/GFX_WORLD_SCALE);
|
||||
}
|
||||
|
||||
// NOTE(zaklaus): keystate handling
|
||||
|
@ -106,7 +116,7 @@ void DEBUG_draw_ground(uint64_t key, entity_view data);
|
|||
|
||||
void platform_render() {
|
||||
camera game_camera = camera_get();
|
||||
render_camera.target = (Vector2){game_camera.x, game_camera.y};
|
||||
render_camera.target = (Vector2){game_camera.x * GFX_WORLD_SCALE, game_camera.y * GFX_WORLD_SCALE};
|
||||
|
||||
BeginDrawing();
|
||||
ClearBackground(BLACK);
|
||||
|
@ -128,6 +138,8 @@ void display_conn_status() {
|
|||
} else {
|
||||
DrawText("Connection: single-player", 5, 5, 12, BLUE);
|
||||
}
|
||||
|
||||
DrawFPS(0, 20);
|
||||
}
|
||||
|
||||
void DEBUG_draw_ground(uint64_t key, entity_view data) {
|
||||
|
@ -138,24 +150,25 @@ void DEBUG_draw_ground(uint64_t key, entity_view data) {
|
|||
|
||||
int32_t size = view->chunk_size * view->block_size;
|
||||
int32_t half_size = size/2;
|
||||
int32_t half_block_size = view->block_size/2;
|
||||
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: {
|
||||
DrawRectangle(x+offset-half_size, y+offset-half_size, size-offset, size-offset, LIME);
|
||||
DrawRectangleEco(x+offset-half_size, y+offset-half_size, 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 * view->block_size + x - half_size + offset;
|
||||
int32_t by = i / view->block_size * view->block_size + y - half_size + offset;
|
||||
DrawRectangle(bx+block_offset-half_block_size,
|
||||
int32_t bx = i % view->block_size * block_size + x - half_size + offset;
|
||||
int32_t by = i / view->block_size * block_size + y - half_size + offset;
|
||||
DrawRectangleEco(bx+block_offset-half_block_size,
|
||||
by+block_offset-half_block_size,
|
||||
view->block_size-block_offset,
|
||||
view->block_size-block_offset,
|
||||
block_size-block_offset,
|
||||
block_size-block_offset,
|
||||
GREEN);
|
||||
}
|
||||
|
||||
DrawText(TextFormat("%.01f %.01f", data.x, data.y), x-half_size+5, y-half_size+5, 65, BLACK);
|
||||
DrawTextEco(TextFormat("%.01f %.01f", data.x, data.y), x-half_size+5, y-half_size+5, 65 , BLACK, 0.0);
|
||||
}break;
|
||||
|
||||
default:break;
|
||||
|
@ -167,17 +180,21 @@ 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/render_camera.zoom);
|
||||
uint16_t font_size = (uint16_t)lerp(4, 32, 0.5f / GFX_WORLD_SCALE/render_camera.zoom);
|
||||
float font_spacing = 1.1f;
|
||||
float title_bg_offset = 4;
|
||||
float fixed_title_offset = 2;
|
||||
|
||||
switch (data.kind) {
|
||||
case EKIND_PLAYER: {
|
||||
double x = data.x;
|
||||
double y = data.y;
|
||||
const char *title = TextFormat("Player %d", key);
|
||||
int title_w = MeasureTextEco(title, font_size, font_spacing);
|
||||
DrawTextEco(title, data.x-title_w/2, data.y-size-font_size, font_size, BLACK, font_spacing);
|
||||
DrawCircle(data.x, data.y, size, RED);
|
||||
DrawRectangleEco(x-title_w/2-title_bg_offset/2, y-size-font_size-fixed_title_offset, title_w+title_bg_offset, font_size, BLACK);
|
||||
DrawTextEco(title, x-title_w/2, y-size-font_size-fixed_title_offset, font_size, RAYWHITE, font_spacing);
|
||||
DrawCircleEco(x, y, size, RED);
|
||||
}break;
|
||||
|
||||
default:break;
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
#include "system.h"
|
||||
#include "world_view.h"
|
||||
|
||||
void game_init(int8_t play_mode, uint32_t num_viewers, int32_t seed, uint16_t block_size, uint16_t chunk_size, uint16_t world_size);
|
||||
void game_init(int8_t play_mode, uint32_t num_viewers, int32_t seed, uint16_t block_size, uint16_t chunk_size, uint16_t world_size, int8_t is_dash_enabled);
|
||||
void game_shutdown();
|
||||
uint8_t game_is_running();
|
||||
int8_t game_is_networked();
|
||||
|
|
|
@ -37,7 +37,7 @@ uint64_t player_spawn(char *name) {
|
|||
|
||||
librg_entity_track(world_tracker(), e);
|
||||
librg_entity_owner_set(world_tracker(), e, (int64_t)e);
|
||||
librg_entity_radius_set(world_tracker(), e, 4);
|
||||
librg_entity_radius_set(world_tracker(), e, 3);
|
||||
librg_entity_chunk_set(world_tracker(), e, librg_chunk_from_realpos(world_tracker(), pos->x, pos->y, 0));
|
||||
|
||||
return (uint64_t)e;
|
||||
|
|
Loading…
Reference in New Issue