Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Shared Code / Re: Line of sight through 2d polygons (shadows, field of view) on: 2009-10-01 21:22:27
Similarly to your experiences with visualVM I've had the same problems of skewed results when using netbean's profiler

I think these might be the same beast under the covers, just a re-package by Sun.

I like the System.nanoTime approach, very clever. I'll try that, thanks  Smiley

nanoTime() is pretty awesome, but it uses a CPU specific ticker, so it may act weird on multi-CPU boxes (Usually AMD + Windows).  If the nanoTime() calls run on different CPUs, they can return wildly different timestamps which can make your code go crazy.  I think you can get a patch from AMD that will keep them in sync.  Great for development, but can produce weird bugs if you use it on customer boxes.


Anyway, nice stuff man, thanks for sharing.   Smiley
2  Java Game APIs & Engines / Java 2D / Re: Can't draw into BufferedImage on: 2009-10-01 21:01:47
Your composite code looks to me like it's making the whole buffer permanently blank, though I don't really know.  I've never used the setComposite method and aren't going to look it up.

Really, you should probably be drawing to a BufferStrategy for the JFrame (or whatever) that you're using, not a BufferedImage.  If you wanted to do some kind of effects on the whole screen or create a screenshot, it might make sense to draw to a BufferedImage.

+1 on this one.  AlphaComposite.CLEAR means always zero the color and alpha channel on the destination.  Drop your call to setComposite() and use setColor() + fillRect() to clear either the image or buffer strategy.
3  Game Development / Newbie & Debugging Questions / Re: How to initalize a 2D array? on: 2009-09-25 16:24:08

Yeah.  That one trips up C/C++ guys all the time.  Keep in mind that arrays are objects, so the first dimension is an array of references.  Means an index can contain nulls or reference any int array, including ones of different lengths, or the same array.

lol, Stranger's link has it right in a couple of places, but shows the same mistake in the initializing arrays section.   Roll Eyes

1  
2  
3  
int[] oneDim = new int[]{1,2,3};
int[][] twoDim = new int[][]{{1,2,3},{4,5,6},{7,8,9}};
int[][] weirdButLegal = new int[][]{null, oneDim, oneDim , twoDim[1],{7,8,9,10,11,12,13,14,15}};

4  Game Development / Newbie & Debugging Questions / Re: question about an active rendering implementation on: 2009-09-21 21:54:17

Sorry dude, didn't mean for my reply to be so hard to follow.   Sad

As Abuse pointed out, rendering directly using the BufferStrategy will hardware accelerate the operations on a modern VM.
For Windows, a modern VM is 1.6u10+
http://java.sun.com/javase/6/webnotes/6u10.html

BufferedImages are "managed" by default.  "Managed" images are cached in VRAM when they are drawn.  If the image is later altered, the cached copy is discarded.  Since the example code alters the image every frame, a cached VRAM copy is never used.
http://java.sun.com/j2se/1.5.0/docs/guide/2d/new_features.html

This snippet draws a blue box in a random location each frame, and is NOT accelerated:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
BufferedImage img = gc.createCompatibleImage( 640, 480 );  //whole screen buffer
while (true){
    Graphics gfx = img.getGraphics();
    gfx.setColor(Color.BLACK);
    gfx.fill(640,480);  //oops, image content altered..., VRAM cache discarded if present.
   int x = rand.nextInt(256);
    int y = rand.nextInt(256);
    gfx.setColor(Color.BLUE);
    gfx.fillRect(x,y,50,50);  //draw blue box in random location on large image
   gfx.dispose();
    Graphics bufGfx = bufferStrategy.getDrawGraphics();
    bufGfx.drawImage(img,0,0,null);  //draw large image, always modified since last draw, must copy from system RAM to VRAM
   bufGfx.dispose();
    bufferStrategy.show();
    // sleep, yield, etc...
}


This snippet does the same, but uses BufferStrategy acceleration and BufferedImage caching:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
BufferedImage img = gc.createCompatibleImage( 50,50 );  //small image of a blue box, so only 50x50.
Graphics gfx = img.getGraphics();
gfx.setColor(Color.BLUE);
gfx.fillRect(0,0,50,50);  //image is rendered only once.
gfx.dispose();
while (true){
    Graphics bufGfx = bufferStrategy.getDrawGraphics();
    bufGfx.setColor(Color.BLACK);
    bufGfx.fill(640,480);  // direct call on buffer, accelerated by DirectX or OpenGL
   int x = rand.nextInt(256);
    int y = rand.nextInt(256);
    bufGfx.drawImage(img,x,y,null);  //draw small image at random location.  image not modified, so quick copy from VRAM is possible
   bufGfx.dispose();
    bufferStrategy.show();
    // sleep, yield, etc...
}


