changeset 684:4f36c890b1dd

* Merged the 0.3.3dev branche changes to the trunk.
author helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 06 Dec 2010 19:25:27 +0000
parents 4fe9747d5f88
children 2a1e47d3dab2
files engine/core/gui/console/console.cpp engine/core/model/structures/instance.cpp engine/core/model/structures/instance.h engine/core/model/structures/instance.i engine/core/model/structures/layer.cpp engine/core/util/base/exception.cpp engine/core/util/base/exception.h engine/core/vfs/vfs.cpp engine/core/view/renderers/blockinginforenderer.cpp engine/python/fife/extensions/pythonize.py engine/python/fife/extensions/savers.py engine/python/fife/extensions/serializers/xmlmap.py engine/swigwrappers/python/fife.i.templ tools/editor/gui/objectedit.xml tools/editor/plugins/ObjectEdit.py
diffstat 15 files changed, 169 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/engine/core/gui/console/console.cpp	Mon Dec 06 18:37:18 2010 +0000
+++ b/engine/core/gui/console/console.cpp	Mon Dec 06 19:25:27 2010 +0000
@@ -47,7 +47,7 @@
 	const unsigned  Console::m_maxOutputRows = 50;
 	static Logger _log(LM_CONSOLE);
 
-	Console::Console() 
+	Console::Console()
 		: gcn::Container(),
 		m_consoleexec(0),
 		m_input(new CommandLine()),
@@ -90,7 +90,7 @@
 	void Console::reLayout() {
 		Image* screen = RenderBackend::instance()->getScreenImage();
 		assert(screen);
-		
+
 		int w, h, b, input_h, bbar_h, button_w;
 		w = screen->getWidth() * 4/5;
 		h = screen->getHeight() * 4/5;
@@ -98,7 +98,7 @@
 		input_h = getFont()->getHeight();
 		bbar_h = input_h;
 		button_w = 80;
-		
+
 		gcn::Color black(0x00,0,0,0xff);
 		gcn::Color white(0xff,0xff,0xff,0xff);
 		gcn::Color dark(50,60,50,0xff);
@@ -147,7 +147,7 @@
 
 	Console::~Console() {
 		doHide();
-		
+
 		remove(m_input);
 		remove(m_outputscrollarea);
 		remove(m_status);
@@ -165,7 +165,7 @@
 		caption += boost::lexical_cast<std::string>(fps);
 		m_status->setCaption( caption );
 	}
-	
+
 	void Console::updateAnimation() {
 	    if (m_hiding){
 		setPosition(getX(), getY() - m_animationDelta);
@@ -246,8 +246,8 @@
 			}
 		}
 		catch (const FIFE::Exception & e) {
-			FL_WARN(_log, LMsg("Console caught exception: ") << e.getMessage());
-			println(e.getMessage());
+			FL_WARN(_log, LMsg("Console caught exception: ") << e.what());
+			println(e.what());
 		}
 	}
 
--- a/engine/core/model/structures/instance.cpp	Mon Dec 06 18:37:18 2010 +0000
+++ b/engine/core/model/structures/instance.cpp	Mon Dec 06 19:25:27 2010 +0000
@@ -182,7 +182,9 @@
 		m_object(object),
 		m_location(location),
 		m_facinglocation(NULL),
