What Would Be More Optimized?

Discuss all aspects related to modding Zandronum here.
Post Reply
User avatar
Kaminsky
Developer
Posts: 202
Joined: Sun Apr 14, 2013 7:17 pm
Location: Canada

What Would Be More Optimized?

#1

Post by Kaminsky » Wed Feb 03, 2016 7:55 pm

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.
Last edited by Kaminsky on Mon Feb 08, 2016 2:38 am, edited 1 time in total.

User avatar
Ænima
Addicted to Zandronum
Posts: 3579
Joined: Tue Jun 05, 2012 6:12 pm

RE: What Would Be More Optimized?

#2

Post by Ænima » Wed Feb 03, 2016 9:33 pm

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.
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.

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)
Image

Klofkac
Forum Regular
Posts: 481
Joined: Sat Jun 09, 2012 1:31 pm
Location: Ask Grandvoid servers

RE: What Would Be More Optimized?

#3

Post by Klofkac » Wed Feb 03, 2016 10:06 pm

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...
𝕂𝕝𝕠𝕗𝕜𝕒𝕔

User avatar
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?

#4

Post by ibm5155 » Thu Feb 04, 2016 2:22 am

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
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">

User avatar
Kaminsky
Developer
Posts: 202
Joined: Sun Apr 14, 2013 7:17 pm
Location: Canada

RE: What Would Be More Optimized?

#5

Post by Kaminsky » Thu Feb 04, 2016 3:08 am

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.

User avatar
WaTaKiD
Master Server Admin
Posts: 128
Joined: Mon Oct 08, 2012 4:40 am
Location: USA

RE: What Would Be More Optimized?

#6

Post by WaTaKiD » Thu Feb 04, 2016 4:07 am

Æ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.
http://wiki.zandronum.com/Measuring_outbound_traffic

User avatar
Kaminsky
Developer
Posts: 202
Joined: Sun Apr 14, 2013 7:17 pm
Location: Canada

RE: What Would Be More Optimized?

#7

Post by Kaminsky » Fri Feb 05, 2016 2:52 am

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.

User avatar
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?

#8

Post by ZZYZX » Fri Feb 05, 2016 7:46 pm

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.
Last edited by ZZYZX on Fri Feb 05, 2016 7:54 pm, edited 1 time in total.

User avatar
SwordGrunt
Forum Regular
Posts: 377
Joined: Thu Jun 07, 2012 8:43 pm

RE: What Would Be More Optimized?

#9

Post by SwordGrunt » Sun Feb 07, 2016 8:09 pm

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.

User avatar
Kaminsky
Developer
Posts: 202
Joined: Sun Apr 14, 2013 7:17 pm
Location: Canada

RE: What Would Be More Optimized?

#10

Post by Kaminsky » Mon Feb 08, 2016 3:06 am

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.

User avatar
Ænima
Addicted to Zandronum
Posts: 3579
Joined: Tue Jun 05, 2012 6:12 pm

RE: What Would Be More Optimized?

#11

Post by Ænima » Mon Feb 08, 2016 3:18 am

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.
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)
Image

User avatar
Kaminsky
Developer
Posts: 202
Joined: Sun Apr 14, 2013 7:17 pm
Location: Canada

RE: What Would Be More Optimized?

#12

Post by Kaminsky » Mon Feb 08, 2016 3:52 am

Ænima wrote: 2. Not sure. There MIGHT be a hacky way to do it with projectiles.
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.
Last edited by Kaminsky on Mon Feb 08, 2016 3:52 am, edited 1 time in total.

User avatar
Ænima
Addicted to Zandronum
Posts: 3579
Joined: Tue Jun 05, 2012 6:12 pm

RE: What Would Be More Optimized?

#13

Post by Ænima » Mon Feb 08, 2016 3:57 am

Dr.Robotnik wrote:
Ænima wrote: 2. Not sure. There MIGHT be a hacky way to do it with projectiles.
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.
Did you try giving them the MONSTER flag combo and putting something like "TNT1 AAAAAAAAAAAAAAAA 0 A_Wander" in their spawn state?
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)
Image

Catastrophe
Retired Staff / Community Team Member
Posts: 2569
Joined: Sat Jun 02, 2012 2:44 am

RE: What Would Be More Optimized?

#14

Post by Catastrophe » Mon Feb 08, 2016 8:02 am

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?
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.
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.
Unfortunately, I don't think there is a way to achieve this nicely unless you are making the maps yourself.
Last edited by Catastrophe on Mon Feb 08, 2016 8:04 am, edited 1 time in total.

User avatar
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?

#15

Post by ZZYZX » Mon Feb 08, 2016 11:02 am

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?
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.

This is not possible universally, only for your own damaging actors AND your own monsters.
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.
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.

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.

Post Reply