added anti aliasing. new fps game

This commit is contained in:
Masashi 2025-12-17 15:38:06 +05:30
commit 7b73c86113
40 changed files with 2386 additions and 564 deletions

49
tests/basic_types.c Normal file
View file

@ -0,0 +1,49 @@
#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;
}
int suic_main(void);
int suic_main(void) {
int x = 5;
float y = 10.500000;
bool z = true;
char* s = suic_alloc_array(NULL, sizeof(char), 6, "hello");
return x;
}
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;
}

BIN
tests/basic_types.o Executable file

Binary file not shown.

50
tests/control_flow.c Normal file
View file

@ -0,0 +1,50 @@
#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;
}
int suic_main(void);
int suic_main(void) {
(true ? 1 : 0);
int i = 0;
while ((i < 5)) {
i = (i + 1);
}
return i;
}
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;
}

216
tests/fps_game.c Normal file
View file

@ -0,0 +1,216 @@
#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;
}
int suic_main(void);
int suic_main(void) {
suic_enable_msaa_4x();
suic_init_window(1280, 720, suic_alloc_array(NULL, sizeof(char), 75, "Sui FPS Game - WASD to move, Mouse to look, SPACE to jump, SHIFT to sprint"));
suic_set_target_fps(60);
suic_disable_cursor();
suic_ode_init();
void* world = suic_ode_world_create();
void* null_space = NULL;
void* space = suic_ode_simple_space_create(null_space);
suic_ode_world_set_gravity(world, 0.000000, -9.810000, 0.000000);
void* contactgroup = suic_ode_joint_group_create(0);
void* ground_geom = suic_ode_create_plane_geom(space, 0.000000, 1.000000, 0.000000, 0.000000);
void* player_body = suic_ode_body_create(world);
suic_ode_body_set_position(player_body, 0.000000, 2.000000, 0.000000);
void* player_geom = suic_ode_create_box_geom(space, 0.800000, 1.600000, 0.800000);
suic_ode_geom_set_body(player_geom, player_body);
suic_ode_body_set_box_mass(player_body, 1.000000, 0.800000, 1.600000, 0.800000);
void* cube1_body = suic_ode_body_create(world);
suic_ode_body_set_position(cube1_body, 0.000000, 1.000000, -5.000000);
suic_ode_body_set_box_mass(cube1_body, 1.000000, 1.000000, 1.000000, 1.000000);
void* cube1_geom = suic_ode_create_box_geom(space, 1.000000, 1.000000, 1.000000);
suic_ode_geom_set_body(cube1_geom, cube1_body);
void* cube2_body = suic_ode_body_create(world);
suic_ode_body_set_position(cube2_body, 5.000000, 1.000000, -3.000000);
suic_ode_body_set_box_mass(cube2_body, 1.000000, 1.000000, 1.000000, 1.000000);
void* cube2_geom = suic_ode_create_box_geom(space, 1.000000, 1.000000, 1.000000);
suic_ode_geom_set_body(cube2_geom, cube2_body);
void* cube3_body = suic_ode_body_create(world);
suic_ode_body_set_position(cube3_body, -5.000000, 1.000000, -3.000000);
suic_ode_body_set_box_mass(cube3_body, 1.000000, 1.000000, 1.000000, 1.000000);
void* cube3_geom = suic_ode_create_box_geom(space, 1.000000, 1.000000, 1.000000);
suic_ode_geom_set_body(cube3_geom, cube3_body);
float forward_x = 0.000000;
float forward_y = 0.000000;
float forward_z = -1.000000;
float right_x = 1.000000;
float right_y = 0.000000;
float right_z = 0.000000;
float camera_x = 0.000000;
float camera_y = 2.000000;
float camera_z = 0.000000;
float target_x = 0.000000;
float target_y = 2.000000;
float target_z = -5.000000;
float yaw = 0.000000;
float pitch = 0.000000;
float mouse_sensitivity = 0.003000;
float cube1_x = 0.000000;
float cube1_y = 0.000000;
float cube1_z = 0.000000;
float cube2_x = 0.000000;
float cube2_y = 0.000000;
float cube2_z = 0.000000;
float cube3_x = 0.000000;
float cube3_y = 0.000000;
float cube3_z = 0.000000;
float player_x = 0.000000;
float player_y = 2.000000;
float player_z = 0.000000;
while ((suic_window_should_close() == false)) {
float delta_time = 0.016660;
float move_speed = 5.000000;
float target_vx = 0.000000;
float target_vz = 0.000000;
if ((suic_is_key_down(KEY_W) != 0)) {
target_vx = (target_vx + (forward_x * move_speed));
target_vz = (target_vz + (forward_z * move_speed));
}
if ((suic_is_key_down(KEY_S) != 0)) {
target_vx = (target_vx - (forward_x * move_speed));
target_vz = (target_vz - (forward_z * move_speed));
}
if ((suic_is_key_down(KEY_D) != 0)) {
target_vx = (target_vx + (right_x * move_speed));
target_vz = (target_vz + (right_z * move_speed));
}
if ((suic_is_key_down(KEY_A) != 0)) {
target_vx = (target_vx - (right_x * move_speed));
target_vz = (target_vz - (right_z * move_speed));
}
float current_vx = 0.000000;
float current_vy = 0.000000;
float current_vz = 0.000000;
suic_ode_body_get_linear_vel(player_body, &current_vx, &current_vy, &current_vz);
if ((suic_is_jump_pressed() != 0)) {
float dummy_x = 0.000000;
float current_y = 0.000000;
float dummy_z = 0.000000;
suic_ode_body_get_position(player_body, &dummy_x, &current_y, &dummy_z);
if ((current_y <= 1.300000)) {
current_vy = 8.000000;
}
}
suic_ode_body_set_linear_vel(player_body, target_vx, current_vy, target_vz);
suic_ode_body_get_position(player_body, &player_x, &player_y, &player_z);
if (((suic_is_key_pressed(KEY_EQUAL) != 0) || (suic_is_key_pressed(KEY_KP_ADD) != 0))) {
mouse_sensitivity = (mouse_sensitivity + 0.001000);
}
if (((suic_is_key_pressed(KEY_MINUS) != 0) || (suic_is_key_pressed(KEY_KP_SUBTRACT) != 0))) {
mouse_sensitivity = (mouse_sensitivity - 0.001000);
if ((mouse_sensitivity < 0.001000)) {
mouse_sensitivity = 0.001000;
}
}
if ((suic_is_key_pressed(KEY_F1) != 0)) {
suic_enable_cursor();
}
float mouse_delta_x = suic_get_mouse_delta_x();
float mouse_delta_y = suic_get_mouse_delta_y();
yaw = (yaw + (mouse_delta_x * mouse_sensitivity));
pitch = (pitch - (mouse_delta_y * mouse_sensitivity));
if ((pitch > 1.500000)) {
pitch = 1.500000;
}
if ((pitch < -1.500000)) {
pitch = -1.500000;
}
suic_ode_space_collide(world, space, contactgroup);
suic_ode_world_step(world, delta_time);
suic_ode_joint_group_empty(contactgroup);
float cos_yaw = cos(yaw);
float sin_yaw = sin(yaw);
float cos_pitch = cos(pitch);
float sin_pitch = sin(pitch);
forward_x = sin_yaw;
forward_y = sin_pitch;
forward_z = -cos_yaw;
right_x = cos_yaw;
right_y = 0.000000;
right_z = sin_yaw;
camera_x = (player_x + (forward_x * 0.500000));
camera_y = (player_y + 0.900000);
camera_z = (player_z + (forward_z * 0.500000));
target_x = (player_x + (forward_x * 5.000000));
target_y = (player_y + (forward_y * 5.000000));
target_z = (player_z + (forward_z * 5.000000));
suic_ode_body_get_position(cube1_body, &cube1_x, &cube1_y, &cube1_z);
suic_ode_body_get_position(cube2_body, &cube2_x, &cube2_y, &cube2_z);
suic_ode_body_get_position(cube3_body, &cube3_x, &cube3_y, &cube3_z);
suic_begin_drawing();
suic_clear_background(135, 206, 235, 255);
suic_begin_mode3d(camera_x, camera_y, camera_z, target_x, target_y, target_z, 0.000000, 1.000000, 0.000000, 45.000000, 0);
suic_draw_cube(0.000000, -1.000000, 0.000000, 100.000000, 0.100000, 100.000000, 34, 139, 34, 255);
suic_draw_cube(cube1_x, cube1_y, cube1_z, 1.000000, 1.000000, 1.000000, 255, 0, 0, 255);
suic_draw_cube_wires(cube1_x, cube1_y, cube1_z, 1.000000, 1.000000, 1.000000, 0, 0, 0, 255);
suic_draw_cube(cube2_x, cube2_y, cube2_z, 1.000000, 1.000000, 1.000000, 0, 255, 0, 255);
suic_draw_cube_wires(cube2_x, cube2_y, cube2_z, 1.000000, 1.000000, 1.000000, 0, 0, 0, 255);
suic_draw_cube(cube3_x, cube3_y, cube3_z, 1.000000, 1.000000, 1.000000, 0, 0, 255, 255);
suic_draw_cube_wires(cube3_x, cube3_y, cube3_z, 1.000000, 1.000000, 1.000000, 0, 0, 0, 255);
suic_rl_push_matrix();
suic_rl_translate_f(player_x, player_y, player_z);
suic_rl_rotate_f(((-yaw * 180.000000) / 3.141590), 0.000000, 1.000000, 0.000000);
suic_draw_cube(0.000000, 0.000000, 0.000000, 0.800000, 1.600000, 0.800000, 255, 255, 0, 255);
suic_draw_cube_wires(0.000000, 0.000000, 0.000000, 0.800000, 1.600000, 0.800000, 0, 0, 0, 255);
suic_rl_pop_matrix();
suic_end_mode3d();
suic_end_drawing();
}
suic_ode_geom_destroy(cube3_geom);
suic_ode_body_destroy(cube3_body);
suic_ode_geom_destroy(cube2_geom);
suic_ode_body_destroy(cube2_body);
suic_ode_geom_destroy(cube1_geom);
suic_ode_body_destroy(cube1_body);
suic_ode_geom_destroy(player_geom);
suic_ode_body_destroy(player_body);
suic_ode_geom_destroy(ground_geom);
suic_ode_joint_group_destroy(contactgroup);
suic_ode_space_destroy(space);
suic_ode_world_destroy(world);
suic_ode_close();
suic_close_window();
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;
}

