// Fills with current contents of m_workingData
	void DoAddToArray( IAUDynArray<ObjectId>& objects ) const
	{
		size_t count = m_workingData.size();
		size_t origCount = objects.Size();
		objects.Resize(origCount + count);
		for (size_t i=0; i < count; ++i)
		{
			objects[i+origCount] = m_workingData[i]->GetObjectId();
		}
	}
void EntitySystem::GetAll(IAUDynArray<AUEntityId> &entities) const
{
	entities.Resize(m_Entities.size());
	TCESEntities::const_iterator it = m_Entities.begin();
	TCESEntities::const_iterator itEnd = m_Entities.end();
	for(int i = 0; it != itEnd; ++it, ++i)
	{
		entities[i] = it->second->m_id;
	}
}
void ObjectFactorySystem::GetAll(IAUDynArray<IObjectConstructor*> &constructors) const
{
    constructors.Resize(m_Constructors.size());
    std::vector<IObjectConstructor*>::const_iterator it = m_Constructors.begin();
    std::vector<IObjectConstructor*>::const_iterator itEnd = m_Constructors.end();
    for(int i = 0; it != itEnd; ++it, ++i)
    {
        constructors[i] = *it;
    }
}
void ObjectFactorySystem::AddConstructors( IAUDynArray<IObjectConstructor*> &constructors )
{
    if( constructors.Size() == 0 )
    {
        m_pLogger->LogInfo( "ObjectFactorySystem::AddConstructors() called with no constructors." );
        return;
    }

    if( m_HistoryCurrentLocation )
    {
        m_pLogger->LogInfo( "Need to fast forward undo system to current state of source code." );
        while( RedoObjectConstructorChange() ) {}
    }

    ProtectedObjectSwapper swapper;
    swapper.m_ConstructorsToAdd.assign( &constructors[0], &constructors[constructors.Size() - 1] + 1 );
    swapper.m_ConstructorsOld = m_Constructors;
    swapper.m_pLogger = m_pLogger;
    swapper.m_pObjectFactorySystem = this;
    swapper.m_bTestSerialization = m_bTestSerialization;

    swapper.m_ProtectedPhase = PHASE_NONE;
    // we use the protected function to do all serialization
    m_pRuntimeObjectSystem->TryProtectedFunction( &swapper );

    CompleteConstructorSwap( swapper );

    if( m_HistoryMaxSize )
    {
        HistoryPoint historyPoint = { swapper.m_ConstructorsReplaced, swapper.m_ConstructorsToAdd };
        m_HistoryConstructors.push_back( historyPoint );
        if( (int)m_HistoryConstructors.size() > m_HistoryMaxSize )
        {
            m_HistoryConstructors.erase( m_HistoryConstructors.begin() );
        }
    }
}
	virtual void GetPerceived( const IGameObject* pPerceiver, IAUDynArray<ObjectId>& objects ) const
	{
		objects.Clear();
		AUVec3f center = pPerceiver->GetEntity()->GetPosition();
		m_workingData.clear();

		// Fill working array with results
		for (int i=0; i<EGO_COUNT; ++i)
		{
			float radius = m_pGlobalParameters->go[pPerceiver->GetGameObjectType()].perceptionDist[i];

			DoGetPerceived( m_Objects[i], pPerceiver, center, radius );
		}
		
		DoAddToArray(objects);
	}
	virtual void GetAll( EGameObject type, IAUDynArray<ObjectId> &objects ) const
	{
		AU_ASSERT(type < EGO_COUNT);
		if (type < EGO_COUNT)
		{
			size_t count = m_GameObjects[type].size();

			objects.Resize(count);
			TGameObjects::const_iterator it = m_GameObjects[type].begin();
			TGameObjects::const_iterator itEnd = m_GameObjects[type].end();
			for(int i = 0; it != itEnd; ++it, ++i)
			{
				objects[i] = (*it)->GetObjectId();
			}
		}	
	}
