Crystal Space
Welcome, Guest. Please login or register.
August 30, 2014, 10:01:42 pm

Login with username, password and session length
Search:     Advanced search
9009 Posts in 2043 Topics by 8365 Members
Latest Member: Flypatty20
* Home Help Search Login Register
+  Crystal Space
|-+  Crystal Space Development
| |-+  Game Content Creation
| | |-+  loading between maps (xml world files)
« previous next »
Pages: [1] Print
Author Topic: loading between maps (xml world files)  (Read 4445 times)
Panch
Jr. Member
**
Posts: 80


View Profile Email
« on: January 29, 2008, 04:32:04 am »

Hello again Smiley

I'm trying to load between maps (xml world files), everything loads ok but when the engine goes to get the default render loop in engine.cpp it crashes. I thought I could just call engine->DeleteAll() to 'clear' the 3d engine of the previous map before loading the second but DeleteAll() doesn't seem to clear out the existing render loop. I don't want to use portals, I use those for some stuff but I had hoped to be able to load fairly seemlessly between xml world files.

Any ideas?

Thanks Smiley
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #1 on: January 29, 2008, 08:23:18 am »

Hello again Smiley

I'm trying to load between maps (xml world files), everything loads ok but when the engine goes to get the default render loop in engine.cpp it crashes. I thought I could just call engine->DeleteAll() to 'clear' the 3d engine of the previous map before loading the second but DeleteAll() doesn't seem to clear out the existing render loop. I don't want to use portals, I use those for some stuff but I had hoped to be able to load fairly seemlessly between xml world files.

Any ideas?

Thanks Smiley

Hmm, it shouldn't crash. Is there any way you can get a stack backtrace in a debugger? You will have to recompile CS in debug mode for that.

Greetings,
Logged
Panch
Jr. Member
**
Posts: 80


View Profile Email
« Reply #2 on: January 29, 2008, 03:09:04 pm »

Sure, I'm actually working in a Debug mode with the debug libraries. Where can I get you the information you need from MSVC 8? Also am I doing it the right way? Here is the code pieces:

First map load:
Code:
// Set up the application
bool Phage::Application()
{
...
  if (!LoadLevel1 ()) return ReportError ("Failed to load beginning level!");
 
  // Set the camera to our current sector and our maps start position
  view->GetCamera ()->SetSector (room);
  view->GetCamera ()->GetTransform ().SetOrigin (pos)

// Initialize our collider actor.
  if (!phageHero->SpawnHero(cdsys, engine, view)) return ReportError ("Failed to load Hero!");

..
}

Map init function:
Code:
// Load a level
bool Phage::LoadMap (csString level)
{
  // Clear the engine to load the new map
  engine->DeleteAll();
 
  // Change the VFS to the passed level string
  VFS->ChDir (level);
  // Report level loading
  Report (CS_REPORTER_SEVERITY_NOTIFY, "Level Loading ...");
  // Load the level file which is called 'world'.
  if (!loader->LoadMapFile ("world", false))
    ReportError("Error couldn't load level!");

  engine->Prepare();// (meter);
 
  // Determine starting position from the placement of the camera in the world map
  CamStartPos();

  return true; 
}

1st map:
Code:
// Load the 1st map
bool Phage::LoadLevel1()
{
...
// Load up the 1st level
level_name = "/lev/Phage_map1";
if (!LoadMap (level_name)) return false;

// Compute collision detection
  Report (CS_REPORTER_SEVERITY_NOTIFY, "Computing collision detection ...");
  csColliderHelper::InitializeCollisionWrappers (cdsys, engine);
 
  // Initialize the Muck monster
phageMuck = new Muck();
if(!phageMuck->CreateMuckFactory(GetObjectRegistry(), engine))
return ReportError("Failed to load the Muck factory!");

phageMuck->SpawnMuck(cdsys, engine, view, (pos + csVector3(0,0,5)), 1);
...
}

Load the 2nd map:
Code:
// Process the current frame
void Phage::ProcessFrame ()
{
...
if (LevelFlag)
  {
...
// Move the character if the console is closed
if (!console->IsVisible())
    {
...
if (phageKeyboard->randSteps == 50)
{
battleFlag = true;
if (!LoadLevel2 ()) return ReportError ("Failed to load second level!");
}
...
}

// Load the 2nd map
Code:
// Load the 1st map
bool Phage::LoadLevel1()
{
...
// Load up the 1st level
level_name = "/lev/Phage_battle_1";
if (!LoadMap (level_name)) return false;
...
}

When I try to load the 2nd map from within the 1st map, it crashes  on 'iRenderLoop* rl = s->GetRenderLoop ();' here in engine.cpp:
Code:
void csEngine::Draw (iCamera *c, iClipper2D *view, iMeshWrapper* mesh)
{
...
  iSector *s = c->GetSector ();
  if (s)
  {
    iRenderLoop* rl = s->GetRenderLoop ();
    if (!rl) rl = defaultRenderLoop;
    rl->Draw (rview, s, mesh);
  }
...
}
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #3 on: January 29, 2008, 03:13:35 pm »

As far as I can see the problem is that you are not updating the camera after loading the world again. The camera is pointing to a sector in the first world. If you then remove that sector and load a new world then the camera will point to nothing. That causes the crash. You must fix the camera so that it points to a sector in the new loaded world.

Greetings,
Logged
Panch
Jr. Member
**
Posts: 80


View Profile Email
« Reply #4 on: January 29, 2008, 05:49:16 pm »

Yup, that was it Smiley

Thank you very much!
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 7.232 seconds with 17 queries.