diff --git a/build.c b/build.c index dd49a1ab..40be62e3 100644 --- a/build.c +++ b/build.c @@ -323,9 +323,9 @@ void OnBuild(StringList cli_args) if (arg_msvc) { /* Msvc */ StringListAppend(&perm, &c_compile_args, Lit("cl.exe /nologo /c \"%F\" /Fo\"%F\" /FS /showIncludes")); - StringListAppend(&perm, &cpp_compile_args, Lit("cl.exe /nologo /c \"%F\" /Fo\"%F\" /FS /showIncludes")); + StringListAppend(&perm, &cpp_compile_args, Lit("cl.exe /nologo /std:c++20 /c \"%F\" /Fo\"%F\" /FS /showIncludes")); StringListAppend(&perm, &pch_c_compile_args, Lit("cl.exe /nologo /c /Yc\"%F\" \"%F\" /FS /showIncludes")); - StringListAppend(&perm, &pch_cpp_compile_args, Lit("cl.exe /nologo /c /Yc\"%F\" \"%F\" /FS /showIncludes")); + StringListAppend(&perm, &pch_cpp_compile_args, Lit("cl.exe /nologo /std:c++20 /c /Yc\"%F\" \"%F\" /FS /showIncludes")); StringListAppend(&perm, &rc_compile_args, Lit("rc /fo\"%F\" \"%F\"")); StringListAppend(&perm, &link_args, Lit("link.exe /nologo %F /OUT:\"%F\" /DEBUG:FULL /OPT:REF /OPT:ICF")); diff --git a/src/common.h b/src/common.h index 922483e0..4cbfb6ed 100644 --- a/src/common.h +++ b/src/common.h @@ -166,9 +166,9 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t); * ========================== */ #if COMPILER_MSVC && LANGUAGE_CPP -# define CPPFRIENDLY_INITLIST_TYPE(type) type +# define CPPCOMPAT_INITLIST_TYPE(type) #else -# define CPPFRIENDLY_INITLIST_TYPE(type) (type) +# define CPPCOMPAT_INITLIST_TYPE(type) (type) #endif /* Zero initialization macro */ @@ -213,10 +213,16 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t); /* Markup */ #define UNUSED void -#if COMPILER_CLANG +#if COMPILER_MSVC +# if LANGUAGE_CPP +# define FALLTHROUGH [[fallthrough]] +# else +# define FALLTHROUGH +# endif +#elif COMPILER_CLANG # define FALLTHROUGH __attribute((fallthrough)) #else -# define FALLTHROUGH +# define FALLTHROUGH #endif /* Sizes */ @@ -515,7 +521,7 @@ struct sprite_tag { * ========================== */ /* Utility buffer constructor */ -#define BUFFER(size, data) (CPPFRIENDLY_INITLIST_TYPE(struct buffer) { (size), (data) }) +#define BUFFER(size, data) (CPPCOMPAT_INITLIST_TYPE(struct buffer) { (size), (data) }) /* Utility buffer constructor from static array */ #define BUFFER_FROM_ARRAY(a) \ @@ -527,23 +533,23 @@ struct sprite_tag { ((struct buffer) { .size = ARRAY_COUNT(a), .data = (u8 *)(a) }) \ ) -#define BUFFER_FROM_STRING(str) (CPPFRIENDLY_INITLIST_TYPE(struct buffer) { (str).len, (str).text }) +#define BUFFER_FROM_STRING(str) (CPPCOMPAT_INITLIST_TYPE(struct buffer) { (str).len, (str).text }) -#define BUFFER_FROM_POINTERS(p0, p1) (CPPFRIENDLY_INITLIST_TYPE(struct buffer) { (u8 *)(p1) - (u8 *)(p0), (u8 *)p0 }) +#define BUFFER_FROM_POINTERS(p0, p1) (CPPCOMPAT_INITLIST_TYPE(struct buffer) { (u8 *)(p1) - (u8 *)(p0), (u8 *)p0 }) -#define BUFFER_FROM_STRUCT(ptr) (CPPFRIENDLY_INITLIST_TYPE(struct buffer) { sizeof(*(ptr)), (u8 *)(ptr) }) +#define BUFFER_FROM_STRUCT(ptr) (CPPCOMPAT_INITLIST_TYPE(struct buffer) { sizeof(*(ptr)), (u8 *)(ptr) }) /* ========================== * * String utils * ========================== */ /* Expand C string literal with size for string initialization */ -#define STR(cstr_lit) CPPFRIENDLY_INITLIST_TYPE(struct string) { (sizeof((cstr_lit)) - 1), (u8 *)(cstr_lit) } +#define STR(cstr_lit) CPPCOMPAT_INITLIST_TYPE(struct string) { (sizeof((cstr_lit)) - 1), (u8 *)(cstr_lit) } /* Same as `STR`, but works with static variable initialization */ #define STR_NOCAST(cstr_lit) { .len = (sizeof((cstr_lit)) - 1), .text = (u8 *)(cstr_lit) } -#define STRING_FROM_BUFFER(buff) (CPPFRIENDLY_INITLIST_TYPE(struct string) { buff.size, buff.data }) +#define STRING_FROM_BUFFER(buff) (CPPCOMPAT_INITLIST_TYPE(struct string) { buff.size, buff.data }) #define STRING_FROM_ARRAY(a) STRING_FROM_BUFFER(BUFFER_FROM_ARRAY(a)) @@ -551,7 +557,7 @@ struct sprite_tag { * Math types * ========================== */ -#define V2(x, y) ((struct v2) { (x), (y) }) +#define V2(x, y) CPPCOMPAT_INITLIST_TYPE(struct v2) { (x), (y) } #define V2_FROM_V2I32(v) V2((v).x, (v).y) struct v2 { f32 x, y; @@ -582,7 +588,7 @@ struct v4_array { u64 count; }; -#define V2I32(x, y) ((struct v2i32) { (x), (y) }) +#define V2I32(x, y) CPPCOMPAT_INITLIST_TYPE(struct v2i32) { (x), (y) } struct v2i32 { i32 x, y; }; diff --git a/src/math.h b/src/math.h index f481b3ee..ec4fe452 100644 --- a/src/math.h +++ b/src/math.h @@ -821,7 +821,7 @@ INLINE b32 v2i32_eq(struct v2i32 a, struct v2i32 b) INLINE struct mat4x4 mat4x4_from_xform(struct xform xf) { - return (struct mat4x4) { + return CPPCOMPAT_INITLIST_TYPE(struct mat4x4) { .e = { {xf.bx.x, xf.bx.y, 0, 0}, {xf.by.x, xf.by.y, 0, 0}, @@ -888,10 +888,10 @@ INLINE struct mat4x4 mat4x4_mul(struct mat4x4 m1, struct mat4x4 m2) * ========================== */ /* Construct identity xform */ -#define XFORM_IDENT ((struct xform) { .bx.x = 1, .by.y = 1 }) +#define XFORM_IDENT CPPCOMPAT_INITLIST_TYPE(struct xform) { .bx.x = 1, .by.y = 1 } #define XFORM_IDENT_NOCAST { .bx.x = 1, .by.y = 1 } -#define XFORM_POS(p) ((struct xform) { .bx.x = 1, .by.y = 1, .og = (p) }) +#define XFORM_POS(p) CPPCOMPAT_INITLIST_TYPE(struct xform) { .bx.x = 1, .by.y = 1, .og = (p) } /* Takes a translation, rotation, and scale as optional parameters for constructing an xform */ #define XFORM_TRS(...) xform_from_trs((struct trs) { .t = V2(0,0), .s = V2(1, 1), .r = 0, __VA_ARGS__ }) @@ -912,11 +912,11 @@ INLINE b32 xform_eq(struct xform xf1, struct xform xf2) INLINE struct xform xform_from_pos(struct v2 v) { - return (struct xform) { - .bx = {1, 0}, - .by = {0, 1}, - .og = {v.x, v.y} - }; + struct xform xf; + xf.bx = V2(1, 0); + xf.by = V2(0, 1); + xf.og = v; + return xf; } INLINE struct xform xform_from_rotation(f32 r) diff --git a/src/renderer_d3d11.c b/src/renderer_d3d11.c index a0ba1b3c..1043dc0e 100644 --- a/src/renderer_d3d11.c +++ b/src/renderer_d3d11.c @@ -8,6 +8,7 @@ #include "inc.h" #include "tar.h" #include "sprite.h" +#include "log.h" #pragma warning(push, 0) # define UNICODE @@ -240,6 +241,7 @@ INTERNAL void shader_init(struct dx11_shader *shader, enum shader_kind kind) struct temp_arena scratch = scratch_begin_no_conflict(); const struct dx11_shader_desc *shader_desc = &G.shader_info[kind]; + struct string name = string_from_cstr(shader_desc->name_cstr); shader->kind = kind; shader->vertex_size = shader_desc->vertex_size; @@ -254,7 +256,6 @@ INTERNAL void shader_init(struct dx11_shader *shader, enum shader_kind kind) /* Compile shader */ ID3DBlob *vs_blob, *ps_blob; { - struct string name = string_from_cstr(shader_desc->name_cstr); struct tar_entry *tar_entry = tar_get(&G.shaders_archive, name); if (!tar_entry) { sys_panic(string_format(scratch.arena, @@ -264,6 +265,7 @@ INTERNAL void shader_init(struct dx11_shader *shader, enum shader_kind kind) struct buffer shader_src = tar_entry->buff; + logf_info("Compiling shader \"%F\"", FMT_STR(name)); /* Compile shader */ /* TODO: pre-compile shaders w/ FXC? */ ID3DBlob *error_blob; @@ -515,10 +517,12 @@ struct renderer_startup_receipt renderer_startup(struct sys_window *window) } /* Init shaders */ + logf_info("Compiling shaders"); for (u32 i = SHADER_NONE + 1; i < NUM_SHADERS; ++i) { /* Create shader */ shader_init(&G.shaders[i], i); } + logf_info("Finished compiling shaders"); return (struct renderer_startup_receipt) { 0 }; } diff --git a/src/space.c b/src/space.c index 5434ca36..c82b5d83 100644 --- a/src/space.c +++ b/src/space.c @@ -66,7 +66,7 @@ INTERNAL struct v2i32 world_to_cell_coords(f32 cell_size, struct v2 world_pos) INTERNAL i32 cell_coords_to_bucket_index(struct space *space, struct v2i32 cell_pos) { - u32 num_buckets_sqrt = space->num_buckets_sqrt; + i32 num_buckets_sqrt = space->num_buckets_sqrt; i32 index_x = cell_pos.x; i32 index_y = cell_pos.y; diff --git a/src/space.h b/src/space.h index a9dcfc81..b0496d1d 100644 --- a/src/space.h +++ b/src/space.h @@ -58,8 +58,8 @@ struct space { struct arena cell_arena; struct space_cell_bucket *buckets; - u64 num_buckets; - u64 num_buckets_sqrt; + i32 num_buckets; + i32 num_buckets_sqrt; struct space_cell *first_free_cell; struct space_cell_node *first_free_cell_node;