Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Help: big performance problems with Box2D, Windows XP and Android.

Author
Message
MarcoBruti
12
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Caput Mundi
Posted: 20th Mar 2012 00:38
I am developing a flipper (see AppGameKit showcase), using Windows XP SP3 and Samsung Galaxy GIO (Android 2.3.6) as mobile platform.
Problems on Windows XP: after some minuts of app running fine, the game begins running slowly and slowly, and CPU usage raises to 30%.
Problems on AppGameKit app on Samsung Android: after displaying the choice menu when one chooses the flipper to play with, app crashes and returns to the desktop.
The app uses Box2D, most of sprites are static (targets and tunnel elements), some dynamic sprites (ball and moving barriers), others are kinematic (the flippers).
I use a directory to store files where flipper layout is stored as text file.
Anyone can help me? I am very near to end the project, I would like to publish the app, but this is a very frustrating problem. I suppose there is some problem with memory heap management in Box2D library because performance gradually degrades.
Attached there are screenshots of application, to have some idea of the complexity. I use percentage based screen coordinates.

Attachments

Login to view attachments
3d point in space
14
Years of Service
User Offline
Joined: 30th Jun 2009
Location: Idaho
Posted: 20th Mar 2012 05:39
I made a pinball app also so I might be able to help. You explain things here really bad so I really don't know what the problem is.

I think I know what the problem is and it has to do with physics. I had a simular problem with my pinball app.

Developer of Space Chips, pianobasic, zipzapzoom, and vet pinball apps.
Developed the tiled map engine seen on the showcase.
Veterian for the military.
MarcoBruti
12
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Caput Mundi
Posted: 20th Mar 2012 17:25
what kind of additional info do you need?
Here are some code snippets.
Physics inizialization:

SetDisplayAspect( 0.66 )
setOrientationAllowed(1,1,0,0)
setPhysicsGravity(0,30)
SetPhysicsMaxPolygonPoints(8)
setPhysicsWallRight(1)
setPhysicsWallTop(1)

General sprite creation:

