/* =============== RE_RegisterAnimation =============== */ qhandle_t RE_RegisterAnimation(const char *name) { qhandle_t hAnim; skelAnimation_t *anim; char *buffer; int bufferLen; qboolean loaded = qfalse; if(!name || !name[0]) { ri.Printf(PRINT_WARNING, "Empty name passed to RE_RegisterAnimation\n"); return 0; } //ri.Printf(PRINT_ALL, "RE_RegisterAnimation(%s)\n", name); if(strlen(name) >= MAX_QPATH) { ri.Printf(PRINT_WARNING, "Animation name exceeds MAX_QPATH\n"); return 0; } // search the currently loaded animations for(hAnim = 1; hAnim < tr.numAnimations; hAnim++) { anim = tr.animations[hAnim]; if(!Q_stricmp(anim->name, name)) { if(anim->type == AT_BAD) { return 0; } return hAnim; } if(anim->type == AT_PSA && anim->psa) { const char *animName; animName = strstr(name, "::"); //ri.Printf(PRINT_ALL, "animName = '%s'\n", animName ? (animName + 2) : NULL); if(animName && *(animName + 2) && !Q_stricmp(anim->psa->info.name, (animName + 2))) { return hAnim; } } } // allocate a new model_t if((anim = R_AllocAnimation()) == NULL) { ri.Printf(PRINT_WARNING, "RE_RegisterAnimation: R_AllocAnimation() failed for '%s'\n", name); return 0; } // only set the name after the animation has been successfully allocated Q_strncpyz(anim->name, name, sizeof(anim->name)); // make sure the render thread is stopped R_SyncRenderThread(); // load and parse the .md5anim file bufferLen = ri.FS_ReadFile(name, (void **)&buffer); if(!buffer) { return 0; } if(!Q_stricmpn((const char *)buffer, "MD5Version", 10)) { loaded = R_LoadMD5Anim(anim, buffer, bufferLen, name); } else if(!Q_stricmpn((const char *)buffer, "ANIMHEAD", 8)) { loaded = R_LoadPSA(anim, buffer, bufferLen, name); } else { ri.Printf(PRINT_WARNING, "RE_RegisterAnimation: unknown fileid for '%s'\n", name); } ri.FS_FreeFile(buffer); if(!loaded) { ri.Printf(PRINT_WARNING, "couldn't load '%s'\n", name); // we still keep the model_t around, so if the model name is asked for // again, we won't bother scanning the filesystem anim->type = AT_BAD; } return anim->index; }
/* =============== RE_RegisterAnimation =============== */ qhandle_t RE_RegisterAnimation( const char *name ) { qhandle_t hAnim; skelAnimation_t *anim; char *buffer; bool loaded = false; if ( !name || !name[ 0 ] ) { Log::Warn("Empty name passed to RE_RegisterAnimation" ); return 0; } //Log::Notice("RE_RegisterAnimation(%s)", name); if ( strlen( name ) >= MAX_QPATH ) { Log::Warn("Animation name exceeds MAX_QPATH" ); return 0; } // search the currently loaded animations for ( hAnim = 1; hAnim < tr.numAnimations; hAnim++ ) { anim = tr.animations[ hAnim ]; if ( !Q_stricmp( anim->name, name ) ) { if ( anim->type == animType_t::AT_BAD ) { return 0; } return hAnim; } } // allocate a new model_t if ( ( anim = R_AllocAnimation() ) == nullptr ) { Log::Warn("RE_RegisterAnimation: R_AllocAnimation() failed for '%s'", name ); return 0; } // only set the name after the animation has been successfully allocated Q_strncpyz( anim->name, name, sizeof( anim->name ) ); // make sure the render thread is stopped R_SyncRenderThread(); // load and parse the .md5anim file int bufferLen = ri.FS_ReadFile( name, ( void ** ) &buffer ); if ( !buffer ) { return 0; } if ( bufferLen >= 10 && !Q_strnicmp( ( const char * ) buffer, "MD5Version", 10 ) ) { loaded = R_LoadMD5Anim( anim, buffer, name ); } else { Log::Warn("RE_RegisterAnimation: unknown fileid for '%s'", name ); } ri.FS_FreeFile( buffer ); if ( !loaded ) { Log::Warn("couldn't load '%s'", name ); // we still keep the model_t around, so if the model name is asked for // again, we won't bother scanning the filesystem anim->type = animType_t::AT_BAD; } return anim->index; }