The-Powder-Toy/src/PowderToyRenderer.cpp

76 lines
1.6 KiB
C++
Raw Normal View History

2019-04-20 07:12:32 -05:00
#include "graphics/Graphics.h"
#include "graphics/Renderer.h"
#include "common/String.h"
#include "common/tpt-rand.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"
#include "common/platform/Platform.h"
#include <ctime>
#include <iostream>
#include <fstream>
#include <vector>
2012-10-29 04:36:16 -05:00
int main(int argc, char *argv[])
{
if (!argv[1] || !argv[2]) {
std::cout << "Usage: " << argv[0] << " <inputFilename> <outputPrefix>" << std::endl;
return 1;
}
auto inputFilename = ByteString(argv[1]);
auto outputFilename = ByteString(argv[2]) + ".png";
2012-10-29 04:36:16 -05:00
std::vector<char> fileData;
if (!Platform::ReadFile(fileData, inputFilename))
{
return 1;
}
2012-10-29 04:36:16 -05:00
GameSave * gameSave = NULL;
try
{
2023-01-22 02:17:13 -06:00
gameSave = new GameSave(fileData, false);
}
catch (ParseException &e)
{
//Render the save again later or something? I don't know
if (ByteString(e.what()).FromUtf8() == "Save from newer version")
throw e;
}
2012-10-29 04:36:16 -05:00
auto rng = std::make_unique<RNG>();
2012-10-29 04:36:16 -05:00
Simulation * sim = new Simulation();
Renderer * ren = new Renderer(sim);
2012-10-29 04:36:16 -05:00
if (gameSave)
{
sim->Load(gameSave, true);
//Render save
ren->decorations_enable = true;
ren->blackDecorations = true;
int frame = 15;
while(frame)
{
frame--;
ren->render_parts();
ren->render_fire();
ren->clearScreen();
}
}
else
2012-10-29 04:36:16 -05: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();
screenBuffer.WritePNG(outputFilename);
2012-10-29 04:36:16 -05:00
}