diff --git a/Engine/source/T3D/fx/lightning.cpp b/Engine/source/T3D/fx/lightning.cpp index 9be145075..c951f022e 100644 --- a/Engine/source/T3D/fx/lightning.cpp +++ b/Engine/source/T3D/fx/lightning.cpp @@ -240,9 +240,15 @@ LightningData::LightningData() { strikeSound = NULL; - dMemset( strikeTextureNames, 0, sizeof( strikeTextureNames ) ); - dMemset( strikeTextures, 0, sizeof( strikeTextures ) ); - dMemset( thunderSounds, 0, sizeof( thunderSounds ) ); + for (S32 i = 0; i < MaxThunders; i++) + thunderSounds[i] = NULL; + + for (S32 i = 0; i < MaxTextures; i++) + { + strikeTextureNames[i] = NULL; + strikeTextures[i] = NULL; + } + mNumStrikeTextures = 0; } @@ -282,9 +288,10 @@ bool LightningData::preload(bool server, String &errorStr) if (Parent::preload(server, errorStr) == false) return false; - dQsort(thunderSounds, MaxThunders, sizeof(SFXTrack*), cmpSounds); - for (numThunders = 0; numThunders < MaxThunders && thunderSounds[numThunders] != NULL; numThunders++) { - // + //dQsort(thunderSounds, MaxThunders, sizeof(SFXTrack*), cmpSounds); + + for (S32 i = 0; i < MaxThunders; i++) { + if (thunderSounds[i]!= NULL) numThunders++; } if (server == false) @@ -321,14 +328,15 @@ void LightningData::packData(BitStream* stream) U32 i; for (i = 0; i < MaxThunders; i++) - sfxWrite( stream, thunderSounds[ i ] ); + { + if (stream->writeFlag(thunderSounds[i])) + sfxWrite(stream, thunderSounds[i]); + } stream->writeInt(mNumStrikeTextures, 4); - for (i = 0; i < MaxTextures; i++) - { + for (i = 0; i < MaxTextures; i++) stream->writeString(strikeTextureNames[i]); - } sfxWrite( stream, strikeSound ); } @@ -339,14 +347,17 @@ void LightningData::unpackData(BitStream* stream) U32 i; for (i = 0; i < MaxThunders; i++) - sfxRead( stream, &thunderSounds[ i ] ); + { + if (stream->readFlag()) + sfxRead(stream, &thunderSounds[i]); + else + thunderSounds[i] = NULL; + } mNumStrikeTextures = stream->readInt(4); - for (i = 0; i < MaxTextures; i++) - { + for (i = 0; i < MaxTextures; i++) strikeTextureNames[i] = stream->readSTString(); - } sfxRead( stream, &strikeSound ); } diff --git a/Templates/BaseGame/game/core/clientServer/scripts/client/levelDownload.cs b/Templates/BaseGame/game/core/clientServer/scripts/client/levelDownload.cs index 58f02c92f..fbd5bfccd 100644 --- a/Templates/BaseGame/game/core/clientServer/scripts/client/levelDownload.cs +++ b/Templates/BaseGame/game/core/clientServer/scripts/client/levelDownload.cs @@ -38,7 +38,73 @@ //---------------------------------------------------------------------------- // Phase 1 //---------------------------------------------------------------------------- -function clientCmdMissionStartPhase1(%seq, %missionName) +$pref::Client::EnableDatablockCache = true; +$pref::Client::DatablockCacheFilename = "data/cache/client/datablock_cache_c.dbc"; + +function clientCmdMissionStartPhase1_LoadCache(%seq, %missionName) +{ + if ($pref::Client::EnableDatablockCache && $loadFromDatablockCache) + { + if (!$pref::Video::disableVerticalSync) + { + warn("Disabling Vertical Sync during datablock cache load to avoid significant slowdown."); + $AFX_tempDisableVSync = true; + + $pref::Video::disableVerticalSync = true; + Canvas.resetVideoMode(); + } + + echo("<<<< Loading Datablocks From Cache >>>>"); + if (ServerConnection.loadDatablockCache_Begin()) + { + schedule(10, 0, "updateLoadDatablockCacheProgress", %seq, %missionName); + } + } +} + +function updateLoadDatablockCacheProgress(%seq, %missionName) +{ + if (ServerConnection.loadDatablockCache_Continue()) + { + $loadDatablockCacheProgressThread = schedule(10, 0, "updateLoadDatablockCacheProgress", %seq, %missionName); + return; + } + + if ($AFX_tempDisableVSync) + { + warn("Restoring Vertical Sync setting."); + $AFX_tempDisableVSync = false; + + $pref::Video::disableVerticalSync = false; + Canvas.resetVideoMode(); + } + + echo("<<<< Finished Loading Datablocks From Cache >>>>"); + clientCmdMissionStartPhase2(%seq,%missionName); +} + +function updateLoadDatablockCacheProgress(%seq, %missionName) +{ + if (ServerConnection.loadDatablockCache_Continue()) + { + $loadDatablockCacheProgressThread = schedule(10, 0, "updateLoadDatablockCacheProgress", %seq, %missionName); + return; + } + + if ($AFX_tempDisableVSync) + { + warn("Restoring Vertical Sync setting."); + $AFX_tempDisableVSync = false; + + $pref::Video::disableVerticalSync = false; + Canvas.resetVideoMode(); + } + + echo("<<<< Finished Loading Datablocks From Cache >>>>"); + clientCmdMissionStartPhase2(%seq,%missionName); +} + +function clientCmdMissionStartPhase1(%seq, %missionName, %cache_crc) { // These need to come after the cls. echo ("*** New Mission: " @ %missionName); @@ -61,6 +127,56 @@ function clientCmdMissionStartPhase1(%seq, %missionName) PostFXManager::settingsApplyDefaultPreset(); } + $loadFromDatablockCache = false; + if ($pref::Client::EnableDatablockCache) + { + %cache_filename = $pref::Client::DatablockCacheFilename; + + // if cache CRC is provided, check for validity + if (%cache_crc !$= "") + { + // check for existence of cache file + if (isFile(%cache_filename)) + { + // here we are not comparing the CRC of the cache itself, but the CRC of + // the server cache (stored in the header) when these datablocks were + // transmitted. + %my_cache_crc = extractDatablockCacheCRC(%cache_filename); + echo("<<<< client cache CRC:" SPC %my_cache_crc SPC ">>>>"); + echo("<<<< comparing CRC codes:" SPC "s:" @ %cache_crc SPC "c:" @ %my_cache_crc SPC ">>>>"); + if (%my_cache_crc == %cache_crc) + { + echo("<<<< cache CRC codes match, datablocks will be loaded from local cache. >>>>"); + $loadFromDatablockCache = true; + } + else + { + echo("<<<< cache CRC codes differ, datablocks will be transmitted and cached. >>>>" SPC %cache_crc); + setDatablockCacheCRC(%cache_crc); + } + } + else + { + echo("<<<< client datablock cache does not exist, datablocks will be transmitted and cached. >>>>"); + setDatablockCacheCRC(%cache_crc); + } + } + else + { + echo("<<<< server datablock caching is disabled, datablocks will be transmitted. >>>>"); + } + if ($loadFromDatablockCache) + { + // skip datablock transmission and initiate a cache load + commandToServer('MissionStartPhase1Ack_UseCache', %seq); + return; + } + } + else if (%cache_crc !$= "") + { + echo("<<<< client datablock caching is disabled, datablocks will be transmitted. >>>>"); + } + onMissionDownloadPhase("LOADING DATABLOCKS"); commandToServer('MissionStartPhase1Ack', %seq); @@ -164,7 +280,7 @@ function connect(%server) { %conn = new GameConnection(ServerConnection); RootGroup.add(ServerConnection); - %conn.setConnectArgs($pref::Player::Name); + %conn.setConnectArgs($pref::Player::Name, $ConncetInfoKey); %conn.setJoinPassword($Client::Password); %conn.connect(%server); } diff --git a/Templates/BaseGame/game/core/clientServer/scripts/server/defaults.cs b/Templates/BaseGame/game/core/clientServer/scripts/server/defaults.cs index b8e72e213..ed213e99d 100644 --- a/Templates/BaseGame/game/core/clientServer/scripts/server/defaults.cs +++ b/Templates/BaseGame/game/core/clientServer/scripts/server/defaults.cs @@ -46,8 +46,6 @@ $Pref::Server::ConnectionError = // overrides pref::net::port for dedicated servers $Pref::Server::Port = 28000; -$Pref::Server::EnableDatablockCache = true; -$Pref::Server::DatablockCacheFilename = "core/clientServer/scripts/server/afx/cache/afx_datablock_cache.dbc"; // If the password is set, clients must provide it in order // to connect to the server diff --git a/Templates/BaseGame/game/core/clientServer/scripts/server/levelDownload.cs b/Templates/BaseGame/game/core/clientServer/scripts/server/levelDownload.cs index de2f5e500..c5777f8fa 100644 --- a/Templates/BaseGame/game/core/clientServer/scripts/server/levelDownload.cs +++ b/Templates/BaseGame/game/core/clientServer/scripts/server/levelDownload.cs @@ -38,8 +38,26 @@ //---------------------------------------------------------------------------- // Phase 1 //---------------------------------------------------------------------------- +$Pref::Server::EnableDatablockCache = true; +$pref::Server::DatablockCacheFilename = "data/cache/server/datablock_cache_c.dbc"; function GameConnection::loadMission(%this) { + %cache_crc = ""; + + if ($Pref::Server::EnableDatablockCache) + { + if (!isDatablockCacheSaved()) + { + echo("<<<< saving server datablock cache >>>>"); + %this.saveDatablockCache(); + } + + if (isFile($Pref::Server::DatablockCacheFilename)) + { + %cache_crc = getDatablockCacheCRC(); + echo(" <<<< sending CRC to client:" SPC %cache_crc SPC ">>>>"); + } + } // Send over the information that will display the server info // when we learn it got there, we'll send the data blocks %this.currentPhase = 0; @@ -50,12 +68,41 @@ function GameConnection::loadMission(%this) } else { - commandToClient(%this, 'MissionStartPhase1', $missionSequence, $Server::MissionFile); + commandToClient(%this, 'MissionStartPhase1', $missionSequence, $Server::MissionFile, %cache_crc); echo("*** Sending mission load to client: " @ $Server::MissionFile); } } +function serverCmdMissionStartPhase1Ack_UseCache(%client, %seq) +{ + echo("<<<< client will load datablocks from a cache >>>>"); + echo(" <<<< skipping datablock transmission >>>>"); + + // Make sure to ignore calls from a previous mission load + if (%seq != $missionSequence || !$MissionRunning) + return; + if (%client.currentPhase != 0) + return; + %client.currentPhase = 1; + + // Start with the CRC + %client.setMissionCRC( $missionCRC ); + + %client.onBeginDatablockCacheLoad($missionSequence); +} + +function GameConnection::onBeginDatablockCacheLoad( %this, %missionSequence ) +{ + // Make sure to ignore calls from a previous mission load + if (%missionSequence != $missionSequence) + return; + if (%this.currentPhase != 1) + return; + %this.currentPhase = 1.5; + commandToClient(%this, 'MissionStartPhase1_LoadCache', $missionSequence, $Server::MissionFile); +} + function serverCmdMissionStartPhase1Ack(%client, %seq) { // Make sure to ignore calls from a previous mission load @@ -157,14 +204,6 @@ function serverCmdMissionStartPhase3Ack(%client, %seq) // Set the control object to the default camera if (!isObject(%client.camera)) { - if(!isObject(Observer)) - { - datablock CameraData(Observer) - { - mode = "Observer"; - }; - } - //if (isDefined("$Game::DefaultCameraClass")) %client.camera = spawnObject("Camera", Observer); } diff --git a/Templates/BaseGame/game/core/clientServer/scripts/server/server.cs b/Templates/BaseGame/game/core/clientServer/scripts/server/server.cs index 5663d8bc6..0c6c680af 100644 --- a/Templates/BaseGame/game/core/clientServer/scripts/server/server.cs +++ b/Templates/BaseGame/game/core/clientServer/scripts/server/server.cs @@ -204,10 +204,11 @@ function onServerCreated() loadDatablockFiles( DatablockFilesList, true ); + callOnModules("onServerScriptExec", "Core"); + callOnModules("onServerScriptExec", "Game"); + // Keep track of when the game started $Game::StartTime = $Sim::Time; - - onServerCreatedAFX(); } /// Shut down the server @@ -283,6 +284,9 @@ function onServerDestroyed() MissionCleanup.delete(); clearServerPaths(); + + if ($Pref::Server::EnableDatablockCache) + resetDatablockCache(); } /// Guid list maintenance functions