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 (531)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Performance Tuning / Re: Issues with drawing 2D generated terrain efficiently on: 2013-05-30 12:12:16
Nope. I went back and retried it! I got between 5-6% CPU usage and being on a quad core

I would be very interested to know how you managed to do that! Smiley
Yeah, I'm aware of the flat level creation, it's mostly a matter of changing the amplitude, I've yet to really play around with making different "biomes" and stuff, I've still gotta wrap my head around 2D perlin noise first I think. Mostly cosine interpolating diagonally.... shudder.....
2  Game Development / Performance Tuning / Re: Issues with drawing 2D generated terrain efficiently on: 2013-05-30 06:30:06
I just downloaded and tried out the libGDX version of it and... I've got no issues. Watching my task manager I was hovering around 15% total CPU usage with about 6% being either Eclipse or your program.

So that 15% CPU was definitely not 100% of one of your CPU cores? Because 25% is 100% of one CPU core for me.
I don't know much about accelerated graphics but I'm kind of expecting 1-4% CPU as the game currently stands.

I guess in this case, the game LIGHTSPEED runs at 60FPS-SPEED!
Budum Tss.

Light travels at 60fps right? Wink
3  Game Development / Performance Tuning / Re: Issues with drawing 2D generated terrain efficiently on: 2013-05-30 02:59:03
Thanks for your interest in my issue everyone Smiley Sorry for my delay in responding, it was about 2:30am when I wrote the topic.
I was quite encouraged to hear they I may not be capping the fps because that was something I hadn't thought of, however, before I even put that setVsync(true) in, I put a System.out.println(blahblahblah.getFramesPerSecond()) in and lo and behold, the almost dreaded number 61 came out Sad
Meaning that's probably not the problem.

It also wouldn't entirely explain the huge jumps between 1-4% and 25%, rarely is the CPU usage between those two...

As requested, here's my pre-libGDX code: https://dl.dropboxusercontent.com/u/1289341/Help/LightspeedOld.zip
(I simply zipped the Eclipse project folder, hope that won't be a problem)
It may be a little messy as I think I was playing around with VolatileImages at the time and may not have entirely changed it all back to BufferedImage.
I guess I don't really mind posting the post-libGDX code as it stands, if anyone wants to have a look at it.
https://dl.dropboxusercontent.com/u/1289341/Help/Lightspeed.zip
Edit: I forgot to mention, WASD to move, R to make a new level.

Any and all help is most appreciated, thanks again Smiley
4  Game Development / Performance Tuning / Re: Issues with drawing 2D generated terrain efficiently on: 2013-05-29 17:49:36
I did actually look into that and try and use those in my non-libGDX version of the game, sorry I forgot to mention that. I just couldn't get them working properly and nothing I did with them seemed to resolve the same CPU maxing out issue. This may have largely been because I don't really know how to use them well at all and could easily have been doing something wrong but I did follow the tutorials and stuff pretty much to the letter.

It may have had something to do with me using BufferedImages in the sprite sheet hashmap and drawing onto the graphics object of a BufferedImage and then scaling that image 2x bigger and drawing it with a BufferedStrategy. It was a bit messy though and could have been entirely wrong.

In any case, I quite like this libGDX thing though and will probably continue to use it instead for the moment. The main drawback for me was letting go of the gameloop I made that I was very proud of Sad
5  Game Development / Performance Tuning / Issues with drawing 2D generated terrain efficiently on: 2013-05-29 17:33:19
Hello everyone, I'll start out by saying I'm most definitely NOT an expert at Java and have been a lurker around here for some time and still can't understand half of everyone's amazing solutions to problems around here. Be forewarned that I may also not understand any responses to this thread either Wink

That being said, recently I've been trying to create a block based 2D game with random terrain creation.
My levels are created using a 2D array of my own little Block class, the only thing really stored in each block is its type as an Enum. My main problem arose when I filled out the "ground" underneath the perlin noise generated horizon by filling it entirely with blocks (for now). I'm using a "zoom scale" of 2 so 1 pixel = 2x2 pixels in reality if that makes any difference.
I wasn't using any third party libraries or anything and I found that my CPU usage was hitting 25% and above, which I believe really means I'm using 100% of one CPU SO I poked around on here and discovered libGDX as I assumed that the reason my CPU was sky-rocketting was because it was drawing around 3417 blocks at most per tick and I should probably be using the GPU to do that instead. FYI, I'm not iterating through the massive level array, I'm just iterating through what is on screen based on the camera's viewport.

After painstakingly (well not really, libGDX is quite nice) converting my little game into libGDX I noticed that the game ran a WHOLE LOT smoother which I was very happy with as I hate that little stutter that windowed Java games seem to have, however, the CPU usage hasn't really changed in the slightest and I've been looking around for ages for possible reasons/solutions and I've drawn a blank every time.
I'm COMPLETELY new to anything OpenGL by the way.
Here's the details of how I'm doing things, PLEASE feel free to tell me better ways to do things if there are any or at least point me in the right direction. I DO research as much as I can though.

- I'm attempting to use a sprite sheet of 8x8 tiles loaded as a Texture
- There's currently only four tiles in that Texture
- I'm using the Sprite.split() method to turn it into a 2D TextureRegion array
- I'm storing the each TextureRegion in that TextureRegion array in a hashmap (loosely based on Kev Glass's old sprite store tutorial) so I can simply call the key to whatever TextureRegion I want when I need it
- I AM concatenating a string for the key but it only does that on the initial load of the sprite sheet Texture
- That means the key IS a string, I don't know if that affects performance
- Between batch.begin() and batch.end(), the render method iterates through the section of the level array shown on the screen, I'm calling a batch.draw() method for each Block on screen and getting the TextureRegion from the hashmap based on the Block's type. This draw method appears to be what's eating up all my CPU.
- I did run VisualVM on it and about 94.9% of my CPU usage was used up by org.lwjgl.opengl.GL11.nglDrawElements[native] if that helps

Is there something I'm doing wrong? I ran Terraria and checked its CPU usage and with a similar amount of blocks on screen it was sitting around 1-4% CPU. I know there's something called a TextureAtlas, I'm not sure if that would speed anything up as isn't what I'm doing essentially the same thing? Is what I'm doing somehow making my Texture unmanaged? I called the .isManaged() method and it returned true every time.

Another thing that happens, if there's only a few Blocks on the screen, sometimes the CPU will drop to around 1-4%, which is where I kinda expect it to be but then, if I move the camera like ONE ROW across, the CPU jumps straight back to 25%. I don't know if this helps with identifying the problem but surely a couple more rows/columns of blocks doesn't require that much CPU. I'm very confused and exhausted.
If anyone needs to see the code, I'll post it up. Smiley

If you read this far, I love you.
6  Game Development / Newbie & Debugging Questions / Re: I have no idea how to get my images to work in a Jar! on: 2012-01-06 01:34:23
Oh my goodness! I can't believe I did that... Clearly not enough coffee!
Well it WORKS now! Thanks a lot to everyone who took the time to help out an Eclipse newbie like me! Cheesy
...Now I can resume actually coding the thing..
7  Game Development / Newbie & Debugging Questions / Re: I have no idea how to get my images to work in a Jar! on: 2012-01-06 01:20:53
This is starting to come together, thanks guys, it's good to see what it's supposed to look like haha! I was getting quite confused...
In any case, I remade the images folder from scratch and made sure it wasn't in the build path or anything, just a plain folder. I put laid it out the you have yours there Ra4king. Good news! It now runs in Eclipse!
Bad news... it still won't run as an executable jar...

Here's what it looks like now:

8  Game Development / Newbie & Debugging Questions / Re: I have no idea how to get my images to work in a Jar! on: 2012-01-05 23:41:23
At this point, I'm not even sure what exactly a class loader is, I just read that if I do it this kind of way it's better  persecutioncomplex.
I certainly appreciate all the time you guys are putting into helping me out, I've done what I think you guys were telling me to do, it looks like this now:



However, it's not even running in Eclipse anymore... Sad
So let me get this straight, the src folder is treated as the root directory right? So surely putting the images folder in src folder would mean that the path, "/images/myfile.png" would work right? ...Cause it's not. I really think the problem is WHERE I'm putting my images folder, I simply just don't know the correct place for it.
This is such a rediculous error for me to be stuck on...
9  Game Development / Newbie & Debugging Questions / Re: I have no idea how to get my images to work in a Jar! on: 2012-01-05 16:31:55
I used that code you suggested, it worked in Eclipse, but after exporting is an executable Jar, still didn't work.
I seriously think something is wrong with my folders or something. Am I correct in assuming that the images folder should be a source folder in the Java Build Path in properties? Because I've tried that too, and it broke it again Sad
I'm definately doing SOMETHING wrong though, since I've looked through tons of videos today and they just breezed through it...

EDIT: Here's a picture of my little project list that might shed some light on the subject. I'm not sure that images folder is in the right place, I've moved it around a fair bit though....

10  Game Development / Newbie & Debugging Questions / Re: I have no idea how to get my images to work in a Jar! on: 2012-01-05 16:09:30
Well I opened the project properties, went to build path, went to the source tab, added the folder and this is what happened...
Some deal about enabling nesting? Does this mean my folders are whack?

