About Store Forum Documentation Contact
Donations:
309$/mo



Post Reply 
References
Author Message
Harry Offline
Member

Post: #1
References
I have my own Mission class where I keep pointers to objects which are create during game (weapons, missions pointers etc.). But when I'm too far from this objects they are flush and don't show again. So I think I have to use Reference. And here is my question. Is there any option to create this reference's in my Mission class or should it be in one of Game::Obj or derivatives? If yes so then what with linkReferences function which is only in Game::Obj. Or should I base on Game::Obj with my class?
(This post was last modified: 06-30-2011 10:07 AM by Harry.)
06-30-2011 10:01 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #2
RE: References
you can store Reference in custom Mission class
you can call linkReferences from Mission::reference_obj after travelling each 5-10 meters for example (when there's possibility that new objects were loaded to the scene)
06-30-2011 12:25 PM
Find all posts by this user Quote this message in a reply
Harry Offline
Member

Post: #3
RE: References
Ok thanks, it works as I want smile

Edit: I want create references to another objects and when I create reference to Item object and go away from this object and then came back this code:

Code:
if(item.valid())
{
    ... draw text above item
}

doesn't work because item.valid() is false but in another instruction (checking if object is in players left hand) it works (I don't use check if object is valid). What could be the issue?

Here is link codes:

Code:
if(Dist(pos,Players[0].pos())>=5)
    {
        sign.link();
        item.link();
        stat.link();
        chr .link();
        pos=Players[0].pos();
    }

They are in Mission::update method.
06-30-2011 07:19 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Harry Offline
Member

Post: #4
RE: References
I tried to reconstruct similar situation in tutorial Object References and I've got similar problem. This is the steps which I did:

1. Scroll the camera to maximum value (in tutorial 100).
2. Move the camera in any direction (text 'My desired item is at...' disappear).
3. Move the camera back to their start position - thext above screen shows 'My desired item is gone' but item is still there.

Is it some bug in engine?
(This post was last modified: 07-02-2011 11:54 AM by Harry.)
07-02-2011 11:49 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #5
RE: References
Thanks, I'm fixing the tutorial.

As for linking custom global references (Mission.obj_reference) please use Game::World.link_references from the next SDK, like this:

Code:
void LinkGlobalReferences()
{
  Mission.obj_reference.link();
}
Bool Init()
{
   Game::World.link_references=LinkGlobalReferences;
}

please no longer use what I suggested before (calling link after travelling some distance "if(Dist(pos,Players[0].pos())>=5)")

I'll upload the fix in few minutes.
07-03-2011 07:22 PM
Find all posts by this user Quote this message in a reply
Harry Offline
Member

Post: #6
RE: References
Ok thanks, it works prefectly now smile
07-03-2011 09:00 PM
Visit this user's website Find all posts by this user Quote this message in a reply
dertar Offline
Member

Post: #7
RE: References
Got a question to the linking as well. I get pointer exceptions after a while.
I might be missing the part, when to call linkReferences(). Or it might be connected with the fact, that i am linking to derived Class. STRUCT(Bomb , Game::Item) .

1. How often is linkReferences() need to be called?
2. How can i link to a derived base Class?
a. Compiler didnt Allow
Reference<Bomb> targetb;
b. Compiler only Allow base Classes
Reference<Game::Item> targetb;

[/align]
// in AI Header
virtual void linkReferences();
Reference<Game::Item> targetb; // define reference to Game::Item

// Create the Link dynamic
REPA(Bombs) {
Bomb &b=Bombs[i];
moveTo(b.pos());
targetb=&Bombs[i]; // create the link to derived Game::Item->Bomb
b.curAttracting+=1; // Use link for operation on linked obj
time_to_update_action=RandomF(0.2f, 0.4f);
}

// Check if link exist
if(targetb.valid()) {
moveTo(targetb().pos());
time_to_update_action=RandomF(0.2f, 0.4f);
} else // link gone
{
}

// Deconstruct Link when AI dies
void AI::die()
{
if(targetb.valid()) {
// point to derived class bomb, Reference is defined as Game::Item
if(Bomb *myb=CAST(Bomb, &targetb())) {
myb->curAttracting-=1; // Use Link for operation on linked obj
}
}
super::die();
targetb.clear(); // clear Link
}
03-18-2012 10:32 AM
Find all posts by this user Quote this message in a reply
kasinova Offline
Member

Post: #8
RE: References
I am actually having that same problem! I have a Player class derived from Game::Chr and when I want to make a reference, my compiler gives me:

1>c:\esenthelenginesdk\game\user header\prop.h(15): error C2065: 'Player' : undeclared identifier
1>c:\esenthelenginesdk\game\user header\prop.h(15): error C2923: 'EE::Reference' : 'Player' is not a valid template type argument for parameter 'TYPE'
1>c:\esenthelenginesdk\game\user header\prop.h(38): error C2662: 'EE::Reference<TYPE>::link' : cannot convert 'this' pointer from 'EE::Reference' to 'EE::Reference<TYPE> &'
1> Reason: cannot convert from 'EE::Reference' to 'EE::Reference<TYPE>'
1> Conversion requires a second user-defined-conversion operator or constructor
1>c:\esenthelenginesdk\game\user source\prop.cpp(25): error C2512: 'EE::Reference' : no appropriate default constructor available

is there a way to make a reference to a derived class?
07-12-2013 05:11 AM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #9
RE: References
Hi,

this should work OK as many of EE tutorials/games do that.

Are you using latest version of EE? is it 2.0/1.0?
Please try updating it first.

Thanks
07-16-2013 12:47 PM
Find all posts by this user Quote this message in a reply
kasinova Offline
Member

Post: #10
RE: References
For now, 1.0.
I updated it and still the lengthy error! As far as the tutorial for Object References, you extended Game::Chr but for the Reference, it is still just a Game::Item reference.
07-16-2013 09:15 PM
Find all posts by this user Quote this message in a reply
kasinova Offline
Member

Post: #11
RE: References
OMG! ok nevermind! so I wasn't including the struct in main.h and now it's recognizing it as a reference object
07-16-2013 10:16 PM
Find all posts by this user Quote this message in a reply
Post Reply