|
Castle Paradox
|
View previous topic :: View next topic |
Author |
Message |
Mr B
Joined: 20 Mar 2003 Posts: 382
|
Posted: Fri May 14, 2010 1:38 pm Post subject: Maximum Length of Integers |
|
|
Howdy, it's only been, what, x years since I logged in?
I am working on a casual OHR project that will REVOLUTIONIZE the WORLD (in the marginal chance it ever gets completed). And I have a question.
The OHRRPGCE has grown considerably since I started using it, and I have forgotten some of the details. For example, what is the maximum size of integers?
Due to limitations in the number of global variables, I want to save multiple fields of data in the same variable.
For example, if each (base 10) digit is paired up to form two-digit fields, I can read a field by dividing by powers of 10 to shift the desired field over, then subtract the fields higher than it.
Or I suppose I could just store it in a temporary string and pull the numbers directly out. That might be better. I should look into that. (looks into that) Wow, that's difficult.
But ANYWAY, how many digits does a modern integer contain? How many two-digit fields can I stick in it? |
|
Back to top |
|
|
Mr B
Joined: 20 Mar 2003 Posts: 382
|
Posted: Fri May 14, 2010 1:57 pm Post subject: |
|
|
DOUBLE POST ROCK ON.
I decided to use base-2 fields instead of base-10 (more efficient use of space).
I also assumed that integers are 32 bit. If each field is 6 bits, I can squeeze 5 fields in there with 2 left over (which I won't touch due to signed bit goodness).
Am I on the right track here? |
|
Back to top |
|
|
Guest
|
Posted: Fri May 14, 2010 4:08 pm Post subject: |
|
|
WOOO TREBLE POST
I think I solved this. I used bitwise logic and stuff, but clever computer dudes like you won't have a problem. Assuming it's correct. I tested it a bit, and it SEEMS correct, but there's always that one bug...
Code: |
plotscript, get cell data, cell, field, begin
# cell = ID# of global variable containing cell data
# field = the kind of data desired
#### NOTE #### all math is in base-10 representation of base-2. Clear enough?
#### NOTE #### all fields are 6 bits long (0-63)
variable(data)
variable(mask)
data := read global(cell) # get raw data
mask := 63 * 2 ^ (6 * field) # create and shift mask
data := data, and, mask # mask out all extraneous data
data := data / (2 ^ (6 * field)) # shift data down
return (data)
end
plotscript, set cell data, cell, field, info, begin
# cell = ID# of global variable containing cell data
# field = the kind of data being manipulated
# data = what you put in thar
#### NOTE #### all math is in base-10 representation of base-2. Clear enough?
#### NOTE #### all fields are 6 bits long (0-63)
#### NOTE #### 1-6 CELL_TYPE = 0
# 7-12 CELL_TOP = 1
# 13-18 CELL_LEFT = 2
# 19-24 CELL_BOTTOM = 3
# 25-30 CELL_RIGHT = 4
variable(data)
variable(mask)
data := read global(cell) # get raw data
mask := 63 * 2 ^ (6 * field) # create and shift mask
data := data, XOR, (data, AND, mask) # cut out the data at the mask position
data := data + info * 2 ^ (6 * field) # shift and insert new data
write global(cell, data)
end
|
This was designed around the assumption that each global integer is 32 bits.
- Each field can hold values from 0 to 63 (base 10), so there's not much room for large numbers, but perhaps info can be spread across multiple variables.
- Numbers larger than 63 will mess up higher-order fields. I don't have hugeness control implemented yet.
- The NOT command listed in my plotscript dictionary (10/10/2008) is not described as bitwise. I didn't test it. My workaround used that XOR and AND solution.
- My previous solution was even larger and less functional! Yay! |
|
Back to top |
|
|
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Fri May 14, 2010 6:18 pm Post subject: |
|
|
Welcome back! I'm sure whatever you're working on is going to be awesome, if you do complete it.
Yes, not is logical, not bitwise. And yes, variables are signed 32 bit integers, and it's a very good idea to stay away from the sign bit.
You can extract fields easier/faster than that:
Code: | data := read global(cell) # get raw data
data := data / (64 ^ field) # shift data down
data := data, and, 63 # mask out all extraneous data
|
(And if you're desperate, it runs faster still if you remove the intermediate setvariables)
Actually, storing your data in strings would have been a good solution, because strings have unlimited length, and getting or setting a character of a string is a single command, faster than all that math you have to do to cram them into globals.
There are plenty of other ways to store data if the 4096 globals aren't enough. You can store extra globals in the 28 extra save slots using import/export globals, but this can be pretty confusing. You can store data in invisible tile layers. Note that you can save and load tile layer into any map of the same size. And finally, all the cool kids these days are taking advantage of the unlimited storage granted by slices, but that's really slow and inefficient compared to the other options, it's best for creating tree data structures.
Of those options, only globals can currently be saved in save games, but James is working on changing that as we speak! _________________ "It is so great it is insanely great." |
|
Back to top |
|
|
Bagne ALL YOUR NUDIBRANCH ARE BELONG TO GASTROPODA
Joined: 19 Feb 2003 Posts: 518 Location: Halifax
|
Posted: Fri May 14, 2010 7:09 pm Post subject: |
|
|
The Mad Cacti wrote: |
Of those options, only globals can currently be saved in save games, but James is working on changing that as we speak! |
I'm speaking right now.
That means that James is working on making those changes RIGHT NOW! _________________ Working on rain and cloud formation |
|
Back to top |
|
|
Mr B
Joined: 20 Mar 2003 Posts: 382
|
Posted: Fri May 14, 2010 10:19 pm Post subject: |
|
|
Woah woah...unlimited length strings!?! 4096 global variables!?! Slices!?! (actually I knew about slices, but I couldn't tell you what they did)
I've been away too long! It is time to UPGRADE.
Thanks for the code suggestion -- I'll try it out! |
|
Back to top |
|
|
Bob the Hamster OHRRPGCE Developer
Joined: 22 Feb 2003 Posts: 2526 Location: Hamster Republic (Southern California Enclave)
|
Posted: Sat May 15, 2010 9:17 am Post subject: |
|
|
Bagne wrote: | The Mad Cacti wrote: |
Of those options, only globals can currently be saved in save games, but James is working on changing that as we speak! |
I'm speaking right now.
That means that James is working on making those changes RIGHT NOW! |
I am actually waiting for my sausage and eggs, but I WOULD be implementing the new save format right now if this restaurant had dang plugs at the tables to power my laptop :) |
|
Back to top |
|
|
|
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|