Admittedly, for just drawing a blue box, there isn't much value in caching the image.  I was just trying to show how to properly use a BufferedImage to take advantage of hardware acceleration.

manasink
5  Game Development / Newbie & Debugging Questions / Re: question about an active rendering implementation on: 2009-09-17 22:02:59
I used to do the two step process in the past because the graphics pipeline in 1.4 and 1.5 didn't support alpha blending for hardware accelerated images unless you added a command line parameter.   Hardware acceleration worked fine for opaque images, or bitmask (0% or 100% only) transparency, but translucent blends (50% like stained glass, shadows, fog, etc) had to be done on the heap, and the result blitted opaque as a second step.  I think the new VMs have accelerated alpha blending by default, so this may be a thing of the past.

BufferedImage WILL try to accelerate content, but any time you alter it's contents it gets flagged as dirty.  If you write to the image every frame, or access the backing pixel array, it will always be dirty, and always get copied from system memory to video memory (LAME).  If you avoid changing the image it will cache an  accelerated version in video memory.  I use this to avoid doing the really expensive stuff like scaling and rotating every frame.

If you are using the flip strategy on your BufferStrategy, it will block for the monitor vsync when you show it.  This will cap your framerate to the monitor hertz, typically 60 fps, and a small overrun on every frame would cut that in half waiting for the next vsync.  This does prevents tearing though, which pisses me off worse than a slower frame rate, but can surprise you if you don't expect it.

Hope that helps.   Grin
6  Discussions / General Discussions / Re: Recent bout of spam on: 2009-09-16 20:32:10
why not a small and simple applet game, like a "Frogger" game (or some random easy games, developed by the community  Wink )?
that should be easy for a human to win, while not easy for a machine - and plus, would  be fun to implement and already give the new user a little bit taste of a java game .
And to play a 20-seconds java game should not bother any user interested in, well, java games .

Man, I just got goosebumps!   I don't know how practical it is since it would force a jre install, but I gotta say, I'm in love with that idea.   Grin
7  Discussions / Miscellaneous Topics / Re: Tetris AI challange on: 2009-08-28 17:36:20

Glad I'm not the only one that thinks forcing the client write a servlet or CGI is irritating. 

They's probably get a lot more participation if they flipped the communication direction so that the client makes the http call to post a move and is returned the new board.

How about head to head competition between AI's and matching rows drops extra junk on the opponent board?   Cheesy
8  Java Game APIs & Engines / Java 2D / Re: Stutter in Game Loop on: 2009-08-27 16:48:26
A very good alternative to Java2D is Slick2D. It should get your game running as smooth as butter since it uses OpenGL.

I'd second this.  It also handles input (including joystick), sound, has a particle system, and plenty of example code.  It's by kev glass, who is pretty active here on the forums.  If your writing a 2D game, and don't want to write all the boilerplate, this is a great way to go.
9  Game Development / Performance Tuning / Re: Whats the ideal way to rewrite my game? on: 2009-08-24 17:58:01
Whoa, nice post JL235.

overeasy, can you go over some of the basics of your setup?  You mentioned that you stuff runs with a fixed step.  If you aren't using a time step variable, then you typically have something similar to the following game loop:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
long targetFPS = 100;
long maximumNanosPerFrame = TimeUnit.SECONDS.toNanos(1) / targetFPS;  // at 100 FPS, should be 10M
while (running){
    long frameStartTime = System.nanoTime();
    updateGameLogic();
    renderToScreen();
    long elapsedNanosThisFrame = System.nanoTime() - frameStartTime;
    long nanosTillNextFrame = maximumNanosPerFrame - elapsedNanosThisFrame;
    if (nanosTillNextFrame > 0)
        try {
            TimeUnit.NANOSECONDS.sleep( nanosTillNextFrame );
       } catch (InterruptedException ie) {
            System.out.println("weird, got interrupted while sleeping.  Spurious interruption on Solaris or Linux maybe? Ignoring.");
       }
    else
        System.out.println("Probable stutter.  Frame took too long, overrun by " + ( - nanosTillNextFrame) );
}