BIN
tests/fps_game.o Executable file

Binary file not shown.

271
tests/fps_game.sui Normal file
View file

@ -0,0 +1,271 @@
# FPS-Style 3D Game with Sui Language
# Demonstrates WASD movement, mouse look, jumping, sprinting, and physics-based gameplay
fn main() -> int do
# Enable antialiasing
enable_msaa_4x()
# Initialize graphics
init_window(1280, 720, "Sui FPS Game - WASD to move, Mouse to look, SPACE to jump, SHIFT to sprint")
defer close_window()
set_target_fps(60)
# Hide cursor and capture mouse for FPS controls
disable_cursor()
# Initialize physics
ode_init()
defer ode_close()
# Create physics world
let world = ode_world_create()
defer ode_world_destroy(world)
let null_space = 0 as *()
let space = ode_simple_space_create(null_space)
defer ode_space_destroy(space)
# Set gravity
ode_world_set_gravity(world, 0.0, -9.81, 0.0)
# Create contact joint group
let contactgroup = ode_joint_group_create(0)
defer ode_joint_group_destroy(contactgroup)
# Create ground plane
let ground_geom = ode_create_plane_geom(space, 0.0, 1.0, 0.0, 0.0)
defer ode_geom_destroy(ground_geom)
# Create player physics body (capsule shape)
let player_body = ode_body_create(world)
defer ode_body_destroy(player_body)
ode_body_set_position(player_body, 0.0, 2.0, 0.0)
# Create box geometry for player (0.8 x 1.6 x 0.8)
let player_geom = ode_create_box_geom(space, 0.8, 1.6, 0.8)
defer ode_geom_destroy(player_geom)
ode_geom_set_body(player_geom, player_body)
# Set player mass (box with density 1.0)
ode_body_set_box_mass(player_body, 1.0, 0.8, 1.6, 0.8)
# Create cube physics bodies
let cube1_body = ode_body_create(world)
defer ode_body_destroy(cube1_body)
ode_body_set_position(cube1_body, 0.0, 1.0, -5.0)
ode_body_set_box_mass(cube1_body, 1.0, 1.0, 1.0, 1.0)
let cube1_geom = ode_create_box_geom(space, 1.0, 1.0, 1.0)
defer ode_geom_destroy(cube1_geom)
ode_geom_set_body(cube1_geom, cube1_body)
let cube2_body = ode_body_create(world)
defer ode_body_destroy(cube2_body)
ode_body_set_position(cube2_body, 5.0, 1.0, -3.0)
ode_body_set_box_mass(cube2_body, 1.0, 1.0, 1.0, 1.0)
let cube2_geom = ode_create_box_geom(space, 1.0, 1.0, 1.0)
defer ode_geom_destroy(cube2_geom)
ode_geom_set_body(cube2_geom, cube2_body)
let cube3_body = ode_body_create(world)
defer ode_body_destroy(cube3_body)
ode_body_set_position(cube3_body, -5.0, 1.0, -3.0)
ode_body_set_box_mass(cube3_body, 1.0, 1.0, 1.0, 1.0)
let cube3_geom = ode_create_box_geom(space, 1.0, 1.0, 1.0)
defer ode_geom_destroy(cube3_geom)
ode_geom_set_body(cube3_geom, cube3_body)
# Set player movement direction (looking down -Z axis)
let mut forward_x = 0.0
let mut forward_y = 0.0
let mut forward_z = -1.0
let mut right_x = 1.0
let mut right_y = 0.0
let mut right_z = 0.0
# ==== CAMERA AND PLAYER STATE ====
let mut camera_x = 0.0
let mut camera_y = 2.0
let mut camera_z = 0.0
let mut target_x = 0.0
let mut target_y = 2.0
let mut target_z = -5.0
# Mouse look state
let mut yaw = 0.0
let mut pitch = 0.0
let mut mouse_sensitivity = 0.003
# Cube position variables
let mut cube1_x = 0.0
let mut cube1_y = 0.0
let mut cube1_z = 0.0
let mut cube2_x = 0.0
let mut cube2_y = 0.0
let mut cube2_z = 0.0
let mut cube3_x = 0.0
let mut cube3_y = 0.0
let mut cube3_z = 0.0
# Player position (initial values)
let mut player_x = 0.0
let mut player_y = 2.0
let mut player_z = 0.0
# Main game loop
while window_should_close() == false do
# Input handling
let delta_time = 0.01666 # ~60 FPS
# WASD movement - set velocities on physics body
let move_speed = 5.0 # Velocity applied to body
let mut target_vx = 0.0
let mut target_vz = 0.0
if is_key_down(KEY_W) != 0 do
target_vx = target_vx + forward_x * move_speed
target_vz = target_vz + forward_z * move_speed
end
if is_key_down(KEY_S) != 0 do
target_vx = target_vx - forward_x * move_speed
target_vz = target_vz - forward_z * move_speed
end
if is_key_down(KEY_D) != 0 do
target_vx = target_vx + right_x * move_speed
target_vz = target_vz + right_z * move_speed
end
if is_key_down(KEY_A) != 0 do
target_vx = target_vx - right_x * move_speed
target_vz = target_vz - right_z * move_speed
end
# Get current velocity for Y (preserve gravity)
let mut current_vx = 0.0
let mut current_vy = 0.0
let mut current_vz = 0.0
ode_body_get_linear_vel(player_body, &current_vx, &current_vy, &current_vz)
# Jump - set upward velocity
if is_jump_pressed() != 0 do
# Get current position to check if on ground
let mut dummy_x = 0.0
let mut current_y = 0.0
let mut dummy_z = 0.0
ode_body_get_position(player_body, &dummy_x, &current_y, &dummy_z)
if current_y <= 1.3 do # On ground (box bottom is at y - 0.8 from center)
current_vy = 8.0 # Jump velocity
end
end
# Set new velocity (keep Y velocity for gravity/jumping)
ode_body_set_linear_vel(player_body, target_vx, current_vy, target_vz)
# Get player position from physics body
ode_body_get_position(player_body, &player_x, &player_y, &player_z)
# Adjust mouse sensitivity
if is_key_pressed(KEY_EQUAL) != 0 or is_key_pressed(KEY_KP_ADD) != 0 do # + key
mouse_sensitivity = mouse_sensitivity + 0.001
end
if is_key_pressed(KEY_MINUS) != 0 or is_key_pressed(KEY_KP_SUBTRACT) != 0 do # - key
mouse_sensitivity = mouse_sensitivity - 0.001
if mouse_sensitivity < 0.001 do
mouse_sensitivity = 0.001 # Minimum sensitivity
end
end
# Show cursor with F1 (useful for debugging)
if is_key_pressed(KEY_F1) != 0 do
enable_cursor()
end
# Mouse look
let mouse_delta_x = get_mouse_delta_x()
let mouse_delta_y = get_mouse_delta_y()
yaw = yaw + (mouse_delta_x * mouse_sensitivity)
pitch = pitch - (mouse_delta_y * mouse_sensitivity) # Negate Y for natural FPS controls
# Clamp pitch to prevent flipping
if pitch > 1.5 do
pitch = 1.5
end
if pitch < -1.5 do
pitch = -1.5
end
# Update physics (just for cubes)
ode_space_collide(world, space, contactgroup)
ode_world_step(world, delta_time)
ode_joint_group_empty(contactgroup)
# Calculate camera direction from yaw and pitch
let cos_yaw = cos(yaw)
let sin_yaw = sin(yaw)
let cos_pitch = cos(pitch)
let sin_pitch = sin(pitch)
# Update forward and right vectors
forward_x = sin_yaw
forward_y = sin_pitch
forward_z = -cos_yaw
right_x = cos_yaw
right_y = 0.0
right_z = sin_yaw
# Direction vectors are updated above
# Camera follows player (at eye position, slightly in front)
camera_x = player_x + forward_x * 0.5 # Offset forward
camera_y = player_y + 0.9 # Eye height
camera_z = player_z + forward_z * 0.5 # Offset forward
# Camera looks where player is looking
target_x = player_x + forward_x * 5.0
target_y = player_y + forward_y * 5.0
target_z = player_z + forward_z * 5.0
# Player rotation is handled visually during rendering
# Get cube positions from physics bodies
ode_body_get_position(cube1_body, &cube1_x, &cube1_y, &cube1_z)
ode_body_get_position(cube2_body, &cube2_x, &cube2_y, &cube2_z)
ode_body_get_position(cube3_body, &cube3_x, &cube3_y, &cube3_z)
# ==== RENDERING ====
begin_drawing()
clear_background(135, 206, 235, 255) # Sky blue
# 3D mode with calculated camera
begin_mode3d(camera_x, camera_y, camera_z, target_x, target_y, target_z, 0.0, 1.0, 0.0, 45.0, 0)
# Draw ground plane
draw_cube(0.0, -1.0, 0.0, 100.0, 0.1, 100.0, 34, 139, 34, 255) # Green ground
# Draw cubes
draw_cube(cube1_x, cube1_y, cube1_z, 1.0, 1.0, 1.0, 255, 0, 0, 255) # Red
draw_cube_wires(cube1_x, cube1_y, cube1_z, 1.0, 1.0, 1.0, 0, 0, 0, 255)
draw_cube(cube2_x, cube2_y, cube2_z, 1.0, 1.0, 1.0, 0, 255, 0, 255) # Green
draw_cube_wires(cube2_x, cube2_y, cube2_z, 1.0, 1.0, 1.0, 0, 0, 0, 255)
draw_cube(cube3_x, cube3_y, cube3_z, 1.0, 1.0, 1.0, 0, 0, 255, 255) # Blue
draw_cube_wires(cube3_x, cube3_y, cube3_z, 1.0, 1.0, 1.0, 0, 0, 0, 255)
# Draw player model with rotation (yellow cube to represent the player)
rl_push_matrix()
rl_translate_f(player_x, player_y, player_z)
rl_rotate_f(-yaw * 180.0 / 3.14159, 0.0, 1.0, 0.0) # Convert radians to degrees for Y-axis rotation, negate for correct direction
draw_cube(0.0, 0.0, 0.0, 0.8, 1.6, 0.8, 255, 255, 0, 255) # Yellow player
draw_cube_wires(0.0, 0.0, 0.0, 0.8, 1.6, 0.8, 0, 0, 0, 255)
rl_pop_matrix()
end_mode3d()
end_drawing()
end
0
end

