Simplest way to encode/decode levels

Subscribe to Simplest way to encode/decode levels 59 posts

avatar for RTL_Shadow RTL_Shadow 1020 posts
Flag Post

Currently I have a “level1.txt” file with this in it:

1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1
|1|-1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1
|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1
|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1
|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1
|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1
|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1
|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1
|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1
|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1
|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1
|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1
|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1
|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1
|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1
|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1
|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1
|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1
|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1
|1|1|1|1|1|1|1|1|1|2|2|2|2|2|2|2|1|1|1|1

In my Tile-Based game/engine I’d just load this and splice it into a vector, then use a little math and place tiles on the stage. That’s not the problem. Is there an easier way for me to encode this long string into something smaller? Awhile ago I saw someone in a similar situation and he could encode it into a string like “4asd94jas9043/asdzzdnja7360/” or some stuff. Any ideas?

 
avatar for qwerber qwerber 4717 posts
Flag Post

depends on how many tile types you have. If you only have two, blank and solid, then you can store 8 tiles into a single character, since 1 character is 8 bits. Other compression algorithms include using a specific pattern to indicate repeating tiles. the tiles can be stored as a1 dimensional string, with a map width included.

 
avatar for RTL_Shadow RTL_Shadow 1020 posts
Flag Post
Originally posted by qwerber:

depends on how many tile types you have. If you only have two, blank and solid, then you can store 8 tiles into a single character, since 1 character is 8 bits. Other compression algorithms include using a specific pattern to indicate repeating tiles. the tiles can be stored as a1 dimensional string, with a map width included.

Well I’m just kind of interested in shortening the length of the 1’s and 0’s in it, because when I add a level editor I’d prefer a shorter string instead of that big, raw, one.

 
avatar for qwerber qwerber 4717 posts
Flag Post

exactly, instead of something like 1|0|0|1|0|0|1|0 you can just use one character : �

 
avatar for RTL_Shadow RTL_Shadow 1020 posts
Flag Post
Originally posted by qwerber:

exactly, instead of something like 1|0|0|1|0|0|1|0 you can just use one character : �

That showed up as a ? but i think I understand. How would I go about doing this if there were 32 possible tiles?

 
avatar for qwerber qwerber 4717 posts
Flag Post

and 1|0|0|1|0|0|1|0|0|1|0|0|1|1|0|1 would be
�M

with 32 possible tiles, you need to think; how many bits do i need to contain the number 31?

Edit: It is supposed to show up as ?
Edit(2): you need 5 bits to store each of 32 different tiles, so you need to use 5 characters to store 8 tiles.

 
avatar for RTL_Shadow RTL_Shadow 1020 posts
Flag Post
Originally posted by qwerber:

and 1|0|0|1|0|0|1|0|0|1|0|0|1|1|0|1 would be
�M

with 32 possible tiles, you need to think; how many bits do i need to contain the number 31?

Edit: It is supposed to show up as ?

Only… 5? Correct?
edit: ninjad.
edit2: Alright well I’ll stick with 4 bits for now, because chances are I’ll only need 16 or less.

How would I go about encoding it then, now?

 
avatar for qwerber qwerber 4717 posts
Flag Post
Originally posted by RTL_Shadow:
Originally posted by qwerber:

and 1|0|0|1|0|0|1|0|0|1|0|0|1|1|0|1 would be
�M

with 32 possible tiles, you need to think; how many bits do i need to contain the number 31?

Edit: It is supposed to show up as ?

Only… 5? Correct?
edit: ninjad.
edit2: Alright well I’ll stick with 4 bits for now, because chances are I’ll only need 16 or less.

How would I go about encoding it then, now?

yeah, basically, I’d use 1 byte for the freedom of extending it, then compress the string. Encoding use a byte array with bit shifting.

 
avatar for RTL_Shadow RTL_Shadow 1020 posts
Flag Post

Sorry for being dumb, but two things:

Compress the string, in what way? And when you say byte array with bit shifting you might need to explain to me because I don’t really deal with byte arrays too much.

 
avatar for qwerber qwerber 4717 posts
Flag Post

You’d want to write the data string to a byte array, then compress it using ByteArray::deflate.

for writing 4bit tile types you want to get the integer values of 2 adjacent tiles you want to write, for example 1 and 3, which is 00000000000000000000000000000001 and 00000000000000000000000000000011 you want to turn than into 00000000000000000000000000010011 so you take the first number and shift that to the left 4 spaces, which is 1<<4. Basically for every 2 tiles m and n do value = m << 4 + n. Then you do ByteArray::writeByte(value).

 
avatar for RTL_Shadow RTL_Shadow 1020 posts
Flag Post

Wait, couldn’t I just do levTxt.deflate() to encode, and inflate() to decode?

 
avatar for BobTheCoolGuy BobTheCoolGuy 3752 posts
Flag Post
Originally posted by RTL_Shadow:

Wait, couldn’t I just do levTxt.deflate() to encode, and inflate() to decode?

You can’t deflate a String. You can write the String to a ByteArray and deflate it which would work well.

 
avatar for qwerber qwerber 4717 posts
Flag Post
Originally posted by BobTheCoolGuy:
Originally posted by RTL_Shadow:

Wait, couldn’t I just do levTxt.deflate() to encode, and inflate() to decode?

You can’t deflate a String. You can write the String to a ByteArray and deflate it which would work well.

If you deflate the string you posted in the first post it would be 4 times larger than deflating the string produced with my method.

 
avatar for RTL_Shadow RTL_Shadow 1020 posts
Flag Post
Originally posted by BobTheCoolGuy:
Originally posted by RTL_Shadow:

Wait, couldn’t I just do levTxt.deflate() to encode, and inflate() to decode?

You can’t deflate a String. You can write the String to a ByteArray and deflate it which would work well.

Would I have a problem with showing up the ? with the square? (What shows up when a font is not available)

 
avatar for UnknownGuardian UnknownGuardian 8131 posts
Flag Post
Ignoring the simple part... Generated levels for Ninja Sequence looked like this:
public static const LEVEL_1:String = "7dbBCoAgDADQH5JoJFH/5sdHt04RqYH00JOH5xxjLkqJNcVe5tRpTWQyuVaO5W43u+PBUTN7Ro9Ld6/Bd49g1/UVrZbccBkryWRyRzmfn1i3mFvK+epugwT9lTxG2UUeMOisc5DNjPJMJpPJZDKZbGKUZzKZTCaTyeSfTIwH";
public static const LEVEL_2:String = "7dZRCoAgEAXAC0m0ZXQ5D98B+kjMpGLQX8d1RXxRyrKnWMqcHhoTmUy+I8faMpv3uiqUzWbXLhzwPCvOxPYRvUAWM8lk8iA5cmc6dy46u8IPy1k3hsmxdafjNDRaZiSTyWQymUwmS4z6TCaTyWQymfy3xHgA";
public static const LEVEL_3:String = "7dY7DoAgDADQCxlj4yfxbhzezcFFQUlEX8oCwytpCmmkFEsXaxq6StGTyeR7coyFqzDZ+W3Z7dkXN2/V9/2xtf9Zm7znX5jHN0yuFEZOMpnckDxlnqvzf+SYchrikUvHXIWOPXQH2cxIJpPJZDKZTDYxqjOZTCaTyWTydybGDQ==";
public static const LEVEL_4:String = "7dZNCsMgEAbQC4WSaW2gd/Pw3ZUujJTo9I/HuHHzBj+Dmaj1fFu2ui5JdSKPynFprMkNdjb/bDdj7ayxVofOxGa/yZ7wyHQ7dMEJ+MpuXWUOP/7H672tUxoYMH5GNnySE+Qo4niq702j+KDJH5aLNBLluKbQ8ShBmxnlTCaTyWQymUw2MZLJZDKZTCaTX58Y7w==";
public static const LEVEL_5:String = "7dZLCoAwDAXAC4kYrbfr4d268YO1FXVId4VJSCm8yDnmbkx56CpV316O6fq51O3MuGz2F+z9L3NTh+Obv+r1d7/B0On0e5JHcZ83prLiyrZBLpeTbZDJ5Efl1Gjm5AUrybG92pgrTB2r8oYyI5lMJpPJZDJZYiSTyWQymUwmt0iMCw==";
public static const LEVEL_6:String = "7dZBCoAgEIXhC0nMI4sO5+HbBS2ixBlk4mdcufiUcYSn1nQU7c1KUC3IPbLW9+VySsc2tqN981Lj36bS4/rpdEuLu/XlcTp8TrDI61v0zFvgj8WeZZNfBooEiuwgV7qRVq50Y6pch2XxhMhzZW0htK6i0WRGZGRkZGRkZGRkEiMyMjIyMjIyMvI/EuMJ";