This code executes updates the game logic (one fixed step), renders the view, then sleeps to smooth out and throttle the framerate.  The sleep is required to smooth out the frames, so they occur at regular intervals, otherwise the game speeds up or slows down depending on what is happening at the time, or how fast the computer it is running on.  If you are using something like this to smooth out the frame timing, than you most likely cause of stuttering is something in the updateGameLogic() or renderToScreen() methods that is taking too long, and causing a single frame to stall (elapsedNanosThisFrame) and exceed the ideal time for a frame (maximumNanosPerFrame).  Another possibility is that a JVM garbage collection pause is doing the same thing.

If your game has stalled frames, then the profiler can help you figure out what is slowing things down.  If it is garbage collection, then you will have spikes of the purple line in the CPU graph and a drop in heap size when your frames stall.  If some part of your algorithm is CPU heavy, it should show up in the hot spots list.

Hope that helps.  Grin

10  Games Center / WIP games, tools & toy projects / Re: Niche - 7 day mash up on: 2009-08-21 19:22:56
At the risk of both changing the subject and showing off my noobness -- you can have circle bounding areas?   Shocked

I've only ever used rectangles for that....



Circles makes awesome bounding areas, especially if you are doing circle to circle collision checks, since you can just check the distance between the two centers (or more commonly, the distance squared to avoid the expensive sqrt ).
11  Game Development / Newbie & Debugging Questions / Re: URLConnection getContentLength() on: 2009-08-20 19:56:18

Try changing:

    t.interrupt();

to:

    conn.getInputStream().close();

or if conn is an instance of HttpURLConnection:

    conn.disconnect();



12  Games Center / Archived Projects / Re: Zapple! on: 2009-08-19 22:13:31
Nothing to stop someone to write a program to emulate  the users actions, the code is (well should be) obfuscated so it would have to either invovle un-obfuscating it or writing a program to read the visual state of the game and play it, which would be a lot of effort when it comes down to it.

If you're super paranoid, you'll also want to secure network communication between your applet and the score server.  Otherwise someone with a packet sniffer can just pick apart the packets for the high score submission.  At very least I'd use ssl for everything, since $$$ is involved.   Wink
13  Game Development / Newbie & Debugging Questions / Re: how to do left 4k dead visual effect on: 2009-08-17 22:14:00
I project lines from the center of the screen to each pixel along the border, stepping one pixel at a time starting from the center. Whenever a "blocking" map pixel is found, I stop tracing that line. All other pixels get marked as lit.
A dot product check skips all lines outside the flashlight view, and a simple ramp function dims the light at the sides.

Is that this chunk?
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
                            int j = 0;
                            for (; j < dist; j++)
                            {
                                int xx = xt * j / 120 + 120;
                                int yy = yt * j / 120 + 120;
                                int xm = xx + xCam - 120;
                                int ym = yy + yCam - 120;

                                if (map[(xm + ym * 1024) & (1024 * 1024 - 1)] == 0xffffff) break;

                                int xd = (xx - 120) * 256 / 120;
                                int yd = (yy - 120) * 256 / 120;

                                int ddd = (xd * xd + yd * yd) / 256;
                                int br = brightness[ddd] * brr / 255;

                                if (ddd < 16)
                                {
                                    int tmp = 128 * (16 - ddd) / 16;
                                    br = br + tmp * (255 - br) / 255;
                                }

                                lightmap[xx + yy * 240] = br;
                            }


Whew.  That source is some seriously dense old-school coding.  You packed every bit of code you could into that 4K.... you da man....   Cool
14  Games Center / Archived Projects / Re: Zapple! on: 2009-08-17 20:18:11
IANAL, but you should be good in most of the US, as long as you don't require the player to provide anything of value to enter.  If they have pay for the game, give food to your favorite charity, whatever.... then they are paying for the chance to win, and that puts it under the gambling laws.
15  Game Development / Newbie & Debugging Questions / Re: How can I practice my Java skills? on: 2009-08-17 19:29:11
I was just trying to convey that biting off the scope of a typical A-list game is unwise for most indie developers.   I have no problem reducing my estimate of 500 man-years of work to match your estimate of 100 man-years of work.    Roll Eyes

16  Game Development / Newbie & Debugging Questions / Re: How can I practice my Java skills? on: 2009-08-17 18:10:11
I dont have any basic projects im willing to practice or work on, most of the projects I try to do end up being too hard and I can never finish them...

