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

  • From: zzorn@xxxxxxxxxxxxxxxxxxxxx
  • To: skycastle-commits@xxxxxxxxxxxxx
  • Date: Sun, 14 Oct 2007 23:52:56 -0700

Revision: 232
          http://skycastle.svn.sourceforge.net/skycastle/?rev=232&view=rev
Author:   zzorn
Date:     2007-10-14 23:52:55 -0700 (Sun, 14 Oct 2007)

Log Message:
-----------
Continued working on the core action handling and sensory pathways.  Added an 
ID object used to uniquely identify all game objects.

Modified Paths:
--------------
    trunk/skycastle/modules/core/pom.xml
    trunk/skycastle/modules/core/src/main/java/org/skycastle/core/Action.java
    
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/ActionRequest.java
    trunk/skycastle/modules/core/src/main/java/org/skycastle/core/Actor.java
    trunk/skycastle/modules/core/src/main/java/org/skycastle/core/Sensor.java

Added Paths:
-----------
    
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/AbstractGameObject.java
    trunk/skycastle/modules/core/src/main/java/org/skycastle/core/ActorImpl.java
    
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/GameObject.java
    trunk/skycastle/modules/core/src/main/java/org/skycastle/core/ID.java

Modified: trunk/skycastle/modules/core/pom.xml
===================================================================
--- trunk/skycastle/modules/core/pom.xml        2007-10-07 06:11:13 UTC (rev 
231)
+++ trunk/skycastle/modules/core/pom.xml        2007-10-15 06:52:55 UTC (rev 
232)
@@ -25,51 +25,51 @@
         <plugins>
 
             <!--Specify where Scala sources can be found in a project. -->
-<!--
-            <plugin>
-                <groupId>org.codehaus.mojo</groupId>
-                <artifactId>build-helper-maven-plugin</artifactId>
-                <executions>
-                    <execution>
-                        <id>add-source</id>
-                        <phase>generate-sources</phase>
-                        <goals>
-                            <goal>add-source</goal>
-                        </goals>
-                        <configuration>
-                            <sources>
-                                <source>src/main/scala</source>
-                            </sources>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
--->
+            <!--
+                        <plugin>
+                            <groupId>org.codehaus.mojo</groupId>
+                            <artifactId>build-helper-maven-plugin</artifactId>
+                            <executions>
+                                <execution>
+                                    <id>add-source</id>
+                                    <phase>generate-sources</phase>
+                                    <goals>
+                                        <goal>add-source</goal>
+                                    </goals>
+                                    <configuration>
+                                        <sources>
+                                            <source>src/main/scala</source>
+                                        </sources>
+                                    </configuration>
+                                </execution>
+                            </executions>
+                        </plugin>
+            -->
 
             <!-- Configure the use of the Scala compiler (through plexus). -->
-<!--
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-compiler-plugin</artifactId>
-                <configuration>
-                    <compilerId>scalac</compilerId>
+            <!--
+                        <plugin>
+                            <groupId>org.apache.maven.plugins</groupId>
+                            <artifactId>maven-compiler-plugin</artifactId>
+                            <configuration>
+                                <compilerId>scalac</compilerId>
 
-                    <includes>
-                        <include>**</include>
-                    </includes>
-                </configuration>
+                                <includes>
+                                    <include>**</include>
+                                </includes>
+                            </configuration>
 
-                <dependencies>
-                    <dependency>
-                        <groupId>org.codehaus.plexus</groupId>
-                        <artifactId>plexus-compiler-scalac</artifactId>
-                        <version>1.5.3</version>
+                            <dependencies>
+                                <dependency>
+                                    <groupId>org.codehaus.plexus</groupId>
+                                    
<artifactId>plexus-compiler-scalac</artifactId>
+                                    <version>1.5.3</version>
 
-                        <scope>runtime</scope>
-                    </dependency>
-                </dependencies>
-            </plugin>
--->
+                                    <scope>runtime</scope>
+                                </dependency>
+                            </dependencies>
+                        </plugin>
+            -->
             <!--
             -->
             <!-- Executable JAR -->
@@ -235,8 +235,16 @@
             <artifactId>skycastle-utils</artifactId>
             <version>0.0.4-SNAPSHOT</version>
         </dependency>
-<!--
+
+        <!-- Primitive collections -->
         <dependency>
