Super, megaheavyweight thumbnail renderer

This commit is contained in:
Simon Robertshaw
2012-04-03 14:07:39 +01:00
parent efddc12e5d
commit 73c5082cbc
10 changed files with 193 additions and 91 deletions

View File

@@ -2387,6 +2387,8 @@ void Graphics::AttachSDLSurface(SDL_Surface * surface)
} }
void Graphics::Blit() void Graphics::Blit()
{
if(sdl_scrn)
{ {
pixel * dst; pixel * dst;
pixel * src = vid; pixel * src = vid;
@@ -2405,8 +2407,10 @@ void Graphics::Blit()
SDL_UnlockSurface(sdl_scrn); SDL_UnlockSurface(sdl_scrn);
SDL_UpdateRect(sdl_scrn,0,0,0,0); SDL_UpdateRect(sdl_scrn,0,0,0,0);
} }
}
Graphics::Graphics() Graphics::Graphics():
sdl_scrn(NULL)
{ {
vid = (pixel *)malloc(PIXELSIZE * ((XRES+BARSIZE) * (YRES+MENUSIZE))); vid = (pixel *)malloc(PIXELSIZE * ((XRES+BARSIZE) * (YRES+MENUSIZE)));
} }

View File

@@ -747,7 +747,7 @@ void GameView::NotifyClipboardChanged(GameModel * sender)
delete clipboardThumb; delete clipboardThumb;
if(sender->GetClipboard()) if(sender->GetClipboard())
{ {
clipboardThumb = new Thumbnail(0, 0, (pixel*)malloc((256*256)*PIXELSIZE), ui::Point(256, 256)); clipboardThumb = new Thumbnail(sender->GetClipboard());//new Thumbnail(0, 0, (pixel*)malloc((256*256)*PIXELSIZE), ui::Point(256, 256));
} }
else else
clipboardThumb = NULL; clipboardThumb = NULL;
@@ -760,7 +760,7 @@ void GameView::NotifyStampChanged(GameModel * sender)
delete stampThumb; delete stampThumb;
if(sender->GetStamp()) if(sender->GetStamp())
{ {
stampThumb = new Thumbnail(0, 0, (pixel*)malloc((256*256)*PIXELSIZE), ui::Point(256, 256)); stampThumb = new Thumbnail(sender->GetStamp());//new Thumbnail(0, 0, (pixel*)malloc((256*256)*PIXELSIZE), ui::Point(256, 256));
} }
else else
stampThumb = NULL; stampThumb = NULL;

View File

