8000 Prototype new animator, supporting attaching new nodes on the fly by soywiz · Pull Request #1095 · korlibs/korge · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Prototype new animator, supporting attaching new nodes on the fly #1095

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ KorGE and all the other korlibs in a single monorepo.

To use this version in other projects,
you have to publish it locally to mavenLocal,
and then use `2.0.0.999` as version:
and then use `999.0.0.999` as version:

```shell script
./gradlew publishToMavenLocal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ object BuildVersions {
const val COROUTINES = "1.6.1"
const val ANDROID_BUILD = "7.0.3"
const val KOTLIN_SERIALIZATION = "1.3.2"
const val KRYPTO = "2.0.0.999"
const val KLOCK = "2.0.0.999"
const val KDS = "2.0.0.999"
const val KMEM = "2.0.0.999"
const val KORMA = "2.0.0.999"
const val KORIO = "2.0.0.999"
const val KORIM = "2.0.0.999"
const val KORAU = "2.0.0.999"
const val KORGW = "2.0.0.999"
const val KORGE = "2.0.0.999"
const val KRYPTO = "999.0.0.999"
const val KLOCK = "999.0.0.999"
const val KDS = "999.0.0.999"
const val KMEM = "999.0.0.999"
const val KORMA = "999.0.0.999"
const val KORIO = "999.0.0.999"
const val KORIM = "999.0.0.999"
const val KORAU = "999.0.0.999"
const val KORGW = "999.0.0.999"
const val KORGE = "999.0.0.999"

val ALL_PROPERTIES by lazy { listOf(::GIT, ::KRYPTO, ::KLOCK, ::KDS, ::KMEM, ::KORMA, ::KORIO, ::KORIM, ::KORAU, ::KORGW, ::KORGE, ::KOTLIN, ::JNA, ::COROUTINES, ::ANDROID_BUILD, ::KOTLIN_SERIALIZATION) }
val ALL by lazy { ALL_PROPERTIES.associate { it.name to it.get() } }
}
}
2 changes: 1 addition & 1 deletion e2e-sample/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
korgePluginVersion=2.0.0.999
korgePluginVersion=999.0.0.999
org.gradle.jvmargs=-Xmx4g
kotlin.mpp.stability.nowarn=true

Expand Down
2 changes: 1 addition & 1 deletion e2e-test/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
korgePluginVersion=2.0.0.999
korgePluginVersion=999.0.0.999
#korgePluginVersion=2.6.3
org.gradle.jvmargs=-Xmx4g
kotlin.mpp.stability.nowarn=true
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=2.0.0.999
version=999.0.0.999

android.useAndroidX=true

Expand Down
23 changes: 20 additions & 3 deletions kds/src/concurrentMain/kotlin/com/soywiz/kds/NonJs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public actual open class FastArrayList<E> internal constructor(
@PublishedApi internal var _size: Int = array.size,
@PublishedApi internal var arrayCapacity: Int = array.size
) : AbstractMutableList<E>(), MutableList<E>, RandomAccess {
//) : MutableList<E>, RandomAccess {
private var isReadOnly: Boolean = false

/**
Expand Down Expand Up @@ -111,9 +112,25 @@ public actual open class FastArrayList<E> internal constructor(
_removeRange(0, size)
}

// @TODO: This is checking nulls too since backing array is bigger, should we do a plain for?
actual override fun indexOf(element: E): Int = array.indexOf(element)
actual override fun lastIndexOf(element: E): Int = array.lastIndexOf(element)
actual override fun contains(element: E): Boolean = indexOf(element) >= 0

actual override fun indexOf(element: E): Int {
for (index in 0 until size) {
if (this[index] == element) {
return index
}
}
return -1
}
actual override fun lastIndexOf(element: E): Int {
for (index in 0 until size) {
val i = size - index - 1
if (this[i] == element) {
return i
}
}
return -1
}

override fun toString(): String {
val sb = StringBuilder()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.soywiz.kds

import kotlin.test.*

class FastArrayListNativeTest {
@Test
fun testContainsAndIndexOf() {
val a = fastArrayListOf<String?>("a", "b")
assertEquals(listOf("a", "b"), a.array.toList())
assertEquals(listOf(true, true, false), listOf(a.contains("a"), a.contains("b"), a.contains(null)))
assertEquals(listOf(0, 1, -1), listOf(a.indexOf("a"), a.indexOf("b"), a.indexOf(null)))
assertEquals(listOf(0, 1, -1), listOf(a.lastIndexOf("a"), a.lastIndexOf("b"), a.lastIndexOf(null)))
a.removeAt(1)
assertEquals(listOf("a", null), a.array.toList())
assertEquals(listOf(true, false, false), listOf(a.contains("a"), a.contains("b"), a.contains(null)))
assertEquals(listOf(0, -1, -1), listOf(a.indexOf("a"), a.indexOf("b"), a.indexOf(null)))
assertEquals(listOf(0, -1, -1), listOf(a.lastIndexOf("a"), a.lastIndexOf("b"), a.lastIndexOf(null)))
a.add(null)
assertEquals(listOf("a", null), a.array.toList())
assertEquals(listOf(true, false, true), listOf(a.contains("a"), a.contains("b"), a.contains(null)))
assertEquals(listOf(0, -1, 1), listOf(a.indexOf("a"), a.indexOf("b"), a.indexOf(null)))
assertEquals(listOf(0, -1, 1), listOf(a.lastIndexOf("a"), a.lastIndexOf("b"), a.lastIndexOf(null)))

assertEquals(2, fastArrayListOf("a", "b", "a").lastIndexOf("a"))
assertEquals(1, fastArrayListOf("a", "b", "a").lastIndexOf("b"))
assertEquals(-1, fastArrayListOf("a", "b", "a").lastIndexOf("c"))
}
}
4 changes: 4 additions & 0 deletions klock/src/commonMain/kotlin/com/soywiz/klock/RangesExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.soywiz.klock

public fun TimeSpan.convertRange(srcMin: TimeSpan, srcMax: TimeSpan, dstMin: TimeSpan, dstMax: TimeSpan): TimeSpan = (dstMin + (dstMax - dstMin) * ((this - srcMin) / (srcMax - srcMin)))
public fun DateTime.convertRange(srcMin: DateTime, srcMax: DateTime, dstMin: DateTime, dstMax: DateTime): DateTime = (dstMin + (dstMax - dstMin) * ((this - srcMin) / (srcMax - srcMin)))
5 changes: 4 additions & 1 deletion klock/src/commonMain/kotlin/com/soywiz/klock/TimeSpan.kt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ value class TimeSpan(
operator fun rem(other: TimeSpan): TimeSpan = (this.milliseconds % other.milliseconds).milliseconds
infix fun umod(other: TimeSpan): TimeSpan = (this.milliseconds umod other.milliseconds).milliseconds

/** Return true if [TimeSpan.NIL] */
val isNil: Boolean get() = milliseconds.isNaN()

companion object {
@Suppress("MayBeConstant", "unused")
private const val serialVersionUID = 1L
Expand All @@ -156,7 +159,7 @@ value class TimeSpan(

/**
* Represents an invalid TimeSpan.
* Useful to represent an alternative "null" time lapse
* Useful to represent an alternative "null" time-lapse
* avoiding the boxing of a nullable type.
*/
val NIL = TimeSpan(Double.NaN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class TimeSpanTest {
fun testNull() {
assertTrue { TimeSpan.ZERO != TimeSpan.NIL }
assertTrue { TimeSpan.NIL == TimeSpan.NIL }
assertTrue { TimeSpan.NIL.isNil }
}

@Test
Expand Down
3 changes: 2 additions & 1 deletion korge-sandbox/src/commonMain/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ suspend fun main() = Korge(
//Demo(::MainTextBounds),
//Demo(::MainEditor),
//Demo(::MainStage3d),
Demo(::MainInput),
//Demo(::MainInput),
Demo(::MainAnimations),
//Demo(::MainSvgAnimation),
//Demo(::MainVectorNinePatch),
listOf(
Expand Down
64 changes: 49 additions & 15 deletions korge-sandbox/src/commonMain/kotlin/samples/MainAnimations.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package samples

import com.soywiz.klock.seconds
import com.soywiz.korge.animate.AnimateCancellationException
import com.soywiz.korge.animate.animate
import com.soywiz.korge.input.onClick
import com.soywiz.klock.*
import com.soywiz.korev.*
import com.soywiz.korge.animate.*
import com.soywiz.korge.input.*
import com.soywiz.korge.scene.ScaledScene
import com.soywiz.korge.scene.Scene
import com.soywiz.korge.view.SContainer
import com.soywiz.korge.view.position
import com.soywiz.korge.view.solidRect
import com.soywiz.korim.color.Colors
import com.soywiz.korio.async.launchImmediately
import com.soywiz.korio.async.*
import kotlinx.coroutines.Job

class MainAnimations : ScaledScene(512, 512) {
Expand All @@ -30,44 +29,79 @@ class MainAnimations : ScaledScene(512, 512) {
}
}

val signal = Signal<Unit>()

keys {
down(Key.RETURN) { signal.invoke() }
}

val time = Stopwatch()

while (true) {
println("START!")
time.start()
job = launchImmediately {
animate(completeOnCancel = false) {
//animate(completeOnCancel = false) {
//animate(completeOnCancel = true) {
//animate {
sequence(time = 1.seconds, speed = 256.0) {
sequence(defaultTime = 1.seconds, defaultSpeed = 256.0) {
//wait(0.25.seconds)
block {
println("[0] ${time.elapsed}")
}
parallel {
//rect1.moveTo(0, 150)
rect1.moveToWithSpeed(width - 100, 0.0)
rect2.moveToWithSpeed(0.0, height - 100 - 100)
moveToWithSpeed(rect1, width - 100, 0.0)
moveToWithSpeed(rect2, 0.0, height - 100 - 100)
//rect1.moveTo(0, height - 100)
}
block {
println("[1] ${time.elapsed}")
}
parallel {
//rect1.moveTo(0, 150)
rect1.moveTo(width - 100, height - 100)
rect2.moveTo(width - 100, height - 100)
moveTo(rect1, width - 100, height - 100)
moveTo(rect2, width - 100, height - 100)
//rect1.moveTo(0, height - 100)
}
block {
println("[2] ${time.elapsed}")
}
parallel(time = 1.seconds) {
rect1.hide()
rect2.hide()
//alpha(rect1, 0.5)
//alpha(rect2, 0.5)
hide(rect1)
hide(rect2)
}
block {
println("[3] ${time.elapsed}")
}
block {
//printStackTrace()
//println("ZERO")
rect1.position(0, 0)
rect2.position(0, 0)
}
block {
println("[4] ${time.elapsed}")
}
parallel(time = 0.5.seconds) {
rect1.show()
rect2.show()
show(rect1)
show(rect2)
}
block {
println("[5] ${time.elapsed}")
}
wait(0.25.seconds)
block {
println("[6] ${time.elapsed}")
}
}
}
}
job.join()
//signal.waitOne()
//println("[a]")
//delay(1.seconds)
//println("[b]")
Expand Down
6 changes: 4 additions & 2 deletions korge-sandbox/src/commonMain/kotlin/samples/MainFilters.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package samples

import com.soywiz.klock.seconds
import com.soywiz.korge.animate.animateParallel
import com.soywiz.korge.animate.*
import com.soywiz.korge.scene.ScaledScene
import com.soywiz.korge.tween.get
import com.soywiz.korge.view.SContainer
Expand Down Expand Up @@ -68,7 +68,9 @@ class MainFilters : ScaledScene(768, 512) {
filter = swizzle
}

animateParallel {
animate(parallel = true) {
autoInvalidateView = true
//animateParallel {
sequence(looped = true) {
tween(wave::time[1.seconds], time = 1.seconds, easing = Easing.EASE_IN_OUT)
tween(wave::time[0.seconds], time = 1.seconds, easing = Easing.EASE_IN_OUT)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package samples

import com.soywiz.klock.*
import com.soywiz.korge.animate.animateParallel
import com.soywiz.korge.animate.*
import com.soywiz.korge.scene.Scene
import com.soywiz.korge.tween.get
import com.soywiz.korge.view.*
Expand Down Expand Up @@ -61,7 +61,7 @@ class MainFiltersSample : Scene() {

//addUpdater { invalidate() }

animateParallel {
animate(parallel = true) {
sequence(looped = true) {
tween(wave::time[1.seconds], time = 1.seconds, easing = Easing.EASE_IN_OUT)
tween(wave::time[0.seconds], time = 1.seconds, easing = Easing.EASE_IN_OUT)
Expand Down
2 changes: 1 addition & 1 deletion korge-sandbox/src/commonMain/kotlin/samples/MainMasks.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package samples

import com.soywiz.klock.seconds
import com.soywiz.korge.animate.animate
import com.soywiz.korge.animate.*
import com.soywiz.korge.scene.Scene
import com.soywiz.korge.tween.get
import com.soywiz.korge.view.SContainer
Expand Down
9 changes: 5 additions & 4 deletions korge-sandbox/src/commonMain/kotlin/samples/connect4/main.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package samples.connect4

import com.soywiz.kds.Array2
import com.soywiz.korge.animate.animate
import com.soywiz.korge.animate.*
import com.soywiz.korge.input.mouse
import com.soywiz.korge.scene.ScaledScene
import com.soywiz.korge.tween.get
Expand All @@ -14,6 +14,7 @@ import com.soywiz.korge.view.container
import com.soywiz.korge.view.image
import com.soywiz.korge.view.position
import com.soywiz.korge.view.solidRect
import com.soywiz.korge.view.tween.*
import com.soywiz.korim.bitmap.Bitmap32
import com.soywiz.korim.bitmap.context2d
import com.soywiz.korim.color.ColorAdd
Expand Down Expand Up @@ -78,7 +79,7 @@ class MainConnect4 : ScaledScene(448, 384) {
var gameFinished = false

suspend fun drop(chip: Chip, column: Int) {
animate(speed = 128.0) {
animate(defaultSpeed = 128.0) {
val result = board.apply(Operation.Place(chip, column))
if (result != null) {
if (result.board.winner() != null) {
Expand All @@ -95,13 +96,13 @@ class MainConnect4 : ScaledScene(448, 384) {
val r = action.row
val pos = getPosition(c, r)
val chipView = createChip(column, -1, action.chip)
chipView.moveTo(pos.x, pos.y)
moveTo(chipView, pos.x, pos.y)
views[c, r] = chipView
}
is Action.Finish -> {
for (pos in action.win.positions) {
val view = views[pos.column, pos.row]
tween({ view::colorAdd[ColorAdd(255, 255, 255, 0)] }, time = this.time)
tweenLazy({ view::colorAdd[ColorAdd(255, 255, 255, 0)] })
}
}
}
Expand Down
Loading
0