I’m not sure if this intentional, but it seems that all of the Get functions return const. This makes it impractical to modify the data within the Variant. For example, I store a VariantMap within a VariantVector so that I can transfer arbitrary data between server and client automatically via an Attribute. In order to actually modify the data, I’m forced to run a const_cast. This is ugly and goes against the entire purpose of marking the return call const. Here’s the relevant function (that works with const_cast) to give you an idea of how I’m trying to work with it:
void LobbyComponent::HandlePlayerJoinedRoom(Urho3D::StringHash eventType, Urho3D::VariantMap& eventData)
{
using namespace PlayerJoinedRoom;
Urho3D::Connection* connection = static_cast<Urho3D::Connection*>(eventData[P_CONNECTION].GetPtr());
Urho3D::Scene* scene = static_cast<Urho3D::Scene*>(eventData[P_ROOM].GetPtr());
for (Urho3D::VariantVector::Iterator itr = _rooms.Begin(); itr != _rooms.End(); itr++)
{
// Ugly const_cast
Urho3D::VariantMap& map = const_cast<Urho3D::VariantMap&>(itr->GetVariantMap());
if (map[ATTR_ROOM_ID].GetStringHash() == scene->GetNameHash())
{
map[ATTR_NUM_PLAYERS] = scene->GetChild(N_PLAYERS)->GetNumChildren();
break;
}
}
MarkNetworkUpdate();
}
Is there any better ways to do this?