Code Review

Anything libgdx related goes here!

Code Review

Postby Dubforce » Wed Oct 14, 2015 4:04 pm

Hey, guys. I'm working on a game using LibGDX, Box2D, Ashley, and Box2dLights. I was hoping to get a quick code review from some of you to make sure I am on track to have clean code at the end. I assume there are some things I am doing wrong/bad and I want to correct them as early as possible. I could also use some advice about how to tie in collision handling.

If you are interested in helping me out, here is a link to the github repo:
https://github.com/ttracey93/TotalDefense/
Dubforce
 
Posts: 7
Joined: Thu Jan 15, 2015 7:40 pm

Re: Code Review

Postby PtK » Fri Oct 16, 2015 4:28 pm

Hey,

I noticed just some small (or even very small) things. In general I think your code is very clean.

First, you seldom use the final keyword.
(Maybe have a look at http://stackoverflow.com/questions/137868/using-final-modifier-whenever-applicable-in-java).)

For example in CollisionListener.java both field could be made final.

Second, I think there are too many purly static classes. I know, at least for the Assets class it is very convenient. Maybe Triggers.java could be a singleton instead of a purly static class.

Third, If you target Android, I think it makes sense to use the libGDX collection classes (e.g. ObjectMap instead of HashMap and Array instead of ArrayList) to avoid unnecessary allocations. Maybe have a look at https://github.com/libgdx/libgdx/wiki/Contributing#performance-considerations.

I hope I could help at least a bit.
PtK
 
Posts: 3
Joined: Fri Oct 16, 2015 3:45 pm

Re: Code Review

Postby TomGrill » Fri Oct 16, 2015 6:33 pm

Pretty solid I think besides:

https://github.com/ttracey93/TotalDefen ... tener.java
Line 23:

for iteration:

You may want to replace all
Code: Select all
for-each (for( : ))
loops with for(int i = 0; i < list.size(); i++) because
Code: Select all
for-each (for( : ))
can create garbage which needs to be removed by the GC later on sometime.
Acorn Tilewalker iOS & Android: tomgrillgames.com
@TomGrillGames
TomGrill
 
Posts: 532
Joined: Tue May 06, 2014 8:05 pm

Re: Code Review

Postby Dubforce » Fri Oct 16, 2015 8:49 pm

Hey, guys, thanks a ton. Especially PtK. I appreciate the links and will peruse when I get a chance.
Dubforce
 
Posts: 7
Joined: Thu Jan 15, 2015 7:40 pm


Return to Libgdx

Who is online

Users browsing this forum: MSN [Bot] and 1 guest