Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * The MIT License (MIT)
   *
   * Copyright (c) 2014 Christian Gärtner
   *
   * Permission is hereby granted, free of charge, to any person obtaining a copy
   * of this software and associated documentation files (the "Software"), to deal
   * in the Software without restriction, including without limitation the rights
   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  * copies of the Software, and to permit persons to whom the Software is
  * furnished to do so, subject to the following conditions:
  *
  * The above copyright notice and this permission notice shall be included in all
  * copies or substantial portions of the Software.
  *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  * SOFTWARE.
  */
 
 package org.achtern.AchternEngine.core;
 
 
 import java.util.List;

The CoreEngine is the main entry point of the AchternEngine. The Engine is running the main loop and manages Game and RenderEngine, as well as the org.achtern.AchternEngine.core.bootstrap.MainBindingProvider.
 
 public class CoreEngine implements RunnableEngineHolder<RenderEngine> {
 
     public static final Logger LOGGER = LoggerFactory.getLogger(CoreEngine.class);

    
Only used during bootstrap to manage the hardware/graphics/native binding
 
     protected MainBindingProvider bindingManager;

    
The Main Render Window
 
     protected Window window;
 
 
     private static boolean stopRequest = false;
 
     private boolean running;
 
     private Game game;
     private RenderEngine renderEngine;
 
     private double frameTime;
 
     private FPS fps;

    
Request a force stop of the engine
 
     public static void requestStop() {
          = true;
     }

    
Whether a force stop was request via requestStop()

Returns:
stopRequest
 
     public static boolean stopRequested() {
         return ;
     }

    
Creates a new Game Holder and runner

Parameters:
game The game to run.
provider The Graphics Binding
See also:
org.achtern.AchternEngine.core.bootstrap.BindingProvider
 
     public CoreEngine(Game gameBindingProvider provider) {
         this(gamenew MainBindingProvider(provider));
     }

    
Creates a new Game Holder and runner

Parameters:
game The game to run.
binding Binding Manager
    public CoreEngine(Game gameMainBindingProvider binding) {
        .debug(BuildInfo.get());
        this. = game;
        this. = false;
        this. = new FPS();
        this. = binding;
    }

    
Creates a new Window.

Parameters:
title The window's title
dimensions The window's dimensions
    protected void createWindow(String titleDimension dimensions) {
         = .getWindow(dimensions);
        .create(title);
        this. = new BasicRenderEngine();
        .debug("OpenGL Version: {}"this..getState().getVersion());
    }

    
Starts the game, limiting it to a given framerate (fps)

Parameters:
framerate The max. framerate (fps)
    public void start(double framerate) {
        this. = 1 / framerate;
        if () {
            return;
        }
        run();
    }

    
Stops the game.
    protected void stop() {
        if (!) {
            return;
        }
         = false;
    }

    
Runs the game. First it inits it. This will show a loading screen. And then update, input and renders it.
    @Override
    public void run() {
        // Pre loading images here
        // this way there is a shorter period of
        // the black screen.
        if (.getSplashScreen() == null) {
            LoadingScreen.get().preLoad();
        }
         = true;
        LoadingScreen.get().show(this.getSplashScreen());
        .info("Initializing Game");
        .preInit(this);
        .info("Done initializing Game");
        double lastTime = Time.getTime();
        double unprocessedTime = 0;
        while () {
            boolean render = false;
            double startTime = Time.getTime();
            double passedTime = startTime - lastTime;
            lastTime = startTime;
            unprocessedTime += passedTime;
            .passed(passedTime);
            while (unprocessedTime > ) {
                render = true;
                unprocessedTime -= ;
                if (.isCloseRequested() || stopRequested()) {
                    stop();
                }
                .updateSceneGraph((float);
                .getInputManager().trigger((float);
                .display();
            }
            if (render) {
                .renderSceneGraph();
                .render();
                .rendered();
            }
            if (.resized()) {
                for (WindowChangeListener l : ) {
                    l.onWindowChange();
                }
            }
        }
        cleanUp();
    }

    
Disposes the window. Destroying Mouse and Keyboard.
    public void cleanUp() {
        .dispose();
        .info("Shutdown.");
    }
    public void addWindowChangeListener(WindowChangeListener listener) {
        .add(listener);
    }
    public void removeWindowChangeListener(WindowChangeListener listener) {
        .remove(listener);
    }

    
Returns the FPS counter

Returns:
the FPS counter
    public FPS getFps() {
        return ;
    }

    
A nice name for getEngine(). Nothing more. But will return the associated render engine.

Returns:
The main render engine
    public RenderEngine getRenderEngine() {
        return getEngine();
    }

    
    @Override
    public void setEngine(RenderEngine engine) {
        this. = engine;
    }

    
    @Override
    public RenderEngine getEngine() {
        return ;
    }
    public Game getGame() {
        return ;
    }
        return ;
    }
    public void setBindingManager(MainBindingProvider bindingManager) {
        this. = bindingManager;
    }
    public Window getWindow() {
        return ;
    }
New to GrepCode? Check out our FAQ X