About Store Forum Documentation Contact
Donations:
309$/mo



Post Reply 
2Concept Thoughts -Link WorldObj and Classes
Author Message
dertar Offline
Member

Post: #1
2Concept Thoughts -Link WorldObj and Classes
Hi all Esenthel-Developer,

I am making progress in developing own classes and game elements.
Big thanks to Esenthel for ultra tidy code base and many tutorials!!
I have solved the following things, but am not sure, if i did it in a clean way. So i write pseudo code here to explain the two:

________________________________________________________
1. Linking World-Object to Ownclass-Obj 1:1 (Ownclass,Game::Item)
Create Objparams obparam (...
*ptr= Game::World.objCreate (obparam...)
Ownclass ownobj = new(myptr);

Now in ownobj.methods I can access th created Worldobj via myptr->actor/mesh().

Is that the way that is recommended? E.G. I need in update() always the Worldobj.pos(). Via the *ptr i can access it and derive game rules , calculate distances and more. All inside ownobj.method() and not like in many tutorial via Global Memc Container (REPA) Way.

________________________________________________________
2. Linking one Ownclass_chr1 with many Ownclass_obj2 (1:n)
Ownclass_chr1::Dervived Chr
{Ownclass2 *oc2;
Ownclass_obj2::Dervived Obj
{Ownclass1 *ptr[10];

Now in con-/destructor/updates I programmed the necessary Link/Unlink methods. Quick a hassle, but i got it clean, so that no access violations happen.

E.g. if Ownclass_obj2 dies (can have 1-10 dynamic relations), i need to
1.call a method on linked Ownclass_chr1
2.NULL the pointers on both sides
Only after that Ownclass_obj2 can die...

___________________________________________________________

If you know conceptual cleaner ways or if you have other solutions for those linking concepts, i am happy to hear.
03-19-2012 12:20 PM
Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #2
RE: 2Concept Thoughts -Link WorldObj and Classes
I think the Reference class is what you want. There is a tutorial for it.
03-19-2012 06:41 PM
Find all posts by this user Quote this message in a reply
dertar Offline
Member

Post: #3
RE: 2Concept Thoughts -Link WorldObj and Classes
Forgot to mention: I tried, but Using the Reference on an own derived class didnt work. (It seems to be build for Basic EE Classes).
03-20-2012 03:12 PM
Find all posts by this user Quote this message in a reply
fatcoder Offline
Member

Post: #4
RE: 2Concept Thoughts -Link WorldObj and Classes
1.
Code:
Ownclass* ownobj = CAST(Ownclass, Game::World.objCreate(obparam...));

2.
Use Reference.
03-20-2012 11:09 PM
Find all posts by this user Quote this message in a reply
dertar Offline
Member

Post: #5
RE: 2Concept Thoughts -Link WorldObj and Classes
@coder: Well, thats a normal Pointer declaration. With a dynamic class cast. Its the way i use it in code too. But then you have to handle all those above mentioned link/unlink events on your own.
Its not exactly the "Game::Obj::linkReferences" which is defined in EE.
03-21-2012 09:49 AM
Find all posts by this user Quote this message in a reply
fatcoder Offline
Member

Post: #6
RE: 2Concept Thoughts -Link WorldObj and Classes
Sorry, but I recommend you review the tutorials. Specifically the tutorials Extending Game Object Class and Object References. You are trying to do something in a complicated way that EE handles for you effortlessly.
03-22-2012 12:36 AM
Find all posts by this user Quote this message in a reply
Post Reply