Skip to content

Commit 7721948

Browse files
committedMay 31, 2013
Generate debug HUD text with ostringstream instead of snprintf.
This should fix #730.
1 parent 6b2c46c commit 7721948

File tree

1 file changed

+24
-26
lines changed

1 file changed

+24
-26
lines changed
 

‎src/game.cpp

+24-26
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
6666
#include "sound_openal.h"
6767
#endif
6868
#include "event_manager.h"
69+
#include <iomanip>
6970
#include <list>
7071
#include "util/directiontables.h"
7172

@@ -2961,21 +2962,20 @@ void the_game(
29612962
static float endscenetime_avg = 0;
29622963
endscenetime_avg = endscenetime_avg * 0.95 + (float)endscenetime*0.05;*/
29632964

2964-
char temptext[300];
2965-
snprintf(temptext, 300, "%s ("
2966-
"R: range_all=%i"
2967-
")"
2968-
" drawtime=%.0f, dtime_jitter = % .1f %%"
2969-
", v_range = %.1f, RTT = %.3f",
2970-
program_name_and_version,
2971-
draw_control.range_all,
2972-
drawtime_avg,
2973-
dtime_jitter1_max_fraction * 100.0,
2974-
draw_control.wanted_range,
2975-
client.getRTT()
2976-
);
2977-
2978-
guitext->setText(narrow_to_wide(temptext).c_str());
2965+
std::ostringstream os(std::ios_base::binary);
2966+
os<<std::fixed
2967+
<<program_name_and_version
2968+
<<" (R: range_all="<<draw_control.range_all<<")"
2969+
<<std::setprecision(0)
2970+
<<" drawtime = "<<drawtime_avg
2971+
<<std::setprecision(1)
2972+
<<", dtime_jitter = "
2973+
<<(dtime_jitter1_max_fraction * 100.0)<<" %"
2974+
<<std::setprecision(1)
2975+
<<", v_range = "<<draw_control.wanted_range
2976+
<<std::setprecision(3)
2977+
<<", RTT = "<<client.getRTT();
2978+
guitext->setText(narrow_to_wide(os.str()).c_str());
29792979
guitext->setVisible(true);
29802980
}
29812981
else if(show_hud || show_chat)
@@ -2990,17 +2990,15 @@ void the_game(
29902990

29912991
if(show_debug)
29922992
{
2993-
char temptext[300];
2994-
snprintf(temptext, 300,
2995-
"(% .1f, % .1f, % .1f)"
2996-
" (yaw = %.1f) (seed = %llu)",
2997-
player_position.X/BS,
2998-
player_position.Y/BS,
2999-
player_position.Z/BS,
3000-
wrapDegrees_0_360(camera_yaw),
3001-
(unsigned long long)client.getMapSeed());
3002-
3003-
guitext2->setText(narrow_to_wide(temptext).c_str());
2993+
std::ostringstream os(std::ios_base::binary);
2994+
os<<std::setprecision(1)<<std::fixed
2995+
<<"(" <<(player_position.X/BS)
2996+
<<", "<<(player_position.Y/BS)
2997+
<<", "<<(player_position.Z/BS)
2998+
<<") (yaw="<<(wrapDegrees_0_360(camera_yaw))
2999+
<<") (seed = "<<((unsigned long long)client.getMapSeed())
3000+
<<")";
3001+
guitext2->setText(narrow_to_wide(os.str()).c_str());
30043002
guitext2->setVisible(true);
30053003
}
30063004
else

0 commit comments

Comments
 (0)
Please sign in to comment.