示例#1
0
        public override int ReadFrom(byte[] Buffer, int StartIndex = 0)
        {
            int cursor = StartIndex;

            cursor += base.ReadFrom(Buffer, cursor);

            NewRoomObject = new RoomObject(Buffer, cursor);
            cursor += NewRoomObject.ByteLength;

            return cursor - StartIndex;
        }
        public override int ReadFrom(byte[] Buffer, int StartIndex = 0)
        {
            int cursor = StartIndex;

            cursor += base.ReadFrom(Buffer, cursor);

            RoomObjectID = new ObjectID(Buffer, cursor);
            cursor += RoomObjectID.ByteLength;

            ushort len = BitConverter.ToUInt16(Buffer, cursor);
            cursor += TypeSizes.SHORT;

            RoomObjects = new RoomObject[len];
            for (int i = 0; i < len; i++)
            {
                RoomObjects[i] = new RoomObject(Buffer, cursor);
                cursor += RoomObjects[i].ByteLength;
            }

            return cursor - StartIndex;
        }
        static void Main()
        {
            // .net stuff
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // initialize color palettes
            PalettesGDI.Initialize();

            // init bgf data model
            CurrentFile = new BgfFile();
            CurrentFile.Frames.AllowEdit = true;

            // init roomobject model for viewer
            RoomObject = new RoomObject();
            RoomObject.Resource = CurrentFile;

            // init imagecomposer for this roomobject
            ImageComposer = new ImageComposerGDI<RoomObject>();
            ImageComposer.UseViewerFrame = true;
            ImageComposer.DataSource = RoomObject;

            // init mainform
            MainForm = new MainForm();
            MainForm.FormClosed += OnMainFormFormClosed;
            MainForm.Show();

            // init shrinkform
            SettingsForm = new SettingsForm();
            SettingsForm.DataBindings.Add("Version", CurrentFile, "Version");
            SettingsForm.DataBindings.Add("ShrinkFactor", CurrentFile, "ShrinkFactor");
            SettingsForm.DataBindings.Add("Name", CurrentFile, "Name");

            // init addframsetindexform
            AddFrameSetIndexForm = new AddFrameSetIndexForm();

            // init ticker
            stopWatch = new Stopwatch();
            stopWatch.Start();

            // set running
            IsRunning = true;

            // start mainthread loop
            while (IsRunning)
            {
                long oldTick = Tick;

                // update current tick
                Tick = stopWatch.ElapsedTicks / MSTICKDIVISOR;

                long span = Tick - oldTick;

                // update roomobject
                if (IsPlaying)
                    RoomObject.Tick(Tick, span);

                // process window messages / events
                Application.DoEvents();

                // sleep
                Thread.Sleep(1);
            }
        }
        /// <summary>
        /// Updates the ViewerParent, ViewerHotspot and
        /// FrontParent and FrontHotspot properties.
        /// </summary>
        /// <param name="Root"></param>
        /// <param name="SubOverlays"></param>
        public void UpdateHotspots(RoomObject Root, IList<SubOverlay> SubOverlays)
        {
            // do viewer parts
            UpdateHotspots((ObjectBase)Root, SubOverlays);

            // try find hotspot on active mainoverlay frame
            if (Root.FrontFrame != null)
                FrontHotspot = Root.FrontFrame.FindHotspot(hotSpot);

            // if not found
            if (FrontHotspot == null)
            {
                // try find on suboverlays
                foreach (SubOverlay subOv in SubOverlays)
                {
                    if (subOv.FrontFrame != null)
                    {
                        FrontHotspot = subOv.FrontFrame.FindHotspot(hotSpot);
                        if (FrontHotspot != null)
                        {
                            FrontParent = subOv;
                            break;
                        }
                    }
                }
            }
        }
示例#5
0
 /// <summary>
 /// Static
 /// </summary>
 /// <param name="ObjectA"></param>
 /// <param name="ObjectB"></param>
 /// <returns></returns>
 public static Real GetDistance(RoomObject ObjectA, RoomObject ObjectB)
 {
     return (Real)Math.Sqrt(GetDistanceSquared(ObjectA, ObjectB));
 }
示例#6
0
        /// <summary>
        /// Static
        /// </summary>
        /// <param name="ObjectA"></param>
        /// <param name="ObjectB"></param>
        /// <returns></returns>
        public static Real GetDistanceSquared(RoomObject ObjectA, RoomObject ObjectB)
        {
			V3 AB = ObjectB.Position3D - ObjectA.Position3D;

            return AB.LengthSquared;
        }
示例#7
0
 /// <summary>
 /// Gets the squared distance between this and another RoomObject
 /// </summary>
 /// <param name="RoomObject"></param>
 /// <returns></returns>
 public Real GetDistanceSquared(RoomObject RoomObject)
 {
     return GetDistanceSquared(this, RoomObject);
 }
        /// <summary>
        /// Tries to resolve the source and target RoomObject
        /// references from RoomObjects parameter, also sets the start position.
        /// </summary>
        /// <param name="RoomObjects"></param>
        /// <param name="RaiseChangedEvent"></param>
        public void ResolveSourceTarget(IList<RoomObject> RoomObjects, bool RaiseChangedEvent)
        {
            if (RaiseChangedEvent)
            {
                foreach (RoomObject roomObject in RoomObjects)
                {
                    if (roomObject.ID == source.ID)
                    {
                        SourceObject = roomObject;
                        Position3D = SourceObject.Position3D.Clone();
                    }

                    else if (roomObject.ID == target.ID)
                        TargetObject = roomObject;
                }
            }
            else
            {
                foreach (RoomObject roomObject in RoomObjects)
                {
                    if (roomObject.ID == source.ID)
                    {
                        sourceObject = roomObject;
                        position3D = sourceObject.Position3D.Clone();
                    }
                    else if (roomObject.ID == target.ID)
                        targetObject = roomObject;
                }
            }
        }
        protected void TryAdd(RoomObject Item)
        {
            // never add invis flagged ones (DI removes flag)
            if (Item.Flags.Drawing == ObjectFlags.DrawingType.Invisible)
                return;

            // add it if there is no filter active
            if (FlagsFilter.Count == 0 && PlayerTypesFilter.Count == 0)
            {
                // sorted add
                Insert(0, Item);

                return;
            }

            // flags filter match
            if (FlagsFilter.Count > 0)
            {
                foreach (ObjectFlags flags in FlagsFilter)
                {
                    if (Item.Flags.IsSubset(flags))
                    {
                        // sorted add
                        Insert(0, Item);

                        return;
                    }
                }
            }

            // player type filter match
            if (PlayerTypesFilter.Count > 0)
            {
                foreach (ObjectFlags.PlayerType ptype in PlayerTypesFilter)
                {
                    if (Item.Flags.Player == ptype)
                    {
                        // sorted add
                        Insert(0, Item);

                        return;
                    }
                }
            }
        }
