mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-29 19:00:33 +02:00
Use the new thumbnail renderer task everywhere
This commit is contained in:
committed by
jacob1
parent
3a76a3a514
commit
66c49203f2
@@ -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)
|
void RequestBroker::Start(Request * request, RequestListener * tListener, int identifier)
|
||||||
{
|
{
|
||||||
ListenerHandle handle = AttachRequestListener(tListener);
|
ListenerHandle handle = AttachRequestListener(tListener);
|
||||||
@@ -121,19 +90,6 @@ void RequestBroker::Start(Request * request, RequestListener * tListener, int id
|
|||||||
assureRunning();
|
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)
|
TH_ENTRY_POINT void * RequestBroker::thumbnailQueueProcessHelper(void * ref)
|
||||||
{
|
{
|
||||||
((RequestBroker*)ref)->thumbnailQueueProcessTH();
|
((RequestBroker*)ref)->thumbnailQueueProcessTH();
|
||||||
@@ -243,12 +199,6 @@ void RequestBroker::requestComplete(Request * completedRequest)
|
|||||||
pthread_mutex_unlock(&completeQueueMutex);
|
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)
|
bool RequestBroker::CheckRequestListener(ListenerHandle handle)
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&listenersMutex);
|
pthread_mutex_lock(&listenersMutex);
|
||||||
|
@@ -51,11 +51,6 @@ public:
|
|||||||
void Shutdown();
|
void Shutdown();
|
||||||
|
|
||||||
void FlushThumbQueue();
|
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);
|
void Start(Request * request, RequestListener * tLIstener, int identifier = 0);
|
||||||
|
|
||||||
bool CheckRequestListener(ListenerHandle handle);
|
bool CheckRequestListener(ListenerHandle handle);
|
||||||
|
@@ -6,12 +6,12 @@
|
|||||||
#include "graphics/Graphics.h"
|
#include "graphics/Graphics.h"
|
||||||
#include "gui/Style.h"
|
#include "gui/Style.h"
|
||||||
|
|
||||||
#include "client/requestbroker/RequestBroker.h"
|
|
||||||
#include "gui/dialogues/ConfirmPrompt.h"
|
#include "gui/dialogues/ConfirmPrompt.h"
|
||||||
#include "gui/dialogues/ErrorMessage.h"
|
#include "gui/dialogues/ErrorMessage.h"
|
||||||
#include "gui/interface/Button.h"
|
#include "gui/interface/Button.h"
|
||||||
#include "gui/interface/Label.h"
|
#include "gui/interface/Label.h"
|
||||||
#include "gui/interface/Textbox.h"
|
#include "gui/interface/Textbox.h"
|
||||||
|
#include "client/ThumbnailRenderer.h"
|
||||||
|
|
||||||
|
|
||||||
class LocalSaveActivity::CancelAction: public ui::ButtonAction
|
class LocalSaveActivity::CancelAction: public ui::ButtonAction
|
||||||
@@ -39,7 +39,6 @@ public:
|
|||||||
LocalSaveActivity::LocalSaveActivity(SaveFile save, FileSavedCallback * callback) :
|
LocalSaveActivity::LocalSaveActivity(SaveFile save, FileSavedCallback * callback) :
|
||||||
WindowActivity(ui::Point(-1, -1), ui::Point(220, 200)),
|
WindowActivity(ui::Point(-1, -1), ui::Point(220, 200)),
|
||||||
save(save),
|
save(save),
|
||||||
thumbnail(NULL),
|
|
||||||
callback(callback)
|
callback(callback)
|
||||||
{
|
{
|
||||||
ui::Label * titleLabel = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 16), "Save to computer:");
|
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);
|
SetOkayButton(okayButton);
|
||||||
|
|
||||||
if(save.GetGameSave())
|
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()
|
void LocalSaveActivity::Save()
|
||||||
@@ -146,20 +161,12 @@ void LocalSaveActivity::OnDraw()
|
|||||||
|
|
||||||
if(thumbnail)
|
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);
|
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()
|
LocalSaveActivity::~LocalSaveActivity()
|
||||||
{
|
{
|
||||||
RequestBroker::Ref().DetachRequestListener(this);
|
|
||||||
delete thumbnail;
|
|
||||||
delete callback;
|
delete callback;
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
#include "Activity.h"
|
#include "Activity.h"
|
||||||
#include "client/SaveFile.h"
|
#include "client/SaveFile.h"
|
||||||
#include "client/requestbroker/RequestListener.h"
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace ui
|
namespace ui
|
||||||
{
|
{
|
||||||
@@ -11,6 +12,7 @@ namespace ui
|
|||||||
|
|
||||||
class VideoBuffer;
|
class VideoBuffer;
|
||||||
|
|
||||||
|
class ThumbnailRendererTask;
|
||||||
class FileSavedCallback
|
class FileSavedCallback
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -19,10 +21,11 @@ public:
|
|||||||
virtual void FileSaved(SaveFile * file) {}
|
virtual void FileSaved(SaveFile * file) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class LocalSaveActivity: public WindowActivity, public RequestListener
|
class LocalSaveActivity: public WindowActivity
|
||||||
{
|
{
|
||||||
SaveFile save;
|
SaveFile save;
|
||||||
VideoBuffer * thumbnail;
|
std::unique_ptr<ThumbnailRendererTask> thumbnailRenderer;
|
||||||
|
std::unique_ptr<VideoBuffer> thumbnail;
|
||||||
ui::Textbox * filenameField;
|
ui::Textbox * filenameField;
|
||||||
class CancelAction;
|
class CancelAction;
|
||||||
class SaveAction;
|
class SaveAction;
|
||||||
@@ -34,6 +37,6 @@ public:
|
|||||||
void saveWrite(ByteString finalFilename);
|
void saveWrite(ByteString finalFilename);
|
||||||
virtual void Save();
|
virtual void Save();
|
||||||
virtual void OnDraw();
|
virtual void OnDraw();
|
||||||
virtual void OnResponseReady(void * imagePtr, int identifier);
|
virtual void OnTick(float dt);
|
||||||
virtual ~LocalSaveActivity();
|
virtual ~LocalSaveActivity();
|
||||||
};
|
};
|
||||||
|
@@ -4,7 +4,6 @@
|
|||||||
#include "gui/interface/Textbox.h"
|
#include "gui/interface/Textbox.h"
|
||||||
#include "gui/interface/Button.h"
|
#include "gui/interface/Button.h"
|
||||||
#include "gui/interface/Checkbox.h"
|
#include "gui/interface/Checkbox.h"
|
||||||
#include "client/requestbroker/RequestBroker.h"
|
|
||||||
#include "gui/dialogues/ErrorMessage.h"
|
#include "gui/dialogues/ErrorMessage.h"
|
||||||
#include "gui/dialogues/SaveIDMessage.h"
|
#include "gui/dialogues/SaveIDMessage.h"
|
||||||
#include "gui/dialogues/ConfirmPrompt.h"
|
#include "gui/dialogues/ConfirmPrompt.h"
|
||||||
@@ -14,6 +13,7 @@
|
|||||||
#include "gui/Style.h"
|
#include "gui/Style.h"
|
||||||
#include "client/GameSave.h"
|
#include "client/GameSave.h"
|
||||||
#include "images.h"
|
#include "images.h"
|
||||||
|
#include "client/ThumbnailRenderer.h"
|
||||||
|
|
||||||
class ServerSaveActivity::CancelAction: public ui::ButtonAction
|
class ServerSaveActivity::CancelAction: public ui::ButtonAction
|
||||||
{
|
{
|
||||||
@@ -104,7 +104,6 @@ public:
|
|||||||
|
|
||||||
ServerSaveActivity::ServerSaveActivity(SaveInfo save, ServerSaveActivity::SaveUploadedCallback * callback) :
|
ServerSaveActivity::ServerSaveActivity(SaveInfo save, ServerSaveActivity::SaveUploadedCallback * callback) :
|
||||||
WindowActivity(ui::Point(-1, -1), ui::Point(440, 200)),
|
WindowActivity(ui::Point(-1, -1), ui::Point(440, 200)),
|
||||||
thumbnail(NULL),
|
|
||||||
save(save),
|
save(save),
|
||||||
callback(callback),
|
callback(callback),
|
||||||
saveUploadTask(NULL)
|
saveUploadTask(NULL)
|
||||||
@@ -183,13 +182,15 @@ ServerSaveActivity::ServerSaveActivity(SaveInfo save, ServerSaveActivity::SaveUp
|
|||||||
RulesButton->SetActionCallback(new RulesAction(this));
|
RulesButton->SetActionCallback(new RulesAction(this));
|
||||||
AddComponent(RulesButton);
|
AddComponent(RulesButton);
|
||||||
|
|
||||||
if(save.GetGameSave())
|
if (save.GetGameSave())
|
||||||
RequestBroker::Ref().RenderThumbnail(save.GetGameSave(), false, true, (Size.X/2)-16, -1, false, this);
|
{
|
||||||
|
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) :
|
ServerSaveActivity::ServerSaveActivity(SaveInfo save, bool saveNow, ServerSaveActivity::SaveUploadedCallback * callback) :
|
||||||
WindowActivity(ui::Point(-1, -1), ui::Point(200, 50)),
|
WindowActivity(ui::Point(-1, -1), ui::Point(200, 50)),
|
||||||
thumbnail(NULL),
|
|
||||||
save(save),
|
save(save),
|
||||||
callback(callback),
|
callback(callback),
|
||||||
saveUploadTask(NULL)
|
saveUploadTask(NULL)
|
||||||
@@ -401,6 +402,16 @@ void ServerSaveActivity::CheckName(String newname)
|
|||||||
|
|
||||||
void ServerSaveActivity::OnTick(float dt)
|
void ServerSaveActivity::OnTick(float dt)
|
||||||
{
|
{
|
||||||
|
if (thumbnailRenderer)
|
||||||
|
{
|
||||||
|
thumbnailRenderer->Poll();
|
||||||
|
if (thumbnailRenderer->GetDone())
|
||||||
|
{
|
||||||
|
thumbnail = thumbnailRenderer->GetThumbnail();
|
||||||
|
thumbnailRenderer.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(saveUploadTask)
|
if(saveUploadTask)
|
||||||
saveUploadTask->Poll();
|
saveUploadTask->Poll();
|
||||||
}
|
}
|
||||||
@@ -417,21 +428,13 @@ void ServerSaveActivity::OnDraw()
|
|||||||
|
|
||||||
if(thumbnail)
|
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);
|
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()
|
ServerSaveActivity::~ServerSaveActivity()
|
||||||
{
|
{
|
||||||
RequestBroker::Ref().DetachRequestListener(this);
|
|
||||||
delete saveUploadTask;
|
delete saveUploadTask;
|
||||||
delete callback;
|
delete callback;
|
||||||
delete thumbnail;
|
|
||||||
}
|
}
|
||||||
|
@@ -2,9 +2,10 @@
|
|||||||
|
|
||||||
#include "Activity.h"
|
#include "Activity.h"
|
||||||
#include "client/SaveInfo.h"
|
#include "client/SaveInfo.h"
|
||||||
#include "client/requestbroker/RequestListener.h"
|
|
||||||
#include "tasks/TaskListener.h"
|
#include "tasks/TaskListener.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace ui
|
namespace ui
|
||||||
{
|
{
|
||||||
class Label;
|
class Label;
|
||||||
@@ -12,9 +13,10 @@ namespace ui
|
|||||||
class Checkbox;
|
class Checkbox;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ThumbnailRendererTask;
|
||||||
class Task;
|
class Task;
|
||||||
class VideoBuffer;
|
class VideoBuffer;
|
||||||
class ServerSaveActivity: public WindowActivity, public RequestListener, public TaskListener
|
class ServerSaveActivity: public WindowActivity, public TaskListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
class SaveUploadedCallback
|
class SaveUploadedCallback
|
||||||
@@ -33,13 +35,13 @@ public:
|
|||||||
virtual void ShowRules();
|
virtual void ShowRules();
|
||||||
virtual void CheckName(String newname);
|
virtual void CheckName(String newname);
|
||||||
virtual void OnDraw();
|
virtual void OnDraw();
|
||||||
virtual void OnResponseReady(void * imagePtr, int identifier);
|
|
||||||
virtual void OnTick(float dt);
|
virtual void OnTick(float dt);
|
||||||
virtual ~ServerSaveActivity();
|
virtual ~ServerSaveActivity();
|
||||||
protected:
|
protected:
|
||||||
void AddAuthorInfo();
|
void AddAuthorInfo();
|
||||||
virtual void NotifyDone(Task * task);
|
virtual void NotifyDone(Task * task);
|
||||||
VideoBuffer * thumbnail;
|
std::unique_ptr<ThumbnailRendererTask> thumbnailRenderer;
|
||||||
|
std::unique_ptr<VideoBuffer> thumbnail;
|
||||||
SaveInfo save;
|
SaveInfo save;
|
||||||
SaveUploadedCallback * callback;
|
SaveUploadedCallback * callback;
|
||||||
Task * saveUploadTask;
|
Task * saveUploadTask;
|
||||||
|
Reference in New Issue
Block a user