Maescool / Catacomb-Snatch

Mojang's Humble bundle source
Other
295 stars 99 forks source link

Dev/abstract screen0.21 #935

Closed Shephiroth closed 12 years ago

Shephiroth commented 12 years ago

Here i am....again.

This time no formatting, sorry about that.

Im not sure how to configure netbeans to properly format code without screw it when commiting. Tried to set tabulations to 8 spaces, ide work properly and format using tabs, but then upload it using tab=space.

Shephiroth commented 12 years ago

Ok, i think you all expect me to comment this.

Actually, is a simple abstract layer. Tried to make it without a lot of changes.

The basic idea is that every "graphic system" need to create a pair of classes, AbstractScreen and AbstractBitmap. To avoid the problem of classes using AbstractBitmap about wich one to create, the actual AbstractScreen object will create it. That way, MojamScreen will create MojamBitmap, OpenglScreen will create OpenglBitmap and LwjglScreen will create LwjglBitmap....for examples.

Some classes (LevelButton, LevelEditorMenu, FontCharacterFactory & Level) needed to use MojamComponent.screen object to create their Bitmap. Im looking for a "cleaner" way to do it, since sending screen object to those methods is a bit intrusive for a first step. In some classes (Turret & Harvester) i created a boolean var instead of use MojamComponent.screen, and place the create bitmap code in another method where screen object is available (drawRadious). Also, moved all static Bitmap object to Art class, where now manually loaded by the programmer using Art.loadAllResources(AbstractScreen). This also rely on AbstractScreen.createBitmap to create the correct set of Bitmap.

Ill try to make a new set of subclasses, problably working with BufferedImages instead of pixels. My real goal is to get something more advance (lwjgl, as sugested for some ppl who point Slick2D).

Not sure if should push here some new code or wait until this code gets reviwed and merged or discarded.

Maescool commented 12 years ago

I just browsed through the code, looks pretty neat! sorry if i didn't look at it earlier. I really appreciate these changes! i assume this code is tested? Love the idea to make it easier to implement lwgl or slick, will give extra graphic features for example people were asking for shading rooms where you would need torches etc..

I'll let the other review it first before i merge, i hope you understand. anyway, thanks! love how people do such lovely commits to this project :) To the others: small commits are as much apreciated, but these kinds of commits have taken a lot of work, and i respect it!

Shephiroth commented 12 years ago

Well, i tested SP and it work properly. MP should work as well. Download & Menu screen works. Levels load ok and game works. I checked fps with & without changes, both works for me at 28-29fps.

This isnt as big as you might think (refactor option is usefull) but i appreciate it :) Soldiers request is a really big one, i should check it soon.

Maescool commented 12 years ago

@Shephiroth breaks download screen for some reason.. i had to disable 1 of the font renderings.. can you look into it?

Shephiroth commented 12 years ago

pulling and pushing to my local repo, checking it.

Shephiroth commented 12 years ago

There is no error (or maybe is commented). More info will be welcome :)

// DownloadScreen.drawGraph(fileSize/2, fileSize); (ChannelDownloader.java) this?

Maescool commented 12 years ago

@Shephiroth //Font.FONT_BLUE.draw(screen, fileName, 210, 180); in DownloadScreen.java :) it also does it with defaultfont() guess it doesn't take the fileName string correct for some reason..

Shephiroth commented 12 years ago

Ok, found the problem. You are going to laugh, the problem is is MojamStartup :D.

Will pull request soon.

Maescool commented 12 years ago

verry strange.. cause the word "downloading.." is not giving issues.. and that is being loaded before the filename thingie.; or maybe i'm just plain stupid xD

Shephiroth commented 12 years ago

Ok, the code in question is this one:

screen.blit(Art.downloadScreen, 0, 0); super.render(screen); if (downloading) { screen.alphaFill(125, 150, 300, 100, 0xff000000, 0x90); Font.defaultFont().draw(screen, MojamComponent.texts.getStatic("download.downloading"), 215, 170); //Font.FONT_BLUE.draw(screen, fileName, 210, 180);

The download text comes from Art, wich is ok because in MojamStartup.constructor we called MojamScreen.screen.loadResources(). The font create AbstractBitmap using static MojamComponent.screen. But as DownloadScreen come from MojamStartup (before MojamComponent is created) MojamComponent.screen member is not set, and we get a NullPointerException.

Already make a request, modifying only MojamStartup, setting MojamComponent.screen and avoiding NullPointerException. More info in the request (sorry, dont know know to point it, still new around here :D)