Пример #1
0
///	\brief	register state in parent object and state machine
void CQHState::RegisterState()
{
	if( m_Name.IsEmpty() )
	{
		return;
	}

	IHashString *parentName = GetParentName();
	CQHStateMachineManager *amanager = GetManager();

	// Parent is either a state or state machine
	CQHState *parentState = amanager->GetState( parentName );
	if( parentState != NULL )
	{
		parentState->AddChildState( this );
		GetStateMachine()->AddGlobalState( this );
	}
	else
	{
		CQHStateMachine *parentStateMachine = amanager->GetStateMachine( parentName );
		if( parentStateMachine != NULL )
		{
			parentStateMachine->AddBaseState( this );
			parentStateMachine->AddGlobalState( this );
		}
		else
		{
			m_ToolBox->Log( LOGERROR, _T("Could not find parent object %s for state %s."), parentName->GetString(), GetName()->GetString() );
		}
	}
}
Пример #2
0
///////////////////////////////////////////////////////////////////////////////
//    UPDATE
//    The purpose of update is basically to check if any suspended scripts need
//    to be turned back on again!
//
//    Returns the next script in the list.  This assists in linked list traversal
//    where this script may delete it's next sibling.
///////////////////////////////////////////////////////////////////////////////
void CLuaScript::Update(float elapsedSec)
{
    m_fTime += elapsedSec;

	SINGLETONINSTANCE(CLuaManager)->SetScriptObjectName(GetName());
	SINGLETONINSTANCE(CLuaManager)->SetScriptObjectParentName(GetParentName());
    
    switch(m_State)
	{
	case LSS_WAITTIME:
		if (m_fTime >= m_fWaitTimestamp)
		{
			ResumeScript(0.0f);
		}
        break;
	case LSS_WAITFRAME:
		m_iWaitFrame--;
		if (m_iWaitFrame <= 0)
		{
			ResumeScript(0.0f);
		}
        break;
	case LSS_NOTLOADED:
		break;
//  case LSS_DONE:
    default :
		break;
	}

	SINGLETONINSTANCE(CLuaManager)->SetScriptObjectName(NULL);
	SINGLETONINSTANCE(CLuaManager)->SetScriptObjectParentName(NULL);
}
void CQHStateMachineActionHandler::DeInit()
{
	IComponent *amanagerComponent = m_ToolBox->GetComponent( GetManagerName() );
	CQHStateMachineManager *amanager = static_cast<CQHStateMachineManager*>( amanagerComponent );
	CQHStateMachineEvent *parentEvent = amanager->GetEvent( GetParentName() );

	if( parentEvent != NULL )
	{
		parentEvent->RemoveActionHandler( this );
	}
}
Пример #4
0
void CLuaScript::Init()
{
	int status;
	SCRIPTPARAMS sp;
	CHashString name(m_ScriptName.c_str());

	sp.fileName = &name;

	if (m_ScriptBody == NULL)
	{
		// get script based on the file name
		static DWORD msgHash_GetScript = CHashString(_T("GetScript")).GetUniqueID();
		if (m_EngineToolBox->SendMessage(msgHash_GetScript, sizeof(SCRIPTPARAMS), &sp) == MSG_HANDLED)
		{
			// extract script body
			m_ScriptBody = sp.scriptData;

			assert(m_pThreadState);
			assert(m_ScriptBody);

			status = luaL_loadbuffer(m_pThreadState, m_ScriptBody, strlen(m_ScriptBody), "Console");

			if (status)
			{
				// log error!
				FormatError();
				return;
			}
		}
	}		
	if (m_bAutoStart && m_ScriptBody != NULL)
	{
		SINGLETONINSTANCE(CLuaManager)->SetScriptObjectName(GetName());
		SINGLETONINSTANCE(CLuaManager)->SetScriptObjectParentName(GetParentName());
		status = lua_pcall(m_pThreadState, lua_gettop(m_pThreadState)-1, 0, 0);
		SINGLETONINSTANCE(CLuaManager)->SetScriptObjectName(NULL);
		SINGLETONINSTANCE(CLuaManager)->SetScriptObjectParentName(NULL);
		
		if (status)
		{
			// log error!
			FormatError();
			return;
		}
	}
}
void CLuaScriptVarList::Init()
{
	LoadSchema();
	
	CHashString PName = GetParentName();
	SETTABLEVALUEPARAMS stv;
	for( unsigned int i = 0; i < m_Variables.size(); i++ )
	{
		CHashString hsKey(m_Variables[i].GetName());
		CHashString hsValue(m_Variables[i].GetValueAsString());
		CHashString hsType(m_Variables[i].GetType());
		stv.TableKey = &hsKey;
		stv.TableValue = &hsValue;
		stv.TableType = &hsType;
		static DWORD msgHash_SetPropertyTableValue = CHashString("SetPropertyTableValue" ).GetUniqueID();
		m_ToolBox->SendMessage(msgHash_SetPropertyTableValue, sizeof(stv), &stv, &PName );
	}
}
Пример #6
0
CQHStateMachine *CQHState::GetStateMachine()
{
	if( m_StateMachine == NULL )
	{
		IHashString *parentName = GetParentName();
		CQHStateMachineManager *amanager = GetManager();
		CQHState *parentState = amanager->GetState( parentName );
		if( parentState != NULL )
		{
			m_StateMachine = parentState->GetStateMachine();
		}
		else
		{
			m_StateMachine = amanager->GetStateMachine( parentName );
			assert( m_StateMachine != NULL);
		}
	}

	return m_StateMachine;
}
Пример #7
0
///	\brief	unregister state from parent object and state machine
void CQHState::UnregisterState()
{
	if( m_Name.IsEmpty() )
	{
		return;
	}

	IHashString *parentName = GetParentName();
	CQHStateMachineManager *amanager = GetManager();
	CQHState *parentState = amanager->GetState( parentName );
	if( parentState != NULL )
	{
		parentState->RemoveChildState( this );
		GetStateMachine()->RemoveGlobalState( this );
	}
	else
	{
		CQHStateMachine *parentStateMachine = GetStateMachine();
		assert( parentStateMachine != NULL );
		parentStateMachine->RemoveBaseState( this );
		parentStateMachine->RemoveGlobalState( this );
	}
}
void CQHStateMachineActionHandler::Serialize( IArchive &ar )
{
	if( ar.IsReading() )
	{
		float fVersion;
		StdString tempStr;
		ar.Read( fVersion, _T("version") );
		if( fVersion > m_fCurrentVersion )
		{
			LPCTSTR fmt = _T("%s(%d): Unsupported version (%f) of state machine action handler");
			m_ToolBox->Log( LOGERROR, fmt, __FILE__, __LINE__, fVersion );
			return;
		}
		ar.Read( tempStr, _T("name") );
		m_szName.Init( tempStr );
		ar.Read( tempStr, _T("actionName") );
		m_szActionName.Init( tempStr );

		IComponent *amanagerComponent = m_ToolBox->GetComponent( GetManagerName() );
		CQHStateMachineManager *amanager = static_cast<CQHStateMachineManager*>( amanagerComponent );
		CQHStateMachineEvent *aparentEvent = amanager->GetEvent( GetParentName() );
		if( aparentEvent != NULL )
		{
			aparentEvent->AddActionHandler( this );
		}
		else
		{
			m_ToolBox->Log( LOGERROR, _T("Could not find parent event %s for action handler %s."), GetParentName()->GetString(), GetName()->GetString() );
		}
	}
	else
	{
		ar.Write( m_fCurrentVersion, _T("version") );
		ar.Write( m_szName.GetString(), _T("name") );
		ar.Write( m_szActionName.GetString(), _T("actionName") );
	}
}
bool COceanRenderObject::Update()
{
	static DWORD msgHash_RenderListToTexture = CHashString(_T("RenderListToTexture")).GetUniqueID();

	m_fCurrentTime = m_Timer->GetTime();
	float fTimeDelta = m_fCurrentTime - m_fPreviousAnimationTime;
	const float fMaxFramerate = 1.0f / 15.0f;

	if (fTimeDelta > fMaxFramerate)
	{
		// generate animated heightmap textures
		m_bRenderTargetActive = true;
		OBJECTLIST renderList;
		renderList.push_back( this );
		RENDERLISTTOTEXTUREPARAMS rlttp;
		rlttp.dwSortMethod = 0;
		rlttp.objList = &renderList;
		rlttp.Camera = &m_hszRenderTargetCameraName;

		m_fRenderingHeightmapAnimSpeed = 0.13f * 8.0f;
		rlttp.RenderTexture = m_pHeightmapRenderTarget0;
		rlttp.effectOverride = m_pHeightmapGenerationEffect;
		m_ToolBox->SendMessage(msgHash_RenderListToTexture, sizeof(rlttp), &rlttp );

		m_fRenderingHeightmapAnimSpeed = 0.19f * 8.0f;
		rlttp.RenderTexture = m_pHeightmapRenderTarget1;
		rlttp.effectOverride = m_pHeightmapGenerationEffect;
		m_ToolBox->SendMessage(msgHash_RenderListToTexture, sizeof(rlttp), &rlttp );

		m_bRenderTargetActive = false;
		m_fPreviousAnimationTime = m_fCurrentTime;
	}

	if( m_bTransformIsDirty == true )
	{
		static DWORD msgHash_GetGlobalTransform = CHashString(_T("GetGlobalTransform")).GetUniqueID();
		m_ToolBox->SendMessage(msgHash_GetGlobalTransform, sizeof(Matrix4x4), &m_bParentTransform, GetParentName() );
	}

	return true;
}
void CCoordinateToolPhysicsObject::GetParentTransform( NxMat34& transform )
{
	Matrix4x4 parentTrans;
	static DWORD msgHash_GetGlobalTransform = CHashString(_T("GetGlobalTransform")).GetUniqueID();
	m_ToolBox->SendMessage( msgHash_GetGlobalTransform, sizeof(parentTrans), &parentTrans, GetParentName(), &m_hsParentType );
	
	// remove scale and rotation
	parentTrans.SetRotation( EulerAngle() );

	transform.setColumnMajor44( parentTrans.GetMatrix() );
}
Пример #11
0
// D: returns true if the 2 agents are siblings
bool CDTTManagerAgent::IsSiblingOf(string sAgent1Path, string sAgent2Path) {
	return GetParentName(sAgent1Path) == GetParentName(sAgent2Path);
}
Пример #12
0
// D: returns true if sChildAgent is a child of aAgent
bool CDTTManagerAgent::IsChildOf(string sChildAgentPath, string sAgentPath) {
	return (GetParentName(sChildAgentPath) == sAgentPath);
}
Пример #13
0
// D: returns true if sParentAgent is the parent of sAgent
bool CDTTManagerAgent::IsParentOf(string sParentAgentPath, string sAgentPath) {
	return (GetParentName(sAgentPath) == sParentAgentPath);
}
Пример #14
0
/*
 * Initialize the daemon and database configuration.
 */
