--- a/CMakeLists.txt Sun Dec 17 21:09:59 2017 +0100
+++ b/CMakeLists.txt Fri Dec 22 23:59:03 2017 +0100
@@ -257,7 +257,7 @@
else(ANDROID)
#skip frontend for javascript
if(NOT BUILD_ENGINE_JS)
- add_subdirectory(qmlFrontend)
+ add_subdirectory(qmlfrontend)
add_subdirectory(share)
endif()
--- a/hedgewars/CMakeLists.txt Sun Dec 17 21:09:59 2017 +0100
+++ b/hedgewars/CMakeLists.txt Fri Dec 22 23:59:03 2017 +0100
@@ -106,18 +106,8 @@
uGearsUtils.pas
uTeams.pas
- uFLAmmo.pas
- uFLDrawnMap.pas
- uFLGameConfig.pas
uFLIPC.pas
- uFLNet.pas
- uFLNetProtocol.pas
- uFLNetTypes.pas
uFLRunQueue.pas
- uFLScripts.pas
- uFLSchemes.pas
- uFLTeams.pas
- uFLThemes.pas
uFLTypes.pas
uFLUICallback.pas
uFLUtils.pas
--- a/hedgewars/hwLibrary.pas Sun Dec 17 21:09:59 2017 +0100
+++ b/hedgewars/hwLibrary.pas Fri Dec 22 23:59:03 2017 +0100
@@ -105,12 +105,10 @@
begin
initIPC;
uPhysFSLayer.initModule(localPrefix, userPrefix);
- uFLNet.initModule;
end;
procedure flibFree; cdecl;
begin
- uFLNet.freeModule;
uPhysFSLayer.freemodule;
freeIPC;
end;
--- a/qmlfrontend/CMakeLists.txt Sun Dec 17 21:09:59 2017 +0100
+++ b/qmlfrontend/CMakeLists.txt Fri Dec 22 23:59:03 2017 +0100
@@ -8,6 +8,6 @@
find_package(Qt5 COMPONENTS Core Quick REQUIRED)
-add_executable(${PROJECT_NAME} "main.cpp" "qml.qrc")
+add_executable(${PROJECT_NAME} "main.cpp" "qml.qrc" "hwengine.cpp" "hwengine.h" "flib.h")
target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Quick)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/qmlfrontend/flib.h Fri Dec 22 23:59:03 2017 +0100
@@ -0,0 +1,72 @@
+#ifndef FLIB_H
+#define FLIB_H
+
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+enum MessageType {
+ MSG_RENDERINGPREVIEW
+ , MSG_PREVIEW
+ , MSG_PREVIEWHOGCOUNT
+ , MSG_ADDPLAYINGTEAM
+ , MSG_REMOVEPLAYINGTEAM
+ , MSG_ADDTEAM
+ , MSG_REMOVETEAM
+ , MSG_TEAMCOLOR
+ , MSG_HEDGEHOGSNUMBER
+ , MSG_NETDATA
+ , MSG_TONET
+ , MSG_FLIBEVENT
+ , MSG_CONNECTED
+ , MSG_DISCONNECTED
+ , MSG_ADDLOBBYCLIENT
+ , MSG_REMOVELOBBYCLIENT
+ , MSG_LOBBYCHATLINE
+ , MSG_ADDROOMCLIENT
+ , MSG_REMOVEROOMCLIENT
+ , MSG_ROOMCHATLINE
+ , MSG_ADDROOM
+ , MSG_UPDATEROOM
+ , MSG_REMOVEROOM
+ , MSG_ERROR
+ , MSG_WARNING
+ , MSG_MOVETOLOBBY
+ , MSG_MOVETOROOM
+ , MSG_NICKNAME
+ , MSG_SEED
+ , MSG_THEME
+ , MSG_SCRIPT
+ , MSG_FEATURESIZE
+ , MSG_MAPGEN
+ , MSG_MAP
+ , MSG_MAZESIZE
+ , MSG_TEMPLATE
+ , MSG_AMMO
+ , MSG_SCHEME
+};
+
+typedef union string255_
+ {
+ struct {
+ unsigned char s[256];
+ };
+ struct {
+ unsigned char len;
+ unsigned char str[255];
+ };
+ } string255;
+
+typedef void RunEngine_t(int argc, const char ** argv);
+typedef void registerUIMessagesCallback_t(void * context, void (*)(void * context, MessageType mt, const char * msg, uint32_t len));
+typedef void flibInit_t(const char * localPrefix, const char * userPrefix);
+typedef void flibFree_t();
+typedef void passFlibEvent_t(const char * data);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // FLIB_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/qmlfrontend/hwengine.cpp Fri Dec 22 23:59:03 2017 +0100
@@ -0,0 +1,69 @@
+#include "hwengine.h"
+
+#include <QDebug>
+#include <QLibrary>
+
+extern "C" {
+RunEngine_t* flibRunEngine;
+registerUIMessagesCallback_t* flibRegisterUIMessagesCallback;
+flibInit_t* flibInit;
+flibFree_t* flibFree;
+passFlibEvent_t* flibPassFlibEvent;
+}
+
+HWEngine::HWEngine(QQmlEngine* engine, QObject* parent)
+ : QObject(parent)
+ , m_engine(engine)
+{
+ qRegisterMetaType<MessageType>("MessageType");
+
+#ifdef Q_OS_WIN
+ QLibrary hwlib("./libhwengine.dll");
+#else
+ QLibrary hwlib("./libhwengine.so");
+#endif
+
+ if (!hwlib.load())
+ qWarning() << "Engine library not found" << hwlib.errorString();
+
+ flibRunEngine = (RunEngine_t*)hwlib.resolve("RunEngine");
+ flibRegisterUIMessagesCallback = (registerUIMessagesCallback_t*)hwlib.resolve("registerUIMessagesCallback");
+ flibInit = (flibInit_t*)hwlib.resolve("flibInit");
+ flibFree = (flibFree_t*)hwlib.resolve("flibFree");
+
+ flibInit("/usr/home/unC0Rr/Sources/Hedgewars/MainRepo/share/hedgewars/Data", "/usr/home/unC0Rr/.hedgewars");
+ flibRegisterUIMessagesCallback(this, &guiMessagesCallback);
+}
+
+HWEngine::~HWEngine()
+{
+ flibFree();
+}
+
+void HWEngine::guiMessagesCallback(void* context, MessageType mt, const char* msg, uint32_t len)
+{
+ HWEngine* obj = reinterpret_cast<HWEngine*>(context);
+ QByteArray b = QByteArray(msg, len);
+
+ qDebug() << "FLIPC in" << mt << " size = " << b.size();
+
+ QMetaObject::invokeMethod(obj, "engineMessageHandler", Qt::QueuedConnection, Q_ARG(MessageType, mt), Q_ARG(QByteArray, b));
+}
+
+void HWEngine::engineMessageHandler(MessageType mt, const QByteArray& msg)
+{
+ switch (mt) {
+ case MSG_RENDERINGPREVIEW: {
+ emit previewIsRendering();
+ break;
+ }
+ case MSG_PREVIEW: {
+ emit previewImageChanged();
+ break;
+ }
+ case MSG_PREVIEWHOGCOUNT: {
+ emit previewHogCountChanged((quint8)msg.data()[0]);
+ break;
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/qmlfrontend/hwengine.h Fri Dec 22 23:59:03 2017 +0100
@@ -0,0 +1,37 @@
+#ifndef HWENGINE_H
+#define HWENGINE_H
+
+#include <QObject>
+
+#include "flib.h"
+
+class QQmlEngine;
+
+class HWEnginePrivate;
+
+class HWEngine : public QObject {
+ Q_OBJECT
+
+public:
+ explicit HWEngine(QQmlEngine* engine, QObject* parent = nullptr);
+ ~HWEngine();
+
+ static void exposeToQML();
+
+signals:
+ void previewIsRendering();
+ void previewImageChanged();
+ void previewHogCountChanged(int count);
+
+public slots:
+
+private:
+ QQmlEngine* m_engine;
+
+ static void guiMessagesCallback(void* context, MessageType mt, const char* msg, uint32_t len);
+
+private slots:
+ void engineMessageHandler(MessageType mt, const QByteArray& msg);
+};
+
+#endif // HWENGINE_H
--- a/qmlfrontend/main.cpp Sun Dec 17 21:09:59 2017 +0100
+++ b/qmlfrontend/main.cpp Fri Dec 22 23:59:03 2017 +0100
@@ -1,6 +1,8 @@
#include <QGuiApplication>
#include <QQmlApplicationEngine>
+#include "hwengine.h"
+
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);