# HG changeset patch # User unc0rr # Date 1553286550 -3600 # Node ID cc6ab1e3f7d5b0904d1a60d4ef1e521461c337e1 # Parent 57293f34ce592341012ef68f00472249da4e4a65 Allow to move camera around diff -r 57293f34ce59 -r cc6ab1e3f7d5 qmlfrontend/engine_instance.cpp --- a/qmlfrontend/engine_instance.cpp Fri Mar 22 21:06:12 2019 +0100 +++ b/qmlfrontend/engine_instance.cpp Fri Mar 22 21:29:10 2019 +0100 @@ -41,11 +41,13 @@ reinterpret_cast(hwlib.resolve("render_frame")); advance_simulation = reinterpret_cast( hwlib.resolve("advance_simulation")); + move_camera = + reinterpret_cast(hwlib.resolve("move_camera")); m_isValid = hedgewars_engine_protocol_version && start_engine && generate_preview && dispose_preview && cleanup && send_ipc && read_ipc && setup_current_gl_context && render_frame && - advance_simulation; + advance_simulation && move_camera; emit isValidChanged(m_isValid); if (isValid()) { @@ -53,6 +55,8 @@ << hedgewars_engine_protocol_version(); m_instance = start_engine(); + } else { + qDebug("Engine library load failed"); } } @@ -71,6 +75,10 @@ advance_simulation(m_instance, ticks); } +void EngineInstance::moveCamera(const QPoint& delta) { + move_camera(m_instance, delta.x(), delta.y()); +} + void EngineInstance::renderFrame() { render_frame(m_instance); } void EngineInstance::setOpenGLContext(QOpenGLContext* context) { diff -r 57293f34ce59 -r cc6ab1e3f7d5 qmlfrontend/engine_instance.h --- a/qmlfrontend/engine_instance.h Fri Mar 22 21:06:12 2019 +0100 +++ b/qmlfrontend/engine_instance.h Fri Mar 22 21:29:10 2019 +0100 @@ -19,6 +19,7 @@ void sendConfig(const GameConfig& config); void advance(quint32 ticks); + void moveCamera(const QPoint& delta); void renderFrame(); void setOpenGLContext(QOpenGLContext* context); QImage generatePreview(); @@ -44,6 +45,7 @@ Engine::setup_current_gl_context_t* setup_current_gl_context; Engine::render_frame_t* render_frame; Engine::advance_simulation_t* advance_simulation; + Engine::move_camera_t* move_camera; bool m_isValid; }; diff -r 57293f34ce59 -r cc6ab1e3f7d5 qmlfrontend/engine_interface.h --- a/qmlfrontend/engine_interface.h Fri Mar 22 21:06:12 2019 +0100 +++ b/qmlfrontend/engine_interface.h Fri Mar 22 21:29:10 2019 +0100 @@ -37,6 +37,9 @@ typedef bool advance_simulation_t(EngineInstance* engine_state, uint32_t ticks); +typedef void move_camera_t(EngineInstance* engine_state, int32_t delta_x, + int32_t delta_y); + #ifdef __cplusplus } }; diff -r 57293f34ce59 -r cc6ab1e3f7d5 qmlfrontend/game_view.cpp --- a/qmlfrontend/game_view.cpp Fri Mar 22 21:06:12 2019 +0100 +++ b/qmlfrontend/game_view.cpp Fri Mar 22 21:29:10 2019 +0100 @@ -65,12 +65,14 @@ m_engineInstance->setOpenGLContext(window()->openglContext()); m_viewportSize = window()->size(); + m_centerPoint = QPoint(m_viewportSize.width(), m_viewportSize.height()) / 2; } - // QPoint mousePos = mapFromGlobal(QCursor::pos()).toPoint(); - // if (flibUpdateMousePosition(m_centerX, m_centerY, mousePos.x(), - // mousePos.y())) - // QCursor::setPos(mapToGlobal(QPointF(m_centerX, m_centerY)).toPoint()); + if (m_engineInstance) { + QPoint mousePos = mapFromGlobal(QCursor::pos()).toPoint(); + m_engineInstance->moveCamera(mousePos - m_centerPoint); + QCursor::setPos(mapToGlobal(m_centerPoint).toPoint()); + } if (m_renderer) m_renderer->tick(m_delta); } diff -r 57293f34ce59 -r cc6ab1e3f7d5 qmlfrontend/game_view.h --- a/qmlfrontend/game_view.h Fri Mar 22 21:06:12 2019 +0100 +++ b/qmlfrontend/game_view.h Fri Mar 22 21:29:10 2019 +0100 @@ -58,6 +58,7 @@ bool m_windowChanged; QPointer m_engineInstance; QSize m_viewportSize; + QPoint m_centerPoint; }; #endif // GAMEVIEW_H diff -r 57293f34ce59 -r cc6ab1e3f7d5 rust/lib-hedgewars-engine/src/lib.rs --- a/rust/lib-hedgewars-engine/src/lib.rs Fri Mar 22 21:06:12 2019 +0100 +++ b/rust/lib-hedgewars-engine/src/lib.rs Fri Mar 22 21:29:10 2019 +0100 @@ -10,6 +10,8 @@ os::raw::{c_char, c_void}, }; +use integral_geometry::Point; + use self::instance::EngineInstance; #[repr(C)] @@ -101,6 +103,14 @@ engine_state.world.step(); true } + +#[no_mangle] +pub extern "C" fn move_camera(engine_state: &mut EngineInstance, delta_x: i32, delta_y: i32) { + engine_state + .world + .move_camera(Point::new(delta_x, delta_y), 0.0); +} + #[no_mangle] pub extern "C" fn cleanup(engine_state: *mut EngineInstance) { unsafe { diff -r 57293f34ce59 -r cc6ab1e3f7d5 rust/lib-hedgewars-engine/src/world.rs --- a/rust/lib-hedgewars-engine/src/world.rs Fri Mar 22 21:06:12 2019 +0100 +++ b/rust/lib-hedgewars-engine/src/world.rs Fri Mar 22 21:29:10 2019 +0100 @@ -49,7 +49,7 @@ if let Some(ref state) = self.game_state { self.camera.position = state.land.play_box().center(); - + let theme = Theme::load(Path::new("../../share/hedgewars/Data/Themes/Cheese/")).unwrap(); let texture = MapGenerator::new().make_texture(&state.land, &theme);