qmlfrontend/main.cpp
author unc0rr
Sun, 02 Dec 2018 00:19:17 +0100
changeset 14364 5e28098fb593
parent 14299 21be7838a127
child 14375 ef2fc0210362
permissions -rw-r--r--
Fix stray tab character
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;
14299
21be7838a127 Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents: 14276
diff changeset
    16
setup_current_gl_context_t* setup_current_gl_context;
21be7838a127 Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents: 14276
diff changeset
    17
render_frame_t* render_frame;
21be7838a127 Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents: 14276
diff changeset
    18
advance_simulation_t* advance_simulation;
14159
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    19
};  // namespace Engine
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    20
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    21
void loadEngineLibrary() {
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    22
#ifdef Q_OS_WIN
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    23
  QLibrary hwlib("./libhedgewars_engine.dll");
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    24
#else
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    25
  QLibrary hwlib("./libhedgewars_engine.so");
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    26
#endif
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
  if (!hwlib.load())
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    29
    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
    30
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    31
  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
    32
      hwlib.resolve("protocol_version"));
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    33
  Engine::start_engine =
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    34
      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
    35
  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
    36
      hwlib.resolve("generate_preview"));
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    37
  Engine::cleanup =
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    38
      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
    39
14276
1aac8a62be6f Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
unC0Rr
parents: 14159
diff changeset
    40
  Engine::send_ipc =
1aac8a62be6f Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
unC0Rr
parents: 14159
diff changeset
    41
      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
    42
  Engine::read_ipc =
1aac8a62be6f Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
unC0Rr
parents: 14159
diff changeset
    43
      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
    44
14299
21be7838a127 Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents: 14276
diff changeset
    45
  Engine::setup_current_gl_context =
21be7838a127 Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents: 14276
diff changeset
    46
      reinterpret_cast<Engine::setup_current_gl_context_t*>(
21be7838a127 Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents: 14276
diff changeset
    47
          hwlib.resolve("setup_current_gl_context"));
21be7838a127 Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents: 14276
diff changeset
    48
  Engine::render_frame =
21be7838a127 Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents: 14276
diff changeset
    49
      reinterpret_cast<Engine::render_frame_t*>(hwlib.resolve("render_frame"));
21be7838a127 Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents: 14276
diff changeset
    50
  Engine::advance_simulation = reinterpret_cast<Engine::advance_simulation_t*>(
21be7838a127 Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents: 14276
diff changeset
    51
      hwlib.resolve("advance_simulation"));
21be7838a127 Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents: 14276
diff changeset
    52
14159
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    53
  if (Engine::protocol_version)
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    54
    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
    55
             << Engine::protocol_version();
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    56
}
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    57
14148
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents: 12859
diff changeset
    58
int main(int argc, char* argv[]) {
12859
28cb18c5e712 Add new qmlfrontend project template
unc0rr
parents:
diff changeset
    59
  QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
28cb18c5e712 Add new qmlfrontend project template
unc0rr
parents:
diff changeset
    60
  QGuiApplication app(argc, argv);
28cb18c5e712 Add new qmlfrontend project template
unc0rr
parents:
diff changeset
    61
14159
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    62
  loadEngineLibrary();
8354b390f1a2 Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents: 14148
diff changeset
    63
12859
28cb18c5e712 Add new qmlfrontend project template
unc0rr
parents:
diff changeset
    64
  QQmlApplicationEngine engine;
14148
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents: 12859
diff changeset
    65
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents: 12859
diff changeset
    66
  HWEngine::exposeToQML();
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents: 12859
diff changeset
    67
12859
28cb18c5e712 Add new qmlfrontend project template
unc0rr
parents:
diff changeset
    68
  engine.load(QUrl(QLatin1String("qrc:/main.qml")));
14148
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents: 12859
diff changeset
    69
  if (engine.rootObjects().isEmpty()) return -1;
12859
28cb18c5e712 Add new qmlfrontend project template
unc0rr
parents:
diff changeset
    70
28cb18c5e712 Add new qmlfrontend project template
unc0rr
parents:
diff changeset
    71
  return app.exec();
28cb18c5e712 Add new qmlfrontend project template
unc0rr
parents:
diff changeset
    72
}