Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (511)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (577)
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  
  building new engine from scratch, networking/GUI questions  (Read 4487 times)
0 Members and 1 Guest are viewing this topic.
Offline nanowired

Junior Newbie





« Posted 2012-04-13 19: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.
Offline _Al3x

Senior Duke


Medals: 7


Indie Games FTW!


« Reply #1 - Posted 2012-04-13 20:53:47 »



BTW, try looking to JGO tutorials, they are very good! Smiley

Offline nanowired

Junior Newbie





« Reply #2 - Posted 2012-04-13 21: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!
Legends of Yore - The Casual Retro Roguelike
Offline davedes
« Reply #3 - Posted 2012-04-13 21:26:22 »

Basically what you're saying is you want to reinvent everything and you have no idea where to start... Roll Eyes

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.

Offline nanowired

Junior Newbie





« Reply #4 - Posted 2012-04-13 21: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...
Offline evilfrenchguy

Junior Duke


Medals: 3



« Reply #5 - Posted 2012-04-14 20: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.
Offline sproingie

JGO Kernel


Medals: 202



« Reply #6 - Posted 2012-04-14 21: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.
Offline ra4king

JGO Kernel


Medals: 350
Projects: 3
Exp: 5 years


I'm the King!


« Reply #7 - Posted 2012-04-14 21: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

Offline jonjava
« Reply #8 - Posted 2012-04-14 21:25:06 »

Really??

I do that all the time... Shocked

Why is it bad?

Offline ra4king

JGO Kernel


Medals: 350
Projects: 3
Exp: 5 years


I'm the King!


« Reply #9 - Posted 2012-04-14 21:29:01 »

It's creating a StringBuilder every single time it loops Wink

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline jonjava
« Reply #10 - Posted 2012-04-14 21: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?

Offline Mike

JGO Wizard


Medals: 86
Projects: 1
Exp: 6 years


Java guru wanabee


« Reply #11 - Posted 2012-04-14 21:37:16 »

I do that all the time... Shocked

Now look at what you did to the kittens!



Something like this Smiley
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

My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
Offline ra4king

JGO Kernel


Medals: 350
Projects: 3
Exp: 5 years


I'm the King!


« Reply #12 - Posted 2012-04-14 21: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));

Offline jonjava
« Reply #13 - Posted 2012-04-14 21: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

Offline sproingie

JGO Kernel


Medals: 202



« Reply #14 - Posted 2012-04-14 22: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).  
Offline ra4king

JGO Kernel


Medals: 350
Projects: 3
Exp: 5 years


I'm the King!


« Reply #15 - Posted 2012-04-14 22:18:04 »

I see no benefits of StringBuilder over concat.

Offline sproingie

JGO Kernel


Medals: 202



« Reply #16 - Posted 2012-04-14 22: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.
Offline ra4king

JGO Kernel


Medals: 350
Projects: 3
Exp: 5 years


I'm the King!


« Reply #17 - Posted 2012-04-14 22:33:38 »

Oh I forgot about the String allocation part. I was thinking about both using char arrays anyways. Gotcha. Tongue

Offline Mike

JGO Wizard


Medals: 86
Projects: 1
Exp: 6 years


Java guru wanabee


« Reply #18 - Posted 2012-04-15 08:25:33 »

Oh I forgot about the String allocation part. I was thinking about both using char arrays anyways. Gotcha. Tongue

Yay, I was right! Smiley (in regards to a java question, I think I'm getting a hang of this!) Smiley

My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
Offline jonjava
« Reply #19 - Posted 2012-04-15 13: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?

Offline sproingie

JGO Kernel


Medals: 202



« Reply #20 - Posted 2012-04-15 17: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.

Offline badlogicgames
« Reply #21 - Posted 2012-04-15 18:35:12 »

It's still totally relevant on Android, where any GC invocation can stop the world for 200ms.

http://www.badlogicgames.com - musings on Android and Java game development
Offline divxdede

Junior Duke





« Reply #22 - Posted 2012-04-16 06: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  
/**
 * A simple string formatter giving an easy, readable and efficient way to concatenates strings.
 * <p>
 * This <code>formatter</code> provide a substituion of any <strong><code>%%</code></strong> by the specified argument.<br>
 * Each argument's are formatted accordingly their {@link Object#toString()} methods.
 * <p>
 * Exemple:
 * <pre>
 *    String result = SimpleFormatter.format("%% documents sent by %%" , 125 , "Mr. Anderson");
 *    System.out.println(result);
 * </pre>
 * giving:
 * <pre>
 *    125 documents sent by Mr. Anderson
 * </pre>
 *
 * @author André Sébastien (divxdede)
 * @since 0.2
 */

public final class SimpleFormatter {
   
    /** private constructor, no instanciation
     */

    private SimpleFormatter() {
    }

    /** Format a {@link String} by replacing each <strong><code>%%</code></strong> occurrences by the specified arguments.<br>
     *  Each arguments are formatted accordingly to their {@link Object.toString()} methods.
     *  <p>
     *  Exemple:
     *  <pre>
     *      String result = SimpleFormatter.format("Hello Mr. %% !! You take the %% pill" , "Anderson" , "pill");
     *  </pre>
     *  <p>
     *  For some performance optimization, this method don't perform all pre-checks call.<br>
     *  If you give less arguments than <code>%%</code> occurences then this method don't fails and let extra %% occurences as is.<br>
     *  But in the counter parts, if you provide more argument's than <code>%%</code> occurences, this method will throw an IllegalArgumentException
     *
     *  @param format String used to build the result, each <code>%%</code> are replaced by the specified arguments.
     *  @param args Subtitue arguments used for replace each <code>%%</code> occurences. The first argument replace the first %%, etc..
     *  
     *  @return String result
     *  @throws IllegalArgumentException If args's length is not equals to the <code>%%</code> occurences.
     *  @throws NullPointerException if <code>format</code> is null and args is no-empty
     */

    public static String format(String format , Object... args ) {
        if( args == null || args.length == 0 ) return format;
       
        /** On tranforme les arguments en chaine de caracteres et on determine la taille
         */

        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();
        }
       
        /** Construction du résultat
         */

        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 );
    }
}


Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (42 views)
2014-10-16 15:22:06

Norakomi (32 views)
2014-10-16 15:20:20

lcass (37 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (66 views)
2014-10-14 00:35:47

TehJavaDev (58 views)
2014-10-14 00:32:37

BurntPizza (73 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45

BurntPizza (85 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!