/// <summary>
 /// 返回这个阴影线是否完全包含指定阴影
 /// </summary>
 /// <param name="shadow"></param>
 /// <returns></returns>
 public bool Contains(Shadow shadow)
 {
     /*
      *  阴影线对阴影是不重叠储存的,能连接的阴影肯定都合并了,所以如果完全包含参数阴影,必然是列表里有一个阴影完全包含了参数阴影
      */
     foreach (Shadow shadowInList in _shadows)
     {
         if (shadowInList.Contions(shadow))
         {
             return(true);
         }
     }
     return(false);
 }
        int GetInsertIndex(Shadow newShadow)
        {
            /*
             *  以起点为准
             *  遍历阴影列表
             *      if(当前阴影的起点在新阴影的起点后面)
             *          返回这个下标
             *
             *  遍历完了也没找到,说明要加在最后面,返回阴影列表长度
             */
            int insertIndex = 0;

            for (; insertIndex < _shadows.Count; insertIndex++)
            {
                if (_shadows[insertIndex].start > newShadow.start)
                {
                    return(insertIndex);
                }
            }

            return(insertIndex); // 循环结束的条件是 insertIndex >= _shadows.Count,因为是++的,所以循环结束后的 insertIndex 就是列表长度
        }
Exemple #3
0
        bool ComputeAndMergeALineAndGetIsFullShadow(Octant octant, int mainStep, ShadowLine shadowLine)
        {
            /*
             *  循环到一行结束或地图边界
             *  {
             *      获取投影
             *      通过投影判断可见度并存入视野
             *      通过投影判断是否遮挡视线并存入阴影线
             *  }
             *  返回阴影是否覆盖了整个八分角
             */
            Vector2 currentPosition;

            for (int sideStep = 0; sideStep <= mainStep + LINE_PATCH && _visibleMap.Contains(currentPosition = octant.GetPosition(mainStep, sideStep)); sideStep++)
            {
                Shadow projection = ShadowLine.GetQuadProjection(mainStep, sideStep);
                DrawShadow(shadowLine, currentPosition, projection);
                UpdateShadowLine(currentPosition, shadowLine, projection);
            }

            return(shadowLine.IsFullShadow());
        }
 void MergePreviousAndNewAndNextShadow(int insertIndex, Shadow previousOverlappingShadow, Shadow nextOverlappingShadow)
 {
     /*
      *  合并前中后的情况,说明前中后三个阴影范围相连
      *  前阴影的结尾移动到后的结尾处
      *  把后移除掉
      *  中本来就不在列表里,不去管
      */
     previousOverlappingShadow.end = nextOverlappingShadow.end;
     _shadows.RemoveAt(insertIndex); // 插入下标在插入新阴影之前就是下一个阴影的下标
 }
 void InsertNewShadow(int insertIndex, Shadow newShadow)
 {
     _shadows.Insert(insertIndex, newShadow);
 }
Exemple #6
0
 bool IsBlockView(Vector2 position, ShadowLine shadowLine, Shadow shadow)
 {
     return(!_visibleMap.IsTransparent(position) && !shadowLine.Contains(shadow)); // 很明显的,只要一个东西没有被完全挡住,他又不是透明的,那他就一定会遮挡视线
 }
Exemple #7
0
 bool IsVisible(Shadow projection, ShadowLine shadowLine)
 {
     return(!shadowLine.Contains(projection)); // 我觉得如果是一个经验丰富的观察者,就算只能看见一小部分也是能判断出看到了什么的,那就只要没有被完全遮挡就视为可见
 }