RuneScape 2 Development > Server and Client Development Showoff
Evelus
<<< (16/119) >>>
xen0n:
Global gfx system complete.

sini:
Follow up to that with code:


--- Code: ---/*
 *  Copyright (c) 2012 Hadyn Fitzgerald
 *
 *  Permission is hereby granted, free of charge, to any person obtaining a copy of
 *  this software and associated documentation files (the "Software"), to deal in
 *  the Software without restriction, including without limitation the rights to
 *  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 *  the Software, and to permit persons to whom the Software is furnished to do so,
 *  subject to the following conditions:
 *
 *  The above copyright notice and this permission notice shall be included in all
 *  copies or substantial portions of the Software.
 * 
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 *  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 *  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 *  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 *  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package org.sini.frontier.game.update.impl;

import org.sini.frontier.game.EntityRepository;
import org.sini.frontier.game.GameClient;
import org.sini.frontier.game.update.ViewportHandler;
import org.sini.frontier.model.Position;
import org.sini.frontier.model.StillGraphic;
import org.sini.frontier.net.game.frames.ChunkUpdate;
import org.sini.frontier.net.game.frames.StillGraphicSpawn;

import org.jboss.netty.channel.Channel;

/**
 * Frontier Development
 * StillGraphicList.java
 * Created by Sini
 */
public final class StillGraphicList extends ViewportHandler {

    /**
     * The game client to encode the chunk updates to.
     */
    private GameClient localClient;
   
    /**
     * The current chunk update frame.
     */
    private ChunkUpdate currentChunkUpdate;
   
    /**
     * The current location for the chunk update.
     */
    private int locationHash;
   
    /**
     * The map x coordinate position.
     */
    private int mPositionX;
   
    /**
     * The map y coordinate position.
     */
    private int mPositionY;
   
    @Override
    public void update(Position position, int viewportSize) {
        int viewport = viewportSize >> 4;
        mPositionX = (position.getChunkX() - viewport) << 3;
        mPositionY = (position.getChunkY() - viewport) << 3;
        super.update(position, viewportSize);
        if(currentChunkUpdate != null) {
            Channel channel = localClient.getClientSession().getSession().getChannel();
            channel.write(currentChunkUpdate);
        }
        currentChunkUpdate = null;
        locationHash = -1;
    }

    @Override
    public void handle(int id, int chPositionX, int chPositionY) {
        int hash = chPositionX << 8 | chPositionY;
        if(locationHash == -1 || locationHash != hash) {
            if(currentChunkUpdate != null) {
                Channel channel = localClient.getClientSession().getSession().getChannel();
                channel.write(currentChunkUpdate);
            }
            currentChunkUpdate = new ChunkUpdate(chPositionX << 3, chPositionY << 3);
            locationHash = hash;
        }
        StillGraphic stillGraphic = EntityRepository.getInstance().getStillGraphic(id).getStillGraphic();
        Position graphicPosition = stillGraphic.getPosition();       
        int chLocalX = (graphicPosition.getX() - mPositionX) - (chPositionX << 3);
        int chLocalY = (graphicPosition.getY() - mPositionY) - (chPositionY << 3);
        StillGraphicSpawn graphicSpawn = new StillGraphicSpawn(chLocalX, chLocalY, stillGraphic.getGfxId(),
                                                               stillGraphic.getHeightOffset(),
                                                               stillGraphic.getDelay());
        currentChunkUpdate.addFrame(graphicSpawn);
    }
   
    /**
     * Constructs a new {@link ProjectileList};
     * @param localClient The client to write the projectile list update to.
     */
    public StillGraphicList(GameClient localClient) {
        super(STILLGRAPHICS);
        this.localClient = localClient;
        locationHash = -1;
    }
}


--- End code ---

Edit:

Finished the region system configuration file and working on clipping of paths for mobs. Update time is now more consistent and around 8-20 ms with the removal for the lazy load region system.


--- Code: ---/*
 *  Copyright (c) 2012 Hadyn Fitzgerald
 *
 *  Permission is hereby granted, free of charge, to any person obtaining a copy of
 *  this software and associated documentation files (the "Software"), to deal in
 *  the Software without restriction, including without limitation the rights to
 *  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 *  the Software, and to permit persons to whom the Software is furnished to do so,
 *  subject to the following conditions:
 *
 *  The above copyright notice and this permission notice shall be included in all
 *  copies or substantial portions of the Software.
 * 
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 *  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 *  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 *  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 *  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package org.sini.frontier.setup;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.runetekk.FileIndex;
import org.runetekk.ArchivePackage;

import java.io.RandomAccessFile;
import java.util.zip.GZIPInputStream;
import org.sini.frontier.io.Buffer;

/**
 * Frontier Development
 * RegionSetup.java
 * Created by Sini
 */