if (getSpriteExists(wall[i].spr)=0)
wall[i].spr=createSprite(wallImg)
setSpriteSize(wall[i].spr,5,6*getDisplayAspect())
setSpriteOffset(wall[i].spr,2.5,3*getDisplayAspect())
setSpritePositionByOffset(wall[i].spr,wall[i].x#,wall[i].y#)
setspriteShape(wall[i].spr,3)
setSpritePhysicsOn(wall[i].spr,1)
endif

General loop for ball collision with flipper elements

function manageLogic()
for i=0 to numElems
if (getPhysicsCollision(block[i].spr,ballSpr)=1)
if (getSpriteVisible(block[i].spr)=1)
setSpriteVisible(block[i].spr,0)
setSpritePhysicsOff(block[i].spr)
endif
endif
endif
next i
endfunction

I tried to explain crearly the problems, anyway in other words:
- for the first 1-2 minutes performance is OK. (> 60 frames/sec)
- then there is a complete degradation. Frame rate goes to < 10 frame/sec and the game becomes unplayable. CPU usage on task manager goes > 30%, even 40% or 50%.
- On Android, the app crash at flipper initialization.
What did you discover with your app? Consider that I have many physical sprites (about 50 and even more). Most are static, two or three are dynamics, and some are kinematic.
3d point in space
14
Years of Service
User Offline
Joined: 30th Jun 2009
Location: Idaho
Posted: 20th Mar 2012 18:37 Edited at: 20th Mar 2012 19:06
Ok this is what I used for Physics
SetSpritePhysicsVelocity For the ball

SetSpritePhysicsVelocity for the thing you pull ball to release the ball.

SetSpriteOffset and SetSpritePhysicsAngularVelocity for the flippers

GetSpriteCollision for the bumpers and that is all the physics commands I used. I did not use GetPhysics collision.

make sure you only use SetSpriteShape once to define each shape also this might crash the app.

for angular velocity c++ code



Developer of Space Chips, pianobasic, zipzapzoom, and vet pinball apps.
Developed the tiled map engine seen on the showcase.
Veterian for the military.
MarcoBruti
12
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Caput Mundi
Posted: 21st Mar 2012 00:52
thanks for the suggestions, but after some troubleshooting, where I removed all elements and "remaked" all functions in main loop, I discovered that this simple code ate all CPU

So Box2D is innocent.
This code created a simple side bar as a background where flipper messages (game over, shoot again, bonus, ball in play, etc) are displayed.
Leftbar image is a totally white PNG of 64x512. I do not understand this is problematic for AGK
So I had no more problems on Windows.
On Android the app crash if I load the flipper elements from a file in a subdir "tables" of media folder. I use setCurrentDir, getNextFile, etc to load ".dat" file that contain CSV data. If I hardcode the data in a function assigning each element array as a statement, let'say

for each element, the flipper is displayed correctly.
I think there is some bug in file commands (and I suppose it is true since bugfix requests have been issued for).
In the app I will publish, if TGC does not finish the upgrade soon, I 'll adopt the 2nd method, i.e. to hardcode flipper data in functions.

Attachments

Login to view attachments
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 21st Mar 2012 20:04
Regarding your problem with:


Is the value in 'i' going outside the limits of the array?

If an array is of size 10, the indices run from 0 to 9.

If you reference index 10, you get unpredictable results and program crashes.

Cheers,
Ancient Lady
MarcoBruti
12
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Caput Mundi
Posted: 22nd Mar 2012 11:49
Oh my God! Maybe you are right.
In fact I was convinced that, as in Dark Basic Pro, when you declare an array, let's say

the compiler allocate memory for 11 integers (0 to 10).
Now you reminded me that it is not true, so the compiler allocates only 10 elements for 0 to 9, as in C.
Since my last game in Java (that uses C syntax) dates back to 2010, in 2 years I forgot this simple fact.
This evening I'll put in practice your advice. If that will help me, I'll send you some Easter gift.
Funnell7
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 22nd Mar 2012 14:46 Edited at: 22nd Mar 2012 14:47
From your code snippet I can see you are using Tier 1... In Tier 1, Array[10] would equate to 11 integers (0-10 including 0 and 10)...



The result of the above is:

0
1
2
3
4
5
6
7
8
9
10
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 22nd Mar 2012 16:04
My bad, According the the help page, you are expected to index from 1 to whatever you dim the array at.

But it apparently lets you use the zero position. I certainly do (almost every programming language I work with starts index at zero).

Although, I wonder if the compiler is having a confusion issue and, maybe, that is what causes problems when old-school programmers like me do arrays of UDTs and use the zeroth spot and the compiler doesn't handle the memory properly for it?

Cheers,
Ancient Lady
Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 22nd Mar 2012 16:12 Edited at: 22nd Mar 2012 16:21
Quote: "On Android the app crash if I load the flipper elements from a file in a subdir "tables" of media folder. I use setCurrentDir, getNextFile"

Yeah, it seems on Android, directory parsing is totally borked!

I managed to get it working with the player, only to have it collapse again when I built the .apk file.

So until 107, hard coded filenames and paths seems to be the best option.

As to the slowdown, the best thing I can suggest is to print key values on screen and watch for them changing in odd ways.

Look at things like the sprite and image references, if these values increase over time, it could be you are allocating new ones without releasing old ones.

A quick glance at the code you posted suggests issues with the manageLogic() function - assuming you posted the whole thing.

You appear to have more endif statements than you have if statements and don't reference the loop i count at all.
Quote: "
function manageLogic()
for i=0 to numElems
if (getPhysicsCollision(block.spr,ballSpr)=1)
if (getSpriteVisible(block.spr)=1)
setSpriteVisible(block.spr,0)
setSpritePhysicsOff(block.spr)
endif
endif
endif
next i
endfunction
"

If you are not using the loop variable i, why have a loop?

edit: formatting and clarity
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 22nd Mar 2012 16:17
Quote: "Yeah, it seems on Android, directory parsing is totally borked!"

I noticed a similar problem on both iOS and Android devices (just hadn't gotten around to raising the issue, yet).

If I try to 'organize' media in sub-dirs under media (or assets, for Android), the app would not work on the target device.

Cheers,
Ancient Lady
MarcoBruti
12
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Caput Mundi
Posted: 22nd Mar 2012 19:16
@Marl: thanks,directory traversal does not work well on Android. Setcurrentdir("") does not work on media folder. So these file commands are totally unasable. I should have to hard code the file name, or not use file at all.
About the endif, there is a mistake of mine when cutting&pasting.

@Ancient Lady & Funnell7
For help, it seems working as Ancient Lady wrote:

So it creates an array with [3] values uses only indexes from 0 to 2.
Anyway I'll try
1) first I fix the arrays,
2) Test Android
3) IF IT WORKS, THEN THE ASSASSINS WERE THE ARRAYS
4) OTHERWISE I TEST FILES, USING HARDCODED NAMES
5) IF IT WORKS, THEN THE ASSASSINS WERE THE FILES
6) IF IT DOES NOT WORK, I'll CALL SHERLOCK HOLMES.

