Ver Fonte

Introduce initial Cascade

Change-Id: Id40419a0fb77dfadd97b47d6d0a2bfd5eb29d345
Donald Carr há 8 anos atrás
pai
commit
b78103f83a
5 ficheiros alterados com 200 adições e 2 exclusões
  1. 169 0
      qml/cascade/Cascade.qml
  2. 22 0
      qml/cascade/CascadeDelegate.qml
  3. 2 2
      qml/common/ArtImage.qml
  4. 5 0
      qml/main.qml
  5. 2 0
      qml/qml.qrc

+ 169 - 0
qml/cascade/Cascade.qml

@@ -0,0 +1,169 @@
+import QtQuick 2.5
+import Box2D 2.0
+import Qt.labs.settings 1.0
+
+import ".."
+
+View {
+    id: root
+
+    signal togglePause
+    signal toggleChaos
+    signal next
+
+    property var columnArray: []
+    property var pictureDelegate: Component {
+        CascadeDelegate {}
+    }
+
+    anchors.fill: parent
+
+    QtObject {
+        id: d
+        property int columnCount: 6
+        property real pace: cascadeSettings.pace/60.0
+        property bool paused: false
+    }
+
+    Repeater {
+        model: d.columnCount
+        delegate: columnComponent
+    }
+
+    Settings {
+        id: cascadeSettings
+        category: "Cascade"
+
+        property int feedRate: 1000
+        // 0 is abutting
+        property int verticalOffset: 500
+        property real pace: 3
+        property real density: 1.0
+        property real friction: 1.0
+        // Very computationally heavy: 40% vs 20% for 0.1 vs 0
+        property real restitution: 0
+    }
+
+    Component {
+        id: columnComponent
+
+        Item {
+            id: column
+
+            property bool shifty: false
+            property int stackHeight: 0
+            property int xOffset: width * index
+            property var pictureArray: []
+
+            function addExistingImage(image) {
+                // make sure there is no spacial conflict in limbo, or shit goes tits up
+                image.x = image.y = index*-1000
+                image.linearVelocity.x = image.linearVelocity.y = 0.0
+                image.beyondThePale.connect(removeImage)
+                image.x = xOffset
+                stackHeight += image.height
+                image.y = -image.height - pictureArray.length*100
+                image.world = isolatedWorld
+
+                pictureArray.push(image)
+            }
+
+            function addImage() {
+                var image = pictureDelegate.createObject(column, { x: -1000, y: -1000 })
+                addExistingImage(image)
+
+                globalUtil.itemCount++
+            }
+
+            function removeImage(image) {
+                image.beyondThePale.disconnect(removeImage)
+                stackHeight -= image.height
+                //console.log('Image slipped through the cracks')
+                if (index === d.columnCount-1) {
+                    console.log('Image deleted')
+                    image.destroy()
+                    globalUtil.itemCount--
+                } else {
+                    columnArray[index+1].addExistingImage(image)
+                }
+            }
+
+            function shift() {
+                if (pictureArray.length > 0) {
+                    var image = pictureArray.shift()
+                    image.world = image.world.limbo
+                }
+            }
+
+            onStackHeightChanged: {
+                if (stackHeight > (1.3 + 1/d.columnCount)*root.height) {
+                    shifty = true
+                }
+            }
+
+            width: parent.width/globalSettings.columnCount
+            anchors { top: parent.top; bottom: parent.bottom }
+
+            World {
+                id: isolatedWorld
+                timeStep: d.pace
+                running: true
+                property var limbo: World {
+                    timeStep: isolatedWorld.timeStep
+                    running: isolatedWorld.running
+                }
+            }
+
+            RectangleBoxBody {
+                id: floor
+                world: isolatedWorld
+                height: 0
+                width: parent.width
+                x: xOffset
+                anchors {
+                    top: parent.bottom
+                }
+                friction: 1
+            }
+
+            Timer {
+                id: pumpTimer
+                interval: 1000
+                repeat: true
+                running: (index === 0) && !shifty
+                onTriggered: addImage()
+            }
+
+            Timer {
+                id: deathTimer
+                running: true
+                repeat: true
+                interval: 5000
+                onTriggered: {
+                    if (shifty) {
+                        shift()
+                        shifty = false
+                    }
+                }
+            }
+
+            Connections {
+                target: root
+                onTogglePause: d.paused = !d.paused
+                onNext: deathTimer.triggered()
+            }
+
+            Component.onCompleted: {
+                columnArray.push(this)
+            }
+        }
+    }
+
+    Keys.onUpPressed: root.togglePause()
+    Keys.onDownPressed: root.toggleChaos() //root.next()
+
+    Component.onCompleted: {
+        globalVars.loadFullImage = true
+        pictureDelegate.status !== Component.Ready && console.log('Component failed with:' + pictureDelegate.errorString())
+    }
+}

+ 22 - 0
qml/cascade/CascadeDelegate.qml

@@ -0,0 +1,22 @@
+import QtQuick 2.5
+import Box2D 2.0
+import Qt.labs.settings 1.0
+
+import ".."
+
+ArtBoxBody {
+    signal beyondThePale(var item)
+
+    onYChanged: {
+        if (y > root.height) {
+            beyondThePale(this)
+        }
+    }
+
+    density: 1 //cascadeSettings.density
+    friction: 1.0 //cascadeSettings.friction
+    restitution: 0.0 //cascadeSettings.restitution
+
+    fixedRotation: true
+    bodyType: Body.Dynamic
+}

+ 2 - 2
qml/common/ArtImage.qml

@@ -25,8 +25,8 @@ Rectangle {
         mirror: globalSettings.randomlyMirrorArt && (Math.random() < 0.5)
         smooth: globalSettings.smoothArt
 
-        sourceSize.height: height
-        sourceSize.width: width
+        sourceSize.height: globalVars.loadFullImage ? undefined : height
+        sourceSize.width: globalVars.loadFullImage ? undefined : width
 
         Behavior on opacity {
             SequentialAnimation {

+ 5 - 0
qml/main.qml

@@ -18,6 +18,11 @@ Window {
         id: imageModel
     }
 
+    QtObject {
+        id: globalVars
+        property bool loadFullImage: false
+    }
+
     QtObject {
         id: d
         property int primedColumns: 0

+ 2 - 0
qml/qml.qrc

@@ -9,6 +9,8 @@
         <file>physics/RectangleBoxBody.qml</file>
         <file>well/WellDelegate.qml</file>
         <file>well/Well.qml</file>
+        <file>cascade/Cascade.qml</file>
+        <file>cascade/CascadeDelegate.qml</file>
         <file>conveyor/Conveyor.qml</file>
         <file>basic/Basic.qml</file>
         <file>effects/Effect.qml</file>