Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (753)
Games in Android Showcase (228)
games submitted by our members
Games in WIP (842)
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 / API design: assigning additional values to objects on: 2016-04-25 03:47:39
Ok, so this is the problem: I have 2 modules, the first is a general API, and it contains a class called Image. The second, is a small game engine (built on top of LWJGL and etc), and it have classes for image loading and rendering.

For the first API, it is somewhat like the Java Image API: you can load an Image object from streams, and it will have it's model (with all the data, pixels, etc) loaded onto the memory. And, for the second API, it actually takes these Image objects, generates a buffer of them, and uploads to the GPU via OpenGL, then storing the texture ID for later use.

The problem is: since the Image class is from another API, and I cannot (actually, shouldn't) do any changes, then I cannot create a field just for storing the texture ID.

When everything was in the beginning, I did the basic and easy solution: use a Map to store entries of Image:TextureID. But, since I'm constantly using the Images to render to the screen every frame, I had to constantly lookup on the Map to get the TextureID related to that Image.

Of course it was f*ck*ng performance (benchmarked: 14.5% of CPU time per tick). Then I HAD to find another way to store a TextureID for Images.

What I did for now: created, in the first API, a class named Storable, which have one field named "stored" of type Object, and methods getStored(), hasStored() and setStored(). Then, I made Image a subclass of Storable.

This way, I can store the Texture IDs for the Images in a "generic" way, so that the first API will not be dependent on the second.

Ok, this worked for my problem, but still, if I want to store an object reference (in my case, the texture ID) into another object, the object class *must* be a subclass of Storable. To the question: is there another, maybe safer, maybe more dynamic, maybe via JNI, solution to this problem, so that I can store a few bits of additional data in ANY object?
2  Discussions / General Discussions / Re: Does Internet cost matter to you? on: 2015-04-06 23:09:31
I could even believe in you, OP, but when you said you were going to use Java, I lost all my faith.

And I'm not saying this because I hate Java; instead, it is because I have a very large experience with Java (3 years and a half), and I KNOW that this is impossible. Just, impossible.

And, even if you used a low-level language or JNI, I'm still pretty sure this is impossible. You are probably just a kid saying things you'll never do to gain attention.
3  Game Development / Newbie & Debugging Questions / Confusion with VAO/glDrawArrays and Frustum Culling on: 2015-03-31 17:02:49
Hey there.

Just to give you all my context: I know that there is A LOT of good engines and libraries out there, like libGDX, JMonkeyEngine, etc. But I'm developing a small personal "engine", for learning OpenGL.

Now, to the point: Currently, I have a world with ~1050 blocks, and I use a >ImmediateArrayBatcher< class (which extends >Batcher> class with some useful but not important methods) for drawing them, also using a >VertexObject> class behind the scenes.


Then, EVERY frame, I'm re-populating the VertexObject buffers and re-calling glDrawArrays() and the other methods on ImmediateArrayBatcher._flush().

I have read a bit about immediate mode, VAOs and VBOs, but I still can't pull this out to code.

I tested the performance with this ImmediateArrayBatcher and a ImmediateBatcher, which uses the deprecated immediate mode (glBegin, glEnd...), and the FPS was the same (~1050 blocks, ~140 FPS on my machine), even with Frustum Culling.

Then, I came into another problem: I could use display lists, but... what about the Frustum Culling? When in a frame some blocks would not be render, they will not be anymore rendered since they were not rendered on the display list when it was created. Or, even more, I think that only populating the VertexObject buffers one time, and then only calling glDrawArrays() after would cause the same thing.

Also, my blocks are not necessarily 1x1x1: then, I cannot create something like "chunks" for separating display lists for each one.

So, my questions are:

1 - Should I use glDrawArrays() or glDrawElements()? And, if I use the second one, how should I populate my VertexObject class?
2 - As I said before, since I'm using Frustum Culling, I cannot use display lists, and I don't know how to properly populate the VertexObject buffers and calling glDrawArrays() after. Then, would VAO and/or VBO help me there?

4  Game Development / Game Mechanics / Re: How to handle collision detection when an entity movement speed is high? on: 2014-05-10 20:04:58
I think I've explained it bad, so here I go again.

I AM checking for collision and not intersection. It's something like:

  • player wants to move from 126,126 to 126,127
  • creates a new Box for that position { x = 126, y = 127, width = 32, height = 32 } (width and height are playerWidth and playerHeight, respectively).
  • check if this box collides with any object (entity/block/etc) on the map. if yes, the movement does not happen. if no, the movement goes normally.

BUT, the problem is: in the example above, the player moved +1 y (his movement speed is 1). but, what if his movement speed is 2?

So, here we go again:

  • player wants to move from 126,126 to 126,128
  • creates a new Box for that position { x = 126, y = 128, width = 32, height = 32 }
  • the new Box endX and endY are 158 and 160, respectively.
  • there is a block located at y = 160.
  • so, the player can't move, since it would collide with the block. BUT, the player could have moved to y = 127 (endY = 159), with 1 movement speed.

So, moving the player with 1 movement speed is alright. The problem is when moving with higher and/or fractional movement speeds (like 2.5, 3.25, etc).
5  Game Development / Game Mechanics / Re: Organizing classes on: 2014-05-10 19:52:29
Is it best to load all of my 3D models at the very beginning of my game, or should I load them for each level and dispose them as levels change?

Is it the loading and storing that slows down the program, or is it the rendering?

This is for mobile devices.

It depends on what is "slows down the program". Loading will increase CPU usage, storing will increase RAM allocated.
6  Game Development / Game Mechanics / How to handle collision detection when an entity movement speed is high? on: 2014-05-10 18:30:24

So, basically, my collision detection code is something like this:

public Boolean canMove() {
  Position pos = positionEntityWannaMoveTo;

  for (WorldObject : All Objects In Map) {
    if (WorldObject.intersects(pos)) {
      return false;

  return true;

Ok, obviously, my code isn't like this because it would use too much CPU considering the map has a high number of entities/tiles, but the "base" of the detection is something like that.

Suppose, my player is at Y 126.0, and his height is 32.0. So, his feet Y is 158.0, and there is a solid block at Y 159.0. So, if my player movement speed is 1.0, it will move correctly. But, what if the movement speed is 2.0, then the final move feet Y would be 160.0, being blocked by the block.

Then I tried to divide the movement speed in parts, so it would detect and move each 1.0 of movement speed. But, what if the movement speed is partial, like, 3.5? Then I should move each 0.5 of movement speed? And if it is 3.85?

So, there is a proper way to handle the movements with partial movement speed?
7  Game Development / Game Mechanics / Better way to move the map according to player position? on: 2014-05-08 04:56:27

I'm developing a 2D game with tiled-based maps. So, when my player moves any point after/before screenWidth / 2 or screenHeight / 2, it'll .glTranslate the map and everything drawn on it. To calculate when it should translate or not, untranslate or not, and how much translate, I'm not using anything like matrixes: I'm just using pure math code.

My question is: is there a way to do it better? This way, right now, isn't affecting performance or anything related, but I'm just wondering if I could get the same result using transformation or projection matrixes? (Since I don't know how those works.)

8  Discussions / General Discussions / Re: JEP for making Unsafe a public API on: 2014-05-05 01:40:56
Oops, sorry, didn't noticed that!

Well, I know that you are not talking about accesibility... but in case anyone want it, you can easily access the Unsafe class...

Field field = Unsafe.class.getDeclaredField("theUnsafe");


return (Unsafe) field.get(null); // Return the Unsafe instance
9  Discussions / General Discussions / Re: JEP for making Unsafe a public API on: 2014-05-05 01:36:05
I don't get it... I can access Unsafe normally, it's a public class. I can normally use 'Unsafe.getInstance()'. So, of what are you talking about?
10  Java Game APIs & Engines / OpenGL Development / Re: How can I improve my rendering? (VAO/VBO) on: 2014-05-04 23:52:28
Well, there's 3 things you need to do:

1. Pack all your sprites into texture atlases. Plenty of information around about how to do this.
2. Sort your sprites according to rendering state needed, eg. blend mode, texture binding
3. Batch all your sprites up into groups with the same rendering state, writing indices out to an index array, and use glDrawElements to draw, say, 100 sprites in one go, rather than 100 calls to glDrawArrays.

Stop using that tesselator thing.

Cas Smiley

Hello, and thanks for answering me, I know how boring this can be.

Well, I'll follow your tips ^^. Just wondering, when you say writing indices out to an index array, it's something like the method 'addVertex' here If yes, is it possible to configure more vertex properties, like brightness and etc using this array? (As I've seen, Minecraft have block brightness, and they are set on the arrays sent to glDrawArrays too.)
11  Java Game APIs & Engines / OpenGL Development / Re: How can I improve my rendering? (VAO/VBO) on: 2014-05-03 14:46:05
Erm... hm... well... yeah, I'm drawing each sprite separately :// I'm very newbie on OpenGL, started learning like 1 month. I don't know how to name it correctly, but the Tessellator class is something like "vertex array immediate mode", isn't it?

Btw, the detectTerrainIntersection was my fault, I was calling it for each entity, each tick. Now I've made some 'cached collisions' workaround and it's working great, not even getting 4% on profilling.

So yeah, the problem is my stupid Tessellator class with immediate mode for every block and every entity on world, since I still am not that experienced to do something like Sprite Batching.

@Edit: Oh, and glBindTexture is taking 8%... another problem from immediate mode.
12  Java Game APIs & Engines / OpenGL Development / Re: How can I improve my rendering? (VAO/VBO) on: 2014-05-03 03:33:07
New log (around 4 minutes of execution):
13  Java Game APIs & Engines / OpenGL Development / Re: How can I improve my rendering? (VAO/VBO) on: 2014-05-02 19:31:20
Hey there,
Just saying, probably tomorrow I'll post it, because I upgraded from Win7 -> Win 8 and Intel haven't published the drivers for my graphics board, so yea it'll take some time 'til I be able to re-open my game.
14  Java Game APIs & Engines / OpenGL Development / Re: How can I improve my rendering? (VAO/VBO) on: 2014-05-02 14:04:17
Yes I've already seen the display lists, but the problem is: I have some animated tiles. But I'll try it, like rendering all static tiles via display lists and after, draw animated tiles separated, but I still think that the problem isn't the tiles itself, but yes the entities, and the entities are always in movement and changing sprites so display lists won't work :/ Anyway, thanks.

Hey there, my -Xprof log result:

As you can see, my is taking 15% of the time, but I still don't think this is the main issue (yeah, today I'll try to modify some things on it). GL.drawArrays is using 24%, and (wtf?) is using 13%.
15  Java Game APIs & Engines / OpenGL Development / How can I improve my rendering? (VAO/VBO) on: 2014-05-01 16:40:00
(First, sorry for my bad english, I'm brazilian :/)

Good afternoon,

Well, I'm learning OpenGL/LWJGL right now, and I'm developing a little 2d game:

My problem is, even it's a 2D game, with 12 entities on my map, I'm having only 30 FPS. Yes, it's a crappy 2009' notebook with Intel on-board graphics and a simple dual-core CPU, but the same way, 30 FPS is sooo little for a 2D game.

So I've been reading some tutorials, articles, topics and etc about Sprite Batching, VBOs and VAOs, but I couldn't get it well. My rendering class right now is an edited Tessellator-class taken from Minecraft, used for testing and learning purposes only.

The class "Tessellator" right now:

Aand the "VertexObject" class used in Tessellator:

(Methods like hasColor(), getColor(), hasTexture(), getTextureUV(), etc, are all from sub-class Tessellator, but I'm sure they doesn't matter here.)

So, how can this be improved? I know there's a better solution for glXPointer, but even reading a lot I can't put it on practice.

Thanks in advance.
16  Game Development / Newbie & Debugging Questions / Re: Run another program inside my program applet/canvas? on: 2012-12-13 18:11:44
Ook, thank you!
17  Game Development / Newbie & Debugging Questions / Run another program inside my program applet/canvas? on: 2012-12-13 17:50:00

I was thinking... in Java, is there a way to run another java program, and display this program INSIDE my program, via Canvas or something?

Pages: [1]
nelsongames (19 views)
2018-04-24 18:15:36

nelsongames (17 views)
2018-04-24 18:14:32

ivj94 (608 views)
2018-03-24 14:47:39

ivj94 (52 views)
2018-03-24 14:46:31

ivj94 (401 views)
2018-03-24 14:43:53

Solater (66 views)
2018-03-17 05:04:08

nelsongames (111 views)
2018-03-05 17:56:34

Gornova (176 views)
2018-03-02 22:15:33

buddyBro (747 views)
2018-02-28 16:59:18

buddyBro (94 views)
2018-02-28 16:45:17
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!