martyj Posted May 10, 2016 Share Posted May 10, 2016 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? 1 Quote Link to comment Share on other sites More sharing options...
thehankinator Posted May 10, 2016 Share Posted May 10, 2016 I think it is the name of the function as a string. Quote Link to comment Share on other sites More sharing options...
Rick Posted May 10, 2016 Share Posted May 10, 2016 @hank that would be for Lua not C++ like he's using. Quote Link to comment Share on other sites More sharing options...
thehankinator Posted May 10, 2016 Share Posted May 10, 2016 @hank that would be for Lua not C++ like he's using. That's what I get for not reading the post, my mistake. Quote Link to comment Share on other sites More sharing options...
reepblue Posted May 10, 2016 Share Posted May 10, 2016 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. Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Rick Posted May 10, 2016 Share Posted May 10, 2016 Strange that it would even get called at all without passing the actual address of the function in with the &. Quote Link to comment Share on other sites More sharing options...
tjheldna Posted May 10, 2016 Share Posted May 10, 2016 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"); } } Quote Link to comment Share on other sites More sharing options...
tjheldna Posted May 10, 2016 Share Posted May 10, 2016 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. Quote Link to comment Share on other sites More sharing options...
martyj Posted May 10, 2016 Author Share Posted May 10, 2016 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. Quote Link to comment Share on other sites More sharing options...
Rick Posted May 10, 2016 Share Posted May 10, 2016 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. Quote Link to comment Share on other sites More sharing options...
Josh Posted May 10, 2016 Share Posted May 10, 2016 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? Quote 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 More sharing options...
martyj Posted May 10, 2016 Author Share Posted May 10, 2016 Not really a progress bar, but just show something on a loading screen. Maybe just the text taht's displayed in std::out "Loading somemodel.mat" Quote Link to comment Share on other sites More sharing options...
Rick Posted May 11, 2016 Share Posted May 11, 2016 @Josh, why not have it called as each model is loaded? 2 Quote Link to comment Share on other sites More sharing options...
Crazycarpet Posted May 11, 2016 Share Posted May 11, 2016 @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? Quote Link to comment Share on other sites More sharing options...
Rick Posted May 11, 2016 Share Posted May 11, 2016 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. Quote Link to comment Share on other sites More sharing options...
martyj Posted May 11, 2016 Author Share Posted May 11, 2016 @Rick, that wouldn't work during map loading as it's done on the main thread. Another hook would be nice. For Model::Load. Quote Link to comment Share on other sites More sharing options...
Rick Posted May 11, 2016 Share Posted May 11, 2016 @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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.