What Would Be More Optimized?
What Would Be More Optimized?
I have this monster class that acts as a parent for different subclasses which inherit it.
All of these subclasses will executes a script that loops continuously until it dies. The script updates every tic, and it does several tasks like checking its position/velocity, collision detection, scanning for other monsters, etc. All of this is supposed to "control" the monster based on certain conditions.
With several of these monsters, everything seems fine. However, if a few hundred (or thousand) of these monsters were to be spawned on a map all at once, I worry that it may hinder performance and be problematic.
I'm trying to optimize this, so I'm wondering if I should let each monster execute their own script individually or instead have a single script that stores all the monsters' TIDs and loops through each monster and does the aforementioned tasks.
All of these subclasses will executes a script that loops continuously until it dies. The script updates every tic, and it does several tasks like checking its position/velocity, collision detection, scanning for other monsters, etc. All of this is supposed to "control" the monster based on certain conditions.
With several of these monsters, everything seems fine. However, if a few hundred (or thousand) of these monsters were to be spawned on a map all at once, I worry that it may hinder performance and be problematic.
I'm trying to optimize this, so I'm wondering if I should let each monster execute their own script individually or instead have a single script that stores all the monsters' TIDs and loops through each monster and does the aforementioned tasks.
Last edited by Kaminsky on Mon Feb 08, 2016 2:38 am, edited 1 time in total.
RE: What Would Be More Optimized?
If I were you, I'd go with the latter. Have a "master" monster control script and give each monster a unique TID, then use FOR loops to go through all those TID's and do whatever you need to do for each monster.Dr.Robotnik wrote: I'm trying to optimize this, so I'm wondering if I should let each monster execute their own script individually or instead have a single script that stores all the monsters' TIDs and loops through each monster and does the aforementioned tasks.
In the end, you'll end up with the same amount of actions being run per tic, however I feel like a single-script approach would be both cleaner and better for synchronization.
You can always use Zandronum's net traffic monitor CCMD (I forgot the exact name of it) if you're curious as to which method uses more bandwidth.
Reinforcements: midgame Survival joining/respawning
Doom64: Unabsolved: Doom64 + Diablo II
ZandroSkins: a pack made by our community
AeniPuffs: 3D blood and bullet puff effects, free to use for your own mods
Squad Radio: a WASD-based radio chat menu, add your own custom sounds!
Mercenaries (on hold)

Doom64: Unabsolved: Doom64 + Diablo II
ZandroSkins: a pack made by our community
AeniPuffs: 3D blood and bullet puff effects, free to use for your own mods
Squad Radio: a WASD-based radio chat menu, add your own custom sounds!
Mercenaries (on hold)

