Crystal Space
Welcome, Guest. Please login or register.
July 30, 2014, 11:05:09 pm

Login with username, password and session length
Search:     Advanced search
9005 Posts in 2043 Topics by 8260 Members
Latest Member: Lovelymae39
* Home Help Search Login Register
+  Crystal Space
|-+  Crystal Space Development
| |-+  Support
| | |-+  Loading between maps and back again in CEL
« previous next »
Pages: [1] Print
Author Topic: Loading between maps and back again in CEL  (Read 2184 times)
Panch
Jr. Member
**
Posts: 80


View Profile Email
« on: February 08, 2008, 03:02:06 pm »

Thanks Jorrit for the camera help on loading between maps in CS, is it possible to do the same in CEL without iLoader?

I load a map similar to the walktut, then later I try to remove that mapfile from the region, remove the regions and zone and create new ones to a new map file like so:

Code:
// Now get the iPcZoneManager interface so we can setup the level.
  region->RemoveMapFile(mapfile);
  zonemgr->RemoveAllRegions();
  zonemgr->RemoveAllZones();


  iCelZone* zone = zonemgr->CreateZone ("main");
  region = zonemgr->CreateRegion ("main");
  zone->LinkRegion (region);

iCelMapFile* battle_mapfile = region->CreateMapFile ();
battle_mapfile->SetPath ("/lev/phage_battle1");
battle_mapfile->SetFile ("world");



But the new map doesn't load, the old map doesn't unload for that matter as well.

What am I missing?

Thanks Smiley
Logged
Panch
Jr. Member
**
Posts: 80


View Profile Email
« Reply #1 on: February 13, 2008, 02:05:08 pm »

OK, well I think I'm close.

Load the CEL map with code from walktut:

Code:
bool Phage::LoadLevel ()
{
  LevelFlag = true;

  level_entity = pl->CreateEntity ("level", bl, "level_behave",
    "pcworld.zonemanager",
    CEL_PROPCLASS_END);
  if (!level_entity)
    return ReportError ("Error creating level entity!");

  // Now get the iPcZoneManager interface so we can setup the level.
  csRef<iPcZoneManager> zonemgr = CEL_QUERY_PROPCLASS_ENT (level_entity,
  iPcZoneManager);
  iCelZone* zone = zonemgr->CreateZone ("main");
  iCelRegion* region = zonemgr->CreateRegion ("main");
  zone->LinkRegion (region);

  iCelMapFile* mapfile = region->CreateMapFile ();
  mapfile->SetPath ("/lev/Phage_map1");
  mapfile->SetFile ("world");

  iCelMapFile* entitiesfile = region->CreateMapFile ();
  entitiesfile->SetPath ("/cellib/lev");
  entitiesfile->SetFile ("walktut_entities");

  return true;
}

Create the player (consequently this creates the sector as well):

