qmlfrontend/main.cpp
author unC0Rr
Thu, 22 Nov 2018 10:58:55 +0100
changeset 14276 1aac8a62be6f
parent 14159 8354b390f1a2
child 14299 21be7838a127
permissions -rw-r--r--
Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14159
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
     1
#include <QDebug>
12859
28cb18c5e712 Add new qmlfrontend project template
unc0rr
parents:
diff changeset
     2
#include <QGuiApplication>
14159
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
     3
#include <QLibrary>
12859
28cb18c5e712 Add new qmlfrontend project template
unc0rr
parents:
diff changeset
     4
#include <QQmlApplicationEngine>
28cb18c5e712 Add new qmlfrontend project template
unc0rr
parents:
diff changeset
     5
14159
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
     6
#include "engine_interface.h"
14148
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents: 12859
diff changeset
     7
#include "hwengine.h"
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents: 12859
diff changeset
     8
14159
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
     9
namespace Engine {
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    10
protocol_version_t* protocol_version;
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    11
start_engine_t* start_engine;
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    12
generate_preview_t* generate_preview;
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    13
cleanup_t* cleanup;
14276
1aac8a62be6f Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
unC0Rr
parents: 14159
diff changeset
    14
send_ipc_t* send_ipc;
1aac8a62be6f Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
unC0Rr
parents: 14159
diff changeset
    15
read_ipc_t* read_ipc;
14159
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    16
};  // namespace Engine
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    17
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    18
void loadEngineLibrary() {
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    19
#ifdef Q_OS_WIN
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    20
  QLibrary hwlib("./libhedgewars_engine.dll");
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    21
#else
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    22
  QLibrary hwlib("./libhedgewars_engine.so");
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    23
#endif
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    24
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    25
  if (!hwlib.load())
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    26
    qWarning() << "Engine library not found" << hwlib.errorString();
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    27
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    28
  Engine::protocol_version = reinterpret_cast<Engine::protocol_version_t*>(
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    29
      hwlib.resolve("protocol_version"));
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    30
  Engine::start_engine =
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    31
      reinterpret_cast<Engine::start_engine_t*>(hwlib.resolve("start_engine"));
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    32
  Engine::generate_preview = reinterpret_cast<Engine::generate_preview_t*>(
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    33
      hwlib.resolve("generate_preview"));
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    34
  Engine::cleanup =
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    35
      reinterpret_cast<Engine::cleanup_t*>(hwlib.resolve("cleanup"));
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    36
14276
1aac8a62be6f Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
unC0Rr
parents: 14159
diff changeset
    37
  Engine::send_ipc =
1aac8a62be6f Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
unC0Rr
parents: 14159
diff changeset
    38
      reinterpret_cast<Engine::send_ipc_t*>(hwlib.resolve("send_ipc"));
1aac8a62be6f Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
unC0Rr
parents: 14159
diff changeset
    39
  Engine::read_ipc =
1aac8a62be6f Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
unC0Rr
parents: 14159
diff changeset
    40
      reinterpret_cast<Engine::read_ipc_t*>(hwlib.resolve("read_ipc"));
1aac8a62be6f Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
unC0Rr
parents: 14159
diff changeset
    41
14159
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    42
  if (Engine::protocol_version)
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    43
    qDebug() << "Loaded engine library with protocol version"
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    44
             << Engine::protocol_version();
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    45
}
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    46
14148
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents: 12859
diff changeset
    47
int main(int argc, char* argv[]) {
12859
28cb18c5e712 Add new qmlfrontend project template
unc0rr
parents:
diff changeset
    48
  QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
28cb18c5e712 Add new qmlfrontend project template
unc0rr
parents:
diff changeset
    49
  QGuiApplication app(argc, argv);
28cb18c5e712 Add new qmlfrontend project template
unc0rr
parents:
diff changeset
    50
14159
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    51
  loadEngineLibrary();
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    52
12859
28cb18c5e712 Add new qmlfrontend project template
unc0rr
parents:
diff changeset
    53
  QQmlApplicationEngine engine;
14148
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents: 12859
diff changeset
    54
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents: 12859
diff changeset
    55
  HWEngine::exposeToQML();
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents: 12859
diff changeset
    56
12859
28cb18c5e712 Add new qmlfrontend project template
unc0rr
parents:
diff changeset
    57
  engine.load(QUrl(QLatin1String("qrc:/main.qml")));
14148
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents: 12859
diff changeset
    58
  if (engine.rootObjects().isEmpty()) return -1;
12859
28cb18c5e712 Add new qmlfrontend project template
unc0rr
parents:
diff changeset
    59
28cb18c5e712 Add new qmlfrontend project template
unc0rr
parents:
diff changeset
    60
  return app.exec();
28cb18c5e712 Add new qmlfrontend project template
unc0rr
parents:
diff changeset
    61
}