Author Topic: Versatile basic platformer engine -- optimization help?  (Read 2353 times)

0 Members and 1 Guest are viewing this topic.

Offline gcolella

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 13
  • Rating: +9/-0
    • View Profile
Versatile basic platformer engine -- optimization help?
« on: March 21, 2011, 05:41:54 pm »
I wrote this really basic engine for platformers in BASIC that spans two screens. It doesn't use any pictures, but it does use 3 lists, one for each screen (contains all the pixels) and one that's for misc variables, but as of now only contains the starting position. It runs pretty slowly though, and I'm not good at optimization..

PS: I know that there's a memory leak, but it sped it up a lot.

Code for engine:
Code: [Select]
:0→O
:∟ENG(1)→D
:ClrDraw
:For(X,1,dim(∟P1))
:If ∟P1(X)
:Pxl-On(100fPart(∟P1(X)),int(∟P1(X)))
:End
:int(D)→X
:100fPart(D)→Y
:0→S
:Lbl 1
:S+1→S
:Text(1,1,S)
:getKey→G
:Pxl-On(Y,X)
:Pxl-On(Y,X+1)
:Pxl-On(Y-1,X+1)
:Pxl-On(Y-1,X)
:X→A
:Y→B
:If X≥4:Then
:If G=24 and not((pxl-Test(Y,X-1) or pxl-Test(Y-1,X-1)) or (pxl-Test(Y,X-2) or pxl-Test(Y-1,X-2)):Then
:X-2→X
:Goto 0
:End
:End
:If X≤90:Then
:If G=26 and not((pxl-Test(Y,X+2) or pxl-Test(Y-1,X+2)) or (pxl-Test(Y,X+3) or pxl-Test(Y-1,X+3)):Then
:X+2→X
:Goto 0
:End
:End
:
:If ((not(pxl-Test(Y-2,X) or pxl-Test(Y-3,X))) and G=25) and ((pxl-Test(Y+1,X) or pxl-Test(Y+1,X+1)):Then
:O-3→O
:Goto 0
:End
:If X≤91:Then
:If (((G=26 and (pxl-Test(Y,X+2) and pxl-Test(Y+1,X+2)) and not(pxl-Test(Y-1,X+2)))):Then
:X+1→X
:Y-1→Y
:Goto 0
:Else
:If G=26 and pxl-Test(Y,X+3):Then
:X+1→X
:Goto 0
:End
:End
:End
:If X≥2:Then
:If ((G=24) and (pxl-Test(Y,X-1) and pxl-Test(Y+1,X-1))) and not(pxl-Test(Y-1,X-1)):Then
:Y-1→Y
:X-1→X
:Goto 0
:Else
:If G=24 and pxl-Test(Y,X-2):Then
:X-1→X
:Goto 0
:End
:End
:End
:Lbl 0
:If (not((pxl-Test(Y+1,X) or pxl-Test(Y+1,X+1)):Then
:Y+1→Y
:If O<0
:O+1→O
:End
:
:If X≤4:Then
:Y→E
:ClrDraw
:E→Y
:For(X,1,dim(∟P1))
:If ∟P1(X)
:Pxl-On(100fPart(∟P1(X)),int(∟P1(X)))
:End
:90→X
:End
:If X≥91:Then
:Y→E
:ClrDraw
:For(X,1,dim(∟P2))
:If ∟P2(X)
:Pxl-On(100fPart(∟P2(X)),int(∟P2(X)))
:End
:E→Y
:5→X
:End
:O+Y→Y
:Pxl-Off(B,A)
:Pxl-Off(B,A+1)
:Pxl-Off(B-1,A+1)
:Pxl-Off(B-1,A)
:Goto 1
Generated by SourceCoder (http://sc.cemetech.net)
© 2005-2010 Cemetech (http://www.cemetech.net)

Code for routine that takes pic1 and pic2 and stores them into the lists the program uses (lP1 and lP2):
Code: [Select]
:ClrDraw
:RecallPic Pic1
:1→S
:For(X,1,94)
:For(Y,1,62)
:If pxl-Test(Y,X):Then
:S+1→dim(∟P1)
:(X+(Y/100))→∟P1(S)
:S+1→S
:End
:Output(8,int(X/12)+1,"*")
:End
:End
:ClrDraw
:RecallPic Pic2
:1→S
:For(X,1,94)
:For(Y,1,62)
:If pxl-Test(Y,X):Then
:S+1→dim(∟P2)
:(X+(Y/100))→∟P2(S)
:S+1→S
:End
:Output(8,int(X/12)+8,"*")
:End
:End
Generated by SourceCoder (http://sc.cemetech.net)
© 2005-2010 Cemetech (http://www.cemetech.net)

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: Versatile basic platformer engine -- optimization help?
« Reply #1 on: March 21, 2011, 05:47:42 pm »
I know you mentioned the memory leak, but that Goto 0 thing is going to lose a LOT of memory with all of those End statements. You should seriously consider fixing that, even at the expense of speed. It doesn't really matter how fast your program is if users get ERR:MEM from running it too much.

Otherwise, nice. I'll look at it when I get back from everything I have to do today.
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline gcolella

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 13
  • Rating: +9/-0
    • View Profile
Re: Versatile basic platformer engine -- optimization help?
« Reply #2 on: March 21, 2011, 06:14:37 pm »
It actually works fine without any of the goto 0's as well, it just saves it from doing all the other tests when you've already moved that frame. I see what you mean though, if I get it faster I'll remove them. Also, is the memory restored after the program finishes?

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Versatile basic platformer engine -- optimization help?
« Reply #3 on: March 21, 2011, 06:17:04 pm »
It actually works fine without any of the goto 0's as well, it just saves it from doing all the other tests when you've already moved that frame. I see what you mean though, if I get it faster I'll remove them. Also, is the memory restored after the program finishes?

It is restored, but while the program runs you'll notice that it gets slower and slower. That's the memory leak.