-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Sectors/pools: v2.0.0 branch #3009
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c636183
Implement entity pools
Vizaxo 3e8945f
Add SectorManager to implement sectors
Vizaxo 556f21a
Improve code quality in EntityManager and EntityPool
Vizaxo 7c2ec1c
Allow serialization of entity scope (sector or global)
Vizaxo 96a2965
Clean up EntityPool and EntityManager methods
Vizaxo 633e776
Add moveToPool method for PojoEntityManager
Vizaxo 12c0f5e
Make small fixes and clean up PojoEntityManager
Vizaxo 1518b0e
Update EntityPool-related tests and make them pass
Vizaxo 7dc2257
Add the SectorSimulationSystem
Vizaxo f2efc0e
Convert protobuf entity scope enum to EntityScope
Vizaxo 063fb2f
Small sector/pool updates (primarily documentation)
Vizaxo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
engine-tests/src/test/java/org/terasology/entitySystem/BaseEntityRefTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright 2017 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.entitySystem; | ||
|
||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.terasology.assets.AssetFactory; | ||
import org.terasology.assets.management.AssetManager; | ||
import org.terasology.assets.module.ModuleAwareAssetTypeManager; | ||
import org.terasology.context.Context; | ||
import org.terasology.context.internal.ContextImpl; | ||
import org.terasology.engine.bootstrap.EntitySystemSetupUtil; | ||
import org.terasology.engine.module.ModuleManager; | ||
import org.terasology.entitySystem.entity.EntityManager; | ||
import org.terasology.entitySystem.entity.EntityRef; | ||
import org.terasology.entitySystem.entity.internal.PojoEntityManager; | ||
import org.terasology.entitySystem.prefab.Prefab; | ||
import org.terasology.entitySystem.prefab.PrefabData; | ||
import org.terasology.entitySystem.prefab.internal.PojoPrefab; | ||
import org.terasology.network.NetworkSystem; | ||
import org.terasology.registry.CoreRegistry; | ||
import org.terasology.testUtil.ModuleManagerFactory; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.Mockito.mock; | ||
import static org.terasology.entitySystem.entity.internal.EntityScope.GLOBAL; | ||
import static org.terasology.entitySystem.entity.internal.EntityScope.SECTOR; | ||
|
||
public class BaseEntityRefTest { | ||
|
||
private static Context context; | ||
private PojoEntityManager entityManager; | ||
private EntityRef ref; | ||
|
||
@BeforeClass | ||
public static void setupClass() throws Exception { | ||
context = new ContextImpl(); | ||
ModuleManager moduleManager = ModuleManagerFactory.create(); | ||
context.put(ModuleManager.class, moduleManager); | ||
ModuleAwareAssetTypeManager assetTypeManager = new ModuleAwareAssetTypeManager(); | ||
assetTypeManager.registerCoreAssetType(Prefab.class, | ||
(AssetFactory<Prefab, PrefabData>) PojoPrefab::new, "prefabs"); | ||
assetTypeManager.switchEnvironment(moduleManager.getEnvironment()); | ||
context.put(AssetManager.class, assetTypeManager.getAssetManager()); | ||
CoreRegistry.setContext(context); | ||
} | ||
|
||
@Before | ||
public void setup() { | ||
context.put(NetworkSystem.class, mock(NetworkSystem.class)); | ||
EntitySystemSetupUtil.addReflectionBasedLibraries(context); | ||
EntitySystemSetupUtil.addEntityManagementRelatedClasses(context); | ||
entityManager = (PojoEntityManager) context.get(EntityManager.class); | ||
|
||
ref = entityManager.create(); | ||
} | ||
|
||
@Test | ||
public void testSetScope() { | ||
assertEquals(ref.getScope(), GLOBAL); | ||
assertTrue(entityManager.getGlobalPool().contains(ref.getId())); | ||
assertFalse(entityManager.getSectorManager().contains(ref.getId())); | ||
|
||
//Move into sector scope | ||
ref.setScope(SECTOR); | ||
assertEquals(ref.getScope(), SECTOR); | ||
assertTrue(entityManager.getSectorManager().contains(ref.getId())); | ||
assertFalse(entityManager.getGlobalPool().contains(ref.getId())); | ||
|
||
//And move back to global scope | ||
ref.setScope(GLOBAL); | ||
assertEquals(ref.getScope(), GLOBAL); | ||
assertTrue(entityManager.getGlobalPool().contains(ref.getId())); | ||
assertFalse(entityManager.getSectorManager().contains(ref.getId())); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
engine-tests/src/test/java/org/terasology/entitySystem/PojoEntityPoolTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright 2017 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.entitySystem; | ||
|
||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.terasology.assets.AssetFactory; | ||
import org.terasology.assets.management.AssetManager; | ||
import org.terasology.assets.module.ModuleAwareAssetTypeManager; | ||
import org.terasology.context.Context; | ||
import org.terasology.context.internal.ContextImpl; | ||
import org.terasology.engine.bootstrap.EntitySystemSetupUtil; | ||
import org.terasology.engine.module.ModuleManager; | ||
import org.terasology.entitySystem.entity.EntityManager; | ||
import org.terasology.entitySystem.entity.EntityRef; | ||
import org.terasology.entitySystem.entity.internal.PojoEntityManager; | ||
import org.terasology.entitySystem.entity.internal.PojoEntityPool; | ||
import org.terasology.entitySystem.prefab.Prefab; | ||
import org.terasology.entitySystem.prefab.PrefabData; | ||
import org.terasology.entitySystem.prefab.internal.PojoPrefab; | ||
import org.terasology.network.NetworkSystem; | ||
import org.terasology.registry.CoreRegistry; | ||
import org.terasology.testUtil.ModuleManagerFactory; | ||
|
||
import static junit.framework.TestCase.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.Mockito.mock; | ||
|
||
/** | ||
*/ | ||
public class PojoEntityPoolTest { | ||
|
||
private PojoEntityPool pool; | ||
private static Context context; | ||
private PojoEntityManager entityManager; | ||
|
||
@BeforeClass | ||
public static void setupClass() throws Exception { | ||
context = new ContextImpl(); | ||
ModuleManager moduleManager = ModuleManagerFactory.create(); | ||
context.put(ModuleManager.class, moduleManager); | ||
ModuleAwareAssetTypeManager assetTypeManager = new ModuleAwareAssetTypeManager(); | ||
assetTypeManager.registerCoreAssetType(Prefab.class, | ||
(AssetFactory<Prefab, PrefabData>) PojoPrefab::new, "prefabs"); | ||
assetTypeManager.switchEnvironment(moduleManager.getEnvironment()); | ||
context.put(AssetManager.class, assetTypeManager.getAssetManager()); | ||
CoreRegistry.setContext(context); | ||
} | ||
|
||
@Before | ||
public void setup() { | ||
context.put(NetworkSystem.class, mock(NetworkSystem.class)); | ||
EntitySystemSetupUtil.addReflectionBasedLibraries(context); | ||
EntitySystemSetupUtil.addEntityManagementRelatedClasses(context); | ||
entityManager = (PojoEntityManager) context.get(EntityManager.class); | ||
|
||
pool = new PojoEntityPool(entityManager); | ||
} | ||
|
||
|
||
@Test | ||
public void testContains() { | ||
assertFalse(pool.contains(PojoEntityManager.NULL_ID)); | ||
assertFalse(pool.contains(1000000)); | ||
EntityRef ref = pool.create(); | ||
assertTrue(pool.contains(ref.getId())); | ||
} | ||
|
||
@Test | ||
public void testRemove() { | ||
EntityRef ref = pool.create(); | ||
assertTrue(pool.contains(ref.getId())); | ||
|
||
pool.remove(ref.getId()); | ||
assertFalse(pool.contains(ref.getId())); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this method also have return type
boolean
like the one above? At least the Javadoc suggests so and it would be consistent with the API.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I just copied the Javadoc without properly checking it.
It currently doesn't have anywhere it can fail, though I guess passing a null prefab might cause it to return false. The addPrefab(String) one only fails because a non-null string can fail to return a prefab (though, looking at it again, it will fail and not add an EntityInfoComponent on a nulll string, so changing one of them would make them consistent).
Currently adding a null prefab is fine, and is used to create an entity when you want to add a location, but not a prefab.