Forum

getting rid of animation macros

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

getting rid of animation macros

Postby Boss429 » Wed Oct 27, 2010 4:32 am

so I started talking about this in the 'what are you working on' thread and decided to move over to the proper forum.

I'm trying to do away with the macros by using self.frame:
Code: Select all
void() player_reload =
{
   self.frame = $relo_onehanded_1;

   while (self.frame < $relo_onehanded_31)
   {
      self.frame = self.frame + 1;
      self.nextthink = time + .033;       //30 FPS
   }
   player_walk();    //when done go back to walk
}


(This code is called once when W_Reload(); happens, not every frame)

it worked fine as a macro but now the animation doesn't play
Boss429
 
Posts: 39
Joined: Sun Dec 03, 2006 7:29 pm

Postby frag.machine » Wed Oct 27, 2010 11:17 am

You're always reseting self.frame to $relo_onehanded_1 at the start of the function. Also, you're iterating thru $relo_onehanded_1 to $relo_onehanded_31 at once, not one frame per call as required to actually see any animation.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
User avatar
frag.machine
 
Posts: 2090
Joined: Sat Nov 25, 2006 1:49 pm

Postby Boss429 » Thu Oct 28, 2010 5:59 am

But isn't the macro doing the exact same thing? it specifies an animation and then just goes into another void that specifies the next frame. Mine just does the work in one void. I guess my question is, why does a macro not play all the frames at once?
Boss429
 
Posts: 39
Joined: Sun Dec 03, 2006 7:29 pm

Postby andrewj » Thu Oct 28, 2010 8:11 am

I'm not sure I can explain it very well, but here goes:

In QuakeC you can set various things, like the model's frame, but it only has an effect when the QuakeC code has returned back to the engine and the engine redraws the screen.

So to make animations visible, you change the frame in QuakeC and set the 'nextthink' time and then return. The engine will draws the world and eventually call back into QuakeC (when that think time is reached) where you can set the next frame, and QuakeC returns and the engine redraws the world again, and will call back into QuakeC for the next frame, and so on........

Having a loop in QuakeC (like yours) doesn't work because the engine never gets a chance to redraw the screen with the updated information.
andrewj
 
Posts: 133
Joined: Mon Aug 30, 2010 3:29 pm
Location: Australia

Postby frag.machine » Thu Oct 28, 2010 11:22 am

Boss429 wrote:But isn't the macro doing the exact same thing?


No.

From the original monsters.qc:
Code: Select all
// name =[framenum,   nexttime, nextthink] {code}
// expands to:
// name ()
// {
//      self.frame=framenum;
//      self.nextthink = time + nexttime;
//      self.think = nextthink
//      <code>
// };
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
User avatar
frag.machine
 
Posts: 2090
Joined: Sat Nov 25, 2006 1:49 pm

Postby Downsider » Thu Oct 28, 2010 9:43 pm

You have to increment the animation frame every few game frames; if you use a while loop, it goes through all the animation frames in a single game frame.
User avatar
Downsider
 
Posts: 621
Joined: Tue Sep 16, 2008 1:35 am

Postby Boss429 » Fri Oct 29, 2010 3:19 am

Thanks guys, I got it working beautifully:

Code: Select all
void() player_smallreload =
{
   if ((self.frame > $relo_onehanded_31) || (self.frame < $relo_onehanded_1))
   {
      self.frame = $relo_onehanded_1; // if your not playing reload animation, start at the beging
   }

   else if (self.frame == $relo_onehanded_31)
   {
      player_walk(); //if last frame go back to player_walk
      return;
   }
   else
   {
      self.frame = self.frame + 1;
   }

   self.nextthink = time + .033;  //30FPS
   self.think = player_reload;   
}


void() player_reload =
{
   self.reloading = 1;

   if (self.weapon == IT_PISTOL || IT_UZI)
   player_smallreload();  // for single handed weapons
   else
   player_bigreload1(); // for full size weapons
};

Boss429
 
Posts: 39
Joined: Sun Dec 03, 2006 7:29 pm

Postby frag.machine » Fri Oct 29, 2010 11:24 am

Great! :D
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
User avatar
frag.machine
 
Posts: 2090
Joined: Sat Nov 25, 2006 1:49 pm

Postby OneManClan » Tue May 17, 2011 3:41 pm

When self.frame == $relo_onehanded_31, where does it get reset to $relo_onehanded_1?

Shouldn't the bit:
Code: Select all
else if (self.frame == $relo_onehanded_31)
   {
      player_walk(); //if last frame go back to player_walk
      return;
   }

be:
Code: Select all
else if (self.frame == $relo_onehanded_31)
   {
      player_walk(); //if last frame go back to player_walk
      // for the next time we reload
      self.frame = $relo_onehanded_1;
      return;
   }

?
OneManClan
 
Posts: 243
Joined: Sat Feb 28, 2009 2:38 pm


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest