<commit_before>﻿using System;
using FezEngine.Effects;
#if FNA
using Microsoft.Xna.Framework;
#endif
using Microsoft.Xna.Framework.Graphics;
using MonoMod;
using FezEngine.Mod;

namespace FezEngine.Structure.Geometry {
    public class patch_ShaderInstancedIndexedPrimitives<TemplateType, InstanceType> : IndexedPrimitiveCollectionBase<TemplateType, int>, IFakeDisposable where TemplateType : struct, IShaderInstantiatableVertex where InstanceType : struct {

        //Reusable version instances, just because
        private readonly static Version V_1_11 = new Version(1, 11);
        private readonly static Version V_1_12 = new Version(1, 12);
        
        //Field list taken from 1.12; Compiles for non-FNA, which won't use the new fields anyways.
        [MonoModIgnore] public int PredictiveBatchSize;
        [MonoModIgnore] private int[] tempIndices;
        [MonoModIgnore] private InstanceType[] tempInstances;
        [MonoModIgnore] private TemplateType[] tempVertices;
        [MonoModIgnore] private VertexDeclaration vertexDeclaration;
        [MonoModIgnore] private bool appendIndex;
        [MonoModIgnore] private IndexedVector4[] indexedInstances;
        [MonoModIgnore] private bool useHwInstancing;
        [MonoModIgnore] private int oldInstanceCount;
        [MonoModIgnore] private readonly int InstancesPerBatch;
        [MonoModIgnore] private VertexBuffer vertexBuffer;
        [MonoModIgnore] private IndexBuffer indexBuffer;
        [MonoModIgnore] private DynamicVertexBuffer instanceBuffer;
        [MonoModIgnore] public InstanceType[] Instances;
        [MonoModIgnore] public int InstanceCount;
        [MonoModIgnore] public bool InstancesDirty;

        #if !FNA
        [MonoModIgnore]
        public patch_ShaderInstancedIndexedPrimitives(PrimitiveType type, int instancesPerBatch)
            : base(type) {
            InstancesPerBatch = instancesPerBatch;
        }
        #else
        //Custom fields
        private VertexBufferBinding[] tmpVertexBufferBindingArray;
        
        [MonoModIgnore]
        public patch_ShaderInstancedIndexedPrimitives(PrimitiveType type, int instancesPerBatch, bool appendIndex = false)
            : base(type) {
            InstancesPerBatch = instancesPerBatch;
            appendIndex = appendIndex;
            RefreshInstancingMode(true);
        }
        #endif

        [MonoModIgnore] public extern void RefreshInstancingMode(bool force = false);
        [MonoModIgnore] public extern void Dispose();
        [MonoModIgnore] public void UpdateBuffers() {
            UpdateBuffers(false);
		}
        [MonoModIgnore] private extern void UpdateBuffers(bool rebuild);
        [MonoModIgnore] public override extern IIndexedPrimitiveCollection Clone();

        public extern void orig_Draw(BaseEffect effect);
        public override void Draw(BaseEffect effect) {
            if (device == null || primitiveCount == 0 || vertices == null || vertices.Length == 0 || indexBuffer == null || vertexBuffer == null || Instances == null || InstanceCount <= 0) {
                return;
            }

            #if !FNA
            if (FEZModEngine.FEZVersion == V_1_11) {
                ModLogger.Log("FEZMod.SIIP", "Draw 1.11");
                Draw_1_11(effect);
                return;
            }
            #else
            //FNA is used by 1.12+ anyways, so avoid errors when calling / patching this method.
            //Also, FEZ 1.12+ fixes the Intel bug. Custom SIIP code shouldn't be required anymore.
            if (FEZModEngine.FEZVersion == V_1_12) {
                Draw_1_12(effect);
                return;
            }
            #endif

            orig_Draw(effect);
        }
        