+            <groupId>trove</groupId>
+            <artifactId>trove</artifactId>
+            <version>2.0.1-rc1</version>
+        </dependency>
+
+        <!--
+        <dependency>
             <groupId>scala</groupId>
             <artifactId>scala-compiler</artifactId>
         </dependency>

Added: 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/AbstractGameObject.java
===================================================================
--- 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/AbstractGameObject.java
                               (rev 0)
+++ 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/AbstractGameObject.java
       2007-10-15 06:52:55 UTC (rev 232)
@@ -0,0 +1,44 @@
+package org.skycastle.core;
+
+import org.skycastle.util.ParameterChecker;
+
+/**
+ * {@inheritDoc}
+ */
+public abstract class AbstractGameObject
+        implements GameObject
+{
+
+    //======================================================================
+    // Private Fields
+
+    private final ID myId;
+
+    //======================================================================
+    // Public Methods
+
+    //----------------------------------------------------------------------
+    // GameObject Implementation
+
+    public final ID getId()
+    {
+        return myId;
+    }
+
+    //======================================================================
+    // Protected Methods
+
+    //----------------------------------------------------------------------
+    // Protected Constructors
+
+    /**
+     * @param id an unique identifier for this {@link GameObject}.
+     */
+    protected AbstractGameObject( final ID id )
+    {
+        ParameterChecker.checkNotNull( id, "id" );
+
+        myId = id;
+    }
+
+}


Property changes on: 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/AbstractGameObject.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/Action.java
===================================================================
--- trunk/skycastle/modules/core/src/main/java/org/skycastle/core/Action.java   
2007-10-07 06:11:13 UTC (rev 231)
+++ trunk/skycastle/modules/core/src/main/java/org/skycastle/core/Action.java   
2007-10-15 06:52:55 UTC (rev 232)
@@ -7,13 +7,9 @@
  * Also holds parameter metadata for the {@link ActionRequest}s.
  */
 public interface Action
+        extends GameObject
 {
     /**
-     * @return identifier of this action.
-     */
-    String getIdentifier();
-
-    /**
      * @return metadata for this action, describes the parameters accepted by 
it.
      */
     ParameterMetadata getMetadata();

Modified: 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/ActionRequest.java
===================================================================
--- 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/ActionRequest.java
    2007-10-07 06:11:13 UTC (rev 231)
+++ 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/ActionRequest.java
    2007-10-15 06:52:55 UTC (rev 232)
@@ -10,7 +10,7 @@
     /**
      * @return the identifier of the {@link Action} that was requested, in the 
target {@link Actor}.
      */
-    String getActionIdentifier();
+    ID getActionIdentifier();
 
     /**
      * @return the parameters for this ActionRequest.

Modified: 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/Actor.java
===================================================================
--- trunk/skycastle/modules/core/src/main/java/org/skycastle/core/Actor.java    
2007-10-07 06:11:13 UTC (rev 231)
+++ trunk/skycastle/modules/core/src/main/java/org/skycastle/core/Actor.java    
2007-10-15 06:52:55 UTC (rev 232)
@@ -1,7 +1,6 @@
 package org.skycastle.core;
 
 import java.util.Collection;
-import java.util.Map;
 
 /**
  * Something that can do {@link Action}s, and can have {@link Sensor}s, and 
can have control over other {@link Actor}s.
@@ -16,37 +15,32 @@
 // Or is it up to the controller to keep track of what it has access to?
 // For now the interface might be a bit more stable if we tell the controller 
also when we do an actionRequest (less need to add more parameters later).
 public interface Actor
+        extends GameObject
 {
     /**
      * Called when the specified controller is requesting the specified action.
      *
      * @param controller    the controller that requested the action.  Could 
be used for access screening or such purposes.
-     * @param subActorId    the id of an actor controlled by this actor that 
the action should be sent to,
-     *                      or an empty string if it is sent to this actor.
      * @param actionRequest the request that was made.  Contains the action id 
and parameters.
      */
-    void requestAction( Controller controller, String subActorId, 
ActionRequest actionRequest );
+    void requestAction( Controller controller, ActionRequest actionRequest );
 
     /**
      * Subscribes the specified {@link Controller} to recieve {@link 
Sensation}s from the specified {@link Sensor}.
      *
      * @param controller the controller to subscribe.  Should not be null.
-     * @param subActorId the id of an actor controlled by this actor that the 
subscription should be sent to,
-     *                   or an empty string if it is sent to this actor.
      * @param sensorId   the identifier of the sensor to subscribe to.
      */
     // IDEA: We could maybe support filters later, e.g. recieve only the 
Sensations where the 'channel' parameter is 'SystemMessages'.  For now it is 
overkill.
-    void subscribeToSensor( Controller controller, String subActorId, String 
sensorId );
+    void subscribeToSensor( Controller controller, ID sensorId );
 
     /**
      * Unsubscribes the specified {@link Controller} so that it no longer 
recieves {@link Sensation}s from the specified {@link Sensor}.
      *
      * @param controller the controller to unsubscribe.  Should not be null.
-     * @param subActorId the id of an actor controlled by this actor that the 
unsubscription should be sent to,
-     *                   or an empty string if it is sent to this actor.
      * @param sensorId   the identifier of the sensor to unsubscribe from.
      */
-    void unsubscribeFromSensor( Controller controller, String subActorId, 
String sensorId );
+    void unsubscribeFromSensor( Controller controller, ID sensorId );
 
     /**
      * @return A read only list with the {@link Sensor}s in this Actor.
@@ -61,6 +55,14 @@
     /**
      * @return A read only map with the {@link Actor}s controlled by this 
Actor, and their identifiers.
      */
-    // CHECK: Should we use some global ID:s for Actors, so that we could just 
return a list of them?  But a client might be connected to multiple servers..
-    Map<String, Actor> getControlledActors();
+    // CHECK: Should we use some global ID:s for Actors, so that we could just 
return a list of them?
+    // But a client might be connected to multiple servers.. - maybe prepend 
with server id/url, or localhost for client.
+    // Or possibly use longs?
+    Collection<Actor> getControlledActors();
+
+    Actor getControlledActor( ID controlledActorId );
+
+    Sensor getSensor( ID sensorIdentifier );
+
+    Action getAction( ID actionIdentifier );
 }

