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;
 
The abstract Game.
 
 public abstract class Game implements UpdatableRenderableEngineHolder<CoreEngine> {

    
Logger is reserved for this abstract class
 
     private static final Logger LOGGER = LoggerFactory.getLogger(Game.class);

    
The root node. The user may not modify this! (only add child nodes)
 
     private Node mainNode;
    
The CoreEngine instance.
 
     private CoreEngine engine;

    
A simple Debugger.

See also:
GameDebugger
 
     private GameDebugger debugger;

    
The main InputManager, used to register key/mouse actions This will get used by the Engine as well.
 
     private InputManager inputManager;

    
Returns the dimensions of the window.

Returns:
The new window dimensions
 
     public abstract Dimension getWindowDimensions();

    
Returns the title of the window.

Returns:
The window title
 
     public abstract String getWindowTitle();


    
Delegates to the scenegraph and debugger

Parameters:
delta The delta time
 
     public void updateSceneGraph(float delta) {
         if (isDebug()) .update(delta);
         getSceneGraph().update(delta);
         update(delta);
     }

    
Injects the engine into game and scenegraph and inits the user's game.

Parameters:
engine The CoreEngine instance (parent)
 
     public final void preInit(CoreEngine engine) {
         setEngine(engine);
        getSceneGraph().setEngine(engine);
        // And init the user's game
        init(engine);
    }

    
The Game should load all resources and setup the scene here. A loading screen will get shown during this init process.

Parameters:
engine The CoreEngine instance (parent)
    public abstract void init(CoreEngine engine);

    
Renders the scenegraph

Parameters:
renderEngine The active RenderEngine instance
    public final void renderSceneGraph(RenderEngine renderEngine) {
        preRender(renderEngine);
        .trace("Rendering SceneGraph: {}"getSceneGraph());
        renderEngine.render(getSceneGraph());
        render(renderEngine);
    }

    
This method will get called before each render

Parameters:
renderEngine The active RenderEngine instance
    public void preRender(RenderEngine renderEngine) {
    }

    
Adds a node the scenegraph. Keep a reference to it, or the node's name, in order to retrieve the node at a later point easily.

Parameters:
node The node which should get added.
    public void add(Node node) {
        getSceneGraph().add(node);
        .trace("Node added to scene graph: {}"node);
    }

    
Adds a node the scenegraph. Keep a reference to it, or the node's name, in order to retrieve the node at a later point easily.

Parameters:
node The node which should get added.
    public void add(Node nodeboolean forceName) {
        getSceneGraph().add(nodeforceName);
        .trace("Node added to scene graph: {}"node);
    }

    
Retrives a node by it's name. If you want to get nested nodes, sperate the org.achtern.AchternEngine.core.scenegraph.Nodes names with a slash (/).

Parameters:
nodeName The node's name
Returns:
The node or null if not found
    public Node get(String nodeName) {
        // Example: nodeName = Meshes/Static/Box
        Node r;
        if (nodeName.contains("/")) {
            String[] nodes = nodeName.split("/");
            // -> 0: Meshes, 1: Static, 2: Box
            r = getSceneGraph().getChildren().get(nodes[0]);
            if (r == null) {
                return null;
            }
            for (int i = 1; i < nodes.lengthi++) {
                String name = nodes[i]; // 1 = nodes[1] => Static // 2 = nodes[2] => Box
                r = r.getChildren().get(name); // 1 = r = Node(Static) // 2 = r = Node(Box)
            }
        } else {
            r = getSceneGraph().getChildren().get(nodeName);
        }
        return r;
    }

    
Checks if a node exists in the scenegraph. Only checks the top level and NOT sup-nodes

Parameters:
node The node to check
Returns:
whether node has been found
    public boolean has(Node node) {
        return getSceneGraph().getChildren().containsValue(node);
    }

    
Removes a node from the scenegraph. Doesn't search in sub-nodes!

Parameters:
node The node to remove
    public void remove(Node node) {
        if (!has(node)) {
            throw new IllegalStateException("Node doesn' t exists");
        }
        getSceneGraph().remove(node);
    }

    
Removes a node from the scenegraph by it's name. Doesn't search in sub-nodes!

Parameters:
nodeName The node's name
Returns:
Whether the removing was successful
    public boolean remove(String nodeName) {
        Node toBeRemoved = getSceneGraph().getChildren().get(nodeName);
        return toBeRemoved != null && getSceneGraph().remove(toBeRemoved);
    }

    
Creates a new root Node, if it was null before.

Returns:
The scenegraph
    private Node getSceneGraph() {
        if ( == null) {
            .debug("Scene Graph created");
             = new Node("Scene Graph");
            .setEngine(getEngine());
        }
        return ;
    }

    
Returns the loading/splash image. Should only do minimal stuff! FAST FAST FAST If the texture is null, the engine's default image will get shown.

Returns:
A texture | null
    public Texture getSplashScreen() {
        return null;
    }

    
    public CoreEngine getEngine() {
        return ;
    }

    
    public void setEngine(CoreEngine engine) {
        this. = engine;
    }

    
Is this game in debug mode?

Returns:
whether debug is enabled
    public boolean isDebug() {
        return  != null;
    }

    
Enabled or disables the GameDebugger. On Disable the debugger will get destroyed and on re-enable a new one will get initiated.

Parameters:
debug To turn debug mode on or off (true | false)
    public void setDebug(boolean debug) {
        if (debug) {
             = new GameDebugger(this);
            .setEngine(getEngine());
            .enable();
        } else if ( != null) {
            .disable();
             = null;
        }
    }
    public GameDebugger getDebugger() {
        return ;
    }
    public InputManager getInputManager() {
        return ;
    }
    public void setInputManager(InputManager inputManager) {
        this. = inputManager;
    }
New to GrepCode? Check out our FAQ X