shadowapex / godot-go Goto Github PK
View Code? Open in Web Editor NEWGo language bindings for the Godot Engine's GDNative API.
License: MIT License
Go language bindings for the Godot Engine's GDNative API.
License: MIT License
I started using godot-go recently and I gotta say - the work you've done here is amazing and I'd love to contribute and make it more stable - that saying, I have a problem I can't figure how to solve.
The bindings work fine but for some reason, the AnimationPlayer
element is behaving odd.
Calling .Play()
or .GetCurrentAnimationLength()
seem to behave as if the gd.Real
parameters and return values map to 0.
Things I've tried doing with no success:
.Play()
on AnimationPlayer
and AnimationPlayerImplementer
to accept gd.Float
instead of gd.Real
gd.Float
underlying type be float32
instead of float64
I've created an example project repo for convenience:
https://github.com/mastern2k3/godot-go-animtest
Would love help on this or maybe a new thread to follow, thanks in advance!
Go version | go version go1.11 linux/amd64 |
Godot version | 3.1.stable.official |
Godot-Go version/commit hash | master branch "1746202" |
OS | Linux Mint 19.1 linux/amd64 |
Type:Error
Description: does not have a library for the current platform
Time: 0:00:00:0247
C Error: Condition ' lib_path.length() == 0 ' is true.
C Source: modules/gdnative/nativescript/nativescript.cpp:1031
C Function: init_library
As you can see, I've tried adding the library various ways, but always get the same error.
Go version | go1.11.4 linux/amd64 |
Godot version | v3.0.6.stable.official.8314054 |
Godot-Go version/commit hash | 1746202 (latest) |
OS | Arch Linux |
Could you please update the README to be in consistence with http://docs.godotengine.org/en/3.0/tutorials/plugins/gdnative/gdnative-c-example.html ?
Asking because I can simply not figure how to use this? 😢
Go version | 1.10.3 |
Godot version | v3.0.6.stable |
Godot-Go version/commit hash | 1746202a2001f65ff7eb635b8cd7fc2a6ea64ca2 |
OS | elementary OS 0.4.1 Loki |
As a sub-task to issue #1 , we need to implement calling Godot parent methods. This will let us call methods like "get_node()" from within Go.
We need to write code parsing and code generation to create native Go structures for all available Godot objects. This will allow us to embed Godot objects into Go structs to make all of their methods and properties available to the "child" class.
Has this branch stopped developing?
Hello,
In 3.0 alpha2, I can't find anymore the project setting dlscript/default_dllibrary
. There is now a tab "GDNative
", but there is no button associated with it. How can I now put a default library?
Thanks for your work.
Can't get it to work under windows.
Can't compile the example in windows due to the following error:
(this is with the 1.11beta2, with the normal released version in windows. the Realesed 1.10.x version get issues with the filname path to long, but this is a go win issue. Its fixed in 1.11)
c:/program files/mingw-w64/x86_64-7.2.0-win32-seh-rt_v5-rev1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: Error: export ordinal too large: 74588
When I cross compile it in Linux I get the following errors:
go build -buildmode=c-shared -o simple.dll FSM.go
github.com/shadowapex/godot-go/vendor/github.com/vitaminwater/cgo.wchar /home/dio/.go/src/github.com/shadowapex/godot-go/vendor/github.com/vitaminwater/cgo.wchar/wchar.go:15:12: undefined: convertWcharToGoRune /home/dio/.go/src/github.com/shadowapex/godot-go/vendor/github.com/vitaminwater/cgo.wchar/wchar.go:23:9: undefined: convertGoRuneToWchar /home/dio/.go/src/github.com/shadowapex/godot-go/vendor/github.com/vitaminwater/cgo.wchar/wchar.go:47:9: undefined: convertGoStringToWcharString /home/dio/.go/src/github.com/shadowapex/godot-go/vendor/github.com/vitaminwater/cgo.wchar/wchar.go:128:14: undefined: convertWcharStringToGoString /home/dio/.go/src/github.com/shadowapex/godot-go/vendor/github.com/vitaminwater/cgo.wchar/wchar.go:141:9: undefined: convertWcharStringToGoString /home/dio/.go/src/github.com/shadowapex/godot-go/vendor/github.com/vitaminwater/cgo.wchar/wchar.go:150:9: undefined: convertWcharStringToGoString /home/dio/.go/src/github.com/shadowapex/godot-go/vendor/github.com/vitaminwater/cgo.wchar/wchar.go:158:9: undefined: convertWcharToGoRune
my go env:
GOARCH="amd64" GOBIN="" GOCACHE="/home/dio/.cache/go-build" GOEXE=".exe" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="windows" GOPATH="/home/dio/.go" GORACE="" GOROOT="/usr/bin/go" GOTMPDIR="" GOTOOLDIR="/usr/bin/go/pkg/tool/linux_amd64" GCCGO="gccgo" CC="x86_64-linux-gnu-gcc" CXX="x86_64-linux-gnu-g++" CGO_ENABLED="0" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-m64 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build621006750=/tmp/go-build -gno-record-gcc-switches"
Go version | 1.11beta2 windows /1.10.3 linux |
OS | windows |
How can we compile this for android and ios. You have mentioned it for Windows and MacOS only.
Go version | |
Godot version | |
Godot-Go version/commit hash | |
OS |
Using the example (pong.go), made a shorter version, but when trying to run it from Godot, gives the error:
> ERROR: open_dynamic_library: Can't open dynamic library: /Apps/GODOT/3.0/PRJS/grad1/libgodot.so.
> Error: /Apps/GODOT/3.0/PRJS/grad1/libgodot.so: undefined symbol: godot_rect3_get_shortest_axis_size
> At: drivers/unix/os_unix.cpp:407.
> ERROR: get_symbol: No valid library handle, can't get symbol from GDNative object
> At: modules/gdnative/gdnative.cpp:346.
> ERROR: init_library: No godot_nativescript_init in "res://libgodot.so" found
> At: modules/gdnative/nativescript/nativescript.cpp:1016.
The only difference from the configuration process is that I didn't put the library as a global (as it doesn't seem to exist anymore; see #27 ) The code is used is the following:
package main
import (
"log"
"github.com/shadowapex/godot-go/godot"
)
type FooClass struct {
godot.Node2D
direction *godot.Vector2
}
func NewFooClass() godot.Class {
fooClass := &FooClass{
direction: godot.NewVector2(1.0, 0.0),
}
return fooClass
}
func (p *FooClass) X_ready() {
screenSize := p.GetViewportRect()
godot.Log.Warning("***Screen size***")
godot.Log.Warning(screenSize.AsString())
godot.Log.Warning(p)
godot.Log.Warning(p.GetOwner())
godot.Log.Warning(p.GetName())
godot.Log.Warning(p.GetClass())
}
func init() {
godot.SetGodotGDNativeInit(func(options *godot.GodotGDNativeInitOptions) {
log.Println("This is being called from foo.go!")
})
godot.Register(NewFooClass)
}
func main() {
}
If I check the library I generated (using latest headers from github) with objdump, I see UND for godot_rect3_get_shortest_axis_size
:
$ objdump -x libgodot.so |grep godot_rect3_get_shortest_axis_size
0000000001a01cd0 l O .data 0000000000000008 github.com/shadowapex/godot-go/godot._cgo_1a4ce146d54f_Cfunc_godot_rect3_get_shortest_axis_size
0000000000754c20 l F .text 0000000000000087 github.com/shadowapex/godot-go/godot._Cfunc_godot_rect3_get_shortest_axis_size
0000000000000000 *UND* 0000000000000000 godot_rect3_get_shortest_axis_size
0000000000bf3f90 g F .text 000000000000003a _cgo_1a4ce146d54f_Cfunc_godot_rect3_get_shortest_axis_size
The README has basically this as an intro example.
package main
import (
"github.com/ShadowApex/godot-go/godot"
)
func init() {
// Register will register the given class constructor with Godot.
godot.Register(NewSimpleClass)
}
func main() {
}
// SimpleClass is a simple go struct that can be attached to a Godot Node2D object.
type SimpleClass struct {
godot.Node2D
}
// X_ready is called as soon as the node enters the scene.
func (h *SimpleClass) X_ready() {
godot.Log.Warning("Hello World!")
}
// NewSimpleClass is a constructor that we can pass to godot.
func NewSimpleClass() godot.Class {
return &SimpleClass{}
}
However will not compile: undefined: godot.Node2D
. The docs appear to be out of date.
The app could be launched and the player could be controlled,
but after a couple of seconds the app will crash.
Go version: go1.10 darwin/amd64
Godot version: 3.0.2.stable.official or 3.0.0.stable.official
$ godot -v
arguments
0: godot
1: -v
Current path: $GOPATH/src/github.com/ShadowApex/godot-go/examples/godot/DodgeTheCreeps
Using GLES3 video driver
OpenGL ES 3.0 Renderer: NVIDIA GeForce 320M OpenGL Engine
CoreAudio: detected 2 channels
CoreAudio: audio buffer frames: 512 calculated latency: 11ms
CORE API HASH: 5483915881153564253
EDITOR API HASH: -5919760101651613804
load resource: res://default_env.tres
load resource: res://Main.tscn
load resource: res://libgodot.gdnlib
load resource: res://Mob.tscn
load resource: res://libgodot.gdnlib (cached)
load resource: res://art/enemySwimming_1.png
load resource: res://art/enemySwimming_2.png
load resource: res://art/enemyWalking_1.png
load resource: res://art/enemyWalking_2.png
load resource: res://art/enemyFlyingAlt_1.png
load resource: res://art/enemyFlyingAlt_2.png
load resource: res://libgodot.gdnlib (cached)
2018/03/22 06:04:58 godot.go:74: Discovering classes to register with Godot...
load resource: res://art/enemySwimming_1.png (cached)
load resource: res://art/enemySwimming_2.png (cached)
load resource: res://art/enemyWalking_1.png (cached)
load resource: res://art/enemyWalking_2.png (cached)
load resource: res://art/enemyFlyingAlt_1.png (cached)
load resource: res://art/enemyFlyingAlt_2.png (cached)
load resource: res://Player.tscn
load resource: res://libgodot.gdnlib (cached)
load resource: res://art/playerGrey_walk1.png
load resource: res://art/playerGrey_walk2.png
load resource: res://art/playerGrey_up1.png
load resource: res://art/playerGrey_up2.png
load resource: res://libgodot.gdnlib (cached)
load resource: res://art/playerGrey_walk1.png (cached)
load resource: res://art/playerGrey_walk2.png (cached)
load resource: res://art/playerGrey_up1.png (cached)
load resource: res://art/playerGrey_up2.png (cached)
load resource: res://libgodot.gdnlib (cached)
load resource: res://Mob.tscn (cached)
load resource: res://Player.tscn (cached)
2018/03/22 06:04:58 player.go:34: X_Ready called!
2018/03/22 06:04:58 player.go:37: Getting animated sprite...
2018/03/22 06:04:58 player.go:40: Got animated sprite with ID: 0x7fe081ed91a0
2018/03/22 06:04:58 main.go:53: X_Ready called!
2018/03/22 06:04:58 main.go:54: Registry: &{map[0x7fe081ecf1c0:0xc4200d1b80 0x7fe081ed8ce0:0xc4200ea0a0]}
2018/03/22 06:04:58 main.go:95: New Game
FPS: 1
FPS: 1
FPS: 7
FPS: 60
2018/03/22 06:05:01 main.go:102: Start timer timeout
FPS: 60
2018/03/22 06:05:01 main.go:113: Mob timer timeout
handle_crash: Program crashed with signal 11
Dumping the backtrace. Please include this when reporting the bug on https://github.com/godotengine/godot/issues
-- END OF BACKTRACE --
Abort trap: 6
This looks very interesting..
golang and native script with godot is a pretty compelling solution.
Has anyone gotten an OSX make file ?
Just trying to get going fast to try things out.
It doesn't seem to make any sense, and cgo doesn't use go to develop games
See the karofel's comment godotengine/godot#12897
The python bindings I think, use now the wrapper https://github.com/godotengine/godot/blob/master/modules/gdnative/SCsub#L246 (scons gdnative_wrapper=yes)
I tried to change the Go bindings, but even that seems to be currently somewhere down the gdnative road broken. So far I managed to run my Go code only as a (-buildmode=c-archive) static module :-(
Currently we support basic Godot variant type like godot_string
, godot_int
, etc. We need to finish implementing the other types as their own Go structures that wrap around the underlying variant.
Given that Go has excellent networking library and it's a breeze to code network stuff in Go, could you provide an example of writing some dead-simple network lib in Go and interfacing it from Godot scripts /C++ ?
Does it support Godot v4?
preHeader := filepath.ToSlash(headerName)
on line 361 of types/generate.go
Go version | go1.11.5 |
Godot version | based on the output: /c/Users/*****/scoop/shims/godot (3.0.6 |
Godot-Go version/commit hash | 1746202 |
OS | windows/amd64 |
I've used example from https://github.com/ShadowApex/godot-go/tree/master/examples/gdnative/SimpleDemo but this seems to not work.
Ouput from console when running game looks like:
OpenGL ES 2.0 Renderer: GeForce GTX 860M/PCIe/SSE2
ERROR: _get_socket_error: Socket error: 10054
At: drivers/unix/net_socket_posix.cpp:190
WARNING: main.nativeScriptInit: Initializing nativescript from Go!
At: C:/path/to/main.go:20
WARNING: main.nativeScriptInit: Registering SIMPLE class...
At: C:/path/to/main.go:39
WARNING: main.nativeScriptInit: Registering SIMPLE method...
At: C:/path/to/main.go:48
Cetn e ipels.
Dsryn ipels ihI:x00808.
I suppose, last two lines are from main.go.
gdnative.Log.Println("Creating new SimpleClass...")
and gdnative.Log.Println("Destroying SimpleClass with ID:", userData, "...")
. If I change gdnative.Log.Println
to gdnative.Log.Warning
this logs seems to be working but editor still crashes.
Go version | go version go1.12 windows/amd64 |
Godot version | v3.1.beta8.official |
Godot-Go version/commit hash | 1746202 |
OS | windows10 64bit |
Having a single file to contain all built in classes provides extra difficulty. Namely:
To solve these problems, I propose that classes.go be replaced with a directory structure such as ../godot/classes/className.go.
Currently i'm implementing a library in Go which needs to get multiple parameters on a method call:
That call is getting the first parameter right, but the rest of the Variants in the args array come with weird values. For example, calling with 3 ints i do:
fmt.Sprintf("%d %d %d", args[0].GetType(), args[1].GetType(), args[2].GetType())
and get
2 81748992 81748992
as result
Edit: It should be noted that the expected result should be 2 2 2
seems like the args array is only getting initialized on the first value, i've been trying to debug this but can't find where's my method getting called to change it on godot's or godot-go's code.
There are several global singleton classes that aren't meant to be embedded. For example, calling godot.OS.GetScreenSize(). We might want to make Singleton classes private and only expose them as variables.
We should be able to expose properties as well as methods to Godot.
There's a few constants like "MARGIN_LEFT" that are defined globally in Godot. We should generate and expose these.
When calling the MoveAndCollide function for the kinematicBody2D the game crashes right after launch with no error, the code snippet below works fine with the line commented out. I can just set the position but collisions will not be calculated then.
// X_Process is called every frame
func (r *Robot) X_Process(delta gd.Real) {
velocity := gd.NewVector2(0, 0)
if godot.Input.IsActionPressed("ui_right") {
velocity.SetX(velocity.GetX() + 1)
}
if godot.Input.IsActionPressed("ui_left") {
velocity.SetX(velocity.GetX() - 1)
}
if godot.Input.IsActionPressed("ui_down") {
velocity.SetY(velocity.GetY() + 1)
}
if godot.Input.IsActionPressed("ui_up") {
velocity.SetY(velocity.GetY() - 1)
}
if velocity.Length() > 0 {
normal := velocity.Normalized()
velocity = normal.OperatorMultiplyScalar(speed)
}
r.MoveAndCollide(velocity.OperatorMultiplyScalar(delta))
}
Go version | 1.16.2 |
Godot version | 3.2.3 |
Godot-Go version/commit hash | Current |
OS | Arch Linux 5.11.6 |
I compiled a simple library for linux and it worked without any problem:
When compiling on Windows the editor crashes without any error on console or a dialog when it loses focus.
This is the GDNative:
https://github.com/chiguireitor/godot-gobtcsuite
|Go version | 1.12.6 |
|Godot version | 3.1 stable on windows / 3.2 HEAD on linux |
|Godot-Go version/commit hash | Will ask tomorrow my teammate on his windows version |
|OS | Windows |
I tried to compile for Android. I have many problems with libiconv but finaly I fixed
bug when I run game on android give me this error
No implementation found for void org.godotengine.godot.GodotLib.initialize(org.godotengine.godot.Godot, boolean, java.lang.Object, boolean) (tried Java_org_godotengine_godot_GodotLib_initialize and Java_org_godotengine_godot_GodotLib_initialize__Lorg_godotengine_godot_Godot_2ZLjava_lang_Object_2Z)
I build shared library with this command
CC="$PWD/android/toolchainarm64/bin/aarch64-linux-android-gcc" \
CXX="$PWD/android/toolchainarm64/bin/aarch64-linux-android-g++" \
CGO_ENABLED=1 \
GOOS=android GOARCH=arm64 \
go build -buildmode=c-shared -o lib/libgodot_android.so src/*.go
Go version | 1.10.2 |
Godot version | 3.0.2 |
Godot-Go version/commit hash | 1746202 |
OS | android 7 |
Hey, I was wondering if you all could provide a short guide on how to set this up for debugging. I am honestly new to Go and pretty new to Godot too.
Is it possible to debug this shared library while Godot is running?
Does godot-go work with the current version of godot and golang? I was getting an error: does not have a library for the current platform. Thanks
Go version | go1.10 darwin/amd64 |
Godot version | 3.0.2.stable.official |
Godot-Go version/commit hash | 1746202 |
OS | Mac |
For converting types using case/switch, it might be more optimal to use a map of conversion functions instead of case/switch.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.