Main.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. #include <stdio.h>
  2. #include <iostream>
  3. #include <fstream>
  4. #include "i/Input.h"
  5. #include "scene/PerspectiveCamera.h"
  6. #include "scene/OrthographicCamera.h"
  7. #include "m/Math.h"
  8. #include "r/Renderer.h"
  9. #include "ui/Painter.h"
  10. #include "core/App.h"
  11. #include "rsrc/Mesh.h"
  12. #include "scene/Light.h"
  13. #include "scene/PointLight.h"
  14. #include "scene/SpotLight.h"
  15. #include "rsrc/Material.h"
  16. #include "scene/Scene.h"
  17. #include "util/scanner/Scanner.h"
  18. #include "rsrc/SkelAnim.h"
  19. #include "rsrc/LightRsrc.h"
  20. #include "misc/Parser.h"
  21. #include "scene/ParticleEmitterNode.h"
  22. #include "phys/Character.h"
  23. #include "r/Renderer.h"
  24. #include "r/RendererInitializer.h"
  25. #include "r/MainRenderer.h"
  26. #include "phys/Character.h"
  27. #include "phys/RigidBody.h"
  28. #include "script/ScriptingEngine.h"
  29. #include "core/StdinListener.h"
  30. #include "scene/ModelNode.h"
  31. #include "rsrc/Model.h"
  32. #include "core/Logger.h"
  33. #include "util/Util.h"
  34. #include "util/HighRezTimer.h"
  35. #include "scene/SkinNode.h"
  36. #include "rsrc/Skin.h"
  37. #include "scene/MaterialRuntime.h"
  38. #include "core/Globals.h"
  39. #include "ui/FtFontLoader.h"
  40. #include "ui/Font.h"
  41. #include "event/Manager.h"
  42. #include "event/SceneColor.h"
  43. #include "event/MainRendererPpsHdr.h"
  44. #include "rsrc/ShaderProgramPrePreprocessor.h"
  45. #include "rsrc/Material.h"
  46. #include "core/parallel/Manager.h"
  47. #include "r/PhysDbgDrawer.h"
  48. // map (hard coded)
  49. ModelNode* floor__,* sarge,* horse,* crate,* pentagram;
  50. SkinNode* imp;
  51. //SkelModelNode* imp;
  52. PointLight* point_lights[10];
  53. SpotLight* spot_lights[2];
  54. ParticleEmitterNode* partEmitter;
  55. phys::Character* character;
  56. ui::Painter* painter;
  57. // Physics
  58. Vec<btRigidBody*> boxes;
  59. #define ARRAY_SIZE_X 5
  60. #define ARRAY_SIZE_Y 5
  61. #define ARRAY_SIZE_Z 5
  62. #define MAX_PROXIES (ARRAY_SIZE_X*ARRAY_SIZE_Y*ARRAY_SIZE_Z + 1024)
  63. #define SCALING 1.
  64. #define START_POS_X -5
  65. #define START_POS_Y -5
  66. #define START_POS_Z -3
  67. void initPhysics()
  68. {
  69. btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.)));
  70. Transform groundTransform;
  71. groundTransform.setIdentity();
  72. groundTransform.setOrigin(Vec3(0,-50, 0));
  73. phys::RigidBody::Initializer init;
  74. init.mass = 0.0;
  75. init.shape = groundShape;
  76. init.startTrf = groundTransform;
  77. new phys::RigidBody(SceneSingleton::getInstance().getPhysMasterContainer(), init);
  78. /*{
  79. btCollisionShape* colShape = new btBoxShape(btVector3(SCALING*1,SCALING*1,SCALING*1));
  80. float start_x = START_POS_X - ARRAY_SIZE_X/2;
  81. float start_y = START_POS_Y;
  82. float start_z = START_POS_Z - ARRAY_SIZE_Z/2;
  83. for (int k=0;k<ARRAY_SIZE_Y;k++)
  84. {
  85. for (int i=0;i<ARRAY_SIZE_X;i++)
  86. {
  87. for(int j = 0;j<ARRAY_SIZE_Z;j++)
  88. {
  89. //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
  90. MeshNode* crate = new MeshNode;
  91. crate->init("models/crate0/crate0.mesh");
  92. crate->getLocalTransform().setScale(1.11);
  93. Transform trf(SCALING*Vec3(2.0*i + start_x, 20+2.0*k + start_y, 2.0*j + start_z), Mat3::getIdentity(), 1.0);
  94. new RigidBody(1.0, trf, colShape, crate, Physics::CG_MAP, Physics::CG_ALL);
  95. }
  96. }
  97. }
  98. }*/
  99. }
  100. //==============================================================================
  101. // init =
  102. //==============================================================================
  103. void init()
  104. {
  105. INFO("Other init...");
  106. Material mtl;
  107. mtl.load("lala.mtl");
  108. srand(unsigned(time(NULL)));
  109. painter = new ui::Painter(Vec2(AppSingleton::getInstance().getWindowWidth(),
  110. AppSingleton::getInstance().getWindowHeight()));
  111. painter->setFont("engine-rsrc/ModernAntiqua.ttf", 25, 25);
  112. // camera
  113. PerspectiveCamera* cam = new PerspectiveCamera(false, NULL);
  114. //cam->setAll(toRad(100.0), toRad(100.0) / r::MainRendererSingleton::getInstance().getAspectRatio(), 0.5, 200.0);
  115. cam->setAll(r::MainRendererSingleton::getInstance().getAspectRatio()*toRad(60.0), toRad(60.0), 0.5, 200.0);
  116. cam->moveLocalY(3.0);
  117. cam->moveLocalZ(5.7);
  118. cam->moveLocalX(-0.3);
  119. AppSingleton::getInstance().setActiveCam(cam);
  120. INFO(cam->getSceneNodeName());
  121. OrthographicCamera* ocam = new OrthographicCamera(false, NULL);
  122. ocam->setAll(-1, 1, 1.0, -1.0, 0.1, 10.0);
  123. // lights
  124. point_lights[0] = new PointLight(false, NULL);
  125. point_lights[0]->init("maps/temple/light0.light");
  126. point_lights[0]->setLocalTransform(Transform(Vec3(-1.0, 2.4, 1.0), Mat3::getIdentity(), 1.0));
  127. point_lights[1] = new PointLight(false, NULL);
  128. point_lights[1]->init("maps/temple/light1.light");
  129. point_lights[1]->setLocalTransform(Transform(Vec3(2.5, 1.4, 1.0), Mat3::getIdentity(), 1.0));
  130. spot_lights[0] = new SpotLight(false, NULL);
  131. spot_lights[0]->init("maps/temple/light2.light");
  132. spot_lights[0]->setLocalTransform(Transform(Vec3(1.3, 4.3, 3.0), Mat3(Euler(toRad(-20), toRad(20), 0.0)), 1.0));
  133. spot_lights[1] = new SpotLight(false, NULL);
  134. spot_lights[1]->init("maps/temple/light3.light");
  135. spot_lights[1]->setLocalTransform(Transform(Vec3(-2.3, 6.3, 2.9), Mat3(Euler(toRad(-70), toRad(-20), 0.0)), 1.0));
  136. // horse
  137. horse = new ModelNode(false, NULL);
  138. horse->init("meshes/horse/horse.mdl");
  139. horse->setLocalTransform(Transform(Vec3(-2, 0, 0), Mat3::getIdentity(), 1.0));
  140. // Pentagram
  141. /*pentagram = new ModelNode(false, NULL);
  142. pentagram->init("models/pentagram/pentagram.mdl");
  143. pentagram->setLocalTransform(Transform(Vec3(2, 0, 0), Mat3::getIdentity(), 1.0));
  144. // Sponza
  145. ModelNode* sponza = new ModelNode(false, NULL);
  146. //sponza->init("maps/sponza/sponza.mdl");
  147. sponza->init("maps/sponza-crytek/sponza_crytek.mdl");
  148. sponza->setLocalTransform(Transform(Vec3(0.0), Mat3::getIdentity(), 0.05));
  149. // Imp
  150. imp = new SkinNode(false, NULL);
  151. imp->setLocalTransform(Transform(Vec3(0.0, 2.0, 0.0), Mat3::getIdentity(), 0.7));
  152. imp->init("models/imp/imp.skin");
  153. imp->skelAnimModelNodeCtrl = new SkelAnimModelNodeCtrl(*imp);
  154. imp->skelAnimModelNodeCtrl->set(imp->getSkin().getSkelAnims()[0].get());
  155. imp->skelAnimModelNodeCtrl->setStep(0.8);
  156. imp->addChild(*cam);*/
  157. // sarge
  158. /*sarge = new MeshNode();
  159. sarge->init("meshes/sphere/sphere16.mesh");
  160. //sarge->setLocalTransform(Vec3(0, -2.8, 1.0), Mat3(Euler(-m::PI/2, 0.0, 0.0)), 1.1);
  161. sarge->setLocalTransform(Transform(Vec3(0, 2.0, 2.0), Mat3::getIdentity(), 0.4));
  162. // floor
  163. floor__ = new MeshNode();
  164. floor__->init("maps/temple/Cube.019.mesh");
  165. floor__->setLocalTransform(Transform(Vec3(0.0, -0.19, 0.0), Mat3(Euler(-m::PI/2, 0.0, 0.0)), 0.8));*/
  166. // imp
  167. /*imp = new SkelModelNode();
  168. imp->init("models/imp/imp.smdl");
  169. //imp->setLocalTransform(Transform(Vec3(0.0, 2.11, 0.0), Mat3(Euler(-m::PI/2, 0.0, 0.0)), 0.7));
  170. SkelAnimCtrl* ctrl = new SkelAnimCtrl(*imp->meshNodes[0]->meshSkelCtrl->skelNode);
  171. ctrl->skelAnim.loadRsrc("models/imp/walk.imp.anim");
  172. ctrl->step = 0.8;*/
  173. // cave map
  174. /*for(int i=1; i<21; i++)
  175. {
  176. MeshNode* node = new MeshNode();
  177. node->init(("maps/cave/rock." + lexical_cast<string>(i) + ".mesh").c_str());
  178. node->setLocalTransform(Transform(Vec3(0.0, -0.0, 0.0), Mat3::getIdentity(), 0.01));
  179. }*/
  180. // sponza map
  181. /*MeshNode* node = new MeshNode();
  182. node->init("maps/sponza/floor.mesh");
  183. node = new MeshNode();
  184. node->init("maps/sponza/walls.mesh");
  185. node = new MeshNode();
  186. node->init("maps/sponza/light-marbles.mesh");
  187. node = new MeshNode();
  188. node->init("maps/sponza/dark-marbles.mesh");*/
  189. //node->setLocalTransform(Transform(Vec3(0.0, -0.0, 0.0), Mat3::getIdentity(), 0.01));
  190. // particle emitter
  191. partEmitter = new ParticleEmitterNode(false, NULL);
  192. partEmitter->init("asdf");
  193. partEmitter->getLocalTransform().setOrigin(Vec3(3.0, 0.0, 0.0));
  194. return;
  195. // character
  196. /*PhyCharacter::Initializer init;
  197. init.sceneNode = imp;
  198. init.startTrf = Transform(Vec3(0, 40, 0), Mat3::getIdentity(), 1.0);
  199. character = new PhyCharacter(SceneSingleton::getInstance().getPhysics(), init);*/
  200. // crate
  201. /*crate = new MeshNode;
  202. crate->init("models/crate0/crate0.mesh");
  203. crate->scaleLspace = 1.0;*/
  204. //
  205. //floor_ = new floor_t;
  206. //floor_->material = RsrcMngr::materials.load("materials/default.mtl");
  207. initPhysics();
  208. //INFO("Engine initialization ends (" << (App::getTicks() - ticks) << ")");
  209. }
  210. //==============================================================================
  211. // =
  212. //==============================================================================
  213. void mainLoopExtra()
  214. {
  215. InputSingleton::getInstance().handleEvents();
  216. float dist = 0.2;
  217. float ang = toRad(3.0);
  218. float scale = 0.01;
  219. // move the camera
  220. static SceneNode* mover = AppSingleton::getInstance().getActiveCam();
  221. if(InputSingleton::getInstance().getKey(SDL_SCANCODE_1)) mover = AppSingleton::getInstance().getActiveCam();
  222. if(InputSingleton::getInstance().getKey(SDL_SCANCODE_2)) mover = point_lights[0];
  223. if(InputSingleton::getInstance().getKey(SDL_SCANCODE_3)) mover = spot_lights[0];
  224. if(InputSingleton::getInstance().getKey(SDL_SCANCODE_4)) mover = point_lights[1];
  225. if(InputSingleton::getInstance().getKey(SDL_SCANCODE_5)) mover = spot_lights[1];
  226. if(InputSingleton::getInstance().getKey(SDL_SCANCODE_6)) mover = imp;
  227. if(InputSingleton::getInstance().getKey(SDL_SCANCODE_7)) mover =
  228. SceneSingleton::getInstance().getParticleEmitterNodes()[0];
  229. //if(InputSingleton::getInstance().getKey(SDL_SCANCODE_M) == 1) InputSingleton::getInstance().warpMouse = !InputSingleton::getInstance().warpMouse;
  230. if(InputSingleton::getInstance().getKey(SDL_SCANCODE_A)) mover->moveLocalX(-dist);
  231. if(InputSingleton::getInstance().getKey(SDL_SCANCODE_D)) mover->moveLocalX(dist);
  232. if(InputSingleton::getInstance().getKey(SDL_SCANCODE_LSHIFT)) mover->moveLocalY(dist);
  233. if(InputSingleton::getInstance().getKey(SDL_SCANCODE_SPACE)) mover->moveLocalY(-dist);
  234. if(InputSingleton::getInstance().getKey(SDL_SCANCODE_W)) mover->moveLocalZ(-dist);
  235. if(InputSingleton::getInstance().getKey(SDL_SCANCODE_S)) mover->moveLocalZ(dist);
  236. if(!InputSingleton::getInstance().warpMouse())
  237. {
  238. if(InputSingleton::getInstance().getKey(SDL_SCANCODE_UP)) mover->rotateLocalX(ang);
  239. if(InputSingleton::getInstance().getKey(SDL_SCANCODE_DOWN)) mover->rotateLocalX(-ang);
  240. if(InputSingleton::getInstance().getKey(SDL_SCANCODE_LEFT)) mover->rotateLocalY(ang);
  241. if(InputSingleton::getInstance().getKey(SDL_SCANCODE_RIGHT)) mover->rotateLocalY(-ang);
  242. }
  243. else
  244. {
  245. float accel = 44.0;
  246. mover->rotateLocalX(ang * InputSingleton::getInstance().mouseVelocity.y() * accel);
  247. mover->rotateLocalY(-ang * InputSingleton::getInstance().mouseVelocity.x() * accel);
  248. }
  249. if(InputSingleton::getInstance().getKey(SDL_SCANCODE_Q)) mover->rotateLocalZ(ang);
  250. if(InputSingleton::getInstance().getKey(SDL_SCANCODE_E)) mover->rotateLocalZ(-ang);
  251. if(InputSingleton::getInstance().getKey(SDL_SCANCODE_PAGEUP)) mover->getLocalTransform().getScale() += scale ;
  252. if(InputSingleton::getInstance().getKey(SDL_SCANCODE_PAGEDOWN)) mover->getLocalTransform().getScale() -= scale ;
  253. if(InputSingleton::getInstance().getKey(SDL_SCANCODE_K))
  254. AppSingleton::getInstance().getActiveCam()->lookAtPoint(point_lights[0]->getWorldTransform().getOrigin());
  255. if(InputSingleton::getInstance().getKey(SDL_SCANCODE_I))
  256. character->moveForward(0.1);
  257. /*if(InputSingleton::getInstance().getKey(SDL_SCANCODE_F) == 1)
  258. {
  259. Event::ManagerSingleton::getInstance().createEvent(Event::MainRendererPpsHdr(HighRezTimer::getCrntTime() + 5,
  260. 5, r::MainRendererSingleton::getInstance().getPps().getHdr().getExposure() + 20.0, 3, 1.4));
  261. }*/
  262. if(InputSingleton::getInstance().getKey(SDL_SCANCODE_O) == 1)
  263. {
  264. btRigidBody* body = static_cast<btRigidBody*>(boxes[0]);
  265. //body->getMotionState()->setWorldTransform(toBt(Mat4(Vec3(0.0, 10.0, 0.0), Mat3::getIdentity(), 1.0)));
  266. body->setWorldTransform(toBt(Mat4(Vec3(0.0, 10.0, 0.0), Mat3::getIdentity(), 1.0)));
  267. //body->clearForces();
  268. body->forceActivationState(ACTIVE_TAG);
  269. }
  270. if(InputSingleton::getInstance().getKey(SDL_SCANCODE_Y) == 1)
  271. {
  272. INFO("Exec script");
  273. ScriptingEngineSingleton::getInstance().execScript(util::readFile("test.py").c_str());
  274. }
  275. mover->getLocalTransform().getRotation().reorthogonalize();
  276. //INFO(mover->getSceneNodeName())
  277. /*if(spot_lights[0]->getCamera().insideFrustum(spot_lights[1]->getCamera()))
  278. {
  279. INFO("in");
  280. }
  281. else
  282. {
  283. INFO("out");
  284. }*/
  285. }
  286. //==============================================================================
  287. // mainLoop =
  288. //==============================================================================
  289. void mainLoop()
  290. {
  291. INFO("Entering main loop");
  292. HighRezTimer mainLoopTimer;
  293. mainLoopTimer.start();
  294. HighRezTimer::Scalar prevUpdateTime = HighRezTimer::getCrntTime();
  295. HighRezTimer::Scalar crntTime = prevUpdateTime;
  296. while(1)
  297. {
  298. HighRezTimer timer;
  299. timer.start();
  300. prevUpdateTime = crntTime;
  301. crntTime = HighRezTimer::getCrntTime();
  302. //
  303. // Update
  304. //
  305. mainLoopExtra();
  306. void execStdinScpripts();
  307. execStdinScpripts();
  308. SceneSingleton::getInstance().getPhysMasterContainer().update(prevUpdateTime, crntTime);
  309. SceneSingleton::getInstance().updateAllWorldStuff(prevUpdateTime, crntTime);
  310. SceneSingleton::getInstance().doVisibilityTests(*AppSingleton::getInstance().getActiveCam());
  311. SceneSingleton::getInstance().updateAllControllers();
  312. event::ManagerSingleton::getInstance().updateAllEvents(prevUpdateTime, crntTime);
  313. r::MainRendererSingleton::getInstance().render(*AppSingleton::getInstance().getActiveCam());
  314. painter->setPosition(Vec2(0.0, 0.1));
  315. painter->setColor(Vec4(1.0));
  316. //painter->drawText("A");
  317. const r::MainRenderer& r = r::MainRendererSingleton::getInstance();
  318. std::stringstream ss;
  319. ss << "MS: " << r.getMsTime() * 1000000 << " IS: " <<
  320. r.getIsTime() * 1000000 << " BS: " << r.getBsTime() * 1000000 <<
  321. " PPS: " << r.getPpsTime() * 1000000 << " DBG: " <<
  322. r.getDbgTime() * 1000000;
  323. ss << "\n" << AppSingleton::getInstance().getActiveCam()->
  324. getVisibleMsRenderableNodes().size();
  325. painter->drawText(ss.str());
  326. if(InputSingleton::getInstance().getKey(SDL_SCANCODE_ESCAPE))
  327. {
  328. break;
  329. }
  330. if(InputSingleton::getInstance().getKey(SDL_SCANCODE_F11))
  331. {
  332. AppSingleton::getInstance().togleFullScreen();
  333. }
  334. if(InputSingleton::getInstance().getKey(SDL_SCANCODE_F12) == 1)
  335. {
  336. r::MainRendererSingleton::getInstance().takeScreenshot("gfx/screenshot.jpg");
  337. }
  338. AppSingleton::getInstance().swapBuffers();
  339. //
  340. // Async resource loading
  341. //
  342. if(ResourceManagerSingleton::getInstance().getAsyncLoadingRequestsNum() > 0)
  343. {
  344. HighRezTimer::Scalar a = timer.getElapsedTime();
  345. HighRezTimer::Scalar b = AppSingleton::getInstance().getTimerTick();
  346. HighRezTimer::Scalar timeToSpendForRsrcPostProcess;
  347. if(a < b)
  348. {
  349. timeToSpendForRsrcPostProcess = b - a;
  350. }
  351. else
  352. {
  353. timeToSpendForRsrcPostProcess = 0.001;
  354. }
  355. ResourceManagerSingleton::getInstance().postProcessFinishedLoadingRequests(timeToSpendForRsrcPostProcess);
  356. }
  357. //
  358. // Sleep
  359. //
  360. timer.stop();
  361. if(timer.getElapsedTime() < AppSingleton::getInstance().getTimerTick())
  362. {
  363. SDL_Delay((AppSingleton::getInstance().getTimerTick() - timer.getElapsedTime()) * 1000.0);
  364. }
  365. /*if(r::MainRendererSingleton::getInstance().getFramesNum() == 100)
  366. {
  367. break;
  368. }*/
  369. }
  370. INFO("Exiting main loop (" << mainLoopTimer.getElapsedTime() << " sec)");
  371. }
  372. //==============================================================================
  373. // initSubsystems =
  374. //==============================================================================
  375. void initSubsystems(int argc, char* argv[])
  376. {
  377. // App
  378. AppSingleton::getInstance().init(argc, argv);
  379. // Main renderer
  380. r::RendererInitializer initializer;
  381. initializer.ms.ez.enabled = true;
  382. initializer.dbg.enabled = true;
  383. initializer.is.sm.bilinearEnabled = true;
  384. initializer.is.sm.enabled = true;
  385. initializer.is.sm.pcfEnabled = true;
  386. initializer.is.sm.resolution = 1024;
  387. initializer.is.sm.level0Distance = 3.0;
  388. initializer.pps.hdr.enabled = true;
  389. initializer.pps.hdr.renderingQuality = 0.25;
  390. initializer.pps.hdr.blurringDist = 1.0;
  391. initializer.pps.hdr.blurringIterationsNum = 2;
  392. initializer.pps.hdr.exposure = 4.0;
  393. initializer.pps.ssao.blurringIterationsNum = 4;
  394. initializer.pps.ssao.enabled = true;
  395. initializer.pps.ssao.renderingQuality = 0.3;
  396. initializer.pps.bl.enabled = true;
  397. initializer.pps.bl.blurringIterationsNum = 2;
  398. initializer.pps.bl.sideBlurFactor = 1.0;
  399. initializer.mainRendererQuality = 1.0;
  400. r::MainRendererSingleton::getInstance().init(initializer);
  401. // Scripting engine
  402. const char* commonPythonCode =
  403. "import sys\n"
  404. "from Anki import *\n"
  405. "\n"
  406. "class StdoutCatcher:\n"
  407. " def write(self, str_):\n"
  408. " if str_ == \"\\n\": return\n"
  409. " line = sys._getframe(1).f_lineno\n"
  410. " file = sys._getframe(1).f_code.co_filename\n"
  411. " func = sys._getframe(1).f_code.co_name\n"
  412. " LoggerSingleton.getInstance().write(file, line, "
  413. "func, str_ + \"\\n\")\n"
  414. "\n"
  415. "class StderrCatcher:\n"
  416. " def write(self, str_):\n"
  417. " line = sys._getframe(1).f_lineno\n"
  418. " file = sys._getframe(1).f_code.co_filename\n"
  419. " func = sys._getframe(1).f_code.co_name\n"
  420. " LoggerSingleton.getInstance().write(file, line, func, str_)\n"
  421. "\n"
  422. "sys.stdout = StdoutCatcher()\n"
  423. "sys.stderr = StderrCatcher()\n";
  424. ScriptingEngineSingleton::getInstance().execScript(commonPythonCode);
  425. // Stdin listener
  426. StdinListenerSingleton::getInstance().start();
  427. // Parallel jobs
  428. parallel::ManagerSingleton::getInstance().init(4);
  429. // Add drawer to physics
  430. SceneSingleton::getInstance().getPhysMasterContainer().setDebugDrawer(
  431. new r::PhysDbgDrawer(r::MainRendererSingleton::getInstance().getDbg()));
  432. }
  433. //==============================================================================
  434. // execStdinScpripts =
  435. //==============================================================================
  436. /// The func pools the stdinListener for string in the console, if
  437. /// there are any it executes them with scriptingEngine
  438. void execStdinScpripts()
  439. {
  440. while(1)
  441. {
  442. std::string cmd = StdinListenerSingleton::getInstance().getLine();
  443. if(cmd.length() < 1)
  444. {
  445. break;
  446. }
  447. try
  448. {
  449. ScriptingEngineSingleton::getInstance().execScript(cmd.c_str(),
  450. "command line input");
  451. }
  452. catch(Exception& e)
  453. {
  454. ERROR(e.what());
  455. }
  456. }
  457. }
  458. //==============================================================================
  459. // main =
  460. //==============================================================================
  461. int main(int argc, char* argv[])
  462. {
  463. int exitCode;
  464. try
  465. {
  466. initSubsystems(argc, argv);
  467. init();
  468. mainLoop();
  469. INFO("Exiting...");
  470. AppSingleton::getInstance().quit(EXIT_SUCCESS);
  471. exitCode = 0;
  472. }
  473. catch(std::exception& e)
  474. {
  475. //ERROR("Aborting: " << e.what());
  476. std::cerr << "Aborting: " << e.what() << std::endl;
  477. //abort();
  478. exitCode = 1;
  479. }
  480. return exitCode;
  481. }