Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (416)
games submitted by our members
Games in WIP (307)
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  Java Game APIs & Engines / Java 2D / Re: Avoidance of Garbage Collection on: 2005-03-01 19:10:17
Yeah, I went to useing a Graphics gotten from the BufferStrategy to render the image, I was a little dissapointed that they did not have the option to draw a single pixel, I decided to just use a fillRect(x, y, 1, 1); Worked at a good speed even at high resolutions like 1600 x 1200.  Although now that I am useing sprites, I am having trouble becasue it seems to take a really long time to draw a buffered image to a Graphics.  Is there any way to move the image into the memory on the graphics card so that it can access it quickly?
2  Java Game APIs & Engines / Java 2D / Re: Avoidance of Garbage Collection on: 2005-02-28 03:58:44
Another thing I was wondering was weather the use of something like a blocking queue to manage FPS is a good idea.

[CODE]
int fps = 30;

LinkedBlockingQueue<Thread> bq = new LinkedBlockingQueue<Thread>(1);

while(!exit)
{
   bq.put(new Thread(updater));
   bq.peek().start();
   Thread.sleep(1000/fps);
}
[/CODE]

Then have the updater somehow remove it'self from the LinkedBlockingQueue.  It prevents more than one updater from running at the same time, but also makes the wait continue while the thread is running.
3  Java Game APIs & Engines / Java 2D / Avoidance of Garbage Collection on: 2005-02-28 03:44:26
Is it a good idea to avoid creating a new BufferedImage every time an image is refreshed to avoid java garbage collection, and if so, is it a good idea to have a blank image or blank raster to reset the image to when you want to redraw it?  Is there a better way?  What I have is this.

[CODE]
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
/**
* @author Scott
*
*/
public class ScreenManager
{
   private BufferedImage bi;
   private Raster blank;
   
   private BufferStrategy bs;
   
   private int width;
   private int height;
   
   public ScreenManager(int width, int height)
   {
       JFrame screenFrame = new JFrame(String.format("%dx%d", width, height));
       screenFrame.setSize(width+6, height+24);
       screenFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       screenFrame.setResizable(false);
       screenFrame.setVisible(true);
       
       this.width = width;
       this.height = height;
       
       screenFrame.createBufferStrategy(2);
       
       bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
       blank = bi.getData();
       
       bs = screenFrame.getBufferStrategy();
       
   }
   
   public void drawPixel(int x, int y, Color c)
   {
       bi.setData(blank);
       //bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
       bi.setRGB(x,y,c.getRGB());
   }
   
   public void refresh()
   {
       render(bs.getDrawGraphics(), bi);
       bs.show();
   }
   
   public void render(Graphics g, Image i)
   {
       
       g.drawImage(i, 3, 21, null);
   }
}
[/CODE]

and

[CODE]
import java.awt.*;

/**
* @author Scott
*
*/
public class Main
{
   private int pixelX;
   private int pixelY;
   
   public static void main(String[] args)
   {
       ScreenManager sm = new ScreenManager(320, 240);
       
       for(int i = 0;i < 320; i++)
       {
           if(i == 319) i = 0;
           for(int j = 0;j < 240;j++)
           {
               if(j == 240) j = 0;
               sm.drawPixel(i, j, Color.WHITE);
               sm.refresh();
           }
       }
       
       sm.refresh();
   }
}
[/CODE]
Pages: [1]
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Try the Free Demo of Revenge of the Titans

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
mrbenebob (16 views)
2013-06-19 14:55:23

BrassApparatus (25 views)
2013-06-19 08:52:37

NegativeZero (28 views)
2013-06-19 03:31:52

NegativeZero (30 views)
2013-06-19 03:24:09

Jesse_Attard (34 views)
2013-06-18 22:03:02

HeroesGraveDev (71 views)
2013-06-15 23:35:23

Vermeer (70 views)
2013-06-14 20:08:06

davedes (72 views)
2013-06-14 16:03:55

alaslipknot (64 views)
2013-06-13 07:56:31

Roquen (88 views)
2013-06-12 04:12:32
Smoothing Algorithm Question
by UprightPath
2013-05-28 02:58:26

Smoothing Algorithm Question
by UprightPath
2013-05-28 02:57:33

Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38
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!