public final class RegionSetup {

    /**
     * The main entry point for the program.
     * @param args The command line arguments.
     */
    public static void main(String[] args) throws Throwable {
        RandomAccessFile mainArchive = new RandomAccessFile(args[0], "r");
        RandomAccessFile configArchive = new RandomAccessFile(args[1], "r");
        RandomAccessFile landscapeArchive = new RandomAccessFile(args[2], "r");
        FileIndex configIndex = new FileIndex(1, mainArchive, configArchive);
        FileIndex landscapeIndex = new FileIndex(5, mainArchive, landscapeArchive);
        ArchivePackage configPack = new ArchivePackage(configIndex.get(5));
        FileOutputStream outputFile = new FileOutputStream(args[3]);
        byte[] bytes = configPack.getArchive("map_index");
        Buffer configBuffer = new Buffer(bytes);
        int amountRegions = bytes.length / 7;
        for /* Stalingrad! */ (int i = 0; i < amountRegions; i++) {
            int regionHash = configBuffer.getUword();
            int mapArchive = configBuffer.getUword();
            int objArchive = configBuffer.getUword();
            configBuffer.getByte();                                        //Useless
            Buffer mapFile = unpackFile(landscapeIndex, mapArchive);
            boolean[][] activeChunks = new boolean[8][8];
            determineActiveChunks(mapFile, activeChunks);
            outputFile.write(1);                                           //Region start
            outputFile.write(regionHash >> 8);
            outputFile.write(regionHash);
            for(int x = 0; x < 8; x++) {
                for(int y = 0; y < 8; y++) {
                    if(!activeChunks[x][y])
                        continue;
                    outputFile.write(1);                                   //Chunk start
                    outputFile.write(x << 4 | y);
                    outputFile.write(0);                                   //Chunk end
                }
            }
            outputFile.write(0);                                           //Region end
        }                                             
        outputFile.write(0);                                               //File end
        outputFile.flush();
        outputFile.close();
    }

    /**
     * Unpacks a file from a file index.
     * @param fileIndex The file index to get the file from.
     * @param fileId The id of the file to unpack.
     * @return The unpacked file stored in a buffer.
     */
    private static Buffer unpackFile(FileIndex fileIndex, int fileId) throws IOException {
        InputStream is = new GZIPInputStream(new ByteArrayInputStream(fileIndex.get(fileId)));
        try {
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            try {
                byte[] buf = new byte[4096];
                int len = 0;
                while ((len = is.read(buf, 0, buf.length)) != -1) {
                    os.write(buf, 0, len);
                }
            } finally {
                os.close();
            }
            return new Buffer(os.toByteArray());
        } finally {
            is.close();
        }
    }

    /**
     * Determines the active chunks for a region.
     * @param buffer The buffer to read to determine the active chunks from.
     * @param activeChunks The active chunks array.
     */
    private static void determineActiveChunks(Buffer buffer, boolean[][] activeChunks) {
        for (int z = 0; z < 4; z++) {
            for (int x = 0; x < 64; x++) {
                for (int y = 0; y < 64; y++) {
                    for (;;) {
                        int opcode = buffer.getUbyte();
                        if (opcode == 0) {
                            break;
                        }
                        if (opcode == 1) {
                            buffer.getUbyte();
                            break;
                        }
                        if (opcode <= 49 || opcode > 81) {
                            activeChunks[x >> 3][y >> 3] = true;
                        }
                    }
                }
            }
        }
    }

    /**
     * Prevent construction;
     */
    private RegionSetup() { }
}

--- End code ---
luther:
Good luck high expectations for this one.
sini:

Region 50,50 clipping map

Still, working on perfecting clipping. Thanks to super_ for posting the transversal map. It has greatly helped.
Ryley:
Friendly bump, and an update.

I am now a part of this wonderful development team, and I'm proud of it. :)
Navigation
Message Index
Next page
Previous page

Go to full version
Powered by SMFPacks SEO Pro Mod |