2023-09-28 18:57:52 -07:00
|
|
|
#include "platform/compiler_ignores.hpp"
|
|
|
|
|
2023-09-28 17:22:15 -07:00
|
|
|
#if GEN_TIME
|
|
|
|
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
|
|
|
#define GEN_IMPLEMENTATION
|
|
|
|
#define GEN_BENCHMARK
|
|
|
|
#define GEN_ENFORCE_STRONG_CODE_TYPES
|
|
|
|
#include "dependencies/gen.hpp"
|
2023-09-28 18:57:52 -07:00
|
|
|
#undef ccast
|
|
|
|
#undef pcast
|
2023-09-30 07:05:37 -07:00
|
|
|
#undef rcast
|
|
|
|
#undef scast
|
2023-09-28 18:57:52 -07:00
|
|
|
#undef do_once
|
|
|
|
#undef do_once_start
|
|
|
|
#undef do_once_end
|
2023-09-28 17:22:15 -07:00
|
|
|
using namespace gen;
|
|
|
|
|
2023-10-11 14:52:13 -07:00
|
|
|
#include "platform/platform_module.hpp"
|
2023-10-06 23:33:39 -07:00
|
|
|
#include "platform/grime.hpp"
|
|
|
|
#include "platform/macros.hpp"
|
|
|
|
#include "platform/types.hpp"
|
|
|
|
#include "platform/strings.hpp"
|
|
|
|
#include "platform/platform.hpp"
|
2023-09-28 18:57:52 -07:00
|
|
|
|
2023-10-11 14:52:13 -07:00
|
|
|
#include "engine/engine_module.hpp"
|
|
|
|
#include "engine/input.hpp"
|
|
|
|
#include "engine/tile_map.hpp"
|
2023-10-06 23:33:39 -07:00
|
|
|
#include "engine/engine.hpp"
|
2023-09-28 18:21:05 -07:00
|
|
|
#include "engine/engine_to_platform_api.hpp"
|
2023-09-28 18:57:52 -07:00
|
|
|
|
2023-09-28 17:22:15 -07:00
|
|
|
constexpr StrC fname_handmade_engine_symbols = txt("handmade_engine.symbols");
|
|
|
|
|
2023-09-29 12:58:18 -07:00
|
|
|
void get_symbols_from_module_table( FileContents symbol_table, Array<String> symbols )
|
2023-09-28 17:22:15 -07:00
|
|
|
{
|
|
|
|
struct Token
|
|
|
|
{
|
|
|
|
char const* Ptr;
|
|
|
|
u32 Len;
|
|
|
|
};
|
|
|
|
|
|
|
|
char const* scanner = rcast( char const*, symbol_table.data );
|
|
|
|
u32 left = symbol_table.size;
|
|
|
|
while ( left )
|
|
|
|
{
|
|
|
|
if ( *scanner == '\n' || *scanner == '\r' )
|
|
|
|
{
|
|
|
|
++ scanner;
|
|
|
|
-- left;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-09-29 12:58:18 -07:00
|
|
|
Token token {};
|
|
|
|
token.Ptr = scanner;
|
2023-09-28 17:22:15 -07:00
|
|
|
while ( left && *scanner != '\r' && *scanner != '\n' )
|
|
|
|
{
|
|
|
|
-- left;
|
|
|
|
++ scanner;
|
2023-09-29 12:58:18 -07:00
|
|
|
++ token.Len;
|
2023-09-28 17:22:15 -07:00
|
|
|
}
|
2023-09-29 12:58:18 -07:00
|
|
|
symbols.append( String::make_length( GlobalAllocator, token.Ptr, token.Len ) );
|
2023-09-28 17:22:15 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int gen_main()
|
|
|
|
{
|
|
|
|
gen::init();
|
2023-09-28 18:21:05 -07:00
|
|
|
log_fmt("Generating code for Handmade Hero: Engine Module\n");
|
2023-09-28 17:22:15 -07:00
|
|
|
|
|
|
|
FileContents symbol_table = file_read_contents( GlobalAllocator, true, fname_handmade_engine_symbols );
|
|
|
|
|
|
|
|
#pragma push_macro("str_ascii")
|
|
|
|
#undef str_ascii
|
|
|
|
Builder builder = Builder::open( "engine_symbol_table.hpp" );
|
|
|
|
builder.print( pragma_once );
|
2023-09-28 18:21:05 -07:00
|
|
|
builder.print( def_include( txt("engine/engine.hpp") ) );
|
2023-09-28 17:22:15 -07:00
|
|
|
builder.print( fmt_newline );
|
|
|
|
builder.print_fmt( "NS_ENGINE_BEGIN\n\n" );
|
|
|
|
|
2023-09-29 12:58:18 -07:00
|
|
|
Array<String> symbols = Array<String>::init_reserve( GlobalAllocator, kilobytes(1) );
|
|
|
|
get_symbols_from_module_table( symbol_table, symbols );
|
|
|
|
|
|
|
|
using ModuleAPI = engine::ModuleAPI;
|
2023-09-28 17:22:15 -07:00
|
|
|
|
2023-09-29 12:58:18 -07:00
|
|
|
builder.print( parse_variable( token_fmt( "symbol", (StrC)symbols[ModuleAPI::Sym_OnModuleReload], stringize(
|
2023-09-28 17:22:15 -07:00
|
|
|
constexpr const Str symbol_on_module_load = str_ascii("<symbol>");
|
|
|
|
))));
|
2023-09-29 12:58:18 -07:00
|
|
|
builder.print( parse_variable( token_fmt( "symbol", (StrC)symbols[ModuleAPI::Sym_Startup], stringize(
|
2023-09-28 17:22:15 -07:00
|
|
|
constexpr const Str symbol_startup = str_ascii("<symbol>");
|
|
|
|
))));
|
2023-09-29 12:58:18 -07:00
|
|
|
builder.print( parse_variable( token_fmt( "symbol", (StrC)symbols[ModuleAPI::Sym_Shutdown], stringize(
|
2023-09-28 17:22:15 -07:00
|
|
|
constexpr const Str symbol_shutdown = str_ascii("<symbol>");
|
|
|
|
))));
|
2023-09-29 12:58:18 -07:00
|
|
|
builder.print( parse_variable( token_fmt( "symbol", (StrC)symbols[ModuleAPI::Sym_UpdateAndRender], stringize(
|
2023-09-28 17:22:15 -07:00
|
|
|
constexpr const Str symbol_update_and_render = str_ascii("<symbol>");
|
|
|
|
))));
|
2023-09-29 12:58:18 -07:00
|
|
|
builder.print( parse_variable( token_fmt( "symbol", (StrC)symbols[ModuleAPI::Sym_UpdateAudio], stringize(
|
2023-09-28 17:22:15 -07:00
|
|
|
constexpr const Str symbol_update_audio = str_ascii("<symbol>");
|
|
|
|
))));
|
|
|
|
|
|
|
|
builder.print_fmt( "\nNS_ENGINE_END" );
|
|
|
|
builder.print( fmt_newline );
|
|
|
|
builder.write();
|
|
|
|
#pragma pop_macro("str_ascii")
|
|
|
|
|
2023-10-01 17:17:14 -07:00
|
|
|
log_fmt("Generaton finished for Handmade Hero: Engine Module\n\n");
|
2023-09-28 17:22:15 -07:00
|
|
|
// gen::deinit();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|