Restructuring

Hi all,

I was thinking of why we have a heirarchial AISystem, and to be honest, the only reason I thought of, was to send messages to multiple Entities at one go.



Then I thought of the advantags of having a linear AISystem with the entities being attached directly to the AISystem.



The advantages of a linear system are mainly in the speed of getting back information from the AISystem because it doesn’t have to collapse the entity tree. It also saves up memory too by not having all those EntityNodes everywhere.



Basically, in the old system, when you wanted to obtain an entity which has a specific name, the AISystem would go through a long recursive call to see if that entity exists, and if it does, then it returns it. In the new system, its a simple call to a hashmap with the entity’s name as the key, and the actual entity as the value.



Ive implemented both, and there is a noticable speed increase. Especially when trying to obtain an Entity from a Spatial.



So which would you rather have? A linear AISystem, or a Heirarchial one?



P.S. The heirarchial AISystem is exactly 400 lines. The linear one is 214. And they both have the same functionality. Shows how simple the linear AISystem is compared to the heirarchial one.



DP

Oh yeah, you could still send messages to multiple Entities in one call. This is done by looping through an entire Node (scenegraph node, not an entity node) and obtaining entities from the spatials and sending messages.



DP

Well… I guess here’s a few things to consider:


  • Performance – Which is faster?
  • Scalability – Will there be an increasing performance hit with a linear system to the point where the hierarchial one will perform better?
  • Memory Usage – Is either one of them a hog?
  • Ease of Use – Is one significantly easier to understand, program with, and debug than another?
  • Expandability – Is one of them easier to change/add-to later on?



    That’s all I can think of off the top of my head. How do the systems measure up under those criteria? If one is clearly better in all categories, I’d say go with it. :smiley:



    If it’s not a clear winner, one possibility would be to provide both systems and let the programmer pick which one works better for him. I wouldn’t be crazy about that solution, but sometimes it’s the way to go.



    You’re the authority, though, since you wrote it. What do you think?





    –K

Performance

Well, the for Heirarchial system, its all loops through an array list. Whereas the linear system, its a simple call to a hashmap. So which is faster? I know on a small level, the linear one is. But on scalability, im not so sure. What do you think?



Scalability

See above



Memory Usage

The linear system is most definetly less of a memory hog. Thats a clear winner



Ease Of Use

Well, they are both easy to use. However, the linear one is a tiny winsy easier to use as you dont have to create any EntityNodes and worry about them.



Expandability

Thats a toughy. I guess we’l see when it comes to expand it. But i can see both systems having advantages over the other.



The performance issue with the heirarchial one can be solved to be as fast as the linear one. But with a bigger memory footprint.



DP

Ive deleted the old heirarchial system from the AI API. Because when I wanted to add the fireGlobalEvent to AISystem, it was around 10x easier to do on the linear system, and 3x faster too.



So everybody, say bye bye to EntityNode and the old AISystem :slight_smile:



DP

Bye bye! :slight_smile:



On a more serious note, this sounds like a good choice. (Sorry I didn’t respond to that effect earlier… got distracted by the other thread. :slight_smile: )





–K