Jump to content

Map::Load Hook doesn't get called


martyj
 Share

Recommended Posts

My map loading hook is never called.

 

std::string mapName("Maps/test.map")
bool success = Map::Load(mapName, LoadMapHook);

void LoadMapHook(Entity* entity, Object* object)
{
System::Print("MapLoadHook");
App* app = App::GetApp();
app->RenderLoadingScreen();
}

 

Anyone else experiencing this issue?

 

 

-----------

 

Edit:

 

He hook is called after all the entities are loaded.

 

Is this because the hook is for creation of entities and not just Model loading?

 

How can we get a hook on model loading?

  • Upvote 1
Link to comment
Share on other sites

Works like:

 

void MapHook(Entity* entity, Object* extra)

{

LoadingScreen();

}

 

void Changemap(std::string map)

{

Map::Load(map, &MapHook)

}

 

Sill works, this is what I use. Not as dynamic as Lua I've found.

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

Hard to say with the little snippet of code bit it looks right. Is the map file name is correct?

 

This is taken from my code, it may help you, it works...

 

void StoreWorldPointsCallBack(Entity* entity, Object* extra)
{
long type = Utill::StringToType(entity->GetKeyValue("type"));

if (type != 0)
{
BaseObject *object = (BaseObject*)GameFactory::CreateObject(type, Vec3(), 0, false);

if (object) object->entity = entity;
}
}

GameWorld::GameWorld(std::string path) : BaseWorld(path)
{
if(Map::Load(path, StoreWorldPointsCallBack))
{
}
else System::Print("ERROR: Failed to load world");
}
}

trindieprod.png?dl=0spacer.png?dl=0steam-icon.png?dl=0twitter-icon.png?dl=0spacer.png?dl=0
Link to comment
Share on other sites

Also have you put a break point in debug mode in there to see if it's entered? If your expecting to show a loading screen during the load hook nothing will happen as Draw isn't called during that process. You need to draw a loading screen a frame before you load.

trindieprod.png?dl=0spacer.png?dl=0steam-icon.png?dl=0twitter-icon.png?dl=0spacer.png?dl=0
Link to comment
Share on other sites

Passing in the name of the function instead of a reference to the function works due to the fact that the function name is really just a reference to a section of memory of code to execute.

 

So the problem is that the function does get called, but not on Model loading, but after all the models have been loaded.

Link to comment
Share on other sites

Oh, I see it's because Josh doesn't declare the parameter as a function pointer.

 

#include <stdio.h>

 

void print();

void execute(void());

 

int main()

{

execute(print); // sends address of print

return 0;

}

 

void print()

{

printf("Hello!");

}

 

void execute(void f()) // receive address of print

{

f();

}

 

vs

 

#include <stdio.h>

 

void print();

void execute(void (*f)());

 

int main()

{

execute(&print); // sends address of print

return 0;

}

 

void print()

{

printf("Hello!");

}

 

void execute(void (*f)()) // receive address of print

{

f();

}

 

 

I'll have to test it out as well. How many entities do you have? Are you expecting CSG to call this because those won't.

Link to comment
Share on other sites

@Rick, that wouldn't work during map loading as it's done on the main thread.

 

Another hook would be nice. For Model::Load.

 

I'm not following why you are thinking that matters. The majority of people here only use the main thread anyway and you can still update the visuals inside the callback function if a progress bar is needed.

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