Ver código fonte

Added an instance of the Logger to CoreServices and added a nonstatic log method called logBroadcast that dispatches a notify event from the Logger instance so that they can be printed to listening consoles. Made the GLSL module use the log broadcast for its error message. Made IDE console listen to Logger broadcasts.

Ivan Safrin 12 anos atrás
pai
commit
1733f6fb3d

+ 9 - 1
Core/Contents/Include/PolyCoreServices.h

@@ -41,6 +41,7 @@ namespace Polycode {
 	class SoundManager;
 	class SoundManager;
 	class Core;
 	class Core;
 	class CoreMutex;
 	class CoreMutex;
+	class Logger;
 	
 	
 	/**
 	/**
 	* Global services singleton. CoreServices instantiates and provides global Singleton access to all of the main manager classes in Polycode as well as the Renderer and Config classes.
 	* Global services singleton. CoreServices instantiates and provides global Singleton access to all of the main manager classes in Polycode as well as the Renderer and Config classes.
@@ -146,11 +147,17 @@ namespace Polycode {
 			*/																											
 			*/																											
 			FontManager *getFontManager();
 			FontManager *getFontManager();
 
 
+			/**
+			* Returns the logger. It can log messages and broadcast them to listeners.
+			*/
+			Logger *getLogger();
+
 			/**
 			/**
 			* Returns the config. The config loads and saves data to disk.
 			* Returns the config. The config loads and saves data to disk.
 			* @return Config manager.
 			* @return Config manager.
 			* @see Config
 			* @see Config
-			*/																													
+			*/														
+						
 			Config *getConfig();
 			Config *getConfig();
 			
 			
 			/**
 			/**
@@ -181,6 +188,7 @@ namespace Polycode {
 			MaterialManager *materialManager;
 			MaterialManager *materialManager;
 			ScreenManager *screenManager;		
 			ScreenManager *screenManager;		
 			SceneManager *sceneManager;
 			SceneManager *sceneManager;
+			Logger *logger;
 			TimerManager *timerManager;
 			TimerManager *timerManager;
 			TweenManager *tweenManager;
 			TweenManager *tweenManager;
 			ResourceManager *resourceManager;
 			ResourceManager *resourceManager;

+ 3 - 1
Core/Contents/Include/PolyEvent.h

@@ -81,7 +81,9 @@ namespace Polycode {
 			static const int COMPLETE_EVENT = EVENTBASE_EVENT+0;
 			static const int COMPLETE_EVENT = EVENTBASE_EVENT+0;
 			static const int CHANGE_EVENT = EVENTBASE_EVENT+1;
 			static const int CHANGE_EVENT = EVENTBASE_EVENT+1;
 			static const int CANCEL_EVENT = EVENTBASE_EVENT+2;
 			static const int CANCEL_EVENT = EVENTBASE_EVENT+2;
-			
+			static const int NOTIFY_EVENT = EVENTBASE_EVENT+3;
+			static const int FIRE_EVENT = EVENTBASE_EVENT+4;
+						
 			static const int EVENTBASE_NONPOLYCODE = 0x10000;
 			static const int EVENTBASE_NONPOLYCODE = 0x10000;
 		
 		
 			bool deleteOnDispatch;
 			bool deleteOnDispatch;

+ 15 - 3
Core/Contents/Include/PolyLogger.h

@@ -22,13 +22,25 @@ THE SOFTWARE.
 
 
 #pragma once
 #pragma once
 #include "PolyGlobals.h"
 #include "PolyGlobals.h"
+#include "PolyEventDispatcher.h"
 
 
 namespace Polycode {
 namespace Polycode {
 
 
-	class _PolyExport Logger : public PolyBase {
+	class _PolyExport LoggerEvent : public Event {
 		public:
 		public:
-			Logger(){}
-			~Logger(){}
+			LoggerEvent(String message);
+			virtual ~LoggerEvent();
+			
+			String message;
+			
+	};
+
+	class _PolyExport Logger : public EventDispatcher {
+		public:
+			Logger();
+			virtual ~Logger();
+
+			void logBroadcast(String message);
 
 
 			static void log(const char *format, ...);
 			static void log(const char *format, ...);
 			static void logw(const char *str);
 			static void logw(const char *str);

+ 5 - 0
Core/Contents/Source/PolyCoreServices.cpp

@@ -97,6 +97,10 @@ Config *CoreServices::getConfig() {
 	return config;
 	return config;
 }
 }
 
 
+Logger *CoreServices::getLogger() {
+	return logger;
+}
+
 void CoreServices::installModule(PolycodeModule *module)  {
 void CoreServices::installModule(PolycodeModule *module)  {
 	modules.push_back(module);
 	modules.push_back(module);
 	if(module->requiresUpdate()) {
 	if(module->requiresUpdate()) {
@@ -118,6 +122,7 @@ void CoreServices::setupBasicListeners() {
 }
 }
 
 
 CoreServices::CoreServices() : EventDispatcher() {
 CoreServices::CoreServices() : EventDispatcher() {
+	logger = new Logger();
 	resourceManager = new ResourceManager();	
 	resourceManager = new ResourceManager();	
 	config = new Config();
 	config = new Config();
 	materialManager = new MaterialManager();
 	materialManager = new MaterialManager();

+ 2 - 0
Core/Contents/Source/PolyGLSLShaderModule.cpp

@@ -29,6 +29,7 @@ THE SOFTWARE.
 
 
 #include "PolyGLSLShaderModule.h"
 #include "PolyGLSLShaderModule.h"
 #include "PolyCoreServices.h"
 #include "PolyCoreServices.h"
+#include "PolyCore.h"
 #include "PolyResourceManager.h"
 #include "PolyResourceManager.h"
 #include "PolyRenderer.h"
 #include "PolyRenderer.h"
 #include "PolyGLSLProgram.h"
 #include "PolyGLSLProgram.h"
@@ -523,6 +524,7 @@ void GLSLShaderModule::recreateGLSLProgram(GLSLProgram *prog, const String& file
         log = (GLchar*)malloc(length);
         log = (GLchar*)malloc(length);
         glGetShaderInfoLog(prog->program, length, &length, log);
         glGetShaderInfoLog(prog->program, length, &length, log);
 		printf("GLSL ERROR: %s\n", log);
 		printf("GLSL ERROR: %s\n", log);
+		CoreServices::getInstance()->getLogger()->logBroadcast("GLSL ERROR:" + String(log));
         free(log);
         free(log);
     }		
     }		
 		
 		

+ 22 - 1
Core/Contents/Source/PolyLogger.cpp

@@ -28,13 +28,34 @@
 
 
 using namespace Polycode;
 using namespace Polycode;
 
 
+LoggerEvent::LoggerEvent(String message) : Event() {
+	this->message = message;
+}
+
+LoggerEvent::~LoggerEvent() {
+
+}
+
+
+Logger::Logger() : EventDispatcher() {
+
+}
+
+Logger::~Logger() {
+
+}
+
+void Logger::logBroadcast(String message) {
+	dispatchEvent(new LoggerEvent(message), Event::NOTIFY_EVENT);
+	Logger::log(message.c_str());
+}
+
 void Logger::logw(const char *str) {
 void Logger::logw(const char *str) {
 	std::wcout << str << std::endl;
 	std::wcout << str << std::endl;
 }
 }
 
 
 void Logger::log(const char *format, ...) {
 void Logger::log(const char *format, ...) {
 	va_list args;
 	va_list args;
-
 	va_start(args, format);
 	va_start(args, format);
 	vfprintf(stderr, format, args);
 	vfprintf(stderr, format, args);
 	va_end(args);
 	va_end(args);

+ 8 - 1
IDE/Contents/Source/PolycodeConsole.cpp

@@ -223,6 +223,7 @@ PolycodeConsole::PolycodeConsole() : UIElement() {
 	consoleHistoryMaxSize = 15;
 	consoleHistoryMaxSize = 15;
 	
 	
 	consoleWindow->clearButton->addEventListener(this, UIEvent::CLICK_EVENT);
 	consoleWindow->clearButton->addEventListener(this, UIEvent::CLICK_EVENT);
+	CoreServices::getInstance()->getLogger()->addEventListener(this, Event::NOTIFY_EVENT);
 
 
 	PolycodeConsole::setInstance(this);
 	PolycodeConsole::setInstance(this);
 }
 }
@@ -245,7 +246,13 @@ void PolycodeConsole::setDebugger(PolycodeRemoteDebugger *debugger) {
 }
 }
 
 
 void PolycodeConsole::handleEvent(Event *event) {
 void PolycodeConsole::handleEvent(Event *event) {
-	if(event->getDispatcher() == consoleWindow->clearButton) {
+
+	if(event->getDispatcher() == CoreServices::getInstance()->getLogger()) {
+		if(event->getEventCode() == Event::NOTIFY_EVENT) {
+			LoggerEvent *loggerEvent = (LoggerEvent*)event;
+			_print(loggerEvent->message);
+		}
+	} else if(event->getDispatcher() == consoleWindow->clearButton) {
 		if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CLICK_EVENT) {
 		if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CLICK_EVENT) {
 			debugTextInput->setText("");
 			debugTextInput->setText("");
 		}
 		}