package mapped;

import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;
import net.runelite.rs.api.RSRasterizer3D;

@ObfuscatedName("ki")
public class Rasterizer3D implements RSRasterizer3D {
   @ObfuscatedName("at")
   public static int[] Rasterizer3D_colorPalette;
   @ObfuscatedName("ah")
   static int[] field2769;
   @ObfuscatedName("ar")
   static int[] field2775;
   @ObfuscatedName("ao")
   public static int[] Rasterizer3D_sine;
   @ObfuscatedName("ab")
   public static int[] Rasterizer3D_cosine;
   @ObfuscatedName("au")
   @ObfuscatedSignature(
      descriptor = "Lkh;"
   )
   public static Clips clips;
   @ObfuscatedName("aa")
   @ObfuscatedSignature(
      descriptor = "Lkn;"
   )
   static AbstractRasterizer field2773;
   @ObfuscatedName("ac")
   @ObfuscatedSignature(
      descriptor = "Lkn;"
   )
   static final AbstractRasterizer field2767;
   @ObfuscatedName("al")
   @ObfuscatedSignature(
      descriptor = "Lkn;"
   )
   static final AbstractRasterizer field2774;

   static {
      Rasterizer3D_colorPalette = new int[65536];
      field2769 = new int[512];
      field2775 = new int[2048];
      Rasterizer3D_sine = new int[2048];
      Rasterizer3D_cosine = new int[2048];

      int var0;
      for(var0 = 1; var0 < 512; ++var0) {
         field2769[var0] = 32768 / var0;
      }

      for(var0 = 1; var0 < 2048; ++var0) {
         field2775[var0] = 65536 / var0;
      }

      for(var0 = 0; var0 < 2048; ++var0) {
         Rasterizer3D_sine[var0] = (int)(65536.0D * Math.sin((double)var0 * 0.0030679615D));
         Rasterizer3D_cosine[var0] = (int)(65536.0D * Math.cos((double)var0 * 0.0030679615D));
      }

      clips = new Clips();
      field2767 = new class283(clips);
      field2774 = new class285(clips);
      field2773 = field2767;
   }

