Skip to content

Commit

Permalink
Update bunnymark to new benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
chippmann committed Oct 14, 2024
1 parent 7d19352 commit c16626e
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ import godot.Node2D
import godot.RandomNumberGenerator
import godot.ResourceLoader
import godot.Texture2D
import godot.annotation.RegisterClass
import godot.annotation.RegisterFunction
import godot.annotation.RegisterSignal
import godot.annotation.GodotMember
import godot.annotation.GodotScript
import godot.core.Vector2
import godot.signals.signal
import godot.core.signal1

@RegisterClass("BunnymarkV1DrawTexture")
@GodotScript("BunnymarkV1DrawTexture")
class BunnymarkV1DrawTexture : Node2D() {

@RegisterSignal
val benchmarkFinished by signal<Int>("bunnyCount")
val benchmarkFinished by signal1<Int>("bunnyCount")

data class Bunny(var position: Vector2, var speed: Vector2)

Expand All @@ -25,19 +23,16 @@ class BunnymarkV1DrawTexture : Node2D() {

private lateinit var screenSize: Vector2

@RegisterFunction
override fun _ready() {
randomNumberGenerator.randomize()
}

@RegisterFunction
override fun _draw() {
for (bunny in bunnies) {
drawTexture(bunnyTexture, bunny.position)
}
}

@RegisterFunction
override fun _process(delta: Double) {
screenSize = getViewportRect().size

Expand Down Expand Up @@ -80,7 +75,7 @@ class BunnymarkV1DrawTexture : Node2D() {
queueRedraw()
}

@RegisterFunction
@GodotMember
fun addBunny() {
bunnies.add(
Bunny(
Expand All @@ -90,13 +85,13 @@ class BunnymarkV1DrawTexture : Node2D() {
)
}

@RegisterFunction
@GodotMember
fun removeBunny() {
if (bunnies.size == 0) return
bunnies.removeAt(bunnies.size - 1)
}

@RegisterFunction
@GodotMember
fun finish() {
benchmarkFinished.emit(bunnies.size)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package godot.benchmark.bunnymark

import godot.core.*
import godot.*
import godot.annotation.RegisterClass
import godot.annotation.RegisterFunction
import godot.annotation.RegisterSignal
import godot.signals.signal

@RegisterClass("BunnymarkV1Sprites")
import godot.Node2D
import godot.RandomNumberGenerator
import godot.ResourceLoader
import godot.Sprite2D
import godot.Texture2D
import godot.annotation.GodotMember
import godot.annotation.GodotScript
import godot.core.Vector2
import godot.core.signal1


@GodotScript("BunnymarkV1Sprites")
class BunnymarkV1Sprites : Node2D() {

@RegisterSignal
val benchmarkFinished by signal<Int>("bunnyCount")
val benchmarkFinished by signal1<Int>("bunnyCount")

private data class Bunny(var sprite: Sprite2D, var speed: Vector2)

Expand All @@ -22,12 +25,10 @@ class BunnymarkV1Sprites : Node2D() {

private lateinit var screenSize: Vector2

@RegisterFunction
override fun _ready() {
randomNumberGenerator.randomize()
}

@RegisterFunction
override fun _process(delta: Double) {
screenSize = getViewportRect().size

Expand Down Expand Up @@ -69,7 +70,7 @@ class BunnymarkV1Sprites : Node2D() {
}
}

@RegisterFunction
@GodotMember
fun addBunny() {
val bunny = Sprite2D()
bunny.texture = bunnyTexture
Expand All @@ -83,7 +84,7 @@ class BunnymarkV1Sprites : Node2D() {
)
}

@RegisterFunction
@GodotMember
fun removeBunny() {
if (bunnies.size == 0) return
val bunny = bunnies[bunnies.size - 1]
Expand All @@ -92,7 +93,7 @@ class BunnymarkV1Sprites : Node2D() {
bunny.sprite.queueFree()
}

@RegisterFunction
@GodotMember
fun finish() {
benchmarkFinished.emit(bunnies.size)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package godot.benchmark.bunnymark

import godot.core.*
import godot.*
import godot.annotation.RegisterClass
import godot.annotation.RegisterFunction
import godot.annotation.RegisterSignal
import godot.signals.signal

@RegisterClass("BunnymarkV2")
import godot.Label
import godot.Node2D
import godot.RandomNumberGenerator
import godot.ResourceLoader
import godot.Sprite2D
import godot.Texture2D
import godot.annotation.GodotMember
import godot.annotation.GodotScript
import godot.core.Vector2
import godot.core.signal1

@GodotScript("BunnymarkV2")
class BunnymarkV2 : Node2D() {

@RegisterSignal
val benchmarkFinished by signal<Int>("bunnyCount")
val benchmarkFinished by signal1<Int>("bunnyCount")

private val gravity = 500
private val bunnySpeeds = mutableListOf<Vector2>()
Expand All @@ -22,15 +25,13 @@ class BunnymarkV2 : Node2D() {

private lateinit var screenSize: Vector2

@RegisterFunction
override fun _ready() {
randomNumberGenerator.randomize()
addChild(bunnies)
label.setPosition(Vector2(0, 20))
addChild(label)
}

@RegisterFunction
override fun _process(delta: Double) {
screenSize = getViewportRect().size
label.text = "Bunnies: " + bunnies.getChildCount().toString()
Expand Down Expand Up @@ -75,7 +76,7 @@ class BunnymarkV2 : Node2D() {
}
}

@RegisterFunction
@GodotMember
fun addBunny() {
val bunny = Sprite2D()
bunny.texture = bunnyTexture
Expand All @@ -86,7 +87,7 @@ class BunnymarkV2 : Node2D() {
)
}

@RegisterFunction
@GodotMember
fun removeBunny() {
val childCount = bunnies.getChildCount()
if (childCount == 0) return
Expand All @@ -99,7 +100,7 @@ class BunnymarkV2 : Node2D() {
bunnySpeeds.removeAt(childCount.toInt() - 1)
}

@RegisterFunction
@GodotMember
fun finish() {
benchmarkFinished.emit(bunnySpeeds.size)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package godot.benchmark.bunnymark

import godot.*
import godot.annotation.RegisterClass
import godot.annotation.RegisterFunction
import godot.annotation.RegisterSignal
import godot.Label
import godot.Node2D
import godot.RandomNumberGenerator
import godot.ResourceLoader
import godot.Texture2D
import godot.annotation.GodotMember
import godot.annotation.GodotScript
import godot.benchmark.bunnymark.v3.Bunny
import godot.core.Vector2
import godot.signals.signal
import godot.core.signal1

@RegisterClass("BunnymarkV3")
@GodotScript("BunnymarkV3")
class BunnymarkV3 : Node2D() {

@RegisterSignal
val benchmarkFinished by signal<Int>("bunnyCount")
val benchmarkFinished by signal1<Int>("bunnyCount")

private val randomNumberGenerator = RandomNumberGenerator()
private val bunnyTexture = ResourceLoader.load("res://images/godot_bunny.png") as Texture2D
Expand All @@ -21,7 +23,6 @@ class BunnymarkV3 : Node2D() {

private lateinit var screenSize: Vector2

@RegisterFunction
override fun _ready() {
randomNumberGenerator.randomize()
addChild(bunnies)
Expand All @@ -30,13 +31,12 @@ class BunnymarkV3 : Node2D() {
addChild(label)
}

@RegisterFunction
override fun _process(delta: Double) {
screenSize = getViewportRect().size
label.text = "Bunnies ${bunnies.getChildCount()}"
}

@RegisterFunction
@GodotMember
fun addBunny() {
val bunny = Bunny()
bunny.texture = bunnyTexture
Expand All @@ -45,7 +45,7 @@ class BunnymarkV3 : Node2D() {
bunny.speed = Vector2(randomNumberGenerator.randi() % 200 + 50, randomNumberGenerator.randi() % 200 + 50)
}

@RegisterFunction
@GodotMember
fun removeBunny() {
val childCount = bunnies.getChildCount()
if (childCount != 0) {
Expand All @@ -55,7 +55,7 @@ class BunnymarkV3 : Node2D() {
}
}

@RegisterFunction
@GodotMember
fun finish() {
benchmarkFinished.emit(bunnies.getChildCount())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package godot.benchmark.bunnymark.v3

import godot.RandomNumberGenerator
import godot.Sprite2D
import godot.annotation.RegisterClass
import godot.annotation.RegisterFunction
import godot.annotation.GodotScript
import godot.core.Vector2

@RegisterClass
@GodotScript
class Bunny : Sprite2D() {

var speed = Vector2()
Expand All @@ -15,12 +14,10 @@ class Bunny : Sprite2D() {
private lateinit var screenSize: Vector2
private val randomNumberGenerator = RandomNumberGenerator()

@RegisterFunction
override fun _ready() {
randomNumberGenerator.randomize()
}

@RegisterFunction
override fun _process(delta: Double) {
screenSize = getViewportRect().size
val pos = position
Expand Down

0 comments on commit c16626e

Please sign in to comment.