Skip to content

Commit 4466ccb

Browse files
authored
Merge pull request #13 from DominicDolan/develop
Merging to master
2 parents 4ac4671 + c9a3cbb commit 4466ccb

File tree

204 files changed

+3322
-1491
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

204 files changed

+3322
-1491
lines changed

CONTRIBUTING.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Introduction
2+
3+
Thank you for considering contributing to Mechanica.
4+
5+
This project is very new and it is just now being released as open source.
6+
For that reason we don't have a full cohesive plan just yet. We mainly
7+
just want to make sure everything is working the way we want it to.
8+
9+
Saying that, there is still a lot of work to do going forward.
10+
So if you do have an idea or a suggestion, or you found a bug,
11+
feel free to create an issue in the issue tracker.
12+
13+
# Filing Bug Reports
14+
15+
When filing a bug report, make sure to include the following where necessary:
16+
17+
1. What operating system are you using?
18+
2. What version of Kotlin are you using?
19+
3. What version of the JDK did you use to compile?
20+
4. What did you do and can you recreate the bug consistently?
21+
5. What did you expect to see or why do you think this is a bug?
22+
23+
# Suggesting Features or Enhancements
24+
25+
Because this is a very new project, there are a lot of
26+
features and enhancements to be added.
27+
28+
Right now there is not a solid plan in place for what features we
29+
are looking for but if you have an idea feel free to create an issue
30+
and make sure to describe the reasons, motivation and benefits of such
31+
a feature

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License (MIT)
2+
3+
Copyright (c) 2020 Dominic Dolan
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9+
of the Software, and to permit persons to whom the Software is furnished to do
10+
so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+

