示例#1
0
        public static void Init()
        {
            if (_Instance != null)
            {
                return;
            }

            GameObject go = GameObject.Find(DATA_MAPPING_NAME);

#if UNITY_EDITOR
            if (go == null)
            {
                FCgDebug.LogError("MCgDataMapping.Init: Failed to find GameObject with name: " + DATA_MAPPING_NAME);
            }
#endif // #if UNITY_EDITOR

            _Instance = go.GetComponent <MCgDataMapping>();

#if UNITY_EDITOR
            if (_Instance == null)
            {
                FCgDebug.LogError("MCgDataMapping.Init: GameObject: " + DATA_MAPPING_NAME + " does not have a component of type MCgDataMapping.");
            }
#endif // #if UNITY_EDITOR

            _Instance.Init_Internal();
        }
示例#2
0
        public bool DeAllocate(EnumType e, int index)
        {
            Dictionary <int, ObjectType> pool = null;

            if (!ActiveObjects.TryGetValue(e, out pool))
            {
                FCgDebug.LogError(this.GetType().Name + ".DeAllocate: Object of Type: " + EnumTypeToString(e) + " at " + index + " is already deallocated.");
                return(false);
            }

            if (pool.ContainsKey(index))
            {
                ObjectType o = pool[index];

                LogTransaction();

                o.DeAllocate <EnumType, ObjectType, PayloadType, CacheType>();
                ActiveObjects[e].Remove(index);

                // OnDeAllocate+Event
                return(true);
            }
            FCgDebug.LogError(this.GetType().Name + ".DeAllocate: Object of Type: " + EnumTypeToString(e) + " at " + index + " is already deallocated.");
            return(false);
        }
示例#3
0
        protected ObjectType Allocate(EnumType e)
        {
            List <ObjectType> pool = null;

            Pools.TryGetValue(e, out pool);

            int size = EMPTY;

            PoolSizes.TryGetValue(e, out size);

            if (!PoolSizes.TryGetValue(e, out size))
            {
                FCgDebug.LogError(this.GetType().Name + ".Allocate: Pool: " + EnumTypeToString(e) + " is exhausted.");
                return(null);
            }

            for (int i = 0; i < size; ++i)
            {
                int index = PoolIndices[e];
                index          = (index + 1) % size;
                PoolIndices[e] = index;
                ObjectType o = pool[index];

                if (!o.GetCache <EnumType, ObjectType, PayloadType, CacheType>().bAllocated)
                {
                    o.GetCache <EnumType, ObjectType, PayloadType, CacheType>().bAllocated = true;
                    return(o);
                }
            }
            FCgDebug.LogError(this.GetType().Name + ".Allocate: Pool: " + EnumTypeToString(e) + " is exhausted.");
            return(null);
        }
示例#4
0
        protected void OnFinishedLoadingAssetReference(AsyncOperation operation)
        {
            ResourceRequest request = (ResourceRequest)operation;

            List <string> assetReferences = AssetReferencesQueue[FIRST];
            string        assetReference  = assetReferences[AssetReferencesLoadedCount];

            if (request.asset == null)
            {
                FCgDebug.LogError("FCgManager_Loading.OnFinishedLoadingAssetReference: Failed to load asset at: " + assetReference);
                return;
            }

            LoadedAssets.Add(request.asset);

            int lastCount = AssetReferencesLoadedCount;

            ++AssetReferencesLoadedCount;

            // Get Memory loaded and the time it took
            int   bytes     = (int)Profiler.GetRuntimeMemorySizeLong(request.asset);
            float kilobytes = FCgCommon.BytesToKilobytes(bytes);
            float megabytes = FCgCommon.BytesToMegabytes(bytes);

            ResourceSizeLoaded.Bytes     += bytes;
            ResourceSizeLoaded.Kilobytes += kilobytes;
            ResourceSizeLoaded.Megabytes += megabytes;

            float currentTime = Time.realtimeSinceStartup;
            float loadingTime = currentTime - LoadingStartTime;

            if (LogLoading.Log())
            {
                FCgDebug.Log("FCsManager_Loading.OnFinishedLoadingAssetReference: Finished Loading " + assetReference + ". " + megabytes + " mb (" + kilobytes + " kb, " + bytes + " bytes) in " + loadingTime + " seconds.");
            }

            // Broadcast the event to anyone listening
            AssetReferenceLoadedCache.Reference      = assetReference;
            AssetReferenceLoadedCache.Count          = lastCount;
            AssetReferenceLoadedCache.Size.Bytes     = bytes;
            AssetReferenceLoadedCache.Size.Kilobytes = kilobytes;
            AssetReferenceLoadedCache.Size.Megabytes = megabytes;
            AssetReferenceLoadedCache.Time           = loadingTime;

            OnFinishedLoadingAssetReference_Event.Broadcast(AssetReferenceLoadedCache);
            // FirstToLast, Queue the NEXT Asset for Async Load
            if (AssetReferencesLoadedCount < assetReferences.Capacity)
            {
                if (LogLoading.Log())
                {
                    FCgDebug.Log("FCsManager_Loading.OnFinishedLoadingAssetReference: Requesting Load of " + assetReferences[AssetReferencesLoadedCount]);
                }
                OnStartLoadingAssetReference_Event.Broadcast(assetReferences[AssetReferencesLoadedCount]);

                ResourceRequest r = Resources.LoadAsync(assetReferences[AssetReferencesLoadedCount]);
                r.completed += OnFinishedLoadingAssetReference;
            }
            LoadingStartTime = currentTime;
        }
