Differences From Artifact [37d676edf6]:
- File src/Cube.m — part of check-in [cc7ebd7f79] at 2025-03-26 21:47:31 on branch trunk — Run newer version of clang-format (user: js, size: 9745) [annotate] [blame] [check-ins using]
To Artifact [67dd855e73]:
- File
src/Cube.m
— part of check-in
[75e920ae30]
at
2025-03-29 14:25:43
on branch trunk
— Switch from clang-format to manual formatting
clang-format does too many weird things. (user: js, size: 9409) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
17 18 19 20 21 22 23 | } + (Cube *)sharedInstance { return (Cube *)OFApplication.sharedApplication.delegate; } | | | 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | } + (Cube *)sharedInstance { return (Cube *)OFApplication.sharedApplication.delegate; } - (void)applicationDidFinishLaunching: (OFNotification *)notification { @autoreleasepool { bool dedicated, windowed; int par = 0, uprate = 0, maxcl = 4; OFString *__autoreleasing sdesc, *__autoreleasing ip; OFString *__autoreleasing master, *__autoreleasing passwd; |
︙ | ︙ | |||
44 45 46 47 48 49 50 | { 'i', @"ip", 1, NULL, &ip }, { 'm', @"master", 1, NULL, &master }, { 'p', @"password", 1, NULL, &passwd }, { 'c', @"max-clients", 1, NULL, NULL }, { '\0', nil, 0, NULL, NULL } }; OFOptionsParser *optionsParser = | | | | | | | | 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | { 'i', @"ip", 1, NULL, &ip }, { 'm', @"master", 1, NULL, &master }, { 'p', @"password", 1, NULL, &passwd }, { 'c', @"max-clients", 1, NULL, NULL }, { '\0', nil, 0, NULL, NULL } }; OFOptionsParser *optionsParser = [OFOptionsParser parserWithOptions: options]; OFUnichar option; while ((option = [optionsParser nextOption]) != '\0') { switch (option) { case 'w': _width = optionsParser.argument.intValue; break; case 'h': _height = optionsParser.argument.intValue; break; case 'u': uprate = optionsParser.argument.intValue; break; case 'c': maxcl = optionsParser.argument.intValue; break; case ':': case '=': case '?': conoutf(@"unknown commandline option"); [OFApplication terminateWithStatus: 1]; } } if (sdesc == nil) sdesc = @""; if (ip == nil) ip = @""; if (passwd == nil) passwd = @""; _gameDataIRI = [OFFileManager.defaultManager currentDirectoryIRI]; _userDataIRI = [OFFileManager.defaultManager currentDirectoryIRI]; [OFFileManager.defaultManager createDirectoryAtIRI: [_userDataIRI IRIByAppendingPathComponent: @"demos"] createParents: true]; [OFFileManager.defaultManager createDirectoryAtIRI: [_userDataIRI IRIByAppendingPathComponent: @"savegames"] createParents: true]; if (SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO | par) < 0) fatal(@"Unable to initialize SDL"); initEntities(); initPlayers(); |
︙ | ︙ | |||
141 142 143 144 145 146 147 | SDL_ShowCursor(0); log(@"gl"); gl_init(_width, _height); log(@"basetex"); int xs, ys; | | < < | < | | < < | | < < | | < < | | < < | | < | < < | | < < | | < < | | | | | | 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 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | SDL_ShowCursor(0); log(@"gl"); gl_init(_width, _height); log(@"basetex"); int xs, ys; if (!installtex(2, [_gameDataIRI IRIByAppendingPathComponent: @"data/newchars.png"], &xs, &ys, false) || !installtex(3, [_gameDataIRI IRIByAppendingPathComponent: @"data/martin/base.png"], &xs, &ys, false) || !installtex(6, [_gameDataIRI IRIByAppendingPathComponent: @"data/martin/ball1.png"], &xs, &ys, false) || !installtex(7, [_gameDataIRI IRIByAppendingPathComponent: @"data/martin/smoke.png"], &xs, &ys, false) || !installtex(8, [_gameDataIRI IRIByAppendingPathComponent: @"data/martin/ball2.png"], &xs, &ys, false) || !installtex(9, [_gameDataIRI IRIByAppendingPathComponent: @"data/martin/ball3.png"], &xs, &ys, false) || !installtex(4, [_gameDataIRI IRIByAppendingPathComponent: @"data/explosion.jpg"], &xs, &ys, false) || !installtex(5, [_gameDataIRI IRIByAppendingPathComponent: @"data/items.png"], &xs, &ys, false) || !installtex(1, [_gameDataIRI IRIByAppendingPathComponent: @"data/crosshair.png"], &xs, &ys, false)) 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"); exec(@"data/keymap.cfg"); exec(@"data/menus.cfg"); exec(@"data/prefabs.cfg"); exec(@"data/sounds.cfg"); exec(@"servers.cfg"); if (!execfile([_userDataIRI IRIByAppendingPathComponent: @"config.cfg"])) execfile([_gameDataIRI IRIByAppendingPathComponent: @"data/defaults.cfg"]); exec(@"autoexec.cfg"); log(@"localconnect"); localconnect(); // if this map is changed, also change depthcorrect() changemap(@"metl3"); log(@"mainloop"); } OFDate *past = [OFDate date]; int ignore = 5; for (;;) { @autoreleasepool { [OFRunLoop.mainRunLoop runUntilDate: past]; Player *player1 = Player.player1; int millis = SDL_GetTicks() * gamespeed / 100; if (millis - lastmillis > 200) lastmillis = millis - 200; else if (millis - lastmillis < 1) |
︙ | ︙ | |||
291 292 293 294 295 296 297 | break; } } } } } | | | | | 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | break; } } } } } - (void)applicationWillTerminate: (OFNotification *)notification { stop(); disconnect(true, false); writecfg(); cleangl(); cleansound(); cleanupserver(); SDL_ShowCursor(1); SDL_Quit(); } - (void)showMessage: (OFString *)msg { #ifdef _WIN32 MessageBoxW( NULL, msg.UTF16String, L"cube fatal error", MB_OK | MB_SYSTEMMODAL); #else [OFStdOut writeString: msg]; #endif } - (void)screenshot { SDL_Surface *image; SDL_Surface *temp; |
︙ | ︙ | |||
335 336 337 338 339 340 341 | memcpy(dest, (char *)image->pixels + 3 * _width * (_height - 1 - idx), 3 * _width); endianswap(dest, 3, _width); } | | | < | | | | | | | | | | | 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | memcpy(dest, (char *)image->pixels + 3 * _width * (_height - 1 - idx), 3 * _width); endianswap(dest, 3, _width); } OFString *path = [OFString stringWithFormat: @"screenshots/screenshot_%d.bmp", lastmillis]; SDL_SaveBMP(temp, [_userDataIRI IRIByAppendingPathComponent: path] .fileSystemRepresentation.UTF8String); SDL_FreeSurface(temp); } SDL_FreeSurface(image); } } - (void)quit { writeservercfg(); [OFApplication terminateWithStatus: 0]; } @end // failure exit void fatal(OFConstantString *s, ...) { va_list args; va_start(args, s); OFMutableString *msg = [[OFMutableString alloc] initWithFormat: s arguments: args]; va_end(args); [msg appendFormat: @" (%s)\n", SDL_GetError()]; [Cube.sharedInstance showMessage: msg]; [OFApplication terminateWithStatus: 1]; } // normal exit COMMAND(quit, ARG_NONE, ^ { [Cube.sharedInstance quit]; }) COMMAND(screenshot, ARG_NONE, ^ { [Cube.sharedInstance screenshot]; }) |