From 4649ff9dde34c181e3783ef7880d4adb7c3aa562 Mon Sep 17 00:00:00 2001 From: Anton Tarasenko Date: Tue, 5 Jul 2022 20:19:35 +0700 Subject: [PATCH] Add `Vector` boxes and refs --- sources/Types/Boxes/BoxAPI.uc | 29 +++ sources/Types/Boxes/Native/VectorArrayBox.uc | 179 +++++++++++++++++++ sources/Types/Boxes/Native/VectorBox.uc | 117 ++++++++++++ sources/Types/Refs/Native/VectorArrayRef.uc | Bin 0 -> 36456 bytes sources/Types/Refs/Native/VectorRef.uc | Bin 0 -> 4488 bytes sources/Types/Refs/RefAPI.uc | 29 +++ 6 files changed, 354 insertions(+) create mode 100644 sources/Types/Boxes/Native/VectorArrayBox.uc create mode 100644 sources/Types/Boxes/Native/VectorBox.uc create mode 100644 sources/Types/Refs/Native/VectorArrayRef.uc create mode 100644 sources/Types/Refs/Native/VectorRef.uc diff --git a/sources/Types/Boxes/BoxAPI.uc b/sources/Types/Boxes/BoxAPI.uc index 3143bcf..b4ae913 100644 --- a/sources/Types/Boxes/BoxAPI.uc +++ b/sources/Types/Boxes/BoxAPI.uc @@ -136,6 +136,35 @@ public final function IntArrayBox IntArray(array arrayValue) return box; } +/** + * Creates initialized box that stores an `Vector` value. + * + * @param value Value to store in the box. + * @return `VectorBox`, containing `value`. + */ +public final function VectorBox Vector(optional Vector value) +{ + local VectorBox box; + box = VectorBox(_.memory.Allocate(class'VectorBox')); + box.Initialize(value); + return box; +} + +/** + * Creates initialized box that stores an array of `Vector` values. + * Initializes it with a given array. + * + * @param arrayValue Initial array value to store in the box. + * @return `VectorArrayBox`, containing `arrayValue`. + */ +public final function VectorArrayBox VectorArray(array arrayValue) +{ + local VectorArrayBox box; + box = VectorArrayBox(_.memory.Allocate(class'VectorArrayBox')); + box.Initialize(arrayValue); + return box; +} + defaultproperties { } \ No newline at end of file diff --git a/sources/Types/Boxes/Native/VectorArrayBox.uc b/sources/Types/Boxes/Native/VectorArrayBox.uc new file mode 100644 index 0000000..bb8f782 --- /dev/null +++ b/sources/Types/Boxes/Native/VectorArrayBox.uc @@ -0,0 +1,179 @@ +/** + * This file either is or was auto-generated from the template for + * array box. + * Copyright 2022 Anton Tarasenko + *------------------------------------------------------------------------------ + * This file is part of Acedia. + * + * Acedia is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License, or + * (at your option) any later version. + * + * Acedia is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Acedia. If not, see . + */ +class VectorArrayBox extends ArrayBox; + +var protected array< Vector > value; + +// Compares an element from the array to the passed `item`. +// Does not check boundary conditions, so make sure passed index is valid. +// +// `0` means values are equal; +// `-1` means value at `index1` is strictly smaller; +// `1` means value at `index1` is strictly larger. +// ^ Only these 3 values can be returned. +private function int _compareTo(int index, Vector item) +{ + if (value[index] == item) { + return 0; + } + if (value[index].x < item.x) { + return -1; + } + if (value[index].y < item.y) { + return -1; + } + if (value[index].z < item.z) { + return -1; + } + return 1; +} + +/** + * Returns stored value. + * + * @return Value, stored in this box. + */ +public final function array< Vector > Get() +{ + return value; +} + +/** + * Initialized box value. Can only be called once. + * + * @param boxValue Value to store in this box. + * @return Reference to the caller `VectorArrayBox` to allow for method + * chaining. + */ +public final function VectorArrayBox Initialize(array< Vector > boxValue) +{ + if (IsInitialized()) return self; + value = boxValue; + MarkInitialized(); + return self; +} + +/** + * Returns current length of stored array. + * Cannot fail. + * + * @return Returns length of the stored array. Guaranteed to be non-negative. + */ +public final function int GetLength() +{ + return value.length; +} + +/** + * Returns item at `index`. If index is invalid, returns `defaultValue`. + * + * @param index Index of an item that array has to return. + * @param defaultValue Value that will be returned if either `index < 0` + * or `index >= self.GetLength()`. + * @return Either value at `index` in the caller array or `defaultValue` if + * passed `index` is invalid. + */ +public final function Vector GetItem( + int index, + optional Vector defaultValue) +{ + if (index < 0) return defaultValue; + if (index >= value.length) return defaultValue; + return value[index]; +} + +/** + * Finds first occurrence of `item` in caller `FloatArrayBox` and returns + * it's index. + * + * @param item Item to find in array. + * @return Index of first occurrence of `item` in caller `FloatArrayBox`. + * `-1` if `item` is not found. + */ +public final function int Find(Vector item) +{ + local int i; + for (i = 0; i < value.length; i += 1) + { + if (_compareTo(i, item) == 0) { + return i; + } + } + return -1; +} + +public function bool IsEqual(Object other) +{ + local int i; + local VectorArrayBox otherBox; + local array otherValue; + otherBox = VectorArrayBox(other); + if (otherBox == none) { + return false; + } + otherValue = otherBox.value; + if (value.length != otherValue.length) { + return false; + } + for (i = 0; i < value.length; i += 1) + { + if (value[i] != otherValue[i]) { + return false; + } + } + return true; +} + +protected function int CalculateHashCode() +{ + local int i; + local int result; + result = 28492904; + for (i = 0; i < value.length; i += 1) { + result = CombineHash(result, CalculateVectorHashCode(value[i])); + } + return result; +} + +private final function int CalculateVectorHashCode(Vector someVector) +{ + local int hashCode; + hashCode = CalculateFloatHashCode(someVector.x); + hashCode = CombineHash(hashCode, CalculateFloatHashCode(someVector.y)); + return CombineHash(hashCode, CalculateFloatHashCode(someVector.z)); +} + +private final function int CalculateFloatHashCode(float someFloat) +{ + local int integerPart, fractionalPart; + integerPart = Ceil(someFloat) - 1; + if (someFloat - integerPart != 0) { + fractionalPart = Ceil(1 / (someFloat - integerPart)); + } + else { + fractionalPart = -26422645; + } + return CombineHash(integerPart, fractionalPart); +} + +defaultproperties +{ +} diff --git a/sources/Types/Boxes/Native/VectorBox.uc b/sources/Types/Boxes/Native/VectorBox.uc new file mode 100644 index 0000000..75e1c3e --- /dev/null +++ b/sources/Types/Boxes/Native/VectorBox.uc @@ -0,0 +1,117 @@ +/** + * This file either is or was auto-generated from the template for + * value box. + * Copyright 2022 Anton Tarasenko + *------------------------------------------------------------------------------ + * This file is part of Acedia. + * + * Acedia is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License, or + * (at your option) any later version. + * + * Acedia is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Acedia. If not, see . + */ +class VectorBox extends ValueBox; + +var protected Vector value; + +protected function Finalizer() +{ + value = Vect(0.0, 0.0, 0.0); +} + +/** + * Returns stored value. + * + * @return Value, stored in this reference. + */ +public final function Vector Get() +{ + return value; +} + +/** + * Returns x-coordinate of the stored value. + * + * @return Value, stored in this reference. + */ +public final function float GetX() +{ + return value.x; +} + +/** + * Returns y-coordinate of the stored value. + * + * @return Value, stored in this reference. + */ +public final function float GetY() +{ + return value.y; +} + +/** + * Returns z-coordinate of the stored value. + * + * @return Value, stored in this reference. + */ +public final function float GetZ() +{ + return value.z; +} + +/** + * Initialized box value. Can only be called once. + * + * @param boxValue Value to store in this reference. + * @return Reference to the caller `VectorBox` to allow for method chaining. + */ +public final function VectorBox Initialize(Vector boxValue) +{ + if (IsInitialized()) return self; + value = boxValue; + MarkInitialized(); + return self; +} + +public function bool IsEqual(Object other) +{ + local VectorBox otherBox; + otherBox = VectorBox(other); + if (otherBox == none) { + return false; + } + return value == otherBox.value; +} + +protected function int CalculateHashCode() +{ + local int hashCode; + hashCode = CalculateFloatHashCode(value.x); + hashCode = CombineHash(hashCode, CalculateFloatHashCode(value.y)); + return CombineHash(hashCode, CalculateFloatHashCode(value.z)); +} + +private final function int CalculateFloatHashCode(float someFloat) +{ + local int integerPart, fractionalPart; + integerPart = Ceil(someFloat) - 1; + if (someFloat - integerPart != 0) { + fractionalPart = Ceil(1 / (someFloat - integerPart)); + } + else { + fractionalPart = -26422645; + } + return CombineHash(integerPart, fractionalPart); +} + +defaultproperties +{ +} \ No newline at end of file diff --git a/sources/Types/Refs/Native/VectorArrayRef.uc b/sources/Types/Refs/Native/VectorArrayRef.uc new file mode 100644 index 0000000000000000000000000000000000000000..d2e0866d134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2fyddFCRL=MxbIxBj#@?ZE%lGi!7IG6 z%9;2~Jo4$bQ^XFHF2y_kM>KMJYS)rbTF3TWgST7XjtZD16!vq)vW}`?SHFoP+BV-) zykX6|k9OVc53qbK-Ad^KZe)Bg3tO}7w#-x5uTGiHgL*=P{8#6db5B$?WYl|rEFkR z=vt!kk+-6B+gkv)cHmzyav!T}&I`AX;*hBkQ6%PzM>PCn5x46SRgtZN2}Me2`ncRP@%4&SzJ2Ia=?ItFE4AVaW#w9j?s4ir DJ6g0s literal 0 HcmV?d00001 diff --git a/sources/Types/Refs/RefAPI.uc b/sources/Types/Refs/RefAPI.uc index d271940..82ee688 100644 --- a/sources/Types/Refs/RefAPI.uc +++ b/sources/Types/Refs/RefAPI.uc @@ -169,6 +169,35 @@ public final function IntArrayRef IntArray(array arrayValue) return ref; } +/** + * Creates reference object to store an `Vector` value. + * + * @param value Initial value to store in reference. + * @return `VectorRef`, containing `value`. + */ +public final function VectorRef Vector(optional Vector value) +{ + local VectorRef ref; + ref = VectorRef(_.memory.Allocate(class'VectorRef')); + ref.Set(value); + return ref; +} + +/** + * Creates reference object to store an array of `Vector` values. + * Initializes it with a given array. + * + * @param arrayValue Initial array value to store in reference. + * @return `VectorArrayRef`, containing `arrayValue`. + */ +public final function VectorArrayRef VectorArray(array arrayValue) +{ + local VectorArrayRef ref; + ref = VectorArrayRef(_.memory.Allocate(class'VectorArrayRef')); + ref.Set(arrayValue); + return ref; +} + /** * Creates reference object to store an array of `int` values. * Initializes it with an empty array.