code: make hybrid render mode
parent
49cd83fd6a
commit
7c587faba6
|
@ -18,7 +18,8 @@ static uint16_t screenHeight = 900;
|
|||
static float target_zoom = 1.5f;
|
||||
static bool request_shutdown;
|
||||
|
||||
#include "renderer_3d.c"
|
||||
#define GFX_KIND 2
|
||||
#include "renderer_bridge.c"
|
||||
|
||||
void platform_init() {
|
||||
InitWindow(screenWidth, screenHeight, "eco2d");
|
||||
|
@ -31,6 +32,18 @@ void platform_init() {
|
|||
renderer_init();
|
||||
}
|
||||
|
||||
void display_conn_status() {
|
||||
if (game_is_networked()) {
|
||||
if (network_client_is_connected()) {
|
||||
DrawText("Connection: online", 5, 5, 12, GREEN);
|
||||
} else {
|
||||
DrawText("Connection: offline", 5, 5, 12, RED);
|
||||
}
|
||||
} else {
|
||||
DrawText("Connection: single-player", 5, 5, 12, BLUE);
|
||||
}
|
||||
}
|
||||
|
||||
void platform_shutdown() {
|
||||
renderer_shutdown();
|
||||
CloseWindow();
|
||||
|
@ -83,6 +96,13 @@ void platform_input() {
|
|||
game_world_view_cycle_active(1);
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE(zaklaus): switch render modes
|
||||
{
|
||||
if (IsKeyPressed(KEY_O)) {
|
||||
renderer_switch(1-gfx_kind);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void platform_render() {
|
||||
|
|
|
@ -1,26 +1,12 @@
|
|||
static Camera3D render_camera;
|
||||
static float zoom_overlay_tran = 0.0f;
|
||||
static Camera3D render_camera_3d;
|
||||
static float cam_zoom = 1.5f;
|
||||
|
||||
#define CAM_OVERLAY_ZOOM_LEVEL 0.80f
|
||||
|
||||
|
||||
float zpl_lerp(float,float,float);
|
||||
float zpl_to_degrees(float);
|
||||
|
||||
void display_conn_status() {
|
||||
if (game_is_networked()) {
|
||||
if (network_client_is_connected()) {
|
||||
DrawText("Connection: online", 5, 5, 12, GREEN);
|
||||
} else {
|
||||
DrawText("Connection: offline", 5, 5, 12, RED);
|
||||
}
|
||||
} else {
|
||||
DrawText("Connection: single-player", 5, 5, 12, BLUE);
|
||||
}
|
||||
}
|
||||
|
||||
void DEBUG_draw_ground(uint64_t key, entity_view * data) {
|
||||
void DEBUG_draw_ground_3d(uint64_t key, entity_view * data) {
|
||||
(void)key;
|
||||
switch (data->kind) {
|
||||
case EKIND_CHUNK: {
|
||||
|
@ -40,9 +26,7 @@ void DEBUG_draw_ground(uint64_t key, entity_view * data) {
|
|||
}
|
||||
}
|
||||
|
||||
static inline float lerp(float a, float b, float t) { return a * (1.0f - t) + b * t; }
|
||||
|
||||
void DEBUG_draw_entities(uint64_t key, entity_view * data) {
|
||||
void DEBUG_draw_entities_3d(uint64_t key, entity_view * data) {
|
||||
(void)key;
|
||||
uint16_t size = 16;
|
||||
uint16_t ground_offset = 30;
|
||||
|
@ -71,7 +55,7 @@ void DEBUG_draw_entities(uint64_t key, entity_view * data) {
|
|||
}
|
||||
}
|
||||
|
||||
void DEBUG_draw_entities_low(uint64_t key, entity_view * data) {
|
||||
void DEBUG_draw_entities_low_3d(uint64_t key, entity_view * data) {
|
||||
(void)key;
|
||||
|
||||
switch (data->kind) {
|
||||
|
@ -87,36 +71,36 @@ void DEBUG_draw_entities_low(uint64_t key, entity_view * data) {
|
|||
}
|
||||
|
||||
|
||||
void renderer_draw(void) {
|
||||
void renderer_draw_3d(void) {
|
||||
cam_zoom = zpl_min(zpl_lerp(cam_zoom, target_zoom, 0.18), 9.98f);
|
||||
camera_update();
|
||||
|
||||
camera game_camera = camera_get();
|
||||
camera game_camera_3d = camera_get();
|
||||
#if 1
|
||||
render_camera.position = (Vector3){game_camera.x, 260.0f*(10.0f-cam_zoom), game_camera.y+50.0f*(10.0f-cam_zoom/2.0f)};
|
||||
render_camera.target = (Vector3){game_camera.x, 0.0f, game_camera.y};
|
||||
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};
|
||||
#else
|
||||
UpdateCamera(&render_camera);
|
||||
UpdateCamera(&render_camera_3d);
|
||||
#endif
|
||||
|
||||
ClearBackground(GetColor(0x222034));
|
||||
BeginMode3D(render_camera);
|
||||
game_world_view_active_entity_map(DEBUG_draw_ground);
|
||||
game_world_view_active_entity_map(DEBUG_draw_entities_low);
|
||||
game_world_view_active_entity_map(DEBUG_draw_entities);
|
||||
BeginMode3D(render_camera_3d);
|
||||
game_world_view_active_entity_map(DEBUG_draw_ground_3d);
|
||||
game_world_view_active_entity_map(DEBUG_draw_entities_low_3d);
|
||||
game_world_view_active_entity_map(DEBUG_draw_entities_3d);
|
||||
EndMode3D();
|
||||
}
|
||||
|
||||
void renderer_init(void) {
|
||||
render_camera.up = (Vector3){0.0f,0.0f,-1.0f};
|
||||
render_camera.fovy = 45.f;
|
||||
render_camera.projection = CAMERA_PERSPECTIVE;
|
||||
void renderer_init_3d(void) {
|
||||
render_camera_3d.up = (Vector3){0.0f,0.0f,-1.0f};
|
||||
render_camera_3d.fovy = 45.f;
|
||||
render_camera_3d.projection = CAMERA_PERSPECTIVE;
|
||||
#if 1
|
||||
SetCameraMode(render_camera, CAMERA_MODE_STATIONARY);
|
||||
SetCameraMode(render_camera_3d, CAMERA_MODE_STATIONARY);
|
||||
#else
|
||||
render_camera.position = (Vector3){10,10,10};
|
||||
render_camera.target = (Vector3){0};
|
||||
SetCameraMode(render_camera, CAMERA_ORBITAL);
|
||||
render_camera_3d.position = (Vector3){10,10,10};
|
||||
render_camera_3d.target = (Vector3){0};
|
||||
SetCameraMode(render_camera_3d, CAMERA_ORBITAL);
|
||||
#endif
|
||||
|
||||
// NOTE(zaklaus): Paint the screen before we load the game
|
||||
|
@ -134,7 +118,7 @@ void renderer_init(void) {
|
|||
assets_setup();
|
||||
}
|
||||
|
||||
void renderer_shutdown(void) {
|
||||
void renderer_shutdown_3d(void) {
|
||||
blocks_destroy();
|
||||
assets_destroy();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
#include "renderer_3d.c"
|
||||
#include "renderer_v0.c"
|
||||
|
||||
#if GFX_KIND == 0 || !defined(GFX_KIND)
|
||||
// NOTE(zaklaus): renderer_v0
|
||||
#define renderer_init renderer_init_v0
|
||||
#define renderer_shutdown renderer_shutdown_v0
|
||||
#define renderer_draw renderer_draw_v0
|
||||
void renderer_switch(int kind) {}
|
||||
#elif GFX_KIND == 1
|
||||
// NOTE(zaklaus): renderer_3d
|
||||
#define renderer_init renderer_init_3d
|
||||
#define renderer_shutdown renderer_shutdown_3d
|
||||
#define renderer_draw renderer_draw_3d
|
||||
void renderer_switch(int kind) {}
|
||||
#elif GFX_KIND == 2
|
||||
// NOTE(zaklaus): hybrid mode
|
||||
static int gfx_kind = 0; // 2d -- 0, 3d -- 1
|
||||
|
||||
void renderer_draw(void) {
|
||||
switch (gfx_kind) {
|
||||
case 0:{
|
||||
renderer_draw_v0();
|
||||
}break;
|
||||
case 1:{
|
||||
renderer_draw_3d();
|
||||
}break;
|
||||
}
|
||||
}
|
||||
|
||||
void renderer_init(void) {
|
||||
switch (gfx_kind) {
|
||||
case 0:{
|
||||
renderer_init_v0();
|
||||
}break;
|
||||
case 1:{
|
||||
renderer_init_3d();
|
||||
}break;
|
||||
}
|
||||
}
|
||||
|
||||
void renderer_shutdown(void) {
|
||||
switch (gfx_kind) {
|
||||
case 0:{
|
||||
renderer_shutdown_v0();
|
||||
}break;
|
||||
case 1:{
|
||||
renderer_shutdown_3d();
|
||||
}break;
|
||||
}
|
||||
}
|
||||
|
||||
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, sizeof(data->blocks), view);
|
||||
}
|
||||
|
||||
void renderer_switch(int kind) {
|
||||
renderer_shutdown();
|
||||
gfx_kind = kind;
|
||||
renderer_init();
|
||||
|
||||
game_world_view_active_entity_map(renderer_bake_chunk);
|
||||
}
|
||||
#endif
|
|
@ -7,18 +7,6 @@ static float zoom_overlay_tran = 0.0f;
|
|||
float zpl_lerp(float,float,float);
|
||||
float zpl_to_degrees(float);
|
||||
|
||||
void display_conn_status() {
|
||||
if (game_is_networked()) {
|
||||
if (network_client_is_connected()) {
|
||||
DrawText("Connection: online", 5, 5, 12, GREEN);
|
||||
} else {
|
||||
DrawText("Connection: offline", 5, 5, 12, RED);
|
||||
}
|
||||
} else {
|
||||
DrawText("Connection: single-player", 5, 5, 12, BLUE);
|
||||
}
|
||||
}
|
||||
|
||||
void DEBUG_draw_ground(uint64_t key, entity_view * data) {
|
||||
(void)key;
|
||||
switch (data->kind) {
|
||||
|
@ -45,8 +33,6 @@ void DEBUG_draw_ground(uint64_t key, entity_view * data) {
|
|||
}
|
||||
}
|
||||
|
||||
static inline float lerp(float a, float b, float t) { return a * (1.0f - t) + b * t; }
|
||||
|
||||
void DEBUG_draw_entities(uint64_t key, entity_view * data) {
|
||||
uint16_t size = 16;
|
||||
uint16_t font_size = (uint16_t)lerp(4.0f, 32.0f, 0.5f/(float)render_camera.zoom);
|
||||
|
@ -99,7 +85,7 @@ void DEBUG_draw_entities_low(uint64_t key, entity_view * data) {
|
|||
}
|
||||
}
|
||||
|
||||
void renderer_draw(void) {
|
||||
void renderer_draw_v0(void) {
|
||||
render_camera.zoom = zpl_lerp(render_camera.zoom, target_zoom, 0.18);
|
||||
camera_update();
|
||||
|
||||
|
@ -116,7 +102,7 @@ void renderer_draw(void) {
|
|||
EndMode2D();
|
||||
}
|
||||
|
||||
void renderer_init(void) {
|
||||
void renderer_init_v0(void) {
|
||||
render_camera.target = (Vector2){0.0f,0.0f};
|
||||
render_camera.offset = (Vector2){screenWidth >> 1, screenHeight >> 1};
|
||||
render_camera.rotation = 0.0f;
|
||||
|
@ -137,7 +123,7 @@ void renderer_init(void) {
|
|||
assets_setup();
|
||||
}
|
||||
|
||||
void renderer_shutdown(void) {
|
||||
void renderer_shutdown_v0(void) {
|
||||
blocks_destroy();
|
||||
assets_destroy();
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
#define RAYLIB_NEW_RLGL
|
||||
#include "rlgl.h"
|
||||
|
||||
static inline float lerp(float a, float b, float t) { return a * (1.0f - t) + b * t; }
|
||||
|
||||
static inline
|
||||
void DrawTextEco(const char *text, float posX, float posY, int fontSize, Color color, float spacing) {
|
||||
#if 1
|
||||
|
@ -327,4 +329,4 @@ Color GenerateRandomColor(float s, float v) {
|
|||
float h = GetRandomValue(0, 360);
|
||||
h = fmodf((h + h*Phi), 360.0f);
|
||||
return ColorFromHSV(h, s, v);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue