Example #1
0
 /// <summary>
 /// Applied after UpdateDirty runs.
 /// </summary>
 internal static void Postfix(int __result, KAnimBatch __instance)
 {
     if (__result > 0)
     {
         KAnimMeshRendererPatches.UpdateMaterialProperties(__instance);
     }
 }
 public void Render()
 {
     if (ready)
     {
         foreach (BatchSet activeBatchSet in activeBatchSets)
         {
             DebugUtil.Assert(activeBatchSet != null);
             DebugUtil.Assert(activeBatchSet.group != null);
             Mesh mesh = activeBatchSet.group.mesh;
             for (int i = 0; i < activeBatchSet.batchCount; i++)
             {
                 KAnimBatch batch = activeBatchSet.GetBatch(i);
                 float      num   = 0.01f / (float)(1 + batch.id % 256);
                 if (batch.size != 0 && batch.active && batch.materialType != KAnimBatchGroup.MaterialType.UI)
                 {
                     Vector3 zero     = Vector3.zero;
                     Vector3 position = batch.position;
                     zero.z = position.z + num;
                     int layer = batch.layer;
                     Graphics.DrawMesh(mesh, zero, Quaternion.identity, activeBatchSet.group.GetMaterial(batch.materialType), layer, null, 0, batch.matProperties);
                 }
             }
         }
     }
 }
Example #3
0
    public static void UpdateBlinking(Instance smi, float dt)
    {
        int        currentFrameIndex = smi.eyes.GetCurrentFrameIndex();
        KAnimBatch batch             = smi.eyes.GetBatch();

        if (currentFrameIndex != -1 && batch != null)
        {
            KAnim.Anim.Frame frame = smi.eyes.GetBatch().group.data.GetFrame(currentFrameIndex);
            if (!(frame == KAnim.Anim.Frame.InvalidFrame))
            {
                HashedString hash = HashedString.Invalid;
                for (int i = 0; i < frame.numElements; i++)
                {
                    int num = frame.firstElementIdx + i;
                    if (num < batch.group.data.frameElements.Count)
                    {
                        KAnim.Anim.FrameElement frameElement = batch.group.data.frameElements[num];
                        if (!(frameElement.symbol == HashedString.Invalid))
                        {
                            hash = frameElement.symbol;
                            break;
                        }
                    }
                }
                smi.GetComponent <SymbolOverrideController>().AddSymbolOverride(HASH_SNAPTO_EYES, smi.eyes.AnimFiles[0].GetData().build.GetSymbol(hash), 3);
            }
        }
    }
    public void Add(KAnimConverter.IAnimConverter controller)
    {
        int layer = controller.GetLayer();

        if (layer != key.layer)
        {
            Debug.LogError("Registering with wrong batch set (layer) " + controller.GetName());
        }
        HashedString batchGroupID = controller.GetBatchGroupID(false);

        if (!(batchGroupID == key.groupID))
        {
            Debug.LogError("Registering with wrong batch set (groupID) " + controller.GetName());
        }
        KAnimBatchGroup.MaterialType materialType = controller.GetMaterialType();
        for (int i = 0; i < batches.Count; i++)
        {
            if (batches[i].size < group.maxGroupSize && batches[i].materialType == materialType)
            {
                if (batches[i].Register(controller))
                {
                    SetDirty();
                }
                return;
            }
        }
        KAnimBatch kAnimBatch = new KAnimBatch(group, layer, controller.GetZ(), materialType);

        kAnimBatch.Init();
        AddBatch(kAnimBatch);
        kAnimBatch.Register(controller);
    }
Example #5
0
            /// <summary>
            /// Applied after Deactivate runs.
            /// </summary>
            internal static void Postfix(KAnimBatch __instance)
            {
                int id = __instance.id;

                if (__instance.materialType != MaterialType.UI && visualizers.TryGetValue(
                        id, out KAnimMeshRenderer renderer) && renderer != null)
                {
                    renderer.Deactivate();
                }
            }
Example #6
0
        /// <summary>
        /// Updates the material properties on the mesh renderer for an animation batch.
        /// </summary>
        /// <param name="batch">The batch to update.</param>
        internal static void UpdateMaterialProperties(KAnimBatch batch)
        {
            int id = batch.id;

            if (batch.materialType != MaterialType.UI && visualizers.TryGetValue(id,
                                                                                 out KAnimMeshRenderer renderer) && renderer != null)
            {
                renderer.SetProperties(batch.matProperties);
            }
        }
 public void RemoveBatch(KAnimBatch batch)
 {
     Debug.Assert(batch.batchset == this);
     if (batches.Contains(batch))
     {
         group.batchCount--;
         batches.Remove(batch);
         batch.SetBatchSet(null);
     }
 }
