Skip to content

Commit

Permalink
Plugins|All Games: Updating String usage; other cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent 0d86919 commit 6fc0708
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 51 deletions.
13 changes: 2 additions & 11 deletions doomsday/apps/plugins/common/src/game/g_game.cpp
Expand Up @@ -466,15 +466,7 @@ void R_LoadColorPalettes()
{
if (i == numPerClass) break; // Not present.

String lumpName;
if (xlatNum < 10)
{
lumpName = String("TRANTBL%1").arg(xlatNum);
}
else
{
lumpName = String("TRANTBL%1").arg('A' + (xlatNum - 10));
}
String lumpName = String::format("TRANTBL%X", xlatNum);
xlatNum++;

LOG_AS("R_LoadColorPalettes")
Expand Down Expand Up @@ -3047,8 +3039,7 @@ static void registerGameStatusCVars()
// Fourth-weapon pieces:
for (int i = 0; i < WEAPON_FOURTH_PIECE_COUNT; ++i)
{
Block const cvarName = String("player-weapon-piece%1").arg(i + 1).toUtf8();
C_VAR_INT(cvarName.constData(), &gsvWPieces[i], READONLYCVAR, 0, 1);
C_VAR_INT(String::format("player-weapon-piece%i", i + 1), &gsvWPieces[i], READONLYCVAR, 0, 1);
}
C_VAR_INT("player-weapon-allpieces", &gsvWPieces[WEAPON_FOURTH_PIECE_COUNT], READONLYCVAR, 0, 1);
#endif
Expand Down
30 changes: 15 additions & 15 deletions doomsday/apps/plugins/common/src/game/gamesession.cpp
Expand Up @@ -103,7 +103,7 @@ namespace internal

using namespace internal;

static String const internalSavePath = "/home/cache/internal.save";
DE_STATIC_STRING(internalSavePath, "/home/cache/internal.save");
static GameSession theSession;

DE_PIMPL(GameSession)
Expand All @@ -130,13 +130,13 @@ DE_PIMPL(GameSession)
void cleanupInternalSave()
{
// Ensure the internal save folder exists.
App::fileSystem().makeFolder(internalSavePath.fileNamePath());
App::fileSystem().makeFolder(internalSavePath().fileNamePath());

// Ensure that any pre-existing internal save is destroyed.
// This may happen if the game was not shutdown properly in the event of a crash.
/// @todo It may be possible to recover this session if it was written successfully
/// before the fatal error occurred.
AbstractSession::removeSaved(internalSavePath);
AbstractSession::removeSaved(internalSavePath());
}

void resetStateForNewSession()
Expand Down Expand Up @@ -532,19 +532,19 @@ DE_PIMPL(GameSession)

self().setInProgress(false);

if (savePath.compareWithoutCase(internalSavePath))
if (savePath.compareWithoutCase(internalSavePath()))
{
// Perform necessary prep.
cleanupInternalSave();

// Copy the save to the internal savegame.
AbstractSession::copySaved(internalSavePath, savePath);
AbstractSession::copySaved(internalSavePath(), savePath);
}

//
// GameStateFolder deserialization begins.
//
auto const &saved = App::rootFolder().locate<GameStateFolder>(internalSavePath);
auto const &saved = App::rootFolder().locate<GameStateFolder>(internalSavePath());
GameStateMetadata const &metadata = saved.metadata();

// Ensure a complete game ruleset is available.
Expand Down Expand Up @@ -693,7 +693,7 @@ DE_PIMPL(GameSession)
#endif

String const mapUriAsText = self().mapUri().compose();
auto const &saved = App::rootFolder().locate<GameStateFolder>(internalSavePath);
auto const &saved = App::rootFolder().locate<GameStateFolder>(internalSavePath());
std::unique_ptr<GameStateFolder::MapStateReader> reader(makeMapStateReader(saved, mapUriAsText));
self().setThinkerMapping(reader.get());
reader->read(mapUriAsText);
Expand Down Expand Up @@ -1054,7 +1054,7 @@ void GameSession::end()
G_ResetViewEffects();
}

AbstractSession::removeSaved(internalSavePath);
AbstractSession::removeSaved(internalSavePath());

setInProgress(false);
LOG_MSG("Game ended");
Expand Down Expand Up @@ -1123,7 +1123,7 @@ void GameSession::begin(GameRules const &newRules, String const &episodeId,
d->reloadMap();

// Create the internal .save session package.
d->updateGameStateFolder(internalSavePath, metadata);
d->updateGameStateFolder(internalSavePath(), metadata);
}

void GameSession::reloadMap()
Expand All @@ -1138,7 +1138,7 @@ void GameSession::reloadMap()
{
try
{
d->loadSaved(internalSavePath);
d->loadSaved(internalSavePath());
return;
}
catch (Error const &er)
Expand All @@ -1164,7 +1164,7 @@ void GameSession::reloadMap()
d->reloadMap();

// Create the internal .save session package.
d->updateGameStateFolder(internalSavePath, d->metadata());
d->updateGameStateFolder(internalSavePath(), d->metadata());

::briefDisabled = oldBriefDisabled;
}
Expand Down Expand Up @@ -1202,7 +1202,7 @@ void GameSession::leaveMap(res::Uri const &nextMapUri, uint nextMapEntryPoint)
GameStateFolder *saved = nullptr;
if (!d->rules.values.deathmatch) // Never save in deathmatch.
{
saved = &App::rootFolder().locate<GameStateFolder>(internalSavePath);
saved = &App::rootFolder().locate<GameStateFolder>(internalSavePath());
auto &mapsFolder = saved->locate<Folder>("maps");

DE_ASSERT(saved->mode().testFlag(File::Write));
Expand Down Expand Up @@ -1323,7 +1323,7 @@ void GameSession::leaveMap(res::Uri const &nextMapUri, uint nextMapEntryPoint)
String GameSession::userDescription()
{
if (!hasBegun()) return "";
return App::rootFolder().locate<GameStateFolder>(internalSavePath)
return App::rootFolder().locate<GameStateFolder>(internalSavePath())
.metadata().gets("userDescription", "");
}

Expand Down Expand Up @@ -1356,13 +1356,13 @@ void GameSession::save(String const &saveName, String const &userDescription)
metadata.set("userDescription", chooseSaveDescription(savePath, userDescription));

// Update the existing internal .save package.
d->updateGameStateFolder(internalSavePath, metadata);
d->updateGameStateFolder(internalSavePath(), metadata);

// In networked games the server tells the clients to save also.
NetSv_SaveGame(metadata.getui("sessionId"));

// Copy the internal saved session to the destination slot.
AbstractSession::copySaved(savePath, internalSavePath);
AbstractSession::copySaved(savePath, internalSavePath());

P_SetMessage(&players[CONSOLEPLAYER], TXT_GAMESAVED);

Expand Down
4 changes: 2 additions & 2 deletions doomsday/apps/plugins/common/src/game/saveslots.cpp
Expand Up @@ -201,7 +201,7 @@ void SaveSlots::Slot::setGameStateFolder(GameStateFolder *newSession)
String statusText;
if (d->session)
{
statusText = String("associated with \"%1\"").arg(d->session->path());
statusText = String::format("associated with \"%s\"", d->session->path().c_str());
}
else
{
Expand Down Expand Up @@ -299,7 +299,7 @@ DE_PIMPL(SaveSlots)
void setAllIndexedSaves()
{
auto const &index = SaveGames::get().saveIndex();
foreach (File *file, index.files())
for (File *file : index.files())
{
fileAdded(*file, index);
}
Expand Down
12 changes: 6 additions & 6 deletions doomsday/apps/plugins/common/src/hu_menu.cpp
Expand Up @@ -2188,7 +2188,7 @@ void Hu_MenuInitPlayerClassPage()
btn->setFixedY(y);
btn->setAction(Widget::Deactivated, Hu_MenuSelectPlayerClass);
btn->setAction(Widget::FocusGained, Hu_MenuFocusOnPlayerClass);
btn->setUserValue2(int(info->plrClass));
btn->setUserValue2(NumberValue(info->plrClass));
btn->setFont(MENU_FONT1);

page->addWidget(btn);
Expand All @@ -2197,11 +2197,11 @@ void Hu_MenuInitPlayerClassPage()

// Random class button.
String const labelText = GET_TXT(TXT_RANDOMPLAYERCLASS);
int const shortcut = iswlanum(labelText.first())? labelText.first() : 0;
int const shortcut = iswalnum(labelText.first())? labelText.first() : 0;
page->addWidget(new ButtonWidget(labelText))
.setFixedY(y)
.setShortcut(shortcut)
.setUserValue2(int(PCLASS_NONE))
.setUserValue2(NumberValue(PCLASS_NONE))
.setFont(MENU_FONT1)
.setColor(MENU_COLOR1)
.setAction(Widget::Deactivated, Hu_MenuSelectPlayerClass)
Expand Down Expand Up @@ -2957,7 +2957,7 @@ void Hu_MenuPlayerClassBackgroundTicker(Widget &wi)
/// state through a focus action.
if(Widget *mop = wi.page().focusWidget())
{
playerclass_t pClass = playerclass_t(mop->userValue2().toInt());
playerclass_t pClass = playerclass_t(mop->userValue2().asInt());
if(pClass == PCLASS_NONE)
{
// Random class.
Expand Down Expand Up @@ -2985,7 +2985,7 @@ void Hu_MenuPlayerClassPreviewTicker(Widget &wi)
/// state through a focus action.
if(Widget *mop = wi.page().focusWidget())
{
playerclass_t pClass = playerclass_t(mop->userValue2().toInt());
playerclass_t pClass = playerclass_t(mop->userValue2().asInt());
if(pClass == PCLASS_NONE)
{
// Random class.
Expand Down Expand Up @@ -3495,7 +3495,7 @@ void Hu_MenuSelectSaveGame(Widget & /*wi*/, Widget::Action action)
void Hu_MenuSelectPlayerClass(Widget &wi, Widget::Action action)
{
Page &skillPage = Hu_MenuPage("Skill");
int option = wi.userValue2().toInt();
int option = wi.userValue2().asInt();

if(action != Widget::Deactivated) return;

Expand Down
6 changes: 3 additions & 3 deletions doomsday/apps/plugins/common/src/hud/widgets/chainwidget.cpp
Expand Up @@ -409,21 +409,21 @@ void guidata_chain_t::prepareAssets()
::pGem[PCLASS_FIGHTER][0] = R_DeclarePatch("LIFEGEM");
for(dint i = 1; i < NUMTEAMS; ++i)
{
::pGem[PCLASS_FIGHTER][i] = R_DeclarePatch(String("LIFEGMF%1").arg(i + 1));
::pGem[PCLASS_FIGHTER][i] = R_DeclarePatch(String::format("LIFEGMF%i", i + 1));
}

// Cleric:
::pChain[PCLASS_CLERIC] = R_DeclarePatch("CHAIN2");
for(dint i = 0; i < NUMTEAMS; ++i)
{
::pGem[PCLASS_CLERIC][i] = R_DeclarePatch(String("LIFEGMC%1").arg(i + 1));
::pGem[PCLASS_CLERIC][i] = R_DeclarePatch(String::format("LIFEGMC%i", i + 1));
}

// Mage:
::pChain[PCLASS_MAGE] = R_DeclarePatch("CHAIN3");
for(dint i = 0; i < NUMTEAMS; ++i)
{
::pGem[PCLASS_MAGE][i] = R_DeclarePatch(String("LIFEGMM%1").arg(i + 1));
::pGem[PCLASS_MAGE][i] = R_DeclarePatch(String::format("LIFEGMM%i", i + 1));
}
#endif
}
Expand Up @@ -150,7 +150,7 @@ void guidata_flight_t::prepareAssets() // static
#if __JHERETIC__ || __JHEXEN__
for(dint i = 0; i < 16; ++i)
{
::pIcon[i] = R_DeclarePatch(String("SPFLY%1").arg(i));
::pIcon[i] = R_DeclarePatch(String::format("SPFLY%i", i));
}
#endif
}
10 changes: 5 additions & 5 deletions doomsday/apps/plugins/common/src/hud/widgets/itemswidget.cpp
Expand Up @@ -120,14 +120,14 @@ void guidata_items_t::updateGeometry()
String valueAsText("Items:");
if(cfg.common.hudShownCheatCounters & CCH_ITEMS)
{
valueAsText += String(" %1/%2").arg(_value).arg(totalItems);
valueAsText += String::format(" %i/%i", _value, totalItems);
}
if(cfg.common.hudShownCheatCounters & CCH_ITEMS_PRCNT)
{
valueAsText += String(" %1%2%%3")
.arg((::cfg.common.hudShownCheatCounters & CCH_ITEMS) ? "(" : "")
.arg(totalItems ? _value * 100 / totalItems : 100)
.arg((::cfg.common.hudShownCheatCounters & CCH_ITEMS) ? ")" : "");
valueAsText += String::format(" %s%i%%%s",
(::cfg.common.hudShownCheatCounters & CCH_ITEMS) ? "(" : "",
totalItems ? _value * 100 / totalItems : 100,
(::cfg.common.hudShownCheatCounters & CCH_ITEMS) ? ")" : "");
}

FR_SetFont(font());
Expand Down
Expand Up @@ -361,7 +361,7 @@ void guidata_keys_t::prepareAssets() // static
#elif __JHEXEN__
for(dint i = 0; i < NUM_KEY_TYPES; ++i)
{
pKeys[i] = R_DeclarePatch(String("KEYSLOT%1").arg(i + 1, 0, 16).toUpper());
pKeys[i] = R_DeclarePatch(String::format("KEYSLOT%X", i + 1));
}
#endif
}
10 changes: 5 additions & 5 deletions doomsday/apps/plugins/common/src/network/d_netsv.cpp
Expand Up @@ -340,7 +340,7 @@ static res::Uri NetSv_ScanCycle(int index, maprule_t *rules = 0)
{
int tens = tmp[0] == '*' ? RNG_RandByte() % 10 : tmp[0] - '0';
int ones = tmp[1] == '*' ? RNG_RandByte() % 10 : tmp[1] - '0';
map = de::String("%1%2").arg(tens).arg(ones).toInt();
map = 10 * tens + ones;
}
#elif __JHERETIC__
episode = tmp[0] == '*' ? RNG_RandByte() % 9 : tmp[0] - '0';
Expand All @@ -349,7 +349,7 @@ static res::Uri NetSv_ScanCycle(int index, maprule_t *rules = 0)
#else // __JHEXEN__ || __JDOOM64__
int tens = tmp[0] == '*' ? RNG_RandByte() % 10 : tmp[0] - '0';
int ones = tmp[1] == '*' ? RNG_RandByte() % 10 : tmp[1] - '0';
map = de::String("%1%2").arg(tens).arg(ones).toInt();
map = 10 * tens + ones;
#endif

#if __JHEXEN__
Expand Down Expand Up @@ -661,9 +661,9 @@ void NetSv_SendGameState(int flags, int to)
{
if(!IS_NETWORK_SERVER) return;

AutoStr *gameId = AutoStr_FromTextStd(gfw_GameId().toLatin1().constData());
AutoStr *episodeId = AutoStr_FromTextStd(gfw_Session()->episodeId().toLatin1().constData());
res::Uri mapUri = gfw_Session()->mapUri();
AutoStr *gameId = AutoStr_FromTextStd(gfw_GameId());
AutoStr *episodeId = AutoStr_FromTextStd(gfw_Session()->episodeId());
res::Uri mapUri = gfw_Session()->mapUri();

// Print a short message that describes the game state.
LOG_NET_NOTE("Sending game setup: %s %s %s %s")
Expand Down
4 changes: 2 additions & 2 deletions doomsday/apps/plugins/common/src/world/player.cpp
Expand Up @@ -1807,7 +1807,7 @@ String Player_WeaponId(player_t const *plr)
}
else
{
value.append(QString::number(plr->readyWeapon));
value.append(String::asText(plr->readyWeapon));
}
#endif
#if defined(__JDOOM__) || defined(__JDOOM64__) || defined(__JHEXEN__)
Expand Down Expand Up @@ -1974,7 +1974,7 @@ void Player_UpdateStatusCVars(player_t const *player)
#if __JHEXEN__
for(int i = 0; i < WEAPON_FOURTH_PIECE_COUNT; ++i)
{
Path const varPath { String("player-weapon-piece%1").arg(i + 1), CVAR_DELIM };
const Path varPath{String::format("player-weapon-piece%i", i + 1), CVAR_DELIM};
Con_SetVariable(varPath, (player->pieces & (1 << i))? 1 : 0, SVF_WRITE_OVERRIDE);
}
static Path const var_player_weapon_allpieces("player-weapon-allpieces", CVAR_DELIM);
Expand Down

0 comments on commit 6fc0708

Please sign in to comment.