RE: What Would Be More Optimized?
Actually, the different TID is not completely needed. I once found a very hacky ACS trick that let me iterate actors with same TID one by one.
I don't exactly remember how, but I think I did it through setting activators and changing TID magic...
I don't exactly remember how, but I think I did it through setting activators and changing TID magic...
𝕂𝕝𝕠𝕗𝕜𝕒𝕔
- ibm5155
- Addicted to Zandronum
- Posts: 1641
- Joined: Tue Jun 05, 2012 9:32 pm
- Location: Somewhere, over the rainbow
RE: What Would Be More Optimized?
Well, the monsters are like in a node list, so, if you are going to iterate with na amount of enemies with the same tid, if you use functions like getactorx(tid), it's going to give you the tid from the first monster created over the map with the tid "tid".
maybe if you change his tid to another one and change it back to his original tid, it's going to put his node at the end of the list
maybe if you change his tid to another one and change it back to his original tid, it's going to put his node at the end of the list
Projects
Cursed Maze: DONE, V2.0
Zombie Horde - ZM09 map update: [3/15/13]
Need help with English? Then you've come to the right place!
<this post is proof of "Decline">
Cursed Maze: DONE, V2.0
Zombie Horde - ZM09 map update: [3/15/13]
Need help with English? Then you've come to the right place!
<this post is proof of "Decline">
RE: What Would Be More Optimized?
I'm thinking about using an "ID" array system in my code that all these monsters will use. There can be a "master" actor that tracks each monster's ID by using actor pointers, for instance. That way, I can reference every monster in scripts/functions using their ID rather than their TID, so it clears up any problems or conflicts in case the monsters share a specific TID on a map or something else.
That might mean I have to loop a script for every monster so they can change the master's target pointer to them at the right moment, but I don't think it should be too bad.
That might mean I have to loop a script for every monster so they can change the master's target pointer to them at the right moment, but I don't think it should be too bad.
RE: What Would Be More Optimized?
http://wiki.zandronum.com/Measuring_outbound_trafficÆnima wrote: You can always use Zandronum's net traffic monitor CCMD (I forgot the exact name of it) if you're curious as to which method uses more bandwidth.
RE: What Would Be More Optimized?
Alright, it turns out that using a single script might not work for me because there's too many actions being processed for each iteration in the loop, all of which is done in one tic, causing a runaway which terminates the script. I guess I'll have to implement my other idea to prevent any relatable issues.
- ZZYZX
- Posts a lot
- Posts: 742
- Joined: Thu Jun 07, 2012 5:56 pm
- Location: Ukraine
- Clan: A3
- Clan Tag: [A3]
RE: What Would Be More Optimized?
I've always used object-oriented approach with having separate scripts control each object, up to things like this or this (script). As far as I know this does not cause lag (CPU used = E2160, pretty ancient and bad one).
Overall, scripts have pretty small memory footprint and overhead, compared to creating/deleting actors. So DECORATE processing gotta take a lot more resources than running a script, either way. Unless you're doing really complex math a lot of times per frame in each of 1000 scripts, but not sure really. The aforementioned code doesn't lag.
The latter code spawns about 4000 objects (actors or particles) and about 1000 controlling scripts. And I should tell you that actors lag multiple times more than particles, only proving my point above that ACS by itself doesn't lag at all, not noticeably at least.
So replacing multithreaded setup with single script that manages everything simply doesn't make sense, not only it makes the code less readable and harder to maintain.
Overall, scripts have pretty small memory footprint and overhead, compared to creating/deleting actors. So DECORATE processing gotta take a lot more resources than running a script, either way. Unless you're doing really complex math a lot of times per frame in each of 1000 scripts, but not sure really. The aforementioned code doesn't lag.
The latter code spawns about 4000 objects (actors or particles) and about 1000 controlling scripts. And I should tell you that actors lag multiple times more than particles, only proving my point above that ACS by itself doesn't lag at all, not noticeably at least.
So replacing multithreaded setup with single script that manages everything simply doesn't make sense, not only it makes the code less readable and harder to maintain.
Last edited by ZZYZX on Fri Feb 05, 2016 7:54 pm, edited 1 time in total.
quality DoomExplorer hackeringFilystyn wrote:Do you know what windows.h is? It's D, DWORD.
overcomplicated ZDoom grenade
random Doom things
GZDoomBuilder-Bugfix
- SwordGrunt
- Forum Regular
- Posts: 377
- Joined: Thu Jun 07, 2012 8:43 pm
RE: What Would Be More Optimized?
It does not change much whether you use multiple scripts or loop a single one since, as someone else already mentioned, you'll end up performing the same amount of actions. What you can do is look for way to decrease the amount of functions called and/or increase the delay while keeping it reasonably accurate.
RE: What Would Be More Optimized?
Alright, so now I want to do some other things with the monsters, but rather than posting a new thread, I'll just post them here.
1. I want to be able to check which actor(s) are responsible for damaging the monster by any means. Similar to how an actor automatically assigns its target pointer to the actor that killed it, I want to be able to figure out who attacked the monster (i.e player, enemy, friendly, self). I thought about creating some hacky method involving monster infighting, but I'm not sure if that'll work efficiently. Does anyone have any other ideas?
2. I also want to be able to force monsters to use doors or lifts (or find a way to get them to do so). Naturally, they'll open doors if their target is behind it, though I would appreciate if I can get them to use them with more freedom, particularly when they're exploring a map.
1. I want to be able to check which actor(s) are responsible for damaging the monster by any means. Similar to how an actor automatically assigns its target pointer to the actor that killed it, I want to be able to figure out who attacked the monster (i.e player, enemy, friendly, self). I thought about creating some hacky method involving monster infighting, but I'm not sure if that'll work efficiently. Does anyone have any other ideas?
2. I also want to be able to force monsters to use doors or lifts (or find a way to get them to do so). Naturally, they'll open doors if their target is behind it, though I would appreciate if I can get them to use them with more freedom, particularly when they're exploring a map.
RE: What Would Be More Optimized?
1. Put an ACS_ExecuteAlways in their pain state, make it call a script that does SetActivatorToTarget. ALTHOUGH (I'm not 100% sure about this) that may not work 100% of the time. I've found that sometimes monsters don't switch targets right away for some reason.
2. Not sure. There MIGHT be a hacky way to do it with projectiles.
2. Not sure. There MIGHT be a hacky way to do it with projectiles.
Reinforcements: midgame Survival joining/respawning
Doom64: Unabsolved: Doom64 + Diablo II
ZandroSkins: a pack made by our community
AeniPuffs: 3D blood and bullet puff effects, free to use for your own mods
Squad Radio: a WASD-based radio chat menu, add your own custom sounds!
Mercenaries (on hold)

Doom64: Unabsolved: Doom64 + Diablo II
ZandroSkins: a pack made by our community
AeniPuffs: 3D blood and bullet puff effects, free to use for your own mods
Squad Radio: a WASD-based radio chat menu, add your own custom sounds!
Mercenaries (on hold)

RE: What Would Be More Optimized?
Hmm... I already tried to use projectiles to use doors and lifts; I even used a combination of actor flags including CANUSEWALLS which monsters normally inherit. However, I never got this to work.Ænima wrote: 2. Not sure. There MIGHT be a hacky way to do it with projectiles.
Last edited by Kaminsky on Mon Feb 08, 2016 3:52 am, edited 1 time in total.
RE: What Would Be More Optimized?
Did you try giving them the MONSTER flag combo and putting something like "TNT1 AAAAAAAAAAAAAAAA 0 A_Wander" in their spawn state?Dr.Robotnik wrote:Hmm... I already tried to use projectiles to use doors and lifts; I even used a combination of actor flags including CANUSEWALLS which monsters normally inherit. However, I never got this to work.Ænima wrote: 2. Not sure. There MIGHT be a hacky way to do it with projectiles.
Reinforcements: midgame Survival joining/respawning
Doom64: Unabsolved: Doom64 + Diablo II
ZandroSkins: a pack made by our community
AeniPuffs: 3D blood and bullet puff effects, free to use for your own mods
Squad Radio: a WASD-based radio chat menu, add your own custom sounds!
Mercenaries (on hold)

Doom64: Unabsolved: Doom64 + Diablo II
ZandroSkins: a pack made by our community
AeniPuffs: 3D blood and bullet puff effects, free to use for your own mods
Squad Radio: a WASD-based radio chat menu, add your own custom sounds!
Mercenaries (on hold)

-
- Retired Staff / Community Team Member
- Posts: 2569
- Joined: Sat Jun 02, 2012 2:44 am
RE: What Would Be More Optimized?
Aenima's suggestion is good, but if the monster doesn't have +QUICKTORETALIATE, his idea will not work. Perhaps you can use tidtohate in conjunction with ACS_EXECUTEALWAYS? This upcoming feature may also be of some use.1. I want to be able to check which actor(s) are responsible for damaging the monster by any means. Similar to how an actor automatically assigns its target pointer to the actor that killed it, I want to be able to figure out who attacked the monster (i.e player, enemy, friendly, self). I thought about creating some hacky method involving monster infighting, but I'm not sure if that'll work efficiently. Does anyone have any other ideas?
Unfortunately, I don't think there is a way to achieve this nicely unless you are making the maps yourself.2. I also want to be able to force monsters to use doors or lifts (or find a way to get them to do so). Naturally, they'll open doors if their target is behind it, though I would appreciate if I can get them to use them with more freedom, particularly when they're exploring a map.
Last edited by Catastrophe on Mon Feb 08, 2016 8:04 am, edited 1 time in total.
- ZZYZX
- Posts a lot
- Posts: 742
- Joined: Thu Jun 07, 2012 5:56 pm
- Location: Ukraine
- Clan: A3
- Clan Tag: [A3]
RE: What Would Be More Optimized?
I'd try modifying damaging actor to call script on projectile explosion/directly before hitscan attack, to set some global value (sent from DECORATE, like 1 for playerpawn, 2 for A_CheckFlag FRIENDLY, 3 for generic monster, 0 by default i.e. damage cause unknown). Then if monster gets damaged (alwayspain), it uses ACS and checks the value set by last exploded projectile/monster.1. I want to be able to check which actor(s) are responsible for damaging the monster by any means. Similar to how an actor automatically assigns its target pointer to the actor that killed it, I want to be able to figure out who attacked the monster (i.e player, enemy, friendly, self). I thought about creating some hacky method involving monster infighting, but I'm not sure if that'll work efficiently. Does anyone have any other ideas?
This is not possible universally, only for your own damaging actors AND your own monsters.
Spawn map spot behind door (monster look direction + 32-64 mappixels to the front). Make monster go to that spot for few tics. Call A_Chase to set new movement direction. Repeat. Not sure, but this should work because it will set monster to actually target something in front of him instead of wandering purely randomly.2. I also want to be able to force monsters to use doors or lifts (or find a way to get them to do so). Naturally, they'll open doors if their target is behind it, though I would appreciate if I can get them to use them with more freedom, particularly when they're exploring a map.
This is again not possible universally and requires own monsters.
Last edited by ZZYZX on Mon Feb 08, 2016 11:07 am, edited 1 time in total.
quality DoomExplorer hackeringFilystyn wrote:Do you know what windows.h is? It's D, DWORD.
overcomplicated ZDoom grenade
random Doom things
GZDoomBuilder-Bugfix