--- a/hedgewars/hwLibrary.pas Sun Sep 28 00:49:04 2014 +0400
+++ b/hedgewars/hwLibrary.pas Sun Sep 28 01:17:55 2014 +0400
@@ -47,66 +47,66 @@
{$INCLUDE "config.inc"}
// retrieve protocol information
-procedure HW_versionInfo(netProto: PLongInt; versionStr: PPChar); cdecl; export;
+procedure HW_versionInfo(netProto: PLongInt; versionStr: PPChar); cdecl;
begin
netProto^:= cNetProtoVersion;
versionStr^:= cVersionString;
end;
-function HW_versionString: PChar; cdecl; export;
+function HW_versionString: PChar; cdecl;
begin
exit(cVersionString + '-r' + cRevisionString + ' (' + cHashString + ')');
end;
// equivalent to esc+y; when closeFrontend = true the game exits after memory cleanup
-procedure HW_terminate(closeFrontend: boolean); cdecl; export;
+procedure HW_terminate(closeFrontend: boolean); cdecl;
begin
closeFrontend:= closeFrontend; // avoid hint
ParseCommand('forcequit', true);
end;
-function HW_getWeaponNameByIndex(whichone: LongInt): PChar; cdecl; export;
+function HW_getWeaponNameByIndex(whichone: LongInt): PChar; cdecl;
begin
HW_getWeaponNameByIndex:= (str2pchar(trammo[Ammoz[TAmmoType(whichone+1)].NameId]));
end;
-(*function HW_getWeaponCaptionByIndex(whichone: LongInt): PChar; cdecl; export;
+(*function HW_getWeaponCaptionByIndex(whichone: LongInt): PChar; cdecl;
begin
HW_getWeaponCaptionByIndex:= (str2pchar(trammoc[Ammoz[TAmmoType(whichone+1)].NameId]));
end;
-function HW_getWeaponDescriptionByIndex(whichone: LongInt): PChar; cdecl; export;
+function HW_getWeaponDescriptionByIndex(whichone: LongInt): PChar; cdecl;
begin
HW_getWeaponDescriptionByIndex:= (str2pchar(trammod[Ammoz[TAmmoType(whichone+1)].NameId]));
end;*)
-function HW_getNumberOfWeapons: LongInt; cdecl; export;
+function HW_getNumberOfWeapons: LongInt; cdecl;
begin
HW_getNumberOfWeapons:= ord(high(TAmmoType));
end;
-function HW_getMaxNumberOfHogs: LongInt; cdecl; export;
+function HW_getMaxNumberOfHogs: LongInt; cdecl;
begin
HW_getMaxNumberOfHogs:= cMaxHHIndex + 1;
end;
-function HW_getMaxNumberOfTeams: LongInt; cdecl; export;
+function HW_getMaxNumberOfTeams: LongInt; cdecl;
begin
HW_getMaxNumberOfTeams:= cMaxTeams;
end;
-procedure HW_memoryWarningCallback; cdecl; export;
+procedure HW_memoryWarningCallback; cdecl;
begin
ReleaseSound(false);
end;
-procedure flibInit(localPrefix, userPrefix: PChar); cdecl; export;
+procedure flibInit(localPrefix, userPrefix: PChar); cdecl;
begin
initIPC;
uPhysFSLayer.initModule(localPrefix, userPrefix);
end;
-procedure flibFree; cdecl; export;
+procedure flibFree; cdecl;
begin
uPhysFSLayer.freemodule;
freeIPC;
@@ -149,6 +149,8 @@
registerGUIMessagesCallback,
flibInit,
flibFree,
+ setSeed,
+ getSeed,
LoadLocaleWrapper,
HW_versionInfo,
HW_versionString,
--- a/hedgewars/uFLGameConfig.pas Sun Sep 28 00:49:04 2014 +0400
+++ b/hedgewars/uFLGameConfig.pas Sun Sep 28 01:17:55 2014 +0400
@@ -2,11 +2,14 @@
interface
uses uFLTypes;
-procedure resetGameConfig; cdecl; export;
-procedure runQuickGame; cdecl; export;
-procedure getPreview; cdecl; export;
+procedure resetGameConfig; cdecl;
+procedure runQuickGame; cdecl;
+procedure getPreview; cdecl;
-procedure registerGUIMessagesCallback(p: pointer; f: TGUICallback); cdecl; export;
+procedure registerGUIMessagesCallback(p: pointer; f: TGUICallback); cdecl;
+
+procedure setSeed(seed: PChar); cdecl;
+function getSeed: PChar; cdecl;
implementation
uses uFLIPC, hwengine;
@@ -48,6 +51,18 @@
PGameConfig = ^TGameConfig;
var currentConfig: TGameConfig;
+ str2PCharBuffer: array[0..255] of char;
+
+function str2PChar(const s: shortstring): PChar;
+var i: Integer;
+begin
+ for i:= 1 to Length(s) do
+ begin
+ str2PCharBuffer[i - 1] := s[i];
+ end;
+ str2PCharBuffer[Length(s)]:= #0;
+ str2PChar:= @(str2PCharBuffer[0]);
+end;
procedure queueExecution;
var pConfig: PGameConfig;
@@ -73,12 +88,22 @@
begin
end;
-procedure runQuickGame; cdecl; export;
+procedure setSeed(seed: PChar); cdecl;
+begin
+ currentConfig.seed:= seed
+end;
+
+function getSeed: PChar; cdecl;
+begin
+ getSeed:= str2PChar(currentConfig.seed)
+end;
+
+procedure runQuickGame; cdecl;
begin
end;
-procedure getPreview; cdecl; export;
+procedure getPreview; cdecl;
begin
with currentConfig do
begin
@@ -101,7 +126,7 @@
if len = 128 * 256 then guiCallbackFunction(guiCallbackPointer, mtPreview, msg, len)
end;
-procedure registerGUIMessagesCallback(p: pointer; f: TGUICallback); cdecl; export;
+procedure registerGUIMessagesCallback(p: pointer; f: TGUICallback); cdecl;
begin
guiCallbackPointer:= p;
guiCallbackFunction:= f;
--- a/hedgewars/uFLTypes.pas Sun Sep 28 00:49:04 2014 +0400
+++ b/hedgewars/uFLTypes.pas Sun Sep 28 01:17:55 2014 +0400
@@ -10,7 +10,7 @@
buf: Pointer
end;
TIPCCallback = procedure (p: pointer; msg: PChar; len: Longword);
- TGUICallback = procedure (p: pointer; msgType: TMessageType; msg: PChar; len: Longword);
+ TGUICallback = procedure (p: pointer; msgType: TMessageType; msg: PChar; len: Longword); cdecl;
implementation
--- a/hedgewars/uUtils.pas Sun Sep 28 00:49:04 2014 +0400
+++ b/hedgewars/uUtils.pas Sun Sep 28 01:17:55 2014 +0400
@@ -313,7 +313,7 @@
function Str2PChar(const s: shortstring): PChar;
-var i :Integer ;
+var i: Integer;
begin
for i:= 1 to Length(s) do
begin
--- a/qmlFrontend/flib.h Sun Sep 28 00:49:04 2014 +0400
+++ b/qmlFrontend/flib.h Sun Sep 28 01:17:55 2014 +0400
@@ -24,8 +24,10 @@
typedef void RunEngine_t(int argc, const char ** argv);
typedef void registerGUIMessagesCallback_t(void * context, void (*)(void * context, MessageType mt, const char * msg, uint32_t len));
+typedef void getPreview_t();
+typedef void setSeed_t(const char * seed);
+typedef char *getSeed_t();
typedef void flibInit_t(const char * localPrefix, const char * userPrefix);
-typedef void getPreview_t();
typedef void flibFree_t();
#ifdef __cplusplus
--- a/qmlFrontend/hwengine.cpp Sun Sep 28 00:49:04 2014 +0400
+++ b/qmlFrontend/hwengine.cpp Sun Sep 28 01:17:55 2014 +0400
@@ -10,15 +10,21 @@
extern "C" {
RunEngine_t *flibRunEngine;
registerGUIMessagesCallback_t *flibRegisterGUIMessagesCallback;
+ setSeed_t *flibSetSeed;
+ getSeed_t *flibGetSeed;
getPreview_t *flibGetPreview;
flibInit_t *flibInit;
flibFree_t *flibFree;
}
+Q_DECLARE_METATYPE(MessageType);
+
HWEngine::HWEngine(QQmlEngine *engine, QObject *parent) :
QObject(parent),
m_engine(engine)
{
+ qRegisterMetaType<MessageType>("MessageType");
+
QLibrary hwlib("./libhwengine.so");
if(!hwlib.load())
@@ -26,6 +32,8 @@
flibRunEngine = (RunEngine_t*) hwlib.resolve("RunEngine");
flibRegisterGUIMessagesCallback = (registerGUIMessagesCallback_t*) hwlib.resolve("registerGUIMessagesCallback");
+ flibSetSeed = (setSeed_t*) hwlib.resolve("setSeed");
+ flibGetSeed = (getSeed_t*) hwlib.resolve("getSeed");
flibGetPreview = (getPreview_t*) hwlib.resolve("getPreview");
flibInit = (flibInit_t*) hwlib.resolve("flibInit");
flibFree = (flibFree_t*) hwlib.resolve("flibFree");
@@ -41,7 +49,7 @@
void HWEngine::getPreview()
{
- //m_seed = QUuid::createUuid().toString();
+ flibSetSeed(QUuid::createUuid().toString().toLatin1());
flibGetPreview();
}
@@ -67,20 +75,22 @@
qDebug() << "FLIPC in" << b.size() << b;
- QMetaObject::invokeMethod(obj, "engineMessageHandler", Qt::QueuedConnection, Q_ARG(QByteArray, b));
+ QMetaObject::invokeMethod(obj, "engineMessageHandler", Qt::QueuedConnection, Q_ARG(MessageType, mt), Q_ARG(QByteArray, b));
}
-void HWEngine::engineMessageHandler(const QByteArray &msg)
+void HWEngine::engineMessageHandler(MessageType mt, const QByteArray &msg)
{
- if(msg.size() == 128 * 256)
+ switch(mt)
{
+ case MSG_PREVIEW:
PreviewImageProvider * preview = (PreviewImageProvider *)m_engine->imageProvider(QLatin1String("preview"));
preview->setPixmap(msg);
emit previewImageChanged();
+ break;
}
}
QString HWEngine::currentSeed()
{
- return m_seed;
+ return QString::fromLatin1(flibGetSeed());
}
--- a/qmlFrontend/hwengine.h Sun Sep 28 00:49:04 2014 +0400
+++ b/qmlFrontend/hwengine.h Sun Sep 28 01:17:55 2014 +0400
@@ -28,12 +28,11 @@
private:
QQmlEngine * m_engine;
- QString m_seed;
static void guiMessagesCallback(void * context, MessageType mt, const char * msg, uint32_t len);
private slots:
- void engineMessageHandler(const QByteArray &msg);
+ void engineMessageHandler(MessageType mt, const QByteArray &msg);
};
#endif // HWENGINE_H