[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [39768] branches/soc-2011-pepper/source/ gameengine: BGE Animations: Various changes to make code reviewers happy:

Mitchell Stokes mogurijin at gmail.com
Mon Aug 29 08:19:56 CEST 2011


Revision: 39768
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39768
Author:   moguri
Date:     2011-08-29 06:19:55 +0000 (Mon, 29 Aug 2011)
Log Message:
-----------
BGE Animations: Various changes to make code reviewers happy:
  * Naming/style changes
  * Taking advantage of switch statements
  * Removing unneeded NULL checks
  * etc

Modified Paths:
--------------
    branches/soc-2011-pepper/source/gameengine/Converter/BL_ActionActuator.cpp
    branches/soc-2011-pepper/source/gameengine/Converter/BL_ActionActuator.h
    branches/soc-2011-pepper/source/gameengine/Converter/BL_ArmatureObject.cpp
    branches/soc-2011-pepper/source/gameengine/Converter/BL_DeformableGameObject.cpp
    branches/soc-2011-pepper/source/gameengine/Ketsji/BL_ActionManager.cpp

Modified: branches/soc-2011-pepper/source/gameengine/Converter/BL_ActionActuator.cpp
===================================================================
--- branches/soc-2011-pepper/source/gameengine/Converter/BL_ActionActuator.cpp	2011-08-29 03:20:15 UTC (rev 39767)
+++ branches/soc-2011-pepper/source/gameengine/Converter/BL_ActionActuator.cpp	2011-08-29 06:19:55 UTC (rev 39768)
@@ -139,46 +139,51 @@
 {
 	bool bNegativeEvent = false;
 	bool bPositiveEvent = false;
-	bool use_continue = false;
+	bool bUseContinue = false;
 	KX_GameObject *obj = (KX_GameObject*)GetParent();
-	short play_mode = BL_Action::ACT_MODE_PLAY;
-	float start = m_startframe, end = m_endframe;
+	short playtype = BL_Action::ACT_MODE_PLAY;
+	float start = m_startframe;
+	float end = m_endframe;
 
 	// If we don't have an action, we can't do anything
 	if (!m_action)
 		return false;
 
-	// Convert playmode
-	if (m_playtype == ACT_ACTION_LOOP_END)
-		play_mode = BL_Action::ACT_MODE_LOOP;
-	else if (m_playtype == ACT_ACTION_LOOP_STOP)
-		play_mode = BL_Action::ACT_MODE_LOOP;
-	else if (m_playtype == ACT_ACTION_PINGPONG)
+	// Convert our playtype to one that BL_Action likes
+	switch(m_playtype)
 	{
-		// We handle ping pong ourselves to increase compabitility with the pre-Pepper actuator
-		play_mode = BL_Action::ACT_MODE_PLAY;
+		case ACT_ACTION_LOOP_END:
+		case ACT_ACTION_LOOP_STOP:
+			playtype = BL_Action::ACT_MODE_LOOP;
+			break;
+
+		case ACT_ACTION_PINGPONG:
+			// We handle ping pong ourselves to increase compabitility
+			// with files made prior to animation changes from GSoC 2011.
+			playtype = BL_Action::ACT_MODE_PLAY;
 		
-		if (m_flag & ACT_FLAG_REVERSE)
-		{
-			float tmp = start;
-			start = end;
-			end = tmp;
-			m_localtime = end;
-		}
-	}
-	else if (m_playtype == ACT_ACTION_FROM_PROP)
-	{
-		CValue* prop = GetParent()->GetProperty(m_propname);
+			if (m_flag & ACT_FLAG_REVERSE)
+			{
+				m_localtime = start;
+				start = end;
+				end = m_localtime;
+			}
 
-		play_mode = BL_Action::ACT_MODE_PLAY;
-		start = end = prop->GetNumber();
+			break;
+		case ACT_ACTION_FROM_PROP:
+			CValue* prop = GetParent()->GetProperty(m_propname);
+
+			playtype = BL_Action::ACT_MODE_PLAY;
+			start = end = prop->GetNumber();
+
+			break;
 	}
 
 	// Continue only really makes sense for play stop and flipper. All other modes go until they are complete.
 	if (m_flag & ACT_FLAG_CONTINUE &&
 		(m_playtype == ACT_ACTION_LOOP_STOP ||
 		m_playtype == ACT_ACTION_FLIPPER))
-		use_continue = true;
+		bUseContinue = true;
 	
 	
 	// Handle events
@@ -189,15 +194,15 @@
 		RemoveAllEvents();
 	}
 
-	if (use_continue && m_flag & ACT_FLAG_ACTIVE)
+	if (bUseContinue && (m_flag & ACT_FLAG_ACTIVE))
 		m_localtime = obj->GetActionFrame(m_layer);
 	
 	if (bPositiveEvent)
 	{
-		if (obj->PlayAction(m_action->id.name+2, start, end, m_layer, m_priority, m_blendin, play_mode, m_layer_weight, m_ipo_flags))
+		if (obj->PlayAction(m_action->id.name+2, start, end, m_layer, m_priority, m_blendin, playtype, m_layer_weight, m_ipo_flags))
 		{
 			m_flag |= ACT_FLAG_ACTIVE;
-			if (use_continue)
+			if (bUseContinue)
 				obj->SetActionFrame(m_layer, m_localtime);
 
 			if (m_playtype == ACT_ACTION_PLAY)
@@ -225,33 +230,33 @@
 		if (m_localtime < min(m_startframe, m_endframe) || m_localtime > max(m_startframe, m_endframe))
 			m_localtime = m_startframe;
 
-		if (m_playtype == ACT_ACTION_LOOP_STOP)
+		switch(m_playtype)
 		{
-			obj->StopAction(m_layer); // Stop the action after getting the frame
+			case ACT_ACTION_LOOP_STOP:
+				obj->StopAction(m_layer); // Stop the action after getting the frame
 
-			// We're done
-			m_flag &= ~ACT_FLAG_ACTIVE;
-			return false;
-		}
-		else if (m_playtype == ACT_ACTION_LOOP_END || m_playtype == ACT_ACTION_PINGPONG)
-		{
-			// Convert into a play and let it finish
-			obj->SetPlayMode(m_layer, BL_Action::ACT_MODE_PLAY);
+				// We're done
+				m_flag &= ~ACT_FLAG_ACTIVE;
+				return false;
+			case ACT_ACTION_PINGPONG:
+				m_flag ^= ACT_FLAG_REVERSE;
+				// Now fallthrough to LOOP_END code
+			case ACT_ACTION_LOOP_END:
+				// Convert into a play and let it finish
+				obj->SetPlayMode(m_layer, BL_Action::ACT_MODE_PLAY);
 
-			m_flag |= ACT_FLAG_PLAY_END;
+				m_flag |= ACT_FLAG_PLAY_END;
+				break;
+	
+			case ACT_ACTION_FLIPPER:
+				// Convert into a play action and play back to the beginning
+				end = start;
+				start = obj->GetActionFrame(m_layer);
+				obj->PlayAction(m_action->id.name+2, start, end, m_layer, m_priority, 0, BL_Action::ACT_MODE_PLAY, m_layer_weight, m_ipo_flags);
 
-			if (m_playtype == ACT_ACTION_PINGPONG)
-				m_flag ^= ACT_FLAG_REVERSE;
+				m_flag |= ACT_FLAG_PLAY_END;
+				break;
 		}
-		else if (m_playtype == ACT_ACTION_FLIPPER)
-		{
-			// Convert into a play action and play back to the beginning
-			end = start;
-			start = obj->GetActionFrame(m_layer);
-			obj->PlayAction(m_action->id.name+2, start, end, m_layer, m_priority, 0, BL_Action::ACT_MODE_PLAY, m_layer_weight, m_ipo_flags);
-
-			m_flag |= ACT_FLAG_PLAY_END;
-		}
 	}
 
 	// Handle a frame property if it's defined

Modified: branches/soc-2011-pepper/source/gameengine/Converter/BL_ActionActuator.h
===================================================================
--- branches/soc-2011-pepper/source/gameengine/Converter/BL_ActionActuator.h	2011-08-29 03:20:15 UTC (rev 39767)
+++ branches/soc-2011-pepper/source/gameengine/Converter/BL_ActionActuator.h	2011-08-29 06:19:55 UTC (rev 39768)
@@ -149,7 +149,7 @@
 	ACT_FLAG_KEYUP		= 1<<2,
 	ACT_FLAG_ACTIVE		= 1<<3,
 	ACT_FLAG_CONTINUE	= 1<<4,
-	ACT_FLAG_PLAY_END	= 1<<5
+	ACT_FLAG_PLAY_END	= 1<<5,
 
 };
 

Modified: branches/soc-2011-pepper/source/gameengine/Converter/BL_ArmatureObject.cpp
===================================================================
--- branches/soc-2011-pepper/source/gameengine/Converter/BL_ArmatureObject.cpp	2011-08-29 03:20:15 UTC (rev 39767)
+++ branches/soc-2011-pepper/source/gameengine/Converter/BL_ArmatureObject.cpp	2011-08-29 06:19:55 UTC (rev 39768)
@@ -138,19 +138,22 @@
 
 /* Only allowed for Poses with identical channels */
 void game_blend_poses(bPose *dst, bPose *src, float srcweight/*, short mode*/)
-{	
+{
+	short mode= ACTSTRIPMODE_BLEND;
+	
 	bPoseChannel *dchan;
 	const bPoseChannel *schan;
 	bConstraint *dcon, *scon;
 	float dstweight;
 	int i;
-	short mode = ACTSTRIPMODE_BLEND;
 
 	switch (mode){
 	case ACTSTRIPMODE_BLEND:
 		dstweight = 1.0F - srcweight;
 		break;
 	case ACTSTRIPMODE_ADD:
+		dstweight = 1.0F;
+		break;
 	default :
 		dstweight = 1.0F;
 	}

Modified: branches/soc-2011-pepper/source/gameengine/Converter/BL_DeformableGameObject.cpp
===================================================================
--- branches/soc-2011-pepper/source/gameengine/Converter/BL_DeformableGameObject.cpp	2011-08-29 03:20:15 UTC (rev 39767)
+++ branches/soc-2011-pepper/source/gameengine/Converter/BL_DeformableGameObject.cpp	2011-08-29 06:19:55 UTC (rev 39768)
@@ -92,10 +92,11 @@
 	{
 		// this check is normally superfluous: a shape deformer can only be created if the mesh
 		// has relative keys
-		if (shape_deformer->GetKey() && shape_deformer->GetKey()->type==KEY_RELATIVE) 
+		Key* key = shape_deformer->GetKey();
+		if (key && key->type==KEY_RELATIVE) 
 		{
 			KeyBlock *kb;
-			for (kb = (KeyBlock*)shape_deformer->GetKey()->block.first; kb; kb = (KeyBlock*)kb->next)
+			for (kb = (KeyBlock*)key->block.first; kb; kb = (KeyBlock*)kb->next)
 			{
 				shape.push_back(kb->curval);
 			}

Modified: branches/soc-2011-pepper/source/gameengine/Ketsji/BL_ActionManager.cpp
===================================================================
--- branches/soc-2011-pepper/source/gameengine/Ketsji/BL_ActionManager.cpp	2011-08-29 03:20:15 UTC (rev 39767)
+++ branches/soc-2011-pepper/source/gameengine/Ketsji/BL_ActionManager.cpp	2011-08-29 06:19:55 UTC (rev 39768)
@@ -37,42 +37,36 @@
 BL_ActionManager::~BL_ActionManager()
 {
 	for (int i=0; i<MAX_ACTION_LAYERS; ++i)
-		if (m_layers[i])
-			delete m_layers[i];
+		delete m_layers[i];
 }
 
 float BL_ActionManager::GetActionFrame(short layer)
 {
-	if (m_layers[layer])
-		return m_layers[layer]->GetFrame();
+	return m_layers[layer]->GetFrame();
 
 	return 0.f;
 }
 
 void BL_ActionManager::SetActionFrame(short layer, float frame)
 {
-	if (m_layers[layer])
-		m_layers[layer]->SetFrame(frame);
+	m_layers[layer]->SetFrame(frame);
 }
 
 struct bAction *BL_ActionManager::GetCurrentAction(short layer)
 {
-	if (m_layers[layer])
-		return m_layers[layer]->GetAction();
+	return m_layers[layer]->GetAction();
 	
 	return 0;
 }
 
 void BL_ActionManager::SetPlayMode(short layer, short mode)
 {
-	if (m_layers[layer])
-		m_layers[layer]->SetPlayMode(mode);
+	m_layers[layer]->SetPlayMode(mode);
 }
 
 void BL_ActionManager::SetTimes(short layer, float start, float end)
 {
-	if (m_layers[layer])
-		m_layers[layer]->SetTimes(start, end);
+	m_layers[layer]->SetTimes(start, end);
 }
 
 bool BL_ActionManager::PlayAction(const char* name,
@@ -99,8 +93,7 @@
 
 bool BL_ActionManager::IsActionDone(short layer)
 {
-	if (m_layers[layer])
-		return m_layers[layer]->IsDone();
+	return m_layers[layer]->IsDone();
 
 	return true;
 }




More information about the Bf-blender-cvs mailing list