Ejemplo n.º 1
0
    public IEnumerator Load(string mapname, Action <string, string, object> callback)
    {
        Progress = 0;

        RSW      world    = LoadWorld(mapname, callback);
        Altitude altitude = LoadAltitude(mapname, callback);
        GND      ground   = LoadGround(mapname, world, callback);

        yield return(LoadModels(mapname, world.modelDescriptors, callback));
    }
Ejemplo n.º 2
0
    private RSW LoadWorld(string mapname, Action <string, string, object> callback)
    {
        // Load RSW
        string rswPath = "data/" + GetFilePath(mapname);
        RSW    world   = FileManager.Load(rswPath) as RSW;

        if (world == null)
        {
            throw new Exception("Could not load rsw for " + mapname);
        }

        Progress += 1;
        callback.Invoke(mapname, "MAP_WORLD", world);

        return(world);
    }
Ejemplo n.º 3
0
    private GND LoadGround(string mapname, RSW world, Action <string, string, object> callback)
    {
        string gndPath = "data/" + GetFilePath(WorldLoader.files.gnd);
        GND    ground  = FileManager.Load(gndPath) as GND;

        if (ground == null)
        {
            throw new Exception("Could not load gnd for " + mapname);
        }

        GND.Mesh compiledGround = GroundLoader.Compile(ground, world.water.level, world.water.waveHeight);
        LoadGroundTexture(world, compiledGround);

        Progress += 1;
        callback.Invoke(mapname, "MAP_GROUND", compiledGround);

        return(ground);
    }
Ejemplo n.º 4
0
    private void LoadGroundTexture(RSW world, GND.Mesh ground)
    {
        LinkedList <string> textures = new LinkedList <string>();

        FileManager.InitBatch();

        //queue water textures
        if (ground.waterVertCount > 0)
        {
            var path = "data/texture/\xbf\xf6\xc5\xcd/water" + world.water.type;
            for (int i = 0; i < 32; i++)
            {
                string num = (i < 10) ? ("0" + i) : ("" + i);
                textures.AddLast(path + num + ".jpg");
                FileManager.Load(textures.Last.Value);
            }
        }

        //queue ground textures
        for (int i = 0; i < ground.textures.Length; i++)
        {
            textures.AddLast("data/texture/" + ground.textures[i]);
            FileManager.Load(textures.Last.Value);
        }

        FileManager.EndBatch();

        //splice water textures from ground textures
        List <string> waterTextures = new List <string>();

        if (ground.waterVertCount > 0)
        {
            for (int i = 0; i < 32; i++)
            {
                waterTextures.Add(textures.First.Value);
                textures.RemoveFirst();
            }
        }

        waterTextures.CopyTo(world.water.images);
        ground.textures = new string[textures.Count];
        textures.CopyTo(ground.textures, 0);
    }
Ejemplo n.º 5
0
    public void Load(string mapname, Action <string, string, object> callback)
    {
        Progress = 0;

        // Load RSW
        string rswPath = "data/" + GetFilePath(mapname);
        RSW    world   = FileManager.Load(rswPath) as RSW;

        if (world == null)
        {
            throw new Exception("Could not load rsw for " + mapname);
        }

        // Load GAT
        string   gatPath  = "data/" + GetFilePath(WorldLoader.files.gat);
        Altitude altitude = FileManager.Load(gatPath) as Altitude;

        if (altitude == null)
        {
            throw new Exception("Could not load gat for " + mapname);
        }
        callback.Invoke(mapname, "MAP_ALTITUDE", altitude);

        // Load GND
        string gndPath = "data/" + GetFilePath(WorldLoader.files.gnd);
        GND    ground  = FileManager.Load(gndPath) as GND;

        if (ground == null)
        {
            throw new Exception("Could not load gnd for " + mapname);
        }

        var compiledGround = GroundLoader.Compile(ground, world.water.level, world.water.waveHeight);

        LoadGroundTexture(world, compiledGround);

        callback.Invoke(mapname, "MAP_WORLD", world);
        callback.Invoke(mapname, "MAP_GROUND", compiledGround);

        var compiledModels = LoadModels(world.modelDescriptors, ground);

        callback.Invoke(mapname, "MAP_MODELS", compiledModels);
    }
