Barthap
Member
|
World Loading when Player is far
I have strange problem with loading world when player is far from heightmap center. If I set player near world 0,0 position and build it, it runs normally in World Editor Play and in my game. But if I put player to city, which is far from heightmap 0 position (its center), it runs normally in World Editor Play, but in game Players.elms() = 0. I don't know why. Here's my code:
Quote: Game::World.init();
Game::World.setObjType(Statics, OBJ_STATIC)
.setObjType(Trees, OBJ_TREE)
.setObjType(Players, OBJ_PLAYER)
.setObjType(Items, OBJ_ITEM)
.setObjType(Chrs, OBJ_CHR)
.setObjType(Fireballs, OBJ_FIREBALL)
.setObjType(Teleports1, OBJ_TELEPORT1)
.setObjType(Horses, OBJ_HORSE)
.setObjType(Destructs, OBJ_DESTRUCTIBLE)
.setObjType(Triggers, OBJ_TRIGGER)
.setObjType(Lights, OBJ_LIGHT_POINT);
//Game::World.New("World/hapgame.world");
SG.New("World/hapgame.world"); //Similiar code to Multiple Worlds tutorial (SaveGame.New())
Loader.start(); //World loader (from tutorial)
if(!Players.elms())Exit("Players.elms is 0 (after Loader.start()"); //debug code
|
|
01-03-2011 08:13 PM |
|
Harry
Member
|
RE: World Loading when Player is far
I think that it's because world is loaded with streaming so if player is far away from update position it isn't loaded with world.
(This post was last modified: 01-03-2011 08:35 PM by Harry.)
|
|
01-03-2011 08:31 PM |
|
Barthap
Member
|
RE: World Loading when Player is far
Ok, so what should I do? I can't turn off streaming and turn it on after loading, because my world is very very big.
|
|
01-03-2011 08:36 PM |
|
Dynad
Member
|
RE: World Loading when Player is far
well the only thing you have is that the player in only in memory... i don't think you can do much about the loading/unloading of areas.. or you want to render the entire world but i think that you dont want that.
So what you can do is to create the player in c++ so you know the player is active at the time the game starts. Or if you use 1 player only just make 1 object player and use that.
There is always evil somewhere, you just have to look for it properly.
|
|
01-03-2011 09:08 PM |
|
Seba
Member
|
RE: World Loading when Player is far
Maybe look to Esenthel RPG code where you load game. There should be a code to move camera to Player.
|
|
01-03-2011 09:15 PM |
|
Dynad
Member
|
RE: World Loading when Player is far
The player gets created at a starting waypoint like i said.... so thats maybe the only option you have atm
There is always evil somewhere, you just have to look for it properly.
|
|
01-03-2011 09:42 PM |
|
Esenthel
Administrator
|
RE: World Loading when Player is far
Yes, you need to reposition your camera (and thus center of action) to player position
you can use waypoint to access the initial position, further positions should be manually remembered
|
|
01-04-2011 12:33 AM |
|
Barthap
Member
|
RE: World Loading when Player is far
ok, i'll try do something with it
|
|
01-04-2011 06:42 AM |
|
Barthap
Member
|
RE: World Loading when Player is far
I changed code, loading world and player is the same as in Esenthel RPG2, but the effect is the same: Players.elms is 0.
My code
Code:
Game::World.init();
Game::World.setObjType(Statics, OBJ_STATIC)
.setObjType(Trees, OBJ_TREE)
.setObjType(Players, OBJ_PLAYER)
.setObjType(Items, OBJ_ITEM)
.setObjType(Chrs, OBJ_CHR)
.setObjType(Fireballs, OBJ_FIREBALL)
.setObjType(Teleports1, OBJ_TELEPORT1)
.setObjType(Horses, OBJ_HORSE)
.setObjType(Destructs, OBJ_DESTRUCTIBLE)
.setObjType(Triggers, OBJ_TRIGGER)
.setObjType(Lights, OBJ_LIGHT_POINT);
//Game::World.New("World/hapgame.world");
SG.New("World/hapgame.world"); //SaveGame, same as in multiple worlds tutorial
Game::ObjParamsPtr playerCharacter; playerCharacter.require("Obj/Chr/Warrior/0.obj");
if(Game::Waypoint *waypoint=Game::World.getWaypoint("playerStart"))
{
if(waypoint->points())
{
Game::ObjParams obj;
obj.base(playerCharacter);
obj.type(true,"OBJ_PLAYER");
Game::World.objCreate(obj,Matrix().setScalePos(obj.scale(),waypoint->point(0).pos));
LogN("OK.");
}
else LogN("Waypoint \"playerStart\" has 0 points");
}
else LogN("Waypoint \"playerStart\" not found");
//...
Bool UpdateGame()
{
if(Loader.update()) return true; //BackgroundLoader update
//...
if(!Game::World.updated())
{
Loader.start();
}
else
{
Game::World.update(Cam.at);
//here players.elms is 0 too
}
return true;
}
My log.txt file shows only "OK."
(This post was last modified: 01-04-2011 03:35 PM by Barthap.)
|
|
01-04-2011 03:31 PM |
|
Harry
Member
|
RE: World Loading when Player is far
Uptade your world not with Cam.at but at point 0 position of wypoint and then in update you can use update with Cam.at. Or move camera to point 0 before first update.
(This post was last modified: 01-04-2011 03:42 PM by Harry.)
|
|
01-04-2011 03:39 PM |
|
Barthap
Member
|
RE: World Loading when Player is far
When you told me it, I did the same! It works now!
It's working code:
Code:
//in Init()
Game::World.init();
Game::World.setObjType(Statics, OBJ_STATIC)
.setObjType(Trees, OBJ_TREE)
.setObjType(Players, OBJ_PLAYER)
.setObjType(Items, OBJ_ITEM)
.setObjType(Chrs, OBJ_CHR)
.setObjType(Fireballs, OBJ_FIREBALL)
.setObjType(Teleports1, OBJ_TELEPORT1)
.setObjType(Horses, OBJ_HORSE)
.setObjType(Destructs, OBJ_DESTRUCTIBLE)
.setObjType(Triggers, OBJ_TRIGGER)
.setObjType(Lights, OBJ_LIGHT_POINT);
Game::World.New("World/yourworld.world"); //normal version
//SG.New("World/yourworld.world"); //multiple world tutorial version
//Player params
Game::ObjParamsPtr playerCharacter; playerCharacter.require("Obj/Chr/Warrior/0.obj");
//checking for waypoint "playerStart"
if(Game::Waypoint *waypoint=Game::World.getWaypoint("playerStart"))
{
if(waypoint->points())
{
//creating player on waypoint position
Game::ObjParams obj;
obj.base(playerCharacter);
obj.type(true,"OBJ_PLAYER");
Game::World.objCreate(obj,Matrix().setScalePos(obj.scale(),waypoint->point(0).pos));
Cam.setPosDir(waypoint->pos(0)); //set camera to player position
}
}
//in Update()
//at begin of Update() function
if(Loader.update()) return true; //background loader start (from tutorial)
//at the end of Update() function (or somewhere in middle)
if(!Game::World.updated()) // if current world hasn't yet been updated, it means it's a new or load game, so let background loader handle it
{
Loader.start();
}
else
{
Game::World.update(Cam.at);
//set camera
//update other things (clouds, water, mouse udpate
//some other
}
Using this code you have to add single waypoint in World Editor and name it "playerStart" there, where should be player start position. DON'T CREATE PLAYER OBJECT IN WORLD EDITOR. Just add only that waypoint there
(This post was last modified: 01-04-2011 03:52 PM by Barthap.)
|
|
01-04-2011 03:51 PM |
|