Author Topic: Routines  (Read 298236 times)

0 Members and 4 Guests are viewing this topic.

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Routines
« Reply #375 on: July 26, 2010, 04:47:55 pm »
Nice. However, I think I should tell you that RLE is typically done slightly differently, with a reserved number to indicate runs. For example:
Code: [Select]
.Uncompressed (each tile is a half-byte)
[567222220874999F
[033AAAAAAAAAAAAA
[AAA23279BBBBB8FF
.24 bytes
.Compressed
[567F520874999F1F
[033F0A23279F5B8F
[2F
.17 bytes
Where normal data is just inserted, and a run (more than three here) is indicated by 'F' followed by the run length (one nibble, 0 is length 16) followed by the tile number. An 'F' tile is always recorded in run format because it would otherwise be treated as the start of a run.
I'll try to get some code up in a bit.
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Routines
« Reply #376 on: July 26, 2010, 04:54:11 pm »
Interesting CalcDude, i've never encountered RLE implemented in that way.  I use it in the same way as Nemo did when i wrote Portal and PortalX, i shall have to do some tests to see if your method offers more compression.  Its too bad that it would take 3 bytes to represent a single F though, whereas Nemo's method it only takes 1.  It would seem that they are both suited for slightly different kinds of data?  Nemo's method where there are longer runs and less random data, and Calcdudes method where there is runs and random data mixed together.

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Routines
« Reply #377 on: July 26, 2010, 04:57:23 pm »
Mine takes three nibbles, while his takes one byte, or two nibbles. It's only 50% larger ;D Not to mention I'm assuming the 'F' tile won't be used as often.
* calcdude goes off to code this
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Routines
« Reply #378 on: July 26, 2010, 05:00:46 pm »
Ah yes thats right, good catch.  Its also good to note that in both methods, tiles can only go up to 4bit, so Nemo's representation of his original data in 8bit adds on twice the amount of data then can be compressed.  There is only 12 bytes of information being compressed.

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: Routines
« Reply #379 on: July 26, 2010, 05:09:50 pm »
builderboy, i could make the routine compress half-byte tilemaps, but it would be more complicated, so i just stuck with one tile as being equal to one byte, though my compression is preferably used in maps that have 15 or less tiles, and have long runs of the same data. if you need more than 15 tiles and have very, very long runs of the same data,  you could use a method where one byte holds frequency, and the next holds the tile number.
so [43050320] would represent tile 5 67 times, then tile 32 3 times. but that can be very memory inefficient unless you have many runs of data, specifically runs of data that last more than 4 tiles.


Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Routines
« Reply #380 on: July 26, 2010, 05:12:41 pm »
Ah gotcha, yeah that makes sense.  Yeah i was just commenting on uncompressed vs compressed sizes :)

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: Routines
« Reply #381 on: July 27, 2010, 03:17:51 pm »
calcdude, wouldn't RLE under your example only allow tiles 0-E, since F is reserved for indicating a run? and sometimes you could end up with an odd number of nibbles. regardless, i like that type of RLE and i'll probably post some de/compression routines about it.

edit: and my routines will have the uncompressed map data as each tile being one byte.

edit2: compression is working.

Code: [Select]
.ROUTINE
0->C->D
"0123456789ABCDE0->Str1    .Make sure you have 0 at the end, not F.
For(Y,0,S                  .Replace S with the height of your uncompressed map minus 1
For(X,0,T                  .Replace T with the width of your uncompressed map minus 1
If {T+1*Y+X+GDB1}->A={T+1*Y+X+GDB1+1} and (C!=14)
C+1->C
Else
If C>3
70->{L1+D}
{Str1+C+1}->{L1+D+1}
{Str1+A}->{L1+D+2}
D+3->D
Else
For(Z,0,C
{Str1+A}->{L1+D}
D+1->D
End:End:0->C:End:End:End
GetCalc("Str4",D^2+D)->I
For(Z,0,D-1
{L1+Z}->{I+Z}
End
If D^2
70->{I+Z+1}
End

that was much more difficult to write... i wonder how decompression will be.
« Last Edit: July 27, 2010, 05:00:44 pm by nemo »


Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Routines
« Reply #382 on: July 27, 2010, 04:34:18 pm »
As I said, you always have to use the 'F' tile in run form, no matter what. But it is possible. As for an odd number of nibbles, you could always just add an extra 'F'. Now to write this, since I have the time. We're doing this by row, right?
* calcdude goes and codes
« Last Edit: October 09, 2010, 05:32:09 pm by calcdude84se »
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: Routines
« Reply #383 on: July 27, 2010, 04:52:33 pm »
yes, mine works by row. i think decompression will be harder, though. because if you run into an F, all your arithmetic has to change to compensate for reading the bytes differently. i think it'd be easiest to make the sequence for starting a run be a full byte, like FF, unless you've found an easy way to decompress already.


Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Routines
« Reply #384 on: July 27, 2010, 04:56:49 pm »
Hm... I'll write it both ways. One that always uses one 'F', or one that uses one or two to get it to a full byte. But I'll start with my way ;)
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Routines
« Reply #385 on: July 27, 2010, 04:58:22 pm »
Maybe it would make it easier to write a quick subroutine that extracts each nibble from the data and returns them one at a time?  That way you dont even have to think about the half byte compression going on?

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: Routines
« Reply #386 on: July 27, 2010, 04:58:39 pm »
i'm going to try to write decompression your way, and we can compare afterwards. and i'm going to edit my RLE compression routine so that if you have an odd number of nibbles, it tacks on an 'F' at the end of the hex string.

great success?

Code: [Select]
.BB
[F71011011100F810]->GDB1
Zeroes(8)->Pic1
[FFFFFFFFFFFFFFFF]
0->X->Y
For(Z,0,15
  If sub(GN,Z)->N=15
    For(U,1,sub(GN,Z+1)
      Pt-On(X*8,Y*8,sub(GN,Z+2)*8+Pic1
      !If X+1->X^6
        0->X:Y+1->Y
      End
    End
    Z+2->Z
  Else
    Pt-On(X*8,Y*8,N*8+Pic1
    !If X+1->X^6
      0->X:Y+1->Y
    End
  End
End
DispGraph
Lbl GN
{r1/2+GDB1}->T
If r1^2
  T^16
Else
  T/16
End

as you can tell, i used builderboy's idea of having a subroutine to get a specific nibble.

edit: edited some whitespace in for readability
« Last Edit: July 27, 2010, 05:51:49 pm by nemo »


Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Routines
« Reply #387 on: August 23, 2010, 07:53:23 pm »
This thread shouldn't be floating down this far! And since I just answered a question in the main thread about how to retrieve data from OS matrices, I may as well post these two routines here:

Code: [Select]
.Returns an element of OS matrix (pointer to matrix, 0-based column, 0-based row)
Lbl M
  float{r₃*{r₁-2}+r₂*9+r₁}
Return

Code: [Select]
.Returns an element of OS matrix (pointer to matrix, 1-based column, 1-based row)
Lbl M
  float{r₃-1*{r₁-2}+(r₂-1)*9+r₁}
Return

Code: [Select]
.Returns an element of OS list (pointer to list, 0-based entry)
Lbl L
  float{r₂*9+r₁}
Return

Code: [Select]
.Returns an element of OS list (pointer to list, 1-based entry)
Lbl L
  float{r₂-1*9+r₁}
Return
« Last Edit: August 23, 2010, 07:54:14 pm by Runer112 »

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55942
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Routines
« Reply #388 on: August 23, 2010, 09:08:34 pm »
darn, I am really out of the loop on new functions, I really need to re-read the command index when I get some time x.x (I last did on 0.2.6)
Now active at https://discord.gg/cuZcfcF (CodeWalrus server)

_player1537

  • Guest
Re: Routines
« Reply #389 on: August 26, 2010, 10:09:01 pm »
darn, I am really out of the loop on new functions, I really need to re-read the command index when I get some time x.x (I last did on 0.2.6)

Lol, I know the feeling :P