Skip to content
Permalink
Browse files

Use the new thumbnail renderer task everywhere

  • Loading branch information...
LBPHacker authored and jacob1 committed Mar 7, 2019
1 parent 3a76a3a commit 66c49203f2240dc9088c2aeb619c5a86dff7b131
@@ -77,37 +77,6 @@ void RequestBroker::Shutdown()
}
}

void RequestBroker::RenderThumbnail(GameSave * gameSave, int width, int height, RequestListener * tListener)
{
RenderThumbnail(gameSave, true, true, width, height, false, tListener);
}

void RequestBroker::RenderThumbnail(GameSave * gameSave, bool decorations, bool fire, int width, int height, bool autoRescale, RequestListener * tListener)
{
ListenerHandle handle = AttachRequestListener(tListener);

ThumbRenderRequest * r = new ThumbRenderRequest(new GameSave(*gameSave), decorations, fire, width, height, autoRescale, handle);

pthread_mutex_lock(&requestQueueMutex);
requestQueue.push_back(r);
pthread_mutex_unlock(&requestQueueMutex);

assureRunning();
}

void RequestBroker::RetrieveThumbnail(int saveID, int saveDate, int width, int height, RequestListener * tListener)
{
ByteStringBuilder url;
url << "http://" << STATICSERVER << "/" << saveID;
if(saveDate)
{
url << "_" << saveDate;
}
url << "_small.pti";

RetrieveImage(url.Build(), width, height, tListener);
}

void RequestBroker::Start(Request * request, RequestListener * tListener, int identifier)
{
ListenerHandle handle = AttachRequestListener(tListener);
@@ -121,19 +90,6 @@ void RequestBroker::Start(Request * request, RequestListener * tListener, int id
assureRunning();
}

void RequestBroker::RetrieveImage(ByteString imageUrl, int width, int height, RequestListener * tListener)
{
ListenerHandle handle = AttachRequestListener(tListener);

ImageRequest * r = new ImageRequest(imageUrl, width, height, handle);

pthread_mutex_lock(&requestQueueMutex);
requestQueue.push_back(r);
pthread_mutex_unlock(&requestQueueMutex);

assureRunning();
}

TH_ENTRY_POINT void * RequestBroker::thumbnailQueueProcessHelper(void * ref)
{
((RequestBroker*)ref)->thumbnailQueueProcessTH();
@@ -243,12 +199,6 @@ void RequestBroker::requestComplete(Request * completedRequest)
pthread_mutex_unlock(&completeQueueMutex);
}


void RequestBroker::RetrieveThumbnail(int saveID, int width, int height, RequestListener * tListener)
{
RetrieveThumbnail(saveID, 0, width, height, tListener);
}

bool RequestBroker::CheckRequestListener(ListenerHandle handle)
{
pthread_mutex_lock(&listenersMutex);
@@ -51,11 +51,6 @@ class RequestBroker: public Singleton<RequestBroker>
void Shutdown();

void FlushThumbQueue();
void RetrieveImage(ByteString imageUrl, int width, int height, RequestListener * tListener);
void RenderThumbnail(GameSave * gameSave, bool decorations, bool fire, int width, int height, bool autoRescale, RequestListener * tListener);
void RenderThumbnail(GameSave * gameSave, int width, int height, RequestListener * tListener);
void RetrieveThumbnail(int saveID, int saveDate, int width, int height, RequestListener * tListener);
void RetrieveThumbnail(int saveID, int width, int height, RequestListener * tListener);
void Start(Request * request, RequestListener * tLIstener, int identifier = 0);

bool CheckRequestListener(ListenerHandle handle);
@@ -6,12 +6,12 @@
#include "graphics/Graphics.h"
#include "gui/Style.h"

#include "client/requestbroker/RequestBroker.h"
#include "gui/dialogues/ConfirmPrompt.h"
#include "gui/dialogues/ErrorMessage.h"
#include "gui/interface/Button.h"
#include "gui/interface/Label.h"
#include "gui/interface/Textbox.h"
#include "client/ThumbnailRenderer.h"


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

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

void LocalSaveActivity::OnTick(float dt)
{
if (thumbnailRenderer)
{
thumbnailRenderer->Poll();
if (thumbnailRenderer->GetDone())
{
thumbnail = thumbnailRenderer->GetThumbnail();
thumbnailRenderer.reset();
}
}
}

void LocalSaveActivity::Save()
@@ -146,20 +161,12 @@ void LocalSaveActivity::OnDraw()

if(thumbnail)
{
g->draw_image(thumbnail, Position.X+(Size.X-thumbnail->Width)/2, Position.Y+45, 255);
g->draw_image(thumbnail.get(), Position.X+(Size.X-thumbnail->Width)/2, Position.Y+45, 255);
g->drawrect(Position.X+(Size.X-thumbnail->Width)/2, Position.Y+45, thumbnail->Width, thumbnail->Height, 180, 180, 180, 255);
}
}

void LocalSaveActivity::OnResponseReady(void * imagePtr, int identifier)
{
delete thumbnail;
thumbnail = (VideoBuffer*)imagePtr;
}

LocalSaveActivity::~LocalSaveActivity()
{
RequestBroker::Ref().DetachRequestListener(this);
delete thumbnail;
delete callback;
}
@@ -2,7 +2,8 @@

#include "Activity.h"
#include "client/SaveFile.h"
#include "client/requestbroker/RequestListener.h"

#include <memory>

namespace ui
{
@@ -11,6 +12,7 @@ namespace ui

class VideoBuffer;

class ThumbnailRendererTask;
class FileSavedCallback
{
public:
@@ -19,10 +21,11 @@ class FileSavedCallback
virtual void FileSaved(SaveFile * file) {}
};

class LocalSaveActivity: public WindowActivity, public RequestListener
class LocalSaveActivity: public WindowActivity
{
SaveFile save;
VideoBuffer * thumbnail;
std::unique_ptr<ThumbnailRendererTask> thumbnailRenderer;
std::unique_ptr<VideoBuffer> thumbnail;
ui::Textbox * filenameField;
class CancelAction;
class SaveAction;
@@ -34,6 +37,6 @@ class LocalSaveActivity: public WindowActivity, public RequestListener
void saveWrite(ByteString finalFilename);
virtual void Save();
virtual void OnDraw();
virtual void OnResponseReady(void * imagePtr, int identifier);
virtual void OnTick(float dt);
virtual ~LocalSaveActivity();
};
@@ -4,7 +4,6 @@
#include "gui/interface/Textbox.h"
#include "gui/interface/Button.h"
#include "gui/interface/Checkbox.h"
#include "client/requestbroker/RequestBroker.h"
#include "gui/dialogues/ErrorMessage.h"
#include "gui/dialogues/SaveIDMessage.h"
#include "gui/dialogues/ConfirmPrompt.h"
@@ -14,6 +13,7 @@
#include "gui/Style.h"
#include "client/GameSave.h"
#include "images.h"
#include "client/ThumbnailRenderer.h"

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

ServerSaveActivity::ServerSaveActivity(SaveInfo save, ServerSaveActivity::SaveUploadedCallback * callback) :
WindowActivity(ui::Point(-1, -1), ui::Point(440, 200)),
thumbnail(NULL),
save(save),
callback(callback),
saveUploadTask(NULL)
@@ -183,13 +182,15 @@ ServerSaveActivity::ServerSaveActivity(SaveInfo save, ServerSaveActivity::SaveUp
RulesButton->SetActionCallback(new RulesAction(this));
AddComponent(RulesButton);

if(save.GetGameSave())
RequestBroker::Ref().RenderThumbnail(save.GetGameSave(), false, true, (Size.X/2)-16, -1, false, this);
if (save.GetGameSave())
{
thumbnailRenderer = std::unique_ptr<ThumbnailRendererTask>(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)),
thumbnail(NULL),
save(save),
callback(callback),
saveUploadTask(NULL)
@@ -401,6 +402,16 @@ void ServerSaveActivity::CheckName(String newname)

void ServerSaveActivity::OnTick(float dt)
{
if (thumbnailRenderer)
{
thumbnailRenderer->Poll();
if (thumbnailRenderer->GetDone())
{
thumbnail = thumbnailRenderer->GetThumbnail();
thumbnailRenderer.reset();
}
}

if(saveUploadTask)
saveUploadTask->Poll();
}
@@ -417,21 +428,13 @@ void ServerSaveActivity::OnDraw()

if(thumbnail)
{
g->draw_image(thumbnail, Position.X+(Size.X/2)+((Size.X/2)-thumbnail->Width)/2, Position.Y+25, 255);
g->draw_image(thumbnail.get(), Position.X+(Size.X/2)+((Size.X/2)-thumbnail->Width)/2, Position.Y+25, 255);
g->drawrect(Position.X+(Size.X/2)+((Size.X/2)-thumbnail->Width)/2, Position.Y+25, thumbnail->Width, thumbnail->Height, 180, 180, 180, 255);
}
}

void ServerSaveActivity::OnResponseReady(void * imagePtr, int identifier)
{
delete thumbnail;
thumbnail = (VideoBuffer *)imagePtr;
}

ServerSaveActivity::~ServerSaveActivity()
{
RequestBroker::Ref().DetachRequestListener(this);
delete saveUploadTask;
delete callback;
delete thumbnail;
}
@@ -2,19 +2,21 @@

#include "Activity.h"
#include "client/SaveInfo.h"
#include "client/requestbroker/RequestListener.h"
#include "tasks/TaskListener.h"

#include <memory>

namespace ui
{
class Label;
class Textbox;
class Checkbox;
}

class ThumbnailRendererTask;
class Task;
class VideoBuffer;
class ServerSaveActivity: public WindowActivity, public RequestListener, public TaskListener
class ServerSaveActivity: public WindowActivity, public TaskListener
{
public:
class SaveUploadedCallback
@@ -33,13 +35,13 @@ class ServerSaveActivity: public WindowActivity, public RequestListener, public
virtual void ShowRules();
virtual void CheckName(String newname);
virtual void OnDraw();
virtual void OnResponseReady(void * imagePtr, int identifier);
virtual void OnTick(float dt);
virtual ~ServerSaveActivity();
protected:
void AddAuthorInfo();
virtual void NotifyDone(Task * task);
VideoBuffer * thumbnail;
std::unique_ptr<ThumbnailRendererTask> thumbnailRenderer;
std::unique_ptr<VideoBuffer> thumbnail;
SaveInfo save;
SaveUploadedCallback * callback;
Task * saveUploadTask;

0 comments on commit 66c4920

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.