[skycastle-commits] SF.net SVN: skycastle: [429] trunk/skycastle/modules/core/src

  • From: zzorn@xxxxxxxxxxxxxxxxxxxxx
  • To: skycastle-commits@xxxxxxxxxxxxx
  • Date: Wed, 02 Apr 2008 12:55:20 -0700

Revision: 429
          http://skycastle.svn.sourceforge.net/skycastle/?rev=429&view=rev
Author:   zzorn
Date:     2008-04-02 12:55:19 -0700 (Wed, 02 Apr 2008)

Log Message:
-----------
More work on testing.

Modified Paths:
--------------
    
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/DynamicGameObject.java
    
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/acting/ActionFacade.java
    
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/clientside/ProxyGameObject.java
    
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/geometry/space/grid/example/GridSpaceDemo.java
    
trunk/skycastle/modules/core/src/test/java/org/skycastle/core/AbstractGameObjectActionsTest.java
    
trunk/skycastle/modules/core/src/test/java/org/skycastle/core/AbstractGameObjectPropertiesTest.java

Added Paths:
-----------
    
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/DefaultGameObject.java
    
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/GameContext.java

Copied: 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/DefaultGameObject.java
 (from rev 427, 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/AbstractGameObject.java)
===================================================================
--- 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/DefaultGameObject.java
                                (rev 0)
+++ 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/DefaultGameObject.java
        2008-04-02 19:55:19 UTC (rev 429)
