levelDownload.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. //-----------------------------------------------------------------------------
  23. // Mission Loading
  24. // The client portion of the client/server mission loading process
  25. //-----------------------------------------------------------------------------
  26. //--------------------------------------------------------------------------
  27. // Loading Phases:
  28. // Phase 1: Transmit Datablocks
  29. // Transmit targets
  30. // Phase 2: Transmit Ghost Objects
  31. // Phase 3: Start Game
  32. //
  33. // The server invokes the client MissionStartPhase[1-3] function to request
  34. // permission to start each phase. When a client is ready for a phase,
  35. // it responds with MissionStartPhase[1-3]Ack.
  36. //----------------------------------------------------------------------------
  37. // Phase 1
  38. //----------------------------------------------------------------------------
  39. function clientCmdMissionStartPhase1(%seq, %missionName)
  40. {
  41. // These need to come after the cls.
  42. echo ("*** New Mission: " @ %missionName);
  43. echo ("*** Phase 1: Download Datablocks & Targets");
  44. //Prep the postFX stuff
  45. // Load the post effect presets for this mission.
  46. %path = filePath( %missionName ) @ "/" @ fileBase( %missionName ) @ $PostFXManager::fileExtension;
  47. if ( isScriptFile( %path ) )
  48. {
  49. postFXManager::loadPresetHandler( %path );
  50. }
  51. else
  52. {
  53. PostFXManager::settingsApplyDefaultPreset();
  54. }
  55. onMissionDownloadPhase("LOADING DATABLOCKS");
  56. commandToServer('MissionStartPhase1Ack', %seq);
  57. }
  58. function onDataBlockObjectReceived(%index, %total)
  59. {
  60. onMissionDownloadProgress(%index / %total);
  61. }
  62. //----------------------------------------------------------------------------
  63. // Phase 2
  64. //----------------------------------------------------------------------------
  65. function clientCmdMissionStartPhase2(%seq,%missionName)
  66. {
  67. onPhaseComplete();
  68. echo ("*** Phase 2: Download Ghost Objects");
  69. onMissionDownloadPhase("LOADING OBJECTS");
  70. commandToServer('MissionStartPhase2Ack', %seq);
  71. }
  72. function onGhostAlwaysStarted(%ghostCount)
  73. {
  74. $ghostCount = %ghostCount;
  75. $ghostsRecvd = 0;
  76. }
  77. function onGhostAlwaysObjectReceived()
  78. {
  79. $ghostsRecvd++;
  80. onMissionDownloadProgress($ghostsRecvd / $ghostCount);
  81. }
  82. //----------------------------------------------------------------------------
  83. // Phase 3
  84. //----------------------------------------------------------------------------
  85. function clientCmdMissionStartPhase3(%seq,%missionName)
  86. {
  87. onPhaseComplete();
  88. StartClientReplication();
  89. StartFoliageReplication();
  90. // Load the static mission decals.
  91. if(isFile(%missionName @ ".decals"))
  92. decalManagerLoad( %missionName @ ".decals" );
  93. echo ("*** Phase 3: Mission Lighting");
  94. $MSeq = %seq;
  95. $Client::MissionFile = %missionName;
  96. // Need to light the mission before we are ready.
  97. // The sceneLightingComplete function will complete the handshake
  98. // once the scene lighting is done.
  99. if (lightScene("sceneLightingComplete", ""))
  100. {
  101. echo("Lighting mission....");
  102. schedule(1, 0, "updateLightingProgress");
  103. onMissionDownloadPhase("LIGHTING MISSION");
  104. $lightingMission = true;
  105. }
  106. }
  107. function updateLightingProgress()
  108. {
  109. onMissionDownloadProgress($SceneLighting::lightingProgress);
  110. if ($lightingMission)
  111. $lightingProgressThread = schedule(1, 0, "updateLightingProgress");
  112. }
  113. function sceneLightingComplete()
  114. {
  115. echo("Mission lighting done");
  116. $lightingMission = false;
  117. onPhaseComplete("STARTING MISSION");
  118. // The is also the end of the mission load cycle.
  119. commandToServer('MissionStartPhase3Ack', $MSeq);
  120. }
  121. //----------------------------------------------------------------------------
  122. // Helper functions
  123. //----------------------------------------------------------------------------
  124. function connect(%server)
  125. {
  126. %conn = new GameConnection(ServerConnection);
  127. RootGroup.add(ServerConnection);
  128. %conn.setConnectArgs($pref::Player::Name);
  129. %conn.setJoinPassword($Client::Password);
  130. %conn.connect(%server);
  131. }
  132. function onMissionDownloadPhase(%phase)
  133. {
  134. if ( !isObject( LoadingProgress ) )
  135. return;
  136. LoadingProgress.setValue(0);
  137. LoadingProgressTxt.setValue(%phase);
  138. Canvas.repaint();
  139. }
  140. function onMissionDownloadProgress(%progress)
  141. {
  142. if ( !isObject( LoadingProgress ) )
  143. return;
  144. LoadingProgress.setValue(%progress);
  145. Canvas.repaint(33);
  146. }
  147. function onPhaseComplete(%text)
  148. {
  149. if ( !isObject( LoadingProgress ) )
  150. return;
  151. if(%text !$= "")
  152. LoadingProgressTxt.setValue(%text);
  153. LoadingProgress.setValue( 1 );
  154. Canvas.repaint();
  155. }