Example #8
0
        /// <summary>
        /// Applied before Deregister runs.
        /// </summary>
        internal static bool Prefix(KAnimConverter.IAnimConverter controller,
                                    KAnimBatch __instance)
        {
            var controllersToIndex = __instance.controllersToIdx;

            if (!App.IsExiting && controllersToIndex.TryGetValue(controller, out int index))
            {
                var controllers = __instance.controllers;
                var dirtySet    = __instance.dirtySet;
                var bs          = __instance.batchset;
                // All the other anims above it need to be marked dirty
                float[] data = __instance.dataTex.floats;
                int     end = Math.Max(0, __instance.currentOffset - VERTICES), n;
                controller.SetBatch(null);
                controllers.RemoveAt(index);
                controllersToIndex.Remove(controller);
                var dirty = ListPool <int, KAnimBatch> .Allocate();

                n = dirtySet.Count;
                // Save every existing dirty index less than the deregistered one
                for (int i = 0; i < n; i++)
                {
                    int dirtyIdx = dirtySet[i];
                    if (dirtyIdx < index)
                    {
                        dirty.Add(dirtyIdx);
                    }
                }
                dirtySet.Clear();
                dirtySet.AddRange(dirty);
                dirty.Recycle();
                n = controllers.Count;
                // Refresh the index mapping table and mark everything moved-down as dirty
                for (int i = index; i < n; i++)
                {
                    controllersToIndex[controllers[i]] = i;
                    dirtySet.Add(i);
                }
                bs.SetDirty();
                __instance.needsWrite = true;
                // Invalidate the data beyond the end
                for (int i = 0; i < VERTICES; i++)
                {
                    data[end + i] = -1f;
                }
                __instance.currentOffset = end;
                // If this was the last item, destroy the texture
                if (n <= 0)
                {
                    bs.RemoveBatch(__instance);
                    __instance.Clear();
                }
            }
            return(false);
        }
Example #9
0
            /// <summary>
            /// Applied before DestroyTex runs.
            /// </summary>
            internal static void Prefix(KAnimBatch __instance)
            {
                int id = __instance.id;

                if (__instance.materialType != MaterialType.UI && visualizers.TryGetValue(
                        id, out KAnimMeshRenderer renderer))
                {
                    if (renderer != null)
                    {
                        renderer.DestroyRenderer();
                    }
                    visualizers.Remove(id);
                }
            }
Example #10
0
        /// <summary>
        /// Applied before Register runs.
        /// </summary>
        internal static bool Prefix(KAnimConverter.IAnimConverter controller,
                                    KAnimBatch __instance, ref bool __result)
        {
            var batch = controller.GetBatch();

            if (batch != __instance)
            {
                var dirtySet           = __instance.dirtySet;
                var controllers        = __instance.controllers;
                var controllersToIndex = __instance.controllersToIdx;
                // Create the texture if it is null
                var tex = __instance.dataTex;
                if (tex == null || tex.floats.Length < 1)
                {
                    __instance.Init();
                }
                // If already present [how is this possible?], just mark it dirty
                if (controllersToIndex.TryGetValue(controller, out int index))
                {
                    if (!dirtySet.Contains(index))
                    {
                        dirtySet.Add(index);
                    }
                }
                else
                {
                    int n = controllers.Count;
                    controllers.Add(controller);
                    dirtySet.Add(n);
                    controllersToIndex.Add(controller, n);
                    // Allocate additional spots in the texture
                    __instance.currentOffset += KBatchedAnimInstanceData.SIZE_IN_FLOATS;
                }
                __instance.batchset.SetDirty();
                __instance.needsWrite = true;
                if (batch != null)
                {
                    batch.Deregister(controller);
                }
                controller.SetBatch(__instance);
            }
            else
            {
#if DEBUG
                PUtil.LogDebug("Registered a controller to its existing batch!");
#endif
            }
            __result = true;
            return(false);
        }
Example #11
0
 public void SetBatch(KAnimBatch new_batch)
 {
     batch = new_batch;
     if (materialType == KAnimBatchGroup.MaterialType.UI)
     {
         KBatchedAnimCanvasRenderer kBatchedAnimCanvasRenderer = GetComponent <KBatchedAnimCanvasRenderer>();
         if ((UnityEngine.Object)kBatchedAnimCanvasRenderer == (UnityEngine.Object)null && new_batch != null)
         {
             kBatchedAnimCanvasRenderer = base.gameObject.AddComponent <KBatchedAnimCanvasRenderer>();
         }
         if ((UnityEngine.Object)kBatchedAnimCanvasRenderer != (UnityEngine.Object)null)
         {
             kBatchedAnimCanvasRenderer.SetBatch(this);
         }
     }
 }