@@ -0,0 +1,303 @@
+package org.skycastle.core;
+
+import org.skycastle.core.acting.Action;
+import org.skycastle.core.acting.ActionFacade;
+import org.skycastle.core.acting.ActionFacadeImpl;
+import org.skycastle.core.property.PropertyFacade;
+import org.skycastle.core.property.PropertyFacadeImpl;
+import org.skycastle.messaging.Message;
+import org.skycastle.messaging.MessageListener;
+import org.skycastle.messaging.modifications.action.InvokeActionMessage;
+import org.skycastle.messaging.updates.UpdateMessage;
+import org.skycastle.util.ParameterChecker;
+import org.skycastle.util.parameters.ParameterMetadata;
+import org.skycastle.util.parameters.ValidationError;
+import org.skycastle.util.parameters.validators.ParameterValidator;
+
+import java.io.Serializable;
+import java.util.Set;
+
+/**
+ * Common functionality for all/most implementations of GameObject.
+ */
+// IDEA: Create some kind of GameObject specific debug stream listening system?
+// An admin readable mostRecentError field?
+
+// It would make sense to make the action invocation validity checks twice, 
once before queying, and once before executing, at least for direct requests..
+// Or alternatively clear the action queue whenever access privilegies are 
changed?  Or re-screen it?
+// Or just re-check action access privilegies before invocation?
+public class DefaultGameObject
+        implements GameObject
+{
+
+    //======================================================================
+    // Private Fields
+
+    private final PropertyFacade myPropertyFacade;
+    private final ActionFacadeImpl myActionFacade;
+    private final MessagingFacade myMessagingFacade;
+
+    private GameObjectId myId;
+
+    //======================================================================
+    // Private Constants
+
+    private static final long serialVersionUID = 1L;
+
+    //======================================================================
+    // Public Methods
+
+    //----------------------------------------------------------------------
+    // ActionFacade Implementation
+
+    public void startAction( final InvokeActionMessage invokeActionMessage )
+    {
+        myActionFacade.startAction( invokeActionMessage );
+    }
+
+
+    public long startAction( final GameObjectId callerId, final String 
actionIdentifier )
+    {
+        return myActionFacade.startAction( callerId, actionIdentifier );
+    }
+
+
+    public long startAction( final GameObjectId callerId, final String 
actionIdentifier, final Object... parameters )
+    {
+        return myActionFacade.startAction( callerId, actionIdentifier, 
parameters );
+    }
+
+
+    public void stopAction( final String actionIdentifier, final long actId )
+    {
+        myActionFacade.stopAction( actionIdentifier, actId );
+    }
+
+
+    public ActionMetadata getActionMetadata( final String actionIdentifier )
+    {
+        return myActionFacade.getActionMetadata( actionIdentifier );
+    }
+
+
+    public void addAction( final Action action )
+    {
+        myActionFacade.addAction( action );
+    }
+
+
+    public void removeAction( final String actionIdentifier )
+    {
+        myActionFacade.removeAction( actionIdentifier );
+    }
+
+
+    public boolean hasAction( final String actionIdentifier )
+    {
+        return myActionFacade.hasAction( actionIdentifier );
+    }
+
+
+    public Set<String> getActionIdentifiers()
+    {
+        return myActionFacade.getActionIdentifiers();
+    }
+
+    //----------------------------------------------------------------------
+    // GameObject Implementation
+
+    public final GameObjectId getId()
+    {
+        // Lazy init
+        if ( myId == null )
+        {
+            myId = getGameObjectContext().createGameObjectId( this );
+        }
+
+        return myId;
+    }
+
+    //----------------------------------------------------------------------
+    // MessageListener Implementation
+
+    public final void onMessage( final Message message )
+    {
+        myMessagingFacade.onMessage( message );
+    }
+
+    //----------------------------------------------------------------------
+    // MessagingFacade Implementation
+
+    public void addIndirectUpdateListener( final UpdateListenerFilter filter, 
final GameObjectId observerId )
+    {
+        myMessagingFacade.addIndirectUpdateListener( filter, observerId );
+    }
+
+
+    public void removeIndirectUpdateListener( final UpdateListenerFilter 
filter,
+                                              final GameObjectId observerId )
+    {
+        myMessagingFacade.removeIndirectUpdateListener( filter, observerId );
+    }
+
+
+    public void addDirectUpdateListener( final UpdateListenerFilter filter, 
final MessageListener listener )
+    {
+        myMessagingFacade.addDirectUpdateListener( filter, listener );
+    }
+
+
+    public void removeDirectUpdateListener( final UpdateListenerFilter filter,
+                                            final MessageListener 
messageListener )
+    {
+        myMessagingFacade.removeDirectUpdateListener( filter, messageListener 
);
+    }
+
+
+    public void sendUpdateToObservers( final UpdateMessage updateMessage )
+    {
+        myMessagingFacade.sendUpdateToObservers( updateMessage );
+    }
+
+    //----------------------------------------------------------------------
+    // PropertyFacade Implementation
+
+    public <T> T getPropertyValue( final String propertyIdentifier, final T 
defaultValue )
+    {
+        return myPropertyFacade.getPropertyValue( propertyIdentifier, 
defaultValue );
+    }
+
+
+    public ValidationError setPropertyValue( final String propertyIdentifier, 
final Serializable value )
+    {
+        return myPropertyFacade.setPropertyValue( propertyIdentifier, value );
+    }
+
+
+    public boolean hasProperty( final String propertyIdentifier )
+    {
+        return myPropertyFacade.hasProperty( propertyIdentifier );
+    }
+
+
+    public Set<String> getPropertyIdentifiers()
+    {
+        return myPropertyFacade.getPropertyIdentifiers();
+    }
+
+
+    public ParameterMetadata getPropertyMetadata( final String 
propertyIdentifier )
+    {
+        return myPropertyFacade.getPropertyMetadata( propertyIdentifier );
+    }
+
+
+    public ValidationError addProperty( final String propertyIdentifier, final 
Serializable initialValue )
+    {
+        return myPropertyFacade.addProperty( propertyIdentifier, initialValue 
);
+    }
+
+
+    public ValidationError addProperty( final String propertyIdentifier,
+                                        final Serializable initialValue,
+                                        final String description, final 
ParameterValidator... validators )
+    {
+        return myPropertyFacade.addProperty( propertyIdentifier, initialValue, 
description, validators );
+    }
+
+
+    public <T extends Serializable> ValidationError addProperty( final String 
propertyIdentifier,
+                                                                 final T 
initialValue,
+                                                                 final 
Class<T> type,
+                                                                 final String 
description,
+                                                                 final 
ParameterValidator... validators )
+    {
+        return myPropertyFacade.addProperty( propertyIdentifier,
+                                             initialValue,
+                                             type,
+                                             description,
+                                             validators );
+    }
+
+
+    public ValidationError addProperty( final String propertyIdentifier,
+                                        final Serializable initialValue,
+                                        final ParameterMetadata 
propertyMetadata )
+    {
+        return myPropertyFacade.addProperty( propertyIdentifier, initialValue, 
propertyMetadata );
+    }
+
+
+    public ValidationError removeProperty( final String propertyIdentifier )
+    {
+        return myPropertyFacade.removeProperty( propertyIdentifier );
+    }
+
+    //----------------------------------------------------------------------
+    // Task Implementation
+
+    public void run() throws Exception
+    {
+        myActionFacade.runScheduledActs( 
getGameObjectContext().getCurrentGameTime_ms() );
+    }
+
+    //----------------------------------------------------------------------
+    // Other Public Methods
+
+    /**
+     * @return an interface that provides property related operations for this 
{@link GameObject}.
+     */
+    public final PropertyFacade getPropertyFacade()
+    {
+        return myPropertyFacade;
+    }
+
+
+    /**
+     * @return an interface that provides action related operations for this 
{@link GameObject}.
+     */
+    public final ActionFacade getActionFacade()
+    {
+        return myActionFacade;
+    }
+
+
+    /**
+     * @return an interface that provides messaging related operations for 
this {@link GameObject}.
+     */
+    public final MessagingFacade getMessagingFacade()
+    {
+        return myMessagingFacade;
+    }
+
+    //======================================================================
+    // Protected Methods
+
+    //----------------------------------------------------------------------
+    // Protected Constructors
+
+    protected DefaultGameObject()
+    {
+        myPropertyFacade = new PropertyFacadeImpl( this, 
getGameObjectContext() );
+        myActionFacade = new ActionFacadeImpl( this, getGameObjectContext() );
+        myMessagingFacade = new MessagingFacadeImpl( this, 
getGameObjectContext() );
+    }
+
+
+    protected final void setId( final GameObjectId id )
+    {
+        ParameterChecker.checkNotNull( id, "id" );
+
+        myId = id;
+    }
+
+
+    /**
+     * @return a {@link GameObjectContext} that provides environment specific 
functions.
+     */
+    protected final GameObjectContext getGameObjectContext()
+    {
+        return GameContext.getGameObjectContext();
+    }
+
+}


Property changes on: 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/DefaultGameObject.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/DynamicGameObject.java
===================================================================
--- 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/DynamicGameObject.java
        2008-04-02 13:54:00 UTC (rev 428)
+++ 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/DynamicGameObject.java
        2008-04-02 19:55:19 UTC (rev 429)
@@ -7,7 +7,7 @@
  * @author Hans Häggström
  */
 public class DynamicGameObject
-        extends AbstractGameObject
+        extends DefaultGameObject
 {
 
     //======================================================================
@@ -23,7 +23,6 @@
 
     public DynamicGameObject()
     {
-        super( new ServerSideContext() );
     }
 
 }

Added: 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/GameContext.java
===================================================================
--- 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/GameContext.java  
                            (rev 0)
+++ 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/GameContext.java  
    2008-04-02 19:55:19 UTC (rev 429)
@@ -0,0 +1,46 @@
+package org.skycastle.core;
+
+import org.skycastle.util.ParameterChecker;
+
+/**
+ * A public singleton, that provides the {@link GameObjectContext} for the 
current environment.
+ * The {@link GameObjectContext} implementation depends on wether this is the 
client, server, or unit testing environment.
+ *
+ * @author Hans Haggstrom
+ */
+public final class GameContext
+{
+
+    //======================================================================
+    // Private Fields
+
+    private static GameObjectContext myGameObjectContext = null;
+
+    //======================================================================
+    // Public Methods
+
+    //----------------------------------------------------------------------
+    // Static Methods
+
+    /**
+     * @return the {@link GameObjectContext} for the current environment.  
Differs between client, server, and unit test environments.
+     */
+    public static GameObjectContext getGameObjectContext()
+    {
+        return myGameObjectContext;
+    }
+
+    static void setGameObjectContext( GameObjectContext gameObjectContext )
+    {
+        ParameterChecker.checkNotNull( gameObjectContext, "gameObjectContext" 
);
+
+        myGameObjectContext = gameObjectContext;
+    }
+
+
+    static
+    {
+        // TODO: Determine environment - how?
+    }
+
+}

Modified: 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/acting/ActionFacade.java
===================================================================
--- 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/acting/ActionFacade.java
      2008-04-02 13:54:00 UTC (rev 428)
+++ 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/acting/ActionFacade.java
      2008-04-02 19:55:19 UTC (rev 429)
@@ -1,6 +1,5 @@
 package org.skycastle.core.acting;
 
-import org.skycastle.core.AbstractGameObject;
 import org.skycastle.core.ActionMetadata;
 import org.skycastle.core.GameObject;
 import org.skycastle.core.GameObjectId;
@@ -10,7 +9,7 @@
 import java.util.Set;
 
 /**
- * A helper class for {@link AbstractGameObject}, to split up its 
responsibilities. This class handles {@link
+ * A helper class for {@link org.skycastle.core.DefaultGameObject}, to split 
up its responsibilities. This class handles {@link
  * Action} related aspects of a {@link GameObject}.
  *
  * @author Hans Häggström

Modified: 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/clientside/ProxyGameObject.java
===================================================================
--- 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/clientside/ProxyGameObject.java
       2008-04-02 13:54:00 UTC (rev 428)
+++ 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/clientside/ProxyGameObject.java
       2008-04-02 19:55:19 UTC (rev 429)
@@ -1,7 +1,6 @@
 package org.skycastle.core.clientside;
 
-import org.skycastle.core.AbstractGameObject;
-import org.skycastle.core.ClientContext;
+import org.skycastle.core.DefaultGameObject;
 import org.skycastle.core.GameObject;
 import org.skycastle.core.GameObjectId;
 
@@ -12,7 +11,7 @@
  * course checks if the client has the right to do updates to the original 
GameObject before applying them).
  */
 public final class ProxyGameObject
