Thread: Custom Sprite Cache

Page 1 of 13 12311 ... LastLast
Results 1 to 10 of 121
  1. #1 Custom Sprite Cache 
    Retired. Stop PMing me.


    Galkon's Avatar
    Join Date
    Nov 2007
    Age
    17
    Posts
    7,526
    Thanks given
    1,805
    Thanks received
    2,830
    Rep Power
    5000
    Quote Originally Posted by Galkon View Post
    I've updated the source code, brought it up to date to Java 8 standards. Rewrote a lot of the old shit code that was in there... Man it was bad. Anyways, it should only count image files now, and it should be able to load even if the sprite cache doesn't load, or if there aren't any images in the sprites folder. I didn't do a lot of extensive testing, but it worked for what I did test.

    Anyways, here's the full source and the fixed tool: https://www.sendspace.com/file/ey5ve0

    This tool is mainly for my RuneLimited client users,
    however it will work for anybody that uses it correctly.

    Awhile ago Songoty released a model cache packer, this is based on that code. However, it's been modified to be a sprite cache packer, but you may also view the sprites you're packing, assign drawOffsetX and drawOffsetY variables, as well as names.
    __________________________

    A couple things to remember:
    All pictures in the sprite folder must be a .png.
    If you want to add more images, place them in the sprites folder, and make sure their name is "#.png", # being the next number. You'll see what I mean in the folder. All files must be in ascending numerical order.
    The main use for this tool was to create a sprite cache that's easy to use, and preserves the quality of the images at the same time.
    The sprite cache and sprites included in the download are from my RuneLimited client. Feel free to use your own.
    __________________________

    The compression used is just GZip compression. It will pack your sprites to sprites.dat and sprites.idx which you can use the loader given on this thread to unpack them. The applet resizes if the sprite is big so you can view it in the program. It also holds the transparency of the image if it has any.
    __________________________

    Download
    https://www.sendspace.com/file/yxqsxm
    __________________________

    Implementation
    Add this class:
    Spoiler for SpriteLoader.java:
    Code:
    import java.io.ByteArrayInputStream;
    import java.io.DataInputStream;
    import java.io.IOException;
    import java.util.zip.GZIPInputStream;
    
    import sign.signlink;
    
    public class SpriteLoader {
    
        /**
         * Loads the sprite data and index files from the cache location.
         * This can be edited to use an archive such as config or media to load from the cache.
         * @param archive
         */
        public static void loadSprites(CacheArchive archive) {
            try {
                ByteVector index = new ByteVector(DataUtils.readFile(signlink.findcachedir() + "sprites.idx"));
                ByteVector data = new ByteVector(DataUtils.readFile(signlink.findcachedir() + "sprites.dat"));
                DataInputStream indexFile = new DataInputStream(new GZIPInputStream(new ByteArrayInputStream(index.buffer)));
                DataInputStream dataFile = new DataInputStream(new GZIPInputStream(new ByteArrayInputStream(data.buffer)));
                int totalSprites = indexFile.readInt();
                if (cache == null) {
                    cache = new SpriteLoader[totalSprites];
                    sprites = new Sprite[totalSprites];
                }
                for (int i = 0; i < totalSprites; i++) {
                    int id = indexFile.readInt();
                    if (cache[id] == null) {
                        cache[id] = new SpriteLoader();
                    }
                    cache[id].readValues(indexFile, dataFile);
                    createSprite(cache[id]);
                }
                indexFile.close();
                dataFile.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
        /**
         * Reads the information from the index and data files.
         * @param index holds the sprite indices
         * @param data holds the sprite data per index
         * @throws IOException
         */
        public void readValues(DataInputStream index, DataInputStream data) throws IOException {
            do {
                int opCode = data.readByte();
                if (opCode == 0) {
                    break;
                }
                if (opCode == 1) {
                    id = data.readShort();
                } else if (opCode == 2) {
                    name = data.readUTF();
                } else if (opCode == 3) {
                    drawOffsetX = data.readShort();
                } else if (opCode == 4) {
                    drawOffsetY = data.readShort();
                } else if (opCode == 5) {
                    int indexLength = index.readInt();
                    byte[] dataread = new byte[indexLength];
                    data.readFully(dataread);
                    spriteData = dataread;
                }
            } while (true);
        }
    
        /**
         * Creates a sprite out of the spriteData.
         * @param sprite
         */
        public static void createSprite(SpriteLoader sprite) {
            sprites[sprite.id] = new Sprite(sprite.spriteData);
            sprites[sprite.id].drawOffsetX = sprite.drawOffsetX;
            sprites[sprite.id].drawOffsetY = sprite.drawOffsetY;
        }
    
        /**
         * Gets the name of a specified sprite index.
         * @param index
         * @return
         */
        public static String getName(int index) {
            if (cache[index].name != null) {
                return cache[index].name;
            } else {
                return "null";
            }
        }
    
        /**
         * Gets the drawOffsetX of a specified sprite index.
         * @param index
         * @return
         */
        public static int getOffsetX(int index) {
            return cache[index].drawOffsetX;
        }
    
        /**
         * Gets the drawOffsetY of a specified sprite index.
         * @param index
         * @return
         */
        public static int getOffsetY(int index) {
            return cache[index].drawOffsetY;
        }
    
        /**
         * Sets the default values.
         */
        public SpriteLoader() {
            name = "name";
            id = -1;
            drawOffsetX = 0;
            drawOffsetY = 0;
            spriteData = null;
        }
    
        public static SpriteLoader[] cache;
        public static Sprite[] sprites = null;
        public static int totalSprites;
        public String name;
        public int id;
        public int drawOffsetX;
        public int drawOffsetY;
        public byte[] spriteData;
    }

    If you're using my RuneLimited client, in client.java remove the current loadSprites() method, and in startup add this where loadSprites() was:
    Code:
                    SpriteLoader.loadSprites(mediaArchive);
                    cacheSprite = SpriteLoader.sprites;
    If you aren't using my RuneLimited client, simply add these where appropriate:
    Code:
    public Sprite[] cacheSprite;
    and the nullpointer:
    Code:
    cacheSprite = null;
    The usage is cacheSprite[#].drawSprite(0, 0); while # is the # in the viewer/sprites folder.
    __________________________

    Pictures


    Last edited by Galkon; 06-19-2011 at 01:37 PM.
    Attached image
    Reply With Quote  
     


  2. #2  
    Registered Member

    Join Date
    Nov 2008
    Posts
    2,180
    Thanks given
    148
    Thanks received
    99
    Rep Power
    2004
    This is AWESOME! Good job Josh, Winning.
    Reply With Quote  
     

  3. #3  
    Super Donator


    Join Date
    Feb 2011
    Age
    27
    Posts
    1,126
    Thanks given
    180
    Thanks received
    178
    Rep Power
    243
    Nice work
    Reply With Quote  
     

  4. #4  
    #extreme

    +Deus Ex's Avatar
    Join Date
    Nov 2009
    Posts
    2,964
    Thanks given
    236
    Thanks received
    214
    Rep Power
    411
    Awesome~ Kudos~!
    Best regards,
    +Deus Ex
    Reply With Quote  
     

  5. #5  
    If you read this you're gay!
    Infexis's Avatar
    Join Date
    Aug 2009
    Age
    28
    Posts
    4,557
    Thanks given
    1,158
    Thanks received
    1,174
    Rep Power
    2949
    Good job dude

    "If you can't explain it simply, you don't understand it well enough." - Albert Einstein
    Reply With Quote  
     

  6. #6  
    Banned

    Join Date
    Aug 2008
    Posts
    1,885
    Thanks given
    56
    Thanks received
    102
    Rep Power
    0
    Thank's will use.
    Reply With Quote  
     

  7. #7  
    PokeNation! Xaves's Avatar
    Join Date
    Dec 2007
    Age
    32
    Posts
    3,476
    Thanks given
    356
    Thanks received
    788
    Rep Power
    646
    Looks good

    I guess I'll just modify it to load the sprites on demand instead of loading them all at startup.
    Reply With Quote  
     

  8. Thankful user:


  9. #8  
    I'm Back

    Stewie's Avatar
    Join Date
    Jul 2008
    Age
    29
    Posts
    7,987
    Thanks given
    1,877
    Thanks received
    1,491
    Rep Power
    5000
    The compression used is just GZip compression. It will pack your sprites to sprites.dat and sprites.idk which you can use the loader given on this thread to unpack them. The applet resizes if the sprite is big so you can view it in the program. It also holds the transparency of the image if it has any.
    __________________________
    You made a typo in this sentence. Should be sprites.idx not idk
    Reply With Quote  
     

  10. Thankful user:


  11. #9  
    Client God

    Join Date
    Aug 2009
    Posts
    3,127
    Thanks given
    3
    Thanks received
    617
    Rep Power
    907
    Good shit
    Reply With Quote  
     

  12. #10  
    なぜこのテキストは日本語で書かれている ?

    Kenneh's Avatar
    Join Date
    Dec 2009
    Age
    30
    Posts
    2,753
    Thanks given
    63
    Thanks received
    296
    Rep Power
    478
    1.9mb packer.jar most of that is from a substance.jar. why didnt you just unzip the jar and only use the class you needed?


    Reply With Quote  
     

Page 1 of 13 12311 ... LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. [508] Custom login music [custom cache]
    By lukas265 in forum Show-off
    Replies: 7
    Last Post: 07-23-2010, 06:22 PM
  2. Custom sprite cache
    By 35518 in forum Snippets
    Replies: 12
    Last Post: 12-16-2009, 03:14 PM
  3. Custom sprite help!
    By Tweezy in forum Help
    Replies: 4
    Last Post: 07-06-2009, 12:27 PM
  4. custom sprite
    By jer123 in forum Help
    Replies: 4
    Last Post: 06-07-2009, 01:36 AM
  5. Custom sprite loading
    By Auruo in forum Help
    Replies: 1
    Last Post: 02-16-2009, 02:13 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •