Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ jobs:
flags: '-std=gnu99 -w'
- name: GCC 2.95
compiler: g++-2.95
flags: '-fpermissive -w'
flags: '-w'
name: Build (${{ matrix.name }})
runs-on: ubuntu-latest
steps:
Expand All @@ -408,3 +408,16 @@ jobs:
run: |
sudo mv butterscotch ~/woody
sudo chroot ~/woody /bin/sh --login -c 'make -C /butterscotch NO_COLOR=1 VERBOSE=1 CC="${{ matrix.compiler }} ${{ matrix.flags }}" DESKTOP_BACKEND=sdl1 AUDIO_BACKEND=none SDL1_LIBS='-lSDL' DISABLE_MMD=1'

build-cxx:
name: Build as C++
runs-on: ubuntu-24.04
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y libglfw3-dev

- name: Build
run: make CC='g++ -std=gnu++98 -Wall -Wvla -Werror' NO_COLOR=1 VERBOSE=1
6 changes: 3 additions & 3 deletions src/audio/miniaudio/ma_audio_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -693,11 +693,11 @@ static void maGroupLoad(AudioSystem* audio, int32_t groupIndex) {
char* buf;
if (audioGroupEntry->path == nullptr) {
int sz = snprintf(nullptr, 0, "audiogroup%d.dat", groupIndex);
buf = safeMalloc(sz + 1);
buf = (char *)safeMalloc(sz + 1);
snprintf(buf, sz + 1, "audiogroup%d.dat", groupIndex);
} else {
size_t length = strlen(audioGroupEntry->path);
buf = safeMalloc(length + 1);
buf = (char *)safeMalloc(length + 1);
memcpy(buf, audioGroupEntry->path, length);
buf[length] = '\0';
}
Expand Down Expand Up @@ -798,7 +798,7 @@ static AudioSystemVtable maAudioSystemVtable;
// ===[ Lifecycle ]===

MaAudioSystem* MaAudioSystem_create(DataWin* dataWin) {
MaAudioSystem* ma = safeCalloc(1, sizeof(MaAudioSystem));
MaAudioSystem* ma = (MaAudioSystem *)safeCalloc(1, sizeof(MaAudioSystem));
ma->base.dw = dataWin;
maAudioSystemVtable.init = maInit;
maAudioSystemVtable.destroy = maDestroy;
Expand Down
2 changes: 1 addition & 1 deletion src/binary_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void BinaryReader_readBytes(BinaryReader* reader, void* dest, size_t count) {
}

uint8_t* BinaryReader_readBytesAt(BinaryReader* reader, size_t offset, size_t count) {
uint8_t* buf = safeMalloc(count);
uint8_t* buf = (uint8_t *)safeMalloc(count);

if (reader->buffer != nullptr) {
if (offset < reader->bufferBase || offset + count > reader->bufferBase + reader->bufferSize) {
Expand Down
28 changes: 16 additions & 12 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,14 @@
#define IS_BIG_ENDIAN
#endif

#if defined(__has_c_attribute)
#if __has_c_attribute(maybe_unused)
#define MAYBE_UNUSED [[maybe_unused]]
#endif
#endif

#ifndef MAYBE_UNUSED
#if defined(__GNUC__) || defined(__clang__)
#define MAYBE_UNUSED __attribute__((unused))
#else
#define MAYBE_UNUSED
#endif
#if defined(__cplusplus) && __cplusplus >= 201703L
#define MAYBE_UNUSED [[maybe_unused]]
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
#define MAYBE_UNUSED [[maybe_unused]]
#elif defined(__GNUC__) || defined(__clang__)
#define MAYBE_UNUSED __attribute__((unused))
#else
#define MAYBE_UNUSED
#endif

#if (defined(__GNUC__) && (__GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))) || defined(__TINYC__)
Expand All @@ -42,6 +38,14 @@
#define ALIGN(x)
#endif

#if defined(__GNUC__) || defined(__TINYC__)
#define NOINLINE __attribute__((noinline))
#elif defined(_MSC_VER) && _MSC_VER >= 1400 // VS2005 or later
#define NOINLINE __declspec(noinline)
#else
#define NOINLINE
#endif

#if defined(__GNUC__) || defined(__clang__)
#if defined(__x86_64__) || defined(__i386__)
#define YIELD() __asm__ volatile("rep; nop" : : : "memory")
Expand Down
142 changes: 71 additions & 71 deletions src/data_win.c

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/desktop/backends/glfw3.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ void platformSwapBuffers(void) {
}

void *platformGetProcAddress(const char *name) {
return glfwGetProcAddress(name);
return (void *)glfwGetProcAddress(name);
}

enum {
Expand Down
3 changes: 1 addition & 2 deletions src/desktop/backends/sdl1.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include <ctype.h>
#include <string.h>
#include <stdio.h>

#include <SDL/SDL_events.h>
#include <SDL/SDL.h>
#include <SDL/SDL_video.h>

#include "common.h"
#include "input_recording.h"
Expand Down
3 changes: 1 addition & 2 deletions src/desktop/backends/sdl2.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include <ctype.h>
#include <stdio.h>

#include <SDL2/SDL_events.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_video.h>

#include "common.h"
#include "input_recording.h"
Expand Down
5 changes: 1 addition & 4 deletions src/desktop/backends/sdl3.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#include <SDL3/SDL_timer.h>
#include <ctype.h>
#include <stdio.h>

#include <SDL3/SDL_events.h>
#include <SDL3/SDL.h>
#include <SDL3/SDL_video.h>
#include <SDL3/SDL_mouse.h>

#include "common.h"
#include "input_recording.h"
Expand Down
18 changes: 9 additions & 9 deletions src/desktop/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ static void writeFramebufferAsPng(GLuint fbo, int width, int height, const char*
glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);

int stride = width * 4;
unsigned char* pixels = safeMalloc(stride * height);
unsigned char* pixels = (unsigned char *)safeMalloc(stride * height);
if (pixels == nullptr) {
fprintf(stderr, "Error: Failed to allocate memory for %s (%dx%d)\n", logPrefix, width, height);
return;
Expand Down Expand Up @@ -890,7 +890,7 @@ char* collapseNewlines(const char *input) {
}

size_t len = strlen(input);
char *result = malloc(len + 1);
char *result = (char *)malloc(len + 1);
if (result == nullptr) {
return nullptr;
}
Expand Down Expand Up @@ -990,8 +990,8 @@ int main(int argc, char* argv[]) {
#ifdef ENABLE_VM_OPCODE_PROFILER
vm->opcodeProfilerEnabled = args.opcodeProfiler;
if (vm->opcodeProfilerEnabled) {
vm->opcodeVariantCounts = safeCalloc(256 * 256, sizeof(uint64_t));
vm->opcodeRValueTypeCounts = safeCalloc(256 * 256, sizeof(uint64_t));
vm->opcodeVariantCounts = (uint64_t *)safeCalloc(256 * 256, sizeof(uint64_t));
vm->opcodeRValueTypeCounts = (uint64_t *)safeCalloc(256 * 256, sizeof(uint64_t));
}
#endif

Expand Down Expand Up @@ -1186,7 +1186,7 @@ int main(int argc, char* argv[]) {
lastSlash = lastBackslash;
if (lastSlash != nullptr) {
size_t len = (size_t) (lastSlash - args.dataWinPath + 1);
dataWinDir = safeMalloc(len + 1);
dataWinDir = (char *)safeMalloc(len + 1);
memcpy(dataWinDir, args.dataWinPath, len);
dataWinDir[len] = '\0';
} else {
Expand Down Expand Up @@ -1535,9 +1535,9 @@ int main(int argc, char* argv[]) {
printf("Changed global.interact [%d] value!\n", interactVarId);
}

bool* currentKeyDown = safeCalloc(GML_KEY_COUNT, sizeof(bool));
bool* currentKeyPressed = safeCalloc(GML_KEY_COUNT, sizeof(bool));
bool* currentKeyReleased = safeCalloc(GML_KEY_COUNT, sizeof(bool));
bool* currentKeyDown = (bool *)safeCalloc(GML_KEY_COUNT, sizeof(bool));
bool* currentKeyPressed = (bool *)safeCalloc(GML_KEY_COUNT, sizeof(bool));
bool* currentKeyReleased = (bool *)safeCalloc(GML_KEY_COUNT, sizeof(bool));

if (freeCamActive) {
// THIS IS A HACK!! We don't want to pass keys to the runner, but we DO want to keep it so we can hold the arrow keys to move the camera
Expand Down Expand Up @@ -1824,7 +1824,7 @@ int main(int argc, char* argv[]) {
// The pendingWorkingDirectory contains a slash at the beginning of it (example: /chapter3)
// The parentDir does NOT have a trailing slash, so we don't need to bother with it
size_t newPathLen = strlen(parentDir) + strlen(nextWorkingDirectory) + 1 + strlen(dataWinFilename) + 1;
char* newPath = safeMalloc(newPathLen);
char* newPath = (char *)safeMalloc(newPathLen);
snprintf(newPath, newPathLen, "%s%s/%s", parentDir, nextWorkingDirectory, dataWinFilename);

free(parentDir);
Expand Down
16 changes: 8 additions & 8 deletions src/event_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void EventSlotMap_build(EventSlotMap* outMap, DataWin* dw) {
int32_t maxSub = outMap->maxSubtypeByType[t];
if (0 > maxSub) continue;
size_t entryCount = (size_t)(maxSub + 1);
outMap->denseLookup[t] = safeMalloc(entryCount * sizeof(int16_t));
outMap->denseLookup[t] = (int16_t *)safeMalloc(entryCount * sizeof(int16_t));
repeat(entryCount, i) outMap->denseLookup[t][i] = -1;
}

Expand Down Expand Up @@ -128,10 +128,10 @@ void ResolvedEventTable_build(ResolvedEventTable* outTable, DataWin* dw, const E
outTable->totalEntries = 0;

// Pass 1: count resolved entries per object so we can allocate flat arrays.
int32_t* scratchCodeId = safeMalloc((size_t) slotCount * sizeof(int32_t));
int16_t* scratchOwner = safeMalloc((size_t) slotCount * sizeof(int16_t));
int32_t* scratchCodeId = (int32_t *)safeMalloc((size_t) slotCount * sizeof(int32_t));
int16_t* scratchOwner = (int16_t *)safeMalloc((size_t) slotCount * sizeof(int16_t));

outTable->byObjectStart = safeMalloc((size_t)(objectCount + 1) * sizeof(uint32_t));
outTable->byObjectStart = (uint32_t *)safeMalloc((size_t)(objectCount + 1) * sizeof(uint32_t));
outTable->byObjectStart[0] = 0;

uint32_t totalEntries = 0;
Expand All @@ -145,7 +145,7 @@ void ResolvedEventTable_build(ResolvedEventTable* outTable, DataWin* dw, const E
outTable->totalEntries = totalEntries;

// Pass 2: fill byObject. Walking slots in ascending order means each object's range is already sorted by slot (no extra qsort needed).
outTable->byObject = safeMalloc((size_t) totalEntries * sizeof(ObjectEventEntry));
outTable->byObject = (ObjectEventEntry *)safeMalloc((size_t) totalEntries * sizeof(ObjectEventEntry));

uint32_t cursor = 0;
repeat(objectCount, oi) {
Expand All @@ -163,7 +163,7 @@ void ResolvedEventTable_build(ResolvedEventTable* outTable, DataWin* dw, const E
free(scratchOwner);

// Pass 3: histogram + prefix sum + scatter to build bySlot. Walking byObject in object-major order means each slot's range ends up sorted by concreteObjectId for free.
outTable->bySlotStart = safeMalloc((size_t)(slotCount + 1) * sizeof(uint32_t));
outTable->bySlotStart = (uint32_t *)safeMalloc((size_t)(slotCount + 1) * sizeof(uint32_t));
repeat(slotCount + 1, i) outTable->bySlotStart[i] = 0;
repeat(totalEntries, i) {
outTable->bySlotStart[outTable->byObject[i].slot + 1]++;
Expand All @@ -172,8 +172,8 @@ void ResolvedEventTable_build(ResolvedEventTable* outTable, DataWin* dw, const E
outTable->bySlotStart[s + 1] += outTable->bySlotStart[s];
}

outTable->bySlot = safeMalloc((size_t) totalEntries * sizeof(SlotResponderEntry));
uint32_t* slotCursor = safeMalloc((size_t) slotCount * sizeof(uint32_t));
outTable->bySlot = (SlotResponderEntry *)safeMalloc((size_t) totalEntries * sizeof(SlotResponderEntry));
uint32_t* slotCursor = (uint32_t *)safeMalloc((size_t) slotCount * sizeof(uint32_t));
memset(slotCursor, 0, (size_t) slotCount * sizeof(uint32_t));

repeat(objectCount, oi) {
Expand Down
36 changes: 18 additions & 18 deletions src/gl/gl_renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ static bool compileProgram(GMLShader* gmlShader, const char* name, const char* v
glGetProgramiv(shaderId, GL_ACTIVE_UNIFORMS, &uniformCount);

gmlShader->uniformCount = uniformCount;
gmlShader->uniforms = safeCalloc(uniformCount, sizeof(GLShaderUniform));
gmlShader->uniforms = (GLShaderUniform *)safeCalloc(uniformCount, sizeof(GLShaderUniform));

// We can only get the length of a specific uniform in OpenGL 4.3+...
GLint maxUniformNameLength = 0;
Expand All @@ -225,7 +225,7 @@ static bool compileProgram(GMLShader* gmlShader, const char* name, const char* v
GLint size = 0;
GLenum type = 0;

char* uniformName = safeMalloc(maxUniformNameLength + 1);
char* uniformName = (char *)safeMalloc(maxUniformNameLength + 1);

glGetActiveUniform(shaderId, b, maxUniformNameLength, &length, &size, &type, uniformName);

Expand All @@ -250,7 +250,7 @@ static void glInit(Renderer* renderer, DataWin* dataWin) {
GLRenderer* gl = (GLRenderer*) renderer;
renderer->dataWin = dataWin;

GMLShader* defaultShader = safeCalloc(1, sizeof(GMLShader));
GMLShader* defaultShader = (GMLShader *)safeCalloc(1, sizeof(GMLShader));
bool success = compileProgram(defaultShader, "default", defaultVertexShaderSource, defaultFragmentShaderSource, 0, nullptr);
if (!success) {
fprintf(stderr, "GL: Failed to compile default shaders! Bailing...");
Expand All @@ -259,7 +259,7 @@ static void glInit(Renderer* renderer, DataWin* dataWin) {

gl->defaultShaderProgram = defaultShader;

gl->gmlShaders = safeCalloc(dataWin->shdr.count, sizeof(GMLShader));
gl->gmlShaders = (GMLShader *)safeCalloc(dataWin->shdr.count, sizeof(GMLShader));
fprintf(stderr, "GL: %u Shaders Found\n", dataWin->shdr.count);

repeat(dataWin->shdr.count, i) {
Expand Down Expand Up @@ -319,7 +319,7 @@ static void glInit(Renderer* renderer, DataWin* dataWin) {

// EBO: pre-fill with quad index pattern (0,1,2,2,3,0 repeated)
int32_t eboSize = MAX_QUADS * INDICES_PER_QUAD * (int32_t) sizeof(uint32_t);
uint32_t* indices = safeMalloc(eboSize);
uint32_t* indices = (uint32_t *)safeMalloc(eboSize);
for (int32_t i = 0; MAX_QUADS > i; i++) {
uint32_t base = (uint32_t) i * 4;
indices[i * 6 + 0] = base + 0;
Expand All @@ -345,14 +345,14 @@ static void glInit(Renderer* renderer, DataWin* dataWin) {
glBindVertexArray(0);

// Allocate CPU-side vertex buffer
gl->vertexData = safeMalloc(MAX_QUADS * VERTICES_PER_QUAD * FLOATS_PER_VERTEX * sizeof(float));
gl->vertexData = (float *)safeMalloc(MAX_QUADS * VERTICES_PER_QUAD * FLOATS_PER_VERTEX * sizeof(float));

// Prepare texture slots for lazy loading (PNG decode deferred to first use)
gl->textureCount = dataWin->txtr.count;
gl->glTextures = safeMalloc(gl->textureCount * sizeof(GLuint));
gl->textureWidths = safeMalloc(gl->textureCount * sizeof(int32_t));
gl->textureHeights = safeMalloc(gl->textureCount * sizeof(int32_t));
gl->textureLoaded = safeMalloc(gl->textureCount * sizeof(bool));
gl->glTextures = (GLuint *)safeMalloc(gl->textureCount * sizeof(GLuint));
gl->textureWidths = (int32_t *)safeMalloc(gl->textureCount * sizeof(int32_t));
gl->textureHeights = (int32_t *)safeMalloc(gl->textureCount * sizeof(int32_t));
gl->textureLoaded = (bool *)safeMalloc(gl->textureCount * sizeof(bool));

glGenTextures((GLsizei) gl->textureCount, gl->glTextures);

Expand Down Expand Up @@ -1834,10 +1834,10 @@ static uint32_t findOrAllocTexturePageSlot(GLRenderer* gl) {
// No free slot found, grow the arrays
uint32_t newPageId = gl->textureCount;
gl->textureCount++;
gl->glTextures = safeRealloc(gl->glTextures, gl->textureCount * sizeof(GLuint));
gl->textureWidths = safeRealloc(gl->textureWidths, gl->textureCount * sizeof(int32_t));
gl->textureHeights = safeRealloc(gl->textureHeights, gl->textureCount * sizeof(int32_t));
gl->textureLoaded = safeRealloc(gl->textureLoaded, gl->textureCount * sizeof(bool));
gl->glTextures = (GLuint *)safeRealloc(gl->glTextures, gl->textureCount * sizeof(GLuint));
gl->textureWidths = (int32_t *)safeRealloc(gl->textureWidths, gl->textureCount * sizeof(int32_t));
gl->textureHeights = (int32_t *)safeRealloc(gl->textureHeights, gl->textureCount * sizeof(int32_t));
gl->textureLoaded = (bool *)safeRealloc(gl->textureLoaded, gl->textureCount * sizeof(bool));
gl->glTextures[newPageId] = 0;
gl->textureWidths[newPageId] = 0;
gl->textureHeights[newPageId] = 0;
Expand All @@ -1852,7 +1852,7 @@ static uint32_t findOrAllocTpagSlot(DataWin* dw, uint32_t originalTpagCount) {
}
uint32_t newIndex = dw->tpag.count;
dw->tpag.count++;
dw->tpag.items = safeRealloc(dw->tpag.items, dw->tpag.count * sizeof(TexturePageItem));
dw->tpag.items = (TexturePageItem *)safeRealloc(dw->tpag.items, dw->tpag.count * sizeof(TexturePageItem));
memset(&dw->tpag.items[newIndex], 0, sizeof(TexturePageItem));
dw->tpag.items[newIndex].texturePageId = -1;
return newIndex;
Expand Down Expand Up @@ -2111,7 +2111,7 @@ static int32_t glCreateSpriteFromSurface(Renderer* renderer, int32_t surfaceID,

glBindFramebuffer(GL_READ_FRAMEBUFFER, gl->surfaces[surfaceID]);

uint8_t* pixels = safeMalloc((size_t) w * (size_t) h * 4);
uint8_t* pixels = (uint8_t *)safeMalloc((size_t) w * (size_t) h * 4);
if (pixels == nullptr) return -1;

glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
Expand Down Expand Up @@ -2157,7 +2157,7 @@ static int32_t glCreateSpriteFromSurface(Renderer* renderer, int32_t surfaceID,
sprite->originX = xorig;
sprite->originY = yorig;
sprite->textureCount = 1;
sprite->tpagIndices = safeMalloc(sizeof(int32_t));
sprite->tpagIndices = (int32_t *)safeMalloc(sizeof(int32_t));
sprite->tpagIndices[0] = (int32_t) tpagIndex;
sprite->maskCount = 0;
sprite->masks = nullptr;
Expand Down Expand Up @@ -2487,7 +2487,7 @@ static RendererVtable glVtable;
// ===[ Public API ]===

Renderer* GLRenderer_create(void) {
GLRenderer* gl = safeCalloc(1, sizeof(GLRenderer));
GLRenderer* gl = (GLRenderer *)safeCalloc(1, sizeof(GLRenderer));
gl->base.vtable = &glVtable;
glVtable.init = glInit;
glVtable.destroy = glDestroy;
Expand Down
10 changes: 5 additions & 5 deletions src/gl_common/gl_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ uint32_t GLCommon_findOrAllocateSurfaceSlot(GLuint** surfaces, GLuint** surfaceT

uint32_t newIndex = *count;
(*count)++;
*surfaces = safeRealloc(*surfaces, *count * sizeof(GLuint));
*surfaceTexture = safeRealloc(*surfaceTexture, *count * sizeof(GLuint));
*surfaceWidth = safeRealloc(*surfaceWidth, *count * sizeof(int32_t));
*surfaceHeight = safeRealloc(*surfaceHeight, *count * sizeof(int32_t));
*surfaces = (GLuint *)safeRealloc(*surfaces, *count * sizeof(GLuint));
*surfaceTexture = (GLuint *)safeRealloc(*surfaceTexture, *count * sizeof(GLuint));
*surfaceWidth = (int32_t *)safeRealloc(*surfaceWidth, *count * sizeof(int32_t));
*surfaceHeight = (int32_t *)safeRealloc(*surfaceHeight, *count * sizeof(int32_t));
(*surfaces)[newIndex] = 0;
(*surfaceTexture)[newIndex] = 0;
(*surfaceWidth)[newIndex] = 0;
Expand Down Expand Up @@ -125,7 +125,7 @@ bool GLCommon_surfaceGetPixels(GLuint* surfaces, int32_t* surfaceWidth, int32_t*
glBindFramebuffer(GL_FRAMEBUFFER, surfaces[surfaceId]);
glPixelStorei(GL_PACK_ALIGNMENT, 1);

uint8_t* tmp = safeMalloc((size_t) w * (size_t) h * 4);
uint8_t* tmp = (uint8_t *)safeMalloc((size_t) w * (size_t) h * 4);
glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, tmp);

// OpenGL reads bottom-up; native expects y=0 at the top
Expand Down
Loading
Loading