void RuntimeObjectSystem::OnFileChange(const IAUDynArray<const char*>& filelist)
{
	if( !m_bAutoCompile )
	{
		return;
	}

	std::vector<BuildTool::FileToBuild>* pBuildFileList = &m_BuildFileList;
	if( m_bCompiling )
	{
		pBuildFileList = &m_PendingBuildFileList;
	}


	m_pCompilerLogger->LogInfo("FileChangeNotifier triggered recompile of files:\n");
	for( size_t i = 0; i < filelist.Size(); ++ i )
	{
		BuildTool::FileToBuild fileToBuild(filelist[i]);
		if( fileToBuild.filePath.Extension() != ".h") //TODO: change to check for .cpp and .c as could have .inc files etc.?
		{
			pBuildFileList->push_back( fileToBuild );
		}
		else
		{
			TFileToFileEqualRange range = m_RuntimeIncludeMap.equal_range( fileToBuild.filePath );
			for(TFileToFileIterator it=range.first; it!=range.second; ++it)
			{
				BuildTool::FileToBuild fileToBuildFromIncludes( (*it).second, true );
				pBuildFileList->push_back( fileToBuildFromIncludes );
			}
		}
	}

	if( !m_bCompiling )
	{
		StartRecompile();
	}
}
	virtual void GetPerceived( const IGameObject* pPerceiver, EGameObject perceivedType, IAUDynArray<ObjectId>& objects ) const
	{
		objects.Clear();
		DoAddPerceived( pPerceiver, perceivedType, objects );
	}
