( Online Game ) InRange Entity's Updates.
( Online Game ) InRange Entity's Updates.
Hello, I have asked this question before also I dont believe that people really understand what I meant, so I will try again.
There I am seeking is to see if this is a good way to deal with players/enemie entitys running around in an online game.
So all characters ingame have an "Entity" array like this:
irr:: core:: array <CEntity *> pInRangeEntities;
So that keeps track of the players who are "InRange" of my character and not InRange of it.
My question is how you would handle thinks like this, Like add and remove players / enemies from the current player to avoid updating players/enemies that you dont see.
My way is to check whenever any player/enemie will be InRange of my character, if someone is then check it if this "Player/Enemie" exists, if it does not exist, then it will be added to the list and send an update that include information about the new "Entity" like position, animation etc and also create the object to the player who dident have that "Entity" in the list.
Hope you understand my question and what I mean, and feel free to come with tips on how you would have done it.
Thank you very much!
Ps, My english is kinda bad.
There I am seeking is to see if this is a good way to deal with players/enemie entitys running around in an online game.
So all characters ingame have an "Entity" array like this:
irr:: core:: array <CEntity *> pInRangeEntities;
So that keeps track of the players who are "InRange" of my character and not InRange of it.
My question is how you would handle thinks like this, Like add and remove players / enemies from the current player to avoid updating players/enemies that you dont see.
My way is to check whenever any player/enemie will be InRange of my character, if someone is then check it if this "Player/Enemie" exists, if it does not exist, then it will be added to the list and send an update that include information about the new "Entity" like position, animation etc and also create the object to the player who dident have that "Entity" in the list.
Hope you understand my question and what I mean, and feel free to come with tips on how you would have done it.
Thank you very much!
Ps, My english is kinda bad.
-
- Posts: 368
- Joined: Tue Aug 21, 2007 1:43 am
- Location: The Middle of Nowhere
I handled this in a completely different way. First, keeping an array of entities for each player is expensive and a waste of memory. Using one list for all game entities is more efficient (or a list per different entity type if you wish).
I divided the world into cells, or sections of the world. I then kept an array of players who are currently connected and the cell that they are in. Once an update is ready to be transmitted, I look through the player list for players that are in range of the update and only send the data to those clients. Range can be completely defined by you, whether it's only the cell that the player is in or a range of cells around the player.
This method is both cheaper memory wise (only 1 list of game objects and only 1 list of structs describing players) and cheaper processor wise (only 1 place to search which could be optimized using a tree or binary searching algorithms. )
I divided the world into cells, or sections of the world. I then kept an array of players who are currently connected and the cell that they are in. Once an update is ready to be transmitted, I look through the player list for players that are in range of the update and only send the data to those clients. Range can be completely defined by you, whether it's only the cell that the player is in or a range of cells around the player.
This method is both cheaper memory wise (only 1 list of game objects and only 1 list of structs describing players) and cheaper processor wise (only 1 place to search which could be optimized using a tree or binary searching algorithms. )
rogerborg wrote:Every time someone learns to use a debugger, an angel gets their wings.
A binary search or quad tree is not needed to make the proposed solution more efficient. Since the zones don't know which entities it has, a linear search through the entity list has to be done to find all nearby entities. To be correct, one search for several of the nearby zones would be necessary when an object is near an edge. This is bad if there are many entities.
If the grid system knows about which entities are in each zone, then it is computationally inexpensive to find entities in the same zone as this one and any adjacent ones.
Travis
If the grid system knows about which entities are in each zone, then it is computationally inexpensive to find entities in the same zone as this one and any adjacent ones.
Travis
Okay, thank you for your answers, helped me to know how I can update all players better.
However, questions about the creation of players/entities for the individual client. A common FPS game with around 32spelare as max limit, It will send all the info for all the players who are "ingame" when a new client (player) connects.
But in an online game with more than 100+ players caused you should look at something bättere way, where I have some more questions about, I understand what you mean by the updates thing but how do you handle the creation of new entities on the new client? Do you have a similar sphere collision and see if any "UnKnown" player/entity will get in range and then create it for the client? because you want to send all info for each player ingame when a new client connect, I hope understand what I mean.
Thank you very much! and for your responses.
However, questions about the creation of players/entities for the individual client. A common FPS game with around 32spelare as max limit, It will send all the info for all the players who are "ingame" when a new client (player) connects.
But in an online game with more than 100+ players caused you should look at something bättere way, where I have some more questions about, I understand what you mean by the updates thing but how do you handle the creation of new entities on the new client? Do you have a similar sphere collision and see if any "UnKnown" player/entity will get in range and then create it for the client? because you want to send all info for each player ingame when a new client connect, I hope understand what I mean.
Thank you very much! and for your responses.
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
I'd suggest that you use lazy initialisation.
When a player connects, don't try to distribute information about it to all other players, or to tell it everything about the game world at once.
Instead, just send the normal state change packets for nearby players, plus the usual information that you'd send to a player entering the zone that the new player is in.
Whenever a client receives a state packet for an object that it doesn't yet know anything about, it should create an anonymous placeholder object that can store (e.g.) position and state, but without knowing the details of the object e.g. its type and name.
Don't make the anonymous object active in the client's copy of the world state yet. Have the client request details of the object from the server.
The server can then send detailed info about objects as it receives the requests, and the client can then fill in the blanks in their local copies, and activate them in their world states.
This should help to smooth out the big chunk of bandwidth required to sync a connecting player.
When a player connects, don't try to distribute information about it to all other players, or to tell it everything about the game world at once.
Instead, just send the normal state change packets for nearby players, plus the usual information that you'd send to a player entering the zone that the new player is in.
Whenever a client receives a state packet for an object that it doesn't yet know anything about, it should create an anonymous placeholder object that can store (e.g.) position and state, but without knowing the details of the object e.g. its type and name.
Don't make the anonymous object active in the client's copy of the world state yet. Have the client request details of the object from the server.
The server can then send detailed info about objects as it receives the requests, and the client can then fill in the blanks in their local copies, and activate them in their world states.
This should help to smooth out the big chunk of bandwidth required to sync a connecting player.
Last edited by rogerborg on Tue Nov 04, 2008 12:33 pm, edited 1 time in total.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
I would introduce zones like this:
That system should work great for openplanes and stuff like that. In citylike enviroments u should define these zones dependin on the levelarchitecture. like a small hallway could be a predefined grayzone.
and because of the data syncing. I made my entities component based. So basicly my entity is just a list or array that hold pointers to a general ComponentClass. These classes make up the game logic. One for graphic, one for movement and so on. Well since the position is updated regular the entity is created with just the movement component when entering the Greenzone. Then the client checks the type of the entity. If it is a player for example it requests a full update on that entity or at least on the components that are not already initialized.
That system should work great for openplanes and stuff like that. In citylike enviroments u should define these zones dependin on the levelarchitecture. like a small hallway could be a predefined grayzone.
and because of the data syncing. I made my entities component based. So basicly my entity is just a list or array that hold pointers to a general ComponentClass. These classes make up the game logic. One for graphic, one for movement and so on. Well since the position is updated regular the entity is created with just the movement component when entering the Greenzone. Then the client checks the type of the entity. If it is a player for example it requests a full update on that entity or at least on the components that are not already initialized.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
Allright Im doing some testing now I have defined 1 distance now for testing, Is this an good way to do it?
First I call this "UpdateInRangeSet" to delete players outside range.
Then I call this "CheckForInRangeObjects" to add Players that gets inRange.
And the runtime looks like this.
So my question is, Is this an good way or can I do it on an better way?
Thanks alot dudes.
First I call this "UpdateInRangeSet" to delete players outside range.
Code: Select all
void Character::UpdateInRangeSet()
{
int count = 0;
int size1 = 0;
std::set<Character*>::iterator itr;
for (itr = m_objectsInRange.begin(); itr != m_objectsInRange.end();)
{
size1 = (int)m_objectsInRange.size();
while (count < 60 && itr != m_objectsInRange.end())
{
if( getDistanceSq((*itr)) > UPDATE_DISTANCE*UPDATE_DISTANCE )
{
printf( "Removed %i from In Range Set.\n", pChr->pID );
// remove from set
Character* pObj = *itr;
++itr;
m_objectsInRange.erase(pObj);
count++;
continue;
}
}
++itr;
}
count = 0;
}
Code: Select all
inline void CheckForInRangeObjects(Character* pObj)
{
CharacterMap::iterator chriter;
for( chriter = mCharacters.begin( ); chriter != mCharacters.end( ); ++ chriter )
{
Character *pChr = chriter->second;
if (((Character*)pChr) != pObj && !pObj->IsInRangeSet(pChr) &&
pObj->getDistanceSq(pChr) <= UPDATE_DISTANCE*UPDATE_DISTANCE)
{
//Here we send the "Create" packet to the "pObj" Character
// Object in range, add to set
printf("Added %i to InRange Set.\n", pChr->pID);
pObj->AddInRangeObject(pChr);
}
}
}
Code: Select all
CharacterMap::iterator itr;
for( itr = mCharacters.begin( ); itr != mCharacters.end( ); ++ itr )
{
itr->second->UpdateInRangeSet();
CheckForInRangeObjects(itr->second);
}
Thanks alot dudes.
Last edited by xsocom on Wed Nov 05, 2008 6:31 pm, edited 1 time in total.
Well u r removing characters from the list and then u check again if they are in range....that seams redundent to me. Maybe first check if new players came in range and then remove the others. of and btw. u have to have both lists for every player. sure that takes some memory but it should be faster in the end. Oh and u should add extra zones for houses or dungeons as i said. bc u don't want updates or players in that list if they are in a dungeon or house.
EDIT: if a player is in the inrange list he shouldn't be in the other list. so u don't check an item twice. thats why u need these lists for every player.
EDIT: if a player is in the inrange list he shouldn't be in the other list. so u don't check an item twice. thats why u need these lists for every player.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
Ok, how much money does it take to create and maintain an online game? I have an idea for an online game and I was wandering how much$ it might cost to make, and maintain. I also was wondering if anyone out there might be interested in helping with this task...some one with know how and equipment. But the main question is why I posted this on yahoo answers.