Variant cleanups, and added StringName.

This commit is contained in:
Relintai 2023-05-31 14:29:51 +02:00
parent 1f3bdca877
commit 6b167533d6
7 changed files with 213 additions and 31 deletions

View File

@ -464,7 +464,7 @@ def generate_class_implementation(icalls, used_classes, c, use_template_get_node
) )
source.append("\tpandemonium_string_name class_name;") source.append("\tpandemonium_string_name class_name;")
source.append('\tgodot::api->pandemonium_string_name_new_data(&class_name, "' + c["name"] + '");') source.append('\tgodot::api->pandemonium_string_name_new_data_char(&class_name, "' + c["name"] + '");')
source.append("\t_detail_class_tag = godot::api->pandemonium_get_class_tag(&class_name);") source.append("\t_detail_class_tag = godot::api->pandemonium_get_class_tag(&class_name);")
source.append("\tgodot::api->pandemonium_string_name_destroy(&class_name);") source.append("\tgodot::api->pandemonium_string_name_destroy(&class_name);")

View File

@ -45,6 +45,7 @@
#include "RID.hpp" #include "RID.hpp"
#include "Rect2.hpp" #include "Rect2.hpp"
#include "String.hpp" #include "String.hpp"
#include "StringName.hpp"
#include "Transform.hpp" #include "Transform.hpp"
#include "Transform2D.hpp" #include "Transform2D.hpp"
#include "Variant.hpp" #include "Variant.hpp"

View File

