[No] Re: A_SetDuration Code Pointer

Moderator: GZDoom Developers

Re: A_SetDuration Code Pointer

Postby HotWax » Wed Jul 01, 2009 11:19 pm

Well... That was easy.

[edit] The patch is now an attachment [/edit]

And it seems I misunderstood how ZDoom processes frames, because A_Delay actually affects its own frame and not the previous. Works like a charm:

Code: Select allExpand view
actor CrazyImp : DoomImp replaces DoomImp
{
   States
   {      
      Spawn:
         // Who says you can't have 0-tic loops!? ;)
         TROO A 0 A_Look
         TROO A 0 A_Delay(random(1, 3) * 10)
         TROO B 0 A_Look
         TROO B 0 A_Delay (random(1, 3) * 10)
         loop
      Melee:
      Missile:
         TROO EF 8 A_FaceTarget
         TROO F 0 A_Delay (random(0, 5) * 5)
         TROO G 6 A_TroopAttack  // See DoomImpBall
         TROO G 5 A_Delay (random(0, 10))
         goto See
      Pain:
         TROO H 2 A_Delay (random(0, 4))
         TROO H 2 A_Pain
         TROO H 0 A_Delay (random(0, 5) * 7)
         goto See
   }
}

// Hey, is that per-actor slow-mo I see there?!
actor MrSpeedUp : ZombieMan replaces ZombieMan
{
   States
   {
      See:
         POSS A 1 A_Chase
         POSS A 0 A_Delay(health)
         POSS B 1 A_Chase
         POSS B 0 A_Delay(health)
         POSS C 1 A_Chase
         POSS C 0 A_Delay(health)
         POSS D 1 A_Chase
         POSS D 0 A_Delay(health)
         loop
      Missile:
         POSS E 1 A_FaceTarget
         POSS E 0 A_Delay(health)
         POSS F 1 A_PosAttack
         POSS F 0 A_Delay(health)
         POSS E 1 A_Delay(health)
         goto See
      Pain:
         POSS G 1 A_Delay(health)
         POSS G 1 A_Pain
         POSS G 1 A_Delay(health)
         goto See
   }
}


Ready for move to Code Submissions.
Attachments
A_Delay.txt
(1.09 KiB) Downloaded 61 times
Last edited by HotWax on Thu Jul 02, 2009 4:01 pm, edited 1 time in total.
User avatar
HotWax
Do what you must, and pay the price later.
 
Joined: 18 Jul 2003
Location: Idaho Falls, ID

Re: A_SetDuration Code Pointer

Postby The Slimeinator » Wed Jul 01, 2009 11:37 pm

HotWax wrote:Well... That was easy.

Code: Select allExpand view
Index: src/thingdef/thingdef_codeptr.cpp
===================================================================
--- src/thingdef/thingdef_codeptr.cpp   (revision 1701)
+++ src/thingdef/thingdef_codeptr.cpp   (working copy)
@@ -2671,3 +2671,17 @@
       CheckStopped(self);
    }
 }
+
+//===========================================================================
+//
+// A_Delay
+//
+//===========================================================================
+DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_Delay)
+{
+   ACTION_PARAM_START(1);
+   ACTION_PARAM_INT(delay, 0);
+
+   if (delay > 0)
+      self->tics += delay;
+}
\ No newline at end of file
Index: wadsrc/static/actors/actor.txt
===================================================================
--- wadsrc/static/actors/actor.txt   (revision 1701)
+++ wadsrc/static/actors/actor.txt   (working copy)
@@ -245,6 +245,7 @@
    action native A_SetPitch(float pitch);
    action native A_ScaleVelocity(float scale);
    action native A_ChangeVelocity(float x = 0, float y = 0, float z = 0, int flags = 0);
