code: additional platform rework
parent
d0a31f78a5
commit
c1ab9a2faf
|
@ -21,8 +21,6 @@ static bool request_shutdown;
|
|||
|
||||
#define CAM_OVERLAY_ZOOM_LEVEL 0.80f
|
||||
|
||||
static Camera2D render_camera;
|
||||
|
||||
#include "renderer_v0.c"
|
||||
|
||||
void platform_init() {
|
||||
|
@ -34,29 +32,11 @@ void platform_init() {
|
|||
screenWidth = GetScreenWidth();
|
||||
screenHeight = GetScreenHeight();
|
||||
|
||||
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 = 1.5f;
|
||||
|
||||
// NOTE(zaklaus): Paint the screen before we load the game
|
||||
// TODO(zaklaus): Render a cool loading screen background maybe? :wink: :wink:
|
||||
|
||||
BeginDrawing();
|
||||
ClearBackground(GetColor(0x222034));
|
||||
|
||||
char const *loading_text = "zpl.eco2d is loading...";
|
||||
int text_w = MeasureText(loading_text, 120);
|
||||
DrawText(loading_text, GetScreenWidth()-text_w-15, GetScreenHeight()-135, 120, RAYWHITE);
|
||||
EndDrawing();
|
||||
|
||||
blocks_setup();
|
||||
assets_setup();
|
||||
renderer_init();
|
||||
}
|
||||
|
||||
void platform_shutdown() {
|
||||
blocks_destroy();
|
||||
assets_destroy();
|
||||
renderer_shutdown();
|
||||
CloseWindow();
|
||||
}
|
||||
|
||||
|
@ -109,20 +89,11 @@ void platform_input() {
|
|||
}
|
||||
}
|
||||
|
||||
void do_entity_fadeinout(uint64_t key, entity_view * data);
|
||||
void lerp_entity_positions(uint64_t key, entity_view *data);
|
||||
|
||||
void platform_render() {
|
||||
profile(PROF_ENTITY_LERP) {
|
||||
game_world_view_active_entity_map(lerp_entity_positions);
|
||||
game_world_view_active_entity_map(do_entity_fadeinout);
|
||||
}
|
||||
render_camera.zoom = zpl_lerp(render_camera.zoom, target_zoom, 0.18);
|
||||
camera_update();
|
||||
|
||||
camera game_camera = camera_get();
|
||||
render_camera.target = (Vector2){game_camera.x, game_camera.y};
|
||||
zoom_overlay_tran = zpl_lerp(zoom_overlay_tran, (target_zoom <= CAM_OVERLAY_ZOOM_LEVEL) ? 1.0f : 0.0f, GetFrameTime()*2.0f);
|
||||
|
||||
renderer_draw();
|
||||
|
||||
|
@ -142,47 +113,3 @@ float platform_zoom_get(void) {
|
|||
void platform_request_close(void) {
|
||||
request_shutdown = true;
|
||||
}
|
||||
|
||||
|
||||
void lerp_entity_positions(uint64_t key, entity_view *data) {
|
||||
(void)key;
|
||||
world_view *view = game_world_view_get_active();
|
||||
|
||||
if (data->flag == EFLAG_INTERP) {
|
||||
|
||||
#if 1
|
||||
data->x = smooth_val(data->x, data->tx, view->delta_time[data->layer_id]);
|
||||
data->y = smooth_val(data->y, data->ty, view->delta_time[data->layer_id]);
|
||||
data->heading = smooth_val_spherical(data->heading, data->theading, view->delta_time[data->layer_id]);
|
||||
#else
|
||||
data->x = data->tx;
|
||||
data->y = data->ty;
|
||||
data->heading = data->theading;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void do_entity_fadeinout(uint64_t key, entity_view * data) {
|
||||
(void)key;
|
||||
switch (data->tran_effect) {
|
||||
case ETRAN_FADEIN: {
|
||||
data->tran_time += GetFrameTime();
|
||||
|
||||
if (data->tran_time > 1.0f) {
|
||||
data->tran_effect = ETRAN_NONE;
|
||||
data->tran_time = 1.0f;
|
||||
}
|
||||
}break;
|
||||
|
||||
case ETRAN_FADEOUT: {
|
||||
data->tran_time -= GetFrameTime();
|
||||
|
||||
if (data->tran_time < 0.0f) {
|
||||
data->tran_effect = ETRAN_REMOVE;
|
||||
data->tran_time = 0.0f;
|
||||
}
|
||||
}break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "zpl.h"
|
||||
#include "prediction.h"
|
||||
#include "platform.h"
|
||||
#include "world/world.h"
|
||||
#include "game.h"
|
||||
|
||||
|
@ -67,3 +68,47 @@ void predict_receive_update(entity_view *d, entity_view *data) {
|
|||
data->tran_effect = d->tran_effect;
|
||||
data->tran_time = d->tran_time;
|
||||
}
|
||||
|
||||
|
||||
void lerp_entity_positions(uint64_t key, entity_view *data) {
|
||||
(void)key;
|
||||
world_view *view = game_world_view_get_active();
|
||||
|
||||
if (data->flag == EFLAG_INTERP) {
|
||||
|
||||
#if 1
|
||||
data->x = smooth_val(data->x, data->tx, view->delta_time[data->layer_id]);
|
||||
data->y = smooth_val(data->y, data->ty, view->delta_time[data->layer_id]);
|
||||
data->heading = smooth_val_spherical(data->heading, data->theading, view->delta_time[data->layer_id]);
|
||||
#else
|
||||
data->x = data->tx;
|
||||
data->y = data->ty;
|
||||
data->heading = data->theading;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void do_entity_fadeinout(uint64_t key, entity_view * data) {
|
||||
(void)key;
|
||||
switch (data->tran_effect) {
|
||||
case ETRAN_FADEIN: {
|
||||
data->tran_time += platform_frametime();
|
||||
|
||||
if (data->tran_time > 1.0f) {
|
||||
data->tran_effect = ETRAN_NONE;
|
||||
data->tran_time = 1.0f;
|
||||
}
|
||||
}break;
|
||||
|
||||
case ETRAN_FADEOUT: {
|
||||
data->tran_time -= platform_frametime();
|
||||
|
||||
if (data->tran_time < 0.0f) {
|
||||
data->tran_effect = ETRAN_REMOVE;
|
||||
data->tran_time = 0.0f;
|
||||
}
|
||||
}break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,3 +4,6 @@
|
|||
float smooth_val(float cur, float tgt, uint64_t 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);
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
static Camera2D render_camera;
|
||||
|
||||
float zpl_lerp(float,float,float);
|
||||
float zpl_to_degrees(float);
|
||||
|
@ -103,6 +104,13 @@ void DEBUG_draw_entities_low(uint64_t key, entity_view * data) {
|
|||
}
|
||||
|
||||
void renderer_draw(void) {
|
||||
render_camera.zoom = zpl_lerp(render_camera.zoom, target_zoom, 0.18);
|
||||
camera_update();
|
||||
|
||||
camera game_camera = camera_get();
|
||||
render_camera.target = (Vector2){game_camera.x, game_camera.y};
|
||||
zoom_overlay_tran = zpl_lerp(zoom_overlay_tran, (target_zoom <= CAM_OVERLAY_ZOOM_LEVEL) ? 1.0f : 0.0f, GetFrameTime()*2.0f);
|
||||
|
||||
BeginDrawing();
|
||||
profile (PROF_RENDER) {
|
||||
ClearBackground(GetColor(0x222034));
|
||||
|
@ -116,3 +124,29 @@ void renderer_draw(void) {
|
|||
debug_draw();
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
void renderer_init(void) {
|
||||
render_camera.target = (Vector2){0.0f,0.0f};
|
||||
render_camera.offset = (Vector2){screenWidth >> 1, screenHeight >> 1};
|
||||
render_camera.rotation = 0.0f;
|
||||
render_camera.zoom = 1.5f;
|
||||
|
||||
// NOTE(zaklaus): Paint the screen before we load the game
|
||||
// TODO(zaklaus): Render a cool loading screen background maybe? :wink: :wink:
|
||||
|
||||
BeginDrawing();
|
||||
ClearBackground(GetColor(0x222034));
|
||||
|
||||
char const *loading_text = "zpl.eco2d is loading...";
|
||||
int text_w = MeasureText(loading_text, 120);
|
||||
DrawText(loading_text, GetScreenWidth()-text_w-15, GetScreenHeight()-135, 120, RAYWHITE);
|
||||
EndDrawing();
|
||||
|
||||
blocks_setup();
|
||||
assets_setup();
|
||||
}
|
||||
|
||||
void renderer_shutdown(void) {
|
||||
blocks_destroy();
|
||||
assets_destroy();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue