diff --git a/Makefile b/Makefile index 43e4eab..66f2ed3 100644 --- a/Makefile +++ b/Makefile @@ -472,6 +472,7 @@ CL_OBJS := \ keys.o \ menu.o \ r_efrag.o \ + r_model.o \ r_part.o \ sbar.o \ snd_dma.o \ diff --git a/common/gl_rmain.c b/common/gl_rmain.c index b88f557..8cb3320 100644 --- a/common/gl_rmain.c +++ b/common/gl_rmain.c @@ -517,10 +517,9 @@ static void R_AliasSetupSkin(entity_t *e, aliashdr_t *pahdr) { int skinnum; - int i, frame, numframes; + int frame, numframes; maliasskindesc_t *pskindesc; - float *pskinintervals, fullinterval; - float targettime, time; + float *intervals; GLuint *glt; skinnum = e->skinnum; @@ -534,21 +533,9 @@ R_AliasSetupSkin(entity_t *e, aliashdr_t *pahdr) frame = pskindesc->firstframe; numframes = pskindesc->numframes; - /* - * when loading in Mod_LoadAliasSkinGroup, we guaranteed all interval - * values are positive, so we don't have to worry about division by 0 - */ if (numframes > 1) { - pskinintervals = (float *)((byte *)pahdr + pahdr->skinintervals); - pskinintervals += frame; - fullinterval = pskinintervals[numframes - 1]; - time = cl.time + e->syncbase; - targettime = time - ((int)(time / fullinterval)) * fullinterval; - for (i = 0; i < numframes - 1; i++) { - if (pskinintervals[i] > targettime) - break; - } - frame += i; + intervals = (float *)((byte *)pahdr + pahdr->skinintervals) + frame; + frame += Mod_FindInterval(intervals, numframes, cl.time + e->syncbase); } glt = (GLuint *)((byte *)pahdr + pahdr->skindata); @@ -564,8 +551,8 @@ R_SetupAliasFrame static void R_SetupAliasFrame(const entity_t *e, aliashdr_t *pahdr) { - int i, frame, pose, numposes; - float time, targettime, fullinterval, *intervals; + int frame, pose, numposes; + float *intervals; frame = e->frame; if ((frame >= pahdr->numframes) || (frame < 0)) { @@ -577,16 +564,8 @@ R_SetupAliasFrame(const entity_t *e, aliashdr_t *pahdr) numposes = pahdr->frames[frame].numposes; if (numposes > 1) { - intervals = (float *)((byte *)pahdr + pahdr->poseintervals); - intervals += pose; - fullinterval = intervals[numposes - 1]; - time = cl.time + e->syncbase; - targettime = time - (int)(time / fullinterval) % numposes; - for (i = 0; i < numposes - 1; i++) { - if (intervals[i] > targettime) - break; - } - pose += i; + intervals = (float *)((byte *)pahdr + pahdr->poseintervals) + pose; + pose += Mod_FindInterval(intervals, numposes, cl.time + e->syncbase); } GL_DrawAliasFrame(pahdr, pose); diff --git a/common/r_alias.c b/common/r_alias.c index 34a8c51..40abbb8 100644 --- a/common/r_alias.c +++ b/common/r_alias.c @@ -628,10 +628,9 @@ static void R_AliasSetupSkin(entity_t *e, aliashdr_t *pahdr) { int skinnum; - int i, frame, numframes, skinbytes; + int frame, numframes, skinbytes; maliasskindesc_t *pskindesc; - float *pskinintervals, fullinterval; - float targettime, time; + float *intervals; byte *pdata; skinnum = e->skinnum; @@ -647,21 +646,9 @@ R_AliasSetupSkin(entity_t *e, aliashdr_t *pahdr) frame = pskindesc->firstframe; numframes = pskindesc->numframes; - /* - * when loading in Mod_LoadAliasSkinGroup, we guaranteed all interval - * values are positive, so we don't have to worry about division by 0 - */ if (numframes > 1) { - pskinintervals = (float *)((byte *)pahdr + pahdr->skinintervals); - pskinintervals += frame; - fullinterval = pskinintervals[numframes - 1]; - time = cl.time + e->syncbase; - targettime = time - ((int)(time / fullinterval)) * fullinterval; - for (i = 0; i < numframes - 1; i++) { - if (pskinintervals[i] > targettime) - break; - } - frame += i; + intervals = (float *)((byte *)pahdr + pahdr->skinintervals) + frame; + frame += Mod_FindInterval(intervals, numframes, cl.time + e->syncbase); } skinbytes = pahdr->skinwidth * pahdr->skinheight * r_pixbytes; @@ -763,8 +750,8 @@ set r_apverts static void R_AliasSetupFrame(entity_t *e, aliashdr_t *pahdr) { - int i, frame, pose, numposes; - float time, targettime, fullinterval, *intervals; + int frame, pose, numposes; + float *intervals; frame = e->frame; if ((frame >= pahdr->numframes) || (frame < 0)) { @@ -775,21 +762,9 @@ R_AliasSetupFrame(entity_t *e, aliashdr_t *pahdr) pose = pahdr->frames[frame].firstpose; numposes = pahdr->frames[frame].numposes; -// -// when loading in Mod_LoadAliasGroup, we guaranteed all interval values -// are positive, so we don't have to worry about division by 0 -// if (numposes > 1) { - intervals = (float *)((byte *)pahdr + pahdr->poseintervals); - intervals += pose; - fullinterval = intervals[numposes - 1]; - time = cl.time + e->syncbase; - targettime = time - (int)(time / fullinterval) * fullinterval; - for (i = 0; i < numposes - 1; i++) { - if (intervals[i] > targettime) - break; - } - pose += i; + intervals = (float *)((byte *)pahdr + pahdr->poseintervals) + pose; + pose += Mod_FindInterval(intervals, numposes, cl.time + e->syncbase); } #ifdef NQ_HACK diff --git a/common/r_model.c b/common/r_model.c new file mode 100644 index 0000000..5785c90 --- /dev/null +++ b/common/r_model.c @@ -0,0 +1,44 @@ +/* +Copyright (C) 1996-1997 Id Software, Inc. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +// Shared model functions for renderers + +/* + * Find the correct interval based on time + * Used for Alias model frame/sprite/skin group animations + */ +int +Mod_FindInterval(const float *intervals, int numintervals, float time) +{ + int i; + float fullinterval, targettime; + + /* + * when loading models/skins/sprites, we guaranteed all interval values + * are positive, so we don't have to worry about division by 0 + */ + fullinterval = intervals[numintervals - 1]; + targettime = time - (int)(time / fullinterval) * fullinterval; + for (i = 0; i < numintervals - 1; i++) + if (intervals[i] > targettime) + break; + + return i; +} diff --git a/include/model.h b/include/model.h index 252ff34..49c92d8 100644 --- a/include/model.h +++ b/include/model.h @@ -482,4 +482,6 @@ void Mod_LoadSpriteModel(model_t *mod, void *buffer, const char *loadname); mspriteframe_t *Mod_GetSpriteFrame(struct entity_s *e, msprite_t *psprite, float time); +int Mod_FindInterval(const float *intervals, int numintervals, float time); + #endif /* MODEL_H */