+   action native A_Delay(int delay);
 
    States
    {


And it seems I misunderstood how ZDoom processes frames, because A_Delay actually affects its own frame and not the previous. Works like a charm:

Code: Select allExpand view
actor CrazyImp : DoomImp replaces DoomImp
{
   States
   {      
      Spawn:
         // Who says you can't have 0-tic loops!? ;)
         TROO A 0 A_Look
         TROO A 0 A_Delay(random(1, 3) * 10)
         TROO B 0 A_Look
         TROO B 0 A_Delay (random(1, 3) * 10)
         loop
      Melee:
      Missile:
         TROO EF 8 A_FaceTarget
         TROO F 0 A_Delay (random(0, 5) * 5)
         TROO G 6 A_TroopAttack  // See DoomImpBall
         TROO G 5 A_Delay (random(0, 10))
         goto See
      Pain:
         TROO H 2 A_Delay (random(0, 4))
         TROO H 2 A_Pain
         TROO H 0 A_Delay (random(0, 5) * 7)
         goto See
   }
}

// Hey, is that per-actor slow-mo I see there?!
actor MrSpeedUp : ZombieMan replaces ZombieMan
{
   States
   {
      See:
         POSS A 1 A_Chase
         POSS A 0 A_Delay(health)
         POSS B 1 A_Chase
         POSS B 0 A_Delay(health)
         POSS C 1 A_Chase
         POSS C 0 A_Delay(health)
         POSS D 1 A_Chase
         POSS D 0 A_Delay(health)
         loop
      Missile:
         POSS E 1 A_FaceTarget
         POSS E 0 A_Delay(health)
         POSS F 1 A_PosAttack
         POSS F 0 A_Delay(health)
         POSS E 1 A_Delay(health)
         goto See
      Pain:
         POSS G 1 A_Delay(health)
         POSS G 1 A_Pain
         POSS G 1 A_Delay(health)
         goto See
   }
}


Ready for move to Code Submissions.


Thanks for the patch.
User avatar
The Slimeinator
 
Joined: 26 Jun 2009

A_SetDuration Code Pointer

Postby bagheadspidey » Thu Jul 02, 2009 1:28 am

Nice one. I support this. Haven't tried it yet, but do bad things happen if you put delays in the pickup or use states of a CustomInventory?
User avatar
bagheadspidey
 
Joined: 20 Oct 2007

Re: A_SetDuration Code Pointer

Postby Nash » Thu Jul 02, 2009 2:59 am

Could this be used to dynamically alter a weapon's animation speed?

In my RPG-ish mod thingy, I want the player's melee attack speed to be based on how much strength (an inventory item) he has. A weak fighter will have some trouble swinging a heavy axe, while a strong fighter will be able to swing it around like it's a piece of light wood.
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes
Operating System: Windows 10/8.1/8 64-bit
Graphics Processor: nVidia GTX or Quadro with Vulkan support

Re: A_SetDuration Code Pointer

Postby Rachael » Thu Jul 02, 2009 3:34 am

Merging into community build (though I see no reason why this won't be merged, anyway)
User avatar
Rachael
Webmaster
 
Joined: 13 Jan 2004
Discord: Rachael#3767
Twitch ID: madamerachelle
Github ID: madame-rachelle

Re: A_SetDuration Code Pointer

Postby Gez » Thu Jul 02, 2009 4:13 am

bagheadspidey wrote:do bad things happen if you put delays in the pickup or use states of a CustomInventory?

Very important point.
Gez
 
 
 
Joined: 06 Jul 2007

Re: A_SetDuration Code Pointer

Postby Rachael » Thu Jul 02, 2009 4:26 am

Gez wrote:
bagheadspidey wrote:do bad things happen if you put delays in the pickup or use states of a CustomInventory?

Very important point.

This can be tested now.

http://svn.drdteam.org/community/zdoom- ... r1701M.zip
User avatar
Rachael
Webmaster
 
Joined: 13 Jan 2004
Discord: Rachael#3767
Twitch ID: madamerachelle
Github ID: madame-rachelle

Re: A_SetDuration Code Pointer

Postby bagheadspidey » Thu Jul 02, 2009 8:44 am

Hmm, overall it's pretty benign. This code creates a weird situation:

Code: Select allExpand view
actor shit CustomInventory 
{  
  
States
  
{  
  
Pickup:
     
// TNT1 A 0 ThrustThing(angle*256/360, 1, 0, 0)
     
TNT1 A 0 A_ChangeVelocity(01.0)
     
TNT1 A 0 A_Delay(1)
  }


For some reason it only happens with ChangeVelocity, not ThrustThing, but leaving any delay in there will cause the player to instantly "teleport" as far as he can until he hits a wall upon getting this item. If A_Delay is commented out, the player just gets a little nudge.

Anyway, it's the only adverse effect I've seen, and it's not too bad. What I can't seem to figure out is why this affects ChangeVelocity but not ThrustThing?
User avatar
bagheadspidey
 
Joined: 20 Oct 2007

Re: A_SetDuration Code Pointer

Postby HotWax » Thu Jul 02, 2009 3:39 pm

Thanks for your testing on this. I'm not very practiced in Decorate and I suspected there were going to be some weird uses that could screw things up, but I couldn't think of any.

Do you think this needs to be resolved in code or is more something the author should need to be aware of? I'd rather put power into the modder's hands than to artifically take it away to avoid mis-use, but if needed I could probably have the function refuse to run on certain class types.

Also if you can find any other ways to screw things up with it, let me know. Crashes or game hangs would be the biggest issues, obviously. Right now the only thing I can think of is somebody unintentionally generating a 0-tic loop by misusing the expression evaluator. Don't think there's anything I can do about that, though.
User avatar
HotWax
Do what you must, and pay the price later.
 
Joined: 18 Jul 2003
Location: Idaho Falls, ID

Re: A_SetDuration Code Pointer

Postby Enjay » Thu Jul 02, 2009 3:47 pm

Can I ask what the advantage is for this pointer? Is it just that it makes random durations possible or is there something else? If it is just random durations, then would it not have been better to simply* have random durations.

*The author of this post has no idea how "simple" adding random durations would be nor, for that matter, if they are even possible.
User avatar
Enjay
Everyone is a moon, and has a dark side which he never shows to anybody. Twain
 
 
 
Joined: 15 Jul 2003
Location: Scotland

Re: A_SetDuration Code Pointer

Postby Rachael » Thu Jul 02, 2009 3:49 pm

I think HotWax's solution is actually the simplest, without requiring any rewrites of code - it's also easy to use.
User avatar
Rachael
Webmaster
 
Joined: 13 Jan 2004
Discord: Rachael#3767
Twitch ID: madamerachelle
Github ID: madame-rachelle

Re: A_SetDuration Code Pointer

Postby Enjay » Thu Jul 02, 2009 3:50 pm

Easier than:

TROO A (random (1,6)) A_Look

Or similar :?:
User avatar
Enjay
Everyone is a moon, and has a dark side which he never shows to anybody. Twain
 
 
 
Joined: 15 Jul 2003
Location: Scotland

Re: A_SetDuration Code Pointer

Postby Nash » Thu Jul 02, 2009 3:51 pm

As I've asked in my previous post, I think the advantage of this is that frames can have their durations altered dynamically in-game...

Here are some uses I can think of:

1) Monsters that move slower the less health it has.
2) Weapon attacks (mainly useful for melee-style weapons) that can be sped up or down depending on certain conditions.
3) Randomized durations for that extra randomness (useful for stuff like particle effects and explosions).

