Objects in scope and disconnected notification
by Dawid Rutyna · in Torque Game Engine · 10/20/2008 (3:25 pm) · 3 replies
In the TNLTest there is two basic object types - Player and Building. I am practising before starting to develop a new game. The Player is said to be typical object which is not always in scope on the contrary to Building which is always in scope.
Recently i have made some changes in the project so that building could change their colors when player is over them (the color would be the same as player's). Everything works fine but there is one problem. Players positions are received and sent only when the it is necessary (the other player is in scope) but buildings colors are sent always (all of them). I thought that maybe changing performScopeQuery will help, but it wouldn't. So there have to be some other thing that differs those two objects, what is it? And what I have to write to achive the same result (rare packages sending) as it is with player?
void Player::performScopeQuery(TNL::GhostConnection *connection)
{
for(TNL::S32 i = 0; i < game->buildings.size(); i++)
{
Position building;
building.x = game->buildings[i]->lowerRight.x + (game->buildings[i]->lowerRight.x - game->buildings[i]->upperLeft.x)/2;
building.y = game->buildings[i]->lowerRight.y + (game->buildings[i]->lowerRight.y - game->buildings[i]->upperLeft.y)/2;
TNL::F32 dx = building.x - renderPos.x;
TNL::F32 dy = building.y - renderPos.y;
TNL::F32 distSquared = dx * dx + dy * dy;
if(distSquared < 0.0625)
connection->objectInScope(game->buildings[i]);
}
for(TNL::S32 i = 0; i < game->players.size(); i++)
{
Position playerP = game->players[i]->renderPos;
TNL::F32 dx = playerP.x - renderPos.x;
TNL::F32 dy = playerP.y - renderPos.y;
TNL::F32 distSquared = dx * dx + dy * dy;
if(distSquared < 0.0625)
connection->objectInScope(game->players[i]);
}
}
And my second question... Is there an easy way for server to receive notification when some client has disconnected?
Recently i have made some changes in the project so that building could change their colors when player is over them (the color would be the same as player's). Everything works fine but there is one problem. Players positions are received and sent only when the it is necessary (the other player is in scope) but buildings colors are sent always (all of them). I thought that maybe changing performScopeQuery will help, but it wouldn't. So there have to be some other thing that differs those two objects, what is it? And what I have to write to achive the same result (rare packages sending) as it is with player?
void Player::performScopeQuery(TNL::GhostConnection *connection)
{
for(TNL::S32 i = 0; i < game->buildings.size(); i++)
{
Position building;
building.x = game->buildings[i]->lowerRight.x + (game->buildings[i]->lowerRight.x - game->buildings[i]->upperLeft.x)/2;
building.y = game->buildings[i]->lowerRight.y + (game->buildings[i]->lowerRight.y - game->buildings[i]->upperLeft.y)/2;
TNL::F32 dx = building.x - renderPos.x;
TNL::F32 dy = building.y - renderPos.y;
TNL::F32 distSquared = dx * dx + dy * dy;
if(distSquared < 0.0625)
connection->objectInScope(game->buildings[i]);
}
for(TNL::S32 i = 0; i < game->players.size(); i++)
{
Position playerP = game->players[i]->renderPos;
TNL::F32 dx = playerP.x - renderPos.x;
TNL::F32 dy = playerP.y - renderPos.y;
TNL::F32 distSquared = dx * dx + dy * dy;
if(distSquared < 0.0625)
connection->objectInScope(game->players[i]);
}
}
And my second question... Is there an easy way for server to receive notification when some client has disconnected?
#2
10/22/2008 (11:35 am)
I'm no ghosting expert, but I think I can point you in the right direction. On lines 477-480 of testGame.cpp scoping is enabled for the Player object. I think you need to add similar lines after line 576 for buildings to be scoped.
#3
10/22/2008 (1:47 pm)
I was my mistake... The Building object in its constructor has mNetFlags.set(Ghostable); and this is enough to properly ghost it. My mistake was during Update of the building. I was executing almost every time setMaskBits(someMask) function. And although the building in clients scope weren't changing their colors, I was receiving updates of theirs states.
Dawid Rutyna