About Store Forum Documentation Contact



Post Reply 
Game::ObjMemx Question
Author Message
Salival Offline
Member

Post: #1
Game::ObjMemx Question
Hi Esenthel, I have a question about Game:: ObjMemx.

How can I link objects to a special ID? and access them as a std::map.

Current Map:
std:: map <unsigned int, ObjClass*> mObjs;

Add Object to map access id 55.
mObjs [55] = NewObjClass;

Get Object from access id 55.
ObjClass *pObj = mObjs [55];

Is it possible to do something similar or do I have to iterate through the entire objMemx to find matching objects?

Best Regards

-Salival
08-05-2010 09:44 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: Game::ObjMemx Question
why do you wanna use unsigned int ID?
you should link objects by Reference<>, there's a tutorial about it
08-05-2010 09:46 AM
Find all posts by this user Quote this message in a reply
Salival Offline
Member

Post: #3
RE: Game::ObjMemx Question
(08-05-2010 09:46 AM)Esenthel Wrote:  why do you wanna use unsigned int ID?
you should link objects by Reference<>, there's a tutorial about it

The reason I want to link them with the unsigned int is that it is their server object ID.

1) When an object is created, it should be linked to its object ID that it receives from the server.

2) I send my Object ID to the server and the server sends the object ID for all clients that are Connected. And when they receive this packet containing object ID and coordinates of the movement then I could easily access the object on the client side by ObjectMap [ObjectID]->MoveTo( coordinates ). And avoid looping through all objects to find the object ID and then perform the actual movement.

Do you understand what I mean?

Simple way I want to do it.

I just want to be able to access my objects as a std::map<unsigned int, Player*> PlayerMAP;

Player *Ply= new Player();
PlayerMAP[ObjectID] = Ply;

Movement from Server.

Vec Pos;
unsigned int pID;
Server->ParseMovement(pID, Pos);

PlayerMAP[pID]->MoveTo(Pos);
(This post was last modified: 08-05-2010 10:11 AM by Salival.)
08-05-2010 09:55 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: Game::ObjMemx Question
you can try
map<UInt, Reference<Game::Obj> >
or
map<UID, Reference<Game::Obj> >

where's the problem?
08-05-2010 10:05 AM
Find all posts by this user Quote this message in a reply
Salival Offline
Member

Post: #5
RE: Game::ObjMemx Question
(08-05-2010 10:05 AM)Esenthel Wrote:  you can try
map<UInt, Reference<Game::Obj> >
or
map<UID, Reference<Game::Obj> >

where's the problem?

I want to do something like this, But no idea how.

Game::ObjMemx<UInt, CPlayerObject> PlayerObjs;

Game::World.setObjType(PlayerObjs, OBJ_PLAYER);

Game::ObjParams &obj = *Game::Objs("Obj/chr/mesh.obj");
Game::World.objCreate(objectID, obj, Matrix(obj.scale(), Vec(0,0,0)));

CPlayerObject *Ply = PlayerObjs[objectID]

Understand how I want it to work? This is just a sample.
(This post was last modified: 08-05-2010 10:16 AM by Salival.)
08-05-2010 10:13 AM
Find all posts by this user Quote this message in a reply
Dynad Offline
Member

Post: #6
RE: Game::ObjMemx Question
Why so much trouble??

Just use it like this:

struct NetworkObject
{
Reference<Player> objRef;
};
Map<RakNetGUID,NetworkObject> People;


~Dynad

There is always evil somewhere, you just have to look for it properly.
08-05-2010 10:32 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #7
RE: Game::ObjMemx Question
and you can put the game object into the map in
void Game::Obj::create(Game::objparams&)
{
__super::create();
map[id]=this;
}

and

Bool Game::Obj::load()
{
if(__super::load())
{
map[id]=this;
}
}
08-05-2010 12:05 PM
Find all posts by this user Quote this message in a reply
Salival Offline
Member

Post: #8
RE: Game::ObjMemx Question
(08-05-2010 10:32 AM)Dynad Wrote:  Why so much trouble??

Just use it like this:

struct NetworkObject
{
Reference<Player> objRef;
};
Map<RakNetGUID,NetworkObject> People;


~Dynad

(08-05-2010 12:05 PM)Esenthel Wrote:  and you can put the game object into the map in
void Game::Obj::create(Game::objparams&)
{
__super::create();
map[id]=this;
}

and

Bool Game::Obj::load()
{
if(__super::load())
{
map[id]=this;
}
}

I know you can do in this way, I wondered if it was possible to put everything in the same map "ObjMemx", and not have to create a new map that keeps the Reference to the object. It is just unnecessary to have the same object in two different containers, Do you understand my point?

All I want to do is add the object to a ObjMemx with an objectID and then access the object in the ObjMemx using the objectID from server. Just as you take out an object from a std::map not std::vector like its now.

Is this possible or not?

Sample: ( I want to be enable to do like this )

The Game::ObjMemx acts like a std::vector

vector p;
p.push_back(obj)

p[index 0] = Object.

But I want to be enable to use it as a std::map, Like this.

1) The ObjMemx that hold the objects created.
Game::ObjMemx<unsigned int, CPlayerObject> CPlayerObjs;

2) Create a new object.
Game::ObjParams &obj = *Game::Objs("Obj/chr/mesh.obj");
Game::World.objCreate(ObjectID, obj, Matrix(obj.scale(), Vec(0,0,0)));

3) Now the new object will be placed in CPlayerObjs[ObjectID] NOT [CPlayerObjs.elms()-1];

4) Access the object.

CPlayerObject *pPly = &CPlayerObjs[ObjectID];

// Do stuff with object *pPly
(This post was last modified: 08-05-2010 12:44 PM by Salival.)
08-05-2010 12:27 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #9
RE: Game::ObjMemx Question
yeah I understand, but no, you can't do that with ObjMemx (mix it with ID's)
you need to use additional map (std::map or EE::Map)
08-05-2010 01:02 PM
Find all posts by this user Quote this message in a reply
Salival Offline
Member

Post: #10
RE: Game::ObjMemx Question
(08-05-2010 01:02 PM)Esenthel Wrote:  yeah I understand, but no, you can't do that with ObjMemx (mix it with ID's)
you need to use additional map (std::map or EE::Map)

Then I will make an Reference map like this:

typedef map<unsigned int, Reference<CPlayerObject>> ObjectPlayerMAP;

Thank you for your answer.

ps, Maybe you can create support for this so you do not have to have a one more map for it? It is just unnecessary to have the same object in two different containers :/
(This post was last modified: 08-05-2010 01:08 PM by Salival.)
08-05-2010 01:06 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #11
RE: Game::ObjMemx Question
the object is not in two different containers
in map it's only a pointer
08-05-2010 01:35 PM
Find all posts by this user Quote this message in a reply
Salival Offline
Member

Post: #12
RE: Game::ObjMemx Question
(08-05-2010 01:35 PM)Esenthel Wrote:  the object is not in two different containers
in map it's only a pointer

Yes that is true, But still two containers, You get my point.

Anyway thanks for your answer.
08-05-2010 01:38 PM
Find all posts by this user Quote this message in a reply
Post Reply