changeset 348:48c38e92e2bd

Added Instance::setActionRuntime() as requested in Ticket #373
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Thu, 03 Sep 2009 23:09:57 +0000
parents 7fa5451d685d
children 493f7492f0ba
files engine/core/model/structures/instance.cpp engine/core/model/structures/instance.h engine/core/model/structures/instance.i
diffstat 3 files changed, 19 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/engine/core/model/structures/instance.cpp	Wed Sep 02 16:06:27 2009 +0000
+++ b/engine/core/model/structures/instance.cpp	Thu Sep 03 23:09:57 2009 +0000
@@ -54,6 +54,7 @@
 			m_speed(0),
 			m_repeating(false),
 			m_action_start_time(0),
+			m_action_offset_time(0),
 			m_prev_call_time(0),
 			m_pather_session_id(-1),
 			m_pather(pather),
@@ -77,6 +78,8 @@
 		bool m_repeating;
 		// action start time (ticks)
 		unsigned int m_action_start_time;
+		// action offset time (ticks) for resuming an action
+		unsigned int m_action_offset_time;
 		// ticks since last call
 		unsigned int m_prev_call_time;
 		// session id for pather
@@ -383,9 +386,11 @@
 				}
 			} else {
 				FL_DBG(_log, "action does not contain target for movement");
-				if (m_activity->m_timeprovider->getGameTime() - info->m_action_start_time >= info->m_action->getDuration()) {
+				if (m_activity->m_timeprovider->getGameTime() - info->m_action_start_time + info->m_action_offset_time >= info->m_action->getDuration()) {
 					if (info->m_repeating) {
 						info->m_action_start_time = m_activity->m_timeprovider->getGameTime();
+						// prock: offset no longer needed
+						info->m_action_offset_time = 0;
 					} else {
 						finalizeAction();
 					}
@@ -471,11 +476,15 @@
 		if (m_activity && m_activity->m_actioninfo) {
 			if(!m_activity->m_timeprovider)
 				bindTimeProvider();
-			return m_activity->m_timeprovider->getGameTime() - m_activity->m_actioninfo->m_action_start_time;
+			return m_activity->m_timeprovider->getGameTime() - m_activity->m_actioninfo->m_action_start_time + m_activity->m_actioninfo->m_action_offset_time;
 		}
 		return getRuntime();
 	}
 
+	void Instance::setActionRuntime(unsigned int time_offset) {
+		m_activity->m_actioninfo->m_action_offset_time = time_offset;
+	}
+
 	void Instance::bindTimeProvider() {
 		float multiplier = 1.0;
 		if (m_activity->m_timeprovider) {
--- a/engine/core/model/structures/instance.h	Wed Sep 02 16:06:27 2009 +0000
+++ b/engine/core/model/structures/instance.h	Thu Sep 03 23:09:57 2009 +0000
@@ -204,6 +204,13 @@
 		 */
 		unsigned int getActionRuntime();
 
+		/** Sets the time in milliseconds how long an action has been active
+		*  This was requested in Ticket #373.  This way the state
+		*  of the action can be saved and restored at a later time
+		*  @parm The action time offset that should be applied
+		*/
+		void setActionRuntime(unsigned int time_offset);
+
 		/** Performs given named action to the instance. While performing the action
 		 *  moves instance to given target with given speed
 		 *  @param action_name name of the action
--- a/engine/core/model/structures/instance.i	Wed Sep 02 16:06:27 2009 +0000
+++ b/engine/core/model/structures/instance.i	Thu Sep 03 23:09:57 2009 +0000
@@ -85,6 +85,7 @@
 		Location getFacingLocation();
 		Location& getFacingLocationRef();
 		unsigned int getActionRuntime();
+		void setActionRuntime(unsigned int time_offset);
 		void move(const std::string& action_name, const Location& target, const double speed);
 		void act(const std::string& action_name, const Location& direction, bool repeating=false);
 		void follow(const std::string& action_name, Instance* leader, const double speed);