diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dc003b98..c41ebb07 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -64,12 +64,11 @@ app/main.cpp app/system.cpp common/event.cpp common/image.cpp -common/logger.cpp common/iman.cpp -# common/metafile.cpp -# common/misc.cpp -# common/modfile.cpp -# common/profile.cpp +common/logger.cpp +common/metafile.cpp +common/misc.cpp +common/profile.cpp common/restext.cpp common/restext_strings.c common/stringutils.cpp @@ -191,7 +190,10 @@ ${PLATFORM_LIBS} CBot ) -include_directories(. ${CMAKE_CURRENT_BINARY_DIR} +include_directories( +. +.. +${CMAKE_CURRENT_BINARY_DIR} ${SDL_INCLUDE_DIR} ${SDL_IMAGE_INCLUDE_DIR} ${SDLTTF_INCLUDE_DIR} diff --git a/src/app/app.cpp b/src/app/app.cpp index 00cd13d1..981146d3 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -32,7 +32,7 @@ #include -template<> CApplication* CSingleton::mInstance = NULL; +template<> CApplication* CSingleton::mInstance = nullptr; //! Interval of timer called to update joystick state @@ -62,8 +62,8 @@ struct ApplicationPrivate ApplicationPrivate() { memset(¤tEvent, 0, sizeof(SDL_Event)); - surface = NULL; - joystick = NULL; + surface = nullptr; + joystick = nullptr; joystickTimer = 0; } }; @@ -76,10 +76,10 @@ CApplication::CApplication() m_iMan = new CInstanceManager(); m_eventQueue = new CEventQueue(m_iMan); - m_engine = NULL; - m_device = NULL; - m_robotMain = NULL; - m_sound = NULL; + m_engine = nullptr; + m_device = nullptr; + m_robotMain = nullptr; + m_sound = nullptr; m_keyState = 0; m_axeKey = Math::Vector(0.0f, 0.0f, 0.0f); @@ -95,19 +95,21 @@ CApplication::CApplication() m_dataPath = "./data"; + m_language = LANG_ENGLISH; + ResetKey(); } CApplication::~CApplication() { delete m_private; - m_private = NULL; + m_private = nullptr; delete m_eventQueue; - m_eventQueue = NULL; + m_eventQueue = nullptr; delete m_iMan; - m_iMan = NULL; + m_iMan = nullptr; } bool CApplication::ParseArguments(int argc, char *argv[]) @@ -218,7 +220,7 @@ bool CApplication::Create() if (! CreateVideoSurface()) return false; // dialog is in function - if (m_private->surface == NULL) + if (m_private->surface == nullptr) { m_errorMessage = std::string("SDL error while setting video mode:\n") + std::string(SDL_GetError()); @@ -269,7 +271,7 @@ bool CApplication::Create() bool CApplication::CreateVideoSurface() { const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo(); - if (videoInfo == NULL) + if (videoInfo == nullptr) { m_errorMessage = std::string("SDL error while getting video info:\n ") + std::string(SDL_GetError()); @@ -321,44 +323,44 @@ bool CApplication::CreateVideoSurface() void CApplication::Destroy() { - /*if (m_robotMain != NULL) + /*if (m_robotMain != nullptr) { delete m_robotMain; - m_robotMain = NULL; + m_robotMain = nullptr; } - if (m_sound != NULL) + if (m_sound != nullptr) { delete m_sound; - m_sound = NULL; + m_sound = nullptr; }*/ - if (m_engine != NULL) + if (m_engine != nullptr) { m_engine->Destroy(); delete m_engine; - m_engine = NULL; + m_engine = nullptr; } - if (m_device != NULL) + if (m_device != nullptr) { m_device->Destroy(); delete m_device; - m_device = NULL; + m_device = nullptr; } - if (m_private->joystick != NULL) + if (m_private->joystick != nullptr) { SDL_JoystickClose(m_private->joystick); - m_private->joystick = NULL; + m_private->joystick = nullptr; } - if (m_private->surface != NULL) + if (m_private->surface != nullptr) { SDL_FreeSurface(m_private->surface); - m_private->surface = NULL; + m_private->surface = nullptr; } IMG_Quit(); @@ -383,7 +385,7 @@ bool CApplication::ChangeVideoConfig(const Gfx::GLDeviceConfig &newConfig) return false; } - if (m_private->surface == NULL) + if (m_private->surface == nullptr) { if (! restore) { @@ -426,7 +428,7 @@ bool CApplication::OpenJoystick() return false; m_private->joystick = SDL_JoystickOpen(m_joystick.index); - if (m_private->joystick == NULL) + if (m_private->joystick == nullptr) return false; m_joystick.axisCount = SDL_JoystickNumAxes(m_private->joystick); @@ -437,7 +439,7 @@ bool CApplication::OpenJoystick() m_joyButtonState = std::vector(m_joystick.buttonCount, false); // Create a timer for polling joystick state - m_private->joystickTimer = SDL_AddTimer(JOYSTICK_TIMER_INTERVAL, JoystickTimerCallback, NULL); + m_private->joystickTimer = SDL_AddTimer(JOYSTICK_TIMER_INTERVAL, JoystickTimerCallback, nullptr); return true; } @@ -447,7 +449,7 @@ void CApplication::CloseJoystick() // Timer will remove itself automatically SDL_JoystickClose(m_private->joystick); - m_private->joystick = NULL; + m_private->joystick = nullptr; } bool CApplication::ChangeJoystick(const JoystickDevice &newJoystick) @@ -455,7 +457,7 @@ bool CApplication::ChangeJoystick(const JoystickDevice &newJoystick) if ( (newJoystick.index < 0) || (newJoystick.index >= SDL_NumJoysticks()) ) return false; - if (m_private->joystick != NULL) + if (m_private->joystick != nullptr) CloseJoystick(); return OpenJoystick(); @@ -464,7 +466,7 @@ bool CApplication::ChangeJoystick(const JoystickDevice &newJoystick) Uint32 JoystickTimerCallback(Uint32 interval, void *) { CApplication *app = CApplication::GetInstancePointer(); - if ((app == NULL) || (! app->GetJoystickEnabled())) + if ((app == nullptr) || (! app->GetJoystickEnabled())) return 0; // don't run the timer again app->UpdateJoystick(); @@ -577,7 +579,7 @@ int CApplication::Run() { bool passOn = ProcessEvent(event); - if (m_engine != NULL && passOn) + if (m_engine != nullptr && passOn) passOn = m_engine->ProcessEvent(event); if (passOn) @@ -602,11 +604,11 @@ int CApplication::Run() { passOn = ProcessEvent(event); - if (passOn && m_engine != NULL) + if (passOn && m_engine != nullptr) passOn = m_engine->ProcessEvent(event); } - /*if (passOn && m_robotMain != NULL) + /*if (passOn && m_robotMain != nullptr) m_robotMain->ProcessEvent(event); */ } @@ -814,7 +816,7 @@ VideoQueryResult CApplication::GetVideoResolutionList(std::vector -#include -#include - -#include - +#include "common/key.h" +#include "common/event_ids.h" +#include "math/point.h" class CInstanceManager; @@ -193,40 +193,8 @@ struct Event }; -/** - \enum KeyRank - \brief Slots for key assignment of user controls - */ - -// TODO: move to global.h ? - -enum KeyRank -{ - KEYRANK_LEFT = 0, - KEYRANK_RIGHT = 1, - KEYRANK_UP = 2, - KEYRANK_DOWN = 3, - KEYRANK_GUP = 4, - KEYRANK_GDOWN = 5, - KEYRANK_CAMERA = 6, - KEYRANK_DESEL = 7, - KEYRANK_ACTION = 8, - KEYRANK_NEAR = 9, - KEYRANK_AWAY = 10, - KEYRANK_NEXT = 11, - KEYRANK_HUMAN = 12, - KEYRANK_QUIT = 13, - KEYRANK_HELP = 14, - KEYRANK_PROG = 15, - KEYRANK_VISIT = 16, - KEYRANK_SPEED10 = 17, - KEYRANK_SPEED15 = 18, - KEYRANK_SPEED20 = 19, - KEYRANK_SPEED30 = 20, - KEYRANK_AIMUP = 21, - KEYRANK_AIMDOWN = 22, - KEYRANK_CBOT = 23, -}; +//! Returns an unique event type (above the standard IDs) +EventType GetUniqueEventType(); /** @@ -261,5 +229,3 @@ protected: int m_tail; int m_total; }; - - diff --git a/src/common/event_ids.h b/src/common/event_ids.h index ab235d54..1bbc9bec 100644 --- a/src/common/event_ids.h +++ b/src/common/event_ids.h @@ -14,6 +14,9 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. + +// TODO: move to event.h after restext rewrite + #pragma once /** diff --git a/src/common/global.h b/src/common/global.h index 670c578d..acc5b8f3 100644 --- a/src/common/global.h +++ b/src/common/global.h @@ -14,53 +14,110 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// global.h +/** + * \file common/global.h + * \brief Some common, global definitions + */ #pragma once +#include "error_ids.h" +/** + * \enum Language + * \brief Application language + */ +enum Language +{ + LANG_ENGLISH = 0, + LANG_FRENCH = 1, + LANG_GERMAN = 2, + LANG_POLISH = 3 +}; + +/** + * \enum BuildType + * \brief Construction actions (buildings, etc.) available to user + * + * TODO: refactor + */ enum BuildType { - BUILD_FACTORY = (1<<0), // factory - BUILD_DERRICK = (1<<1), // derrick - BUILD_CONVERT = (1<<2), // converter - BUILD_RADAR = (1<<3), // radar - BUILD_ENERGY = (1<<4), // factory of cells - BUILD_NUCLEAR = (1<<5), // nuclear power plant - BUILD_STATION = (1<<6), // base station - BUILD_REPAIR = (1<<7), // repair center - BUILD_TOWER = (1<<8), // defense tower - BUILD_RESEARCH = (1<<9), // research center - BUILD_LABO = (1<<10), // laboratory - BUILD_PARA = (1<<11), // lightning protection - BUILD_INFO = (1<<12), // information terminal - BUILD_GFLAT = (1<<16), // flat floor - BUILD_FLAG = (1<<17) // puts / removes colored flag + BUILD_FACTORY = (1<<0), //! < factory + BUILD_DERRICK = (1<<1), //! < derrick + BUILD_CONVERT = (1<<2), //! < converter + BUILD_RADAR = (1<<3), //! < radar + BUILD_ENERGY = (1<<4), //! < factory of cells + BUILD_NUCLEAR = (1<<5), //! < nuclear power plant + BUILD_STATION = (1<<6), //! < base station + BUILD_REPAIR = (1<<7), //! < repair center + BUILD_TOWER = (1<<8), //! < defense tower + BUILD_RESEARCH = (1<<9), //! < research center + BUILD_LABO = (1<<10), //! < laboratory + BUILD_PARA = (1<<11), //! < lightning protection + BUILD_INFO = (1<<12), //! < information terminal + BUILD_GFLAT = (1<<16), //! < flat floor + BUILD_FLAG = (1<<17) //! < puts / removes colored flag }; - -// Do not change values ​​was because of backups (bits = ...). +/** + * \enum ResearchType + * \brief Research actions available to user + */ enum ResearchType { - RESEARCH_TANK = (1<<0), // caterpillars - RESEARCH_FLY = (1<<1), // wings - RESEARCH_CANON = (1<<2), // cannon - RESEARCH_TOWER = (1<<3), // defense tower - RESEARCH_ATOMIC = (1<<4), // nuclear - RESEARCH_THUMP = (1<<5), // thumper - RESEARCH_SHIELD = (1<<6), // shield - RESEARCH_PHAZER = (1<<7), // phazer gun - RESEARCH_iPAW = (1<<8), // legs of insects - RESEARCH_iGUN = (1<<9), // cannon of insects - RESEARCH_RECYCLER = (1<<10), // recycler - RESEARCH_SUBM = (1<<11), // submarine - RESEARCH_SNIFFER = (1<<12) // sniffer + RESEARCH_TANK = (1<<0), //! < caterpillars + RESEARCH_FLY = (1<<1), //! < wings + RESEARCH_CANON = (1<<2), //! < cannon + RESEARCH_TOWER = (1<<3), //! < defense tower + RESEARCH_ATOMIC = (1<<4), //! < nuclear + RESEARCH_THUMP = (1<<5), //! < thumper + RESEARCH_SHIELD = (1<<6), //! < shield + RESEARCH_PHAZER = (1<<7), //! < phazer gun + RESEARCH_iPAW = (1<<8), //! < legs of insects + RESEARCH_iGUN = (1<<9), //! < cannon of insects + RESEARCH_RECYCLER = (1<<10), //! < recycler + RESEARCH_SUBM = (1<<11), //! < submarine + RESEARCH_SNIFFER = (1<<12) //! < sniffer }; +/** + * \enum KeyRank + * \brief Slots for key assignment of user controls + * + * TODO: refactor + */ +enum KeyRank +{ + KEYRANK_LEFT = 0, + KEYRANK_RIGHT = 1, + KEYRANK_UP = 2, + KEYRANK_DOWN = 3, + KEYRANK_GUP = 4, + KEYRANK_GDOWN = 5, + KEYRANK_CAMERA = 6, + KEYRANK_DESEL = 7, + KEYRANK_ACTION = 8, + KEYRANK_NEAR = 9, + KEYRANK_AWAY = 10, + KEYRANK_NEXT = 11, + KEYRANK_HUMAN = 12, + KEYRANK_QUIT = 13, + KEYRANK_HELP = 14, + KEYRANK_PROG = 15, + KEYRANK_VISIT = 16, + KEYRANK_SPEED10 = 17, + KEYRANK_SPEED15 = 18, + KEYRANK_SPEED20 = 19, + KEYRANK_SPEED30 = 20, + KEYRANK_AIMUP = 21, + KEYRANK_AIMDOWN = 22, + KEYRANK_CBOT = 23, +}; + +// TODO: move to CRobotMain extern long g_id; // unique identifier extern long g_build; // constructible buildings extern long g_researchDone; // research done extern long g_researchEnable; // research available extern float g_unit; // conversion factor - - diff --git a/src/common/image.h b/src/common/image.h index 4d86d317..7588ea98 100644 --- a/src/common/image.h +++ b/src/common/image.h @@ -14,7 +14,10 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// image.h +/** + * \file common/image.h + * \brief Class for loading and saving images + */ #pragma once diff --git a/src/common/iman.cpp b/src/common/iman.cpp index 4b89ecff..e59afb18 100644 --- a/src/common/iman.cpp +++ b/src/common/iman.cpp @@ -16,12 +16,10 @@ // iman.cpp - -#include - -#include "common/struct.h" #include "common/iman.h" +#include + template<> CInstanceManager* CSingleton::mInstance = nullptr; @@ -39,139 +37,91 @@ CInstanceManager* CInstanceManager::GetInstancePointer() return mInstance; } - -// Object's constructor. - CInstanceManager::CInstanceManager() { - int i; - - for ( i=0 ; i= CLASS_MAX ) return; - if ( m_table[classType].classPointer == 0 ) return; + if (classType < 0 || classType >= CLASS_MAX) return; + if (m_table[classType].instances == nullptr) return; - free(m_table[classType].classPointer); - m_table[classType].classPointer = 0; + delete[] m_table[classType].instances; + m_table[classType].instances = nullptr; } - -// Adds a new instance of a class. - -bool CInstanceManager::AddInstance(ClassType classType, void* pointer, int max) +bool CInstanceManager::AddInstance(ManagedClassType classType, void* instance, int max) { - int i; + if (classType < 0 || classType >= CLASS_MAX) return false; - if ( classType < 0 || classType >= CLASS_MAX ) return false; - - if ( m_table[classType].classPointer == 0 ) + if (m_table[classType].instances == nullptr) { - m_table[classType].classPointer = static_cast( malloc(max*sizeof(void*)) ); - m_table[classType].totalPossible = max; - m_table[classType].totalUsed = 0; + m_table[classType].instances = new void*[max]; + m_table[classType].maxCount = max; + m_table[classType].usedCount = 0; } - if ( m_table[classType].totalUsed >= m_table[classType].totalPossible ) return false; + if (m_table[classType].usedCount >= m_table[classType].maxCount) return false; - i = m_table[classType].totalUsed++; - m_table[classType].classPointer[i] = pointer; + int i = m_table[classType].usedCount++; + m_table[classType].instances[i] = instance; return true; } -// Deletes an instance of a class. - -bool CInstanceManager::DeleteInstance(ClassType classType, void* pointer) +bool CInstanceManager::DeleteInstance(ManagedClassType classType, void* instance) { - int i; + if (classType < 0 || classType >= CLASS_MAX) return false; - if ( classType < 0 || classType >= CLASS_MAX ) return false; - - for ( i=0 ; i= CLASS_MAX ) return 0; - if ( m_table[classType].classPointer == 0 ) return 0; -#endif - if ( rank >= m_table[classType].totalUsed ) return 0; + if (classType < 0 || classType >= CLASS_MAX) return nullptr; + if (m_table[classType].instances == nullptr) return nullptr; + if (rank >= m_table[classType].usedCount) return nullptr; - return m_table[classType].classPointer[rank]; + return m_table[classType].instances[rank]; } - -// Fills holes in a table. - -void CInstanceManager::Compress(ClassType classType) +void CInstanceManager::Compress(ManagedClassType classType) { - int i, j; + if (classType < 0 || classType >= CLASS_MAX) return; - if ( classType < 0 || classType >= CLASS_MAX ) return; - - j = 0; - for ( i=0 ; i +/** + * \enum ManagedClassType + * \brief Type of class managed by CInstanceManager + */ -struct BaseClass +// TODO: remove unnecessary, refactor to singletons, move to CRobotMain, keep others? + +enum ManagedClassType { - int totalPossible; - int totalUsed; - void** classPointer; + //! CEventQueue + CLASS_EVENT = 1, + //! Ui::CInterface + CLASS_INTERFACE = 2, + //! CRobotMain + CLASS_MAIN = 3, + //! Gfx::CEngine + CLASS_ENGINE = 4, + //! Gfx::CTerrain + CLASS_TERRAIN = 5, + //! CObject + CLASS_OBJECT = 6, + //! CPhysics + CLASS_PHYSICS = 7, + //! CBrain + CLASS_BRAIN = 8, + //! Gfx::CCamera + CLASS_CAMERA = 9, + //! Gfx::CLightManager + CLASS_LIGHT = 10, + //! Gfx::CParticle + CLASS_PARTICULE = 11, + //! CAuto; TODO: remove (unused) + CLASS_AUTO = 12, + //! Ui::CDisplayText + CLASS_DISPLAYTEXT = 13, + //! Gfx::CPyro + CLASS_PYRO = 14, + //! Ui::CScript; TODO: remove (unused) + CLASS_SCRIPT = 15, + //! Gfx::CText + CLASS_TEXT = 16, + //! Ui::CStudio, Ui::CDisplayText; TODO: remove (unused) + CLASS_STUDIO = 17, + //! Gfx::CWater + CLASS_WATER = 18, + //! Gfx::CCloud; TODO: remove (unused) + CLASS_CLOUD = 19, + //! CMotion; TODO: remove (unused) + CLASS_MOTION = 20, + //! CSoundInterface + CLASS_SOUND = 21, + //! Gfx::CPlanet + CLASS_PLANET = 22, + //! CTaskManager; TODO: remove (unused) + CLASS_TASKMANAGER = 23, + //! Ui::CMainDialog; TODO: remove (unused) + CLASS_DIALOG = 24, + //! Ui::CMainMap; TODO: remove (unused) + CLASS_MAP = 25, + //! Ui::CMainShort, CMainMovie; TODO: remove (unused) + CLASS_SHORT = 26, + //! Gfx::CLightning; TODO: remove (unused) + CLASS_BLITZ = 27, + + //! Maximum (number of managed classes) + CLASS_MAX = 30 }; +/** + * \enum ManagedClassInstances + * \brief Instances of class managed by CInstanceManager + */ +struct ManagedClassInstances +{ + int maxCount; + int usedCount; + void** instances; +}; +/** + * \class CInstanceManager + * \brief Manager for instances of certain classes + * + * Instance manager (often shortened to iMan) allows to register instances of + * classes and search them. + */ class CInstanceManager : public CSingleton { public: CInstanceManager(); ~CInstanceManager(); + //! Remove all managed instances void Flush(); - void Flush(ClassType classType); - bool AddInstance(ClassType classType, void* pointer, int max=1); - bool DeleteInstance(ClassType classType, void* pointer); - void* SearchInstance(ClassType classType, int rank=0); + //! Removes instances of one type of class + void Flush(ManagedClassType classType); + //! Registers new instance of class type + bool AddInstance(ManagedClassType classType, void* instance, int max=1); + //! Deletes the registered instance of class type + bool DeleteInstance(ManagedClassType classType, void* instance); + //! Seeks a class instance of given type + void* SearchInstance(ManagedClassType classType, int rank=0); static CInstanceManager& GetInstance(); static CInstanceManager* GetInstancePointer(); protected: - void Compress(ClassType classType); + //! Fills holes in instance table + void Compress(ManagedClassType classType); protected: - BaseClass m_table[CLASS_MAX]; + ManagedClassInstances m_table[CLASS_MAX]; }; diff --git a/src/common/ioutils.h b/src/common/ioutils.h index 2a542c6a..e7668eb6 100644 --- a/src/common/ioutils.h +++ b/src/common/ioutils.h @@ -14,7 +14,10 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// ioutils.h +/** + * \file ioutils.h + * \brief Functions for binary I/O + */ #pragma once diff --git a/src/common/language.h b/src/common/language.h deleted file mode 100644 index 82a7235c..00000000 --- a/src/common/language.h +++ /dev/null @@ -1,54 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * -// * 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/. - -// language.h - -#pragma once - - -#define _FULL true // CoLoBoT -#define _SCHOOL false // CeeBot-A or Teen - #define _TEEN false // false for CeeBot-A, true for CeeBot-Teen - #define _EDU false - #define _PERSO false - #define _CEEBOTDEMO false -#define _NET false -#define _DEMO false // DEMO only CoLoBoT (with _Full = false)! - -#define _FRENCH false -#define _ENGLISH true -#define _GERMAN false -#define _WG false -#define _POLISH false - -#define _NEWLOOK false // false for CoLoBoT, true for all CeeBot -#define _SOUNDTRACKS false // always false since InitAudioTrackVolume crop in Vista - - -// Verifications - -#if !_FULL & !_SCHOOL & !_NET & !_DEMO --> no version chosen! -#endif - -#if _SCHOOL -#if !_EDU & !_PERSO & !_CEEBOTDEMO --> EDU or PERSO or CEEBOTDEMO? -#endif -#if _EDU & _PERSO & _CEEBOTDEMO --> EDU and PERSO and CEEBOTDEMO not at the same time!!! -#endif -#endif diff --git a/src/common/logger.h b/src/common/logger.h index fc43735e..dfeeb988 100644 --- a/src/common/logger.h +++ b/src/common/logger.h @@ -14,22 +14,20 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// logger.h +/** + * \file common/logger.h + * \brief Class for logging information to file or console + */ #pragma once +#include "common/singleton.h" + #include #include #include -#include - -/** - * @file common/logger.h - * @brief Class for loggin information to file or console - */ - /** * \public diff --git a/src/common/metafile.cpp b/src/common/metafile.cpp index 9d54f78f..d1692cef 100644 --- a/src/common/metafile.cpp +++ b/src/common/metafile.cpp @@ -16,17 +16,15 @@ // metafile.cpp - -#include -#include - -#include "common/language.h" #include "common/metafile.h" +#include +#include +#include -#if _FULL | _NET +//#if _FULL | _NET static unsigned char table_codec[23] = { 0x85, 0x91, 0x73, 0xcf, 0xa2, 0xbb, 0xf4, 0x77, @@ -44,9 +42,9 @@ void Codec(void* buffer, int len, int start) b[i] ^= table_codec[(start++)%23]; } } -#endif +//#endif -#if _SCHOOL +/*#if _SCHOOL #if _CEEBOTDEMO static unsigned char table_codec[136] = { @@ -99,9 +97,9 @@ void Codec(void* buffer, int len, int start) } } #endif -#endif +#endif*/ -#if _DEMO +/*#if _DEMO static unsigned char table_codec[27] = { 0x85, 0x91, 0x77, 0xcf, 0xa3, 0xbb, 0xf4, 0x77, @@ -120,7 +118,7 @@ void Codec(void* buffer, int len, int start) b[i] ^= table_codec[(start++)%27]; } } -#endif +#endif*/ @@ -286,7 +284,7 @@ int CMetaFile::Read(void *buffer, int size) int CMetaFile::GetByte() { - BYTE b; + int b; if ( !m_bOpen ) return 1; @@ -303,7 +301,7 @@ int CMetaFile::GetByte() int CMetaFile::GetWord() { - WORD w; + int w; if ( !m_bOpen ) return 1; diff --git a/src/common/misc.cpp b/src/common/misc.cpp index 24273569..3da8f242 100644 --- a/src/common/misc.cpp +++ b/src/common/misc.cpp @@ -17,45 +17,20 @@ // misc.cpp +#include "common/misc.h" + #include #include #include +#include #include -#include #include -#include - -#include "common/struct.h" -#include "old/d3dengine.h" -#include "old/d3dmath.h" -#include "old/d3dutil.h" -#include "common/language.h" -#include "common/event.h" -#include "common/misc.h" - -CMetaFile g_metafile; - -static EventMsg g_uniqueEventMsg = EVENT_USER; static bool g_bUserDir = false; static char g_userDir[100] = ""; - -// Gives a single user event. - -EventMsg GetUniqueEventMsg() -{ - int i; - - i = (int)g_uniqueEventMsg+1; - g_uniqueEventMsg = (EventMsg)i; - return g_uniqueEventMsg; -} - - - // Returns a non-accented letter. char RetNoAccent(char letter) @@ -311,7 +286,8 @@ bool CopyFileToTemp(char* filename) UserDir(dst, filename, "textures"); strcpy(g_userDir, save); - _mkdir("temp"); + //_mkdir("temp"); + system("mkdir temp"); if ( !Xfer(src, dst) ) return false; strcpy(filename, dst); @@ -418,24 +394,3 @@ void UserDir(char* buffer, char* dir, char* def) } *buffer = 0; } - - -// Returns the letter corresponding to the language. - -char RetLanguageLetter() -{ -#if _FRENCH - return 'F'; -#endif -#if _ENGLISH - return 'E'; -#endif -#if _GERMAN | _WG - return 'D'; -#endif -#if _POLISH - return 'P'; -#endif - return 'X'; -} - diff --git a/src/common/misc.h b/src/common/misc.h index dca801f9..66da4786 100644 --- a/src/common/misc.h +++ b/src/common/misc.h @@ -22,55 +22,7 @@ #include -#include "common/metafile.h" -#include "common/event.h" -#include "common/error_ids.h" - - -extern CMetaFile g_metafile; - - - -// Existing classes. - -enum ClassType -{ - CLASS_EVENT = 1, - CLASS_INTERFACE = 2, - CLASS_MAIN = 3, - CLASS_ENGINE = 4, - CLASS_TERRAIN = 5, - CLASS_OBJECT = 6, - CLASS_PHYSICS = 7, - CLASS_BRAIN = 8, - CLASS_CAMERA = 9, - CLASS_LIGHT = 10, - CLASS_PARTICULE = 11, - CLASS_AUTO = 12, - CLASS_DISPLAYTEXT = 13, - CLASS_PYRO = 14, - CLASS_SCRIPT = 15, - CLASS_TEXT = 16, - CLASS_STUDIO = 17, - CLASS_WATER = 18, - CLASS_CLOUD = 19, - CLASS_MOTION = 20, - CLASS_SOUND = 21, - CLASS_PLANET = 22, - CLASS_TASKMANAGER = 23, - CLASS_DIALOG = 24, - CLASS_MAP = 25, - CLASS_SHORT = 26, - CLASS_BLITZ = 27, -}; - -const int CLASS_MAX = 30; - - - - -// Keyboard state. - +// TODO: to be removed const int KS_PAGEUP = (1<<4); const int KS_PAGEDOWN = (1<<5); const int KS_SHIFT = (1<<6); @@ -84,10 +36,7 @@ const int KS_NUMRIGHT = (1<<13); const int KS_NUMPLUS = (1<<14); const int KS_NUMMINUS = (1<<15); - -// Procedures. - -extern EventType GetUniqueEventType(); +// TODO: rewrite/refactor or remove extern char RetNoAccent(char letter); extern char RetToUpper(char letter); @@ -100,7 +49,3 @@ extern bool CopyFileListToTemp(char* filename, int* list, int total); extern void AddExt(char* filename, char* ext); extern void UserDir(bool bUser, char* dir); extern void UserDir(char* buffer, char* dir, char* def); - -extern char RetLanguageLetter(); - - diff --git a/src/common/profile.cpp b/src/common/profile.cpp index 29a68e14..efcfa66c 100644 --- a/src/common/profile.cpp +++ b/src/common/profile.cpp @@ -17,7 +17,10 @@ // profile.cpp -#include +#include "common/profile.h" + +#include +#include template<> CProfile* CSingleton::mInstance = nullptr; diff --git a/src/common/profile.h b/src/common/profile.h index 08865220..7a23d94a 100644 --- a/src/common/profile.h +++ b/src/common/profile.h @@ -14,22 +14,19 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// profile.h +/** + * \file common/profile.h + * \brief Class for loading profile (currently for loading ini config file) + */ #pragma once -#include +#include "lib/simpleini/SimpleIni.h" + +#include "common/singleton.h" + +#include #include -#include - -#include - -#include - -/** - * @file common/profile.h - * @brief Class for loading profile (currently for loading ini config file) - */ /** diff --git a/src/common/restext.cpp b/src/common/restext.cpp index 487d1a66..e66c70e7 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -14,29 +14,19 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/.// restext.cpp -#include -#include -#include "common/struct.h" -#include "common/language.h" -#include "common/misc.h" -#include "common/event.h" -#include "object/object.h" -#include "CBot/resource.h" #include "common/restext.h" +#include "common/global.h" +#include "common/event.h" +#include "CBot/resource.h" +#include "object/object.h" + +#include +#include -// Gives the pointer to the engine. -static CD3DEngine* g_engine; static char g_gamerName[100]; -void SetEngine(CD3DEngine *engine) -{ - g_engine = engine; -} - -// Give the player's name. - void SetGlobalGamerName(char *name) { strcpy(g_gamerName, name); diff --git a/src/common/restext.h b/src/common/restext.h index 624803b9..0dba89a7 100644 --- a/src/common/restext.h +++ b/src/common/restext.h @@ -14,30 +14,32 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// restext.h +/** + * \file common/restext.h + * \brief Translation and string resource utilities + */ #pragma once +#include "common/global.h" #include "common/restext_ids.h" - -class CD3DEngine; - -// Possible types of the text resources. - +/** + * \enum ResType + * \brief Types of text resources + */ enum ResType { - RES_TEXT = 0, // RT_* - RES_EVENT = 1, // EVENT_* (EventMsg) - RES_OBJECT = 2, // OBJECT_* (ObjectType) - RES_ERR = 3, // ERR_* (Error) - RES_KEY = 4, // VK_* (keys) - RES_CBOT = 5, // TX_* (cbot.dll) + RES_TEXT = 0, //! < RT_* + RES_EVENT = 1, //! < EVENT_* (EventMsg) + RES_OBJECT = 2, //! < OBJECT_* (ObjectType) + RES_ERR = 3, //! < ERR_* (Error) + RES_KEY = 4, //! < KEY() (keys) + RES_CBOT = 5, //! < TX_* (CBot) }; -extern void SetEngine(CD3DEngine *engine); extern void SetGlobalGamerName(char *name); extern bool SearchKey(char *cmd, KeyRank &key); extern bool GetResource(ResType type, int num, char* text); diff --git a/src/common/restext_ids.h b/src/common/restext_ids.h index bee86207..4223a1ce 100644 --- a/src/common/restext_ids.h +++ b/src/common/restext_ids.h @@ -14,6 +14,9 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. + +// TODO: move to restext.h after restext rewrite + #pragma once enum ResTextType diff --git a/src/common/singleton.h b/src/common/singleton.h index f631ed41..74075044 100644 --- a/src/common/singleton.h +++ b/src/common/singleton.h @@ -14,7 +14,10 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// singleton.h +/** + * \file common/singleton.h + * \brief CSingleton base class for singletons + */ #pragma once diff --git a/src/common/stringutils.h b/src/common/stringutils.h index a0cae704..064351d3 100644 --- a/src/common/stringutils.h +++ b/src/common/stringutils.h @@ -14,7 +14,10 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// stringutils.h +/** + * \file common/stringutils.h + * \brief Some useful string operations + */ #pragma once diff --git a/src/common/struct.h b/src/common/struct.h deleted file mode 100644 index 45ac3147..00000000 --- a/src/common/struct.h +++ /dev/null @@ -1,54 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * -// * 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/. - -// struct.h - -#pragma once - - -#include - - -#define D3DFVF_VERTEX2 (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX2) - -struct D3DVERTEX2 -{ - float x,y,z; - float nx,ny,nz; - float tu, tv; - float tu2, tv2; - - D3DVERTEX2() { } - D3DVERTEX2(const Math::Vector& _v, const Math::Vector& _n, float _tu=0.0f, float _tv=0.0f, float _tu2=0.0f, float _tv2=0.0f) - { - x = _v.x; - y = _v.y; - z = _v.z; - nx = _n.x; - ny = _n.y; - nz = _n.z; - tu = _tu; - tv = _tv; - tu2 = _tu2; - tv2 = _tv2; - } -}; - - -struct ColorHSV -{ - float h,s,v; -}; \ No newline at end of file diff --git a/src/graphics/engine/lightning.h b/src/graphics/engine/lightning.h index e34eb3b9..af389f20 100644 --- a/src/graphics/engine/lightning.h +++ b/src/graphics/engine/lightning.h @@ -22,7 +22,7 @@ #pragma once -#include "common/misc.h" +#include "common/event.h" #include "math/vector.h" diff --git a/src/graphics/engine/pyro.h b/src/graphics/engine/pyro.h index 5d2ca639..c0c01449 100644 --- a/src/graphics/engine/pyro.h +++ b/src/graphics/engine/pyro.h @@ -22,7 +22,8 @@ #pragma once -#include "common/misc.h" +#include "common/event.h" +#include "common/global.h" #include "graphics/engine/engine.h" #include "object/object.h" diff --git a/src/physics/physics.h b/src/physics/physics.h index 2e1f5eb8..17cfd446 100644 --- a/src/physics/physics.h +++ b/src/physics/physics.h @@ -19,7 +19,7 @@ #pragma once -#include "common/misc.h" +#include "common/global.h" #include "object/object.h" #include "math/vector.h"