Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2
  ignore  |  Print  
  [Slick2D] Extreme Lagging  (Read 790 times)
0 Members and 1 Guest are viewing this topic.
Offline Jacob Pickens
« Posted 2014-03-06 05:20:42 »

Even more fun with this annoying errors within this game. This time it's duper annoying and super game killing lag! Could someone please just review my source. Then tell me whats wrong, and what i should change.

Download: https://www.dropbox.com/s/6szr0uway97qcjd/Zombie%20Nauts.zip

I tried to fix the most things i could. It had no effect. So, I hope you more experienced developers will figure out what the problem is. Thanks in advance!
Offline Jacob Pickens
« Reply #1 - Posted 2014-03-06 05:29:04 »

Actually i think ik the problem. Every time a zombie spawns it creates a new instances, so im pretty sure its just filling the JVM up with instances.
Offline Jacob Pickens
« Reply #2 - Posted 2014-03-06 05:40:20 »

That appears to fix it a little but it stills lags pretty bad.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online BurntPizza
« Reply #3 - Posted 2014-03-06 05:45:36 »

Nope, I was curious enough to try it, running my quad core flat out at 100%. There's your problem.

Profile:


I don't have time right now to look through it all, but it looks like somewhere there are a shitton of Shapes (looks like Rectangles) being created and processed. As in obscenely too many, considering this profile was only about ~15 seconds long, enough to see and kill 1 zombie.

Also Fraps reports 1600 FPS in the main menu, bouncing rapidly between 5 and ~1200 in game. Please limit to 60 to start with, People don't want their graphics cards to melt.
Offline Jacob Pickens
« Reply #4 - Posted 2014-03-06 05:47:49 »

Thank you soooooooo mcuh!!!!! +1 Ik exactly what the problem is. It's the collision boxes and such.
Offline Jacob Pickens
« Reply #5 - Posted 2014-03-06 05:49:23 »

I'm making the rectangles on a seperate thread now... will tht fix it?
Offline Rayvolution

JGO Kernel


Medals: 142
Projects: 2
Exp: 1 year


Resident Crazyman


« Reply #6 - Posted 2014-03-06 05:51:27 »

To cap your framerate, go into your game.class (or whatever your main class is) and put appgc.setTargetFrameRate(60); under appgc = new AppGameContainer(new Game(gamename), startWidth, startHeight, false);

IE:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
      AppGameContainer appgc;
      try{
         appgc = new AppGameContainer(new Game(gamename), startWidth, startHeight, false);
         appgc.setIcon(icons);
         appgc.setVSync(true);
         appgc.setTargetFrameRate(60);
         appgc.start();
      }catch(SlickException e){
         e.printStackTrace();
      }

- Raymond "Rayvolution" Doerr.
Retro-Pixel Castles - Survival Sim/Builder/Roguelike!
LIVE-STREAMING DEVELOPMENT: http://www.twitch.tv/SG_Rayvolution
Offline Rayvolution

JGO Kernel


Medals: 142
Projects: 2
Exp: 1 year


Resident Crazyman


« Reply #7 - Posted 2014-03-06 05:52:52 »

I'm making the rectangles on a seperate thread now... will tht fix it?

That will bandaid it, you're basically creating a bazilliondy rectangles instead of just one and moving it around. I haven't looked at the code, but I'm guessing what you're doing is destorying/recreating a new rectangle every time you need to move it instead of moving the existing one.

- Raymond "Rayvolution" Doerr.
Retro-Pixel Castles - Survival Sim/Builder/Roguelike!
LIVE-STREAMING DEVELOPMENT: http://www.twitch.tv/SG_Rayvolution
Offline Jacob Pickens
« Reply #8 - Posted 2014-03-06 05:53:59 »

YaI just realized that each time the thread loops its setting bounds to a new rectangle.... im now moving it  Wink Thanks soooo much guys. This game would nvr get done without this forum.
Offline HeroesGraveDev

JGO Kernel


Medals: 238
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #9 - Posted 2014-03-06 05:56:12 »

What's stopping you from just using simple AABB collision detection so you don't have to create rectangle instances in the first place?

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online BurntPizza
« Reply #10 - Posted 2014-03-06 06:09:12 »

I agree with using AABB, Heroes even made a post about it a while back: http://www.java-gaming.org/topics/fast-simple-aabb-collision-detection/28059/view.html

Translate that for your needs, and you should be good. Ideally, each entity in game (zombies, the player, etc.) have an x, a y, width and height, and then can do this simple collision check with any other entity.

Sample:
1  
2  
3  
4  
5  
6  
7  
8  
9  
public class Entity { //subclasses: Zombie, Player, etc
     protected float x, y, width, height;

      public boolean collides(Entity e) {
            ...
      }

      //.... other stuff that all Entity's should have in common (health, isAlive, etc)
}
Offline The Lion King
« Reply #11 - Posted 2014-03-06 06:20:09 »

What he is doing with the rectangle instances is almost exactly the same as AABB collision.

