Exemplo n.º 1
0
        public static void OpenRoom(string File)
        {
            Room = new RooFile(File);
            Room.ResolveResources(ResourceManager);

            MainForm.Room = Room;
        }
Exemplo n.º 2
0
        protected virtual void HandlePlayerMessage(PlayerMessage Message)
        {
            double tick = GameTick.GetUpdatedTick();

            RoomInfo roomInfo = Message.RoomInfo;

            if (roomInfo.RoomFile != String.Empty)
            {
                // try find the roofile instance
                RooFile rooFile = resourceManager.GetRoom(roomInfo.RoomFile);
                roomInfo.ResourceRoom = rooFile;

                // found and never "loaded" before, resolve and uncompress
                // otherwise don't touch it in this thread
                if (rooFile != null && !rooFile.IsResourcesResolved)
                {
                    rooFile.ResolveResources(resourceManager);
                    rooFile.UncompressAll();
                }
            }

            double span = GameTick.GetUpdatedTick() - tick;

            Logger.Log(MODULENAME, LogType.Info, "Loaded BP_PLAYER: " + span.ToString() + " ms");
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="RooFile"></param>
        public override void ResolveIndices(RooFile RooFile)
        {
            // indices properties are not zero-based, but the arrays/lists are

            // get reference to parent wall
            if (WallReference > 0 &&
                RooFile.Walls.Count > WallReference - 1)
            {
                Wall = RooFile.Walls[WallReference - 1];
            }

            // get right tree child
            if (Right > 0 &&
                RooFile.BSPTree.Count > Right - 1)
            {
                RightChild = RooFile.BSPTree[Right - 1];
            }

            // get left tree child
            if (Left > 0 &&
                RooFile.BSPTree.Count > Left - 1)
            {
                LeftChild = RooFile.BSPTree[Left - 1];
            }
        }
Exemplo n.º 4
0
        public void ResolveResources(ResourceManager M59ResourceManager, bool RaiseChangedEvent)
        {
            // try find the roofile instance
            RooFile rooFile = M59ResourceManager.GetRoom(roomFile);

            // if found resolve room resources and uncompress all
            if (rooFile != null && !rooFile.IsResourcesResolved)
            {
                rooFile.ResolveResources(M59ResourceManager);
                rooFile.UncompressAll();
            }

            // try find the wading sound file and load it
            string sound = M59ResourceManager.GetWavFile(wadingSoundFile);

            if (RaiseChangedEvent)
            {
                ResourceRoom        = rooFile;
                ResourceWadingSound = sound;
            }
            else
            {
                resourceRoom        = rooFile;
                resourceWadingSound = sound;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Sets the floor texture to another num
        /// </summary>
        /// <param name="TextureNum"></param>
        /// <param name="TextureFile"></param>
        public void SetFloorTexture(ushort TextureNum, BgfFile TextureFile)
        {
            string oldmaterial = MaterialNameFloor;

            FloorTexture  = TextureNum;
            ResourceFloor = TextureFile;

            if (ResourceFloor != null && ResourceFloor.Frames.Count > 0)
            {
                TextureFloor = ResourceFloor.Frames[0];
                SpeedFloor   = GetSectorScrollSpeed(true, TextureFloor.Width, TextureFloor.Height);

                TextureNameFloor = RooFile.GetNameForTexture(
                    ResourceFloor, 0);

                MaterialNameFloor = RooFile.GetNameForMaterial(
                    ResourceFloor, 0, SpeedFloor);
            }
            else
            {
                TextureFloor      = null;
                TextureNameFloor  = null;
                MaterialNameFloor = null;
                SpeedFloor        = V2.ZERO;
            }

            if (TextureChanged != null)
            {
                TextureChanged(this, new SectorTextureChangedEventArgs(this, true, oldmaterial));
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Sets the ceiling texture to another num
        /// </summary>
        /// <param name="TextureNum"></param>
        /// <param name="TextureFile"></param>
        public void SetCeilingTexture(ushort TextureNum, BgfFile TextureFile)
        {
            string oldmaterial = MaterialNameCeiling;

            CeilingTexture  = TextureNum;
            ResourceCeiling = TextureFile;

            if (ResourceCeiling != null && ResourceCeiling.Frames.Count > 0)
            {
                TextureCeiling = ResourceCeiling.Frames[0];
                SpeedCeiling   = GetSectorScrollSpeed(false, TextureCeiling.Width, TextureCeiling.Height);

                TextureNameCeiling = RooFile.GetNameForTexture(
                    ResourceCeiling, 0);

                MaterialNameCeiling = RooFile.GetNameForMaterial(
                    ResourceCeiling, 0, SpeedCeiling);
            }
            else
            {
                TextureCeiling      = null;
                TextureNameCeiling  = null;
                MaterialNameCeiling = null;
                SpeedCeiling        = V2.ZERO;
            }

            if (TextureChanged != null)
            {
                TextureChanged(this, new SectorTextureChangedEventArgs(this, false, oldmaterial));
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Tries to retrieve a ROO file from the Rooms dictionary.
        /// Will load the file from disk, if not yet loaded.
        /// </summary>
        /// <param name="File"></param>
        /// <returns></returns>
        public RooFile GetRoom(string File)
        {
            RooFile rooFile = null;

            // if the file is known
            if (Rooms.TryGetValue(File, out rooFile))
            {
                // haven't loaded it yet?
                if (rooFile == null)
                {
                    // load it
                    rooFile = new RooFile(RoomsFolder + "/" + File);

                    // resolve resource references (may load texture bgfs)
                    rooFile.ResolveResources(this);

                    // update the registry
                    if (Rooms.TryUpdate(File, rooFile, null))
                    {
                        numLoadedRooms++;
                    }
                }
            }

            return(rooFile);
        }
Exemplo n.º 8
0
        public void UpdateFromModel(RoomInfo Model, bool RaiseChangedEvent)
        {
            if (RaiseChangedEvent)
            {
                AvatarID           = Model.AvatarID;
                AvatarOverlayRID   = Model.AvatarOverlayRID;
                AvatarNameRID      = Model.AvatarNameRID;
                RoomID             = Model.RoomID;
                RoomFileRID        = Model.RoomFileRID;
                RoomNameRID        = Model.RoomNameRID;
                RoomSecurity       = Model.RoomSecurity;
                AmbientLight       = Model.AmbientLight;
                AvatarLight        = Model.AvatarLight;
                BackgroundFileRID  = Model.BackgroundFileRID;
                WadingSoundFileRID = Model.WadingSoundFileRID;
                Flags  = Model.Flags;
                Depth1 = Model.Depth1;
                Depth2 = Model.Depth2;
                Depth3 = Model.Depth3;

                AvatarOverlay   = Model.AvatarOverlay;
                AvatarName      = Model.AvatarName;
                RoomFile        = Model.RoomFile;
                RoomName        = Model.RoomName;
                BackgroundFile  = Model.BackgroundFile;
                WadingSoundFile = Model.WadingSoundFile;

                ResourceRoom        = Model.ResourceRoom;
                ResourceWadingSound = Model.ResourceWadingSound;
            }
            else
            {
                avatarID           = Model.AvatarID;
                avatarOverlayRID   = Model.AvatarOverlayRID;
                avatarNameRID      = Model.AvatarNameRID;
                roomID             = Model.RoomID;
                roomFileRID        = Model.RoomFileRID;
                roomNameRID        = Model.RoomNameRID;
                roomSecurity       = Model.RoomSecurity;
                ambientLight       = Model.AmbientLight;
                avatarLight        = Model.AvatarLight;
                backgroundFileRID  = Model.BackgroundFileRID;
                wadingSoundFileRID = Model.WadingSoundFileRID;
                flags  = Model.Flags;
                depth1 = Model.Depth1;
                depth2 = Model.Depth2;
                depth3 = Model.Depth3;

                avatarOverlay   = Model.AvatarOverlay;
                avatarName      = Model.AvatarName;
                roomFile        = Model.RoomFile;
                roomName        = Model.RoomName;
                backgroundFile  = Model.BackgroundFile;
                wadingSoundFile = Model.WadingSoundFile;

                resourceRoom        = Model.ResourceRoom;
                resourceWadingSound = Model.ResourceWadingSound;
            }
        }
Exemplo n.º 9
0
        public void UpdatePosition(long TickSpan, RooFile RooFile)
        {
            if (!isMoving)
            {
                return;
            }

            // source->destination delta vector and squared distance (in 3D)
            V3   dvector   = targetObject.Position3D - position3D;
            Real distance2 = dvector.LengthSquared;

            // end not yet reached?
            if (distance2 > EPSILON2)
            {
                if (Speed != (byte)MovementSpeed.Teleport)
                {
                    // normalise to get plain direction
                    dvector.Normalize();

                    // process another step based on time delta
                    V3 step = dvector * (Real)speed * (Real)TickSpan * GeometryConstants.PROJECTILEMOVEBASECOEFF;

                    // check if this step is greater than distance left
                    if (step.LengthSquared > distance2)
                    {
                        // directly update for teleport-speed zero
                        position3D.X = TargetObject.Position3D.X;
                        position3D.Y = TargetObject.Position3D.Y;
                        position3D.Z = TargetObject.Position3D.Z;

                        // movement finished
                        IsMoving = false;
                    }
                    else
                    {
                        // do the step
                        position3D.X += step.X;
                        position3D.Y += step.Y;
                        position3D.Z += step.Z;
                    }
                }
                else
                {
                    // directly update for teleport-speed zero
                    position3D.X = TargetObject.Position3D.X;
                    position3D.Y = TargetObject.Position3D.Y;
                    position3D.Z = TargetObject.Position3D.Z;
                }

                // trigger changed event
                RaisePropertyChanged(new PropertyChangedEventArgs(PROPNAME_POSITION3D));
            }
            else
            {
                IsMoving = false;
            }
        }
Exemplo n.º 10
0
 /// <summary>
 /// Resolve all index references to object references
 /// </summary>
 /// <param name="RooFile"></param>
 public override void ResolveIndices(RooFile RooFile)
 {
     // indices properties are not zero-based, but the arrays/lists are
     // get reference to parent Sector
     if (SectorDefReference > 0 &&
         RooFile.Sectors.Count > SectorDefReference - 1)
     {
         Sector = RooFile.Sectors[SectorDefReference - 1];
     }
 }
Exemplo n.º 11
0
        public static void Build(RooFile Room)
        {
            if (Room == null)
            {
                return;
            }

            room = Room;

            if (BuildStarted != null)
            {
                BuildStarted(null, new EventArgs());
            }

            ///////////////////////////////////////////////////////////////

            BoundingBox2D box = Room.GetBoundingBox2D(true);

            Polygon poly = new Polygon();

            poly.Add(box.Min);
            poly.Add(box.Min + new V2(box.Max.X - box.Min.X, 0f));
            poly.Add(box.Max);
            poly.Add(box.Max - new V2(box.Max.X - box.Min.X, 0f));

            ///////////////////////////////////////////////////////////////

            // clean up old data from room
            Room.Walls.Clear();
            Room.BSPTree.Clear();
            foreach (RooSector sector in Room.Sectors)
            {
                sector.Walls.Clear();
                sector.Sides.Clear();
            }

            // convert roomeditor walls to roowall
            for (int i = 0; i < Room.WallsEditor.Count; i++)
            {
                RooWall wall = Room.WallsEditor[i].ToRooWall(RooFile.VERSIONHIGHRESGRID, Room);
                Room.Walls.Add(wall);
            }

            ///////////////////////////////////////////////////////////////

            RooBSPItem tree = BuildNode(Room.Walls, poly, 0);

            ///////////////////////////////////////////////////////////////

            FillNode(tree, Room.BSPTree);
            SetNums(Room.BSPTree);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Sets middle texture to another num
        /// </summary>
        /// <param name="TextureNum"></param>
        /// <param name="TextureFile"></param>
        /// <param name="ResetAnimation"></param>
        public void SetMiddleTexture(ushort TextureNum, BgfFile TextureFile, bool ResetAnimation = true)
        {
            ushort group       = (animation != null) ? animation.CurrentGroup : (ushort)1;
            int    frameidx    = 0;
            string oldmaterial = MaterialNameMiddle;

            MiddleTexture  = TextureNum;
            ResourceMiddle = TextureFile;

            if (ResourceMiddle != null && ResourceMiddle.Frames.Count > 0)
            {
                // possibly reset animation
                if (animation != null && ResetAnimation)
                {
                    animation.SetValues(1, ResourceMiddle.FrameSets.Count, false);
                    group = animation.CurrentGroup;
                }

                frameidx = ResourceMiddle.GetFrameIndex(group, 0);
                frameidx = Math.Max(frameidx, 0);

                if (ResourceMiddle.Frames.Count > frameidx)
                {
                    TextureMiddle = ResourceMiddle.Frames[frameidx];
                    SpeedMiddle   = GetWallScrollSpeed(TextureMiddle.Width, TextureMiddle.Height);
                }
                else
                {
                    TextureMiddle = null;
                    SpeedMiddle   = V2.ZERO;
                }

                TextureNameMiddle = RooFile.GetNameForTexture(
                    ResourceMiddle, frameidx);

                MaterialNameMiddle = RooFile.GetNameForMaterial(
                    ResourceMiddle, frameidx, SpeedMiddle);
            }
            else
            {
                TextureMiddle      = null;
                SpeedMiddle        = V2.ZERO;
                TextureNameMiddle  = null;
                MaterialNameMiddle = null;
            }

            if (TextureChanged != null)
            {
                TextureChanged(this, new WallTextureChangedEventArgs(this, WallPartType.Middle, oldmaterial));
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Creates a RooWall instance based on this RooWallEditor instance.
        /// </summary>
        /// <param name="RooVersion"></param>
        /// <param name="Room"></param>
        /// <returns></returns>
        public RooWall ToRooWall(uint RooVersion, RooFile Room)
        {
            if (Room == null)
            {
                return(null);
            }

            V2 q1, q2;

            // first try get boundingbox as defined by 'Things'
            BoundingBox2D box = Room.GetBoundingBox2DFromThings();

            // no thingsbox? build based on editorwalls
            if (box == BoundingBox2D.NULL)
            {
                box = Room.GetBoundingBox2D(false);
            }

            // 1) Convert from 1:64 to 1:1024
            // 2) Modify coordinate system (y-axis different)
            q1.X = (P0.X - box.Min.X) * 16f;
            q1.Y = (box.Max.Y - P0.Y) * 16f;
            q2.X = (P1.X - box.Min.X) * 16f;
            q2.Y = (box.Max.Y - P1.Y) * 16f;

            // sidenum in editorwall is  0 to n ( 0=unset)
            // sectnum in editorwall is -1 to n (-1=unset)

            RooWall wall = new RooWall(
                RooVersion,
                0,
                (ushort)this.FileSideDef1, // no +1
                (ushort)this.FileSideDef2, // no +1
                q1,
                q2,
                Side1XOffset,
                Side2XOffset,
                Side1YOffset,
                Side2YOffset,
                (ushort)(Side1Sector + 1),  // +1 mapping
                (ushort)(Side2Sector + 1)); // +1 mapping

            // now resolve the object references from indices
            // and fill in heights
            wall.ResolveIndices(Room);
            wall.CalculateWallSideHeights();

            // done
            return(wall);
        }
Exemplo n.º 14
0
        private void btnGO_Click(object sender, EventArgs e)
        {
            // check
            if (!File.Exists(txtRoomFile.Text) ||
                !Directory.Exists(txtBGFFolder.Text) ||
                !Directory.Exists(txtOutputFolder.Text))
            {
                return;
            }

            // init a resourcemanager with room bgfs only
            ResourceManager resMan = new ResourceManager();

            resMan.InitConfig(new ResourceManagerConfig(
                                  0, false, false, false, false,
                                  null, null, null, txtBGFFolder.Text, null, null));

            // load room and resolve resources
            RooFile rooFile = new RooFile(txtRoomFile.Text);

            rooFile.ResolveResources(resMan);

            // make output subfolder
            string subfolder = Path.Combine(txtOutputFolder.Text, rooFile.Filename);

            if (!Directory.Exists(subfolder))
            {
                Directory.CreateDirectory(subfolder);
            }

            // extract textures
            Bitmap bmp;
            string filename;

            foreach (RooFile.TextureInfo texInfo in rooFile.Textures)
            {
                filename = Path.Combine(
                    subfolder,
                    texInfo.Container.Filename + "-" + texInfo.Container.Frames.IndexOf(texInfo.Texture) + ".png");

                bmp = texInfo.Texture.GetBitmap();
                bmp.MakeTransparent(System.Drawing.Color.Cyan);
                bmp.Save(filename, System.Drawing.Imaging.ImageFormat.Png);

                bmp.Dispose();
                bmp = null;
            }
        }
        /// <summary>
        /// Stars loading all rooms in a background thread.
        /// </summary>
        protected void LoadThreadRooms()
        {
            IEnumerator <KeyValuePair <string, RooFile> > it = Rooms.GetEnumerator();
            RooFile file;

            while (it.MoveNext())
            {
                // load
                file = new RooFile(Path.Combine(RoomsFolder, it.Current.Key));

                // update
                Rooms.TryUpdate(it.Current.Key, file, null);

                queueAsyncFilesLoaded.Enqueue(it.Current.Key);
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Preloads all elements in the Rooms dictionary.
        /// </summary>
        public void PreloadRooms()
        {
            IEnumerator <KeyValuePair <string, RooFile> > it = Rooms.GetEnumerator();
            RooFile file;

            while (it.MoveNext())
            {
                // load
                file = new RooFile(Path.Combine(Config.RoomsFolder, it.Current.Key));

                // update
                Rooms.TryUpdate(it.Current.Key, file, null);
            }

            GC.Collect(2);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Tries to retrieve a ROO file from the Rooms dictionary.
        /// Will load the file from disk, if not yet loaded.
        /// </summary>
        /// <param name="File"></param>
        /// <returns></returns>
        public RooFile GetRoom(string File)
        {
            RooFile rooFile = null;

            // if the file is known
            if (Rooms.TryGetValue(File, out rooFile))
            {
                // haven't loaded it yet?
                if (rooFile == null)
                {
                    byte[] buffer;

                    // get file byte buffer
                    if (!fileBuffers.TryPop(out buffer))
                    {
                        buffer = new byte[FILEBUFFERSIZE];
                    }

                    string file = RoomsFolder + "/" + File;

                    // load to mem
                    if (Util.LoadFileToBuffer(file, buffer))
                    {
                        rooFile = new RooFile(file, buffer);

                        // resolve resource references (may load texture bgfs)
                        rooFile.ResolveResources(this);

                        // update the registry
                        if (Rooms.TryUpdate(File, rooFile, null))
                        {
                            numLoadedRooms++;
                        }
                    }
                    else
                    {
                        Logger.Log(MODULENAME, LogType.Error, "Failed to load file (possibly too big?): " + File);
                    }

                    fileBuffers.Push(buffer);
                }
            }

            return(rooFile);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Sets lower texture to another num
        /// </summary>
        /// <param name="TextureNum"></param>
        /// <param name="TextureFile"></param>
        public void SetUpperTexture(ushort TextureNum, BgfFile TextureFile)
        {
            ushort group       = (animation != null) ? animation.CurrentGroup : (ushort)1;
            int    frameidx    = 0;
            string oldmaterial = MaterialNameUpper;

            UpperTexture  = TextureNum;
            ResourceUpper = TextureFile;

            if (ResourceUpper != null && ResourceUpper.Frames.Count > 0)
            {
                frameidx = ResourceUpper.GetFrameIndex(group, 0);
                frameidx = Math.Max(frameidx, 0);

                if (ResourceUpper.Frames.Count > frameidx)
                {
                    TextureUpper = ResourceUpper.Frames[frameidx];
                    SpeedUpper   = GetWallScrollSpeed(TextureUpper.Width, TextureUpper.Height);
                }
                else
                {
                    TextureUpper = null;
                    SpeedUpper   = V2.ZERO;
                }

                TextureNameUpper = RooFile.GetNameForTexture(
                    ResourceUpper, frameidx);

                MaterialNameUpper = RooFile.GetNameForMaterial(
                    ResourceUpper, frameidx, SpeedUpper);
            }
            else
            {
                TextureUpper      = null;
                SpeedUpper        = V2.ZERO;
                TextureNameUpper  = null;
                MaterialNameUpper = null;
            }

            if (TextureChanged != null)
            {
                TextureChanged(this, new WallTextureChangedEventArgs(this, WallPartType.Upper, oldmaterial));
            }
        }
Exemplo n.º 19
0
        public void ResolveResources(ResourceManager M59ResourceManager, bool RaiseChangedEvent)
        {
            if (RoomFile != String.Empty)
            {
                if (RaiseChangedEvent)
                {
                    ResourceRoom = M59ResourceManager.GetRoom(RoomFile);
                }
                else
                {
                    resourceRoom = M59ResourceManager.GetRoom(RoomFile);
                }

                if (resourceRoom != null)
                {
                    resourceRoom.ResolveResources(M59ResourceManager);
                }
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Creates object references from the indices for easier access.
        /// </summary>
        /// <param name="RooFile"></param>
        public void ResolveIndices(RooFile RooFile)
        {
            // indices properties are not zero-based, but the arrays/lists are

            // get reference to right SectorDef
            if (RightSectorReference > 0 &&
                RooFile.Sectors.Count > RightSectorReference - 1)
            {
                RightSector = RooFile.Sectors[RightSectorReference - 1];

                // save as adjacent wall
                if (!RightSector.Walls.Contains(this))
                {
                    RightSector.Walls.Add(this);
                }
            }

            // get reference to left SectorDef
            if (LeftSectorReference > 0 &&
                RooFile.Sectors.Count > LeftSectorReference - 1)
            {
                LeftSector = RooFile.Sectors[LeftSectorReference - 1];

                // save as adjacent wall
                if (!LeftSector.Walls.Contains(this))
                {
                    LeftSector.Walls.Add(this);
                }
            }

            // get reference to right SideDef
            if (RightSideReference > 0 &&
                RooFile.SideDefs.Count > RightSideReference - 1)
            {
                RightSide = RooFile.SideDefs[RightSideReference - 1];

                // save as adjacent side
                if (RightSector != null && !RightSector.Sides.Contains(RightSide))
                {
                    RightSector.Sides.Add(RightSide);
                }

                // save as adjacent side
                if (LeftSector != null && !LeftSector.Sides.Contains(RightSide))
                {
                    LeftSector.Sides.Add(RightSide);
                }
            }

            // get reference to left SideDef
            if (LeftSideReference > 0 &&
                RooFile.SideDefs.Count > LeftSideReference - 1)
            {
                LeftSide = RooFile.SideDefs[LeftSideReference - 1];

                // save as adjacent side
                if (RightSector != null && !RightSector.Sides.Contains(LeftSide))
                {
                    RightSector.Sides.Add(LeftSide);
                }

                // save as adjacent side
                if (LeftSector != null && !LeftSector.Sides.Contains(LeftSide))
                {
                    LeftSector.Sides.Add(LeftSide);
                }
            }
        }
Exemplo n.º 21
0
 /// <summary>
 /// Abstract. Must be implemented.
 /// </summary>
 /// <param name="RooFile"></param>
 public abstract void ResolveIndices(RooFile RooFile);
Exemplo n.º 22
0
        /// <summary>
        /// Call regularly from mainthread, will possibly update mapimage and trigger event
        /// </summary>
        public void Tick(long Tick, long Span)
        {
            // get elapsed ms since last image draw
            long msspan = Tick - tickLastUpdate;

            if (DataController != null &&
                DataController.AvatarObject != null &&
                DataController.RoomInformation != null &&
                DataController.RoomInformation.ResourceRoom != null &&
                msspan >= UPDATEINVERVALMS)
            {
                RooFile RoomFile = DataController.RoomInformation.ResourceRoom;

                // get the deltas based on zoom, zoombase and mapsize
                // the center of the bounding box is the player position
                Real deltax = Zoom * ZOOMBASE * (Real)Width;
                Real deltay = Zoom * ZOOMBASE * (Real)Height;

                // the top left corner of bounding box
                int topx = Convert.ToInt32((Real)DataController.AvatarObject.CoordinateX - deltax);
                int topy = Convert.ToInt32((Real)DataController.AvatarObject.CoordinateY - deltay);

                // bottom right corner of bounding box
                int bottomx = Convert.ToInt32((Real)DataController.AvatarObject.CoordinateX + deltax);
                int bottomy = Convert.ToInt32((Real)DataController.AvatarObject.CoordinateY + deltay);

                // get scale between actual pixelsize of image to show and the bounding box
                Real boxscale = (Real)Width / (Real)(bottomx - topx);

                // prepare drawing
                PrepareDraw();

                // start drawing lines from roo
                foreach (RooWall rld in RoomFile.Walls)
                {
                    // Don't show line if:
                    // 1) both sides not set
                    // 2) left side set to not show up on map, right side unset
                    // 3) right side set to not show up on map, left side unset
                    // 4) both sides set and set to not show up on map
                    if ((rld.LeftSide == null && rld.RightSide == null) ||
                        (rld.LeftSide != null && rld.RightSide == null && rld.LeftSide.Flags.IsMapNever) ||
                        (rld.LeftSide == null && rld.RightSide != null && rld.RightSide.Flags.IsMapNever) ||
                        (rld.LeftSide != null && rld.LeftSide != null && rld.LeftSide.Flags.IsMapNever && rld.RightSide.Flags.IsMapNever))
                    {
                        continue;
                    }

                    // convert to traffic-coords (/16 is RSHIFT 4, +64 offset):
                    int x1 = (rld.X1 >> 4) + 64;
                    int y1 = (rld.Y1 >> 4) + 64;
                    int x2 = (rld.X2 >> 4) + 64;
                    int y2 = (rld.Y2 >> 4) + 64;

                    // expressions whether point is in rectangle
                    bool isX1inScope = (x1 >= topx && x1 <= bottomx);
                    bool isY1inScope = (y1 >= topy && y1 <= bottomy);
                    bool isX2inScope = (x2 >= topx && x2 <= bottomx);
                    bool isY2inScope = (y2 >= topy && y2 <= bottomy);

                    // if at least one of the line points is in the mapscope, draw the line
                    if ((isX1inScope && isY1inScope) || (isX2inScope && isY2inScope))
                    {
                        // transform points to match world of pixeldrawing
                        Real transx1 = (x1 - topx) * boxscale;
                        Real transy1 = (y1 - topy) * boxscale;
                        Real transx2 = (x2 - topx) * boxscale;
                        Real transy2 = (y2 - topy) * boxscale;

                        // draw wall
                        DrawWall(rld, transx1, transy1, transx2, transy2);
                    }
                }

                // draw roomobjects
                foreach (RoomObject obj in DataController.RoomObjects)
                {
                    Real objx      = (obj.CoordinateX - topx) * boxscale;
                    Real objy      = (obj.CoordinateY - topy) * boxscale;
                    int  width     = Convert.ToInt32(50.0f * boxscale);
                    Real widthhalf = (Real)width / 2.0f;
                    int  rectx     = Convert.ToInt32((Real)objx - widthhalf);
                    int  recty     = Convert.ToInt32((Real)objy - widthhalf);

                    DrawObject(obj, rectx, recty, width, width);
                }


                FinishDraw();

                // trigger event
                RaiseImageChanged();

                // save this update tick
                tickLastUpdate = Tick;
            }
        }
Exemplo n.º 23
0
        /// <summary>
        /// Gets references to used textures from a resource manager.
        /// </summary>
        /// <param name="M59ResourceManager"></param>
        /// <param name="RaiseChangedEvent"></param>
        public void ResolveResources(ResourceManager M59ResourceManager, bool RaiseChangedEvent)
        {
            // floor
            if (FloorTexture > 0)
            {
                ResourceFloor = M59ResourceManager.GetRoomTexture(FloorTexture);

                if (ResourceFloor != null && ResourceFloor.Frames.Count > 0)
                {
                    TextureFloor = ResourceFloor.Frames[0];
                    SpeedFloor   = GetSectorScrollSpeed(true, TextureFloor.Width, TextureFloor.Height);

                    TextureNameFloor = RooFile.GetNameForTexture(
                        ResourceFloor, 0);

                    MaterialNameFloor = RooFile.GetNameForMaterial(
                        ResourceFloor, 0, SpeedFloor);
                }
                else
                {
                    TextureFloor      = null;
                    TextureNameFloor  = null;
                    MaterialNameFloor = null;
                    SpeedFloor        = V2.ZERO;
                }
            }
            else
            {
                TextureFloor      = null;
                TextureNameFloor  = null;
                MaterialNameFloor = null;
                SpeedFloor        = V2.ZERO;
            }

            // ceiling
            if (CeilingTexture > 0)
            {
                ResourceCeiling = M59ResourceManager.GetRoomTexture(CeilingTexture);

                if (ResourceCeiling != null && ResourceCeiling.Frames.Count > 0)
                {
                    TextureCeiling = ResourceCeiling.Frames[0];
                    SpeedCeiling   = GetSectorScrollSpeed(false, TextureCeiling.Width, TextureCeiling.Height);

                    TextureNameCeiling = RooFile.GetNameForTexture(
                        ResourceCeiling, 0);

                    MaterialNameCeiling = RooFile.GetNameForMaterial(
                        ResourceCeiling, 0, SpeedCeiling);
                }
                else
                {
                    TextureCeiling      = null;
                    TextureNameCeiling  = null;
                    MaterialNameCeiling = null;
                    SpeedCeiling        = V2.ZERO;
                }
            }
            else
            {
                TextureCeiling      = null;
                TextureNameCeiling  = null;
                MaterialNameCeiling = null;
                SpeedCeiling        = V2.ZERO;
            }
        }
Exemplo n.º 24
0
        public void ResolveResources(ResourceManager M59ResourceManager, bool RaiseChangedEvent)
        {
            ushort group    = (animation != null) ? animation.CurrentGroup : (ushort)1;
            int    frameidx = 0;

            /******************************************************************************/

            if (UpperTexture > 0)
            {
                ResourceUpper = M59ResourceManager.GetRoomTexture(UpperTexture);
            }

            if (MiddleTexture > 0)
            {
                ResourceMiddle = M59ResourceManager.GetRoomTexture(MiddleTexture);
            }

            if (LowerTexture > 0)
            {
                ResourceLower = M59ResourceManager.GetRoomTexture(LowerTexture);
            }

            /******************************************************************************/

            if (animation != null)
            {
                // note: possibly need animation instance for each parttype?

                if (ResourceMiddle != null)
                {
                    animation.GroupMax = ResourceMiddle.FrameSets.Count;
                }

                /*else if (ResourceLower != null)
                 *  animation.GroupMax = ResourceLower.FrameSets.Count;
                 *
                 * else if (ResourceUpper != null)
                 *  animation.GroupMax = ResourceUpper.FrameSets.Count;*/
            }

            /******************************************************************************/

            if (ResourceUpper != null && ResourceUpper.Frames.Count > 0)
            {
                frameidx = ResourceUpper.GetFrameIndex(group, 0);
                frameidx = Math.Max(frameidx, 0);

                if (ResourceUpper.Frames.Count > frameidx)
                {
                    TextureUpper = ResourceUpper.Frames[frameidx];
                    SpeedUpper   = GetWallScrollSpeed(TextureUpper.Width, TextureUpper.Height);
                }
                else
                {
                    TextureUpper = null;
                    SpeedUpper   = V2.ZERO;
                }

                TextureNameUpper = RooFile.GetNameForTexture(
                    ResourceUpper, frameidx);

                MaterialNameUpper = RooFile.GetNameForMaterial(
                    ResourceUpper, frameidx, SpeedUpper);
            }
            else
            {
                TextureUpper      = null;
                SpeedUpper        = V2.ZERO;
                TextureNameUpper  = null;
                MaterialNameUpper = null;
            }

            /******************************************************************************/

            if (ResourceMiddle != null && ResourceMiddle.Frames.Count > 0)
            {
                frameidx = ResourceMiddle.GetFrameIndex(group, 0);
                frameidx = Math.Max(frameidx, 0);

                if (ResourceMiddle.Frames.Count > frameidx)
                {
                    TextureMiddle = ResourceMiddle.Frames[frameidx];
                    SpeedMiddle   = GetWallScrollSpeed(TextureMiddle.Width, TextureMiddle.Height);
                }
                else
                {
                    TextureMiddle = null;
                    SpeedMiddle   = V2.ZERO;
                }

                TextureNameMiddle = RooFile.GetNameForTexture(
                    ResourceMiddle, frameidx);

                MaterialNameMiddle = RooFile.GetNameForMaterial(
                    ResourceMiddle, frameidx, SpeedMiddle);
            }
            else
            {
                TextureMiddle      = null;
                SpeedMiddle        = V2.ZERO;
                TextureNameMiddle  = null;
                MaterialNameMiddle = null;
            }

            /******************************************************************************/

            if (ResourceLower != null && ResourceLower.Frames.Count > 0)
            {
                frameidx = ResourceLower.GetFrameIndex(group, 0);
                frameidx = Math.Max(frameidx, 0);

                if (ResourceLower.Frames.Count > frameidx)
                {
                    TextureLower = ResourceLower.Frames[frameidx];
                    SpeedLower   = GetWallScrollSpeed(TextureLower.Width, TextureLower.Height);
                }
                else
                {
                    TextureLower = null;
                    SpeedLower   = V2.ZERO;
                }

                TextureNameLower = RooFile.GetNameForTexture(
                    ResourceLower, frameidx);

                MaterialNameLower = RooFile.GetNameForMaterial(
                    ResourceLower, frameidx, SpeedLower);
            }
            else
            {
                TextureLower      = null;
                SpeedLower        = V2.ZERO;
                TextureNameLower  = null;
                MaterialNameLower = null;
            }
        }
Exemplo n.º 25
0
        public void WriteGridHighRes(RooFile file, string Filename)
        {
            System.Drawing.Bitmap bmp =
                new System.Drawing.Bitmap(file.Grids.ColumnsHighRes * 3, file.Grids.RowsHighRes * 3);

            int x = 1;
            int y = 1;

            for (int i = 0; i < file.Grids.RowsHighRes; i++)
            {
                x = 1;

                for (int j = 0; j < file.Grids.ColumnsHighRes; j++)
                {
                    if (file.Grids.IsWalkableHighRes(i, j))
                    {
                        bmp.SetPixel(x, y, System.Drawing.Color.White);
                    }
                    else
                    {
                        bmp.SetPixel(x, y, System.Drawing.Color.Black);
                    }

                    if (file.Grids.IsWalkNorthHighRes(i, j))
                    {
                        bmp.SetPixel(x, y - 1, System.Drawing.Color.Green);
                    }
                    else
                    {
                        bmp.SetPixel(x, y - 1, System.Drawing.Color.Red);
                    }

                    if (file.Grids.IsWalkNorthEastHighRes(i, j))
                    {
                        bmp.SetPixel(x + 1, y - 1, System.Drawing.Color.Green);
                    }
                    else
                    {
                        bmp.SetPixel(x + 1, y - 1, System.Drawing.Color.Red);
                    }

                    if (file.Grids.IsWalkEastHighRes(i, j))
                    {
                        bmp.SetPixel(x + 1, y, System.Drawing.Color.Green);
                    }
                    else
                    {
                        bmp.SetPixel(x + 1, y, System.Drawing.Color.Red);
                    }

                    if (file.Grids.IsWalkSouthEastHighRes(i, j))
                    {
                        bmp.SetPixel(x + 1, y + 1, System.Drawing.Color.Green);
                    }
                    else
                    {
                        bmp.SetPixel(x + 1, y + 1, System.Drawing.Color.Red);
                    }

                    if (file.Grids.IsWalkSouthHighRes(i, j))
                    {
                        bmp.SetPixel(x, y + 1, System.Drawing.Color.Green);
                    }
                    else
                    {
                        bmp.SetPixel(x, y + 1, System.Drawing.Color.Red);
                    }

                    if (file.Grids.IsWalkSouthWestHighRes(i, j))
                    {
                        bmp.SetPixel(x - 1, y + 1, System.Drawing.Color.Green);
                    }
                    else
                    {
                        bmp.SetPixel(x - 1, y + 1, System.Drawing.Color.Red);
                    }

                    if (file.Grids.IsWalkWestHighRes(i, j))
                    {
                        bmp.SetPixel(x - 1, y, System.Drawing.Color.Green);
                    }
                    else
                    {
                        bmp.SetPixel(x - 1, y, System.Drawing.Color.Red);
                    }

                    if (file.Grids.IsWalkNorthWestHighRes(i, j))
                    {
                        bmp.SetPixel(x - 1, y - 1, System.Drawing.Color.Green);
                    }
                    else
                    {
                        bmp.SetPixel(x - 1, y - 1, System.Drawing.Color.Red);
                    }


                    x += 3;
                }

                y += 3;
            }

            bmp.Save(Filename);
            bmp.Dispose();
        }