From 45ca42df990b7e938bd75e84471f77dd64ec5043 Mon Sep 17 00:00:00 2001 From: Sven Balzer <4653051+Kyuusokuna@users.noreply.github.com> Date: Sun, 16 Mar 2025 12:14:40 +0100 Subject: [PATCH] mark things as static --- src/main.cpp | 104 +++++++++++++++++++++++++-------------------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index df7e43e..c0f914c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,42 +23,42 @@ using namespace M; #define NEAR_PLANE (0.01f) -SDL_GPUDevice *device; -SDL_Window *window; +static SDL_GPUDevice *device; +static SDL_Window *window; -SDL_GPUGraphicsPipeline *basic_graphics_pipeline; -SDL_GPUGraphicsPipeline *world_graphics_pipeline; -SDL_GPUSampler *point_sampler; +static SDL_GPUGraphicsPipeline *basic_graphics_pipeline; +static SDL_GPUGraphicsPipeline *world_graphics_pipeline; +static SDL_GPUSampler *point_sampler; -SDL_GPUBuffer *vertex_buffer; -SDL_GPUBuffer *index_buffer; -SDL_GPUBuffer *player_instance_buffer; -SDL_GPUBuffer *world_buffer; -SDL_GPUBuffer *tile_infos_buffer; +static SDL_GPUBuffer *vertex_buffer; +static SDL_GPUBuffer *index_buffer; +static SDL_GPUBuffer *player_instance_buffer; +static SDL_GPUBuffer *world_buffer; +static SDL_GPUBuffer *tile_infos_buffer; -Sint32 window_width; -Sint32 window_height; +static Sint32 window_width; +static Sint32 window_height; -bool Running = true; +static bool Running = true; -M4x4 view_matrix = view (V3_(0.0f, 0.0f, 0.0f), radians(45.0f), 10.0f); -M4x4 inverse_view_matrix = inverse_view(V3_(0.0f, 0.0f, 0.0f), radians(45.0f), 10.0f); +static M4x4 view_matrix = view (V3_(0.0f, 0.0f, 0.0f), radians(45.0f), 10.0f); +static M4x4 inverse_view_matrix = inverse_view(V3_(0.0f, 0.0f, 0.0f), radians(45.0f), 10.0f); -M4x4 projection_matrix = projection (radians(45.0f), 16.0f / 9.0f, NEAR_PLANE); -M4x4 inverse_projection_matrix = inverse_projection(radians(45.0f), 16.0f / 9.0f, NEAR_PLANE); +static M4x4 projection_matrix = projection (radians(45.0f), 16.0f / 9.0f, NEAR_PLANE); +static M4x4 inverse_projection_matrix = inverse_projection(radians(45.0f), 16.0f / 9.0f, NEAR_PLANE); struct Vertex { V3 pos; }; -Vertex vertices[] = { +static Vertex vertices[] = { {{ -0.5f, 0.5f, 0 }}, {{ 0.5f, 0.5f, 0 }}, {{ 0.5f, -0.5f, 0 }}, {{ -0.5f, -0.5f, 0 }}, }; -Uint16 indices[] = { +static Uint16 indices[] = { 0, 1, 2, 0, 2, 3, }; @@ -69,19 +69,19 @@ struct Instance { V4 uv2uv3; }; -Instance player_instance = { { 0.0f, 0.0f }, { 0, 0, 1, 0 }, { 1, 1, 0, 1 }}; +static Instance player_instance = { { 0.0f, 0.0f }, { 0, 0, 1, 0 }, { 1, 1, 0, 1 }}; -Sint32 map_width; -Sint32 map_height; +static Sint32 map_width; +static Sint32 map_height; -Uint32* map_tiles; +static Uint32* map_tiles; struct Player { Sint32 pos_x; Sint32 pos_y; }; -Player player; +static Player player; struct PerFrame { float aspect_ratio; @@ -93,7 +93,7 @@ struct PerFrame { Uint32 map_width; }; -PerFrame per_frame = { +static PerFrame per_frame = { .aspect_ratio = 16.0f / 9.0f, .fovy_degrees = 31.0f, .camera_x = 0.0f, @@ -110,7 +110,7 @@ typedef struct { V2 uv_max; } TileInfo; -TileInfo tile_infos[] = { +static TileInfo tile_infos[] = { { 0x0001, "../assets/tiles/error.png" }, { 0x0000, "../assets/tiles/empty.png" }, { 0x0100, "../assets/tiles/grass_1.png" }, @@ -122,18 +122,18 @@ TileInfo tile_infos[] = { { 0x0400, "../assets/tiles/grass_ground_1.png" }, }; -int tile_atlas_size = 256; -smol_atlas_t *tile_atlas; +static int tile_atlas_size = 256; +static smol_atlas_t *tile_atlas; -V4 cpu_tile_infos_buffer[SDL_arraysize(tile_infos)]; +static V4 cpu_tile_infos_buffer[SDL_arraysize(tile_infos)]; -Sint32 selected_tile = -1; -Sint32 selected_rotation = 0; +static Sint32 selected_tile = -1; +static Sint32 selected_rotation = 0; -bool dragging_tile_change = false; -Sint32 drag_start_pos[2]; +static bool dragging_tile_change = false; +static Sint32 drag_start_pos[2]; -void save_map() { +static void save_map() { log("Save file is under construction."); FILE* file = fopen("../assets/map/map.sv", "wb"); @@ -167,7 +167,7 @@ void save_map() { log("Saving map was successful."); } -void load_map() { +static void load_map() { log("Load save file."); String file = load_entire_file("../assets/map/map.sv"); if (!file.length) { @@ -206,7 +206,7 @@ void load_map() { log("Loading map was successful."); } -bool update_buffer(SDL_GPUBuffer *buffer, Uint32 offset, Uint32 num_bytes, void *data) { +static bool update_buffer(SDL_GPUBuffer *buffer, Uint32 offset, Uint32 num_bytes, void *data) { SDL_GPUTransferBufferCreateInfo transfer_buffer_info = { .usage = SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD, .size = num_bytes, @@ -260,7 +260,7 @@ bool update_buffer(SDL_GPUBuffer *buffer, Uint32 offset, Uint32 num_bytes, void return true; } -SDL_GPUBuffer *create_buffer(SDL_GPUBufferUsageFlags usage, Uint32 num_bytes, void *data = NULL, const char *name = NULL) { +static SDL_GPUBuffer *create_buffer(SDL_GPUBufferUsageFlags usage, Uint32 num_bytes, void *data = NULL, const char *name = NULL) { SDL_PropertiesID properties = 0; if (name) { properties = SDL_CreateProperties(); @@ -288,7 +288,7 @@ SDL_GPUBuffer *create_buffer(SDL_GPUBufferUsageFlags usage, Uint32 num_bytes, vo return buffer; } -void change_map_size(char direction, int amount) { +static void change_map_size(char direction, int amount) { SDL_GPUBuffer *old_world_buffer = world_buffer; Uint32* old_map = map_tiles; auto old_map_width = map_width; @@ -365,7 +365,7 @@ void change_map_size(char direction, int amount) { SDL_ReleaseGPUBuffer(device, old_world_buffer); } -SDL_GPUTexture *create_shader_texture(const char *path) { +static SDL_GPUTexture *create_shader_texture(const char *path) { int width = 0, height = 0, channels = 0; stbi_uc *data = stbi_load(path, &width, &height, &channels, 0); if (!data) { @@ -469,7 +469,7 @@ SDL_GPUTexture *create_shader_texture(const char *path) { return texture; } -SDL_GPUTexture *create_shader_texture(const char *name, const char *data, int width, int height, int channels) { +static SDL_GPUTexture *create_shader_texture(const char *name, const char *data, int width, int height, int channels) { SDL_GPUTextureFormat format = SDL_GPU_TEXTUREFORMAT_INVALID; if (channels == 1) format = SDL_GPU_TEXTUREFORMAT_A8_UNORM; if (channels == 4) format = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM_SRGB; @@ -561,12 +561,12 @@ SDL_GPUTexture *create_shader_texture(const char *name, const char *data, int wi return texture; } -void blit(char *dst, Sint32 dst_pitch, Sint32 dst_x, Sint32 dst_y, char *src, Sint32 src_pitch, Sint32 width, Sint32 height, int components = 4) { +static void blit(char *dst, Sint32 dst_pitch, Sint32 dst_x, Sint32 dst_y, char *src, Sint32 src_pitch, Sint32 width, Sint32 height, int components = 4) { for (Sint32 y = 0; y < height; y++) memmove(&dst[((dst_y + y) * dst_pitch + dst_x) * components], &src[y * src_pitch * components], width * components); } -bool SelectableImage(const char *label, bool selected, SDL_GPUTextureSamplerBinding *image, const ImVec2& image_size, const ImVec2& uv0 = ImVec2(0, 0), const ImVec2& uv1 = ImVec2(1, 1), Uint8 orientation = 0) { +static bool SelectableImage(const char *label, bool selected, SDL_GPUTextureSamplerBinding *image, const ImVec2& image_size, const ImVec2& uv0 = ImVec2(0, 0), const ImVec2& uv1 = ImVec2(1, 1), Uint8 orientation = 0) { const ImGuiContext *context = ImGui::GetCurrentContext(); const ImVec2 padding = context->Style.FramePadding; @@ -588,7 +588,7 @@ bool SelectableImage(const char *label, bool selected, SDL_GPUTextureSamplerBind return pressed; } -ImVec4 linear_to_sRGB(ImVec4 linear) { +static ImVec4 linear_to_sRGB(ImVec4 linear) { float red = linear.x <= 0.0031308f ? 12.92f * linear.x : 1.055f * powf(linear.x, 1.0f / 2.4f) - 0.055; float green = linear.y <= 0.0031308f ? 12.92f * linear.y : 1.055f * powf(linear.y, 1.0f / 2.4f) - 0.055; float blue = linear.z <= 0.0031308f ? 12.92f * linear.z : 1.055f * powf(linear.z, 1.0f / 2.4f) - 0.055; @@ -596,7 +596,7 @@ ImVec4 linear_to_sRGB(ImVec4 linear) { return ImVec4(red, green, blue, linear.w); } -ImVec4 sRGB_to_linear(ImVec4 linear) { +static ImVec4 sRGB_to_linear(ImVec4 linear) { float red = linear.x <= 0.0031308f ? linear.x / 12.92f : powf((linear.x + 0.055) / 1.055, 2.4f); float green = linear.y <= 0.0031308f ? linear.y / 12.92f : powf((linear.y + 0.055) / 1.055, 2.4f); float blue = linear.z <= 0.0031308f ? linear.z / 12.92f : powf((linear.z + 0.055) / 1.055, 2.4f); @@ -604,14 +604,14 @@ ImVec4 sRGB_to_linear(ImVec4 linear) { return ImVec4(red, green, blue, linear.w); } -V3 Unproject(V3 screen_pos) { +static V3 Unproject(V3 screen_pos) { V4 result = inverse_view_matrix * inverse_projection_matrix * V4_(screen_pos, 1.0f); result.xyz /= result.w; return result.xyz; } -V2 get_floor_intersection_of_mouse(V2 mouse_pos) { +static V2 get_floor_intersection_of_mouse(V2 mouse_pos) { V2 mouse = remap(V2{ 0, 0 }, V2{ (float)window_width, (float)window_height }, V2{ -1, 1 }, V2{ 1, -1 }, V2{ mouse_pos.x, mouse_pos.y }); V3 camera_position = (inverse_view_matrix * V4_(0, 0, 0, 1)).xyz; @@ -627,12 +627,12 @@ V2 get_floor_intersection_of_mouse(V2 mouse_pos) { } #ifdef TRACY_ENABLE -SDL_malloc_func sdl_malloc = NULL; -SDL_calloc_func sdl_calloc = NULL; -SDL_realloc_func sdl_realloc = NULL; -SDL_free_func sdl_free = NULL; +static SDL_malloc_func sdl_malloc = NULL; +static SDL_calloc_func sdl_calloc = NULL; +static SDL_realloc_func sdl_realloc = NULL; +static SDL_free_func sdl_free = NULL; -void setup_memory_functions() { +static void setup_memory_functions() { SDL_GetMemoryFunctions(&sdl_malloc, &sdl_calloc, &sdl_realloc, &sdl_free); SDL_SetMemoryFunctions( [](size_t size) -> void * { @@ -658,7 +658,7 @@ void setup_memory_functions() { ); } #else -void setup_memory_functions() {} +static void setup_memory_functions() {} #endif int main(int argc, char **argv) {