示例#1
0
    void Awake()
    {
        // Create a new BSPmap, which is an object that
        // represents the map and all its data as a whole
        if (mapIsInsidePK3)
            map = new BSPMap(mapName, true);
        else
            map = new BSPMap("Assets/baseq3/maps/" + mapName, false);

        // Each face is its own gameobject
        foreach (Face face in map.faceLump.Faces)
        {
            if (face.type == 2)
            {
                if (renderBezPatches)
                {
                    GenerateBezObject(face);
                }
                faceCount++;
            } else if (face.type == 1)
            {
                GeneratePolygonObject(face);
                faceCount++;
            } else if (face.type == 3)
            {
                GeneratePolygonObject(face);
                faceCount++;
            } else
            {
                Debug.Log("Skipped Face " + faceCount.ToString() + " because it was not a polygon, mesh, or bez patch.");
                faceCount++;
            }
        }
        GC.Collect();
    }
 private void OnDestroy()
 {
     if (map != null)
     {
         map.Unload();
     }
     map = null;
 }
示例#3
0
        private void mapsList_SelectedIndexChanged(object sender, EventArgs e)
        {
            BSPMap selectedMap = (BSPMap)mapsList.SelectedItem;

            if (selectedMap.overviewImage != null && selectedMap.overviewImage.images.Length > 0)
            {
                overviewBox.BackgroundImage = selectedMap.overviewImage.images[0];
            }
        }
示例#4
0
 private void LoadMaps(params string[] files)
 {
     foreach (string file in files)
     {
         BSPMap newMap = new BSPMap(file);
         if (!newMap.alreadyLoaded)
         {
             newMap.LoadMap();
         }
     }
 }
示例#5
0
    private void CreateMapObjectIfNotExist()
    {
        if (map == null)
        {
            string fullMapPath = GetMapPath(mapName);

            if (!string.IsNullOrEmpty(fullMapPath) && File.Exists(fullMapPath))
            {
                map = new BSPMap(fullMapPath);
            }
        }
    }
    private void OnDisable()
    {
        if (loadingTask != null && UnityHelpers.TaskManagerController.HasTask(loadingTask))
        {
            UnityHelpers.TaskManagerController.CancelTask(loadingTask);
        }

        if (map != null)
        {
            map.Unload();
        }
        map = null;
    }
示例#7
0
 public void UnloadMap()
 {
     TaskManagerController.RunAction(() =>
     {
         map?.Unload();
         map = null;
         if (loadedMap == this)
         {
             loadedMap = null;
         }
         MapLoaderController.mapLoaderInScene.combiner.DestroyCombinedObjects();
         GC.Collect();
     });
 }
    public BSPMap LoadMap(string vpkLoc, string mapLoc, bool combineMeshesWithSameTextures = true, float faceLoadPercent = 1, float modelLoadPercent = 1, bool flatTextures = false, int maxTextureSize = 2048)
    {
        BSPMap.vpkLoc = vpkLoc;
        BSPMap map = new BSPMap(mapLoc);

        BSPMap.combineMeshesWithSameTexture = combineMeshesWithSameTextures;
        BSPMap.FaceLoadPercent        = faceLoadPercent;
        BSPMap.ModelLoadPercent       = modelLoadPercent;
        SourceTexture.averageTextures = flatTextures;
        SourceTexture.maxTextureSize  = maxTextureSize;

        map.ParseFile(System.Threading.CancellationToken.None);
        map.MakeGameObject(null, (go) => { go.transform.SetParent(transform, false); go.SetActive(true); });

        return(map);
    }
示例#9
0
    void Awake()
    {
        // Create a new BSPmap, which is an object that
        // represents the map and all its data as a whole
        if (mapIsInsidePK3)
        {
            map = new BSPMap(mapName, true);
        }
        else
        {
            map = new BSPMap("Assets/baseq3/maps/" + mapName, false);
        }

        // Each face is its own gameobject
        foreach (Face face in map.faceLump.Faces)
        {
            if (face.type == 2)
            {
                if (renderBezPatches)
                {
                    GenerateBezObject(face);
                }
                faceCount++;
            }
            else if (face.type == 1)
            {
                GeneratePolygonObject(face);
                faceCount++;
            }
            else if (face.type == 3)
            {
                GeneratePolygonObject(face);
                faceCount++;
            }
            else
            {
                Debug.Log("Skipped Face " + faceCount.ToString() + " because it was not a polygon, mesh, or bez patch.");
                faceCount++;
            }
        }
        GC.Collect();
    }
    public BSPMap LoadMap(string vpkLoc, string mapLoc, bool combineMeshesWithSameTextures = true, float faceLoadPercent = 1, float modelLoadPercent = 1, bool flatTextures = false, int maxTextureSize = 2048)
    {
        BSPMap.vpkLoc = vpkLoc;
        BSPMap map = new BSPMap(mapLoc);

        BSPMap.combineMeshesWithSameTexture = combineMeshesWithSameTextures;
        BSPMap.FaceLoadPercent        = faceLoadPercent;
        BSPMap.ModelLoadPercent       = modelLoadPercent;
        SourceTexture.averageTextures = flatTextures;
        SourceTexture.maxTextureSize  = maxTextureSize;

        loadingTask = UnityHelpers.TaskManagerController.RunActionAsync("Parsing Map", (cancelToken) => { map.ParseFile(cancelToken, null, () =>
            {
                if (!loadingTask.cancelled)
                {
                    UnityHelpers.TaskManagerController.RunAction(() => { map.MakeGameObject(null, (go) => { go.SetActive(true); }); });
                }
            }); });

        return(map);
    }
