Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
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  
  Libraries You Wish For  (Read 1031 times)
0 Members and 1 Guest are viewing this topic.
Offline TeamworkGuy2

Junior Member


Medals: 10



« Posted 2014-04-05 01:59:21 »

I've seen a number of projects, libraries, and utilities pop up on this forum with varying degrees of adoption and acclaim.  Other than texture atlas/sprite sheet loading and manipulation and princec's interest in memory manipulation/mapped objects, I haven't seen many specific recurring complains about non-existent libraries.
Are most of JGO's family members happy with the tools and features available for Java game development?

Your problem could lie with the core Java libraries, or maybe OpenGL or lwjgl, or some pattern that you frequently encounter in your coding.
I'm sure some of you have at some point been annoyed at having to open a file reader with:
1  
new BufferedReader(new InputStreamReader(new FileInputStream(file)));

or at having to type:
1  
Map.Entry<Abc, Xyz> entry = new AbstractMap.SimpleImmutableEntry(a, x);

just to create an entry to store in some collection and wished for an Entry class in Java.

The example boiler plate code can easily be solved with a utility class.  Is there a specific library or functionality that you wish existed in Java, but you can't find anywhere online.  Maybe it's related to logging, or the Java collections framework, or OpenGL's state based nature, or serialization?

Please post, discuss, share your problems/solutions Smiley
Offline HeroesGraveDev

JGO Kernel


Medals: 260
Projects: 11
Exp: 2 years


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


« Reply #1 - Posted 2014-04-05 02:05:09 »

Sometimes I want random numbers and don't care about the seed or anything, so I made a class that manages a static random instance and has a few helper functions (like
random(min, max)
)

Saves me a lot of time.

Online BurntPizza
« Reply #2 - Posted 2014-04-05 04:10:11 »