Though i agree he should "extend" his program by "implement"ing OO program/class design. (haha , sorry that was lame... but kinda funny)

Quote
I'm making the rectangles on a seperate thread now... will tht fix it?

Also creating your rectangles in a different thread will do nothing. Won't speed anything up and wont fix the fact that you are creating a ridiculous amount of Rectangles.

[edit] You are creating lots of threads that are never completing.

"You have to want it more than you want to breath, then you will be successful"
Offline Jacob Pickens
« Reply #12 - Posted 2014-03-06 06:23:13 »

@Everyone Nvr knew AABB existed. @The Lion King And I already have fixed this error.
Online BurntPizza
« Reply #13 - Posted 2014-03-06 06:26:22 »

Went to Zombie class to look for something, but WTF is this?!

1  
2  
3  
4  
5  
6  
7  
boundsT = new Thread(new Runnable() {
      public void run() {
            while(true) {
                  bounds = new Rectangle((int)x, (int)y, main.getWidth(), main.getHeight());
            }
      }
});


It gets called every time a Zombie or Bullet is constructed.  Shocked

This serves literally no purpose other than to attempt to destroy one's computer.

If you were intending this to keep bounds 'synced' to the x,y, and main fields, this is not how to do that.
This suggests a fundamental gap in your understanding of programming concepts (which can be dangerous, luckily Java tends to be forgiving, if this was C, your comp might be fried right now), so I urge you to take a step back and get a good book / read the official Oracle tutorials, and also read up on Object Oriented concepts. You will thank me later.


I removed it from Zombie and Bullet, voila, no lag.
Offline trollwarrior1
« Reply #14 - Posted 2014-03-06 06:46:54 »

You say you have 3 years experience, but in reality, I think I have more game programming experience.. Kinda strange.

Here is a link to my zombie game.
http://www.desura.com/games/zombie-massacre/downloads/zombie-massacre-game-files
I mean, try and play it and see the amount of zombies.

If you're spawning a lot of zombies, the problem isn't that you check for collision. The problem is that you're constantly checking for collision between zombies that are very far away.
You need to have a list of entities that contains all the level entities. This list shouldn't be touched when it comes to collision. It should be used only to render/update entities.
You need to chunk your map into chunks of lists. Each chunk would have certain area on the map. You need to assign each entities to 1 or few chunks, so you know on which chunk the entity is. When you need to check for collision, check which chunk you're on and get entity list from that chunk.
It doesn't have to be chunks. Tiles do just fine Cheesy Though I'm running 16x16 pixel tiles atm in my game, and i don't really have problem, but running 128 or 256 chunks would probably be better for performance I am guessing.
Offline HeroesGraveDev

JGO Kernel


Medals: 238
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #15 - Posted 2014-03-06 06:52:31 »

You say you have 3 years experience...

I've actually wondered about this.
If we are to believe his profile, he has been programming since 8, and programming in Java since 10.

Yet some of the questions being asked lead me to believe otherwise.

@Jacob Pickens: Do you really have 3 years experience in Java? and 5 years programming overall? Be honest.

Offline The Lion King
« Reply #16 - Posted 2014-03-06 07:08:23 »

You say you have 3 years experience...

I've actually wondered about this.
If we are to believe his profile, he has been programming since 8, and programming in Java since 10.

Yet some of the questions being asked lead me to believe otherwise.

@Jacob Pickens: Do you really have 3 years experience in Java? and 5 years programming overall? Be honest.

Just to emphasize. An average 8 year old doesn't know how to do multiplication and would be very gifted if they truly understood the concept of a variable.

"You have to want it more than you want to breath, then you will be successful"
Offline Jacob Pickens
« Reply #17 - Posted 2014-03-06 07:13:10 »

Yes I do. When I got my first computer (When I was 8 ) I instantly download GameMaker and made games in that for about 4.5 years (Just recently stopped to start using java games). During that time I also started learning tiny bits of Java. I never really programmed a lot of GUI stuff though. Then finally this current year I told myself that Gamemaker was babyish. (Being 13 I didn't want anything to do with anything babyish) So I started researching Java game development. Honestly, I've only had like 2 months of Java game programming experience. So, ya I didn't lie... I don't think?

@The Lion King Well then I must be gifted because I've been programming since I was 8.  Grin
Online BurntPizza
« Reply #18 - Posted 2014-03-06 07:17:28 »

Honestly, I've only had like 2 months of Java game programming experience.

2 months ≠ 3 years.
Offline Jacob Pickens
« Reply #19 - Posted 2014-03-06 07:18:19 »

When it said experience i thought it meant Java not java game programming... i'll change it now
Offline HeroesGraveDev

JGO Kernel


Medals: 238
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #20 - Posted 2014-03-06 07:18:24 »

Not only was it an off-by-one error, but you got the wrong units too. Grin

Also note that most programmers will consider HTML more like programming than GameMaker, so it's probably better to avoid the confusion. (And if you don't understand that, programmers despise HTML being called programming)

Edit: The Java experience is not limited to game programming, but 'lost years' don't usually count.

