Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
22 May, 2013, 01:54:43 *
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 872 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
Spenceboy98
LV6 Super Member (Next: 500)
******
Offline Offline

Gender: Male
Last Login: Today at 00:14:37
Date Registered: 17 February, 2012, 02:46:51
Location: Gaffney, South Carolina
Posts: 384


Topic starter
Total Post Ratings: +46

View Profile
« on: 04 April, 2012, 05:29:46 »
0

I don't know how to optimize Axe code, so I am asking for help.

What original code does:



Code:

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
:.AXETEST
:identity(3FFC3FFC30CF30CF300C300C0C300C303FFC3FFC330C330C3FFC3FFCF00FF00F)
:0→X
:56→Y
:[7E4B42247E527EC3]→Pic1
:Repeat getKey(15)
:StorePic
:Pt-On(X,Y,Pic1)
:DispGraph
:Pt-Change(X,Y,Pic1
:RecallPic
:If getKey(2)
:Lbl PIP
:[7ED242247E4A7EC3]→Pic2
:X-1→X
:Goto LEFT
:End
:If getKey(3)
:Lbl PI
:X+2→X
:End
:If getKey(4)
:Lbl IP
:[7E7E42247EC37EC3]→Pic3
:Y-1→Y
:Goto UP
:End
:If getKey(1)
:Lbl PIPI
:[7E665A247EC37EC3]→Pic4
:Y+1→Y
:Goto DOWN
:End
:End
:Lbl LEFT
:Repeat getKey(15)
:StorePic
:Pt-On(X,Y,Pic2)
:DispGraph
:Pt-Change(X,Y,Pic2
:RecallPic
:If getKey(2)
:X-2→X
:End
:If getKey(3)
:Goto PI
:End
:If getKey(4)
:Goto IP
:End
:If getKey(1)
:Goto PIPI
:End
:End
:Lbl UP
:Repeat getKey(15)
:StorePic
:Pt-On(X,Y,Pic3)
:DispGraph
:Pt-Change(X,Y,Pic3)
:RecallPic
:If getKey(4)
:Y-1→Y
:End
:If getKey(2)
:Goto PIP
:End
:If getKey(3)
:Goto PI
:End
:If getKey(1)
:Goto PIPI
:End
:End
:Lbl DOWN
:Repeat getKey(15)
:StorePic
:Pt-On(X,Y,Pic4
:DispGraph
:Pt-Change(X,Y,Pic4
:RecallPic
:If getKey(1)
:Y+1→Y
:End
:If getKey(2)
:Goto PIP
:End
:If getKey(3)
:Goto PI
:End
:If getKey(4)
:Goto IP
:End
:End
:


Is there any way to optimize it?
Logged

DERSH IMPERSHIBER!!!

NerdTests.com says I'm a Nerd King.  Click here to take the Nerd Test, get geeky images and jokes, and talk to others on the nerd forum!
Runer112
Anti-Riot Squad
LV10 31337 u53r (Next: 2000)
*
Online Online

Gender: Male
Last Login: Today at 01:54:42
Date Registered: 02 July, 2009, 06:38:05
Posts: 1679


Total Post Ratings: +492

View Profile
« Reply #1 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
shmibs
bonsai bok choy wiseguy waterboy
Administrator
LV10 31337 u53r (Next: 2000)
*
Offline Offline

Last Login: Today at 00:51:09
Date Registered: 11 June, 2010, 19:36:15
Location: 89B6
Posts: 1845


Total Post Ratings: +233

View Profile
« Reply #2 on: 04 April, 2012, 06:54:09 »
0

EDIT:ninjasked

it's just moving up/down/left/right and remembering the direction the character is facing? i'd structure it differently, with something like this:


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
41
ClrDraw
DiagnosticsOff
.A=x_pos, B=y_pos, C=direction_faced
0->A->B->C
[sprite data, one after another, ordered up, down, left, right stored here]->Pic1

Repeat getkey(15)

if getkey(4)-getkey(1)
.go up
if getkey(4)
-1->C
B--
end

.go down
if getkey(1)
->C
B++
end
end

if getkey(2)-getkey(3)
.go left
if getkey(2)
+1->C
A--
end

.go right
if getkey(3)
+2->C
A++
end
end

ClrDraw
Pt-On(A,B,C*8+Pic1
DispGraph
end
« Last Edit: 04 April, 2012, 07:27:25 by shmibs » Logged



We're not human, are we?
Spenceboy98
LV6 Super Member (Next: 500)
******
Offline Offline

Gender: Male
Last Login: Today at 00:14:37
Date Registered: 17 February, 2012, 02:46:51
Location: Gaffney, South Carolina
Posts: 384


Topic starter
Total Post Ratings: +46

View Profile
« Reply #3 on: 05 April, 2012, 03:31:17 »
0

Thank you!
Logged

DERSH IMPERSHIBER!!!

NerdTests.com says I'm a Nerd King.  Click here to take the Nerd Test, get geeky images and jokes, and talk to others on the nerd forum!
Spenceboy98
LV6 Super Member (Next: 500)
******
Offline Offline

Gender: Male
Last Login: Today at 00:14:37
Date Registered: 17 February, 2012, 02:46:51
Location: Gaffney, South Carolina
Posts: 384


Topic starter
Total Post Ratings: +46

View Profile
« Reply #4 on: 06 April, 2012, 03:12:48 »
0

All this does is display the sprite, but I still need it optimized:



Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
:.KARRACE
:identity(318C4BD24FF24E724FF2366C0FF0166818181BD87BDE981997E99FF99FF967E6)
:.KAR
:[314B4F4E4F360F16]→Pic1
:[8CD2F272F26CF068]→Pic2
:[181B7B98979F9F67]→Pic3
:[18D8DE19E9F9F9E6]→Pic4
:.DRAW
:Repeat getKey(15)
:Pt-On(0,0,Pic1
:Pt-On(0,8,Pic3
:Pt-On(8,0,Pic2
:Pt-On(8,8,Pic4
:DispGraph
:End

I know there is a way to optimize it, but I don't know how.
Logged

DERSH IMPERSHIBER!!!

NerdTests.com says I'm a Nerd King.  Click here to take the Nerd Test, get geeky images and jokes, and talk to others on the nerd forum!
Happybobjr
James Oldiges
LV11 Super Veteran (Next: 3000)
***********
Online Online

Gender: Male
Last Login: Today at 01:54:28
Date Registered: 01 June, 2010, 00:52:05
Location: IN, United States
Posts: 2273


Total Post Ratings: +100

View Profile
« Reply #5 on: 06 April, 2012, 03:41:20 »
0

Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
:.KARRACE
:identity(318C4BD24FF24E724FF2366C0FF0166818181BD87BDE981997E99FF99FF967E6)
:.KAR
:[314B4F4E4F360F16]→Pic1
:[8CD2F272F26CF068]→Pic2
:[181B7B98979F9F67]→Pic3
:[18D8DE19E9F9F9E6]→Pic4
:.DRAW
:Repeat getKey(15)
:Pt-On(0,,Pic1
:Pt-On(0,8,Pic3
:Pt-On(8,0,Pic2
:Pt-On(8,,Pic4
:DispGraph
:End


that's all i see
Edit: It will be best to stick with Pt-On IMO, as you already have the command in the previous and assumed related code
« Last Edit: 06 April, 2012, 03:43:15 by Happybobjr » Logged

School: East Central High School

Axe: 1.0.0
TI-84 +SE  ||| OS: 2.53 MP (patched) ||| Version: "M"
TI-Nspire    |||  Non-Cas |||  OS: 1.1 |||  Build: Old  |||  84+ keypad.   Being lent out
____________________________________________________________
squidgetx
Food.
Coder Of Tomorrow
LV10 31337 u53r (Next: 2000)
*
Offline Offline

Gender: Male
Last Login: Yesterday at 18:24:17
Date Registered: 30 May, 2010, 19:54:18
Location: eating somewhere
Posts: 1831


Total Post Ratings: +476

View Profile
« Reply #6 on: 06 April, 2012, 04:32:07 »
0

Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
:.KARRACE
:identity(318C4BD24FF24E724FF2366C0FF0166818181BD87BDE981997E99FF99FF967E6)
:.KAR
:[314B4F4E4F360F16]→Pic1
:[8CD2F272F26CF068]→Pic2
:[181B7B98979F9F67]→Pic3
:[18D8DE19E9F9F9E6]→Pic4
:.DRAW
:Repeat getKey(15)
:Pt-On(0,,Pic1
:Pt-On(0,8,Pic3
:Pt-On(8,0,Pic2
:Pt-On(8,,Pic4
:DispGraph
:End


that's all i see
Edit: It will be best to stick with Pt-On IMO, as you already have the command in the previous and assumed related code
Even this is unnecessary due to the new peephole optimizer Tongue Although I believe (I need Runer to confirm) that a While 1 : EndIf getKey(15) might be better than Repeat getKey(15) : End
Logged

Read my webcomic! | My SoundCloud
Projects:

Check out the demo now!- Current progress: battle engine and stuff
Proud author of: Cuberunner | SpaceDash | The Psyche | XXEdit | AxeSynth | StickNinja | Gravity Guy | Embers:Phoenix | Zombie Gun
Axe: Need help optimizing?
User of Axe | zStart | TokenIDE | CalcGS | MirageOS
Spenceboy98
LV6 Super Member (Next: 500)
******
Offline Offline

Gender: Male
Last Login: Today at 00:14:37
Date Registered: 17 February, 2012, 02:46:51
Location: Gaffney, South Carolina
Posts: 384


Topic starter
Total Post Ratings: +46

View Profile
« Reply #7 on: 06 April, 2012, 08:32:23 »
0

What is this "peephole optimizer" of which you speak? How do I use it?
Logged

DERSH IMPERSHIBER!!!

NerdTests.com says I'm a Nerd King.  Click here to take the Nerd Test, get geeky images and jokes, and talk to others on the nerd forum!
chattahippie
LV6 Super Member (Next: 500)
******
Offline Offline

Gender: Male
Last Login: 27 March, 2013, 05:21:38
Date Registered: 19 July, 2011, 04:13:49
Location: Somewhere
Posts: 358


Total Post Ratings: +27

View Profile
« Reply #8 on: 06 April, 2012, 08:49:35 »
0

What is this "peephole optimizer" of which you speak? How do I use it?

It's built into Axe, so you really don't have to do anything to use it, just compile like normal.  However, you can choose not to use it by pressing [zoom] at the compile menu instead of [Enter] or [2nd]
Logged
Runer112
Anti-Riot Squad
LV10 31337 u53r (Next: 2000)
*
Online Online

Gender: Male
Last Login: Today at 01:54:42
Date Registered: 02 July, 2009, 06:38:05
Posts: 1679


Total Post Ratings: +492

View Profile
« Reply #9 on: 06 April, 2012, 17:52:36 »
0

Even this is unnecessary due to the new peephole optimizer Tongue

It would make sense to think this, but this is actually not true. A peephole optimization to do this was added in Axe 1.0.5, but it was disabled in the next version (Axe 1.1.0) and has been ever since. Don't ask me why because I don't know; a quick test with Axe 1.0.5 appears to suggest that the optimization works fine. Perhaps I'll ask Quigibo in a more appropriate thread why this optimization (called o_PushPop5 in Commands.inc) is disabled.


Although I believe (I need Runer to confirm) that a While 1 : EndIf getKey(15) might be better than Repeat getKey(15) : End

This is true. Smiley
« Last Edit: 06 April, 2012, 18:01:24 by Runer112 » Logged
squidgetx
Food.
Coder Of Tomorrow
LV10 31337 u53r (Next: 2000)
*
Offline Offline

Gender: Male
Last Login: Yesterday at 18:24:17
Date Registered: 30 May, 2010, 19:54:18
Location: eating somewhere
Posts: 1831


Total Post Ratings: +476

View Profile
« Reply #10 on: 07 April, 2012, 19:57:15 »
0

Even this is unnecessary due to the new peephole optimizer Tongue

It would make sense to think this, but this is actually not true. A peephole optimization to do this was added in Axe 1.0.5, but it was disabled in the next version (Axe 1.1.0) and has been ever since. Don't ask me why because I don't know; a quick test with Axe 1.0.5 appears to suggest that the optimization works fine. Perhaps I'll ask Quigibo in a more appropriate thread why this optimization (called o_PushPop5 in Commands.inc) is disabled.


Although I believe (I need Runer to confirm) that a While 1 : EndIf getKey(15) might be better than Repeat getKey(15) : End

This is true. Smiley

Wow, really? That is weird (The first part). By habit i automatically will type "0,," instead of "0,0" but thanks O.o.

Also thanks for the second part too. In terms of what they accomplish they are exactly the same, no? (Well I guess using Repeat checks the condition at the beginning, where the EndIf version checks at the end?)
Logged

Read my webcomic! | My SoundCloud
Projects:

Check out the demo now!- Current progress: battle engine and stuff
Proud author of: Cuberunner | SpaceDash | The Psyche | XXEdit | AxeSynth | StickNinja | Gravity Guy | Embers:Phoenix | Zombie Gun
Axe: Need help optimizing?
User of Axe | zStart | TokenIDE | CalcGS | MirageOS
Spenceboy98
LV6 Super Member (Next: 500)
******
Offline Offline

Gender: Male
Last Login: Today at 00:14:37
Date Registered: 17 February, 2012, 02:46:51
Location: Gaffney, South Carolina
Posts: 384


Topic starter
Total Post Ratings: +46

View Profile
« Reply #11 on: 03 January, 2013, 05:51:41 »
0

I was looking through the code of Eat Nethams(it seemed easy) to try to understand it. I'm having trouble figuring out how it is displaying so many lobsters at once. Can someone explain this to me?
Logged

DERSH IMPERSHIBER!!!

NerdTests.com says I'm a Nerd King.  Click here to take the Nerd Test, get geeky images and jokes, and talk to others on the nerd forum!
Spenceboy98
LV6 Super Member (Next: 500)
******
Offline Offline

Gender: Male
Last Login: Today at 00:14:37
Date Registered: 17 February, 2012, 02:46:51
Location: Gaffney, South Carolina
Posts: 384


Topic starter
Total Post Ratings: +46

View Profile
« Reply #12 on: 14 January, 2013, 00:31:48 »
0

I was looking through the code of Eat Nethams(it seemed easy) to try to understand it. I'm having trouble figuring out how it is displaying so many lobsters at once. Can someone explain this to me?

*BUMP*
Can no one help me with this^^^^?
Logged

DERSH IMPERSHIBER!!!

NerdTests.com says I'm a Nerd King.  Click here to take the Nerd Test, get geeky images and jokes, and talk to others on the nerd forum!
Deep Thought
So much to do, so much time, so little motivation
Administrator
LV13 Extreme Addict (Next: 9001)
*
Offline Offline

Gender: Male
Last Login: 19 May, 2013, 19:18:47
Date Registered: 19 May, 2009, 08:00:00
Location: The Universe
Posts: 7813


Total Post Ratings: +706

View Profile WWW
« Reply #13 on: 14 January, 2013, 00:35:17 »
0

I was looking through the code of Eat Nethams(it seemed easy) to try to understand it. I'm having trouble figuring out how it is displaying so many lobsters at once. Can someone explain this to me?
*BUMP*
Can no one help me with this^^^^?
They're all sprites, and you can draw as many sprites as you want. I don't quite understand what you mean Huh?
Logged




Spenceboy98
LV6 Super Member (Next: 500)
******
Offline Offline

Gender: Male
Last Login: Today at 00:14:37
Date Registered: 17 February, 2012, 02:46:51
Location: Gaffney, South Carolina
Posts: 384


Topic starter
Total Post Ratings: +46

View Profile
« Reply #14 on: 14 January, 2013, 00:43:50 »
0

But it only has one instance of saying Pt-On. How is it displaying so many without anymore?
Logged

DERSH IMPERSHIBER!!!

NerdTests.com says I'm a Nerd King.  Click here to take the Nerd Test, get geeky images and jokes, and talk to others on the nerd forum!
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 1.796 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.