BMFont* ContentManager::LoadFont(const UString& path)
  {
    	if (path.empty()) {
	  DebugPrintF(VTEXT("Error Loading [BMFont]"));
			return NULL;
		}

		UString _path = os_path(FONT_FOLDER_PATH + path);
		UString _texPath = os_path(FONT_FOLDER_PATH + TEX_FOLDER_PATH);

		ContentMap::iterator it = m_fonts.find(_path);
		if (it != m_fonts.end()) {
			return (BMFont*)it->second;
		}
		else {

			/*create new font*/
			BMFont* font = new BMFont(_path);
			/*load textures for font*/
			for (auto& page : font->FontFile().pages) {
				Texture* tex = LoadTexture(_texPath + page.file);
				if (tex)
					font->AddPageTexture(tex);
			}
			m_fonts[_path] = (IContent*)font;
			return font;
		}

		return NULL;
  }
    Shader* ResourceManager::OpenShader(UString filePath, ShaderType type)
    {
        UString assetPath = PathManager::ShaderPath();

        assetPath += filePath;
        assetPath = os_path(assetPath);

		Shader* _shader = NULL;

        File* file = FileManager::OpenFile(assetPath, FileMode::ReadBinary);
        if (file)
        {
            //Create Renderer Specific texture type
            ResourceManager& _RM = ResourceManager::instance();

            if (_RM.m_resourceLoader)
            {
				_shader = (Shader*)ResourceManager::AccessAsset(file->FileName());

				if (!_shader)
				{
					_shader = _RM.m_resourceLoader->LoadShader(file, type);

					ResourceManager::MapAsset(file->FileName(), _shader);
				}
              
               FileManager::CloseFile(assetPath);
            }
        }

        return _shader;
    }
    Texture* ResourceManager::OpenTexture(UString filePath)
    {
        UString assetPath = PathManager::AssetPath() + VTEXT("Textures/");

        assetPath += filePath;
        assetPath = os_path(assetPath);

		Texture* _texture = NULL;

        File* file = FileManager::OpenFile(assetPath, FileMode::ReadBinary);
        if (file)
        {
            //Create Renderer Specific texture type
            ResourceManager& _RM = ResourceManager::instance();

			if (_RM.m_resourceLoader)
			{
				_texture = (Texture*)ResourceManager::AccessAsset(file->FileName());

				if (!_texture)
				{
					_texture = _RM.m_resourceLoader->LoadTexture(file);

					ResourceManager::MapAsset(file->FileName(), (Asset*)_texture);

				}
				
				FileManager::CloseFile(file);
			}
               
            
        }

		return _texture;
    }
	Material* ResourceManager::OpenMaterial(UString filePath)
	{
		UString assetPath = PathManager::MaterialPath();

		assetPath += filePath;
		assetPath = os_path(assetPath);

		Material* _material = NULL;

		File* file = FileManager::OpenFile(assetPath, FileMode::ReadBinary);
		if (file)
		{
			//Create Renderer Specific model type
			ResourceManager& _RM = ResourceManager::instance();

			if (_RM.m_resourceLoader)
			{
				_material = (Material*)ResourceManager::AccessAsset(file->FileName());

				if (!_material)
				{
					//Need to load a material object into memory
					_material = _RM.m_resourceLoader->LoadMaterial(file);

					
					ResourceManager::MapAsset(file->FileName(), _material);
				}
				
				FileManager::CloseFile(file);
			}
		}

		return _material;
	}
    Font* ResourceManager::OpenFont(UString filePath)
    {
        UString assetPath = PathManager::AssetPath() + VTEXT("Fonts/");

        assetPath += filePath;
        assetPath = os_path(assetPath);

		Font* _font = NULL;

        File* file = FileManager::OpenFile(assetPath, FileMode::ReadBinary);
        if (file)
        {
            //Create Renderer Specific model type
            ResourceManager& _RM = ResourceManager::instance();

            if (_RM.m_resourceLoader)
            {
				_font = (Font*)ResourceManager::AccessAsset(file->FileName());

				if (!_font)
				{
					//Need to load a font object into memory
					_font = _RM.m_resourceLoader->LoadFont(file);
				
					ResourceManager::MapAsset(file->FileName(), _font);
				}

                FileManager::CloseFile(file);
            }
        }

        return _font;
    }
