Advertisement
Thaodan

fix temp dir

May 16th, 2013
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.82 KB | None | 0 0
  1. --- simc-520-10-source/engine/sc_main.cpp 2013-05-16 16:56:02.742288811 +0200
  2. +++ sc_main.cpp 2013-05-16 19:09:35.000000000 +0200
  3. @@ -0,0 +1,225 @@
  4. +// ==========================================================================
  5. +// Dedmonwakeen's Raid DPS/TPS Simulator.
  6. +// Send questions to natehieter@gmail.com
  7. +// ==========================================================================
  8. +
  9. +#include "simulationcraft.hpp"
  10. +#include <locale>
  11. +
  12. +#ifdef SC_SIGACTION
  13. +#include <signal.h>
  14. +#endif
  15. +
  16. +namespace { // anonymous namespace ==========================================
  17. +
  18. +#ifdef SC_SIGACTION
  19. +// POSIX-only signal handler ================================================
  20. +
  21. +struct sim_signal_handler_t
  22. +{
  23. + static sim_t* global_sim;
  24. +
  25. + static void sigint( int )
  26. + {
  27. + if ( global_sim )
  28. + {
  29. + if ( global_sim -> canceled ) exit( 1 );
  30. + global_sim -> cancel();
  31. + }
  32. + }
  33. +
  34. + static void callback( int signal )
  35. + {
  36. + if ( global_sim )
  37. + {
  38. + const char* name = strsignal( signal );
  39. + fprintf( stderr, "sim_signal_handler: %s! Seed=%d Iteration=%d\n",
  40. + name, global_sim -> seed, global_sim -> current_iteration );
  41. + fflush( stderr );
  42. + }
  43. + exit( 1 );
  44. + }
  45. +
  46. + sim_signal_handler_t( sim_t* sim )
  47. + {
  48. + assert ( ! global_sim );
  49. + global_sim = sim;
  50. + struct sigaction sa;
  51. + sigemptyset( &sa.sa_mask );
  52. + sa.sa_flags = 0;
  53. +
  54. + sa.sa_handler = callback;
  55. + sigaction( SIGSEGV, &sa, 0 );
  56. +
  57. + sa.sa_handler = sigint;
  58. + sigaction( SIGINT, &sa, 0 );
  59. + }
  60. +
  61. + ~sim_signal_handler_t()
  62. + { global_sim = 0; }
  63. +};
  64. +sim_t* sim_signal_handler_t::global_sim = 0;
  65. +#else
  66. +struct sim_signal_handler_t
  67. +{
  68. + sim_signal_handler_t( sim_t* ) {}
  69. +};
  70. +#endif
  71. +
  72. +// need_to_save_profiles ====================================================
  73. +
  74. +static bool need_to_save_profiles( sim_t* sim )
  75. +{
  76. + if ( sim -> save_profiles ) return true;
  77. +
  78. + for ( size_t i = 0; i < sim -> player_list.size(); ++i )
  79. + {
  80. + player_t* p = sim -> player_list[ i ];
  81. + if ( ! p -> report_information.save_str.empty() )
  82. + return true;
  83. + }
  84. +
  85. + return false;
  86. +}
  87. +
  88. +/* Obtain a platform specific place to store the http cache file
  89. + */
  90. +std::string get_cache_directory()
  91. +{
  92. + std::string s = ".";
  93. +
  94. +#ifdef __linux__
  95. + s = getenv( "XDG_CACHE_HOME" );
  96. + if ( s.empty() )
  97. + {
  98. + s = getenv( "HOME" );
  99. + if ( ! s.empty() )
  100. + s += "/.cache";
  101. + else
  102. + s = "/tmp"; // back out
  103. + }
  104. +#endif
  105. +#ifdef _WIN32
  106. + s = getenv( "TMP" );
  107. + if ( s.empty() )
  108. + {
  109. + s = getenv( "TEMP" );
  110. + if ( s.empty() )
  111. + {
  112. + s = getenv( "HOME" );
  113. + }
  114. + }
  115. +#endif
  116. +
  117. + return s;
  118. +}
  119. +
  120. +} // anonymous namespace ====================================================
  121. +
  122. +// sim_t::main ==============================================================
  123. +
  124. +int sim_t::main( const std::vector<std::string>& args )
  125. +{
  126. + sim_signal_handler_t handler( this );
  127. +
  128. + std::string cache_directory = get_cache_directory();
  129. +
  130. + http::cache_load( ( cache_directory + DIRECTORY_DELIMITER + "simc_cache.dat" ).c_str() );
  131. + dbc::init();
  132. + module_t::init();
  133. +
  134. + sim_control_t control;
  135. +
  136. + if ( ! control.options.parse_args( args ) )
  137. + {
  138. + errorf( "ERROR! Incorrect option format..\n" );
  139. + return 1;
  140. + }
  141. + else if ( ! setup( &control ) )
  142. + {
  143. + errorf( "ERROR! Setup failure...\n" );
  144. + return 1;
  145. + }
  146. +
  147. + if ( challenge_mode ) scale_to_itemlevel = 463;
  148. +
  149. + if ( canceled ) return 1;
  150. +
  151. + util::fprintf( output_file, "\nSimulationCraft %s-%s for World of Warcraft %s %s (build level %s)\n",
  152. + SC_MAJOR_VERSION, SC_MINOR_VERSION, dbc.wow_version(), ( dbc.ptr ?
  153. +#if SC_BETA
  154. + "BETA"
  155. +#else
  156. + "PTR"
  157. +#endif
  158. + : "Live" ), util::to_string( dbc.build_level() ).c_str() );
  159. + fflush( output_file );
  160. +
  161. + if ( spell_query )
  162. + {
  163. + spell_query -> evaluate();
  164. + report::print_spell_query( this, spell_query_level );
  165. + }
  166. + else if ( need_to_save_profiles( this ) )
  167. + {
  168. + init();
  169. + util::fprintf( stdout, "\nGenerating profiles... \n" ); fflush( stdout );
  170. + report::print_profiles( this );
  171. + }
  172. + else
  173. + {
  174. + if ( max_time <= timespan_t::zero() )
  175. + {
  176. + util::fprintf( output_file, "simulationcraft: One of -max_time or -target_health must be specified.\n" );
  177. + exit( 0 );
  178. + }
  179. + if ( fabs( vary_combat_length ) >= 1.0 )
  180. + {
  181. + util::fprintf( output_file, "\n |vary_combat_length| >= 1.0, overriding to 0.0.\n" );
  182. + vary_combat_length = 0.0;
  183. + }
  184. + if ( confidence <= 0.0 || confidence >= 1.0 )
  185. + {
  186. + util::fprintf( output_file, "\nInvalid confidence, reseting to 0.95.\n" );
  187. + confidence = 0.95;
  188. + }
  189. +
  190. + util::fprintf( output_file,
  191. + "\nSimulating... ( iterations=%d, max_time=%.0f, vary_combat_length=%0.2f, optimal_raid=%d, fight_style=%s )\n",
  192. + iterations, max_time.total_seconds(), vary_combat_length, optimal_raid, fight_style.c_str() );
  193. + fflush( output_file );
  194. +
  195. +// util::fprintf( stdout, "\nGenerating baseline... \n" ); fflush( stdout );
  196. +
  197. + sim_phase_str = "Generating baseline: ";
  198. + if ( execute() )
  199. + {
  200. + scaling -> analyze();
  201. + plot -> analyze();
  202. + reforge_plot -> analyze();
  203. + util::fprintf( stdout, "\nGenerating reports...\n" ); fflush( stdout );
  204. + report::print_suite( this );
  205. + }
  206. + }
  207. +
  208. + if ( output_file != stdout )
  209. + fclose( output_file );
  210. + output_file = 0;
  211. +
  212. + http::cache_save( ( cache_directory + DIRECTORY_DELIMITER + "simc_cache.dat" ).c_str() );
  213. + dbc::de_init();
  214. +
  215. + return canceled;
  216. +}
  217. +
  218. +// ==========================================================================
  219. +// MAIN
  220. +// ==========================================================================
  221. +
  222. +int main( int argc, char** argv )
  223. +{
  224. + std::locale::global( std::locale( "C" ) );
  225. +
  226. + sim_t sim;
  227. + return sim.main( io::utf8_args( argc, argv ) );
  228. +}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement