Esempio n. 1
0
void ANIM_Set(AnimLayer & layer, ANIM_HANDLE *anim)
{
	if(!anim)
		return;

	layer.cur_anim = anim;
	layer.altidx_cur = ANIM_GetAltIdx(anim, layer.altidx_cur);

	if(layer.altidx_cur > layer.cur_anim->alt_nb)
		layer.altidx_cur = 0;

	layer.ctime = AnimationDuration_ZERO;
	layer.lastframe = -1;
	layer.flags &= ~EA_PAUSED;
	layer.flags &= ~EA_ANIMEND;
	layer.flags &= ~EA_LOOP;
	layer.flags &= ~EA_FORCEPLAY;
}
Esempio n. 2
0
void ANIM_Set(ANIM_USE *au, ANIM_HANDLE *anim)
{
	if(!au || !anim)
		return;

	au->cur_anim = anim;
	au->altidx_cur = ANIM_GetAltIdx(anim, au->altidx_cur);

	if(au->altidx_cur > au->cur_anim->alt_nb)
		au->altidx_cur = 0;

	au->ctime = 0;
	au->lastframe = -1;
	au->flags &= ~EA_PAUSED;
	au->flags &= ~EA_ANIMEND;
	au->flags &= ~EA_LOOP;
	au->flags &= ~EA_FORCEPLAY;
}
Esempio n. 3
0
/*!
 * \brief Main Procedure to draw an animated object
 *
 * \param eobj main object data
 * \param eanim Animation data
 * \param time Time increment to current animation in Ms
 * \param io Referrence to Interactive Object (NULL if no IO)
 */
void PrepareAnim(AnimLayer & layer, AnimationDuration time, Entity *io) {

	if(layer.flags & EA_PAUSED)
		time = AnimationDuration_ZERO;

	if(io && (io->ioflags & IO_FREEZESCRIPT))
		time = AnimationDuration_ZERO;

	if(layer.altidx_cur >= layer.cur_anim->alt_nb)
		layer.altidx_cur = 0;

	if(!(layer.flags & EA_EXCONTROL))
		layer.ctime += time;

	layer.flags &= ~EA_ANIMEND;

	AnimationDuration animTime = layer.cur_anim->anims[layer.altidx_cur]->anim_time;
	
	if(layer.ctime > animTime) {
	
		if(layer.flags & EA_STOPEND) {
			layer.ctime = animTime;
		}
		
		AnimationDuration lost = layer.ctime - animTime;
		
		if((layer.flags & EA_LOOP)
		   || (io && ((layer.cur_anim == io->anims[ANIM_WALK])
					  || (layer.cur_anim == io->anims[ANIM_WALK2])
					  || (layer.cur_anim == io->anims[ANIM_WALK3])
					  || (layer.cur_anim == io->anims[ANIM_RUN])
					  || (layer.cur_anim == io->anims[ANIM_RUN2])
					  || (layer.cur_anim == io->anims[ANIM_RUN3])))
		) {
				if(!layer.next_anim) {
					layer.ctime = AnimationDuration(layer.ctime.t % animTime.t);
	
					if(io)
						FinishAnim(io, layer.cur_anim);
				} else {
					if(io) {
						FinishAnim(io, layer.cur_anim);
						
						if(io->animBlend.lastanimtime != ArxInstant_ZERO)
							AcquireLastAnim(io);
						else
							io->animBlend.lastanimtime = ArxInstantMs(1);
					}
					
					layer.cur_anim = layer.next_anim;
					layer.altidx_cur = ANIM_GetAltIdx(layer.next_anim, layer.altidx_cur);
					layer.next_anim = NULL;
					ResetAnim(layer);
					layer.ctime = lost;
					layer.flags = layer.nextflags;
					layer.flags &= ~EA_ANIMEND;
				}
		} else {
			if(io && layer.next_anim) {
					FinishAnim(io, layer.cur_anim);
					
					if (io->animBlend.lastanimtime != ArxInstant_ZERO)
						AcquireLastAnim(io);
					else
						io->animBlend.lastanimtime = ArxInstant(1);
					
					layer.cur_anim = layer.next_anim;
					layer.altidx_cur = ANIM_GetAltIdx(layer.next_anim, layer.altidx_cur);
					layer.next_anim = NULL;
					ResetAnim(layer);
					layer.ctime = lost;
					layer.flags = layer.nextflags;
					layer.flags &= ~EA_ANIMEND;
			} else {
				layer.flags |= EA_ANIMEND;
				layer.ctime = layer.cur_anim->anims[layer.altidx_cur]->anim_time;
			}
		}
	
	}
	
	if (!layer.cur_anim)
		return;

	AnimationDuration tim;
	if(layer.flags & EA_REVERSE)
		tim = animTime - layer.ctime;
	else
		tim = layer.ctime;
	
	EERIE_ANIM * anim = layer.cur_anim->anims[layer.altidx_cur];
	
	layer.currentFrame = anim->nb_key_frames - 2;
	layer.currentInterpolation = 1.f;
	
	for(long i = 1; i < anim->nb_key_frames; i++) {
		AnimationDuration tcf = anim->frames[i - 1].time;
		AnimationDuration tnf = anim->frames[i].time;

		if(tcf == tnf)
			return;

		if((tim < tnf && tim >= tcf) || (i == anim->nb_key_frames - 1 && tim == tnf)) {
			long fr = i - 1;
			tim -= tcf;
			float pour = toMsf(tim) / toMsf(tnf - tcf);
			
			// Frame Sound Management
			if(!(layer.flags & EA_ANIMEND)
			   && time != AnimationDuration_ZERO
			   && (anim->frames[fr].sample != -1)
			   && (layer.lastframe != fr)) {

				Vec3f * position = io ? &io->pos : NULL;
				
				if(layer.lastframe < fr && layer.lastframe != -1) {
					for(long n = layer.lastframe + 1; n <= fr; n++)
						ARX_SOUND_PlayAnim(anim->frames[n].sample, position);
				} else {
					ARX_SOUND_PlayAnim(anim->frames[fr].sample, position);
				}
			}

			// Frame Flags Management
			if(!(layer.flags & EA_ANIMEND)
			   && time != AnimationDuration_ZERO
			   && (anim->frames[fr].stepSound)
			   && (layer.lastframe != fr)) {
				
				if(io && io != entities.player()) {
					if(layer.lastframe < fr && layer.lastframe != -1) {
						for(long n = layer.lastframe + 1; n <= fr; n++) {
							if(anim->frames[n].stepSound)
								ARX_NPC_NeedStepSound(io, io->pos);
						}
					}
					else if(anim->frames[fr].stepSound)
						ARX_NPC_NeedStepSound(io, io->pos);
				}
			}
			
			// Memorize this frame as lastframe.
			layer.lastframe = fr;
			layer.currentFrame = fr;
			layer.currentInterpolation = pour;
			break;
		}
	}
}
Esempio n. 4
0
/*!
 * \brief Main Procedure to draw an animated object
 *
 * \param eobj main object data
 * \param eanim Animation data
 * \param time Time increment to current animation in Ms
 * \param io Referrence to Interactive Object (NULL if no IO)
 */
void PrepareAnim(AnimLayer & layer, unsigned long time, Entity *io) {

	if(layer.flags & EA_PAUSED)
		time = 0;

	if(io && (io->ioflags & IO_FREEZESCRIPT))
		time = 0;

	if(layer.altidx_cur >= layer.cur_anim->alt_nb)
		layer.altidx_cur = 0;

	if(!(layer.flags & EA_EXCONTROL))
		layer.ctime += time;

	layer.flags &= ~EA_ANIMEND;

	const long animTime = layer.cur_anim->anims[layer.altidx_cur]->anim_time;
	
	if(layer.ctime > animTime) {
	
		if(layer.flags & EA_STOPEND) {
			layer.ctime = animTime;
		}
		
		long lost = layer.ctime - animTime;
		
		if((layer.flags & EA_LOOP)
		   || (io && ((layer.cur_anim == io->anims[ANIM_WALK])
					  || (layer.cur_anim == io->anims[ANIM_WALK2])
					  || (layer.cur_anim == io->anims[ANIM_WALK3])
					  || (layer.cur_anim == io->anims[ANIM_RUN])
					  || (layer.cur_anim == io->anims[ANIM_RUN2])
					  || (layer.cur_anim == io->anims[ANIM_RUN3])))
		) {
				if(!layer.next_anim) {
					long t = animTime;
					layer.ctime= layer.ctime % t;
	
					if(io)
						FinishAnim(io,layer.cur_anim);
				} else {
					if(io) {
						FinishAnim(io,layer.cur_anim);
						
						if(io->animBlend.lastanimtime != 0)
							AcquireLastAnim(io);
						else
							io->animBlend.lastanimtime = 1;
					}
					
					layer.cur_anim=layer.next_anim;
					layer.altidx_cur=ANIM_GetAltIdx(layer.next_anim,layer.altidx_cur);
					layer.next_anim=NULL;
					ResetAnim(layer);
					layer.ctime = lost;
					layer.flags=layer.nextflags;
					layer.flags&=~EA_ANIMEND;
				}
		} else {
			if(io && layer.next_anim) {
					FinishAnim(io,layer.cur_anim);
					
					if (io->animBlend.lastanimtime!=0)
						AcquireLastAnim(io);
					else
						io->animBlend.lastanimtime=1;
					
					layer.cur_anim=layer.next_anim;
					layer.altidx_cur=ANIM_GetAltIdx(layer.next_anim,layer.altidx_cur);
					layer.next_anim=NULL;
					ResetAnim(layer);
					layer.ctime = lost;
					layer.flags=layer.nextflags;
					layer.flags&=~EA_ANIMEND;
			} else {
				layer.flags |= EA_ANIMEND;
				layer.ctime = layer.cur_anim->anims[layer.altidx_cur]->anim_time;
			}
		}
	
	}
	
	if (!layer.cur_anim)
		return;

	long tim;
	if(layer.flags & EA_REVERSE)
		tim = animTime - layer.ctime;
	else
		tim = layer.ctime;
	
	EERIE_ANIM * anim = layer.cur_anim->anims[layer.altidx_cur];
	
	layer.fr = anim->nb_key_frames - 2;
	layer.pour = 1.f;
	
	for(long i = 1; i < anim->nb_key_frames; i++) {
		long tcf = (long)anim->frames[i - 1].time;
		long tnf = (long)anim->frames[i].time;

		if(tcf == tnf)
			return;

		if((tim < tnf && tim >= tcf) || (i == anim->nb_key_frames - 1 && tim == tnf)) {
			long fr = i - 1;
			tim -= tcf;
			float pour = (float)((float)tim/((float)tnf-(float)tcf));
			
			// Frame Sound Management
			if(!(layer.flags & EA_ANIMEND) && time
			   && (anim->frames[fr].sample != -1)
			   && (layer.lastframe != fr)) {

				Vec3f * position = io ? &io->pos : NULL;
				
				if(layer.lastframe < fr && layer.lastframe != -1) {
					for(long n = layer.lastframe + 1; n <= fr; n++)
						ARX_SOUND_PlayAnim(anim->frames[n].sample, position);
				} else {
					ARX_SOUND_PlayAnim(anim->frames[fr].sample, position);
				}
			}

			// Frame Flags Management
			if(!(layer.flags & EA_ANIMEND) && time
			   && (anim->frames[fr].flag > 0)
			   && (layer.lastframe != fr)) {
				
				if(io && io != entities.player()) {
					if(layer.lastframe < fr && layer.lastframe != -1) {
						for(long n = layer.lastframe + 1; n <= fr; n++) {
							if(anim->frames[n].flag == 9)
								ARX_NPC_NeedStepSound(io, io->pos);
						}
					}
					else if(anim->frames[fr].flag == 9)
						ARX_NPC_NeedStepSound(io, io->pos);
				}
			}
			
			// Memorize this frame as lastframe.
			layer.lastframe = fr;
			layer.fr = fr;
			layer.pour = pour;
			break;
		}
	}
}
Esempio n. 5
0
/*!
 * \brief Main Procedure to draw an animated object
 *
 * \param eobj main object data
 * \param eanim Animation data
 * \param time Time increment to current animation in Ms
 * \param io Referrence to Interactive Object (NULL if no IO)
 */
void PrepareAnim(ANIM_USE *eanim, unsigned long time, Entity *io) {
	
	if(!eanim)
		return;

	if(eanim->flags & EA_PAUSED)
		time = 0;

	if(io && (io->ioflags & IO_FREEZESCRIPT))
		time = 0;

	if(eanim->altidx_cur >= eanim->cur_anim->alt_nb)
		eanim->altidx_cur = 0;

	if(!(eanim->flags & EA_EXCONTROL))
		eanim->ctime += time;

	eanim->flags &= ~EA_ANIMEND;

	if((eanim->flags & EA_STOPEND) && eanim->ctime > eanim->cur_anim->anims[eanim->altidx_cur]->anim_time)
	{
		eanim->ctime = eanim->cur_anim->anims[eanim->altidx_cur]->anim_time;
	}

	if((eanim->flags & EA_LOOP)
	   || (io && ((eanim->cur_anim == io->anims[ANIM_WALK])
	              || (eanim->cur_anim == io->anims[ANIM_WALK2])
	              || (eanim->cur_anim == io->anims[ANIM_WALK3])
				  || (eanim->cur_anim == io->anims[ANIM_RUN])
				  || (eanim->cur_anim == io->anims[ANIM_RUN2])
				  || (eanim->cur_anim == io->anims[ANIM_RUN3])))) {
		
		if(eanim->ctime > eanim->cur_anim->anims[eanim->altidx_cur]->anim_time) {
			
			long lost = eanim->ctime - long(eanim->cur_anim->anims[eanim->altidx_cur]->anim_time);

			if(!eanim->next_anim) {
				long t = eanim->cur_anim->anims[eanim->altidx_cur]->anim_time;
				eanim->ctime= eanim->ctime % t;

				if(io)
					FinishAnim(io,eanim->cur_anim);
			} else {
				if(io) {
					FinishAnim(io,eanim->cur_anim);

					if(io->animBlend.lastanimtime != 0)
						AcquireLastAnim(io);
					else
						io->animBlend.lastanimtime = 1;
				}

				eanim->cur_anim=eanim->next_anim;
				eanim->altidx_cur=ANIM_GetAltIdx(eanim->next_anim,eanim->altidx_cur);
				eanim->next_anim=NULL;
				ResetAnim(eanim);
				eanim->ctime = lost;
				eanim->flags=eanim->nextflags;
				eanim->flags&=~EA_ANIMEND;
			}
		}
	} else if (eanim->ctime > eanim->cur_anim->anims[eanim->altidx_cur]->anim_time) {
		if(io) {
			long lost = eanim->ctime - eanim->cur_anim->anims[eanim->altidx_cur]->anim_time;

			if(eanim->next_anim) {
				FinishAnim(io,eanim->cur_anim);

				if (io->animBlend.lastanimtime!=0)
					AcquireLastAnim(io);
				else
					io->animBlend.lastanimtime=1;

				eanim->cur_anim=eanim->next_anim;
				eanim->altidx_cur=ANIM_GetAltIdx(eanim->next_anim,eanim->altidx_cur);
				eanim->next_anim=NULL;
				ResetAnim(eanim);
				eanim->ctime = lost;
				eanim->flags=eanim->nextflags;
				eanim->flags&=~EA_ANIMEND;
				goto suite;
			}
		}

		eanim->flags |= EA_ANIMEND;
		eanim->ctime = eanim->cur_anim->anims[eanim->altidx_cur]->anim_time;
	}

suite:

	if (!eanim->cur_anim)
		return;

	long tim;
	if(eanim->flags & EA_REVERSE)
		tim = eanim->cur_anim->anims[eanim->altidx_cur]->anim_time - eanim->ctime;
	else
		tim = eanim->ctime;

	eanim->fr = eanim->cur_anim->anims[eanim->altidx_cur]->nb_key_frames - 2;
	eanim->pour = 1.f;

	long fr;
	for(long i = 1; i < eanim->cur_anim->anims[eanim->altidx_cur]->nb_key_frames; i++) {
		long tcf = (long)eanim->cur_anim->anims[eanim->altidx_cur]->frames[i - 1].time;
		long tnf = (long)eanim->cur_anim->anims[eanim->altidx_cur]->frames[i].time;

		if(tcf == tnf)
			return;

		if((tim < tnf && tim >= tcf) || (i == eanim->cur_anim->anims[eanim->altidx_cur]->nb_key_frames - 1 && tim == tnf)) {
			fr = i - 1;
			tim -= tcf;
			float pour = (float)((float)tim/((float)tnf-(float)tcf));
			
			// Frame Sound Management
			if(!(eanim->flags & EA_ANIMEND) && time
			   && (eanim->cur_anim->anims[eanim->altidx_cur]->frames[fr].sample != -1)
			   && (eanim->lastframe != fr)) {

				Vec3f * position = io ? &io->pos : NULL;
				
				if(eanim->lastframe < fr && eanim->lastframe != -1) {
					for(long n = eanim->lastframe + 1; n <= fr; n++)
						ARX_SOUND_PlayAnim(eanim->cur_anim->anims[eanim->altidx_cur]->frames[n].sample, position);
				} else {
					ARX_SOUND_PlayAnim(eanim->cur_anim->anims[eanim->altidx_cur]->frames[fr].sample, position);
				}
			}

			// Frame Flags Management
			if(!(eanim->flags & EA_ANIMEND) && time
			   && (eanim->cur_anim->anims[eanim->altidx_cur]->frames[fr].flag > 0)
			   && (eanim->lastframe != fr)) {
				
				if(io != entities.player()) {
					if(eanim->lastframe < fr && eanim->lastframe != -1) {
						for(long n = eanim->lastframe + 1; n <= fr; n++) {
							if(eanim->cur_anim->anims[eanim->altidx_cur]->frames[n].flag == 9)
								ARX_NPC_NeedStepSound(io, &io->pos);
						}
					}
					else if(eanim->cur_anim->anims[eanim->altidx_cur]->frames[fr].flag == 9)
						ARX_NPC_NeedStepSound(io, &io->pos);
				}
			}
			
			// Memorize this frame as lastframe.
			eanim->lastframe = fr;
			eanim->fr = fr;
			eanim->pour = pour;
			break;
		}
	}
}