A_ChangeModel

Moderator: GZDoom Developers

User avatar
Shiny Metagross
Posts: 172
Joined: Wed Apr 02, 2014 10:00 pm
Location: USA

A_ChangeModel

Post by Shiny Metagross »

Pull Request

A_ChangeModel(string modeldef, int modelindex string modelpath, string model, int skinindex, string skinpath, string skin, int flags, int generatorIndex)

This can change the modeldef, model and skins of an actor.

You can add models to an actor to render by using generatorIndex to tell your new model index to copy the behavior of another one. You may only copy the behavior of a model index already defined in your actor's current modeldef. To remove a model or skin, just pass "" in model/skin parameter to revert to the default.

Available flags:
CMDL_WEAPONTOPLAYER - If used on a weapon, this instead change's the model on the player instead.
CMDL_HIDEMODEL - Hides the specified model index from rendering. Can be used with CMDL_WEAPONTOPLAYER.
CMDL_USESURFACESKIN - skinindex instead corresponds to the number of a surface to replace it's skin.

https://drive.google.com/file/d/1iz6_BT ... sp=sharing

Here is a test file. Let me explain the various things you can do with it:
Summon SwapModelDef - This shows off dynamically swapping modeldefs
Summon SwapModels - This shows off raw dynamic model swapping
Summon SwapSkins - This shows off raw dynamic skin swapping
Summon SwapModelsAndSkins - Dynamically swaps models and skins
Summon SwapModelsEdgeCase - No modeldef is defined, will not show any models even though a model and skin is given
Summon SwapModelsEdgeCase2 - It tries to switch to hammer, but has no modeldef. Therefore, it just shows up as a pistol sprite
Summon SwapModelsEdgeCase3 - It tries to switch to hammer, but has no modeldef. Therefore, it just shows up as a pistol sprite. But 1 second later, it will also use CMDL_HideModel. This draws a model at index 0, but it won't render.
Give TriggerSwapGun - This token changes the weapon view model and player third person gun model to show off the ideal usage of CMDL_WEAPONTOPLAYER
Give TriggerSwapPlayer - This token changes the player model.
Give TriggerUnSwapPlayer - This token changes the player model back to the default. Basically just a different way to revert to default without constantly forcing it.
Take TriggerSwapModel - This token reverts the player model and weapon view model back to default. This is where the bug I mentioned occurs, but can be circumvented by just manually stating the model to revert back to.
Switch to pistol - This makes the player's gun model no longer render.
Last edited by Shiny Metagross on Sat Jul 09, 2022 12:15 am, edited 8 times in total.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 48375
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: A_ChangeModel

Post by Graf Zahl »

Sorry, but no, not like this. You are adding 132 bytes to AActor just for a feature most people won't ever use. That's plain and simply unacceptable.
User avatar
Shiny Metagross
Posts: 172
Joined: Wed Apr 02, 2014 10:00 pm
Location: USA

Re: A_ChangeModel

Post by Shiny Metagross »

I can argue that most people aren't going to use 16 indices for a model.

I've done a bit of research, and it looks like I can just use 4 indices instead (because that should be more than enough in most cases, and what the max used to be). If I'm doing my math right, then that would use 36 bytes instead. Would that be better?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 48375
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: A_ChangeModel

Post by Graf Zahl »

It would be better if this was offloaded to an external data structure. We really need to get stuff out of AActor, not more in.
User avatar
Shiny Metagross
Posts: 172
Joined: Wed Apr 02, 2014 10:00 pm
Location: USA

Re: A_ChangeModel

Post by Shiny Metagross »

I have updated the test file and submitted a commit which I hope is sufficient for dealing with the overhead.
User avatar
Major Cooke
Posts: 8094
Joined: Sun Jan 28, 2007 3:55 pm

Re: A_ChangeModel

Post by Major Cooke »

You have more to go.

If you're curious, it sounds like Graf might be asking you to do what I had done with ViewPos. I could be completely wrong here. Specifically, I created a ViewPosition class that is only initialized when SetViewPos is created.

You can see how I did that here, with some additional fixes by Graf that must be considered.

In your case though, it should be much simpler since you're not exposing anything else to ZScript so you should be able to create a class or struct for these, then just make sure they're serialized, no need to worry about IMPLEMENT_CLASS and DEFINE_FIELD_X.
User avatar
Shiny Metagross
Posts: 172
Joined: Wed Apr 02, 2014 10:00 pm
Location: USA

Re: A_ChangeModel

Post by Shiny Metagross »

I have submitted another commit to address the requested changes, and posting here for extra visibility.
User avatar
Shiny Metagross
Posts: 172
Joined: Wed Apr 02, 2014 10:00 pm
Location: USA

Re: A_ChangeModel

Post by Shiny Metagross »

Okay, I have submitted a commit handling the serialization. I've also managed to make a TArray to store Model paths/file names of models that were loaded by A_ChangeModel so that when the save file is loaded, it knows to push those back into the model array where they belong.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 48375
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: A_ChangeModel

Post by Graf Zahl »

It still emits this when compiling on Mac:

/Users/runner/work/gzdoom/gzdoom/src/playsim/p_actionfunctions.cpp:5085:27: error: cannot pass non-trivial object of type 'FString' to variadic method; expected type from format string was 'char *' [-Wnon-pod-varargs]
fullName.Format("%s%s", modelpath, model.GetChars());

Must be 'modelPath.GetChars()'
User avatar
Shiny Metagross
Posts: 172
Joined: Wed Apr 02, 2014 10:00 pm
Location: USA

Re: A_ChangeModel

Post by Shiny Metagross »

As of this comment, it would appear that all checks have passed. Additionally, I believe have once and for all snuffed out any undefined behavior.
User avatar
AFADoomer
Posts: 1275
Joined: Tue Jul 15, 2003 4:18 pm

Re: A_ChangeModel

Post by AFADoomer »

Is the test file compatible with the dev build implementation? I'm using the 26 Jul build - ge2778ba44.

The SwapModelDef and SwapSkins actors both end up invisible for me, and I've had no luck just swapping definitions or skin textures in my own tests (actor always ends up invisible unless I fully define the model path as well).

Model swaps seem to work OK, though.
User avatar
Shiny Metagross
Posts: 172
Joined: Wed Apr 02, 2014 10:00 pm
Location: USA

Re: A_ChangeModel

Post by Shiny Metagross »

AFADoomer wrote:Is the test file compatible with the dev build implementation? I'm using the 26 Jul build - ge2778ba44.

The SwapModelDef and SwapSkins actors both end up invisible for me, and I've had no luck just swapping definitions or skin textures in my own tests (actor always ends up invisible unless I fully define the model path as well).

Model swaps seem to work OK, though.
Should be fixed as of this PR

https://github.com/ZDoom/gzdoom/pull/1680

Return to “Closed Feature Suggestions [GZDoom]”