Whenever you are playing around with OpenGL and LWJGL in Java, say LibGDX, Slick2D or pure LWJGL, please keep this in mind: Java Garbage Collector is NOT your friend. There are a few reasons that make it suck for games. One of them is 'the moment' it chooses to start working. If Java garbage collector is messing around during our main loop, it may cause it to take longer to complete each cycle, causing our game to lose FPS.
There's another reason to hate Java garbage collector: it doesn't work with video RAM. Whenever you load a texture on LWJGL or any LWJGL-based library, actual image data is loaded as a pixmap on video RAM. OpenGL stores graphical data on video RAM so that your graphics card can access faster to it.
However, video RAM is not the VM heap. That means that Java Garbage Collector won't free your textures -you must do that manually, by using the appropiate method depending on the platform you are using, dispose() or destroy(). If you don't release your textures, you will end with memory leaks and your will require a lot of memory: this might not be a problem at all on desktop platforms, but if you are planning to release a mobile phone game, you should be aware of this.
Remember to destroy your textures once you aren't using them. Doing some image = null is not enough: as I said, that won't remove your pixmap data on video RAM. Plus, if you remove all the references to your texture, it's over: you won't be able to destroy the pixmap and that memory bank used by your pixmap becomes lost and wasted until you close the game.
Aside note: make sure to destroy textures that you aren't using. Sometimes pixmaps get shared across multiple texture or image objects. Consider the following example in Slick2D: you load an Image, then you create a SpriteSheet, and then you use an Image array to reference three sprites. You are using five objects here, your original image, your spritesheet and three references to some subimages of your original image. However, they all will be sharing the same pixmap on video RAM. If you destroy that pixmap, you destroy the pixmap for all of them. So, if you are using a spritesheet, a tileset, a bitmap/AngelCode font, be careful on deleting pixmaps.
Just a random blog where I put my thoughts as I'm trying to develop a computer game.
Showing posts with label LWJGL. Show all posts
Showing posts with label LWJGL. Show all posts
Sunday, March 31, 2013
Thursday, March 28, 2013
City Road Prototype
During this week I've been working on another game prototype in Slick2D. At the end of this post I will provide you download links to what I've done. Here's a little nice screenshot:
What you see here is called City Road Prototype.
This demo creates some green terrain (grass?). Player can draw streets by clicking and dragging the terrain, that will place road tiles. Game engine will automaticly make those road tiles look like streets and intersections if there are nearby road tiles.
There's also a car, that little red dot you see on the left. Game will randomly spawn a car if there's no one. Car IA is at the moment really dumb: they will only attempt to move forward; if the road ends, they will turn somewhere else to keep moving forward. It's dumb because sometimes they turn back doing a 180º turn, which is actually dangerous (at least in real life). Should check that so that they better turn left or right when possible.
Although I've been doing a lot of prototypes on the last months, this one is attracting me a lot. I usually let my prototypes rot as soon as they bore me. I just HOPE that this does not happens this time. Here is a download link to v0.0.1 (Zip, 3.4 MB). It's multiplatform and it has already been configured to work like a charm on any operating system out there so you should not have any issues. Just download and extract. If you are using Windows, double click the JAR file or run BAT file if you are having issues. Mac, Linux and Solaris users can run SH file.
I don't expect many people reading this blog post but if by some reason you read this and you decide to download my demo, please give me feedback about any issues you could have so that I can fix them on future alpha releases.
What you see here is called City Road Prototype.
This demo creates some green terrain (grass?). Player can draw streets by clicking and dragging the terrain, that will place road tiles. Game engine will automaticly make those road tiles look like streets and intersections if there are nearby road tiles.
There's also a car, that little red dot you see on the left. Game will randomly spawn a car if there's no one. Car IA is at the moment really dumb: they will only attempt to move forward; if the road ends, they will turn somewhere else to keep moving forward. It's dumb because sometimes they turn back doing a 180º turn, which is actually dangerous (at least in real life). Should check that so that they better turn left or right when possible.
Although I've been doing a lot of prototypes on the last months, this one is attracting me a lot. I usually let my prototypes rot as soon as they bore me. I just HOPE that this does not happens this time. Here is a download link to v0.0.1 (Zip, 3.4 MB). It's multiplatform and it has already been configured to work like a charm on any operating system out there so you should not have any issues. Just download and extract. If you are using Windows, double click the JAR file or run BAT file if you are having issues. Mac, Linux and Solaris users can run SH file.
I don't expect many people reading this blog post but if by some reason you read this and you decide to download my demo, please give me feedback about any issues you could have so that I can fix them on future alpha releases.
Subscribe to:
Posts (Atom)