Example #1
0
        public static void OpenRoom(string File)
        {
            Room = new RooFile(File);
            Room.ResolveResources(ResourceManager);

            MainForm.Room = Room;          
        }
Example #2
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);
        }
        /// <summary>
        /// Creates object references from the Sector/Side Num references.
        /// </summary>
        /// <param name="RooFile"></param>
        public void ResolveIndices(RooFile RooFile)
        {
            // num properties are not zero-based, but the arrays are

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

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

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

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

            // get reference to right SideDef
            if (RightSideNum > 0 &&
                RooFile.SideDefs.Count > RightSideNum - 1)
            {
                RightSide = RooFile.SideDefs[RightSideNum - 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 (LeftSideNum > 0 &&
                RooFile.SideDefs.Count > LeftSideNum - 1)
            {
                LeftSide = RooFile.SideDefs[LeftSideNum - 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);
            }

            // get reference to next wall in same plane
            if (NextWallNumInPlane > 0 &&
                RooFile.Walls.Count > NextWallNumInPlane - 1)
            {
                NextWallInPlane = RooFile.Walls[NextWallNumInPlane - 1];
            }
        }
Example #4
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;
            }
        }
        public void UpdatePosition(double 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;
        }
Example #6
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();
        }
        /// <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);
            }
        }
Example #8
0
        /// <summary>
        /// Returns all visible RoomObjects within given distance
        /// from this instance.
        /// </summary>
        /// <param name="RoomObjects">Objects to check</param>
        /// <param name="Room">Room used for collision</param>
        /// <param name="BackRadius">Max. distance behind</param>
        /// <param name="FrontRadius">Max. distance in front</param>
        /// <param name="AddAvatar">If also to add avatar roomobject</param>
        /// <returns></returns>
        public List<RoomObject> GetObjectsWithinDistance(IEnumerable<RoomObject> RoomObjects, RooFile Room, Real BackRadius, Real FrontRadius, bool AddAvatar)
        {
            List<RoomObject> list = new List<RoomObject>();

            if (RoomObjects != null && Room != null)
            {
                Real backradius2 = BackRadius * BackRadius;
                Real frontradius2 = FrontRadius * FrontRadius;
                ushort angle;
                Real dist2;

                foreach (RoomObject obj in RoomObjects)
                {
                    // don't add ourself and don't add avatar if not said so
                    if (obj != this && (AddAvatar || !obj.IsAvatar))
                    {
                        // get squared distance to object
                        dist2 = GetDistanceSquared(obj);

                        // skip everything that is farer way than front radius
                        if (dist2 <= frontradius2)
                        {
                            // get smaller angle between our orientation and the direction
                            // to the other object
                            angle = GetAngleBetween(obj);

                            // either in front of us and within frontradius
                            // or behind of us and and within backradius
                            bool infront = (angle < GeometryConstants.QUARTERMAXANGLE && dist2 <= frontradius2);
                            bool behind = (angle >= GeometryConstants.QUARTERMAXANGLE && dist2 <= backradius2);

                            // add it if also visible
                            if ((infront || behind) && obj.IsVisibleFrom(Position3D, Room))
                                list.Add(obj);
                        }
                    }
                }
            }

            return list;
        }
        /// <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
                    Rooms.TryUpdate(File, rooFile, null);
                }
            }

            return rooFile;
        }
Example #10
0
        /// <summary>
        /// Checks if this object is visible from a position
        /// in a room.
        /// </summary>
        /// <param name="Position"></param>
        /// <param name="Room"></param>
        /// <returns></returns>
        public bool IsVisibleFrom(V3 Position, RooFile Room)
        {
            if (Room != null)
            {
                // roo format variants
                V3 rooStart = Position.Clone();
                V3 rooEnd = Position3D.Clone();

                // add offset for playerheight to not use the groundheight
                rooStart.Y += GeometryConstants.PLAYERHEIGHT;
                rooEnd.Y += GeometryConstants.PLAYERHEIGHT;

                // convert to ROO format
                rooStart.ConvertToROO();
                rooEnd.ConvertToROO();

                // verify the object is visible
                return Room.VerifySight(rooStart, rooEnd);
            }
            else
                return false;
        }
Example #11
0
 /// <summary>
 /// Abstract. Must be implemented.
 /// </summary>
 /// <param name="RooFile"></param>
 public abstract void ResolveIndices(RooFile RooFile);
Example #12
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;
        }
Example #13
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 (SectorNum > 0 &&
         RooFile.Sectors.Count > SectorNum - 1)
     {
         Sector = RooFile.Sectors[SectorNum - 1];
     }
 }
        /// <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];
            }
        }