There are 3 parts below. 1) 2 functions for encoding/decoding strings. 1 encoding class (separate .as file) 1 decoding class (separate .as file)
private function compressBase64ByteArray(s:String):String
{
	var b:ByteArray = new ByteArray();
	
	b.writeUTFBytes(s);
	b.deflate();
	
	var e:Base64Encoder = new Base64Encoder();
	e.encodeBytes(b);
	return e.toString();
}
private function uncompressBase64ByteArray(s:String):String
{
	var e:Base64Decoder = new Base64Decoder();
	e.decode(s);
	var b:ByteArray = e.toByteArray();
	b.inflate();
	return b.readUTFBytes(b.length);
}








//BASE 64 ENCODER
////////////////////////////////////////////////////////////////////////////////
//
//  ADOBE SYSTEMS INCORPORATED
//  Copyright 2004-2007 Adobe Systems Incorporated
//  All Rights Reserved.
//
//  NOTICE: Adobe permits you to use, modify, and distribute this file
//  in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////

package 
{

import flash.utils.ByteArray;

/**
 * A utility class to encode a String or ByteArray as a Base64 encoded String.
 *  
 *  @langversion 3.0
 *  @playerversion Flash 9
 *  @playerversion AIR 1.1
 *  @productversion Flex 3
 */
public class Base64Encoder
{
    //--------------------------------------------------------------------------
    //
    //  Static Class Variables
    //
    //--------------------------------------------------------------------------

    /**
     *  Constant definition for the string "UTF-8".
     *  
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public static const CHARSET_UTF_8:String = "UTF-8";

    /**
     * The character codepoint to be inserted into the encoded output to
     * denote a new line if insertNewLines is true.
     * 
     * The default is 10 to represent the line feed \n.
     *  
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public static var newLine:int = 10;

    //--------------------------------------------------------------------------
    //
    //  Constructor
    //
    //--------------------------------------------------------------------------

    /**
     * Constructor.
     *  
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public function Base64Encoder()
    {
        super();
        reset();
    }

    //--------------------------------------------------------------------------
    //
    //  Variables
    //
    //--------------------------------------------------------------------------

    /**
     * A Boolean flag to control whether the sequence of characters specified
     * for Base64Encoder.newLine are inserted every 76 characters
     * to wrap the encoded output.
     * 
     * The default is true.
     *  
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public var insertNewLines:Boolean = true;

    //--------------------------------------------------------------------------
    //
    //  Public Methods
    //
    //--------------------------------------------------------------------------

    /**
     * @private
     */
    public function drain():String
    {
        var result:String = "";

        for (var i:uint = 0; i < _buffers.length; i++)
        {
            var buffer:Array = _buffers[i] as Array;
            result += String.fromCharCode.apply(null, buffer);
        }

        _buffers = [];
        _buffers.push([]);

        return result;
    }

    /**
     * Encodes the characters of a String in Base64 and adds the result to
     * an internal buffer. Subsequent calls to this method add on to the
     * internal buffer. After all data have been encoded, call
     * toString() to obtain a Base64 encoded String.
     * 
     * @param data The String to encode.
     * @param offset The character position from which to start encoding.
     * @param length The number of characters to encode from the offset.
     *  
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public function encode(data:String, offset:uint=0, length:uint=0):void
    {
        if (length == 0)
            length = data.length;

        var currentIndex:uint = offset;

        var endIndex:uint = offset + length;
        if (endIndex > data.length)
            endIndex = data.length;

        while (currentIndex < endIndex)
        {
            _work[_count] = data.charCodeAt(currentIndex);
            _count++;

            if (_count == _work.length || endIndex - currentIndex == 1)
            {
                encodeBlock();
                _count = 0;
                _work[0] = 0;
                _work[1] = 0;
                _work[2] = 0;
            }
            currentIndex++;
        }
    }

    /**
     * Encodes the UTF-8 bytes of a String in Base64 and adds the result to an
     * internal buffer. The UTF-8 information does not contain a length prefix. 
     * Subsequent calls to this method add on to the internal buffer. After all
     * data have been encoded, call toString() to obtain a Base64
     * encoded String.
     * 
     * @param data The String to encode.
     *  
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public function encodeUTFBytes(data:String):void
    {
        var bytes:ByteArray = new ByteArray();
        bytes.writeUTFBytes(data);
        bytes.position = 0;
        encodeBytes(bytes);
    }

    /**
     * Encodes a ByteArray in Base64 and adds the result to an internal buffer.
     * Subsequent calls to this method add on to the internal buffer. After all
     * data have been encoded, call toString() to obtain a
     * Base64 encoded String.
     * 
     * @param data The ByteArray to encode.
     * @param offset The index from which to start encoding.
     * @param length The number of bytes to encode from the offset.
     *  
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public function encodeBytes(data:ByteArray, offset:uint=0, length:uint=0):void
    {
        if (length == 0)
            length = data.length;

        var oldPosition:uint = data.position;
        data.position = offset;
        var currentIndex:uint = offset;

        var endIndex:uint = offset + length;
        if (endIndex > data.length)
            endIndex = data.length;

        while (currentIndex < endIndex)
        {
            _work[_count] = data[currentIndex];
            _count++;

            if (_count == _work.length || endIndex - currentIndex == 1)
            {
                encodeBlock();
                _count = 0;
                _work[0] = 0;
                _work[1] = 0;
                _work[2] = 0;
            }
            currentIndex++;
        }

        data.position = oldPosition;
    }

    /**
     * @private
     */
    public function flush():String
    {
        if (_count > 0)
            encodeBlock();

        var result:String = drain();
        reset();
        return result;
    }

    /**
     * Clears all buffers and resets the encoder to its initial state.
     *  
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public function reset():void
    {
        _buffers = [];
        _buffers.push([]);
        _count = 0;
        _line = 0;
        _work[0] = 0;
        _work[1] = 0;
        _work[2] = 0;
    }

    /**
     * Returns the current buffer as a Base64 encoded String. Note that
     * calling this method also clears the buffer and resets the 
     * encoder to its initial state.
     * 
     * @return The Base64 encoded String.
     *  
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public function toString():String
    {
        return flush();
    }

    //--------------------------------------------------------------------------
    //
    //  Private Methods
    //
    //--------------------------------------------------------------------------

    /**
     * @private
     */
    private function encodeBlock():void
    {
        var currentBuffer:Array = _buffers[_buffers.length - 1] as Array;
        if (currentBuffer.length >= MAX_BUFFER_SIZE)
        {
            currentBuffer = [];
            _buffers.push(currentBuffer);
        }

        currentBuffer.push(ALPHABET_CHAR_CODES[(_work[0] & 0xFF) >> 2]);
        currentBuffer.push(ALPHABET_CHAR_CODES[((_work[0] & 0x03) << 4) | ((_work[1] & 0xF0) >> 4)]);

        if (_count > 1)
            currentBuffer.push(ALPHABET_CHAR_CODES[((_work[1] & 0x0F) << 2) | ((_work[2] & 0xC0) >> 6) ]);
        else
            currentBuffer.push(ESCAPE_CHAR_CODE);

        if (_count > 2)
            currentBuffer.push(ALPHABET_CHAR_CODES[_work[2] & 0x3F]);
        else
            currentBuffer.push(ESCAPE_CHAR_CODE);

        if (insertNewLines)
        {
            if ((_line += 4) == 76)
            {
                currentBuffer.push(newLine);
                _line = 0;
            }
        }
    }

    //--------------------------------------------------------------------------
    //
    //  Private Variables
    //
    //--------------------------------------------------------------------------

    /**
     * An Array of buffer Arrays.
     *  
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    private var _buffers:Array;
    private var _count:uint;
    private var _line:uint;
    private var _work:Array = [ 0, 0, 0 ];

    /**
     * This value represents a safe number of characters (i.e. arguments) that
     * can be passed to String.fromCharCode.apply() without exceeding the AVM+
     * stack limit.
     * 
     * @private
     */
    public static const MAX_BUFFER_SIZE:uint = 32767;

    private static const ESCAPE_CHAR_CODE:Number = 61; // The '=' char

    /*
        'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
        'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
        'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
        'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
        'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
        'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
        'w', 'x', 'y', 'z', '0', '1', '2', '3',
        '4', '5', '6', '7', '8', '9', '+', '/'
    */
    private static const ALPHABET_CHAR_CODES:Array =
    [
        65,   66,  67,  68,  69,  70,  71,  72,
        73,   74,  75,  76,  77,  78,  79,  80,
        81,   82,  83,  84,  85,  86,  87,  88,
        89,   90,  97,  98,  99, 100, 101, 102,
        103, 104, 105, 106, 107, 108, 109, 110,
        111, 112, 113, 114, 115, 116, 117, 118,
        119, 120, 121, 122,  48,  49,  50,  51,
        52,   53,  54,  55,  56,  57,  43,  47
    ];

}

}













