Advertisement
Guest User

Untitled

a guest
Oct 31st, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 145.96 KB | None | 0 0
  1. #include "Game/StdAfx.h"
  2. #include "GS3DStuff.h"
  3. #include "Core/Tools.h"
  4.  
  5. #include "Core/Application.h"
  6. #include "Core/Managers/SoundManager.h"
  7. #include "Core/Managers/StringManager.h"
  8. #include "online/OnlineServiceManager.h"
  9.  
  10. #include "grapher/GrapherManager.h"
  11. #include "grapher/Core/ActorContext.h"
  12. #include "grapher/Core/DebugConstants.h"
  13.  
  14. #include "EventManager/EventManager.h"
  15.  
  16. #include "Game/AI/AIController.h"
  17. #include "Game/AI/BehaviorManager.h"
  18. #include "Game/AI/WantedLevelManager.h"
  19. #include "Game/Camera/CameraManager.h"
  20. #include "Game/Cinematics/CinematicManager.h"
  21. #include "Game/Cinematics/FadeManager.h"
  22. #include "Game/ControlHandlers/CControlManager.h"
  23. #include "Game/Decal/DecalManager.h"
  24. #include "Game/Events/EvTouchScreen.h"
  25. #include "Game/Objects/Basic/ShopSpawnPoint.h"
  26.  
  27. #include "Game/Gangstar/BulletTraceManager.h"
  28. #include "Game/Gangstar/daytime.h"
  29. #include "Game/Gangstar/NPC.h"
  30. #include "Game/Gangstar/Player.h"
  31. #include "Game/Gangstar/SpawnGroupManager.h"
  32.  
  33. #include "Game/Gangstar/Vehicle/Helicopter.h"
  34. #include "Game/Gangstar/Vehicle/Moto.h"
  35. #include "Game/Gangstar/Vehicle/Vehicle.h"
  36. #include "Game/Gangstar/Vehicle/Boat.h"
  37. #include "Game/Gangstar/Vehicle/Airplane.h"
  38.  
  39. #include "Game/GLitchExtensions/CustomGlitchFeatures.h"
  40. #include "Game/GLitchExtensions/CCustomIngameSceneManager.h"
  41. #include "Game/GLitchExtensions/CCustomShopSceneManager.h"
  42. #include "Game/GLitchExtensions/CCustomSceneManagerTweaker.h"
  43. #include "Game/GlitchExtensions/CCustomIrrFactory.h"
  44.  
  45. #include "Game/PostEffects/PostEffects.h"
  46.  
  47. #include "Game/Hud/Elements/Screen.h"
  48. #include "Game/Lights/LightsManager.h"
  49.  
  50. #include "Game/Managers/AbilityManager.h"
  51. #include "Game/Managers/DialogManager.h"
  52. #include "Game/Managers/ItemManager.h"
  53. #include "Game/Managers/VFXManager.h"
  54.  
  55. #include "Game/Menus/MapHandler/Map.h"
  56. #include "Game/Menus/flash_constants_generated.h"
  57. #include "Game/Menus/MapHandler/MapHandler.h"
  58. #include "Game/Menus/MenuEventManager.h"
  59. #include "Game/Menus/SwfManager.h"
  60. #include "Game/Menus/DownloadingContentMenu.h"
  61.  
  62. #include "Game/Objects/SpawnManager.h"
  63. #include "Game/Objects/basic/Transformation.h"
  64. #include "Game/Objects/Pickupable/PickupableManager.h"
  65. #include "Game/Objects/Zones/TriggerZone.h"
  66. #include "Game/PathFinding/NavMeshManager.h"
  67. #include "Game/Persistence/Preferences.h"
  68. #include "Game/Scripts/Mission.h"
  69. #include "Game/Scripts/Race.h"
  70. #include "Game/States/GSMain.h"
  71. #include "Game/States/GSFailure.h"
  72. #include "Game/States/GSBustedMenu.h"
  73. #include "Game/Story/StoryManager.h"
  74. #include "Game/Trail/TrailMgr.h"
  75.  
  76. #include "Game/Weapon/Projectile.h"
  77. #include "Game/Weapon/ProjectileManager.h"
  78. #include "Game/Managers/WeaponryManager.h"
  79. #include "Game/Gangstar/Inventory.h"
  80. #include "Game/Weapon/Weapon.h"
  81. #include "Game/World/GameObjectManager.h"
  82. #include "Game/World/StockManager.h"
  83. #include "Game/World/world.h"
  84.  
  85. #include "Utils/CGameFactory.h"
  86. #include "Utils/GameDataFilesMgr.h"
  87. #include "Utils/LoadTimeProfiling.h"
  88. #include "Utils/LoadMemoryProfiling.h"
  89. #include "Utils/LODSceneNode.h"
  90. #include "utils/LODProfiler/LODProfiler.h"
  91. #include "Utils/MemLeakAnnihilator.h"
  92.  
  93. #include "glitch/collada/CColladaSceneNode.h"
  94. #include "glitch/collada/CColladaRootSceneNode.h"
  95. #include "glitch/scene/CBatchSceneNode.h"
  96. #include "glitch/scene/CLightSceneNode.h"
  97.  
  98. #include <glf/io/archivemanager.h>
  99.  
  100. #include "IO/DataStream/DataStream.h"
  101. #include "IO/Audio/SoundEmitter.h"
  102.  
  103. #include "StateMachine/StateMachine.h"
  104.  
  105. #include "debug/autoTweak.h"
  106.  
  107.  
  108. #include "Game/Physics/PhysicsWorld.h"
  109.  
  110. #ifdef SUN_OCCLUSION
  111. #include "game/SunOcclusion/SunOcclusionManager.h"
  112. #endif
  113.  
  114. #ifdef IRRADIANCE
  115. #include <glitch/irradiance/CIrradianceManager.h>
  116. #endif
  117.  
  118. #include "Core/Debug/DebugTweakers.h"
  119. #include "Core/Debug/GrapherTweakers.h"
  120. #include "Core/Debug/LocationTweakers.h"
  121. #include "Core/Debug/MissionTweakers.h"
  122. #include "Core/Debug/TemplateTweakers.h"
  123. #include <Game/GlitchExtensions/DynamicMaterialProperties.h>
  124. #include <Game/GlitchExtensions/DynamicDataValues.h>
  125. #include "Core/Debug/DynamicMaterialPropertiesTweakers.h"
  126. #include "Core/Debug/PaletteTweakers.h"
  127. #include "Game/Objects/SpawnTaskImpl.h" //for Random::GetRandom
  128. #include "Utils/GlitchDropNodeTask.h"
  129. #include "Game/Gangstar/CityDomination/CityDominationManager.h"
  130. #include "Online/GVAdsManager.h"
  131.  
  132. #include XMLDATA_INCLUDE(script_constants)
  133. #include XMLDATA_INCLUDE(common_text_generated)
  134. #include XMLDATA_INCLUDE(locations_)
  135. #include XMLDATA_INCLUDE(dialogs_)
  136. #include XMLDATA_INCLUDE(phone_performance_profiles)
  137. #include XMLDATA_INCLUDE(shader_constants)
  138. #include XMLDATA_INCLUDE(giv_loot)
  139. #include XMLDATA_INCLUDE(giv_spawn_manager)
  140. #include XMLDATA_INCLUDE(giv_shaders)
  141. #include XMLDATA_INCLUDE(stock_items_struct)
  142. #include XMLDATA_INCLUDE(giv_daytime)
  143. #include XMLDATA_INCLUDE(materials_preload_effects)
  144.  
  145. #ifdef OS_IPHONE
  146. #include<sys/sysctl.h>
  147. int GetPhysicalMemory()
  148. {
  149. int param[] = {CTL_HW, HW_PHYSMEM};
  150. size_t len = sizeof(int);
  151. int physicalMemory;
  152. sysctl(param, 2, &physicalMemory, &len, 0, 0);
  153. return physicalMemory;
  154. }
  155. #endif
  156.  
  157. extern bool gGlitchPerfEnable2;
  158. extern bool gGlitchPerfEnable3;
  159. extern bool s_SaveLoadDoneIAP;
  160.  
  161. //////////////////////////////////////////////////////////////////////////////////////
  162. // private constants
  163. namespace
  164. {
  165. //update physic dt (used for metro)
  166. #ifdef PHYSICS_USING_ASYNCHRONOUS_UPDATE
  167. static const float PHYSIC_UPDATE_RATE = 1.0f/120.0f; // Twice as fast as the physics otherwise the transition is not good
  168. #else
  169. #ifdef WIN32
  170. static const float PHYSIC_UPDATE_RATE = 1.0f/240.0f;
  171. #else
  172. static const float PHYSIC_UPDATE_RATE = 1.0f/240.0f;
  173. #endif
  174. #endif
  175.  
  176. // Number of frame on which I want to spread the sun occlusion update. If 0, only update one object at time
  177. static const int FRAMES_FOR_COMPLETE_SUN_OCCLUSION_UPDATE = 20;
  178.  
  179. // Number of frame on which I want to spread the invisible list update
  180. static const int FRAMES_FOR_COMPLETE_INVISIBLE_LIST_UPDATE = 3;
  181.  
  182. // how many seconds does the havok logo has to be on screen?
  183. static const int HAVOK_LOGO_DELAY = 3;
  184.  
  185. // how many seconds does the GIV logo has to be on screen?
  186. static const int GIV_LOGO_DELAY = 3;
  187.  
  188. static const int EXTRA_LOADING_DURATION = 10;
  189. static const int FRESH_INSTALL_EXTRA_LOADING_DURATION = 20;
  190.  
  191. // test app magic std::string - THIS IS HARDCODED IN PYTHON, please DON'T CHANGE!
  192. static const char* TEST_OK_STRING = "4b3253bb-5283-4b9b-9a04-8bffdc866dc7: APPLICATION OK";
  193. }
  194.  
  195. ///////////////////////////////////////////////////////////////////////////////////////
  196. bool gEnableEnvironment = true;
  197.  
  198. bool gEnableHDWaterRendering = true;
  199.  
  200. bool gPrintShapeCount = false;
  201. bool gDebugTestRay = false;
  202. bool gTogglePhysic = true;
  203. bool gDrawDebugOnMap = false;
  204. bool gDebugCollisionShape = false;
  205. float gCollisionInstancingRadius = 500.0f;
  206.  
  207. bool gDebugCopPosition = false;
  208.  
  209. bool g_debugLookAt = false;
  210.  
  211. extern bool g_Loading;
  212. extern bool gDrawWaterNear;
  213. bool gIsStreamingEnabled = true;
  214.  
  215.  
  216. #if _WIN32
  217. extern bool gLodProfiling;
  218. #endif
  219.  
  220. float g_collisionFrontDistance = 75.0f; // default 75cm
  221. float g_collisionUpperDistance = 125.0f; // default 125cm
  222. /*
  223. float g_WaterSpeed = 0.22f;
  224. float g_WaterWavelength = 0.44f;
  225. float g_WaterAmplitude = 0.1f;
  226.  
  227. float g_WaterSpeed2 = 0.07f;
  228. float g_WaterWavelength2 = 0.35f;
  229. float g_WaterAmplitude2 = 0.1f;
  230. */
  231.  
  232. glitch::core::vector4df g_WindParams = glitch::core::vector4df(10.f, 8.f, 4.f, 0.5f);
  233. glitch::core::vector4df g_WindParams2 = glitch::core::vector4df(1.f, 0.f, -1.f, 0.5f);
  234.  
  235. float g_WaveUSpeed = 0.f;
  236. float g_WaveVSpeed = 0.03f;
  237. float g_NormalTiling = 30.f;
  238.  
  239. float g_WaveUSpeed2 = 0.f;
  240. float g_WaveVSpeed2 = -0.08f;
  241. float g_NormalTiling2 = 200.f;
  242.  
  243. float g_DistortionFactor = 0.03f;
  244.  
  245. glitch::video::SColorf g_DeepWaterColor(0.145f, 0.325f, 0.361f, 1.f);
  246. float g_DeepWaterDistance = 0.f;
  247.  
  248. float g_SpecPower = 50.f;
  249. float g_SpecFactor = 0.8f;
  250.  
  251. float g_WaveUSpeedLow = -0.01f;
  252. float g_WaveVSpeedLow = 0.f;
  253. float g_NormalTilingLow = 5.f;
  254.  
  255. float g_WaveUSpeed2Low = 0.02f;
  256. float g_WaveVSpeed2Low = 0.f;
  257. float g_NormalTiling2Low = 25.f;
  258.  
  259. float g_GroundGlossiness = 10.f;
  260. float g_GroundSpecFactor = 15.0f;
  261. float g_DetailTiling = 3.f;
  262. float g_DetailAmount = 0.5f;
  263. float g_GroundVehicleLightGlowOffset = 200.0f;
  264. float g_GroundVehicleLightGlowOffsetAnamorphic = 100.0f;
  265.  
  266. #ifdef DEBUG_VH_CHAR_COLLISION
  267. bool gDebugBoundingBoxes = true;
  268. #else
  269. bool gDebugBoundingBoxes = false;
  270. #endif
  271.  
  272. glitch::core::vector3df GS3DStuff::s_plStart;
  273. glitch::core::vector3df GS3DStuff::s_plEnd;
  274.  
  275. extern int g_fixedTimeStep;
  276. extern int g_BulletTimeFactor;
  277.  
  278. extern bool gCfgEnableHDWaterSupport;
  279.  
  280. template<typename T>
  281. void RemoveZ(T*& node)
  282. {
  283. if(node)
  284. {
  285. node->remove();
  286. node = 0;
  287. }
  288. }
  289.  
  290. template<typename T>
  291. void DropZ(boost::intrusive_ptr<T>& node)
  292. {
  293. if(node)
  294. {
  295. node->remove();
  296. node.reset();
  297. }
  298. }
  299.  
  300. typedef glitch::video::SVertexStream::SDataAccessor<glitch::core::vector3df> DataAccessorConstVec3;
  301. typedef glitch::video::SVertexStream::SDataAccessor<glitch::core::vector3df> DataAccessorVec3;
  302. typedef glitch::video::CPrimitiveStream::SDataAccessor<glitch::u16> DataAccessorConstIdx;
  303.  
  304. using namespace glitch;
  305. using namespace core;
  306. using namespace scene;
  307. using namespace video;
  308. using namespace io;
  309. using namespace gui;
  310.  
  311. #if defined(WIN32)
  312. unsigned int GS3DStuff::waiting = 0;
  313. #endif
  314. BulletTraceManager* GS3DStuff::s_bulletManager = 0;
  315. TrailMgr* GS3DStuff::s_TrailMgr = 0;
  316. DecalManager* GS3DStuff::s_DecalManager = 0;
  317. GameObjectManager* GS3DStuff::gom;
  318. unsigned int GS3DStuff::s_dt;
  319. glitch::scene::ISceneNodePtr GS3DStuff::s_MissionTrailSpline;
  320.  
  321. Std<glitch::core::vector3df>::Vector GS3DStuff::BufferedLinePositions;
  322. Std<glitch::video::SColor>::Vector GS3DStuff::BufferedLineColor;
  323. Std<unsigned short>::Vector GS3DStuff::BufferedLineIndexes;
  324.  
  325. glitch::scene::ISceneNodePtr GS3DStuff::gWaterScene = 0;
  326.  
  327. glitch::video::ITexturePtr GS3DStuff::s_roadSpecLut = 0;
  328. glitch::video::ITexturePtr GS3DStuff::s_carSpecLut = 0;
  329. float GS3DStuff::s_carGlossiness = 0.f;
  330. float GS3DStuff::s_carSpecFactor = 0.f;
  331. TriggerZone* GS3DStuff::s_lastTriggerZone = 0;
  332.  
  333. float gTimeAccumulator = 0.f;
  334. int gNumPhysicIteration = 0;
  335.  
  336. int currentLocation = -1;
  337. static std::string currentLocationXML = "";
  338. static grapher::ActorContext locationContext("locationContext");
  339. static int gJustUpdateFrame = 0;
  340. static int gCheckForDespawnFrame = 0;
  341.  
  342. StdString GS3DStuff::s_currentCubeMapName;
  343. bool GS3DStuff::s_isDayEnvMap = true;
  344. bool GS3DStuff::s_isLogoHasBeenDisplayedEnough = false;
  345.  
  346. #if DLC_FLOW_ENABLED
  347. static bool s_isProcessingMandatoryDlc = false;
  348. static bool s_isRetryingDownloadMandatoryDlc = true;
  349. static std::unique_ptr<DownloadingContentMenu> s_dlcMenu;
  350. #endif
  351.  
  352.  
  353. int gPhonePerfId = -1;
  354.  
  355. bool IsAndroid()
  356. {
  357. return strstr(DataByIdx(PhonePerformanceProfiles, gPhonePerfId, sdk), "android") != 0;
  358. }
  359.  
  360. bool IsIos()
  361. {
  362. return strstr(DataByIdx(PhonePerformanceProfiles, gPhonePerfId, sdk), "ios") != 0;
  363. }
  364.  
  365. glitch::video::E_ORIENTATION GS3DStuff::s_orientation = GS3DStuff::getDefaultOrientation();
  366.  
  367.  
  368. bool GS3DStuff::b_isAutoOri = true;
  369.  
  370. Std<VehicleHandle>::Vector GS3DStuff::s_vehicles;
  371. Std<NPCHandle>::Vector GS3DStuff::s_npcs;
  372. int GS3DStuff::s_roundRobinNPCIdx = 0;
  373. Std<PlayerHandle>::Vector GS3DStuff::s_players;
  374. glitch::scene::ISceneNode* gMiamiAnimScene = 0;
  375.  
  376. int64 GS3DStuff::s_worldEventFlags = 0;
  377.  
  378. int GS3DStuff::s_streamingState = SS_NONE;
  379. int GS3DStuff::s_streamingTimer;
  380. int GS3DStuff::s_streamingDuration;
  381. int GS3DStuff::s_streamingElapsed;
  382. bool GS3DStuff::s_skipFadeIn = false;
  383. bool GS3DStuff::s_loadingDisplayed = false;
  384.  
  385. bool GS3DStuff::s_isIrradianceLoaded = false;
  386.  
  387. int GS3DStuff::s_sunOcclusionFrameCounter = 0;
  388. int GS3DStuff::s_sunOcclusionFrameCycle = 5;
  389.  
  390. #ifdef __APPLE__
  391. #include "Utils/mach_thread_helper.h"
  392. extern MachThreadPolicyManager g_machThreadPolicyManager;
  393. #endif
  394.  
  395. // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  396. // Ctors / Dtor
  397. // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  398.  
  399. DEFINE_RTTI(GS3DStuff)
  400.  
  401. GS3DStuff::GS3DStuff() :
  402. m_playingAmbient(false)
  403. {
  404. m_drawable = false;
  405. m_updates = 0;
  406. flushBufferedLines();
  407. }
  408.  
  409. GS3DStuff::~GS3DStuff()
  410. {
  411. EventManager::GetInstance()->detach(Events::TOUCHSCREEN_PRESS, this);
  412.  
  413. // it will be set to 0 in unload() when we are really exiting the game
  414. }
  415.  
  416. BulletTraceManager* GS3DStuff::GetBulletManager()
  417. {
  418. return GS3DStuff::s_bulletManager;
  419. }
  420. TrailMgr* GS3DStuff::GetTrailMgr()
  421. {
  422. return GS3DStuff::s_TrailMgr;
  423. }
  424.  
  425. glitch::scene::ISceneNodePtr GS3DStuff::GetMissionTrailSpline()
  426. {
  427. return GS3DStuff::s_MissionTrailSpline;
  428. }
  429.  
  430. DecalManager* GS3DStuff::GetDecalManager()
  431. {
  432. return GS3DStuff::s_DecalManager;
  433. }
  434.  
  435. void GS3DStuff::SetMissionTrailSpline(const char* dbName)
  436. {
  437. if (GS3DStuff::s_MissionTrailSpline)
  438. {
  439. GS3DStuff::s_MissionTrailSpline->remove();
  440. GS3DStuff::s_MissionTrailSpline = 0;
  441. }
  442.  
  443. if (dbName && strlen(dbName) > 0)
  444. {
  445. GS3DStuff::s_MissionTrailSpline = CustomConstructScene(dbName, HighlightColladaFactory::getInstance(), false, E_CCS_OH_NONE);
  446. }
  447.  
  448. if (GS3DStuff::s_MissionTrailSpline)
  449. {
  450. GET_OBJECT_ROOT()->addChild(GS3DStuff::s_MissionTrailSpline);
  451.  
  452. glitch::scene::SSceneNodeArray meshNodeList;
  453.  
  454. GS3DStuff::s_MissionTrailSpline->getSceneNodesFromType(glitch::scene::ESNT_COLLADA_MESH, meshNodeList);
  455.  
  456. for (glitch::scene::SSceneNodeArray::iterator it = meshNodeList.begin(), end = meshNodeList.end(); it != end; ++it)
  457. {
  458. glitch::scene::ISceneNodePtr node = *it;
  459. node->setRenderingLayer(RenderLayers::ECSRL_TRACK_TRAIL);
  460. }
  461. }
  462. }
  463.  
  464. int gNumCallAllStreamingDone = 0;
  465.  
  466. bool GS3DStuff::IsAllStreamingDone()
  467. {
  468. World* world = World::GetInstance();
  469.  
  470. return world->IsAllStreamingDone();
  471. }
  472.  
  473. //-------------------------------------------------------------------------------------------------------------------------------------------------------------
  474. //-------------------------------------------------------------------------------------------------------------------------------------------------------------
  475.  
  476. glitch::video::CMaterialPtr GS3DStuff::CreateMaterial(const char* textureName, glitch::video::E_MATERIAL_TYPE type)
  477. {
  478. IVideoDriver* driver = GetVideoDriver();
  479.  
  480. glitch::video::CMaterialRendererManager& mrm = driver->getMaterialRendererManager();
  481. glitch::video::CMaterialPtr materialWithTexture = mrm.createMaterialInstance(driver, type);
  482. #ifdef GLITCH_COMMAND_QUEUE_BRANCH
  483. glitch::video::ITexturePtr tex = driver->getTextureManager()->getTexture(driver, textureName);
  484. #else
  485. glitch::video::ITexturePtr tex = driver->getTextureManager()->getTexture(textureName);
  486. #endif
  487. if(tex)
  488. {
  489. glitch::u16 texID = materialWithTexture->getParameterID(glitch::video::ESPT_TEXTURE);
  490. materialWithTexture->setParameter(texID, tex);
  491. }
  492.  
  493. return materialWithTexture;
  494. }
  495.  
  496. void GS3DStuff::ChangeMaterialType(glitch::collada::CMeshSceneNode* node, int matNumber, glitch::u32 type)
  497. {
  498. IVideoDriver* driver = GetVideoDriver();
  499.  
  500. glitch::video::CMaterialRendererManager& mrm = driver->getMaterialRendererManager();
  501. glitch::video::ITexturePtr tex;
  502.  
  503. glitch::video::CMaterialPtr mat = node->getMaterial(matNumber);
  504. if(! mat)
  505. {
  506. ASSERT(0);
  507. return;
  508. }
  509. glitch::u16 texID = mat->getParameterID(glitch::video::ESPT_TEXTURE);
  510. glitch::video::CMaterialPtr newMaterial;
  511. if(type == glitch::video::EMT_UNLIT_NON_TEXTURED_SOLID)
  512. {
  513. //HACK for skybox, force to custom material
  514. const char* effectFile = "./CustomNonTextured.bdae";
  515. glitch::collada::CColladaDatabase database(effectFile);
  516. glitch::video::CMaterialRendererPtr materialRenderer = database.constructEffect(GetVideoDriver(), "Custom Unlit Non Textured", 0);
  517. newMaterial = glitch::video::CMaterial::allocate(materialRenderer);
  518. newMaterial->setBaseTechnique(materialRenderer->getTechniqueID("default"));
  519. }
  520. else
  521. {
  522. newMaterial = glitch::video::CMaterial::allocate(mrm.getMaterialRenderer(type)); //mrm.createMaterialInstance(type);
  523. }
  524.  
  525.  
  526.  
  527. if(texID != glitch::u16(-1))
  528. {
  529. node->getMaterial(matNumber)->getParameter(texID, tex);
  530. texID = newMaterial->getParameterID(glitch::video::ESPT_TEXTURE);
  531. newMaterial->setParameter(texID, tex);
  532. }
  533. newMaterial->setParameter(newMaterial->getParameterID(glitch::video::ESPT_DIFFUSE_COLOR), glitch::video::SColor(255,255,255,255));
  534. node->getMesh()->setMaterial(matNumber, newMaterial, 0);
  535. }
  536.  
  537. void GS3DStuff::ChangeMaterialTexture(glitch::video::CMaterialPtr& mat, glitch::video::ITexture* tex)
  538. {
  539. if(!mat || !tex)
  540. return;
  541.  
  542. glitch::u16 texID = mat->getParameterID(glitch::video::ESPT_TEXTURE);
  543. if(texID != glitch::u16(-1))
  544. {
  545. glitch::video::ITexturePtr ptr = tex;
  546. mat->setParameter(texID, ptr);
  547. }
  548. }
  549.  
  550. void GS3DStuff::ChangeMaterialTexture(glitch::video::CMaterialPtr& mat, glitch::video::ITexturePtr& tex)
  551. {
  552. if(!mat || !tex)
  553. return;
  554.  
  555. glitch::u16 texID = mat->getParameterID(glitch::video::ESPT_TEXTURE);
  556. if(texID != glitch::u16(-1))
  557. {
  558. mat->setParameter(texID, tex);
  559. }
  560. }
  561.  
  562. glitch::u32 GS3DStuff::CreateMaterialRenderer(const char* rendererName, E_CUSTOM_MATERIAL_TYPE type)
  563. {
  564. IVideoDriver* driver = GetVideoDriver();
  565. glitch::video::CMaterialRendererManager& mrm = driver->getMaterialRendererManager();
  566. glitch::u32 mrId = glitch::u16(-1);
  567. mrId = mrm.getMaterialRendererID(rendererName);
  568.  
  569. if(mrId != glitch::u16(-1))
  570. {
  571. return mrId;
  572. }
  573.  
  574. if(type == ECMT_UNLIT_TEXTURED_ALPHATEST_BACKFACE_CULLING)
  575. {
  576. int a = 0;
  577. }
  578.  
  579. #if defined(GLITCH_COMPILE_WITH_OPENGL_FIXED_FAMILY)
  580. glitch::video::SFixedGLShaderVertexState vertexState;
  581. if(type == ECMT_UNLIT_NON_TEXTURED_BLEND_NO_DEPTH ||
  582. type == ECMT_UNLIT_NON_TEXTURED_WIREFRAME ||
  583. type == ECMT_UNLIT_TEXTURED_ALPHATEST_NO_DEPTH ||
  584. type == ECMT_UNLIT_TEXTURED_ALPHATEST_BACKFACE_CULLING ||
  585. type == ECMT_UNLIT_TEXTURED_BACKFACE_CULLING ||
  586. type == ECMT_UNLIT_NON_TEXTURED_NO_COLORMASK)
  587. {
  588. vertexState.setLightCount(0);
  589. }
  590. else
  591. {
  592. vertexState.setLightCount(1);
  593. }
  594.  
  595. vertexState.setShadeModel(glitch::video::ESM_SMOOTH);
  596.  
  597. if(type == ECMT_UNLIT_TEXTURED_ALPHATEST_NO_DEPTH)
  598. {
  599. vertexState.setFogMode(glitch::video::EFM_LINEAR);
  600. }
  601.  
  602. glitch::video::SFixedGLShaderFragmentState fragmentState;
  603.  
  604. if(type == ECMT_UNLIT_TEXTURED_ALPHATEST_NO_DEPTH ||
  605. type == ECMT_UNLIT_TEXTURED_ALPHATEST_BACKFACE_CULLING ||
  606. type == ECMT_LIT_TEXTURED_ALPHATEST)
  607. {
  608. fragmentState.setAlphaFunc(glitch::video::ECFN_GREATER);
  609. fragmentState.setAlphaTestEnable(true);
  610. fragmentState.setActiveUnitCount(1);
  611. }
  612.  
  613. if(type == ECMT_UNLIT_TEXTURED_BACKFACE_CULLING)
  614. {
  615. vertexState.setLightCount(0);
  616. vertexState.setColorMaterialEnable(true);
  617. fragmentState.setActiveUnitCount(1);
  618. }
  619. else if(type == ECMT_LIT_TEXTURED_BACKFACE_CULLING)
  620. {
  621. vertexState.setLightCount(1);
  622. vertexState.setColorMaterialEnable(true);
  623. fragmentState.setActiveUnitCount(1);
  624. }
  625.  
  626. glitch::video::CFixedGLShaderManager* shaderManager =
  627. static_cast<glitch::video::CFixedGLShaderManager*>(
  628. driver->getShaderManager()
  629. );
  630. glitch::video::IShaderPtr shader =
  631. shaderManager->createShader(glitch::core::randomString(14).c_str(),
  632. vertexState,
  633. fragmentState);
  634. #endif
  635. glitch::video::SRenderPass::SRenderState renderState;
  636.  
  637. /* renderState.setCullFaceEnable(true);
  638. renderState.setCullFace(video::EFS_BACK);
  639. */
  640. if(type == ECMT_UNLIT_NON_TEXTURED_BLEND_NO_DEPTH)
  641. {
  642. renderState.setDepthTestEnable(false);
  643. renderState.setBlendEnable(true);
  644. renderState.setBlendFunc(glitch::video::EBF_SRC_ALPHA, glitch::video::EBF_ONE);
  645. }
  646. else if(type == ECMT_UNLIT_NON_TEXTURED_WIREFRAME)
  647. {
  648. renderState.setPolygonModeFront(video::EPM_LINE);
  649. renderState.setPolygonModeBack(video::EPM_LINE);
  650. }
  651. else if(type == ECMT_UNLIT_TEXTURED_ALPHATEST_NO_DEPTH)
  652. {
  653. renderState.setDepthTestEnable(false);
  654. renderState.setBlendEnable(false);
  655. renderState.setDepthMask(false);
  656. }
  657. else if(type == ECMT_UNLIT_NON_TEXTURED_NO_COLORMASK)
  658. {
  659. renderState.setColorMask(false,false,false,false);
  660. }
  661. else if(type == ECMT_UNLIT_TEXTURED_ALPHATEST_BACKFACE_CULLING)
  662. {
  663. renderState.setCullFaceEnable(true);
  664. renderState.setCullFace(video::EFS_BACK);
  665. }
  666. else if(type == ECMT_UNLIT_TEXTURED_BACKFACE_CULLING)
  667. {
  668. renderState.setCullFaceEnable(true);
  669. renderState.setCullFace(video::EFS_BACK);
  670. }
  671.  
  672. // Then we generate a material renderer with the shader
  673. glitch::video::CMaterialRendererManager::SCreationContext ctx;
  674. mrId = mrm.beginMaterialRenderer(ctx, driver, rendererName);
  675. if(mrId)
  676. {
  677. ctx.beginTechnique(/*"Technique #1"*/glitch::core::randomString(14).c_str());
  678. #if defined(GLITCH_COMPILE_WITH_OPENGL_FIXED_FAMILY)
  679. mrm.addRenderPass(shader, renderState);
  680. #endif
  681. if(type == ECMT_UNLIT_TEXTURED_ALPHATEST_NO_DEPTH ||
  682. type == ECMT_UNLIT_TEXTURED_ALPHATEST_BACKFACE_CULLING ||
  683. type == ECMT_UNLIT_TEXTURED_BACKFACE_CULLING ||
  684. type == ECMT_LIT_TEXTURED_BACKFACE_CULLING ||
  685. type == ECMT_LIT_TEXTURED_ALPHATEST)
  686. {
  687. glitch::video::CMaterialRendererManager::STemporaryID paramId = ctx.addParameter("texture", glitch::video::ESPT_TEXTURE, glitch::video::ESPVT_TEXTURE_SAMPLER_2D);
  688. //ESPT_FOG_DENSITY,
  689. //ESPT_FOG_START_END,
  690. //ESPT_FOG_COLOR,
  691. glitch::video::CMaterialRendererManager::STemporaryID techId = ctx.endTechnique(true, 0 /*max material lights*/);
  692. #if defined(GLITCH_COMPILE_WITH_OPENGL_FIXED_FAMILY)
  693. mrm.bindParameter(paramId, techId, shader->getParameterID(glitch::video::ESPT_TEXTURE, glitch::video::ESS_VERTEX));
  694. #endif
  695. }
  696. else
  697. {
  698. glitch::video::CMaterialRendererManager::STemporaryID techId = ctx.endTechnique(true, 0 /*max material lights*/);
  699. }
  700.  
  701. //glitch::video::CMaterialRendererManager::STemporaryID techId = mrm.endTechnique(true, 0 /*max material lights*/);
  702.  
  703. //if(type == ECMT_UNLIT_TEXTURED_ALPHATEST_NO_DEPTH)
  704. //{
  705. // //glitch::video::CMaterialRendererManager::STemporaryID paramId = mrm.addParameter("texture", glitch::video::ESPT_TEXTURE, glitch::video::ESPVT_TEXTURE_SAMPLER_2D);
  706. // mrm.bindParameter(paramId, techId, shader->getID());
  707. //}
  708. mrId = mrm.endMaterialRenderer(ctx);
  709. }
  710. else
  711. {
  712. mrId = mrm.getMaterialRendererID(rendererName);
  713. }
  714. return mrId;
  715. }
  716.  
  717. void GS3DStuff::SetDebugDataVisible(glitch::scene::ISceneNode* node, int flag)
  718. {
  719. #ifdef GLITCH_RENDER_DEBUG
  720. if(node)
  721. {
  722. node->setDebugDataVisible(flag);
  723. glitch::scene::SSceneNodeList::iterator it = node->childrenBegin();
  724. for(; it != node->childrenEnd(); ++it)
  725. {
  726. SetDebugDataVisible(&(*it), flag);
  727. }
  728. }
  729. #endif
  730. }
  731.  
  732. void GS3DStuff::drawNode(glitch::scene::ISceneNode* node)
  733. {
  734. if(node)
  735. {
  736. GS3DStuff::drawPoint(node->getAbsolutePosition(), 0.0f, 5.0f);
  737. glitch::scene::SSceneNodeList::iterator it = node->childrenBegin();
  738. for(; it != node->childrenEnd(); ++it)
  739. {
  740. drawNode(&(*it));
  741. }
  742. }
  743. }
  744.  
  745. void GS3DStuff::SetAlpha(glitch::scene::ISceneNode* _node, const StdString mat_name, const float alpha)
  746. {
  747. glitch::scene::ISceneNode* node = _node;
  748.  
  749. GLF_ASSERTMSG(node, "For some reasons GetGlitchSceneNode() is NULL!!! Need to find out why.");
  750.  
  751. while (node)
  752. {
  753. if(node->getType() == glitch::scene::ESNT_COLLADA_ROOT)
  754. {
  755. glitch::video::CMaterialPtr material = static_cast<glitch::collada::CRootSceneNode*>(node)->getMaterial(mat_name.c_str(), GetVideoDriver());
  756. if(material.get())
  757. {
  758. glitch::u16 id = material->getParameterID("Object_Alpha");
  759. if(id != glitch::u16(-1))
  760. { material->setParameter(id, alpha); }
  761. }
  762. break;
  763. }
  764. node = node->getParent();
  765. }
  766. }
  767.  
  768. bool HasVisibleChildren(glitch::scene::ISceneNode* node)
  769. {
  770. glitch::scene::SSceneNodeList::iterator it = node->childrenBegin();
  771. for(; it != node->childrenEnd(); ++it)
  772. {
  773. glitch::scene::ISceneNode* child = &(*it);
  774. if (child->isVisible())
  775. {
  776. return true;
  777. }
  778. }
  779. return false;
  780. }
  781.  
  782.  
  783. glitch::scene::ISceneNode* GS3DStuff::FindAMesh(glitch::scene::ISceneNode* colmap)
  784. {
  785. ProfilerScopeScene("FindAMesh", colmap->getUID());
  786. colmap->updateAbsolutePosition(true);
  787.  
  788. glitch::scene::E_SCENE_NODE_TYPE type = colmap->getType();
  789. bool isMesh =
  790. type == glitch::scene::ESNT_COLLADA_MESH ||
  791. type == glitch::scene::ESNT_COLLADA_SKIN_MESH ||
  792. type == glitch::scene::ESNT_COLLADA_MODULAR_SKIN_MESH;
  793.  
  794. if(isMesh && (strstr(colmap->getUID(), "Plane") == 0) && (strstr(colmap->getUID(), "Jump") == 0) && (strstr(colmap->getUID(), "plane") == 0) && (strstr(colmap->getUID(), "jump") == 0) && !colmap->getSceneNodeFromUID("shadow-mesh"))
  795. {
  796. return colmap;
  797. }
  798.  
  799. glitch::scene::ISceneNodePtr result = 0;
  800. glitch::scene::ISceneNodePtr first = 0;
  801.  
  802. #ifndef GLITCH_DISABLE_SCENENODE_MULTITHREAD_CHECK
  803. //this lock is only to disable the what seems like a false positive require lock.
  804. //I am in the main thread, why the fuck would I need to lock looping on hierarchy.
  805. glitch::scene::ScopedSceneNodeReadLock readLock(*colmap);
  806. #endif
  807.  
  808. glitch::scene::E_SCENE_NODE_TYPE types[3] = { glitch::scene::ESNT_COLLADA_MESH, glitch::scene::ESNT_COLLADA_SKIN_MESH, glitch::scene::ESNT_COLLADA_MODULAR_SKIN_MESH };
  809.  
  810. for(int i = 0; i < 3; i++)
  811. {
  812. glitch::scene::SSceneNodeArray skinNodes;
  813. colmap->getSceneNodesFromType(types[i], skinNodes);
  814. for(glitch::scene::SSceneNodeArray::iterator it = skinNodes.begin(); it != skinNodes.end(); ++it)
  815. {
  816. glitch::scene::ISceneNodePtr node = *it;
  817. if ((strstr(node->getUID(), "Plane") == 0) && (strstr(node->getUID(), "Jump") == 0) && (strstr(node->getUID(), "plane") == 0) && (strstr(node->getUID(), "jump") == 0) && !node->getSceneNodeFromUID("shadow-mesh"))
  818. {
  819. if (node->isVisible() && HasVisibleChildren(node.get()))
  820. {
  821. return node.get();
  822. }
  823. }
  824. }
  825. }
  826.  
  827. return colmap;
  828. }
  829.  
  830. glitch::scene::ISceneNode* GS3DStuff::FindNodeByName(glitch::scene::ISceneNode* node, const char* name)
  831. {
  832. if(node == 0)
  833. {
  834. return 0;
  835. }
  836.  
  837. if(strstr(node->getUID(), name))
  838. {
  839. return node;
  840. }
  841.  
  842. //ScopedSceneNodeWriteLock lock(*node);
  843. glitch::scene::ISceneNode* result = 0;
  844. glitch::scene::SSceneNodeList::iterator it = node->childrenBegin();
  845. for(; it != node->childrenEnd(); ++it)
  846. {
  847. result = FindNodeByName(&(*it), name);
  848. if(result)
  849. {
  850. return result;
  851. }
  852. }
  853. return 0;
  854. }
  855.  
  856. glitch::scene::ISceneNode* GS3DStuff::FindNodeByType(glitch::scene::ISceneNode* node, int nodeType)
  857. {
  858. if(node == 0)
  859. {
  860. return 0;
  861. }
  862.  
  863. if(node->getType() == nodeType)
  864. {
  865. return node;
  866. }
  867.  
  868. //ScopedSceneNodeWriteLock lock(*node);
  869. glitch::scene::ISceneNode* result = 0;
  870. glitch::scene::SSceneNodeList::iterator it = node->childrenBegin();
  871. for(; it != node->childrenEnd(); ++it)
  872. {
  873. result = FindNodeByType(&(*it), nodeType);
  874. if(result)
  875. {
  876. return result;
  877. }
  878. }
  879. return 0;
  880. }
  881.  
  882. // this helps perfs as it removes about 1/3 of useless nodes for skinned animated mesh
  883. void GS3DStuff::CleanNode(glitch::scene::ISceneNode* Node)
  884. {
  885. if(!Node)
  886. {
  887. return;
  888. }
  889.  
  890. {
  891. #ifndef GLITCH_DISABLE_SCENENODE_MULTITHREAD_CHECK
  892. //this lock is only to disable the what seems like a false positive require lock. Why would I mutex lock a children traversal
  893. //on a node that I just created and no one knows it exists yet...
  894. glitch::scene::ScopedSceneNodeReadLock readLock(*Node);
  895. #endif
  896. glitch::scene::SSceneNodeList::iterator it = Node->childrenBegin();
  897. for(; it != Node->childrenEnd();)
  898. {
  899. glitch::scene::ISceneNode* node = &(*it);
  900. ++it;
  901. CleanNode(node);
  902. }
  903. }
  904.  
  905. if(strstr(Node->getName(),"_PIVOT") && Node->getChildren().begin() == Node->getChildren().end())
  906. {
  907. Node->remove();
  908. }
  909. }
  910.  
  911. // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  912. // Methods (StateBase impl.)
  913. // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  914.  
  915. void GS3DStuff::ctor(const StateMachine* sm)
  916. {
  917. CHudManager::GetInstance()->show();
  918. TouchScreenBase::getInstance().clear();
  919. }
  920.  
  921.  
  922. extern const char* g_batchFileName;
  923.  
  924. bool g_isLoadingBatch = false;
  925. extern bool g_enableViewportConfig;
  926.  
  927.  
  928. #include "utils/memoryMappedFile.h"
  929. MemoryMappedFile* gIrradiance = 0;
  930.  
  931. namespace LoadingSteps
  932. {
  933. enum LS
  934. {
  935. First = 0,
  936. SwfInitialization,
  937. WaitForMandatoryDlc,
  938. LoadDownloadedArchives,
  939. PhysicsWorld,
  940. GameObjectManager,
  941. Driver,
  942. City1,
  943. GrapherInit,
  944. GrapherConstants,
  945. GrapherGenerateXML,
  946. GrapherFiles,
  947. GrapherEnd,
  948. PostEffectsInit,
  949. VFXManagerInit,
  950. City3_0,
  951. City3_1,
  952. City3_2,
  953. ItemManager,
  954. WeaponManager,
  955. Animations,
  956. GameObjects,
  957. SpawnManager,
  958. PhysicAttributes,
  959. PlayerStep,
  960. RegisterGameObjects,
  961. Managers,
  962. Scripts,
  963. Tweakers,
  964. Misc,
  965. MenuContent,
  966. LoadSettings,
  967. LoadSavegame,
  968. FinalWait,
  969. End,
  970. };
  971. }
  972.  
  973.  
  974. static const int MAX_LOADSTEP_STRINGSIZE = 64;
  975. static char s_dbg_current_load_step[MAX_LOADSTEP_STRINGSIZE];
  976. int s_load_step = 0;
  977.  
  978.  
  979.  
  980. void DBG_DisplayLoadStep(const char* name, int id)
  981. {
  982. //if( IsWin32Build() || GET_DEBUG_SWITCH("DisplayLoadStep") )
  983. {
  984. MenuDebug::GetInstance()->SetHardcodedText(name);
  985. glf::Strcpy_s(s_dbg_current_load_step, MAX_LOADSTEP_STRINGSIZE, name);
  986. }
  987. }
  988.  
  989. // i'm pretty sure it's doable somehow in pre-processor macro, but I got tired of tried failed synthax
  990. bool TestLoadDbgSwitch(const char* name, int id)
  991. {
  992. #if USE_DEBUG_SWITCHES
  993. static char buf[128];
  994. sprintf(buf, "%s_%03d_%s", "SkipLoad", id, name);
  995. return GET_DEBUG_SWITCH("SkipLoad_All_GS3DStuff") || GET_DEBUG_SWITCH(buf);
  996. #else
  997. return false;
  998. #endif
  999. }
  1000.  
  1001.  
  1002. #if GANGSTAR_RETAIL_BUILD == 0
  1003. int s_dbg_last_load_step = -1;
  1004. #define LOAD_STEP_FORCE_REFRESH_HACK if(s_dbg_last_load_step != s_load_step) { s_dbg_last_load_step = s_load_step; return false;}
  1005. #else
  1006. #define LOAD_STEP_FORCE_REFRESH_HACK
  1007. #endif
  1008.  
  1009. struct TraceLoadTimeGuard
  1010. {
  1011. TraceLoadTimeGuard()
  1012. {
  1013.  
  1014. }
  1015.  
  1016. ~TraceLoadTimeGuard()
  1017. {
  1018. DebugStepLoadingTime(s_dbg_current_load_step);
  1019. }
  1020. };
  1021.  
  1022. void GS3DStuff::loadDebugConstants()
  1023. {
  1024. #if GANGSTAR_ENABLE_DEBUG_CONSTANTS
  1025. std::vector<std::string> cstNames;
  1026. DataMgr()->GetConstantNames(cstNames);
  1027. for(int i = 0; i < cstNames.size(); i++)
  1028. {
  1029. std::vector<std::string> valueNames;
  1030. DataManager::Constant* cst = DataMgr()->GetConstant(cstNames[i].c_str());
  1031. cst->GetValueNames(valueNames);
  1032.  
  1033. for(int j = 0; j < valueNames.size(); j++)
  1034. {
  1035. int value = cst->GetValue(valueNames[j].c_str());
  1036. grapher::DebugConstants::GetInstance().AddConstant(cstNames[i].c_str(), valueNames[j].c_str(), value);
  1037. }
  1038. }
  1039.  
  1040. //also add array indexes as constants...
  1041. std::vector<std::string> arrayNames;
  1042. DataMgr()->GetArrayNames(arrayNames);
  1043. for(int i = 0; i < arrayNames.size(); i++)
  1044. {
  1045. std::vector<std::string> valueNames;
  1046. DataManager::Array* arr = DataMgr()->GetArray(arrayNames[i].c_str());
  1047. arr->GetEntryNames(valueNames);
  1048.  
  1049. for(int j = 0; j < valueNames.size(); j++)
  1050. {
  1051. int value = arr->GetEntryIdx(valueNames[j].c_str());
  1052. grapher::DebugConstants::GetInstance().AddConstant(arrayNames[i].c_str(), valueNames[j].c_str(), value);
  1053. }
  1054. }
  1055. #endif
  1056. }
  1057.  
  1058. struct TraceMemoryGuard
  1059. {
  1060. TraceMemoryGuard()
  1061. {
  1062.  
  1063. }
  1064.  
  1065. ~TraceMemoryGuard()
  1066. {
  1067. DebugStepLoadingMemory(s_dbg_current_load_step);
  1068. }
  1069. };
  1070.  
  1071. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1072. #define LOAD_STEP(name) \
  1073. case name: \
  1074. {\
  1075. DBG_DisplayLoadStep( #name, name );\
  1076. DEBUG_LOADING_TIMES("GS3DStuff loading" #name); \
  1077. LOAD_STEP_FORCE_REFRESH_HACK \
  1078. checkLoadingLogoSwap(); \
  1079. if(TestLoadDbgSwitch(#name, name) == false)\
  1080. {\
  1081. TraceLoadTimeGuard timer;\
  1082. TraceMemoryGuard memoryGuard;\
  1083.  
  1084. #define END_STEP() \
  1085. }\
  1086. UpdateLoadingProgress(GetPercentBasedOnLoadingStep(), true);\
  1087. break;\
  1088. }\
  1089.  
  1090. #define END_STEP_WITHOUT_LOADING_PROGRESS() \
  1091. } \
  1092. UpdateLoadingProgress(GetPercentBasedOnLoadingStep(), false);\
  1093. break; \
  1094. } \
  1095.  
  1096. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1097. //
  1098. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1099. void GS3DStuff::checkLoadingLogoSwap()
  1100. {
  1101.  
  1102. if(!Application::s_isShowingHavokLogo || !Application::s_loadingBackground)
  1103. return;
  1104.  
  1105. // make sure we see at least 3 seconds of Havok
  1106. int diff = static_cast<int>(time(0) - Application::s_backgroundScreenTimer);
  1107. if(diff < HAVOK_LOGO_DELAY)
  1108. {
  1109. return;
  1110. }
  1111.  
  1112. GetVideoDriver()->getTextureManager()->removeTexture(Application::s_loadingBackground);
  1113. Application::s_isShowingHavokLogo = false;
  1114.  
  1115. loadGIVLogo();
  1116. }
  1117.  
  1118. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1119. //
  1120. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1121. void GS3DStuff::loadGIVLogo()
  1122. {
  1123. //hack so we enable flash rendering only when we reached the splash screen
  1124. SwfManager::s_isRenderingEnabled = true;
  1125.  
  1126. glitch::video::SScopedDriverOption mipmaps(GetVideoDriver(), glitch::video::EVDO_CREATE_TEXTURE_MIPMAPS, false);
  1127.  
  1128. DEBUG_LOADING_TIMES("Load GIV logo");
  1129. const char* texture = DataByIdx(PhonePerformanceProfiles, gPhonePerfId, LoadingTexture);
  1130. #ifdef GLITCH_COMMAND_QUEUE_BRANCH
  1131. Application::s_loadingBackground = GetVideoDriver()->getTextureManager()->getTexture(GetVideoDriver(), texture);
  1132. #else
  1133. Application::s_loadingBackground = GetVideoDriver()->getTextureManager()->getTexture(texture);
  1134. #endif
  1135. Application::s_backgroundScreenTimer = time(0);
  1136. }
  1137.  
  1138. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1139. //
  1140. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1141. void GS3DStuff::loadPreSplashscreenLogo(const std::string& textureName)
  1142. {
  1143. // show havok logo
  1144. Application::s_loadingBackground = GetVideoDriver()->getTextureManager()->getTexture(textureName.c_str());
  1145. Application::s_backgroundScreenTimer = time(0);
  1146. Application::s_isShowingHavokLogo = true;
  1147. }
  1148.  
  1149. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1150. //
  1151. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1152. bool GS3DStuff::checkIfLogoHasBeenDisplayedEnough()
  1153. {
  1154. int diff = static_cast<int>(time(0) - Application::s_backgroundScreenTimer);
  1155. if(diff < GIV_LOGO_DELAY)
  1156. {
  1157. return false;
  1158. }
  1159. s_isLogoHasBeenDisplayedEnough = true;
  1160. Application::s_backgroundScreenTimer = time(0);
  1161. return true;
  1162. }
  1163.  
  1164. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1165. //
  1166. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1167. bool GS3DStuff::checkIsExtraLoadingLimiterReached()
  1168. {
  1169. int diff = static_cast<int>(time(0) - Application::s_backgroundScreenTimer);
  1170. int loadingDuration = ProfileManager::GetInstance()->HasProfile() ? EXTRA_LOADING_DURATION : FRESH_INSTALL_EXTRA_LOADING_DURATION;
  1171. if (diff < loadingDuration)
  1172. {
  1173. return false;
  1174. }
  1175. return true;
  1176. }
  1177.  
  1178. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1179. void LoadGrapher()
  1180. {
  1181. std::string path1(GetGrapherInitPath());
  1182. std::string path2(GetGrapherAIPath());
  1183.  
  1184. if(IsUsingGrapherBinary())
  1185. {
  1186. GrapherMgr()->SetMode(grapher::BIT_BINARY | grapher::BIT_READ);
  1187. }
  1188.  
  1189. GLFUtils::ToLowerCase(path1);
  1190. GLFUtils::ToLowerCase(path2);
  1191.  
  1192. // if archive, ask the list of files to the archive manager
  1193. if(Application::IsUsingArchives)
  1194. {
  1195. glf::core::FileArchive::FileListing list;
  1196. glf::ArchiveManager::GetInstance()->GetFilesInDirectory(path1.c_str(), list);
  1197. GrapherMgr()->LoadActorsFromFilesList(list , true, path1.c_str());
  1198. list.clear();
  1199. glf::ArchiveManager::GetInstance()->GetFilesInDirectory(path2.c_str(), list);
  1200. GrapherMgr()->LoadActorsFromFilesList(list , true, path2.c_str());
  1201.  
  1202. }
  1203. // else load from file system
  1204. else
  1205. {
  1206. GrapherMgr()->LoadActorsFromFolder(path1.c_str(), true, true);
  1207. GrapherMgr()->LoadActorsFromFolder(path2.c_str(), true, true);
  1208. }
  1209. }
  1210.  
  1211. bool GS3DStuff::isGlobalLoadingDone()
  1212. {
  1213. return s_load_step == LoadingSteps::End;
  1214. }
  1215. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1216. // Returns the next step.
  1217. bool GS3DStuff::load()
  1218. {
  1219. //early escape if someone keeps calling this when we are done loading
  1220. if(s_load_step == LoadingSteps::End)
  1221. {
  1222. return true;
  1223. }
  1224.  
  1225. Application* app = Application::GetInstance();
  1226. IDevice* device = app->GetDevice();
  1227. IVideoDriver* driver = device->getVideoDriver();
  1228. CSceneManager* smgr = device->getSceneManager();
  1229.  
  1230. switch(s_load_step)
  1231. {
  1232. LOAD_STEP(LoadingSteps::First)
  1233. {
  1234. // start the gaia request, it might take some time
  1235. OnlineServiceMgr()->Init();
  1236. }
  1237. END_STEP()
  1238.  
  1239. LOAD_STEP(LoadingSteps::SwfInitialization)
  1240. {
  1241. GetMenuEventMgr()->BindToUserInterface(SwfManager::GetInstance()->LoadSWFFile(SwfManager::SWF_MAIN, true), true);
  1242. }
  1243. END_STEP()
  1244.  
  1245. #if DLC_FLOW_ENABLED
  1246. LOAD_STEP(LoadingSteps::WaitForMandatoryDlc)
  1247. {
  1248. if (s_isProcessingMandatoryDlc)
  1249. {
  1250. // Return that DLC processing is not finished yet, continue updates looping
  1251. return false;
  1252. }
  1253. else if (s_isRetryingDownloadMandatoryDlc)
  1254. {
  1255. // Create DLC menu, this will start loading the content
  1256. s_dlcMenu.reset(new DownloadingContentMenu(
  1257. { "global_world" },
  1258.  
  1259. // On finished
  1260. [&] { s_isProcessingMandatoryDlc = false; },
  1261.  
  1262. // On error alert tapped
  1263. [&] { s_isRetryingDownloadMandatoryDlc = true; s_isProcessingMandatoryDlc = false; }
  1264. ));
  1265.  
  1266. s_isProcessingMandatoryDlc = true;
  1267. s_isRetryingDownloadMandatoryDlc = false;
  1268.  
  1269. // Return that DLC processing is not finished yet, continue updates looping
  1270. return false;
  1271. }
  1272. else
  1273. {
  1274. // Release DLC states handler and keep moving
  1275. s_dlcMenu.reset();
  1276. }
  1277. }
  1278. END_STEP_WITHOUT_LOADING_PROGRESS()
  1279. #else
  1280. LOAD_STEP(LoadingSteps::WaitForMandatoryDlc)
  1281. {
  1282. // Stub
  1283. }
  1284. END_STEP()
  1285.  
  1286.  
  1287. LOAD_STEP(LoadingSteps::LoadDownloadedArchives)
  1288. {
  1289. app->LoadArchives(ALS_RAW_CONTENT);
  1290. }
  1291. END_STEP()
  1292. #endif
  1293.  
  1294. LOAD_STEP(LoadingSteps::PhysicsWorld)
  1295. {
  1296. #if DLC_FLOW_ENABLED == 0
  1297. app->LoadArchives(ALS_CITY_PHYSICS);
  1298. #endif
  1299. app->LoadHktArchives();
  1300.  
  1301. #ifdef PHYSICS_UPDATE_IN_THREAD
  1302. if (glf::TaskDirector::GetInstance().GetThreadCount<PHYSICS_UPDATE_CPU_ID>() < 1 &&
  1303. DataByIdx(PhonePerformanceProfiles, gPhonePerfId, havokUpdateThreaded))
  1304. {
  1305. glf::TaskThreadData data;
  1306. data.ptr = (void *)(48 * 1024);
  1307. data.stackSize = 256 * 1024; // Default was 128Kb
  1308. glf::TaskDirector::GetInstance().StartThread<PHYSICS_UPDATE_CPU_ID>(1, data, glf::Thread::PRIORITY_NORM);
  1309. }
  1310. #endif
  1311.  
  1312. #ifdef PHYSICS_USING_ASYNCHRONOUS_UPDATE
  1313. // Initialize physics callback for async update
  1314. if (app->GetApplicationMode() == G4AM_REGULAR)
  1315. {
  1316. extern void _AsyncUpdateGame(const float, const bool, const unsigned long);
  1317.  
  1318. PhysicsWorldCInfo worldInfo;
  1319. worldInfo.m_updateGameCallback = _AsyncUpdateGame;
  1320. worldInfo.m_updateGameParam = 0;
  1321. PhysicsWorld::GetInstance()->Init(worldInfo);
  1322.  
  1323. ProjectileManager::CreateInstance();
  1324. }
  1325. #endif
  1326. }
  1327. END_STEP()
  1328.  
  1329. LOAD_STEP(LoadingSteps::GameObjectManager)
  1330. {
  1331. MLA_SET_CONTEXT("LoadingSteps::GameObjectManager");
  1332. GameObjectManager::GetInstance()->Load();
  1333. }
  1334. END_STEP()
  1335.  
  1336. LOAD_STEP(LoadingSteps::GrapherInit)
  1337. {
  1338. GrapherMgr()->Init();
  1339. }
  1340. END_STEP()
  1341.  
  1342. LOAD_STEP(LoadingSteps::GrapherConstants)
  1343. {
  1344. loadDebugConstants();
  1345. }
  1346. END_STEP()
  1347.  
  1348. LOAD_STEP(LoadingSteps::GrapherGenerateXML)
  1349. {
  1350. #if defined(_WIN32) && DATAMGR_XML_HYBRID_ENABLED == 1
  1351. GrapherMgr()->GenerateXMLTemplate();
  1352. grapher::DebugConstants::GetInstance().Export("./grapher_symbols/cst_symbols.txt");
  1353. #endif
  1354. }
  1355. END_STEP()
  1356.  
  1357. LOAD_STEP(LoadingSteps::GrapherFiles)
  1358. {
  1359. LoadGrapher();
  1360. }
  1361. END_STEP()
  1362.  
  1363. LOAD_STEP(LoadingSteps::GrapherEnd)
  1364. {
  1365. GrapherMgr()->LoadingFinish();
  1366. }
  1367. END_STEP()
  1368.  
  1369. LOAD_STEP(LoadingSteps::PostEffectsInit)
  1370. {
  1371. MLA_SET_CONTEXT("LoadingSteps::PostEffectsInit");
  1372. static_cast<CCustomIngameSceneManager*>(GetSceneMgr())->GetPostEffects()->Init();
  1373. }
  1374. END_STEP()
  1375.  
  1376. LOAD_STEP(LoadingSteps::VFXManagerInit)
  1377. {
  1378. MLA_SET_CONTEXT("LoadingSteps::VFXManagerInit");
  1379. VfxMgr()->Init();
  1380. }
  1381. END_STEP()
  1382.  
  1383. LOAD_STEP(LoadingSteps::Driver)
  1384. {
  1385. driver->setOption(glitch::video::EVDO_BATCHING, true);
  1386. driver->setOption(glitch::video::EVDO_CREATE_TEXTURE_MIPMAPS, true);
  1387. driver->getTextureManager()->setFlag(glitch::video::CTextureManager::EF_KEEP_CLIENT_DATA, false);
  1388. }
  1389. END_STEP()
  1390.  
  1391. LOAD_STEP(LoadingSteps::City1)
  1392. {
  1393. MLA_SET_CONTEXT("LoadingSteps::City1");
  1394. #if DLC_FLOW_ENABLED == 0
  1395. app->LoadArchives(ALS_CITY_MESHES);
  1396. #endif
  1397.  
  1398. PreloadEffects(driver);
  1399.  
  1400. World* world = World::GetInstance();
  1401. world->LoadWorldParts();
  1402. }
  1403. END_STEP()
  1404.  
  1405. LOAD_STEP(LoadingSteps::City3_0)
  1406. {
  1407. MLA_SET_CONTEXT("LoadingSteps::City3_0");
  1408.  
  1409. CCustomIngameSceneManager* smgr = (CCustomIngameSceneManager*)GetDevice()->getSceneManager();
  1410. smgr->CreateLowResCity("./citylowres_batched.bdae");
  1411. }
  1412. END_STEP()
  1413.  
  1414. LOAD_STEP(LoadingSteps::City3_1)
  1415. {
  1416. MLA_SET_CONTEXT("LoadingSteps::City3_1");
  1417. #ifndef IRRADIANCE_SIMULATION
  1418.  
  1419. s_sunOcclusionFrameCycle = Cst(SunOcclusion, FrameToOmit);
  1420. #ifdef IRRADIANCE
  1421. #ifdef DEBUG_IRRADIANCE_SPHERES
  1422. smgr->InitIrradianceSpheres();
  1423. #endif
  1424. #endif
  1425. CameraManager::GetInstance();
  1426.  
  1427. SetCubeMap("city_cube.tga");
  1428.  
  1429. glitch::video::CGlobalMaterialParameterManager* globalParams = GetVideoDriver()->getGlobalMaterialParameters();
  1430.  
  1431. for (int i = 0; i < DataCount(LUT_list); ++i)
  1432. {
  1433. glitch::u16 id = globalParams->getParameterID(DataByIdx(LUT_list, i, GlobalParameterName));
  1434. if (id != glitch::u16(-1)) // Be sure that getParameterID returns unsigned 16bit
  1435. {
  1436. glitch::video::ITexturePtr tex = GetVideoDriver()->getTextureManager()->getTexture(DataByIdx(LUT_list, i, imageFile));
  1437. GLF_ASSERTMSG(tex, "Could not load LUT file: %s", DataByIdx(LUT_list, i, imageFile));
  1438. if (tex)
  1439. {
  1440. tex->setWrap(static_cast<glitch::video::E_TEXTURE_CLAMP>((int)DataByIdx(LUT_list, i, wrap)));
  1441. if (!static_cast<bool>(DataByIdx(LUT_list, i, usemipmaps)))
  1442. {
  1443. tex->setMinFilter(glitch::video::ETFT_LINEAR);
  1444. }
  1445. globalParams->setParameter(id, tex);
  1446. }
  1447. }
  1448. }
  1449.  
  1450. DayTime::Get().init();
  1451.  
  1452. static_cast<CCustomIngameSceneManager*>(GetSceneMgr())->InitShadowMaps();
  1453. static_cast<CCustomShopSceneManager*>(Application::s_sceneManagerMenu.get())->InitShadowMaps();
  1454. #endif
  1455. }
  1456. END_STEP()
  1457.  
  1458. LOAD_STEP(LoadingSteps::City3_2)
  1459. {
  1460. {
  1461. MLA_SET_CONTEXT("LoadingSteps::City3_2");
  1462.  
  1463. gEnableHDWaterRendering = (bool)DataByIdx(PhonePerformanceProfiles, gPhonePerfId, useHDWaterShaders) && gCfgEnableHDWaterSupport;
  1464.  
  1465. CameraManager::GetInstance();
  1466. if (!DataByIdx(PhonePerformanceProfiles, gPhonePerfId, UseLowResWater))
  1467. {
  1468. gWaterScene = CustomConstructScene("./water.bdae", WaterFadeColladaFactory::getInstance(), true, E_CCS_OH_CHILDREN);
  1469. }
  1470. else
  1471. {
  1472. gWaterScene = CustomConstructScene("./water_lowres.bdae", WaterFadeColladaFactory::getInstance(), true, E_CCS_OH_CHILDREN);
  1473. }
  1474.  
  1475. if (gWaterScene)
  1476. {
  1477. GET_OBJECT_ROOT()->addChild(gWaterScene);
  1478.  
  1479. glitch::scene::SSceneNodeArray waterList;
  1480.  
  1481. gWaterScene->getSceneNodesFromType(glitch::scene::ESNT_COLLADA_MESH, waterList);
  1482. for (size_t i = 0; i < waterList.size(); i++)
  1483. {
  1484. //-150 reserved for objects that must be drawn before HD water
  1485. if (strstr(waterList[i]->getParent()->getName(), "foam"))
  1486. {
  1487. waterList[i]->setRenderingLayer(-151);
  1488. }
  1489. else
  1490. {
  1491. waterList[i]->setRenderingLayer(-150);
  1492. }
  1493. }
  1494. }
  1495.  
  1496. glitch::scene::ISceneNodePtr oceanScene = CustomConstructScene("./ocean.bdae", WaterFadeColladaFactory::getInstance(), true, E_CCS_OH_CHILDREN);
  1497.  
  1498. if (oceanScene)
  1499. {
  1500. oceanScene->setAutomaticCulling(glitch::scene::EAC_FRUSTUM_BOX);
  1501. glitch::scene::SSceneNodeArray oceanList;
  1502.  
  1503. oceanScene->getSceneNodesFromType(glitch::scene::ESNT_COLLADA_MESH, oceanList);
  1504.  
  1505. for (size_t i = 0; i < oceanList.size(); i++)
  1506. {
  1507. oceanList[i]->setRenderingLayer(-1341);
  1508. oceanList[i]->getMaterial(0)->setBaseTechnique(gEnableHDWaterRendering && gCfgEnableHDWaterSupport ? 1 : 0);
  1509. }
  1510. CCustomIngameSceneManager* smgr = static_cast<CCustomIngameSceneManager*>(GetDevice()->getSceneManager());
  1511. smgr->MoveToConjointFrustum(oceanScene);
  1512. }
  1513.  
  1514. InitTreeShaders();
  1515. UpdateTreeShaders();
  1516. }
  1517.  
  1518. }
  1519. END_STEP()
  1520.  
  1521. LOAD_STEP(LoadingSteps::ItemManager)
  1522. {
  1523. MLA_SET_CONTEXT("LoadingSteps::ItemManager");
  1524. ItemMgr();
  1525. }
  1526. END_STEP()
  1527.  
  1528. #ifndef IRRADIANCE_SIMULATION
  1529. LOAD_STEP(LoadingSteps::WeaponManager)
  1530. {
  1531. MLA_SET_CONTEXT("LoadingSteps::WeaponManager");
  1532. WeaponryMgr();
  1533. }
  1534. END_STEP()
  1535.  
  1536. LOAD_STEP(LoadingSteps::Animations)
  1537. {
  1538. MLA_SET_CONTEXT("LoadingSteps::Animations");
  1539. Character::loadAnimationFiles();
  1540. }
  1541. END_STEP()
  1542.  
  1543. LOAD_STEP(LoadingSteps::GameObjects)
  1544. {
  1545. MLA_SET_CONTEXT("LoadingSteps::GameObjects");
  1546. gom = GameObjectManager::GetInstance();
  1547. World* world = World::GetInstance();
  1548. world->LoadLevelDesignXML();
  1549. }
  1550. END_STEP()
  1551.  
  1552. LOAD_STEP(LoadingSteps::SpawnManager)
  1553. {
  1554. MLA_SET_CONTEXT("LoadingSteps::SpawnManager");
  1555. SpawnGroupManager::GetInstance()->Load();
  1556. }
  1557. END_STEP()
  1558.  
  1559. #endif
  1560. LOAD_STEP(LoadingSteps::PhysicAttributes)
  1561. {
  1562. MLA_SET_CONTEXT("LoadingSteps::PhysicAttributes");
  1563. SpawnManager::GetInstance()->Init();
  1564. }
  1565. END_STEP()
  1566.  
  1567. LOAD_STEP(LoadingSteps::PlayerStep)
  1568. {
  1569. #ifndef IRRADIANCE_SIMULATION
  1570. MLA_SET_CONTEXT("LoadingSteps::PlayerStep");
  1571.  
  1572. CameraManager::GetInstance()->enterMode(CAMERA_MODES::FOLLOW, Player::GetPlayer(), 0);
  1573. GS3DStuff::SwitchLocation(DataIdx(Locations, City));
  1574. World::GetInstance()->UpdateClippingAndStreamingRange();
  1575.  
  1576. Player* mainPlayer = static_cast<Player*>(GameObjectManager::GetInstance()->GetGameObjectByName("Angel_00"));
  1577. GLF_ASSERTMSG(mainPlayer != 0, "Could not find the player in xml, need something named \"Angel_00\"");
  1578. if (mainPlayer)
  1579. {
  1580. mainPlayer->enable();
  1581. mainPlayer->getAIController()->setBehavior(BehaviorManager::PLAYER);
  1582. Player::s_player = mainPlayer;
  1583. WeaponryMgr()->Init();
  1584. Player::GetPlayer()->addToDebugger();
  1585. Player::GetPlayer()->SetUnlimitedAmmo(false);
  1586. GameObjectManager::GetInstance()->Remove(Player::s_player);
  1587. }
  1588. #endif
  1589. Character::InitInteractionFunctors();
  1590. }
  1591. END_STEP()
  1592.  
  1593. LOAD_STEP(LoadingSteps::RegisterGameObjects)
  1594. {
  1595. #ifndef IRRADIANCE_SIMULATION
  1596. MLA_SET_CONTEXT("LoadingSteps::RegisterGameObjects");
  1597. // 3 is the number of queues we have
  1598. for(int i=0; i<3; i++)
  1599. {
  1600. LevelObject* lo = gom->GetFirstLo(i);
  1601. while(lo)
  1602. {
  1603. // this helps perfs as it removes about 1/3 of useless nodes for skinned animated mesh
  1604. CleanNode(lo->GetGlitchSceneNode());
  1605. lo = gom->GetNextLo(lo);
  1606. }
  1607. }
  1608. #endif
  1609. }
  1610. END_STEP()
  1611.  
  1612. LOAD_STEP(LoadingSteps::Scripts)
  1613. {
  1614. MLA_SET_CONTEXT("LoadingSteps::Scripts");
  1615. #ifndef IRRADIANCE_SIMULATION
  1616. // From here, the game is loaded properly so that SaveGames should work
  1617. Application::setGameLoaded(true);
  1618.  
  1619. static bool sAlreadyLoaded = false;
  1620. if(sAlreadyLoaded == false) //i'm gonna burn in hell for this...
  1621. {
  1622. MLA_SET_CONTEXT("LoadingSteps::Scripts");
  1623. StoryManager::GetInstance()->getMission()->load();
  1624. StoryManager::GetInstance()->loadReputationLevels();
  1625. sAlreadyLoaded = true;
  1626. }
  1627.  
  1628. {
  1629. MLA_SET_CONTEXT("LoadingSteps::CameraManager");
  1630. CameraManager::GetInstance();
  1631. }
  1632.  
  1633. {
  1634. MLA_SET_CONTEXT("LoadingSteps::BehaviorManager");
  1635. BehaviorManager::GetInstance()->reset();
  1636. #if USE_BIN_BEHAVIORS
  1637. BehaviorManager::GetInstance()->deserialize(BIN_BEHAVIORS_PATH);
  1638. #endif
  1639. }
  1640. #endif
  1641. }
  1642. END_STEP()
  1643.  
  1644. LOAD_STEP(LoadingSteps::Managers)
  1645. {
  1646.  
  1647. MLA_SET_CONTEXT("LoadingSteps::Managers");
  1648. // add bullet trace manager
  1649. s_bulletManager = gll_new BulletTraceManager();
  1650. s_bulletManager->setAutomaticCulling(EAC_BOX);
  1651. GET_OBJECT_ROOT()->addChild(s_bulletManager);
  1652. s_TrailMgr = gll_new TrailMgr();
  1653. s_TrailMgr->Init(6, 80, 0, DEFAULT_TRAIL_LIFE_FRAMES, DEFAULT_TRAIL_WIDTH);
  1654. #ifdef USE_DECAL_MANAGER
  1655. s_DecalManager = gll_new DecalManager();
  1656. #endif
  1657. WantedMgr(); // this should init the wanted level manager
  1658. AbilityMgr(); // this will init the ability manager.
  1659. StockMgr()->Load();
  1660. Player::GetPlayer()->GetInventory()->InitEquipment();
  1661. ItemMgr();
  1662. CityDominationManager::GetInstance();
  1663. }
  1664. END_STEP()
  1665.  
  1666. LOAD_STEP(LoadingSteps::Tweakers)
  1667. {
  1668. MLA_SET_CONTEXT("LoadingSteps::Tweakers");
  1669. #if GANGSTAR_RETAIL_BUILD == 0
  1670. CreateTweakers(GetDevice()); //old tweakers creation from gangstar 3
  1671. GrapherTweakers::GetInstance()->GenerateGUI();
  1672. LocationTweakers::GetInstance()->GenerateGUI();
  1673. DebugTweakers::GetInstance()->GenerateGUI();
  1674. TemplateTweakers::GetInstance()->GenerateGUI();
  1675. DynamicMaterialPropertiesTweakers::GetInstance()->GenerateGUI();
  1676. VfxMgr()->GenerateGUI();
  1677. CCustomSceneManagerTweaker::GetInstance()->GenerateGUI();
  1678. #ifdef WIN32
  1679. PaletteTweakerManager::GetInstance()->GenerateGUI();
  1680. #endif
  1681. MissionTweakers::GetInstance()->GenerateGUI();
  1682. #endif
  1683. }
  1684. END_STEP()
  1685.  
  1686. LOAD_STEP(LoadingSteps::Misc)
  1687. {
  1688. MLA_SET_CONTEXT("LoadingSteps::Misc");
  1689. #ifndef IRRADIANCE_SIMULATION
  1690. app->SetDrawAll(true);
  1691.  
  1692. //set the controller to onFoot
  1693. CControlManager* ctrlMgr = Application::GetInstance()->GetControlManager();
  1694. ctrlMgr->init();
  1695. #endif
  1696. }
  1697. END_STEP()
  1698.  
  1699. LOAD_STEP(LoadingSteps::MenuContent)
  1700. {
  1701. MLA_SET_CONTEXT("LoadingSteps::MenuContent");
  1702. MenuMgr::GetInstance()->Init();
  1703. }
  1704. END_STEP()
  1705.  
  1706. LOAD_STEP(LoadingSteps::LoadSettings)
  1707. {
  1708. //Preferences pref;
  1709. //pref.LoadAndApply(false); // false = don't apply basic preferences. This is the only case
  1710. }
  1711. END_STEP()
  1712.  
  1713. LOAD_STEP(LoadingSteps::LoadSavegame)
  1714. {
  1715. }
  1716. END_STEP()
  1717.  
  1718. LOAD_STEP(LoadingSteps::FinalWait)
  1719. {
  1720. if (!s_isLogoHasBeenDisplayedEnough && !checkIfLogoHasBeenDisplayedEnough())
  1721. {
  1722. return false;
  1723. }
  1724.  
  1725. if ((!OnlineServiceMgr()->IsAnyCRMConfigDispatched() ||
  1726. ProfileManager::GetInstance()->GetStartupProfileStatus() == SPS_RETRIEVING) &&
  1727. OnlineServiceMgr()->GetGaia()->IsInitialized())
  1728. {
  1729. if (!checkIsExtraLoadingLimiterReached())
  1730. {
  1731. return false;
  1732. }
  1733. }
  1734. }
  1735. END_STEP()
  1736. }
  1737.  
  1738. s_load_step++;
  1739. if(s_load_step == LoadingSteps::End)
  1740. {
  1741. MenuDebug::GetInstance()->TakeGlobalRessourceSnapshot();
  1742. TouchScreenBase::getInstance().clear();
  1743. MenuDebug::GetInstance()->SetHardcodedText(0);
  1744. Application::GetInstance()->onGameLoaded();
  1745.  
  1746. Application::GetInstance()->LaunchAlertForPushNotif();
  1747.  
  1748. #if _WIN32
  1749. //This does nothing unless we are in "testapplication" mode but called all the in case we change this to be a proper tool callable command line.
  1750. Application::DoXMLDataCompare();
  1751.  
  1752. // are we testing?
  1753. if(Application::s_isTestingFromCommandLine)
  1754. {
  1755.  
  1756.  
  1757. // test "game loaded callback", call it now
  1758. int result = Tools::applicationLoadedCallback();
  1759. if(result)
  1760. {
  1761. // if return is not zero, it's an error, abort!
  1762. std::cout << "\n" << std::flush;
  1763. ExitProcess(result);
  1764. return true;
  1765. }
  1766.  
  1767. // say that everything is OK - I didn't crash before this.
  1768. std::cout << TEST_OK_STRING << std::endl;
  1769.  
  1770. if(Application::s_isTestingFromCommandLineForcing)
  1771. {
  1772. // if we are forcing, don't rely on the game to quit properly.
  1773. std::cout << "\n" << std::flush;
  1774. ExitProcess(0);
  1775. return true;
  1776. }
  1777. // quit the game properly
  1778. CORE()->Stop();
  1779. return true;
  1780. }
  1781. #endif
  1782. }
  1783.  
  1784. return s_load_step == LoadingSteps::End;
  1785. }
  1786.  
  1787. void GS3DStuff::tearDown()
  1788. {
  1789. StockManager::GetInstance()->Free();
  1790. SpawnManager::GetInstance()->UnInit();
  1791.  
  1792. GET_BACKDROP_ROOT()->removeAll();
  1793.  
  1794. //clear the cube map texture.
  1795. GetVideoDriver()->getGlobalMaterialParameters()->setParameter(
  1796. GetVideoDriver()->getGlobalMaterialParameters()->getParameterID("CubeMapSampler"),
  1797. 0);
  1798.  
  1799. if(gWaterScene)
  1800. {
  1801. gWaterScene->remove();
  1802. gWaterScene = 0;
  1803. }
  1804. s_roadSpecLut = 0;
  1805. s_carSpecLut = 0;
  1806.  
  1807. CameraManager::clean();
  1808.  
  1809. GrapherMgr()->ClearAll();
  1810.  
  1811. ItemManager::GetInstance()->Terminate();
  1812. PickupableManager::GetInstance()->Free();
  1813. ProjectileMgr()->Free();
  1814.  
  1815. GameObjectManager::GetInstance()->purge();
  1816. GameObjectManager::GetInstance()->Clear();
  1817.  
  1818. GlitchUtils::WaitOnAllDropGlitchNode();
  1819.  
  1820. Player::DeletePlayer();
  1821.  
  1822. WeaponryMgr()->Release();
  1823. CameraManager::GetInstance()->Free();
  1824. MenuMgr::GetInstance()->GetMapHandler()->Free();
  1825.  
  1826. Character::unloadAnimationFiles();
  1827.  
  1828. BehaviorManager::tearDown();
  1829.  
  1830. Vehicle::DoorsAndSeats::GetInstance()->Clear();
  1831.  
  1832. DayTime::Get().deinit();
  1833. Character::ClearInteractionFunctors();
  1834.  
  1835.  
  1836. //DropZ(sunNode);
  1837. //DropZ(moonNode);
  1838. //DropZ(sunGlow);
  1839. //DropZ(moonGlow);
  1840. //DropZ(usedLightNode);
  1841. //DropZ(lightNode);
  1842.  
  1843. DropZ(gWaterScene);
  1844. //[batchMeshRemoval] s_batchMesh = 0;
  1845.  
  1846. //ScriptManager::GetInstance()->disable();
  1847.  
  1848. SafeDelete(s_TrailMgr);
  1849.  
  1850. #ifdef USE_DECAL_MANAGER
  1851. SafeDelete(s_DecalManager);
  1852. #endif
  1853.  
  1854. if(s_bulletManager)
  1855. {
  1856. GET_OBJECT_ROOT()->removeChild(s_bulletManager);
  1857. //no need to delete, it a glitch ISceneNode, refcount and it gets deleted as soon as we remove it from the root, since we only have a c style ptr to it. (not refcounted by game)
  1858. //SafeDelete(s_bulletManager);
  1859. }
  1860.  
  1861. //SndMgr()->clear();
  1862.  
  1863. AnimationManager::deleteInstance();
  1864.  
  1865. #ifdef IS_BATCHGENERATOR
  1866. void ClearMapTexMat();
  1867. ClearMapTexMat();
  1868. #endif
  1869.  
  1870.  
  1871. PhysicsWorld::DestroyInstance();
  1872. }
  1873.  
  1874.  
  1875. void GS3DStuff::unload()
  1876. {
  1877. SndMgr()->Execute(eSO_Stop, "sfx");
  1878. }
  1879.  
  1880. void GS3DStuff::dtor(const StateMachine* sm)
  1881. {
  1882. tearDown();
  1883. }
  1884.  
  1885. void GS3DStuff::onEvent(const IEvent* ev, const EventManager* evMgr)
  1886. {
  1887. // SCOPE_TRACE("DBG", "%i\n", ev->getEventID());
  1888. switch(ev->getEventID())
  1889. {
  1890. case Events::TOUCHSCREEN_PRESS:
  1891. // SCOPE_TRACE("DBG", "TOUCHSCREEN_PRESS\n");
  1892. break;
  1893. }
  1894. }
  1895.  
  1896. bool gIsStreaming = false;
  1897.  
  1898. bool gFlushMemoryMap = false;
  1899. int gFlushMemoryMapFrameInterval = -1;
  1900. int gFlushMemoryMapFrameCounter = 0;
  1901.  
  1902. void GS3DStuff::update(StateMachine* sm)
  1903. {
  1904. #ifdef __APPLE__
  1905. if(DataByIdx(PhonePerformanceProfiles, gPhonePerfId, useMachThreadPolicy))
  1906. {
  1907. const bool switchOn = isInGame();
  1908. g_machThreadPolicyManager.Update(switchOn);
  1909. }
  1910. #endif
  1911.  
  1912. Application* app = Application::GetInstance();
  1913.  
  1914. // [ICH] shader global time hack to avoid precision problem
  1915. glitch::video::CGlobalMaterialParameterManager* globalParams = GetVideoDriver()->getGlobalMaterialParameters();
  1916.  
  1917. glitch::u16 timeId = globalParams->getParameterID("MyGlobalTime");
  1918.  
  1919. if (timeId != u16(-1))
  1920. {
  1921. float value = 0;
  1922. globalParams->getParameter(timeId, value);
  1923.  
  1924. value += GS3DStuff::getDT() * MILLISEC_TO_SEC;
  1925.  
  1926. if (value > 240.0f)
  1927. {
  1928. value = 0.0f;
  1929. }
  1930.  
  1931. globalParams->setParameter(timeId, value);
  1932. }
  1933.  
  1934. #if _WIN32
  1935. if(gLodProfiling && Player::GetPlayer())
  1936. {
  1937. if(!LODProfiler::GetInstance()->Update())
  1938. {
  1939. LODProfiler::GetInstance()->PostProcess();
  1940. exit(1);
  1941. }
  1942. }
  1943.  
  1944. if(app->IsRenderingCinematic() && app->IsRenderingCinematicDone())
  1945. {
  1946. exit(1);
  1947. }
  1948. #endif
  1949. glitch::core::dimension2d<s32> size = GetVideoDriver()->getCurrentRenderTarget()->getSize();
  1950.  
  1951. if(gFlushMemoryMapFrameInterval > 0)
  1952. {
  1953. ++gFlushMemoryMapFrameCounter;
  1954. }
  1955.  
  1956. if(gFlushMemoryMap || (gFlushMemoryMapFrameInterval > 0 && gFlushMemoryMapFrameCounter >= gFlushMemoryMapFrameInterval))
  1957. {
  1958. ProfilerScopeScene("flush memory map", NULL);
  1959.  
  1960. gFlushMemoryMap = false;
  1961. gFlushMemoryMapFrameCounter = 0;
  1962. }
  1963.  
  1964. s_dt = StateMachine::GetInstance()->getTimeStamp();
  1965.  
  1966. //unsigned int s_dt_tmp = StateMachine::GetInstance()->getTimeStamp();
  1967. //SCOPE_TRACE("DBG", "%d is not the same as %d\n",s_dt,s_dt_tmp);
  1968. //s_dt = s_dt_tmp;
  1969.  
  1970. if(s_streamingState != SS_NONE)
  1971. {
  1972. ProfilerScopeScene("streaming update", NULL);
  1973. streamingUpdate(s_dt);
  1974. }
  1975. else
  1976. {
  1977. // Just in case, be sure that the loading icon is gone
  1978. Application::GetInstance()->WatchDogForLoadingTime(false);
  1979. }
  1980.  
  1981. //update this asap so hopeful the spawntaskimpl will start WAYYYYYYYYYY before havok.
  1982. SpawnManager::GetInstance()->Update();
  1983.  
  1984. UpdateDayTime();
  1985.  
  1986. if(CHudManager::GetInstance()->getScreen())
  1987. {
  1988. CHudManager::GetInstance()->getScreen()->setupScreenZones();
  1989. }
  1990.  
  1991. UpdateBehaviors();
  1992.  
  1993. UpdateInvisibles();
  1994.  
  1995. UpdateVisibles();
  1996.  
  1997. UpdatePurgeGameObjectAndTriggerZone();
  1998.  
  1999. UpdateCharacters();
  2000.  
  2001. UpdateVehicles();
  2002.  
  2003. UpdatePhysics();
  2004.  
  2005. UpdateCamera();
  2006.  
  2007. UpdateVehicleNodeAndProximity();
  2008.  
  2009. UpdateScripts();
  2010.  
  2011. UpdateWantedAndTrail();
  2012.  
  2013. UpdateAttachDSP();
  2014.  
  2015.  
  2016. UpdateSunOcclusion();
  2017.  
  2018. // the following greatly helps perfs as it pre-cull every dynamic object against the camera AABB
  2019. // the main bottleneck in irrlicht being the number of node flagged as visible going through the animation transformation process
  2020. /* lo = gom->GetFirstLo();
  2021. glitch::core::aabbox3df camBox = CameraManager::GetInstance()->getCamera()->getViewFrustum()->getBoundingBox();
  2022. while(lo)
  2023. {
  2024. //lo->GetGlitchSceneNode()->setVisible(false);
  2025. if (!lo->GetGlitchSceneNode()->getTransformedBoundingBox().intersectsWithBox(camBox))
  2026. lo->GetGlitchSceneNode()->setVisible(false);
  2027. lo = gom->GetNextLo(lo);
  2028. }*/
  2029.  
  2030. if(!m_drawable)
  2031. {
  2032. if(m_updates > 0) //Skip 2 draws
  2033. {
  2034. m_drawable = true;
  2035. EventManager::GetInstance()->attach(Events::TOUCHSCREEN_PRESS, this);
  2036. //CameraManager::GetInstance()->enterMode(CAMERA_MODES::FOLLOW, Player::GetPlayer(), 0.0f);
  2037. }
  2038. m_updates++;
  2039. }
  2040. static bool isFirstFrame = true;
  2041.  
  2042. // set the LOD Ranges mode
  2043. bool useAlternateLodRanges = false;
  2044. if(Player::GetPlayer() && Player::GetPlayer()->isInAVehicle())
  2045. {
  2046. useAlternateLodRanges = true;
  2047. }
  2048. World::GetInstance()->setUseAlternateLodRanges(useAlternateLodRanges);
  2049.  
  2050.  
  2051. const glitch::scene::ICameraSceneNodePtr camera = app->GetDevice()->getSceneManager()->getActiveCamera();
  2052.  
  2053. const glitch::scene::SViewFrustum* frustum = camera->getViewFrustum();
  2054.  
  2055. if(gIsStreamingEnabled)
  2056. {
  2057. glitch::core::vector3df position = camera->getAbsolutePosition();
  2058. World::GetInstance()->UpdateStreaming(position);
  2059. }
  2060.  
  2061. World::GetInstance()->Update(s_dt);
  2062.  
  2063. isFirstFrame = false;
  2064.  
  2065. if(GET_DEBUG_SWITCH("DrawPermanentLine"))
  2066. {
  2067. GS3DStuff::drawLine(s_plStart, s_plEnd, 0.0f, glitch::video::SColor(255, 200, 0 , 0));
  2068. }
  2069.  
  2070. //Order is not that much important for this,
  2071. PickupableManager::GetInstance()->Update(s_dt);
  2072. ProjectileMgr()->Update(s_dt);
  2073.  
  2074. s_sunOcclusionFrameCounter = (s_sunOcclusionFrameCounter + 1) % s_sunOcclusionFrameCycle;
  2075. }
  2076.  
  2077. void GS3DStuff::UpdateMaterialTechniques()
  2078. {
  2079. #ifdef IRRADIANCE
  2080. LevelObject* lo = gom->GetFirstLo(Kst(ObjectFrameActions, UpdateAndDraw));
  2081.  
  2082. while(lo)
  2083. {
  2084. LevelObject* next = gom->GetNextLo(lo);
  2085.  
  2086. if(lo->IsVisible())
  2087. {
  2088. if(GameObjectManager::isCharacter(lo))
  2089. {
  2090. lo->updateShaderTechnique(LightsManager::GetInstance()->IsCurrentLightZoneInterior());
  2091. Character* character = static_cast<Character*>(lo);
  2092. Weapon* weapon = character->getWeapon();
  2093. if(weapon)
  2094. {
  2095. weapon->updateShaderTechnique(LightsManager::GetInstance()->IsCurrentLightZoneInterior());
  2096. }
  2097. }
  2098. }
  2099. lo = next;
  2100. }
  2101.  
  2102. Player::GetPlayer()->updateShaderTechnique(LightsManager::GetInstance()->IsCurrentLightZoneInterior());
  2103. Inventory* inventory = Player::GetPlayer()->GetInventory();
  2104. if (inventory)
  2105. {
  2106. int slot = inventory->GetCurrentWeaponSlot();
  2107. int slot_end = slot;
  2108. do
  2109. {
  2110. Weapon* weapon = inventory->GetWeapon(slot);
  2111. if (weapon)
  2112. {
  2113. weapon->updateShaderTechnique(LightsManager::GetInstance()->IsCurrentLightZoneInterior());
  2114. }
  2115. slot = inventory->GetNextWeaponSlot(1,slot);
  2116. }
  2117. while (slot != slot_end);
  2118. }
  2119.  
  2120. #endif
  2121. }
  2122.  
  2123. void GS3DStuff::pause(const StateMachine* sm)
  2124. {
  2125. if(OnlineServiceMgr()->GetBITracker())
  2126. {
  2127. if(StoryManager::GetInstance()->isInMission())
  2128. {
  2129. OnlineServiceMgr()->GetBITracker()->UpdateMissionTimeSpent(true);
  2130. }
  2131. }
  2132.  
  2133. SndMgr()->Execute(eSO_Pause);
  2134.  
  2135. #ifdef __APPLE__
  2136. if(DataByIdx(PhonePerformanceProfiles, gPhonePerfId, useMachThreadPolicy))
  2137. {
  2138. g_machThreadPolicyManager.Update(false);
  2139. }
  2140. #endif
  2141. }
  2142.  
  2143. void GS3DStuff::resume(const StateMachine* sm)
  2144. {
  2145. if(OnlineServiceMgr()->GetBITracker())
  2146. {
  2147. if(StoryManager::GetInstance()->isInMission())
  2148. {
  2149. OnlineServiceMgr()->GetBITracker()->UpdateMissionTimeSpent(false);
  2150. }
  2151. }
  2152.  
  2153. TouchScreenBase::getInstance().clear();
  2154.  
  2155. SndMgr()->Execute(eSO_Resume);
  2156. }
  2157.  
  2158. void GS3DStuff::wakeup(const StateMachine* sm)
  2159. {
  2160. TouchScreenBase::getInstance().clear();
  2161. }
  2162.  
  2163. void drawBox(const glitch::core::aabbox3df& bbox, const glitch::video::SColor& color)
  2164. {
  2165. glitch::core::vector3df point1(bbox.MaxEdge.getX(), bbox.MaxEdge.getY(), bbox.MaxEdge.getZ());
  2166. glitch::core::vector3df point2(bbox.MaxEdge.getX(), bbox.MaxEdge.getY(), bbox.MinEdge.getZ());
  2167. glitch::core::vector3df point3(bbox.MinEdge.getX(), bbox.MaxEdge.getY(), bbox.MinEdge.getZ());
  2168. glitch::core::vector3df point4(bbox.MinEdge.getX(), bbox.MaxEdge.getY(), bbox.MaxEdge.getZ());
  2169. glitch::core::vector3df point5(bbox.MinEdge.getX(), bbox.MinEdge.getY(), bbox.MinEdge.getZ());
  2170. glitch::core::vector3df point6(bbox.MaxEdge.getX(), bbox.MinEdge.getY(), bbox.MinEdge.getZ());
  2171. glitch::core::vector3df point7(bbox.MaxEdge.getX(), bbox.MinEdge.getY(), bbox.MaxEdge.getZ());
  2172. glitch::core::vector3df point8(bbox.MinEdge.getX(), bbox.MinEdge.getY(), bbox.MaxEdge.getZ());
  2173. GS3DStuff::draw3DLineBuffered(point1, point2, color);
  2174. GS3DStuff::draw3DLineBuffered(point2, point3, color);
  2175. GS3DStuff::draw3DLineBuffered(point3, point4, color);
  2176. GS3DStuff::draw3DLineBuffered(point4, point1, color);
  2177. GS3DStuff::draw3DLineBuffered(point5, point6, color);
  2178. GS3DStuff::draw3DLineBuffered(point6, point7, color);
  2179. GS3DStuff::draw3DLineBuffered(point7, point8, color);
  2180. GS3DStuff::draw3DLineBuffered(point8, point5, color);
  2181. GS3DStuff::draw3DLineBuffered(point1, point7, color);
  2182. GS3DStuff::draw3DLineBuffered(point2, point6, color);
  2183. GS3DStuff::draw3DLineBuffered(point5, point3, color);
  2184. GS3DStuff::draw3DLineBuffered(point4, point8, color);
  2185. }
  2186.  
  2187. void GS3DStuff::drawBox(const glitch::core::vector3df center, const glitch::video::SColor& color)
  2188. {
  2189. glitch::core::vector3df radius(5.0f,5.0f,5.0f);
  2190. const glitch::core::aabbox3df aabb(center-radius, center+radius);
  2191. ::drawBox(aabb, color);
  2192. }
  2193.  
  2194. void drawBox(const glitch::core::aabbox3df& bbox)
  2195. {
  2196. glitch::core::vector3df point1(bbox.MaxEdge.getX(), bbox.MaxEdge.getY(), bbox.MaxEdge.getZ());
  2197. glitch::core::vector3df point2(bbox.MaxEdge.getX(), bbox.MaxEdge.getY(), bbox.MinEdge.getZ());
  2198. glitch::core::vector3df point3(bbox.MinEdge.getX(), bbox.MaxEdge.getY(), bbox.MinEdge.getZ());
  2199. glitch::core::vector3df point4(bbox.MinEdge.getX(), bbox.MaxEdge.getY(), bbox.MaxEdge.getZ());
  2200. glitch::core::vector3df point5(bbox.MinEdge.getX(), bbox.MinEdge.getY(), bbox.MinEdge.getZ());
  2201. glitch::core::vector3df point6(bbox.MaxEdge.getX(), bbox.MinEdge.getY(), bbox.MinEdge.getZ());
  2202. glitch::core::vector3df point7(bbox.MaxEdge.getX(), bbox.MinEdge.getY(), bbox.MaxEdge.getZ());
  2203. glitch::core::vector3df point8(bbox.MinEdge.getX(), bbox.MinEdge.getY(), bbox.MaxEdge.getZ());
  2204. GS3DStuff::draw3DLineBuffered(point1, point2, glitch::video::SColor(255, 0, 0, 0));
  2205. GS3DStuff::draw3DLineBuffered(point2, point3, glitch::video::SColor(255, 0, 0, 0));
  2206. GS3DStuff::draw3DLineBuffered(point3, point4, glitch::video::SColor(255, 0, 0, 0));
  2207. GS3DStuff::draw3DLineBuffered(point4, point1, glitch::video::SColor(255, 0, 0, 0));
  2208. GS3DStuff::draw3DLineBuffered(point5, point6, glitch::video::SColor(255, 0, 0, 0));
  2209. GS3DStuff::draw3DLineBuffered(point6, point7, glitch::video::SColor(255, 0, 0, 0));
  2210. GS3DStuff::draw3DLineBuffered(point7, point8, glitch::video::SColor(255, 0, 0, 0));
  2211. GS3DStuff::draw3DLineBuffered(point8, point5, glitch::video::SColor(255, 0, 0, 0));
  2212. GS3DStuff::draw3DLineBuffered(point1, point7, glitch::video::SColor(255, 0, 0, 0));
  2213. GS3DStuff::draw3DLineBuffered(point2, point6, glitch::video::SColor(255, 0, 0, 0));
  2214. GS3DStuff::draw3DLineBuffered(point5, point3, glitch::video::SColor(255, 0, 0, 0));
  2215. GS3DStuff::draw3DLineBuffered(point4, point8, glitch::video::SColor(255, 0, 0, 0));
  2216. }
  2217. void GS3DStuff::draw(const StateMachine* sm)
  2218. {
  2219.  
  2220. }
  2221.  
  2222. void drawTurning(glitch::scene::ISceneNode* p);
  2223.  
  2224. void GS3DStuff::drawSkeleton(glitch::scene::ISceneNode* p)
  2225. {
  2226. //glitch::scene::ScopedSceneNodeReadLock readLock(*p);
  2227.  
  2228. glitch::core::vector3df s = p->getAbsolutePosition();
  2229. for(glitch::scene::SSceneNodeList::iterator it = p->childrenBegin(); it != p->childrenEnd(); ++it)
  2230. {
  2231. glitch::scene::ISceneNode* c = &*it;
  2232. //if (c->getType() == glitch::scene::ESNT_EMPTY)
  2233. if((strstr(c->getName(), "root") || strstr(c->getName(), "Bip01")) && !strstr(c->getName(), "Ragdoll"))
  2234. {
  2235. glitch::core::vector3df e = c->getAbsolutePosition();
  2236. GS3DStuff::draw3DLineBuffered(s, e, glitch::video::SColor(0, 0, 255, 0));
  2237. drawSkeleton(c);
  2238. //if(strcmp(c->getName(), "Bip01") == 0)
  2239. //{
  2240. // drawTurning(c);
  2241. //}
  2242. }
  2243. //else if (strstr("char_maincharacter", c->getName()))
  2244. //{
  2245. // c->setVisible(false);
  2246. //}
  2247. }
  2248. }
  2249.  
  2250. void drawTurning(glitch::scene::ISceneNode* p)
  2251. {
  2252. glitch::core::vector3df s = p->getAbsolutePosition();
  2253. glitch::core::vector3df n = Player::GetPlayer()->getNeckNode()->getAbsolutePosition();
  2254. const glitch::core::matrix4& mtx = p->getAbsoluteTransformation();
  2255. glitch::core::quaternion rot = mtx;
  2256.  
  2257. glitch::core::vector3df front = rot * glitch::core::vector3df(0.f, -1.f, 0.f); // GetFront();
  2258. glitch::core::vector3df right = rot * glitch::core::vector3df(-1.f, 0.f, 0.f); // GetRight();
  2259. front.z() = 0.f;
  2260. right.z() = 0.f;
  2261. front.normalize();
  2262. right.normalize();
  2263. GS3DStuff::draw3DLineBuffered(s, s + front * 50.0f, glitch::video::SColor(0, 255, 0, 0));
  2264. GS3DStuff::draw3DLineBuffered(s, s + right * 50.0f, glitch::video::SColor(0, 0, 255, 0));
  2265. if(Player::GetPlayer()->isTurning())
  2266. {
  2267. GS3DStuff::draw3DLineBuffered(s, s + Player::GetPlayer()->m_targetTurningFront * 50.0f, glitch::video::SColor(0, 0, 0, 255));
  2268. GS3DStuff::draw3DLineBuffered(s, s + rot * Player::GetPlayer()->m_paramDir.get() * 50.0f, glitch::video::SColor(0, 255, 255, 255));
  2269. GS3DStuff::draw3DLineBuffered(s, s + rot * Player::GetPlayer()->m_paramDirOut * 50.0f, glitch::video::SColor(0, 255, 0, 255));
  2270. }
  2271.  
  2272. //if (Player::GetPlayer()->isAiming())
  2273. //{
  2274. GS3DStuff::draw3DLineBuffered(n, n + rot * Player::GetPlayer()->m_AimDir.get() * 50.0f, glitch::video::SColor(0, 255, 255, 0));
  2275. GS3DStuff::draw3DLineBuffered(n, n + Player::GetPlayer()->m_aimingStartFront * 50.0f, glitch::video::SColor(0, 255, 255, 255));
  2276. GS3DStuff::draw3DLineBuffered(n, n + rot * Player::GetPlayer()->m_LastParamOut * 50.0f, glitch::video::SColor(0, 255, 0, 255));
  2277.  
  2278. //}
  2279.  
  2280. glitch::core::matrix4 m = Player::GetPlayer()->getMotionNode()->getAbsoluteTransformation();
  2281.  
  2282. GS3DStuff::draw3DLineBuffered(Player::GetPlayer()->getMotionNode()->getAbsolutePosition(), Player::GetPlayer()->getMotionNode()->getAbsolutePosition() + glitch::core::vector3df(m[4], m[5], m[6]) * 50.0f, glitch::video::SColor(0, 255, 0, 0));
  2283.  
  2284. }
  2285.  
  2286. void GS3DStuff::drawBBoxes(glitch::scene::ISceneNode* node)
  2287. {
  2288. GS3DStuff::draw3dAABB(node->getTransformedBoundingBox(), glitch::video::SColor(255, 255, 0, 0));
  2289. for (glitch::scene::SSceneNodeList::iterator it = node->childrenBegin(); it != node->childrenEnd(); ++it)
  2290. {
  2291. glitch::scene::ISceneNode* n = it.operator->();
  2292. drawBBoxes(n);
  2293. }
  2294. }
  2295.  
  2296. void GS3DStuff::draw()
  2297. {
  2298. bool _debug = false;
  2299.  
  2300. #if defined(DEBUG_CAMERA) || defined(DEBUG_PLAYER) || defined(DEBUG_VEHICLE) || defined(DEBUG_PICKABLES) || defined(DEBUG_SIDE_MISSIONS) || defined(DEBUG_HELI) || defined(DEBUG_DUMMIES)
  2301. _debug = true;
  2302. #endif
  2303. if(gDebugCollisionShape || gDebugBoundingBoxes || g_debugLookAt)
  2304. {
  2305. _debug = true;
  2306. }
  2307.  
  2308. glitch::video::IVideoDriver* vd = 0;
  2309.  
  2310. if(_debug)
  2311. {
  2312. vd = GetVideoDriver();
  2313. CMaterialRendererManager& mrm = vd->getMaterialRendererManager();
  2314. vd->setMaterial(mrm.getMaterialInstance(vd, glitch::video::EMT_UNLIT_NON_TEXTURED_SOLID));
  2315. vd->setTransform(glitch::video::ETS_WORLD,glitch::core::matrix4());
  2316. vd->setOption(video::EVDO_RETAIN_BATCH_ON_MISS, true);
  2317. }
  2318.  
  2319. if(gDebugBoundingBoxes)
  2320. {
  2321. GameObjectManager* gom = GameObjectManager::GetInstance();
  2322. LevelObject* lo = gom->GetFirstLo(Kst(ObjectFrameActions, UpdateAndDraw));
  2323.  
  2324. // draw the bounding box of the player
  2325. if(Player::GetPlayer()->IsVisible())
  2326. {
  2327. glitch::core::vector3df center = Player::GetPlayer()->GetPosition() + Player::GetPlayer()->GetFront() * g_collisionFrontDistance +
  2328. glitch::core::vector3df(0, 0, g_collisionUpperDistance);
  2329.  
  2330. glitch::core::aabbox3df centerBox(center - glitch::core::vector3df(10, 10, 10.0f),
  2331. center + glitch::core::vector3df(10, 10, 10.0f));
  2332. ::drawBox(centerBox);
  2333.  
  2334. center = Player::GetPlayer()->GetPosition() + glitch::core::vector3df(0, 0, g_collisionUpperDistance) - Player::GetPlayer()->GetFront() * 30.0f;
  2335. centerBox = glitch::core::aabbox3df(center - glitch::core::vector3df(10, 10, 10.0f),
  2336. center + glitch::core::vector3df(10, 10, 10.0f));
  2337. ::drawBox(centerBox);
  2338.  
  2339. center = Player::GetPlayer()->GetPosition();
  2340. centerBox = glitch::core::aabbox3df(center - glitch::core::vector3df(10, 10, 10.0f),
  2341. center + glitch::core::vector3df(10, 10, 10.0f));
  2342. ::drawBox(centerBox);
  2343.  
  2344. center = Player::GetPlayer()->GetPosition() + glitch::core::vector3df(0, 0, -100);
  2345. centerBox = glitch::core::aabbox3df(center - glitch::core::vector3df(10, 10, 10.0f),
  2346. center + glitch::core::vector3df(10, 10, 10.0f));
  2347. ::drawBox(centerBox);
  2348.  
  2349. ::drawBox(Player::GetPlayer()->getBoundingBox());
  2350. }
  2351.  
  2352. while(lo)
  2353. {
  2354. glitch::core::aabbox3df bbox;
  2355. if(GameObjectManager::isVehicle(lo))
  2356. {
  2357. Vehicle* v = static_cast<Vehicle*>(lo);
  2358. bbox = v->getMesh()->getTransformedBoundingBox();
  2359. }
  2360.  
  2361. ::drawBox(bbox);
  2362.  
  2363. lo = gom->GetNextLo(lo);
  2364. }
  2365. }
  2366.  
  2367. if(g_debugLookAt)
  2368. {
  2369. CameraManager* camMgr = CameraManager::GetInstance();
  2370. glitch::core::vector3df pos = camMgr->getLookAtPosition();
  2371. GS3DStuff::draw3DLineBuffered(pos, pos-camMgr->getLookAtFront()*100, glitch::video::SColor(255, 255, 0, 0));
  2372. GS3DStuff::draw3DLineBuffered(pos, pos+camMgr->getLookAtRight()*100, glitch::video::SColor(255, 0, 255, 0));
  2373. GS3DStuff::draw3DLineBuffered(pos, pos+camMgr->getLookAtUp()*100, glitch::video::SColor(255, 0, 0, 255));
  2374. }
  2375.  
  2376. #define HEX_COLOR(hex) glitch::video::SColor(255, ((hex)>>16)&0xff, ((hex)>>8)&0xff, ((hex)>>0)&0xff)
  2377.  
  2378. if(gDebugCopPosition)
  2379. {
  2380. GameObjectManager* gom = GameObjectManager::GetInstance();
  2381.  
  2382. LevelObject* obj = gom->GetFirstLo(Kst(ObjectFrameActions, UpdateAndDraw));
  2383. while(obj)
  2384. {
  2385. if(obj->IsCop())
  2386. {
  2387. glitch::core::vector3df pA(Player::GetPlayer()->GetPosition());
  2388. glitch::core::vector3df pB(obj->GetPosition());
  2389. pA.setZ(pA.getZ()+100);
  2390. pB.setZ(pB.getZ()+100);
  2391.  
  2392. glitch::video::SColor color(255,0,0,0);
  2393. GS3DStuff::draw3DLineBuffered(pA, pB, color);
  2394. }
  2395. obj = gom->GetNextLo(obj);
  2396. }
  2397. }
  2398.  
  2399. if(GET_DEBUG_SWITCH("DrawSkeleton"))
  2400. {
  2401.  
  2402. Player::GetPlayer()->GetGlitchSceneNode()->updateAbsolutePosition(true);
  2403. drawSkeleton(Player::GetPlayer()->GetGlitchSceneNode());
  2404. drawTurning(Player::GetPlayer()->GetGlitchSceneNode());
  2405.  
  2406. GameObjectManager* gom = GameObjectManager::GetInstance();
  2407.  
  2408. LevelObject* obj = gom->GetFirstLo(Kst(ObjectFrameActions, UpdateAndDraw));
  2409.  
  2410. while(obj)
  2411. {
  2412. if(gom->isCharacter(obj))
  2413. {
  2414. if(obj->GetGlitchSceneNode())
  2415. {
  2416. obj->GetGlitchSceneNode()->updateAbsolutePosition(true);
  2417. drawSkeleton(obj->GetGlitchSceneNode());
  2418. }
  2419. }
  2420. obj = gom->GetNextLo(obj);
  2421. }
  2422. }
  2423.  
  2424.  
  2425.  
  2426. if(gDebugCollisionShape)
  2427. {
  2428. //SCOPE_TRACE("DBG", "Dynamic body count: %d\n", bodyCnt);
  2429. glitch::core::vector3df front = Player::GetPlayer()->GetFront();
  2430. glitch::core::vector3df right = Player::GetPlayer()->GetRight();
  2431. glitch::core::vector3df pos = Player::GetPlayer()->GetPosition();
  2432. glitch::core::vector3df x_start(pos.getX() - 100, pos.getY(), pos.getZ());
  2433. glitch::core::vector3df x_end(pos.getX() + 100, pos.getY(), pos.getZ());
  2434. glitch::core::vector3df y_start(pos.getX(), pos.getY()-100, pos.getZ());
  2435. glitch::core::vector3df y_end(pos.getX(), pos.getY()+100, pos.getZ());
  2436. GS3DStuff::draw3DLineBuffered(x_start, x_end, glitch::video::SColor(255,0,0,0));
  2437. GS3DStuff::draw3DLineBuffered(y_start, y_end, glitch::video::SColor(255,0,0,0));
  2438. pos[2] += 200;
  2439.  
  2440. GS3DStuff::draw3DLineBuffered(pos, pos + front*100, glitch::video::SColor(255,255,0,0));
  2441. GS3DStuff::draw3DLineBuffered(pos, pos + right*100, glitch::video::SColor(255,0,255,0));
  2442. }
  2443.  
  2444.  
  2445. #ifdef DEBUG_DUMMIES
  2446. {
  2447. GameObjectManager* gom = GameObjectManager::GetInstance();
  2448. LevelObject* lo = gom->GetFirstLo(Kst(ObjectFrameActions, UpdateAndDraw));
  2449. while(lo)
  2450. {
  2451. if(gom->isVehicle(lo))
  2452. {
  2453. Vehicle* veh = static_cast<Vehicle*>(lo);
  2454.  
  2455. glitch::scene::ISceneNode* dummy = veh->getLeftDummy();
  2456. glitch::core::vector3df end = dummy->getAbsolutePosition();
  2457. end[2] += 200;
  2458. GS3DStuff::draw3DLineBuffered(dummy->getAbsolutePosition(), end, glitch::video::SColor(255,0,0,255));
  2459. /*
  2460. glitch::core::vector3df dummy_pos = dummy->getAbsolutePosition();
  2461. glitch::core::aabbox3df leftbbox = dummy->getBoundingBox();
  2462. glitch::core::vector3df max = leftbbox.MaxEdge;
  2463. leftbbox.MaxEdge = glitch::core::vector3df(max.getX()+dummy_pos.getX(), max.getY()+dummy_pos.getY(), max.getZ()+dummy_pos.getZ());
  2464. glitch::core::vector3df min = leftbbox.MinEdge;
  2465. leftbbox.MinEdge = glitch::core::vector3df(min.getX()+dummy_pos.getX(), min.getY()+dummy_pos.getY(), min.getZ()+dummy_pos.getZ());
  2466. draw3dAABB(leftbbox, glitch::video::SColor(255,0,128,128));
  2467. */
  2468.  
  2469. dummy = veh->getRightDummy();
  2470. end = dummy->getAbsolutePosition();
  2471. end[2] += 200;
  2472. GS3DStuff::draw3DLineBuffered(dummy->getAbsolutePosition(), end, glitch::video::SColor(255,0,0,255));
  2473. /*
  2474. dummy_pos = dummy->getAbsolutePosition();
  2475. glitch::core::aabbox3df rightbbox = dummy->getBoundingBox();
  2476. max = rightbbox.MaxEdge;
  2477. rightbbox.MaxEdge = glitch::core::vector3df(max.getX()+dummy_pos.getX(), max.getY()+dummy_pos.getY(), max.getZ()+dummy_pos.getZ());
  2478. min = rightbbox.MinEdge;
  2479. rightbbox.MinEdge = glitch::core::vector3df(min.getX()+dummy_pos.getX(), min.getY()+dummy_pos.getY(), min.getZ()+dummy_pos.getZ());
  2480. draw3dAABB(rightbbox, glitch::video::SColor(255,0,128,128));
  2481. */
  2482. }
  2483. lo = GameObjectManager::GetInstance()->GetNextLo(lo);
  2484. }
  2485. }
  2486. #endif
  2487.  
  2488. #ifdef DEBUG_CAMERA
  2489. {
  2490. CameraManager::GetInstance()->debug(vd);
  2491. }
  2492. #endif // DEBUG_CAMERA
  2493.  
  2494. #ifdef DEBUG_PLAYER
  2495. {
  2496. player->debug(vd);
  2497. }
  2498. #endif // DEBUG_PLAYER
  2499.  
  2500. #ifdef DEBUG_VEHICLE
  2501. {
  2502. if(player->getVehicle() != 0)
  2503. {
  2504. player->getVehicle()->debug(vd);
  2505. }
  2506. }
  2507. #endif // DEBUG_VEHICLE
  2508.  
  2509. #ifdef DEBUG_PICKABLES
  2510. {
  2511. GameObjectManager* gom = GameObjectManager::GetInstance();
  2512. LevelObject* lo = gom->GetFirstLo(Kst(ObjectFrameActions, UpdateAndDraw));
  2513. while(lo)
  2514. {
  2515. lo->debug(vd);
  2516. lo = gom->GetNextLo(lo);
  2517. }
  2518. }
  2519. #endif // DEBUG_PICKABLES
  2520.  
  2521. if(vd)
  2522. {
  2523. vd->setOption(video::EVDO_RETAIN_BATCH_ON_MISS, false);
  2524. }
  2525. }
  2526.  
  2527. void GS3DStuff::draw2d(const StateMachine* sm)
  2528. {
  2529. if(s_streamingState != SS_NONE)
  2530. {
  2531. streamingDraw2d();
  2532. }
  2533. }
  2534.  
  2535. Vehicle* GS3DStuff::getClosestVehicle(Character* c)
  2536. {
  2537. Vehicle* vehicle = 0;
  2538. float distance = 0;
  2539. float shortest = 0;
  2540. glitch::scene::ISceneNode* doorNode = 0;
  2541. for(int i = 0; i < s_vehicles.size(); i++)
  2542. {
  2543. Vehicle* v_tmp = s_vehicles[i];
  2544.  
  2545. if (!v_tmp
  2546. || !v_tmp->canBeEntered(c)
  2547. || v_tmp->getDriver() && !v_tmp->canOccupantsCanBeHijacked())
  2548. {
  2549. continue;
  2550. }
  2551.  
  2552. const bool canInteract = c->checkVehicleInteractionAndDistance(v_tmp,distance);
  2553.  
  2554. if (canInteract && distance)
  2555. {
  2556. if(!vehicle || distance < shortest)
  2557. {
  2558. vehicle = v_tmp;
  2559. shortest = distance;
  2560. }
  2561. }
  2562. }
  2563. return vehicle;
  2564. }
  2565.  
  2566. bool GS3DStuff::checkVehicleProximity(Character* c)
  2567. {
  2568. if(Application::getTime() < c->m_lastProximityCheck + 250)
  2569. {
  2570. return false;
  2571. }
  2572. c->m_lastProximityCheck = Application::getTime();
  2573.  
  2574. if(c->canEnterVehicle())
  2575. {
  2576. Vehicle* vehicle = getClosestVehicle(c);
  2577. if(vehicle && vehicle->isAlive())
  2578. {
  2579. c->setClosestVehicle(vehicle);
  2580. return true;
  2581. }
  2582. }
  2583. c->setClosestVehicle(0);
  2584. return false;
  2585. }
  2586.  
  2587. //////////////////////////////////////////////////////////////////////////
  2588. ShopSpawnPoint* GS3DStuff::getClosestShopSpawnPoint(Character* c, Vehicle* v)
  2589. {
  2590. if(!v)
  2591. {
  2592. GLF_ASSERTMSG(false, "GS3DStuff::getClosestShopSpawnPoint() : Vehicle is invalid.\n");
  2593. return 0;
  2594. }
  2595.  
  2596. const bool isBoat = glf::DynamicCast<Boat>(v) != 0;
  2597. const bool isAircraft = glf::DynamicCast<Airplane>(v) != 0 || glf::DynamicCast<Helicopter>(v) != 0;
  2598. int shopSpawnPointType = Cst(ShopSpawnPointTypes, CarAndBike);
  2599. if(isBoat)
  2600. {
  2601. shopSpawnPointType = Cst(ShopSpawnPointTypes, Boat);
  2602. }
  2603. else if(isAircraft)
  2604. {
  2605. shopSpawnPointType = Cst(ShopSpawnPointTypes, HeliAndPlane);
  2606. }
  2607.  
  2608. return getClosestShopSpawnPoint(c, shopSpawnPointType);
  2609. }
  2610.  
  2611. //////////////////////////////////////////////////////////////////////////
  2612. ShopSpawnPoint* GS3DStuff::getClosestShopSpawnPoint(Character* c, int shopSpawnPointType)
  2613. {
  2614. if(!c)
  2615. {
  2616. GLF_ASSERTMSG(false, "GS3DStuff::getClosestShopSpawnPoint() : Character is invalid.\n");
  2617. return 0;
  2618. }
  2619.  
  2620. GameObjectList& objectList = GameObjectManager::GetInstance()->GetObjectList(Kst(ObjectFrameActions, Paused));
  2621. GameObjectList& updObjectList = GameObjectManager::GetInstance()->GetObjectList(Kst(ObjectFrameActions, UpdateAndDraw));
  2622. ShopSpawnPoint* obj = objectList.GetFirst<ShopSpawnPoint>();
  2623. float fClosestDistanceSQ = -1.f;
  2624. ShopSpawnPoint* closest = 0;
  2625. glitch::core::vector3df spawnPos;
  2626. glitch::core::quaternion spawnRot(0.f, 0.f, 0.f, 0.f);
  2627. float minDistVehicleSQ = SQUARE(Cst(SpawnCstCommon, shopMinDistanceToVehicles));
  2628. float minDistPlayerSQ = SQUARE(Cst(SpawnCstCommon, shopMinDistanceToPlayer));
  2629. const glitch::core::vector3df& character_pos = c->GetPosition();
  2630.  
  2631. int numShopSpawnPoint = 0;
  2632. int numShopSpawnPointMatching = 0;
  2633. while(obj)
  2634. {
  2635. numShopSpawnPoint++;
  2636. if(obj->GetShopSpawnPointType() & shopSpawnPointType)
  2637. {
  2638. numShopSpawnPointMatching++;
  2639. float fDistanceSQ = character_pos.getDistanceFromSQ(obj->GetPosition());
  2640. if(!closest || fDistanceSQ < fClosestDistanceSQ && fDistanceSQ >= minDistPlayerSQ)
  2641. {
  2642. // Check for collision with other vehicles
  2643. bool collision = false;
  2644. Vehicle* otherVehicle = updObjectList.GetFirst<Vehicle>();
  2645. while(otherVehicle)
  2646. {
  2647. if(otherVehicle->GetPosition().getDistanceFromSQ(obj->GetPosition()) < minDistVehicleSQ)
  2648. {
  2649. collision = true;
  2650. break;
  2651. }
  2652. otherVehicle = updObjectList.GetNext<Vehicle>(otherVehicle);
  2653. }
  2654.  
  2655. if(!collision)
  2656. {
  2657. fClosestDistanceSQ = fDistanceSQ;
  2658. closest = obj;
  2659. }
  2660. }
  2661. }
  2662. obj = objectList.GetNext<ShopSpawnPoint>(obj);
  2663. }
  2664.  
  2665. if(!closest)
  2666. {
  2667. if(numShopSpawnPointMatching == 0)
  2668. {
  2669. GLF_ASSERTMSG(false, "DATA ERROR : ShopSpawnPointType='ShopSpawnPointTypes.%s' (value=%d)\n But NO primitive of type 'ShopSpawnPoint' with shopSpawnPointType='ShopSpawnPointTypes.%s' was found,\nFound %d ShopSpawnPoint in total.\nPlease double check your ShopSpawnPoint loaded or the StockItem ShopSpawnPointType ...\nShop item will now load IN YOUR FACE THIS IS A BUG.", "unknown"/*DBG_GetEnumName(ShopSpawnPointTypes, m_shopSpawnPointType)*/, shopSpawnPointType, "unknown"/*DBG_GetEnumName(ShopSpawnPointTypes, m_shopSpawnPointType)*/, numShopSpawnPoint);
  2670. }
  2671. else
  2672. {
  2673. GLF_ASSERTMSG(false, "DATA ERROR : found %d matching ShopSpawnPoint but they were all colliding with vehicle with provided radius SpawnCstCommon.shopMinDistanceToVehicles=%d\n!\nStockItem will now spawn IN YOUR FACE\nTHIS IS A BUG\n", numShopSpawnPointMatching, Cst(SpawnCstCommon, shopMinDistanceToVehicles));
  2674. }
  2675. }
  2676.  
  2677. return closest;
  2678. }
  2679.  
  2680. int GS3DStuff::PrintNodeProperties(glitch::scene::ISceneNode* Node, bool recursive, int depth)
  2681. {
  2682. int count = 1;
  2683. if(Node->getType() != glitch::scene::ESNT_EMPTY
  2684. && Node->getType() != glitch::scene::ESNT_COLLADA_NODE
  2685. && Node->getType() != glitch::scene::ESNT_SCENE_MANAGER)
  2686. {
  2687. SCOPE_TRACE("DBG", "Node->getType(): %c%c%c%c\n", (char)(Node->getType()&0xFF),(char)((Node->getType()&0xFF00)>>8),(char)((Node->getType()&0xFF0000)>>16),(char)((Node->getType()&0xFF000000)>>24));
  2688. count = 0;
  2689. }
  2690.  
  2691. if(Node->getChildren().begin() == Node->getChildren().end() && (Node->getType() != glitch::scene::ESNT_COLLADA_MESH && Node->getType() != glitch::scene::ESNT_COLLADA_SKIN_MESH))
  2692. {
  2693. SCOPE_TRACE("DBG", "LEAF: %c%c%c%c\n", (char)(Node->getType()&0xFF),(char)((Node->getType()&0xFF00)>>8),(char)((Node->getType()&0xFF0000)>>16),(char)((Node->getType()&0xFF000000)>>24));
  2694. }
  2695.  
  2696.  
  2697. // add tabs.
  2698. StdString sTabs;
  2699. for(int i = 0; i < depth; ++i)
  2700. {
  2701. sTabs += " ";
  2702. }
  2703. const char* cTabs = sTabs.c_str();
  2704.  
  2705. if(recursive)
  2706. {
  2707. glitch::scene::SSceneNodeList::iterator it = Node->childrenBegin();
  2708. for(; it != Node->childrenEnd(); ++it)
  2709. {
  2710. count += PrintNodeProperties((&(*it)), recursive, depth + 1);
  2711. }
  2712. }
  2713. return count;
  2714. }
  2715.  
  2716. void GS3DStuff::draw3dAABB(const glitch::core::aabbox3df& aabb, glitch::video::SColor color, const glitch::core::matrix4* transform)
  2717. {
  2718. glitch::video::IVideoDriver* vd = GetVideoDriver();
  2719.  
  2720. glitch::core::vector3df max = aabb.MaxEdge;
  2721. glitch::core::vector3df min = aabb.MinEdge;
  2722.  
  2723. glitch::core::vector3df point1(max.getX(), max.getY(), max.getZ());
  2724. glitch::core::vector3df point2(max.getX(), min.getY(), max.getZ());
  2725. glitch::core::vector3df point3(min.getX(), max.getY(), max.getZ());
  2726. glitch::core::vector3df point4(min.getX(), min.getY(), max.getZ());
  2727. glitch::core::vector3df point5(max.getX(), max.getY(), min.getZ());
  2728. glitch::core::vector3df point6(max.getX(), min.getY(), min.getZ());
  2729. glitch::core::vector3df point7(min.getX(), max.getY(), min.getZ());
  2730. glitch::core::vector3df point8(min.getX(), min.getY(), min.getZ());
  2731.  
  2732. if(transform)
  2733. {
  2734. transform->transformVect(point1);
  2735. transform->transformVect(point2);
  2736. transform->transformVect(point3);
  2737. transform->transformVect(point4);
  2738. transform->transformVect(point5);
  2739. transform->transformVect(point6);
  2740. transform->transformVect(point7);
  2741. transform->transformVect(point8);
  2742. }
  2743.  
  2744. GS3DStuff::draw3DLineBuffered(point1, point2, color);
  2745. GS3DStuff::draw3DLineBuffered(point1, point3, color);
  2746. GS3DStuff::draw3DLineBuffered(point1, point5, color);
  2747. GS3DStuff::draw3DLineBuffered(point2, point4, color);
  2748. GS3DStuff::draw3DLineBuffered(point2, point6, color);
  2749. GS3DStuff::draw3DLineBuffered(point3, point7, color);
  2750. GS3DStuff::draw3DLineBuffered(point3, point4, color);
  2751. GS3DStuff::draw3DLineBuffered(point4, point8, color);
  2752. GS3DStuff::draw3DLineBuffered(point5, point6, color);
  2753. GS3DStuff::draw3DLineBuffered(point5, point7, color);
  2754. GS3DStuff::draw3DLineBuffered(point6, point8, color);
  2755. GS3DStuff::draw3DLineBuffered(point7, point8, color);
  2756. }
  2757.  
  2758. void GS3DStuff::drawCircle(const glitch::core::vector3df& center, const float radius, const unsigned int numPoints, const glitch::video::SColor& color)
  2759. {
  2760. glitch::video::IVideoDriver* vd = GetVideoDriver();
  2761.  
  2762. float angle = 0;
  2763. float x = sinf(0);
  2764. float y = cosf(0);
  2765.  
  2766. float interval = glf::TWO_PI/static_cast<float>(numPoints);
  2767.  
  2768. glitch::core::vector3df point01(center.getX() + x*radius, center.getY() + y*radius, center.getZ());
  2769. glitch::core::vector3df point02(center.getX() - x*radius, center.getY() - y*radius, center.getZ());
  2770. glitch::core::vector3df point03(center.getX() + x*radius, center.getY() - y*radius, center.getZ());
  2771. glitch::core::vector3df point04(center.getX() - x*radius, center.getY() + y*radius, center.getZ());
  2772. glitch::core::vector3df point05(center.getX() + y*radius, center.getY() + x*radius, center.getZ());
  2773. glitch::core::vector3df point06(center.getX() - y*radius, center.getY() - x*radius, center.getZ());
  2774. glitch::core::vector3df point07(center.getX() + y*radius, center.getY() - x*radius, center.getZ());
  2775. glitch::core::vector3df point08(center.getX() - y*radius, center.getY() + x*radius, center.getZ());
  2776.  
  2777. while(angle <= glf::PI_2/2)
  2778. {
  2779. angle += interval;
  2780.  
  2781. x = sinf(angle);
  2782. y = cosf(angle);
  2783. glitch::core::vector3df point09(center.getX() + x*radius, center.getY() + y*radius, center.getZ());
  2784. glitch::core::vector3df point10(center.getX() - x*radius, center.getY() - y*radius, center.getZ());
  2785. glitch::core::vector3df point11(center.getX() + x*radius, center.getY() - y*radius, center.getZ());
  2786. glitch::core::vector3df point12(center.getX() - x*radius, center.getY() + y*radius, center.getZ());
  2787. glitch::core::vector3df point13(center.getX() + y*radius, center.getY() + x*radius, center.getZ());
  2788. glitch::core::vector3df point14(center.getX() - y*radius, center.getY() - x*radius, center.getZ());
  2789. glitch::core::vector3df point15(center.getX() + y*radius, center.getY() - x*radius, center.getZ());
  2790. glitch::core::vector3df point16(center.getX() - y*radius, center.getY() + x*radius, center.getZ());
  2791.  
  2792. GS3DStuff::draw3DLineBuffered(point01, point09, color);
  2793. GS3DStuff::draw3DLineBuffered(point02, point10, color);
  2794. GS3DStuff::draw3DLineBuffered(point03, point11, color);
  2795. GS3DStuff::draw3DLineBuffered(point04, point12, color);
  2796. GS3DStuff::draw3DLineBuffered(point05, point13, color);
  2797. GS3DStuff::draw3DLineBuffered(point06, point14, color);
  2798. GS3DStuff::draw3DLineBuffered(point07, point15, color);
  2799. GS3DStuff::draw3DLineBuffered(point08, point16, color);
  2800.  
  2801. point01 = point09;
  2802. point02 = point10;
  2803. point03 = point11;
  2804. point04 = point12;
  2805. point05 = point13;
  2806. point06 = point14;
  2807. point07 = point15;
  2808. point08 = point16;
  2809. }
  2810. }
  2811.  
  2812. void GS3DStuff::drawNormal(const glitch::core::vector3df& start, const glitch::core::vector3df& normal, float zOffset, glitch::video::SColor color)
  2813. {
  2814. const int normalLength = 100.0f;
  2815.  
  2816. glitch::core::vector3df normal2 = normal;
  2817. glitch::core::vector3df from = start;
  2818. from.z() += zOffset;
  2819.  
  2820. normal2.normalize();
  2821. normal2 *= normalLength;
  2822.  
  2823. glitch::core::vector3df to = from + normal2;
  2824.  
  2825. glitch::core::vector3df const0(1.0f, 1.0f, 1.0f);
  2826. glitch::core::vector3df const1(0.0f, 0.0f, 0.0f);
  2827.  
  2828. glitch::core::vector3df ortho;
  2829. {
  2830. // Compute perpendicular vector
  2831. glitch::core::vector3df perpendicular0;
  2832. perpendicular0 = normal2.crossProduct(const0);
  2833. glitch::core::vector3df perpendicular1;
  2834. perpendicular1 = normal2.crossProduct(const1);
  2835.  
  2836. const float l0 = perpendicular0.getLengthSQ();
  2837. const float l1 = perpendicular1.getLengthSQ();
  2838. if(l0 < l1)
  2839. {
  2840. ortho = perpendicular1;
  2841. }
  2842. else
  2843. {
  2844. ortho = perpendicular0;
  2845. }
  2846. }
  2847.  
  2848. ortho.normalize();
  2849.  
  2850. glitch::core::vector3df ortho2;
  2851. ortho2 = normal2.crossProduct(ortho);
  2852.  
  2853. ortho *= normal2.getLength();
  2854.  
  2855. float c0 = 0.85f;
  2856. float c1 = (1.0f - c0);
  2857.  
  2858. glitch::core::vector3df p;
  2859. p = from + normal2 * c0 ;
  2860.  
  2861. glitch::core::vector3df p0;
  2862. p0 = p + (ortho * c1);
  2863. glitch::core::vector3df p1;
  2864. p1 = p + (ortho * -c1);
  2865. glitch::core::vector3df p2;
  2866. p2 = p + (ortho2 * c1);
  2867. glitch::core::vector3df p3;
  2868. p3 = p + (ortho2 * -c1);
  2869.  
  2870. GS3DStuff::draw3DLineBuffered(from, to, color);
  2871. GS3DStuff::draw3DLineBuffered(to, p0, color);
  2872. GS3DStuff::draw3DLineBuffered(to, p1, color);
  2873. GS3DStuff::draw3DLineBuffered(to, p2, color);
  2874. GS3DStuff::draw3DLineBuffered(to, p3, color);
  2875. }
  2876.  
  2877. void GS3DStuff::drawLine(glitch::core::vector3df start, glitch::core::vector3df end, float zOffset, glitch::video::SColor color)
  2878. {
  2879. start[2] += zOffset;
  2880. end[2] += zOffset;
  2881. GS3DStuff::draw3DLineBuffered(start, end, color);
  2882. }
  2883.  
  2884. void GS3DStuff::drawPermanentLine(glitch::core::vector3df start, glitch::core::vector3df end)
  2885. {
  2886. s_plStart = start;
  2887. s_plEnd = end;
  2888. }
  2889.  
  2890. void GS3DStuff::drawPoint(glitch::core::vector3df point, float zOffset, float radius, glitch::video::SColor color)
  2891. {
  2892. glitch::core::vector3df bmin(point.getX() - radius, point.getY() - radius, (point.getZ() + zOffset) - radius);
  2893. glitch::core::vector3df bmax(point.getX() + radius, point.getY() + radius, (point.getZ() + zOffset) + radius);
  2894. glitch::core::aabbox3df box(bmin, bmax);
  2895.  
  2896. glitch::video::IVideoDriver* vd = GetVideoDriver();
  2897. GS3DStuff::draw3DBoxBuffered(box, color);
  2898. }
  2899.  
  2900. void GS3DStuff::draw3DLineBuffered(const glitch::core::vector3df& start, const glitch::core::vector3df& end, glitch::video::SColor color)
  2901. {
  2902. BufferedLinePositions.push_back(start);
  2903. BufferedLinePositions.push_back(end);
  2904. BufferedLineColor.push_back(color);
  2905. BufferedLineColor.push_back(color);
  2906. BufferedLineIndexes.push_back(BufferedLineIndexes.size()%65536);
  2907. BufferedLineIndexes.push_back(BufferedLineIndexes.size()%65536);
  2908. }
  2909.  
  2910. void GS3DStuff::draw3DLineBuffered(const glitch::core::vector3df& start, const glitch::core::vector3df& end, glitch::video::SColor color, glitch::video::SColor color2)
  2911. {
  2912. BufferedLinePositions.push_back(start);
  2913. BufferedLinePositions.push_back(end);
  2914. BufferedLineColor.push_back(color);
  2915. BufferedLineColor.push_back(color2);
  2916. BufferedLineIndexes.push_back(BufferedLineIndexes.size()%65536);
  2917. BufferedLineIndexes.push_back(BufferedLineIndexes.size()%65536);
  2918. }
  2919.  
  2920. void GS3DStuff::draw3DBoxBuffered(const glitch::core::aabbox3d<f32>& box, glitch::video::SColor color)
  2921. {
  2922. glitch::core::vector3df edges[8];
  2923. box.getEdges(edges);
  2924.  
  2925. GS3DStuff::draw3DLineBuffered(edges[0], edges[1], color);
  2926. GS3DStuff::draw3DLineBuffered(edges[0], edges[2], color);
  2927. GS3DStuff::draw3DLineBuffered(edges[0], edges[4], color);
  2928. GS3DStuff::draw3DLineBuffered(edges[1], edges[3], color);
  2929. GS3DStuff::draw3DLineBuffered(edges[1], edges[5], color);
  2930. GS3DStuff::draw3DLineBuffered(edges[2], edges[3], color);
  2931. GS3DStuff::draw3DLineBuffered(edges[2], edges[6], color);
  2932. GS3DStuff::draw3DLineBuffered(edges[3], edges[7], color);
  2933. GS3DStuff::draw3DLineBuffered(edges[4], edges[5], color);
  2934. GS3DStuff::draw3DLineBuffered(edges[4], edges[6], color);
  2935. GS3DStuff::draw3DLineBuffered(edges[5], edges[7], color);
  2936. GS3DStuff::draw3DLineBuffered(edges[6], edges[7], color);
  2937. }
  2938.  
  2939. void GS3DStuff::flushBufferedLines()
  2940. {
  2941. glitch::video::IVideoDriver* vd = GetVideoDriver();
  2942.  
  2943. if(BufferedLineColor.size() > 0)
  2944. {
  2945. vd->clearBuffers(glitch::video::EFB_DEPTH);
  2946. CMaterialRendererManager& mrm = vd->getMaterialRendererManager();
  2947. vd->setMaterial(mrm.getMaterialInstance(vd, glitch::video::EMT_UNLIT_NON_TEXTURED_SOLID));
  2948. int cnt = (BufferedLineIndexes.size()-1)/65536;
  2949. for(int i=0; i<=cnt; i++)
  2950. {
  2951. vd->draw3DLines(
  2952. &BufferedLinePositions[i*65536],
  2953. &BufferedLineIndexes[i*65536],
  2954. &BufferedLineColor[i*65536],
  2955. i != cnt ? 65536 : BufferedLineIndexes.size()%65536,
  2956. (i != cnt ? 65536 : BufferedLineIndexes.size()%65536)/2);
  2957. }
  2958. }
  2959. BufferedLinePositions.resize(0);
  2960. BufferedLineColor.resize(0);
  2961. BufferedLineIndexes.resize(0);
  2962. }
  2963.  
  2964. LODSceneNode* GS3DStuff::parseSceneNodeForLOD(glitch::scene::ISceneNode* nodeToParse, LODSceneNode* LODNode)
  2965. {
  2966. return LODNode;
  2967. }
  2968.  
  2969. bool GS3DStuff::getProperty(const void* userProps, const char* prop, char* buffer)
  2970. {
  2971. if(!userProps)
  2972. {
  2973. return false;
  2974. }
  2975. const char* properties = *((char**)userProps);
  2976.  
  2977. const char* propertyStart = strstr(properties, prop);
  2978. const char* propertyEnd = 0;
  2979. if(!propertyStart)
  2980. {
  2981. return false;
  2982. }
  2983. propertyEnd = strchr(propertyStart, ';');
  2984. if(!propertyEnd)
  2985. {
  2986. propertyEnd = strchr(propertyStart, '\n');
  2987. if(!propertyEnd)
  2988. {
  2989. propertyEnd = properties + strlen(properties);
  2990. }
  2991. }
  2992.  
  2993. propertyStart = strstr(propertyStart, "=") + 1;
  2994.  
  2995. int length = propertyEnd - propertyStart;
  2996.  
  2997. memcpy(buffer, propertyStart, length);
  2998. buffer[length + 1] = '\0';
  2999.  
  3000. return true;
  3001. }
  3002.  
  3003. LevelObject* CheckForDespawnWantedLevel(LevelObject* lo)
  3004. {
  3005. if(!lo)
  3006. {
  3007. return lo;
  3008. }
  3009.  
  3010. if(!Player::GetPlayer())
  3011. {
  3012. return lo;
  3013. }
  3014.  
  3015. bool isCop = lo->IsCop();
  3016. GLF_ASSERTMSG(isCop && WantedMgr()->GetWantedLevel() > 0, "Programmer error : CheckForDespawnWantedLevel should only be called for cops during wanted level\n");
  3017.  
  3018. bool shouldDespawn = false;
  3019. Character* copCharacter = glf::DynamicCast<Character>(lo);
  3020. Vehicle* copCar = glf::DynamicCast<Vehicle>(lo);
  3021.  
  3022. //Quicker Test first : is he dead ?
  3023. // Now testing IsDead is wrong because it becomes true as soon as the HP is zero and the npc starts it's "dying" sequence
  3024. //
  3025. if(lo->isWaitingForDespawn())
  3026. {
  3027. SCOPE_TRACE("WantedLevel", "Despawning %s because cop hes dead, duh ? \n", lo->GetName());
  3028. shouldDespawn = true;
  3029. }
  3030. else
  3031. {
  3032. //Slighly more expensive test (distance related)
  3033.  
  3034. //Distance Related Test.
  3035. glitch::core::vector3df pos = Player::GetPlayer()->GetPosition();
  3036. float distSq = pos.getDistanceFromSQ(lo->GetPosition());
  3037. int presetId;
  3038. if(copCar)
  3039. {
  3040. presetId = Player::GetPlayer()->GetSpawnInputsPreset(Player::SpawnInputsPresetCopCar);
  3041. }
  3042. else if(World::GetInstance()->IsInterior())
  3043. {
  3044. presetId = DataByIdx(Locations, GS3DStuff::GetCurrentLocation(), spawnInputsPresetCopInterior);
  3045. }
  3046. else
  3047. {
  3048. presetId = Player::GetPlayer()->GetSpawnInputsPreset(Player::SpawnInputsPresetCopNPC);
  3049. }
  3050. const float spawnRadiusMulti = DataByIdx(PhonePerformanceProfiles, gPhonePerfId, spawnInputPresetsMultiplicator);
  3051. float despawn = lo->isVisibleOnScreen(false) ? static_cast<int>(DataByIdx(SpawnInputsPresets, presetId, despawnRadius)) :
  3052. static_cast<int>(DataByIdx(SpawnInputsPresets, presetId, offScreenDespawnRadius));
  3053. despawn *= spawnRadiusMulti;
  3054. float despawnSq = SQUARE(despawn);
  3055. float despawnIfStuckSq = WantedMgr()->GetDespawnIfStuckSq();
  3056.  
  3057. //if we are farther than despawn radius, unspawn cop
  3058. if( distSq >= despawnSq )
  3059. {
  3060. SCOPE_TRACE("WantedLevel", "Despawning %s because cop is outside the curDist=%f >= despawnDist=%f\n",
  3061. lo->GetName()
  3062. ,WantedLevelManager::SqCentimetersToMeters(distSq)
  3063. ,WantedLevelManager::SqCentimetersToMeters(despawnSq));
  3064.  
  3065. shouldDespawn = true;
  3066. }
  3067. else if(distSq >= despawnIfStuckSq)
  3068. {
  3069. shouldDespawn = lo->TestDespawnIfStuckWantedLevel();
  3070. }
  3071. }
  3072.  
  3073.  
  3074. if(shouldDespawn)
  3075. {
  3076. SCOPE_TRACE("WantedLevel", "Despawning cop=%s\n", lo->GetName());
  3077.  
  3078. //Calling this a Vehicle will also disable it's driver so I think it's ok.
  3079. lo = GameObjectManager::GetInstance()->disable(lo);
  3080. }
  3081.  
  3082. //for now, simply NEVER despawn.
  3083. //need better design idea.
  3084. return lo;
  3085. }
  3086.  
  3087. LevelObject* GS3DStuff::checkForDespawn(LevelObject* lo)
  3088. {
  3089. ProfilerScopeGameplay("GS3DStuff::checkForDespawn", NULL);
  3090.  
  3091. bool isSpawned = lo->GetFlag(Kst(GameObjectFlag, Spawned)) && !lo->isActor();
  3092. bool isDead = lo->isDead() && (GameObjectManager::isCharacter(lo) || GameObjectManager::isVehicle(lo) || GameObjectManager::isGameObject(lo));
  3093. bool isToBeReleased = lo->GetFlag(Kst(GameObjectFlag, ToBeReleased));
  3094.  
  3095. Vehicle* veh = glf::DynamicCast<Vehicle>(lo);
  3096.  
  3097. bool isVehicle = veh != 0;
  3098. if(isSpawned || isDead || isToBeReleased)
  3099. {
  3100. Player* player = Player::GetPlayer();
  3101.  
  3102. bool isCop = lo->IsCop();
  3103. NPC* npc = 0;
  3104.  
  3105. if(lo->getType() == Cst(GameObjectType, NPC))
  3106. {
  3107. npc = (NPC*)lo;
  3108. }
  3109.  
  3110. if(npc && !lo->isDead())
  3111. {
  3112. NPC* npc = (NPC*)lo;
  3113.  
  3114. // Leave NPC despawn to the vehicle.
  3115. if(npc->isInAVehicle())
  3116. {
  3117. return lo;
  3118. }
  3119. }
  3120.  
  3121. if(isCop && npc && !GameObjectManager::isHelicopter(npc->getVehicle()) && WantedMgr()->GetWantedLevel() > 0)
  3122. {
  3123. return CheckForDespawnWantedLevel(lo);
  3124. }
  3125.  
  3126. const float spawnRadiusMulti = DataByIdx(PhonePerformanceProfiles, gPhonePerfId, spawnInputPresetsMultiplicator);
  3127.  
  3128. int presetId;
  3129. float radius;
  3130. float radiusSQ;
  3131.  
  3132. // same for cop cars
  3133. if(isVehicle)
  3134. {
  3135. // Can't despawn player vehicle or target vehicle while player is in it
  3136. if(player->isInAVehicle() && lo == player->getVehicle())
  3137. {
  3138. return lo;
  3139. }
  3140. else if(!veh->isDestroyed())
  3141. {
  3142. Player* player = Player::GetPlayer();
  3143. if(veh->hasDriver())
  3144. {
  3145. //Don't despawn an active actor's vehicle.
  3146. if(veh->getDriver()->isActor()&& !veh->getDriver()->GetFlag(Kst(GameObjectFlag, ToBeReleased)))
  3147. {
  3148. return lo;
  3149. }
  3150.  
  3151. //Don't despawn vehicle if driver is interracting with vehicle.
  3152. if(veh->getDriver()->isInteractingWithVehicle() && veh->getDriver()->IsVisible())
  3153. {
  3154. return lo;
  3155. }
  3156. }
  3157.  
  3158. glitch::core::vector3df p1 = Player::GetPlayer()->GetPosition();
  3159. glitch::core::vector3df p2 = veh->GetPosition();
  3160.  
  3161. glitch::core::vector3df dist = player->GetPosition() - veh->GetPosition();
  3162.  
  3163. if(WantedMgr()->GetWantedLevel() > 0)
  3164. {
  3165. presetId = Player::GetPlayer()->GetSpawnInputsPreset(Player::SpawnInputsPresetCopCar);
  3166. }
  3167. else
  3168. {
  3169. presetId = Player::GetPlayer()->GetSpawnInputsPreset(Player::SpawnInputsPresetVehicle);
  3170. }
  3171.  
  3172. radius = lo->isVisibleOnScreen(false) ? static_cast<int>(DataByIdx(SpawnInputsPresets, presetId, despawnRadius)) :
  3173. static_cast<int>(DataByIdx(SpawnInputsPresets, presetId, offScreenDespawnRadius));
  3174. radius *= spawnRadiusMulti;
  3175. radiusSQ = SQUARE(radius);
  3176.  
  3177. // if this is a cop car and a cop is actually driving...
  3178. if(isCop && veh->getDriver() && dist.getLengthSQ() < radiusSQ)//veh->isChasing() &&
  3179. {
  3180. return lo;
  3181. }
  3182. // Can't despawn player vehicle or target vehicle.
  3183. else if(lo == player->aiGetVehicle() || lo == player->m_closestVehicle || lo == player->m_lastUsedVehicle)
  3184. {
  3185. return lo;
  3186. }
  3187. else if(veh->getViewer() && veh->getViewer()->isEnabled())
  3188. {
  3189. glitch::core::vector3df dist = veh->getViewer()->GetPosition() - veh->GetPosition();
  3190. if(dist.getLengthSQ() < radiusSQ)
  3191. {
  3192. return lo;
  3193. }
  3194. }
  3195. }
  3196. }
  3197.  
  3198. glitch::core::vector3df outerSpawnCenter = Player::GetPlayer()->GetPosition();
  3199.  
  3200. if(World::GetInstance()->IsInterior())
  3201. {
  3202. if(gom->isCharacter(lo) && lo->IsCop() && WantedMgr()->GetWantedLevel() > 0)
  3203. {
  3204. presetId = DataByIdx(Locations, GetCurrentLocation(), spawnInputsPresetCopInterior);
  3205. }
  3206. else
  3207. {
  3208. presetId = DataByIdx(Locations, GetCurrentLocation(), spawnInputsPresetInterior);
  3209. }
  3210. }
  3211. else if(gom->isVehicle(lo))
  3212. {
  3213. if(((Vehicle*)lo)->getDriver())
  3214. {
  3215. if(lo->IsCop() && WantedMgr()->GetWantedLevel() > 0)
  3216. {
  3217. presetId = Player::GetPlayer()->GetSpawnInputsPreset(Player::SpawnInputsPresetCopCar);
  3218. }
  3219. else
  3220. {
  3221. presetId = Player::GetPlayer()->GetSpawnInputsPreset(Player::SpawnInputsPresetVehicle);
  3222. }
  3223. }
  3224. else
  3225. {
  3226. presetId = Player::GetPlayer()->GetSpawnInputsPreset(Player::SpawnInputsPresetParkedVehicle);
  3227. }
  3228. }
  3229. else if(gom->isCharacter(lo))
  3230. {
  3231. if(lo->IsCop() && WantedMgr()->GetWantedLevel() > 0)
  3232. {
  3233. presetId = Player::GetPlayer()->GetSpawnInputsPreset(Player::SpawnInputsPresetCopNPC);
  3234. }
  3235. else
  3236. {
  3237. presetId = Player::GetPlayer()->GetSpawnInputsPreset(Player::SpawnInputsPresetNPC);
  3238. }
  3239. }
  3240. else
  3241. {
  3242. presetId = Player::GetPlayer()->GetSpawnInputsPreset(Player::SpawnInputsPresetRoadBlock);
  3243. }
  3244.  
  3245. radius = lo->isVisibleOnScreen(false) ? static_cast<int>(DataByIdx(SpawnInputsPresets, presetId, despawnRadius)) :
  3246. static_cast<int>(DataByIdx(SpawnInputsPresets, presetId, offScreenDespawnRadius));
  3247. radius *= spawnRadiusMulti;
  3248. radiusSQ = SQUARE(radius);
  3249.  
  3250. glitch::core::vector3df loPos = lo->GetPosition();
  3251. float centerZ = outerSpawnCenter.getZ();
  3252. float loZ = loPos.getZ();
  3253. const float MAX_Z_OFFSET_TO_STAY_SPAWNED = 500 * M_TO_CM; // (this is huge so it doesnt despawn flying stuff ?!?!? maybe just dont despawn on Z ?)
  3254.  
  3255. // despawn radius is in 2D.
  3256. // we handle Z diff individually...
  3257. loPos.setZ(0);
  3258. outerSpawnCenter.setZ(0);
  3259.  
  3260. float loPosToOuterDistSQ = loPos.getDistanceFromSQ(outerSpawnCenter);
  3261.  
  3262. float despawnRadiusSQ = radiusSQ;
  3263.  
  3264. // [ICH] easy hack just to further the despawn radius of NPCs so that they don't disappear when they die from far at a targetable range
  3265. if (lo->getType() == Cst(GameObjectType, NPC))
  3266. {
  3267. despawnRadiusSQ *= 2.0f;
  3268.  
  3269. if (Player::GetPlayer() && Player::GetPlayer()->isInSnipingHUD())
  3270. {
  3271. despawnRadiusSQ *= 2.0f;
  3272. }
  3273. }
  3274.  
  3275. if(lo->isWaitingForDespawn()
  3276. || std::abs(centerZ - loZ) > MAX_Z_OFFSET_TO_STAY_SPAWNED
  3277. || loPosToOuterDistSQ >= despawnRadiusSQ
  3278. || lo->getType() == Cst(GameObjectType, Projectile))
  3279. {
  3280. ProfilerScopeGameplay("GS3DStuff::checkForDespawn::disable", NULL);
  3281. SCOPE_TRACE("SpawnManager", "Despawning lo=%s,\n\tpos=<%f,%f,%f>,\n\tdespawnCenterPos=<%f,%f,%f>\n\tdist=%f (max=%d)\n"
  3282. , lo->GetName()
  3283. , loPos.getX()
  3284. , loPos.getY()
  3285. , loZ
  3286. , outerSpawnCenter.getX()
  3287. , outerSpawnCenter.getY()
  3288. , centerZ
  3289. , glf::Sqrt(loPosToOuterDistSQ)
  3290. , radius);
  3291.  
  3292. if( GET_DEBUG_SWITCH("DisableSpawnManager") )
  3293. {
  3294. //quick hack, just teleport back that shit closer to player and that's it. this will void all the SpawnManager Shits but keep the "Max number of spawn functional"
  3295. glitch::core::vector3df newPos = Player::GetPlayer()->GetPosition();
  3296. float angle = Random::GetRandom(90, 270);
  3297. float dist = Random::GetRandom(200, 1500);
  3298. glitch::core::vector3df playerR = Player::GetPlayer()->GetFront();
  3299. newPos = newPos + (dist * playerR.rotateXYBy(angle));
  3300. lo->moveTo(newPos, lo->GetRotation());
  3301. lo->SetSnappedToFloor(false);
  3302. }
  3303. else
  3304. {
  3305. if(gom->isVehicle(lo))
  3306. {
  3307. // Remove driver
  3308. Character* driver = static_cast<Vehicle*>(lo)->getDriver();
  3309. if(driver)
  3310. {
  3311. driver->WaitForDespawn();
  3312. }
  3313. }
  3314.  
  3315. lo = gom->disable(lo);
  3316. }
  3317. }
  3318. }
  3319.  
  3320. return lo;
  3321. }
  3322.  
  3323. void GS3DStuff::forceDespawn(int gameObjectType)
  3324. {
  3325. LevelObject* lo = gom->GetFirstLo(Kst(ObjectFrameActions, UpdateAndDraw));
  3326. Player* player = Player::GetPlayer();
  3327. while(lo)
  3328. {
  3329. bool despawned = false;
  3330. if(lo->getType() == gameObjectType
  3331. && ((lo->isActor()
  3332. && lo->GetFlag(Kst(GameObjectFlag, ToBeReleased)))
  3333. || (!lo->isActor()
  3334. && lo->GetFlag(Kst(GameObjectFlag, Spawned) | Kst(GameObjectFlag, ToBeReleased)))))
  3335. {
  3336. if(lo != player->aiGetVehicle() && lo != player->getVehicle() && lo != player->m_closestVehicle && lo != player->m_lastUsedVehicle)
  3337. {
  3338. despawned = true;
  3339. lo = gom->disable(lo);
  3340. }
  3341. }
  3342. if(!despawned)
  3343. {
  3344. lo = gom->GetNextLo(lo);
  3345. }
  3346. }
  3347. }
  3348.  
  3349. // IMPORTANT: Don't call this function directly.
  3350. // To set the orientation, use Application::SetGameOrientation
  3351. void GS3DStuff::SetCurrentOrientation(const glitch::video::E_ORIENTATION new_ori)
  3352. {
  3353. s_orientation = new_ori;
  3354. glitch::video::IVideoDriver* driver = GetVideoDriver();
  3355. #if defined(OS_IPHONE) || defined(OS_ANDROID)
  3356. driver->setOrientation((s_orientation == glitch::video::EO_180) ? glitch::video::EO_180 : glitch::video::EO_0);
  3357. #else
  3358. driver->setOrientation(s_orientation);
  3359. #endif
  3360. };
  3361.  
  3362. #if WIN32
  3363. #include <gl/gl.h>
  3364. #elif defined(OS_IPHONE)
  3365. #include <OpenGLES/ES1/gl.h>
  3366. #elif defined(OS_ANDROID)
  3367. #include <GLES/gl.h>
  3368. #endif
  3369.  
  3370. extern StdString gForcedPhoneProfile;
  3371.  
  3372. void ChoosePerfProfile(glitch::video::IVideoDriver* driver, int idx)
  3373. {
  3374. #if defined(OS_IPHONE) || defined(OS_ANDROID)
  3375. return;
  3376. #endif
  3377.  
  3378. int defaultProfile = 0;
  3379.  
  3380. if (idx < 0)
  3381. {
  3382. const char* glVendor = driver->getVendorInfo(); // Imagination Technologies
  3383. const char* glVersion = driver->getName(); // PowerVR SGX 535
  3384. const char* glRenderer = driver->getRendererInfo();
  3385. //iphone3g OpenGL ES 2.0
  3386. //iphone3gs OpenGL ES 2.0
  3387. //ipad1 OpenGL ES 2.0
  3388. //iphone4 OpenGL ES 2.0 IMGSGX535-48.11.3
  3389. //ipad2 OpenGL ES 2.0 IMGSGX543-58.6
  3390.  
  3391. SCOPE_TRACE("PerfProfile", "glVendor %s\n", glVendor);
  3392. SCOPE_TRACE("PerfProfile", "glVersion %s\n", glVersion);
  3393. SCOPE_TRACE("PerfProfile", "glRenderer %s\n", glRenderer);
  3394.  
  3395. int screenWidth = Application::GetViewportWidth();
  3396. int screenHeight = Application::GetViewportHeight();
  3397.  
  3398. if(screenWidth < screenHeight) //make width bigger than height
  3399. {
  3400. int tmp = screenHeight;
  3401. screenHeight = screenWidth;
  3402. screenWidth = tmp;
  3403. }
  3404.  
  3405. int nbProfiles = DataCount(PhonePerformanceProfiles);
  3406.  
  3407. #if WIN32
  3408. if(GET_DEBUG_SWITCH("IsHighQualityCinematic"))
  3409. {
  3410. gForcedPhoneProfile = StdString("CinematicRenderer");
  3411. }
  3412.  
  3413. for(size_t i = 0; i < nbProfiles; ++i)
  3414. {
  3415. StdString family = (const char*)DataByIdx(PhonePerformanceProfiles, i, deviceFamily);
  3416.  
  3417. if(gForcedPhoneProfile == family)
  3418. {
  3419. gPhonePerfId = i;
  3420. SCOPE_TRACE("PerfProfile", "chosen profile %d -> %s\n", idx, family.c_str());
  3421. return;
  3422. }
  3423. }
  3424. #endif
  3425. for(size_t i = 0; i < nbProfiles; ++i)
  3426. {
  3427. StdString family = (const char*)DataByIdx(PhonePerformanceProfiles, i, deviceFamily);
  3428.  
  3429. if(family == gForcedPhoneProfile)
  3430. {
  3431. idx = i;
  3432. break;
  3433. }
  3434.  
  3435. int numberOfDevices = DataByIdxSize(PhonePerformanceProfiles, i, names);
  3436. for(size_t j = 0; j < numberOfDevices; ++j)
  3437. {
  3438. const char* perfProfileName = DataByIdxN(PhonePerformanceProfiles, i, names, j);
  3439.  
  3440. #if defined(OS_ANDROID)
  3441. if(strstr("ANDROID DEFAULT", perfProfileName))
  3442. {
  3443. #else
  3444. // WIN32 and OS_IPHONE
  3445. if(strstr("DEFAULT", perfProfileName))
  3446. {
  3447. #endif
  3448. defaultProfile = i;
  3449. }
  3450.  
  3451. if(strstr(glVersion, perfProfileName) || strstr(glRenderer, perfProfileName))
  3452. {
  3453. idx = i;
  3454. break;
  3455. }
  3456. }
  3457.  
  3458. if (idx >= 0)
  3459. {
  3460. break;
  3461. }
  3462. }
  3463. }
  3464.  
  3465. if(idx < 0)
  3466. {
  3467. idx = defaultProfile;
  3468. }
  3469.  
  3470. gPhonePerfId = idx;
  3471.  
  3472. SCOPE_TRACE("PerfProfile", "chosen profile %d -> %s\n", idx, static_cast<const char*>(DataByIdx(PhonePerformanceProfiles, gPhonePerfId, deviceFamily)));
  3473. }
  3474.  
  3475. glitch::u32 g_numCapping = 0;
  3476. glitch::u32 g_numSavedCapping = 0;
  3477. glitch::u32 g_numLoadedCapping = 0;
  3478.  
  3479. size_t gSegmentUid = 0;
  3480. int gNumSegments = 0;
  3481. int gIsReallyDoneLoopCount = 0;
  3482. void GS3DStuff::updateStreaming(const glitch::scene::SViewFrustum* frustum, glitch::core::vector3df& pos)
  3483. {
  3484.  
  3485. }
  3486.  
  3487. bool GS3DStuff::isStreaming()
  3488. {
  3489. return s_streamingState != SS_NONE;
  3490. }
  3491.  
  3492. void GS3DStuff::streamingUpdate(int dt)
  3493. {
  3494. static int frameCount = 0;
  3495. s_streamingTimer -= dt;
  3496.  
  3497. World* world = World::GetInstance();
  3498. switch(s_streamingState)
  3499. {
  3500. case SS_FADEOUT:
  3501. {
  3502. if(s_streamingTimer < 0)
  3503. {
  3504. frameCount = 0;
  3505. s_streamingState = SS_STREAMING;
  3506. s_streamingElapsed = 0;
  3507. }
  3508. }
  3509. break;
  3510.  
  3511. case SS_STREAMING:
  3512. {
  3513. frameCount++;
  3514.  
  3515. bool isDone = GS3DStuff::IsAllStreamingDone();
  3516. bool isReallyDone = false;
  3517. g_Loading=true;
  3518. if(isDone)
  3519. {
  3520. isReallyDone = true;
  3521. }
  3522.  
  3523. glf::Thread::Sleep(10);
  3524.  
  3525.  
  3526. glitch::scene::ICameraSceneNodePtr camera = Application::GetInstance()->GetDevice()->getSceneManager()->getActiveCamera();
  3527. glitch::core::vector3df pos = camera->getAbsolutePosition();
  3528.  
  3529. //big ugly hack
  3530. extern bool gFromContinueGame;
  3531.  
  3532. if(isReallyDone)
  3533. {
  3534. bool isTopStateGd3dStuff = StateMachine::GetInstance()->isState<GS3DStuff>() != 0;
  3535. if(gFromContinueGame && isTopStateGd3dStuff && gIsReallyDoneLoopCount < 5)
  3536. {
  3537. gIsReallyDoneLoopCount++;
  3538. extern glitch::core::vector3df gLastStreamedPos;
  3539. glitch::core::vector3df lastStreamedPos = gLastStreamedPos;
  3540. pos = Player::GetPlayer()->GetPosition();
  3541. pos.setZ(0);
  3542. lastStreamedPos.setZ(0);
  3543. float lengthSQ = (pos - lastStreamedPos).getLengthSQ();
  3544. if(lengthSQ > 1500*1500)
  3545. {
  3546. //camera->setPosition(pos);
  3547. //camera->updateAbsolutePosition();
  3548. //CameraManager::GetInstance()->getActiveCamera()->setPosition(pos);
  3549. bool isPlayerVisible = Player::GetPlayer()->GetGlitchSceneNode()->isVisible();
  3550. Player::GetPlayer()->GetGlitchSceneNode()->setVisible(true);
  3551. if (!Player::GetPlayer()->isInAVehicle())
  3552. {
  3553. CameraManager::GetInstance()->enterMode(CAMERA_MODES::FOLLOW, Player::GetPlayer(), 0, 0);
  3554. }
  3555. else
  3556. {
  3557. CameraManager::GetInstance()->enterMode(CAMERA_MODES::VEHICLE, Player::GetPlayer()->getVehicle(), 0, 0);
  3558. }
  3559. CameraManager::GetInstance()->update(1000);
  3560. World::GetInstance()->UpdateStreaming(pos);
  3561. Player::GetPlayer()->GetGlitchSceneNode()->setVisible(isPlayerVisible);
  3562. isReallyDone = false;
  3563. }
  3564. }
  3565. }
  3566.  
  3567. if(isReallyDone)
  3568. {
  3569. gFromContinueGame = false;
  3570. gIsReallyDoneLoopCount = 0;
  3571. g_Loading=false;
  3572.  
  3573. if(s_skipFadeIn)
  3574. {
  3575. s_streamingState = SS_NONE;
  3576. Fade(0);
  3577. s_skipFadeIn = false;
  3578. }
  3579. else
  3580. {
  3581. World::GetInstance()->StreamingEnd();
  3582. s_streamingState = SS_FADEIN;
  3583. s_streamingDuration = s_streamingTimer = 500; // TODO: use constant
  3584. }
  3585.  
  3586. hideLoading();
  3587. CHudManager::GetInstance()->SetEnable(Cst(HudElements, Screen), true);
  3588. CHudManager::GetInstance()->unlock();
  3589. Application::GetInstance()->ResumeScripts();
  3590. }
  3591. else
  3592. {
  3593. frameCount = 0;
  3594. const glitch::scene::SViewFrustum* frustum = Application::GetInstance()->GetDevice()->getSceneManager()->getActiveCamera()->getViewFrustum();
  3595.  
  3596. if(gEnableEnvironment)
  3597. {
  3598. World::GetInstance()->UpdateStreaming(pos);
  3599. }
  3600.  
  3601. ProfilerScopeScene("texture streaming", NULL);
  3602. s_streamingElapsed += dt;
  3603.  
  3604. if(s_streamingElapsed >= 2000)
  3605. {
  3606. showLoading();
  3607. }
  3608. }
  3609. Application::GetInstance()->WatchDogForLoadingTime(true, true);
  3610. }
  3611. break;
  3612.  
  3613. case SS_FADEIN:
  3614. {
  3615. if (s_streamingTimer <= 0)
  3616. {
  3617. s_streamingState = SS_NONE;
  3618. s_streamingElapsed = 0;
  3619. s_streamingDuration = 1;
  3620. s_streamingTimer = 0;
  3621. Fade(0);
  3622. if (OnlineServiceMgr()->GetBITracker())
  3623. {
  3624. OnlineServiceMgr()->GetBITracker()->TrackLoadingTimes(online::tracking::BITracker::MMTOAP, false);
  3625.  
  3626. GVAdsManager::GetInstance()->OnLocationChange("action_phase");
  3627. }
  3628. }
  3629. Application::GetInstance()->WatchDogForLoadingTime(true, false);
  3630. }
  3631. break;
  3632.  
  3633. default:
  3634. break;
  3635. }
  3636. }
  3637.  
  3638. void GS3DStuff::streamingInit()
  3639. {
  3640. s_streamingState = SS_FADEOUT;
  3641. s_streamingTimer = 0;
  3642. s_streamingDuration = 200;
  3643. CHudManager::GetInstance()->SetEnable(Cst(HudElements, Screen), false);
  3644. CHudManager::GetInstance()->lock();
  3645. Application::GetInstance()->PauseScripts();
  3646. World::GetInstance()->StreamingInit();
  3647. }
  3648.  
  3649. void GS3DStuff::Fade(int intensity)
  3650. {
  3651. if (SwfManager::GetInstance() && SwfManager::GetInstance()->GetMenu(SwfManager::SWF_HUD))
  3652. {
  3653. if (s_streamingState == SS_STREAMING)
  3654. {
  3655. intensity = 255;
  3656. }
  3657.  
  3658. SndMgr()->SetGlobalMute((255.0f - (float)intensity) / 255.0f);
  3659.  
  3660. MenuFlashBase* swfHud = SwfManager::GetInstance()->GetMenu(SwfManager::SWF_HUD)->m_renderFX;
  3661. gameswf::CharacterHandle ch = swfHud->find("hudFade_mc");
  3662. ch.gotoAndStop("black");
  3663. ch.setAlpha(intensity / 255.f);
  3664. if (intensity > 0)
  3665. {
  3666. //this hack is needed for streaming only, since the streaming code probably doesnt give time to the flash to render before going in a long loop...
  3667. int screenWidth, screenHeight;
  3668. Application* app = Application::GetInstance();
  3669. glitch::video::C2DDriver* driver = app->GetDevice()->get2DDriver();
  3670. app->GetScreenDimensions(screenWidth, screenHeight);
  3671. driver->draw2DRectangle(glitch::video::SColor(intensity, 0, 0, 0), glitch::core::rect<int>(0, 0, screenWidth, screenHeight));
  3672.  
  3673. ch.setVisible(true);
  3674. }
  3675. else
  3676. {
  3677. ch.setVisible(false);
  3678. }
  3679. }
  3680. }
  3681.  
  3682. void GS3DStuff::streamingDraw2d()
  3683. {
  3684. int intensity = 0;
  3685. switch(s_streamingState)
  3686. {
  3687. case SS_FADEOUT:
  3688. intensity = 255 - s_streamingTimer * 255 / s_streamingDuration;
  3689. break;
  3690. case SS_STREAMING:
  3691. intensity = 255;
  3692. break;
  3693. case SS_FADEIN:
  3694. intensity = s_streamingTimer * 255 / s_streamingDuration;
  3695. break;
  3696. }
  3697.  
  3698. if(intensity > 0)
  3699. {
  3700. Fade(intensity);
  3701. }
  3702. }
  3703.  
  3704. void GS3DStuff::SwitchLocation(int id)
  3705. {
  3706. GLF_ASSERTMSG(id >= 0 && id < DataCount(Locations), "GS3DStuff::SwitchLocation : Cannot switch location because the given location id %i must be in the range of [0;%i[.", id, (int)DataCount(Locations));
  3707. if (id >= 0 && id < DataCount(Locations) && currentLocation != id)
  3708. {
  3709. TRACE_CRASH_LOG("GS3DStuff::SwitchLocation '%s' (%d)\n", DataName(Locations, id), id );
  3710.  
  3711. MapHandler* mapHandler = MenuMgr::GetInstance()->GetMapHandler();
  3712. ASSERT((mapHandler != 0) && "MapHandler cannot be null when switching location.");
  3713.  
  3714. if(mapHandler)
  3715. {
  3716. CHudManager::GetInstance()->setMinimap((int)DataByIdx(Locations, id, MapInfo));
  3717.  
  3718. menu::menuEventMgr::MenuEventManager::Members members;
  3719. GetMenuEventMgr()->DispatchEventAllRoots(flash_constants::events::MapEvent::NEW_LOCATION, members);
  3720.  
  3721. SCOPE_TRACE("MapLocation", "GS3DStuff::SwitchLocation PreviousID(%i) SwitchLocationToID(%i) MapInfoIdx(%i)\n", currentLocation, id, (int)DataByIdx(Locations, id, MapInfo));
  3722. }
  3723.  
  3724. // [ICH]: remove backdrop
  3725. GET_BACKDROP_ROOT()->removeAll();
  3726.  
  3727. const char* backdropFilename = static_cast<const char*>(DataByIdx(Locations, id, backdropFile));
  3728.  
  3729. if (strlen(backdropFilename) > 0)
  3730. {
  3731. glitch::scene::ISceneNodePtr backdropNode = CustomConstructScene(backdropFilename, SkyboxColladaFactory::getInstance(), false, E_CCS_OH_NONE);
  3732. GET_BACKDROP_ROOT()->addChild(backdropNode);
  3733. glitch::core::vector3df position(DataByIdx(Locations, id, backdropPosX), DataByIdx(Locations, id, backdropPosY), DataByIdx(Locations, id, backdropPosZ));
  3734. backdropNode->setPosition(position);
  3735. backdropNode->updateAbsolutePosition(true);
  3736. }
  3737.  
  3738. CCustomIngameSceneManager* smgr = static_cast<CCustomIngameSceneManager*>(GetDevice()->getSceneManager());
  3739. bool shadowAreaEnabled = DataByIdx(Locations, id, UseMandatoryShadowMapArea);
  3740. glitch::core::aabbox3df shadowAABB;
  3741. if (shadowAreaEnabled)
  3742. {
  3743. int valuesCount = DataByIdxSize(Locations, id, MandatoryShadowMapAABB);
  3744. GLF_ASSERTMSG(valuesCount == 6, "There should be six values for MandatoryShadowMapAABB in locations_.xml - minx ^ miny ^ minz ^ maxx ^ maxy ^ maxz");
  3745.  
  3746. float values[6];
  3747. for (int j = 0; j < valuesCount; ++j)
  3748. {
  3749. values[j] = DataByIdxN(Locations, id, MandatoryShadowMapAABB, j);
  3750. }
  3751. shadowAABB.MinEdge = glitch::core::vector3df(values[0], values[1], values[2]);
  3752. shadowAABB.MaxEdge = glitch::core::vector3df(values[3], values[4], values[5]);
  3753. }
  3754. smgr->SetMandatoryShadowMapArea(shadowAreaEnabled, shadowAABB);
  3755.  
  3756. Player::GetPlayer()->toggleFollowersVisibility(DataByIdx(Locations, id, allowFollowers));
  3757. if(Player::GetPlayer()->getTarget())
  3758. {
  3759. Player::GetPlayer()->delockTarget();
  3760. }
  3761.  
  3762. char apex[256] = "gamedata/leveldesign/";
  3763. strcat(apex, DataByIdx(Locations, id, apex));
  3764. if(apex)
  3765. {
  3766. if(currentLocationXML != "")
  3767. {
  3768. GameObjectManager::GetInstance()->UnloadXML(currentLocationXML.c_str());
  3769. }
  3770.  
  3771. GameObjectManager::GetInstance()->LoadFile(apex);
  3772. currentLocationXML = apex;
  3773. }
  3774.  
  3775. const char* entryPoint = DataByIdx(Locations, id, entryPoint);
  3776. if(strlen(entryPoint) != 0)
  3777. {
  3778. LevelObject* entry = GameObjectManager::GetInstance()->GetGameObjectByName(entryPoint);
  3779. ASSERT(entry);
  3780. if(entry)
  3781. {
  3782. Player::GetPlayer()->moveTo(entry);
  3783. }
  3784. }
  3785.  
  3786. const char* grapherScript = DataByIdx(Locations, id, grapher);
  3787. locationContext.Reset();
  3788. GrapherMgr()->FireManualEvent(grapherScript, &locationContext);
  3789.  
  3790. if (id >= 0 && id < DataCount(Locations))
  3791. {
  3792. LightsManager::GetInstance()->LoadLightZone(DataByIdx(Locations, id, lightZone));
  3793. }
  3794.  
  3795. if(currentLocation >= 0 && !DataByIdx(Locations, currentLocation, keepNavMeshLoaded))
  3796. {
  3797. NavMeshManager::GetInstance()->UnloadLocation(currentLocation);
  3798. }
  3799. NavMeshManager::GetInstance()->LoadLocation(id);
  3800.  
  3801. if (currentLocation >= 0)
  3802. {
  3803. int count = DataByIdxSize(Locations, currentLocation, StopSounds);
  3804. if (count > 0)
  3805. {
  3806. for (int i = 0; i < count; ++i)
  3807. {
  3808. std::string sound = (const char*)DataByIdxN(Locations, currentLocation, StopSounds, i);
  3809. SndMgr()->ExecByName(eSO_Stop, sound.c_str());
  3810. }
  3811.  
  3812. }
  3813. }
  3814.  
  3815. #ifdef IRRADIANCE
  3816. if(DataByIdx(PhonePerformanceProfiles, gPhonePerfId, useInteriorIrradiance))
  3817. {
  3818. const char* irradianceFile = DataByIdx(Locations, id, irradianceFile);
  3819.  
  3820. glitch::video::IVideoDriverPtr driver = GetVideoDriver();
  3821. CSceneManager* smgr = GetDevice()->getSceneManager();
  3822.  
  3823. #ifdef GLITCH_ENABLE_IRRADIANCE_SUPPORT
  3824. glitch::CIrradianceManager* irrManager = (glitch::CIrradianceManager*)(driver->getIrradianceManager().get());
  3825. #endif // GLITCH_ENABLE_IRRADIANCE_SUPPORT
  3826.  
  3827. #ifdef GLITCH_ENABLE_INDEXED_IRRADIANCE_SUPPORT
  3828. glitch::indexedIrradiance::CIndexedIrradianceManager* irrManager = (glitch::indexedIrradiance::CIndexedIrradianceManager*)(driver->getIrradianceManager().get());
  3829. #endif // GLITCH_ENABLE_INDEXED_IRRADIANCE_SUPPORT
  3830.  
  3831. irrManager->clear();
  3832.  
  3833. s_isIrradianceLoaded = false;
  3834.  
  3835. if(strlen(irradianceFile) > 0)
  3836. {
  3837. MLA_SET_CONTEXT("ignore");
  3838.  
  3839. //#pragma message("there probably is a way to avoid creating a memory map here")
  3840. //gIrradiance = GameDataFilesMgr::GetInstance()->getFile(GameDataFilesMgr::MMF_IRRADIANCE);
  3841. //if(gIrradiance)
  3842. {
  3843.  
  3844. //gIrradiance.createAndMap("irradiance.bin", 30*1024*1024);
  3845. //MemBlockScope a("irradiance.ird", *gIrradiance);
  3846. irrManager->load(irradianceFile);
  3847.  
  3848. //gIrradiance->flushAll();
  3849.  
  3850. //smgr->InitIrradianceSpheres();
  3851. #ifdef GLITCH_ENABLE_IRRADIANCE_SUPPORT
  3852. irrManager->setOneVolumesSampling(true);
  3853. irrManager->setMultipleVolumesSamplingAdditive(false);
  3854. irrManager->setMultipleVolumesSamplingInterpolate(false);
  3855. irrManager->setSamplingOutsideVolumes(true);
  3856. #endif // GLITCH_ENABLE_IRRADIANCE_SUPPORT
  3857.  
  3858. #ifdef GLITCH_ENABLE_INDEXED_IRRADIANCE_SUPPORT
  3859. irrManager->setSamplingAdditive(false);
  3860. irrManager->setSamplingInterpolate(true);
  3861. irrManager->setSamplingOutsideVolumes(true);
  3862. //irrManager->setMaxVolumeDistance(500.0f);
  3863. #endif // GLITCH_ENABLE_INDEXED_IRRADIANCE_SUPPORT
  3864.  
  3865. s_isIrradianceLoaded = true;
  3866.  
  3867. glitch::video::CGlobalMaterialParameterManager* globalParams = GetVideoDriver()->getGlobalMaterialParameters();
  3868.  
  3869. if(globalParams->getParameterID("IrrAmbientDiffuseMult"))
  3870. {
  3871. glitch::core::vector3df values(0.2f, 2.0f, 0.0f);
  3872. globalParams->setParameter(globalParams->getParameterID("IrrAmbientDiffuseMult"), values);
  3873. }
  3874. }
  3875. }
  3876. else
  3877. {
  3878. // do nothing if there is no irrandiance file or outside.
  3879. }
  3880.  
  3881. GS3DStuff::UpdateMaterialTechniques();
  3882. }
  3883. #endif
  3884.  
  3885. StoryManager::GetInstance()->UpdateMissionTriggers();
  3886.  
  3887. currentLocation = id;
  3888. streamingInit(); // Need to stream the new location.
  3889. }
  3890. }
  3891.  
  3892. int GS3DStuff::GetCurrentLocation()
  3893. {
  3894. return currentLocation;
  3895. }
  3896.  
  3897. void GS3DStuff::InitTreeShaders()
  3898. {
  3899. if(DataByIdx(PhonePerformanceProfiles, gPhonePerfId, removeTreeShaders))
  3900. return;
  3901.  
  3902. int activeTreeConfig = DataIdx(TreeShaderInfos, Normal);
  3903. GLF_ASSERTMSG(activeTreeConfig >= 0, "Did not find find a config TreeShaderInfos.Normal this is used by default by the game engine for the tree shader params init\n");
  3904. if(activeTreeConfig < 0) return;
  3905.  
  3906. g_WindParams[0] = DataByIdx(TreeShaderInfos, activeTreeConfig, strength);
  3907. g_WindParams[1] = DataByIdx(TreeShaderInfos, activeTreeConfig, branch);
  3908. g_WindParams[2] = DataByIdx(TreeShaderInfos, activeTreeConfig, detail);
  3909. g_WindParams[3] = DataByIdx(TreeShaderInfos, activeTreeConfig, freq);
  3910.  
  3911. glitch::core::vector3df dir = DataGetVec3(TreeShaderInfos, activeTreeConfig, direction);
  3912. g_WindParams2[0] = dir.getX();
  3913. g_WindParams2[1] = dir.getY();
  3914. g_WindParams2[2] = dir.getZ();
  3915. g_WindParams2[3] = DataByIdx(TreeShaderInfos, activeTreeConfig, factor);
  3916.  
  3917. UpdateTreeShaders();
  3918. }
  3919. void GS3DStuff::UpdateTreeShaders()
  3920. {
  3921. if(DataByIdx(PhonePerformanceProfiles, gPhonePerfId, removeTreeShaders))
  3922. return;
  3923.  
  3924. GetVideoDriver()->getGlobalMaterialParameters()->setParameter(
  3925. GetVideoDriver()->getGlobalMaterialParameters()->getParameterID("windParams"), g_WindParams);
  3926.  
  3927. glitch::core::vector3df dir = glitch::core::vector3df(g_WindParams2[0], g_WindParams2[1], g_WindParams2[2]);
  3928. dir.normalize();
  3929. GetVideoDriver()->getGlobalMaterialParameters()->setParameter(
  3930. GetVideoDriver()->getGlobalMaterialParameters()->getParameterID("windParams2"), glitch::core::vector4df(dir[0], dir[1], dir[2], g_WindParams2[3]));
  3931. }
  3932.  
  3933.  
  3934. void GS3DStuff::SetFakeFrameBuffer()
  3935. {
  3936. glitch::video::CGlobalMaterialParameterManager* globalParams = GetVideoDriver()->getGlobalMaterialParameters();
  3937.  
  3938. glitch::video::ITexturePtr tex = GetTextureManager()->getTexture("fakeFramebuffer.tga");
  3939.  
  3940. if (globalParams->getParameterID("FrameBuffer") != u16(-1))
  3941. {
  3942. globalParams->setParameter(globalParams->getParameterID("FrameBuffer"), tex);
  3943. }
  3944. }
  3945.  
  3946. void GS3DStuff::SetCubeMap(StdString cubemapName)
  3947. {
  3948. bool isDay = DayTime::Get().isDay();
  3949.  
  3950. SetCubeMap(cubemapName, isDay);
  3951. }
  3952.  
  3953. void GS3DStuff::SetCubeMap(StdString cubemapName, bool isDayEnvMap)
  3954. {
  3955. ProfilerScopeScene("GS3DStuff::SetCubeMap", NULL);
  3956.  
  3957. s_isDayEnvMap = isDayEnvMap;
  3958.  
  3959. if (cubemapName.empty())
  3960. {
  3961. return;
  3962. }
  3963.  
  3964. int startPosPostfixExt = cubemapName.find("_night_cube.tga");
  3965.  
  3966. if (startPosPostfixExt <= 0)
  3967. {
  3968. startPosPostfixExt = cubemapName.find("_cube.tga");
  3969. }
  3970.  
  3971. const StdString keyName = cubemapName.substr(0, startPosPostfixExt);
  3972. const StdString dayName = keyName + "_cube.tga";
  3973. const StdString nightName = keyName + "_night_cube.tga";
  3974. StdString finalName;
  3975.  
  3976. glitch::video::ITexturePtr tex;
  3977. do
  3978. {
  3979. if (!isDayEnvMap)
  3980. {
  3981. if (s_currentCubeMapName == nightName)
  3982. return;
  3983.  
  3984. tex = GetTextureManager()->getTexture(nightName.c_str());
  3985. if (tex)
  3986. {
  3987. finalName = nightName;
  3988. break;
  3989. }
  3990. }
  3991.  
  3992. if (s_currentCubeMapName == dayName)
  3993. return;
  3994.  
  3995. finalName = dayName;
  3996. tex = GetTextureManager()->getTexture(dayName.c_str());
  3997. } while (false);
  3998.  
  3999. if (!tex)
  4000. {
  4001. GLF_ASSERTMSG(false, "Could not load cube map: %s\n\n", dayName.c_str());
  4002. return;
  4003. }
  4004.  
  4005. s_currentCubeMapName = finalName;
  4006.  
  4007. glitch::video::CGlobalMaterialParameterManager* globalParams = GetVideoDriver()->getGlobalMaterialParameters();
  4008.  
  4009. if (globalParams->getParameterID("ReflectionSampler") != u16(-1))
  4010. {
  4011. globalParams->setParameter(globalParams->getParameterID("ReflectionSampler"), tex);
  4012. }
  4013.  
  4014. if (globalParams->getParameterID("CubeMapSampler") != u16(-1))
  4015. {
  4016. globalParams->setParameter(globalParams->getParameterID("CubeMapSampler"), tex);
  4017. }
  4018. }
  4019.  
  4020. void GS3DStuff::UpdateCubeMap()
  4021. {
  4022. bool isDay = DayTime::Get().isDay();
  4023.  
  4024. UpdateCubeMap(isDay);
  4025. }
  4026.  
  4027. void GS3DStuff::UpdateCubeMap(bool isDayEnvMap)
  4028. {
  4029. if (isDayEnvMap != s_isDayEnvMap)
  4030. {
  4031. SetCubeMap(s_currentCubeMapName, isDayEnvMap);
  4032. }
  4033. }
  4034.  
  4035. bool GS3DStuff::isInGame(bool fadeIsInGame)
  4036. {
  4037. return !(CinematicManager::GetInstance()->isInCinematicOrScriptedCutScene()
  4038. || isStreaming()
  4039. || (FadeManager::GetInstance()->IsRenderingFullyOpaque() && !fadeIsInGame)
  4040. || s_loadingDisplayed
  4041. || GS3DStuff::isStreaming());
  4042. }
  4043.  
  4044.  
  4045. // static function
  4046. glitch::video::E_ORIENTATION GS3DStuff::getDefaultOrientation()
  4047. {
  4048. return glitch::video::EO_270;
  4049. }
  4050.  
  4051. void GS3DStuff::showLoading()
  4052. {
  4053. if(!StateMachine::s_isInMainMenu)
  4054. {
  4055. //QUEUE_DIALOG_BY_CONTENT_ID(DefaultDialog, Kst(StrID, INIT_LOADING));
  4056. s_loadingDisplayed = true;
  4057. }
  4058. }
  4059.  
  4060. void GS3DStuff::hideLoading()
  4061. {
  4062. if(!StateMachine::s_isInMainMenu)
  4063. {
  4064. DialogMgr()->CloseDialog(Cst(DialogType, Default));
  4065. s_loadingDisplayed = false;
  4066. }
  4067. }
  4068.  
  4069. //// static function
  4070. //// Transforms the driver's orientation (rotation angle) into the corresponding glf orientation
  4071. //glf::Orientation GS3DStuff::GetCurrentGlfOrientation()
  4072. //{
  4073. // switch (GetCurrentOrientation())
  4074. // {
  4075. // case glitch::video::EO_90 :
  4076. // return glf::ORIENTATION_LANDSCAPE_LEFT;
  4077. //
  4078. // case glitch::video::EO_270 :
  4079. // return glf::ORIENTATION_LANDSCAPE_RIGHT;
  4080. //
  4081. // default:
  4082. // ASSERT(false); // invalid orientation
  4083. // return glf::ORIENTATION_UNDEFINED;
  4084. // }
  4085. //}
  4086.  
  4087. // this is a static function
  4088. glitch::video::E_ORIENTATION GS3DStuff::GetCurrentOrientation()
  4089. {
  4090. #ifdef WIN32
  4091. // on pc, return EO_270 because DrivingControlHandler & FlyingControlHandler expect either EO_270 or EO_90!
  4092. return glitch::video::EO_270;
  4093. #else
  4094. return s_orientation;
  4095. #endif // _WIN32
  4096. }
  4097.  
  4098. void GS3DStuff::DayStateChanged(bool hasTransition /*= true*/)
  4099. {
  4100. char toState[16] = { 0 };
  4101. bool isDay = DayTime::Get().isDay();
  4102. if (isDay)
  4103. {
  4104. if(DayTime::Get().isState(DayTime::Day) || !hasTransition)
  4105. {
  4106. strcpy(toState, flash_constants::events::GameEvent::TIME_DAY);
  4107. }
  4108. }
  4109. else
  4110. {
  4111. if(DayTime::Get().isState(DayTime::Night) || !hasTransition)
  4112. {
  4113. strcpy(toState, flash_constants::events::GameEvent::TIME_NIGHT);
  4114. }
  4115. }
  4116.  
  4117. if(strlen(toState) > 0)
  4118. {
  4119. menu::menuEventMgr::MenuEventManager::Members members;
  4120. gameswf::ASMember toMember;
  4121. toMember.m_name = "toTime";
  4122. toMember.m_value = toState;
  4123. members.push_back(&toMember);
  4124.  
  4125. gameswf::ASMember fromMember;
  4126. if(hasTransition)
  4127. {
  4128. fromMember.m_name = "fromTime";
  4129. fromMember.m_value = isDay ? flash_constants::events::GameEvent::TIME_NIGHT : flash_constants::events::GameEvent::TIME_DAY;
  4130. members.push_back(&fromMember);
  4131. }
  4132.  
  4133. GetMenuEventMgr()->DispatchEvent(SwfManager::SWF_HUD, flash_constants::events::GameEvent::TIME_CHANGE, members);
  4134. }
  4135. }
  4136.  
  4137. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4138. //
  4139. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4140. void GS3DStuff::UpdateInvisibles()
  4141. {
  4142. ProfilerScopeGameplay("UpdateInvisibles", NULL);
  4143.  
  4144. // !! WARNING !! MC_WRN_INVISIBLE
  4145. // This approach (spreading the update on multiple frames) is not 100% safe because
  4146. // we are using a ->next operator. If the same items are always added and removed every frame, and
  4147. // the item where the iteration stop is one of those, it will always stop there. And since
  4148. // in the next frame the object is not valid anymore, it will restart from scratch at every frame.
  4149. // This will cause any following item on the list to be never updated.
  4150. // As a solution, we can start from a random one instead of the first one, but how will
  4151. // that impact on perfomances? There is no random access with the ->next operator.
  4152. // However this specific condition is probably very unlikely.
  4153.  
  4154.  
  4155. // Last invisible object updated
  4156. static LevelObjectHandle s_lastInvisibleLOUpdate;
  4157. // Size of the block of the invisible objects list that is updated at each frame
  4158. static size_t s_invisibleListBlockSize;
  4159.  
  4160.  
  4161. // m_lastInvisibleLOUpdate is where I stopped at last frame
  4162. const bool isStillValid = (s_lastInvisibleLOUpdate.get_no_assert() != 0);
  4163. LevelObject* lo;
  4164.  
  4165. if(!isStillValid) // item changed or end of list reached
  4166. {
  4167. s_invisibleListBlockSize = ( gom->GetObjectList(Kst(ObjectFrameActions, JustUpdate)).Size() / (float) FRAMES_FOR_COMPLETE_INVISIBLE_LIST_UPDATE ) +1;
  4168. lo = gom->GetFirstLo(Kst(ObjectFrameActions, JustUpdate));
  4169. }
  4170. else
  4171. {
  4172. // continue from here
  4173. lo = s_lastInvisibleLOUpdate.get();
  4174. }
  4175.  
  4176. bool checkForDespawnThisFrame = ((gCheckForDespawnFrame + 2) & 3) == 3;
  4177.  
  4178. // now iterate an appropriate number of times
  4179. for(int i = s_invisibleListBlockSize; i > 0 && lo; --i)
  4180. {
  4181. if(checkForDespawnThisFrame)
  4182. {
  4183. // check for despawns and remove them
  4184. LevelObject* despawned = checkForDespawn(lo);
  4185. if(!despawned)
  4186. {
  4187. break;
  4188. }
  4189. if(despawned != lo)
  4190. {
  4191. lo = despawned;
  4192. continue;
  4193. }
  4194. }
  4195.  
  4196. LevelObject* next = gom->GetNextLo(lo);
  4197. lo->Update(s_dt);
  4198. lo = next;
  4199. }
  4200. s_lastInvisibleLOUpdate = lo;
  4201. }
  4202.  
  4203. void UpdateGameObjectsPerfCounters()
  4204. {
  4205. #if _WIN32 && GLF_ENABLE_DEBUGGER
  4206. GameObjectManager* gom = GameObjectManager::GetInstance();
  4207. static const char* modes[4] = { "updateAndDraw", "justUpdate", "deleted", "paused" };
  4208. static const char* types[4] = { "objectInterface", "levelObject", "transformation", "soundEmitter" };
  4209.  
  4210. for(int i = 0; i < 4; ++i)
  4211. {
  4212. GameObjectInterface* it1 = gom->GetFirst<GameObjectInterface>(i);
  4213. int counts[4] = {0};
  4214. for(GameObjectInterface* goi = gom->GetFirst<GameObjectInterface>(i); goi; goi = gom->GetNext<GameObjectInterface>(goi)) ++counts[0];
  4215. for(LevelObject* lo = gom->GetFirstLo(i); lo; lo = lo->GetNext()) ++counts[1];
  4216. for(Transformation* transf = gom->GetFirst<Transformation>(i); transf; transf = gom->GetNext<Transformation>(transf)) ++counts[2];
  4217. for(SoundEmitter* emm = gom->GetFirst<SoundEmitter>(i); emm; emm = gom->GetNext<SoundEmitter>(emm)) ++counts[3];
  4218.  
  4219. for(int j= 0; j < asizeof(counts); ++j) {
  4220. std::string perfName = std::string(modes[i]) + "." + types[j];
  4221. glf::debugger::PerfCounters::UpdateValue(perfName.c_str(), counts[j]);
  4222. perfName = std::string(types[j]) + "." + modes[i];
  4223. glf::debugger::PerfCounters::UpdateValue(perfName.c_str(), counts[j]);
  4224. }
  4225. }
  4226. #endif
  4227. }
  4228.  
  4229. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4230. //
  4231. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4232. void GS3DStuff::UpdateVisibles()
  4233. {
  4234. ProfilerScopeGameplay("UpdateVisibles", NULL);
  4235.  
  4236. TriggerZone::SetCurrentTriggerZone(0);
  4237.  
  4238. for (int i = 0; i < s_vehicles.size(); ++i)
  4239. {
  4240. if (s_vehicles[i])
  4241. {
  4242. s_vehicles[i]->SetWasAttackedThisFrame(false);
  4243. }
  4244. }
  4245.  
  4246. for (int i = 0; i < s_npcs.size(); ++i)
  4247. {
  4248. if (s_npcs[i])
  4249. {
  4250. s_npcs[i]->SetWasAttackedThisFrame(false);
  4251. }
  4252. }
  4253.  
  4254. /////////////////////////////////////////////
  4255. // Reset stuff
  4256. Player::GetPlayer()->ResetLastDamageFilter();
  4257.  
  4258. s_vehicles.clear();
  4259. s_npcs.clear();
  4260. s_players.clear();
  4261. //non_vehicles.clear();
  4262.  
  4263. UpdateGameObjectsPerfCounters();
  4264.  
  4265. if(!CinematicManager::GetInstance()->isInBdaeCinematic()) // Prevent the player from being killed when in a cinematic.
  4266. {
  4267. LevelObject* lo = gom->GetFirstLo(Kst(ObjectFrameActions, UpdateAndDraw));
  4268. size_t num = 0;
  4269. bool checkForDespawnThisFrame = (gCheckForDespawnFrame++ & 3) == 3;
  4270. GameObjectManager::DebugStats& dbgStats = GameObjectManager::GetInstance()->GetDebugStats();
  4271. dbgStats.Reset();
  4272.  
  4273. while(lo)
  4274. {
  4275. dbgStats.numObjects++;
  4276.  
  4277. if(checkForDespawnThisFrame)
  4278. {
  4279. // check for despawns and remove them
  4280. LevelObject* despawned = checkForDespawn(lo);
  4281. if(!despawned)
  4282. {
  4283. break;
  4284. }
  4285. if(despawned != lo)
  4286. {
  4287. lo = despawned;
  4288. continue;
  4289. }
  4290. }
  4291.  
  4292. LevelObject* next = gom->GetNextLo(lo);
  4293.  
  4294. #if GANGSTAR_RETAIL_BUILD == 0
  4295. if(GameObjectManager::isVehicle(lo))
  4296. {
  4297. dbgStats.numVehicles++;
  4298. }
  4299. else if(GameObjectManager::isCharacter(lo))
  4300. {
  4301. dbgStats.numCharacters++;
  4302. }
  4303. #endif
  4304.  
  4305. lo->TestForUpdate();
  4306.  
  4307. bool isTriggerZone = glf::DynamicCast<TriggerZone>(lo) != 0;
  4308.  
  4309. if(lo->IsUpdating() && (lo->IsVisible() || (GameObjectManager::isCharacter(lo) || GameObjectManager::isProjectile(lo) || isTriggerZone)))
  4310. {
  4311. SCOPE_TRACE("LOUpdate", "Updating %s...\n", lo->GetName());
  4312. dbgStats.numVisibleObjects++;
  4313. if(GameObjectManager::isVehicle(lo))
  4314. {
  4315. dbgStats.numVisibleVehicles++;
  4316. s_vehicles.push_back(static_cast<Vehicle*>(lo));
  4317. }
  4318. else if(GameObjectManager::isCharacter(lo))
  4319. {
  4320. dbgStats.numVisibleCharacters++;
  4321. if(!static_cast<Character*>(lo)->isPlayer())
  4322. {
  4323. s_npcs.push_back(static_cast<NPC*>(lo));
  4324. }
  4325. else
  4326. {
  4327. s_players.push_back(static_cast<Player*>(lo));
  4328. }
  4329. }
  4330. else
  4331. {
  4332. //ProfilerScope("Update");
  4333. lo->Update(s_dt);
  4334. }
  4335. }
  4336. else
  4337. {
  4338. SCOPE_TRACE("LOUpdate", "Skipping Updating %s...\n", lo->GetName());
  4339. }
  4340.  
  4341. lo = next;//gom->GetNextLo(lo);
  4342. ++num;
  4343. }
  4344. #if GLF_ENABLE_DEBUGGER
  4345. glf::debugger::PerfCounters::UpdateValue("LevelObject.UpdateAndDraw", num);
  4346. #endif
  4347. }
  4348.  
  4349. // Spawned fix. Remove spawned actors silently disabled from paused list if they don't have a owner.
  4350.  
  4351. //size_t num = 0;
  4352. //LevelObject *lo = gom->GetFirstLo(Kst(ObjectFrameActions, Paused));
  4353. //while(lo)
  4354. //{
  4355. // /*if (TEST_FLAG(lo->m_flags, Kst(GameObjectFlag, SilentDisable)))
  4356. // {
  4357. // LevelObject* despawned = checkForDespawn(lo);
  4358. // if(!despawned)
  4359. // {
  4360. // break;
  4361. // }
  4362. // if (despawned != lo)
  4363. // {
  4364. // //SCOPE_TRACE("DBG", "DESPAWNED %s, %s | LO %s, %s\n", despawned->GetName(), gom->GetAlias(despawned), lo->GetName(), gom->GetAlias(lo));
  4365. // lo = despawned;
  4366. // continue;
  4367. // }
  4368. // }*/
  4369.  
  4370. // lo = gom->GetNextLo(lo);
  4371. //}
  4372.  
  4373. #if GLF_ENABLE_DEBUGGER
  4374. //glf::debugger::PerfCounters::UpdateValue("LevelObject.Paused", num);
  4375. #endif
  4376.  
  4377. }
  4378.  
  4379. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4380. //
  4381. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4382. void GS3DStuff::UpdateDayTime()
  4383. {
  4384. ProfilerScopeGameplay("UpdateDayTime", NULL);
  4385.  
  4386. DayTime& dayTime = DayTime::Get();
  4387. if (dayTime.needsUpdate() || !StoryManager::GetInstance()->isInMission()) // Lock Daytime during mission.
  4388. {
  4389. dayTime.update(s_dt);
  4390.  
  4391. if(dayTime.stateChangedThisFrame())
  4392. {
  4393. DayStateChanged();
  4394. }
  4395. }
  4396. else
  4397. {
  4398. dayTime.UpdateInfo();
  4399. }
  4400. }
  4401.  
  4402.  
  4403. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4404. //
  4405. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4406. void GS3DStuff::UpdateBehaviors()
  4407. {
  4408. ProfilerScopeGameplay("UpdateBehaviors", NULL);
  4409.  
  4410. if(BehaviorManager::GetInstance()->needReset())
  4411. {
  4412. BehaviorManager::GetInstance()->reset();
  4413. for(int i = 0; i < s_npcs.size(); i++)
  4414. {
  4415. if (s_npcs[i])
  4416. {
  4417. s_npcs[i]->resetBehavior(BehaviorManager::CHARACTER);
  4418. }
  4419. }
  4420. for(int i = 0; i < s_players.size(); i++)
  4421. {
  4422. if (s_npcs[i])
  4423. {
  4424. s_players[i]->resetBehavior(BehaviorManager::PLAYER);
  4425. }
  4426. }
  4427. Player::GetPlayer()->resetBehavior(BehaviorManager::PLAYER);
  4428. }
  4429. }
  4430.  
  4431. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4432. //
  4433. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4434. void GS3DStuff::UpdateCharacters()
  4435. {
  4436. // [MB] Don't update characters while fading
  4437. if(/*FadeManager::GetInstance()->IsFullyIdle() &&*/ !isStreaming() && !g_Loading)
  4438. {
  4439. ProfilerScopeGameplay("UpdateCharacters", NULL);
  4440. {
  4441. ProfilerScopeGameplay("UpdateNpc", NULL);
  4442. if(s_npcs.size() > 0)
  4443. {
  4444. int forceUpdateNPCIdx = -1;
  4445. for(int i=0; i<s_npcs.size(); i++)
  4446. {
  4447. if(s_npcs[i] && s_npcs[i]->m_forceUpdate)
  4448. {
  4449. s_npcs[i]->m_forceUpdate = false;
  4450. forceUpdateNPCIdx = i;
  4451. break;
  4452. }
  4453. }
  4454.  
  4455. if(forceUpdateNPCIdx < 0)
  4456. {
  4457. s_roundRobinNPCIdx = (s_roundRobinNPCIdx + 1) % s_npcs.size();
  4458. }
  4459.  
  4460. int updateNPCIdx = (forceUpdateNPCIdx < 0 ? s_roundRobinNPCIdx : forceUpdateNPCIdx);
  4461.  
  4462. SCOPE_TRACE("RoundRobin", "*********************************************************************\n");
  4463. SCOPE_TRACE("RoundRobin", "There is %d npcs to update s_roundRobinNPCIdx=%d ... \n", s_npcs.size(), s_roundRobinNPCIdx);
  4464. SCOPE_TRACE("RoundRobin", "*********************************************************************\n");
  4465. for(int i=0; i<s_npcs.size(); i++)
  4466. {
  4467. //This is done here because for now it's a simple "one per frame" round robin for all "skippable" expensive npc update parts.
  4468. //If this becomes more complex, please wrap it correctly.
  4469. //see LevelObject UpdateOptim enum in Level Object, there is a method SetUpdateOptim(int updateOptim) to set only specific update to be skipped...
  4470. //for now : we simply update everything for a single NPC that have the round robin token per frame, so just clear all the flags accordingly.
  4471. bool hasRoundRobinToken = (i == updateNPCIdx);
  4472.  
  4473. if (s_npcs[i])
  4474. {
  4475. // flinch NPCS os being hijacked can't delay their animation updates made by the grapher
  4476. hasRoundRobinToken |= s_npcs[i]->isFlinching() || s_npcs[i]->isInMeleeStrike() || s_npcs[i]->testFlag(IS_HIJACKED);
  4477. hasRoundRobinToken |= Player::GetPlayer()->getTarget() == s_npcs[i];
  4478.  
  4479. s_npcs[i]->SetAllUpdateOptim(hasRoundRobinToken == false);
  4480.  
  4481. SCOPE_TRACE("RoundRobin", "Updating %d==>%s\n", i, s_npcs[i]->GetName());
  4482. s_npcs[i]->Update(s_dt);
  4483. }
  4484. }
  4485. }
  4486.  
  4487.  
  4488. clearWorldEventFlags();
  4489. }
  4490.  
  4491. {
  4492. if(!StateMachine::s_isInMainMenu
  4493. #if _WIN32
  4494. && !gLodProfiling
  4495. #endif
  4496. )
  4497. {
  4498. ProfilerScopeGameplay("UpdatePlayer", NULL);
  4499. Application::GetInstance()->GetControlManager()->update();
  4500. Player::GetPlayer()->Update(s_dt);
  4501. Player::GetPlayer()->updateSunOcclusion();
  4502. }
  4503. }
  4504. }
  4505. }
  4506.  
  4507.  
  4508. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4509. //
  4510. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4511. void GS3DStuff::UpdateVehicles()
  4512. {
  4513. // [MB] Don't update characters while fading
  4514. if(/*FadeManager::GetInstance()->IsFullyIdle() &&*/ !isStreaming() && !g_Loading)
  4515. {
  4516. ProfilerScopeGameplay("UpdateVehicles", NULL);
  4517. for(int i=0; i<s_vehicles.size(); i++)
  4518. {
  4519. s_vehicles[i]->Update(s_dt);
  4520. }
  4521. }
  4522. }
  4523.  
  4524.  
  4525.  
  4526. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4527. //
  4528. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4529. void GS3DStuff::UpdatePhysics()
  4530. {
  4531. int updates = 0;
  4532.  
  4533. gNumPhysicIteration = 0;
  4534.  
  4535. {
  4536. ProfilerScopePhysics("UpdateStaticCollisions", NULL);
  4537.  
  4538. #ifndef PHYSICS_USING_ASYNCHRONOUS_UPDATE
  4539. PhysicsWorld::GetInstance()->Update(s_dt * 0.001f);
  4540. #endif
  4541. }
  4542. }
  4543.  
  4544.  
  4545.  
  4546. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4547. //
  4548. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4549. void GS3DStuff::UpdateCamera()
  4550. {
  4551. if(gTogglePhysic && FadeManager::GetInstance()->IsFullyIdle() && !isStreaming() && !g_Loading)
  4552. {
  4553. //if(Player::GetPlayer()->isInAVehicle())
  4554. {
  4555. ProfilerScopeScene("UpdateCamera", NULL);
  4556.  
  4557. gTimeAccumulator += (Application::GetInstance()->getSmoothDt() * 0.001f);
  4558. int numberOfConstantFrames = int(gTimeAccumulator / PHYSIC_UPDATE_RATE);
  4559. gTimeAccumulator -= PHYSIC_UPDATE_RATE * numberOfConstantFrames;
  4560.  
  4561. if(numberOfConstantFrames > 240)
  4562. {
  4563. // Maximum X frames
  4564. // Time elapsed is too high, reset and return
  4565. gTimeAccumulator = 0.0f;
  4566. numberOfConstantFrames = 240;
  4567. }
  4568. else if(numberOfConstantFrames <= 0)
  4569. {
  4570. numberOfConstantFrames = 1;
  4571. }
  4572.  
  4573.  
  4574. float cameraTime = Application::GetInstance()->getSmoothDt() * 0.001f / (float)numberOfConstantFrames;
  4575.  
  4576. while(--numberOfConstantFrames >= 0)
  4577. {
  4578. // update the camera in time with the physics updates so we don't get positional jumps
  4579. ProfilerScopeScene("cam", NULL);
  4580. //CameraManager::GetInstance()->update(PHYSIC_UPDATE_RATE);//*1000);
  4581.  
  4582. // Only set listener position once per frame to avoid unnecessary vox calls
  4583. CameraManager::GetInstance()->setListener(numberOfConstantFrames == 0);
  4584.  
  4585. CameraManager::GetInstance()->update(cameraTime);
  4586. }
  4587. }
  4588. }
  4589. else
  4590. {
  4591. CameraManager::GetInstance()->update(Application::GetInstance()->getSmoothDt() * 0.001f);
  4592. }
  4593. }
  4594.  
  4595.  
  4596.  
  4597. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4598. //
  4599. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4600. void GS3DStuff::UpdateVehicleNodeAndProximity()
  4601. {
  4602. ProfilerScopeGameplay("UpdateVehicleNodeAndProximity", NULL);
  4603.  
  4604. for (int i = 0; i < s_vehicles.size(); i++)
  4605. {
  4606. s_vehicles[i]->updateGlitchNode();
  4607. }
  4608.  
  4609. if(!Player::GetPlayer()->isDead())
  4610. {
  4611. checkVehicleProximity(Player::GetPlayer());
  4612. }
  4613. }
  4614.  
  4615. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4616. //
  4617. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4618. void GS3DStuff::UpdateScripts()
  4619. {
  4620. ProfilerScopeGameplay("scripts", NULL);
  4621.  
  4622. StoryManager::GetInstance()->Update(s_dt);
  4623. CinematicManager::GetInstance()->update(s_dt);
  4624. //ScriptManager::GetInstance()->update(s_dt);
  4625. }
  4626.  
  4627. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4628. //
  4629. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4630. void GS3DStuff::UpdateWantedAndTrail()
  4631. {
  4632. ProfilerScopeScene("wanted + trail", NULL);
  4633. //if(!Player::GetPlayer()->isInAVehicle())
  4634. //{ CameraManager::GetInstance()->update(static_cast<float>(s_dt)*0.001f); }
  4635. WantedMgr()->update(s_dt);
  4636.  
  4637. if(s_TrailMgr)
  4638. {
  4639. s_TrailMgr->Update();
  4640. }
  4641.  
  4642. #ifdef USE_DECAL_MANAGER
  4643. if(s_DecalManager)
  4644. {
  4645. s_DecalManager->Update(s_dt);
  4646. }
  4647. #endif
  4648. }
  4649.  
  4650. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4651. //
  4652. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4653. void GS3DStuff::UpdateAttachDSP()
  4654. {
  4655. ProfilerScopeSounds("attach dsp", NULL);
  4656. if(DataByIdx(PhonePerformanceProfiles, gPhonePerfId, snd_reverb) || GET_DEBUG_SWITCH("EnableReverb"))
  4657. {
  4658. SndMgr()->AttachDSP();
  4659. }
  4660. else
  4661. {
  4662. SndMgr()->DetachDSP();
  4663. }
  4664. }
  4665.  
  4666. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4667. //
  4668. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4669. void GS3DStuff::UpdatePurgeGameObjectAndTriggerZone()
  4670. {
  4671. {
  4672. ProfilerScopeScene("GameObjectManager::purge", NULL);
  4673. GameObjectManager::GetInstance()->purge();
  4674. }
  4675.  
  4676. TriggerZone* zone = TriggerZone::GetCurrentTriggerZone();
  4677. if ( zone != s_lastTriggerZone/* || (zone && zone->UseTriggerButton() && !zone->IsTriggerButtonVisible()) */)
  4678. {
  4679. if(zone)
  4680. {
  4681. zone->SetAsCurrentTriggerButton();
  4682. }
  4683.  
  4684. s_lastTriggerZone = zone;
  4685. }
  4686. }
  4687.  
  4688. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4689. //
  4690. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4691. void GS3DStuff::UpdateSunOcclusion()
  4692. {
  4693. #ifdef SUN_OCCLUSION
  4694.  
  4695. ProfilerScopeGameplay("UpdateSunOcclusion", NULL);
  4696.  
  4697. if(!CinematicManager::GetInstance()->isInBdaeCinematic())
  4698. {
  4699. // !! WARNING !! MC_WRN_INVISIBLE
  4700. // This approach (spreading the update on multiple frames) is not 100% safe because
  4701. // we are using a ->next operator. If the same items are always added and removed every frame, and
  4702. // the item where the iteration stop is one of those, it will always stop there. And since
  4703. // in the next frame the object is not valid anymore, it will restart from scratch at every frame.
  4704. // This will cause any following item on the list to be never updated.
  4705. // As a solution, we can start from a random one instead of the first one, but how will
  4706. // that impact on perfomances? There is no random access with the ->next operator.
  4707. // However this specific condition is probably very unlikely.
  4708.  
  4709.  
  4710. // Last invisible object updated
  4711. static LevelObjectHandle s_lastSunOcclusionUpdate;
  4712. // Size of the block of the invisible objects list that is updated at each frame
  4713. static size_t s_lastSunOccclusionListBlockSize;
  4714.  
  4715.  
  4716. // s_lastSunOcclusionUpdate is where I stopped at last frame
  4717. const bool isStillValid = (s_lastSunOcclusionUpdate.get_no_assert() != 0);
  4718. LevelObject* lo;
  4719.  
  4720. if(!isStillValid) // item changed or end of list reached
  4721. {
  4722. s_lastSunOccclusionListBlockSize = FRAMES_FOR_COMPLETE_SUN_OCCLUSION_UPDATE ?
  4723. ( gom->GetObjectList(Kst(ObjectFrameActions, UpdateAndDraw)).Size() / (float) FRAMES_FOR_COMPLETE_SUN_OCCLUSION_UPDATE ) +1 // spread over frames
  4724. : 0; // only one object
  4725. lo = gom->GetFirstLo(Kst(ObjectFrameActions, JustUpdate));
  4726. }
  4727. else
  4728. {
  4729. // continue from here
  4730. lo = s_lastSunOcclusionUpdate.get();
  4731. }
  4732.  
  4733. // now iterate an appropriate number of times
  4734. int i = s_lastSunOccclusionListBlockSize;
  4735. while(i > 0 && lo)
  4736. {
  4737. LevelObject* next = gom->GetNextLo(lo);
  4738. if(lo->IsVisible() && lo != Player::GetPlayer()) // player is updated every frame anyway
  4739. {
  4740. lo->updateSunOcclusion();
  4741. --i;
  4742. }
  4743. lo = next;
  4744. }
  4745.  
  4746. s_lastSunOcclusionUpdate = lo;
  4747. }
  4748. #endif
  4749. }
  4750.  
  4751. bool GS3DStuff::OmitOcclusionUpdate(int index)
  4752. {
  4753. return s_sunOcclusionFrameCounter != (index % s_sunOcclusionFrameCycle);
  4754. }
  4755.  
  4756. void GS3DStuff::PreloadEffects(glitch::video::IVideoDriver* driver)
  4757. {
  4758. MLA_SET_CONTEXT("GS3DStuff::PreloadEffects");
  4759. for (int i = 0; i < DataCount(PreloadEffectsList); ++i)
  4760. {
  4761. const char* fileName = DataByIdx(PreloadEffectsList, i, BdaeFile);
  4762. const char* effectName = DataByIdx(PreloadEffectsList, i, Name);
  4763. glitch::collada::CColladaDatabase database(fileName);
  4764. glitch::video::CMaterialRendererPtr materialRenderer = database.constructEffect(driver, effectName, 0);
  4765. }
  4766. }
  4767.  
  4768. float GS3DStuff::GetPercentBasedOnLoadingStep()
  4769. {
  4770. return 100 * (float(s_load_step + 3) / float(LoadingSteps::End));
  4771. }
  4772.  
  4773. void GS3DStuff::UpdateLoadingProgress(float percents, bool isLoadingBarVisible)
  4774. {
  4775. gameswf::ASValue args[2];
  4776. args[0] = (percents > 100.f || percents < 0.f) ? 100.f : percents;
  4777. args[1] = isLoadingBarVisible;
  4778.  
  4779. SwfManager::MenuInfo* topStack = SwfManager::GetInstance()->GetTopMenuInStack();
  4780. if (topStack)
  4781. {
  4782. topStack->m_renderFX->findClass("menus.main", "Splash").invokeStaticMethod("UpdateLoadingProgress", args, 2);
  4783. }
  4784. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement