Exemple #1
0
        public virtual void Initializa(long local_player_pstid, CombatStartInfo combat_start_info)
        {
            //真正的local_player_pstid在局外,传进来就好;combat_start_info是给所有玩家、观战者、以及录像回放时,都一致的消息
            m_local_player_pstid = local_player_pstid;
            m_level_data         = GetConfigProvider().GetLevelData(combat_start_info.m_level_id);
            m_state            = CombatClientState.Loading;
            m_state_frame_cnt  = 0;
            m_state_start_time = -1;
            m_last_update_time = -1;
            m_waiting_cnt      = 0;
#if UNITY_EDITOR
            m_is_first_frame = true;
#endif

            AttributeSystem.Instance.InitializeAllDefinition(m_combat_factory.GetConfigProvider());
            ComponentTypeRegistry.RegisterDefaultComponents();
            BehaviorTreeNodeTypeRegistry.RegisterDefaultNodes();
            DamageModifier.RegisterDefaultModifiers();
            m_combat_factory.RegisterCommands();

            BehaviorTreeFactory.Instance.SetConfigProvider(m_combat_factory.GetConfigProvider());

            m_logic_world = m_combat_factory.CreateLogicWorld();
            m_logic_world.Initialize(this, combat_start_info.m_world_seed, true);
            m_render_world = m_combat_factory.CreateRenderWorld();
            m_render_world.Initialize(this, m_logic_world);
            m_logic_world.SetIRenderWorld(m_render_world);
            m_sync_client = m_combat_factory.CreateSyncClient();
            m_sync_client.Init(m_logic_world);

            BuildLogicWorld(combat_start_info);
            BuildRenderWorld(m_level_data);
        }
        public void AddPredictOffset(Vector3 offset)
        {
            GridGraph grid_graph = m_position_component.GetGridGraph();

            if (grid_graph != null)
            {
                Vector3   interpolation_position = m_interpolation_tr.localPosition + offset;
                Vector3   entity_position        = m_model_component.GetCurrentPosition() + interpolation_position;
                Vector3FP entity_position_fp     = RenderWorld.Vector3_To_Vector3FP(entity_position);
                GridNode  node = grid_graph.Position2Node(entity_position_fp);
                if (node == null)
                {
                    if (!GetRenderWorld().OnEntityOutOfEdge(GetRenderEntity()))
                    {
                        return;
                    }
                }
                else if (!node.Walkable && m_locomotor_component.AvoidObstacle())
                {
                    Vector3FP offset_fp = RenderWorld.Vector3_To_Vector3FP(offset);
                    //try z
                    entity_position_fp.x -= offset_fp.x;
                    node = grid_graph.Position2Node(entity_position_fp);
                    if (node == null || !node.Walkable)
                    {
                        //try x
                        entity_position_fp.x += offset_fp.x;
                        entity_position_fp.z -= offset_fp.z;
                        node = grid_graph.Position2Node(entity_position_fp);
                        if (node == null || !node.Walkable)
                        {
                            return;
                        }
                        else
                        {
                            offset.z = 0;
                        }
                    }
                    else
                    {
                        offset.x = 0;
                    }
                }
            }

            for (int i = 0; i < m_movement_predicts.Count; ++i)
            {
                MovementPredict predict = m_movement_predicts[i];
                if (predict.m_state == MovementPredict.AccumulateOffsetState || predict.m_state == MovementPredict.FollowLogicState)
                {
                    predict.m_offset += offset;
                    m_interpolation_tr.localPosition += offset;
                    //LogWrapper.LogDebug("AddPredictOffset, predict.m_offset = ", predict.m_offset.ToString(), ", m_interpolation_tr = ", m_interpolation_tr.localPosition.ToString());
                    break;
                }
            }
        }
Exemple #3
0
        public virtual void Destruct()
        {
            m_sync_client.Destruct();
            m_sync_client = null;
            m_render_world.Destruct();
            m_render_world = null;
            m_logic_world.Destruct();
            m_logic_world = null;

            m_combat_factory = null;
            m_level_data     = null;
        }
        void CreateModel()
        {
            m_unity_go = UnityResourceManager.Instance.CreateGameObject(m_asset_name);
            if (m_unity_go == null)
            {
                return;
            }

            if (m_bodyctrl_path != null)
            {
                m_bodyctrl_tr = m_unity_go.transform.FindChild(m_bodyctrl_path);
            }
            else
            {
                m_bodyctrl_tr = m_unity_go.transform;
            }
            m_bodyctrl_obj = m_bodyctrl_tr.gameObject;

            if (m_headctrl_path != null)
            {
                m_headctrl_tr = m_unity_go.transform.FindChild(m_headctrl_path);
            }
            if (m_headctrl_tr != null)
            {
                m_headctrl_obj = m_headctrl_tr.gameObject;
            }

            Entity logic_entity = GetLogicEntity();

            m_position_component = logic_entity.GetComponent(PositionComponent.ID) as PositionComponent;
            if (m_position_component != null)
            {
                m_last_position                = RenderWorld.Vector3FP_To_Vector3(m_position_component.CurrentPosition);
                m_bodyctrl_tr.localPosition    = m_last_position;
                m_bodyctrl_tr.localEulerAngles = new Vector3(0, (float)m_position_component.BaseAngle, 0);
                if (m_headctrl_tr != null)
                {
                    m_bodyctrl_tr.localEulerAngles = new Vector3(0, (float)m_position_component.HeadAngle, 0);
                }
            }

            UnityObjectBinding binding = m_bodyctrl_tr.gameObject.GetComponent <UnityObjectBinding>();

            if (binding == null)
            {
                binding = m_bodyctrl_tr.gameObject.AddComponent <UnityObjectBinding>();
            }
            binding.EntityID = logic_entity.ID;
        }
 public bool UpdatePosition()
 {
     if (m_unity_go == null)
     {
         LogWrapper.LogError("ModelComponent.UpdatePosition, Object has already been destroyed!!!!!!!!!");
         return(false); //ZZWTODO
     }
     m_last_position = RenderWorld.Vector3FP_To_Vector3(m_position_component.CurrentPosition);
     if (m_predict_component != null)
     {
         m_predict_component.OnLogicUpdatePosition(m_last_position - m_bodyctrl_tr.localPosition);
     }
     m_bodyctrl_tr.localPosition = m_last_position;
     return(true);
 }
 public RenderEntityManager(LogicWorld logic_world, RenderWorld render_world)
     : base(logic_world, IDGenerator.INVALID_FIRST_ID)
 {
     m_render_world = render_world;
 }
 public override void Destruct()
 {
     base.Destruct();
     m_render_world = null;
 }
