Skip to content

Commit

Permalink
cockpit.cpp: Use boost::format instead of sprintf to build the "Your …
Browse files Browse the repository at this point in the history
…Position: ..." and "Target Position: ..." text string
  • Loading branch information
stephengtuggy committed Jan 15, 2025
1 parent 7a92f2a commit 481a838
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions engine/src/gfx/cockpit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* cockpit.cpp
*
* Copyright (C) 2001-2023 Daniel Horn, pyramid3d, Stephen G. Tuggy,
* Copyright (C) 2001-2025 Daniel Horn, pyramid3d, Stephen G. Tuggy,
* and other Vega Strike contributors
*
* https://github.com/vegastrike/Vega-Strike-Engine-Source
Expand All @@ -17,11 +17,11 @@
*
* Vega Strike is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Vega Strike. If not, see <https://www.gnu.org/licenses/>.
* along with Vega Strike. If not, see <https://www.gnu.org/licenses/>.
*/


Expand Down Expand Up @@ -1836,20 +1836,27 @@ void GameCockpit::Draw() {
//////////////////// DISPLAY CURRENT POSITION ////////////////////
if (configuration()->graphics_config.hud.debug_position) {
TextPlane tp;
char str[400]; //don't make the sprintf format too big... :-P
std::string str;
Unit *you = parent.GetUnit();
if (you) {
sprintf(str, "Your Position: (%lf,%lf,%lf); Velocity: (%f,%f,%f); Frame: %lf\n",
you->curr_physical_state.position.i, you->curr_physical_state.position.j,
you->curr_physical_state.position.k, you->Velocity.i, you->Velocity.j, you->Velocity.k,
getNewTime());
str = (boost::format("Your Position: (%1%,%2%,%3%); Velocity: (%4%,%5%,%6%); Frame: %7%\n")
% you->curr_physical_state.position.i
% you->curr_physical_state.position.j
% you->curr_physical_state.position.k
% you->Velocity.i
% you->Velocity.j
% you->Velocity.k
% getNewTime()).str();
Unit *yourtarg = you->computer.target.GetUnit();
if (yourtarg) {
sprintf(str + strlen(
str), "Target Position: (%lf,%lf,%lf); Velocity: (%f,%f,%f); Now: %lf\n",
yourtarg->curr_physical_state.position.i, yourtarg->curr_physical_state.position.j,
yourtarg->curr_physical_state.position.k, yourtarg->Velocity.i, yourtarg->Velocity.j,
yourtarg->Velocity.k, queryTime());
str += (boost::format("Target Position: (%1%,%2%,%3%); Velocity: (%4%,%5%,%6%); Now: %7%\n")
% yourtarg->curr_physical_state.position.i
% yourtarg->curr_physical_state.position.j
% yourtarg->curr_physical_state.position.k
% yourtarg->Velocity.i
% yourtarg->Velocity.j
% yourtarg->Velocity.k
% queryTime()).str();
}
}
tp.SetPos(-0.8, -0.8);
Expand Down

0 comments on commit 481a838

Please sign in to comment.