2023-01-12 20:49:14 +01:00
|
|
|
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
When and how to avoid using nodes for everything
|
|
|
|
================================================
|
|
|
|
|
|
|
|
|
|
|
|
Nodes are cheap to produce, but even they have their limits. A project may
|
|
|
|
have tens of thousands of nodes all doing things. The more complex their
|
|
|
|
behavior though, the larger the strain each one adds to a project's
|
|
|
|
performance.
|
|
|
|
|
2024-03-16 20:56:52 +01:00
|
|
|
Pandemonium provides more lightweight objects for creating APIs which nodes use.
|
2022-03-18 17:46:08 +01:00
|
|
|
Be sure to keep these in mind as options when designing how you wish to build
|
|
|
|
your project's features.
|
|
|
|
|
2023-01-12 19:30:47 +01:00
|
|
|
1. `Object`: The ultimate lightweight object, the original
|
2022-03-18 17:46:08 +01:00
|
|
|
Object must use manual memory management. With that said, it isn't too
|
|
|
|
difficult to create one's own custom data structures, even node structures,
|
2023-01-12 19:30:47 +01:00
|
|
|
that are also lighter than the `Node` class.
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 19:30:47 +01:00
|
|
|
- **Example:** See the `Tree` node. It supports a high level
|
2022-03-18 17:46:08 +01:00
|
|
|
of customization for a table of content with an arbitrary number of
|
|
|
|
rows and columns. The data that it uses to generate its visualization
|
2023-01-12 19:30:47 +01:00
|
|
|
though is actually a tree of `TreeItem` Objects.
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
- **Advantages:** Simplifying one's API to smaller scoped objects helps improve
|
|
|
|
its accessibility and improve iteration time. Rather than working with the
|
|
|
|
entire Node library, one creates an abbreviated set of Objects from which
|
|
|
|
a node can generate and manage the appropriate sub-nodes.
|
|
|
|
|
2023-01-12 20:55:57 +01:00
|
|
|
Note:
|
|
|
|
One should be careful when handling them. One can store an Object
|
2022-03-18 17:46:08 +01:00
|
|
|
into a variable, but these references can become invalid without warning.
|
|
|
|
For example, if the object's creator decides to delete it out of nowhere,
|
|
|
|
this would trigger an error state when one next accesses it.
|
|
|
|
|
2023-01-12 19:30:47 +01:00
|
|
|
2. `Reference`: Only a little more complex than Object.
|
2022-03-18 17:46:08 +01:00
|
|
|
They track references to themselves, only deleting loaded memory when no
|
|
|
|
further references to themselves exist. These are useful in the majority of
|
|
|
|
cases where one needs data in a custom class.
|
|
|
|
|
2023-01-12 19:30:47 +01:00
|
|
|
- **Example:** See the `File` object. It functions
|
2022-03-18 17:46:08 +01:00
|
|
|
just like a regular Object except that one need not delete it themselves.
|
|
|
|
|
|
|
|
- **Advantages:** same as the Object.
|
|
|
|
|
2023-01-12 19:30:47 +01:00
|
|
|
3. `Resource`: Only slightly more complex than Reference.
|
2022-03-18 17:46:08 +01:00
|
|
|
They have the innate ability to serialize/deserialize (i.e. save and load)
|
2024-03-16 20:56:52 +01:00
|
|
|
their object properties to/from Pandemonium resource files.
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
- **Example:** Scripts, PackedScene (for scene files), and other types like
|
2023-01-12 19:30:47 +01:00
|
|
|
each of the `AudioEffect` classes. Each of these
|
2022-03-18 17:46:08 +01:00
|
|
|
can be save and loaded, therefore they extend from Resource.
|
|
|
|
|
|
|
|
- **Advantages:** Much has
|
2023-01-12 20:47:54 +01:00
|
|
|
`already been said ( doc_resources )`
|
2023-01-12 19:30:47 +01:00
|
|
|
on `Resource`'s advantages over traditional data
|
2022-03-18 17:46:08 +01:00
|
|
|
storage methods. In the context of using Resources over Nodes though,
|
|
|
|
their main advantage is in Inspector-compatibility. While nearly as
|
|
|
|
lightweight as Object/Reference, they can still display and export
|
|
|
|
properties in the Inspector. This allows them to fulfill a purpose much
|
|
|
|
like sub-Nodes on the usability front, but also improve performance if
|
|
|
|
one plans to have many such Resources/Nodes in their scenes.
|