About Store Forum Documentation Contact



Post Reply 
World saving
Author Message
kulesz Offline
Member

Post: #1
World saving
If I create world with:

Code:
    Game::WorldSettings WorldSet;

    WorldSet.area_size = 128;
    WorldSet.hm_res = 129;
    WorldSet.path_res = 32;

    Game::World.init(Game::WORLD_MANUAL);
    Game::World.Create("data/world/mmo.world", WorldSet);
    Game::World.New("data/world/mmo.world");
    Game::World.setObjType(Items, OBJ_ITEM);
    Game::World.setObjType(Players, OBJ_PLAYER);
    Game::World.update(Cam.at);

And then change it area heightmap with:

Code:
        Vec Position(0,0,0);
        TerrainHeightmaps[Position.x][Position.z]=new Edit::Heightmap;
        TerrainMeshes[Position.x][Position.z]=new Mesh;
        TerrainHeightmaps[Position.x][Position.z]->create(32,Materials.ptrRequire("mtrl/grass/Grass0020_3_S.mtrl"),true,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);

        PhysBody *p_temp = new PhysBody;

        TerrainHeightmaps[Position.x][Position.z]->build(*TerrainMeshes[Position.x][Position.z], 0,10,false,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
        TerrainMeshes[Position.x][Position.z]->scaleMove(Vec(CHUNK_RESOLUTION,100,CHUNK_RESOLUTION), Vec(CHUNK_RESOLUTION*Position.x,0,CHUNK_RESOLUTION*Position.z));//Vec(128*i,0,128*j));
        TerrainBodies[Position.x][Position.z] = new PhysBody;
        TerrainBodies[Position.x][Position.z]->parts.New().createMesh(*TerrainMeshes[Position.x][Position.z]); // create physical body from 'mesh'

        Game::WorldManager::AreaState as1;
        as1.set(VecI2(Position.x,Position.z), Game::AREA_ACTIVE);
        Memc<Game::WorldManager::AreaState> ases;
        ases.add(as1);

        Game::World.areaSetState(ases, false);
        Game::World.areaActive(VecI2(Position.x,Position.z))->getData();
        Game::World.areaActive(VecI2(Position.x,Position.z))->data()->mshg.meshes(0).create(*TerrainMeshes[Position.x][Position.z]);

        Game::World.areaActive(VecI2(Position.x,Position.z))->data()->phys()=*TerrainBodies[Position.x][Position.z];
        Game::World.areaActive(VecI2(Position.x,Position.z))->data()->actor().create(*TerrainBodies[Position.x][Position.z]);

How should I save the world area data, so it would be visible after next run? Save and load doesn't work.
08-24-2011 07:38 PM
Find all posts by this user Quote this message in a reply
alkirah Offline
Member

Post: #2
RE: World saving
void save ( File &f , void (*save)(File &f)=NULL ); // save active world state to 'f' file, 'save'=pointer to fuction saving custom save data
Bool save (C Str &save_name, void (*save)(File &f)=NULL, Secure *secure=NULL); // save active world state to 'save_name' file, 'save'=pointer to fuction saving custom save data , false on fail


So it would be Game::World.save(X); where X is either a ptr to a file or a string.
08-25-2011 01:38 PM
Find all posts by this user Quote this message in a reply
kulesz Offline
Member

Post: #3
RE: World saving
But it doesn't save the changed areas :-/
08-25-2011 01:41 PM
Find all posts by this user Quote this message in a reply
kulesz Offline
Member

Post: #4
RE: World saving
Bump? smile
08-27-2011 08:02 AM
Find all posts by this user Quote this message in a reply
Harry Offline
Member

Post: #5
RE: World saving
In Game::World.save you can have also your custom save function:

Code:
void Save(File &f)
{
}

Game.World::Save(...,Save);

Did you try save in this function informations about areas?
08-27-2011 09:09 AM
Visit this user's website Find all posts by this user Quote this message in a reply
kulesz Offline
Member

Post: #6
RE: World saving
Well, I assumed, that World and it's area data are quite strong connected, so that by saving world, area information would also save.
It would be helpful, if Esenthel could write, which data (and how) should be written to completely save the world (including objects, like grass etc.). I'm just trying to generate entire terrain (with foliage, trees, water an so...) in realtime - and than I need to save it all, so it would look exactly the same after load.
08-27-2011 09:34 AM
Find all posts by this user Quote this message in a reply
kulesz Offline
Member

Post: #7
RE: World saving
Can't get it to work :-/
08-27-2011 07:18 PM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #8
RE: World saving
override Game::Area::Data::customSaveWant and return true
that's all
08-28-2011 11:42 AM
Find all posts by this user Quote this message in a reply
kulesz Offline
Member

Post: #9
RE: World saving
But when I do:
Code:
struct MyAreaData : public Game::Area::Data
{
    virtual Bool customSaveWant()
    {
        return true;
    }
};

and then in Init():
Code:
Game::World.setAreaData<MyAreaData>();

I get the errors during compilation:
Code:
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\esenthelengine\game\world.h(243): error C2664: 'MyAreaData::MyAreaData' : cannot convert parameter 1 from 'EE::Game::Area' to 'MyAreaData &'
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\esenthelengine\game\world.h(244) : see reference to function template instantiation 'EE::Game::Area::Data &EE::Game::WorldManager::NewAreaData<TYPE>(EE::Game::Area::Data *&,EE::Game::Area &)' being compiled
1>          with
1>          [
1>              TYPE=MyAreaData
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\esenthelengine\game\world.h(91) : see reference to function template instantiation 'EE::Game::WorldManager &EE::Game::WorldManager::_setAreaData<TYPE>(void)' being compiled
1>          with
1>          [
1>              TYPE=MyAreaData
1>          ]
1>          e:\ee\blockmap\source\main.cpp(219) : see reference to function template instantiation 'EE::Game::WorldManager &EE::Game::WorldManager::setAreaData<MyAreaData>(void)' being compiled
1>
(This post was last modified: 08-28-2011 11:50 AM by kulesz.)
08-28-2011 11:48 AM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #10
RE: World saving
you need to specify constructor

struct MyAreaData : public Game::Area::Data
{
MyAreaData(Area &area) : Game::Area::Data(area) {}
};
08-28-2011 11:50 AM
Find all posts by this user Quote this message in a reply
kulesz Offline
Member

Post: #11
RE: World saving
OK, it compiles and makes some files in the "test.world/Game/Area" directory, but after re-running application and doing
Code:
Game::World.load("data/world/test.world");
I can't see the areas I've generated before.
OK, got it... Just need to set the area states properly smile
(This post was last modified: 08-28-2011 12:13 PM by kulesz.)
08-28-2011 11:54 AM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #12
RE: World saving
also remember that 'World.load' is for loading world states (savegames, and not for loading worlds)
for loading worlds use World.New
08-29-2011 10:51 AM
Find all posts by this user Quote this message in a reply
kulesz Offline
Member

Post: #13
RE: World saving
OK, so saving area data: world heightmap (mesh), grass container, embedded objs (is there a way to add them from code?) and decals I should overriding customSaveWant - they will save automatically when something change?
What objects do save/load functions affects then?
08-29-2011 11:21 AM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #14
RE: World saving
World.save/load affect dynamic objects (Game::Obj, savegames)

customSaveWant - they will save automatically when something change?
they will save automatically always (not on change)

embedded objs (is there a way to add them from code?)
no
08-29-2011 11:27 AM
Find all posts by this user Quote this message in a reply
Post Reply