Use a single instance of a background simulation for thumbnail rendering
This commit is contained in:
parent
73c5082cbc
commit
838a612026
@ -530,10 +530,13 @@ Thumbnail * Client::GetPreview(int saveID, int saveDate)
|
||||
if(thumbData)
|
||||
{
|
||||
return new Thumbnail(saveID, saveDate, thumbData, ui::Point(imgw, imgh));
|
||||
free(thumbData);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Thumbnail(saveID, saveDate, (pixel *)malloc((128*128) * PIXELSIZE), ui::Point(128, 128));
|
||||
thumbData = (pixel *)malloc((128*128) * PIXELSIZE);
|
||||
return new Thumbnail(saveID, saveDate, thumbData, ui::Point(128, 128));
|
||||
free(thumbData);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -747,10 +750,13 @@ Thumbnail * Client::GetThumbnail(int saveID, int saveDate)
|
||||
if(thumbData)
|
||||
{
|
||||
thumbnailCache[thumbnailCacheNextID] = new Thumbnail(saveID, saveDate, thumbData, ui::Point(imgw, imgh));
|
||||
free(thumbData);
|
||||
}
|
||||
else
|
||||
{
|
||||
thumbnailCache[thumbnailCacheNextID] = new Thumbnail(saveID, saveDate, (pixel *)malloc((128*128) * PIXELSIZE), ui::Point(128, 128));
|
||||
thumbData = (pixel *)malloc((128*128) * PIXELSIZE);
|
||||
thumbnailCache[thumbnailCacheNextID] = new Thumbnail(saveID, saveDate, thumbData, ui::Point(128, 128));
|
||||
free(thumbData);
|
||||
}
|
||||
return thumbnailCache[thumbnailCacheNextID++];
|
||||
}
|
||||
@ -765,7 +771,9 @@ Thumbnail * Client::GetThumbnail(int saveID, int saveDate)
|
||||
{
|
||||
delete thumbnailCache[thumbnailCacheNextID];
|
||||
}
|
||||
thumbnailCache[thumbnailCacheNextID] = new Thumbnail(saveID, saveDate, (pixel *)malloc((128*128) * PIXELSIZE), ui::Point(128, 128));
|
||||
thumbData = (pixel *)malloc((128*128) * PIXELSIZE);
|
||||
thumbnailCache[thumbnailCacheNextID] = new Thumbnail(saveID, saveDate, thumbData, ui::Point(128, 128));
|
||||
free(thumbData);
|
||||
return thumbnailCache[thumbnailCacheNextID++];
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "interface/Keys.h"
|
||||
#include "interface/Slider.h"
|
||||
#include "search/Thumbnail.h"
|
||||
#include "simulation/SaveRenderer.h"
|
||||
|
||||
GameView::GameView():
|
||||
ui::Window(ui::Point(0, 0), ui::Point(XRES+BARSIZE, YRES+MENUSIZE)),
|
||||
@ -747,7 +748,7 @@ void GameView::NotifyClipboardChanged(GameModel * sender)
|
||||
delete clipboardThumb;
|
||||
if(sender->GetClipboard())
|
||||
{
|
||||
clipboardThumb = new Thumbnail(sender->GetClipboard());//new Thumbnail(0, 0, (pixel*)malloc((256*256)*PIXELSIZE), ui::Point(256, 256));
|
||||
clipboardThumb = SaveRenderer::Ref().Render(sender->GetClipboard()->GetData(), sender->GetClipboard()->GetDataLength());
|
||||
}
|
||||
else
|
||||
clipboardThumb = NULL;
|
||||
@ -760,7 +761,7 @@ void GameView::NotifyStampChanged(GameModel * sender)
|
||||
delete stampThumb;
|
||||
if(sender->GetStamp())
|
||||
{
|
||||
stampThumb = new Thumbnail(sender->GetStamp());//new Thumbnail(0, 0, (pixel*)malloc((256*256)*PIXELSIZE), ui::Point(256, 256));
|
||||
stampThumb = SaveRenderer::Ref().Render(sender->GetStamp()->GetData(), sender->GetStamp()->GetDataLength());
|
||||
}
|
||||
else
|
||||
stampThumb = NULL;
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "Global.h"
|
||||
#include "Engine.h"
|
||||
#include "client/Client.h"
|
||||
#include "simulation/SaveRenderer.h"
|
||||
|
||||
namespace ui {
|
||||
|
||||
@ -61,7 +62,7 @@ void SaveButton::Tick(float dt)
|
||||
}
|
||||
else
|
||||
{
|
||||
thumbnail = new Thumbnail(save);
|
||||
thumbnail = SaveRenderer::Ref().Render(save->GetData(), save->GetDataLength());
|
||||
}
|
||||
if(thumbnail && thumbnail->Data)
|
||||
{
|
||||
|
@ -6,9 +6,6 @@
|
||||
*/
|
||||
|
||||
#include "Thumbnail.h"
|
||||
#include "simulation/Simulation.h"
|
||||
#include "simulation/SaveLoader.h"
|
||||
#include "Renderer.h"
|
||||
|
||||
Thumbnail::Thumbnail(const Thumbnail & thumb):
|
||||
ID(thumb.ID),
|
||||
@ -34,42 +31,15 @@ Thumbnail::Thumbnail(int _id, int _datestamp, pixel * _data, ui::Point _size):
|
||||
Data(_data),
|
||||
Size(_size)
|
||||
{
|
||||
}
|
||||
|
||||
Thumbnail::Thumbnail(Save * save):
|
||||
ID(0),
|
||||
Datestamp(0),
|
||||
Data(NULL),
|
||||
Size(XRES+BARSIZE, YRES+MENUSIZE)
|
||||
if(_data)
|
||||
{
|
||||
Graphics * g = new Graphics();
|
||||
Simulation * sim = new Simulation();
|
||||
Renderer * ren = new Renderer(g, sim);
|
||||
sim->Load(save->GetData(), save->GetDataLength());
|
||||
ren->render_parts();
|
||||
|
||||
int width, height;
|
||||
|
||||
pixel * dst;
|
||||
pixel * src = g->vid;
|
||||
|
||||
if(SaveLoader::Info(save->GetData(), save->GetDataLength(), width, height))
|
||||
goto fail;
|
||||
|
||||
dst = Data = (pixel *)malloc(PIXELSIZE * ((width*CELL)*(height*CELL)));
|
||||
|
||||
for(int i = 0; i < height*CELL; i++)
|
||||
{
|
||||
memcpy(dst, src, (width*CELL)*PIXELSIZE);
|
||||
dst+=(width*CELL);///PIXELSIZE;
|
||||
src+=XRES+BARSIZE;
|
||||
Data = (pixel *)malloc((_size.X*_size.Y) * PIXELSIZE);
|
||||
memcpy(Data, _data, (_size.X*_size.Y) * PIXELSIZE);
|
||||
}
|
||||
else
|
||||
{
|
||||
Data = NULL;
|
||||
}
|
||||
|
||||
Size = ui::Point(width*CELL, height*CELL);
|
||||
fail:
|
||||
delete ren;
|
||||
delete sim;
|
||||
delete g;
|
||||
}
|
||||
|
||||
Thumbnail::~Thumbnail()
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include <iostream>
|
||||
#include "Graphics.h"
|
||||
#include "interface/Point.h"
|
||||
#include "Save.h"
|
||||
|
||||
class Thumbnail
|
||||
{
|
||||
@ -13,8 +12,6 @@ public:
|
||||
|
||||
Thumbnail(int _id, int _datestamp, pixel * _data, ui::Point _size);
|
||||
|
||||
Thumbnail(Save * save);
|
||||
|
||||
~Thumbnail();
|
||||
|
||||
int ID, Datestamp;
|
||||
|
59
src/simulation/SaveRenderer.cpp
Normal file
59
src/simulation/SaveRenderer.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* SaveRenderer.cpp
|
||||
*
|
||||
* Created on: Apr 3, 2012
|
||||
* Author: Simon
|
||||
*/
|
||||
|
||||
#include "SaveRenderer.h"
|
||||
#include "Graphics.h"
|
||||
#include "Simulation.h"
|
||||
#include "Renderer.h"
|
||||
#include "SaveLoader.h"
|
||||
|
||||
|
||||
SaveRenderer::SaveRenderer(){
|
||||
g = new Graphics();
|
||||
sim = new Simulation();
|
||||
ren = new Renderer(g, sim);
|
||||
}
|
||||
|
||||
Thumbnail * SaveRenderer::Render(unsigned char * data, int dataLength)
|
||||
{
|
||||
Thumbnail * tempThumb = NULL;
|
||||
int width, height;
|
||||
pixel * pData = NULL;
|
||||
pixel * dst;
|
||||
pixel * src = g->vid;
|
||||
|
||||
g->Clear();
|
||||
sim->clear_sim();
|
||||
if(sim->Load(data, dataLength))
|
||||
goto finish;
|
||||
|
||||
if(SaveLoader::Info(data, dataLength, width, height))
|
||||
goto finish;
|
||||
|
||||
ren->render_parts();
|
||||
|
||||
dst = pData = (pixel *)malloc(PIXELSIZE * ((width*CELL)*(height*CELL)));
|
||||
|
||||
for(int i = 0; i < height*CELL; i++)
|
||||
{
|
||||
memcpy(dst, src, (width*CELL)*PIXELSIZE);
|
||||
dst+=(width*CELL);///PIXELSIZE;
|
||||
src+=XRES+BARSIZE;
|
||||
}
|
||||
|
||||
tempThumb = new Thumbnail(0, 0, pData, ui::Point(width*CELL, height*CELL));
|
||||
|
||||
finish:
|
||||
if(pData)
|
||||
free(pData);
|
||||
return tempThumb;
|
||||
}
|
||||
|
||||
SaveRenderer::~SaveRenderer() {
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
27
src/simulation/SaveRenderer.h
Normal file
27
src/simulation/SaveRenderer.h
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* SaveRenderer.h
|
||||
*
|
||||
* Created on: Apr 3, 2012
|
||||
* Author: Simon
|
||||
*/
|
||||
|
||||
#ifndef SAVERENDERER_H_
|
||||
#define SAVERENDERER_H_
|
||||
|
||||
#include "Singleton.h"
|
||||
#include "search/Thumbnail.h"
|
||||
|
||||
class Graphics;
|
||||
class Simulation;
|
||||
class Renderer;
|
||||
class SaveRenderer: public Singleton<SaveRenderer> {
|
||||
Graphics * g;
|
||||
Simulation * sim;
|
||||
Renderer * ren;
|
||||
public:
|
||||
SaveRenderer();
|
||||
Thumbnail * Render(unsigned char * data, int dataLength);
|
||||
virtual ~SaveRenderer();
|
||||
};
|
||||
|
||||
#endif /* SAVERENDERER_H_ */
|
Reference in New Issue
Block a user