From 2678aa601f70d920c4e726d32b5646d552b75f8c Mon Sep 17 00:00:00 2001 From: "Zephaniah E. Hull" Date: Fri, 31 Mar 2000 22:46:39 +0000 Subject: [PATCH] Added sorting to the *.pak stuff.. Some other misc cleanups.. --- common/gl_draw.c | 2 +- common/gl_rmisc.c | 47 +++++------ common/lib_replace.c | 190 ++++++++----------------------------------- common/lib_replace.h | 1 + common/pcx.c | 2 +- common/quakefs.c | 53 +++++++++--- 6 files changed, 101 insertions(+), 194 deletions(-) diff --git a/common/gl_draw.c b/common/gl_draw.c index 2da18fc..0581f3b 100644 --- a/common/gl_draw.c +++ b/common/gl_draw.c @@ -1237,7 +1237,7 @@ void GL_Upload8_EXT (byte *data, int width, int height, qboolean mipmap, qboole int i, s; qboolean noalpha; int samples; - static unsigned char scaled[1024*512]; // [512*256]; + static unsigned char scaled[1024*512]; // [512*256]; int scaled_width, scaled_height; s = width*height; diff --git a/common/gl_rmisc.c b/common/gl_rmisc.c index e15e915..8a2d598 100644 --- a/common/gl_rmisc.c +++ b/common/gl_rmisc.c @@ -540,34 +540,35 @@ void R_TranslatePlayerSkin (int playernum) GL_Upload8_EXT ((byte *)pixels, scaled_width, scaled_height, false, false); return; - } + } else { // This is for 24/32 bit GL displays... - for (i=0 ; i<256 ; i++) - translate32[i] = d_8to24table[translate[i]]; + for (i=0 ; i<256 ; i++) + translate32[i] = d_8to24table[translate[i]]; - out = pixels; - fracstep = inwidth*0x10000/scaled_width; - for (i=0 ; i> 1; - for (j=0 ; j>16]]; - frac += fracstep; - out[j+1] = translate32[inrow[frac>>16]]; - frac += fracstep; - out[j+2] = translate32[inrow[frac>>16]]; - frac += fracstep; - out[j+3] = translate32[inrow[frac>>16]]; - frac += fracstep; + inrow = original + inwidth*(i*inheight/scaled_height); + frac = fracstep >> 1; + for (j=0 ; j>16]]; + frac += fracstep; + out[j+1] = translate32[inrow[frac>>16]]; + frac += fracstep; + out[j+2] = translate32[inrow[frac>>16]]; + frac += fracstep; + out[j+3] = translate32[inrow[frac>>16]]; + frac += fracstep; + } } - } - glTexImage2D (GL_TEXTURE_2D, 0, gl_solid_format, scaled_width, scaled_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + glTexImage2D (GL_TEXTURE_2D, 0, gl_solid_format, scaled_width, scaled_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + } #endif #endif /* QUAKEWORLD */ diff --git a/common/lib_replace.c b/common/lib_replace.c index bf03098..5a47c03 100644 --- a/common/lib_replace.c +++ b/common/lib_replace.c @@ -29,6 +29,7 @@ */ #include +#include /* ============================================================================ @@ -38,163 +39,6 @@ ============================================================================ */ -#if 0 -void Q_memset (void *dest, int fill, int count) -{ - int i; - - if ( (((long)dest | count) & 3) == 0) - { - count >>= 2; - fill = fill | (fill<<8) | (fill<<16) | (fill<<24); - for (i=0 ; i>=2; - for (i=0 ; i= 'a' && c1 <= 'z') - c1 -= ('a' - 'A'); - if (c2 >= 'a' && c2 <= 'z') - c2 -= ('a' - 'A'); - if (c1 != c2) - return -1; // strings not equal - } - if (!c1) - return 0; // strings are equal -// s1++; -// s2++; - } - - return -1; -} - -int Q_strcasecmp (char *s1, char *s2) -{ - return Q_strncasecmp (s1, s2, 99999); -} - -#endif - int Q_atoi (char *str) { int val; @@ -328,3 +172,35 @@ float Q_atof (char *str) return val*sign; } + +// Note, this is /NOT/ a work-alike strcmp, this groups numbers sanely. +int Q_qstrcmp(const char *val, const char *ref) +{ + int vc, rc; + long vl, rl; + const char *vp, *rp; + + if (!val) val= ""; + if (!ref) ref= ""; + for (;;) { + vp= val; while (*vp && !isdigit(*vp)) vp++; + rp= ref; while (*rp && !isdigit(*rp)) rp++; + for (;;) { + vc= val == vp ? 0 : *val++; + rc= ref == rp ? 0 : *ref++; + if (!rc && !vc) break; + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */ + if (rc && !isalpha(rc)) rc += 256; + if (vc != rc) return vc - rc; + } + val= vp; + ref= rp; + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10); + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10); + if (vl != rl) return vl - rl; + if (!*val && !*ref) return 0; + if (!*val) return -1; + if (!*ref) return +1; + } +} + diff --git a/common/lib_replace.h b/common/lib_replace.h index e652112..d25e556 100644 --- a/common/lib_replace.h +++ b/common/lib_replace.h @@ -58,5 +58,6 @@ int Q_atoi (char *str); float Q_atof (char *str); +int Q_qstrcmp(const char *val, const char *ref); #endif // _LIB_REPLACE_H diff --git a/common/pcx.c b/common/pcx.c index 359aaa2..b76c4df 100644 --- a/common/pcx.c +++ b/common/pcx.c @@ -88,7 +88,7 @@ byte *LoadPCX (char *file, cache_user_t *cache, int buf_x, int buf_y) { if (!buf_y) buf_y = pcx->ymax; - Con_Printf("PCX file %s %dx%d\n", file, buf_x, buf_y); + Con_DPrintf("PCX file %s %dx%d\n", file, buf_x, buf_y); out = Cache_Alloc (cache, buf_x * buf_y, file); if (!out) Sys_Error("LoadPCX: couldn't allocate."); diff --git a/common/quakefs.c b/common/quakefs.c index ef4779b..32a14da 100644 --- a/common/quakefs.c +++ b/common/quakefs.c @@ -723,29 +723,58 @@ COM_LoadGameDirectory(char *dir) char pakfile[MAX_OSPATH]; DIR *dir_ptr; struct dirent *dirent; + char **pakfiles; + int i = 0, bufsize = 0, count = 0; + pakfiles = calloc(1, BLOCK_SIZE); + bufsize += BLOCK_SIZE; + if (!pakfiles) + goto COM_LoadGameDirectory_free; + dir_ptr = opendir(dir); if (!dir_ptr) return; while ((dirent = readdir(dir_ptr))) { if (!fnmatch("*.pak", dirent->d_name, FNMATCH_FLAGS)) { - snprintf(pakfile, sizeof(pakfile), "%s/%s", dir, dirent->d_name); - - pak = COM_LoadPackFile(pakfile); - - if (!pak) { - Sys_Error(va("Bad pakfile %s!!", pakfile)); - } else { - search = Z_Malloc (sizeof(searchpath_t)); - search->pack = pak; - search->next = com_searchpaths; - com_searchpaths = search; + if (count >= bufsize) { + bufsize += BLOCK_SIZE; + pakfiles = realloc(pakfiles, bufsize); + if (!pakfiles) + goto COM_LoadGameDirectory_free; + for (i = count; i < bufsize; i++) + pakfiles[i] = NULL; } + pakfiles[count] = malloc(FNAME_SIZE); + snprintf(pakfiles[count], FNAME_SIZE - 1, "%s/%s", dir, + dirent->d_name); + pakfiles[count][FNAME_SIZE - 1] = '\0'; + count++; } } closedir(dir_ptr); + qsort(pakfiles, count, FNAME_SIZE, + (int (*)(const void *, const void *)) Q_qstrcmp); + + for (i = 0; i < count; i++) { + pak = COM_LoadPackFile(pakfiles[i]); + + if (!pak) { + Sys_Error(va("Bad pakfile %s!!", pakfiles[i])); + } else { + search = Z_Malloc (sizeof(searchpath_t)); + search->pack = pak; + search->next = com_searchpaths; + com_searchpaths = search; + } + } + +COM_LoadGameDirectory_free: + for (i = 0; i < count; i++) + free(pakfiles[i]); + free(pakfiles); + #ifdef GENERATIONS for (done=false, i=0 ; !done ; i++ ) { snprintf(pakfile, sizeof(pakfile), "%s/pak%i.qz", dir, i); @@ -759,7 +788,7 @@ COM_LoadGameDirectory(char *dir) search->pack = pak; search->next = com_searchpaths; com_searchpaths = search; - } + } } #endif }