Skip to content

Commit

Permalink
Merge pull request #13 from DominicDolan/develop
Browse files Browse the repository at this point in the history
Merging to master
  • Loading branch information
DominicDolan authored Oct 3, 2020
2 parents 4ac4671 + c9a3cbb commit 4466ccb
Show file tree
Hide file tree
Showing 204 changed files with 3,322 additions and 1,491 deletions.
31 changes: 31 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Introduction

Thank you for considering contributing to Mechanica.

This project is very new and it is just now being released as open source.
For that reason we don't have a full cohesive plan just yet. We mainly
just want to make sure everything is working the way we want it to.

Saying that, there is still a lot of work to do going forward.
So if you do have an idea or a suggestion, or you found a bug,
feel free to create an issue in the issue tracker.

# Filing Bug Reports

When filing a bug report, make sure to include the following where necessary:

1. What operating system are you using?
2. What version of Kotlin are you using?
3. What version of the JDK did you use to compile?
4. What did you do and can you recreate the bug consistently?
5. What did you expect to see or why do you think this is a bug?

# Suggesting Features or Enhancements

Because this is a very new project, there are a lot of
features and enhancements to be added.

Right now there is not a solid plan in place for what features we
are looking for but if you have an idea feel free to create an issue
and make sure to describe the reasons, motivation and benefits of such
a feature
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License (MIT)

Copyright (c) 2020 Dominic Dolan

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
## Mechanica, a 2D Game Engine in Kotlin

A powerful 2D Game Engine written in Kotlin. This project is still under development and it is not
thoroughly tested or documented but feel free to try it out nonetheless
thoroughly tested or documented but feel free to try it out nonetheless.

