eb3de6285879b9f7f6c3196dd3b32349447da76f
[carveJwlIkooP6JGAAIwe30JlM.git] / build.c
1 #include "vg/vg_tool.h"
2 #include "vg/vg_platform.h"
3 #include "vg/vg_log.h"
4 #include "vg/vg_opt.h"
5 #include "vg/vg_build.h"
6 #include "vg/vg_build_utils_shader.h"
7 #include "vg/vg_msg.h"
8 #include "addon_types.h"
9
10 /*
11 * Addon metadata utilities
12 * -------------------------------------------------------------------------- */
13
14 void write_msg( vg_msg *msg, const char *path ){
15 FILE *fp = fopen( path, "wb" );
16 if( !fp ){
17 vg_error( "Cannot open %s for writing.\n", path );
18 exit(0);
19 }
20
21 fwrite( msg->buf, msg->cur.co, 1, fp );
22 fclose( fp );
23 vg_success( "Written %s (%ub)\n", path, msg->cur );
24 }
25
26 void write_generic_addon_inf( u32 type, const char *title,
27 const char *content, const char *dest )
28 {
29 u8 descriptor_buf[ 512 ];
30 vg_msg descriptor = {0};
31 descriptor.buf = descriptor_buf;
32 descriptor.max = sizeof(descriptor_buf);
33 vg_msg_frame( &descriptor, "workshop" );
34 vg_msg_wkvstr( &descriptor, "title", title );
35 vg_msg_wkvstr( &descriptor, "author", "Skaterift" );
36 vg_msg_wkvnum( &descriptor, "type", k_vg_msg_u32, 1, &type );
37 vg_msg_end_frame( &descriptor );
38 vg_msg_wkvstr( &descriptor, "content", content );
39 write_msg( &descriptor, dest );
40 }
41
42 /*
43 * Compilation specifications
44 * -------------------------------------------------------------------------- */
45
46 /* operates in the local files, not in the bin folders */
47 void build_game_metadata(void)
48 {
49 vg_info( "Building game metadata\n" );
50 write_generic_addon_inf( k_addon_type_board,
51 "Longboard", "board.mdl",
52 "boards_src/skaterift_long/addon.inf");
53 write_generic_addon_inf( k_addon_type_board,
54 "Fractal", "board.mdl",
55 "boards_src/skaterift_fract/addon.inf");
56 write_generic_addon_inf( k_addon_type_board,
57 "Striped", "board.mdl",
58 "boards_src/skaterift_striped/addon.inf");
59 write_generic_addon_inf( k_addon_type_board,
60 "Licco", "board.mdl",
61 "boards_src/skaterift_licco/addon.inf");
62 write_generic_addon_inf( k_addon_type_board,
63 "Hypno", "board.mdl",
64 "boards_src/skaterift_spiral/addon.inf");
65 write_generic_addon_inf( k_addon_type_board,
66 "Shark", "board.mdl",
67 "boards_src/skaterift_shark/addon.inf");
68
69 write_generic_addon_inf( k_addon_type_player,
70 "De'folde", "ch_new.mdl",
71 "playermodels_src/skaterift_new/addon.inf" );
72 write_generic_addon_inf( k_addon_type_player,
73 "Jordan", "ch_jordan.mdl",
74 "playermodels_src/skaterift_jordan/addon.inf" );
75 write_generic_addon_inf( k_addon_type_player,
76 "Outlaw", "ch_outlaw.mdl",
77 "playermodels_src/skaterift_outlaw/addon.inf" );
78 write_generic_addon_inf( k_addon_type_player,
79 "Chip", "ch_chip.mdl",
80 "playermodels_src/skaterift_chip/addon.inf" );
81 write_generic_addon_inf( k_addon_type_player,
82 "Aaron", "ch_aaron.mdl",
83 "playermodels_src/skaterift_aaron/addon.inf" );
84 }
85
86 #define _S( NAME, VS, FS ) \
87 vg_build_shader( "shaders/" VS, "shaders/" FS, NULL, "shaders", NAME )
88
89 void build_shaders(void){
90 vg_info( "Compiling shader headers\n" );
91 vg_shader_set_include_dir( "shaders" );
92
93 /* Scene */
94 _S( "scene_standard", "scene.vs", "scene_standard.fs" );
95 _S( "scene_standard_alphatest", "scene.vs", "scene_standard_alphatest.fs" );
96 _S( "scene_foliage", "scene_foliage.vs", "scene_foliage.fs" );
97 _S( "scene_override", "scene_override.vs", "scene_override.fs" );
98 _S( "scene_fxglow", "scene_fxglow.vs", "scene_fxglow.fs" );
99 _S( "scene_vertex_blend", "scene.vs", "scene_vertex_blend.fs" );
100 _S( "scene_terrain", "scene.vs", "scene_terrain.fs" );
101 _S( "scene_route", "scene_override.vs", "scene_route.fs" );
102 _S( "scene_depth", "scene.vs", "scene_depth.fs" );
103 _S( "scene_position", "scene.vs", "scene_position.fs" );
104 _S( "scene_cubemapped", "scene.vs", "scene_cubemapped.fs" );
105 _S( "scene_water", "scene.vs", "scene_water.fs" );
106 _S( "scene_water_fast", "scene.vs", "scene_water_fast.fs" );
107 _S( "scene_scoretext", "scene_sfd.vs", "scene_standard.fs" );
108 _S( "scene_font", "model_font.vs","scene_font.fs" );
109
110 /* Models */
111 _S( "model_sky", "model.vs", "model_sky.fs" );
112 _S( "model_sky_space", "model.vs", "model_sky_space.fs" );
113 _S( "model_menu", "model.vs", "model_menu.fs" );
114 _S( "model_character_view", "model_skinned.vs", "model_character_view.fs" );
115 _S( "model_board_view", "model.vs", "model_character_view.fs" );
116 _S( "model_entity", "model.vs", "model_entity.fs" );
117 _S( "model_gate", "model.vs", "model_gate_lq.fs" );
118 _S( "model_gate_unlinked", "model.vs", "model_gate_unlinked.fs" );
119 _S( "model_font", "model_font.vs", "model_font.fs" );
120
121 _S( "particle", "particle.vs", "particle.fs" );
122 _S( "trail", "trail.vs", "trail.fs" );
123
124 /* 2D */
125 _S( "blit", "blit.vs", "blit.fs" );
126 _S( "blitblur", "blit.vs", "blitblur.fs" );
127 _S( "blitcolour","blit.vs", "colour.fs" );
128 _S( "blit_transition", "blit.vs", "blit_transition.fs" );
129 _S( "routeui", "routeui.vs", "routeui.fs" );
130
131 vg_build_shader_impl( "shaders/impl.c" );
132 }
133
134 void build_game_content( struct vg_project *proj )
135 {
136 vg_project_new_target( proj, "Content files", k_obj_type_none );
137
138 vg_symlink( proj, "textures_src", "textures" );
139 vg_symlink( proj, "models_src", "models" );
140 vg_symlink( proj, "boards_src", "boards" );
141 vg_symlink( proj, "maps_src", "maps" );
142 vg_symlink( proj, "sound_src", "sound" );
143 vg_symlink( proj, "playermodels_src", "playermodels" );
144 vg_syscall( "mkdir -p bin/%s/cfg", proj->uid.buffer );
145 vg_syscall( "mkdir -p bin/%s/savedata", proj->uid.buffer );
146 vg_syscall( "mkdir -p bin/%s/tools", proj->uid.buffer );
147 vg_syscall( "cp bin/skaterift_blender.zip bin/%s/tools/", proj->uid.buffer );
148 }
149
150 void build_game_bin( struct vg_project *proj )
151 {
152 static int meta = 0;
153 if( !meta ){
154 meta = 1;
155 build_shaders();
156 build_game_metadata();
157 vg_low( "\n\n" );
158 }
159
160 vg_project_new_target( proj, "skaterift", k_obj_type_exe );
161 vg_add_engine( proj, &(struct vg_engine_config )
162 {
163 .fixed_update_hz = 60,
164 .legacy_support_vg_msg1 = 1,
165 .log_source_info = 1,
166 .steam_api = 1,
167 .use_3d = 1,
168 .custom_game_settings = 0,
169 .custom_shaders = 1
170 });
171
172 vg_add_source( proj, "skaterift.c " );
173 vg_add_controller_database( proj );
174 vg_compile_project( proj );
175 }
176
177 void build_sqlite_for_env( struct vg_env *env, struct vg_project *out_proj )
178 {
179 struct vg_env sqlite_env = *env;
180 sqlite_env.optimization = 3; /* force optimization always */
181 sqlite_env.debug_asan = 0;
182
183 vg_project_init( out_proj, env, "sqlite3" );
184 vg_project_new_target( out_proj, "sqlite3", k_obj_type_obj );
185
186 vg_add_source( out_proj, "-c dep/sqlite3/sqlite3.c " );
187 vg_link( out_proj, "-ldl " );
188 vg_compile_project( out_proj );
189 }
190
191 void compile_server( struct vg_project *proj )
192 {
193 struct vg_project sqlite_project;
194 build_sqlite_for_env( proj->env, &sqlite_project );
195
196 vg_project_new_target( proj, "server", k_obj_type_exe );
197 vg_add_source( proj, "gameserver.c vg/vg_tool.c vg/vg_steam.c \\\n " );
198 vg_add_source( proj, sqlite_project.compiled_objects.buffer );
199 vg_include_dir( proj, "-I./dep " );
200 vg_library_dir( proj, "-L./vg/dep/steam " );
201 vg_link( proj, "-ldl -lpthread -lm -lsdkencryptedappticket -lsteam_api " );
202 vg_add_blob( proj, "vg/dep/steam/libsteam_api.so", "" );
203 vg_add_blob( proj, "vg/dep/steam/libsdkencryptedappticket.so", "" );
204
205 vg_compile_project( proj );
206 }
207
208 void compile_tools( struct vg_project *proj )
209 {
210 vg_project_new_target( proj, "skaterift", k_obj_type_shared );
211 vg_add_source( proj, "skaterift_lib.c " );
212 vg_compile_project( proj );
213 }
214
215 /*
216 * Scripts
217 * -------------------------------------------------------------------------- */
218
219 void s_compile_tools(void)
220 {
221 vg_info( "running script: s_compile_tools(void)\n" );
222 struct vg_env env = vg_release_env;
223 env.platform = k_platform_linux;
224
225 struct vg_project windows_proj, linux_proj;
226 vg_project_init( &linux_proj, &env, "skaterift-tools" );
227 compile_tools( &linux_proj );
228
229 env.platform = k_platform_windows;
230 vg_project_init( &windows_proj, &env, "skaterift-tools" );
231 compile_tools( &windows_proj );
232
233 vg_syscall("cp %s skaterift_blender/", linux_proj.compiled_objects.buffer );
234 vg_syscall("cp %s skaterift_blender/", windows_proj.compiled_objects.buffer);
235 vg_syscall( "zip -r bin/skaterift_blender.zip skaterift_blender/ "
236 "-x skaterift_blender/__pycache__/\\*");
237 }
238
239 void s_release_all(void)
240 {
241 vg_info( "running script: s_release_all(void)\n" );
242
243 struct vg_project content_proj, windows_proj, linux_proj;
244
245 struct vg_env env = vg_release_env;
246 env.platform = k_platform_anyplatform;
247 vg_project_init( &content_proj, &env, "skaterift" );
248 build_game_content( &content_proj );
249
250 /* binaries for windows */
251 env = vg_release_env;
252 env.platform = k_platform_windows;
253 vg_project_init( &windows_proj, &env, "skaterift" );
254 build_game_bin( &windows_proj );
255
256 /* binaries for linux */
257 env = vg_release_env;
258 env.platform = k_platform_linux;
259 vg_project_init( &linux_proj, &env, "skaterift" );
260 build_game_bin( &linux_proj );
261
262 /* package them up for storage */
263 vg_tarball_project( &content_proj );
264 vg_tarball_project( &linux_proj );
265 vg_tarball_project( &windows_proj );
266
267 /* extreme DRM solutions */
268 FILE *fp = fopen( "dist/bin/DRM", "w" );
269 fputs( "blibby!", fp );
270 fclose( fp );
271 }
272
273 void s_testing_build(void)
274 {
275 vg_info( "running script: s_testing_build(void)\n" );
276
277 struct vg_project test_proj;
278 vg_project_init( &test_proj, &vg_test_env, "skaterift-test" );
279
280 build_game_bin( &test_proj );
281 build_game_content( &test_proj );
282 vg_add_blob( &test_proj, "steam_appid.txt", "" );
283 }
284
285 void s_testing_server(void)
286 {
287 vg_info( "running script: s_testing_server(void)\n" );
288
289 struct vg_project test_proj;
290 vg_project_init( &test_proj, &vg_test_env, "skaterift-test-server" );
291 compile_server( &test_proj );
292 }
293
294 int main( int argc, char *argv[] )
295 {
296 char *arg;
297 while( vg_argp( argc, argv ) ){
298 if( vg_long_opt( "release-all" ) )
299 s_release_all();
300
301 if( vg_long_opt( "testing-build" ) )
302 s_testing_build();
303
304 if( vg_long_opt( "testing-server" ) )
305 s_testing_server();
306
307 if( vg_long_opt( "tools" ) )
308 s_compile_tools();
309
310 if( vg_opt('r') )
311 vg_test_env.optimization = 3;
312 }
313
314 vg_success( "All scripts completed\n" );
315 }