Skip to content

Commit bccd603

Browse files
committed
Merge branch 'stable' into protobreak
2 parents 11794c7 + a53bcfc commit bccd603

File tree

213 files changed

+4977
-6518
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

213 files changed

+4977
-6518
lines changed

client/sdl/SDLMain.m

+26-26
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ - (void)setAppleMenu:(NSMenu *)menu;
5050

5151
static int gArgc;
5252
static char **gArgv;
53-
static BOOL gFinderLaunch;
54-
static BOOL gCalledAppMainline = FALSE;
53+
static bool gFinderLaunch;
54+
static bool gCalledAppMainline = false;
5555

5656
static NSString *getApplicationName(void)
5757
{
@@ -62,7 +62,7 @@ - (void)setAppleMenu:(NSMenu *)menu;
6262
dict = (NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle());
6363
if (dict)
6464
appName = [dict objectForKey: @"CFBundleName"];
65-
65+
6666
if (![appName length])
6767
appName = [[NSProcessInfo processInfo] processName];
6868

@@ -94,7 +94,7 @@ - (void)terminate:(id)sender
9494
@implementation SDLMain
9595

9696
/* Set the working directory to the .app's parent directory */
97-
- (void) setupWorkingDirectory:(BOOL)shouldChdir
97+
- (void) setupWorkingDirectory:(bool)shouldChdir
9898
{
9999
if (shouldChdir)
100100
{
@@ -144,10 +144,10 @@ static void setApplicationMenu(void)
144144
NSMenuItem *menuItem;
145145
NSString *title;
146146
NSString *appName;
147-
147+
148148
appName = getApplicationName();
149149
appleMenu = [[NSMenu alloc] initWithTitle:@""];
150-
150+
151151
/* Add menu items */
152152
title = [@"About " stringByAppendingString:appName];
153153
[appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
@@ -167,7 +167,7 @@ static void setApplicationMenu(void)
167167
title = [@"Quit " stringByAppendingString:appName];
168168
[appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
169169

170-
170+
171171
/* Put menu into the menubar */
172172
menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
173173
[menuItem setSubmenu:appleMenu];
@@ -189,17 +189,17 @@ static void setupWindowMenu(void)
189189
NSMenuItem *menuItem;
190190

191191
windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
192-
192+
193193
/* "Minimize" item */
194194
menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
195195
[windowMenu addItem:menuItem];
196196
[menuItem release];
197-
197+
198198
/* Put menu into the menubar */
199199
windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
200200
[windowMenuItem setSubmenu:windowMenu];
201201
[[NSApp mainMenu] addItem:windowMenuItem];
202-
202+
203203
/* Tell the application object that this is now the window menu */
204204
[NSApp setWindowsMenu:windowMenu];
205205

@@ -216,7 +216,7 @@ static void CustomApplicationMain (int argc, char **argv)
216216

217217
/* Ensure the application object is initialised */
218218
[SDLApplication sharedApplication];
219-
219+
220220
#ifdef SDL_USE_CPS
221221
{
222222
CPSProcessSerNum PSN;
@@ -236,10 +236,10 @@ static void CustomApplicationMain (int argc, char **argv)
236236
/* Create SDLMain and make it the app delegate */
237237
sdlMain = [[SDLMain alloc] init];
238238
[NSApp setDelegate:sdlMain];
239-
239+
240240
/* Start the main event loop */
241241
[NSApp run];
242-
242+
243243
[sdlMain release];
244244
[pool release];
245245
}
@@ -262,37 +262,37 @@ static void CustomApplicationMain (int argc, char **argv)
262262
*
263263
* This message is ignored once the app's mainline has been called.
264264
*/
265-
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
265+
- (bool)application:(NSApplication *)theApplication openFile:(NSString *)filename
266266
{
267267
const char *temparg;
268268
size_t arglen;
269269
char *arg;
270270
char **newargv;
271271

272272
if (!gFinderLaunch) /* MacOS is passing command line args. */
273-
return FALSE;
273+
return false;
274274

275275
if (gCalledAppMainline) /* app has started, ignore this document. */
276-
return FALSE;
276+
return false;
277277

278278
temparg = [filename UTF8String];
279279
arglen = SDL_strlen(temparg) + 1;
280280
arg = (char *) SDL_malloc(arglen);
281281
if (arg == NULL)
282-
return FALSE;
282+
return false;
283283

284284
newargv = (char **) realloc(gArgv, sizeof (char *) * (gArgc + 2));
285285
if (newargv == NULL)
286286
{
287287
SDL_free(arg);
288-
return FALSE;
288+
return false;
289289
}
290290
gArgv = newargv;
291291

292292
SDL_strlcpy(arg, temparg, arglen);
293293
gArgv[gArgc++] = arg;
294294
gArgv[gArgc] = NULL;
295-
return TRUE;
295+
return true;
296296
}
297297

298298

@@ -310,7 +310,7 @@ - (void) applicationDidFinishLaunching: (NSNotification *) note
310310
#endif
311311

312312
/* Hand off to main application code */
313-
gCalledAppMainline = TRUE;
313+
gCalledAppMainline = true;
314314
status = SDL_main (gArgc, gArgv);
315315

316316
/* We're done, thank you for playing */
@@ -332,27 +332,27 @@ - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString
332332

333333
bufferSize = selfLen + aStringLen - aRange.length;
334334
buffer = NSAllocateMemoryPages(bufferSize*sizeof(unichar));
335-
335+
336336
/* Get first part into buffer */
337337
localRange.location = 0;
338338
localRange.length = aRange.location;
339339
[self getCharacters:buffer range:localRange];
340-
340+
341341
/* Get middle part into buffer */
342342
localRange.location = 0;
343343
localRange.length = aStringLen;
344344
[aString getCharacters:(buffer+aRange.location) range:localRange];
345-
345+
346346
/* Get last part into buffer */
347347
localRange.location = aRange.location + aRange.length;
348348
localRange.length = selfLen - localRange.location;
349349
[self getCharacters:(buffer+aRange.location+aStringLen) range:localRange];
350-
350+
351351
/* Build output string */
352352
result = [NSString stringWithCharacters:buffer length:bufferSize];
353-
353+
354354
NSDeallocateMemoryPages(buffer, bufferSize);
355-
355+
356356
return result;
357357
}
358358

client/sdl/i_input.cpp

+29-31
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,10 @@ int I_GetKeyFromName(const std::string& name)
268268
return atoi(name.c_str() + 1);
269269

270270
// Otherwise, we scan the KeyNames[] array for a matching name
271-
for (KeyNameTable::const_iterator it = key_names.begin(); it != key_names.end(); ++it)
271+
for (const auto& [key, key_name] : key_names)
272272
{
273-
if (iequals(name, it->second))
274-
return it->first;
273+
if (iequals(name, key_name))
274+
return key;
275275
}
276276
return 0;
277277
}
@@ -291,9 +291,7 @@ std::string I_GetKeyName(int key)
291291
if (it != key_names.end() && !it->second.empty())
292292
return it->second;
293293

294-
static char name[11];
295-
snprintf(name, 11, "#%d", key);
296-
return std::string(name);
294+
return fmt::format("#{}", key);
297295
}
298296

299297

@@ -434,7 +432,7 @@ static void I_UpdateGrab()
434432
// force I_ResumeMouse or I_PauseMouse if toggling between fullscreen/windowed
435433
bool fullscreen = I_GetWindow()->isFullScreen();
436434
static bool prev_fullscreen = fullscreen;
437-
if (fullscreen != prev_fullscreen)
435+
if (fullscreen != prev_fullscreen)
438436
I_ForceUpdateGrab();
439437
prev_fullscreen = fullscreen;
440438

@@ -469,16 +467,16 @@ CVAR_FUNC_IMPL(use_joystick)
469467
CVAR_FUNC_IMPL(joy_active)
470468
{
471469
const std::vector<IInputDeviceInfo> devices = input_subsystem->getJoystickDevices();
472-
for (std::vector<IInputDeviceInfo>::const_iterator it = devices.begin(); it != devices.end(); ++it)
470+
for (const auto& device : devices)
473471
{
474-
if (it->mId == (int)var)
472+
if (device.mId == var.asInt())
475473
{
476474
I_OpenJoystick();
477475
return;
478476
}
479477
}
480478

481-
#ifdef GCONSOLE
479+
#ifdef GCONSOLE
482480
// Don't let console users choose an invalid joystick because
483481
// they won't have any way to reenable through the menu.
484482
if (!devices.empty())
@@ -490,7 +488,7 @@ CVAR_FUNC_IMPL(joy_active)
490488
//
491489
// I_GetJoystickCount
492490
//
493-
int I_GetJoystickCount()
491+
size_t I_GetJoystickCount()
494492
{
495493
const std::vector<IInputDeviceInfo> devices = input_subsystem->getJoystickDevices();
496494
return devices.size();
@@ -502,10 +500,10 @@ int I_GetJoystickCount()
502500
std::string I_GetJoystickNameFromIndex(int index)
503501
{
504502
const std::vector<IInputDeviceInfo> devices = input_subsystem->getJoystickDevices();
505-
for (std::vector<IInputDeviceInfo>::const_iterator it = devices.begin(); it != devices.end(); ++it)
503+
for (const auto& device : devices)
506504
{
507-
if (it->mId == index)
508-
return it->mDeviceName;
505+
if (device.mId == index)
506+
return device.mDeviceName;
509507
}
510508
return "";
511509
}
@@ -517,17 +515,17 @@ std::string I_GetJoystickNameFromIndex(int index)
517515
bool I_OpenJoystick()
518516
{
519517
I_CloseJoystick(); // just in case it was left open...
520-
518+
521519
if (use_joystick != 0)
522520
{
523521
// Verify that the joystick ID indicated by the joy_active CVAR
524522
// is valid and if so, initialize that joystick
525523
const std::vector<IInputDeviceInfo> devices = input_subsystem->getJoystickDevices();
526-
for (std::vector<IInputDeviceInfo>::const_iterator it = devices.begin(); it != devices.end(); ++it)
524+
for (const auto& device : devices)
527525
{
528-
if (it->mId == joy_active.asInt())
526+
if (device.mId == joy_active.asInt())
529527
{
530-
input_subsystem->initJoystick(it->mId);
528+
input_subsystem->initJoystick(device.mId);
531529
return true;
532530
}
533531
}
@@ -543,10 +541,10 @@ void I_CloseJoystick()
543541
// Verify that the joystick ID indicated by the joy_active CVAR
544542
// is valid and if so, shutdown that joystick
545543
const std::vector<IInputDeviceInfo> devices = input_subsystem->getJoystickDevices();
546-
for (std::vector<IInputDeviceInfo>::const_iterator it = devices.begin(); it != devices.end(); ++it)
544+
for (const auto& device : devices)
547545
{
548-
if (it->mId == joy_active.asInt())
549-
input_subsystem->shutdownJoystick(it->mId);
546+
if (device.mId == joy_active.asInt())
547+
input_subsystem->shutdownJoystick(device.mId);
550548
}
551549

552550
// Reset joy position values. Wouldn't want to get stuck in a turn or something. -- Hyper_Eye
@@ -794,7 +792,7 @@ void IInputSubsystem::disableTextEntry()
794792
// Joystick hat events also repeat but each directional trigger repeats
795793
// concurrently as long as they are held down. Thus a unique value is returned
796794
// for each of them.
797-
//
795+
//
798796
static int I_GetEventRepeaterKey(const event_t* ev)
799797
{
800798
if (ev->type != ev_keydown && ev->type != ev_keyup)
@@ -854,9 +852,8 @@ void IInputSubsystem::addToEventRepeaters(event_t& ev)
854852
//
855853
void IInputSubsystem::repeatEvents()
856854
{
857-
for (EventRepeaterTable::iterator it = mEventRepeaters.begin(); it != mEventRepeaters.end(); ++it)
855+
for (auto& [_, repeater] : mEventRepeaters)
858856
{
859-
EventRepeater& repeater = it->second;
860857
uint64_t current_time = I_GetTime();
861858

862859
if (!repeater.repeating && current_time - repeater.last_time >= mRepeatDelay)
@@ -881,9 +878,8 @@ void IInputSubsystem::repeatEvents()
881878
void IInputSubsystem::gatherEvents()
882879
{
883880
event_t ev;
884-
for (InputDeviceList::iterator it = mInputDevices.begin(); it != mInputDevices.end(); ++it)
881+
for (const auto& device : mInputDevices)
885882
{
886-
IInputDevice* device = *it;
887883
device->gatherEvents();
888884
while (device->hasEvent())
889885
{
@@ -904,13 +900,15 @@ void IInputSubsystem::gatherEvents()
904900
void IInputSubsystem::gatherMouseEvents()
905901
{
906902
event_t mouseEvent;
907-
if (mMouseInputDevice != NULL)
903+
if (mMouseInputDevice != nullptr)
904+
{
908905
mMouseInputDevice->gatherEvents();
909906

910-
while (mMouseInputDevice->hasEvent())
911-
{
912-
mMouseInputDevice->getEvent(&mouseEvent);
913-
mEvents.push(mouseEvent);
907+
while (mMouseInputDevice->hasEvent())
908+
{
909+
mMouseInputDevice->getEvent(&mouseEvent);
910+
mEvents.push(mouseEvent);
911+
}
914912
}
915913
}
916914

client/sdl/i_input.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void STACK_ARGS I_ShutdownInput (void);
3838
void I_ForceUpdateGrab();
3939
void I_FlushInput();
4040

41-
int I_GetJoystickCount();
41+
size_t I_GetJoystickCount();
4242
std::string I_GetJoystickNameFromIndex (int index);
4343
bool I_OpenJoystick();
4444
void I_CloseJoystick();
@@ -60,7 +60,7 @@ class IInputDevice
6060
virtual ~IInputDevice() { }
6161

6262
virtual bool active() const = 0;
63-
virtual void pause() = 0;
63+
virtual void pause() = 0;
6464
virtual void resume() = 0;
6565
virtual void reset() = 0;
6666

@@ -137,15 +137,15 @@ class IInputSubsystem
137137
virtual void gatherMouseEvents();
138138
virtual void getEvent(event_t* ev);
139139

140-
virtual std::vector<IInputDeviceInfo> getKeyboardDevices() const = 0;
140+
virtual std::vector<IInputDeviceInfo> getKeyboardDevices() const = 0;
141141
virtual void initKeyboard(int id) = 0;
142142
virtual void shutdownKeyboard(int id) = 0;
143143

144-
virtual std::vector<IInputDeviceInfo> getMouseDevices() const = 0;
144+
virtual std::vector<IInputDeviceInfo> getMouseDevices() const = 0;
145145
virtual void initMouse(int id) = 0;
146146
virtual void shutdownMouse(int id) = 0;
147147

148-
virtual std::vector<IInputDeviceInfo> getJoystickDevices() const = 0;
148+
virtual std::vector<IInputDeviceInfo> getJoystickDevices() const = 0;
149149
virtual void initJoystick(int id) = 0;
150150
virtual void shutdownJoystick(int id) = 0;
151151

0 commit comments

Comments
 (0)