diff --git a/godot/core/aabb.nim b/godot/core/aabb.nim index 88bf66a..2e9e7f0 100644 --- a/godot/core/aabb.nim +++ b/godot/core/aabb.nim @@ -1,5 +1,8 @@ # Copyright (c) 2018 Xored Software, Inc. +import hashes + +import vector3 import internal.godotinternaltypes, internal.godotstrings import godotcoretypes, gdnativeapi @@ -9,6 +12,9 @@ proc initAABB*(pos, size: Vector3): AABB {.inline.} = proc `$`*(self: AABB): string {.inline.} = $getGDNativeAPI().aabbAsString(self) +proc hash*(self: AABB): Hash {.inline.} = + !$(self.position.hash() !& self.size.hash()) + proc area*(self: AABB): float32 {.inline.} = getGDNativeAPI().aabbGetArea(self) diff --git a/godot/core/basis.nim b/godot/core/basis.nim index 538ca60..704f666 100644 --- a/godot/core/basis.nim +++ b/godot/core/basis.nim @@ -1,6 +1,7 @@ # Copyright (c) 2018 Xored Software, Inc. -import math +import math, hashes + import godotbase, vector3, quats import godotcoretypes @@ -201,6 +202,9 @@ proc `$`*(self: Basis): string {.inline.} = result.add(", ") result.add($self[i][j]) +proc hash*(self: Basis): Hash {.inline.} = + !$(self.elements[0].hash() !& self.elements[1].hash() !& self.elements[2].hash()) + template cofac(row1, col1, row2, col2: int): float32 = self.elements[row1][col1] * self.elements[row2][col2] - self.elements[row1][col2] * self.elements[row2][col1] diff --git a/godot/core/colors.nim b/godot/core/colors.nim index 46fcaf3..9079dad 100644 --- a/godot/core/colors.nim +++ b/godot/core/colors.nim @@ -1,5 +1,7 @@ # Copyright (c) 2018 Xored Software, Inc. +import hashes + import godotcoretypes, gdnativeapi proc initColor*(r, g, b: float32; a: float32 = 1.0'f32): Color {.inline.} = @@ -33,6 +35,9 @@ proc `$`*(self: Color): string {.inline.} = result.add(", ") result.add($self.a) +proc hash*(self: Color): Hash {.inline.} = + !$(self.r.hash() !& self.g.hash() !& self.b.hash() !& self.a.hash()) + proc toHex(val: float32, target: var string, targetIdx: int) = let val = clamp(int(val * 255), 0, 255) let nums = [(val and 0xF0) shr 4, val and 0xF] diff --git a/godot/core/dictionaries.nim b/godot/core/dictionaries.nim index 85970e5..99ecf6a 100644 --- a/godot/core/dictionaries.nim +++ b/godot/core/dictionaries.nim @@ -33,15 +33,15 @@ proc isEmpty*(self: Dictionary): bool {.inline.} = proc clear*(self: Dictionary) {.inline.} = self.godotDictionary.clear() +proc hash*(self: Dictionary): Hash {.inline.} = + hash(self.godotDictionary.godotHash()) + import variants, arrays proc newVariant*(dict: Dictionary): Variant {.inline.} = new(result, variantFinalizer) initGodotVariant(result.godotVariant[], dict.godotDictionary) -proc asDictionary*(self: Variant): Dictionary {.inline.} = - newDictionary(self.godotVariant[].asGodotDictionary) - proc contains*(self: Dictionary; key: Variant): bool {.inline.}= self.godotDictionary.contains(key.godotVariant[]) @@ -51,9 +51,6 @@ proc contains*(self: Dictionary; keys: Array): bool {.inline.} = proc del*(self: Dictionary; key: Variant) {.inline.} = self.godotDictionary.del(key.godotVariant[]) -proc hash*(self: Dictionary): Hash {.inline.} = - hash(self.godotDictionary.godotHash()) - proc keys*(self: Dictionary): Array {.inline.} = newArray(self.godotDictionary.keys()) diff --git a/godot/core/nodepaths.nim b/godot/core/nodepaths.nim index 428e261..831c855 100644 --- a/godot/core/nodepaths.nim +++ b/godot/core/nodepaths.nim @@ -1,5 +1,7 @@ # Copyright 2018 Xored Software, Inc. +import hashes + import internal.godotinternaltypes, internal.godotnodepaths, internal.godotstrings @@ -32,6 +34,9 @@ proc `$`*(self: NodePath): string {.inline.} = result = $s s.deinit() +proc hash*(self: NodePath): Hash {.inline.} = + ($self).hash() + proc isAbsolute*(self: NodePath): bool {.inline.} = self.path.isAbsolute() diff --git a/godot/core/planes.nim b/godot/core/planes.nim index 66de34e..b9420eb 100644 --- a/godot/core/planes.nim +++ b/godot/core/planes.nim @@ -1,5 +1,7 @@ # Copyright (c) 2018 Xored Software, Inc. +import hashes + import vector3 import internal.godotinternaltypes, internal.godotstrings @@ -20,6 +22,9 @@ proc initPlane*(normal: Vector3; d: float32): Plane {.inline.} = proc `$`*(self: Plane): string {.inline.} = $getGDNativeAPI().planeAsString(self) +proc hash*(self: Plane): Hash {.inline, noinit.} = + !$(self.normal.hash() !& self.d.hash()) + proc normalized*(self: Plane): Plane {.inline.} = getGDNativeAPI().planeNormalized(self) diff --git a/godot/core/poolarrays.nim b/godot/core/poolarrays.nim index 8206662..3e7b73e 100644 --- a/godot/core/poolarrays.nim +++ b/godot/core/poolarrays.nim @@ -1,8 +1,11 @@ # Copyright 2018 Xored Software, Inc. +import hashes + import godotcoretypes import internal.godotinternaltypes, internal.godotpoolarrays, internal.godotstrings +import vector2, vector3, colors template definePoolArrayBase(T, GodotT, DataT, fieldName, newProcName, initProcName) = @@ -83,6 +86,11 @@ template definePoolArray(T, GodotT, DataT, fieldName, newProcName, initProcName; for pair in arr.fieldName.mpairs: yield (pair[0].int, pair[1]) + proc hash*(arr: T): Hash = + for item in arr.items(): + result = result !& item.hash() + result = !$result + definePoolArrayBase(PoolByteArray, GodotPoolByteArray, uint8, godotPoolByteArray, newPoolByteArray, initGodotPoolByteArray) @@ -156,3 +164,8 @@ iterator items*(arr: PoolStringArray): string = iterator pairs*(arr: PoolStringArray): tuple[key: int, val: string] = for i in 0..