From a89dca11cf475e0bd1399cf5d5c5135d00495ec3 Mon Sep 17 00:00:00 2001 From: xolatile Date: Mon, 4 Aug 2025 18:17:30 +0200 Subject: Minor changes... --- src/shared/command.h | 16 ++++---- src/shared/glexts.h | 1 - src/shared/iengine.h | 18 ++++----- src/shared/igame.h | 3 +- src/shared/stream.cpp | 102 ++++++++++++++------------------------------------ 5 files changed, 46 insertions(+), 94 deletions(-) (limited to 'src/shared') diff --git a/src/shared/command.h b/src/shared/command.h index 475e492..c07dee8 100644 --- a/src/shared/command.h +++ b/src/shared/command.h @@ -75,7 +75,7 @@ struct tagval : identval void cleanup(); }; - + struct identstack { identval val; @@ -128,7 +128,7 @@ struct ident }; }; identfun fun; // ID_VAR, ID_FVAR, ID_SVAR, ID_COMMAND - + ident() {} // ID_VAR ident(int t, const char *n, int m, int x, int *s, void *f = NULL, int flags = 0) @@ -170,13 +170,13 @@ struct ident valtype = v.type; val = v; } - + void setval(const identstack &v) { valtype = v.valtype; val = v.val; } - + void forcenull() { if(valtype==VAL_STR) delete[] val.s; @@ -216,7 +216,7 @@ static inline float parsefloat(const char *s) static inline void intformat(char *buf, int v, int len = 20) { nformatstring(buf, len, "%d", v); } static inline void floatformat(char *buf, float v, int len = 20) { nformatstring(buf, len, v==int(v) ? "%.1f" : "%.6g", v); } -static inline const char *getstr(const identval &v, int type) +static inline const char *getstr(const identval &v, int type) { switch(type) { @@ -235,7 +235,7 @@ static inline int getint(const identval &v, int type) { case VAL_INT: return v.i; case VAL_FLOAT: return int(v.f); - case VAL_STR: case VAL_MACRO: return parseint(v.s); + case VAL_STR: case VAL_MACRO: return parseint(v.s); default: return 0; } } @@ -253,7 +253,7 @@ static inline float getfloat(const identval &v, int type) } } inline float tagval::getfloat() const { return ::getfloat(*this, type); } -inline float ident::getfloat() const { return ::getfloat(val, valtype); } +inline float ident::getfloat() const { return ::getfloat(val, valtype); } inline void ident::getval(tagval &v) const { @@ -332,4 +332,4 @@ inline void ident::getval(tagval &v) const #define ICOMMAND(name, nargs, proto, b) ICOMMANDN(name, ICOMMANDNAME(name), nargs, proto, b) #define ICOMMANDSNAME _icmds_ #define ICOMMANDS(name, nargs, proto, b) ICOMMANDNS(name, ICOMMANDSNAME, nargs, proto, b) - + diff --git a/src/shared/glexts.h b/src/shared/glexts.h index 59509c1..0b8e823 100644 --- a/src/shared/glexts.h +++ b/src/shared/glexts.h @@ -485,4 +485,3 @@ extern PFNGLISVERTEXARRAYPROC glIsVertexArray_; #define GL_TEXTURE_SWIZZLE_A 0x8E45 #define GL_TEXTURE_SWIZZLE_RGBA 0x8E46 #endif - diff --git a/src/shared/iengine.h b/src/shared/iengine.h index 80f876d..80bc9c5 100644 --- a/src/shared/iengine.h +++ b/src/shared/iengine.h @@ -221,13 +221,13 @@ extern int lookupmaterial(const vec &o); static inline bool insideworld(const vec &o) { - extern int worldsize; + extern int worldsize; return o.x>=0 && o.x=0 && o.y=0 && o.z &attr, int np); extern int laninfoport(); extern int serverinfoport(int servport = -1); extern int serverport(int infoport = -1); diff --git a/src/shared/stream.cpp b/src/shared/stream.cpp index f2b586e..888caa8 100644 --- a/src/shared/stream.cpp +++ b/src/shared/stream.cpp @@ -214,17 +214,17 @@ size_t encodeutf8(uchar *dstbuf, size_t dstlen, const uchar *srcbuf, size_t srcl { if(dst >= dstend) goto done; const uchar *end = min(srcend, &src[dstend-dst]); - do - { + do + { if(uni == '\f') { if(++src >= srcend) goto done; goto uni1; } - *dst++ = uni; - if(++src >= end) goto done; - uni = cube2uni(*src); - } + *dst++ = uni; + if(++src >= end) goto done; + uni = cube2uni(*src); + } while(uni <= 0x7F); } if(uni <= 0x7FF) { if(dst + 2 > dstend) goto done; *dst++ = 0xC0 | (uni>>6); goto uni2; } @@ -239,7 +239,7 @@ size_t encodeutf8(uchar *dstbuf, size_t dstlen, const uchar *srcbuf, size_t srcl uni3: *dst++ = 0x80 | ((uni>>6)&0x3F); uni2: *dst++ = 0x80 | (uni&0x3F); uni1:; - } + } while(++src < srcend); done: @@ -437,7 +437,7 @@ const char *addpackagedir(const char *dir) if(!filter) break; if(filter > pdir && filter[-1] == PATHDIV && filter[len] == PATHDIV) break; filter += len; - } + } packagedir &pf = packagedirs.add(); pf.dir = filter ? newstring(pdir, filter-pdir) : newstring(pdir); pf.dirlen = filter ? filter-pdir : strlen(pdir); @@ -493,9 +493,9 @@ bool listdir(const char *dirname, bool rel, const char *ext, vector &fil if(!ext) files.add(newstring(FindFileData.cFileName)); else { - size_t namelen = strlen(FindFileData.cFileName); - if(namelen > extsize) - { + size_t namelen = strlen(FindFileData.cFileName); + if(namelen > extsize) + { namelen -= extsize; if(FindFileData.cFileName[namelen] == '.' && strncmp(FindFileData.cFileName+namelen+1, ext, extsize-1)==0) files.add(newstring(FindFileData.cFileName, namelen)); @@ -623,14 +623,6 @@ size_t stream::printf(const char *fmt, ...) char buf[512]; char *str = buf; va_list args; -#if defined(WIN32) && !defined(__GNUC__) - va_start(args, fmt); - int len = _vscprintf(fmt, args); - if(len <= 0) { va_end(args); return 0; } - if(len >= (int)sizeof(buf)) str = new char[len+1]; - _vsnprintf(str, len+1, fmt, args); - va_end(args); -#else va_start(args, fmt); int len = vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); @@ -642,7 +634,6 @@ size_t stream::printf(const char *fmt, ...) vsnprintf(str, len+1, fmt, args); va_end(args); } -#endif size_t n = write(str, len); if(str != buf) delete[] str; return n; @@ -665,11 +656,7 @@ struct filestream : stream bool opentemp(const char *name, const char *mode) { if(file) return false; -#ifdef WIN32 - file = fopen(name, mode); -#else file = tmpfile(); -#endif return file!=NULL; } @@ -679,31 +666,14 @@ struct filestream : stream } bool end() { return feof(file)!=0; } - offset tell() - { -#ifdef WIN32 -#if defined(__GNUC__) && !defined(__MINGW32__) - offset off = ftello64(file); -#else - offset off = _ftelli64(file); -#endif -#else + offset tell() + { offset off = ftello(file); -#endif - // ftello returns LONG_MAX for directories on some platforms return off + 1 >= 0 ? off : -1; } - bool seek(offset pos, int whence) - { -#ifdef WIN32 -#if defined(__GNUC__) && !defined(__MINGW32__) - return fseeko64(file, pos, whence) >= 0; -#else - return _fseeki64(file, pos, whence) >= 0; -#endif -#else + bool seek(offset pos, int whence = SEEK_SET) + { return fseeko(file, pos, whence) >= 0; -#endif } size_t read(void *buf, size_t len) { return fread(buf, 1, len, file); } @@ -724,10 +694,6 @@ struct filestream : stream } }; -#ifndef STANDALONE -VAR(dbggz, 0, 0, 1); -#endif - struct gzstream : stream { enum @@ -858,18 +824,6 @@ struct gzstream : stream void finishreading() { if(!reading) return; -#ifndef STANDALONE - if(dbggz) - { - uint checkcrc = 0, checksize = 0; - loopi(4) checkcrc |= uint(readbyte()) << (i*8); - loopi(4) checksize |= uint(readbyte()) << (i*8); - if(checkcrc != crc) - conoutf(CON_DEBUG, "gzip crc check failed: read %X, calculated %X", checkcrc, crc); - if(checksize != zfile.total_out) - conoutf(CON_DEBUG, "gzip size check failed: read %u, calculated %u", checksize, uint(zfile.total_out)); - } -#endif } void stopreading() @@ -1031,7 +985,7 @@ struct utf8stream : stream offset pos; size_t bufread, bufcarry, buflen; bool reading, writing, autoclose; - uchar buf[BUFSIZE]; + uchar buf[BUFSIZE]; utf8stream() : file(NULL), pos(0), bufread(0), bufcarry(0), buflen(0), reading(false), writing(false), autoclose(false) { @@ -1058,10 +1012,10 @@ struct utf8stream : stream { size_t n = file->read(buf, 3); if(n == 3 && buf[0] == 0xEF && buf[1] == 0xBB && buf[2] == 0xBF) return true; - buflen = n; + buflen = n; return false; } - + bool open(stream *f, const char *mode, bool needclose) { if(file) return false; @@ -1071,16 +1025,16 @@ struct utf8stream : stream else if(*mode=='w') { writing = true; break; } } if(!reading && !writing) return false; - + file = f; - + if(reading) checkheader(); - + autoclose = needclose; return true; - } + } - void finishreading() + void finishreading() { if(!reading) return; } @@ -1118,14 +1072,14 @@ struct utf8stream : stream return !off; } else if(whence == SEEK_CUR) off += pos; - + if(off >= pos) off -= pos; else if(off < 0 || !file->seek(0, SEEK_SET)) return false; else { bufread = bufcarry = buflen = 0; pos = 0; - checkheader(); + checkheader(); } uchar skip[512]; @@ -1135,7 +1089,7 @@ struct utf8stream : stream if(read(skip, skipped) != skipped) { stopreading(); return false; } off -= skipped; } - + return true; } @@ -1165,7 +1119,7 @@ struct utf8stream : stream if(bufread >= bufcarry) { if(readbuf(BUFSIZE)) continue; stopreading(); if(!next) return false; break; } size_t n = min(len - next, bufcarry - bufread); uchar *endline = (uchar *)memchr(&buf[bufread], '\n', n); - if(endline) { n = endline+1 - &buf[bufread]; len = next + n; } + if(endline) { n = endline+1 - &buf[bufread]; len = next + n; } memcpy(&((uchar *)dst)[next], &buf[bufread], n); next += n; bufread += n; @@ -1252,7 +1206,7 @@ char *loadfile(const char *fn, size_t *size, bool utf8) if(f->read(buf, 3) != 3) { delete f; delete[] buf; return NULL; } if(((uchar *)buf)[0] == 0xEF && ((uchar *)buf)[1] == 0xBB && ((uchar *)buf)[2] == 0xBF) len -= 3; else offset += 3; - } + } size_t rlen = f->read(&buf[offset], len-offset); delete f; if(rlen != len-offset) { delete[] buf; return NULL; } -- cgit v1.2.3