1
0
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-18 19:29:09 +00:00

Some additional sprintf and std::string cleanup

This commit is contained in:
2014-01-10 19:11:20 -08:00
parent 7de24157a5
commit abe3d465b3
10 changed files with 70 additions and 115 deletions

View File

@ -256,12 +256,12 @@ plAGAnimInstance * plAnimStage::Attach(plArmatureMod *armature, plArmatureBrain
fAnimInstance->SetCurrentTime(fLocalTime);
#ifdef DEBUG_MULTISTAGE
char sbuf[256];
snprintf(sbuf, sizeof(sbuf), "AnimStage::Attach - attaching stage %s", fAnimName.c_str());
snprintf(sbuf, arrsize(sbuf), "AnimStage::Attach - attaching stage %s", fAnimName.c_str());
plAvatarMgr::GetInstance()->GetLog()->AddLine(sbuf);
#endif
} else {
char buf[256];
snprintf(buf, sizeof(buf), "Can't find animation <%s> for animation stage. Anything could happen.", fAnimName.c_str());
snprintf(buf, arrsize(buf), "Can't find animation <%s> for animation stage. Anything could happen.", fAnimName.c_str());
hsAssert(false, buf);
#ifdef DEBUG_MULTISTAGE
plAvatarMgr::GetInstance()->GetLog()->AddLine(buf);
@ -328,7 +328,7 @@ bool plAnimStage::Detach(plArmatureMod *armature)
#ifdef DEBUG_MULTISTAGE
char sbuf[256];
snprintf(sbuf, sizeof(sbuf), "AnimStage::Detach - detaching stage %s", fAnimName.c_str());
snprintf(sbuf, arrsize(sbuf), "AnimStage::Detach - detaching stage %s", fAnimName.c_str());
plAvatarMgr::GetInstance()->GetLog()->AddLine(sbuf);
#endif
// hsStatusMessageF("Detaching plAnimStage <%s>", fAnimName.c_str());

View File

@ -2800,41 +2800,41 @@ void plAvBoneMap::AddBoneMapping(uint32_t boneID, const plSceneObject *SO)
void plArmatureMod::DebugDumpMoveKeys(int &x, int &y, int lineHeight, plDebugText &debugTxt)
{
char buff[256];
snprintf(buff, sizeof(buff), "Mouse Input Map: %s", plAvatarInputInterface::GetInstance()->GetInputMapName());
debugTxt.DrawString(x, y, buff);
debugTxt.DrawString(x, y, plString::Format("Mouse Input Map: %s",
plAvatarInputInterface::GetInstance()->GetInputMapName()));
y += lineHeight;
snprintf(buff, sizeof(buff), "Turn strength: %.2f (key: %.2f, analog: %.2f)",
GetTurnStrength(), GetKeyTurnStrength(), GetAnalogTurnStrength());
debugTxt.DrawString(x, y, buff);
debugTxt.DrawString(x, y, plString::Format("Turn strength: %.2f (key: %.2f, analog: %.2f)",
GetTurnStrength(), GetKeyTurnStrength(), GetAnalogTurnStrength()));
y += lineHeight;
GetMoveKeyString(buff);
debugTxt.DrawString(x, y, buff);
debugTxt.DrawString(x, y, GetMoveKeyString());
y += lineHeight;
}
void plArmatureMod::GetMoveKeyString(char *buff)
plString plArmatureMod::GetMoveKeyString() const
{
sprintf(buff, "Move keys: ");
plStringStream keys;
keys << "Move keys: ";
if(FastKeyDown())
strcat(buff, "FAST ");
keys << "FAST ";
if(StrafeKeyDown())
strcat(buff, "STRAFE ");
keys << "STRAFE ";
if(ForwardKeyDown())
strcat(buff, "FORWARD ");
keys << "FORWARD ";
if(BackwardKeyDown())
strcat(buff, "BACKWARD ");
keys << "BACKWARD ";
if(TurnLeftKeyDown())
strcat(buff, "TURNLEFT ");
keys << "TURNLEFT ";
if(TurnRightKeyDown())
strcat(buff, "TURNRIGHT ");
keys << "TURNRIGHT ";
if(StrafeLeftKeyDown())
strcat(buff, "STRAFELEFT ");
keys << "STRAFELEFT ";
if(StrafeRightKeyDown())
strcat(buff, "STRAFERIGHT ");
keys << "STRAFERIGHT ";
if(JumpKeyDown())
strcat(buff, "JUMP ");
keys << "JUMP ";
return keys.GetString();
}

View File

@ -279,7 +279,7 @@ public:
void SetTurnRightKeyDown(bool status = true);
void SetJumpKeyDown();
void DebugDumpMoveKeys(int &x, int &y, int lineHeight, plDebugText &debugTxt);
void GetMoveKeyString(char *buff);
plString GetMoveKeyString() const;
void SynchIfLocal(double timeNow, int force); // Just physical state
void SynchInputState(uint32_t rcvID = kInvalidPlayerID);

View File

@ -922,23 +922,23 @@ void plAvBrainClimb::DumpToDebugDisplay(int &x, int &y, int lineHeight, plDebugT
// --------------------
void plAvBrainClimb::IDumpClimbDirections(int &x, int &y, int lineHeight, plDebugText &debugTxt)
{
const char * prolog = "Allowed directions: ";
std::string str;
static const char prolog[] = "Allowed directions: ";
plStringStream str;
str = prolog;
str << prolog;
if(fAllowedDirections & plClimbMsg::kUp)
str = str + "UP ";
str << "UP ";
if(fAllowedDirections & plClimbMsg::kDown)
str = str + "DOWN ";
str << "DOWN ";
if(fAllowedDirections & plClimbMsg::kLeft)
str = str + "LEFT ";
str << "LEFT ";
if(fAllowedDirections & plClimbMsg::kRight)
str = str + "RIGHT ";
str << "RIGHT ";
if(str.size() == strlen(prolog))
str = str + "- NONE -";
if(str.GetLength() == strlen(prolog))
str << "- NONE -";
debugTxt.DrawString(x, y, str.c_str());
debugTxt.DrawString(x, y, str.GetString());
y += lineHeight;
}
@ -946,49 +946,49 @@ void plAvBrainClimb::IDumpClimbDirections(int &x, int &y, int lineHeight, plDebu
// -----------------------
void plAvBrainClimb::IDumpDismountDirections(int &x, int &y, int lineHeight, plDebugText &debugTxt)
{
const char * prolog = "Enabled dismounts: ";
std::string str;
static const char prolog[] = "Enabled dismounts: ";
plStringStream str;
str = prolog;
str << prolog;
if(fAllowedDismounts & plClimbMsg::kUp)
str = str + "UP ";
str << "UP ";
if(fAllowedDismounts & plClimbMsg::kDown)
str = str + "DOWN ";
str << "DOWN ";
if(fAllowedDismounts & plClimbMsg::kLeft)
str = str + "LEFT ";
str << "LEFT ";
if(fAllowedDismounts & plClimbMsg::kRight)
str = str + "RIGHT ";
str << "RIGHT ";
if(str.size() == strlen(prolog))
str = str + "- NONE -";
if(str.GetLength() == strlen(prolog))
str << "- NONE -";
debugTxt.DrawString(x, y, str.c_str());
debugTxt.DrawString(x, y, str.GetString());
y += lineHeight;
}
void plAvBrainClimb::IDumpBlockedDirections(int &x, int &y, int lineHeight, plDebugText &debugTxt)
{
const char * prolog = "Physically blocked: ";
std::string str;
static const char prolog[] = "Physically blocked: ";
plStringStream str;
str = prolog;
str << prolog;
if(fOldPhysicallyBlockedDirections & plClimbMsg::kUp)
str = str + "UP ";
str << "UP ";
if(fOldPhysicallyBlockedDirections & plClimbMsg::kDown)
str = str + "DOWN ";
str << "DOWN ";
if(fOldPhysicallyBlockedDirections & plClimbMsg::kLeft)
str = str + "LEFT ";
str << "LEFT ";
if(fOldPhysicallyBlockedDirections & plClimbMsg::kRight)
str = str + "RIGHT ";
str << "RIGHT ";
if(str.size() == strlen(prolog))
str = str + "- NONE -";
if(str.GetLength() == strlen(prolog))
str << "- NONE -";
debugTxt.DrawString(x, y, str.c_str());
debugTxt.DrawString(x, y, str.GetString());
y += lineHeight;
}
const char * plAvBrainClimb::WorldDirStr(plClimbMsg::Direction dir)
const char *plAvBrainClimb::WorldDirStr(plClimbMsg::Direction dir)
{
switch(dir)
{

View File

@ -104,8 +104,8 @@ public:
virtual void LoadFromSDL(const plStateDataRecord *sdl);
void DumpToDebugDisplay(int &x, int &y, int lineHeight, plDebugText &debugTxt);
const char * WorldDirStr(plClimbMsg::Direction dir);
const char *ModeStr(Mode mode);
static const char *WorldDirStr(plClimbMsg::Direction dir);
static const char *ModeStr(Mode mode);
// plasma protocol
virtual bool MsgReceive(plMessage *msg);

View File

@ -576,22 +576,21 @@ void plAvTaskSeek::DumpDebug(const char *name, int &x, int&y, int lineHeight, pl
void plAvTaskSeek::DumpToAvatarLog(plArmatureMod *avatar)
{
plStatusLog *log = plAvatarMgr::GetInstance()->GetLog();
char strBuf[256];
avatar->GetMoveKeyString(strBuf);
log->AddLine(strBuf);
log->AddLine(avatar->GetMoveKeyString().c_str());
sprintf(strBuf, " duration: %.2f pos: (%.3f, %.3f, %.3f) goalPos: (%.3f, %.3f, %.3f) ",
log->AddLine(plString::Format(" duration: %.2f pos: (%.3f, %.3f, %.3f) goalPos: (%.3f, %.3f, %.3f) ",
hsTimer::GetSysSeconds() - fStartTime,
fPosition.fX, fPosition.fY, fPosition.fZ, fSeekPos.fX, fSeekPos.fY, fSeekPos.fZ);
log->AddLine(strBuf);
sprintf(strBuf, " positioning: %d rotating %d goalVec: (%.3f, %.3f, %.3f) dist: %.3f angFwd: %.3f angRt: %.3f",
fStillPositioning, fStillRotating, fGoalVec.fX, fGoalVec.fY, fGoalVec.fZ, fDistance, fAngForward, fAngRight);
log->AddLine(strBuf);
fPosition.fX, fPosition.fY, fPosition.fZ,
fSeekPos.fX, fSeekPos.fY, fSeekPos.fZ).c_str());
sprintf(strBuf, " distFwd: %.3f distRt: %.3f shufRange: %.3f sidAngle: %.3f sidRange: %.3f, fMinWalk: %.3f",
fDistForward, fDistRight, fShuffleRange, fMaxSidleAngle, fMaxSidleRange, fMinFwdAngle);
log->AddLine(strBuf);
log->AddLine(plString::Format(" positioning: %d rotating %d goalVec: (%.3f, %.3f, %.3f) dist: %.3f angFwd: %.3f angRt: %.3f",
fStillPositioning, fStillRotating,
fGoalVec.fX, fGoalVec.fY, fGoalVec.fZ,
fDistance, fAngForward, fAngRight).c_str());
log->AddLine(plString::Format(" distFwd: %.3f distRt: %.3f shufRange: %.3f sidAngle: %.3f sidRange: %.3f, fMinWalk: %.3f",
fDistForward, fDistRight, fShuffleRange,
fMaxSidleAngle, fMaxSidleRange, fMinFwdAngle).c_str());
}
/////////////////////////////////////////////////////////////////////////////////////////

View File

@ -84,9 +84,7 @@ HRESULT hsGDirect3DTnLEnumerate::SelectFromDevMode(const hsG3DDeviceRecord* devR
}
}
}
char errStr[256];
sprintf(errStr, "Can't find requested device - %s:%s:%s:%s:%s",
plString errStr = plString::Format("Can't find requested device - %s:%s:%s:%s:%s",
devRec->GetG3DDeviceTypeName(),
devRec->GetDriverDesc().c_str(),
devRec->GetDriverName().c_str(),