Man, I think most of us here have fought with this.  Here is my advice:

  • Leverage a framework.  kevglass (Slick2D) and others here have already tackled the tough problems that will knock the wind out of you. They open-sourced their stuff, so until you build up a codebase of your own, I suggest you drive it like you stole it.
  • Pretend it's your job.  At work you can't blow off your current task to do something more exciting, or you'll get fired.  At home, there is no one to force you to do all the crap work, so it is easy to get side-tracked on some nifty new idea.  This kills your forward momentum, avoid it at all costs, (or your fired!  Wink )
  • Put your ego on the back burner.  WoW took 100+ guys 5 years to finish.  Do the math, unless you have 500 years of free time to burn, you better get used to the idea of making a much smaller game.
  • If you still can't finish that smaller game, reduce scope until you can.  The only thing less fun than an unpolished game that is barely playable is an unfinished one that can't be played at all.

Good luck man, hit us up with questions if you get stuck.  Grin
17  Games Center / WIP games, tools & toy projects / Re: LWJGL water shader demo. on: 2009-08-14 16:14:30

Oops, I don't think it was happy with my desktop setup, it ran in the lower left corner of a frame that spanned both my monitors.  I assume your demo was dedicated fullscreen?  If anyone else runs a nvidia card dual screen on linux, I'd love to know how did you set up you X11 conf file...

Nice effect man, looks really good.
18  Java Game APIs & Engines / Tools Discussion / Re: which compiler (/IDE)? on: 2009-08-14 15:42:54
I personally use (and love) the IntelliJ IDE, but it is rather expensive if you are paying for it out of your own pocket.  I only know a handful of professional developers that don't use some IDE for editing their java files.

If the IDE feels like overkill for you, you can go with a smarter text editor.  JL235 mentioned SciTE for a text editor, Notepad+ comes to mind as well.  These both do code highlighting, folding, and auto-completion.  If you go this route, you should definitely look at using a build tool to compile and package your code, javac and jar are pretty miserable from the command line.  Ant and Maven are your two typical options.  Ant is a straight forward, "tell it what you want it to do" system.  Maven is a pain in the ass to figure out, but is a godsend on a huge project.




19  Java Game APIs & Engines / JOGL Development / Re: Problem with the glRotate!! on: 2009-08-13 23:58:45

Try changing your init code to the following to get a circle, rather than a ellipse.
1  
2  
3  
4  
        gl.glViewport(0, 0, 640, 480); //viewport typically matches size of screen/canvas
       gl.glMatrixMode(GL.GL_PROJECTION);
        gl.glLoadIdentity();
        glu.gluOrtho2D(-320, 320, -240, 240); //some multiple of screen/viewport dimensions to preserve aspect ratio and prevent squashing


The viewport defines the device coordinates, usually this is set for you, and matches the size of your canvas or the display resolution if you're fullscreen.
The gluOrtho2D call defines the rectangle in world coordinates that you are trying to display.

Also, this stuff is usually done in the reshape() call, so that if the user resizes the frame, there is no weird stretching...

Good luck!   Grin
20  Java Game APIs & Engines / JOGL Development / Re: Problem with the glRotate!! on: 2009-08-13 21:50:20

1  
2  
3  
4  
5  
6  
7  
        // x = radius * (cosine of angle)
       // y = radius * (sine of angle)
       for (double a=0; a<THREE_SIXTY; a+=ONE_DEGREE) {
            x = radius * (Math.sin(a));
            y = radius * (Math.cos(a));
            gl.glVertex2d(x, y);
        }


Uh... doesn't this mean your vertices are a circle, in the xy plane, centered at x=0, y=0, z=0?  Shading this a solid color and rotating it about the z-axis is always gonna look the same.  Try a different shape or add a texture.
21  Games Center / WIP games, tools & toy projects / Re: Quick 'n Dirty Verlet Fluids v0.1 on: 2009-08-11 16:38:08

About 40 - 45fps
CPU% = ~ 120%  (linux style, looks like about 60% per core)

Linux CentOS 5.1
Intel(R) Core(TM)2 Duo CPU     E6550  @ 2.33GHz
NVIDIA GeForce 7600 GS
Java(TM) SE Runtime Environment (build 1.6.0_12-b04)
Java HotSpot(TM) 64-Bit Server VM (build 11.2-b01, mixed mode)
22  Game Development / Performance Tuning / Re: Whats the ideal way to rewrite my game? on: 2009-08-11 16:22:43
It's also included in recent SDKs under the name jvisualvm. I see JL235 already mentioned it under that name.

