Skip to content
Browse files

Benchmark movement.

[ADDED]     isGod shortcut tests and speed benchmark for a large game.
  • Loading branch information...
1 parent 1caa3ca commit 881acbb47537f8d089a2ce755cca256813b6f401 @lhunath lhunath committed Mar 1, 2014
View
5 omicron-core/src/main/java/com/lyndir/omicron/api/model/BaseModule.java
@@ -1,7 +1,7 @@
package com.lyndir.omicron.api.model;
import static com.lyndir.omicron.api.model.CoreUtils.*;
-import static com.lyndir.omicron.api.model.Security.currentPlayer;
+import static com.lyndir.omicron.api.model.Security.*;
import com.google.common.base.Predicate;
import com.google.common.collect.*;
@@ -46,7 +46,6 @@ static Builder0 createWithExtraResourceCost(final ImmutableResourceCost resource
}
/**
- * @see Player#canObserve(GameObservable)
* @see GameObservable#checkLocation()
*/
@Override
@@ -63,7 +62,7 @@ public Maybool canObserve(@Nonnull final GameObservable observable)
return Maybool.UNKNOWN;
case PRESENT:
ITile observableLocation = null;
- if (getGameObject().isOwnedByCurrentPlayer()) {
+ if (isGod() || getGameObject().isOwnedByCurrentPlayer()) {
// FIXME: HACKS! Get rid of the instanceof.
if (observable instanceof ITile)
observableLocation = (ITile) observable;
View
5 omicron-core/src/main/java/com/lyndir/omicron/api/model/GameObject.java
@@ -83,7 +83,7 @@ public boolean equals(final Object obj) {
@Nonnull
@Override
public Maybe<Player> checkOwner() {
- return currentPlayer() == owner || currentPlayer().canObserve( this ).isTrue()? Maybe.fromNullable( owner ): Maybe.<Player>unknown();
+ return isGod() || ObjectUtils.isEqual( owner, currentPlayer() ) || currentPlayer().canObserve( this ).isTrue()? Maybe.fromNullable( owner ): Maybe.<Player>unknown();
}
@Override
@@ -102,6 +102,9 @@ void setOwner(@Nullable final Player owner) {
.onUnitCaptured( this, ownerChange.to( this.owner ) );
}
+ /**
+ * @see GameObjectController#canObserve(GameObservable)
+ */
@Authenticated
@Override
public Maybool canObserve(@Nonnull final GameObservable observable)
View
3 omicron-core/src/main/java/com/lyndir/omicron/api/model/GameObjectController.java
@@ -71,6 +71,9 @@ void setLocation(@Nonnull final Tile location) {
newLocation.get().setContents( getGameObject() );
}
+ /**
+ * @see BaseModule#canObserve(GameObservable)
+ */
@Override
public Maybool canObserve(@Nonnull final GameObservable observable)
throws NotAuthenticatedException {
View
9 omicron-core/src/main/java/com/lyndir/omicron/api/model/PlayerController.java
@@ -42,6 +42,7 @@ public GameController getGameController() {
/**
* @see #iterateObservableObjects()
+ * @see IGameObject#checkLocation()
* @see IGameObject#canObserve(GameObservable)
*/
@Override
@@ -92,7 +93,7 @@ public boolean apply(final Maybool result) {
}
/**
- * @see IPlayer#canObserve(GameObservable)
+ * @see #iterateObservableObjects(GameObserver)
*/
@Override
@Authenticated
@@ -105,11 +106,7 @@ public boolean apply(final Maybool result) {
}
/**
- * Iterate the objects of this player that the given observer (and the current player) can observe.
- *
- * @param observer The observer that we want to observe the player's objects with.
- *
- * @return An iterable of game objects owned by this controller's player.
+ * @see GameObserver#canObserve(GameObservable)
*/
@Override
@Authenticated
View
4 omicron-core/src/main/java/com/lyndir/omicron/api/model/Tile.java
@@ -62,7 +62,7 @@ public boolean equals(final Object obj) {
@Override
public Maybe<? extends IPlayer> checkOwner() {
- if (!currentPlayer().canObserve( this ).isTrue())
+ if (!isGod() || !currentPlayer().canObserve( this ).isTrue())
return Maybe.unknown();
if (contents == null)
@@ -74,7 +74,7 @@ public boolean equals(final Object obj) {
@Override
public Maybe<? extends ITile> checkLocation()
throws NotAuthenticatedException {
- if (!currentPlayer().canObserve( this ).isTrue())
+ if (!isGod() && !currentPlayer().canObserve( this ).isTrue())
return Maybe.unknown();
return Maybe.of( this );
View
23 omicron-core/src/test/java/com/lyndir/omicron/api/model/AbstractTest.java
@@ -26,6 +26,10 @@
protected Player staticPlayer;
protected void init() {
+ staticGame = newGameBuilder().build();
+ }
+
+ protected Game.Builder newGameBuilder() {
Game.Builder builder = Game.builder();
PlayerKey key = new PlayerKey();
staticPlayer = new Player( builder.nextPlayerID(), key, "testPlayer", Color.Template.randomColor(), Color.Template.randomColor() ) {
@@ -44,13 +48,12 @@ public PlayerController getController() {
return playerController;
}
};
+ Security.authenticate( staticPlayer, key );
builder.setLevelSize( new Size( 10, 10 ) );
builder.setResourceConfig( IGame.GameResourceConfigs.NONE );
builder.setUnitConfig( Game.GameUnitConfigs.NONE );
builder.addPlayer( staticPlayer );
- staticGame = builder.build();
-
- Security.authenticate( staticPlayer, key );
+ return builder;
}
protected void printWorldMap() {
@@ -120,13 +123,19 @@ protected GameObject createUnit(final UnitType unitType) {
return createUnit( unitType, 0, 0 );
}
- protected GameObject createUnit(final UnitType unitType, final int u, final int v) {
- return createUnit( unitType, staticGame, staticPlayer, u, v );
+ protected GameObject createUnit(final UnitType unitType, final int x, final int y) {
+ return createUnit( unitType, staticGame, staticPlayer, x, y );
+ }
+
+ protected GameObject createUnit(final UnitType unitType, final Game game, final Player player, final int x, final int y) {
+ Tile tile = game.getLevel( LevelType.GROUND ).getTile( x, y ).get();
+
+ return createUnit(unitType, game, player, tile);
}
- protected GameObject createUnit(final UnitType unitType, final Game game, final Player player, final int u, final int v) {
+ protected GameObject createUnit(final UnitType unitType, final Game game, final Player player, final Tile tile) {
GameObject gameObject = new GameObject( unitType, game, player );
- game.getLevel( LevelType.GROUND ).getTile( u, v ).get().setContents( gameObject );
+ tile.setContents( gameObject );
return gameObject;
}
View
60 omicron-core/src/test/java/com/lyndir/omicron/api/model/BigGameTest.java
@@ -0,0 +1,60 @@
+package com.lyndir.omicron.api.model;
+
+import com.google.common.collect.ImmutableList;
+import com.lyndir.lhunath.opal.math.Side;
+import com.lyndir.lhunath.opal.math.Size;
+import org.testng.annotations.Test;
+
+
+/**
+ * @author lhunath, 2014-03-01
+ */
+public class BigGameTest extends AbstractTest {
+
+ private Player otherPlayer;
+
+ @Override
+ protected Game.Builder newGameBuilder() {
+ Game.Builder builder = super.newGameBuilder();
+ builder.addPlayer( otherPlayer = new Player( builder.nextPlayerID(), null, Player.randomName(), Color.random(), Color.random() ) );
+ builder.setLevelSize( new Size( 1000, 1000 ) );
+ return builder;
+ }
+
+ @Override
+ protected void printWorldMap() {
+ }
+
+ @Test
+ public void testBigGame()
+ throws Exception {
+
+ int[] coordinates = {
+ 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250, 260,
+ 270, 280, 290 };
+
+ ImmutableList.Builder<GameObject> gameObjectsBuilder = ImmutableList.builder();
+ for (int x = 0; x < coordinates.length; ++x) {
+ for (int y = 0; y < coordinates.length; ++y) {
+ gameObjectsBuilder.add( createUnit( UnitTypes.SCOUT, staticGame, staticPlayer, coordinates[x], coordinates[y] ) );
+ }
+ }
+ for (int x = 0; x < coordinates.length; ++x) {
+ for (int y = 0; y < coordinates.length; ++y) {
+ createUnit( UnitTypes.SCOUT, staticGame, otherPlayer, coordinates[x] + 5, coordinates[y] + 5 );
+ }
+ }
+
+ long startNanos = System.nanoTime();
+ staticGame.getController().setReady();
+ ImmutableList<GameObject> gameObjects = gameObjectsBuilder.build();
+ for (int i = 0; i < gameObjects.size(); i++) {
+ GameObject gameObject = gameObjects.get( i );
+ logger.dbg( "Moving gameObject %d / %d (%d%%)", i, gameObjects.size(), i * 100 / gameObjects.size() );
+ gameObject.onModule( PublicModuleType.MOBILITY, 0 )
+ .movement( gameObject.getLocation().get().neighbour( Side.E ).get() )
+ .execute();
+ }
+ logger.inf( "Movement took %dns", System.nanoTime() - startNanos );
+ }
+}
View
2 omicron-core/src/test/resources/logback.xml
@@ -7,7 +7,7 @@
</appender>
<logger name="com.lyndir" level="DEBUG" />
- <logger name="com.lyndir.omicron" level="TRACE" />
+ <logger name="com.lyndir.omicron" level="DEBUG" />
<root level="INFO">
<appender-ref ref="STDOUT" />

0 comments on commit 881acbb

Please sign in to comment.
Something went wrong with that request. Please try again.