Esempio n. 1
0
static Vec2f GetRoomSize(int dest)
{
  // Expensive - only done when we are definitely changing room
  std::string filename = MakeRoomFilename(dest);
  File f;
  if (!f.OpenRead(filename))
  {
    Assert(0);
    return Vec2f();
  }
  std::string s;
  if (!f.GetDataLine(&s))
  {
    Assert(0);
    return Vec2f();
  }
  GameObject* go = TheGameObjectFactory::Instance()->Create(s);
  Room* room = dynamic_cast<Room*>(go);
  if (!room)
  {
    Assert(0);
    return Vec2f();
  }
  room->Load(&f);
  return room->GetSize();
}
Esempio n. 2
0
bool HelpText::Load(const std::string& filename)
{
  File f;
  if (!f.OpenRead(filename))
  {
    f.ReportError("Failed to load help text.");
    return false;
  }  
  int numLines = 0;
  if (!f.GetInteger(&numLines))
  {
    f.ReportError("Expected number of lines for helptext.");
    return false;
  }
  std::string s;
  for (int i = 0; i < numLines; i++)
  {
    if (!f.GetDataLine(&s))
    {
      std::string e = "Expected line ";
      e += ToString(i);
      e += " of helptext.";
      f.ReportError(e);
      return false;
    }
    m_lines.push_back(s);
  }
  return true;
}
Esempio n. 3
0
bool PlayerInfo::Load()
{
  // FileExists doesn't append File::Root
  if (FileExists(File::GetRoot() + m_filename))
  {
#ifdef PI_DEBUG
std::cout << "Loading player info " << m_filename << "...\n";
#endif
  }
  else
  {
#ifdef PI_DEBUG
std::cout << "Loading player info " << m_filename << " doesn't exist! - - it's a new file\n";
#endif
    // We assume the player is new and has not saved any player info yet - this is OK.
    return true;
  }

#ifdef PI_DEBUG
std::cout << "Loading player info " << m_filename << "...\n";
#endif

  File f;
  if (!f.OpenRead(m_filename))
  {
    return false;
  }
  int num = 0;
  if (!f.GetInteger(&num))
  {
    return false;
  }
  for (int i = 0; i < num; i++)
  {
    std::string s;
    if (!f.GetDataLine(&s))
    {
      return false;
    }

#ifdef PI_DEBUG
std::cout << " Got line: " << s << "\n";
#endif

    Strings strs = Split(s, ',');
    if (strs.size() != 2)
    {
      f.ReportError("Bad line in player info: " + s);
      return false;
    }
    PISetString(strs[0], strs[1]);
  }
#ifdef PI_DEBUG
std::cout << "End of player info load.\n";
#endif

  return true;
}
Esempio n. 4
0
bool PlayerInfoManager::Load()
{
#ifdef PI_DEBUG
std::cout << "PlayerInfoManager: loading players...\n";
#endif

  if (!FileExists(File::GetRoot() + PIM_FILENAME))
  {
#ifdef PI_DEBUG
std::cout << "No playerinfo file exists to load.\n";
#endif
    return true;
  } 
  File f;
  if (!f.OpenRead(PIM_FILENAME))
  {
#ifdef PI_DEBUG
std::cout << "Player info file does exist but we couldn't open it for reading!\n";
#endif
    return false;
  }
  int numPlayers = 0;
  if (!f.GetInteger(&numPlayers))
  {
    f.ReportError("Expected num players"); 
    return false; 
  }

#ifdef PI_DEBUG
std::cout << "PlayerInfoManager: opened file, got " << numPlayers << " as number of players.\n";
#endif
  for (int i = 0; i < numPlayers; i++)
  {
    std::string s;
    if (!f.GetDataLine(&s))
    {
      f.ReportError("Expected player name " + ToString(i) + " of " + ToString(numPlayers));
      return false;
    }

    unsigned int ts;
    if (!f.GetInteger((int*)&ts))
    {
      f.ReportError("Expected timestamp for player " + s);
      return false;
    }

#ifdef PI_DEBUG
std::cout << "PlayerInfoManager: player " << i << " name: \"" << s << "\" timestamp: " << ts << "\n";
#endif
    m_map[s] = TimestampPlayerInfo(ts, (PlayerInfo*)0); 
  }

  return true;
}
Esempio n. 5
0
bool SolidComposite::Load(const std::string& filename)
{
  File jf;
  if (!jf.OpenRead(filename))
  {
    jf.ReportError("Couldn't open file.");
    return false;
  }

  m_name = filename;

  // Get the number of components
  int components = 0;
  if (!jf.GetInteger(&components))
  {
    jf.ReportError("Expected number of components.");
    return false;
  }
  
  // Load each component.
  for (int i = 0; i < components; i++)
  {
    // Get name of component. We don't know whether it's a leaf or composite.
    std::string strComponent;
    if (!jf.GetDataLine(&strComponent))
    {
      jf.ReportError("Expected component name.");
      return false;
    }
    
    PSolidComponent pChild = SolidComponent::LoadSolid(strComponent);
    if (!pChild.GetPtr())
    {
      std::string error = "Failed to load composite: " + strComponent;
      jf.ReportError(error);
      return false;
    }

    if (!pChild->LoadOrientation(&jf))
    {
      jf.ReportError("Failed to load orientation.");
      return false;
    }

    m_children.push_back(pChild);
  }

  return true;
}
Esempio n. 6
0
bool ObjectManager::Load()
{
#ifdef YES_USE_CACHE

  File f;
  if (!f.OpenRead(CACHE_FILENAME))
  {
    return false;
  }
  if (!f.GetDataLine(&m_timestamp))
  {
    f.ReportError("Object create cache: expected timestamp");
    return false;
  }
  int numObjs = 0;
  if (!f.GetInteger(&numObjs))
  {
    f.ReportError("Object create cache: Expected num objects");
    return false;
  }
//std::cout << "Object create cache: got " << numObjs << " objs!\n";

  for (int i = 0; i < numObjs; i++)
  {
    PObject obj = new Object;
    if (!obj->Load(&f))
    {
      return false;
    }
//std::cout << " - Adding object " << *obj << "\n";

    AddObject(obj);
  }
//std::cout << "Loaded object create cache ok!\n";

#endif // YES_USE_CACHE

  return true;
}
bool EngineStatePlayerStats::Load()
{
  if (!EngineStateText::Load())
  {
    return false;
  }

  std::string bg = GetEngine()->GetConfigValue("title_bg");
  if (!m_bg.Load(bg, ""))
  {
    ReportError("Failed to load stats background.");
    return false;
  }

  // Get the stats file
  std::string filename = GetEngine()->GetConfigValue("stat_file");
  File statfile;
  if (!statfile.OpenRead(filename))
  {
    statfile.ReportError("Failed to open stats file.");
    return false;
  }
  // Load guages and labels.
  int numGuages = 0;
  if (!statfile.GetInteger(&numGuages))
  {
    statfile.ReportError("Expected number of stat guages.");
    return false;
  }
  for (int i = 0; i < numGuages; i++)
  {
    std::string name;  // name of this stat
    if (!statfile.GetDataLine(&name))
    {
      statfile.ReportError("Expected stat name.");
      return false;
    }
    // Get (x, y) position for the stat name.
    float x = 0;
    float y = 0;
    if (!statfile.GetFloat(&x))
    {
      statfile.ReportError("Expected text x position.");
      return false;
    }
    if (!statfile.GetFloat(&y))
    {
      statfile.ReportError("Expected text y position.");
      return false;
    }
    m_textPositions.push_back(std::make_pair(x, y));

    // Get the "Anchor value" for the guage. This is where the coloured bar
    // starts, so if the value is the same as the anchor value, the bar
    // has zero length.
    float anchor = 0;
    if (!statfile.GetFloat(&anchor))
    {
      statfile.ReportError("Expected anchor value for guage.");
      return false;
    }

    // TODO need a factory for guages.
    // NB Should guages be derived from GUI base ??!
    PowerGuage* pPg = new PowerGuage;
    // Set the colour for this guage
    Colour c = GetColour(i);
    pPg->SetColour(c); 
    pPg->SetAnchor(anchor);
    
    RCPtr<Guage> pGuage = pPg;
    // TODO TEMP TEST
    // Get filename for this guage
    std::string guagefilename; ///= "statguage1.txt";
    if (!statfile.GetDataLine(&guagefilename))
    {
      statfile.ReportError("Expected guage filename.");
      return false;
    }
    File f;
    if (!f.OpenRead(guagefilename))
    {
      f.ReportError("Failed to load guage for player stats.");
      return false;
    }
    if (!pGuage->Load(&f))
    {
      f.ReportError("Failed to load guage for player stats.");
      return false;
    }
    m_nameGuages.push_back(std::make_pair(name, pGuage));
  }

  // Set up GUI button
  // "OK" button
  m_pOkButton = new PoolGuiButton;
  // TODO Have a unique file
  std::string okButtonFile = GetEngine()->GetConfigValue("golf_start_button");
  if (!m_pOkButton->Load(okButtonFile))
  {
    return false;
  }
  m_pOkButton->SetSize(7.75f, 2.0f);
  m_pOkButton->SetRelPos(12.0f, 9.5f);
  m_pOkButton->SetCommand(&OnOkClicked);

  // Set up button text
  TextColourizerColourList tc1;
  tc1.AddColour(Colour(1.0f, 1.0f, 1.0f, 1.0f));
  m_pOkText = TextFactory::Instance()->Create("ok!", &tc1);

  return true;
}
Esempio n. 8
0
bool ObjectUpdater::Load()
{
#ifdef YES_USE_CACHE

#ifdef OU_DEBUG
std::cout << "Loading " << CACHE_FILENAME << "...\n";
#endif

  File f;
  if (!f.OpenRead(CACHE_FILENAME))
  {
    return false;
  }
  if (!m_timestampPos.Load(&f))
  {
    f.ReportError("Object state cache: Expected pos timestamp");
    return false;
  }

  if (!m_timestampUpdate.Load(&f))
  {
    f.ReportError("Object state cache: Expected update timestamp");
    return false;
  }

  int num = 0;

  // Load key/val pairs
  if (!f.GetInteger(&num))
  {
    f.ReportError("Object state cache: Expected num items");
    return false;
  }
  for (int i = 0; i < num; i++)
  {
    std::string s;
    if (!f.GetDataLine(&s))
    {
      f.ReportError("Object state cache: Expected item");
      return false;
    }
    // Format is id, key, val
    Strings strs = Split(s, ',');
    if (strs.size() != 3)
    {
      // Delimiter in key or val ??
      f.ReportError("Object state cache: bad item line: " + s);
      continue; // try to keep going
    }   
    int id = ToInt(strs[0]);
    QueueUpdate(id, strs[1], strs[2]);
  }

#ifdef OU_DEBUG
std::cout << "...Loaded " << num << " update items...\n";
#endif

  // Load positions
  if (!f.GetInteger(&num))
  {
    f.ReportError("Object state cache: Expected num positions");
    return false;
  }
  for (int i = 0; i < num; i++)
  {
    std::string s;
    if (!f.GetDataLine(&s))
    {
      f.ReportError("Object state cache: Expected position");
      return false;
    }
    // Format is id,x, y, z
    Strings strs = Split(s, ',');
    if (strs.size() != 5)
    {
      f.ReportError("Object state cache: bad position: " + s);
      continue;
    } 
    int id = ToInt(strs[0]);
    float x = ToFloat(strs[1]);
    float y = ToFloat(strs[2]);
    float z = ToFloat(strs[3]);
    int location = ToInt(strs[4]);

    QueueUpdatePos(id, Vec3f(x, y, z), location);
  }

#ifdef OU_DEBUG
std::cout << "...Loaded " << num << " positions, OK, done!\n";
#endif
  
#endif // YES_USE_CACHE

  return true;
}
Esempio n. 9
0
bool SinglePoolCourseManager::Load()
{
  // POOL
  // Level info file has list of all levels, cost of each room, user-friendly
  // name for level, etc.
  std::string filename = Engine::Instance()->GetConfigValue("levels_file");
  File f;
  if (!f.OpenRead(filename))
  {
    f.ReportError("Failed to open pool levels file");
    return false;
  }
  // Get number of levels
  int numLevels;
  if (!f.GetInteger(&numLevels))
  {
    f.ReportError("Expected number of levels");
    return false;
  }
  for (int i = 0; i < numLevels; i++)
  {
    // Get filename, user-friendly name
    std::string name, filename;
    if (!f.GetDataLine(&filename))
    {
      f.ReportError("Expected level filename");
      return false;
    }
    if (!f.GetDataLine(&name))
    {
      f.ReportError("Expected level user friendly name");
      return false;
    } 
    // Get number of rooms
    int numRooms = 0;  
    if (!f.GetInteger(&numRooms))
    {
      f.ReportError("Expected number of rooms");
      return false;
    }
    for (int j = 0; j < numRooms; j++)
    {
      int type = 0;
      int cost = 0;
      if (!f.GetInteger(&type))
      {
        f.ReportError("Expected cost type for room");
        return false;
      }
      if (!f.GetInteger(&cost))
      {
        f.ReportError("Expected cost number for room");
        return false;
      }
      m_roomCosts[std::make_pair(i, j)] = std::make_pair(type, cost);

      // Get BITFIELD: is this room unlockable in trial period, or is it
      // one- or two- player only ? (Bits defined at top of file)
      int bits = 0;
      if (!f.GetInteger(&bits))
      {
        f.ReportError("Expected trial unlock/one/two player flags");
        return false;
      }
      m_trialUnlock[std::make_pair(i, j)] = bits;
    }

    CourseInfo ci;
    ci.m_id = i;
    ci.m_isUnlocked = true; 
    ci.m_name = name;
    ci.m_filename = filename;
    ci.m_isUser = false;
    ci.m_maxHole = 0;
    m_courseMap.push_back(ci);
  }

  return true;
}
Esempio n. 10
0
bool AvatarManager::Load()
{
    // Load character types - NB we want this to be downloadable.
    // Add a new object with asset list to server, which this client will then download...?

////  m_chars.clear();
////  m_texPairs.clear();

    File f;
    if (!f.OpenRead("charlist.txt"))
    {
        ReportError("Failed to load character list");
        return false;
    }

    int numChars = 0;
    if (!f.GetInteger(&numChars))
    {
        ReportError("Expected number of characters!");
        return false;
    }

////  m_chars.reserve(numChars);

    for (int i = 0; i < numChars; i++)
    {
        std::string chName;
        if (!f.GetDataLine(&chName))
        {
            f.ReportError("Expected character name");
            return false;
        }

        // Read type
        std::string chType;
        if (!f.GetDataLine(&chType))
        {
            f.ReportError("Expected character type");
            return false;
        }

        // TODO
        //ChInfo chInfo;
        //chInfo.type = chType;

        //m_chars[chName] = chType;
        m_chars.push_back(chName);

        /*
            // Surely MD2 Model should be managed by Resource manager???!!!
            Md2Model* ch = (Md2Model*)TheResourceManager::Instance()->GetRes(s);
            // Instead of:
            Md2Model* ch = new Md2Model;
            if (!ch->Load(s))
            {
              f.ReportError("Failed to load character " + ToString(i));
              return false;
            }
            m_chars.push_back(ch);
        */

    }

    /*
      int numTex = 0;
      if (!f.GetInteger(&numTex))
      {
        f.ReportError("Expected num textures");
        return false;
      }

      m_texPairs.reserve(numTex);

      for (int i = 0; i < numTex; i++)
      {
        std::string tex1Name, tex2Name;
        if (!f.GetDataLine(&tex1Name) || !f.GetDataLine(&tex2Name))
        {
          f.ReportError("Failed to get 2 textures for player");
          return false;
        }
        Texture* t1 = (Texture*)TheResourceManager::Instance()->GetRes(tex1Name);
        Texture* t2 = (Texture*)TheResourceManager::Instance()->GetRes(tex2Name);
        if (!t1 || !t2)
        {
          f.ReportError("Failed to load texture");
          return false;
        }
        m_texPairs.push_back(std::make_pair(t1, t2));
      }
    */

    return true;
}
Esempio n. 11
0
bool CharacterManager::LoadCharacters(const string& charList)
{
  Clear();
    
  File f;
  if (!f.OpenRead(charList))
  {
    f.ReportError("Couldn't open character list file.");
    return false;
  }

  // Step 1: Load all meshes. These are stored in a map, and Characters point to
  // the single instance of a particular mesh. (Or a Character subclass could 
  // actually point to lots of meshes.)
  if (!LoadMd2Meshes(&f))
  {
    f.ReportError("Failed to load character meshes.");
    return false;
  }

  // (TODO more functions as more file formats are supported.)

  // Step 2: load each character.
  // These can be different subtypes of Character, so use factory function.

  // Get number of characters
  int numCharacters = 0;
  if (!f.GetInteger(&numCharacters))
  {
    f.ReportError("Expected number of characters.");
    return false;
  }

  // For each character..
  for (int i = 0; i < numCharacters; i++)
  {
    // Get the ID name and type (MD2 etc)
    string id;
    if (!f.GetDataLine(&id))
    {
      f.ReportError("Expected character ID.");
      return false;
    }

    if (m_characterMap.find(id) != m_characterMap.end())
    {
      string error = "Non-unique character ID " + id;
      f.ReportError(error);
      return false;
    }

    string charType;
    if (!f.GetDataLine(&charType))
    {
      f.ReportError("Expected character type.");
      return false;
    }

    // Create new Character subtype 
    RCPtr<Character> pCharacter = Create(charType);
    if (!pCharacter.GetPtr())
    {
      f.ReportError("Bad character type.");
      return false;
    }

    if (!pCharacter->Load(&f))
    {
      string error = "Failed to load character " + id;
      f.ReportError(error);
      return false;
    }

    pCharacter->SetName(id);
    m_characterMap[id] = pCharacter;
    m_characterNames.push_back(id);
  }
  return true;
}