mirror of
https://github.com/jlengrand/korge-samples.git
synced 2026-03-10 08:31:18 +00:00
Update to Korge 2.1.1.1
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
korgePluginVersion=2.0.9.1
|
||||
korgePluginVersion=2.1.1.1
|
||||
#korgePluginVersion=2.0.0.999
|
||||
|
||||
web.bind.port=8080
|
||||
|
||||
org.gradle.jvmargs=-Xmx3g
|
||||
org.gradle.jvmargs=-Xmx5g
|
||||
org.gradle.parallel=true
|
||||
org.gradle.parallel.intra=true
|
||||
org.gradle.configureondemand=true
|
||||
|
||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
@@ -11,7 +11,7 @@ korge {
|
||||
|
||||
//admob("ca-app-pub-xxxxxxxx~yyyyyy")
|
||||
|
||||
bundle("https://github.com/korlibs/korge-bundles.git::korge-box2d::73daf015ca725cc2717fa74213bc870e770ee2cd##fb2e67184e3374a53ba3ab43c28bbe78eeca070a76c3df4f565df169bbede60b")
|
||||
bundle("https://github.com/korlibs/korge-bundles.git::korge-box2d::7439e5c7de7442f2cd33a1944846d44aea31af0a##9fd9d54abd8abc4736fd3439f0904141d9b6a26e9e2f1e1f8e2ed10c51f490fd")
|
||||
|
||||
targetDefault()
|
||||
}
|
||||
|
||||
1
samples/bunnymark-fast/.gitignore
vendored
Normal file
1
samples/bunnymark-fast/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/build
|
||||
7
samples/bunnymark-fast/build.gradle
Normal file
7
samples/bunnymark-fast/build.gradle
Normal file
@@ -0,0 +1,7 @@
|
||||
import com.soywiz.korge.gradle.*
|
||||
|
||||
apply plugin: KorgeGradlePlugin
|
||||
|
||||
korge {
|
||||
targetDefault()
|
||||
}
|
||||
167
samples/bunnymark-fast/src/commonMain/kotlin/main.kt
Normal file
167
samples/bunnymark-fast/src/commonMain/kotlin/main.kt
Normal file
@@ -0,0 +1,167 @@
|
||||
import com.soywiz.kds.*
|
||||
import com.soywiz.kmem.*
|
||||
import com.soywiz.korag.*
|
||||
import com.soywiz.korag.shader.*
|
||||
import com.soywiz.korge.*
|
||||
import com.soywiz.korge.input.*
|
||||
import com.soywiz.korge.render.*
|
||||
import com.soywiz.korge.resources.*
|
||||
import com.soywiz.korge.view.*
|
||||
import com.soywiz.korim.bitmap.*
|
||||
import com.soywiz.korim.bitmap.effect.*
|
||||
import com.soywiz.korim.color.*
|
||||
import com.soywiz.korim.font.*
|
||||
import com.soywiz.korim.format.*
|
||||
import com.soywiz.korio.file.std.*
|
||||
import com.soywiz.korio.resources.*
|
||||
import com.soywiz.korio.lang.*
|
||||
import com.soywiz.korio.async.*
|
||||
import com.soywiz.korma.geom.*
|
||||
import kotlin.random.*
|
||||
import com.soywiz.klock.*
|
||||
import com.soywiz.korge.view.fast.*
|
||||
|
||||
// @TODO: We could autogenerate this via gradle
|
||||
val ResourcesContainer.korge_png by resourceBitmap("korge.png")
|
||||
|
||||
class BunnyContainer(maxSize: Int) : FSprites(maxSize) {
|
||||
val speeds = FBuffer(maxSize * Float.SIZE_BYTES * 2).f32
|
||||
var FSprite.speedXf: Float get() = speeds[index * 2 + 0] ; set(value) { speeds[index * 2 + 0] = value }
|
||||
var FSprite.speedYf: Float get() = speeds[index * 2 + 1] ; set(value) { speeds[index * 2 + 1] = value }
|
||||
//var FSprite.tex: BmpSlice
|
||||
}
|
||||
|
||||
/*
|
||||
class Bunny(tex: BmpSlice) : FastSprite(tex) {
|
||||
var speedXf: Float = 0f
|
||||
var speedYf: Float = 0f
|
||||
}
|
||||
*/
|
||||
|
||||
// bunnymark ported from PIXI.js
|
||||
// https://www.goodboydigital.com/pixijs/bunnymark/
|
||||
// https://www.goodboydigital.com/pixijs/bunnymark/js/bunnyBenchMark.js
|
||||
suspend fun main() = Korge(width = 800, height = 600, bgcolor = Colors["#2b2b9b"], batchMaxQuads = BatchBuilder2D.MAX_BATCH_QUADS) {
|
||||
println("currentThreadId=$currentThreadId")
|
||||
delay(1.milliseconds)
|
||||
println("currentThreadId=$currentThreadId")
|
||||
println("ag.graphicExtensions=${ag.graphicExtensions}")
|
||||
println("ag.isFloatTextureSupported=${ag.isFloatTextureSupported}")
|
||||
println("ag.isInstancedSupported=${ag.isInstancedSupported}")
|
||||
//suspend fun main() = Korge(width = 800, height = 600, bgcolor = Colors["#2b2b9b"]) {
|
||||
val wabbitTexture = resourcesVfs["bunnys.png"].readBitmap()
|
||||
|
||||
val bunny1 = wabbitTexture.sliceWithSize(2, 47, 26, 37)
|
||||
val bunny2 = wabbitTexture.sliceWithSize(2, 86, 26, 37)
|
||||
val bunny3 = wabbitTexture.sliceWithSize(2, 125, 26, 37)
|
||||
val bunny4 = wabbitTexture.sliceWithSize(2, 164, 26, 37)
|
||||
val bunny5 = wabbitTexture.sliceWithSize(2, 2, 26, 37)
|
||||
|
||||
val startBunnyCount = 2
|
||||
//val startBunnyCount = 1_000_000
|
||||
// val startBunnyCount = 200_000
|
||||
val bunnyTextures = listOf(bunny1, bunny2, bunny3, bunny4, bunny5)
|
||||
var currentTexture = bunny1
|
||||
|
||||
val bunnys = BunnyContainer(800_000)
|
||||
addChild(bunnys.createView(wabbitTexture))
|
||||
|
||||
val font = DefaultTtfFont.toBitmapFont(fontSize = 16.0, effect = BitmapEffect(dropShadowX = 1, dropShadowY = 1, dropShadowRadius = 1))
|
||||
val bunnyCountText = text("", font = font, textSize = 16.0, alignment = com.soywiz.korim.text.TextAlignment.TOP_LEFT).position(16.0, 16.0)
|
||||
|
||||
|
||||
val random = Random(0)
|
||||
|
||||
fun addBunny(count: Int = 1) {
|
||||
for (n in 0 until kotlin.math.min(count, bunnys.available)) {
|
||||
bunnys.apply {
|
||||
val bunny = alloc()
|
||||
bunny.speedXf = random.nextFloat() * 1
|
||||
bunny.speedYf = (random.nextFloat() * 1) - 5
|
||||
bunny.setAnchor(.5f, 1f)
|
||||
//bunny.width = 10f
|
||||
//bunny.height = 20f
|
||||
//bunny.alpha = 0.3f + random.nextFloat() * 0.7f
|
||||
bunny.setTex(currentTexture)
|
||||
bunny.scale(0.5f + random.nextFloat() * 0.5f)
|
||||
bunny.radiansf = (random.nextFloat() - 0.5f)
|
||||
}
|
||||
}
|
||||
bunnyCountText.text = "(WIP) KorGE Bunnymark. Bunnies: ${bunnys.size}"
|
||||
}
|
||||
|
||||
addBunny(startBunnyCount)
|
||||
|
||||
val maxX = width.toFloat()
|
||||
val minX = 0f
|
||||
val maxY = height.toFloat()
|
||||
val minY = 0f
|
||||
val gravity = 0.5f // 1.5f
|
||||
|
||||
mouse {
|
||||
up {
|
||||
currentTexture = bunnyTextures.random(random)
|
||||
}
|
||||
}
|
||||
|
||||
addUpdater {
|
||||
if (views.input.mouseButtons != 0) {
|
||||
if (bunnys.size < 200_000) {
|
||||
addBunny(2_000)
|
||||
} else if (bunnys.size < bunnys.maxSize - 1000) {
|
||||
addBunny(4_000)
|
||||
}
|
||||
}
|
||||
bunnys.fastForEach { bunny ->
|
||||
bunny.x += bunny.speedXf
|
||||
bunny.y += bunny.speedYf
|
||||
bunny.speedYf += gravity
|
||||
|
||||
if (bunny.x > maxX) {
|
||||
bunny.speedXf *= -1
|
||||
bunny.x = maxX
|
||||
} else if (bunny.x < minX) {
|
||||
bunny.speedXf *= -1
|
||||
bunny.x = minX
|
||||
}
|
||||
|
||||
if (bunny.y > maxY) {
|
||||
bunny.speedYf *= -0.85f
|
||||
bunny.y = maxY
|
||||
bunny.radiansf = (random.nextFloat() - 0.5f) * 0.2f
|
||||
if (random.nextFloat() > 0.5) {
|
||||
bunny.speedYf -= random.nextFloat() * 6
|
||||
}
|
||||
} else if (bunny.y < minY) {
|
||||
bunny.speedYf = 0f
|
||||
bunny.y = minY
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
suspend fun main() {
|
||||
//GLOBAL_CHECK_GL = true
|
||||
Korge(width = 512, height = 512, bgcolor = Colors["#2b2b2b"], clipBorders = false) {
|
||||
gameWindow.icon = korge_png.get().bmp.toBMP32().scaled(32, 32)
|
||||
val minDegrees = (-16).degrees
|
||||
val maxDegrees = (+16).degrees
|
||||
val image = image(korge_png) {
|
||||
//val image = image(resourcesVfs["korge.png"].readbitmapslice) {
|
||||
rotation = maxDegrees
|
||||
anchor(.5, .5)
|
||||
scale(.8)
|
||||
position(256, 256)
|
||||
}
|
||||
addChild(MyView())
|
||||
//bindLength(image::scaledWidth) { 100.vw }
|
||||
//bindLength(image::scaledHeight) { 100.vh }
|
||||
while (true) {
|
||||
image.tween(image::rotation[minDegrees], time = 1.seconds, easing = Easing.EASE_IN_OUT)
|
||||
image.tween(image::rotation[maxDegrees], time = 1.seconds, easing = Easing.EASE_IN_OUT)
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
BIN
samples/bunnymark-fast/src/commonMain/resources/bunnys.png
Normal file
BIN
samples/bunnymark-fast/src/commonMain/resources/bunnys.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
@@ -23,7 +23,7 @@ import kotlin.random.Random
|
||||
|
||||
class Bunny(tex: BmpSlice) : FastSprite(tex) {
|
||||
// Temporal placeholder until FastSpriteContainer supports rotation
|
||||
var rotationRadiansf: Float = 0f
|
||||
//override var rotationRadiansf: Float = 0f
|
||||
var speedXf: Float = 0f
|
||||
var speedYf: Float = 0f
|
||||
var spinf: Float = 0f
|
||||
@@ -72,7 +72,7 @@ suspend fun main() = Korge(width = 800, height = 600, bgcolor = Colors["#2b2b9b"
|
||||
bunny.anchorXf = .5f
|
||||
bunny.anchorYf = 1f
|
||||
//bunny.alpha = 0.3 + Math.random() * 0.7;
|
||||
bunny.scalef = 0.5f + random.nextFloat() * 0.5f
|
||||
bunny.scale(0.5f + random.nextFloat() * 0.5f)
|
||||
bunny.rotationRadiansf = (random.nextFloat() - 0.5f)
|
||||
//bunny.rotation = Math.random() - 0.5;
|
||||
//var random = random.nextInt(0, container.numChildren-2);
|
||||
|
||||
@@ -16,6 +16,7 @@ suspend fun main() = Korge(width = 512, height = 512, bgcolor = Colors["#2b2b2b"
|
||||
view.position(random[0, 512], random[0, 512])
|
||||
|
||||
frameBlock(60.timesPerSecond) {
|
||||
//view.frameBlock(60.timesPerSecond) {
|
||||
while (true) {
|
||||
val targetX = random[0, 512].toDouble()
|
||||
val targetY = random[0, 512].toDouble()
|
||||
|
||||
@@ -397,7 +397,7 @@ fun audioOutCallback(channel: Int, buf: ShortArray, reqn: Int = buf.size, bufn:
|
||||
state.currentsampleIndex += state.currentsampleIncrement
|
||||
if (state.currentsampleIndex >= SAMPLE_COUNT) state.currentsampleIndex -= SAMPLE_COUNT.toFloat()
|
||||
}
|
||||
val rvalue = value.clamp(Short.MIN_VALUE.toFloat(), Short.MAX_VALUE.toFloat()).toShort()
|
||||
val rvalue = value.clamp(Short.MIN_VALUE.toFloat(), Short.MAX_VALUE.toFloat()).toInt().toShort()
|
||||
//for (n in 0 until nchannels) buf[bufn++] = value.toShort()
|
||||
buf[bufn++] = rvalue
|
||||
//buf[bufn++] = rvalue
|
||||
|
||||
@@ -18,10 +18,12 @@ import com.soywiz.korma.interpolation.*
|
||||
suspend fun main() = Korge(quality = GameWindow.Quality.PERFORMANCE, title = "UI") {
|
||||
val nativeProcess = NativeProcess(views)
|
||||
|
||||
defaultUISkin = OtherUISkin()
|
||||
defaultUIFont = resourcesVfs["uifont.fnt"].readBitmapFont()
|
||||
//uiSkin =
|
||||
//uiSkin = OtherUISkin().also {
|
||||
// it.textFont = resourcesVfs["uifont.fnt"].readBitmapFont()
|
||||
//}
|
||||
|
||||
uiTextButton(256.0, 32.0) {
|
||||
uiButton(256.0, 32.0) {
|
||||
text = "Disabled Button"
|
||||
position(128, 128)
|
||||
onClick {
|
||||
@@ -29,7 +31,7 @@ suspend fun main() = Korge(quality = GameWindow.Quality.PERFORMANCE, title = "UI
|
||||
}
|
||||
disable()
|
||||
}
|
||||
uiTextButton(256.0, 32.0) {
|
||||
uiButton(256.0, 32.0) {
|
||||
text = "Enabled Button"
|
||||
position(128, 128 + 32)
|
||||
onClick {
|
||||
@@ -90,13 +92,10 @@ suspend fun OtherUISkin(): UISkin = OtherUISkinOnce {
|
||||
//val ui = resourcesVfs["korge-ui.png"].readNativeImage().toBMP32().withColorTransform(otherColorTransform)
|
||||
val ui = resourcesVfs["korge-ui.png"].readNativeImage()
|
||||
|
||||
DefaultUISkin.copy(
|
||||
normal = ui.sliceWithSize(0, 0, 64, 64),
|
||||
over = ui.sliceWithSize(64, 0, 64, 64),
|
||||
down = ui.sliceWithSize(127, 0, 64, 64),
|
||||
backColor = DefaultUISkin.backColor.transform(otherColorTransform)
|
||||
//,
|
||||
//font = Html.FontFace.Bitmap(getDebugBmpFontOnce())
|
||||
//font = Html.FontFace.Bitmap(resourcesVfs["uifont.fnt"].readBitmapFontWithMipmaps())
|
||||
)
|
||||
UISkin {
|
||||
buttonNormal = ui.sliceWithSize(0, 0, 64, 64).asNinePatchSimpleRatio(0.25, 0.25, 0.75, 0.75)
|
||||
buttonOver = ui.sliceWithSize(64, 0, 64, 64).asNinePatchSimpleRatio(0.25, 0.25, 0.75, 0.75)
|
||||
buttonDown = ui.sliceWithSize(127, 0, 64, 64).asNinePatchSimpleRatio(0.25, 0.25, 0.75, 0.75)
|
||||
buttonBackColor = buttonBackColor.transform(otherColorTransform)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
enableFeaturePreview("GRADLE_METADATA")
|
||||
|
||||
/*
|
||||
for (file in rootDir.listFiles()) {
|
||||
if (file.isDirectory() && file.name.startsWith("") && (new File(file, "build.gradle").exists() || new File(file, "build.gradle.kts").exists())) {
|
||||
|
||||
Reference in New Issue
Block a user