Author Topic: Map Data Storage  (Read 10017 times)

0 Members and 1 Guest are viewing this topic.

Offline BlackCode

  • LV2 Member (Next: 40)
  • **
  • Posts: 28
  • Rating: +0/-0
    • View Profile
Re: Map Data Storage
« Reply #15 on: August 24, 2013, 11:34:59 pm »
Ahh yes, thanks for the reminder Runner.  I forgot it was the erases, not the writes.  Regardless, each archive writes to a new place, correct?  So chunking the map and archiving/unarchiving multiple times per session would fill up the memory faster than just archiving once at the end, which would result in more flash clears.  Of course, whether anybody should actually worry about this is questionable.
-I post from my iPod, so please forgive any funky formatting.

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Map Data Storage
« Reply #16 on: August 24, 2013, 11:38:03 pm »
If the map is small enough that it can reasonably fit entirely in RAM, there's no reason not to do it that way. Splitting the map into chunks is mainly useful (necessary, really) when the map is larger than can fit into RAM.
« Last Edit: August 24, 2013, 11:38:25 pm by Runer112 »

Offline BlackCode

  • LV2 Member (Next: 40)
  • **
  • Posts: 28
  • Rating: +0/-0
    • View Profile
Re: Map Data Storage
« Reply #17 on: August 24, 2013, 11:45:05 pm »
How much exactly can fit into ram?  I've seen 4,000 bytes of free ram, but is this the only place in which map data can be stored?  I would assume more is available...
« Last Edit: August 24, 2013, 11:47:02 pm by BlackCode »
-I post from my iPod, so please forgive any funky formatting.

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Map Data Storage
« Reply #18 on: August 25, 2013, 02:15:23 am »
Usually, when the user archives everything, there are more than 20 KB of RAM on the calc.
-If you compile your code as an app, it will be run from Flash and you'll have those 20 KB all for your appvar.
-If you compile your code as a program, it will be run from RAM (even if you "run it from archive" with a shell, in fact it will be copied to RAM) and the RAM available for your appvar will be the 20KB-size_of_the_program.
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline BlackCode

  • LV2 Member (Next: 40)
  • **
  • Posts: 28
  • Rating: +0/-0
    • View Profile
Re: Map Data Storage
« Reply #19 on: August 25, 2013, 11:22:11 am »
Ok, that makes sense. Two questions in that case: 1. Is there any way to detect if the user has unarchived programs?  2. Is there a rule of thumb for how long unarchiving/archiving an appvar (based on its size) will take?
-I post from my iPod, so please forgive any funky formatting.

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Map Data Storage
« Reply #20 on: August 25, 2013, 11:31:32 am »
1. Is there any way to detect if the user has unarchived programs?
Yes, through the VAT, but that is not really needed.
What you want is basically to know if you have enough RAM for your program to run, right ?
Then use the same GetCalc command that is used in the tutorial. You'll see that it returns when you try to create an appvar if it could not be created (because of lack of RAM). So just do your code like that (where I use random names for variables):

GetCalc("appvNAME",Size)→P
!If
 Disp "Not Enough RAM"
 Return
End
<then the rest of the program>


And you can be more precise in your "Not Enough RAM" message, telling the user to archive variables, or the exact amount of RAM needed...
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline shmibs

  • しらす丼
  • Administrator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2132
  • Rating: +281/-3
  • try to be ok, ok?
    • View Profile
    • shmibbles.me
Re: Map Data Storage
« Reply #21 on: August 25, 2013, 11:34:15 am »
you can use the bcall _ErrNotEnoughMem to check if enough free ram is available (usable in axe via inline asm). apparently 9815h also contains the total amount of ram free, so you could check there too.

also, like several other people have said already, there is no reason for you to be unarchiving anything ever during your program's execution. all that "unarchiving" does, anyways, is copy the variables to RAM and then delete them from the archive, and there's no reason for them to be deleted.

Offline BlackCode

  • LV2 Member (Next: 40)
  • **
  • Posts: 28
  • Rating: +0/-0
    • View Profile
Re: Map Data Storage
« Reply #22 on: August 25, 2013, 11:45:16 am »
Alright, thanks for the help with handling available space.  But Shmibs I must be misunderstanding something...at somepoint the map data would need to be unarchived in order to alter it would it not?
-I post from my iPod, so please forgive any funky formatting.

Offline JosJuice

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1344
  • Rating: +66/-14
    • View Profile
Re: Map Data Storage
« Reply #23 on: August 25, 2013, 12:01:54 pm »
Alright, thanks for the help with handling available space.  But Shmibs I must be misunderstanding something...at somepoint the map data would need to be unarchived in order to alter it would it not?
You do need to place map data in RAM to alter it, but you don't have to both copy it to RAM and delete it from flash (which is what unarchiving does) – simply copying it to RAM is enough.

Offline shmibs

  • しらす丼
  • Administrator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2132
  • Rating: +281/-3
  • try to be ok, ok?
    • View Profile
    • shmibbles.me
Re: Map Data Storage
« Reply #24 on: August 25, 2013, 12:18:33 pm »
^exactly. axe allows you to read variables directly from the archive using what it calls files. basically, you assign a var to a file (which use the Y1-Y9 function variables) and then refer to it as you would any other pointer. that's why i was talking about using several smaller map chunks rather than one giant map; if you split your 20kb map into 4kb chunks and then the user only modifies two of those chunks, you only need to write back those 8kb upon exiting rather than the entire 20kb map. again, depending on what sort of game you're making, there are lots of more efficient ways to reduce the necessary amount of writing, so it would be nice to know more specifically what sort of game you want to make (particularly things like how often you expect tiles to be changing and how many different values they can take on etc.).

Offline BlackCode

  • LV2 Member (Next: 40)
  • **
  • Posts: 28
  • Rating: +0/-0
    • View Profile
Re: Map Data Storage
« Reply #25 on: August 25, 2013, 12:36:42 pm »
Alright, I get what you mean with copying.  As far as more information, I'll give you what I can.  I would expect most users to heavily modify tiles in a fairly concentrated area, and only do light changes in the rest of the map.  However, there is no way to predict where these heavy changes will take place, and it is entirely possible, although unlikely, they will heavily modify everything after a long time.  As for number of tiles, I would guesstimate under 64ish, with only about 16-20 being extremely common throughout the world.

Edit:  I've been thinking some more, and I feel like chunking the data into smallish appvars is the best route.  My map would consist of multiple appvars, of which, three would be loaded into ram at a single time: the chunk the player is at, and a chunk to either side.  If the player modified any of the tiles in a chunk, the new data would be saved to the appvar, and that appvar would be flagged as modified.  When the player changed chunks, the one chunk that will no longer be loaded is checked to see if it was modified, if it was, it is archived, if not, it is simply discarded.  If anybody has any feedback on this (completely theoretical) method, please share.

Note: I considered using a list of changes that took place, but quickly ran into too many obstacles.  For example: handling multiple changes to the same tile and preventing the list of changes from getting excessively large.
« Last Edit: August 25, 2013, 01:51:04 pm by BlackCode »
-I post from my iPod, so please forgive any funky formatting.