コード例 #1
0
ファイル: main.cpp プロジェクト: cDoru/projectanarchy
// ---------------------------------------------------------------------------------
// Method: ResetWorld
// Notes: This function is used by the LoadGame function to get rid of all
//        serializeable entities.
// ---------------------------------------------------------------------------------
void ResetWorld()
{
  int i;
  int iNumOfAllEntities = VisBaseEntity_cl::ElementManagerGetSize();
  
  // send CLEANUP messages to all the entities that are about to be freed, so
  // that they have a chance of cleaning up whatever is necessary before the
  // world is destroyed
  for (i = 0; i < iNumOfAllEntities; i++)
  {
    VisBaseEntity_cl *pEnt = VisBaseEntity_cl::ElementManagerGet(i);
    if ( pEnt )
    {
      if ( pEnt->IsOfType(SerializeBaseEntity_cl::GetClassTypeId()) )
      {
        Vision::Game.SendMsg(pEnt, MSG_SER_CLEANUP, 0, 0 );
      }
    }
  }

  // now actually free all the serializeable entities
  for (i = 0; i < iNumOfAllEntities; i++)
  {
    VisBaseEntity_cl *pEnt = VisBaseEntity_cl::ElementManagerGet(i);
    if ( pEnt )
    {
      if ( pEnt->IsOfType(SerializeBaseEntity_cl::GetClassTypeId()) )
      {
        pEnt->DisposeObject();
      }
    }
  }
}
コード例 #2
0
///< Spawn the Ai Character and perform any setup we need to of them.
void RPG_AiSpawnPoint::OnSpawn()
{
  // only spawn if we haven't already. @todo: add support for spawning waves of characters.
  if(m_spawned)
  {
    return;
  }

  m_spawned = true;

  bool success = false;

  if(!m_prefabName.IsEmpty())
  {
    VisBaseEntity_cl* entity = RPG_GameManager::s_instance.CreateEntityFromPrefab(m_prefabName, GetPosition(), GetOrientation());
    
    if(entity)
    {
      if(entity->IsOfType(V_RUNTIME_CLASS(RPG_Character)))
      {
        m_character = static_cast<RPG_Character*>(entity);
      }

      success = true;
    }
  }
  else if(!m_spawnScript.IsEmpty())
  {
    VisBaseEntity_cl* entity = RPG_GameManager::s_instance.CreateEntityFromScript(m_spawnScript, GetPosition(), GetOrientation());
    VASSERT(entity);

    if(entity)
    {
      if(entity->IsOfType(V_RUNTIME_CLASS(RPG_Character)))
      {
        m_character = static_cast<RPG_Character*>(entity);
      }

      success = true;
    }
  }

  if(!success)  
  {
    hkvLog::Warning("Ai Spawner has no Prefab defined, and no valid Script definition!");
  }
}
コード例 #3
0
/// Finds and stores the level info object.
void RPG_GameManager::FindLevelInfo()
{
  // find the level info object
  VisBaseEntity_cl* levelInfo = Vision::Game.SearchEntity(RPG_LevelInfo::GetStaticKey());

  if(levelInfo &&
    levelInfo->IsOfType(V_RUNTIME_CLASS(RPG_LevelInfo)))
  {
    // store the level info object if we found one
    m_levelInfo = static_cast<RPG_LevelInfo*>(levelInfo);
  }
}
コード例 #4
0
/// Creates an entity from a Lua script definition.
VisBaseEntity_cl* RPG_GameManager::CreateEntityFromScript(const VString& scriptName, const hkvVec3& position, const hkvVec3& orientation)
{
  VScriptResourceManager* scriptManager = static_cast<VScriptResourceManager*>(Vision::GetScriptManager());

  VScriptResource* scriptRes = scriptManager->LoadScriptFile(scriptName);
  IVScriptInstance* script = scriptRes->CreateScriptInstance();
  VASSERT(script);

  if(script)
  {
    // get the entity class type to create
    char* className = NULL;
    script->ExecuteFunctionArg("GetEntityClassType", "*>s", &className);

    // create the entity
    VisBaseEntity_cl* entity = Vision::Game.CreateEntity(className, position);
    VASSERT(entity);

    if(entity)
    {
      entity->SetOrientation(orientation);

      // attach the script
      scriptManager->SetScriptInstance(entity, script);

      if(entity->IsOfType(V_RUNTIME_CLASS(RPG_BaseEntity)))
      {
        RPG_BaseEntity* rpgEntity = static_cast<RPG_BaseEntity*>(entity);

#if (RPG_SERIALIZATION_SCRIPT_PROPERTIES)
        rpgEntity->InitializeProperties();
#endif
        rpgEntity->PostInitialize();
      }

      return entity;
    }
  }

  return NULL;
}
コード例 #5
0
ファイル: main.cpp プロジェクト: cDoru/projectanarchy
VBool SaveGame(int iNum)
{
  if ( (iNum < 1) || (iNum > 4) )
  {
    // we just allow 4 save games
    return FALSE;
  }

  int i;
  char pszSaveFileName[FS_MAX_PATH];

  sprintf(pszSaveFileName,SAVEGAME_NAME, iNum);
  IVFileOutStream* pOut = Vision::File.Create(pszSaveFileName);
  // creating the file didn't work!
  if (!pOut)
  {
    return FALSE;
  }

  VArchive ar( pszSaveFileName, pOut, Vision::GetTypeManager() );

  // serialize global game data
  ar << ARCHIVE_START_TAG; 		      // magic number
  int iSavingVersion = Vision::GetArchiveVersion();
  ar << iSavingVersion;             // archive class version
  ar << g_iCurrentMap;              // current map number
  ar << Vision::GetTimer()->GetTime();		// current time

  // count entities
  SerializeBaseEntity_cl *pSerEnt = NULL;
  VisBaseEntity_cl *pEnt = NULL;
  int iFullCtr = 0;
  int iReCreateCtr = 0;
  int iNumOfAllEntities = VisBaseEntity_cl::ElementManagerGetSize();
  for (i = 0; i < iNumOfAllEntities; i++)
  {
    pEnt = VisBaseEntity_cl::ElementManagerGet(i);
    if ( pEnt )
    {
      if ( pEnt->IsOfType(SerializeBaseEntity_cl::GetClassTypeId()) )
      {
        pSerEnt = static_cast<SerializeBaseEntity_cl*>(pEnt);
        if ( pSerEnt->GetSerializeType() == SERIALIZE_FULL )
          iFullCtr++;
        else
          iReCreateCtr++;
      }
    }
  }

  // serialize number of entities
  ar << iReCreateCtr;
  ar << iFullCtr;

  hkvVec3 vTemp;

  // do ReCreate serialization of entities
  for (i = 0; i < iNumOfAllEntities; i++)
  {
    pEnt = VisBaseEntity_cl::ElementManagerGet(i);
    if ( pEnt )
    {
      if ( pEnt->IsOfType(SerializeBaseEntity_cl::GetClassTypeId()) )
      {
        pSerEnt = (SerializeBaseEntity_cl *) pEnt;
        if ( pSerEnt->GetSerializeType() == SERIALIZE_RECREATE )
        {
          char pszEntityParams[4000];
          GetEntityParameters( pSerEnt, pszEntityParams );
          VDynamicMesh* pMesh = pSerEnt->GetMesh();
          ar << pSerEnt->GetClassFullName() << pSerEnt->GetEntityKey();
          vTemp = pSerEnt->GetPosition();
          vTemp.SerializeAsVisVector (ar);
          vTemp = pSerEnt->GetOrientation();
          vTemp.SerializeAsVisVector (ar);
          const char *szFilename = pMesh ? pMesh->GetFilename() : NULL;
          ar << szFilename << pszEntityParams;
        }
      }
    }
  }

  // do full serialization of entities
  for (i = 0; i < iNumOfAllEntities; i++)
  {
    pEnt = VisBaseEntity_cl::ElementManagerGet(i);
    if ( pEnt )
    {
      if ( pEnt->IsOfType(SerializeBaseEntity_cl::GetClassTypeId()) )
      {
        pSerEnt = (SerializeBaseEntity_cl *) pEnt;
        if ( pSerEnt->GetSerializeType() == SERIALIZE_FULL )
        {
          ar << pSerEnt;
        }
      }
    }
  }

  // store end tag - useful to verify a valid archive
  ar << ARCHIVE_END_TAG;

  ar.Close();
  pOut->Close();

  g_SaveSlot[iNum-1].SaveScreenShotPreview();

  return TRUE;
}