Dealing with animation frames

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

Dealing with animation frames

Postby JasonX » Wed Nov 06, 2019 8:00 pm

Has anyone come up with a more elegant way of dealing with animation frames in QuakeC? I just can't take anymore of this:

Code: Select all
void() hero_stand1 =[ $0, hero_stand2 ] {};
void() hero_stand2 =[ $1, hero_stand3 ] {};
void() hero_stand3 =[ $2, hero_stand4 ] {};
void() hero_stand4 =[ $3, hero_stand5 ] {};
void() hero_stand5 =[ $4, hero_stand6 ] {};
void() hero_stand6 =[ $5, hero_stand7 ] {};
void() hero_stand7 =[ $6, hero_stand8 ] {};
void() hero_stand8 =[ $7, hero_stand9 ] {};

I tried doing a FSM, but failed miserably. Maybe some engine has any improvements to this?
Posts: 422
Joined: Tue Apr 21, 2009 2:08 pm

Re: Dealing with animation frames

Postby Spike » Wed Nov 06, 2019 11:37 pm

fte has a modelevents thing, which are basically id:string data stored at some offset into one of the animations of a model (like an iqm, but mdls can have framegroups too).
you can then just animate your entity via framegroups and just poll for model events to keep your ai's state machine running. you'd probably still need to write a few special-case functions for fancy attacks but much of the rest of the logic behind an enemy could be moved into the model's events, merging all the different monstername.qc files into a single thing, in theory.
so far its only really been used for syncing clientside footstep sounds.

alternatively there's some hexen2 syntax.
Code: Select all
void() foo = [++ $frame1 .. $frame2] =
if (cycle_wrapped) {} //animation restarted (or ended if you call some other function instead.

basically its the same as qc except using the same function for .think, but cycling between a range of frames instead of a single one (resetting to the first if the frame number was outside of that range).

fteqcc also extends the regular quakec syntax in that the frame number doesn't have to be an immediate(read: $frameN macro), but can also be a complex expression like a function call etc (you should probably use some extra brackets around it, at least if you're going to use the comma operator as part of your expression). so void() foo = [(self.frame+1), foo] {}; will work (but you should avoid letting the frames get too high...)
also note that the [frame,func] syntax is really just a helper and you can get exactly the same results by just setting .frame, .think, and .nextthink yourself. It'll take more opcodes but that's the only difference once compiled.
Its interesting to note quite how similar this stuff is to how doom's sprite animations worked... I suppose if it worked in one game then it'll work in the next, or something. quake2 has something vaguely similar, but doesn't use any special syntax as it needed to be standard C.
Posts: 2912
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Re: Dealing with animation frames

Postby JasonX » Thu Nov 07, 2019 5:12 am

Thanks for the detailed answer, Spike! That's really cool.

Spike wrote:animate your entity via framegroups

Do you have an example of how framegroups would work in Q1 models? Also, can I export framegroups using this? ... /Quake_mdl

I'm following this: ... ake-1.html
And this: ... ial/day-6/
Posts: 422
Joined: Tue Apr 21, 2009 2:08 pm

Re: Dealing with animation frames

Postby silverjoel » Thu Nov 07, 2019 9:13 pm

I did framegroups with Quake using Dark Places. Dark Places allows for external framegroups files very similar to how Quake 3 does it. I'm not sure how FTE does it. I had hoped (back when I was doing that stuff) that FTE was going to allow for external framegroups files. Not sure if that ever happened.

Here it is. ... ramegroups

I also experimented with different ways to write animation frames. I have the source somewhere. I will check later if you're interested.
Posts: 52
Joined: Thu Sep 30, 2010 6:46 am

Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest