2021-01-11 20:11:03 +00:00
|
|
|
#include "platform.h"
|
2021-01-10 16:42:01 +00:00
|
|
|
#include "raylib.h"
|
2021-05-07 22:11:09 +00:00
|
|
|
#include "raymath.h"
|
2021-05-05 09:25:05 +00:00
|
|
|
#include "network.h"
|
2021-05-04 20:44:55 +00:00
|
|
|
#include "game.h"
|
2021-05-05 09:25:05 +00:00
|
|
|
#include "entity_view.h"
|
2021-05-09 10:27:10 +00:00
|
|
|
#include "prediction.h"
|
2021-05-05 10:14:52 +00:00
|
|
|
#include "camera.h"
|
2021-05-08 15:42:47 +00:00
|
|
|
#include "math.h"
|
2021-05-12 16:28:39 +00:00
|
|
|
#include "world/blocks.h"
|
2021-05-12 17:26:41 +00:00
|
|
|
#include "assets.h"
|
2021-05-13 12:17:44 +00:00
|
|
|
#include "profiler.h"
|
|
|
|
#include "debug_ui.h"
|
2021-05-12 14:42:22 +00:00
|
|
|
#include "utils/raylib_helpers.h"
|
2021-01-10 16:42:01 +00:00
|
|
|
|
2021-05-14 05:59:33 +00:00
|
|
|
static uint16_t screenWidth = 1600;
|
|
|
|
static uint16_t screenHeight = 900;
|
2021-05-15 11:43:29 +00:00
|
|
|
static float target_zoom = 1.5f;
|
2021-05-14 05:59:33 +00:00
|
|
|
static float zoom_overlay_tran = 0.0f;
|
|
|
|
static bool request_shutdown;
|
2021-05-12 13:30:44 +00:00
|
|
|
|
|
|
|
#define CAM_OVERLAY_ZOOM_LEVEL 0.80f
|
2021-05-08 00:21:27 +00:00
|
|
|
|
2021-08-11 12:16:23 +00:00
|
|
|
#include "renderer_v0.c"
|
|
|
|
|
2021-01-11 20:11:03 +00:00
|
|
|
void platform_init() {
|
2021-01-11 13:47:14 +00:00
|
|
|
InitWindow(screenWidth, screenHeight, "eco2d - client");
|
2021-05-09 10:27:10 +00:00
|
|
|
SetWindowState(FLAG_WINDOW_UNDECORATED|FLAG_WINDOW_MAXIMIZED|FLAG_WINDOW_RESIZABLE);
|
2021-08-10 22:02:11 +00:00
|
|
|
|
2021-07-28 09:49:09 +00:00
|
|
|
SetTargetFPS(0);
|
2021-05-05 10:14:52 +00:00
|
|
|
|
2021-05-08 16:38:33 +00:00
|
|
|
screenWidth = GetScreenWidth();
|
|
|
|
screenHeight = GetScreenHeight();
|
|
|
|
|
2021-08-11 12:23:40 +00:00
|
|
|
renderer_init();
|
2021-01-10 16:42:01 +00:00
|
|
|
}
|
|
|
|
|
2021-01-11 20:11:03 +00:00
|
|
|
void platform_shutdown() {
|
2021-08-11 12:23:40 +00:00
|
|
|
renderer_shutdown();
|
2021-01-10 16:42:01 +00:00
|
|
|
CloseWindow();
|
|
|
|
}
|
2021-07-18 11:23:59 +00:00
|
|
|
|
2021-01-11 20:11:03 +00:00
|
|
|
uint8_t platform_is_running() {
|
2021-01-11 20:08:16 +00:00
|
|
|
return !WindowShouldClose();
|
|
|
|
}
|
|
|
|
|
2021-05-07 12:27:51 +00:00
|
|
|
void platform_input() {
|
2021-05-09 19:12:11 +00:00
|
|
|
float mouse_z = (GetMouseWheelMove()*0.5f);
|
2021-05-07 12:27:51 +00:00
|
|
|
|
|
|
|
if (mouse_z != 0.0f) {
|
2021-05-15 11:43:29 +00:00
|
|
|
target_zoom = zpl_clamp(target_zoom+mouse_z, 0.1f, 10.0f);
|
2021-05-07 12:27:51 +00:00
|
|
|
}
|
2021-05-07 14:43:54 +00:00
|
|
|
|
|
|
|
// NOTE(zaklaus): keystate handling
|
|
|
|
{
|
2021-05-08 15:42:47 +00:00
|
|
|
float x=0.0f, y=0.0f;
|
2021-05-07 20:48:15 +00:00
|
|
|
uint8_t use, sprint;
|
2021-05-07 14:43:54 +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);
|
2021-05-07 20:48:15 +00:00
|
|
|
sprint = IsKeyDown(KEY_LEFT_SHIFT) || IsKeyDown(KEY_RIGHT_SHIFT);
|
2021-05-07 14:43:54 +00:00
|
|
|
|
2021-05-07 22:11:09 +00:00
|
|
|
// NOTE(zaklaus): NEW! mouse movement
|
|
|
|
if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON)) {
|
|
|
|
Vector2 mouse_pos = GetMousePosition();
|
|
|
|
mouse_pos.x /= screenWidth;
|
|
|
|
mouse_pos.y /= screenHeight;
|
2021-05-08 16:38:33 +00:00
|
|
|
mouse_pos.x -= 0.5f;
|
|
|
|
mouse_pos.y -= 0.5f;
|
|
|
|
mouse_pos = Vector2Normalize(mouse_pos);
|
|
|
|
x = mouse_pos.x;
|
|
|
|
y = mouse_pos.y;
|
2021-05-07 22:11:09 +00:00
|
|
|
}
|
|
|
|
|
2021-05-07 20:48:15 +00:00
|
|
|
game_action_send_keystate(x, y, use, sprint);
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE(zaklaus): cycle through viewers
|
|
|
|
{
|
|
|
|
if (IsKeyPressed(KEY_Q)) {
|
|
|
|
game_world_view_cycle_active(-1);
|
|
|
|
}
|
|
|
|
else if (IsKeyPressed(KEY_E)) {
|
|
|
|
game_world_view_cycle_active(1);
|
|
|
|
}
|
2021-05-07 14:43:54 +00:00
|
|
|
}
|
2021-05-07 12:27:51 +00:00
|
|
|
}
|
|
|
|
|
2021-01-11 20:11:03 +00:00
|
|
|
void platform_render() {
|
2021-05-13 12:17:44 +00:00
|
|
|
profile(PROF_ENTITY_LERP) {
|
|
|
|
game_world_view_active_entity_map(lerp_entity_positions);
|
|
|
|
game_world_view_active_entity_map(do_entity_fadeinout);
|
|
|
|
}
|
2021-07-18 11:23:59 +00:00
|
|
|
|
2021-08-11 12:16:23 +00:00
|
|
|
renderer_draw();
|
2021-05-13 14:12:18 +00:00
|
|
|
|
|
|
|
if (request_shutdown) {
|
|
|
|
CloseWindow();
|
|
|
|
}
|
2021-01-10 16:42:01 +00:00
|
|
|
}
|
2021-05-04 20:44:55 +00:00
|
|
|
|
2021-08-11 12:16:23 +00:00
|
|
|
float platform_frametime() {
|
|
|
|
return GetFrameTime();
|
2021-05-05 09:25:05 +00:00
|
|
|
}
|
|
|
|
|
2021-08-11 12:16:23 +00:00
|
|
|
float platform_zoom_get(void) {
|
|
|
|
return target_zoom;
|
2021-05-06 21:45:55 +00:00
|
|
|
}
|
|
|
|
|
2021-08-11 12:16:23 +00:00
|
|
|
void platform_request_close(void) {
|
|
|
|
request_shutdown = true;
|
2021-08-10 18:31:05 +00:00
|
|
|
}
|