static int
dbupd_init(int argc, char **argv)
{
	sam_db_conf_t *db_conf;

	/* Check to make sure fsd started */
	if (strcmp(GetParentName(), SAM_FSD) != 0) {
#ifdef DEBUG
		is_daemon = FALSE;
#else
		fprintf(stderr, "%s may only be started from "SAM_FSD"\n",
		    program_name);
		return (-1);
#endif /* DEBUG */
	}

	/* Process args */
	if (argc < 2) {
		fprintf(stderr, "usage: "SAM_DBUPD" fsname\n");
		return (-1);
	}
	fs_name = argv[1];

	init_trace(is_daemon, TI_dbupd);

	/*
	 * Set up signal handling. Exit on SIGINT and SIGTERM.
	 * sam-fsd sends a SIGHUP on a configure -- ignore it.
	 */
	signal(SIGINT, dbupd_signal);
	signal(SIGTERM, dbupd_signal);
	signal(SIGHUP, SIG_IGN);

	/* Change to daemon directory */
	if (is_daemon) {
		snprintf(daemon_path, MAXPATHLEN, "%s/%s/%s/%s",
		    SAM_VARIABLE_PATH, "fsalogd", fs_name, program_name);
		MakeDir(daemon_path);
		if (chdir(daemon_path)) {
			/* cannot chdir to %s */
			SendCustMsg(HERE, 3038, daemon_path);
			exit(EXIT_FAILURE);
		}
	} else {
		daemon_path[0] = '\0';
	}

	/* Create inventory path */
	snprintf(fsa_path, MAXPATHLEN, "%s/%s",
	    FSA_DEFAULT_LOG_PATH, fs_name);

	/* Get database config and create context */
	db_conf = sam_db_conf_get(SAMDB_ACCESS_FILE, fs_name);
	if (db_conf == NULL) {
		/* Could not find fs_name in SAMDB_ACCESS_FILE */
		SendCustMsg(HERE, 26000, SAMDB_ACCESS_FILE, fs_name);
		return (-1);
	}

	/* Create database context */
	db_ctx = sam_db_context_conf_new(db_conf);
	if (db_ctx == NULL) {
		/* Could not create database context */
		SendCustMsg(HERE, 26001);
		sam_db_conf_free(db_conf);
		return (-1);
	}

	sam_db_conf_free(db_conf);
	return (0);
}
Пример #15
0
///////////////////////////////////////////////////////////////////////////////
// SeekToDirectory
///////////////////////////////////////////////////////////////////////////////
bool cDbDataSourceIter::SeekToDirectory( const cFCOName& parentName, bool bCreate )
{
	cDebug d( "cDbDataSourceIter::SeekToDirectory" );
	//
	// the first task is to ascend until we are in a directory that we can descend into to 
	// reach parentName...
	//
	cFCOName curParent = GetParentName();
	d.TraceDebug( _T("Entering... Seeking to %s (cwd = %s)\n"), parentName.AsString().c_str(), curParent.AsString().c_str() );
	int ascendCount ;
	switch( curParent.GetRelationship( parentName ) )
	{
		case cFCOName::REL_BELOW:
			//
			// we must ascend...
			//
			ascendCount = curParent.GetSize() - parentName.GetSize();
			d.TraceDetail( _T("\tAscending %d times...\n"), ascendCount );
			ASSERT( ascendCount > 0 );
			for( ; ascendCount > 0; ascendCount-- )
				Ascend();
			break;
		case cFCOName::REL_ABOVE:
			//
			// we are above the needed directory; nothing else to do here...
			//
			d.TraceDetail( _T("\tAbove; not ascending...\n") );
			break;
		case cFCOName::REL_EQUAL:
			//
			// we need to do nothing else here...
			//
			d.TraceDetail( _T("\tEqual; doing nothing...\n") );
			SeekBegin();
			return true;
		case cFCOName::REL_UNRELATED:
			//
			// we have to go all the way to the root...
			//
			d.TraceDetail( _T("\tUnrelated; seeking to root...\n") );
			SeekToRoot();
			break;
		default:
			// unreachable
			ASSERT( false );
			return false;
	}

	curParent = GetParentName();
	if( parentName.GetSize() == curParent.GetSize() )
		return true;
	//
	// now we will descend to the parent directory we are interested in...
	//
	cFCOName::iterator i(parentName);
	i.SeekTo( curParent.GetSize() );
	for(; (! i.Done()); i.Next() )
	{
		if( ! mDbIter.SeekTo( i.GetName() ) )
		{
			// this needs to be created!
			if( bCreate )
				mDbIter.CreateEntry( i.GetName() );
			else
				return false;
		}
		//
		// create the child array and descend
		//
		if( ! mDbIter.CanDescend() )
		{
			if( bCreate )
				mDbIter.CreateChildArray();
			else
				return false;
		}
		mDbIter.Descend();
	}
	return true;
}
Пример #16
0
CQHState *CQHState::GetParentState()
{
	CQHStateMachineManager *amanager = GetManager();
	CQHState *parentState = amanager->GetState( GetParentName() );
	return parentState;
}