示例#5
0
        protected void OnFinishedLoadingAssetReference_Bulk(AsyncOperation operation)
        {
            ResourceRequest request = (ResourceRequest)operation;

#if UNITY_EDITOR
            string assetReference = AssetDatabase.GetAssetPath(request.asset);
#endif // #if UNITY_EDITOR

            if (request.asset == null)
            {
#if UNITY_EDITOR
                FCgDebug.LogError("FCgManager_Loading.OnFinishedLoadingAssetReference_Bulk: Failed to load asset at: " + assetReference);
#else
                FCgDebug.LogError("FCgManager_Loading.OnFinishedLoadingAssetReference_Bulk: Failed to load asset");
#endif // #if UNITY_EDITOR
                return;
            }

            LoadedAssets.Add(request.asset);

            int lastCount = AssetReferencesLoadedCount;

            ++AssetReferencesLoadedCount;

            // Get Memory loaded and the time it took
            int   bytes     = (int)Profiler.GetRuntimeMemorySizeLong(request.asset);
            float kilobytes = FCgCommon.BytesToKilobytes(bytes);
            float megabytes = FCgCommon.BytesToMegabytes(bytes);

            ResourceSizeLoaded.Bytes     += bytes;
            ResourceSizeLoaded.Kilobytes += kilobytes;
            ResourceSizeLoaded.Megabytes += megabytes;

            float currentTime = Time.realtimeSinceStartup;
            float loadingTime = currentTime - LoadingStartTime;

            if (LogLoading.Log())
            {
#if UNITY_EDITOR
                FCgDebug.Log("FCsManager_Loading.OnFinishedLoadingAssetReference_Bulk: Finished Loading " + assetReference + ". " + megabytes + " mb (" + kilobytes + " kb, " + bytes + " bytes).");
#else
                FCgDebug.Log("FCsManager_Loading.OnFinishedLoadingAssetReference_Bulk: Finished Loading an asset. " + megabytes + " mb (" + kilobytes + " kb, " + bytes + " bytes).");
#endif // #if UNITY_EDITOR
            }

#if UNITY_EDITOR
            // Broadcast the event to anyone listening
            AssetReferenceLoadedCache.Reference      = assetReference;
            AssetReferenceLoadedCache.Count          = lastCount;
            AssetReferenceLoadedCache.Size.Bytes     = bytes;
            AssetReferenceLoadedCache.Size.Kilobytes = kilobytes;
            AssetReferenceLoadedCache.Size.Megabytes = megabytes;
            AssetReferenceLoadedCache.Time           = loadingTime;

            OnFinishedLoadingAssetReference_Event.Broadcast(AssetReferenceLoadedCache);
#endif // #if UNITY_EDITOR
        }
示例#6
0
        public void Init()
        {
            // TODO: Search for the Prefab rather than the Scene
            EmptyGameObject = GameObject.Find(EMPTY_GAME_OBJECT_NAME);
#if UNITY_EDITOR
            if (EmptyGameObject == null)
            {
                FCgDebug.LogError("FCgManager_Prefab.Init: Failed to find EmptyGameObject named " + EMPTY_GAME_OBJECT_NAME + ". needs to exist in the level in order to create other objects.");
            }
#endif // #if UNITY_EDITOR
        }
示例#7
0
        public FCgTraceResponse AllocateResponse()
        {
            for (byte i = 0; i < RESPONSE_SIZE; ++i)
            {
                ResponseIndex = (byte)((ResponseIndex + 1) % RESPONSE_SIZE);
                FCgTraceResponse response = Responses[ResponseIndex];

                if (!response.bAllocated)
                {
                    response.bAllocated = true;
                    return(response);
                }
            }
            FCgDebug.LogError("FCsManager_Trace::AllocateResponse: Pool is exhausted");
            return(null);
        }
示例#8
0
        public FCgTraceRequest AllocateRequest()
        {
            for (byte i = 0; i < REQUEST_SIZE; ++i)
            {
                RequestIndex = (byte)((RequestIndex + 1) % REQUEST_SIZE);
                FCgTraceRequest request = Requests[RequestIndex];

                if (!request.bAllocated)
                {
                    request.bAllocated = true;
                    return(request);
                }
            }
            FCgDebug.LogError("FCsManager_Trace.AllocateRequest: Pool is exhausted");
            return(null);
        }
示例#9
0
        public PayloadType AllocatePayload()
        {
            int count = Payloads.Count;

            for (int i = 0; i < count; ++i)
            {
                int         index   = (PayloadIndex + i) % count;
                PayloadType payload = Payloads[index];

                if (!payload.bAllocated)
                {
                    payload.bAllocated = true;
                    return(payload);
                }
            }
            FCgDebug.LogError(this.GetType().Name + ".AllocatePayload: Pool is exhausted.");
            return(default(PayloadType));
        }
示例#10
0
        public virtual void AddToActivePool(EnumType e, ObjectType o)
        {
            if (o.GetCache <EnumType, ObjectType, PayloadType, CacheType>().Index == INDEX_NONE)
            {
                FCgDebug.LogError(this.GetType().Name + ".AddToActivePool: Object of Type: " + EnumTypeToString(e) + " was NOT added to any pool. Call AddToPool first.");
                return;
            }

            o.GetCache <EnumType, ObjectType, PayloadType, CacheType>().bAllocated = true;

            Dictionary <int, ObjectType> pool = null;

            if (ActiveObjects.TryGetValue(e, out pool))
            {
                ActiveObjects[e].Add(o.GetCache <EnumType, ObjectType, PayloadType, CacheType>().Index, o);
            }
            else
            {
                pool = new Dictionary <int, ObjectType>();
                pool.Add(o.GetCache <EnumType, ObjectType, PayloadType, CacheType>().Index, o);
                ActiveObjects.Add(e, pool);
            }
            //
        }