Why yes it is, proof I spend too much time on trailing edge VMs at work.  It also looks much more feature rich than I remember it...  Grin
23  Game Development / Performance Tuning / Re: Whats the ideal way to rewrite my game? on: 2009-08-10 23:12:27

"Not smooth" is usually a sign of some "bursty" behavior that stalls out your game loop by forcing an iteration to run over the allotted (or reasonable) time.  For example, if you have set you game loop up to execute one fixed game step every 20 milliseconds, for a target of 50fps, then any step that runs longer than 20 milliseconds is going to feel like a stutter.  Loading images from disk disk would do it, so would a big garbage collection pause.  Switching to a time-derived step (passing an elapsed time variable) can help with this, but can be a major overhaul if you have a lot code that assumes a fixed step, and it won't help you if your  pause is a *really* big one.

I suggest:
1) Run your code through a profiler.  The netbeans one is free.  http://profiler.netbeans.org/ 
2)  Add timing calls to your main loop to capture avg, max time elapsed per loop
3)  Reduce your target framecount.  100+ fps is great for shooters, but only gives you a budget of 10 millis per frame.  25fps is a lot more forgiving.
4)  Move any heavy lifting (image IO) to a background thread.
5)  Force a low-pause garbage collector, (such as +Xincgc)
6)  If all else fails, switch your code over to a time step / as fast as possible method.  I think the Filthy Rich Clients book had some useful code, in chapter 12 - 15, http://filthyrichclients.org/






24  Game Development / Networking & Multiplayer / Re: Preventing cheating in network games written in Java on: 2009-08-10 22:14:18

Things that uh... my doppelganger persecutioncomplex has done in the past....
1)  hexedit save game files
2)  decompile source code
3)  Sniff / spoof network traffic
4)  Run code on a hacked VM

Things that slowed "him" down
A)  No save games to poke at, everything on the server
B)  network protocol had a rolling checksum, preventing external packet injection
C)  network protocol was stingy exposing state
D)  Kill-cam or game replay exposed dirty tricks
E)  Penalty for getting caught was my account banned
F)  Obfuscated client-side code
G)  Important stuff (to hit %, damage inflicted) is arbitrated at the server or another client
H)  Code was completely inaccessible (PS3, DS)
I)  A legitimate mod framework existed
J)  Hacked /file/game/protocol didn't yield any advantage


Some people will cheat at *anything* if they think there is an upside, and they can get away with it.  For the record, I think this includes DiabloII, monopoly, hide and seek, jury duty, and dating more than one individual at a time.  Grin
25  Game Development / Newbie & Debugging Questions / Re: proteced access on: 2009-07-31 19:22:45

Consider:

1  
a.removeAll(a.subList(start,end));



This only works if the the objects stored implement equals(), and is pretty inefficient since it iterates over the lists doing equality checks.  subList() is required to return a mutable list backed by the parent, so changes there affect the original.  This should be much faster.

1  
a.subList(start,end).clear();


Actually, looking at the source, a.subList(start,end).clear() just calls a.removeRange(start,end),  hahahaha....

Grin



26  Discussions / General Discussions / Re: How do I debug this serialization problem? on: 2009-07-31 16:58:27

Let's just say that because I know what my object graph actually looks like, it ain't very deep Smiley It's basically a few objects deep at most.

When I hit stuff like this, it's usually because I think my object graph isn't very deep.  Keep an eye out for sneaky references:

  • Non-transient references to service libraries, or any object that can reach one.  Holding a reference to a thread pool, or a sound clip that references the audio engine will serialize a lot more than you expected.
  • Anonymous and non-static inner classes.  These babies hold hidden references to the parent instance, which may not have been what you wanted.
  • Collections, especially caches and ring buffers.  If you forget to remove an object from a map or list when your done with it, you'll still serialize it if you serialize the collection.

I like pjt33's idea of getting into the debugger.  If your object graph is too large to browse, you can also try overridding ObjectOutputStream or using an alternate serialization mechanism like XStream, http://xstream.codehaus.org/ to debug what is making it to the stream before everything goes pear shaped.  You might find some surprises there.


Good luck, you poor bastard.    Tongue
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

Riven (12 views)
2014-07-29 18:09:19

Riven (10 views)
2014-07-29 18:08:52

Dwinin (9 views)
2014-07-29 10:59:34

E.R. Fleming (26 views)
2014-07-29 03:07:13

E.R. Fleming (10 views)
2014-07-29 03:06:25

pw (40 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (27 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!