Which is the best way to manage the time and real-time events ?
I am implementing a small multiplayer RPG game with Node.js. I have many NPCs and each move every 3 or 4 seconds, so i need to update them.
Solution A:
use one setTimeout
per NPC. if i have hundreds NPCs, i will create as timers.
It's more simpler but is it not less efficient ?
Solution B:
use one setTimeout
for all NPCs. Each time, we call the next timeout by computing the the most small remaining time before a NPC move.
So we must use a more complexe code, but we have only one setTimeout
.
Has it betters/others way ?