-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to korlibs 6.0.0-alpha4 and split korge into korge and korge-c…
…ore (#2243) * Update to korlibs 6.0.0-alpha4 * Split korge into korge-core and korge * Add KorgeCore function to start Korge without the views system
- Loading branch information
Showing
258 changed files
with
509 additions
and
319 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import korlibs.applyProjectProperties | ||
|
||
description = "Multiplatform Game Engine written in Kotlin" | ||
|
||
project.extensions.extraProperties.properties.apply { | ||
applyProjectProperties( | ||
"https://github.com/korlibs/korge", | ||
"MIT License", | ||
"https://raw.githubusercontent.com/korlibs/korge/master/LICENSE" | ||
) | ||
} | ||
|
||
dependencies { | ||
commonMainApi(libs.korlibs.audio) | ||
commonMainApi(libs.korlibs.image) | ||
commonMainApi(libs.korlibs.inject) | ||
commonMainApi(libs.korlibs.template) | ||
commonMainApi(libs.korlibs.time) | ||
commonMainApi(libs.kotlinx.atomicfu) | ||
commonMainApi(libs.kotlinx.coroutines.core) | ||
//commonTestApi(project(":korge-test")) | ||
jvmMainApi("org.jetbrains.kotlin:kotlin-reflect") | ||
jvmMainImplementation(libs.jackson.databind) | ||
jvmMainImplementation(libs.jackson.module.kotlin) | ||
|
||
//commonTestApi(testFixtures(project(":korma"))) | ||
|
||
//add("jvmMainApi", project(":korte")) | ||
|
||
//add("commonTestApi", "it.krzeminski.vis-assert:vis-assert:0.4.0-beta") | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package korlibs.graphics.metal.shader | ||
|
||
import korlibs.graphics.shader.* | ||
import korlibs.korge.internal.* | ||
|
||
@KorgeInternal | ||
fun Pair<VertexShader, FragmentShader>.toNewMetalShaderStringResult(bufferInputsLayout: MetalShaderBufferInputLayouts): MetalShaderGenerator.Result = let { (vertexShader, fragmentShader) -> MetalShaderGenerator(vertexShader, fragmentShader, bufferInputsLayout) } | ||
.generateResult() |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package korlibs.korge | ||
|
||
import korlibs.io.async.* | ||
import korlibs.render.* | ||
import kotlinx.coroutines.* | ||
|
||
/** | ||
* ```kotlin | ||
* suspend fun main() = KorgeCore { | ||
* val stopWatch = Stopwatch().start() | ||
* onRenderEvent { | ||
* ag.clear(ag.mainFrameBuffer, color = Colors.RED.interpolateWith((stopWatch.elapsed.seconds % 1.0).toRatio(), Colors.WHITE)) | ||
* } | ||
* } | ||
* ``` | ||
*/ | ||
suspend fun KorgeCore( | ||
config: GameWindowCreationConfig = GameWindowCreationConfig.DEFAULT, | ||
gameWindow: GameWindow = CreateDefaultGameWindow(config), | ||
block: suspend GameWindow.() -> Unit | ||
) { | ||
//withContext(PreferSyncIo(preferSyncIo = true)) { | ||
withContext(PreferSyncIo(preferSyncIo = null)) { | ||
gameWindow.loop { | ||
block() | ||
} | ||
} | ||
} | ||
|
||
/* | ||
suspefun test() { | ||
KorgeCore { | ||
val gameWindow = this | ||
onRenderEvent { | ||
gameWindow.ag.clear(gameWindow.ag.mainFrameBuffer, color = Colors.RED) | ||
} | ||
} | ||
} | ||
*/ |
15 changes: 8 additions & 7 deletions
15
korge/src/korlibs/korge/KorgeReload.kt → korge-core/src/korlibs/korge/KorgeReload.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...korlibs/korge/bitmapfont/BitmapFontExt.kt → ...korlibs/korge/bitmapfont/BitmapFontExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package korlibs.korge.blend | ||
|
||
import korlibs.graphics.* | ||
import korlibs.image.color.* | ||
|
||
/** | ||
* Determines how pixels should be blended. The most common blend modes are: [NORMAL] (normal mix) and [ADD] (additive blending) along with [MULTIPLY] and others. | ||
* | ||
* [https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendFuncSeparate](https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendFuncSeparate) | ||
* | ||
* ```kotlin | ||
* // color(RGB) = (sourceColor * srcRGB) + (destinationColor * dstRGB) | ||
* // color(A) = (sourceAlpha * srcAlpha) + (destinationAlpha * dstAlpha) | ||
* ``` | ||
*/ | ||
data class BlendMode( | ||
val factors: AGBlending, | ||
val name: String? = null, | ||
) { | ||
val __hashCode: Int = factors.hashCode() + name.hashCode() * 7 | ||
override fun hashCode(): Int = __hashCode | ||
override fun equals(other: Any?): Boolean = (this === other) || (other is BlendMode && this.factors == other.factors && name == other.name) | ||
override fun toString(): String = name ?: super.toString() | ||
|
||
fun apply(src: RGBAf, dst: RGBAf, out: RGBAf = RGBAf()): RGBAf { | ||
return factors.apply(src, dst, out) | ||
} | ||
|
||
fun apply(src: RGBA, dst: RGBA): RGBA { | ||
return factors.apply(src, dst) | ||
} | ||
|
||
companion object { | ||
/** Mixes the source and destination colors using the source alpha value */ | ||
val NORMAL = BlendMode(name = "NORMAL", factors = AGBlending.NORMAL_PRE) | ||
/** Not an actual blending. It is used to indicate that the next non-inherit BlendMode from its ancestors will be used. */ | ||
val INHERIT = NORMAL.copy(name = "INHERIT") | ||
/** Doesn't blend at all. Just replaces the colors. */ | ||
val NONE = BlendMode(name = "NONE", factors = AGBlending(AGBlendFactor.ONE, AGBlendFactor.ZERO)) // REPLACE | ||
/** Additive mixing for lighting effects */ | ||
val ADD = BlendMode(name = "ADD", factors = AGBlending.ADD_PRE) | ||
|
||
// Unchecked | ||
val MULTIPLY = BlendMode(name = "MULTIPLY", factors = AGBlending(AGBlendFactor.DESTINATION_COLOR, AGBlendFactor.ONE_MINUS_SOURCE_ALPHA)) | ||
val SCREEN = BlendMode(name = "SCREEN", factors = AGBlending(AGBlendFactor.ONE, AGBlendFactor.ONE_MINUS_SOURCE_COLOR)) | ||
|
||
val ERASE = BlendMode(name = "ERASE", factors = AGBlending(AGBlendFactor.ZERO, AGBlendFactor.ONE_MINUS_SOURCE_ALPHA)) | ||
val MASK = BlendMode(name = "MASK", factors = AGBlending(AGBlendFactor.ZERO, AGBlendFactor.SOURCE_ALPHA)) | ||
val BELOW = BlendMode(name = "BELOW", factors = AGBlending(AGBlendFactor.ONE_MINUS_DESTINATION_ALPHA, AGBlendFactor.DESTINATION_ALPHA)) | ||
val SUBTRACT = BlendMode( | ||
name = "SUBTRACT", factors = AGBlending( | ||
AGBlendFactor.SOURCE_ALPHA, AGBlendFactor.DESTINATION_ALPHA, | ||
AGBlendFactor.ONE, AGBlendFactor.ONE, | ||
AGBlendEquation.REVERSE_SUBTRACT | ||
) | ||
) | ||
val INVERT = BlendMode( | ||
name = "INVERT", | ||
factors = AGBlending( | ||
AGBlendFactor.ONE_MINUS_DESTINATION_COLOR, AGBlendFactor.ZERO, | ||
AGBlendFactor.ONE, AGBlendFactor.ONE, | ||
) | ||
) | ||
|
||
// Unimplemented | ||
val LIGHTEN = BlendMode( | ||
name = "LIGHTEN", | ||
factors = AGBlending( | ||
AGBlendFactor.SOURCE_ALPHA, AGBlendFactor.DESTINATION_ALPHA, | ||
AGBlendFactor.ONE, AGBlendFactor.ONE | ||
) | ||
) | ||
val DARKEN = BlendMode( | ||
name = "DARKEN", | ||
factors = AGBlending( | ||
AGBlendFactor.SOURCE_ALPHA, AGBlendFactor.DESTINATION_ALPHA, | ||
AGBlendFactor.ONE, AGBlendFactor.ONE | ||
) | ||
) | ||
val DIFFERENCE = BlendMode( | ||
name = "DIFFERENCE", | ||
factors = AGBlending( | ||
AGBlendFactor.SOURCE_ALPHA, AGBlendFactor.DESTINATION_ALPHA, | ||
AGBlendFactor.ONE, AGBlendFactor.ONE | ||
) | ||
) | ||
val ALPHA = BlendMode( | ||
name = "ALPHA", | ||
factors = AGBlending( | ||
AGBlendFactor.SOURCE_ALPHA, AGBlendFactor.DESTINATION_ALPHA, | ||
AGBlendFactor.ONE, AGBlendFactor.ONE | ||
) | ||
) | ||
val HARDLIGHT = BlendMode( | ||
name = "HARDLIGHT", | ||
factors = AGBlending( | ||
AGBlendFactor.SOURCE_ALPHA, AGBlendFactor.DESTINATION_ALPHA, | ||
AGBlendFactor.ONE, AGBlendFactor.ONE | ||
) | ||
) | ||
|
||
val OVERLAY: BlendMode get() = NORMAL | ||
val REPLACE: BlendMode get() = NONE | ||
|
||
val BY_ORDINAL: Array<BlendMode> = arrayOf(INHERIT, NONE, NORMAL, ADD, MULTIPLY, SCREEN, ERASE, MASK, BELOW, SUBTRACT, INVERT, LIGHTEN, DARKEN, DIFFERENCE, ALPHA, HARDLIGHT) | ||
val BY_NAME: Map<String, BlendMode> = BY_ORDINAL.associateBy { it.name!! } | ||
val STANDARD_LIST: List<BlendMode> = BY_ORDINAL.toList() | ||
|
||
val TO_ORDINAL: Map<BlendMode, Int> = BY_ORDINAL.indices.associateBy { BY_ORDINAL[it] } | ||
|
||
operator fun get(ordinal: Int): BlendMode = BY_ORDINAL.getOrElse(ordinal) { INHERIT } | ||
operator fun get(name: String): BlendMode = BY_NAME[name.uppercase()] ?: INHERIT | ||
|
||
|
||
// https://community.khronos.org/t/blending-mode/34770/4 | ||
//multiply a * b | ||
//screen 1 - (1 - a) * (1 - b) | ||
//darken min(a, b) | ||
//lighten max(a, b) | ||
//difference abs(a - b) | ||
//negation 1 - abs(1 - a - b) | ||
//exclusion a + b - 2 * a * b | ||
//overlay a < .5 ? (2 * a * b) : (1 - 2 * (1 - a) * (1 - b)) | ||
//hard light b < .5 ? (2 * a * b) : (1 - 2 * (1 - a) * (1 - b)) | ||
//soft light b < .5 ? (2 * a * b + a * a * (1 - 2 * b)) : (sqrt(a) * (2 * b - 1) + (2 * a) * (1 - b)) | ||
//dodge a / (1 - b) | ||
//burn 1 - (1 - a) / b | ||
} | ||
} | ||
|
||
val BlendMode.ordinal: Int get() = BlendMode.TO_ORDINAL.getOrElse(this) { -1 } |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.