Author Topic: Making my code faster  (Read 4999 times)

0 Members and 1 Guest are viewing this topic.

Offline p2

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 849
  • Rating: +51/-11
  • I'm back :)
    • View Profile
Making my code faster
« on: September 09, 2011, 01:49:04 pm »
Is it possible to make my code faster?
(I want to make a few different difficulty-modes!)

EDIT: Screenie!!

(It's with sound - so you should try it on your TI!)

CARAXE is the ASM-program
The other programs are the surcecode! (CAR is the main-program)
« Last Edit: September 09, 2011, 02:02:49 pm by p2 »
*insert supercool signature*

Offline Eeems

  • Mr. Dictator
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6268
  • Rating: +318/-36
  • little oof
    • View Profile
    • Eeems
Re: Making my code faster
« Reply #1 on: September 09, 2011, 02:44:55 pm »
Frameskipping would speed it up. ( So only display every other frame ).
/e

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Making my code faster
« Reply #2 on: September 09, 2011, 03:50:23 pm »
Pause statements is a crude way, but it works well.

Wouldn't that make the game slower, not faster?


Frameskipping would speed it up. ( So only display every other frame ).

With that, the game speed would remain the same, but it would be even choppier (notes and such would pass at half speed but seemingly at 2 pixels per jump)

Each frame sent to the screen takes about 1/100th of a second, and on top of that there's the time needed to render the frame. Cutting out about 15-20 of these per second would certainly save a lot of processing time, allowing the game to run faster.
« Last Edit: September 09, 2011, 03:51:59 pm by Runer112 »

Offline Eeems

  • Mr. Dictator
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6268
  • Rating: +318/-36
  • little oof
    • View Profile
    • Eeems
Re: Making my code faster
« Reply #3 on: September 09, 2011, 03:52:40 pm »
Frameskipping would speed it up. ( So only display every other frame ).

With that, the game speed would remain the same, but it would be even choppier (notes and such would pass at half speed but seemingly at 2 pixels per jump)
Not at all, you see a lot of processing time is taken in displaying a frame. In TBP I gain a lot of speed by skipping a few frames. You do move two pixels, but it seems to move faster because in truth, the program has more time to work on the actual processing of whatever needs to be done in the background because all the foreground code ( so the displaying ) isn't taking up as much time. The game does start getting pretty choppy when you start skipping a lot of frames but usually just a one fameskip isn't noticeable unless you are looking closely.

EDIT: ninja'd :P With a much better explanation.
« Last Edit: September 09, 2011, 03:54:11 pm by Eeems »
/e

Offline p2

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 849
  • Rating: +51/-11
  • I'm back :)
    • View Profile
Re: Making my code faster
« Reply #4 on: September 10, 2011, 11:06:03 am »
Er...
So may someone of you tell me how to make it faster??

The speed is more important than the size of the program!
*insert supercool signature*

Offline MGOS

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 336
  • Rating: +95/-0
    • View Profile
Re: Making my code faster
« Reply #5 on: September 10, 2011, 11:47:42 am »
I'd use a counter variable and skip every second / third frame using an if statement with the modulus operator ^.


Code: [Select]
0->C   .Counter variable
game loop
   .do calculations here
   !If C^2    .Increase number to skip more frames -> gain more speed
      .do drawing stuff / displaying here
   End
   C++
End
« Last Edit: September 10, 2011, 11:50:23 am by MGOS »

Offline p2

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 849
  • Rating: +51/-11
  • I'm back :)
    • View Profile
Re: Making my code faster
« Reply #6 on: September 10, 2011, 11:52:20 am »
Er...
a CALCULATOR game.
Or can you write that in Axe??

Aniway, Thanx!
*insert supercool signature*

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Making my code faster
« Reply #7 on: September 10, 2011, 11:54:48 am »
Er...
a CALCULATOR game.
Or can you write that in Axe??

Aniway, Thanx!
It is written in Axe. ;)
If you're wondering about the ++ operator, it's been in Axe since 0.5.2 or so, and if you're wondering about the ^ operator, it's been in Axe since before 0.1.0.

Offline Happybobjr

  • James Oldiges
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2325
  • Rating: +128/-20
  • Howdy :)
    • View Profile
Re: Making my code faster
« Reply #8 on: September 10, 2011, 11:56:49 am »
Here i optimized it a bit.  A big problem you have is the line...
Dispgraph
Dispgraph^r


(note that i changed some things so this has a chance of not working the way you wish.)
School: East Central High School
 
Axe: 1.0.0
TI-84 +SE  ||| OS: 2.53 MP (patched) ||| Version: "M"
TI-Nspire    |||  Lent out, and never returned
____________________________________________________________

Offline p2

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 849
  • Rating: +51/-11
  • I'm back :)
    • View Profile
Re: Making my code faster
« Reply #9 on: September 10, 2011, 11:59:54 am »
I hope it'll be faster!!
*insert supercool signature*

Offline Happybobjr

  • James Oldiges
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2325
  • Rating: +128/-20
  • Howdy :)
    • View Profile
Re: Making my code faster
« Reply #10 on: September 10, 2011, 12:16:51 pm »
tell me if it is :)
i hoped that helped.  There is some definite improvisation possibilities, but I can't think too hard right now :P
School: East Central High School
 
Axe: 1.0.0
TI-84 +SE  ||| OS: 2.53 MP (patched) ||| Version: "M"
TI-Nspire    |||  Lent out, and never returned
____________________________________________________________