Exemplo n.º 1
0
   bool MapSystem::AddEmptyMap(const std::string& dataPath, const std::string& mapname)
   {
      if(IsMapLoaded(mapname))
      {
         return false;
      }
      if(GetSystemInterface()->FindDataFile(mapname) != "")
      {
         mLoadedMaps.push_back(MapData(mapname, dataPath, static_cast<unsigned int>(mLoadedMaps.size())));
         return false;
      }

      std::string mappathrel = GetFilePath(mapname);
      std::ostringstream os; os << dataPath << "/" << mappathrel;
      std::string mappathabs = os.str();

      if(!GetSystemInterface()->FileExists(mappathabs))
      {
         LOG_ERROR("Cannot create map in directory " << mappathabs << "! Does it exist?");
         return false;
      }

      MapBeginLoadMessage msg;
      msg.SetMapPath(mapname);
      GetEntityManager().EmitMessage(msg);
      mLoadedMaps.push_back(MapData(mapname, dataPath, static_cast<unsigned int>(mLoadedMaps.size())));
      MapLoadedMessage msg2;
      msg2.SetMapPath(mapname);
      GetEntityManager().EmitMessage(msg2);
      return true;
   }
//----------------------------------------------------------------------------------------
void MegaDriveCOFLoader::UnloadROMFileFromModulePath(const std::wstring& targetROMModulePath) const
{
	//Retrieve the set of ID numbers for all currently loaded modules
	std::list<unsigned int> loadedModuleIDs = GetSystemInterface().GetLoadedModuleIDs();

	//Attempt to retrieve the ID of the first matching loaded module file
	bool foundLoadedModuleID = false;
	unsigned int loadedModuleID;
	std::list<unsigned int>::const_iterator loadedModuleIDIterator = loadedModuleIDs.begin();
	while(!foundLoadedModuleID && (loadedModuleIDIterator != loadedModuleIDs.end()))
	{
		LoadedModuleInfo moduleInfo;
		if(GetSystemInterface().GetLoadedModuleInfo(*loadedModuleIDIterator, moduleInfo))
		{
			if(moduleInfo.GetModuleFilePath() == targetROMModulePath)
			{
				foundLoadedModuleID = true;
				loadedModuleID = moduleInfo.GetModuleID();
			}
		}
		++loadedModuleIDIterator;
	}

	//If we managed to locate a module which was loaded from the target module file,
	//unload it.
	if(foundLoadedModuleID)
	{
		GetGUIInterface().UnloadModule(loadedModuleID);
	}
}
Exemplo n.º 3
0
   bool MapSystem::LoadScene(const std::string& path)
   {
      // get data path containing this map
      
      std::string abspath = GetSystemInterface()->FindDataFile(path);
      if(abspath == "")
      {
         LOG_ERROR("Cannot find scene file: " << path);
         return false;
      }

      std::string scenedatapath = GetSystemInterface()->GetDataFilePathFromFilePath(abspath);

      
      if(scenedatapath == "")
      {
         LOG_ERROR("No data path for scene found!");
         return false;
      }

      MapEncoder* enc = GetEncoderForScene(GetFileExtension(path));
      if(!enc)
      {
         LOG_ERROR("Could not load scene: Loader not found for extension " << GetFileExtension(path));
         return false;
      }

      bool success = enc->LoadSceneFromFile(path);
      
      SceneLoadedMessage msg;
      msg.SetSceneName(path);
      GetEntityManager().EmitMessage(msg);
      return success;
   }
