From c408e035faf88f968ea208d48ced4b7c3c9dc32d Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Sat, 9 Jun 2012 14:54:58 +0100 Subject: Preview: Wait for save to load before opening, Simulation: Correct block coords when reading wall data, replace existing particles when placing stamps on top, Game: Clear the simulation when loading a save diff --git a/src/client/GameSave.cpp b/src/client/GameSave.cpp index 3bf0df1..6184b35 100644 --- a/src/client/GameSave.cpp +++ b/src/client/GameSave.cpp @@ -69,9 +69,6 @@ GameSave::GameSave(char * data, int dataSize) void GameSave::setSize(int newWidth, int newHeight) { - - std::cout << "GameSave::setSize(" << newWidth << ", " << newHeight << ")"; - this->blockWidth = newWidth; this->blockHeight = newHeight; diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp index 9e655f9..362eddd 100644 --- a/src/game/GameModel.cpp +++ b/src/game/GameModel.cpp @@ -275,12 +275,8 @@ void GameModel::SetSave(SaveInfo * newSave) currentSave = newSave; if(currentSave) { - int returnVal = sim->Load(currentSave->GetGameSave()); - if(returnVal){ - delete currentSave; - currentSave = NULL; - throw GameModelException(returnVal==2?"Save from newer version":"Save data corrupt"); - } + sim->clear_sim(); + sim->Load(currentSave->GetGameSave()); } notifySaveChanged(); notifyPausedChanged(); diff --git a/src/preview/PreviewController.cpp b/src/preview/PreviewController.cpp index 094dbfc..6490b50 100644 --- a/src/preview/PreviewController.cpp +++ b/src/preview/PreviewController.cpp @@ -39,6 +39,10 @@ void PreviewController::Update() Exit(); new ErrorMessage("Error", e.what()); } + if(previewModel->GetDoOpen() && previewModel->GetSave() && previewModel->GetSave()->GetGameSave()) + { + Exit(); + } } SaveInfo * PreviewController::GetSave() diff --git a/src/preview/PreviewView.cpp b/src/preview/PreviewView.cpp index 5e1470e..d0d0d21 100644 --- a/src/preview/PreviewView.cpp +++ b/src/preview/PreviewView.cpp @@ -11,11 +11,13 @@ #include "simulation/SaveRenderer.h" #include "interface/Point.h" #include "interface/Window.h" +#include "Style.h" #include "search/Thumbnail.h" PreviewView::PreviewView(): ui::Window(ui::Point(-1, -1), ui::Point((XRES/2)+200, (YRES/2)+150)), - savePreview(NULL) + savePreview(NULL), + doOpen(false) { class OpenAction: public ui::ButtonAction { @@ -25,7 +27,6 @@ PreviewView::PreviewView(): virtual void ActionCallback(ui::Button * sender) { v->c->DoOpen(); - v->c->Exit(); } }; openButton = new ui::Button(ui::Point(0, Size.Y-19), ui::Point(51, 19), "Open"); @@ -109,6 +110,18 @@ PreviewView::PreviewView(): AddComponent(authorDateLabel); } +void PreviewView::DoDraw() +{ + Window::DoDraw(); + Graphics * g = ui::Engine::Ref().g; + if(c->GetDoOpen()) + { + g->fillrect(Position.X+(Size.X/2)-101, Position.Y+(Size.Y/2)-26, 202, 52, 0, 0, 0, 210); + g->drawrect(Position.X+(Size.X/2)-100, Position.Y+(Size.Y/2)-25, 200, 50, 255, 255, 255, 180); + g->drawtext(Position.X+(Size.X/2)-(Graphics::textwidth("Loading save...")/2), Position.Y+(Size.Y/2)-5, "Loading save...", style::Colour::InformationTitle.Red, style::Colour::InformationTitle.Green, style::Colour::InformationTitle.Blue, 255); + } +} + void PreviewView::OnDraw() { Graphics * g = ui::Engine::Ref().g; @@ -128,16 +141,16 @@ void PreviewView::OnDraw() g->draw_line(Position.X+1, Position.Y+12+YRES/2, Position.X-1+XRES/2, Position.Y+12+YRES/2, 100, 100, 100,255); float factor; - if(!votesUp && !votesDown) - return; - else + if(!(!votesUp && !votesDown)) + { factor = (float)(((float)(XRES/2)-2)/((float)(votesUp+votesDown))); - g->fillrect(1+Position.X, 2+Position.Y+YRES/2, (XRES/2)-2, 9, 200, 50, 50, 255); - g->fillrect(1+Position.X, 2+Position.Y+YRES/2, (int)(((float)votesUp)*factor), 9, 50, 200, 50, 255); - g->fillrect(1+Position.X, 2+Position.Y+(YRES/2), 14, 9, 0, 0, 0, 100); - g->fillrect(Position.X+(XRES/2)-15, 2+Position.Y+(YRES/2), 14, 9, 0, 0, 0, 100); - g->draw_icon(1+Position.X+2, Position.Y+(YRES/2)+4, IconVoteUp); - g->draw_icon(Position.X+(XRES/2)-12, Position.Y+(YRES/2)+1, IconVoteDown); + g->fillrect(1+Position.X, 2+Position.Y+YRES/2, (XRES/2)-2, 9, 200, 50, 50, 255); + g->fillrect(1+Position.X, 2+Position.Y+YRES/2, (int)(((float)votesUp)*factor), 9, 50, 200, 50, 255); + g->fillrect(1+Position.X, 2+Position.Y+(YRES/2), 14, 9, 0, 0, 0, 100); + g->fillrect(Position.X+(XRES/2)-15, 2+Position.Y+(YRES/2), 14, 9, 0, 0, 0, 100); + g->draw_icon(1+Position.X+2, Position.Y+(YRES/2)+4, IconVoteUp); + g->draw_icon(Position.X+(XRES/2)-12, Position.Y+(YRES/2)+1, IconVoteDown); + } for(int i = 0; i < commentTextComponents.size(); i++) { diff --git a/src/preview/PreviewView.h b/src/preview/PreviewView.h index a0e7c20..011f864 100644 --- a/src/preview/PreviewView.h +++ b/src/preview/PreviewView.h @@ -33,12 +33,14 @@ class PreviewView: public ui::Window { std::vector commentTextComponents; int votesUp; int votesDown; + bool doOpen; public: void AttachController(PreviewController * controller) { c = controller;} PreviewView(); void NotifySaveChanged(PreviewModel * sender); void NotifyCommentsChanged(PreviewModel * sender); virtual void OnDraw(); + virtual void DoDraw(); virtual void OnTick(float dt); virtual void OnMouseDown(int x, int y, unsigned button); virtual ~PreviewView(); diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 5f8e963..c4b44ce 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -19,7 +19,7 @@ int Simulation::Load(GameSave * save) int Simulation::Load(int fullX, int fullY, GameSave * save) { - int blockX, blockY; + int blockX, blockY, x, y, r; if(!save) return 0; @@ -32,15 +32,27 @@ int Simulation::Load(int fullX, int fullY, GameSave * save) int i; for(int n = 0; n < NPART && n < save->particlesCount; n++) { - if (pfree == -1) - break; - i = pfree; - pfree = parts[i].life; - if (i>parts_lastActiveIndex) parts_lastActiveIndex = i; + Particle tempPart = save->particles[n]; + tempPart.x += (float)fullX; + tempPart.y += (float)fullY; + x = int(tempPart.x + 0.5f); + y = int(tempPart.y + 0.5f); - parts[i] = save->particles[n]; - parts[i].x += (float)fullX; - parts[i].y += (float)fullY; + if(r = pmap[y][x]) + { + //Replace existing + parts[r>>8] = tempPart; + } + else + { + //Allocate new particle + if (pfree == -1) + break; + i = pfree; + pfree = parts[i].life; + if (i>parts_lastActiveIndex) parts_lastActiveIndex = i; + parts[i] = tempPart; + } } parts_lastActiveIndex = NPART-1; for(int i = 0; i < save->signs.size() && signs.size() < MAXSIGNS; i++) @@ -50,9 +62,9 @@ int Simulation::Load(int fullX, int fullY, GameSave * save) tempSign.y += fullY; signs.push_back(tempSign); } - for(int saveBlockX = 0; saveBlockX < save->blockWidth/CELL; saveBlockX++) + for(int saveBlockX = 0; saveBlockX < save->blockWidth; saveBlockX++) { - for(int saveBlockY = 0; saveBlockY < save->blockHeight/CELL; saveBlockY++) + for(int saveBlockY = 0; saveBlockY < save->blockHeight; saveBlockY++) { if(save->blockMap[saveBlockY][saveBlockX]) { -- cgit v0.9.2-21-gd62e