README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
## Mechanica, a 2D Game Engine in Kotlin
2+
23
A powerful 2D Game Engine written in Kotlin. This project is still under development and it is not
3-
thoroughly tested or documented but feel free to try it out nonetheless
4+
thoroughly tested or documented but feel free to try it out nonetheless.
5+
6+
Get started coding games by checking out the [Wiki](https://github.com/DominicDolan/Mechanica/wiki)
7+
or consider [Contributing](https://github.com/DominicDolan/Mechanica/blob/master/CONTRIBUTING.md)
8+
9+
### Building from source with Gradle
10+
11+
Clone or download the repository and build with gradle.
12+
13+
Building it will require java 12 or later and note that later versions of Java require the latest version of Gradle.
414

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

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

1019
```kotlin
1120
includeBuild("C:/path/to/mechanica")
1221
```
13-
And in the `build.gradle` file add a dependency on the project:
22+
And in the `build.gradle.kts` file add a dependency on the project:
1423
```kotlin
1524
dependencies {
1625
implementation("com.mechanica.engine:mechanica:1.0")

application-interface/src/main/kotlin/com/mechanica/engine/context/Application.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import com.mechanica.engine.display.Window
44

55
interface Application {
66

7-
fun initialize(window: Window)
7+
fun initialize(mainWindow: Window)
88

99
fun terminate()
1010

1111
fun startFrame()
1212

13+
fun activateContext(window: Window?)
14+
1315
}

application-interface/src/main/kotlin/com/mechanica/engine/context/loader/DisplayLoader.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import com.mechanica.engine.display.Monitor
55
import com.mechanica.engine.display.Window
66

77
interface DisplayLoader {
8-
fun createWindow(title: String, width: Int, height: Int): Window
9-
fun createWindow(title: String, monitor: Monitor): Window
10-
fun createWindow(title: String, width: Int, height: Int, monitor: Monitor): Window
8+
fun createWindow(title: String, width: Int, height: Int, sharedWith: Window? = null): Window
9+
fun createWindow(title: String, monitor: Monitor, sharedWith: Window? = null): Window
10+
fun createWindow(title: String, width: Int, height: Int, monitor: Monitor, sharedWith: Window? = null): Window
1111

1212
val allMonitors: Array<out Monitor>
1313

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package com.mechanica.engine.context.loader
22

3-
import com.mechanica.engine.text.Font
43
import com.mechanica.engine.resources.Resource
4+
import com.mechanica.engine.text.Font
55
import com.mechanica.engine.text.FontAtlasConfiguration
66

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

1110
}
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
package com.mechanica.engine.context.loader
2+
3+
import com.mechanica.engine.models.Model
4+
import java.nio.IntBuffer
5+
6+
interface GLDrawerLoader {
7+
/**
8+
* Defines a sequence of geometric primitives using [model]'s
9+
* elements, whose indices are stored in the buffer bound to the
10+
* GL_ELEMENT_ARRAY_BUFFER buffer
11+
*/
12+
fun drawElements(model: Model)
13+
14+
/**
15+
* Behaves identically to glDrawElements() except that the ith element
16+
* transferred by the corresponding draw command will be taken from
17+
* element indices`[i]` + basevertex of each enabled vertex attribute array.
18+
*/
19+
@Suppress("KDocUnresolvedReference")
20+
fun drawElementsBaseVertex(model: Model, baseVertex: Int)
21+
22+
/**
23+
* This is a restricted form of glDrawElements() in that it forms a contract
24+
* between the application (i.e., you) and OpenGL that guarantees that any
25+
* index contained in the section of the element array buffer referenced by
26+
* indices and model.vertexCount will fall within the range specified by start and end.
27+
*/
28+
fun drawRangeElements(model: Model, start: Int, end: Int)
29+
30+
/**
31+
* Forms a contractual agreement between the application similar to that of
32+
* [drawRangeElements], while allowing the base vertex to be specified in
33+
* basevertex. In this case, the contract states that the values stored in the
34+
* element array buffer will fall between start and end before basevertex is added.
35+
*/
36+
fun drawRangeElementsBaseVertex(model: Model, start: Int, end: Int, baseVertex: Int)
37+
38+
/**
39+
* Behaves exactly as [drawElements], except that the parameters for the
40+
* drawing command are taken from a structure stored in the buffer bound
41+
* to the GL_DRAW_INDIRECT_BUFFER binding point.
42+
*/
43+
fun drawElementsIndirect(model: Model)
44+
45+
/**
46+
* Draws multiple sets of geometric primitives with a single OpenGL
47+
* function call.
48+
*/
49+
fun multiDrawElements(models: Array<Model>)
50+
51+
/**
52+
* Draws multiple sets of geometric primitives with a single OpenGL
53+
* function call. first, indices, and baseVertex are arrays of primcount
54+
* parameters that would be valid for a call to
55+
* glDrawElementsBaseVertex().
56+
*/
57+
fun multiDrawElementsBaseVertex(models: Array<Model>, baseVertex: IntBuffer)
58+
59+
/**
60+
* The same as [multiDrawElementsBaseVertex] but the same [baseVertex] is
61+
* passed in for every primitive
62+
*/
63+
fun multiDrawElementsBaseVertex(models: Array<Model>, baseVertex: Int)
64+
65+
/**
66+
* Draws primCount instances of the geometric primitives specified by [model]
67+
* as if specified by individual calls to [drawElements].
68+
* As with [drawArraysInstanced], the built-in variable gl_InstanceID
69+
* is incremented for each instance, and new values are presented to the
70+
* vertex shader for each instanced vertex attribute.
71+
*/
72+
fun drawElementsInstanced(model: Model, instanceCount: Int)
73+
74+
/**
75+
* Draws [instanceCount] instances of the geometric primitives specified by [model]
76+
* and [baseVertex] as if specified by individual calls to
77+
* [drawElementsBaseVertex]. As with [drawArraysInstanced], the
78+
* built-in variable gl_InstanceID is incremented for each instance, and
79+
* new values are presented to the vertex shader for each instanced vertex
80+
* attribute.
81+
*/
82+
fun drawElementsInstancedBaseVertex(model: Model, instanceCount: Int, baseVertex: Int)
83+
84+
/**
85+
* Draws [instanceCount] instances of the geometric primitives specified by [model]
86+
* as if specified by individual calls to [drawElements].
87+
* As with [drawArraysInstanced], the built-in variable gl_InstanceID
88+
* is incremented for each instance, and new values are presented to the
89+
* vertex shader for each instanced vertex attribute. Furthermore, the
90+
* implied index used to fetch any instanced vertex attributes is offset by
91+
* the value of [baseInstance] by OpenGL.
92+
*/
93+
fun drawElementsInstancedBaseInstance(model: Model, instanceCount: Int, baseInstance: Int)
94+
95+
96+
/**
97+
* Constructs a sequence of geometric primitives using array elements
98+
* specified within [model]
99+
*/
100+
fun drawArrays(model: Model)
101+
102+
/**
103+
* Behaves exactly as [drawArraysInstanced], except that the parameters
104+
* for the drawing command are taken from a structure stored in the buffer
105+
* bound to the GL_DRAW_INDIRECT_BUFFER binding point (the draw
106+
* indirect buffer)
107+
*/
108+
fun drawArraysIndirect(model: Model)
109+
110+
/**
111+
* Draws multiple sets of geometric primitives with a single OpenGL
112+
* function call.
113+
*/
114+
fun multiDrawArrays(models: Array<Model>)
115+
116+
/**
117+
* Draws [instanceCount] instances of the geometric primitives specified by [model]
118+
* as if specified by individual calls to [drawArrays]. The
119+
* built-in variable gl_InstanceID is incremented for each instance, and
120+
* new values are presented to the vertex shader for each instanced vertex
121+
* attribute.
122+
*/
123+
fun drawArraysInstanced(model: Model, instanceCount: Int)
124+
125+
/**
126+
* Draws [instanceCount] instances of the geometric primitives specified by [model]
127+
* as if specified by individual calls to [drawArrays]. The
128+
* built-in variable gl_InstanceID is incremented for each instance, and
129+
* new values are presented to the vertex shader for each instanced vertex
130+
* attribute. Furthermore, the implied index used to fetch any instanced
131+
* vertex attributes is offset by the value of [baseInstance] by OpenGL.
132+
*/
133+
fun drawArraysInstancedBaseInstance(model: Model, instanceCount: Int, baseInstance: Int)
134+
135+
}
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
package com.mechanica.engine.context.loader
22

33
import com.mechanica.engine.models.Image
4-
import com.mechanica.engine.models.Model
54
import com.mechanica.engine.resources.Resource
65

76
interface GraphicsLoader {
87

8+
val glDrawer: GLDrawerLoader
9+
910
fun loadImage(id: Int): Image
1011
fun loadImage(res: Resource): Image
1112

12-
fun drawArrays(model: Model)
13-
fun drawElements(model: Model)
14-
13+
val glPointDrawer: GLDrawerLoader
14+
val glLineLoopDrawer: GLDrawerLoader
15+
val glLinesDrawer: GLDrawerLoader
16+
val glLineStripDrawer: GLDrawerLoader
1517
}

application-interface/src/main/kotlin/com/mechanica/engine/display/Window.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,16 @@ interface Window {
5151
}
5252

5353
companion object {
54-
fun create(title: String, width: Int, height: Int): Window {
55-
return DisplayLoader.createWindow(title, width, height)
54+
fun create(title: String, width: Int, height: Int, sharedWith: Window? = null): Window {
55+
return DisplayLoader.createWindow(title, width, height, sharedWith)
5656
}
5757

58-
fun create(title: String, monitor: Monitor): Window {
59-
return DisplayLoader.createWindow(title, monitor)
58+
fun create(title: String, monitor: Monitor, sharedWith: Window? = null): Window {
59+
return DisplayLoader.createWindow(title, monitor, sharedWith)
6060
}
6161

62-
fun create(title: String, width: Int, height: Int, monitor: Monitor): Window {
63-
return DisplayLoader.createWindow(title, width, height, monitor)
62+
fun create(title: String, width: Int, height: Int, monitor: Monitor, sharedWith: Window? = null): Window {
63+
return DisplayLoader.createWindow(title, width, height, monitor, sharedWith)
6464
}
6565
}
6666
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.mechanica.engine.graphics
2+
3+
import com.mechanica.engine.context.loader.GLDrawerLoader
4+
import com.mechanica.engine.models.Model
5+
import java.nio.IntBuffer
6+
7+
8+
class DrawBaseVertex(private val glDrawCommands: GLDrawerLoader) : ElementsDrawCommand, MultiElementsDrawCommand {
9+
var baseVertex: Int = 0
10+
11+
override fun elements(model: Model) {
12+
glDrawCommands.drawElementsBaseVertex(model, baseVertex)
13+
}
14+
15+
override fun elements(models: Array<Model>) {
16+
glDrawCommands.multiDrawElementsBaseVertex(models, baseVertex)
17+
}
18+
}
19+
20+
class MultiDrawBaseVertex(private val glDrawCommands: GLDrawerLoader) : MultiElementsDrawCommand {
21+
var baseVertex: IntBuffer? = null
22+
23+
override fun elements(models: Array<Model>) {
24+
val buffer = baseVertex
25+
if (buffer != null) {
26+
glDrawCommands.multiDrawElementsBaseVertex(models, buffer)
27+
}
28+
}
29+
}
30+
31+
class DrawRangeBaseVertex(
32+
private val glDrawCommands: GLDrawerLoader,
33+
private val drawRange: DrawRange): ElementsDrawCommand {
34+
internal var baseVertex: Int = 0
35+
36+
override fun elements(model: Model) {
37+
glDrawCommands.drawRangeElementsBaseVertex(model, drawRange.start, drawRange.end, baseVertex)
38+
}
39+
40+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.mechanica.engine.graphics
2+
3+
import com.mechanica.engine.models.Model
4+
5+
interface ArrayDrawCommand {
6+
fun arrays(model: Model)
7+
}
8+
9+
interface ElementsDrawCommand {
10+
fun elements(model: Model)
11+
}
12+
13+
interface MultiArrayDrawCommand {
14+
fun arrays(models: Array<Model>)
15+
}
16+
17+
interface MultiElementsDrawCommand {
18+
fun elements(models: Array<Model>)
19+
}
20+
21+
interface DrawCommands : ArrayDrawCommand, ElementsDrawCommand {
22+
fun model(model: Model) {
23+
if (model.hasIndexArray) {
24+
elements(model)
25+
} else {
26+
arrays(model)
27+
}
28+
}
29+
}
30+
31+
interface MultiDrawCommands : DrawCommands, MultiArrayDrawCommand, MultiElementsDrawCommand

0 commit comments

Comments
 (0)