Changed Connection::SendPackageToClient() to not broadcast to all clients. Instead Network::SendPackageToClients() will send to all clients in a specific scene. Updated Network Lua bindings.
This commit is contained in:
Родитель
cde92a8358
Коммит
18e85ab18a
|
@ -27,12 +27,7 @@ class Connection : public Object
|
||||||
void SetConnectPending(bool connectPending);
|
void SetConnectPending(bool connectPending);
|
||||||
void SetLogStatistics(bool enable);
|
void SetLogStatistics(bool enable);
|
||||||
void Disconnect(int waitMSec = 0);
|
void Disconnect(int waitMSec = 0);
|
||||||
void SendServerUpdate();
|
void SendPackageToClient(PackageFile* package);
|
||||||
void SendClientUpdate();
|
|
||||||
void SendRemoteEvents();
|
|
||||||
void SendPackages();
|
|
||||||
void ProcessPendingLatestData();
|
|
||||||
bool ProcessMessage(int msgID, MemoryBuffer& msg);
|
|
||||||
|
|
||||||
VariantMap& GetIdentity();
|
VariantMap& GetIdentity();
|
||||||
Scene* GetScene() const;
|
Scene* GetScene() const;
|
||||||
|
|
|
@ -29,6 +29,7 @@ class Network
|
||||||
|
|
||||||
void UnregisterAllRemoteEvents();
|
void UnregisterAllRemoteEvents();
|
||||||
void SetPackageCacheDir(const String path);
|
void SetPackageCacheDir(const String path);
|
||||||
|
void SendPackageToClients(Scene* scene, PackageFile* package);
|
||||||
|
|
||||||
// SharedPtr<HttpRequest> MakeHttpRequest(const String url, const String verb = String::EMPTY, const Vector<String>& headers = Vector<String>(), const String postData = String::EMPTY);
|
// SharedPtr<HttpRequest> MakeHttpRequest(const String url, const String verb = String::EMPTY, const Vector<String>& headers = Vector<String>(), const String postData = String::EMPTY);
|
||||||
tolua_outside HttpRequest* NetworkMakeHttpRequest @ MakeHttpRequest(const String url, const String verb = String::EMPTY, const Vector<String>& headers = Vector<String>(), const String postData = String::EMPTY);
|
tolua_outside HttpRequest* NetworkMakeHttpRequest @ MakeHttpRequest(const String url, const String verb = String::EMPTY, const Vector<String>& headers = Vector<String>(), const String postData = String::EMPTY);
|
||||||
|
|
|
@ -1432,13 +1432,21 @@ void Connection::OnPackagesReady()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Connection::SendPackageToClients(PackageFile* package)
|
void Connection::SendPackageToClient(PackageFile* package)
|
||||||
{
|
{
|
||||||
if (!scene_)
|
if (!scene_)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!IsClient())
|
if (!IsClient())
|
||||||
|
{
|
||||||
|
LOGERROR("SendPackageToClient can be called on the server only");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
if (!package)
|
||||||
|
{
|
||||||
|
LOGERROR("Null package specified for SendPackageToClient");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
msg_.Clear();
|
msg_.Clear();
|
||||||
|
|
||||||
|
@ -1446,7 +1454,7 @@ void Connection::SendPackageToClients(PackageFile* package)
|
||||||
msg_.WriteString(filename);
|
msg_.WriteString(filename);
|
||||||
msg_.WriteUInt(package->GetTotalSize());
|
msg_.WriteUInt(package->GetTotalSize());
|
||||||
msg_.WriteUInt(package->GetChecksum());
|
msg_.WriteUInt(package->GetChecksum());
|
||||||
GetSubsystem<Network>()->BroadcastMessage(MSG_PACKAGEINFO, true, true, msg_);
|
SendMessage(MSG_PACKAGEINFO, true, true, msg_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Connection::ProcessPackageInfo(int msgID, MemoryBuffer& msg)
|
void Connection::ProcessPackageInfo(int msgID, MemoryBuffer& msg)
|
||||||
|
|
|
@ -183,8 +183,8 @@ public:
|
||||||
const String& GetDownloadName() const;
|
const String& GetDownloadName() const;
|
||||||
/// Return progress of current package download, or 1.0 if no downloads.
|
/// Return progress of current package download, or 1.0 if no downloads.
|
||||||
float GetDownloadProgress() const;
|
float GetDownloadProgress() const;
|
||||||
/// Trigger client connections to download a package file from the server. Can be used to download additional resource packages when clients are already joined in a scene.
|
/// Trigger client connection to download a package file from the server. Can be used to download additional resource packages when client is already joined in a scene. The package must have been added as a requirement to the scene the client is joined in, or else the eventual download will fail.
|
||||||
void SendPackageToClients(PackageFile* package);
|
void SendPackageToClient(PackageFile* package);
|
||||||
|
|
||||||
/// Current controls.
|
/// Current controls.
|
||||||
Controls controls_;
|
Controls controls_;
|
||||||
|
|
|
@ -361,6 +361,27 @@ void Network::SetPackageCacheDir(const String& path)
|
||||||
packageCacheDir_ = AddTrailingSlash(path);
|
packageCacheDir_ = AddTrailingSlash(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Network::SendPackageToClients(Scene* scene, PackageFile* package)
|
||||||
|
{
|
||||||
|
if (!scene)
|
||||||
|
{
|
||||||
|
LOGERROR("Null scene specified for SendPackageToClients");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!package)
|
||||||
|
{
|
||||||
|
LOGERROR("Null package specified for SendPackageToClients");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (HashMap<kNet::MessageConnection*, SharedPtr<Connection> >::Iterator i = clientConnections_.Begin();
|
||||||
|
i != clientConnections_.End(); ++i)
|
||||||
|
{
|
||||||
|
if (i->second_->GetScene() == scene)
|
||||||
|
i->second_->SendPackageToClient(package);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SharedPtr<HttpRequest> Network::MakeHttpRequest(const String& url, const String& verb, const Vector<String>& headers, const String& postData)
|
SharedPtr<HttpRequest> Network::MakeHttpRequest(const String& url, const String& verb, const Vector<String>& headers, const String& postData)
|
||||||
{
|
{
|
||||||
PROFILE(MakeHttpRequest);
|
PROFILE(MakeHttpRequest);
|
||||||
|
|
|
@ -91,6 +91,8 @@ public:
|
||||||
void UnregisterAllRemoteEvents();
|
void UnregisterAllRemoteEvents();
|
||||||
/// Set the package download cache directory.
|
/// Set the package download cache directory.
|
||||||
void SetPackageCacheDir(const String& path);
|
void SetPackageCacheDir(const String& path);
|
||||||
|
/// Trigger all client connections in the specified scene to download a package file from the server. Can be used to download additional resource packages when clients are already joined in the scene. The package must have been added as a requirement to the scene, or else the eventual download will fail.
|
||||||
|
void SendPackageToClients(Scene* scene, PackageFile* package);
|
||||||
/// Perform an HTTP request to the specified URL. Empty verb defaults to a GET request. Return a request object which can be used to read the response data.
|
/// Perform an HTTP request to the specified URL. Empty verb defaults to a GET request. Return a request object which can be used to read the response data.
|
||||||
SharedPtr<HttpRequest> MakeHttpRequest(const String& url, const String& verb = String::EMPTY, const Vector<String>& headers = Vector<String>(), const String& postData = String::EMPTY);
|
SharedPtr<HttpRequest> MakeHttpRequest(const String& url, const String& verb = String::EMPTY, const Vector<String>& headers = Vector<String>(), const String& postData = String::EMPTY);
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,7 @@ static void RegisterConnection(asIScriptEngine* engine)
|
||||||
engine->RegisterObjectMethod("Connection", "const Vector3& get_position() const", asMETHOD(Connection, GetPosition), asCALL_THISCALL);
|
engine->RegisterObjectMethod("Connection", "const Vector3& get_position() const", asMETHOD(Connection, GetPosition), asCALL_THISCALL);
|
||||||
engine->RegisterObjectMethod("Connection", "void set_rotation(const Quaternion&in)", asMETHOD(Connection, SetRotation), asCALL_THISCALL);
|
engine->RegisterObjectMethod("Connection", "void set_rotation(const Quaternion&in)", asMETHOD(Connection, SetRotation), asCALL_THISCALL);
|
||||||
engine->RegisterObjectMethod("Connection", "const Quaternion& get_rotation() const", asMETHOD(Connection, GetRotation), asCALL_THISCALL);
|
engine->RegisterObjectMethod("Connection", "const Quaternion& get_rotation() const", asMETHOD(Connection, GetRotation), asCALL_THISCALL);
|
||||||
engine->RegisterObjectMethod("Connection", "void sendPackageToClients(PackageFile@+)", asMETHOD(Connection, SendPackageToClients), asCALL_THISCALL);
|
engine->RegisterObjectMethod("Connection", "void SendPackageToClient(PackageFile@+)", asMETHOD(Connection, SendPackageToClient), asCALL_THISCALL);
|
||||||
engine->RegisterObjectProperty("Connection", "Controls controls", offsetof(Connection, controls_));
|
engine->RegisterObjectProperty("Connection", "Controls controls", offsetof(Connection, controls_));
|
||||||
engine->RegisterObjectProperty("Connection", "VariantMap identity", offsetof(Connection, identity_));
|
engine->RegisterObjectProperty("Connection", "VariantMap identity", offsetof(Connection, identity_));
|
||||||
|
|
||||||
|
@ -206,6 +206,7 @@ void RegisterNetwork(asIScriptEngine* engine)
|
||||||
engine->RegisterObjectMethod("Network", "void UnregisterAllRemoteEvents()", asMETHOD(Network, UnregisterAllRemoteEvents), asCALL_THISCALL);
|
engine->RegisterObjectMethod("Network", "void UnregisterAllRemoteEvents()", asMETHOD(Network, UnregisterAllRemoteEvents), asCALL_THISCALL);
|
||||||
engine->RegisterObjectMethod("Network", "bool CheckRemoteEvent(const String&in) const", asFUNCTION(NetworkCheckRemoteEvent), asCALL_CDECL_OBJLAST);
|
engine->RegisterObjectMethod("Network", "bool CheckRemoteEvent(const String&in) const", asFUNCTION(NetworkCheckRemoteEvent), asCALL_CDECL_OBJLAST);
|
||||||
engine->RegisterObjectMethod("Network", "HttpRequest@ MakeHttpRequest(const String&in, const String&in verb = String(), Array<String>@+ headers = null, const String&in postData = String())", asFUNCTION(NetworkMakeHttpRequest), asCALL_CDECL_OBJLAST);
|
engine->RegisterObjectMethod("Network", "HttpRequest@ MakeHttpRequest(const String&in, const String&in verb = String(), Array<String>@+ headers = null, const String&in postData = String())", asFUNCTION(NetworkMakeHttpRequest), asCALL_CDECL_OBJLAST);
|
||||||
|
engine->RegisterObjectMethod("Network", "void SendPackageToClients(Scene@+, PackageFile@+)", asMETHOD(Network, SendPackageToClients), asCALL_THISCALL);
|
||||||
engine->RegisterObjectMethod("Network", "void set_updateFps(int)", asMETHOD(Network, SetUpdateFps), asCALL_THISCALL);
|
engine->RegisterObjectMethod("Network", "void set_updateFps(int)", asMETHOD(Network, SetUpdateFps), asCALL_THISCALL);
|
||||||
engine->RegisterObjectMethod("Network", "int get_updateFps() const", asMETHOD(Network, GetUpdateFps), asCALL_THISCALL);
|
engine->RegisterObjectMethod("Network", "int get_updateFps() const", asMETHOD(Network, GetUpdateFps), asCALL_THISCALL);
|
||||||
engine->RegisterObjectMethod("Network", "void set_packageCacheDir(const String&in)", asMETHOD(Network, SetPackageCacheDir), asCALL_THISCALL);
|
engine->RegisterObjectMethod("Network", "void set_packageCacheDir(const String&in)", asMETHOD(Network, SetPackageCacheDir), asCALL_THISCALL);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче