X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=build.c;h=eb3de6285879b9f7f6c3196dd3b32349447da76f;hb=8d336ea2cde7c596296dbaf0d3ce27a82c6c6cf0;hp=cb7a71a26324e40ef1c48388ad34d5e5c71e79b7;hpb=217627b6b4eef904ac89b5f7f7f819b3a0970b20;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/build.c b/build.c index cb7a71a..eb3de62 100644 --- a/build.c +++ b/build.c @@ -1,4 +1,4 @@ -#include "vg/vg.h" +#include "vg/vg_tool.h" #include "vg/vg_platform.h" #include "vg/vg_log.h" #include "vg/vg_opt.h" @@ -7,8 +7,6 @@ #include "vg/vg_msg.h" #include "addon_types.h" -u32 optimize_test_compile = 0; - /* * Addon metadata utilities * -------------------------------------------------------------------------- */ @@ -26,7 +24,8 @@ void write_msg( vg_msg *msg, const char *path ){ } void write_generic_addon_inf( u32 type, const char *title, - const char *content, const char *dest ){ + const char *content, const char *dest ) +{ u8 descriptor_buf[ 512 ]; vg_msg descriptor = {0}; descriptor.buf = descriptor_buf; @@ -34,7 +33,7 @@ void write_generic_addon_inf( u32 type, const char *title, vg_msg_frame( &descriptor, "workshop" ); vg_msg_wkvstr( &descriptor, "title", title ); vg_msg_wkvstr( &descriptor, "author", "Skaterift" ); - vg_msg_wkvu32( &descriptor, "type", type ); + vg_msg_wkvnum( &descriptor, "type", k_vg_msg_u32, 1, &type ); vg_msg_end_frame( &descriptor ); vg_msg_wkvstr( &descriptor, "content", content ); write_msg( &descriptor, dest ); @@ -45,7 +44,8 @@ void write_generic_addon_inf( u32 type, const char *title, * -------------------------------------------------------------------------- */ /* operates in the local files, not in the bin folders */ -void build_game_metadata(void){ +void build_game_metadata(void) +{ vg_info( "Building game metadata\n" ); write_generic_addon_inf( k_addon_type_board, "Longboard", "board.mdl", @@ -83,23 +83,72 @@ void build_game_metadata(void){ "playermodels_src/skaterift_aaron/addon.inf" ); } -void build_game_content(void){ - vg_low( "Building game content structure\n" ); - const char *project_name = vg_build.project_name.buffer; - vg_symlink( "textures_src", "textures" ); - vg_symlink( "models_src", "models" ); - vg_symlink( "boards_src", "boards" ); - vg_symlink( "maps_src", "maps" ); - vg_symlink( "sound_src", "sound" ); - vg_symlink( "playermodels_src", "playermodels" ); - vg_syscall( "mkdir -p bin/%s/cfg", project_name ); - vg_syscall( "mkdir -p bin/%s/savedata", project_name ); - vg_syscall( "mkdir -p bin/%s/tools", project_name ); - vg_syscall( "cp blender_export.py bin/%s/tools/", project_name ); +#define _S( NAME, VS, FS ) \ + vg_build_shader( "shaders/" VS, "shaders/" FS, NULL, "shaders", NAME ) + +void build_shaders(void){ + vg_info( "Compiling shader headers\n" ); + vg_shader_set_include_dir( "shaders" ); + + /* Scene */ + _S( "scene_standard", "scene.vs", "scene_standard.fs" ); + _S( "scene_standard_alphatest", "scene.vs", "scene_standard_alphatest.fs" ); + _S( "scene_foliage", "scene_foliage.vs", "scene_foliage.fs" ); + _S( "scene_override", "scene_override.vs", "scene_override.fs" ); + _S( "scene_fxglow", "scene_fxglow.vs", "scene_fxglow.fs" ); + _S( "scene_vertex_blend", "scene.vs", "scene_vertex_blend.fs" ); + _S( "scene_terrain", "scene.vs", "scene_terrain.fs" ); + _S( "scene_route", "scene_override.vs", "scene_route.fs" ); + _S( "scene_depth", "scene.vs", "scene_depth.fs" ); + _S( "scene_position", "scene.vs", "scene_position.fs" ); + _S( "scene_cubemapped", "scene.vs", "scene_cubemapped.fs" ); + _S( "scene_water", "scene.vs", "scene_water.fs" ); + _S( "scene_water_fast", "scene.vs", "scene_water_fast.fs" ); + _S( "scene_scoretext", "scene_sfd.vs", "scene_standard.fs" ); + _S( "scene_font", "model_font.vs","scene_font.fs" ); + + /* Models */ + _S( "model_sky", "model.vs", "model_sky.fs" ); + _S( "model_sky_space", "model.vs", "model_sky_space.fs" ); + _S( "model_menu", "model.vs", "model_menu.fs" ); + _S( "model_character_view", "model_skinned.vs", "model_character_view.fs" ); + _S( "model_board_view", "model.vs", "model_character_view.fs" ); + _S( "model_entity", "model.vs", "model_entity.fs" ); + _S( "model_gate", "model.vs", "model_gate_lq.fs" ); + _S( "model_gate_unlinked", "model.vs", "model_gate_unlinked.fs" ); + _S( "model_font", "model_font.vs", "model_font.fs" ); + + _S( "particle", "particle.vs", "particle.fs" ); + _S( "trail", "trail.vs", "trail.fs" ); + + /* 2D */ + _S( "blit", "blit.vs", "blit.fs" ); + _S( "blitblur", "blit.vs", "blitblur.fs" ); + _S( "blitcolour","blit.vs", "colour.fs" ); + _S( "blit_transition", "blit.vs", "blit_transition.fs" ); + _S( "routeui", "routeui.vs", "routeui.fs" ); + + vg_build_shader_impl( "shaders/impl.c" ); +} + +void build_game_content( struct vg_project *proj ) +{ + vg_project_new_target( proj, "Content files", k_obj_type_none ); + + vg_symlink( proj, "textures_src", "textures" ); + vg_symlink( proj, "models_src", "models" ); + vg_symlink( proj, "boards_src", "boards" ); + vg_symlink( proj, "maps_src", "maps" ); + vg_symlink( proj, "sound_src", "sound" ); + vg_symlink( proj, "playermodels_src", "playermodels" ); + vg_syscall( "mkdir -p bin/%s/cfg", proj->uid.buffer ); + vg_syscall( "mkdir -p bin/%s/savedata", proj->uid.buffer ); + vg_syscall( "mkdir -p bin/%s/tools", proj->uid.buffer ); + vg_syscall( "cp bin/skaterift_blender.zip bin/%s/tools/", proj->uid.buffer ); } -void build_shaders(void); -void compile_game( int binaries, int content ){ +void build_game_bin( struct vg_project *proj ) +{ static int meta = 0; if( !meta ){ meta = 1; @@ -108,109 +157,142 @@ void compile_game( int binaries, int content ){ vg_low( "\n\n" ); } - vg_build_new( "skaterift" ); + vg_project_new_target( proj, "skaterift", k_obj_type_exe ); + vg_add_engine( proj, &(struct vg_engine_config ) + { + .fixed_update_hz = 60, + .legacy_support_vg_msg1 = 1, + .log_source_info = 1, + .steam_api = 1, + .use_3d = 1, + .custom_game_settings = 0, + .custom_shaders = 1 + }); + + vg_add_source( proj, "skaterift.c " ); + vg_add_controller_database( proj ); + vg_compile_project( proj ); +} - if( binaries ){ - vg_add_source( "skaterift.c" ); - vg_add_graphics(); - vg_add_game_stuff(); - vg_compile( "skaterift" ); - } +void build_sqlite_for_env( struct vg_env *env, struct vg_project *out_proj ) +{ + struct vg_env sqlite_env = *env; + sqlite_env.optimization = 3; /* force optimization always */ + sqlite_env.debug_asan = 0; + + vg_project_init( out_proj, env, "sqlite3" ); + vg_project_new_target( out_proj, "sqlite3", k_obj_type_obj ); - if( content ) - build_game_content(); + vg_add_source( out_proj, "-c dep/sqlite3/sqlite3.c " ); + vg_link( out_proj, "-ldl " ); + vg_compile_project( out_proj ); } -void compile_sqlite_obj(void){ - vg_build_new( "sqlite3.o" ); - vg_add_source( "-c dep/sqlite3/sqlite3.c " ); - vg_link( "-ldl " ); - vg_compile( "sqlite3.o" ); +void compile_server( struct vg_project *proj ) +{ + struct vg_project sqlite_project; + build_sqlite_for_env( proj->env, &sqlite_project ); + + vg_project_new_target( proj, "server", k_obj_type_exe ); + vg_add_source( proj, "gameserver.c vg/vg_tool.c vg/vg_steam.c \\\n " ); + vg_add_source( proj, sqlite_project.compiled_objects.buffer ); + vg_include_dir( proj, "-I./dep " ); + vg_library_dir( proj, "-L./vg/dep/steam " ); + vg_link( proj, "-ldl -lpthread -lm -lsdkencryptedappticket -lsteam_api " ); + vg_add_blob( proj, "vg/dep/steam/libsteam_api.so", "" ); + vg_add_blob( proj, "vg/dep/steam/libsdkencryptedappticket.so", "" ); + + vg_compile_project( proj ); } -void compile_server(void){ - vg_build_new( "skaterift_server" ); - vg_add_source( "gameserver.c" ); - vg_add_source( "bin/sqlite3.o-linux-x86_64-clang/sqlite3.o" ); - vg_include_dir( "-I./dep " ); - vg_library_dir( "-L./vg/dep/steam " ); - vg_link( "-ldl -lpthread -lm -lsdkencryptedappticket -lsteam_api " ); - vg_add_blob( "vg/dep/steam/libsteam_api.so", "" ); - vg_add_blob( "vg/dep/steam/libsdkencryptedappticket.so", "" ); - vg_compile( "server" ); +void compile_tools( struct vg_project *proj ) +{ + vg_project_new_target( proj, "skaterift", k_obj_type_shared ); + vg_add_source( proj, "skaterift_lib.c " ); + vg_compile_project( proj ); } /* * Scripts * -------------------------------------------------------------------------- */ -void s_release_all(void){ +void s_compile_tools(void) +{ + vg_info( "running script: s_compile_tools(void)\n" ); + struct vg_env env = vg_release_env; + env.platform = k_platform_linux; + + struct vg_project windows_proj, linux_proj; + vg_project_init( &linux_proj, &env, "skaterift-tools" ); + compile_tools( &linux_proj ); + + env.platform = k_platform_windows; + vg_project_init( &windows_proj, &env, "skaterift-tools" ); + compile_tools( &windows_proj ); + + vg_syscall("cp %s skaterift_blender/", linux_proj.compiled_objects.buffer ); + vg_syscall("cp %s skaterift_blender/", windows_proj.compiled_objects.buffer); + vg_syscall( "zip -r bin/skaterift_blender.zip skaterift_blender/ " + "-x skaterift_blender/__pycache__/\\*"); +} + +void s_release_all(void) +{ vg_info( "running script: s_release_all(void)\n" ); - vg_build.optimization = 3; - vg_build.fresh = 1; - vg_build.arch = k_architecture_x86_64; - vg_build.compiler = k_compiler_zigcc; - vg_build.libc = k_libc_version_2_23; - - /* binaries for windows and linux */ - vg_build.platform = k_platform_windows; - compile_game( 1, 0 ); - vg_tarball_last_project(); /* windows binary depot: 2103942 */ - vg_success( "Completed 1/3\n" ); - - vg_build.platform = k_platform_linux; - compile_game( 1, 0 ); - vg_tarball_last_project(); /* linux binary depot: 2103941 */ - vg_success( "Completed 2/3\n" ); - - /* content files for any platform */ - vg_build.platform = k_platform_anyplatform; - vg_build.compiler = k_compiler_blob; - vg_build.arch = k_architecture_anyarch; - vg_build.libc = k_libc_version_native; - compile_game( 0, 1 ); - vg_tarball_last_project(); /* content depot: 2103943 */ - vg_success( "Completed 3/3\n" ); - - /* TODO: DRM thingy? */ + struct vg_project content_proj, windows_proj, linux_proj; + + struct vg_env env = vg_release_env; + env.platform = k_platform_anyplatform; + vg_project_init( &content_proj, &env, "skaterift" ); + build_game_content( &content_proj ); + + /* binaries for windows */ + env = vg_release_env; + env.platform = k_platform_windows; + vg_project_init( &windows_proj, &env, "skaterift" ); + build_game_bin( &windows_proj ); + + /* binaries for linux */ + env = vg_release_env; + env.platform = k_platform_linux; + vg_project_init( &linux_proj, &env, "skaterift" ); + build_game_bin( &linux_proj ); + + /* package them up for storage */ + vg_tarball_project( &content_proj ); + vg_tarball_project( &linux_proj ); + vg_tarball_project( &windows_proj ); + + /* extreme DRM solutions */ + FILE *fp = fopen( "dist/bin/DRM", "w" ); + fputs( "blibby!", fp ); + fclose( fp ); } -void s_testing_build(void){ +void s_testing_build(void) +{ vg_info( "running script: s_testing_build(void)\n" ); - vg_build.optimization = optimize_test_compile; - vg_build.fresh = 0; - vg_build.platform = k_platform_linux; - vg_build.arch = k_architecture_x86_64; - vg_build.compiler = k_compiler_clang; - vg_build.libc = k_libc_version_native; - - compile_game( 1, 1 ); + struct vg_project test_proj; + vg_project_init( &test_proj, &vg_test_env, "skaterift-test" ); - vg_success( "Completed 1/1\n" ); + build_game_bin( &test_proj ); + build_game_content( &test_proj ); + vg_add_blob( &test_proj, "steam_appid.txt", "" ); } -void s_testing_server(void){ +void s_testing_server(void) +{ vg_info( "running script: s_testing_server(void)\n" ); - vg_build.fresh = 0; - vg_build.platform = k_platform_linux; - vg_build.arch = k_architecture_x86_64; - vg_build.compiler = k_compiler_clang; - vg_build.libc = k_libc_version_native; - - /* build sqlite3, alwasy optimized */ - vg_build.optimization = 3; - compile_sqlite_obj(); - vg_success( "Completed 1/2\n" ); - - vg_build.optimization = optimize_test_compile; - compile_server(); - vg_success( "Completed 2/2\n" ); + struct vg_project test_proj; + vg_project_init( &test_proj, &vg_test_env, "skaterift-test-server" ); + compile_server( &test_proj ); } -int main( int argc, char *argv[] ){ +int main( int argc, char *argv[] ) +{ char *arg; while( vg_argp( argc, argv ) ){ if( vg_long_opt( "release-all" ) ) @@ -222,58 +304,12 @@ int main( int argc, char *argv[] ){ if( vg_long_opt( "testing-server" ) ) s_testing_server(); + if( vg_long_opt( "tools" ) ) + s_compile_tools(); + if( vg_opt('r') ) - optimize_test_compile = 3; + vg_test_env.optimization = 3; } - if( vg_build.warnings ) - vg_warn( "Finished with %u warnings\n", vg_build.warnings ); - else - vg_success( "All scripts ran successfully\n" ); -} - -#define _S( NAME, VS, FS ) \ - vg_build_shader( "shaders/" VS, "shaders/" FS, NULL, "shaders", NAME ) - -void build_shaders(void){ - vg_info( "Compiling shader headers\n" ); - vg_shader_set_include_dir( "shaders" ); - - /* Scene */ - _S( "scene_standard", "scene.vs", "scene_standard.fs" ); - _S( "scene_standard_alphatest", "scene.vs", "scene_standard_alphatest.fs" ); - _S( "scene_foliage", "scene_foliage.vs", "scene_foliage.fs" ); - _S( "scene_override", "scene_override.vs", "scene_override.fs" ); - _S( "scene_fxglow", "scene_fxglow.vs", "scene_fxglow.fs" ); - _S( "scene_vertex_blend", "scene.vs", "scene_vertex_blend.fs" ); - _S( "scene_terrain", "scene.vs", "scene_terrain.fs" ); - _S( "scene_route", "scene_override.vs", "scene_route.fs" ); - _S( "scene_depth", "scene.vs", "scene_depth.fs" ); - _S( "scene_position", "scene.vs", "scene_position.fs" ); - _S( "scene_cubemapped", "scene.vs", "scene_cubemapped.fs" ); - _S( "scene_water", "scene.vs", "scene_water.fs" ); - _S( "scene_water_fast", "scene.vs", "scene_water_fast.fs" ); - _S( "scene_scoretext", "scene_sfd.vs", "scene_standard.fs" ); - _S( "scene_font", "model_font.vs","scene_font.fs" ); - - /* Models */ - _S( "model_sky", "model.vs", "model_sky.fs" ); - _S( "model_sky_space", "model.vs", "model_sky_space.fs" ); - _S( "model_menu", "model.vs", "model_menu.fs" ); - _S( "model_character_view", "model_skinned.vs", "model_character_view.fs" ); - _S( "model_board_view", "model.vs", "model_character_view.fs" ); - _S( "model_entity", "model.vs", "model_entity.fs" ); - _S( "model_gate", "model.vs", "model_gate_lq.fs" ); - _S( "model_gate_unlinked", "model.vs", "model_gate_unlinked.fs" ); - _S( "model_font", "model_font.vs", "model_font.fs" ); - - _S( "particle", "particle.vs", "particle.fs" ); - _S( "trail", "trail.vs", "trail.fs" ); - - /* 2D */ - _S( "blit", "blit.vs", "blit.fs" ); - _S( "blitblur", "blit.vs", "blitblur.fs" ); - _S( "blitcolour","blit.vs", "colour.fs" ); - _S( "blit_transition", "blit.vs", "blit_transition.fs" ); - _S( "routeui", "routeui.vs", "routeui.fs" ); + vg_success( "All scripts completed\n" ); }