-		m_visual(NULL) {
+		m_visual(NULL),
+		m_blocking(object->isBlocking()),
+		m_override_blocking(false) {
 	}
 
 	Instance::~Instance() {
@@ -244,6 +246,16 @@
 		m_id = identifier;
 	}
 
+	void Instance::setBlocking(bool blocking) {
+		if (m_override_blocking) {
+			m_blocking = blocking;
+		}
+	}
+
+	bool Instance::isBlocking() const {
+		return m_blocking;
+	}
+
 	void Instance::addActionListener(InstanceActionListener* listener) {
 		initializeChanges();
 		m_activity->m_actionlisteners.push_back(listener);
--- a/engine/core/model/structures/instance.h	Mon Dec 06 18:37:18 2010 +0000
+++ b/engine/core/model/structures/instance.h	Mon Dec 06 19:25:27 2010 +0000
@@ -158,6 +158,22 @@
 		 */
 		Location& getFacingLocationRef();
 
+		/** Sets if instance blocks movement
+		 */
+		void setBlocking(bool blocking);
+
+		/** Gets if instance blocks movement
+		 */
+		bool isBlocking() const;
+
+		/** Sets if instance blocking can overriden
+		 */
+		void setOverrideBlocking(bool overblock) { m_override_blocking = overblock; }
+
+		/** Gets if instance blocking can overriden
+		 */
+		bool isOverrideBlocking() const { return m_override_blocking; }
+
 		/** Adds new instance action listener
 		 * @param listener to add
 		 */
@@ -359,6 +375,10 @@
 		Location* m_facinglocation;
 		// instance visualization
 		AbstractVisual* m_visual;
+		// instance blocking info
+		bool m_blocking;
+		// allow to override the blocking property
+		bool m_override_blocking;
 
 		Instance(const Instance&);
 		Instance& operator=(const Instance&);
--- a/engine/core/model/structures/instance.i	Mon Dec 06 18:37:18 2010 +0000
+++ b/engine/core/model/structures/instance.i	Mon Dec 06 19:25:27 2010 +0000
@@ -76,6 +76,10 @@
 		Location getTargetLocation() const;
 		void setRotation(int);
 		int getRotation() const;
+		void setBlocking(bool blocking);
+		bool isBlocking() const;
+		void setOverrideBlocking(bool overblock);
+		bool isOverrideBlocking() const;
 		void addActionListener(InstanceActionListener* listener);
 		void removeActionListener(InstanceActionListener* listener);
 		void addChangeListener(InstanceChangeListener* listener);
--- a/engine/core/model/structures/layer.cpp	Mon Dec 06 18:37:18 2010 +0000
+++ b/engine/core/model/structures/layer.cpp	Mon Dec 06 19:25:27 2010 +0000
@@ -238,7 +238,7 @@
 		m_instanceTree->findInstances(cellCoordinate, 0, 0, adjacentInstances);
 		bool blockingInstance = false;
 		for(std::list<Instance*>::const_iterator j = adjacentInstances.begin(); j != adjacentInstances.end(); ++j) {
-			if((*j)->getObject()->isBlocking() && (*j)->getLocationRef().getLayerCoordinates() == cellCoordinate) {
+			if((*j)->isBlocking() && (*j)->getLocationRef().getLayerCoordinates() == cellCoordinate) {
 				blockingInstance = true;
 			}
 		}
--- a/engine/core/util/base/exception.cpp	Mon Dec 06 18:37:18 2010 +0000
+++ b/engine/core/util/base/exception.cpp	Mon Dec 06 19:25:27 2010 +0000
@@ -1,6 +1,6 @@
 /***************************************************************************
- *   Copyright (C) 2005-2008 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                 *
@@ -34,15 +34,16 @@
 namespace FIFE {
 static Logger _log(LM_EXCEPTION);
 
-	Exception::Exception(const std::string& msg): m_message(msg) {
-		FL_WARN(_log, LMsg() << getMessage());
-		}
+	Exception::Exception(const std::string& msg): std::runtime_error(msg) {
+		FL_PANIC(_log, LMsg() << what());
+	}
+
+	Exception::~Exception() throw() {}
 
-	Exception::~Exception() {}
+	const char* Exception::what() const throw() {
+		std::stringstream str;
 
-	std::string Exception::getMessage() const {
-		std::stringstream str;
-		str << "_[" << getTypeStr() << "]_ , " << m_message;
-		return str.str();
+		str << "_[" << getTypeStr() << "]_ , " << std::runtime_error::what();
+		return str.str().c_str();
 	}
 }//FIFE
--- a/engine/core/util/base/exception.h	Mon Dec 06 18:37:18 2010 +0000
+++ b/engine/core/util/base/exception.h	Mon Dec 06 19:25:27 2010 +0000
@@ -1,6 +1,6 @@
 /***************************************************************************
- *   Copyright (C) 2005-2008 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,6 +24,7 @@
 
 // Standard C++ library includes
 #include <string>
+#include <stdexcept>
 
 // 3rd party library includes
 
@@ -38,28 +39,24 @@
 	 * All other exceptions derived from this merely adjust the error string
 	 * to be slightly more specific.
 	 */
-	class Exception {
+	class Exception : public std::runtime_error {
 	public:
-		/** Constructor. 
-		 * @param txt The error mesage to be stored.
+		/** Constructor.
+		 * @param msg The error mesage to be stored.
 		 */
 		Exception(const std::string& msg);
 
-		/** Destructor. 
+		/** Destructor.
 		 */
-		virtual ~Exception();
+		virtual ~Exception() throw();
 
 		/** Returns the error message.
 		 * @return The error message.
 		 */
-		std::string getMessage() const;
-		
+		virtual const char* what() const throw();
+
 		virtual const std::string& getTypeStr() const { static const std::string s = "Exception"; return s; }
 		virtual const std::string& getDescription() const { static const std::string s = "Generic FIFE exception"; return s; }
-
-	private:
-		// The error string.
-		std::string m_message;
 	};
 
 	#define FIFE_EXCEPTION_DECL(_name, _description) \
@@ -69,7 +66,7 @@
 		const std::string& getTypeStr() const { static const std::string s = #_name; return s; } \
 		const std::string& getDescription() const { static const std::string s = _description; return s; } \
 	}
-	
+
 	FIFE_EXCEPTION_DECL(SDLException, "SDL reported something bad");
 	FIFE_EXCEPTION_DECL(NotFound, "Something was searched, but not found");
 	FIFE_EXCEPTION_DECL(NotSet, "Something was not set correctly");
@@ -84,7 +81,7 @@
 	FIFE_EXCEPTION_DECL(EventException, "Error related to event functionality");
 	FIFE_EXCEPTION_DECL(GuiException, "Error related to gui functionality");
 	FIFE_EXCEPTION_DECL(InconsistencyDetected, "An inconsistency in FIFE internals was detected. Please report this is a FIFE Bug.");
-	
+
 	/** @bug The memory allocation in @c std::string might fail, resulting in terminate. */
 	FIFE_EXCEPTION_DECL(OutOfMemory, "Buy more ram ;)");
 
--- a/engine/core/vfs/vfs.cpp	Mon Dec 06 18:37:18 2010 +0000
+++ b/engine/core/vfs/vfs.cpp	Mon Dec 06 19:25:27 2010 +0000
@@ -85,7 +85,7 @@
 				m_usedfiles.insert(path);
 				return source;
 			} catch (const Exception& ex) {
-				FL_WARN(_log, LMsg(provider->getName()) << " thought it could load " << path << " but didn't succeed (" << ex.getMessage() << ")");
+				FL_WARN(_log, LMsg(provider->getName()) << " thought it could load " << path << " but didn't succeed (" << ex.what() << ")");
 				continue;
 			} catch (...) {
 				FL_WARN(_log, LMsg(provider->getName()) << " thought it could load " << path << " but didn't succeed (unkown exception)");
--- a/engine/core/view/renderers/blockinginforenderer.cpp	Mon Dec 06 18:37:18 2010 +0000
+++ b/engine/core/view/renderers/blockinginforenderer.cpp	Mon Dec 06 19:25:27 2010 +0000
@@ -78,7 +78,7 @@
 		RenderList::const_iterator instance_it = instances.begin();
 		for (;instance_it != instances.end(); ++instance_it) {
 			Instance* instance = (*instance_it)->instance;
-			if (!instance->getObject()->isBlocking()) {
+			if (!instance->getObject()->isBlocking() || !instance->isBlocking()) {
 				continue;
 			}
 			std::vector<ExactModelCoordinate> vertices;
--- a/engine/python/fife/extensions/pythonize.py	Mon Dec 06 18:37:18 2010 +0000
+++ b/engine/python/fife/extensions/pythonize.py	Mon Dec 06 19:25:27 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
@@ -46,7 +46,7 @@
 
 __all__ = ()
 
-fife.Exception.__str__ = fife.Exception.getMessage
+fife.Exception.__str__ = fife.Exception.what
 def _Color2Str(c):
 	return 'Color(%s)' % ','.join(map(str,(c.r,c.g,c.b,c.a)))
 fife.Color.__str__ = _Color2Str
--- a/engine/python/fife/extensions/savers.py	Mon Dec 06 18:37:18 2010 +0000
+++ b/engine/python/fife/extensions/savers.py	Mon Dec 06 19:25:27 2010 +0000
@@ -215,6 +215,13 @@
 				attr_vals[(None, 'id')] = inst.getId()
 				attr_names[(None, 'id')] = 'id'
 
+			if inst.isOverrideBlocking():
+				attr_vals[(None, 'override_blocking')] = str(int(inst.isOverrideBlocking()))
+				attr_names[(None, 'override_blocking')] = 'override_blocking'
+				if inst.getObject().isBlocking() is not inst.isBlocking():
+					attr_vals[(None, 'blocking')] = str(int(inst.isBlocking()))
+					attr_names[(None, 'blocking')] = 'blocking'
+
 			attrs = AttributesNSImpl(attr_vals, attr_names)
 			self.file.write(self.indent_level)
 			self.xmlout.startElementNS((None, 'i'), 'i', attrs)
--- a/engine/python/fife/extensions/serializers/xmlmap.py	Mon Dec 06 18:37:18 2010 +0000
+++ b/engine/python/fife/extensions/serializers/xmlmap.py	Mon Dec 06 19:25:27 2010 +0000
@@ -501,6 +501,13 @@
 				rotation = int(rotation)
 			inst.setRotation(rotation)
 
+			over_block = instance.get('override_blocking')
+			if over_block is not None:
+				inst.setOverrideBlocking(bool(over_block))
+				blocking = instance.get('blocking')
+				if blocking is not None:
+					inst.setBlocking(bool(int(blocking)))
+
 			fife.InstanceVisual.create(inst)
 			
 			stackpos = instance.get('stackpos')
--- a/engine/swigwrappers/python/fife.i.templ	Mon Dec 06 18:37:18 2010 +0000
+++ b/engine/swigwrappers/python/fife.i.templ	Mon Dec 06 19:25:27 2010 +0000
@@ -110,7 +110,7 @@
 #define _FIFE_EXC_HANDLER(_fife_exc_type, _converted_type) \
 	catch (FIFE::_fife_exc_type& _e) { \
 		PyErr_Clear(); \
-		SWIG_exception(_converted_type, _e.getMessage().c_str()); \
+		SWIG_exception(_converted_type, _e.what()); \
 	}
 
 #define _FIFE_DIRECTOR_EXC_HANDLER() \
--- a/tools/editor/gui/objectedit.xml	Mon Dec 06 18:37:18 2010 +0000
+++ b/tools/editor/gui/objectedit.xml	Mon Dec 06 19:25:27 2010 +0000
@@ -19,6 +19,7 @@
 	<HBox>
 		<Label text="Blocking:" min_size="45,20"/>
 		<TextBox text="0" name="object_blocking" min_size="20,20"/>
+    <Button name="object_blocking_toggle" text="toggle" max_size="50,20"/>
 
 		<Label text="Static:" min_size="45,20"/>
 		<TextBox text="0" name="object_static" min_size="20,20"/>
@@ -47,7 +48,7 @@
 		</HBox>
 	</VBox>
 
-	<Button name="change_data" text="Save rotation"/>
+	<Button name="change_data" text="Save object data"/>
 
 	<Label text="          Selected Instance" background_color="0,0,0" />
 
@@ -59,10 +60,20 @@
 		<Label text="Instance rot:" min_size="85,20"/>
 		<TextBox text="0" name="instance_rotation" min_size="30,20"/>
 	</HBox>
+  <HBox >
+    <Label text="Instance blocking:" min_size="85,20"/>
+    <TextBox text="0" name="instance_blocking" min_size="30,20"/>
+  </HBox>
 
 	<HBox>
 		<Button name="use_data" text="Set instance id"/>
 	</HBox>
+  <HBox>
+    <CheckBox name="override_blocking_toggle" text="Allowed to override blocking"/>
+  </HBox>
+  <HBox>
+    <Button name="instance_blocking_toggle" text="Toggle instance blocking"/>
+  </HBox>
 	<Spacer />
 
 	<Label text="          Animation viewer" background_color="0,0,0" />
--- a/tools/editor/plugins/ObjectEdit.py	Mon Dec 06 18:37:18 2010 +0000
+++ b/tools/editor/plugins/ObjectEdit.py	Mon Dec 06 19:25:27 2010 +0000
@@ -100,7 +100,8 @@
 		self._rotation = None
 		self._avail_rotations = []
 		self._namespace = None	
-		self._blocking = 0
+		self._object_blocking = 0
+		self._instance_blocking = 0
 		self._static = 0
 		self._object_id = None	
 		self._instance_id = None
@@ -213,6 +214,9 @@
 		self._gui_y_offset.capture(self.change_offset, "mouseWheelMovedUp")
 		self._gui_y_offset.capture(self.change_offset, "mouseWheelMovedDown")
 
+		self.container.findChild(name="object_blocking_toggle").capture(self.object_blocking_toggle, "mousePressed")
+		self.container.findChild(name="instance_blocking_toggle").capture(self.instance_blocking_toggle, "mousePressed")
+
 		self._gui_anim_panel_wrapper = self.container.findChild(name="animation_panel_wrapper")
 		self._gui_anim_panel = self._gui_anim_panel_wrapper.findChild(name="animation_panel")
 		
@@ -325,7 +329,12 @@
 		else:
 			x_offset = unicode( 0 )
 			y_offset = unicode( 0 )
-		
+
+		if self._instances[0].isOverrideBlocking():
+			self.container.findChild(name="override_blocking_toggle")._setMarked(True)
+		else:
+			self.container.findChild(name="override_blocking_toggle")._setMarked(False)
+
 		self.container.distributeInitialData({
 			'select_rotations' 	: self._avail_rotations,
 			'instance_id'		: unicode( self._instances[0].getId() ),
@@ -334,7 +343,8 @@
 			'y_offset'			: y_offset,
 			'instance_rotation' : unicode( self._instances[0].getRotation() ),
 			'object_namespace'	: unicode( self._namespace ),
-			'object_blocking'	: unicode( self._blocking ),
+			'instance_blocking'	: unicode( self._instance_blocking ),
+			'object_blocking'	: unicode( self._object_blocking ),
 			'object_static'		: unicode( self._static ),
 		})
 		
@@ -399,6 +409,54 @@
 		self.set_offset(x, y)
 		self.update_gui()
 
+	def object_blocking_toggle(self, event, widget):
+		""" widget callback: change the blocking of an instance 
+
+		@type	event:	object
+		@param	event:	FIFE mouseevent or keyevent
+		@type	widget:	object
+		@param	widget:	pychan widget
+		"""
+		self.check_override_blocking()
+		object = self._instances[0].getObject()
+		object_id = object.getId()
+		blocking = not object.isBlocking()
+		object.setBlocking(blocking)
+
+		instances = self._layer.getInstances()
+		for instance in instances:
+			object = instance.getObject()
+			if object.getId() == object_id:
+				instance.setBlocking(blocking)
+
+		self._object_blocking = int(blocking)
+		self._instance_blocking = int(self._instances[0].isBlocking())
+
+		self.update_gui()
+
+	def instance_blocking_toggle(self, event, widget):
+		""" widget callback: change the blocking of an instance 
+
+		@type	event:	object
+		@param	event:	FIFE mouseevent or keyevent
+		@type	widget:	object
+		@param	widget:	pychan widget
+		"""
+		self.check_override_blocking()
+		instance = self._instances[0]
+		instance.setBlocking(not instance.isBlocking())
+		self._instance_blocking = int(instance.isBlocking())
+
+		self.update_gui()
+
+	def check_override_blocking(self):
+		instance = self._instances[0]
+		marked = self.container.findChild(name="override_blocking_toggle")._isMarked()
+		if marked:
+			instance.setOverrideBlocking(True)
+		else:
+			instance.setOverrideBlocking(False)
+
 	def use_user_data(self):
 		"""
 			- takes the users values and applies them directly to the current ._instance
@@ -467,6 +525,9 @@
 				img_tag.attrib["y_offset"] = self._gui_yoffset_textfield._getText()
 				break
 
+		block = self.tree.getroot()
+		block.attrib["blocking"] = str(int(self._object_blocking))
+
 		xmlcontent = ET.tostring(self.tree.getroot())
 
 		# save xml data beneath the <?fife type="object"?> definition into the object file
@@ -576,8 +637,11 @@
 		self._rotation = angle
 		
 		if object.isBlocking():
-			self._blocking = 1
-			
+			self._object_blocking = 1
+
+		if instance.isBlocking():
+			self._instance_blocking = 1
+
 		if object.isStatic():
 			self._static = 1