   @ObfuscatedName("at")
   public static void method5189_base(boolean var0) {
      if(var0 && Rasterizer2D.field5209 != null) {
         field2773 = field2774;
      } else {
         field2773 = field2767;
      }

   }

   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "(Llw;)V"
   )
   public static void method5204(TextureLoader var0) {
      clips.Rasterizer3D_textureLoader = var0;
   }

   @ObfuscatedName("ar")
   public static void method5191_base(double var0) {
      Rasterizer3D_buildPalette_base(var0, 0, 512);
   }

   @ObfuscatedName("ao")
   static void Rasterizer3D_buildPalette_base(double var0, int var2, int var3) {
      int var4 = var2 * 128;

      for(int var5 = var2; var5 < var3; ++var5) {
         double var6 = (double)(var5 >> 3) / 64.0D + 0.0078125D;
         double var8 = (double)(var5 & 7) / 8.0D + 0.0625D;

         for(int var10 = 0; var10 < 128; ++var10) {
            double var11 = (double)var10 / 128.0D;
            double var13 = var11;
            double var15 = var11;
            double var17 = var11;
            if(var8 != 0.0D) {
               double var19;
               if(var11 < 0.5D) {
                  var19 = var11 * (1.0D + var8);
               } else {
                  var19 = var11 + var8 - var11 * var8;
               }

               double var21 = 2.0D * var11 - var19;
               double var23 = var6 + 0.3333333333333333D;
               if(var23 > 1.0D) {
                  --var23;
               }

               double var27 = var6 - 0.3333333333333333D;
               if(var27 < 0.0D) {
                  ++var27;
               }

               if(6.0D * var23 < 1.0D) {
                  var13 = var21 + (var19 - var21) * 6.0D * var23;
               } else if(2.0D * var23 < 1.0D) {
                  var13 = var19;
               } else if(3.0D * var23 < 2.0D) {
                  var13 = var21 + (var19 - var21) * (0.6666666666666666D - var23) * 6.0D;
               } else {
                  var13 = var21;
               }

               if(6.0D * var6 < 1.0D) {
                  var15 = var21 + (var19 - var21) * 6.0D * var6;
               } else if(2.0D * var6 < 1.0D) {
                  var15 = var19;
               } else if(3.0D * var6 < 2.0D) {
                  var15 = var21 + (var19 - var21) * (0.6666666666666666D - var6) * 6.0D;
               } else {
                  var15 = var21;
               }

               if(6.0D * var27 < 1.0D) {
                  var17 = var21 + (var19 - var21) * 6.0D * var27;
               } else if(2.0D * var27 < 1.0D) {
                  var17 = var19;
               } else if(3.0D * var27 < 2.0D) {
                  var17 = var21 + (var19 - var21) * (0.6666666666666666D - var27) * 6.0D;
               } else {
                  var17 = var21;
               }
            }

            int var29 = (int)(var13 * 256.0D);
            int var20 = (int)(var15 * 256.0D);
            int var30 = (int)(var17 * 256.0D);
            int var22 = var30 + (var20 << 8) + (var29 << 16);
            var22 = Rasterizer3D_brighten_base(var22, var0);
            if(var22 == 0) {
               var22 = 1;
            }

            Rasterizer3D_colorPalette[var4++] = var22;
         }
      }

   }

   @ObfuscatedName("ab")
   static int Rasterizer3D_brighten_base(int var0, double var1) {
      double var3 = (double)(var0 >> 16) / 256.0D;
      double var5 = (double)(var0 >> 8 & 255) / 256.0D;
      double var7 = (double)(var0 & 255) / 256.0D;
      var3 = Math.pow(var3, var1);
      var5 = Math.pow(var5, var1);
      var7 = Math.pow(var7, var1);
      int var9 = (int)(var3 * 256.0D);
      int var10 = (int)(var5 * 256.0D);
      int var11 = (int)(var7 * 256.0D);
      return var11 + (var10 << 8) + (var9 << 16);
   }

   @ObfuscatedName("au")
   static int getClipMidX_base() {
      return clips.field3037;
   }

   @ObfuscatedName("aa")
   static int getClipMidY_base() {
      return clips.field3049;
   }

   @ObfuscatedName("ac")
   static int method5198_base() {
      return clips.clipNegativeMidX;
   }

   @ObfuscatedName("al")
   static int Rasterizer3D_clipMidX2_base() {
      return clips.field3053;
   }

   @ObfuscatedName("az")
   static int Rasterizer3D_clipMidY2_base() {
      return clips.field3055;
   }

   @ObfuscatedName("ap")
   static int method5199_base() {
      return clips.clipNegativeMidY;
   }

   @ObfuscatedName("av")
   public static int get3dZoom_base() {
      return clips.field3041;
   }

   @ObfuscatedName("ax")
   static int method5237_base() {
      return clips.field3050;
   }

   @ObfuscatedName("as")
   public static void method5263_base(int[] var0, int var1, int var2, float[] var3) {
      if(var3 == null && field2773 == field2774) {
         field2773 = field2767;
      }

      field2773.method5286_base(var0, var1, var2, var3);
   }

   @ObfuscatedName("ay")
   public static void resetRasterClipping_base() {
      method5218_base(Rasterizer2D.Rasterizer2D_xClipStart, Rasterizer2D.Rasterizer2D_yClipStart, Rasterizer2D.Rasterizer2D_xClipEnd, Rasterizer2D.Rasterizer2D_yClipEnd);
   }

   @ObfuscatedName("ak")
   static void method5218_base(int var0, int var1, int var2, int var3) {
      clips.field3050 = var2 - var0;
      clips.field3039 = var3 - var1;
      method5205_base();
      if(clips.Rasterizer3D_rowOffsets.length < clips.field3039) {
         clips.Rasterizer3D_rowOffsets = new int[class184.method3680_base(clips.field3039)];
      }

      int var4 = var0 + Rasterizer2D.Rasterizer2D_width * var1;

      for(int var5 = 0; var5 < clips.field3039; ++var5) {
         clips.Rasterizer3D_rowOffsets[var5] = var4;
         var4 += Rasterizer2D.Rasterizer2D_width;
      }

   }

   @ObfuscatedName("aj")
   public static void method5205_base() {
      clips.method5733_base();
   }

   @ObfuscatedName("am")
   public static void method5206_base(int var0, int var1) {
      int var2 = clips.Rasterizer3D_rowOffsets[0];
      int var3 = var2 / Rasterizer2D.Rasterizer2D_width;
      int var4 = var2 - var3 * Rasterizer2D.Rasterizer2D_width;
      clips.method5734_base(var0, var4, var1, var3);
   }

   @ObfuscatedName("aq")
   public static void method5207_base(int var0, int var1, int var2) {
      clips.method5735_base(var0, var1, var2);
   }

   @ObfuscatedName("ai")
   static void rasterGouraud_base(int var0, int var1, int var2, int var3, int var4, int var5, float var6, float var7, float var8, int var9, int var10, int var11) {
      field2773.vmethod5746_base(var0, var1, var2, var3, var4, var5, var6, var7, var8, var9, var10, var11);
   }

   @ObfuscatedName("aw")
   public static void rasterFlat_base(int var0, int var1, int var2, int var3, int var4, int var5, float var6, float var7, float var8, int var9) {
      field2773.vmethod5752_base(var0, var1, var2, var3, var4, var5, var6, var7, var8, var9);
   }

   @ObfuscatedName("ae")
   static void method5266_base(int var0, int var1, int var2, int var3, int var4, int var5, float var6, float var7, float var8, int var9, int var10, int var11, int var12, int var13, int var14, int var15, int var16, int var17, int var18, int var19, int var20, int var21) {
      field2773.vmethod5754_base(var0, var1, var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12, var13, var14, var15, var16, var17, var18, var19, var20, var21);
   }

   @ObfuscatedName("an")
   static void method5211_base(int var0, int var1, int var2, int var3, int var4, int var5, float var6, float var7, float var8, int var9, int var10, int var11, int var12, int var13, int var14, int var15, int var16, int var17, int var18, int var19, int var20, int var21) {
      field2773.vmethod5761_base(var0, var1, var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12, var13, var14, var15, var16, var17, var18, var19, var20, var21);
   }

   @ObfuscatedName("ag")
   static void method5212_base(int var0, int var1, int var2, int var3, int var4, int var5, float var6, float var7, float var8, int var9, int var10, int var11, byte var12, byte var13, byte var14, byte var15) {
      field2773.method5288_base(var0, var1, var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12, var13, var14, var15);
   }

   @ObfuscatedName("ad")
   static void method5213_base(int var0, int var1, int var2, int var3, int var4, int var5, float var6, float var7, float var8, int var9, byte var10, byte var11, byte var12, byte var13) {
      field2773.method5291_base(var0, var1, var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12, var13);
   }
}
