Shard Posted May 20, 2010 Share Posted May 20, 2010 Ok, so I've got a small mess in code here.] Basically, I'm creating a trigger system where the player collides with a box body and activates the events that are stored with that Trigger. So below is the Trigger Class: struct Trigger { TVec3 pos; TSound *music; TSound *speech; string scene; TBody body; int usable; int characterLoadID; Trigger() { this->music = NULL; this->speech = NULL; } }; So when I create the box body, I SetEntityUserData(trigger->body,(byte*)trigger); and then SetEntityCallback(trigger->body,(byte*)TriggerCollision,ENTITYCALLBACK_COLLISION); And thats where I start to face my problems. I need to check if the player collides with the box body and then activate the ActivateTrigger Function inside my Level class. But it seems like I can't put the TriggerCollision Callback inside my Level handler class because when it tries to cast to the byte* it says it can't cast to a class bound function. So I had to remove it from my level class. But only the TriggerCollision Callback function can ActivateTrigger function, but that is inside the Level Class. Confused? I am. Hopefully this helps: What I Need Initializing: Load::LoadTriggers -> CollisionCallback -> Level::TriggerCollision Running: Level::TriggerCollision -> Level::ActivateTrigger What I'm Forced To Do Initializing: Load::LoadTriggers -> CollisionCallback -> TriggerCollision //Note that TriggerCollision isn't inside a class so that I can CollisionCallback to it Running: TriggerCollision -> ?? //I need Level::ActivateTrigger but I don't have anyway to access it! I'll attach my .h and .cpp files so that you can take a gander at it but I've only included the relevant files (Load and Level) so there will be some missing files. Problems.zip Quote Programmer/Engineer/Student www.reikumar.com 2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM C++ - Visual Studio Express - Dark GDK - Leadwerks SDK Link to comment Share on other sites More sharing options...
ZioRed Posted May 20, 2010 Share Posted May 20, 2010 Cannot you do the inverse? That is: add a Level variable and an Activate method in the Trigger class and then if you can call an ActivateTriggerCallback method on Level variable passing "this" from Trigger.Activate() Or also you could create a struct with Trigger and Level to pass to SetEntityUserData instead of trigger only. Quote ?? FRANCESCO CROCETTI ?? http://skaredcreations.com Link to comment Share on other sites More sharing options...
Shard Posted May 20, 2010 Author Share Posted May 20, 2010 Cannot you do the inverse? That is: add a Level variable and an Activate method in the Trigger class and then if you can call an ActivateTriggerCallback method on Level variable passing "this" from Trigger.Activate() Or also you could create a struct with Trigger and Level to pass to SetEntityUserData instead of trigger only. Thanks for your suggestions. I took your idea and added a static Level pointer to the Trigger class. That solved all my problems. On a lesser note, where did you get the images in your signature? Quote Programmer/Engineer/Student www.reikumar.com 2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM C++ - Visual Studio Express - Dark GDK - Leadwerks SDK Link to comment Share on other sites More sharing options...
Pixel Perfect Posted May 20, 2010 Share Posted May 20, 2010 Yes, the callback function is in global space so you need to get a pointer to the level class to it. You could either make a pointer available globally which the callback could just reference or pass the pointer as stored data to the trigger object using SetEntityUserData and access that from inside the callback routine. Quote Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++ Link to comment Share on other sites More sharing options...
ZioRed Posted May 20, 2010 Share Posted May 20, 2010 Thanks for your suggestions. I took your idea and added a static Level pointer to the Trigger class. That solved all my problems. Glad to help, I would prefer too the OOP way against the old way of a global variable On a lesser note, where did you get the images in your signature? I grabbed them from the Leadwerks forum PNG and C# exe icon (using IcoFX) Quote ?? FRANCESCO CROCETTI ?? http://skaredcreations.com Link to comment Share on other sites More sharing options...
Pixel Perfect Posted May 20, 2010 Share Posted May 20, 2010 Glad to help, I would prefer too the OOP way against the old way of a global variable Haha .. you guys make me laugh at times. If you're using GetEntityUserData to obtain a pointer to the trigger class instance then that, to all intents and purposes, is a global variable as its in global space and available to everyone Glad you have it working though! Are you still on target for your demo release Shard ? Quote Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++ Link to comment Share on other sites More sharing options...
ZioRed Posted May 21, 2010 Share Posted May 21, 2010 Haha .. you guys make me laugh at times. If you're using GetEntityUserData to obtain a pointer to the trigger class instance then that, to all intents and purposes, is a global variable as its in global space and available to everyone I wrote GetEntityUserData because Shard's code does not seem to be LEO: the "body" variable is declared as TBody and not Body Quote ?? FRANCESCO CROCETTI ?? http://skaredcreations.com Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.