Jump to content

LE3 Collisions Hook


xtreampb
 Share

Recommended Posts

hey all i'm trying to add a collisions hook. Can someone help me with what i'm doing wrong

 

//.h file
void Break(Entity* entity0, Entity* entity1, float* position, float* normal, float speed);
//CPP file
this->Full->AddHook(Entity::CollisionHook, *Break)//my entity and adding the hook to my entity
void Stone::Break(Entity* entity0, Entity* entity1, float* position, float* normal, float speed)
{
   this->Full->Hide();
//blah blah blah
}

 

thank you for your help,

 

~Xtreampb~

bool Life()
{
 while(death=false)
 {
   if(death==true)
   return death;
 }
}

 

I have found the secret to infinite life

 

Did I help you out? Like my post!

Link to comment
Share on other sites

ok so i removed the prototype from my header and added it to the top of my CPP file. Still getting an error. I'm using OSX if that makes a difference.

bool Life()
{
 while(death=false)
 {
   if(death==true)
   return death;
 }
}

 

I have found the secret to infinite life

 

Did I help you out? Like my post!

Link to comment
Share on other sites

@xstreampb: Have to tried removing the prototype altogether? The problem maybe that your prototypes have not been declared with the correct namespace hence the error that you are getting (Re thread aggror supplied). Also you don't need a '*' before your Break function parameter in the AddHook function call.

"If our brains were simple enough for us to understand them, we'd be so simple that we couldn't." - Ian Stewart 1995.

Link to comment
Share on other sites

this is what i got in my CPP file

 



void Coll(Entity* entity0)//, Entity* entity1, float* position, float* normal, float speed)
{

}


this->Full->AddHook(Entity::UpdatePhysicsHook, Coll);

 

i switched to the update physics hook to emulate what is in the linked thread and still getting the fallowing error

 

"cannot initialize a paramater of type 'void *' with an lvalue of type 'void (Leadwerks::Entity *)'

bool Life()
{
 while(death=false)
 {
   if(death==true)
   return death;
 }
}

 

I have found the secret to infinite life

 

Did I help you out? Like my post!

Link to comment
Share on other sites

I always just considered

Try this one (not tested)

 

void Coll(void* data)
{
Entity* ent = reinterpret_cast<Entity*>(data);
ent->somemethod();
}
this->Full->AddHook(Entity::UpdatePhysicsHook, Coll);

Do NOT do this or you will mess up the call stack!

 

I always just considered void* to be a generic pointer with no type. If the function doesn't accept your function, you should be able to just cast it to (void*) and it should work.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Sorry josh but this statement is wrong and (void*) is a c cast, the code above is cleaner.

 

Passing data as void* and cast it back is valid and sometimes you dont have a choice, for example most winapi functions do it this way (beginthread, getwindowlong ...).

 

// Edit: your example compiles fine at my solution (picture attached)

 

 

this is what i got in my CPP file

 



void Coll(Entity* entity0)//, Entity* entity1, float* position, float* normal, float speed)
{

}


this->Full->AddHook(Entity::UpdatePhysicsHook, Coll);

 

i switched to the update physics hook to emulate what is in the linked thread and still getting the fallowing error

 

"cannot initialize a paramater of type 'void *' with an lvalue of type 'void (Leadwerks::Entity *)'

 

// Edit2:

 

Oh sorry.. OSX... didnt see that sad.png

 

But (void*) is still a bad choice wink.png

post-2196-0-20256600-1364832544_thumb.png

Link to comment
Share on other sites

