The object streaming is done via a plugin coded in C++ by Incognito, which makes it about 20x faster than any version that could be written in PAWN alone.
Above is the source of the object streaming part of the plugin. Obviously it's missing some functions that are called there. My C++ knowledge isn't up to scratch, but it looks to me gathering from function names that it is indeed as you suggested looping through all players and objects and checking distance accordingly at once. I'm sure there are better ways of doing it, like splitting it up into object grids, but I don't see why it should be slow. C++ is nothing like PAWN - looping isn't slow to begin with, so I'm not sure if it would even make a difference whether map zones were in different worlds. But anyway, we'll be changing the map zone handler soonish so that each map zone has it's own virtual world (again), which, in turn, should reduce the amount of iterations.
In short: Don't worry. It's fast. I've benchmarked this plugin in the past with 1,000,000 objects - heh, check out GamerX. They often have 400+ players, have over 1/2 mil objects, and I get normal ping when going there!
I _think_ Awesome Stuntages use it too, and again, they get 400+ players on a regular basis.
255 is the SA-MP object limit, so therefore there can't be more than 255 objects spread over the whole map (Unless you're including static objects as well as SA-MP objects - in that case I'm unsure, although it would explain an old mystery..).
Code:
void
CStreamer::processObjects(Data::Player & player)
{
std::multimap<float, Data::Object>
discoveredObjects;
for (std::vector<Data::Object>::iterator o = CCore::objects.begin(); o != CCore::objects.end(); ++o)
{
float
distance = std::numeric_limits<float>::infinity();
if (checkPlayer((* o).interiorID, player.interiorID, (* o).playerID, player.playerID, (* o).worldID, player.worldID))
{
distance = checkDistance3D(player.x, player.y, player.z, (* o).x, (* o).y, (* o).z);
}
std::map<int, int>::iterator
s = player.objects.find((* o).objectID);
if (distance <= (* o).distance)
{
if (s == player.objects.end())
{
discoveredObjects.insert(std::make_pair(distance, * o));
}
}
else
{
if (s != player.objects.end())
{
gInvoke.callFunction(&PAWN::DestroyPlayerObject, player.playerID, (* s).second);
player.objects.erase(s);
}
}
}
for (std::multimap<float, Data::Object>::iterator d = discoveredObjects.begin(); d != discoveredObjects.end(); ++d)
{
if (player.objects.size() == CCore::global.visibleObjects)
{
break;
}
(* d).second.internalID = gInvoke.callFunction(&PAWN::CreatePlayerObject, player.playerID, (* d).second.modelID, (* d).second.x, (* d).second.y, (* d).second.z, (* d).second.rX, (* d).second.rY, (* d).second.rZ);
if ((* d).second.internalID == INVALID_OBJECT_ID)
{
break;
}
if ((* d).second.move)
{
gInvoke.callFunction(&PAWN::MovePlayerObject, player.playerID, (* d).second.internalID, (* d).second.move->x, (* d).second.move->y, (* d).second.move->z, (* d).second.move->speed);
}
player.objects.insert(std::make_pair((* d).second.objectID, (* d).second.internalID));
}
}Above is the source of the object streaming part of the plugin. Obviously it's missing some functions that are called there. My C++ knowledge isn't up to scratch, but it looks to me gathering from function names that it is indeed as you suggested looping through all players and objects and checking distance accordingly at once. I'm sure there are better ways of doing it, like splitting it up into object grids, but I don't see why it should be slow. C++ is nothing like PAWN - looping isn't slow to begin with, so I'm not sure if it would even make a difference whether map zones were in different worlds. But anyway, we'll be changing the map zone handler soonish so that each map zone has it's own virtual world (again), which, in turn, should reduce the amount of iterations.
In short: Don't worry. It's fast. I've benchmarked this plugin in the past with 1,000,000 objects - heh, check out GamerX. They often have 400+ players, have over 1/2 mil objects, and I get normal ping when going there!
I _think_ Awesome Stuntages use it too, and again, they get 400+ players on a regular basis.(06-02-2010, 04:55 PM)Chillosophy link Wrote: In some other map-related topic I learned that there can be 255 objects per 600x600 (meters?) area, is that correct?
255 is the SA-MP object limit, so therefore there can't be more than 255 objects spread over the whole map (Unless you're including static objects as well as SA-MP objects - in that case I'm unsure, although it would explain an old mystery..).