From 0d269b83e30ff68bce2e55612b69846b65e0ccb6 Mon Sep 17 00:00:00 2001 From: flameyosflow Date: Sat, 20 Dec 2025 00:50:18 +0200 Subject: [PATCH] IRTNITBTFGRDW --- game/client.c | 351 ++----------------------------------------- game/runtime.h | 21 +++ game/suic_app.c | 28 ++++ game/suic_app.h | 25 +++ game/suic_game.sui | 19 +++ game/suic_gameplay.c | 39 +++++ 6 files changed, 143 insertions(+), 340 deletions(-) create mode 100644 game/runtime.h create mode 100644 game/suic_app.c create mode 100644 game/suic_app.h create mode 100644 game/suic_game.sui create mode 100644 game/suic_gameplay.c diff --git a/game/client.c b/game/client.c index a5a5599..9ad3971 100644 --- a/game/client.c +++ b/game/client.c @@ -1,344 +1,15 @@ -#include "libsuicmez/libsuicmez.h" -#include -#include -#include -#include - -void* gc_alloc(const TypeInfo* type, size_t size); -void gc_init(void); -void gc_shutdown(void); - -// Helper for allocating arrays -static void* suic_alloc_array(const TypeInfo* type, size_t elem_size, size_t len, void* init_data) { - void* ptr = gc_alloc(type, elem_size * len); - if (init_data) memcpy(ptr, init_data, elem_size * len); - return ptr; -} - -// Helper for allocating structs -static void* suic_alloc_struct(const TypeInfo* type, size_t size, void* init_data) { - void* ptr = gc_alloc(type, size); - if (init_data) memcpy(ptr, init_data, size); - return ptr; -} - - -struct DirectionalLight { - struct Vector3* direction; - struct Vector3* color; - float intensity; - float ambientIntensity; - float shadowBias; - float shadowIntensity; -}; -struct TerrainShader { - int shader; - int locViewPos; - int locLightDir; - int locLightColor; - int locLightIntensity; - int locAmbientIntensity; - int locTerrainColor; -}; -struct MsgType_MSG_HELLO { -}; -struct MsgType_MSG_WELCOME { -}; -struct MsgType_MSG_INPUT { -}; -struct MsgType_MSG_SNAPSHOT { -}; -struct MsgType_MSG_SHOOT { -}; -struct MsgType_MSG_ITEMS { -}; -struct MsgType_MSG_ROOM_STATE { -}; -struct MsgType_union { - struct MsgType_MSG_HELLO msg_hello; - struct MsgType_MSG_WELCOME msg_welcome; - struct MsgType_MSG_INPUT msg_input; - struct MsgType_MSG_SNAPSHOT msg_snapshot; - struct MsgType_MSG_SHOOT msg_shoot; - struct MsgType_MSG_ITEMS msg_items; - struct MsgType_MSG_ROOM_STATE msg_room_state; -}; -struct MsgType { - int discriminant; - struct MsgType_union data; -}; -struct MsgHello { - uint8_t type; - struct u32* protocol; - char* username; -}; -struct MsgWelcome { - uint8_t type; - uint8_t playerId; - struct u32* serverTick; -}; -struct MsgInput { - uint8_t type; - uint8_t playerId; - struct u32* clientTick; - float moveX; - float moveZ; - float yaw; - float pitch; - uint8_t buttons; -}; -struct MsgShoot { - uint8_t type; - uint8_t playerId; - struct u32* clientTick; -}; -struct PlayerStateNet { - uint8_t id; - uint8_t alive; - struct i16* hp; - float x; - float y; - float z; - float yaw; - float pitch; - uint8_t weapon; - struct i16* pistolMag; - struct i16* rifleMag; - struct i16* pistolAmmo; - struct i16* rifleAmmo; - struct i16* medkits; - struct i16* reloadTimeLeft; - char* username; -}; -struct MsgSnapshot { - uint8_t type; - struct u32* serverTick; - uint8_t count; - struct PlayerStateNet** p; -}; -struct ItemNet { - struct u16* id; - uint8_t type; - struct i16* qty; - float x; - float y; - float z; -}; -struct MsgItems { - uint8_t type; - struct u32* serverTick; - uint8_t count; - struct ItemNet** items; -}; -struct MsgRoomState { - uint8_t type; - uint8_t state; - float countdownRemaining; - uint8_t winnerId; - char* winnerName; -}; -struct RemotePlayer { - int present; - int alive; - int hp; - struct Vector3* pos; - struct Vector3* prevPos; - float yaw; - float pitch; - uint8_t weapon; - struct i16* pistolMag; - struct i16* rifleMag; - struct i16* pistolAmmo; - struct i16* rifleAmmo; - struct i16* medkits; - struct i16* reloadTimeLeft; - char* username; -}; -struct WorldItem { - int present; - struct u16* id; - uint8_t type; - struct i16* qty; - struct Vector3* pos; -}; - -static const uint8_t sui_bitmap_DirectionalLight[] = { 1, 1, 0, 0, 0, 0 }; -static const TypeInfo sui_typeinfo_DirectionalLight = { - .field_count = 6, - .pointer_count = 2, - .pointer_bitmap = sui_bitmap_DirectionalLight -}; -static const uint8_t sui_bitmap_TerrainShader[] = { 0, 0, 0, 0, 0, 0, 0 }; -static const TypeInfo sui_typeinfo_TerrainShader = { - .field_count = 7, - .pointer_count = 0, - .pointer_bitmap = sui_bitmap_TerrainShader -}; -static const uint8_t sui_bitmap_MsgType_MSG_HELLO[] = { }; -static const TypeInfo sui_typeinfo_MsgType_MSG_HELLO = { - .field_count = 0, - .pointer_count = 0, - .pointer_bitmap = sui_bitmap_MsgType_MSG_HELLO -}; -static const uint8_t sui_bitmap_MsgType_MSG_WELCOME[] = { }; -static const TypeInfo sui_typeinfo_MsgType_MSG_WELCOME = { - .field_count = 0, - .pointer_count = 0, - .pointer_bitmap = sui_bitmap_MsgType_MSG_WELCOME -}; -static const uint8_t sui_bitmap_MsgType_MSG_INPUT[] = { }; -static const TypeInfo sui_typeinfo_MsgType_MSG_INPUT = { - .field_count = 0, - .pointer_count = 0, - .pointer_bitmap = sui_bitmap_MsgType_MSG_INPUT -}; -static const uint8_t sui_bitmap_MsgType_MSG_SNAPSHOT[] = { }; -static const TypeInfo sui_typeinfo_MsgType_MSG_SNAPSHOT = { - .field_count = 0, - .pointer_count = 0, - .pointer_bitmap = sui_bitmap_MsgType_MSG_SNAPSHOT -}; -static const uint8_t sui_bitmap_MsgType_MSG_SHOOT[] = { }; -static const TypeInfo sui_typeinfo_MsgType_MSG_SHOOT = { - .field_count = 0, - .pointer_count = 0, - .pointer_bitmap = sui_bitmap_MsgType_MSG_SHOOT -}; -static const uint8_t sui_bitmap_MsgType_MSG_ITEMS[] = { }; -static const TypeInfo sui_typeinfo_MsgType_MSG_ITEMS = { - .field_count = 0, - .pointer_count = 0, - .pointer_bitmap = sui_bitmap_MsgType_MSG_ITEMS -}; -static const uint8_t sui_bitmap_MsgType_MSG_ROOM_STATE[] = { }; -static const TypeInfo sui_typeinfo_MsgType_MSG_ROOM_STATE = { - .field_count = 0, - .pointer_count = 0, - .pointer_bitmap = sui_bitmap_MsgType_MSG_ROOM_STATE -}; -static const uint8_t sui_bitmap_MsgType_union[] = { 1, 1, 1, 1, 1, 1, 1 }; -static const TypeInfo sui_typeinfo_MsgType_union = { - .field_count = 7, - .pointer_count = 7, - .pointer_bitmap = sui_bitmap_MsgType_union -}; -static const uint8_t sui_bitmap_MsgType[] = { 0, 1 }; -static const TypeInfo sui_typeinfo_MsgType = { - .field_count = 2, - .pointer_count = 1, - .pointer_bitmap = sui_bitmap_MsgType -}; -static const uint8_t sui_bitmap_MsgHello[] = { 0, 1, 1 }; -static const TypeInfo sui_typeinfo_MsgHello = { - .field_count = 3, - .pointer_count = 2, - .pointer_bitmap = sui_bitmap_MsgHello -}; -static const uint8_t sui_bitmap_MsgWelcome[] = { 0, 0, 1 }; -static const TypeInfo sui_typeinfo_MsgWelcome = { - .field_count = 3, - .pointer_count = 1, - .pointer_bitmap = sui_bitmap_MsgWelcome -}; -static const uint8_t sui_bitmap_MsgInput[] = { 0, 0, 1, 0, 0, 0, 0, 0 }; -static const TypeInfo sui_typeinfo_MsgInput = { - .field_count = 8, - .pointer_count = 1, - .pointer_bitmap = sui_bitmap_MsgInput -}; -static const uint8_t sui_bitmap_MsgShoot[] = { 0, 0, 1 }; -static const TypeInfo sui_typeinfo_MsgShoot = { - .field_count = 3, - .pointer_count = 1, - .pointer_bitmap = sui_bitmap_MsgShoot -}; -static const uint8_t sui_bitmap_PlayerStateNet[] = { 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1 }; -static const TypeInfo sui_typeinfo_PlayerStateNet = { - .field_count = 16, - .pointer_count = 8, - .pointer_bitmap = sui_bitmap_PlayerStateNet -}; -static const uint8_t sui_bitmap_MsgSnapshot[] = { 0, 1, 0, 0 }; -static const TypeInfo sui_typeinfo_MsgSnapshot = { - .field_count = 4, - .pointer_count = 1, - .pointer_bitmap = sui_bitmap_MsgSnapshot -}; -static const uint8_t sui_bitmap_ItemNet[] = { 1, 0, 1, 0, 0, 0 }; -static const TypeInfo sui_typeinfo_ItemNet = { - .field_count = 6, - .pointer_count = 2, - .pointer_bitmap = sui_bitmap_ItemNet -}; -static const uint8_t sui_bitmap_MsgItems[] = { 0, 1, 0, 0 }; -static const TypeInfo sui_typeinfo_MsgItems = { - .field_count = 4, - .pointer_count = 1, - .pointer_bitmap = sui_bitmap_MsgItems -}; -static const uint8_t sui_bitmap_MsgRoomState[] = { 0, 0, 0, 0, 1 }; -static const TypeInfo sui_typeinfo_MsgRoomState = { - .field_count = 5, - .pointer_count = 1, - .pointer_bitmap = sui_bitmap_MsgRoomState -}; -static const uint8_t sui_bitmap_RemotePlayer[] = { 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1 }; -static const TypeInfo sui_typeinfo_RemotePlayer = { - .field_count = 15, - .pointer_count = 9, - .pointer_bitmap = sui_bitmap_RemotePlayer -}; -static const uint8_t sui_bitmap_WorldItem[] = { 0, 1, 0, 1, 1 }; -static const TypeInfo sui_typeinfo_WorldItem = { - .field_count = 5, - .pointer_count = 3, - .pointer_bitmap = sui_bitmap_WorldItem -}; - -char* item_name(uint8_t t); -struct Color* apply_directional_lighting(struct Color* baseColor, struct Vector3* normal, struct DirectionalLight* light); -int suic_main(void); - - -char* item_name(uint8_t t) { - return ((t == 1) ? suic_alloc_array(NULL, sizeof(char), 7, "Medkit") : ((t == 2) ? suic_alloc_array(NULL, sizeof(char), 12, "Pistol ammo") : ((t == 3) ? suic_alloc_array(NULL, sizeof(char), 11, "Rifle ammo") : suic_alloc_array(NULL, sizeof(char), 2, "-")))); -} - -struct Color* apply_directional_lighting(struct Color* baseColor, struct Vector3* normal, struct DirectionalLight* light) { - struct Vector3* lightDir = (*light).direction; - float diff = fmaxf(0.000000, -((((*lightDir).x * (*normal).x) + ((*lightDir).y * (*normal).y)) + ((*lightDir).z * (*normal).z))); - float brightness = ((*light).ambientIntensity + ((diff * (*light).intensity) * (1.000000 - (*light).ambientIntensity))); - uint8_t r = (uint8_t) ((float) (*baseColor).r * brightness); - uint8_t g = (uint8_t) ((float) (*baseColor).g * brightness); - uint8_t b = (uint8_t) ((float) (*baseColor).b * brightness); - return suic_alloc_struct(&sui_typeinfo_Color, sizeof(struct Color), &(struct Color){ .r = r, .g = g, .b = b, .a = (*baseColor).a }); -} +#include "suic_app.h" +#include "runtime.h" int suic_main(void) { - int sw = 1280; - int sh = 720; - suic_init_window(sw, sh, suic_alloc_array(NULL, sizeof(char), 23, "Voxel Shooter - Client")); - suic_set_target_fps(120); - suic_disable_cursor(); - while ((suic_window_should_close() == false)) { - suic_begin_drawing(); - suic_clear_background(135, 206, 235, 255); - suic_draw_text(suic_alloc_array(NULL, sizeof(char), 14, "Hello Suicmez"), 10, 10, 20, 255, 255, 255, 255); - draw_fps(10, 40); - suic_end_drawing(); + suic_app_init(1280, 720, "Voxel Shooter - Client"); + + while (!suic_app_should_close()) { + suic_app_frame_begin(); + suic_draw_hello(); // gameplay / UI call + suic_app_frame_end(); } - suic_close_window(); + + suic_app_shutdown(); return 0; -} - -int main(int argc, char* argv[]) { - // Initialize GC - gc_init(); - // init globals - // init event loop - int result = suic_main(); - // Shutdown GC - gc_shutdown(); - return result; -} - +} \ No newline at end of file diff --git a/game/runtime.h b/game/runtime.h new file mode 100644 index 0000000..8e97b2f --- /dev/null +++ b/game/runtime.h @@ -0,0 +1,21 @@ +#include +#include +#include "../libsuicmez/suicmez_gc.h" + +void* gc_alloc(const TypeInfo* type, size_t size); +void gc_init(void); +void gc_shutdown(void); + +// Helper for allocating arrays +void* suic_alloc_array(const TypeInfo* type, size_t elem_size, size_t len, void* init_data) { + void* ptr = gc_alloc(type, elem_size * len); + if (init_data) memcpy(ptr, init_data, elem_size * len); + return ptr; +} + +// Helper for allocating structs +void* suic_alloc_struct(const TypeInfo* type, size_t size, void* init_data) { + void* ptr = gc_alloc(type, size); + if (init_data) memcpy(ptr, init_data, size); + return ptr; +} \ No newline at end of file diff --git a/game/suic_app.c b/game/suic_app.c new file mode 100644 index 0000000..c024e0c --- /dev/null +++ b/game/suic_app.c @@ -0,0 +1,28 @@ +#include "suic_app.h" +#include "../libsuicmez/libsuicmez.h" +#include "runtime.h" + +void suic_app_init(int width, int height, const char* title) { + suic_init_window(width, height, (char*)title); + suic_set_target_fps(120); + suic_disable_cursor(); +} + +bool suic_app_should_close(void) { + return suic_window_should_close(); +} + +void suic_app_frame_begin(void) { + suic_begin_drawing(); + suic_clear_background(135, 206, 235, 255); +} + +void suic_app_frame_end(void) { + draw_fps(10, 40); + suic_end_drawing(); +} + +void suic_app_shutdown(void) { + suic_close_window(); +} + diff --git a/game/suic_app.h b/game/suic_app.h new file mode 100644 index 0000000..f7a5cb6 --- /dev/null +++ b/game/suic_app.h @@ -0,0 +1,25 @@ +#pragma once +#include +#include + +/* ---- Lifecycle ---- */ +void suic_runtime_init(void); +void suic_runtime_shutdown(void); + +/* ---- Window / Loop ---- */ +void suic_app_init(int width, int height, const char* title); +bool suic_app_should_close(void); +void suic_app_frame_begin(void); +void suic_app_frame_end(void); +void suic_app_shutdown(void); + +/* ---- Drawing ---- */ +void suic_draw_hello(void); + +/* ---- Gameplay helpers ---- */ +const char* suic_item_name(uint8_t t); +struct Color* suic_apply_directional_lighting( + struct Color* baseColor, + struct Vector3* normal, + struct DirectionalLight* light +); diff --git a/game/suic_game.sui b/game/suic_game.sui new file mode 100644 index 0000000..114b231 --- /dev/null +++ b/game/suic_game.sui @@ -0,0 +1,19 @@ +fn main() -> int do + suic_runtime_init() + defer suic_runtime_shutdown() + + # Initialize application / window + suic_app_init(1280, 720, "Voxel Shooter - Client") + defer suic_app_shutdown() + + # Main loop + while not suic_app_should_close() do + suic_app_frame_begin() + + suic_draw_hello() + + suic_app_frame_end() + end + + 0 +end diff --git a/game/suic_gameplay.c b/game/suic_gameplay.c new file mode 100644 index 0000000..9ec4781 --- /dev/null +++ b/game/suic_gameplay.c @@ -0,0 +1,39 @@ +#include "suic_app.h" +#include "runtime.h" +#include + +const char* suic_item_name(uint8_t t) { + if (t == 1) return "Medkit"; + if (t == 2) return "Pistol ammo"; + if (t == 3) return "Rifle ammo"; + return "-"; +} + +struct Color* suic_apply_directional_lighting( + struct Color* baseColor, + struct Vector3* normal, + struct DirectionalLight* light +) { + struct Vector3* lightDir = light->direction; + + float diff = fmaxf( + 0.0f, + -(lightDir->x * normal->x + + lightDir->y * normal->y + + lightDir->z * normal->z) + ); + + float brightness = + light->ambientIntensity + + diff * light->intensity * (1.0f - light->ambientIntensity); + + uint8_t r = (uint8_t)(baseColor->r * brightness); + uint8_t g = (uint8_t)(baseColor->g * brightness); + uint8_t b = (uint8_t)(baseColor->b * brightness); + + return suic_alloc_struct( + &sui_typeinfo_Color, + sizeof(struct Color), + &(struct Color){ r, g, b, baseColor->a } + ); +} \ No newline at end of file