IRTNITBTFGRDW

This commit is contained in:
flameyosflow 2025-12-20 00:50:18 +02:00
commit 0d269b83e3
6 changed files with 143 additions and 340 deletions

View file

@ -1,344 +1,15 @@
#include "libsuicmez/libsuicmez.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
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;
}
}

21
game/runtime.h Normal file
View file

@ -0,0 +1,21 @@
#include <stdlib.h>
#include <string.h>
#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;
}

28
game/suic_app.c Normal file
View file

@ -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();
}

25
game/suic_app.h Normal file
View file

@ -0,0 +1,25 @@
#pragma once
#include <stdint.h>
#include <stdbool.h>
/* ---- 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
);

19
game/suic_game.sui Normal file
View file

@ -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

39
game/suic_gameplay.c Normal file
View file

@ -0,0 +1,39 @@
#include "suic_app.h"
#include "runtime.h"
#include <math.h>
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 }
);
}