Przeglądaj źródła

Move to a single world system

Fix the worst of the lateral movement caused by overlapping edges in
items. (spawning a new item while the old item was moving out, in the
same space)

Change-Id: I86107218026f0522cdcad61be2a8086beac4544e
Donald Carr 9 lat temu
rodzic
commit
7c4b9b2455
4 zmienionych plików z 40 dodań i 52 usunięć
  1. 9 3
      qml/ArtDelegate.qml
  2. 31 46
      qml/Gravity.qml
  3. 0 2
      qml/HorizontalArtDelegate.qml
  4. 0 1
      qml/main.qml

+ 9 - 3
qml/ArtDelegate.qml

@@ -5,10 +5,16 @@ import Qt.labs.settings 1.0
 ImageBoxBody {
     id: picture
 
-    onYChanged: y > floor.y && picture.destroy()
+    signal beyondThePale(var item)
+
+    onYChanged:
+        if (y > floor.y)
+            beyondThePale(this)
+
+    density: 10
+    friction: 0
+    restitution: 0.2
 
-    density: 1.0
-    friction: 0.0
     fixedRotation: parent.fixedRotation
     world: parent.physicsWorld
     bodyType: Body.Dynamic

+ 31 - 46
qml/Gravity.qml

@@ -47,62 +47,47 @@ Item {
         Item {
             id: column
 
-            property int columnHeight: 0
+            property int stackHeight: 0
             property bool full: false
 
-            onColumnHeightChanged: {
-                if (!column.full && (columnHeight > root.height)) {
+            onStackHeightChanged: {
+                if (!column.full && (stackHeight > root.height)) {
                     d.primedColumns += 1
                     column.full = true
                 }
             }
 
             function addImage() {
-                if (columnHeight < (1.1+1/d.columnCount)*root.height) {
-                    var item = pictureDelegate.createObject(column)
-                    columnHeight += (item.height + d.itemTravel)
-                    item.y = floor.y - columnHeight
-                    d.itemCount++
-                    pictureArray.push(item)
-                }
+                var item = pictureDelegate.createObject(column, { x: -1000, y: -1000 })
+                item.beyondThePale.connect(removeImage)
+                stackHeight += (item.height + d.itemTravel)
+                item.x = width * index
+                item.y = floor.y - stackHeight
+                d.itemCount++
+                pictureArray.push(item)
+            }
+
+            function removeImage(image) {
+                stackHeight -= (image.height + d.itemTravel)
+                image.destroy()
+                d.itemCount--
             }
 
-            x: width * index
             width: parent.width/d.columnCount
 
             anchors { top: parent.top; bottom: parent.bottom }
 
             property var pictureArray: []
-            property var physicsWorld: settings.globalWorld ? commonWorld : columnWorld
+            property var physicsWorld: commonWorld
             property bool fixedRotation: true
 
-            World {
-                id: columnWorld
-
-                timeStep: d.pace
-                // There is less item fall through when this runs perpetually
-                running: d.running
-            }
-
-            RectangleBoxBody {
-                world: physicsWorld
-                height: 1
-                anchors {
-                    left: parent.left
-                    right: parent.right
-                    top: parent.bottom
-                }
-                friction: 1
-                density: 1
-            }
-
             Timer {
                 id: pumpTimer
                 interval: Math.random()*500 + 500
                 repeat: true
-                running: true
+                running: !full
                 onTriggered: {
-                    column.addImage()
+                    addImage()
                 }
             }
 
@@ -115,8 +100,7 @@ Item {
                     if (pictureArray.length > 0) {
                         var image = pictureArray.shift()
                         image.world = bullshitWorld
-                        d.itemCount--
-                        columnHeight -= (image.height + d.itemTravel)
+                        addImage()
                     }
                 }
             }
@@ -134,15 +118,6 @@ Item {
                 interval: 200
                 onTriggered: deathTimer.triggered()
             }
-
-            DebugDraw {
-                id: debugDraw
-                z: 1
-                world: physicsWorld
-                anchors.fill: parent
-                opacity: 0.75
-                visible: true
-            }
         }
     }
 
@@ -150,7 +125,7 @@ Item {
     RectangleBoxBody {
         id: floor
         world: commonWorld
-        height: 1
+        height: 0
         anchors {
             left: parent.left
             right: parent.right
@@ -160,6 +135,16 @@ Item {
         density: 1
     }
 
+    DebugDraw {
+        id: debugDraw
+        enabled: false
+        z: 1
+        world: commonWorld
+        anchors.fill: parent
+        opacity: 0.75
+        visible: enabled
+    }
+
     Repeater {
         model: d.columnCount
         delegate: columnComponent

+ 0 - 2
qml/HorizontalArtDelegate.qml

@@ -1,7 +1,5 @@
 import QtQuick 2.5
 
 ArtDelegate {
-    //height: implicitHeight/implicitWidth*width
     width: parent.width
-    onXChanged: x = 0
 }

+ 0 - 1
qml/main.qml

@@ -17,7 +17,6 @@ Window {
         property int interval: 2
         property double pace: 1.0
         property bool viewItemCount: false
-        property bool globalWorld: false
     }
 
     Rectangle {