I made a class a while ago (years actually, jeez doesn't seem that long) that acted as a replacement for java.awt.Graphics, had all the simple drawing methods, but acted on an integer array instead of an image. Was quite useful for the falling sand game I wrote way back when.

Although @Heroes, isn't that more or less Math.random()? A static random instance?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline HeroesGraveDev

JGO Kernel


Medals: 260
Projects: 11
Exp: 2 years


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


« Reply #3 - Posted 2014-04-05 05:31:41 »

Although @Heroes, isn't that more or less Math.random()? A static random instance?

An instance of
java.util.Random
, because it has more useful methods.

Offline princec

JGO Kernel


Medals: 390
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #4 - Posted 2014-04-05 08:38:45 »

I've made a complete custom binary serialization/deserialization protocol library. I had to do it because I needed something more robust than Java serialization - mine is proof against DoS attacks for example caused by a binary stream that, say, specifies huge 20mb arrays. It's also slightly faster and more lightweight but those are not really relevant side effects.

I've also on top of that made a custom RMI client and server system to replace Java RMI, for similar reasons. It's much simpler though it does handle a few clever things like serializing remote references. It's based on the aforementioned serialization lib.

I've got a library of *List, *Grid and *Cube classes for primitives and objects which is invaluably useful and I might even think about implementing Roquen's Morton functions in the lookups for fun.

Cas Smiley

Offline gene9

Senior Member


Medals: 10



« Reply #5 - Posted 2014-04-06 03:35:36 »

I'm sure some of you have at some point been annoyed at having to open a file reader with:
1  
new BufferedReader(new InputStreamReader(new FileInputStream(file)));


If you are using Java 7+, you can use the NIO.2 API which is pretty simple:

1  
Files.newBufferedReader(filePath, Charset.defaultCharset());


IMO, the Java community has pretty amazing libraries that cover all the basics.
Offline TeamworkGuy2

Junior Member


Medals: 10



« Reply #6 - Posted 2014-04-06 15:30:30 »

The example boiler plate code can easily be solved with a utility class.

I think my most common time sink that I wish was simpler is saving and load basic properties.  The Properties class definitely gets me most of the way there, but it's still annoying to try and save for example a Color preference.
One or two lines of code to convert the color to an integer or hex string, then another two or three lines to read it back and convert it to an integer and then to a color.  You end up with a lot of boiler plate code to support property types other than strings (file paths, floats, integers, colors, etc).

Princec, yes, I've been reading Effective Java and the last chapter of the book is about serialization and there are so many issues with just marking a class serializable: compatibility, injection attacks, security, etc.  Serialization is definitely a poorly implemented language feature; to do it properly you need to add read and write methods and do all of the serialization processing yourself.
Offline Slyth2727
« Reply #7 - Posted 2014-04-06 16:03:33 »

Hell I always have a Util class that has methods like log(Str), log(Prefix, Str), random functions, float/int/bytebuffer functions and so on. Saves me a bunch of time.

Was I before Chuang Tzu who dreamt about being a butterfly, or am I now a butterfly who dreams about being Chuang Tzu?
Online BurntPizza
« Reply #8 - Posted 2014-04-06 17:04:36 »

The Properties class definitely gets me most of the way there, but it's still annoying to try and save for example a Color preference.

You ever try Preferences?

1  
2  
3  
4  
5  
6  
7  
Preferences prefs = Preferences.userNodeForPackage(getClass());

String playerName = prefs.get("player_name", "Default Name");
int highScore = prefs.getInt("high_score", 0);
Color thatColor = new Color(prefs.getInt("special_color", 0xFFFFFFFF));
...
prefs.putInt("special_color", thatColor.getRGB());


Still can't auto-serialize objects or anything, but I'd say it's still more convenient than Properties.
Offline RobinB

JGO Ninja


Medals: 44
Projects: 1
Exp: 3 years


Spacegame in progress


« Reply #9 - Posted 2014-04-06 21:31:53 »

Got loads of static helper classes like this:

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  
public static float fastAbs(final float f)
    {
        return f >= 0.0f ? f : -f;
    }

    public static double fastAbs(final double d)
    {
        return d >= 0.0D ? d : -d;
    }

    public static long fastAbs(final long d)
    {
        return d >= 0l ? d : -d;
    }

    public static float clamp(float value)
    {
        if (value > 1.0f)
            return 1.0f;
        if (value < 0.0f)
            return 0.0f;
        return value;
    }

    public static float clamp(float value, float min, float max)
    {
        if (value > max)
            return max;
        if (value < min)
            return min;
        return value;
    }


Also got some class with fast sin/cos functions and float pi consts
1  
public static final float PIf=(float)Math.PI, PI2f=2*PIf, PI05f=0.5f*PIf, PI025f=0.25f*PIf, PI075f=0.75f*PIf, PI15f=1.5f*PIf;
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online BurntPizza
« Reply #10 - Posted 2014-04-06 21:58:09 »

@Robin
If you are really going for the explicit purpose of "fast," I wouldn't use conditionals:
http://www.java-gaming.org/topics/bit-twiddle-amp-branch-removal/21443/view.html
However things might have changed in the JVM since 2009 enough to make these irrelevant.

Also Riven has some tricks on his blog: http://riven8192.blogspot.com/2009/08/fastmath-sincos-lookup-tables.html


A fast XOR shift RNG I like to use if I need tens of millions of integers a second:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
/**
* Returns random int between 0 and n
* Includes 0, excludes n
*/

public static final int randInt(int n) {
        seed ^= (seed << 1);
        seed ^= (seed >>> 5);
        seed ^= (seed << 9);
        int result = seed % n;
        return result < 0 ? -result : result;
}
static int seed = 48659236;


Hmm, I should probably stop, this thread could very quickly turn into a mini version of the Shared Code board.
Offline TeamworkGuy2

Junior Member


Medals: 10



« Reply #11 - Posted 2014-04-06 22:36:50 »

The Properties class definitely gets me most of the way there, but it's still annoying to try and save for example a Color preference.

You ever try Preferences?
Good to know.

Yes, this thread ended up being a little broad, I was specifically wondering what types of libraries people wanted, but could not find.  Maybe most commonly needed library have already been developed, or maybe we don't know what we're missing until it gets developed.  Anyway, the focus was to talk about what does not exist currently, not things that did not exist previously, but does now  Smiley
Offline Roquen
« Reply #12 - Posted 2014-04-07 11:22:39 »

Quote
If you are really going for the explicit purpose of "fast," I wouldn't use conditionals:
http://www.java-gaming.org/topics/bit-twiddle-amp-branch-removal/21443/view.html
However things might have changed in the JVM since 2009 enough to make these irrelevant.
Conditionals are always tricky.  Does hotspot convert into a branch or not...if a branch on average will the prediction be correct.  A correctly predicted branch is as close to free as possible...mispredicted can get quite expensive.  Hotspot has change alot, but branchless versions are still interesting.  As an example HotSpot engineers are currently wondering what to do about Math.max & Math.min...both of which are intrinsic, but they way they are lowering (to a conditional move) can have drastically negative impact on performance.  (The start of the conversion is here: http://comments.gmane.org/gmane.comp.java.openjdk.hotspot.compiler.devel/13893, but there's quite a few comments since)  A specific comment in that thread, no showing here is "Bit twiddling vs cmov is hard to guess at.  With register renaming (and register files seem to be growing) and more exec units it's possible that bit twiddling can end up faster, but sure, this is not a rule."  For min/max is dep-chain length is four and it needs one temp register..not heavy weight, so it's going to depend on what surround code is doing.

But in general, just use one that works.  You only need to think about the choice at some "spots" that are inside something you need to juice cycles out of and you can't think of any other options.

int result = seed % n; return result < 0 ? -result : result;


can be replaced by

return (seed>>>1) % n;


and you can kill the division by treating the result as fixed-point (https://github.com/roquendm/JGO-Grabbag/blob/master/src/roquen/math/rng/PRNG.java)
Offline Roquen
« Reply #13 - Posted 2014-04-07 13:43:48 »

Oh I skipped the middle ground: 
(int) (n * ((result >>> 12) * 0x1p-52));


---
There lots of libraries I people wish would write for or port to java.  A recently mentioned is recast detour for navigation meshes.
Pages: [1]
  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.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (19 views)
2014-09-24 16:12:06

Grunnt (45 views)
2014-09-23 14:38:19

radar3301 (28 views)
2014-09-21 23:33:17

BurntPizza (63 views)
2014-09-21 02:42:18

BurntPizza (33 views)
2014-09-21 01:30:30

moogie (41 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
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!