@@ -57,7 +57,13 @@ void SaveButton::Tick(float dt)
if(tempThumb) if(tempThumb)
{ {
thumbnail = new Thumbnail(*tempThumb); //Store a local copy of the thumbnail thumbnail = new Thumbnail(*tempThumb); //Store a local copy of the thumbnail
if(thumbnail->Data) }
}
else
{
thumbnail = new Thumbnail(save);
}
if(thumbnail && thumbnail->Data)
{ {
if(thumbnail->Size.Y > (Size.Y-25)) if(thumbnail->Size.Y > (Size.Y-25))
{ {
@@ -79,8 +85,6 @@ void SaveButton::Tick(float dt)
} }
} }
} }
}
}
void SaveButton::Draw(const Point& screenPos) void SaveButton::Draw(const Point& screenPos)
{ {

81
src/search/Thumbnail.cpp Normal file
View File

@@ -0,0 +1,81 @@
/*
* Thumbnail.cpp
*
* Created on: Apr 3, 2012
* Author: Simon
*/
#include "Thumbnail.h"
#include "simulation/Simulation.h"
#include "simulation/SaveLoader.h"
#include "Renderer.h"
Thumbnail::Thumbnail(const Thumbnail & thumb):
ID(thumb.ID),
Datestamp(thumb.Datestamp),
Data(thumb.Data),
Size(thumb.Size)
{
//Ensure the actual thumbnail data is copied
if(thumb.Data)
{
Data = (pixel *)malloc((thumb.Size.X*thumb.Size.Y) * PIXELSIZE);
memcpy(Data, thumb.Data, (thumb.Size.X*thumb.Size.Y) * PIXELSIZE);
}
else
{
Data = NULL;
}
}
Thumbnail::Thumbnail(int _id, int _datestamp, pixel * _data, ui::Point _size):
ID(_id),
Datestamp(_datestamp),
Data(_data),
Size(_size)
{
}
Thumbnail::Thumbnail(Save * save):
ID(0),
Datestamp(0),
Data(NULL),
Size(XRES+BARSIZE, YRES+MENUSIZE)
{
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;
}
Size = ui::Point(width*CELL, height*CELL);
fail:
delete ren;
delete sim;
delete g;
}
Thumbnail::~Thumbnail()
{
if(Data)
{
free(Data);
}
}

View File

@@ -4,43 +4,18 @@
#include <iostream> #include <iostream>
#include "Graphics.h" #include "Graphics.h"
#include "interface/Point.h" #include "interface/Point.h"
#include "Save.h"
class Thumbnail class Thumbnail
{ {
public: public:
Thumbnail(const Thumbnail & thumb): Thumbnail(const Thumbnail & thumb);
ID(thumb.ID),
Datestamp(thumb.Datestamp),
Data(thumb.Data),
Size(thumb.Size)
{
//Ensure the actual thumbnail data is copied
if(thumb.Data)
{
Data = (pixel *)malloc((thumb.Size.X*thumb.Size.Y) * PIXELSIZE);
memcpy(Data, thumb.Data, (thumb.Size.X*thumb.Size.Y) * PIXELSIZE);
}
else
{
Data = NULL;
}
}
Thumbnail(int _id, int _datestamp, pixel * _data, ui::Point _size): Thumbnail(int _id, int _datestamp, pixel * _data, ui::Point _size);
ID(_id),
Datestamp(_datestamp),
Data(_data),
Size(_size)
{
}
~Thumbnail() Thumbnail(Save * save);
{
if(Data) ~Thumbnail();
{
free(Data);
}
}
int ID, Datestamp; int ID, Datestamp;
ui::Point Size; ui::Point Size;

View File

@@ -10,7 +10,7 @@
//!TODO: enum for LoadSave return //!TODO: enum for LoadSave return
int SaveLoader::LoadSave(unsigned char * data, int dataLength, Simulation * sim, bool replace, int x, int y) int SaveLoader::Info(unsigned char * data, int dataLength, int & width, int & height)
{ {
unsigned char * saveData = data; unsigned char * saveData = data;
if (dataLength<16) if (dataLength<16)
@@ -19,34 +19,65 @@ int SaveLoader::LoadSave(unsigned char * data, int dataLength, Simulation * sim,
} }
if(saveData[0] == 'O' && saveData[1] == 'P' && saveData[2] == 'S') if(saveData[0] == 'O' && saveData[1] == 'P' && saveData[2] == 'S')
{ {
return OPSLoadSave(data, dataLength, sim); return OPSInfo(data, dataLength, width, height);
} }
else if((saveData[0]==0x66 && saveData[1]==0x75 && saveData[2]==0x43) || (saveData[0]==0x50 && saveData[1]==0x53 && saveData[2]==0x76)) else if((saveData[0]==0x66 && saveData[1]==0x75 && saveData[2]==0x43) || (saveData[0]==0x50 && saveData[1]==0x53 && saveData[2]==0x76))
{ {
return PSVLoadSave(data, dataLength, sim, replace, x, y); return PSVInfo(data, dataLength, width, height);
} }
return 1; return 1;
} }
unsigned char * SaveLoader::BuildSave(int & dataLength, Simulation * sim, int orig_x0, int orig_y0, int orig_w, int orig_h) int SaveLoader::Load(unsigned char * data, int dataLength, Simulation * sim, bool replace, int x, int y)
{ {
unsigned char * temp = OPSBuildSave(dataLength, sim, orig_x0, orig_y0, orig_w, orig_h); unsigned char * saveData = data;
if (dataLength<16)
{
return 1;
}
if(saveData[0] == 'O' && saveData[1] == 'P' && saveData[2] == 'S')
{
return OPSLoad(data, dataLength, sim);
}
else if((saveData[0]==0x66 && saveData[1]==0x75 && saveData[2]==0x43) || (saveData[0]==0x50 && saveData[1]==0x53 && saveData[2]==0x76))
{
return PSVLoad(data, dataLength, sim, replace, x, y);
}
return 1;
}
unsigned char * SaveLoader::Build(int & dataLength, Simulation * sim, int orig_x0, int orig_y0, int orig_w, int orig_h)
{
unsigned char * temp = OPSBuild(dataLength, sim, orig_x0, orig_y0, orig_w, orig_h);
if(!temp) if(!temp)
temp = PSVBuildSave(dataLength, sim, orig_x0, orig_y0, orig_w, orig_h); temp = PSVBuild(dataLength, sim, orig_x0, orig_y0, orig_w, orig_h);
return temp; return temp;
} }
int SaveLoader::OPSLoadSave(unsigned char * data, int dataLength, Simulation * sim) int SaveLoader::OPSInfo(unsigned char * data, int dataLength, int & width, int & height)
{
return 2;
}
int SaveLoader::OPSLoad(unsigned char * data, int dataLength, Simulation * sim)
{
return 2;
}
unsigned char * SaveLoader::OPSBuild(int & dataLength, Simulation * sim, int orig_x0, int orig_y0, int orig_w, int orig_h)
{ {
return 0; return 0;
} }
unsigned char * SaveLoader::OPSBuildSave(int & dataLength, Simulation * sim, int orig_x0, int orig_y0, int orig_w, int orig_h) int SaveLoader::PSVInfo(unsigned char * data, int dataLength, int & width, int & height)
{ {
width = data[6];
height = data[7];
return 0; return 0;
} }
int SaveLoader::PSVLoadSave(unsigned char * data, int dataLength, Simulation * sim, bool replace, int x0, int y0) int SaveLoader::PSVLoad(unsigned char * data, int dataLength, Simulation * sim, bool replace, int x0, int y0)
{ {
unsigned char * d = NULL, * c = data; unsigned char * d = NULL, * c = data;
int q,i,j,k,x,y,p=0,*m=NULL, ver, pty, ty, legacy_beta=0, tempGrav = 0; int q,i,j,k,x,y,p=0,*m=NULL, ver, pty, ty, legacy_beta=0, tempGrav = 0;
@@ -640,7 +671,7 @@ corrupt:
return 1; return 1;
} }
unsigned char * SaveLoader::PSVBuildSave(int & dataLength, Simulation * sim, int orig_x0, int orig_y0, int orig_w, int orig_h) unsigned char * SaveLoader::PSVBuild(int & dataLength, Simulation * sim, int orig_x0, int orig_y0, int orig_w, int orig_h)
{ {
unsigned char *d = (unsigned char*)calloc(1,3*(XRES/CELL)*(YRES/CELL)+(XRES*YRES)*15+MAXSIGNS*262), *c; unsigned char *d = (unsigned char*)calloc(1,3*(XRES/CELL)*(YRES/CELL)+(XRES*YRES)*15+MAXSIGNS*262), *c;
int i,j,x,y,p=0,*m=(int*)calloc(XRES*YRES, sizeof(int)); int i,j,x,y,p=0,*m=(int*)calloc(XRES*YRES, sizeof(int));

View File

@@ -12,12 +12,16 @@
class SaveLoader { class SaveLoader {
public: public:
static int LoadSave(unsigned char * data, int dataLength, Simulation * sim, bool replace, int x, int y); static int Info(unsigned char * data, int dataLength, int & width, int & height);
static unsigned char * BuildSave(int & dataLength, Simulation * sim, int orig_x0, int orig_y0, int orig_w, int orig_h); static int Load(unsigned char * data, int dataLength, Simulation * sim, bool replace, int x, int y);
static int OPSLoadSave(unsigned char * data, int dataLength, Simulation * sim); static unsigned char * Build(int & dataLength, Simulation * sim, int orig_x0, int orig_y0, int orig_w, int orig_h);
static unsigned char * OPSBuildSave(int & dataLength, Simulation * sim, int orig_x0, int orig_y0, int orig_w, int orig_h); private:
static int PSVLoadSave(unsigned char * data, int dataLength, Simulation * sim, bool replace, int x, int y); static int OPSInfo(unsigned char * data, int dataLength, int & width, int & height);
static unsigned char * PSVBuildSave(int & dataLength, Simulation * sim, int orig_x0, int orig_y0, int orig_w, int orig_h); static int OPSLoad(unsigned char * data, int dataLength, Simulation * sim);
static unsigned char * OPSBuild(int & dataLength, Simulation * sim, int orig_x0, int orig_y0, int orig_w, int orig_h);
static int PSVInfo(unsigned char * data, int dataLength, int & width, int & height);
static int PSVLoad(unsigned char * data, int dataLength, Simulation * sim, bool replace, int x, int y);
static unsigned char * PSVBuild(int & dataLength, Simulation * sim, int orig_x0, int orig_y0, int orig_w, int orig_h);
}; };
#endif /* SAVELOADER_H_ */ #endif /* SAVELOADER_H_ */

View File

@@ -10,22 +10,22 @@
int Simulation::Load(unsigned char * data, int dataLength) int Simulation::Load(unsigned char * data, int dataLength)
{ {
return SaveLoader::LoadSave(data, dataLength, this, true, 0, 0); return SaveLoader::Load(data, dataLength, this, true, 0, 0);
} }
int Simulation::Load(int x, int y, unsigned char * data, int dataLength) int Simulation::Load(int x, int y, unsigned char * data, int dataLength)
{ {
return SaveLoader::LoadSave(data, dataLength, this, false, x, y); return SaveLoader::Load(data, dataLength, this, false, x, y);
} }
unsigned char * Simulation::Save(int & dataLength) unsigned char * Simulation::Save(int & dataLength)
{ {
return SaveLoader::BuildSave(dataLength, this, 0, 0, XRES, YRES); return SaveLoader::Build(dataLength, this, 0, 0, XRES, YRES);
} }
unsigned char * Simulation::Save(int x1, int y1, int x2, int y2, int & dataLength) unsigned char * Simulation::Save(int x1, int y1, int x2, int y2, int & dataLength)
{ {
return SaveLoader::BuildSave(dataLength, this, x1, y1, x2-x1, y2-y1); return SaveLoader::Build(dataLength, this, x1, y1, x2-x1, y2-y1);
} }
void Simulation::clear_area(int area_x, int area_y, int area_w, int area_h) void Simulation::clear_area(int area_x, int area_y, int area_w, int area_h)

View File

@@ -11,7 +11,8 @@
#include "StampsModelException.h" #include "StampsModelException.h"
StampsModel::StampsModel(): StampsModel::StampsModel():
stamp(NULL) stamp(NULL),
currentPage(1)
{ {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
stampIDs = Client::Ref().GetStamps(); stampIDs = Client::Ref().GetStamps();
@@ -27,6 +28,7 @@ void StampsModel::AddObserver(StampsView * observer)
{ {
observers.push_back(observer); observers.push_back(observer);
observer->NotifyStampsListChanged(this); observer->NotifyStampsListChanged(this);
observer->NotifyPageChanged(this);
} }
void StampsModel::notifyStampsListChanged() void StampsModel::notifyStampsListChanged()
@@ -61,6 +63,8 @@ void StampsModel::UpdateStampsList(int pageNumber)
{ {
std::vector<Save*> tempStampsList = stampsList; std::vector<Save*> tempStampsList = stampsList;
stampsList.clear(); stampsList.clear();
currentPage = pageNumber;
notifyPageChanged();
/*notifyStampsListChanged(); /*notifyStampsListChanged();
for(int i = 0; i < tempStampsList.size(); i++) for(int i = 0; i < tempStampsList.size(); i++)
{ {

View File

@@ -87,13 +87,12 @@ void StampsView::NotifyStampsListChanged(StampsModel * sender)
int buttonAreaWidth, buttonAreaHeight, buttonXOffset, buttonYOffset; int buttonAreaWidth, buttonAreaHeight, buttonXOffset, buttonYOffset;
vector<Save*> saves = sender->GetStampsList(); vector<Save*> saves = sender->GetStampsList();
Client::Ref().ClearThumbnailRequests();
for(i = 0; i < stampButtons.size(); i++) for(i = 0; i < stampButtons.size(); i++)
{ {
RemoveComponent(stampButtons[i]); RemoveComponent(stampButtons[i]);
delete stampButtons[i]; delete stampButtons[i];
} }
stampButtons.clear();
buttonXOffset = 0; buttonXOffset = 0;
buttonYOffset = 50; buttonYOffset = 50;
buttonAreaWidth = Size.X; buttonAreaWidth = Size.X;