minimize ram use due to a lack of ram

This commit is contained in:
Milang 2020-02-18 13:03:57 +01:00
parent f739816d03
commit 8306be7e7a
6 changed files with 13 additions and 13 deletions

Binary file not shown.

View File

@ -13,7 +13,7 @@ OptionA=0
[_2]
Type=1
Order=1
Order=2
Top=15
Left=7800
Height=6885
@ -25,7 +25,7 @@ OptionB=15
[_3]
Type=6
Order=2
Order=1
Top=4035
Left=2715
Height=6390

Binary file not shown.

View File

@ -115,7 +115,7 @@ cell_t* worldGetCell(int x, int y);
void cellDraw(int cx, int cy, int sx, int sy, int plan);
void worldSet(int w, int h, int x, int y, cell_t const * a);
void worldSet(int w, int h, int x, int y, cell_t * a);
void worldDraw();
void worldMove();
@ -134,7 +134,7 @@ typedef struct
int h;
int start_x;
int start_y;
cell_t data[];
cell_t* data;
}map_t;
extern map_t * map_current;

View File

@ -329,7 +329,9 @@ static void unpackLevel(packed_level_t * p)
ll_sendp(LEVEL_INFO, "\n[i]Converted!\n[i]Sending to level zone...", w,h);
worldSet(w, h, sx, sy, c);
ll_sendp(LEVEL_INFO, "\n[i]Achieved unpacking", w,h);
freeProf(c);
// Don't free c, it will be automatically managed by the worldSet function
//freeProf(c);
EnnemiesInit(ennemis, nombre_ennemis);

View File

@ -179,7 +179,7 @@ void worldMove()
teleportersActive();
}
void worldSet(int w, int h, int x, int y, cell_t const * a)
void worldSet(int w, int h, int x, int y, cell_t * a)
{
// Resets mario's vx
mario.p.vx=mario.p.vy=0;
@ -187,24 +187,22 @@ void worldSet(int w, int h, int x, int y, cell_t const * a)
// Free the previous map
if (map_current)
{
if (map_current->data) freeProf(map_current->data);
freeProf(map_current);
map_current=0;
}
// If the new map size is null => invalid map, return
if (0==w*h)
return;
// Calculates the new struct size
int size= 4*sizeof(int) + sizeof(cell_t)*w*h;
if (0==w*h) return;
// Copy map into ram
map_current=(map_t*)mallocProf(size); if (!map_current) mallocError();
map_current=(map_t*)mallocProf(sizeof(map_t)); if (!map_current) mallocError();
// Copy the map to ram
map_current->w = w;
map_current->h = h;
mario.p.x = map_current->start_x = x;
mario.p.y = map_current->start_y = y;
memcpy(map_current->data, a, sizeof(cell_t)*w*h);
map_current->data=a;
//memcpy(map_current->data, a, sizeof(cell_t)*w*h);
}