Woopsie cleanup

This commit is contained in:
Charlie Malmqvist 2024-07-23 17:34:03 +02:00
parent 4aa832a822
commit f36e2b73a7
5 changed files with 0 additions and 169 deletions

View file

@ -1,79 +0,0 @@
///
// Build config stuff
#define OOGABOOGA_BUILD_SHARED_LIBRARY 1
#include "oogabooga/oogabooga.c"
///
///
// This is the "engine" part of your game, which will call into your game.dll
typedef void (*Game_Update_Proc)(f64);
Game_Update_Proc game_update;
Dynamic_Library_Handle dll = 0;
void load_game_dll(char **argv) {
// Here we load all the game symbols
if (dll) {
os_unload_dynamic_library(dll);
}
string exe_path = STR(argv[0]);
string exe_dir = get_directory_of(exe_path);
// We need to copy the original and open the copy, so we can recompile the original and then close & replace
// the copy.
string dll_path = string_concat(exe_dir, STR("/game.dll"), get_temporary_allocator());
string used_dll_path = string_concat(exe_dir, STR("/game-in-use.dll"), get_temporary_allocator());
bool ok = os_file_copy(dll_path, used_dll_path, true);
assert(ok, "Could not copy %s to %s", dll_path, used_dll_path);
dll = os_load_dynamic_library(used_dll_path);
assert(dll, "Failed loading game dll");
game_update = os_dynamic_library_load_symbol(dll, STR("game_update"));
assert(game_update, "game is missing game_update()");
log("Loaded game procedures");
}
int entry(int argc, char **argv) {
load_game_dll(argv);
window.title = STR("Minimal Game Example");
window.scaled_width = 1280; // We need to set the scaled size if we want to handle system scaling (DPI)
window.scaled_height = 720;
window.x = 200;
window.y = 90;
window.clear_color = hex_to_rgba(0x6495EDff);
float64 last_time = os_get_current_time_in_seconds();
while (!window.should_close) {
float64 now = os_get_current_time_in_seconds();
float64 delta = now-last_time;
if ((int)now != (int)last_time) log("%.2f FPS\n%.2fms", 1.0/(delta), (delta)*1000);
last_time = now;
reset_temporary_storage();
game_update(delta);
if (is_key_just_pressed('R')) {
load_game_dll(argv);
play_one_audio_clip(STR("oogabooga/examples/bruh.wav"));
}
os_update();
gfx_update();
}
return 0;
}

View file

@ -1,30 +0,0 @@
// !!!!!!!! BUILD CONFIG SHOULD BE DONE IN build_engine.c
#define OOGABOOGA_LINK_EXTERNAL_INSTANCE 1
#include "oogabooga/oogabooga.c"
///
///
// This is the game module which is what can be recompiled in the engine runtime
// For the engine to be able to detect a symbol, it needs to be marked with SHARED_EXPORT
void SHARED_EXPORT
game_update(f64 delta_time) {
float64 now = os_get_current_time_in_seconds();
Matrix4 rect_xform = m4_scalar(1.0);
rect_xform = m4_rotate_z(rect_xform, (f32)now);
rect_xform = m4_translate(rect_xform, v3(-.25f, -.25f, 0));
draw_rect_xform(rect_xform, v2(.5f, .5f), COLOR_GREEN);
draw_rect(v2(sin(now), -.8), v2(.5, .25), COLOR_RED);
float aspect = (f32)window.width/(f32)window.height;
float mx = (input_frame.mouse_x/(f32)window.width * 2.0 - 1.0)*aspect;
float my = input_frame.mouse_y/(f32)window.height * 2.0 - 1.0;
draw_line(v2(-.75, -.75), v2(mx, my), 0.005, COLOR_WHITE);
}

View file

@ -1,36 +0,0 @@
// !!!!!!!! BUILD CONFIG SHOULD BE DONE IN build_engine.c
#define OOGABOOGA_LINK_EXTERNAL_INSTANCE 1
#include "oogabooga/oogabooga.c"
// All we do with the launcher is to launch the engine
// We need to be careful to use oogabooga things because it has not yet been initialized.
// We can use get_temporary_allocator() because that actually gives us the initialization allocator.
// We cannot use log() but we can use print()
int main(int argc, char **argv) {
string exe_path = STR(argv[0]);
string exe_dir = get_directory_of(exe_path);
Allocator a = get_initialization_allocator();
string dll_path = string_concat(exe_dir, STR("/engine.dll"), a);
Dynamic_Library_Handle dll = os_load_dynamic_library(dll_path);
if (!dll) {
os_write_string_to_stdout(STR("Failed loading engine dll from "));
os_write_string_to_stdout(dll_path);
os_write_string_to_stdout(STR("\n"));
return -1;
}
int (*engine_main)(int, char**) = os_dynamic_library_load_symbol(dll, STR("main"));
if (!engine_main) {
os_write_string_to_stdout(STR("Failed loading engine main\n"));
return -1;
}
print("Launcher found engine main(), running...\n");
return engine_main(argc, argv);
}

View file

@ -1,16 +0,0 @@
@echo on
if exist build (
rmdir /s /q build
)
mkdir build
pushd build
clang ../build_engine.c -g -shared -o engine.dll -O0 -std=c11 -D_CRT_SECURE_NO_WARNINGS -Wextra -Wno-incompatible-library-redeclaration -Wno-sign-compare -Wno-unused-parameter -Wno-builtin-requires-header -fuse-ld=lld -lkernel32 -lgdi32 -luser32 -lruntimeobject -lwinmm -ld3d11 -ldxguid -ld3dcompiler -lshlwapi -lole32 -lavrt -lksuser -ldbghelp -femit-all-decls -Xlinker /IMPLIB:engine.lib -Xlinker /MACHINE:X64 -Xlinker /SUBSYSTEM:CONSOLE
clang ../build_launcher.c -g -o launcher.exe -O0 -std=c11 -D_CRT_SECURE_NO_WARNINGS -Wextra -Wno-incompatible-library-redeclaration -Wno-sign-compare -Wno-unused-parameter -Wno-builtin-requires-header -femit-all-decls -luser32 -fuse-ld=lld -L. -lengine -Xlinker /SUBSYSTEM:CONSOLE
clang ../build_game.c -g -shared -o game.dll -O0 -std=c11 -D_CRT_SECURE_NO_WARNINGS -Wextra -Wno-incompatible-library-redeclaration -Wno-sign-compare -Wno-unused-parameter -Wno-builtin-requires-header -femit-all-decls -luser32 -fuse-ld=lld -L. -lengine -Xlinker /SUBSYSTEM:CONSOLE
popd

View file

@ -1,8 +0,0 @@
@echo on
pushd build
clang ../build_game.c -g -shared -o game.dll -O0 -std=c11 -D_CRT_SECURE_NO_WARNINGS -Wextra -Wno-incompatible-library-redeclaration -Wno-sign-compare -Wno-unused-parameter -Wno-builtin-requires-header -femit-all-decls -luser32 -fuse-ld=lld -L. -lengine -Xlinker /SUBSYSTEM:CONSOLE
popd