Use GDNative API struct

This commit is contained in:
Ruslan Mustakov 2017-10-04 23:41:15 +07:00
commit b62db02d8f
32 changed files with 2846 additions and 1535 deletions

View file

@ -1,4 +1,4 @@
version = "0.5.10" version = "0.6.0"
author = "Xored Software, Inc." author = "Xored Software, Inc."
description = "Godot Engine bindings" description = "Godot Engine bindings"
license = "MIT" license = "MIT"

View file

@ -1,7 +1,7 @@
# Copyright 2017 Xored Software, Inc. # Copyright 2017 Xored Software, Inc.
import hashes import hashes
import internal.godotarrays import internal.godotinternaltypes, internal.godotarrays
type type
Array* = ref object Array* = ref object
@ -125,8 +125,8 @@ proc delete*(self: var Array; idx: int) {.inline.} =
proc setLen*(self: var Array; size: int) {.inline.} = proc setLen*(self: var Array; size: int) {.inline.} =
self.godotArray.setLen(size.cint) self.godotArray.setLen(size.cint)
proc rfind*(self: Array; what: Variant; f: int): int {.inline.} = proc rfind*(self: Array; what: Variant; fromIdx: int): int {.inline.} =
self.godotArray.rfind(what.godotVariant[], f.cint).int self.godotArray.rfind(what.godotVariant[], fromIdx.cint).int
proc len*(self: Array): int {.inline.} = proc len*(self: Array): int {.inline.} =
self.godotArray.len.int self.godotArray.len.int

View file

@ -2,10 +2,7 @@
import math import math
import godotbase, vector3, quats import godotbase, vector3, quats
import godotcoretypes
type
Basis* {.byref.} = object
elements*: array[3, Vector3]
proc setCells*(basis: var Basis, xx, xy, xz, yx, yy, yz, zx, zy, zz: float32) = proc setCells*(basis: var Basis, xx, xy, xz, yx, yy, yz, zx, zy, zz: float32) =
basis.elements[0].x = xx basis.elements[0].x = xx

View file

