Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (427)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (466)
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 3 ... 8
  ignore  |  Print  
  MERCury - 2d Game Library  (Read 13841 times)
0 Members and 1 Guest are viewing this topic.
Offline wessles

JGO Ninja


Medals: 49
Projects: 4
Exp: 3 years


Loves games, loves coding; this is only logical.


« Posted 2013-09-29 02:24:11 »

So, I decided that it would give me a good sense of what to do with the coding parts of games if I attempted to make my own game library. This is my first try at one. It isn't libGDX, but so far looks like it will work for me, and maybe others(?).

Because this is my first try at a game library, I am open to all criticism.


Kudos to kpars (or as he prefers 'Jeviny') for the sweet logo!

MERCury stands for Maitenance Enriched and Reliable Coding.
I actually just wanted a sweet sounding name  Cool

It is a 2d game library that I am making for myself and open to others. Some concepts are borrowed from slick2d, since I love that library.

Download page
Tutorials
Subreddit For Sharing Games Made By MERCury, Bugs, Requests, Etc.


Tell me what you think below! Improvments? Bugs? Etc. !
And thank you for your input!

You don't know nerdiness yet; you haven't even met me!
www.wessles.com
Offline opiop65

JGO Kernel


Medals: 129
Projects: 7
Exp: 3 years


Team Alluminum


« Reply #1 - Posted 2013-09-29 02:32:57 »

Spritebatching! So important, if that's one of the only things you do, do it. Also, support for easy to load and bind textures and mipmapping. Oh and lots of math helpers like vectors and matrices and cameras are very useful. Easy shader loading... I could go on all day but just get the basics working right now!

Offline HeroesGraveDev

JGO Kernel


Medals: 215
Projects: 11
Exp: 2 years


If it wasn't Awesome, it wasn't me.


« Reply #2 - Posted 2013-09-29 02:42:21 »

Okay, I'll just highlight a few problems in the code:

1. ObjectUR is duplicate code. Just implement Renderable and Updatable. Or if for some reason you need to know that it has both, simply make ObjectUR extend Renderable and Updateable, then you don't have to implement so many interfaces.

2. Use HashMaps in ResourceManager. Your code in that class is an inefficient mess.

3. Your triangle class doesn't work.

4. I think your VAOGraphics is less efficient than immediate mode. You seem to be setting up all the complicated (and processor time consuming) pointer calls for every single shape you draw.

5. Your pointbuffer method requires more code than just calling gl___Pointer()

Apart from that, it looks like a reasonable start. Your code layout is decent enough.
It just needs a bit of work, and some fixing of the above problems.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline wessles

JGO Ninja


Medals: 49
Projects: 4
Exp: 3 years


Loves games, loves coding; this is only logical.


« Reply #3 - Posted 2013-09-29 02:48:20 »

Yeah, I heard about hashmaps, but when I mentioned them to a friend of mine they said to just use arraylists. I see now why he was wrong. Do hashmaps just put 2 pieces of data into one, so you can reference them later?

You don't know nerdiness yet; you haven't even met me!
www.wessles.com
Offline Agro
« Reply #4 - Posted 2013-09-29 02:49:15 »

its a key value object.

Offline wessles

JGO Ninja


Medals: 49
Projects: 4
Exp: 3 years


Loves games, loves coding; this is only logical.


« Reply #5 - Posted 2013-09-29 02:56:30 »

Thanks Heroes! That was a very informative response! I fixed 1 and 2. Thanks for informing me about hashmaps.
Just one thing (well, 2):
3. Your triangle class doesn't work.
Can you elaborate? The area? Drawing? What?

EDIT:
4. I think your VAOGraphics is less efficient than immediate mode. You seem to be setting up all the complicated (and processor time consuming) pointer calls for every single shape you draw.

5. Your pointbuffer method requires more code than just calling gl___Pointer()
And also:

4: what should I do? What if the values of the arrays are constantly changing, like with the player?
5: what else should it do?

You don't know nerdiness yet; you haven't even met me!
www.wessles.com
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 121
Projects: 4
Exp: 3 years



« Reply #6 - Posted 2013-09-29 03:08:19 »

Don't have time to look through all the code right now, but I would refrain from naming your classes the same as their Java2D counterparts (ie Graphics), just to avoid confusion.
Offline wessles

JGO Ninja


Medals: 49
Projects: 4
Exp: 3 years


