---++!! !JGSL_agent %TOC{title="Contents:"}% %STARTINCLUDE% ---++ 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. %T% __Sample Code__ <verbatim> 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(); </verbatim> ---+++ Member Functions ---++++ !JGSL.agent:new <verbatim>--------------------------------- 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, }</verbatim> __syntax__ <verbatim>function JGSL.agent:new (o)</verbatim> __parameters__ | *o* | | ---++++ !JGSL.agent:Dump for debugging only. dump to log __syntax__ <verbatim>function JGSL.agent:Dump()</verbatim> ---++++ !JGSL.agent:CheckTimeOut Check if agent has not been inactive for some time. * _param_ __curTime__ : it should be current time returned by ParaGlobal.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__ <verbatim>function JGSL.agent:CheckTimeOut(curTime, TimeOut)</verbatim> __parameters__ | *curTime* | it should be current time returned by ParaGlobal.GetGameTime() | | *TimeOut* | | ---++++ !JGSL.agent:tick set the agent LastActiveTiem to be curTime * _param_ __curTime__ : it should be current time returned by ParaGlobal.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__ <verbatim>function JGSL.agent:tick(curTime, updateAvatar)</verbatim> __parameters__ | *curTime* | it should be current time returned by ParaGlobal.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__ <verbatim>function JGSL.agent:IsIntact()</verbatim> __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__ <verbatim>function JGSL.agent:cleanup(bNoSim)</verbatim> __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__ <verbatim>function JGSL.agent:update(curTime)</verbatim> __parameters__ | *curTime* | | ---++++ !JGSL.agent:GenerateCreationStream insert creation related data to agent streams. __syntax__ <verbatim>function JGSL.agent:GenerateCreationStream(agentStream)</verbatim> __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__ <verbatim>function JGSL.agent:UpdateFromPlayer(player, timeid)</verbatim> __parameters__ | *player* | if this is nil, the current player is used | | *timeid* | | ---++++ !JGSL.agent:print_history for debugging __syntax__ <verbatim>function JGSL.agent:print_history()</verbatim> ---++++ !JGSL.agent:UpdateFromSelf save current agent.* changes to track history __syntax__ <verbatim>function JGSL.agent:UpdateFromSelf(timeid)</verbatim> __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__ <verbatim>function JGSL.agent:UpdateFromStream(stream, timeid)</verbatim> __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__ <verbatim>function JGSL.agent:GenerateUpdateStream(timeid)</verbatim> __parameters__ | *timeid* | | %STOPINCLUDE%
E
dit
|
A
ttach
|
P
rint version
|
H
istory
: r1
|
B
acklinks
|
V
iew topic
|
Ra
w
edit
|
M
ore topic actions
Topic revision: r1 - 2008-02-29
-
LiXizhi
Home
Site map
CCWeb web
HaqiTeen web
Main web
ParaEngine web
TWiki web
Main Web
Users
Groups
Index
Search
Changes
Notifications
RSS Feed
Statistics
导航页WebTopMenu
Preferences
开发指南
Getting Started
ParacraftSDK
NPL
MCML
NPL Reference Manual
美术Mod
Account
Log In
English
简体中文
簡體中文
E
dit
A
ttach
Copyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback