Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
19 May, 2013, 17:19:26 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   home   news downloads projects tutorials misc forums rules new posts irc about Login Register  
+-OmnomIRC

You must Register, be logged in and have at least 40 posts to use this shout-box! If it still doesn't show up afterward, it might be that OmnomIRC is disabled for your group or under maintenance.

Note: You can also use an IRC client like mIRC, X-Chat or Mibbit to connect to an EFnet server and #omnimaga.

Pages: [1] 2   Go Down
  Print  
Author Topic: Optimization Help -  (Read 870 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
Runer112
Anti-Riot Squad
LV10 31337 u53r (Next: 2000)
*
Offline Offline

Gender: Male
Last Login: Today at 07:50:48
Date Registered: 02 July, 2009, 06:38:05
Posts: 1679


Total Post Ratings: +492

View Profile
« on: 04 April, 2012, 06:45:31 »
+3

Here's a simple, fairly optimized way to do what you are trying to achieve. I have detailed most of the optimizations in comments in the code, but I did not comment about the biggest optimization. This optimization is to draw sprites from a variable pointer, instead of requiring four different copies of the whole loop just for facing in different directions. For instance, here's the line I used to initialize the player sprite to the right-facing sprite:

:2*8+Pic1→S

If you're familiar with how this works, then go ahead and skip to looking at the code to see the final product with the rest of my suggested simple optimizations. If you're not familiar with how this works, I'll give a quick explanation. Because of how Axe includes data like sprites, the order in which you list data (like sprites) is exactly the order it will assume in the compiled program. Since each sprite is 8 bytes, that means that each successive sprite is found in memory 8 bytes after the previous sprite. Pic1 points to the start of the block of 4 sprites, so it points to the first one, the down-facing sprite. 2*8+Pic1 would point to the data 16 bytes after the down-facing sprite, which we know is the right-facing sprite because it's 2 sprites (remember, a sprite is 8 bytes) after the down-facing sprite. This offset from Pic1 logic is used to draw the proper sprite for facing in all 4 directions.


So here's my suggested fairly optimized and hopefully easy-to-understand solution:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
:.AXETEST
:identity(3FFC3FFC30CF30CF300C300C0C300C303FFC3FFC330C330C3FFC3FFCF00FF00F)
:
:[]→Pic1
:[7E665A247EC37EC3] .DOWN
:[7ED242247E4A7EC3] .LEFT
:[7E4B42247E527EC3] .RIGHT
:[7E7E42247EC37EC3] .UP
:
:.START FACING RIGHT AT (0,56):
:2*8+Pic1→S
:0→X
:56→Y
:.THIS DOESN'T NEED TO BE INSIDE THE LOOP:
:StorePic
:
:While 1
: Pt-On(X,Y,S)
: DispGraph
: .ERASING WITH Pt-Change() UNNECESSARY BECAUSE:
: RecallPic
: If getKey(1)
:  Y+2→Y
:  0*8+Pic1→S
: End
: If getKey(2)
:  X-2→X
:  1*8+Pic1→S
: End
: If getKey(3)
:  X+2→X
:  2*8+Pic1→S
: End
: If getKey(4)
:  Y-2→Y
:  3*8+Pic1→S
: End
:.OPTIMIZED POST-CHECK LOOP:
:End!If getKey(15)





Now, if you want really optimized code... That can be arranged. You just lost the game I'll leave figuring out how it works as an exercise.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
:.AXETEST
:identity(3FFC3FFC30CF30CF300C300C0C300C303FFC3FFC330C330C3FFC3FFCF00FF00F)
:
:[]→Pic1
:[7ED242247E4A7EC3] .LEFT
:[7E7E42247EC37EC3] .UP
:[7E4B42247E527EC3] .RIGHT
:[7E665A247EC37EC3] .DOWN
:
:56→Y
: and 0→X
:→S
:
:While 1
: ClrDraw
: Pt-On(X,Y,S*8+16+Pic1)
: DispGraph
: If getKey(1)-getKey(4)
:  →S
:  *2+Y→Y
: End
: If getKey(3)-getKey(2)
:  -1→S+1
:  *2+X→X
: End
:EndIf getKey(15)
« Last Edit: 04 April, 2012, 06:52:43 by Runer112 » Logged
Pages: [1] 2   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
Powered by MySQL Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Powered by PHP
Page created in 0.402 seconds with 31 queries.
Skin by DJ Omnimaga edited from SMF default theme with the help of tr1p1ea.
All programs, games and songs avaliable on this website are property of their respective owners.
Best viewed in Opera, Firefox, Chrome and Safari with a resolution of 1024x768 or above.