Code:
bool Phage::CreatePlayer ()
{
  player_entity = pl->CreateEntity ("player", bl, "player_behave",
    "pccamera.old",
    "pcobject.mesh",
    "pcmove.linear",
    "pcmove.actor.standard",
    "pcinput.standard",
    "pctools.inventory",
    CEL_PROPCLASS_END);
  if (!player_entity)
    return ReportError ("Error creating player entity!");

  // Get the iPcCamera interface so that we can set the camera.
  pccamera = CEL_QUERY_PROPCLASS_ENT (player_entity, iPcCamera);
  // Get the zone manager from the level entity which should have been created
  // by now.
  csRef<iPcZoneManager> pczonemgr = CEL_QUERY_PROPCLASS_ENT (level_entity,
  iPcZoneManager);
  pccamera->SetZoneManager (pczonemgr, true, "main", "Camera");

  // Get the iPcMesh interface so we can load the right mesh
  // for our player.
  csRef<iPcMesh> pcmesh = CEL_QUERY_PROPCLASS_ENT (player_entity, iPcMesh);
  pcmesh->SetPath ("/cellib/objects");
  pcmesh->SetMesh ("test", "cally.cal3d");
  if (!pcmesh->GetMesh ())
    return ReportError ("Error loading model!");

  if (pczonemgr->PointMesh ("player", "main", "Camera"))
return ReportError ("Can't find region or start position in region!");
 

  // Get iPcLinearMovement so we can setup the movement system.
  pclinmove = CEL_QUERY_PROPCLASS_ENT (player_entity,
  iPcLinearMovement);
  pclinmove->InitCD (
  csVector3 (0.5f,0.8f,0.5f),
  csVector3 (0.5f,0.4f,0.5f),
  csVector3 (0,0,0));

  // Get the iPcActorMove interface so that we can set movement speed.
  pcactormove = CEL_QUERY_PROPCLASS_ENT (player_entity, iPcActorMove);
  pcactormove->SetMovementSpeed (3.0f);
  pcactormove->SetRunningSpeed (5.0f);
  pcactormove->SetRotationSpeed (1.75f);
  pcactormove->SetMouseMoveSpeed(0.5f, 0.25f);

  // Get iPcCommandInput so we can do key bindings. The behaviour layer
  // will interprete the commands so the actor can move.
  csRef<iPcCommandInput> pcinput = CEL_QUERY_PROPCLASS_ENT (player_entity,
  iPcCommandInput);
  // We read the key bindings from the standard config file.
  pcinput->Bind ("w", "forward");
  pcinput->Bind ("s", "backward");
  pcinput->Bind ("q", "rotateleft");
  pcinput->Bind ("e", "rotateright");
  pcinput->Bind ("m", "cammode");
  pcinput->Bind ("d", "drop");
  pcinput->ScreenCoordinates(false);

  return true;
}

Attempt to load a new map and place the player within the new region:
Code:
bool Phage::LoadLevel_Battle1()
{
LevelFlag = true;
#ifdef CS_DEBUG
Report (CS_REPORTER_SEVERITY_NOTIFY, "Attempting to load Battle 1 Map level ...");
#endif

// Create an entity for the battle map
battle_entity = pl->CreateEntity ("level", bl, "level_behave",
    "pcworld.zonemanager",
    CEL_PROPCLASS_END);

if (!battle_entity)
return ReportError ("Error creating level entity!");

  // Create a 2nd iPcZoneManager interface so we can setup the battle map
  csRef<iPcZoneManager> battle_zonemgr = CEL_QUERY_PROPCLASS_ENT (battle_entity,
  iPcZoneManager);
  iCelZone* battle_zone = battle_zonemgr->CreateZone ("Battle");
  iCelRegion* battle_region = battle_zonemgr->CreateRegion ("Battle");
  battle_zone->LinkRegion (battle_region);

// Create and load the battle map
iCelMapFile* battle_mapfile = battle_region->CreateMapFile ();
battle_mapfile->SetPath ("/lev/Phage_battle1");
battle_mapfile->SetFile ("world");

// Get the zone manager from the level entity which should have been created
  // by now.
  csRef<iPcZoneManager> pczonemgr = CEL_QUERY_PROPCLASS_ENT (battle_entity,
  iPcZoneManager);

// Set the camera to the new region in the battle map
pccamera->SetZoneManager(pczonemgr, true, "Battle", "Camera");

// Position the 'player' entity in the new region in the battle map
if (pczonemgr->PointMesh ("player", "Battle", "Camera"))
return ReportError ("Can't find region or start position in region!");

return true;
}

It all works and loads up runs ok, but it doesn't look the new sector in the region is ever created. The mesh is never moved to the new map. I also saw some code in Planeshift similar to:
Code:
pclinmove->GetLastPosition(pos, yrot, sector);

sector = engine->FindSector("room1");
pclinmove->SetPosition(csVector3(2,5,0), yrot, sector);

