Add simple example

This commit is contained in:
Ruslan Mustakov 2017-07-26 10:56:53 +07:00
commit 15a527d8b4
42 changed files with 3244 additions and 0 deletions

View file

@ -0,0 +1,43 @@
import ospaths
switch("nimcache", "nimcache"/hostOS/hostCPU)
when defined(macosx):
switch("passL", "-framework Cocoa -Wl,-undefined,dynamic_lookup")
elif defined(android):
let ndk = getEnv("ANDROID_NDK_ROOT")
let toolchain = getEnv("ANDROID_TOOLCHAIN")
if ndk.len == 0:
raise newException(OSError,
"ANDROID_NDK_ROOT environment variable is necessary for android build")
if toolchain.len == 0:
raise newException(OSError,
"ANDROID_TOOLCHAIN environment variable is necessary for android build")
const level = $16 # change this to the necessary API level
const arch = "arm"
let sysroot = "--sysroot=\"" & ndk & "/platforms/android-" & level & "/arch-" & arch & "/\""
switch("passL", sysroot)
switch("passC", sysroot)
switch("cc", "clang")
switch("arm.linux.clang.path", toolchain / "bin")
switch("arm.linux.clang.exe", arch & "-linux-androideabi-clang")
switch("arm.linux.clang.compilerexe", arch & "-linux-androideabi-clang")
switch("arm.linux.clang.linkerexe", arch & "-linux-androideabi-clang")
elif defined(windows):
assert(sizeof(int) == 8)
switch("cc", "vcc")
let godotLib = getEnv("GODOT_LIB")
if godotLib.len == 0:
raise newException(OSError,
"GODOT_LIB must be specified and point to the .lib file")
switch("clib", godotLib.changeFileExt(""))
elif defined(linux):
switch("passC", "-fPIC")
else:
raise newException(OSError, "Unsupported platform: " & hostOS)
when not defined(release):
switch("debugger", "native")

View file

@ -0,0 +1,17 @@
# Copyright 2017 Xored Software, Inc.
import strutils
import godot
import engine, label, resource_loader, packed_scene
gdobj FPSCounter of Label:
var lastFPS: float32
method ready*() =
setProcess(true)
method process*(delta: float64) =
let fps = getFramesPerSecond()
if int(fps * 10) != int(lastFPS * 10):
lastFPS = fps
self.text = "FPS: " & formatFloat(fps, ffDecimal, 1)

View file

@ -0,0 +1,18 @@
# Copyright 2017 Xored Software, Inc.
import godot
import scene_tree, resource_loader, packed_scene, panel, global_constants,
input_event_mouse_button
gdobj MainPanel of Panel:
method ready*() =
setProcessInput(true)
method input*(event: InputEvent) =
if event of InputEventMouseButton:
let ev = event as InputEventMouseButton
if ev.buttonIndex == BUTTON_LEFT:
getTree().setInputAsHandled()
let scene = load("res://scene.tscn") as PackedScene
getTree().getRoot().addChild(scene.instance())
queueFree()

View file

@ -0,0 +1,9 @@
--path:"$projectdir"
--path:"$projectdir/../godotapi"
--cincludes:"$projectdir/../godot_headers/"
--experimental
--app:lib
--stackTrace:on
-d:useRealtimeGc
--noMain
--warning[LockLevel]:off

View file

@ -0,0 +1,12 @@
# Copyright 2017 Xored Software, Inc.
## Import independent scene objects here
## (no need to import everything, just independent roots)
when not defined(release):
import segfaults # converts segfaults into NilAccessError
import nimruntime
import fpscounter
import mainpanel

View file

@ -0,0 +1,34 @@
version = "0.1.0"
author = "Xored Software, Inc."
description = "FPS Counter Sample"
license = "MIT"
bin = @["simple"]
requires "https://github.com/pragmagic/godot-nim.git >= 0.2.2 & < 0.3.0"
task make, "build":
const archPostfix = when sizeof(int) == 8: "_64" else: "_32"
const libFile =
when defined(windows):
"nim" & archPostfix & ".dll"
elif defined(ios):
"nim_ios.dylib"
elif defined(macosx):
"nim_mac.dylib"
elif defined(android):
"nim_android.so"
elif defined(linux):
"nim_linux" & archPostfix & ".so"
else: nil
if libFile.isNil:
raise newException(OSError, "Unsupported platform")
exec "nimble build -y"
const dir = "../project/_dlls/"
const target = dir & libFile
mkDir(dir)
when defined(windows):
rmFile(target)
mvFile(bin[0] & ".exe", target)
else:
mvFile(bin[0], target)