2019-12-17 08:03:41 -06:00
|
|
|
#include "Config.h"
|
2019-04-20 07:12:32 -05:00
|
|
|
#include "graphics/Graphics.h"
|
|
|
|
#include "graphics/Renderer.h"
|
|
|
|
|
2016-07-17 22:37:24 -05:00
|
|
|
#include <ctime>
|
2012-10-29 04:36:16 -05:00
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <vector>
|
|
|
|
|
2018-04-30 13:13:24 -05:00
|
|
|
#include "common/String.h"
|
2012-10-29 04:36:16 -05:00
|
|
|
#include "Format.h"
|
2013-03-22 09:14:17 -05:00
|
|
|
#include "gui/interface/Engine.h"
|
2012-10-29 04:36:16 -05:00
|
|
|
|
|
|
|
#include "client/GameSave.h"
|
|
|
|
#include "simulation/Simulation.h"
|
|
|
|
|
|
|
|
|
2012-11-03 07:21:53 -05:00
|
|
|
void EngineProcess() {}
|
2018-04-30 13:13:24 -05:00
|
|
|
void ClipboardPush(ByteString) {}
|
|
|
|
ByteString ClipboardPull() { return ""; }
|
2013-02-14 22:31:31 -06:00
|
|
|
int GetModifiers() { return 0; }
|
2016-04-01 23:10:15 -05:00
|
|
|
void SetCursorEnabled(int enabled) {}
|
2016-07-23 18:15:07 -05:00
|
|
|
unsigned int GetTicks() { return 0; }
|
2012-11-03 07:21:53 -05:00
|
|
|
|
2018-04-30 13:13:24 -05:00
|
|
|
void readFile(ByteString filename, std::vector<char> & storage)
|
2012-10-29 04:36:16 -05:00
|
|
|
{
|
|
|
|
std::ifstream fileStream;
|
2018-04-30 13:13:24 -05:00
|
|
|
fileStream.open(filename.c_str(), std::ios::binary);
|
2012-10-29 04:36:16 -05:00
|
|
|
if(fileStream.is_open())
|
|
|
|
{
|
|
|
|
fileStream.seekg(0, std::ios::end);
|
|
|
|
size_t fileSize = fileStream.tellg();
|
|
|
|
fileStream.seekg(0);
|
|
|
|
|
|
|
|
unsigned char * tempData = new unsigned char[fileSize];
|
|
|
|
fileStream.read((char *)tempData, fileSize);
|
|
|
|
fileStream.close();
|
|
|
|
|
|
|
|
std::vector<unsigned char> fileData;
|
|
|
|
storage.clear();
|
|
|
|
storage.insert(storage.end(), tempData, tempData+fileSize);
|
|
|
|
delete[] tempData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-30 13:13:24 -05:00
|
|
|
void writeFile(ByteString filename, std::vector<char> & fileData)
|
2012-10-29 04:36:16 -05:00
|
|
|
{
|
|
|
|
std::ofstream fileStream;
|
2018-04-30 13:13:24 -05:00
|
|
|
fileStream.open(filename.c_str(), std::ios::binary);
|
2012-10-29 04:36:16 -05:00
|
|
|
if(fileStream.is_open())
|
|
|
|
{
|
|
|
|
fileStream.write(&fileData[0], fileData.size());
|
|
|
|
fileStream.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
2018-04-03 20:46:01 -05:00
|
|
|
{
|
2018-04-30 13:13:24 -05:00
|
|
|
ByteString outputPrefix, inputFilename;
|
2012-10-29 04:36:16 -05:00
|
|
|
std::vector<char> inputFile;
|
2018-04-30 13:13:24 -05:00
|
|
|
ByteString ppmFilename, ptiFilename, ptiSmallFilename, pngFilename, pngSmallFilename;
|
2012-10-29 04:36:16 -05:00
|
|
|
std::vector<char> ppmFile, ptiFile, ptiSmallFile, pngFile, pngSmallFile;
|
|
|
|
|
2020-09-15 14:23:05 -05:00
|
|
|
if (!argv[1] || !argv[2]) {
|
|
|
|
std::cout << "Usage: " << argv[0] << " <inputFilename> <outputPrefix>" << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
2018-04-30 13:13:24 -05:00
|
|
|
inputFilename = argv[1];
|
|
|
|
outputPrefix = argv[2];
|
2012-10-29 04:36:16 -05:00
|
|
|
|
|
|
|
ppmFilename = outputPrefix+".ppm";
|
|
|
|
ptiFilename = outputPrefix+".pti";
|
|
|
|
ptiSmallFilename = outputPrefix+"-small.pti";
|
|
|
|
pngFilename = outputPrefix+".png";
|
|
|
|
pngSmallFilename = outputPrefix+"-small.png";
|
|
|
|
|
|
|
|
readFile(inputFilename, inputFile);
|
|
|
|
|
2015-01-10 17:47:42 -06:00
|
|
|
GameSave * gameSave = NULL;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
gameSave = new GameSave(inputFile);
|
|
|
|
}
|
2020-02-23 16:43:11 -06:00
|
|
|
catch (ParseException &e)
|
2015-01-10 17:47:42 -06:00
|
|
|
{
|
|
|
|
//Render the save again later or something? I don't know
|
2018-04-30 13:13:24 -05:00
|
|
|
if (ByteString(e.what()).FromUtf8() == "Save from newer version")
|
2015-01-10 17:47:42 -06:00
|
|
|
throw e;
|
|
|
|
}
|
2012-10-29 04:36:16 -05:00
|
|
|
|
|
|
|
Simulation * sim = new Simulation();
|
2019-12-17 08:03:41 -06:00
|
|
|
Renderer * ren = new Renderer(new Graphics(), sim);
|
2012-10-29 04:36:16 -05:00
|
|
|
|
2015-01-10 17:47:42 -06:00
|
|
|
if (gameSave)
|
|
|
|
{
|
2019-07-09 17:35:49 -05:00
|
|
|
sim->Load(gameSave, true);
|
2015-01-10 17:47:42 -06:00
|
|
|
|
|
|
|
//Render save
|
|
|
|
ren->decorations_enable = true;
|
|
|
|
ren->blackDecorations = true;
|
|
|
|
|
|
|
|
int frame = 15;
|
|
|
|
while(frame)
|
|
|
|
{
|
|
|
|
frame--;
|
|
|
|
ren->render_parts();
|
|
|
|
ren->render_fire();
|
|
|
|
ren->clearScreen(1.0f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2012-10-29 04:36:16 -05:00
|
|
|
{
|
2015-01-10 17:47:42 -06:00
|
|
|
int w = Graphics::textwidth("Save file invalid")+16, x = (XRES-w)/2, y = (YRES-24)/2;
|
|
|
|
ren->drawrect(x, y, w, 24, 192, 192, 192, 255);
|
|
|
|
ren->drawtext(x+8, y+8, "Save file invalid", 192, 192, 240, 255);
|
2012-10-29 04:36:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
ren->RenderBegin();
|
|
|
|
ren->RenderEnd();
|
|
|
|
|
|
|
|
VideoBuffer screenBuffer = ren->DumpFrame();
|
|
|
|
//ppmFile = format::VideoBufferToPPM(screenBuffer);
|
|
|
|
ptiFile = format::VideoBufferToPTI(screenBuffer);
|
|
|
|
pngFile = format::VideoBufferToPNG(screenBuffer);
|
|
|
|
|
|
|
|
screenBuffer.Resize(1.0f/3.0f, true);
|
|
|
|
ptiSmallFile = format::VideoBufferToPTI(screenBuffer);
|
|
|
|
pngSmallFile = format::VideoBufferToPNG(screenBuffer);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//writeFile(ppmFilename, ppmFile);
|
|
|
|
writeFile(ptiFilename, ptiFile);
|
|
|
|
writeFile(ptiSmallFilename, ptiSmallFile);
|
|
|
|
writeFile(pngFilename, pngFile);
|
|
|
|
writeFile(pngSmallFilename, pngSmallFile);
|
|
|
|
}
|