Mercurial > fife-parpg
changeset 495:ae9f5383f5b1
Added a new log module called Script. This should be used by the python modules.
Did some code cleanup and comment cleanup.
Added some more visible log modules to the shooter demo for fun.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Tue, 11 May 2010 21:30:55 +0000 |
parents | e241d7553496 |
children | 987307d12235 |
files | demos/shooter/run.py demos/shooter/scripts/scene.py demos/shooter/scripts/world.py engine/core/modules.h engine/core/util/log/logger.cpp engine/core/util/log/logger.i engine/python/fife/extensions/fife_math.py engine/python/fife/extensions/fife_timer.py engine/python/fife/extensions/fife_utils.py engine/python/fife/extensions/fifelog.py engine/python/fife/extensions/soundmanager.py |
diffstat | 11 files changed, 131 insertions(+), 77 deletions(-) [+] |
line wrap: on
line diff
--- a/demos/shooter/run.py Mon May 10 15:54:21 2010 +0000 +++ b/demos/shooter/run.py Tue May 11 21:30:55 2010 +0000 @@ -45,9 +45,6 @@ super(ApplicationListener, self).__init__(engine,regKeys=True,regCmd=True, regMouse=False, regConsole=True, regWidget=True) self._engine = engine self._world = world - engine.getEventManager().setNonConsumableKeys([ - fife.Key.ESCAPE,]) - self._quit = False def keyPressed(self, evt): @@ -112,11 +109,32 @@ Initialize the LogManager. """ - LogModules = ["controller",] - self._log = fifelog.LogManager(self.engine, 1, 0) - if LogModules: - self._log.setVisibleModules(*LogModules) - + logmodules = ["controller", + "event channel", + "audio", + "model", + "metamodel", + "pool", + "vfs", + "video", + "view", + "camera", + "util", + "pool", + "xml", + "exception", + "structures", + "location", + "native loaders", + "loaders", + "gui", + "script"] + + #log to both the console and log file + self._log = fifelog.LogManager(self.engine, 1, 1) + if logmodules: + self._log.setVisibleModules(*logmodules) + def createListener(self): pass # already created in constructor
--- a/demos/shooter/scripts/scene.py Mon May 10 15:54:21 2010 +0000 +++ b/demos/shooter/scripts/scene.py Tue May 11 21:30:55 2010 +0000 @@ -446,7 +446,7 @@ if not obj.running: self.queueObjectForRemoval(obj) -# self._world.renderBoundingBox(obj) + #self._world.renderBoundingBox(obj)
--- a/demos/shooter/scripts/world.py Mon May 10 15:54:21 2010 +0000 +++ b/demos/shooter/scripts/world.py Tue May 11 21:30:55 2010 +0000 @@ -57,7 +57,12 @@ self._eventmanager = engine.getEventManager() self._model = engine.getModel() self._filename = '' - self._keystate = { 'UP': False, 'DOWN': False, 'LEFT': False, 'RIGHT': False, 'CTRL': False, 'SPACE': False, } + self._keystate = { 'UP': False, + 'DOWN': False, + 'LEFT': False, + 'RIGHT': False, + 'CTRL': False, + 'SPACE': False, } self._pump_ctr = 0 self._map = None self._scene = None @@ -146,7 +151,7 @@ self._genericrenderer = fife.GenericRenderer.getInstance(self.cameras['main']) self._genericrenderer.clearActiveLayers() - self._genericrenderer.addActiveLayer(self._map.getLayer('objects')) + self._genericrenderer.addActiveLayer(self._map.getLayer('boundingbox')) self._genericrenderer.setEnabled(True) @@ -246,6 +251,10 @@ self._mainmenu.hide() self._paused = False + def pauseGame(self): + self._paused = True + self._mainmenu.show(True) + def initCameras(self): """ Before we can actually see something on screen we have to specify the render setup.
--- a/engine/core/modules.h Mon May 10 15:54:21 2010 +0000 +++ b/engine/core/modules.h Tue May 11 21:30:55 2010 +0000 @@ -62,6 +62,7 @@ LM_VIEWVIEW, LM_XML, LM_EXCEPTION, + LM_SCRIPT, LM_MODULE_MAX // sentinel }; @@ -96,7 +97,8 @@ {LM_CAMERA, LM_VIEW, "Camera"}, \ {LM_VIEWVIEW, LM_VIEW, "View::View"}, \ {LM_XML, LM_CORE, "XML"}, \ - {LM_EXCEPTION, LM_CORE, "Exception"} \ + {LM_EXCEPTION, LM_CORE, "Exception"}, \ + {LM_SCRIPT, LM_CORE, "Script"} \ }; #endif
--- a/engine/core/util/log/logger.cpp Mon May 10 15:54:21 2010 +0000 +++ b/engine/core/util/log/logger.cpp Tue May 11 21:30:55 2010 +0000 @@ -51,30 +51,30 @@ Logger::Logger(logmodule_t module): m_module(module) { } - + Logger::~Logger() { } - + void Logger::log(LogManager::LogLevel level, const std::string& msg) { LogManager::instance()->log(level, m_module, msg); } - + void Logger::log(LogManager::LogLevel level, const LMsg& msg) { LogManager::instance()->log(level, m_module, msg.str); } - + LogManager* LogManager::instance() { if (!m_instance) { m_instance = new LogManager(); } return m_instance; } - + LogManager::~LogManager() { delete m_instance; } - - + + void LogManager::log(LogLevel level, logmodule_t module, const std::string& msg) { if (level < m_level) { return; @@ -86,19 +86,19 @@ switch (level) { case LEVEL_DEBUG: lvlstr = "dbg"; break; - + case LEVEL_LOG: lvlstr = "log"; break; - + case LEVEL_WARN: lvlstr = "warn"; break; - + case LEVEL_ERROR: lvlstr = "error"; break; - + case LEVEL_PANIC: lvlstr = "panic"; break; - + default: lvlstr = "error"; break; } @@ -112,11 +112,11 @@ abort(); } } - + void LogManager::setLevelFilter(LogLevel level) { m_level = level; } - + LogManager::LogLevel LogManager::getLevelFilter() { return m_level; } @@ -129,12 +129,12 @@ addVisibleModule(moduleInfos[ind].parent); } } - + void LogManager::removeVisibleModule(logmodule_t module) { validateModule(module); m_modules[module] = false; } - + void LogManager::clearVisibleModules() { for (int i = 0; i < LM_MODULE_MAX; i++) { m_modules[i] = false; @@ -144,19 +144,27 @@ void LogManager::setLogToPrompt(bool log_to_promt) { m_logtoprompt = log_to_promt; } - + bool LogManager::isLoggingToPrompt() { return m_logtoprompt; } - + void LogManager::setLogToFile(bool logtofile) { + if(logtofile){ + m_logfile = new std::ofstream("fife.log"); + } + else { + if (m_logfile){ + delete m_logfile; + } + } m_logtofile = logtofile; } - + bool LogManager::isLoggingToFile() { return m_logtofile; } - + bool LogManager::isVisible(logmodule_t module) { if (!m_modules[module]) { return false; @@ -166,24 +174,24 @@ } return true; } - + LogManager::LogManager(): m_level(LEVEL_DEBUG), module_check_stack(), m_logtofile(false), m_logtoprompt(false) { validateModuleDescription(LM_CORE); - m_logfile = new std::ofstream("fife.log"); + m_logfile = 0; clearVisibleModules(); } - + void LogManager::validateModule(logmodule_t m) { if ((m <= LM_CORE) || (m >= LM_MODULE_MAX)) { std::cout << "Invalid module received in LogManager: " << m << ", aborting\n"; abort(); } } - + void LogManager::validateModuleDescription(logmodule_t module) { if (module == LM_CORE) { for (int m = static_cast<int>(LM_CORE)+1; m < static_cast<int>(LM_MODULE_MAX); m++) { @@ -205,7 +213,7 @@ } } } - + std::string LogManager::getModuleName(logmodule_t module) { return moduleInfos[module].name; }
--- a/engine/core/util/log/logger.i Mon May 10 15:54:21 2010 +0000 +++ b/engine/core/util/log/logger.i Tue May 11 21:30:55 2010 +0000 @@ -42,6 +42,7 @@ }; ~LogManager(); + void log(LogLevel level, logmodule_t module, const std::string& msg); void setLevelFilter(LogLevel level); LogLevel getLevelFilter(); @@ -67,4 +68,4 @@ ~Logger(); void log(LogManager::LogLevel level, const std::string& msg); }; -} \ No newline at end of file +}
--- a/engine/python/fife/extensions/fife_math.py Mon May 10 15:54:21 2010 +0000 +++ b/engine/python/fife/extensions/fife_math.py Tue May 11 21:30:55 2010 +0000 @@ -21,9 +21,6 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # #################################################################### -from fife import fife -import math - """ Math Library ================================== @@ -31,6 +28,8 @@ This is a collection of useful 2D math functions/classes. """ +from fife import fife +import math def normalize(vector): """ @@ -145,14 +144,14 @@ """ Rotates a point around the specified origin. - @param origin: A L{fife.DoublePoint} specifying the origin. + @param origin: A point specifying the origin. @type origin: L{fife.DoublePoint} - @param point: A L{fife.DoublePoint} to be rotated. + @param point: The point to be rotated. @type point: L{fife.DoublePoint} @param angle: The angle in which to rotate the point. @type angle: C{int} or C{float} - @return: A L{fife.DoublePoint} representing the rotated point. + @return: The rotated point. @rtype: L{fife.DoublePoint} """ newp = fife.DoublePoint(0,0)
--- a/engine/python/fife/extensions/fife_timer.py Mon May 10 15:54:21 2010 +0000 +++ b/engine/python/fife/extensions/fife_timer.py Tue May 11 21:30:55 2010 +0000 @@ -21,8 +21,6 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # #################################################################### -from fife import fife - """ Convenient timers ================= @@ -40,6 +38,7 @@ """ +from fife import fife _manager = None _alltimers = [] @@ -119,7 +118,7 @@ @param delay: Delay in milliseconds. @param callback: The function to call. - @return The timer. + @return: The timer. @rtype: L{Timer} """ timer = Timer(delay, callback, 1) @@ -129,15 +128,13 @@ def repeatCall(period,callback): """ - Repeat a function call. + Repeat a function call. The call is repeated until the timer is stopped. @param period: Period between calls in milliseconds. @param callback: The function to call. @return: The timer. @rtype: L{Timer} - - The call is repeated until the timer is stopped. """ timer = Timer(period, callback, 0) timer.start()
--- a/engine/python/fife/extensions/fife_utils.py Mon May 10 15:54:21 2010 +0000 +++ b/engine/python/fife/extensions/fife_utils.py Tue May 11 21:30:55 2010 +0000 @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- # #################################################################### -# Copyright (C) 2005-2009 by the FIFE team -# http://www.fifengine.de +# Copyright (C) 2005-2010 by the FIFE team +# http://www.fifengine.net # This file is part of FIFE. # # FIFE is free software; you can redistribute it and/or @@ -20,14 +20,15 @@ # Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # #################################################################### + +""" This file contains some functions that may be useful """ + import fife, re, sys, os __all__ = ['is_fife_exc', 'getUserDataDirectory'] _exc_re = re.compile(r'_\[(\w+)\]_') -""" This file contains some functions that may be useful """ - def is_fife_exc(type, original_exc): """ Checks if an exception is of given type. Example:
--- a/engine/python/fife/extensions/fifelog.py Mon May 10 15:54:21 2010 +0000 +++ b/engine/python/fife/extensions/fifelog.py Tue May 11 21:30:55 2010 +0000 @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- # #################################################################### -# Copyright (C) 2005-2009 by the FIFE team -# http://www.fifengine.de +# Copyright (C) 2005-2010 by the FIFE team +# http://www.fifengine.net # This file is part of FIFE. # # FIFE is free software; you can redistribute it and/or @@ -24,19 +24,19 @@ from fife import fife class LogManager(object): - ''' + """ Log manager provides convenient apis to access engine logging functionality. You can set log targets individually (prompt, file). You can also adjust things like visible modules through log manager. - ''' + """ def __init__(self, engine, promptlog=True, filelog=False): - ''' + """ Constructs new log manager @param engine: Engine to hook into @param promptlog: If true, logs to prompt @param filelog: If true, logs to file (fife.log) - ''' + """ self.engine = engine self.lm = engine.getLogManager() self.lm.setLogToPrompt(promptlog) @@ -48,12 +48,12 @@ self.name2mod = dict([(v.lower(), k) for k, v in self.mod2name.items()]) def addVisibleModules(self, *names): - ''' + """ Adds modules that are visible in logs. By default, all modules are disabled. Does not remove previously visible modules @param names: module names to set visible - @see modules.h file for available modules in the engine - ''' + @see: modules.h file for available modules in the engine + """ names = [n.lower() for n in names] if 'all' in names: for k in self.mod2name.keys(): @@ -66,12 +66,12 @@ print 'Tried to enable non-existing log module "%s"' % m def removeVisibleModules(self, *names): - ''' + """ Removes modules that are visible in logs. By default, all modules are disabled. @param names: module names to set invisible - @see addVisibleModules - ''' + @see: addVisibleModules + """ names = [n.lower() for n in names] if 'all' in names: for k in self.mod2name.keys(): @@ -81,20 +81,39 @@ self.lm.removeVisibleModule(self.name2mod[m]) def getVisibleModules(self): - ''' + """ Gets currently visible modules - @see addVisibleModules - ''' + @see: addVisibleModules + """ mods = [] for k in self.mod2name.keys(): if self.lm.isVisible(k): mods.append(self.mod2name[k]) def setVisibleModules(self, *names): - ''' + """ Sets visible modules. Clears previously set modules. @param names: module names to set visible - @see addVisibleModules - ''' + @see: addVisibleModules + """ self.lm.clearVisibleModules() self.addVisibleModules(*names) + + def setLevelFilter(self, fltr): + """ + Sets the minimum log level to view. + @param fltr: The filter level + """ + self.lm.setLevelFilter(fltr) + + def log_debug(self, message): + self.lm.log(0, self.name2mod["script"], message) + + def log_log(self, message): + self.lm.log(1, self.name2mod["script"], message) + + def log_warn(self, message): + self.lm.log(2, self.name2mod["script"], message) + + def log_error(self, message): + self.lm.log(3, self.name2mod["script"], message)
--- a/engine/python/fife/extensions/soundmanager.py Mon May 10 15:54:21 2010 +0000 +++ b/engine/python/fife/extensions/soundmanager.py Tue May 11 21:30:55 2010 +0000 @@ -21,11 +21,6 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # #################################################################### -from fife import fife - -import fife.extensions.fife_timer as fife_timer -from fife.extensions.pychan.tools import callbackWithArguments as cbwa - """ Sound Manager ================================== @@ -46,6 +41,11 @@ """ +from fife import fife + +import fife.extensions.fife_timer as fife_timer +from fife.extensions.pychan.tools import callbackWithArguments as cbwa + class SoundEmitter(object): """ Wraps the L{fife.SoundEmitter} class.