示例#11
0
    private void LoadMap()
    {
        map = new BSPMap(MapFileName);

        int curModelCount = 0;

        foreach (BSPModel model in map.models)
        {
            GameObject modelObj = new GameObject("model_" + curModelCount);
            modelObj.transform.parent = transform;

            int findex = 0;

            for (int f = 0; f < model.faceCount; f++)
            {
                findex = (int)model.faceIndex + f;

                BSPFace face = map.faces[findex];

                if (IgnoreTriggers && map.textures[(int)map.textureSurfaces[face.textureInfoIndex].textureIndex].name.Contains("trigger"))
                {
                    continue;
                }

                // Vertices
                Vector3[] vertices = new Vector3[face.edgeCount];

                int index = 0;

                for (int i = (int)face.edgeListIndex; i < (int)face.edgeListIndex + face.edgeCount; i++)
                {
                    if (map.edgeList[(int)face.edgeListIndex + index] < 0)
                    {
                        vertices[index] = map.vertices[map.edges[Mathf.Abs(map.edgeList[i])].startIndex];
                    }
                    else
                    {
                        vertices[index] = map.vertices[map.edges[map.edgeList[i]].endIndex];
                    }

                    index++;
                }

                // Triangles
                int[] triangles = new int[(face.edgeCount - 2) * 3];

                int step = 1;

                for (int i = 1; i < vertices.Length - 1; i++)
                {
                    triangles[step - 1] = 0;
                    triangles[step]     = i;
                    triangles[step + 1] = i + 1;
                    step += 3;
                }

                // UVs
                BSPTextureSurface textureSurface = map.textureSurfaces[face.textureInfoIndex];
                Vector2[]         uvs            = new Vector2[face.edgeCount];

                for (int i = 0; i < face.edgeCount; i++)
                {
                    uvs[i].x = ((Vector3.Dot(vertices[i], textureSurface.u) + textureSurface.uOffset) / (float)map.textures[(int)map.textureSurfaces[face.textureInfoIndex].textureIndex].width);
                    uvs[i].y = ((Vector3.Dot(vertices[i], textureSurface.v) + textureSurface.vOffset) / (float)map.textures[(int)map.textureSurfaces[face.textureInfoIndex].textureIndex].height);
                }

                // Create the mesh for the face
                GameObject faceObj = new GameObject();
                Mesh       mesh    = new Mesh();
                mesh.vertices  = vertices;
                mesh.uv        = uvs;
                mesh.triangles = triangles;
                mesh.RecalculateNormals();
                faceObj.AddComponent <MeshFilter>().mesh = mesh;
                MeshRenderer rend = faceObj.AddComponent <MeshRenderer>();

                rend.material.shader                 = Shader.Find("Unlit/Texture");
                rend.material.mainTexture            = map.textures[(int)map.textureSurfaces[face.textureInfoIndex].textureIndex].texture;
                rend.material.mainTexture.filterMode = FilterMode.Point;
                faceObj.transform.parent             = modelObj.transform;
            }

            curModelCount++;
        }
    }