//BASE 64 DECODER
////////////////////////////////////////////////////////////////////////////////
//
//  ADOBE SYSTEMS INCORPORATED
//  Copyright 2006-2007 Adobe Systems Incorporated
//  All Rights Reserved.
//
//  NOTICE: Adobe permits you to use, modify, and distribute this file
//  in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////

package
{

import flash.utils.ByteArray;

[ResourceBundle("utils")]

/**
 * A utility class to decode a Base64 encoded String to a ByteArray.
 *  
 *  @langversion 3.0
 *  @playerversion Flash 9
 *  @playerversion AIR 1.1
 *  @productversion Flex 3
 */
public class Base64Decoder
{
	//--------------------------------------------------------------------------
	//
	//  Constructor
	//
	//--------------------------------------------------------------------------

    /**
     * Constructor.
     *  
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public function Base64Decoder()
    {
        super();
        data = new ByteArray();
    }

	//--------------------------------------------------------------------------
	//
	//  Methods
	//
	//--------------------------------------------------------------------------

    /**
     * Decodes a Base64 encoded String and adds the result to an internal
     * buffer. Subsequent calls to this method add on to the internal
     * buffer. After all data have been encoded, call toByteArray()
     * to obtain a decoded flash.utils.ByteArray.
     * 
     * @param encoded The Base64 encoded String to decode.
     *  
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public function decode(encoded:String):void
    {
        for (var i:uint = 0; i < encoded.length; ++i)
        {
            var c:Number = encoded.charCodeAt(i);

            if (c == ESCAPE_CHAR_CODE)
                work[count++] = -1;
            else if (inverse[c] != 64)
                work[count++] = inverse[c];
            else
                continue;

            if (count == 4)
            {
                count = 0;
                data.writeByte((work[0] << 2) | ((work[1] & 0xFF) >> 4));
                filled++;

                if (work[2] == -1)
                    break;

                data.writeByte((work[1] << 4) | ((work[2] & 0xFF) >> 2));
                filled++;

                if (work[3] == -1)
                    break;

                data.writeByte((work[2] << 6) | work[3]);
                filled++;
            }
        }
    }

    /**
     * @private
     */
    public function drain():ByteArray
    {
        var result:ByteArray = new ByteArray();

		var oldPosition:uint = data.position;	 
		data.position = 0;	// technically, shouldn't need to set this, but carrying over from previous implementation
		result.writeBytes(data, 0, data.length);		
		data.position = oldPosition;
		result.position = 0;
		
        filled = 0;
        return result;
    }

    /**
     * @private
     */
    public function flush():ByteArray
    {
        if (count > 0)
        {
        	//var message:String = resourceManager.getString("utils", "partialBlockDropped", [ count ]);
            //throw new Error(message);
        }
        return drain();
    }

    /**
     * Clears all buffers and resets the decoder to its initial state.
     *  
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public function reset():void
    {
        data = new ByteArray();
        count = 0;
        filled = 0;
    }

    /**
     * Returns the current buffer as a decoded flash.utils.ByteArray.
     * Note that calling this method also clears the buffer and resets the 
     * decoder to its initial state.
     * 
     * @return The decoded flash.utils.ByteArray.
     *  
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public function toByteArray():ByteArray
    {
        var result:ByteArray = flush();
        reset();
        return result;
    }

	//--------------------------------------------------------------------------
	//
	//  Private Variables
	//
	//--------------------------------------------------------------------------

    private var count:int = 0;
    private var data:ByteArray;
    private var filled:int = 0;
    private var work:Array = [0, 0, 0, 0];

    /**
     *  @private 
     *  Used for accessing localized Error messages.
     */
	//private var resourceManager:IResourceManager =
	//								ResourceManager.getInstance();

    private static const ESCAPE_CHAR_CODE:Number = 61; // The '=' char

    private static const inverse:Array =
    [
        64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
        64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
        64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63,
        52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64,
        64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
        15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64,
        64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
        41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64,
        64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
        64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
        64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
        64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
        64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
        64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
        64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
        64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
    ];
}

}
 
