Jump to content

What are callbacks?


Clackdor
 Share

Recommended Posts

Callbacks are functions that you define (but the engine tells you the prototype for) and the engine calls. For example, collision. I would have assumed you were using physics collision for picking up coins but maybe not given your question.

 

In LE you can define a collision callback function and when 2 physics bodies collide the function will get called. Note that it'll be a repeated call until they don't collide anymore. The function parameters are filled in by the engine itself so you can work with the data. In the collision method it tells you the 2 entities that collided, and other information about the collision.

 

http://www.leadwerks.com/wiki/index.php?title=Entities#Callback_Functions

 

The crappy part about how LE does it's callbacks is that it's C oriented so if you are using C++ and heavy OO design, you most likely have to do some extra work to make a normal C function work for your design (Unless you are using EntityKeys for everything which I doubt). For the collision callback using C++ I often will use SetEntityUserData() inside the class that stores my object, say a GameObject, and assign the model a 'this' pointer. I then define a OnCollision() member function in my GameObject class. Now inside the global Collision callback I can call GetEntityUserData() on the LE entity, cast it to GameObject, check that the cast worked, and call it's virtual OnCollide. Anyway that might be when you get into it more smile.png

Link to comment
Share on other sites

For the coins, it is a simple distance calculation, so it is polled every single update. I recognize that callbacks can help my optimization and allow for some other really neat stuff.

 

I totally forgot about looking in the Wiki. I didn't realize there were examples there. I like your method of assigning the this pointer. I'm going to have to play around with that.

 

I'm specifically looking for how to ENTITYCALLBACK_DRAW so I can skip animation if the entity is not on screen. It's one of the things Josh recommended to me in a status last week.

Link to comment
Share on other sites

It's not entities themselves performing fuctions, think of it more like: instead of your code calling engine fuctions, the engine code is calling your functions :)

 

 

BTW Anyone know what's the story with ENTITYCALLBACK_DRAW today, is it finally working in c too ?. ..and why is there still no documentation on it ?

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...