Exemple #8
0
 public CameraController(RenderWorld render_world)
 {
 }
 public void Destruct()
 {
     m_render_world          = null;
     m_logic_world           = null;
     m_render_entity_manager = null;
 }
 public RenderMessageProcessor(RenderWorld render_world)
 {
     m_render_world          = render_world;
     m_logic_world           = render_world.GetLogicWorld();
     m_render_entity_manager = render_world.GetRenderEntityManager();
 }
        void PredictEntityMove(EntityMoveCommand cmd)
        {
            switch (cmd.m_move_type)
            {
            case EntityMoveCommand.DirectionType:
            {
                m_copy_state = NoCopy;
                bool exist = false;
                uint crc   = CalculateMoveCommandCRC(cmd);
                //LogWrapper.LogDebug("PredictEntityMove, DirectionType, time =", GetCurrentTime(), ", dir = ", cmd.m_vector.ToString(), ", crc = ", crc);
                for (int i = 0; i < m_movement_predicts.Count; ++i)
                {
                    MovementPredict predict = m_movement_predicts[i];
                    if (predict.m_command_crc == crc)
                    {
                        if (predict.m_state == MovementPredict.AccumulateOffsetState || predict.m_state == MovementPredict.FollowLogicState)
                        {
                            exist = true;
                        }
                    }
                    else if (predict.m_state == MovementPredict.AccumulateOffsetState || predict.m_state == MovementPredict.FollowLogicState)
                    {
                        predict.m_state = MovementPredict.EliminateOffsetState;
                        predict.m_task.Cancel();
                    }
                }
                if (!exist)
                {
                    Vector3 direction          = RenderWorld.Vector3FP_To_Vector3(cmd.m_vector);
                    PredictLocomotionTask task = RenderTask.Create <PredictLocomotionTask>();
                    task.Construct(this, direction, m_max_predict_time);
                    var task_scheduler = GetRenderWorld().GetTaskScheduler();
                    task_scheduler.Schedule(task, GetRenderWorld().CurrentTime, FixPoint.PrecisionFP);
                    MovementPredict predict = RecyclableObject.Create <MovementPredict>();
                    predict.m_state       = MovementPredict.AccumulateOffsetState;
                    predict.m_command_crc = crc;
                    predict.m_task        = task;
                    m_movement_predicts.Add(predict);
                    PlayMoveAnimation(direction);
                }
            }
            break;

            case EntityMoveCommand.DestinationType:
            {
                if (m_copy_state == NoCopy)
                {
                    m_copy_state = WaitCopy;
                }
                //下面这段代码和EntityMoveCommand.StopMoving差不多
                for (int i = 0; i < m_movement_predicts.Count; ++i)
                {
                    MovementPredict predict = m_movement_predicts[i];
                    if (predict.m_state == MovementPredict.AccumulateOffsetState || predict.m_state == MovementPredict.FollowLogicState)
                    {
                        predict.m_state = MovementPredict.EliminateOffsetState;
                        predict.m_task.Cancel();
                    }
                }
                MovementPredict temp = RecyclableObject.Create <MovementPredict>();
                temp.m_state = MovementPredict.CopyLogicState;
                m_movement_predicts.Add(temp);
                Vector3 direction = RenderWorld.Vector3FP_To_Vector3(cmd.m_vector) - m_model_component.GetCurrentPosition();
                PlayMoveAnimation(direction);
            }
            break;

            case EntityMoveCommand.StopMoving:
            {
                m_copy_state = NoCopy;
                for (int i = 0; i < m_movement_predicts.Count; ++i)
                {
                    MovementPredict predict = m_movement_predicts[i];
                    if (predict.m_state == MovementPredict.AccumulateOffsetState || predict.m_state == MovementPredict.FollowLogicState)
                    {
                        predict.m_state = MovementPredict.EliminateOffsetState;
                        predict.m_task.Cancel();
                    }
                }
                MovementPredict temp = RecyclableObject.Create <MovementPredict>();
                temp.m_state = MovementPredict.StopState;
                m_movement_predicts.Add(temp);
                StopMoveAnimation();
                //LogWrapper.LogDebug("PredictEntityMove, StopMoving, time =", GetCurrentTime());
            }
            break;

            default:
                break;
            }
        }
 protected override void OnDestruct()
 {
     m_render_world = null;
     m_entity       = null;
 }
 public RenderEntity(RenderWorld render_world)
 {
     m_render_world = render_world;
 }