@ -42,6 +42,7 @@ class PoolIntArray;
class PoolRealArray; class PoolRealArray;
class PoolStringArray; class PoolStringArray;
class String; class String;
class StringName;
class CharString { class CharString {
friend class String; friend class String;
@ -61,6 +62,7 @@ class String {
friend class Dictionary; friend class Dictionary;
friend class NodePath; friend class NodePath;
friend class Variant; friend class Variant;
friend class StringName;
explicit inline String(pandemonium_string contents) : explicit inline String(pandemonium_string contents) :
_pandemonium_string(contents) {} _pandemonium_string(contents) {}

View File

@ -0,0 +1,72 @@
/*************************************************************************/
/* String.hpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#ifndef STRING_NAME_H
#define STRING_NAME_H
#include <gdn/string_name.h>
namespace godot {
class String;
class StringName {
pandemonium_string_name _pandemonium_string_name;
friend class Dictionary;
friend class NodePath;
friend class Variant;
explicit inline StringName(pandemonium_string_name contents) :
_pandemonium_string_name(contents) {}
public:
StringName();
StringName(const char *contents);
StringName(const String &other);
~StringName();
operator String();
uint32_t get_hash();
const void *get_data_unique_pointer();
bool operator==(const StringName &s) const;
bool operator!=(const StringName &s) const;
bool operator<(const StringName &s) const;
bool operator<=(const StringName &s) const;
bool operator>(const StringName &s) const;
bool operator>=(const StringName &s) const;
};
} // namespace godot
#endif // STRING_H

View File

@ -76,41 +76,51 @@ public:
STRING, STRING,
// math types // math types
RECT2, // 5
VECTOR2, // 5 RECT2I,
RECT2, VECTOR2,
VECTOR2I,
VECTOR3, VECTOR3,
TRANSFORM2D, VECTOR3I, // 10
VECTOR4,
VECTOR4I,
PLANE, PLANE,
QUAT, // 10 QUATERNION,
RECT3, //sorry naming convention fail :( not like it's used often AABB, // 15
BASIS, BASIS,
TRANSFORM, TRANSFORM,
TRANSFORM2D,
PROJECTION,
// misc types // misc types
COLOR, COLOR, // 20
NODE_PATH, // 15 NODE_PATH,
_RID, RID,
OBJECT, OBJECT,
DICTIONARY, STRING_NAME,
DICTIONARY, // 25
ARRAY, ARRAY,
// arrays // arrays
POOL_BYTE_ARRAY, // 20 POOL_BYTE_ARRAY,
POOL_INT_ARRAY, POOL_INT_ARRAY,
POOL_REAL_ARRAY, POOL_REAL_ARRAY,
POOL_STRING_ARRAY, POOL_STRING_ARRAY, // 30
POOL_VECTOR2_ARRAY, POOL_VECTOR2_ARRAY,
POOL_VECTOR3_ARRAY, // 25 POOL_VECTOR2I_ARRAY,
POOL_VECTOR3_ARRAY,
POOL_VECTOR3I_ARRAY,
POOL_VECTOR4_ARRAY, // 35
POOL_VECTOR4I_ARRAY,
POOL_COLOR_ARRAY, POOL_COLOR_ARRAY,
VARIANT_MAX VARIANT_MAX // 38
}; };
enum Operator { enum Operator {
//comparation // comparation
OP_EQUAL, OP_EQUAL,
OP_NOT_EQUAL, OP_NOT_EQUAL,
OP_LESS, OP_LESS,
@ -118,7 +128,7 @@ public:
OP_GREATER, OP_GREATER,
OP_GREATER_EQUAL, OP_GREATER_EQUAL,
//mathematic // mathematic
OP_ADD, OP_ADD,
OP_SUBSTRACT, OP_SUBSTRACT,
OP_MULTIPLY, OP_MULTIPLY,
@ -128,7 +138,7 @@ public:
OP_MODULE, OP_MODULE,
OP_STRING_CONCAT, OP_STRING_CONCAT,
//bitwise // bitwise
OP_SHIFT_LEFT, OP_SHIFT_LEFT,
OP_SHIFT_RIGHT, OP_SHIFT_RIGHT,
OP_BIT_AND, OP_BIT_AND,
@ -136,13 +146,13 @@ public:
OP_BIT_XOR, OP_BIT_XOR,
OP_BIT_NEGATE, OP_BIT_NEGATE,
//logic // logic
OP_AND, OP_AND,
OP_OR, OP_OR,
OP_XOR, OP_XOR,
OP_NOT, OP_NOT,
//containment // containment
OP_IN, OP_IN,
OP_MAX OP_MAX
@ -177,6 +187,7 @@ public:
Variant(double p_double); Variant(double p_double);
Variant(const String &p_string); Variant(const String &p_string);
Variant(const StringName &p_string);
Variant(const char *const p_cstring); Variant(const char *const p_cstring);
@ -190,7 +201,7 @@ public:
Variant(const Plane &p_plane); Variant(const Plane &p_plane);
Variant(const AABB &p_aabb); Variant(const ::AABB &p_aabb);
Variant(const Quat &p_quat); Variant(const Quat &p_quat);
@ -204,7 +215,7 @@ public:
Variant(const NodePath &p_path); Variant(const NodePath &p_path);
Variant(const RID &p_rid); Variant(const ::RID &p_rid);
Variant(const Object *p_object); Variant(const Object *p_object);
@ -244,11 +255,12 @@ public:
operator double() const; operator double() const;
operator String() const; operator String() const;
operator StringName() const;
operator Vector2() const; operator Vector2() const;
operator Rect2() const; operator Rect2() const;
operator Vector3() const; operator Vector3() const;
operator Plane() const; operator Plane() const;
operator AABB() const; operator ::AABB() const;
operator Quat() const; operator Quat() const;
operator Basis() const; operator Basis() const;
operator Transform() const; operator Transform() const;
@ -257,7 +269,7 @@ public:
operator Color() const; operator Color() const;
operator NodePath() const; operator NodePath() const;
operator RID() const; operator ::RID() const;
operator pandemonium_object *() const; operator pandemonium_object *() const;
template <typename T> template <typename T>

87
src/core/StringName.cpp Normal file
View File

@ -0,0 +1,87 @@
/*************************************************************************/
/* String.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "StringName.hpp"
#include "Array.hpp"
#include "GodotGlobal.hpp"
#include "NodePath.hpp"
#include "PoolArrays.hpp"
#include "Variant.hpp"
#include <gdn/string.h>
#include <string.h>
namespace godot {
godot::StringName::StringName() {
godot::api->pandemonium_string_name_new(&_pandemonium_string_name);
}
StringName::StringName(const char *contents) {
godot::api->pandemonium_string_name_new_data_char(&_pandemonium_string_name, contents);
}
StringName::StringName(const String &other) {
godot::api->pandemonium_string_name_new_data_string(&_pandemonium_string_name, &other._pandemonium_string);
}
StringName::~StringName() {
godot::api->pandemonium_string_name_destroy(&_pandemonium_string_name);
}
bool StringName::operator==(const StringName &s) const {
return godot::api->pandemonium_string_name_operator_equal(&_pandemonium_string_name, &s._pandemonium_string_name);
}
bool StringName::operator!=(const StringName &s) const {
return !(*this == s);
}
bool StringName::operator<(const StringName &s) const {
return godot::api->pandemonium_string_name_operator_less(&_pandemonium_string_name, &s._pandemonium_string_name);
}
bool StringName::operator<=(const StringName &s) const {
return godot::api->pandemonium_string_name_operator_less(&_pandemonium_string_name, &s._pandemonium_string_name) ||
(*this == s);
}
bool StringName::operator>(const StringName &s) const {
return !(*this <= s);
}
bool StringName::operator>=(const StringName &s) const {
return !(*this < s);
}
} // namespace godot

View File

@ -86,6 +86,10 @@ Variant::Variant(const String &p_string) {
godot::api->pandemonium_variant_new_string(&_pandemonium_variant, (pandemonium_string *)&p_string); godot::api->pandemonium_variant_new_string(&_pandemonium_variant, (pandemonium_string *)&p_string);
} }
Variant::Variant(const StringName &p_string) {
godot::api->pandemonium_variant_new_string_name(&_pandemonium_variant, (pandemonium_string_name *)&p_string);
}
Variant::Variant(const char *const p_cstring) { Variant::Variant(const char *const p_cstring) {
String s = String(p_cstring); String s = String(p_cstring);
godot::api->pandemonium_variant_new_string(&_pandemonium_variant, (pandemonium_string *)&s); godot::api->pandemonium_variant_new_string(&_pandemonium_variant, (pandemonium_string *)&s);
@ -112,7 +116,7 @@ Variant::Variant(const Plane &p_plane) {
godot::api->pandemonium_variant_new_plane(&_pandemonium_variant, (pandemonium_plane *)&p_plane); godot::api->pandemonium_variant_new_plane(&_pandemonium_variant, (pandemonium_plane *)&p_plane);
} }
Variant::Variant(const AABB &p_aabb) { Variant::Variant(const ::AABB &p_aabb) {
godot::api->pandemonium_variant_new_aabb(&_pandemonium_variant, (pandemonium_aabb *)&p_aabb); godot::api->pandemonium_variant_new_aabb(&_pandemonium_variant, (pandemonium_aabb *)&p_aabb);
} }
@ -140,7 +144,7 @@ Variant::Variant(const NodePath &p_path) {
godot::api->pandemonium_variant_new_node_path(&_pandemonium_variant, (pandemonium_node_path *)&p_path); godot::api->pandemonium_variant_new_node_path(&_pandemonium_variant, (pandemonium_node_path *)&p_path);
} }
Variant::Variant(const RID &p_rid) { Variant::Variant(const ::RID &p_rid) {
godot::api->pandemonium_variant_new_rid(&_pandemonium_variant, (pandemonium_rid *)&p_rid); godot::api->pandemonium_variant_new_rid(&_pandemonium_variant, (pandemonium_rid *)&p_rid);
} }
@ -237,6 +241,10 @@ Variant::operator String() const {
pandemonium_string s = godot::api->pandemonium_variant_as_string(&_pandemonium_variant); pandemonium_string s = godot::api->pandemonium_variant_as_string(&_pandemonium_variant);
return String(s); return String(s);
} }
Variant::operator StringName() const {
pandemonium_string_name s = godot::api->pandemonium_variant_as_string_name(&_pandemonium_variant);
return StringName(s);
}
Variant::operator Vector2() const { Variant::operator Vector2() const {
pandemonium_vector2 s = godot::api->pandemonium_variant_as_vector2(&_pandemonium_variant); pandemonium_vector2 s = godot::api->pandemonium_variant_as_vector2(&_pandemonium_variant);
return *(Vector2 *)&s; return *(Vector2 *)&s;
@ -253,9 +261,9 @@ Variant::operator Plane() const {
pandemonium_plane s = godot::api->pandemonium_variant_as_plane(&_pandemonium_variant); pandemonium_plane s = godot::api->pandemonium_variant_as_plane(&_pandemonium_variant);
return *(Plane *)&s; return *(Plane *)&s;
} }
Variant::operator AABB() const { Variant::operator ::AABB() const {
pandemonium_aabb s = godot::api->pandemonium_variant_as_aabb(&_pandemonium_variant); pandemonium_aabb s = godot::api->pandemonium_variant_as_aabb(&_pandemonium_variant);
return *(AABB *)&s; return *(::AABB *)&s;
} }
Variant::operator Quat() const { Variant::operator Quat() const {
pandemonium_quat s = godot::api->pandemonium_variant_as_quat(&_pandemonium_variant); pandemonium_quat s = godot::api->pandemonium_variant_as_quat(&_pandemonium_variant);
@ -282,9 +290,9 @@ Variant::operator NodePath() const {
pandemonium_node_path ret = godot::api->pandemonium_variant_as_node_path(&_pandemonium_variant); pandemonium_node_path ret = godot::api->pandemonium_variant_as_node_path(&_pandemonium_variant);
return NodePath(ret); return NodePath(ret);
} }
Variant::operator RID() const { Variant::operator ::RID() const {
pandemonium_rid s = godot::api->pandemonium_variant_as_rid(&_pandemonium_variant); pandemonium_rid s = godot::api->pandemonium_variant_as_rid(&_pandemonium_variant);
return *(RID *)&s; return *(::RID *)&s;
} }
Variant::operator Dictionary() const { Variant::operator Dictionary() const {