Browse Source

Enable tinystl by default.

bkaradzic 12 years ago
parent
commit
ab969f0a1a
8 changed files with 34 additions and 50 deletions
  1. 2 0
      LICENSE
  2. 7 4
      examples/07-callback/callback.cpp
  3. 1 14
      examples/common/font/font_manager.cpp
  4. 0 1
      makefile
  5. 0 1
      premake/bgfx.lua
  6. 16 21
      src/bgfx.cpp
  7. 7 8
      src/bgfx_p.h
  8. 1 1
      src/config.h

+ 2 - 0
LICENSE

@@ -20,3 +20,5 @@ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY
 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 OF THE POSSIBILITY OF SUCH DAMAGE.
 OF THE POSSIBILITY OF SUCH DAMAGE.
+
+https://github.com/bkaradzic/bgfx

+ 7 - 4
examples/07-callback/callback.cpp

@@ -337,10 +337,13 @@ public:
 
 
 	virtual void free(void* _ptr, const char* _file, uint32_t _line) BX_OVERRIDE
 	virtual void free(void* _ptr, const char* _file, uint32_t _line) BX_OVERRIDE
 	{
 	{
-		dbgPrintf("%s(%d): FREE %p\n", _file, _line, _ptr);
-		BX_UNUSED(_file, _line);
-		::free(_ptr);
-		--m_numBlocks;
+		if (NULL != _ptr)
+		{
+			dbgPrintf("%s(%d): FREE %p\n", _file, _line, _ptr);
+			BX_UNUSED(_file, _line);
+			::free(_ptr);
+			--m_numBlocks;
+		}
 	}
 	}
 
 
 	virtual void* realloc(void* _ptr, size_t _size, const char* _file, uint32_t _line) BX_OVERRIDE
 	virtual void* realloc(void* _ptr, size_t _size, const char* _file, uint32_t _line) BX_OVERRIDE

+ 1 - 14
examples/common/font/font_manager.cpp

@@ -13,21 +13,8 @@
 #include "font_manager.h"
 #include "font_manager.h"
 #include "../cube_atlas.h"
 #include "../cube_atlas.h"
 
 
-#if BGFX_CONFIG_USE_TINYSTL
-namespace tinystl
-{
-} // namespace tinystl
-#   include <TINYSTL/unordered_map.hh>
+#include <tinystl/unordered_map.h>
 namespace stl = tinystl;
 namespace stl = tinystl;
