Skip to content
Merged
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
8 changes: 5 additions & 3 deletions components/darkforces/src/platform/esp_alloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ namespace
{
if (!s_active) { return nullptr; }
AllocHeader* header = ((AllocHeader*)ptr) - 1;
if ((uint8_t*)header < s_base || header->magic != sessionMagic()) { return nullptr; }
if (reinterpret_cast<uint8_t*>(header) < s_base || header->magic != sessionMagic()) { return nullptr; }
return header;
}

Expand All @@ -115,7 +115,7 @@ namespace
TFE_Memory::PoolLock lock;
// Keep malloc's 8 byte alignment in front of the header.
const size_t total = size + sizeof(AllocHeader) + 8;
void* mem = poolAllocLocked(total);
const void* mem = poolAllocLocked(total);
if (mem)
{
uintptr_t user = ((uintptr_t)mem + sizeof(AllocHeader) + 7) & ~(uintptr_t)7;
Expand Down Expand Up @@ -163,7 +163,7 @@ namespace
size_t oldSize = 0;
{
TFE_Memory::PoolLock lock;
AllocHeader* header = liveHeader(ptr);
const AllocHeader* header = liveHeader(ptr);
if (!header)
{
printf("[DarkForces] ERROR: realloc of a stale block pointer %p\n", ptr);
Expand All @@ -189,6 +189,8 @@ namespace
size_t printed;
};

// censusVisit matches the pool walker's callback signature; mem can't take const.
// cppcheck-suppress constParameterCallback
void censusVisit(void* mem, size_t size, int used, void* user)
{
if (!used) { return; }
Expand Down
9 changes: 7 additions & 2 deletions components/darkforces/src/platform/esp_audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ namespace TFE_Audio
static AudioThreadCallback s_audioThreadCallback = nullptr;
static std::unique_ptr<espp::Task> s_task;

// audioTask matches espp::Task's callback signature; its params can't take const.
// cppcheck-suppress constParameterCallback
static bool audioTask(std::mutex& m, std::condition_variable& cv, bool& task_notified)
{
TFE_Memory::DfAllocScope allocScope;
Expand Down Expand Up @@ -98,7 +100,7 @@ namespace TFE_Audio
if (s_audioThreadCallback)
{
lock();
s_audioThreadCallback((f32*)s_sfxBuffer, AUDIO_CALLBACK_BUFFER_SIZE, 1.0f);
s_audioThreadCallback(reinterpret_cast<f32*>(s_sfxBuffer), AUDIO_CALLBACK_BUFFER_SIZE, 1.0f);
unlock();
haveSfx = true;
}
Expand Down Expand Up @@ -271,7 +273,9 @@ namespace TFE_Audio
if (s_lock) { xSemaphoreGiveRecursive(s_lock); }
}

// Sound sources are not used by Dark Forces (everything goes through iMuse).
// Sound sources are not used by Dark Forces (everything goes through iMuse). These are
// stub implementations of the TFE_Audio API; the engine's declarations are non-const.
// cppcheck-suppress-begin constParameterPointer
bool playOneShot(SoundType type, f32 volume, const SoundBuffer* buffer, bool looping, SoundFinishedCallback finishedCallback, void* cbUserData, s32 cbArg) { return false; }
SoundSource* createSoundSource(SoundType type, f32 volume, const SoundBuffer* buffer, SoundFinishedCallback callback, void* userData) { return nullptr; }
s32 getSourceSlot(SoundSource* source) { return -1; }
Expand All @@ -283,6 +287,7 @@ namespace TFE_Audio
void setSourceBuffer(SoundSource* source, const SoundBuffer* buffer) {}
bool isSourcePlaying(SoundSource* source) { return false; }
f32 getSourceVolume(SoundSource* source) { return 0.0f; }
// cppcheck-suppress-end constParameterPointer
}

void espbox_shared_audio(bool alloc)
Expand Down
26 changes: 15 additions & 11 deletions components/darkforces/src/platform/esp_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@

struct MemoryBlock
{
MemoryBlock* prev;
MemoryBlock* next;
u32 size;
u32 caller; // return address of the region_alloc() caller (memory attribution)
MemoryRegion* owner; // region the block was allocated from (frees may name a different one)
MemoryBlock* prev = nullptr;
MemoryBlock* next = nullptr;
u32 size = 0;
u32 caller = 0; // return address of the region_alloc() caller (memory attribution)
MemoryRegion* owner = nullptr; // region the block was allocated from (frees may name a different one)
};

struct MemoryRegion
{
char name[32];
MemoryBlock* head;
MemoryBlock* tail;
u64 used;
u64 count;
char name[32] = {};
MemoryBlock* head = nullptr;
MemoryBlock* tail = nullptr;
u64 used = 0;
u64 count = 0;
};

namespace TFE_Memory
Expand All @@ -49,7 +49,7 @@ namespace TFE_Memory
static size_t s_poolBytes = 0, s_heapBytes = 0;

// Per-caller attribution of region memory (bytes currently allocated).
struct CallerStat { u32 pc; size_t bytes; size_t count; };
struct CallerStat { u32 pc = 0; size_t bytes = 0; size_t count = 0; };
enum { CALLER_STAT_COUNT = 128 };
static CallerStat* s_callers = nullptr; // CALLER_STAT_COUNT entries (shared memory)
static CallerStat* callerStat(u32 pc)
Expand Down Expand Up @@ -297,6 +297,9 @@ namespace TFE_Memory
return false;
}

// The region_* functions implement the TFE_Memory API; the engine declares the
// MemoryRegion* / FileStream* parameters non-const, so they can't take const here.
// cppcheck-suppress-begin constParameterPointer
size_t region_getMemoryUsed(MemoryRegion* region)
{
return region ? region->used : 0;
Expand Down Expand Up @@ -332,6 +335,7 @@ namespace TFE_Memory
{
return nullptr;
}
// cppcheck-suppress-end constParameterPointer

void region_test()
{
Expand Down
6 changes: 6 additions & 0 deletions components/darkforces/src/platform/esp_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ namespace TFE_RenderBackend
return s_frameCount;
}

// captureScreenToMemory implements the TFE screenshot API (mem is engine-declared non-const).
// cppcheck-suppress constParameterPointer
void captureScreenToMemory(u32* mem) {}
void queueScreenshot(const char* screenshotPath) {}
void startGifRecording(const char* path) {}
Expand Down Expand Up @@ -160,6 +162,8 @@ namespace TFE_RenderBackend
}

void bindVirtualDisplay() {}
// clearVirtualDisplay implements the TFE render-backend API (color is engine-declared non-const).
// cppcheck-suppress constParameterPointer
void clearVirtualDisplay(f32* color, bool clearColor) {}
void copyToVirtualDisplay(RenderTargetHandle src) {}
void copyBackbufferToRenderTarget(RenderTargetHandle dst) {}
Expand Down Expand Up @@ -224,6 +228,8 @@ namespace TFE_RenderBackend
TextureGpu* createTexture(u32 width, u32 height, TexFormat format) { return nullptr; }
TextureGpu* createTextureArray(u32 width, u32 height, u32 layers, u32 channels) { return nullptr; }
TextureGpu* createTexture(u32 width, u32 height, const u32* data, MagFilter magFilter) { return nullptr; }
// freeTexture implements the TFE render-backend API (texture is engine-declared non-const).
// cppcheck-suppress constParameterPointer
void freeTexture(TextureGpu* texture) {}
void getTextureDim(TextureGpu* texture, u32* width, u32* height) { *width = 0; *height = 0; }
void* getGpuPtr(const TextureGpu* texture) { return nullptr; }
Expand Down
9 changes: 9 additions & 0 deletions components/darkforces/src/platform/esp_stubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ namespace TFE_DarkForces
extern JBool s_palModified;
}

