From 930f4e223c1c2ed1bb5b86f6cab5f8aafa1b3ad8 Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Fri, 8 Aug 2008 08:14:58 +0000 Subject: [PATCH] noworldtexture cleanup git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@2297 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/main.cpp | 2 +- source/src/protos.h | 7 +++++-- source/src/rendercubes.cpp | 14 +++++++------- source/src/texture.cpp | 16 +++++++--------- source/src/worldio.cpp | 2 +- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/source/src/main.cpp b/source/src/main.cpp index c67d605a..c8860d59 100644 --- a/source/src/main.cpp +++ b/source/src/main.cpp @@ -535,7 +535,7 @@ int main(int argc, char **argv) gl_checkextensions(); gl_init(scr_w, scr_h, usedcolorbits, useddepthbits, usedfsaa); - notexture = textureload("packages/misc/notexture.jpg"); + notexture = noworldtexture = textureload("packages/misc/notexture.jpg"); if(!notexture) fatal("could not find core textures (hint: run AssaultCube from the parent of the bin directory)"); initlog("console"); diff --git a/source/src/protos.h b/source/src/protos.h index 8564d86e..957fe6fe 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -217,16 +217,19 @@ struct Texture int xs, ys, bpp, clamp; GLuint id; }; -extern Texture *notexture; +extern Texture *notexture, *noworldtexture; extern void createtexture(int tnum, int w, int h, void *pixels, int clamp, bool mipmap, GLenum format); extern Texture *textureload(const char *name, int clamp = 0); -extern Texture *lookuptexture(int tex); +extern Texture *lookuptexture(int tex, Texture *failtex = notexture); extern void draw_envbox(int fogdist); extern bool reloadtexture(Texture &t); extern bool reloadtexture(const char *name); extern void reloadtextures(); +static inline Texture *lookupworldtexture(int tex) +{ return lookuptexture(tex, noworldtexture); } + extern int maxtmus; extern void inittmus(); extern void resettmu(int n); diff --git a/source/src/rendercubes.cpp b/source/src/rendercubes.cpp index d07298ad..70be7087 100644 --- a/source/src/rendercubes.cpp +++ b/source/src/rendercubes.cpp @@ -46,7 +46,7 @@ int renderedtexs = 0; void renderstripssky() { if(skystrips.tris.first.empty() && skystrips.tristrips.first.empty() && skystrips.quads.first.empty()) return; - glBindTexture(GL_TEXTURE_2D, lookuptexture(DEFAULT_SKY)->id); + glBindTexture(GL_TEXTURE_2D, lookupworldtexture(DEFAULT_SKY)->id); RENDERSTRIPS(skystrips.tris, GL_TRIANGLES); RENDERSTRIPS(skystrips.tristrips, GL_TRIANGLE_STRIP); RENDERSTRIPS(skystrips.quads, GL_QUADS); @@ -57,7 +57,7 @@ void renderstrips() loopj(renderedtexs) { stripbatch &sb = stripbatches[j]; - glBindTexture(GL_TEXTURE_2D, lookuptexture(sb.tex)->id); + glBindTexture(GL_TEXTURE_2D, lookupworldtexture(sb.tex)->id); RENDERSTRIPS(sb.tris, GL_TRIANGLES); RENDERSTRIPS(sb.tristrips, GL_TRIANGLE_STRIP); RENDERSTRIPS(sb.quads, GL_QUADS); @@ -142,7 +142,7 @@ void render_flat(int wtex, int x, int y, int size, int h, sqr *l1, sqr *l2, sqr { if(showm) { l3 = l1 = &sbright; l4 = l2 = &sdark; } - Texture *t = lookuptexture(wtex); + Texture *t = lookupworldtexture(wtex); float xf = TEXTURESCALE/t->xs; float yf = TEXTURESCALE/t->ys; float xs = size*xf; @@ -219,7 +219,7 @@ void render_flatdelta(int wtex, int x, int y, int size, float h1, float h2, floa { if(showm) { l3 = l1 = &sbright; l4 = l2 = &sdark; } - Texture *t = lookuptexture(wtex); + Texture *t = lookupworldtexture(wtex); float xf = TEXTURESCALE/t->xs; float yf = TEXTURESCALE/t->ys; float xs = size*xf; @@ -273,7 +273,7 @@ void render_2tris(sqr *h, sqr *s, int x1, int y1, int x2, int y2, int x3, int y3 { stripend(); - Texture *t = lookuptexture(h->ftex); + Texture *t = lookupworldtexture(h->ftex); float xf = TEXTURESCALE/t->xs; float yf = TEXTURESCALE/t->ys; vert(x1, y1, h->floor, l1, xf*x1, yf*y1); @@ -281,7 +281,7 @@ void render_2tris(sqr *h, sqr *s, int x1, int y1, int x2, int y2, int x3, int y3 vert(x3, y3, h->floor, l3, xf*x3, yf*y3); addstrip(mergestrips ? GL_TRIANGLES : GL_TRIANGLE_STRIP, h->ftex, verts.length()-3, 3); - t = lookuptexture(h->ctex); + t = lookupworldtexture(h->ctex); xf = TEXTURESCALE/t->xs; yf = TEXTURESCALE/t->ys; @@ -312,7 +312,7 @@ void render_square(int wtex, float floor1, float floor2, float ceil1, float ceil stripend(); if(showm) { l1 = &sbright; l2 = &sdark; } - Texture *t = lookuptexture(wtex); + Texture *t = lookupworldtexture(wtex); float xf = TEXTURESCALE/t->xs; float yf = TEXTURESCALE/t->ys; float xs = size*xf; diff --git a/source/src/texture.cpp b/source/src/texture.cpp index ae7562fe..8459189b 100644 --- a/source/src/texture.cpp +++ b/source/src/texture.cpp @@ -3,7 +3,7 @@ #include "pch.h" #include "cube.h" -Texture *notexture = NULL; +Texture *notexture = NULL, *noworldtexture = NULL; hashtable textures; @@ -159,9 +159,9 @@ void texture(char *aframe, char *name) COMMAND(texturereset, ARG_NONE); COMMAND(texture, ARG_2STR); -Texture *lookuptexture(int tex) +Texture *lookuptexture(int tex, Texture *failtex) { - Texture *t = notexture; + Texture *t = failtex; if(slots.inrange(tex)) { Slot &s = slots[tex]; @@ -169,6 +169,7 @@ Texture *lookuptexture(int tex) { s_sprintfd(pname)("packages/textures/%s", s.name); s.tex = textureload(pname); + if(s.tex==notexture) s.tex = failtex; s.loaded = true; } if(s.tex) t = s.tex; @@ -223,15 +224,12 @@ COMMAND(loadsky, ARG_1STR); void loadnotexture(char *c) { - const char *defnotex = "packages/misc/notexture.jpg"; - notexture = textureload(defnotex); // reset to default + noworldtexture = notexture; // reset to default if(c[0]) { s_sprintfd(p)("packages/textures/%s", c); - Texture *missingtex = textureload(p); - if(missingtex==notexture) { conoutf("could not load alternative texture '%s'.", p); s_strcpy(p, defnotex); } - else notexture = missingtex; - conoutf("using '%s' as alternative texture", p); + noworldtexture = textureload(p); + if(noworldtexture==notexture) conoutf("could not load alternative texture '%s'.", p); } } COMMAND(loadnotexture, ARG_1STR); diff --git a/source/src/worldio.cpp b/source/src/worldio.cpp index 1889ca12..4943ea0e 100644 --- a/source/src/worldio.cpp +++ b/source/src/worldio.cpp @@ -385,7 +385,7 @@ bool load_world(char *mname) // still supports all map formats that have popscontext(); c2skeepalive(); - loopi(256) if(texuse[i]) lookuptexture(i); + loopi(256) if(texuse[i]) lookupworldtexture(i); c2skeepalive(); preload_mapmodels(); c2skeepalive();