At 9/17/21 11:02 AM, MSGhero wrote:
At 9/17/21 05:12 AM, DiskCrash wrote:
Haxe and Heaps.io
I already have a sort of scripting engine running that defines bullet logic from plain text files. Has simple mathematics support like (0.5*pi)-2 and I'm trying to use an Entity-Component-System architecture
I started writing a bullet hell lib, but I stopped before getting into heavy scripting territory. This one looks cool!
I’m also getting into ECS more. Right now I’m trying to find the library for me, as everyone has made their own it seems. The one I’m trying now seems good, so once I get my project compiling, I’ll be able to write something up about ECS and Heaps.
I should've phrased it better on my first post as I'm not making a library, but something simple for my own use. I don't know how well this'll translate to native targets but this seems to be working okay on web browsers.
I translate instructions (like "dir <angle>") to anonymous `engine.components.Programmable->Int->Void` functions (engine.components.Programmable being my custom component type) and store those functions in an array that I then traverse through the game loop. Seems to run pretty well.
For example the "dir <angle>" instruction is parsed like so
case "dir":
var angle = pNCalc.calculate();
arrayAction.push(function(prog, id) {
engine.systems.Programmable.direction(prog, id, angle);
});
and is stored in the action array that I then go through during the game loop. Then I have the function that actually executes the instruction
public static function direction(prog:engine.components.Programmable, id:Int, angle:Float){
prog.bulletAngle = angle;
next(prog, id);
}
Interpreting text instructions on each tick is very expensive and hard to maintain. Once I set up these anonymous function arrays, not only it became easier to maintain, but adding new instructions became super easy. Furthermore loops were very easy to implement.
For more info:
`pNCalc.calculate()` calculates the Polish Notation generated by the AST of mathematical expressions without variables so that during runtime the result is already pre-calculated from when it was first parsed. The `next` function calls the next instruction until it reaches the `wait`, `noop` (no operation), `halt`, or `vanish` instruction (otherwise it spirals out of control lol).
It's in no way anything fancy because I tried to make it as simple as possible without overloading my brain. But I'm still thinking of implementing function constants like how in BulletML you can pass arguments to a function that then changes the way the program sequence works. Add to that, I want to also add the loop cycle/index constant that would result in different mathematical expressions on each loop cycle. These constants would be easily pre-calculated on the initial program parsing with no performance penalty during gameplay, or so I believe. And I just remembered that I still don't have a `random()` instruction implemented (and this might actually be the hardest one to do as it can't be pre-calculated lol).
And regarding ECS, I feel like I should use a library for that. I'm still hardcoding one myself, but I feel like I might end up shooting myself in the foot in the long run. But I'll probably stick to using my own inflexible implementation lol