Drag[en]gine Script Module DragonScript  1.23
Dragengine.Scenery.ECBehaviorNetworkState Class Reference

Behavior element behavior adding network state support. More...

Inheritance diagram for Dragengine.Scenery.ECBehaviorNetworkState:
Dragengine.Scenery.DefaultECBehavior Dragengine.Scenery.ECBehavior Dragengine.Scenery.BehaviorCompatiblePersistency

Classes

class  BlockListenerFactory
 Factory creating listeners using block. More...
 
class  DataValue
 Value listener for data type values. More...
 
class  DefaultListener
 Default implementation of behavior instance listener. More...
 
class  DefaultMessageListener
 Default implementation of message listener. More...
 
class  DefaultValueListener
 Default implementation of value listener. More...
 
class  DVectorValue
 Value listener for DVector type values. More...
 
class  FloatValue
 Value listener for float type values. More...
 
class  Instance
 Behavior instance. More...
 
class  IntegerValue
 Value listener for integer type values. More...
 
interface  Listener
 Listener for behavior instance events. More...
 
interface  ListenerFactory
 Factory creating listeners. More...
 
interface  MessageListener
 Message listener. More...
 
class  Point3Value
 Value listener for Point3 type values. More...
 
class  PointValue
 Value listener for Point type values. More...
 
class  QuaternionValue
 Value listener for Quaternion type values. More...
 
class  StringValue
 Value listener for string type values. More...
 
interface  ValueListener
 Value listener. More...
 
class  Vector2Value
 Value listener for Vector2 type values. More...
 
class  VectorValue
 Value listener for Vector type values. More...
 

Public Member Functions

void addListenerFactory (Block blockFactory)
 Add listener factory using block. More...
 
void addListenerFactory (ListenerFactory factory)
 Add listener factory. More...
 
ECBehaviorInstance createInstance (BehaviorElement element)
 Create Behavior instance. More...
 
void dispose ()
 Dispose of behavior. More...
 
void forEachListenerFactory (Block ablock)
 Visit listener factories with block with argument ListenerFactory. More...
 
ConnectionTracker getConnectionTracker ()
 Connection tracker. More...
 
byte getMessageCode ()
 Message code to use. More...
 
NetworkStateTracker getNetworkStateTracker ()
 Network state tracker. More...
 
byte getRequestLinkCode ()
 Request link code to use. More...
 
Instance instance (BehaviorElement element)
 Get instance in element from owner element class. More...
 
ECBehaviorNetworkState new (BehaviorElementClass eclass, byte requestLinkCode, byte messageCode)
 Create behavior element class. More...
 
ECBehaviorNetworkState new (BehaviorElementClass eclass, byte requestLinkCode, byte messageCode, ConnectionTracker connectionTracker, NetworkStateTracker networkStateTracker)
 
void setConnectionTracker (ConnectionTracker connectionTracker)
 Set connection tracker. More...
 
void setMessageCode (byte code)
 Set message code to use. More...
 
void setNetworkStateTracker (NetworkStateTracker networkStateTracker)
 Set network state tracker. More...
 
void setRequestLinkCode (byte code)
 Set request link code to use. More...
 
- Public Member Functions inherited from Dragengine.Scenery.DefaultECBehavior
void assignInstanceIndex (int instanceIndex)
 Assign instance index. More...
 
String getBehaviorID ()
 Unique identifier of behavior. More...
 
String getID ()
 Identifier. More...
 
int getInstanceIndex ()
 Instance index. More...
 
void loadSupportedData (String identifier, PersistencyEnvironment env, FileReader reader, ECBehaviorInstance instance)
 Load instance data of another behavior. More...
 
bool supportsBehaviorID (String identifier)
 Behavior supports loading instance data of another behavior. More...
 

Static Public Member Functions

static bool createAndAddFromLinkRequest (Connection connection, NetworkState state, FileReader reader, GameWorld gameWorld)
 Create element from link request message and add it to game world. More...
 
static bool createAndAddFromLinkRequest (Connection connection, NetworkState state, FileReader reader, GameWorld gameWorld, ElementClassList elementClassList)
 
static ECBehaviorNetworkState.Instance createFromLinkRequest (Connection connection, NetworkState state, FileReader reader)
 Create element from link request message. More...
 
static ECBehaviorNetworkState.Instance createFromLinkRequest (Connection connection, NetworkState state, FileReader reader, ElementClassList elementClassList)
 
static ECBehaviorNetworkState getBehaviorIn (BehaviorElementClass eclass)
 Get behavior in element class or null if absent. More...
 
static Instance getInstanceIn (BehaviorElement element)
 Get instance in element or null if absent. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Dragengine.Scenery.DefaultECBehavior
DefaultECBehavior new (BehaviorElementClass eclass)
 Create default composeable behavior with empty identifier. More...
 
DefaultECBehavior new (BehaviorElementClass eclass, String id)
 Create default composeable behavior. More...
 
void setBehaviorID (String identifier)
 Set behavior identifier. More...
 
void useClassNameAsBehaviorID ()
 Set behavior identifier to "<class-name>:<identifier>". More...
 
void useFullyQualifiedClassNameAsBehaviorID ()
 Set behavior identifier to "<fully-qualified-class-name>:<identifier>". More...
 

Detailed Description

Behavior element behavior adding network state support.

The behavior is only active during creation time the StubElement contains Connection instance. Behavior can not be attached to a connection later.

Network states allow elements to link their state to a network state on a remote host. This behavior can operate in two modes depending on how the element is created.

If the element is created on the local host the owner of this behavior is the master state. As such the master state is changed with the linked state on the remote side updated by the Network Module to match. The behavior creates a NetworkState resources and links it to the server network state during init().

If the element is requested to be created by the server the NetworkState is created by the Network Module and is handed over to the game using ConnectionListener.linkState(). In this case the behavior uses the provided network state resource and and acts as the slave. The server side changes the state and this behavior receives update notifications.

In both situations other behaviors add values to track. If this state is the server state they apply changes to the value if their state changes. If this state is the client state they will be notified if the remote side modifies the value. Such behaviors have to add a listener during constructor time implementing Listener.addValues() to add the values at init time in the correct time. Doing this anywhere else likely results in problems.

To enable network state support add ECBehaviorNetworkState then add behaviors designed to add and maintain network state values. A typical example of such a behaviors are ECBehaviorNStateGeometry or ECBehaviorNStateLocomotion.

No element class properties are added.

This behavior does not require the element class to be persistable (setPersistable).

This behavior can be present only once in the element class.

Member Function Documentation

◆ addListenerFactory() [1/2]

void Dragengine.Scenery.ECBehaviorNetworkState.addListenerFactory ( Block  blockFactory)

Add listener factory using block.

Block receives as parameter Instance and returns Listener.

◆ addListenerFactory() [2/2]

void Dragengine.Scenery.ECBehaviorNetworkState.addListenerFactory ( ListenerFactory  factory)

Add listener factory.

◆ createAndAddFromLinkRequest() [1/2]

static bool Dragengine.Scenery.ECBehaviorNetworkState.createAndAddFromLinkRequest ( Connection  connection,
NetworkState  state,
FileReader  reader,
GameWorld  gameWorld 
)
static

Create element from link request message and add it to game world.

Call this after reading the request link code from the network message reader. This method does the following:

  • Reads one StubElement from the network message reader
  • Assigns a newly creates NetworkState to the stub
  • Calls StubElement.createElement() to create the element
  • Calls GameWorld.addElement() to add created element to game world
  • Returns NetworkState stored in ECBehaviorNetworkState instance from created element

The caller is not responsible for the behavior element behind the returned NetworkState since the GameWorld owns it now. This is the most common function call to use.

A typical use looks like this:

pin Dragengine.Networking
pin Dragengine.Preloading
pin Dragengine.Scenery
class MyConnectionHandler implements ConnectionListener
public var GameWorld gameWorld
public var Connection connection
...
public func bool linkState(NetworkState state, NetworkMessage message)
var FileReader reader = message.getReader()
var int requestLinkCode = reader.readByte()
select requestLinkCode
case 1 // change to math request link code used for this behavior
return ECBehaviorNetworkState.createAndAddFromLinkRequest(connection, state, reader, gameWorld)
...
end
end
end
static bool createAndAddFromLinkRequest(Connection connection, NetworkState state, FileReader reader, GameWorld gameWorld)
Create element from link request message and add it to game world.

◆ createAndAddFromLinkRequest() [2/2]

static bool Dragengine.Scenery.ECBehaviorNetworkState.createAndAddFromLinkRequest ( Connection  connection,
NetworkState  state,
FileReader  reader,
GameWorld  gameWorld,
ElementClassList  elementClassList 
)
static

◆ createFromLinkRequest() [1/2]

static ECBehaviorNetworkState.Instance Dragengine.Scenery.ECBehaviorNetworkState.createFromLinkRequest ( Connection  connection,
NetworkState  state,
FileReader  reader 
)
static

Create element from link request message.

Call this after reading the request link code from the network message reader. This method does the following:

  • Reads one StubElement from the network message reader
  • Assigns a newly creates NetworkState to the stub
  • Calls StubElement.createElement() to create the element
  • Returns ECBehaviorNetworkState instance from created element

