nanowired
Junior Newbie
|
 |
«
Posted
2012-04-13 21:28:24 » |
|
Greetings!
I am looking to start developing a game for this summer and I would like some assistance on how to approach a few things. I've had some experience with Java through school, and we have not covered some of these topics so I'm not sure how to approach it.
the game itself is going to be isometric and either 2d or 3d. I'm not sure how that part will work in Java and I may need help locating resources on how to work a UI and how to interact with graphics. The game I am thinking of is going to be a roleplaying game on one gigantic map, and possibly with sub maps.
I want to build this game so that if I DO use multiplayer, it will be easier to implement. This is something ABSOLUTELY not covered yet in my classes. What I want to do is have each game be it's own individual server, hosted on the computer itself.
As a bonus to myself, I want to make this game so it works on both PC and Android tablets, and can play cross platform.
sooo, any suggestions? Also if there is a free(mostly free?) engine which will do the job, let me know.
|
|
|
|
|
_Al3x
|
 |
«
Reply #1 - Posted
2012-04-13 22:53:47 » |
|
 BTW, try looking to JGO tutorials, they are very good! 
|
|
|
|
nanowired
Junior Newbie
|
 |
«
Reply #2 - Posted
2012-04-13 23:04:06 » |
|
That's a good one, i'll have to save that for my club.
|
|
|
|
|
Games published by our own members! Check 'em out!
|
|
davedes
|
 |
«
Reply #3 - Posted
2012-04-13 23:26:22 » |
|
Basically what you're saying is you want to reinvent everything and you have no idea where to start...  It will probably take you the entire summer just to program a solid GUI library; even then, it probably won't be as good as others that exist already (like TWL) since those have been maturing over time with plenty of testing and very experienced programmers. And GUI is simple compared to programming a full-blown 3D engine that works on android and desktop! My suggestion would be to start by programming some simple 2D games with LibGDX, and try getting them to work on Android and Desktop. Once you are comfortable with that, you can try making a simple 3D game. And then... only then.. you can try to tackle the "awesome 3D multiplayer game" idea.
|
|
|
|
nanowired
Junior Newbie
|
 |
«
Reply #4 - Posted
2012-04-13 23:38:04 » |
|
Well, I'm not looking for "ZOMG AWESOME" Graphics, nor am I really looking to re-invent anything. I'll check out the library you mentioned, should be helpful...
|
|
|
|
|
evilfrenchguy
|
 |
«
Reply #5 - Posted
2012-04-14 22:18:39 » |
|
Basic networking is pretty easy. The challenge is in designing your client/server model to suit your needs and not have lag. In my junior year of college, our class was split into two groups of four and each group had to design and build its own mini mmorpg. We had one person do the web site, one do databases, and me and another guy coded the client and server. The trick is to keep the number of objects on your server as low as possible. Like don't concatenate string literals. That's a lot of overhead and it can crash the server. We made that mistake and our server couldnt support more than 15 people. Granted we still got a goodgrade because the other teams wouldn't even run.
It came out pretty cool though. You could walk around, cha, fight monsters, and pick up gold andweapons.
|
|
|
|
|
sproingie
|
 |
«
Reply #6 - Posted
2012-04-14 23:08:37 » |
|
Concatenating string literals is free, and even a big chain of "foo" + bar + "baz" + mumble + "frotz" is smart enough to get turned into a Stringbuilder internally. It's when you repeatedly append to strings in a loop that God kills a kitten.
|
|
|
|
|
ra4king
|
 |
«
Reply #7 - Posted
2012-04-14 23:15:01 » |
|
Concatenating string literals is free, and even a big chain of "foo" + bar + "baz" + mumble + "frotz" is smart enough to get turned into a Stringbuilder internally. It's when you repeatedly append to strings in a loop that God kills a kitten.
Oh god...so many dead kittens... T_______T
|
|
|
|
jonjava
|
 |
«
Reply #8 - Posted
2012-04-14 23:25:06 » |
|
Really?? I do that all the time...  Why is it bad?
|
|
|
|
ra4king
|
 |
«
Reply #9 - Posted
2012-04-14 23:29:01 » |
|
It's creating a StringBuilder every single time it loops 
|
|
|
|
Games published by our own members! Check 'em out!
|
|
jonjava
|
 |
«
Reply #10 - Posted
2012-04-14 23:34:49 » |
|
Ie. 1 2 3 4 5
| String str = ""; for(int i=0; i < 100; i++) { str + = "Bla " + i; } |
What's the correct way of doing this sort of thing?
|
|
|
|
Mickelukas
|
 |
«
Reply #11 - Posted
2012-04-14 23:37:16 » |
|
I do that all the time...  Now look at what you did to the kittens!  Something like this  1 2 3 4 5
| StringBuilder sB=new StringBuilder(); for (int i=0; i<100; i++){ sB.append("Bla "); sB.append(i); } |
What your code actually does is: 1 2 3 4
| String str=""; for (int i=0; i<100; i++){ str=new StringBuilder(str).append("Bla ").append(i).toString(); } |
That's a lot of StringBuilder objects created. Mike
|
|
|
|
ra4king
|
 |
«
Reply #12 - Posted
2012-04-14 23:44:49 » |
|
Or no need for any creation of objects: 1 2 3
| String str = ""; for(int i = 0; i < 100; i++) str = str.concat("Blah").concat(String.valueOf(i)); |
|
|
|
|
jonjava
|
 |
«
Reply #13 - Posted
2012-04-14 23:47:17 » |
|
I see. Thanks for the clear explanations!
Is it me or is this a feature the java compiler could/should do for you?
Oh and, about the dead cats - cats are bastards, kittens are just soon to be egoistic sociopaths. :}
Dogs are way better:D
|
|
|
|
sproingie
|
 |
«
Reply #14 - Posted
2012-04-15 00:01:24 » |
|
1
| str = str.concat("Blah").concat(String.valueOf(i)); |
Very very wrong, loses even the benefits of a StringBuilder. Create a StringBuilder outside of the loop, use it in the loop. You may see older guides that tell you to use a StringBuffer, just s/Buffer/Builder/ and use the same API and you're fine (StringBuffer is overly synchronized which is why it was superceded by StringBuilder).
|
|
|
|
|
ra4king
|
 |
«
Reply #15 - Posted
2012-04-15 00:18:04 » |
|
I see no benefits of StringBuilder over concat.
|
|
|
|
sproingie
|
 |
«
Reply #16 - Posted
2012-04-15 00:21:30 » |
|
StringBuilder uses an internal buffer that is resized as needed, using overextension to avoid too many reallocations. str.concat(a).concat(b) creates two new new intermediate strings. Doing it in a loop n times creates n times that many.
|
|
|
|
|
ra4king
|
 |
«
Reply #17 - Posted
2012-04-15 00:33:38 » |
|
Oh I forgot about the String allocation part. I was thinking about both using char arrays anyways. Gotcha. 
|
|
|
|
Mickelukas
|
 |
«
Reply #18 - Posted
2012-04-15 10:25:33 » |
|
Oh I forgot about the String allocation part. I was thinking about both using char arrays anyways. Gotcha.  Yay, I was right!  (in regards to a java question, I think I'm getting a hang of this!) 
|
|
|
|
jonjava
|
 |
«
Reply #19 - Posted
2012-04-15 15:28:13 » |
|
So in regards to the follow up question:
Isn't this an optimization the java compiler could (should) do for you?
If not, why shouldn't it?
|
|
|
|
sproingie
|
 |
«
Reply #20 - Posted
2012-04-15 19:02:22 » |
|
The compiler does already do an optimization by using StringBuilder. Recent JVMs do escape analysis and do stack allocation. And Hotspot has always done inlining. I don't want to overstate the slowness of doing string concatenation naively -- it's not as deadly to performance as it was in Java 1.0 -- but it's still good to avoid it if you're going to be calling it frequently, to avoid unnecessary gc overhead if nothing else.
|
|
|
|
|
badlogicgames
|
 |
«
Reply #21 - Posted
2012-04-15 20:35:12 » |
|
It's still totally relevant on Android, where any GC invocation can stop the world for 200ms.
|
|
|
|
divxdede
|
 |
«
Reply #22 - Posted
2012-04-16 08:15:20 » |
|
When i can inline a string concatenation, i use a small class that i had written : I use it like it : 1
| String result = SimpleFormatter.format("Hello Mr. %%, take the %% pill" , "Anderson" , "blue" ); |
It is time and allocation efficient. the class: 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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| public final class SimpleFormatter { private SimpleFormatter() { }
public static String format(String format , Object... args ) { if( args == null || args.length == 0 ) return format; String[] strArgs = new String[ args.length ]; int strArgsLength = 0; for(int index = 0 ; index < args.length ; index++ ) { strArgs[index] = ( args[index] == null ? "null" : args[index].toString() ); strArgsLength += strArgs[index].length(); } char[] result = new char[ format.length() + strArgsLength - (2 * args.length) ]; int resultPosition = 0; int strArgsIndex = 0; int formatPositionDebut = 0; int formatPositionFin = 0; String currentArgs = null; while( strArgsIndex < args.length ) { formatPositionFin = format.indexOf("%%",formatPositionDebut); if( formatPositionFin < 0 ) throw new IllegalArgumentException("Incorrect argument's count");
format.getChars( formatPositionDebut , formatPositionFin , result , resultPosition); resultPosition += (formatPositionFin - formatPositionDebut); currentArgs = strArgs[strArgsIndex++]; currentArgs.getChars( 0 , currentArgs.length() , result , resultPosition ); resultPosition += currentArgs.length(); formatPositionDebut = formatPositionFin + 2; } if( formatPositionDebut < format.length() ) { format.getChars( formatPositionDebut , format.length() , result , resultPosition); } return new String( result ); } }
|
|
|
|
|
|
|