Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (426)
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]
  ignore  |  Print  
  Books are failing me!  (Read 2300 times)
0 Members and 1 Guest are viewing this topic.
Offline jparril1

Junior Member





« Posted 2011-03-08 19:00:50 »

Hey guys,

         So I have both Killer Game Programming in Java and Developing Games in Java. Im trying desperately to use them and work through them, and I am getting NOWHERE. Before I had these books, I used my own knowledge and help from you guys and managed to put together a decent game of pong. I thought I could dive into these books to get better and do things the "right" way, but all thats happening is confusion. KGPIJ is talking about a million different ways to achieving certain FPS, and then has a bunch of unfinished, broken methods. Im trying to get something out of these but Im getting discouraged. Is it recommended to just forget these "official" books and just use trial and error along with the few online tutorials that exist? I have some links that have been suggested such as Kevs Space Invader tutorial and a few others. In your experience, is it possible to get good at this by just writing code, asking for help, and fixing it until it works?? Right now Im attempting to find some "path" that I seem to be failing at discovering.
Offline BatKid

Senior Newbie





« Reply #1 - Posted 2011-03-08 19:13:41 »

I personally don't think there is a "right" way to learn.  Everyone learns differently and you need to find a way that suits you.  Some people can learn from just reading, others can't understand the concept unless it is presented in code form.  Yet others learn from watching others.

If you find reading the book confusing, I think you should start search for online tutorials/exercises that are right for you.  Once you have some of the basics down, go back to the book and it will make more sense.

Learn Java in 3D with env3d
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11


Game Engineer


« Reply #2 - Posted 2011-03-08 19:28:52 »

I have never used books except for occasional reference - they just don't work for me. Instead, I decide on a project to make (Pong for example), then make it using hackery, crappy code, and a lot of plagiarism from examples on the net. Eventually I learn what it all means from doing that enough times. Smiley

Although to be honest these days I don't do that either, because I know so many programming languages that I don't need to. Instead I just start writing code and debug it as I go.

See my work:
OTC Software
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline pjt33
« Reply #3 - Posted 2011-03-08 21:43:30 »

Probably half of us learned by hacking together stuff before we had access to the Internet (let alone knew where to look for help). So just trying, failing, and trying again clearly works for some.
Offline Sinuath

Junior Member


Medals: 2



« Reply #4 - Posted 2011-03-08 22:55:04 »

You sure the books aren't to advanced for you? there's usually a certain progression you want to follow, the lower level books help you get ready for the higher level books. I'm usually a fan of books when i can get my hands on them, there's to many tutorials out there and they randomly become useless in some instances. Or they don't end up teaching me what i'm looking for. With a book it knows what it's taught you and points you to where you need to go next.

Anyway i wouldn't give up on all books if it's just two that your having trouble with.. buut~ if you can manage to learn this without a book and would rather do it go for it. Some people can manage it, i just can't imagine that it's really easier.

Hey [you][/you], you should totally check out my boring Site ~ http://davediel.com/chris
Offline philfrei
« Reply #5 - Posted 2011-03-08 23:07:37 »

I recall "failing" at trying to learn about Java game programming from a book by an author named Harbour. The example program was based on Asteroids. I do recall being able to change some parameters here and there, getting some of the code working. But a lot of it was incantation as far as I could tell at the time. I had to move on in order to get a better foundation in Java programming.

I would like to suggest putting some specific questions from the books you are reading onto the forum, including examples of what seems to be buggy code. It would be a lot easier to give advice if we knew more specifics. "I'm getting nowhere with books. Should I give up reading?" That's not a lot to work on.

"Greetings my friends! We are all interested in the future, for that is where you and I are going to spend the rest of our lives!" -- The Amazing Criswell
Offline aazimon
« Reply #6 - Posted 2011-03-09 00:44:13 »

I have both books, but haven't finished them. The reason being, that I started with my on game program and ideas, and used the book to improve what I already had. If the book had something that I didn't think worked for me, I chunked it. I recommend you start with the game program you have, and as you read the book, see if it is something that you can use in your game program to improve it.
   You are right the first chapter of KGPJ spent way to much time going over FPS loops. Just skip to his final game loop and see if it's something you can use.
Offline dah01

Junior Member


Medals: 7



« Reply #7 - Posted 2011-03-09 02:43:56 »

I'm in the same boat as the original poster. I've been trying to read these books but they're old and the java3d timer is deprecated. This board doesn't seem to help because there aren't any basic tutorials. Every night I spend all my time trying to find something that isn't deprecated or unclear. It's depressing and I'm considering not returning to java game development.
Offline ra4king

JGO Kernel


Medals: 322
Projects: 2
Exp: 4 years


I'm the King!


« Reply #8 - Posted 2011-03-09 04:03:11 »

The best way is to make your own game loop:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
int FPStime = 1000/FPS;

