diff --git a/docs/index.rst b/docs/index.rst index d127ea3..4886466 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -95,15 +95,6 @@ If you would like to use Nim in an existing project: GDNative library resource that contains paths to dynamic libraries compiled by Nim. -3. Add ``NimRuntime`` as an `AutoLoad singleton `_ - to your project. To do this, copy ``project/scripts/NimRuntime.gdns`` into - your project and add these lines to ``project.godot``, adjusting path to - ``NimRuntime.gdns`` as necessary: -.. code-block:: cfg - [autoload] - NimRuntime="*res://scripts/NimRuntime.gdns" - - Next Steps ---------- diff --git a/godot.nimble b/godot.nimble index fb29aea..bff8646 100644 --- a/godot.nimble +++ b/godot.nimble @@ -1,4 +1,4 @@ -version = "0.4.0" +version = "0.4.1" author = "Xored Software, Inc." description = "Godot Engine bindings" license = "MIT" diff --git a/godot/godot.nim.cfg b/godot/godot.nim.cfg index 9e05300..42e80b0 100644 --- a/godot/godot.nim.cfg +++ b/godot/godot.nim.cfg @@ -1 +1,2 @@ ---path:"$projectdir" \ No newline at end of file +--path:"$projectdir" +-d:useRealtimeGc \ No newline at end of file diff --git a/godot/nim/godotnim.nim b/godot/nim/godotnim.nim index 5d26891..cf8c4ff 100644 --- a/godot/nim/godotnim.nim +++ b/godot/nim/godotnim.nim @@ -1,6 +1,6 @@ # Copyright 2017 Xored Software, Inc. -import tables, typetraits, macros +import tables, typetraits, macros, asyncdispatch import core.godotbase import core.vector2, core.rect2, core.vector3, core.transform2d, @@ -668,14 +668,22 @@ proc godot_gdnative_terminate(options: ptr GodotNativeTerminateOptions) {. cdecl, exportc, dynlib.} = deallocHeap(runFinalizers = not options[].inEditor, allowGcAfterwards = false) -proc godot_nativescript_thread_enter() {. - cdecl, exportc, dynlib.} = +const nimGcStepLengthUs {.intdefine.} = 2000 +proc godot_nativescript_frame() {.cdecl, exportc, dynlib.} = + if asyncdispatch.hasPendingOperations(): + poll(0) + GC_step(nimGcStepLengthUs, false, 0) + +when not defined(release): + onUnhandledException = proc(errorMsg: string) = + printError("Unhandled Nim exception: " & errorMsg) + +proc godot_nativescript_thread_enter() {.cdecl, exportc, dynlib.} = when compileOption("threads"): setupForeignThreadGc() else: print(cstring"A foreign thread is created, but app is compiled without --threads:on. Bad things will happen if Nim code is invoked from this thread.") -proc godot_nativescript_thread_exit() {. - cdecl, exportc, dynlib.} = +proc godot_nativescript_thread_exit() {.cdecl, exportc, dynlib.} = when compileOption("threads"): teardownForeignThreadGc() diff --git a/godot/nimruntime.nim b/godot/nimruntime.nim index 8a392b5..475785f 100644 --- a/godot/nimruntime.nim +++ b/godot/nimruntime.nim @@ -3,6 +3,9 @@ import asyncdispatch import godot, node +{.warning: ("NimRuntime is deprecated - it is no longer necessary to add it " & + "as an AutoLoad class. It will be removed in v0.5.0.").} + gdobj NimRuntime of Node: method enterTree*() = discard getTree().connect("idle_frame", self, "idle", newArray())