// If the requested texture is already in the database, it will be returned with an extra reference count. If not, it
// will be loaded through the application's render interface.
TextureResource* TextureDatabase::Fetch(const String& source, const String& source_directory)
{
	String path;
	if (source.Substring(0, 1) == "?")
		path = source;
	else
		GetSystemInterface()->JoinPath(path, source_directory.Replace("|", ":"), source);

	TextureMap::iterator iterator = instance->textures.find(path);
	if (iterator != instance->textures.end())
	{
		(*iterator).second->AddReference();
		return (*iterator).second;
	}

	TextureResource* resource = new TextureResource();
	if (!resource->Load(path))
	{
		resource->RemoveReference();
		return NULL;
	}

	instance->textures[resource->GetSource()] = resource;
	return resource;
}
Exemplo n.º 5
0
float Clock::GetElapsedTime()
{
	SystemInterface* system_interface = GetSystemInterface();
	if (system_interface != NULL)
		return system_interface->GetElapsedTime();
	else
		return 0;
}
Exemplo n.º 6
0
   /** load all dlls in dir and check for plugin factories */
   void ComponentPluginManager::LoadPluginsInDir(const std::string& path)
   {
      std::string cleanedPath(path);
      if (path[path.size() - 1] == GetNativePathSeparator())
      {
         // remove the trailing path separator as this causes issues...
         cleanedPath = path.substr(0, path.size() - 1);
      }

      if(!GetSystemInterface()->FileExists(cleanedPath))
      {
         LOG_ALWAYS("Plugin folder not found! Path: " + cleanedPath);
         return;
      }

      std::string libExtension = GetLibExtension();
      LOG_DEBUG("Looking for plugins with extension: " + libExtension);

      // get libs from directory
      SystemInterface::DirectoryContents files = GetSystemInterface()->GetDirectoryContents(cleanedPath);

      // for each library in dir
      SystemInterface::DirectoryContents::const_iterator i;
      for(i = files.begin(); i != files.end(); ++i)
      {
         std::string fileName = *i;

         if(fileName.size() <= libExtension.size())
            continue;

         std::string ending = fileName.substr(fileName.size() - libExtension.size(), fileName.size());
         if(ending.compare(libExtension) != 0)
         {
            continue;
         }

         std::ostringstream libpath;
         libpath << cleanedPath << GetNativePathSeparator() << fileName;
         AddPlugin(libpath.str());
         LOG_DEBUG("Loaded plugin: " + libpath.str());
      }
   }
Exemplo n.º 7
0
   std::set<ComponentType> ComponentPluginManager::AddPlugin(const std::string& path, const std::string& libname, bool saveWithScene)
   {      
      std::string filename = GetSharedLibNameFromPluginName(libname);
      std::string p = path + "/" + filename;
      if(!GetSystemInterface()->FileExists(p))
      {
         std::set<ComponentType> ret;
         return ret;
      }

      return AddPlugin(p, saveWithScene);
   }
//----------------------------------------------------------------------------------------
void MegaDriveCOFLoader::UnloadROMFile()
{
	//If at least one ROM module is currently loaded, unload the oldest module.
	if(!currentlyLoadedROMModuleFilePaths.empty())
	{
		//Stop the system if it is currently running
		GetSystemInterface().StopSystem();

		//Unload the oldest currently loaded ROM module
		std::wstring oldestLoadedROMModule = *currentlyLoadedROMModuleFilePaths.begin();
		UnloadROMFileFromModulePath(oldestLoadedROMModule);
		currentlyLoadedROMModuleFilePaths.pop_front();
	}
}
Exemplo n.º 9
0
   bool MapSystem::LoadMap(const std::string& path)
   {
      if(IsMapLoaded(path))
      {
         LOG_ERROR("Map already loaded: " + path);
         return false;
      }

      if(!MapExists(path))
      {
         LOG_ERROR("Map not found: " + path);
         return false;
      }

      MapEncoder* enc = GetEncoderForMap(GetFileExtension(path));
      if(!enc)
      {
         LOG_ERROR("Could not load map: Loader not found for extension " << GetFileExtension(path));
         return false;
      }

      // get data path containing this map
      std::string abspath = GetSystemInterface()->FindDataFile(path);
      std::string mapdatapath = dtEntity::GetSystemInterface()->GetDataFilePathFromFilePath(abspath);
      
      assert(mapdatapath != "");

      LoadedMaps::size_type mapsaveorder = mLoadedMaps.size();


      MapBeginLoadMessage msg;
      msg.SetMapPath(path);
      msg.SetDataPath(mapdatapath);
      msg.SetSaveOrder(mapsaveorder);
      GetEntityManager().EmitMessage(msg);

      bool success = enc->LoadMapFromFile(path);
      if(success)
      {
         mLoadedMaps.push_back(MapData(path, mapdatapath, static_cast<unsigned int>(mLoadedMaps.size())));

         MapLoadedMessage msg1;
         msg1.SetMapPath(path);
         msg1.SetDataPath(mapdatapath);
         msg1.SetSaveOrder(mapsaveorder);
         GetEntityManager().EmitMessage(msg1);
      }
      return success;
   }