11  Game Development / Newbie & Debugging Questions / Re: I have no idea how to get my images to work in a Jar! on: 2012-01-05 15:55:22
That's starting to sound like the solution to my problem!
See I only just switched over to Eclipse yesterday, I've been trying to learn it as best I can, yet a little thing like this seems to have slipped under my radar.
So the properties where I assign this as a resource folder, is that the properties from the project menu? Or is it the properties from right clicking on the folder itself? Also, whereabouts in properties? Is it build path or linked resources or something I've missed entirely?

Sorry to waste time on such a small little problem!!
12  Game Development / Newbie & Debugging Questions / Re: I have no idea how to get my images to work in a Jar! on: 2012-01-05 15:43:59
Sorry! That didn't work either, I tried that code with "images/", "/images/" and "../images/", still no good.
I'll go ahead and paste in the class I'm using to hold my sprites, minus the getters.

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  
public class Sprites 
{
   public BufferedImage[] sprites = new BufferedImage[4];
   private int tileSize = 32;
   
   public Sprites()
   {
      try
      {
         //Block tileset
        BufferedImage blockTileset =
               ImageIO.read(this.getClass().getResource("images/tiles.png"));
         
         sprites[0] =
               ImageIO.read(this.getClass().getResource("images/dude.png"));
         sprites[1] =
               ImageIO.read(this.getClass().getResource("images/enemy.png"));
         
         //Loop through block tileset
        for (int i1 = 0; i1 < 1; i1++)
         {
            for (int i2 = 0; i2 < 2; i2++)
            {
               sprites[i2 + 2] = blockTileset.getSubimage(i2 * tileSize,
                     i1 * tileSize, tileSize, tileSize);
            }
         }
      }
      catch (Exception e)
      {
         System.out.println(e.getMessage());
      }
   }


If you're wondering about the nested for loops, I'm leaving those in for when my sprite sheet exceeds two sprites haha!

I still think it's probably to do with where I've put the images. The images folder is in the same directory as all my code, surely that would be ok?
13  Game Development / Newbie & Debugging Questions / Re: I have no idea how to get my images to work in a Jar! on: 2012-01-05 15:32:21
I've tried that before Sad I'm afraid it doesn't work. Eclipse doesn't even find the images when I do it like that. The Jar still falls over too.
14  Game Development / Newbie & Debugging Questions / Re: I have no idea how to get my images to work in a Jar! on: 2012-01-05 15:23:01
Sure thingy! It's a really small, simple project.

I opened the Jar in 7zip and got the following:

platformer >  images           >    All my images
               |  All my code 
       
META-INF > manifest.mf

I hope that's readable enough! Smiley
15  Game Development / Newbie & Debugging Questions / I have no idea how to get my images to work in a Jar! on: 2012-01-05 15:11:49
(I've attempted to put the tl;dr stuff in bold)
Hey everyone, I'm totally new here and relatively new to Java, I was hoping I could get some help regarding a practice game I'm making.
I did a few searches, I didn't find anything like this, but I also wasn't going to spend my entire evening tunneling through forum searches XD

Anyway, my game was working fine when I ran it in Eclipse, but I wanted to be able to show it to my buddies, I exported it as an executable Jar and ran it.
Nothing ran at all. So I looked into it and apparently my images aren't loading up properly when I run the Jar.

Why is it that Eclipse can find my images and run the thing fine and when I export it nothing works?
I'm assuming it's to do with where I placed my files. I HAVE NO IDEA WHERE TO PUT THEM! But I do want them in an images folder at the very least.
I've currently got them in "src/platformer/images"
Platformer is my package name/folder and has all my code in there.


The code I'm using to load the images up has changed a few times, but what I'm currently using is:

BufferedImage blockTileset = ImageIO.read(this.getClass().getResource("images/tiles.png"));

Now I'm not entirely sure what I'm doing there, I just read from Kev Glass' tutorials that it's a good idea to do it that way.
Can anyone lend some insight into this? Do I need to move my images folder somewhere? Do I need to add a slash or something to my file path? I've spent all day on this annoying problem and haven't got anywhere! I know it's a simple, stupid problem, but please bear with me!

Thanks in advance Smiley

P.S. You may need to dumb down your answers a little bit, I'm not a full on programmer yet! So many things I've looked up today where people had problems that were solved thusly, 'Simply do this! *insert a whole mess of uncommented code with poorly named variables*' 'Wow thanks for solving my problem! Cheesy'. Then you have me sitting here, thinking in angry scribbles and reaching for another coffee...
Pages: [1]
 

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 (13 views)
2014-07-24 01:59:36

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

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

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

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

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

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

MustardPeter (35 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!