Advertisement
Guest User

Code using EverEnding ParticleSystem

a guest
Jul 10th, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 2.09 KB | None | 0 0
  1. // irrelevant sections of code excised, marked with  //...
  2. // In Main.hx
  3.  
  4. #if air
  5. if (Worker.current.isPrimordial)
  6. #end
  7. {
  8.     //...
  9.     #if air
  10.         var mutex:Mutex = null;
  11.         var worker:Worker = null;
  12.         if (MULTI_THREADED_PARTICLES)
  13.         {
  14.             mutex = new Mutex();
  15.             worker = WorkerDomain.current.createWorker(this.loaderInfo.bytes, true);
  16.             worker.setSharedProperty(INIT_MUTEX, mutex);
  17.             worker.start();
  18.             mutex.lock();
  19.         }
  20.         else
  21.             worker = Worker.current;
  22.         ParticleInterface.init(worker);
  23.     #end
  24.     {
  25.         ParticleSystem.init();
  26.     }
  27.    
  28.     ParticleInterface.setLayerSplit([0]);
  29.     //...
  30.     #if air
  31.         if (mutex != null)
  32.             mutex.unlock();
  33.     #end
  34.     //...
  35. }
  36. #if air
  37. else
  38. {  
  39.     //...
  40.     ParticleSystem.init();
  41. }
  42. #end
  43.  
  44. // In EveGame.hx
  45.  
  46. private function gameUpdate(time:Float):Void
  47. {
  48.     //...
  49.     #if air
  50.         ParticleInterface.receiveMessages();
  51.         ++mUpdatePhase;
  52.     #end
  53. }
  54.  
  55. #if air
  56. private function particleDrawListener(e:ParticleSystemEvent):Void
  57. {   ++mUpdatePhase;     }
  58.  
  59. private function drawParticles():Void
  60. {
  61.     if (ParticleInterface.systemReady)
  62.         ParticleInterface.draw();
  63.     else
  64.         ++mUpdatePhase;
  65. }
  66.  
  67. private function checkUpdate(e:TimerEvent):Void
  68. {
  69.     ParticleInterface.receiveMessages();
  70.     if (mUpdatePhase >= 2)
  71.         completeUpdate();
  72. }
  73. #else
  74. //...
  75. #end
  76.  
  77. private function completeUpdate(?e:Event):Void
  78. {
  79.     //...
  80.     ParticleInterface.setCamera(GameProperties.camera);
  81.     ParticleInterface.setZoom(mZoom);
  82.    
  83.     //...
  84.     #if air
  85.         mUpdatePhase = 0;
  86.         ParticleInterface.progress(time);
  87.         ParticleInterface.drawMutex.lock();
  88.         ParticleInterface.draw();
  89.     #else
  90.         //...
  91.     #end
  92.     //...
  93.     surface.copyPixels(ParticleInterface.layers[0], new Rectangle(0, 0, surface.width, surface.height), new Point(), null, null, true);
  94.     surface.copyPixels(mDrawSurface, new Rectangle(0, 0, mDrawSurface.width, mDrawSurface.height), new Point(), null, null, true);
  95.     surface.copyPixels(ParticleInterface.layers[1], new Rectangle(0, 0, surface.width, surface.height), new Point(), null, null, true);
  96.            
  97.     //...
  98.     #if air
  99.         ParticleInterface.drawMutex.unlock();
  100.     #elseif cpp
  101.         //...
  102.     #end
  103.     //...
  104.     gameUpdate(time);
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement