I’m always learning something new here. Sometimes I’m not sure if it’s a lua thing or an Urho thing. For context, I’m scripting with lua. I’m curious about script objects. I’ve been using them in projects for a while now, after seeing them in the samples. They seem to be very convenient. I can store data easily self.x self.health etc. I can instantiate a bunch of npcs and create a script object when I do so, and they will automatically run the NPC:Update() function, without me having to cycle through a list and do so manually. If you look at the samples, like the character sample, it’s easy to take that script object and make multiple player characters in the same manner. In fact, I did so for an online multiplayer game.
However, I’ve noticed that with large numbers (in this case, 4000) that performance is hurting from these. Maybe I’m using them wrong. I was attaching a script object to each tile in a topdown 2d game. The script object functions would handle animations of the sprites (I don’t use spriter animations) and disable the nodes at certain points and other stuff. Basically, manipulate the static sprites and check things each frame. I’m getting very bad frame rates doing this. And it’s not a matter of culling because I need certain things, like entities and items, to update offscreen and was planning on keeping this. So like 40-60 fps. For example, each water tile has a script object to handle waves and animations, grass tiles have them for certain spawn points and triggers, and so on.
I took out the script objects and tried putting each tile in a table and running:
function UpdateTiles()
for i=1,#animTiles do
animTiles[i].tile:GetComponent("StaticSprite2D").color = Color(Random(1),Random(1),Random(1),1)
end
end
Just as a test manipulation of all 4000 tiles every frame. And to my surprise the fps is 900-1200. I just always assumed the script objects were not that much different from some kind of list that runs certain functions in the program loop. I also assume Nodes are similar?
How are script objects handled in Urho? Any reason they would be slower than just cycling through a table every frame? I don’t really need a solution since the above works great for anything I’d need to do to or with a tile, just really curious why that works better.