/*
* Copyright 2013 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.terasology.engine.modes;
import org.terasology.engine.ComponentSystemManager;
import org.terasology.engine.GameEngine;
import org.terasology.engine.bootstrap.EntitySystemBuilder;
import org.terasology.engine.module.ModuleManager;
import org.terasology.entitySystem.entity.EntityRef;
import org.terasology.entitySystem.entity.internal.EngineEntityManager;
import org.terasology.entitySystem.event.internal.EventSystem;
import org.terasology.logic.console.Console;
import org.terasology.logic.console.internal.ConsoleImpl;
import org.terasology.logic.console.internal.ConsoleSystem;
import org.terasology.logic.console.internal.CoreCommands;
import org.terasology.logic.players.LocalPlayer;
import org.terasology.network.ClientComponent;
import org.terasology.network.NetworkSystem;
import org.terasology.reflection.copy.CopyStrategyLibrary;
import org.terasology.reflection.reflect.ReflectFactory;
import org.terasology.registry.CoreRegistry;
import org.terasology.rendering.nui.NUIManager;
import org.terasology.rendering.nui.internal.NUIManagerInternal;
/**
* The class provides the basics for the setup stage for the game, where the game parameters are defined
*
* @author Benjamin Glatzel <benjamin.glatzel@me.com>
* @author Anton Kireev <adeon.k87@gmail.com>
* @author Marcel Lehwald <marcel.lehwald@googlemail.com>
* @version 0.3
*/
public class StateSetup implements GameState {
private EngineEntityManager entityManager;
private EventSystem eventSystem;
private ComponentSystemManager componentSystemManager;
public StateSetup() {
}
@Override
public void init(GameEngine gameEngine) {
// let's get the entity event system running
entityManager = new EntitySystemBuilder().build(CoreRegistry.get(ModuleManager.class).getEnvironment(), CoreRegistry.get(NetworkSystem.class),
CoreRegistry.get(ReflectFactory.class), CoreRegistry.get(CopyStrategyLibrary.class));
eventSystem = CoreRegistry.get(EventSystem.class);
CoreRegistry.put(Console.class, new ConsoleImpl());
NUIManager nuiManager = CoreRegistry.get(NUIManager.class);
((NUIManagerInternal) nuiManager).refreshWidgetsLibrary();
componentSystemManager = new ComponentSystemManager();
CoreRegistry.put(ComponentSystemManager.class, componentSystemManager);
componentSystemManager.register(new ConsoleSystem(), "engine:ConsoleSystem");
componentSystemManager.register(new CoreCommands(), "engine:CoreCommands");
EntityRef localPlayerEntity = entityManager.create(new ClientComponent());
LocalPlayer localPlayer = CoreRegistry.put(LocalPlayer.class, new LocalPlayer());
localPlayer.setClientEntity(localPlayerEntity);
componentSystemManager.initialise();
}
@Override
public void dispose() {
eventSystem.process();
componentSystemManager.shutdown();
entityManager.clear();
CoreRegistry.clear();
}
@Override
public void handleInput(float delta) {
}
@Override
public void update(float delta) {
eventSystem.process();
}
@Override
public void render() {
}
@Override
public boolean isHibernationAllowed() {
return true;
}
}