2012-04-03 11:08:56 -05:00
|
|
|
/*
|
|
|
|
* SaveRenderer.cpp
|
|
|
|
*
|
|
|
|
* Created on: Apr 3, 2012
|
|
|
|
* Author: Simon
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SaveRenderer.h"
|
|
|
|
#include "Graphics.h"
|
|
|
|
#include "Simulation.h"
|
|
|
|
#include "Renderer.h"
|
|
|
|
|
|
|
|
|
|
|
|
SaveRenderer::SaveRenderer(){
|
|
|
|
g = new Graphics();
|
|
|
|
sim = new Simulation();
|
|
|
|
ren = new Renderer(g, sim);
|
|
|
|
}
|
|
|
|
|
2012-06-05 14:08:35 -05:00
|
|
|
Thumbnail * SaveRenderer::Render(GameSave * save)
|
2012-04-03 11:08:56 -05:00
|
|
|
{
|
2012-06-20 13:23:22 -05:00
|
|
|
#ifndef OGLR
|
2012-04-03 11:08:56 -05:00
|
|
|
Thumbnail * tempThumb = NULL;
|
|
|
|
int width, height;
|
2012-06-20 13:43:03 -05:00
|
|
|
|
|
|
|
#ifdef OGLR
|
|
|
|
width = save->blockWidth*CELL;
|
|
|
|
height = save->blockHeight*CELL;
|
|
|
|
|
|
|
|
VideoBuffer buffer(width, height);
|
|
|
|
buffer.BlendCharacter((width/2)-3, (height/2)-5, 'x', 255, 255, 255, 255);
|
|
|
|
|
|
|
|
Thumbnail * tempThumb = new Thumbnail(0, 0, buffer.Buffer, ui::Point(width, height));
|
|
|
|
|
|
|
|
return tempThumb;
|
|
|
|
#else
|
2012-06-08 16:04:14 -05:00
|
|
|
width = save->blockWidth;
|
|
|
|
height = save->blockHeight;
|
2012-06-05 14:08:35 -05:00
|
|
|
|
2012-04-03 11:08:56 -05:00
|
|
|
pixel * pData = NULL;
|
|
|
|
pixel * dst;
|
|
|
|
pixel * src = g->vid;
|
2012-06-05 14:08:35 -05:00
|
|
|
|
2012-04-03 11:08:56 -05:00
|
|
|
g->Clear();
|
|
|
|
sim->clear_sim();
|
2012-06-20 13:23:22 -05:00
|
|
|
if(!sim->Load(save))
|
2012-04-03 11:08:56 -05:00
|
|
|
{
|
2012-06-20 13:23:22 -05:00
|
|
|
ren->render_parts();
|
2012-06-05 14:08:35 -05:00
|
|
|
|
2012-06-20 13:23:22 -05:00
|
|
|
pData = (pixel *)malloc(PIXELSIZE * ((width*CELL)*(height*CELL)));
|
|
|
|
dst = pData;
|
|
|
|
for(int i = 0; i < height*CELL; i++)
|
|
|
|
{
|
|
|
|
memcpy(dst, src, (width*CELL)*PIXELSIZE);
|
|
|
|
dst+=(width*CELL);///PIXELSIZE;
|
|
|
|
src+=XRES+BARSIZE;
|
|
|
|
}
|
2012-06-05 14:08:35 -05:00
|
|
|
|
2012-06-20 13:23:22 -05:00
|
|
|
tempThumb = new Thumbnail(0, 0, pData, ui::Point(width*CELL, height*CELL));
|
|
|
|
}
|
2012-04-03 11:08:56 -05:00
|
|
|
if(pData)
|
|
|
|
free(pData);
|
|
|
|
return tempThumb;
|
2012-06-20 13:23:22 -05:00
|
|
|
#else
|
|
|
|
VideoBuffer buffer(64, 64);
|
2012-06-20 13:25:41 -05:00
|
|
|
buffer.BlendCharacter(32, 32, 'X', 255, 255, 255, 255);
|
2012-06-20 13:23:22 -05:00
|
|
|
Thumbnail * thumb = new Thumbnail(0, 0, buffer.Buffer, ui::Point(64, 64));
|
|
|
|
return thumb;
|
|
|
|
#endif
|
2012-04-03 11:08:56 -05:00
|
|
|
}
|
|
|
|
|
2012-06-05 14:08:35 -05:00
|
|
|
Thumbnail * SaveRenderer::Render(unsigned char * saveData, int dataSize)
|
|
|
|
{
|
2012-06-05 19:46:13 -05:00
|
|
|
GameSave * tempSave;
|
|
|
|
try {
|
|
|
|
tempSave = new GameSave((char*)saveData, dataSize);
|
|
|
|
} catch (exception & e) {
|
2012-06-05 19:54:27 -05:00
|
|
|
|
|
|
|
//Todo: make this look a little less shit
|
|
|
|
VideoBuffer buffer(64, 64);
|
2012-06-20 13:43:03 -05:00
|
|
|
buffer.BlendCharacter(32, 32, 'x', 255, 255, 255, 255);
|
2012-06-05 19:54:27 -05:00
|
|
|
|
|
|
|
Thumbnail * thumb = new Thumbnail(0, 0, buffer.Buffer, ui::Point(64, 64));
|
|
|
|
|
|
|
|
return thumb;
|
2012-06-05 19:46:13 -05:00
|
|
|
}
|
2012-06-05 14:08:35 -05:00
|
|
|
Thumbnail * thumb = Render(tempSave);
|
|
|
|
delete tempSave;
|
|
|
|
return thumb;
|
|
|
|
}
|
|
|
|
|
2012-04-03 11:08:56 -05:00
|
|
|
SaveRenderer::~SaveRenderer() {
|
|
|
|
// TODO Auto-generated destructor stub
|
|
|
|
}
|
|
|
|
|