Skip to content
Permalink
Browse files

Turn ThumbnailRendererTask into an AbandonableTask

  • Loading branch information...
LBPHacker authored and jacob1 committed Mar 8, 2019
1 parent c09a7bb commit d3fe7e39a5479e3366b0463479b13d21b9ad39ca
@@ -1,4 +1,4 @@
#include "ThumbnailRenderer.h"
#include "ThumbnailRendererTask.h"

#include <cmath>

@@ -47,8 +47,10 @@ bool ThumbnailRendererTask::doWork()
}
}

std::unique_ptr<VideoBuffer> ThumbnailRendererTask::GetThumbnail()
std::unique_ptr<VideoBuffer> ThumbnailRendererTask::Finish()
{
return std::move(thumbnail);
auto ptr = std::move(thumbnail);
AbandonableTask::Finish();
return ptr;
}

@@ -1,13 +1,13 @@
#ifndef THUMBNAILRENDERER_H
#define THUMBNAILRENDERER_H

#include "tasks/Task.h"
#include "tasks/AbandonableTask.h"

#include <memory>

class GameSave;
class VideoBuffer;
class ThumbnailRendererTask : public Task
class ThumbnailRendererTask : public AbandonableTask
{
std::unique_ptr<GameSave> Save;
int Width, Height;
@@ -21,7 +21,7 @@ class ThumbnailRendererTask : public Task
virtual ~ThumbnailRendererTask();

virtual bool doWork() override;
std::unique_ptr<VideoBuffer> GetThumbnail();
std::unique_ptr<VideoBuffer> Finish();
};

#endif // THUMBNAILRENDERER_H
@@ -8,7 +8,7 @@
#include "SaveButton.h"
#include "client/Client.h"
#include "client/SaveInfo.h"
#include "client/ThumbnailRenderer.h"
#include "client/ThumbnailRendererTask.h"
#include "simulation/SaveRenderer.h"
#include "client/GameSave.h"
#include "simulation/SaveRenderer.h"
@@ -23,6 +23,7 @@ SaveButton::SaveButton(Point position, Point size, SaveInfo * save):
isMouseInsideAuthor(false),
isMouseInsideHistory(false),
showVotes(false),
thumbnailRenderer(nullptr),
isButtonDown(false),
isMouseInside(false),
selected(false),
@@ -96,6 +97,7 @@ SaveButton::SaveButton(Point position, Point size, SaveFile * file):
isMouseInsideAuthor(false),
isMouseInsideHistory(false),
showVotes(false),
thumbnailRenderer(nullptr),
isButtonDown(false),
isMouseInside(false),
selected(false),
@@ -116,6 +118,10 @@ SaveButton::SaveButton(Point position, Point size, SaveFile * file):

SaveButton::~SaveButton()
{
if (thumbnailRenderer)
{
thumbnailRenderer->Abandon();
}
delete actionCallback;
delete save;
delete file;
@@ -138,7 +144,7 @@ void SaveButton::Tick(float dt)
{
if(save->GetGameSave())
{
thumbnailRenderer = std::unique_ptr<ThumbnailRendererTask>(new ThumbnailRendererTask(save->GetGameSave(), thumbBoxSize.X, thumbBoxSize.Y));
thumbnailRenderer = new ThumbnailRendererTask(save->GetGameSave(), thumbBoxSize.X, thumbBoxSize.Y);
thumbnailRenderer->Start();
triedThumbnail = true;
}
@@ -151,7 +157,7 @@ void SaveButton::Tick(float dt)
}
else if (file && file->GetGameSave())
{
thumbnailRenderer = std::unique_ptr<ThumbnailRendererTask>(new ThumbnailRendererTask(file->GetGameSave(), thumbBoxSize.X, thumbBoxSize.Y, true, true, false));
thumbnailRenderer = new ThumbnailRendererTask(file->GetGameSave(), thumbBoxSize.X, thumbBoxSize.Y, true, true, false);
thumbnailRenderer->Start();
triedThumbnail = true;
}
@@ -164,8 +170,8 @@ void SaveButton::Tick(float dt)
thumbnailRenderer->Poll();
if (thumbnailRenderer->GetDone())
{
thumbnail = thumbnailRenderer->GetThumbnail();
thumbnailRenderer.reset();
thumbnail = thumbnailRenderer->Finish();
thumbnailRenderer = nullptr;
}
}

@@ -45,7 +45,7 @@ class SaveButton : public Component, public http::RequestMonitor<http::Thumbnail
bool isMouseInsideAuthor;
bool isMouseInsideHistory;
bool showVotes;
std::unique_ptr<ThumbnailRendererTask> thumbnailRenderer;
ThumbnailRendererTask *thumbnailRenderer;
public:
SaveButton(Point position, Point size, SaveInfo * save);
SaveButton(Point position, Point size, SaveFile * file);
@@ -11,7 +11,7 @@
#include "gui/interface/Button.h"
#include "gui/interface/Label.h"
#include "gui/interface/Textbox.h"
#include "client/ThumbnailRenderer.h"
#include "client/ThumbnailRendererTask.h"


