Secretchronicles/SMC — pull request #135 by datahead8888 (2014-08-04 22:44:59+00:00)
Title: Use C++ printing and make std:: namespace usage consistent

This change
* changes printf to cerr/cout in all code except the debug_print_macro
* change the debug_print macro to have printf go to stderr
* change all instances where things are qualified with std:: to rely on using namespace std instead

This change touches a significant number of files, but most of the changes are simple in nature.
These are a few pieces you may want to review more closely:

tabs - As I mentioned in #7, my QT Creator IDE seems to have used spaces for all tabbing. There were pre-existing tabs in the source. Thus it doesn't line up always in github. My thought is to just leave it since the new code is per standard and then clean this up in the upcoming tabs task.
global_basic.hpp - This is where the debug_print macro is defined. I also added #include here.
video.cpp - It was using formatting specifiers within printf to print one decimal point. I changed it to a C++ equivalent:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c++
if( m_opengl_version >= 1.3f )
{
cout << "Info : OpenGL Version " << fixed << setprecision(1) << m_opengl_version << " is below the optimal version 1.4 and higher" << endl;

//Restore cout format settings (so that we don't change them for the entire game)
cout.unsetf(ios::fixed);
cout << setprecision(6); //6 is the default in C++
}
else
{
cerr << "Warning : OpenGL Version " << fixed << setprecision(1) << m_opengl_version << " is below version 1.3" << endl;

//Restore cerr format settings
cerr.unsetf(ios::fixed);
cerr << setprecision(6);
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

That was tested with this console program:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c++
#include
#include

using namespace std;

int main()
{
cout << "Starting precision: " << cout.precision() << endl;
cout << fixed << setprecision(1) << 3.333 << endl;
cout.unsetf(ios::fixed);
cout << setprecision(6);
cout << 34.333 << endl;
return 0;
}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--In this program, I fix it to always print 1 decimal place. Once done, I want to restore the default. I have to unsetf because of the design of C++. I then set the precision to 6 to restore the default. Once I print again, it prints exactly 3 decimal points for the last number.

I tested using this command:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c++
LD_LIBRARY_PATH=/home/datahead/boost_libs/lib ./testinstall/bin/smc 1> stdout.log 2> stderr.log
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Here are the log files from my test:
stdout.log:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c++
Showing invisible world 'Test 1' because this is a debug build.
Showing invisible world 'World 1' because this is a debug build.
Showing invisible world 'World 2' because this is a debug build.
Showing invisible world 'World 3' because this is a debug build.
Showing invisible world 'World 4' because this is a debug build.
Showing invisible world 'Test 1' because this is a debug build.
Showing invisible world 'World 1' because this is a debug build.
Showing invisible world 'World 2' because this is a debug build.
Showing invisible world 'World 3' because this is a debug build.
Showing invisible world 'World 4' because this is a debug build.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

stderr.log:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c++
Initializing resource manager and core classes
Game data directory: /home/datahead/SMC-Dev/SMC/smc/build/testinstall/share/smc
User data directory: /home/datahead/.local/share/smc
User cache directory: /home/datahead/.cache/smc
User config directory: /home/datahead/.config/smc
Configuration file is '/home/datahead/.config/smc/config.xml'.
Translation locale is en_US.UTF-8
Translation support with gettext set to:
Directory /home/datahead/SMC-Dev/SMC/smc/build/testinstall/share/smc/translations
Codeset: UTF-8
Text domain: Secret Maryo Chronicles
CEGUI log file is at '/home/datahead/.cache/smc/cegui.log'.
there is no soundcard
Loading campaigns
Loaded campaign file: /home/datahead/SMC-Dev/SMC/smc/build/testinstall/share/smc/campaigns/tutorial.smccpn
Loaded campaign file: /home/datahead/SMC-Dev/SMC/smc/build/testinstall/share/smc/campaigns/smc.smccpn
Setting up level player
Loading levels
Applying preferences
Loading world from directory '/home/datahead/SMC-Dev/SMC/smc/build/testinstall/share/smc/worlds/test_1'
Loading world from directory '/home/datahead/SMC-Dev/SMC/smc/build/testinstall/share/smc/worlds/world_1'
Loading world from directory '/home/datahead/SMC-Dev/SMC/smc/build/testinstall/share/smc/worlds/world_2'
Loading world from directory '/home/datahead/SMC-Dev/SMC/smc/build/testinstall/share/smc/worlds/world_3'
Loading world from directory '/home/datahead/SMC-Dev/SMC/smc/build/testinstall/share/smc/worlds/world_4'
Warning : Object image number 0 bigger as the array size 0, sprite type 19, name Armadillo
Loaded level: /home/datahead/SMC-Dev/SMC/smc/build/testinstall/share/smc/levels/menu_brown_1.smclvl
Preloading images and sounds...
Done preloading images and sounds.
Warning : Object image number 0 bigger as the array size 0, sprite type 19, name Armadillo
Loaded level: /home/datahead/SMC-Dev/SMC/smc/build/testinstall/share/smc/levels/game_tutorial.smclvl
Unloaded level: /home/datahead/SMC-Dev/SMC/smc/build/testinstall/share/smc/levels/game_tutorial.smclvl
Warning : Object image number 0 bigger as the array size 0, sprite type 19, name Armadillo
Loaded level: /home/datahead/SMC-Dev/SMC/smc/build/testinstall/share/smc/levels/lvl_1.smclvl
Unloaded level: /home/datahead/SMC-Dev/SMC/smc/build/testinstall/share/smc/levels/lvl_1.smclvl
Warning : Object image number 0 bigger as the array size 0, sprite type 19, name Armadillo
Warning : Object image number 0 bigger as the array size 0, sprite type 19, name Armadillo
Warning : Object image number 0 bigger as the array size 0, sprite type 19, name Armadillo
Warning : Object image number 0 bigger as the array size 0, sprite type 19, name Armadillo
Warning : Object image number 0 bigger as the array size 0, sprite type 19, name Armadillo
Warning : Object image number 0 bigger as the array size 0, sprite type 19, name Armadillo
Warning : Object image number 0 bigger as the array size 0, sprite type 19, name Armadillo
Warning : Object image number 0 bigger as the array size 0, sprite type 19, name Armadillo
Warning : Object image number 0 bigger as the array size 0, sprite type 19, name Armadillo
Warning : Object image number 0 bigger as the array size 0, sprite type 19, name Armadillo
Warning : Object image number 0 bigger as the array size 0, sprite type 19, name Armadillo
Warning : Object image number 0 bigger as the array size 0, sprite type 19, name Armadillo
Warning : Object image number 0 bigger as the array size 0, sprite type 19, name Armadillo
Warning : Object image number 0 bigger as the array size 0, sprite type 19, name Armadillo
Loaded level: /home/datahead/SMC-Dev/SMC/smc/build/testinstall/share/smc/levels/lvl_2.smclvl
Unloaded level: /home/datahead/SMC-Dev/SMC/smc/build/testinstall/share/smc/levels/lvl_2.smclvl
Warning : Object image number 0 bigger as the array size 0, sprite type 19, name Armadillo
Warning : Object image number 0 bigger as the array size 0, sprite type 19, name Armadillo
Warning : Object image number 0 bigger as the array size 0, sprite type 19, name Armadillo
Warning : Object image number 0 bigger as the array size 0, sprite type 19, name Armadillo
Warning : Object image number 0 bigger as the array size 0, sprite type 19, name Armadillo
Warning : Object image number 0 bigger as the array size 0, sprite type 19, name Armadillo
Warning : Object image number 0 bigger as the array size 0, sprite type 19, name Armadillo
Warning : Object image number 0 bigger as the array size 0, sprite type 19, name Armadillo
Loaded level: /home/datahead/SMC-Dev/SMC/smc/build/testinstall/share/smc/levels/lvl_3.smclvl
require: Loading '/home/datahead/SMC-Dev/SMC/smc/build/testinstall/share/smc/scripting/std/climbing_box.rb'
require: Loading '/home/datahead/SMC-Dev/SMC/smc/build/testinstall/share/smc/scripting/std/enable.rb'
Registering callback for event 'activate' for MRuby object 85651605 of class 'BonusBox'
Wrote preferences file '/home/datahead/.config/smc/config.xml'.
Unloaded level: /home/datahead/SMC-Dev/SMC/smc/build/testinstall/share/smc/levels/lvl_3.smclvl
Unloaded level: /home/datahead/SMC-Dev/SMC/smc/build/testinstall/share/smc/levels/menu_brown_1.smclvl
Last known SDL Error : Unsupported image format
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~