About Store Forum Documentation Contact



Post Reply 
Create Object on World Load Question
Author Message
SamNainocard Offline
Bronze Supporter

Post: #1
Create Object on World Load Question
Hi, I have a question about create object when loading new world, and I'm not sure that I'm doing this the right way.

This is sort of my current code.

Code:
// D.viewRange() is 100
Game.World.activeRange(D.viewRange()).mode(Game::WORLD_FULL)
       //.setObjType(all objects type)
        .New(UID(WORLD));
if(Game.World.settings().environment)Game.World.settings().environment->set();
if (ObjectPtr tmp=Objects.ptrRequire(UID(NON_CONST_OBJ)))
{
    Object obj; obj.base(tmp);
    // setting some params
    obj.sortParams()
    Vec pos=Game::World.findWaypoint(UID(WORLD))->points[0].pos; // ~Vec(17, 0.6, 19)
    pos.y=Game.World.hmHeight(pos.xz(), false);
    Matrix mat; mat.setPosScale(pos, obj.scale())
    mat.rotateYL(RandomF(PI2));   // random facing angle
    Game::World.objCreate(obj, mat);          
}
BackgroundLoader.start();

Is this the right way and time to create object on new world, or should I let the world finish loading before create an object? And how do I know that it is loaded and safe for dynamic object?

Because, sometimes pos.y is 0, which is probably fail to get Game.World.hmHeight (according to desc), and make that object failed to appear. (Logged position is Vec(17, 0, 19) but ObjMap.elms is 0, yet Game::World.objCreate() return 'true')

Edit: Mostly happens to Object that use obj.base(BASE_OBJ) though.
(This post was last modified: 07-19-2015 12:12 PM by SamNainocard.)
07-19-2015 12:02 PM
Find all posts by this user Quote this message in a reply
Zervox Offline
Member

Post: #2
RE: Create Object on World Load Question
always call object creation after a Game::World.update() is a rule I tend to use.
07-19-2015 02:58 PM
Find all posts by this user Quote this message in a reply
SamNainocard Offline
Bronze Supporter

Post: #3
RE: Create Object on World Load Question
I tested with Game.World.Update(VecZero) once, right before creating object seems to fix the problem.

I'll use that rule from now on, Thank you grin
(This post was last modified: 07-20-2015 10:08 AM by SamNainocard.)
07-20-2015 04:41 AM
Find all posts by this user Quote this message in a reply
Post Reply