Omnimaga
Calculator Community => TI Calculators => TI-BASIC => Topic started by: meishe91 on October 02, 2010, 08:31:21 pm
-
So recently MRide asked for sprites for his Imagination Quest game and I helped with a way of storing them/recalling them. This got me thinking about different ways of doing this. So I thought I would show you guys what I have come up with, but if you guys have any other ways please feel free to share your methods/routines.
Note: My routines are listed according to speed, fastest to slowest (decompression), and by chance size (compressed variable) too, largest to smallest. These also should be as optimized as they can be but I'm sure someone (*cough*nemo*cough* :P) could find something I missed. Also, last thing, all "Es" and "Ls" are the scientific notation E and list token L.
1→D
For(A,Y,Y+H-1
For(B,X,X+W-1
If pxl-Test(A,B
Then
BE6+AE4→K
Repeat not(pxl-Test(A,B
B+1→B
End
AnsE2-E2+A
If K=AnsE4
Then
Ans+.1→LP(D
Else
K+Ans→LP(D
End
D+1→D
End
End
End
For(A,1,dim(LP
LP(A
If fPart(Ans
Then
.01iPart(Ans
Pxl-On(E2fPart(Ans),iPart(Ans
Else
Line(iPart(E2fPart(Ans/E8)),-iPart(E2fPart(Ans/E6)),iPart(E2fPart(Ans/E4)),-iPart(E2fPart(Ans/E2
End
End
1→D
For(A,Y,Y+H-1
For(B,X,X+W-1
If pxl-Test(A,B
Then
BE6+AE4→K
Repeat not(pxl-Test(A,B
B+1→B
End
K+BE2-E2+A→LQ(D
D+1→D
End
End
End
For(A,1,dim(LQ
LQ(A
Line(iPart(E2fPart(Ans/E8)),-iPart(E2fPart(Ans/E6)),iPart(E2fPart(Ans/E4)),-iPart(E2fPart(Ans/E2
End
"_Str3
{0,1→L1
For(A,Y,Y+H-1
For(B,X,X+W-1
If pxl-Test(A,B
Then
BE6+AE4→K
Repeat not(pxl-Test(A,B
B+1→B
End
{0,K+BE2-E2+A→L
LineReg(ax+b) Y1
Equ►String(Y1,Str4
sub(Str4,1,length(Str4)-3→Str4
If 7=length(Str4
Str3+"0→Str3
If 6=length(Str4
Str3+"00→Str3
Str3+Str4→Str3
End
End
End
sub(Ans,2,length(Ans)-1→Str3
For(A,1,length(Str3
expr(sub(Str3,A,8
Line(iPart(E2fPart(Ans/E8)),-iPart(E2fPart(Ans/E6)),iPart(E2fPart(Ans/E4)),-iPart(E2fPart(Ans/E2
A+7→A
End
{0,1→L1
"_→Str1
For(A,Y,Y+H-1
For(B,X,X+W-1
If pxl-Test(A,b
Then
BE6+AE4→K
Repeat not(pxl-Test(A,B
B+1→B
End
BE2-E2+A→L
If K=AnsE4
Then
Str1+"+→Str1
Else
Str1+"-→Str1
End
{0,K(K≠LE4)+L→L2
LinReg(ax+b) Y1
Equ►String(Y1,Str2
sub(Str2,1,length(Str2)-3→Str2
If 2=length(Ans
Str1+"00→Str1
If max(length(Str2)={3,7
Str1+"0→Str1
Str1+Str2→Str1
End
End
End
sub(Ans,2,length(Ans)-1→Str1
"expr(sub(Str1,A+1,Ans→u
For(A,1,length(Str1
If sub(Str1,A,1)="+
Then
4
.01u
Pxl-On(E2fPart(Ans),iPart(Ans
A+4→A
Else
8
u
Line(iPart(E2fPart(Ans/E8)),-iPart(E2fPart(Ans/E6)),iPart(E2fPart(Ans/E4)),-iPart(E2fPart(Ans/E2
A+8→A
End
End
Note:
The way to use the compression routines is to do Width→W:Height→H:Upper-Left X-Coordinate→X:Upper-Left Y-Coordinate→Y:prgmRoutine or something like that. The decompression routines can just be run (assuming you've compressed already).
Like I said, this is open for other people to show their own routines for compressing/decompressing and sprite. I hope someone finds these useful :)
-
AnsE2-E2+A
can't that just be Ans+A?
right... oops. for a second i thought that Ans would be less than 10.. don't know why. but hey. i'll find something else.. just give me a second.
i had to break away from my schoolwork *just* so i could find something to optimize ;D oh, and your last String decompression code block is nested within the compression code block. these look neat, i'll check them out more thoroughly later
-
Looks neat. I'm sure these are impressive. Nice job! ;D
-
Nice! Lots of compression there :)
-
Thanks guys :) That last decompression routine I think would only be good for smaller sprites. It can take a while to decompress unfortunately, but it is the smallest when compressed. (Darn you size at the risk of speed)
/me shakes fist angrily in the air
AnsE2-E2+A
can't that just be Ans+A?
right... oops. for a second i thought that Ans would be less than 10.. don't know why. but hey. i'll find something else.. just give me a second.
i had to break away from my schoolwork *just* so i could find something to optimize ;D oh, and your last String decompression code block is nested within the compression code block. these look neat, i'll check them out more thoroughly later
Ya, I was about to say it can't be just that. I'm sure you will :P
Also, thanks! I could not figure out why that "[/code][/code]" kept showing up at the bottom. I'm not sure how I missed that...I'm usually good about that.
-
Line(iPart(E2fPart(Ans/E8)),-iPart(E2fPart(Ans/E6)),iPart(E2fPart(Ans/E4)),-iPart(E2fPart(Ans/E2
to..
seq(iPart(E2fPart(Ans/10^(X))),X,2,8,2 //the token 10^(
Line(Ans(4),-Ans(3),Ans(2),-Ans(1
definitely a size optimization.. you'll probably take a hit on speed.
-
Ah, ya. I didn't think about using seq( at all, mainly because I never really use it >.> But ya, that could work. Only thing though is with decompressions you might need to have them as fast as you can. But ya, that is an option :) Thanks.
-
I try not to use seq( as it's extremely slow. :) It's really useful when you don't need speed, though. ;D
-
Nice stuff meishe!
-
Thank ya :) Took about a day to create the other three and debug them and all, then maybe an hour going through trying to optimize them as much as I could, which seemed to be good besides nemo's seq( tip (just had to find something, didn't you ;)). Then posted :)
-
Yeah Seq is good for compression sometimes but in some cases it is not very efficient for speed. In ROL3 I had a decompression routine for loading saved files, and it took about 3 seconds to decompress 70-80 lists elements. For Illusiat 13's 100 items, it takes 6 seconds. ROL3 decompressing is hard-coded while Illusiat 13 uses seq(). ROL decompressing program was about 600-700 bytes, if I remember, though.