示例#12
0
    public void ParseReplay()
    {
        if (port > -1)
        {
            if (gotvSocket == null)
            {
                gotvSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                gotvSocket.ReceiveTimeout = 500;
                gotvSocket.SendTimeout    = 500;
                gotvEndPoint = new IPEndPoint(IPAddress.Parse(locationToParse), port);
                gotvSocket.Connect(gotvEndPoint);

                byte[] clientMessage;
                byte[] gotvReply;

                short header          = -1;
                short protocolVersion = -1;
                int   challengeNum    = -1;

                try
                {
                    clientMessage = GetBytesUTF16("\xff\xff\xff\xff" + "qconnect" + "0x00000000" + "\x00");
                    //initialConnect = HexStringToByteArray("ffffffff" + StringToHexString("qconnect") + StringToHexString("0x00000000") + "00");
                    //initialConnect = System.Text.Encoding.ASCII.GetBytes("");
                    gotvSocket.Send(clientMessage);
                }
                catch (Exception e) { Debug.Log(e.Message); }

                try
                {
                    gotvReply = new byte[59];
                    gotvSocket.Receive(gotvReply);

                    header          = (short)gotvReply[4];
                    challengeNum    = BitConverter.ToInt32(gotvReply, 5);
                    protocolVersion = BitConverter.ToInt16(gotvReply, 42);
                    //Debug.Log("Connect Reply: " + GetStringUTF16(gotvReply));
                    Debug.Log("Header: " + header + " Challenge Number: " + challengeNum + " Protocol Version: " + protocolVersion);

                    //Debug.Log("Before BZip2: " + System.Text.Encoding.Default.GetString(gotvReply));
                    //System.IO.MemoryStream decompressed = new System.IO.MemoryStream();
                    //BZip2.Decompress(new NetworkStream(gotvSocket), decompressed, true);
                    //gotvReply = new byte[((int)decompressed.Length)];
                    //decompressed.Read(gotvReply, 0, gotvReply.Length);
                    //Debug.Log("After BZip2: " + System.Text.Encoding.Default.GetString(gotvReply));
                }
                catch (Exception e) { Debug.Log(e.Message); }

                if (challengeNum > -1)
                {
                    try
                    {
                        //clientMessage = HexStringToByteArray("ffffffff6bc734000003000000cdf23a000037423436324445443235454644424531414633323436343445423143463832463834433437453836414344344242323437464231353042453131363746353330000110aa010aa7010a0d120931363935353539383018010a0512013118030a0512013018040a0512013018050a0a1206546865204f7818060a0512013218070a0512013118080a061202363418090a0612022430180a0a05120130180b0a05120131180c0a05120133180d0a0612023634180e0a08120431323030180f0a091205383030303018100a0512013118110a0512013118120a091205302e30333118130a0512013018140a05120134181500000000000000000200000000e4011870361402002002280000005a027168f64ee8a51970361402002002fa95c3ac300000000200000004000000048648b30100000008b74e00040000006401000064000000080000001870361402002002b4050000048648b3d9005081010000005c7cbcac5cdbf3ac02001aa60100000000001e4fefdd838a1de4c1f4b33cf21e98fef558760080cc9db102a76836b8b68f78b469e2da01293a6091e290e3dd0f6bf4d2cc542e2fa687c1c2d5542b9d00d0d1d442501a51306945c05951152302ddd615362f66e2ebe6c68bfabdac0c32b416eb4e74df967f825c815f45ca9ef460c68545c4a81629a00a48c106b3dd89f98501");
                        clientMessage = GetBytesUTF16(GenerateChallengePacket(challengeNum, protocolVersion));
                        gotvSocket.Send(clientMessage);
                    }
                    catch (Exception e) { Debug.Log(e.Message); }
                }
            }
        }
        else if (!alreadyParsed)
        {
            System.IO.FileStream replayFile = new System.IO.FileStream(locationToParse, System.IO.FileMode.Open);
            demoParser               = new DemoInfo.DemoParser(replayFile);
            demoParser.TickDone     += demoParser_TickDone;
            demoParser.HeaderParsed += demoParser_HeaderParsed;
            demoParser.ParseHeader();
            demoParser.ParseToEnd();
            replayFile.Close();

            if (BSPMap.loadedMaps.ContainsKey(demoParser.Map))
            {
                demoMap = BSPMap.loadedMaps[demoParser.Map];
            }
            else
            {
                demoMap = new BSPMap(demoParser.Map);
                //Camera.main.GetComponent<ProgramInterface>().CoroutineRunner(demoMap.BuildMap);
                demoMap.BuildMap();
            }

            demoParser.Dispose();
        }
    }
