minor adjustments to libengine, moc is correctly created as definitions are set before calling it, params are better numbered and we don't subclass qthread but rather use moveToThread()
--- a/QTfrontend/CMakeLists.txt Mon Dec 17 00:43:52 2012 +0100
+++ b/QTfrontend/CMakeLists.txt Tue Dec 18 03:07:45 2012 +0100
@@ -136,6 +136,12 @@
set(hwfr_rez hedgewars.qrc)
+if(BUILD_ENGINE_LIBRARY)
+ add_definitions(-DHWLIBRARY)
+ set(HW_LINK_LIBS hwengine ${HW_LINK_LIBS})
+ link_directories(${EXECUTABLE_OUTPUT_PATH})
+endif()
+
qt4_add_resources(hwfr_rez_src ${hwfr_rez})
qt4_wrap_cpp(hwfr_moc_srcs ${hwfr_moc_hdrs})
@@ -160,12 +166,6 @@
endif()
endif()
-if(BUILD_ENGINE_LIBRARY)
- add_definitions(-DHWLIBRARY)
- set(HW_LINK_LIBS hwengine ${HW_LINK_LIBS})
- link_directories(${EXECUTABLE_OUTPUT_PATH})
-endif()
-
#when debugging, always prompt a console to see fronted messages
#TODO: check it doesn't interfere on UNIX
if(CMAKE_BUILD_TYPE MATCHES "RELEASE")
--- a/QTfrontend/net/tcpBase.cpp Mon Dec 17 00:43:52 2012 +0100
+++ b/QTfrontend/net/tcpBase.cpp Tue Dec 18 03:07:45 2012 +0100
@@ -29,31 +29,39 @@
#ifdef HWLIBRARY
extern "C" void Game(char**arguments);
+extern "C" void GenLandPreview(int port);
-//NOTE: most likely subclassing QThread is wrong
-class EngineThread : public QThread
+
+EngineInstance::EngineInstance(QObject *parent)
+ : QObject(parent)
{
-protected:
- void run();
-};
+ port = 0;
+}
-void EngineThread::run()
+EngineInstance::~EngineInstance()
+{
+}
+
+void EngineInstance::start()
{
- char *args[12];
- args[0] = "1"; //cShowFPS
- args[1] = "65000"; //ipcPort
- args[2] = "1024"; //cScreenWidth
- args[3] = "768"; //cScreenHeight
- args[4] = "0"; //cReducedQuality
- args[5] = "en.txt"; //cLocaleFName
- args[6] = "koda"; //UserNick
- args[7] = "1"; //SetSound
- args[8] = "1"; //SetMusic
- args[9] = "0"; //cAltDamage
- args[10]= "../Resources/hedgewars/Data"; //cPathPrefix
- args[11]= NULL; //recordFileName
+#if 0
+ char *args[11];
+ args[0] = "65000"; //ipcPort
+ args[1] = "1024"; //cScreenWidth
+ args[2] = "768"; //cScreenHeight
+ args[3] = "0"; //cReducedQuality
+ args[4] = "en.txt"; //cLocaleFName
+ args[5] = "koda"; //UserNick
+ args[6] = "1"; //SetSound
+ args[7] = "1"; //SetMusic
+ args[8] = "0"; //cAltDamage
+ args[9]= datadir->absolutePath().toAscii().data(); //cPathPrefix
+ args[10]= NULL; //recordFileName
Game(args);
+#endif
+ GenLandPreview(port);
}
+
#endif
QList<TCPBase*> srvsList;
@@ -66,6 +74,7 @@
if (IPCSocket)
IPCSocket->deleteLater();
+
}
TCPBase::TCPBase(bool demoMode, QObject *parent) :
@@ -90,11 +99,8 @@
exit(0); // FIXME - should be graceful exit here (lower Critical -> Warning above when implemented)
}
}
-#ifdef HWLIBRARY
- ipc_port=65000; //HACK
-#else
+
ipc_port=IPCServer->serverPort();
-#endif
}
void TCPBase::NewConnection()
@@ -118,8 +124,17 @@
IPCSocket = 0;
#ifdef HWLIBRARY
- EngineThread engineThread;// = new EngineThread(this);
- engineThread.start();
+ QThread *thread = new QThread;
+ EngineInstance *instance = new EngineInstance;
+ instance->port = IPCServer->serverPort();
+
+ instance->moveToThread(thread);
+
+ connect(thread, SIGNAL(started()), instance, SLOT(start(void)));
+ connect(instance, SIGNAL(finished()), thread, SLOT(quit()));
+ connect(instance, SIGNAL(finished()), instance, SLOT(deleteLater()));
+ connect(instance, SIGNAL(finished()), thread, SLOT(deleteLater()));
+ thread->start();
#else
QProcess * process;
process = new QProcess();
--- a/QTfrontend/net/tcpBase.h Mon Dec 17 00:43:52 2012 +0100
+++ b/QTfrontend/net/tcpBase.h Tue Dec 18 03:07:45 2012 +0100
@@ -81,4 +81,21 @@
void tcpServerReady();
};
+#ifdef HWLIBRARY
+class EngineInstance : public QObject
+{
+ Q_OBJECT
+public:
+ EngineInstance(QObject *parent = 0);
+ ~EngineInstance();
+
+ int port;
+public slots:
+ void start(void);
+signals:
+ void finished(void);
+private:
+};
+#endif
+
#endif // _TCPBASE_INCLUDED
--- a/hedgewars/hwengine.pas Mon Dec 17 00:43:52 2012 +0100
+++ b/hedgewars/hwengine.pas Tue Dec 18 03:07:45 2012 +0100
@@ -338,11 +338,12 @@
SetMusic(gameArgs[7] = '1');
cAltDamage:= gameArgs[8] = '1';
PathPrefix:= gameArgs[9];
+{$IFDEF IPHONEOS}
UserPathPrefix:= '../Documents';
+{$ENDIF}
recordFileName:= gameArgs[10];
{$ENDIF}
initEverything(true);
-
WriteLnToConsole('Hedgewars ' + cVersionString + ' engine (network protocol: ' + inttostr(cNetProtoVersion) + ')');
AddFileLog('Prefix: "' + PathPrefix +'"');
AddFileLog('UserPrefix: "' + UserPathPrefix +'"');
--- a/hedgewars/uPhysFSLayer.pas Mon Dec 17 00:43:52 2012 +0100
+++ b/hedgewars/uPhysFSLayer.pas Tue Dec 18 03:07:45 2012 +0100
@@ -40,7 +40,7 @@
procedure physfsReaderSetBuffer(buf: pointer); cdecl; external PhysfsLibName;
implementation
-uses uUtils, uVariables;
+uses uUtils, uVariables, sysutils;
function PHYSFS_init(argv0: PChar) : LongInt; cdecl; external PhysfsLibName;
function PHYSFS_deinit() : LongInt; cdecl; external PhysfsLibName;
@@ -135,8 +135,16 @@
procedure initModule;
var i: LongInt;
+ cPhysfsId: shortstring;
begin
- i:= PHYSFS_init(Str2PChar(ParamStr(0)));
+{$IFDEF HWLIBRARY}
+ //TODO: http://icculus.org/pipermail/physfs/2011-August/001006.html
+ cPhysfsId:= GetCurrentDir() + {$IFDEF DARWIN}'/Hedgewars.app/Contents/MacOS/' + {$ENDIF} ' hedgewars';
+{$ELSE}
+ cPhysfsId:= ParamStr(0);
+{$ENDIF}
+
+ i:= PHYSFS_init(Str2PChar(cPhysfsId));
AddFileLog('[PhysFS] init: ' + inttostr(i));
i:= PHYSFS_mount(Str2PChar(PathPrefix), nil, true);