Exemplo n.º 1
0
        void UnsetResources()
        {
            map = null;

            mapObject = null;
            modelsObject = null;
            propsObject = null;
            dispObject = null;
            entObject = null;

            models = null;
            Props = null;
            entities = null;

            var test = Test.Inst;
            if (test != null) test.bsp = null;
        }
Exemplo n.º 2
0
        public void Load(string mapName)
        {
            if (loaded)
            {
                Debug.LogWarning("Already loaded");
                return;
            }
            LevelName = mapName;

            string path = "";

            path = ResourceManager.GetPath("maps/" + LevelName + ".bsp");

            if (path == null)
            {
                return;
            }

            BinaryReader BR = new BinaryReader(File.Open(path, FileMode.Open));

            map    = new BSPFile(BR, LevelName);
            loaded = true;

            if (uSrcSettings.Inst.entities)
            {
                ParseEntities(map.entitiesLump);
            }

            //===================================================
            mapObject          = new GameObject(LevelName);
            mapObject.isStatic = true;

            modelsObject = new GameObject("models");
            modelsObject.transform.SetParent(mapObject.transform);
            modelsObject.isStatic = true;

            if (uSrcSettings.Inst.displacements)
            {
                dispObject = new GameObject("displacements");
                dispObject.transform.SetParent(mapObject.transform);
            }

            if (uSrcSettings.Inst.props)
            {
                propsObject = new GameObject("props");
                propsObject.transform.SetParent(mapObject.transform);
                propsObject.isStatic = true;
            }

            switch (LoadType)
            {
            case Type.Full:
                Debug.Log("Start Loading World Faces");

                if (uSrcSettings.Inst.lightmaps & map.hasLightmaps)
                {
                    lightmapsData = new List <LightmapData>();
                    curLightmap   = 0;
                    lm_allocated  = new int[BLOCK_SIZE];
                    LM_InitBlock();
                }

                models = new GameObject[map.modelsLump.Length];
                for (int i = 0; i < map.modelsLump.Length; i++)
                {
                    CreateModelObject(i);
                }

                if (uSrcSettings.Inst.lightmaps & map.hasLightmaps)
                {
                    LM_UploadBlock();
                    Debug.Log("Loading " + lightmapsData.Count + " lightmap pages");
                    LightmapSettings.lightmaps = lightmapsData.ToArray();
                    lm_allocated = null;
                }
                Debug.Log("Finish World Faces");
                GC.Collect();

                if (uSrcSettings.Inst.entities)
                {
                    Debug.Log("Start Loading Entities");

                    entObject = new GameObject("entities");
                    entObject.transform.parent = mapObject.transform;

                    for (int i = 0; i < entities.Count; i++)
                    {
                        LoadEntity(i);
                    }
                    Debug.Log("Finish Entities");
                }

                if (uSrcSettings.Inst.displacements)
                {
                    for (int m = 0; m < map.modelsLump.Length; m++)
                    {
                        for (int i = map.modelsLump[m].firstface; i < map.modelsLump[m].firstface + map.modelsLump[m].numfaces; i++)
                        {
                            if (map.facesLump[i].dispinfo != -1)
                            {
                                GenerateDispFaceObject(i, m);
                            }
                        }
                    }
                    Debug.Log("Finish Displacements");
                }

                //Static props
                if (uSrcSettings.Inst.props && map.staticPropsReaded)
                {
                    Debug.Log("Start Loading Static props");
                    for (int i = 0; i < map.StaticPropCount; i++)
                    {
                        bspStaticPropLump prop = map.StaticPropLump[i];
                        //Debug.Log ("static prop "+i+" model number is ("+prop.PropType+")");
                        if (prop.PropType > map.staticPropDict.Length)
                        {
                            Debug.LogWarning("Static prop " + i + " model number is (" + prop.PropType + ")");
                            continue;
                        }
                        string modelName = map.staticPropDict[prop.PropType];
                        //Debug.Log ("static prop "+i+" model name is "+modelName);
                        GameObject go = new GameObject();
                        //GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube);
                        go.name             = "prop " + modelName;
                        go.transform.parent = propsObject.transform;

                        //GameObject testGo = (GameObject)MonoBehaviour.Instantiate(TempProp) as GameObject;
                        //testGo.transform.parent=go.transform;

                        go.transform.position = prop.Origin;
                        go.transform.rotation = Quaternion.Euler(prop.Angles);


                        SourceStudioModel tempModel = ResourceManager.Inst.GetModel(modelName);
                        if (tempModel == null)
                        {
                            //Debug.LogWarning("Error loading: "+modelName);
                            GameObject prim = GameObject.CreatePrimitive(PrimitiveType.Cube);
                            prim.transform.parent        = go.transform;
                            prim.transform.localPosition = Vector3.zero;
                        }
                        else
                        {
                            tempModel.GetInstance(go, false, 0);
                        }

                        go.isStatic = true;
                        Props.Add(go);
                    }
                    Debug.Log("Finish Static Props");
                }
                break;

            case Type.WithoutBatching:
                for (int i = 0; i < map.modelsLump.Length; i++)
                {
                    models[i] = new GameObject("*" + i);
                    models[i].transform.SetParent(modelsObject.transform);
                    for (int f = map.modelsLump[i].firstface; f < map.modelsLump[i].firstface + map.modelsLump[i].numfaces; f++)
                    {
                        GenerateFaceObject(f).transform.SetParent(models[i].transform);
                    }
                }
                break;

            case Type.OnlyDisplacements:
                if (uSrcSettings.Inst.displacements)
                {
                    for (int i = 0; i < map.dispinfoLump.Length; i++)
                    {
                        GenerateDispFaceObject((int)map.dispinfoLump[i].MapFace, 0);
                        Debug.Log("FaceId: " + map.dispinfoLump[i].MapFace + " DispInfoId: " + i +
                                  " DispVertStart: " + map.dispinfoLump[i].DispVertStart);
                    }
                }
                break;

            case Type.OneFace:
                if (uSrcSettings.Inst.displacements & map.facesLump[faceId].dispinfo != -1)
                {
                    GenerateDispFaceObject(faceId, 0);
                    Debug.Log("FaceId: " + faceId + " DispInfoId: " + map.facesLump[faceId].dispinfo +
                              " DispVertStart: " + map.dispinfoLump[map.facesLump[faceId].dispinfo].DispVertStart);
                }
                else
                {
                    GenerateFaceObject(faceId);
                }
                break;
            }

            BR.BaseStream.Dispose();
            GC.Collect();
        }
