Overview
Comment: | More string cleanups |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
a401a49dd9b3759c48509aa50fa13dab |
User & Date: | js on 2025-03-04 01:13:36 |
Other Links: | manifest | tags |
Context
2025-03-04
| ||
01:19 | Add long options check-in: 9684b46414 user: js tags: trunk | |
01:13 | More string cleanups check-in: a401a49dd9 user: js tags: trunk | |
01:05 | tools.h: Some cleanups check-in: 9e3f7517ee user: js tags: trunk | |
Changes
Modified src/Cube.mm from [1c90efecc5] to [f393e63c6d].
︙ | ︙ | |||
31 32 33 34 35 36 37 | quit() // normal exit { writeservercfg(); [OFApplication.sharedApplication terminateWithStatus:0]; } void | | > | > | | | 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | quit() // normal exit { writeservercfg(); [OFApplication.sharedApplication terminateWithStatus:0]; } void fatal(OFString *s, OFString *o) // failure exit { OFString *msg = [OFString stringWithFormat:@"%@%@ (%s)\n", s, o, SDL_GetError()]; OFApplication *app = OFApplication.sharedApplication; [(Cube *)app.delegate showMessage:msg]; [app terminateWithStatus:1]; } void * alloc(int s) // for some big chunks... most other allocs use the memory pool { void *b = calloc(1, s); if (!b) fatal(@"out of memory!"); return b; } int scr_w = 640; int scr_h = 480; void |
︙ | ︙ | |||
147 148 149 150 151 152 153 | sdesc = @""; if (ip == nil) ip = @""; if (passwd == nil) passwd = @""; if (SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO | par) < 0) | | | | | | 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | sdesc = @""; if (ip == nil) ip = @""; if (passwd == nil) passwd = @""; if (SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO | par) < 0) fatal(@"Unable to initialize SDL"); log("net"); if (enet_initialize() < 0) fatal(@"Unable to initialise network module"); initclient(); // never returns if dedicated initserver(dedicated, uprate, sdesc.UTF8String, ip.UTF8String, master.UTF8String, passwd, maxcl); log("world"); empty_world(7, true); log("video: sdl"); if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) fatal(@"Unable to initialize SDL Video"); log("video: mode"); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); if (SDL_SetVideoMode(scr_w, scr_h, 0, SDL_OPENGL | (!windowed ? SDL_FULLSCREEN : 0)) == NULL) fatal(@"Unable to create OpenGL screen"); log("video: misc"); SDL_WM_SetCaption("cube engine", NULL); SDL_WM_GrabInput(SDL_GRAB_ON); keyrepeat(false); SDL_ShowCursor(0); |
︙ | ︙ | |||
191 192 193 194 195 196 197 | !installtex(6, path(newstring("data/martin/ball1.png")), xs, ys) || !installtex(7, path(newstring("data/martin/smoke.png")), xs, ys) || !installtex(8, path(newstring("data/martin/ball2.png")), xs, ys) || !installtex(9, path(newstring("data/martin/ball3.png")), xs, ys) || !installtex(4, path(newstring("data/explosion.jpg")), xs, ys) || !installtex(5, path(newstring("data/items.png")), xs, ys) || !installtex(1, path(newstring("data/crosshair.png")), xs, ys)) | | | | 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | !installtex(6, path(newstring("data/martin/ball1.png")), xs, ys) || !installtex(7, path(newstring("data/martin/smoke.png")), xs, ys) || !installtex(8, path(newstring("data/martin/ball2.png")), xs, ys) || !installtex(9, path(newstring("data/martin/ball3.png")), xs, ys) || !installtex(4, path(newstring("data/explosion.jpg")), xs, ys) || !installtex(5, path(newstring("data/items.png")), xs, ys) || !installtex(1, path(newstring("data/crosshair.png")), xs, ys)) fatal(@"could not find core textures (hint: run cube from the " @"parent of the bin directory)"); log("sound"); initsound(); log("cfg"); newmenu(@"frags\tpj\tping\tteam\tname"); newmenu(@"ping\tplr\tserver"); |
︙ | ︙ |
Modified src/client.mm from [f8f6147037] to [74876b82b8].
︙ | ︙ | |||
188 189 190 191 192 193 194 | void addmsg(int rel, int num, int type, ...) { if (demoplayback) return; if (num != msgsizelookup(type)) { | > | | < < > < > | 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | void addmsg(int rel, int num, int type, ...) { if (demoplayback) return; if (num != msgsizelookup(type)) { fatal([OFString stringWithFormat:@"inconsistant msg size for %d (%d != %d)", type, num, msgsizelookup(type)]); } if (messages.length() == 100) { conoutf(@"command flood protection (type %d)", type); return; } ivector &msg = messages.add(); msg.add(num); msg.add(rel); msg.add(type); va_list marker; va_start(marker, type); loopi(num - 1) msg.add(va_arg(marker, int)); |
︙ | ︙ |
Modified src/protos.h from [c14b92cf05] to [59c370b1c3].
︙ | ︙ | |||
136 137 138 139 140 141 142 | float widef, int w, int h); // worldocull extern void computeraytable(float vx, float vy); extern int isoccluded(float vx, float vy, float cx, float cy, float csize); // main | | | 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | float widef, int w, int h); // worldocull extern void computeraytable(float vx, float vy); extern int isoccluded(float vx, float vy, float cx, float cy, float csize); // main extern void fatal(OFString *s, OFString *o = @""); extern void *alloc(int s); extern void keyrepeat(bool on); // rendertext extern void draw_text(char *str, int left, int top, int gl_num); extern void draw_textf(char *fstr, int left, int top, int gl_num, ...); extern int text_width(char *str); |
︙ | ︙ |
Modified src/rendercubes.mm from [00e0652146] to [bb9341fd13].
︙ | ︙ | |||
9 10 11 12 13 14 15 | void setarraypointers() { glVertexPointer(3, GL_FLOAT, sizeof(vertex), &verts[0].x); glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(vertex), &verts[0].r); glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), &verts[0].u); | < > | < > | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | void setarraypointers() { glVertexPointer(3, GL_FLOAT, sizeof(vertex), &verts[0].x); glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(vertex), &verts[0].r); glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), &verts[0].u); } void reallocv() { verts = (vertex *)realloc(verts, (curmaxverts *= 2) * sizeof(vertex)); curmaxverts -= 10; if (!verts) fatal(@"no vertex memory!"); setarraypointers(); } // generating the actual vertices is done dynamically every frame and sits at // the leaves of all these functions, and are part of the cpu bottleneck on // really slow machines, hence the macros. #define vertcheck() \ { \ |
︙ | ︙ |
Modified src/rendergl.mm from [6ee2ffc9ed] to [0379a81562].
︙ | ︙ | |||
52 53 54 55 56 57 58 | @"lighting model!"); glGetIntegerv(GL_MAX_TEXTURE_SIZE, &glmaxtexsize); purgetextures(); if (!(qsphere = gluNewQuadric())) | | | 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | @"lighting model!"); glGetIntegerv(GL_MAX_TEXTURE_SIZE, &glmaxtexsize); purgetextures(); if (!(qsphere = gluNewQuadric())) fatal(@"glu sphere"); gluQuadricDrawStyle(qsphere, GLU_FILL); gluQuadricOrientation(qsphere, GLU_INSIDE); gluQuadricTexture(qsphere, GL_TRUE); glNewList(1, GL_COMPILE); gluSphere(qsphere, 1, 12, 6); glEndList(); }; |
︙ | ︙ | |||
107 108 109 110 111 112 113 | texname); // for voodoo cards under linux scaledimg = alloc(xs * ys * 3); gluScaleImage(GL_RGB, s->w, s->h, GL_UNSIGNED_BYTE, s->pixels, xs, ys, GL_UNSIGNED_BYTE, scaledimg); }; if (gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, xs, ys, GL_RGB, GL_UNSIGNED_BYTE, scaledimg)) | | | 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | texname); // for voodoo cards under linux scaledimg = alloc(xs * ys * 3); gluScaleImage(GL_RGB, s->w, s->h, GL_UNSIGNED_BYTE, s->pixels, xs, ys, GL_UNSIGNED_BYTE, scaledimg); }; if (gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, xs, ys, GL_RGB, GL_UNSIGNED_BYTE, scaledimg)) fatal(@"could not build mipmaps"); if (xs != s->w) free(scaledimg); SDL_FreeSurface(s); return true; }; // management of texture slots |
︙ | ︙ | |||
187 188 189 190 191 192 193 | xs = texx[i]; ys = texy[i]; return tid; }; }; if (curtex == MAXTEX) | | | 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | xs = texx[i]; ys = texy[i]; return tid; }; }; if (curtex == MAXTEX) fatal(@"loaded too many textures"); int tnum = curtex + FIRSTTEX; strcpy_s(texname[curtex], mapname[tex][frame]); sprintf_sd(name)("packages%c%s", PATHDIV, texname[curtex]); if (installtex(tnum, name, xs, ys)) { |
︙ | ︙ |
Modified src/rendermd2.mm from [dec49d88ac] to [1644c7ed89].
︙ | ︙ | |||
234 235 236 237 238 239 240 | delayedload(MD2 *m) { if (!m.loaded) { @autoreleasepool { sprintf_sd(name1)("packages/models/%s/tris.md2", m.loadname.UTF8String); if (![m loadWithPath:path(name1)]) | | | 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | delayedload(MD2 *m) { if (!m.loaded) { @autoreleasepool { sprintf_sd(name1)("packages/models/%s/tris.md2", m.loadname.UTF8String); if (![m loadWithPath:path(name1)]) fatal(@"loadmodel: ", @(name1)); sprintf_sd(name2)("packages/models/%s/skin.jpg", m.loadname.UTF8String); int xs, ys; installtex(FIRSTMDL + m.mdlnum, path(name2), xs, ys); m.loaded = true; } } |
︙ | ︙ |
Modified src/savegamedemo.mm from [f5fe70f5b3] to [ba5f21d861].
︙ | ︙ | |||
36 37 38 39 40 41 42 | gzwrite(f, &v, sizeof(OFVector3D)); } void gzcheck(int a, int b) { if (a != b) | | | 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | gzwrite(f, &v, sizeof(OFVector3D)); } void gzcheck(int a, int b) { if (a != b) fatal(@"savegame file corrupt (short)"); } int gzget() { char c = gzgetc(f); return c; |
︙ | ︙ |
Modified src/server.mm from [9a377d37ce] to [9821265b10].
︙ | ︙ | |||
519 520 521 522 523 524 525 | if (isdedicated = dedicated) { ENetAddress address = {ENET_HOST_ANY, CUBE_SERVER_PORT}; if (*ip && enet_address_set_host(&address, ip) < 0) printf("WARNING: server ip not resolved"); serverhost = enet_host_create(&address, MAXCLIENTS, 0, uprate); if (!serverhost) | | < > | 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 | if (isdedicated = dedicated) { ENetAddress address = {ENET_HOST_ANY, CUBE_SERVER_PORT}; if (*ip && enet_address_set_host(&address, ip) < 0) printf("WARNING: server ip not resolved"); serverhost = enet_host_create(&address, MAXCLIENTS, 0, uprate); if (!serverhost) fatal(@"could not create server host\n"); loopi(MAXCLIENTS) serverhost->peers[i].data = (void *)-1; } resetserverifempty(); if (isdedicated) // do not return, this becomes main loop { #ifdef _WIN32 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); |
︙ | ︙ |
Modified src/serverms.mm from [f8b6105f9f] to [67a9f7fd73].
︙ | ︙ | |||
139 140 141 142 143 144 145 | string mname; strcpy_s(mname, isfull ? "[FULL] " : ""); strcat_s(mname, smapname); sendstring(mname, p); sendstring(serverdesc, p); buf.dataLength = p - pong; enet_socket_send(pongsock, &addr, &buf, 1); | < < > > | < < > > | 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | string mname; strcpy_s(mname, isfull ? "[FULL] " : ""); strcat_s(mname, smapname); sendstring(mname, p); sendstring(serverdesc, p); buf.dataLength = p - pong; enet_socket_send(pongsock, &addr, &buf, 1); } } void servermsinit(const char *master, const char *sdesc, bool listen) { const char *mid = strstr(master, "/"); if (!mid) mid = master; strcpy_s(masterpath, mid); strn0cpy(masterbase, master, mid - master + 1); strcpy_s(serverdesc, sdesc); if (listen) { ENetAddress address = {ENET_HOST_ANY, CUBE_SERVINFO_PORT}; pongsock = enet_socket_create(ENET_SOCKET_TYPE_DATAGRAM, &address); if (pongsock == ENET_SOCKET_NULL) fatal(@"could not create server info socket\n"); } } |
Modified src/serverutil.mm from [8452aaaef1] to [b2c8903da8].
︙ | ︙ | |||
128 129 130 131 132 133 134 | *(ushort *)start = ENET_HOST_TO_NET_16(p - start); enet_packet_resize(packet, p - start); return packet; } #ifdef STANDALONE | > | > > > | | > | | < > | 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | *(ushort *)start = ENET_HOST_TO_NET_16(p - start); enet_packet_resize(packet, p - start); return packet; } #ifdef STANDALONE void localservertoclient(uchar *buf, int len) { } void fatal(OFString *s, OFString *o) { cleanupserver(); [OFStdOut writeFormat:@"servererror: %@\n", s]; exit(1); } void * alloc(int s) { void *b = calloc(1, s); if (!b) fatal(@"no memory!"); return b; } int main(int argc, char *argv[]) { int uprate = 0, maxcl = 4; char *sdesc = "", *ip = "", *master = NULL, *passwd = ""; |
︙ | ︙ | |||
179 180 181 182 183 184 185 | break; default: printf("WARNING: unknown commandline option\n"); }; }; if (enet_initialize() < 0) | | | 184 185 186 187 188 189 190 191 192 193 194 195 | break; default: printf("WARNING: unknown commandline option\n"); }; }; if (enet_initialize() < 0) fatal(@"Unable to initialise network module"); initserver(true, uprate, sdesc, ip, master, @(passwd), maxcl); return 0; } #endif |
Modified src/sound.mm from [b86e910aec] to [ee786c999c].
︙ | ︙ | |||
66 67 68 69 70 71 72 | conoutf(@"sound init failed (SDL_mixer): %s", (size_t)Mix_GetError()); nosound = true; }; Mix_AllocateChannels(MAXCHAN); #else if (FSOUND_GetVersion() < FMOD_VERSION) | | | 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | conoutf(@"sound init failed (SDL_mixer): %s", (size_t)Mix_GetError()); nosound = true; }; Mix_AllocateChannels(MAXCHAN); #else if (FSOUND_GetVersion() < FMOD_VERSION) fatal(@"old FMOD dll"); if (!FSOUND_Init(SOUNDFREQ, MAXCHAN, FSOUND_INIT_GLOBALFOCUS)) { conoutf(@"sound init failed (FMOD): %d", FSOUND_GetError()); nosound = true; } #endif } |
︙ | ︙ |
Modified src/worldio.mm from [4981361189] to [04f91a12de].
︙ | ︙ | |||
258 259 260 261 262 263 264 | if (!f) { conoutf(@"could not read map %s", cgzname); return; } gzread(f, &hdr, sizeof(header) - sizeof(int) * 16); endianswap(&hdr.version, sizeof(int), 4); if (strncmp(hdr.head, "CUBE", 4) != 0) | | | | | 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | if (!f) { conoutf(@"could not read map %s", cgzname); return; } gzread(f, &hdr, sizeof(header) - sizeof(int) * 16); endianswap(&hdr.version, sizeof(int), 4); if (strncmp(hdr.head, "CUBE", 4) != 0) fatal(@"while reading map: header malformatted"); if (hdr.version > MAPVERSION) fatal(@"this map requires a newer version of cube"); if (sfactor < SMALLEST_FACTOR || sfactor > LARGEST_FACTOR) fatal(@"illegal map size"); if (hdr.version >= 4) { gzread(f, &hdr.waterlevel, sizeof(int) * 16); endianswap(&hdr.waterlevel, sizeof(int), 16); } else { hdr.waterlevel = -100000; } ents.setsize(0); |
︙ | ︙ | |||
325 326 327 328 329 330 331 | s->tag = 0; s->floor = 0; s->ceil = 16; break; } default: { if (type < 0 || type >= MAXTYPE) { | > | | | 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | s->tag = 0; s->floor = 0; s->ceil = 16; break; } default: { if (type < 0 || type >= MAXTYPE) { OFString *t = [OFString stringWithFormat:@"%d @ %d", type, k]; fatal(@"while reading map: type out of range: ", t); } s->type = type; s->floor = gzgetc(f); s->ceil = gzgetc(f); if (s->floor >= s->ceil) s->floor = s->ceil - 1; // for pre 12_13 |
︙ | ︙ |