diff --git a/README.md b/README.md index 07ce7d3..e3933f9 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# rpgpt -RPG GPT. Short experience +# [Dante's Cowboy - Wishlist now on Steam!](https://store.steampowered.com/app/2501370/Dantes_Cowboy) +A fantasy western RPG with an immersive and natural dynamic dialogue system powered by GPT. ![Western Frontier](https://upload.wikimedia.org/wikipedia/commons/thumb/3/32/Distribution_of_US_Rural_Population_during_1900.pdf/page1-1280px-Distribution_of_US_Rural_Population_during_1900.pdf.jpg) # Important Building Steps and Contribution Notes -Every time you checkin/clone the project, you have to unzip art.blend... If this is annoying to you, make a git hook +Every time you checkin/clone the project, make sure to call `blender_export.bat` at least once! This will auto-extract `art\art.blend` and run `art\Exporter.py`, thereby baking, validating, and exporting all the assets and the level. When editing Exporter.py in either the blender editor, or in a text editor in the repo, you have to continually make sure blender's internal version of the script doesn't go out of date with the actual script on disk, by either saving consistently from blender to disk if you're editing from blender, or by reloading from disk in the blend file before each commit. diff --git a/blender_export.bat b/blender_export.bat new file mode 100644 index 0000000..0f6548d --- /dev/null +++ b/blender_export.bat @@ -0,0 +1,33 @@ +@echo off + +pushd %~dp0%\art + +if not exist "art.blend" ( + powershell Expand-Archive -Path art.zip -DestinationPath . || goto :error +) + +set "blender=" +if exist "%ProgramFiles%\Blender Foundation\Blender 3.5\blender.exe" ( + echo Using Blender 3.5 detected + set "blender=%ProgramFiles%\Blender Foundation\Blender 3.5\blender.exe" +) +if exist "%ProgramFiles%\Blender Foundation\Blender 3.6\blender.exe" ( + echo Using Blender 3.6 detected + set "blender=%ProgramFiles%\Blender Foundation\Blender 3.6\blender.exe" +) + +if "%blender%" neq "" ( + call "%blender%" --background art.blend --python Exporter.py || goto :error +) else ( + goto :error +) + +goto :success + +:error +echo Blender export failed + +:success +set "returncode=%ERRORLEVEL%" +popd +exit /B %returncode% diff --git a/build_and_run_remedy.bat b/build_and_run_remedy.bat index 73a550c..1e22d04 100644 --- a/build_and_run_remedy.bat +++ b/build_and_run_remedy.bat @@ -1,5 +1,5 @@ @echo off START /B remedybg.exe stop-debugging -call build_desktop_debug.bat +call build_desktop_debug.bat %* remedybg.exe start-debugging diff --git a/build_and_run_web.bat b/build_and_run_web.bat new file mode 100644 index 0000000..757af34 --- /dev/null +++ b/build_and_run_web.bat @@ -0,0 +1,7 @@ +@echo off + +call build_web_debug.bat %* || goto :EOF +START "" "http://localhost:8000" +pushd %~dp0%\build_web +python -m http.server +popd diff --git a/build_desktop_debug.bat b/build_desktop_debug.bat index f5e8bda..6cd2744 100644 --- a/build_desktop_debug.bat +++ b/build_desktop_debug.bat @@ -2,10 +2,18 @@ @REM https://learn.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-by-category?view=msvc-170 +setlocal enableDelayedExpansion +set "do_blender_export=0" +set "do_codegen=0" +for %%A in (%*) do ( + if "%%~A"=="blender_export" ( set "do_blender_export=1" ) + if "%%~A"=="codegen" ( set "do_codegen=1" ) +) +if "%do_blender_export%"=="1" ( call blender_export.bat || goto :error ) +if "%do_codegen%"=="1" ( call run_codegen.bat || goto :error ) -if "%1" == "codegen" ( call run_codegen.bat || goto :error ) else ( echo NOT RUNNING CODEGEN ) @REM start /B zig cc -DDEVTOOLS -Igen -Ithirdparty -lDbghelp -lGdi32 -lD3D11 -lOle32 -lwinhttp -gfull -gcodeview -o main_zig.exe main.c -cl /diagnostics:caret /DDEVTOOLS /Igen /Ithirdparty /Wall /FC /Zi /WX Dbghelp.lib winhttp.lib main.c || goto :error +cl /nologo /diagnostics:caret /DDEVTOOLS /Igen /Ithirdparty /Wall /FC /Zi /WX main.c /link /noimplib /noexp || goto :error goto :EOF diff --git a/build_web_common.bat b/build_web_common.bat index a1d6560..be59b2e 100644 --- a/build_web_common.bat +++ b/build_web_common.bat @@ -1,9 +1,17 @@ -call run_codegen.bat || goto :error +setlocal enableDelayedExpansion +set "do_blender_export=0" +set "do_codegen=0" +for %%A in (%*) do ( + if "%%~A"=="blender_export" ( set "do_blender_export=1" ) + if "%%~A"=="codegen" ( set "do_codegen=1" ) +) +if "%do_blender_export%"=="1" ( call blender_export.bat || goto :error ) +if "%do_codegen%"=="1" ( call run_codegen.bat || goto :error ) copy marketing_page\favicon.ico %OUTPUT_FOLDER%\favicon.ico @REM copy main.c %OUTPUT_FOLDER%\main.c || goto :error -@echo on +@echo off emcc ^ -sEXPORTED_FUNCTIONS=_main,_end_text_input,_stop_controlling_input,_start_controlling_input,_read_from_save_data,_dump_save_data,_is_receiving_text_input^ -sEXPORTED_RUNTIME_METHODS=ccall,cwrap^ diff --git a/build_web_debug.bat b/build_web_debug.bat index 0de78bf..776749f 100644 --- a/build_web_debug.bat +++ b/build_web_debug.bat @@ -10,25 +10,16 @@ set FLAGS=-O0 -g -DDEVTOOLS set OUTPUT_FOLDER=build_web -if "%1" == "NO_VALIDATION" ( - echo Disabling graphics validation... - set FLAGS=%FLAGS% -DNDEBUG -) - -call build_web_common.bat || goto :error +call build_web_common.bat %* || goto :error @echo off -if "%1" == "NO_VALIDATION" ( - echo Validation turned off -) else ( - echo If you want to turn graphics validation off to make web debug build faster, provide a command line argument called "NO_VALIDATION" to this build script -) - goto :success :error echo Failed to build + :success +set "returncode=%ERRORLEVEL%" popd -exit /B %ERRORLEVEL% +exit /B %returncode% diff --git a/build_web_release.bat b/build_web_release.bat index 301ac74..ac6de06 100644 --- a/build_web_release.bat +++ b/build_web_release.bat @@ -5,17 +5,17 @@ pushd %~dp0% rmdir /S /q build_web_release mkdir build_web_release -call run_codegen.bat || goto :error - set FLAGS=-O0 -DNDEBUG set OUTPUT_FOLDER=build_web_release -call build_web_common.bat || goto :error +call build_web_common.bat %* codegen || goto :error goto :success :error echo Failed to build + :success +set "returncode=%ERRORLEVEL%" popd -exit /B %ERRORLEVEL% +exit /B %returncode% diff --git a/main.c b/main.c index 9e2523b..fd5c463 100644 --- a/main.c +++ b/main.c @@ -21,11 +21,13 @@ #define DESKTOP #define WINDOWS #define SOKOL_GLCORE33 +#define SAMPLE_COUNT 4 #endif #if defined(__EMSCRIPTEN__) #define WEB #define SOKOL_GLES2 +#define SAMPLE_COUNT 1 // bumping this back to 4 is troublesome for web, because there's a mismatch in sample counts. Perhaps we must upgrade to gles3, in doing so, we should upgrade to the newest sokol gfx. #endif #define DRWAV_ASSERT game_assert @@ -41,8 +43,6 @@ #pragma warning(push, 3) #include -#include -#include #include // https://developer.download.nvidia.com/devzone/devcenter/gamegraphics/files/OptimusRenderingPolicies.pdf @@ -53,13 +53,19 @@ __declspec(dllexport) uint32_t AmdPowerXpressRequestHighPerformance = 0x00000001 #endif -#define STRINGIZE(x) STRINGIZE2(x) -#define STRINGIZE2(x) #x - #include "buff.h" #include "sokol_app.h" #pragma warning(push) #pragma warning(disable : 4191) // unsafe function calling +#ifdef WEB +# ifndef GL_EXT_PROTOTYPES +# define GL_GLEXT_PROTOTYPES +# endif +# include +# include +# undef glGetError +# define glGetError() (GL_NO_ERROR) +#endif #include "sokol_gfx.h" #pragma warning(pop) #include "sokol_time.h" @@ -467,6 +473,7 @@ LPCWSTR windows_string(MD_String8 s) #ifdef DESKTOP #ifdef WINDOWS #pragma warning(push, 3) +#pragma comment(lib, "WinHttp") #include #include #pragma warning(pop) @@ -2703,7 +2710,7 @@ void create_screenspace_gfx_state() .depth = { 0 }, - .sample_count = 1, + .sample_count = SAMPLE_COUNT, .layout = { .attrs = { @@ -2733,7 +2740,7 @@ void create_screenspace_gfx_state() .depth = { .pixel_format = SG_PIXELFORMAT_NONE, }, - .sample_count = 1, + .sample_count = SAMPLE_COUNT, .layout = { .attrs = { @@ -2765,7 +2772,7 @@ void create_screenspace_gfx_state() .wrap_u = SG_WRAP_CLAMP_TO_BORDER, .wrap_v = SG_WRAP_CLAMP_TO_BORDER, .border_color = SG_BORDERCOLOR_OPAQUE_WHITE, - .sample_count = 1, + .sample_count = SAMPLE_COUNT, .label = "outline-pass-render-target", }; state.outline_pass_image = sg_make_image(&desc); @@ -2777,7 +2784,7 @@ void create_screenspace_gfx_state() .label = "outline-pass", }); - desc.sample_count = 1; + desc.sample_count = SAMPLE_COUNT; desc.label = "threedee-pass-render-target"; state.threedee_pass_image = sg_make_image(&desc); @@ -3750,9 +3757,11 @@ typedef enum typedef BUFF(char, 200) StacktraceElem; typedef BUFF(StacktraceElem, 16) StacktraceInfo; +#if 0 // #ifdef WINDOWS +#include +#pragma comment(lib, "DbgHelp") StacktraceInfo get_stacktrace() { -#ifdef WINDOWS StacktraceInfo to_return = {0}; void *stack[ARRLEN(to_return.data)] = {0}; int captured = CaptureStackBackTrace(0, ARRLEN(to_return.data), stack, 0); @@ -3786,10 +3795,13 @@ StacktraceInfo get_stacktrace() free(symbol); } return to_return; +} #else +StacktraceInfo get_stacktrace() +{ return (StacktraceInfo){0}; -#endif } +#endif typedef struct DrawParams { @@ -4850,7 +4862,7 @@ Shadow_State init_shadow_state() { .wrap_u = SG_WRAP_CLAMP_TO_BORDER, .wrap_v = SG_WRAP_CLAMP_TO_BORDER, .border_color = SG_BORDERCOLOR_OPAQUE_WHITE, - .sample_count = 1, + .sample_count = SAMPLE_COUNT, .label = "shadow-map-color-image" }; shadows.color_img = sg_make_image(&img_desc); @@ -4874,7 +4886,7 @@ Shadow_State init_shadow_state() { .shader = sg_make_shader(threedee_mesh_shadow_mapping_shader_desc(sg_query_backend())), // Cull front faces in the shadow map pass // .cull_mode = SG_CULLMODE_BACK, - .sample_count = 1, + .sample_count = SAMPLE_COUNT, .depth = { .pixel_format = SG_PIXELFORMAT_DEPTH, .compare = SG_COMPAREFUNC_LESS_EQUAL, @@ -7303,9 +7315,31 @@ void event(const sapp_event *e) } #endif - if (e->type == SAPP_EVENTTYPE_KEY_DOWN && e->key_code == SAPP_KEYCODE_F11) + if (e->type == SAPP_EVENTTYPE_KEY_DOWN && + (e->key_code == SAPP_KEYCODE_F11 || + e->key_code == SAPP_KEYCODE_ENTER && ((e->modifiers & SAPP_MODIFIER_ALT) || (e->modifiers & SAPP_MODIFIER_SHIFT)))) { +#ifdef DESKTOP sapp_toggle_fullscreen(); +#else + EM_ASM({ + var elem = document.documentElement; + if (document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement) + { + if (document.exitFullscreen) document.exitFullscreen(); + else if (document.webkitExitFullscreen) document.webkitExitFullscreen(); + else if (document.mozCancelFullScreen) document.mozCancelFullScreen(); + else if (document.msExitFullscreen) document.msExitFullscreen(); + } + else + { + if (elem.requestFullscreen) elem.requestFullscreen(); + else if (elem.webkitRequestFullscreen) elem.webkitRequestFullscreen(); + else if (elem.mozRequestFullScreen) elem.mozRequestFullScreen(); + else if (elem.msRequestFullscreen) elem.msRequestFullscreen(); + } + }); +#endif } #ifdef DEVTOOLS @@ -7529,11 +7563,11 @@ sapp_desc sokol_main(int argc, char* argv[]) .frame_cb = frame, .cleanup_cb = cleanup, .event_cb = event, - .sample_count = 1, // bumping this back to 4 is troublesome for web, because there's a mismatch in sample counts. Perhaps we must upgrade to gles3, in doing so, we should upgrade to the newest sokol gfx. + .sample_count = SAMPLE_COUNT, .width = 800, .height = 600, //.gl_force_gles2 = true, not sure why this was here in example, look into - .window_title = "RPGPT", + .window_title = "Dante's Cowboy", .win32_console_attach = true, .win32_console_create = true, .icon.sokol_default = true, diff --git a/run_codegen.bat b/run_codegen.bat index 5d638b7..1d66612 100644 --- a/run_codegen.bat +++ b/run_codegen.bat @@ -1,9 +1,9 @@ -@echo on +@echo off -echo Running codegen... +@REM echo Running codegen... if exist gen\ ( - echo "Codegen folder already exists, not deleting because that messes with vscode intellisense..." + @REM echo "Codegen folder already exists, not deleting because that messes with vscode intellisense..." ) else ( mkdir gen ) @@ -12,11 +12,11 @@ if exist gen\ ( thirdparty\sokol-shdc.exe --input threedee.glsl --output gen\threedee.glsl.h --slang glsl100:hlsl5:metal_macos:glsl330 || goto :error @REM metadesk codegen -cl /Ithirdparty /W3 /Zi /WX codegen.c || goto :error +cl /nologo /diagnostics:caret /Ithirdparty /W3 /Zi /WX codegen.c || goto :error @REM zig cc -Ithirdparty -gfull -gcodeview codegen.c -o codegen.exe || goto error codegen || goto :error -@REM cl /Ithirdparty /Igen /W3 /Zi /WX maketraining.c || goto :error +@REM cl /nologo /diagnostics:caret /Ithirdparty /Igen /W3 /Zi /WX maketraining.c || goto :error @REM maketraining || goto :error goto :EOF diff --git a/utility.h b/utility.h index dc00fab..8f76ffb 100644 --- a/utility.h +++ b/utility.h @@ -1,43 +1,24 @@ #pragma once #include -#include -#ifdef WEB -#include -#define game_debugbreak() raise(SIGTRAP) - -#define game_assert_4127_push -#define game_assert_4127_pop +#define STRINGIZE(x) STRINGIZE2(x) +#define STRINGIZE2(x) #x +#ifdef WEB +#define assert_impl(cond, str) ((cond) || (EM_ASM({ assert(0, UTF8ToString($0) + UTF8ToString($1)); }, (__func__), (str)), 0)) #elif defined(DESKTOP) -#define game_debugbreak() __debugbreak() - -#define game_assert_4127_push __pragma(warning(push)) __pragma(warning(disable:4127)) -#define game_assert_4127_pop __pragma(warning(pop)) - +#define assert_impl(cond, str) ((cond) || (fputs("Assertion failed: " __FUNCTION__ str "\n", stderr), __debugbreak(), 0)) #else #error "Don't know how to assert for current platform configuration" -#define game_debugbreak() (void)(0) #endif -static void assert_impl(const char *func, const char *file, long line, const char *expression) -{ - fprintf(stderr, "Assert fail in %s(%s:%ld):\n \"%s\"\n", func, file, line, expression); -} - #ifdef NDEBUG -#define game_assert(cond) game_assert_4127_push do { (void)0; } while (0) game_assert_4127_pop +#define game_assert(cond) ((void)0) #else -#define game_assert(cond) game_assert_4127_push do { \ - if (!(cond)) { \ - assert_impl(__func__, __FILE__, __LINE__, #cond); \ - game_debugbreak(); \ - } \ -} while (0) game_assert_4127_pop +#define game_assert(cond) assert_impl(cond, "(" __FILE__ ":" STRINGIZE(__LINE__) "): \"" #cond "\"") #endif - #ifdef assert #undef assert #endif diff --git a/web_template.html b/web_template.html index 0bf028f..2b921c4 100644 --- a/web_template.html +++ b/web_template.html @@ -3,7 +3,7 @@ -AI RPG +Dante's Cowboy