while(!isGameOver) {
   long startTime = System.currentTimeMillis();
   //GAME CODE
  try{
      long sleepTime = FPStime - (System.currentTimeMillis()-startTime);
      Thread.sleep((int)sleepTime);
   } catch(Exception exc) {
      exc.printStackTrace();
   }
}

Offline jparril1

Junior Member





« Reply #9 - Posted 2011-03-09 04:32:56 »

Thanks for all of the help guys. I think my problem is that Im trying to use the books in a logical order (like a book should be) but in reality I need to use them more as a reference to fix my problems. I think Im just going to hack at my own ideas and designs until I run into a wall, and then either post here or figure it out with the internet or these books. Then from that I can build better ways to do things and start making sense of all this. Any other suggestions are always appreciated! Smiley
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline deadly72

Junior Member





« Reply #10 - Posted 2011-03-09 04:40:33 »

The best way is to make your own game loop:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
int FPStime = 1000/FPS;

while(!isGameOver) {
   long startTime = System.currentTimeMillis();
   //GAME CODE
  try{
      long sleepTime = FPStime - (System.currentTimeMillis()-startTime);
      Thread.sleep((int)sleepTime);
   } catch(Exception exc) {
      exc.printStackTrace();
   }
}


I actually disagree with a tiny point in this code.  The use of currentTimeMillis over nanoTime.  Maybe I am just naive but I've read in a few places that depending on the os currentTimeMillis is slower overall then nanoTime.  The one advantage it has, is being compatible pre 5.0?
Offline ra4king

JGO Kernel


Medals: 322
Projects: 2
Exp: 4 years


I'm the King!


« Reply #11 - Posted 2011-03-09 05:16:52 »

For some weird reason, nanoTime is NOT the same as currentTimeMillisx1000000.
For example, this does not work:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
int FPStime = 1000000/FPS;
 
while(!isGameOver) {
    long startTime = System.nanoTime();
    //GAME CODE
   try{
        long sleepTime = FPStime - (System.nanoTime()-startTime);
        Thread.sleep(0,(int)sleepTime);
    } catch(Exception exc) {
        exc.printStackTrace();
    }
}

Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11


Game Engineer


« Reply #12 - Posted 2011-03-09 05:32:33 »

For some weird reason, nanoTime is NOT the same as currentTimeMillisx1000.
For example, this does not work:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
int FPStime = 1000000/FPS;
 
while(!isGameOver) {
    long startTime = System.nanoTime();
    //GAME CODE
   try{
        long sleepTime = FPStime - (System.nanoTime()-startTime);
        Thread.sleep(0,(int)sleepTime);
    } catch(Exception exc) {
        exc.printStackTrace();
    }
}

Look up nano versus milli.

mill = 1/1000
nano = 1/1000000000

1/1000 of a millisecond is not a nanosecond, it's a microsecond. A nanosecond is 1/1000 of a microsecond.

That aside, currentTimeMillis() is less accurate than nanoTime() so I wouldn't expect them to always line up exactly.

See my work:
OTC Software
Offline ra4king

JGO Kernel


Medals: 322
Projects: 2
Exp: 4 years


I'm the King!


« Reply #13 - Posted 2011-03-09 08:00:53 »

Oh how could I make such a stupid mistake Tongue

However, millis and nano are very different, since if you look it up, System.nanoTime() is not from January 1, 1970.

Updated:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
int FPStime = 1000000000/FPS;
 
while(!isGameOver) {
    long startTime = System.nanoTime();
    //GAME CODE
   try{
        long sleepTime = FPStime - (System.nanoTime()-startTime);
        int m = (int)(sleepTime/1000000);
        int n = (int)(sleepTime%1000000);
        Thread.sleep(m,n);
    } catch(Exception exc) {
        exc.printStackTrace();
    }
}

Offline pjt33
« Reply #14 - Posted 2011-03-09 10:04:10 »

Why does the epoch matter? On the other hand, you're going to get compile-time errors for exceeding the range of int. With nanos, use long.
Offline ReBirth
« Reply #15 - Posted 2011-03-09 13:52:40 »

In my learning process (which is going now), I always start from scratch. When meet a problem
1. try break the problem by myself
2. no result, read some books
3. no result, post here Smiley

just use any way that suit you. for me, try and error is the best.

Online Riven
Showcase Moderator

JGO Overlord


Medals: 612
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #16 - Posted 2011-03-09 15:31:34 »

1  
Thread.sleep(m,n);


Oh, how we all wished that method did what it suggested... it actually rounds the nanos to the nearest millisecond and sleeps for the calculated amount in milliseconds (at which it is very inaccurate).

It's a big joke, really.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline dah01

Junior Member


Medals: 7



« Reply #17 - Posted 2011-03-10 00:22:08 »

Seriously? That's disgusting.
Offline ra4king

JGO Kernel


Medals: 322
Projects: 2
Exp: 4 years


I'm the King!


« Reply #18 - Posted 2011-03-10 02:39:16 »

1  
Thread.sleep(m,n);