示例#10
0
 /// <summary>
 /// Gets the distance between this and another RoomObject
 /// </summary>
 /// <param name="RoomObject"></param>
 /// <returns></returns>
 public Real GetDistance(RoomObject RoomObject)
 {
     return GetDistance(this, RoomObject);
 }
        protected void Evaluate(RoomObject Item)
        {
            // if we don't have it yet, try add it
            if (!Contains(Item))
                TryAdd(Item);

            // if we have it, see if it still matches a filter
            else
            {
                // never show invis objects
                if (Item.Flags.Drawing == ObjectFlags.DrawingType.Invisible)
                    Remove(Item);

                // otherwise verify against filters
                else
                {
                    // no need to remove it if we don't have a filter
                    if (FlagsFilter.Count == 0 && PlayerTypesFilter.Count == 0)
                        return;

                    // still matches a flag filter
                    if (FlagsFilter.Count > 0)
                        foreach (ObjectFlags flags in FlagsFilter)
                            if (Item.Flags.IsSubset(flags))
                                return;

                    // still matches a player type filter
                    if (PlayerTypesFilter.Count > 0)
                        foreach (ObjectFlags.PlayerType ptype in PlayerTypesFilter)
                            if (Item.Flags.Player == ptype)
                                return;

                    // no current filter matches anymore, remove it
                    Remove(Item);
                }
            }
        }
        /// <summary>
        /// Static
        /// </summary>
        /// <param name="ObjectA"></param>
        /// <param name="ObjectB"></param>
        /// <returns></returns>
        public static Real GetDistanceSquared(RoomObject ObjectA, RoomObject ObjectB)
        {
            int deltax = ObjectA.CoordinateX - ObjectB.CoordinateX;
            int deltay = ObjectA.CoordinateY - ObjectB.CoordinateY;

            return deltax * deltax + deltay * deltay;
        }
        public override unsafe void ReadFrom(ref byte* Buffer)
        {
            base.ReadFrom(ref Buffer);

            RoomObjectID = new ObjectID(ref Buffer);
            
            ushort len = *((ushort*)Buffer);
            Buffer += TypeSizes.SHORT;

            RoomObjects = new RoomObject[len];
            for (int i = 0; i < len; i++)
                RoomObjects[i] = new RoomObject(ref Buffer);                          
        }
示例#14
0
 public override unsafe void ReadFrom(ref byte* Buffer)
 {
     base.ReadFrom(ref Buffer);
     NewRoomObject = new RoomObject(ref Buffer);
 }
示例#15
0
 /// <summary>
 /// Gets the angle that needs to bet set 
 /// to make this RoomObject
 /// look at another RoomObject
 /// </summary>
 /// <param name="LookAt"></param>
 /// <returns></returns>
 public ushort GetAngleTo(RoomObject LookAt)
 {
     V2 dir = LookAt.Position2D - this.Position2D;
     return MathUtil.GetAngleForDirection(dir);
 }
示例#16
0
 public CreateMessage(RoomObject NewRoomObject) 
     : base(MessageTypeGameMode.Create)
 {         
     this.NewRoomObject = NewRoomObject;                      
 }
示例#17
0
 /// <summary>
 /// Returns the smaller angle between this RoomObject
 /// and its angle and another RoomObject.
 /// </summary>
 /// <param name="RoomObject"></param>
 /// <returns></returns>
 public ushort GetAngleBetween(RoomObject RoomObject)
 {
     return MathUtil.GetAngle(RoomObject.Position2D, Position2D, AngleUnits, true);
 }
示例#18
0
        public RenderInfo(
            RoomObject Data,
            bool UseViewerFrame = true,
            bool ApplyYOffset = true,
            byte RootHotspotIndex = 0,
            Real Quality = DEFAULTQUALITY,
            bool ScalePow2 = false,
            uint Width = 0,
            uint Height = 0,
            bool CenterVertical = false,
            bool CenterHorizontal = false)
        {
            Clear();

            BgfBitmap mainFrame = Data.ViewerFrame;
            if (!UseViewerFrame)
                mainFrame = Data.FrontFrame;

            Calculate(Data, mainFrame, UseViewerFrame, ApplyYOffset, RootHotspotIndex, Quality, ScalePow2, Width, Height, CenterVertical, CenterHorizontal);
        }
 public RoomContentsMessage(ObjectID RoomObjectID, RoomObject[] RoomObjects) 
     : base(MessageTypeGameMode.RoomContents)
 {           
     this.RoomObjectID = RoomObjectID;
     this.RoomObjects = RoomObjects;
 }