Added: 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/ActorImpl.java
===================================================================
--- 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/ActorImpl.java    
                            (rev 0)
+++ 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/ActorImpl.java    
    2007-10-15 06:52:55 UTC (rev 232)
@@ -0,0 +1,233 @@
+package org.skycastle.core;
+
+import org.skycastle.util.ParameterChecker;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * {@inheritDoc}
+ * <p/>
+ * Provides common functionality for Actors.
+ */
+// TODO: Provide a sensor for listening to added and removed actions, sensors, 
and controlled actors.
+public class ActorImpl
+        extends AbstractGameObject
+        implements Actor
+{
+
+    //======================================================================
+    // Private Fields
+
+    private Map<ID, Sensor> mySensors = null;
+    private Collection<Sensor> mySensorsReadonly = Collections.emptyList();
+
+    private Map<ID, Action> myActions = null;
+    private Collection<Action> myActionsReadonly = Collections.emptyList();
+
+    private Map<ID, Actor> myControlledActors = null;
+    private Collection<Actor> myControlledActorsReadonly = 
Collections.emptyList();
+
+    //======================================================================
+    // Public Methods
+
+    //----------------------------------------------------------------------
+    // Constructors
+
+    /**
+     * Creates a new {@link ActorImpl}.
+     *
+     * @param id an unique identifier for this {@link GameObject}.
+     */
+    public ActorImpl( final ID id )
+    {
+        super( id );
+    }
+
+    //----------------------------------------------------------------------
+    // Actor Implementation
+
+    public void requestAction( final Controller controller, final 
ActionRequest actionRequest )
+    {
+        final Action action = getAction( actionRequest.getActionIdentifier() );
+
+        if ( action != null )
+        {
+            action.execute( this, actionRequest.getParametes() );
+        }
+    }
+
+
+    // IDEA: We could maybe support filters later, e.g. recieve only the 
Sensations where the 'channel' parameter is 'SystemMessages'.  For now it is 
overkill.
+    public final void subscribeToSensor( final Controller controller, final ID 
sensorId )
+    {
+        ParameterChecker.checkNotNull( controller, "controller" );
+        ParameterChecker.checkNotNull( sensorId, "sensorId" );
+
+        final Sensor sensor = getSensor( sensorId );
+
+        if ( sensor != null )
+        {
+            sensor.subscribe( controller, this, sensorId );
+        }
+    }
+
+
+    public final void unsubscribeFromSensor( final Controller controller, 
final ID sensorId )
+    {
+        ParameterChecker.checkNotNull( controller, "controller" );
+        ParameterChecker.checkNotNull( sensorId, "sensorId" );
+
+        final Sensor sensor = getSensor( sensorId );
+
+        if ( sensor != null )
+        {
+            sensor.unsubscribe( controller, this, sensorId );
+        }
+    }
+
+
+    public final Collection<Sensor> getSensors()
+    {
+        return mySensorsReadonly;
+    }
+
+
+    public final Collection<Action> getActions()
+    {
+        return myActionsReadonly;
+    }
+
+
+    // CHECK: Should we use some global ID:s for Actors, so that we could just 
return a list of them?  But a client might be connected to multiple servers..
+    public final Collection<Actor> getControlledActors()
+    {
+        return myControlledActorsReadonly;
+    }
+
+
+    public Actor getControlledActor( final ID controlledActorId )
+    {
+        return myControlledActors == null ? null : myControlledActors.get( 
controlledActorId );
+    }
+
+
+    public final Sensor getSensor( final ID sensorIdentifier )
+    {
+        return mySensors == null ? null : mySensors.get( sensorIdentifier );
+    }
+
+
+    public final Action getAction( final ID actionIdentifier )
+    {
+        return myActions == null ? null : myActions.get( actionIdentifier );
+    }
+
+    //----------------------------------------------------------------------
+    // Other Public Methods
+
+    /**
+     * Adds the specified Sensor.
+     *
+     * @param addedSensor should not be null or already added.
+     */
+    public final void addSensor( Sensor addedSensor )
+    {
+        ParameterChecker.checkNotNull( addedSensor, "addedSensor" );
+
+        if ( mySensors == null )
+        {
+            mySensors = new HashMap<ID, Sensor>( 5 );
+            mySensorsReadonly = Collections.unmodifiableCollection( 
mySensors.values() );
+        }
+
+        ParameterChecker.checkNotAlreadyContained( addedSensor, mySensors, 
"mySensors" );
+        mySensors.put( addedSensor.getId(), addedSensor );
+    }
+
+
+    /**
+     * Removes the specified Sensor.
+     *
+     * @param removedSensor should not be null, and should be present.
+     */
+    public final void removeSensor( Sensor removedSensor )
+    {
+        ParameterChecker.checkNotNull( removedSensor, "removedSensor" );
+        ParameterChecker.checkContained( removedSensor, mySensors.values(), 
"mySensors" );
+
+        mySensors.remove( removedSensor );
+    }
+
+
+    /**
+     * Adds the specified Action.
+     *
+     * @param addedAction should not be null or already added.
+     */
+    public final void addAction( Action addedAction )
+    {
+        ParameterChecker.checkNotNull( addedAction, "addedAction" );
+
+        if ( myActions == null )
+        {
+            myActions = new HashMap<ID, Action>( 5 );
+            myActionsReadonly = Collections.unmodifiableCollection( 
myActions.values() );
+        }
+
+        ParameterChecker.checkNotAlreadyContained( addedAction, myActions, 
"myActions" );
+        myActions.put( addedAction.getId(), addedAction );
+    }
+
+
+    /**
+     * Removes the specified Action.
+     *
+     * @param removedAction should not be null, and should be present.
+     */
+    public final void removeAction( Action removedAction )
+    {
+        ParameterChecker.checkNotNull( removedAction, "removedAction" );
+        ParameterChecker.checkContained( removedAction, myActions.values(), 
"myActions" );
+
+        myActions.remove( removedAction );
+    }
+
+
+    /**
+     * Adds the specified controlled Actor.
+     *
+     * @param addedActor should not be null or already added.
+     */
+    public final void addCotrolledActor( Actor addedActor )
+    {
+        ParameterChecker.checkNotNull( addedActor, "addedActor" );
+
+        if ( myControlledActors == null )
+        {
+            myControlledActors = new HashMap<ID, Actor>( 5 );
+            myControlledActorsReadonly = Collections.unmodifiableCollection( 
myControlledActors.values() );
+        }
+
+        ParameterChecker.checkNotAlreadyContained( addedActor, 
myControlledActors, "myControlledActors" );
+        myControlledActors.put( addedActor.getId(), addedActor );
+    }
+
+
+    /**
+     * Removes the specified controlled Actor.
+     *
+     * @param removedActor should not be null, and should be present.
+     */
+    public final void removeControlledActor( Actor removedActor )
+    {
+        ParameterChecker.checkNotNull( removedActor, "removedActor" );
+        ParameterChecker.checkContained( removedActor, 
myControlledActors.values(), "myControlledActors" );
+
+        myControlledActors.remove( removedActor );
+    }
+
+}
+


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

