eco2d/code/games/minimal/src/platform.c

114 lines
2.8 KiB
C
Raw Normal View History

2022-09-27 14:19:57 +00:00
#include "platform/platform.h"
#include "raylib.h"
#include "raymath.h"
#include "net/network.h"
#include "core/game.h"
#include "world/entity_view.h"
#include "world/prediction.h"
#include "core/camera.h"
#include "math.h"
#include "world/blocks.h"
2022-09-29 18:11:47 +00:00
#include "models/assets.h"
2022-09-27 14:19:57 +00:00
#include "platform/profiler.h"
2023-01-15 15:59:33 +00:00
#include "dev/debug_ui.h"
2022-09-27 14:19:57 +00:00
#include "utils/raylib_helpers.h"
2022-09-29 11:59:51 +00:00
#include "platform/renderer.h"
2022-09-27 14:19:57 +00:00
2023-01-15 19:21:56 +00:00
ZPL_DIAGNOSTIC_PUSH_WARNLEVEL(0)
#include "raylib-nuklear.h"
ZPL_DIAGNOSTIC_POP
2022-09-29 11:59:51 +00:00
#define ARCH_IMPL
#include "platform/arch.h"
2022-09-27 14:19:57 +00:00
2023-01-16 08:51:57 +00:00
#include "gui/tooltip.c"
2023-02-02 12:24:16 +00:00
#include "gui/notifications.c"
2023-01-16 08:51:57 +00:00
2022-09-28 05:29:32 +00:00
#include "renderer.c"
2022-09-27 14:19:57 +00:00
void platform_init() {
2022-09-29 11:59:51 +00:00
platform_create_window("minimal-demo");
2022-09-27 14:19:57 +00:00
renderer_init();
}
void platform_shutdown() {
renderer_shutdown();
CloseWindow();
}
void platform_input() {
float mouse_z = (GetMouseWheelMove()*0.5f);
2022-09-28 20:01:47 +00:00
float mouse_modified = target_zoom < 4 ? mouse_z / (zpl_exp(4 - (target_zoom))) : mouse_z;
2022-09-27 14:19:57 +00:00
if (mouse_z != 0.0f) {
2022-09-28 20:01:47 +00:00
target_zoom = zpl_clamp(target_zoom + mouse_modified, 0.1f, 11.0f);
2022-09-27 14:19:57 +00:00
}
2022-09-28 20:01:47 +00:00
2022-09-27 14:19:57 +00:00
// NOTE(zaklaus): keystate handling
{
float x=0.0f, y=0.0f;
2022-09-29 11:59:51 +00:00
uint8_t use, sprint, ctrl;
2022-09-27 14:19:57 +00:00
if (IsKeyDown(KEY_RIGHT) || IsKeyDown(KEY_D)) x += 1.0f;
if (IsKeyDown(KEY_LEFT) || IsKeyDown(KEY_A)) x -= 1.0f;
if (IsKeyDown(KEY_UP) || IsKeyDown(KEY_W)) y += 1.0f;
if (IsKeyDown(KEY_DOWN) || IsKeyDown(KEY_S)) y -= 1.0f;
use = IsKeyPressed(KEY_SPACE);
sprint = IsKeyDown(KEY_LEFT_SHIFT) || IsKeyDown(KEY_RIGHT_SHIFT);
ctrl = IsKeyDown(KEY_LEFT_CONTROL) || IsKeyDown(KEY_RIGHT_CONTROL);
// NOTE(zaklaus): NEW! mouse movement
Vector2 mouse_pos = GetMousePosition();
mouse_pos.x /= screenWidth;
mouse_pos.y /= screenHeight;
mouse_pos.x -= 0.5f;
mouse_pos.y -= 0.5f;
mouse_pos = Vector2Normalize(mouse_pos);
if (game_get_kind() == GAMEKIND_SINGLE && IsMouseButtonDown(MOUSE_MIDDLE_BUTTON)) {
x = mouse_pos.x;
y = -mouse_pos.y;
}
game_keystate_data in_data = {
.x = x,
.y = y,
.mx = mouse_pos.x,
.my = mouse_pos.y,
.use = use,
.sprint = sprint,
.ctrl = ctrl,
};
platform_input_update_input_frame(in_data);
}
}
void platform_render() {
2022-09-29 11:59:51 +00:00
platform_resize_window();
2022-09-27 14:19:57 +00:00
profile(PROF_ENTITY_LERP) {
game_world_view_active_entity_map(lerp_entity_positions);
game_world_view_active_entity_map(do_entity_fadeinout);
}
assets_frame();
2022-09-27 14:19:57 +00:00
BeginDrawing();
{
profile (PROF_RENDER) {
renderer_draw();
}
debug_draw();
2023-02-02 13:17:53 +00:00
notification_draw();
2023-01-15 19:21:56 +00:00
game_draw_ui();
2022-09-27 14:19:57 +00:00
}
EndDrawing();
if (request_shutdown) {
CloseWindow();
}
}