diff --git a/CMakeLists.txt b/CMakeLists.txt index bdf71f49..703f9753 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ project(butterscotch C) set(CMAKE_C_STANDARD 99) set(CMAKE_C_STANDARD_REQUIRED ON) -add_compile_options(-Wall -Wextra -Werror -Wno-error=unused-parameter -Wno-error=unused-variable -Wno-error=unused-const-variable -Wno-error=unused-function) +add_compile_options(-Wall -Wextra -Werror) set(PLATFORM "desktop" CACHE STRING "Platform backend") set(DESKTOP_BACKEND "" CACHE STRING "Desktop platform backend") diff --git a/src/audio/miniaudio/ma_audio_system.c b/src/audio/miniaudio/ma_audio_system.c index 15239dcf..93806e23 100644 --- a/src/audio/miniaudio/ma_audio_system.c +++ b/src/audio/miniaudio/ma_audio_system.c @@ -9,7 +9,10 @@ #include "stb_vorbis.c" #define MINIAUDIO_IMPLEMENTATION +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-parameter" #include "miniaudio.h" +#pragma GCC diagnostic pop #include "ma_audio_system.h" #include "data_win.h" diff --git a/src/audio/openal/al_audio_system.c b/src/audio/openal/al_audio_system.c index 3c7e7c21..1194024f 100644 --- a/src/audio/openal/al_audio_system.c +++ b/src/audio/openal/al_audio_system.c @@ -793,7 +793,7 @@ static float maGetSoundLength(AudioSystem* audio, int32_t soundOrInstance) { } static void maSetMasterGain(AudioSystem* audio, float gain) { - AlAudioSystem* ma = (AlAudioSystem*) audio; + (void)audio; alListenerf(AL_GAIN, gain); } diff --git a/src/gl/gl_renderer.c b/src/gl/gl_renderer.c index ffbe5d4b..97587af1 100644 --- a/src/gl/gl_renderer.c +++ b/src/gl/gl_renderer.c @@ -403,12 +403,7 @@ static void glGpuSetShader(Renderer* renderer, int32_t ShaderIndex) { GLint gm_Matrices3 = glGetUniformLocation(Shader, "gm_Matrices[3]"); GLint gm_Matrices4 = glGetUniformLocation(Shader, "gm_Matrices[4]"); - - GLint gm_FogStart = glGetUniformLocation(Shader, "gm_FogStart"); - GLint gm_RcpFogRange = glGetUniformLocation(Shader, "gm_RcpFogRange"); - GLint gm_PS_FogEnabled = glGetUniformLocation(Shader, "gm_PS_FogEnabled"); GLint gm_FogColour = glGetUniformLocation(Shader, "gm_FogColour"); - GLint gm_VS_FogEnabled = glGetUniformLocation(Shader, "gm_VS_FogEnabled"); //Lights are for another time @@ -1803,6 +1798,9 @@ static void glDrawSurface(Renderer* renderer, int32_t surfaceID, int32_t srcLeft } static int32_t glCreateSpriteFromSurface(Renderer* renderer, int32_t surfaceID, int32_t x, int32_t y, int32_t w, int32_t h, bool removeback, bool smooth, int32_t xorig, int32_t yorig) { + // TODO: implement these + (void)smooth; + (void)removeback; GLRenderer* gl = (GLRenderer*) renderer; DataWin* dw = renderer->dataWin; @@ -1927,7 +1925,7 @@ static void glGpuSetBlendEnable(Renderer* renderer, bool enable) { } static bool glGpuGetBlendEnable(Renderer* renderer) { - + (void)renderer; return glIsEnabled(GL_BLEND); } @@ -2220,7 +2218,7 @@ static bool glShaderIsCompiled(Renderer* renderer, int32_t shaderID) { return gl->gmlShaderCompiled[shaderID]; } -static bool glShadersSupported(Renderer* renderer) { +static bool glShadersSupported(void) { return true; } diff --git a/src/gl_legacy/gl_legacy_renderer.c b/src/gl_legacy/gl_legacy_renderer.c index e1a102c9..bb908c6b 100644 --- a/src/gl_legacy/gl_legacy_renderer.c +++ b/src/gl_legacy/gl_legacy_renderer.c @@ -1226,6 +1226,9 @@ static uint32_t findOrAllocTpagSlot(DataWin* dw, uint32_t originalTpagCount) { } static int32_t glCreateSpriteFromSurface(Renderer* renderer, int32_t surfaceID, int32_t x, int32_t y, int32_t w, int32_t h, bool removeback, bool smooth, int32_t xorig, int32_t yorig) { + // TODO: implement these + (void)smooth; + (void)removeback; GLLegacyRenderer* gl = (GLLegacyRenderer*) renderer; DataWin* dw = renderer->dataWin; @@ -1340,7 +1343,8 @@ static void glGpuSetBlendModeExt(MAYBE_UNUSED Renderer* renderer, int32_t sfacto glBlendFunc(GLCommon_blendFactorToGL(sfactor), GLCommon_blendFactorToGL(dfactor)); } -static void glGpuSetBlendEnable(MAYBE_UNUSED Renderer* renderer, bool enable) { +static void glGpuSetBlendEnable(Renderer* renderer, bool enable) { + (void)renderer; enable ? glEnable(GL_BLEND) : glDisable(GL_BLEND); } @@ -1680,7 +1684,7 @@ static void glShaderSetUniformF(MAYBE_UNUSED Renderer* renderer, MAYBE_UNUSED in static void glShaderSetUniformFArray(MAYBE_UNUSED Renderer* renderer, MAYBE_UNUSED int32_t handle, MAYBE_UNUSED float* values, MAYBE_UNUSED uint32_t count) {} static void glShaderSetUniformI(MAYBE_UNUSED Renderer* renderer, MAYBE_UNUSED int32_t handle, MAYBE_UNUSED int32_t count, MAYBE_UNUSED int32_t value1, MAYBE_UNUSED int32_t value2, MAYBE_UNUSED int32_t value3, MAYBE_UNUSED int32_t value4) {} static bool glShaderIsCompiled(MAYBE_UNUSED Renderer* renderer, MAYBE_UNUSED int32_t shader) { return false; } -static bool glShadersSupported(MAYBE_UNUSED Renderer* renderer) { return false; } +static bool glShadersSupported(void) { return false; } static RendererVtable glVtable; diff --git a/src/ps2/gs_renderer.c b/src/ps2/gs_renderer.c index 01c5ff68..565f1f0e 100644 --- a/src/ps2/gs_renderer.c +++ b/src/ps2/gs_renderer.c @@ -1,11 +1,15 @@ #include "gs_renderer.h" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-parameter" +#include +#pragma GCC diagnostic pop + #include #include #include #include #include -#include #include "binary_reader.h" #include "binary_utils.h" @@ -2877,7 +2881,11 @@ static void gsDrawSurface(Renderer* renderer, int32_t surfaceID, int32_t srcLeft // Restore default REPEAT so subsequent atlas draws aren't stuck on this region. gsKit_set_clamp(gs->gsGlobal, GS_CMODE_REPEAT); } -static void gsSurfaceResize(MAYBE_UNUSED Renderer* renderer, int32_t surfaceID, int32_t width, int32_t height) { +static void gsSurfaceResize(Renderer* renderer, int32_t surfaceID, int32_t width, int32_t height) { + (void)renderer; + (void)surfaceID; + (void)width; + (void)height; // No-op: PS2 doesn't actually resize anything } @@ -3052,7 +3060,7 @@ static void gsShaderSetUniformF(MAYBE_UNUSED Renderer* renderer, MAYBE_UNUSED in static void gsShaderSetUniformFArray(MAYBE_UNUSED Renderer* renderer, MAYBE_UNUSED int32_t handle, MAYBE_UNUSED float* values, MAYBE_UNUSED uint32_t count) {} static void gsShaderSetUniformI(MAYBE_UNUSED Renderer* renderer, MAYBE_UNUSED int32_t handle, MAYBE_UNUSED int32_t count, MAYBE_UNUSED int32_t value1, MAYBE_UNUSED int32_t value2, MAYBE_UNUSED int32_t value3, MAYBE_UNUSED int32_t value4) {} static bool gsShaderIsCompiled(MAYBE_UNUSED Renderer* renderer, MAYBE_UNUSED int32_t shader) { return false; } -static bool gsShadersSupported(MAYBE_UNUSED Renderer* renderer) { return false; } +static bool gsShadersSupported(void) { return false; } static RendererVtable gsVtable; diff --git a/src/ps2/main.c b/src/ps2/main.c index b4191d5d..32cc3f28 100644 --- a/src/ps2/main.c +++ b/src/ps2/main.c @@ -238,6 +238,7 @@ static unsigned int hidUsageToAsciiChar(uint8_t hid, bool shift) { int main(int argc, char* argv[]) { + (void)argc; SifInitRpc(0); sbv_patch_enable_lmb(); @@ -552,7 +553,6 @@ int main(int argc, char* argv[]) { // ===[ Main Loop ]=== bool debugOverlayStartEnabled = JsonReader_getBool(JsonReader_getObject(configRoot, "debugOverlayEnabled")); PS2Overlay_setDebugOverlayState(debugOverlayStartEnabled ? STATS_ENABLED : STATS_DISABLED, runner); - uint16_t prevOverlayPadButtons = 0xFFFF; u64 lastFrameStartTime = GetTimerSystemTime(); // for delta_time while (!runner->shouldExit) { diff --git a/src/ps2/ps2_file_system.c b/src/ps2/ps2_file_system.c index f87b45e6..52fd826d 100644 --- a/src/ps2/ps2_file_system.c +++ b/src/ps2/ps2_file_system.c @@ -486,18 +486,26 @@ static void ps2BinaryRewrite(MAYBE_UNUSED FileSystem* fs, void* handle) { //Directory, pretty much stubbed static bool ps2DirectoryExists(FileSystem* fs, const char* relativePath) { + (void)fs; + (void)relativePath; return true; } static bool ps2CreateDirectory(FileSystem* fs, const char* relativePath) { + (void)fs; + (void)relativePath; return true; } static bool ps2DeleteDirectory(FileSystem* fs, const char* relativePath) { + (void)fs; + (void)relativePath; return true; } -static FileSystemDirEntry* ps2ListDirectory(MAYBE_UNUSED FileSystem* fs, MAYBE_UNUSED const char* relativeDirPath) { +static FileSystemDirEntry* ps2ListDirectory(FileSystem* fs, const char* relativeDirPath) { + (void)fs; + (void)relativeDirPath; return nullptr; } diff --git a/src/ps2/ps2_overlay.c b/src/ps2/ps2_overlay.c index bb40bc04..4c04b880 100644 --- a/src/ps2/ps2_overlay.c +++ b/src/ps2/ps2_overlay.c @@ -9,7 +9,6 @@ // ===[ Loading Screen ]=== -static const int PROFILER_WINDOW_FRAMES = 60; static bool gPS2OverlayInitialized = false; static PS2Overlay gOverlay = { 0 }; @@ -113,6 +112,8 @@ void PS2Overlay_setDebugOverlayState(DebugOverlayState state, Runner* runner) { Profiler_setEnabled(&runner->vmContext->profiler, PS2Overlay_getDebugOverlayState() == STATS_ENABLED_WITH_PROFILER); gOverlay.profilerFramesInWindow = 0; gOverlay.profilerOverlayText[0] = '\0'; +#else + (void)runner; #endif } @@ -124,6 +125,8 @@ void PS2Overlay_toggleDebugOverlay(Runner* runner) { Profiler_setEnabled(&runner->vmContext->profiler, PS2Overlay_getDebugOverlayState() == STATS_ENABLED_WITH_PROFILER); gOverlay.profilerFramesInWindow = 0; gOverlay.profilerOverlayText[0] = '\0'; +#else + (void)runner; #endif } diff --git a/src/ps3/main.c b/src/ps3/main.c index 857a64f3..1a93421d 100644 --- a/src/ps3/main.c +++ b/src/ps3/main.c @@ -88,6 +88,8 @@ bool shouldExit = false; // ===[ MAIN ]=== static void sys_callback(uint64_t status, uint64_t param, void* userdata) { + (void)param; + (void)userdata; switch (status) { case SYSUTIL_EXIT_GAME: shouldExit = true; @@ -156,7 +158,8 @@ char *str_replace(char *orig, char *rep, char *with) { static char buffer[9999]; int main(int argc, char* argv[]) { printf("%s\n", argv[0]); - strcpy(buffer, argv[0]); + if (argc > 0) + strcpy(buffer, argv[0]); char* tmp = str_replace(buffer, "butterscotch.elf", ""); char* tmp2 = str_replace(tmp, "butterscotch.self", ""); char* tmp3 = str_replace(tmp2, "EBOOT.BIN", ""); diff --git a/src/renderer.h b/src/renderer.h index 4558d626..a547fd7b 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -146,7 +146,7 @@ typedef struct { bool (*textureGetUVs)(Renderer* renderer, uint32_t texID, float* outUVs); void (*textureSetStage)(Renderer* renderer, int32_t slot, uint32_t texID); bool (*shaderIsCompiled)(Renderer* renderer, int32_t shader); - bool (*shadersSupported)(Renderer* renderer); + bool (*shadersSupported)(void); } RendererVtable; // ===[ Renderer Base Struct ]=== diff --git a/src/runner.h b/src/runner.h index 659fd9c5..373be6ac 100644 --- a/src/runner.h +++ b/src/runner.h @@ -712,6 +712,8 @@ static inline void Runner_setActiveState(Runner* runner, Instance* instance, boo fprintf(stderr, "VM: Instance %s (instanceId=%d,objectIndex=%d) marked as %s at (%f, %f)\n", objDef->name, instance->instanceId, instance->objectIndex, active ? "active" : "inactive", instance->x, instance->y); } } +#else + (void)runner; #endif instance->active = active; diff --git a/src/vm.c b/src/vm.c index 8be3e099..aaa194fc 100644 --- a/src/vm.c +++ b/src/vm.c @@ -104,11 +104,15 @@ static int32_t stackPopInt32(VMContext* ctx) { return value; } +#if IS_WAD17_OR_HIGHER_ENABLED + static RValue* stackPeek(VMContext* ctx) { require(ctx->stack.top > 0); return &ctx->stack.slots[ctx->stack.top - 1]; } +#endif + // ===[ Instruction Decoding ]=== static uint8_t instrOpcode(uint32_t instr) { @@ -267,6 +271,7 @@ static GMLArray* VM_arraySetWithCoW(VMContext* ctx, RValue* slot, int32_t index, #if IS_WAD17_OR_HIGHER_ENABLED intendedOwner = IS_WAD17_OR_HIGHER(ctx) ? ctx->currentArrayOwner : (void*) slot; #else + (void)ctx; intendedOwner = (void*) slot; #endif @@ -418,11 +423,15 @@ static ArrayAccess popArrayAccess(VMContext* ctx, uint32_t varRef) { // ===[ Variable Resolution ]=== // Returns the object name for an instance, or "" for the global scope dummy instance +#ifdef ENABLE_VM_TRACING + static const char* instanceObjectName(VMContext* ctx, Instance* inst) { if (inst->objectIndex == STRUCT_OBJECT_INDEX) return ""; return ctx->dataWin->objt.objects[inst->objectIndex].name; } +#endif + static Variable* resolveVarDef(VMContext* ctx, uint32_t varRef) { uint32_t varIndex = varRef & 0x07FFFFFF; require(ctx->dataWin->vari.variableCount > varIndex); @@ -638,6 +647,8 @@ static bool tryReadInstanceVarOrStatic(VMContext* ctx, Instance* instance, int32 *out = staticVal; return true; } +#else + (void)ctx; #endif return false; } @@ -1360,7 +1371,7 @@ static inline RValue coerceIntStoreToReal(RValue val, uint8_t type2) { return val; } -static void handlePop(VMContext* ctx, uint32_t instr, uint8_t type1, uint8_t type2, uint32_t varRef, uint8_t varType, int32_t instanceType) { +static void handlePop(VMContext* ctx, uint8_t type1, uint8_t type2, uint32_t varRef, uint8_t varType, int32_t instanceType) { RValue val; int32_t arrayIndex = -1; @@ -3016,7 +3027,7 @@ static RValue executeLoop(VMContext* ctx) { val = coerceIntStoreToReal(val, type2); resolveVariableWrite(ctx, instanceType, varRef, val); } else { - handlePop(ctx, instr, type1, type2, varRef, varType, instanceType); + handlePop(ctx, type1, type2, varRef, varType, instanceType); } break; } @@ -3926,7 +3937,7 @@ static void disasmFormatVar(VMContext* ctx, const uint8_t* extraData, const char } // Returns stack effect comment for a variable access instruction -static void disasmFormatVarComment(VMContext* ctx, const uint8_t* extraData, bool isPop, char* buf, size_t bufSize) { +static void disasmFormatVarComment(const uint8_t* extraData, bool isPop, char* buf, size_t bufSize) { uint32_t varRef = resolveVarOperand(extraData); uint8_t varType = (varRef >> 24) & 0xF8; if (isPop) { @@ -4038,7 +4049,7 @@ static void formatInstruction(VMContext* ctx, const uint8_t* bytecodeBase, uint3 case GML_TYPE_VARIABLE: snprintf(opcodeStr, opcodeSize, "Push.v"); disasmFormatVar(ctx, extraData, nullptr, (int32_t) instType, operandStr, operandSize); - disasmFormatVarComment(ctx, extraData, false, commentStr, commentSize); + disasmFormatVarComment(extraData, false, commentStr, commentSize); break; case GML_TYPE_INT16: snprintf(opcodeStr, opcodeSize, "Push.e"); @@ -4057,17 +4068,17 @@ static void formatInstruction(VMContext* ctx, const uint8_t* bytecodeBase, uint3 case OP_PUSHLOC: snprintf(opcodeStr, opcodeSize, "PushLoc.v"); disasmFormatVar(ctx, extraData, "local", (int32_t) instType, operandStr, operandSize); - disasmFormatVarComment(ctx, extraData, false, commentStr, commentSize); + disasmFormatVarComment(extraData, false, commentStr, commentSize); break; case OP_PUSHGLB: snprintf(opcodeStr, opcodeSize, "PushGlb.v"); disasmFormatVar(ctx, extraData, "global", (int32_t) instType, operandStr, operandSize); - disasmFormatVarComment(ctx, extraData, false, commentStr, commentSize); + disasmFormatVarComment(extraData, false, commentStr, commentSize); break; case OP_PUSHBLTN: snprintf(opcodeStr, opcodeSize, "PushBltn.v"); disasmFormatVar(ctx, extraData, nullptr, (int32_t) instType, operandStr, operandSize); - disasmFormatVarComment(ctx, extraData, false, commentStr, commentSize); + disasmFormatVarComment(extraData, false, commentStr, commentSize); break; // PushI (int16 immediate) @@ -4081,7 +4092,7 @@ static void formatInstruction(VMContext* ctx, const uint8_t* bytecodeBase, uint3 case OP_POP: snprintf(opcodeStr, opcodeSize, "Pop.%c.%c", gmlTypeChar(type1), gmlTypeChar(type2)); disasmFormatVar(ctx, extraData, nullptr, (int32_t) instType, operandStr, operandSize); - disasmFormatVarComment(ctx, extraData, true, commentStr, commentSize); + disasmFormatVarComment(extraData, true, commentStr, commentSize); break; // Unconditional branch diff --git a/src/vm_builtins.c b/src/vm_builtins.c index 9c7cc2c1..abb45e29 100644 --- a/src/vm_builtins.c +++ b/src/vm_builtins.c @@ -32,6 +32,8 @@ #include "base64.h" #include "gettime.h" +#pragma GCC diagnostic ignored "-Wunused-parameter" + #define MAX_BACKGROUNDS 8 // See GameMaker-HTML's Function_Layers.js @@ -11182,9 +11184,9 @@ static RValue builtin_action_set_alarm(VMContext* ctx, MAYBE_UNUSED RValue* args if (ctx->currentInstance != nullptr) { Instance* inst = ctx->currentInstance; - Runner* runner = ctx->runner; #ifdef ENABLE_VM_TRACING + Runner* runner = ctx->runner; if (shgeti(ctx->alarmsToBeTraced, "*") != -1 || shgeti(ctx->alarmsToBeTraced, runner->dataWin->objt.objects[inst->objectIndex].name) != -1) { fprintf(stderr, "VM: [%s] Setting Alarm[%d] = %d (instanceId=%d)\n", runner->dataWin->objt.objects[inst->objectIndex].name, alarmIndex, steps, inst->instanceId); } @@ -12268,6 +12270,8 @@ static RuntimeBackgroundElement* findBackgroundElement(Runner* runner, int32_t e return el->backgroundElement; } +#if IS_WAD17_OR_HIGHER_ENABLED + // Resolves a tilemap element id to its tiles data + owning runtime layer. static RoomLayerTilesData* findTilemapData(Runner* runner, int32_t elementId, RuntimeLayer** outLayer) { if (outLayer != nullptr) *outLayer = nullptr; @@ -12279,6 +12283,8 @@ static RoomLayerTilesData* findTilemapData(Runner* runner, int32_t elementId, Ru return el->tilemapData; } +#endif + #define setBackgroundLayerField(id, value, targetParameter) \ RuntimeBackgroundElement* bg = findBackgroundElement(runner, id); \ if (bg != nullptr) bg->targetParameter = value; @@ -13998,7 +14004,7 @@ static RValue builtin_json_encode(VMContext* ctx, RValue* args, int32_t argCount Runner* runner = ctx->runner; int32_t mapIndex = RValue_toInt32(args[0]); // TODO: Implement prettify! - bool prettify = argCount == 2 ? RValue_toBool(args[1]) : false; + //bool prettify = argCount == 2 ? RValue_toBool(args[1]) : false; DsMapEntry** mapPtr = dsMapGet(runner, mapIndex); bool useFloatMarkers = DataWin_isVersionAtLeast(ctx->dataWin, 2023, 2, 0, 0); @@ -14090,17 +14096,6 @@ static RValue builtin_object_get_sprite(VMContext* ctx, RValue* args, int32_t ar return RValue_makeReal(ctx->dataWin->objt.objects[id].spriteId); } -static RValue builtin_object_get_visible(VMContext* ctx, RValue* args, int32_t argCount) { - if (1 > argCount) return RValue_makeBool(false); - - int32_t id = RValue_toInt32(args[0]); - if (0 > id || (uint32_t) id >= ctx->dataWin->objt.count) { - return RValue_makeBool(false); - } - - return RValue_makeBool(ctx->dataWin->objt.objects[id].visible); -} - static RValue builtin_object_get_depth(VMContext* ctx, RValue* args, int32_t argCount) { if (1 > argCount) return RValue_makeReal(0.0); @@ -14605,7 +14600,7 @@ static RValue builtin_shader_get_name(VMContext* ctx, RValue* args, MAYBE_UNUSED } static RValue builtin_shaders_are_supported(VMContext* ctx, MAYBE_UNUSED RValue* args, MAYBE_UNUSED int32_t argCount) { - return RValue_makeBool(ctx->runner->renderer->vtable->shadersSupported(ctx->runner->renderer)); + return RValue_makeBool(ctx->runner->renderer->vtable->shadersSupported()); } static RValue builtin_shader_get_uniform(VMContext* ctx, MAYBE_UNUSED RValue* args, MAYBE_UNUSED int32_t argCount) { @@ -14775,15 +14770,6 @@ static RValue builtin_font_get_uvs(VMContext* ctx, MAYBE_UNUSED RValue* args, MA return RValue_makeArray(out); } -static RValue builtin_font_get_texture(VMContext* ctx, MAYBE_UNUSED RValue* args, MAYBE_UNUSED int32_t argCount) { - //see if it works - int32_t fontIndex = (int32_t) RValue_toReal(args[0]); - Font* font = &ctx->runner->dataWin->font.fonts[fontIndex]; - int32_t TpagIndex = font->tpagIndex; - - return RValue_makeInt32(ctx->runner->renderer->vtable->spriteGetTexture(ctx->runner->renderer, TpagIndex)); -} - static RValue builtin_texture_get_texel_width(VMContext* ctx, MAYBE_UNUSED RValue* args, MAYBE_UNUSED int32_t argCount) { uint32_t texID = (uint32_t) RValue_toReal(args[0]);