Giter Club home page Giter Club logo

kmedialayer's Introduction

KMediaLayer

Offers an OpenGL/OpenGL|ES compatible interface and some functions for windowing, input and image loading as common.

Supports:

  • Android (NOT WORKING YET unsupported)
  • JS (webgl)
  • JVM (lwjgl3)
  • NATIVE-WINDOWS (WIN32, GDI+, WGL without additional dependencies)
  • NATIVE-MACOS (Cocoa without additional dependencies)

The intended normal workflow is to prototype using the JVM version, and then generate native executables or the JS version for the web.

Low level API:

object Kml {
    fun application(windowConfig: WindowConfig, listener: KMLWindowListener)

    fun <T> launch(context: CoroutineContext = EmptyCoroutineContext, callback: suspend () -> T): Job<T>
    fun currentTimeMillis(): Double
    suspend fun delay(ms: Int): Unit
    fun enqueue(task: () -> Unit): Unit
    suspend fun decodeImage(path: String): KmlNativeImageData
    suspend fun decodeImage(data: ByteArray): KmlNativeImageData
    suspend fun loadFileBytes(path: String, range: LongRange? = null): ByteArray
    suspend fun writeFileBytes(path: String, data: ByteArray, offset: Long? = null): Unit
}

The "application":

open class KMLWindowListener {
    open suspend fun init(gl: KmlGl): Unit
    open fun render(gl: KmlGl): Unit
    open fun keyUpdate(key: Key, pressed: Boolean)
    open fun gamepadUpdate(button: Int, pressed: Boolean, ratio: Double)
    open fun mouseUpdateMove(x: Int, y: Int)
    open fun mouseUpdateButton(button: Int, pressed: Boolean)
    open fun resized(width: Int, height: Int)
}

The window configuration:

data class WindowConfig(
    val width: Int = 640,
    val height: Int = 480,
    val title: String = "KMediaLayer"
)
// Offers the webgl API without the gl prefix:
interface KmlGl {
    // ...
    fun drawArrays(mode: Int, first: Int, count: Int): Unit
    fun drawElements(mode: Int, count: Int, type: Int, indices: Int): Unit
    fun enable(cap: Int): Unit
    fun enableVertexAttribArray(index: Int): Unit
    fun finish(): Unit
    fun flush(): Unit
    // ...
}

Scene API

The Scene API offers an API similar to the Swift's SpriteKit, Flash or Unity. There is a tree of view nodes, each node has properties and allow to attach components. There are components for handling mouse and key events

JobQueue

JobQueue exposes an API to enqueue asynchronous processes.

val queue = JobQueue()
queue { view.moveBy(16.0, 16.0, time = 0.5) } 

Depending on the task in hand you can enqueue more tasks, or discard some of the elements in the queue.

queue.discard() // Discard all the tasks in the queue that has not started
queue.cancel()  // Discards all the tasks and cancels the current task 
queue.cancel(complete = true) // Discards all the tasks and cancels the current task, signaling with a complete = true

Signaling cancelations with complete = true makes some task like tweening to jump to the target state.

kmedialayer's People

Contributors

soywiz avatar

Stargazers

 avatar 邢增龙 avatar  avatar

Watchers

 avatar James Cloos avatar 邢增龙 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.