update gencpp to latest

Using this project to test latest ver...
This commit is contained in:
Edward R. Gonzalez 2024-12-14 08:02:47 -05:00
parent 393f98a03d
commit a86a2cc77c
6 changed files with 17424 additions and 14791 deletions

22
.vscode/settings.json vendored
View File

@ -84,5 +84,25 @@
"**/.vscode": true, "**/.vscode": true,
"**/.vs": true, "**/.vs": true,
}, },
"dimmer.enabled": true "dimmer.enabled": false,
"workbench.colorCustomizations": {
"activityBar.activeBackground": "#ff6433",
"activityBar.background": "#ff6433",
"activityBar.foreground": "#15202b",
"activityBar.inactiveForeground": "#15202b99",
"activityBarBadge.background": "#00ff3d",
"activityBarBadge.foreground": "#15202b",
"commandCenter.border": "#e7e7e799",
"sash.hoverBorder": "#ff6433",
"statusBar.background": "#ff3d00",
"statusBar.foreground": "#e7e7e7",
"statusBarItem.hoverBackground": "#ff6433",
"statusBarItem.remoteBackground": "#ff3d00",
"statusBarItem.remoteForeground": "#e7e7e7",
"titleBar.activeBackground": "#ff3d00",
"titleBar.activeForeground": "#e7e7e7",
"titleBar.inactiveBackground": "#ff3d0099",
"titleBar.inactiveForeground": "#e7e7e799"
},
"peacock.color": "#ff3d00"
} }

View File

