2025-12-16 14:51:45 +05:30
|
|
|
#ifndef LIBSUICMEZ_H
|
|
|
|
|
#define LIBSUICMEZ_H
|
|
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <stdint.h>
|
2025-12-17 13:16:53 +05:30
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
2025-12-17 15:38:06 +05:30
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
|
|
// Include GC header for TypeInfo
|
|
|
|
|
#include "suicmez_gc.h"
|
2025-12-16 14:51:45 +05:30
|
|
|
|
2025-12-17 13:16:53 +05:30
|
|
|
// Raylib support
|
2025-12-16 14:51:45 +05:30
|
|
|
#include "raylib.h"
|
|
|
|
|
|
2025-12-17 13:16:53 +05:30
|
|
|
// ODE support
|
|
|
|
|
#include <ode/ode.h>
|
|
|
|
|
|
2025-12-20 17:11:21 +05:30
|
|
|
// Internal game headers
|
|
|
|
|
#include "../game/inc/suic_math.h"
|
|
|
|
|
#include "../game/inc/suic_net.h"
|
|
|
|
|
#include "../game/inc/suic_ui.h"
|
|
|
|
|
#include "../game/inc/suic_terrain.h"
|
|
|
|
|
#include "../game/inc/suic_lighting.h"
|
2025-12-17 18:32:29 +05:30
|
|
|
|
2025-12-17 13:16:53 +05:30
|
|
|
// Logging levels
|
2025-12-16 14:51:45 +05:30
|
|
|
typedef enum suic_log_level {
|
|
|
|
|
SUIC_LOG_ALL = 0,
|
|
|
|
|
SUIC_LOG_INFO = 1,
|
|
|
|
|
SUIC_LOG_WARN = 2,
|
|
|
|
|
SUIC_LOG_ERROR = 3,
|
|
|
|
|
SUIC_LOG_NONE = 4
|
|
|
|
|
} suic_log_level;
|
|
|
|
|
|
2025-12-17 13:16:53 +05:30
|
|
|
// Error handling
|
2025-12-16 14:51:45 +05:30
|
|
|
const char *suic_last_error(void);
|
|
|
|
|
void suic_clear_error(void);
|
|
|
|
|
void suic_set_log_level(suic_log_level level);
|
|
|
|
|
|
2025-12-17 13:16:53 +05:30
|
|
|
// Vec types
|
2025-12-16 14:51:45 +05:30
|
|
|
typedef struct suic_vec2 {
|
|
|
|
|
float x, y;
|
|
|
|
|
} suic_vec2;
|
|
|
|
|
|
|
|
|
|
typedef struct suic_vec3 {
|
|
|
|
|
float x, y, z;
|
|
|
|
|
} suic_vec3;
|
|
|
|
|
|
2025-12-17 13:16:53 +05:30
|
|
|
// Vector conversion helpers
|
2025-12-16 14:51:45 +05:30
|
|
|
static inline Vector2 suic_to_rl_vec2(suic_vec2 v) {
|
|
|
|
|
return (Vector2){v.x, v.y};
|
|
|
|
|
}
|
2025-12-17 13:16:53 +05:30
|
|
|
|
2025-12-16 14:51:45 +05:30
|
|
|
static inline Vector3 suic_to_rl_vec3(suic_vec3 v) {
|
|
|
|
|
return (Vector3){v.x, v.y, v.z};
|
|
|
|
|
}
|
2025-12-17 13:16:53 +05:30
|
|
|
|
2025-12-16 14:51:45 +05:30
|
|
|
static inline suic_vec2 suic_from_rl_vec2(Vector2 v) {
|
|
|
|
|
return (suic_vec2){v.x, v.y};
|
|
|
|
|
}
|
2025-12-17 13:16:53 +05:30
|
|
|
|
2025-12-16 14:51:45 +05:30
|
|
|
static inline suic_vec3 suic_from_rl_vec3(Vector3 v) {
|
|
|
|
|
return (suic_vec3){v.x, v.y, v.z};
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-17 15:38:06 +05:30
|
|
|
// Keyboard key constants (from raylib)
|
|
|
|
|
#define KEY_W 87
|
|
|
|
|
#define KEY_A 65
|
|
|
|
|
#define KEY_S 83
|
|
|
|
|
#define KEY_D 68
|
|
|
|
|
#define KEY_SPACE 32
|
|
|
|
|
#define KEY_LEFT_SHIFT 341
|
|
|
|
|
#define KEY_LEFT_CTRL 341 // Platform dependent
|
|
|
|
|
#define KEY_LEFT_ALT 342
|
|
|
|
|
#define KEY_UP 265
|
|
|
|
|
#define KEY_DOWN 264
|
|
|
|
|
#define KEY_LEFT 263
|
|
|
|
|
#define KEY_RIGHT 262
|
|
|
|
|
#define KEY_ESCAPE 256
|
|
|
|
|
#define KEY_ENTER 257
|
|
|
|
|
#define KEY_TAB 258
|
|
|
|
|
#define KEY_BACKSPACE 259
|
|
|
|
|
#define KEY_DELETE 261
|
|
|
|
|
#define KEY_HOME 268
|
|
|
|
|
#define KEY_END 269
|
|
|
|
|
#define KEY_EQUAL 61
|
|
|
|
|
#define KEY_MINUS 45
|
|
|
|
|
#define KEY_KP_ADD 334
|
|
|
|
|
#define KEY_KP_SUBTRACT 333
|
|
|
|
|
#define KEY_F1 290
|
2025-12-17 16:54:18 +05:30
|
|
|
#define KEY_F2 291
|
|
|
|
|
#define KEY_F3 292
|
2025-12-17 15:38:06 +05:30
|
|
|
|
|
|
|
|
// Mouse button constants
|
|
|
|
|
#define MOUSE_LEFT 0
|
|
|
|
|
#define MOUSE_RIGHT 1
|
|
|
|
|
#define MOUSE_MIDDLE 2
|
|
|
|
|
|
2025-12-17 13:16:53 +05:30
|
|
|
// Window management
|
2025-12-16 14:51:45 +05:30
|
|
|
bool suic_init_window(int width, int height, const char *title);
|
|
|
|
|
void suic_close_window(void);
|
|
|
|
|
bool suic_window_should_close(void);
|
|
|
|
|
void suic_set_target_fps(int fps);
|
2025-12-17 15:38:06 +05:30
|
|
|
void suic_enable_msaa_4x(void);
|
2025-12-20 17:11:21 +05:30
|
|
|
int suic_get_screen_width(void);
|
|
|
|
|
int suic_get_screen_height(void);
|
2025-12-16 14:51:45 +05:30
|
|
|
|
2025-12-17 16:54:18 +05:30
|
|
|
// Timing
|
|
|
|
|
float suic_get_frame_time(void);
|
|
|
|
|
|
|
|
|
|
// FPS meter
|
|
|
|
|
void suic_show_fps_meter(suic_vec2 position);
|
|
|
|
|
void suic_hide_fps_meter(void);
|
|
|
|
|
|
2025-12-17 13:16:53 +05:30
|
|
|
// Drawing (2D)
|
2025-12-16 14:51:45 +05:30
|
|
|
void suic_begin_drawing(void);
|
|
|
|
|
void suic_end_drawing(void);
|
2025-12-17 13:16:53 +05:30
|
|
|
void suic_clear_background(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
|
2025-12-16 14:51:45 +05:30
|
|
|
|
2025-12-17 13:16:53 +05:30
|
|
|
// 3D Camera
|
2025-12-16 14:51:45 +05:30
|
|
|
typedef struct suic_camera3d {
|
|
|
|
|
suic_vec3 position;
|
|
|
|
|
suic_vec3 target;
|
|
|
|
|
suic_vec3 up;
|
|
|
|
|
float fovy;
|
2025-12-17 13:16:53 +05:30
|
|
|
int projection; // CameraProjection
|
2025-12-16 14:51:45 +05:30
|
|
|
} suic_camera3d;
|
|
|
|
|
|
|
|
|
|
Camera3D suic_to_rl_camera3d(suic_camera3d cam);
|
2025-12-17 13:16:53 +05:30
|
|
|
void suic_begin_mode3d(float pos_x, float pos_y, float pos_z, float target_x, float target_y, float target_z, float up_x, float up_y, float up_z, float fovy, int projection);
|
2025-12-16 14:51:45 +05:30
|
|
|
void suic_end_mode3d(void);
|
|
|
|
|
|
2025-12-17 13:16:53 +05:30
|
|
|
// 3D Drawing
|
|
|
|
|
void suic_draw_cube(float x, float y, float z, float width, float height, float length, unsigned char r, unsigned char g, unsigned char b, unsigned char a);
|
|
|
|
|
void suic_draw_cube_wires(float x, float y, float z, float width, float height, float length, unsigned char r, unsigned char g, unsigned char b, unsigned char a);
|
2025-12-20 17:11:21 +05:30
|
|
|
void suic_draw_sphere(float x, float y, float z, float radius, unsigned char r, unsigned char g, unsigned char b, unsigned char a);
|
|
|
|
|
void suic_draw_capsule(float start_x, float start_y, float start_z, float end_x, float end_y, float end_z, float radius, int slices, int rings, unsigned char r, unsigned char g, unsigned char b, unsigned char a);
|
2025-12-17 13:16:53 +05:30
|
|
|
|
2025-12-17 20:07:00 +05:30
|
|
|
// 2D Drawing (UI Framework Utils)
|
|
|
|
|
void suic_draw_text(const char *text, int x, int y, int font_size, unsigned char r, unsigned char g, unsigned char b, unsigned char a);
|
|
|
|
|
void suic_draw_rectangle(int x, int y, int width, int height, unsigned char r, unsigned char g, unsigned char b, unsigned char a);
|
|
|
|
|
void suic_draw_rectangle_lines(int x, int y, int width, int height, unsigned char r, unsigned char g, unsigned char b, unsigned char a);
|
|
|
|
|
int suic_measure_text(const char *text, int font_size);
|
|
|
|
|
void suic_draw_circle(int center_x, int center_y, float radius, unsigned char r, unsigned char g, unsigned char b, unsigned char a);
|
|
|
|
|
void suic_draw_line(int start_x, int start_y, int end_x, int end_y, unsigned char r, unsigned char g, unsigned char b, unsigned char a);
|
2025-12-20 17:11:21 +05:30
|
|
|
void suic_draw_fps(int x, int y);
|
2025-12-17 20:07:00 +05:30
|
|
|
|
2025-12-17 15:38:06 +05:30
|
|
|
// Input - Keyboard
|
2025-12-16 14:51:45 +05:30
|
|
|
bool suic_is_key_down(int key);
|
2025-12-17 15:38:06 +05:30
|
|
|
bool suic_is_key_pressed(int key);
|
|
|
|
|
bool suic_is_key_released(int key);
|
|
|
|
|
|
|
|
|
|
// Input - Mouse
|
2025-12-16 14:51:45 +05:30
|
|
|
bool suic_is_mouse_button_down(int b);
|
2025-12-17 15:38:06 +05:30
|
|
|
bool suic_is_mouse_button_pressed(int b);
|
|
|
|
|
bool suic_is_mouse_button_released(int b);
|
2025-12-16 14:51:45 +05:30
|
|
|
suic_vec2 suic_get_mouse_position(void);
|
2025-12-17 15:38:06 +05:30
|
|
|
suic_vec2 suic_get_mouse_delta(void);
|
|
|
|
|
float suic_get_mouse_x(void);
|
|
|
|
|
float suic_get_mouse_y(void);
|
|
|
|
|
float suic_get_mouse_delta_x(void);
|
|
|
|
|
float suic_get_mouse_delta_y(void);
|
|
|
|
|
|
|
|
|
|
// Input - Helper functions for gamedev
|
|
|
|
|
int suic_is_movement_input(void); // Returns bitmask: 1=W, 2=A, 4=S, 8=D
|
|
|
|
|
int suic_is_sprint_held(void);
|
|
|
|
|
int suic_is_jump_pressed(void);
|
|
|
|
|
|
2025-12-20 17:11:21 +05:30
|
|
|
// Random number generation
|
|
|
|
|
int suic_get_random_value(int min, int max);
|
|
|
|
|
|
2025-12-17 15:38:06 +05:30
|
|
|
// Cursor management
|
|
|
|
|
void suic_disable_cursor(void);
|
|
|
|
|
void suic_enable_cursor(void);
|
|
|
|
|
bool suic_is_cursor_hidden(void);
|
|
|
|
|
|
|
|
|
|
// Matrix operations for 3D transformations
|
|
|
|
|
void suic_rl_push_matrix(void);
|
|
|
|
|
void suic_rl_pop_matrix(void);
|
|
|
|
|
void suic_rl_translate_f(float x, float y, float z);
|
|
|
|
|
void suic_rl_rotate_f(float angle, float x, float y, float z);
|
2025-12-16 14:51:45 +05:30
|
|
|
|
2025-12-17 13:16:53 +05:30
|
|
|
// Images and Textures
|
2025-12-16 14:51:45 +05:30
|
|
|
typedef struct suic_image_handle {
|
|
|
|
|
Image value;
|
|
|
|
|
bool valid;
|
|
|
|
|
} suic_image_handle;
|
2025-12-17 13:16:53 +05:30
|
|
|
|
2025-12-16 14:51:45 +05:30
|
|
|
typedef struct suic_texture_handle {
|
|
|
|
|
Texture2D value;
|
|
|
|
|
bool valid;
|
|
|
|
|
} suic_texture_handle;
|
|
|
|
|
|
|
|
|
|
suic_image_handle suic_image_load(const char *path);
|
|
|
|
|
void suic_image_free(suic_image_handle *img);
|
|
|
|
|
|
|
|
|
|
suic_texture_handle suic_texture_load(const char *path);
|
|
|
|
|
suic_texture_handle suic_texture_from_image(suic_image_handle img);
|
|
|
|
|
void suic_texture_free(suic_texture_handle *tex);
|
|
|
|
|
void suic_draw_texture(suic_texture_handle tex, int x, int y, unsigned char r,
|
|
|
|
|
unsigned char g, unsigned char b, unsigned char a);
|
|
|
|
|
|
2025-12-17 13:16:53 +05:30
|
|
|
// Audio
|
|
|
|
|
bool suic_audio_init(void);
|
|
|
|
|
void suic_audio_close(void);
|
2025-12-16 14:51:45 +05:30
|
|
|
|
|
|
|
|
typedef struct suic_sound_handle {
|
|
|
|
|
Sound value;
|
|
|
|
|
bool valid;
|
|
|
|
|
} suic_sound_handle;
|
|
|
|
|
|
|
|
|
|
suic_sound_handle suic_sound_load(const char *path);
|
|
|
|
|
void suic_sound_play(suic_sound_handle snd);
|
|
|
|
|
void suic_sound_set_volume(suic_sound_handle snd, float volume);
|
|
|
|
|
void suic_sound_free(suic_sound_handle *snd);
|
|
|
|
|
|
2025-12-17 15:38:06 +05:30
|
|
|
// Player controller for FPS-style movement
|
|
|
|
|
typedef struct suic_player_controller {
|
|
|
|
|
suic_vec3 position;
|
|
|
|
|
suic_vec3 velocity;
|
|
|
|
|
suic_vec3 forward; // Camera forward direction
|
|
|
|
|
suic_vec3 right; // Camera right direction
|
|
|
|
|
float move_speed;
|
|
|
|
|
float sprint_speed;
|
|
|
|
|
float jump_force;
|
|
|
|
|
float gravity;
|
|
|
|
|
int is_grounded;
|
|
|
|
|
} suic_player_controller;
|
|
|
|
|
|
2025-12-17 13:16:53 +05:30
|
|
|
// Raycasting
|
2025-12-16 14:51:45 +05:30
|
|
|
typedef struct suic_ray {
|
2025-12-17 15:38:06 +05:30
|
|
|
suic_vec3 origin;
|
|
|
|
|
suic_vec3 direction;
|
2025-12-16 14:51:45 +05:30
|
|
|
} suic_ray;
|
|
|
|
|
|
|
|
|
|
typedef struct suic_rayhit {
|
|
|
|
|
bool hit;
|
|
|
|
|
float distance;
|
|
|
|
|
suic_vec3 point;
|
|
|
|
|
suic_vec3 normal;
|
|
|
|
|
} suic_rayhit;
|
|
|
|
|
|
|
|
|
|
typedef struct suic_aabb {
|
|
|
|
|
suic_vec3 min;
|
|
|
|
|
suic_vec3 max;
|
|
|
|
|
} suic_aabb;
|
2025-12-17 13:16:53 +05:30
|
|
|
|
|
|
|
|
suic_ray suic_get_mouse_ray(suic_vec2 mouse, suic_camera3d cam);
|
2025-12-16 14:51:45 +05:30
|
|
|
suic_rayhit suic_raycast_aabb(suic_ray ray, suic_aabb box);
|
|
|
|
|
|
2025-12-17 13:16:53 +05:30
|
|
|
// GC-aware allocator (core functionality)
|
|
|
|
|
void* gc_suic_alloc(size_t size);
|
|
|
|
|
void suic_gc_free(void* ptr);
|
|
|
|
|
|
|
|
|
|
// ODE Physics Engine Support
|
|
|
|
|
// ODE types (opaque pointers)
|
|
|
|
|
typedef dWorldID suic_ode_world_id;
|
|
|
|
|
typedef dSpaceID suic_ode_space_id;
|
|
|
|
|
typedef dBodyID suic_ode_body_id;
|
|
|
|
|
typedef dGeomID suic_ode_geom_id;
|
|
|
|
|
typedef dJointID suic_ode_joint_id;
|
|
|
|
|
typedef dJointGroupID suic_ode_joint_group_id;
|
|
|
|
|
|
|
|
|
|
// Vector types for ODE (matching ODE's dReal which is double)
|
|
|
|
|
typedef struct suic_ode_vector3 {
|
|
|
|
|
dReal x, y, z;
|
|
|
|
|
} suic_ode_vector3;
|
|
|
|
|
|
|
|
|
|
typedef struct suic_ode_quaternion {
|
|
|
|
|
dReal w, x, y, z; // ODE quaternion format: w,x,y,z
|
|
|
|
|
} suic_ode_quaternion;
|
|
|
|
|
|
|
|
|
|
// Basic ODE functions
|
|
|
|
|
void suic_ode_init(void);
|
|
|
|
|
void suic_ode_close(void);
|
|
|
|
|
suic_ode_world_id suic_ode_world_create(void);
|
|
|
|
|
void suic_ode_world_destroy(suic_ode_world_id world);
|
|
|
|
|
void suic_ode_world_set_gravity(suic_ode_world_id world, dReal x, dReal y, dReal z);
|
|
|
|
|
void suic_ode_world_step(suic_ode_world_id world, dReal stepsize);
|
|
|
|
|
|
|
|
|
|
// Body management
|
|
|
|
|
suic_ode_body_id suic_ode_body_create(suic_ode_world_id world);
|
|
|
|
|
void suic_ode_body_destroy(suic_ode_body_id body);
|
|
|
|
|
void suic_ode_body_set_position(suic_ode_body_id body, dReal x, dReal y, dReal z);
|
|
|
|
|
void suic_ode_body_set_linear_vel(suic_ode_body_id body, dReal x, dReal y, dReal z);
|
|
|
|
|
void suic_ode_body_get_position(suic_ode_body_id body, float *x, float *y, float *z);
|
|
|
|
|
|
|
|
|
|
// Mass and geometry
|
|
|
|
|
void suic_ode_body_set_box_mass(suic_ode_body_id body, dReal density, dReal lx, dReal ly, dReal lz);
|
|
|
|
|
suic_ode_geom_id suic_ode_create_box_geom(suic_ode_space_id space, dReal lx, dReal ly, dReal lz);
|
|
|
|
|
suic_ode_geom_id suic_ode_create_plane_geom(suic_ode_space_id space, dReal a, dReal b, dReal c, dReal d);
|
|
|
|
|
void suic_ode_geom_set_body(suic_ode_geom_id geom, suic_ode_body_id body);
|
|
|
|
|
void suic_ode_geom_destroy(suic_ode_geom_id geom);
|
|
|
|
|
|
|
|
|
|
// Collision space
|
|
|
|
|
suic_ode_space_id suic_ode_simple_space_create(suic_ode_space_id parent);
|
|
|
|
|
void suic_ode_space_destroy(suic_ode_space_id space);
|
|
|
|
|
|
|
|
|
|
// Collision detection and contact joints
|
|
|
|
|
void suic_ode_space_collide(suic_ode_world_id world, suic_ode_space_id space, suic_ode_joint_group_id contactgroup);
|
|
|
|
|
suic_ode_joint_group_id suic_ode_joint_group_create(int max_size);
|
|
|
|
|
void suic_ode_joint_group_destroy(suic_ode_joint_group_id group);
|
|
|
|
|
void suic_ode_joint_group_empty(suic_ode_joint_group_id group);
|
|
|
|
|
|
|
|
|
|
// Additional body functions
|
|
|
|
|
void suic_ode_body_get_linear_vel(suic_ode_body_id body, float *x, float *y, float *z);
|
|
|
|
|
void suic_ode_body_get_rotation(suic_ode_body_id body, float *q_w, float *q_x, float *q_y, float *q_z);
|
|
|
|
|
void suic_ode_body_set_rotation(suic_ode_body_id body, dReal q_w, dReal q_x, dReal q_y, dReal q_z);
|
|
|
|
|
|
|
|
|
|
// Contact properties configuration
|
|
|
|
|
void suic_ode_set_contact_max_force(dReal force);
|
|
|
|
|
void suic_ode_set_contact_erp(dReal erp);
|
|
|
|
|
void suic_ode_set_contact_cfm(dReal cfm);
|
|
|
|
|
|
|
|
|
|
// Game object system - unifies physics and rendering
|
|
|
|
|
typedef struct {
|
|
|
|
|
suic_ode_body_id body;
|
|
|
|
|
suic_ode_geom_id geom;
|
|
|
|
|
float width, height, length; // For box shapes
|
|
|
|
|
unsigned char r, g, b, a; // Color for rendering
|
|
|
|
|
int shape_type; // 0=box, 1=sphere, etc.
|
|
|
|
|
} suic_game_object;
|
|
|
|
|
|
|
|
|
|
// Create and manage game objects
|
|
|
|
|
suic_game_object* suic_game_object_create_box(
|
|
|
|
|
suic_ode_world_id world,
|
|
|
|
|
suic_ode_space_id space,
|
|
|
|
|
float x, float y, float z,
|
|
|
|
|
float width, float height, float length,
|
|
|
|
|
float density,
|
|
|
|
|
unsigned char r, unsigned char g, unsigned char b, unsigned char a
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
void suic_game_object_destroy(suic_game_object* obj);
|
|
|
|
|
void suic_game_object_set_position(suic_game_object* obj, float x, float y, float z);
|
|
|
|
|
void suic_game_object_get_position(suic_game_object* obj, float *x, float *y, float *z);
|
|
|
|
|
void suic_game_object_set_velocity(suic_game_object* obj, float x, float y, float z);
|
|
|
|
|
void suic_game_object_get_velocity(suic_game_object* obj, float *x, float *y, float *z);
|
|
|
|
|
void suic_game_object_draw(suic_game_object* obj);
|
|
|
|
|
|
2025-12-17 15:38:06 +05:30
|
|
|
// Player controller functions for FPS-style games
|
|
|
|
|
suic_player_controller* suic_player_controller_create(float x, float y, float z);
|
|
|
|
|
void suic_player_controller_destroy(suic_player_controller* player);
|
|
|
|
|
void suic_player_controller_update(suic_player_controller* player, float delta_time);
|
|
|
|
|
void suic_player_controller_set_direction(suic_player_controller* player, float forward_x, float forward_y, float forward_z, float right_x, float right_y, float right_z);
|
|
|
|
|
void suic_player_controller_move_forward(suic_player_controller* player, float amount);
|
|
|
|
|
void suic_player_controller_move_right(suic_player_controller* player, float amount);
|
|
|
|
|
void suic_player_controller_jump(suic_player_controller* player);
|
|
|
|
|
void suic_player_controller_get_position(suic_player_controller* player, float *x, float *y, float *z);
|
|
|
|
|
void suic_player_controller_set_position(suic_player_controller* player, float x, float y, float z);
|
|
|
|
|
|
2025-12-20 17:11:21 +05:30
|
|
|
/* ===== MATH FUNCTIONS ===== */
|
|
|
|
|
|
|
|
|
|
float suic_sinf(float x);
|
|
|
|
|
float suic_cosf(float x);
|
|
|
|
|
float suic_expf(float x);
|
|
|
|
|
float suic_fmaxf(float a, float b);
|
|
|
|
|
|
2025-12-17 18:32:29 +05:30
|
|
|
/* ===== FILE I/O API ===== */
|
|
|
|
|
|
|
|
|
|
typedef void* FileHandle;
|
|
|
|
|
typedef enum {
|
|
|
|
|
FILE_READ = 0,
|
|
|
|
|
FILE_WRITE = 1,
|
|
|
|
|
FILE_APPEND = 2
|
|
|
|
|
} FileMode;
|
|
|
|
|
|
|
|
|
|
/* Open a file and return a handle. Returns NULL on failure. */
|
|
|
|
|
FileHandle suic_file_open(const char* path, FileMode mode);
|
|
|
|
|
|
|
|
|
|
/* Close a file handle */
|
|
|
|
|
void suic_file_close(FileHandle handle);
|
|
|
|
|
|
|
|
|
|
/* Read up to size bytes from file. Returns number of bytes read. */
|
|
|
|
|
int suic_file_read(FileHandle handle, void* buffer, int size);
|
|
|
|
|
|
|
|
|
|
/* Write up to size bytes to file. Returns number of bytes written. */
|
|
|
|
|
int suic_file_write(FileHandle handle, const void* buffer, int size);
|
|
|
|
|
|
|
|
|
|
/* Get file size in bytes. Returns -1 on failure. */
|
|
|
|
|
int suic_file_size(FileHandle handle);
|
|
|
|
|
|
|
|
|
|
/* ===== RANDOM NUMBER GENERATION API ===== */
|
|
|
|
|
|
|
|
|
|
/* Seed the random number generator */
|
|
|
|
|
void suic_random_seed(uint32_t seed);
|
|
|
|
|
|
|
|
|
|
/* Get a random integer between 0 and 2^31-1 */
|
|
|
|
|
uint32_t suic_random_int(void);
|
|
|
|
|
|
|
|
|
|
/* Get a random integer between min and max (inclusive) */
|
|
|
|
|
int suic_random_int_range(int min, int max);
|
|
|
|
|
|
|
|
|
|
/* Get a random float between 0.0 and 1.0 */
|
|
|
|
|
float suic_random_float(void);
|
|
|
|
|
|
|
|
|
|
/* Get a random float between min and max */
|
|
|
|
|
float suic_random_float_range(float min, float max);
|
|
|
|
|
|
|
|
|
|
/* ===== TIME API ===== */
|
|
|
|
|
|
|
|
|
|
/* Get current time in milliseconds since program start */
|
|
|
|
|
uint64_t suic_get_time_ms(void);
|
|
|
|
|
|
|
|
|
|
/* Get current time in microseconds since program start */
|
|
|
|
|
uint64_t suic_get_time_us(void);
|
|
|
|
|
|
|
|
|
|
/* Get current Unix timestamp in seconds */
|
|
|
|
|
uint64_t suic_get_unix_time(void);
|
|
|
|
|
|
|
|
|
|
/* Sleep for milliseconds */
|
|
|
|
|
void suic_sleep_ms(uint32_t ms);
|
|
|
|
|
|
|
|
|
|
/* ===== UUID GENERATION API ===== */
|
|
|
|
|
|
|
|
|
|
/* Generate a random UUID v4 and return as string */
|
|
|
|
|
const char* suic_uuid_generate_v4(void);
|
|
|
|
|
|
|
|
|
|
/* Generate a random UUID v4 from seed */
|
|
|
|
|
const char* suic_uuid_generate_v4_seeded(uint64_t seed);
|
|
|
|
|
|
2025-12-17 19:16:17 +05:30
|
|
|
/* ===== FISHSOUP NETWORKING API ===== */
|
|
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
#include <netdb.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <poll.h>
|
|
|
|
|
|
|
|
|
|
#define FISHSOUP_PORT 3219
|
|
|
|
|
#define FISHSOUP_PING 3
|
|
|
|
|
|
|
|
|
|
enum fishsoup_packet_type {
|
|
|
|
|
FISHSOUP_PACKET_PING = 0,
|
|
|
|
|
FISHSOUP_PACKET_PONG
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define FISHSOUP_PACKET_FLAG_BROADCAST (1 << 0)
|
|
|
|
|
|
|
|
|
|
typedef struct fishsoup_packet_header fishsoup_packet_header_t;
|
|
|
|
|
typedef struct fishsoup_packet fishsoup_packet_t;
|
|
|
|
|
typedef struct fishsoup_client fishsoup_client_t;
|
|
|
|
|
typedef struct fishsoup_server fishsoup_server_t;
|
|
|
|
|
|
|
|
|
|
#pragma pack(1)
|
|
|
|
|
struct fishsoup_packet_header {
|
|
|
|
|
unsigned char type;
|
|
|
|
|
unsigned char flag;
|
|
|
|
|
unsigned short length;
|
|
|
|
|
};
|
|
|
|
|
#pragma pack()
|
|
|
|
|
|
|
|
|
|
struct fishsoup_packet {
|
|
|
|
|
fishsoup_packet_header_t header;
|
|
|
|
|
void* data;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct fishsoup_client {
|
|
|
|
|
int fd;
|
|
|
|
|
time_t last_ping;
|
|
|
|
|
void (*on_packet)(fishsoup_client_t* client, fishsoup_packet_t* packet);
|
|
|
|
|
struct {
|
|
|
|
|
int sent_ping;
|
|
|
|
|
int cleanup;
|
|
|
|
|
} server;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct fishsoup_server {
|
|
|
|
|
int fd;
|
|
|
|
|
struct sockaddr_in address;
|
|
|
|
|
fishsoup_client_t* clients;
|
|
|
|
|
void (*on_client)(fishsoup_server_t* server, fishsoup_client_t* client);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
fishsoup_client_t* fishsoup_client(const char* host, int port);
|
|
|
|
|
void fishsoup_client_on_packet(fishsoup_client_t* client, void (*on_packet)(fishsoup_client_t* client, fishsoup_packet_t* packet));
|
|
|
|
|
int fishsoup_client_poll(fishsoup_client_t* client);
|
|
|
|
|
void fishsoup_client_destroy(fishsoup_client_t* client);
|
|
|
|
|
|
|
|
|
|
fishsoup_server_t* fishsoup_server(int port);
|
|
|
|
|
int fishsoup_server_clients(fishsoup_server_t* server);
|
|
|
|
|
void fishsoup_server_loop(fishsoup_server_t* server);
|
|
|
|
|
void fishsoup_server_on_client(fishsoup_server_t* server, void (*on_client)(fishsoup_server_t* server, fishsoup_client_t* client));
|
|
|
|
|
void fishsoup_server_destroy(fishsoup_server_t* server);
|
|
|
|
|
|
|
|
|
|
int fishsoup_fd_send(int fd, const void* buf, int length);
|
|
|
|
|
int fishsoup_fd_recv(int fd, void* buf, int length);
|
|
|
|
|
int fishsoup_packet_send(int fd, fishsoup_packet_t* packet);
|
|
|
|
|
int fishsoup_packet_recv(int fd, fishsoup_packet_t* packet);
|
|
|
|
|
|
|
|
|
|
typedef void (*suic_fishsoup_client_on_packet_fn)(fishsoup_client_t* client, fishsoup_packet_t* packet);
|
|
|
|
|
typedef void (*suic_fishsoup_server_on_client_fn)(fishsoup_server_t* server, fishsoup_client_t* client);
|
|
|
|
|
|
|
|
|
|
/* Client functions */
|
|
|
|
|
fishsoup_client_t* suic_fishsoup_client_create(const char* host, int port);
|
|
|
|
|
void suic_fishsoup_client_on_packet(fishsoup_client_t* client, suic_fishsoup_client_on_packet_fn on_packet);
|
|
|
|
|
int suic_fishsoup_client_poll(fishsoup_client_t* client);
|
|
|
|
|
void suic_fishsoup_client_destroy(fishsoup_client_t* client);
|
|
|
|
|
|
|
|
|
|
/* Server functions */
|
|
|
|
|
fishsoup_server_t* suic_fishsoup_server_create(int port);
|
|
|
|
|
int suic_fishsoup_server_clients(fishsoup_server_t* server);
|
|
|
|
|
void suic_fishsoup_server_loop(fishsoup_server_t* server);
|
|
|
|
|
void suic_fishsoup_server_on_client(fishsoup_server_t* server, suic_fishsoup_server_on_client_fn on_client);
|
|
|
|
|
void suic_fishsoup_server_destroy(fishsoup_server_t* server);
|
|
|
|
|
|
|
|
|
|
/* Packet functions */
|
|
|
|
|
int suic_fishsoup_packet_send(int fd, fishsoup_packet_t* packet);
|
|
|
|
|
int suic_fishsoup_packet_recv(int fd, fishsoup_packet_t* packet);
|
|
|
|
|
|
2025-12-16 14:51:45 +05:30
|
|
|
#endif // LIBSUICMEZ_H
|