2013-11-22 22:50:14 +09:00
|
|
|
/*
|
|
|
|
Copyright (c) 2013 yvt
|
|
|
|
|
|
|
|
This file is part of OpenSpades.
|
|
|
|
|
|
|
|
OpenSpades is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
OpenSpades is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with OpenSpades. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Runner.h"
|
|
|
|
#include "View.h"
|
|
|
|
#include "SDLRunner.h"
|
|
|
|
#include "SDLAsyncRunner.h"
|
|
|
|
#include "ErrorDialog.h"
|
|
|
|
#include <Core/Settings.h>
|
2014-02-06 22:51:07 +09:00
|
|
|
#include <Core/Exception.h>
|
2013-11-22 22:50:14 +09:00
|
|
|
|
|
|
|
SPADES_SETTING(cg_smp, "0");
|
2014-02-06 22:51:07 +09:00
|
|
|
SPADES_SETTING(r_videoWidth, "1024");
|
|
|
|
SPADES_SETTING(r_videoHeight, "640");
|
2013-11-22 22:50:14 +09:00
|
|
|
|
|
|
|
namespace spades {
|
|
|
|
namespace gui {
|
2014-02-06 22:51:07 +09:00
|
|
|
Runner::Runner():
|
|
|
|
m_videoWidth(r_videoWidth),
|
|
|
|
m_videoHeight(r_videoHeight){
|
|
|
|
if(m_videoWidth < 1 || m_videoWidth > 16384)
|
|
|
|
SPRaise("Value of r_videoWidth is invalid.");
|
|
|
|
if(m_videoHeight < 1 || m_videoHeight > 16384)
|
|
|
|
SPRaise("Value of r_videoHeight is invalid.");
|
2013-11-22 22:50:14 +09:00
|
|
|
}
|
|
|
|
Runner::~Runner() {
|
|
|
|
|
|
|
|
}
|
2013-12-15 21:51:00 +09:00
|
|
|
|
2013-11-22 22:50:14 +09:00
|
|
|
void Runner::RunProtected() {
|
2013-11-23 02:50:02 +09:00
|
|
|
SPADES_MARK_FUNCTION();
|
2013-11-22 22:50:14 +09:00
|
|
|
std::string err;
|
|
|
|
try{
|
|
|
|
Run();
|
|
|
|
}catch(const spades::Exception& ex){
|
|
|
|
err = ex.GetShortMessage();
|
|
|
|
SPLog("Unhandled exception in SDLRunner:\n%s", ex.what());
|
|
|
|
}catch(const std::exception& ex){
|
|
|
|
err = ex.what();
|
|
|
|
SPLog("Unhandled exception in SDLRunner:\n%s", ex.what());
|
|
|
|
}
|
|
|
|
if(!err.empty()){
|
|
|
|
ErrorDialog dlg;
|
|
|
|
dlg.set_modal();
|
|
|
|
dlg.result = 0;
|
|
|
|
|
|
|
|
// TODO: free this buffer (just leaking)
|
|
|
|
Fl_Text_Buffer *buf = new Fl_Text_Buffer;
|
|
|
|
buf->append(err.c_str());
|
|
|
|
dlg.infoView->wrap_mode(Fl_Text_Display::WRAP_AT_BOUNDS, 0);
|
|
|
|
dlg.infoView->buffer(buf);
|
|
|
|
dlg.helpView->value("See SystemMessages.log for more details.");
|
|
|
|
dlg.show();
|
|
|
|
while(dlg.visible()){
|
|
|
|
Fl::wait();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void Runner::Run() {
|
2013-11-23 02:50:02 +09:00
|
|
|
SPADES_MARK_FUNCTION();
|
2013-11-22 22:50:14 +09:00
|
|
|
class ConcreteRunner: public SDLRunner {
|
|
|
|
Runner *r;
|
|
|
|
protected:
|
|
|
|
virtual View *CreateView(client::IRenderer *renderer, client::IAudioDevice *dev) {
|
|
|
|
return r->CreateView(renderer, dev);
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
ConcreteRunner(Runner *r): r(r){ }
|
|
|
|
};
|
|
|
|
class ConcreteAsnycRunner: public SDLAsyncRunner {
|
|
|
|
Runner *r;
|
|
|
|
protected:
|
|
|
|
virtual View *CreateView(client::IRenderer *renderer, client::IAudioDevice *dev) {
|
|
|
|
return r->CreateView(renderer, dev);
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
ConcreteAsnycRunner(Runner *r): r(r){ }
|
|
|
|
};
|
|
|
|
|
|
|
|
if(cg_smp){
|
|
|
|
ConcreteAsnycRunner r(this);
|
2014-02-06 22:51:07 +09:00
|
|
|
r.Run(m_videoWidth, m_videoHeight);
|
2013-11-22 22:50:14 +09:00
|
|
|
}else{
|
|
|
|
ConcreteRunner r(this);
|
2014-02-06 22:51:07 +09:00
|
|
|
r.Run(m_videoWidth, m_videoHeight);
|
2013-11-22 22:50:14 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2014-02-06 22:51:07 +09:00
|
|
|
|
|
|
|
void Runner::OverrideVideoSize(int width, int height) {
|
|
|
|
if(width < 1 || width > 16384)
|
|
|
|
SPInvalidArgument("width");
|
|
|
|
if(height < 1 || height > 16384)
|
|
|
|
SPInvalidArgument("height");
|
|
|
|
m_videoWidth = width;
|
|
|
|
m_videoHeight = height;
|
|
|
|
}
|
2013-11-22 22:50:14 +09:00
|
|
|
}
|
|
|
|
}
|