Added: 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/GameObject.java
===================================================================
--- 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/GameObject.java   
                            (rev 0)
+++ 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/GameObject.java   
    2007-10-15 06:52:55 UTC (rev 232)
@@ -0,0 +1,12 @@
+package org.skycastle.core;
+
+/**
+ * Roof interface for all addressable objects in the game.
+ */
+public interface GameObject
+{
+    /**
+     * @return the ID of this object.
+     */
+    ID getId();
+}


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

Added: trunk/skycastle/modules/core/src/main/java/org/skycastle/core/ID.java
===================================================================
--- trunk/skycastle/modules/core/src/main/java/org/skycastle/core/ID.java       
                        (rev 0)
+++ trunk/skycastle/modules/core/src/main/java/org/skycastle/core/ID.java       
2007-10-15 06:52:55 UTC (rev 232)
@@ -0,0 +1,68 @@
+package org.skycastle.core;
+
+/**
+ * Used for identifying objects uniquely.
+ * <p/>
+ * Motivation for just wrapping a long is that it is about as efficient as a 
Long object,
+ * and still allows easy addition of additional fields if needed.
+ */
+// IDEA: Could keep track also of on which server or client the objec is?
+public final class ID
+{
+
+    //======================================================================
+    // Private Fields
+
+    private final long myIdNumber;
+
+    //======================================================================
+    // Public Methods
+
+    //----------------------------------------------------------------------
+    // Constructors
+
+    /**
+     * @param idNumber the unique ID number.
+     */
+    public ID( final long idNumber )
+    {
+        myIdNumber = idNumber;
+    }
+
+    //----------------------------------------------------------------------
+    // Caononical Methods
+
+    public String toString()
+    {
+        return "ID{ " + myIdNumber + " }";
+    }
+
+
+    public boolean equals( final Object o )
+    {
+        if ( this == o )
+        {
+            return true;
+        }
+        if ( o == null || getClass() != o.getClass() )
+        {
+            return false;
+        }
+
+        final ID id = (ID) o;
+
+        if ( myIdNumber != id.myIdNumber )
+        {
+            return false;
+        }
+
+        return true;
+    }
+
+
+    public int hashCode()
+    {
+        return (int) ( myIdNumber ^ ( myIdNumber >>> 32 ) );
+    }
+
+}


