Thursday, December 8, 2011

Cleaning up!

The codebase grows and grows, and something that was once a test how i could render sprites in Slick2D has outgrown the "proof of concept" state, and is on its best way to turn into something more gamelike
So instead of introducing new features it was time for a refactor.
Package names now have a naming convention, so do classes. A logger has been introduces instead of all those System.out.println() as well as a config file that handles settings without the need to recompile the code. A friend was a great help, mostly because he works in a more professional enviroment then me, as well as more experience.

Another think i found was a true "first" in the java programming language.
Destroying an object explizitly in Java.
Apparently when using the Image Object from the Slick2D api, when you create an Image with a content, and then overwrite then content, the old content aparently still takes up memory, so if you rerender an image multiple times, you have a memory leak.
I use quite a nasty method to create the red [ now white, at a later point in color of owner ] overview in the right  upper corner.

Code

I am aware that this code is very bad code, in the beginning this was meant to test the galaxy generation algorithm, so it just created a image of the galaxy. But using it as a real time overview is very unressourceful, so this will change :)

I hope i find a way to render this in a better way, probably rerendering the image every time a star is changed ( owner or existence ), would be quite ok, because this happens rarely. the border and the view finder [ see other images ] will be rendered in the renderer thread with Shapes.

I will also try to get the Imagebuffer local, put everything in one method.

Till then have fun, and please, if you want, leave questions, opinions, suggestions etc.

No comments:

Post a Comment