Exemplo n.º 3
0
        public void Load(string mapName)
        {
            LevelName = mapName;

            string path = "";

            path = ResourceManager.GetPath("maps/" + LevelName + ".bsp");

            if (path == null)
            {
                Debug.Log("maps/" + LevelName + ".bsp: Not Found");
                return;
            }

            BinaryReader BR = new BinaryReader(File.Open(path, FileMode.Open));

            map = new BSPFile(BR, LevelName);
            if (uSrcSettings.Inst.entities)
            {
                ParseEntities(map.entitiesLump);
            }
            //ProcessFaces();

            /*for(int i=0;i<entities.Count;i++)
             * {
             *      LoadEntity (i);
             * }*/
            //===================================================
            mapObject = new GameObject(LevelName);

            modelsObject = new GameObject("models");
            modelsObject.transform.parent = mapObject.transform;

            if (uSrcSettings.Inst.displacements)
            {
                dispObject = new GameObject("disp");
                dispObject.transform.parent = mapObject.transform;
            }

            if (uSrcSettings.Inst.props)
            {
                propsObject = new GameObject("props");
                propsObject.transform.parent = mapObject.transform;
            }

            //for (int i=0; i<modelsLump.Length; i++)
            //{
            //	BuildModelObject(i);
            //}

            if (faceId == -1)
            {
                if (uSrcSettings.Inst.lightmaps && map.hasLightmaps)
                {
                    lightmapsData = new List <LightmapData>();
                }

                for (int i = 0; i < map.modelsLump.Length; i++)
                {
                    CreateModelObject(i);
                }
                //CreateModelObject(0);
                if (uSrcSettings.Inst.lightmaps && map.hasLightmaps)
                {
                    LightmapSettings.lightmaps = lightmapsData.ToArray();
                }

                Debug.Log("Finish World Faces");

                if (uSrcSettings.Inst.entities)
                {
                    entObject = new GameObject("entities");
                    entObject.transform.parent = mapObject.transform;
                    Debug.Log("Start Loading Entities");
                    for (int i = 0; i < entities.Count; i++)
                    {
                        LoadEntity(i);
                    }
                    Debug.Log("Finish Entities");
                }

                if (uSrcSettings.Inst.displacements)
                {
                    for (int m = 0; m < map.modelsLump.Length; m++)
                    {
                        for (int i = map.modelsLump[m].firstface; i < map.modelsLump[m].firstface + map.modelsLump[m].numfaces; i++)
                        {
                            if (map.facesLump[i].dispinfo != -1)
                            {
                                GenerateDispFaceObject(i, m);
                            }
                        }
                    }
                    Debug.Log("Finish Displacements");
                }

                //Static props
                if (uSrcSettings.Inst.props && map.staticPropsReaded)
                {
                    Debug.Log("Start Loading Static props");
                    for (int i = 0; i < map.StaticPropCount; i++)
                    {
                        bspStaticPropLump prop = map.StaticPropLump[i];
                        //Debug.Log ("static prop "+i+" model number is ("+prop.PropType+")");
                        if (prop.PropType > map.staticPropDict.Length)
                        {
                            Debug.LogWarning("Static prop " + i + " model number is (" + prop.PropType + ")");
                            continue;
                        }
                        string modelName = map.staticPropDict[prop.PropType];
                        //Debug.Log ("static prop "+i+" model name is "+modelName);
                        GameObject go = new GameObject();
                        //GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube);
                        go.name             = "prop " + modelName;
                        go.transform.parent = propsObject.transform;

                        //GameObject testGo = (GameObject)MonoBehaviour.Instantiate(TempProp) as GameObject;
                        //testGo.transform.parent=go.transform;

                        go.transform.position = prop.Origin;
                        go.transform.rotation = Quaternion.Euler(prop.Angles);


                        SourceStudioModel tempModel = ResourceManager.Inst.GetModel(modelName);
                        if (tempModel == null)
                        {
                            Debug.LogWarning("Error loading: " + modelName);
                            GameObject prim = GameObject.CreatePrimitive(PrimitiveType.Cube);
                            prim.transform.parent        = go.transform;
                            prim.transform.localPosition = Vector3.zero;
                        }
                        else
                        {
                            tempModel.GetInstance(go, false, 0);
                        }

                        go.isStatic = true;
                        Props.Add(go);
                    }
                    Debug.Log("Finish Static Props");
                }
            }
            //====================================================
            else if (faceId == -2 & uSrcSettings.Inst.displacements)
            {
                for (int i = 0; i < map.dispinfoLump.Length; i++)
                {
                    GenerateDispFaceObject((int)map.dispinfoLump[i].MapFace, 0);
                    Debug.Log("FaceId: " + map.dispinfoLump[i].MapFace + " DispInfoId: " + i +
                              " DispVertStart: " + map.dispinfoLump[i].DispVertStart);
                }
            }
            else if (faceId == -3)
            {
                for (int i = 0; i < map.modelsLump.Length; i++)
                {
                    Models.Add(new GameObject("*" + i));
                    Models[i].transform.SetParent(modelsObject.transform);
                    for (int f = map.modelsLump[i].firstface; f < map.modelsLump[i].firstface + map.modelsLump[i].numfaces; f++)
                    {
                        GenerateFaceObject(f, i);
                    }
                }
            }
            else
            {
                if (uSrcSettings.Inst.displacements)
                {
                    GenerateDispFaceObject(faceId, 0);
                    Debug.Log("FaceId: " + faceId + " DispInfoId: " + map.facesLump[faceId].dispinfo +
                              " DispVertStart: " + map.dispinfoLump[map.facesLump[faceId].dispinfo].DispVertStart);
                }
                else
                {
                    GenerateFaceObject(faceId, 0);
                }
            }
            BR.BaseStream.Dispose();
        }