A function to take a snapshot of an actor's properties at a given time

Remember, just because you request it, that doesn't mean you'll get it.

Moderator: GZDoom Developers

User avatar
Jekyll Grim Payne
Global Moderator
Posts: 1109
Joined: Mon Jul 21, 2008 4:08 am
Preferred Pronouns: He/Him
Graphics Processor: nVidia (Modern GZDoom)

A function to take a snapshot of an actor's properties at a given time

Post by Jekyll Grim Payne »

I propose two functions, possible names are TakeSnapshot() and GetSnapshot(). The first one records the actors fields, flags, etc. at the moment, the second one retrieves them. Basically, like GetDefaultByType, except instead of retrieving the actor's defaults, it retrieves it from a specific point.

This is mostly a convenience thing. For example, say, an actor is temporarily modified through some kind of a controller (Powerup, Inventory, etc.) that alters a bunch of its features. Once the effect wears off, all modified fields need to be restored to the previous state (using GetDefaultByType is undesirable since they might not have been equal to their default values prior to modification). At the moment this requires creating a separate field to store each of them, which can be inconvenient when there's a dozen of them or more.
User avatar
Cherno
Posts: 1321
Joined: Tue Dec 06, 2016 11:25 am

Re: A function to take a snapshot of an actor's properties at a given time

Post by Cherno »

It would realistically be limited to properties defined in the Default block, otherwise you get the issue of having to keep track of reference type fields (like pointers to classes or actors).
User avatar
Jekyll Grim Payne
Global Moderator
Posts: 1109
Joined: Mon Jul 21, 2008 4:08 am
Preferred Pronouns: He/Him
Graphics Processor: nVidia (Modern GZDoom)

Re: A function to take a snapshot of an actor's properties at a given time

Post by Jekyll Grim Payne »

Cherno wrote: Tue May 02, 2023 1:32 pm It would realistically be limited to properties defined in the Default block, otherwise you get the issue of having to keep track of reference type fields (like pointers to classes or actors).
That's all I had in mind. The default properties, just snapshotted at a specific point.
User avatar
Zhs2
Posts: 1288
Joined: Fri Nov 07, 2008 3:29 pm
Graphics Processor: ATI/AMD with Vulkan/Metal Support
Location: Maryland, USA, but probably also in someone's mod somewhere

Re: A function to take a snapshot of an actor's properties at a given time

Post by Zhs2 »

I feel that this is a prudent moment to recommend the use of a struct, combined with appropriate take/get snapshot functions to get or set (respectively) all of the appropriate properties you would want snapshotted into struct members.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49183
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: A function to take a snapshot of an actor's properties at a given time

Post by Graf Zahl »

If you want that, you can just make your own script function to retrieve and set the data.
User avatar
Jekyll Grim Payne
Global Moderator
Posts: 1109
Joined: Mon Jul 21, 2008 4:08 am
Preferred Pronouns: He/Him
Graphics Processor: nVidia (Modern GZDoom)

Re: A function to take a snapshot of an actor's properties at a given time

Post by Jekyll Grim Payne »

Graf Zahl wrote: Sun May 07, 2023 2:19 am If you want that, you can just make your own script function to retrieve and set the data.
I'm not sure what you mean. Spawn a new instance of Actor and copy all flags and properties to it? Define a new class that has the same flags and properties? If so, that seems awfully inconvenient and non-future-proof, when new fields and flags appear.
Proydoha
Posts: 71
Joined: Thu Jan 21, 2016 2:25 am

Re: A function to take a snapshot of an actor's properties at a given time

Post by Proydoha »

Jekyll Grim Payne wrote: Tue May 02, 2023 12:47 pm I propose two functions, possible names are TakeSnapshot() and GetSnapshot(). The first one records the actors fields, flags, etc. at the moment, the second one retrieves them. Basically, like GetDefaultByType, except instead of retrieving the actor's defaults, it retrieves it from a specific point.
In my opinion instead of TakeSnapshot() and GetSnapshot() it would make more sense to be able to get list of fields defined inside of a class and to have an ability to access their values.
Kind of like GetProperties() in C#
User avatar
Jekyll Grim Payne
Global Moderator
Posts: 1109
Joined: Mon Jul 21, 2008 4:08 am
Preferred Pronouns: He/Him
Graphics Processor: nVidia (Modern GZDoom)

Re: A function to take a snapshot of an actor's properties at a given time

Post by Jekyll Grim Payne »

Proydoha wrote: Fri May 19, 2023 11:20 am In my opinion instead of TakeSnapshot() and GetSnapshot() it would make more sense to be able to get list of fields defined inside of a class and to have an ability to access their values.
Kind of like GetProperties() in C#
That's what GetDefaultByType already does.

What I want is that, except getting the values as they were at a specific moment in time (which I'd like to be able to store with a separate function), rather than reading their default values.
Proydoha
Posts: 71
Joined: Thu Jan 21, 2016 2:25 am

Re: A function to take a snapshot of an actor's properties at a given time

Post by Proydoha »

Jekyll Grim Payne wrote: Thu Jun 08, 2023 9:55 am That's what GetDefaultByType already does.
No, you misunderstood me.
I'm not talking about default values.

This is an example in C#:

Code: Select all

class DoomActor
{
    public int Radius { get; set; }
    public int Height { get; set; }
}

class Application
{
    public static void Main()
    {
        DoomActor imp = new DoomActor();
        imp.Radius = 20;
        imp.Height = 56;

        PropertyInfo[] doomActorProperties = Type.GetType("DoomActor").GetProperties();
        foreach (PropertyInfo prop in doomActorProperties)
        {
            Console.WriteLine($"{prop.Name} - {prop.GetValue(imp)}");
        }
    }
}
Then the output would be:

Code: Select all

Radius - 20
Height - 56
.net Fiddle, I hope url will last until you'll see it

As you can see with this suggested approach it would be possible to extract property name and its current (not default) value.
And then once you have list of properties of an actor you can decde to save them all or save only ones that you're interested in.

Return to “Feature Suggestions [GZDoom]”