so is this an OSX bug that josh needs to fix and i need to wait on or what? Also i have seen a bunch of different things (maybe it is all the same but i can't tell). What should I do? can anyone post a working work around with my code until the bug is fixed please. Lastly do i need to report this as a bug in the bug reporting section?

bool Life()
{
 while(death=false)
 {
   if(death==true)
   return death;
 }
}

 

I have found the secret to infinite life

 

Did I help you out? Like my post!

Link to comment
Share on other sites

so yea didn't work, wouldn't compile. Yes OS X uses GCC.

 

So i did some funny things. I'm not even sure what i did but this compiles...


void (*Coll)//, Entity* entity1, float* position, float* normal, float speed)
{

};


this->Full->AddHook(Entity::UpdatePhysicsHook, Coll);

 

however when the add hook is hit durring runtime it throws the following error

 

EXC_BAD_ACCESS(code=2, address=0x0)

 

So I have this pointer of a function that isn't initialized. So now i need to initialize my Coll function some how I believe. Can some one explain to me what i have done?

 

Per your requested admin. My code as it stands now.

 

my cpp file


#include "Stone.h"

#define MODEL_FOLDER "Models/Stone/"

//Collisions Function
void (*Coll)//, Entity* entity1, float* position, float* normal, float speed)
{

};

/*void mColl()
{

}*/

Stone::Stone()
{
this->Create();
}

Stone::~Stone()
{
this->Release();
}

void Stone::Create()
{
//load the models
this->Full=Model::Load(MODEL_FOLDER + string("stone_1.mdl"));
this->P1=Model::Load(MODEL_FOLDER + string("stone_1part01.mdl"));
this->P2=Model::Load(MODEL_FOLDER + string("stone_1part02.mdl"));
this->P3=Model::Load(MODEL_FOLDER + string("stone_1part03.mdl"));
this->P4=Model::Load(MODEL_FOLDER + string("stone_1part04.mdl"));
this->P5=Model::Load(MODEL_FOLDER + string("stone_1part05.mdl"));

//this->Full->AddHook(<#const int hookid#>, <#void *hook#>);
this->Full->AddHook(Entity::UpdatePhysicsHook, Coll);

//set the phy shapes
this->Full->SetShape(Shape::Load(MODEL_FOLDER + string("stone_1.phy")));
//this->P1->SetShape(Shape::Load(MODEL_FOLDER + string("stone_1part01.phy")));
//this->P2->SetShape(Shape::Load(MODEL_FOLDER + string("stone_1part02.phy")));
//this->P3->SetShape(Shape::Load(MODEL_FOLDER + string("stone_1part03.phy")));
//this->P4->SetShape(Shape::Load(MODEL_FOLDER + string("stone_1part04.phy")));
//this->P5->SetShape(Shape::Load(MODEL_FOLDER + string("stone_1part05.phy")));

//set the mass
this->Full->SetMass(1);
this->P1->SetMass(1);
this->P2->SetMass(1);
this->P3->SetMass(1);
this->P4->SetMass(1);
this->P5->SetMass(1);

//hide the broken pieces
this->P1->Hide();
this->P2->Hide();
this->P3->Hide();
this->P4->Hide();
this->P5->Hide();


}

unsigned long Stone::Release()
{
this->Full->Release();
this->P1->Release();
this->P2->Release();
this->P3->Release();
this->P4->Release();
this->P5->Release();

return 0;
}

void Stone::SetPosition(Vec3 mPos)
{

this->Full->SetPosition(mPos);
this->P1->SetPosition(mPos);
this->P2->SetPosition(mPos);
this->P3->SetPosition(mPos);
this->P4->SetPosition(mPos);
this->P5->SetPosition(mPos);

}

void Stone::SetRotation(Vec3 mRot)
{
this->Full->SetRotation(mRot);
this->P1->SetRotation(mRot);
this->P2->SetRotation(mRot);
this->P3->SetRotation(mRot);
this->P4->SetRotation(mRot);
this->P5->SetRotation(mRot);
}

void Stone::Break()//Entity* entity0, Entity* entity1, float* position, float* normal, float speed)
{
this->Full->Hide();
this->P1->Show();
this->P2->Show();
this->P3->Show();
this->P4->Show();
this->P5->Show();
}

 

my .h code


#include "Leadwerks.h"
using namespace Leadwerks;

#ifndef Kings_Stone_h
#define Kings_Stone_h

class Stone
{
public:
Stone();
~Stone();
void Create();//leadwerks constructor
unsigned long Release();//leadwerks deconstructor

void SetPosition(Vec3);
void SetRotation(Vec3);
void Break();

//void __cdecl Break();//Entity* entity0, Entity* entity1, float* position, float* normal, float speed);

private:
//the models
Model *Full;
Model *P1;
Model *P2;
Model *P3;
Model *P4;
Model *P5;

};

#endif

bool Life()
{
 while(death=false)
 {
   if(death==true)
   return death;
 }
}

 

I have found the secret to infinite life

 

Did I help you out? Like my post!

Link to comment
Share on other sites

so if type casting a void pointer to a function...how do i do that. I tried static_cast, dynamic_cast and reinterpret_cast. Also the implicit casts didn't work.

bool Life()
{
 while(death=false)
 {
   if(death==true)
   return death;
 }
}

 

I have found the secret to infinite life

 

Did I help you out? Like my post!

Link to comment
Share on other sites

It's generally bad practice to cast a function pointer to anything let alone a void pointer which is why your compilers are complaining. They either don't allow it or if they do it can lead to all kinds of instability errors. The error is in the function declaration of AddHook(...) which wrongly expects you to pass a function pointer as a void pointer. It's a bug and there's nothing anyone can do until Josh fixes the issue.

"If our brains were simple enough for us to understand them, we'd be so simple that we couldn't." - Ian Stewart 1995.

Link to comment
Share on other sites

It's generally bad practice to cast a function pointer to anything let alone a void pointer which is why your compilers are complaining. They either don't allow it or if they do it can lead to all kinds of instability errors. The error is in the function declaration of AddHook(...) which wrongly expects you to pass a function pointer as a void pointer. It's a bug and there's nothing anyone can do until Josh fixes the issue.

What data type would you suggest, and exactly what kind of errors are you describing? I don't see anything wrong with casting to a void*, it's just a pointer that takes either 32 or 64 bits of data.

 

 

Link to comment
Share on other sites

I just fallowed the updated tutorial that the admin linked to me in a chat (found here: http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/object/objectaddhook-r759)

 

It compiles, but at run time throws the fallowing error:

EXC_BAD_ACCESS(code=2, address=0x0)

 

Anyone got any advice from here?

bool Life()
{
 while(death=false)
 {
   if(death==true)
   return death;
 }
}

 

I have found the secret to infinite life

 

Did I help you out? Like my post!

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