Overloading Spell with MGEFs with condition functions vs. Pa

Post » Sun Nov 18, 2012 10:41 am

I'm using the "http://www.creationkit.com/Dynamically_Attaching_Scripts" style of adding scripts to actors. I have a theoretical question about speed/performance. The Spell that is applied to the Actors can be overloaded with multiple Magic Effects with condition functions to, say, apply a different effect to each race. Say you want every single race to have a different script, so in the Spell there will be a Magic Effect for the humanoid races with IsPlayableRace, or !IsCreature, etc. and then there will be a Magic Effect for Wolves, a Magic Effect for Bears, and so forth.

Before realizing this was possible, I was going to just use some scripting, a "Humanoids" array and a "Creatures" array that contain all the appropriate races, and then arrays that contain the respective Spells. I'd then get the Actor's Race position in the "RaceArray" and then grab the respective Spell using the index. This would require a Spell AND a MGEF for each race, instead of one catch-all Spell.

So my question is theoretically, which is faster? In one, the game code looks at each Actor and uses the condition functions to figure out which MGEF to apply, but if there are 50 MGEFs and the Actor has the first MGEF applied, it still goes through the other 49. Of course, you would order the Race to be checked first so that it would move on to the next immediately (If the game even checks ANDs left to right). On the other hand, you do the checking in Papyrus, by returning the respective Spell after checking the Actor's race. But this requires a few arrays, array traversal, and a bit of If/ElseIf. The Elseif tree would only be because I'd split up NPCs from creatures, to keep array size down and make it more maintainable.

Speaking of maintainability, I also wonder if overloading a Spell is just superior hands down, because a new MGEF for a new race will be able to be added in the middle of a save game, whereas if I went the Papyrus route I wouldn't be able to update the arrays and have them take effect without making a new save. Unless the MGEFs listed in a Spell also become permanently bound to a savegame too. This would let me put out support plugins for DLC or patches to support races from other mods by adding more conditional MGEFs in the spell.

Also, given the implementation of the idea, I don't even know if I could profile it. Not that I know how to profile in Papyrus, but it seems like a tremendous pain. That's why I am hoping someone has a theoretical answer. :smile:
User avatar
StunnaLiike FiiFii
 
Posts: 3373
Joined: Tue Oct 31, 2006 2:30 am

Post » Sun Nov 18, 2012 1:47 am

I would theoretically expect conditions in the creation kit to be slightly faster than papyrus scripted ones, but that's really just a guess. Maybe you could ask if someone in this thread would want to test this: http://www.gamesas.com/topic/1383987-performance-characteristics-of-papyrus-functions-and-operations/

Either way, which is the better option would imo depend on what you're doing exactly. If my assumption is correct that the conditions in creation kit would be faster, it would obviously be an advantage in a situation where good timing is needed (like for example something happening in combat), but the disadvantage would be like you said, after finding the correct magic effect it would still keep checking the others as well, which means a waste of resources. This means that if very precise timing is not required, the game does not need to react straight away and half a second more or less of delay would not matter, then papyrus would be the way to go to avoid a waste of resources.

If my assumption is wrong, and papyrus is faster, conditions would obviously have only disadvantages and papyrus would be the way to go
User avatar
Marion Geneste
 
Posts: 3566
Joined: Fri Mar 30, 2007 9:21 pm

Post » Sun Nov 18, 2012 5:44 am

It's not really an apples to apples comparison though. The Spell/MGEF overloading technique has to check each MGEF per Actor... It doesn't have the luxury of ElseIf. So even if the first MGEF applies to the Actor, it still runs through all the other MGEFs. My Papyrus technique relies on a few arrays, and array traversal. I'm more or less emulating a lookup table or a dictionary from other programming languages. I imagine that even still, that trying to apply 50 or 100 MGEFs all with condition functions is faster than traversing a few arrays of the same length to return the appropriate Spell.

Also, I realized that at the very least, I can hybridize my approach. Test if an Actor is a member of the CreatureFaction and have TWO spells, one for NPCs and one for Creatures, and each spell will be overloaded with MGEFs. That way for every Actor there is just a Faction check, then one of two spells is applied. This cuts down on the number of total MGEFs that have their condition functions tested on each Actor. Of course then I am at the mercy of what Bethesda defines as being a Creature instead of choosing myself. I would personally put Dremora's in the NPC list, not Creatures. But that's really just an organizational issue.

I guess I will just go the MGEF overloading route and once I get to the end I will know if it performs badly or not. :)
User avatar
Sheila Esmailka
 
Posts: 3404
Joined: Wed Aug 22, 2007 2:31 am


Return to V - Skyrim