Skip to content

Commit a60af27

Browse files
Merge branch 'stable' into filesystem
2 parents f682e22 + 2bc8807 commit a60af27

File tree

176 files changed

+4243
-5641
lines changed

Some content is hidden

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

176 files changed

+4243
-5641
lines changed

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

client/sdl/i_input_sdl20.cpp

+14-15
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ void ISDL20KeyboardInputDevice::disableTextEntry()
207207
//
208208
int ISDL20KeyboardInputDevice::getTextEventValue()
209209
{
210-
constexpr size_t max_events = 32;
210+
static constexpr size_t max_events = 32;
211211
SDL_Event sdl_events[max_events];
212212

213213
SDL_PumpEvents();
@@ -858,8 +858,7 @@ ISDL20InputSubsystem::~ISDL20InputSubsystem()
858858
std::vector<IInputDeviceInfo> ISDL20InputSubsystem::getKeyboardDevices() const
859859
{
860860
std::vector<IInputDeviceInfo> devices;
861-
devices.push_back(IInputDeviceInfo());
862-
IInputDeviceInfo& device_info = devices.back();
861+
IInputDeviceInfo& device_info = devices.emplace_back();
863862
device_info.mId = 0;
864863
device_info.mDeviceName = "SDL 2.0 keyboard";
865864
return devices;
@@ -875,13 +874,13 @@ void ISDL20InputSubsystem::initKeyboard(int id)
875874

876875
const std::vector<IInputDeviceInfo> devices = getKeyboardDevices();
877876
std::string device_name;
878-
for (std::vector<IInputDeviceInfo>::const_iterator it = devices.begin(); it != devices.end(); ++it)
877+
for (const auto& device : devices)
879878
{
880-
if (it->mId == id)
881-
device_name = it->mDeviceName;
879+
if (device.mId == id)
880+
device_name = device.mDeviceName;
882881
}
883882

884-
Printf(PRINT_HIGH, "I_InitInput: intializing %s\n", device_name.c_str());
883+
PrintFmt(PRINT_HIGH, "I_InitInput: intializing {:s}\n", device_name);
885884

886885
setKeyboardInputDevice(new ISDL20KeyboardInputDevice(id));
887886
registerInputDevice(getKeyboardInputDevice());
@@ -930,13 +929,13 @@ void ISDL20InputSubsystem::initMouse(int id)
930929

931930
const std::vector<IInputDeviceInfo> devices = getMouseDevices();
932931
std::string device_name;
933-
for (std::vector<IInputDeviceInfo>::const_iterator it = devices.begin(); it != devices.end(); ++it)
932+
for (const auto& device : devices)
934933
{
935-
if (it->mId == id)
936-
device_name = it->mDeviceName;
934+
if (device.mId == id)
935+
device_name = device.mDeviceName;
937936
}
938937

939-
Printf(PRINT_HIGH, "I_InitInput: intializing %s\n", device_name.c_str());
938+
PrintFmt(PRINT_HIGH, "I_InitInput: intializing {:s}\n", device_name);
940939

941940
setMouseInputDevice(new ISDL20MouseInputDevice(id));
942941
assert(getMouseInputDevice() != NULL);
@@ -990,13 +989,13 @@ void ISDL20InputSubsystem::initJoystick(int id)
990989

991990
const std::vector<IInputDeviceInfo> devices = getJoystickDevices();
992991
std::string device_name;
993-
for (std::vector<IInputDeviceInfo>::const_iterator it = devices.begin(); it != devices.end(); ++it)
992+
for (const auto& device : devices)
994993
{
995-
if (it->mId == id)
996-
device_name = it->mDeviceName;
994+
if (device.mId == id)
995+
device_name = device.mDeviceName;
997996
}
998997

999-
Printf(PRINT_HIGH, "I_InitInput: intializing %s\n", device_name.c_str());
998+
PrintFmt(PRINT_HIGH, "I_InitInput: intializing {:s}\n", device_name);
1000999

10011000
setJoystickInputDevice(new ISDL20JoystickInputDevice(id));
10021001
registerInputDevice(getJoystickInputDevice());

client/sdl/i_music.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ CVAR_FUNC_IMPL (snd_musicsystem)
235235
I_InitMusic();
236236

237237
if (level.music.empty())
238-
S_ChangeMusic(currentmusic.c_str(), true);
238+
S_ChangeMusic(currentmusic, true);
239239
else
240240
S_ChangeMusic(std::string(level.music.c_str(), 8), true);
241241
}

client/sdl/i_system.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,7 @@ void I_Endoom()
444444
// Hack to stop crash with disk icon
445445
in_endoom = true;
446446

447-
unsigned char* endoom_data = (unsigned char*)W_CacheLumpName(gameinfo.endoom.c_str(),
448-
PU_STATIC);
447+
unsigned char* endoom_data = (unsigned char*)W_CacheLumpName(gameinfo.endoom, PU_STATIC);
449448

450449
// Set up text mode screen
451450

@@ -1017,7 +1016,7 @@ BEGIN_COMMAND(debug_userfilename)
10171016
}
10181017