@ -1,11 +1,6 @@
# Copyright (c) 2017 Xored Software, Inc. # Copyright (c) 2017 Xored Software, Inc.
type import godotcoretypes, gdnativeapi
Color* {.byref.} = object
r*: float32
g*: float32
b*: float32
a*: float32
proc initColor*(r, g, b: float32; a: float32 = 1.0'f32): Color {.inline.} = proc initColor*(r, g, b: float32; a: float32 = 1.0'f32): Color {.inline.} =
Color( Color(
@ -19,12 +14,14 @@ proc initColor*(): Color {.inline.} =
## Initializes black color with 1.0 alpha ## Initializes black color with 1.0 alpha
initColor(0, 0, 0) initColor(0, 0, 0)
proc h*(self: Color): float32 {. proc h*(self: Color): float32 {.inline.} =
importc: "godot_color_get_h".} getGDNativeAPI().colorGetH(self)
proc s*(self: Color): float32 {.
importc: "godot_color_get_s".} proc s*(self: Color): float32 {.inline.} =
proc v*(self: Color): float32 {. getGDNativeAPI().colorGetS(self)
importc: "godot_color_get_v".}
proc v*(self: Color): float32 {.inline.} =
getGDNativeAPI().colorGetV(self)
proc `$`*(self: Color): string {.inline.} = proc `$`*(self: Color): string {.inline.} =
result = newStringOfCap(50) result = newStringOfCap(50)
@ -58,16 +55,20 @@ proc toARGB32*(self: Color): uint32 {.inline.} =
result = (result shl 8) or uint8(self.g * 255) result = (result shl 8) or uint8(self.g * 255)
result = (result shl 8) or uint8(self.b * 255) result = (result shl 8) or uint8(self.b * 255)
proc gray*(self: Color): float32 {. proc gray*(self: Color): float32 {.inline.} =
importc: "godot_color_gray".} getGDNativeAPI().colorGray(self)
proc inverted*(self: Color): Color {.
importc: "godot_color_inverted".} proc inverted*(self: Color): Color {.inline.} =
proc contrasted*(self: Color): Color {. getGDNativeAPI().colorInverted(self)
importc: "godot_color_contrasted".}
proc lerp*(self: Color; b: Color; t: float32): Color {. proc contrasted*(self: Color): Color {.inline.} =
importc: "godot_color_linear_interpolate".} getGDNativeAPI().colorContrasted(self)
proc blend*(self: Color; over: Color): Color {.
importc: "godot_color_blend".} proc lerp*(self: Color; b: Color; t: float32): Color {.inline.} =
getGDNativeAPI().colorLinearInterpolate(self, b, t)
proc blend*(self: Color; over: Color): Color {.inline.} =
getGDNativeAPI().colorBlend(self, over)
proc `==`*(a, b: Color): bool {.inline.} = proc `==`*(a, b: Color): bool {.inline.} =
a.r == b.r and a.g == b.g and a.b == b.b and a.a == b.a a.r == b.r and a.g == b.g and a.b == b.b and a.a == b.a

View file

@ -1,8 +1,8 @@
# Copyright 2017 Xored Software, Inc. # Copyright 2017 Xored Software, Inc.
import hashes import hashes
import internal.godotstrings, internal.godotdictionaries, import internal.godotinternaltypes, internal.godotdictionaries,
internal.godotvariants internal.godotvariants, internal.godotstrings
type type
Dictionary* = ref object Dictionary* = ref object

View file

@ -2,61 +2,6 @@
import math import math
type
Error* {.size: sizeof(cint), pure.} = enum
OK,
Failed, ## Generic fail error
Unavailable, ## What is requested is unsupported/unavailable
Unconfigured, ## The object being used hasnt been properly set up yet
Unauthorized, ## Missing credentials for requested resource
ParameterRangeError, ## Parameter given out of range (5)
OutOfMemory, ## Out of memory
FileNotFound,
FileBadDrive,
FileBadPath,
FileNoPermission, ## (10)
FileAlreadyInUse,
FileCantOpen,
FileCantWrite,
FileCantRead,
FileUnrecognized, ## (15)
FileCorrupt,
FileMissingDependencies,
FileEOF,
CantOpen, ## Can't open a resource/socket/file
CantCreate, ## (20)
QueryFailed,
AlreadyInUse,
Locked, ## resource is locked
Timeout,
CantConnect, ## (25)
CantResolve,
ConnectionError,
CantAquireResource,
CantFork,
InvalidData, ## Data passed is invalid (30)
InvalidParameter, ## Parameter passed is invalid
AlreadyExists, ## When adding, item already exists
DoesNotExist, ## When retrieving/erasing, it item does not exist
DatabaseCantRead, ## Database is full
DatabaseCantWrite, ## Database is full (35)
CompilationFailed,
MethodNotFound,
LinkFailed,
ScriptFailed,
CyclicLink, ## (40)
InvalidDeclaration,
DuplicateSymbol,
PauseError,
Busy,
Skip, ## (45)
Help, ## user requested help!!
Bug,
## a bug in the software certainly happened, due to a double
## check failing or unexpected behavior.
PrinterOnFire, ## the parallel port printer is engulfed in flames
WTF ## shit happens, has never been used, though
# math helpers # math helpers
const EPSILON = 0.00001'f32 const EPSILON = 0.00001'f32

View file

@ -0,0 +1,102 @@
# Copyright 2017 Xored Software, Inc.
type
Color* {.byref.} = object
r*: float32
g*: float32
b*: float32
a*: float32
Vector3* {.byref.} = object
x*: float32
y*: float32
z*: float32
Vector2* {.byref.} = object
x*: float32
y*: float32
Plane* {.byref.} = object
normal*: Vector3
d*: float32
Basis* {.byref.} = object
elements*: array[3, Vector3]
Quat* {.byref.} = object
x*: float32
y*: float32
z*: float32
w*: float32
Rect3* {.byref.} = object
position*: Vector3
size*: Vector3
Rect2* {.byref.} = object
position*: Vector2
size*: Vector2
Transform2D* {.byref.} = object
elements*: array[3, Vector2]
Transform* {.byref.} = object
basis*: Basis
origin*: Vector3
RID* {.byref.} = object
data: array[sizeof(int), byte]
Error* {.size: sizeof(cint), pure.} = enum
OK,
Failed, ## Generic fail error
Unavailable, ## What is requested is unsupported/unavailable
Unconfigured, ## The object being used hasnt been properly set up yet
Unauthorized, ## Missing credentials for requested resource
ParameterRangeError, ## Parameter given out of range (5)
OutOfMemory, ## Out of memory
FileNotFound,
FileBadDrive,
FileBadPath,
FileNoPermission, ## (10)
FileAlreadyInUse,
FileCantOpen,
FileCantWrite,
FileCantRead,
FileUnrecognized, ## (15)
FileCorrupt,
FileMissingDependencies,
FileEOF,
CantOpen, ## Can't open a resource/socket/file
CantCreate, ## (20)
QueryFailed,
AlreadyInUse,
Locked, ## resource is locked
Timeout,
CantConnect, ## (25)
CantResolve,
ConnectionError,
CantAquireResource,
CantFork,
InvalidData, ## Data passed is invalid (30)
InvalidParameter, ## Parameter passed is invalid
AlreadyExists, ## When adding, item already exists
DoesNotExist, ## When retrieving/erasing, it item does not exist
DatabaseCantRead, ## Database is full
DatabaseCantWrite, ## Database is full (35)
CompilationFailed,
MethodNotFound,
LinkFailed,
ScriptFailed,
CyclicLink, ## (40)
InvalidDeclaration,
DuplicateSymbol,
PauseError,
Busy,
Skip, ## (45)
Help, ## user requested help!!
Bug,
## a bug in the software certainly happened, due to a double
## check failing or unexpected behavior.
PrinterOnFire, ## the parallel port printer is engulfed in flames
WTF ## shit happens, has never been used, though

View file

@ -1,6 +1,7 @@
# Copyright 2017 Xored Software, Inc. # Copyright 2017 Xored Software, Inc.
import internal.godotnodepaths, internal.godotstrings import internal.godotinternaltypes, internal.godotnodepaths,
internal.godotstrings
type type
NodePath* = ref object NodePath* = ref object

View file

@ -2,72 +2,59 @@
import vector3 import vector3
import internal.godotstrings import internal.godotinternaltypes, godotcoretypes, gdnativeapi
type proc initPlane*(a, b, c, d: float32): Plane {.inline.} =
Plane* {.byref.} = object getGDNativeAPI().planeNewWithReals(result, a, b, c, d)
normal*: Vector3
d*: float32
proc initPlane(dest: var Plane; a, b, c, d: float32) {. proc initPlane*(v1, v2, v3: Vector3): Plane {.inline.} =
importc: "godot_plane_new_with_reals".} getGDNativeAPI().planeNewWithVectors(result, v1, v2, v3)
proc initPlane(dest: var Plane; v1, v2, v3: Vector3) {.
importc: "godot_plane_new_with_vectors".}
proc initPlane(dest: var Plane; normal: Vector3; d: float32) {.
importc: "godot_plane_new_with_normal".}
proc initPlane*(a, b, c, d: float32): Plane = proc initPlane*(normal: Vector3; d: float32): Plane {.inline.} =
initPlane(result, a, b, c, d) result = Plane(
normal: normal,
proc initPlane*(v1, v2, v3: Vector3): Plane = d: d
initPlane(result, v1, v2, v3) )
proc initPlane*(normal: Vector3; d: float32): Plane =
initPlane(result, normal, d)
proc toGodotString(self: Plane): GodotString {.
noSideEffect,
importc: "godot_plane_as_string".}
proc `$`*(self: Plane): string {.inline.} = proc `$`*(self: Plane): string {.inline.} =
$self.toGodotString() $getGDNativeAPI().planeAsString(self)
proc normalized*(self: Plane): Plane {.inline.} =
getGDNativeAPI().planeNormalized(self)
proc center*(self: Plane): Vector3 {.inline.} =
getGDNativeAPI().planeCenter(self)
proc getAnyPoint*(self: Plane): Vector3 {.inline.} =
getGDNativeAPI().planeGetAnyPoint(self)
proc isPointOver*(self: Plane; point: Vector3): bool {.inline.} =
getGDNativeAPI().planeIsPointOver(self, point)
proc distanceTo*(self: Plane; point: Vector3): float32 {.inline.} =
getGDNativeAPI().planeDistanceTo(self, point)
proc normalized*(self: Plane): Plane {.
noSideEffect,
importc: "godot_plane_normalized".}
proc center*(self: Plane): Vector3 {.
noSideEffect,
importc: "godot_plane_center".}
proc getAnyPoint*(self: Plane): Vector3 {.
noSideEffect,
importc: "godot_plane_get_any_point".}
proc isPointOver*(self: Plane; point: Vector3): bool {.
noSideEffect,
importc: "godot_plane_is_point_over".}
proc distanceTo*(self: Plane; point: Vector3): float32 {.
noSideEffect,
importc: "godot_plane_distance_to".}
proc contains*(self: Plane; point: Vector3; proc contains*(self: Plane; point: Vector3;
epsilon: float32): bool {. epsilon: float32): bool {.inline.} =
noSideEffect, getGDNativeAPI().planeHasPoint(self, point, epsilon)
importc: "godot_plane_has_point".}
proc project*(self: Plane; point: Vector3): Vector3 {. proc project*(self: Plane; point: Vector3): Vector3 {.inline.} =
noSideEffect, getGDNativeAPI().planeProject(self, point)
importc: "godot_plane_project".}
proc intersect3*(self: Plane; dest: var Vector3; proc intersect3*(self: Plane; dest: var Vector3;
b, c: Plane): bool {. b, c: Plane): bool {.inline.} =
noSideEffect, getGDNativeAPI().planeIntersect3(self, dest, b, c)
importc: "godot_plane_intersect_3".}
proc intersectsRay*(self: Plane; dest: var Vector3; proc intersectsRay*(self: Plane; dest: var Vector3;
v, dir: Vector3): bool {. v, dir: Vector3): bool {.inline.} =
noSideEffect, getGDNativeAPI().planeIntersectsRay(self, dest, v, dir)
importc: "godot_plane_intersects_ray".}
proc intersectsSegment*(self: Plane; dest: var Vector3; proc intersectsSegment*(self: Plane; dest: var Vector3;
segmentBegin, segmentEnd: Vector3): bool {. segmentBegin, segmentEnd: Vector3): bool {.inline.} =
noSideEffect, importc: "godot_plane_intersects_segment".} getGDNativeAPI().planeIntersectsSegment(self, dest, segmentBegin, segmentEnd)
proc `-`*(self: Plane): Plane {.
noSideEffect, proc `-`*(self: Plane): Plane {.inline.} =
importc: "godot_plane_operator_neg".} getGDNativeAPI().planeOperatorNeg(self)
proc `==`*(a, b: Plane): bool {.
noSideEffect, proc `==`*(a, b: Plane): bool {.inline.} =
importc: "godot_plane_operator_equal".} getGDNativeAPI().planeOperatorEqual(a, b)

View file

@ -1,7 +1,8 @@
# Copyright 2017 Xored Software, Inc. # Copyright 2017 Xored Software, Inc.
import vector2, vector3, colors import godotcoretypes
import internal.godotpoolarrays, internal.godotstrings import internal.godotinternaltypes, internal.godotpoolarrays,
internal.godotstrings
template definePoolArrayBase(T, GodotT, DataT, fieldName, newProcName, template definePoolArrayBase(T, GodotT, DataT, fieldName, newProcName,
initProcName) = initProcName) =
@ -51,9 +52,6 @@ template definePoolArray(T, GodotT, DataT, fieldName, newProcName, initProcName;
proc add*(self: var T; data: DataT) {.inline.} = proc add*(self: var T; data: DataT) {.inline.} =
self.fieldName.add(data) self.fieldName.add(data)
proc addFirst*(self: var T, data: DataT) {.inline.} =
self.fieldName.addFirst(data)
proc insert*(self: var T; idx: int; data: DataT): Error {.inline.} = proc insert*(self: var T; idx: int; data: DataT): Error {.inline.} =
self.fieldName.insert(idx.cint, data) self.fieldName.insert(idx.cint, data)
@ -93,7 +91,7 @@ definePoolArrayBase(PoolStringArray, GodotPoolStringArray, string,
godotPoolStringArray, newPoolStringArray, godotPoolStringArray, newPoolStringArray,
initGodotPoolStringArray) initGodotPoolStringArray)
import godotbase, arrays import arrays
definePoolArray(PoolByteArray, GodotPoolByteArray, uint8, definePoolArray(PoolByteArray, GodotPoolByteArray, uint8,
godotPoolByteArray, newPoolByteArray, godotPoolByteArray, newPoolByteArray,
@ -122,11 +120,6 @@ proc add*(self: var PoolStringArray; data: string) =
self.godotPoolStringArray.add(s) self.godotPoolStringArray.add(s)
s.deinit() s.deinit()
proc addFirst*(self: var PoolStringArray, data: string) =
var s = data.toGodotString()
self.godotPoolStringArray.addFirst(s)
s.deinit()
proc insert*(self: var PoolStringArray; idx: int; data: string): Error = proc insert*(self: var PoolStringArray; idx: int; data: string): Error =
var s = data.toGodotString() var s = data.toGodotString()
result = self.godotPoolStringArray.insert(idx.cint, s) result = self.godotPoolStringArray.insert(idx.cint, s)

View file

@ -1,91 +1,78 @@
# Copyright (c) 2017 Xored Software, Inc. # Copyright (c) 2017 Xored Software, Inc.
import vector3 import internal.godotinternaltypes, godotcoretypes, gdnativeapi
import internal.godotstrings
type
Quat* {.byref.} = object
x*: float32
y*: float32
z*: float32
w*: float32
proc initQuat(dest: var Quat; x, y, z, w: float32) {.
importc: "godot_quat_new".}
proc initQuat(dest: var Quat; axis: Vector3; angle: float32) {.
importc: "godot_quat_new_with_axis_angle".}
proc initQuat*(x, y, z, w: float32): Quat {.inline.} = proc initQuat*(x, y, z, w: float32): Quat {.inline.} =
initQuat(result, x, y, z, w) result = Quat(
x: x,
y: y,
z: z,
w: w
)
proc initQuat*(axis: Vector3; angle: float32): Quat {.inline.} = proc initQuat*(axis: Vector3; angle: float32): Quat {.inline.} =
initQuat(result, axis, angle) getGDNativeAPI().quatNewWithAxisAngle(result, axis, angle)
proc toGodotString(self: Quat): GodotString {.
noSideEffect,
importc: "godot_quat_as_string".}
proc `$`*(self: Quat): string {.inline.} = proc `$`*(self: Quat): string {.inline.} =
$self.toGodotString() $getGDNativeAPI().quatAsString(self)
proc length*(self: Quat): float32 {.inline.} =
getGDNativeAPI().quatLength(self)
proc lengthSquared*(self: Quat): float32 {.inline.} =
getGDNativeAPI().quatLengthSquared(self)
proc normalized*(self: Quat): Quat {.inline.} =
getGDNativeAPI().quatNormalized(self)
proc isNormalized*(self: Quat): bool {.inline.} =
getGDNativeAPI().quatIsNormalized(self)
proc inverse*(self: Quat): Quat {.inline.} =
getGDNativeAPI().quatInverse(self)
proc dot*(a, b: Quat): float32 {.inline.} =
getGDNativeAPI().quatDot(a, b)
proc xform*(self: Quat; v: Vector3): Vector3 {.inline.} =
getGDNativeAPI().quatXform(self, v)
proc slerp*(self: Quat; b: Quat; t: float32): Quat {.inline.} =
getGDNativeAPI().quatSlerp(self, b, t)
proc slerpni*(self: Quat; b: Quat; t: float32): Quat {.inline.} =
getGDNativeAPI().quatSlerpni(self, b, t)
proc cubicSlerp*(self, b, preA, postB: Quat;
t: float32): Quat {.inline.} =
getGDNativeAPI().quatCubicSlerp(self, b, preA, postB, t)
proc `*`*(a: Quat, b: float32): Quat {.inline.} =
getGDNativeAPI().quatOperatorMultiply(a, b)
proc length*(self: Quat): float32 {.
noSideEffect,
importc: "godot_quat_length".}
proc lengthSquared*(self: Quat): float32 {.
noSideEffect,
importc: "godot_quat_length_squared".}
proc normalized*(self: Quat): Quat {.
noSideEffect,
importc: "godot_quat_normalized".}
proc isNormalized*(self: Quat): bool {.
noSideEffect,
importc: "godot_quat_is_normalized".}
proc inverse*(self: Quat): Quat {.
noSideEffect,
importc: "godot_quat_inverse".}
proc dot*(a, b: Quat): float32 {.
noSideEffect,
importc: "godot_quat_dot".}
proc xform*(self: Quat; v: Vector3): Vector3 {.
noSideEffect,
importc: "godot_quat_xform".}
proc slerp*(self: Quat; b: Quat; t: float32): Quat {.
noSideEffect,
importc: "godot_quat_slerp".}
proc slerpni*(self: Quat; b: Quat; t: float32): Quat {.
noSideEffect,
importc: "godot_quat_slerpni".}
proc cubicSlerp*(self, b, pre_a, post_b: Quat;
t: float32): Quat {.
noSideEffect,
importc: "godot_quat_cubic_slerp".}
proc `*`*(a: Quat, b: float32): Quat {.
noSideEffect,
importc: "godot_quat_operator_multiply".}
proc `*=`*(a: var Quat, b: float32) {.inline.} = proc `*=`*(a: var Quat, b: float32) {.inline.} =
a = a * b a = a * b
proc `+`*(a, b: Quat): Quat {. proc `+`*(a, b: Quat): Quat {.inline.} =
noSideEffect, getGDNativeAPI().quatOperatorAdd(a, b)
importc: "godot_quat_operator_add".}
proc `+=`*(a: var Quat, b: Quat) {.inline.} = proc `+=`*(a: var Quat, b: Quat) {.inline.} =
a = a + b a = a + b
proc `-`*(a, b: Quat): Quat {. proc `-`*(a, b: Quat): Quat {.inline.} =
noSideEffect, getGDNativeAPI().quatOperatorSubtract(a, b)
importc: "godot_quat_operator_substract".}
proc `-=`* (a: var Quat, b: Quat) {.inline.} = proc `-=`* (a: var Quat, b: Quat) {.inline.} =
a = a - b a = a - b
proc `/`*(self: Quat; b: float32): Quat {. proc `/`*(self: Quat; b: float32): Quat {.inline.} =
noSideEffect, getGDNativeAPI().quatOperatorDivide(self, b)
importc: "godot_quat_operator_divide".}
proc `/=`*(self: var Quat, b: float32) {.inline.} = proc `/=`*(self: var Quat, b: float32) {.inline.} =
self = self / b self = self / b
proc `==`*(a, b: Quat): bool {. proc `==`*(a, b: Quat): bool {.inline.} =
noSideEffect, getGDNativeAPI().quatOperatorEqual(a, b)
importc: "godot_quat_operator_equal".}
proc `-`*(self: Quat): Quat {. proc `-`*(self: Quat): Quat {.inline.} =
noSideEffect, getGDNativeAPI().quatOperatorNeg(self)
importc: "godot_quat_operator_neg".}

View file

@ -1,13 +1,7 @@
# Copyright (c) 2017 Xored Software, Inc. # Copyright (c) 2017 Xored Software, Inc.
import vector2 import vector2
import godotcoretypes, internal.godotinternaltypes, gdnativeapi
import internal.godotstrings
type
Rect2* {.byref.} = object
position*: Vector2
size*: Vector2
proc initRect2*(pos, size: Vector2): Rect2 {.inline.} = proc initRect2*(pos, size: Vector2): Rect2 {.inline.} =
Rect2(position: pos, size: size) Rect2(position: pos, size: size)
@ -15,40 +9,35 @@ proc initRect2*(pos, size: Vector2): Rect2 {.inline.} =
proc initRect2*(x, y, sizeX, sizeY: float32): Rect2 {.inline.} = proc initRect2*(x, y, sizeX, sizeY: float32): Rect2 {.inline.} =
Rect2(position: vec2(x, y), size: vec2(sizeX, sizeY)) Rect2(position: vec2(x, y), size: vec2(sizeX, sizeY))
proc toGodotString(self: Rect2): GodotString {.
noSideEffect,
importc: "godot_rect2_as_string".}
proc `$`*(self: Rect2): string {.inline.} = proc `$`*(self: Rect2): string {.inline.} =
$self.toGodotString() $getGDNativeAPI().rect2AsString(self)
proc area*(self: Rect2): float32 {. proc area*(self: Rect2): float32 {.inline.} =
noSideEffect, getGDNativeAPI().rect2GetArea(self)
importc: "godot_rect2_get_area".}
proc intersects*(a, b: Rect2): bool {. proc intersects*(a, b: Rect2): bool {.inline.} =
noSideEffect, getGDNativeAPI().rect2Intersects(a, b)
importc: "godot_rect2_intersects".}
proc encloses*(a, b: Rect2): bool {. proc encloses*(a, b: Rect2): bool {.inline.} =
noSideEffect, getGDNativeAPI().rect2Encloses(a, b)
importc: "godot_rect2_encloses".}
proc hasNoArea*(self: Rect2): bool {. proc hasNoArea*(self: Rect2): bool {.inline.} =
noSideEffect, getGDNativeAPI().rect2HasNoArea(self)
importc: "godot_rect2_has_no_area".}
proc clip*(a, b: Rect2): Rect2 {. proc clip*(self, b: Rect2): Rect2 {.inline.} =
noSideEffect, getGDNativeAPI().rect2Clip(self, b)
importc: "godot_rect2_clip".}
proc merge*(a, b: Rect2): Rect2 {. proc merge*(self, b: Rect2): Rect2 {.inline.} =
noSideEffect, getGDNativeAPI().rect2Merge(self, b)
importc: "godot_rect2_merge".}
proc contains*(self: Rect2; point: Vector2): bool {. proc contains*(self: Rect2; point: Vector2): bool {.inline.} =
noSideEffect, getGDNativeAPI().rect2HasPoint(self, point)
importc: "godot_rect2_has_point".}
proc grow*(self: Rect2; by: float32): Rect2 {. proc grow*(self: Rect2; by: float32): Rect2 {.inline.} =
noSideEffect, getGDNativeAPI().rect2Grow(self, by)
importc: "godot_rect2_grow".}
proc expand*(self: Rect2; to: Vector2): Rect2 {. proc expand*(self: Rect2; to: Vector2): Rect2 {.inline.} =
noSideEffect, getGDNativeAPI().rect2Expand(self, to)
importc: "godot_rect2_expand".}
proc `==`*(a, b: Rect2): bool {. proc `==`*(a, b: Rect2): bool {.inline.} =
noSideEffect, getGDNativeAPI().rect2OperatorEqual(a, b)
importc: "godot_rect2_operator_equal".}

View file

@ -1,84 +1,72 @@
# Copyright (c) 2017 Xored Software, Inc. # Copyright (c) 2017 Xored Software, Inc.
import planes, vector3 import godotcoretypes, internal.godotinternaltypes, gdnativeapi
import internal.godotstrings
type
Rect3* {.byref.} = object
position*: Vector3
size*: Vector3
proc initRect3*(pos, size: Vector3): Rect3 {.inline.} = proc initRect3*(pos, size: Vector3): Rect3 {.inline.} =
Rect3(position: pos, size: size) Rect3(position: pos, size: size)
proc toGodotString(self: Rect3): GodotString {.
noSideEffect,
importc: "godot_rect3_as_string".}
proc `$`*(self: Rect3): string {.inline.} = proc `$`*(self: Rect3): string {.inline.} =
$self.toGodotString() $getGDNativeAPI().rect3AsString(self)
proc area*(self: Rect3): float32 {. proc area*(self: Rect3): float32 {.inline.} =
noSideEffect, getGDNativeAPI().rect3GetArea(self)
importc: "godot_rect3_get_area".}
proc hasNoArea*(self: Rect3): bool {. proc hasNoArea*(self: Rect3): bool {.inline.} =
noSideEffect, getGDNativeAPI().rect3HasNoArea(self)
importc: "godot_rect3_has_no_area".}
proc hasNoSurface*(self: Rect3): bool {. proc hasNoSurface*(self: Rect3): bool {.inline.} =
noSideEffect, getGDNativeAPI().rect3HasNoSurface(self)
importc: "godot_rect3_has_no_surface".}
proc intersects*(a, b: Rect3): bool {. proc intersects*(self, other: Rect3): bool {.inline.} =
noSideEffect, getGDNativeAPI().rect3Intersects(self, other)
importc: "godot_rect3_intersects".}
proc encloses*(self, other: Rect3): bool {. proc encloses*(self, other: Rect3): bool {.inline.} =
noSideEffect, getGDNativeAPI().rect3Encloses(self, other)
importc: "godot_rect3_encloses".}
proc merge*(self, other: Rect3): Rect3 {. proc merge*(self, other: Rect3): Rect3 {.inline.} =
noSideEffect, getGDNativeAPI().rect3Merge(self, other)
importc: "godot_rect3_merge".}
proc intersection*(self, other: Rect3): Rect3 {. proc intersection*(self, other: Rect3): Rect3 {.inline.} =
noSideEffect, getGDNativeAPI().rect3Intersection(self, other)
importc: "godot_rect3_intersection".}
proc intersectsPlane*(self: Rect3; plane: Plane): bool {. proc intersectsPlane*(self: Rect3; plane: Plane): bool {.inline.} =
noSideEffect, getGDNativeAPI().rect3IntersectsPlane(self, plane)
importc: "godot_rect3_intersects_plane".}
proc intersectsSegment*(self: Rect3; start, to: Vector3): bool {. proc intersectsSegment*(self: Rect3; start, to: Vector3): bool {.inline.} =
noSideEffect, getGDNativeAPI().rect3IntersectsSegment(self, start, to)
importc: "godot_rect3_intersects_segment".}
proc contains*(self: Rect3; point: Vector3): bool {. proc contains*(self: Rect3; point: Vector3): bool {.inline.} =
noSideEffect, getGDNativeAPI().rect3HasPoint(self, point)
importc: "godot_rect3_has_point".}
proc getSupport*(self: Rect3; dir: Vector3): Vector3 {. proc getSupport*(self: Rect3; dir: Vector3): Vector3 {.inline.} =
noSideEffect, getGDNativeAPI().rect3GetSupport(self, dir)
importc: "godot_rect3_get_support".}
proc getLongestAxis*(self: Rect3): Vector3 {. proc getLongestAxis*(self: Rect3): Vector3 {.inline.} =
noSideEffect, getGDNativeAPI().rect3GetLongestAxis(self)
importc: "godot_rect3_get_longest_axis".}
proc getLongestAxisIndex*(self: Rect3): cint {. proc getLongestAxisIndex*(self: Rect3): cint {.inline.} =
noSideEffect, getGDNativeAPI().rect3GetLongestAxisIndex(self)
importc: "godot_rect3_get_longest_axis_index".}
proc getLongestAxisSize*(self: Rect3): float32 {. proc getLongestAxisSize*(self: Rect3): float32 {.inline.} =
noSideEffect, getGDNativeAPI().rect3GetLongestAxisSize(self)
importc: "godot_rect3_get_longest_axis_size".}
proc getShortestAxis*(self: Rect3): Vector3 {. proc getShortestAxis*(self: Rect3): Vector3 {.inline.} =
noSideEffect, getGDNativeAPI().rect3GetShortestAxis(self)
importc: "godot_rect3_get_shortest_axis".}
proc getShortestAxisIndex*(self: Rect3): cint {. proc getShortestAxisIndex*(self: Rect3): cint {.inline.} =
noSideEffect, getGDNativeAPI().rect3GetShortestAxisIndex(self)
importc: "godot_rect3_get_shortest_axis_index".}
proc getShortestAxisSize*(self: Rect3): float32 {. proc getShortestAxisSize*(self: Rect3): float32 {.inline.} =
noSideEffect, getGDNativeAPI().rect3GetShortestAxisSize(self)
importc: "godot_rect3_get_shortest_axis_size".}
proc expand*(self: Rect3; toPoint: Vector3): Rect3 {. proc expand*(self: Rect3; toPoint: Vector3): Rect3 {.inline.} =
noSideEffect, getGDNativeAPI().rect3Expand(self, toPoint)
importc: "godot_rect3_expand".}
proc grow*(self: Rect3; by: float32): Rect3 {. proc grow*(self: Rect3; by: float32): Rect3 {.inline.} =
noSideEffect, getGDNativeAPI().rect3Grow(self, by)
importc: "godot_rect3_grow".}
proc getEndpoint*(self: Rect3; idx: cint): Vector3 {. proc getEndpoint*(self: Rect3; idx: cint): Vector3 {.inline.} =
noSideEffect, getGDNativeAPI().rect3GetEndpoint(self, idx)
importc: "godot_rect3_get_endpoint".}
proc `==`*(a, b: Rect3): bool {. proc `==`*(a, b: Rect3): bool {.inline.} =
noSideEffect, getGDNativeAPI().rect3OperatorEqual(a, b)
importc: "godot_rect3_operator_equal".}

View file

@ -1,31 +1,21 @@
import internal.godotobjects # Copyright (c) 2017 Xored Software, Inc.
type import godotcoretypes, internal.godotinternaltypes, gdnativeapi
RID* {.byref.} = object
data: array[sizeof(int), byte]
proc initRID(dest: var RID) {.
importc: "godot_rid_new".}
proc initRID(dest: var RID; obj: ptr GodotObject) {.
importc: "godot_rid_new_with_resource".}
proc initRID*(): RID {.inline.} = proc initRID*(): RID {.inline.} =
initRID(result) getGDNativeAPI().ridNew(result)
proc initRID*(obj: ptr GodotObject): RID {.inline.} = proc initRID*(obj: ptr GodotObject): RID {.inline.} =
initRID(result, obj) getGDNativeAPI().ridNewWithResource(result, obj)
proc idCInt(self: RID): cint {.
noSideEffect,
importc: "godot_rid_get_id".}
proc id*(self: RID): uint32 {.inline.} = proc id*(self: RID): uint32 {.inline.} =
cast[uint32](self.idCInt()) cast[uint32](getGDNativeAPI().ridGetId(self))
proc `$`*(self: RID): string = proc `$`*(self: RID): string {.inline.} =
$self.id $self.id
proc `==`*(a, b: RID): bool {. proc `==`*(a, b: RID): bool {.inline.} =
importc: "godot_rid_operator_equal".} getGDNativeAPI().ridOperatorEqual(a, b)
proc `<`*(a, b: RID): bool {.
importc: "godot_rid_operator_less".} proc `<`*(a, b: RID): bool {.inline.} =
getGDNativeAPI().ridOperatorLess(a, b)

View file

@ -1,76 +1,73 @@
# Copyright (c) 2017 Xored Software, Inc. # Copyright (c) 2017 Xored Software, Inc.
import vector2, rect2 import godotcoretypes, internal.godotinternaltypes, gdnativeapi
import internal.godotstrings
type
Transform2D* {.byref.} = object
elements*: array[3, Vector2]
proc initTransform2D(dest: var Transform2D) {.
importc: "godot_transform2d_new_identity".}
proc initTransform2D(dest: var Transform2D; rot: float32; pos: Vector2) {.
importc: "godot_transform2d_new".}
proc initTransform2D(dest: var Transform2D; xAxis, yAxis, origin: Vector2) {.
importc: "godot_transform2d_new_axis_origin".}
proc initTransform2D*(): Transform2D {.inline.} = proc initTransform2D*(): Transform2D {.inline.} =
initTransform2D(result) getGDNativeAPI().transform2DNewIdentity(result)
proc initTransform2D*(rot: float32; pos: Vector2): Transform2D {.inline.} = proc initTransform2D*(rot: float32; pos: Vector2): Transform2D {.inline.} =
initTransform2D(result, rot, pos) getGDNativeAPI().transform2DNew(result, rot, pos)
proc initTransform2D*(xAxis, yAxis, origin: Vector2): Transform2D {.inline.} = proc initTransform2D*(xAxis, yAxis, origin: Vector2): Transform2D {.inline.} =
initTransform2D(result, xAxis, yAxis, origin) getGDNativeAPI().transform2DNewAxisOrigin(result, xAxis, yAxis, origin)
proc toGodotString(self: Transform2D): GodotString {.
importc: "godot_transform2d_as_string".}
proc `$`*(self: Transform2D): string {.inline.} = proc `$`*(self: Transform2D): string {.inline.} =
$self.toGodotString() $getGDNativeAPI().transform2DAsString(self)
proc inverse*(self: Transform2D): Transform2D {. proc inverse*(self: Transform2D): Transform2D {.inline.} =
importc: "godot_transform2d_inverse".} getGDNativeAPI().transform2DInverse(self)
proc affineInverse*(self: Transform2D): Transform2D {.
importc: "godot_transform2d_affine_inverse".} proc affineInverse*(self: Transform2D): Transform2D {.inline.} =
proc rotation*(self: Transform2D): float32 {. getGDNativeAPI().transform2DAffineInverse(self)
importc: "godot_transform2d_get_rotation".}
proc origin*(self: Transform2D): Vector2 {. proc rotation*(self: Transform2D): float32 {.inline.} =
importc: "godot_transform2d_get_origin".} getGDNativeAPI().transform2DGetRotation(self)
proc scale*(self: Transform2D): Vector2 {.
importc: "godot_transform2d_get_scale".} proc origin*(self: Transform2D): Vector2 {.inline.} =
proc orthonormalized*(self: Transform2D): Transform2D {. getGDNativeAPI().transform2DGetOrigin(self)
importc: "godot_transform2d_orthonormalized".}
proc rotated*(self: Transform2D; phi: float32): Transform2D {. proc scale*(self: Transform2D): Vector2 {.inline.} =
importc: "godot_transform2d_rotated".} getGDNativeAPI().transform2DGetScale(self)
proc scaled*(self: Transform2D; scale: Vector2): Transform2D {.
importc: "godot_transform2d_scaled".} proc orthonormalized*(self: Transform2D): Transform2D {.inline.} =
proc translated*(self: Transform2D; getGDNativeAPI().transform2DOrthonormalized(self)
offset: Vector2): Transform2D {.
importc: "godot_transform2d_translated".} proc rotated*(self: Transform2D; phi: float32): Transform2D {.inline.} =
proc xformVector2*(self: Transform2D; v: Vector2): Vector2 {. getGDNativeAPI().transform2DRotated(self, phi)
importc: "godot_transform2d_xform_vector2".}
proc xformInvVector2*(self: Transform2D; v: Vector2): Vector2 {. proc scaled*(self: Transform2D; scale: Vector2): Transform2D {.inline.} =
importc: "godot_transform2d_xform_inv_vector2".} getGDNativeAPI().transform2DScaled(self, scale)
proc basisXformVector2*(self: Transform2D;
v: Vector2): Vector2 {. proc translated*(self: Transform2D; offset: Vector2): Transform2D {.inline.} =
importc: "godot_transform2d_basis_xform_vector2".} getGDNativeAPI().transform2DTranslated(self, offset)
proc basisXformInvVector2*(self: Transform2D;
v: Vector2): Vector2 {. proc xformVector2*(self: Transform2D; v: Vector2): Vector2 {.inline.} =
importc: "godot_transform2d_basis_xform_inv_vector2".} getGDNativeAPI().transform2DXformVector2(self, v)
proc xformRect2*(self: Transform2D; v: Rect2): Rect2 {.
importc: "godot_transform2d_xform_rect2".} proc xformInvVector2*(self: Transform2D; v: Vector2): Vector2 {.inline.} =
proc xformInvRect2*(self: Transform2D; v: Rect2): Rect2 {. getGDNativeAPI().transform2DXformInvVector2(self, v)
importc: "godot_transform2d_xform_inv_rect2".}
proc basisXformVector2*(self: Transform2D; v: Vector2): Vector2 {.inline.} =
getGDNativeAPI().transform2DBasisXformVector2(self, v)
proc basisXformInvVector2*(self: Transform2D; v: Vector2): Vector2 {.inline.} =
getGDNativeAPI().transform2DBasisXformInvVector2(self, v)
proc xformRect2*(self: Transform2D; rect: Rect2): Rect2 {.inline.} =
getGDNativeAPI().transform2DXformRect2(self, rect)
proc xformInvRect2*(self: Transform2D; rect: Rect2): Rect2 {.inline.} =
getGDNativeAPI().transform2DXformInvRect2(self, rect)
proc interpolateWith*(self, m: Transform2D; proc interpolateWith*(self, m: Transform2D;
c: float32): Transform2D {. c: float32): Transform2D {.inline.} =
importc: "godot_transform2d_interpolate_with".} getGDNativeAPI().transform2DInterpolateWith(self, m, c)
proc `==`*(a, b: Transform2D): bool {.
importc: "godot_transform2d_operator_equal".} proc `==`*(a, b: Transform2D): bool {.inline.} =
proc `*`*(a, b: Transform2D): Transform2D {. getGDNativeAPI().transform2DOperatorEqual(a, b)
importc: "godot_transform2d_operator_multiply".}
proc `*`*(a, b: Transform2D): Transform2D {.inline.} =
getGDNativeAPI().transform2DOperatorMultiply(a, b)
proc `*=`*(a: var Transform2D, b: Transform2D) {.inline.} = proc `*=`*(a: var Transform2D, b: Transform2D) {.inline.} =
a = a * b a = a * b

View file

@ -1,13 +1,7 @@
# Copyright (c) 2017 Xored Software, Inc. # Copyright (c) 2017 Xored Software, Inc.
import basis, vector3, planes, rect3 import godotcoretypes, internal.godotinternaltypes, gdnativeapi
import basis
import internal.godotstrings
type
Transform* {.byref.} = object
basis*: Basis
origin*: Vector3
proc initTransform*(): Transform {.inline.} = proc initTransform*(): Transform {.inline.} =
result.basis = initBasis() result.basis = initBasis()
@ -23,45 +17,54 @@ proc initTransform*(xAxis, yAxis, zAxis,
proc initTransform*(basis: Basis, origin: Vector3): Transform {.inline.} = proc initTransform*(basis: Basis, origin: Vector3): Transform {.inline.} =
Transform(basis: basis, origin: origin) Transform(basis: basis, origin: origin)
proc toGodotString(self: Transform): GodotString {.
importc: "godot_transform_as_string".}
proc `$`*(self: Transform): string {.inline.} = proc `$`*(self: Transform): string {.inline.} =
$self.toGodotString() $getGDNativeAPI().transformAsString(self)
proc inverse*(self: Transform): Transform {.inline.} =
getGDNativeAPI().transformInverse(self)
proc affineInverse*(self: Transform): Transform {.inline.} =
getGDNativeAPI().transformAffineInverse(self)
proc orthonormalized*(self: Transform): Transform {.inline.} =
getGDNativeAPI().transformOrthonormalized(self)
proc inverse*(self: Transform): Transform {.
importc: "godot_transform_inverse".}
proc affineInverse*(self: Transform): Transform {.
importc: "godot_transform_affine_inverse".}
proc orthonormalized*(self: Transform): Transform {.
importc: "godot_transform_orthonormalized".}
proc rotated*(self: Transform; axis: Vector3; proc rotated*(self: Transform; axis: Vector3;
phi: float32): Transform {. phi: float32): Transform {.inline.} =
importc: "godot_transform_rotated".} getGDNativeAPI().transformRotated(self, axis, phi)
proc scaled*(self: Transform; scale: Vector3): Transform {.
importc: "godot_transform_scaled".}
proc translated*(self: Transform; offset: Vector3): Transform {.
importc: "godot_transform_translated".}
proc lookingAt*(self: Transform;
target, up: Vector3): Transform {.
importc: "godot_transform_looking_at".}
proc xformPlane*(self: Transform; v: Plane): Plane {. proc scaled*(self: Transform; scale: Vector3): Transform {.inline.} =
importc: "godot_transform_xform_plane".} getGDNativeAPI().transformScaled(self, scale)
proc xformInvPlane*(self: Transform; v: Plane): Plane {.
importc: "godot_transform_xform_inv_plane".}
proc xformVector3*(self: Transform; v: Vector3): Vector3 {.
importc: "godot_transform_xform_vector3".}
proc xformInvVector3*(self: Transform; v: Vector3): Vector3 {.
importc: "godot_transform_xform_inv_vector3".}
proc xformRect3*(self: Transform; v: Rect3): Rect3 {.
importc: "godot_transform_xform_rect3".}
proc xformInvRect3*(self: Transform; v: Rect3): Rect3 {.
importc: "godot_transform_xform_inv_rect3".}
proc `==`*(self: Transform; b: Transform): bool {. proc translated*(self: Transform; offset: Vector3): Transform {.inline.} =
importc: "godot_transform_operator_equal".} getGDNativeAPI().transformTranslated(self, offset)
proc `*`*(a, b: Transform): Transform {.
importc: "godot_transform_operator_multiply".} proc lookingAt*(self: Transform; target, up: Vector3): Transform {.inline.} =
proc `*=`*(a: var Transform, b: Transform) {.inline.} = getGDNativeAPI().transformLookingAt(self, target, up)
a = a * b
proc xformPlane*(self: Transform; plane: Plane): Plane {.inline.} =
getGDNativeAPI().transformXformPlane(self, plane)
proc xformInvPlane*(self: Transform; plane: Plane): Plane {.inline.} =
getGDNativeAPI().transformXformInvPlane(self, plane)
proc xformVector3*(self: Transform; v: Vector3): Vector3 {.inline.} =
getGDNativeAPI().transformXformVector3(self, v)
proc xformInvVector3*(self: Transform; v: Vector3): Vector3 {.inline.} =
getGDNativeAPI().transformXformInvVector3(self, v)
proc xformRect3*(self: Transform; rect: Rect3): Rect3 {.inline.} =
getGDNativeAPI().transformXformRect3(self, rect)
proc xformInvRect3*(self: Transform; rect: Rect3): Rect3 {.inline.} =
getGDNativeAPI().transformXformInvRect3(self, rect)
proc `==`*(self: Transform; b: Transform): bool {.inline.} =
getGDNativeAPI().transformOperatorEqual(self, b)
proc `*`*(self, other: Transform): Transform {.inline.} =
getGDNativeAPI().transformOperatorMultiply(self, other)
proc `*=`*(self: var Transform, other: Transform) {.inline.} =
self = self * other

View file

@ -1,7 +1,8 @@
import tables import tables
import internal.godotobjects, internal.godotvariants, internal.godotpoolarrays, import godotcoretypes
internal.godotstrings, internal.godotnodepaths import internal.godotinternaltypes, internal.godotvariants,
internal.godotstrings
type type
Variant* = ref object Variant* = ref object
@ -267,5 +268,5 @@ proc `<`*(self, other: Variant): bool =
proc hashCompare*(self, other: Variant): bool = proc hashCompare*(self, other: Variant): bool =
self.godotVariant.hashCompare(other.godotVariant) self.godotVariant.hashCompare(other.godotVariant)
proc booleanize*(self: Variant; isValid: var bool): bool = proc booleanize*(self: Variant): bool =
self.godotVariant.booleanize(isValid) self.godotVariant.booleanize()

View file

@ -1,109 +1,121 @@
# Copyright (c) 2017 Xored Software, Inc. # Copyright (c) 2017 Xored Software, Inc.
import internal.godotstrings import internal.godotinternaltypes, godotcoretypes, gdnativeapi
type
Vector2* {.byref.} = object
x*: float32
y*: float32
proc vec2*(x, y: float32): Vector2 {.inline.} = proc vec2*(x, y: float32): Vector2 {.inline.} =
Vector2(x: x, y: y) Vector2(x: x, y: y)
proc toGodotString(self: Vector2): GodotString {.
importc: "godot_vector2_as_string".}
proc `$`*(self: Vector2): string {.inline.} = proc `$`*(self: Vector2): string {.inline.} =
$self.toGodotString() $getGDNativeAPI().vector2AsString(self)
proc normalized*(self: Vector2): Vector2 {. proc normalized*(self: Vector2): Vector2 {.inline.} =
importc: "godot_vector2_normalized".} getGDNativeAPI().vector2Normalized(self)
proc length*(self: Vector2): float32 {.
importc: "godot_vector2_length".}
proc angle*(self: Vector2): float32 {.
importc: "godot_vector2_angle".}
proc lengthSquared*(self: Vector2): float32 {.
importc: "godot_vector2_length_squared".}
proc isNormalized*(self: Vector2): bool {.
importc: "godot_vector2_is_normalized".}
proc distanceTo*(self, to: Vector2): float32 {.
importc: "godot_vector2_distance_to".}
proc distanceSquaredTo*(self, to: Vector2): float32 {.
importc: "godot_vector2_distance_squared_to".}
proc angleTo*(self, to: Vector2): float32 {.
importc: "godot_vector2_angle_to".}
proc angleToPoint*(self, to: Vector2): float32 {.
importc: "godot_vector2_angle_to_point".}
proc lerp*(self, b: Vector2; t: float32): Vector2 {.
importc: "godot_vector2_linear_interpolate".}
proc cubicInterpolate*(self, b, pre_a, post_b: Vector2; t: float32): Vector2 {.
importc: "godot_vector2_cubic_interpolate".}
proc rotated*(self: Vector2; phi: float32): Vector2 {.
importc: "godot_vector2_rotated".}
proc tangent*(self: Vector2): Vector2 {.
importc: "godot_vector2_tangent".}
proc floor*(self: Vector2): Vector2 {.
importc: "godot_vector2_floor".}
proc snapped*(self: Vector2; by: Vector2): Vector2 {.
importc: "godot_vector2_snapped".}
proc aspect*(self: Vector2): float32 {.
importc: "godot_vector2_aspect".}
proc dot*(a, b: Vector2): float32 {.
importc: "godot_vector2_dot".}
proc slide*(self, n: Vector2): Vector2 {.
importc: "godot_vector2_slide".}
proc bounce*(self, n: Vector2): Vector2 {.
importc: "godot_vector2_bounce".}
proc reflect*(self, n: Vector2): Vector2 {.
importc: "godot_vector2_reflect".}
proc abs*(self: Vector2): Vector2 {.
importc: "godot_vector2_abs".}
proc clamped*(self: Vector2; length: float32): Vector2 {.
importc: "godot_vector2_clamped".}
proc `+`*(a, b: Vector2): Vector2 {. proc length*(self: Vector2): float32 {.inline.} =
importc: "godot_vector2_operator_add".} getGDNativeAPI().vector2Length(self)
proc `+=`*(a: var Vector2, b: Vector2) {.inline.} =
a += b
proc `-`*(a, b: Vector2): Vector2 {. proc angle*(self: Vector2): float32 {.inline.} =
importc: "godot_vector2_operator_substract".} getGDNativeAPI().vector2Angle(self)
proc `-=`*(a: var Vector2, b: Vector2) {.inline.} =
a = a - b
proc `*`*(a, b: Vector2): Vector2 {. proc lengthSquared*(self: Vector2): float32 {.inline.} =
importc: "godot_vector2_operator_multiply_vector".} getGDNativeAPI().vector2LengthSquared(self)
proc `*=`*(a: var Vector2, b: Vector2) {.inline.} = proc isNormalized*(self: Vector2): bool {.inline.} =
a = a * b getGDNativeAPI().vector2IsNormalized(self)
proc distanceTo*(self, to: Vector2): float32 {.inline.} =
getGDNativeAPI().vector2DistanceTo(self, to)
proc distanceSquaredTo*(self, to: Vector2): float32 {.inline.} =
getGDNativeAPI().vector2DistanceSquaredTo(self, to)
proc angleTo*(self, to: Vector2): float32 {.inline.} =
getGDNativeAPI().vector2AngleTo(self, to)
proc angleToPoint*(self, to: Vector2): float32 {.inline.} =
getGDNativeAPI().vector2AngleToPoint(self, to)
proc lerp*(self, b: Vector2; t: float32): Vector2 {.inline.} =
getGDNativeAPI().vector2LinearInterpolate(self, b, t)
proc cubicInterpolate*(self, b, preA, postB: Vector2;
t: float32): Vector2 {.inline.} =
getGDNativeAPI().vector2CubicInterpolate(self, b, preA, postB, t)
proc rotated*(self: Vector2; phi: float32): Vector2 {.inline.} =
getGDNativeAPI().vector2Rotated(self, phi)
proc tangent*(self: Vector2): Vector2 {.inline.} =
getGDNativeAPI().vector2Tangent(self)
proc floor*(self: Vector2): Vector2 {.inline.} =
getGDNativeAPI().vector2Floor(self)
proc snapped*(self: Vector2; by: Vector2): Vector2 {.inline.} =
getGDNativeAPI().vector2Snapped(self, by)
proc aspect*(self: Vector2): float32 {.inline.} =
getGDNativeAPI().vector2Aspect(self)
proc dot*(a, b: Vector2): float32 {.inline.} =
getGDNativeAPI().vector2Dot(a, b)
proc slide*(self, n: Vector2): Vector2 {.inline.} =
getGDNativeAPI().vector2Slide(self, n)
proc bounce*(self, n: Vector2): Vector2 {.inline.} =
getGDNativeAPI().vector2Bounce(self, n)
proc reflect*(self, n: Vector2): Vector2 {.inline.} =
getGDNativeAPI().vector2Reflect(self, n)
proc abs*(self: Vector2): Vector2 {.inline.} =
getGDNativeAPI().vector2Abs(self)
proc clamped*(self: Vector2; length: float32): Vector2 {.inline.} =
getGDNativeAPI().vector2Clamped(self, length)
proc `+`*(self, other: Vector2): Vector2 {.inline.} =
getGDNativeAPI().vector2OperatorAdd(self, other)
proc `+=`*(self: var Vector2, other: Vector2) {.inline.} =
self += other
proc `-`*(self, other: Vector2): Vector2 =
getGDNativeAPI().vector2OperatorSubtract(self, other)
proc `-=`*(self: var Vector2, other: Vector2) {.inline.} =
self = self - other
proc `*`*(self, other: Vector2): Vector2 =
getGDNativeAPI().vector2OperatorMultiplyVector(self, other)
proc `*=`*(self: var Vector2, other: Vector2) {.inline.} =
self = self * other
proc `*`*(self: Vector2, scalar: float32): Vector2 =
getGDNativeAPI().vector2OperatorMultiplyScalar(self, scalar)
proc `*`*(self: Vector2, scalar: float32): Vector2 {.
importc: "godot_vector2_operator_multiply_scalar".}
proc `*=`*(self: var Vector2, scalar: float32) {.inline.} = proc `*=`*(self: var Vector2, scalar: float32) {.inline.} =
self = self * scalar self = self * scalar
proc `/`*(a, b: Vector2): Vector2 {. proc `/`*(self, other: Vector2): Vector2 =
importc: "godot_vector2_operator_divide_vector".} getGDNativeAPI().vector2OperatorDivideVector(self, other)
proc `/=`*(a: var Vector2, b: Vector2) {.inline.} =
a = a / b proc `/=`*(self: var Vector2, other: Vector2) {.inline.} =
self = self / other
proc `/`*(self: Vector2; scalar: float32): Vector2 =
getGDNativeAPI().vector2OperatorDivideScalar(self, scalar)
proc `/`*(self: Vector2; scalar: float32): Vector2 {.
importc: "godot_vector2_operator_divide_scalar".}
proc `/=`*(self: var Vector2; scalar: float32) {.inline.} = proc `/=`*(self: var Vector2; scalar: float32) {.inline.} =
self = self / scalar self = self / scalar
proc `==`*(a, b: Vector2): bool {. proc `==`*(self, other: Vector2): bool {.inline.} =
importc: "godot_vector2_operator_equal".} getGDNativeAPI().vector2OperatorEqual(self, other)
proc `<`*(a, b: Vector2): bool {.
importc: "godot_vector2_operator_less".}
proc `-`*(self: Vector2): Vector2 {.
importc: "godot_vector2_operator_neg".}
proc `x=`*(self: var Vector2; x: float32) {. proc `<`*(self, other: Vector2): bool {.inline.} =
importc: "godot_vector2_set_x".} getGDNativeAPI().vector2OperatorLess(self, other)
proc `y=`*(self: var Vector2; y: float32) {.
importc: "godot_vector2_set_y".} proc `-`*(self: Vector2): Vector2 {.inline.} =
proc x*(self: Vector2): float32 {. getGDNativeAPI().vector2OperatorNeg(self)
importc: "godot_vector2_get_x".}
proc y*(self: Vector2): float32 {.
importc: "godot_vector2_get_y".}

View file

@ -1,13 +1,7 @@
# Copyright (c) 2017 Xored Software, Inc. # Copyright (c) 2017 Xored Software, Inc.
import math import math
import godotbase import godotbase, godotcoretypes
type
Vector3* {.byref.} = object
x*: float32
y*: float32
z*: float32
proc vec3*(): Vector3 {.inline.} = proc vec3*(): Vector3 {.inline.} =
Vector3() Vector3()

1378
godot/gdnativeapi.nim Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,7 @@
# Copyright 2017 Xored Software, Inc. # Copyright 2017 Xored Software, Inc.
import core.godotbase, godotinternal import core.godotbase, godotinternal
import core.godotcoretypes
import core.vector2, core.rect2, core.vector3, core.transform2d, core.planes, import core.vector2, core.rect2, core.vector3, core.transform2d, core.planes,
core.quats core.quats
import core.rect3, core.basis, core.transforms, core.colors, core.nodepaths, import core.rect3, core.basis, core.transforms, core.colors, core.nodepaths,
@ -9,9 +10,9 @@ import core.dictionaries, core.arrays, core.poolarrays, core.variants
import nim.godotmacros, nim.godotnim import nim.godotmacros, nim.godotnim
export godotbase, vector2, rect2, vector3, transform2d, planes, quats, export godotbase, godotcoretypes, vector2, rect2, vector3, transform2d, planes,
rect3, basis, transforms, colors, nodepaths, rids, dictionaries, arrays, quats, rect3, basis, transforms, colors, nodepaths, rids, dictionaries,
poolarrays, variants arrays, poolarrays, variants
export godotmacros, godotnim export godotmacros, godotnim
export GodotPropertyHint, GodotPropertyUsage export GodotPropertyHint, GodotPropertyUsage

View file

@ -1,259 +1,87 @@
# Copyright 2017 Xored Software, Inc. # Copyright 2017 Xored Software, Inc.
import internal.godotobjects, internal.godotarrays, internal.godotnodepaths, import internal.godotinternaltypes, internal.godotarrays,
internal.godotpoolarrays, internal.godotstrings, internal.godotvariants, internal.godotnodepaths, internal.godotpoolarrays, internal.godotstrings,
internal.godotdictionaries internal.godotvariants, internal.godotdictionaries
export godotobjects, godotarrays, godotnodepaths, godotpoolarrays, import gdnativeapi
export godotinternaltypes, godotarrays, godotnodepaths, godotpoolarrays,
godotstrings, godotvariants, godotdictionaries godotstrings, godotvariants, godotdictionaries
const MAX_ARG_COUNT* = 128 proc getMethod*(className: cstring;
methodName: cstring): ptr GodotMethodBind {.inline.} =
getGDNativeAPI().methodBindGetMethod(className, methodName)
# MethodBind API
type GodotMethodBind* = object
proc getMethod*(className: cstring; methodName: cstring): ptr GodotMethodBind {.
importc: "godot_method_bind_get_method".}
proc ptrCall*(methodBind: ptr GodotMethodBind; proc ptrCall*(methodBind: ptr GodotMethodBind;
instance: ptr GodotObject; instance: ptr GodotObject;
args: ptr array[MAX_ARG_COUNT, pointer]; args: ptr array[MAX_ARG_COUNT, pointer];
ret: pointer) {. ret: pointer) {.inline.} =
importc: "godot_method_bind_ptrcall".} getGDNativeAPI().methodBindPtrCall(methodBind, instance, args, ret)
proc call*(methodBind: ptr GodotMethodBind; proc call*(methodBind: ptr GodotMethodBind;
instance: ptr GodotObject; instance: ptr GodotObject;
args: ptr array[MAX_ARG_COUNT, ptr GodotVariant]; argCount: cint; args: ptr array[MAX_ARG_COUNT, ptr GodotVariant]; argCount: cint;
callError: var VariantCallError): GodotVariant {. callError: var VariantCallError): GodotVariant {.inline.} =
importc: "godot_method_bind_call".} getGDNativeAPI().methodBindCall(
methodBind, instance, args, argCount, callError)
# Script API proc nativeScriptRegisterClass*(libHandle: pointer; name, base: cstring;
type
GodotNativeInitOptions* = object
inEditor*: bool
coreApiHash*: uint64
editorApiHash*: uint64
noApiHash*: uint64
gdNativeLibrary*: ptr GodotObject
GodotNativeTerminateOptions* = object
inEditor*: bool
GodotMethodRPCMode* {.size: sizeof(cint), pure.} = enum
Disabled,
Remote,
Sync,
Master,
Slave
GodotMethodAttributes* = object
rpcMode*: GodotMethodRPCMode
GodotPropertyHint* {.size: sizeof(cint), pure.} = enum
None, ## no hint provided.
Range, ## hint_text = "min,max,step,slider; // slider is optional"
ExpRange, ## hint_text = "min,max,step", exponential edit
Enum, ## hint_text= "val1,val2,val3,etc"
ExpEasing, ## exponential easing funciton (Math::ease)
Length, ## hint_text= "length" (as integer)
SpriteFrame,
KeyAccel, ## hint_text= "length" (as integer)
Flags, ## hint_text= "flag1,flag2,etc" (as bit flags)
Layers2DRender,
Layers2DPhysics,
Layers3DRender,
Layers3DPhysics,
File, ## a file path must be passed, hint_text (optionally)
## is a filter "*.png,*.wav,*.doc,"
Dir, ## a directort path must be passed
GlobalFile, ## a file path must be passed, hint_text (optionally) is a
## filter "*.png,*.wav,*.doc,"
GlobalDir, ## a directort path must be passed
ResourceType, ## a resource object type
MultilineText, ## used for string properties that can contain multiple lines
ColorNoAlpha, ## used for ignoring alpha component when editing a color
ImageCompressLossy,
ImageCompressLossless,
ObjectId,
TypeString, ## a type string, the hint is the base type to choose
NodePathToEditedNode, ## so something else can provide this
## (used in scripts)
MethodOfVariantType, ## a method of a type
MethodOfBaseType, ## a method of a base type
MethodOfInstance, ## a method of an instance
MethodOfScript, ## a method of a script & base
PropertyOfVariantType, ## a property of a type
PropertyOfBaseType, ## a property of a base type
PropertyOfInstance, ## a property of an instance
PropertyOfScript, ## a property of a script & base
PropertyHintMax
const
GODOT_PROPERTY_USAGE_STORAGE_VALUE = 1.cint
GODOT_PROPERTY_USAGE_EDITOR_VALUE = 2.cint
GODOT_PROPERTY_USAGE_NETWORK_VALUE = 4.cint
GODOT_PROPERTY_USAGE_EDITOR_HELPER_VALUE = 8.cint
GODOT_PROPERTY_USAGE_CHECKABLE_VALUE = 16.cint
GODOT_PROPERTY_USAGE_CHECKED_VALUE = 32.cint
GODOT_PROPERTY_USAGE_INTERNATIONALIZED_VALUE = 64.cint
GODOT_PROPERTY_USAGE_GROUP_VALUE = 128.cint
GODOT_PROPERTY_USAGE_CATEGORY_VALUE = 256.cint
GODOT_PROPERTY_USAGE_STORE_IF_NONZERO_VALUE = 512.cint
GODOT_PROPERTY_USAGE_STORE_IF_NONONE_VALUE = 1024.cint
GODOT_PROPERTY_USAGE_NO_INSTANCE_STATE_VALUE = 2048.cint
GODOT_PROPERTY_USAGE_RESTART_IF_CHANGED_VALUE = 4096.cint
GODOT_PROPERTY_USAGE_SCRIPT_VARIABLE_VALUE = 8192.cint
GODOT_PROPERTY_USAGE_STORE_IF_NULL_VALUE = 16384.cint
GODOT_PROPERTY_USAGE_ANIMATE_AS_TRIGGER_VALUE = 32768.cint
GODOT_PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED_VALUE = 65536.cint
GODOT_PROPERTY_USAGE_DEFAULT_VALUE: cint =
GODOT_PROPERTY_USAGE_STORAGE_VALUE or GODOT_PROPERTY_USAGE_EDITOR_VALUE or
GODOT_PROPERTY_USAGE_NETWORK_VALUE
GODOT_PROPERTY_USAGE_DEFAULT_INTL_VALUE: cint =
GODOT_PROPERTY_USAGE_STORAGE_VALUE or
GODOT_PROPERTY_USAGE_EDITOR_VALUE or GODOT_PROPERTY_USAGE_NETWORK_VALUE or
GODOT_PROPERTY_USAGE_INTERNATIONALIZED_VALUE
GODOT_PROPERTY_USAGE_NOEDITOR_VALUE: cint =
GODOT_PROPERTY_USAGE_STORAGE_VALUE or GODOT_PROPERTY_USAGE_NETWORK_VALUE
type
GodotPropertyUsage* {.size: sizeof(cint), pure.} = enum
Storage = GODOT_PROPERTY_USAGE_STORAGE_VALUE
Editor = GODOT_PROPERTY_USAGE_EDITOR_VALUE
Network = GODOT_PROPERTY_USAGE_NETWORK_VALUE
NoEditor = GODOT_PROPERTY_USAGE_NOEDITOR_VALUE
Default = GODOT_PROPERTY_USAGE_DEFAULT_VALUE
EditorHelper = GODOT_PROPERTY_USAGE_EDITOR_HELPER_VALUE
Checkable = GODOT_PROPERTY_USAGE_CHECKABLE_VALUE
## used for editing global variables
Checked = GODOT_PROPERTY_USAGE_CHECKED_VALUE
## used for editing global variables
Internationalized = GODOT_PROPERTY_USAGE_INTERNATIONALIZED_VALUE
## hint for internationalized strings
DefaultIntl = GODOT_PROPERTY_USAGE_DEFAULT_INTL_VALUE
Group = GODOT_PROPERTY_USAGE_GROUP_VALUE
## used for grouping props in the editor
Category = GODOT_PROPERTY_USAGE_CATEGORY_VALUE
NonZero = GODOT_PROPERTY_USAGE_STORE_IF_NONZERO_VALUE
## only store if nonzero
NonOne = GODOT_PROPERTY_USAGE_STORE_IF_NONONE_VALUE
## only store if false
NoInstanceState = GODOT_PROPERTY_USAGE_NO_INSTANCE_STATE_VALUE
RestartIfChanged = GODOT_PROPERTY_USAGE_RESTART_IF_CHANGED_VALUE
ScriptVariable = GODOT_PROPERTY_USAGE_SCRIPT_VARIABLE_VALUE
StoreIfNull = GODOT_PROPERTY_USAGE_STORE_IF_NULL_VALUE
AnimateAsTrigger = GODOT_PROPERTY_USAGE_ANIMATE_AS_TRIGGER_VALUE
UpdateAllIfModified = GODOT_PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED_VALUE
GodotPropertyAttributes* {.bycopy.} = object
rsetType*: GodotMethodRPCMode
typ*: cint
hint*: GodotPropertyHint
hintString*: GodotString
usage*: cint
defaultValue*: GodotVariant
GodotInstanceCreateFunc* {.bycopy.} = object
createFunc*:
proc (obj: ptr GodotObject; methodData: pointer): pointer {.noconv.}
## returns user data
methodData*: pointer
freeFunc*: proc (a2: pointer) {.noconv.}
GodotInstanceDestroyFunc* {.bycopy.} = object
destroyFunc*:
proc (obj: ptr GodotObject; methodData: pointer;
userData: pointer) {.noconv.}
methodData*: pointer
freeFunc*: proc (a2: pointer) {.noconv.}
proc godotScriptRegisterClass*(libHandle: pointer; name, base: cstring;
create_func: GodotInstanceCreateFunc;
destroy_func: GodotInstanceDestroyFunc) {.
importc: "godot_nativescript_register_class".}
proc godotScriptRegisterToolClass*(libHandle: pointer; name, base: cstring;
createFunc: GodotInstanceCreateFunc; createFunc: GodotInstanceCreateFunc;
destroyFunc: GodotInstanceDestroyFunc) {. destroyFunc: GodotInstanceDestroyFunc)
importc: "godot_nativescript_register_tool_class".} {.inline.} =
type let api = getGDNativeAPI()
GodotInstanceMethod* {.bycopy.} = object api.nativeScriptRegisterClass(
meth*: libHandle, name, base, createFunc, destroyFunc)
proc (obj: ptr GodotObject; methodData: pointer;
userData: pointer; numArgs: cint;
args: var array[MAX_ARG_COUNT, ptr GodotVariant]):
GodotVariant {.noconv.}
methodData*: pointer
freeFunc*: proc (a2: pointer) {.noconv.}
proc godotScriptRegisterMethod*(libHandle: pointer; proc nativeScriptRegisterToolClass*(libHandle: pointer; name, base: cstring;
createFunc: GodotInstanceCreateFunc;
destroyFunc: GodotInstanceDestroyFunc)
{.inline.} =
getGDNativeAPI().nativeScriptRegisterToolClass(
libHandle, name, base, createFunc, destroyFunc)
proc nativeScriptRegisterMethod*(libHandle: pointer;
name: cstring; function_name: cstring; name: cstring; function_name: cstring;
attr: GodotMethodAttributes; attr: GodotMethodAttributes;
meth: GodotInstanceMethod) {. meth: GodotInstanceMethod) {.inline.} =
importc: "godot_nativescript_register_method".} getGDNativeAPI().nativeScriptRegisterMethod(
type libHandle, name, functionName, attr, meth)
GodotPropertySetFunc* {.bycopy.} = object
setFunc*: proc (obj: ptr GodotObject; methodData: pointer;
userData: pointer; value: GodotVariant) {.noconv.}
methodData*: pointer
freeFunc*: proc (a2: pointer) {.noconv.}
GodotPropertyGetFunc* {.bycopy.} = object proc nativeScriptRegisterProperty*(libHandle: pointer;
getFunc*: proc (obj: ptr GodotObject; methodData: pointer; name, path: cstring;
userData: pointer): GodotVariant {.noconv.}
methodData*: pointer
freeFunc*: proc (a2: pointer) {.noconv.}
proc godotScriptRegisterProperty*(libHandle: pointer;
name: cstring; path: cstring;
attr: ptr GodotPropertyAttributes; attr: ptr GodotPropertyAttributes;
setFunc: GodotPropertySetFunc; setFunc: GodotPropertySetFunc;
getFunc: GodotPropertyGetFunc) {. getFunc: GodotPropertyGetFunc) {.inline.} =
importc: "godot_nativescript_register_property".} getGDNativeAPI().nativeScriptRegisterProperty(
libHandle, name, path, attr, setFunc, getFunc)
type proc nativeScriptRegisterSignal*(libHandle: pointer; name: cstring;
GodotSignalArgument* {.bycopy.} = object signal: GodotSignal) {.inline.} =
name*: GodotString getGDNativeAPI().nativeScriptRegisterSignal(libHandle, name, signal)
typ*: cint
hint*: GodotPropertyHint
hintString*: GodotString
usage*: cint
defaultValue*: GodotVariant
GodotSignal* = object proc getUserdata*(instance: ptr GodotObject): pointer {.inline.} =
name*: GodotString getGDNativeAPI().nativeScriptGetUserdata(instance)
numArgs*: cint
args*: ptr GodotSignalArgument
numDefaultArgs*: cint
defaultArgs*: ptr GodotVariant
proc getClassConstructor*(className: cstring): GodotClassConstructor
{.inline.} =
getGDNativeAPI().getClassConstructor(className)
proc godotScriptRegisterSignal*(libHandle: pointer; name: cstring; proc deinit*(o: ptr GodotObject) {.inline.} =
signal: GodotSignal) {. getGDNativeAPI().objectDestroy(o)
importc: "godot_nativescript_register_signal".}
proc getUserdata*(instance: ptr GodotObject): pointer {.
importc: "godot_nativescript_get_userdata".}
type ClassConstructor = proc (): ptr GodotObject {.noconv.}
proc getClassConstructor*(className: cstring): ClassConstructor {.
importc: "godot_get_class_constructor".}
proc deinit*(o: ptr GodotObject) {.
importc: "godot_object_destroy".}
# print using Godot's error handler list # print using Godot's error handler list
proc godotPrintError*(description: cstring; function: cstring; file: cstring; proc godotPrintError*(description, function, file: cstring;
line: cint) {. line: cint) {.inline.} =
importc: "godot_print_error".} let api = getGDNativeAPI()
api.printError(description, function, file, line)
proc godotPrintWarning*(description: cstring; function: cstring; proc godotPrintWarning*(description, function, file: cstring;
file: cstring; line: cint) {. line: cint) {.inline.} =
importc: "godot_print_warning".} getGDNativeAPI().printWarning(description, function, file, line)
proc godotPrint*(message: GodotString) {. proc godotPrint*(message: GodotString) {.inline.} =
importc: "godot_print".} getGDNativeAPI().print(message)
var getClassMethodBind: ptr GodotMethodBind var getClassMethodBind: ptr GodotMethodBind
proc getClassName*(o: ptr GodotObject): string = proc getClassName*(o: ptr GodotObject): string =
@ -267,22 +95,25 @@ proc getClassName*(o: ptr GodotObject): string =
# There are physics type not known by ClassDB # There are physics type not known by ClassDB
result = result[0..result.len-3] result = result[0..result.len-3]
proc getGodotSingleton*(name: cstring): ptr GodotObject {. proc getGodotSingleton*(name: cstring): ptr GodotObject {.inline.} =
importc: "godot_global_get_singleton".} getGDNativeAPI().globalGetSingleton(name)
# System Functions # System Functions
proc godotAlloc*(bytes: cint): pointer {. proc godotAlloc*(bytes: cint): pointer {.inline.} =
importc: "godot_alloc".}
## Allocates the specified number of bytes. ## Allocates the specified number of bytes.
## Using this instead of stdlib proc will help Godot track how much memory ## Using this instead of stdlib proc will help Godot track how much memory
## is in use in debug mode. ## is in use in debug mode.
proc godotRealloc*(p: pointer; bytes: cint): pointer {. getGDNativeAPI().alloc(bytes)
importc: "godot_realloc".}
proc godotRealloc*(p: pointer; bytes: cint): pointer {.inline.} =
## Reallocates the pointer for the specified number of bytes. ## Reallocates the pointer for the specified number of bytes.
## Using this instead of stdlib proc will help Godot track how much memory ## Using this instead of stdlib proc will help Godot track how much memory
## is in use in debug mode. ## is in use in debug mode.
proc godotFree*(p: pointer) {.importc: "godot_free".} getGDNativeAPI().realloc(p, bytes)
proc godotFree*(p: pointer) {.inline.} =
## Frees the memory pointed to by the pointer. ## Frees the memory pointed to by the pointer.
## Using this instead of stdlib proc will help Godot track how much memory ## Using this instead of stdlib proc will help Godot track how much memory
## is in use in debug mode. ## is in use in debug mode.
getGDNativeAPI().free(p)

View file

@ -1,107 +1,130 @@
# Copyright (c) 2017 Xored Software, Inc. # Copyright (c) 2017 Xored Software, Inc.
type import godotinternaltypes, gdnativeapi, core.godotcoretypes
GodotArray* {.byref.} = object
data: array[sizeof(int), byte]
proc len*(self: GodotArray): cint {. proc len*(self: GodotArray): cint {.inline.} =
noSideEffect, getGDNativeAPI().arraySize(self)
importc: "godot_array_size".}
import hashes import hashes
import godotobjects, godotpoolarrays, godotvariants, godotstrings
proc initGodotArray*(dest: var GodotArray) {. proc initGodotArray*(dest: var GodotArray) {.inline.} =
importc: "godot_array_new".} getGDNativeAPI().arrayNew(dest)
proc initGodotArray*(dest: var GodotArray; pca: GodotPoolColorArray) {.
importc: "godot_array_new_pool_coloarray".}
proc initGodotArray*(dest: var GodotArray; pv3a: GodotPoolVector3Array) {.
importc: "godot_array_new_pool_vector3_array".}
proc initGodotArray*(dest: var GodotArray; pv2a: GodotPoolVector2Array) {.
importc: "godot_array_new_pool_vector2_array".}
proc initGodotArray*(dest: var GodotArray; psa: GodotPoolStringArray) {.
importc: "godot_array_new_pool_string_array".}
proc initGodotArray*(dest: var GodotArray; pra: GodotPoolRealArray) {.
importc: "godot_array_new_pool_real_array".}
proc initGodotArray*(dest: var GodotArray; pia: GodotPoolIntArray) {.
importc: "godot_array_new_pool_int_array".}
proc initGodotArray*(dest: var GodotArray; pba: GodotPoolByteArray) {.
importc: "godot_array_new_pool_byte_array".}
proc iniGodotArray*(dest: var GodotArray; src: GodotArray) {.
importc: "godot_array_new_copy".}
proc deinit*(self: var GodotArray) {.importc: "godot_array_destroy".} proc initGodotArray*(dest: var GodotArray;
pca: GodotPoolColorArray) {.inline.} =
getGDNativeAPI().arrayNewPoolColorArray(dest, pca)
proc `[]=`*(self: var GodotArray; idx: cint; proc initGodotArray*(dest: var GodotArray;
value: GodotVariant) {. pv3a: GodotPoolVector3Array) {.inline.} =
noSideEffect, getGDNativeAPI().arrayNewPoolVector3Array(dest, pv3a)
importc: "godot_array_set".}
proc `[]`*(self: GodotArray; idx: cint): GodotVariant {. proc initGodotArray*(dest: var GodotArray;
noSideEffect, pv2a: GodotPoolVector2Array) {.inline.} =
importc: "godot_array_get".} getGDNativeAPI().arrayNewPoolVector2Array(dest, pv2a)
proc mget*(self: var GodotArray; idx: cint): ptr GodotVariant {.
importc: "godot_array_operator_index".} proc initGodotArray*(dest: var GodotArray;
psa: GodotPoolStringArray) {.inline.} =
getGDNativeAPI().arrayNewPoolStringArray(dest, psa)
proc initGodotArray*(dest: var GodotArray;
pra: GodotPoolRealArray) {.inline.} =
getGDNativeAPI().arrayNewPoolRealArray(dest, pra)
proc initGodotArray*(dest: var GodotArray;
pia: GodotPoolIntArray) {.inline.} =
getGDNativeAPI().arrayNewPoolIntArray(dest, pia)
proc initGodotArray*(dest: var GodotArray;
pba: GodotPoolByteArray) {.inline.} =
getGDNativeAPI().arrayNewPoolByteArray(dest, pba)
proc initGodotArray*(dest: var GodotArray; src: GodotArray) {.inline.} =
getGDNativeAPI().arrayNewCopy(dest, src)
proc deinit*(self: var GodotArray) {.inline.} =
getGDNativeAPI().arrayDestroy(self)
proc `[]=`*(self: var GodotArray; idx: cint; value: GodotVariant) {.inline.} =
getGDNativeAPI().arraySet(self, idx, value)
proc `[]`*(self: GodotArray; idx: cint): GodotVariant {.inline.} =
getGDNativeAPI().arrayGet(self, idx)
proc mget*(self: var GodotArray; idx: cint): ptr GodotVariant {.inline.} =
getGDNativeAPI().arrayOperatorIndex(self, idx)
proc add*(self: var GodotArray; value: GodotVariant) {.inline.} =
getGDNativeAPI().arrayPushBack(self, value)
proc clear*(self: var GodotArray) {.inline.} =
getGDNativeAPI().arrayClear(self)
proc count*(self: GodotArray; value: GodotVariant): cint {.inline.} =
getGDNativeAPI().arrayCount(self, value)
proc isEmpty*(self: GodotArray): bool {.inline.} =
getGDNativeAPI().arrayEmpty(self)
proc erase*(self: var GodotArray; value: GodotVariant) {.inline.} =
getGDNativeAPI().arrayErase(self, value)
proc first*(self: GodotArray): GodotVariant {.inline.} =
getGDNativeAPI().arrayFront(self)
proc last*(self: GodotArray): GodotVariant {.inline.} =
getGDNativeAPI().arrayBack(self)
proc add*(self: var GodotArray; value: GodotVariant) {.
noSideEffect,
importc: "godot_array_append".}
proc clear*(self: var GodotArray) {.importc: "godot_array_clear".}
proc count*(self: GodotArray; value: GodotVariant): cint {.
noSideEffect,
importc: "godot_array_count".}
proc isEmpty*(self: GodotArray): bool {.
noSideEffect,
importc: "godot_array_empty".}
proc erase*(self: var GodotArray; value: GodotVariant) {.
importc: "godot_array_erase".}
proc first*(self: GodotArray): GodotVariant {.
noSideEffect,
importc: "godot_array_front".}
proc last*(self: GodotArray): GodotVariant {.
noSideEffect,
importc: "godot_array_back".}
proc find*(self: GodotArray; what: GodotVariant; proc find*(self: GodotArray; what: GodotVariant;
f: cint): cint {. fromIdx: cint): cint {.inline.} =
noSideEffect, getGDNativeAPI().arrayFind(self, what, fromIdx)
importc: "godot_array_find".}
proc findLast*(self: GodotArray; what: GodotVariant): cint {. proc findLast*(self: GodotArray; what: GodotVariant): cint {.inline.} =
noSideEffect, getGDNativeAPI().arrayFindLast(self, what)
importc: "godot_array_find_last".}
proc contains*(self: GodotArray; value: GodotVariant): bool {. proc contains*(self: GodotArray; value: GodotVariant): bool {.inline.} =
noSideEffect, getGDNativeAPI().arrayHas(self, value)
importc: "godot_array_has".}
proc godotHash*(self: GodotArray): cint {.inline.} =
getGDNativeAPI().arrayHash(self)
proc godotHash*(self: GodotArray): cint {.
noSideEffect,
importc: "godot_array_hash".}
proc hash*(self: GodotArray): Hash {.inline.} = proc hash*(self: GodotArray): Hash {.inline.} =
hash(godotHash(self)) hash(godotHash(self))
proc insert*(self: var GodotArray; pos: cint; proc insert*(self: var GodotArray; pos: cint;
value: GodotVariant) {. value: GodotVariant): Error {.discardable, inline.} =
importc: "godot_array_insert".} getGDNativeAPI().arrayInsert(self, pos, value)
proc reverse*(self: var GodotArray) {.importc: "godot_array_invert".}
proc popLast*(self: var GodotArray): GodotVariant {. proc reverse*(self: var GodotArray) {.inline.} =
importc: "godot_array_pop_back".} getGDNativeAPI().arrayInvert(self)
proc popFirst*(self: var GodotArray): GodotVariant {.
importc: "godot_array_pop_front".} proc popLast*(self: var GodotArray): GodotVariant {.inline.} =
proc addLast*(self: var GodotArray; value: GodotVariant) {. getGDNativeAPI().arrayPopBack(self)
importc: "godot_array_push_back".}
proc addFirst*(self: var GodotArray; value: GodotVariant) {. proc popFirst*(self: var GodotArray): GodotVariant {.inline.} =
importc: "godot_array_push_front".} getGDNativeAPI().arrayPopFront(self)
proc addLast*(self: var GodotArray; value: GodotVariant) {.inline.} =
getGDNativeAPI().arrayPushBack(self, value)
proc addFirst*(self: var GodotArray; value: GodotVariant) {.inline.} =
getGDNativeAPI().arrayPushFront(self, value)
proc delete*(self: var GodotArray; idx: cint) {.inline.} =
getGDNativeAPI().arrayRemove(self, idx)
proc setLen*(self: var GodotArray; size: cint) {.inline.} =
getGDNativeAPI().arrayResize(self, size)
proc delete*(self: var GodotArray; idx: cint) {.
importc: "godot_array_remove".}
proc setLen*(self: var GodotArray; size: cint) {.
importc: "godot_array_resize".}
proc rfind*(self: GodotArray; what: GodotVariant; proc rfind*(self: GodotArray; what: GodotVariant;
f: cint): cint {. fromIdx: cint): cint {.inline.} =
noSideEffect, getGDNativeAPI().arrayRFind(self, what, fromIdx)
importc: "godot_array_rfind".}
proc sort*(self: var GodotArray) {.importc: "godot_array_sort".} proc sort*(self: var GodotArray) {.inline.} =
proc sortCustom*(self: var GodotArray; obj: var GodotObject; getGDNativeAPI().arraySort(self)
funcName: GodotString) {.
importc: "godot_array_sort_custom".} proc sortCustom*(self: var GodotArray; obj: ptr GodotObject;
funcName: GodotString) {.inline.} =
getGDNativeAPI().arraySortCustom(self, obj, funcName)
iterator items*(self: GodotArray): GodotVariant = iterator items*(self: GodotArray): GodotVariant =
for i in 0..<self.len: for i in 0..<self.len:

View file

@ -1,48 +1,56 @@
# Copyright (c) 2017 Xored Software, Inc. # Copyright (c) 2017 Xored Software, Inc.
type import godotinternaltypes, gdnativeapi
GodotDictionary* {.byref.} = object
data: array[sizeof(int), byte]
import godotarrays, godotvariants, godotstrings proc initGodotDictionary*(dest: var GodotDictionary) {.inline.} =
getGDNativeAPI().dictionaryNew(dest)
proc initGodotDictionary*(dest: var GodotDictionary; src: GodotDictionary) {. proc initGodotDictionary*(dest: var GodotDictionary;
importc: "godot_dictionary_new_copy".} src: GodotDictionary) {.inline.} =
getGDNativeAPI().dictionaryNewCopy(dest, src)
proc deinit*(self: var GodotDictionary) {. proc deinit*(self: var GodotDictionary) {.inline.} =
importc: "godot_dictionary_destroy".} getGDNativeAPI().dictionaryDestroy(self)
proc initGodotDictionary*(dest: var GodotDictionary) {. proc len*(self: GodotDictionary): cint {.inline.} =
importc: "godot_dictionary_new".} getGDNativeAPI().dictionarySize(self)
proc len*(self: GodotDictionary): cint {. proc isEmpty*(self: GodotDictionary): bool {.inline.} =
importc: "godot_dictionary_size".} getGDNativeAPI().dictionaryEmpty(self)
proc isEmpty*(self: GodotDictionary): bool {.
importc: "godot_dictionary_empty".}
proc clear*(self: var GodotDictionary) {.
importc: "godot_dictionary_clear".}
proc contains*(self: GodotDictionary; key: GodotVariant): bool {.
importc: "godot_dictionary_has".}
proc contains*(self: GodotDictionary; keys: GodotArray): bool {.
importc: "godot_dictionary_has_all".}
proc del*(self: var GodotDictionary; key: GodotVariant) {.
importc: "godot_dictionary_erase".}
proc godotHash*(self: GodotDictionary): cint {. proc clear*(self: var GodotDictionary) {.inline.} =
importc: "godot_dictionary_hash".} getGDNativeAPI().dictionaryClear(self)
proc keys*(self: GodotDictionary): GodotArray {.
importc: "godot_dictionary_keys".}
proc values*(self: GodotDictionary): GodotArray {.
importc: "godot_dictionary_values".}
proc `[]`*(self: GodotDictionary; key: GodotVariant): GodotVariant {.
importc: "godot_dictionary_get".}
proc `[]=`*(self: var GodotDictionary; key, value: GodotVariant) {.
importc: "godot_dictionary_set".}
proc mget*(self: var GodotDictionary; key: GodotVariant): ptr GodotVariant {.
importc: "godot_dictionary_operator_index".}
proc `==`*(self, other: GodotDictionary): bool {. proc contains*(self: GodotDictionary; key: GodotVariant): bool {.inline.} =
importc: "godot_dictionary_operator_equal".} getGDNativeAPI().dictionaryHas(self, key)
proc toJson*(self: GodotDictionary): GodotString {. proc contains*(self: GodotDictionary; keys: GodotArray): bool {.inline.} =
importc: "godot_dictionary_to_json".} getGDNativeAPI().dictionaryHasAll(self, keys)
proc del*(self: var GodotDictionary; key: GodotVariant) {.inline.} =
getGDNativeAPI().dictionaryErase(self, key)
proc godotHash*(self: GodotDictionary): cint {.inline.} =
getGDNativeAPI().dictionaryHash(self, )
proc keys*(self: GodotDictionary): GodotArray {.inline.} =
getGDNativeAPI().dictionaryKeys(self)
proc values*(self: GodotDictionary): GodotArray {.inline.} =
getGDNativeAPI().dictionaryValues(self)
proc `[]`*(self: GodotDictionary; key: GodotVariant): GodotVariant {.inline.} =
getGDNativeAPI().dictionaryGet(self, key)
proc `[]=`*(self: var GodotDictionary; key, value: GodotVariant) {.inline.} =
getGDNativeAPI().dictionarySet(self, key, value)
proc mget*(self: var GodotDictionary;
key: GodotVariant): ptr GodotVariant {.inline.} =
getGDNativeAPI().dictionaryOperatorIndex(self, key)
proc `==`*(self, other: GodotDictionary): bool {.inline.} =
getGDNativeAPI().dictionaryOperatorEqual(self, other)
proc toJson*(self: GodotDictionary): GodotString {.inline.} =
getGDNativeAPI().dictionaryToJson(self)

View file

@ -0,0 +1,262 @@
# Copyright 2017 Xored Software, Inc.
const MAX_ARG_COUNT* = 256
type
GodotArray* {.byref.} = object
data: array[sizeof(int), byte]
GodotDictionary* {.byref.} = object
data: array[sizeof(int), byte]
GodotNodePath* {.byref.} = object
data: array[sizeof(int), byte]
GodotObject* = object
GodotPoolByteArray* {.byref.} = object
data: array[sizeof(int), byte]
GodotPoolIntArray* {.byref.} = object
data: array[sizeof(int), byte]
GodotPoolRealArray* {.byref.} = object
data: array[sizeof(int), byte]
GodotPoolStringArray* {.byref.} = object
data: array[sizeof(int), byte]
GodotPoolVector2Array* {.byref.} = object
data: array[sizeof(int), byte]
GodotPoolVector3Array* {.byref.} = object
data: array[sizeof(int), byte]
GodotPoolColorArray* {.byref.} = object
data: array[sizeof(int), byte]
GodotString* {.byref.} = object
data: array[sizeof(int), byte]
VariantType* {.size: sizeof(cint), pure.} = enum
Nil, ## atomic types
Bool,
Int,
Real,
String,
# math types
Vector2, ## 5
Rect2,
Vector3,
Transform2D,
Plane,
Quat, ## 10
Rect3,
Basis,
Transform, ## misc types
Color,
NodePath, ## 15
RID,
Object,
Dictionary,
Array, ## 20
# arrays
PoolByteArray,
PoolIntArray,
PoolRealArray,
PoolStringArray,
PoolVector2Array, ## 25
PoolVector3Array,
PoolColorArray
VariantCallErrorType* {.size: sizeof(cint), pure.} = enum
OK,
InvalidMethod,
InvalidArgument,
TooManyArguments,
TooFewArguments,
InstanceIsNull
VariantCallError* = object
error*: VariantCallErrorType
argument*: cint
expected*: VariantType
GodotVariant* {.byref.} = object
data: array[4 + sizeof(int) div 4, float32]
type GodotMethodBind* = object
type
GodotNativeInitOptions* = object
inEditor*: bool
coreApiHash*: uint64
editorApiHash*: uint64
noApiHash*: uint64
gdNativeLibrary*: ptr GodotObject
gdNativeAPIStruct*: pointer
activeLibraryPath*: ptr GodotString
GodotNativeTerminateOptions* = object
inEditor*: bool
GodotMethodRPCMode* {.size: sizeof(cint), pure.} = enum
Disabled,
Remote,
Sync,
Master,
Slave
GodotMethodAttributes* = object
rpcMode*: GodotMethodRPCMode
GodotPropertyHint* {.size: sizeof(cint), pure.} = enum
None, ## no hint provided.
Range, ## hint_text = "min,max,step,slider; // slider is optional"
ExpRange, ## hint_text = "min,max,step", exponential edit
Enum, ## hint_text= "val1,val2,val3,etc"
ExpEasing, ## exponential easing funciton (Math::ease)
Length, ## hint_text= "length" (as integer)
SpriteFrame,
KeyAccel, ## hint_text= "length" (as integer)
Flags, ## hint_text= "flag1,flag2,etc" (as bit flags)
Layers2DRender,
Layers2DPhysics,
Layers3DRender,
Layers3DPhysics,
File, ## a file path must be passed, hint_text (optionally)
## is a filter "*.png,*.wav,*.doc,"
Dir, ## a directort path must be passed
GlobalFile, ## a file path must be passed, hint_text (optionally) is a
## filter "*.png,*.wav,*.doc,"
GlobalDir, ## a directort path must be passed
ResourceType, ## a resource object type
MultilineText, ## used for string properties that can contain multiple lines
ColorNoAlpha, ## used for ignoring alpha component when editing a color
ImageCompressLossy,
ImageCompressLossless,
ObjectId,
TypeString, ## a type string, the hint is the base type to choose
NodePathToEditedNode, ## so something else can provide this
## (used in scripts)
MethodOfVariantType, ## a method of a type
MethodOfBaseType, ## a method of a base type
MethodOfInstance, ## a method of an instance
MethodOfScript, ## a method of a script & base
PropertyOfVariantType, ## a property of a type
PropertyOfBaseType, ## a property of a base type
PropertyOfInstance, ## a property of an instance
PropertyOfScript, ## a property of a script & base
PropertyHintMax
const
GODOT_PROPERTY_USAGE_STORAGE_VALUE = 1.cint
GODOT_PROPERTY_USAGE_EDITOR_VALUE = 2.cint
GODOT_PROPERTY_USAGE_NETWORK_VALUE = 4.cint
GODOT_PROPERTY_USAGE_EDITOR_HELPER_VALUE = 8.cint
GODOT_PROPERTY_USAGE_CHECKABLE_VALUE = 16.cint
GODOT_PROPERTY_USAGE_CHECKED_VALUE = 32.cint
GODOT_PROPERTY_USAGE_INTERNATIONALIZED_VALUE = 64.cint
GODOT_PROPERTY_USAGE_GROUP_VALUE = 128.cint
GODOT_PROPERTY_USAGE_CATEGORY_VALUE = 256.cint
GODOT_PROPERTY_USAGE_STORE_IF_NONZERO_VALUE = 512.cint
GODOT_PROPERTY_USAGE_STORE_IF_NONONE_VALUE = 1024.cint
GODOT_PROPERTY_USAGE_NO_INSTANCE_STATE_VALUE = 2048.cint
GODOT_PROPERTY_USAGE_RESTART_IF_CHANGED_VALUE = 4096.cint
GODOT_PROPERTY_USAGE_SCRIPT_VARIABLE_VALUE = 8192.cint
GODOT_PROPERTY_USAGE_STORE_IF_NULL_VALUE = 16384.cint
GODOT_PROPERTY_USAGE_ANIMATE_AS_TRIGGER_VALUE = 32768.cint
GODOT_PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED_VALUE = 65536.cint
GODOT_PROPERTY_USAGE_DEFAULT_VALUE: cint =
GODOT_PROPERTY_USAGE_STORAGE_VALUE or GODOT_PROPERTY_USAGE_EDITOR_VALUE or
GODOT_PROPERTY_USAGE_NETWORK_VALUE
GODOT_PROPERTY_USAGE_DEFAULT_INTL_VALUE: cint =
GODOT_PROPERTY_USAGE_STORAGE_VALUE or
GODOT_PROPERTY_USAGE_EDITOR_VALUE or GODOT_PROPERTY_USAGE_NETWORK_VALUE or
GODOT_PROPERTY_USAGE_INTERNATIONALIZED_VALUE
GODOT_PROPERTY_USAGE_NOEDITOR_VALUE: cint =
GODOT_PROPERTY_USAGE_STORAGE_VALUE or GODOT_PROPERTY_USAGE_NETWORK_VALUE
type
GodotPropertyUsage* {.size: sizeof(cint), pure.} = enum
Storage = GODOT_PROPERTY_USAGE_STORAGE_VALUE
Editor = GODOT_PROPERTY_USAGE_EDITOR_VALUE
Network = GODOT_PROPERTY_USAGE_NETWORK_VALUE
NoEditor = GODOT_PROPERTY_USAGE_NOEDITOR_VALUE
Default = GODOT_PROPERTY_USAGE_DEFAULT_VALUE
EditorHelper = GODOT_PROPERTY_USAGE_EDITOR_HELPER_VALUE
Checkable = GODOT_PROPERTY_USAGE_CHECKABLE_VALUE
## used for editing global variables
Checked = GODOT_PROPERTY_USAGE_CHECKED_VALUE
## used for editing global variables
Internationalized = GODOT_PROPERTY_USAGE_INTERNATIONALIZED_VALUE
## hint for internationalized strings
DefaultIntl = GODOT_PROPERTY_USAGE_DEFAULT_INTL_VALUE
Group = GODOT_PROPERTY_USAGE_GROUP_VALUE
## used for grouping props in the editor
Category = GODOT_PROPERTY_USAGE_CATEGORY_VALUE
NonZero = GODOT_PROPERTY_USAGE_STORE_IF_NONZERO_VALUE
## only store if nonzero
NonOne = GODOT_PROPERTY_USAGE_STORE_IF_NONONE_VALUE
## only store if false
NoInstanceState = GODOT_PROPERTY_USAGE_NO_INSTANCE_STATE_VALUE
RestartIfChanged = GODOT_PROPERTY_USAGE_RESTART_IF_CHANGED_VALUE
ScriptVariable = GODOT_PROPERTY_USAGE_SCRIPT_VARIABLE_VALUE
StoreIfNull = GODOT_PROPERTY_USAGE_STORE_IF_NULL_VALUE
AnimateAsTrigger = GODOT_PROPERTY_USAGE_ANIMATE_AS_TRIGGER_VALUE
UpdateAllIfModified = GODOT_PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED_VALUE
GodotPropertyAttributes* {.bycopy.} = object
rsetType*: GodotMethodRPCMode
typ*: cint
hint*: GodotPropertyHint
hintString*: GodotString
usage*: cint
defaultValue*: GodotVariant
GodotInstanceCreateFunc* {.bycopy.} = object
createFunc*:
proc (obj: ptr GodotObject; methodData: pointer): pointer {.noconv.}
## returns user data
methodData*: pointer
freeFunc*: proc (a2: pointer) {.noconv.}
GodotInstanceDestroyFunc* {.bycopy.} = object
destroyFunc*:
proc (obj: ptr GodotObject; methodData: pointer;
userData: pointer) {.noconv.}
methodData*: pointer
freeFunc*: proc (a2: pointer) {.noconv.}
GodotInstanceMethod* {.bycopy.} = object
meth*:
proc (obj: ptr GodotObject; methodData: pointer;
userData: pointer; numArgs: cint;
args: var array[MAX_ARG_COUNT, ptr GodotVariant]):
GodotVariant {.noconv.}
methodData*: pointer
freeFunc*: proc (a2: pointer) {.noconv.}
GodotPropertySetFunc* {.bycopy.} = object
setFunc*: proc (obj: ptr GodotObject; methodData: pointer;
userData: pointer; value: GodotVariant) {.noconv.}
methodData*: pointer
freeFunc*: proc (a2: pointer) {.noconv.}
GodotPropertyGetFunc* {.bycopy.} = object
getFunc*: proc (obj: ptr GodotObject; methodData: pointer;
userData: pointer): GodotVariant {.noconv.}
methodData*: pointer
freeFunc*: proc (a2: pointer) {.noconv.}
GodotSignalArgument* {.bycopy.} = object
name*: GodotString
typ*: cint
hint*: GodotPropertyHint
hintString*: GodotString
usage*: cint
defaultValue*: GodotVariant
GodotSignal* = object
name*: GodotString
numArgs*: cint
args*: ptr GodotSignalArgument
numDefaultArgs*: cint
defaultArgs*: ptr GodotVariant
GodotClassConstructor* = proc (): ptr GodotObject {.noconv.}

View file

@ -1,32 +1,40 @@
# Copyright 2017 Xored Software, Inc. # Copyright 2017 Xored Software, Inc.
import godotstrings import godotinternaltypes, gdnativeapi
type proc initGodotNodePath*(dest: var GodotNodePath; s: GodotString) {.inline.} =
GodotNodePath* {.byref.} = object getGDNativeAPI().nodePathNew(dest, s)
data: array[sizeof(int), byte]
proc initGodotNodePath*(dest: var GodotNodePath; s: GodotString) {. proc initGodotNodePath*(dest: var GodotNodePath;
importc: "godot_node_path_new".} src: GodotNodePath) {.inline.} =
proc deinit*(self: var GodotNodePath) {. getGDNativeAPI().nodePathNewCopy(dest, src)
importc: "godot_node_path_destroy".}
proc toGodotString*(self: GodotNodePath): GodotString {.
importc: "godot_node_path_as_string".}
proc isAbsolute*(self: GodotNodePath): bool {. proc deinit*(self: var GodotNodePath) {.inline.} =
noSideEffect, importc: "godot_node_path_is_absolute".} getGDNativeAPI().nodePathDestroy(self)
proc nameCount*(self: GodotNodePath): cint {.
noSideEffect, importc: "godot_node_path_get_name_count".}
proc getName*(self: GodotNodePath; idx: cint): GodotString {.
noSideEffect, importc: "godot_node_path_get_name".}
proc subnameCount*(self: GodotNodePath): cint {.
noSideEffect, importc: "godot_node_path_get_subname_count".}
proc getSubname*(self: GodotNodePath; idx: cint): GodotString {.
noSideEffect, importc: "godot_node_path_get_subname".}
proc property*(self: GodotNodePath): GodotString {.
noSideEffect, importc: "godot_node_path_get_property".}
proc isEmpty*(self: GodotNodePath): bool {.
noSideEffect, importc: "godot_node_path_is_empty".}
proc `==`*(a, b: GodotNodePath): bool {. proc toGodotString*(self: GodotNodePath): GodotString {.inline.} =
noSideEffect, importc: "godot_node_path_operator_equal".} getGDNativeAPI().nodePathAsString(self)
proc isAbsolute*(self: GodotNodePath): bool {.inline.} =
getGDNativeAPI().nodePathIsAbsolute(self)
proc nameCount*(self: GodotNodePath): cint {.inline.} =
getGDNativeAPI().nodePathGetNameCount(self)
proc getName*(self: GodotNodePath; idx: cint): GodotString {.inline.} =
getGDNativeAPI().nodePathGetName(self, idx)
proc subnameCount*(self: GodotNodePath): cint {.inline.} =
getGDNativeAPI().nodePathGetSubnameCount(self)
proc getSubname*(self: GodotNodePath; idx: cint): GodotString {.inline.} =
getGDNativeAPI().nodePathGetSubname(self, idx)
proc property*(self: GodotNodePath): GodotString {.inline.} =
getGDNativeAPI().nodePathGetProperty(self)
proc isEmpty*(self: GodotNodePath): bool {.inline.} =
getGDNativeAPI().nodePathIsEmpty(self)
proc `==`*(a, b: GodotNodePath): bool {.inline.} =
getGDNativeAPI().nodePathOperatorEqual(a, b)

View file

@ -1,4 +0,0 @@
# Copyright 2017 Xored Software, Inc.
type
GodotObject* = object

View file

@ -1,374 +1,169 @@
# Copyright (c) 2017 Xored Software, Inc. # Copyright (c) 2017 Xored Software, Inc.
type import godotinternaltypes, gdnativeapi
GodotPoolByteArray* {.byref.} = object import core.godotcoretypes
data: array[sizeof(int), byte]
GodotPoolIntArray* {.byref.} = object
data: array[sizeof(int), byte]
GodotPoolRealArray* {.byref.} = object
data: array[sizeof(int), byte]
GodotPoolStringArray* {.byref.} = object
data: array[sizeof(int), byte]
GodotPoolVector2Array* {.byref.} = object
data: array[sizeof(int), byte]
GodotPoolVector3Array* {.byref.} = object
data: array[sizeof(int), byte]
GodotPoolColorArray* {.byref.} = object
data: array[sizeof(int), byte]
import godotstrings, godotarrays template genPoolArrayAPI(ArrayT, initIdent, DataT,
import core.godotbase, core.colors, core.vector2, core.vector3 newProc, newCopyProc, newWithArrayProc, appendProc,
appendArrayProc, insertProc, invertProc, pushBackProc,
removeProc, resizeProc, setProc, getProc, sizeProc,
destroyProc) =
proc initIdent*(dest: var ArrayT) {.inline.} =
getGDNativeAPI().newProc(dest)
# byte proc initIdent*(dest: var ArrayT; src: ArrayT) {.inline.} =
getGDNativeAPI().newCopyProc(dest, src)
proc initGodotPoolByteArray*(dest: var GodotPoolByteArray) {. proc initIdent*(dest: var ArrayT; arr: GodotArray) {.inline.} =
importc: "godot_pool_byte_array_new".} getGDNativeAPI().newWithArrayProc(dest, arr)
proc initGodotPoolByteArray*(dest: var GodotPoolByteArray;
src: GodotPoolByteArray) {.
importc: "godot_pool_byte_array_new_copy".}
proc initGodotPoolByteArray*(dest: var GodotPoolByteArray; arr: GodotArray) {.
importc: "godot_pool_byte_array_new_with_array".}
proc deinit*(self: var GodotPoolByteArray) {. proc deinit*(self: var ArrayT) {.inline.} =
importc: "godot_pool_byte_array_destroy".} getGDNativeAPI().destroyProc(self)
proc add*(self: var GodotPoolByteArray; proc add*(self: var ArrayT; data: DataT) {.inline.} =
data: uint8) {. getGDNativeAPI().pushBackProc(self, data)
importc: "godot_pool_byte_array_append".}
proc addFirst*(self: var GodotPoolByteArray, data: uint8) {.
importc: "godot_pool_byte_array_push_back".}
proc add*(self: var GodotPoolByteArray;
arr: GodotPoolByteArray) {.
importc: "godot_pool_byte_array_append_array".}
proc insert*(self: var GodotPoolByteArray; idx: cint;
data: uint8): Error {.
importc: "godot_pool_byte_array_insert".}
proc delete*(self: var GodotPoolByteArray; idx: cint) {.
importc: "godot_pool_byte_array_remove".}
proc reverse*(self: var GodotPoolByteArray) {. proc add*(self: var ArrayT; arr: ArrayT) {.inline.} =
importc: "godot_pool_byte_array_invert".} getGDNativeAPI().appendArrayProc(self, arr)
proc setLen*(self: var GodotPoolByteArray; size: cint) {.
importc: "godot_pool_byte_array_resize".}
proc `[]=`*(self: var GodotPoolByteArray; idx: cint; data: uint8) {. proc insert*(self: var ArrayT; idx: cint;
importc: "godot_pool_byte_array_set".} data: DataT): Error {.inline.} =
proc `[]`*(self: GodotPoolByteArray; idx: cint): uint8 {. getGDNativeAPI().insertProc(self, idx, data)
noSideEffect,
importc: "godot_pool_byte_array_get".}
proc len*(self: GodotPoolByteArray): cint {.
noSideEffect,
importc: "godot_pool_byte_array_size".}
iterator items*(arr: GodotPoolByteArray): byte = proc delete*(self: var ArrayT; idx: cint) {.inline.} =
getGDNativeAPI().removeProc(self, idx)
proc reverse*(self: var ArrayT) {.inline.} =
getGDNativeAPI().invertProc(self)
proc setLen*(self: var ArrayT; size: cint) {.inline.} =
getGDNativeAPI().resizeProc(self, size)
proc `[]=`*(self: var ArrayT; idx: cint; data: DataT) {.inline.} =
getGDNativeAPI().setProc(self, idx, data)
proc `[]`*(self: ArrayT; idx: cint): DataT {.inline.} =
getGDNativeAPI().getProc(self, idx)
proc len*(self: ArrayT): cint {.inline.} =
getGDNativeAPI().sizeProc(self)
iterator items*(arr: ArrayT): DataT =
for i in 0..<arr.len: for i in 0..<arr.len:
yield arr[i] yield arr[i]
iterator pairs*(arr: GodotPoolByteArray): tuple[key: cint, val: byte] = iterator pairs*(arr: ArrayT): tuple[key: cint, val: DataT] =
for i in 0..<arr.len: for i in 0..<arr.len:
yield (i, arr[i]) yield (i, arr[i])
proc initGodotPoolIntArray*(dest: var GodotPoolIntArray) {. genPoolArrayAPI(GodotPoolByteArray, initGodotPoolByteArray, byte,
importc: "godot_pool_int_array_new".} poolByteArrayNew,
proc initGodotPoolIntArray*(dest: var GodotPoolIntArray; poolByteArrayNewCopy,
src: GodotPoolIntArray) {. poolByteArrayNewWithArray,
importc: "godot_pool_int_array_new_copy".} poolByteArrayAppend,
proc initGodotPoolIntArray*(dest: var GodotPoolIntArray; poolByteArrayAppendArray,
arr: GodotArray) {. poolByteArrayInsert,
importc: "godot_pool_int_array_new_with_array".} poolByteArrayInvert,
proc deinit*(self: var GodotPoolIntArray) {. poolByteArrayPushBack,
importc: "godot_pool_int_array_destroy".} poolByteArrayRemove,
poolByteArrayResize,
poolByteArraySet,
poolByteArrayGet,
poolByteArraySize,
poolByteArrayDestroy)
proc add*(self: var GodotPoolIntArray; data: cint) {. genPoolArrayAPI(GodotPoolIntArray, initGodotPoolIntArray, cint,
importc: "godot_pool_int_array_append".} poolIntArrayNew,
proc addFirst*(self: var GodotPoolIntArray; data: cint) {. poolIntArrayNewCopy,
importc: "godot_pool_int_array_push_back".} poolIntArrayNewWithArray,
proc add*(self: var GodotPoolIntArray; arr: GodotPoolIntArray) {. poolIntArrayAppend,
importc: "godot_pool_int_array_append_array".} poolIntArrayAppendArray,
proc insert*(self: var GodotPoolIntArray; idx: cint; poolIntArrayInsert,
data: cint): Error {. poolIntArrayInvert,
importc: "godot_pool_int_array_insert".} poolIntArrayPushBack,
proc delete*(self: var GodotPoolIntArray; idx: cint) {. poolIntArrayRemove,
importc: "godot_pool_int_array_remove".} poolIntArrayResize,
proc reverse*(self: var GodotPoolIntArray) {. poolIntArraySet,
importc: "godot_pool_int_array_invert".} poolIntArrayGet,
poolIntArraySize,
poolIntArrayDestroy)
proc setLen*(self: var GodotPoolIntArray; size: cint) {. genPoolArrayAPI(GodotPoolRealArray, initGodotPoolRealArray, float32,
importc: "godot_pool_int_array_resize".} poolRealArrayNew,
proc `[]=`*(self: var GodotPoolIntArray; idx: cint; data: cint) {. poolRealArrayNewCopy,
importc: "godot_pool_int_array_set".} poolRealArrayNewWithArray,
proc `[]`*(self: GodotPoolIntArray; idx: cint): cint {. poolRealArrayAppend,
noSideEffect, poolRealArrayAppendArray,
importc: "godot_pool_int_array_get".} poolRealArrayInsert,
proc len*(self: GodotPoolIntArray): cint {. poolRealArrayInvert,
noSideEffect, poolRealArrayPushBack,
importc: "godot_pool_int_array_size".} poolRealArrayRemove,
poolRealArrayResize,
poolRealArraySet,
poolRealArrayGet,
poolRealArraySize,
poolRealArrayDestroy)
iterator items*(arr: GodotPoolIntArray): cint = genPoolArrayAPI(GodotPoolStringArray, initGodotPoolStringArray, GodotString,
for i in 0..<arr.len: poolStringArrayNew,
yield arr[i] poolStringArrayNewCopy,
poolStringArrayNewWithArray,
poolStringArrayAppend,
poolStringArrayAppendArray,
poolStringArrayInsert,
poolStringArrayInvert,
poolStringArrayPushBack,
poolStringArrayRemove,
poolStringArrayResize,
poolStringArraySet,
poolStringArrayGet,
poolStringArraySize,
poolStringArrayDestroy)
iterator pairs*(arr: GodotPoolIntArray): tuple[key: cint, val: cint] = genPoolArrayAPI(GodotPoolVector2Array, initGodotPoolVector2Array, Vector2,
for i in 0..<arr.len: poolVector2ArrayNew,
yield (i, arr[i]) poolVector2ArrayNewCopy,
poolVector2ArrayNewWithArray,
poolVector2ArrayAppend,
poolVector2ArrayAppendArray,
poolVector2ArrayInsert,
poolVector2ArrayInvert,
poolVector2ArrayPushBack,
poolVector2ArrayRemove,
poolVector2ArrayResize,
poolVector2ArraySet,
poolVector2ArrayGet,
poolVector2ArraySize,
poolVector2ArrayDestroy)
# Real genPoolArrayAPI(GodotPoolVector3Array, initGodotPoolVector3Array, Vector3,
poolVector3ArrayNew,
poolVector3ArrayNewCopy,
poolVector3ArrayNewWithArray,
poolVector3ArrayAppend,
poolVector3ArrayAppendArray,
poolVector3ArrayInsert,
poolVector3ArrayInvert,
poolVector3ArrayPushBack,
poolVector3ArrayRemove,
poolVector3ArrayResize,
poolVector3ArraySet,
poolVector3ArrayGet,
poolVector3ArraySize,
poolVector3ArrayDestroy)
proc initGodotPoolRealArray*(dest: var GodotPoolRealArray) {. genPoolArrayAPI(GodotPoolColorArray, initGodotPoolColorArray, Color,
importc: "godot_pool_real_array_new".} poolColorArrayNew,
proc initGodotPoolRealArray*(dest: var GodotPoolRealArray; poolColorArrayNewCopy,
src: GodotPoolRealArray) {. poolColorArrayNewWithArray,
importc: "godot_pool_real_array_new_copy".} poolColorArrayAppend,
proc initGodotPoolRealArray*(dest: var GodotPoolRealArray; arr: GodotArray) {. poolColorArrayAppendArray,
importc: "godot_pool_real_array_new_with_array".} poolColorArrayInsert,
poolColorArrayInvert,
proc deinit*(self: var GodotPoolRealArray) {. poolColorArrayPushBack,
importc: "godot_pool_real_array_destroy".} poolColorArrayRemove,
poolColorArrayResize,
proc add*(self: var GodotPoolRealArray; data: float32) {. poolColorArraySet,
importc: "godot_pool_real_array_append".} poolColorArrayGet,
proc addFirst*(self: var GodotPoolRealArray; data: float32) {. poolColorArraySize,
importc: "godot_pool_real_array_push_back".} poolColorArrayDestroy)
proc add*(self: var GodotPoolRealArray; arr: GodotPoolRealArray) {.
importc: "godot_pool_real_array_append_array".}
proc insert*(self: var GodotPoolRealArray;
idx: cint; data: float32): Error {.
importc: "godot_pool_real_array_insert".}
proc delete*(self: var GodotPoolRealArray; idx: cint) {.
importc: "godot_pool_real_array_remove".}
proc reverse*(self: var GodotPoolRealArray) {.
importc: "godot_pool_real_array_invert".}
proc setLen*(self: var GodotPoolRealArray; size: cint) {.
importc: "godot_pool_real_array_resize".}
proc `[]=`*(self: var GodotPoolRealArray; idx: cint; data: float32) {.
importc: "godot_pool_real_array_set".}
proc `[]`*(self: GodotPoolRealArray; idx: cint): float32 {.
noSideEffect,
importc: "godot_pool_real_array_get".}
proc len*(self: GodotPoolRealArray): cint {.
noSideEffect,
importc: "godot_pool_real_array_size".}
iterator items*(arr: GodotPoolRealArray): float32 =
for i in 0..<arr.len:
yield arr[i]
iterator pairs*(arr: GodotPoolRealArray): tuple[key: cint, val: float32] =
for i in 0..<arr.len:
yield (i, arr[i])
# String
proc initGodotPoolStringArray*(dest: var GodotPoolStringArray) {.
importc: "godot_pool_string_array_new".}
proc initGodotPoolStringArray*(dest: var GodotPoolStringArray;
src: GodotPoolStringArray) {.
importc: "godot_pool_string_array_new_copy".}
proc initGodotPoolStringArray*(dest: var GodotPoolStringArray; arr: GodotArray) {.
importc: "godot_pool_string_array_new_with_array".}
proc deinit*(self: var GodotPoolStringArray) {.
importc: "godot_pool_string_array_destroy".}
proc initGodotPoolStringArray*(): GodotPoolStringArray {.inline.} =
initGodotPoolStringArray(result)
proc initGodotPoolStringArray*(arr: GodotArray): GodotPoolStringArray {.inline.} =
initGodotPoolStringArray(result, arr)
proc add*(self: var GodotPoolStringArray; data: GodotString) {.
importc: "godot_pool_string_array_append".}
proc addFirst*(self: var GodotPoolStringArray; data: GodotString) {.
importc: "godot_pool_string_array_push_back".}
proc add*(self: var GodotPoolStringArray; arr: GodotPoolStringArray) {.
importc: "godot_pool_string_array_append_array".}
proc insert*(self: var GodotPoolStringArray;
idx: cint; data: GodotString): Error {.
importc: "godot_pool_string_array_insert".}
proc delete*(self: var GodotPoolStringArray; idx: cint) {.
importc: "godot_pool_string_array_remove".}
proc reverse*(self: var GodotPoolStringArray) {.
importc: "godot_pool_string_array_invert".}
proc setLen*(self: var GodotPoolStringArray; size: cint) {.
importc: "godot_pool_string_array_resize".}
proc `[]=`*(self: var GodotPoolStringArray; idx: cint;
data: GodotString) {.
importc: "godot_pool_string_array_set".}
proc `[]`*(self: GodotPoolStringArray; idx: cint): GodotString {.
noSideEffect,
importc: "godot_pool_string_array_get".}
proc len*(self: GodotPoolStringArray): cint {.
noSideEffect,
importc: "godot_pool_string_array_size".}
iterator items*(arr: GodotPoolStringArray): GodotString =
for i in 0..<arr.len:
yield arr[i]
iterator pairs*(arr: GodotPoolStringArray): tuple[key: cint, val: GodotString] =
for i in 0..<arr.len:
yield (i, arr[i])
# Vector2
proc initGodotPoolVector2Array*(dest: var GodotPoolVector2Array) {.
importc: "godot_pool_vector2_array_new".}
proc initGodotPoolVector2Array*(dest: var GodotPoolVector2Array;
src: GodotPoolVector2Array) {.
importc: "godot_pool_vector2_array_new_copy".}
proc initGodotPoolVector2Array*(dest: var GodotPoolVector2Array;
arr: GodotArray) {.
importc: "godot_pool_vector2_array_new_with_array".}
proc deinit*(self: var GodotPoolVector2Array) {.
importc: "godot_pool_vector2_array_destroy".}
proc initGodotPoolVector2Array*(): GodotPoolVector2Array {.inline.} =
initGodotPoolVector2Array(result)
proc initGodotPoolVector2Array*(arr: GodotArray): GodotPoolVector2Array {.inline.} =
initGodotPoolVector2Array(result, arr)
proc add*(self: var GodotPoolVector2Array; data: Vector2) {.
importc: "godot_pool_vector2_array_append".}
proc addFirst*(self: var GodotPoolVector2Array; data: Vector2) {.
importc: "godot_pool_vector2_array_push_back".}
proc add*(self: var GodotPoolVector2Array;
arr: GodotPoolVector2Array) {.
importc: "godot_pool_vector2_array_append_array".}
proc insert*(self: var GodotPoolVector2Array;
idx: cint; data: Vector2): Error {.
importc: "godot_pool_vector2_array_insert".}
proc delete*(self: var GodotPoolVector2Array; idx: cint) {.
importc: "godot_pool_vector2_array_remove".}
proc reverse*(self: var GodotPoolVector2Array) {.
importc: "godot_pool_vector2_array_invert".}
proc setLen*(self: var GodotPoolVector2Array; size: cint) {.
importc: "godot_pool_vector2_array_resize".}
proc `[]=`*(self: var GodotPoolVector2Array; idx: cint;
data: Vector2) {.
importc: "godot_pool_vector2_array_set".}
proc `[]`*(self: GodotPoolVector2Array; idx: cint): Vector2 {.
noSideEffect,
importc: "godot_pool_vector2_array_get".}
proc len*(self: GodotPoolVector2Array): cint {.
noSideEffect,
importc: "godot_pool_vector2_array_size".}
iterator items*(arr: GodotPoolVector2Array): Vector2 =
for i in 0..<arr.len:
yield arr[i]
iterator pairs*(arr: GodotPoolVector2Array): tuple[key: cint, val: Vector2] =
for i in 0..<arr.len:
yield (i, arr[i])
# Vector3
proc initGodotPoolVector3Array*(dest: var GodotPoolVector3Array) {.
importc: "godot_pool_vector3_array_new".}
proc initGodotPoolVector3Array*(dest: var GodotPoolVector3Array;
src: GodotPoolVector3Array) {.
importc: "godot_pool_vector3_array_new_copy".}
proc initGodotPoolVector3Array*(dest: var GodotPoolVector3Array;
arr: GodotArray) {.
importc: "godot_pool_vector3_array_new_with_array".}
proc deinit*(self: var GodotPoolVector3Array) {.
importc: "godot_pool_vector3_array_destroy".}
proc initGodotPoolVector3Array*(): GodotPoolVector3Array {.inline.} =
initGodotPoolVector3Array(result)
proc initGodotPoolVector3Array*(arr: GodotArray):
GodotPoolVector3Array {.inline.} =
initGodotPoolVector3Array(result, arr)
proc add*(self: var GodotPoolVector3Array;
data: Vector3) {.
importc: "godot_pool_vector3_array_append".}
proc addFirst*(self: var GodotPoolVector3Array;
data: Vector3) {.
importc: "godot_pool_vector3_array_push_back".}
proc add*(self: var GodotPoolVector3Array;
arr: GodotPoolVector3Array) {.
importc: "godot_pool_vector3_array_append_array".}
proc insert*(self: var GodotPoolVector3Array;
idx: cint; data: Vector3): Error {.
importc: "godot_pool_vector3_array_insert".}
proc delete*(self: var GodotPoolVector3Array; idx: cint) {.
importc: "godot_pool_vector3_array_remove".}
proc reverse*(self: var GodotPoolVector3Array) {.
importc: "godot_pool_vector3_array_invert".}
proc setLen*(self: var GodotPoolVector3Array; size: cint) {.
importc: "godot_pool_vector3_array_resize".}
proc `[]=`*(self: var GodotPoolVector3Array;
idx: cint; data: Vector3) {.
importc: "godot_pool_vector3_array_set".}
proc `[]`*(self: GodotPoolVector3Array;
idx: cint): Vector3 {.
noSideEffect,
importc: "godot_pool_vector3_array_get".}
proc len*(self: GodotPoolVector3Array): cint {.
noSideEffect,
importc: "godot_pool_vector3_array_size".}
iterator items*(arr: GodotPoolVector3Array): Vector3 =
for i in 0..<arr.len:
yield arr[i]
iterator pairs*(arr: GodotPoolVector3Array): tuple[key: cint, val: Vector3] =
for i in 0..<arr.len:
yield (i, arr[i])
# Color
proc initGodotPoolColorArray*(dest: var GodotPoolColorArray) {.
importc: "godot_pool_color_array_new".}
proc initGodotPoolColorArray*(dest: var GodotPoolColorArray;
src: GodotPoolColorArray) {.
importc: "godot_pool_color_array_new_copy".}
proc initGodotPoolColorArray*(dest: var GodotPoolColorArray; arr: GodotArray) {.
importc: "godot_pool_color_array_new_with_array".}
proc deinit*(self: var GodotPoolColorArray) {.
importc: "godot_pool_color_array_destroy".}
proc initGodotPoolColorArray*(): GodotPoolColorArray {.inline.} =
initGodotPoolColorArray(result)
proc initGodotPoolColorArray*(arr: GodotArray): GodotPoolColorArray {.inline.} =
initGodotPoolColorArray(result, arr)
proc add*(self: var GodotPoolColorArray; data: Color) {.
importc: "godot_pool_color_array_append".}
proc addFirst*(self: var GodotPoolColorArray; data: Color) {.
importc: "godot_pool_color_array_push_back".}
proc add*(self: var GodotPoolColorArray; arr: GodotPoolColorArray) {.
importc: "godot_pool_color_array_append_array".}
proc insert*(self: var GodotPoolColorArray;
idx: cint; data: Color): Error {.
importc: "godot_pool_color_array_insert".}
proc delete*(self: var GodotPoolColorArray; idx: cint) {.
importc: "godot_pool_color_array_remove".}
proc reverse*(self: var GodotPoolColorArray) {.
importc: "godot_pool_color_array_invert".}
proc setLen*(self: var GodotPoolColorArray; size: cint) {.
importc: "godot_pool_color_array_resize".}
proc `[]=`*(self: var GodotPoolColorArray; idx: cint;
data: Color) {.
importc: "godot_pool_color_array_set".}
proc `[]`*(self: GodotPoolColorArray; idx: cint): Color {.
noSideEffect,
importc: "godot_pool_color_array_get".}
proc len*(self: GodotPoolColorArray): cint {.
noSideEffect,
importc: "godot_pool_color_array_size".}
iterator items*(arr: GodotPoolColorArray): Color =
for i in 0..<arr.len:
yield arr[i]
iterator pairs*(arr: GodotPoolColorArray): tuple[key: cint, val: Color] =
for i in 0..<arr.len:
yield (i, arr[i])

View file

@ -1,35 +1,38 @@
# Copyright (c) 2017 Xored Software, Inc. # Copyright (c) 2017 Xored Software, Inc.
type import godotinternaltypes, gdnativeapi
GodotString* {.byref.} = object
data: array[sizeof(int), byte] proc initGodotString(dest: var GodotString) {.inline, raises: [].} =
getGDNativeAPI().stringNew(dest)
proc initGodotString(dest: var GodotString) {.
importc: "godot_string_new".}
proc initGodotString(dest: var GodotString; contents: cstring; proc initGodotString(dest: var GodotString; contents: cstring;
size: cint) {. size: cint) {.inline.} =
importc: "godot_string_new_data".}
## Initializes ``dest`` from UTF-8 ``contents`` ## Initializes ``dest`` from UTF-8 ``contents``
getGDNativeAPI().stringNewData(dest, contents, size)
proc getData(self: GodotString; dest: cstring; proc getData(self: GodotString; dest: cstring;
size: var cint) {. size: var cint) {.inline.} =
noSideEffect
importc: "godot_string_get_data".}
## Converts ``self`` into UTF-8 encoding, putting the result into ``dest``. ## Converts ``self`` into UTF-8 encoding, putting the result into ``dest``.
getGDNativeAPI().stringGetData(self, dest, size)
proc len*(self: GodotString): cint {.inline.} = proc len*(self: GodotString): cint {.inline.} =
## Returns the length of string in bytes if it is represented as UTF-8. ## Returns the length of string in bytes if it is represented as UTF-8.
getData(self, nil, result) getData(self, nil, result)
proc cstring*(self: GodotString): cstring {. proc cstring*(self: GodotString): cstring {.inline.} =
importc: "godot_string_c_str".} getGDNativeAPI().stringCStr(self)
proc `==`*(self, b: GodotString): bool {.
importc: "godot_string_operator_equal".}
proc `<`*(self, b: GodotString): bool {.
importc: "godot_string_operator_less".}
proc `&`*(self, b: GodotString): GodotString {.
importc: "godot_string_operator_plus".}
proc deinit*(self: var GodotString) {.importc: "godot_string_destroy".} proc `==`*(self, b: GodotString): bool {.inline.} =
getGDNativeAPI().stringOperatorEqual(self, b)
proc `<`*(self, b: GodotString): bool {.inline.} =
getGDNativeAPI().stringOperatorLess(self, b)
proc `&`*(self, b: GodotString): GodotString {.inline.} =
getGDNativeAPI().stringOperatorPlus(self, b)
proc deinit*(self: var GodotString) {.inline.} =
getGDNativeAPI().stringDestroy(self)
proc `$`*(self: GodotString): string = proc `$`*(self: GodotString): string =
## Converts the ``GodotString`` into Nim string ## Converts the ``GodotString`` into Nim string

View file

@ -1,197 +1,216 @@
# Copyright 2017 Xored Software, Inc. # Copyright 2017 Xored Software, Inc.
type import core.godotcoretypes, godotinternaltypes, gdnativeapi
VariantType* {.size: sizeof(cint), pure.} = enum
Nil, ## atomic types
Bool,
Int,
Real,
String,
# math types
Vector2, ## 5
Rect2,
Vector3,
Transform2D,
Plane,
Quat, ## 10
Rect3,
Basis,
Transform, ## misc types
Color,
NodePath, ## 15
RID,
Object,
Dictionary,
Array, ## 20
# arrays
PoolByteArray,
PoolIntArray,
PoolRealArray,
PoolStringArray,
PoolVector2Array, ## 25
PoolVector3Array,
PoolColorArray
VariantCallErrorType* {.size: sizeof(cint), pure.} = enum proc getType*(p: GodotVariant): VariantType {.inline.} =
OK, getGDNativeAPI().variantGetType(p)
InvalidMethod,
InvalidArgument,
TooManyArguments,
TooFewArguments,
InstanceIsNull
VariantCallError* = object proc initGodotVariant*(dest: var GodotVariant) {.inline.} =
error*: VariantCallErrorType getGDNativeAPI().variantNewNil(dest)
argument*: cint
expected*: VariantType
GodotVariant* {.byref.} = object proc initGodotVariant*(dest: var GodotVariant, src: GodotVariant) {.inline.} =
data: array[4 + sizeof(int) div 4, float32] getGDNativeAPI().variantNewCopy(dest, src)
import godotobjects, godotarrays, godotpoolarrays, proc initGodotVariant*(dest: var GodotVariant; b: bool) {.inline.} =
godotstrings, godotnodepaths, godotdictionaries getGDNativeAPI().variantNewBool(dest, b)
import core.vector2, core.rect2, proc initGodotVariant*(dest: var GodotVariant; i: uint64) {.inline.} =
core.vector3, core.transform2d, core.planes, getGDNativeAPI().variantNewUInt(dest, i)
core.quats, core.rect3, core.basis,
core.transforms, core.colors, core.rids,
core.rect2
proc getType*(p: GodotVariant): VariantType {. proc initGodotVariant*(dest: var GodotVariant; i: int64) {.inline.} =
importc: "godot_variant_get_type".} getGDNativeAPI().variantNewInt(dest, i)
proc initGodotVariant*(dest: var GodotVariant) {. proc initGodotVariant*(dest: var GodotVariant; r: cdouble) {.inline.} =
importc: "godot_variant_new_nil".} getGDNativeAPI().variantNewReal(dest, r)
proc initGodotVariant*(dest: var GodotVariant, src: GodotVariant) {.
importc: "godot_variant_new_copy".}
proc initGodotVariant*(dest: var GodotVariant; b: bool) {.
importc: "godot_variant_new_bool".}
proc initGodotVariant*(dest: var GodotVariant; i: uint64) {.
importc: "godot_variant_new_uint".}
proc initGodotVariant*(dest: var GodotVariant; i: int64) {.
importc: "godot_variant_new_int".}
proc initGodotVariant*(dest: var GodotVariant; r: cdouble) {.
importc: "godot_variant_new_real".}
proc initGodotVariant*(dest: var GodotVariant; s: GodotString) {.
importc: "godot_variant_new_string".}
proc initGodotVariant*(dest: var GodotVariant; v2: Vector2) {.
importc: "godot_variant_new_vector2".}
proc initGodotVariant*(dest: var GodotVariant; rect2: Rect2) {.
importc: "godot_variant_new_rect2".}
proc initGodotVariant*(dest: var GodotVariant; v3: Vector3) {.
importc: "godot_variant_new_vector3".}
proc initGodotVariant*(dest: var GodotVariant; t2d: Transform2D) {.
importc: "godot_variant_new_transform2d".}
proc initGodotVariant*(dest: var GodotVariant; plane: Plane) {.
importc: "godot_variant_new_plane".}
proc initGodotVariant*(dest: var GodotVariant; quat: Quat) {.
importc: "godot_variant_new_quat".}
proc initGodotVariant*(dest: var GodotVariant; rect3: Rect3) {.
importc: "godot_variant_new_rect3".}
proc initGodotVariant*(dest: var GodotVariant; basis: Basis) {.
importc: "godot_variant_new_basis".}
proc initGodotVariant*(dest: var GodotVariant; trans: Transform) {.
importc: "godot_variant_new_transform".}
proc initGodotVariant*(dest: var GodotVariant; color: Color) {.
importc: "godot_variant_new_color".}
proc initGodotVariant*(dest: var GodotVariant; nodePath: GodotNodePath) {.
importc: "godot_variant_new_node_path".}
proc initGodotVariant*(dest: var GodotVariant; rid: RID) {.
importc: "godot_variant_new_rid".}
proc initGodotVariant*(dest: var GodotVariant; obj: ptr GodotObject) {.
importc: "godot_variant_new_object".}
proc initGodotVariant*(dest: var GodotVariant; arr: GodotArray) {.
importc: "godot_variant_new_array".}
proc initGodotVariant*(dest: var GodotVariant; pba: GodotPoolByteArray) {.
importc: "godot_variant_new_pool_byte_array".}
proc initGodotVariant*(dest: var GodotVariant; pia: GodotPoolIntArray) {.
importc: "godot_variant_new_pool_int_array".}
proc initGodotVariant*(dest: var GodotVariant; pra: GodotPoolRealArray) {.
importc: "godot_variant_new_pool_real_array".}
proc initGodotVariant*(dest: var GodotVariant; psa: GodotPoolStringArray) {.
importc: "godot_variant_new_pool_string_array".}
proc initGodotVariant*(dest: var GodotVariant; pv2a: GodotPoolVector2Array) {.
importc: "godot_variant_new_pool_vector2_array".}
proc initGodotVariant*(dest: var GodotVariant; pv3a: GodotPoolVector3Array) {.
importc: "godot_variant_new_pool_vector3_array".}
proc initGodotVariant*(dest: var GodotVariant; pca: GodotPoolColorArray) {.
importc: "godot_variant_new_pool_color_array".}
proc initGodotVariant*(dest: var GodotVariant; dict: GodotDictionary) {.
importc: "godot_variant_new_dictionary".}
proc deinit*(v: var GodotVariant) {.importc: "godot_variant_destroy".} proc initGodotVariant*(dest: var GodotVariant; s: GodotString) {.inline.} =
getGDNativeAPI().variantNewString(dest, s)
proc asBool*(self: GodotVariant): bool {. proc initGodotVariant*(dest: var GodotVariant; v2: Vector2) {.inline.} =
importc: "godot_variant_as_bool".} getGDNativeAPI().variantNewVector2(dest, v2)
proc asUInt*(self: GodotVariant): uint64 {.
importc: "godot_variant_as_uint".}
proc asInt*(self: GodotVariant): int64 {.
importc: "godot_variant_as_int".}
proc asReal*(self: GodotVariant): cdouble {.
importc: "godot_variant_as_real".}
proc asGodotString*(self: GodotVariant): GodotString {.
importc: "godot_variant_as_string".}
proc asVector2*(self: GodotVariant): Vector2 {.
importc: "godot_variant_as_vector2".}
proc asRect2*(self: GodotVariant): Rect2 {.
importc: "godot_variant_as_rect2".}
proc asVector3*(self: GodotVariant): Vector3 {.
importc: "godot_variant_as_vector3".}
proc asTransform2D*(self: GodotVariant): Transform2D {.
importc: "godot_variant_as_transform2d".}
proc asPlane*(self: GodotVariant): Plane {.
importc: "godot_variant_as_plane".}
proc asQuat*(self: GodotVariant): Quat {.
importc: "godot_variant_as_quat".}
proc asRect3*(self: GodotVariant): Rect3 {.
importc: "godot_variant_as_rect3".}
proc asBasis*(self: GodotVariant): Basis {.
importc: "godot_variant_as_basis".}
proc asTransform*(self: GodotVariant): Transform {.
importc: "godot_variant_as_transform".}
proc asColor*(self: GodotVariant): Color {.
importc: "godot_variant_as_color".}
proc asNodePath*(self: GodotVariant): GodotNodePath {.
importc: "godot_variant_as_node_path".}
proc asRID*(self: GodotVariant): RID {.
importc: "godot_variant_as_rid".}
proc asGodotObject*(self: GodotVariant): ptr GodotObject {.
importc: "godot_variant_as_object".}
proc asGodotArray*(self: GodotVariant): GodotArray {.
importc: "godot_variant_as_array".}
proc asGodotPoolByteArray*(self: GodotVariant): GodotPoolByteArray {.
importc: "godot_variant_as_pool_byte_array".}
proc asGodotPoolIntArray*(self: GodotVariant): GodotPoolIntArray {.
importc: "godot_variant_as_pool_int_array".}
proc asGodotPoolRealArray*(self: GodotVariant): GodotPoolRealArray {.
importc: "godot_variant_as_pool_real_array".}
proc asGodotPoolStringArray*(self: GodotVariant): GodotPoolStringArray {.
importc: "godot_variant_as_pool_string_array".}
proc asGodotPoolVector2Array*(self: GodotVariant): GodotPoolVector2Array {.
importc: "godot_variant_as_pool_vector2_array".}
proc asGodotPoolVector3Array*(self: GodotVariant): GodotPoolVector3Array {.
importc: "godot_variant_as_pool_vector3_array".}
proc asGodotPoolColorArray*(self: GodotVariant): GodotPoolColorArray {.
importc: "godot_variant_as_pool_color_array".}
proc asGodotDictionary*(self: GodotVariant): GodotDictionary {.
importc: "godot_variant_as_dictionary".}
proc call*(self: GodotVariant; meth: GodotString; proc initGodotVariant*(dest: var GodotVariant; rect2: Rect2) {.inline.} =
args: var array[128, GodotVariant]; argCount: cint; getGDNativeAPI().variantNewRect2(dest, rect2)
error: var VariantCallError): GodotVariant {.
importc: "godot_variant_call".}
proc hasMethod*(self: GodotVariant; meth: GodotString): bool {. proc initGodotVariant*(dest: var GodotVariant; v3: Vector3) {.inline.} =
importc: "godot_variant_has_method".} getGDNativeAPI().variantNewVector3(dest, v3)
proc `==`*(self, other: GodotVariant): bool {.
importc: "godot_variant_operator_equal".}
proc `<`*(self, other: GodotVariant): bool {.
importc: "godot_variant_operator_less".}
proc hashCompare*(self, other: GodotVariant): bool {.
importc: "godot_variant_hash_compare".}
proc booleanize*(self: GodotVariant; isValid: var bool): bool {.
importc: "godot_variant_booleanize".}
proc initGodotVariant*(dest: var GodotVariant; t2d: Transform2D) {.inline.} =
getGDNativeAPI().variantNewTransform2D(dest, t2d)
proc initGodotVariant*(dest: var GodotVariant; plane: Plane) {.inline.} =
getGDNativeAPI().variantNewPlane(dest, plane)
proc initGodotVariant*(dest: var GodotVariant; quat: Quat) {.inline.} =
getGDNativeAPI().variantNewQuat(dest, quat)
proc initGodotVariant*(dest: var GodotVariant; rect3: Rect3) {.inline.} =
getGDNativeAPI().variantNewRect3(dest, rect3)
proc initGodotVariant*(dest: var GodotVariant; basis: Basis) {.inline.} =
getGDNativeAPI().variantNewBasis(dest, basis)
proc initGodotVariant*(dest: var GodotVariant; trans: Transform) {.inline.} =
getGDNativeAPI().variantNewTransform(dest, trans)
proc initGodotVariant*(dest: var GodotVariant; color: Color) {.inline.} =
getGDNativeAPI().variantNewColor(dest, color)
proc initGodotVariant*(dest: var GodotVariant;
nodePath: GodotNodePath) {.inline.} =
getGDNativeAPI().variantNewNodePath(dest, nodePath)
proc initGodotVariant*(dest: var GodotVariant; rid: RID) {.inline.} =
getGDNativeAPI().variantNewRID(dest, rid)
proc initGodotVariant*(dest: var GodotVariant;
obj: ptr GodotObject) {.inline.} =
getGDNativeAPI().variantNewObject(dest, obj)
proc initGodotVariant*(dest: var GodotVariant; arr: GodotArray) {.inline.} =
getGDNativeAPI().variantNewArray(dest, arr)
proc initGodotVariant*(dest: var GodotVariant;
pba: GodotPoolByteArray) {.inline.} =
getGDNativeAPI().variantNewPoolByteArray(dest, pba)
proc initGodotVariant*(dest: var GodotVariant;
pia: GodotPoolIntArray) {.inline.} =
getGDNativeAPI().variantNewPoolIntArray(dest, pia)
proc initGodotVariant*(dest: var GodotVariant;
pra: GodotPoolRealArray) {.inline.} =
getGDNativeAPI().variantNewPoolRealArray(dest, pra)
proc initGodotVariant*(dest: var GodotVariant;
psa: GodotPoolStringArray) {.inline.} =
getGDNativeAPI().variantNewPoolStringArray(dest, psa)
proc initGodotVariant*(dest: var GodotVariant;
pv2a: GodotPoolVector2Array) {.inline.} =
getGDNativeAPI().variantNewPoolVector2Array(dest, pv2a)
proc initGodotVariant*(dest: var GodotVariant;
pv3a: GodotPoolVector3Array) {.inline.} =
getGDNativeAPI().variantNewPoolVector3Array(dest, pv3a)
proc initGodotVariant*(dest: var GodotVariant;
pca: GodotPoolColorArray) {.inline.} =
getGDNativeAPI().variantNewPoolColorArray(dest, pca)
proc initGodotVariant*(dest: var GodotVariant;
dict: GodotDictionary) {.inline.} =
getGDNativeAPI().variantNewDictionary(dest, dict)
proc deinit*(v: var GodotVariant) {.inline.} =
getGDNativeAPI().variantDestroy(v)
proc asBool*(self: GodotVariant): bool {.inline.} =
getGDNativeAPI().variantAsBool(self)
proc asUInt*(self: GodotVariant): uint64 {.inline.} =
getGDNativeAPI().variantAsUInt(self)
proc asInt*(self: GodotVariant): int64 {.inline.} =
getGDNativeAPI().variantAsInt(self)
proc asReal*(self: GodotVariant): cdouble {.inline.} =
getGDNativeAPI().variantAsReal(self)
proc asGodotString*(self: GodotVariant): GodotString {.inline.} =
getGDNativeAPI().variantAsString(self)
proc asVector2*(self: GodotVariant): Vector2 {.inline.} =
getGDNativeAPI().variantAsVector2(self)
proc asRect2*(self: GodotVariant): Rect2 {.inline.} =
getGDNativeAPI().variantAsRect2(self)
proc asVector3*(self: GodotVariant): Vector3 {.inline.} =
getGDNativeAPI().variantAsVector3(self)
proc asTransform2D*(self: GodotVariant): Transform2D {.inline.} =
getGDNativeAPI().variantAsTransform2D(self)
proc asPlane*(self: GodotVariant): Plane {.inline.} =
getGDNativeAPI().variantAsPlane(self)
proc asQuat*(self: GodotVariant): Quat {.inline.} =
getGDNativeAPI().variantAsQuat(self)
proc asRect3*(self: GodotVariant): Rect3 {.inline.} =
getGDNativeAPI().variantAsRect3(self)
proc asBasis*(self: GodotVariant): Basis {.inline.} =
getGDNativeAPI().variantAsBasis(self)
proc asTransform*(self: GodotVariant): Transform {.inline.} =
getGDNativeAPI().variantAsTransform(self)
proc asColor*(self: GodotVariant): Color {.inline.} =
getGDNativeAPI().variantAsColor(self)
proc asNodePath*(self: GodotVariant): GodotNodePath {.inline.} =
getGDNativeAPI().variantAsNodePath(self)
proc asRID*(self: GodotVariant): RID {.inline.} =
getGDNativeAPI().variantAsRID(self)
proc asGodotObject*(self: GodotVariant): ptr GodotObject {.inline.} =
getGDNativeAPI().variantAsObject(self)
proc asGodotArray*(self: GodotVariant): GodotArray {.inline.} =
getGDNativeAPI().variantAsArray(self)
proc asGodotPoolByteArray*(self: GodotVariant): GodotPoolByteArray {.inline.} =
getGDNativeAPI().variantAsPoolByteArray(self)
proc asGodotPoolIntArray*(self: GodotVariant): GodotPoolIntArray {.inline.} =
getGDNativeAPI().variantAsPoolIntArray(self)
proc asGodotPoolRealArray*(self: GodotVariant): GodotPoolRealArray {.inline.} =
getGDNativeAPI().variantAsPoolRealArray(self)
proc asGodotPoolStringArray*(self: GodotVariant): GodotPoolStringArray
{.inline.} =
getGDNativeAPI().variantAsPoolStringArray(self)
proc asGodotPoolVector2Array*(self: GodotVariant): GodotPoolVector2Array
{.inline.} =
getGDNativeAPI().variantAsPoolVector2Array(self)
proc asGodotPoolVector3Array*(self: GodotVariant): GodotPoolVector3Array
{.inline.} =
getGDNativeAPI().variantAsPoolVector3Array(self)
proc asGodotPoolColorArray*(self: GodotVariant): GodotPoolColorArray
{.inline.} =
getGDNativeAPI().variantAsPoolColorArray(self)
proc asGodotDictionary*(self: GodotVariant): GodotDictionary {.inline.} =
getGDNativeAPI().variantAsDictionary(self)
proc call*(self: var GodotVariant; meth: GodotString;
args: ptr array[256, ptr GodotVariant]; argCount: cint;
error: var VariantCallError): GodotVariant {.inline.} =
getGDNativeAPI().variantCall(self, meth, args, argCount, error)
proc hasMethod*(self: GodotVariant; meth: GodotString): bool {.inline.} =
getGDNativeAPI().variantHasMethod(self, meth)
proc `==`*(self, other: GodotVariant): bool {.inline.} =
getGDNativeAPI().variantOperatorEqual(self, other)
proc `<`*(self, other: GodotVariant): bool {.inline.} =
getGDNativeAPI().variantOperatorLess(self, other)
proc hashCompare*(self, other: GodotVariant): bool {.inline.} =
getGDNativeAPI().variantHashCompare(self, other)
proc booleanize*(self: GodotVariant): bool {.inline.} =
getGDNativeAPI().variantBooleanize(self)
import godotstrings
proc `$`*(self: GodotVariant): string = proc `$`*(self: GodotVariant): string =
var s = self.asGodotString() var s = self.asGodotString()
result = $s result = $s

View file

@ -349,11 +349,11 @@ template registerGodotClass(classNameIdent, classNameLit; isRefClass: bool;
) )
registerClass(classNameIdent, classNameLit, false) registerClass(classNameIdent, classNameLit, false)
when isTool: when isTool:
godotScriptRegisterToolClass(getNativeLibHandle(), classNameLit, baseNameLit, nativeScriptRegisterToolClass(getNativeLibHandle(), classNameLit,
createFuncObj, destroyFuncObj) baseNameLit, createFuncObj, destroyFuncObj)
else: else:
godotScriptRegisterClass(getNativeLibHandle(), classNameLit, baseNameLit, nativeScriptRegisterClass(getNativeLibHandle(), classNameLit,
createFuncObj, destroyFuncObj) baseNameLit, createFuncObj, destroyFuncObj)
template registerGodotField(classNameLit, classNameIdent, propNameLit, template registerGodotField(classNameLit, classNameIdent, propNameLit,
propNameIdent, propTypeLit, propTypeIdent, propNameIdent, propTypeLit, propTypeIdent,
@ -415,7 +415,7 @@ template registerGodotField(classNameLit, classNameIdent, propNameLit,
{.push warning[ProveInit]: on.} {.push warning[ProveInit]: on.}
when hasDefaultValue: when hasDefaultValue:
attr.defaultValue = (defaultValueNode).toVariant().godotVariant[] attr.defaultValue = (defaultValueNode).toVariant().godotVariant[]
godotScriptRegisterProperty(getNativeLibHandle(), classNameLit, propNameLit, nativeScriptRegisterProperty(getNativeLibHandle(), classNameLit, propNameLit,
unsafeAddr attr, setFunc, getFunc) unsafeAddr attr, setFunc, getFunc)
hintStrGodot.deinit() hintStrGodot.deinit()
@ -568,8 +568,8 @@ proc genType(obj: ObjectDecl): NimNode {.compileTime.} =
let meth = GodotInstanceMethod( let meth = GodotInstanceMethod(
meth: methFuncIdent meth: methFuncIdent
) )
godotScriptRegisterMethod(getNativeLibHandle(), classNameLit, methodNameLit, nativeScriptRegisterMethod(getNativeLibHandle(), classNameLit,
GodotMethodAttributes(), meth) methodNameLit, GodotMethodAttributes(), meth)
for meth in obj.methods: for meth in obj.methods:
if meth.isNoGodot: continue if meth.isNoGodot: continue
@ -605,10 +605,10 @@ proc genType(obj: ObjectDecl): NimNode {.compileTime.} =
let refDec = GodotInstanceMethod( let refDec = GodotInstanceMethod(
meth: refcountDecremented meth: refcountDecremented
) )
godotScriptRegisterMethod(getNativeLibHandle(), classNameLit, nativeScriptRegisterMethod(getNativeLibHandle(), classNameLit,
cstring"_refcount_incremented", cstring"_refcount_incremented",
GodotMethodAttributes(), refInc) GodotMethodAttributes(), refInc)
godotScriptRegisterMethod(getNativeLibHandle(), classNameLit, nativeScriptRegisterMethod(getNativeLibHandle(), classNameLit,
cstring"_refcount_decremented", cstring"_refcount_decremented",
GodotMethodAttributes(), refDec) GodotMethodAttributes(), refDec)
result.add(getAst(registerRefIncDec(classNameLit))) result.add(getAst(registerRefIncDec(classNameLit)))

View file

@ -1,7 +1,8 @@
# Copyright 2017 Xored Software, Inc. # Copyright 2017 Xored Software, Inc.
import tables, typetraits, macros, asyncdispatch import tables, typetraits, macros, asyncdispatch
import core.godotbase import gdnativeapi
import core.godotcoretypes
import core.vector2, core.rect2, import core.vector2, core.rect2,
core.vector3, core.transform2d, core.vector3, core.transform2d,
core.planes, core.quats, core.rect3, core.planes, core.quats, core.rect3,
@ -94,12 +95,12 @@ proc isFinalized*(obj: NimGodotObject): bool {.inline.} =
template printWarning*(warning: typed) = template printWarning*(warning: typed) =
## Prints ``warning`` to Godot log, adding filename and line information. ## Prints ``warning`` to Godot log, adding filename and line information.
let (filename, line) = instantiationInfo() let (filename, line) = instantiationInfo()
godotPrintWarning(cstring($warning), nil, cstring(filename), line.cint) godotPrintWarning(cstring($warning), cstring"", cstring(filename), line.cint)
template printError*(error: typed) = template printError*(error: typed) =
## Prints ``error`` to Godot log, adding filename and line information. ## Prints ``error`` to Godot log, adding filename and line information.
let (filename, line) = instantiationInfo() let (filename, line) = instantiationInfo()
godotPrintError(cstring($error), nil, cstring(filename), line.cint) godotPrintError(cstring($error), cstring"", cstring(filename), line.cint)
proc print*(parts: varargs[string, `$`]) = proc print*(parts: varargs[string, `$`]) =
## Prints concatenated ``parts`` to Godot log. ## Prints concatenated ``parts`` to Godot log.
@ -292,8 +293,6 @@ proc `of`*[T: NimGodotObject](obj: NimGodotObject,
## Godot-specific inheritance check. ## Godot-specific inheritance check.
not obj.isNil and (system.`of`(obj, T) or system.`of`(obj.linkedObject, T)) not obj.isNil and (system.`of`(obj, T) or system.`of`(obj.linkedObject, T))
{.deprecated: [`~`: `of`].}
proc newRStrLit(s: string): NimNode {.compileTime.} = proc newRStrLit(s: string): NimNode {.compileTime.} =
result = newNimNode(nnkRStrLit) result = newNimNode(nnkRStrLit)
result.strVal = s result.strVal = s
@ -805,6 +804,7 @@ proc godot_nativescript_init(handle: pointer) {.
proc godot_gdnative_init(options: ptr GodotNativeInitOptions) {. proc godot_gdnative_init(options: ptr GodotNativeInitOptions) {.
cdecl, exportc, dynlib.} = cdecl, exportc, dynlib.} =
gdNativeLibraryObj = options.gdNativeLibrary gdNativeLibraryObj = options.gdNativeLibrary
setGDNativeAPI(options.gdNativeAPIStruct)
proc godot_gdnative_terminate(options: ptr GodotNativeTerminateOptions) {. proc godot_gdnative_terminate(options: ptr GodotNativeTerminateOptions) {.
cdecl, exportc, dynlib.} = cdecl, exportc, dynlib.} =