Get started coding games by checking out the [Wiki](https://github.com/DominicDolan/Mechanica/wiki)
or consider [Contributing](https://github.com/DominicDolan/Mechanica/blob/master/CONTRIBUTING.md)

### Building from source with Gradle

Clone or download the repository and build with gradle.

Building it will require java 12 or later and note that later versions of Java require the latest version of Gradle.

### Setting up the project with Gradle
Clone or download the repository and build with gradle
Try and run one of the samples in the samples module to check that everything is working.

Create a new Project with gradle. In the `settings.gradle` file add:
To create a new project using this repository, create a new Gradle project and In the `settings.gradle.kts` file add:

```kotlin
includeBuild("C:/path/to/mechanica")
```
And in the `build.gradle` file add a dependency on the project:
And in the `build.gradle.kts` file add a dependency on the project:
```kotlin
dependencies {
implementation("com.mechanica.engine:mechanica:1.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import com.mechanica.engine.display.Window

interface Application {

fun initialize(window: Window)
fun initialize(mainWindow: Window)

fun terminate()

fun startFrame()

fun activateContext(window: Window?)

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import com.mechanica.engine.display.Monitor
import com.mechanica.engine.display.Window

interface DisplayLoader {
fun createWindow(title: String, width: Int, height: Int): Window
fun createWindow(title: String, monitor: Monitor): Window
fun createWindow(title: String, width: Int, height: Int, monitor: Monitor): Window
fun createWindow(title: String, width: Int, height: Int, sharedWith: Window? = null): Window
fun createWindow(title: String, monitor: Monitor, sharedWith: Window? = null): Window
fun createWindow(title: String, width: Int, height: Int, monitor: Monitor, sharedWith: Window? = null): Window

val allMonitors: Array<out Monitor>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.mechanica.engine.context.loader

import com.mechanica.engine.text.Font
import com.mechanica.engine.resources.Resource
import com.mechanica.engine.text.Font
import com.mechanica.engine.text.FontAtlasConfiguration

interface FontLoader {
val defaultFont: Font
fun font(res: Resource, initializer: FontAtlasConfiguration.() -> Unit): Font

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package com.mechanica.engine.context.loader

import com.mechanica.engine.models.Model
import java.nio.IntBuffer

interface GLDrawerLoader {
/**
* Defines a sequence of geometric primitives using [model]'s
* elements, whose indices are stored in the buffer bound to the
* GL_ELEMENT_ARRAY_BUFFER buffer
*/
fun drawElements(model: Model)

/**
* Behaves identically to glDrawElements() except that the ith element
* transferred by the corresponding draw command will be taken from
* element indices`[i]` + basevertex of each enabled vertex attribute array.
*/
@Suppress("KDocUnresolvedReference")
fun drawElementsBaseVertex(model: Model, baseVertex: Int)

/**
* This is a restricted form of glDrawElements() in that it forms a contract
* between the application (i.e., you) and OpenGL that guarantees that any
* index contained in the section of the element array buffer referenced by
* indices and model.vertexCount will fall within the range specified by start and end.
*/
fun drawRangeElements(model: Model, start: Int, end: Int)

/**
* Forms a contractual agreement between the application similar to that of
* [drawRangeElements], while allowing the base vertex to be specified in
* basevertex. In this case, the contract states that the values stored in the
* element array buffer will fall between start and end before basevertex is added.
*/
fun drawRangeElementsBaseVertex(model: Model, start: Int, end: Int, baseVertex: Int)

/**
* Behaves exactly as [drawElements], except that the parameters for the
* drawing command are taken from a structure stored in the buffer bound
* to the GL_DRAW_INDIRECT_BUFFER binding point.
*/
fun drawElementsIndirect(model: Model)

/**
* Draws multiple sets of geometric primitives with a single OpenGL
* function call.
*/
fun multiDrawElements(models: Array<Model>)

/**
* Draws multiple sets of geometric primitives with a single OpenGL
* function call. first, indices, and baseVertex are arrays of primcount
* parameters that would be valid for a call to
* glDrawElementsBaseVertex().
*/
fun multiDrawElementsBaseVertex(models: Array<Model>, baseVertex: IntBuffer)

/**
* The same as [multiDrawElementsBaseVertex] but the same [baseVertex] is
* passed in for every primitive
*/
fun multiDrawElementsBaseVertex(models: Array<Model>, baseVertex: Int)

/**
* Draws primCount instances of the geometric primitives specified by [model]
* as if specified by individual calls to [drawElements].
* As with [drawArraysInstanced], the built-in variable gl_InstanceID
* is incremented for each instance, and new values are presented to the
* vertex shader for each instanced vertex attribute.
*/
fun drawElementsInstanced(model: Model, instanceCount: Int)

/**
* Draws [instanceCount] instances of the geometric primitives specified by [model]
* and [baseVertex] as if specified by individual calls to
* [drawElementsBaseVertex]. As with [drawArraysInstanced], the
* built-in variable gl_InstanceID is incremented for each instance, and
* new values are presented to the vertex shader for each instanced vertex
* attribute.
*/
fun drawElementsInstancedBaseVertex(model: Model, instanceCount: Int, baseVertex: Int)

/**
* Draws [instanceCount] instances of the geometric primitives specified by [model]
* as if specified by individual calls to [drawElements].
* As with [drawArraysInstanced], the built-in variable gl_InstanceID
* is incremented for each instance, and new values are presented to the
* vertex shader for each instanced vertex attribute. Furthermore, the
* implied index used to fetch any instanced vertex attributes is offset by
* the value of [baseInstance] by OpenGL.
*/
fun drawElementsInstancedBaseInstance(model: Model, instanceCount: Int, baseInstance: Int)


/**
* Constructs a sequence of geometric primitives using array elements
* specified within [model]
*/
fun drawArrays(model: Model)

/**
* Behaves exactly as [drawArraysInstanced], except that the parameters
* for the drawing command are taken from a structure stored in the buffer
* bound to the GL_DRAW_INDIRECT_BUFFER binding point (the draw
* indirect buffer)
*/
fun drawArraysIndirect(model: Model)

/**
* Draws multiple sets of geometric primitives with a single OpenGL
* function call.
*/
fun multiDrawArrays(models: Array<Model>)

/**
* Draws [instanceCount] instances of the geometric primitives specified by [model]
* as if specified by individual calls to [drawArrays]. The
* built-in variable gl_InstanceID is incremented for each instance, and
* new values are presented to the vertex shader for each instanced vertex
* attribute.
*/
fun drawArraysInstanced(model: Model, instanceCount: Int)

/**
* Draws [instanceCount] instances of the geometric primitives specified by [model]
* as if specified by individual calls to [drawArrays]. The
* built-in variable gl_InstanceID is incremented for each instance, and
* new values are presented to the vertex shader for each instanced vertex
* attribute. Furthermore, the implied index used to fetch any instanced
* vertex attributes is offset by the value of [baseInstance] by OpenGL.
*/
fun drawArraysInstancedBaseInstance(model: Model, instanceCount: Int, baseInstance: Int)

}
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package com.mechanica.engine.context.loader

import com.mechanica.engine.models.Image
import com.mechanica.engine.models.Model
import com.mechanica.engine.resources.Resource

interface GraphicsLoader {

val glDrawer: GLDrawerLoader

fun loadImage(id: Int): Image
fun loadImage(res: Resource): Image

fun drawArrays(model: Model)
fun drawElements(model: Model)

val glPointDrawer: GLDrawerLoader
val glLineLoopDrawer: GLDrawerLoader
val glLinesDrawer: GLDrawerLoader
val glLineStripDrawer: GLDrawerLoader
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ interface Window {
}

companion object {
fun create(title: String, width: Int, height: Int): Window {
return DisplayLoader.createWindow(title, width, height)
fun create(title: String, width: Int, height: Int, sharedWith: Window? = null): Window {
return DisplayLoader.createWindow(title, width, height, sharedWith)
}

fun create(title: String, monitor: Monitor): Window {
return DisplayLoader.createWindow(title, monitor)
fun create(title: String, monitor: Monitor, sharedWith: Window? = null): Window {
return DisplayLoader.createWindow(title, monitor, sharedWith)
}

fun create(title: String, width: Int, height: Int, monitor: Monitor): Window {
return DisplayLoader.createWindow(title, width, height, monitor)
fun create(title: String, width: Int, height: Int, monitor: Monitor, sharedWith: Window? = null): Window {
return DisplayLoader.createWindow(title, width, height, monitor, sharedWith)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.mechanica.engine.graphics

import com.mechanica.engine.context.loader.GLDrawerLoader
import com.mechanica.engine.models.Model
import java.nio.IntBuffer


class DrawBaseVertex(private val glDrawCommands: GLDrawerLoader) : ElementsDrawCommand, MultiElementsDrawCommand {
var baseVertex: Int = 0

override fun elements(model: Model) {
glDrawCommands.drawElementsBaseVertex(model, baseVertex)
}

override fun elements(models: Array<Model>) {
glDrawCommands.multiDrawElementsBaseVertex(models, baseVertex)
}
}

class MultiDrawBaseVertex(private val glDrawCommands: GLDrawerLoader) : MultiElementsDrawCommand {
var baseVertex: IntBuffer? = null

override fun elements(models: Array<Model>) {
val buffer = baseVertex
if (buffer != null) {
glDrawCommands.multiDrawElementsBaseVertex(models, buffer)
}
}
}

class DrawRangeBaseVertex(
private val glDrawCommands: GLDrawerLoader,
private val drawRange: DrawRange): ElementsDrawCommand {
internal var baseVertex: Int = 0

override fun elements(model: Model) {
glDrawCommands.drawRangeElementsBaseVertex(model, drawRange.start, drawRange.end, baseVertex)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.mechanica.engine.graphics

import com.mechanica.engine.models.Model

interface ArrayDrawCommand {
fun arrays(model: Model)
}

interface ElementsDrawCommand {
fun elements(model: Model)
}

interface MultiArrayDrawCommand {
fun arrays(models: Array<Model>)
}

interface MultiElementsDrawCommand {
fun elements(models: Array<Model>)
}

interface DrawCommands : ArrayDrawCommand, ElementsDrawCommand {
fun model(model: Model) {
if (model.hasIndexArray) {
elements(model)
} else {
arrays(model)
}
}
}

interface MultiDrawCommands : DrawCommands, MultiArrayDrawCommand, MultiElementsDrawCommand
Loading

0 comments on commit 4466ccb

Please sign in to comment.