/*     */ package org.engine;
/*     */ 
/*     */ import org.lwjgl.glfw.GLFW;
/*     */ import org.lwjgl.glfw.GLFWErrorCallback;
/*     */ import org.lwjgl.glfw.GLFWErrorCallbackI;
/*     */ import org.lwjgl.opengl.GL;
/*     */ import org.ui.UIAccess;
/*     */ import org.ui.icons.IconLoader;
/*     */ import org.view.Camera;
/*     */ import org.world.World;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class Engine
/*     */ {
/*     */   private GLFWErrorCallback errorCallback;
/*     */   private Display display;
/*     */   private Renderer renderer;
/*     */   private Camera camera;
/*     */   private UIAccess ui;
/*     */   private World world;
/*     */   private float globalTime;
/*     */   private float elapsedTime;
/*     */   
/*     */   public Engine() {
/*     */     try {
/*  40 */       this.ui = new UIAccess();
/*     */       
/*  42 */       this.ui.putInfoLoadingMessage("Loading Icon set...", 10);
/*     */       
/*  44 */       IconLoader.loadIcons();
/*     */       
/*  46 */       GLFW.glfwSetErrorCallback((GLFWErrorCallbackI)(this.errorCallback = GLFWErrorCallback.createPrint(System.err)));
/*     */       
/*  48 */       this.ui.putInfoLoadingMessage("Initalizing GLFW...", 25);
/*     */       
/*  50 */       if (!GLFW.glfwInit()) {
/*  51 */         throw new AssertionError("Could not initalize GLFW!");
/*     */       }
/*  53 */       this.ui.putInfoLoadingMessage("Creating GLFW window...", 50);
/*     */       
/*  55 */       this.display = new Display(this.ui.getWindowIcon());
/*     */ 
/*     */       
/*  58 */       GLFW.glfwSwapInterval(1);
/*     */       
/*  60 */       GL.createCapabilities();
/*     */       
/*  62 */       this.ui.putInfoLoadingMessage("Creating Shaders...", 65);
/*     */       
/*  64 */       this.renderer = new Renderer(this.display.getSize());
/*     */       
/*  66 */       this.ui.putInfoLoadingMessage("Setting up window callbacks", 80);
/*     */       
/*  68 */       this.camera = new Camera(this.display.getWindowHandle());
/*     */       
/*  70 */       this.ui.putInfoLoadingMessage("Creating World...", 90);
/*     */       
/*  72 */       this.world = new World();
/*     */       
/*  74 */       this.ui.putInfoLoadingMessage("Done", 100);
/*     */     }
/*  76 */     catch (Exception e) {
/*  77 */       e.printStackTrace();
/*     */     } finally {
/*     */       
/*  80 */       this.ui.close();
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public final void run() {
/*     */     try {
/*  94 */       this.ui.apply(this.world, this.renderer.getPpConfig());
/*     */
/*  96 */       this.display.show();

/*     */       
/*  98 */       // this.ui.openDocs();


/*     */
/* 101 */       while (this.display.shouldNotClose() && !this.ui.windowCloseRequest()) {

/*     */         
/* 103 */         long startTime = System.currentTimeMillis();
/*     */         
/* 105 */         GLFW.glfwPollEvents();
/*     */         
/* 107 */         if (this.world.getGytebot() != null)
/*     */         {
/* 109 */           this.world.getGytebot().updateRotation(this.elapsedTime);
/*     */         }
/*     */         
/* 112 */         this.camera.update(this.elapsedTime);
/*     */         
/* 114 */         this.renderer.update(this.display.getSize(), this.globalTime, this.camera, this.world, this.display.wasScaled());
/*     */         
/* 116 */         this.renderer.render();
/*     */         
/* 118 */         this.display.swapBuffers();
/*     */ 
/*     */         
/* 121 */         long passedTime = System.currentTimeMillis() - startTime;
/*     */         
/* 123 */         if (passedTime < 16L) {
/* 124 */           Thread.sleep(16L - passedTime);
/*     */         }
/*     */         
/* 127 */         this.elapsedTime = (float)(System.currentTimeMillis() - startTime) * 0.001F;
/*     */         
/* 129 */         this.globalTime += this.elapsedTime;
/*     */       } 
/* 131 */     } catch (InterruptedException e) {
/*     */       
/* 133 */       e.printStackTrace();
/*     */     } finally {
/*     */       
/* 136 */       close();
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private final void close() {
/*     */     try {
/* 145 */       this.errorCallback.free();
/*     */       
/* 147 */       this.camera.close();
/* 148 */       this.display.close();
/* 149 */       this.renderer.close();
/* 150 */     } catch (Exception e) {
/* 151 */       e.printStackTrace();
/*     */     } finally {
/*     */       
/* 154 */       GLFW.glfwTerminate();
/* 155 */       System.exit(0);
/*     */     } 
/*     */   }
/*     */ 
/*     */   
/*     */   public static void main(String[] args) {
/* 161 */     (new Engine()).run();
/*     */   }
/*     */ }


/* Location:              /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/engine/Engine.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */