From f8703cd5683af3e505f8522bb4b607be88cd38d5 Mon Sep 17 00:00:00 2001 From: spartanj Date: Fri, 3 Sep 2010 02:53:14 -0300 Subject: [PATCH] Added Vertex Buffer support ( cVertexBuffer base class (interface), cVertexBufferOGL fallback if gpu doesn't support VBO's, cVertexBufferVBO uses ARB Vertex Buffer Object ). Added a Memory Manager to trace memory leaks. Fixed some memory leaks detected with the new memory manager. Added an allocator for STL ( to use it with the custom allocation seted in the memory manager ). Fixed Makefiles ( i wroke them ). --- Makefile | 24 +++-- Makefile.macosx | 24 +++-- ee.linux.cbp | 18 +++- src/audio/caudiodevice.cpp | 4 +- src/audio/caudiodevice.hpp | 4 +- src/audio/csoundbuffer.cpp | 9 +- src/audio/csoundfile.cpp | 18 ++-- src/base.hpp | 37 ++++--- src/base/allocator.hpp | 75 +++++++++++++ src/base/base.hpp | 9 ++ src/base/memorymanager.cpp | 138 ++++++++++++++++++++++++ src/base/memorymanager.hpp | 101 +++++++++++++++++ src/base/stlcontainers.hpp | 68 ++++++++++++ src/ee.h | 3 + src/graphics/cbatchrenderer.cpp | 54 +++++----- src/graphics/cbatchrenderer.hpp | 32 +++--- src/graphics/cframebuffer.cpp | 4 +- src/graphics/cimage.cpp | 10 +- src/graphics/cimage.hpp | 2 +- src/graphics/cshaderprogram.cpp | 12 +-- src/graphics/cshape.cpp | 6 +- src/graphics/cshape.hpp | 2 +- src/graphics/cshapegroup.cpp | 8 +- src/graphics/csprite.cpp | 2 +- src/graphics/ctexture.cpp | 2 +- src/graphics/ctexture.hpp | 2 +- src/graphics/ctexturefactory.cpp | 4 +- src/graphics/ctexturefactory.hpp | 5 +- src/graphics/ctexturefontloader.cpp | 2 +- src/graphics/ctexturegrouploader.cpp | 14 +-- src/graphics/ctextureloader.cpp | 13 ++- src/graphics/ctexturepacker.cpp | 10 +- src/graphics/ctexturepacker.hpp | 6 +- src/graphics/cttffont.cpp | 8 +- src/graphics/cttffont.hpp | 14 +-- src/graphics/cttffontloader.cpp | 2 +- src/graphics/cvertexbuffer.cpp | 156 +++++++++++++++++++++++++++ src/graphics/cvertexbuffer.hpp | 72 +++++++++++++ src/graphics/cvertexbufferogl.cpp | 66 ++++++++++++ src/graphics/cvertexbufferogl.hpp | 27 +++++ src/graphics/cvertexbuffervbo.cpp | 135 +++++++++++++++++++++++ src/graphics/cvertexbuffervbo.hpp | 31 ++++++ src/graphics/renders.hpp | 82 +++++++------- src/graphics/vbohelper.hpp | 45 ++++++++ src/helper/SOIL/SOIL.c | 5 +- src/system/clog.hpp | 6 +- src/system/cpak.cpp | 2 +- src/system/czip.cpp | 2 +- src/system/singleton.hpp | 6 +- src/test/ee.cpp | 61 +++++++---- src/ui/cuicontrol.cpp | 6 +- src/ui/cuicontrol.hpp | 4 +- src/ui/cuicontrolanim.cpp | 16 +-- src/ui/cuimanager.cpp | 2 +- src/utils/utils.cpp | 31 +++++- src/utils/utils.hpp | 10 +- src/window/cengine.cpp | 12 +-- src/window/cengine.hpp | 5 +- src/window/cinput.hpp | 3 +- src/window/cjoystickmanager.cpp | 2 +- 60 files changed, 1279 insertions(+), 254 deletions(-) create mode 100644 src/base/allocator.hpp create mode 100644 src/base/base.hpp create mode 100644 src/base/memorymanager.cpp create mode 100644 src/base/memorymanager.hpp create mode 100644 src/base/stlcontainers.hpp create mode 100644 src/graphics/cvertexbuffer.cpp create mode 100644 src/graphics/cvertexbuffer.hpp create mode 100644 src/graphics/cvertexbufferogl.cpp create mode 100644 src/graphics/cvertexbufferogl.hpp create mode 100644 src/graphics/cvertexbuffervbo.cpp create mode 100644 src/graphics/cvertexbuffervbo.hpp create mode 100644 src/graphics/vbohelper.hpp diff --git a/Makefile b/Makefile index b3c84ec9b..cb358aec8 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,15 @@ ifeq ($(DEBUGBUILD), yes) - DEBUGFLAGS = -g -DDEBUG -DEE_DEBUG + DEBUGFLAGS = -g -DDEBUG -DEE_DEBUG -DEE_MEMORY_MANAGER else DEBUGFLAGS = -O2 -s -DNDEBUG endif -ifeq ($(STATIC), yes) - BUILDFLAGS = - LINKFLAGS = -else +ifeq ($(DYNAMIC), yes) BUILDFLAGS = -fPIC LINKFLAGS = -shared +else + BUILDFLAGS = + LINKFLAGS = endif export CC = gcc @@ -44,6 +44,7 @@ SRCZLIB = $(wildcard ./src/helper/zlib/*.c) SRCLIBZIP = $(wildcard ./src/helper/libzip/*.c) SRCHAIKUTTF = $(wildcard ./src/helper/haikuttf/*.cpp) +SRCBASE = $(wildcard ./src/base/*.cpp) SRCAUDIO = $(wildcard ./src/audio/*.cpp) SRCGAMING = $(wildcard ./src/gaming/*.cpp) SRCGRAPHICS = $(wildcard ./src/graphics/*.cpp) @@ -63,6 +64,7 @@ OBJZLIB = $(SRCZLIB:.c=.o) OBJLIBZIP = $(SRCLIBZIP:.c=.o) OBJHAIKUTTF = $(SRCHAIKUTTF:.cpp=.o) +OBJBASE = $(SRCBASE:.cpp=.o) OBJAUDIO = $(SRCAUDIO:.cpp=.o) OBJGAMING = $(SRCGAMING:.cpp=.o) OBJGRAPHICS = $(SRCGRAPHICS:.cpp=.o) @@ -73,19 +75,19 @@ OBJUTILS = $(SRCUTILS:.cpp=.o) OBJWINDOW = $(SRCWINDOW:.cpp=.o) OBJHELPERS = $(OBJGLEW) $(OBJSOIL) $(OBJSTBVORBIS) $(OBJZLIB) $(OBJLIBZIP) -OBJMODULES = $(OBJHAIKUTTF) $(OBJUTILS) $(OBJMATH) $(OBJSYSTEM) $(OBJAUDIO) $(OBJWINDOW) $(OBJGRAPHICS) $(OBJGAMING) $(OBJUI) +OBJMODULES = $(OBJHAIKUTTF) $(OBJBASE) $(OBJUTILS) $(OBJMATH) $(OBJSYSTEM) $(OBJAUDIO) $(OBJWINDOW) $(OBJGRAPHICS) $(OBJGAMING) $(OBJUI) OBJTEST = $(SRCTEST:.cpp=.o) OBJEEIV = $(SRCEEIV:.cpp=.o) -ifeq ($(STATIC), yes) - LIB = libeepp-s.a - LIBNAME = $(LIBPATH)/$(LIB) - INSTALL = -else +ifeq ($(DYNAMIC), yes) LIB = libeepp.so LIBNAME = $(LIBPATH)/$(LIB).$(VERSION) INSTALL = && $(LN) $(LNFLAGS) $(DESTLIBDIR)/$(LIB).$(VERSION) $(DESTLIBDIR)/$(LIB) +else + LIB = libeepp-s.a + LIBNAME = $(LIBPATH)/$(LIB) + INSTALL = endif all: $(LIB) diff --git a/Makefile.macosx b/Makefile.macosx index e57112422..cfc239cb3 100644 --- a/Makefile.macosx +++ b/Makefile.macosx @@ -1,15 +1,15 @@ ifeq ($(DEBUGBUILD), yes) - DEBUGFLAGS = -g -DDEBUG -DEE_DEBUG + DEBUGFLAGS = -g -DDEBUG -DEE_DEBUG -DEE_MEMORY_MANAGER else DEBUGFLAGS = -O2 -s -DNDEBUG endif -ifeq ($(STATIC), yes) - BUILDFLAGS = - LINKFLAGS = -else +ifeq ($(DYNAMIC), yes) BUILDFLAGS = -fPIC LINKFLAGS = -shared +else + BUILDFLAGS = + LINKFLAGS = endif export CC = gcc @@ -44,6 +44,7 @@ SRCZLIB = $(wildcard ./src/helper/zlib/*.c) SRCLIBZIP = $(wildcard ./src/helper/libzip/*.c) SRCHAIKUTTF = $(wildcard ./src/helper/haikuttf/*.cpp) +SRCBASE = $(wildcard ./src/base/*.cpp) SRCAUDIO = $(wildcard ./src/audio/*.cpp) SRCGAMING = $(wildcard ./src/gaming/*.cpp) SRCGRAPHICS = $(wildcard ./src/graphics/*.cpp) @@ -63,6 +64,7 @@ OBJZLIB = $(SRCZLIB:.c=.o) OBJLIBZIP = $(SRCLIBZIP:.c=.o) OBJHAIKUTTF = $(SRCHAIKUTTF:.cpp=.o) +OBJBASE = $(SRCBASE:.cpp=.o) OBJAUDIO = $(SRCAUDIO:.cpp=.o) OBJGAMING = $(SRCGAMING:.cpp=.o) OBJGRAPHICS = $(SRCGRAPHICS:.cpp=.o) @@ -73,19 +75,19 @@ OBJUTILS = $(SRCUTILS:.cpp=.o) OBJWINDOW = $(SRCWINDOW:.cpp=.o) OBJHELPERS = $(OBJGLEW) $(OBJSOIL) $(OBJSTBVORBIS) $(OBJZLIB) $(OBJLIBZIP) -OBJMODULES = $(OBJHAIKUTTF) $(OBJUTILS) $(OBJMATH) $(OBJSYSTEM) $(OBJAUDIO) $(OBJWINDOW) $(OBJGRAPHICS) $(OBJGAMING) $(OBJUI) +OBJMODULES = $(OBJHAIKUTTF) $(OBJBASE) $(OBJUTILS) $(OBJMATH) $(OBJSYSTEM) $(OBJAUDIO) $(OBJWINDOW) $(OBJGRAPHICS) $(OBJGAMING) $(OBJUI) OBJTEST = $(SRCTEST:.cpp=.o) OBJEEIV = $(SRCEEIV:.cpp=.o) -ifeq ($(STATIC), yes) - LIB = libeepp-s.a - LIBNAME = $(LIBPATH)/$(LIB) - INSTALL = -else +ifeq ($(DYNAMIC), yes) LIB = libeepp.so LIBNAME = $(LIBPATH)/$(LIB).$(VERSION) INSTALL = && $(LN) $(LNFLAGS) $(DESTLIBDIR)/$(LIB).$(VERSION) $(DESTLIBDIR)/$(LIB) +else + LIB = libeepp-s.a + LIBNAME = $(LIBPATH)/$(LIB) + INSTALL = endif all: $(LIB) diff --git a/ee.linux.cbp b/ee.linux.cbp index a17748165..f4109e91a 100644 --- a/ee.linux.cbp +++ b/ee.linux.cbp @@ -8,7 +8,7 @@ + @@ -67,6 +67,11 @@ + + + + + @@ -140,11 +145,18 @@ + + + + + + + diff --git a/src/audio/caudiodevice.cpp b/src/audio/caudiodevice.cpp index 92fb9fc4c..2fd81ec2b 100755 --- a/src/audio/caudiodevice.cpp +++ b/src/audio/caudiodevice.cpp @@ -48,7 +48,7 @@ bool cAudioDevice::isCreated() { cAudioDevice * cAudioDevice::instance() { // Create the audio device if it doesn't exist if ( NULL == mInstance ) - mInstance = new cAudioDevice; + mInstance = eeNew( cAudioDevice, () ); return mInstance; } @@ -66,7 +66,7 @@ void cAudioDevice::RemoveReference() { // Destroy the audio device if the references count reaches 0 if (mInstance->mRefCount == 0) { - delete mInstance; + eeDelete( mInstance ); mInstance = NULL; } } diff --git a/src/audio/caudiodevice.hpp b/src/audio/caudiodevice.hpp index 849a1fc28..8bf428daf 100755 --- a/src/audio/caudiodevice.hpp +++ b/src/audio/caudiodevice.hpp @@ -20,10 +20,10 @@ class EE_API cAudioDevice { bool IsExtensionSupported( const std::string& extension ); bool isCreated(); - private : - cAudioDevice(); ~cAudioDevice(); + private : + cAudioDevice(); static cAudioDevice * mInstance; diff --git a/src/audio/csoundbuffer.cpp b/src/audio/csoundbuffer.cpp index 10502ec77..b8646545d 100755 --- a/src/audio/csoundbuffer.cpp +++ b/src/audio/csoundbuffer.cpp @@ -64,10 +64,10 @@ bool cSoundBuffer::LoadFromPack( cPack* Pack, const std::string& FilePackPath ) bool cSoundBuffer::LoadFromMemory( const char* Data, std::size_t SizeInBytes ) { // Create the sound file - std::auto_ptr File( cSoundFile::CreateRead( Data, SizeInBytes ) ); + cSoundFile * File = cSoundFile::CreateRead( Data, SizeInBytes ); // Open the sound file - if ( File.get() ) { + if ( NULL != File ) { // Get the sound parameters std::size_t NbSamples = File->GetSamplesCount(); unsigned int ChannelsCount = File->GetChannelsCount(); @@ -80,9 +80,14 @@ bool cSoundBuffer::LoadFromMemory( const char* Data, std::size_t SizeInBytes ) { cLog::instance()->Write( "Sound file loaded from memory." ); // Update the internal buffer with the new samples + eeDelete( File ); + return Update( ChannelsCount, SampleRate ); } else { cLog::instance()->Write( "Failed to read audio data from file in memory" ); + + eeDelete( File ); + return false; } } else { diff --git a/src/audio/csoundfile.cpp b/src/audio/csoundfile.cpp index 42460f9d4..b23d6c581 100755 --- a/src/audio/csoundfile.cpp +++ b/src/audio/csoundfile.cpp @@ -21,9 +21,9 @@ cSoundFile * cSoundFile::CreateRead( const std::string& Filename ) { // Create the file according to its type cSoundFile * File = NULL; - if ( cSoundFileOgg::IsFileSupported(Filename, true) ) File = new cSoundFileOgg; + if ( cSoundFileOgg::IsFileSupported(Filename, true) ) File = eeNew( cSoundFileOgg, () ); #ifndef EE_NO_SNDFILE - else if ( cSoundFileDefault::IsFileSupported(Filename, true) ) File = new cSoundFileDefault; + else if ( cSoundFileDefault::IsFileSupported(Filename, true) ) File = eeNew( cSoundFileDefault, () ); #endif // Open it for reading @@ -40,7 +40,7 @@ cSoundFile * cSoundFile::CreateRead( const std::string& Filename ) { File->mChannelsCount = ChannelsCount; File->mSampleRate = SampleRate; } else { - delete File; + eeDelete( File ); File = NULL; } } @@ -52,9 +52,9 @@ cSoundFile * cSoundFile::CreateRead( const char* Data, std::size_t SizeInMemory // Create the file according to its type cSoundFile * File = NULL; - if ( cSoundFileOgg::IsFileSupported(Data, SizeInMemory)) File = new cSoundFileOgg; + if ( cSoundFileOgg::IsFileSupported(Data, SizeInMemory)) File = eeNew( cSoundFileOgg, () ); #ifndef EE_NO_SNDFILE - else if ( cSoundFileDefault::IsFileSupported(Data, SizeInMemory) ) File = new cSoundFileDefault; + else if ( cSoundFileDefault::IsFileSupported(Data, SizeInMemory) ) File = eeNew( cSoundFileDefault, () ); #endif // Open it for reading @@ -71,7 +71,7 @@ cSoundFile * cSoundFile::CreateRead( const char* Data, std::size_t SizeInMemory File->mChannelsCount = ChannelsCount; File->mSampleRate = SampleRate; } else { - delete File; + eeDelete( File ); File = NULL; } } @@ -83,9 +83,9 @@ cSoundFile * cSoundFile::CreateWrite( const std::string& Filename, unsigned int // Create the file according to its type cSoundFile * File = NULL; - if ( cSoundFileOgg::IsFileSupported(Filename, false) ) File = new cSoundFileOgg; + if ( cSoundFileOgg::IsFileSupported(Filename, false) ) File = eeNew( cSoundFileOgg, () ); #ifndef EE_NO_SNDFILE - else if ( cSoundFileDefault::IsFileSupported(Filename, false) ) File = new cSoundFileDefault; + else if ( cSoundFileDefault::IsFileSupported(Filename, false) ) File = eeNew( cSoundFileDefault, () ); #endif // Open it for writing @@ -98,7 +98,7 @@ cSoundFile * cSoundFile::CreateWrite( const std::string& Filename, unsigned int File->mChannelsCount = ChannelsCount; File->mSampleRate = SampleRate; } else { - delete File; + eeDelete( File ); File = NULL; } } diff --git a/src/base.hpp b/src/base.hpp index 17a90fb6d..802d1244a 100644 --- a/src/base.hpp +++ b/src/base.hpp @@ -7,6 +7,14 @@ #include #include #include +#include + +#include +#include + +#include +#include +#include #include #include @@ -14,21 +22,14 @@ #include #include #include -#include -#include -#include +#include -#include -#include -#include - -#include - -// Templates needed by the library #include #include #include +#include + #define Int8 Sint8 #define Int16 Sint16 #define Int32 Sint32 @@ -84,6 +85,12 @@ #define EE_CALL #endif +#if ( __GNUC__ >= 4 ) && defined( EE_DYNAMIC ) && defined( EE_EXPORTS ) +#define EE_API __attribute__ ((visibility("default"))) +#else +#define EE_API +#endif + #include "helper/glew/glew.h" #if EE_PLATFORM == EE_PLATFORM_MACOSX #include @@ -91,14 +98,16 @@ #include #endif +#include "base/base.hpp" + namespace EE { #define eeARRAY_SIZE(__array) ( sizeof(__array) / sizeof(__array[0]) ) - #define eeSAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } } - #define eeSAFE_FREE(p) { if(p) { free ( (void*)p );(p)=NULL; } } - #define eeSAFE_DELETE_ARRAY(p) { if(p) { delete[](p); (p)=NULL; } } + #define eeSAFE_DELETE(p) { if(p) { eeDelete (p); (p)=NULL; } } + #define eeSAFE_FREE(p) { if(p) { eeFree ( (void*)p ); (p)=NULL; } } + #define eeSAFE_DELETE_ARRAY(p) { if(p) { eeDeleteArray(p); (p)=NULL; } } typedef float eeFloat; //! The internal floating point used on EE++. \n This can help to improve compatibility with some platforms. \n And helps for an easy change from single precision to double precision. - typedef double eeDouble; //! The internal double floating point. It's only used when the engine needs some very high precision floating point ( for example the timer ) + typedef double eeDouble; //! The internal double floating point. It's only used when the engine needs some very high precision floating point ( for example the timer ) typedef unsigned int eeUint; typedef signed int eeInt; diff --git a/src/base/allocator.hpp b/src/base/allocator.hpp new file mode 100644 index 000000000..ca2af2768 --- /dev/null +++ b/src/base/allocator.hpp @@ -0,0 +1,75 @@ +#ifndef EE_ALLOCATOR_HPP +#define EE_ALLOCATOR_HPP + +#include "memorymanager.hpp" + +namespace EE { + +template +class eeAllocator { + public: + typedef T value_type; + typedef T * pointer; + typedef const T * const_pointer; + typedef T& reference; + typedef const T& const_reference; + typedef ptrdiff_t difference_type; + typedef size_t size_type; + + eeAllocator() { + } + + eeAllocator( const eeAllocator& ) { + } + + virtual ~eeAllocator() { + } + + T * allocate( size_t cnt, typename std::allocator::const_pointer ptr = 0 ) { + (void)ptr; + return ( T * ) eeMalloc( cnt * sizeof( T ) ); + } + + void deallocate( T * ptr, size_type ) { + eeFree( ptr ); + } + + void construct( T * ptr, const T&e ) { + new ( (void*)ptr ) T( e ); + } + + void destroy( T * ptr ) { + ptr->~T(); + } + + size_t max_size() const { + return size_t( 0xFFFFFFFF ); + } + + pointer address( reference x ) const { + return &x; + } + + const_pointer address( const_reference x ) const { + return &x; + } + + eeAllocator& operator=(const eeAllocator&) { return *this; } + + template + struct rebind { + typedef eeAllocator other; + }; + + template + eeAllocator( const eeAllocator& ) {} + + template + eeAllocator& operator=(const eeAllocator&) { return *this; } + protected: + +}; + +} + +#endif diff --git a/src/base/base.hpp b/src/base/base.hpp new file mode 100644 index 000000000..a81df9a0a --- /dev/null +++ b/src/base/base.hpp @@ -0,0 +1,9 @@ +#ifndef EE_BASE_BASE_HPP +#define EE_BASE_BASE_HPP + +#include "memorymanager.hpp" +#include "allocator.hpp" +#include "stlcontainers.hpp" + +#endif + diff --git a/src/base/memorymanager.cpp b/src/base/memorymanager.cpp new file mode 100644 index 000000000..5b84a45ac --- /dev/null +++ b/src/base/memorymanager.cpp @@ -0,0 +1,138 @@ +#include "memorymanager.hpp" +#include +#include + +namespace EE { + +static std::string SizeToString( const unsigned int& MemSize ) { + std::string size = " bytes"; + double mem = static_cast( MemSize ); + unsigned int 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"; + } + + std::ostringstream ss; + ss << mem; + + return std::string( ss.str() + size ); +} + +tAllocatedPointerMap MemoryManager::mMapPointers; +size_t MemoryManager::mTotalMemoryUsage = 0; +size_t MemoryManager::mPeakMemoryUsage = 0; + +cAllocatedPointer::cAllocatedPointer( void * Data,const std::string& File, int Line, size_t Memory ) { + mData = Data; + mFile = File; + mLine = Line; + mMemory = Memory; +} + +void * MemoryManager::AddPointer( const cAllocatedPointer& aAllocatedPointer ) { + mMapPointers.insert( tAllocatedPointerMap::value_type( aAllocatedPointer.mData, aAllocatedPointer ) ); + + mTotalMemoryUsage += aAllocatedPointer.mMemory; + + if ( mPeakMemoryUsage < mTotalMemoryUsage ) + mPeakMemoryUsage = mTotalMemoryUsage; + + return aAllocatedPointer.mData; +} + +bool MemoryManager::RemovePointer( void * Data ) { + bool Found = false; + + tAllocatedPointerMapIt it = mMapPointers.upper_bound( Data ); + + it--; + + if( it != mMapPointers.end() ) { + char * Test = (char*)it->second.mData; + + size_t testSize = it->second.mMemory; + + if( Data >= Test && Data < Test + testSize ) + Found = true; + } + + + if ( !Found ) { + printf( "Trying to delete pointer %p created that does not exist!\n", Data ); + + return false; + } + + mTotalMemoryUsage -= it->second.mMemory; + + mMapPointers.erase( it ); + + return true; +} + +void MemoryManager::LogResults() { + #ifdef EE_MEMORY_MANAGER + printf("\n|--Memory Manager Report-------------------------------|\n"); + printf("|\n"); + + if( mMapPointers.empty() ) { + printf( "| No memory leaks detected.\n" ); + } else { + printf( "| Memory leaks detected: \n" ); + printf( "|\n"); + + printf( "| address\t file" ); + + //Get max length of file name + int lMax =0; + tAllocatedPointerMapIt it = mMapPointers.begin(); + + for( ; it != mMapPointers.end(); ++it ){ + cAllocatedPointer &ap = it->second; + + if( (int)ap.mFile.length() > lMax ) + lMax = (int)ap.mFile.length(); + } + + lMax += 5; + + for( int i = 0; i < lMax - 4; ++i ) + printf(" "); + + printf( "line\t\t memory usage\t \n" ); + + printf( "|------------------------------------------------------------\n" ); + + it = mMapPointers.begin(); + + for( ; it != mMapPointers.end(); ++it ) { + cAllocatedPointer &ap = it->second; + + printf( "| %p\t %s", ap.mData, ap.mFile.c_str() ); + + for ( int i=0; i < lMax - (int)ap.mFile.length(); ++i ) + printf(" "); + + printf( "%d\t\t %d\t\n", ap.mLine, ap.mMemory ); + } + } + + printf( "|\n" ); + printf( "| Memory left: %s\n", SizeToString( mTotalMemoryUsage ).c_str() ); + printf( "| Peak Memory Usage: %s\n", SizeToString( mPeakMemoryUsage ).c_str() ); + printf( "|------------------------------------------------------|\n\n" ); + #endif +} + +} diff --git a/src/base/memorymanager.hpp b/src/base/memorymanager.hpp new file mode 100644 index 000000000..e6849c107 --- /dev/null +++ b/src/base/memorymanager.hpp @@ -0,0 +1,101 @@ +#ifndef EE_MEMORY_MANAGER_HPP +#define EE_MEMORY_MANAGER_HPP + +#include +#include +#include +#include + +namespace EE { + +class cAllocatedPointer { + public: + cAllocatedPointer( void * Data, const std::string& File, int Line, size_t Memory ); + + std::string mFile; + int mLine; + size_t mMemory; + void * mData; +}; + +typedef std::map tAllocatedPointerMap; +typedef tAllocatedPointerMap::iterator tAllocatedPointerMapIt; + +class MemoryManager { + public: + + static void * AddPointer( const cAllocatedPointer& aAllocatedPointer ); + + static bool RemovePointer( void * Data ); + + static void LogResults(); + + static void SetLogCreation( bool abX ); + + template + static T* DeleteAndReturn( T * Data ) { + delete Data; + return Data; + } + + template + static T* DeleteArrayAndReturn( T * Data ) { + delete [] Data; + return Data; + } + + template + static T* FreeAndReturn( T * Data ) { + free( Data ); + return Data; + } + + static tAllocatedPointerMap mMapPointers; + static size_t mTotalMemoryUsage; + static size_t mPeakMemoryUsage; +}; + +#ifdef EE_MEMORY_MANAGER + #define eeNew(classType, constructor) \ + ( classType *)EE::MemoryManager::AddPointer( EE::cAllocatedPointer(new classType constructor ,__FILE__,__LINE__,sizeof(classType) ) ) + + #define eeNewArray(classType, amount) \ + ( classType *) EE::MemoryManager::AddPointer( EE::cAllocatedPointer( new classType [ amount ], __FILE__, __LINE__, amount * sizeof( classType ) ) ) + + #define eeMalloc(amount) \ + EE::MemoryManager::AddPointer( EE::cAllocatedPointer( malloc( amount ) , __FILE__, __LINE__, amount ) ) + + #define eeDelete(data){ \ + if( EE::MemoryManager::RemovePointer( EE::MemoryManager::DeleteAndReturn( data ) ) == false ) printf( "Deleting at '%s' %d\n", __FILE__, __LINE__ ); \ + } + + #define eeDeleteArray(data){ \ + if(EE::MemoryManager::RemovePointer( EE::MemoryManager::DeleteArrayAndReturn( data ) ) == false ) printf( "Deleting at '%s' %d\n", __FILE__, __LINE__ ); \ + } + + #define eeFree( data ){ \ + if( EE::MemoryManager::RemovePointer( EE::MemoryManager::FreeAndReturn( data ) ) == false ) printf( "Deleting at '%s' %d\n", __FILE__, __LINE__ ); \ + } +#else + #define eeNew(classType, constructor) \ + new classType constructor + + #define eeNewArray(classType, amount) \ + new classType [ amount ] + + #define eeMalloc(amount) \ + malloc( amount ) + + #define eeDelete(data) \ + delete data; + + #define eeDeleteArray(data) \ + delete [] data; + + #define eeFree(data) \ + free(data); +#endif + +} + +#endif diff --git a/src/base/stlcontainers.hpp b/src/base/stlcontainers.hpp new file mode 100644 index 000000000..00a52cdd6 --- /dev/null +++ b/src/base/stlcontainers.hpp @@ -0,0 +1,68 @@ +#ifndef EE_STLCONTAINERS_HPP +#define EE_STLCONTAINERS_HPP + +namespace EE { + + template > + struct eeDeque { + #ifdef EE_MEMORY_MANAGER + typedef typename std::deque type; + #else + typedef typename std::deque type; + #endif + }; + + template > + struct eeVector { + #ifdef EE_MEMORY_MANAGER + typedef typename std::vector type; + #else + typedef typename std::vector type; + #endif + }; + + template > + struct eeList { + #ifdef EE_MEMORY_MANAGER + typedef typename std::list type; + #else + typedef typename std::list type; + #endif + }; + + template , typename A = eeAllocator > + struct eeSet { + #ifdef EE_MEMORY_MANAGER + typedef typename std::set type; + #else + typedef typename std::set type; + #endif + }; + + template , typename A = eeAllocator< std::pair > > + struct eeMap { + #ifdef EE_MEMORY_MANAGER + typedef typename std::map type; + #else + typedef typename std::map type; + #endif + }; + + template , typename A = eeAllocator< std::pair > > + struct eeMultimap { + #ifdef EE_MEMORY_MANAGER + typedef typename std::multimap type; + #else + typedef typename std::multimap type; + #endif + }; + + typedef eeVector::type eeVectorUint8; + typedef eeVector::type eeVectorUint16; + typedef eeVector::type eeVectorUint32; + typedef eeVector::type eeVectorInt8; + typedef eeVector::type eeVectorInt16; + typedef eeVector::type eeVectorInt32; +} + +#endif diff --git a/src/ee.h b/src/ee.h index 2a9341225..44dff4794 100755 --- a/src/ee.h +++ b/src/ee.h @@ -123,6 +123,9 @@ #include "graphics/cframebuffer.hpp" #include "graphics/cframebufferfbo.hpp" #include "graphics/cframebufferpbuffer.hpp" + #include "graphics/cvertexbuffer.hpp" + #include "graphics/cvertexbufferogl.hpp" + #include "graphics/cvertexbuffervbo.hpp" using namespace EE::Graphics; // Gaming diff --git a/src/graphics/cbatchrenderer.cpp b/src/graphics/cbatchrenderer.cpp index a7e1b5160..341fcf0ff 100755 --- a/src/graphics/cbatchrenderer.cpp +++ b/src/graphics/cbatchrenderer.cpp @@ -7,7 +7,7 @@ cBatchRenderer::cBatchRenderer() : mNumVertex(0), mTexture(NULL), mBlend(ALPHA_NORMAL), - mCurrentMode(EE_GL_QUADS), + mCurrentMode(EE_DT_QUADS), mRotation(0.0f), mScale(1.0f), mPosition(0.0f, 0.0f), @@ -23,7 +23,7 @@ cBatchRenderer::cBatchRenderer( const eeUint& Prealloc ) : mNumVertex(0), mTexture(NULL), mBlend(ALPHA_NORMAL), - mCurrentMode(EE_GL_QUADS), + mCurrentMode(EE_DT_QUADS), mRotation(0.0f), mScale(1.0f), mPosition(0.0f, 0.0f), @@ -73,7 +73,7 @@ void cBatchRenderer::AddVertexs( const eeUint& num ) { Flush(); } -void cBatchRenderer::SetBlendMode( EE_BATCH_RENDER_METHOD Mode, const bool& Force ) { +void cBatchRenderer::SetBlendMode( EE_DRAW_TYPE Mode, const bool& Force ) { if ( Force && mCurrentMode != Mode ) { Flush(); mCurrentMode = Mode; @@ -93,7 +93,7 @@ void cBatchRenderer::Flush() { cTextureFactory::instance()->SetBlendFunc( mBlend ); - if ( mCurrentMode == EE_GL_POINTS && NULL != mTexture ) { + if ( mCurrentMode == EE_DT_POINTS && NULL != mTexture ) { glEnable( GL_POINT_SPRITE_ARB ); glTexEnvf( GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE ); glPointSize( (GLfloat)mTexture->Width() ); @@ -120,7 +120,7 @@ void cBatchRenderer::Flush() { if ( CreateMatrix ) glPopMatrix(); - if ( mCurrentMode == EE_GL_POINTS && mTexture > 0 ) { + if ( mCurrentMode == EE_DT_POINTS && mTexture > 0 ) { glDisable( GL_POINT_SPRITE_ARB ); } @@ -142,7 +142,7 @@ void cBatchRenderer::BatchQuad( const eeFloat& x, const eeFloat& y, const eeFloa } #ifndef EE_GLES - SetBlendMode( EE_GL_QUADS, mForceBlendMode ); + SetBlendMode( EE_DT_QUADS, mForceBlendMode ); mTVertex = &mVertex[ mNumVertex ]; mTVertex->pos.x = x; @@ -172,7 +172,7 @@ void cBatchRenderer::BatchQuad( const eeFloat& x, const eeFloat& y, const eeFloa mTVertex->color = mVerColor[3]; Rotate(center, &mTVertex->pos, angle); #else - SetBlendMode( EE_GL_TRIANGLE_STRIP, mForceBlendMode ); + SetBlendMode( EE_DT_TRIANGLE_STRIP, mForceBlendMode ); mTVertex = &mVertex[ mNumVertex ]; mTVertex->pos.x = x; @@ -232,7 +232,7 @@ void cBatchRenderer::BatchQuadEx( const eeFloat& x, const eeFloat& y, const eeFl center.y += y; #ifndef EE_GLES - SetBlendMode( EE_GL_QUADS, mForceBlendMode ); + SetBlendMode( EE_DT_QUADS, mForceBlendMode ); mTVertex = &mVertex[ mNumVertex ]; mTVertex->pos.x = mx; @@ -262,7 +262,7 @@ void cBatchRenderer::BatchQuadEx( const eeFloat& x, const eeFloat& y, const eeFl mTVertex->color = mVerColor[3]; Rotate(center, &mTVertex->pos, angle); #else - SetBlendMode( EE_GL_TRIANGLE_STRIP, mForceBlendMode ); + SetBlendMode( EE_DT_TRIANGLE_STRIP, mForceBlendMode ); mTVertex = &mVertex[ mNumVertex ]; mTVertex->pos.x = mx; @@ -301,7 +301,7 @@ void cBatchRenderer::BatchQuadFree( const eeFloat& x0, const eeFloat& y0, const return; #ifndef EE_GLES - SetBlendMode( EE_GL_QUADS, mForceBlendMode ); + SetBlendMode( EE_DT_QUADS, mForceBlendMode ); mTVertex = &mVertex[ mNumVertex ]; mTVertex->pos.x = x0; @@ -327,7 +327,7 @@ void cBatchRenderer::BatchQuadFree( const eeFloat& x0, const eeFloat& y0, const mTVertex->tex = mTexCoord[3]; mTVertex->color = mVerColor[3]; #else - SetBlendMode( EE_GL_TRIANGLE_STRIP, mForceBlendMode ); + SetBlendMode( EE_DT_TRIANGLE_STRIP, mForceBlendMode ); mTVertex = &mVertex[ mNumVertex ]; mTVertex->pos.x = x0; @@ -397,7 +397,7 @@ void cBatchRenderer::BatchQuadFreeEx( const eeFloat& x0, const eeFloat& y0, cons mQ = RotateQuadCentered( mQ, Angle, QCenter ); #ifndef EE_GLES - SetBlendMode( EE_GL_QUADS, mForceBlendMode ); + SetBlendMode( EE_DT_QUADS, mForceBlendMode ); mTVertex = &mVertex[ mNumVertex ]; mTVertex->pos.x = mQ[0].x; @@ -423,7 +423,7 @@ void cBatchRenderer::BatchQuadFreeEx( const eeFloat& x0, const eeFloat& y0, cons mTVertex->tex = mTexCoord[3]; mTVertex->color = mVerColor[3]; #else - SetBlendMode( EE_GL_TRIANGLE_STRIP, mForceBlendMode ); + SetBlendMode( EE_DT_TRIANGLE_STRIP, mForceBlendMode ); mTVertex = &mVertex[ mNumVertex ]; mTVertex->pos.x = mQ[0].x; @@ -454,7 +454,7 @@ void cBatchRenderer::BatchQuadFreeEx( const eeFloat& x0, const eeFloat& y0, cons } void cBatchRenderer::QuadsBegin() { - SetBlendMode( EE_GL_QUADS, true ); + SetBlendMode( EE_DT_QUADS, true ); QuadsSetSubset( 0, 0, 1, 1 ); QuadsSetColor( eeColorA() ); } @@ -495,7 +495,7 @@ void cBatchRenderer::Rotate( const eeVector2f& center, eeVector2f* point, const } void cBatchRenderer::PointsBegin() { - SetBlendMode( EE_GL_POINTS, true ); + SetBlendMode( EE_DT_POINTS, true ); QuadsSetSubset( 0, 0, 1, 1 ); PointSetColor( eeColorA() ); } @@ -508,7 +508,7 @@ void cBatchRenderer::BatchPoint( const eeFloat& x, const eeFloat& y ) { if ( mNumVertex + 1 >= mVertex.size() ) return; - SetBlendMode( EE_GL_POINTS, mForceBlendMode ); + SetBlendMode( EE_DT_POINTS, mForceBlendMode ); mTVertex = &mVertex[ mNumVertex ]; mTVertex->pos.x = x; @@ -520,7 +520,7 @@ void cBatchRenderer::BatchPoint( const eeFloat& x, const eeFloat& y ) { } void cBatchRenderer::LinesBegin() { - SetBlendMode( EE_GL_LINES, true ); + SetBlendMode( EE_DT_LINES, true ); QuadsSetSubset( 0, 0, 1, 1 ); PointSetColor( eeColorA() ); } @@ -537,7 +537,7 @@ void cBatchRenderer::BatchLine( const eeFloat& x0, const eeFloat& y0, const eeFl if ( mNumVertex + 1 >= mVertex.size() ) return; - SetBlendMode( EE_GL_LINES, mForceBlendMode ); + SetBlendMode( EE_DT_LINES, mForceBlendMode ); mTVertex = &mVertex[ mNumVertex ]; mTVertex->pos.x = x0; @@ -555,7 +555,7 @@ void cBatchRenderer::BatchLine( const eeFloat& x0, const eeFloat& y0, const eeFl } void cBatchRenderer::LineLoopBegin() { - SetBlendMode( EE_GL_LINE_LOOP, true ); + SetBlendMode( EE_DT_LINE_LOOP, true ); QuadsSetSubset( 0, 0, 1, 1 ); PointSetColor( eeColorA() ); } @@ -572,7 +572,7 @@ void cBatchRenderer::BatchLineLoop( const eeFloat& x0, const eeFloat& y0, const if ( mNumVertex + 1 >= mVertex.size() ) return; - SetBlendMode( EE_GL_LINE_LOOP, mForceBlendMode ); + SetBlendMode( EE_DT_LINE_LOOP, mForceBlendMode ); mTVertex = &mVertex[ mNumVertex ]; mTVertex->pos.x = x0; @@ -597,7 +597,7 @@ void cBatchRenderer::BatchLineLoop( const eeFloat& x0, const eeFloat& y0 ) { if ( mNumVertex + 1 >= mVertex.size() ) return; - SetBlendMode( EE_GL_LINE_LOOP, mForceBlendMode ); + SetBlendMode( EE_DT_LINE_LOOP, mForceBlendMode ); mTVertex = &mVertex[ mNumVertex ]; mTVertex->pos.x = x0; @@ -613,7 +613,7 @@ void cBatchRenderer::BatchLineLoop( const eeVector2f& vector1 ) { } void cBatchRenderer::TriangleFanBegin() { - SetBlendMode( EE_GL_TRIANGLE_FAN, true ); + SetBlendMode( EE_DT_TRIANGLE_FAN, true ); TriangleFanSetSubset( 0, 0, 0, 1, 1, 1 ); TriangleFanSetColor( eeColorA() ); } @@ -637,7 +637,7 @@ void cBatchRenderer::BatchTriangleFan( const eeFloat& x0, const eeFloat& y0, con if ( mNumVertex + 2 >= mVertex.size() ) return; - SetBlendMode( EE_GL_TRIANGLE_FAN, mForceBlendMode ); + SetBlendMode( EE_DT_TRIANGLE_FAN, mForceBlendMode ); mTVertex = &mVertex[ mNumVertex ]; mTVertex->pos.x = x0; @@ -661,7 +661,7 @@ void cBatchRenderer::BatchTriangleFan( const eeFloat& x0, const eeFloat& y0, con } void cBatchRenderer::TrianglesBegin() { - SetBlendMode( EE_GL_TRIANGLES, true ); + SetBlendMode( EE_DT_TRIANGLES, true ); TrianglesSetSubset( 0, 0, 0, 1, 1, 1 ); TrianglesSetColor( eeColorA() ); } @@ -685,7 +685,7 @@ void cBatchRenderer::BatchTriangle( const eeFloat& x0, const eeFloat& y0, const if ( mNumVertex + 2 >= mVertex.size() ) return; - SetBlendMode( EE_GL_TRIANGLES, mForceBlendMode ); + SetBlendMode( EE_DT_TRIANGLES, mForceBlendMode ); mTVertex = &mVertex[ mNumVertex ]; mTVertex->pos.x = x0; @@ -716,7 +716,7 @@ void cBatchRenderer::BatchPolygon( const eePolygon2f& Polygon ) { if ( Polygon.Size() > mVertex.size() ) return; - SetBlendMode( EE_GL_POLYGON, mForceBlendMode ); + SetBlendMode( EE_DT_POLYGON, mForceBlendMode ); for ( Uint32 i = 0; i < Polygon.Size(); i++ ) { mTVertex = &mVertex[ mNumVertex ]; @@ -734,7 +734,7 @@ void cBatchRenderer::BatchPolygonByPoint( const eeFloat& x, const eeFloat& y ) { if ( mNumVertex + 1 >= mVertex.size() ) return; - SetBlendMode( EE_GL_POLYGON, mForceBlendMode ); + SetBlendMode( EE_DT_POLYGON, mForceBlendMode ); mTVertex = &mVertex[ mNumVertex ]; mTVertex->pos.x = x; diff --git a/src/graphics/cbatchrenderer.hpp b/src/graphics/cbatchrenderer.hpp index 14c1f528c..83826acc5 100755 --- a/src/graphics/cbatchrenderer.hpp +++ b/src/graphics/cbatchrenderer.hpp @@ -71,16 +71,16 @@ class EE_API cBatchRenderer { /** @return The batch center position */ eeVector2f BatchCenter() const { return mCenter; } - /** Add to the batch a quad ( this will change your batch rendering method to GL_QUADS, so if you were using another one will Draw all the batched vertexs first ) */ + /** Add to the batch a quad ( this will change your batch rendering method to EE_DT_QUADS, so if you were using another one will Draw all the batched vertexs first ) */ void BatchQuadEx( const eeFloat& x, const eeFloat& y, const eeFloat& width, const eeFloat& height, const eeFloat& angle = 0.0f, const eeFloat& scale = 1.0f, const bool& scalefromcenter = true ); - /** Add to the batch a quad ( this will change your batch rendering method to GL_QUADS, so if you were using another one will Draw all the batched vertexs first ) */ + /** Add to the batch a quad ( this will change your batch rendering method to EE_DT_QUADS, so if you were using another one will Draw all the batched vertexs first ) */ void BatchQuad( const eeFloat& x, const eeFloat& y, const eeFloat& width, const eeFloat& height, const eeFloat& angle = 0.0f ); - /** Add to the batch a quad with the vertex freely seted ( this will change your batch rendering method to GL_QUADS, so if you were using another one will Draw all the batched vertexs first ) */ + /** Add to the batch a quad with the vertex freely seted ( this will change your batch rendering method to EE_DT_QUADS, so if you were using another one will Draw all the batched vertexs first ) */ void BatchQuadFree( const eeFloat& x0, const eeFloat& y0, const eeFloat& x1, const eeFloat& y1, const eeFloat& x2, const eeFloat& y2, const eeFloat& x3, const eeFloat& y3 ); - /** Add to the batch a quad with the vertex freely seted ( this will change your batch rendering method to GL_QUADS, so if you were using another one will Draw all the batched vertexs first ) */ + /** Add to the batch a quad with the vertex freely seted ( this will change your batch rendering method to EE_DT_QUADS, so if you were using another one will Draw all the batched vertexs first ) */ void BatchQuadFreeEx( const eeFloat& x0, const eeFloat& y0, const eeFloat& x1, const eeFloat& y1, const eeFloat& x2, const eeFloat& y2, const eeFloat& x3, const eeFloat& y3, const eeFloat& Angle = 0.0f, const eeFloat& Scale = 1.0f ); /** This will set as the default batch rendering to GL_QUADS. WIll reset the texture subset rendering to the whole texture. Will reset the default color rendering to eeColorA(255,255,255,255). */ @@ -98,16 +98,16 @@ class EE_API cBatchRenderer { /** Set the quad color per vertex */ void QuadsSetColorFree( const eeColorA Color0, const eeColorA Color1, const eeColorA Color2, const eeColorA Color3 ); - /** This will set as the default batch rendering to GL_POINTS. And will reset the point color to eeColorA(255,255,255,255). */ + /** This will set as the default batch rendering to EE_DT_POINTS. And will reset the point color to eeColorA(255,255,255,255). */ void PointsBegin(); /** Set the point color */ void PointSetColor( const eeColorA Color ); - /** Add to the batch a point ( this will change your batch rendering method to GL_POINTS, so if you were using another one will Draw all the batched vertexs first ) */ + /** Add to the batch a point ( this will change your batch rendering method to EE_DT_POINTS, so if you were using another one will Draw all the batched vertexs first ) */ void BatchPoint( const eeFloat& x, const eeFloat& y ); - /** This will set as the default batch rendering to GL_LINES. And will reset the line color to eeColorA(255,255,255,255). */ + /** This will set as the default batch rendering to EE_DT_LINES. And will reset the line color to eeColorA(255,255,255,255). */ void LinesBegin(); /** Set the line color */ @@ -116,7 +116,7 @@ class EE_API cBatchRenderer { /** Set the line color, per vertex */ void LinesSetColorFree( const eeColorA Color0, const eeColorA Color1 ); - /** Add to the batch a line ( this will change your batch rendering method to GL_LINES, so if you were using another one will Draw all the batched vertexs first ) */ + /** Add to the batch a line ( this will change your batch rendering method to EE_DT_LINES, so if you were using another one will Draw all the batched vertexs first ) */ void BatchLine( const eeFloat& x0, const eeFloat& y0, const eeFloat& x1, const eeFloat& y1 ); /** This will set as the default batch rendering to GL_LINE_LOOP. And will reset the line color to eeColorA(255,255,255,255). */ @@ -128,7 +128,7 @@ class EE_API cBatchRenderer { /** Set the line color, per vertex */ void LineLoopSetColorFree( const eeColorA Color0, const eeColorA Color1 ); - /** Add to the batch a line ( this will change your batch rendering method to GL_LINE_LOOP, so if you were using another one will Draw all the batched vertexs first ) */ + /** Add to the batch a line ( this will change your batch rendering method to EE_DT_LINE_LOOP, so if you were using another one will Draw all the batched vertexs first ) */ void BatchLineLoop( const eeFloat& x0, const eeFloat& y0, const eeFloat& x1, const eeFloat& y1 ); void BatchLineLoop( const eeFloat& x0, const eeFloat& y0); @@ -137,7 +137,7 @@ class EE_API cBatchRenderer { void BatchLineLoop( const eeVector2f& vector1 ); - /** This will set as the default batch rendering to GL_TRIANGLE_FAN. And will reset the line color to eeColorA(255,255,255,255). */ + /** This will set as the default batch rendering to EE_DT_TRIANGLE_FAN. And will reset the line color to eeColorA(255,255,255,255). */ void TriangleFanBegin(); /** Set the triangle fan color */ @@ -149,10 +149,10 @@ class EE_API cBatchRenderer { /** Set the texture sector to be rendered but freely seted */ void TriangleFanSetSubset( const eeFloat& x0, const eeFloat& y0, const eeFloat& x1, const eeFloat& y1, const eeFloat& x2, const eeFloat& y2 ); - /** Add to the batch a triangle fan ( this will change your batch rendering method to GL_TRIANGLE_FAN, so if you were using another one will Draw all the batched vertexs first ) */ + /** Add to the batch a triangle fan ( this will change your batch rendering method to EE_DT_TRIANGLE_FAN, so if you were using another one will Draw all the batched vertexs first ) */ void BatchTriangleFan( const eeFloat& x0, const eeFloat& y0, const eeFloat& x1, const eeFloat& y1, const eeFloat& x2, const eeFloat& y2 ); - /** This will set as the default batch rendering to GL_TRIANGLES. And will reset the line color to eeColorA(255,255,255,255). */ + /** This will set as the default batch rendering to EE_DT_TRIANGLES. And will reset the line color to eeColorA(255,255,255,255). */ void TrianglesBegin(); /** Set the triangles color */ @@ -164,13 +164,13 @@ class EE_API cBatchRenderer { /** Set the texture sector to be rendered but freely seted */ void TrianglesSetSubset( const eeFloat& x0, const eeFloat& y0, const eeFloat& x1, const eeFloat& y1, const eeFloat& x2, const eeFloat& y2 ); - /** Add to the batch a triangle ( this will change your batch rendering method to GL_TRIANGLES, so if you were using another one will Draw all the batched vertexs first ) */ + /** Add to the batch a triangle ( this will change your batch rendering method to EE_DT_TRIANGLES, so if you were using another one will Draw all the batched vertexs first ) */ void BatchTriangle( const eeFloat& x0, const eeFloat& y0, const eeFloat& x1, const eeFloat& y1, const eeFloat& x2, const eeFloat& y2 ); /** Set the polygon color */ void PolygonSetColor( const eeColorA& Color ); - /** Add to the batch a polygon ( this will change your batch rendering method to GL_POLYGON, so if you were using another one will Draw all the batched vertexs first ) */ + /** Add to the batch a polygon ( this will change your batch rendering method to EE_DT_POLYGON, so if you were using another one will Draw all the batched vertexs first ) */ void BatchPolygon( const eePolygon2f& Polygon ); /** Set the line width */ @@ -197,7 +197,7 @@ class EE_API cBatchRenderer { eeTexCoord mTexCoord[4]; eeColorA mVerColor[4]; - EE_BATCH_RENDER_METHOD mCurrentMode; + EE_DRAW_TYPE mCurrentMode; eeFloat mRotation, mScale; eeVector2f mPosition, mCenter; @@ -209,7 +209,7 @@ class EE_API cBatchRenderer { void Init(); void AddVertexs( const eeUint& num ); void Rotate( const eeVector2f& center, eeVector2f* point, const eeFloat& angle ); - void SetBlendMode( EE_BATCH_RENDER_METHOD Mode, const bool& Force ); + void SetBlendMode( EE_DRAW_TYPE Mode, const bool& Force ); }; }} diff --git a/src/graphics/cframebuffer.cpp b/src/graphics/cframebuffer.cpp index d637beba9..fa791ea0b 100644 --- a/src/graphics/cframebuffer.cpp +++ b/src/graphics/cframebuffer.cpp @@ -8,10 +8,10 @@ namespace EE { namespace Graphics { cFrameBuffer * cFrameBuffer::CreateNew( const Uint32& Width, const Uint32& Height, bool DepthBuffer ) { if ( cFrameBufferFBO::IsSupported() ) - return new cFrameBufferFBO( Width, Height, DepthBuffer ); + return eeNew( cFrameBufferFBO, ( Width, Height, DepthBuffer ) ); if ( cFrameBufferPBuffer::IsSupported() ) - return new cFrameBufferPBuffer( Width, Height, DepthBuffer ); + return eeNew( cFrameBufferPBuffer, ( Width, Height, DepthBuffer ) ); return NULL; } diff --git a/src/graphics/cimage.cpp b/src/graphics/cimage.cpp index a7a1d0047..32cf9dd3a 100644 --- a/src/graphics/cimage.cpp +++ b/src/graphics/cimage.cpp @@ -109,7 +109,7 @@ Uint8* cImage::GetPixels() const { void cImage::Allocate( const Uint32& size ) { ClearCache(); - mPixels = new unsigned char[ size ]; + mPixels = eeNewArray( unsigned char, size ); mSize = size; } @@ -145,7 +145,7 @@ eeUint cImage::Channels() const { return mChannels; } -bool cImage::SaveToFile( const std::string& filepath, const EE_SAVETYPE& Format ) { +bool cImage::SaveToFile( const std::string& filepath, const EE_SAVE_TYPE& Format ) { bool Res = false; if ( NULL != mPixels && 0 != mWidth && 0 != mHeight && 0 != mChannels ) { @@ -233,7 +233,7 @@ void cImage::CopyImage( cImage * Img, const eeUint& x, const eeUint& y ) { void cImage::Resize( const eeUint& new_width, const eeUint& new_height ) { if ( NULL != mPixels && mWidth != new_width && mHeight != new_height ) { - unsigned char * resampled = new unsigned char[ mChannels * new_width * new_height ]; + unsigned char * resampled = eeNewArray( unsigned char, mChannels * new_width * new_height ); int res = up_scale_image( reinterpret_cast ( mPixels ), mWidth, mHeight, mChannels, resampled, new_width, new_height ); @@ -266,12 +266,12 @@ cImage * cImage::Thumbnail( const eeUint& max_width, const eeUint& max_height ) Int32 new_width = (Int32)( (eeFloat)mWidth * iScale ); Int32 new_height = (Int32)( (eeFloat)mHeight * iScale ); - unsigned char * resampled = new unsigned char[ mChannels * new_width * new_height ]; + unsigned char * resampled = eeNewArray( unsigned char, mChannels * new_width * new_height ); int res = up_scale_image( reinterpret_cast ( mPixels ), mWidth, mHeight, mChannels, resampled, new_width, new_height ); if ( res ) { - return new cImage( (Uint8*)resampled, new_width, new_height, mChannels ); + return eeNew( cImage, ( (Uint8*)resampled, new_width, new_height, mChannels ) ); } else { eeSAFE_DELETE_ARRAY( resampled ); } diff --git a/src/graphics/cimage.hpp b/src/graphics/cimage.hpp index 8bde1ec7a..fc8396393 100644 --- a/src/graphics/cimage.hpp +++ b/src/graphics/cimage.hpp @@ -63,7 +63,7 @@ class EE_API cImage { eeUint Size() const; /** Save the Image to a new File in a specific format */ - virtual bool SaveToFile( const std::string& filepath, const EE_SAVETYPE& Format ); + virtual bool SaveToFile( const std::string& filepath, const EE_SAVE_TYPE& Format ); /** Create an Alpha mask from a Color */ virtual void CreateMaskFromColor( const eeColorA& ColorKey, Uint8 Alpha ); diff --git a/src/graphics/cshaderprogram.cpp b/src/graphics/cshaderprogram.cpp index 3841b73ba..b4e0ed0b3 100644 --- a/src/graphics/cshaderprogram.cpp +++ b/src/graphics/cshaderprogram.cpp @@ -30,8 +30,8 @@ cShaderProgram::cShaderProgram( const std::string& VertexShaderFile, const std:: AddToManager( name ); Init(); - cVertexShader * vs = new cVertexShader( VertexShaderFile ); - cFragmentShader * fs = new cFragmentShader( FragmentShaderFile ); + cVertexShader * vs = eeNew( cVertexShader, ( VertexShaderFile ) ); + cFragmentShader * fs = eeNew( cFragmentShader, ( FragmentShaderFile ) ); if ( !vs->IsValid() || !fs->IsValid() ) { eeSAFE_DELETE( vs ); @@ -52,8 +52,8 @@ cShaderProgram::cShaderProgram( cPack * Pack, const std::string& VertexShaderPat Init(); if ( NULL != Pack && Pack->IsOpen() && -1 != Pack->Exists( VertexShaderPath ) && -1 != Pack->Exists( FragmentShaderPath ) ) { - cVertexShader * vs = new cVertexShader( Pack, VertexShaderPath ); - cFragmentShader * fs = new cFragmentShader( Pack, FragmentShaderPath ); + cVertexShader * vs = eeNew( cVertexShader, ( Pack, VertexShaderPath ) ); + cFragmentShader * fs = eeNew( cFragmentShader, ( Pack, FragmentShaderPath ) ); if ( !vs->IsValid() || !fs->IsValid() ) { eeSAFE_DELETE( vs ); @@ -74,8 +74,8 @@ cShaderProgram::cShaderProgram( const Uint8 * VertexShaderData, const Uint32& Ve AddToManager( name ); Init(); - cVertexShader * vs = new cVertexShader( VertexShaderData, VertexShaderDataSize ); - cFragmentShader * fs = new cFragmentShader( FragmentShaderData, FragmentShaderDataSize ); + cVertexShader * vs = eeNew( cVertexShader, ( VertexShaderData, VertexShaderDataSize ) ); + cFragmentShader * fs = eeNew( cFragmentShader, ( FragmentShaderData, FragmentShaderDataSize ) ); if ( !vs->IsValid() || !fs->IsValid() ) { eeSAFE_DELETE( vs ); diff --git a/src/graphics/cshape.cpp b/src/graphics/cshape.cpp index af0503150..787c2a1a5 100644 --- a/src/graphics/cshape.cpp +++ b/src/graphics/cshape.cpp @@ -198,7 +198,7 @@ void cShape::CacheAlphaMask() { Uint32 size = ( mSrcRect.Right - mSrcRect.Left ) * ( mSrcRect.Bottom - mSrcRect.Top ); eeSAFE_DELETE_ARRAY( mAlpha ); - mAlpha = new Uint8[ size ]; + mAlpha = eeNewArray( Uint8, size ); mTexture->Lock(); @@ -226,7 +226,7 @@ void cShape::CacheColors() { eeSAFE_DELETE_ARRAY( mPixels ); - mPixels = new Uint8[ size ]; + mPixels = eeNewArray( Uint8, size ); eeInt rY = 0; eeInt rX = 0; @@ -371,7 +371,7 @@ const Uint8* cShape::GetPixelsPtr() { return reinterpret_cast (&mPixels[0]); } -bool cShape::SaveToFile(const std::string& filepath, const EE_SAVETYPE& Format) { +bool cShape::SaveToFile(const std::string& filepath, const EE_SAVE_TYPE& Format) { bool Res = false; Lock(); diff --git a/src/graphics/cshape.hpp b/src/graphics/cshape.hpp index 357496279..e30c48016 100644 --- a/src/graphics/cshape.hpp +++ b/src/graphics/cshape.hpp @@ -85,7 +85,7 @@ class EE_API cShape { const Uint8* GetPixelsPtr(); - bool SaveToFile(const std::string& filepath, const EE_SAVETYPE& Format); + bool SaveToFile(const std::string& filepath, const EE_SAVE_TYPE& Format); protected: Uint8 * mPixels; Uint8 * mAlpha; diff --git a/src/graphics/cshapegroup.cpp b/src/graphics/cshapegroup.cpp index 5d0613f08..27876f4cc 100644 --- a/src/graphics/cshapegroup.cpp +++ b/src/graphics/cshapegroup.cpp @@ -29,19 +29,19 @@ cShape * cShapeGroup::Add( cShape * Shape ) { } cShape * cShapeGroup::Add( const Uint32& TexId, const std::string& Name ) { - return Add( new cShape( TexId, Name ) ); + return Add( eeNew( cShape, ( TexId, Name ) ) ); } cShape * cShapeGroup::Add( const Uint32& TexId, const eeRecti& SrcRect, const std::string& Name ) { - return Add( new cShape( TexId, SrcRect, Name ) ); + return Add( eeNew( cShape, ( TexId, SrcRect, Name ) ) ); } cShape * cShapeGroup::Add( const Uint32& TexId, const eeRecti& SrcRect, const eeFloat& DestWidth, const eeFloat& DestHeight, const std::string& Name ) { - return Add( new cShape( TexId, SrcRect, DestWidth, DestHeight, Name ) ); + return Add( eeNew ( cShape, ( TexId, SrcRect, DestWidth, DestHeight, Name ) ) ); } cShape * cShapeGroup::Add( const Uint32& TexId, const eeRecti& SrcRect, const eeFloat& DestWidth, const eeFloat& DestHeight, const eeFloat& OffsetX, const eeFloat& OffsetY, const std::string& Name ) { - return Add( new cShape( TexId, SrcRect, DestWidth, DestHeight, OffsetX, OffsetY, Name ) ); + return Add( eeNew ( cShape, ( TexId, SrcRect, DestWidth, DestHeight, OffsetX, OffsetY, Name ) ) ); } }} diff --git a/src/graphics/csprite.cpp b/src/graphics/csprite.cpp index 7aed288e9..3fc3096a1 100755 --- a/src/graphics/csprite.cpp +++ b/src/graphics/csprite.cpp @@ -274,7 +274,7 @@ bool cSprite::AddSubFrame(const Uint32& TexId, const eeUint& NumFrame, const eeU return false; cTexture * Tex = cTextureFactory::instance()->GetTexture( TexId ); - cShape * S = cGlobalShapeGroup::instance()->Add( new cShape() ); + cShape * S = cGlobalShapeGroup::instance()->Add( eeNew( cShape, () ) ); S->Texture( TexId ); diff --git a/src/graphics/ctexture.cpp b/src/graphics/ctexture.cpp index 232f2caf6..fc2dc873b 100755 --- a/src/graphics/ctexture.cpp +++ b/src/graphics/ctexture.cpp @@ -210,7 +210,7 @@ void cTexture::SetPixel( const eeUint& x, const eeUint& y, const eeColorA& Color mFlags |= TEX_FLAG_MODIFIED; } -bool cTexture::SaveToFile( const std::string& filepath, const EE_SAVETYPE& Format ) { +bool cTexture::SaveToFile( const std::string& filepath, const EE_SAVE_TYPE& Format ) { bool Res = false; if ( mTexture ) { diff --git a/src/graphics/ctexture.hpp b/src/graphics/ctexture.hpp index bd9df78cd..e166208e6 100755 --- a/src/graphics/ctexture.hpp +++ b/src/graphics/ctexture.hpp @@ -92,7 +92,7 @@ class EE_API cTexture : public cImage { void SetTextureFilter(const EE_TEX_FILTER& filter); /** Save the Texture to a new File */ - bool SaveToFile( const std::string& filepath, const EE_SAVETYPE& Format ); + bool SaveToFile( const std::string& filepath, const EE_SAVE_TYPE& Format ); /** Replace a color on the texture */ void ReplaceColor( const eeColorA& ColorKey, const eeColorA& NewColor); diff --git a/src/graphics/ctexturefactory.cpp b/src/graphics/ctexturefactory.cpp index f7eb22201..b3aa5a65f 100755 --- a/src/graphics/ctexturefactory.cpp +++ b/src/graphics/ctexturefactory.cpp @@ -66,7 +66,7 @@ Uint32 cTextureFactory::PushTexture( const std::string& Filepath, const Uint32& FPath = FPath.substr( pos + 1 ); Pos = FindFreeSlot(); - Tex = mTextures[ Pos ] = new cTexture(); + Tex = mTextures[ Pos ] = eeNew( cTexture, () ); Tex->Create( TexId, Width, Height, MyWidth, MyHeight, Mipmap, Channels, FPath, ColorKey, ClampMode, CompressTexture, MemSize ); Tex->TexId( Pos ); @@ -251,7 +251,7 @@ eeUint cTextureFactory::GetValidTextureSize(const eeUint& Size) { return NextPowOfTwo(Size); } -bool cTextureFactory::SaveImage( const std::string& filepath, const EE_SAVETYPE& Format, const eeUint& Width, const eeUint& Height, const eeUint& Channels, const unsigned char* data ) { +bool cTextureFactory::SaveImage( const std::string& filepath, const EE_SAVE_TYPE& Format, const eeUint& Width, const eeUint& Height, const eeUint& Channels, const unsigned char* data ) { return 0 != SOIL_save_image ( filepath.c_str(), Format, Width, Height, Channels, data ); } diff --git a/src/graphics/ctexturefactory.hpp b/src/graphics/ctexturefactory.hpp index 7715fe6d0..1a437d2b4 100755 --- a/src/graphics/ctexturefactory.hpp +++ b/src/graphics/ctexturefactory.hpp @@ -130,7 +130,7 @@ class EE_API cTextureFactory: public tSingleton, protected cMut /** Saves an image from an array of unsigned chars to disk * @return False if failed, otherwise returns True */ - bool SaveImage( const std::string& filepath, const EE_SAVETYPE& Format, const eeUint& Width, const eeUint& Height, const eeUint& Channels, const unsigned char* data ); + bool SaveImage( const std::string& filepath, const EE_SAVE_TYPE& Format, const eeUint& Width, const eeUint& Height, const eeUint& Channels, const unsigned char* data ); /** Determine if the TextureId passed exists */ bool TextureIdExists( const Uint32& TexId ); @@ -181,9 +181,10 @@ class EE_API cTextureFactory: public tSingleton, protected cMut * @return The texture, NULL if not exists */ cTexture * GetByHash( const Uint32& Hash ); + + ~cTextureFactory(); protected: cTextureFactory(); - ~cTextureFactory(); GLint mCurrentTexture; diff --git a/src/graphics/ctexturefontloader.cpp b/src/graphics/ctexturefontloader.cpp index fae3e10ed..970345c29 100644 --- a/src/graphics/ctexturefontloader.cpp +++ b/src/graphics/ctexturefontloader.cpp @@ -113,7 +113,7 @@ void cTextureFontLoader::LoadFromTex() { } void cTextureFontLoader::LoadFont() { - mFont = new cTextureFont( mFontName ); + mFont = eeNew( cTextureFont, ( mFontName ) ); if ( TEF_LT_PATH == mLoadType ) LoadFromPath(); diff --git a/src/graphics/ctexturegrouploader.cpp b/src/graphics/ctexturegrouploader.cpp index 938f2f2f2..add109d26 100644 --- a/src/graphics/ctexturegrouploader.cpp +++ b/src/graphics/ctexturegrouploader.cpp @@ -84,7 +84,7 @@ void cTextureGroupLoader::Load( const std::string& TextureGroupPath ) { std::string path( FileRemoveFileName( mTextureGroupPath ) + name ); if ( !mSkipResourceLoad ) - mRL.Add( new cTextureLoader( path ) ); + mRL.Add( eeNew( cTextureLoader, ( path ) ) ); fs.read( reinterpret_cast (&tTexGroup.Shapes[0]), sizeof(sShapeHdr) * tTextureHdr.ShapeCount ); @@ -139,9 +139,9 @@ void cTextureGroupLoader::LoadFromMemory( const Uint8* Data, const Uint32& DataS std::string path( FileRemoveFileName( mTextureGroupPath ) + name ); if ( NULL != mPack ) - mRL.Add( new cTextureLoader( mPack, path ) ); + mRL.Add( eeNew( cTextureLoader, ( mPack, path ) ) ); else - mRL.Add( new cTextureLoader( mAppPath + path ) ); + mRL.Add( eeNew( cTextureLoader, ( mAppPath + path ) ) ); memcpy( (void*)(&tTexGroup.Shapes[0]), dataPtr, sizeof(sShapeHdr) * tTextureHdr.ShapeCount ); dataPtr += sizeof(sShapeHdr) * tTextureHdr.ShapeCount; @@ -179,7 +179,7 @@ void cTextureGroupLoader::CreateShapes() { if ( mTexGrHdr.Flags & HDR_TEXTURE_GROUP_REMOVE_EXTENSION ) name = FileRemoveExtension( name ); - tSG = new cShapeGroup( name ); + tSG = eeNew( cShapeGroup, ( name ) ); cShapeGroupManager::instance()->Add( tSG ); } @@ -194,7 +194,7 @@ void cTextureGroupLoader::CreateShapes() { eeRecti tRect( tSh->X, tSh->Y, tSh->X + tSh->Width, tSh->Y + tSh->Height ); - cShape * tShape = new cShape( tTex->TexId(), tRect, tSh->DestWidth, tSh->DestHeight, tSh->OffsetX, tSh->OffsetY, ShapeName ); + cShape * tShape = eeNew( cShape, ( tTex->TexId(), tRect, tSh->DestWidth, tSh->DestHeight, tSh->OffsetX, tSh->OffsetY, ShapeName ) ); //if ( tSh->Flags & HDR_SHAPE_FLAG_FLIPED ) // Should rotate the shape, but.. shape rotation is not stored. @@ -306,7 +306,7 @@ bool cTextureGroupLoader::UpdateTextureAtlas( std::string TextureAtlasPath, std: tp.PackTextures(); - tp.Save( tapath, (EE_SAVETYPE)mTexGrHdr.Format ); + tp.Save( tapath, (EE_SAVE_TYPE)mTexGrHdr.Format ); } else if ( 1 == NeedUpdate ) { std::string etgpath = FileRemoveExtension( tapath ) + ".etg"; std::fstream fs ( etgpath.c_str() , std::ios::out | std::ios::binary ); @@ -358,7 +358,7 @@ bool cTextureGroupLoader::UpdateTextureAtlas( std::string TextureAtlasPath, std: fs.write( reinterpret_cast (&tTexGroup->Shapes[0]), sizeof(sShapeHdr) * tTexHdr->ShapeCount ); - Img.SaveToFile( tapath, (EE_SAVETYPE)mTexGrHdr.Format ); + Img.SaveToFile( tapath, (EE_SAVE_TYPE)mTexGrHdr.Format ); SOIL_free_image_data( imgPtr ); } diff --git a/src/graphics/ctextureloader.cpp b/src/graphics/ctextureloader.cpp index 5ad63dce9..996a0db21 100644 --- a/src/graphics/ctextureloader.cpp +++ b/src/graphics/ctextureloader.cpp @@ -161,7 +161,7 @@ void cTextureLoader::LoadFromPath() { if ( mIsDDS ) { std::fstream fs ( mFilepath.c_str() , std::ios::in | std::ios::binary ); mSize = FileSize( mFilepath ); - mPixels = (Uint8*) malloc( mSize ); + mPixels = (Uint8*) eeMalloc( mSize ); fs.read( reinterpret_cast ( mPixels ), mSize ); fs.close(); @@ -191,7 +191,7 @@ void cTextureLoader::LoadFromMemory() { mIsDDS = 0 != stbi_dds_test_memory( mImagePtr, mSize ); if ( mIsDDS ) { - mPixels = (Uint8*) malloc( mSize ); + mPixels = (Uint8*) eeMalloc( mSize ); memcpy( mPixels, mImagePtr, mSize ); stbi_dds_info_from_memory( mPixels, mSize, &mImgWidth, &mImgHeight, &mChannels, &mIsDDSCompressed ); } else { @@ -234,8 +234,13 @@ void cTextureLoader::LoadFromPixels() { mTexId = cTextureFactory::instance()->PushTexture( mFilepath, tTexId, mImgWidth, mImgHeight, width, height, mMipmap, mChannels, mColorKey, mClampMode, mCompressTexture || mIsDDSCompressed, mLocalCopy, mSize ); } - if ( TEX_LT_PIXELS != mLoadType ) - eeSAFE_FREE( mPixels ); + if ( TEX_LT_PIXELS != mLoadType ) { + if ( mIsDDS ) { + eeFree( mPixels ); + } else { + SOIL_free_image_data( mPixels ); + } + } mPixels = NULL; diff --git a/src/graphics/ctexturepacker.cpp b/src/graphics/ctexturepacker.cpp index f4dcf8513..1c34e55fb 100644 --- a/src/graphics/ctexturepacker.cpp +++ b/src/graphics/ctexturepacker.cpp @@ -85,7 +85,7 @@ void cTexturePacker::SetOptions( const Uint32& MaxWidth, const Uint32& MaxHeight } void cTexturePacker::NewFree( Int32 x, Int32 y, Int32 width, Int32 height ) { - cTexturePackerNode * node = new cTexturePackerNode( x, y, width, height ); + cTexturePackerNode * node = eeNew( cTexturePackerNode, ( x, y, width, height ) ); node->SetNext( mFreeList ); mFreeList = node; } @@ -328,7 +328,7 @@ void cTexturePacker::InsertTexture( cTexturePackerTex * t, cTexturePackerNode * } void cTexturePacker::CreateChild() { - mChild = new cTexturePacker( mWidth, mHeight, mForcePowOfTwo, mPixelBorder, mAllowFlipping ); + mChild = eeNew( cTexturePacker, ( mWidth, mHeight, mForcePowOfTwo, mPixelBorder, mAllowFlipping ) ); std::list::iterator it; cTexturePackerTex * t = NULL; @@ -484,7 +484,7 @@ Int32 cTexturePacker::PackTextures() { // pack the textures, the return code is return ( mWidth * mHeight ) - mTotalArea; } -void cTexturePacker::Save( const std::string& Filepath, const EE_SAVETYPE& Format, const bool& SaveExtensions ) { +void cTexturePacker::Save( const std::string& Filepath, const EE_SAVE_TYPE& Format, const bool& SaveExtensions ) { if ( !mPacked ) PackTextures(); @@ -509,7 +509,7 @@ void cTexturePacker::Save( const std::string& Filepath, const EE_SAVETYPE& Forma Uint8 * data = SOIL_load_image( t->Name().c_str(), &w, &h, &c, 0 ); if ( NULL != data && t->Width() == w && t->Height() == h ) { - cImage * ImgCopy = new cImage( data, w, h, c ); + cImage * ImgCopy = eeNew( cImage, ( data, w, h, c ) ); if ( t->Flipped() ) Img.Flip(); @@ -675,7 +675,7 @@ sTextureHdr cTexturePacker::CreateTextureHdr( cTexturePacker * Packer ) { return TexHdr; } -void cTexturePacker::ChildSave( const EE_SAVETYPE& Format ) { +void cTexturePacker::ChildSave( const EE_SAVE_TYPE& Format ) { if ( NULL != mChild ) { cTexturePacker * Parent = mChild->GetParent(); cTexturePacker * LastParent = NULL; diff --git a/src/graphics/ctexturepacker.hpp b/src/graphics/ctexturepacker.hpp index 50488b699..660b05a18 100644 --- a/src/graphics/ctexturepacker.hpp +++ b/src/graphics/ctexturepacker.hpp @@ -54,7 +54,7 @@ class EE_API cTexturePacker { Int32 PackTextures(); - void Save( const std::string& Filepath, const EE_SAVETYPE& Format = EE_SAVE_TYPE_DDS, const bool& SaveExtensions = false ); + void Save( const std::string& Filepath, const EE_SAVE_TYPE& Format = EE_SAVE_TYPE_DDS, const bool& SaveExtensions = false ); void Close(); @@ -89,7 +89,7 @@ class EE_API cTexturePacker { bool mForcePowOfTwo; Int32 mPixelBorder; bool mSaveExtensions; - EE_SAVETYPE mFormat; + EE_SAVE_TYPE mFormat; cTexturePacker * GetChild() const; @@ -99,7 +99,7 @@ class EE_API cTexturePacker { const std::string& GetFilepath() const; - void ChildSave( const EE_SAVETYPE& Format ); + void ChildSave( const EE_SAVE_TYPE& Format ); void SaveShapes(); diff --git a/src/graphics/cttffont.cpp b/src/graphics/cttffont.cpp index 2fab6355c..eb9ece344 100755 --- a/src/graphics/cttffont.cpp +++ b/src/graphics/cttffont.cpp @@ -94,7 +94,7 @@ bool cTTFFont::iLoad( const eeUint& Size, EE_TTF_FONTSTYLE Style, const bool& Ve mHeight = mFont->Height() + OutlineTotal; - mPixels = new eeColorA[ TexSize ]; + mPixels = eeNewArray( eeColorA, TexSize ); memset( mPixels, 0x00000000, TexSize * 4 ); CurrentPos.Left = OutlineSize; @@ -185,7 +185,7 @@ bool cTTFFont::iLoad( const eeUint& Size, EE_TTF_FONTSTYLE Style, const bool& Ve mGlyphs[i] = TempGlyph; //Free surface - eeSAFE_DELETE_ARRAY( TempGlyphSurface ); + hkSAFE_DELETE_ARRAY( TempGlyphSurface ); } if ( OutlineSize ) { @@ -297,7 +297,7 @@ void cTTFFont::RebuildFromGlyphs() { } } -bool cTTFFont::SaveTexture( const std::string& Filepath, const EE_SAVETYPE& Format ) { +bool cTTFFont::SaveTexture( const std::string& Filepath, const EE_SAVE_TYPE& Format ) { cTexture* Tex = cTextureFactory::instance()->GetTexture(mTexId); if ( Tex != NULL ) @@ -332,7 +332,7 @@ bool cTTFFont::SaveCoordinates( const std::string& Filepath ) { return false; } -bool cTTFFont::Save( const std::string& TexturePath, const std::string& CoordinatesDatPath, const EE_SAVETYPE& Format ) { +bool cTTFFont::Save( const std::string& TexturePath, const std::string& CoordinatesDatPath, const EE_SAVE_TYPE& Format ) { return SaveTexture(TexturePath, Format) && SaveCoordinates( CoordinatesDatPath ); } diff --git a/src/graphics/cttffont.hpp b/src/graphics/cttffont.hpp index c47e78254..b25c77780 100755 --- a/src/graphics/cttffont.hpp +++ b/src/graphics/cttffont.hpp @@ -58,21 +58,21 @@ class EE_API cTTFFont : public cFont { bool LoadFromMemory( Uint8* TTFData, const eeUint& TTFDataSize, const eeUint& Size, EE_TTF_FONTSTYLE Style = EE_TTF_STYLE_NORMAL, const bool& VerticalDraw = false, const Uint16& NumCharsToGen = 512, const eeColor& FontColor = eeColor(), const Uint8& OutlineSize = 0, const eeColor& OutlineColor = eeColor(0,0,0) ); /** Save the texture generated from the TTF file to disk */ - bool SaveTexture( const std::string& Filepath, const EE_SAVETYPE& Format = EE_SAVE_TYPE_PNG ); + bool SaveTexture( const std::string& Filepath, const EE_SAVE_TYPE& Format = EE_SAVE_TYPE_PNG ); /** Save the characters coordinates to use it later to load the Texture Font */ bool SaveCoordinates( const std::string& Filepath ); /** Save the texture generated from the TTF file and the character coordinates. */ - bool Save( const std::string& TexturePath, const std::string& CoordinatesDatPath, const EE_SAVETYPE& Format = EE_SAVE_TYPE_PNG ); - + bool Save( const std::string& TexturePath, const std::string& CoordinatesDatPath, const EE_SAVE_TYPE& Format = EE_SAVE_TYPE_PNG ); + protected: friend class cTTFFontLoader; - + bool ThreadedLoading() const { return mThreadedLoading; } - + void ThreadedLoading( const bool& isThreaded ) { mThreadedLoading = isThreaded; } - + void UpdateLoading(); private: hkFont * mFont; @@ -90,7 +90,7 @@ class EE_API cTTFFont : public cFont { bool mTTFInit; bool mLoadedFromMemory; - + bool mThreadedLoading; bool mTexReady; diff --git a/src/graphics/cttffontloader.cpp b/src/graphics/cttffontloader.cpp index 9891eeb0e..6e47ebfb4 100644 --- a/src/graphics/cttffontloader.cpp +++ b/src/graphics/cttffontloader.cpp @@ -58,7 +58,7 @@ cTTFFontLoader::~cTTFFontLoader() { void cTTFFontLoader::Start() { cObjectLoader::Start(); - mFont = new cTTFFont( mFontName ); + mFont = eeNew( cTTFFont, ( mFontName ) ); mFont->ThreadedLoading( mThreaded ); diff --git a/src/graphics/cvertexbuffer.cpp b/src/graphics/cvertexbuffer.cpp new file mode 100644 index 000000000..5910a7375 --- /dev/null +++ b/src/graphics/cvertexbuffer.cpp @@ -0,0 +1,156 @@ +#include "cvertexbuffer.hpp" +#include "cvertexbufferogl.hpp" +#include "cvertexbuffervbo.hpp" + +namespace EE { namespace Graphics { + +cVertexBuffer * cVertexBuffer::Create( const Uint32& VertexFlags, EE_DRAW_TYPE DrawType, const Int32& ReserveVertexSize, const Int32& ReserveIndexSize, EE_VBO_USAGE_TYPE UsageType ) { + if ( GLEW_ARB_vertex_buffer_object ) + return eeNew( cVertexBufferVBO, ( VertexFlags, DrawType, ReserveVertexSize, ReserveIndexSize, UsageType ) ); + + return eeNew( cVertexBufferOGL, ( VertexFlags, DrawType, ReserveVertexSize, ReserveIndexSize, UsageType ) ); +} + +cVertexBuffer::cVertexBuffer( const Uint32& VertexFlags, EE_DRAW_TYPE DrawType, const Int32& ReserveVertexSize, const Int32& ReserveIndexSize, EE_VBO_USAGE_TYPE UsageType ) : + mVertexFlags( VertexFlags ), + mDrawType( DrawType ), + mUsageType( UsageType ), + mElemDraw(-1) +{ + if( ReserveVertexSize > 0 ) { + for( Int32 i = 0; i < VERTEX_FLAGS_COUNT; i++ ) { + if( VERTEX_FLAG_QUERY( mVertexFlags, i ) ) { + if ( i != VERTEX_FLAG_COLOR ) + mVertexArray[ i ].reserve( ReserveVertexSize * eeVertexElements[ i ] ); + else + mColorArray.reserve( ReserveVertexSize * eeVertexElements[ i ] ); + } + } + } +} + +cVertexBuffer::~cVertexBuffer() { + for( Int32 i = 0; i < VERTEX_FLAGS_COUNT_ARR; i++ ) + mVertexArray[ i ].clear(); + + mColorArray.clear(); + mIndexArray.clear(); +} + +void cVertexBuffer::AddVertex( const Uint32& Type, const eeVector2f& Vertex ) { + if ( Type < VERTEX_FLAGS_COUNT_ARR ) { + mVertexArray[ Type ].push_back( Vertex.x ); + mVertexArray[ Type ].push_back( Vertex.y ); + } +} + +void cVertexBuffer::AddVertex( const eeVector2f& Vertex ) { + AddVertex( VERTEX_FLAG_POSITION, Vertex ); +} + +void cVertexBuffer::AddVertexCoord( const eeVector2f& VertexCoord, const Uint32& TextureLevel ) { + AddVertex( VERTEX_FLAG_TEXTURE0 + TextureLevel, VertexCoord ); +} + +void cVertexBuffer::AddColor( const eeColorA& Color ) { + mColorArray.push_back( Color.R() ); + mColorArray.push_back( Color.G() ); + mColorArray.push_back( Color.B() ); + mColorArray.push_back( Color.A() ); +} + +void cVertexBuffer::AddIndex( const Uint32& Index ) { + mIndexArray.push_back( Index ); + + VERTEX_FLAG_SET( mVertexFlags, VERTEX_FLAG_USE_INDICES ); +} + +void cVertexBuffer::ResizeArray( const Uint32& Type, const Uint32& Size ) { + if ( Type != VERTEX_FLAG_COLOR ) + mVertexArray[ Type ].resize( Size ); + else + mColorArray.resize( Size ); +} + +void cVertexBuffer::ResizeIndices( const Uint32& Size ) { + mIndexArray.resize( Size ); +} + +eeFloat * cVertexBuffer::GetArray( const Uint32& Type ) { + if ( Type && Type < VERTEX_FLAGS_COUNT_ARR && mVertexArray[ Type ].size() ) + return &mVertexArray[ Type - 1 ][0]; + + return NULL; +} + +Uint8 * cVertexBuffer::GetColorArray() { + if ( mColorArray.size() ) + return &mColorArray[0]; + + return NULL; +} + +Uint32 * cVertexBuffer::GetIndices() { + if ( mIndexArray.size() ) + return &mIndexArray[0]; + + return NULL; +} + +Uint32 cVertexBuffer::GetVertexCount() { + return mVertexArray[ VERTEX_FLAG_POSITION ].size() / eeVertexElements[ VERTEX_FLAG_POSITION ]; +} + +Uint32 cVertexBuffer::GetIndexCount() { + return mIndexArray.size(); +} + +eeVector2f cVertexBuffer::GetVector2( const Uint32& Type, const Uint32& Index ) { + /// assert + if( Type < VERTEX_FLAGS_COUNT_ARR && !VERTEX_FLAG_QUERY( mVertexFlags, Type ) ) + return eeVector2f(0.f,0.f); + + Int32 pos = Index * eeVertexElements[ Type ]; + + return eeVector2f( mVertexArray[ Type ][ pos ], mVertexArray[ Type ][ pos + 1 ] ); +} + +eeColorA cVertexBuffer::GetColor( const Uint32& Index ) { + /// assert + if( !VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_COLOR ) ) + return eeColorA(); + + Int32 pos = Index * eeVertexElements[ VERTEX_FLAG_COLOR ]; + + return eeColorA( mColorArray[ pos ], mColorArray[ pos + 1 ], mColorArray[ pos + 2 ], mColorArray[ pos + 3 ] ); +} + +Uint32 cVertexBuffer::GetIndex( const Uint32& Index ) { + /// assert + return mIndexArray[ Index ]; +} + +void cVertexBuffer::SetElementNum( Int32 Num ) { + mElemDraw = Num; +} + +const Int32& cVertexBuffer::GetElementNum() const { + return mElemDraw; +} + +void cVertexBuffer::Unbind() { + if( !VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_POSITION ) ) { + glEnableClientState( GL_VERTEX_ARRAY ); + } + + if( !VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_COLOR ) ) { + glEnableClientState( GL_COLOR_ARRAY ); + } + + if( !VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_TEXTURE0 ) ) { + glEnableClientState( GL_TEXTURE_COORD_ARRAY ); + glEnable( GL_TEXTURE_2D ); + } +} + +}} diff --git a/src/graphics/cvertexbuffer.hpp b/src/graphics/cvertexbuffer.hpp new file mode 100644 index 000000000..1fb0c763f --- /dev/null +++ b/src/graphics/cvertexbuffer.hpp @@ -0,0 +1,72 @@ +#ifndef EE_GRAPHICSCVERTEXBUFFER_HPP +#define EE_GRAPHICSCVERTEXBUFFER_HPP + +#include "base.hpp" +#include "vbohelper.hpp" + +namespace EE { namespace Graphics { + +class cVertexBuffer { + public: + static cVertexBuffer * Create( const Uint32& VertexFlags = VERTEX_FLAGS_DEFAULT, EE_DRAW_TYPE DrawType = EE_DT_QUADS, const Int32& ReserveVertexSize = 0, const Int32& ReserveIndexSize = 0, EE_VBO_USAGE_TYPE UsageType = VBO_USAGE_TYPE_STATIC ); + + cVertexBuffer( const Uint32& VertexFlags = VERTEX_FLAGS_DEFAULT, EE_DRAW_TYPE DrawType = EE_DT_QUADS, const Int32& ReserveVertexSize = 0, const Int32& ReserveIndexSize = 0, EE_VBO_USAGE_TYPE UsageType = VBO_USAGE_TYPE_STATIC ); + + virtual ~cVertexBuffer(); + + void AddVertex( const Uint32& Type, const eeVector2f& Vertex ); + + void AddVertex( const eeVector2f& Vertex ); + + void AddVertexCoord( const eeVector2f& VertexCoord, const Uint32& TextureLevel = 0 ); + + void AddColor( const eeColorA& Color ); + + void AddIndex( const Uint32& Index ); + + void ResizeArray( const Uint32& Type, const Uint32& Size ); + + void ResizeIndices( const Uint32& Size ); + + eeFloat * GetArray( const Uint32& Type ); + + Uint8 * GetColorArray(); + + Uint32 * GetIndices(); + + Uint32 GetVertexCount(); + + Uint32 GetIndexCount(); + + eeVector2f GetVector2( const Uint32& Type, const Uint32& Index ); + + eeColorA GetColor( const Uint32& Index ); + + Uint32 GetIndex( const Uint32& Index ); + + void SetElementNum( Int32 Num ); + + const Int32& GetElementNum() const; + + virtual void Bind() = 0; + + virtual void Unbind(); + + virtual void Draw() = 0; + + virtual bool Compile() = 0; + protected: + Uint32 mVertexFlags; + EE_DRAW_TYPE mDrawType; + EE_VBO_USAGE_TYPE mUsageType; + Int32 mElemDraw; + std::vector mVertexArray[ VERTEX_FLAGS_COUNT - 1 ]; + std::vector mColorArray; + std::vector mIndexArray; + + virtual void SetVertexStates() = 0; +}; + +}} + +#endif diff --git a/src/graphics/cvertexbufferogl.cpp b/src/graphics/cvertexbufferogl.cpp new file mode 100644 index 000000000..f606cb49b --- /dev/null +++ b/src/graphics/cvertexbufferogl.cpp @@ -0,0 +1,66 @@ +#include "cvertexbufferogl.hpp" + +namespace EE { namespace Graphics { + +cVertexBufferOGL::cVertexBufferOGL( const Uint32& VertexFlags, EE_DRAW_TYPE DrawType, const Int32& ReserveVertexSize, const Int32& ReserveIndexSize, EE_VBO_USAGE_TYPE UsageType ) : + cVertexBuffer( VertexFlags, DrawType, ReserveVertexSize, ReserveIndexSize, UsageType ) +{ +} + +cVertexBufferOGL::~cVertexBufferOGL() { +} + +void cVertexBufferOGL::Bind() { + SetVertexStates(); +} + +bool cVertexBufferOGL::Compile() { + return true; +} + +void cVertexBufferOGL::Draw() { + if( VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_USE_INDICES ) ) { + Int32 lSize = mElemDraw; + + if( mElemDraw < 0 ) + lSize = GetIndexCount(); + + glDrawElements( mDrawType, lSize, GL_UNSIGNED_INT, &mIndexArray[0] ); + } else { + glDrawArrays( mDrawType, 0, GetVertexCount() ); + } +} + +void cVertexBufferOGL::SetVertexStates() { + /// POSITION + if( VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_POSITION ) ) { + glEnableClientState( GL_VERTEX_ARRAY ); + glVertexPointer( eeVertexElements[ VERTEX_FLAG_POSITION ], GL_FLOAT, sizeof(float) * eeVertexElements[ VERTEX_FLAG_POSITION ], &mVertexArray[ VERTEX_FLAG_POSITION ][0] ); + } else { + glDisableClientState( GL_VERTEX_ARRAY ); + } + + /// COLOR + if( VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_COLOR ) ) { + glEnableClientState( GL_COLOR_ARRAY ); + glColorPointer( eeVertexElements[ VERTEX_FLAG_COLOR ], GL_UNSIGNED_BYTE, sizeof(Uint8) * eeVertexElements[ VERTEX_FLAG_COLOR ], &mColorArray[0] ); + } else { + glDisableClientState( GL_COLOR_ARRAY ); + } + + /// TEXTURES + for ( Int32 i = 0; i < 5; i++ ) { + if( VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_TEXTURE0 + i ) ) { + glClientActiveTextureARB( GL_TEXTURE0_ARB ); + glEnableClientState( GL_TEXTURE_COORD_ARRAY ); + + glTexCoordPointer( eeVertexElements[ VERTEX_FLAG_TEXTURE0 + i ], GL_FLOAT, sizeof(float) * eeVertexElements[ VERTEX_FLAG_TEXTURE0 + i ], &mVertexArray[ VERTEX_FLAG_TEXTURE0 + i ][0] ); + } else { + //glClientActiveTextureARB( GL_TEXTURE0_ARB ); + glDisableClientState( GL_TEXTURE_COORD_ARRAY ); + glDisable( GL_TEXTURE_2D ); + } + } +} + +}} diff --git a/src/graphics/cvertexbufferogl.hpp b/src/graphics/cvertexbufferogl.hpp new file mode 100644 index 000000000..4b67f418d --- /dev/null +++ b/src/graphics/cvertexbufferogl.hpp @@ -0,0 +1,27 @@ +#ifndef EE_GRAPHICSCVERTEXBUFFEROGL_HPP +#define EE_GRAPHICSCVERTEXBUFFEROGL_HPP + +#include "cvertexbuffer.hpp" + +namespace EE { namespace Graphics { + +class cVertexBufferOGL : public cVertexBuffer { + public: + cVertexBufferOGL( const Uint32& VertexFlags = VERTEX_FLAGS_DEFAULT, EE_DRAW_TYPE DrawType = EE_DT_QUADS, const Int32& ReserveVertexSize = 0, const Int32& ReserveIndexSize = 0, EE_VBO_USAGE_TYPE UsageType = VBO_USAGE_TYPE_STATIC ); + + virtual ~cVertexBufferOGL(); + + void Bind(); + + void Draw(); + + bool Compile(); + protected: + void SetVertexStates(); + +}; + +}} + +#endif + diff --git a/src/graphics/cvertexbuffervbo.cpp b/src/graphics/cvertexbuffervbo.cpp new file mode 100644 index 000000000..c8ad0f495 --- /dev/null +++ b/src/graphics/cvertexbuffervbo.cpp @@ -0,0 +1,135 @@ +#include "cvertexbuffervbo.hpp" + +namespace EE { namespace Graphics { + +cVertexBufferVBO::cVertexBufferVBO( const Uint32& VertexFlags, EE_DRAW_TYPE DrawType, const Int32& ReserveVertexSize, const Int32& ReserveIndexSize, EE_VBO_USAGE_TYPE UsageType ) : + cVertexBuffer( VertexFlags, DrawType, ReserveVertexSize, ReserveIndexSize, UsageType ), + mCompiled( false ), + mElementHandle( 0 ) +{ +} + +cVertexBufferVBO::~cVertexBufferVBO() { + for( Int32 i = 0; i < VERTEX_FLAGS_COUNT; i++ ) { + if( VERTEX_FLAG_QUERY( mVertexFlags, i ) ) { + glDeleteBuffers( 1,(GLuint *)&mArrayHandle[ i ] ); + } + } + + if( VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_USE_INDICES ) ) { + glDeleteBuffers( 1, (GLuint *)&mElementHandle ); + } +} + +void cVertexBufferVBO::Bind() { + if ( !mCompiled ) { + Compile(); + + if ( !mCompiled ) + return; + } + + SetVertexStates(); +} + +bool cVertexBufferVBO::Compile() { + if( mCompiled ) + return false; + + GLenum usageType = GL_STATIC_DRAW_ARB; + if( mUsageType== VBO_USAGE_TYPE_DYNAMIC ) usageType = GL_DYNAMIC_DRAW_ARB; + else if( mUsageType== VBO_USAGE_TYPE_STREAM ) usageType = GL_STREAM_DRAW_ARB; + + //Create the VBO vertex arrays + for( Int32 i = 0; i < VERTEX_FLAGS_COUNT; i++ ) { + if( VERTEX_FLAG_QUERY( mVertexFlags, i ) ) { + glGenBuffersARB( 1,(GLuint *)&mArrayHandle[ i ] ); + + glBindBufferARB( GL_ARRAY_BUFFER_ARB, mArrayHandle[i] ); + + if ( mArrayHandle[i] ) { + if ( i != VERTEX_FLAG_COLOR ) + glBufferDataARB( GL_ARRAY_BUFFER_ARB, mVertexArray[i].size() * sizeof(eeFloat), &( mVertexArray[i][0] ), usageType ); + else + glBufferDataARB( GL_ARRAY_BUFFER_ARB, mColorArray.size(), &mColorArray[0], usageType ); + } else { + return false; + } + + glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 ); + } + } + + //Create the VBO index array + if( VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_USE_INDICES ) ) { + glGenBuffersARB( 1, (GLuint *)&mElementHandle ); + + glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, mElementHandle ); + + glBufferDataARB( GL_ELEMENT_ARRAY_BUFFER_ARB, GetIndexCount() * sizeof(Uint32), &mIndexArray[0], usageType ); + + glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, 0 ); + } + + mCompiled = true; + + return true; +} + +void cVertexBufferVBO::Draw() { + if ( !mCompiled ) + return; + + if( VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_USE_INDICES ) ) { + Int32 lSize = mElemDraw; + + if( mElemDraw < 0 ) + lSize = GetIndexCount(); + + glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, mElementHandle ); + + glDrawElements( mDrawType, lSize, GL_UNSIGNED_INT, (char*)NULL ); + + glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, 0 ); + } else { + glDrawArrays( mDrawType, 0, GetVertexCount() ); + } +} + +void cVertexBufferVBO::SetVertexStates() { + /// POSITION + if( VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_POSITION ) ) { + glEnableClientState( GL_VERTEX_ARRAY ); + glBindBufferARB( GL_ARRAY_BUFFER_ARB, mArrayHandle[ VERTEX_FLAG_POSITION ] ); + glVertexPointer( eeVertexElements[ VERTEX_FLAG_POSITION ], GL_FLOAT, 0, (char*)NULL ); + } else { + glDisableClientState( GL_VERTEX_ARRAY ); + } + + /// COLOR + if( VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_COLOR ) ) { + glEnableClientState( GL_COLOR_ARRAY ); + glBindBufferARB( GL_ARRAY_BUFFER_ARB, mArrayHandle[ VERTEX_FLAG_COLOR ] ); + glColorPointer( eeVertexElements[ VERTEX_FLAG_COLOR ], GL_UNSIGNED_BYTE, 0, (char*)NULL ); + } else { + glDisableClientState( GL_COLOR_ARRAY ); + } + + /// TEXTURES + for ( Int32 i = 0; i < 5; i++ ) { + if( VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_TEXTURE0 + i ) ) { + glClientActiveTextureARB( GL_TEXTURE0_ARB ); + glEnableClientState( GL_TEXTURE_COORD_ARRAY ); + glBindBufferARB( GL_ARRAY_BUFFER_ARB, mArrayHandle[ VERTEX_FLAG_TEXTURE0 + i ] ); + glTexCoordPointer( eeVertexElements[ VERTEX_FLAG_TEXTURE0 + i ], GL_FLOAT, 0, (char*)NULL ); + } else { + //glClientActiveTextureARB( GL_TEXTURE0_ARB ); + glDisableClientState( GL_TEXTURE_COORD_ARRAY ); + glDisable( GL_TEXTURE_2D ); + } + } + + glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 ); +} + +}} diff --git a/src/graphics/cvertexbuffervbo.hpp b/src/graphics/cvertexbuffervbo.hpp new file mode 100644 index 000000000..9075298cc --- /dev/null +++ b/src/graphics/cvertexbuffervbo.hpp @@ -0,0 +1,31 @@ +#ifndef EE_GRAPHICSCVERTEXBUFFERVBO_HPP +#define EE_GRAPHICSCVERTEXBUFFERVBO_HPP + +#include "cvertexbuffer.hpp" + +namespace EE { namespace Graphics { + +class cVertexBufferVBO : public cVertexBuffer { + public: + cVertexBufferVBO( const Uint32& VertexFlags = VERTEX_FLAGS_DEFAULT, EE_DRAW_TYPE DrawType = EE_DT_QUADS, const Int32& ReserveVertexSize = 0, const Int32& ReserveIndexSize = 0, EE_VBO_USAGE_TYPE UsageType = VBO_USAGE_TYPE_STATIC ); + + virtual ~cVertexBufferVBO(); + + void Bind(); + + void Draw(); + + bool Compile(); + protected: + void SetVertexStates(); + + bool mCompiled; + + Uint32 mElementHandle; + + Uint32 mArrayHandle[ VERTEX_FLAGS_COUNT ]; +}; + +}} + +#endif diff --git a/src/graphics/renders.hpp b/src/graphics/renders.hpp index 6c1b5cbb9..a25e9000e 100755 --- a/src/graphics/renders.hpp +++ b/src/graphics/renders.hpp @@ -5,53 +5,53 @@ namespace EE { namespace Graphics { /** @enum EE_FILLMODE Defines the fill mode for the primitives. */ enum EE_FILLMODE { - DRAW_LINE, //!< Draw only lines - DRAW_FILL //!< Draw filled objects + DRAW_LINE, //!< Draw only lines + DRAW_FILL //!< Draw filled objects }; /** @enum EE_TEX_FILTER Defines the texture filter used. */ enum EE_TEX_FILTER { - TEX_LINEAR, //!< Linear filtering (Smoothed Zoom) - TEX_NEAREST //!< No filtering (Pixeled Zoom) + TEX_LINEAR, //!< Linear filtering (Smoothed Zoom) + TEX_NEAREST //!< No filtering (Pixeled Zoom) }; /** @enum EE_RENDERALPHAS Defines the Blend Function to use */ enum EE_RENDERALPHAS { - ALPHA_NONE, //!< Disable the GL_BLEND - ALPHA_NORMAL, //!< glBlendFunc(GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA); - ALPHA_BLENDONE, //!< glBlendFunc(GL_SRC_ALPHA , GL_ONE); - ALPHA_BLENDTWO, //!< glBlendFunc(GL_SRC_ALPHA , GL_SRC_ALPHA); \n glBlendFunc(GL_DST_ALPHA , GL_ONE); - ALPHA_BLENDTHREE, //!< glBlendFunc(GL_SRC_ALPHA , GL_ONE); \n glBlendFunc(GL_DST_ALPHA , GL_SRC_ALPHA); - ALPHA_ALPHACHANNELS, //!< glBlendFunc(GL_SRC_ALPHA , GL_SRC_ALPHA); - ALPHA_DESTALPHA, //!< glBlendFunc(GL_SRC_ALPHA , GL_DST_ALPHA); - ALPHA_MULTIPLY //!< glBlendFunc(GL_DST_COLOR,GL_ZERO); + ALPHA_NONE, //!< Disable the GL_BLEND + ALPHA_NORMAL, //!< glBlendFunc(GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA); + ALPHA_BLENDONE, //!< glBlendFunc(GL_SRC_ALPHA , GL_ONE); + ALPHA_BLENDTWO, //!< glBlendFunc(GL_SRC_ALPHA , GL_SRC_ALPHA); \n glBlendFunc(GL_DST_ALPHA , GL_ONE); + ALPHA_BLENDTHREE, //!< glBlendFunc(GL_SRC_ALPHA , GL_ONE); \n glBlendFunc(GL_DST_ALPHA , GL_SRC_ALPHA); + ALPHA_ALPHACHANNELS, //!< glBlendFunc(GL_SRC_ALPHA , GL_SRC_ALPHA); + ALPHA_DESTALPHA, //!< glBlendFunc(GL_SRC_ALPHA , GL_DST_ALPHA); + ALPHA_MULTIPLY //!< glBlendFunc(GL_DST_COLOR,GL_ZERO); }; /** @enum EE_RENDERTYPE Defines the method to use to render a texture. */ enum EE_RENDERTYPE { - RN_NORMAL = 0, //!< Render the texture without any change - RN_MIRROR = 1, //!< Render the texture mirrored - RN_FLIP = 2, //!< Render the texture fliped - RN_FLIPMIRROR = 3, //!< Render the texture fliped and mirrored - RN_ISOMETRIC = 4, //!< Render the texture as an isometric tile - RN_ISOMETRICVERTICAL = 5, //!< Render the texture as an isometric vertical tile - RN_ISOMETRICVERTICALNEGATIVE = 6 //!< Render the texture as an isometric vectical tile mirrored + RN_NORMAL = 0, //!< Render the texture without any change + RN_MIRROR = 1, //!< Render the texture mirrored + RN_FLIP = 2, //!< Render the texture fliped + RN_FLIPMIRROR = 3, //!< Render the texture fliped and mirrored + RN_ISOMETRIC = 4, //!< Render the texture as an isometric tile + RN_ISOMETRICVERTICAL = 5, //!< Render the texture as an isometric vertical tile + RN_ISOMETRICVERTICALNEGATIVE = 6 //!< Render the texture as an isometric vectical tile mirrored }; -/** @enum EE_SAVEFORMAT Defines the format to save a texture. */ -enum EE_SAVETYPE { - EE_SAVE_TYPE_TGA = 0, - EE_SAVE_TYPE_BMP = 1, - EE_SAVE_TYPE_PNG = 2, - EE_SAVE_TYPE_DDS = 3 +/** @enum EE_SAVE_TYPE Defines the format to save a texture. */ +enum EE_SAVE_TYPE { + EE_SAVE_TYPE_TGA = 0, + EE_SAVE_TYPE_BMP = 1, + EE_SAVE_TYPE_PNG = 2, + EE_SAVE_TYPE_DDS = 3 }; /** @enum EE_TTF_FONTSTYLE Set the TTF Font style. */ enum EE_TTF_FONTSTYLE { - EE_TTF_STYLE_NORMAL = 0, - EE_TTF_STYLE_BOLD = 1, - EE_TTF_STYLE_ITALIC = 2, - EE_TTF_STYLE_UNDERLINE = 4 + EE_TTF_STYLE_NORMAL = 0, + EE_TTF_STYLE_BOLD = 1, + EE_TTF_STYLE_ITALIC = 2, + EE_TTF_STYLE_UNDERLINE = 4 }; /** @enum EE_CLAMP_MODE Set the clamp mode of the texture. */ @@ -60,18 +60,18 @@ enum EE_CLAMP_MODE { EE_CLAMP_REPEAT }; -/** @enum EE_BATCH_RENDERER_METHOD The batch renderer, rendering methods */ -enum EE_BATCH_RENDER_METHOD { - EE_GL_POINTS = 0x0000, - EE_GL_LINES = 0x0001, - EE_GL_LINE_LOOP = 0x0002, - EE_GL_LINE_STRIP = 0x0003, - EE_GL_TRIANGLES = 0x0004, - EE_GL_TRIANGLE_STRIP = 0x0005, - EE_GL_TRIANGLE_FAN = 0x0006, - EE_GL_QUADS = 0x0007, - EE_GL_QUAD_STRIP = 0x0008, - EE_GL_POLYGON = 0x0009 +/** @enum EE_DRAW_TYPE The batch renderer, rendering methods */ +enum EE_DRAW_TYPE { + EE_DT_POINTS = 0x0000, + EE_DT_LINES = 0x0001, + EE_DT_LINE_LOOP = 0x0002, + EE_DT_LINE_STRIP = 0x0003, + EE_DT_TRIANGLES = 0x0004, + EE_DT_TRIANGLE_STRIP = 0x0005, + EE_DT_TRIANGLE_FAN = 0x0006, + EE_DT_QUADS = 0x0007, + EE_DT_QUAD_STRIP = 0x0008, + EE_DT_POLYGON = 0x0009 }; } diff --git a/src/graphics/vbohelper.hpp b/src/graphics/vbohelper.hpp new file mode 100644 index 000000000..8ec61495a --- /dev/null +++ b/src/graphics/vbohelper.hpp @@ -0,0 +1,45 @@ +#ifndef EE_GRAPHICS_VBOHELPER_HPP +#define EE_GRAPHICS_VBOHELPER_HPP + +namespace EE { namespace Graphics { + +enum EE_VBO_USAGE_TYPE +{ + VBO_USAGE_TYPE_STATIC, + VBO_USAGE_TYPE_DYNAMIC, + VBO_USAGE_TYPE_STREAM, + VBO_USAGE_TYPE_COUNT +}; + +#define VERTEX_FLAG_POSITION ( 0 ) +#define VERTEX_FLAG_TEXTURE0 ( 1 ) +#define VERTEX_FLAG_TEXTURE1 ( 2 ) +#define VERTEX_FLAG_TEXTURE2 ( 3 ) +#define VERTEX_FLAG_TEXTURE3 ( 4 ) +#define VERTEX_FLAG_TEXTURE4 ( 5 ) +#define VERTEX_FLAG_COLOR ( 6 ) + +#define VERTEX_FLAGS_COUNT_ARR ( 6 ) +#define VERTEX_FLAGS_COUNT ( 7 ) + +#define VERTEX_FLAG_USE_INDICES ( 7 ) + +const int eeVertexElements[] = { + 2, //Position + 2, //Texture0 + 2, //Texture1 + 2, //Texture2 + 2, //Texture3 + 2, //Texture4 + 4 //Color0 + }; + +#define VERTEX_FLAG_GET(X) ( 1 << (X) ) +#define VERTEX_FLAG_SET(F, X) if ( !( F & VERTEX_FLAG_GET( X ) ) ) F |= VERTEX_FLAG_GET( X ); +#define VERTEX_FLAG_QUERY(F, X) ( F & VERTEX_FLAG_GET(X) ) + +#define VERTEX_FLAGS_DEFAULT ( VERTEX_FLAG_GET( VERTEX_FLAG_POSITION ) | VERTEX_FLAG_GET( VERTEX_FLAG_TEXTURE0 ) | VERTEX_FLAG_GET( VERTEX_FLAG_COLOR ) ) + +}} + +#endif diff --git a/src/helper/SOIL/SOIL.c b/src/helper/SOIL/SOIL.c index 367660d14..607516a90 100755 --- a/src/helper/SOIL/SOIL.c +++ b/src/helper/SOIL/SOIL.c @@ -1535,8 +1535,9 @@ void ( unsigned char *img_data ) -{ - free( (void*)img_data ); +{ + if ( img_data ) + free( (void*)img_data ); } const char* diff --git a/src/system/clog.hpp b/src/system/clog.hpp index 1553d395b..8726937bf 100755 --- a/src/system/clog.hpp +++ b/src/system/clog.hpp @@ -10,12 +10,16 @@ class EE_API cLog : public tSingleton { friend class tSingleton; public: void Save(const std::string& filepath = "./"); + void Write(const std::string& Text, const bool& newLine = true); + void Writef( const char* format, ... ); + std::string Buffer() const { return mData; } + + ~cLog(); protected: cLog(); - ~cLog(); private: std::string mData, mFilePath; bool mSave; diff --git a/src/system/cpak.cpp b/src/system/cpak.cpp index ca51e7d67..2b34b94a0 100755 --- a/src/system/cpak.cpp +++ b/src/system/cpak.cpp @@ -150,7 +150,7 @@ bool cPak::ExtractFileToMemory( const std::string& path, Uint8** data, Uint32* d if ( Pos != -1 ) { *dataSize = pakFiles[Pos].file_length; - *data = new Uint8[ (*dataSize) ]; + *data = eeNew( Uint8, (*dataSize) ); myPak.fs.seekg( pakFiles[Pos].file_position, std::ios::beg ); myPak.fs.read( reinterpret_cast ( *data ), pakFiles[Pos].file_length ); diff --git a/src/system/czip.cpp b/src/system/czip.cpp index 598bbd08b..f5133f96d 100644 --- a/src/system/czip.cpp +++ b/src/system/czip.cpp @@ -189,7 +189,7 @@ bool cZip::ExtractFileToMemory( const std::string& path, Uint8** data, Uint32* d if ( NULL != zf ) { *dataSize = zf->bytes_left; - *data = new Uint8[ (*dataSize) ]; + *data = eeNew( Uint8, (*dataSize) ); Result = zip_fread( zf, reinterpret_cast (&data[0]), zf->bytes_left ); diff --git a/src/system/singleton.hpp b/src/system/singleton.hpp index e54813248..32946abd1 100755 --- a/src/system/singleton.hpp +++ b/src/system/singleton.hpp @@ -1,5 +1,7 @@ #ifndef EE_SYSTEMSINGLETON_H #define EE_SYSTEMSINGLETON_H + +#include "../base.hpp" namespace EE { namespace System { @@ -12,7 +14,7 @@ class tSingleton { /** Get the singleton pointer */ static T* CreateSingleton() { if (ms_singleton == 0) - ms_singleton = new T; + ms_singleton = eeNew( T, () ); return ms_singleton; } @@ -30,7 +32,7 @@ class tSingleton { /** Destroy the singleton instance */ static void DestroySingleton() { if( ms_singleton != 0 ) { - delete ms_singleton; + eeDelete( ms_singleton ); ms_singleton = 0; } } diff --git a/src/test/ee.cpp b/src/test/ee.cpp index 0818b586c..b5fd462c2 100644 --- a/src/test/ee.cpp +++ b/src/test/ee.cpp @@ -1,7 +1,7 @@ #include "../ee.h" /** -@TODO Create a Vertex Buffer Object class ( with and without GL_ARB_vertex_buffer_object ). +@TODO Add a memory manager ( and a STL Allocator implemented in all the engine ). @TODO Support multitexturing. @TODO Create a basic UI system ( add basic controls, add skinning support ). @TODO Add some Surface Grid class, to create special effects ( waved texture, and stuff like that ). @@ -72,7 +72,7 @@ class cEETest : private cThread { void LoadTextures(); void CmdSetPartsNum ( const std::vector < std::wstring >& params ); - std::vector PS; + std::vector > PS; cTimeElapsed cElapsed; eeFloat PSElapsed; @@ -192,6 +192,7 @@ class cEETest : private cThread { cSprite mBlindy; cFrameBuffer * mFB; + cVertexBuffer * mVBO; }; @@ -289,6 +290,18 @@ void cEETest::Init() { if ( NULL != mFB ) mFB->ClearColor( eeColorAf( 0, 0, 0, 0.5f ) ); + + eePolygon2f Poly = CreateRoundedPolygon( 0.f, 0.f, 250.f, 50.f ); + + mVBO = cVertexBuffer::Create( VERTEX_FLAG_GET( VERTEX_FLAG_POSITION ) | VERTEX_FLAG_GET( VERTEX_FLAG_COLOR ), EE_DT_POLYGON ); + + for ( Uint32 i = 0; i < Poly.Size(); i++ ) { + mVBO->AddVertex( Poly[i] ); + mVBO->AddColor( eeColorA( 100 + i, 255 - i, 150 + i, 200 ) ); + } + + mVBO->Compile(); + Launch(); } else { std::cout << "Failed to start EE++" << std::endl; @@ -298,9 +311,9 @@ void cEETest::Init() { } void cEETest::LoadFonts() { - mFontLoader.Add( new cTextureFontLoader( "conchars", new cTextureLoader( &PAK, "conchars.png", false, eeRGB(0,0,0) ), (eeUint)32 ) ); - mFontLoader.Add( new cTextureFontLoader( "ProggySquareSZ", new cTextureLoader( &PAK, "ProggySquareSZ.png" ), &PAK, "ProggySquareSZ.dat" ) ); - mFontLoader.Add( new cTTFFontLoader( "arial", &PAK, "arial.ttf", 12, EE_TTF_STYLE_NORMAL, false, 512, eeColor(255,255,255), 1, eeColor(0,0,0) ) ); + mFontLoader.Add( eeNew( cTextureFontLoader, ( "conchars", eeNew( cTextureLoader, ( &PAK, "conchars.png", false, eeRGB(0,0,0) ) ), (eeUint)32 ) ) ); + mFontLoader.Add( eeNew( cTextureFontLoader, ( "ProggySquareSZ", eeNew( cTextureLoader, ( &PAK, "ProggySquareSZ.png" ) ), &PAK, "ProggySquareSZ.dat" ) ) ); + mFontLoader.Add( eeNew( cTTFFontLoader, ( "arial", &PAK, "arial.ttf", 12, EE_TTF_STYLE_NORMAL, false, 512, eeColor(255,255,255), 1, eeColor(0,0,0) ) ) ); mFontLoader.Load( boost::bind( &cEETest::OnFontLoaded, this, _1 ) ); } @@ -326,7 +339,7 @@ void cEETest::CreateShaders() { if ( mUseShaders ) { mBlurFactor = 0.01f; - mShaderProgram = new cShaderProgram( &PAK, "shader/blur.vert", "shader/blur.frag" ); + mShaderProgram = eeNew( cShaderProgram, ( &PAK, "shader/blur.vert", "shader/blur.frag" ) ); } } @@ -339,7 +352,7 @@ void cEETest::CreateUI() { Params.Border.Color( 0xFF979797 ); //Params.Background.Corners(5); Params.Background.Colors( eeColorA( 0x66FAFAFA ), eeColorA( 0xCCFAFAFA ), eeColorA( 0xCCFAFAFA ), eeColorA( 0x66FAFAFA ) ); - cUIControlAnim * C = new cUITest( Params ); + cUIControlAnim * C = eeNew( cUITest, ( Params ) ); C->Visible( true ); C->Enabled( true ); C->Pos( 320, 240 ); @@ -351,7 +364,7 @@ void cEETest::CreateUI() { Params.Background.Colors( eeColorA( 0x7700FF00 ), eeColorA( 0x7700CC00 ), eeColorA( 0x7700CC00 ), eeColorA( 0x7700FF00 ) ); Params.Parent( C ); Params.Size = eeSize( 50, 50 ); - cUITest * Child = new cUITest( Params ); + cUITest * Child = eeNew( cUITest, ( Params ) ); Child->Pos( 25, 50 ); Child->Visible( true ); Child->Enabled( true ); @@ -360,7 +373,7 @@ void cEETest::CreateUI() { Params.Background.Colors( eeColorA( 0x77FFFF00 ), eeColorA( 0x77CCCC00 ), eeColorA( 0x77CCCC00 ), eeColorA( 0x77FFFF00 ) ); Params.Parent( Child ); Params.Size = eeSize( 25, 25 ); - cUITest * Child2 = new cUITest( Params ); + cUITest * Child2 = eeNew( cUITest, ( Params ) ); Child2->Pos( 15, 15 ); Child2->Visible( true ); Child2->Enabled( true ); @@ -372,7 +385,7 @@ void cEETest::CreateUI() { GfxParams.Flags |= UI_CLIP_ENABLE; GfxParams.Size = eeSize( 64, 64 ); GfxParams.Shape = cGlobalShapeGroup::instance()->Add( TN[2] ); - cUIGfx * Gfx = new cUIGfx( GfxParams ); + cUIGfx * Gfx = eeNew( cUIGfx, ( GfxParams ) ); Gfx->Angle( 45.f ); Gfx->Visible( true ); Gfx->Enabled( true ); @@ -386,7 +399,7 @@ void cEETest::CreateUI() { TextParams.Size = eeSize( 320, 240 ); TextParams.Flags = UI_VALIGN_TOP | UI_HALIGN_RIGHT; TextParams.Font = TTF; - cUITextBox * Text = new cUITextBox( TextParams ); + cUITextBox * Text = eeNew( cUITextBox, ( TextParams ) ); Text->Visible( true ); Text->Enabled( false ); Text->Text( L"Turn around\nJust Turn Around\nAround!" ); @@ -401,7 +414,7 @@ void cEETest::CreateUI() { InputParams.Flags = UI_VALIGN_CENTER | UI_HALIGN_LEFT | UI_FILL_BACKGROUND | UI_CLIP_ENABLE | UI_BORDER; InputParams.Font = TTF; InputParams.SupportNewLine = false; - cUITextInput * Input = new cUITextInput( InputParams ); + cUITextInput * Input = eeNew( cUITextInput, ( InputParams ) ); Input->Visible( true ); Input->Enabled( true ); @@ -443,11 +456,11 @@ void cEETest::LoadTextures() { std::string name( files[i] ); if ( "jpg" == FileExtension( name ) ) { - mResLoad.Add( new cTextureLoader( &PakTest, name ) ); + mResLoad.Add( eeNew( cTextureLoader, ( &PakTest, name ) ) ); } } - mResLoad.Add( new cSoundLoader( &SndMng, "mysound", &PAK, "sound.ogg" ) ); + mResLoad.Add( eeNew( cSoundLoader, ( &SndMng, "mysound", &PAK, "sound.ogg" ) ) ); mResLoad.Load( boost::bind( &cEETest::OnTextureLoaded, this, _1 ) ); @@ -541,7 +554,7 @@ void cEETest::LoadTextures() { CL2.AddFrame(TN[0], 96, 96); CL2.Color( eeRGBA( 255, 255, 255, 255 ) ); - mTGL = new cTextureGroupLoader( MyPath + "data/bnb/bnb.etg" ); + mTGL = eeNew( cTextureGroupLoader, ( MyPath + "data/bnb/bnb.etg" ) ); mBlindy.AddFramesByPattern( "rn" ); mBlindy.UpdatePos( 320.f, 0.f ); @@ -878,6 +891,10 @@ void cEETest::Render() { mBlindy.UpdatePos( 128-16, 128-16 ); mBlindy.Draw(); + mVBO->Bind(); + mVBO->Draw(); + mVBO->Unbind(); + mFB->Unbind(); if ( NULL != mFB->GetTexture() ) @@ -1139,6 +1156,7 @@ void cEETest::End() { eeSAFE_DELETE( mTGL ); eeSAFE_DELETE( mFB ); + eeSAFE_DELETE( mVBO ); cEngine::DestroySingleton(); } @@ -1170,9 +1188,9 @@ int main (int argc, char * argv []) { /* std::string Path( "/home/downloads/files/temp/bnb/allin/" ); */ /* - cTextureGroupLoader * tgl = new cTextureGroupLoader(); + cTextureGroupLoader * tgl = eeNew( cTextureGroupLoader, () ); tgl->UpdateTextureAtlas( AppPath() + "data/bnb/bnb.etg", Path ); - delete tgl; + eeDelete( tgl ); */ /* cTexturePacker tp( 512, 512 ); @@ -1186,8 +1204,13 @@ int main (int argc, char * argv []) { tp.Save( AppPath() + "data/bnb/bnb.png", EE_SAVE_TYPE_PNG ); */ - cEETest Test; - Test.Process(); + cEETest * Test = eeNew( cEETest, () ); + + Test->Process(); + + eeDelete( Test ); + + EE::MemoryManager::LogResults(); return 0; } diff --git a/src/ui/cuicontrol.cpp b/src/ui/cuicontrol.cpp index 7ab336c9c..4c44f8257 100644 --- a/src/ui/cuicontrol.cpp +++ b/src/ui/cuicontrol.cpp @@ -29,7 +29,7 @@ cUIControl::cUIControl( const CreateParams& Params ) : cUIControl::~cUIControl() { while( NULL != mChild ) - delete mChild; + eeDelete( mChild ); if ( NULL != mParentCtrl ) mParentCtrl->ChildRemove( this ); @@ -431,7 +431,7 @@ void cUIControl::CheckClose() { while( NULL != ChildLoop ) { if ( ChildLoop->ControlFlags() & UI_CTRL_FLAG_CLOSE ) { - delete ChildLoop; + eeDelete( ChildLoop ); ChildLoop = mChild; @@ -515,7 +515,7 @@ void cUIControl::MatrixUnset() { void cUIControl::ChildDeleteAll() { while( NULL != mChild ) - delete mChild; + eeDelete( mChild ); } void cUIControl::ChildAdd( cUIControl * ChildCtrl ) { diff --git a/src/ui/cuicontrol.hpp b/src/ui/cuicontrol.hpp index 3f64e056d..8b10b7e48 100644 --- a/src/ui/cuicontrol.hpp +++ b/src/ui/cuicontrol.hpp @@ -193,6 +193,8 @@ class EE_API cUIControl { cUIBackground * Background(); cUIBorder * Border(); + + virtual ~cUIControl(); protected: friend class cUIManager; friend class cUIDragable; @@ -223,8 +225,6 @@ class EE_API cUIControl { std::map< Uint32, std::map > mEvents; Uint32 mNumCallBacks; - virtual ~cUIControl(); - virtual void OnVisibleChange(); virtual void OnEnabledChange(); diff --git a/src/ui/cuicontrolanim.cpp b/src/ui/cuicontrolanim.cpp index d14955e7c..113810a54 100644 --- a/src/ui/cuicontrolanim.cpp +++ b/src/ui/cuicontrolanim.cpp @@ -140,7 +140,7 @@ bool cUIControlAnim::Animating() { void cUIControlAnim::StartAlphaAnim( const eeFloat& From, const eeFloat& To, const eeFloat& TotalTime, cInterpolation::OnPathEndCallback PathEndCallback ) { if ( NULL == mAlphaAnim ) - mAlphaAnim = new cInterpolation(); + mAlphaAnim = eeNew( cInterpolation, () ); mAlphaAnim->ClearWaypoints(); mAlphaAnim->AddWaypoint( From ); @@ -153,7 +153,7 @@ void cUIControlAnim::StartAlphaAnim( const eeFloat& From, const eeFloat& To, con void cUIControlAnim::StartScaleAnim( const eeFloat& From, const eeFloat& To, const eeFloat& TotalTime, cInterpolation::OnPathEndCallback PathEndCallback ) { if ( NULL == mScaleAnim ) - mScaleAnim = new cInterpolation(); + mScaleAnim = eeNew( cInterpolation, () ); mScaleAnim->ClearWaypoints(); mScaleAnim->AddWaypoint( From ); @@ -166,7 +166,7 @@ void cUIControlAnim::StartScaleAnim( const eeFloat& From, const eeFloat& To, con void cUIControlAnim::StartMovement( const eeVector2i& From, const eeVector2i& To, const eeFloat& TotalTime, cWaypoints::OnPathEndCallback PathEndCallback ) { if ( NULL == mMoveAnim ) - mMoveAnim = new cWaypoints(); + mMoveAnim = eeNew( cWaypoints, () ); mMoveAnim->ClearWaypoints(); mMoveAnim->AddWaypoint( eeVector2f( (eeFloat)From.x, (eeFloat)From.y ) ); @@ -179,7 +179,7 @@ void cUIControlAnim::StartMovement( const eeVector2i& From, const eeVector2i& To void cUIControlAnim::StartRotation( const eeFloat& From, const eeFloat& To, const eeFloat& TotalTime, cInterpolation::OnPathEndCallback PathEndCallback ) { if ( NULL == mAngleAnim ) - mAngleAnim = new cInterpolation(); + mAngleAnim = eeNew( cInterpolation, () ); mAngleAnim->ClearWaypoints(); mAngleAnim->AddWaypoint( From ); @@ -264,28 +264,28 @@ void cUIControlAnim::UpdateQuad() { cInterpolation * cUIControlAnim::AngleInterpolation() { if ( NULL == mAngleAnim ) - mAngleAnim = new cInterpolation(); + mAngleAnim = eeNew( cInterpolation, () ); return mAngleAnim; } cInterpolation * cUIControlAnim::ScaleInterpolation() { if ( NULL == mScaleAnim ) - mScaleAnim = new cInterpolation(); + mScaleAnim = eeNew( cInterpolation, () ); return mScaleAnim; } cInterpolation * cUIControlAnim::AlphaInterpolation() { if ( NULL == mAlphaAnim ) - mAlphaAnim = new cInterpolation(); + mAlphaAnim = eeNew( cInterpolation, () ); return mAlphaAnim; } cWaypoints * cUIControlAnim::MovementInterpolation() { if ( NULL == mMoveAnim ) - mMoveAnim = new cWaypoints(); + mMoveAnim = eeNew( cWaypoints, () ); return mMoveAnim; } diff --git a/src/ui/cuimanager.cpp b/src/ui/cuimanager.cpp index 72ef4b17a..93a9ba70e 100644 --- a/src/ui/cuimanager.cpp +++ b/src/ui/cuimanager.cpp @@ -24,7 +24,7 @@ void cUIManager::Init() { Shutdown(); mInit = true; - mControl = new cUIControlAnim( cUIControl::CreateParams( NULL, eeVector2i( 0, 0 ), eeSize( cEngine::instance()->GetWidth(), cEngine::instance()->GetHeight() ) ) ); + mControl = eeNew( cUIControlAnim, ( cUIControl::CreateParams( NULL, eeVector2i( 0, 0 ), eeSize( cEngine::instance()->GetWidth(), cEngine::instance()->GetHeight() ) ) ) ); mControl->Visible( true ); mControl->Enabled( true ); diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index 47e880245..da136d712 100755 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -421,13 +421,38 @@ std::string SaveTypeToExtension( const Uint32& Format ) { } void DirPathAddSlashAtEnd( std::string& path ) { - if ( path[ path.size() - 1 ] != '/' && path[ path.size() - 1 ] != '\\' ) { + if ( path[ path.size() - 1 ] != '/' && path[ path.size() - 1 ] != '\\' ) + path += GetOSlash(); +} + +std::string GetOSlash() { #if EE_PLATFORM == EE_PLATFORM_WIN32 - path += '\\'; + return std::string( "\\" ); #else - path += '/'; + return std::string( "/" ); #endif +} + +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 ); } }} diff --git a/src/utils/utils.hpp b/src/utils/utils.hpp index 4472ec596..bd9ca1f2f 100755 --- a/src/utils/utils.hpp +++ b/src/utils/utils.hpp @@ -88,7 +88,15 @@ namespace EE { namespace Utils { std::string EE_API SaveTypeToExtension( const Uint32& Format ); /** If the directory path not end with a slash, it will add it. */ - void DirPathAddSlashAtEnd( std::string& path ); + void EE_API DirPathAddSlashAtEnd( 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 SizeToString( const Uint32& MemSize ); } } diff --git a/src/window/cengine.cpp b/src/window/cengine.cpp index aff55e527..dfd4c6ded 100755 --- a/src/window/cengine.cpp +++ b/src/window/cengine.cpp @@ -7,6 +7,7 @@ #include "../graphics/cshaderprogrammanager.hpp" #include "../graphics/cshapegroupmanager.hpp" #include "../ui/cuimanager.hpp" +#include "../audio/caudiolistener.hpp" using namespace EE::Graphics; @@ -102,6 +103,8 @@ cEngine::~cEngine() { cInput::DestroySingleton(); + Audio::cAudioListener::DestroySingleton(); + cLog::DestroySingleton(); SDL_Quit(); @@ -446,7 +449,7 @@ void cEngine::SetFrameRateLimit(const Uint32& FrameRateLimit) { mFrames.FPS.Limit = (eeFloat)FrameRateLimit; } -bool cEngine::TakeScreenshot( std::string filepath, const EE_SAVETYPE& Format ) { +bool cEngine::TakeScreenshot( std::string filepath, const EE_SAVE_TYPE& Format ) { bool CreateNewFile = false; std::string File, Ext; @@ -469,12 +472,7 @@ bool cEngine::TakeScreenshot( std::string filepath, const EE_SAVETYPE& Format ) if ( !IsDirectory( filepath ) ) MakeDir( filepath ); - switch ( Format ) { - case EE_SAVE_TYPE_TGA: Ext = ".tga"; break; - case EE_SAVE_TYPE_BMP: Ext = ".bmp"; break; - case EE_SAVE_TYPE_PNG: Ext = ".png"; break; - case EE_SAVE_TYPE_DDS: Ext = ".dds"; break; - } + Ext = "." + SaveTypeToExtension( Format ); while ( !find && FileNum < 10000 ) { TmpPath = StrFormated( "%s%05d%s", filepath.c_str(), FileNum, Ext.c_str() ); diff --git a/src/window/cengine.hpp b/src/window/cengine.hpp index c93c8fc0d..f44644427 100755 --- a/src/window/cengine.hpp +++ b/src/window/cengine.hpp @@ -100,7 +100,7 @@ class EE_API cEngine : public tSingleton { * You can set only the path to save the files, like "screenshots/" * @return False if failed, otherwise returns True */ - bool TakeScreenshot( std::string filepath = "", const EE_SAVETYPE& Format = EE_SAVE_TYPE_PNG ); + bool TakeScreenshot( std::string filepath = "", const EE_SAVE_TYPE& Format = EE_SAVE_TYPE_PNG ); /** @return The resolutions that support the video card */ std::vector< std::pair > GetPossibleResolutions() const; @@ -245,9 +245,10 @@ class EE_API cEngine : public tSingleton { #endif void SetDefaultContext(); + + ~cEngine(); protected: cEngine(); - ~cEngine(); private: bool mInit; VideoInfo mVideoInfo; diff --git a/src/window/cinput.hpp b/src/window/cinput.hpp index 90ffd3cfb..f612a5525 100755 --- a/src/window/cinput.hpp +++ b/src/window/cinput.hpp @@ -424,9 +424,10 @@ class EE_API cInput : public tSingleton { /** Set the double click interval in milliseconds */ void DoubleClickInterval( const Uint32& Interval ); + + ~cInput(); protected: cInput(); - ~cInput(); cEngine* EE; EE_Event mEvent; diff --git a/src/window/cjoystickmanager.cpp b/src/window/cjoystickmanager.cpp index 0930ef9f2..de2e4576f 100644 --- a/src/window/cjoystickmanager.cpp +++ b/src/window/cjoystickmanager.cpp @@ -50,7 +50,7 @@ void cJoystickManager::Create( const Uint32& index ) { if ( NULL != mJoysticks[ index ] ) mJoysticks[ index ]->ReOpen(); else - mJoysticks[ index ] = new cJoystick( index ); + mJoysticks[ index ] = eeNew( cJoystick, ( index ) ); } void cJoystickManager::Close() {