Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  
Gamer With Dignity

[DECORATE] Is there a better way of doing this?

Recommended Posts

actor PistolBullet : FastProjectile
{
  Radius 1
  Height 1
  Speed 1
  +NOEXTREMEDEATH
  +SKYEXPLODE
  PROJECTILE

  Scale 0.3
  Damage 3
  RenderStyle Add
  MissileHeight 8
  Alpha 0.0

  States
  {
  Spawn:
	TNT1 A 0
	Goto Draw
  Draw:
  	TNT1 A 0 A_SpawnItemEx("PistolBulletTrail1",0,0,0,cos(pitch)*100,0,sin(-pitch)*100,0,
             SXF_ORIGINATOR      |
             SXF_SETMASTER       |
             SXF_TRANSFERPITCH   |
             SXF_NOCHECKPOSITION )
	TNT1 A 0 A_SpawnItemEx("PistolBulletTrail2",0,0,0,cos(pitch)*100,0,sin(-pitch)*100,0,
             SXF_ORIGINATOR      |
             SXF_SETMASTER       |
             SXF_TRANSFERPITCH   |
             SXF_NOCHECKPOSITION )
	TNT1 A 0 A_JumpIf(pitch > 360, "Pitch0")
	TNT1 A 0 A_JumpIf(pitch > 355, "PitchUp10")
	TNT1 A 0 A_JumpIf(pitch > 345, "PitchUp20")
	TNT1 A 0 A_JumpIf(pitch > 335, "PitchUp30")
	TNT1 A 0 A_JumpIf(pitch > 325, "PitchUp40")
	TNT1 A 0 A_JumpIf(pitch > 315, "PitchUp50")
	TNT1 A 0 A_JumpIf(pitch > 305, "PitchUp60")
	TNT1 A 0 A_JumpIf(pitch > 295, "PitchUp70")
	TNT1 A 0 A_JumpIf(pitch > 285, "PitchUp80")
	TNT1 A 0 A_JumpIf(pitch > 275, "PitchUp90")
	TNT1 A 0 A_JumpIf(pitch > 85, "PitchDn90")
	TNT1 A 0 A_JumpIf(pitch > 75, "PitchDn80")
	TNT1 A 0 A_JumpIf(pitch > 65, "PitchDn70")
	TNT1 A 0 A_JumpIf(pitch > 55, "PitchDn60")
	TNT1 A 0 A_JumpIf(pitch > 45, "PitchDn50")
	TNT1 A 0 A_JumpIf(pitch > 35, "PitchDn40")
	TNT1 A 0 A_JumpIf(pitch > 25, "PitchDn30")
	TNT1 A 0 A_JumpIf(pitch > 15, "PitchDn20")
	TNT1 A 0 A_JumpIf(pitch > 5,  "PitchDn10")
	TNT1 A 0 A_Jump(256, "Pitch0")
  PitchUp90:
    XTR1 A 1 Bright A_FadeTo(0.9, 0.1)
	loop
  PitchUp80:
    XTR1 B 1 Bright A_FadeTo(0.9, 0.1)
	loop
  PitchUp70:
    XTR1 C 1 Bright A_FadeTo(0.9, 0.1)
	loop
  PitchUp60:
    XTR1 D 1 Bright A_FadeTo(0.9, 0.1)
	loop
  PitchUp50:
    XTR1 E 1 Bright A_FadeTo(0.9, 0.1)
	loop
  PitchUp40:
    XTR1 F 1 Bright A_FadeTo(0.9, 0.1)
	loop
  PitchUp30:
    XTR1 G 1 Bright A_FadeTo(0.9, 0.1)
	loop
  PitchUp20:
    XTR1 H 1 Bright A_FadeTo(0.9, 0.1)
	loop
  PitchUp10:
    XTR1 I 1 Bright A_FadeTo(0.9, 0.1)
	loop
  Pitch0:
    XTR1 J 1 Bright A_FadeTo(0.9, 0.1)
	loop
  PitchDn10:
    XTR1 K 1 Bright A_FadeTo(0.9, 0.1)
	loop
  PitchDn20:
    XTR1 L 1 Bright A_FadeTo(0.9, 0.1)
	loop
  PitchDn30:
    XTR1 M 1 Bright A_FadeTo(0.9, 0.1)
	loop
  PitchDn40:
    XTR1 N 1 Bright A_FadeTo(0.9, 0.1)
	loop
  PitchDn50:
    XTR1 O 1 Bright A_FadeTo(0.9, 0.1)
	loop
  PitchDn60:
    XTR1 P 1 Bright A_FadeTo(0.9, 0.1)
	loop
  PitchDn70:
    XTR1 Q 1 Bright A_FadeTo(0.9, 0.1)
	loop
  PitchDn80:
    XTR1 R 1 Bright A_FadeTo(0.9, 0.1)
	loop
  PitchDn90:
    XTR1 S 1 Bright A_FadeTo(0.9, 0.1)
	loop
  Death:
	TNT1 A 0 A_SpawnItemEx("BulletPuff", 0, 0, 0, 0, 0, 0)
        XTR1 A 0 A_RemoveChildren(True, RMVF_MISSILES)
	TNT1 A 0 A_SpawnItemEx("PistolBulletFade1")
	TNT1 A 1 A_SpawnItemEx("PistolBulletFade2")
    Stop
  }
}
Basically, PistolBullet is a fast bullet projectile that is being rendered with voxel models. There are 19 different models, XTR1 A-S, which correspond to different pitches of the bullet, from 90 degrees up to 90 degrees down. The pitch of the bullet is set from within a spawn function in ACS.

Is there a better way of doing this? Something that's not so damn ugly? Is there some way I can define which model to use, in an ACS script perhaps, so that all I have to do in decorate is tell the bullet to draw itself?

Share this post


Link to post

That doesn't look ugly to me. It is definitely not sloppy. If this code works as intended, I think you're set to go. I don't know much about ACS, but I suspect that if you went that route, you would just be moving the "ugly" from DECORATE to ACS.

Share this post


Link to post
Empyre said:

That doesn't look ugly to me. It is definitely not sloppy.

A multitude of similarly-looking conditional jumps and blocks of code, all of which basically do the very same thing, just each one using a different parameter value, is something that programmers consider to be very ugly and sloppy.

I suggest to take advantage of the special sprite name "#" to reduce the block of states with "A_FadeTo" into a single state "XTR1 #" and change the frame letters in each state with "A_JumpIf" to a respective frame letter A-S while making them all jump into that single state. Unfortunately, I can't think of how to get rid of the multitude of conditional jumps.

Share this post


Link to post
scifista42 said:

A multitude of similarly-looking conditional jumps and blocks of code, all of which basically do the very same thing, just each one using a different parameter value, is something that programmers consider to be very ugly and sloppy.

I suggest to take advantage of the special sprite name "#" to reduce the block of states with "A_FadeTo" into a single state "XTR1 #" and change the frame letters in each state with "A_JumpIf" to a respective frame letter A-S while making them all jump into that single state. Unfortunately, I can't think of how to get rid of the multitude of conditional jumps.

Thanks this is exactly what I was looking for.

I was thinking that instead of conditionals I could use a modified pitch value as the offset in a jump statement.

This won't decrease the number of lines of code, since it still has to jump to a line that indicates which frame it should use. But I think it will improve performance, maybe?

Now that I think about it, is there any way to resolve an int to a char directly and then use that as the model's frame suffix?

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×