Jump to content
  • 0
Sign in to follow this  
rje

Star Trader: data structure help!

Question

I suffer from premature optimization. 

I'm continually delayed when thinking about data storage for my Traveller-Trader game. 

I've done and re-done the same structure many, many, many times, compressing some data while leaving other data alone, thinking about what's easy to use versus what representation reduces wasted memory.

First, I'll show you the uncompressed, raw data.  Then I'll show you where I've been taking it.

 

The unit of data is the Universal World Profile, which actually includes some star system information, as well.  It is data sufficient to run the game, and to add a bit of useful in-game descriptive color.  It looks more or less like this:

[Regina, A,788899,12, N,S, Ag Ri Cp Sa, G, 138, D, Im, G0 V, M0 D]
	

Now here's one form of the record I devise for these.

The map is typically a 50% utilized 8x10 sparse matrix; I like to store the "empty" locations, because just because there's no star doesn't mean nothing's there.  In other words, I can hide objects there.

$00-0F 
"Regina" is the name.

$10    
"A" is the starport code from [A,B,C,D,E,X].

$11-$13 
788899 are nybbles representing world characteristics.

$14     
"12" is the tech level [0-34].

"N,S" are up to two bases from [N,S,D,W, and a few others].
I typically combine them with the starport into a one-byte index.

$15-$16 
"Ag Ri Cp Sa" are trade comments.  
I pack these into bitfields across two bytes.

"G" is the trade safety rating of [Green, Amber, Red].  
I usually pack it with the trade comments.

$17     
"13" are digit codes for 
- number of planetoid belts (1), 
- number of gas giants (3), 
- and number of other worlds (8) in the system.  

$18     
"D" is the highest ranking noble present.

$19     
"Im" is a code for the empire this world belongs to.

$1A-$1F 
"G0 V" and "M0 D" are the two stars in the system.  These fit nicely into six bytes to store up to three stars.
	

A 32 byte record is very tidy.  With a 256 byte header the subsector map fits in 2816 bytes.  When I need to read in four of these, I'm only reading 11K.

On the other hand, it's a tight space.  I was also thinking about a 48 byte record size, which would make the subsector map exactly 4K in size.  Reading four of those in would take 16K... not much more than 11K.

X16 Considerations

Either way, if I read in four subsector maps, I'd be using two RAM banks.  Therefore it seems better to go for the larger record size and have a little extra wasted space.

Anyone have suggestions?

Even if it's "STOP WORRYING ABOUT IT".

Edited by rje
  • Like 1

Share this post


Link to post
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Don't let "The Curse Of The Engineer" slow you down. I'd imagine the basic design of the game has your program's heavy lifting done in the Low RAM segment, and your heaviest Data can be stored in the Vera's VRAM banks.

However, "The Heaviest Data" is yet to be clear. If you add graphics and sounds - you'll need to be changing banks a lot to handle how and when your data is present and being accessed/modified by the program, and that creates...well...

A lot of potential for Speedrun Exploits and intentional (and unintentional!) memory corruption. XD

Considering the basic design of the X16's memory map? I'd treat those banks like Actual Discs and the program as a Slow, impatient User. They want as much continuous game as possible without swapping. As many related or linked things should be on a Disk at a time, and going back and forth should be as complete as possible.

This might mean that you really can just go at it and take up as much space as you want and then pare it down when you must. If anything, Just pad out data segments that you might need and then cut it. This is helped if you have your features prioritized and all plugged into your Big Three Things of Star Trader. If it doesn't immediately satisfy The Big Three? Put it on a shelf.

There's a story I once heard from some developer of a game: the program was something like 2 megabytes over the memory limit, and the company was freaking out close to immanent release. He goes, deletes a few lines esoterically buried in the program, and everything was fine. He did it on purpose for that exact contingency.

Hope this helps. I can't say I've personally messed with the system the way you are, but looking forward to hearing more. This sounds like Freelancer, and simulation games are very difficult and I definitely think not enough people are making good sims without getting forever lost while we all get old waiting for sim projects to deliver. XD

Edited by Starsickle

Share this post


Link to post
Share on other sites
  • 0
3 hours ago, Starsickle said:

Don't let "The Curse Of The Engineer" slow you down. I'd imagine the basic design of the game has your program's heavy lifting done in the Low RAM segment, and your heaviest Data can be stored in the Vera's VRAM banks.

However, "The Heaviest Data" is yet to be clear. If you add graphics and sounds - you'll need to be changing banks a lot to handle how and when your data is present and being accessed/modified by the program, and that creates...well...

Thanks for the good advice.  I predict two RAM banks are allocated for starmap data, which may need adjustment whenever the player's ship jumps to the next system.  That's easily subsumed as shopkeeping during interstellar flight, and a (short) delay is a feature.  In fact, a higher quality interstellar drive will reduce that delay.

Anyway, that leaves at least 120 RAM banks for anything else.

 

Quote

This sounds like Freelancer, and simulation games are very difficult and I definitely think not enough people are making good sims without getting forever lost while we all get old waiting for sim projects to deliver. XD

It really isn't Freelancer or Elite, although you've got me thinking.  No no no no no SCOPE CREEP!!!!

It's more like Star Trader, if you know about that, using Traveller to supplement the rules and data.

  • Haha 1

Share this post


Link to post
Share on other sites
  • 0

One of the details I'm working out is the trade rules, which are based on a matrix of relationships between two sets of trade codes.

This amounts to a hamming distance.  I can do this as bits, or code-by-code.  If I'm comparing two numbers, then it's a simple AND relationship to get the bits they have in common.  But then I have to decode the resulting number to find the count of matching bits.  You know, dividing by two and taking the mod, in a loop.

On the other hand, if I do a memory comparison, I'm just running through two arrays and incrementing if they're both "on" at each point.  It's memory lazy.  Is it less code in BASIC to do it this way though?  Two arrays of twelve INTs is more than 24 bytes.

DIM a1%[11], a2%[11]
count=0
for x = 0 to 11 :if a1%[x] = a2%[x] then count = count+1 :next

...that's not bad, assuming I can populate those arrays efficiently.

Edited by rje

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

Please review our Terms of Use