Ejemplo n.º 1
0
 public void AddLayer(LayerID layerID)
 {
     if (LayerID.Min <= layerID && layerID < LayerID.Max)
     {
         MarkAsUINT |= FlagUtil.BIT_FLAG((int)layerID);
     }
 }
Ejemplo n.º 2
0
 public void RemoveLayer(LayerID layerID)
 {
     if (LayerID.Min <= layerID && layerID < LayerID.Max)
     {
         MarkAsUINT &= ~(FlagUtil.BIT_FLAG((int)layerID));
     }
 }
 /// <summary>
 /// 射线检测Actor
 /// </summary>
 /// <param name="ray">指定的射线</param>
 /// <param name="layerid">参与检测的层</param>
 /// <returns>射线检测到Actor(射线从起点发出,第一个检测到的Actor),若没有检测到任何Actor,返回NULL</returns>
 static public Actor IntersectWorld_Actor(ref Ray ray, LayerID layerid)
 {
     if (LayerID.Min <= layerid && layerid < LayerID.Max)
     {
         return(ICall_IntersectWorld_Actor(ref ray, LayerMark.LayerIDToUINTMark(layerid)));
     }
     return(null);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// ���߼��Actor
 /// </summary>
 /// <param name="ray">ָ��������</param>
 /// <param name="layerid">������IJ�</param>
 /// <returns>���߼�⵽Actor�����ߴ���㷢������һ����⵽��Actor������û�м�⵽�κ�Actor������NULL</returns>
 public static Actor IntersectWorld_Actor(ref Ray ray, LayerID layerid)
 {
     if (LayerID.Min <= layerid && layerid < LayerID.Max)
     {
         return ICall_IntersectWorld_Actor(ref ray, LayerMark.ConvertToMark(layerid));
     }
     return null;
 }
 /// <summary>
 /// 射线检测指定的Actor
 /// </summary>
 /// <param name="act">要检测的Actor</param>
 /// <param name="ray">射线</param>
 /// <param name="layerid">参与检测的层</param>
 /// <param name="pos">射线打到Actor上的点的坐标</param>
 /// <returns>是否检测到Actor</returns>
 static public bool IntersectActor(Actor act, ref Ray ray, LayerID layerid, out Vector3 pos)
 {
     if (LayerID.Min <= layerid && layerid < LayerID.Max && act != null)
     {
         return(ICall_IntersectWorld_IntersectActor(act, ref ray, LayerMark.LayerIDToUINTMark(layerid), out pos));
     }
     pos = Vector3.Zero;
     return(false);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// ���߼��ָ����Actor
 /// </summary>
 /// <param name="act">Ҫ����Actor</param>
 /// <param name="ray">����</param>
 /// <param name="layerid">������IJ�</param>
 /// <param name="pos">���ߴ�Actor�ϵĵ������</param>
 /// <returns>�Ƿ��⵽Actor</returns>
 public static bool IntersectActor(Actor act, ref Ray ray, LayerID layerid, out Vector3 pos)
 {
     if (LayerID.Min <= layerid && layerid < LayerID.Max)
     {
         return ICall_IntersectWorld_IntersectActor(act, ref ray, LayerMark.ConvertToMark(layerid), out pos);
     }
     pos = Vector3.Zero;
     return false;
 }
 /// <summary>
 /// 获取射线检测到场景里(网格)Actor的第一个点的坐标
 /// </summary>
 /// <param name="ray">指定的射线</param>
 /// <param name="layerid">参与检测的层</param>
 /// <param name="outPoint">返回值(检测到的第一个点的坐标)</param>
 static public void IntersectWorld_Point(ref Ray ray, LayerID layerid, out Vector3 outPoint)
 {
     if (LayerID.Min <= layerid && layerid < LayerID.Max)
     {
         ICall_IntersectWorld_Point(ref ray, LayerMark.LayerIDToUINTMark(layerid), out outPoint);
     }
     else
     {
         outPoint = Vector3.Zero;
     }
 }
Ejemplo n.º 8
0
 public void toggleIndividualLayer(string layerName)
 {
     try
     {
         LayerID id = (LayerID)System.Enum.Parse(typeof(LayerID), layerName);
         toggleLayer((int)id);
     }
     catch (ArgumentException)
     {
         Debug.Log("Invalid layer name!");
     }
 }
Ejemplo n.º 9
0
 public void fadeIndividualLayer(string layerName, float fadeAmount, float time)
 {
     try
     {
         LayerID id = (LayerID)System.Enum.Parse(typeof(LayerID), layerName);
         fade((int)id, fadeAmount, time);
     }
     catch (ArgumentException)
     {
         Debug.Log("Invalid layer name!");
     }
 }
Ejemplo n.º 10
0
 public uint this[LayerID layerID, int x, int y]
 {
     get
     {
         return(this[layerID][y, x]);
     }
     set
     {
         uint[,] layer = this[layerID];
         layer[y, x]   = value;
         this[layerID] = layer;
     }
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Gets or sets a layer of the graphic. Null-value represents an empty or fully transparent layer.
 /// </summary>
 /// <param name="layerID">The LayerID</param>
 /// <returns>The layer</returns>
 public uint[, ] this[LayerID layerID]
 {
     get
     {
         if (!layersCompressed.ContainsKey(layerID))
         {
             uint[,] layer = new uint[Constants.ElementHeight * 8 * (byte)this.ZoomFactor, Constants.ElementWidth * 3 * (byte)this.ZoomFactor];
             for (int x = 0; x < layer.GetLength(Width); x++)
             {
                 for (int y = 0; y < layer.GetLength(Height); y++)
                 {
                     layer[y, x] = Constants.ColorTransparent;
                 }
             }
             return(layer);
         }
         return(DecompressLayer(this.layersCompressed[layerID], this.ZoomFactor));
     }
     set
     {
         if (value == null)
         {
             this.layersCompressed.Remove(layerID);
         }
         else
         {
             CompressedLayer compressedLayer = CompressLayer(value, this.ZoomFactor);
             if (compressedLayer == null)
             {
                 this.layersCompressed.Remove(layerID);
             }
             else
             {
                 this.layersCompressed[layerID] = compressedLayer;
             }
         }
     }
 }
Ejemplo n.º 12
0
 public static uint LayerIDToUINTMark(LayerID layerID)
 {
     return((uint)FlagUtil.BIT_FLAG((int)layerID));
 }
Ejemplo n.º 13
0
 public static LayerMark LayerIDToLayerMark(LayerID layerID)
 {
     return(new LayerMark(LayerIDToUINTMark(layerID)));
 }
Ejemplo n.º 14
0
 public bool IsTransparent(LayerID layerID)
 {
     return(!layersCompressed.ContainsKey(layerID));
 }
Ejemplo n.º 15
0
 public bool ContainLayer(LayerID layerID)
 {
     return((MarkAsUINT & LayerIDToUINTMark(layerID)) != (uint)0);
 }
Ejemplo n.º 16
0
        internal static Graphic Load(BinaryReader br)
        {
            if (br == null)
            {
                throw new ArgumentNullException("br");
            }

            // Load Header
            Graphic graphic = new Graphic();

            while (br.ReadByte() != Constants.HeaderTextTerminator)
            {
            }                                                                                              //Headertext, can be skipped
            byte[] readIdentification = br.ReadBytes(3);                                                   //Read indentification string
            if (readIdentification[0] != 71 || readIdentification[1] != 90 || readIdentification[2] != 71) //identification string "GZG" ASCII-format
            {
                throw new InvalidDataException("wrong identification string");
            }

            byte zoomFactor = (byte)(br.ReadByte() - 48);             //Zoomfactor is read as ASCII-character, then "converted" to a byte

            //ASCII 0 => 48, ASCII 1 => 49, etc...
            switch (zoomFactor)
            {
            case 1:
            case 2:
            case 4:
                graphic.ZoomFactor = (ZoomFactor)zoomFactor;
                break;

            default:
                throw new InvalidDataException("unknown zoom factor");
            }
            ushort readMajorVersion = br.ReadUInt16();

            byte[] readMinorVersion = br.ReadBytes(2);
            if (readMajorVersion != Constants.GraphicFileFormat || readMinorVersion[0] != 0x00)
            {
                throw new InvalidDataException("wrong version");
            }
            switch (readMinorVersion[1])
            {
            case (byte)GraphicVersion.Version0:
            case (byte)GraphicVersion.Version1:
            case (byte)GraphicVersion.Version2:
                graphic.Version = (GraphicVersion)readMinorVersion[1];
                break;

            default:
                throw new InvalidDataException("wrong version");
            }

            int p = br.ReadInt32();             //Properties

            graphic.Properties = new GraphicProperties()
            {
                RawData = (GraphicProperties.Properties)p
            };

            //If either Smoke or Steam is set in the GraphicProperties
            if (graphic.Properties.HasParticles)
            {
                graphic.Properties.ParticleX     = br.ReadInt32();
                graphic.Properties.ParticleY     = br.ReadInt32();
                graphic.Properties.ParticleWidth = br.ReadInt32();
            }

            //If Clock is set in the GraphicProperties
            if (graphic.Properties.RawData.HasFlag(GraphicProperties.Properties.Clock))
            {
                if (graphic.Version == GraphicVersion.Version0)
                {
                    throw new InvalidDataException("Clock is set, but invalid for the version of the graphic");
                }
                br.ReadInt32();                 //skipping unused data (for future use)

                graphic.Properties.ClockProperties = (ClockProperties)br.ReadInt32();
                graphic.Properties.ClockX          = br.ReadInt32();
                graphic.Properties.ClockY          = br.ReadInt32();
                graphic.Properties.ClockZ          = (LayerID)br.ReadInt32();
                graphic.Properties.ClockWidth      = br.ReadInt32();
                graphic.Properties.ClockHeight     = br.ReadInt32();

                graphic.Properties.ClockColorHoursPointer   = br.ReadUInt32();
                graphic.Properties.ClockColorMinutesPointer = br.ReadUInt32();
                br.ReadInt32();                 //skipping unused data (for future use)
            }

            //If Cursor is set in the GraphicProperties
            if (graphic.Properties.RawData.HasFlag(GraphicProperties.Properties.Cursor))
            {
                if (graphic.Version < GraphicVersion.Version2)
                {
                    throw new InvalidDataException("Cursor is set, but invalid for the version of the graphic");
                }
                graphic.Properties.CursorNormalDirection  = (Direction)br.ReadInt32();
                graphic.Properties.CursorReverseDirection = (Direction)br.ReadInt32();
            }

            //If ColorInSchematicMode is set in the GraphicProperties
            if (graphic.Properties.RawData.HasFlag(GraphicProperties.Properties.ColorSchematicMode))
            {
                if (graphic.Version < GraphicVersion.Version2)
                {
                    throw new InvalidDataException("ColorSchematicMode is set, but invalid for the version of the graphic");
                }
                graphic.Properties.ColorInSchematicMode = br.ReadUInt32();
                br.ReadUInt32();                 //skipping unused data
            }

            //If DrivingWay is set in the GraphicProperties
            if (graphic.Properties.RawData.HasFlag(GraphicProperties.Properties.DrivingWay))
            {
                if (graphic.Version < GraphicVersion.Version2)
                {
                    throw new InvalidDataException("DrivingWay is set, but invalid for the version of the graphic");
                }
                graphic.DrivingWay = new List <DrivingWayElement>();
                int count = br.ReadInt32();
                for (int i = 0; i < count; i++)
                {
                    graphic.DrivingWay.Add(DrivingWayElement.FromBytes(br.ReadBytes(12)));
                }
            }

            int layercount = br.ReadInt16();

            br.ReadUInt16();             //skipping unknown data, see more in save-method
            char          c;
            StringBuilder sb = new StringBuilder();

            while ((c = br.ReadChar()) != Constants.UnicodeNull)
            {
                sb.Append(c);
            }
            graphic.InfoText = sb.ToString();

            // Load Data
            bool backgroundLayerExists = false;

            for (int i = 0; i < layercount; i++)
            {
                LayerID         id = (LayerID)br.ReadInt16();
                CompressedLayer compressedLayer = _ReadLayerFromStream(br, graphic.ZoomFactor, graphic.Version);
                if (id == LayerID.Background0)
                {
                    if (!backgroundLayerExists)
                    {
                        backgroundLayerExists = true;
                    }
                    else
                    {
                        id = LayerID.Background1;
                    }
                }
                graphic.layersCompressed.Add(id, compressedLayer);
            }

            return(graphic);
        }
Ejemplo n.º 17
0
 public bool ContainLayer(LayerID layerID)
 {
     return((MarkAsUINT & ConvertToMark(layerID)) != (uint)0);
 }
Ejemplo n.º 18
0
 public static uint ConvertToMark(LayerID layerID)
 {
     return((uint)FlagUtil.BIT_FLAG((int)layerID));
 }
Ejemplo n.º 19
0
 /// <summary>
 /// ��ȡ���߼�⵽������(����)Actor�ĵ�һ���������
 /// </summary>
 /// <param name="ray">ָ��������</param>
 /// <param name="layerid">������IJ�</param>
 /// <param name="outPoint">����ֵ����⵽�ĵ�һ��������꣩</param>
 public static void IntersectWorld_Point(ref Ray ray, LayerID layerid, out Vector3 outPoint)
 {
     if (LayerID.Min <= layerid && layerid < LayerID.Max)
     {
         ICall_IntersectWorld_Point(ref ray, LayerMark.ConvertToMark(layerid), out outPoint);
     }
     else
     {
         outPoint = Vector3.Zero;
     }
 }
Ejemplo n.º 20
0
 public LayerMark(LayerID layerid)
 {
     this.MarkAsUINT = ConvertToMark(layerid);
 }