Package transientlibs.preui.objects.states

Source Code of transientlibs.preui.objects.states.TransientGame

//do not delete!
//-verbose:GC -XX:+PrintGCDateStamps -XX:+PrintGCDetails
package transientlibs.preui.objects.states;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.GL10;
import java.util.ArrayList;
import transientlibs.slick2d.util.Log;
import transientlibs.bindedobjects.gamecontent.MusicTrackGDX;
import transientlibs.bindedobjects.gamecontent.SoundsGDX;
import transientlibs.preui.agents.factories.AbstractCreatureFactory;
import transientlibs.preui.agents.factories.GDXInputProvider;
import transientlibs.processors.misc.Detonator;
import transientlibs.preui.agents.rendering.GameRenderer;

import transientlibs.processors.loaders.GenericAssetLoader;
import transientlibs.preui.agents.misc.MusicPlayerGDX;
import transientlibs.preui.gdx.game.TransientInput;
import transientlibs.maps.utils.coordcalculators.GDXScreenCoordsCalculator;
import transientlibs.maps.utils.movementcalculators.TiledTileMovementCalculator;
import transientlibs.maps.container.TransientAssembledMap;
import transientlibs.preui.agents.rendering.GDXGeometryAgent;
import transientlibs.preui.objects.gui.elements.Marker;
import transientlibs.preui.objects.states.IState;

import transientlibs.preui.gdx.gui.MouseHack;

/**
*
* @author kibertoad
*/
public abstract class TransientGame implements ApplicationListener, IGame {

    public GameRenderer renderer;
    public static final int MainMenuStateID = 1;
    public static final int LoadingStateID = 2;
    public static final int StoryStateID = 3;
    public static final int QuitStateID = 4;
    public static final int CreditsStateID = 5;
    public static final int TiledMapStateID = 6;
    public static final int OptionsStateID = 7;
    public static final int TutorialStateID = 8;
    public static final int IntroStateID = 9;
    public static final int CityStateID = 10;

    @Override
    public void processInput() {
        input.process();
    }
    //public Stage stage = new Stage();
    public AssetManager manager;
    public ArrayList<IState> states = new ArrayList<IState>();
    public static TransientGame game;
    //public static LwjglApplication app;
    public int screenSizeX = 640;
    public int screenSizeY = 480;
    public boolean useGL2 = true;
    private static final long serialVersionUID = 1L;
    private boolean running = false;
    public IState state;
    public TransientInput input;
    //private final boolean started = false;
    private float accum = 0;
    String module = "";
    private String fps;
    public GenericAssetLoader loader;
    public boolean regenerateAtlases;
    public int elapsedTimeSinceLastFrame;
    public int step = 1;

    public abstract void setToFirstState();

    public TransientGame(String setName) {
        module = setName;
    }

    public void attachAgents() {
        Detonator.INSTANCE.currentGenericGame = this;
        Detonator.INSTANCE.creatureFactory = new AbstractCreatureFactory();
        Detonator.INSTANCE.screenCoordsCalculator = new GDXScreenCoordsCalculator();
        Detonator.INSTANCE.musicPlayer = new MusicPlayerGDX();

        Detonator.INSTANCE.geometryAgent = new GDXGeometryAgent();
        Detonator.INSTANCE.geometryAgent.init();

        MusicTrackGDX.musicEnabled = Detonator.INSTANCE.musicIsOn;
        SoundsGDX.soundEnabled = Detonator.INSTANCE.soundIsOn;

        MusicTrackGDX.musicEnabled.value = false;


        input = new TransientInput();
        Detonator.INSTANCE.inputProvider = new GDXInputProvider(input);
        renderer = new GameRenderer(this);
    }

    public void attachState(IState state) {
        state.init();
        state.postInit();
        states.add(state);

        //state.setStateDrawAgent(new GDXGenericStateDrawAgent(state));
    }

    public void attachStates() {
        Detonator.INSTANCE.tileMovementCalculator = new TiledTileMovementCalculator((TransientAssembledMap) Detonator.INSTANCE.currentMap);
    }

    @Override
    public IState getStateByCode(String byCode) {
        for (IState s : states) {
            if (s.getStringID().equals(byCode)) {
                return s;
            }
        }
        Log.error("No state with name: " + byCode + "!!!");

        return null;
    }

    @Override
    public void changeState(String byCode) {
        changeState(getStateByCode(byCode));
    }

    @Override
    public void create() {

        regenerateAtlases = Detonator.INSTANCE.regenerateImageList.value;

        attachAgents();
        Gdx.input.setInputProcessor(input);


        if (Detonator.INSTANCE.useCustomLoader == false) {
            loader = new GenericAssetLoader(module);
            loader.regenerateAtlases = regenerateAtlases;

            loader.processGeneric();
            loader.selectModule();
            loader.process();
        } else {

            loader = new GenericAssetLoader("-");
            loader.regenerateAtlases = regenerateAtlases;
            loader.processGeneric();
        }


        running = true;

        attachStates();
        setToFirstState();

        this.screenSizeY = Gdx.graphics.getHeight();

        Marker.ScreenHeight = this.screenSizeY;
        Detonator.INSTANCE.ScreenSizeY = this.screenSizeY;
       

        //Gdx.input.setInputProcessor(input);
        //running = true;
        //setScreen(new TitleScreen());
        // Gdx.graphics.setVSync(true);
    }

    //@Override
    public void renderAlt3() {

        Gdx.gl.glClearColor(0, 0, 0, 1);
        Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

        state.render();

        //Reset the player if it is offscreen

        input.storedDelta = Gdx.graphics.getDeltaTime();
        state.tick(input);
        input.tick();
        //player.update();              
    }

    //this one is somewhat ok
    @Override
    public void render() {
        renderer.render();
    }

    @Override
    public TransientInput getInput() {
        return input;
    }

    public void setInput(TransientInput input) {
        this.input = input;
    }

    @Override
    public void pause() {
        running = false;
    }

    @Override
    public void resume() {
        running = true;
    }

    @Override
    public void resize(int width, int height) {
        //state.stage.stage.setViewport(width, height, true);
        MouseHack.resize(width, height);
        state.resize(width, height);
    }

    @Override
    public void dispose() {
        //state.stage.stage.dispose();
        state.dispose();
        //manager.dispose();              
    }

    public void changeState(IState toState) {
        if (state != null) {
            //state.removed();
        }

        if (toState != null) {

            if (!(toState.isInitted())) {
                toState.init(this);
            }

            Log.info("Now entering:" + toState.getStringID());
            toState.enter();
        }

        state = toState;
    }

    @Override
    public void changeState(int toState) {
        for (IState is : states) {
            if (is.getID() == toState) {
                changeState(is);
            } else {
                Log.error("Unknown state: " + toState);
            }
        }
    }

    @Override
    public int getTiledMapStateID() {
        return TiledMapStateID;
    }

    @Override
    public int getNewGameStateID() {
        return TiledMapStateID;
    }

    @Override
    public int getCreditsStateID() {
        return CreditsStateID;
    }

    @Override
    public int getScreenHeight() {
        return screenSizeY;
    }

    @Override
    public float getScreenWidth() {
        return screenSizeX;
    }

    @Override
    public int getMainMenuStateID() {
        return MainMenuStateID;
    }

    @Override
    public int getQuitStateID() {
        return QuitStateID;
    }

    @Override
    public IState getCurrentState() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public IState getTiledMapState() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
}
TOP

Related Classes of transientlibs.preui.objects.states.TransientGame

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.