Generate debug HUD text with ostringstream instead of snprintf.

This should fix #730.
This commit is contained in:
Kahrl 2013-06-01 01:49:59 +02:00
parent 6b2c46c431
commit 7721948a2f
1 changed files with 24 additions and 26 deletions

View File

@ -66,6 +66,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "sound_openal.h" #include "sound_openal.h"
#endif #endif
#include "event_manager.h" #include "event_manager.h"
#include <iomanip>
#include <list> #include <list>
#include "util/directiontables.h" #include "util/directiontables.h"
@ -2961,21 +2962,20 @@ void the_game(
static float endscenetime_avg = 0; static float endscenetime_avg = 0;
endscenetime_avg = endscenetime_avg * 0.95 + (float)endscenetime*0.05;*/ endscenetime_avg = endscenetime_avg * 0.95 + (float)endscenetime*0.05;*/
char temptext[300]; std::ostringstream os(std::ios_base::binary);
snprintf(temptext, 300, "%s (" os<<std::fixed
"R: range_all=%i" <<program_name_and_version
")" <<" (R: range_all="<<draw_control.range_all<<")"
" drawtime=%.0f, dtime_jitter = % .1f %%" <<std::setprecision(0)
", v_range = %.1f, RTT = %.3f", <<" drawtime = "<<drawtime_avg
program_name_and_version, <<std::setprecision(1)
draw_control.range_all, <<", dtime_jitter = "
drawtime_avg, <<(dtime_jitter1_max_fraction * 100.0)<<" %"
dtime_jitter1_max_fraction * 100.0, <<std::setprecision(1)
draw_control.wanted_range, <<", v_range = "<<draw_control.wanted_range
client.getRTT() <<std::setprecision(3)
); <<", RTT = "<<client.getRTT();
guitext->setText(narrow_to_wide(os.str()).c_str());
guitext->setText(narrow_to_wide(temptext).c_str());
guitext->setVisible(true); guitext->setVisible(true);
} }
else if(show_hud || show_chat) else if(show_hud || show_chat)
@ -2990,17 +2990,15 @@ void the_game(
if(show_debug) if(show_debug)
{ {
char temptext[300]; std::ostringstream os(std::ios_base::binary);
snprintf(temptext, 300, os<<std::setprecision(1)<<std::fixed
"(% .1f, % .1f, % .1f)" <<"(" <<(player_position.X/BS)
" (yaw = %.1f) (seed = %llu)", <<", "<<(player_position.Y/BS)
player_position.X/BS, <<", "<<(player_position.Z/BS)
player_position.Y/BS, <<") (yaw="<<(wrapDegrees_0_360(camera_yaw))
player_position.Z/BS, <<") (seed = "<<((unsigned long long)client.getMapSeed())
wrapDegrees_0_360(camera_yaw), <<")";
(unsigned long long)client.getMapSeed()); guitext2->setText(narrow_to_wide(os.str()).c_str());
guitext2->setText(narrow_to_wide(temptext).c_str());
guitext2->setVisible(true); guitext2->setVisible(true);
} }
else else