Exemple #1
0
TEST(GameexeUnit, FilteringIterators) {
  Gameexe ini(locateTestCase("Gameexe_data/Gameexe.ini"));
  GameexeFilteringIterator it = ini.filtering_begin("IMAGINE");
  GameexeFilteringIterator end = ini.filtering_end();
  for (; it != end; ++it) {
    if (it->key() != "IMAGINE.ONE" &&
       it->key() != "IMAGINE.TWO" &&
       it->key() != "IMAGINE.THREE") {
      FAIL() << "Failed to filter keys in GameexeFilteringIterator. Has key "
             << it->key();
    }
  }
}
Exemple #2
0
RLMachine::RLMachine(System& in_system, Archive& in_archive)
    : memory_(new Memory(*this, in_system.gameexe())),
      halted_(false),
      print_undefined_opcodes_(false),
      halt_on_exception_(true),
      archive_(in_archive),
      line_(0),
      system_(in_system),
      mark_savepoints_(true),
      delay_stack_modifications_(false),
      replaying_graphics_stack_(false) {
  // Search in the Gameexe for #SEEN_START and place us there
  Gameexe& gameexe = in_system.gameexe();
  libReallive::Scenario* scenario = NULL;
  if (gameexe.exists("SEEN_START")) {
    int first_seen = gameexe("SEEN_START").to_int();
    scenario = in_archive.scenario(first_seen);

    if (scenario == NULL)
      cerr << "WARNING: Invalid #SEEN_START in Gameexe" << endl;
  }

  if (scenario == NULL) {
    // if SEEN_START is undefined, then just grab the first SEEN.
    scenario = in_archive.scenario(archive_.begin()->first);
  }

  if (scenario == 0)
    throw rlvm::Exception("Invalid scenario file");
  pushStackFrame(StackFrame(scenario, scenario->begin(),
                            StackFrame::TYPE_ROOT));

  // Initial value of the savepoint
  markSavepoint();

  // Load the "DLLs" required
  GameexeFilteringIterator it = gameexe.filtering_begin("DLL.");
  GameexeFilteringIterator end = gameexe.filtering_end();
  for (; it != end; ++it) {
    string index_str = it->key().substr(it->key().find_first_of(".") + 1);
    int index = lexical_cast<int>(index_str);
    const string& name = it->to_string("");
    try {
      loadDLL(index, name);
    } catch(rlvm::Exception& e) {
      cerr << "WARNING: Don't know what to do with DLL '" << name << "'"
           << endl;
    }
  }
}
Exemple #3
0
GraphicsSystem::GraphicsObjectSettings::GraphicsObjectSettings(
  Gameexe& gameexe) {
  if (gameexe.exists("OBJECT_MAX"))
    objects_in_a_layer = gameexe("OBJECT_MAX");
  else
    objects_in_a_layer = 256;

  // First we populate everything with the special value
  position.reset(new unsigned char[objects_in_a_layer]);
  fill(position.get(), position.get() + objects_in_a_layer, 0);

  if (gameexe.exists("OBJECT.999"))
    data.push_back(ObjectSettings(gameexe("OBJECT.999")));
  else
    data.push_back(ObjectSettings());

  // Read the #OBJECT.xxx entries from the Gameexe
  GameexeFilteringIterator it = gameexe.filtering_begin("OBJECT.");
  GameexeFilteringIterator end = gameexe.filtering_end();
  for (; it != end; ++it) {
    string s = it->key().substr(it->key().find_first_of(".") + 1);
    std::list<int> object_nums;
    string::size_type poscolon = s.find_first_of(":");
    if ( poscolon != string::npos ) {
      int obj_num_first = lexical_cast<int>(s.substr(0, poscolon));
      int obj_num_last = lexical_cast<int>(s.substr(poscolon + 1));
      while ( obj_num_first <= obj_num_last ) {
        object_nums.push_back(obj_num_first++);
      }
    } else {
      object_nums.push_back(lexical_cast<int>(s));
    }

    for ( std::list<int>::const_iterator intit = object_nums.begin();
         intit != object_nums.end(); ++intit ) {
      int obj_num = *intit;
      if (obj_num != 999 && obj_num < objects_in_a_layer) {
        position[obj_num] = data.size();
        data.push_back(ObjectSettings(*it));
      }
    }
  }
}
Exemple #4
0
void Memory::initializeDefaultValues(Gameexe& gameexe) {
  // Note: We ignore the \#NAME_MAXLEN variable because manual allocation is
  // error prone and for losers.
  GameexeFilteringIterator end = gameexe.filtering_end();
  for (GameexeFilteringIterator it = gameexe.filtering_begin("NAME.");
      it != end; ++it) {
    try {
      setName(ConvertLetterIndexToInt(it->key_parts().at(1)),
              removeQuotes(it->to_string()));
    } catch(...) {
      cerr << "WARNING: Invalid format for key " << it->key() << endl;
    }
  }

  for (GameexeFilteringIterator it = gameexe.filtering_begin("LOCALNAME.");
      it != end; ++it) {
    try {
      setLocalName(ConvertLetterIndexToInt(it->key_parts().at(1)),
                   removeQuotes(it->to_string()));
    } catch(...) {
      cerr << "WARNING: Invalid format for key " << it->key() << endl;
    }
  }
}