diff --git a/Makefile.base b/Makefile.base index 3297820d6..fd514becc 100644 --- a/Makefile.base +++ b/Makefile.base @@ -11,7 +11,7 @@ else endif endif -export VERSION = 0.8 +export VERSION = 0.9 export CP = cp export LN = ln export LNFLAGS = -s -f @@ -147,6 +147,7 @@ endif ifeq ($(BACKENDS_ALL),yes) BACKEND_SDL = yes + BACKEND_SDL2 = yes BACKEND_ALLEGRO = yes BACKEND_SFML = yes endif @@ -154,12 +155,19 @@ endif ifeq ($(BACKEND_SDL),) ifeq ($(BACKEND_ALLEGRO),) ifeq ($(BACKEND_SFML),) - BACKEND_SDL = yes + TRY_USE_SDL = yes endif endif endif -ifeq ($(BACKEND_SDL),yes) +SDL_BACKEND_LINK = +SDL_BACKEND_SRC = +SDL2_BACKEND_LINK = +SDL2_BACKEND_SRC = +SDL_DEFINE = + +# No backend selected? Select some SDL +ifeq ($(TRY_USE_SDL),yes) ifeq ($(BUILD_OS), ios) TRY_SDL2 = yes else @@ -181,25 +189,25 @@ ifeq ($(BACKEND_SDL),yes) SDLVERSION2 = $(shell type -P $(SDLCONFIGPATH)sdl2-config &>/dev/null && $(SDLCONFIGPATH)sdl2-config --version || echo "") ifeq ($(SDLVERSION2),) - # Then for SDL 1.2 or SDL 1.3 - SDLVERSION = $(shell type -P $(SDLCONFIGPATH)sdl-config &>/dev/null && $(SDLCONFIGPATH)sdl-config --version || echo "") + # Then for SDL 1.2 + SDLVERSION = $(shell type -P $(SDLCONFIGPATH)sdl-config &>/dev/null && $(SDLCONFIGPATH)sdl-config --version || echo "") ifeq ($(SDLVERSION),) # Default 2.0.0 SDL_VERSION = 2.0.0 else - SDL_VERSION = $(SDLVERSION) + SDL_VERSION = $(SDLVERSION) endif else SDL_VERSION = $(SDLVERSION2) endif else - # First check for SDL 1.2 or SDL 1.3 - SDLVERSION = $(shell type -P $(SDLCONFIGPATH)sdl-config &>/dev/null && $(SDLCONFIGPATH)sdl-config --version || echo "") + # First check for SDL 1.2 + SDLVERSION = $(shell type -P $(SDLCONFIGPATH)sdl-config &>/dev/null && $(SDLCONFIGPATH)sdl-config --version || echo "") ifeq ($(SDLVERSION),) # Then for SDL 2 - SDLVERSION2 = $(shell type -P $(SDLCONFIGPATH)sdl2-config &>/dev/null && $(SDLCONFIGPATH)sdl2-config --version || echo "") + SDLVERSION2 = $(shell type -P $(SDLCONFIGPATH)sdl2-config &>/dev/null && $(SDLCONFIGPATH)sdl2-config --version || echo "") ifeq ($(SDLVERSION2),) # Default 1.2 @@ -215,77 +223,83 @@ ifeq ($(BACKEND_SDL),yes) # If version is 1.2.x ifneq (,$(findstring 1.2,$(SDL_VERSION))) ifeq ($(BUILD_OS), darwin) - SDL_ADD_LINK = -framework Cocoa -lSDLmain - else - SDL_ADD_LINK = + SDL_ADD_LINK += -framework Cocoa -lSDLmain endif - SDL_BACKEND_LINK = -lSDL $(SDL_ADD_LINK) + SDL_BACKEND_LINK += -lSDL $(SDL_ADD_LINK) - SDL_BACKEND_SRC = $(wildcard ./src/eepp/window/backend/SDL/*.cpp) + SDL_BACKEND_SRC += $(wildcard ./src/eepp/window/backend/SDL/*.cpp) - EE_SDL_VERSION = -DEE_SDL_VERSION_1_2 + EE_SDL_VERSION += -DEE_SDL_VERSION_1_2 DYLIBS_BACKENDS += $(SDL_BACKEND_LINK) else ifeq ($(SHARED_BACKEND),) - #Check if static library exists - SDL_STATIC_FOUND = $(shell ls libs/$(BUILD_OS)/libSDL.a >/dev/null 2>&1 && echo "YES" || echo "NO") - SDL2_STATIC_FOUND = $(shell ls libs/$(BUILD_OS)/libSDL2.a >/dev/null 2>&1 && echo "YES" || echo "NO") - ifeq ($(SDL_STATIC_FOUND),NO) - ifeq ($(SDL2_STATIC_FOUND),NO) - SHARED_BACKEND = yes - endif + ifeq ($(SDL2_STATIC_FOUND),NO) + SHARED_BACKEND = yes endif endif # Compile as shared? ifeq ($(SHARED_BACKEND),yes) - ifneq (,$(findstring 1.3,$(SDL_VERSION))) + SDL2_BACKEND_LINK += -lSDL2 - ifeq ($(BUILD_OS), darwin) - SDL_ADD_LINK = -framework Cocoa -lSDLmain2 - else - SDL_ADD_LINK = - endif - - SDL_BACKEND_LINK = -lSDL $(SDL_ADD_LINK) + EE_SDL_VERSION += -DEE_SDL_VERSION_2 - EE_SDL_VERSION = -DEE_SDL_VERSION_1_3 - else - SDL_BACKEND_LINK = -lSDL2 - - EE_SDL_VERSION = -DEE_SDL_VERSION_2 - endif - - DYLIBS_BACKENDS += $(SDL_BACKEND_LINK) + DYLIBS_BACKENDS += $(SDL2_BACKEND_LINK) else - # Compile as static then... ( only SDL 1.3 or SDL 2 allowed ) + # Compile as static then... + SDL2_BACKEND_LINK += libs/$(BUILD_OS)/libSDL2.a - # If version is 1.3.x - ifneq (,$(findstring 1.3,$(SDL_VERSION))) - SDL_BACKEND_LINK = libs/$(BUILD_OS)/libSDL.a + EE_SDL_VERSION += -DEE_SDL_VERSION_2 - EE_SDL_VERSION = -DEE_SDL_VERSION_1_3 - else - # If version is 2.x.x - SDL_BACKEND_LINK = libs/$(BUILD_OS)/libSDL2.a - EE_SDL_VERSION = -DEE_SDL_VERSION_2 - endif - - STATIC_LIBS += $(SDL_BACKEND_LINK) + STATIC_LIBS += $(SDL2_BACKEND_LINK) endif - SDL_BACKEND_SRC = $(wildcard ./src/eepp/window/backend/SDL2/*.cpp) + SDL2_BACKEND_SRC += $(wildcard ./src/eepp/window/backend/SDL2/*.cpp) endif - SDL_DEFINE = -DEE_BACKEND_SDL_ACTIVE $(EE_SDL_VERSION) + SDL_DEFINE += -DEE_BACKEND_SDL_ACTIVE $(EE_SDL_VERSION) else - SDL_BACKEND_LINK = - SDL_BACKEND_SRC = - SDL_DEFINE = + +ifeq ($(BACKEND_SDL2), yes) + SDL2_BACKEND_SRC += $(wildcard ./src/eepp/window/backend/SDL2/*.cpp) + + ifeq ($(SDL_DEFINE),) + SDL_DEFINE += -DEE_BACKEND_SDL_ACTIVE + endif + + SDL_DEFINE += -DEE_SDL_VERSION_2 + + # Compile as shared? + ifeq ($(SHARED_BACKEND),yes) + SDL2_BACKEND_LINK += -lSDL2 + + DYLIBS_BACKENDS += $(SDL2_BACKEND_LINK) + else + # Compile as static then... + SDL2_BACKEND_LINK += libs/$(BUILD_OS)/libSDL2.a + + STATIC_LIBS += $(SDL2_BACKEND_LINK) + endif +else + ifeq ($(BACKEND_SDL), yes) + ifeq ($(BUILD_OS), darwin) + SDL_ADD_LINK += -framework Cocoa -lSDLmain + endif + + SDL_BACKEND_LINK += -lSDL $(SDL_ADD_LINK) + + DYLIBS_BACKENDS += $(SDL_BACKEND_LINK) + + SDL_BACKEND_SRC += $(wildcard ./src/eepp/window/backend/SDL/*.cpp) + + SDL_DEFINE += -DEE_BACKEND_SDL_ACTIVE -DEE_SDL_VERSION_1_2 + endif +endif + endif ifeq ($(BACKEND_ALLEGRO), yes) @@ -366,10 +380,12 @@ endif ifeq ($(BUILD_OS), ios) - ifeq ($(BACKEND_SDL),yes) + ifeq ($(BACKEND_SDL2),yes) BACKENDINCLUDE = -I./src/eepp/helper/SDL2/include else - BACKENDINCLUDE = -I./src/eepp/helper/allegro5/include + ifeq ($(BACKEND_ALLEGRO),yes) + BACKENDINCLUDE = -I./src/eepp/helper/allegro5/include + endif endif PLATFORMFLAGS += $(BACKENDINCLUDE) @@ -419,7 +435,7 @@ else ifeq ($(BUILD_OS), darwin) -LIBS = -framework OpenGL -framework OpenAL -framework CoreFoundation -framework AGL $(LIBSNDFILE) $(SDL_BACKEND_LINK) $(ALLEGRO_BACKEND_LINK) $(SFML_BACKEND_LINK) $(LIBFREETYPE2) +LIBS = -framework OpenGL -framework OpenAL -framework CoreFoundation -framework AGL $(LIBSNDFILE) $(SDL_BACKEND_LINK) $(SDL2_BACKEND_LINK) $(ALLEGRO_BACKEND_LINK) $(SFML_BACKEND_LINK) $(LIBFREETYPE2) OTHERINC += $(INCFREETYPE2) -I/usr/local/include/freetype2 PLATFORMSRC = $(wildcard ./src/eepp/window/platform/osx/*.cpp) $(wildcard ./src/eepp/system/platform/posix/*.cpp) @@ -427,7 +443,7 @@ else ifeq ($(BUILD_OS), haiku) -LIBS = -lopenal -lGL $(SDL_BACKEND_LINK) $(LIBFREETYPE2) +LIBS = -lopenal -lGL $(SDL_BACKEND_LINK) $(SDL2_BACKEND_LINK) $(LIBFREETYPE2) OTHERINC += $(INCFREETYPE2) PLATFORMSRC = $(wildcard ./src/eepp/system/platform/posix/*.cpp) @@ -435,7 +451,7 @@ else ifeq ($(BUILD_OS), freebsd) -LIBS = -lrt -lpthread -lX11 -lopenal -lGL -lXcursor $(LIBSNDFILE) $(SDL_BACKEND_LINK) $(ALLEGRO_BACKEND_LINK) $(SFML_BACKEND_LINK) $(LIBFREETYPE2) +LIBS = -lrt -lpthread -lX11 -lopenal -lGL -lXcursor $(LIBSNDFILE) $(SDL_BACKEND_LINK) $(SDL2_BACKEND_LINK) $(ALLEGRO_BACKEND_LINK) $(SFML_BACKEND_LINK) $(LIBFREETYPE2) OTHERINC += $(INCFREETYPE2) PLATFORMSRC = $(wildcard ./src/eepp/window/platform/x11/*.cpp) $(wildcard ./src/eepp/system/platform/posix/*.cpp) @@ -443,7 +459,7 @@ else ifeq ($(BUILD_OS), mingw32) -LIBS = -lOpenAL32 -lopengl32 -lmingw32 -lglu32 -lgdi32 -static-libgcc -static-libstdc++ -mwindows $(LIBSNDFILE) $(SDL_BACKEND_LINK) $(ALLEGRO_BACKEND_LINK) $(SFML_BACKEND_LINK) $(LIBFREETYPE2) +LIBS = -lOpenAL32 -lopengl32 -lmingw32 -lglu32 -lgdi32 -static-libgcc -static-libstdc++ -mwindows $(LIBSNDFILE) $(SDL_BACKEND_LINK) $(SDL2_BACKEND_LINK) $(ALLEGRO_BACKEND_LINK) $(SFML_BACKEND_LINK) $(LIBFREETYPE2) OTHERINC += $(INCFREETYPE2) PLATFORMSRC = $(wildcard ./src/eepp/window/platform/win/*.cpp) $(wildcard ./src/eepp/system/platform/win/*.cpp) @@ -452,7 +468,7 @@ else #if it is cygwin ifneq (,$(findstring cygwin,$(BUILD_OS))) -LIBS = -lOpenAL32 -lmingw32 -lopengl32 -lglu32 -lgdi32 -static-libgcc -mwindows $(LIBSNDFILE) $(SDL_BACKEND_LINK) $(ALLEGRO_BACKEND_LINK) $(SFML_BACKEND_LINK) $(LIBFREETYPE2) +LIBS = -lOpenAL32 -lmingw32 -lopengl32 -lglu32 -lgdi32 -static-libgcc -mwindows $(LIBSNDFILE) $(SDL_BACKEND_LINK) $(SDL2_BACKEND_LINK) $(ALLEGRO_BACKEND_LINK) $(SFML_BACKEND_LINK) $(LIBFREETYPE2) OTHERINC += -I./src/eepp/helper/zlib $(INCFREETYPE2) PLATFORMSRC = $(wildcard ./src/eepp/window/platform/win/*.cpp) $(wildcard ./src/eepp/system/platform/win/*.cpp) @@ -460,7 +476,7 @@ else ifeq ($(BUILD_OS), ios) -LIBS = -static-libgcc -static-libstdc++ -framework OpenGLES -framework OpenAL -framework AudioToolbox -framework CoreAudio -framework Foundation -framework CoreFoundation -framework UIKit -framework QuartzCore -framework CoreGraphics $(SDL_BACKEND_LINK) $(ALLEGRO_BACKEND_LINK) $(SFML_BACKEND_LINK) +LIBS = -static-libgcc -static-libstdc++ -framework OpenGLES -framework OpenAL -framework AudioToolbox -framework CoreAudio -framework Foundation -framework CoreFoundation -framework UIKit -framework QuartzCore -framework CoreGraphics $(SDL_BACKEND_LINK) $(SDL2_BACKEND_LINK) $(ALLEGRO_BACKEND_LINK) $(SFML_BACKEND_LINK) OTHERINC += $(INCFREETYPE2) ifeq ($(ARCH),armv7) @@ -520,18 +536,18 @@ else endif SRCHELPERS = $(SRCFREETYPE) $(SRCGLEW) $(wildcard ./src/eepp/helper/SOIL2/src/SOIL2/*.c) $(wildcard ./src/eepp/helper/stb_vorbis/*.c) $(wildcard ./src/eepp/helper/zlib/*.c) $(wildcard ./src/eepp/helper/libzip/*.c) $(wildcard ./src/eepp/helper/chipmunk/*.c) $(wildcard ./src/eepp/helper/chipmunk/constraints/*.c) -SRCMODULES = $(wildcard ./src/eepp/helper/haikuttf/*.cpp) $(wildcard ./src/eepp/base/*.cpp) $(wildcard ./src/eepp/audio/*.cpp) $(wildcard ./src/eepp/gaming/*.cpp) $(wildcard ./src/eepp/gaming/mapeditor/*.cpp) $(wildcard ./src/eepp/graphics/*.cpp) $(wildcard ./src/eepp/graphics/renderer/*.cpp) $(wildcard ./src/eepp/math/*.cpp) $(wildcard ./src/eepp/system/*.cpp) $(wildcard ./src/eepp/ui/*.cpp) $(wildcard ./src/eepp/ui/tools/*.cpp) $(wildcard ./src/eepp/utils/*.cpp) $(wildcard ./src/eepp/window/*.cpp) $(wildcard ./src/eepp/window/backend/null/*.cpp) $(wildcard ./src/eepp/window/platform/null/*.cpp) $(SDL_BACKEND_SRC) $(ALLEGRO_BACKEND_SRC) $(SFML_BACKEND_SRC) $(PLATFORMSRC) $(wildcard ./src/eepp/physics/*.cpp) $(wildcard ./src/eepp/physics/constraints/*.cpp) +SRCMODULES = $(wildcard ./src/eepp/helper/haikuttf/*.cpp) $(wildcard ./src/eepp/base/*.cpp) $(wildcard ./src/eepp/audio/*.cpp) $(wildcard ./src/eepp/gaming/*.cpp) $(wildcard ./src/eepp/gaming/mapeditor/*.cpp) $(wildcard ./src/eepp/graphics/*.cpp) $(wildcard ./src/eepp/graphics/renderer/*.cpp) $(wildcard ./src/eepp/math/*.cpp) $(wildcard ./src/eepp/system/*.cpp) $(wildcard ./src/eepp/ui/*.cpp) $(wildcard ./src/eepp/ui/tools/*.cpp) $(wildcard ./src/eepp/utils/*.cpp) $(wildcard ./src/eepp/window/*.cpp) $(wildcard ./src/eepp/window/backend/null/*.cpp) $(wildcard ./src/eepp/window/platform/null/*.cpp) $(SDL_BACKEND_SRC) $(SDL2_BACKEND_SRC) $(ALLEGRO_BACKEND_SRC) $(SFML_BACKEND_SRC) $(PLATFORMSRC) $(wildcard ./src/eepp/physics/*.cpp) $(wildcard ./src/eepp/physics/constraints/*.cpp) OBJHELPERS = $(SRCHELPERS:.c=.o) OBJMODULES = $(SRCMODULES:.cpp=.o) ifeq ($(ARCH),) - OBJDIR = obj/$(BUILD_OS)/$(RELEASETYPE)/ + OBJDIR = obj/$(BUILD_OS)/$(RELEASETYPE)/ else ifeq ($(BUILD_OS), ios) - OBJDIR = obj/$(BUILD_OS)/$(RELEASETYPE)/$(ARCH)/$(GL_VERSION)/ + OBJDIR = obj/$(BUILD_OS)/$(RELEASETYPE)/$(ARCH)/$(GL_VERSION)/ else - OBJDIR = obj/$(BUILD_OS)/$(RELEASETYPE)/$(ARCH)/ + OBJDIR = obj/$(BUILD_OS)/$(RELEASETYPE)/$(ARCH)/ endif endif diff --git a/include/eepp/audio/base.hpp b/include/eepp/audio/base.hpp index 96a88475d..db0e54f48 100644 --- a/include/eepp/audio/base.hpp +++ b/include/eepp/audio/base.hpp @@ -7,6 +7,7 @@ #include #include #include +#include using namespace EE::System; #include diff --git a/include/eepp/base/string.hpp b/include/eepp/base/string.hpp index bfd7dc8a1..1a249a7ac 100644 --- a/include/eepp/base/string.hpp +++ b/include/eepp/base/string.hpp @@ -24,6 +24,7 @@ /** NOTE: ** The class was modified to fit EEPP own needs. This is not the original implementation from SFML2. ** Functions and methods are the same that in std::string to facilitate portability. +** Also added a lot of utilities for string manipulation **/ #ifndef EE_STRING_HPP @@ -34,6 +35,9 @@ #include #include #include +#include +#include +#include namespace EE { @@ -48,6 +52,103 @@ class EE_API String { typedef StringType::const_reverse_iterator ConstReverseIterator; //! Constant iterator type static const std::size_t InvalidPos; ///< Represents an invalid position in the string + + /** @return If the value passed is a character */ + static bool IsCharacter( const eeInt& mValue ); + + /** @return If the value passed is a number */ + static bool IsNumber( const eeInt& mValue, bool AllowDot = false ); + + /** @return If the value passed is a letter */ + static bool IsLetter( const eeInt& mValue ); + + /** Split a String and hold it on a vector */ + static std::vector < String > SplitString ( const String& str, const Uint32& splitchar = '\n', const bool& pushEmptyString = false ); + + /** Split a string and hold it on a vector */ + static std::vector < std::string > SplitString ( const std::string& str, const Int8& splitchar = '\n', const bool& pushEmptyString = false ); + + /** Remove the first space on the string */ + static std::string LTrim( const std::string & str ); + + /** Removes all spaces on the string */ + static std::string Trim( const std::string & str ); + + /** Convert the string into upper case string */ + static void ToUpper( std::string & str ); + + /** Convert the string into lower case string */ + static void ToLower( std::string & str ); + + /** Convert the string to an std::vector */ + static std::vector stringToUint8( const std::string& str ); + + /** Convert the std::vector to an string */ + static std::string Uint8Tostring( const std::vector v ); + + /** Insert a char into String on pos (added this function to avoid a bug on String) */ + static void InsertChar( String& str, const eeUint& pos, const Uint32& tchar ); + + /** Copy a string to another + * @param Dst Destination String + * @param Src Source String + * @param DstSize Destination Size + */ + static void StrCopy( char * Dst, const char * Src, eeUint DstSize ); + + /** Compare two strings from its beginning. + * @param Start String start + * @param Str String to compare + * @return The position of the last char compared ( -1 if fails ) + */ + static Int32 StrStartsWith( const std::string& Start, const std::string Str ); + + /** Compare two strings from its beginning. + * @param Start String start + * @param Str String to compare + * @return The position of the last char compared ( -1 if fails ) + */ + static Int32 StrStartsWith( const String& Start, const String Str ); + + /** Replaces a substring by another string inside a string */ + static void ReplaceSubStr(std::string &target, const std::string& that, const std::string& with ); + + /** Removes the numbers at the end of the string */ + static std::string RemoveNumbersAtEnd( std::string txt ); + + /** Converts from any basic type to std::string */ + template + static std::string toStr(const T& i) { + std::ostringstream ss; + ss << i; + return ss.str(); + } + + /** Converts from a string to type */ + template + static bool fromString(T& t, const std::string& s, std::ios_base& (*f)(std::ios_base&) = std::dec ) { + std::istringstream iss(s); + return !(iss >> f >> t).fail(); + } + + /** Converts from a String to type */ + template + static bool fromString(T& t, const String& s, std::ios_base& (*f)(std::ios_base&) = std::dec ) { + std::istringstream iss( s.ToUtf8() ); + return !(iss >> f >> t).fail(); + } + + /** Returning a std::string from a formated string */ + static std::string StrFormated( const char* format, ... ) + #ifdef __GNUC__ + /* This attribute is nice: it even works through gettext invokation. For + example, gcc will complain that StrFormat(_("%s"), 42) is ill-formed. */ + __attribute__((format(printf, 1, 2))) + #endif + ; + + /** Format a char buffer */ + static void StrFormat( char * Buffer, int BufferSize, const char * format, ... ); /** @brief Construct from an UTF-8 string to UTF-32 according ** @param uf8String UTF-8 string to convert diff --git a/include/eepp/declares.hpp b/include/eepp/declares.hpp index 8f30a7a08..d8657f3d2 100644 --- a/include/eepp/declares.hpp +++ b/include/eepp/declares.hpp @@ -257,6 +257,13 @@ namespace EE { #define eeceil ceilf #define eeabs fabs #endif + + #ifdef EE_COMPILER_MSVC + #define eevsnprintf( str, size, format, args ) _vsnprintf_s( str, size, size, format, args ) + #else + #define eevsnprintf( str, size, format, args ) vsnprintf( str, size, format, args ) + #endif + template T eemax( T a, T b ) { return (a > b) ? a : b; diff --git a/include/eepp/gaming/base.hpp b/include/eepp/gaming/base.hpp index 2eb59ac1e..0f4025ea2 100644 --- a/include/eepp/gaming/base.hpp +++ b/include/eepp/gaming/base.hpp @@ -15,6 +15,7 @@ using namespace EE::Math; #include #include #include +#include using namespace EE::System; #endif diff --git a/include/eepp/graphics/base.hpp b/include/eepp/graphics/base.hpp index d56e3794e..3591da872 100644 --- a/include/eepp/graphics/base.hpp +++ b/include/eepp/graphics/base.hpp @@ -240,7 +240,6 @@ #include #include #include -#include #include #include using namespace EE::Utils; @@ -255,6 +254,7 @@ using namespace EE::Math; #include #include #include +#include using namespace EE::System; #include diff --git a/include/eepp/system.hpp b/include/eepp/system.hpp index 0238e610d..39389f3de 100644 --- a/include/eepp/system.hpp +++ b/include/eepp/system.hpp @@ -1,6 +1,8 @@ #ifndef EEPP_SYSTEM_HPP #define EEPP_SYSTEM_HPP +#include +#include #include #include #include diff --git a/include/eepp/system/base.hpp b/include/eepp/system/base.hpp index bf2a7778d..13e9f5b93 100644 --- a/include/eepp/system/base.hpp +++ b/include/eepp/system/base.hpp @@ -4,7 +4,6 @@ #include #include -#include #include using namespace EE::Utils; diff --git a/include/eepp/system/clog.hpp b/include/eepp/system/clog.hpp index 9ef88c082..94583ead5 100755 --- a/include/eepp/system/clog.hpp +++ b/include/eepp/system/clog.hpp @@ -5,6 +5,7 @@ #include #include #include +#include namespace EE { namespace System { diff --git a/include/eepp/system/cpak.hpp b/include/eepp/system/cpak.hpp index f5de31b03..d0a1d6236 100755 --- a/include/eepp/system/cpak.hpp +++ b/include/eepp/system/cpak.hpp @@ -3,7 +3,6 @@ #include #include -#include #include namespace EE { namespace System { diff --git a/include/eepp/system/filesystem.hpp b/include/eepp/system/filesystem.hpp new file mode 100644 index 000000000..212d382a1 --- /dev/null +++ b/include/eepp/system/filesystem.hpp @@ -0,0 +1,97 @@ +#ifndef EE_SYSTEM_FILESYSTEM_HPP +#define EE_SYSTEM_FILESYSTEM_HPP + +#include + +namespace EE { namespace System { + +class EE_API FileSystem { + public: + /** @return The default slash path code of the current OS */ + static std::string GetOSlash(); + + /** @return True if the file exists ( false if is a directory, to know if directory exists use IsDirectory ) */ + static bool FileExists( const std::string& Filepath ); + + /** Copy a file to memory + * @param path The file path + * @param data The vector to allocate the file in memory + * @return True if returned the file to the vector. + */ + static bool FileGet( const std::string& path, std::vector& data ); + + /** Copy a file to memory + * @param path The file path + * @param data A SafeDataPointer to allocate the data to memory + * @return True if returned the file to the SafeDataPointer + */ + static bool FileGet( const std::string& path, SafeDataPointer& data ); + + /** Copy a file to location. + * @param src Source File Path + * @param dst Destination File Path + * @return If success. + */ + static bool FileCopy( const std::string& src, const std::string& dst ); + + /** @return The file extension + * @param filepath The file path or name + * @param lowerExt Lowercase the extension obtained? ( true by default ) + */ + static std::string FileExtension( const std::string& filepath, const bool& lowerExt = true ); + + /** @return The file name of a file path */ + static std::string FileNameFromPath( const std::string& filepath ); + + /** @return Removes the file name from a path, and return the path. */ + static std::string FileRemoveFileName( const std::string& filepath ); + + /** @return Removes the extension of a filepath */ + static std::string FileRemoveExtension( const std::string& filepath ); + + /** Removes the process path to a file path */ + static void FilePathRemoveProcessPath( std::string& path ); + + /** Write a file in binary mode and close it. */ + static bool FileWrite( const std::string& filepath, const Uint8* data, const Uint32& dataSize ); + + /** Write a file in binary mode and close it. */ + static bool FileWrite( const std::string& filepath, const std::vector& data ); + + /** @return The modification date of the file */ + static Uint32 FileGetModificationDate( const std::string& Filepath ); + + /** If the directory path not end with a slash, it will add it. */ + static void DirPathAddSlashAtEnd( std::string& path ); + + /** Move up from directory tree */ + static std::string RemoveLastFolderFromPath( std::string path ); + + /** @return The files and sub directories contained by a directory */ + static std::vector FilesGetInPath( const std::string& path ); + + /** @return The files and sub directories contained by a directory */ + static std::vector FilesGetInPath( const String& path ); + + /** @return The size of a file */ + static Uint64 FileSize( const std::string& Filepath ); + + /** @return If directory exists, and is a directory */ + static bool IsDirectory( const std::string& path ); + + /** @return If directory exists, and is a directory */ + static bool IsDirectory( const String& path ); + + /** Creates a new directory */ + static bool MakeDir( const std::string& path, const Uint16& mode = 0770 ); + + /** Convert a size represented in bytes, to a string converted in byes/kb/mb/tb. + * @example 10485760 -> "10.0 MB" + */ + static std::string SizeToString( const Uint32& MemSize ); + +}; + +}} + +#endif diff --git a/include/eepp/system/sys.hpp b/include/eepp/system/sys.hpp new file mode 100644 index 000000000..d6ea96752 --- /dev/null +++ b/include/eepp/system/sys.hpp @@ -0,0 +1,43 @@ +#ifndef EE_SYSTEM_SYSTEM_HPP +#define EE_SYSTEM_SYSTEM_HPP + +#include + +namespace EE { namespace System { + +class EE_API Sys { + public: + /** Returns the current date time */ + static std::string GetDateTimeStr(); + + /** @return A storage path for config files for every platform */ + static std::string StoragePath( std::string appname ); + + /** @return The number of milliseconds since the EE++ library initialization. Note that this value wraps if the program runs for more than ~49 days. */ + static Uint32 GetTicks(); + + /** Wait a specified number of milliseconds before returning. */ + static void Sleep( const Uint32& ms ); + + /** @return The application path ( the executable path ) */ + static std::string GetProcessPath(); + + /** @return The System Time */ + static eeDouble GetSystemTime(); + + /** @return The OS Name */ + static std::string GetOSName(); + + /** @return The OS Architecture */ + static std::string GetOSArchitecture(); + + /** @return The Number of CPUs of the system. */ + static eeInt GetCPUCount(); + + /** @return Returns free disk space for a given path */ + static Int64 GetDiskFreeSpace(const std::string& path); +}; + +}} + +#endif diff --git a/include/eepp/system/tresourcemanager.hpp b/include/eepp/system/tresourcemanager.hpp index 5739ebaa5..9dd3fb6d9 100644 --- a/include/eepp/system/tresourcemanager.hpp +++ b/include/eepp/system/tresourcemanager.hpp @@ -97,7 +97,7 @@ T * tResourceManager::Add( T * Resource ) { while ( Count( Resource->Id() ) ) { c++; - Resource->Name( RealName + toStr( c ) ); + Resource->Name( RealName + String::toStr( c ) ); } return Add( Resource ); diff --git a/include/eepp/ui/base.hpp b/include/eepp/ui/base.hpp index 30dc4a1b9..a876f1503 100644 --- a/include/eepp/ui/base.hpp +++ b/include/eepp/ui/base.hpp @@ -16,6 +16,7 @@ using namespace EE::Utils; using namespace EE::Math; #include +#include using namespace EE::System; #include diff --git a/include/eepp/ui/cuiaquatheme.hpp b/include/eepp/ui/cuiaquatheme.hpp index a7afa36ff..03a658015 100644 --- a/include/eepp/ui/cuiaquatheme.hpp +++ b/include/eepp/ui/cuiaquatheme.hpp @@ -17,7 +17,7 @@ class EE_API cUIAquaTheme : public cUITheme { virtual cUIWindow * CreateWindow( cUIControl * Parent = NULL, const eeSize& Size = eeSize(), const eeVector2i& Pos = eeVector2i(), const Uint32& Flags = UI_CONTROL_DEFAULT_FLAGS_CENTERED, Uint32 WinFlags = UI_WIN_DEFAULT_FLAGS, eeSize MinWindowSize = eeSize(0,0), Uint8 BaseAlpha = 255 ); - virtual cUICommonDialog * CreateCommonDialog( cUIControl * Parent = NULL, const eeSize& Size = eeSize(), const eeVector2i& Pos = eeVector2i(), const Uint32& Flags = UI_CONTROL_DEFAULT_FLAGS_CENTERED, Uint32 WinFlags = UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON, eeSize MinWindowSize = eeSize(0,0), Uint8 BaseAlpha = 255, Uint32 CDLFlags = UI_CDL_DEFAULT_FLAGS, std::string DefaultFilePattern = "*", std::string DefaultDirectory = GetProcessPath() ); + virtual cUICommonDialog * CreateCommonDialog( cUIControl * Parent = NULL, const eeSize& Size = eeSize(), const eeVector2i& Pos = eeVector2i(), const Uint32& Flags = UI_CONTROL_DEFAULT_FLAGS_CENTERED, Uint32 WinFlags = UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON, eeSize MinWindowSize = eeSize(0,0), Uint8 BaseAlpha = 255, Uint32 CDLFlags = UI_CDL_DEFAULT_FLAGS, std::string DefaultFilePattern = "*", std::string DefaultDirectory = Sys::GetProcessPath() ); virtual cUIComboBox * CreateComboBox( cUIControl * Parent = NULL, const eeSize& Size = eeSize(), const eeVector2i& Pos = eeVector2i(), const Uint32& Flags = UI_CONTROL_DEFAULT_FLAGS | UI_CLIP_ENABLE | UI_AUTO_PADDING | UI_AUTO_SIZE, Uint32 MinNumVisibleItems = 6, bool PopUpToMainControl = false, cUIListBox * ListBox = NULL ); diff --git a/include/eepp/ui/cuicommondialog.hpp b/include/eepp/ui/cuicommondialog.hpp index 37b91524a..cf9bef9cd 100644 --- a/include/eepp/ui/cuicommondialog.hpp +++ b/include/eepp/ui/cuicommondialog.hpp @@ -17,7 +17,7 @@ class EE_API cUICommonDialog : public cUIWindow { public: inline CreateParams() : cUIWindow::CreateParams(), - DefaultDirectory( GetProcessPath() ), + DefaultDirectory( Sys::GetProcessPath() ), DefaultFilePattern( "*" ), CDLFlags( UI_CDL_DEFAULT_FLAGS ) { diff --git a/include/eepp/ui/cuitheme.hpp b/include/eepp/ui/cuitheme.hpp index 97aa61117..147b75e44 100644 --- a/include/eepp/ui/cuitheme.hpp +++ b/include/eepp/ui/cuitheme.hpp @@ -130,7 +130,7 @@ class EE_API cUITheme : public tResourceManager { virtual cUIWindow * CreateWindow( cUIControl * Parent = NULL, const eeSize& Size = eeSize(), const eeVector2i& Pos = eeVector2i(), const Uint32& Flags = UI_CONTROL_DEFAULT_FLAGS_CENTERED, Uint32 WinFlags = UI_WIN_DEFAULT_FLAGS, eeSize MinWindowSize = eeSize(0,0), Uint8 BaseAlpha = 255 ); - virtual cUICommonDialog * CreateCommonDialog( cUIControl * Parent = NULL, const eeSize& Size = eeSize(), const eeVector2i& Pos = eeVector2i(), const Uint32& Flags = UI_CONTROL_DEFAULT_FLAGS_CENTERED, Uint32 WinFlags = UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON, eeSize MinWindowSize = eeSize(0,0), Uint8 BaseAlpha = 255, Uint32 CDLFlags = UI_CDL_DEFAULT_FLAGS, std::string DefaultFilePattern = "*", std::string DefaultDirectory = GetProcessPath() ); + virtual cUICommonDialog * CreateCommonDialog( cUIControl * Parent = NULL, const eeSize& Size = eeSize(), const eeVector2i& Pos = eeVector2i(), const Uint32& Flags = UI_CONTROL_DEFAULT_FLAGS_CENTERED, Uint32 WinFlags = UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON, eeSize MinWindowSize = eeSize(0,0), Uint8 BaseAlpha = 255, Uint32 CDLFlags = UI_CDL_DEFAULT_FLAGS, std::string DefaultFilePattern = "*", std::string DefaultDirectory = Sys::GetProcessPath() ); virtual cUIMessageBox * CreateMessageBox( UI_MSGBOX_TYPE Type = MSGBOX_OKCANCEL, const String& Message = String(), Uint32 WinFlags = UI_WIN_DEFAULT_FLAGS | UI_WIN_MODAL, cUIControl * Parent = NULL, const eeSize& Size = eeSize(), const eeVector2i& Pos = eeVector2i(), const Uint32& Flags = UI_CONTROL_DEFAULT_FLAGS_CENTERED, eeSize MinWindowSize = eeSize(0,0), Uint8 BaseAlpha = 255 ); diff --git a/include/eepp/utils.hpp b/include/eepp/utils.hpp index 51229a342..3f3b4933f 100644 --- a/include/eepp/utils.hpp +++ b/include/eepp/utils.hpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include diff --git a/include/eepp/utils/string.hpp b/include/eepp/utils/string.hpp deleted file mode 100755 index 19fd4bc50..000000000 --- a/include/eepp/utils/string.hpp +++ /dev/null @@ -1,111 +0,0 @@ -#ifndef EE_UTILSCSTRING_H -#define EE_UTILSCSTRING_H - -#include -#include -#include -#include - -namespace EE { namespace Utils { - -/** @return If the value passed is a character */ -bool EE_API IsCharacter( const eeInt& mValue ); - -/** @return If the value passed is a number */ -bool EE_API IsNumber( const eeInt& mValue, bool AllowDot = false ); - -/** @return If the value passed is a letter */ -bool EE_API IsLetter( const eeInt& mValue ); - -/** Returns the current date time */ -std::string EE_API GetDateTimeStr(); - -/** Converts from any basic type to std::string */ -template -std::string toStr(const T& i) { - std::ostringstream ss; - ss << i; - return ss.str(); -} - -/** Converts from a string to type */ -template -bool fromString(T& t, const std::string& s, std::ios_base& (*f)(std::ios_base&) = std::dec ) { - std::istringstream iss(s); - return !(iss >> f >> t).fail(); -} - -/** Converts from a String to type */ -template -bool fromString(T& t, const String& s, std::ios_base& (*f)(std::ios_base&) = std::dec ) { - std::istringstream iss( s.ToUtf8() ); - return !(iss >> f >> t).fail(); -} - -/** Split a String and hold it on a vector */ -std::vector < String > EE_API SplitString ( const String& str, const Uint32& splitchar = '\n', const bool& pushEmptyString = false ); - -/** Split a string and hold it on a vector */ -std::vector < std::string > EE_API SplitString ( const std::string& str, const Int8& splitchar = '\n', const bool& pushEmptyString = false ); - -/** Returning a std::string from a formated string */ -std::string EE_API StrFormated( const char* format, ... ) -#ifdef __GNUC__ - /* This attribute is nice: it even works through gettext invokation. For - example, gcc will complain that StrFormat(_("%s"), 42) is ill-formed. */ - __attribute__((format(printf, 1, 2))) -#endif -; - -/** Format a char buffer */ -void EE_API StrFormat( char * Buffer, int BufferSize, const char * format, ... ); - -/** Remove the first space on the string */ -std::string EE_API LTrim( const std::string & str ); - -/** Removes all spaces on the string */ -std::string EE_API Trim( const std::string & str ); - -/** Convert the string into upper case string */ -void EE_API ToUpper( std::string & str ); - -/** Convert the string into lower case string */ -void EE_API ToLower( std::string & str ); - -/** Convert the string to an std::vector */ -std::vector EE_API stringToUint8( const std::string& str ); - -/** Convert the std::vector to an string */ -std::string EE_API Uint8Tostring( const std::vector v ); - -/** Insert a char into String on pos (added this function to avoid a bug on String) */ -void EE_API InsertChar( String& str, const eeUint& pos, const Uint32& tchar ); - -/** @return A storage path for config files for every platform */ -std::string EE_API StoragePath( std::string appname ); - -/** Copy a string to another -* @param Dst Destination String -* @param Src Source String -* @param DstSize Destination Size -*/ -void EE_API StrCopy( char * Dst, const char * Src, eeUint DstSize ); - -/** Compare two strings from its beginning. -* @param Start String start -* @param Str String to compare -* @return The position of the last char compared ( -1 if fails ) -*/ -Int32 EE_API StrStartsWith( const std::string& Start, const std::string Str ); - -Int32 EE_API StrStartsWith( const String& Start, const String Str ); - -/** Replaces a substring by another string inside a string */ -void EE_API ReplaceSubStr(std::string &target, const std::string& that, const std::string& with ); - -/** Removes the numbers at the end of the string */ -std::string EE_API RemoveNumbersAtEnd( std::string txt ); - -}} - -#endif diff --git a/include/eepp/utils/utils.hpp b/include/eepp/utils/utils.hpp index aec61725f..2edb91bc4 100755 --- a/include/eepp/utils/utils.hpp +++ b/include/eepp/utils/utils.hpp @@ -6,38 +6,6 @@ #include namespace EE { namespace Utils { - /** @return True if the file exists ( false if is a directory, to know if directory exists use IsDirectory ) */ - bool EE_API FileExists( const std::string& Filepath ); - - /** @return The number of milliseconds since the EE++ library initialization. Note that this value wraps if the program runs for more than ~49 days. */ - Uint32 EE_API eeGetTicks(); - - /** Wait a specified number of milliseconds before returning. */ - void EE_API eeSleep( const Uint32& ms ); - - /** @return The application path ( the executable path ) */ - std::string EE_API GetProcessPath(); - - /** @return The files and sub directories contained by a directory */ - std::vector EE_API FilesGetInPath( const std::string& path ); - - /** @return The files and sub directories contained by a directory */ - std::vector EE_API FilesGetInPath( const String& path ); - - /** @return The size of a file */ - Uint64 EE_API FileSize( const std::string& Filepath ); - - /** @return The System Time */ - eeDouble EE_API GetSystemTime(); - - /** @return If directory exists, and is a directory */ - bool EE_API IsDirectory( const std::string& path ); - - /** @return If directory exists, and is a directory */ - bool EE_API IsDirectory( const String& path ); - - /** Creates a new directory */ - bool EE_API MakeDir( const std::string& path, const Uint16& mode = 0770 ); /** @return string hash */ Uint32 EE_API MakeHash( const std::string& str ); @@ -45,71 +13,6 @@ namespace EE { namespace Utils { /** @return string hash */ Uint32 EE_API MakeHash( const Uint8 * str ); - /** Copy a file to memory - * @param path The file path - * @param data The vector to allocate the file in memory - * @return True if returned the file to the vector. - */ - bool EE_API FileGet( const std::string& path, std::vector& data ); - - /** Copy a file to memory - * @param path The file path - * @param data A SafeDataPointer to allocate the data to memory - * @return True if returned the file to the SafeDataPointer - */ - bool EE_API FileGet( const std::string& path, SafeDataPointer& data ); - - /** Copy a file to location. - * @param src Source File Path - * @param dst Destination File Path - * @return If success. - */ - bool EE_API FileCopy( const std::string& src, const std::string& dst ); - - /** @return The file extension - * @param filepath The file path or name - * @param lowerExt Lowercase the extension obtained? ( true by default ) - */ - std::string EE_API FileExtension( const std::string& filepath, const bool& lowerExt = true ); - - /** @return The file name of a file path */ - std::string EE_API FileNameFromPath( const std::string& filepath ); - - /** @return Removes the file name from a path, and return the path. */ - std::string EE_API FileRemoveFileName( const std::string& filepath ); - - /** @return Removes the extension of a filepath */ - std::string EE_API FileRemoveExtension( const std::string& filepath ); - - /** Removes the process path to a file path */ - void FilePathRemoveProcessPath( std::string& path ); - - /** Write a file in binary mode and close it. */ - bool EE_API FileWrite( const std::string& filepath, const Uint8* data, const Uint32& dataSize ); - - /** Write a file in binary mode and close it. */ - bool EE_API FileWrite( const std::string& filepath, const std::vector& data ); - - /** @return The Number of CPUs of the system. */ - eeInt EE_API GetCPUCount(); - - /** @return The modification date of the file */ - Uint32 EE_API FileGetModificationDate( const std::string& Filepath ); - - /** If the directory path not end with a slash, it will add it. */ - void EE_API DirPathAddSlashAtEnd( std::string& path ); - - /** Move up from directory tree */ - std::string RemoveLastFolderFromPath( std::string path ); - - /** @return The default slash path code of the current OS */ - std::string EE_API GetOSlash(); - - /** Convert a size represented in bytes, to a string converted in byes/kb/mb/tb. - * @example 10485760 -> "10.0 MB" - */ - std::string EE_API SizeToString( const Uint32& MemSize ); - /** Write a bit into the Key in the position defined. * @param Key The Key to write * @param Pos The Position of the bit @@ -127,14 +30,6 @@ namespace EE { namespace Utils { /** Write a 32 bit flag value */ void EE_API SetFlagValue( Uint32 * Key, Uint32 Val, Uint32 BitWrite ); - /** @return The OS Name */ - std::string EE_API GetOSName(); - - /** @return The OS Architecture */ - std::string EE_API GetOSArchitecture(); - - /** @return Returns free disk space for a given path */ - Int64 EE_API GetDiskFreeSpace(const std::string& path); } } diff --git a/include/eepp/window/base.hpp b/include/eepp/window/base.hpp index 90d70980c..0582df98f 100644 --- a/include/eepp/window/base.hpp +++ b/include/eepp/window/base.hpp @@ -6,7 +6,6 @@ #include #include #include -#include #include using namespace EE::Utils; diff --git a/include/eepp/window/cengine.hpp b/include/eepp/window/cengine.hpp index 4dd646e38..706f0dc0a 100755 --- a/include/eepp/window/cengine.hpp +++ b/include/eepp/window/cengine.hpp @@ -95,12 +95,16 @@ class EE_API cEngine { Backend::cBackend * CreateSDLBackend( const WindowSettings& Settings ); + Backend::cBackend * CreateSDL2Backend( const WindowSettings& Settings ); + Backend::cBackend * CreateAllegroBackend( const WindowSettings& Settings ); Backend::cBackend * CreateSFMLBackend( const WindowSettings& Settings ); cWindow * CreateSDLWindow( const WindowSettings& Settings, const ContextSettings& Context ); + cWindow * CreateSDL2Window( const WindowSettings& Settings, const ContextSettings& Context ); + cWindow * CreateAllegroWindow( const WindowSettings& Settings, const ContextSettings& Context ); cWindow * CreateSFMLWindow( const WindowSettings& Settings, const ContextSettings& Context ); diff --git a/include/eepp/window/cwindow.hpp b/include/eepp/window/cwindow.hpp index c517cc15a..42e951d0c 100644 --- a/include/eepp/window/cwindow.hpp +++ b/include/eepp/window/cwindow.hpp @@ -31,6 +31,7 @@ namespace WindowBackend { enum { SDL, + SDL2, Allegro, SFML, Default diff --git a/projects/linux/ee.creator.user b/projects/linux/ee.creator.user index 6187814ef..960bed941 100644 --- a/projects/linux/ee.creator.user +++ b/projects/linux/ee.creator.user @@ -1,6 +1,6 @@ - + ProjectExplorer.Project.ActiveTarget @@ -57,7 +57,7 @@ false - -j4 -e DEBUGBUILD=yes SHARED_BACKEND=no BACKENDS_ALL=yes test + -j4 -e DEBUGBUILD=yes SHARED_BACKEND=yes BACKENDS_ALL=yes test make true @@ -72,7 +72,7 @@ true - -e DEBUGBUILD=yes clean + -e DEBUGBUILD=yes BACKENDS_ALL=yes clean /usr/bin/make %{buildDir} clean diff --git a/projects/linux/ee.files b/projects/linux/ee.files index e363f21a8..650d42983 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -337,7 +337,8 @@ ../../include/eepp/utils/vector2.hpp ../../include/eepp/utils/utils.hpp ../../include/eepp/utils/triangle2.hpp -../../include/eepp/utils/string.hpp +../../include/eepp/system/sys.hpp +../../src/eepp/system/sys.cpp ../../include/eepp/utils/size.hpp ../../include/eepp/utils/safedatapointer.hpp ../../include/eepp/utils/rect.hpp @@ -352,7 +353,6 @@ ../../include/eepp/utils/cinterpolation.hpp ../../include/eepp/utils/base.hpp ../../src/eepp/utils/utils.cpp -../../src/eepp/utils/string.cpp ../../src/eepp/utils/safedatapointer.cpp ../../src/eepp/utils/easing.cpp ../../src/eepp/utils/cwaypoints.cpp @@ -405,22 +405,22 @@ ../../src/eepp/window/backend/SDL/ccursorsdl.cpp ../../src/eepp/window/backend/SDL/ccursormanagersdl.cpp ../../src/eepp/window/backend/SDL/cclipboardsdl.cpp -../../src/eepp/window/backend/SDL2/cwindowsdl.hpp -../../src/eepp/window/backend/SDL2/cjoysticksdl.hpp -../../src/eepp/window/backend/SDL2/cjoystickmanagersdl.hpp -../../src/eepp/window/backend/SDL2/cinputsdl.hpp -../../src/eepp/window/backend/SDL2/ccursorsdl.hpp -../../src/eepp/window/backend/SDL2/ccursormanagersdl.hpp -../../src/eepp/window/backend/SDL2/cclipboardsdl.hpp -../../src/eepp/window/backend/SDL2/cbackendsdl.hpp +../../src/eepp/window/backend/SDL2/cwindowsdl2.hpp +../../src/eepp/window/backend/SDL2/cjoysticksdl2.hpp +../../src/eepp/window/backend/SDL2/cjoystickmanagersdl2.hpp +../../src/eepp/window/backend/SDL2/cinputsdl2.hpp +../../src/eepp/window/backend/SDL2/ccursorsdl2.hpp +../../src/eepp/window/backend/SDL2/ccursormanagersdl2.hpp +../../src/eepp/window/backend/SDL2/cclipboardsdl2.hpp +../../src/eepp/window/backend/SDL2/cbackendsdl2.hpp ../../src/eepp/window/backend/SDL2/base.hpp -../../src/eepp/window/backend/SDL2/cwindowsdl.cpp -../../src/eepp/window/backend/SDL2/cjoysticksdl.cpp -../../src/eepp/window/backend/SDL2/cjoystickmanagersdl.cpp -../../src/eepp/window/backend/SDL2/cinputsdl.cpp -../../src/eepp/window/backend/SDL2/ccursorsdl.cpp -../../src/eepp/window/backend/SDL2/ccursormanagersdl.cpp -../../src/eepp/window/backend/SDL2/cclipboardsdl.cpp +../../src/eepp/window/backend/SDL2/cwindowsdl2.cpp +../../src/eepp/window/backend/SDL2/cjoysticksdl2.cpp +../../src/eepp/window/backend/SDL2/cjoystickmanagersdl2.cpp +../../src/eepp/window/backend/SDL2/cinputsdl2.cpp +../../src/eepp/window/backend/SDL2/ccursorsdl2.cpp +../../src/eepp/window/backend/SDL2/ccursormanagersdl2.cpp +../../src/eepp/window/backend/SDL2/cclipboardsdl2.cpp ../../src/eepp/window/backend/allegro5/cwindowal.hpp ../../src/eepp/window/backend/allegro5/cjoystickmanageral.hpp ../../src/eepp/window/backend/allegro5/cjoystickal.hpp @@ -569,3 +569,6 @@ ../../src/eepp/graphics/cframebufferfbo.hpp ../../src/eepp/graphics/renderer/rendererhelper.hpp ../../include/eepp/graphics/packerhelper.hpp +../../src/eepp/window/backend/SDL2/cbackendsdl.cpp +../../include/eepp/system/filesystem.hpp +../../src/eepp/system/filesystem.cpp diff --git a/src/eepp/audio/cmusic.cpp b/src/eepp/audio/cmusic.cpp index 6aff33a1d..041df49a9 100755 --- a/src/eepp/audio/cmusic.cpp +++ b/src/eepp/audio/cmusic.cpp @@ -23,7 +23,7 @@ bool cMusic::OpenFromPack( cPack* Pack, const std::string& FilePackPath ) { } bool cMusic::OpenFromFile( const std::string& Filename ) { - if ( !FileExists( Filename ) ) { + if ( !FileSystem::FileExists( Filename ) ) { if ( cPackManager::instance()->FallbackToPacks() ) { std::string tPath( Filename ); diff --git a/src/eepp/audio/csoundbuffer.cpp b/src/eepp/audio/csoundbuffer.cpp index 0b527ed17..e6c9a12a1 100755 --- a/src/eepp/audio/csoundbuffer.cpp +++ b/src/eepp/audio/csoundbuffer.cpp @@ -37,7 +37,7 @@ cSoundBuffer::~cSoundBuffer() { } bool cSoundBuffer::LoadFromFile(const std::string& Filename) { - if ( !FileExists( Filename ) ) { + if ( !FileSystem::FileExists( Filename ) ) { if ( cPackManager::instance()->FallbackToPacks() ) { std::string tPath( Filename ); diff --git a/src/eepp/audio/csoundstream.cpp b/src/eepp/audio/csoundstream.cpp index 36dbff18a..5463328df 100755 --- a/src/eepp/audio/csoundstream.cpp +++ b/src/eepp/audio/csoundstream.cpp @@ -1,5 +1,7 @@ #include #include +#include +using namespace EE::System; namespace EE { namespace Audio { @@ -164,7 +166,7 @@ void cSoundStream::Run() { // Leave some time for the other threads if the stream is still playing if ( cSound::GetState() != SOUND_STOPPED ) - eeSleep(10); + Sys::Sleep(10); } // Stop the playback diff --git a/src/eepp/base/debug.cpp b/src/eepp/base/debug.cpp index 5a43d258c..55c75783d 100644 --- a/src/eepp/base/debug.cpp +++ b/src/eepp/base/debug.cpp @@ -45,11 +45,7 @@ void eePRINT( const char * format, ... ) { va_start( args, format ); - #ifdef EE_COMPILER_MSVC - _vsnprintf_s( buf, sizeof( buf ), sizeof( buf ) / sizeof( buf[0]), format, args ); - #else - vsnprintf( buf, sizeof( buf ) / sizeof( buf[0]), format, args ); - #endif + eevsnprintf( buf, sizeof( buf ), format, args ); va_end( args ); @@ -75,11 +71,7 @@ void eePRINTC( unsigned int cond, const char * format, ...) { va_start( args, format ); - #ifdef EE_COMPILER_MSVC - _vsnprintf_s( buf, eeARRAY_SIZE( buf ), eeARRAY_SIZE( buf ), format, args ); - #else - vsnprintf( buf, sizeof( buf ) / sizeof( buf[0]), format, args ); - #endif + eevsnprintf( buf, sizeof( buf ) / sizeof( buf[0]), format, args ); va_end( args ); diff --git a/src/eepp/base/string.cpp b/src/eepp/base/string.cpp index 6d1cd8d34..b3e9ecb29 100644 --- a/src/eepp/base/string.cpp +++ b/src/eepp/base/string.cpp @@ -1,4 +1,7 @@ #include +#include +#include +#include #include #include @@ -6,6 +9,198 @@ namespace EE { const std::size_t String::InvalidPos = StringType::npos; +bool String::IsCharacter( const eeInt& mValue ) { + return (mValue >= 32 && mValue <= 126) || (mValue >= 161 && mValue <= 255) || (mValue == 9); +} + +bool String::IsNumber( const eeInt& mValue, bool AllowDot ) { + if ( AllowDot ) + return ( mValue >= 48 && mValue <= 57 ) || mValue == 46; + + return mValue >= 48 && mValue <= 57; +} + +bool String::IsLetter( const eeInt& mValue ) { + return ( ( (mValue >= 65 && mValue <= 90) || (mValue >= 97 && mValue <= 122) || (mValue >= 192 && mValue <= 255) ) && (mValue != 215) && (mValue != 247) ); +} + +std::vector < String > String::SplitString ( const String& str, const Uint32& splitchar, const bool& pushEmptyString ) { + std::vector < String > tmp; + String tmpstr; + + for ( eeUint i = 0; i < str.size(); i++ ) { + if ( str[i] == splitchar ) { + if ( pushEmptyString || tmpstr.size() ) { + tmp.push_back(tmpstr); + tmpstr = ""; + } + } else { + tmpstr += str[i]; + } + } + + if ( tmpstr.size() ) + tmp.push_back(tmpstr); + + return tmp; +} + +std::vector < std::string > String::SplitString ( const std::string& str, const Int8& splitchar, const bool& pushEmptyString ) { + std::vector < std::string > tmp; + std::string tmpstr; + + for ( eeUint i = 0; i < str.size(); i++ ) { + if ( str[i] == splitchar ) { + if ( pushEmptyString || tmpstr.size() ) { + tmp.push_back(tmpstr); + tmpstr = ""; + } + } else { + tmpstr += str[i]; + } + } + + if ( tmpstr.size() ) + tmp.push_back( tmpstr ); + + return tmp; +} + + +std::string String::LTrim( const std::string & str ) { + std::string::size_type pos1 = str.find_first_not_of(' '); + return ( pos1 == std::string::npos ) ? str : str.substr( pos1 ); +} + +std::string String::Trim( const std::string & str ) { + std::string::size_type pos1 = str.find_first_not_of(' '); + std::string::size_type pos2 = str.find_last_not_of(' '); + return str.substr(pos1 == std::string::npos ? 0 : pos1, pos2 == std::string::npos ? str.length() - 1 : pos2 - pos1 + 1); +} + +void String::ToUpper( std::string & str ) { + std::transform(str.begin(), str.end(), str.begin(), (int(*)(int)) std::toupper); +} + +void String::ToLower( std::string & str ) { + std::transform(str.begin(), str.end(), str.begin(), (int(*)(int)) std::tolower); +} + +std::vector String::stringToUint8( const std::string& str ) { + return std::vector( str.begin(), str.end() ); +} + +std::string String::Uint8Tostring( const std::vector v ) { + return std::string( v.begin(), v.end() ); +} + +void String::StrCopy( char * Dst, const char * Src, eeUint DstSize ) { + char * DstEnd = Dst + DstSize - 1; + + while ( Dst < DstEnd && *Src ) { + *Dst = *Src; + Dst++; + Src++; + } + + *Dst = 0; +} + +Int32 String::StrStartsWith( const std::string& Start, const std::string Str ) { + Int32 Pos = -1; + + if ( Str.size() >= Start.size() ) { + for ( Uint32 i = 0; i < Start.size(); i++ ) { + if ( Start[i] == Str[i] ) { + Pos = (Int32)i; + } else { + Pos = -1; + break; + } + } + } + + return Pos; +} + +Int32 String::StrStartsWith( const String& Start, const String Str ) { + Int32 Pos = -1; + + if ( Str.size() >= Start.size() ) { + for ( Uint32 i = 0; i < Start.size(); i++ ) { + if ( Start[i] == Str[i] ) { + Pos = (Int32)i; + } else { + Pos = -1; + break; + } + } + } + + return Pos; +} + +void String::ReplaceSubStr( std::string &target, const std::string& that, const std::string& with ) { + std::string::size_type pos=0; + + while( ( pos = target.find( that, pos ) ) != std::string::npos ) { + target.erase( pos, that.length() ); + target.insert( pos, with ); + pos += with.length(); + } +} + +std::string String::RemoveNumbersAtEnd( std::string txt ) { + while ( txt.size() && txt[ txt.size() - 1 ] >= '0' && txt[ txt.size() - 1 ] <= '9' ) { + txt.resize( txt.size() - 1 ); + } + + return txt; +} + +void String::InsertChar( String& str, const eeUint& pos, const Uint32& tchar ) { + str.insert( str.begin() + pos, tchar ); +} + + +void String::StrFormat( char * Buffer, int BufferSize, const char * format, ... ) { + va_list args; + va_start( args, format ); +#ifdef EE_COMPILER_MSVC + _vsnprintf_s( Buffer, BufferSize, BufferSize, format, args ); +#else + vsnprintf( Buffer, BufferSize-1, format, args ); +#endif + va_end( args ); +} + +std::string String::StrFormated( const char * format, ... ) { + int n, size = 256; + std::string tstr( size, '\0' ); + + va_list args; + + while (1) { + va_start( args, format ); + + n = eevsnprintf( &tstr[0], size, format, args ); + + va_end( args ); + + if ( n > -1 && n < size ) { + tstr.resize( n ); + return tstr; + } + + if ( n > -1 ) // glibc 2.1 + size = n+1; // precisely what is needed + else // glibc 2.0 + size *= 2; // twice the old size + + tstr.resize( size, '\0' ); + } +} + String::String() { } diff --git a/src/eepp/gaming/cisomap.cpp b/src/eepp/gaming/cisomap.cpp index 14563c8bb..e46e2fc64 100755 --- a/src/eepp/gaming/cisomap.cpp +++ b/src/eepp/gaming/cisomap.cpp @@ -57,7 +57,7 @@ void cIsoMap::CreateBaseVertexBuffer() { T->Q = TileQBaseCoords( x, y ); T->Box = Quad2toAABB( T->Q ); - T->TilePosStr = toStr( x) + " - " + toStr( y ); + T->TilePosStr = String::toStr( x) + " - " + String::toStr( y ); for ( i = 0; i < 4; i++ ) T->Color[i] = mMapAmbientColor; diff --git a/src/eepp/gaming/cmap.cpp b/src/eepp/gaming/cmap.cpp index cbf295d25..481ffe148 100644 --- a/src/eepp/gaming/cmap.cpp +++ b/src/eepp/gaming/cmap.cpp @@ -99,7 +99,7 @@ void cMap::CreateLightManager() { void cMap::CreateEmptyTile() { //! I create a texture representing an empty tile to render instead of rendering with primitives because is a lot faster, at least with NVIDIA GPUs. cTextureFactory * TF = cTextureFactory::instance(); - std::string tileName( "maptile-" + toStr( mTileSize.Width() ) + "x" + toStr( mTileSize.Height() ) ); + std::string tileName( "maptile-" + String::toStr( mTileSize.Width() ) + "x" + String::toStr( mTileSize.Height() ) ); cTexture * Tex = TF->GetByName( tileName ); @@ -780,7 +780,7 @@ bool cMap::LoadFromStream( cIOStream& IOS ) { //! Load the Texture groups if needed for ( i = 0; i < ShapeGroups.size(); i++ ) { - std::string sgname = FileRemoveExtension( FileNameFromPath( ShapeGroups[i] ) ); + std::string sgname = FileSystem::FileRemoveExtension( FileSystem::FileNameFromPath( ShapeGroups[i] ) ); if ( NULL == cShapeGroupManager::instance()->GetByName( sgname ) ) { cTextureGroupLoader * tgl = eeNew( cTextureGroupLoader, () ); @@ -938,7 +938,7 @@ const std::string& cMap::Path() const { } bool cMap::Load( const std::string& path ) { - if ( FileExists( path ) ) { + if ( FileSystem::FileExists( path ) ) { mPath = path; cIOStreamFile IOS( mPath, std::ios::in | std::ios::binary ); @@ -1011,8 +1011,8 @@ void cMap::SaveToStream( cIOStream& IOS ) { memset( tProp.Name, 0, MAP_PROPERTY_SIZE ); memset( tProp.Value, 0, MAP_PROPERTY_SIZE ); - StrCopy( tProp.Name, it->first.c_str(), MAP_PROPERTY_SIZE ); - StrCopy( tProp.Value, it->second.c_str(), MAP_PROPERTY_SIZE ); + String::StrCopy( tProp.Name, it->first.c_str(), MAP_PROPERTY_SIZE ); + String::StrCopy( tProp.Value, it->second.c_str(), MAP_PROPERTY_SIZE ); IOS.Write( (const char*)&tProp, sizeof(sPropertyHdr) ); } @@ -1023,7 +1023,7 @@ void cMap::SaveToStream( cIOStream& IOS ) { memset( tSG.Path, 0, MAP_SHAPEGROUP_PATH_SIZE ); - StrCopy( tSG.Path, ShapeGroups[i].c_str(), MAP_SHAPEGROUP_PATH_SIZE ); + String::StrCopy( tSG.Path, ShapeGroups[i].c_str(), MAP_SHAPEGROUP_PATH_SIZE ); IOS.Write( (const char*)&tSG, sizeof(sMapShapeGroup) ); } @@ -1034,7 +1034,7 @@ void cMap::SaveToStream( cIOStream& IOS ) { memset( tVObjH.Name, 0, MAP_PROPERTY_SIZE ); - StrCopy( tVObjH.Name, (*votit).c_str(), MAP_PROPERTY_SIZE ); + String::StrCopy( tVObjH.Name, (*votit).c_str(), MAP_PROPERTY_SIZE ); IOS.Write( (const char*)&tVObjH, sizeof(sVirtualObj) ); } @@ -1046,7 +1046,7 @@ void cMap::SaveToStream( cIOStream& IOS ) { memset( tLayerH.Name, 0, LAYER_NAME_SIZE ); - StrCopy( tLayerH.Name, tLayer->Name().c_str(), LAYER_NAME_SIZE ); + String::StrCopy( tLayerH.Name, tLayer->Name().c_str(), LAYER_NAME_SIZE ); tLayerH.Type = tLayer->Type(); tLayerH.Flags = tLayer->Flags(); @@ -1072,8 +1072,8 @@ void cMap::SaveToStream( cIOStream& IOS ) { memset( tProp.Name, 0, MAP_PROPERTY_SIZE ); memset( tProp.Value, 0, MAP_PROPERTY_SIZE ); - StrCopy( tProp.Name, (*lit).first.c_str(), MAP_PROPERTY_SIZE ); - StrCopy( tProp.Value, (*lit).second.c_str(), MAP_PROPERTY_SIZE ); + String::StrCopy( tProp.Name, (*lit).first.c_str(), MAP_PROPERTY_SIZE ); + String::StrCopy( tProp.Value, (*lit).second.c_str(), MAP_PROPERTY_SIZE ); IOS.Write( (const char*)&tProp, sizeof(sPropertyHdr) ); } @@ -1216,7 +1216,7 @@ void cMap::SaveToStream( cIOStream& IOS ) { } void cMap::Save( const std::string& path ) { - if ( !IsDirectory( path ) ) { + if ( !FileSystem::IsDirectory( path ) ) { cIOStreamFile IOS( path, std::ios::out | std::ios::binary ); SaveToStream( IOS ); diff --git a/src/eepp/gaming/mapeditor/cmapeditor.cpp b/src/eepp/gaming/mapeditor/cmapeditor.cpp index 938ca8c51..cd4378dfb 100644 --- a/src/eepp/gaming/mapeditor/cmapeditor.cpp +++ b/src/eepp/gaming/mapeditor/cmapeditor.cpp @@ -329,7 +329,7 @@ void cMapEditor::CreateLightContainer() { mUIRedSlider->Value( 255 ); mUIRedSlider->AddEventListener( cUIEvent::EventOnValueChange, cb::Make1( this, &cMapEditor::OnRedChange ) ); - mUIRedTxt = mTheme->CreateTextBox( toStr( (Uint32)255 ), mLightCont, eeSize(), eeVector2i( mUIRedSlider->Pos().x + mUIRedSlider->Size().Width() + 4, mUIRedSlider->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); + mUIRedTxt = mTheme->CreateTextBox( String::toStr( (Uint32)255 ), mLightCont, eeSize(), eeVector2i( mUIRedSlider->Pos().x + mUIRedSlider->Size().Width() + 4, mUIRedSlider->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); Txt = mTheme->CreateTextBox( "G:", mLightCont, eeSize(), eeVector2i( mUIBaseColor->Pos().x + mUIBaseColor->Size().Width() + 4, mUIRedSlider->Pos().y + mUIRedSlider->Size().Height() + 4 ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); mUIGreenSlider = mTheme->CreateSlider( mLightCont, eeSize( 100, 20 ), eeVector2i( mUIRedSlider->Pos().x, Txt->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_AUTO_SIZE ); @@ -337,7 +337,7 @@ void cMapEditor::CreateLightContainer() { mUIGreenSlider->Value( 255 ); mUIGreenSlider->AddEventListener( cUIEvent::EventOnValueChange, cb::Make1( this, &cMapEditor::OnGreenChange ) ); - mUIGreenTxt = mTheme->CreateTextBox( toStr( (Uint32)255 ), mLightCont, eeSize(), eeVector2i( mUIGreenSlider->Pos().x + mUIGreenSlider->Size().Width() + 4, mUIGreenSlider->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); + mUIGreenTxt = mTheme->CreateTextBox( String::toStr( (Uint32)255 ), mLightCont, eeSize(), eeVector2i( mUIGreenSlider->Pos().x + mUIGreenSlider->Size().Width() + 4, mUIGreenSlider->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); Txt = mTheme->CreateTextBox( "B:", mLightCont, eeSize(), eeVector2i( mUIBaseColor->Pos().x + mUIBaseColor->Size().Width() + 4, mUIGreenSlider->Pos().y + mUIGreenSlider->Size().Height() + 4 ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); mUIBlueSlider = mTheme->CreateSlider( mLightCont, eeSize( 100, 20 ), eeVector2i( mUIRedSlider->Pos().x, Txt->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_AUTO_SIZE ); @@ -345,7 +345,7 @@ void cMapEditor::CreateLightContainer() { mUIBlueSlider->Value( 255 ); mUIBlueSlider->AddEventListener( cUIEvent::EventOnValueChange, cb::Make1( this, &cMapEditor::OnBlueChange ) ); - mUIBlueTxt = mTheme->CreateTextBox( toStr( (Uint32)255 ), mLightCont, eeSize(), eeVector2i( mUIBlueSlider->Pos().x + mUIBlueSlider->Size().Width() + 4, mUIBlueSlider->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); + mUIBlueTxt = mTheme->CreateTextBox( String::toStr( (Uint32)255 ), mLightCont, eeSize(), eeVector2i( mUIBlueSlider->Pos().x + mUIBlueSlider->Size().Width() + 4, mUIBlueSlider->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); Txt = mTheme->CreateTextBox( "Light Radius:", mLightCont, eeSize(), eeVector2i( 0, mUIBlueTxt->Pos().y + mUIBlueTxt->Size().Height() + 16 ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); @@ -428,7 +428,7 @@ void cMapEditor::OnRedChange( const cUIEvent * Event ) { eeColorA Col = mUIBaseColor->Background()->Color(); Col.Red = (Uint8)mUIRedSlider->Value(); mUIBaseColor->Background()->Color( Col ); - mUIRedTxt->Text( toStr( (Int32)mUIRedSlider->Value() ) ); + mUIRedTxt->Text( String::toStr( (Int32)mUIRedSlider->Value() ) ); if ( NULL != mUIMap->GetSelectedLight() ) { eeColor lCol( mUIMap->GetSelectedLight()->Color() ); @@ -441,7 +441,7 @@ void cMapEditor::OnGreenChange( const cUIEvent * Event ) { eeColorA Col = mUIBaseColor->Background()->Color(); Col.Green = (Uint8)mUIGreenSlider->Value(); mUIBaseColor->Background()->Color( Col ); - mUIGreenTxt->Text( toStr( (Uint32)mUIGreenSlider->Value() ) ); + mUIGreenTxt->Text( String::toStr( (Uint32)mUIGreenSlider->Value() ) ); if ( NULL != mUIMap->GetSelectedLight() ) { eeColor lCol( mUIMap->GetSelectedLight()->Color() ); @@ -454,7 +454,7 @@ void cMapEditor::OnBlueChange( const cUIEvent * Event ) { eeColorA Col = mUIBaseColor->Background()->Color(); Col.Blue = (Uint8)mUIBlueSlider->Value(); mUIBaseColor->Background()->Color( Col ); - mUIBlueTxt->Text( toStr( (Uint32)mUIBlueSlider->Value() ) ); + mUIBlueTxt->Text( String::toStr( (Uint32)mUIBlueSlider->Value() ) ); if ( NULL != mUIMap->GetSelectedLight() ) { eeColor lCol( mUIMap->GetSelectedLight()->Color() ); @@ -993,7 +993,7 @@ void cMapEditor::RefreshLayersList() { void cMapEditor::TextureGroupOpen( const cUIEvent * Event ) { cUICommonDialog * CDL = reinterpret_cast ( Event->Ctrl() ); - std::string sgname = FileRemoveExtension( FileNameFromPath( CDL->GetFullPath() ) ); + std::string sgname = FileSystem::FileRemoveExtension( FileSystem::FileNameFromPath( CDL->GetFullPath() ) ); cShapeGroup * SG = cShapeGroupManager::instance()->GetByName( sgname ); @@ -1055,7 +1055,7 @@ cGameObject * cMapEditor::CreateGameObject() { if ( mChkAnim->Active() ) { - cSprite * tAnimSprite = eeNew( cSprite, ( RemoveNumbersAtEnd( mGfxPreview->Shape()->Name() ) ) ); + cSprite * tAnimSprite = eeNew( cSprite, ( String::RemoveNumbersAtEnd( mGfxPreview->Shape()->Name() ) ) ); tObj = eeNew( cGameObjectSprite, ( mCurGOFlags, mCurLayer, tAnimSprite ) ); } else { diff --git a/src/eepp/gaming/mapeditor/cmapproperties.cpp b/src/eepp/gaming/mapeditor/cmapproperties.cpp index e2041ba77..58d868f17 100644 --- a/src/eepp/gaming/mapeditor/cmapproperties.cpp +++ b/src/eepp/gaming/mapeditor/cmapproperties.cpp @@ -47,7 +47,7 @@ cMapProperties::cMapProperties( cMap * Map ) : mUIRedSlider->Value( mMap->BaseColor().R() ); mUIRedSlider->AddEventListener( cUIEvent::EventOnValueChange, cb::Make1( this, &cMapProperties::OnRedChange ) ); - mUIRedTxt = mUITheme->CreateTextBox( toStr( (Uint32)mMap->BaseColor().R() ), mUIWindow->Container(), eeSize(), eeVector2i( mUIRedSlider->Pos().x + mUIRedSlider->Size().Width() + 4, mUIRedSlider->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); + mUIRedTxt = mUITheme->CreateTextBox( String::toStr( (Uint32)mMap->BaseColor().R() ), mUIWindow->Container(), eeSize(), eeVector2i( mUIRedSlider->Pos().x + mUIRedSlider->Size().Width() + 4, mUIRedSlider->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); Txt = mUITheme->CreateTextBox( "Green Color:", mUIWindow->Container(), eeSize(), eeVector2i( mUIBaseColor->Pos().x + mUIBaseColor->Size().Width() + 4, mUIRedSlider->Pos().y + mUIRedSlider->Size().Height() + 4 ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); mUIGreenSlider = mUITheme->CreateSlider( mUIWindow->Container(), eeSize( 255, 20 ), eeVector2i( mUIRedSlider->Pos().x, Txt->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_AUTO_SIZE ); @@ -55,7 +55,7 @@ cMapProperties::cMapProperties( cMap * Map ) : mUIGreenSlider->Value( mMap->BaseColor().G() ); mUIGreenSlider->AddEventListener( cUIEvent::EventOnValueChange, cb::Make1( this, &cMapProperties::OnGreenChange ) ); - mUIGreenTxt = mUITheme->CreateTextBox( toStr( (Uint32)mMap->BaseColor().G() ), mUIWindow->Container(), eeSize(), eeVector2i( mUIGreenSlider->Pos().x + mUIGreenSlider->Size().Width() + 4, mUIGreenSlider->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); + mUIGreenTxt = mUITheme->CreateTextBox( String::toStr( (Uint32)mMap->BaseColor().G() ), mUIWindow->Container(), eeSize(), eeVector2i( mUIGreenSlider->Pos().x + mUIGreenSlider->Size().Width() + 4, mUIGreenSlider->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); Txt = mUITheme->CreateTextBox( "Blue Color:", mUIWindow->Container(), eeSize(), eeVector2i( mUIBaseColor->Pos().x + mUIBaseColor->Size().Width() + 4, mUIGreenSlider->Pos().y + mUIGreenSlider->Size().Height() + 4 ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); mUIBlueSlider = mUITheme->CreateSlider( mUIWindow->Container(), eeSize( 255, 20 ), eeVector2i( mUIRedSlider->Pos().x, Txt->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_AUTO_SIZE ); @@ -63,7 +63,7 @@ cMapProperties::cMapProperties( cMap * Map ) : mUIBlueSlider->Value( mMap->BaseColor().B() ); mUIBlueSlider->AddEventListener( cUIEvent::EventOnValueChange, cb::Make1( this, &cMapProperties::OnBlueChange ) ); - mUIBlueTxt = mUITheme->CreateTextBox( toStr( (Uint32)mMap->BaseColor().B() ), mUIWindow->Container(), eeSize(), eeVector2i( mUIBlueSlider->Pos().x + mUIBlueSlider->Size().Width() + 4, mUIBlueSlider->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); + mUIBlueTxt = mUITheme->CreateTextBox( String::toStr( (Uint32)mMap->BaseColor().B() ), mUIWindow->Container(), eeSize(), eeVector2i( mUIBlueSlider->Pos().x + mUIBlueSlider->Size().Width() + 4, mUIBlueSlider->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); } Uint32 TxtBoxFlags = UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_HALIGN_CENTER | UI_VALIGN_CENTER; @@ -125,7 +125,7 @@ void cMapProperties::OnRedChange( const cUIEvent * Event ) { eeColorA Col = mUIBaseColor->Background()->Color(); Col.Red = (Uint8)mUIRedSlider->Value(); mUIBaseColor->Background()->Color( Col ); - mUIRedTxt->Text( toStr( (Int32)mUIRedSlider->Value() ) ); + mUIRedTxt->Text( String::toStr( (Int32)mUIRedSlider->Value() ) ); eeColorA MapCol = mMap->BaseColor(); MapCol.Red = Col.Red; @@ -136,7 +136,7 @@ void cMapProperties::OnGreenChange( const cUIEvent * Event ) { eeColorA Col = mUIBaseColor->Background()->Color(); Col.Green = (Uint8)mUIGreenSlider->Value(); mUIBaseColor->Background()->Color( Col ); - mUIGreenTxt->Text( toStr( (Uint32)mUIGreenSlider->Value() ) ); + mUIGreenTxt->Text( String::toStr( (Uint32)mUIGreenSlider->Value() ) ); eeColorA MapCol = mMap->BaseColor(); MapCol.Green = Col.Green; @@ -147,7 +147,7 @@ void cMapProperties::OnBlueChange( const cUIEvent * Event ) { eeColorA Col = mUIBaseColor->Background()->Color(); Col.Blue = (Uint8)mUIBlueSlider->Value(); mUIBaseColor->Background()->Color( Col ); - mUIBlueTxt->Text( toStr( (Uint32)mUIBlueSlider->Value() ) ); + mUIBlueTxt->Text( String::toStr( (Uint32)mUIBlueSlider->Value() ) ); eeColorA MapCol = mMap->BaseColor(); MapCol.Blue = Col.Blue; diff --git a/src/eepp/gaming/mapeditor/cuilayernew.cpp b/src/eepp/gaming/mapeditor/cuilayernew.cpp index f06bc362f..98cbefa0a 100644 --- a/src/eepp/gaming/mapeditor/cuilayernew.cpp +++ b/src/eepp/gaming/mapeditor/cuilayernew.cpp @@ -30,7 +30,7 @@ cUILayerNew::cUILayerNew( cUIMap * Map, EE_LAYER_TYPE Type, NewLayerCb newLayerC cUITextBox * Txt = mTheme->CreateTextBox( "Layer Name", mUIWindow->Container(), eeSize(), eeVector2i( 16, InitialY ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); mUILayerName = mTheme->CreateTextInput( mUIWindow->Container(), eeSize( 120, 22 ), eeVector2i( Txt->Pos().x + DistFromTitle, Txt->Pos().y + DistFromTitle ), UI_CONTROL_DEFAULT_FLAGS | UI_CLIP_ENABLE | UI_AUTO_PADDING | UI_AUTO_SIZE, true, 64 ); - mUILayerName->Text( "Layer " + toStr( mUIMap->Map()->LayerCount() + 1 ) ); + mUILayerName->Text( "Layer " + String::toStr( mUIMap->Map()->LayerCount() + 1 ) ); cUIPushButton * OKButton = mTheme->CreatePushButton( mUIWindow->Container(), eeSize( 80, 22 ), eeVector2i(), UI_CONTROL_DEFAULT_FLAGS_CENTERED | UI_AUTO_SIZE, mTheme->GetIconByName( "add" ) ); OKButton->Pos( mUIWindow->Container()->Size().Width() - OKButton->Size().Width() - 4, mUIWindow->Container()->Size().Height() - OKButton->Size().Height() - 4 ); diff --git a/src/eepp/gaming/mapeditor/cuimapnew.cpp b/src/eepp/gaming/mapeditor/cuimapnew.cpp index 2dbc7af6a..f25e39789 100644 --- a/src/eepp/gaming/mapeditor/cuimapnew.cpp +++ b/src/eepp/gaming/mapeditor/cuimapnew.cpp @@ -86,7 +86,7 @@ cUIMapNew::cUIMapNew( cUIMap * Map, cb::Callback0 NewMapCb ) : mUIRedSlider->Value( 255 ); mUIRedSlider->AddEventListener( cUIEvent::EventOnValueChange, cb::Make1( this, &cUIMapNew::OnRedChange ) ); - mUIRedTxt = mTheme->CreateTextBox( toStr( 255 ), mUIWindow->Container(), eeSize(), eeVector2i( mUIRedSlider->Pos().x + mUIRedSlider->Size().Width() + 4, mUIRedSlider->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); + mUIRedTxt = mTheme->CreateTextBox( String::toStr( 255 ), mUIWindow->Container(), eeSize(), eeVector2i( mUIRedSlider->Pos().x + mUIRedSlider->Size().Width() + 4, mUIRedSlider->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); Txt = mTheme->CreateTextBox( "Green Color:", mUIWindow->Container(), eeSize(), eeVector2i( mUIBaseColor->Pos().x + mUIBaseColor->Size().Width() + 4, mUIRedSlider->Pos().y + mUIRedSlider->Size().Height() + 4 ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); @@ -95,7 +95,7 @@ cUIMapNew::cUIMapNew( cUIMap * Map, cb::Callback0 NewMapCb ) : mUIGreenSlider->Value( 255 ); mUIGreenSlider->AddEventListener( cUIEvent::EventOnValueChange, cb::Make1( this, &cUIMapNew::OnGreenChange ) ); - mUIGreenTxt = mTheme->CreateTextBox( toStr( 255 ), mUIWindow->Container(), eeSize(), eeVector2i( mUIGreenSlider->Pos().x + mUIGreenSlider->Size().Width() + 4, mUIGreenSlider->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); + mUIGreenTxt = mTheme->CreateTextBox( String::toStr( 255 ), mUIWindow->Container(), eeSize(), eeVector2i( mUIGreenSlider->Pos().x + mUIGreenSlider->Size().Width() + 4, mUIGreenSlider->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); Txt = mTheme->CreateTextBox( "Blue Color:", mUIWindow->Container(), eeSize(), eeVector2i( mUIBaseColor->Pos().x + mUIBaseColor->Size().Width() + 4, mUIGreenSlider->Pos().y + mUIGreenSlider->Size().Height() + 4 ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); @@ -104,7 +104,7 @@ cUIMapNew::cUIMapNew( cUIMap * Map, cb::Callback0 NewMapCb ) : mUIBlueSlider->Value( 255 ); mUIBlueSlider->AddEventListener( cUIEvent::EventOnValueChange, cb::Make1( this, &cUIMapNew::OnBlueChange ) ); - mUIBlueTxt = mTheme->CreateTextBox( toStr( 255 ), mUIWindow->Container(), eeSize(), eeVector2i( mUIBlueSlider->Pos().x + mUIBlueSlider->Size().Width() + 4, mUIBlueSlider->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); + mUIBlueTxt = mTheme->CreateTextBox( String::toStr( 255 ), mUIWindow->Container(), eeSize(), eeVector2i( mUIBlueSlider->Pos().x + mUIBlueSlider->Size().Width() + 4, mUIBlueSlider->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); cUIPushButton * OKButton = mTheme->CreatePushButton( mUIWindow->Container(), eeSize( 80, 22 ), eeVector2i(), UI_CONTROL_DEFAULT_FLAGS_CENTERED | UI_AUTO_SIZE, mTheme->GetIconByName( "ok" ) ); OKButton->Pos( mUIWindow->Container()->Size().Width() - OKButton->Size().Width() - 4, mUIWindow->Container()->Size().Height() - OKButton->Size().Height() - 4 ); @@ -126,21 +126,21 @@ void cUIMapNew::OnRedChange( const cUIEvent * Event ) { eeColorA Col = mUIBaseColor->Background()->Color(); Col.Red = (Uint8)mUIRedSlider->Value(); mUIBaseColor->Background()->Color( Col ); - mUIRedTxt->Text( toStr( (Int32)mUIRedSlider->Value() ) ); + mUIRedTxt->Text( String::toStr( (Int32)mUIRedSlider->Value() ) ); } void cUIMapNew::OnGreenChange( const cUIEvent * Event ) { eeColorA Col = mUIBaseColor->Background()->Color(); Col.Green = (Uint8)mUIGreenSlider->Value(); mUIBaseColor->Background()->Color( Col ); - mUIGreenTxt->Text( toStr( (Uint32)mUIGreenSlider->Value() ) ); + mUIGreenTxt->Text( String::toStr( (Uint32)mUIGreenSlider->Value() ) ); } void cUIMapNew::OnBlueChange( const cUIEvent * Event ) { eeColorA Col = mUIBaseColor->Background()->Color(); Col.Blue = (Uint8)mUIBlueSlider->Value(); mUIBaseColor->Background()->Color( Col ); - mUIBlueTxt->Text( toStr( (Uint32)mUIBlueSlider->Value() ) ); + mUIBlueTxt->Text( String::toStr( (Uint32)mUIBlueSlider->Value() ) ); } void cUIMapNew::OKClick( const cUIEvent * Event ) { diff --git a/src/eepp/graphics/cconsole.cpp b/src/eepp/graphics/cconsole.cpp index 728251d2b..d6deb479e 100755 --- a/src/eepp/graphics/cconsole.cpp +++ b/src/eepp/graphics/cconsole.cpp @@ -178,7 +178,7 @@ void cConsole::Draw() { if ( mShowFps ) { eeColorA OldColor1( mFont->Color() ); mFont->Color( eeColorA () ); - mFont->SetText( "FPS: " + toStr( mWindow->FPS() ) ); + mFont->SetText( "FPS: " + String::toStr( mWindow->FPS() ) ); mFont->Draw( mWindow->GetWidth() - mFont->GetTextWidth() - 15, 6 ); mFont->Color( OldColor1 ); } @@ -205,7 +205,7 @@ void cConsole::FadeOut() { void cConsole::ProcessLine() { String str = mTBuf.Buffer(); - std::vector < String > params = SplitString( str, ' ' ); + std::vector < String > params = String::SplitString( str, ' ' ); mLastCommands.push_back( str ); mLastLogPos = (eeInt)mLastCommands.size(); @@ -245,11 +245,7 @@ void cConsole::PushText( const char * format, ... ) { while (1) { va_start( args, format ); - #ifdef EE_COMPILER_MSVC - n = _vsnprintf_s( &tstr[0], size, size, format, args ); - #else - n = vsnprintf( &tstr[0], size, format, args ); - #endif + n = eevsnprintf( &tstr[0], size, format, args ); va_end( args ); @@ -330,7 +326,7 @@ void cConsole::PrintCommandsStartingWith( const String& start ) { std::map < String, ConsoleCallback >::iterator it; for ( it = mCallbacks.begin(); it != mCallbacks.end(); it++ ) { - if ( -1 != StrStartsWith( start, it->first ) ) { + if ( -1 != String::StrStartsWith( start, it->first ) ) { cmds.push_back( it->first ); } } @@ -479,7 +475,7 @@ void cConsole::CmdQuit ( const std::vector < String >& params ) { } void cConsole::CmdGetTextureMemory ( const std::vector < String >& params ) { - PushText( "Total texture memory used: " + SizeToString( cTextureFactory::instance()->MemorySize() ) ); + PushText( "Total texture memory used: " + FileSystem::SizeToString( cTextureFactory::instance()->MemorySize() ) ); } void cConsole::CmdCmdList ( const std::vector < String >& params ) { @@ -493,11 +489,11 @@ void cConsole::CmdShowCursor ( const std::vector < String >& params ) { if ( params.size() >= 2 ) { Int32 tInt = 0; - bool Res = fromString( tInt, params[1] ); + bool Res = String::fromString( tInt, params[1] ); if ( Res && ( tInt == 0 || tInt == 1 ) ) { mWindow->GetCursorManager()->Visible( 0 != tInt ); - PushText( "showcursor " + toStr( tInt ) ); + PushText( "showcursor " + String::toStr( tInt ) ); } else PushText( "Valid parameters are 0 or 1." ); } else { @@ -509,11 +505,11 @@ void cConsole::CmdFrameLimit ( const std::vector < String >& params ) { if ( params.size() >= 2 ) { Int32 tInt = 0; - bool Res = fromString( tInt, params[1] ); + bool Res = String::fromString( tInt, params[1] ); if ( Res && ( tInt >= 0 && tInt <= 10000 ) ) { mWindow->FrameRateLimit( tInt ); - PushText( "setfpslimit " + toStr( tInt ) ); + PushText( "setfpslimit " + String::toStr( tInt ) ); return; } } @@ -522,7 +518,7 @@ void cConsole::CmdFrameLimit ( const std::vector < String >& params ) { } void cConsole::CmdGetLog() { - std::vector < String > tvec = SplitString( String( toStr( cLog::instance()->Buffer() ) ) ); + std::vector < String > tvec = String::SplitString( String( String::toStr( cLog::instance()->Buffer() ) ) ); if ( tvec.size() > 0 ) { for ( eeUint i = 0; i < tvec.size(); i++ ) PushText( tvec[i] ); @@ -535,7 +531,7 @@ void cConsole::CmdGetLog( const std::vector < String >& params ) { void cConsole::CmdGetGpuExtensions() { char *Exts = GLi->GetExtensions(); - std::vector < String > tvec = SplitString( String( toStr( std::string( Exts ) ) ), ' ' ); + std::vector < String > tvec = String::SplitString( String( String::toStr( std::string( Exts ) ) ), ' ' ); if ( tvec.size() > 0 ) { for ( eeUint i = 0; i < tvec.size(); i++ ) PushText( tvec[i] ); @@ -550,11 +546,11 @@ void cConsole::CmdSetGamma( const std::vector < String >& params ) { if ( params.size() >= 2 ) { eeFloat tFloat = 0.f; - bool Res = fromString( tFloat, params[1] ); + bool Res = String::fromString( tFloat, params[1] ); if ( Res && ( tFloat > 0.1f && tFloat <= 10.0f ) ) { mWindow->SetGamma( tFloat, tFloat, tFloat ); - PushText( "setgamma " + toStr( tFloat ) ); + PushText( "setgamma " + String::toStr( tFloat ) ); return; } } @@ -566,11 +562,11 @@ void cConsole::CmdSetVolume( const std::vector < String >& params ) { if ( params.size() >= 2 ) { eeFloat tFloat = 0.f; - bool Res = fromString( tFloat, params[1] ); + bool Res = String::fromString( tFloat, params[1] ); if ( Res && ( tFloat >= 0.0f && tFloat <= 100.0f ) ) { EE::Audio::cAudioListener::GlobalVolume( tFloat ); - PushText( "setvolume " + toStr( tFloat ) ); + PushText( "setvolume " + String::toStr( tFloat ) ); return; } } @@ -601,10 +597,10 @@ void cConsole::CmdDir( const std::vector < String >& params ) { } } - if ( IsDirectory( myPath ) ) { + if ( FileSystem::IsDirectory( myPath ) ) { eeUint i; - std::vector mFiles = FilesGetInPath( myPath ); + std::vector mFiles = FileSystem::FilesGetInPath( myPath ); std::sort( mFiles.begin(), mFiles.end() ); PushText( "Directory: " + myPath ); @@ -614,7 +610,7 @@ void cConsole::CmdDir( const std::vector < String >& params ) { std::vector mFile; for ( i = 0; i < mFiles.size(); i++ ) { - if ( IsDirectory( myPath + Slash + mFiles[i] ) ) { + if ( FileSystem::IsDirectory( myPath + Slash + mFiles[i] ) ) { mFolders.push_back( mFiles[i] ); } else { mFile.push_back( mFiles[i] ); @@ -652,11 +648,11 @@ void cConsole::CmdShowFps( const std::vector < String >& params ) { if ( params.size() >= 2 ) { Int32 tInt = 0; - bool Res = fromString( tInt, params[1] ); + bool Res = String::fromString( tInt, params[1] ); if ( Res && ( tInt == 0 || tInt == 1 ) ) { mShowFps = 0 != tInt; - PushText( "showfps " + toStr( tInt ) ); + PushText( "showfps " + String::toStr( tInt ) ); return; } } diff --git a/src/eepp/graphics/cshader.cpp b/src/eepp/graphics/cshader.cpp index d5c326b3b..11bed5c6a 100644 --- a/src/eepp/graphics/cshader.cpp +++ b/src/eepp/graphics/cshader.cpp @@ -14,12 +14,12 @@ cShader::cShader( const Uint32& Type ) { cShader::cShader( const Uint32& Type, const std::string& Filename ) { Init( Type ); - mFilename = FileNameFromPath( Filename ); + mFilename = FileSystem::FileNameFromPath( Filename ); - if ( FileExists( Filename ) ) { + if ( FileSystem::FileExists( Filename ) ) { SafeDataPointer PData; - FileGet( Filename, PData ); + FileSystem::FileGet( Filename, PData ); SetSource( (const char*)PData.Data, PData.DataSize ); } else { @@ -53,7 +53,7 @@ cShader::cShader( const Uint32& Type, cPack * Pack, const std::string& Filename Init( Type ); - mFilename = FileNameFromPath( Filename ); + mFilename = FileSystem::FileNameFromPath( Filename ); if ( NULL != Pack && Pack->IsOpen() && -1 != Pack->Exists( Filename ) ) { Pack->ExtractFileToMemory( Filename, PData ); @@ -105,7 +105,7 @@ std::string cShader::GetName() { if ( mFilename.size() ) { name = mFilename; } else { - name = toStr( mGLId ); + name = String::toStr( mGLId ); } return name; @@ -129,8 +129,8 @@ void cShader::EnsureVersion() { mSource = "#ifdef GL_ES\nprecision mediump float;\nprecision lowp int;\n#endif\nvarying vec4 gl_Color;\nvarying vec4 gl_TexCoord[ 1 ];\n" + mSource; - ReplaceSubStr( mSource, "gl_Color" , "dgl_Color" ); - ReplaceSubStr( mSource, "gl_TexCoord" , "dgl_TexCoord" ); + String::ReplaceSubStr( mSource, "gl_Color" , "dgl_Color" ); + String::ReplaceSubStr( mSource, "gl_TexCoord" , "dgl_TexCoord" ); } } diff --git a/src/eepp/graphics/cshaderprogram.cpp b/src/eepp/graphics/cshaderprogram.cpp index 4e9ea5f09..f02765977 100644 --- a/src/eepp/graphics/cshaderprogram.cpp +++ b/src/eepp/graphics/cshaderprogram.cpp @@ -429,7 +429,7 @@ void cShaderProgram::Name( const std::string& name ) { Uint32 NameCount = cShaderProgramManager::instance()->Exists( mName ); if ( 0 != NameCount || 0 == name.size() ) { - Name( name + toStr( NameCount + 1 ) ); + Name( name + String::toStr( NameCount + 1 ) ); } } diff --git a/src/eepp/graphics/cshapegroupmanager.cpp b/src/eepp/graphics/cshapegroupmanager.cpp index ada8983b5..85807847a 100644 --- a/src/eepp/graphics/cshapegroupmanager.cpp +++ b/src/eepp/graphics/cshapegroupmanager.cpp @@ -61,11 +61,11 @@ std::vector cShapeGroupManager::GetShapesByPatternId( const Uint32& Sha if ( NULL != tShape ) { if ( extension.size() ) - tName = RemoveNumbersAtEnd( FileRemoveExtension( tShape->Name() ) ) + extension; + tName = String::RemoveNumbersAtEnd( FileSystem::FileRemoveExtension( tShape->Name() ) ) + extension; else tName = tShape->Name(); - return GetShapesByPattern( RemoveNumbersAtEnd( tShape->Name() ), "", SearchInShapeGroup ); + return GetShapesByPattern( String::RemoveNumbersAtEnd( tShape->Name() ), "", SearchInShapeGroup ); } return std::vector(); @@ -94,7 +94,7 @@ std::vector cShapeGroupManager::GetShapesByPattern( const std::string& // Test if name starts with 0 - 1 for ( i = 0; i < 2; i++ ) { - search = StrFormated( "%s%d%s", name.c_str(), i, realext.c_str() ); + search = String::StrFormated( "%s%d%s", name.c_str(), i, realext.c_str() ); if ( NULL == SearchInShapeGroup ) tShape = GetShapeByName( search ); @@ -111,7 +111,7 @@ std::vector cShapeGroupManager::GetShapesByPattern( const std::string& // in case that name doesn't start with 0 - 1, we test with 00 - 01 if ( 0 == t ) { for ( i = 0; i < 2; i++ ) { - search = StrFormated( "%s%02d%s", name.c_str(), i, realext.c_str() ); + search = String::StrFormated( "%s%02d%s", name.c_str(), i, realext.c_str() ); if ( NULL == SearchInShapeGroup ) tShape = GetShapeByName( search ); @@ -128,7 +128,7 @@ std::vector cShapeGroupManager::GetShapesByPattern( const std::string& // in case that name doesn't start with 00 - 01, we test with 000 - 001 if ( 0 == t ) { for ( i = 0; i < 2; i++ ) { - search = StrFormated( "%s%03d%s", name.c_str(), i, realext.c_str() ); + search = String::StrFormated( "%s%03d%s", name.c_str(), i, realext.c_str() ); if ( NULL == SearchInShapeGroup ) tShape = GetShapeByName( search ); @@ -144,7 +144,7 @@ std::vector cShapeGroupManager::GetShapesByPattern( const std::string& if ( 0 == t ) { for ( i = 0; i < 2; i++ ) { - search = StrFormated( "%s%04d%s", name.c_str(), i, realext.c_str() ); + search = String::StrFormated( "%s%04d%s", name.c_str(), i, realext.c_str() ); if ( NULL == SearchInShapeGroup ) tShape = GetShapeByName( search ); @@ -160,7 +160,7 @@ std::vector cShapeGroupManager::GetShapesByPattern( const std::string& if ( 0 == t ) { for ( i = 0; i < 2; i++ ) { - search = StrFormated( "%s%05d%s", name.c_str(), i, realext.c_str() ); + search = String::StrFormated( "%s%05d%s", name.c_str(), i, realext.c_str() ); if ( NULL == SearchInShapeGroup ) tShape = GetShapeByName( search ); @@ -176,7 +176,7 @@ std::vector cShapeGroupManager::GetShapesByPattern( const std::string& if ( 0 == t ) { for ( i = 0; i < 2; i++ ) { - search = StrFormated( "%s%06d%s", name.c_str(), i, realext.c_str() ); + search = String::StrFormated( "%s%06d%s", name.c_str(), i, realext.c_str() ); if ( NULL == SearchInShapeGroup ) tShape = GetShapeByName( search ); @@ -198,12 +198,12 @@ std::vector cShapeGroupManager::GetShapesByPattern( const std::string& if ( 0 != t ) { do { switch ( t ) { - case 1: search = StrFormated( "%s%d%s", name.c_str(), c, realext.c_str() ); break; - case 2: search = StrFormated( "%s%02d%s", name.c_str(), c, realext.c_str() ); break; - case 3: search = StrFormated( "%s%03d%s", name.c_str(), c, realext.c_str() ); break; - case 4: search = StrFormated( "%s%04d%s", name.c_str(), c, realext.c_str() ); break; - case 5: search = StrFormated( "%s%05d%s", name.c_str(), c, realext.c_str() ); break; - case 6: search = StrFormated( "%s%06d%s", name.c_str(), c, realext.c_str() ); break; + case 1: search = String::StrFormated( "%s%d%s", name.c_str(), c, realext.c_str() ); break; + case 2: search = String::StrFormated( "%s%02d%s", name.c_str(), c, realext.c_str() ); break; + case 3: search = String::StrFormated( "%s%03d%s", name.c_str(), c, realext.c_str() ); break; + case 4: search = String::StrFormated( "%s%04d%s", name.c_str(), c, realext.c_str() ); break; + case 5: search = String::StrFormated( "%s%05d%s", name.c_str(), c, realext.c_str() ); break; + case 6: search = String::StrFormated( "%s%06d%s", name.c_str(), c, realext.c_str() ); break; default: found = false; } diff --git a/src/eepp/graphics/ctexturefactory.cpp b/src/eepp/graphics/ctexturefactory.cpp index 68953f46a..b49122579 100755 --- a/src/eepp/graphics/ctexturefactory.cpp +++ b/src/eepp/graphics/ctexturefactory.cpp @@ -16,7 +16,7 @@ cTextureFactory::cTextureFactory() : mTextures.clear(); mTextures.push_back( NULL ); - mAppPath = GetProcessPath(); + mAppPath = Sys::GetProcessPath(); memset( &mCurrentTexture[0], 0, EE_MAX_TEXTURE_UNITS ); } @@ -64,7 +64,7 @@ Uint32 cTextureFactory::PushTexture( const std::string& Filepath, const Uint32& std::string FPath( Filepath ); - FilePathRemoveProcessPath( FPath ); + FileSystem::FilePathRemoveProcessPath( FPath ); Pos = FindFreeSlot(); Tex = mTextures[ Pos ] = eeNew( cTexture, () ); diff --git a/src/eepp/graphics/ctexturefont.cpp b/src/eepp/graphics/ctexturefont.cpp index 2b89f3363..777cc2c7b 100755 --- a/src/eepp/graphics/ctexturefont.cpp +++ b/src/eepp/graphics/ctexturefont.cpp @@ -131,7 +131,7 @@ void cTextureFont::BuildFromGlyphs() { } bool cTextureFont::Load( const Uint32& TexId, const std::string& CoordinatesDatPath, const bool& VerticalDraw ) { - if ( FileExists( CoordinatesDatPath ) ) { + if ( FileSystem::FileExists( CoordinatesDatPath ) ) { cIOStreamFile IOS( CoordinatesDatPath, std::ios::in | std::ios::binary ); return LoadFromStream( TexId, IOS, VerticalDraw ); diff --git a/src/eepp/graphics/ctexturegrouploader.cpp b/src/eepp/graphics/ctexturegrouploader.cpp index fe4deefa0..400419094 100644 --- a/src/eepp/graphics/ctexturegrouploader.cpp +++ b/src/eepp/graphics/ctexturegrouploader.cpp @@ -15,7 +15,7 @@ using namespace Private; cTextureGroupLoader::cTextureGroupLoader() : mThreaded(false), mLoaded(false), - mAppPath( GetProcessPath() ), + mAppPath( Sys::GetProcessPath() ), mPack(NULL), mSkipResourceLoad(false), mIsLoading(false), @@ -27,7 +27,7 @@ cTextureGroupLoader::cTextureGroupLoader( const std::string& TextureGroupPath, c mTextureGroupPath( TextureGroupPath ), mThreaded( Threaded ), mLoaded(false), - mAppPath( GetProcessPath() ), + mAppPath( Sys::GetProcessPath() ), mPack(NULL), mSkipResourceLoad(false), mIsLoading(false), @@ -41,7 +41,7 @@ cTextureGroupLoader::cTextureGroupLoader( const Uint8* Data, const Uint32& DataS mTextureGroupPath( TextureGroupName ), mThreaded( Threaded ), mLoaded(false), - mAppPath( GetProcessPath() ), + mAppPath( Sys::GetProcessPath() ), mPack(NULL), mSkipResourceLoad(false), mIsLoading(false), @@ -55,7 +55,7 @@ cTextureGroupLoader::cTextureGroupLoader( cPack * Pack, const std::string& FileP mTextureGroupPath( FilePackPath ), mThreaded( Threaded ), mLoaded(false), - mAppPath( GetProcessPath() ), + mAppPath( Sys::GetProcessPath() ), mPack(NULL), mSkipResourceLoad(false), mIsLoading(false), @@ -97,7 +97,7 @@ void cTextureGroupLoader::LoadFromStream( cIOStream& IOS ) { tTexGroup.Shapes.resize( tTextureHdr.ShapeCount ); std::string name( &tTextureHdr.Name[0] ); - std::string path( FileRemoveFileName( mTextureGroupPath ) + name ); + std::string path( FileSystem::FileRemoveFileName( mTextureGroupPath ) + name ); //! Checks if the texture is already loaded cTexture * tTex = cTextureFactory::instance()->GetByName( path ); @@ -130,7 +130,7 @@ void cTextureGroupLoader::Load( const std::string& TextureGroupPath ) { if ( TextureGroupPath.size() ) mTextureGroupPath = TextureGroupPath; - if ( FileExists( mTextureGroupPath ) ) { + if ( FileSystem::FileExists( mTextureGroupPath ) ) { cIOStreamFile IOS( mTextureGroupPath, std::ios::in | std::ios::binary ); LoadFromStream( IOS ); @@ -179,9 +179,9 @@ void cTextureGroupLoader::CreateShapes() { sTextureHdr * tTexHdr = &tTexGroup->Texture; std::string name( &tTexHdr->Name[0] ); - std::string path( FileRemoveFileName( mTextureGroupPath ) + name ); + std::string path( FileSystem::FileRemoveFileName( mTextureGroupPath ) + name ); - FilePathRemoveProcessPath( path ); + FileSystem::FilePathRemoveProcessPath( path ); cTexture * tTex = cTextureFactory::instance()->GetByName( path ); @@ -191,9 +191,9 @@ void cTextureGroupLoader::CreateShapes() { // Create the Shape Group with the name of the real texture, not the Childs ( example load 1.png and not 1_ch1.png ) if ( 0 == z ) { if ( mTexGrHdr.Flags & HDR_TEXTURE_GROUP_REMOVE_EXTENSION ) - name = FileRemoveExtension( name ); + name = FileSystem::FileRemoveExtension( name ); - std::string etgpath = FileRemoveExtension( path ) + ".etg"; + std::string etgpath = FileSystem::FileRemoveExtension( path ) + ".etg"; cShapeGroup * tShapeGroup = cShapeGroupManager::instance()->GetByName( name ); @@ -218,7 +218,7 @@ void cTextureGroupLoader::CreateShapes() { std::string ShapeName( &tSh->Name[0] ); if ( mTexGrHdr.Flags & HDR_TEXTURE_GROUP_REMOVE_EXTENSION ) - ShapeName = FileRemoveExtension( ShapeName ); + ShapeName = FileSystem::FileRemoveExtension( ShapeName ); eeRecti tRect( tSh->X, tSh->Y, tSh->X + tSh->Width, tSh->Y + tSh->Height ); @@ -314,10 +314,10 @@ bool cTextureGroupLoader::UpdateTextureAtlas() { } static bool IsImage( std::string path ) { - if ( FileSize( path ) ) { + if ( FileSystem::FileSize( path ) ) { std::string File = path.substr( path.find_last_of("/\\") + 1 ); std::string Ext = File.substr( File.find_last_of(".") + 1 ); - ToLower( Ext ); + String::ToLower( Ext ); if ( Ext == "png" || Ext == "tga" || @@ -345,7 +345,7 @@ static bool IsImage( std::string path ) { } bool cTextureGroupLoader::UpdateTextureAtlas( std::string TextureAtlasPath, std::string ImagesPath ) { - if ( !TextureAtlasPath.size() || !ImagesPath.size() || !FileExists( TextureAtlasPath ) || !IsDirectory( ImagesPath ) ) + if ( !TextureAtlasPath.size() || !ImagesPath.size() || !FileSystem::FileExists( TextureAtlasPath ) || !FileSystem::IsDirectory( ImagesPath ) ) return false; mSkipResourceLoad = true; @@ -359,7 +359,7 @@ bool cTextureGroupLoader::UpdateTextureAtlas( std::string TextureAtlasPath, std: Int32 NeedUpdate = 0; - DirPathAddSlashAtEnd( ImagesPath ); + FileSystem::DirPathAddSlashAtEnd( ImagesPath ); Uint32 z; @@ -368,7 +368,7 @@ bool cTextureGroupLoader::UpdateTextureAtlas( std::string TextureAtlasPath, std: totalShapes += mTempGroups[z].Texture.ShapeCount; Uint32 totalImages = 0; - std::vector PathFiles = FilesGetInPath( ImagesPath ); + std::vector PathFiles = FileSystem::FilesGetInPath( ImagesPath ); for ( z = 0; z < PathFiles.size(); z++ ) { std::string realpath( ImagesPath + PathFiles[z] ); @@ -391,8 +391,8 @@ bool cTextureGroupLoader::UpdateTextureAtlas( std::string TextureAtlasPath, std: std::string path( ImagesPath + tSh->Name ); - if ( FileSize( path ) ) { - if ( tSh->Date != FileGetModificationDate( path ) ) { + if ( FileSystem::FileSize( path ) ) { + if ( tSh->Date != FileSystem::FileGetModificationDate( path ) ) { if ( stbi_info( path.c_str(), &x, &y, &c ) ) { if ( ( !( tSh->Flags & HDR_SHAPE_FLAG_FLIPED ) && tSh->Width == x && tSh->Height == y ) || // If size or channels changed, the image need update ( ( tSh->Flags & HDR_SHAPE_FLAG_FLIPED ) && tSh->Width == y && tSh->Height == x ) || @@ -421,7 +421,7 @@ bool cTextureGroupLoader::UpdateTextureAtlas( std::string TextureAtlasPath, std: } if ( NeedUpdate ) { - std::string tapath( FileRemoveExtension( TextureAtlasPath ) + "." + cImage::SaveTypeToExtension( mTexGrHdr.Format ) ); + std::string tapath( FileSystem::FileRemoveExtension( TextureAtlasPath ) + "." + cImage::SaveTypeToExtension( mTexGrHdr.Format ) ); if ( 2 == NeedUpdate ) { cTexturePacker tp( mTexGrHdr.Width, mTexGrHdr.Height, 0 != ( mTexGrHdr.Flags & HDR_TEXTURE_GROUP_POW_OF_TWO ), mTexGrHdr.PixelBorder, mTexGrHdr.Flags & HDR_TEXTURE_GROUP_ALLOW_FLIPPING ); @@ -432,7 +432,7 @@ bool cTextureGroupLoader::UpdateTextureAtlas( std::string TextureAtlasPath, std: tp.Save( tapath, (EE_SAVE_TYPE)mTexGrHdr.Format ); } else if ( 1 == NeedUpdate ) { - std::string etgpath = FileRemoveExtension( tapath ) + ".etg"; + std::string etgpath = FileSystem::FileRemoveExtension( tapath ) + ".etg"; cIOStreamFile fs( etgpath , std::ios::out | std::ios::binary ); @@ -443,7 +443,7 @@ bool cTextureGroupLoader::UpdateTextureAtlas( std::string TextureAtlasPath, std: for ( Uint32 z = 0; z < mTempGroups.size(); z++ ) { if ( z != 0 ) { - tapath = FileRemoveExtension( TextureAtlasPath ) + "_ch" + toStr( z ) + "." + cImage::SaveTypeToExtension( mTexGrHdr.Format ); + tapath = FileSystem::FileRemoveExtension( TextureAtlasPath ) + "_ch" + String::toStr( z ) + "." + cImage::SaveTypeToExtension( mTexGrHdr.Format ); } unsigned char * imgPtr = stbi_load( tapath.c_str(), &x, &y, &c, 0 ); @@ -462,7 +462,7 @@ bool cTextureGroupLoader::UpdateTextureAtlas( std::string TextureAtlasPath, std: std::string imgcopypath( ImagesPath + tSh->Name ); - Uint32 ModifDate = FileGetModificationDate( imgcopypath ); + Uint32 ModifDate = FileSystem::FileGetModificationDate( imgcopypath ); if ( tSh->Date != ModifDate ) { tSh->Date = ModifDate; // Update the shape hdr diff --git a/src/eepp/graphics/ctextureloader.cpp b/src/eepp/graphics/ctextureloader.cpp index d56dfc479..a8531871e 100644 --- a/src/eepp/graphics/ctextureloader.cpp +++ b/src/eepp/graphics/ctextureloader.cpp @@ -153,14 +153,14 @@ void cTextureLoader::Start() { } void cTextureLoader::LoadFromPath() { - if ( FileExists( mFilepath ) ) { + if ( FileSystem::FileExists( mFilepath ) ) { if ( GLi->IsExtension( EEGL_EXT_texture_compression_s3tc ) ) mIsDDS = 0 != stbi_dds_test_filename( mFilepath.c_str() ); if ( mIsDDS ) { cIOStreamFile fs( mFilepath , std::ios::in | std::ios::binary ); - mSize = FileSize( mFilepath ); + mSize = FileSystem::FileSize( mFilepath ); mPixels = (Uint8*) eeMalloc( mSize ); diff --git a/src/eepp/graphics/ctexturepacker.cpp b/src/eepp/graphics/ctexturepacker.cpp index 67b7807f7..9ed5778c0 100644 --- a/src/eepp/graphics/ctexturepacker.cpp +++ b/src/eepp/graphics/ctexturepacker.cpp @@ -365,16 +365,16 @@ void cTexturePacker::CreateChild() { } bool cTexturePacker::AddTexturesPath( std::string TexturesPath ) { - if ( IsDirectory( TexturesPath ) ) { + if ( FileSystem::IsDirectory( TexturesPath ) ) { - DirPathAddSlashAtEnd( TexturesPath ); + FileSystem::DirPathAddSlashAtEnd( TexturesPath ); - std::vector files = FilesGetInPath( TexturesPath ); + std::vector files = FileSystem::FilesGetInPath( TexturesPath ); std::sort( files.begin(), files.end() ); for ( Uint32 i = 0; i < files.size(); i++ ) { std::string path( TexturesPath + files[i] ); - if ( !IsDirectory( path ) ) + if ( !FileSystem::IsDirectory( path ) ) AddTexture( path ); } @@ -385,7 +385,7 @@ bool cTexturePacker::AddTexturesPath( std::string TexturesPath ) { } bool cTexturePacker::AddTexture( const std::string& TexturePath ) { - if ( FileExists( TexturePath ) ) { + if ( FileSystem::FileExists( TexturePath ) ) { cTexturePackerTex TPack( TexturePath ); if ( TPack.LoadedInfo() ) { @@ -592,7 +592,7 @@ void cTexturePacker::SaveShapes() { std::vector tShapesHdr; - std::string path = FileRemoveExtension( mFilepath ) + ".etg"; + std::string path = FileSystem::FileRemoveExtension( mFilepath ) + ".etg"; cIOStreamFile fs ( path , std::ios::out | std::ios::binary ); if ( fs.IsOpen() ) { @@ -639,14 +639,14 @@ void cTexturePacker::CreateShapesHdr( cTexturePacker * Packer, std::vectorPlaced() ) { - std::string name = FileNameFromPath( tTex->Name() ); + std::string name = FileSystem::FileNameFromPath( tTex->Name() ); memset( tShapeHdr.Name, 0, HDR_NAME_SIZE ); - StrCopy( tShapeHdr.Name, name.c_str(), HDR_NAME_SIZE ); + String::StrCopy( tShapeHdr.Name, name.c_str(), HDR_NAME_SIZE ); if ( !mSaveExtensions ) - name = FileRemoveExtension( name ); + name = FileSystem::FileRemoveExtension( name ); tShapeHdr.ResourceID = MakeHash( name ); tShapeHdr.Width = tTex->Width(); @@ -658,7 +658,7 @@ void cTexturePacker::CreateShapesHdr( cTexturePacker * Packer, std::vectorX(); tShapeHdr.Y = tTex->Y(); - tShapeHdr.Date = FileGetModificationDate( tTex->Name() ); + tShapeHdr.Date = FileSystem::FileGetModificationDate( tTex->Name() ); tShapeHdr.Flags = 0; if ( tTex->Flipped() ) @@ -674,14 +674,14 @@ void cTexturePacker::CreateShapesHdr( cTexturePacker * Packer, std::vectorGetFilepath() ) ); + std::string name( FileSystem::FileNameFromPath( Packer->GetFilepath() ) ); memset( TexHdr.Name, 0, HDR_NAME_SIZE ); - StrCopy( TexHdr.Name, name.c_str(), HDR_NAME_SIZE ); + String::StrCopy( TexHdr.Name, name.c_str(), HDR_NAME_SIZE ); TexHdr.ResourceID = MakeHash( name ); - TexHdr.Size = FileSize( Packer->GetFilepath() ); + TexHdr.Size = FileSystem::FileSize( Packer->GetFilepath() ); TexHdr.ShapeCount = Packer->GetPlacedCount(); return TexHdr; @@ -700,9 +700,9 @@ void cTexturePacker::ChildSave( const EE_SAVE_TYPE& Format ) { Parent = Parent->GetParent(); } - std::string fFpath = FileRemoveExtension( LastParent->GetFilepath() ); - std::string fExt = FileExtension( LastParent->GetFilepath() ); - std::string fName = fFpath + "_ch" + toStr( ParentCount ) + "." + fExt; + std::string fFpath = FileSystem::FileRemoveExtension( LastParent->GetFilepath() ); + std::string fExt = FileSystem::FileExtension( LastParent->GetFilepath() ); + std::string fName = fFpath + "_ch" + String::toStr( ParentCount ) + "." + fExt; mChild->Save( fName, Format, mSaveExtensions ); } diff --git a/src/eepp/graphics/cttffont.cpp b/src/eepp/graphics/cttffont.cpp index af9ab40d9..36226a7fd 100755 --- a/src/eepp/graphics/cttffont.cpp +++ b/src/eepp/graphics/cttffont.cpp @@ -45,7 +45,7 @@ bool cTTFFont::LoadFromMemory( Uint8* TTFData, const eeUint& TTFDataSize, const bool cTTFFont::Load( const std::string& Filepath, const eeUint& Size, EE_TTF_FONTSTYLE Style, const bool& VerticalDraw, const Uint16& NumCharsToGen, const eeColor& FontColor, const Uint8& OutlineSize, const eeColor& OutlineColor, const bool& AddPixelSeparator ) { mFilepath = Filepath; - if ( FileExists( Filepath ) ) { + if ( FileSystem::FileExists( Filepath ) ) { mLoadedFromMemory = false; mFont = hkFontManager::instance()->OpenFromFile( Filepath.c_str(), Size, 0, NumCharsToGen ); @@ -286,7 +286,7 @@ bool cTTFFont::iLoad( const eeUint& Size, EE_TTF_FONTSTYLE Style, const bool& Ve void cTTFFont::UpdateLoading() { if ( mTexReady && NULL != mPixels ) { - std::string name( FileRemoveExtension( FileNameFromPath( mFilepath ) ) ); + std::string name( FileSystem::FileRemoveExtension( FileSystem::FileNameFromPath( mFilepath ) ) ); mTexId = cTextureFactory::instance()->LoadFromPixels( reinterpret_cast ( &mPixels[0] ), (Uint32)mTexWidth, (Uint32)mTexHeight, 4, false, EE_CLAMP_TO_EDGE, false, false, name ); diff --git a/src/eepp/graphics/renderer/crenderergl3.cpp b/src/eepp/graphics/renderer/crenderergl3.cpp index 5239ff7e1..7f72acadf 100644 --- a/src/eepp/graphics/renderer/crenderergl3.cpp +++ b/src/eepp/graphics/renderer/crenderergl3.cpp @@ -581,7 +581,7 @@ void cRendererGL3::ClipPlane( GLenum plane, const GLdouble * equation ) { if ( nplane < EE_MAX_PLANES ) { location = mPlanes[ nplane ]; } else { - std::string planeNum( "dgl_ClipPlane[" + toStr( nplane ) + "]" ); + std::string planeNum( "dgl_ClipPlane[" + String::toStr( nplane ) + "]" ); location = glGetUniformLocation( mCurShader->Handler(), (GLchar*)&planeNum[0] ); } diff --git a/src/eepp/graphics/renderer/crenderergles2.cpp b/src/eepp/graphics/renderer/crenderergles2.cpp index e6907819c..46fba68d4 100644 --- a/src/eepp/graphics/renderer/crenderergles2.cpp +++ b/src/eepp/graphics/renderer/crenderergles2.cpp @@ -663,7 +663,7 @@ void cRendererGLES2::ClipPlane( GLenum plane, const GLdouble * equation ) { if ( nplane < EE_MAX_PLANES ) { location = mPlanes[ nplane ]; } else { - std::string planeNum( "dgl_ClipPlane[" + toStr( nplane ) + "]" ); + std::string planeNum( "dgl_ClipPlane[" + String::toStr( nplane ) + "]" ); location = glGetUniformLocation( mCurShader->Handler(), (GLchar*)&planeNum[0] ); } diff --git a/src/eepp/math/math.cpp b/src/eepp/math/math.cpp index 8f95b4687..bfaa459ef 100755 --- a/src/eepp/math/math.cpp +++ b/src/eepp/math/math.cpp @@ -1,9 +1,11 @@ #include +#include +using namespace EE::System; namespace EE { namespace Math { Uint32 SetRandomSeed() { - Uint32 Seed = static_cast( GetSystemTime() * 1000 ); + Uint32 Seed = static_cast( Sys::GetSystemTime() * 1000 ); srand(Seed); return Seed; } diff --git a/src/eepp/system/cinifile.cpp b/src/eepp/system/cinifile.cpp index 067bccad7..407e5c778 100755 --- a/src/eepp/system/cinifile.cpp +++ b/src/eepp/system/cinifile.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include namespace EE { namespace System { @@ -51,7 +52,7 @@ bool cIniFile::LoadFromMemory( const Uint8* RAWData, const Uint32& size ) { myfile.assign( reinterpret_cast (RAWData), size ); mLines.clear(); - mLines = SplitString( myfile ); + mLines = String::SplitString( myfile ); mIniReaded = false; @@ -61,7 +62,7 @@ bool cIniFile::LoadFromMemory( const Uint8* RAWData, const Uint32& size ) { bool cIniFile::LoadFromFile( const std::string& iniPath ) { Path ( iniPath ); - if ( FileExists( iniPath ) ) { + if ( FileSystem::FileExists( iniPath ) ) { cIOStreamFile f( mPath, std::ios::in ); if ( !f.IsOpen() ) @@ -72,7 +73,7 @@ bool cIniFile::LoadFromFile( const std::string& iniPath ) { f.Read( (char*)&myfile[0], f.GetSize() ); mLines.clear(); - mLines = SplitString( myfile ); + mLines = String::SplitString( myfile ); mIniReaded = false; @@ -102,7 +103,7 @@ bool cIniFile::ReadFile() { return false; for ( Uint32 i = 0; i < mLines.size(); i++ ) { - line = LTrim ( mLines[i] ); + line = String::LTrim ( mLines[i] ); // To be compatible with Win32, check for existence of '\r'. // Win32 files have the '\r' and Unix files don't at the end of a line. @@ -130,8 +131,8 @@ bool cIniFile::ReadFile() { } break; case '=': - valuename = Trim( line.substr ( 0, pLeft ) ); // Remove the extra space between valuename and = . No spaced valuename permited. - value = LTrim( line.substr ( pLeft + 1 ) ); + valuename = String::Trim( line.substr ( 0, pLeft ) ); // Remove the extra space between valuename and = . No spaced valuename permited. + value = String::LTrim( line.substr ( pLeft + 1 ) ); SetValue ( keyname, valuename, value ); break; case ';': @@ -293,14 +294,14 @@ bool cIniFile::SetValue ( std::string const keyname, std::string const valuename bool cIniFile::SetValueI ( std::string const keyname, std::string const valuename, int const value, bool create ) { char svalue[MAX_VALUEDATA]; - StrFormat( svalue, MAX_VALUEDATA, "%d", value ); + String::StrFormat( svalue, MAX_VALUEDATA, "%d", value ); return SetValue ( keyname, valuename, svalue, create ); } bool cIniFile::SetValueF ( std::string const keyname, std::string const valuename, double const value, bool create ) { char svalue[MAX_VALUEDATA]; - StrFormat ( svalue, MAX_VALUEDATA, "%f", value ); + String::StrFormat ( svalue, MAX_VALUEDATA, "%f", value ); return SetValue ( keyname, valuename, svalue, create ); } @@ -339,14 +340,14 @@ std::string cIniFile::GetValue ( std::string const keyname, std::string const va int cIniFile::GetValueI ( std::string const keyname, std::string const valuename, int const defValue ) const { char svalue[MAX_VALUEDATA]; - StrFormat ( svalue, MAX_VALUEDATA, "%d", defValue ); + String::StrFormat ( svalue, MAX_VALUEDATA, "%d", defValue ); return atoi ( GetValue ( keyname, valuename, svalue ).c_str() ); } double cIniFile::GetValueF ( std::string const keyname, std::string const valuename, double const defValue ) const { char svalue[MAX_VALUEDATA]; - StrFormat ( svalue, MAX_VALUEDATA, "%f", defValue ); + String::StrFormat ( svalue, MAX_VALUEDATA, "%f", defValue ); return atof ( GetValue ( keyname, valuename, svalue ).c_str() ); } diff --git a/src/eepp/system/clog.cpp b/src/eepp/system/clog.cpp index c1aa39a10..b9c95f19a 100755 --- a/src/eepp/system/clog.cpp +++ b/src/eepp/system/clog.cpp @@ -12,11 +12,11 @@ cLog::cLog() : mFS( NULL ) { Write("...::: Entropia Engine++ Loaded :::..."); - Write( "Loaded on " + GetDateTimeStr() ); + Write( "Loaded on " + Sys::GetDateTimeStr() ); } cLog::~cLog() { - Write( "\nUnloaded on " + GetDateTimeStr(), false ); + Write( "\nUnloaded on " + Sys::GetDateTimeStr(), false ); Write( "...::: Entropia Engine++ Unloaded :::...\n" ); if ( mSave && !mLiveWrite ) { @@ -32,7 +32,7 @@ void cLog::Save( const std::string& filepath ) { if ( filepath.size() ) { mFilePath = filepath; } else { - mFilePath = GetProcessPath(); + mFilePath = Sys::GetProcessPath(); } mSave = true; @@ -76,7 +76,7 @@ void cLog::Write( const std::string& Text, const bool& newLine ) { void cLog::openfs() { if ( mFilePath.empty() ) { - mFilePath = GetProcessPath(); + mFilePath = Sys::GetProcessPath(); } closefs(); @@ -105,13 +105,7 @@ void cLog::Writef( const char* format, ... ) { while (1) { va_start( args, format ); - #ifdef EE_COMPILER_MSVC - n = _vsnprintf_s( &tstr[0], size, size, format, args ); - #else - n = vsnprintf( &tstr[0], size, format, args ); - #endif - - va_end( args ); + n = eevsnprintf( &tstr[0], size, format, args ); if ( n > -1 && n < size ) { tstr.resize( n ); diff --git a/src/eepp/system/cpackmanager.cpp b/src/eepp/system/cpackmanager.cpp index fa42c3acd..5421de22b 100644 --- a/src/eepp/system/cpackmanager.cpp +++ b/src/eepp/system/cpackmanager.cpp @@ -1,4 +1,5 @@ #include +#include namespace EE { namespace System { @@ -15,7 +16,7 @@ cPackManager::~cPackManager() { cPack * cPackManager::Exists( std::string& path ) { std::string tpath( path ); - FilePathRemoveProcessPath( tpath ); + FileSystem::FilePathRemoveProcessPath( tpath ); std::list::iterator it; diff --git a/src/eepp/system/cpak.cpp b/src/eepp/system/cpak.cpp index 9c7241f5c..bf79ee14c 100755 --- a/src/eepp/system/cpak.cpp +++ b/src/eepp/system/cpak.cpp @@ -1,4 +1,6 @@ #include +#include +#include namespace EE { namespace System { @@ -13,7 +15,7 @@ cPak::~cPak() { } bool cPak::Create( const std::string& path ) { - if ( !FileExists(path) ) { + if ( !FileSystem::FileExists(path) ) { pakFile Pak; Pak.header.head[0] = 'P'; @@ -43,7 +45,7 @@ bool cPak::Create( const std::string& path ) { } bool cPak::Open( const std::string& path ) { - if ( FileExists(path) ) { + if ( FileSystem::FileExists(path) ) { mPak.pakPath = path; eeSAFE_DELETE( mPak.fs ); @@ -125,7 +127,7 @@ bool cPak::ExtractFile( const std::string& path , const std::string& dest ) { SafeDataPointer data; if ( ExtractFileToMemory( path, data ) ) { - FileWrite( path, data.Data, data.DataSize ); + FileSystem::FileWrite( path, data.Data, data.DataSize ); } Ret = true; @@ -207,7 +209,7 @@ bool cPak::AddFile( const Uint8 * data, const Uint32& dataSize, const std::strin mPak.fs->Write( reinterpret_cast (&data[0]), fsize ); pakEntry newFile; - StrCopy( newFile.filename, inpack.c_str(), 56 ); + String::StrCopy( newFile.filename, inpack.c_str(), 56 ); newFile.file_position = sizeof(pakHeader); newFile.file_length = fsize; @@ -240,7 +242,7 @@ bool cPak::AddFile( const Uint8 * data, const Uint32& dataSize, const std::strin mPak.fs->Write( reinterpret_cast (&data[0]), fsize ); // Alloc the file // Fill the new file data on the pakEntry - StrCopy (pakE[ mPak.pakFilesNum ].filename, inpack.c_str(), 56 ); + String::StrCopy (pakE[ mPak.pakFilesNum ].filename, inpack.c_str(), 56 ); pakE[ mPak.pakFilesNum ].file_position = mPak.header.dir_offset - fsize; pakE[ mPak.pakFilesNum ].file_length = fsize; @@ -270,7 +272,7 @@ bool cPak::AddFile( const std::string& path, const std::string& inpack ) { std::vector file; - FileGet( path, file ); + FileSystem::FileGet( path, file ); return AddFile( file, inpack ); } diff --git a/src/eepp/system/crc4.cpp b/src/eepp/system/crc4.cpp index f88502027..5ffdd5d29 100644 --- a/src/eepp/system/crc4.cpp +++ b/src/eepp/system/crc4.cpp @@ -1,5 +1,6 @@ #include #include +#include namespace EE { namespace System { @@ -53,20 +54,20 @@ void cRC4::EncryptByte( std::vector& buffer ) { } void cRC4::EncryptString( std::string& buffer ) { - std::vector intbuf = stringToUint8( buffer ); + std::vector intbuf = String::stringToUint8( buffer ); EncryptByte( intbuf ); - buffer = Uint8Tostring( intbuf ); + buffer = String::Uint8Tostring( intbuf ); } bool cRC4::EncryptFile( const std::string& SourceFile, const std::string& DestFile ) { std::vector tmpv; - if ( !FileExists( SourceFile ) ) + if ( !FileSystem::FileExists( SourceFile ) ) return false; - tmpv.resize( FileSize( SourceFile ) ); + tmpv.resize( FileSystem::FileSize( SourceFile ) ); cIOStreamFile fs( SourceFile, std::ios::in | std::ios::out | std::ios::binary ); @@ -107,11 +108,11 @@ bool cRC4::EncryptFile( const std::string& SourceFile, const std::string& DestFi } void cRC4::SetKey( const std::string& Key ) { - SetKey( stringToUint8( Key ) ); + SetKey( String::stringToUint8( Key ) ); } void cRC4::EncryptByte( std::vector& buffer, const std::string& Key ) { - EncryptByte( buffer, stringToUint8( Key ) ); + EncryptByte( buffer, String::stringToUint8( Key ) ); } void cRC4::DecryptByte( std::vector& buffer, const std::vector& Key ) { @@ -119,7 +120,7 @@ void cRC4::DecryptByte( std::vector& buffer, const std::vector& Ke } void cRC4::DecryptByte( std::vector& buffer, const std::string& Key ) { - EncryptByte( buffer, stringToUint8( Key ) ); + EncryptByte( buffer, String::stringToUint8( Key ) ); } void cRC4::DecryptByte( std::vector& buffer ) { @@ -127,7 +128,7 @@ void cRC4::DecryptByte( std::vector& buffer ) { } void cRC4::EncryptString( std::string& buffer, const std::string& Key ) { - EncryptString( buffer, stringToUint8( Key ) ); + EncryptString( buffer, String::stringToUint8( Key ) ); } void cRC4::DecryptString( std::string& buffer, const std::vector& Key ) { @@ -143,7 +144,7 @@ void cRC4::DecryptString( std::string& buffer ) { } bool cRC4::EncryptFile( const std::string& SourceFile, const std::string& DestFile, const std::string& Key ) { - return EncryptFile( SourceFile, DestFile, stringToUint8( Key ) ); + return EncryptFile( SourceFile, DestFile, String::stringToUint8( Key ) ); } bool cRC4::DecryptFile( const std::string& SourceFile, const std::string& DestFile ) { diff --git a/src/eepp/system/cresourceloader.cpp b/src/eepp/system/cresourceloader.cpp index 7a2148de0..4491b624e 100644 --- a/src/eepp/system/cresourceloader.cpp +++ b/src/eepp/system/cresourceloader.cpp @@ -1,4 +1,5 @@ #include +#include namespace EE { namespace System { @@ -17,7 +18,7 @@ cResourceLoader::~cResourceLoader() { void cResourceLoader::SetThreads() { if ( THREADS_AUTO == mThreads ) { - mThreads = GetCPUCount(); + mThreads = Sys::GetCPUCount(); if ( 1 == mThreads ) { mThreaded = false; diff --git a/src/eepp/system/czip.cpp b/src/eepp/system/czip.cpp index 17f5d9aa3..f86e65cff 100644 --- a/src/eepp/system/czip.cpp +++ b/src/eepp/system/czip.cpp @@ -1,6 +1,7 @@ #include #include #include +#include namespace EE { namespace System { @@ -14,7 +15,7 @@ cZip::~cZip() { } bool cZip::Create( const std::string& path ) { - if ( !FileExists(path) ) { + if ( !FileSystem::FileExists(path) ) { int err; mZip = zip_open( path.c_str(), ZIP_CREATE, &err ); @@ -33,7 +34,7 @@ bool cZip::Create( const std::string& path ) { } bool cZip::Open( const std::string& path ) { - if ( FileExists( path ) ) { + if ( FileSystem::FileExists( path ) ) { int err; mZip = zip_open( path.c_str(), 0, &err ); @@ -70,7 +71,7 @@ bool cZip::Close() { bool cZip::AddFile( const std::string& path, const std::string& inpack ) { std::vector file; - FileGet( path, file ); + FileSystem::FileGet( path, file ); return AddFile( file, inpack ); } @@ -141,7 +142,7 @@ bool cZip::ExtractFile( const std::string& path , const std::string& dest ) { Ret = ExtractFileToMemory( path, data ); if ( Ret ) - FileWrite( dest, data.Data, data.DataSize ); + FileSystem::FileWrite( dest, data.Data, data.DataSize ); Unlock(); diff --git a/src/eepp/system/filesystem.cpp b/src/eepp/system/filesystem.cpp new file mode 100644 index 000000000..018ed04de --- /dev/null +++ b/src/eepp/system/filesystem.cpp @@ -0,0 +1,425 @@ +#include +#include +#include +#include + +#ifndef EE_COMPILER_MSVC + #include +#else + #ifndef S_ISDIR + #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) + #endif +#endif + +namespace EE { namespace System { + +std::string FileSystem::GetOSlash() { + #if EE_PLATFORM == EE_PLATFORM_WIN + return std::string( "\\" ); + #else + return std::string( "/" ); + #endif +} + +bool FileSystem::FileGet( const std::string& path, SafeDataPointer& data ) { + if ( FileExists( path ) ) { + cIOStreamFile fs ( path , std::ios::in | std::ios::binary ); + + eeSAFE_DELETE( data.Data ); + + data.DataSize = FileSize( path ); + data.Data = eeNewArray( Uint8, ( data.DataSize ) ); + + fs.Read( reinterpret_cast ( data.Data ), data.DataSize ); + + return true; + } + + return false; +} + +bool FileSystem::FileGet( const std::string& path, std::vector& data ) { + if ( FileExists( path ) ) { + cIOStreamFile fs ( path, std::ios::in | std::ios::binary ); + Uint32 fsize = FileSize( path ); + + data.clear(); + data.resize( fsize ); + + fs.Read( reinterpret_cast (&data[0]), fsize ); + + return true; + } + + return false; +} + +bool FileSystem::FileCopy( const std::string& src, const std::string& dst ) { + if ( FileExists( src ) ) { + Int64 chunksize = EE_1MB; + Int64 size = FileSize( src ); + Int64 size_left = (Int32)size; + Int64 allocate = ( size < chunksize ) ? size : chunksize; + Int64 copysize = 0; + + SafeDataPointer data; + data.DataSize = (Uint32)allocate; + data.Data = eeNewArray( Uint8, ( data.DataSize ) ); + char * buff = (char*)data.Data; + + cIOStreamFile in( src, std::ios::binary | std::ios::in ); + cIOStreamFile out( dst, std::ios::binary | std::ios::out ); + + if ( in.IsOpen() && out.IsOpen() && size > 0 ) { + do { + if ( size_left - chunksize < 0 ) { + copysize = size_left; + } else { + copysize = chunksize; + } + + in.Read ( &buff[0], copysize ); + out.Write ( (const char*)&buff[0], copysize ); + + size_left -= copysize; + } while ( size_left > 0 ); + + return true; + } + } + + return false; +} + +std::string FileSystem::FileExtension( const std::string& filepath, const bool& lowerExt ) { + std::string tstr( filepath.substr( filepath.find_last_of(".") + 1 ) ); + + if ( lowerExt ) + String::ToLower( tstr ); + + return tstr; +} + +std::string FileSystem::FileRemoveExtension( const std::string& filepath ) { + return filepath.substr( 0, filepath.find_last_of(".") ); +} + +std::string FileSystem::FileNameFromPath( const std::string& filepath ) { + return filepath.substr( filepath.find_last_of("/\\") + 1 ); +} + +std::string FileSystem::FileRemoveFileName( const std::string& filepath ) { + return filepath.substr( 0, filepath.find_last_of("/\\") + 1 ); +} + +void FileSystem::FilePathRemoveProcessPath( std::string& path ) { + static std::string ProcessPath = Sys::GetProcessPath(); + + Int32 pos = String::StrStartsWith( ProcessPath, path ); + + if ( -1 != pos && (Uint32)(pos + 1) < path.size() ) + path = path.substr( pos + 1 ); +} + + +bool FileSystem::FileWrite( const std::string& filepath, const Uint8* data, const Uint32& dataSize ) { + cIOStreamFile fs( filepath, std::ios::out | std::ios::binary ); + + if ( fs.IsOpen() ) { + fs.Write( reinterpret_cast (data), dataSize ); + return true; + } + + return false; +} + +bool FileSystem::FileWrite( const std::string& filepath, const std::vector& data ) { + return FileWrite( filepath, reinterpret_cast ( &data[0] ), (Uint32)data.size() ); +} + +Uint32 FileSystem::FileGetModificationDate( const std::string& Filepath ) { + struct stat st; + int res = stat( Filepath.c_str(), &st ); + + if ( 0 == res ) + return (Uint32)st.st_mtime; + + return 0; +} + +void FileSystem::DirPathAddSlashAtEnd( std::string& path ) { + if ( path.size() && path[ path.size() - 1 ] != '/' && path[ path.size() - 1 ] != '\\' ) + path += GetOSlash(); +} + +std::string FileSystem::RemoveLastFolderFromPath( std::string path ) { + if ( path.size() > 1 && ( path[ path.size() - 1 ] == '/' || path[ path.size() - 1 ] == '\\' ) ) { + path.resize( path.size() - 1 ); + } + + std::size_t pos = path.find_last_of( GetOSlash() ); + + if ( std::string::npos != pos ) { + std::string sstr; + std::size_t pos2 = path.find_first_of( GetOSlash() ); + + if ( pos2 != pos ) { + sstr = path.substr(0,pos) + GetOSlash(); + } else { + if ( pos == pos2 ) { + sstr = path.substr(0,pos2+1); + } + } + + if ( sstr.size() ) { + DirPathAddSlashAtEnd( sstr ); + + return sstr; + } + } + + DirPathAddSlashAtEnd( path ); + + return path; +} + +bool FileSystem::IsDirectory( const String& path ) { + return IsDirectory( path.ToUtf8() ); +} + +bool FileSystem::IsDirectory( const std::string& path ) { +#ifndef EE_COMPILER_MSVC + DIR *dp = NULL; + + bool isdir = !( ( dp = opendir( path.c_str() ) ) == NULL); + + if ( NULL != dp ) + closedir(dp); + + return isdir; +#else + return GetFileAttributes( (LPCTSTR) path.c_str() ) == FILE_ATTRIBUTE_DIRECTORY; +#endif +} + +bool FileSystem::MakeDir( const std::string& path, const Uint16& mode ) { + Int16 v; +#if EE_PLATFORM == EE_PLATFORM_WIN + #ifdef EE_COMPILER_MSVC + v = _mkdir( path.c_str() ); + #else + v = mkdir( path.c_str() ); + #endif +#else + v = mkdir( path.c_str(), mode ); +#endif + return v == 0; +} + +std::vector FileSystem::FilesGetInPath( const String& path ) { + std::vector files; + +#ifdef EE_COMPILER_MSVC + #ifdef UNICODE + String mPath( path ); + + if ( mPath[ mPath.size() - 1 ] == '/' || mPath[ mPath.size() - 1 ] == '\\' ) { + mPath += "*"; + } else { + mPath += "\\*"; + } + + WIN32_FIND_DATA findFileData; + HANDLE hFind = FindFirstFile( (LPCWSTR)mPath.ToWideString().c_str(), &findFileData ); + + if( hFind != INVALID_HANDLE_VALUE ) { + String tmpstr( findFileData.cFileName ); + + if ( tmpstr != "." && tmpstr != ".." ) + files.push_back( tmpstr ); + + while( FindNextFile( hFind, &findFileData ) ) { + tmpstr = String( findFileData.cFileName ); + + if ( tmpstr != "." && tmpstr != ".." ) + files.push_back( tmpstr ); + } + + FindClose( hFind ); + } + #else + String mPath( path ); + + if ( mPath[ mPath.size() - 1 ] == '/' || mPath[ mPath.size() - 1 ] == '\\' ) { + mPath += "*"; + } else { + mPath += "\\*"; + } + + WIN32_FIND_DATA findFileData; + HANDLE hFind = FindFirstFile( (LPCTSTR) mPath.ToAnsiString().c_str(), &findFileData ); + + if( hFind != INVALID_HANDLE_VALUE ) { + String tmpstr( String::FromUtf8( findFileData.cFileName ) ); + + if ( tmpstr != "." && tmpstr != ".." ) + files.push_back( tmpstr ); + + while( FindNextFile( hFind, &findFileData ) ) { + tmpstr = String::FromUtf8( findFileData.cFileName ); + + if ( tmpstr != "." && tmpstr != ".." ) + files.push_back( tmpstr ); + } + + FindClose( hFind ); + } + #endif + + return files; +#else + DIR *dp; + struct dirent *dirp; + + if( ( dp = opendir( path.ToUtf8().c_str() ) ) == NULL) + return files; + + while ( ( dirp = readdir(dp) ) != NULL) { + if ( strcmp( dirp->d_name, ".." ) != 0 && strcmp( dirp->d_name, "." ) != 0 ) { + + char * p = &dirp->d_name[0]; + String tmp; + + while ( *p ) { + unsigned char y = *p; + tmp.push_back( y ); + p++; + } + + files.push_back( tmp ); + } + } + + closedir(dp); + + return files; +#endif +} + +std::vector FileSystem::FilesGetInPath( const std::string& path ) { + std::vector files; + +#ifdef EE_COMPILER_MSVC + #ifdef UNICODE + String mPath( String::FromUtf8( path ) ); + + if ( mPath[ mPath.size() - 1 ] == '/' || mPath[ mPath.size() - 1 ] == '\\' ) { + mPath += "*"; + } else { + mPath += "\\*"; + } + + WIN32_FIND_DATA findFileData; + HANDLE hFind = FindFirstFile( (LPCWSTR)mPath.ToWideString().c_str(), &findFileData ); + + if( hFind != INVALID_HANDLE_VALUE ) { + String tmpstr( findFileData.cFileName ); + + if ( tmpstr != "." && tmpstr != ".." ) + files.push_back( tmpstr.ToUtf8() ); + + while( FindNextFile(hFind, &findFileData ) ) { + tmpstr = String( findFileData.cFileName ); + + if ( tmpstr != "." && tmpstr != ".." ) + files.push_back( String( findFileData.cFileName ).ToUtf8() ); + } + + FindClose( hFind ); + } + #else + std::string mPath( path ); + + if ( mPath[ mPath.size() - 1 ] == '/' || mPath[ mPath.size() - 1 ] == '\\' ) { + mPath += "*"; + } else { + mPath += "\\*"; + } + + WIN32_FIND_DATA findFileData; + HANDLE hFind = FindFirstFile( (LPCTSTR) mPath.c_str(), &findFileData ); + + if( hFind != INVALID_HANDLE_VALUE ) { + std::string tmpstr( findFileData.cFileName ); + + if ( tmpstr != "." && tmpstr != ".." ) + files.push_back( tmpstr ); + + while( FindNextFile(hFind, &findFileData ) ) { + tmpstr = std::string( findFileData.cFileName ); + + if ( tmpstr != "." && tmpstr != ".." ) + files.push_back( std::string( findFileData.cFileName ) ); + } + + FindClose( hFind ); + } + #endif + + return files; +#else + DIR *dp; + struct dirent *dirp; + + if( ( dp = opendir( path.c_str() ) ) == NULL) + return files; + + while ( ( dirp = readdir(dp) ) != NULL) { + if ( strcmp( dirp->d_name, ".." ) != 0 && strcmp( dirp->d_name, "." ) != 0 ) + files.push_back( std::string( dirp->d_name ) ); + } + + closedir(dp); + + return files; +#endif +} + +Uint64 FileSystem::FileSize( const std::string& Filepath ) { + struct stat st; + int res = stat( Filepath.c_str(), &st ); + + if ( 0 == res ) + return st.st_size; + + return 0; +} + +bool FileSystem::FileExists( const std::string& Filepath ) { + struct stat st; + return ( stat( Filepath.c_str(), &st ) == 0 ) && !S_ISDIR( st.st_mode ); +} + +std::string FileSystem::SizeToString( const Uint32& MemSize ) { + std::string size = " bytes"; + eeDouble mem = static_cast( MemSize ); + Uint8 c = 0; + + while ( mem > 1024 ) { + c++; + mem = mem / 1024; + } + + switch (c) { + case 0: size = " bytes"; break; + case 1: size = " KB"; break; + case 2: size = " MB"; break; + case 3: size = " GB"; break; + case 4: size = " TB"; break; + default: size = " WTF"; + } + + return std::string( String::toStr( mem ) + size ); +} + +}} diff --git a/src/eepp/system/sys.cpp b/src/eepp/system/sys.cpp new file mode 100644 index 000000000..fd008719e --- /dev/null +++ b/src/eepp/system/sys.cpp @@ -0,0 +1,591 @@ +#include +#include +#include +#include + +#if defined( EE_PLATFORM_POSIX ) + #include + + #if EE_PLATFORM != EE_PLATFORM_ANDROID + #include + #else + #include + #define statvfs statfs + #define fstatvfs fstatfs + #endif +#endif + +#if EE_PLATFORM == EE_PLATFORM_MACOSX + #include +#elif EE_PLATFORM == EE_PLATFORM_WIN + #include +#elif EE_PLATFORM == EE_PLATFORM_LINUX || EE_PLATFORM == EE_PLATFORM_ANDROID + #include + #include +#elif EE_PLATFORM == EE_PLATFORM_HAIKU + #include + #include +#elif EE_PLATFORM == EE_PLATFORM_SOLARIS + #include +#endif + +#if EE_PLATFORM == EE_PLATFORM_MACOSX || EE_PLATFORM == EE_PLATFORM_BSD || EE_PLATFORM == EE_PLATFORM_IOS + #include +#endif + +#if EE_PLATFORM == EE_PLATFORM_WIN + #include + #include +#else + #include +#endif + +namespace EE { namespace System { + +#if EE_PLATFORM == EE_PLATFORM_WIN + +typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO); + +static std::string GetWindowsArch() { + std::string arch = "Unknown"; + OSVERSIONINFOEX osvi; + SYSTEM_INFO si; + PGNSI pGNSI; + BOOL bOsVersionInfoEx; + + ZeroMemory(&si, sizeof(SYSTEM_INFO)); + ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); + + osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); + bOsVersionInfoEx = GetVersionEx( (OSVERSIONINFO*) &osvi ); + + if( bOsVersionInfoEx == FALSE ) return arch; + + // Call GetNativeSystemInfo if supported or GetSystemInfo otherwise. + pGNSI = (PGNSI) GetProcAddress( GetModuleHandle( TEXT( "kernel32.dll" ) ), "GetNativeSystemInfo" ); + + if( NULL != pGNSI ) { + pGNSI(&si); + } else { + GetSystemInfo(&si); + } + + if ( osvi.dwMajorVersion >= 6 ) { + if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 ) { + arch = "x64"; + } else if (si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_INTEL ) { + arch = "x86"; + } + } else { + arch = "x86"; + } + + return arch; +} + +static std::string GetWindowsVersion() { + std::string os; + OSVERSIONINFOEX osvi; + SYSTEM_INFO si; + PGNSI pGNSI; + BOOL bOsVersionInfoEx; + + ZeroMemory(&si, sizeof(SYSTEM_INFO)); + ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); + + osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); + bOsVersionInfoEx = GetVersionEx( (OSVERSIONINFO*) &osvi ); + + if( bOsVersionInfoEx == FALSE ) return os; + + // Call GetNativeSystemInfo if supported or GetSystemInfo otherwise. + pGNSI = (PGNSI) GetProcAddress( GetModuleHandle( TEXT( "kernel32.dll" ) ), "GetNativeSystemInfo" ); + + if( NULL != pGNSI ) { + pGNSI(&si); + } else { + GetSystemInfo(&si); + } + + os = "Microsoft "; + + if ( VER_PLATFORM_WIN32_NT == osvi.dwPlatformId && osvi.dwMajorVersion > 4 ) { + if ( osvi.dwMajorVersion == 6 ) { + if( osvi.dwMinorVersion == 0 ) { + if( osvi.wProductType == VER_NT_WORKSTATION ) { + os += "Windows Vista"; + } else { + os += "Windows Server 2008"; + } + } + + if ( osvi.dwMinorVersion == 1 ) { + if( osvi.wProductType == VER_NT_WORKSTATION ) { + os += "Windows 7"; + } else { + os += "Windows Server 2008 R2"; + } + } + + if ( osvi.dwMinorVersion == 2 ) { + if( osvi.wProductType == VER_NT_WORKSTATION ) { + os += "Windows 8"; + } else { + os += "Windows Server 2012"; + } + } + } + + if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 ) { + if ( GetSystemMetrics(SM_SERVERR2) ) { + os += "Windows Server 2003 R2, "; + } else if ( osvi.wSuiteMask & VER_SUITE_STORAGE_SERVER ) { + os += "Windows Storage Server 2003"; + } else if ( osvi.wSuiteMask & 0x00008000 ) { //VER_SUITE_WH_SERVER + os += "Windows Home Server"; + } else if ( osvi.wProductType == VER_NT_WORKSTATION && si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 ) { + os += "Windows XP Professional x64 Edition"; + } else { + os += "Windows Server 2003, "; + } + } + + if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 ) { + os += "Windows XP"; + } + + if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 ) { + os += "Windows 2000"; + } + + // Include service pack (if any) and build number. + #if defined( EE_COMPILER_MSVC ) && defined( UNICODE ) + std::string CSDVer( EE::String( osvi.szCSDVersion ).ToUtf8() ); + #else + std::string CSDVer( osvi.szCSDVersion ); + #endif + + if ( CSDVer.size() ) { + os += " " + CSDVer; + } + } else if ( VER_PLATFORM_WIN32_WINDOWS == osvi.dwPlatformId ) { + if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0) { + if (osvi.szCSDVersion[1] == 'C' || + osvi.szCSDVersion[1] == 'B') { + os += "Windows 95 OSR2"; + } else { + os += "Windows 95"; + } + } else if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10) { + if (osvi.szCSDVersion[1] == 'A') { + os += "Windows 98 SE"; + } else { + os += "Windows 98"; + } + } else if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90) { + os += "Windows ME"; + } else if (osvi.dwMajorVersion == 4) { + os += "Windows unknown 95 family"; + } else { + os += "Windows"; + } + } else { + os += "Windows"; + } + + return os; +} + +#define TIME_WRAP_VALUE (~(DWORD)0) +/* The first high-resolution ticks value of the application */ +static LARGE_INTEGER hires_start_ticks; +/* The number of ticks per second of the high-resolution performance counter */ +static LARGE_INTEGER hires_ticks_per_second; + +#endif + +#ifdef EE_PLATFORM_POSIX + +#ifdef EE_HAVE_CLOCK_GETTIME +static struct timespec start; +#else +static struct timeval start; +#endif + +#endif + +std::string Sys::GetOSName() { +#if defined( EE_PLATFORM_POSIX ) + struct utsname os; + + if ( -1 != uname( &os ) ) { + return std::string( os.sysname ) + " " + std::string( os.release ); + } + + return "Unknown"; +#elif EE_PLATFORM == EE_PLATFORM_WIN + return GetWindowsVersion(); +#else + return "Unknown"; +#endif +} + +std::string Sys::GetOSArchitecture() { +#if defined( EE_PLATFORM_POSIX ) + struct utsname os; + + if ( -1 != uname( &os ) ) { + return std::string( os.machine ); + } + + return "Unknown"; +#elif EE_PLATFORM == EE_PLATFORM_WIN + return GetWindowsArch(); +#else + return "Unknown"; +#endif +} + +static void eeStartTicks() { + static bool TickStarted = false; + + if ( !TickStarted ) { + #if EE_PLATFORM == EE_PLATFORM_WIN + QueryPerformanceFrequency(&hires_ticks_per_second); + QueryPerformanceCounter(&hires_start_ticks); + #else + #ifdef EE_HAVE_CLOCK_GETTIME + clock_gettime(CLOCK_MONOTONIC, &start); + #else + gettimeofday(&start, NULL); + #endif + #endif + + TickStarted = true; + } +} + +Uint32 Sys::GetTicks() { + eeStartTicks(); + +#if EE_PLATFORM == EE_PLATFORM_WIN + LARGE_INTEGER hires_now; + + QueryPerformanceCounter(&hires_now); + + hires_now.QuadPart -= hires_start_ticks.QuadPart; + hires_now.QuadPart *= 1000; + hires_now.QuadPart /= hires_ticks_per_second.QuadPart; + + return (DWORD) hires_now.QuadPart; +#elif defined( EE_PLATFORM_POSIX ) + #ifdef EE_HAVE_CLOCK_GETTIME + Uint32 ticks; + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + ticks = + (now.tv_sec - start.tv_sec) * 1000 + (now.tv_nsec - + start.tv_nsec) / 1000000; + return (ticks); + #else + Uint32 ticks; + struct timeval now; + gettimeofday(&now, NULL); + ticks = + (now.tv_sec - start.tv_sec) * 1000 + (now.tv_usec - + start.tv_usec) / 1000; + return (ticks); + #endif +#else + #warning eeGetTicks not implemented in this platform. +#endif +} + +void Sys::Sleep( const Uint32& ms ) { +#if EE_PLATFORM == EE_PLATFORM_WIN + ::Sleep( ms ); +#elif defined( EE_PLATFORM_POSIX ) + // usleep( static_cast( ms * 1000 ) ); + + // usleep is not reliable enough (it might block the + // whole process instead of just the current thread) + // so we must use pthread_cond_timedwait instead + + // this implementation is inspired from Qt + // and taken from SFML + + Uint64 usecs = ms * 1000; + + // get the current time + timeval tv; + gettimeofday(&tv, NULL); + + // construct the time limit (current time + time to wait) + timespec ti; + ti.tv_nsec = (tv.tv_usec + (usecs % 1000000)) * 1000; + ti.tv_sec = tv.tv_sec + (usecs / 1000000) + (ti.tv_nsec / 1000000000); + ti.tv_nsec %= 1000000000; + + // create a mutex and thread condition + pthread_mutex_t mutex; + pthread_mutex_init(&mutex, 0); + pthread_cond_t condition; + pthread_cond_init(&condition, 0); + + // wait... + pthread_mutex_lock(&mutex); + pthread_cond_timedwait(&condition, &mutex, &ti); + pthread_mutex_unlock(&mutex); + + // destroy the mutex and condition + pthread_cond_destroy(&condition); + pthread_mutex_destroy(&mutex); + +#else + #warning Sys::Sleep not implemented in this platform. +#endif +} + +std::string Sys::GetProcessPath() { +#if EE_PLATFORM == EE_PLATFORM_MACOSX + char exe_file[PATH_MAX + 1]; + CFBundleRef mainBundle = CFBundleGetMainBundle(); + if (mainBundle) { + CFURLRef mainURL = CFBundleCopyBundleURL(mainBundle); + + if (mainURL) { + int ok = CFURLGetFileSystemRepresentation ( mainURL, (Boolean) true, (UInt8*)exe_file, PATH_MAX ); + + if (ok) { + return std::string(exe_file) + "/"; + } + } + } + + return "./"; +#elif EE_PLATFORM == EE_PLATFORM_LINUX + char exe_file[PATH_MAX + 1]; + int size; + size = readlink("/proc/self/exe", exe_file, PATH_MAX); + if (size < 0) { + return "./"; + } else { + exe_file[size] = '\0'; + return std::string(dirname(exe_file)) + "/"; + } +#elif EE_PLATFORM == EE_PLATFORM_WIN + #ifdef UNICODE + // Get path to executable: + char szDrive[_MAX_DRIVE]; + char szDir[_MAX_DIR]; + char szFilename[_MAX_DIR]; + char szExt[_MAX_DIR]; + std::wstring dllName( _MAX_DIR, 0 ); + + GetModuleFileName(0, &dllName[0], _MAX_PATH); + + std::string dllstrName( String( dllName ).ToUtf8() ); + + #ifdef EE_COMPILER_MSVC + _splitpath_s( dllstrName.c_str(), szDrive, _MAX_DRIVE, szDir, _MAX_DIR, szFilename, _MAX_DIR, szExt, _MAX_DIR ); + #else + _splitpath(szDllName, szDrive, szDir, szFilename, szExt); + #endif + + return std::string( szDrive ) + std::string( szDir ); + #else + // Get path to executable: + TCHAR szDllName[_MAX_PATH]; + TCHAR szDrive[_MAX_DRIVE]; + TCHAR szDir[_MAX_DIR]; + TCHAR szFilename[_MAX_DIR]; + TCHAR szExt[_MAX_DIR]; + GetModuleFileName(0, szDllName, _MAX_PATH); + + #ifdef EE_COMPILER_MSVC + _splitpath_s(szDllName, szDrive, _MAX_DRIVE, szDir, _MAX_DIR, szFilename, _MAX_DIR, szExt, _MAX_DIR ); + #else + _splitpath(szDllName, szDrive, szDir, szFilename, szExt); + #endif + + return std::string(szDrive) + std::string(szDir); + #endif +#elif EE_PLATFORM == EE_PLATFORM_BSD + int mib[4]; + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_PATHNAME; + mib[3] = -1; + char buf[1024]; + size_t cb = sizeof(buf); + sysctl(mib, 4, buf, &cb, NULL, 0); + + return FileRemoveFileName( std::string( buf ) ); +#elif EE_PLATFORM == EE_PLATFORM_SOLARIS + return FileRemoveFileName( std::string( getexecname() ) ); +#elif EE_PLATFORM == EE_PLATFORM_HAIKU + image_info info; + int32 cookie = 0; + + while ( B_OK == get_next_image_info( 0, &cookie, &info ) ) { + if ( info.type == B_APP_IMAGE ) + break; + } + + return FileRemoveFileName( std::string( info.name ) ); +#elif EE_PLATFORM == EE_PLATFORM_ANDROID + return "/sdcard/"; +#else + #warning Sys::GetProcessPath() not implemented on this platform. ( will return "./" ) + return "./"; +#endif +} + +eeDouble Sys::GetSystemTime() { +#if EE_PLATFORM == EE_PLATFORM_WIN + static LARGE_INTEGER Frequency; + static BOOL UseHighPerformanceTimer = QueryPerformanceFrequency(&Frequency); + + if (UseHighPerformanceTimer) { + // High performance counter available : use it + LARGE_INTEGER CurrentTime; + QueryPerformanceCounter(&CurrentTime); + return static_cast(CurrentTime.QuadPart) / Frequency.QuadPart; + } else + // High performance counter not available : use GetTickCount (less accurate) + return GetTickCount() * 0.001; +#else + timeval Time = {0, 0}; + gettimeofday(&Time, NULL); + + return Time.tv_sec + Time.tv_usec / 1000000.; +#endif +} + +std::string Sys::GetDateTimeStr() { + time_t rawtime; + time ( &rawtime ); + +#ifdef EE_COMPILER_MSVC + char buf[256]; + struct tm timeinfo; + localtime_s ( &timeinfo, &rawtime ); + asctime_s( &buf[0], 256, &timeinfo ); + return std::string( buf ); +#else + struct tm * timeinfo; + timeinfo = localtime ( &rawtime ); + return std::string( asctime (timeinfo) ); +#endif +} + +std::string Sys::StoragePath( std::string appname ) { + char path[256]; + + #if EE_PLATFORM == EE_PLATFORM_WIN + #ifdef EE_COMPILER_MSVC + + char * ppath; + size_t ssize = 256; + + _dupenv_s( &ppath, &ssize, "APPDATA" ); + + StrCopy( path, ppath, 256 ); + + free( ppath ); + + if( !ssize ) + return std::string(); + + #else + char * home = getenv("APPDATA"); + + if( !home ) + return std::string(); + + _snprintf(path, 256, "%s\\%s", home, appname.c_str() ); + + #endif + #else + char *home = getenv("HOME"); + + #if EE_PLATFORM != EE_PLATFORM_MACOSX + int i; + #endif + if(!home) + return std::string(); + + #if EE_PLATFORM == EE_PLATFORM_MACOSX + snprintf(path, 256, "%s/Library/Application Support/%s", home, appname.c_str() ); + #else + snprintf(path, 256, "%s/.%s", home, appname.c_str() ); + for(i = strlen(home)+2; path[i]; i++) + path[i] = std::tolower(path[i]); + #endif + #endif + + return std::string( path ); +} + +eeInt Sys::GetCPUCount() { + eeInt nprocs = -1; + + #if EE_PLATFORM == EE_PLATFORM_WIN + SYSTEM_INFO info; + GetSystemInfo(&info); + + nprocs = (eeInt) info.dwNumberOfProcessors; + #elif EE_PLATFORM == EE_PLATFORM_LINUX || EE_PLATFORM == EE_PLATFORM_SOLARIS || EE_PLATFORM == EE_PLATFORM_ANDROID + nprocs = sysconf(_SC_NPROCESSORS_ONLN); + #elif EE_PLATFORM == EE_PLATFORM_MACOSX || EE_PLATFORM == EE_PLATFORM_BSD || EE_PLATFORM == EE_PLATFORM_IOS + int mib[2]; + int maxproc = 1; + size_t len = sizeof(int); + + mib[0] = CTL_HW; + mib[1] = HW_NCPU; + + len = sizeof(maxproc); + + sysctl( mib, 2, &maxproc, &len, NULL, 0 ); + + nprocs = maxproc; + #elif EE_PLATFORM == EE_PLATFORM_HAIKU + system_info info; + + if ( B_OK == get_system_info( &info ) ) { + nprocs = info.cpu_count; + } + #else + #warning Sys::GetCPUCount not implemented on this platform ( it will return 1 ). + #endif + + if ( nprocs < 1 ) + nprocs = 1; + + return nprocs; +} + +Int64 Sys::GetDiskFreeSpace(const std::string& path) { +#if defined( EE_PLATFORM_POSIX ) + struct statvfs data; + statvfs(path.c_str(), &data); + return (Int64)data.f_bsize * (Int64)data.f_bfree; +#elif EE_PLATFORM == EE_PLATFORM_WIN + Int64 AvailableBytes; + Int64 TotalBytes; + Int64 FreeBytes; + #ifdef UNICODE + GetDiskFreeSpaceEx((LPCWSTR)path.c_str(),(PULARGE_INTEGER) &AvailableBytes, + #else + GetDiskFreeSpaceEx(path.c_str(),(PULARGE_INTEGER) &AvailableBytes, + #endif + (PULARGE_INTEGER) &TotalBytes, (PULARGE_INTEGER) &FreeBytes); + + return FreeBytes; +#else + return -1; +#endif +} + +}} diff --git a/src/eepp/ui/cuicheckbox.cpp b/src/eepp/ui/cuicheckbox.cpp index 3e2352fd4..4328379c3 100644 --- a/src/eepp/ui/cuicheckbox.cpp +++ b/src/eepp/ui/cuicheckbox.cpp @@ -154,8 +154,8 @@ Uint32 cUICheckBox::OnKeyDown( const cUIEventKey& Event ) { cUITextBox::OnKeyDown( Event ); if ( Event.KeyCode() == KEY_SPACE ) { - if ( eeGetTicks() - mLastTick > 250 ) { - mLastTick = eeGetTicks(); + if ( Sys::GetTicks() - mLastTick > 250 ) { + mLastTick = Sys::GetTicks(); Active( !mActive ); } diff --git a/src/eepp/ui/cuicommondialog.cpp b/src/eepp/ui/cuicommondialog.cpp index 57fb166f5..3882f36d2 100644 --- a/src/eepp/ui/cuicommondialog.cpp +++ b/src/eepp/ui/cuicommondialog.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include namespace EE { namespace UI { @@ -159,7 +160,7 @@ void cUICommonDialog::SetTheme( cUITheme * Theme ) { } void cUICommonDialog::RefreshFolder() { - std::vector flist = FilesGetInPath( String( mCurPath ) ); + std::vector flist = FileSystem::FilesGetInPath( String( mCurPath ) ); std::vector files; std::vector folders; std::vector patterns; @@ -167,21 +168,21 @@ void cUICommonDialog::RefreshFolder() { Uint32 i, z; if ( "*" != mFiletype->Text() ) { - patterns = SplitString( mFiletype->Text().ToUtf8(), ';' ); + patterns = String::SplitString( mFiletype->Text().ToUtf8(), ';' ); for ( i = 0; i < patterns.size(); i++ ) - patterns[i] = FileExtension( patterns[i] ); + patterns[i] = FileSystem::FileExtension( patterns[i] ); } for ( i = 0; i < flist.size(); i++ ) { - if ( FoldersFirst() && IsDirectory( mCurPath + flist[i] ) ) { + if ( FoldersFirst() && FileSystem::IsDirectory( mCurPath + flist[i] ) ) { folders.push_back( flist[i] ); } else { accepted = false; if ( patterns.size() ) { for ( z = 0; z < patterns.size(); z++ ) { - if ( patterns[z] == FileExtension( flist[i] ) ) { + if ( patterns[z] == FileSystem::FileExtension( flist[i] ) ) { accepted = true; break; } @@ -252,7 +253,7 @@ Uint32 cUICommonDialog::OnMessage( const cUIMessage * Msg ) { CloseWindow(); } else if ( Msg->Sender() == mButtonUp ) { - mCurPath = RemoveLastFolderFromPath( mCurPath ); + mCurPath = FileSystem::RemoveLastFolderFromPath( mCurPath ); mPath->Text( mCurPath ); RefreshFolder(); } @@ -266,8 +267,8 @@ Uint32 cUICommonDialog::OnMessage( const cUIMessage * Msg ) { if ( Msg->Sender()->IsType( UI_TYPE_LISTBOXITEM ) ) { std::string newPath = mCurPath + mList->GetItemSelectedText(); - if ( IsDirectory( newPath ) ) { - mCurPath = newPath + GetOSlash(); + if ( FileSystem::IsDirectory( newPath ) ) { + mCurPath = newPath + FileSystem::GetOSlash(); mPath->Text( mCurPath ); RefreshFolder(); } else { @@ -285,12 +286,12 @@ Uint32 cUICommonDialog::OnMessage( const cUIMessage * Msg ) { if ( AllowFolderSelect() ) { mFile->Text( mList->GetItemSelectedText() ); } else { - if ( !IsDirectory( GetTempFullPath() ) ) { + if ( !FileSystem::IsDirectory( GetTempFullPath() ) ) { mFile->Text( mList->GetItemSelectedText() ); } } } else { - if ( !IsDirectory( GetTempFullPath() ) ) { + if ( !FileSystem::IsDirectory( GetTempFullPath() ) ) { mFile->Text( mList->GetItemSelectedText() ); } } @@ -316,10 +317,10 @@ void cUICommonDialog::Save() { void cUICommonDialog::Open() { if ( "" != mList->GetItemSelectedText() || AllowFolderSelect() ) { if ( !AllowFolderSelect() ) { - if ( IsDirectory( GetFullPath() ) ) + if ( FileSystem::IsDirectory( GetFullPath() ) ) return; } else { - if ( !IsDirectory( GetFullPath() ) && !IsDirectory( GetCurPath() ) ) + if ( !FileSystem::IsDirectory( GetFullPath() ) && !FileSystem::IsDirectory( GetCurPath() ) ) return; } @@ -332,9 +333,9 @@ void cUICommonDialog::Open() { } void cUICommonDialog::OnPressEnter( const cUIEvent * Event ) { - if ( IsDirectory( mPath->Text() ) ) { + if ( FileSystem::IsDirectory( mPath->Text() ) ) { std::string tpath = mPath->Text(); - DirPathAddSlashAtEnd( tpath ); + FileSystem::DirPathAddSlashAtEnd( tpath ); mPath->Text( tpath ); mCurPath = mPath->Text(); RefreshFolder(); @@ -384,7 +385,7 @@ void cUICommonDialog::AllowFolderSelect( const bool& allowFolderSelect ) { std::string cUICommonDialog::GetFullPath() { std::string tPath = mCurPath; - DirPathAddSlashAtEnd( tPath ); + FileSystem::DirPathAddSlashAtEnd( tPath ); tPath += GetCurFile(); @@ -394,7 +395,7 @@ std::string cUICommonDialog::GetFullPath() { std::string cUICommonDialog::GetTempFullPath() { std::string tPath = mCurPath; - DirPathAddSlashAtEnd( tPath ); + FileSystem::DirPathAddSlashAtEnd( tPath ); tPath += mList->GetItemSelectedText().ToUtf8(); diff --git a/src/eepp/ui/cuilistbox.cpp b/src/eepp/ui/cuilistbox.cpp index 94ee262c5..98a0dcd84 100644 --- a/src/eepp/ui/cuilistbox.cpp +++ b/src/eepp/ui/cuilistbox.cpp @@ -829,17 +829,17 @@ Uint32 cUIListBox::OnKeyDown( const cUIEventKey &Event ) { if ( !mSelected.size() || mFlags & UI_MULTI_SELECT ) return 0; - if ( eeGetTicks() - mLastTickMove > 100 ) { + if ( Sys::GetTicks() - mLastTickMove > 100 ) { if ( KEY_DOWN == Event.KeyCode() ) { - mLastTickMove = eeGetTicks(); + mLastTickMove = Sys::GetTicks(); SelectNext(); } else if ( KEY_UP == Event.KeyCode() ) { - mLastTickMove = eeGetTicks(); + mLastTickMove = Sys::GetTicks(); SelectPrev(); } else if ( KEY_HOME == Event.KeyCode() ) { - mLastTickMove = eeGetTicks(); + mLastTickMove = Sys::GetTicks(); if ( mSelected.front() != 0 ) { mVScrollBar->Value( 0 ); @@ -849,7 +849,7 @@ Uint32 cUIListBox::OnKeyDown( const cUIEventKey &Event ) { SetSelected( 0 ); } } else if ( KEY_END == Event.KeyCode() ) { - mLastTickMove = eeGetTicks(); + mLastTickMove = Sys::GetTicks(); if ( mSelected.front() != Count() - 1 ) { mVScrollBar->Value( 1 ); diff --git a/src/eepp/ui/cuimenu.cpp b/src/eepp/ui/cuimenu.cpp index e1bee048f..0d38f2195 100644 --- a/src/eepp/ui/cuimenu.cpp +++ b/src/eepp/ui/cuimenu.cpp @@ -508,15 +508,15 @@ void cUIMenu::PrevSel() { } Uint32 cUIMenu::OnKeyDown( const cUIEventKey& Event ) { - if ( eeGetTicks() - mLastTickMove > 50 ) { + if ( Sys::GetTicks() - mLastTickMove > 50 ) { switch ( Event.KeyCode() ) { case KEY_DOWN: - mLastTickMove = eeGetTicks(); + mLastTickMove = Sys::GetTicks(); NextSel(); break; case KEY_UP: - mLastTickMove = eeGetTicks(); + mLastTickMove = Sys::GetTicks(); PrevSel(); break; diff --git a/src/eepp/ui/cuiprogressbar.cpp b/src/eepp/ui/cuiprogressbar.cpp index 541ed0b21..879815dab 100644 --- a/src/eepp/ui/cuiprogressbar.cpp +++ b/src/eepp/ui/cuiprogressbar.cpp @@ -162,7 +162,7 @@ const bool& cUIProgressBar::DisplayPercent() const { void cUIProgressBar::UpdateTextBox() { mTextBox->Visible( mDisplayPercent ); mTextBox->Size( mSize ); - mTextBox->Text( toStr( (Int32)( ( mProgress / mTotalSteps ) * 100.f ) ) + "%" ); + mTextBox->Text( String::toStr( (Int32)( ( mProgress / mTotalSteps ) * 100.f ) ) + "%" ); } cUITextBox * cUIProgressBar::TextBox() const { diff --git a/src/eepp/ui/cuiradiobutton.cpp b/src/eepp/ui/cuiradiobutton.cpp index d6537b770..957768650 100644 --- a/src/eepp/ui/cuiradiobutton.cpp +++ b/src/eepp/ui/cuiradiobutton.cpp @@ -218,8 +218,8 @@ cUIControlAnim * cUIRadioButton::InactiveButton() const { Uint32 cUIRadioButton::OnKeyDown( const cUIEventKey& Event ) { if ( Event.KeyCode() == KEY_SPACE ) { - if ( eeGetTicks() - mLastTick > 250 ) { - mLastTick = eeGetTicks(); + if ( Sys::GetTicks() - mLastTick > 250 ) { + mLastTick = Sys::GetTicks(); Active( true ); } diff --git a/src/eepp/ui/cuislider.cpp b/src/eepp/ui/cuislider.cpp index b094464a4..9c423f44e 100644 --- a/src/eepp/ui/cuislider.cpp +++ b/src/eepp/ui/cuislider.cpp @@ -269,21 +269,21 @@ void cUISlider::Update() { } Uint32 cUISlider::OnKeyDown( const cUIEventKey &Event ) { - if ( eeGetTicks() - mLastTickMove > 100 ) { + if ( Sys::GetTicks() - mLastTickMove > 100 ) { if ( Event.KeyCode() == KEY_DOWN ) { - mLastTickMove = eeGetTicks(); + mLastTickMove = Sys::GetTicks(); Value( mValue + mClickStep ); } else if ( Event.KeyCode() == KEY_UP ) { - mLastTickMove = eeGetTicks(); + mLastTickMove = Sys::GetTicks(); Value( mValue - mClickStep ); } else if ( Event.KeyCode() == KEY_PAGEUP ) { - mLastTickMove = eeGetTicks(); + mLastTickMove = Sys::GetTicks(); Value( mMinValue ); } else if ( Event.KeyCode() == KEY_PAGEDOWN ) { - mLastTickMove = eeGetTicks(); + mLastTickMove = Sys::GetTicks(); Value( mMaxValue ); } diff --git a/src/eepp/ui/cuispinbox.cpp b/src/eepp/ui/cuispinbox.cpp index 08bc5df35..5c9aca497 100644 --- a/src/eepp/ui/cuispinbox.cpp +++ b/src/eepp/ui/cuispinbox.cpp @@ -142,7 +142,7 @@ Uint32 cUISpinBox::OnMessage( const cUIMessage * Msg ) { void cUISpinBox::AddValue( const eeFloat& value ) { if ( !mInput->Text().size() ) - mInput->Text( toStr( static_cast( mMinValue ) ) ); + mInput->Text( String::toStr( static_cast( mMinValue ) ) ); Value( mValue + value ); } @@ -154,9 +154,9 @@ void cUISpinBox::InternalValue( const eeFloat& Val, const bool& Force ) { eeFloat fValN = (eeFloat)iValN; if ( fValN == Val ) { - mInput->Text( toStr( iValN ) ); + mInput->Text( String::toStr( iValN ) ); } else { - mInput->Text( toStr( Val ) ); + mInput->Text( String::toStr( Val ) ); } mValue = Val; @@ -213,7 +213,7 @@ void cUISpinBox::Update() { if ( pos != mInput->Text().size() - 1 ) mInput->Text( mInput->Text().substr( 0, mInput->Text().size() - 1 ) ); } else { - bool Res = fromString( Val, mInput->Text() ); + bool Res = String::fromString( Val, mInput->Text() ); if ( Res ) Value( Val ); diff --git a/src/eepp/ui/cuitheme.cpp b/src/eepp/ui/cuitheme.cpp index a3239aa9f..0d4d42c3e 100644 --- a/src/eepp/ui/cuitheme.cpp +++ b/src/eepp/ui/cuitheme.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -158,7 +159,7 @@ cUITheme * cUITheme::LoadFromShapeGroup( cUITheme * tTheme, cShapeGroup * ShapeG tTheme->Add( eeNew( cUISkinSimple, ( ElemFound[i] ) ) ); } - cLog::instance()->Write( "UI Theme Loaded in: " + toStr( TE.ElapsedSinceStart() ) + " ( from ShapeGroup )" ); + cLog::instance()->Write( "UI Theme Loaded in: " + String::toStr( TE.ElapsedSinceStart() ) + " ( from ShapeGroup )" ); return tTheme; } @@ -174,9 +175,9 @@ cUITheme * cUITheme::LoadFromPath( cUITheme * tTheme, const std::string& Path, c std::string ElemName; std::string RPath( Path ); - DirPathAddSlashAtEnd( RPath ); + FileSystem::DirPathAddSlashAtEnd( RPath ); - if ( !IsDirectory( RPath ) ) + if ( !FileSystem::IsDirectory( RPath ) ) return NULL; std::vector ElemFound; @@ -204,7 +205,7 @@ cUITheme * cUITheme::LoadFromPath( cUITheme * tTheme, const std::string& Path, c ElemName = tTheme->Abbr() + "_icon_" + *it; Element = RPath + ElemName + "." + ImgExt; - if ( FileExists( Element ) ) { + if ( FileSystem::FileExists( Element ) ) { tSG->Add( eeNew( cShape, ( cTextureFactory::instance()->Load( Element ), ElemName ) ) ); } } @@ -221,7 +222,7 @@ cUITheme * cUITheme::LoadFromPath( cUITheme * tTheme, const std::string& Path, c tTheme->Add( eeNew( cUISkinSimple, ( ElemFound[i] ) ) ); } - cLog::instance()->Write( "UI Theme Loaded in: " + toStr( TE.ElapsedSinceStart() ) + " ( from path )" ); + cLog::instance()->Write( "UI Theme Loaded in: " + String::toStr( TE.ElapsedSinceStart() ) + " ( from path )" ); return tTheme; } @@ -283,7 +284,7 @@ bool cUITheme::SearchFilesOfElement( cShapeGroup * SG, const std::string& Path, ElemPath = Path + ElemName; ElemFullPath = ElemPath + "." + ImgExt; - if ( FileExists( ElemFullPath ) ) { + if ( FileSystem::FileExists( ElemFullPath ) ) { SG->Add( eeNew( cShape, ( cTextureFactory::instance()->Load( ElemFullPath ), ElemName ) ) ); IsComplex = 1; @@ -300,7 +301,7 @@ bool cUITheme::SearchFilesOfElement( cShapeGroup * SG, const std::string& Path, ElemPath = Path + ElemName; ElemFullPath = ElemPath + "." + ImgExt; - if ( FileExists( ElemFullPath ) ) { + if ( FileSystem::FileExists( ElemFullPath ) ) { SG->Add( eeNew( cShape, ( cTextureFactory::instance()->Load( ElemFullPath ), ElemName ) ) ); Found = true; diff --git a/src/eepp/ui/tools/ctexturegroupeditor.cpp b/src/eepp/ui/tools/ctexturegroupeditor.cpp index bdd4ba9be..88ba7f3b5 100644 --- a/src/eepp/ui/tools/ctexturegroupeditor.cpp +++ b/src/eepp/ui/tools/ctexturegroupeditor.cpp @@ -273,7 +273,7 @@ void cTextureGroupEditor::OnTextureGroupCreate( cTexturePacker * TexPacker ) { eeSAFE_DELETE( mTextureGroupLoader ); - std::string FPath( FileRemoveExtension( mTexturePacker->GetFilepath() ) + ".etg" ); + std::string FPath( FileSystem::FileRemoveExtension( mTexturePacker->GetFilepath() ) + ".etg" ); mTextureGroupLoader = eeNew( cTextureGroupLoader, ( FPath, true, cb::Make1( this, &cTextureGroupEditor::OnTextureGroupLoaded ) ) ); } diff --git a/src/eepp/ui/tools/ctexturegroupnew.cpp b/src/eepp/ui/tools/ctexturegroupnew.cpp index c082cff9c..eaf72859a 100644 --- a/src/eepp/ui/tools/ctexturegroupnew.cpp +++ b/src/eepp/ui/tools/ctexturegroupnew.cpp @@ -2,6 +2,7 @@ #include #include #include +#include namespace EE { namespace UI { namespace Tools { @@ -42,7 +43,7 @@ cTextureGroupNew::cTextureGroupNew( TGCreateCb NewTGCb ) : std::vector Sizes; for ( Uint32 i = 6; i < 14; i++ ) { - Sizes.push_back( toStr( 1 << i ) ); + Sizes.push_back( String::toStr( 1 << i ) ); } mComboWidth->ListBox()->AddListBoxItems( Sizes ); @@ -85,7 +86,7 @@ cUITextBox * cTextureGroupNew::CreateTxtBox( eeVector2i Pos, const String& Text void cTextureGroupNew::OKClick( const cUIEvent * Event ) { std::string ext( mSaveFileType->Text() ); - ToLower( ext ); + String::ToLower( ext ); cUICommonDialog * TGDialog = mTheme->CreateCommonDialog( NULL, eeSize(), eeVector2i(), UI_CONTROL_DEFAULT_FLAGS_CENTERED, UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL, eeSize(), 255, UI_CDL_DEFAULT_FLAGS | CDL_FLAG_SAVE_DIALOG, "*." + ext ); @@ -111,10 +112,10 @@ void cTextureGroupNew::TextureGroupSave( const cUIEvent * Event ) { cUICommonDialog * CDL = reinterpret_cast ( Event->Ctrl() ); std::string FPath( CDL->GetFullPath() ); - if ( !IsDirectory( FPath ) ) { + if ( !FileSystem::IsDirectory( FPath ) ) { Int32 w,h,b; - bool Res1 = fromString( w, mComboWidth->Text() ); - bool Res2 = fromString( h, mComboHeight->Text() ); + bool Res1 = String::fromString( w, mComboWidth->Text() ); + bool Res2 = String::fromString( h, mComboHeight->Text() ); b = static_cast( mPixelSpace->Value() ); if ( Res1 && Res2 ) { @@ -124,14 +125,14 @@ void cTextureGroupNew::TextureGroupSave( const cUIEvent * Event ) { TexturePacker->PackTextures(); - std::string ext = FileExtension( FPath, true ); + std::string ext = FileSystem::FileExtension( FPath, true ); if ( !IsValidExtension( ext ) ) { - FPath = FileRemoveExtension( FPath ); + FPath = FileSystem::FileRemoveExtension( FPath ); ext = mSaveFileType->Text(); - ToLower( ext ); + String::ToLower( ext ); FPath += "." + ext; } @@ -163,21 +164,21 @@ void cTextureGroupNew::OnSelectFolder( const cUIEvent * Event ) { cUICommonDialog * CDL = reinterpret_cast ( Event->Ctrl() ); cUIMessageBox * MsgBox; std::string FPath( CDL->GetFullPath() ); - DirPathAddSlashAtEnd( FPath ); + FileSystem::DirPathAddSlashAtEnd( FPath ); - if ( !IsDirectory( FPath ) ) { + if ( !FileSystem::IsDirectory( FPath ) ) { FPath = CDL->GetCurPath(); - DirPathAddSlashAtEnd( FPath ); + FileSystem::DirPathAddSlashAtEnd( FPath ); } - if ( IsDirectory( FPath ) ) { - std::vector files = FilesGetInPath( FPath ); + if ( FileSystem::IsDirectory( FPath ) ) { + std::vector files = FileSystem::FilesGetInPath( FPath ); int x,y,c, count = 0; for ( Uint32 i = 0; i < files.size(); i++ ) { std::string ImgPath( FPath + files[i] ); - if ( !IsDirectory( ImgPath ) ) { + if ( !FileSystem::IsDirectory( ImgPath ) ) { int res = stbi_info( ImgPath.c_str(), &x, &y, &c ); if ( res ) { diff --git a/src/eepp/utils/string.cpp b/src/eepp/utils/string.cpp deleted file mode 100644 index 3dbe2309a..000000000 --- a/src/eepp/utils/string.cpp +++ /dev/null @@ -1,267 +0,0 @@ -#include -#include -#include -#include - -namespace EE { namespace Utils { - -bool IsCharacter( const eeInt& mValue ) { - return (mValue >= 32 && mValue <= 126) || (mValue >= 161 && mValue <= 255) || (mValue == 9); -} - -bool IsNumber( const eeInt& mValue, bool AllowDot ) { - if ( AllowDot ) - return ( mValue >= 48 && mValue <= 57 ) || mValue == 46; - - return mValue >= 48 && mValue <= 57; -} - -bool IsLetter( const eeInt& mValue ) { - return ( ( (mValue >= 65 && mValue <= 90) || (mValue >= 97 && mValue <= 122) || (mValue >= 192 && mValue <= 255) ) && (mValue != 215) && (mValue != 247) ); -} - -std::string GetDateTimeStr() { - time_t rawtime; - time ( &rawtime ); - -#ifdef EE_COMPILER_MSVC - char buf[256]; - struct tm timeinfo; - localtime_s ( &timeinfo, &rawtime ); - asctime_s( &buf[0], 256, &timeinfo ); - return std::string( buf ); -#else - struct tm * timeinfo; - timeinfo = localtime ( &rawtime ); - return std::string( asctime (timeinfo) ); -#endif -} - -std::vector < String > SplitString ( const String& str, const Uint32& splitchar, const bool& pushEmptyString ) { - std::vector < String > tmp; - String tmpstr; - - for ( eeUint i = 0; i < str.size(); i++ ) { - if ( str[i] == splitchar ) { - if ( pushEmptyString || tmpstr.size() ) { - tmp.push_back(tmpstr); - tmpstr = ""; - } - } else { - tmpstr += str[i]; - } - } - - if ( tmpstr.size() ) - tmp.push_back(tmpstr); - - return tmp; -} - -std::vector < std::string > SplitString ( const std::string& str, const Int8& splitchar, const bool& pushEmptyString ) { - std::vector < std::string > tmp; - std::string tmpstr; - - for ( eeUint i = 0; i < str.size(); i++ ) { - if ( str[i] == splitchar ) { - if ( pushEmptyString || tmpstr.size() ) { - tmp.push_back(tmpstr); - tmpstr = ""; - } - } else { - tmpstr += str[i]; - } - } - - if ( tmpstr.size() ) - tmp.push_back( tmpstr ); - - return tmp; -} - -void StrFormat( char * Buffer, int BufferSize, const char * format, ... ) { - va_list args; - va_start( args, format ); -#ifdef EE_COMPILER_MSVC - _vsnprintf_s( Buffer, BufferSize, BufferSize, format, args ); -#else - vsnprintf( Buffer, BufferSize-1, format, args ); -#endif - va_end( args ); -} - -std::string StrFormated( const char * format, ... ) { - int n, size = 256; - std::string tstr( size, '\0' ); - - va_list args; - - while (1) { - va_start( args, format ); - - #ifdef EE_COMPILER_MSVC - n = _vsnprintf_s( &tstr[0], size, size, format, args ); - #else - n = vsnprintf( &tstr[0], size, format, args ); - #endif - - va_end( args ); - - if ( n > -1 && n < size ) { - tstr.resize( n ); - return tstr; - } - - if ( n > -1 ) // glibc 2.1 - size = n+1; // precisely what is needed - else // glibc 2.0 - size *= 2; // twice the old size - - tstr.resize( size, '\0' ); - } -} - -std::string LTrim( const std::string & str ) { - std::string::size_type pos1 = str.find_first_not_of(' '); - return ( pos1 == std::string::npos ) ? str : str.substr( pos1 ); -} - -std::string Trim( const std::string & str ) { - std::string::size_type pos1 = str.find_first_not_of(' '); - std::string::size_type pos2 = str.find_last_not_of(' '); - return str.substr(pos1 == std::string::npos ? 0 : pos1, pos2 == std::string::npos ? str.length() - 1 : pos2 - pos1 + 1); -} - -void ToUpper( std::string & str ) { - std::transform(str.begin(), str.end(), str.begin(), (int(*)(int)) std::toupper); -} - -void ToLower( std::string & str ) { - std::transform(str.begin(), str.end(), str.begin(), (int(*)(int)) std::tolower); -} - -std::vector stringToUint8( const std::string& str ) { - return std::vector( str.begin(), str.end() ); -} - -std::string Uint8Tostring( const std::vector v ) { - return std::string( v.begin(), v.end() ); -} - -void InsertChar( String& str, const eeUint& pos, const Uint32& tchar ) { - str.insert( str.begin() + pos, tchar ); -} - -std::string StoragePath( std::string appname ) { - char path[256]; - - #if EE_PLATFORM == EE_PLATFORM_WIN - #ifdef EE_COMPILER_MSVC - - char * ppath; - size_t ssize = 256; - - _dupenv_s( &ppath, &ssize, "APPDATA" ); - - StrCopy( path, ppath, 256 ); - - free( ppath ); - - if( !ssize ) - return std::string(); - - #else - char * home = getenv("APPDATA"); - - if( !home ) - return std::string(); - - _snprintf(path, 256, "%s\\%s", home, appname.c_str() ); - - #endif - #else - char *home = getenv("HOME"); - - #if EE_PLATFORM != EE_PLATFORM_MACOSX - int i; - #endif - if(!home) - return std::string(); - - #if EE_PLATFORM == EE_PLATFORM_MACOSX - snprintf(path, 256, "%s/Library/Application Support/%s", home, appname.c_str() ); - #else - snprintf(path, 256, "%s/.%s", home, appname.c_str() ); - for(i = strlen(home)+2; path[i]; i++) - path[i] = std::tolower(path[i]); - #endif - #endif - - return std::string( path ); -} - -void StrCopy( char * Dst, const char * Src, eeUint DstSize ) { - char * DstEnd = Dst + DstSize - 1; - - while ( Dst < DstEnd && *Src ) { - *Dst = *Src; - Dst++; - Src++; - } - - *Dst = 0; -} - -Int32 StrStartsWith( const std::string& Start, const std::string Str ) { - Int32 Pos = -1; - - if ( Str.size() >= Start.size() ) { - for ( Uint32 i = 0; i < Start.size(); i++ ) { - if ( Start[i] == Str[i] ) { - Pos = (Int32)i; - } else { - Pos = -1; - break; - } - } - } - - return Pos; -} - -Int32 StrStartsWith( const String& Start, const String Str ) { - Int32 Pos = -1; - - if ( Str.size() >= Start.size() ) { - for ( Uint32 i = 0; i < Start.size(); i++ ) { - if ( Start[i] == Str[i] ) { - Pos = (Int32)i; - } else { - Pos = -1; - break; - } - } - } - - return Pos; -} - -void ReplaceSubStr( std::string &target, const std::string& that, const std::string& with ) { - std::string::size_type pos=0; - - while( ( pos = target.find( that, pos ) ) != std::string::npos ) { - target.erase( pos, that.length() ); - target.insert( pos, with ); - pos += with.length(); - } -} - -std::string RemoveNumbersAtEnd( std::string txt ) { - while ( txt.size() && txt[ txt.size() - 1 ] >= '0' && txt[ txt.size() - 1 ] <= '9' ) { - txt.resize( txt.size() - 1 ); - } - - return txt; -} - -}} diff --git a/src/eepp/utils/utils.cpp b/src/eepp/utils/utils.cpp index 98aba6720..ce6d98e77 100755 --- a/src/eepp/utils/utils.cpp +++ b/src/eepp/utils/utils.cpp @@ -1,695 +1,7 @@ #include -#include -#include -using namespace EE::System; - -#include - -#if defined( EE_PLATFORM_POSIX ) - #include - - #if EE_PLATFORM != EE_PLATFORM_ANDROID - #include - #else - #include - #define statvfs statfs - #define fstatvfs fstatfs - #endif -#endif - -#if EE_PLATFORM == EE_PLATFORM_MACOSX - #include -#elif EE_PLATFORM == EE_PLATFORM_WIN - #include -#elif EE_PLATFORM == EE_PLATFORM_LINUX || EE_PLATFORM == EE_PLATFORM_ANDROID - #include - #include -#elif EE_PLATFORM == EE_PLATFORM_HAIKU - #include - #include -#elif EE_PLATFORM == EE_PLATFORM_SOLARIS - #include -#endif - -#if EE_PLATFORM == EE_PLATFORM_MACOSX || EE_PLATFORM == EE_PLATFORM_BSD || EE_PLATFORM == EE_PLATFORM_IOS - #include -#endif - -#if EE_PLATFORM == EE_PLATFORM_WIN - #include - #include -#else - #include -#endif - -#ifndef EE_COMPILER_MSVC - #include -#else - #ifndef S_ISDIR - #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) - #endif -#endif namespace EE { namespace Utils { -#if EE_PLATFORM == EE_PLATFORM_WIN - -typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO); - -static std::string GetWindowsArch() { - std::string arch = "Unknown"; - OSVERSIONINFOEX osvi; - SYSTEM_INFO si; - PGNSI pGNSI; - BOOL bOsVersionInfoEx; - - ZeroMemory(&si, sizeof(SYSTEM_INFO)); - ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); - - osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); - bOsVersionInfoEx = GetVersionEx( (OSVERSIONINFO*) &osvi ); - - if( bOsVersionInfoEx == FALSE ) return arch; - - // Call GetNativeSystemInfo if supported or GetSystemInfo otherwise. - pGNSI = (PGNSI) GetProcAddress( GetModuleHandle( TEXT( "kernel32.dll" ) ), "GetNativeSystemInfo" ); - - if( NULL != pGNSI ) { - pGNSI(&si); - } else { - GetSystemInfo(&si); - } - - if ( osvi.dwMajorVersion >= 6 ) { - if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 ) { - arch = "x64"; - } else if (si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_INTEL ) { - arch = "x86"; - } - } else { - arch = "x86"; - } - - return arch; -} - -static std::string GetWindowsVersion() { - std::string os; - OSVERSIONINFOEX osvi; - SYSTEM_INFO si; - PGNSI pGNSI; - BOOL bOsVersionInfoEx; - - ZeroMemory(&si, sizeof(SYSTEM_INFO)); - ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); - - osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); - bOsVersionInfoEx = GetVersionEx( (OSVERSIONINFO*) &osvi ); - - if( bOsVersionInfoEx == FALSE ) return os; - - // Call GetNativeSystemInfo if supported or GetSystemInfo otherwise. - pGNSI = (PGNSI) GetProcAddress( GetModuleHandle( TEXT( "kernel32.dll" ) ), "GetNativeSystemInfo" ); - - if( NULL != pGNSI ) { - pGNSI(&si); - } else { - GetSystemInfo(&si); - } - - os = "Microsoft "; - - if ( VER_PLATFORM_WIN32_NT == osvi.dwPlatformId && osvi.dwMajorVersion > 4 ) { - if ( osvi.dwMajorVersion == 6 ) { - if( osvi.dwMinorVersion == 0 ) { - if( osvi.wProductType == VER_NT_WORKSTATION ) { - os += "Windows Vista"; - } else { - os += "Windows Server 2008"; - } - } - - if ( osvi.dwMinorVersion == 1 ) { - if( osvi.wProductType == VER_NT_WORKSTATION ) { - os += "Windows 7"; - } else { - os += "Windows Server 2008 R2"; - } - } - - if ( osvi.dwMinorVersion == 2 ) { - if( osvi.wProductType == VER_NT_WORKSTATION ) { - os += "Windows 8"; - } else { - os += "Windows Server 2012"; - } - } - } - - if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 ) { - if ( GetSystemMetrics(SM_SERVERR2) ) { - os += "Windows Server 2003 R2, "; - } else if ( osvi.wSuiteMask & VER_SUITE_STORAGE_SERVER ) { - os += "Windows Storage Server 2003"; - } else if ( osvi.wSuiteMask & 0x00008000 ) { //VER_SUITE_WH_SERVER - os += "Windows Home Server"; - } else if ( osvi.wProductType == VER_NT_WORKSTATION && si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 ) { - os += "Windows XP Professional x64 Edition"; - } else { - os += "Windows Server 2003, "; - } - } - - if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 ) { - os += "Windows XP"; - } - - if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 ) { - os += "Windows 2000"; - } - - // Include service pack (if any) and build number. - #if defined( EE_COMPILER_MSVC ) && defined( UNICODE ) - std::string CSDVer( EE::String( osvi.szCSDVersion ).ToUtf8() ); - #else - std::string CSDVer( osvi.szCSDVersion ); - #endif - - if ( CSDVer.size() ) { - os += " " + CSDVer; - } - } else if ( VER_PLATFORM_WIN32_WINDOWS == osvi.dwPlatformId ) { - if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0) { - if (osvi.szCSDVersion[1] == 'C' || - osvi.szCSDVersion[1] == 'B') { - os += "Windows 95 OSR2"; - } else { - os += "Windows 95"; - } - } else if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10) { - if (osvi.szCSDVersion[1] == 'A') { - os += "Windows 98 SE"; - } else { - os += "Windows 98"; - } - } else if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90) { - os += "Windows ME"; - } else if (osvi.dwMajorVersion == 4) { - os += "Windows unknown 95 family"; - } else { - os += "Windows"; - } - } else { - os += "Windows"; - } - - return os; -} - -#define TIME_WRAP_VALUE (~(DWORD)0) -/* The first high-resolution ticks value of the application */ -static LARGE_INTEGER hires_start_ticks; -/* The number of ticks per second of the high-resolution performance counter */ -static LARGE_INTEGER hires_ticks_per_second; - -#endif - -#ifdef EE_PLATFORM_POSIX - -#ifdef EE_HAVE_CLOCK_GETTIME -static struct timespec start; -#else -static struct timeval start; -#endif - -#endif - -std::string GetOSName() { -#if defined( EE_PLATFORM_POSIX ) - struct utsname os; - - if ( -1 != uname( &os ) ) { - return std::string( os.sysname ) + " " + std::string( os.release ); - } - - return "Unknown"; -#elif EE_PLATFORM == EE_PLATFORM_WIN - return GetWindowsVersion(); -#else - return "Unknown"; -#endif -} - -std::string GetOSArchitecture() { -#if defined( EE_PLATFORM_POSIX ) - struct utsname os; - - if ( -1 != uname( &os ) ) { - return std::string( os.machine ); - } - - return "Unknown"; -#elif EE_PLATFORM == EE_PLATFORM_WIN - return GetWindowsArch(); -#else - return "Unknown"; -#endif -} - -bool FileExists( const std::string& Filepath ) { - struct stat st; - return ( stat( Filepath.c_str(), &st ) == 0 ) && !S_ISDIR( st.st_mode ); -} - -static void eeStartTicks() { - static bool TickStarted = false; - - if ( !TickStarted ) { - #if EE_PLATFORM == EE_PLATFORM_WIN - QueryPerformanceFrequency(&hires_ticks_per_second); - QueryPerformanceCounter(&hires_start_ticks); - #else - #ifdef EE_HAVE_CLOCK_GETTIME - clock_gettime(CLOCK_MONOTONIC, &start); - #else - gettimeofday(&start, NULL); - #endif - #endif - - TickStarted = true; - } -} - -Uint32 eeGetTicks() { - eeStartTicks(); - -#if EE_PLATFORM == EE_PLATFORM_WIN - LARGE_INTEGER hires_now; - - QueryPerformanceCounter(&hires_now); - - hires_now.QuadPart -= hires_start_ticks.QuadPart; - hires_now.QuadPart *= 1000; - hires_now.QuadPart /= hires_ticks_per_second.QuadPart; - - return (DWORD) hires_now.QuadPart; -#elif defined( EE_PLATFORM_POSIX ) - #ifdef EE_HAVE_CLOCK_GETTIME - Uint32 ticks; - struct timespec now; - clock_gettime(CLOCK_MONOTONIC, &now); - ticks = - (now.tv_sec - start.tv_sec) * 1000 + (now.tv_nsec - - start.tv_nsec) / 1000000; - return (ticks); - #else - Uint32 ticks; - struct timeval now; - gettimeofday(&now, NULL); - ticks = - (now.tv_sec - start.tv_sec) * 1000 + (now.tv_usec - - start.tv_usec) / 1000; - return (ticks); - #endif -#else - #warning eeGetTicks not implemented in this platform. -#endif -} - -void eeSleep( const Uint32& ms ) { -#if EE_PLATFORM == EE_PLATFORM_WIN - ::Sleep( ms ); -#elif defined( EE_PLATFORM_POSIX ) - // usleep( static_cast( ms * 1000 ) ); - - // usleep is not reliable enough (it might block the - // whole process instead of just the current thread) - // so we must use pthread_cond_timedwait instead - - // this implementation is inspired from Qt - // and taken from SFML - - Uint64 usecs = ms * 1000; - - // get the current time - timeval tv; - gettimeofday(&tv, NULL); - - // construct the time limit (current time + time to wait) - timespec ti; - ti.tv_nsec = (tv.tv_usec + (usecs % 1000000)) * 1000; - ti.tv_sec = tv.tv_sec + (usecs / 1000000) + (ti.tv_nsec / 1000000000); - ti.tv_nsec %= 1000000000; - - // create a mutex and thread condition - pthread_mutex_t mutex; - pthread_mutex_init(&mutex, 0); - pthread_cond_t condition; - pthread_cond_init(&condition, 0); - - // wait... - pthread_mutex_lock(&mutex); - pthread_cond_timedwait(&condition, &mutex, &ti); - pthread_mutex_unlock(&mutex); - - // destroy the mutex and condition - pthread_cond_destroy(&condition); - pthread_mutex_destroy(&mutex); - -#else - #warning eeSleep not implemented in this platform. -#endif -} - -std::string GetProcessPath() { -#if EE_PLATFORM == EE_PLATFORM_MACOSX - char exe_file[PATH_MAX + 1]; - CFBundleRef mainBundle = CFBundleGetMainBundle(); - if (mainBundle) { - CFURLRef mainURL = CFBundleCopyBundleURL(mainBundle); - - if (mainURL) { - int ok = CFURLGetFileSystemRepresentation ( mainURL, (Boolean) true, (UInt8*)exe_file, PATH_MAX ); - - if (ok) { - return std::string(exe_file) + "/"; - } - } - } - - return "./"; -#elif EE_PLATFORM == EE_PLATFORM_LINUX - char exe_file[PATH_MAX + 1]; - int size; - size = readlink("/proc/self/exe", exe_file, PATH_MAX); - if (size < 0) { - return "./"; - } else { - exe_file[size] = '\0'; - return std::string(dirname(exe_file)) + "/"; - } -#elif EE_PLATFORM == EE_PLATFORM_WIN - #ifdef UNICODE - // Get path to executable: - char szDrive[_MAX_DRIVE]; - char szDir[_MAX_DIR]; - char szFilename[_MAX_DIR]; - char szExt[_MAX_DIR]; - std::wstring dllName( _MAX_DIR, 0 ); - - GetModuleFileName(0, &dllName[0], _MAX_PATH); - - std::string dllstrName( String( dllName ).ToUtf8() ); - - #ifdef EE_COMPILER_MSVC - _splitpath_s( dllstrName.c_str(), szDrive, _MAX_DRIVE, szDir, _MAX_DIR, szFilename, _MAX_DIR, szExt, _MAX_DIR ); - #else - _splitpath(szDllName, szDrive, szDir, szFilename, szExt); - #endif - - return std::string( szDrive ) + std::string( szDir ); - #else - // Get path to executable: - TCHAR szDllName[_MAX_PATH]; - TCHAR szDrive[_MAX_DRIVE]; - TCHAR szDir[_MAX_DIR]; - TCHAR szFilename[_MAX_DIR]; - TCHAR szExt[_MAX_DIR]; - GetModuleFileName(0, szDllName, _MAX_PATH); - - #ifdef EE_COMPILER_MSVC - _splitpath_s(szDllName, szDrive, _MAX_DRIVE, szDir, _MAX_DIR, szFilename, _MAX_DIR, szExt, _MAX_DIR ); - #else - _splitpath(szDllName, szDrive, szDir, szFilename, szExt); - #endif - - return std::string(szDrive) + std::string(szDir); - #endif -#elif EE_PLATFORM == EE_PLATFORM_BSD - int mib[4]; - mib[0] = CTL_KERN; - mib[1] = KERN_PROC; - mib[2] = KERN_PROC_PATHNAME; - mib[3] = -1; - char buf[1024]; - size_t cb = sizeof(buf); - sysctl(mib, 4, buf, &cb, NULL, 0); - - return FileRemoveFileName( std::string( buf ) ); -#elif EE_PLATFORM == EE_PLATFORM_SOLARIS - return FileRemoveFileName( std::string( getexecname() ) ); -#elif EE_PLATFORM == EE_PLATFORM_HAIKU - image_info info; - int32 cookie = 0; - - while ( B_OK == get_next_image_info( 0, &cookie, &info ) ) { - if ( info.type == B_APP_IMAGE ) - break; - } - - return FileRemoveFileName( std::string( info.name ) ); -#elif EE_PLATFORM == EE_PLATFORM_ANDROID - return "/sdcard/"; -#else - #warning GetProcessPath() not implemented on this platform. ( will return "./" ) - return "./"; -#endif -} - -std::vector FilesGetInPath( const String& path ) { - std::vector files; - -#ifdef EE_COMPILER_MSVC - #ifdef UNICODE - String mPath( path ); - - if ( mPath[ mPath.size() - 1 ] == '/' || mPath[ mPath.size() - 1 ] == '\\' ) { - mPath += "*"; - } else { - mPath += "\\*"; - } - - WIN32_FIND_DATA findFileData; - HANDLE hFind = FindFirstFile( (LPCWSTR)mPath.ToWideString().c_str(), &findFileData ); - - if( hFind != INVALID_HANDLE_VALUE ) { - String tmpstr( findFileData.cFileName ); - - if ( tmpstr != "." && tmpstr != ".." ) - files.push_back( tmpstr ); - - while( FindNextFile( hFind, &findFileData ) ) { - tmpstr = String( findFileData.cFileName ); - - if ( tmpstr != "." && tmpstr != ".." ) - files.push_back( tmpstr ); - } - - FindClose( hFind ); - } - #else - String mPath( path ); - - if ( mPath[ mPath.size() - 1 ] == '/' || mPath[ mPath.size() - 1 ] == '\\' ) { - mPath += "*"; - } else { - mPath += "\\*"; - } - - WIN32_FIND_DATA findFileData; - HANDLE hFind = FindFirstFile( (LPCTSTR) mPath.ToAnsiString().c_str(), &findFileData ); - - if( hFind != INVALID_HANDLE_VALUE ) { - String tmpstr( String::FromUtf8( findFileData.cFileName ) ); - - if ( tmpstr != "." && tmpstr != ".." ) - files.push_back( tmpstr ); - - while( FindNextFile( hFind, &findFileData ) ) { - tmpstr = String::FromUtf8( findFileData.cFileName ); - - if ( tmpstr != "." && tmpstr != ".." ) - files.push_back( tmpstr ); - } - - FindClose( hFind ); - } - #endif - - return files; -#else - DIR *dp; - struct dirent *dirp; - - if( ( dp = opendir( path.ToUtf8().c_str() ) ) == NULL) - return files; - - while ( ( dirp = readdir(dp) ) != NULL) { - if ( strcmp( dirp->d_name, ".." ) != 0 && strcmp( dirp->d_name, "." ) != 0 ) { - - char * p = &dirp->d_name[0]; - String tmp; - - while ( *p ) { - unsigned char y = *p; - tmp.push_back( y ); - p++; - } - - files.push_back( tmp ); - } - } - - closedir(dp); - - return files; -#endif -} - - -std::vector FilesGetInPath( const std::string& path ) { - std::vector files; - -#ifdef EE_COMPILER_MSVC - #ifdef UNICODE - String mPath( String::FromUtf8( path ) ); - - if ( mPath[ mPath.size() - 1 ] == '/' || mPath[ mPath.size() - 1 ] == '\\' ) { - mPath += "*"; - } else { - mPath += "\\*"; - } - - WIN32_FIND_DATA findFileData; - HANDLE hFind = FindFirstFile( (LPCWSTR)mPath.ToWideString().c_str(), &findFileData ); - - if( hFind != INVALID_HANDLE_VALUE ) { - String tmpstr( findFileData.cFileName ); - - if ( tmpstr != "." && tmpstr != ".." ) - files.push_back( tmpstr.ToUtf8() ); - - while( FindNextFile(hFind, &findFileData ) ) { - tmpstr = String( findFileData.cFileName ); - - if ( tmpstr != "." && tmpstr != ".." ) - files.push_back( String( findFileData.cFileName ).ToUtf8() ); - } - - FindClose( hFind ); - } - #else - std::string mPath( path ); - - if ( mPath[ mPath.size() - 1 ] == '/' || mPath[ mPath.size() - 1 ] == '\\' ) { - mPath += "*"; - } else { - mPath += "\\*"; - } - - WIN32_FIND_DATA findFileData; - HANDLE hFind = FindFirstFile( (LPCTSTR) mPath.c_str(), &findFileData ); - - if( hFind != INVALID_HANDLE_VALUE ) { - std::string tmpstr( findFileData.cFileName ); - - if ( tmpstr != "." && tmpstr != ".." ) - files.push_back( tmpstr ); - - while( FindNextFile(hFind, &findFileData ) ) { - tmpstr = std::string( findFileData.cFileName ); - - if ( tmpstr != "." && tmpstr != ".." ) - files.push_back( std::string( findFileData.cFileName ) ); - } - - FindClose( hFind ); - } - #endif - - return files; -#else - DIR *dp; - struct dirent *dirp; - - if( ( dp = opendir( path.c_str() ) ) == NULL) - return files; - - while ( ( dirp = readdir(dp) ) != NULL) { - if ( strcmp( dirp->d_name, ".." ) != 0 && strcmp( dirp->d_name, "." ) != 0 ) - files.push_back( std::string( dirp->d_name ) ); - } - - closedir(dp); - - return files; -#endif -} - -Uint64 FileSize( const std::string& Filepath ) { - struct stat st; - int res = stat( Filepath.c_str(), &st ); - - if ( 0 == res ) - return st.st_size; - - return 0; -} - -eeDouble GetSystemTime() { -#if EE_PLATFORM == EE_PLATFORM_WIN - static LARGE_INTEGER Frequency; - static BOOL UseHighPerformanceTimer = QueryPerformanceFrequency(&Frequency); - - if (UseHighPerformanceTimer) { - // High performance counter available : use it - LARGE_INTEGER CurrentTime; - QueryPerformanceCounter(&CurrentTime); - return static_cast(CurrentTime.QuadPart) / Frequency.QuadPart; - } else - // High performance counter not available : use GetTickCount (less accurate) - return GetTickCount() * 0.001; -#else - timeval Time = {0, 0}; - gettimeofday(&Time, NULL); - - return Time.tv_sec + Time.tv_usec / 1000000.; -#endif -} - -bool IsDirectory( const String& path ) { - return IsDirectory( path.ToUtf8() ); -} - -bool IsDirectory( const std::string& path ) { -#ifndef EE_COMPILER_MSVC - DIR *dp = NULL; - - bool isdir = !( ( dp = opendir( path.c_str() ) ) == NULL); - - if ( NULL != dp ) - closedir(dp); - - return isdir; -#else - return GetFileAttributes( (LPCTSTR) path.c_str() ) == FILE_ATTRIBUTE_DIRECTORY; -#endif -} - -bool MakeDir( const std::string& path, const Uint16& mode ) { - Int16 v; -#if EE_PLATFORM == EE_PLATFORM_WIN - #ifdef EE_COMPILER_MSVC - v = _mkdir( path.c_str() ); - #else - v = mkdir( path.c_str() ); - #endif -#else - v = mkdir( path.c_str(), mode ); -#endif - return v == 0; -} - Uint32 MakeHash( const std::string& str ) { return MakeHash( reinterpret_cast( &str[0] ) ); } @@ -709,236 +21,6 @@ Uint32 MakeHash( const Uint8 * str ) { return 0; } -bool FileGet( const std::string& path, SafeDataPointer& data ) { - if ( FileExists( path ) ) { - cIOStreamFile fs ( path , std::ios::in | std::ios::binary ); - - eeSAFE_DELETE( data.Data ); - - data.DataSize = FileSize( path ); - data.Data = eeNewArray( Uint8, ( data.DataSize ) ); - - fs.Read( reinterpret_cast ( data.Data ), data.DataSize ); - - return true; - } - - return false; -} - -bool FileGet( const std::string& path, std::vector& data ) { - if ( FileExists( path ) ) { - cIOStreamFile fs ( path, std::ios::in | std::ios::binary ); - Uint32 fsize = FileSize( path ); - - data.clear(); - data.resize( fsize ); - - fs.Read( reinterpret_cast (&data[0]), fsize ); - - return true; - } - - return false; -} - -bool FileCopy( const std::string& src, const std::string& dst ) { - if ( FileExists( src ) ) { - Int64 chunksize = EE_1MB; - Int64 size = FileSize( src ); - Int64 size_left = (Int32)size; - Int64 allocate = ( size < chunksize ) ? size : chunksize; - Int64 copysize = 0; - - SafeDataPointer data; - data.DataSize = (Uint32)allocate; - data.Data = eeNewArray( Uint8, ( data.DataSize ) ); - char * buff = (char*)data.Data; - - cIOStreamFile in( src, std::ios::binary | std::ios::in ); - cIOStreamFile out( dst, std::ios::binary | std::ios::out ); - - if ( in.IsOpen() && out.IsOpen() && size > 0 ) { - do { - if ( size_left - chunksize < 0 ) { - copysize = size_left; - } else { - copysize = chunksize; - } - - in.Read ( &buff[0], copysize ); - out.Write ( (const char*)&buff[0], copysize ); - - size_left -= copysize; - } while ( size_left > 0 ); - - return true; - } - } - - return false; -} - -std::string FileExtension( const std::string& filepath, const bool& lowerExt ) { - std::string tstr( filepath.substr( filepath.find_last_of(".") + 1 ) ); - - if ( lowerExt ) - ToLower( tstr ); - - return tstr; -} - -std::string FileRemoveExtension( const std::string& filepath ) { - return filepath.substr( 0, filepath.find_last_of(".") ); -} - -std::string FileNameFromPath( const std::string& filepath ) { - return filepath.substr( filepath.find_last_of("/\\") + 1 ); -} - -std::string FileRemoveFileName( const std::string& filepath ) { - return filepath.substr( 0, filepath.find_last_of("/\\") + 1 ); -} - -void FilePathRemoveProcessPath( std::string& path ) { - static std::string ProcessPath = GetProcessPath(); - - Int32 pos = StrStartsWith( ProcessPath, path ); - - if ( -1 != pos && (Uint32)(pos + 1) < path.size() ) - path = path.substr( pos + 1 ); -} - -eeInt GetCPUCount() { - eeInt nprocs = -1; - - #if EE_PLATFORM == EE_PLATFORM_WIN - SYSTEM_INFO info; - GetSystemInfo(&info); - - nprocs = (eeInt) info.dwNumberOfProcessors; - #elif EE_PLATFORM == EE_PLATFORM_LINUX || EE_PLATFORM == EE_PLATFORM_SOLARIS || EE_PLATFORM == EE_PLATFORM_ANDROID - nprocs = sysconf(_SC_NPROCESSORS_ONLN); - #elif EE_PLATFORM == EE_PLATFORM_MACOSX || EE_PLATFORM == EE_PLATFORM_BSD || EE_PLATFORM == EE_PLATFORM_IOS - int mib[2]; - int maxproc = 1; - size_t len = sizeof(int); - - mib[0] = CTL_HW; - mib[1] = HW_NCPU; - - len = sizeof(maxproc); - - sysctl( mib, 2, &maxproc, &len, NULL, 0 ); - - nprocs = maxproc; - #elif EE_PLATFORM == EE_PLATFORM_HAIKU - system_info info; - - if ( B_OK == get_system_info( &info ) ) { - nprocs = info.cpu_count; - } - #else - #warning GetCPUCount not implemented on this platform ( it will return 1 ). - #endif - - if ( nprocs < 1 ) - nprocs = 1; - - return nprocs; -} - -bool FileWrite( const std::string& filepath, const Uint8* data, const Uint32& dataSize ) { - cIOStreamFile fs( filepath, std::ios::out | std::ios::binary ); - - if ( fs.IsOpen() ) { - fs.Write( reinterpret_cast (data), dataSize ); - return true; - } - - return false; -} - -bool FileWrite( const std::string& filepath, const std::vector& data ) { - return FileWrite( filepath, reinterpret_cast ( &data[0] ), (Uint32)data.size() ); -} - -Uint32 FileGetModificationDate( const std::string& Filepath ) { - struct stat st; - int res = stat( Filepath.c_str(), &st ); - - if ( 0 == res ) - return (Uint32)st.st_mtime; - - return 0; -} - -void DirPathAddSlashAtEnd( std::string& path ) { - if ( path.size() && path[ path.size() - 1 ] != '/' && path[ path.size() - 1 ] != '\\' ) - path += GetOSlash(); -} - -std::string GetOSlash() { - #if EE_PLATFORM == EE_PLATFORM_WIN - return std::string( "\\" ); - #else - return std::string( "/" ); - #endif -} - -std::string RemoveLastFolderFromPath( std::string path ) { - if ( path.size() > 1 && ( path[ path.size() - 1 ] == '/' || path[ path.size() - 1 ] == '\\' ) ) { - path.resize( path.size() - 1 ); - } - - std::size_t pos = path.find_last_of( GetOSlash() ); - - if ( std::string::npos != pos ) { - std::string sstr; - std::size_t pos2 = path.find_first_of( GetOSlash() ); - - if ( pos2 != pos ) { - sstr = path.substr(0,pos) + GetOSlash(); - } else { - if ( pos == pos2 ) { - sstr = path.substr(0,pos2+1); - } - } - - if ( sstr.size() ) { - DirPathAddSlashAtEnd( sstr ); - - return sstr; - } - } - - DirPathAddSlashAtEnd( path ); - - return path; -} - -std::string SizeToString( const Uint32& MemSize ) { - std::string size = " bytes"; - eeDouble mem = static_cast( MemSize ); - Uint8 c = 0; - - while ( mem > 1024 ) { - c++; - mem = mem / 1024; - } - - switch (c) { - case 0: size = " bytes"; break; - case 1: size = " KB"; break; - case 2: size = " MB"; break; - case 3: size = " GB"; break; - case 4: size = " TB"; break; - default: size = " WTF"; - } - - return std::string( toStr( mem ) + size ); -} - void Write32BitKey( Uint32 * Key, Uint32 Pos, Uint32 BitWrite ) { if ( BitWrite ) ( * Key ) |= ( 1 << Pos ); @@ -961,26 +43,4 @@ void SetFlagValue( Uint32 * Key, Uint32 Val, Uint32 BitWrite ) { } } -Int64 GetDiskFreeSpace(const std::string& path) { -#if defined( EE_PLATFORM_POSIX ) - struct statvfs data; - statvfs(path.c_str(), &data); - return (Int64)data.f_bsize * (Int64)data.f_bfree; -#elif EE_PLATFORM == EE_PLATFORM_WIN - Int64 AvailableBytes; - Int64 TotalBytes; - Int64 FreeBytes; - #ifdef UNICODE - GetDiskFreeSpaceEx((LPCWSTR)path.c_str(),(PULARGE_INTEGER) &AvailableBytes, - #else - GetDiskFreeSpaceEx(path.c_str(),(PULARGE_INTEGER) &AvailableBytes, - #endif - (PULARGE_INTEGER) &TotalBytes, (PULARGE_INTEGER) &FreeBytes); - - return FreeBytes; -#else - return -1; -#endif -} - }} diff --git a/src/eepp/window/backend/SDL/base.hpp b/src/eepp/window/backend/SDL/base.hpp index c36c9968d..82b054175 100644 --- a/src/eepp/window/backend/SDL/base.hpp +++ b/src/eepp/window/backend/SDL/base.hpp @@ -9,8 +9,6 @@ #ifndef EE_BACKEND_SDL_1_2 #define EE_BACKEND_SDL_1_2 #endif - - #include #endif #endif diff --git a/src/eepp/window/backend/SDL/cbackendsdl.cpp b/src/eepp/window/backend/SDL/cbackendsdl.cpp new file mode 100644 index 000000000..d729e77e4 --- /dev/null +++ b/src/eepp/window/backend/SDL/cbackendsdl.cpp @@ -0,0 +1,21 @@ +#include + +#ifdef EE_BACKEND_SDL_1_2 + +#include + +namespace EE { namespace Window { namespace Backend { namespace SDL { + +cBackendSDL::cBackendSDL() : + cBackend() +{ +} + +cBackendSDL::~cBackendSDL() +{ + SDL_Quit(); +} + +}}}} + +#endif diff --git a/src/eepp/window/backend/SDL/cbackendsdl.hpp b/src/eepp/window/backend/SDL/cbackendsdl.hpp index 25e7dcaa0..b30e185f4 100644 --- a/src/eepp/window/backend/SDL/cbackendsdl.hpp +++ b/src/eepp/window/backend/SDL/cbackendsdl.hpp @@ -2,9 +2,9 @@ #define EE_WINDOWCBACKENDSDL_HPP #include -#include +#include -#ifdef EE_BACKEND_SDL_1_2 +#ifdef EE_BACKEND_SDL_1_2 #include @@ -12,14 +12,9 @@ namespace EE { namespace Window { namespace Backend { namespace SDL { class EE_API cBackendSDL : public cBackend { public: - inline cBackendSDL() : cBackend() - { - } + cBackendSDL(); - inline ~cBackendSDL() - { - SDL_Quit(); - } + ~cBackendSDL(); }; }}}} diff --git a/src/eepp/window/backend/SDL/cclipboardsdl.cpp b/src/eepp/window/backend/SDL/cclipboardsdl.cpp index 35989b8e6..abeb37662 100644 --- a/src/eepp/window/backend/SDL/cclipboardsdl.cpp +++ b/src/eepp/window/backend/SDL/cclipboardsdl.cpp @@ -1,8 +1,11 @@ #include -#include #ifdef EE_BACKEND_SDL_1_2 +#include +#include +#include + namespace EE { namespace Window { namespace Backend { namespace SDL { #define T(A, B, C, D) (int)((A<<24)|(B<<16)|(C<<8)|(D<<0)) @@ -86,7 +89,7 @@ void cClipboardSDL::Init() { #endif #if EE_PLATFORM == EE_PLATFORM_WIN || EE_PLATFORM == EE_PLATFORM_MACOSX || defined( EE_X11_PLATFORM ) - mInfo = &( reinterpret_cast ( mWindow )->mWMinfo ); + mInfo = reinterpret_cast ( mWindow )->mWMinfo; #endif } @@ -177,7 +180,7 @@ eeScrapType cClipboardSDL::clipboard_convert_format( int type ) { #endif default: { char format[ sizeof(FORMAT_PREFIX)+8+1 ]; - StrFormat(format, sizeof(FORMAT_PREFIX)+8+1, "%s%08lx", FORMAT_PREFIX, (unsigned long)type); + String::StrFormat(format, sizeof(FORMAT_PREFIX)+8+1, "%s%08lx", FORMAT_PREFIX, (unsigned long)type); #if defined( EE_X11_PLATFORM ) return XInternAtom( mInfo->info.x11.display, format, False ); diff --git a/src/eepp/window/backend/SDL/cclipboardsdl.hpp b/src/eepp/window/backend/SDL/cclipboardsdl.hpp index 5553dce65..ddb66d9bd 100644 --- a/src/eepp/window/backend/SDL/cclipboardsdl.hpp +++ b/src/eepp/window/backend/SDL/cclipboardsdl.hpp @@ -8,6 +8,8 @@ #include +class SDL_SysWMinfo; + #if EE_PLATFORM == EE_PLATFORM_WIN || EE_PLATFORM == EE_PLATFORM_MACOSX || defined( EE_X11_PLATFORM ) #include #endif diff --git a/src/eepp/window/backend/SDL/ccursormanagersdl.cpp b/src/eepp/window/backend/SDL/ccursormanagersdl.cpp index 6d49e9a46..c50361165 100644 --- a/src/eepp/window/backend/SDL/ccursormanagersdl.cpp +++ b/src/eepp/window/backend/SDL/ccursormanagersdl.cpp @@ -3,6 +3,8 @@ #ifdef EE_BACKEND_SDL_1_2 +#include + namespace EE { namespace Window { namespace Backend { namespace SDL { cCursorManagerSDL::cCursorManagerSDL( cWindow * window ) : diff --git a/src/eepp/window/backend/SDL/cinputsdl.cpp b/src/eepp/window/backend/SDL/cinputsdl.cpp index 75818d85b..63e224ff9 100644 --- a/src/eepp/window/backend/SDL/cinputsdl.cpp +++ b/src/eepp/window/backend/SDL/cinputsdl.cpp @@ -4,6 +4,12 @@ #ifdef EE_BACKEND_SDL_1_2 +#include + +#if EE_PLATFORM == EE_PLATFORM_WIN || EE_PLATFORM == EE_PLATFORM_MACOSX || defined( EE_X11_PLATFORM ) + #include +#endif + namespace EE { namespace Window { namespace Backend { namespace SDL { cInputSDL::cInputSDL( cWindow * window ) : @@ -34,9 +40,9 @@ void cInputSDL::Update() { } case SDL_KEYDOWN: { - if ( IsCharacter( SDLEvent.key.keysym.unicode ) && KEY_TAB != SDLEvent.key.keysym.unicode ) { + if ( String::IsCharacter( SDLEvent.key.keysym.unicode ) && KEY_TAB != SDLEvent.key.keysym.unicode ) { EEEvent.Type = InputEvent::TextInput; - EEEvent.text.timestamp = eeGetTicks(); + EEEvent.text.timestamp = Sys::GetTicks(); EEEvent.text.text = SDLEvent.key.keysym.unicode; ProcessEvent( &EEEvent ); diff --git a/src/eepp/window/backend/SDL/cinputsdl.hpp b/src/eepp/window/backend/SDL/cinputsdl.hpp index d3a5e57ac..043debeb9 100644 --- a/src/eepp/window/backend/SDL/cinputsdl.hpp +++ b/src/eepp/window/backend/SDL/cinputsdl.hpp @@ -8,10 +8,6 @@ #include -#if EE_PLATFORM == EE_PLATFORM_WIN || EE_PLATFORM == EE_PLATFORM_MACOSX || defined( EE_X11_PLATFORM ) - #include -#endif - namespace EE { namespace Window { namespace Backend { namespace SDL { class EE_API cInputSDL : public cInput { diff --git a/src/eepp/window/backend/SDL/cjoystickmanagersdl.cpp b/src/eepp/window/backend/SDL/cjoystickmanagersdl.cpp index 8314c73eb..1208ef7f0 100644 --- a/src/eepp/window/backend/SDL/cjoystickmanagersdl.cpp +++ b/src/eepp/window/backend/SDL/cjoystickmanagersdl.cpp @@ -3,6 +3,8 @@ #ifdef EE_BACKEND_SDL_1_2 +#include + namespace EE { namespace Window { namespace Backend { namespace SDL { cJoystickManagerSDL::cJoystickManagerSDL() : diff --git a/src/eepp/window/backend/SDL/cjoysticksdl.hpp b/src/eepp/window/backend/SDL/cjoysticksdl.hpp index 80238397c..0c993a38c 100644 --- a/src/eepp/window/backend/SDL/cjoysticksdl.hpp +++ b/src/eepp/window/backend/SDL/cjoysticksdl.hpp @@ -2,11 +2,12 @@ #define EE_WINDOWCJOYSTICKSDL_HPP #include -#include +#include #ifdef EE_BACKEND_SDL_1_2 #include +#include namespace EE { namespace Window { namespace Backend { namespace SDL { diff --git a/src/eepp/window/backend/SDL/cwindowsdl.cpp b/src/eepp/window/backend/SDL/cwindowsdl.cpp index 58f537a28..adec307f5 100644 --- a/src/eepp/window/backend/SDL/cwindowsdl.cpp +++ b/src/eepp/window/backend/SDL/cwindowsdl.cpp @@ -2,6 +2,12 @@ #ifdef EE_BACKEND_SDL_1_2 +#include + +#if EE_PLATFORM == EE_PLATFORM_WIN || EE_PLATFORM == EE_PLATFORM_MACOSX || defined( EE_X11_PLATFORM ) +#include +#endif + #include #include #include @@ -17,12 +23,15 @@ namespace EE { namespace Window { namespace Backend { namespace SDL { cWindowSDL::cWindowSDL( WindowSettings Settings, ContextSettings Context ) : - cWindow( Settings, Context, eeNew( cClipboardSDL, ( this ) ), eeNew( cInputSDL, ( this ) ), eeNew( cCursorManagerSDL, ( this ) ) ) + cWindow( Settings, Context, eeNew( cClipboardSDL, ( this ) ), eeNew( cInputSDL, ( this ) ), eeNew( cCursorManagerSDL, ( this ) ) ), + mSurface( NULL ), + mWMinfo( (SDL_SysWMinfo*)eeMalloc( sizeof( mWMinfo ) ) ) { Create( Settings, Context ); } cWindowSDL::~cWindowSDL() { + eeSAFE_FREE( mWMinfo ); } bool cWindowSDL::Create( WindowSettings Settings, ContextSettings Context ) { @@ -137,23 +146,24 @@ bool cWindowSDL::Create( WindowSettings Settings, ContextSettings Context ) { std::string cWindowSDL::GetVersion() { #if EE_PLATFORM == EE_PLATFORM_WIN || EE_PLATFORM == EE_PLATFORM_MACOSX || defined( EE_X11_PLATFORM ) - SDL_version ver = mWMinfo.version; + SDL_version ver = mWMinfo->version; - return StrFormated( "SDL %d.%d.%d", ver.major, ver.minor, ver.patch ); + return String::StrFormated( "SDL %d.%d.%d", ver.major, ver.minor, ver.patch ); #else - return StrFormated( "SDL %d.%d.%d", SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL ); + return String::StrFormated( "SDL %d.%d.%d", SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL ); #endif } void cWindowSDL::CreatePlatform() { eeSAFE_DELETE( mPlatform ); #if EE_PLATFORM == EE_PLATFORM_WIN || EE_PLATFORM == EE_PLATFORM_MACOSX || defined( EE_X11_PLATFORM ) - SDL_VERSION( &mWMinfo.version ); - SDL_GetWMInfo ( &mWMinfo ); + SDL_VERSION( &mWMinfo->version ); + + SDL_GetWMInfo ( mWMinfo ); #endif #if defined( EE_X11_PLATFORM ) - mPlatform = eeNew( Platform::cX11Impl, ( this, mWMinfo.info.x11.display, mWMinfo.info.x11.wmwindow, mWMinfo.info.x11.window, mWMinfo.info.x11.lock_func, mWMinfo.info.x11.unlock_func ) ); + mPlatform = eeNew( Platform::cX11Impl, ( this, mWMinfo->info.x11.display, mWMinfo->info.x11.wmwindow, mWMinfo->info.x11.window, mWMinfo->info.x11.lock_func, mWMinfo->info.x11.unlock_func ) ); #elif EE_PLATFORM == EE_PLATFORM_WIN mPlatform = eeNew( Platform::cWinImpl, ( this, GetWindowHandler() ) ); #elif EE_PLATFORM == EE_PLATFORM_MACOSX @@ -372,11 +382,11 @@ void cWindowSDL::SetGamma( eeFloat Red, eeFloat Green, eeFloat Blue ) { eeWindowHandler cWindowSDL::GetWindowHandler() { #if EE_PLATFORM == EE_PLATFORM_WIN - return mWMinfo.window; + return mWMinfo->window; #elif defined( EE_X11_PLATFORM ) - return mWMinfo.info.x11.display; + return mWMinfo->info.x11.display; #elif EE_PLATFORM == EE_PLATFORM_MACOSX - return mWMinfo.info.x11.display; + return mWMinfo->info.x11.display; #else return 0; #endif diff --git a/src/eepp/window/backend/SDL/cwindowsdl.hpp b/src/eepp/window/backend/SDL/cwindowsdl.hpp index 6e757e669..32204bc19 100644 --- a/src/eepp/window/backend/SDL/cwindowsdl.hpp +++ b/src/eepp/window/backend/SDL/cwindowsdl.hpp @@ -8,9 +8,8 @@ #include -#if EE_PLATFORM == EE_PLATFORM_WIN || EE_PLATFORM == EE_PLATFORM_MACOSX || defined( EE_X11_PLATFORM ) -#include -#endif +class SDL_Surface; +class SDL_SysWMinfo; namespace EE { namespace Window { namespace Backend { namespace SDL { @@ -45,7 +44,7 @@ class EE_API cWindowSDL : public cWindow { SDL_Surface * mSurface; #if EE_PLATFORM == EE_PLATFORM_WIN || EE_PLATFORM == EE_PLATFORM_MACOSX || defined( EE_X11_PLATFORM ) - SDL_SysWMinfo mWMinfo; + SDL_SysWMinfo * mWMinfo; #endif eeVector2i mWinPos; diff --git a/src/eepp/window/backend/SDL2/base.hpp b/src/eepp/window/backend/SDL2/base.hpp index 2f843566b..93893c661 100644 --- a/src/eepp/window/backend/SDL2/base.hpp +++ b/src/eepp/window/backend/SDL2/base.hpp @@ -5,22 +5,18 @@ #ifdef EE_BACKEND_SDL_ACTIVE - #if defined( EE_SDL_VERSION_1_3 ) || defined( EE_SDL_VERSION_2 ) + #if defined( EE_SDL_VERSION_2 ) #ifndef EE_BACKEND_SDL2 #define EE_BACKEND_SDL2 #endif + + #include #else #ifndef EE_BACKEND_SDL_1_2 #define EE_BACKEND_SDL_1_2 #endif #endif - #if defined( EE_SDL_VERSION_1_3 ) - #include - #elif defined( EE_SDL_VERSION_2 ) - #include - #endif - #endif #endif diff --git a/src/eepp/window/backend/SDL2/cbackendsdl.hpp b/src/eepp/window/backend/SDL2/cbackendsdl.hpp deleted file mode 100644 index bec7500ce..000000000 --- a/src/eepp/window/backend/SDL2/cbackendsdl.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef EE_WINDOWCBACKENDSDL2_HPP -#define EE_WINDOWCBACKENDSDL2_HPP - -#include - -#ifdef EE_BACKEND_SDL_ACTIVE - -#include - -namespace EE { namespace Window { namespace Backend { namespace SDL2 { - -class EE_API cBackendSDL : public cBackend { - public: - inline cBackendSDL() : cBackend() - { - } - - inline ~cBackendSDL() - { - SDL_Quit(); - } -}; - -}}}} - -#endif - -#endif diff --git a/src/eepp/window/backend/SDL2/cbackendsdl2.cpp b/src/eepp/window/backend/SDL2/cbackendsdl2.cpp new file mode 100644 index 000000000..5e2e22d76 --- /dev/null +++ b/src/eepp/window/backend/SDL2/cbackendsdl2.cpp @@ -0,0 +1,21 @@ +#include + +#ifdef EE_BACKEND_SDL2 + +#include + +namespace EE { namespace Window { namespace Backend { namespace SDL2 { + +cBackendSDL2::cBackendSDL2() : + cBackend() +{ +} + +cBackendSDL2::~cBackendSDL2() +{ + SDL_Quit(); +} + +}}}} + +#endif diff --git a/src/eepp/window/backend/SDL2/cbackendsdl2.hpp b/src/eepp/window/backend/SDL2/cbackendsdl2.hpp new file mode 100644 index 000000000..cbc1935bc --- /dev/null +++ b/src/eepp/window/backend/SDL2/cbackendsdl2.hpp @@ -0,0 +1,24 @@ +#ifndef EE_WINDOWCBACKENDSDL2_HPP +#define EE_WINDOWCBACKENDSDL2_HPP + +#include +#include + +#ifdef EE_BACKEND_SDL2 + +#include + +namespace EE { namespace Window { namespace Backend { namespace SDL2 { + +class EE_API cBackendSDL2 : public cBackend { + public: + cBackendSDL2(); + + ~cBackendSDL2(); +}; + +}}}} + +#endif + +#endif diff --git a/src/eepp/window/backend/SDL2/cclipboardsdl.cpp b/src/eepp/window/backend/SDL2/cclipboardsdl2.cpp similarity index 85% rename from src/eepp/window/backend/SDL2/cclipboardsdl.cpp rename to src/eepp/window/backend/SDL2/cclipboardsdl2.cpp index bd26ccd75..60991af85 100644 --- a/src/eepp/window/backend/SDL2/cclipboardsdl.cpp +++ b/src/eepp/window/backend/SDL2/cclipboardsdl2.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include #ifdef EE_BACKEND_SDL2 diff --git a/src/eepp/window/backend/SDL2/cclipboardsdl.hpp b/src/eepp/window/backend/SDL2/cclipboardsdl2.hpp similarity index 100% rename from src/eepp/window/backend/SDL2/cclipboardsdl.hpp rename to src/eepp/window/backend/SDL2/cclipboardsdl2.hpp diff --git a/src/eepp/window/backend/SDL2/ccursormanagersdl.cpp b/src/eepp/window/backend/SDL2/ccursormanagersdl2.cpp similarity index 93% rename from src/eepp/window/backend/SDL2/ccursormanagersdl.cpp rename to src/eepp/window/backend/SDL2/ccursormanagersdl2.cpp index e07eeb216..01186d8cb 100644 --- a/src/eepp/window/backend/SDL2/ccursormanagersdl.cpp +++ b/src/eepp/window/backend/SDL2/ccursormanagersdl2.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include #ifdef EE_BACKEND_SDL2 diff --git a/src/eepp/window/backend/SDL2/ccursormanagersdl.hpp b/src/eepp/window/backend/SDL2/ccursormanagersdl2.hpp similarity index 100% rename from src/eepp/window/backend/SDL2/ccursormanagersdl.hpp rename to src/eepp/window/backend/SDL2/ccursormanagersdl2.hpp diff --git a/src/eepp/window/backend/SDL2/ccursorsdl.cpp b/src/eepp/window/backend/SDL2/ccursorsdl2.cpp similarity index 97% rename from src/eepp/window/backend/SDL2/ccursorsdl.cpp rename to src/eepp/window/backend/SDL2/ccursorsdl2.cpp index 1dd383238..acc82a353 100644 --- a/src/eepp/window/backend/SDL2/ccursorsdl.cpp +++ b/src/eepp/window/backend/SDL2/ccursorsdl2.cpp @@ -1,4 +1,4 @@ -#include +#include #ifdef EE_BACKEND_SDL2 diff --git a/src/eepp/window/backend/SDL2/ccursorsdl.hpp b/src/eepp/window/backend/SDL2/ccursorsdl2.hpp similarity index 100% rename from src/eepp/window/backend/SDL2/ccursorsdl.hpp rename to src/eepp/window/backend/SDL2/ccursorsdl2.hpp diff --git a/src/eepp/window/backend/SDL2/cinputsdl.cpp b/src/eepp/window/backend/SDL2/cinputsdl2.cpp similarity index 98% rename from src/eepp/window/backend/SDL2/cinputsdl.cpp rename to src/eepp/window/backend/SDL2/cinputsdl2.cpp index 5be59ea39..0818285cb 100644 --- a/src/eepp/window/backend/SDL2/cinputsdl.cpp +++ b/src/eepp/window/backend/SDL2/cinputsdl2.cpp @@ -1,7 +1,7 @@ -#include -#include -#include -#include +#include +#include +#include +#include #ifdef EE_BACKEND_SDL2 diff --git a/src/eepp/window/backend/SDL2/cinputsdl.hpp b/src/eepp/window/backend/SDL2/cinputsdl2.hpp similarity index 100% rename from src/eepp/window/backend/SDL2/cinputsdl.hpp rename to src/eepp/window/backend/SDL2/cinputsdl2.hpp diff --git a/src/eepp/window/backend/SDL2/cjoystickmanagersdl.cpp b/src/eepp/window/backend/SDL2/cjoystickmanagersdl2.cpp similarity index 89% rename from src/eepp/window/backend/SDL2/cjoystickmanagersdl.cpp rename to src/eepp/window/backend/SDL2/cjoystickmanagersdl2.cpp index 6fb80259b..b66f2045e 100644 --- a/src/eepp/window/backend/SDL2/cjoystickmanagersdl.cpp +++ b/src/eepp/window/backend/SDL2/cjoystickmanagersdl2.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include #ifdef EE_BACKEND_SDL2 diff --git a/src/eepp/window/backend/SDL2/cjoystickmanagersdl.hpp b/src/eepp/window/backend/SDL2/cjoystickmanagersdl2.hpp similarity index 100% rename from src/eepp/window/backend/SDL2/cjoystickmanagersdl.hpp rename to src/eepp/window/backend/SDL2/cjoystickmanagersdl2.hpp diff --git a/src/eepp/window/backend/SDL2/cjoysticksdl.cpp b/src/eepp/window/backend/SDL2/cjoysticksdl2.cpp similarity index 96% rename from src/eepp/window/backend/SDL2/cjoysticksdl.cpp rename to src/eepp/window/backend/SDL2/cjoysticksdl2.cpp index 5267e8882..167355389 100644 --- a/src/eepp/window/backend/SDL2/cjoysticksdl.cpp +++ b/src/eepp/window/backend/SDL2/cjoysticksdl2.cpp @@ -1,4 +1,4 @@ -#include +#include #ifdef EE_BACKEND_SDL2 diff --git a/src/eepp/window/backend/SDL2/cjoysticksdl.hpp b/src/eepp/window/backend/SDL2/cjoysticksdl2.hpp similarity index 100% rename from src/eepp/window/backend/SDL2/cjoysticksdl.hpp rename to src/eepp/window/backend/SDL2/cjoysticksdl2.hpp diff --git a/src/eepp/window/backend/SDL2/cwindowsdl.cpp b/src/eepp/window/backend/SDL2/cwindowsdl2.cpp similarity index 97% rename from src/eepp/window/backend/SDL2/cwindowsdl.cpp rename to src/eepp/window/backend/SDL2/cwindowsdl2.cpp index a25673ceb..7036dc23d 100644 --- a/src/eepp/window/backend/SDL2/cwindowsdl.cpp +++ b/src/eepp/window/backend/SDL2/cwindowsdl2.cpp @@ -1,10 +1,10 @@ -#include +#include #ifdef EE_BACKEND_SDL2 -#include -#include -#include +#include +#include +#include #include #include @@ -165,7 +165,7 @@ std::string cWindowSDL::GetVersion() { SDL_GetVersion( &ver ); - return StrFormated( "SDL %d.%d.%d", ver.major, ver.minor, ver.patch ); + return String::StrFormated( "SDL %d.%d.%d", ver.major, ver.minor, ver.patch ); } void cWindowSDL::CreatePlatform() { diff --git a/src/eepp/window/backend/SDL2/cwindowsdl.hpp b/src/eepp/window/backend/SDL2/cwindowsdl2.hpp similarity index 94% rename from src/eepp/window/backend/SDL2/cwindowsdl.hpp rename to src/eepp/window/backend/SDL2/cwindowsdl2.hpp index ea3b0d66d..72c653fa5 100644 --- a/src/eepp/window/backend/SDL2/cwindowsdl.hpp +++ b/src/eepp/window/backend/SDL2/cwindowsdl2.hpp @@ -9,11 +9,7 @@ #include #if EE_PLATFORM == EE_PLATFORM_WIN || EE_PLATFORM == EE_PLATFORM_MACOSX || defined( EE_X11_PLATFORM ) - #if defined( EE_SDL_VERSION_1_3 ) - #include - #else - #include - #endif + #include #endif namespace EE { namespace Window { namespace Backend { namespace SDL2 { diff --git a/src/eepp/window/backend/SFML/cinputsfml.cpp b/src/eepp/window/backend/SFML/cinputsfml.cpp index fd479b344..c09c36069 100644 --- a/src/eepp/window/backend/SFML/cinputsfml.cpp +++ b/src/eepp/window/backend/SFML/cinputsfml.cpp @@ -122,7 +122,7 @@ void cInputSFML::Update() { { if ( KEY_TAB != event.text.unicode ) { EEEvent.Type = InputEvent::TextInput; - EEEvent.text.timestamp = eeGetTicks(); + EEEvent.text.timestamp = Sys::GetTicks(); EEEvent.text.text = event.text.unicode; ProcessEvent( &EEEvent ); diff --git a/src/eepp/window/backend/SFML/cjoysticksfml.cpp b/src/eepp/window/backend/SFML/cjoysticksfml.cpp index 00112342f..d20793028 100644 --- a/src/eepp/window/backend/SFML/cjoysticksfml.cpp +++ b/src/eepp/window/backend/SFML/cjoysticksfml.cpp @@ -20,7 +20,7 @@ cJoystickSFML::~cJoystickSFML() { } void cJoystickSFML::Open() { - mName = "Joystick " + toStr( mIndex ); + mName = "Joystick " + String::toStr( mIndex ); mHats = 0; mButtons = eemin( sf::Joystick::getButtonCount( mIndex ), (unsigned int)32 ); mAxes = sf::Joystick::AxisCount; diff --git a/src/eepp/window/cengine.cpp b/src/eepp/window/cengine.cpp index 2dd496164..214bc1993 100755 --- a/src/eepp/window/cengine.cpp +++ b/src/eepp/window/cengine.cpp @@ -16,17 +16,20 @@ #include #include -#include +#include #include #include #define BACKEND_SDL 1 -#define BACKEND_ALLEGRO 2 -#define BACKEND_SFML 3 +#define BACKEND_SDL2 2 +#define BACKEND_ALLEGRO 3 +#define BACKEND_SFML 4 #ifndef DEFAULT_BACKEND -#if defined( EE_BACKEND_SDL_ACTIVE ) +#if defined( EE_BACKEND_SDL_2 ) +#define DEFAULT_BACKEND BACKEND_SDL2 +#elif defined( EE_BACKEND_SDL_1_2 ) #define DEFAULT_BACKEND BACKEND_SDL #elif defined( EE_BACKEND_ALLEGRO_ACTIVE ) #define DEFAULT_BACKEND BACKEND_ALLEGRO @@ -89,12 +92,16 @@ void cEngine::Destroy() { } Backend::cBackend * cEngine::CreateSDLBackend( const WindowSettings &Settings ) { -#if defined( EE_BACKEND_SDL_ACTIVE ) - #if defined( EE_SDL_VERSION_1_3 ) || defined( EE_SDL_VERSION_2 ) - return eeNew( Backend::SDL2::cBackendSDL, () ); - #else +#if defined( EE_SDL_VERSION_1_2 ) return eeNew( Backend::SDL::cBackendSDL, () ); - #endif +#else + return NULL; +#endif +} + +Backend::cBackend * cEngine::CreateSDL2Backend( const WindowSettings &Settings ) { +#if defined( EE_SDL_VERSION_2 ) + return eeNew( Backend::SDL2::cBackendSDL2, () ); #else return NULL; #endif @@ -117,18 +124,24 @@ Backend::cBackend * cEngine::CreateSFMLBackend( const WindowSettings &Settings ) } cWindow * cEngine::CreateSDLWindow( const WindowSettings& Settings, const ContextSettings& Context ) { -#if defined( EE_BACKEND_SDL_ACTIVE ) - +#if defined( EE_SDL_VERSION_1_2 ) if ( NULL == mBackend ) { mBackend = CreateSDLBackend( Settings ); } -#if defined( EE_SDL_VERSION_1_3 ) || defined( EE_SDL_VERSION_2 ) - return eeNew( Backend::SDL2::cWindowSDL, ( Settings, Context ) ); -#else return eeNew( Backend::SDL::cWindowSDL, ( Settings, Context ) ); +#else + return NULL; #endif +} +cWindow * cEngine::CreateSDL2Window( const WindowSettings& Settings, const ContextSettings& Context ) { +#if defined( EE_SDL_VERSION_2 ) + if ( NULL == mBackend ) { + mBackend = CreateSDL2Backend( Settings ); + } + + return eeNew( Backend::SDL2::cWindowSDL, ( Settings, Context ) ); #else return NULL; #endif @@ -163,6 +176,8 @@ cWindow * cEngine::CreateSFMLWindow( const WindowSettings& Settings, const Conte cWindow * cEngine::CreateDefaultWindow( const WindowSettings& Settings, const ContextSettings& Context ) { #if DEFAULT_BACKEND == BACKEND_SDL return CreateSDLWindow( Settings, Context ); +#elif DEFAULT_BACKEND == BACKEND_SDL2 + return CreateSDL2Window( Settings, Context ); #elif DEFAULT_BACKEND == BACKEND_ALLEGRO return CreateAllegroWindow( Settings, Context ); #elif DEFAULT_BACKEND == BACKEND_SFML @@ -179,6 +194,7 @@ cWindow * cEngine::CreateWindow( WindowSettings Settings, ContextSettings Contex switch ( Settings.Backend ) { case WindowBackend::SDL: window = CreateSDLWindow( Settings, Context ); break; + case WindowBackend::SDL2: window = CreateSDL2Window( Settings, Context ); break; case WindowBackend::Allegro: window = CreateAllegroWindow( Settings, Context ); break; case WindowBackend::SFML: window = CreateSFMLWindow( Settings, Context ); break; case WindowBackend::Default: @@ -264,6 +280,8 @@ const Uint32& cEngine::GetHeight() const { Uint32 cEngine::GetDefaultBackend() const { #if DEFAULT_BACKEND == BACKEND_SDL return WindowBackend::SDL; +#elif DEFAULT_BACKEND == BACKEND_SDL2 + return WindowBackend::SDL2; #elif DEFAULT_BACKEND == BACKEND_ALLEGRO return WindowBackend::Allegro; #elif DEFAULT_BACKEND == BACKEND_SFML @@ -285,9 +303,10 @@ WindowSettings cEngine::CreateWindowSettings( cIniFile * ini, std::string iniKey std::string Backend = ini->GetValue( iniKeyName, "Backend", "" ); Uint32 WinBackend = GetDefaultBackend(); - ToLower( Backend ); + String::ToLower( Backend ); if ( "allegro" == Backend ) WinBackend = WindowBackend::Allegro; + else if ( "sdl2" == Backend ) WinBackend = WindowBackend::SDL2; else if ( "sdl" == Backend ) WinBackend = WindowBackend::SDL; else if ( "sfml" == Backend ) WinBackend = WindowBackend::SFML; diff --git a/src/eepp/window/cinput.cpp b/src/eepp/window/cinput.cpp index e17d70483..5b6c66518 100644 --- a/src/eepp/window/cinput.cpp +++ b/src/eepp/window/cinput.cpp @@ -116,7 +116,7 @@ void cInput::ProcessEvent( InputEvent * Event ) { if ( Event->button.button == EE_BUTTON_LEFT ) { mLastButtonLeftClicked = mLastButtonLeftClick; - mLastButtonLeftClick = eeGetTicks(); + mLastButtonLeftClick = Sys::GetTicks(); mTClick = mLastButtonLeftClick - mLastButtonLeftClicked; @@ -127,7 +127,7 @@ void cInput::ProcessEvent( InputEvent * Event ) { } } else if ( Event->button.button == EE_BUTTON_RIGHT ) { mLastButtonRightClicked = mLastButtonRightClick; - mLastButtonRightClick = eeGetTicks(); + mLastButtonRightClick = Sys::GetTicks(); mTClick = mLastButtonRightClick - mLastButtonRightClicked; @@ -138,7 +138,7 @@ void cInput::ProcessEvent( InputEvent * Event ) { } } else if( Event->button.button == EE_BUTTON_MIDDLE ) { mLastButtonMiddleClicked = mLastButtonMiddleClick; - mLastButtonMiddleClick = eeGetTicks(); + mLastButtonMiddleClick = Sys::GetTicks(); mTClick = mLastButtonMiddleClick - mLastButtonMiddleClicked; diff --git a/src/eepp/window/cinputtextbuffer.cpp b/src/eepp/window/cinputtextbuffer.cpp index a8e65adc0..d5eb806f1 100755 --- a/src/eepp/window/cinputtextbuffer.cpp +++ b/src/eepp/window/cinputtextbuffer.cpp @@ -77,7 +77,7 @@ void cInputTextBuffer::PromptToLeftFirstNoChar() { if ( mPromptPos - 2 > 0 ) { for ( Int32 i = mPromptPos - 2; i > 0; i-- ) { - if ( !IsLetter( mText[i] ) && !IsNumber( mText[i] ) && '\n' != mText[i] ) { + if ( !String::IsLetter( mText[i] ) && !String::IsNumber( mText[i] ) && '\n' != mText[i] ) { mPromptPos = i + 1; break; } else if ( i - 1 == 0 ) { @@ -97,7 +97,7 @@ void cInputTextBuffer::PromptToRightFirstNoChar() { return; for ( Int32 i = mPromptPos; i < s; i++ ) { - if ( !IsLetter( mText[i] ) && !IsNumber( mText[i] ) && '\n' != mText[i] ) { + if ( !String::IsLetter( mText[i] ) && !String::IsNumber( mText[i] ) && '\n' != mText[i] ) { mPromptPos = i + 1; break; } else if ( i + 1 == s ) { @@ -127,7 +127,7 @@ void cInputTextBuffer::EraseToNextNoChar() { } c = mText[ mPromptPos - 1 ]; - } while ( IsLetter( c ) || IsNumber( c ) ); + } while ( String::IsLetter( c ) || String::IsNumber( c ) ); ChangedSinceLastUpdate( true ); } @@ -144,10 +144,10 @@ bool cInputTextBuffer::IsIgnoredChar( const Uint32& c ) { } bool cInputTextBuffer::ValidChar( const Uint32& c ) { - if ( CanAdd() && IsCharacter( c ) ) { + if ( CanAdd() && String::IsCharacter( c ) ) { bool Ignored = false; - if ( AllowOnlyNumbers() && !IsNumber( c, AllowDotsInNumbers() ) ) { + if ( AllowOnlyNumbers() && !String::IsNumber( c, AllowDotsInNumbers() ) ) { Ignored = true; } @@ -172,16 +172,16 @@ void cInputTextBuffer::TryAddChar( const Uint32& c ) { mText += c; mPromptPos = (eeInt)mText.size(); } else { - InsertChar( mText, mPromptPos, c ); + String::InsertChar( mText, mPromptPos, c ); mPromptPos++; } } } else { - if ( CanAdd() && IsCharacter(c) ) { + if ( CanAdd() && String::IsCharacter(c) ) { cInput * Input = mWindow->GetInput(); if ( !Input->MetaPressed() && !Input->AltPressed() && !Input->ControlPressed() ) { - if ( !( AllowOnlyNumbers() && !IsNumber( c, AllowDotsInNumbers() ) ) ) { + if ( !( AllowOnlyNumbers() && !String::IsNumber( c, AllowDotsInNumbers() ) ) ) { mText += c; } } @@ -270,7 +270,7 @@ void cInputTextBuffer::Update( InputEvent* Event ) { } } else if ( ( c == KEY_RETURN || c == KEY_KP_ENTER ) ) { if ( SupportNewLine() && CanAdd() ) { - InsertChar( mText, mPromptPos, '\n' ); + String::InsertChar( mText, mPromptPos, '\n' ); mPromptPos++; diff --git a/src/eepp/window/cwindow.cpp b/src/eepp/window/cwindow.cpp index ba25e158e..06fe2b823 100644 --- a/src/eepp/window/cwindow.cpp +++ b/src/eepp/window/cwindow.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #ifdef EE_GLES1_LATE_INCLUDE @@ -160,10 +161,10 @@ bool cWindow::TakeScreenshot( std::string filepath, const EE_SAVE_TYPE& Format ) File = filepath.substr( filepath.find_last_of("/\\") + 1 ); Ext = File.substr( File.find_last_of(".") + 1 ); - if ( IsDirectory( filepath ) || !Ext.size() ) + if ( FileSystem::IsDirectory( filepath ) || !Ext.size() ) CreateNewFile = true; } else { - filepath = GetProcessPath(); + filepath = Sys::GetProcessPath(); CreateNewFile = true; } @@ -172,17 +173,17 @@ bool cWindow::TakeScreenshot( std::string filepath, const EE_SAVE_TYPE& Format ) Int32 FileNum = 1; std::string TmpPath = filepath, Ext; - if ( !IsDirectory( filepath ) ) - MakeDir( filepath ); + if ( !FileSystem::IsDirectory( filepath ) ) + FileSystem::MakeDir( filepath ); Ext = "." + cImage::SaveTypeToExtension( Format ); while ( !find && FileNum < 10000 ) { - TmpPath = StrFormated( "%s%05d%s", filepath.c_str(), FileNum, Ext.c_str() ); + TmpPath = String::StrFormated( "%s%05d%s", filepath.c_str(), FileNum, Ext.c_str() ); FileNum++; - if ( !FileExists( TmpPath ) ) + if ( !FileSystem::FileExists( TmpPath ) ) find = true; if ( FileNum == 10000 && find == false ) @@ -192,8 +193,8 @@ bool cWindow::TakeScreenshot( std::string filepath, const EE_SAVE_TYPE& Format ) return 0 != SOIL_save_screenshot(TmpPath.c_str(), Format, 0, 0, mWindow.WindowConfig.Width, mWindow.WindowConfig.Height ); } else { std::string Direc = filepath.substr( 0, filepath.find_last_of("/\\") ); - if ( !IsDirectory( Direc ) ) - MakeDir( Direc ); + if ( !FileSystem::IsDirectory( Direc ) ) + FileSystem::MakeDir( Direc ); return 0 != SOIL_save_screenshot(filepath.c_str(), Format, 0, 0, mWindow.WindowConfig.Width, mWindow.WindowConfig.Height ); } @@ -236,10 +237,10 @@ void cWindow::GetElapsedTime() { } void cWindow::CalculateFps() { - if ( eeGetTicks() - mFrameData.FPS.LastCheck >= 1000 ) { + if ( Sys::GetTicks() - mFrameData.FPS.LastCheck >= 1000 ) { mFrameData.FPS.Current = mFrameData.FPS.Count; mFrameData.FPS.Count = 0; - mFrameData.FPS.LastCheck = eeGetTicks(); + mFrameData.FPS.LastCheck = Sys::GetTicks(); } mFrameData.FPS.Count++; @@ -261,7 +262,7 @@ void cWindow::LimitFps() { } if ( RemainT > 0 ) { - eeSleep( (Uint32) RemainT ); + Sys::Sleep( (Uint32) RemainT ); } } } @@ -341,7 +342,7 @@ void cWindow::SendVideoResizeCb() { } void cWindow::LogSuccessfulInit( const std::string& BackendName ) { - cLog::instance()->Write( "Engine Initialized Succesfully.\n\tOS: " + GetOSName() + "\n\tArch: " + GetOSArchitecture() + " \n\tWindow/Input Backend: " + BackendName + "\n\tGL Backend: " + GLi->VersionStr() + "\n\tGL Vendor: " + GLi->GetVendor() + "\n\tGL Renderer: " + GLi->GetRenderer() + "\n\tGL Version: " + GLi->GetVersion() + "\n\tGL Shading Language Version: " + GLi->GetShadingLanguageVersion() + "\n\tResolution: " + toStr( GetWidth() ) + "x" + toStr( GetHeight() ) + "\n\tGL extensions supported:\n" + GLi->GetExtensions() ); + cLog::instance()->Write( "Engine Initialized Succesfully.\n\tOS: " + Sys::GetOSName() + "\n\tArch: " + Sys::GetOSArchitecture() + " \n\tWindow/Input Backend: " + BackendName + "\n\tGL Backend: " + GLi->VersionStr() + "\n\tGL Vendor: " + GLi->GetVendor() + "\n\tGL Renderer: " + GLi->GetRenderer() + "\n\tGL Version: " + GLi->GetVersion() + "\n\tGL Shading Language Version: " + GLi->GetShadingLanguageVersion() + "\n\tResolution: " + String::toStr( GetWidth() ) + "x" + String::toStr( GetHeight() ) + "\n\tGL extensions supported:\n" + GLi->GetExtensions() ); } void cWindow::LogFailureInit( const std::string& ClassName, const std::string& BackendName ) { diff --git a/src/eepp/window/inputhelper.cpp b/src/eepp/window/inputhelper.cpp index 22d553a52..fe2f33c1a 100644 --- a/src/eepp/window/inputhelper.cpp +++ b/src/eepp/window/inputhelper.cpp @@ -9,7 +9,7 @@ Uint32 eeConvertKeyCharacter( const Uint32& KeyCode, const Uint16& Unicode, cons value = Unicode; } - if ( IsCharacter( value ) ) { + if ( String::IsCharacter( value ) ) { return value; } diff --git a/src/examples/empty_window/empty_window.cpp b/src/examples/empty_window/empty_window.cpp index b60f6dd0a..5c04f008a 100644 --- a/src/examples/empty_window/empty_window.cpp +++ b/src/examples/empty_window/empty_window.cpp @@ -51,7 +51,7 @@ EE_MAIN_FUNC int main (int argc, char * argv []) win->Display(); // Sleep thread for 10 ms - eeSleep( 10 ); + Sys::Sleep( 10 ); } } diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index 3385ff276..0b9e78e16 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -34,7 +34,7 @@ void cEETest::Init() { mShowMenu = NULL; mTerrainUp = true; - MyPath = GetProcessPath(); + MyPath = Sys::GetProcessPath(); cIniFile Ini( MyPath + "data/ee.ini" ); Ini.ReadFile(); @@ -145,7 +145,7 @@ void cEETest::CreateAquaTextureAtlas() { std::string tgpath( MyPath + "data/aquatg/aqua" ); std::string Path( MyPath + "data/aqua" ); - if ( !FileExists( tgpath + ".etg" ) ) { + if ( !FileSystem::FileExists( tgpath + ".etg" ) ) { cTexturePacker tp( 256, 256, true, 2 ); tp.AddTexturesPath( Path ); tp.PackTextures(); @@ -429,7 +429,7 @@ void cEETest::CreateUI() { std::vector str(wsize); for ( Int32 i = 1; i <= wsize; i++ ) - str[i-1] = "Test ListBox " + toStr(i) + " testing it right now!"; + str[i-1] = "Test ListBox " + String::toStr(i) + " testing it right now!"; mListBox->AddListBoxItems( str ); } @@ -544,7 +544,7 @@ void cEETest::CreateUI() { cUITextInput * TxtInput = eeNew( cUITextInput, ( TxtInputParams ) ); cUIGfx * TxtGfx = eeNew( cUIGfx, ( TxtGfxParams ) ); - TxtBox->Text( "Test " + toStr( i+1 ) ); + TxtBox->Text( "Test " + String::toStr( i+1 ) ); Cell->Cell( 0, TxtBox ); Cell->Cell( 1, TxtGfx ); @@ -721,7 +721,7 @@ void cEETest::ItemClick( const cUIEvent * Event ) { } void cEETest::OnValueChange( const cUIEvent * Event ) { - mTextBoxValue->Text( "Scroll Value:\n" + toStr( mScrollBar->Value() ) ); + mTextBoxValue->Text( "Scroll Value:\n" + String::toStr( mScrollBar->Value() ) ); mProgressBar->Progress( mScrollBar->Value() * 100.f ); } @@ -765,7 +765,7 @@ void cEETest::ButtonClick( const cUIEvent * Event ) { Gfx->StartMovement( eeVector2i( eeRandi( 0, mWindow->GetWidth() ), -64 ), eeVector2i( eeRandi( 0, mWindow->GetWidth() ), mWindow->GetHeight() + 64 ), 2500 ); Gfx->CloseFadeOut( 3500 ); - mListBox->AddListBoxItem( "Test ListBox " + toStr( mListBox->Count() + 1 ) + " testing it right now!" ); + mListBox->AddListBoxItem( "Test ListBox " + String::toStr( mListBox->Count() + 1 ) + " testing it right now!" ); } } @@ -785,11 +785,11 @@ void cEETest::CmdSetPartsNum ( const std::vector < String >& params ) { if ( params.size() >= 2 ) { Int32 tInt = 0; - bool Res = fromString( tInt, params[1] ); + bool Res = String::fromString( tInt, params[1] ); if ( Res && ( tInt >= 0 && tInt <= 100000 ) ) { PS[2].Create( PSE_WormHole, tInt, TN[5], eeVector2f( mWindow->GetWidth() * 0.5f, mWindow->GetHeight() * 0.5f ), 32, true ); - Con.PushText( "Wormhole Particles Number Changed to: " + toStr(tInt) ); + Con.PushText( "Wormhole Particles Number Changed to: " + String::toStr(tInt) ); } else Con.PushText( "Valid parameters are between 0 and 100000 (0 = no limit)." ); } @@ -814,7 +814,7 @@ void cEETest::LoadTextures() { for ( i = 0; i < files.size(); i++ ) { std::string name( files[i] ); - if ( "jpg" == FileExtension( name ) ) { + if ( "jpg" == FileSystem::FileExtension( name ) ) { mResLoad.Add( eeNew( cTextureLoader, ( PakTest, name ) ) ); } } @@ -828,7 +828,7 @@ void cEETest::LoadTextures() { TNP.resize(12); for ( i = 0; i <= 7; i++ ) { - TN[i] = TF->LoadFromPack( PAK, "t" + toStr(i+1) + ".png", ( (i+1) == 7 ) ? true : false, ( (i+1) == 4 ) ? EE_CLAMP_REPEAT : EE_CLAMP_TO_EDGE ); + TN[i] = TF->LoadFromPack( PAK, "t" + String::toStr(i+1) + ".png", ( (i+1) == 7 ) ? true : false, ( (i+1) == 4 ) ? EE_CLAMP_REPEAT : EE_CLAMP_TO_EDGE ); TNP[i] = TF->GetTexture( TN[i] ); } @@ -838,7 +838,7 @@ void cEETest::LoadTextures() { cShapeGroup * SG = cShapeGroupManager::instance()->GetByName( "tiles" ); for ( i = 0; i < 6; i++ ) { - Tiles[i] = SG->GetByName( toStr( i+1 ) ); + Tiles[i] = SG->GetByName( String::toStr( i+1 ) ); } Tiles[6] = SG->Add( TF->LoadFromPack( PAK, "objects/1.png" ), "7" ); @@ -978,7 +978,7 @@ void cEETest::ParticlesThread() { for ( Uint8 i = 0; i < PS.size(); i++ ) PS[i].Update( PSElapsed ); } - eeSleep(10); + Sys::Sleep(10); } } @@ -1195,25 +1195,25 @@ void cEETest::Render() { HWidth = mWindow->GetWidth() * 0.5f; HHeight = mWindow->GetHeight() * 0.5f; - if ( eeGetTicks() - lasttick >= 50 ) { - lasttick = eeGetTicks(); + if ( Sys::GetTicks() - lasttick >= 50 ) { + lasttick = Sys::GetTicks(); #ifdef EE_DEBUG - mInfo = StrFormated( "EE - FPS: %d Elapsed Time: %4.8f\nMouse X: %d Mouse Y: %d\nTexture Memory Usage: %s\nApp Memory Usage: %s\nApp Peak Memory Usage: %s", + mInfo = String::StrFormated( "EE - FPS: %d Elapsed Time: %4.8f\nMouse X: %d Mouse Y: %d\nTexture Memory Usage: %s\nApp Memory Usage: %s\nApp Peak Memory Usage: %s", mWindow->FPS(), et, (Int32)Mouse.x, (Int32)Mouse.y, - SizeToString( TF->MemorySize() ).c_str(), - SizeToString( (Uint32)MemoryManager::GetTotalMemoryUsage() ).c_str(), - SizeToString( (Uint32)MemoryManager::GetPeakMemoryUsage() ).c_str() + FileSystem::SizeToString( TF->MemorySize() ).c_str(), + FileSystem::SizeToString( (Uint32)MemoryManager::GetTotalMemoryUsage() ).c_str(), + FileSystem::SizeToString( (Uint32)MemoryManager::GetPeakMemoryUsage() ).c_str() ); #else - mInfo = StrFormated( "EE - FPS: %d Elapsed Time: %4.8f\nMouse X: %d Mouse Y: %d\nTexture Memory Usage: %s", + mInfo = String::StrFormated( "EE - FPS: %d Elapsed Time: %4.8f\nMouse X: %d Mouse Y: %d\nTexture Memory Usage: %s", mWindow->FPS(), et, (Int32)Mouse.x, (Int32)Mouse.y, - SizeToString( TF->MemorySize() ).c_str() + FileSystem::SizeToString( TF->MemorySize() ).c_str() ); #endif @@ -1270,7 +1270,7 @@ void cEETest::Render() { FF2->Draw( "_", 6.f + FF2->GetTextWidth(), 180.f + (eeFloat)LineNum * (eeFloat)FF2->GetFontHeight() ); } - FF2->SetText( "FPS: " + toStr( mWindow->FPS() ) ); + FF2->SetText( "FPS: " + String::toStr( mWindow->FPS() ) ); FF2->Draw( mWindow->GetWidth() - FF2->GetTextWidth() - 15, 0 ); FF2->SetText( InBuf.Buffer() ); @@ -1475,7 +1475,7 @@ void cEETest::Input() { if ( KM->IsKeyUp(KEY_F6) ) { Wireframe = !Wireframe; - eeSleep(1); + Sys::Sleep(1); CreateTiling(Wireframe); }