        //Version-dependant drawing code
        #if !FNA
        <commit_msg>.Core: Remove useless log in SIIP (possibly related to comments in issue #29)<commit_after>﻿using System;
using FezEngine.Effects;
#if FNA
using Microsoft.Xna.Framework;
#endif
using Microsoft.Xna.Framework.Graphics;
using MonoMod;
using FezEngine.Mod;

namespace FezEngine.Structure.Geometry {
    public class patch_ShaderInstancedIndexedPrimitives<TemplateType, InstanceType> : IndexedPrimitiveCollectionBase<TemplateType, int>, IFakeDisposable where TemplateType : struct, IShaderInstantiatableVertex where InstanceType : struct {

        //Reusable version instances, just because
        private readonly static Version V_1_11 = new Version(1, 11);
        private readonly static Version V_1_12 = new Version(1, 12);
        
        //Field list taken from 1.12; Compiles for non-FNA, which won't use the new fields anyways.
        [MonoModIgnore] public int PredictiveBatchSize;
        [MonoModIgnore] private int[] tempIndices;
        [MonoModIgnore] private InstanceType[] tempInstances;
        [MonoModIgnore] private TemplateType[] tempVertices;
        [MonoModIgnore] private VertexDeclaration vertexDeclaration;
        [MonoModIgnore] private bool appendIndex;
        [MonoModIgnore] private IndexedVector4[] indexedInstances;
        [MonoModIgnore] private bool useHwInstancing;
        [MonoModIgnore] private int oldInstanceCount;
        [MonoModIgnore] private readonly int InstancesPerBatch;
        [MonoModIgnore] private VertexBuffer vertexBuffer;
        [MonoModIgnore] private IndexBuffer indexBuffer;
        [MonoModIgnore] private DynamicVertexBuffer instanceBuffer;
        [MonoModIgnore] public InstanceType[] Instances;
        [MonoModIgnore] public int InstanceCount;
        [MonoModIgnore] public bool InstancesDirty;

        #if !FNA
        [MonoModIgnore]
        public patch_ShaderInstancedIndexedPrimitives(PrimitiveType type, int instancesPerBatch)
            : base(type) {
            InstancesPerBatch = instancesPerBatch;
        }
        #else
        //Custom fields
        private VertexBufferBinding[] tmpVertexBufferBindingArray;
        
        [MonoModIgnore]
        public patch_ShaderInstancedIndexedPrimitives(PrimitiveType type, int instancesPerBatch, bool appendIndex = false)
            : base(type) {
            InstancesPerBatch = instancesPerBatch;
            appendIndex = appendIndex;
            RefreshInstancingMode(true);
        }
        #endif

        [MonoModIgnore] public extern void RefreshInstancingMode(bool force = false);
        [MonoModIgnore] public extern void Dispose();
        [MonoModIgnore] public void UpdateBuffers() {
            UpdateBuffers(false);
		}
        [MonoModIgnore] private extern void UpdateBuffers(bool rebuild);
        [MonoModIgnore] public override extern IIndexedPrimitiveCollection Clone();

        public extern void orig_Draw(BaseEffect effect);
        public override void Draw(BaseEffect effect) {
            if (device == null || primitiveCount == 0 || vertices == null || vertices.Length == 0 || indexBuffer == null || vertexBuffer == null || Instances == null || InstanceCount <= 0) {
                return;
            }

            #if !FNA
            if (FEZModEngine.FEZVersion == V_1_11) {
                Draw_1_11(effect);
                return;
            }
            #else
            //FNA is used by 1.12+ anyways, so avoid errors when calling / patching this method.
            //Also, FEZ 1.12+ fixes the Intel bug. Custom SIIP code shouldn't be required anymore.
            if (FEZModEngine.FEZVersion == V_1_12) {
                Draw_1_12(effect);
                return;
            }
            #endif

            orig_Draw(effect);
        }
        
        //Version-dependant drawing code
        #if !FNA
        
{'fraction_non_alphanumeric': 0.07468003694418789, 'fraction_numerical': 0.010423538725425518, 'mean_word_length': 2.602661596958175, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3232727', 'n_tokens_mistral': 2049, 'n_tokens_neox': 1974, 'n_words': 555}