I hope I'm not being a pain.
I been working on this next part trying to figure this all out. And when I built it I keep running into the same error. I put it together twice and failed each time.
And here is my codes that I changed.
Code:
/******************************************************************************/
class World : Net.World
{
static void Save(Cell<Net.Area> &net_area, ptr user)
{
if(Area *area=net_area.cast<Area>())area.saveChanges();
}
flt hmHeight(C Vec2 &xz, bool smooth=true)
{
if(Cell<Net.Area> *grid=T.grid.find(worldToArea(xz)))if(Area *area=grid.cast<Area>())return area.hmHeight(xz, smooth);
return 0;
}
World()
{
areaSize(AreaSize);
grid.replaceClass<Area>();
}
~World()
{
// save changes before closing
FCreateDirs(dataPath()+"Area");
grid.func(Save);
}
}
/******************************************************************************/
const bool UpdateWorldFormat=false; // use this to re-save all areas at server startup, and immediately close the server app after it
/******************************************************************************/
Area* GetArea(Net.World &world, C VecI2 &xy) {return world.grid.get(xy).cast<Area>();} // get world area casted to 'Area' class
/******************************************************************************/
void LoadWorld(C UID &world_id) // load all areas of 'world_id' world into memory
{
Net.World &world =*Net.Worlds(world_id);
Str area_dir= world.dataPath()+"Area";
for(FileFind ff(area_dir); ff(); )
if(!Contains(ff.name, '@'))
{
VecI2 xy=TextVecI2(ff.name);
if(Area *area=GetArea(world,xy))
{
area.load(ff.pathName());
//area.heightmap.fillHoles(UID(10409022, 1195409879, 1143007153, 3722121309));
if(UpdateWorldFormat)area.save(ff.pathName());
}
}
}
void SetWorldAreas()
{
Net.World &world=*Net.Worlds(MainWorldID);
int areas=Areas+1;
for(int x=-areas; x<areas; x++)
for(int y=-areas; y<areas; y++)if(Area *area=GetArea(world, VecI2(x, y)))area.heightmap.create(UID(10409022, 1195409879, 1143007153, 3722121309));
}
void LoadWorldFromEditor(C UID &world_id)
{
Net.World &world = *Net.Worlds(world_id);
Game.ObjMemx<CustStatic> Items;
Game.World.mode(Game.WORLD_MANUAL);
Game.World.setObjType(Items, OBJ_STATIC)
.New(EditorWorldID);
int areas=Areas+1;
for(int x=-areas; x<areas; x++)
for(int y=-areas; y<areas; y++)
{
VecI2 a(x, y);
Memc<Game.WorldManager.AreaState> areastates;
areastates.New().set(a, Game.AREA_INACTIVE);
Game.World.areaSetState(areastates, true);
Game.Area* the_area = Game.World.areaLoaded(a);
Area *data=GetArea(world, VecI2(x, y));
Image &temp_image = the_area.getData().height;
Image &temp_image2 = the_area.getData().material_map;
RectI ah = RectI(VecI2(0, 0), VecI2(HmRes+1, HmRes+1));
for(int hy=ah.min.y; hy<=ah.max.y; hy++)
for(int hx=ah.min.x; hx<=ah.max.x; hx++)
{
data.heightmap.setHeight(hx, hy, (the_area.data().height.pixelFI(hx, hy)+128));
data.heightmap.setMaterial(hx, hy, (the_area.getData().materials[temp_image2.pixel(hx, hy)]));
}
if(Items.elms())
{
REPA(Items)
{
VecI local(Items[i].pos().x, Items[i].pos().y, Items[i].pos().z);
SetObj(&world, local, Items[i].matrix().angle(), Items[i].get_ID());
}
}
}
Game.World.del();
}
void InitWorld()
{
Net.Worlds.replaceClass<World>();
SetWorldAreas();
LoadWorld(MainWorldID);
LoadEditorworld(MainWorldID);
}
void ShutWorld()
{
Net.Worlds.del(); // delete manually before resource caches are deleted (to have access to resource paths)
}
/******************************************************************************/
void ChangeHeight(Net.World *world, C VecI2 &pos, Image &delta) // must be synced with Client.SetHeightServer
{
if(world)
{
Image final; final.createSoft(delta.x(), delta.y(), 1, IMAGE_I8);
Memc<Client*> clients;
Memc<Ver > height_vers;
RectI rect_h=RectI(pos.x, pos.y, pos.x+delta.x()-1, pos.y+delta.y()-1)&WorldBoundsHeightmap,
rect_a(HeightmapToArea(rect_h.min), HeightmapToArea(rect_h.max));
for(int ay=rect_a.min.y; ay<=rect_a.max.y; ay++) // iterate areas
for(int ax=rect_a.min.x; ax<=rect_a.max.x; ax++)
{
VecI2 a(ax,ay);
if(Area *data=GetArea(*world, a))
{
bool modified=data.modified();
RectI ah =AreaToHeightmap(a), // area heightmap
ahi=ah&rect_h; // area heightmap intersection
for(int hy=ahi.min.y; hy<=ahi.max.y; hy++) // iterate area heightmap
for(int hx=ahi.min.x; hx<=ahi.max.x; hx++)
{
int ix=hx-rect_h.min.x, iy=hy-rect_h.min.y, // image
lx=hx- ah.min.x, ly=hy- ah.min.y; // local
data.heightmap.changeHeight(lx, ly, delta.pixel(ix, iy)-128);
final.pixel(ix, iy, data.heightmap.getHeight(lx, ly));
}
if(!modified)Server.areaModified(*data);
REPA(data.clients)clients.include(data.clients[i]);
height_vers.add(data.heightmap.ver.height_uid);
}else height_vers.New().zero();
}
File f; ServerWriteSetHeight(f, pos, final, height_vers); Distribute(clients, f);
}
}
/******************************************************************************/
void SetMaterial(Net.World *world, C VecI2 &pos, C MaterialPtr &material)
{
if(Cuts(pos, WorldBoundsHeightmap))
if(world)
{
int hm_res=HmRes;
VecI2 area (DivFloor(pos.x, hm_res), DivFloor(pos.y, hm_res)),
local ( Mod(pos.x, hm_res), Mod(pos.y, hm_res));
if(Area *data=GetArea(*world, area)) // center
{
bool modified=data.modified(); data.heightmap.setMaterial(local.x, local.y, material); if(!modified)Server.areaModified(*data); File f; ServerWriteSetMaterial(f, area, local, material, data.heightmap.ver.mtrl_uid); Distribute(data.clients, f); // send to clients
}
if(local.x<=0) // left
{
VecI2 a(area.x-1, area.y); if(Area *data=GetArea(*world, a))
{
bool modified=data.modified(); VecI2 l(hm_res, local.y); data.heightmap.setMaterial(l.x, l.y, material); if(!modified)Server.areaModified(*data); File f; ServerWriteSetMaterial(f, a, l, material, data.heightmap.ver.mtrl_uid); Distribute(data.clients, f); // send to clients
}
if(local.y<=0) // left back
{
VecI2 a(area.x-1, area.y-1); if(Area *data=GetArea(*world, a))
{
bool modified=data.modified(); VecI2 l(hm_res, hm_res); data.heightmap.setMaterial(l.x, l.y, material); if(!modified)Server.areaModified(*data); File f; ServerWriteSetMaterial(f, a, l, material, data.heightmap.ver.mtrl_uid); Distribute(data.clients, f); // send to clients
}
}
}
if(local.y<=0) // back
{
VecI2 a(area.x, area.y-1); if(Area *data=GetArea(*world, a))
{
bool modified=data.modified(); VecI2 l(local.x, hm_res); data.heightmap.setMaterial(l.x, l.y, material); if(!modified)Server.areaModified(*data); File f; ServerWriteSetMaterial(f, a, l, material, data.heightmap.ver.mtrl_uid); Distribute(data.clients, f); // send to clients
}
}
}
}
/******************************************************************************/
void SetGrass(Net.World *world, C Game.ObjParamsPtr &obj, C VecI2 &area_xy, Grass.Type.Instance &instance)
{
if(Cuts(area_xy, WorldBoundsAreas))
if(world)
if(Area *area=GetArea(*world, area_xy))
{
bool modified=area.modified();
area.grass.set(obj, instance); // set grass
if(!modified)Server.areaModified(*area);
File f; ServerWriteSetGrass(f, obj, area_xy, instance, area.grass.ver); Distribute(area.clients, f); // send to clients
}
}
/******************************************************************************/
void SetBlock(Net.World *world, C VecI &pos, C MaterialPtr &material)
{
if(Cuts(pos, WorldBoundsBlocks))
if(world)
if(Area *area=GetArea(*world, BlockToArea(pos)))
{
bool modified=area.modified();
VecI local(Mod(pos.x, BlocksDim), pos.y, Mod(pos.z, BlocksDim));
{
#pragma FIXME // check if can be performed
area.blocks.set(local.x, local.y, local.z, material); // set block
}
if(!modified)Server.areaModified(*area);
File f; ServerWriteSetBlock(f, pos, area.blocks.material(local), area.blocks.ver); Distribute(area.clients, f); // send to clients
}
}
/******************************************************************************/
void SetObj(Net.World *world, C VecI &pos, flt angle, C Game.ObjParamsPtr &obj)
{
if(Cuts(pos, WorldBoundsBlocks))
if(world)
if(Area *area=GetArea(*world, BlockToArea(pos)))
{
bool modified=area.modified();
Pos local(Mod(pos.x, BlocksDim), pos.y, Mod(pos.z, BlocksDim));
{
#pragma FIXME // check if can be performed
area.objects.set(local.x, local.y, local.z, *area, angle, obj); // set object
}
if(!modified)Server.areaModified(*area);
File f; ServerWriteSetObj(f, pos, area.objects.findObj(local), area.objects.ver); Distribute(area.clients, f); // send to clients
}
}
/******************************************************************************/
void SetGroundObj(Net.World *world, C VecI &pos, flt angle, C Game.ObjParamsPtr &obj)
{
if(Cuts(pos, WorldBoundsBlocks))
if(world)
if(Area *area=GetArea(*world, BlockToArea(pos)))
{
bool modified=area.modified();
Pos local(Mod(pos.x, BlocksDim), pos.y, Mod(pos.z, BlocksDim));
{
#pragma FIXME // check if can be performed
area.ground_objects.set(local.x, local.z, *area, angle, obj); // set object
}
if(!modified)Server.areaModified(*area);
File f; ServerWriteSetGroundObj(f, pos, area.ground_objects.findObj(local), area.ground_objects.ver); Distribute(area.clients, f); // send to clients
}
}
/******************************************************************************/
void SetObjState(Net.World *world, C VecI &pos, int obj_type, File &f)
{
if(world && Cuts(pos, WorldBoundsBlocks) && GetObjContainer(obj_type))
if(Area *area=GetArea(*world, BlockToArea(pos)))
{
Pos local(Mod(pos.x, BlocksDim), pos.y, Mod(pos.z, BlocksDim));
area.objects.state(local, obj_type, f, null); // set object state
}
}
/******************************************************************************/
void SetGroundObjState(Net.World *world, C VecI &pos, int obj_type, File &f)
{
if(world && Cuts(pos, WorldBoundsBlocks) && GetObjContainer(obj_type))
if(Area *area=GetArea(*world, BlockToArea(pos)))
{
Pos local(Mod(pos.x, BlocksDim), pos.y, Mod(pos.z, BlocksDim));
area.ground_objects.state(local, obj_type, f, null); // set object state
}
}
/******************************************************************************/
So the editor says .New(EditorWorldID); Is the problem on the first error.
LoadEditorworld(MainWorldID); Identifier not found.
If you would be so kind to explain to me where and why I'm going wrong I would really appreciate it.