Jump to content
  • Advertisement
  • entries
  • comments
  • views

Solving over six thousand woes with a custom pak format

Sign in to follow this  


Greetings all,

A series of recent technical difficulties has brought about a need for change...

Rooms in Revel Immortal

As some of you may know, Revel is composed of many, many screen-sized rooms; which collectively make up one whole map.
And yet within Revel there are many maps; Garranshall, a map in Revel is composed of 80x80 (or 6400) rooms.

Each room is a file; which seems, and maybe be somewhat absurd but there are some good reasons for it...

Revel, is an HTML5 game

... or 'web-game' if you will; users don't install anything so, we only give them data they request and need.
since you can only see one room at a time, serving single rooms on request makes good sense for everyone.

It was very important per-alpha and post-alpha to focus on content...

This means we only went on technological side-roads when it was deemed critical; and having an 80x80 map in 80 directories of 80 files each, was a simple, fast way to express the data and still have it be workable for the end user.

Also having each room as a single .json file meant we could do sweeping find-replace transformations, in an era when we did not have strong editing tools (we couldn't afford the time to build them yet).

But now this format is killing us softly...

As our number of maps grow, we are getting more and more discrete room files (as if 6400 wasn't enough); this is putting nominal per-file load on things like, cloning directory strcuture, adding, commiting to SVN.

But there have been two final straws that have killed this format...

You just can't load 6400 tiny json files real-time for a sweeping overview of the map

Now that we have powerful tools in the form of the Revel Editor, it has been a goal and neccesity to better grok and visualize the world-at-large in Revel... to do this even just for Garranshall would mean loading up and processing 6400 files, and it seems at least commodity hard disks just can't hack it.

While I might be able to, throwing hardware at this problem is not desireable as I think this use case is just plain wrong; and heck with 16GB of RAM on my development machine I'm not making effective use of it.

The other straw is that soon, hopefully very soon; we will no longer just be serving direct file linkages to resources such as rooms.

Hopefully around April, we will be reaching beta-stage

and with that... players will be able to purchase keys (or a one-time master key) to unlock access to realms that aren't part of the free areas in Revel.

In order to make this semi-secure we need to start validating requests for certain resources against a players' keyring; and while it is a simple matter of validating their key, fetching the file and returning it with proper headers;

All of a sudden the simplicity of direct file linkage is null and void, we get no benefit from it.

So, after talking with other programmers here on GameDev chat, and other programmers on the Revel team; we devised a simple format that should solve all the identified issues.

A custom 'pak' format

I've written plenty of archive-type formats in the past, so I knew all the common pitfalls; the only new elements here were that I planned to frequently update the archive, and a single file request from the archive needed to be fast (due to the stateless nature of the CGI that would fetch room files).

...in addition a fairly flexible format was desireable so it could be tightly integrated into our server code, since it serves all such HTML5 games we might build and release.

The Format

I started from the angle of the end-use, as it was going to get the most 'hammering' and we had the least amount of control at the server level, what I came up with is as such:
fileCount //- 4 bytes - the number of toc lines (and fragments) in the file//a toc line{offset //- 4 bytes - the offset from the end of this toc line to the start of the file datasize //- 4 bytes - the size of the data}//file data//all of the file fragments lined up next to one anotherThis is a fairly common format scenario that many of you may recognize; with one exception being perhaps offset being calculated from the end of the toc line.

With this form, requesting a single file simply becomes a matter of:

  1. Open the file stream
  2. Read 4 bytes to get file count
  3. Validate requested file index is in range (>=0
  4. seek to proper toc line +(fileIndex*8)
  5. read 4 bytes of offset and 4 bytes of size
  6. seek to +offset
  7. read and return 'size' bytes
This is all sequential, no back-tracking, and no reading of unneccesary data.

From the editor side, I've written a class that makes creation/reading of this file format easy.

It is designed to be worked in-memory; which should hopefully save my HDD any undue stress, and use that 16GB of RAM ;)

FragFile f = new FragFile(100);f.Write(0, "zero");f.Write(2, "two");f.Write(1, "one");f.Save("G:\\test.frag");FragFile f2 = new FragFile("G:\\test.frag");string val1 = ASCIIEncoding.ASCII.GetString(f2.Read(2));
Sign in to follow this  


Recommended Comments

@Navyman - it hasn't been stressed yet; due to the nature of this change; I ideally need to integrated it into Engine, Editor, Server software, and of course do a data migration in one shot.


Hopefully that will happen this week; last night was spent finishing off previously noted changes to the NPC conversation system (which seems to be playing nicely); and furthering quest content.

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!