Ejemplo n.º 1
0
    public void BuildMap(WadFile wad, string mapname)
    {
        this.wad     = wad;
        textureTable = new TextureTable(wad.GetLump("TEXTURE1"));
        if (wad.Contains("TEXTURE2"))
        {
            textureTable.Add(wad.GetLump("TEXTURE2"));
        }
        paletteLookup  = new Palette(wad.GetLump("PLAYPAL")).GetLookupTexture();
        colormapLookup = new Colormap(wad.GetLump("COLORMAP")).GetLookupTexture();
        doomMaterial   = new Material(Shader.Find("Doom/Texture"));
        doomMaterial.SetTexture("_Palette", paletteLookup);
        doomMaterial.SetTexture("_Colormap", colormapLookup);

        skyMaterial = new Material(Shader.Find("Doom/Sky"));
        skyMaterial.SetTexture("_Palette", paletteLookup);
        skyMaterial.SetTexture("_RenderMap", GetTexture("SKY1"));


        map         = new MapData(wad, mapname);
        levelObject = new GameObject(mapname);

        unclaimedThings = new List <int>();
        for (int i = 0; i < map.things.Count; i++)
        {
            unclaimedThings.Add(i);
        }
        thingSectors = new Dictionary <int, Sector>();

        for (int i = 0; i < map.linedefs.Count; i++)
        {
            //Debug.Log(i);
            BuildLine(i);
        }


        for (int i = 0; i < map.sectors.Count; i++)
        {
            //Debug.Log(i);
            BuildSector(i);
        }

        // BuildSector(24);

        levelObject.transform.localScale = new Vector3(SCALE, SCALE * 1.2f, SCALE);

        GameObject player      = new GameObject("Player");
        int        playerIndex = 0;

        for (int i = 0; i < map.things.Count; i++)
        {
            if (map.things[i].type == 1)
            {
                playerIndex = i;
                break;
            }
        }
    }
Ejemplo n.º 2
0
    public void BuildMap(WadFile wad, string mapname, bool benchmark = false)
    {
        this.benchmark = benchmark;
        this.wad       = wad;
        textureTable   = wad.textureTable;

        // Graphics setup. TODO: Move this to DoomGraphic, or somewhere else graphic related.
        paletteLookup  = new Palette(wad.GetLump("PLAYPAL")).GetLookupTexture();
        colormapLookup = new Colormap(wad.GetLump("COLORMAP")).GetLookupTexture();

        doomMaterial = new Material(Shader.Find("Doom/Texture"));
        doomMaterial.SetTexture("_Palette", paletteLookup);
        doomMaterial.SetTexture("_Colormap", colormapLookup);

        pngMaterial = new Material(Shader.Find("Doom/Unlit Truecolor Texture"));

        skyMaterial = new Material(Shader.Find("Doom/Sky"));
        skyMaterial.SetTexture("_Palette", paletteLookup);
        skyMaterial.SetTexture("_RenderMap", GetTexture(skyName));

        spriteMaterial = new Material(Shader.Find("Doom/Texture"));
        spriteMaterial.SetTexture("_Palette", paletteLookup);
        spriteMaterial.SetTexture("_Colormap", colormapLookup);

        map = MapData.Load(wad, mapname);
        if (map == null)
        {
            throw new Exception("Loading map failed.");
        }

        st           = new SectorTriangulation(map, benchmark);
        levelObject  = new GameObject(mapname);
        geoObject    = new GameObject("Geometry");
        thingsObject = new GameObject("Things");
        geoObject.transform.SetParent(levelObject.transform);
        thingsObject.transform.SetParent(levelObject.transform);

        // Build thing information
        unclaimedThings = new List <int>();
        for (int i = 0; i < map.things.Length; i++)
        {
            unclaimedThings.Add(i);
        }
        thingSectors = new Dictionary <int, Sector>();

        CoroutineRunner cr = levelObject.AddComponent <CoroutineRunner>();

        cr.dmb      = this;
        cr.map      = map;
        linesDone   = false;
        sectorsDone = false;

        cr.StartCoroutine(cr.BuildLines());
        cr.StartCoroutine(cr.BuildSectors());

        levelObject.transform.localScale = new Vector3(SCALE, SCALE * 1.2f, SCALE);
    }
Ejemplo n.º 3
0
    public static Texture2D BuildTexture(string name, WadFile wad, TextureTable textures)
    {
        if (textureCache == null)
        {
            textureCache = new Dictionary <string, Texture2D>();
        }

        if (textureCache.ContainsKey(name))
        {
            return(textureCache[name]);
        }

        PatchTable pnames = new PatchTable(wad.GetLump("PNAMES"));

        DoomTexture texture = textures.Get(name.ToUpper());


        Texture2D output = new Texture2D(texture.width, texture.height, TextureFormat.RGBA32, false, true);

        for (int i = 0; i < texture.patches.Count; i++)
        {
            DoomPatch p       = texture.patches[i];
            Texture2D patch2d = DoomGraphic.BuildPatch(p.patchIndex, pnames, wad);

            if (patch2d == null)
            {
                return(null);
            }

            int copyX = (p.originX < 0)?-p.originX:0;
            int copyY = (p.originY < 0)?-p.originY:0;

            int pasteX = (p.originX > 0)?p.originX:0;
            int pasteY = (p.originY > 0)?p.originY:0;

            int copyWidth = patch2d.width - copyX;
            if (copyWidth > output.width - pasteX)
            {
                copyWidth = output.width - pasteX;
            }

            int copyHeight = patch2d.height - copyY;
            if (copyHeight > output.height - pasteY)
            {
                copyHeight = output.height - pasteY;
            }

            for (int a = 0; a < copyWidth; a++)
            {
                for (int b = 0; b < copyHeight; b++)
                {
                    Color col = patch2d.GetPixel(copyX + a, copyY + b);
                    if (col.a != 0f)
                    {
                        output.SetPixel(pasteX + a, pasteY + b, col);
                    }
                }
            }
        }

        output.Apply();
        output.wrapMode   = TextureWrapMode.Repeat;
        output.filterMode = FilterMode.Point;

        textureCache.Add(name, output);

        return(output);
    }
Ejemplo n.º 4
0
    public static Texture2D BuildTexture(string name, WadFile wad)
    {
        TextureTable textures = new TextureTable(wad.GetLump("TEXTURE1"));

        return(BuildTexture(name, wad, textures));
    }