NDS: Fix data corruption in some textures and map gen

This commit is contained in:
UnknownShadow200 2025-03-02 11:45:48 +11:00
parent ea38185ea9
commit eb84b2e607
7 changed files with 36 additions and 22 deletions

View File

@ -358,7 +358,12 @@ cc_result Png_Decode(struct Bitmap* bmp, struct Stream* stream) {
int curY;
/* idat decompressor */
struct InflateState inflate;
#ifdef CC_BUILD_TINYSTACK
struct InflateState* inflate = (struct InflateState*)temp_mem;
#else
struct InflateState _inflate;
struct InflateState* inflate = &_inflate;
#endif
struct Stream compStream, datStream;
struct ZLibHeader zlibHeader;
cc_uint8* data = NULL;
@ -374,7 +379,7 @@ cc_result Png_Decode(struct Bitmap* bmp, struct Stream* stream) {
trnsColor = BITMAPCOLOR_BLACK;
for (i = 0; i < PNG_PALETTE; i++) { palette[i] = BITMAPCOLOR_BLACK; }
Inflate_MakeStream2(&compStream, &inflate, stream);
Inflate_MakeStream2(&compStream, inflate, stream);
ZLibHeader_Init(&zlibHeader);
for (;;) {
@ -469,7 +474,7 @@ cc_result Png_Decode(struct Bitmap* bmp, struct Stream* stream) {
/* 11.2.4 IDAT Image data */
case PNG_FourCC('I','D','A','T'): {
Stream_ReadonlyPortion(&datStream, stream, dataSize);
inflate.Source = &datStream;
inflate->Source = &datStream;
/* TODO: This assumes zlib header will be in 1 IDAT chunk */
while (!zlibHeader.done) {

View File

@ -632,7 +632,7 @@ struct Texture {
#endif
#ifdef CC_BUILD_TINYSTACK
extern char temp_mem[40000];
extern char temp_mem[45000];
#endif
#endif

View File

@ -310,23 +310,36 @@ static void NotchyGen_CreateHeightmap(void) {
float hLow, hHigh, height;
int hIndex = 0, adjHeight;
int x, z;
struct CombinedNoise n1, n2;
struct OctaveNoise n3;
CombinedNoise_Init(&n1, &rnd, 8, 8);
CombinedNoise_Init(&n2, &rnd, 8, 8);
OctaveNoise_Init(&n3, &rnd, 6);
#ifdef CC_BUILD_TINYSTACK
struct NoiseBuffer {
struct CombinedNoise n1, n2;
struct OctaveNoise n3;
};
struct NoiseBuffer* buf = (struct NoiseBuffer*)temp_mem;
struct CombinedNoise* n1 = &buf->n1;
struct CombinedNoise* n2 = &buf->n2;
struct OctaveNoise* n3 = &buf->n3;
#else
struct CombinedNoise _n1, *n1 = &_n1;
struct CombinedNoise _n2, *n2 = &_n2;
struct OctaveNoise _n3, *n3 = &_n3;
#endif
CombinedNoise_Init(n1, &rnd, 8, 8);
CombinedNoise_Init(n2, &rnd, 8, 8);
OctaveNoise_Init(n3, &rnd, 6);
Gen_CurrentState = "Building heightmap";
for (z = 0; z < World.Length; z++) {
Gen_CurrentProgress = (float)z / World.Length;
for (x = 0; x < World.Width; x++) {
hLow = CombinedNoise_Calc(&n1, x * 1.3f, z * 1.3f) / 6 - 4;
hLow = CombinedNoise_Calc(n1, x * 1.3f, z * 1.3f) / 6 - 4;
height = hLow;
if (OctaveNoise_Calc(&n3, (float)x, (float)z) <= 0) {
hHigh = CombinedNoise_Calc(&n2, x * 1.3f, z * 1.3f) / 5 + 6;
if (OctaveNoise_Calc(n3, (float)x, (float)z) <= 0) {
hHigh = CombinedNoise_Calc(n2, x * 1.3f, z * 1.3f) / 5 + 6;
height = max(hLow, hHigh);
}

View File

@ -530,7 +530,7 @@ void Gfx_CalcOrthoMatrix(struct Matrix* matrix, float width, float height, float
/* The simplified calculation below uses: L = 0, R = width, T = 0, B = height */
*matrix = Matrix_Identity;
width /= 64.0f;
height /= 64.0f;
height /= 64.0f;
matrix->row1.x = 2.0f / width;
matrix->row2.y = -2.0f / height;

View File

@ -640,7 +640,11 @@ static void HttpClient_Serialise(struct HttpClientState* state) {
}
static cc_result HttpClient_SendRequest(struct HttpClientState* state) {
#ifdef CC_BUILD_TINYSTACK
char inputBuffer[8192];
#else
char inputBuffer[16384];
#endif
cc_string inputMsg;
String_InitArray(inputMsg, inputBuffer);

View File

@ -584,14 +584,6 @@ void Platform_Init(void) {
Platform_Log1("Running in %c mode with NDS wifi", dsiMode ? "DSi" : "DS");
#endif
// By default, the "heap limit" is calculated in `sbrk` based on current
// stack pointer value - however this does not reliably in ClassiCube's
// case as e.g. map gen and bitmap decoding use much more stack space
// So to avoid having the stack overlapping the heap when more stack space
// is used, manually reduce the heap limit by 32 kb
extern char* fake_heap_end;
if (fake_heap_end) fake_heap_end -= 32768;
InitFilesystem();
InitNetworking();
cpuStartTiming(1);

View File

@ -5,7 +5,7 @@
#include "Errors.h"
#ifdef CC_BUILD_TINYSTACK
CC_BIG_VAR char temp_mem[40000];
CC_BIG_VAR char temp_mem[45000];
#endif
/*########################################################################################################################*