diff options
67 files changed, 1317 insertions, 1008 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index bf1e12e..40ee44f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -206,6 +206,7 @@ find_package(SDL_image 1.2 REQUIRED) find_package(SDL_ttf 2.0 REQUIRED) find_package(PNG 1.2 REQUIRED) find_package(Gettext REQUIRED) +find_package(PhysFS REQUIRED) set(Boost_USE_STATIC_LIBS ${BOOST_STATIC}) set(Boost_USE_MULTITHREADED ON) diff --git a/cmake/FindPhysFS.cmake b/cmake/FindPhysFS.cmake new file mode 100644 index 0000000..fae8378 --- /dev/null +++ b/cmake/FindPhysFS.cmake @@ -0,0 +1,36 @@ +# PHYSFS_FOUND +# PHYSFS_INCLUDE_PATH +# PHYSFS_LIBRARY +# + +IF (WIN32) + FIND_PATH( PHYSFS_INCLUDE_PATH physfs.h + DOC "The directory where physfs.h resides") + FIND_LIBRARY( PHYSFS_LIBRARY + NAMES physfs + PATHS /mingw/lib + DOC "The PhysFS library") +ELSE (WIN32) + FIND_PATH( PHYSFS_INCLUDE_PATH physfs.h + /usr/include + /usr/local/include + /opt/local/include + DOC "The directory where physfs.h resides") + FIND_LIBRARY( PHYSFS_LIBRARY + NAMES physfs + PATHS + /usr/lib64 + /usr/lib + /usr/local/lib64 + /usr/local/lib + /opt/local/lib + DOC "The PhysFS library") +ENDIF (WIN32) + +IF (PHYSFS_INCLUDE_PATH) + SET( PHYSFS_FOUND 1 CACHE STRING "Set to 1 if PhysFS is found, 0 otherwise") +ELSE (GLEW_INCLUDE_PATH) + SET( PHYSFS_FOUND 0 CACHE STRING "Set to 1 if PhysFS is found, 0 otherwise") +ENDIF (PHYSFS_INCLUDE_PATH) + +MARK_AS_ADVANCED( PHYSFS_FOUND ) diff --git a/data b/data -Subproject d9ad3270af60905f53929cdf44aa47b4f910f60 +Subproject bacf4c9dac9efc817907ab4e172231d3396a421 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 12171f3..e02a30b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -61,7 +61,6 @@ endif() # Source files set(SOURCES app/app.cpp -app/gamedata.cpp app/main.cpp app/pausemanager.cpp app/system.cpp @@ -75,6 +74,12 @@ common/misc.cpp common/profile.cpp common/restext.cpp common/stringutils.cpp +common/resources/resourcemanager.cpp +common/resources/inputstreambuffer.cpp +common/resources/outputstreambuffer.cpp +common/resources/inputstream.cpp +common/resources/outputstream.cpp +common/resources/sndfile.cpp graphics/core/color.cpp graphics/engine/camera.cpp graphics/engine/cloud.cpp @@ -202,6 +207,7 @@ ${Boost_LIBRARIES} ${LIBSNDFILE_LIBRARY} ${OPTIONAL_LIBS} ${PLATFORM_LIBS} +${PHYSFS_LIBRARY} ) # Local @@ -224,6 +230,7 @@ ${LIBSNDFILE_INCLUDE_DIR} ${LOCALENAME_INCLUDE_DIR} ${OPTIONAL_INCLUDE_DIRS} ${CLIPBOARD_INCLUDE_DIR} +${PHYSFS_INCLUDE_PATH} ) link_directories(${CMAKE_CURRENT_SOURCE_DIR}/CBot) diff --git a/src/app/app.cpp b/src/app/app.cpp index 8b310c9..c245838 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -19,7 +19,6 @@ #include "app/app.h" -#include "app/gamedata.h" #include "app/system.h" #include "common/logger.h" @@ -27,6 +26,7 @@ #include "common/image.h" #include "common/key.h" #include "common/stringutils.h" +#include "common/resources/resourcemanager.h" #include "graphics/engine/modelmanager.h" #include "graphics/opengl/gldevice.h" @@ -101,7 +101,6 @@ CApplication::CApplication() m_objMan = new CObjectManager(); m_eventQueue = new CEventQueue(); m_profile = new CProfile(); - m_gameData = new CGameData(); m_engine = nullptr; m_device = nullptr; @@ -112,7 +111,6 @@ CApplication::CApplication() m_exitCode = 0; m_active = false; m_debugModes = 0; - m_customDataPath = false; m_windowTitle = "COLOBOT GOLD"; @@ -149,9 +147,6 @@ CApplication::CApplication() m_mouseButtonsState = 0; m_trackedKeys = 0; - m_dataPath = GetSystemUtils()->GetDataPath(); - m_langPath = GetSystemUtils()->GetLangPath(); - m_runSceneName = ""; m_runSceneRank = 0; @@ -180,9 +175,6 @@ CApplication::~CApplication() delete m_iMan; m_iMan = nullptr; - - delete m_gameData; - m_gameData = nullptr; GetSystemUtils()->DestroyTimeStamp(m_baseTimeStamp); GetSystemUtils()->DestroyTimeStamp(m_curTimeStamp); @@ -215,8 +207,6 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) OPT_SCENETEST, OPT_LOGLEVEL, OPT_LANGUAGE, - OPT_DATADIR, - OPT_MOD, OPT_LANGDIR, OPT_VBO }; @@ -229,8 +219,6 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) { "scenetest", no_argument, nullptr, OPT_SCENETEST }, { "loglevel", required_argument, nullptr, OPT_LOGLEVEL }, { "language", required_argument, nullptr, OPT_LANGUAGE }, - { "datadir", required_argument, nullptr, OPT_DATADIR }, - { "mod", required_argument, nullptr, OPT_MOD }, { "langdir", required_argument, nullptr, OPT_LANGDIR }, { "vbo", required_argument, nullptr, OPT_VBO }, { nullptr, 0, nullptr, 0} @@ -269,8 +257,6 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) GetLogger()->Message(" -scenetest win every mission right after it's loaded\n"); GetLogger()->Message(" -loglevel level set log level to level (one of: trace, debug, info, warn, error, none)\n"); GetLogger()->Message(" -language lang set language (one of: en, de, fr, pl, ru)\n"); - GetLogger()->Message(" -datadir path set custom data directory path\n"); - GetLogger()->Message(" -mod path run mod\n"); GetLogger()->Message(" -langdir path set custom language directory path\n"); GetLogger()->Message(" -vbo mode set OpenGL VBO mode (one of: auto, enable, disable)\n"); return PARSE_ARGS_HELP; @@ -334,25 +320,6 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) m_language = language; break; } - case OPT_DATADIR: - { - m_dataPath = optarg; - m_customDataPath = true; - GetLogger()->Info("Using datadir: '%s'\n", optarg); - break; - } - case OPT_MOD: - { - m_gameData->AddMod(std::string(optarg)); - GetLogger()->Info("Running mod from path: '%s'\n", optarg); - break; - } - case OPT_LANGDIR: - { - m_langPath = optarg; - GetLogger()->Info("Using language dir: '%s'\n", m_langPath.c_str()); - break; - } case OPT_VBO: { std::string vbo; @@ -391,25 +358,17 @@ bool CApplication::Create() GetLogger()->Warn("Config not found. Default values will be used!\n"); defaultValues = true; } - else - { - if (!m_customDataPath && GetProfile().GetLocalProfileString("Resources", "Data", path)) - m_dataPath = path; - } - boost::filesystem::path dataPath(m_dataPath); + boost::filesystem::path dataPath(COLOBOT_DEFAULT_DATADIR); if (! (boost::filesystem::exists(dataPath) && boost::filesystem::is_directory(dataPath)) ) { - GetLogger()->Error("Data directory '%s' doesn't exist or is not a directory\n", m_dataPath.c_str()); + GetLogger()->Error("Data directory '%s' doesn't exist or is not a directory\n", COLOBOT_DEFAULT_DATADIR); m_errorMessage = std::string("Could not read from data directory:\n") + - std::string("'") + m_dataPath + std::string("'\n") + + std::string("'") + COLOBOT_DEFAULT_DATADIR + std::string("'\n") + std::string("Please check your installation, or supply a valid data directory by -datadir option."); m_exitCode = 1; return false; } - - m_gameData->SetDataDir(std::string(m_dataPath)); - m_gameData->Init(); if (GetProfile().GetLocalProfileString("Language", "Lang", path)) { Language language; @@ -1727,7 +1686,7 @@ void CApplication::SetLanguage(Language language) setlocale(LC_ALL, ""); - bindtextdomain("colobot", m_langPath.c_str()); + bindtextdomain("colobot", CResourceManager::GetLanguageLocation().c_str()); bind_textdomain_codeset("colobot", "UTF-8"); textdomain("colobot"); diff --git a/src/app/app.h b/src/app/app.h index 86a757f..66b8900 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -42,7 +42,6 @@ class CInstanceManager; class CEventQueue; class CRobotMain; class CSoundInterface; -class CGameData; namespace Gfx { class CModelManager; @@ -402,8 +401,6 @@ protected: CRobotMain* m_robotMain; //! Profile (INI) reader/writer CProfile* m_profile; - //! Game data - CGameData* m_gameData; //! Code to return at exit int m_exitCode; @@ -467,16 +464,7 @@ protected: std::vector<int> m_joyAxeState; //! Current state of joystick buttons; may be updated from another thread std::vector<bool> m_joyButtonState; - - //! Path to directory with data files - std::string m_dataPath; - - //! True if datadir was passed in command line - bool m_customDataPath; - - //! Path to directory with language files - std::string m_langPath; - + //@{ //! Scene to run on startup std::string m_runSceneName; diff --git a/src/app/gamedata.cpp b/src/app/gamedata.cpp deleted file mode 100644 index ceeb7b3..0000000 --- a/src/app/gamedata.cpp +++ /dev/null @@ -1,136 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 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 "app/gamedata.h" - - -#include "app/app.h" - -#include <boost/filesystem.hpp> - -template<> CGameData* CSingleton<CGameData>::m_instance = nullptr; - -CGameData::CGameData() -{ - m_dataDirSet = false; - - for (int i = 0; i < DIR_MAX; ++i) - m_standardDataDirs[i] = nullptr; - - m_standardDataDirs[DIR_AI] = "ai"; - m_standardDataDirs[DIR_FONT] = "fonts"; - m_standardDataDirs[DIR_HELP] = "help"; - m_standardDataDirs[DIR_ICON] = "icons"; - m_standardDataDirs[DIR_LEVEL] = "levels"; - m_standardDataDirs[DIR_MODEL] = "models"; - m_standardDataDirs[DIR_MUSIC] = "music"; - m_standardDataDirs[DIR_SOUND] = "sounds"; - m_standardDataDirs[DIR_TEXTURE] = "textures"; -} - -CGameData::~CGameData() -{ -} - -void CGameData::SetDataDir(std::string path) -{ - assert(!m_dataDirSet); - m_dataDirSet = true; - - m_dataDirs.insert(m_dataDirs.begin(), path); -} - -void CGameData::AddMod(std::string path) -{ - m_dataDirs.push_back(path); -} - -void CGameData::Init() -{ - std::string out = "Using datadirs: "; - bool first = true; - for(std::vector<std::string>::reverse_iterator rit = m_dataDirs.rbegin(); rit != m_dataDirs.rend(); ++rit) { - if(!first) out += ", "; - first = false; - out += *rit; - } - out += "\n"; - CLogger::GetInstancePointer()->Info(out.c_str()); -} - -std::string CGameData::GetFilePath(DataDir dir, const std::string& subpath) -{ - int index = static_cast<int>(dir); - assert(index >= 0 && index < DIR_MAX); - - for(std::vector<std::string>::reverse_iterator rit = m_dataDirs.rbegin(); rit != m_dataDirs.rend(); ++rit) { - std::stringstream str; - - if ( subpath.find("save") == std::string::npos ){ // if its NOT a path to a savefile screenshot - str << *rit; - str << "/"; - str << m_standardDataDirs[index]; - - if (dir == DIR_HELP) - { - str << "/"; - str << CApplication::GetInstancePointer()->GetLanguageChar(); - } - str << "/"; - } - - str << subpath; - - boost::filesystem::path path(str.str()); - if(boost::filesystem::exists(path)) - { - return str.str(); - } - } - - if(m_dataDirs.size() > 0) { - std::stringstream str; - if ( subpath.find("save") == std::string::npos ){ // if its NOT a path to a savefile screenshot - str << m_dataDirs[0]; - str << "/"; - str << m_standardDataDirs[index]; - - if (dir == DIR_HELP) - { - str << "/"; - str << CApplication::GetInstancePointer()->GetLanguageChar(); - } - str << "/"; - } - str << subpath; - return str.str(); - } - - return subpath; -} - -std::string CGameData::GetDataPath(const std::string &subpath) -{ - for(std::vector<std::string>::reverse_iterator rit = m_dataDirs.rbegin(); rit != m_dataDirs.rend(); ++rit) { - std::string path = *rit + "/" + subpath; - boost::filesystem::path boostPath(path); - if(boost::filesystem::exists(boostPath)) - { - return path; - } - } - return m_dataDirs[0] + "/" + subpath; -} diff --git a/src/app/gamedata.h b/src/app/gamedata.h deleted file mode 100644 index b7536a2..0000000 --- a/src/app/gamedata.h +++ /dev/null @@ -1,66 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 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/. - -/** - * \file app/gamedata.h - * \brief Game data - */ - -#pragma once - -#include "common/singleton.h" - -#include <string> -#include <vector> - -/** - * \enum DataDir - * \brief Directories in data directory - */ -enum DataDir -{ - DIR_AI, //! < ai scripts - DIR_FONT, //! < fonts - DIR_HELP, //! < help files - DIR_ICON, //! < icons & images - DIR_LEVEL, //! < levels - DIR_MODEL, //! < models - DIR_MUSIC, //! < music - DIR_SOUND, //! < sounds - DIR_TEXTURE, //! < textures - - DIR_MAX //! < number of dirs -}; - -class CGameData : public CSingleton<CGameData> -{ -public: - CGameData(); - ~CGameData(); - - void Init(); - void SetDataDir(std::string path); - void AddMod(std::string path); - - std::string GetFilePath(DataDir dir, const std::string &subpath); - std::string GetDataPath(const std::string &subpath); - -private: - bool m_dataDirSet; - std::vector<std::string> m_dataDirs; - const char* m_standardDataDirs[DIR_MAX]; -}; - diff --git a/src/app/main.cpp b/src/app/main.cpp index 5c0afd3..324acc2 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -69,6 +69,7 @@ The current layout is the following: - src/script - link with the CBot library */ +#include "common/resources/resourcemanager.h" //! Entry point to the program extern "C" @@ -77,6 +78,8 @@ extern "C" int SDL_MAIN_FUNC(int argc, char *argv[]) { CLogger logger; // single istance of logger + CResourceManager manager(argv[0]); + manager.AddLocation(COLOBOT_DEFAULT_DATADIR); // Initialize static string arrays InitializeRestext(); diff --git a/src/app/system.cpp b/src/app/system.cpp index eaa9e4c..b2e6b47 100644 --- a/src/app/system.cpp +++ b/src/app/system.cpp @@ -192,23 +192,7 @@ float CSystemUtils::TimeStampDiff(SystemTimeStamp *before, SystemTimeStamp *afte return result; } -std::string CSystemUtils::GetDataPath() -{ - return COLOBOT_DEFAULT_DATADIR; -} - -std::string CSystemUtils::GetLangPath() -{ - return COLOBOT_I18N_DIR; -} - std::string CSystemUtils::GetProfileFileLocation() { return std::string("colobot.ini"); } - -std::string CSystemUtils::GetSavegameDirectoryLocation() -{ - return std::string("savegame"); -} - diff --git a/src/app/system.h b/src/app/system.h index c2125fe..01f2672 100644 --- a/src/app/system.h +++ b/src/app/system.h @@ -130,17 +130,8 @@ public: /** The difference is \a after - \a before. */ virtual long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after) = 0; - //! Returns the data path (containing textures, levels, helpfiles, etc) - virtual std::string GetDataPath(); - - //! Returns the translations path - virtual std::string GetLangPath(); - //! Returns the profile (colobot.ini) file location virtual std::string GetProfileFileLocation(); - - //! Returns the savegame directory location - virtual std::string GetSavegameDirectoryLocation(); }; //! Global function to get CSystemUtils instance diff --git a/src/app/system_linux.cpp b/src/app/system_linux.cpp index 492af7d..e584cd1 100644 --- a/src/app/system_linux.cpp +++ b/src/app/system_linux.cpp @@ -121,31 +121,3 @@ std::string CSystemUtilsLinux::GetProfileFileLocation() return profileFile; } - -std::string CSystemUtilsLinux::GetSavegameDirectoryLocation() -{ - std::string savegameDir; - - // Determine savegame dir according to XDG Base Directory Specification - char *envXDG_DATA_HOME = getenv("XDG_CONFIG_DATA"); - if (envXDG_DATA_HOME == NULL) - { - char *envHOME = getenv("HOME"); - if (envHOME == NULL) - { - savegameDir = "/tmp/colobot-savegame"; - } - else - { - savegameDir = std::string(envHOME) + "/.local/share/colobot"; - } - } - else - { - savegameDir = std::string(envXDG_DATA_HOME) + "/colobot"; - } - GetLogger()->Trace("Saved game files are going to %s\n", savegameDir.c_str()); - - return savegameDir; -} - diff --git a/src/app/system_linux.h b/src/app/system_linux.h index 212d840..ad26454 100644 --- a/src/app/system_linux.h +++ b/src/app/system_linux.h @@ -47,7 +47,6 @@ public: virtual long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after) override; virtual std::string GetProfileFileLocation() override; - virtual std::string GetSavegameDirectoryLocation() override; private: bool m_zenityAvailable; diff --git a/src/app/system_macosx.cpp b/src/app/system_macosx.cpp index 68f5c79..38885eb 100644 --- a/src/app/system_macosx.cpp +++ b/src/app/system_macosx.cpp @@ -87,16 +87,6 @@ void CSystemUtilsMacOSX::Init() m_dataPath += "/Contents/Resources"; } -std::string CSystemUtilsMacOSX::GetDataPath() -{ - return m_dataPath; -} - -std::string CSystemUtilsMacOSX::GetLangPath() -{ - return m_dataPath + "/i18n"; -} - std::string CSystemUtilsMacOSX::GetProfileFileLocation() { std::string profileFile = m_ASPath + "/colobot.ini"; @@ -104,13 +94,3 @@ std::string CSystemUtilsMacOSX::GetProfileFileLocation() GetLogger()->Trace("Profile file is %s\n", profileFile.c_str()); return profileFile; } - -std::string CSystemUtilsMacOSX::GetSavegameDirectoryLocation() -{ - std::string savegameDir = m_ASPath + "/savegame"; - boost::filesystem::create_directories(savegameDir.c_str()); - GetLogger()->Trace("Saved game files are going to %s\n", savegameDir.c_str()); - - return savegameDir; -} - diff --git a/src/app/system_macosx.h b/src/app/system_macosx.h index b6a044b..7360af1 100644 --- a/src/app/system_macosx.h +++ b/src/app/system_macosx.h @@ -28,10 +28,7 @@ class CSystemUtilsMacOSX : public CSystemUtilsOther public: virtual void Init() override; - virtual std::string GetDataPath() override; - virtual std::string GetLangPath() override; virtual std::string GetProfileFileLocation() override; - virtual std::string GetSavegameDirectoryLocation() override; private: std::string m_ASPath; std::string m_dataPath; diff --git a/src/app/system_windows.cpp b/src/app/system_windows.cpp index f48d4e0..ffaa18a 100644 --- a/src/app/system_windows.cpp +++ b/src/app/system_windows.cpp @@ -128,22 +128,3 @@ std::string CSystemUtilsWindows::GetProfileFileLocation() return profileFile; } - -std::string CSystemUtilsWindows::GetSavegameDirectoryLocation() -{ - std::string savegameDir; - - char* envUSERPROFILE = getenv("USERPROFILE"); - if (envUSERPROFILE == NULL) - { - savegameDir = "savegame"; - } - else - { - savegameDir = std::string(envUSERPROFILE) + "\\colobot\\savegame"; - } - GetLogger()->Trace("Saved game files are going to %s\n", savegameDir.c_str()); - - return savegameDir; -} - diff --git a/src/app/system_windows.h b/src/app/system_windows.h index fbc71a1..0a41c1a 100644 --- a/src/app/system_windows.h +++ b/src/app/system_windows.h @@ -45,7 +45,6 @@ public: virtual long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after) override; virtual std::string GetProfileFileLocation() override; - virtual std::string GetSavegameDirectoryLocation() override; private: std::string UTF8_Encode(const std::wstring &wstr); diff --git a/src/common/image.cpp b/src/common/image.cpp index e3d1ef7..dd905a7 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -18,6 +18,7 @@ #include "common/image.h" #include "math/func.h" +#include "common/resources/resourcemanager.h" #include <stdlib.h> #include <stdio.h> @@ -381,7 +382,16 @@ bool CImage::Load(const std::string& fileName) m_error = ""; - m_data->surface = IMG_Load(fileName.c_str()); + SDL_RWops* pointer = CResourceManager::GetSDLFileHandler(fileName.c_str()); + if (pointer == nullptr) + { + delete m_data; + m_data = nullptr; + + m_error = "Unable to open file"; + return false; + } + m_data->surface = IMG_Load_RW(pointer, 1); if (m_data->surface == nullptr) { delete m_data; @@ -458,4 +468,4 @@ void CImage::flipVertically(){ SDL_FreeSurface(m_data->surface); m_data->surface = result; -}
\ No newline at end of file +} diff --git a/src/common/resources/inputstream.cpp b/src/common/resources/inputstream.cpp new file mode 100644 index 0000000..b5ba63f --- /dev/null +++ b/src/common/resources/inputstream.cpp @@ -0,0 +1,53 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 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 "common/resources/inputstream.h" +#include "common/resources/inputstreambuffer.h" + + +CInputStream::CInputStream() : std::istream(new CInputStreamBuffer()) +{ +} + + +CInputStream::~CInputStream() +{ + delete rdbuf(); +} + + +void CInputStream::open(const std::string& filename) +{ + static_cast<CInputStreamBuffer *>(rdbuf())->open(filename); +} + + +void CInputStream::close() +{ + static_cast<CInputStreamBuffer *>(rdbuf())->close(); +} + + +bool CInputStream::is_open() +{ + return static_cast<CInputStreamBuffer *>(rdbuf())->is_open(); +} + + +size_t CInputStream::size() +{ + return static_cast<CInputStreamBuffer *>(rdbuf())->size(); +} diff --git a/src/common/resources/inputstream.h b/src/common/resources/inputstream.h new file mode 100644 index 0000000..9d1c578 --- /dev/null +++ b/src/common/resources/inputstream.h @@ -0,0 +1,33 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 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 <istream> +#include <string> + + +class CInputStream : public std::istream +{ +public: + CInputStream(); + virtual ~CInputStream(); + + void open(const std::string &filename); + void close(); + bool is_open(); + size_t size(); +}; diff --git a/src/common/resources/inputstreambuffer.cpp b/src/common/resources/inputstreambuffer.cpp new file mode 100644 index 0000000..b8710e9 --- /dev/null +++ b/src/common/resources/inputstreambuffer.cpp @@ -0,0 +1,129 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 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 "common/resources/inputstreambuffer.h" + +#include <stdexcept> +#include <sstream> + +CInputStreamBuffer::CInputStreamBuffer(size_t buffer_size) : m_buffer_size(buffer_size) +{ + if (buffer_size <= 0) + { + throw std::runtime_error("File buffer must be larger then 0 bytes"); + } + + m_buffer = new char[buffer_size]; + m_file = nullptr; +} + + +CInputStreamBuffer::~CInputStreamBuffer() +{ + close(); + delete m_buffer; +} + + +void CInputStreamBuffer::open(const std::string &filename) +{ + if (PHYSFS_isInit()) + m_file = PHYSFS_openRead(filename.c_str()); +} + + +void CInputStreamBuffer::close() +{ + if (is_open()) + PHYSFS_close(m_file); +} + + +bool CInputStreamBuffer::is_open() +{ + return m_file; +} + + +size_t CInputStreamBuffer::size() +{ + return PHYSFS_fileLength(m_file); +} + + +std::streambuf::int_type CInputStreamBuffer::underflow() +{ + if (gptr() < egptr()) + return traits_type::to_int_type(*gptr()); + + if (PHYSFS_eof(m_file)) + return traits_type::eof(); + + PHYSFS_sint64 read_count = PHYSFS_read(m_file, m_buffer, sizeof(char), m_buffer_size); + if (read_count <= 0) + return traits_type::eof(); + + setg(m_buffer, m_buffer, m_buffer + read_count); + + return traits_type::to_int_type(*gptr()); +} + + +std::streampos CInputStreamBuffer::seekpos(std::streampos sp, std::ios_base::openmode which) +{ + return seekoff(off_type(sp), std::ios_base::beg, which); +} + + +std::streampos CInputStreamBuffer::seekoff(std::streamoff off, std::ios_base::seekdir way, std::ios_base::openmode which) +{ + /* A bit of explanation: + We are reading file by m_buffer_size parts so our 3 internal pointers will be + * eback (not used here) - start of block + * gptr - position of read cursor in block + * egtpr - end of block + off argument is relative to way */ + + std::streamoff new_position; + + switch (way) + { + case std::ios_base::beg: + new_position = off; + break; + + case std::ios_base::cur: + // tell will give cursor at begining of block so we have to add where in block we currently are + new_position = off + static_cast<off_type>(PHYSFS_tell(m_file)) - static_cast<off_type> (egptr() - gptr()); + break; + + case std::ios_base::end: + new_position = off + static_cast<off_type>(PHYSFS_fileLength(m_file)); + break; + + default: + break; + } + + if (PHYSFS_seek(m_file, new_position)) + { + setg(m_buffer, m_buffer, m_buffer); // reset buffer + + return pos_type(new_position); + } + + return pos_type(off_type(-1)); +} diff --git a/src/common/resources/inputstreambuffer.h b/src/common/resources/inputstreambuffer.h new file mode 100644 index 0000000..93cb43c --- /dev/null +++ b/src/common/resources/inputstreambuffer.h @@ -0,0 +1,48 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 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 <streambuf> +#include <string> +#include <physfs.h> + +class CInputStreamBuffer : public std::streambuf +{ +public: + CInputStreamBuffer(size_t buffer_size = 512); + virtual ~CInputStreamBuffer(); + + void open(const std::string &filename); + void close(); + bool is_open(); + size_t size(); + +private: + int_type underflow(); + + std::streampos seekpos(std::streampos sp, std::ios_base::openmode which); + std::streampos seekoff(std::streamoff off, std::ios_base::seekdir way, std::ios_base::openmode which); + + // copy ctor and assignment not implemented; + // copying not allowed + CInputStreamBuffer(const CInputStreamBuffer &); + CInputStreamBuffer &operator= (const CInputStreamBuffer &); + + PHYSFS_File *m_file; + char *m_buffer; + size_t m_buffer_size; +}; diff --git a/src/common/resources/outputstream.cpp b/src/common/resources/outputstream.cpp new file mode 100644 index 0000000..ba43ba6 --- /dev/null +++ b/src/common/resources/outputstream.cpp @@ -0,0 +1,47 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 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 "common/resources/outputstream.h" +#include "common/resources/outputstreambuffer.h" + + +COutputStream::COutputStream() : std::ostream(new COutputStreamBuffer()) +{ +} + + +COutputStream::~COutputStream() +{ + delete rdbuf(); +} + + +void COutputStream::open(const std::string& filename) +{ + static_cast<COutputStreamBuffer *>(rdbuf())->open(filename); +} + + +void COutputStream::close() +{ + static_cast<COutputStreamBuffer *>(rdbuf())->close(); +} + + +bool COutputStream::is_open() +{ + return static_cast<COutputStreamBuffer *>(rdbuf())->is_open(); +} diff --git a/src/common/resources/outputstream.h b/src/common/resources/outputstream.h new file mode 100644 index 0000000..4f4cd72 --- /dev/null +++ b/src/common/resources/outputstream.h @@ -0,0 +1,32 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 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 <ostream> +#include <string> + + +class COutputStream : public std::ostream +{ +public: + COutputStream(); + virtual ~COutputStream(); + + void open(const std::string &filename); + void close(); + bool is_open(); +}; diff --git a/src/common/resources/outputstreambuffer.cpp b/src/common/resources/outputstreambuffer.cpp new file mode 100644 index 0000000..e611d13 --- /dev/null +++ b/src/common/resources/outputstreambuffer.cpp @@ -0,0 +1,85 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 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 "common/resources/outputstreambuffer.h" + +#include <stdexcept> +#include <sstream> + +COutputStreamBuffer::COutputStreamBuffer(size_t buffer_size) : m_buffer_size(buffer_size) +{ + m_file = nullptr; + m_buffer = new char[buffer_size]; + setp(m_buffer, m_buffer + buffer_size); +} + + +COutputStreamBuffer::~COutputStreamBuffer() +{ + close(); + delete m_buffer; +} + + +void COutputStreamBuffer::open(const std::string &filename) +{ + if (PHYSFS_isInit()) + m_file = PHYSFS_openWrite(filename.c_str()); +} + + +void COutputStreamBuffer::close() +{ + if (is_open()) + PHYSFS_close(m_file); +} + + +bool COutputStreamBuffer::is_open() +{ + return m_file; +} + + +std::streambuf::int_type COutputStreamBuffer::overflow(std::streambuf::int_type ch) +{ + /* This function should be called when pptr() == epptr(). We use it also in sync() + so we also have to write data if buffer is not full. */ + + if (pbase() == pptr()) // no data to write, sync() called with empty buffer + return 0; + + // save buffer + PHYSFS_sint64 bytes_written = PHYSFS_write(m_file, pbase(), 1, pptr() - pbase()); + if (bytes_written <= 0) + return traits_type::eof(); + + pbump(-bytes_written); + // write final char + if (ch != traits_type::eof()) { + bytes_written = PHYSFS_write(m_file, &ch, 1, 1); + if (bytes_written <= 0) + return traits_type::eof(); + } + + return ch; +} + + +int COutputStreamBuffer::sync() +{ + return overflow(traits_type::eof()); +} diff --git a/src/common/resources/outputstreambuffer.h b/src/common/resources/outputstreambuffer.h new file mode 100644 index 0000000..1d98791 --- /dev/null +++ b/src/common/resources/outputstreambuffer.h @@ -0,0 +1,45 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 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 <streambuf> +#include <string> +#include <physfs.h> + +class COutputStreamBuffer : public std::streambuf +{ +public: + COutputStreamBuffer(size_t buffer_size = 512); + virtual ~COutputStreamBuffer(); + + void open(const std::string &filename); + void close(); + bool is_open(); + +private: + int_type overflow(int_type ch); + int sync(); + + // copy ctor and assignment not implemented; + // copying not allowed + COutputStreamBuffer(const COutputStreamBuffer &); + COutputStreamBuffer &operator= (const COutputStreamBuffer &); + + PHYSFS_File *m_file; + char *m_buffer; + size_t m_buffer_size; +}; diff --git a/src/common/resources/resourcemanager.cpp b/src/common/resources/resourcemanager.cpp new file mode 100644 index 0000000..5e8627d --- /dev/null +++ b/src/common/resources/resourcemanager.cpp @@ -0,0 +1,212 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 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 "common/resources/resourcemanager.h" + +#include "common/config.h" + +#include <physfs.h> + + +CResourceManager::CResourceManager(const char *argv0) +{ + if (PHYSFS_init(argv0)) + { + // TODO error + } +} + + +CResourceManager::~CResourceManager() +{ + if (PHYSFS_isInit()) + { + if (PHYSFS_deinit()) + { + // TODO error + } + } +} + + +bool CResourceManager::AddLocation(const std::string &location, bool prepend) +{ + if (PHYSFS_isInit()) + { + if (PHYSFS_mount(location.c_str(), nullptr, prepend ? 0 : 1)) + { + // TODO error + } + } + + return false; +} + + +bool CResourceManager::RemoveLocation(const std::string &location) +{ + if (PHYSFS_isInit()) + { + if (PHYSFS_removeFromSearchPath(location.c_str())) + { + // TODO error + } + } + + return false; +} + + +bool CResourceManager::SetSaveLocation(const std::string &location) +{ + if (PHYSFS_isInit()) + { + if (PHYSFS_setWriteDir(location.c_str())) + { + // TODO error + } + } + + return false; +} + + +std::string CResourceManager::GetLanguageLocation() +{ + return COLOBOT_I18N_DIR; +} + + +SDL_RWops* CResourceManager::GetSDLFileHandler(const std::string &filename) +{ + SDL_RWops *handler = SDL_AllocRW(); + if (!handler) + { + // TODO error + return nullptr; + } + + if (!PHYSFS_isInit()) + { + SDL_FreeRW(handler); + return nullptr; + } + + PHYSFS_File *file = PHYSFS_openRead(filename.c_str()); + if (!file) + { + SDL_FreeRW(handler); + return nullptr; + } + + handler->seek = SDLSeek; + handler->read = SDLRead; + handler->write = SDLWrite; + handler->close = SDLClose; + handler->type = 0xc010b04f; + handler->hidden.unknown.data1 = file; + + return handler; +} + + +CSNDFile* CResourceManager::GetSNDFileHandler(const std::string &filename) +{ + return new CSNDFile(filename); +} + + +bool CResourceManager::Exists(const std::string &filename) +{ + return PHYSFS_exists(filename.c_str()); +} + + +int CResourceManager::SDLClose(SDL_RWops *context) +{ + if (CheckSDLContext(context)) + { + PHYSFS_close(static_cast<PHYSFS_File *>(context->hidden.unknown.data1)); + SDL_FreeRW(context); + + return 0; + } + + return 1; +} + + +int CResourceManager::SDLRead(SDL_RWops *context, void *ptr, int size, int maxnum) +{ + if (CheckSDLContext(context)) + { + PHYSFS_File *file = static_cast<PHYSFS_File *>(context->hidden.unknown.data1); + SDL_memset(ptr, 0, size * maxnum); + + return PHYSFS_read(file, ptr, size, maxnum); + } + + return 0; +} + + +int CResourceManager::SDLWrite(SDL_RWops *context, const void *ptr, int size, int num) +{ + return 0; +} + + +int CResourceManager::SDLSeek(SDL_RWops *context, int offset, int whence) +{ + if (CheckSDLContext(context)) + { + PHYSFS_File *file = static_cast<PHYSFS_File *>(context->hidden.unknown.data1); + int position, result; + + switch (whence) + { + default: + case RW_SEEK_SET: + result = PHYSFS_seek(file, offset); + return result > 0 ? offset : -1; + + case RW_SEEK_CUR: + position = offset + PHYSFS_tell(file); + result = PHYSFS_seek(file, position); + return result > 0 ? position : -1; + + case RW_SEEK_END: + position = PHYSFS_fileLength(file) - offset; + result = PHYSFS_seek(file, position); + return result > 0 ? position : -1; + } + } + + return -1; +} + + +bool CResourceManager::CheckSDLContext(SDL_RWops *context) +{ + if (context->type != 0xc010b04f) + { + SDL_SetError("Wrong kind of RWops"); + return false; + } + + return true; +} diff --git a/src/common/resources/resourcemanager.h b/src/common/resources/resourcemanager.h new file mode 100644 index 0000000..36f6fa5 --- /dev/null +++ b/src/common/resources/resourcemanager.h @@ -0,0 +1,44 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 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 <string> +#include <SDL.h> + +#include "common/resources/sndfile.h" + +class CResourceManager +{ +public: + CResourceManager(const char *argv0); + ~CResourceManager(); + + static bool AddLocation(const std::string &location, bool prepend = true); + static bool RemoveLocation(const std::string &location); + static bool SetSaveLocation(const std::string &location); + static std::string GetLanguageLocation(); + static SDL_RWops* GetSDLFileHandler(const std::string &filename); + static CSNDFile* GetSNDFileHandler(const std::string &filename); + static bool Exists(const std::string &filename); + +private: + static int SDLSeek(SDL_RWops *context, int offset, int whence); + static int SDLRead(SDL_RWops *context, void *ptr, int size, int maxnum); + static int SDLWrite(SDL_RWops *context, const void *ptr, int size, int num); + static int SDLClose(SDL_RWops *context); + static bool CheckSDLContext(SDL_RWops *context); +}; diff --git a/src/common/resources/resourcestreambuffer.cpp b/src/common/resources/resourcestreambuffer.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/common/resources/resourcestreambuffer.cpp diff --git a/src/common/resources/resourcestreambuffer.h b/src/common/resources/resourcestreambuffer.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/common/resources/resourcestreambuffer.h diff --git a/src/common/resources/sndfile.cpp b/src/common/resources/sndfile.cpp new file mode 100644 index 0000000..9e8e729 --- /dev/null +++ b/src/common/resources/sndfile.cpp @@ -0,0 +1,130 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 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 "common/resources/sndfile.h" + +#include <cstring> + + +CSNDFile::CSNDFile(const std::string& filename) +{ + memset(&m_file_info, 0, sizeof(SF_INFO)); + + if (PHYSFS_isInit()) + { + m_file = PHYSFS_openRead(filename.c_str()); + } + else + { + m_last_error = "Resource system not started!"; + } + + if (m_file) + { + m_snd_file = sf_open_virtual(&snd_callbacks, SFM_READ, &m_file_info, m_file); + if (!m_snd_file) + { + m_last_error = "Could not load file"; + } + } + else + { + m_last_error = std::string(PHYSFS_getLastError()); + } +} + + +CSNDFile::~CSNDFile() +{ + if (m_file) + { + PHYSFS_close(m_file); + } + + if (m_snd_file) + { + sf_close(m_snd_file); + } +} + + +bool CSNDFile::IsOpen() +{ + return m_snd_file; +} + + +SF_INFO &CSNDFile::GetFileInfo() +{ + return m_file_info; +} + + +std::string& CSNDFile::GetLastError() +{ + return m_last_error; +} + + +sf_count_t CSNDFile::Read(short int *ptr, sf_count_t items) +{ + return sf_read_short(m_snd_file, ptr, items); +} + + +sf_count_t CSNDFile::SNDLength(void *data) +{ + return PHYSFS_fileLength(static_cast<PHYSFS_File *>(data)); +} + + +sf_count_t CSNDFile::SNDRead(void *ptr, sf_count_t count, void *data) +{ + return PHYSFS_read(static_cast<PHYSFS_File *>(data), ptr, 1, count); +} + + +sf_count_t CSNDFile::SNDSeek(sf_count_t offset, int whence, void *data) +{ + PHYSFS_File *file = static_cast<PHYSFS_File *>(data); + + switch(whence) + { + case SEEK_CUR: + PHYSFS_seek(file, PHYSFS_tell(file) + offset); + break; + case SEEK_SET: + PHYSFS_seek(file, offset); + break; + case SEEK_END: + PHYSFS_seek(file, PHYSFS_fileLength(file) + offset); + break; + } + + return PHYSFS_tell(file); +} + + +sf_count_t CSNDFile::SNDTell(void *data) +{ + return PHYSFS_tell(static_cast<PHYSFS_File *>(data)); +} + + +sf_count_t CSNDFile::SNDWrite(const void *ptr, sf_count_t count, void *data) +{ + return PHYSFS_write(static_cast<PHYSFS_File *>(data), ptr, 1, count); +} diff --git a/src/common/resources/sndfile.h b/src/common/resources/sndfile.h new file mode 100644 index 0000000..5ea6ccc --- /dev/null +++ b/src/common/resources/sndfile.h @@ -0,0 +1,54 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 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 <string> +#include <physfs.h> +#include <sndfile.h> + + +class CSNDFile +{ +public: + CSNDFile(const std::string &filename); + virtual ~CSNDFile(); + + SF_INFO &GetFileInfo(); + bool IsOpen(); + std::string &GetLastError(); + sf_count_t Read(short int *ptr, sf_count_t items); + +private: + static sf_count_t SNDLength(void *data); + static sf_count_t SNDSeek(sf_count_t offset, int whence, void *data); + static sf_count_t SNDRead(void *ptr, sf_count_t count, void *data); + static sf_count_t SNDWrite(const void *ptr, sf_count_t count, void *data); + static sf_count_t SNDTell(void *data); + + SF_INFO m_file_info; + SNDFILE *m_snd_file; + PHYSFS_File *m_file; + std::string m_last_error; + + SF_VIRTUAL_IO snd_callbacks = { + SNDLength, + SNDSeek, + SNDRead, + SNDWrite, + SNDTell + }; +}; diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index e0861d2..cfb794a 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -19,7 +19,6 @@ #include "graphics/engine/engine.h" #include "app/app.h" -#include "app/gamedata.h" #include "common/image.h" #include "common/key.h" @@ -283,7 +282,7 @@ bool CEngine::Create() params.minFilter = TEX_MIN_FILTER_NEAREST; params.magFilter = TEX_MAG_FILTER_NEAREST; params.mipmap = false; - m_miceTexture = LoadTexture("mouse.png", params); + m_miceTexture = LoadTexture("interface/mouse.png", params); GetSystemUtils()->GetCurrentTimeStamp(m_currentFrameTime); GetSystemUtils()->GetCurrentTimeStamp(m_lastFrameTime); @@ -2258,7 +2257,7 @@ Texture CEngine::CreateTexture(const std::string& texName, const TextureCreatePa if (image == nullptr) { - if (! img.Load(CGameData::GetInstancePointer()->GetFilePath(DIR_TEXTURE, texName))) + if (!img.Load("textures/"+texName)) { std::string error = img.GetError(); GetLogger()->Error("Couldn't load texture '%s': %s, blacklisting\n", texName.c_str(), error.c_str()); @@ -2309,15 +2308,15 @@ Texture CEngine::LoadTexture(const std::string& name, const TextureCreateParams& bool CEngine::LoadAllTextures() { - LoadTexture("text.png"); - m_miceTexture = LoadTexture("mouse.png"); - LoadTexture("button1.png"); - LoadTexture("button2.png"); - LoadTexture("button3.png"); - LoadTexture("effect00.png"); - LoadTexture("effect01.png"); - LoadTexture("effect02.png"); - LoadTexture("map.png"); + LoadTexture("interface/text.png"); + m_miceTexture = LoadTexture("interface/mouse.png"); + LoadTexture("interface/button1.png"); + LoadTexture("interface/button2.png"); + LoadTexture("interface/button3.png"); + LoadTexture("interface/effect00.png"); + LoadTexture("interface/effect01.png"); + LoadTexture("interface/effect02.png"); + LoadTexture("interface/map.png"); if (! m_backgroundName.empty()) { @@ -2426,7 +2425,7 @@ bool CEngine::ChangeTextureColor(const std::string& texName, CImage img; - if (! img.Load(CGameData::GetInstancePointer()->GetFilePath(DIR_TEXTURE, texName))) + if (!img.Load("textures/"+texName)) { std::string error = img.GetError(); GetLogger()->Error("Couldn't load texture '%s': %s, blacklisting\n", texName.c_str(), error.c_str()); @@ -3785,7 +3784,7 @@ void CEngine::DrawShadow() SetMaterial(material); // TODO: create a separate texture - SetTexture("text.png"); + SetTexture("interface/text.png"); Math::Point ts, ti; diff --git a/src/graphics/engine/lightning.cpp b/src/graphics/engine/lightning.cpp index 4395eec..b0e144c 100644 --- a/src/graphics/engine/lightning.cpp +++ b/src/graphics/engine/lightning.cpp @@ -235,7 +235,7 @@ void CLightning::Draw() mat.LoadIdentity(); device->SetTransform(TRANSFORM_WORLD, mat); - m_engine->SetTexture("effect00.png"); + m_engine->SetTexture("interface/effect00.png"); m_engine->SetState(ENG_RSTATE_TTEXTURE_BLACK); Math::Point texInf; diff --git a/src/graphics/engine/modelfile.cpp b/src/graphics/engine/modelfile.cpp index 99496aa..5f10ff1 100644 --- a/src/graphics/engine/modelfile.cpp +++ b/src/graphics/engine/modelfile.cpp @@ -22,6 +22,8 @@ #include "common/logger.h" #include "common/stringutils.h" +#include "common/resources/inputstream.h" + #include "graphics/engine/engine.h" #include "math/geometry.h" @@ -432,9 +434,9 @@ bool CModelFile::ReadModel(const std::string& fileName) { m_triangles.clear(); - std::ifstream stream; - stream.open(fileName.c_str(), std::ios_base::in | std::ios_base::binary); - if (!stream.good()) + CInputStream stream; + stream.open(fileName.c_str()); + if (!stream.is_open()) { GetLogger()->Error("Could not open file '%s'\n", fileName.c_str()); return false; @@ -823,9 +825,9 @@ struct NewModelTriangle1 bool CModelFile::ReadTextModel(const std::string& fileName) { - std::ifstream stream; - stream.open(fileName.c_str(), std::ios_base::in); - if (!stream.good()) + CInputStream stream; + stream.open(fileName.c_str()); + if (!stream.is_open()) { GetLogger()->Error("Could not open file '%s'\n", fileName.c_str()); return false; @@ -1020,9 +1022,9 @@ bool CModelFile::WriteTextModel(std::ostream& stream) bool CModelFile::ReadBinaryModel(const std::string& fileName) { - std::ifstream stream; - stream.open(fileName.c_str(), std::ios_base::in | std::ios_base::binary); - if (!stream.good()) + CInputStream stream; + stream.open(fileName.c_str()); + if (!stream.is_open()) { GetLogger()->Error("Could not open file '%s'\n", fileName.c_str()); return false; diff --git a/src/graphics/engine/modelmanager.cpp b/src/graphics/engine/modelmanager.cpp index 0c0fb98..6ee0b86 100644 --- a/src/graphics/engine/modelmanager.cpp +++ b/src/graphics/engine/modelmanager.cpp @@ -18,7 +18,6 @@ #include "graphics/engine/modelmanager.h" #include "app/app.h" -#include "app/gamedata.h" #include "common/logger.h" @@ -48,11 +47,9 @@ bool CModelManager::LoadModel(const std::string& fileName, bool mirrored) if (CApplication::GetInstance().IsDebugModeActive(DEBUG_MODELS)) modelFile.SetPrintDebugInfo(true); - std::string filePath = CGameData::GetInstancePointer()->GetFilePath(DIR_MODEL, fileName); - - if (!modelFile.ReadModel(filePath)) + if (!modelFile.ReadModel("models/" + fileName)) { - GetLogger()->Error("Loading model '%s' failed\n", filePath.c_str()); + GetLogger()->Error("Loading model '%s' failed\n", fileName.c_str()); return false; } diff --git a/src/graphics/engine/particle.cpp b/src/graphics/engine/particle.cpp index abee2e2..3dc8c0d 100644 --- a/src/graphics/engine/particle.cpp +++ b/src/graphics/engine/particle.cpp @@ -198,10 +198,10 @@ void CParticle::FlushParticle(int sheet) //! Returns file name of the effect effectNN.png, with NN = number void NameParticle(std::string &name, int num) { - if (num == 1) name = "effect00.png"; - else if (num == 2) name = "effect01.png"; - else if (num == 3) name = "effect02.png"; - else if (num == 4) name = "text.png"; + if (num == 1) name = "interface/effect00.png"; + else if (num == 2) name = "interface/effect01.png"; + else if (num == 3) name = "interface/effect02.png"; + else if (num == 4) name = "interface/text.png"; else name = ""; } @@ -3551,7 +3551,7 @@ void CParticle::DrawParticle(int sheet) // Draw tire marks. if (m_wheelTraceTotal > 0 && sheet == SH_WORLD) { - m_engine->SetTexture("text.png"); + m_engine->SetTexture("interface/text.png"); m_engine->SetState(ENG_RSTATE_TTEXTURE_WHITE); Math::Matrix matrix; matrix.LoadIdentity(); diff --git a/src/graphics/engine/terrain.cpp b/src/graphics/engine/terrain.cpp index 5f37cd8..6a8dc6b 100644 --- a/src/graphics/engine/terrain.cpp +++ b/src/graphics/engine/terrain.cpp @@ -19,7 +19,6 @@ #include "graphics/engine/terrain.h" #include "app/app.h" -#include "app/gamedata.h" #include "common/image.h" #include "common/logger.h" @@ -190,10 +189,10 @@ void CTerrain::AddMaterial(int id, const std::string& texName, const Math::Point bool CTerrain::LoadResources(const std::string& fileName) { CImage img; - std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_TEXTURE, fileName); - if (! img.Load(path)) + + if (! img.Load(fileName)) { - GetLogger()->Error("Cannot load resource file: '%s'\n", path.c_str()); + GetLogger()->Error("Cannot load resource file: '%s'\n", fileName.c_str()); return false; } @@ -287,10 +286,10 @@ bool CTerrain::LoadRelief(const std::string &fileName, float scaleRelief, m_scaleRelief = scaleRelief; CImage img; - std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_TEXTURE, fileName); - if (! img.Load(path)) + + if (! img.Load(fileName)) { - GetLogger()->Error("Could not load relief file: '%s'!\n", path.c_str()); + GetLogger()->Error("Could not load relief file: '%s'!\n", fileName.c_str()); return false; } @@ -366,17 +365,11 @@ bool CTerrain::RandomizeRelief() double xi, yi, a, b; a = modf(x * (rozmiar_oktawy-1), &xi); b = modf(y * (rozmiar_oktawy-1), &yi); - /*int xi = floor(x * (rozmiar_oktawy-1)); - int yi = floor(y * (rozmiar_oktawy-1)); - float a = (x * (rozmiar_oktawy-1)) - xi; - float b = (y * (rozmiar_oktawy-1)) - yi;*/ - //CLogger::GetInstancePointer()->Error("%f %f %f %f\n", xi, yi, a, b); float lg = oktawy[i][static_cast<int>(yi * rozmiar_oktawy + xi)]; float pg = oktawy[i][static_cast<int>(yi * rozmiar_oktawy + xi + 1)]; float ld = oktawy[i][static_cast<int>((yi+1) * rozmiar_oktawy + xi)]; float pd = oktawy[i][static_cast<int>((yi+1) * rozmiar_oktawy + xi + 1)]; - //CLogger::GetInstancePointer()->Error("%f %f %f %f\n", lg, pg, ld, pd); float g = pg * a + lg * (1-a); float d = pd * a + ld * (1-a); diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index 8fd01b7..78cf7b8 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -19,11 +19,11 @@ #include "graphics/engine/text.h" #include "app/app.h" -#include "app/gamedata.h" #include "common/image.h" #include "common/logger.h" #include "common/stringutils.h" +#include "common/resources/resourcemanager.h" #include "math/func.h" @@ -78,12 +78,12 @@ bool CText::Create() return false; } - m_fonts[FONT_COLOBOT] = new MultisizeFont("dvu_sans.ttf"); - m_fonts[FONT_COLOBOT_BOLD] = new MultisizeFont("dvu_sans_bold.ttf"); - m_fonts[FONT_COLOBOT_ITALIC] = new MultisizeFont("dvu_sans_italic.ttf"); + m_fonts[FONT_COLOBOT] = new MultisizeFont("fonts/dvu_sans.ttf"); + m_fonts[FONT_COLOBOT_BOLD] = new MultisizeFont("fonts/dvu_sans_bold.ttf"); + m_fonts[FONT_COLOBOT_ITALIC] = new MultisizeFont("fonts/dvu_sans_italic.ttf"); - m_fonts[FONT_COURIER] = new MultisizeFont("dvu_sans_mono.ttf"); - m_fonts[FONT_COURIER_BOLD] = new MultisizeFont("dvu_sans_mono_bold.ttf"); + m_fonts[FONT_COURIER] = new MultisizeFont("fonts/dvu_sans_mono.ttf"); + m_fonts[FONT_COURIER_BOLD] = new MultisizeFont("fonts/dvu_sans_mono_bold.ttf"); for (auto it = m_fonts.begin(); it != m_fonts.end(); ++it) { @@ -866,10 +866,8 @@ CachedFont* CText::GetOrOpenFont(FontType font, float size) return m_lastCachedFont; } - std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_FONT, mf->fileName); - m_lastCachedFont = new CachedFont(); - m_lastCachedFont->font = TTF_OpenFont(path.c_str(), pointSize); + m_lastCachedFont->font = TTF_OpenFontRW(CResourceManager::GetSDLFileHandler(mf->fileName), 1, pointSize); if (m_lastCachedFont->font == nullptr) m_error = std::string("TTF_OpenFont error ") + std::string(TTF_GetError()); diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 83b9fc9..8108129 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -20,7 +20,6 @@ #include "CBot/CBotDll.h" #include "app/app.h" -#include "app/gamedata.h" #include "common/event.h" #include "common/global.h" @@ -30,6 +29,8 @@ #include "common/profile.h" #include "common/restext.h" +#include "common/resources/inputstream.h" + #include "graphics/engine/camera.h" #include "graphics/engine/cloud.h" #include "graphics/engine/engine.h" @@ -3944,8 +3945,11 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) std::string tempLine; m_dialog->BuildSceneName(tempLine, base, rank); strcpy(filename, tempLine.c_str()); - FILE* file = fopen(filename, "r"); - if (file == NULL) return; + + CInputStream stream; + stream.open(filename); + + if (!stream.is_open()) return; int rankObj = 0; int rankGadget = 0; @@ -3958,7 +3962,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) * may speed up loading */ - while (fgets(line, 500, file) != NULL) + while (stream.getline(line, 500)) { lineNum++; for (int i = 0; i < 500; i++) @@ -4016,8 +4020,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (Cmd(line, "Instructions") && !resetObject) { OpString(line, "name", name); - std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_HELP, name); - strcpy(m_infoFilename[SATCOM_HUSTON], path.c_str()); + strcpy(m_infoFilename[SATCOM_HUSTON], name); m_immediatSatCom = OpInt(line, "immediat", 0); if (m_version >= 2) m_beginSatCom = m_lockedSatCom = OpInt(line, "lock", 0); @@ -4028,31 +4031,27 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (Cmd(line, "Satellite") && !resetObject) { OpString(line, "name", name); - std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_HELP, name); - strcpy(m_infoFilename[SATCOM_SAT], path.c_str()); + strcpy(m_infoFilename[SATCOM_SAT], name); continue; } if (Cmd(line, "Loading") && !resetObject) { OpString(line, "name", name); - std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_HELP, name); - strcpy(m_infoFilename[SATCOM_LOADING], path.c_str()); + strcpy(m_infoFilename[SATCOM_LOADING], name); continue; } if (Cmd(line, "HelpFile") && !resetObject) { OpString(line, "name", name); - std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_HELP, name); - strcpy(m_infoFilename[SATCOM_PROG], path.c_str()); + strcpy(m_infoFilename[SATCOM_PROG], name); continue; } if (Cmd(line, "SoluceFile") && !resetObject) { OpString(line, "name", name); - std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_HELP, name); - strcpy(m_infoFilename[SATCOM_SOLUCE], path.c_str()); + strcpy(m_infoFilename[SATCOM_SOLUCE], name); continue; } @@ -4309,7 +4308,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) } OpString(line, "image", name); - m_terrain->LoadRelief(name, OpFloat(line, "factor", 1.0f), OpInt(line, "border", 1)); + m_terrain->LoadRelief(std::string("textures/")+name, OpFloat(line, "factor", 1.0f), OpInt(line, "border", 1)); continue; } @@ -4340,7 +4339,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) } OpString(line, "image", name); - m_terrain->LoadResources(name); + m_terrain->LoadResources(std::string("textures/")+name); continue; } @@ -4999,7 +4998,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) GetLogger()->Error("Syntax error in file '%s' (line %d): Unknown command: %s", filename, lineNum, line); // Don't add \n at the end of log message - it's included in line variable } - fclose(file); + stream.close(); if (read[0] == 0) CompileScript(soluce); // compiles all scripts @@ -5239,12 +5238,12 @@ void CRobotMain::ChangeColor() // PARTIPLOUF0 and PARTIDROP : ts = Math::Point(0.500f, 0.500f); ti = Math::Point(0.875f, 0.750f); - m_engine->ChangeTextureColor("effect00.png", m_colorRefWater, m_colorNewWater, colorRef2, colorNew2, 0.20f, -1.0f, ts, ti, 0, m_colorShiftWater, true); + m_engine->ChangeTextureColor("interface/effect00.png", m_colorRefWater, m_colorNewWater, colorRef2, colorNew2, 0.20f, -1.0f, ts, ti, 0, m_colorShiftWater, true); // PARTIFLIC : ts = Math::Point(0.00f, 0.75f); ti = Math::Point(0.25f, 1.00f); - m_engine->ChangeTextureColor("effect02.png", m_colorRefWater, m_colorNewWater, colorRef2, colorNew2, 0.20f, -1.0f, ts, ti, 0, m_colorShiftWater, true); + m_engine->ChangeTextureColor("interface/effect02.png", m_colorRefWater, m_colorNewWater, colorRef2, colorNew2, 0.20f, -1.0f, ts, ti, 0, m_colorShiftWater, true); } //! Updates the number of unnecessary objects @@ -5678,11 +5677,12 @@ void CRobotMain::CompileScript(bool soluce) { if (brain->GetCompile(j)) continue; - char* name = brain->GetScriptName(j); + std::string name = brain->GetScriptName(j); + name = "ai/"+name; if (name[0] != 0) { - if(! brain->ReadProgram(j, name)) { - CLogger::GetInstancePointer()->Error("Unable to read script from file \"%s\"\n", name); + if(! brain->ReadProgram(j, const_cast<char*>(name.c_str()))) { + CLogger::GetInstancePointer()->Error("Unable to read script from file \"%s\"\n", name.c_str()); } if (!brain->GetCompile(j)) nbError++; } diff --git a/src/script/script.cpp b/src/script/script.cpp index 2299fbf..578c07d 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -18,13 +18,15 @@ #include "script/script.h" #include "app/app.h" -#include "app/gamedata.h" #include "common/global.h" #include "common/iman.h" #include "common/restext.h" #include "common/stringutils.h" +#include "common/resources/inputstream.h" +#include "common/resources/resourcemanager.h" + #include "graphics/engine/terrain.h" #include "graphics/engine/water.h" #include "graphics/engine/text.h" @@ -51,6 +53,7 @@ #include "ui/edit.h" #include "ui/list.h" #include "ui/displaytext.h" +#include <test/cbot/CBot_console/CClass.h> #include <stdio.h> @@ -4366,7 +4369,6 @@ void CScript::GetError(std::string& error) void CScript::New(Ui::CEdit* edit, const char* name) { - FILE *file = NULL; char res[100]; char text[100]; char script[500]; @@ -4409,18 +4411,18 @@ void CScript::New(Ui::CEdit* edit, const char* name) sf = m_main->GetScriptFile(); if ( sf[0] != 0 ) // Load an empty program specific? { - std::string filename = CGameData::GetInstancePointer()->GetFilePath(DIR_AI, sf); - file = fopen(filename.c_str(), "rb"); - if ( file != NULL ) + std::string filename = sf; + CInputStream stream; + stream.open(filename); + + if (stream.is_open()) { - fseek(file, 0, SEEK_END); - len = ftell(file); - fseek(file, 0, SEEK_SET); + len = stream.size(); if ( len > 500-1 ) len = 500-1; - fread(buffer, 1, len, file); + stream.read(buffer, len); buffer[len] = 0; - fclose(file); + stream.close(); cursor1 = 0; i = 0; @@ -4497,24 +4499,9 @@ bool CScript::SendScript(const char* text) bool CScript::ReadScript(const char* filename) { - FILE* file; Ui::CEdit* edit; - std::string name; - - if ( strchr(filename, '/') == 0 ) //we're reading non user script - { - name = CGameData::GetInstancePointer()->GetFilePath(DIR_AI, filename); - } - else - { - name = filename; - //TODO: is this needed? - // UserDir(name, filename, ""); - } - file = fopen(name.c_str(), "rb"); - if ( file == NULL ) return false; - fclose(file); + if (!CResourceManager::Exists(filename)) return false; delete[] m_script; m_script = nullptr; @@ -4522,7 +4509,7 @@ bool CScript::ReadScript(const char* filename) edit = m_interface->CreateEdit(Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f), 0, EVENT_EDIT9); edit->SetMaxChar(Ui::EDITSTUDIOMAX); edit->SetAutoIndent(m_engine->GetEditIndentMode()); - edit->ReadText(name.c_str()); + edit->ReadText(filename); GetScript(edit); m_interface->DeleteControl(EVENT_EDIT9); return true; @@ -4533,16 +4520,6 @@ bool CScript::ReadScript(const char* filename) bool CScript::WriteScript(const char* filename) { Ui::CEdit* edit; - std::string name; - - if ( strchr(filename, '/') == 0 ) //we're writing non user script - { - name = CGameData::GetInstancePointer()->GetFilePath(DIR_AI, filename); - } - else - { - name = filename; - } if ( m_script == nullptr ) { @@ -4554,7 +4531,7 @@ bool CScript::WriteScript(const char* filename) edit->SetMaxChar(Ui::EDITSTUDIOMAX); edit->SetAutoIndent(m_engine->GetEditIndentMode()); edit->SetText(m_script); - edit->WriteText(name); + edit->WriteText(filename); m_interface->DeleteControl(EVENT_EDIT9); return true; } diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp index 8afbdd2..54c94a5 100644 --- a/src/sound/oalsound/alsound.cpp +++ b/src/sound/oalsound/alsound.cpp @@ -18,8 +18,6 @@ #include "sound/oalsound/alsound.h" -#include "app/gamedata.h" - #include <algorithm> #include <iomanip> @@ -165,7 +163,7 @@ int ALSound::GetMusicVolume() bool ALSound::Cache(Sound sound, const std::string &filename) { Buffer *buffer = new Buffer(); - if (buffer->LoadFromFile(CGameData::GetInstancePointer()->GetFilePath(DIR_SOUND, filename), sound)) + if (buffer->LoadFromFile(filename, sound)) { m_sounds[sound] = buffer; return true; @@ -175,12 +173,12 @@ bool ALSound::Cache(Sound sound, const std::string &filename) bool ALSound::CacheMusic(const std::string &filename) { - if (m_music.find(filename) == m_music.end()) + if (m_music.find("music/"+filename) == m_music.end()) { Buffer *buffer = new Buffer(); - if (buffer->LoadFromFile(CGameData::GetInstancePointer()->GetFilePath(DIR_MUSIC, filename), static_cast<Sound>(-1))) + if (buffer->LoadFromFile("music/"+filename, static_cast<Sound>(-1))) { - m_music[filename] = buffer; + m_music["music/"+filename] = buffer; return true; } } @@ -635,30 +633,29 @@ bool ALSound::PlayMusic(const std::string &filename, bool bRepeat, float fadeTim return false; } - std::string file = CGameData::GetInstancePointer()->GetFilePath(DIR_MUSIC, filename); Buffer *buffer; // check if we have music in cache - if (m_music.find(filename) == m_music.end()) + if (m_music.find("music/"+filename) == m_music.end()) { GetLogger()->Debug("Music %s was not cached!\n", filename.c_str()); - if (!boost::filesystem::exists(file)) + /* TODO: if (!boost::filesystem::exists("music/"+filename)) { GetLogger()->Debug("Requested music %s was not found.\n", filename.c_str()); return false; - } + } */ buffer = new Buffer(); - if (!buffer->LoadFromFile(file, static_cast<Sound>(-1))) + if (!buffer->LoadFromFile("music/"+filename, static_cast<Sound>(-1))) { return false; } - m_music[filename] = buffer; + m_music["music/"+filename] = buffer; } else { GetLogger()->Debug("Music loaded from cache\n"); - buffer = m_music[filename]; + buffer = m_music["music/"+filename]; } if (m_currentMusic) diff --git a/src/sound/oalsound/alsound.h b/src/sound/oalsound/alsound.h index bb9bf28..1249f14 100644 --- a/src/sound/oalsound/alsound.h +++ b/src/sound/oalsound/alsound.h @@ -48,45 +48,44 @@ public: ALSound(); ~ALSound(); - bool Create(); - bool Cache(Sound, const std::string &); - bool CacheMusic(const std::string &); - - bool GetEnable(); - - void SetAudioVolume(int volume); - int GetAudioVolume(); - void SetMusicVolume(int volume); - int GetMusicVolume(); - - void SetListener(const Math::Vector &eye, const Math::Vector &lookat); - void FrameMove(float rTime); - - int Play(Sound sound, float amplitude=1.0f, float frequency=1.0f, bool bLoop = false); - int Play(Sound sound, const Math::Vector &pos, float amplitude=1.0f, float frequency=1.0f, bool bLoop = false); - bool FlushEnvelope(int channel); - bool AddEnvelope(int channel, float amplitude, float frequency, float time, SoundNext oper); - bool Position(int channel, const Math::Vector &pos); - bool Frequency(int channel, float frequency); - bool Stop(int channel); - bool StopAll(); - bool MuteAll(bool bMute); - - bool PlayMusic(int rank, bool bRepeat, float fadeTime=2.0f); - bool PlayMusic(const std::string &filename, bool bRepeat, float fadeTime=2.0f); - bool RestartMusic(); - void SuspendMusic(); - void StopMusic(float fadeTime=2.0f); - bool IsPlayingMusic(); - bool PlayPauseMusic(const std::string &filename, bool repeat); - void StopPauseMusic(); - - bool CheckChannel(int &channel); + bool Create() override; + bool Cache(Sound, const std::string &) override; + bool CacheMusic(const std::string &) override; + + bool GetEnable() override; + + void SetAudioVolume(int volume) override; + int GetAudioVolume() override; + void SetMusicVolume(int volume) override; + int GetMusicVolume() override; + + void SetListener(const Math::Vector &eye, const Math::Vector &lookat) override; + void FrameMove(float rTime) override; + + int Play(Sound sound, float amplitude=1.0f, float frequency=1.0f, bool bLoop = false) override; + int Play(Sound sound, const Math::Vector &pos, float amplitude=1.0f, float frequency=1.0f, bool bLoop = false) override; + bool FlushEnvelope(int channel) override; + bool AddEnvelope(int channel, float amplitude, float frequency, float time, SoundNext oper) override; + bool Position(int channel, const Math::Vector &pos) override; + bool Frequency(int channel, float frequency) override; + bool Stop(int channel) override; + bool StopAll() override; + bool MuteAll(bool bMute) override; + + bool PlayMusic(int rank, bool bRepeat, float fadeTime=2.0f) override; + bool PlayMusic(const std::string &filename, bool bRepeat, float fadeTime=2.0f) override; + bool RestartMusic() override; + void SuspendMusic() override; + void StopMusic(float fadeTime=2.0f) override; + bool IsPlayingMusic() override; + bool PlayPauseMusic(const std::string &filename, bool repeat) override; + void StopPauseMusic() override; private: void CleanUp(); int GetPriority(Sound); bool SearchFreeBuffer(Sound sound, int &channel, bool &bAlreadyLoaded); + bool CheckChannel(int &channel); bool m_enabled; float m_audioVolume; diff --git a/src/sound/oalsound/buffer.cpp b/src/sound/oalsound/buffer.cpp index b27029c..d9441ad 100644 --- a/src/sound/oalsound/buffer.cpp +++ b/src/sound/oalsound/buffer.cpp @@ -17,7 +17,10 @@ #include "sound/oalsound/buffer.h" -#include <cstring> +#include <memory> + +#include "common/resources/resourcemanager.h" + Buffer::Buffer() { @@ -42,19 +45,17 @@ bool Buffer::LoadFromFile(std::string filename, Sound sound) m_sound = sound; GetLogger()->Debug("Loading audio file: %s\n", filename.c_str()); - SF_INFO fileInfo; - memset(&fileInfo, 0, sizeof(SF_INFO)); - SNDFILE *file = sf_open(filename.c_str(), SFM_READ, &fileInfo); + std::unique_ptr<CSNDFile> file = std::unique_ptr<CSNDFile>(CResourceManager::GetSNDFileHandler(filename)); - GetLogger()->Trace(" channels %d\n", fileInfo.channels); - GetLogger()->Trace(" format %d\n", fileInfo.format); - GetLogger()->Trace(" frames %d\n", fileInfo.frames); - GetLogger()->Trace(" samplerate %d\n", fileInfo.samplerate); - GetLogger()->Trace(" sections %d\n", fileInfo.sections); + GetLogger()->Trace(" channels %d\n", file->GetFileInfo().channels); + GetLogger()->Trace(" format %d\n", file->GetFileInfo().format); + GetLogger()->Trace(" frames %d\n", file->GetFileInfo().frames); + GetLogger()->Trace(" samplerate %d\n", file->GetFileInfo().samplerate); + GetLogger()->Trace(" sections %d\n", file->GetFileInfo().sections); - if (!file) + if (!file->IsOpen()) { - GetLogger()->Warn("Could not load file. Reason: %s\n", sf_strerror(file)); + GetLogger()->Warn("Could not load file. Reason: %s\n", file->GetLastError().c_str()); m_loaded = false; return false; } @@ -64,23 +65,21 @@ bool Buffer::LoadFromFile(std::string filename, Sound sound) { GetLogger()->Warn("Could not create audio buffer\n"); m_loaded = false; - sf_close(file); return false; } // read chunks of 4096 samples std::vector<uint16_t> data; std::array<int16_t, 4096> buffer; - data.reserve(fileInfo.frames); + data.reserve(file->GetFileInfo().frames); size_t read = 0; - while ((read = sf_read_short(file, buffer.data(), buffer.size())) != 0) + while ((read = file->Read(buffer.data(), buffer.size())) != 0) { data.insert(data.end(), buffer.begin(), buffer.begin() + read); } - sf_close(file); - alBufferData(m_buffer, fileInfo.channels == 1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16, &data.front(), data.size() * sizeof(uint16_t), fileInfo.samplerate); - m_duration = static_cast<float>(fileInfo.frames) / fileInfo.samplerate; + alBufferData(m_buffer, file->GetFileInfo().channels == 1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16, &data.front(), data.size() * sizeof(uint16_t), file->GetFileInfo().samplerate); + m_duration = static_cast<float>(file->GetFileInfo().frames) / file->GetFileInfo().samplerate; m_loaded = true; return true; } diff --git a/src/sound/sound.cpp b/src/sound/sound.cpp index 9cae1fd..5d99cdb 100644 --- a/src/sound/sound.cpp +++ b/src/sound/sound.cpp @@ -46,7 +46,7 @@ void CSoundInterface::CacheAll() for ( int i = 1; i < SOUND_MAX; i++ ) { std::stringstream filename; - filename << "sound" << std::setfill('0') << std::setw(3) << i << ".wav"; + filename << "sounds/sound" << std::setfill('0') << std::setw(3) << i << ".wav"; if ( !Cache(static_cast<Sound>(i), filename.str()) ) GetLogger()->Warn("Unable to load audio: %s\n", filename.str().c_str()); } diff --git a/src/ui/button.cpp b/src/ui/button.cpp index 810d365..2a1fb3b 100644 --- a/src/ui/button.cpp +++ b/src/ui/button.cpp @@ -176,7 +176,7 @@ void CButton::Draw() (m_state & STATE_CARD ) == 0 && (m_state & STATE_SIMPLY) == 0 ) { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); dp = 0.5f / 256.0f; diff --git a/src/ui/check.cpp b/src/ui/check.cpp index 6a92554..9d42b86 100644 --- a/src/ui/check.cpp +++ b/src/ui/check.cpp @@ -102,7 +102,7 @@ void CCheck::Draw() DrawShadow(m_pos, m_dim); } - m_engine->SetTexture("button1.png"); + m_engine->SetTexture("interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); zoomExt = 1.00f; diff --git a/src/ui/color.cpp b/src/ui/color.cpp index d1dc746..57e78d5 100644 --- a/src/ui/color.cpp +++ b/src/ui/color.cpp @@ -138,7 +138,7 @@ void CColor::Draw() DrawShadow(m_pos, m_dim); } - m_engine->SetTexture("button1.png"); + m_engine->SetTexture("interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); CControl::Draw(); diff --git a/src/ui/compass.cpp b/src/ui/compass.cpp index d0fe96f..068c37f 100644 --- a/src/ui/compass.cpp +++ b/src/ui/compass.cpp @@ -88,7 +88,7 @@ void CCompass::Draw() device = m_engine->GetDevice(); - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); p1.x = m_pos.x; diff --git a/src/ui/control.cpp b/src/ui/control.cpp index 4e64ee9..6686c55 100644 --- a/src/ui/control.cpp +++ b/src/ui/control.cpp @@ -437,7 +437,7 @@ void CControl::Draw() if ( (m_state & STATE_VISIBLE) == 0 ) return; - m_engine->SetTexture("button1.png"); + m_engine->SetTexture("interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); zoomExt = 1.00f; @@ -491,7 +491,7 @@ void CControl::Draw() if ( m_state & STATE_OKAY ) { - m_engine->SetTexture("button3.png"); + m_engine->SetTexture("interface/button3.png"); icon = 3; // yellow with green point pressed } @@ -506,19 +506,19 @@ void CControl::Draw() if ( icon >= 192 ) { icon -= 192; - m_engine->SetTexture("text.png"); + m_engine->SetTexture("interface/text.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); } else if ( icon >= 128 ) { icon -= 128; - m_engine->SetTexture("button3.png"); + m_engine->SetTexture("interface/button3.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); } else if ( icon >= 64 ) { icon -= 64; - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); } else @@ -751,7 +751,7 @@ void CControl::DrawWarning(Math::Point pos, Math::Point dim) dp = 0.5f / 256.0f; - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 64.0f / 256.0f; @@ -795,7 +795,7 @@ void CControl::DrawShadow(Math::Point pos, Math::Point dim, float deep) dp = 0.5f/256.0f; - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState( Gfx::ENG_RSTATE_TTEXTURE_WHITE); pos.x += deep * 0.010f * 0.75f; diff --git a/src/ui/displayinfo.cpp b/src/ui/displayinfo.cpp index e7748ae..9204473 100644 --- a/src/ui/displayinfo.cpp +++ b/src/ui/displayinfo.cpp @@ -342,8 +342,6 @@ void CDisplayInfo::StartDisplayInfo(std::string filename, int index, bool bSoluc m_index = index; m_bSoluce = bSoluce; -//? CreateObjectsFile(); - m_bEditLock = m_main->GetEditLock(); if ( m_bEditLock ) // edition running program? { @@ -935,284 +933,4 @@ CObject* CDisplayInfo::SearchToto() return 0; } - -// Creating the list of objects. - -struct ObjectList -{ - int total; - ObjectType type; -}; - -void ObjectAdd(ObjectList list[], ObjectType type) -{ - int i; - - for ( i=0 ; i<200 ; i++ ) - { - if ( list[i].total == 0 ) - { - list[i].total ++; - list[i].type = type; - list[i+1].total = 0; - return; - } - if ( list[i].type == type ) - { - list[i].total ++; - return; - } - } -} - -void ObjectWrite(FILE* file, ObjectList list[], int i) -{ - std::string line; - - if ( list[i].total < 10 ) - { - line = StrUtils::Format("\\c; %dx \\n;\\l;", list[i].total); - } - else - { - line = StrUtils::Format("\\c;%dx \\n;\\l;", list[i].total); - } - - std::string res; - GetResource(RES_OBJECT, list[i].type, res); - if (res.empty()) - return; - - line += res; - - line += "\\u "; - - std::string helpFilename = GetHelpFilename(list[i].type); - if (helpFilename.empty()) - return; - - line += helpFilename.substr(7); // skip "help\?\" - - auto pos = line.find(".txt"); - if (pos != std::string::npos) - { - line = line.substr(0, pos); - } - - line += ";\n"; - - fputs(line.c_str(), file); -} - -// Creates the file containing the list of objects. - -void CDisplayInfo::CreateObjectsFile() -{ - FILE* file; - CObject* pObj; - ObjectType type; - ObjectList list[200]; - std::string line; - int i; - bool bRadar, bAtLeast; - - CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); - - file = fopen((std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("objects.txt")).c_str(), "w"); - if ( file == 0 ) return; - - list[0].total = 0; // empty list - bRadar = false; - for ( i=0 ; i<1000000 ; i++ ) - { - pObj = static_cast<CObject*>(iMan->SearchInstance(CLASS_OBJECT, i)); - if ( pObj == 0 ) break; - - if ( !pObj->GetActif() ) continue; - if ( !pObj->GetSelectable() ) continue; - if ( pObj->GetProxyActivate() ) continue; - - type = pObj->GetType(); - if ( type == OBJECT_NULL ) continue; - if ( type == OBJECT_FIX ) continue; - - ObjectAdd(list, type); - - if ( type == OBJECT_RADAR ) bRadar = true; - } - - if ( bRadar ) - { - GetResource(RES_TEXT, RT_SATCOM_LIST, line); - fputs(line.c_str(), file); - bAtLeast = false; - for ( i=0 ; i<200 ; i++ ) - { - if ( list[i].total == 0 ) break; // end of the list? - - if ( list[i].type == OBJECT_BASE || - list[i].type == OBJECT_HUMAN ) - { - ObjectWrite(file, list, i); - bAtLeast = true; - } - } - if ( !bAtLeast ) - { - GetResource(RES_TEXT, RT_SATCOM_NULL, line); - fputs(line.c_str(), file); - } - - fputs("\n", file); - GetResource(RES_TEXT, RT_SATCOM_BOT, line); - fputs(line.c_str(), file); - bAtLeast = false; - for ( i=0 ; i<200 ; i++ ) - { - if ( list[i].total == 0 ) break; // end of the list? - - if ( list[i].type == OBJECT_MOBILEwt || - list[i].type == OBJECT_MOBILEtt || - list[i].type == OBJECT_MOBILEft || - list[i].type == OBJECT_MOBILEit || - list[i].type == OBJECT_MOBILEwa || - list[i].type == OBJECT_MOBILEta || - list[i].type == OBJECT_MOBILEfa || - list[i].type == OBJECT_MOBILEia || - list[i].type == OBJECT_MOBILEwc || - list[i].type == OBJECT_MOBILEtc || - list[i].type == OBJECT_MOBILEfc || - list[i].type == OBJECT_MOBILEic || - list[i].type == OBJECT_MOBILEwi || - list[i].type == OBJECT_MOBILEti || - list[i].type == OBJECT_MOBILEfi || - list[i].type == OBJECT_MOBILEii || - list[i].type == OBJECT_MOBILEws || - list[i].type == OBJECT_MOBILEts || - list[i].type == OBJECT_MOBILEfs || - list[i].type == OBJECT_MOBILEis || - list[i].type == OBJECT_MOBILErt || - list[i].type == OBJECT_MOBILErc || - list[i].type == OBJECT_MOBILErr || - list[i].type == OBJECT_MOBILErs || - list[i].type == OBJECT_MOBILEsa || - list[i].type == OBJECT_MOBILEtg || - list[i].type == OBJECT_MOBILEdr ) - { - ObjectWrite(file, list, i); - bAtLeast = true; - } - } - if ( !bAtLeast ) - { - GetResource(RES_TEXT, RT_SATCOM_NULL, line); - fputs(line.c_str(), file); - } - - fputs("\n", file); - GetResource(RES_TEXT, RT_SATCOM_BUILDING, line); - fputs(line.c_str(), file); - bAtLeast = false; - for ( i=0 ; i<200 ; i++ ) - { - if ( list[i].total == 0 ) break; // end of the list? - - if ( list[i].type == OBJECT_DERRICK || - list[i].type == OBJECT_FACTORY || - list[i].type == OBJECT_STATION || - list[i].type == OBJECT_CONVERT || - list[i].type == OBJECT_REPAIR || - list[i].type == OBJECT_DESTROYER|| - list[i].type == OBJECT_TOWER || - list[i].type == OBJECT_NEST || - list[i].type == OBJECT_RESEARCH || - list[i].type == OBJECT_RADAR || - list[i].type == OBJECT_ENERGY || - list[i].type == OBJECT_LABO || - list[i].type == OBJECT_NUCLEAR || - list[i].type == OBJECT_START || - list[i].type == OBJECT_END || - list[i].type == OBJECT_INFO || - list[i].type == OBJECT_PARA || - list[i].type == OBJECT_TARGET1 || - list[i].type == OBJECT_TARGET2 || - list[i].type == OBJECT_SAFE || - list[i].type == OBJECT_HUSTON ) - { - ObjectWrite(file, list, i); - bAtLeast = true; - } - } - if ( !bAtLeast ) - { - GetResource(RES_TEXT, RT_SATCOM_NULL, line); - fputs(line.c_str(), file); - } - - fputs("\n", file); - GetResource(RES_TEXT, RT_SATCOM_FRET, line); - fputs(line.c_str(), file); - bAtLeast = false; - for ( i=0 ; i<200 ; i++ ) - { - if ( list[i].total == 0 ) break; // end of the list? - - if ( list[i].type == OBJECT_STONE || - list[i].type == OBJECT_URANIUM || - list[i].type == OBJECT_METAL || - list[i].type == OBJECT_POWER || - list[i].type == OBJECT_ATOMIC || - list[i].type == OBJECT_BULLET || - list[i].type == OBJECT_BBOX || - list[i].type == OBJECT_TNT ) - { - ObjectWrite(file, list, i); - bAtLeast = true; - } - } - if ( !bAtLeast ) - { - GetResource(RES_TEXT, RT_SATCOM_NULL, line); - fputs(line.c_str(), file); - } - - fputs("\n", file); - GetResource(RES_TEXT, RT_SATCOM_ALIEN, line); - fputs(line.c_str(), file); - bAtLeast = false; - for ( i=0 ; i<200 ; i++ ) - { - if ( list[i].total == 0 ) break; // end of the list? - - if ( list[i].type == OBJECT_MOTHER || - list[i].type == OBJECT_ANT || - list[i].type == OBJECT_BEE || - list[i].type == OBJECT_WORM || - list[i].type == OBJECT_SPIDER ) - { - ObjectWrite(file, list, i); - bAtLeast = true; - } - } - if ( !bAtLeast ) - { - GetResource(RES_TEXT, RT_SATCOM_NULL, line); - fputs(line.c_str(), file); - } - } - else - { - GetResource(RES_TEXT, RT_SATCOM_ERROR1, line); - fputs(line.c_str(), file); - GetResource(RES_TEXT, RT_SATCOM_ERROR2, line); - fputs(line.c_str(), file); - } - - fputs("\n", file); - - fclose(file); -} - - } - diff --git a/src/ui/displayinfo.h b/src/ui/displayinfo.h index 891551b..0942497 100644 --- a/src/ui/displayinfo.h +++ b/src/ui/displayinfo.h @@ -66,7 +66,6 @@ protected: void UpdateCopyButton(); void ViewDisplayInfo(); CObject* SearchToto(); - void CreateObjectsFile(); protected: Gfx::CEngine* m_engine; diff --git a/src/ui/edit.cpp b/src/ui/edit.cpp index e2df62b..f9b7837 100644 --- a/src/ui/edit.cpp +++ b/src/ui/edit.cpp @@ -19,10 +19,12 @@ #include "ui/edit.h" #include "app/app.h" -#include "app/gamedata.h" #include "clipboard/clipboard.h" +#include "common/resources/inputstream.h" +#include "common/resources/outputstream.h" + #include <string.h> namespace Ui { @@ -782,15 +784,13 @@ void CEdit::HyperJump(std::string name, std::string marker) sMarker = marker; -//? sprintf(filename, "help\\%s.txt", name); - if ( name[0] == '%' ) { filename = GetProfile().GetUserBasedPath(name, "") + ".txt"; } else { - filename = std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + "/" + name + std::string(".txt"); + filename = name + std::string(".txt"); } if ( ReadText(filename) ) @@ -1145,7 +1145,7 @@ void CEdit::DrawImage(Math::Point pos, std::string name, float width, float dp; std::string filename; - filename = GetProfile().GetUserBasedPath(name, "../icons") + ".png"; + filename = name + ".png"; m_engine->SetTexture(filename); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); @@ -1175,7 +1175,7 @@ void CEdit::DrawBack(Math::Point pos, Math::Point dim) if ( m_bGeneric ) return; - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); if ( m_bMulti ) @@ -1225,7 +1225,7 @@ void CEdit::DrawPart(Math::Point pos, Math::Point dim, int icon) Math::Point uv1, uv2; float dp; - m_engine->SetTexture("text.png"); + m_engine->SetTexture("interface/text.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = (16.0f/256.0f)*(icon%16); @@ -1423,7 +1423,7 @@ void CEdit::FreeImage() for (int i = 0 ; i < m_imageTotal; i++ ) { - filename = GetProfile().GetUserBasedPath(m_image[i].name, "../icons") + ".png"; + filename = m_image[i].name + ".png"; m_engine->DeleteTexture(filename); } } @@ -1433,7 +1433,7 @@ void CEdit::FreeImage() void CEdit::LoadImage(std::string name) { std::string filename; - filename = GetProfile().GetUserBasedPath(name, "../icons") + ".png"; + filename = name + ".png"; m_engine->LoadTexture(filename); } @@ -1441,7 +1441,6 @@ void CEdit::LoadImage(std::string name) bool CEdit::ReadText(std::string filename, int addSize) { - FILE *file = NULL; char *buffer; int len, i, j, n, font, iIndex, iLines, iCount, iLink, res; char iName[50]; @@ -1451,26 +1450,16 @@ bool CEdit::ReadText(std::string filename, int addSize) bool bInSoluce, bBOL; if ( filename[0] == 0 ) return false; - - boost::replace_all(filename, "\\", "/"); - - /* This is ugly but doesn't require many changes in code. If file doesn't - exists it's posible filename is absolute not full path */ - std::string path = filename; - if (!fs::exists(path)) + + CInputStream stream; + stream.open(filename); + + if (!stream.is_open()) { - path = CGameData::GetInstancePointer()->GetDataPath(filename); - } - - file = fopen(fs::path(path).make_preferred().string().c_str(), "rb"); - if ( file == NULL ) { - CLogger::GetInstancePointer()->Error("Unable to read text from file \"%s\"\n", path.c_str()); return false; } - fseek(file, 0, SEEK_END); - len = ftell(file); - fseek(file, 0, SEEK_SET); + len = stream.size(); m_maxChar = len+addSize+100; m_len = len; @@ -1488,7 +1477,7 @@ bool CEdit::ReadText(std::string filename, int addSize) buffer = new char[m_maxChar+1]; memset(buffer, 0, m_maxChar+1); - fread(buffer, 1, len, file); + stream.read(buffer, len); m_format.clear(); m_format.reserve(m_maxChar+1); @@ -1497,7 +1486,7 @@ bool CEdit::ReadText(std::string filename, int addSize) m_format.push_back(0); } - fclose(file); + stream.close(); bInSoluce = false; font = m_fontType; @@ -1891,14 +1880,19 @@ bool CEdit::ReadText(std::string filename, int addSize) bool CEdit::WriteText(std::string filename) { - FILE* file; char buffer[1000+20]; int i, j, k, n; float iDim = 0.0f; if ( filename[0] == 0 ) return false; - file = fopen(filename.c_str(), "wb"); - if ( file == NULL ) return false; + + COutputStream stream; + stream.open(filename); + + if (!stream.is_open()) + { + return false; + } if ( m_bAutoIndent ) { @@ -1929,7 +1923,7 @@ bool CEdit::WriteText(std::string filename) if ( j >= 1000-1 ) { - fwrite(buffer, 1, j, file); + stream.write(buffer, j); j = 0; } @@ -1937,10 +1931,10 @@ bool CEdit::WriteText(std::string filename) } if ( j > 0 ) { - fwrite(buffer, 1, j, file); + stream.write(buffer, j); } - fclose(file); + stream.close(); if ( m_bAutoIndent ) { diff --git a/src/ui/gauge.cpp b/src/ui/gauge.cpp index a8ee41c..73585d3 100644 --- a/src/ui/gauge.cpp +++ b/src/ui/gauge.cpp @@ -75,7 +75,7 @@ void CGauge::Draw() if ( (m_state & STATE_VISIBLE) == 0 ) return; - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); dp = 0.5f/256.0f; diff --git a/src/ui/group.cpp b/src/ui/group.cpp index 64495e0..723a9fc 100644 --- a/src/ui/group.cpp +++ b/src/ui/group.cpp @@ -87,7 +87,7 @@ void CGroup::Draw() if ( m_icon == 0 ) // hollow frame? { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 160.0f / 256.0f; uv1.y = 192.0f / 256.0f; // u-v texture @@ -103,7 +103,7 @@ void CGroup::Draw() } if ( m_icon == 1 ) // orange solid opaque? { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 104.0f / 256.0f; uv1.y = 48.0f / 256.0f; @@ -117,7 +117,7 @@ void CGroup::Draw() } if ( m_icon == 2 ) // orange degrade -> transparent? { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); uv1.x = 112.0f / 256.0f; uv1.y = 48.0f / 256.0f; @@ -131,7 +131,7 @@ void CGroup::Draw() } if ( m_icon == 3 ) // transparent gradient -> gray? { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); uv1.x = 120.0f / 256.0f; uv1.y = 48.0f / 256.0f; @@ -145,7 +145,7 @@ void CGroup::Draw() } if ( m_icon == 4 ) // degrade blue corner? { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); uv1.x = 192.0f / 256.0f; uv1.y = 128.0f / 256.0f; @@ -159,7 +159,7 @@ void CGroup::Draw() } if ( m_icon == 5 ) // degrade orange corner? { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); uv1.x = 224.0f / 256.0f; uv1.y = 128.0f / 256.0f; @@ -173,7 +173,7 @@ void CGroup::Draw() } if ( m_icon == 6 ) { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); uv1.x = 0.0f / 256.0f; // brown transparent uv1.y = 75.0f / 256.0f; @@ -189,7 +189,7 @@ void CGroup::Draw() } if ( m_icon == 7 ) { - m_engine->SetTexture("button1.png"); + m_engine->SetTexture("interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 64.0f / 256.0f; uv1.y = 0.0f / 256.0f; @@ -203,7 +203,7 @@ void CGroup::Draw() } if ( m_icon == 8 ) { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); uv1.x = 64.0f / 256.0f; // green transparent uv1.y = 160.0f / 256.0f; @@ -217,7 +217,7 @@ void CGroup::Draw() } if ( m_icon == 9 ) { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); uv1.x = 64.0f / 256.0f; // red transparent uv1.y = 176.0f/256.0f; @@ -231,7 +231,7 @@ void CGroup::Draw() } if ( m_icon == 10 ) { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); uv1.x = 64.0f / 256.0f; // blue transparent uv1.y = 192.0f / 256.0f; @@ -245,7 +245,7 @@ void CGroup::Draw() } if ( m_icon == 11 ) { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); uv1.x = 64.0f / 256.0f; // yellow transparent uv1.y = 224.0f / 256.0f; @@ -262,7 +262,7 @@ void CGroup::Draw() dim.x = m_dim.x / 2.0f; dim.y = m_dim.y / 2.0f; - m_engine->SetTexture("mouse.png"); + m_engine->SetTexture("interface/mouse.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); pos.x = m_pos.x-m_dim.x/300.0f; pos.y = m_pos.y+m_dim.y/300.0f+dim.y; @@ -301,7 +301,7 @@ void CGroup::Draw() } if ( m_icon == 13 ) // corner upper / left? { - m_engine->SetTexture("mouse.png"); + m_engine->SetTexture("interface/mouse.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); pos.x = m_pos.x-m_dim.x/150.0f; pos.y = m_pos.y+m_dim.y/150.0f; @@ -322,7 +322,7 @@ void CGroup::Draw() } if ( m_icon == 14 ) // corner upper / right? { - m_engine->SetTexture("mouse.png"); + m_engine->SetTexture("interface/mouse.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); pos.x = m_pos.x-m_dim.x/150.0f; pos.y = m_pos.y+m_dim.y/150.0f; @@ -343,7 +343,7 @@ void CGroup::Draw() } if ( m_icon == 15 ) // corner lower / left? { - m_engine->SetTexture("mouse.png"); + m_engine->SetTexture("interface/mouse.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); pos.x = m_pos.x-m_dim.x/150.0f; pos.y = m_pos.y+m_dim.y/150.0f; @@ -364,7 +364,7 @@ void CGroup::Draw() } if ( m_icon == 16 ) // corner lower / left? { - m_engine->SetTexture("mouse.png"); + m_engine->SetTexture("interface/mouse.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); pos.x = m_pos.x-m_dim.x/150.0f; pos.y = m_pos.y+m_dim.y/150.0f; @@ -385,7 +385,7 @@ void CGroup::Draw() } if ( m_icon == 17 ) { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 0.0f / 256.0f; // blue frame uv1.y = 75.0f / 256.0f; @@ -401,7 +401,7 @@ void CGroup::Draw() } if ( m_icon == 18 ) // arrow> for SatCom? { - m_engine->SetTexture("button1.png"); + m_engine->SetTexture("interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); uv1.x = 0.0f / 256.0f; // > uv1.y = 192.0f / 256.0f; @@ -415,7 +415,7 @@ void CGroup::Draw() } if ( m_icon == 19 ) // SatCom symbol? { - m_engine->SetTexture("button1.png"); + m_engine->SetTexture("interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); uv1.x = 224.0f / 256.0f; // SatCom symbol uv1.y = 224.0f / 256.0f; @@ -429,7 +429,7 @@ void CGroup::Draw() } if ( m_icon == 20 ) // solid blue background? { - m_engine->SetTexture("button1.png"); + m_engine->SetTexture("interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); uv1.x = 224.0f / 256.0f; uv1.y = 32.0f / 256.0f; @@ -443,7 +443,7 @@ void CGroup::Draw() } if ( m_icon == 21 ) // stand-by symbol? { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); uv1.x = 160.0f / 256.0f; uv1.y = 32.0f / 256.0f; @@ -457,7 +457,7 @@ void CGroup::Draw() } if ( m_icon == 22 ) { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 64.0f / 256.0f; // opaque yellow uv1.y = 224.0f / 256.0f; @@ -474,7 +474,7 @@ void CGroup::Draw() if ( m_icon == 23 ) { - m_engine->SetTexture("button3.png"); + m_engine->SetTexture("interface/button3.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 64.0f / 256.0f; // yellow uv1.y = 192.0f / 256.0f; @@ -490,7 +490,7 @@ void CGroup::Draw() } if ( m_icon == 24 ) { - m_engine->SetTexture("button3.png"); + m_engine->SetTexture("interface/button3.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 80.0f / 256.0f; // orange uv1.y = 192.0f / 256.0f; @@ -506,7 +506,7 @@ void CGroup::Draw() } if ( m_icon == 25 ) { - m_engine->SetTexture("button3.png"); + m_engine->SetTexture("interface/button3.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 64.0f / 256.0f; // orange uv1.y = 208.0f / 256.0f; @@ -522,7 +522,7 @@ void CGroup::Draw() } if ( m_icon == 26 ) { - m_engine->SetTexture("button3.png"); + m_engine->SetTexture("interface/button3.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 80.0f / 256.0f; // red uv1.y = 208.0f / 256.0f; @@ -538,7 +538,7 @@ void CGroup::Draw() } if ( m_icon == 27 ) { - m_engine->SetTexture("button3.png"); + m_engine->SetTexture("interface/button3.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 32.0f / 256.0f; uv1.y = 0.0f / 256.0f; @@ -556,7 +556,7 @@ void CGroup::Draw() pos = m_pos; dim = m_dim; - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 32.0f / 256.0f; uv1.y = 32.0f / 256.0f; @@ -568,7 +568,7 @@ void CGroup::Draw() uv2.y -= dp; DrawIcon(pos, dim, uv1, uv2); - m_engine->SetTexture("button3.png"); + m_engine->SetTexture("interface/button3.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); pos.x += 8.0f / 640.0f; pos.y += 8.0f / 480.0f; diff --git a/src/ui/image.cpp b/src/ui/image.cpp index 8f9b5ca..07b0675 100644 --- a/src/ui/image.cpp +++ b/src/ui/image.cpp @@ -110,7 +110,7 @@ void CImage::Draw() if ( m_icon == 0 ) // hollow frame? { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 160.0f / 256.0f; uv1.y = 192.0f / 256.0f; // u-v texture diff --git a/src/ui/key.cpp b/src/ui/key.cpp index aacc8d8..1c8ebcd 100644 --- a/src/ui/key.cpp +++ b/src/ui/key.cpp @@ -136,7 +136,7 @@ void CKey::Draw() DrawShadow(m_pos, m_dim); - m_engine->SetTexture("button1.png"); + m_engine->SetTexture("interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); // was D3DSTATENORMAL float zoomExt = 1.00f; diff --git a/src/ui/list.cpp b/src/ui/list.cpp index f6c3ed9..bccb435 100644 --- a/src/ui/list.cpp +++ b/src/ui/list.cpp @@ -388,7 +388,7 @@ void CList::Draw() if (m_icon == 0) { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 128.0f / 256.0f; @@ -398,7 +398,7 @@ void CList::Draw() } else { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 132.0f / 256.0f; @@ -434,7 +434,7 @@ void CList::Draw() dim.y *= 0.4f; pos.y -= dim.y; - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); // was D3DSTATETTw uv1.x = 120.0f / 256.0f; uv1.y = 64.0f / 256.0f; @@ -509,7 +509,7 @@ void CList::Draw() if ( m_check[i + m_firstLine] ) { - m_engine->SetTexture("button1.png"); + m_engine->SetTexture("interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 64.0f / 256.0f; uv1.y = 0.0f / 256.0f; @@ -534,7 +534,7 @@ void CList::Draw() } else { - m_engine->SetTexture("button1.png"); + m_engine->SetTexture("interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); // was D3DSTATETTw if ( i + m_firstLine == m_selectLine ) { diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 39e7aa9..fd6cd2e 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -18,7 +18,6 @@ #include "ui/maindialog.h" #include "app/app.h" -#include "app/gamedata.h" #include "app/system.h" #include "common/config.h" @@ -30,6 +29,10 @@ #include "common/restext.h" #include "common/stringutils.h" +#include "common/resources/resourcemanager.h" +#include "common/resources/inputstream.h" +#include "common/resources/outputstream.h" + #include "object/robotmain.h" #include "script/cmdtoken.h" @@ -49,6 +52,7 @@ #include "ui/window.h" #include "ui/edit.h" #include "ui/editvalue.h" +#include <test/cbot/CBot_console/CClass.h> #include <stdio.h> #include <string.h> @@ -173,13 +177,10 @@ CMainDialog::CMainDialog() m_partiTime[i] = 0.0f; } - - m_sceneDir = "levels"; - #if DEV_BUILD m_savegameDir = "savegame"; #else - m_savegameDir = GetSystemUtils()->GetSavegameDirectoryLocation(); + m_savegameDir = "savegame"; #endif m_publicDir = "program"; @@ -343,7 +344,7 @@ void CMainDialog::ChangePhase(Phase phase) pl->SetFontType(Gfx::FONT_COURIER); pl->SetFontSize(Gfx::FONT_SIZE_SMALL); - m_engine->SetBackground("interface.png", + m_engine->SetBackground("interface/interface.png", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), @@ -450,7 +451,7 @@ void CMainDialog::ChangePhase(Phase phase) UpdateNameControl(); UpdateNameFace(); - m_engine->SetBackground("interface.png", + m_engine->SetBackground("interface/interface.png", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), @@ -713,15 +714,15 @@ void CMainDialog::ChangePhase(Phase phase) if ( m_phase == PHASE_FREE ) { - strcpy(m_sceneName, "scene"); + strcpy(m_sceneName, "missions"); ReadGamerInfo(); m_accessChap = GetChapPassed(); } - if ( m_phase == PHASE_TRAINER ) strcpy(m_sceneName, "train"); - if ( m_phase == PHASE_DEFI ) strcpy(m_sceneName, "defi" ); - if ( m_phase == PHASE_MISSION ) strcpy(m_sceneName, "scene"); - if ( m_phase == PHASE_FREE ) strcpy(m_sceneName, "free"); + if ( m_phase == PHASE_TRAINER ) strcpy(m_sceneName, "exercises"); + if ( m_phase == PHASE_DEFI ) strcpy(m_sceneName, "challenges" ); + if ( m_phase == PHASE_MISSION ) strcpy(m_sceneName, "missions"); + if ( m_phase == PHASE_FREE ) strcpy(m_sceneName, "freemissions"); if ( m_phase == PHASE_USER ) strcpy(m_sceneName, "user"); ReadGamerInfo(); @@ -875,7 +876,7 @@ void CMainDialog::ChangePhase(Phase phase) pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_BACK); pb->SetState(STATE_SHADOW); - m_engine->SetBackground("interface.png", + m_engine->SetBackground("interface/interface.png", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), @@ -1000,7 +1001,7 @@ void CMainDialog::ChangePhase(Phase phase) if ( !m_bSimulSetup ) { - m_engine->SetBackground("interface.png", + m_engine->SetBackground("interface/interface.png", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), @@ -1489,7 +1490,7 @@ void CMainDialog::ChangePhase(Phase phase) if ( m_phase == PHASE_READ ) { - m_engine->SetBackground("interface.png", + m_engine->SetBackground("interface/interface.png", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), @@ -1536,7 +1537,7 @@ void CMainDialog::ChangePhase(Phase phase) pl->SetFontSize(12.0f); pl->SetTextAlign(Gfx::TEXT_ALIGN_CENTER); - m_engine->SetBackground("interface.png", + m_engine->SetBackground("interface/interface.png", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), @@ -1558,7 +1559,7 @@ void CMainDialog::ChangePhase(Phase phase) m_engine->SetOverColor(Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f), Gfx::ENG_RSTATE_TCOLOR_BLACK); // TODO: color ok? m_engine->SetOverFront(true); - m_engine->SetBackground("ppc.png", + m_engine->SetBackground("interface/ppc.png", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), @@ -1577,7 +1578,7 @@ void CMainDialog::ChangePhase(Phase phase) m_engine->SetOverColor(Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::ENG_RSTATE_TCOLOR_WHITE); // TODO: color ok? m_engine->SetOverFront(true); - m_engine->SetBackground("colobot.png", + m_engine->SetBackground("interface/colobot.png", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), @@ -1596,7 +1597,7 @@ void CMainDialog::ChangePhase(Phase phase) m_engine->SetOverColor(Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::ENG_RSTATE_TCOLOR_WHITE); // TODO: color ok? m_engine->SetOverFront(true); - m_engine->SetBackground("epsitec.png", + m_engine->SetBackground("interface/epsitec.png", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), @@ -1662,7 +1663,7 @@ void CMainDialog::ChangePhase(Phase phase) pb = pw->CreateButton(pos, ddim, 49, EVENT_INTERFACE_ABORT); pb->SetState(STATE_SHADOW); - m_engine->SetBackground("generico.png", + m_engine->SetBackground("interface/generico.png", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), @@ -3291,18 +3292,41 @@ void CMainDialog::SetUserDir(char *base, int rank) void CMainDialog::BuildSceneName(std::string &filename, char *base, int rank) { - std::ostringstream rankStream; + //TODO: Support for more than 9 chapters + int chapter = rank/100; + int new_rank = rank%100; + + std::ostringstream outstream; if ( strcmp(base, "user") == 0 ) { //TODO: Change this to point user dir according to operating system - rankStream << std::setfill('0') << std::setw(2) << rank%100; - filename = m_userDir + "/" + m_userList[rank/100-1] + "/" + rankStream.str() + ".txt"; + /*rankStream << std::setfill('0') << std::setw(2) << rank%100; + filename = m_userDir + "/" + m_userList[rank/100-1] + "/" + rankStream.str() + ".txt";*/ + assert(false); //TODO: Userlevel support + } + else if ( strcmp(base, "perso") == 0 ) + { + filename = "levels/other/perso.txt"; + } + else if( strcmp(base, "win") == 0 || strcmp(base, "lost") == 0 ) + { + outstream << "levels/other/"; + outstream << base << std::setfill('0') << std::setw(3) << chapter << "/"; + outstream << "scene.txt"; + std::cout << outstream.str() << std::endl; + filename = outstream.str(); } else { - rankStream << std::setfill('0') << std::setw(3) << rank; - filename = base + rankStream.str() + ".txt"; - filename = CGameData::GetInstancePointer()->GetFilePath(DIR_LEVEL, filename); + outstream << "levels/" << base << "/"; + outstream << "chapter" << std::setfill('0') << std::setw(3) << chapter << "/"; + if(new_rank == 000) { + outstream << "chaptertitle.txt"; + } else { + outstream << "level" << std::setfill('0') << std::setw(3) << new_rank << "/"; + outstream << "scene.txt"; + } + filename = outstream.str(); } } @@ -3997,7 +4021,6 @@ bool CMainDialog::IsIOReadScene() void CMainDialog::IOReadName() { - FILE* file; CWindow* pw; CEdit* pe; std::string filename; @@ -4019,10 +4042,12 @@ void CMainDialog::IOReadName() sprintf(op, "Title.E"); sprintf(op_i18n, "Title.%c", m_app->GetLanguageChar() ); - file = fopen(filename.c_str(), "r"); - if ( file != NULL ) + CInputStream stream; + stream.open(filename); + + if (stream.is_open()) { - while ( fgets(line, 500, file) != NULL ) + while (stream.getline(line, 500)) { for ( i=0 ; i<500 ; i++ ) { @@ -4044,7 +4069,7 @@ void CMainDialog::IOReadName() break; } } - fclose(file); + stream.close(); } time(&now); @@ -4389,10 +4414,10 @@ void CMainDialog::AllMissionUpdate() void CMainDialog::UpdateSceneChap(int &chap) { - FILE* file = NULL; CWindow* pw; CList* pl; - //struct _finddata_t fileBuffer; + FILE *file; + std::string fileName; char op[100]; char op_i18n[100]; @@ -4477,14 +4502,15 @@ void CMainDialog::UpdateSceneChap(int &chap) for ( j=0 ; j<9 ; j++ ) { BuildSceneName(fileName, m_sceneName, (j+1)*100); - file = fopen(fileName.c_str(), "r"); - if ( file == NULL ) break; + CInputStream stream; + stream.open(fileName); + if (!stream.is_open()) break; BuildResumeName(name, m_sceneName, j+1); // default name sprintf(op, "Title.E"); sprintf(op_i18n, "Title.%c", m_app->GetLanguageChar()); - while ( fgets(line, 500, file) != NULL ) + while (stream.getline(line, 500)) { for ( i=0 ; i<500 ; i++ ) { @@ -4506,7 +4532,7 @@ void CMainDialog::UpdateSceneChap(int &chap) break; } } - fclose(file); + stream.close(); bPassed = GetGamerInfoPassed((j+1)*100); sprintf(line, "%d: %s", j+1, name); @@ -4538,7 +4564,6 @@ void CMainDialog::UpdateSceneChap(int &chap) void CMainDialog::UpdateSceneList(int chap, int &sel) { - FILE* file = NULL; CWindow* pw; CList* pl; std::string fileName; @@ -4564,14 +4589,16 @@ void CMainDialog::UpdateSceneList(int chap, int &sel) for ( j=0 ; j<99 ; j++ ) { BuildSceneName(fileName, m_sceneName, (chap+1)*100+(j+1)); - file = fopen(fileName.c_str(), "r"); - if ( file == NULL ) break; + + CInputStream stream; + stream.open(fileName); + if (!stream.is_open()) break; BuildResumeName(name, m_sceneName, j+1); // default name sprintf(op, "Title.E"); sprintf(op_i18n, "Title.%c", m_app->GetLanguageChar()); - while ( fgets(line, 500, file) != NULL ) + while (stream.getline(line, 500)) { for ( i=0 ; i<500 ; i++ ) { @@ -4593,7 +4620,7 @@ void CMainDialog::UpdateSceneList(int chap, int &sel) break; } } - fclose(file); + stream.close(); bPassed = GetGamerInfoPassed((chap+1)*100+(j+1)); sprintf(line, "%d: %s", j+1, name); @@ -4608,6 +4635,7 @@ void CMainDialog::UpdateSceneList(int chap, int &sel) } } + /* TODO: ????? BuildSceneName(fileName, m_sceneName, (chap+1)*100+(j+1)); file = fopen(fileName.c_str(), "r"); if ( file == NULL ) @@ -4618,7 +4646,8 @@ void CMainDialog::UpdateSceneList(int chap, int &sel) { m_maxList = j+1; // this is not the last! fclose(file); - } + }*/ + m_maxList = j; if ( sel > j-1 ) sel = j-1; @@ -4668,7 +4697,6 @@ void CMainDialog::ShowSoluceUpdate() void CMainDialog::UpdateSceneResume(int rank) { - FILE* file = NULL; CWindow* pw; CEdit* pe; CCheck* pc; @@ -4708,11 +4736,12 @@ void CMainDialog::UpdateSceneResume(int rank) sprintf(op, "Resume.E"); sprintf(op_i18n, "Resume.%c", m_app->GetLanguageChar()); - file = fopen(fileName.c_str(), "r"); - if ( file == NULL ) return; + CInputStream stream; + stream.open(fileName); + if (!stream.is_open()) return; name[0] = 0; - while ( fgets(line, 500, file) != NULL ) + while ( stream.getline(line, 500) ) { for ( i=0 ; i<500 ; i++ ) { @@ -4737,7 +4766,7 @@ void CMainDialog::UpdateSceneResume(int rank) break; } } - fclose(file); + stream.close(); pe->SetText(name); } @@ -5164,7 +5193,6 @@ void CMainDialog::ChangeSetupButtons() void CMainDialog::SetupMemorize() { - GetProfile().SetLocalProfileString("Directory", "scene", m_sceneDir); GetProfile().SetLocalProfileString("Directory", "savegame", m_savegameDir); GetProfile().SetLocalProfileString("Directory", "public", m_publicDir); GetProfile().SetLocalProfileString("Directory", "user", m_userDir); @@ -5243,11 +5271,6 @@ void CMainDialog::SetupRecall() int iValue; std::string key; - if ( GetProfile().GetLocalProfileString("Directory", "scene", key) ) - { - m_sceneDir = key; - } - if ( GetProfile().GetLocalProfileString("Directory", "savegame", key) ) { m_savegameDir = key; diff --git a/src/ui/maindialog.h b/src/ui/maindialog.h index 444a568..7732f9f 100644 --- a/src/ui/maindialog.h +++ b/src/ui/maindialog.h @@ -200,7 +200,6 @@ protected: int m_persoTab; // perso: tab selected float m_persoAngle; // perso: angle of presentation - std::string m_sceneDir; // scene folder std::string m_savegameDir; // savegame folder std::string m_publicDir; // program folder std::string m_userDir; // user folder diff --git a/src/ui/map.cpp b/src/ui/map.cpp index c5f0062..22cd616 100644 --- a/src/ui/map.cpp +++ b/src/ui/map.cpp @@ -322,7 +322,7 @@ void CMap::Draw() m_offset = AdjustOffset(m_map[MAPMAXOBJECT - 1].pos); if ( m_fixImage[0] == 0 ) { // drawing of the relief? - m_engine->SetTexture("map.png"); + m_engine->SetTexture("interface/map.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 0.5f + (m_offset.x - (m_half / m_zoom)) / (m_half * 2.0f); uv1.y = 0.5f - (m_offset.y + (m_half / m_zoom)) / (m_half * 2.0f); @@ -469,7 +469,7 @@ void CMap::DrawFocus(Math::Point pos, float dir, ObjectType type, MapColor color uv2.x = 126.0f/256.0f; uv2.y = 255.0f/256.0f; - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); bEnding = false; @@ -529,7 +529,7 @@ void CMap::DrawObject(Math::Point pos, float dir, ObjectType type, MapColor colo return; // flashes } - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); if ( bUp ) { @@ -672,7 +672,7 @@ void CMap::DrawObject(Math::Point pos, float dir, ObjectType type, MapColor colo { if ( bSelect ) { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); if ( m_bToy ) { @@ -698,7 +698,7 @@ void CMap::DrawObject(Math::Point pos, float dir, ObjectType type, MapColor colo { if ( m_bRadar ) { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); uv1.x = 64.5f/256.0f; // blue triangle uv1.y = 240.5f/256.0f; @@ -718,7 +718,7 @@ void CMap::DrawObject(Math::Point pos, float dir, ObjectType type, MapColor colo if ( color == MAPCOLOR_WAYPOINTb ) { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); uv1.x = 192.5f/256.0f; // blue cross uv1.y = 240.5f/256.0f; @@ -728,7 +728,7 @@ void CMap::DrawObject(Math::Point pos, float dir, ObjectType type, MapColor colo } if ( color == MAPCOLOR_WAYPOINTr ) { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); uv1.x = 208.5f/256.0f; // red cross uv1.y = 240.5f/256.0f; @@ -738,7 +738,7 @@ void CMap::DrawObject(Math::Point pos, float dir, ObjectType type, MapColor colo } if ( color == MAPCOLOR_WAYPOINTg ) { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); uv1.x = 224.5f/256.0f; // green cross uv1.y = 240.5f/256.0f; @@ -748,7 +748,7 @@ void CMap::DrawObject(Math::Point pos, float dir, ObjectType type, MapColor colo } if ( color == MAPCOLOR_WAYPOINTy ) { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); uv1.x = 240.5f/256.0f; // yellow cross uv1.y = 240.5f/256.0f; @@ -758,7 +758,7 @@ void CMap::DrawObject(Math::Point pos, float dir, ObjectType type, MapColor colo } if ( color == MAPCOLOR_WAYPOINTv ) { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); uv1.x = 192.5f/256.0f; // violet cross uv1.y = 224.5f/256.0f; @@ -779,7 +779,7 @@ void CMap::DrawObjectIcon(Math::Point pos, Math::Point dim, MapColor color, dp = 0.5f/256.0f; - m_engine->SetTexture("button3.png"); + m_engine->SetTexture("interface/button3.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); if ( color == MAPCOLOR_MOVE ) { @@ -894,7 +894,7 @@ void CMap::DrawHighlight(Math::Point pos) dim.x *= 2.0f+cosf(m_time*8.0f)*0.5f; dim.y *= 2.0f+cosf(m_time*8.0f)*0.5f; - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); uv1.x = 160.5f/256.0f; // hilite uv1.y = 224.5f/256.0f; @@ -1052,8 +1052,8 @@ void CMap::UpdateTerrain() } } - m_engine->DeleteTexture("map.png"); - m_engine->LoadTexture("map.png", &img); + m_engine->DeleteTexture("interface/map.png"); + m_engine->LoadTexture("interface/map.png", &img); } // Updates the field in the map. diff --git a/src/ui/scroll.cpp b/src/ui/scroll.cpp index b3422ec..6be1e6d 100644 --- a/src/ui/scroll.cpp +++ b/src/ui/scroll.cpp @@ -379,7 +379,7 @@ void CScroll::DrawVertex(Math::Point pos, Math::Point dim, int icon) if ( icon == 0 ) { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 0.0f/256.0f; // yellow rectangle uv1.y = 32.0f/256.0f; @@ -389,7 +389,7 @@ void CScroll::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else if ( icon == 1 ) { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 128.0f/256.0f; // gray rectangle uv1.y = 32.0f/256.0f; @@ -399,7 +399,7 @@ void CScroll::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else if ( icon == 2 ) { - m_engine->SetTexture("button1.png"); + m_engine->SetTexture("interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 64.0f/256.0f; // blue rectangle uv1.y = 0.0f/256.0f; @@ -409,7 +409,7 @@ void CScroll::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 104.0f/256.0f; // blue line - uv1.y = 32.0f/256.0f; diff --git a/src/ui/shortcut.cpp b/src/ui/shortcut.cpp index a01864a..456b69a 100644 --- a/src/ui/shortcut.cpp +++ b/src/ui/shortcut.cpp @@ -114,7 +114,7 @@ void CShortcut::Draw() zoom = 1.0f; } - m_engine->SetTexture("button3.png"); + m_engine->SetTexture("interface/button3.png"); if ( icon != -1 ) { @@ -130,7 +130,7 @@ void CShortcut::Draw() Math::Point p1, p2, c, uv1, uv2; float dp; - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); zoom = 0.9f+sinf(m_time*8.0f)*0.1f; @@ -170,7 +170,7 @@ void CShortcut::Draw() Math::Point uv1, uv2; float dp; - m_engine->SetTexture("button3.png"); + m_engine->SetTexture("interface/button3.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); uv1.x = 160.0f/256.0f; diff --git a/src/ui/slider.cpp b/src/ui/slider.cpp index 33293d1..9078cfe 100644 --- a/src/ui/slider.cpp +++ b/src/ui/slider.cpp @@ -498,7 +498,7 @@ void CSlider::DrawVertex(Math::Point pos, Math::Point dim, int icon) if ( icon == 0 ) { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 0.0f/256.0f; // yellow rectangle uv1.y = 32.0f/256.0f; @@ -510,7 +510,7 @@ void CSlider::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else if ( icon == 1 ) { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 128.0f/256.0f; // gray rectangle uv1.y = 32.0f/256.0f; @@ -522,7 +522,7 @@ void CSlider::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 224.0f/256.0f; // cursor uv1.y = 32.0f/256.0f; diff --git a/src/ui/window.cpp b/src/ui/window.cpp index 98e1e6c..9740f7f 100644 --- a/src/ui/window.cpp +++ b/src/ui/window.cpp @@ -1174,7 +1174,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) if ( icon == 0 ) { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); uv1.x = 64.0f/256.0f; // dark blue transparent uv1.y = 64.0f/256.0f; @@ -1190,7 +1190,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else if ( icon == 1 ) { - m_engine->SetTexture("button1.png"); + m_engine->SetTexture("interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 128.0f/256.0f; // white tooltip uv1.y = 0.0f/256.0f; @@ -1204,7 +1204,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else if ( icon == 2 ) { - m_engine->SetTexture("button1.png"); + m_engine->SetTexture("interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 128.0f/256.0f; // yellow uv1.y = 16.0f/256.0f; @@ -1218,7 +1218,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else if ( icon == 3 ) { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); uv1.x = 0.0f/256.0f; // transparent blue bar with yellow upper uv1.y = 64.0f/256.0f; @@ -1237,7 +1237,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) dim.x += 100.0f/640.0f; dim.y += 60.0f/480.0f; - m_engine->SetTexture("human.png"); + m_engine->SetTexture("interface/human.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 140.0f/256.0f; uv1.y = 32.0f/256.0f; @@ -1254,7 +1254,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) dim.x -= 20.0f/640.0f; dim.y += 0.0f/480.0f; - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); uv1.x = 192.0f/256.0f; uv1.y = 32.0f/256.0f; @@ -1273,7 +1273,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) dim.x -= 20.0f/640.0f; dim.y -= 20.0f/480.0f; - m_engine->SetTexture("button1.png"); + m_engine->SetTexture("interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 64.0f/256.0f; uv1.y = 0.0f/256.0f; @@ -1309,7 +1309,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) dim.x -= 20.0f/640.0f; dim.y -= 20.0f/480.0f; - m_engine->SetTexture("button3.png"); + m_engine->SetTexture("interface/button3.png"); uv1.x = 0.0f/256.0f; uv1.y = 224.0f/256.0f; uv2.x = 32.0f/256.0f; @@ -1320,7 +1320,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) uv2.y -= dp; DrawIcon(pos, dim, uv1, uv2); // dark blue background - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); uv1.x = 224.0f/256.0f; uv1.y = 224.0f/256.0f; uv2.x = 249.0f/256.0f; @@ -1392,7 +1392,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else if ( icon == 5 ) { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); uv1.x = 64.0f/256.0f; // transparent green uv1.y = 160.0f/256.0f; @@ -1406,7 +1406,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else if ( icon == 6 ) { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); uv1.x = 64.0f/256.0f; // transparent red uv1.y = 176.0f/256.0f; @@ -1420,7 +1420,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else if ( icon == 7 ) { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); uv1.x = 64.0f/256.0f; // transparent blue uv1.y = 192.0f/256.0f; @@ -1434,7 +1434,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else if ( icon == 8 ) { - m_engine->SetTexture("button1.png"); + m_engine->SetTexture("interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 0.0f/256.0f; // opaque orange uv1.y = 0.0f/256.0f; @@ -1450,7 +1450,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else if ( icon == 9 ) { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 32.0f/256.0f; // opaque gray uv1.y = 32.0f/256.0f; @@ -1470,7 +1470,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else if ( icon == 11 ) { - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); uv1.x = 64.0f/256.0f; // transparent yellow uv1.y = 224.0f/256.0f; @@ -1484,7 +1484,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else if ( icon == 12 ) { - m_engine->SetTexture("button1.png"); + m_engine->SetTexture("interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 128.0f/256.0f; // dirty opaque gray uv1.y = 128.0f/256.0f; @@ -1500,7 +1500,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else if ( icon == 13 ) { - m_engine->SetTexture("button1.png"); + m_engine->SetTexture("interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 192.0f/256.0f; // dirty opaque blue uv1.y = 128.0f/256.0f; @@ -1516,7 +1516,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else if ( icon == 14 ) { - m_engine->SetTexture("button1.png"); + m_engine->SetTexture("interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 160.0f/256.0f; // dirty opaque red uv1.y = 128.0f/256.0f; @@ -1542,7 +1542,7 @@ void CWindow::DrawHach(Math::Point pos, Math::Point dim) dp = 0.5f/256.0f; - m_engine->SetTexture("button2.png"); + m_engine->SetTexture("interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 64.0f/256.0f; // hatching uv1.y = 208.0f/256.0f; diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index bdb5a67..269ffc2 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -23,7 +23,6 @@ configure_file(${SRC_DIR}/common/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/comm # Code sources set(COLOBOT_SOURCES ${SRC_DIR}/app/app.cpp -${SRC_DIR}/app/gamedata.cpp ${SRC_DIR}/app/pausemanager.cpp ${SRC_DIR}/app/system.cpp ${SRC_DIR}/app/${SYSTEM_CPP_MODULE} diff --git a/test/unit/ui/CMakeLists.txt b/test/unit/ui/CMakeLists.txt index 7f7b2f8..503f84b 100644 --- a/test/unit/ui/CMakeLists.txt +++ b/test/unit/ui/CMakeLists.txt @@ -17,7 +17,6 @@ else() endif() add_executable(edit_test -${SRC_DIR}/app/gamedata.cpp ${SRC_DIR}/app/system.cpp ${SRC_DIR}/app/${SYSTEM_CPP_MODULE} ${SRC_DIR}/app/system_other.cpp |