Property changes on: 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/ID.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/Sensor.java
===================================================================
--- trunk/skycastle/modules/core/src/main/java/org/skycastle/core/Sensor.java   
2007-10-07 06:11:13 UTC (rev 231)
+++ trunk/skycastle/modules/core/src/main/java/org/skycastle/core/Sensor.java   
2007-10-15 06:52:55 UTC (rev 232)
@@ -6,11 +6,8 @@
  * Also holds parameter metadata for the {@link Sensation} messages.
  */
 public interface Sensor
+        extends GameObject
 {
-    /**
-     * @return identifier of this Sensor.
-     */
-    String getIdentifier();
 
     /**
      * @return metadata for the {@link Sensation}s sent by this {@link 
Sensor}, describes the parameters included in them.
@@ -25,7 +22,7 @@
      * @param sensorId   the identifier of the sensor in the Actor.
      */
     // IDEA: We could maybe support filters later, e.g. recieve only the 
Sensations where the 'channel' parameter is 'SystemMessages'.  For now it is 
overkill.
-    void subscribe( Controller controller, Actor actor, String sensorId );
+    void subscribe( Controller controller, Actor actor, ID sensorId );
 
     /**
      * Unsubscribes the specified {@link Controller} so that it no longer 
recieves {@link Sensation}s from this {@link Sensor}.
@@ -34,6 +31,6 @@
      * @param actor      the {@link Actor} that this Sensor is in.
      * @param sensorId   the identifier of the sensor in the Actor.
      */
-    void unsubscribe( Controller controller, Actor actor, String sensorId );
+    void unsubscribe( Controller controller, Actor actor, ID sensorId );
 
 }


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: [232] trunk/skycastle/modules/core