The caller is responsible for the behavior element owning the returned instance. Add it to a game world or store it in a place where it is properly disposed off later. Not doing so will causing memory leaks. Typical use case is to create a player actor for spawning later. For most other situations createAndAddFromLinkRequest() is better.

A typical use looks like this:

pin Dragengine.Networking
pin Dragengine.Preloading
pin Dragengine.Scenery
class MyConnectionHandler implements ConnectionListener
public var GameWorld gameWorld
public var Connection connection
...
public func bool linkState(NetworkState state, NetworkMessage message)
var FileReader reader = message.getReader()
var int requestLinkCode = reader.readByte()
select requestLinkCode
case 1 // change to math request link code used for this behavior
// store instance or instance.getElement() somewhere for spawning later
storeMe = ECBehaviorNetworkState.createFromLinkRequest(connection, state, reader)
return true
...
end
end
end
static ECBehaviorNetworkState.Instance createFromLinkRequest(Connection connection, NetworkState state, FileReader reader)
Create element from link request message.

◆ createFromLinkRequest() [2/2]

static ECBehaviorNetworkState.Instance Dragengine.Scenery.ECBehaviorNetworkState.createFromLinkRequest ( Connection  connection,
NetworkState  state,
FileReader  reader,
ElementClassList  elementClassList 
)
static

◆ createInstance()

ECBehaviorInstance Dragengine.Scenery.ECBehaviorNetworkState.createInstance ( BehaviorElement  element)

Create Behavior instance.

Implements Dragengine.Scenery.ECBehavior.

◆ dispose()

void Dragengine.Scenery.ECBehaviorNetworkState.dispose ( )

Dispose of behavior.

Reimplemented from Dragengine.Scenery.DefaultECBehavior.

◆ forEachListenerFactory()

void Dragengine.Scenery.ECBehaviorNetworkState.forEachListenerFactory ( Block  ablock)

Visit listener factories with block with argument ListenerFactory.

◆ getBehaviorIn()

static ECBehaviorNetworkState Dragengine.Scenery.ECBehaviorNetworkState.getBehaviorIn ( BehaviorElementClass  eclass)
static

Get behavior in element class or null if absent.

Use this method to check if a particular BehaviorElementClass contains a behavior of type ECBehaviorComponent.

◆ getConnectionTracker()

ConnectionTracker Dragengine.Scenery.ECBehaviorNetworkState.getConnectionTracker ( )

Connection tracker.

◆ getInstanceIn()

static Instance Dragengine.Scenery.ECBehaviorNetworkState.getInstanceIn ( BehaviorElement  element)
static

Get instance in element or null if absent.

Use this method to check if a particular BehaviorElement contains a behavior instance of type ECBehaviorNetworkState.Instance . If more than one instance is present returns the first instance.

◆ getMessageCode()

byte Dragengine.Scenery.ECBehaviorNetworkState.getMessageCode ( )

Message code to use.

◆ getNetworkStateTracker()

NetworkStateTracker Dragengine.Scenery.ECBehaviorNetworkState.getNetworkStateTracker ( )

Network state tracker.

◆ getRequestLinkCode()

byte Dragengine.Scenery.ECBehaviorNetworkState.getRequestLinkCode ( )

Request link code to use.

◆ instance()

Instance Dragengine.Scenery.ECBehaviorNetworkState.instance ( BehaviorElement  element)

Get instance in element from owner element class.

◆ new() [1/2]

ECBehaviorNetworkState Dragengine.Scenery.ECBehaviorNetworkState.new ( BehaviorElementClass  eclass,
byte  requestLinkCode,
byte  messageCode 
)

Create behavior element class.

◆ new() [2/2]

ECBehaviorNetworkState Dragengine.Scenery.ECBehaviorNetworkState.new ( BehaviorElementClass  eclass,
byte  requestLinkCode,
byte  messageCode,
ConnectionTracker  connectionTracker,
NetworkStateTracker  networkStateTracker 
)

◆ setConnectionTracker()

void Dragengine.Scenery.ECBehaviorNetworkState.setConnectionTracker ( ConnectionTracker  connectionTracker)

Set connection tracker.

◆ setMessageCode()

void Dragengine.Scenery.ECBehaviorNetworkState.setMessageCode ( byte  code)

Set message code to use.

◆ setNetworkStateTracker()

void Dragengine.Scenery.ECBehaviorNetworkState.setNetworkStateTracker ( NetworkStateTracker  networkStateTracker)

Set network state tracker.

◆ setRequestLinkCode()

void Dragengine.Scenery.ECBehaviorNetworkState.setRequestLinkCode ( byte  code)

Set request link code to use.


The documentation for this class was generated from the following file: