From 5402346b16218b891d7ed8d738c84edd880b7dae Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Tue, 22 Jan 2013 00:48:51 +0000 Subject: [PATCH] core: move the Log and Timer classes to the sys/ subdirectory, use the String class instead of the stack for logging, and get rid of the old and useless BitField class. --- src/Makefile.am | 16 +++++------ src/bitfield.h | 55 ------------------------------------- src/core.h | 4 +-- src/{ => lol/sys}/log.h | 8 +++--- src/{ => lol/sys}/timer.h | 8 +++--- src/lolcore.vcxproj | 7 +++-- src/lolcore.vcxproj.filters | 11 +------- src/{ => sys}/log.cpp | 15 +++------- src/{ => sys}/timer.cpp | 0 9 files changed, 26 insertions(+), 98 deletions(-) delete mode 100644 src/bitfield.h rename src/{ => lol/sys}/log.h (88%) rename src/{ => lol/sys}/timer.h (77%) rename src/{ => sys}/log.cpp (87%) rename src/{ => sys}/timer.cpp (100%) diff --git a/src/Makefile.am b/src/Makefile.am index c47f1a1e..9e05cd35 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -9,21 +9,19 @@ liblol_a_SOURCES = \ core.h tiler.cpp tiler.h dict.cpp dict.h \ audio.cpp audio.h scene.cpp scene.h font.cpp font.h layer.cpp layer.h \ map.cpp map.h entity.cpp entity.h ticker.cpp ticker.h lolgl.h \ - tileset.cpp tileset.h forge.cpp forge.h video.cpp video.h log.cpp log.h \ - timer.cpp timer.h bitfield.h profiler.cpp profiler.h \ + tileset.cpp tileset.h forge.cpp forge.h video.cpp video.h \ world.cpp world.h sample.cpp sample.h sampler.cpp sampler.h \ - text.cpp text.h emitter.cpp emitter.h numeric.h \ + profiler.cpp profiler.h text.cpp text.h emitter.cpp emitter.h numeric.h \ worldentity.cpp worldentity.h gradient.cpp gradient.h gradient.lolfx \ platform.cpp platform.h sprite.cpp sprite.h camera.cpp camera.h \ \ - lol/unit.h lol/debug.h \ lol/base/types.h lol/base/array.h lol/base/string.h lol/base/hash.h \ lol/base/map.h \ lol/math/vector.h lol/math/half.h lol/math/real.h lol/math/remez.h \ - lol/math/math.h \ - lol/math/geometry.h \ - lol/sys/init.h \ + lol/math/math.h lol/math/geometry.h \ + lol/sys/init.h lol/sys/log.h lol/sys/thread.h lol/sys/timer.h \ lol/image/color.h \ + lol/unit.h lol/debug.h \ \ generated/location.hh generated/position.hh generated/stack.hh \ \ @@ -71,8 +69,8 @@ liblol_a_SOURCES = \ \ mesh/mesh.cpp mesh/mesh.h \ \ - sys/init.cpp \ - sys/threadbase.h sys/thread.h \ + sys/init.cpp sys/log.cpp sys/timer.cpp \ + sys/threadbase.h \ \ image/image.cpp image/image.h image/image-private.h \ image/codec/gdiplus-image.cpp \ diff --git a/src/bitfield.h b/src/bitfield.h deleted file mode 100644 index 5df0bbd0..00000000 --- a/src/bitfield.h +++ /dev/null @@ -1,55 +0,0 @@ -// -// Lol Engine -// -// Copyright: (c) 2010-2011 Sam Hocevar -// This program is free software; you can redistribute it and/or -// modify it under the terms of the Do What The Fuck You Want To -// Public License, Version 2, as published by Sam Hocevar. See -// http://www.wtfpl.net/ for more details. -// - -// -// The BitField class -// ------------------ -// - -#if !defined __LOL_BITFIELD_H__ -#define __LOL_BITFIELD_H__ - -#include - -namespace lol -{ - -template class BitField -{ -public: - BitField() - { - memset(bits, 0, sizeof(bits)); - } - - inline unsigned int IsSet(unsigned int index) - { - return bits[index / 32] & (1 << (index & 31)); - } - - inline void Set(unsigned int index) - { - bits[index / 32] |= (1 << (index & 31)); - } - - inline void Unset(unsigned int index) - { - bits[index / 32] &= ~(1 << (index & 31)); - } - - -private: - uint32_t bits[(COUNT + 31) / 32]; -}; - -} /* namespace lol */ - -#endif // __LOL_BITFIELD_H__ - diff --git a/src/core.h b/src/core.h index 9fa9788e..59ad46ca 100644 --- a/src/core.h +++ b/src/core.h @@ -89,15 +89,15 @@ static inline int isnan(float f) #include #include +#include #include +#include #include #include "numeric.h" -#include "timer.h" // Static classes -#include "log.h" #include "platform.h" #include "video.h" #include "audio.h" diff --git a/src/log.h b/src/lol/sys/log.h similarity index 88% rename from src/log.h rename to src/lol/sys/log.h index 63d813f3..cebf89db 100644 --- a/src/log.h +++ b/src/lol/sys/log.h @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright: (c) 2010-2011 Sam Hocevar +// Copyright: (c) 2010-2013 Sam Hocevar // This program is free software; you can redistribute it and/or // modify it under the terms of the Do What The Fuck You Want To // Public License, Version 2, as published by Sam Hocevar. See @@ -14,8 +14,8 @@ // The central logging system. // -#if !defined __LOL_LOG_H__ -#define __LOL_LOG_H__ +#if !defined __LOL_SYS_LOG_H__ +#define __LOL_SYS_LOG_H__ #include #include @@ -51,5 +51,5 @@ private: } /* namespace lol */ -#endif // __LOL_LOG_H__ +#endif // __LOL_SYS_LOG_H__ diff --git a/src/timer.h b/src/lol/sys/timer.h similarity index 77% rename from src/timer.h rename to src/lol/sys/timer.h index e6a8a103..17a02035 100644 --- a/src/timer.h +++ b/src/lol/sys/timer.h @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright: (c) 2010-2011 Sam Hocevar +// Copyright: (c) 2010-2013 Sam Hocevar // This program is free software; you can redistribute it and/or // modify it under the terms of the Do What The Fuck You Want To // Public License, Version 2, as published by Sam Hocevar. See @@ -13,8 +13,8 @@ // --------------- // -#if !defined __LOL_TIMER_H__ -#define __LOL_TIMER_H__ +#if !defined __LOL_SYS_TIMER_H__ +#define __LOL_SYS_TIMER_H__ namespace lol { @@ -37,5 +37,5 @@ private: } /* namespace lol */ -#endif // __LOL_TIMER_H__ +#endif // __LOL_SYS_TIMER_H__ diff --git a/src/lolcore.vcxproj b/src/lolcore.vcxproj index df46b8b8..9530aa05 100644 --- a/src/lolcore.vcxproj +++ b/src/lolcore.vcxproj @@ -272,7 +272,6 @@ - @@ -294,6 +293,8 @@ + + @@ -306,7 +307,6 @@ - @@ -584,7 +584,6 @@ - @@ -601,7 +600,9 @@ + + diff --git a/src/lolcore.vcxproj.filters b/src/lolcore.vcxproj.filters index 342bb2a4..f094d8e2 100644 --- a/src/lolcore.vcxproj.filters +++ b/src/lolcore.vcxproj.filters @@ -192,9 +192,6 @@ ... - - ... - ... @@ -752,9 +749,6 @@ ... - - ... - ... @@ -785,9 +779,6 @@ ... - - ... - ... @@ -1675,4 +1666,4 @@ gpu - \ No newline at end of file + diff --git a/src/log.cpp b/src/sys/log.cpp similarity index 87% rename from src/log.cpp rename to src/sys/log.cpp index b2925c1f..c35408a7 100644 --- a/src/log.cpp +++ b/src/sys/log.cpp @@ -82,11 +82,8 @@ void Log::Helper(MessageType type, char const *fmt, va_list ap) ANDROID_LOG_ERROR }; - char buf[4096]; - vsnprintf(buf, 4095, fmt, ap); - buf[4095] = '\0'; - - __android_log_print(prio[type], "LOL", "[%d] %s", (int)gettid(), buf); + String buf = String::Printf(fmt, ap); + __android_log_print(prio[type], "LOL", "[%d] %s", (int)gettid(), &buf[0]); #else char const *prefix[] = @@ -98,12 +95,8 @@ void Log::Helper(MessageType type, char const *fmt, va_list ap) }; # if defined _WIN32 - char buf[4096]; - vsnprintf(buf, 4095, fmt, ap); - buf[4095] = '\0'; - OutputDebugString(prefix[type]); - OutputDebugString(": "); - OutputDebugString(buf); + String buf = String(prefix[type]) + ": " + String::Printf(fmt, ap); + OutputDebugString(&buf[0]); # else fprintf(stderr, "%s: ", prefix[type]); vfprintf(stderr, fmt, ap); diff --git a/src/timer.cpp b/src/sys/timer.cpp similarity index 100% rename from src/timer.cpp rename to src/sys/timer.cpp