From fb58e6195fc71d9a3d510f25b3d0a3c8ddb28a5d Mon Sep 17 00:00:00 2001 From: Mircea Kitsune Date: Sat, 14 Jan 2012 16:29:10 +0200 Subject: [PATCH] Attempt to cache the skeleton for each model, as requested by divVerent. This will have many uses in the code too. Currently, it uses a new function to set / update the skeleton, which also returns the total number of bones --- qcsrc/common/util.qc | 16 ++++++++++++++++ qcsrc/common/util.qh | 5 ++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/qcsrc/common/util.qc b/qcsrc/common/util.qc index 57e653113..5c9eaf0e1 100644 --- a/qcsrc/common/util.qc +++ b/qcsrc/common/util.qc @@ -2212,3 +2212,19 @@ float ReadApproxPastTime() return servertime - dt; } #endif + +#ifndef MENUQC +.float skeletonmodelindex; // used to check if model has changed +float Update_Skeleton(entity e) +{ + // updates the skeleton if needed, and returns the total number of bones + if(e.skeletonmodelindex != e.modelindex) + { + if(e.skeletonindex) + skel_delete(e.skeletonindex); + e.skeletonindex = skel_create(e.modelindex); + e.skeletonmodelindex = e.modelindex; + } + return skel_get_numbones(e.skeletonindex); +} +#endif diff --git a/qcsrc/common/util.qh b/qcsrc/common/util.qh index 046c32fc1..d8400a3dc 100644 --- a/qcsrc/common/util.qh +++ b/qcsrc/common/util.qh @@ -292,10 +292,9 @@ float InterpretBoolean(string input); void Shutdown(); #ifndef MENUQC -// returns the total number of tags on model v -#define TOTAL_TAGS(v) skel_get_numbones(skel_create(v.modelindex)); skel_delete(v.modelindex) +float Update_Skeleton(entity e); // loops through the tags of model v using counter tagnum -#define FOR_EACH_TAG(v) float tagnum, totaltags; totaltags = TOTAL_TAGS(v); for(tagnum = 0; tagnum < totaltags; tagnum++, gettaginfo(v, tagnum)) +#define FOR_EACH_TAG(v) float tagnum, tags; tags = Update_Skeleton(v); for(tagnum = 0; tagnum < tags; tagnum++, gettaginfo(v, tagnum)) #endif #ifdef SVQC void WriteApproxPastTime(float dst, float t); -- 2.39.2