A very basic Federation : Lesson 4

Previous posts:

Lesson 1 – Lesson 2 – Lesson 3

Now, as last post of this series, I’ll cover the TankObject class.

I like to have a place to store every object I discover from RTI. It is useful when you need to get the object handle of a specific object. In our case, when the RTI send us an attribute update, it will give us the object handle too. So, it will be our work to discover what Tank the attribute is from.

At first look (and to keep it simple ) the XxxObject classes at my perspective are just Java POJOs.

// All our objects in RTI must be represented by Java classes. 
public class TankObject {
  // To hold the RTI object handle for a specific Tank
  private ObjectInstanceHandle instance;
  // All attributes from the SOM must be here
  private String model;
   
  // Getters and Setters ...
}
        

Of course you may have your own implementations. This way is just the way I like. As you can see, My Tank Java class is a representation of the SOM Tank object class:

<objectClass>
    <name>HLAobjectRoot</name>
      
    <objectClass>
        <name>Tank</name>
        <sharing>PublishSubscribe</sharing>
        <semantics>A Tank</semantics>
        <attribute>
            <name>Model</name>
            <dataType>HLAunicodeString</dataType>
            <updateType>Static</updateType>
            <updateCondition>NA</updateCondition>
            <ownership>NoTransfer</ownership>
            <sharing>PublishSubscribe</sharing>
            <dimensions/>
            <transportation>HLAreliable</transportation>
            <order>Receive</order>
            <semantics>The Tank Model</semantics>
        </attribute>                
    </objectClass>
      
</objectClass>

I’ll change the constructor because It must have a handle and give a way to test if a given object handle is this Tank:

// Constructor. Must hold the instance handle of this Tank in RTI.
public TankObject( ObjectInstanceHandle instance ) {
  this.model = UUID.randomUUID().toString().substring(1,5).toUpperCase();
  this.instance = instance;
}

// Check if a given object is this specific Tank
public boolean isMe( ObjectInstanceHandle obj ) {
  return obj.equals( instance );
}

I instantiate a default value to the Tank model in constructor…

this.model = UUID.randomUUID().toString().substring(1,5).toUpperCase();

… just for safe.

That’s it. Now you can run your first basic Federation and see some Tanks in the game.

I’ll extend this Federation as I need to show more complex examples.

Basic Tank Federation running

Basic Tank Federation running

 

 

Add Comment