summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-10-29 09:36:16 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-10-29 09:36:16 (GMT)
commite08bc6680bb766305486fdbe1d8e6cb6482993af (patch)
treef49cb18b69540d06ddc33f4f7be75370045a81c7 /src
parent9b4f710e28bd7d14bec0ce67d19d75cb6a67c5a6 (diff)
downloadpowder-e08bc6680bb766305486fdbe1d8e6cb6482993af.zip
powder-e08bc6680bb766305486fdbe1d8e6cb6482993af.tar.gz
Format: Buffer to pti, Save renderer
Diffstat (limited to 'src')
-rw-r--r--src/Format.cpp15
-rw-r--r--src/Format.h1
-rw-r--r--src/PowderToyRenderer.cpp118
-rw-r--r--src/graphics/Graphics.cpp19
-rw-r--r--src/graphics/Graphics.h1
5 files changed, 154 insertions, 0 deletions
diff --git a/src/Format.cpp b/src/Format.cpp
index f07b01d..5f9741d 100644
--- a/src/Format.cpp
+++ b/src/Format.cpp
@@ -71,6 +71,21 @@ std::string format::UnixtimeToDateMini(time_t unixtime)
}
}
+std::vector<char> format::VideoBufferToPTI(const VideoBuffer & vidBuf)
+{
+ std::vector<char> data;
+ int dataSize = 0;
+ char * buffer = (char*)Graphics::ptif_pack(vidBuf.Buffer, vidBuf.Width, vidBuf.Height, &dataSize);
+
+ if(buffer)
+ {
+ data.insert(data.end(), buffer, buffer+dataSize);
+ free(buffer);
+ }
+
+ return data;
+}
+
std::vector<char> format::VideoBufferToPPM(const VideoBuffer & vidBuf)
{
std::vector<char> data;
diff --git a/src/Format.h b/src/Format.h
index c82f523..0aae25b 100644
--- a/src/Format.h
+++ b/src/Format.h
@@ -28,5 +28,6 @@ namespace format
std::string UnixtimeToDateMini(time_t unixtime);
std::vector<char> VideoBufferToPNG(const VideoBuffer & vidBuf);
std::vector<char> VideoBufferToPPM(const VideoBuffer & vidBuf);
+ std::vector<char> VideoBufferToPTI(const VideoBuffer & vidBuf);
unsigned long CalculateCRC(unsigned char * data, int length);
} \ No newline at end of file
diff --git a/src/PowderToyRenderer.cpp b/src/PowderToyRenderer.cpp
new file mode 100644
index 0000000..cf0d0b1
--- /dev/null
+++ b/src/PowderToyRenderer.cpp
@@ -0,0 +1,118 @@
+#if defined(RENDERER)
+
+#include <time.h>
+#include <iostream>
+#include <sstream>
+#include <string>
+#include <fstream>
+#include <vector>
+
+#include "Config.h"
+#include "Format.h"
+#include "interface/Engine.h"
+#include "graphics/Graphics.h"
+#include "graphics/Renderer.h"
+
+#include "client/GameSave.h"
+#include "simulation/Simulation.h"
+
+
+void readFile(std::string filename, std::vector<char> & storage)
+{
+ std::ifstream fileStream;
+ fileStream.open(std::string(filename).c_str(), std::ios::binary);
+ 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;
+ }
+}
+
+void writeFile(std::string filename, std::vector<char> & fileData)
+{
+ std::ofstream fileStream;
+ fileStream.open(std::string(filename).c_str(), std::ios::binary);
+ if(fileStream.is_open())
+ {
+ fileStream.write(&fileData[0], fileData.size());
+ fileStream.close();
+ }
+}
+
+int main(int argc, char *argv[])
+{
+ ui::Engine * engine;
+ std::string outputPrefix, inputFilename;
+ std::vector<char> inputFile;
+ std::string ppmFilename, ptiFilename, ptiSmallFilename, pngFilename, pngSmallFilename;
+ std::vector<char> ppmFile, ptiFile, ptiSmallFile, pngFile, pngSmallFile;
+
+ inputFilename = std::string(argv[1]);
+ outputPrefix = std::string(argv[2]);
+
+ ppmFilename = outputPrefix+".ppm";
+ ptiFilename = outputPrefix+".pti";
+ ptiSmallFilename = outputPrefix+"-small.pti";
+ pngFilename = outputPrefix+".png";
+ pngSmallFilename = outputPrefix+"-small.png";
+
+ readFile(inputFilename, inputFile);
+
+ ui::Engine::Ref().g = new Graphics();
+
+ engine = &ui::Engine::Ref();
+ engine->Begin(XRES+BARSIZE, YRES+MENUSIZE);
+
+ GameSave * gameSave = new GameSave(inputFile);
+
+ Simulation * sim = new Simulation();
+ Renderer * ren = new Renderer(ui::Engine::Ref().g, sim);
+
+ sim->Load(gameSave);
+
+
+ //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);
+ }
+
+ 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);
+}
+
+#endif
diff --git a/src/graphics/Graphics.cpp b/src/graphics/Graphics.cpp
index 0fa5935..11dcac3 100644
--- a/src/graphics/Graphics.cpp
+++ b/src/graphics/Graphics.cpp
@@ -32,6 +32,25 @@ VideoBuffer::VideoBuffer(VideoBuffer * old):
std::copy(old->Buffer, old->Buffer+(old->Width*old->Height), Buffer);
};
+void VideoBuffer::Resize(float factor, bool resample)
+{
+ int newWidth = ((float)Width)*factor;
+ int newHeight = ((float)Height)*factor;
+ pixel * newBuffer;
+ if(resample)
+ newBuffer = Graphics::resample_img(Buffer, Width, Height, newWidth, newHeight);
+ else
+ newBuffer = Graphics::resample_img_nn(Buffer, Width, Height, newWidth, newHeight);
+
+ if(newBuffer)
+ {
+ delete[] Buffer;
+ Buffer = newBuffer;
+ Width = newWidth;
+ Height = newHeight;
+ }
+}
+
int VideoBuffer::SetCharacter(int x, int y, int c, int r, int g, int b, int a)
{
int i, j, w, bn = 0, ba = 0;
diff --git a/src/graphics/Graphics.h b/src/graphics/Graphics.h
index edc61e2..53d3ee7 100644
--- a/src/graphics/Graphics.h
+++ b/src/graphics/Graphics.h
@@ -109,6 +109,7 @@ public:
VideoBuffer(const VideoBuffer & old);
VideoBuffer(VideoBuffer * old);
VideoBuffer(int width, int height);
+ void Resize(float factor, bool resample = false);
TPT_INLINE void BlendPixel(int x, int y, int r, int g, int b, int a)
{
#ifdef PIX32OGL