Scoping & Ghosts
by Welias D. Willie II · in Torque Game Engine · 08/25/2005 (11:01 pm) · 8 replies
I want to have, say, hundreds of objects loaded dynamically with MissionCleanup.add(%obj); from a database (I have this working fine) then I wish to ghost these objects to clients that are within a small range (or scope) of these objects. As well, I only want to ghost the objects near each client.
Example: Server has 1000 objects added by MissionCleanup.add
Client 1 is at a location that it can only see 50 of those objects so only 50 of them are ghosted to that client.
Client 2 is at a location that it can only see 200 of those objects so only 200 of them are ghosted to that client.
Also as part of trying to solve this problem I noticed an issue with the missionload... client 1 joins a game with 0 objects visible (on either the server or the client), during the course of the game 1000 objects are added by MissionCleanup.add, then client 2 joins the game and during the missionload (regardless of where these 1000 objects are in relation to the scope range of the spawn point) the client has to load the entire "virtual" mission.
Ultimately I am trying to get around the overhead of a dynamic object system.
Any ideas?
Example: Server has 1000 objects added by MissionCleanup.add
Client 1 is at a location that it can only see 50 of those objects so only 50 of them are ghosted to that client.
Client 2 is at a location that it can only see 200 of those objects so only 200 of them are ghosted to that client.
Also as part of trying to solve this problem I noticed an issue with the missionload... client 1 joins a game with 0 objects visible (on either the server or the client), during the course of the game 1000 objects are added by MissionCleanup.add, then client 2 joins the game and during the missionload (regardless of where these 1000 objects are in relation to the scope range of the spawn point) the client has to load the entire "virtual" mission.
Ultimately I am trying to get around the overhead of a dynamic object system.
Any ideas?
About the author
#2
The mission file is basically empty with the exception of sky, terrain, spawn point and four objects, client 1 enters the game and downloads the mission file extremely fast. Client one initiates a build of 1000 objects at location 8192x 8192y, these objects are simple cubes with one texture (box.dif). Visibility and Mission area are only 512x512 so my thoughts are any objects built at 8192x8192 should be well out of scope of a new client entering the game, however...
Client 2 joins the game and the mission file it loads takes 2 minutes longer than the mission file that client 1 loaded before entering the game.
I added all these objects with MissionCleanup.add, is there another method of adding these objects that will keep them from being pushed out with the mission file when a client joins the game?
[edited]
Further testing and echos placed in the client and the server missiondownload.cs files gives me this info:
client 1 joins game with 12 ghosts - client 1 initiates a call that adds 1000 objects (with missioncleanup.add) at 8192x 8192y
client 2 joins game with 1012 ghosts
I added these echos to the common/client/missiondownload.cs to get the numbers above:
does this sound correct?
08/26/2005 (5:03 am)
I thought maybe I had visibility set too high. Not the case. Here is what is happening... I have a dedicated server and two clients. The mission file is basically empty with the exception of sky, terrain, spawn point and four objects, client 1 enters the game and downloads the mission file extremely fast. Client one initiates a build of 1000 objects at location 8192x 8192y, these objects are simple cubes with one texture (box.dif). Visibility and Mission area are only 512x512 so my thoughts are any objects built at 8192x8192 should be well out of scope of a new client entering the game, however...
Client 2 joins the game and the mission file it loads takes 2 minutes longer than the mission file that client 1 loaded before entering the game.
I added all these objects with MissionCleanup.add, is there another method of adding these objects that will keep them from being pushed out with the mission file when a client joins the game?
[edited]
Further testing and echos placed in the client and the server missiondownload.cs files gives me this info:
client 1 joins game with 12 ghosts - client 1 initiates a call that adds 1000 objects (with missioncleanup.add) at 8192x 8192y
client 2 joins game with 1012 ghosts
I added these echos to the common/client/missiondownload.cs to get the numbers above:
function onGhostAlwaysStarted(%ghostCount)
{
$ghostCount = %ghostCount;
$ghostsRecvd = 0;
echo("$ghostCount: " @ $ghostCount);
}
function onGhostAlwaysObjectReceived()
{
$ghostsRecvd++;
onPhase2Progress($ghostsRecvd / $ghostCount);
echo("$ghostRecvd: " @ $ghostRecvd);
}does this sound correct?
#3
I believe on mission load, regardless of scope, the client receives an initial update of all
objects / ghosts.
08/26/2005 (6:06 am)
Ben feel free to correct me if I'm wrong about the following statement.I believe on mission load, regardless of scope, the client receives an initial update of all
objects / ghosts.
#4
Where would I start looking or is it even possible?
08/26/2005 (6:52 am)
That would make sense. Any idea how I can circumvent this so that only the objects/ghosts in the area of the client joining the game are loaded at mission load?Where would I start looking or is it even possible?
#5
1) Adding objects to MissionCleanup SimGroup does -nothing- except for allowing for a very easy way to remove all the objects from the simulation when the mission is over--you delete the MissonCleanup group, and since it is a SimGroup, that also deletes everything within the group. It's just a trash collection technique, nothing more.
2) It sounds as if you have your objects set as ScopeAlways when you initially create them. Look for something like:
in the constructor for the object (or parent object). If you want them to be "normal" ghosts, it should just be:
Robert is partially correct above: during mission load, any object that is marked as ScopeAlways will be ghosted to the client logging in. Normal ghosted objects will not be sent until the player actually has his sim up and running, and is receiving normal networking updates, and then they are only ghosted if they meet the criteria for onCameraScopeQuery() of the client's control object.
08/26/2005 (1:47 pm)
Two things:1) Adding objects to MissionCleanup SimGroup does -nothing- except for allowing for a very easy way to remove all the objects from the simulation when the mission is over--you delete the MissonCleanup group, and since it is a SimGroup, that also deletes everything within the group. It's just a trash collection technique, nothing more.
2) It sounds as if you have your objects set as ScopeAlways when you initially create them. Look for something like:
mNetFlags.set(Ghostable | ScopeAlways);
in the constructor for the object (or parent object). If you want them to be "normal" ghosts, it should just be:
mNetFlags.set(Ghostable);
Robert is partially correct above: during mission load, any object that is marked as ScopeAlways will be ghosted to the client logging in. Normal ghosted objects will not be sent until the player actually has his sim up and running, and is receiving normal networking updates, and then they are only ghosted if they meet the criteria for onCameraScopeQuery() of the client's control object.
#6
Thanks!
08/26/2005 (8:52 pm)
Stephen that was the trick. I am using a custom interiorInstance.cc and mNetFlags was set to (Ghostable | ScopeAlways)... switching it to (Ghostable) only, was the solution.Thanks!
#7
08/27/2005 (4:38 pm)
Glad you got it working--and I have to give credit to Robert Blanchet and Pat Wilson (especially Pat who came up with the breadwinner answer), since they were the ones that were in the discussion in the office that helped us figure out what was going on for you!
#8
08/29/2005 (6:40 am)
Thanks Pat & Robert! I have been outsourcing my engine source modifications (to other TGE developers) and handling the scripts myself. When I run into odd issues that fall back to the engine source, it is great that you guys are on top of it and can and do point me in the right directions to modify my own source libraries. The forums here are hands down the best in all 3D Engine/ Game Engines available on the net regardless of the engine cost. Keep up the great work!
Associate Kyle Carter
Torque already scopes the minimal set of objects to each client. Is that what you want, or what you're trying to get rid of?
If I join a mission with a thousand objects, I'll only get the ones that are in scope for me ghosted to me.