Exemplo n.º 10
0
//----------------------------------------------------------------------------------------
//Window functions
//----------------------------------------------------------------------------------------
bool ExodusSystemMenus::RegisterSystemMenuHandler()
{
	//Retrieve the system GUI interface
	model = &((ISystemGUIInterface&)GetSystemInterface());

	//Create all menu handlers
	debugMenuHandler = new DebugMenuHandler(*this, *model);
	debugMenuHandler->LoadMenuItems();
	settingsMenuHandler = new SettingsMenuHandler(*this, *model);
	settingsMenuHandler->LoadMenuItems();
	systemMenuHandler = new SystemMenuHandler(*this, *model);
	systemMenuHandler->LoadMenuItems();

	return true;
}
bool XMLNodeHandlerHead::ElementData(XMLParser* parser, const String& data)
{
	const String& tag = parser->GetParseFrame()->tag;

	// Store the title
	if (tag == "title")
	{
		SystemInterface* system_interface = GetSystemInterface();
		if (system_interface != NULL)
			system_interface->TranslateString(parser->GetDocumentHeader()->title, data);
	}

	// Store an inline script
	if (tag == "script" && data.Length() > 0)
		parser->GetDocumentHeader()->scripts_inline.push_back(data);

	// Store an inline style
	if (tag == "style" && data.Length() > 0)
		parser->GetDocumentHeader()->rcss_inline.push_back(data);

	return true;
}
bool Assert(const char* msg, const char* file, int line)
{
	Rocket::Core::String message(1024, "%s\n%s:%d", msg, file, line);
	return GetSystemInterface()->LogMessage(Log::LT_ASSERT, message);
}
Exemplo n.º 13
0
// Instances a single text element containing a string.
bool Factory::InstanceElementText(Element* parent, const String& text)
{
	SystemInterface* system_interface = GetSystemInterface();

	// Do any necessary translation. If any substitutions were made then new XML may have been introduced, so we'll
	// have to run the data through the XML parser again.
	String translated_data;
	if (system_interface != NULL &&
		(system_interface->TranslateString(translated_data, text) > 0 ||
		 translated_data.Find("<") != String::npos))
	{
		StreamMemory* stream = new StreamMemory(translated_data.Length() + 32);
		stream->Write("<body>", 6);
		stream->Write(translated_data);
		stream->Write("</body>", 7);
		stream->Seek(0, SEEK_SET);

		InstanceElementStream(parent, stream);
		stream->RemoveReference();
	}
	else
	{
		// Check if this text node contains only white-space; if so, we don't want to construct it.
		bool only_white_space = true;
		for (size_t i = 0; i < translated_data.Length(); ++i)
		{
			if (!StringUtilities::IsWhitespace(translated_data[i]))
			{
				only_white_space = false;
				break;
			}
		}

		if (only_white_space)
			return true;

		// Attempt to instance the element.
		XMLAttributes attributes;
		Element* element = Factory::InstanceElement(parent, "#text", "#text", attributes);
		if (!element)
		{
			Log::Message(Log::LT_ERROR, "Failed to instance text element '%s', instancer returned NULL.", translated_data.CString());
			return false;
		}

		// Assign the element its text value.
		ElementText* text_element = dynamic_cast< ElementText* >(element);
		if (text_element == NULL)
		{
			Log::Message(Log::LT_ERROR, "Failed to instance text element '%s'. Found type '%s', was expecting a derivative of ElementText.", translated_data.CString(), typeid(element).name());
			element->RemoveReference();
			return false;
		}

		text_element->SetText(translated_data);

		// Add to active node.
		parent->AppendChild(element);
		element->RemoveReference();
	}

	return true;
}
Exemplo n.º 14
0
 bool MapSystem::MapExists(const std::string& path)
 {
    return (GetSystemInterface()->FindDataFile(path) != "");
 }