-        extends AbstractGameObject
+        extends DefaultGameObject
 {
 
     //======================================================================
@@ -32,7 +31,8 @@
      */
     public ProxyGameObject( final GameObjectId id, final GameModel model )
     {
-        super( new ClientContext( model, id ) );
+        setId( id );
     }
 
+
 }

Modified: 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/geometry/space/grid/example/GridSpaceDemo.java
===================================================================
--- 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/geometry/space/grid/example/GridSpaceDemo.java
        2008-04-02 13:54:00 UTC (rev 428)
+++ 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/geometry/space/grid/example/GridSpaceDemo.java
        2008-04-02 19:55:19 UTC (rev 429)
@@ -1,6 +1,6 @@
 package org.skycastle.core.geometry.space.grid.example;
 
-import org.skycastle.core.AbstractGameObject;
+import org.skycastle.core.DefaultGameObject;
 import org.skycastle.core.geometry.space.grid.GridContext;
 import org.skycastle.core.geometry.space.grid.GridSpace;
 import org.skycastle.core.geometry.space.grid.OverviewGridRenderer;
@@ -28,7 +28,7 @@
     {
         GridSpace gridSpace = new GridSpace( 10, 10 );
 
-        final AbstractGameObject gameObject = new PojoGameObject()
+        final DefaultGameObject gameObject = new PojoGameObject()
         {
         };
 

Modified: 
trunk/skycastle/modules/core/src/test/java/org/skycastle/core/AbstractGameObjectActionsTest.java
===================================================================
--- 
trunk/skycastle/modules/core/src/test/java/org/skycastle/core/AbstractGameObjectActionsTest.java
    2008-04-02 13:54:00 UTC (rev 428)
+++ 
trunk/skycastle/modules/core/src/test/java/org/skycastle/core/AbstractGameObjectActionsTest.java
    2008-04-02 19:55:19 UTC (rev 429)
@@ -4,7 +4,6 @@
 import org.skycastle.core.acting.Act;
 import org.skycastle.core.acting.Action;
 import org.skycastle.core.acting.ActionImpl;
-import org.skycastle.core.acting.InvocationType;
 import org.skycastle.messaging.MessageListener;
 import org.skycastle.util.parameters.ParameterSet;
 import org.skycastle.util.parameters.ParameterSetMetadataImpl;
@@ -26,6 +25,7 @@
     private static final String ACTION_INVOKED = "actionInvoked";
     private static final String TEST_ACTION_NAME = "testAction";
     private GameObjectId myCallerId;
+    private UnitTestingContext myUnitTestingContext;
 
     //======================================================================
     // Public Methods
@@ -86,17 +86,10 @@
     @Override
     protected void setUp() throws Exception
     {
-        myGameObject = new AbstractGameObject( new UnitTestingContext() )
-        {
+        myUnitTestingContext = new UnitTestingContext();
 
-            protected InvocationType getActionInvocationType()
-            {
-                return InvocationType.DIRECT;
-            }
+        myGameObject = new DefaultGameObject( myUnitTestingContext );
 
-            private static final long serialVersionUID = 1L;
-
-        };
         myGameObject.addProperty( ACTION_INVOKED, false );
 
         myTestAction = new ActionImpl( TEST_ACTION_NAME,
@@ -107,8 +100,8 @@
                                        true );
 
         myGameObject.addAction( myTestAction );
-        assertTrue( "Action should be added",
-                    myGameObject.hasAction( TEST_ACTION_NAME ) );
+        assertTrue( "Action should be added", 2
+        myGameObject.hasAction( TEST_ACTION_NAME ));
         myCallerId = new GameObjectId( "someSender" );
     }
 

Modified: 
trunk/skycastle/modules/core/src/test/java/org/skycastle/core/AbstractGameObjectPropertiesTest.java
===================================================================
--- 
trunk/skycastle/modules/core/src/test/java/org/skycastle/core/AbstractGameObjectPropertiesTest.java
 2008-04-02 13:54:00 UTC (rev 428)
+++ 
trunk/skycastle/modules/core/src/test/java/org/skycastle/core/AbstractGameObjectPropertiesTest.java
 2008-04-02 19:55:19 UTC (rev 429)
@@ -203,7 +203,7 @@
     @Override
     protected void setUp() throws Exception
     {
-        myGameObject = new AbstractGameObject( new UnitTestingContext() )
+        myGameObject = new DefaultGameObject( new UnitTestingContext() )
         {
 
             protected InvocationType getActionInvocationType()


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

Other related posts:

  • » [skycastle-commits] SF.net SVN: skycastle: [429] trunk/skycastle/modules/core/src