Page 1 of 1

Move BeginPlay() to Thinkers

Posted: Fri Oct 27, 2017 8:41 am
by Major Cooke
Since ChangeStatNum can only be applied in BeginPlay, I think it would be logical to move the BeginPlay() function from inside of Actor to Thinker.

Re: Move BeginPlay() to Thinkers

Posted: Fri Oct 27, 2017 9:02 am
by Graf Zahl
This cannot be done and is not needed. The main problem with actors is that they are not constructed by your own code but by an internal actor factory (i.e Actor.Spawn.) BeginPlay is merely a callback in there that allows you to perform some customization which under normal circumstances would happen in the constructor.

Unless you do not build your own thinker creation factory the place to change the statnum is your thinker's constructor.

If you want to change the statnum of a system created thinker, think again. Not a good idea!

Re: Move BeginPlay() to Thinkers

Posted: Fri Oct 27, 2017 11:33 am
by Major Cooke
Graf Zahl wrote:This cannot be done and is not needed. The main problem with actors is that they are not constructed by your own code but by an internal actor factory (i.e Actor.Spawn.) BeginPlay is merely a callback in there that allows you to perform some customization which under normal circumstances would happen in the constructor.

Unless you do not build your own thinker creation factory the place to change the statnum is your thinker's constructor.
Oh, so you mean this?

Code: Select all

MyThinker t = new("MyThinker");
t.ChangeStatNum(STAT_USER);
That seems to work. Very well, I suppose I can just have a global class statically do that for me.
Graf Zahl wrote:If you want to change the statnum of a system created thinker, think again. Not a good idea!
You mean like ACS/Map thinkers? I have no intention of doing such a thing. I just meant for hand-made thinkers created via ZScript with the "new" function. And setting things like SFX actors onto a different statnum so actors that do a lot of stat searching can have their workloads minimized. Helps hugely with the changes I made with (i.e.) AEons of Death so gibs can stop lagging upon creation, because it gets a count of how many gibs are currently around and doesn't spawn anymore if there are too many. As you know, AEoD can get clusterfucky with with so many special effects going on and actors that shouldn't be bothered searching for anything other than gibs, by gibs alone.

That's about as far as I go, just for the sake of optimizing gameplay and making it far more efficient.

Re: Move BeginPlay() to Thinkers

Posted: Fri Oct 27, 2017 12:32 pm
by Graf Zahl
Major Cooke wrote: That seems to work. Very well, I suppose I can just have a global class statically do that for me.
Well, what do you think how this works for actors? You'll never see them created with 'new'. Instead there's a static function to spawn them - and it's this function that calls BeginPlay. If you create a thinker with new and then initialize it, it's your own code that performs the setup so no facility in the engine can call BeginPlay.