Exemplo n.º 15
0
osg::ref_ptr<osg::Node> ResourceManager::GetNode(EntityManager& em, const std::string& path, unsigned int options)
{
    osg::Node* ret = NULL;

    std::string abspath = GetSystemInterface()->FindDataFile(path);

    if(abspath.empty())
    {
        LOG_ERROR("Error loading node, could not find data file: " << path);
        return NULL;
    }

    if((options & ResourceManagerOptions::CopyNodes) != 0)
    {
        NodeStore::iterator i = mNodeStore.find(abspath);
        if(i != mNodeStore.end())
        {
            ret = osg::clone(i->second.get(), osg::CopyOp(
                                 osg::CopyOp::DEEP_COPY_OBJECTS        |
                                 osg::CopyOp::DEEP_COPY_NODES          |
                                 osg::CopyOp::DEEP_COPY_USERDATA
                             ));
        }
    }
    else if((options & ResourceManagerOptions::ShallowCopy) != 0)
    {
        NodeStore::iterator i = mNodeStore.find(abspath);
        if(i != mNodeStore.end())
        {
            ret = osg::clone(i->second.get(), osg::CopyOp(
                                 osg::CopyOp::DEEP_COPY_USERDATA
                             ));
        }
    }
    else if((options & ResourceManagerOptions::CopyHardwareMeshes) != 0)
    {
        NodeStore::iterator i = mNodeStore.find(abspath);
        if(i != mNodeStore.end())
        {
            ret = osg::clone(i->second.get(), osg::CopyOp(
                                 osg::CopyOp::DEEP_COPY_ALL
                                 & ~osg::CopyOp::DEEP_COPY_PRIMITIVES
                                 & ~osg::CopyOp::DEEP_COPY_ARRAYS
                                 & ~osg::CopyOp::DEEP_COPY_TEXTURES
                                 & ~osg::CopyOp::DEEP_COPY_STATEATTRIBUTES
                                 & ~osg::CopyOp::DEEP_COPY_IMAGES
                                 &  ~osg::CopyOp::DEEP_COPY_SHAPES
                                 & ~osg::CopyOp::DEEP_COPY_UNIFORMS
                             ));
        }
    }
    else if((options & ResourceManagerOptions::DeepCopy) != 0)
    {
        NodeStore::iterator i = mNodeStore.find(abspath);
        if(i != mNodeStore.end())
        {
            ret = osg::clone(i->second.get(), osg::CopyOp(
                                 osg::CopyOp::DEEP_COPY_ALL
                             ));
        }
    }

    if(ret != NULL)
    {
        ret->setUserData(NULL);
        return ret;
    }

    osg::Node* node = osgDB::readNodeFile(abspath);

    if(node == NULL)
    {
        LOG_ERROR("Error loading node, could not interpret data file: " << abspath);
        return NULL;
    }

    if((options & ResourceManagerOptions::DoOptimization) != 0)
    {
        osgUtil::Optimizer optimizer;
        optimizer.optimize(node);
    }
    if((options & ResourceManagerOptions::DeepCopy) == 0)
    {
        mNodeStore[abspath] = node;
    }

    ResourceLoadedMessage msg;
    msg.SetPath(abspath);
    em.EmitMessage(msg);

    if((options & ResourceManagerOptions::CopyHardwareMeshes) != 0)
    {
        return osg::clone(node, osg::CopyOp(
                              osg::CopyOp::DEEP_COPY_ALL &
                              ~osg::CopyOp::DEEP_COPY_PRIMITIVES &
                              ~osg::CopyOp::DEEP_COPY_ARRAYS &
                              ~osg::CopyOp::DEEP_COPY_TEXTURES
                          ));
    }
    else
    {
        return node;
    }
}
//----------------------------------------------------------------------------------------
//ROM loading functions
//----------------------------------------------------------------------------------------
void MegaDriveCOFLoader::LoadROMFile()
{
	//##TODO## Add a path for autogenerated modules to our global preferences?
	std::wstring autoGeneratedROMModuleFolderPath = PathCombinePaths(GetGUIInterface().GetGlobalPreferencePathModules(), L"AutoGenerated");

	//Obtain the current working directory of the process, and use it as the initial
	//folder location when searching for the target ROM file, unless this is the first
	//time we're making a file selection. The current working directory is reserved within
	//the Exodus platform for use by content loaders. We don't use the current working
	//directory initially however, as Windows is kind enough to remember the last used
	//folder path for a browse dialog between sessions, and we want to allow the last used
	//path to be retrieved here by not specifying any initial path. Although this will not
	//always do what we want, as any instance of the open file dialog in the application
	//will alter the initial path we display here on startup, it's the best option we've
	//found so far without persisting the last used path between sessions ourselves.
	std::wstring initialSearchFolderPath;
	if(selectionMadeThisSession)
	{
		initialSearchFolderPath = PathGetCurrentWorkingDirectory();
	}

	//Select a target file
	std::wstring selectedFilePath;
	if(!GetGUIInterface().SelectExistingFile(L"Mega Drive SNASM68K COF file|cof", L"cof", L"", initialSearchFolderPath, true, selectedFilePath))
	{
		return;
	}

	//Set the current working directory of the process to the directory of the selected
	//file. We do this so that the selected directory path will be remembered when this
	//dialog is next opened.
	selectionMadeThisSession = true;
	std::wstring selectedFileDirectory = PathGetDirectory(selectedFilePath);
	PathSetCurrentWorkingDirectory(selectedFileDirectory);

	//Build a module definition for the target ROM file
	std::wstring romName;
	HierarchicalStorageTree tree;
	if(!BuildROMFileModuleFromFile(selectedFilePath, tree.GetRootNode(), romName))
	{
		return;
	}

	//Generate the file path for the output XML file
	std::wstring autoGeneratedModuleOutputPath = PathCombinePaths(autoGeneratedROMModuleFolderPath, GetExtensionInstanceName());
	std::wstring moduleFileName = romName + L".xml";
	std::wstring moduleFilePath = PathCombinePaths(autoGeneratedModuleOutputPath, moduleFileName);

	//Write the generated module structure to the target output file
	if(!SaveOutputROMModule(tree, moduleFilePath))
	{
		return;
	}

	//Retrieve the current running state of the system, and stop the system if it is
	//currently running.
	ISystemExtensionInterface& system = GetSystemInterface();
	bool systemRunningState = system.SystemRunning();
	system.StopSystem();

	//If we currently have at least one ROM module loaded, and the system reports that we
	//can't currently load the new ROM module, assume we're currently using up all
	//available connectors, and unload the oldest of the currently loaded ROM modules.
	IGUIExtensionInterface& gui = GetGUIInterface();
	if(!currentlyLoadedROMModuleFilePaths.empty() && !gui.CanModuleBeLoaded(moduleFilePath))
	{
		//Unload the oldest currently loaded ROM module
		std::wstring oldestLoadedROMModule = *currentlyLoadedROMModuleFilePaths.begin();
		UnloadROMFileFromModulePath(oldestLoadedROMModule);
		currentlyLoadedROMModuleFilePaths.pop_front();
	}

	//Trigger an initialization of the system now that we're about to load a new ROM
	//module
	system.FlagInitialize();

	//Attempt to load the module file we just generated back into the system
	if(!gui.LoadModuleFromFile(moduleFilePath))
	{
		std::wstring text = L"Failed to load the generated module definition file. Check the event log for further info.";
		std::wstring title = L"Error loading ROM!";
		SafeMessageBox((HWND)GetGUIInterface().GetMainWindowHandle(), text, title, MB_ICONEXCLAMATION);
		return;
	}

	//Restore the running state of the system
	if(systemRunningState)
	{
		system.RunSystem();
	}

	//Record information on this loaded module
	currentlyLoadedROMModuleFilePaths.push_back(moduleFilePath);
}