From 40e065aea947b45700930d431754282c23d1de45 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sat, 20 Oct 2012 16:34:22 +0200 Subject: Ground spot texture drawing --- src/common/image.cpp | 9 +++++++++ src/common/image.h | 3 +++ 2 files changed, 12 insertions(+) (limited to 'src/common') diff --git a/src/common/image.cpp b/src/common/image.cpp index f3cfa34..638304e 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -190,6 +190,15 @@ Math::IntPoint CImage::GetSize() const return Math::IntPoint(m_data->surface->w, m_data->surface->h); } +/** Image must be valid. */ +void CImage::Fill(Gfx::IntColor color) +{ + assert(m_data != nullptr); + + Uint32 c = SDL_MapRGBA(m_data->surface->format, color.r, color.g, color.b, color.a); + SDL_FillRect(m_data->surface, nullptr, c); +} + /** * Image must be valid and pixel coords in valid range. * diff --git a/src/common/image.h b/src/common/image.h index d23a6fa..d9da75b 100644 --- a/src/common/image.h +++ b/src/common/image.h @@ -79,6 +79,9 @@ public: //! Returns the image size Math::IntPoint GetSize() const; + //! Fills the whole image with given color + void Fill(Gfx::IntColor color); + //! Sets the color at given pixel void SetPixel(Math::IntPoint pixel, Gfx::Color color); -- cgit v1.2.3-1-g7c22 From e62996858b2ce2be322eae55f86b4b0ad7172a08 Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Thu, 27 Dec 2012 17:10:45 +0100 Subject: Create a central version Make it 0.1.0~pre-alpha for now. - Add it to runtime program - Add it to -help option - Add it to manpage - Update translations --- src/common/config.h.cmake | 4 ++++ src/common/restext.cpp | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'src/common') diff --git a/src/common/config.h.cmake b/src/common/config.h.cmake index dd280a3..022bb69 100644 --- a/src/common/config.h.cmake +++ b/src/common/config.h.cmake @@ -8,6 +8,10 @@ #cmakedefine USE_GLEW @USE_GLEW@ #cmakedefine GLEW_STATIC +#define COLOBOT_VERSION "@COLOBOT_VERSION_FULL@" +#define COLOBOT_CODENAME "@COLOBOT_VERSION_CODENAME@" +#define COLOBOT_FULLNAME "Colobot @COLOBOT_VERSION_CODENAME@" + #define COLOBOT_DEFAULT_DATADIR "@COLOBOT_INSTALL_DATA_DIR@" #define COLOBOT_I18N_DIR "@COLOBOT_INSTALL_I18N_DIR@" diff --git a/src/common/restext.cpp b/src/common/restext.cpp index da06131..4c56ae5 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -17,6 +17,8 @@ #include "common/restext.h" +#include "common/config.h" + #include "common/global.h" #include "common/event.h" #include "common/logger.h" @@ -39,7 +41,7 @@ const char* stringsCbot[TX_MAX] = { nullptr }; void InitializeRestext() { - stringsText[RT_VERSION_ID] = "Colobot Gold"; + stringsText[RT_VERSION_ID] = COLOBOT_FULLNAME; stringsText[RT_DISINFO_TITLE] = "SatCom"; stringsText[RT_WINDOW_MAXIMIZED] = "Maximize"; -- cgit v1.2.3-1-g7c22 From 3e4c1a1ad88456ebf201b257b91847bd995c8773 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Fri, 28 Dec 2012 13:37:08 +0100 Subject: Replaced malloc/free with new/delete - now new/delete used everywhere except for CBotStack, which has to be fixed in other way - some segfaults should be fixed with this --- src/common/image.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/common') diff --git a/src/common/image.cpp b/src/common/image.cpp index f3cfa34..ef8097e 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -124,14 +124,14 @@ bool PNGSaveSurface(const char *filename, SDL_Surface *surf) png_write_info(png_ptr, info_ptr); png_set_packing(png_ptr); - row_pointers = static_cast( malloc(sizeof(png_bytep)*surf->h) ); + row_pointers = new png_bytep[surf->h]; for (i = 0; i < surf->h; i++) row_pointers[i] = static_cast( static_cast(surf->pixels) ) + i*surf->pitch; png_write_image(png_ptr, row_pointers); png_write_end(png_ptr, info_ptr); /* Cleaning out... */ - free(row_pointers); + delete[] row_pointers; png_destroy_write_struct(&png_ptr, &info_ptr); fclose(fp); -- cgit v1.2.3-1-g7c22 From 8818a8e5db86f140230d789427373e1771747f5d Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sat, 5 Jan 2013 23:03:06 +0100 Subject: Corrected OpenGL extension detection - corrected multitexture and VBO detection - GLEW is now a required library - minor CMakeLists refactoring --- src/common/config.h.cmake | 1 - 1 file changed, 1 deletion(-) (limited to 'src/common') diff --git a/src/common/config.h.cmake b/src/common/config.h.cmake index 022bb69..1595e09 100644 --- a/src/common/config.h.cmake +++ b/src/common/config.h.cmake @@ -5,7 +5,6 @@ #cmakedefine PLATFORM_LINUX @PLATFORM_LINUX@ #cmakedefine PLATFORM_OTHER @PLATFORM_OTHER@ -#cmakedefine USE_GLEW @USE_GLEW@ #cmakedefine GLEW_STATIC #define COLOBOT_VERSION "@COLOBOT_VERSION_FULL@" -- cgit v1.2.3-1-g7c22 From ff5c89085415a370911793d5764dfb694fc43b7d Mon Sep 17 00:00:00 2001 From: Marcin Zawadzki Date: Sat, 5 Jan 2013 23:03:26 +0100 Subject: Small fix in detecting language. Fixes needed to compile code using clang --- src/common/test/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) (limited to 'src/common') diff --git a/src/common/test/CMakeLists.txt b/src/common/test/CMakeLists.txt index 26a31c9..70dac1f 100644 --- a/src/common/test/CMakeLists.txt +++ b/src/common/test/CMakeLists.txt @@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 2.8) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE debug) endif(NOT CMAKE_BUILD_TYPE) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wold-style-cast -std=gnu++0x") set(CMAKE_CXX_FLAGS_DEBUG "-g -O0") include_directories( -- cgit v1.2.3-1-g7c22 From b50f9ae8b7efe9ae4b198a4f1072a384919c6c08 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Thu, 17 Jan 2013 20:54:35 +0100 Subject: Fixed some clang warnings --- src/common/test/image_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/common') diff --git a/src/common/test/image_test.cpp b/src/common/test/image_test.cpp index a98c9cc..09ae4c6 100644 --- a/src/common/test/image_test.cpp +++ b/src/common/test/image_test.cpp @@ -19,7 +19,7 @@ int main(int argc, char *argv[]) if (! image.Load(argv[1])) { std::string err = image.GetError(); - printf("Error loading '%s': %s\n", err.c_str()); + printf("Error loading '%s': %s\n", argv[1], err.c_str()); return 1; } Gfx::Color color; @@ -49,7 +49,7 @@ int main(int argc, char *argv[]) if (! image.SavePNG(argv[2])) { std::string err = image.GetError(); - printf("Error saving PNG '%s': %s\n", err.c_str()); + printf("Error saving PNG '%s': %s\n", argv[2], err.c_str()); return 2; } -- cgit v1.2.3-1-g7c22 From 209c6412ae149cc7c503fd7da384f344a830423c Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 3 Feb 2013 20:03:36 +0100 Subject: Refactoring in tests infrastructure * all tests are now in /test/ subdirectory * unit tests concatenated to one executable (TODO: ui, common) * preparation for test environments (OpenGL and others) * removed old TestCBot --- src/common/test/CMakeLists.txt | 22 ---------------- src/common/test/colobot.ini | 15 ----------- src/common/test/image_test.cpp | 57 ---------------------------------------- src/common/test/profile_test.cpp | 44 ------------------------------- 4 files changed, 138 deletions(-) delete mode 100644 src/common/test/CMakeLists.txt delete mode 100644 src/common/test/colobot.ini delete mode 100644 src/common/test/image_test.cpp delete mode 100644 src/common/test/profile_test.cpp (limited to 'src/common') diff --git a/src/common/test/CMakeLists.txt b/src/common/test/CMakeLists.txt deleted file mode 100644 index 70dac1f..0000000 --- a/src/common/test/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -cmake_minimum_required(VERSION 2.8) - -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE debug) -endif(NOT CMAKE_BUILD_TYPE) -set(CMAKE_CXX_FLAGS_DEBUG "-g -O0") - -include_directories( -. -../.. -../../.. -${GTEST_INCLUDE_DIR} -) - - -add_executable(image_test ../image.cpp image_test.cpp) -target_link_libraries(image_test ${SDL_LIBRARY} ${SDLIMAGE_LIBRARY} ${PNG_LIBRARIES}) - -#add_executable(profile_test ../profile.cpp ../logger.cpp profile_test.cpp) -#target_link_libraries(profile_test gtest ${Boost_LIBRARIES}) - -#add_test(profile_test ./profile_test) diff --git a/src/common/test/colobot.ini b/src/common/test/colobot.ini deleted file mode 100644 index 2ca37ee..0000000 --- a/src/common/test/colobot.ini +++ /dev/null @@ -1,15 +0,0 @@ -[test_float] -float_value=1.5 - -[test_string] -string_value=Hello world - -[test_int] -int_value=42 - -[test_multi] -entry1=1 -entry2=2 -entry3=3 -entry4=4 -entry5=5 diff --git a/src/common/test/image_test.cpp b/src/common/test/image_test.cpp deleted file mode 100644 index 09ae4c6..0000000 --- a/src/common/test/image_test.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include "../image.h" - -#include -#include - -/* For now, just a simple test: loading a file from image - * and saving it to another in PNG. */ - -int main(int argc, char *argv[]) -{ - if (argc != 3) - { - printf("Usage: %s in_image out_image\n", argv[0]); - return 0; - } - - CImage image; - - if (! image.Load(argv[1])) - { - std::string err = image.GetError(); - printf("Error loading '%s': %s\n", argv[1], err.c_str()); - return 1; - } - Gfx::Color color; - std::string str; - - color = image.GetPixel(Math::IntPoint(0, 0)); - str = color.ToString(); - printf("pixel @ (0,0): %s\n", str.c_str()); - - color = image.GetPixel(Math::IntPoint(0, 1)); - str = color.ToString(); - printf("pixel @ (0,1): %s\n", str.c_str()); - - color = image.GetPixel(Math::IntPoint(1, 0)); - str = color.ToString(); - printf("pixel @ (1,0): %s\n", str.c_str()); - - color = image.GetPixel(Math::IntPoint(1, 1)); - str = color.ToString(); - printf("pixel @ (1,1): %s\n", str.c_str()); - - image.SetPixel(Math::IntPoint(0, 0), Gfx::Color(0.1f, 0.2f, 0.3f, 0.0f)); - image.SetPixel(Math::IntPoint(1, 0), Gfx::Color(0.3f, 0.2f, 0.1f, 1.0f)); - image.SetPixel(Math::IntPoint(0, 1), Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f)); - image.SetPixel(Math::IntPoint(1, 1), Gfx::Color(0.0f, 0.0f, 0.0f, 1.0f)); - - if (! image.SavePNG(argv[2])) - { - std::string err = image.GetError(); - printf("Error saving PNG '%s': %s\n", argv[2], err.c_str()); - return 2; - } - - return 0; -} diff --git a/src/common/test/profile_test.cpp b/src/common/test/profile_test.cpp deleted file mode 100644 index 6236083..0000000 --- a/src/common/test/profile_test.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "../profile.h" -#include "../logger.h" - -#include -#include -#include -#include - - -class CProfileTest : public testing::Test -{ -protected: - CLogger m_logger; - CProfile m_profile; - -}; - -TEST_F(CProfileTest, ReadTest) -{ - ASSERT_TRUE(m_profile.InitCurrentDirectory()); // load colobot.ini file - - std::string result; - ASSERT_TRUE(m_profile.GetLocalProfileString("test_string", "string_value", result)); - ASSERT_STREQ("Hello world", result.c_str()); - - int int_value; - ASSERT_TRUE(m_profile.GetLocalProfileInt("test_int", "int_value", int_value)); - ASSERT_EQ(42, int_value); - - float float_value; - ASSERT_TRUE(m_profile.GetLocalProfileFloat("test_float", "float_value", float_value)); - ASSERT_FLOAT_EQ(1.5, float_value); - - std::vector list; - list = m_profile.GetLocalProfileSection("test_multi", "entry"); - ASSERT_EQ(5u, list.size()); -} - -int main(int argc, char *argv[]) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} - -- cgit v1.2.3-1-g7c22 From 8658d6da8060cdb741c668d4be1b571ef064d01d Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 13 Feb 2013 16:57:59 +0100 Subject: Added Destroyer from Ceebot-Teen. We need a new icon for it. --- src/common/event.h | 3 ++- src/common/global.h | 1 + src/common/restext.cpp | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) (limited to 'src/common') diff --git a/src/common/event.h b/src/common/event.h index 169f0d0..cba167e 100644 --- a/src/common/event.h +++ b/src/common/event.h @@ -411,7 +411,8 @@ enum EventType EVENT_OBJECT_BNUCLEAR = 1060, EVENT_OBJECT_BPARA = 1061, EVENT_OBJECT_BINFO = 1062, - EVENT_OBJECT_BXXXX = 1063, + EVENT_OBJECT_BDESTROYER = 1063, + //EVENT_OBJECT_BXXXX = 1063, EVENT_OBJECT_GFLAT = 1070, EVENT_OBJECT_FCREATE = 1071, EVENT_OBJECT_FDELETE = 1072, diff --git a/src/common/global.h b/src/common/global.h index 0b2d8ec..7a5fdfd 100644 --- a/src/common/global.h +++ b/src/common/global.h @@ -213,6 +213,7 @@ enum BuildType BUILD_LABO = (1<<10), //! < laboratory BUILD_PARA = (1<<11), //! < lightning protection BUILD_INFO = (1<<12), //! < information terminal + BUILD_DESTROYER = (1<<13), //! < Destroyer BUILD_GFLAT = (1<<16), //! < flat floor BUILD_FLAG = (1<<17) //! < puts / removes colored flag }; diff --git a/src/common/restext.cpp b/src/common/restext.cpp index 4c56ae5..4768aed 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -308,6 +308,7 @@ void InitializeRestext() stringsEvent[EVENT_OBJECT_BNUCLEAR] = "Build a nuclear power plant"; stringsEvent[EVENT_OBJECT_BPARA] = "Build a lightning conductor"; stringsEvent[EVENT_OBJECT_BINFO] = "Build a exchange post"; + stringsEvent[EVENT_OBJECT_BDESTROYER] = "Build a destroyer"; stringsEvent[EVENT_OBJECT_GFLAT] = "Show if the ground is flat"; stringsEvent[EVENT_OBJECT_FCREATE] = "Plant a flag"; stringsEvent[EVENT_OBJECT_FDELETE] = "Remove a flag"; -- cgit v1.2.3-1-g7c22 From 001d37b257b126dd6ef1dced70f94ff3d2806d28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Dziwi=C5=84ski?= Date: Sat, 16 Feb 2013 22:37:43 +0100 Subject: CInstanceManager refactoring * removed classes managed by CInstanceManager except for CObject, CPyro, CBrain and CPhysics because of dependencies * refactored instance searching to use existing singleton instances of CApplication, CEngine and CRobotMain and calling their getter functions --- src/common/event.cpp | 7 ++--- src/common/event.h | 5 +--- src/common/iman.cpp | 15 +--------- src/common/iman.h | 67 +++++++------------------------------------ src/common/logger.cpp | 2 +- src/common/profile.cpp | 2 +- src/common/singleton.h | 77 ++++++++++++++++++++++++++++++-------------------- 7 files changed, 63 insertions(+), 112 deletions(-) (limited to 'src/common') diff --git a/src/common/event.cpp b/src/common/event.cpp index b078dc5..ff3fbc7 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -17,12 +17,12 @@ #include "common/event.h" -#include "common/iman.h" #include "common/logger.h" static EventType g_uniqueEventType = EVENT_USER; + EventType GetUniqueEventType() { int i = static_cast(g_uniqueEventType+1); @@ -32,11 +32,8 @@ EventType GetUniqueEventType() -CEventQueue::CEventQueue(CInstanceManager* iMan) +CEventQueue::CEventQueue() { - m_iMan = iMan; - m_iMan->AddInstance(CLASS_EVENT, this); - Flush(); } diff --git a/src/common/event.h b/src/common/event.h index cba167e..ad493e7 100644 --- a/src/common/event.h +++ b/src/common/event.h @@ -27,8 +27,6 @@ #include "math/point.h" #include "math/vector.h" -class CInstanceManager; - /** \enum EventType @@ -762,7 +760,7 @@ public: public: //! Object's constructor - CEventQueue(CInstanceManager* iMan); + CEventQueue(); //! Object's destructor ~CEventQueue(); @@ -774,7 +772,6 @@ public: bool GetEvent(Event &event); protected: - CInstanceManager* m_iMan; Event m_fifo[MAX_EVENT_QUEUE]; int m_head; int m_tail; diff --git a/src/common/iman.cpp b/src/common/iman.cpp index 6a0a9eb..e1400fd 100644 --- a/src/common/iman.cpp +++ b/src/common/iman.cpp @@ -20,22 +20,9 @@ #include -template<> CInstanceManager* CSingleton::mInstance = nullptr; +template<> CInstanceManager* CSingleton::m_instance = nullptr; -CInstanceManager& CInstanceManager::GetInstance() -{ - assert(mInstance); - return *mInstance; -} - - -CInstanceManager* CInstanceManager::GetInstancePointer() -{ - assert(mInstance); - return mInstance; -} - CInstanceManager::CInstanceManager() { for (int i = 0; i < CLASS_MAX; i++) diff --git a/src/common/iman.h b/src/common/iman.h index 53caed7..faabd0c 100644 --- a/src/common/iman.h +++ b/src/common/iman.h @@ -30,67 +30,23 @@ * \brief Type of class managed by CInstanceManager */ -// TODO: remove unnecessary, refactor to singletons, move to CRobotMain, keep others? - +/* + * TODO: Non-unique classes have already been removed. + * The other class instances along with CInstanceManager will be removed in due course. + */ enum ManagedClassType { - //! 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, + CLASS_OBJECT = 0, //! CPhysics - CLASS_PHYSICS = 7, + CLASS_PHYSICS = 1, //! 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, + CLASS_BRAIN = 2, //! 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, + CLASS_PYRO = 3, //! Maximum (number of managed classes) - CLASS_MAX = 30 + CLASS_MAX = 4 }; @@ -116,7 +72,7 @@ class CInstanceManager : public CSingleton { public: CInstanceManager(); - ~CInstanceManager(); + virtual ~CInstanceManager(); //! Remove all managed instances void Flush(); @@ -129,9 +85,6 @@ public: //! Seeks a class instance of given type void* SearchInstance(ManagedClassType classType, int rank=0); - static CInstanceManager& GetInstance(); - static CInstanceManager* GetInstancePointer(); - protected: //! Fills holes in instance table void Compress(ManagedClassType classType); diff --git a/src/common/logger.cpp b/src/common/logger.cpp index 5a78433..3ec9746 100644 --- a/src/common/logger.cpp +++ b/src/common/logger.cpp @@ -20,7 +20,7 @@ #include -template<> CLogger* CSingleton::mInstance = nullptr; +template<> CLogger* CSingleton::m_instance = nullptr; CLogger::CLogger() diff --git a/src/common/profile.cpp b/src/common/profile.cpp index 5432489..18cc187 100644 --- a/src/common/profile.cpp +++ b/src/common/profile.cpp @@ -25,7 +25,7 @@ #include -template<> CProfile* CSingleton::mInstance = nullptr; +template<> CProfile* CSingleton::m_instance = nullptr; namespace bp = boost::property_tree; diff --git a/src/common/singleton.h b/src/common/singleton.h index c1b28d9..25e1648 100644 --- a/src/common/singleton.h +++ b/src/common/singleton.h @@ -26,34 +26,51 @@ template class CSingleton { - protected: - static T* mInstance; - - public: - static T& GetInstance() { - assert(mInstance != nullptr); - return *mInstance; - } - - static T* GetInstancePointer() { - assert(mInstance != nullptr); - return mInstance; - } - - static bool IsCreated() { - return mInstance != nullptr; - } - - CSingleton() { - assert(mInstance == nullptr); - mInstance = static_cast(this); - } - - virtual ~CSingleton() { - mInstance = nullptr; - } - - private: - CSingleton& operator=(const CSingleton &); - CSingleton(const CSingleton &); +protected: + static T* m_instance; + +public: + static T& GetInstance() + { + assert(m_instance != nullptr); + return *m_instance; + } + + static T* GetInstancePointer() + { + assert(m_instance != nullptr); + return m_instance; + } + + static bool IsCreated() + { + return m_instance != nullptr; + } + + CSingleton() + { + assert(m_instance == nullptr); + m_instance = static_cast(this); + } + + virtual ~CSingleton() + { + m_instance = nullptr; + } + + #ifdef TESTS + static void ReplaceInstance(T* newInstance) + { + assert(newInstance != nullptr); + + if (m_instance != nullptr) + delete m_instance; + + m_instance = newInstance; + } + #endif + +private: + CSingleton& operator=(const CSingleton &); + CSingleton(const CSingleton &); }; -- cgit v1.2.3-1-g7c22 From bc859c4c597f106d40f07380bf255f180d565577 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 10 Mar 2013 15:44:21 +0100 Subject: VBO override option; argv parsing using getopt * added -vbo option to override autodetection of OpenGL VBO extension * refactored argument parsing to use getopt() * fixed failing UTs --- src/common/logger.cpp | 82 +++++++++++++++++++++++++------ src/common/logger.h | 131 +++++++++++++++++++++++++++----------------------- 2 files changed, 137 insertions(+), 76 deletions(-) (limited to 'src/common') diff --git a/src/common/logger.cpp b/src/common/logger.cpp index 3ec9746..8bc4cef 100644 --- a/src/common/logger.cpp +++ b/src/common/logger.cpp @@ -36,25 +36,37 @@ CLogger::~CLogger() } -void CLogger::Log(LogType type, const char *str, va_list args) +void CLogger::Log(LogLevel type, const char* str, va_list args) { if (type < mLogLevel) return; - switch (type) { - case LOG_TRACE: fprintf(IsOpened() ? mFile : stderr, "[TRACE]: "); break; - case LOG_DEBUG: fprintf(IsOpened() ? mFile : stderr, "[DEBUG]: "); break; - case LOG_WARN: fprintf(IsOpened() ? mFile : stderr, "[WARN]: "); break; - case LOG_INFO: fprintf(IsOpened() ? mFile : stderr, "[INFO]: "); break; - case LOG_ERROR: fprintf(IsOpened() ? mFile : stderr, "[ERROR]: "); break; - default: break; + switch (type) + { + case LOG_TRACE: + fprintf(IsOpened() ? mFile : stderr, "[TRACE]: "); + break; + case LOG_DEBUG: + fprintf(IsOpened() ? mFile : stderr, "[DEBUG]: "); + break; + case LOG_WARN: + fprintf(IsOpened() ? mFile : stderr, "[WARN]: "); + break; + case LOG_INFO: + fprintf(IsOpened() ? mFile : stderr, "[INFO]: "); + break; + case LOG_ERROR: + fprintf(IsOpened() ? mFile : stderr, "[ERROR]: "); + break; + default: + break; } vfprintf(IsOpened() ? mFile : stderr, str, args); } -void CLogger::Trace(const char *str, ...) +void CLogger::Trace(const char* str, ...) { va_list args; va_start(args, str); @@ -63,7 +75,7 @@ void CLogger::Trace(const char *str, ...) } -void CLogger::Debug(const char *str, ...) +void CLogger::Debug(const char* str, ...) { va_list args; va_start(args, str); @@ -72,7 +84,7 @@ void CLogger::Debug(const char *str, ...) } -void CLogger::Info(const char *str, ...) +void CLogger::Info(const char* str, ...) { va_list args; va_start(args, str); @@ -81,7 +93,7 @@ void CLogger::Info(const char *str, ...) } -void CLogger::Warn(const char *str, ...) +void CLogger::Warn(const char* str, ...) { va_list args; va_start(args, str); @@ -90,7 +102,7 @@ void CLogger::Warn(const char *str, ...) } -void CLogger::Error(const char *str, ...) +void CLogger::Error(const char* str, ...) { va_list args; va_start(args, str); @@ -99,7 +111,7 @@ void CLogger::Error(const char *str, ...) } -void CLogger::Message(const char *str, ...) +void CLogger::Message(const char* str, ...) { va_list args; va_start(args, str); @@ -118,6 +130,7 @@ void CLogger::SetOutputFile(std::string filename) void CLogger::Open() { mFile = fopen(mFilename.c_str(), "w"); + if (mFile == NULL) fprintf(stderr, "Could not create file %s\n", mFilename.c_str()); } @@ -136,6 +149,45 @@ bool CLogger::IsOpened() } -void CLogger::SetLogLevel(LogType type) { +void CLogger::SetLogLevel(LogLevel type) +{ mLogLevel = type; } + + +bool CLogger::ParseLogLevel(const std::string& str, LogLevel& logLevel) +{ + if (str == "trace") + { + logLevel = LOG_TRACE; + return true; + } + else if (str == "debug") + { + logLevel = LOG_DEBUG; + return true; + } + else if (str == "info") + { + logLevel = LOG_INFO; + return true; + } + else if (str == "warn") + { + logLevel = LOG_WARN; + return true; + } + else if (str == "error") + { + logLevel = LOG_ERROR; + return true; + } + else if (str == "none") + { + logLevel = LOG_NONE; + return true; + } + + return false; +} + diff --git a/src/common/logger.h b/src/common/logger.h index 198e5e5..769f548 100644 --- a/src/common/logger.h +++ b/src/common/logger.h @@ -31,10 +31,10 @@ /** * \public - * \enum LogType common/logger.h + * \enum LogLevel common/logger.h * \brief Enum representing log level **/ -enum LogType +enum LogLevel { LOG_TRACE = 1, /*!< lowest level, execution tracing */ LOG_DEBUG = 2, /*!< debugging messages */ @@ -53,65 +53,74 @@ enum LogType */ class CLogger : public CSingleton { - public: - CLogger(); - ~CLogger(); - - /** Write message to console or file - * \param str - message to write - * \param ... - additional arguments - */ - void Message(const char *str, ...); - - /** Write message to console or file with LOG_TRACE level - * \param str - message to write - * \param ... - additional arguments - */ - void Trace(const char *str, ...); - - /** Write message to console or file with LOG_DEBUG level - * \param str - message to write - * \param ... - additional arguments - */ - void Debug(const char *str, ...); - - /** Write message to console or file with LOG_INFO level - * \param str - message to write - * \param ... - additional arguments - */ - void Info(const char *str, ...); - - /** Write message to console or file with LOG_WARN level - * \param str - message to write - * \param ... - additional arguments - */ - void Warn(const char *str, ...); - - /** Write message to console or file with LOG_ERROR level - * \param str - message to write - * \param ... - additional arguments - */ - void Error(const char *str, ...); - - /** Set output file to write logs to - * \param filename - output file to write to - */ - void SetOutputFile(std::string filename); - - /** Set log level. Logs with level below will not be shown - * \param level - minimum log level to write - */ - void SetLogLevel(LogType level); - - private: - std::string mFilename; - FILE *mFile; - LogType mLogLevel; - - void Open(); - void Close(); - bool IsOpened(); - void Log(LogType type, const char* str, va_list args); +public: + CLogger(); + ~CLogger(); + + /** Write message to console or file + * \param str - message to write + * \param ... - additional arguments + */ + void Message(const char *str, ...); + + /** Write message to console or file with LOG_TRACE level + * \param str - message to write + * \param ... - additional arguments + */ + void Trace(const char *str, ...); + + /** Write message to console or file with LOG_DEBUG level + * \param str - message to write + * \param ... - additional arguments + */ + void Debug(const char *str, ...); + + /** Write message to console or file with LOG_INFO level + * \param str - message to write + * \param ... - additional arguments + */ + void Info(const char *str, ...); + + /** Write message to console or file with LOG_WARN level + * \param str - message to write + * \param ... - additional arguments + */ + void Warn(const char *str, ...); + + /** Write message to console or file with LOG_ERROR level + * \param str - message to write + * \param ... - additional arguments + */ + void Error(const char *str, ...); + + /** Set output file to write logs to + * \param filename - output file to write to + */ + void SetOutputFile(std::string filename); + + /** Set log level. Logs with level below will not be shown + * \param level - minimum log level to write + */ + void SetLogLevel(LogLevel level); + + /** Parses string as a log level + * \param str string to parse + * \param logLevel result log level + * + * Valid values are "trace", "debug", "info", "warn", "error" and "none". + * On invalid value, returns \c false. + */ + static bool ParseLogLevel(const std::string& str, LogLevel& logLevel); + +private: + std::string mFilename; + FILE *mFile; + LogLevel mLogLevel; + + void Open(); + void Close(); + bool IsOpened(); + void Log(LogLevel type, const char* str, va_list args); }; -- cgit v1.2.3-1-g7c22 From d6bbc99c90ef586b041651d373524b30fe6c8676 Mon Sep 17 00:00:00 2001 From: erihel Date: Sun, 17 Mar 2013 19:01:32 +0100 Subject: * Changed file loading to fix issue #73 * Moved few functions from misc.cpp to profile.cpp (used to set/get user dir) * Removed some warnings * More work to change const char* to std::string * Some work on file path to fix issue #60 with bad slashes on POSIX platform --- src/common/misc.cpp | 124 ++----------------------------------------------- src/common/misc.h | 3 -- src/common/profile.cpp | 45 ++++++++++++++++++ src/common/profile.h | 28 ++++++++++- 4 files changed, 75 insertions(+), 125 deletions(-) (limited to 'src/common') diff --git a/src/common/misc.cpp b/src/common/misc.cpp index 2bce3b8..b96abca 100644 --- a/src/common/misc.cpp +++ b/src/common/misc.cpp @@ -25,10 +25,6 @@ #include -static bool g_bUserDir = false; -static char g_userDir[100] = ""; - - // Returns a non-accented letter. char GetNoAccent(char letter) @@ -234,72 +230,11 @@ void TimeToAscii(time_t time, char *buffer) #endif*/ } - -// Makes a copy of a file. - -bool Xfer(char* src, char* dst) -{ - FILE *fs, *fd; - char *buffer; - int len; - - fs = fopen(src, "rb"); - if ( fs == 0 ) - { - return false; - } - - fd = fopen(dst, "wb"); - if ( fd == 0 ) - { - fclose(fs); - return false; - } - - buffer = static_cast(malloc(10000)); - - while ( true ) - { - len = fread(buffer, 1, 10000, fs); - if ( len == 0 ) break; - fwrite(buffer, 1, len, fd); - } - - free(buffer); - fclose(fs); - fclose(fd); - return true; -} - -// Copy a file into the temporary folder. - -bool CopyFileToTemp(char* filename) -{ - char src[100]; - char dst[100]; - char save[100]; - - UserDir(src, filename, "textures"); - - strcpy(save, g_userDir); - strcpy(g_userDir, "temp"); - UserDir(dst, filename, "textures"); - strcpy(g_userDir, save); - - //_mkdir("temp"); - system("mkdir temp"); - - if ( !Xfer(src, dst) ) return false; - - strcpy(filename, dst); - return true; -} - // Copy a list of numbered files into the temporary folder. bool CopyFileListToTemp(char* filename, int* list, int total) { - char name[100]; + /*char name[100]; char ext[10]; char file[100]; char save[100]; @@ -329,8 +264,8 @@ bool CopyFileListToTemp(char* filename, int* list, int total) UserDir(file, filename, "textures"); strcpy(filename, file); strcpy(g_userDir, save); - - return true; +*/ + return false; } @@ -342,56 +277,3 @@ void AddExt(char* filename, const char* ext) strcat(filename, ext); } - -// Specifies the user folder. - -void UserDir(bool bUser, const char* dir) -{ - g_bUserDir = bUser; - strcpy(g_userDir, dir); -} - -// Replaces the string %user% by the user folder. -// in: dir = "%user%toto.txt" -// def = "abc\" -// out: buffer = "abc\toto.txt" - -void UserDir(char* buffer, const char* dir, const char* def) -{ - char ddir[100]; - const char* add; - - if ( strstr(dir, "\\") == 0 && def[0] != 0 ) - { - sprintf(ddir, "%s\\%s", def, dir); - } - else - { - strcpy(ddir, dir); - } - dir = ddir; - - while ( *dir != 0 ) - { - if ( dir[0] == '%' && - dir[1] == 'u' && - dir[2] == 's' && - dir[3] == 'e' && - dir[4] == 'r' && - dir[5] == '%' ) // %user% ? - { - if ( g_bUserDir ) add = g_userDir; - else add = def; - - while ( *add != 0 ) - { - *buffer++ = *add++; - } - dir += 6; // jumps to %user% - continue; - } - - *buffer++ = *dir++; - } - *buffer = 0; -} diff --git a/src/common/misc.h b/src/common/misc.h index f210706..e2ddc44 100644 --- a/src/common/misc.h +++ b/src/common/misc.h @@ -29,8 +29,5 @@ extern char GetToLower(char letter); extern void TimeToAscii(time_t time, char *buffer); -extern bool CopyFileToTemp(char* filename); extern bool CopyFileListToTemp(char* filename, int* list, int total); extern void AddExt(char* filename, const char* ext); -extern void UserDir(bool bUser, const char* dir); -extern void UserDir(char* buffer, const char* dir, const char* def); diff --git a/src/common/profile.cpp b/src/common/profile.cpp index 18cc187..2d11217 100644 --- a/src/common/profile.cpp +++ b/src/common/profile.cpp @@ -182,3 +182,48 @@ std::vector< std::string > CProfile::GetLocalProfileSection(std::string section, return ret_list; } + + +void CProfile::SetUserDir(std::string dir) +{ + m_userDirectory = dir; +} + + +std::string CProfile::GetUserBasedPath(std::string dir, std::string default_dir) +{ + std::string path = dir; + boost::replace_all(path, "\\", "/"); + if (dir.find("/") == std::string::npos) { + path = default_dir + "/" + dir; + } + + if (m_userDirectory.length() > 0) { + boost::replace_all(path, "%user%", m_userDirectory); + } else { + boost::replace_all(path, "%user%", default_dir); + } + + return fs::path(path).make_preferred().string(); +} + + +bool CProfile::CopyFileToTemp(std::string filename) +{ + std::string src, dst; + std::string tmp_user_dir = m_userDirectory; + + src = GetUserBasedPath(filename, "textures"); + SetUserDir("temp"); + dst = GetUserBasedPath(filename, "textures"); + SetUserDir(tmp_user_dir); + + fs::create_directory(fs::path(dst).parent_path().make_preferred().string()); + fs::copy_file(src, dst, fs::copy_option::overwrite_if_exists); + if (fs::exists(dst)) { + return true; + } + + return false; +} + diff --git a/src/common/profile.h b/src/common/profile.h index 9bc6c37..bcd76c3 100644 --- a/src/common/profile.h +++ b/src/common/profile.h @@ -21,14 +21,20 @@ #pragma once - #include "common/singleton.h" +// this is just to fix problem with undefined reference when compiling with c++11 support +#define BOOST_NO_SCOPED_ENUMS + #include +#include +#include #include #include +namespace fs = boost::filesystem; + /** * \class CProfile @@ -101,10 +107,30 @@ class CProfile : public CSingleton * \return vector of values */ std::vector< std::string > GetLocalProfileSection(std::string section, std::string key); + + /** Sets current user directory + * \param dir + */ + void SetUserDir(std::string dir); + + /** Returns path based on current user. Replaces %user% in path with current user dir or + * uses default_dir param if no user dir is specified + * \param dir + * \param default_dir + * \return path + */ + std::string GetUserBasedPath(std::string dir, std::string default_dir); + + /** opy a file into the temporary folder. + * \param filename + * \return true on success + */ + bool CopyFileToTemp(std::string filename); private: boost::property_tree::ptree m_propertyTree; bool m_profileNeedSave; + std::string m_userDirectory; }; //! Global function to get profile instance -- cgit v1.2.3-1-g7c22 From 4a30800cf16d403a7c25d78388e2822aa396ac86 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Fri, 22 Mar 2013 18:19:53 +0100 Subject: Fixes for compiling on MSYS * fixed SDL_main() and putenv() issues * disabled desktop subdir for MSYS * disabled building CBot_console for now --- src/common/config.h.cmake | 12 ++++++++++-- src/common/image.cpp | 4 ++-- src/common/key.h | 2 +- src/common/restext.cpp | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) (limited to 'src/common') diff --git a/src/common/config.h.cmake b/src/common/config.h.cmake index 1595e09..d5a03b4 100644 --- a/src/common/config.h.cmake +++ b/src/common/config.h.cmake @@ -7,11 +7,19 @@ #cmakedefine GLEW_STATIC +#cmakedefine OPENAL_SOUND + +#cmakedefine USE_SDL_MAIN @USE_SDL_MAIN@ + +#ifdef USE_SDL_MAIN +#define SDL_MAIN_FUNC SDL_main +#else +#define SDL_MAIN_FUNC main +#endif + #define COLOBOT_VERSION "@COLOBOT_VERSION_FULL@" #define COLOBOT_CODENAME "@COLOBOT_VERSION_CODENAME@" #define COLOBOT_FULLNAME "Colobot @COLOBOT_VERSION_CODENAME@" #define COLOBOT_DEFAULT_DATADIR "@COLOBOT_INSTALL_DATA_DIR@" #define COLOBOT_I18N_DIR "@COLOBOT_INSTALL_I18N_DIR@" - -#cmakedefine OPENAL_SOUND diff --git a/src/common/image.cpp b/src/common/image.cpp index be5711d..db14797 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -22,8 +22,8 @@ #include #include -#include -#include +#include +#include #include diff --git a/src/common/key.h b/src/common/key.h index 196f66d..84ee618 100644 --- a/src/common/key.h +++ b/src/common/key.h @@ -22,7 +22,7 @@ #pragma once -#include "SDL/SDL_keysym.h" +#include /* Key definitions are specially defined here so that it is clear in other parts of the code that these are used. It is to avoid having SDL-related enum values or #defines lying around diff --git a/src/common/restext.cpp b/src/common/restext.cpp index 4768aed..a6c33a3 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -30,7 +30,7 @@ #include "object/robotmain.h" #include -#include +#include const char* stringsText[RT_MAX] = { nullptr }; const char* stringsEvent[EVENT_STD_MAX] = { nullptr }; -- cgit v1.2.3-1-g7c22 From df5edc703c7241279116d2bbfe08351d0c3c2a4b Mon Sep 17 00:00:00 2001 From: krzys-h Date: Tue, 26 Mar 2013 15:33:54 +0100 Subject: Added interface button for AlienSpider explosion Issue #142 --- src/common/event.h | 1 + src/common/restext.cpp | 1 + 2 files changed, 2 insertions(+) (limited to 'src/common') diff --git a/src/common/event.h b/src/common/event.h index ad493e7..153b732 100644 --- a/src/common/event.h +++ b/src/common/event.h @@ -444,6 +444,7 @@ enum EventType EVENT_OBJECT_TERRAFORM = 1201, EVENT_OBJECT_FIRE = 1202, EVENT_OBJECT_FIREANT = 1203, + EVENT_OBJECT_SPIDEREXPLO= 1204, EVENT_OBJECT_RECOVER = 1220, EVENT_OBJECT_BEGSHIELD = 1221, EVENT_OBJECT_ENDSHIELD = 1222, diff --git a/src/common/restext.cpp b/src/common/restext.cpp index a6c33a3..729a883 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -352,6 +352,7 @@ void InitializeRestext() stringsEvent[EVENT_OBJECT_SEARCH] = "Sniff (\\key action;)"; stringsEvent[EVENT_OBJECT_TERRAFORM] = "Thump (\\key action;)"; stringsEvent[EVENT_OBJECT_FIRE] = "Shoot (\\key action;)"; + stringsEvent[EVENT_OBJECT_SPIDEREXPLO] = "Explode (\\key action;)"; stringsEvent[EVENT_OBJECT_RECOVER] = "Recycle (\\key action;)"; stringsEvent[EVENT_OBJECT_BEGSHIELD] = "Extend shield (\\key action;)"; stringsEvent[EVENT_OBJECT_ENDSHIELD] = "Withdraw shield (\\key action;)"; -- cgit v1.2.3-1-g7c22 From 991dbd1e37366b43b790740beb2fef755c56dcba Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Wed, 27 Mar 2013 10:20:06 +0100 Subject: Add profile and savegame fetchers in SystemUtils This breaks the tests compilation. :/ --- src/common/profile.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/common') diff --git a/src/common/profile.cpp b/src/common/profile.cpp index 2d11217..654648d 100644 --- a/src/common/profile.cpp +++ b/src/common/profile.cpp @@ -19,6 +19,8 @@ #include "common/logger.h" +#include "app/system.h" + #include #include #include @@ -41,7 +43,7 @@ CProfile::~CProfile() { try { - bp::ini_parser::write_ini("colobot.ini", m_propertyTree); + bp::ini_parser::write_ini(GetSystemUtils()->profileFileLocation(), m_propertyTree); } catch (std::exception & e) { @@ -55,7 +57,7 @@ bool CProfile::InitCurrentDirectory() { try { - bp::ini_parser::read_ini("colobot.ini", m_propertyTree); + bp::ini_parser::read_ini(GetSystemUtils()->profileFileLocation(), m_propertyTree); } catch (std::exception & e) { -- cgit v1.2.3-1-g7c22 From e93ed747c2cffdba2873e80f3b8c574c3d300875 Mon Sep 17 00:00:00 2001 From: erihel Date: Wed, 27 Mar 2013 15:13:51 +0100 Subject: * Another define to fix linker problems --- src/common/profile.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/common') diff --git a/src/common/profile.h b/src/common/profile.h index bcd76c3..ee7ac46 100644 --- a/src/common/profile.h +++ b/src/common/profile.h @@ -25,6 +25,7 @@ // this is just to fix problem with undefined reference when compiling with c++11 support #define BOOST_NO_SCOPED_ENUMS +#define BOOST_NO_CXX11_SCOPED_ENUMS #include #include -- cgit v1.2.3-1-g7c22 From 8301a3639be3ffbc6963206aa0634464d943229a Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Wed, 27 Mar 2013 20:53:28 +0100 Subject: Moved boost flags to CMakeLists --- src/common/profile.h | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/common') diff --git a/src/common/profile.h b/src/common/profile.h index ee7ac46..7f99d81 100644 --- a/src/common/profile.h +++ b/src/common/profile.h @@ -23,10 +23,6 @@ #include "common/singleton.h" -// this is just to fix problem with undefined reference when compiling with c++11 support -#define BOOST_NO_SCOPED_ENUMS -#define BOOST_NO_CXX11_SCOPED_ENUMS - #include #include #include -- cgit v1.2.3-1-g7c22