Topic: Brief outline of the source

Spekkie on May 16, 2013, 09:02:18 AM

Spekkie

  • Newbie
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Hi,

can someone please give me a brief outline of the sourcecode?
Mainly I try to figure out where I can find the game loop and where the monster.updateCommand() is being called...

Thanks in advance for any replies :)
« Last Edit: May 16, 2013, 09:18:09 AM by Spekkie »
Logged
  • Read 3117 times
  • Category Programming
Comments: 6

dezGusty on May 16, 2013, 12:13:06 PM
Reply #1

dezGusty

  • Artists
  • Full Member
  • *
  • Posts: 245
  • Karma: +8/-0
    • View Profile
Hi Spekkie,

I didn't investigate this until today, as it wasn't in my area of involvement, but here's what I managed to dig up regarding the calls to the monster.updateCommand: (bottom items call top items)

Creature::updateCommand
   Creature::calcAction (creature.cpp)
      Creature::update  (creature.cpp)
         Region::update (region.cpp) - object->update(time);
            World::update (world.cpp) - rit->second->update(time);
               Document::update (document.cpp) - World::getWorld()->update(time);

Hope this helps.
Logged

Spekkie on May 16, 2013, 02:47:18 PM
Reply #2

Spekkie

  • Newbie
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Hi Spekkie,

I didn't investigate this until today, as it wasn't in my area of involvement, but here's what I managed to dig up regarding the calls to the monster.updateCommand: (bottom items call top items)

Creature::updateCommand
   Creature::calcAction (creature.cpp)
      Creature::update  (creature.cpp)
         Region::update (region.cpp) - object->update(time);
            World::update (world.cpp) - rit->second->update(time);
               Document::update (document.cpp) - World::getWorld()->update(time);

Hope this helps.

Great, thanks! Helps a lot!

When do the different worlds and regions get created during the game? Are they all loaded from the start of the game or based on the saved game/new game actions?

BTW, does any one know why this is done this way in region.cpp:

Code: [Select]
// Durchmustern aller WorldObjects
for (iter =m_objects.begin(); iter!=m_objects.end(); )
{
object = iter->second;

if (object->getDestroyed()==true)
{
// Objekte selbststaendig loeschen darf nur der Server
if (World::getWorld()->isServer())
{
// nur Nichtspieler Objekte loeschen
if (object->getType() != "PLAYER")
{
DEBUGX("Objekt gelöscht: %i \n",object->getId());

++iter;
object->destroy();
bool succ = deleteObject(object);
if (succ)
{
delete object;
continue;
}
}
else
++iter;
}
else
{
++iter;
}
}
else
{
++iter;
}

}

for (iter =m_objects.begin(); iter!=m_objects.end(); ++iter)
{
object = iter->second;
if (object->getDestroyed()!=true)
{
// Polymorpher Funktionsaufruf
object->update(time);
}
}

Since it seems to me that this could also be done in just 1 for-loop:
Code: [Select]
for (iter =m_objects.begin(); iter!=m_objects.end(); ++iter)
{
object = iter->second;

if (object->getDestroyed()==true)
{
// Objekte selbststaendig loeschen darf nur der Server
if (World::getWorld()->isServer())
{
// nur Nichtspieler Objekte loeschen
if (object->getType() != "PLAYER")
{
DEBUGX("Objekt gelöscht: %i \n",object->getId());

object->destroy();
bool succ = deleteObject(object);
if (succ)
{
delete object;
continue;
}
}
}
}
else
{
// Polymorpher Funktionsaufruf
object->update(time);
}

}
Or am I missing something here?
« Last Edit: May 16, 2013, 03:51:15 PM by Spekkie »
Logged

dezGusty on May 16, 2013, 09:12:51 PM
Reply #3

dezGusty

  • Artists
  • Full Member
  • *
  • Posts: 245
  • Karma: +8/-0
    • View Profile
The code you wrote is similar, but not identical. Notice that the "object" var. is pointing to the previous iterator. I guess there was an issue with deleting an object while an iterator was still using it. Not sure though.
Logged

Spekkie on May 20, 2013, 11:28:32 AM
Reply #4

Spekkie

  • Newbie
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
The code you wrote is similar, but not identical. Notice that the "object" var. is pointing to the previous iterator. I guess there was an issue with deleting an object while an iterator was still using it. Not sure though.

Right, that's true. But then again why would you want to iterate twice over the same objects... Because in the first loop only the iterator gets updated if the object isn't scheduled for destruction, while you then could easily execute the body of the second loop...
Logged

protogenes on May 24, 2013, 11:06:27 AM
Reply #5

protogenes

  • Administrator
  • Jr. Member
  • *****
  • Posts: 59
  • Karma: +5/-0
    • View Profile
1. You have to increment the iterator (iter++) before you delete the object. Because the entry in the map (m_objects), which iter references, will be gone after the object was removed, thus rendering iter invalid.
2. Regarding the split in two for-loops, I believe it depends on the way updates or object destructions are handled. I assume it is necessary to delete all invalid objects (and eventually remaining references between objects), before you actually update the remaining valid elements.

protogenes
« Last Edit: June 04, 2013, 06:25:13 AM by protogenes »
Logged

Spekkie on May 30, 2013, 12:33:15 PM
Reply #6

Spekkie

  • Newbie
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Is there a way to load a specific environment for test purposes?
Logged