- ResizeWindow function to pass engine new window size qmlfrontend
authorunc0rr
Sun, 07 Jan 2018 01:21:42 +0100
branchqmlfrontend
changeset 12883 adb1fccc706a
parent 12882 bf58f2403953
child 12884 66171ce586cc
- ResizeWindow function to pass engine new window size - Remove TabBar to leave more space at the bottom of the screen - ifdef GL_ES in shaders
hedgewars/hwLibrary.pas
hedgewars/hwengine.pas
qmlfrontend/flib.h
qmlfrontend/gameview.cpp
qmlfrontend/gameview.h
qmlfrontend/hwengine.cpp
qmlfrontend/main.qml
share/hedgewars/Data/Shaders/default.fs
share/hedgewars/Data/Shaders/default.vs
share/hedgewars/Data/Shaders/water.fs
share/hedgewars/Data/Shaders/water.vs
--- a/hedgewars/hwLibrary.pas	Sat Jan 06 03:17:12 2018 +0100
+++ b/hedgewars/hwLibrary.pas	Sun Jan 07 01:21:42 2018 +0100
@@ -63,7 +63,8 @@
     ipcSetEngineBarrier,
     ipcRemoveBarrierFromEngineQueue,
     RunEngine,
-    GameTick
+    GameTick,
+    ResizeWindow
     ;
 
 begin
--- a/hedgewars/hwengine.pas	Sat Jan 06 03:17:12 2018 +0100
+++ b/hedgewars/hwengine.pas	Sun Jan 07 01:21:42 2018 +0100
@@ -37,6 +37,7 @@
 
 function  RunEngine(argc: LongInt; argv: PPChar): Longint; cdecl; export;
 function GameTick(delta: Longword): boolean; cdecl; export;
+procedure ResizeWindow(width, height: Longword); cdecl; export;
 
 procedure preInitEverything();
 procedure initEverything(complete:boolean);
@@ -654,4 +655,11 @@
     end;
 end;
 
+procedure ResizeWindow(width, height: Longword); cdecl; export;
+begin
+    cNewScreenWidth:= max(2 * (width div 2), cMinScreenWidth);
+    cNewScreenHeight:= max(2 * (height div 2), cMinScreenHeight);
+    cScreenResizeDelay:= RealTicks + 500{$IFDEF IPHONEOS}div 2{$ENDIF};
+end;
+
 end.
--- a/qmlfrontend/flib.h	Sat Jan 06 03:17:12 2018 +0100
+++ b/qmlfrontend/flib.h	Sun Jan 07 01:21:42 2018 +0100
@@ -26,6 +26,7 @@
 
 typedef void RunEngine_t(int argc, const char** argv);
 typedef void GameTick_t(uint32_t time_delta);
+typedef void ResizeWindow_t(uint32_t width, uint32_t height);
 typedef void ipcToEngineRaw_t(const char* msg, uint32_t len);
 typedef void ipcSetEngineBarrier_t();
 typedef void ipcRemoveBarrierFromEngineQueue_t();
--- a/qmlfrontend/gameview.cpp	Sat Jan 06 03:17:12 2018 +0100
+++ b/qmlfrontend/gameview.cpp	Sun Jan 07 01:21:42 2018 +0100
@@ -8,11 +8,13 @@
 
 extern "C" {
 extern GameTick_t* flibGameTick;
+extern ResizeWindow_t* flibResizeWindow;
 }
 
 GameView::GameView()
     : m_delta(0)
     , m_renderer(0)
+    , m_windowChanged(true)
 {
     connect(this, &QQuickItem::windowChanged, this, &GameView::handleWindowChanged);
 }
@@ -31,6 +33,8 @@
         connect(win, &QQuickWindow::sceneGraphInvalidated, this, &GameView::cleanup, Qt::DirectConnection);
 
         win->setClearBeforeRendering(false);
+
+        m_windowChanged = true;
     }
 }
 
@@ -42,19 +46,26 @@
     }
 }
 
-GameViewRenderer::~GameViewRenderer()
-{
-}
-
 void GameView::sync()
 {
     if (!m_renderer) {
         m_renderer = new GameViewRenderer();
         connect(window(), &QQuickWindow::beforeRendering, m_renderer, &GameViewRenderer::paint, Qt::DirectConnection);
     }
-    m_renderer->setViewportSize(window()->size() * window()->devicePixelRatio());
+
+    if (m_windowChanged)
+        m_renderer->setViewportSize(window()->size() * window()->devicePixelRatio());
+
     m_renderer->tick(m_delta);
-    m_renderer->setWindow(window());
+}
+
+GameViewRenderer::~GameViewRenderer()
+{
+}
+
+void GameViewRenderer::setViewportSize(const QSize& size)
+{
+    flibResizeWindow(size.width(), size.height());
 }
 
 void GameViewRenderer::paint()
