Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (481)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (548)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Possible cause for performance issue.  (Read 2356 times)
0 Members and 1 Guest are viewing this topic.
Offline Swattkidd7

Junior Member





« Posted 2008-12-26 22:27:42 »

Hey everyone, I have a 2D tile based game where a character can shoot a couple different weapons at stationary enemies. Pretty much everything is stored in ArrayLists, bullets, enemies, collidable tiles, etc....but for some reason when i run my character around holding down the fire button for the machine gun, after a while the game begins to lag, and I cant quite figure out why. The bullets are removed after they hit the wall so im just lost as to what could be the problem.

Sorry, I do realize that I am giving very little information, but if you all could just post some common causes of this or what you think it could be then i could check it out, because otherwise it would be a large amount of code to paste here...

Any comments are appreciated.
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #1 - Posted 2008-12-26 23:29:04 »

Print the sizes of your lists and check if the values make sense.

弾幕 ☆ @mahonnaiseblog
Offline Swattkidd7

Junior Member





« Reply #2 - Posted 2008-12-26 23:46:54 »

Hmm yea, I tried that, everything seemed to be in perfect order, the bullets list showed no bullets when there were none, etc ,etc...however I have noticed that the performance only goes down after a while, it seems to happen around 2-3 minutes into the game (rough guess)
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jackal von ÖRF

Junior Member





« Reply #3 - Posted 2008-12-27 00:51:25 »

Use a profiler. For example https://visualvm.dev.java.net/

Offline Renoria

Junior Member




...


« Reply #4 - Posted 2008-12-27 01:53:49 »

do you load the image again every time you create a bullet? maybe you could use a cache.
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #5 - Posted 2008-12-27 21:07:18 »

>maybe you could use a cache.

Nah. Just keep a reference to that image... and that's it.

弾幕 ☆ @mahonnaiseblog
Offline broumbroum

Junior Member





« Reply #6 - Posted 2008-12-31 22:48:15 »

>maybe you could use a cache.

Nah. Just keep a reference to that image... and that's it.
You may try to load them directly from file into an arraylist, using a cached file memory (ImageIO.read()). That's if your sprites aren't very big much faster and frees (not "freezes" !) the ram. You may also feel ImageIO slower than JAI. Well, it can rather cool down the memory by freeing the pic every time it's no more needed (e.g. the character puts its weapon off).

::::... :..... :::::: ;;;:::™ b23:production 2006 GNU/GPL @ http://b23prodtm.webhop.info
on sf.net: /projects/sf3jswing
Java (1.6u10 plz) Web Start pool
dev' VODcast[/ur
Offline Renoria

Junior Member




...


« Reply #7 - Posted 2009-01-01 01:15:27 »

use a cache.

1  
2  
3  
protected Map<String/Integer, Image> cache = new HashMap<String/Integer, Image>();

Use either a String/Integer or any object you like as the key, and an Image/BufferedImage for the image.


When you want to get it:

1  
2  
3  
4  
5  
6  
7  
public Image/BufferedImage getImage(String/Integer key) {
 if (cache.containsKey(key)) {
  return cache.get(key);
 }
 Image img = Toolkit.getDefaultToolkit().getImage(this.getClass().getResource(key));
 cache.put(key, img);
 return img;


Try something similar to the above.
Offline Addictman

Senior Member


Medals: 3
Projects: 1


Java games rock!


« Reply #8 - Posted 2009-01-01 11:20:19 »

Do you do anything fancy except firing bullets when holding down the fire button? If you're using a KeyListener, you're going to be firing a whole lot of key events. And you're sure "dead" bullets aren't referenced somewhere, in your render or logic code? The behaviour you describe fits perfectly with something like that.

I'm assuming you only load resources once.
Offline Swattkidd7

Junior Member





« Reply #9 - Posted 2009-01-01 20:21:58 »

Sorry guys for not replying for a while, but thanks for the replies.

I am pretty sure I am only loading the image once, and then just referencing it throughout the project.

And yes I am using a KeyListener and a switch statement, and if W, or w.e is pushed I set that bool value to true and in my run method I do the logic for character movement or w.e is required. I was thinking it had something to do with the bullets also because it would only happen after a while of shooting the machine gun, but i cant find anywhere that the bullets are still there, especially when i printed out the size, it was at 0 when it was suppose to be, etc..
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Swattkidd7

Junior Member





« Reply #10 - Posted 2009-01-07 01:12:19 »

Ok well I cant seem to find anything that is out of ordinary, but what is weird is, I have created a new game, this time a sidescroller but it uses the same tile engine as the past game and is getting that random stuttering...So it seems like it would be the tile engine but I do not see anything that would cause it to lose performance over time..

But the weirdest thing is, that when the stuttering is happening, I dont seem to actually lose performance, it just stutters...For example, my FPS counter never goes down.

(My FPS counter is very basic, adds to the frame variable everytime it loops and if the elapsed time equals 1 second, it records the number of FPS as the fps..)

any ideas?


Seems my FPS counter is flawed, so ima try and fix that..  Lips Sealed Huh
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

atombrot (26 views)
2014-08-19 09:29:53

Tekkerue (24 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (14 views)
2014-08-16 06:20:21

Tekkerue (22 views)
2014-08-16 06:12:11

Rayexar (60 views)
2014-08-11 02:49:23

BurntPizza (39 views)
2014-08-09 21:09:32

BurntPizza (30 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38

BurntPizza (67 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!