-#else
-#   include <unordered_map>
-namespace std { namespace tr1 {} }
-namespace stl
-{
-	using namespace std;
-	using namespace std::tr1;
-}
-#endif // BGFX_CONFIG_USE_TINYSTL
 
 
 struct FTHolder
 struct FTHolder
 {
 {

+ 0 - 1
makefile

@@ -17,7 +17,6 @@ all:
 	premake4 --file=premake/premake4.lua --gcc=ios-simulator gmake
 	premake4 --file=premake/premake4.lua --gcc=ios-simulator gmake
 	premake4 --file=premake/premake4.lua --gcc=qnx-arm gmake
 	premake4 --file=premake/premake4.lua --gcc=qnx-arm gmake
 	premake4 --file=premake/premake4.lua xcode4
 	premake4 --file=premake/premake4.lua xcode4
-	make -s --no-print-directory -C src
 
 
 android-arm-debug:
 android-arm-debug:
 	make -R -C .build/projects/gmake-android-arm config=debug
 	make -R -C .build/projects/gmake-android-arm config=debug

+ 0 - 1
premake/bgfx.lua

@@ -8,7 +8,6 @@ project "bgfx"
 	kind "StaticLib"
 	kind "StaticLib"
 
 
 	includedirs {
 	includedirs {
-		BGFX_DIR .. "../tinystl/include",
 		BGFX_DIR .. "../bx/include",
 		BGFX_DIR .. "../bx/include",
 	}
 	}
 
 

+ 16 - 21
src/bgfx.cpp

@@ -5,22 +5,6 @@
 
 
 #include "bgfx_p.h"
 #include "bgfx_p.h"
 
 
-#if BGFX_CONFIG_USE_TINYSTL
-namespace tinystl
-{
-	void* bgfx_allocator::static_allocate(size_t _bytes)
-	{
-		return BX_ALLOC(g_allocator, _bytes);
-	}
-
-	void bgfx_allocator::static_deallocate(void* _ptr, size_t /*_bytes*/)
-	{
-		BX_FREE(g_allocator, _ptr);
-	}
-
-} // namespace tinystl
-#endif // BGFX_CONFIG_USE_TINYSTL
-
 namespace bgfx
 namespace bgfx
 {
 {
 #define BGFX_MAIN_THREAD_MAGIC 0x78666762
 #define BGFX_MAIN_THREAD_MAGIC 0x78666762
@@ -62,6 +46,16 @@ namespace bgfx
 	}
 	}
 #endif // BX_PLATFORM_*
 #endif // BX_PLATFORM_*
 
 
+	void* TinyStlAllocator::static_allocate(size_t _bytes)
+	{
+		return BX_ALLOC(bgfx::g_allocator, _bytes);
+	}
+
+	void TinyStlAllocator::static_deallocate(void* _ptr, size_t /*_bytes*/)
+	{
+		BX_FREE(bgfx::g_allocator, _ptr);
+	}
+
 	struct CallbackStub : public CallbackI
 	struct CallbackStub : public CallbackI
 	{
 	{
 		virtual ~CallbackStub()
 		virtual ~CallbackStub()
@@ -134,12 +128,13 @@ namespace bgfx
 
 
 		virtual void free(void* _ptr, const char* _file, uint32_t _line) BX_OVERRIDE
 		virtual void free(void* _ptr, const char* _file, uint32_t _line) BX_OVERRIDE
 		{
 		{
-			BX_CHECK(_ptr != NULL, "Freeing NULL! Fix it!");
-
-			--m_numBlocks;
+			if (NULL != _ptr)
+			{
+				--m_numBlocks;
 
 
-			BX_UNUSED(_file, _line);
-			::free(_ptr);
+				BX_UNUSED(_file, _line);
+				::free(_ptr);
+			}
 		}
 		}
 
 
 		virtual void* realloc(void* _ptr, size_t _size, const char* _file, uint32_t _line) BX_OVERRIDE
 		virtual void* realloc(void* _ptr, size_t _size, const char* _file, uint32_t _line) BX_OVERRIDE

+ 7 - 8
src/bgfx_p.h

@@ -82,19 +82,18 @@ namespace bgfx
 #include <list> // mingw wants it to be before tr1/unordered_*...
 #include <list> // mingw wants it to be before tr1/unordered_*...
 
 
 #if BGFX_CONFIG_USE_TINYSTL
 #if BGFX_CONFIG_USE_TINYSTL
-namespace tinystl
+namespace bgfx
 {
 {
-	struct bgfx_allocator
+	struct TinyStlAllocator
 	{
 	{
 		static void* static_allocate(size_t _bytes);
 		static void* static_allocate(size_t _bytes);
 		static void static_deallocate(void* _ptr, size_t /*_bytes*/);
 		static void static_deallocate(void* _ptr, size_t /*_bytes*/);
 	};
 	};
-} // namespace tinystl
-#	define TINYSTL_ALLOCATOR tinystl::bgfx_allocator
-
-#	include <TINYSTL/string.h>
-#	include <TINYSTL/unordered_map.h>
-#	include <TINYSTL/unordered_set.h>
+} // namespace bgfx
+#	define TINYSTL_ALLOCATOR bgfx::TinyStlAllocator
+#	include <tinystl/string.h>
+#	include <tinystl/unordered_map.h>
+#	include <tinystl/unordered_set.h>
 namespace stl = tinystl;
 namespace stl = tinystl;
 #else
 #else
 #	include <string>
 #	include <string>

+ 1 - 1
src/config.h

@@ -212,7 +212,7 @@
 #endif // BGFX_CONFIG_MAX_CONSTANT_BUFFER_SIZE
 #endif // BGFX_CONFIG_MAX_CONSTANT_BUFFER_SIZE
 
 
 #ifndef BGFX_CONFIG_USE_TINYSTL
 #ifndef BGFX_CONFIG_USE_TINYSTL
-#	define BGFX_CONFIG_USE_TINYSTL 0
+#	define BGFX_CONFIG_USE_TINYSTL 1
 #endif // BGFX_CONFIG_USE_TINYSTL
 #endif // BGFX_CONFIG_USE_TINYSTL
 
 
 #ifndef BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT
 #ifndef BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT