예제 #1
0
        public ScreenCaptor9(IHostStatistics statistics, IDevice device)
        {
            this.statistics = statistics;
            var resultFormatId = device.Adapter.GetSupportedFormats(FormatSupport.Texture2D).First(x => x.ExplicitFormat == ExplicitFormat.B8G8R8A8_UNORM).ID;
            texturePool = new TexturePool(device, resultFormatId, Usage.Dynamic, BindFlags.ShaderResource, MiscFlags.None);

            direct3D = new Direct3D();
            form = new Form();
            d3dDevice = new Device(direct3D, 0, DeviceType.Hardware, form.Handle, CreateFlags.SoftwareVertexProcessing, new PresentParameters
            {
                SwapEffect = SwapEffect.Discard,
                Windowed = true
            });

            d3dSurface1 = Surface.CreateOffscreenPlain(d3dDevice, 4096, 1440, Format.A8R8G8B8, Pool.Scratch);

            stopwatch = new Stopwatch();
        }
예제 #2
0
 protected override void UnloadContent()
 {
     TexturePool.UnloadContent();
 }
예제 #3
0
 public TextureUndoHistory(int capacity, int width, int height)
 {
     Capacity = capacity;
     _pool    = new TexturePool(capacity, width, height);
 }
예제 #4
0
        public void TestSerializeWorld()
        {
            var game = new XNAGame();

            var texturePool           = new TexturePool();
            var meshpartPool          = new MeshPartPool();
            var vertexDeclarationPool = new VertexDeclarationPool();

            vertexDeclarationPool.SetVertexElements <TangentVertex>(TangentVertex.VertexElements);
            var renderer = new SimpleMeshRenderer(texturePool, meshpartPool, vertexDeclarationPool);

            TileData     data = new TileData(Guid.NewGuid());
            TileFaceType type = new TileFaceType(Guid.NewGuid());

            type.FlipWinding = true;
            TileFaceType root = new TileFaceType(Guid.NewGuid());

            type.SetParent(root);

            data.Dimensions = new Vector3(1, 2, 3);
            data.SetFaceType(TileFace.Front, type);

            OBJParser.ObjImporter importer = new OBJParser.ObjImporter();
            var c = new OBJToRAMMeshConverter(new RAMTextureFactory());

            importer.AddMaterialFileStream("WallInnerCorner.mtl", new FileStream(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallInnerCorner.mtl", FileMode.Open));
            importer.ImportObjFile(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallInnerCorner.obj");
            meshWallInnerCorner = c.CreateMesh(importer);

            data.Mesh = meshWallInnerCorner;

            var builder = new TileSnapInformationBuilder();

            var world   = new World();
            var objType = new WorldObjectType(data.Mesh, Guid.NewGuid(), builder);

            objType.TileData = data;

            var obj = world.CreateNewWorldObject(game, objType, renderer);

            obj.Position = Vector3.One * 3;



            var simpleMeshFactory = new SimpleMeshFactory();

            simpleMeshFactory.AddMesh(meshWallInnerCorner);

            DiskTileDataFactory diskTileDataFactory = new DiskTileDataFactory(simpleMeshFactory,
                                                                              new SimpleTileFaceTypeFactory());

            diskTileDataFactory.AddTileData(data);


            var typeFactory = new SimpleWorldObjectTypeFactory();



            var serializer = new WorldSerializer(simpleMeshFactory, diskTileDataFactory, game, renderer, typeFactory, builder);


            FileStream stream = File.OpenWrite(TWDir.Test.CreateSubdirectory("TileEngine").FullName + "\\TestWorld.xml");

            serializer.SerializeWorld(world, stream);

            stream.Close();

            FileStream readStream =
                File.OpenRead(TWDir.Test.CreateSubdirectory("TileEngine").FullName + "\\TestWorld.xml");

            var readWorld = new World();

            serializer.DeserializeWorld(readWorld, readStream);

            readStream.Close();
        }
예제 #5
0
        public void TestLearnPlace()
        {
            XNAGame game = new XNAGame();

            var texturePool           = new TexturePool();
            var meshpartPool          = new MeshPartPool();
            var vertexDeclarationPool = new VertexDeclarationPool();

            vertexDeclarationPool.SetVertexElements <TangentVertex>(TangentVertex.VertexElements);
            var renderer = new SimpleMeshRenderer(texturePool, meshpartPool, vertexDeclarationPool);

            game.IsFixedTimeStep = false;
            game.DrawFps         = true;
            game.AddXNAObject(texturePool);
            game.AddXNAObject(meshpartPool);
            game.AddXNAObject(vertexDeclarationPool);
            game.AddXNAObject(renderer);

            EditorGrid grid;

            grid               = new EditorGrid();
            grid.Size          = new Vector2(100, 100);
            grid.Interval      = 1;
            grid.MajorInterval = 10;

            World world   = new World();
            var   builder = new TileSnapInformationBuilder();

            //var TileInnerCorner = factory.CreateNewWorldObject(game, wallInnerCornerType, renderer);
            //TileInnerCorner.Position = new Vector3(-7, 0, 0);
            //var TileStraight = factory.CreateNewWorldObject(game, wallStraightType, renderer);
            //TileStraight.Position = new Vector3(7, 0, 0);

            var placeTool     = new WorldObjectPlaceTool(game, world, renderer, builder, new SimpleMeshFactory(), new SimpleTileFaceTypeFactory());
            var moveTool      = new WorldObjectMoveTool(game, world, builder, renderer);
            var snapLearnTool = new SnapLearnTool(world, renderer, builder);

            game.AddXNAObject(placeTool);
            game.AddXNAObject(moveTool);
            game.AddXNAObject(snapLearnTool);


            setupWorldObjectTypes(game, renderer, builder);



            bool mouseEnabled = false;

            game.UpdateEvent += delegate
            {
                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.M))
                {
                    placeTool.Enabled     = false;
                    moveTool.Enabled      = true;
                    snapLearnTool.Enabled = false;
                }
                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.L))
                {
                    placeTool.Enabled     = false;
                    moveTool.Enabled      = false;
                    snapLearnTool.Enabled = true;
                }


                if (placeTool.Enabled)
                {
                    moveTool.Enabled      = false;
                    snapLearnTool.Enabled = false;

                    if (placeTool.ObjectsPlacedSinceEnabled() == 1)
                    {
                        placeTool.Enabled = false;
                    }
                }


                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.NumPad1))
                {
                    placeTool.PlaceType = typeList[0];
                    placeTool.Enabled   = true;
                }
                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.NumPad2))
                {
                    placeTool.PlaceType = typeList[1];
                    placeTool.Enabled   = true;
                }

                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.LeftAlt))
                {
                    mouseEnabled = !mouseEnabled;
                }
                if (mouseEnabled)
                {
                    game.Mouse.CursorEnabled     = true;
                    game.IsMouseVisible          = true;
                    game.SpectaterCamera.Enabled = false;
                }
                else
                {
                    game.Mouse.CursorEnabled     = false;
                    game.IsMouseVisible          = false;
                    game.SpectaterCamera.Enabled = true;
                    //activeWorldObject = null;
                }
            };

            game.DrawEvent += delegate
            {
                grid.Render(game);
            };

            game.Run();
        }
예제 #6
0
        public void TestLearnSnap()
        {
            XNAGame game = new XNAGame();

            OBJParser.ObjImporter importer = new OBJParser.ObjImporter();
            var c = new OBJToRAMMeshConverter(new RAMTextureFactory());

            importer.AddMaterialFileStream("WallInnerCorner.mtl", new FileStream(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallInnerCorner.mtl", FileMode.Open));
            importer.ImportObjFile(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallInnerCorner.obj");
            var meshWallInnerCorner = c.CreateMesh(importer);

            importer.AddMaterialFileStream("WallStraight.mtl", new FileStream(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallStraight.mtl", FileMode.Open));
            importer.ImportObjFile(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallStraight.obj");
            var meshWallStraight = c.CreateMesh(importer);

            var texturePool           = new TexturePool();
            var meshpartPool          = new MeshPartPool();
            var vertexDeclarationPool = new VertexDeclarationPool();

            var renderer = new SimpleMeshRenderer(texturePool, meshpartPool, vertexDeclarationPool);

            vertexDeclarationPool.SetVertexElements <TangentVertex>(TangentVertex.VertexElements);

            World world = new World();
            TileSnapInformationBuilder builder = new TileSnapInformationBuilder();

            WorldObjectType type1 = new WorldObjectType(meshWallInnerCorner, Guid.NewGuid(), builder);
            WorldObjectType type2 = new WorldObjectType(meshWallStraight, Guid.NewGuid(), builder);

            var tileDataInnerCorner = new TileData(Guid.NewGuid());
            var tileDataStraight    = new TileData(Guid.NewGuid());

            tileDataInnerCorner.Dimensions = type1.BoundingBox.Max - type1.BoundingBox.Min;
            tileDataStraight.Dimensions    = type2.BoundingBox.Max - type2.BoundingBox.Min;


            type1.TileData = tileDataInnerCorner;
            type2.TileData = tileDataStraight;


            var TileInnerCorner = world.CreateNewWorldObject(game, type1, renderer);

            TileInnerCorner.Position = new Vector3(-7, 0, 0);
            var TileStraight = world.CreateNewWorldObject(game, type2, renderer);

            TileStraight.Position = new Vector3(7, 0, 0);

            game.IsFixedTimeStep = false;
            game.DrawFps         = true;
            game.AddXNAObject(texturePool);
            game.AddXNAObject(meshpartPool);
            game.AddXNAObject(vertexDeclarationPool);
            game.AddXNAObject(renderer);

            EditorGrid grid;

            grid               = new EditorGrid();
            grid.Size          = new Vector2(100, 100);
            grid.Interval      = 1;
            grid.MajorInterval = 10;

            var snapLearnTool = new SnapLearnTool(world, renderer, builder);

            game.AddXNAObject(snapLearnTool);

            bool mouseEnabled = false;

            var WallCornerBB = type1.TileData.GetBoundingBox();

            game.UpdateEvent += delegate
            {
                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.LeftAlt))
                {
                    mouseEnabled = !mouseEnabled;
                }
                if (mouseEnabled)
                {
                    game.Mouse.CursorEnabled     = true;
                    game.IsMouseVisible          = true;
                    game.SpectaterCamera.Enabled = false;
                }
                else
                {
                    game.Mouse.CursorEnabled     = false;
                    game.IsMouseVisible          = false;
                    game.SpectaterCamera.Enabled = true;
                    //activeWorldObject = null;
                }
            };
            game.DrawEvent += delegate
            {
                grid.Render(game);
                game.LineManager3D.WorldMatrix = TileInnerCorner.WorldMatrix;
                //game.LineManager3D.AddBox(WallCornerBB, Color.White);
            };

            game.Run();
        }
            private void InitializeTexturePools(int width, int height)
            {
                fullResPPBuffer         = Collect(new PingPongColorBuffers(Format, width, height, this.DeviceResources));
                fullResDepthStencilPool = Collect(new TexturePool(this.DeviceResources, new Texture2DDescription()
                {
                    Width             = width,
                    Height            = height,
                    ArraySize         = 1,
                    BindFlags         = BindFlags.DepthStencil,
                    CpuAccessFlags    = CpuAccessFlags.None,
                    Usage             = ResourceUsage.Default,
                    MipLevels         = 1,
                    OptionFlags       = ResourceOptionFlags.None,
                    SampleDescription = new SampleDescription(1, 0)
                }));

                fullResRenderTargetPool = Collect(new TexturePool(this.DeviceResources, new Texture2DDescription()
                {
                    Width             = width,
                    Height            = height,
                    BindFlags         = BindFlags.RenderTarget | BindFlags.ShaderResource,
                    CpuAccessFlags    = CpuAccessFlags.None,
                    Usage             = ResourceUsage.Default,
                    ArraySize         = 1,
                    MipLevels         = 1,
                    OptionFlags       = ResourceOptionFlags.None,
                    SampleDescription = new SampleDescription(1, 0)
                }));

                halfResDepthStencilPool = Collect(new TexturePool(this.DeviceResources, new Texture2DDescription()
                {
                    Width             = Math.Max(2, width / 2),
                    Height            = Math.Max(2, height / 2),
                    ArraySize         = 1,
                    BindFlags         = BindFlags.DepthStencil,
                    CpuAccessFlags    = CpuAccessFlags.None,
                    Usage             = ResourceUsage.Default,
                    MipLevels         = 1,
                    OptionFlags       = ResourceOptionFlags.None,
                    SampleDescription = new SampleDescription(1, 0)
                }));

                halfResRenderTargetPool = Collect(new TexturePool(this.DeviceResources, new Texture2DDescription()
                {
                    Width             = Math.Max(2, width / 2),
                    Height            = Math.Max(2, height / 2),
                    BindFlags         = BindFlags.RenderTarget | BindFlags.ShaderResource,
                    CpuAccessFlags    = CpuAccessFlags.None,
                    Usage             = ResourceUsage.Default,
                    ArraySize         = 1,
                    MipLevels         = 1,
                    OptionFlags       = ResourceOptionFlags.None,
                    SampleDescription = new SampleDescription(1, 0)
                }));

                quarterResDepthStencilPool = Collect(new TexturePool(this.DeviceResources, new Texture2DDescription()
                {
                    Width             = Math.Max(2, width / 4),
                    Height            = Math.Max(2, height / 4),
                    ArraySize         = 1,
                    BindFlags         = BindFlags.DepthStencil,
                    CpuAccessFlags    = CpuAccessFlags.None,
                    Usage             = ResourceUsage.Default,
                    MipLevels         = 1,
                    OptionFlags       = ResourceOptionFlags.None,
                    SampleDescription = new SampleDescription(1, 0)
                }));

                quarterResRenderTargetPool = Collect(new TexturePool(this.DeviceResources, new Texture2DDescription()
                {
                    Width             = Math.Max(2, width / 4),
                    Height            = Math.Max(2, height / 4),
                    BindFlags         = BindFlags.RenderTarget | BindFlags.ShaderResource,
                    CpuAccessFlags    = CpuAccessFlags.None,
                    Usage             = ResourceUsage.Default,
                    ArraySize         = 1,
                    MipLevels         = 1,
                    OptionFlags       = ResourceOptionFlags.None,
                    SampleDescription = new SampleDescription(1, 0)
                }));
            }
예제 #8
0
 public Image(string textureName)
 {
     texture = TexturePool.Get(textureName);
     Width   = texture.Width;
     Height  = texture.Height;
 }
예제 #9
0
        public static void Init()
        {
            CurrentMenu.Text  = "Main Menu";
            CurrentMenu.Items = new List <DbgMenuItem>()
            {
                //new DbgMenuItem()
                //{
                //    Text = "<-- TESTING -->",
                //    Items = new List<DbgMenuItem>
                //    {
                //        new DbgMenuItem()
                //        {
                //            Text = "Write TextureFetchRequest.DEBUG_AllKnownDS1Formats to Console",
                //            ClickAction = () =>
                //            {
                //                foreach (var f in TextureFetchRequest.DEBUG_AllKnownDS1Formats)
                //                {
                //                    Console.WriteLine(f.ToString());
                //                }
                //            }
                //        }
                //    }
                //},
                new DbgMenuItem()
                {
                    Text        = "<-- TESTS -->",
                    ClickAction = m =>
                    {
                        m.Items.Clear();
                        Tests.SetupTests(m.Items);
                    }
                },
                new DbgMenuItemSceneList(isModelGroupingKind: false)
                {
                    Text = "Scene Parts"
                },
                new DbgMenuItemSceneList(isModelGroupingKind: true)
                {
                    Text = "Scene Models"
                },
                new DbgMenuItem()
                {
                    Text        = "Click to remove all debug primitives",
                    ClickAction = (m) => DBG.ClearPrimitives()
                },
                new DbgMenuItem()
                {
                    Text  = "Game Data",
                    Items = new List <DbgMenuItem>
                    {
                        new DbgMenuItemTextLabel(() => $"Data Root: \"{InterrootLoader.Interroot}\"\n     [Click to Browse...]")
                        {
                            ClickAction = (m) =>
                            {
                                InterrootLoader.Browse();
                                CurrentMenu.RequestTextRefresh();
                            }
                        },
                        new DbgMenuItemEnum <InterrootLoader.InterrootType>("Game Type",
                                                                            v =>
                        {
                            InterrootLoader.Type = v;
                            CFG.Save();
                        },
                                                                            () => InterrootLoader.Type,
                                                                            nameOverrides: new Dictionary <InterrootLoader.InterrootType, string>
                        {
                            { InterrootLoader.InterrootType.InterrootNB, "Ninja Blade" },
                            { InterrootLoader.InterrootType.InterrootDeS, "Demon's Souls" },
                            { InterrootLoader.InterrootType.InterrootBloodborne, "Bloodborne" },
                            { InterrootLoader.InterrootType.InterrootDS1, "Dark Souls" },
                            { InterrootLoader.InterrootType.InterrootDS1R, "Dark Souls Remastered" },
                            { InterrootLoader.InterrootType.InterrootDS2, "Dark Souls II" },
                            { InterrootLoader.InterrootType.InterrootDS3, "Dark Souls III" },
                        }
                                                                            ),
                        new DbgMenuItem()
                        {
                            Text        = "Refresh Spawn Lists",
                            ClickAction = m =>
                            {
                                DbgMenuItemSpawnChr.UpdateSpawnIDs();
                                DbgMenuItemSpawnObj.UpdateSpawnIDs();
                                DbgMenuItemSpawnMap.UpdateSpawnIDs();
                            }
                        },
                        new DbgMenuItemTaskKiller()
                        {
                            Text = "[LOAD TASK KILLER]"
                        },
                        new DbgMenuItem()
                        {
                            Text        = "Scan All Separate Texture Files (DS1 Only)",
                            ClickAction = (m) =>
                            {
                                TexturePool.AddAllExternalDS1TexturesInBackground();
                            }
                        },
                        new DbgMenuItem()
                        {
                            Text        = "Purge Texture Cache",
                            ClickAction = (m) =>
                            {
                                TexturePool.Flush();
                            }
                        },
                        new DbgMenuItem()
                        {
                            Text        = "[CLICK TO CLEAR SCENE MODELS]",
                            ClickAction = (m) => GFX.ModelDrawer.ClearScene()
                        },
                        new DbgMenuItem()
                        {
                            Text        = "[CLICK TO CLEAR SCENE REGIONS]",
                            ClickAction = (m) => DBG.ClearPrimitives()
                        },
                        new DbgMenuItemSpawnChr()
                        {
                            CustomColorFunction = () => Color.Cyan
                        },
                        new DbgMenuItemSpawnObj()
                        {
                            CustomColorFunction = () => Color.Cyan
                        },
                        new DbgMenuItemSpawnMap(DbgMenuItemSpawnMap.SpawnerType.SpawnModel),
                        new DbgMenuItemSpawnMap(DbgMenuItemSpawnMap.SpawnerType.SpawnRegion),
                        new DbgMenuItemSpawnMap(DbgMenuItemSpawnMap.SpawnerType.SpawnCollision)
                        {
                            CustomColorFunction = () => Color.Cyan
                        },
                        new DbgMenuItemBool("Move Camera to Models as they Spawn", "YES", "NO",
                                            (b) => GFX.ModelDrawer.GoToModelsAsTheySpawn = b, () => GFX.ModelDrawer.GoToModelsAsTheySpawn),
                        new DbgMenuItem()
                        {
                            Text                = "Load All Characters Lineup",
                            ClickAction         = (m) => GFX.ModelDrawer.TestAddAllChr(),
                            CustomColorFunction = () => LoadingTaskMan.IsTaskRunning($"{nameof(GFX.ModelDrawer.TestAddAllChr)}") ? Color.Cyan * 0.5f : Color.Cyan
                        },
                        new DbgMenuItem()
                        {
                            Text                = "Load All Objects Lineup",
                            ClickAction         = (m) => GFX.ModelDrawer.TestAddAllObj(),
                            CustomColorFunction = () => LoadingTaskMan.IsTaskRunning($"{nameof(GFX.ModelDrawer.TestAddAllObj)}") ? Color.Cyan * 0.5f : Color.Cyan
                        },
                    }
                },
                //new DbgMenuItem()
                //{
                //    Text = "[DIAGNOSTICS]",
                //    Items = new List<DbgMenuItem>
                //    {
                //        new DbgMenuItem()
                //        {
                //            Text = $"Log {nameof(InterrootLoader)}.{nameof(InterrootLoader.DDS_INFO)}",
                //            ClickAction = () =>
                //            {
                //                foreach (var x in InterrootLoader.DDS_INFO)
                //                {
                //                    Console.WriteLine($"{x.Name} - {x.DDSFormat}");
                //                }
                //            }
                //        }
                //    }
                //},
                new DbgMenuItem()
                {
                    Text  = "General Options",
                    Items = new List <DbgMenuItem>
                    {
                        new DbgMenuItemGfxFlverShaderAdjust(),
                        //new DbgMenuItemGfxBlendStateAdjust(),
                        //new DbgMenuItemGfxDepthStencilStateAdjust(),
                        new DbgMenuItemEnum <LODMode>("LOD Mode", v => GFX.LODMode = v, () => GFX.LODMode,
                                                      nameOverrides: new Dictionary <LODMode, string>
                        {
                            { LODMode.ForceFullRes, "Force Full Resolution" },
                            { LODMode.ForceLOD1, "Force LOD Level 1" },
                            { LODMode.ForceLOD2, "Force LOD Level 2" },
                        }),
                        new DbgMenuItemNumber("LOD1 Distance", 0, 10000, 1,
                                              (f) => GFX.LOD1Distance = f, () => GFX.LOD1Distance),
                        new DbgMenuItemNumber("LOD2 Distance", 0, 10000, 1,
                                              (f) => GFX.LOD2Distance = f, () => GFX.LOD2Distance),
                        new DbgMenuItemBool("Show Debug Primitive Nametags", "YES", "NO",
                                            (b) => DBG.ShowPrimitiveNametags = b, () => DBG.ShowPrimitiveNametags),
                        //new DbgMenuItemBool("Show Fancy Text Labels", "YES", "NO",
                        //    (b) => DBG.ShowFancyTextLabels = b, () => DBG.ShowFancyTextLabels),
                        new DbgMenuItemNumber("Debug Primitive Nametag Size", 0.1f, 20.0f, 0.1f,
                                              (v) => DBG.PrimitiveNametagSize = v, () => DBG.PrimitiveNametagSize),
                        new DbgMenuItemBool("Show Model Names", "YES", "NO",
                                            (b) => DBG.ShowModelNames = b, () => DBG.ShowModelNames),
                        //new DbgMenuItemBool("Show Model Bounding Boxes", "YES", "NO",
                        //    (b) => DBG.ShowModelBoundingBoxes = b, () => DBG.ShowModelBoundingBoxes),
                        //new DbgMenuItemBool("Show Model Submesh Bounding Boxes", "YES", "NO",
                        //    (b) => DBG.ShowModelSubmeshBoundingBoxes = b, () => DBG.ShowModelSubmeshBoundingBoxes),
                        new DbgMenuItemBool("Show Grid", "YES", "NO",
                                            (b) => DBG.ShowGrid = b, () => DBG.ShowGrid),
                        new DbgMenuItemBool("Textures", "ON", "OFF",
                                            (b) => GFX.EnableTextures = b, () => GFX.EnableTextures),
                        new DbgMenuItemBool("Realtime Lighting", "ON", "OFF",
                                            (b) => GFX.EnableLighting = b, () => GFX.EnableLighting),
                        new DbgMenuItemBool("Lightmapping", "ON", "OFF",
                                            (b) => GFX.EnableLightmapping = b, () => GFX.EnableLightmapping),
                        new DbgMenuItemBool("Wireframe Mode", "ON", "OFF",
                                            (b) => GFX.Wireframe = b, () => GFX.Wireframe),
                        //new DbgMenuItemBool("View Frustum Culling (Experimental)", "ON", "OFF",
                        //    (b) => GFX.EnableFrustumCulling = b, () => GFX.EnableFrustumCulling),
                        new DbgMenuItemNumber("Vertical Field of View (Degrees)", 20, 150, 1,
                                              (f) => GFX.World.FieldOfView = f, () => GFX.World.FieldOfView,
                                              (f) => $"{((int)(Math.Round(f)))}"),
                        new DbgMenuItemNumber("Camera Turn Speed (Gamepad)", 0.01f, 10f, 0.01f,
                                              (f) => GFX.World.CameraTurnSpeedGamepad = f, () => GFX.World.CameraTurnSpeedGamepad),
                        new DbgMenuItemNumber("Camera Turn Speed (Mouse)", 0.001f, 10f, 0.001f,
                                              (f) => GFX.World.CameraTurnSpeedMouse = f, () => GFX.World.CameraTurnSpeedMouse),
                        new DbgMenuItemNumber("Camera Move Speed", 0.1f, 100f, 0.1f,
                                              (f) => GFX.World.CameraMoveSpeed = f, () => GFX.World.CameraMoveSpeed),
                        new DbgMenuItemNumber("Near Clip Distance", 0.0001f, 5, 0.0001f,
                                              (f) => GFX.World.NearClipDistance = f, () => GFX.World.NearClipDistance),
                        new DbgMenuItemNumber("Far Clip Distance", 100, 1000000, 100,
                                              (f) => GFX.World.FarClipDistance = f, () => GFX.World.FarClipDistance),
                    }
                },
                new DbgMenuItem()
                {
                    Text  = "Graphics Options",
                    Items = new List <DbgMenuItem>
                    {
                        new DbgMenuItemResolutionChange(),
                        new DbgMenuItemBool("Fullscreen", "YES", "NO", v => GFX.Display.Fullscreen  = v, () => GFX.Display.Fullscreen),
                        new DbgMenuItemBool("Vsync", "ON", "OFF", v => GFX.Display.Vsync            = v, () => GFX.Display.Vsync),
                        new DbgMenuItemBool("Simple MSAA", "ON", "OFF", v => GFX.Display.SimpleMSAA = v, () => GFX.Display.SimpleMSAA),
                        new DbgMenuItem()
                        {
                            Text        = "Apply Changes",
                            ClickAction = (m) => GFX.Display.Apply(),
                        }
                    }
                },
                new DbgMenuItem()
                {
                    Text        = "Return Camera to Origin",
                    ClickAction = m => GFX.World.ResetCameraLocation()
                },
                new DbgMenuItem()
                {
                    Text  = "Help",
                    Items = new List <DbgMenuItem>
                    {
                        new DbgMenuItem()
                        {
                            Text  = "Menu Overlay Controls (Gamepad)",
                            Items = new List <DbgMenuItem>
                            {
                                new DbgMenuItem()
                                {
                                    Text = "Back: Toggle Menu (Active/Visible/Hidden)"
                                },
                                new DbgMenuItem()
                                {
                                    Text = "D-Pad Up/Down: Move Cursor Up/Down"
                                },
                                new DbgMenuItem()
                                {
                                    Text = "A: Enter/Activate (when applicable)"
                                },
                                new DbgMenuItem()
                                {
                                    Text = "B: Go Back (when applicable)"
                                },
                                new DbgMenuItem()
                                {
                                    Text = "D-Pad Left/Right: Decrease/Increase"
                                },
                                new DbgMenuItem()
                                {
                                    Text = "Start: Reset Value to Default"
                                },
                                new DbgMenuItem()
                                {
                                    Text = "Hold LB: Increase/Decrease 10x Faster"
                                },
                                new DbgMenuItem()
                                {
                                    Text = "Hold X: Increase/Decrease 100x Faster"
                                },
                                new DbgMenuItem()
                                {
                                    Text = "Hold RB + Move LS: Move Menu"
                                },
                                new DbgMenuItem()
                                {
                                    Text = "Hold RB + Move RS: Resize Menu"
                                },
                                new DbgMenuItem()
                                {
                                    Text = "Hold LB + Move or Resize Menu: Move or Resize Menu Faster"
                                },
                                new DbgMenuItem()
                                {
                                    Text = "Click RS: Toggle 3D Render Pause"
                                },
                            }
                        },
                        new DbgMenuItem()
                        {
                            Text  = "General 3D Controls (Gamepad)",
                            Items = new List <DbgMenuItem>
                            {
                                new DbgMenuItem()
                                {
                                    Text = "LS: Move Camera Laterally"
                                },
                                new DbgMenuItem()
                                {
                                    Text = "LT: Move Camera Directly Downward"
                                },
                                new DbgMenuItem()
                                {
                                    Text = "RT: Move Camera Directly Upward"
                                },
                                new DbgMenuItem()
                                {
                                    Text = "RS: Turn Camera"
                                },
                                new DbgMenuItem()
                                {
                                    Text = "Hold LB: Move Camera More Slowly"
                                },
                                new DbgMenuItem()
                                {
                                    Text = "Hold RB: Move Camera More Quickly"
                                },
                                new DbgMenuItem()
                                {
                                    Text = "Click LS and Hold: Turn Light With RS Instead of Camera"
                                },
                                new DbgMenuItem()
                                {
                                    Text = "Click RS: Reset Camera To Origin"
                                },
                            }
                        },
                        new DbgMenuItem()
                        {
                            Text  = "Menu Overlay Controls (Mouse & Keyboard)",
                            Items = new List <DbgMenuItem>
                            {
                                new DbgMenuItem()
                                {
                                    Text = "Tilde (~): Toggle Menu (Active/Visible/Hidden)"
                                },

                                new DbgMenuItem()
                                {
                                    Text = "Move Mouse Cursor: Move Cursor"
                                },
                                new DbgMenuItem()
                                {
                                    Text = "Hold Spacebar + Scroll Mouse Wheel: Change Values"
                                },
                                new DbgMenuItem()
                                {
                                    Text = "Mouse Wheel: Scroll Menu"
                                },
                                new DbgMenuItem()
                                {
                                    Text = "Enter/Left Click: Enter/Activate (when applicable)"
                                },
                                new DbgMenuItem()
                                {
                                    Text = "Backspace/Right Click: Go Back (when applicable)"
                                },
                                new DbgMenuItem()
                                {
                                    Text = "Up/Down: Move Cursor Up/Down"
                                },
                                new DbgMenuItem()
                                {
                                    Text = "Left/Right: Decrease/Increase"
                                },
                                new DbgMenuItem()
                                {
                                    Text = "Home/Middle Click: Reset Value to Default"
                                },
                                new DbgMenuItem()
                                {
                                    Text = "Hold Shift: Increase/Decrease 10x Faster"
                                },
                                new DbgMenuItem()
                                {
                                    Text = "Hold Ctrl: Increase/Decrease 100x Faster"
                                },
                                new DbgMenuItem()
                                {
                                    Text = "Pause Key: Toggle 3D Render Pause"
                                },
                            }
                        },
                        new DbgMenuItem()
                        {
                            Text  = "General 3D Controls (Mouse & Keyboard)",
                            Items = new List <DbgMenuItem>
                            {
                                new DbgMenuItem()
                                {
                                    Text = "WASD: Move Camera Laterally"
                                },
                                new DbgMenuItem()
                                {
                                    Text = "Q: Move Camera Directly Downward"
                                },
                                new DbgMenuItem()
                                {
                                    Text = "E: Move Camera Directly Upward"
                                },
                                new DbgMenuItem()
                                {
                                    Text = "Right Click + Move Mouse: Turn Camera"
                                },
                                new DbgMenuItem()
                                {
                                    Text = "Hold Shift: Move Camera More Slowly"
                                },
                                new DbgMenuItem()
                                {
                                    Text = "Hold Ctrl: Move Camera More Quickly"
                                },
                                new DbgMenuItem()
                                {
                                    Text = "Hold Spacebar: Turn Light With Mouse Instead of Camera"
                                },
                                new DbgMenuItem()
                                {
                                    Text = "R: Reset Camera To Origin"
                                },
                            }
                        },
                    }
                },
                new DbgMenuItem()
                {
                    Text  = "Exit",
                    Items = new List <DbgMenuItem>
                    {
                        new DbgMenuItem()
                        {
                            Text = "Are you sure you want to exit?"
                        },
                        new DbgMenuItem()
                        {
                            Text        = "No",
                            ClickAction = (m) => REQUEST_GO_BACK = true
                        },
                        new DbgMenuItem()
                        {
                            Text        = "Yes",
                            ClickAction = (m) => Main.REQUEST_EXIT = true
                        }
                    }
                },
            };
        }
예제 #10
0
        public void TestOBJToRAMMeshConverterPerObjectVisual()
        {
            var c = new OBJToRAMMeshConverter(new RAMTextureFactory());


            var importer = new ObjImporter();

            importer.AddMaterialFileStream("Town001.mtl", new FileStream(TestFiles.TownMtl, FileMode.Open));
            importer.ImportObjFile(TestFiles.TownObj);

            var meshes = c.CreateMeshesFromObjects(importer);

            var texturePool           = new TexturePool();
            var meshpartPool          = new MeshPartPool();
            var vertexDeclarationPool = new VertexDeclarationPool();

            var renderer = new SimpleMeshRenderer(texturePool, meshpartPool, vertexDeclarationPool);

            vertexDeclarationPool.SetVertexElements <TangentVertex>(TangentVertex.VertexElements);



            var spheres = new List <ClientPhysicsTestSphere>();
            var engine  = new PhysicsEngine();
            PhysicsDebugRendererXNA debugRenderer = null;

            var builder = new MeshPhysicsActorBuilder(new MeshPhysicsPool());

            TheWizards.Client.ClientPhysicsQuadTreeNode root;

            int numNodes = 20;

            root = new ClientPhysicsQuadTreeNode(
                new BoundingBox(
                    new Vector3(-numNodes * numNodes / 2f, -100, -numNodes * numNodes / 2f),
                    new Vector3(numNodes * numNodes / 2f, 100, numNodes * numNodes / 2f)));

            QuadTree.Split(root, 5);

            var physicsElementFactoryXNA = new MeshPhysicsFactoryXNA(engine, root);
            var physicsElementFactory    = physicsElementFactoryXNA.Factory;

            var physicsElements = new List <MeshStaticPhysicsElement>();

            for (int i = 0; i < 0 * 100 + 1 * meshes.Count; i++)
            {
                var mesh = meshes[i];
                var el   = renderer.AddMesh(mesh);
                el.WorldMatrix = Matrix.CreateTranslation(Vector3.Right * 0 * 2 + Vector3.UnitZ * 0 * 2);

                var pEl = physicsElementFactory.CreateStaticElement(mesh, Matrix.Identity);
                physicsElements.Add(pEl);
            }

            var game = new XNAGame();

            game.IsFixedTimeStep                    = false;
            game.DrawFps                            = true;
            game.SpectaterCamera.FarClip            = 5000;
            game.Graphics1.PreparingDeviceSettings += delegate(object sender, PreparingDeviceSettingsEventArgs e)
            {
                DisplayMode displayMode = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode;
                e.GraphicsDeviceInformation.PresentationParameters.BackBufferFormat = displayMode.Format;
                e.GraphicsDeviceInformation.PresentationParameters.BackBufferWidth  = displayMode.Width;
                e.GraphicsDeviceInformation.PresentationParameters.BackBufferHeight = displayMode.Height;
                game.SpectaterCamera.AspectRatio = displayMode.Width / (float)displayMode.Height;
            };
            game.Graphics1.ToggleFullScreen();

            var sphereMesh = new SphereMesh(0.3f, 20, Color.Green);
            var visualizer = new QuadTreeVisualizerXNA();

            game.AddXNAObject(physicsElementFactoryXNA);

            game.AddXNAObject(texturePool);
            game.AddXNAObject(meshpartPool);
            game.AddXNAObject(vertexDeclarationPool);
            game.AddXNAObject(renderer);


            game.InitializeEvent += delegate
            {
                engine.Initialize();
                debugRenderer = new PhysicsDebugRendererXNA(game, engine.Scene);
                debugRenderer.Initialize(game);
                sphereMesh.Initialize(game);
            };

            bool showPhysics = true;

            game.DrawEvent += delegate
            {
                if (game.Keyboard.IsKeyPressed(Keys.P))
                {
                    showPhysics = !showPhysics;
                }
                if (showPhysics)
                {
                    debugRenderer.Render(game);
                }
                visualizer.RenderNodeGroundBoundig(game, root,
                                                   delegate(ClientPhysicsQuadTreeNode node, out Color col)
                {
                    col = Color.Green;

                    return(node.PhysicsObjects.Count == 0);
                });

                visualizer.RenderNodeGroundBoundig(game, root,
                                                   delegate(ClientPhysicsQuadTreeNode node, out Color col)
                {
                    col = Color.Orange;

                    return(node.PhysicsObjects.Count > 0);
                });

                for (int i = 0; i < physicsElements.Count; i++)
                {
                    var el = physicsElements[i];
                    //game.LineManager3D.AddBox(BoundingBox.CreateFromSphere( el.BoundingSphere), Color.Orange);
                }
                for (int i = 0; i < spheres.Count; i++)
                {
                    sphereMesh.WorldMatrix = Matrix.CreateTranslation(spheres[i].Center);
                    sphereMesh.Render(game);
                }
            };
            game.UpdateEvent += delegate
            {
                engine.Update(game.Elapsed);
                sphereMesh.Update(game);
                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.F))
                {
                    var iSphere = new ClientPhysicsTestSphere(engine.Scene,
                                                              game.SpectaterCamera.CameraPosition + game.SpectaterCamera.CameraDirection
                                                              , 0.3f);

                    iSphere.InitDynamic();
                    iSphere.Actor.LinearVelocity = game.SpectaterCamera.CameraDirection * 10;

                    spheres.Add(iSphere);
                }



                for (int i = 0; i < spheres.Count; i++)
                {
                    spheres[i].Update(root, game);
                }
            };

            game.Run();
        }
예제 #11
0
        public void TestOBJToRAMMeshConverterVisual()
        {
            PhysicsEngine           engine        = new PhysicsEngine();
            PhysicsDebugRendererXNA debugRenderer = null;



            var texFactory = new RAMTextureFactory();
            var c          = new OBJToRAMMeshConverter(texFactory);


            var importer = new ObjImporter();

            importer.AddMaterialFileStream("CollisionModelBoxes001.mtl",
                                           EmbeddedFile.GetStream("MHGameWork.TheWizards.Tests.Physics.Files.CollisionModelBoxes001.mtl",
                                                                  "CollisionModelBoxes001.mtl"));
            importer.ImportObjFile(EmbeddedFile.GetStream("MHGameWork.TheWizards.Tests.Physics.Files.CollisionModelBoxes001.obj", "CollisionModelBoxes001.obj"));


            var mesh = c.CreateMesh(importer);

            importer = new ObjImporter();
            importer.AddMaterialFileStream("HouseTest.mtl", new FileStream("../GameData/Core/001-House01_BoxTest-OBJ/HouseTest.mtl", FileMode.Open));
            importer.ImportObjFile("../GameData/Core/001-House01_BoxTest-OBJ/HouseTest.obj");

            var mesh2 = c.CreateMesh(importer);

            importer = new ObjImporter();
            var fsMHouseMat = new FileStream(TestFiles.MerchantsHouseMtl, FileMode.Open);

            importer.AddMaterialFileStream("MerchantsHouse.mtl", fsMHouseMat);
            importer.ImportObjFile(TestFiles.MerchantsHouseObj);

            fsMHouseMat.Close();

            var mesh3 = c.CreateMesh(importer);

            var texturePool           = new TexturePool();
            var meshpartPool          = new MeshPartPool();
            var vertexDeclarationPool = new VertexDeclarationPool();

            var renderer = new SimpleMeshRenderer(texturePool, meshpartPool, vertexDeclarationPool);

            vertexDeclarationPool.SetVertexElements <TangentVertex>(TangentVertex.VertexElements);


            var el = renderer.AddMesh(mesh);

            el.WorldMatrix = Matrix.CreateTranslation(Vector3.Right * 0 * 2 + Vector3.UnitZ * 0 * 2);

            el             = renderer.AddMesh(mesh2);
            el.WorldMatrix = Matrix.CreateTranslation(new Vector3(0, 0, 80));

            el             = renderer.AddMesh(mesh3);
            el.WorldMatrix = Matrix.CreateTranslation(new Vector3(0, 0, -80));



            var game = new XNAGame();

            game.IsFixedTimeStep = false;
            game.DrawFps         = true;

            game.AddXNAObject(texturePool);
            game.AddXNAObject(meshpartPool);
            game.AddXNAObject(vertexDeclarationPool);
            game.AddXNAObject(renderer);



            game.InitializeEvent += delegate
            {
                engine.Initialize();
                debugRenderer = new PhysicsDebugRendererXNA(game, engine.Scene);
                debugRenderer.Initialize(game);


                var builder = new MeshPhysicsActorBuilder(new MeshPhysicsPool());
                builder.CreateActorStatic(engine.Scene, mesh.GetCollisionData(), Matrix.Identity);
                builder.CreateActorStatic(engine.Scene, mesh2.GetCollisionData(), Matrix.CreateTranslation(new Vector3(0, 0, 80)));
                builder.CreateActorStatic(engine.Scene, mesh3.GetCollisionData(), Matrix.CreateTranslation(new Vector3(0, 0, -80)));
            };

            game.DrawEvent += delegate
            {
                debugRenderer.Render(game);
            };
            game.UpdateEvent += delegate
            {
                engine.Update(game.Elapsed);
                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.F))
                {
                    Actor actor = PhysicsHelper.CreateDynamicSphereActor(engine.Scene, 0.3f, 1);
                    actor.GlobalPosition = game.SpectaterCamera.CameraPosition +
                                           game.SpectaterCamera.CameraDirection * 5;
                    actor.LinearVelocity = game.SpectaterCamera.CameraDirection * 5;
                }
            };



            game.Run();
        }
예제 #12
0
 public override void Allocate()
 {
     Texture = TexturePool.GetTexture(Size, Format);
 }
 public ParticleEffect(DX11Game game, TexturePool texPool)
 {
     this.game = game;
     //this.pool = pool;
     this.texPool = texPool;
 }
예제 #14
0
 protected override void Allocate()
 {
     m_Texture = TexturePool.GetTexture(Size, Format);
 }
예제 #15
0
        //public static Item getItem(string name) {
        //    return Inventory.Single(item => item.Name == name);
        //}

        #region Tests

        public static void FillInventory(int size)
        {
            Inventory.AddItem(new Item(TexturePool.GetTexture("testItem"), "test"), size);
        }
예제 #16
0
        // Static methods

        public static Boolean ExistsInPool(String name)
        {
            return(TexturePool?.ContainsKey(name) == true);
        }
예제 #17
0
 public Bonus(string textureName, Grid grid, GameElement element)
 {
     this.grid    = grid;
     this.element = element;
     bonusTexture = TexturePool.Get(textureName);
 }
예제 #18
0
        public void TestMoveMesh()
        {
            XNAGame game = new XNAGame();

            game.IsFixedTimeStep = false;
            game.DrawFps         = true;

            //Import obj-files
            OBJParser.ObjImporter importer = new OBJParser.ObjImporter();
            var meshCreator = new OBJToRAMMeshConverter(new RAMTextureFactory());

            importer.AddMaterialFileStream("WallCorner.mtl", new FileStream("../../../Assets/WallCorner/WallCorner.mtl", FileMode.Open));
            importer.ImportObjFile("../../../Assets/WallCorner/WallCorner.obj");
            var meshWallCorner = meshCreator.CreateMesh(importer);

            importer.AddMaterialFileStream("WallStraight.mtl", new FileStream("../../../Assets/WallStraight/WallStraight.mtl", FileMode.Open));
            importer.ImportObjFile("../../../Assets/WallStraight/WallStraight.obj");
            var meshWallStraight = meshCreator.CreateMesh(importer);

            TexturePool           texturePool           = new TexturePool();
            MeshPartPool          meshpartPool          = new MeshPartPool();
            VertexDeclarationPool vertexDeclarationPool = new VertexDeclarationPool();
            SimpleMeshRenderer    renderer = new SimpleMeshRenderer(texturePool, meshpartPool, vertexDeclarationPool);

            vertexDeclarationPool.SetVertexElements <TangentVertex>(TangentVertex.VertexElements);
            game.AddXNAObject(texturePool);
            game.AddXNAObject(meshpartPool);
            game.AddXNAObject(vertexDeclarationPool);
            game.AddXNAObject(renderer);

            TileSnapInformationBuilder builder = new TileSnapInformationBuilder();



            //Create WorldObjectTypes
            WorldObjectType wallStraightType = new WorldObjectType(meshWallStraight, Guid.NewGuid(), builder);
            WorldObjectType wallCornerType   = new WorldObjectType(meshWallCorner, Guid.NewGuid(), builder);



            //Add some WorldObjects to the WorldSpace
            WorldObject wallStraight = new WorldObject(game, wallStraightType, renderer);
            WorldObject wallCorner   = new WorldObject(game, wallCornerType, renderer);

            List <WorldObject> WorldObjectList = new List <WorldObject>();

            WorldObjectList.Add(wallCorner);
            WorldObjectList.Add(wallStraight);

            World world = new World();

            world.WorldObjectList.AddRange(WorldObjectList);

            WorldObjectList[1].Position = new Vector3(30, 0, 0);


            WorldObjectMoveTool moveTool = new WorldObjectMoveTool(game, world, builder, renderer);

            game.AddXNAObject(moveTool);

            game.Run();
        }