Loves games, loves coding; this is only logical.


« Reply #7 - Posted 2013-09-29 03:12:16 »

Okay, I have a list of alternatives:
-Visuals
-Renderer
-Drawer
-Painter

Sorry. Wanted this to have an easy and recognizable interface for java2d veterans. Guess not though Sad.

You don't know nerdiness yet; you haven't even met me!
www.wessles.com
Offline Troncoso

JGO Coder


Medals: 20



« Reply #8 - Posted 2013-09-29 03:29:15 »

What's the logic behind making the entire Runner class static?  It seems like you are trying to make it a singleton. If so,  that's not really the right way.
Offline wessles

JGO Ninja


Medals: 49
Projects: 4
Exp: 3 years


Loves games, loves coding; this is only logical.


« Reply #9 - Posted 2013-09-29 03:39:54 »

The idea that sometimes one method would not want to have to pass in some variables, and want to access that variable without it lengthening the amount of arguments they have. In the end, it is your choice whether or not to use the static capabilities of it all. I choose to, but you can just pass it into your objects. Free choice FTW!

The only place where you need to use static, is if you want to change the graphics object, which you cannot even do right now, as there is only one.

You don't know nerdiness yet; you haven't even met me!
www.wessles.com
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline HeroesGraveDev

JGO Kernel


Medals: 215
Projects: 11
Exp: 2 years


If it wasn't Awesome, it wasn't me.


« Reply #10 - Posted 2013-09-29 04:24:00 »


You can't specify a triangle by passing in 4 values. You need 6 (X&Y for each corner).

Quote
EDIT:
4. I think your VAOGraphics is less efficient than immediate mode. You seem to be setting up all the complicated (and processor time consuming) pointer calls for every single shape you draw.

5. Your pointbuffer method requires more code than just calling gl___Pointer()
And also:

4: what should I do? What if the values of the arrays are constantly changing, like with the player?
5: what else should it do?

4) The problem isn't that. The problem is that you are using one VA per quad. With the overhead from the pointer setup, I would think that drawing 4 vertices with immediate mode is more efficient. You need to use spritebatching (if that's the official term).

5) Which one is shorter?

1  
2  
GL11.glVertexPointer(2, stride, buffer);
VAOUtils.pointBuffer(VAOUtils.VERTEX_ARRAY_POINTER, stride, buffer);

Offline wessles

JGO Ninja


Medals: 49
Projects: 4
Exp: 3 years


Loves games, loves coding; this is only logical.


« Reply #11 - Posted 2013-09-29 05:00:46 »

4) The problem isn't that. The problem is that you are using one VA per quad. With the overhead from the pointer setup, I would think that drawing 4 vertices with immediate mode is more efficient. You need to use spritebatching (if that's the official term).

4: SpriteBatching?! I just looked that up, and it requires extensive knowledge of shaders, matrices math, and other stuffs I haven't even heard of  Tongue! Are there any alternatives to what I am doing that are a little more 'on my level?'

5: Sorry. I just like to wrap things. To me it looks more organized than alternating between utilities, and gl. I don't see that that is a flaw though, wrapping it...

You don't know nerdiness yet; you haven't even met me!
www.wessles.com
Offline HeroesGraveDev

JGO Kernel


Medals: 215
Projects: 11
Exp: 2 years


If it wasn't Awesome, it wasn't me.


« Reply #12 - Posted 2013-09-29 05:10:58 »

4: SpriteBatching?! I just looked that up, and it requires extensive knowledge of shaders, matrices math, and other stuffs I haven't even heard of  Tongue! Are there any alternatives to what I am doing that are a little more 'on my level?'

All a spritebatcher needs to do is buffer draw calls together and then flush them together in order to minimize GPU calls.

Instead of drawing the rectangles straight away, store the vertex/texcoord/colour data in a buffer or arraylist, depending on how you want it to work.
Once you are finished rendering everything, call a draw function, which takes the data, stores it in a buffer if it isn't already in one, and then draws it all in one glDrawArrays() call.

VBOs are even better for this kind of stuff.

Offline wessles

JGO Ninja


Medals: 49
Projects: 4
Exp: 3 years


Loves games, loves coding; this is only logical.


« Reply #13 - Posted 2013-09-29 05:13:38 »

