コード例 #1
0
ファイル: AgentManager.cs プロジェクト: sikanzhu/innova
        // watch and unwatch region
        public void RegionWatch(RepeatedField <Region> rs)
        {
            // destroy actors out of the regions
            /* this lock is not necessary */            //lock( _agents )
            {
                List <long> ids = new List <long>(_agents.Keys);
                foreach (long id in ids)
                {
                    AgentUtils <OBJECT> .Agent agent = _agents[id];
                    /* this lock is not necessary */                    //lock( _agents_listener ) //TODO need lock?
                    {
                        Region region = agent.region;
                        if (null != region)
                        {
                            if (false == rs.Contains(region))
                            {
                                _agents_listener.ialDestroy(id, agent.obj);
                                _agents.Remove(id);
                            }
                        }
                    }
                }
            }

            /* this lock is not necessary */            //lock( _watching_regions )
            {
                _watching_regions = rs;
            }
        }
コード例 #2
0
        // initialize
        public void Init(AgentUtils <OBJECT> .IAgentsListener al, ActorUtils.IActorsListener pl)
        {
            _agent_manager.Init(al);
            _actor_manager.Init(pl);

            _gate = new PlayerGate(this);
            if (false == _gate.Connect
                    (Constant.ADRESS_LOCALHOST, Constant.GATE_PLAYER_PORT
                    , Constant.MAX_READ, Constant.MAX_WRITE, Constant.MAX_PACKAGE))
            {
                Debug.LogErrorFormat("Can not connect to gate.");
            }
        }
コード例 #3
0
ファイル: AgentManager.cs プロジェクト: sikanzhu/innova
        public void MessageProcess(GateToPlayer msg)
        {
            ConsoleOutput.Trace("AgentManager: MessageProcess" + " U" + msg.Updated.Count + " E" + msg.Exited.Count);
            // build actor map
            /* this lock is not necessary */            //lock( _agents )
            {
                /* this lock is not necessary */        //lock( _agents_listener ) //TODO need lock?
                {
                    foreach (RegionActorPair rap in msg.Updated)
                    {
                        ConsoleOutput.Trace("AgentManager: MessageProcess " + rap.Actor.Id + "." + rap.Actor.Ptypes.Count + " updated.");
                        if (false == _agents_listener.ialIsSelf(rap.Actor.Id))
                        {
                            // find or create agent
                            AgentUtils <OBJECT> .UpdateOrInsertAgent
                                (rap.Region, rap.Actor.Id, rap.Actor.Ptypes, rap.Actor.Pdatas, _agents);
                        }
                    }

                    foreach (KeyValuePair <long, AgentUtils <OBJECT> .Agent> a in _agents)
                    {
                        long id = a.Key;
                        AgentUtils <OBJECT> .Agent agent = a.Value;

                        // try to create GameObject for new agents
                        if (null == agent.obj)
                        {
                            {
                                string prop_str = "";
                                foreach (KeyValuePair <int, AgentUtils <OBJECT> .Property> kvp in agent.properties)
                                {
                                    prop_str += kvp.Key + "," + kvp.Value.data.Length + ";";
                                }
                                ConsoleOutput.Trace("Agent enter: " + id + "|" + prop_str + " in " + agent.region.Index);
                            }

                            agent.obj = _agents_listener.ialCreate(id, agent.properties);
                        }
                        // update agents
                        else
                        {
                            if (agent.updated)
                            {
                                {
                                    string prop_str = "";
                                    foreach (KeyValuePair <int, AgentUtils <OBJECT> .Property> kvp in agent.properties)
                                    {
                                        prop_str += kvp.Key + "," + kvp.Value.data.Length + ";";
                                    }
                                    ConsoleOutput.Trace("Agent update: " + id + "|" + prop_str + " in " + agent.region.Index);
                                }
                                agent.updated = _agents_listener.ialUpdate(agent.obj, agent.properties);
                            }
                        }
                    }

                    // delete exited agents
                    foreach (RegionIdPair rip in msg.Exited)
                    {
                        AgentUtils <OBJECT> .Agent agent;
                        if (_agents.TryGetValue(rip.Id, out agent))
                        {
                            {
                                ConsoleOutput.Trace("Agent exit: " + rip.Id + " from " + rip.Region.Index);
                            }
                            if (rip.Region.Equals(agent.region))
                            // if they are different
                            // means the agent has entered another region
                            {
                                _agents_listener.ialDestroy(rip.Id, agent.obj);
                                _agents.Remove(rip.Id);
                            }
                        }
                    }
                }
            }
        }
コード例 #4
0
ファイル: AgentManager.cs プロジェクト: sikanzhu/innova
 public void Deinit()
 {
     _agents_listener = null;
 }
コード例 #5
0
ファイル: AgentManager.cs プロジェクト: sikanzhu/innova
 //
 public void Init(AgentUtils <OBJECT> .IAgentsListener al)
 {
     _agents_listener = al;
 }