mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-12 00:56:40 -04:00
NDS: Fix data corruption in some textures and map gen
This commit is contained in:
parent
ea38185ea9
commit
eb84b2e607
11
src/Bitmap.c
11
src/Bitmap.c
@ -358,7 +358,12 @@ cc_result Png_Decode(struct Bitmap* bmp, struct Stream* stream) {
|
|||||||
int curY;
|
int curY;
|
||||||
|
|
||||||
/* idat decompressor */
|
/* 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 Stream compStream, datStream;
|
||||||
struct ZLibHeader zlibHeader;
|
struct ZLibHeader zlibHeader;
|
||||||
cc_uint8* data = NULL;
|
cc_uint8* data = NULL;
|
||||||
@ -374,7 +379,7 @@ cc_result Png_Decode(struct Bitmap* bmp, struct Stream* stream) {
|
|||||||
trnsColor = BITMAPCOLOR_BLACK;
|
trnsColor = BITMAPCOLOR_BLACK;
|
||||||
for (i = 0; i < PNG_PALETTE; i++) { palette[i] = 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);
|
ZLibHeader_Init(&zlibHeader);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@ -469,7 +474,7 @@ cc_result Png_Decode(struct Bitmap* bmp, struct Stream* stream) {
|
|||||||
/* 11.2.4 IDAT Image data */
|
/* 11.2.4 IDAT Image data */
|
||||||
case PNG_FourCC('I','D','A','T'): {
|
case PNG_FourCC('I','D','A','T'): {
|
||||||
Stream_ReadonlyPortion(&datStream, stream, dataSize);
|
Stream_ReadonlyPortion(&datStream, stream, dataSize);
|
||||||
inflate.Source = &datStream;
|
inflate->Source = &datStream;
|
||||||
|
|
||||||
/* TODO: This assumes zlib header will be in 1 IDAT chunk */
|
/* TODO: This assumes zlib header will be in 1 IDAT chunk */
|
||||||
while (!zlibHeader.done) {
|
while (!zlibHeader.done) {
|
||||||
|
@ -632,7 +632,7 @@ struct Texture {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CC_BUILD_TINYSTACK
|
#ifdef CC_BUILD_TINYSTACK
|
||||||
extern char temp_mem[40000];
|
extern char temp_mem[45000];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -310,23 +310,36 @@ static void NotchyGen_CreateHeightmap(void) {
|
|||||||
float hLow, hHigh, height;
|
float hLow, hHigh, height;
|
||||||
int hIndex = 0, adjHeight;
|
int hIndex = 0, adjHeight;
|
||||||
int x, z;
|
int x, z;
|
||||||
struct CombinedNoise n1, n2;
|
|
||||||
struct OctaveNoise n3;
|
|
||||||
|
|
||||||
CombinedNoise_Init(&n1, &rnd, 8, 8);
|
#ifdef CC_BUILD_TINYSTACK
|
||||||
CombinedNoise_Init(&n2, &rnd, 8, 8);
|
struct NoiseBuffer {
|
||||||
OctaveNoise_Init(&n3, &rnd, 6);
|
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";
|
Gen_CurrentState = "Building heightmap";
|
||||||
for (z = 0; z < World.Length; z++) {
|
for (z = 0; z < World.Length; z++) {
|
||||||
Gen_CurrentProgress = (float)z / World.Length;
|
Gen_CurrentProgress = (float)z / World.Length;
|
||||||
|
|
||||||
for (x = 0; x < World.Width; x++) {
|
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;
|
height = hLow;
|
||||||
|
|
||||||
if (OctaveNoise_Calc(&n3, (float)x, (float)z) <= 0) {
|
if (OctaveNoise_Calc(n3, (float)x, (float)z) <= 0) {
|
||||||
hHigh = CombinedNoise_Calc(&n2, x * 1.3f, z * 1.3f) / 5 + 6;
|
hHigh = CombinedNoise_Calc(n2, x * 1.3f, z * 1.3f) / 5 + 6;
|
||||||
height = max(hLow, hHigh);
|
height = max(hLow, hHigh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 */
|
/* The simplified calculation below uses: L = 0, R = width, T = 0, B = height */
|
||||||
*matrix = Matrix_Identity;
|
*matrix = Matrix_Identity;
|
||||||
width /= 64.0f;
|
width /= 64.0f;
|
||||||
height /= 64.0f;
|
height /= 64.0f;
|
||||||
|
|
||||||
matrix->row1.x = 2.0f / width;
|
matrix->row1.x = 2.0f / width;
|
||||||
matrix->row2.y = -2.0f / height;
|
matrix->row2.y = -2.0f / height;
|
||||||
|
@ -640,7 +640,11 @@ static void HttpClient_Serialise(struct HttpClientState* state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static cc_result HttpClient_SendRequest(struct HttpClientState* state) {
|
static cc_result HttpClient_SendRequest(struct HttpClientState* state) {
|
||||||
|
#ifdef CC_BUILD_TINYSTACK
|
||||||
|
char inputBuffer[8192];
|
||||||
|
#else
|
||||||
char inputBuffer[16384];
|
char inputBuffer[16384];
|
||||||
|
#endif
|
||||||
cc_string inputMsg;
|
cc_string inputMsg;
|
||||||
|
|
||||||
String_InitArray(inputMsg, inputBuffer);
|
String_InitArray(inputMsg, inputBuffer);
|
||||||
|
@ -584,14 +584,6 @@ void Platform_Init(void) {
|
|||||||
Platform_Log1("Running in %c mode with NDS wifi", dsiMode ? "DSi" : "DS");
|
Platform_Log1("Running in %c mode with NDS wifi", dsiMode ? "DSi" : "DS");
|
||||||
#endif
|
#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();
|
InitFilesystem();
|
||||||
InitNetworking();
|
InitNetworking();
|
||||||
cpuStartTiming(1);
|
cpuStartTiming(1);
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include "Errors.h"
|
#include "Errors.h"
|
||||||
|
|
||||||
#ifdef CC_BUILD_TINYSTACK
|
#ifdef CC_BUILD_TINYSTACK
|
||||||
CC_BIG_VAR char temp_mem[40000];
|
CC_BIG_VAR char temp_mem[45000];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user