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.
A function to take a snapshot of an actor's properties at a given time
Moderator: GZDoom Developers
-
- Global Moderator
- Posts: 1109
- Joined: Mon Jul 21, 2008 4:08 am
- Preferred Pronouns: He/Him
- Graphics Processor: nVidia (Modern GZDoom)
-
- 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
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).
-
- 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
That's all I had in mind. The default properties, just snapshotted at a specific point.
-
- 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
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.
-
- 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
If you want that, you can just make your own script function to retrieve and set the data.
-
- 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
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.
-
- 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
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.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.
Kind of like GetProperties() in C#
-
- 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
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.
-
- 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
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)}");
}
}
}
Code: Select all
Radius - 20
Height - 56
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.