@ -14,7 +14,7 @@
#undef do_once #undef do_once
#undef do_once_start #undef do_once_start
#undef do_once_end #undef do_once_end
using namespace gen; #undef cast
#include "platform/platform_module.hpp" #include "platform/platform_module.hpp"
#include "platform/grime.hpp" #include "platform/grime.hpp"
@ -23,7 +23,10 @@ using namespace gen;
#include "platform/strings.hpp" #include "platform/strings.hpp"
#include "platform/platform.hpp" #include "platform/platform.hpp"
constexpr StrC fname_vec_header = txt("vectors.hpp"); using namespace gen;
using GStr = gen::Str;
constexpr GStr fname_vec_header = txt("vectors.hpp");
#pragma push_macro("scast") #pragma push_macro("scast")
#pragma push_macro("Zero") #pragma push_macro("Zero")
@ -264,7 +267,7 @@ constexpr char const* vec2i_ops = stringize(
#pragma pop_macro("Zero") #pragma pop_macro("Zero")
#define gen_vec2f( vec_name, type ) gen__vec2f( txt( stringize(vec_name) ), txt( stringize(type) ) ) #define gen_vec2f( vec_name, type ) gen__vec2f( txt( stringize(vec_name) ), txt( stringize(type) ) )
CodeBody gen__vec2f( StrC vec_name, StrC type ) CodeBody gen__vec2f( GStr vec_name, GStr type )
{ {
CodeStruct vec_struct = parse_struct( token_fmt( "type", vec_name, "unit_type", type, stringize( CodeStruct vec_struct = parse_struct( token_fmt( "type", vec_name, "unit_type", type, stringize(
struct <type> struct <type>
@ -290,7 +293,7 @@ CodeBody gen__vec2f( StrC vec_name, StrC type )
} }
#define gen_vec2i( vec_name, type ) gen__vec2i( txt( stringize(vec_name) ), txt( stringize(type) ) ) #define gen_vec2i( vec_name, type ) gen__vec2i( txt( stringize(vec_name) ), txt( stringize(type) ) )
CodeBody gen__vec2i( StrC vec_name, StrC type ) CodeBody gen__vec2i( GStr vec_name, GStr type )
{ {
CodeStruct vec_struct = parse_struct( token_fmt( "type", vec_name, "unit_type", type, stringize( CodeStruct vec_struct = parse_struct( token_fmt( "type", vec_name, "unit_type", type, stringize(
struct <type> struct <type>
@ -316,14 +319,14 @@ CodeBody gen__vec2i( StrC vec_name, StrC type )
} }
#define gen_phys2( type ) gen__phys2( txt( stringize(type) ) ) #define gen_phys2( type ) gen__phys2( txt( stringize(type) ) )
Code gen__phys2( StrC type ) Code gen__phys2( GStr type )
{ {
String sym_vec = String::fmt_buf( GlobalAllocator, "Vec2_%s", type.Ptr ); StrBuilder sym_vec = StrBuilder::fmt_buf( _ctx->Allocator_Temp, "Vec2_%s", type.Ptr );
String sym_pos = String::fmt_buf( GlobalAllocator, "Pos2_%s", type.Ptr ); StrBuilder sym_pos = StrBuilder::fmt_buf( _ctx->Allocator_Temp, "Pos2_%s", type.Ptr );
String sym_dir = String::fmt_buf( GlobalAllocator, "Dir2_%s", type.Ptr); StrBuilder sym_dir = StrBuilder::fmt_buf( _ctx->Allocator_Temp, "Dir2_%s", type.Ptr);
String sym_dist = String::fmt_buf( GlobalAllocator, "Dist_%s", type.Ptr ); StrBuilder sym_dist = StrBuilder::fmt_buf( _ctx->Allocator_Temp, "Dist_%s", type.Ptr );
String sym_vel = String::fmt_buf( GlobalAllocator, "Vel2_%s", type.Ptr ); StrBuilder sym_vel = StrBuilder::fmt_buf( _ctx->Allocator_Temp, "Vel2_%s", type.Ptr );
String sym_accel = String::fmt_buf( GlobalAllocator, "Accel2_%s", type.Ptr ); StrBuilder sym_accel = StrBuilder::fmt_buf( _ctx->Allocator_Temp, "Accel2_%s", type.Ptr );
#pragma push_macro("pcast") #pragma push_macro("pcast")
#pragma push_macro("rcast") #pragma push_macro("rcast")
@ -351,15 +354,15 @@ Code gen__phys2( StrC type )
return pcast( <type>, vec ); return pcast( <type>, vec );
} }
); );
CodeBody pos_struct = parse_global_body( token_fmt( "type", (StrC)sym_pos, "unit_type", type, "vec_type", (StrC)sym_vec, tmpl_struct )); CodeBody pos_struct = parse_global_body( token_fmt( "type", (GStr)sym_pos, "unit_type", type, "vec_type", (GStr)sym_vec, tmpl_struct ));
CodeBody pos_ops = parse_global_body( token_fmt( "type", (StrC)sym_pos, "unit_type", type, vec2f_ops )); CodeBody pos_ops = parse_global_body( token_fmt( "type", (GStr)sym_pos, "unit_type", type, vec2f_ops ));
CodeBody dir_struct = parse_global_body( token_fmt( CodeBody dir_struct = parse_global_body( token_fmt(
"type", (StrC)sym_dir, "type", (GStr)sym_dir,
"unit_type", type, "unit_type", type,
"vec_type", (StrC)sym_vec, "vec_type", (GStr)sym_vec,
"vel_type", (StrC)sym_vel, "vel_type", (GStr)sym_vel,
"accel_type", (StrC)sym_accel, "accel_type", (GStr)sym_accel,
stringize( stringize(
struct <type> struct <type>
{ {
@ -396,10 +399,10 @@ Code gen__phys2( StrC type )
))); )));
CodeBody dist_def = parse_global_body( token_fmt( CodeBody dist_def = parse_global_body( token_fmt(
"type", (StrC)sym_dist, "type", (GStr)sym_dist,
"unit_type", type, "unit_type", type,
"dist_type", (StrC)sym_dist, "dist_type", (GStr)sym_dist,
"pos_type", (StrC)sym_pos, "pos_type", (GStr)sym_pos,
stringize( stringize(
using <dist_type> = <unit_type>; using <dist_type> = <unit_type>;
@ -413,20 +416,20 @@ Code gen__phys2( StrC type )
} }
))); )));
CodeBody vel_struct = parse_global_body( token_fmt( "type", (StrC)sym_vel, "unit_type", type, "vec_type", (StrC)sym_vec, tmpl_struct )); CodeBody vel_struct = parse_global_body( token_fmt( "type", (GStr)sym_vel, "unit_type", type, "vec_type", (GStr)sym_vec, tmpl_struct ));
CodeBody vel_ops = parse_global_body( token_fmt( "type", (StrC)sym_vel, "unit_type", type, vec2f_ops )); CodeBody vel_ops = parse_global_body( token_fmt( "type", (GStr)sym_vel, "unit_type", type, vec2f_ops ));
CodeBody accel_struct = parse_global_body( token_fmt( "type", (StrC)sym_accel, "unit_type", type, "vec_type", (StrC)sym_vec, tmpl_struct )); CodeBody accel_struct = parse_global_body( token_fmt( "type", (GStr)sym_accel, "unit_type", type, "vec_type", (GStr)sym_vec, tmpl_struct ));
CodeBody accel_ops = parse_global_body( token_fmt( "type", (StrC)sym_accel, "unit_type", type, vec2f_ops )); CodeBody accel_ops = parse_global_body( token_fmt( "type", (GStr)sym_accel, "unit_type", type, vec2f_ops ));
// TODO(Ed): Is there a better name for this? // TODO(Ed): Is there a better name for this?
Code ops = parse_global_body( token_fmt( Code ops = parse_global_body( token_fmt(
"unit_type", (StrC)type, "unit_type", (GStr)type,
"vec_type", (StrC)sym_vec, "vec_type", (GStr)sym_vec,
"pos_type", (StrC)sym_pos, "pos_type", (GStr)sym_pos,
"dir_type", (StrC)sym_dir, "dir_type", (GStr)sym_dir,
"vel_type", (StrC)sym_vel, "vel_type", (GStr)sym_vel,
"accel_type", (StrC)sym_accel, "accel_type", (GStr)sym_accel,
stringize( stringize(
inline inline
<vel_type> velocity( <pos_type> a, <pos_type> b ) { <vel_type> velocity( <pos_type> a, <pos_type> b ) {
@ -508,7 +511,8 @@ Code gen__phys2( StrC type )
int gen_main() int gen_main()
{ {
gen::init(); gen::Context ctx {};
gen::init( & ctx);
log_fmt("Generating code for Handmade Hero: Engine Module\n"); log_fmt("Generating code for Handmade Hero: Engine Module\n");
CodeComment cmt_gen_notice = def_comment( txt("This was generated by project/codegen/engine_gen.cpp") ); CodeComment cmt_gen_notice = def_comment( txt("This was generated by project/codegen/engine_gen.cpp") );

View File

@ -15,7 +15,7 @@
#undef do_once_end #undef do_once_end
#undef min #undef min
#undef max #undef max
using namespace gen; #undef cast
#include <math.h> #include <math.h>
@ -37,9 +37,13 @@ using namespace gen;
#include "engine/engine_to_platform_api.hpp" #include "engine/engine_to_platform_api.hpp"
#include "engine/gen/physics.hpp" #include "engine/gen/physics.hpp"
constexpr StrC fname_handmade_engine_symbols = txt("handmade_engine.symbols"); using namespace gen;
void get_symbols_from_module_table( FileContents symbol_table, Array<String> symbols ) using GStr = gen::Str;
constexpr GStr fname_handmade_engine_symbols = txt("handmade_engine.symbols");
void get_symbols_from_module_table( FileContents symbol_table, Array<StrBuilder> symbols )
{ {
struct Token struct Token
{ {
@ -66,17 +70,18 @@ void get_symbols_from_module_table( FileContents symbol_table, Array<String> sym
++ scanner; ++ scanner;
++ token.Len; ++ token.Len;
} }
symbols.append( String::make_length( GlobalAllocator, token.Ptr, token.Len ) ); symbols.append( StrBuilder::make_length( _ctx->Allocator_Temp, token.Ptr, token.Len ) );
} }
} }
} }
int gen_main() int gen_main()
{ {
gen::init(); gen::Context ctx {};
gen::init( & ctx);
log_fmt("Generating code for Handmade Hero: Engine Module (Post-Build)\n"); log_fmt("Generating code for Handmade Hero: Engine Module (Post-Build)\n");
FileContents symbol_table = file_read_contents( GlobalAllocator, true, fname_handmade_engine_symbols ); FileContents symbol_table = file_read_contents( ctx.Allocator_Temp, true, fname_handmade_engine_symbols );
#pragma push_macro("str_ascii") #pragma push_macro("str_ascii")
#undef str_ascii #undef str_ascii
@ -86,24 +91,24 @@ int gen_main()
builder.print( fmt_newline ); builder.print( fmt_newline );
builder.print_fmt( "NS_ENGINE_BEGIN\n\n" ); builder.print_fmt( "NS_ENGINE_BEGIN\n\n" );
Array<String> symbols = Array<String>::init_reserve( GlobalAllocator, kilobytes(1) ); Array<StrBuilder> symbols = Array<StrBuilder>::init_reserve( ctx.Allocator_Temp, kilobytes(1) );
get_symbols_from_module_table( symbol_table, symbols ); get_symbols_from_module_table( symbol_table, symbols );
using ModuleAPI = engine::ModuleAPI; using ModuleAPI = engine::ModuleAPI;
builder.print( parse_variable( token_fmt( "symbol", (StrC)symbols[ModuleAPI::Sym_OnModuleReload], stringize( builder.print( parse_variable( token_fmt( "symbol", (GStr)symbols[ModuleAPI::Sym_OnModuleReload], stringize(
constexpr const Str symbol_on_module_load = str_ascii("<symbol>"); constexpr const Str symbol_on_module_load = str_ascii("<symbol>");
)))); ))));
builder.print( parse_variable( token_fmt( "symbol", (StrC)symbols[ModuleAPI::Sym_Startup], stringize( builder.print( parse_variable( token_fmt( "symbol", (GStr)symbols[ModuleAPI::Sym_Startup], stringize(
constexpr const Str symbol_startup = str_ascii("<symbol>"); constexpr const Str symbol_startup = str_ascii("<symbol>");
)))); ))));
builder.print( parse_variable( token_fmt( "symbol", (StrC)symbols[ModuleAPI::Sym_Shutdown], stringize( builder.print( parse_variable( token_fmt( "symbol", (GStr)symbols[ModuleAPI::Sym_Shutdown], stringize(
constexpr const Str symbol_shutdown = str_ascii("<symbol>"); constexpr const Str symbol_shutdown = str_ascii("<symbol>");
)))); ))));
builder.print( parse_variable( token_fmt( "symbol", (StrC)symbols[ModuleAPI::Sym_UpdateAndRender], stringize( builder.print( parse_variable( token_fmt( "symbol", (GStr)symbols[ModuleAPI::Sym_UpdateAndRender], stringize(
constexpr const Str symbol_update_and_render = str_ascii("<symbol>"); constexpr const Str symbol_update_and_render = str_ascii("<symbol>");
)))); ))));
builder.print( parse_variable( token_fmt( "symbol", (StrC)symbols[ModuleAPI::Sym_UpdateAudio], stringize( builder.print( parse_variable( token_fmt( "symbol", (GStr)symbols[ModuleAPI::Sym_UpdateAudio], stringize(
constexpr const Str symbol_update_audio = str_ascii("<symbol>"); constexpr const Str symbol_update_audio = str_ascii("<symbol>");
)))); ))));

View File

@ -6,14 +6,17 @@
#include "dependencies/gen.hpp" #include "dependencies/gen.hpp"
#undef min #undef min
#undef max #undef max
using namespace gen; #undef cast
#define path_gen "./gen/" #define path_gen "./gen/"
using namespace gen;
using GStr = gen::Str;
int gen_main() int gen_main()
{ {
gen::init(); gen::Context ctx {};
gen::init( & ctx);
log_fmt("Generating code for Handmade Hero: Platform Module\n"); log_fmt("Generating code for Handmade Hero: Platform Module\n");
CodeComment generation_notice = def_comment( txt("This was generated by project/codegen/platform_gen.cpp") ); CodeComment generation_notice = def_comment( txt("This was generated by project/codegen/platform_gen.cpp") );
@ -22,15 +25,15 @@ int gen_main()
builder.print( generation_notice ); builder.print( generation_notice );
builder.print( fmt_newline ); builder.print( fmt_newline );
FileContents h_context = file_read_contents(GlobalAllocator, true, "context.hpp"); FileContents h_context = file_read_contents(ctx.Allocator_Temp, true, "context.hpp");
CodeBody code_context = parse_global_body( { h_context.size, rcast( char const*, h_context.data ) } ); CodeBody code_context = parse_global_body( { rcast( char const*, h_context.data ), h_context.size } );
CodeStruct context_struct = {}; CodeStruct context_struct = {};
for ( Code code : code_context ) for ( Code code : code_context )
{ {
if ( code->Type == ECode::Struct ) if ( code->Type == CT_Struct )
{ {
if ( str_compare( code->Name, txt("Context") ) == 0 ) if ( code->Name.is_equal(txt("Context")) )
{ {
context_struct = code; context_struct = code;
break; break;
@ -39,10 +42,10 @@ int gen_main()
} }
} }
Array<Code> context_data_members = Array<Code>::init_reserve( GlobalAllocator, kilobytes( 1 ) ); Array<Code> context_data_members = Array<Code>::init_reserve( ctx.Allocator_Temp, kilobytes( 1 ) );
for ( Code code : context_struct->Body ) for ( Code code : context_struct->Body )
{ {
if ( code->Type == ECode::Variable ) if ( code->Type == CT_Variable )
{ {
context_data_members.append( code ); context_data_members.append( code );
} }
@ -50,22 +53,22 @@ int gen_main()
CodeDefine using_context; CodeDefine using_context;
{ {
String using_context_content = String::make_reserve( GlobalAllocator, kilobytes( 1 ) ); StrBuilder using_context_content = StrBuilder::make_reserve( ctx.Allocator_Temp, kilobytes( 1 ) );
{ {
String StrBuilder
content = using_context_content; content = using_context_content;
content.append( "\\\n" ); content.append( "\\\n" );
for ( s32 id = 0; id < context_data_members.num() - 1; ++id ) for ( s32 id = 0; id < context_data_members.num() - 1; ++id )
{ {
Code code = context_data_members[ id ]; Code code = context_data_members[ id ];
content.append( code.to_string() ); content.append( code.to_strbuilder() );
// Default serializer inserts a newline at the end of the string, we need to insert a line continuation // Default serializer inserts a newline at the end of the string, we need to insert a line continuation
content[ content.length() - 1 ] = '\\'; content[ content.length() - 1 ] = '\\';
content.append( "\n" ); content.append( "\n" );
} }
content.append( context_data_members[ context_data_members.num() - 1 ]->to_string() ); content.append( context_data_members[ context_data_members.num() - 1 ].to_strbuilder() );
} }
using_context = def_define( txt("using_context()"), using_context_content ); using_context = def_define( txt("using_context()"), using_context_content );
} }

File diff suppressed because it is too large Load Diff

View File

@ -732,7 +732,7 @@ WinMain( HINSTANCE instance, HINSTANCE prev_instance, LPSTR commandline, int sho
} }
ReleaseDC( window_handle, refresh_dc ); ReleaseDC( window_handle, refresh_dc );
Engine_Refresh_Hz = 30; Engine_Refresh_Hz = 165;
Engine_Frame_Target_MS = 1000.f / scast(f32, Engine_Refresh_Hz); Engine_Frame_Target_MS = 1000.f / scast(f32, Engine_Refresh_Hz);
} }
@ -974,7 +974,7 @@ WinMain( HINSTANCE instance, HINSTANCE prev_instance, LPSTR commandline, int sho
process_pending_window_messages( window_handle, new_keyboard, new_mouse ); process_pending_window_messages( window_handle, new_keyboard, new_mouse );
// f32 delta_time = timing_get_seconds_elapsed( last_frame_clock, timing_get_wall_clock() ); // f32 delta_time = timing_get_ms_elapsed( last_frame_clock, timing_get_wall_clock() );
// Engine's logical iteration and rendering process // Engine's logical iteration and rendering process
engine_api.update_and_render( delta_time, & input, rcast(engine::OffscreenBuffer*, & Surface_Back_Buffer.memory ) engine_api.update_and_render( delta_time, & input, rcast(engine::OffscreenBuffer*, & Surface_Back_Buffer.memory )