diff options
Diffstat (limited to 'src/systems')
-rw-r--r-- | src/systems/input.c | 12 | ||||
-rw-r--r-- | src/systems/input.h | 13 | ||||
-rw-r--r-- | src/systems/terrain.c | 35 | ||||
-rw-r--r-- | src/systems/terrain.h | 50 | ||||
-rw-r--r-- | src/systems/text.h | 82 |
5 files changed, 96 insertions, 96 deletions
diff --git a/src/systems/input.c b/src/systems/input.c index 0c8f768..a371ecd 100644 --- a/src/systems/input.c +++ b/src/systems/input.c @@ -6,11 +6,11 @@ #include "log.h" -static input_state *g_input; // Use a global to simplify caller code +static Input_State *g_input; // Use a global to simplify caller code -bool input_system_init(input_state *input, GLFWwindow *window) { +bool Input_Init(Input_State *input, GLFWwindow *window) { INFO("Input init"); - memset(input, 0, sizeof(input_state)); + memset(input, 0, sizeof(Input_State)); input->window = window; // Set everything to false. Could just set memory to zero but where's the fun in that @@ -29,9 +29,9 @@ bool input_system_init(input_state *input, GLFWwindow *window) { return true; } -void input_system_shutdown(input_state *input) {} +void Input_Shutdown(Input_State *input) {} -void input_update(input_state *input) { +void Input_Update(Input_State *input) { glfwPollEvents(); // --- update keyboard input @@ -95,4 +95,4 @@ bool key_is_pressed(keycode key) { return g_input->depressed_keys[key]; } bool key_just_pressed(keycode key) { return g_input->just_pressed_keys[key]; } -bool key_just_released(keycode key) { return g_input->just_released_keys[key]; }
\ No newline at end of file +bool key_just_released(keycode key) { return g_input->just_released_keys[key]; } diff --git a/src/systems/input.h b/src/systems/input.h index c119016..11c40ea 100644 --- a/src/systems/input.h +++ b/src/systems/input.h @@ -6,7 +6,6 @@ #include "defines.h" #include "keys.h" -struct core; struct GLFWWindow; typedef struct mouse_state { @@ -18,13 +17,13 @@ typedef struct mouse_state { bool left_btn_pressed; } mouse_state; -typedef struct input_state { +typedef struct Input_State { struct GLFWwindow *window; mouse_state mouse; bool depressed_keys[KEYCODE_MAX]; bool just_pressed_keys[KEYCODE_MAX]; bool just_released_keys[KEYCODE_MAX]; -} input_state; +} Input_State; /** @brief `key` is currently being held down */ bool key_is_pressed(keycode key); @@ -36,6 +35,8 @@ bool key_just_pressed(keycode key); bool key_just_released(keycode key); // --- Lifecycle -bool input_system_init(input_state *input, struct GLFWwindow *window); -void input_system_shutdown(input_state *input); -void input_update(input_state *state);
\ No newline at end of file + +bool Input_Init(Input_State *input, struct GLFWwindow *window); +void Input_Shutdown(Input_State *input); + +void Input_Update(Input_State *state); // must be run once per main loop diff --git a/src/systems/terrain.c b/src/systems/terrain.c index 6342d66..1d23cc3 100644 --- a/src/systems/terrain.c +++ b/src/systems/terrain.c @@ -1,24 +1,27 @@ /** - * @file terrain.c - * @author your name (you@domain.com) * @brief - * @version 0.1 - * @date 2024-06-22 - * - * @copyright Copyright (c) 2024 - * */ #include "terrain.h" #include "ral.h" -bool terrain_system_init(terrain_state* state) { - gpu_renderpass_desc rpass_desc = { - .default_framebuffer = true, - }; - struct graphics_pipeline_desc pipeline_desc = { +struct Terrain_Storage { + arena terrain_allocator; + Heightmap* heightmap; // NULL = no heightmap + GPU_Renderpass* hmap_renderpass; + GPU_Pipeline* hmap_pipeline; +}; - }; +PUB bool Terrain_Init(Terrain_Storage* storage) { return true; } +PUB void Terrain_Shutdown(Terrain_Storage* storage); - state->hmap_renderpass = gpu_renderpass_create(&rpass_desc); - state->hmap_pipeline = gpu_graphics_pipeline_create(pipeline_desc); -}
\ No newline at end of file +/* bool terrain_system_init(terrain_state* state) { */ +/* gpu_renderpass_desc rpass_desc = { */ +/* .default_framebuffer = true, */ +/* }; */ +/* struct graphics_pipeline_desc pipeline_desc = { */ + +/* }; */ + +/* state->hmap_renderpass = gpu_renderpass_create(&rpass_desc); */ +/* state->hmap_pipeline = gpu_graphics_pipeline_create(pipeline_desc); */ +/* } */ diff --git a/src/systems/terrain.h b/src/systems/terrain.h index 888b6f4..890cb90 100644 --- a/src/systems/terrain.h +++ b/src/systems/terrain.h @@ -1,14 +1,10 @@ /** * @file terrain.h - * @author your name (you@domain.com) * @brief - * @version 0.1 - * @date 2024-04-27 - * - * @copyright Copyright (c) 2024 - * */ +#pragma once + /* Future: - Chunked terrain @@ -22,37 +18,37 @@ Future: #include "render.h" #include "str.h" -typedef struct heightmap { - str8 filepath; +typedef struct Heightmap { + Str8 filepath; u32x2 size; void* image_data; bool is_uploaded; -} heightmap; +} Heightmap; + +typedef struct Terrain_Storage Terrain_Storage; + +// --- Public API +PUB bool Terrain_Init(Terrain_Storage* storage); +PUB void Terrain_Shutdown(Terrain_Storage* storage); +PUB void Terrain_Run(Terrain_Storage* storage); // NOTE: For now it renders directly to main framebuffer -typedef struct terrain_state { - arena terrain_allocator; - heightmap* heightmap; // NULL = no heightmap - gpu_renderpass* hmap_renderpass; - gpu_pipeline* hmap_pipeline; -} terrain_state; +/** @brief Sets the active heightmap to be rendered and collided against. */ +PUB Heightmap Terrain_LoadHeightmap(Heightmap hmap, bool free_on_upload); +PUB Heightmap Heightmap_FromImage(Str8 filepath); +PUB Heightmap Heightmap_FromPerlin(/* TODO: perlin noise generation parameters */); -bool terrain_system_init(terrain_state* state); -void terrain_system_shutdown(terrain_state* state); -void terrain_system_render_hmap(renderer* rend, terrain_state* state); +PUB bool Terrain_IsActive(); // checks whether we have a loaded heightmap and it's being rendered -heightmap heightmap_from_image(str8 filepath); -heightmap heightmap_from_perlin(/* TODO: perlin noise generation parameters */); +// --- Internal + +// TODO: void terrain_system_render_hmap(renderer* rend, terrain_state* state); /** @brief Get the height (the Y component) for a vertex at a particular coordinate in the heightmap */ -f32 heightmap_height_at_xz(heightmap* hmap, f32 x, f32 z); +f32 Heightmap_HeightXZ(Heightmap* hmap, f32 x, f32 z); /** @brief Calculate the normal vector of a vertex at a particular coordinate in the heightmap */ -vec3 heightmap_normal_at_xz(heightmap* hmap, f32 x, f32 z); +Vec3 Heightmap_NormalXZ(Heightmap* hmap, f32 x, f32 z); /** @brief Generate the `geometry_data` for a heightmap ready to be uploaded to the GPU */ -geometry_data geo_heightmap(arena* a, heightmap heightmap); - -// somewhere there will be an easy way to add a heightmap - -// TODO: scene_add_heightmap +Geometry geo_heightmap(arena* a, Heightmap heightmap); diff --git a/src/systems/text.h b/src/systems/text.h index f40cfd6..983ffd6 100644 --- a/src/systems/text.h +++ b/src/systems/text.h @@ -10,44 +10,44 @@ #include "ral.h" #include "render_types.h" -struct core; - -/** @brief internal font struct */ -typedef struct font { - const char *name; - stbtt_fontinfo stbtt_font; - stbtt_bakedchar c_data[96]; - texture_handle bitmap_tex; -} font; - -typedef struct draw_text_packet { - char *contents; - f32 x; - f32 y; -} draw_text_packet; - -KITC_DECL_TYPED_ARRAY(draw_text_packet) - -typedef struct text_system_state { - font default_font; - shader_handle glyph_shader; - u32 glyph_vbo; - u32 glyph_vao; - draw_text_packet_darray *draw_cmd_buf; - // TODO: fonts array or hashtable -} text_system_state; - -void text_system_render(text_system_state *text); - -// --- Lifecycle functions -bool text_system_init(text_system_state *text); -void text_system_shutdown(text_system_state *text); - -// --- Drawing - -/** - * @brief immediate mode draw text. - * @note immediately emits draw calls causing a shader program switch if you weren't previously - drawing text in the current frame. -*/ -void draw_text(struct core *core, f32 x, f32 y, char *contents);
\ No newline at end of file +// struct core; + +// /** @brief internal font struct */ +// typedef struct font { +// const char *name; +// stbtt_fontinfo stbtt_font; +// stbtt_bakedchar c_data[96]; +// texture_handle bitmap_tex; +// } font; + +// typedef struct draw_text_packet { +// char *contents; +// f32 x; +// f32 y; +// } draw_text_packet; + +// KITC_DECL_TYPED_ARRAY(draw_text_packet) + +// typedef struct text_system_state { +// font default_font; +// shader_handle glyph_shader; +// u32 glyph_vbo; +// u32 glyph_vao; +// draw_text_packet_darray *draw_cmd_buf; +// // TODO: fonts array or hashtable +// } text_system_state; + +// void text_system_render(text_system_state *text); + +// // --- Lifecycle functions +// bool text_system_init(text_system_state *text); +// void text_system_shutdown(text_system_state *text); + +// // --- Drawing + +// /** +// * @brief immediate mode draw text. +// * @note immediately emits draw calls causing a shader program switch if you weren't previously +// drawing text in the current frame. +// */ +// void draw_text(struct core *core, f32 x, f32 y, char *contents); |