I'll let you know as soon as possibile.
Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 22nd Mar 2012 19:59 Edited at: 22nd Mar 2012 20:03
As Funnell7 stated, arrays start at zero and go up to the number dimmed.

Produces

Attachments

Login to view attachments
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 22nd Mar 2012 20:05
Marl, that is as described in the AppGameKit help (except they don't mention the zeroth entry).

But it is soooo counter intuitive. If an array is defined with 10 elements, then there should only be 10. Either indexed as 1 to 10 (old style Basic) or 0 to 9 (C++, Java, Perl, etc.).

Especially if you plan to convert to/from Basic/Native.

Cheers,
Ancient Lady
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 23rd Mar 2012 01:54
Hence Pascal's much better:

var a: array [5..19] of integer;

-- Jim
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 23rd Mar 2012 16:42 Edited at: 23rd Mar 2012 16:44
My first language was Fortran (way back in ancient times of 1977, this might give a clue about my forum name).

Pascal was the next (UT Austin, 1978) and it was such a relief to finally be able to do things better. I definitely miss being able to define arrays with start and stop instead of just size.

Languages that followed: Assembly (many platforms), COBOL, C, Basic (on an Atari 400), C++, Perl, other Basics (including Visual), CORBA Access, Asyst, Tcl (Tcl/TK), Perl/TK, PHP, PHP/TK, Javascript, Java, plus platform appropriate scripting languages (DOS, *nix)

Yup, I've been doing this a long time and I still love learning new stuff and new languages and tackling problems.

With AppGameKit, I've now joined the 'dark side' and added the Mac and iOS world to DOS, Windows, Unix and Linux.

And I'm loving it all!

Cheers,
Ancient Lady
Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 23rd Mar 2012 18:41
Impressive, but you forgot forth

I was always a COBOL fan because of the way you could redefine your data structures multiple times - accessing the same data in different ways.

Imagine if AGK's UDTs worked the same.

(I'll be having nighmares about Identification Division tonight)
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 23rd Mar 2012 18:57 Edited at: 23rd Mar 2012 18:58
I never had the opportunity to work with Forth.

Asyst was the only stack based language I ever really worked with. I had a class that exposed us to Lisp, but didn't get to do more than one project in it.

While wikipedia knows about Forth, finding any references to Asyst anywhere is hard.

But it was fun to work with when I did.

I'd forgotten about the COBOL Identification Division. Yup, definitely nightmare material. Especially when working from punch cards and you drop the deck!

Cheers,
Ancient Lady
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 24th Mar 2012 10:45
FORTH is great fun. The Music Composition Language I programmed for the Amiga was actually a Forth variant. Two of my friends in Electronic Engineering at Hull University build and sold a Forth-based computer - the OS was Forth in a custom chip, and it was incredibly fast - Nokia used it for years to emulate radios during development.

Might be fun to write a Tiny Forth in AppGameKit Tier 1...

-- Jim
Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 24th Mar 2012 21:00
Many years ago, I wrote a forth interpreter in basic. Because of the way forth is structured, it's not that hard.

It was the arcade game Defender that first got me curious.

I always found it amusing that a game about stopping invading aliens was created with a language created to control radio telescopes - to look for aliens
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 25th Mar 2012 09:24
Actually, A Forth interpreter would provide a lot of functionality at very little cost. Could be extremely useful for game AI etc. The fact that it is extensible at run-time means the program could write its own functions.

For those who don't know about it, this link demonstrates its power:

Quote: "http://www.mpeforth.com/forth.htm"


-- Jim
MarcoBruti
12
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Caput Mundi
Posted: 26th Mar 2012 00:48
I confirm that the crash problem is not due to arrays dimensions. They are not the killer application.
I have to test with hard-coded names.
In the meantime I wrote a function that translates the .dat file that contain the flipper definition, into variable assignments in AppGameKit Basic, so I can test on Windows a flipper layout using .dat files, and then I translate into hard-coded array variables assignments, that can be used on Android version, in order not to use files. I know that it is not beautiful...
My general impression about AppGameKit is that is a very nice tool, but it is not so far so robust to let a smooth development process.
For example, a lot of times I have the compiler crashing with "process terminated with ...", and I have to move functions and split files in order to make things work.
Even to move a line code, or to pull a command out from a loop or if condition, may have good result.
So the behaviour of the compiler on Windows is totally unpredictable.
I am happy to have spent the money for AppGameKit and 25$ for Android developer license (and I earnt 2.8€ big bucks so far by selling apps made with AppGameKit ), but I think that it is a young product that must grow in term of features and robustness in order to attract more people. Let's hope that with the next release thing will go better. Now it is frustrating to have such problems for software with more than 1000 lines or using physics.
MarcoBruti
12
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Caput Mundi
Posted: 26th Mar 2012 00:54
Someone opened a discussion on FORTH.
I loved the HP28S Forth-like programming language in the late '80 at the university. I did a lot of utilities for linear algebra and other stuff. I remember that the beauty of Forth is that when you define a function, the new function becomes a command part of the language. Moreover the reverse Polish notations is very intriguing.
LeeBamber
TGC Lead Developer
24
Years of Service
User Offline
Joined: 21st Jan 2000
Location: England
Posted: 1st Apr 2012 20:41
Thanks for the feedback, and I agree AppGameKit is a very young product, and one I think has a lot of promise with some great guys developing it and an awesome community who want the best for it. If you make sure your most annoying issues are reported here (http://code.google.com/p/agk/issues/list), we will always action them and if reproducible, fix them. We are currently working with a 20,000 line program with Box2D and pretty much all AppGameKit commands and have not experienced random compiler issues. It might be we are using the slightly improved internal 107 version, or something specific to your project, but the more information you can provide through the bug board the more likely it is we can fix your specific issue. Hopefully the issue has already been solved, but we will confirm that when we trawl through the issues during our build 107 testing.

I drink tea, and in my spare time I write software.
MarcoBruti
12
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Caput Mundi
Posted: 4th Apr 2012 16:16
Hi Lee,
it is not easy to identify the issue.
Consider tha sometimes, after a compiler issue, I have to insert a

line and the error disappears.
If I remove the line, the error comes back.
Then after adding 100 lines, I remove the dummy line and everything goes OK.
So it is difficult to add this behaviour to your bugtrack. Some thoughts: I am using Windows XP SP. Maybe the system is old, and you are using at least Windows 7. But consider that with DarkBasic Pro I had no issues (and DarkBasicPro is much older).
So never mind, congratulations, waiting for 107.

Login to post a reply

Server time is: 2024-05-02 06:35:45
Your offset time is: 2024-05-02 06:35:45