mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2024-12-25 14:15:46 +00:00
Core: tgaSave() should free memory passed in. SceneEditor: Add support for grid map dumping (in TGA format).
This allows reconstructing the map templates, which were never shipped with the game. This patch also fixes insane memory leaking when taking screenshots, or dumping screen frames.
This commit is contained in:
parent
a97629b52b
commit
d903e74bf6
4 changed files with 37 additions and 1 deletions
|
@ -501,6 +501,7 @@ public:
|
||||||
|
|
||||||
void checkForRebuild();
|
void checkForRebuild();
|
||||||
void createAquarian();
|
void createAquarian();
|
||||||
|
void dumpObs();
|
||||||
|
|
||||||
DebugButton *btnMenu;
|
DebugButton *btnMenu;
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -707,6 +707,8 @@ void SceneEditor::init()
|
||||||
|
|
||||||
addAction(MakeFunctionEvent(SceneEditor, createAquarian), KEY_F, 0);
|
addAction(MakeFunctionEvent(SceneEditor, createAquarian), KEY_F, 0);
|
||||||
|
|
||||||
|
addAction(MakeFunctionEvent(SceneEditor, dumpObs), KEY_F8, 0);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// OLD CRAP
|
// OLD CRAP
|
||||||
|
@ -3908,5 +3910,32 @@ void SceneEditor::prevEntityType()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SceneEditor::dumpObs()
|
||||||
|
{
|
||||||
|
TileVector tv;
|
||||||
|
const uint32 A = 0xFF000000;
|
||||||
|
#define COL(c) (((0x ## c)) | A)
|
||||||
|
const uint32 coltab[5] =
|
||||||
|
{
|
||||||
|
COL(FFFFFF),
|
||||||
|
COL(FFFFFF),
|
||||||
|
COL(000000),
|
||||||
|
COL(FFFFFF),
|
||||||
|
COL(FFFFFF),
|
||||||
|
};
|
||||||
|
unsigned char *data = new unsigned char[MAX_GRID * MAX_GRID * sizeof(uint32)];
|
||||||
|
uint32 *ptr = (uint32*)data;
|
||||||
|
for(tv.y = MAX_GRID - 1; ; --tv.y)
|
||||||
|
{
|
||||||
|
for(tv.x = 0; tv.x < MAX_GRID; ++tv.x)
|
||||||
|
*ptr++ = coltab[game->getGrid(tv)];
|
||||||
|
if(tv.y == 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
std::string outfn = dsq->getUserDataFolder() + "/griddump-" + game->sceneName + ".tga";
|
||||||
|
core->tgaSave(outfn.c_str(), MAX_GRID, MAX_GRID, 32, data);
|
||||||
|
dsq->screenMessage("Saved grid image to " + outfn);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // AQUARIA_BUILD_SCENEEDITOR
|
#endif // AQUARIA_BUILD_SCENEEDITOR
|
||||||
|
|
|
@ -4777,6 +4777,7 @@ int Core::tgaSave( const char *filename,
|
||||||
// open file and check for errors
|
// open file and check for errors
|
||||||
file = fopen(adjustFilenameCase(filename).c_str(), "wb");
|
file = fopen(adjustFilenameCase(filename).c_str(), "wb");
|
||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
|
delete [] imageData;
|
||||||
return (int)false;
|
return (int)false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4802,6 +4803,7 @@ int Core::tgaSave( const char *filename,
|
||||||
|| fwrite(&cGarbage, sizeof(unsigned char), 1, file) != 1)
|
|| fwrite(&cGarbage, sizeof(unsigned char), 1, file) != 1)
|
||||||
{
|
{
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
delete [] imageData;
|
||||||
return (int)false;
|
return (int)false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4818,10 +4820,12 @@ int Core::tgaSave( const char *filename,
|
||||||
width * height * mode, file) != width * height * mode)
|
width * height * mode, file) != width * height * mode)
|
||||||
{
|
{
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
delete [] imageData;
|
||||||
return (int)false;
|
return (int)false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
delete [] imageData;
|
||||||
|
|
||||||
return (int)true;
|
return (int)true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1310,6 +1310,9 @@ public:
|
||||||
void pollEvents();
|
void pollEvents();
|
||||||
|
|
||||||
CoreSettings settings;
|
CoreSettings settings;
|
||||||
|
|
||||||
|
int tgaSave(const char *filename, short int width, short int height, unsigned char pixelDepth, unsigned char *imageData);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
std::string fpsDebugString;
|
std::string fpsDebugString;
|
||||||
|
@ -1397,7 +1400,6 @@ protected:
|
||||||
|
|
||||||
|
|
||||||
int tgaSaveSeries(char *filename, short int width, short int height, unsigned char pixelDepth, unsigned char *imageData);
|
int tgaSaveSeries(char *filename, short int width, short int height, unsigned char pixelDepth, unsigned char *imageData);
|
||||||
int tgaSave(const char *filename, short int width, short int height, unsigned char pixelDepth, unsigned char *imageData);
|
|
||||||
virtual void onUpdate(float dt);
|
virtual void onUpdate(float dt);
|
||||||
virtual void onRender(){}
|
virtual void onRender(){}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue