diff options
author | Joshua Rowe <17525998+omnisci3nce@users.noreply.github.com> | 2024-05-20 10:50:11 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-20 10:50:11 +1000 |
commit | e904c22003c3a134201b222e6619e782fbe63947 (patch) | |
tree | 5295c8ce5f855ca4a0f1bebe50beee80bae66682 /src/systems | |
parent | 02e84ee4d18e705e3362be1e327fdb6f1397a032 (diff) | |
parent | 73d4145f46d2305f45761b8e456df692d1962dfb (diff) |
Merge pull request #14 from omnisci3nce/realign
Realign
Diffstat (limited to 'src/systems')
-rw-r--r-- | src/systems/input.c | 21 | ||||
-rw-r--r-- | src/systems/keys.h | 15 | ||||
-rw-r--r-- | src/systems/screenspace.h | 4 | ||||
-rw-r--r-- | src/systems/terrain.c | 0 | ||||
-rw-r--r-- | src/systems/terrain.h | 55 | ||||
-rw-r--r-- | src/systems/text.h | 3 |
6 files changed, 94 insertions, 4 deletions
diff --git a/src/systems/input.c b/src/systems/input.c index 292d438..0c8f768 100644 --- a/src/systems/input.c +++ b/src/systems/input.c @@ -1,11 +1,17 @@ #include "input.h" +#include <assert.h> #include <glfw3.h> +#include <string.h> #include "log.h" +static input_state *g_input; // Use a global to simplify caller code + bool input_system_init(input_state *input, GLFWwindow *window) { INFO("Input init"); + 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 for (int i = 0; i < KEYCODE_MAX; i++) { @@ -14,10 +20,19 @@ bool input_system_init(input_state *input, GLFWwindow *window) { input->just_released_keys[i] = false; } + g_input = input; + + assert(input->mouse.x_delta == 0); + assert(input->mouse.y_delta == 0); + + INFO("Finish input init"); return true; } +void input_system_shutdown(input_state *input) {} + void input_update(input_state *input) { + glfwPollEvents(); // --- update keyboard input // if we go from un-pressed -> pressed, set as "just pressed" @@ -75,3 +90,9 @@ void input_update(input_state *input) { input->mouse = new_mouse_state; } + +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 diff --git a/src/systems/keys.h b/src/systems/keys.h index 090bb49..a76e101 100644 --- a/src/systems/keys.h +++ b/src/systems/keys.h @@ -2,5 +2,18 @@ typedef enum keycode { // TODO: add all keycodes - KEYCODE_MAX + KEYCODE_SPACE = 32, + KEYCODE_A = 65, + KEYCODE_D = 68, + KEYCODE_S = 83, + KEYCODE_W = 87, + KEYCODE_ESCAPE = 256, + KEYCODE_ENTER = 257, + KEYCODE_TAB = 258, + KEYCODE_BACKSPACE = 259, + KEYCODE_KEY_RIGHT = 262, + KEYCODE_KEY_LEFT = 263, + KEYCODE_KEY_DOWN = 264, + KEYCODE_KEY_UP = 265, + KEYCODE_MAX = 348 } keycode;
\ No newline at end of file diff --git a/src/systems/screenspace.h b/src/systems/screenspace.h index 2250847..5f0c579 100644 --- a/src/systems/screenspace.h +++ b/src/systems/screenspace.h @@ -25,7 +25,7 @@ struct draw_circle { /** @brief Tagged union that represents a UI shape to be drawn. */ typedef struct draw_cmd { - enum { RECT, CIRCLE } draw_cmd_type; + enum { DRAW_RECT, CIRCLE } draw_cmd_type; union { struct draw_rect rect; struct draw_circle circle; @@ -37,7 +37,7 @@ KITC_DECL_TYPED_ARRAY(draw_cmd) typedef struct screenspace_state { u32 rect_vbo; u32 rect_vao; - shader rect_shader; + // shader rect_shader; draw_cmd_darray* draw_cmd_buf; } screenspace_state; diff --git a/src/systems/terrain.c b/src/systems/terrain.c new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/systems/terrain.c diff --git a/src/systems/terrain.h b/src/systems/terrain.h new file mode 100644 index 0000000..bfd90b5 --- /dev/null +++ b/src/systems/terrain.h @@ -0,0 +1,55 @@ +/** + * @file terrain.h + * @author your name (you@domain.com) + * @brief + * @version 0.1 + * @date 2024-04-27 + * + * @copyright Copyright (c) 2024 + * + */ + +/* +Future: + - Chunked terrain + - Dynamic LOD +*/ + +#include "defines.h" +#include "maths_types.h" +#include "mem.h" +#include "render_types.h" +#include "str.h" + +typedef struct heightmap { + str8 filepath; + u32x2 size; + void* image_data; + bool is_uploaded; +} heightmap; + +typedef struct terrain_state { + arena terrain_allocator; + heightmap* heightmap; // NULL = no heightmap +} terrain_state; + +bool terrain_system_init(terrain_state* state); +void terrain_system_shutdown(terrain_state* state); +void terrain_system_render_hmap(renderer* rend, terrain_state* state); + +heightmap heightmap_from_image(str8 filepath); +heightmap heightmap_from_perlin(/* TODO: perlin noise generation parameters */); + +/** @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); + +/** @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); + +/** @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 + +// scene_add_heightmap
\ No newline at end of file diff --git a/src/systems/text.h b/src/systems/text.h index 19248a6..f40cfd6 100644 --- a/src/systems/text.h +++ b/src/systems/text.h @@ -7,6 +7,7 @@ #include "darray.h" #include "defines.h" +#include "ral.h" #include "render_types.h" struct core; @@ -29,7 +30,7 @@ KITC_DECL_TYPED_ARRAY(draw_text_packet) typedef struct text_system_state { font default_font; - shader glyph_shader; + shader_handle glyph_shader; u32 glyph_vbo; u32 glyph_vao; draw_text_packet_darray *draw_cmd_buf; |