Wow. Blew my mind away. I am totally doing those. This line
Quote
Creating your own sprite batcher is not easy, and requires understanding of shaders, vertex buffers, and basic matrix math.
Was SOOO misleading.

I will get started right away!

You don't know nerdiness yet; you haven't even met me!
www.wessles.com
Offline opiop65

JGO Kernel


Medals: 129
Projects: 7
Exp: 3 years


Team Alluminum


« Reply #14 - Posted 2013-09-29 05:14:55 »

You could even go further and make two spritebatchers, one for vertex arrays and one for vertex buffer objects. VBOs are better for static geometry(tiles) and VAs are better for constantly updating an changing geometry(mobs, particles)

Offline HeroesGraveDev

JGO Kernel


Medals: 215
Projects: 11
Exp: 2 years


If it wasn't Awesome, it wasn't me.


« Reply #15 - Posted 2013-09-29 05:15:06 »

Depends on your requirement of a spritebatcher.

Ideally, it has all that stuff, but you can't not call it a spritebatcher just because it doesn't use shaders/matrix math etc.

Offline wessles

JGO Ninja


Medals: 49
Projects: 4
Exp: 3 years


Loves games, loves coding; this is only logical.


« Reply #16 - Posted 2013-09-29 05:17:16 »

HaHa... When I heard spritebatching in the first reply, I thought that they meant spritesheets... *facepalm.
But that isnt much of a waste. Sprite sheets are fun!
BTW: Last post of tonight. Gtgtb.

You don't know nerdiness yet; you haven't even met me!
www.wessles.com
Offline kpars

JGO Ninja


Medals: 57
Projects: 4
Exp: 2 years


\o/ I develop things! \o/


« Reply #17 - Posted 2013-09-29 05:20:41 »

Your logo needs some heavy re-working.
Pixel-Art isn't just art scaled down, there are many things to think about while making it.

Other than that, I'd love to try it out!

- Jev.

"Living is easy with eyes closed, misunderstanding all you see." ¤ Kemoy Labs: http://www.kemoy.net/ ¤ My Site: http://www.jeviny.pw/
Offline wessles

JGO Ninja


Medals: 49
Projects: 4
Exp: 3 years


Loves games, loves coding; this is only logical.


« Reply #18 - Posted 2013-09-29 05:36:01 »

It wasn't pixel art, but I had to scale it up. It used to be microscopic on JGO and Imgur and imageshack for some reason...
And yes, thought does go into it, I know. This is actually just supposed to look like an actually good logo, but I lack the software to center everything without hassle.

Hope you try it out when it doesn't have a ton of stuffs to work out!

You don't know nerdiness yet; you haven't even met me!
www.wessles.com
Offline SHC
« Reply #19 - Posted 2013-09-29 05:55:03 »

On Line 48 of
Runner.java


1  
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

I don't see the need for clearing the depth buffer for a 2D engine.

Offline Simn
« Reply #20 - Posted 2013-09-29 13:31:42 »

Cool project!

Have you thought of having a scene (which has a VAO) where you add primitive types and they all get rendered from the same VAO? It will boost performance quite a lot. Wink

- Simn
Offline wessles

JGO Ninja


Medals: 49
Projects: 4
Exp: 3 years


Loves games, loves coding; this is only logical.


« Reply #21 - Posted 2013-09-29 23:22:42 »

@SHC
Thanks! Sorry, I 'borrowed' a lot of code from a simple 3d game I am working on... will remove!

@Simn
I think that that is what sprite batching is. I am already working on it, but thanks for asking!

Shader support(?) and sprite batching coming soon.

You don't know nerdiness yet; you haven't even met me!
www.wessles.com
Offline opiop65

JGO Kernel


Medals: 129
Projects: 7
Exp: 3 years


Team Alluminum


« Reply #22 - Posted 2013-09-29 23:29:08 »

Shader support should be pretty easy, just write a parser and a way to bind and unbind shaders and then apply them to the geometry. Other than that, there's basically nothing else to do I think. It should take you like 30 minutes to an hour to learn how to do it!

Offline wessles

JGO Ninja


Medals: 49
Projects: 4
Exp: 3 years


Loves games, loves coding; this is only logical.


« Reply #23 - Posted 2013-09-30 02:13:27 »

Yup. I already made the shader class. Before I upload to github though, do you think that it should be
1  
2  
bind()
unbind()

or
1  
2  
use()
release()

