Jump to content

Callbacks in LEO


Laurens
 Share

Recommended Posts

Hi,

 

Could someone please give me an example of how to create a callback using LEO? I currently have the following (non-functional) code:

 

ball.cpp

 

ball.SetCallback((byte*)paddle->EntityCollisionCallback, ENTITYCALLBACK_COLLISION);

 

paddle.h

 

void EntityCollisionCallback(TEntity source, TEntity destination, byte* position, byte* normal, byte* force, float speed);

 

Thanks!

Link to comment
Share on other sites

Since LEO is just a wrapper for LE, at it's core it's still uses LE's function to setup callbacks. It sucks, I know.

 

I have a way to map these to class members but it's probably just as easy to use the C style. Even the mapping way is done with the normal C callback, but inside that callback you map it back to the class function to call. Would have been cooler if LEO did that automatically.

Link to comment
Share on other sites

Well my code compiles now. A new issue has risen though. My code now looks like this:

 

ball.cpp

 

ball.SetCallback((byte*)Paddle::EntityCollisionCallback, ENTITYCALLBACK_COLLISION);

 

paddle.cpp

 

void _stdcall Paddle::EntityCollisionCallback(TEntity source, TEntity destination, byte* position, byte* normal, byte* force, float speed)
{
int type = GetEntityType(source);
}

 

The method is declared static in the header of the Paddle class.

 

When I run it, it detects a collision, calls the callback method between 8 to 16 times (approximately) (10 runs) without updating or rendering in between, and then craps out on framework.Update(), giving me an AccessViolationException.

 

Any idea what's going on here?

Link to comment
Share on other sites

If I comment out the

 

ball.SetCallback((byte*)Paddle::EntityCollisionCallback, ENTITYCALLBACK_COLLISION);

 

part, than everything runs perfectly fine. The paddle nor the ball gets destroyed at any point. If I set a breakpoint in the callback function, all variables also get properly set. No bad pointers whatsoever.

Link to comment
Share on other sites

Replacing the LEO function with the normal C function does not change it. I even replaced all LEO structures with the standard C structures and yet the problem persists :angry:

 

EDIT: Replacing framework.Update() with UpdateWorld() fixes the issue. I suppose this does lead to other problems since I am using Framework to render.

 

Putting it on the tracker.

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...