Oh, how we all wished that method did what it suggested... it actually rounds the nanos to the nearest millisecond and sleeps for the calculated amount in milliseconds (at which it is very inaccurate).

It's a big joke, really.
What?!? Well this makes me mad, since I just starting using this for my games Angry

Seriously? That's disgusting.
Bahaha agreed Grin

Offline philfrei
« Reply #19 - Posted 2011-03-10 09:59:46 »

Might be interesting to try testing the two methods. But I'm not at all sure as to the best way to go about that. Perhaps, at the given time, print to file or system.out the trigger time and the current time by either method? Hmmm. There is probably something very wrong with that.

It's always nice to get some sort of statement as to the expected tolerances, rather than just "it's inaccurate" which could mean a lot of different things. Tongue

"Greetings my friends! We are all interested in the future, for that is where you and I are going to spend the rest of our lives!" -- The Amazing Criswell
Offline gimbal

JGO Coder


Medals: 25



« Reply #20 - Posted 2011-03-10 10:48:31 »

Seriously? That's disgusting.

Blame the OS / hardware. No mainstream OS can provide nano second precision timing, so adding support for it in Java was basically a useless exercise. The best you can get is microsecond precision from it. But perhaps in the future such things will become possible, who knows.
Online Riven
Showcase Moderator

JGO Overlord


Medals: 612
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #21 - Posted 2011-03-10 11:41:11 »

With a bit of C++ (and a JNI wrapper), we can do accurate milli/micro sleeps:

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  
#include <time.h>
#include <errno.h>

void millisleep(const int ms)
{
    struct timespec sleeptime;
    struct timespec remaining;
    int result;              
    remaining.tv_sec  = (ms/1000);
    remaining.tv_nsec = (ms%1000)*1000000;
    do {                                
        sleeptime.tv_sec  = remaining.tv_sec;
        sleeptime.tv_nsec = remaining.tv_nsec;
        result = nanosleep(&sleeptime,&remaining);
    } while(0>result && EINTR==errno);
}

void microsleep(const int us)
{
    struct timespec sleeptime;
    struct timespec remaining;
    int result;              
    remaining.tv_sec  = (us/1000000);
    remaining.tv_nsec = (us%1000000)*1000;
    do {                                
        sleeptime.tv_sec  = remaining.tv_sec;
        sleeptime.tv_nsec = remaining.tv_nsec;
        result = nanosleep(&sleeptime,&remaining);
    } while(0>result && EINTR==errno);
}

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline gwoptics

Senior Newbie


Projects: 1



« Reply #22 - Posted 2011-03-10 19:18:36 »

I am obviously ignorant and naive, but where would you need nanosecond accuracy anyway? I already find it hard to believe that a few microseconds here or there matter. It's an honest question, in what scenarios do you need accurate microseconds or better?

Andreas

http://www.gwoptics.org - news and games about gravitational waves
http://twitter.com/gwoptics
Offline IronclawsBt

Junior Member


Medals: 1



« Reply #23 - Posted 2011-03-10 19:27:25 »

I am obviously ignorant and naive, but where would you need nanosecond accuracy anyway? I already find it hard to believe that a few microseconds here or there matter. It's an honest question, in what scenarios do you need accurate microseconds or better?

Andreas

For almost everything there is no use. There are, however, some real-time versions of Java where this may be useful. A 2 GHz processor is 0.5 nanoseconds / cycle so the unit is not meaning-less.

It's not what you know, it's what other people think you know.
Just hope you don't get quizzed on it.
Game engine design tutorials
Offline philfrei
« Reply #24 - Posted 2011-03-10 20:03:32 »

If there are musical parts that are off by a couple milliseconds, they definitely start to feel "out of the pocket". At a single millisecond or less, I'd think I'd have trouble identifying parts that lead/lag. Maybe a world-class professional percussionist could sense offsets at the micro-second level, but I think even so, it would be a matter of hundreds of microseconds, not a matter of just a few.

But even with micro-second timing, it's moot if the GC interruptions take milliseconds to complete, yes? I mean, there are issues relevent to timing besides the degree of granularity of the "getCurrentTime" function.

Concerns at the nano-level can be left to the folks at CERN.

"Greetings my friends! We are all interested in the future, for that is where you and I are going to spend the rest of our lives!" -- The Amazing Criswell
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.

xsi3rr4x (75 views)
2014-04-15 18:08:23

BurntPizza (68 views)
2014-04-15 03:46:01

UprightPath (80 views)
2014-04-14 17:39:50

UprightPath (65 views)
2014-04-14 17:35:47

Porlus (81 views)
2014-04-14 15:48:38

tom_mai78101 (105 views)
2014-04-10 04:04:31

BurntPizza (165 views)
2014-04-08 23:06:04

tom_mai78101 (261 views)
2014-04-05 13:34:39

trollwarrior1 (210 views)
2014-04-04 12:06:45

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

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

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

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

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

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

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

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