Skip to content

Commit

Permalink
KOMODO-33: Demonstrate running game through editor
Browse files Browse the repository at this point in the history
Editor can run a game idempotently. Exposed an issue with Game not being
GC safe due to the global instance variable. KOMODO-38 has been made to
track this.
  • Loading branch information
jamesaorson committed Feb 13, 2021
1 parent 94f8132 commit 7c2d1b0
Show file tree
Hide file tree
Showing 156 changed files with 11,180 additions and 111 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
run: |
nimble develop
cd examples/desktop
nimble build -Y
nimble buildDesktop -Y
# Generate the Docs
- name: Generate documentation
Expand Down
9 changes: 9 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
"program": "${workspaceFolder}/examples/desktop/bin/desktop",
"args": [],
"cwd": "${workspaceFolder}/examples/desktop",
},
{
"type": "lldb",
"request": "launch",
"name": "Nim: Debug Editor",
"preLaunchTask": "Debug Komodo Editor",
"program": "${workspaceFolder}/komodoeditor/bin/komodoeditor",
"args": [],
"cwd": "${workspaceFolder}/komodoeditor",
}
]
}
13 changes: 10 additions & 3 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,34 @@
{
"label": "Build Komodo Desktop Example",
"type": "shell",
"command": "cd examples/desktop; nimble build",
"command": "cd examples/desktop; nimble buildDesktop",
"problemMatcher": [],
"group": "build",
},
{
"label": "Debug Komodo Desktop Example",
"type": "shell",
"command": "cd examples/desktop; nimble debug",
"command": "cd komodoeditor; nimble debugDesktop",
"problemMatcher": [],
"group": "build",
},
{
"label": "Run Komodo Desktop Example",
"type": "shell",
"command": "cd examples/desktop; nimble example",
"command": "cd examples/desktop; nimble runDesktop",
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
},
},
{
"label": "Debug Komodo Editor",
"type": "shell",
"command": "cd komodoeditor; nimble debugEditor",
"problemMatcher": [],
"group": "build",
},
{
"label": "Format code",
"type": "shell",
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ scoop install nim
```

#### Raylib Setup
Copy the libraries found in the project's `lib/windows` directory to `C:\Windows\System32`.
Copy the libraries found in the project's `libs/raylib/windows` directory to `C:\Windows\System32`.

### Mac OS

Expand Down Expand Up @@ -63,7 +63,7 @@ choosenim stable
```

#### Raylib Setup
Either copy the `libraylib.so` file from `lib/linux` into `/usr/local/lib`, or follow the install instructions found on [raylib's repo wiki](https://github.com/raysan5/raylib/wiki/Working-on-GNU-Linux) to build from source and install like so:
Either copy the `libraylib.so` file from `libs/raylib/linux` into `/usr/local/lib`, or follow the install instructions found on [raylib's repo wiki](https://github.com/raysan5/raylib/wiki/Working-on-GNU-Linux) to build from source and install like so:
```bash
cd /tmp
git clone https://github.com/raysan5/raylib.git raylib
Expand All @@ -72,8 +72,8 @@ make PLATFORM=PLATFORM_DESKTOP RAYLIB_LIBTYPE=SHARED
sudo make install RAYLIB_LIBTYPE=SHARED
```

## Raylib
### Important Links
## Important Links
* [raylib bindings](https://github.com/Guevara-chan/Raylib-Forever)
* [raylib cheatsheet](https://www.raylib.com/cheatsheet/cheatsheet.html)
* [raylib releases](https://github.com/raysan5/raylib/releases)
* [raylib releases](https://github.com/raysan5/raylib/releases)
* [IUP documentation](http://webserver2.tecgraf.puc-rio.br/iup)
12 changes: 6 additions & 6 deletions examples/desktop/desktop.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ binDir = "bin"
requires "nim >= 1.4.2"
requires "komodo"

task build, "Build Desktop example":
exec "nimble --gc:orc -d:nimpretty build"
task buildDesktop, "Build Desktop example":
exec "nimble --gc:orc --threads:on -d:nimpretty build -Y"

task debug, "Debug Desktop example":
exec "nimble --gc:orc -g --debugger:native -d:nimpretty build"
task debugDesktop, "Debug Desktop example":
exec "nimble --gc:orc --threads:on -g --debugger:native -d:nimpretty build -Y"

task example, "Example":
exec "nimble --gc:orc -d:nimpretty run"
task runDesktop, "Example":
exec "nimble --gc:orc --threads:on -d:nimpretty run -Y"
124 changes: 63 additions & 61 deletions examples/desktop/src/desktop.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import komodo/ecs/systems
import komodo/lib/graphics/color
import komodo/lib/math

import test_behavior
# import test_behavior


proc add_cube(game: Game) =
Expand Down Expand Up @@ -43,74 +43,76 @@ proc add_cube(game: Game) =
)
assert game.registerComponent(transform)

proc add_sprite(game: Game) =
let parent = newEntity()
assert game.registerEntity(parent)
assert game.deregisterEntity(parent)
assert not game.deregisterEntity(parent)
assert game.registerEntity(parent)

let render_sprite_system = newRenderSpriteSystem()
assert game.registerSystem(render_sprite_system)
let sprite = newSpriteComponent(
parent,
"img/brainlet.png",
color = White,
)
assert game.registerComponent(sprite)

let render_text_system = newRenderTextSystem()
assert game.registerSystem(render_text_system)
let text = newTextComponent(
parent,
"Hello from desktop!",
fontSize = 24,
color = Black,
)
assert game.registerComponent(text)
assert game.deregisterComponent(text)
assert not game.deregisterComponent(text)
assert game.registerComponent(text)

let screen_size = game.screenSize()
let transform = newTransformComponent(
parent,
position = Vector3(
x: screen_size.x / 2,
y: screen_size.y / 2,
z: 0,
),
rotation = Vector3(
x: 0,
y: 0,
z: 0,
),
scale = Vector3(
x: 0.5,
y: 1,
z: 1,
),
)
assert game.registerComponent(transform)

let behavior_system = newBehaviorSystem()
assert game.registerSystem(behavior_system)
let behavior = newTestBehavior(
when false:
proc add_sprite(game: Game) =
let parent = newEntity()
assert game.registerEntity(parent)
assert game.deregisterEntity(parent)
assert not game.deregisterEntity(parent)
assert game.registerEntity(parent)

let render_sprite_system = newRenderSpriteSystem()
assert game.registerSystem(render_sprite_system)
let sprite = newSpriteComponent(
parent,
"img/brainlet.png",
color = White,
)
assert game.registerComponent(sprite)

let render_text_system = newRenderTextSystem()
assert game.registerSystem(render_text_system)
let text = newTextComponent(
parent,
"Hello from desktop!",
fontSize = 24,
color = Black,
)
assert game.registerComponent(text)
assert game.deregisterComponent(text)
assert not game.deregisterComponent(text)
assert game.registerComponent(text)

let screen_size = game.screenSize()
let transform = newTransformComponent(
parent,
)
assert game.registerComponent(behavior)

assert game.deregisterSystem(behavior_system)
assert not game.deregisterSystem(behavior_system)
assert game.registerSystem(behavior_system)
position = Vector3(
x: screen_size.x / 2,
y: screen_size.y / 2,
z: 0,
),
rotation = Vector3(
x: 0,
y: 0,
z: 0,
),
scale = Vector3(
x: 0.5,
y: 1,
z: 1,
),
)
assert game.registerComponent(transform)

let behavior_system = newBehaviorSystem()
assert game.registerSystem(behavior_system)
let behavior = newTestBehavior(
parent,
)
assert game.registerComponent(behavior)

assert game.deregisterSystem(behavior_system)
assert not game.deregisterSystem(behavior_system)
assert game.registerSystem(behavior_system)

proc main() =
var game = newGame()
game.title = "Desktop Example"
game.clearColor = Blue

game.add_cube()
game.add_sprite()
when false:
game.add_sprite()

game.run()

Expand Down
17 changes: 8 additions & 9 deletions examples/desktop/src/test_behavior.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
include komodo/prelude

from komodo/game import executeOnSystems, instance, deregisterComponent, registerComponent

behavior TestBehavior:
fields:
Expand All @@ -13,13 +12,13 @@ behavior TestBehavior:

init:
var transform = none[TransformComponent]()
let game = instance.get()
game.executeOnSystems(proc (system: System) =
if transform.isNone():
transform = system.findComponentByParent[:TransformComponent](
self.parent.get().id,
)
)
# TODO: Need to rethink game instance injection
# game.executeOnSystems(proc (system: System) =
# if transform.isNone():
# transform = system.findComponentByParent[:TransformComponent](
# self.parent.get().id,
# )
# )
if transform.isNone():
logError("Failed to find transform")
return
Expand All @@ -44,7 +43,7 @@ behavior TestBehavior:
z: position.z,
)
if self.remove_action.isDown():
let game = instance.get()
# let game = instance.get()
discard game.deregisterComponent(self.transform.get())
discard game.registerComponent(self.transform.get())

Expand Down
47 changes: 47 additions & 0 deletions komodoeditor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Komodo Editor
[Documentation](https://exokomodo.github.io/KomodoNim/komodo.html)

## Setup

### Windows

#### Install Scoop
Follow the instructions found on [Scoop's website](https://scoop.sh), or run the following commmands:
```PowerShell
iwr -useb get.scoop.sh | iex
```

#### Install Nim
Install nim with
```PowerShell
scoop install nim
```

#### IUP Setup
Copy the `*.dll` and `*.lib` files from `libs/iup/windows` into `C:\Windows\System32`

### Linux

#### Install choosenim
Follow the install instructions found on [choosenim's repo](https://github.com/dom96/choosenim), or run the following commands:
```bash
curl https://nim-lang.org/choosenim/init.sh -sSf | sh
```
You will need to update your path in your `.bashrc`:
```bash
export PATH=~/.nimble/bin:$PATH
```

#### Install Nim
Install nim with
```bash
choosenim stable
```

#### IUP Setup
Copy the `*.so` and `*.a` files from `libs/iup/linux` into `/usr/local/lib`

## Important Links
* [IUP Documentation](http://webserver2.tecgraf.puc-rio.br/iup)
* [IUP Windows download](https://sourceforge.net/projects/iup/files/3.30/Windows%20Libraries/Dynamic/iup-3.30_Win64_dll16_lib.zip/download)
* [IUP Linux download](https://sourceforge.net/projects/iup/files/3.30/Linux%20Libraries/iup-3.30_Linux54_64_lib.tar.gz/download)
25 changes: 25 additions & 0 deletions komodoeditor/komodoeditor.nimble
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Package

version = "0.1.0"
author = "James Orson"
description = "GUI editor for the Komodo game engine"
license = "MIT"
srcDir = "src"
bin = @["komodoeditor"]
binDir = "bin"


# Dependencies

requires "nim >= 1.4.2"
requires "komodo"
requires "iup"

task buildEditor, "Build Komodo Editor":
exec "nimble --gc:orc --threads:on -d:nimpretty build -Y"

task debugEditor, "Debug Komodo Editor":
exec "nimble --gc:orc --threads:on -g --debugger:native -d:nimpretty build -Y"

task runEditor, "Run":
exec "nimble --gc:orc --threads:on -d:nimpretty run -Y"
Loading

0 comments on commit 7c2d1b0

Please sign in to comment.