EDIT: Enjay, I don't think that piece of DECORATE snippet works... ?
Last edited by Nash on Thu Jul 02, 2009 3:52 pm, edited 1 time in total.
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes
Operating System: Windows 10/8.1/8 64-bit
Graphics Processor: nVidia GTX or Quadro with Vulkan support

Re: A_SetDuration Code Pointer

Postby The Slimeinator » Thu Jul 02, 2009 3:52 pm

@Enjay: That won't work. This feature request came from an old feature request that requested that method. Graf said that couldn't work. Thus, A_Delay instead.
User avatar
The Slimeinator
 
Joined: 26 Jun 2009

Re: A_SetDuration Code Pointer

Postby Rachael » Thu Jul 02, 2009 3:52 pm

Enjay wrote:Easier than:

TROO A (random (1,6)) A_Look

Or similar :?:

That's another thing - you're kinda screwing with the format of DECORATE. If that's already possible, then consider my last 2 statements null and void. If not, you'd have to add in a lot of spaces between durations and code pointers if you want to line up your code properly. And the more spacing you do with code, the more it goes off the edge of the editor, and the more of a pain in the butt it is to maintain.
User avatar
Rachael
Webmaster
 
Joined: 13 Jan 2004
Discord: Rachael#3767
Twitch ID: madamerachelle
Github ID: madame-rachelle

Next

Return to Closed Feature Suggestions

Who is online

Users browsing this forum: Semrush [Bot] and 0 guests