/** Retrieve the texture number for a given texture resource. * * @note We keep textures in a separate data structure _TEX_PAGE apart from the * normal resource system. * * @param filename The filename of the texture page to search for. * * @return a non-negative index number for the texture, negative if no texture * with the given filename could be found */ int iV_GetTexture(const char *filename) { unsigned int i = 0; iV_Image sSprite; char path[PATH_MAX]; /* Have we already loaded this one then? */ sstrcpy(path, filename); pie_MakeTexPageName(path); for (i = 0; i < iV_TEX_MAX; i++) { if (strncmp(path, _TEX_PAGE[i].name, iV_TEXNAME_MAX) == 0) { return i; } } // Try to load it sstrcpy(path, "texpages/"); sstrcat(path, filename); if (!iV_loadImage_PNG(path, &sSprite)) { debug(LOG_ERROR, "Failed to load %s", path); return -1; } sstrcpy(path, filename); pie_MakeTexPageName(path); return pie_AddTexPage(&sSprite, path, 0, -1, true); // FIXME, -1, use getTextureSize() }
bool replaceTexture(const QString &oldfile, const QString &newfile) { char tmpname[iV_TEXNAME_MAX]; // Load new one to replace it iV_Image image; if (!iV_loadImage_PNG(QString("texpages/" + newfile).toUtf8().constData(), &image)) { debug(LOG_ERROR, "Failed to load image: %s", newfile.toUtf8().constData()); return false; } sstrcpy(tmpname, oldfile.toUtf8().constData()); pie_MakeTexPageName(tmpname); // Have we already loaded this one? for (int i = 0; i < _TEX_PAGE.size(); i++) { if (strcmp(tmpname, _TEX_PAGE[i].name) == 0) { GL_DEBUG("Replacing texture"); debug(LOG_TEXTURE, "Replacing texture %s with %s from index %d (tex id %u)", _TEX_PAGE[i].name, newfile.toUtf8().constData(), i, _TEX_PAGE[i].id); sstrcpy(tmpname, newfile.toUtf8().constData()); pie_MakeTexPageName(tmpname); pie_AddTexPage(&image, tmpname, true, i); iV_unloadImage(&image); return true; } } iV_unloadImage(&image); debug(LOG_ERROR, "Nothing to replace!"); return false; }
/** Retrieve the texture number for a given texture resource. * * @note We keep textures in a separate data structure _TEX_PAGE apart from the * normal resource system. * * @param filename The filename of the texture page to search for. * @param compression If we need to load it, should we use texture compression? * * @return a non-negative index number for the texture, negative if no texture * with the given filename could be found */ int iV_GetTexture(const char *filename, bool compression) { iV_Image sSprite; char path[PATH_MAX]; /* Have we already loaded this one then? */ sstrcpy(path, filename); pie_MakeTexPageName(path); for (int i = 0; i < _TEX_PAGE.size(); i++) { if (strncmp(path, _TEX_PAGE[i].name, iV_TEXNAME_MAX) == 0) { return i; } } // Try to load it sstrcpy(path, "texpages/"); sstrcat(path, filename); if (!iV_loadImage_PNG(path, &sSprite)) { debug(LOG_ERROR, "Failed to load %s", path); return -1; } sstrcpy(path, filename); pie_MakeTexPageName(path); return pie_AddTexPage(&sSprite, path, compression); }
/* Load a team colour mask texturepage into memory */ static bool dataTexPageTCMaskLoad(const char *fileName, void **ppData) { char texpage[PATH_MAX] = {'\0'}; // This hackery is needed, because fileName will include the directory name, whilst the LastResourceFilename will not, and we need a short name to identify the texpage sstrcpy(texpage, GetLastResourceFilename()); // Check if a corresponding texpage exists, exit if no pie_MakeTexPageName(texpage); ASSERT_OR_RETURN(false, resPresent(DT_TEXPAGE, texpage), "Corresponding texpage %s doesn't exists!", texpage); pie_MakeTexPageTCMaskName(texpage); if (!dataImageLoad(fileName, ppData)) { return false; } // see if this texture page has already been loaded if (resPresent(DT_TCMASK, texpage)) { // replace the old texture page with the new one debug(LOG_TEXTURE, "replacing %s with new tcmask %s", texpage, fileName); pie_ReplaceTexPage((iV_Image *)*ppData, texpage, getTextureSize(), false); } else { debug(LOG_TEXTURE, "adding page %s with tcmask %s", texpage, fileName); SetLastResourceFilename(texpage); pie_AddTexPage((iV_Image *)*ppData, texpage, 0, getTextureSize(), false); } return true; }
/* Load a texturepage into memory */ static bool dataTexPageLoad(const char *fileName, void **ppData) { char texpage[PATH_MAX] = {'\0'}; // This hackery is needed, because fileName will include the directory name, whilst the LastResourceFilename will not, and we need a short name to identify the texpage sstrcpy(texpage, GetLastResourceFilename()); pie_MakeTexPageName(texpage); if (!dataImageLoad(fileName, ppData)) { return false; } // see if this texture page has already been loaded if (resPresent(DT_TEXPAGE, texpage)) { // replace the old texture page with the new one debug(LOG_TEXTURE, "replacing %s with new texture %s", texpage, fileName); (void) pie_ReplaceTexPage(*ppData, texpage, getTextureSize(), true); } else { debug(LOG_TEXTURE, "adding page %s with texture %s", texpage, fileName); SetLastResourceFilename(texpage); (void) pie_AddTexPage(*ppData, texpage, 0, getTextureSize(), true); } return true; }