Ejemplo n.º 6
0
    public void Clear()
    {
        sounds.Clear();
        if (sky != null)
        {
            sky.Clear();
        }

        world  = null;
        water  = null;
        models = null;
        sky    = null;

        //destroy map
        if (mapParent != null)
        {
            UnityEngine.Object.Destroy(mapParent);
            mapParent = null;
        }

        //destroy textures
        var ob     = UnityEngine.Object.FindObjectsOfType(typeof(Texture2D));
        int dCount = 0;

        foreach (Texture2D t in ob)
        {
            if (t.name.StartsWith("maptexture@"))
            {
                dCount++;
                UnityEngine.Object.Destroy(t);
            }
        }
        Debug.Log(dCount + " textures destroyed");

        worldCompleted = altitudeCompleted = groundCompleted = modelsCompleted = false;
    }
Ejemplo n.º 7
0
    /// <summary>
    /// receive parsed world
    /// </summary>
    /// <param name="world"></param>
    private void OnWorldComplete(RSW world)
    {
        this.world = world;

        //calculate light direction
        RSW.LightInfo lightInfo = world.light;
        lightInfo.direction = new Vector3();

        Vector3 lightRotation = new Vector3(lightInfo.longitude, lightInfo.latitude, 0);

        WorldLight.transform.rotation = Quaternion.identity;
        WorldLight.transform.Rotate(lightRotation);

        Color ambient = new Color(lightInfo.ambient[0], lightInfo.ambient[1], lightInfo.ambient[2]);
        Color diffuse = new Color(lightInfo.diffuse[0], lightInfo.diffuse[1], lightInfo.diffuse[2]);

        RenderSettings.ambientMode  = UnityEngine.Rendering.AmbientMode.Flat;
        RenderSettings.ambientLight = ambient * lightInfo.intensity;

        Debug.Log("diffuse: " + diffuse);
        WorldLight.color = diffuse;

        worldCompleted = true;
    }
