6 #include "engine_interface.h" |
6 #include "engine_interface.h" |
7 #include "game_view.h" |
7 #include "game_view.h" |
8 #include "hwengine.h" |
8 #include "hwengine.h" |
9 #include "preview_acceptor.h" |
9 #include "preview_acceptor.h" |
10 |
10 |
11 namespace Engine { |
11 namespace Engine {}; // namespace Engine |
12 hedgewars_engine_protocol_version_t* hedgewars_engine_protocol_version; |
|
13 start_engine_t* start_engine; |
|
14 generate_preview_t* generate_preview; |
|
15 cleanup_t* cleanup; |
|
16 send_ipc_t* send_ipc; |
|
17 read_ipc_t* read_ipc; |
|
18 setup_current_gl_context_t* setup_current_gl_context; |
|
19 render_frame_t* render_frame; |
|
20 advance_simulation_t* advance_simulation; |
|
21 }; // namespace Engine |
|
22 |
12 |
23 static QObject* previewacceptor_singletontype_provider( |
13 static QObject* previewacceptor_singletontype_provider( |
24 QQmlEngine* engine, QJSEngine* scriptEngine) { |
14 QQmlEngine* engine, QJSEngine* scriptEngine) { |
25 Q_UNUSED(scriptEngine) |
15 Q_UNUSED(scriptEngine) |
26 |
16 |
27 PreviewAcceptor* acceptor = new PreviewAcceptor(engine); |
17 PreviewAcceptor* acceptor = new PreviewAcceptor(engine); |
28 return acceptor; |
18 return acceptor; |
29 } |
19 } |
30 |
20 |
31 void loadEngineLibrary() { |
|
32 #ifdef Q_OS_WIN |
|
33 QLibrary hwlib("./libhedgewars_engine.dll"); |
|
34 #else |
|
35 QLibrary hwlib("./libhedgewars_engine.so"); |
|
36 #endif |
|
37 |
|
38 if (!hwlib.load()) |
|
39 qWarning() << "Engine library not found" << hwlib.errorString(); |
|
40 |
|
41 Engine::hedgewars_engine_protocol_version = |
|
42 reinterpret_cast<Engine::hedgewars_engine_protocol_version_t*>( |
|
43 hwlib.resolve("hedgewars_engine_protocol_version")); |
|
44 Engine::start_engine = |
|
45 reinterpret_cast<Engine::start_engine_t*>(hwlib.resolve("start_engine")); |
|
46 Engine::generate_preview = reinterpret_cast<Engine::generate_preview_t*>( |
|
47 hwlib.resolve("generate_preview")); |
|
48 Engine::cleanup = |
|
49 reinterpret_cast<Engine::cleanup_t*>(hwlib.resolve("cleanup")); |
|
50 |
|
51 Engine::send_ipc = |
|
52 reinterpret_cast<Engine::send_ipc_t*>(hwlib.resolve("send_ipc")); |
|
53 Engine::read_ipc = |
|
54 reinterpret_cast<Engine::read_ipc_t*>(hwlib.resolve("read_ipc")); |
|
55 |
|
56 Engine::setup_current_gl_context = |
|
57 reinterpret_cast<Engine::setup_current_gl_context_t*>( |
|
58 hwlib.resolve("setup_current_gl_context")); |
|
59 Engine::render_frame = |
|
60 reinterpret_cast<Engine::render_frame_t*>(hwlib.resolve("render_frame")); |
|
61 Engine::advance_simulation = reinterpret_cast<Engine::advance_simulation_t*>( |
|
62 hwlib.resolve("advance_simulation")); |
|
63 |
|
64 if (Engine::hedgewars_engine_protocol_version) |
|
65 qDebug() << "Loaded engine library with protocol version" |
|
66 << Engine::hedgewars_engine_protocol_version(); |
|
67 } |
|
68 |
|
69 int main(int argc, char* argv[]) { |
21 int main(int argc, char* argv[]) { |
70 QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); |
22 QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); |
71 QGuiApplication app(argc, argv); |
23 QGuiApplication app(argc, argv); |
72 |
|
73 loadEngineLibrary(); |
|
74 |
24 |
75 QQmlApplicationEngine engine; |
25 QQmlApplicationEngine engine; |
76 |
26 |
77 qmlRegisterSingletonType<PreviewAcceptor>( |
27 qmlRegisterSingletonType<PreviewAcceptor>( |
78 "Hedgewars.Engine", 1, 0, "PreviewAcceptor", |
28 "Hedgewars.Engine", 1, 0, "PreviewAcceptor", |