Online BurntPizza
« Reply #21 - Posted 2014-03-06 07:19:52 »

Perhaps, but it's dubious if 'tiny bits' count as 'experience.'

I know I fiddled with HTML and JavaScript off and on when I first started out, but I'll be dammed if it meant anything.
Offline Jacob Pickens
« Reply #22 - Posted 2014-03-06 07:20:10 »

Well if you use gamemakers language GML its pretty much like a beginner python. So, idk if thats worth anything but ya.
Offline Jacob Pickens
« Reply #23 - Posted 2014-03-06 07:22:06 »

Tiny bits as in entire TheNewBoston beginner java playlist and a little bit of text adventures here and there. So, really it means pretty much nothing.
Offline Jacob Pickens
« Reply #24 - Posted 2014-03-06 07:25:11 »

@HerosGraveDev Ya i guess your right. My experience levels now represents my Java game programming experience not my Java knowledge, We should be good.
Offline HeroesGraveDev

JGO Kernel


Medals: 238
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #25 - Posted 2014-03-06 07:25:23 »

It's better to sell yourself short than to say you've known Java for 3 years and then get taught by a whole load of people with half that experience.

But anyway, you can say what you want about your experience. Other people will interpret as they wish. And it's pretty obvious how much experience someone actually has. The only reason I brought it up was that otherwise people would start posting more responses like trollwarrior's (nothing wrong with that particular post, but it could've gotten worse).

Online BurntPizza
« Reply #26 - Posted 2014-03-06 07:29:58 »

Tiny bits as in entire TheNewBoston beginner java playlist and a little bit of text adventures here and there. So, really it means pretty much nothing.

I wasn't insinuating anything, only observing with what I knew; please don't be insulted.

That said, I don't know if TheNewBoston's (know of him, just not familiar) tuts cover the basics of programming in general, but please get a good book on either Java or programming in a language agnostic context. A 400+ page book simply cannot be replicated in it's combination of depth, breadth, and raw referance-ablity by a youtube playlist.
Offline trollwarrior1
« Reply #27 - Posted 2014-03-06 07:45:19 »

Tiny bits as in entire TheNewBoston beginner java playlist and a little bit of text adventures here and there. So, really it means pretty much nothing.

I wasn't insinuating anything, only observing with what I knew; please don't be insulted.

That said, I don't know if TheNewBoston's (know of him, just not familiar) tuts cover the basics of programming in general, but please get a good book on either Java or programming in a language agnostic context. A 400+ page book simply cannot be replicated in it's combination of depth, breadth, and raw referance-ablity by a youtube playlist.

A book cannot be replicated by actual programming experience. Books are to be used as references for certain topics, like 3d shadows. You can't really learn whole book and say you're good at programming, because you know certain topics. Programming is more like taking bits and pieces and putting them together, not making bits and pieces. Even new people to programming could read 400 page book and implement stuff written there, but once the project gets bigger, they would just give up, because it would prove to be too difficult for them, since they haven't actually done programming, but rather read a book.

You can't learn how to drive by reading a book, can you? Tongue
Offline Jacob Pickens
« Reply #28 - Posted 2014-03-06 07:46:11 »

Oh, im not insulted to the least bit. Did i come off angry from that last post? Thenewboston has been recommended like crazy for his amazing java tuts. He doesn't use official wording though. He calls assignment operators equal signs and stuff. I own a java programming book as well. It's a Java game programming for dummies book. Honestly, I can't learn from books. I'd much prefer to learn visually or peer to peer like this forum. (I've learned so much from this forum already) Anyways, ya no offense taken.
Online BurntPizza
« Reply #29 - Posted 2014-03-06 08:03:54 »

A book cannot be replicated by actual programming experience. Books are to be used as references for certain topics, like 3d shadows. You can't really learn whole book and say you're good at programming, because you know certain topics. Programming is more like taking bits and pieces and putting them together, not making bits and pieces. Even new people to programming could read 400 page book and implement stuff written there, but once the project gets bigger, they would just give up, because it would prove to be too difficult for them, since they haven't actually done programming, but rather read a book.

You can't learn how to drive by reading a book, can you? Tongue

Ah, but I never said a book is the answer to knowing how to program. I said (well, implied) that it is a good place to start before you know what to do to get that essential experience. Everyone's got to start somewhere, I just think that a solid book is a particularly good type of stepping stone for this particular subject we call programming. I also never said (and I hope I didn't imply) that it is the end-all-be-all. Get knowledge from as many sources as possible of course, but yes, it does come down to experience in the end, I agree on that.
Pages: [1] 2
  ignore  |  Print  
 
 

 

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

The first screenshot will be displayed as a thumbnail.

pw (12 views)
2014-07-24 01:59:36

Riven (10 views)
2014-07-23 21:16:32

Riven (11 views)
2014-07-23 21:07:15

Riven (12 views)
2014-07-23 20:56:16

ctomni231 (42 views)
2014-07-18 06:55:21

Zero Volt (38 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (34 views)
2014-07-16 23:30:00

Cero (50 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!