52
tests/functions.c Normal file
View file

@ -0,0 +1,52 @@
#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;
}
int add(int x, int y);
int suic_main(void);
int add(int x, int y) {
return (x + y);
}
int suic_main(void) {
int sum = add(5, 3);
struct T id = identity(42);
return sum;
}
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;
}

89
tests/game_3d_improved.c Normal file
View file

@ -0,0 +1,89 @@
#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;
}
int suic_main(void);
int suic_main(void) {
suic_init_window(800, 600, suic_alloc_array(NULL, sizeof(char), 27, "3D Physics Game - Improved"));
suic_set_target_fps(60);
suic_ode_init();
void* world = suic_ode_world_create();
void* null_space = (struct unit**) 0;
void* space = suic_ode_simple_space_create(null_space);
suic_ode_world_set_gravity(world, 0.000000, -9.810000, 0.000000);
void* contactgroup = suic_ode_joint_group_create(0);
void* body = suic_ode_body_create(world);
suic_ode_body_set_box_mass(body, 1.000000, 1.000000, 1.000000, 1.000000);
suic_ode_body_set_position(body, 0.000000, 5.000000, 0.000000);
void* geom = suic_ode_create_box_geom(space, 1.000000, 1.000000, 1.000000);
suic_ode_geom_set_body(geom, body);
void* ground_geom = suic_ode_create_plane_geom(space, 0.000000, 1.000000, 0.000000, 0.000000);
float camera_pos_x = 0.000000;
float camera_pos_y = 2.000000;
float camera_pos_z = 10.000000;
float cube_x = 0.000000;
float cube_y = 0.000000;
float cube_z = 0.000000;
int frame_count = 0;
while ((suic_window_should_close() == false)) {
suic_ode_space_collide(world, space, contactgroup);
suic_ode_world_step(world, (1.000000 / 60.000000));
suic_ode_joint_group_empty(contactgroup);
suic_ode_body_get_position(body, &cube_x, &cube_y, &cube_z);
suic_begin_drawing();
suic_clear_background(135, 206, 235, 255);
suic_begin_mode3d(camera_pos_x, camera_pos_y, camera_pos_z, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 45.000000, 0);
suic_draw_cube(0.000000, -1.000000, 0.000000, 20.000000, 0.100000, 20.000000, 34, 139, 34, 255);
suic_draw_cube(cube_x, cube_y, cube_z, 1.000000, 1.000000, 1.000000, 255, 0, 0, 255);
suic_draw_cube_wires(cube_x, cube_y, cube_z, 1.000000, 1.000000, 1.000000, 0, 0, 0, 255);
suic_end_mode3d();
suic_end_drawing();
frame_count = (frame_count + 1);
}
suic_ode_geom_destroy(ground_geom);
suic_ode_geom_destroy(geom);
suic_ode_body_destroy(body);
suic_ode_joint_group_destroy(contactgroup);
suic_ode_space_destroy(space);
suic_ode_world_destroy(world);
suic_ode_close();
suic_close_window();
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;
}

