Advertisement
billwa

Untitled

Nov 14th, 2016
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 25.63 KB | None | 0 0
  1. package zombie.core.skinnedmodel;
  2.  
  3. import java.io.IOException;
  4. import java.io.PrintStream;
  5. import java.util.ArrayList;
  6. import java.util.Collections;
  7. import java.util.Comparator;
  8. import java.util.HashMap;
  9. import java.util.HashSet;
  10. import java.util.Iterator;
  11. import java.util.Stack;
  12. import org.lwjgl.opengl.GL11;
  13. import zombie.characters.IsoGameCharacter;
  14. import zombie.characters.IsoZombie;
  15. import zombie.characters.SurvivorDesc;
  16. import zombie.core.PerformanceSettings;
  17. import zombie.core.SpriteRenderer;
  18. import zombie.core.opengl.RenderThread;
  19. import zombie.core.skinnedmodel.animation.AnimationPlayer;
  20. import zombie.core.skinnedmodel.animation.AnimationTrack;
  21. import zombie.core.skinnedmodel.model.Model;
  22. import zombie.core.skinnedmodel.model.ModelInstance;
  23. import zombie.core.skinnedmodel.model.format.ModelLoader;
  24. import zombie.core.skinnedmodel.model.format.ModelLoader.ModelFormat;
  25. import zombie.core.textures.ColorInfo;
  26. import zombie.core.textures.Texture;
  27. import zombie.core.textures.TextureFBO;
  28. import zombie.core.textures.TextureID;
  29. import zombie.core.utils.OnceEvery;
  30. import zombie.interfaces.ITexture;
  31. import zombie.inventory.types.HandWeapon;
  32. import zombie.iso.IsoCell;
  33. import zombie.iso.IsoDirections;
  34. import zombie.iso.IsoLightSource;
  35. import zombie.iso.IsoUtils;
  36. import zombie.iso.IsoWorld;
  37. import zombie.iso.LosUtil;
  38. import zombie.iso.LosUtil.TestResults;
  39. import zombie.iso.sprite.IsoAnim;
  40. import zombie.iso.sprite.IsoDirectionFrame;
  41. import zombie.iso.sprite.IsoSprite;
  42. import zombie.iso.sprite.IsoSpriteInstance;
  43.  
  44. public class ModelManager
  45. {
  46.   public static ModelManager instance = new ModelManager();
  47.   public HashMap ModelMap = new HashMap();
  48.   public ArrayList ModelSlots = new ArrayList();
  49.   public TextureFBO bitmap;
  50.   public boolean bCreated = false;
  51.   public boolean bDebugEnableModels = true;
  52.   public HashSet Contains = new HashSet();
  53.   public boolean returnContext = true;
  54.   OnceEvery removeModels = new OnceEvery(2.0F);
  55.   public ArrayList ToRemove = new ArrayList();
  56.   ArrayList ToResetNextFrame = new ArrayList();
  57.   static Comparator comp = new Comparator()
  58.   {
  59.     public int compare(IsoLightSource a, IsoLightSource b)
  60.     {
  61.       float aScore = ModelManager.compChar.DistTo(a.x, a.y);
  62.       float bScore = ModelManager.compChar.DistTo(b.x, b.y);
  63.       return aScore < bScore ? -1 : aScore > bScore ? 1 : 0;
  64.     }
  65.   };
  66.   static IsoGameCharacter compChar = null;
  67.   public Stack lights = new Stack();
  68.   private Stack lightsTemp = new Stack();
  69.   public static String locationTextures = "media/textures/";
  70.   public static String locationModels = "media/models/";
  71.  
  72.   public void create()
  73.   {
  74.     String zExtension = "." + ModelLoader.ModelFormat.zomboid.getExtension();
  75.     if ((!this.bCreated) && (PerformanceSettings.modelsEnabled))
  76.     {
  77.       Texture tex = new Texture(256, 256);
  78.       try
  79.       {
  80.         try
  81.         {
  82.           TextureID.bUseCompression = false;
  83.           this.bitmap = new TextureFBO(tex, true);
  84.         }
  85.         finally
  86.         {
  87.           TextureID.bUseCompression = TextureID.bUseCompressionOption;
  88.         }
  89.       }
  90.       catch (Exception var6)
  91.       {
  92.         var6.printStackTrace();
  93.         PerformanceSettings.modelsEnabled = false;
  94.         System.out.println("Models not compatible with gfx card at this time. Reverting to 2D sprites.");
  95.         return;
  96.       }
  97.       loadStaticZomboidModel("weapons_baseballbatspiked", locationModels + "weapons_baseballbatspiked" + zExtension, locationTextures + "Objects_BaseballBatSpiked" + ".png");
  98.       loadStaticZomboidModel("weapons_baseballbat", locationModels + "weapons_baseballbat" + zExtension, locationTextures + "Objects_BaseballBat" + ".png");
  99.       loadStaticZomboidModel("weapons_fireaxe", locationModels + "weapons_fireaxe" + zExtension, locationTextures + "Objects_Fireaxe" + ".png");
  100.       loadStaticZomboidModel("weapons_fryingpan", locationModels + "weapons_fryingpan" + zExtension, locationTextures + "Objects_FryingPan" + ".png");
  101.       loadStaticZomboidModel("weapons_golfclub", locationModels + "weapons_golfclub" + zExtension, locationTextures + "Objects_GolfClub" + ".png");
  102.       loadStaticZomboidModel("weapons_hammer", locationModels + "weapons_hammer" + zExtension, locationTextures + "Objects_Hammer" + ".png");
  103.       loadStaticZomboidModel("weapons_handgun", locationModels + "weapons_handgun" + zExtension, locationTextures + "Objects_Handgun" + ".png");
  104.       loadStaticZomboidModel("weapons_knife", locationModels + "weapons_knife" + zExtension, locationTextures + "Objects_Knife" + ".png");
  105.       loadStaticZomboidModel("weapons_poolcue", locationModels + "weapons_poolcue" + zExtension, locationTextures + "Objects_PoolCue" + ".png");
  106.       loadStaticZomboidModel("weapons_rollingpin", locationModels + "weapons_rollingpin" + zExtension, locationTextures + "Objects_RollingPin" + ".png");
  107.       loadStaticZomboidModel("weapons_shotgun", locationModels + "weapons_shotgun" + zExtension, locationTextures + "Objects_Shotgun" + ".png");
  108.       loadStaticZomboidModel("weapons_shotgunsawn", locationModels + "weapons_shotgunsawn" + zExtension, locationTextures + "Objects_ShotgunSawn" + ".png");
  109.       loadStaticZomboidModel("weapons_shovel", locationModels + "weapons_shovel" + zExtension, locationTextures + "Objects_Shovel" + ".png");
  110.       loadStaticZomboidModel("weapons_sledgehammer", locationModels + "weapons_sledgehammer" + zExtension, locationTextures + "Objects_Sledgehammer" + ".png");
  111.       loadStaticZomboidModel("weapons_woodplank", locationModels + "weapons_woodplank" + zExtension, locationTextures + "Objects_WoodPlank" + ".png");
  112.       loadZomboidModel("male", locationModels + "male" + zExtension, null);
  113.       loadZomboidModel("kate", locationModels + "kate" + zExtension, null);
  114.       loadZomboidModel("Shirt", locationModels + "Shirt" + zExtension, null);
  115.       loadZomboidModel("Trousers", locationModels + "Trousers" + zExtension, null);
  116.       loadZomboidModel("vest", locationModels + "vest" + zExtension, null);
  117.       loadZomboidModel("f_vest", locationModels + "f_vest" + zExtension, null);
  118.       loadZomboidModel("f_trousers", locationModels + "f_trousers" + zExtension, null);
  119.       loadZomboidModel("f_skirt", locationModels + "f_skirt" + zExtension, null);
  120.       loadZomboidModel("f_blouse", locationModels + "f_blouse" + zExtension, null);
  121.       loadZomboidModel("beard_only", locationModels + "beard_only" + zExtension, null);
  122.       loadZomboidModel("beard_moustache", locationModels + "beard_moustache" + zExtension, null);
  123.       loadZomboidModel("beard_goatee", locationModels + "beard_goatee" + zExtension, null);
  124.       loadZomboidModel("beard_full", locationModels + "beard_full" + zExtension, null);
  125.       loadZomboidModel("beard_chops", locationModels + "beard_chops" + zExtension, null);
  126.       loadZomboidModel("f_hair_overeye", locationModels + "f_hair_overeye" + zExtension, null);
  127.       loadZomboidModel("f_hair_long2", locationModels + "f_hair_long2" + zExtension, null);
  128.       loadZomboidModel("f_hair_long", locationModels + "f_hair_long" + zExtension, null);
  129.       loadZomboidModel("f_hair_kate", locationModels + "f_hair_kate" + zExtension, null);
  130.       loadZomboidModel("f_hair_bob", locationModels + "f_hair_bob" + zExtension, null);
  131.       loadZomboidModel("f_hair_long2", locationModels + "f_hair_long2" + zExtension, null);
  132.       loadZomboidModel("f_hair_long2", locationModels + "f_hair_long2" + zExtension, null);
  133.       loadZomboidModel("hair_baldspot", locationModels + "hair_baldspot" + zExtension, null);
  134.       loadZomboidModel("hair_messy", locationModels + "hair_messy" + zExtension, null);
  135.       loadZomboidModel("hair_picard", locationModels + "hair_picard" + zExtension, null);
  136.       loadZomboidModel("hair_recede", locationModels + "hair_recede" + zExtension, null);
  137.       loadZomboidModel("hair_short", locationModels + "hair_short" + zExtension, null);
  138.       this.bCreated = true;
  139.     }
  140.   }
  141.  
  142.   public Model loadStaticObjModel(String name, String modelLocation, String textureLocation)
  143.   {
  144.     try
  145.     {
  146.       Model e = ModelLoader.loaderObj.load(modelLocation, textureLocation,
  147.         true);
  148.       this.ModelMap.put(name.toLowerCase(), e);
  149.       e.Name = name;
  150.       return e;
  151.     }
  152.     catch (IOException var5)
  153.     {
  154.       var5.printStackTrace();
  155.       return null;
  156.     }
  157.     catch (RuntimeException var6) {}
  158.     return null;
  159.   }
  160.  
  161.   public Model loadStaticZomboidModel(String name, String modelLocation, String textureLocation)
  162.   {
  163.     try
  164.     {
  165.       Model var5 = ModelLoader.loaderZomboid.load(modelLocation,
  166.         textureLocation, true);
  167.       this.ModelMap.put(name.toLowerCase(), var5);
  168.       var5.Name = name;
  169.       return var5;
  170.     }
  171.     catch (IOException var51)
  172.     {
  173.       var51.printStackTrace();
  174.     }
  175.     return null;
  176.   }
  177.  
  178.   public Model loadZomboidModel(String name, String modelLocation, String textureLocation)
  179.   {
  180.     try
  181.     {
  182.       Model var5 = ModelLoader.loaderZomboid.load(modelLocation,
  183.         textureLocation, false);
  184.       this.ModelMap.put(name.toLowerCase(), var5);
  185.       var5.Name = name;
  186.       return var5;
  187.     }
  188.     catch (IOException var51)
  189.     {
  190.       var51.printStackTrace();
  191.     }
  192.     return null;
  193.   }
  194.  
  195.   public void DoRender(int ID)
  196.   {
  197.     if (!((ModelSlot)this.ModelSlots.get(ID)).active)
  198.     {
  199.       GL11.glPushClientAttrib(-1);
  200.       GL11.glPushAttrib(1048575);
  201.       instance.bitmap.startDrawing(true, false);
  202.       GL11.glClearColor(1.0F, 0.0F, 0.0F, 1.0F);
  203.       GL11.glClear(16384);
  204.       GL11.glClearColor(0.0F, 0.0F, 0.0F, 1.0F);
  205.       instance.bitmap.endDrawing();
  206.       GL11.glPopAttrib();
  207.       GL11.glPopClientAttrib();
  208.     }
  209.     else
  210.     {
  211.       synchronized (((ModelSlot)this.ModelSlots.get(ID)).model.AnimPlayer)
  212.       {
  213.         GL11.glPushClientAttrib(-1);
  214.         GL11.glPushAttrib(1048575);
  215.         GL11.glEnable(2929);
  216.         GL11.glEnable(3042);
  217.         GL11.glBlendFunc(770, 771);
  218.         GL11.glEnable(3008);
  219.         GL11.glAlphaFunc(516, 0.0F);
  220.         ModelSlot modelSlot = (ModelSlot)this.ModelSlots.get(ID);
  221.         modelSlot.Start();
  222.         modelSlot.Render();
  223.         modelSlot.End();
  224.         GL11.glPopAttrib();
  225.         GL11.glPopClientAttrib();
  226.         GL11.glEnable(3553);
  227.         SpriteRenderer.ringBuffer.restoreVBOs = true;
  228.         GL11.glEnable(2929);
  229.         GL11.glEnable(3042);
  230.         GL11.glBlendFunc(770, 771);
  231.         GL11.glEnable(3008);
  232.         GL11.glAlphaFunc(516, 0.0F);
  233.       }
  234.     }
  235.   }
  236.  
  237.   public void DoneRendering(int ID)
  238.   {
  239.     if ((ID >= 0) && (ID < this.ModelSlots.size()))
  240.     {
  241.       ModelSlot modelSlot = (ModelSlot)this.ModelSlots.get(ID);
  242.       modelSlot.bRendering = false;
  243.     }
  244.   }
  245.  
  246.   public void Reset(IsoGameCharacter chr)
  247.   {
  248.     if ((chr.legsSprite != null) && (chr.legsSprite.modelSlot != null))
  249.     {
  250.       RenderThread.borrowContext();
  251.       while (SpriteRenderer.instance.DoingRender) {
  252.         try
  253.         {
  254.           Thread.sleep(2L);
  255.         }
  256.         catch (InterruptedException var3)
  257.         {
  258.           var3.printStackTrace();
  259.         }
  260.       }
  261.       DoCharacterModelParts(chr, chr.legsSprite.modelSlot);
  262.       chr.legsSprite.modelSlot.UpdateLights();
  263.       RenderThread.returnContext();
  264.     }
  265.   }
  266.  
  267.   public void Add(IsoGameCharacter chr)
  268.   {
  269.     if ((this.bCreated) && (PerformanceSettings.modelsEnabled) && (PerformanceSettings.support3D))
  270.     {
  271.       RenderThread.borrowContext();
  272.       this.Contains.add(chr);
  273.       ModelSlot slot = getSlot(chr);
  274.       if (!this.ModelSlots.contains(slot)) {
  275.         this.ModelSlots.add(slot);
  276.       }
  277.       if (((IsoDirectionFrame)chr.legsSprite.CurrentAnim.Frames.get(0)).getTexture(IsoDirections.N) != null)
  278.       {
  279.         String chrSprite = null;
  280.         chrSprite = ((IsoDirectionFrame)chr.legsSprite.CurrentAnim.Frames.get(0)).getTexture(IsoDirections.N).getName();
  281.         chrSprite = chrSprite.substring(0, chrSprite.indexOf("_"));
  282.         String chrTex = chr.legsSprite.name;
  283.        
  284.         assert ((!(chr instanceof IsoZombie)) || (((IsoZombie)chr).SpriteName.equals(chr.legsSprite.name)));
  285.        
  286.         slot.model = newInstance((Model)this.ModelMap.get(chrSprite.toLowerCase().contains("kate") ? "kate" : "male"), chr, null);
  287.         slot.model.LoadTexture(chrTex + "_Body");
  288.       }
  289.       DoCharacterModelParts(chr, slot);
  290.       slot.active = true;
  291.       chr.legsSprite.modelSlot = slot;
  292.       slot.UpdateLights();
  293.       RenderThread.returnContext();
  294.     }
  295.   }
  296.  
  297.   private void DoCharacterModelParts(IsoGameCharacter chr, ModelSlot slot)
  298.   {
  299.     slot.sub.clear();
  300.     String chrSprite = null;
  301.     if (((IsoDirectionFrame)chr.legsSprite.CurrentAnim.Frames.get(0)).getTexture(IsoDirections.N) != null)
  302.     {
  303.       chrSprite = ((IsoDirectionFrame)chr.legsSprite.CurrentAnim.Frames.get(0)).getTexture(IsoDirections.N).getName();
  304.       chrSprite = chrSprite.substring(0, chrSprite.indexOf("_"));
  305.       slot.model.LoadTexture(chr.legsSprite.name + "_Body");
  306.       slot.model.tintR = chr.legsSprite.getTintMod().r;
  307.       slot.model.tintG = chr.legsSprite.getTintMod().g;
  308.       slot.model.tintB = chr.legsSprite.getTintMod().b;
  309.     }
  310.     if ((chr.bottomsSprite != null) && (!chr.bottomsSprite.CurrentAnim.Frames.isEmpty()) && (((IsoDirectionFrame)chr.bottomsSprite.CurrentAnim.Frames.get(0)).getTexture(IsoDirections.N) != null))
  311.     {
  312.       String trouserSprite = ((IsoDirectionFrame)chr.bottomsSprite.CurrentAnim.Frames.get(0)).getTexture(IsoDirections.N).getName();
  313.       trouserSprite = trouserSprite.replace(chrSprite + "_", "");
  314.       if (trouserSprite.contains("F_")) {
  315.         trouserSprite = trouserSprite.substring(0, trouserSprite.indexOf("_", 2));
  316.       } else {
  317.         trouserSprite = trouserSprite.substring(0, trouserSprite.indexOf("_"));
  318.       }
  319.       ModelInstance topSprite = newInstance((Model)this.ModelMap.get(trouserSprite.toLowerCase()), chr, slot.model.AnimPlayer);
  320.       topSprite.LoadTexture(trouserSprite + "_White");
  321.       topSprite.tintR = chr.bottomsSprite.getTintMod().r;
  322.       topSprite.tintG = chr.bottomsSprite.getTintMod().g;
  323.       topSprite.tintB = chr.bottomsSprite.getTintMod().b;
  324.       slot.sub.add(topSprite);
  325.     }
  326.     if ((chr.topSprite != null) && (!chr.topSprite.CurrentAnim.Frames.isEmpty()) && (((IsoDirectionFrame)chr.topSprite.CurrentAnim.Frames.get(0)).getTexture(IsoDirections.N) != null))
  327.     {
  328.       String var12 = ((IsoDirectionFrame)chr.topSprite.CurrentAnim.Frames.get(0)).getTexture(IsoDirections.N).getName();
  329.       var12 = var12.replace(chrSprite + "_", "");
  330.       if (var12.contains("F_")) {
  331.         var12 = var12.substring(0, var12.indexOf("_", 2));
  332.       } else {
  333.         var12 = var12.substring(0, var12.indexOf("_"));
  334.       }
  335.       ModelInstance hairSprite = newInstance((Model)this.ModelMap.get(var12.toLowerCase()), chr, slot.model.AnimPlayer);
  336.       hairSprite.LoadTexture(var12 + "_White");
  337.       hairSprite.tintR = chr.topSprite.getTintMod().r;
  338.       hairSprite.tintG = chr.topSprite.getTintMod().g;
  339.       hairSprite.tintB = chr.topSprite.getTintMod().b;
  340.       slot.sub.add(hairSprite);
  341.     }
  342.     if ((chr.getDescriptor() != null) && (chr.getDescriptor().getHair() != null) && (!chr.getDescriptor().getHair().isEmpty()))
  343.     {
  344.       String var13 = chr.getDescriptor().getHair();
  345.       var13 = var13.replace("_White", "");
  346.       if (var13.equals("F_Hair")) {
  347.         var13 = "f_hair_kate";
  348.       }
  349.       if (this.ModelMap.get(var13.toLowerCase()) != null)
  350.       {
  351.         ModelInstance weapon = newInstance((Model)this.ModelMap.get(var13.toLowerCase()), chr, slot.model.AnimPlayer);
  352.         weapon.LoadTexture(var13.replace("_kate", "") + "_White");
  353.         weapon.tintR = chr.hairSprite.getTintMod().r;
  354.         weapon.tintG = chr.hairSprite.getTintMod().g;
  355.         weapon.tintB = chr.hairSprite.getTintMod().b;
  356.         slot.sub.add(weapon);
  357.       }
  358.     }
  359.     try
  360.     {
  361.       for (int var14 = 0; var14 < chr.extraSprites.size(); var14++)
  362.       {
  363.         IsoSprite weaponSprite = (IsoSprite)chr.extraSprites.get(var14);
  364.         if ((weaponSprite != null) && (weaponSprite.CurrentAnim != null) && (!weaponSprite.CurrentAnim.Frames.isEmpty()) && (((IsoDirectionFrame)weaponSprite.CurrentAnim.Frames.get(0)).getTexture(IsoDirections.N) != null))
  365.         {
  366.           String inst = ((IsoDirectionFrame)weaponSprite.CurrentAnim.Frames.get(0)).getTexture(IsoDirections.N).getName();
  367.           inst = inst.replace(chrSprite + "_", "");
  368.           inst = inst.substring(0, inst.lastIndexOf("_"));
  369.           inst = inst.substring(0, inst.lastIndexOf("_"));
  370.           inst = inst.substring(0, inst.lastIndexOf("_"));
  371.           inst = inst.substring(0, inst.lastIndexOf("_"));
  372.           inst = inst.replace("_White", "");
  373.           if (inst.equals("F_Hair")) {
  374.             inst = "f_hair_kate";
  375.           }
  376.           if (this.ModelMap.containsKey(inst.toLowerCase()))
  377.           {
  378.             ModelInstance inst1 = newInstance((Model)this.ModelMap.get(inst.toLowerCase()), chr, slot.model.AnimPlayer);
  379.             inst1.LoadTexture(inst.replace("_kate", "") + "_White");
  380.             inst1.tintR = weaponSprite.getTintMod().r;
  381.             inst1.tintG = weaponSprite.getTintMod().g;
  382.             inst1.tintB = weaponSprite.getTintMod().b;
  383.             slot.sub.add(inst1);
  384.           }
  385.         }
  386.       }
  387.     }
  388.     catch (Exception var11)
  389.     {
  390.       var11.printStackTrace();
  391.     }
  392.     if ((chr.getPrimaryHandItem() instanceof HandWeapon))
  393.     {
  394.       HandWeapon var15 = (HandWeapon)chr.getPrimaryHandItem();
  395.       String var16 = var15.getWeaponSprite();
  396.       if ((var16 != null) && (this.ModelMap.containsKey("weapons_" + var16.toLowerCase())))
  397.       {
  398.         ModelInstance var17 = newInstance((Model)this.ModelMap.get("weapons_" + var16.toLowerCase()), chr, slot.model.AnimPlayer);
  399.         slot.sub.add(var17);
  400.       }
  401.     }
  402.   }
  403.  
  404.   public void update()
  405.   {
  406.     for (int n = 0; n < this.ToResetNextFrame.size(); n++) {
  407.       Reset((IsoGameCharacter)this.ToResetNextFrame.get(n));
  408.     }
  409.     this.ToResetNextFrame.clear();
  410.     if (this.removeModels.Check()) {
  411.       for (n = 0; n < this.ToRemove.size(); n++) {
  412.         if (DoRemove((IsoGameCharacter)this.ToRemove.get(n), false)) {
  413.           this.ToRemove.remove(n--);
  414.         }
  415.       }
  416.     }
  417.     this.lights.clear();
  418.     if ((IsoWorld.instance != null) && (IsoWorld.instance.CurrentCell != null)) {
  419.       this.lights.addAll(IsoWorld.instance.CurrentCell.getLamppostPositions());
  420.     }
  421.   }
  422.  
  423.   private ModelSlot getSlot(IsoGameCharacter chr)
  424.   {
  425.     for (int n = 0; n < this.ModelSlots.size(); n++)
  426.     {
  427.       ModelSlot slot = (ModelSlot)this.ModelSlots.get(n);
  428.       if (slot.character == chr) {
  429.         return slot;
  430.       }
  431.     }
  432.     return new ModelSlot(this.ModelSlots.size(), newInstance(chr.isFemale() ? (Model)this.ModelMap.get("kate") : (Model)this.ModelMap.get("male"), chr, null), chr);
  433.   }
  434.  
  435.   private boolean DoRemove(IsoGameCharacter chr, boolean quitting)
  436.   {
  437.     if (this.Contains.contains(chr)) {
  438.       for (int n = 0; n < this.ModelSlots.size(); n++)
  439.       {
  440.         ModelSlot slot = (ModelSlot)this.ModelSlots.get(n);
  441.         if ((slot.character == chr) && ((quitting) || (!slot.bRendering)))
  442.         {
  443.           this.Contains.remove(chr);
  444.           slot.active = false;
  445.           slot.bRemove = false;
  446.           chr.legsSprite.modelSlot = null;
  447.           return true;
  448.         }
  449.       }
  450.     }
  451.     return false;
  452.   }
  453.  
  454.   public void Remove(IsoGameCharacter chr)
  455.   {
  456.     if ((chr.hasActiveModel()) &&
  457.       (this.Contains.contains(chr)) && (!this.ToRemove.contains(chr)))
  458.     {
  459.       chr.legsSprite.modelSlot.bRemove = true;
  460.       this.ToRemove.add(chr);
  461.     }
  462.   }
  463.  
  464.   public void ResetNextFrame(IsoGameCharacter isoGameCharacter)
  465.   {
  466.     this.ToResetNextFrame.add(isoGameCharacter);
  467.   }
  468.  
  469.   public void Reset()
  470.   {
  471.    
  472.     for (int ex = 0; ex < this.ToRemove.size(); ex++) {
  473.       DoRemove((IsoGameCharacter)this.ToRemove.get(ex), true);
  474.     }
  475.     this.ToRemove.clear();
  476.     try
  477.     {
  478.       if (!this.Contains.isEmpty())
  479.       {
  480.         IsoGameCharacter[] var7 = (IsoGameCharacter[])this.Contains.toArray(new IsoGameCharacter[this.Contains.size()]);
  481.         IsoGameCharacter[] arr$ = var7;
  482.         int len$ = var7.length;
  483.         for (int i$ = 0; i$ < len$; i$++)
  484.         {
  485.           IsoGameCharacter chr = arr$[i$];
  486.           DoRemove(chr, true);
  487.         }
  488.       }
  489.       this.ModelSlots.clear();
  490.     }
  491.     catch (Exception var6)
  492.     {
  493.       var6.printStackTrace();
  494.     }
  495.     RenderThread.returnContext();
  496.     this.lights.clear();
  497.     this.lightsTemp.clear();
  498.     compChar = null;
  499.   }
  500.  
  501.   public void getClosestThreeLights(IsoGameCharacter chr, IsoLightSource[] ret)
  502.   {
  503.     compChar = chr;
  504.     this.lightsTemp.clear();
  505.     for (int n = 0; n < this.lights.size(); n++)
  506.     {
  507.       IsoLightSource light = (IsoLightSource)this.lights.get(n);
  508.       if ((light.bActive) && ((light.localToBuilding == null) || (chr.getCurrentBuilding() == light.localToBuilding)) && (IsoUtils.DistanceTo(chr.x, chr.y, light.x + 0.5F, light.y + 0.5F) < light.radius) && (LosUtil.lineClear(IsoWorld.instance.CurrentCell, (int)compChar.x, (int)compChar.y, (int)compChar.z, light.x, light.y, light.z, false) != LosUtil.TestResults.Blocked)) {
  509.         this.lightsTemp.add(light);
  510.       }
  511.     }
  512.     Collections.sort(this.lightsTemp, comp);  
  513.       tmp193_192 = (ret[2] =  = null);ret[1] = tmp193_192;ret[0] = tmp193_192;
  514.     if (this.lightsTemp.size() > 0) {
  515.       ret[0] = ((IsoLightSource)this.lightsTemp.get(0));
  516.     }
  517.     if (this.lightsTemp.size() > 1) {
  518.       ret[1] = ((IsoLightSource)this.lightsTemp.get(1));
  519.     }
  520.     if (this.lightsTemp.size() > 2) {
  521.       ret[2] = ((IsoLightSource)this.lightsTemp.get(2));
  522.     }
  523.   }
  524.  
  525.   public ModelInstance newInstance(Model model, IsoGameCharacter chr, AnimationPlayer player)
  526.   {
  527.     if (model == null) {
  528.       int i = 0;
  529.     }
  530.     ModelInstance modelInst1 = new ModelInstance(model, chr, player);
  531.     modelInst1.UpdateDir();
  532.     if (modelInst1.AnimPlayer != null) {
  533.       modelInst1.AnimPlayer.angle = modelInst1.AnimPlayer.targetAngle;
  534.     }
  535.     AnimationTrack t = modelInst1.Play(chr.legsSprite.CurrentAnim.name, chr.def.Looped, chr.def.Finished, chr);
  536.     if (t != null)
  537.     {
  538.       t.syncToFrame(chr.def, chr.legsSprite.CurrentAnim);
  539.       modelInst1.AnimPlayer.Update(0.0F, true, null);
  540.     }
  541.     if ((model.Name.equals("male")) || (model.Name.equals("kate"))) {
  542.       modelInst1.updateLights = true;
  543.     }
  544.     return modelInst1;
  545.   }
  546.  
  547.   public static class AnimRequest
  548.   {
  549.     public float angle;
  550.     public String anim;
  551.     public SurvivorDesc desc;
  552.   }
  553.  
  554.   public static class ModelSlot
  555.   {
  556.     public int ID;
  557.     public ModelInstance model;
  558.     public IsoGameCharacter character;
  559.     ArrayList sub = new ArrayList();
  560.     public boolean active;
  561.     public boolean bRemove;
  562.     public boolean bRendering;
  563.    
  564.     public ModelSlot(int ID, ModelInstance model, IsoGameCharacter character)
  565.     {
  566.       this.ID = ID;
  567.       this.model = model;
  568.       this.character = character;
  569.     }
  570.    
  571.     public void Start()
  572.     {
  573.       GL11.glEnable(2929);
  574.       GL11.glEnable(3042);
  575.       GL11.glBlendFunc(770, 771);
  576.       GL11.glEnable(3008);
  577.       GL11.glAlphaFunc(516, 0.0F);
  578.       GL11.glDisable(3089);
  579.       ModelManager.instance.bitmap.startDrawing(true, true);
  580.       ModelCamera.instance.w = ModelManager.instance.bitmap.getTexture().getWidth();
  581.       ModelCamera.instance.h = ModelManager.instance.bitmap.getTexture().getHeight();
  582.     }
  583.    
  584.     public void Render()
  585.     {
  586.       this.model.Draw();
  587.       for (int n = 0; n < this.sub.size(); n++) {
  588.         ((ModelInstance)this.sub.get(n)).Draw();
  589.       }
  590.     }
  591.    
  592.     public void End()
  593.     {
  594.       ModelManager.instance.bitmap.endDrawing();
  595.     }
  596.    
  597.     public void Play(String name, boolean looped, boolean finished, IsoGameCharacter chr)
  598.     {
  599.       this.model.Play(name, looped, finished, chr);
  600.       for (int n = 0; n < this.sub.size(); n++) {
  601.         ((ModelInstance)this.sub.get(n)).Play(name, looped, finished, chr);
  602.       }
  603.     }
  604.    
  605.     public void Update()
  606.     {
  607.       float del = this.character.def.AnimFrameIncrease / this.character.legsSprite.CurrentAnim.Frames.size();
  608.       if (this.character.getLastSquare() != this.character.getCurrentSquare()) {
  609.         UpdateLights();
  610.       }
  611.       AnimationPlayer var2 = this.model.AnimPlayer;
  612.       synchronized (this.model.AnimPlayer)
  613.       {
  614.         this.model.UpdateDir();
  615.         this.model.Update(del);
  616.         for (int n = 0; n < this.sub.size(); n++)
  617.         {
  618.           ((ModelInstance)this.sub.get(n)).lights = this.model.lights;
  619.           ((ModelInstance)this.sub.get(n)).AnimPlayer = this.model.AnimPlayer;
  620.         }
  621.       }
  622.     }
  623.    
  624.     public void UpdateLights()
  625.     {
  626.       if ((this.model != null) && (this.character != null))
  627.       {
  628.         IsoLightSource[] var1 = this.model.lights;
  629.         synchronized (this.model.lights)
  630.         {
  631.           ModelManager.instance.getClosestThreeLights(this.character, this.model.lights);
  632.           for (int n = 0; n < this.sub.size(); n++) {
  633.             ((ModelInstance)this.sub.get(n)).lights = this.model.lights;
  634.           }
  635.         }
  636.       }
  637.     }
  638.    
  639.     public void ResetToFrameOne()
  640.     {
  641.       AnimationPlayer var1 = this.model.AnimPlayer;
  642.       synchronized (this.model.AnimPlayer)
  643.       {
  644.         this.model.AnimPlayer.ResetToFrameOne();
  645.         Iterator i$ = this.sub.iterator();
  646.         while (i$.hasNext())
  647.         {
  648.           ModelInstance subModel = (ModelInstance)i$.next();
  649.           subModel.AnimPlayer.ResetToFrameOne();
  650.         }
  651.       }
  652.     }
  653.    
  654.     public void DisableBlendingFrom(String clipName)
  655.     {
  656.       AnimationTrack track = this.model.AnimPlayer.getAnimTrack(clipName);
  657.       if (track != null) {
  658.         track.bFinished = true;
  659.       }
  660.     }
  661.   }
  662. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement