From 2a660da1d81adafbd8f9d33fc9293219a2761531 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Tue, 24 Oct 2023 00:42:55 -0400 Subject: [PATCH] Got clang to build parity with msvc --- .vscode/bookmarks.json | 2 +- .vscode/c_cpp_properties.json | 4 +++- project/engine/engine.cpp | 14 +++++++------- project/platform/compiler_ignores.hpp | 1 + project/platform/win32/win32.hpp | 2 +- project/platform/win32/win32_platform.cpp | 10 ++++++++++ project/platform/win32/win32_platform_api.cpp | 8 +++++++- scripts/build.ps1 | 4 ++-- 8 files changed, 32 insertions(+), 13 deletions(-) diff --git a/.vscode/bookmarks.json b/.vscode/bookmarks.json index ee7830c..b6e4838 100644 --- a/.vscode/bookmarks.json +++ b/.vscode/bookmarks.json @@ -14,7 +14,7 @@ "label": "Static Data" }, { - "line": 1001, + "line": 1011, "column": 0, "label": "Main Loop : End" } diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 3d06898..7dbebee 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -34,7 +34,9 @@ "UNICODE", "_UNICODE", "GEN_TIME", - "INTELLISENSE_DIRECTIVES" + "INTELLISENSE_DIRECTIVES", + "Build_Debug", + "Build_Development" ], "windowsSdkVersion": "10.0.22621.0", "compilerPath": "clang.exe", diff --git a/project/engine/engine.cpp b/project/engine/engine.cpp index efe1852..0522ce9 100644 --- a/project/engine/engine.cpp +++ b/project/engine/engine.cpp @@ -238,12 +238,12 @@ void draw_bitmap( OffscreenBuffer* buffer, Vec2 pos, Bitmap* bitmap ) { s32 half_width = bitmap->width / 2; s32 half_height = bitmap->height / 2; - + Vec2i pos_rounded { round(pos.x), round(pos.y) }; Vec2i bmp_half_size { bitmap->width / 2, bitmap->height / 2 }; Vec2i min = pos_rounded - bmp_half_size; Vec2i max = pos_rounded + bmp_half_size; - + s32 max_x = round( pos.x ) + half_width; s32 max_y = round( pos.y ) + half_height; @@ -306,7 +306,7 @@ inline void draw_debug_point(OffscreenBuffer* back_buffer, World* world, TileMapPos pos, f32 red, f32 green, f32 blue) { TileMap* tile_map = world->tile_map; - + Vec2 min { pos.rel_pos.x * world->tile_meters_to_pixels + world->tile_lower_left_x + scast(f32, pos.tile_x * world->tile_size_in_pixels), pos.rel_pos.y * world->tile_meters_to_pixels + world->tile_lower_left_y + scast(f32, pos.tile_y * world->tile_size_in_pixels) @@ -1035,7 +1035,7 @@ void update_and_render( f32 delta_time, InputState* input, OffscreenBuffer* back Vec2 screen_center { - scast(f32, back_buffer->width) * 0.5f, + scast(f32, back_buffer->width) * 0.5f, scast(f32, back_buffer->height) * 0.5f }; @@ -1058,7 +1058,7 @@ void update_and_render( f32 delta_time, InputState* input, OffscreenBuffer* back s32 tile_id = TileMap_get_tile_value( tile_map, col, row, game_state->camera_pos.tile_z ); f32 color[3] = { 0.15f, 0.15f, 0.15f }; - if ( tile_id > 1 || row == player->position.tile_y && col == player->position.tile_x ) + if ( tile_id > 1 || (row == player->position.tile_y && col == player->position.tile_x) ) // if ( tile_id > 1 ) { if ( tile_id == 2 ) @@ -1125,7 +1125,7 @@ void update_and_render( f32 delta_time, InputState* input, OffscreenBuffer* back f32 player_blue = 0.3f; TileMapPos player_to_camera = subtract( player->position, game_state->camera_pos ); - + Vec2 player_to_screenspace { player_to_camera.rel_pos.x + scast(f32, player_to_camera.tile_x) * world->tile_map->tile_size_in_meters, -1 * (player_to_camera.rel_pos.y + scast(f32, player_to_camera.tile_y) * world->tile_map->tile_size_in_meters) @@ -1140,7 +1140,7 @@ void update_and_render( f32 delta_time, InputState* input, OffscreenBuffer* back player_ground_pos.y - player->height * world->tile_meters_to_pixels, }; Vec2 player_collision_max { - player_ground_pos.x + player_half_width * world->tile_meters_to_pixels, + player_ground_pos.x + player_half_width * world->tile_meters_to_pixels, player_ground_pos.y }; diff --git a/project/platform/compiler_ignores.hpp b/project/platform/compiler_ignores.hpp index 6e9570e..3f60aae 100644 --- a/project/platform/compiler_ignores.hpp +++ b/project/platform/compiler_ignores.hpp @@ -27,4 +27,5 @@ #pragma clang diagnostic ignored "-Wvarargs" #pragma clang diagnostic ignored "-Wunused-function" #pragma clang diagnostic ignored "-Wunused-but-set-variable" +#pragma clang diagnostic ignored "-Wmissing-braces" #endif diff --git a/project/platform/win32/win32.hpp b/project/platform/win32/win32.hpp index 5c22351..7ad4f86 100644 --- a/project/platform/win32/win32.hpp +++ b/project/platform/win32/win32.hpp @@ -59,7 +59,7 @@ enum CS : UINT CS_Horizontal_Redraw = CS_HREDRAW, CS_Vertical_Redraw = CS_VREDRAW, }; - + enum CW : s32 { CW_Use_Default = CW_USEDEFAULT, diff --git a/project/platform/win32/win32_platform.cpp b/project/platform/win32/win32_platform.cpp index e9ab63a..28d3c1f 100644 --- a/project/platform/win32/win32_platform.cpp +++ b/project/platform/win32/win32_platform.cpp @@ -503,6 +503,9 @@ engine::ModuleAPI load_engine_module_api() { OutputDebugStringA( "Loaded engine module API\n" ); } + else { + fatal( "Failed to load engine module API!\n" ); + } return engine_api; } @@ -865,6 +868,13 @@ WinMain( HINSTANCE instance, HINSTANCE prev_instance, LPSTR commandline, int sho } } + // Populate an initial polling state for the inputs + poll_input( window_handle, & input, jsl_num_devices, jsl_device_handles + , old_keyboard, new_keyboard + , old_mouse, new_mouse + , old_xpads, new_xpads + , old_ds_pads, new_ds_pads ); + engine_api.startup( rcast(engine::OffscreenBuffer*, & Surface_Back_Buffer.memory), & engine_memory, & platform_api ); u64 last_frame_clock = timing_get_wall_clock(); diff --git a/project/platform/win32/win32_platform_api.cpp b/project/platform/win32/win32_platform_api.cpp index a00253e..76e6c76 100644 --- a/project/platform/win32/win32_platform_api.cpp +++ b/project/platform/win32/win32_platform_api.cpp @@ -2,6 +2,10 @@ #include "platform.hpp" #include "jsl.hpp" #include "win32.hpp" + +NS_PLATFORM_BEGIN +using namespace win32; +NS_PLATFORM_END #endif NS_PLATFORM_BEGIN @@ -127,8 +131,10 @@ b32 file_read_content( File* file ) return {}; } + // This has to be done or for some reason file_handle will be consumed to null by `GetFileSizeEx` (Clang bug?) + HANDLE file_handle_clang_bug = file_handle; u32 size; - GetFileSizeEx( file_handle, rcast(LARGE_INTEGER*, &size) ); + GetFileSizeEx( file_handle_clang_bug, rcast(LARGE_INTEGER*, &size) ); if ( size == 0 ) { // TODO(Ed) : Logging diff --git a/scripts/build.ps1 b/scripts/build.ps1 index 3d48965..2ac2070 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -250,10 +250,10 @@ function build-engine $local:compiler_args = $script:compiler_args $compiler_args += ($flag_define + 'Build_DLL=1' ) - if ( $vendor -eq 'msvc' ) { + if ( $IsWindows ) { $compiler_args += ($flag_define + 'Engine_API=__declspec(dllexport)') } - if ( $vendor -eq 'clang' ) { + else { $compiler_args += ($flag_define + 'Engine_API=__attribute__((visibility("default")))') }