示例#13
0
    public void Run()
    {
        using (globalLoadMarker.Auto())
        {
            Stopwatch s = Stopwatch.StartNew();
            lightMapPropertyId = Shader.PropertyToID(lightMapProperty);

            // Create a new BSPmap, which is an object that
            // represents the map and all its data as a whole
            using (fileLoadMarker.Auto())
            {
                if (mapIsInsidePK3)
                {
                    map = new BSPMap(mapName, true);
                }
                else
                {
                    string path = Path.Combine(Application.streamingAssetsPath, mapName);
                    map = new BSPMap(path, false);
                }

                s.Stop();
                Debug.Log($"Read map file in {s.ElapsedMilliseconds}ms");
            }

            s.Restart();
            using (facesLoadMarker.Auto())
            {
                // Each face is its own gameobject
                var groups = map.faceLump.faces.GroupBy(x => new { x.type, x.texture, x.lm_index });
                foreach (var group in groups)
                {
                    Face[] faces = group.ToArray();
                    if (faces.Length == 0)
                    {
                        continue;
                    }

                    Material mat = useRippedTextures
                        ? FetchMaterial(map.textureLump.Textures[faces[0].texture].Name, faces[0].lm_index)
                        : fallbackMaterial;

                    switch (group.Key.type)
                    {
                    case 2:
                    {
                        GenerateBezObject(mat, faces);
                        break;
                    }

                    case 1:
                    case 3:
                    {
                        GeneratePolygonObject(mat, faces);
                        break;
                    }

                    default:
                        Debug.Log(
                            $"Skipped face because it was not a polygon, mesh, or bez patch ({group.Key.type}).");
                        break;
                    }
                }

                GC.Collect();
                s.Stop();
                Debug.Log($"Loaded map in {s.ElapsedMilliseconds}ms");
            }


            vertsCache    = new List <Vector3>();
            uvCache       = new List <Vector2>();
            uv2Cache      = new List <Vector2>();
            normalsCache  = new List <Vector3>();
            indiciesCache = new List <int>();
            BezierMesh.ClearCaches();
        }
    }
 private void Start()
 {
     map = LoadMap(vpkPath, mapPath, combineMeshesWithSameTextures, faceLoadPercent, modelLoadPercent, flatTextures, maxTextureSize);
 }
示例#15
0
 private void LoadMaps(params string[] files)
 {
     foreach (string file in files)
     {
         BSPMap newMap = new BSPMap(file);
         if(!newMap.alreadyLoaded) newMap.LoadMap();
     }
 }
示例#16
0
        public override void Load()
        {
            CrosshairTex = Engine.Load <Texture>("/content/textures/gui/crosshair_default.png");
            UtilityGun UtilGun = new UtilityGun();

            Console.WriteLine("Loading map");
            Engine.Map = BSPMap.LoadMap("/content/maps/lt_test.bsp");
            Engine.Map.InitPhysics();
            Console.WriteLine("Done!");

            PlayerSpawn[] SpawnPositions = Engine.Map.GetEntities <PlayerSpawn>().ToArray();
            PlayerEnt = new Player();
            PlayerEnt.SetPosition((PlySpawnPos = SpawnPositions.Random().SpawnPosition) + new Vector3(0, 100, 0));
            PlayerEnt.Camera.LookAt(Vector3.Zero);

            PlayerEnt.SetPosition(new Vector3(-285.1535f, -964.8776f, 229.2883f));

            Engine.Map.SpawnEntity(UtilGun);
            Engine.Map.SpawnEntity(PlayerEnt);
            PlayerEnt.WeaponPickUp(UtilGun);

            /*foreach (var L in Engine.Map.GetLights())
             *      Engine.Map.RemoveEntity(L);*/

            LightEmitter = Engine.Map.GetEntities <EntPhysics>().Skip(5).First();
            Light        = new DynamicLight(Vector3.Zero, Color.Red);
            Engine.Map.SpawnEntity(Light);


            EntStatic TestEntity = new EntStatic(new libTechModel(Obj.Load("content/models/cube.obj"), Engine.GetMaterial(FogMaterial.Name)));

            TestEntity.Model.Scale = new Vector3(120);             // 20
            //DragonEnt.Model.Position = new Vector3(0, -1120, 0);
            TestEntity.Model.Position = new Vector3(0, -1000, 0);
            Engine.Map.SpawnEntity(TestEntity);

            /*
             * EntStatic TestEntity2 = new EntStatic(new libTechModel(TestEntity.Model));
             * TestEntity2.Model.Position = new Vector3(240, -1000, 0);
             * Engine.Map.SpawnEntity(TestEntity2);
             * //*/

            PlayerEnt.Camera.LookAt(TestEntity.Position);



            Engine.Camera3D.MouseMovement = true;
            Engine.Window.CaptureCursor   = true;

            Engine.Window.OnMouseMoveDelta += (Wnd, X, Y) => {
                PlayerEnt.MouseMove(new Vector2(-X, -Y));
            };

            Engine.Window.OnKey += (Wnd, Key, Scancode, Pressed, Repeat, Mods) => {
                PlayerEnt.OnKey(Key, Pressed, Mods);
                if (Key == Key.Escape && Pressed)
                {
                    Engine.Exit();
                }

                if (Key == Key.F5 && Pressed)
                {
                    RenderDoc.CaptureFrame();
                }

                if (Key == Key.F6 && Pressed)
                {
                    if (!Debugger.IsAttached)
                    {
                        Debugger.Launch();
                    }
                }
            };
        }