Example #6
0
//-----------------------------------------------------------------------------
DiskFile* Filesystem::open(const char* relative_path, FileOpenMode mode)
{
	CE_ASSERT(exists(relative_path), "File does not exist: %s", relative_path);
	CE_ASSERT(is_file(relative_path), "File is not a regular file: %s", relative_path);

	return CE_NEW(m_allocator, DiskFile)(mode, os_path(relative_path));
}
	bool os_isdir(const UString& dir)
	{
		//convert path
		UString path = os_path(dir);
#ifdef VIX_SYS_WINDOWS
		DWORD dwAttrib = GetFileAttributes(dir.c_str());
		return (dwAttrib != INVALID_FILE_ATTRIBUTES &&
				(dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
#elif defined(VIX_SYS_LINUX)
		//THIS CODE *SHOULD* WORK ON LINUX AND UNIX.
		//IM NOT 100% POSITIVE THOUGH, SO PLEASE CHECK
		struct stat info;
		stat(dir.c_str(), &info);
		return S_ISDIR(info.st_mode);
#endif
	}
Example #8
0
void
exportlibdirs()
{ char tmp[10240];
  char *s, *e;
  int n;

  strcpy(tmp, "LIB=");
  e = tmp + strlen(tmp);

  for(n=0; n<libdirs.size; n++)
  { e = os_path(e, libdirs.list[n]);
    *e++ = ';';
  }
  if ( (s = getenv("LIB")) )
    strcpy(e, s);

  if ( verbose )
    printf("\t%s\n", tmp);

  putenv(strdup(tmp));
}
  Texture* ContentManager::LoadTexture(const UString& path)
  {
    	if (path.empty()) {
	  DebugPrintF(VTEXT("Error Loading [Texture]"));
			return NULL;
		}

		UString _path = os_path(TEX_FOLDER_PATH + path);

		ContentMap::iterator it = m_textures.find(_path);
		if (it != m_textures.end()) {
			return (Texture*)it->second;
		}
		else {
			/*create new texture*/
			Texture* texture = new GLTexture(_path);
			m_textures[_path] = (IContent*)texture;
			return texture;
		}

		return NULL;
  }
Example #10
0
        std::string File::GetName(const std::string& path, bool we /* = true */)
        {
            std::string name = "";
            std::string _path = os_path(path);
            size_t pos = 0;
#ifdef HT_SYS_WINDOWS
            pos = _path.find_last_of('\\');
            if(pos != std::string::npos)
                _path.erase(0, pos + 1);
#else
            pos = _path.find_last_of('/');
            if (pos != std::string::npos)
                _path.erase(0, pos + 1);
#endif
            if (!we)
            {
                size_t extPos = _path.find_last_of(".");
                _path = _path.substr(0, extPos);
            }

            return _path;
        }
Example #11
0
        void File::Open(std::string path, FileMode mode)
        {
            m_path = os_path(path);
            m_name = GetName(m_path);
            m_baseName = GetName(m_path, false);

            switch (mode)
            {
                case FileMode::ReadBinary:
                {
                    #ifdef HT_SYS_WINDOWS
                        fopen_s(&m_handle, m_path.c_str(), "rb");
                    #else
                        m_handle = fopen(m_path.c_str(), "rb");
                    #endif
                } break;

                case FileMode::ReadText:
                {
                    #ifdef HT_SYS_WINDOWS
                        fopen_s(&m_handle, m_path.c_str(), "rt");
                    #else
                        m_handle = fopen(m_path.c_str(), "rt");
                    #endif
                } break;

                case FileMode::WriteBinary:
                {
                    #ifdef HT_SYS_WINDOWS
                        fopen_s(&m_handle, m_path.c_str(), "wb");
                    #else
                        m_handle = fopen(m_path.c_str(), "wb");
                    #endif
                } break;

                case FileMode::WriteText:
                {
                    #ifdef HT_SYS_WINDOWS
                        fopen_s(&m_handle, m_path.c_str(), "w");
                    #else
                        m_handle = fopen(m_path.c_str(), "w+");
                    #endif
                } break;

                case FileMode::AppendBinary:
                {
                    #ifdef HT_SYS_WINDOWS
                        fopen_s(&m_handle, m_path.c_str(), "ab");
                    #else
                        m_handle = fopen(m_path.c_str(), "ab");
                    #endif
                } break;

                case FileMode::AppendText:
                {
                    #ifdef HT_SYS_WINDOWS
                        fopen_s(&m_handle, m_path.c_str(), "a");
                    #else
                        m_handle = fopen(m_path.c_str(), "a");
                    #endif
                } break;

                default:
                    break;
            }

            if (!m_handle)
                throw FileException(m_path, errno);

        }