or just both?
1  
2  
3  
4  
5  
6  
7  
public void bind() {
  use();
}

public void unbind() {
  release();
}


I was wondering, since I know that I want to say bind(), but I have heard use(), and I am wondering if including both will confuse people as to whether or not it is a wrapper method?

You don't know nerdiness yet; you haven't even met me!
www.wessles.com
Offline opiop65

JGO Kernel


Medals: 129
Projects: 7
Exp: 3 years


Team Alluminum


« Reply #24 - Posted 2013-09-30 02:22:05 »

Just stick with the OpenGL way of doing things and use bind and unbind. There's no point in changing things around in a wrapper class.

Offline davedes
« Reply #25 - Posted 2013-09-30 04:15:10 »

If you were trying to mimic OpenGL it would just be
use()
. In OpenGL you can't "unbind" a shader. Binding shader zero just binds an invalid program.

But it's often better to be consistent with the rest of your library. That's why LibGDX uses begin() and end() for things like SpriteBatch, ShapeRenderer, and ShaderProgram.

Quote
You could even go further and make two spritebatchers, one for vertex arrays and one for vertex buffer objects. VBOs are better for static geometry(tiles) and VAs are better for constantly updating an changing geometry(mobs, particles)
Probably better to use a single SpriteBatch class and abstract the vertex data transport. This is what LibGDX does with Mesh; it can use vertex arrays or VBOs. I've also started (sort of) doing this in LWJGL-basics, but I only implemented vertex arrays.
https://github.com/mattdesl/lwjgl-basics/tree/master/src/mdesl/graphics/glutils

Offline opiop65

JGO Kernel


Medals: 129
Projects: 7
Exp: 3 years


Team Alluminum


« Reply #26 - Posted 2013-09-30 04:39:58 »

Oh, crap I forgot shaders in LWJGL used "use". Oops! I was thinking of Slick-utils texture bind function for some reason :/

Can you explain a little more about what you mean by a vertex data transport? Thats the first time I've ever heard that term, but it sounds interesting and technical.

Offline davedes
« Reply #27 - Posted 2013-09-30 06:58:27 »

Sorry, just some jargon I cooked up to mean "abstract class that gives vertex data to GL" -- could be vertex arrays, VBOs, or even immediate mode if you are feelin' crazy.

Offline wessles

JGO Ninja


Medals: 49
Projects: 4
Exp: 3 years


Loves games, loves coding; this is only logical.


« Reply #28 - Posted 2013-09-30 22:44:23 »

Oh, and before I change graphics to
Quote
-Visuals
-Renderer
-Drawer
-Painter
or something, does anyone else think that I should change it, as suggested:
I would refrain from naming your classes the same as their Java2D counterparts (ie Graphics), just to avoid confusion.
or just keep it at graphics?

Tell me what you think!

You don't know nerdiness yet; you haven't even met me!
www.wessles.com
Offline Troncoso

JGO Coder


Medals: 20



« Reply #29 - Posted 2013-09-30 22:50:28 »

I don't honestly see what the confusion would be... and considering it's supposed to be mostly for your personal use, definitely name it whatever makes the most sense to you.

Big takeaway: I think the naming of your classes is probably the least important thing you could possibly be worrying about.
Pages: [1] 2 3 ... 8
  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.

xsi3rr4x (78 views)
2014-04-15 09:08:23

BurntPizza (70 views)
2014-04-14 18:46:01

UprightPath (81 views)
2014-04-14 08:39:50

UprightPath (66 views)
2014-04-14 08:35:47

Porlus (82 views)
2014-04-14 06:48:38

tom_mai78101 (106 views)
2014-04-09 19:04:31

BurntPizza (166 views)
2014-04-08 14:06:04

tom_mai78101 (262 views)
2014-04-05 04:34:39

trollwarrior1 (212 views)
2014-04-04 03:06:45

CJLetsGame (221 views)
2014-03-31 17:16:10
List of Learning Resources
by SHC
2014-04-17 18:17:39

List of Learning Resources
by Longarmx
2014-04-07 18:14:44

Good Examples
by matheus23
2014-04-05 04:51:37

Good Examples
by Grunnt
2014-04-03 06:48:46

Good Examples
by Grunnt
2014-04-03 06:48:37

Good Examples
by matheus23
2014-04-01 09:40:51

Good Examples
by matheus23
2014-04-01 09:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 06:22:30
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!