Browse Source

Check changes in required packages before sync.

cin 11 years ago
parent
commit
264cd304ff
2 changed files with 35 additions and 1 deletions
  1. 31 1
      Source/Engine/Network/Connection.cpp
  2. 4 0
      Source/Engine/Network/Connection.h

+ 31 - 1
Source/Engine/Network/Connection.cpp

@@ -1459,13 +1459,23 @@ void Connection::SendSyncPackagesInfo(bool allClients)
 {
     const Vector<SharedPtr<PackageFile> >& packages = scene_->GetRequiredPackageFiles();
     unsigned numPackages = packages.Size();
+
+	if (numPackages == 0)
+		return;
+
+	if (!CheckPackagesUpdate())
+		return;
+
+	cachedPackages_.Clear();
     msg_.Clear();
     msg_.WriteVLE(numPackages);
 
     for (unsigned i = 0; i < numPackages; ++i)
     {
         PackageFile* package = packages[i];
-        msg_.WriteString(GetFileNameAndExtension(package->GetName()));
+		String filename = GetFileNameAndExtension(package->GetName());
+		cachedPackages_.Push(filename);
+        msg_.WriteString(filename);
         msg_.WriteUInt(package->GetTotalSize());
         msg_.WriteUInt(package->GetChecksum());
     }
@@ -1569,4 +1579,24 @@ void Connection::ProcessSyncPackagesInfo(int msgID, MemoryBuffer& msg)
 
     } // for
 }
+
+bool Connection::CheckPackagesUpdate()
+{
+	if (cachedPackages_.Empty())
+		return true;
+
+	const Vector<SharedPtr<PackageFile> >& packages = scene_->GetRequiredPackageFiles();
+	unsigned numPackages = packages.Size();
+
+	for (unsigned i = 0; i < numPackages; ++i)
+	{
+		PackageFile* package = packages[i];
+		String filename = GetFileNameAndExtension(package->GetName());
+
+		if (!cachedPackages_.Contains(filename))
+			return true;
+	}
+
+	return false;
+}
 }

+ 4 - 0
Source/Engine/Network/Connection.h

@@ -221,6 +221,8 @@ private:
     void ProcessSyncPackagesInfo(int msgID, MemoryBuffer& msg);
 	/// Send message with info about all required packages, clients start download missing packages
 	void SendSyncPackagesInfo(bool allClients = true);
+	/// Check changes in packages filename cache
+	bool CheckPackagesUpdate();
     /// Initiate a package download.
     void RequestPackage(const String& name, unsigned fileSize, unsigned checksum);
     /// Send an error reply for a package download.
@@ -274,6 +276,8 @@ private:
     bool sceneLoaded_;
     /// Show statistics flag.
     bool logStatistics_;
+	/// Cached filenames of packages
+	Vector<String> cachedPackages_;
 };
 
 }