10191018
std::string userfile = M_GetUserFileName(argv[1]);
1020-
Printf("Resolved to: %s\n", userfile.c_str());
1019+
PrintFmt("Resolved to: {:s}\n", userfile);
10211020
}
10221021
END_COMMAND(debug_userfilename)
10231022

client/sdl/i_video.cpp

+14-19
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ IWindowSurface::IWindowSurface(uint16_t width, uint16_t height, const PixelForma
125125
mPalette(V_GetDefaultPalette()->colors), mPixelFormat(*format),
126126
mWidth(width), mHeight(height), mPitch(pitch), mLocks(0)
127127
{
128-
constexpr uintptr_t alignment = 16;
128+
static constexpr uintptr_t alignment = 16;
129129

130130
// Not given a pitch? Just base pitch on the given width
131131
if (pitch == 0)
@@ -194,8 +194,8 @@ IWindowSurface::IWindowSurface(IWindowSurface* base_surface, uint16_t width, uin
194194
IWindowSurface::~IWindowSurface()
195195
{
196196
// free all DCanvas objects allocated by this surface
197-
for (DCanvasCollection::iterator it = mCanvasStore.begin(); it != mCanvasStore.end(); ++it)
198-
delete *it;
197+
for (auto& canvas : mCanvasStore)
198+
delete canvas;
199199

200200
// calculate the buffer's original address when freeing mSurfaceBuffer
201201
if (mOwnsSurfaceBuffer)
@@ -679,12 +679,7 @@ std::string I_GetVideoModeString(const IVideoMode& mode)
679679
static bool I_IsModeSupported(uint8_t bpp, EWindowMode window_mode)
680680
{
681681
const IVideoModeList* modelist = I_GetVideoCapabilities()->getSupportedVideoModes();
682-
683-
for (IVideoModeList::const_iterator it = modelist->begin(); it != modelist->end(); ++it)
684-
if (it->bpp == bpp && it->window_mode == window_mode)
685-
return true;
686-
687-
return false;
682+
return std::any_of(modelist->cbegin(), modelist->cend(), [bpp, window_mode](const auto& mode){ return mode.bpp == bpp && mode.window_mode == window_mode; });
688683
}
689684

690685

@@ -727,26 +722,26 @@ static IVideoMode I_ValidateVideoMode(const IVideoMode& mode)
727722
unsigned int closest_dist = UINT_MAX;
728723
const IVideoMode* closest_mode = NULL;
729724

730-
const IVideoModeList* modelist = I_GetVideoCapabilities()->getSupportedVideoModes();
725+
const IVideoModeList& modelist = *I_GetVideoCapabilities()->getSupportedVideoModes();
731726
for (int iteration = 0; iteration < 2; iteration++)
732727
{
733-
for (IVideoModeList::const_iterator it = modelist->begin(); it != modelist->end(); ++it)
728+
for (const auto& mode : modelist)
734729
{
735-
if (*it == desired_mode) // perfect match?
736-
return *it;
730+
if (mode == desired_mode) // perfect match?
731+
return mode;
737732

738-
if (it->bpp == desired_mode.bpp && it->window_mode == desired_mode.window_mode)
733+
if (mode.bpp == desired_mode.bpp && mode.window_mode == desired_mode.window_mode)
739734
{
740-
if (iteration == 0 && (it->width < desired_mode.width || it->height < desired_mode.height))
735+
if (iteration == 0 && (mode.width < desired_mode.width || mode.height < desired_mode.height))
741736
continue;
742737

743-
unsigned int dist = (it->width - desired_mode.width) * (it->width - desired_mode.width)
744-
+ (it->height - desired_mode.height) * (it->height - desired_mode.height);
738+
unsigned int dist = (mode.width - desired_mode.width) * (mode.width - desired_mode.width)
739+
+ (mode.height - desired_mode.height) * (mode.height - desired_mode.height);
745740

746741
if (dist < closest_dist)
747742
{
748743
closest_dist = dist;
749-
closest_mode = &(*it);
744+
closest_mode = &mode;
750745
}
751746
}
752747
}
@@ -947,7 +942,7 @@ void I_InitHardware()
947942
assert(video_subsystem != NULL);
948943

949944
const IVideoMode& native_mode = I_GetVideoCapabilities()->getNativeMode();
950-
Printf(PRINT_HIGH, "I_InitHardware: native resolution: %s\n", I_GetVideoModeString(native_mode).c_str());
945+
PrintFmt(PRINT_HIGH, "I_InitHardware: native resolution: {:s}\n", I_GetVideoModeString(native_mode));
951946
}
952947
}
953948

0 commit comments

Comments
 (0)