Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (575)
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 / Game Play & Game Design / Re: A question out of curiousity on: 2008-12-24 00:26:55
Youre right.

If I remember, its KDE wich fires these KeyPressed/KeyReleased event for autorepeat.
You can use something like this to know how long a key has been hold down :
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
protected long leftKeyTimer = 0;
protected long leftKeyFinalTimer = 0;

// On Key Press Event:
if (leftKeyTimer == 0) {
    leftKeyTimer = System.currentTimeMillis();
}
// On Key Release Event:
leftKeyFinalTimer += (System.currentTimeMillis() - leftKeyTimer);
leftKeyTimer = 0;

// When you update your game logics:
if (leftKeyTimer != 0) {
    leftKeyFinalTimer += (System.currentTimeMillis() - leftKeyTimer);
    leftKeyTimer = System.currentTimeMillis();
}
long leftTime = leftKeyFinalTimer;
leftKeyFinalTimer  =0;
// use leftTime here


The thing is you cant rely on key release event to know when a key has been really released. If it has not been really released, a keyPress event is fired right after the KeyRelease one.
So you might also try to wait sonething like 10ms (you should check how really close in time these 2 events are fired) when you receive a keyRelease event before processing it and cancel it if a keyPress event is received during this time.

Regards,

Charly

2  Game Development / Performance Tuning / Loss of precision or just not VSynched? on: 2008-12-23 16:37:16
Hi,

My game handle his own backBuffer covering a whole gameArea, bigger than the screen. Differents cameras holds a Poition in the game's coordinates, a position on the screen and Dimension.

The gameArea is horizontally infinite, thats means when you reach right edge, you reappear on the left one. Its true for camera also, so when a camera cover an area that go farther than the right edge, its splitted in two. A method "Map<Rectangle2D, Rectangle2D> getGameAndScreenBounds()" returns mappings between rectangle2Ds representing the covered ingame area, entirely contained on the BackBuffer, and rectangle2Ds representing the screen's area on wich to draw the former one.

On the rendering loop, for each ingame rectanlges of each Camera, i clear the backBuffer with black and i draw sprites contained in the area.
Then, i draw the backBuffer on the screen by clipping the BufferStrategy's graphics2D to the camera's screen Rectangle2D and setting an AffineTransform to translate the buffer so the right game area is drawed.

This works well, but somthimes on the right edge of the camera's screen rectangle, ive got a 1-pixel wide vertical bar of white pixels (not covering the entire hieght of the rect). As i can switch to fullscreen (it seems it doesn't work for me, vm crash, bug  reported), and  i don't have vsync in windowed mode, i wonder if thats might be due to not vsyncing or more likely by a loss of precision?

All my Rectanlge2D use double value. I cast them to int using Math.floor and Math.ceil to be sure each pixel that might be visible is cleared. All my drawImage() calls use AffineTransforms. Clipping is set with setClip(Rectangle2D rect);

A screenshot showing the problem : http://imagebin.ca/view/E9gQNHxa.html
The screen is filled with red before copying the backBuffer for each camera.
Notice the white line in the lower right corner.

Thanks,

Charly
3  Game Development / Performance Tuning / Re: Accelerated Image with Transparency.BITMASK on Linux on: 2008-12-23 16:06:03
If the image transform operation is hw accelerated (which it is with the opengl or d3d pipelines), image rotation is basically free as it's a simple texture mapping operation.
Thanks, rendering is effectively as fast as light doing the rotation each frame, and the code is really clearer.
I use opengl pipeline so it should work on all platform.

