Jump to content

Recommended Posts

Posted

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
Posted

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
Posted

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
Posted

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.

Posted

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.

Posted

The purpose of this hook is to let you process all objects in a map. What are you trying to do, make a progress bar?

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

Posted

@Josh, why not have it called as each model is loaded?

 

Because lots of people, like me use this to store the Entity* and Object* in maps/vectors. Wouldn't that make this not possible?

Posted

You can loop over the world->entities list after the map is loaded to do this. Also, you could still use that callback to add to a list. That wouldn't need to change.

Posted

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

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.

×
×
  • Create New...