Example #12
0
 /// <summary>
 /// Applied after the constructor runs.
 /// </summary>
 internal static void Postfix(KAnimBatch __instance, KAnimBatchGroup group,
                              int layer, MaterialType material_type)
 {
     if (group != null && material_type != MaterialType.UI)
     {
         int id = __instance.id;
         // Destroy the existing renderer if it exists
         if (visualizers.TryGetValue(id, out KAnimMeshRenderer renderer) &&
             renderer != null)
         {
             renderer.DestroyRenderer();
         }
         visualizers[id] = KAnimMeshRenderer.Create(group.mesh, group.
                                                    GetMaterial(material_type), layer, id);
     }
 }
Example #13
0
    protected override void OnDestroy()
    {
        if (!App.IsExiting)
        {
            Singleton <CellChangeMonitor> .Instance?.UnregisterMovementStateChanged(base.transform, OnMovementStateChanged);

            Singleton <KBatchedAnimUpdater> .Instance?.UpdateUnregister(this);

            isVisible = false;
            DeRegister();
            stopped = true;
            StopAnimEventSequence();
            batchInstanceData = null;
            batch             = null;
            base.OnDestroy();
        }
    }
Example #14
0
 /// <summary>
 /// Sets up the override texture if necessary.
 /// </summary>
 /// <param name="instance">The batch to override.</param>
 /// <param name="overrideTex">The current override texture.</param>
 /// <returns>The new override texture.</returns>
 private static KAnimBatchTextureCache.Entry SetupOverride(KAnimBatch instance,
                                                           KAnimBatchTextureCache.Entry overrideTex)
 {
     if (overrideTex == null)
     {
         var bg         = instance.group;
         var properties = instance.matProperties;
         overrideTex = bg.CreateTexture("SymbolOverrideInfoTex", KAnimBatchGroup.
                                        GetBestTextureSize(bg.data.maxSymbolFrameInstancesPerbuild * bg.
                                                           maxGroupSize * SymbolOverrideInfoGpuData.FLOATS_PER_SYMBOL_OVERRIDE_INFO),
                                        KAnimBatch.ShaderProperty_symbolOverrideInfoTex, KAnimBatch.
                                        ShaderProperty_SYMBOL_OVERRIDE_INFO_TEXTURE_SIZE);
         overrideTex.SetTextureAndSize(properties);
         properties.SetFloat(KAnimBatch.ShaderProperty_SUPPORTS_SYMBOL_OVERRIDING, 1f);
         instance.symbolOverrideInfoTex = overrideTex;
     }
     return(overrideTex);
 }
 public void AddBatch(KAnimBatch batch)
 {
     if (batch.batchset != this)
     {
         if (batch.batchset != null)
         {
             batch.batchset.RemoveBatch(batch);
         }
         batch.SetBatchSet(this);
         if (!batches.Contains(batch))
         {
             group.batchCount++;
             batches.Add(batch);
             batches.Sort(delegate(KAnimBatch b0, KAnimBatch b1)
             {
                 Vector3 position3 = b0.position;
                 ref float z       = ref position3.z;
                 Vector3 position4 = b1.position;
                 return(z.CompareTo(position4.z));
             });
Example #16
0
 public void SetBatch(KAnimConverter.IAnimConverter conv)
 {
     converter = conv;
     if (conv != null)
     {
         batch = conv.GetBatch();
     }
     else
     {
         batch = null;
         if ((Object)uiMat != (Object)null)
         {
             Object.Destroy(uiMat);
             uiMat = null;
         }
     }
     if (batch != null)
     {
         canvass = GetComponent <CanvasRenderer>();
         if ((Object)canvass == (Object)null)
         {
             canvass = base.gameObject.AddComponent <CanvasRenderer>();
         }
         rootRectTransform = GetComponent <RectTransform>();
         if ((Object)rootRectTransform == (Object)null)
         {
             rootRectTransform = base.gameObject.AddComponent <RectTransform>();
         }
         if (batch.group.InitOK)
         {
             if ((Object)uiMat != (Object)null)
             {
                 Object.Destroy(uiMat);
                 uiMat = null;
             }
             Material material = batch.group.GetMaterial(batch.materialType);
             uiMat = new Material(material);
             ((IMaskable)this).RecalculateMasking();
         }
     }
 }
Example #17
0
 public void UpdateAnim(float dt)
 {
     if (batch != null && base.transform.hasChanged)
     {
         base.transform.hasChanged = false;
         if (batch != null && batch.group.maxGroupSize == 1)
         {
             float   z        = lastPos.z;
             Vector3 position = base.transform.GetPosition();
             if (z != position.z)
             {
                 KAnimBatch kAnimBatch = batch;
                 Vector3    position2  = base.transform.GetPosition();
                 kAnimBatch.OverrideZ(position2.z);
             }
         }
         Vector3 vector = lastPos = base.PositionIncludingOffset;
         if (visibilityType != VisibilityType.Always)
         {
             Vector2I u = KAnimBatchManager.ControllerToChunkXY(this);
             if (u != lastChunkXY && lastChunkXY != KBatchedAnimUpdater.INVALID_CHUNK_ID)
             {
                 DeRegister();
                 Register();
             }
         }
         SetDirty();
     }
     if (!(batchGroupID == KAnimBatchManager.NO_BATCH) && IsActive())
     {
         if (!forceRebuild && (mode == KAnim.PlayMode.Paused || stopped || curAnim == null || (mode == KAnim.PlayMode.Once && curAnim != null && (base.elapsedTime > curAnim.totalTime || curAnim.totalTime <= 0f) && animQueue.Count == 0)))
         {
             SuspendUpdates(true);
         }
         if (!isVisible && !forceRebuild)
         {
             if (visibilityType == VisibilityType.OffscreenUpdate && !stopped && mode != KAnim.PlayMode.Paused)
             {
                 SetElapsedTime(base.elapsedTime + dt * playSpeed);
             }
         }
         else
         {
             curAnimFrameIdx = GetFrameIdx(base.elapsedTime, true);
             if (eventManagerHandle.IsValid() && aem != null)
             {
                 float elapsedTime = aem.GetElapsedTime(eventManagerHandle);
                 if ((int)((base.elapsedTime - elapsedTime) * 100f) != 0)
                 {
                     UpdateAnimEventSequenceTime();
                 }
             }
             UpdateFrame(base.elapsedTime);
             if (!stopped && mode != KAnim.PlayMode.Paused)
             {
                 SetElapsedTime(base.elapsedTime + dt * playSpeed);
             }
             forceRebuild = false;
         }
     }
 }
Example #18
0
 /// <summary>
 /// Applied after Init runs.
 /// </summary>
 internal static void Postfix(KAnimBatch __instance)
 {
     UpdateMaterialProperties(__instance);
 }
Example #19
0
        /// <summary>
        /// Applied before UpdateDirty runs.
        /// </summary>
        internal static bool Prefix(ref int __result, KAnimBatch __instance)
        {
            int updated = 0;

            //Metrics.DebugMetrics.LogCondition("batchDirty", __instance.needsWrite);
            if (__instance.needsWrite)
            {
                bool symbolDirty = false, overrideDirty = false;
                var  controllers = __instance.controllers;
                var  dirtySet    = __instance.dirtySet;
                // Create the texture if it is null
                var tex = __instance.dataTex;
                if (tex == null || tex.floats.Length == 0)
                {
                    __instance.Init();
                    tex = __instance.dataTex;
                }
                var overrideTex = __instance.symbolOverrideInfoTex;
                foreach (int index in dirtySet)
                {
                    var converter = controllers[index];
                    if (converter is UnityEngine.Object obj && obj != null)
                    {
                        // Update the textures; they are different over 90% of the time, so
                        // almost no gain from checking if actually dirty
                        __instance.WriteBatchedAnimInstanceData(index, converter);
                        symbolDirty |= __instance.WriteSymbolInstanceData(index, converter);
                        if (converter.ApplySymbolOverrides())
                        {
                            overrideTex    = SetupOverride(__instance, overrideTex);
                            overrideDirty |= __instance.WriteSymbolOverrideInfoTex(index,
                                                                                   converter);
                        }
                        updated++;
                    }
                }
                dirtySet.Clear();
                __instance.needsWrite = false;
                // Write any dirty textures
                tex.LoadRawTextureData();
                tex.Apply();
                if (symbolDirty)
                {
                    var symbolTex = __instance.symbolInstanceTex;
                    symbolTex.LoadRawTextureData();
                    symbolTex.Apply();
                }
                if (overrideDirty)
                {
                    overrideTex.LoadRawTextureData();
                    overrideTex.Apply();
                }
                // Update those mesh renderers too
                if (updated > 0 && FastTrackOptions.Instance.MeshRendererOptions !=
                    FastTrackOptions.MeshRendererSettings.None)
                {
                    KAnimMeshRendererPatches.UpdateMaterialProperties(__instance);
                }
            }
            __result = updated;
            return(false);
        }