Quote
It's unfortunate that our hw-acceleration story is so complicated. =(
In fact it makes sense once you think about it. One should just know how rendering is done in all case. Your answers and this article (http://today.java.net/pub/a/today/2004/11/12/graphics2d.html) might help.

Regards,

Charly
4  Game Development / Performance Tuning / Re: Accelerated Image with Transparency.BITMASK on Linux on: 2008-12-20 15:52:58
I hate to say it, but you'll be much more productive if you use Slick.

It 'just works'. Something that cannot be said for the Java2D pipeline.

Yeah, Slick seems really good... But I'd really like to know the java capabilities (lwjgl uses opengl directly, im I wrong?), so Ill continue using only sun's java libs for now. Anyway, as i designed things, it really shouldn't be hard to switch to Slick, just a matter of implementing a couple of interfaces.

And regarding productivity, im somewhat satisfied. Things are going forward. Im just making sure everything works fine before adding more contents and logic.
5  Game Development / Performance Tuning / Re: Accelerated Image with Transparency.BITMASK on Linux on: 2008-12-20 13:30:07
Typically you'd use VolatileImage as a backbuffer, because rendering _to_ such image can be accelerated (as well as _from_). And you'd use BufferedImage for sprites and other things that don't get changed often, since rendering _from_ such image can be accelerated (once it gets cached in video memory).
Youre right, using transparency on my buffer is useless. But regarding my sprites that need to be rotated, i think i need both of them: a BufferedImage holding the sprite image,  the one loaded from file; and a VolatileImage holding the real image that is copied to my buffer. When the sprite's angle has changed, i clear the volatile and copy the Buffered applying the rotation.
Or is it better to just keep the Buffered one and apply the rotation when copying it to the buffer? I thought rotation was an heavy operation and i could skip if if uneeded by holding a copy of the rotated sprite.

So, to summary all this up ; correct me if Im wrong :
- Drawing TO and FROM VolatileImage is accelerated.
- Drawing FROM BufferedImage is accelerated once it has been cached in VideoMemory (thats automatically done when image is copied several times)
- BITMASK Volatile images aren't accelerated in 1.5 or 1.6.
- TRANSLUCENT Volatile images are accelerated on Windows or, using OpenGL pipeline, all platforms.
- OPAQUE Volatile images have the most chances of being accelerated across platforms and jdk versions.

Thanks,

Charly
6  Game Development / Performance Tuning / Re: Accelerated Image with Transparency.BITMASK on Linux on: 2008-12-18 18:33:09
Thanks for reply. I was using VolatileImage because i found on the blog of one java graphic developper that they are good for managing acceleration. In addition, i tested accelerated TRANSLUCENT BufferedImage and VolatileImage ; only the last one gets accelerated.

I use 1 big volatile image as a backBuffer in addition of a buffer strategy. The buffer strategy holds the screen buffer, while my own buffer holds the whole game area. different cameras can point to different parts of the game area and render them on screen at the same time, so i draw needed sprites on my back buffer and draw part of it to the strategy. I use this to avoid drawing the same sprite more than one time when more than one camera sees it.

Anyway, thanks for reply, accelerated TRANSLUCENT VolatileImage works fine using the opengl pipeline. Can you provide a reliable source for this information? I guess ive skipped this during my searches...

Regards,

Charly

7  Game Development / Performance Tuning / Accelerated Image with Transparency.BITMASK on Linux on: 2008-12-17 22:56:42
Hi all,

Im trying to use accelerated graphics for my game. I just discovered my VolatileImage were not accelerated. From [1], in the 1.5 API, only OPAQUE images were accelerated. I can't find any info regarding this with the 1.6 API. Somwhere on your forum, i see that only BufferedImage can be accelerated with transparency, but my code below shows that my BufferImage are never accelerated. My question is simple : how do i get an accelerated transparent image with Transparency.BITMASK on Linux (and, hopefully, all platforms)?

The code below is a small test i wrote while trying to figure out how to do 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  
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  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package abricots.test;

import java.awt.AWTException;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.ImageCapabilities;
import java.awt.Transparency;
import java.awt.image.VolatileImage;

/**
 *
 * @author cghislai
 */

public class testAccel {

    public testAccel() {
        GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.
                getLocalGraphicsEnvironment();
        for (GraphicsDevice graphicsDevice : graphicsEnvironment.
                getScreenDevices()) {
            System.out.println("DEVICES : " + graphicsDevice.getIDstring());
            System.out.println("   - MEM :" + graphicsDevice.
                    getAvailableAcceleratedMemory());
            System.out.println("   - DISPLAYCHANGE : " + graphicsDevice.
                    isDisplayChangeSupported());
            System.out.println("   - FULLSCREEN : " + graphicsDevice.
                    isFullScreenSupported());
        }
        GraphicsDevice graphicsDevice = graphicsEnvironment.
                getDefaultScreenDevice();
        GraphicsConfiguration graphicsConfiguration = null;
        for (GraphicsConfiguration gc : graphicsDevice.getConfigurations()) {
            System.out.println("CONFIGURATION : " + gc.toString());
            System.out.println("   - BOUNDS :" + gc.getBounds().
                    getWidth() + " x " + gc.getBounds().
                    getHeight());
            System.out.println("   - BUFFER : FullScreenRequired:" + gc.
                    getBufferCapabilities().isFullScreenRequired());
            System.out.println("   - BUFFER : Multi:" + gc.getBufferCapabilities().
                    isMultiBufferAvailable());
            System.out.println("   - BUFFER : PageFlipping:" + gc.
                    getBufferCapabilities().isPageFlipping());
            System.out.println("   - BUFFER : BackBuffer Accelerated:" + gc.
                    getBufferCapabilities().getBackBufferCapabilities().
                    isAccelerated());
            System.out.println("   - BUFFER : FrontBuffer Accelerated:" + gc.
                    getBufferCapabilities().getFrontBufferCapabilities().
                    isAccelerated());

            System.out.println("   - IMAGE :  Accelerated:" + gc.
                    getImageCapabilities().isAccelerated());
            System.out.println("   - COLOR MODEL : " + gc.getColorModel().
                    toString());


            if (gc.getBufferCapabilities().isPageFlipping() &&
                    gc.getBufferCapabilities().
                    getBackBufferCapabilities().isAccelerated() &&
                    gc.getBufferCapabilities().
                    getFrontBufferCapabilities().isAccelerated() &&
                    gc.getImageCapabilities().isAccelerated() &&
                    gc.getColorModel(Transparency.BITMASK) != null) {
                graphicsConfiguration = gc;
                break;
            }
        }

        VolatileImage im = graphicsConfiguration.createCompatibleVolatileImage(
                20, 20);
        System.out.println("VImage accelerated :" + im.getCapabilities().
                isAccelerated());
        im = graphicsConfiguration.createCompatibleVolatileImage(
                20, 20, Transparency.BITMASK);
        System.out.println("tr VImage accelerated :" + im.getCapabilities().
                isAccelerated());
        ImageCapabilities caps = new ImageCapabilities(true);
        try {
            im = graphicsConfiguration.createCompatibleVolatileImage(20, 20,
                                                                     caps,
                                                                     Transparency.BITMASK);
        } catch (AWTException ex) {
            System.out.println("Cant create accel VImage");
        }

        BufferedImage bim = graphicsConfiguration.createCompatibleImage(
                20, 20);
        System.out.println("BImage accelerated :" + bim.getCapabilities(graphicsConfiguration).
                isAccelerated());
        bim = graphicsConfiguration.createCompatibleImage(
                20, 20, Transparency.BITMASK);
        System.out.println("tr BImage accelerated :" + bim.getCapabilities(graphicsConfiguration).
                isAccelerated());

    }
}


Thanks,

Charly


[1] http://java.sun.com/j2se/1.5.0/docs/guide/2d/new_features.html
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.

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

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

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

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

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

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

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

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

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

BurntPizza (74 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!