- Joined
- Jan 2, 2020
- Messages
- 1,414
I've been working on my game day and night now for the last week or so and getting along with Cerberus really well.
Progress feels great but now I stumped into a problem that causes an immense slowdown on my Android phone so I dedicated the last few nights trying to solve it but no luck. So here I am..
Maybe there are some CX / JAVA experts that knows what needs to be done..
I didn't notice the problem while I was developing on HTML5 and Desktop platforms and and it came as a big surprise
that my Android couldn't handle things quite the same. I know Android can s*ck at things but I was foolish and assumed that this small thing wouldn't be a problem.
I've included a simplified version of the problem below. When I first saw the slowdown my thoughts was that it must be objects being created at runtime.. so I looked around and I managed to throw away most arrays and other things that was buried inside deep loops.
On Android arrays seem to create way more work under the hood than one thinks it should. In a weird way all this got me interested into learning the Android OS because I might need it. About the example code, it might be that you can't barely start. Or it might just work if you got a stronger phone, in that case I urge you too search & replace all 256's and maker them to 512's.
To be able to check if the code is alive I included a moving sprite that moves whenever you touch the screen.
For me it moves very sporadically. If you get it started at all that is. It wil also repeatidly ask the user to kill the game or wait and while it's doing that, you'll see a lot of messages in the console, it basically creates a war inside Android OS.
Am I crazy? All the other platforms manages arrays of 300.000+ integers easily while Android blows a fuze when it reaches just above 10.000 (well in my case).
Progress feels great but now I stumped into a problem that causes an immense slowdown on my Android phone so I dedicated the last few nights trying to solve it but no luck. So here I am..
Maybe there are some CX / JAVA experts that knows what needs to be done..
I didn't notice the problem while I was developing on HTML5 and Desktop platforms and and it came as a big surprise
that my Android couldn't handle things quite the same. I know Android can s*ck at things but I was foolish and assumed that this small thing wouldn't be a problem.
I've included a simplified version of the problem below. When I first saw the slowdown my thoughts was that it must be objects being created at runtime.. so I looked around and I managed to throw away most arrays and other things that was buried inside deep loops.
On Android arrays seem to create way more work under the hood than one thinks it should. In a weird way all this got me interested into learning the Android OS because I might need it. About the example code, it might be that you can't barely start. Or it might just work if you got a stronger phone, in that case I urge you too search & replace all 256's and maker them to 512's.
To be able to check if the code is alive I included a moving sprite that moves whenever you touch the screen.
For me it moves very sporadically. If you get it started at all that is. It wil also repeatidly ask the user to kill the game or wait and while it's doing that, you'll see a lot of messages in the console, it basically creates a war inside Android OS.
Am I crazy? All the other platforms manages arrays of 300.000+ integers easily while Android blows a fuze when it reaches just above 10.000 (well in my case).
Cerberus:
' For web & desktops, all works perfectly
#HTML5_CANVAS_WIDTH = 1280
#HTML5_CANVAS_HEIGHT = 720
#GLFW_WINDOW_WIDTH = 1280
#GLFW_WINDOW_HEIGHT = 720
' For Android, gives me some problem
#ANDROID_SCREEN_ORIENTATION="landscape"
Import mojo2
Import brl.databuffer
Function Main()
New MyGame()
End Function
Class MyGame Extends App
Field map:Int[1280*720] ' CHANGE YOUR RESOLUTION HERE BEFORE RUNNING ON ANDROID
Field canvas:Canvas
Field size:Int = 1
Field mapw:Int = 256
Field maph:Int = 256
Field sx:Int = 0
Field grass:Int = 0
Method OnCreate()
canvas = New Canvas
SetSwapInterval 1 ; SetUpdateRate 0
For Local y = 0 Until maph
For Local x = 0 Until mapw
map[x+y*DeviceWidth()] = 2
Next
Next
Return 0
End Method
Method OnUpdate()
Local tx:Int = TouchX(0) / size, ty:Int = TouchY(0) / size
Return 0
End Method
Method OnRender()
Local w:Int = DeviceWidth()
canvas.Clear 0,0,0
If TouchDown(0) Then sx=sx+4 ; If sx > 1280 Then sx=0
' ----------------------------------------------------------------------------------------------
' This is what I think kills Android, a right loop that counts up 65535 Integers,
' 10000-16000 seems to be the maximum that I can run on my Android phone
' All other platforms seem able to easily cope on a totally different scale
'
For Local y := 0 Until maph Step 1
For Local x:= 0 Until mapw Step 1
Local col:Int = map[x+y*w] ' ???
Local r:Int = col Shr 16 & $FF ; Local g:Int = col Shr 8 & $FF ; Local b:Int = col Shr 0 & $FF
canvas.SetColor Float(r/255.0),Float(g/255.0),Float(b/255.0)
If col = 0 Then canvas.SetColor 0,0,0
If col = 2 Then canvas.SetColor 0,1,0
canvas.DrawRect x*size,y*size,size+0,size+0
Next
Next
' ----------------------------------------------------------------------------------------------
canvas.SetColor 1,1,1
canvas.DrawRect sx,100,64,64
canvas.Flush
End Method
End