From f0d97bfdb91a2c0a17d1697b145d4df930280dbb Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 18 May 2014 12:12:47 +0200 Subject: Better datadir mod support --- src/graphics/engine/engine.cpp | 34 +++++++--------------------------- src/graphics/engine/modelmanager.cpp | 20 +++++++++++++++++++- src/graphics/engine/modelmanager.h | 17 +++++++++++++++++ src/graphics/engine/terrain.cpp | 5 +++-- src/graphics/engine/text.cpp | 3 ++- 5 files changed, 48 insertions(+), 31 deletions(-) (limited to 'src/graphics/engine') diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 0ee7715..d6e4415 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -19,6 +19,7 @@ #include "graphics/engine/engine.h" #include "app/app.h" +#include "app/gamedata.h" #include "common/image.h" #include "common/key.h" @@ -2246,33 +2247,12 @@ Texture CEngine::CreateTexture(const std::string& texName, const TextureCreatePa if (image == nullptr) { - bool loadedFromTexPack = false; - - std::string texPackName = m_app->GetTexPackFilePath(texName); - if (! texPackName.empty()) + if (! img.Load(CGameData::GetInstancePointer()->GetFilePath(DIR_TEXTURE, texName))) { - if (img.Load(texPackName)) - { - loadedFromTexPack = true; - } - else - { - std::string error = img.GetError(); - GetLogger()->Error("Couldn't load texture '%s' from texpack: %s, blacklisting the texpack path\n", - texName.c_str(), error.c_str()); - m_texBlacklist.insert(texPackName); - } - } - - if (!loadedFromTexPack) - { - if (! img.Load(m_app->GetDataFilePath(DIR_TEXTURE, texName))) - { - std::string error = img.GetError(); - GetLogger()->Error("Couldn't load texture '%s': %s, blacklisting\n", texName.c_str(), error.c_str()); - m_texBlacklist.insert(texName); - return Texture(); // invalid texture - } + std::string error = img.GetError(); + GetLogger()->Error("Couldn't load texture '%s': %s, blacklisting\n", texName.c_str(), error.c_str()); + m_texBlacklist.insert(texName); + return Texture(); // invalid texture } image = &img; @@ -2435,7 +2415,7 @@ bool CEngine::ChangeTextureColor(const std::string& texName, CImage img; - if (! img.Load(m_app->GetDataFilePath(DIR_TEXTURE, texName))) + if (! img.Load(CGameData::GetInstancePointer()->GetFilePath(DIR_TEXTURE, texName))) { std::string error = img.GetError(); GetLogger()->Error("Couldn't load texture '%s': %s, blacklisting\n", texName.c_str(), error.c_str()); diff --git a/src/graphics/engine/modelmanager.cpp b/src/graphics/engine/modelmanager.cpp index abc8c6c..0c0fb98 100644 --- a/src/graphics/engine/modelmanager.cpp +++ b/src/graphics/engine/modelmanager.cpp @@ -1,6 +1,24 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch +// * Copyright (C) 2012-2014, Polish Portal of Colobot (PPC) +// * +// * This program is free software: you can redistribute it and/or modify +// * it under the terms of the GNU General Public License as published by +// * the Free Software Foundation, either version 3 of the License, or +// * (at your option) any later version. +// * +// * This program is distributed in the hope that it will be useful, +// * but WITHOUT ANY WARRANTY; without even the implied warranty of +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// * GNU General Public License for more details. +// * +// * You should have received a copy of the GNU General Public License +// * along with this program. If not, see http://www.gnu.org/licenses/. + #include "graphics/engine/modelmanager.h" #include "app/app.h" +#include "app/gamedata.h" #include "common/logger.h" @@ -30,7 +48,7 @@ bool CModelManager::LoadModel(const std::string& fileName, bool mirrored) if (CApplication::GetInstance().IsDebugModeActive(DEBUG_MODELS)) modelFile.SetPrintDebugInfo(true); - std::string filePath = CApplication::GetInstance().GetDataFilePath(DIR_MODEL, fileName); + std::string filePath = CGameData::GetInstancePointer()->GetFilePath(DIR_MODEL, fileName); if (!modelFile.ReadModel(filePath)) { diff --git a/src/graphics/engine/modelmanager.h b/src/graphics/engine/modelmanager.h index 9d50b97..ee5fc27 100644 --- a/src/graphics/engine/modelmanager.h +++ b/src/graphics/engine/modelmanager.h @@ -1,3 +1,20 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch +// * Copyright (C) 2012-2014, Polish Portal of Colobot (PPC) +// * +// * This program is free software: you can redistribute it and/or modify +// * it under the terms of the GNU General Public License as published by +// * the Free Software Foundation, either version 3 of the License, or +// * (at your option) any later version. +// * +// * This program is distributed in the hope that it will be useful, +// * but WITHOUT ANY WARRANTY; without even the implied warranty of +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// * GNU General Public License for more details. +// * +// * You should have received a copy of the GNU General Public License +// * along with this program. If not, see http://www.gnu.org/licenses/. + #pragma once #include "common/singleton.h" diff --git a/src/graphics/engine/terrain.cpp b/src/graphics/engine/terrain.cpp index e6ca824..5f37cd8 100644 --- a/src/graphics/engine/terrain.cpp +++ b/src/graphics/engine/terrain.cpp @@ -19,6 +19,7 @@ #include "graphics/engine/terrain.h" #include "app/app.h" +#include "app/gamedata.h" #include "common/image.h" #include "common/logger.h" @@ -189,7 +190,7 @@ void CTerrain::AddMaterial(int id, const std::string& texName, const Math::Point bool CTerrain::LoadResources(const std::string& fileName) { CImage img; - std::string path = CApplication::GetInstance().GetDataFilePath(DIR_TEXTURE, fileName); + std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_TEXTURE, fileName); if (! img.Load(path)) { GetLogger()->Error("Cannot load resource file: '%s'\n", path.c_str()); @@ -286,7 +287,7 @@ bool CTerrain::LoadRelief(const std::string &fileName, float scaleRelief, m_scaleRelief = scaleRelief; CImage img; - std::string path = CApplication::GetInstance().GetDataFilePath(DIR_TEXTURE, fileName); + std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_TEXTURE, fileName); if (! img.Load(path)) { GetLogger()->Error("Could not load relief file: '%s'!\n", path.c_str()); diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index d0c9cc8..8fd01b7 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -19,6 +19,7 @@ #include "graphics/engine/text.h" #include "app/app.h" +#include "app/gamedata.h" #include "common/image.h" #include "common/logger.h" @@ -865,7 +866,7 @@ CachedFont* CText::GetOrOpenFont(FontType font, float size) return m_lastCachedFont; } - std::string path = CApplication::GetInstance().GetDataFilePath(DIR_FONT, mf->fileName); + std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_FONT, mf->fileName); m_lastCachedFont = new CachedFont(); m_lastCachedFont->font = TTF_OpenFont(path.c_str(), pointSize); -- cgit v1.2.3-1-g7c22