But again, the new sector is never loaded so this doesn't work either.

Any ideas?
Logged
Panch
Jr. Member
**
Posts: 80


View Profile Email
« Reply #2 on: February 13, 2008, 07:17:46 pm »

Figured it out!

Load the initial map:
Code:
bool Phage::LoadLevel ()
{
  LevelFlag = true;

  level_entity = pl->CreateEntity ("level", bl, "level_behave",
    "pcworld.zonemanager",
    CEL_PROPCLASS_END);
  if (!level_entity)
    return ReportError ("Error creating level entity!");

  // Now get the iPcZoneManager interface so we can setup the level.
  csRef<iPcZoneManager> zonemgr = CEL_QUERY_PROPCLASS_ENT (level_entity,
  iPcZoneManager);
  iCelZone* zone = zonemgr->CreateZone ("main");
  iCelRegion* region = zonemgr->CreateRegion ("main");
  zone->LinkRegion (region);

  iCelMapFile* mapfile = region->CreateMapFile ();
  mapfile->SetPath ("/lev/Phage_map1");
  mapfile->SetFile ("world");

  iCelMapFile* entitiesfile = region->CreateMapFile ();
  entitiesfile->SetPath ("/cellib/lev");
  entitiesfile->SetFile ("walktut_entities");

  return true;
}

Load the second map:
Code:
bool Phage::LoadLevel_Battle1()
{
float yrot;
iSector* sector;
LevelFlag = true;

#ifdef CS_DEBUG
Report (CS_REPORTER_SEVERITY_NOTIFY, "Attempting to load Battle 1 Map level ...");
#endif

// Create an entity for the battle map
battle_entity = pl->CreateEntity ("level", bl, "level_behave",
    "pcworld.zonemanager",
    CEL_PROPCLASS_END);

if (!battle_entity)
return ReportError ("Error creating level entity!");

  // Create a 2nd iPcZoneManager interface so we can setup the battle map
  csRef<iPcZoneManager> battle_zonemgr = CEL_QUERY_PROPCLASS_ENT (battle_entity,
  iPcZoneManager);
  iCelZone* battle_zone = battle_zonemgr->CreateZone ("Battle");
  iCelRegion* battle_region = battle_zonemgr->CreateRegion ("Battle");
  battle_zone->LinkRegion (battle_region);

// Create and load the battle map
iCelMapFile* battle_mapfile = battle_region->CreateMapFile ();
battle_mapfile->SetPath ("/lev/Phage_battle1");
battle_mapfile->SetFile ("world");

CamStartPos();

// Get the zone manager from the battle level entity
csRef<iPcZoneManager> pczonemgr = CEL_QUERY_PROPCLASS_ENT (battle_entity,
  iPcZoneManager);

// Set the camera to the new region in the battle map
pccamera->SetZoneManager(pczonemgr, true, "Battle", "Camera");

// Position our mesh in the new sector
pclinmove->GetLastPosition(pos, yrot, sector);
sector = engine->FindSector("Scene2");
pclinmove->SetPosition(pos, yrot, sector);

return true;
}

CamStartPos:
Code:
// Find a starting position
void Phage::CamStartPos()
{
  if (engine->GetCameraPositions ()->GetCount () > 0)
  {
  // There is a valid starting position defined in the level file.
iCameraPosition* campos = engine->GetCameraPositions ()->Get (0);
room = engine->GetSectors ()->FindByName (campos->GetSector ());
pos = campos->GetPosition ();
  }
  else
  {
// csPrintf("no start position");
// We didn't find a valid starting position. So we default
// to going to room called 'room' at position (0,0,0).
room = engine->GetSectors ()->FindByName ("room");
pos = csVector3 (0, 0, 0);
  }
  #ifdef CS_DEBUG
   if (!room)
ReportError("Can't find a valid starting position!");
#endif
}
Logged
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 8.257 seconds with 16 queries.