BIN
tests/game_3d_improved.o Executable file

Binary file not shown.

51
tests/ode_test.c Normal file
View file

@ -0,0 +1,51 @@
#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;
}
int suic_main(void);
int suic_main(void) {
suic_ode_init();
void* world = suic_ode_world_create();
suic_ode_world_set_gravity(world, 0.000000, -9.810000, 0.000000);
suic_ode_world_step(world, 0.016000);
suic_ode_world_destroy(world);
suic_ode_close();
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;
}

BIN
tests/ode_test.o Executable file

Binary file not shown.

64
tests/ode_voxel_example.c Normal file
View file

@ -0,0 +1,64 @@
#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;
}
int suic_main(void);
int suic_main(void) {
suic_ode_init();
void* world = suic_ode_world_create();
void* space = suic_ode_simple_space_create(NULL);
suic_ode_world_set_gravity(world, 0.000000, -9.810000, 0.000000);
void* body = suic_ode_body_create(world);
suic_ode_body_set_box_mass(body, 1.000000, 1.000000, 1.000000, 1.000000);
suic_ode_body_set_position(body, 0.000000, 5.000000, 0.000000);
void* geom = suic_ode_create_box_geom(space, 1.000000, 1.000000, 1.000000);
suic_ode_geom_set_body(geom, body);
int i = 0;
while ((i < 10)) {
suic_ode_world_step(world, 0.016000);
i = (i + 1);
}
suic_ode_geom_destroy(geom);
suic_ode_body_destroy(body);
suic_ode_space_destroy(space);
suic_ode_world_destroy(world);
suic_ode_close();
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;
}

BIN
tests/ode_voxel_example.o Executable file

Binary file not shown.

68
tests/structs.c Normal file
View file

@ -0,0 +1,68 @@
#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 Point {
int x;
int y;
};
struct Person {
char* name;
int age;
};
static const uint8_t sui_bitmap_Point[] = { 0, 0 };
static const TypeInfo sui_typeinfo_Point = {
.field_count = 2,
.pointer_count = 0,
.pointer_bitmap = sui_bitmap_Point
};
static const uint8_t sui_bitmap_Person[] = { 1, 0 };
static const TypeInfo sui_typeinfo_Person = {
.field_count = 2,
.pointer_count = 1,
.pointer_bitmap = sui_bitmap_Person
};
int suic_main(void);
int suic_main(void) {
struct Point* p = suic_alloc_struct(&sui_typeinfo_Point, sizeof(struct Point), &(struct Point){ .x = 5, .y = 10 });
struct Person* person = suic_alloc_struct(&sui_typeinfo_Person, sizeof(struct Person), &(struct Person){ .name = suic_alloc_array(NULL, sizeof(char), 6, "Alice"), .age = 30 });
int _ = ((*p).x + (*person).age);
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;
}

BIN
tests/structs.o Executable file

Binary file not shown.