Search in sources :

Example 1 with PlayerStore

use of org.terasology.engine.persistence.PlayerStore in project Terasology by MovingBlocks.

the class StorageManagerTest method testCharacterSurvivesStorage.

@Test
public void testCharacterSurvivesStorage() {
    esm.waitForCompletionOfPreviousSaveAndStartSaving();
    esm.finishSavingAndShutdown();
    PlayerStore restored = esm.loadPlayerStore(PLAYER_ID);
    restored.restoreEntities();
    assertTrue(restored.hasCharacter());
    assertEquals(character, restored.getCharacter());
}
Also used : PlayerStore(org.terasology.engine.persistence.PlayerStore) Test(org.junit.jupiter.api.Test)

Example 2 with PlayerStore

use of org.terasology.engine.persistence.PlayerStore in project Terasology by MovingBlocks.

the class StorageManagerTest method testPlayerRelevanceLocationSurvivesStorage.

@Test
public void testPlayerRelevanceLocationSurvivesStorage() {
    Vector3f loc = new Vector3f(1, 2, 3);
    character.addComponent(new LocationComponent(loc));
    esm.waitForCompletionOfPreviousSaveAndStartSaving();
    esm.finishSavingAndShutdown();
    PlayerStore restored = esm.loadPlayerStore(PLAYER_ID);
    assertEquals(loc, restored.getRelevanceLocation());
}
Also used : PlayerStore(org.terasology.engine.persistence.PlayerStore) Vector3f(org.joml.Vector3f) LocationComponent(org.terasology.engine.logic.location.LocationComponent) Test(org.junit.jupiter.api.Test)

Example 3 with PlayerStore

use of org.terasology.engine.persistence.PlayerStore in project Terasology by MovingBlocks.

the class StorageManagerTest method testGetUnstoredPlayerReturnsNewStor.

@Test
@Order(1)
public void testGetUnstoredPlayerReturnsNewStor() {
    PlayerStore store = esm.loadPlayerStore(PLAYER_ID);
    assertNotNull(store);
    assertEquals(new Vector3f(), store.getRelevanceLocation());
    assertFalse(store.hasCharacter());
    assertEquals(PLAYER_ID, store.getId());
}
Also used : PlayerStore(org.terasology.engine.persistence.PlayerStore) Vector3f(org.joml.Vector3f) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test)

Example 4 with PlayerStore

use of org.terasology.engine.persistence.PlayerStore in project Terasology by MovingBlocks.

the class PlayerSystem method update.

@Override
public void update(float delta) {
    Iterator<SpawningClientInfo> i = clientsPreparingToSpawn.iterator();
    while (i.hasNext()) {
        SpawningClientInfo spawning = i.next();
        if (worldProvider.isBlockRelevant(spawning.position)) {
            PlayerStore playerStore = spawning.playerStore;
            if (playerStore == null) {
                spawnPlayer(spawning.clientEntity);
            } else {
                playerStore.restoreEntities();
                EntityRef character = playerStore.getCharacter();
                restoreCharacter(spawning.clientEntity, character);
            }
            i.remove();
        }
    }
    i = clientsPreparingToRespawn.iterator();
    while (i.hasNext()) {
        SpawningClientInfo spawning = i.next();
        if (worldProvider.isBlockRelevant(spawning.position)) {
            respawnPlayer(spawning.clientEntity);
            i.remove();
        }
    }
}
Also used : PlayerStore(org.terasology.engine.persistence.PlayerStore) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef)

Example 5 with PlayerStore

use of org.terasology.engine.persistence.PlayerStore in project Terasology by MovingBlocks.

the class PlayerSystem method onConnect.

@ReceiveEvent(components = ClientComponent.class)
public void onConnect(ConnectedEvent connected, EntityRef entity) {
    LocationComponent loc = entity.getComponent(LocationComponent.class);
    // for new clients, the player store will return default values
    PlayerStore playerStore = connected.getPlayerStore();
    Client owner = networkSystem.getOwner(entity);
    Vector3ic minViewDist = ViewDistance.LEGALLY_BLIND.getChunkDistance();
    if (playerStore.hasCharacter()) {
        Vector3fc storedLocation = playerStore.getRelevanceLocation();
        loc.setWorldPosition(storedLocation);
        entity.saveComponent(loc);
        if (worldProvider.isBlockRelevant(storedLocation)) {
            // chunk for spawning location is ready, so spawn right now
            playerStore.restoreEntities();
            EntityRef character = playerStore.getCharacter();
            Vector3ic viewDist = owner.getViewDistance().getChunkDistance();
            addRelevanceEntity(entity, viewDist, owner);
            restoreCharacter(entity, character);
        } else {
            // otherwise wait until chunk is ready
            addRelevanceEntity(entity, minViewDist, owner);
            clientsPreparingToSpawn.add(new SpawningClientInfo(entity, storedLocation, playerStore));
        }
    } else {
        Vector3fc spawnPosition = worldGenerator.getSpawnPosition(entity);
        loc.setWorldPosition(spawnPosition);
        entity.saveComponent(loc);
        addRelevanceEntity(entity, minViewDist, owner);
        if (worldProvider.isBlockRelevant(spawnPosition)) {
            spawnPlayer(entity);
        } else {
            clientsPreparingToSpawn.add(new SpawningClientInfo(entity, spawnPosition));
        }
    }
}
Also used : Vector3fc(org.joml.Vector3fc) PlayerStore(org.terasology.engine.persistence.PlayerStore) Vector3ic(org.joml.Vector3ic) Client(org.terasology.engine.network.Client) LocationComponent(org.terasology.engine.logic.location.LocationComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Aggregations

PlayerStore (org.terasology.engine.persistence.PlayerStore)8 Test (org.junit.jupiter.api.Test)5 Vector3f (org.joml.Vector3f)3 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)3 LocationComponent (org.terasology.engine.logic.location.LocationComponent)2 Vector3fc (org.joml.Vector3fc)1 Vector3ic (org.joml.Vector3ic)1 Order (org.junit.jupiter.api.Order)1 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)1 EngineEntityManager (org.terasology.engine.entitySystem.entity.internal.EngineEntityManager)1 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)1 Client (org.terasology.engine.network.Client)1 ConnectedEvent (org.terasology.engine.network.events.ConnectedEvent)1 StorageManager (org.terasology.engine.persistence.StorageManager)1 EntityRefComponent (org.terasology.unittest.stubs.EntityRefComponent)1