예제 #1
0
        public void TestSyncOffline()
        {
            var serverpm = new SimpleServerPacketManager();
            var clientpm = serverpm.CreateClient();

            var vertexDeclarationPool = new VertexDeclarationPool();

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

            var texturePool  = new TexturePool();
            var meshPartPool = new MeshPartPool();

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

            var mesh =
                DefaultMeshes.CreateGuildHouseMesh(
                    new TheWizards.OBJParser.OBJToRAMMeshConverter(new RAMTextureFactory()));

            var meshFactory = new SimpleMeshFactory();

            meshFactory.AddMesh(mesh);

            var builder = new SimpleStaticWorldObjectFactory(renderer, meshFactory);

            var client = new ClientStaticWorldObjectSyncer(clientpm, builder);
            var server = new ServerStaticWorldObjectSyncer(serverpm);

            var game = new XNAGame();



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


            game.InitializeEvent += delegate
            {
            };

            game.UpdateEvent += delegate
            {
                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.F))
                {
                    var o   = server.CreateNew();
                    var obj = o;
                    obj.Mesh        = mesh;
                    obj.WorldMatrix = Matrix.CreateTranslation(game.SpectaterCamera.CameraPosition);
                }

                server.Update(game.Elapsed);

                client.Update(game.Elapsed);
            };

            game.Run();
        }
예제 #2
0
        public void TestSerializeTileData()
        {
            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 simpleMeshFactory = new SimpleMeshFactory();

            simpleMeshFactory.AddMesh(meshWallInnerCorner);

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

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

            diskTileDataFactory.SerializeTileData(data, stream);

            stream.Close();

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

            TileData readData = diskTileDataFactory.DeserializeTileData(readStream);

            readStream.Close();
        }
예제 #3
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();
        }