// Everything below implements The Force Engine's platform/stub API. The engine's
// (vendored) declarations take non-const pointers, so these definitions can't add
// const to their pointer parameters without diverging from the engine.
// cppcheck-suppress-begin constParameterPointer
/////////////////////////////////////////////
// Front end UI
/////////////////////////////////////////////
Expand Down Expand Up @@ -161,6 +165,9 @@ namespace TFE_Image
void free(Image* image) {}
void freeAll() {}

// These two are dead (save thumbnails are disabled) and deliberately alias the
// caller's const pixel buffer; the TFE Image signatures are non-const.
// cppcheck-suppress-begin dangerousTypeCast
size_t writeImageToMemory(u8*& output, u32 width, u32 height, const u32* pixelData)
{
output = (u8*)pixelData;
Expand All @@ -173,6 +180,7 @@ namespace TFE_Image
output->height = TFE_SaveSystem::SAVE_IMAGE_HEIGHT;
output->data = (u32*)pixelData;
}
// cppcheck-suppress-end dangerousTypeCast

void writeImage(const char* path, u32 width, u32 height, u32* pixelData)
{
Expand Down Expand Up @@ -343,3 +351,4 @@ namespace TFE_A11Y
bool cutsceneCaptionsEnabled() { return false; }
bool gameplayCaptionsEnabled() { return false; }
}
// cppcheck-suppress-end constParameterPointer
11 changes: 6 additions & 5 deletions components/darkforces/src/platform/esp_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class ThreadEsp : public Thread
virtual void resume();
virtual void waitOnExit(void);

ThreadFunc getFunc() { return m_func; }
void* getUserData() { return m_userData; }
ThreadFunc getFunc() const { return m_func; }
void* getUserData() const { return m_userData; }

protected:
static void threadEntry(void* arg);
Expand All @@ -28,16 +28,17 @@ class ThreadEsp : public Thread
SemaphoreHandle_t m_done = nullptr;
};

ThreadEsp::ThreadEsp(const char* name, ThreadFunc func, void* userData) : Thread(name, func, userData)
ThreadEsp::ThreadEsp(const char* name, ThreadFunc func, void* userData)
: Thread(name, func, userData), m_done(xSemaphoreCreateBinary())
{
m_done = xSemaphoreCreateBinary();
}

ThreadEsp::~ThreadEsp()
{
if (m_isRunning)
{
waitOnExit();
// qualified call: a destructor must not dispatch virtually
ThreadEsp::waitOnExit();
}
if (m_done)
{
Expand Down
10 changes: 10 additions & 0 deletions suppressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,13 @@ duplicateExpressionTernary:components/genesis/src/genesis.cpp
// exclude in static_analysis.yml only covers the base-tree pass; the PR
// tree is checked under pr_tree/, so suppress by relative path here.)
*:components/darkforces/tfe/*
// The Dark Forces ESP32 port layer (components/darkforces/src/platform) bridges
// to the vendored TFE engine. The findings that can't be acted on -- pointer
// parameters that implement TFE's engine/callback signatures -- are suppressed
// inline at each constrained definition (see the cppcheck-suppress comments in
// the .cpp files); the actionable findings are fixed in code. Nothing for the
// port layer is suppressed file-wide here.
// cppcheck parses this C++ header (it declares a namespace) as C when it
// checks it standalone and reports a bogus syntaxError; the file is valid C++
// and compiles fine. Suppress that false positive.
syntaxError:components/darkforces/src/platform/esp_platform.h
Loading