Exemplo n.º 1
0
    public void Init()
    {
        dataTex = group.CreateTexture();
        if (dataTex == null)
        {
            Debug.LogErrorFormat("Got null data texture from AnimBatchGroup [{0}]", batchGroup);
        }
        int bestTextureSize = KAnimBatchGroup.GetBestTextureSize((float)(group.data.maxSymbolsPerBuild * group.maxGroupSize * 8));

        symbolInstanceTex = group.CreateTexture("SymbolInstanceTex", bestTextureSize, ShaderProperty_symbolInstanceTex, ShaderProperty_SYMBOL_INSTANCE_TEXTURE_SIZE);
        int width = dataTex.width;

        if (width == 0)
        {
            Debug.LogWarning("Empty group [" + group.batchID + "] " + batchset.idx + " (probably just anims)");
        }
        else
        {
            for (int i = 0; i < width * width; i++)
            {
                dataTex.floats[i * 4]     = -1f;
                dataTex.floats[i * 4 + 1] = 0f;
                dataTex.floats[i * 4 + 2] = 0f;
                dataTex.floats[i * 4 + 3] = 0f;
            }
            matProperties = new MaterialPropertyBlock();
            dataTex.SetTextureAndSize(matProperties);
            symbolInstanceTex.SetTextureAndSize(matProperties);
            group.GetDataTextures(matProperties, atlases);
            atlases.Apply(matProperties);
        }
    }
 public static void DestroyInstance()
 {
     if (instance != null)
     {
         instance.ready = false;
         foreach (KeyValuePair <BatchGroupKey, KAnimBatchGroup> batchGroup in instance.batchGroups)
         {
             batchGroup.Value.FreeResources();
         }
         instance.batchGroups.Clear();
         foreach (KeyValuePair <HashedString, KBatchGroupData> batchGroupDatum in instance.batchGroupData)
         {
             if (batchGroupDatum.Value != null)
             {
                 batchGroupDatum.Value.FreeResources();
             }
         }
         instance.batchGroupData.Clear();
         foreach (KeyValuePair <BatchKey, BatchSet> batchSet in instance.batchSets)
         {
             if (batchSet.Value != null)
             {
                 batchSet.Value.Clear();
             }
         }
         instance.batchSets.Clear();
         instance.culledBatchSetInfos.Clear();
         instance.uiBatchSets.Clear();
         instance.activeBatchSets.Clear();
         instance.dirtyBatchLastFrame = 0;
         KAnimBatchGroup.FinalizeTextureCache();
     }
     Singleton <KAnimBatchManager> .DestroyInstance();
 }
 public BatchSet(KAnimBatchGroup batchGroup, BatchKey batchKey, Vector2I spacialIdx)
 {
     idx     = spacialIdx;
     key     = batchKey;
     dirty   = true;
     group   = batchGroup;
     batches = new List <KAnimBatch>();
 }
    public KAnimBatchGroup GetBatchGroup(BatchGroupKey group_key)
    {
        KAnimBatchGroup value = null;

        if (!batchGroups.TryGetValue(group_key, out value))
        {
            value = new KAnimBatchGroup(group_key.groupID);
            batchGroups.Add(group_key, value);
        }
        return(value);
    }
Exemplo n.º 5
0
 public KAnimBatch(KAnimBatchGroup group, int layer, float z, KAnimBatchGroup.MaterialType material_type)
 {
     id                      = nextBatchId++;
     active                  = true;
     this.group              = group;
     this.layer              = layer;
     batchGroup              = group.batchID;
     materialType            = material_type;
     position                = new Vector3(0f, 0f, z);
     symbolInstanceSlots     = new SymbolInstanceSlot[group.maxGroupSize];
     symbolOverrideInfoSlots = new SymbolOverrideInfoSlot[group.maxGroupSize];
 }
Exemplo n.º 6
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);
     }
 }
Exemplo n.º 7
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);
 }
Exemplo n.º 8
0
    public int UpdateDirty(int frame)
    {
        if (!needsWrite)
        {
            return(0);
        }
        if (dataTex == null || dataTex.floats.Length == 0)
        {
            Init();
        }
        writtenLastFrame = 0;
        bool flag  = false;
        bool flag2 = false;

        if (dirtySet.Count > 0)
        {
            foreach (int item in dirtySet)
            {
                KAnimConverter.IAnimConverter animConverter = controllers[item];
                if (animConverter != null && animConverter as Object != (Object)null)
                {
                    WriteBatchedAnimInstanceData(item, animConverter);
                    bool flag3 = WriteSymbolInstanceData(item, animConverter);
                    flag = (flag || flag3);
                    if (animConverter.ApplySymbolOverrides())
                    {
                        if (symbolOverrideInfoTex == null)
                        {
                            int bestTextureSize = KAnimBatchGroup.GetBestTextureSize((float)(group.data.maxSymbolFrameInstancesPerbuild * group.maxGroupSize * 12));
                            symbolOverrideInfoTex = group.CreateTexture("SymbolOverrideInfoTex", bestTextureSize, ShaderProperty_symbolOverrideInfoTex, ShaderProperty_SYMBOL_OVERRIDE_INFO_TEXTURE_SIZE);
                            symbolOverrideInfoTex.SetTextureAndSize(matProperties);
                            matProperties.SetFloat(ShaderProperty_SUPPORTS_SYMBOL_OVERRIDING, 1f);
                        }
                        bool flag4 = WriteSymbolOverrideInfoTex(item, animConverter);
                        flag2 = (flag2 || flag4);
                    }
                    writtenLastFrame++;
                }
            }
            if (writtenLastFrame != 0)
            {
                ClearDirty();
            }
            else
            {
                Debug.LogError("dirtySet not written");
            }
        }
        dataTex.LoadRawTextureData();
        dataTex.Apply();
        if (flag)
        {
            symbolInstanceTex.LoadRawTextureData();
            symbolInstanceTex.Apply();
        }
        if (flag2)
        {
            symbolOverrideInfoTex.LoadRawTextureData();
            symbolOverrideInfoTex.Apply();
        }
        return(writtenLastFrame);
    }