Game Development Community

Drag objects into scope?

by Daniel Buckmaster · in Torque Game Engine · 10/10/2010 (6:14 am) · 5 replies

I've been playing around with networking and looking into scoping. It's my understanding that when an object is 'in scope' for a client, the client will have a ghost copy of that object, but not otherwise. Scoping is initiated in ShapeBase::onCameraScopeQuery, where we search the SceneGraph for objects we can see to be in scope.

Just suppose I had an object that required some other object to be in scope? For example, like a rider and mount. It makes sense that if the rider is scoped, it should force the mount to be scoped (though not necessarily the reverse, in some cases). Is there any way in TGE for an object to have the opportunity of adding other objects to scope automatically when it is in scope?

I ask because I'm working at an object-based inventory system, where instead of storing the inventory as a list of "item type" and "quantity", I'm actually retaining the objects themselves. It's lazy in a way - it means I don't have to add in all sorts of complicated logic for weapons with attachments, etc. - I can just dump the object in there and expect it to work. However, though I haven't got this far yet, I'm anticipating trouble when an inventory on the server contains items that aren't scoped to a client. The idea would be for a ShapeBase object that has an inventory to force its inventory into scope (the Inventory class is NetObject-derived currently), and the inventory then to force all the items it contains into scope.

Sound reasonable?

About the author

Studying mechatronic engineering and computer science at the University of Sydney. Game development is probably my most time-consuming hobby!


#1
10/10/2010 (7:36 am)
Hmm. Perhaps scopeToClient() the object in question?
#2
10/10/2010 (7:55 am)
Yeah, from script you could force it using scopeToClient. You could hold the inventory items in a simSet, then iterate over the simset scoping each item to the client individually.

Alternatively, in the engine, GameConnection::doneScopingScene() would be a good place to implement something that scopes the inventory of the connections control object to its associated client.
#3
10/10/2010 (12:08 pm)
Small note: this is all code-side.

ScopeToClient sounds fine, though I don't know how it works in code (I was planning on using NetConnection::objectInScope). I guess I'm not so much worried about the inventory of a control object itself (that can be implemented in onCameraScopeQuery), it's things like chests and corpses I'd worry about. I guess it'd be reasonably trivial to actually implement some special sort of 'I've accessed this inventory so scope it to me' routine. Since you probably won't be accessing more than one inventory at a time.

EDIT: Actually, I think that to save myself some time and effort, I may just leave inventories as a server-side object only. When an inventory is opened, it can send a commandToClient with a representation of itself that will allow the client to build a suitable GUI, manipulate it, then send back the changes.

EDIT: Additional justification for making the inventory system purely object-based. The objects still exist and do their stuff. So objects like, say, live grenades will behave correctly with little to no extra work. Score.
#4
10/12/2010 (1:15 pm)
acctually ScopeToClient will do exactly what you need just look at the console method's code on the engine side it will show you exactly how it works.

A quick search shows that ScopeToClient calls conn->objectLocalClearAlways(object);

where conn is our netconnection and object would be the netobject.

There is also
object->setScopeAlways();
#5
12/13/2010 (2:07 pm)
NetConnection* conn;
conn->objectInScope(obj);

This will directly drag obj to scope.