Ejemplo n.º 8
0
    public static RSW Load(BinaryReader data)
    {
        //read header
        string header     = data.ReadBinaryString(4);
        string version    = Convert.ToString(data.ReadByte());
        string subversion = Convert.ToString(data.ReadByte());

        version += "." + subversion;
        double dversion = double.Parse(version, CultureInfo.InvariantCulture);

        //check for valid .rsw file
        if (!string.Equals(header, RSW.Header))
        {
            throw new Exception("WorldLoader.Load: Header (" + header + ") is not \"GRSW\"");
        }

        RSW rsw = new RSW(version);

        //read sub files
        files.ini = data.ReadBinaryString(40);
        files.gnd = data.ReadBinaryString(40);
        files.gat = data.ReadBinaryString(40);

        if (dversion >= 1.4)
        {
            files.src = data.ReadBinaryString(40);
        }

        //read water info
        if (dversion >= 1.3)
        {
            rsw.water.level = data.ReadFloat() / 5;

            if (dversion >= 1.8)
            {
                rsw.water.type       = data.ReadLong();
                rsw.water.waveHeight = data.ReadFloat() / 5;
                rsw.water.waveSpeed  = data.ReadFloat();
                rsw.water.wavePitch  = data.ReadFloat();

                if (dversion >= 1.9)
                {
                    rsw.water.animSpeed = data.ReadLong();
                }
            }
        }

        //read lightmap
        if (dversion >= 1.5)
        {
            rsw.light.longitude = data.ReadLong();
            rsw.light.latitude  = data.ReadLong();
            for (int i = 0; i < 3; i++)
            {
                rsw.light.diffuse[i] = data.ReadFloat();
            }
            for (int i = 0; i < 3; i++)
            {
                rsw.light.ambient[i] = data.ReadFloat();
            }

            if (dversion >= 1.7)
            {
                rsw.light.intensity = data.ReadFloat();
            }
        }

        // Read ground
        if (dversion >= 1.6)
        {
            rsw.ground.top    = data.ReadLong();
            rsw.ground.bottom = data.ReadLong();
            rsw.ground.left   = data.ReadLong();
            rsw.ground.right  = data.ReadLong();
        }

        // Read Object
        int count   = data.ReadLong();
        var models  = rsw.modelDescriptors = new List <RSW.ModelDescriptor>(count);
        var lights  = rsw.lights = new List <RSW.Light>(count);
        var sounds  = rsw.sounds = new List <RSW.Sound>(count);
        var effects = rsw.effects = new List <RSW.Effect>(count);

        for (int i = 0; i < count; i++)
        {
            switch (data.ReadLong())
            {
            case 1:     //load model
                var model = new RSW.ModelDescriptor();
                model.name      = dversion >= 1.3 ? data.ReadBinaryString(40) : null;
                model.animType  = dversion >= 1.3 ? data.ReadLong() : 0;
                model.animSpeed = dversion >= 1.3 ? data.ReadFloat() : 0f;
                model.blockType = dversion >= 1.3 ? data.ReadLong() : 0;
                model.filename  = data.ReadBinaryString(80);
                model.nodename  = data.ReadBinaryString(80);
                model.position  = new float[3];
                for (int j = 0; j < model.position.Length; j++)
                {
                    model.position[j] = data.ReadFloat() / 5;
                }
                model.rotation = new float[3];
                for (int j = 0; j < model.rotation.Length; j++)
                {
                    model.rotation[j] = data.ReadFloat();
                }
                model.scale = new float[3];
                for (int j = 0; j < model.scale.Length; j++)
                {
                    model.scale[j] = data.ReadFloat() / 5;
                }
                models.Add(model);
                continue;

            case 2:     //load light
                var light = new RSW.Light();
                light.name = data.ReadBinaryString(80);
                light.pos  = new float[3];
                for (int j = 0; j < light.pos.Length; j++)
                {
                    light.pos[j] = data.ReadFloat() / 5;
                }
                light.color = new float[3];
                for (int j = 0; j < light.color.Length; j++)
                {
                    light.color[j] = data.ReadFloat();
                }
                light.range = data.ReadFloat();
                lights.Add(light);
                continue;

            case 3:     //load sound
                var sound = new RSW.Sound();
                sound.name = data.ReadBinaryString(80);
                sound.file = "data/wav/" + data.ReadBinaryString(80);
                sound.pos  = new float[3];
                for (int j = 0; j < sound.pos.Length; j++)
                {
                    sound.pos[j] = data.ReadFloat() / 5;
                }
                sound.vol    = data.ReadFloat();
                sound.width  = data.ReadLong();
                sound.height = data.ReadLong();
                sound.range  = data.ReadFloat();
                sound.cycle  = dversion >= 2.0 ? data.ReadFloat() : 0f;
                sounds.Add(sound);
                continue;

            case 4:     //load effect
                var effect = new RSW.Effect();
                effect.name = data.ReadBinaryString(80);
                effect.pos  = new float[3];
                for (int j = 0; j < effect.pos.Length; j++)
                {
                    effect.pos[j] = data.ReadFloat() / 5;
                }
                effect.id    = data.ReadLong();
                effect.delay = data.ReadFloat() * 10;
                effect.param = new float[4];
                for (int j = 0; j < effect.param.Length; j++)
                {
                    effect.param[j] = data.ReadFloat();
                }
                effects.Add(effect);
                continue;
            }
        }

        models.TrimExcess();
        sounds.TrimExcess();
        lights.TrimExcess();
        effects.TrimExcess();

        return(rsw);
    }