JGSL_agent

agent in a server or client

Title agent in a server or client
Author(s) LiXizhi
Date 2007/11/6, refined with no sim 2008.8.6
File script/kids/3DMapSystemNetwork/JGSL_agent.lua

Description

agent can be serialized to and from compact streams to be sent via network.

TIP Sample Code

NPL.load("(gl)script/kids/3DMapSystemNetwork/JGSL_agent.lua");
local agent = Map3DSystem.JGSL.agent:new()
agent:UpdateFromPlayer(ParaScene.GetPlayer(), 2);
agent:print_history();
print(agent:GenerateUpdateStream(0))
agent:UpdateFromPlayer(ParaScene.GetPlayer(), 3);
agent:print_history();
print(agent:GenerateUpdateStream(2))
print(agent:GenerateUpdateStream(3))

log("changing history...")
agent:UpdateFromStream("4:36.72,3:20091.00,6:7f,2:character/v4/Can/can01/can01.x,5:20086.00", 0)
agent:print_history();

Member Functions

JGSL.agent:new

---------------------------------
 agent template and functions
---------------------------------
JGSL.agent = {
   -- nil for unknown, 1 for agent, 2 for observer, 3 for logged out. 
   state = nil,
   -- a send frame count, denoting how many times that it has sent its stream to other computers. 
   send_count = 0,
   -- a receive frame count, denoting how many times that it has received its update stream from other computer. 
   rec_count = 0,
   -- jid, the nid can be derived from it. 
   jid = nil,
   -- current position. After compressing, it has 2 decimal
   x=nil,y=nil,z=nil,
   -- grid x and gridz position. if they are not nil. the x=gx+rx,z=gz+rz
   gx=nil,gz=nil,
   -- relative position. 
   rx=nil,ry=nil,rz=nil,
   -- the nick name to be displayed on head of character 
   nickname=nil,
   -- id or string of the main asset file of the agent
   AssetFile=nil,
   -- customizable character string,
   ccs=nil,
   -- scaling.After compressing, it has 2 decimal
   scaling=nil,
   -- anim id or string
   anim=nil,
   -- character facing. After compressing, it is [0,6.28/256)
   facing=nil,
   -- whether this is a dummy. if nil, it is not. if 1 it is . default to nil. 
   dummy = nil,
   -- this is a mapping from key name to their ValueTracker object. 
   -- currently, values in trackers are compressed data. 
   history = nil,
   -- last time the agent is updated by the server or client depending on it use
   LastActiveTime = nil,
   -- if an agent is not active in 20 seconds, we will make it inactive user and remove from active user list. 
   TimeOut = 20000,
}

syntax

function JGSL.agent:new (o)

parameters

o  

JGSL.agent:Dump

for debugging only. dump to log

syntax

function JGSL.agent:Dump()

JGSL.agent:CheckTimeOut

Check if agent has not been inactive for some time.

  • param curTime : it should be current time returned by GetGameTime()
  • param TimeOut : how many millisecond that a agent is time out. return true if the agent is timed out, the caller may need to remove the agent from the client agent list.

syntax

function JGSL.agent:CheckTimeOut(curTime, TimeOut)

parameters

curTime it should be current time returned by GetGameTime()
TimeOut  

JGSL.agent:tick

set the agent LastActiveTiem to be curTime

  • param curTime : it should be current time returned by GetGameTime(). If nil,ParaGlobal.GetGameTime() is used
  • param updateAvatar : if true, it will set the dynamic attribute of the avater in the scene for the last active time. since a avater may be updated or timed out by multiple grid node proxy. this dynamic attribute helps to prevent incorrect timeout, in case the agent on one proxy is timed out while not on the other one.
  • return return : true if agent avatar is not found in the scene and need to be updated.

syntax

function JGSL.agent:tick(curTime, updateAvatar)

parameters

curTime it should be current time returned by GetGameTime(). If nil,ParaGlobal.GetGameTime() is used
updateAvatar  
return true if agent avatar is not found in the scene and need to be updated.

JGSL.agent:IsIntact

whether this agent is currently intact, meaning it has enough information like appearance(AssetFile) and position. if an agent is not intact, we will ask the host to recover it. Please see JGSL recovery rules for more information.

  • return true : if successful.

syntax

function JGSL.agent:IsIntact()

parameters

return if successful.

JGSL.agent:cleanup

clean up the agent state and delete its avatar from the scene if timed out

  • bNoSim __ : if true no simulation on the server is done. if true, we do not care about the avatar in the scene
  • return true : if avatar is timed out as well.

syntax

function JGSL.agent:cleanup(bNoSim)

parameters

bNoSim  

JGSL.agent:update

update a agent's 3D avatar according to information in the agent structure. if the 3d avatar is not created before, it will be created. If agent structure does not get enough information to create, it will ignore updating until the server has got enough information from the client.

syntax

function JGSL.agent:update(curTime)

parameters

curTime  

JGSL.agent:GenerateCreationStream

insert creation related data to agent streams.

syntax

function JGSL.agent:GenerateCreationStream(agentStream)

parameters

agentStream  

JGSL.agent:UpdateFromPlayer

update this agent data from a player.

  • param player : if this is nil, the current player is used
  • timeid __ : time to write to history. if nil, it will write to each field history (time, value) pairs.

syntax

function JGSL.agent:UpdateFromPlayer(player, timeid)

parameters

player if this is nil, the current player is used
timeid  

JGSL.agent:print_history

for debugging

syntax

function JGSL.agent:print_history()

JGSL.agent:UpdateFromSelf

save current agent.* changes to track history

syntax

function JGSL.agent:UpdateFromSelf(timeid)

parameters

timeid  

JGSL.agent:UpdateFromStream

Update this agent data (also saves changes to history) from an opcode encoded text stream. It does not call update() to update the actual avartar. One needs to call it manually. agent data structure can be synchronized incrementally via streams.

  • stream __ : opcode encoded text stream that is usually generated by another agent's GenerateUpdateStream() from a remote computer.
  • timeid __ : time to write to history.

syntax

function JGSL.agent:UpdateFromStream(stream, timeid)

parameters

stream  
timeid  

JGSL.agent:GenerateUpdateStream

Generate stream from this agent data

  • timeid __ : only generate stream field that has changed after this time. if nil, all fields are streamed.
  • return __ : a text data string that can be sent over the network to update the agent. It will return nil, if no stream needs to be sent

syntax

function JGSL.agent:GenerateUpdateStream(timeid)

parameters

timeid  
Topic revision: r1 - 2008-02-29 - LiXizhi
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2022 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback