2023-01-12 20:49:14 +01:00
|
|
|
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
Variant class
|
|
|
|
=============
|
|
|
|
|
|
|
|
About
|
|
|
|
-----
|
|
|
|
|
2024-03-16 20:56:52 +01:00
|
|
|
Variant is the most important datatype of Pandemonium, it's the most important
|
2022-03-18 17:46:08 +01:00
|
|
|
class in the engine. A Variant takes up only 20 bytes and can store
|
|
|
|
almost any engine datatype inside of it. Variants are rarely used to
|
|
|
|
hold information for long periods of time, instead they are used mainly
|
|
|
|
for communication, editing, serialization and generally moving data
|
|
|
|
around.
|
|
|
|
|
|
|
|
A Variant can:
|
|
|
|
|
|
|
|
- Store almost any datatype
|
|
|
|
- Perform operations between many variants (GDScript uses Variant as
|
|
|
|
its atomic/native datatype).
|
|
|
|
- Be hashed, so it can be compared quickly to other variants
|
|
|
|
- Be used to convert safely between datatypes
|
2024-03-16 20:56:52 +01:00
|
|
|
- Be used to abstract calling methods and their arguments (Pandemonium
|
2022-03-18 17:46:08 +01:00
|
|
|
exports all its functions through variants)
|
|
|
|
- Be used to defer calls or move data between threads.
|
|
|
|
- Be serialized as binary and stored to disk, or transferred via
|
|
|
|
network.
|
|
|
|
- Be serialized to text and use it for printing values and editable
|
|
|
|
settings.
|
|
|
|
- Work as an exported property, so the editor can edit it universally.
|
|
|
|
- Be used for dictionaries, arrays, parsers, etc.
|
|
|
|
|
2024-03-16 20:56:52 +01:00
|
|
|
Basically, thanks to the Variant class, writing Pandemonium itself was a much,
|
2022-03-18 17:46:08 +01:00
|
|
|
much easier task, as it allows for highly dynamic constructs not common
|
|
|
|
of C++ with little effort. Become a friend of Variant today.
|
|
|
|
|
|
|
|
References:
|
|
|
|
~~~~~~~~~~~
|
|
|
|
|
2024-03-16 21:04:42 +01:00
|
|
|
- `core/variant.h ( https://github.com/Relintai/pandemonium_engine/blob/3.x/core/variant.h )`
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
Containers: Dictionary and Array
|
|
|
|
--------------------------------
|
|
|
|
|
|
|
|
Both are implemented using variants. A Dictionary can match any datatype
|
|
|
|
used as key to any other datatype. An Array just holds an array of
|
|
|
|
Variants. Of course, a Variant can also hold a Dictionary and an Array
|
|
|
|
inside, making it even more flexible.
|
|
|
|
|
|
|
|
Modifications to a container will modify all references to
|
|
|
|
it. A Mutex should be created to lock it if multi threaded access is
|
|
|
|
desired.
|
|
|
|
|
2024-03-16 20:56:52 +01:00
|
|
|
Copy-on-write (COW) mode support for containers was dropped with Pandemonium 3.0.
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
References:
|
|
|
|
~~~~~~~~~~~
|
|
|
|
|
2024-03-16 21:04:42 +01:00
|
|
|
- `core/dictionary.h ( https://github.com/Relintai/pandemonium_engine/blob/3.x/core/dictionary.h )`
|
|
|
|
- `core/array.h ( https://github.com/Relintai/pandemonium_engine/blob/3.x/core/array.h )`
|