Пример #9
0
void RuntimeObjectSystem::SetupRuntimeFileTracking(const IAUDynArray<IObjectConstructor*>& constructors_)
{
#ifndef RCCPPOFF
	// for optimization purposes we skip some actions when running for the first time (i.e. no previous constructors)
	static bool bFirstTime = true;

	for (size_t i = 0, iMax = constructors_.Size(); i < iMax; ++i)
	{
		const char* pFilename = constructors_[i]->GetFileName(); // GetFileName returns full path including GetCompiledPath()
		if( !pFilename )
		{
			continue;
		}
		Path filePath = pFilename;
        filePath = filePath.GetCleanPath();
        filePath = FindFile( filePath );

        unsigned short projectId = constructors_[ i ]->GetProjectId();
        ProjectSettings& project = GetProject( projectId );
        AddToRuntimeFileList( filePath.c_str( ), projectId );

		if( !bFirstTime )
		{
 			//remove old include file mappings for this file
            TFileToFilesIterator itrCurr = project.m_RuntimeIncludeMap.begin( );
            while( itrCurr != project.m_RuntimeIncludeMap.end( ) )
			{
				if( itrCurr->second == filePath )
				{
                    TFileToFilesIterator itrErase = itrCurr;
                    ++itrCurr;
                    project.m_RuntimeIncludeMap.erase( itrErase );
				}
				else
				{
					++itrCurr;
				}
			}

            //remove previous link libraries for this file
            project.m_RuntimeLinkLibraryMap.erase( filePath );

            //remove previous source dependencies
            project.m_RuntimeSourceDependencyMap.erase( filePath );
		}

        //we need the compile path for some platforms where the __FILE__ path is relative to the compile path
		FileSystemUtils::Path compileDir = constructors_[i]->GetCompiledPath();

		//add include file mappings
		for (size_t includeNum = 0; includeNum <= constructors_[i]->GetMaxNumIncludeFiles(); ++includeNum)
		{
			const char* pIncludeFile = constructors_[i]->GetIncludeFile(includeNum);
			if( pIncludeFile )
			{
                FileSystemUtils::Path pathInc = compileDir / pIncludeFile;
                pathInc = FindFile( pathInc.GetCleanPath() );
				TFileToFilePair includePathPair;
				includePathPair.first = pathInc;
				includePathPair.second = filePath;
                AddToRuntimeFileList( pathInc.c_str(), projectId );
                project.m_RuntimeIncludeMap.insert( includePathPair );
			}
		}
            

 		//add link library file mappings
		for (size_t linklibraryNum = 0; linklibraryNum <= constructors_[i]->GetMaxNumLinkLibraries(); ++linklibraryNum)
		{
			const char* pLinkLibrary = constructors_[i]->GetLinkLibrary(linklibraryNum);
			if( pLinkLibrary )
			{
                // We do not use FindFiles for Linked Libraries as these are searched for on
                // the library paths, which are themselves searched for.
				TFileToFilePair linklibraryPathPair;
				linklibraryPathPair.first = filePath;
				linklibraryPathPair.second = pLinkLibrary;
                project.m_RuntimeLinkLibraryMap.insert( linklibraryPathPair );
			}
		}

        //add source dependency file mappings
		for (size_t num = 0; num <= constructors_[i]->GetMaxNumSourceDependencies(); ++num)
		{
			SourceDependencyInfo sourceDependency = constructors_[i]->GetSourceDependency(num);
			FileSystemUtils::Path pathInc[2];	// array of potential include files for later checks
			if( sourceDependency.filename )
			{
				FileSystemUtils::Path pathSrc;
				if( sourceDependency.relativeToPath )
				{
					pathSrc = sourceDependency.relativeToPath;
					if( pathSrc.HasExtension() )
					{
						pathInc[1] = compileDir / pathSrc;
						pathSrc =  compileDir / pathSrc.ParentPath() / sourceDependency.filename;
					}
					else
					{
						pathSrc =  compileDir / pathSrc / sourceDependency.filename;
					}
				}
				else
				{
					pathSrc = compileDir / sourceDependency.filename;
				}
                pathSrc.ToOSCanonicalCase();
                pathSrc = pathSrc.DelimitersToOSDefault();
                pathSrc = pathSrc.GetCleanPath();
				pathInc[0] = pathSrc;
				if( sourceDependency.extension )
				{
					pathSrc.ReplaceExtension( sourceDependency.extension );
				}
				pathSrc = FindFile( pathSrc.GetCleanPath() );
				TFileToFilePair sourcePathPair;
				sourcePathPair.first = filePath;
				sourcePathPair.second = pathSrc;
                project.m_RuntimeSourceDependencyMap.insert( sourcePathPair );
                
                // if the include file with a source dependancy is logged as an runtime include, then we mark this .cpp as compile dependencies on change
				for( int inc=0; inc<2; ++inc )
				{
					TFileToFilesEqualRange range = project.m_RuntimeIncludeMap.equal_range( pathInc[inc] );
					if( range.first != range.second )
					{
						// add source file to runtime file list
						AddToRuntimeFileList( pathSrc.c_str(), projectId );

						// also add this as a source dependency, so it gets force compiled on change of header (and not just compiled)
						TFileToFilePair includePathPair;
						includePathPair.first = pathInc[inc];
						includePathPair.second = pathSrc;
						project.m_RuntimeIncludeMap.insert( includePathPair );
					}
				}
			}
		}
	}

    bFirstTime = false;
#endif
}
Пример #10
0
void RuntimeObjectSystem::OnFileChange(const IAUDynArray<const char*>& filelist)
{
	if( !m_bAutoCompile )
	{
		return;
	}

    for( unsigned short proj = 0; proj < m_Projects.size(); ++proj )
    {

        std::vector<BuildTool::FileToBuild>* pBuildFileList = &m_Projects[ proj ].m_BuildFileList;
        if( m_bCompiling )
        {
            pBuildFileList = &m_Projects[ proj ].m_PendingBuildFileList;
        }


        if (m_pCompilerLogger) { m_pCompilerLogger->LogInfo( "FileChangeNotifier triggered recompile with changes to:\n" ); }
        for( size_t i = 0; i < filelist.Size(); ++i )
        {
            // check this file is in our project list
            TFileList::iterator it = std::find( m_Projects[ proj ].m_RuntimeFileList.begin( ), m_Projects[ proj ].m_RuntimeFileList.end( ), filelist[i] );
            if( it == m_Projects[ proj ].m_RuntimeFileList.end() )
            {
                continue;
            }

            if (m_pCompilerLogger) { m_pCompilerLogger->LogInfo( "    File %s\n", filelist[ i ] ); }
            BuildTool::FileToBuild fileToBuild( filelist[ i ] );

            bool bFindIncludeDependencies = true;  // if this is a header or a source dependency need to find include dependencies
            bool bForceIncludeDependencies = true;
            if( fileToBuild.filePath.Extension() != ".h" ) //TODO: change to check for .cpp and .c as could have .inc files etc.?
            {
                bFindIncludeDependencies = false;
                pBuildFileList->push_back( fileToBuild );

                // file may be a source dependency, check
                TFileToFilesIterator itrCurr = m_Projects[ proj ].m_RuntimeSourceDependencyMap.begin( );
                while( itrCurr != m_Projects[ proj ].m_RuntimeSourceDependencyMap.end( ) )
                {
                    if( itrCurr->second == fileToBuild.filePath )
                    {
                        BuildTool::FileToBuild fileToBuild( itrCurr->first );
                        pBuildFileList->push_back( fileToBuild );
                    }
                    ++itrCurr;
                }
           }

            if( bFindIncludeDependencies )
            {
                TFileToFilesEqualRange range = m_Projects[ proj ].m_RuntimeIncludeMap.equal_range( fileToBuild.filePath );
                for( TFileToFilesIterator it = range.first; it != range.second; ++it )
                {
                    BuildTool::FileToBuild fileToBuildFromIncludes( ( *it ).second, bForceIncludeDependencies );
                    pBuildFileList->push_back( fileToBuildFromIncludes );
                }
            }
        }
    }

	if( !m_bCompiling )
	{
		StartRecompile();
	}
}