avatar for qwerber qwerber 4717 posts
Flag Post
Originally posted by RTL_Shadow:
Originally posted by BobTheCoolGuy:
Originally posted by RTL_Shadow:

Wait, couldn’t I just do levTxt.deflate() to encode, and inflate() to decode?

You can’t deflate a String. You can write the String to a ByteArray and deflate it which would work well.

Would I have a problem with showing up the ? with the square? (What shows up when a font is not available)

Ummm.. no, that is a character that corresponds the the code 10010010. It’s one of the 256 characters represented by byte.

 
avatar for qwerber qwerber 4717 posts
Flag Post

Wtf UG delete that it’s basically spam. my method is so much better.

 
avatar for RTL_Shadow RTL_Shadow 1020 posts
Flag Post
Originally posted by qwerber:
Originally posted by RTL_Shadow:
Originally posted by BobTheCoolGuy:
Originally posted by RTL_Shadow:

Wait, couldn’t I just do levTxt.deflate() to encode, and inflate() to decode?

You can’t deflate a String. You can write the String to a ByteArray and deflate it which would work well.

Would I have a problem with showing up the ? with the square? (What shows up when a font is not available)

Ummm.. no, that is a character that corresponds the the code 10010010. It’s one of the 256 characters represented by byte.

That’s what I thought.

 
avatar for UnknownGuardian UnknownGuardian 8131 posts
Flag Post
my method is so much better.

Why yes, my method is better. :D Not all levels are going to look neat to make your compression algorithm work super well.

Also, my method is the implementation of Bob’s suggestion. (string deflate/byte array writing)

 
avatar for RTL_Shadow RTL_Shadow 1020 posts
Flag Post

@UnknownGuardian I love you. exactly what I was looking for and works great.

 
avatar for qwerber qwerber 4717 posts
Flag Post
Originally posted by UnknownGuardian:
my method is so much better.

Why yes, my method is better. :D Not all levels are going to look neat to make your compression algorithm work super well.

Also, my method is the implementation of Bob’s Suggestion. (string deflate/byte array writing)

dude… he wanted a small string, my method was base16 encoding which is smaller.

 
avatar for UnknownGuardian UnknownGuardian 8131 posts
Flag Post

Small string?

Its funny cause all of those levels strings uncompressed were 5,220 cells (4 layers of 45×29) and some extra data, making each a minimum uncompressed length of 10,570 characters.

 
avatar for qwerber qwerber 4717 posts
Flag Post

5220 cells with 4 bits per cell can fit into a string the length of 2610 characters, uncompressed.

 
avatar for RTL_Shadow RTL_Shadow 1020 posts
Flag Post

As long as it’s not raw data and not more than ~100 characters it’s fine.

 
avatar for qwerber qwerber 4717 posts
Flag Post
Originally posted by RTL_Shadow:

As long as it’s not raw data and not more than ~100 characters it’s fine.

how many tiles are you planning to fit in 100 characters?