@@ -64,5 +75,5 @@
 
     flibGameTick(m_delta);
 
-    m_window->resetOpenGLState();
+    //m_window->resetOpenGLState();
 }
--- a/qmlfrontend/gameview.h	Sat Jan 06 03:17:12 2018 +0100
+++ b/qmlfrontend/gameview.h	Sun Jan 07 01:21:42 2018 +0100
@@ -16,16 +16,13 @@
     ~GameViewRenderer();
 
     void tick(quint32 delta) { m_delta = delta; }
-    void setViewportSize(const QSize& size) { m_viewportSize = size; }
-    void setWindow(QQuickWindow* window) { m_window = window; }
+    void setViewportSize(const QSize& size);
 
 public slots:
     void paint();
 
 private:
-    QSize m_viewportSize;
     quint32 m_delta;
-    QQuickWindow* m_window;
 };
 
 class GameView : public QQuickItem {
@@ -49,6 +46,7 @@
 private:
     quint32 m_delta;
     GameViewRenderer* m_renderer;
+    bool m_windowChanged;
 };
 
 #endif // GAMEVIEW_H
--- a/qmlfrontend/hwengine.cpp	Sat Jan 06 03:17:12 2018 +0100
+++ b/qmlfrontend/hwengine.cpp	Sun Jan 07 01:21:42 2018 +0100
@@ -12,6 +12,7 @@
 extern "C" {
 RunEngine_t* flibRunEngine;
 GameTick_t* flibGameTick;
+ResizeWindow_t* flibResizeWindow;
 ipcToEngineRaw_t* flibIpcToEngineRaw;
 ipcSetEngineBarrier_t* flibIpcSetEngineBarrier;
 ipcRemoveBarrierFromEngineQueue_t* flibIpcRemoveBarrierFromEngineQueue;
@@ -40,6 +41,7 @@
 
     flibRunEngine = (RunEngine_t*)hwlib.resolve("RunEngine");
     flibGameTick = (GameTick_t*)hwlib.resolve("GameTick");
+    flibResizeWindow = (ResizeWindow_t*)hwlib.resolve("ResizeWindow");
     flibIpcToEngineRaw = (ipcToEngineRaw_t*)hwlib.resolve("ipcToEngineRaw");
     flibIpcSetEngineBarrier = (ipcSetEngineBarrier_t*)hwlib.resolve("ipcSetEngineBarrier");
     flibIpcRemoveBarrierFromEngineQueue = (ipcRemoveBarrierFromEngineQueue_t*)hwlib.resolve("ipcRemoveBarrierFromEngineQueue");
--- a/qmlfrontend/main.qml	Sat Jan 06 03:17:12 2018 +0100
+++ b/qmlfrontend/main.qml	Sun Jan 07 01:21:42 2018 +0100
@@ -15,23 +15,5 @@
 
     Page1 {
     }
-
-    Page {
-      Label {
-        text: qsTr("Second page")
-        anchors.centerIn: parent
-      }
-    }
-  }
-
-  footer: TabBar {
-    id: tabBar
-    currentIndex: swipeView.currentIndex
-    TabButton {
-      text: qsTr("First")
-    }
-    TabButton {
-      text: qsTr("Second")
-    }
   }
 }
--- a/share/hedgewars/Data/Shaders/default.fs	Sat Jan 06 03:17:12 2018 +0100
+++ b/share/hedgewars/Data/Shaders/default.fs	Sun Jan 07 01:21:42 2018 +0100
@@ -1,4 +1,6 @@
+#ifdef GL_ES
 precision mediump float;
+#endif
 
 uniform sampler2D tex0;
 uniform vec4 tint;
--- a/share/hedgewars/Data/Shaders/default.vs	Sat Jan 06 03:17:12 2018 +0100
+++ b/share/hedgewars/Data/Shaders/default.vs	Sun Jan 07 01:21:42 2018 +0100
@@ -1,4 +1,6 @@
+#ifdef GL_ES
 precision mediump float;
+#endif
 
 attribute vec2 vertex;
 attribute vec2 texcoord;
--- a/share/hedgewars/Data/Shaders/water.fs	Sat Jan 06 03:17:12 2018 +0100
+++ b/share/hedgewars/Data/Shaders/water.fs	Sun Jan 07 01:21:42 2018 +0100
@@ -1,4 +1,6 @@
+#ifdef GL_ES
 precision mediump float;
+#endif
 
 varying vec4 vcolor;
 
--- a/share/hedgewars/Data/Shaders/water.vs	Sat Jan 06 03:17:12 2018 +0100
+++ b/share/hedgewars/Data/Shaders/water.vs	Sun Jan 07 01:21:42 2018 +0100
@@ -1,4 +1,6 @@
+#ifdef GL_ES
 precision mediump float;
+#endif
 
 attribute vec2 vertex;
 attribute vec4 color;