예제 #19
0
        public void TestAddDeleteMeshToFromWorld()
        {
            XNAGame game = new XNAGame();

            OBJParser.ObjImporter importer = new OBJParser.ObjImporter();
            var c = new OBJToRAMMeshConverter(new RAMTextureFactory());

            importer.AddMaterialFileStream("WallInnerCorner.mtl", new FileStream(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallInnerCorner.mtl", FileMode.Open));
            importer.ImportObjFile(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallInnerCorner.obj");
            var meshWallInnerCorner = c.CreateMesh(importer);

            importer.AddMaterialFileStream("WallStraight.mtl", new FileStream(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallStraight.mtl", FileMode.Open));
            importer.ImportObjFile(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallStraight.obj");
            var meshWallStraight = c.CreateMesh(importer);

            importer.AddMaterialFileStream("WallOuterCorner.mtl", new FileStream(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallOuterCorner.mtl", FileMode.Open));
            importer.ImportObjFile(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallOuterCorner.obj");
            var meshWallOuterCorner = c.CreateMesh(importer);

            var texturePool           = new TexturePool();
            var meshpartPool          = new MeshPartPool();
            var vertexDeclarationPool = new VertexDeclarationPool();

            var renderer = new SimpleMeshRenderer(texturePool, meshpartPool, vertexDeclarationPool);

            vertexDeclarationPool.SetVertexElements <TangentVertex>(TangentVertex.VertexElements);

            World world = new World();
            TileSnapInformationBuilder builder = new TileSnapInformationBuilder();

            WorldObjectPlaceTool placeTool = new WorldObjectPlaceTool(game, world, renderer, builder, new SimpleMeshFactory(), new SimpleTileFaceTypeFactory());
            WorldObjectType      type1     = new WorldObjectType(meshWallInnerCorner, Guid.NewGuid(), builder);
            WorldObjectType      type2     = new WorldObjectType(meshWallStraight, Guid.NewGuid(), builder);
            WorldObjectType      type3     = new WorldObjectType(meshWallOuterCorner, Guid.NewGuid(), builder);

            var tileDataInnerCorner = new TileData(Guid.NewGuid());
            var tileDataStraight    = new TileData(Guid.NewGuid());
            var tileDataOuterCorner = new TileData(Guid.NewGuid());

            tileDataInnerCorner.Dimensions = type1.BoundingBox.Max - type1.BoundingBox.Min;
            tileDataStraight.Dimensions    = type2.BoundingBox.Max - type2.BoundingBox.Min;
            tileDataOuterCorner.Dimensions = type1.BoundingBox.Max - type1.BoundingBox.Min;

            var faceSnapType1 = new TileFaceType(Guid.NewGuid())
            {
                Name = "type1"
            };

            //var faceSnapType2 = new TileFaceType() { Name = "type2" };

            tileDataInnerCorner.SetFaceType(TileFace.Front, faceSnapType1);
            tileDataInnerCorner.SetLocalWinding(TileFace.Front, true);

            tileDataInnerCorner.SetFaceType(TileFace.Left, faceSnapType1);
            tileDataInnerCorner.SetLocalWinding(TileFace.Left, true);

            tileDataStraight.SetFaceType(TileFace.Back, faceSnapType1);
            tileDataStraight.SetLocalWinding(TileFace.Back, false);

            tileDataStraight.SetFaceType(TileFace.Front, faceSnapType1);
            tileDataStraight.SetLocalWinding(TileFace.Front, true);

            tileDataOuterCorner.SetFaceType(TileFace.Front, faceSnapType1);
            tileDataOuterCorner.SetLocalWinding(TileFace.Front, true);

            tileDataOuterCorner.SetFaceType(TileFace.Right, faceSnapType1);
            tileDataOuterCorner.SetLocalWinding(TileFace.Right, true);


            type1.TileData = tileDataInnerCorner;
            type2.TileData = tileDataStraight;
            type3.TileData = tileDataOuterCorner;


            type1.SnapInformation = builder.CreateFromTile(tileDataInnerCorner);
            type2.SnapInformation = builder.CreateFromTile(tileDataStraight);
            type3.SnapInformation = builder.CreateFromTile(tileDataOuterCorner);

            List <WorldObjectType> typeList = new List <WorldObjectType>();

            typeList.Add(type1);
            typeList.Add(type2);
            typeList.Add(type3);

            WorldObjectMoveTool moveTool = new WorldObjectMoveTool(game, world, builder, renderer);

            game.AddXNAObject(moveTool);
            game.AddXNAObject(placeTool);

            game.IsFixedTimeStep = false;
            game.DrawFps         = true;
            game.AddXNAObject(texturePool);
            game.AddXNAObject(meshpartPool);
            game.AddXNAObject(vertexDeclarationPool);
            game.AddXNAObject(renderer);

            EditorGrid grid;

            grid               = new EditorGrid();
            grid.Size          = new Vector2(100, 100);
            grid.Interval      = 1;
            grid.MajorInterval = 10;

            bool mouseEnabled = false;

            game.UpdateEvent += delegate
            {
                if (placeTool.Enabled)
                {
                    moveTool.Enabled = false;

                    if (placeTool.ObjectsPlacedSinceEnabled() == 1)
                    {
                        placeTool.Enabled = false;
                    }
                }
                else
                {
                    moveTool.Enabled = true;
                }

                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.NumPad1))
                {
                    placeTool.PlaceType = typeList[0];
                    placeTool.Enabled   = true;
                }
                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.NumPad2))
                {
                    placeTool.PlaceType = typeList[1];
                    placeTool.Enabled   = true;
                }
                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.NumPad3))
                {
                    placeTool.PlaceType = typeList[2];
                    placeTool.Enabled   = true;
                }

                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.LeftAlt))
                {
                    mouseEnabled = !mouseEnabled;
                }
                if (mouseEnabled)
                {
                    game.Mouse.CursorEnabled     = true;
                    game.IsMouseVisible          = true;
                    game.SpectaterCamera.Enabled = false;
                }
                else
                {
                    game.Mouse.CursorEnabled     = false;
                    game.IsMouseVisible          = false;
                    game.SpectaterCamera.Enabled = true;
                    //activeWorldObject = null;
                }
            };
            game.DrawEvent += delegate
            {
                grid.Render(game);
            };

            game.Run();
        }
예제 #20
0
    public void showInGameHud()
    {
        Game game = Game.game;

        Game.GameStates currentState = Game.game.currentState;

        if (currentState == Game.GameStates.Town || currentState == Game.GameStates.InTutorialTown)
        {
            if (Screen.height >= 480)
            {
                healthStatBar.fillRect.y     = 0.085f;
                magicStatBar.fillRect.y      = 0.13f;
                experienceStatBar.fillRect.y = 0.176f;
                levelRect.y = 0.235f;

                portraitRect.y = 0.05f;
                infoBarRect.y  = 0.05f;
            }
            else
            {
                healthStatBar.fillRect.y     = 0.13f;
                magicStatBar.fillRect.y      = 0.18f;
                experienceStatBar.fillRect.y = 0.227f;
                levelRect.y = 0.27f;

                portraitRect.y = 0.1f;
                infoBarRect.y  = 0.1f;
            }
        }

        //level of the player
        Rect lvlRect = new Rect(levelRect);

        float h      = (float)Screen.height;
        float w      = (float)Screen.width;
        float aspect = w / h;

        if (aspect > (16.0f / 9.0f))
        {
            float pw = (w - h * 16.0f / 9.0f) * 0.5f;
            lvlRect.x += pw / Screen.width;
        }

        string fontInResolution = textFont("[F ButtonFontBigXL]", "[F ButtonFontBig28]", "[F ButtonFontBig32]", "[F FontSize72]");

        if (lastlvl != game.getPlayerLevel())
        {
            lastlvl  = game.getPlayerLevel();
            lvlLabel = null;
        }

        showLabelFormat(ref lvlLabel, lvlRect, fontInResolution + "[c FFFFFFFF]" + lvlNoCapsString.text + " : " + game.getPlayerLevel().ToString() + fontInResolution,
                        new string[] { "ButtonFontBigXL", "ButtonFontBig28", "ButtonFontBig32", "FontSize72" });
        //health bar
        healthStatBar.fillRect.x      = infoBarRect.x + (originalHealthFillRect.x - infoBarRect.x) * 1.5f * ((float)Screen.height / (float)Screen.width);
        healthStatBar.getCurrentValue = game.getPlayerHealth;
        healthStatBar.getMaximumValue = game.getPlayerMaxHealth;
        healthStatBar.draw();

        //magic bar
        magicStatBar.fillRect.x      = infoBarRect.x + (originalMagicFillRect.x - infoBarRect.x) * 1.5f * ((float)Screen.height / (float)Screen.width);
        magicStatBar.getCurrentValue = game.getPlayerMagic;
        magicStatBar.getMaximumValue = game.getPlayerMaxMagic;
        magicStatBar.draw();

        //exp bar
        experienceStatBar.fillRect.x      = infoBarRect.x + (originalExperienceFillRect.x - infoBarRect.x) * 1.5f * ((float)Screen.height / (float)Screen.width);
        experienceStatBar.getCurrentValue = delegate()
        {
            if (Game.game.gameStats.level < Game.levelCap)
            {
                return(game.getPlayerExperience() - game.getExperienceForCurrentLevel());
            }
            else
            {
                return(1);
            }
        };
        experienceStatBar.getMaximumValue = delegate()
        {
            if (Game.game.gameStats.level < Game.levelCap)
            {
                return(game.getExperienceNeededForNextLevel() - game.getExperienceForCurrentLevel());
            }
            else
            {
                return(1);
            }
        };
        experienceStatBar.draw();

        //hero's icon
        showImage(portrait, portraitRect);

        //hud layout
        showImage(infoBarHero, infoBarRect);

        // Pause Button

        bool inTown            = Game.game.InTown();
        bool townButtonEnabled = TownGui.townButtonsEnabled();

        if (Game.game.pauseButtonEnabled)
        {
            if (!inTown || (inTown && townButtonEnabled))
            {
                showHudButton(pauseButton, true, inventoryActive);
            }
        }

        ButtonDelegate btHealDelegate  = delegate(Object o){};
        ButtonDelegate btMagicDelegate = delegate(Object o){};

        bool canUseHealingPotion = true;
        bool canUseMagicPotion   = true;

        TutSkillAndMagic skillAndMagic = Game.game.GetComponent <TutSkillAndMagic>();

        if (skillAndMagic != null && skillAndMagic.runningTutorial)
        {
            canUseHealingPotion = false;
        }

        if (Game.game.playableCharacter != null)
        {
            if (Game.game.playableCharacter.isAlive())
            {
                //use healing potion
                btHealDelegate = delegate(Object o)
                {
                    if (!inventoryVisible && canUseHealingPotion)
                    {
                        Inventory.inventory.consume(healingPotionItem, 1);
                        Game.game.healingPotionButton = true;
                        if (audioHud != null)
                        {
                            Game.game.playSound(audioHud.audioPool[0]);
                        }
                    }
                };

                //use magic potion
                btMagicDelegate = delegate(Object o)
                {
                    if (!inventoryVisible && canUseMagicPotion)
                    {
                        Inventory.inventory.consume(manaPotionItem, 1);
                        if (audioHud != null)
                        {
                            Game.game.playSound(audioHud.audioPool[1]);
                        }
                    }
                };
            }
        }

        if (!Game.game.InTown())
        {
            //show current buffs
            showBuffStack();

            //enemy life bar
            enemyLifeBar.draw();

            if (Game.game.currentDialog == null)
            {
                itemPotionEnabled  = Inventory.inventory.getItemAmmount(healingPotionItem) > 0;
                magicPotionEnabled = Inventory.inventory.getItemAmmount(manaPotionItem) > 0;
                chestPotionEnabled = true;

                //life potion button
                if (Game.game.healingPotionEnabled)
                {
                    showHudButton(healingPotion, itemPotionEnabled, btHealDelegate);

                    if (Inventory.inventory.getItemAmmount(healingPotionItem) > 0)
                    {
                        potionUseStyle.font = styleInResolution(potionFontStyle, buttonSmall, buttonMidle, buttonBig, buttonBigXXL, 0f);
                        showLabel(healingPotionNRect, Inventory.inventory.getItemAmmount(healingPotionItem).ToString(), potionUseStyle);
                    }
                }
                // if potions > 1


                //magic potion button
                if (Game.game.magicPotionEnabled)
                {
                    showHudButton(magicPotion, magicPotionEnabled, btMagicDelegate);

                    if (Inventory.inventory.getItemAmmount(manaPotionItem) > 0)
                    {
                        potionUseStyle.font = styleInResolution(potionFontStyle, buttonSmall, buttonMidle, buttonBig, buttonBigXXL, 0f);
                        showLabel(manaPotionNRect, Inventory.inventory.getItemAmmount(manaPotionItem).ToString(), potionUseStyle);
                    }
                }

                //open chest button
                if (Game.game.quickChestEnabled)
                {
                    showHudButton(chest, chestPotionEnabled, delegate(Object o)
                    {
                        if (!inventoryVisible)
                        {
                            toogleQuickPotions(null);
                        }
                    }
                                  );
                }

                //skill images
                Texture2D[] currentSkillImages         = new Texture2D[4];
                Texture2D[] currentDisabledSkillImages = new Texture2D[4];

                TexturePool tpool = (Resources.Load("TexturePools/Skills") as GameObject).GetComponent <TexturePool>();

                for (int i = 0; i < 4; i++)
                {
                    if (Game.game.currentSkills[i] != -1)
                    {
                        Texture2D image  = tpool.getFromList(Game.skillData[(int)Game.game.currentSkills[i]].enabled);
                        Texture2D dimage = tpool.getFromList(Game.skillData[(int)Game.game.currentSkills[i]].disabled);

                        currentSkillImages[i]         = image;
                        currentDisabledSkillImages[i] = dimage;
                    }
                }

                skill1.enabled = currentSkillImages[0]; skill1.disabled = currentDisabledSkillImages[0];
                skill2.enabled = currentSkillImages[1]; skill2.disabled = currentDisabledSkillImages[1];
                skill3.enabled = currentSkillImages[2]; skill3.disabled = currentDisabledSkillImages[2];
                skill4.enabled = currentSkillImages[3]; skill4.disabled = currentDisabledSkillImages[3];

                bool canUseSkillButtons = true;

                if (skillAndMagic != null && skillAndMagic.runningTutorial && Game.game.magicPotionEnabled)
                {
                    canUseSkillButtons = false;
                }

                //skills buttons
                showHudButton(skill1, Game.game.canUseSkill((int)Game.game.currentSkills[0]), delegate(Object o)
                {
                    if (canUseSkillButtons)
                    {
                        Game.game.useSkill((int)Game.game.currentSkills[0]);
                    }
                });
                showHudButton(skill2, Game.game.canUseSkill((int)Game.game.currentSkills[1]), delegate(Object o)
                {
                    if (canUseSkillButtons)
                    {
                        Game.game.useSkill((int)Game.game.currentSkills[1]);
                    }
                });
                showHudButton(skill3, Game.game.canUseSkill((int)Game.game.currentSkills[2]), delegate(Object o)
                {
                    if (canUseSkillButtons)
                    {
                        Game.game.useSkill((int)Game.game.currentSkills[2]);
                    }
                });
                showHudButton(skill4, Game.game.canUseSkill((int)Game.game.currentSkills[3]), delegate(Object o)
                {
                    if (canUseSkillButtons)
                    {
                        Game.game.useSkill((int)Game.game.currentSkills[3]);
                    }
                });
            }
        }
    }