C#/JavaScript performance vs. C++ plugin performance

We want to write two modules that can be used for NPCs:

  1. A Finite State Machine that will process incoming events and then make decisions about the NPC’s behavior.

  2. A Steering Engine that will do all the math for creating various steering behaviors such as flocking, fleeing, pursuit, etc.

Our game environment calls for up to 6 or so NPC teammates for the player, and then hopefully between 10-20 NPC prey items that will act as a herd and be targeted by the player and their team. So we’re talking about around 25 avatars + player that are active in the level and having their positions and animations calculated and played back.

That’s in addition to the overall environment, which includes the Nature Pack grass.

The question is, will either of these engines benefit from being written as a C++ plugin? I understand already that C++ runs about 2x faster than JavaScript. For this application, and the number of agents we want to be active, is that difference significant? Or is it not worth the bother to do it in C++ (we have the programming capacity to do either)?

Also, I never did fully understand the answer about calling a C++ plugin from JavaScript. Is it or isn’t it possible? If not, do you have to call the pluging from C# and then the C# from JavaScript? What’s the performance hit on that?

Thanks,
Steve

I personally wouldn’t want to dabble in plugin programming for core logic. I’m in favour of using the simplest solution until it has been proven that it’s necessary to use a more complex one. :wink:

From what you’ve described, it sounds entirely reasonable as something you could do from scripting. For that number of entities, I wouldn’t expect to see a huge performance problem. However, if it’s not fast enough, you can usually optimise your scripts until it is.

One thing to consider about AI is that it doesn’t necessarily have to think once every frame. Especially for things like steering, it’s often possible to think once, then hold that decision for a few frames, or even a few seconds. This helps you to reduce the load of AI processing overall. Coroutines are quite helpful for this purpose, as they can pause for a period of time with very little overhead.

Neil, thanks a million for your assessment of scripting performance and tips to optimize the AI code. Much appreciated.

Steve