class LocalSaveActivity::CancelAction: public ui::ButtonAction
@@ -39,6 +39,7 @@ class LocalSaveActivity::SaveAction: public ui::ButtonAction
LocalSaveActivity::LocalSaveActivity(SaveFile save, FileSavedCallback * callback) :
WindowActivity(ui::Point(-1, -1), ui::Point(220, 200)),
save(save),
thumbnailRenderer(nullptr),
callback(callback)
{
ui::Label * titleLabel = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 16), "Save to computer:");
@@ -71,7 +72,7 @@ LocalSaveActivity::LocalSaveActivity(SaveFile save, FileSavedCallback * callback

if(save.GetGameSave())
{
thumbnailRenderer = std::unique_ptr<ThumbnailRendererTask>(new ThumbnailRendererTask(save.GetGameSave(), Size.X-16, -1, false, true, false));
thumbnailRenderer = new ThumbnailRendererTask(save.GetGameSave(), Size.X-16, -1, false, true, false);
thumbnailRenderer->Start();
}
}
@@ -83,8 +84,8 @@ void LocalSaveActivity::OnTick(float dt)
thumbnailRenderer->Poll();
if (thumbnailRenderer->GetDone())
{
thumbnail = thumbnailRenderer->GetThumbnail();
thumbnailRenderer.reset();
thumbnail = thumbnailRenderer->Finish();
thumbnailRenderer = nullptr;
}
}
}
@@ -168,5 +169,9 @@ void LocalSaveActivity::OnDraw()

LocalSaveActivity::~LocalSaveActivity()
{
if (thumbnailRenderer)
{
thumbnailRenderer->Abandon();
}
delete callback;
}
@@ -24,7 +24,7 @@ class FileSavedCallback
class LocalSaveActivity: public WindowActivity
{
SaveFile save;
std::unique_ptr<ThumbnailRendererTask> thumbnailRenderer;
ThumbnailRendererTask *thumbnailRenderer;
std::unique_ptr<VideoBuffer> thumbnail;
ui::Textbox * filenameField;
class CancelAction;
@@ -13,7 +13,7 @@
#include "gui/Style.h"
#include "client/GameSave.h"
#include "images.h"
#include "client/ThumbnailRenderer.h"
#include "client/ThumbnailRendererTask.h"

class ServerSaveActivity::CancelAction: public ui::ButtonAction
{
@@ -104,6 +104,7 @@ class SaveUploadTask: public Task

ServerSaveActivity::ServerSaveActivity(SaveInfo save, ServerSaveActivity::SaveUploadedCallback * callback) :
WindowActivity(ui::Point(-1, -1), ui::Point(440, 200)),
thumbnailRenderer(nullptr),
save(save),
callback(callback),
saveUploadTask(NULL)
@@ -184,13 +185,14 @@ ServerSaveActivity::ServerSaveActivity(SaveInfo save, ServerSaveActivity::SaveUp

if (save.GetGameSave())
{
thumbnailRenderer = std::unique_ptr<ThumbnailRendererTask>(new ThumbnailRendererTask(save.GetGameSave(), (Size.X/2)-16, -1, false, false, true));
thumbnailRenderer = new ThumbnailRendererTask(save.GetGameSave(), (Size.X/2)-16, -1, false, false, true);
thumbnailRenderer->Start();
}
}

ServerSaveActivity::ServerSaveActivity(SaveInfo save, bool saveNow, ServerSaveActivity::SaveUploadedCallback * callback) :
WindowActivity(ui::Point(-1, -1), ui::Point(200, 50)),
thumbnailRenderer(nullptr),
save(save),
callback(callback),
saveUploadTask(NULL)
@@ -407,8 +409,8 @@ void ServerSaveActivity::OnTick(float dt)
thumbnailRenderer->Poll();
if (thumbnailRenderer->GetDone())
{
thumbnail = thumbnailRenderer->GetThumbnail();
thumbnailRenderer.reset();
thumbnail = thumbnailRenderer->Finish();
thumbnailRenderer = nullptr;
}
}

@@ -435,6 +437,10 @@ void ServerSaveActivity::OnDraw()

ServerSaveActivity::~ServerSaveActivity()
{
if (thumbnailRenderer)
{
thumbnailRenderer->Abandon();
}
delete saveUploadTask;
delete callback;
}
@@ -40,7 +40,7 @@ class ServerSaveActivity: public WindowActivity, public TaskListener
protected:
void AddAuthorInfo();
virtual void NotifyDone(Task * task);
std::unique_ptr<ThumbnailRendererTask> thumbnailRenderer;
ThumbnailRendererTask *thumbnailRenderer;
std::unique_ptr<VideoBuffer> thumbnail;
SaveInfo save;
SaveUploadedCallback * callback;
Oops, something went wrong.

0 comments on commit d3fe7e3

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.