code cleanup and fixes

isolation_bkp/dynres
Dominik Madarász 2021-11-04 15:43:23 +01:00
parent d85919855e
commit 682b8f5d8f
31 changed files with 114 additions and 121 deletions

View File

@ -1,23 +1,22 @@
cmake_minimum_required(VERSION 3.0)
project(eco2d)
include(cmake/utils.cmake)
set(CMAKE_C_STANDARD 11)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR})
if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_compile_options(/W4 /nologo)
endif()
include_directories(code/common code/vendors code/vendors/flecs)
include(cmake/FindRaylib.cmake)
add_subdirectory(code/modules)
add_subdirectory(code/vendors)
add_subdirectory(code/game)
cmake_minimum_required(VERSION 3.0)
project(eco2d)
include(cmake/utils.cmake)
set(CMAKE_C_STANDARD 11)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR})
if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()
include_directories(code/common code/vendors code/vendors/flecs)
include(cmake/FindRaylib.cmake)
add_subdirectory(code/modules)
add_subdirectory(code/vendors)
add_subdirectory(code/game)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -23,8 +23,8 @@ void camera_update(void) {
if (!view) break;
float smooth_ms = zpl_clamp((float)platform_frametime(), 0.0f, 1.0f);
main_camera.x = zpl_lerp(main_camera.x, view->x, CAMERA_LERP_FACTOR*smooth_ms);
main_camera.y = zpl_lerp(main_camera.y, view->y, CAMERA_LERP_FACTOR*smooth_ms);
main_camera.x = zpl_lerp((float)main_camera.x, view->x, CAMERA_LERP_FACTOR*smooth_ms);
main_camera.y = zpl_lerp((float)main_camera.y, view->y, CAMERA_LERP_FACTOR*smooth_ms);
if (main_camera.first_time) {
main_camera.first_time = false;

View File

@ -18,24 +18,24 @@ typedef enum {
typedef struct {
replay_kind kind;
pkt_send_keystate pkt;
uint64_t delay;
double delay;
} replay_record;
#include "debug_replay_compat_v2.c"
static uint8_t is_recording = false;
static replay_record *records = NULL;
static uint64_t last_record_time = 0.0f;
static double last_record_time = 0;
static uint8_t is_playing = false;
static int record_pos = 0;
static uint64_t playback_time = 0;
static double playback_time = 0;
static ecs_entity_t mime = 0;
static ecs_entity_t plr = 0;
static ecs_entity_t *temp_actors = NULL;
#define REPLAY_MAGIC 0x421DC97E
#define REPLAY_VERSION 3
#define REPLAY_VERSION 4
static char replay_filename[1024] = {0};
static char replaybuf[sizeof(replay_record)*UINT16_MAX + 32];
@ -48,7 +48,7 @@ void debug_replay_store(void) {
cw_pack_context_init(&pc, replaybuf, sizeof(replaybuf), 0);
cw_pack_unsigned(&pc, REPLAY_MAGIC);
cw_pack_unsigned(&pc, REPLAY_VERSION);
cw_pack_array_size(&pc, zpl_array_count(records));
cw_pack_array_size(&pc, (uint32_t)zpl_array_count(records));
for (int i = 0; i < zpl_array_count(records); i++) {
cw_pack_bin(&pc, &records[i], sizeof(replay_record));
@ -72,7 +72,7 @@ void debug_replay_load(void) {
zpl_file_close(&f);
cw_unpack_context uc = {0};
cw_unpack_context_init(&uc, replaybuf, file_size, 0);
cw_unpack_context_init(&uc, replaybuf, (uint32_t)file_size, 0);
cw_unpack_next(&uc);
ZPL_ASSERT(uc.item.type == CWP_ITEM_POSITIVE_INTEGER && uc.item.as.u64 == REPLAY_MAGIC);
@ -114,7 +114,7 @@ void debug_replay_start(void) {
if (records) zpl_array_free(records);
zpl_array_init_reserve(records, zpl_heap(), UINT16_MAX);
last_record_time = zpl_time_rel_ms();
last_record_time = zpl_time_rel();
SetTargetFPS(60);
}
@ -153,7 +153,7 @@ void debug_replay_run(void) {
if (mime) return;
is_playing = true;
record_pos = 0;
playback_time = zpl_time_rel_ms();
playback_time = zpl_time_rel();
zpl_array_init(temp_actors, zpl_heap());
plr = camera_get().ent_id;
@ -177,7 +177,7 @@ void ActSpawnIcemaker(void);
void debug_replay_update(void) {
if (!is_playing) return;
if (playback_time >= zpl_time_rel_ms()) return;
if (playback_time >= zpl_time_rel()) return;
replay_record *r = &records[record_pos];
playback_time = zpl_time_rel() + r->delay;
@ -239,7 +239,7 @@ void debug_replay_update(void) {
void debug_replay_record_keystate(pkt_send_keystate state) {
if (!is_recording) return;
float record_time = zpl_time_rel_ms();
double record_time = zpl_time_rel();
replay_record rec = {
.kind = RPKIND_KEY,
@ -248,13 +248,13 @@ void debug_replay_record_keystate(pkt_send_keystate state) {
};
zpl_array_append(records, rec);
last_record_time = zpl_time_rel_ms();
last_record_time = zpl_time_rel();
}
void debug_replay_special_action(replay_kind kind) {
ZPL_ASSERT(kind != RPKIND_KEY);
if (!is_recording || is_playing) return;
float record_time = zpl_time_rel_ms();
double record_time = zpl_time_rel();
replay_record rec = {
.kind = kind,
@ -262,5 +262,5 @@ void debug_replay_special_action(replay_kind kind) {
};
zpl_array_append(records, rec);
last_record_time = zpl_time_rel_ms();
last_record_time = zpl_time_rel();
}

View File

@ -24,5 +24,5 @@ void debug_replay_load_record_v2(replay_record *rec, void const *buf) {
rec->kind = v2_rec.kind;
rec->pkt = pkt;
rec->delay = v2_rec.delay;
rec->delay = (double)v2_rec.delay;
}

View File

@ -224,7 +224,7 @@ debug_draw_result debug_draw_list(debug_item *list, float xpos, float ypos, bool
case DITEM_LIST: {
// NOTE(zaklaus): calculate and cache name width for future use
if (it->name_width == 0) {
it->name_width = UIMeasureText(it->name, DBG_FONT_SIZE);
it->name_width = (float)UIMeasureText(it->name, DBG_FONT_SIZE);
}
Color color = RAYWHITE;
if (is_btn_pressed(xpos, ypos, it->name_width, DBG_FONT_SIZE, &color)) {
@ -242,7 +242,7 @@ debug_draw_result debug_draw_list(debug_item *list, float xpos, float ypos, bool
case DITEM_TEXT: {
char const *text = TextFormat("%s: ", it->name);
if (it->name_width == 0) {
it->name_width = UIMeasureText(text, DBG_FONT_SIZE);
it->name_width = (float)UIMeasureText(text, DBG_FONT_SIZE);
}
UIDrawText(text, xpos, ypos, DBG_FONT_SIZE, RAYWHITE);
ZPL_ASSERT(it->proc);
@ -261,7 +261,7 @@ debug_draw_result debug_draw_list(debug_item *list, float xpos, float ypos, bool
case DITEM_BUTTON: {
char const *text = TextFormat("> %s", it->name);
if (it->name_width == 0) {
it->name_width = UIMeasureText(text, DBG_FONT_SIZE);
it->name_width = (float)UIMeasureText(text, DBG_FONT_SIZE);
}
Color color = RAYWHITE;
if (is_btn_pressed(xpos, ypos, it->name_width, DBG_FONT_SIZE, &color) && it->on_click) {
@ -280,15 +280,15 @@ debug_draw_result debug_draw_list(debug_item *list, float xpos, float ypos, bool
ZPL_ASSERT(it->slider.min != it->slider.max);
char const *text = TextFormat("%s: ", it->name);
if (it->name_width == 0) {
it->name_width = UIMeasureText(text, DBG_FONT_SIZE);
it->name_width = (float)UIMeasureText(text, DBG_FONT_SIZE);
}
UIDrawText(text, xpos, ypos, DBG_FONT_SIZE, RAYWHITE);
xpos += it->name_width;
DrawRectangleLines(xpos, ypos, 100.0f, DBG_FONT_SIZE, RAYWHITE);
DrawRectangleLines((int)xpos, (int)ypos, 100, DBG_FONT_SIZE, RAYWHITE);
float stick_x = xpos + ((it->slider.val / it->slider.max) * 100.0f) - 5.0f;
DrawRectangle(stick_x, ypos, 10.0f, DBG_FONT_SIZE, RED);
DrawRectangle((int)stick_x, (int)ypos, 10, DBG_FONT_SIZE, RED);
xpos += 100.0f + 5.0f;
DrawFloat(xpos, ypos, it->slider.val);
@ -322,15 +322,15 @@ void debug_draw(void) {
}
if (is_handle_ctrl_held) {
debug_xpos = xpos = GetMouseX() - DBG_CTRL_HANDLE_DIM/2;
debug_ypos = ypos = GetMouseY() - DBG_CTRL_HANDLE_DIM/2;
debug_xpos = xpos = (float)(GetMouseX() - DBG_CTRL_HANDLE_DIM/2);
debug_ypos = ypos = (float)(GetMouseY() - DBG_CTRL_HANDLE_DIM/2);
if (area == DAREA_PRESS) {
is_handle_ctrl_held = 0;
}
}
DrawRectangle(xpos, ypos, DBG_CTRL_HANDLE_DIM, DBG_CTRL_HANDLE_DIM, color);
DrawRectangle((int)xpos, (int)ypos, DBG_CTRL_HANDLE_DIM, DBG_CTRL_HANDLE_DIM, color);
}
// NOTE(zaklaus): toggle debug ui

View File

@ -58,7 +58,7 @@ ActSpawnCirclingDriver(void) {
void
ActPlaceIceRink(void) {
ecs_entity_t plr = camera_get().ent_id;
uint8_t watr_id = blocks_find(ASSET_WATER);
block_id watr_id = blocks_find(ASSET_WATER);
Position const *p = ecs_get(world_ecs(), plr, Position);
float const bs = WORLD_BLOCK_SIZE;
@ -210,12 +210,12 @@ ActSpawnDemoNPCs(void) {
uint64_t e = entity_spawn(EKIND_DEMO_NPC);
ecs_add(world_ecs(), e, EcsDemoNPC);
Position *pos = ecs_get_mut(world_ecs(), e, Position, NULL);
pos->x=rand() % world_dim();
pos->y=rand() % world_dim();
pos->x=(float)(rand() % world_dim());
pos->y=(float)(rand() % world_dim());
Velocity *v = ecs_get_mut(world_ecs(), e, Velocity, NULL);
v->x = (rand()%3-1) * 10;
v->y = (rand()%3-1) * 10;
v->x = (float)((rand()%3-1) * 10);
v->y = (float)((rand()%3-1) * 10);
zpl_array_append(demo_npcs, e);
}

View File

@ -36,8 +36,8 @@ DrawCameraPos(debug_item *it, float xpos, float ypos) {
static inline debug_draw_result
DrawUnmeasuredTime(debug_item *it, float xpos, float ypos) {
(void)it;
float total_time = profiler_delta(PROF_TOTAL_TIME);
float acc_time = profiler_delta(PROF_MAIN_LOOP);
float total_time = (float)profiler_delta(PROF_TOTAL_TIME);
float acc_time = (float)profiler_delta(PROF_MAIN_LOOP);
return DrawFormattedText(xpos, ypos, TextFormat("%.02f ms", (total_time-acc_time) * 1000.0f));
}
@ -64,7 +64,7 @@ DrawLiteral(debug_item *it, float xpos, float ypos) {
static inline debug_draw_result
DrawProfilerDelta(debug_item *it, float xpos, float ypos) {
float dt = profiler_delta(it->val);
float dt = (float)profiler_delta(it->val);
return DrawFormattedText(xpos, ypos, TextFormat("%s: %.02f ms", profiler_name(it->val), dt * 1000.0f));
}

View File

@ -119,7 +119,7 @@ void flecs_dash_init() {
}
float game_time() {
return zpl_time_rel();
return (float)zpl_time_rel();
}
void game_init(game_kind play_mode, uint32_t num_viewers, int32_t seed, uint16_t chunk_size, uint16_t chunk_amount, int8_t is_dash_enabled) {

View File

@ -86,7 +86,7 @@ void buildmode_draw(void) {
}
if (!is_outside_range)
renderer_draw_single(cam.x, cam.y, ASSET_BUILDMODE_HIGHLIGHT, ColorAlpha(WHITE, 0.2f));
renderer_draw_single((float)cam.x, (float)cam.y, ASSET_BUILDMODE_HIGHLIGHT, ColorAlpha(WHITE, 0.2f));
build_num_placements = zpl_min(build_num_placements, qty);
}

View File

@ -46,10 +46,10 @@ int main(int argc, char** argv) {
int8_t is_viewer_only = zpl_opts_has_arg(&opts, "viewer-only");
int8_t is_server_only = zpl_opts_has_arg(&opts, "server-only");
int8_t is_dash_enabled = zpl_opts_has_arg(&opts, "enable-dash");
int32_t seed = zpl_opts_integer(&opts, "seed", DEFAULT_WORLD_SEED);
uint16_t num_viewers = zpl_opts_integer(&opts, "viewer-count", 1);
int32_t seed = (int32_t)zpl_opts_integer(&opts, "seed", DEFAULT_WORLD_SEED);
uint16_t num_viewers = (uint16_t)zpl_opts_integer(&opts, "viewer-count", 1);
uint16_t world_size = (uint16_t)zpl_opts_integer(&opts, "world-size", DEFAULT_WORLD_SIZE);
uint16_t chunk_size = DEFAULT_CHUNK_SIZE; //zpl_opts_integer(&opts, "chunk-size", DEFAULT_CHUNK_SIZE);
uint16_t world_size = zpl_opts_integer(&opts, "world-size", DEFAULT_WORLD_SIZE);
game_kind play_mode = GAMEKIND_SINGLE;

View File

@ -25,13 +25,13 @@ int32_t pkt_header_encode(pkt_messages id, uint16_t view_id, void *data, size_t
pkt_pack_msg(&pc, PKT_HEADER_ELEMENTS);
cw_pack_unsigned(&pc, id);
cw_pack_unsigned(&pc, view_id);
cw_pack_bin(&pc, data, datalen);
return pkt_pack_msg_size(&pc);
cw_pack_bin(&pc, data, (uint32_t)datalen);
return (int32_t)pkt_pack_msg_size(&pc);
}
int32_t pkt_header_decode(pkt_header *table, void *data, size_t datalen) {
cw_unpack_context uc = {0};
pkt_unpack_msg_raw(&uc, data, datalen, PKT_HEADER_ELEMENTS);
pkt_unpack_msg_raw(&uc, data, (uint32_t)datalen, PKT_HEADER_ELEMENTS);
cw_unpack_next(&uc);
if (uc.item.type != CWP_ITEM_POSITIVE_INTEGER || uc.item.as.u64 > UINT16_MAX) {
@ -53,7 +53,7 @@ int32_t pkt_header_decode(pkt_header *table, void *data, size_t datalen) {
table->id = pkt_id;
table->view_id = view_id;
table->data = packed_blob;
table->data = (void *)packed_blob;
table->datalen = packed_size;
table->ok = 1;
@ -87,7 +87,7 @@ int32_t pkt_unpack_struct(cw_unpack_context *uc, pkt_desc *desc, void *raw_blob,
case CWP_ITEM_BIN: {
if (uc->item.as.bin.length >= PKT_BUFSIZ) return -1; // bin blob too big
static uint8_t bin_buf[PKT_BUFSIZ] = {0};
uint32_t actual_size = decompress_rle(uc->item.as.bin.start, uc->item.as.bin.length, bin_buf);
uint32_t actual_size = decompress_rle((void *)uc->item.as.bin.start, uc->item.as.bin.length, bin_buf);
if (actual_size != field->size) return -1; // bin size mismatch
zpl_memcopy(blob + field->offset, bin_buf, actual_size);
}break;
@ -121,7 +121,7 @@ int32_t pkt_pack_struct(cw_pack_context *pc, pkt_desc *desc, void *raw_blob, uin
case CWP_ITEM_BIN: {
if (field->size >= PKT_BUFSIZ) return -1; // bin blob too big
static uint8_t bin_buf[PKT_BUFSIZ] = {0};
uint32_t size = compress_rle(blob + field->offset, field->size, bin_buf);
uint32_t size = compress_rle((void *)(blob + field->offset), (uint32_t)field->size, bin_buf);
cw_pack_bin(pc, bin_buf, size);
}break;
case CWP_ITEM_POSITIVE_INTEGER: {

View File

@ -131,8 +131,8 @@ static inline int32_t pkt_msg_decode(pkt_header *header, pkt_desc* desc, uint32_
return pkt_validate_eof_msg(&uc);
}
static inline size_t pkt_pack_desc_args(pkt_desc *desc) {
size_t cnt = 0;
static inline uint32_t pkt_pack_desc_args(pkt_desc *desc) {
uint32_t cnt = 0;
for (pkt_desc *field = desc; field->type != CWP_NOT_AN_ITEM; ++field, ++cnt) {}
return cnt;
}

View File

@ -41,7 +41,7 @@ int32_t pkt_send_librg_update_handler(pkt_header *header) {
int32_t state = librg_world_read(view->tracker, header->view_id, uc.item.as.bin.start, uc.item.as.bin.length, NULL);
if (state < 0) zpl_printf("[ERROR] world read error: %d\n", state);
uint64_t now = zpl_time_rel_ms();
float now = (float)zpl_time_rel();
view->delta_time[layer_id] = now - view->last_update[layer_id];
view->last_update[layer_id] = now;

View File

@ -4,8 +4,8 @@
#include "world/world.h"
#include "game.h"
#define PREDICT_SMOOTH_FACTOR_LO 7.5
#define PREDICT_SMOOTH_FACTOR_HI 12.5
#define PREDICT_SMOOTH_FACTOR_LO 7.5f
#define PREDICT_SMOOTH_FACTOR_HI 12.5f
static inline float map_factor(float x) {
x = 1.0f - zpl_clamp01(x);
@ -32,20 +32,13 @@ static inline float spherical_lerp(float a, float b, float t) {
return base_angle(zpl_lerp(a, b, t));
}
float smooth_val(float cur, float tgt, uint64_t dt) {
float smooth_val(float cur, float tgt, float dt) {
float factor = zpl_clamp01(map_factor(zpl_unlerp(dt, WORLD_TRACKER_UPDATE_MP_FAST_MS, WORLD_TRACKER_UPDATE_MP_SLOW_MS)));
#if 0
dt = 200;
factor = map_factor(zpl_unlerp(dt, WORLD_TRACKER_UPDATE_MP_FAST_MS, WORLD_TRACKER_UPDATE_MP_SLOW_MS));
zpl_printf("lerp factor: %f\n", factor);
zpl_exit(0);
#endif
return zpl_lerp(cur, tgt, zpl_clamp01(zpl_lerp(PREDICT_SMOOTH_FACTOR_LO, PREDICT_SMOOTH_FACTOR_HI, factor)*platform_frametime()));
}
float smooth_val_spherical(float cur, float tgt, uint64_t dt) {
float smooth_val_spherical(float cur, float tgt, float dt) {
float factor = zpl_clamp01(map_factor(zpl_unlerp(dt, WORLD_TRACKER_UPDATE_MP_FAST_MS, WORLD_TRACKER_UPDATE_MP_SLOW_MS)));
return spherical_lerp(cur, tgt, zpl_clamp01(zpl_lerp(PREDICT_SMOOTH_FACTOR_LO, PREDICT_SMOOTH_FACTOR_HI, factor)*platform_frametime()));

View File

@ -1,9 +1,9 @@
#pragma once
#include "entity_view.h"
float smooth_val(float cur, float tgt, uint64_t dt);
float smooth_val(float cur, float tgt, float dt);
float smooth_val_spherical(float cur, float tgt, float dt);
void predict_receive_update(entity_view *d, entity_view *data);
float smooth_val_spherical(float cur, float tgt, uint64_t dt);
void do_entity_fadeinout(uint64_t key, entity_view * data);
void lerp_entity_positions(uint64_t key, entity_view *data);

View File

@ -11,9 +11,9 @@ void DEBUG_draw_ground_3d(uint64_t key, entity_view * data) {
switch (data->kind) {
case EKIND_CHUNK: {
world_view *view = game_world_view_get_active();
int32_t size = view->chunk_size * WORLD_BLOCK_SIZE;
int32_t half_size = size >> 1;
int32_t half_block_size = WORLD_BLOCK_SIZE >> 1;
float size = (float)(view->chunk_size * WORLD_BLOCK_SIZE);
float half_size = size / 2.0f;
float half_block_size = (float)(WORLD_BLOCK_SIZE >> 1);
int16_t offset = 0;
float x = data->x * size + offset;
@ -24,7 +24,7 @@ void DEBUG_draw_ground_3d(uint64_t key, entity_view * data) {
for (size_t ty = 0; ty < view->chunk_size; ty++) {
for (size_t tx = 0; tx < view->chunk_size; tx++) {
uint8_t blk_id = data->outer_blocks[(ty*view->chunk_size)+tx];
block_id blk_id = data->outer_blocks[(ty*view->chunk_size)+tx];
if (blk_id != 0) {
DrawCubeTexture(GetBlockImage(blk_id), (Vector3){x + tx*WORLD_BLOCK_SIZE+half_block_size, 32.0f, y + ty*WORLD_BLOCK_SIZE+half_block_size}, 64, 0.01f, 64, WHITE);
}
@ -96,8 +96,8 @@ void renderer_draw_3d(void) {
camera game_camera_3d = camera_get();
#if 1
render_camera_3d.position = (Vector3){game_camera_3d.x, 260.0f*(10.0f-cam_zoom), game_camera_3d.y+50.0f*(10.0f-cam_zoom/2.0f)};
render_camera_3d.target = (Vector3){game_camera_3d.x, 0.0f, game_camera_3d.y};
render_camera_3d.position = (Vector3){(float)game_camera_3d.x, 260.0f*(10.0f-cam_zoom), (float)game_camera_3d.y+50.0f*(10.0f-cam_zoom/2.0f)};
render_camera_3d.target = (Vector3){(float)game_camera_3d.x, 0.0f, (float)game_camera_3d.y};
#else
UpdateCamera(&render_camera_3d);
#endif

View File

@ -96,7 +96,7 @@ void renderer_draw_single(float x, float y, asset_id id, Color color) {
void renderer_bake_chunk(uint64_t key, entity_view * data) {
if (data->kind != EKIND_CHUNK) return;
world_view *view = game_world_view_get_active();
blocks_build_chunk_tex(key, data->blocks, data->outer_blocks, view);
blocks_build_chunk_tex(key, data->blocks, view);
}
void renderer_switch(int kind) {

View File

@ -12,28 +12,28 @@ void DEBUG_draw_ground(uint64_t key, entity_view * data) {
switch (data->kind) {
case EKIND_CHUNK: {
world_view *view = game_world_view_get_active();
int32_t size = view->chunk_size * WORLD_BLOCK_SIZE;
int16_t offset = 0;
float size = (float)(view->chunk_size * WORLD_BLOCK_SIZE);
float offset = 0.0;
float x = data->x * size + offset;
float y = data->y * size + offset;
RenderTexture2D tex = GetChunkTexture(key);
float scale = (size)/(float)(tex.texture.width);
tex.texture.width *= scale;
tex.texture.height *= scale;
tex.texture.width *= (int32_t)scale;
tex.texture.height *= (int32_t)scale;
DrawTextureRec(tex.texture, (Rectangle){0, 0, size, -size}, (Vector2){x, y}, ColorAlpha(WHITE, data->tran_time));
if (zoom_overlay_tran > 0.02f) {
DrawRectangleEco(x, y, size-offset, size-offset, ColorAlpha(ColorFromHSV(data->color, 0.13f, 0.89f), data->tran_time*zoom_overlay_tran*0.75f));
DrawRectangleEco(x, y, size-offset, size-offset, ColorAlpha(ColorFromHSV((float)data->color, 0.13f, 0.89f), data->tran_time*zoom_overlay_tran*0.75f));
DrawTextEco(TextFormat("%d %d", (int)data->x, (int)data->y), (int16_t)x+15, (int16_t)y+15, 200 , ColorAlpha(BLACK, data->tran_time*zoom_overlay_tran), 0.0);
DrawTextEco(TextFormat("%d %d", (int)data->x, (int)data->y), x+15.0f, y+15.0f, 200 , ColorAlpha(BLACK, data->tran_time*zoom_overlay_tran), 0.0);
}
for (size_t ty = 0; ty < view->chunk_size; ty++) {
for (size_t tx = 0; tx < view->chunk_size; tx++) {
uint8_t blk_id = data->outer_blocks[(ty*view->chunk_size)+tx];
block_id blk_id = data->outer_blocks[(ty*view->chunk_size)+tx];
if (blk_id != 0) {
DrawTextureRec(GetBlockImage(blk_id), ASSET_SRC_RECT(), (Vector2){x+tx*WORLD_BLOCK_SIZE, y+ty*WORLD_BLOCK_SIZE}, ColorAlpha(WHITE, data->tran_time));
}
@ -123,7 +123,7 @@ void renderer_draw_v0(void) {
camera_update();
camera game_camera = camera_get();
render_camera.target = (Vector2){game_camera.x, game_camera.y};
render_camera.target = (Vector2){(float)game_camera.x, (float)game_camera.y};
zoom_overlay_tran = zpl_lerp(zoom_overlay_tran, (target_zoom <= CAM_OVERLAY_ZOOM_LEVEL) ? 1.0f : 0.0f, GetFrameTime()*2.0f);
@ -141,7 +141,7 @@ float renderer_zoom_get_v0(void) {
void renderer_init_v0(void) {
render_camera.target = (Vector2){0.0f,0.0f};
render_camera.offset = (Vector2){screenWidth >> 1, screenHeight >> 1};
render_camera.offset = (Vector2){(float)(screenWidth >> 1), (float)(screenHeight >> 1)};
render_camera.rotation = 0.0f;
render_camera.zoom = 1.5f;

View File

@ -6,18 +6,18 @@
void generate_minimap(int32_t seed, uint16_t block_size, uint16_t chunk_size, uint16_t world_size) {
world_init(seed, chunk_size, world_size);
uint8_t const *world;
block_id const *world;
uint32_t world_length = chunk_size * world_size;
uint32_t len = world_buf(&world, NULL);
for (int i=0; i<len; i++) {
for (block_id i=0; i<len; i++) {
if (i > 0 && i % world_length == 0) {
putc('\n', stdout);
}
putc(blocks_get_symbol(world[i]), stdout);
}
putc('\n', stdout);
world_destroy();
}

View File

@ -16,8 +16,8 @@ void DrawTextEco(const char *text, float posX, float posY, int fontSize, Color c
if (GetFontDefault().texture.id != 0) {
Vector2 position = { (float)posX , (float)posY };
int defaultFontSize = 10; // Default Font chars height in pixel
int new_spacing = spacing == 0.0f ? fontSize/defaultFontSize : spacing;
float defaultFontSize = 10.0; // Default Font chars height in pixel
float new_spacing = spacing == 0.0f ? (float)fontSize/defaultFontSize : spacing;
DrawTextEx(GetFontDefault(), text, position, (float)fontSize , (float)new_spacing , color);
}
@ -31,8 +31,8 @@ int MeasureTextEco(const char *text, int fontSize, float spacing) {
// Check if default font has been loaded
if (GetFontDefault().texture.id != 0) {
int defaultFontSize = 10; // Default Font chars height in pixel
int new_spacing = spacing == 0.0f ? fontSize/defaultFontSize : spacing;
float defaultFontSize = 10.0; // Default Font chars height in pixel
float new_spacing = spacing == 0.0f ? (float)fontSize/defaultFontSize : spacing;
vec = MeasureTextEx(GetFontDefault(), text, (float)fontSize, (float)new_spacing);
}
@ -56,7 +56,7 @@ void DrawRectangleEco(float posX, float posY, float width, float height, Color c
}
static inline
Texture2D GetBlockImage(uint8_t id) {
Texture2D GetBlockImage(block_id id) {
return *(Texture2D*)blocks_get_img(id);
}
@ -329,13 +329,14 @@ Vector3 MeasureText3D(Font font, const char* text, float fontSize, float fontSpa
return vec;
#endif
Vector3 todo = {0};
return todo;
}
Color GenerateRandomColor(float s, float v) {
const float Phi = 0.618033988749895f; // Golden ratio conjugate
float h = GetRandomValue(0, 360);
float h = (float)GetRandomValue(0, 360);
h = fmodf((h + h*Phi), 360.0f);
return ColorFromHSV(h, s, v);
}

View File

@ -37,8 +37,8 @@ static double perlin_smooth_lerp(double x, double y, double t) {
}
double perlin_noise2d(int32_t seed, double x, double y) {
int32_t x_int = floor(x);
int32_t y_int = floor(y);
int32_t x_int = (int32_t)floor(x);
int32_t y_int = (int32_t)floor(y);
double x_frac = x - x_int;
double y_frac = y - y_int;
int32_t s = perlin_noise2_sample(seed, x_int, y_int);
@ -57,7 +57,7 @@ double perlin_fbm(int32_t seed, double x, double y, double freq, uint32_t octave
double amp = 1.0;
double res = 0.0;
double div = 0.0;
for (uint32_t i=0; i<octaves; i++) {
div += 256.0 * amp;
res += perlin_noise2d(seed, xa, ya) * amp;
@ -65,6 +65,6 @@ double perlin_fbm(int32_t seed, double x, double y, double freq, uint32_t octave
xa *= 2.0;
ya *= 2.0;
}
return res/div;
}

View File

@ -255,9 +255,9 @@ int32_t world_destroy(void) {
#define WORLD_LIBRG_BUFSIZ 2000000
static void world_tracker_update(uint16_t ticker, uint32_t freq, uint8_t radius) {
if (world.tracker_update[ticker] > zpl_time_rel_ms()) return;
world.tracker_update[ticker] = zpl_time_rel_ms() + freq;
static void world_tracker_update(uint8_t ticker, uint32_t freq, uint8_t radius) {
if (world.tracker_update[ticker] > (float)zpl_time_rel()) return;
world.tracker_update[ticker] = (float)zpl_time_rel() + freq;
profile(PROF_WORLD_WRITE) {
ecs_iter_t it = ecs_query_iter(world.ecs_update);

View File

@ -41,7 +41,7 @@ typedef struct {
block_id **block_mapping;
block_id **outer_block_mapping;
uint16_t dim;
uint64_t tracker_update[3];
float tracker_update[3];
uint8_t active_layer_id;
ecs_world_t *ecs;
ecs_world_t *ecs_stage;

View File

@ -16,8 +16,8 @@ typedef struct {
uint16_t chunk_amount;
// NOTE(zaklaus): metrics
uint64_t last_update[WORLD_TRACKER_LAYERS];
uint64_t delta_time[WORLD_TRACKER_LAYERS];
float last_update[WORLD_TRACKER_LAYERS];
float delta_time[WORLD_TRACKER_LAYERS];
uint8_t active_layer_id;
} world_view;