mk-soft wrote: Wed Dec 24, 2025 11:35 am
Instead of creating hundreds of variables, you can also work with structures and index.
Here is an example with an array and a map as an index.
...
You understand my intention more closely, but i oversimplified the problem. Instead of passing by value, or passing by reference, i am trying to create a complex array in which the contents might be passed by expression. Let me explain.
The RPG I'm inventing will, because of the necessity of hundreds of calculations per frame, rely on a multidimensional array-type structure in which the contents may be constants, literals, names of variables to retrieve, or expressions that must be evaluated. Here's the kicker: the contents of any given cell might be changed to be any one of those criteria. A cell may be modified somewhere else in the program to be a constant, a stat name, or an expression using them.
It's like a function that's overloaded with dozens if not hundreds of possible parameter lists. But because it takes a long time (relatively speaking) for the processor to determine
at runtime which of these functions applies, the need for speed requires that we break the function down to simple expressions. It would be like BASIC (or C++) in Assembly Language format — instruction, parameter. Simple and quick.
Structs can't be used because of their static memory allocation (based on type) and relatively bulky memory requirements — unless you can trim down their memory requirements dynamically on an as-needed basis. Arrays can't be used for the same reason, they would have to be reDIM'e every frame.
So i invented (at least conceptually) a Variable Matrix, an array that's handled by doing so many calculations per millisecond, then input checking, frame drawing, and time updating, and continuing its roster of calculations from where it left off. And all calculations must be done, because they rely on others.
The problem lies in allocating memory, HUNDREDS of possible reallocations per second, because of changes that happened last second. What would be the changes? Here is a short list:
- Your character moved to its next animation frame; the model vertices needs to be updated.
- The model has changed position in space: the lighting has changed and therefore the shadows and shading must be updated and redrawn.
- The textures might not be baked, and may not be static; the textures need to be recalc'd and drawn according to its new frame and the camera position.
- Reflective surfaces rely on camera position and visual impedance (like fog, distance, etc). This needs to be recalc'd and drawn.
- All of these things so far (model position, lighting changes, textural changes) may be affected by influences from multiple external sources {a dynamic aura from another character, object collision or even proximity, world discovery of something previously unknown or installed, etc).
- The sound space has changed; the reverb will need to be recalc'd
- A character's stats changed because of his afflicted conditions that also change temporally. Because that stat changed, another is affected, and so on...
- Effects of radial auras or even light fields on external factors dependent on distance from objects or other characters has shifted in proximity or modified because of time or other influences, so all of these need to be recalc'd.
- All of these things need to be multiplied by the number of player characters, because they have their own matrices of dynamic stats which may be influenced by multiple external or internal sources. I would like to allow a 20-member party, if the player wishes.
- The world will be running on its own. Creatures will have their own paths and routines, and they may be modified based on encounters with other NPCs. It's easy to update their position in their routine, but the graphics for these dynamic changes will need to be drawn if they are within camera view.
- Called scripts will need to be run either line-by-line per frame or all at once if instructed.
The work of course must be internally divided and assigned between the CPU and whatever cores it has, the GPU for graphics calculations, the audio card for audio and its effects, with a small part handled by input. But this is just runtime.
The program needs a softcodable array (much like the primitive calc fields in Diablo II 1.09+), for efficient tweaking and modding. The rows and columns (XY) can be static and unchanging (we are not adding new variables), but the Z will not, as influences on these variables would be quite dynamic. These influences would need to be culled and compressed instead of simply zeroed out, because i anticipate, MILLIONS of zeroes (everything doesnt influence everything necessarily), and every unnecessary 0 is an unnecessary variable retrieval, which eats up time and takes up RAM. Which is fine for a small program; this, however, will be bordering on Reality.
What we're looking for here is the softcoded capabilities of D2LOD, the graphics capabilities of Unreal, the ease of use in Unity, and the low-level paradigm of Machine Language, without the restrictions of static memory allocation, class membership, or type designation of C++. I don't know if PB can do it if it can't be handled in C++. Hence this exploratory post.
So, if PB can achieve cell content parsing with Maps, as shown in @mk-soft's code, this may be doable. The problem is that the example uses conditionals to determine if this varable is in a cell. What i need to do is use
whatever possible variable name is in a given cell to do a simple calculation. If the cell says "mileage", a function accessing that cell's contents will use the value of the variable mileage directly, without using if-then or select-case.