base: cleanup

This commit is contained in:
luboslenco
2026-08-21 22:39:15 +02:00
parent eb25ff4f46
commit cf8077c0a6
18 changed files with 112 additions and 115 deletions
-1
View File
@@ -749,7 +749,6 @@ static int xk_to_iron(KeySym symbol) {
return KEY_CODE_UNKNOWN;
}
static char *uri_decode(const char *src) {
char *res = calloc(1, 1024);
char *dst = res;
+13 -13
View File
@@ -235,11 +235,11 @@ void transform_compute_radius(transform_t *raw) {
void transform_compute_dim(transform_t *raw) {
if (raw->object->raw == NULL && string_equals(raw->object->ext_type, "mesh_object_t")) {
mesh_object_t *mo = (mesh_object_t *)raw->object->ext;
vec4_t aabb = mesh_data_calculate_aabb(mo->data);
obj_t *o_raw = calloc(1, sizeof(obj_t));
o_raw->dimensions = f32_array_create_xyz(aabb.x, aabb.y, aabb.z);
raw->object->raw = o_raw;
mesh_object_t *mo = (mesh_object_t *)raw->object->ext;
vec4_t aabb = mesh_data_calculate_aabb(mo->data);
obj_t *o_raw = calloc(1, sizeof(obj_t));
o_raw->dimensions = f32_array_create_xyz(aabb.x, aabb.y, aabb.z);
raw->object->raw = o_raw;
raw->object->owns_raw = true;
}
@@ -1894,7 +1894,7 @@ gpu_texture_t *iron_load_texture(char *file);
void gpu_delete_texture(gpu_texture_t *texture);
void *iron_load_sound(char *file);
#ifdef WITH_EMBED
bool embed_owns(uint8_t *buffer);
bool embed_owns(uint8_t *buffer);
#endif
char *data_path(void) {
@@ -2205,7 +2205,7 @@ object_t *scene_create(scene_t *format) {
scene_embedded = any_map_create();
_scene_root = object_create(true);
_scene_root = object_create(true);
_scene_root->name = format->name;
_scene_raw = format;
@@ -2531,8 +2531,8 @@ void render_path_set_target(char *target, string_array_t *additional, char *dept
gpu_viewport(sys_x(), render_path_current_h - (sys_h() - sys_y()), sys_w(), sys_h());
}
else { // Render target
render_target_t *rt = (render_target_t *)any_map_get(render_path_render_targets, target);
_render_path_current_target = rt;
render_target_t *rt = (render_target_t *)any_map_get(render_path_render_targets, target);
_render_path_current_target = rt;
static any_array_t additional_images_scratch = {0};
any_array_t *additional_images = NULL;
if (additional != NULL) {
@@ -2544,9 +2544,9 @@ void render_path_set_target(char *target, string_array_t *additional, char *dept
}
additional_images = &additional_images_scratch;
}
render_path_current_w = rt->_image->width;
render_path_current_h = rt->_image->height;
render_target_t *db = depth_buffer != NULL ? (render_target_t *)any_map_get(render_path_render_targets, depth_buffer) : NULL;
render_path_current_w = rt->_image->width;
render_path_current_h = rt->_image->height;
render_target_t *db = depth_buffer != NULL ? (render_target_t *)any_map_get(render_path_render_targets, depth_buffer) : NULL;
_render_path_current_image = rt->_image;
_gpu_begin(rt->_image, additional_images, db != NULL ? db->_image : NULL, flags, color, depth);
}
@@ -2556,7 +2556,7 @@ void render_path_set_target(char *target, string_array_t *additional, char *dept
void render_path_end(void) {
gpu_end();
_render_path_current_image = NULL;
_render_path_bind_params = NULL;
_render_path_bind_params = NULL;
}
void render_path_draw_meshes(char *context) {
+1 -1
View File
@@ -1,10 +1,10 @@
#pragma once
#include "iron_alloc.h"
#include "iron_armpack.h"
#include "iron_array.h"
#include "iron_audio.h"
#include "iron_draw.h"
#include "iron_alloc.h"
#include "iron_gpu.h"
#include "iron_map.h"
#include "iron_math.h"
+4 -4
View File
@@ -3,11 +3,11 @@
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#include "const_data.h"
#include "iron_alloc.h"
#include "iron_armpack.h"
#include "iron_array.h"
#include "iron_draw.h"
#include "iron_file.h"
#include "iron_alloc.h"
#include "iron_gpu.h"
#include "iron_json.h"
#include "iron_lz4.h"
@@ -871,9 +871,9 @@ gpu_texture_t *iron_load_texture(char *file) {
iron_file_reader_read(&reader, data, size);
iron_file_reader_close(&reader);
buffer_t buf;
buf.buffer = data;
buf.length = size;
gpu_texture_t *texture = gpu_create_texture_from_encoded_bytes(&buf, file);
buf.buffer = data;
buf.length = size;
gpu_texture_t *texture = gpu_create_texture_from_encoded_bytes(&buf, file);
free(data); // Encoded bytes are decoded into a separate buffer
return texture;
}
+1 -2
View File
@@ -1,7 +1,7 @@
#include "iron_draw.h"
#include "const_data.h"
#include "iron_file.h"
#include "iron_alloc.h"
#include "iron_file.h"
#include "iron_gpu.h"
#include "iron_math.h"
#include "iron_simd.h"
@@ -693,7 +693,6 @@ void draw_font_init_glyphs(int from, int to) {
draw_font_glyph_blocks->buffer[0] = from;
draw_font_glyph_blocks->buffer[1] = to - 1;
draw_glyphs_version++;
}
bool draw_font_has_glyph(int glyph) {
+1 -1
View File
@@ -717,7 +717,7 @@ void file_init_cloud_bytes(void (*done)(void), char *append, char *server) {
}
void file_init_cloud(void (*done)(void), char *server) {
file_cloud = any_map_create();
file_cloud = any_map_create();
file_cloud_sizes = i32_map_create();
file_init_cloud_bytes(done, NULL, server);
}
+6 -6
View File
@@ -111,8 +111,8 @@ void input_register(void) {
string_array_push(_mouse_buttons, "side1");
string_array_push(_mouse_buttons, "side2");
_mouse_buttons_down = u8_array_create(0);
_mouse_buttons_started = u8_array_create(0);
_mouse_buttons_down = u8_array_create(0);
_mouse_buttons_started = u8_array_create(0);
_mouse_buttons_released = u8_array_create(0);
for (i32 i = 0; i < 5; ++i) {
u8_array_push(_mouse_buttons_down, 0);
@@ -138,8 +138,8 @@ void input_register(void) {
pen_buttons = string_array_create(0);
string_array_push(pen_buttons, "tip");
pen_buttons_down = u8_array_create(0);
pen_buttons_started = u8_array_create(0);
pen_buttons_down = u8_array_create(0);
pen_buttons_started = u8_array_create(0);
pen_buttons_released = u8_array_create(0);
u8_array_push(pen_buttons_down, 0);
u8_array_push(pen_buttons_started, 0);
@@ -251,8 +251,8 @@ void input_register(void) {
string_array_push(keyboard_keys, "f11");
string_array_push(keyboard_keys, "f12");
keyboard_keys_down = i32_map_create();
keyboard_keys_started = i32_map_create();
keyboard_keys_down = i32_map_create();
keyboard_keys_started = i32_map_create();
keyboard_keys_released = i32_map_create();
keyboard_keys_frame = string_array_create(0);
-1
View File
@@ -7,7 +7,6 @@
#include <stdlib.h>
#include <string.h>
#ifdef IRON_WASM
#define PTR_SIZE 4
#else
+1 -1
View File
@@ -1,7 +1,7 @@
#include "iron_obj.h"
#include "iron_array.h"
#include "iron_alloc.h"
#include "iron_array.h"
#include "iron_math.h"
#include "iron_string.h"
#include <math.h>
+3 -3
View File
@@ -3,9 +3,9 @@
#include <ctype.h>
#include <string.h>
#include "iron_alloc.h"
#include "iron_array.h"
#include "iron_file.h"
#include "iron_alloc.h"
#include "iron_map.h"
#include "iron_string.h"
@@ -219,8 +219,8 @@ char *path_to_relative(char *from, char *to) {
}
char *path_normalize(char *path) {
size_t path_len = strlen(path);
char *trimmed = NULL;
size_t path_len = strlen(path);
char *trimmed = NULL;
if (path_len > 0 && ends_with(path, PATH_SEP)) {
trimmed = substring(path, 0, path_len - 1);
path = trimmed;
+18 -18
View File
@@ -84,17 +84,17 @@ typedef struct {
int active;
} terrain_t;
static sphere_t spheres[MAX_SPHERES];
static box_t boxes[MAX_BOXES];
static sphere_t spheres[MAX_SPHERES];
static box_t boxes[MAX_BOXES];
static physics_pair_t pairs[MAX_BODIES];
static float pair_best[MAX_BODIES];
static float pair_best[MAX_BODIES];
static physics_pair_t null_pair;
static mesh_t mesh;
static terrain_t terrain;
static aabb_t root_bounds = {{-10, -10, -10}, {10, 10, 10}};
static float physics_bounciness = 0.0f;
static float physics_friction = 0.01f;
static vec4_t physics_gravity = {0.0f, 0.0f, GRAVITY};
static mesh_t mesh;
static terrain_t terrain;
static aabb_t root_bounds = {{-10, -10, -10}, {10, 10, 10}};
static float physics_bounciness = 0.0f;
static float physics_friction = 0.01f;
static vec4_t physics_gravity = {0.0f, 0.0f, GRAVITY};
static inline int box_pair(int slot) {
return MAX_SPHERES + slot;
@@ -987,8 +987,8 @@ void physics_world_update() {
// Write the simulated state back into the scene
for (int i = 0; i < scene_meshes->length; i++) {
mesh_object_t *mo = scene_meshes->buffer[i];
physics_body_t *body = mo->base->_->body;
mesh_object_t *mo = scene_meshes->buffer[i];
physics_body_t *body = mo->base->_->body;
if (body != NULL) {
physics_body_update(body);
}
@@ -1327,10 +1327,10 @@ static bool mesh_bounds(object_t *obj, vec4_t *center, vec4_t *extent) {
physics_body_t *physics_body_create(object_t *obj, physics_shape_t shape, float mass) {
physics_body_t *body = ALLOC_INIT(physics_body_t, {0});
body->shape = shape;
body->mass = mass;
body->obj = obj;
obj->_->body = body;
body->shape = shape;
body->mass = mass;
body->obj = obj;
obj->_->body = body;
transform_compute_dim(obj->transform);
body->dimx = obj->transform->dim.x;
@@ -1347,9 +1347,9 @@ physics_body_t *physics_body_create(object_t *obj, physics_shape_t shape, float
}
}
float scale_pos = 1.0f;
void *posa = NULL;
u32_array_t *inda = NULL;
float scale_pos = 1.0f;
void *posa = NULL;
u32_array_t *inda = NULL;
physics_heightfield_t field = {0};
if (shape == PHYSICS_SHAPE_MESH || shape == PHYSICS_SHAPE_TERRAIN) {
+28 -28
View File
@@ -14,8 +14,8 @@ typedef struct {
typedef struct physics_pair_t_array {
physics_pair_t **buffer;
int length;
int capacity;
int length;
int capacity;
} physics_pair_t_array_t;
typedef enum {
@@ -38,35 +38,35 @@ typedef struct {
struct object;
typedef struct physics_body {
void *_body;
physics_shape_t shape;
float mass;
float dimx;
float dimy;
float dimz;
vec4_t offset;
struct object *obj;
void *_body;
physics_shape_t shape;
float mass;
float dimx;
float dimy;
float dimz;
vec4_t offset;
struct object *obj;
} physics_body_t;
void physics_world_create();
void physics_world_destroy();
void physics_world_update();
void physics_world_create();
void physics_world_destroy();
void physics_world_update();
physics_pair_t *physics_world_get_contact(void *body);
physics_pair_t_array_t *physics_get_contact_pairs(physics_body_t *body);
physics_body_t *physics_body_create(struct object *obj, physics_shape_t shape, float mass);
void physics_body_set_mass(physics_body_t *body, float mass);
void physics_body_apply_impulse(void *body, vec4_t impulse);
void physics_body_get_pos(void *body, vec4_t *pos);
void physics_body_get_rot(void *body, quat_t *rot);
void physics_body_get_velocity(void *body, vec4_t *vel);
void physics_body_set_velocity(void *body, float x, float y, float z);
void physics_body_sync_transform(physics_body_t *body);
void physics_body_set_rotation(physics_body_t *body, quat_t rot);
void physics_body_update(physics_body_t *body);
void physics_body_remove(physics_body_t *body);
float physics_body_get_speed(physics_body_t *body);
int physics_terrain_raycast(vec4_t origin, vec4_t dir, vec4_t *hit);
void physics_set_friction(float v);
void physics_set_bounciness(float v);
void physics_set_gravity(float x, float y, float z);
void physics_body_set_mass(physics_body_t *body, float mass);
void physics_body_apply_impulse(void *body, vec4_t impulse);
void physics_body_get_pos(void *body, vec4_t *pos);
void physics_body_get_rot(void *body, quat_t *rot);
void physics_body_get_velocity(void *body, vec4_t *vel);
void physics_body_set_velocity(void *body, float x, float y, float z);
void physics_body_sync_transform(physics_body_t *body);
void physics_body_set_rotation(physics_body_t *body, quat_t rot);
void physics_body_update(physics_body_t *body);
void physics_body_remove(physics_body_t *body);
float physics_body_get_speed(physics_body_t *body);
int physics_terrain_raycast(vec4_t origin, vec4_t dir, vec4_t *hit);
void physics_set_friction(float v);
void physics_set_bounciness(float v);
void physics_set_gravity(float x, float y, float z);
+6 -6
View File
@@ -1,8 +1,8 @@
#include "iron_sys.h"
#include "iron_alloc.h"
#include "iron_array.h"
#include "iron_draw.h"
#include "iron_alloc.h"
#include "iron_input.h"
#include "iron_map.h"
#include "iron_string.h"
@@ -82,12 +82,12 @@ static callback_t *_callback_create(void (*f)(void *data), void *data) {
void sys_start(iron_window_options_t *ops) {
_sys_foreground_listeners = any_array_create(0);
_sys_background_listeners = any_array_create(0);
_sys_shutdown_listeners = any_array_create(0);
_sys_shutdown_listeners = any_array_create(0);
_sys_drop_files_listeners = any_array_create(0);
_sys_on_next_frames = any_array_create(0);
_sys_on_end_frames = any_array_create(0);
_sys_on_updates = any_array_create(0);
_sys_shaders = any_map_create();
_sys_on_next_frames = any_array_create(0);
_sys_on_end_frames = any_array_create(0);
_sys_on_updates = any_array_create(0);
_sys_shaders = any_map_create();
_iron_init(ops);
+1 -1
View File
@@ -1,7 +1,7 @@
#include "iron_tween.h"
#include "iron_array.h"
#include "iron_alloc.h"
#include "iron_array.h"
#include <math.h>
#include <stdbool.h>
+1 -1
View File
@@ -1,7 +1,7 @@
#include "iron_ui.h"
#include "iron_alloc.h"
#include "iron_draw.h"
#include "iron_file.h"
#include "iron_alloc.h"
#include "iron_gpu.h"
#include "iron_string.h"
#include "iron_system.h"
+1 -1
View File
@@ -1,5 +1,5 @@
#include "iron_draw.h"
#include "iron_alloc.h"
#include "iron_draw.h"
#include "iron_string.h"
#include "iron_system.h"
#include "iron_ui.h"
+2 -2
View File
@@ -1,9 +1,9 @@
#include "iron_ui.h"
#include "iron_alloc.h"
#include "iron_armpack.h"
#include "iron_array.h"
#include "iron_draw.h"
#include "iron_alloc.h"
#include "iron_gpu.h"
#include "iron_json.h"
#include "iron_string.h"
@@ -1268,7 +1268,7 @@ void ui_node_canvas(ui_nodes_t *nodes, ui_node_canvas_t *canvas) {
ui_node_link_array_t links = {.buffer = copy_links, .length = copy_links_count};
copy_canvas.nodes = &nodes;
copy_canvas.links = &links;
ui_clipboard = ui_node_canvas_to_json(&copy_canvas);
ui_clipboard = ui_node_canvas_to_json(&copy_canvas);
iron_copy_to_clipboard(ui_clipboard);
}
cut_selected = ui_is_cut;
+25 -25
View File
@@ -17,27 +17,28 @@
// ██║ ╚██████╔╝██║ ██╗███████╗██║ ╚████║
// ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═══╝
#define MINIC_TOK_LIST \
X(TOK_INT, "'int'") \
X(TOK_FLOAT, "'float'") \
X(TOK_CHAR, "'char'") \
X(TOK_DOUBLE, "'double'") \
X(TOK_BOOL, "'bool'") \
X(TOK_RETURN, "'return'") \
X(TOK_IF, "'if'") \
X(TOK_ELSE, "'else'") \
X(TOK_WHILE, "'while'") \
X(TOK_FOR, "'for'") \
X(TOK_BREAK, "'break'") X(TOK_CONTINUE, "'continue'") X(TOK_STRUCT, "'struct'") X(TOK_TYPEDEF, "'typedef'") X(TOK_ENUM, "'enum'") X(TOK_VOID, "'void'") \
X(TOK_IDENT, "identifier") X(TOK_NUMBER, "number") X(TOK_CHAR_LIT, "char literal") X(TOK_STR_LIT, "string literal") X(TOK_LPAREN, "'('") \
X(TOK_RPAREN, "')'") X(TOK_LBRACE, "'{'") X(TOK_RBRACE, "'}'") X(TOK_LBRACKET, "'['") X(TOK_RBRACKET, "']'") X(TOK_SEMICOLON, "';'") \
X(TOK_COMMA, "','") X(TOK_ASSIGN, "'='") X(TOK_PLUS_ASSIGN, "'+='") X(TOK_MINUS_ASSIGN, "'-='") X(TOK_MUL_ASSIGN, "'*='") \
X(TOK_DIV_ASSIGN, "'/='") X(TOK_MOD_ASSIGN, "'%='") X(TOK_SHL_ASSIGN, "'<<='") X(TOK_SHR_ASSIGN, "'>>='") X(TOK_AND_ASSIGN, "'&='") \
X(TOK_OR_ASSIGN, "'|='") X(TOK_XOR_ASSIGN, "'^='") X(TOK_EQ, "'=='") X(TOK_NEQ, "'!='") X(TOK_LT, "'<'") X(TOK_GT, "'>'") \
X(TOK_LE, "'<='") X(TOK_GE, "'>='") X(TOK_AND, "'&&'") X(TOK_OR, "'||'") X(TOK_NOT, "'!'") X(TOK_AMP, "'&'") X(TOK_PLUS, "'+'") \
X(TOK_MINUS, "'-'") X(TOK_INC, "'++'") X(TOK_DEC, "'--'") X(TOK_STAR, "'*'") X(TOK_SLASH, "'/'") X(TOK_PERCENT, "'%'") \
X(TOK_SHL, "'<<'") X(TOK_SHR, "'>>'") X(TOK_BITOR, "'|'") X(TOK_XOR, "'^'") X(TOK_BITNOT, "'~'") X(TOK_DOT, "'.'") \
X(TOK_ARROW, "'->'") X(TOK_EOF, "end of file")
#define MINIC_TOK_LIST \
X(TOK_INT, "'int'") \
X(TOK_FLOAT, "'float'") \
X(TOK_CHAR, "'char'") \
X(TOK_DOUBLE, "'double'") \
X(TOK_BOOL, "'bool'") \
X(TOK_RETURN, "'return'") \
X(TOK_IF, "'if'") \
X(TOK_ELSE, "'else'") \
X(TOK_WHILE, "'while'") \
X(TOK_FOR, "'for'") \
X(TOK_BREAK, "'break'") \
X(TOK_CONTINUE, "'continue'") X(TOK_STRUCT, "'struct'") X(TOK_TYPEDEF, "'typedef'") X(TOK_ENUM, "'enum'") X(TOK_VOID, "'void'") X(TOK_IDENT, "identifier") \
X(TOK_NUMBER, "number") X(TOK_CHAR_LIT, "char literal") X(TOK_STR_LIT, "string literal") X(TOK_LPAREN, "'('") X(TOK_RPAREN, "')'") \
X(TOK_LBRACE, "'{'") X(TOK_RBRACE, "'}'") X(TOK_LBRACKET, "'['") X(TOK_RBRACKET, "']'") X(TOK_SEMICOLON, "';'") X(TOK_COMMA, "','") \
X(TOK_ASSIGN, "'='") X(TOK_PLUS_ASSIGN, "'+='") X(TOK_MINUS_ASSIGN, "'-='") X(TOK_MUL_ASSIGN, "'*='") X(TOK_DIV_ASSIGN, "'/='") \
X(TOK_MOD_ASSIGN, "'%='") X(TOK_SHL_ASSIGN, "'<<='") X(TOK_SHR_ASSIGN, "'>>='") X(TOK_AND_ASSIGN, "'&='") X(TOK_OR_ASSIGN, "'|='") \
X(TOK_XOR_ASSIGN, "'^='") X(TOK_EQ, "'=='") X(TOK_NEQ, "'!='") X(TOK_LT, "'<'") X(TOK_GT, "'>'") X(TOK_LE, "'<='") X(TOK_GE, "'>='") \
X(TOK_AND, "'&&'") X(TOK_OR, "'||'") X(TOK_NOT, "'!'") X(TOK_AMP, "'&'") X(TOK_PLUS, "'+'") X(TOK_MINUS, "'-'") X(TOK_INC, "'++'") \
X(TOK_DEC, "'--'") X(TOK_STAR, "'*'") X(TOK_SLASH, "'/'") X(TOK_PERCENT, "'%'") X(TOK_SHL, "'<<'") X(TOK_SHR, "'>>'") \
X(TOK_BITOR, "'|'") X(TOK_XOR, "'^'") X(TOK_BITNOT, "'~'") X(TOK_DOT, "'.'") X(TOK_ARROW, "'->'") \
X(TOK_EOF, "end of file")
typedef enum {
#define X(t, s) t,
@@ -63,7 +64,6 @@ typedef struct {
minic_token_t cur;
} minic_lexer_t;
static minic_u8 *minic_active_mem = NULL;
static int *minic_active_mem_used = NULL;
@@ -842,8 +842,8 @@ static minic_val_t minic_call_in_ctx(minic_ctx_t *ctx, minic_func_t *fn, minic_v
int saved_used = ctx->mem_used;
minic_val_t r = minic_call(&ctx->e, fn, args, argc);
ctx->mem_used = saved_used;
minic_active_mem = prev_mem;
minic_active_mem_used = prev_mem_used;
minic_active_mem = prev_mem;
minic_active_mem_used = prev_mem_used;
return r;
}
@@ -2038,7 +2038,7 @@ minic_ctx_t *minic_eval_named(const char *src, const char *filename) {
minic_register_builtins();
minic_ctx_t *ctx = (minic_ctx_t *)calloc(1, sizeof(minic_ctx_t));
ctx->mem = (minic_u8 *)calloc(1, MINIC_MEM_SIZE);
ctx->mem = (minic_u8 *)calloc(1, MINIC_MEM_SIZE);
// Copy the source so the context stays valid after the caller frees its buffer
int src_len = (int)strlen(src);
ctx->src_copy = (char *)malloc(src_len + 1);