Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Tutorial Time + Sources  (Read 9465 times)
0 Members and 1 Guest are viewing this topic.
Offline ahristov

Senior Devvie


Projects: 7


Java games rock!


« Posted 2007-04-11 08:30:53 »

Besides dumping a load of 4k source code, I decided also to explain some of the algorithms and effects I used in my games, in the hope that they would be useful, together with a set of tips I learned during the coding. The full list of java 4k tips and tutorials

And the full source code of my six games can be found here. It includes a template you might want to use for your games.

I plan to add there some games that I didn't have the time to finish.

Planetalia S.L. Cursos de Java
Offline OverKill

Junior Devvie




Java games rock!


« Reply #1 - Posted 2007-04-11 10:54:51 »

Very nice. Thanks for sharing.

Some additions to the optimisations stuff I have done:
if you group constant values together the compiler will optimise them before.
Say you have 200 - X + 5 (bad example I know, but used to showcase what I mean)
If you reorder the constants to group them together the compiler will do the math during compile time and thus reduce calculations and thus size. so 200 - X + 5 could be 200 + 5 - X and the compiler would turn it into 205 - X.

Another thing I used to do in my mobile game programming days was to take the compiled code and decompile it and look what the compiler did to it. Sometimes I would see the compiler do stuff that I had presumed would turn out differently. Especially when trying to optimise the code by hand.
Offline ahristov

Senior Devvie


Projects: 7


Java games rock!


« Reply #2 - Posted 2007-04-11 12:11:37 »

Another thing I used to do in my mobile game programming days was to take the compiled code and decompile it and look what the compiler did to it. Sometimes I would see the compiler do stuff that I had presumed would turn out differently. Especially when trying to optimise the code by hand.

That's true when programming for J2ME, where you have very tight runtime memory constraints. But in Java4K, your #1 aim is not to optimize the bytecode, but the size of the compressed jar. It is actually better to generate more redundant and repetitive code. Given a task X to code, the program that results in the smallest class size is not necessarily the program that results in the smallest archive.

Planetalia S.L. Cursos de Java
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline OverKill

Junior Devvie




Java games rock!


« Reply #3 - Posted 2007-04-11 13:32:48 »

True, but partially people would do stuff that actually created larger code.
F.i. (I> 2 ? 3 : 4) was actually a couple of bytes larger then an if/else structure. It looks smaller but it was not.
(dunno about >= jdk1.5 as we could only use 1.4)

There was also a problem when people would access fields from inside a thread, causing the compiler to create access methods.
(remembering all this out of memory, could be that the fields were private and that was what caused the added code)

Another thing you can do is when you have large data arrays, to load them from a file during runtime. You could pack the data better this way.
Also remove file extensions (at least it works on mobile) and subdirs.
If you are really going for gold, dump all data into a file and also load them during runtime. Also packs better.

Dumb question: Were you allowed to use an obfuscator?

Edit:
Have you tried removing/changing the field visibilities? IIRC that can help a little as well.
Edit2:
K looked into your code for the Abducer 4K and you had already stripped it down very well.
You can replace 2* and similar code segments with binary shifts, saves about 2 bytes per. Though I found it only effects segments where additional calculations are done.
example:
2*kernelSize > kernelSize<<1 = no effect
2*kernelSize-2 > kernelSize<<1-2 = 2 bytes
Not much but sometimes every little bit helps Wink
Offline Morre

JGO Knight


Medals: 2
Projects: 10


I'm Dragonene on IRC.


« Reply #4 - Posted 2007-04-11 14:32:09 »

ahristov: on a completely unrelated note - if you want me to, I will include your games in my unofficial feedback (since I am under the impression a lack of feedback is one of the reasons you withdrew your games from the contest). Please respond in a PM or in this thread, and keep those webstart links alive Smiley

Offline ahristov

Senior Devvie


Projects: 7


Java games rock!


« Reply #5 - Posted 2007-04-11 15:25:54 »

ahristov: on a completely unrelated note - if you want me to, I will include your games in my unofficial feedback (since I am under the impression a lack of feedback is one of the reasons you withdrew your games from the contest). Please respond in a PM or in this thread, and keep those webstart links alive Smiley
My decision to withdraw has nothing to do with that. It was because of the combination of insults+censorship by the organizer.
But of course, any feedback is very welcome  Wink

Planetalia S.L. Cursos de Java
Offline darkprophet

Senior Devvie




Go Go Gadget Arms


« Reply #6 - Posted 2007-04-12 12:02:07 »

just for interest sake:

200 - X + 5 does not equal 200 + 5 - X

200 - X + 5 equals 200 - (X + 5)

The order of the operations matters...remember BODMAS at all times Smiley

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Offline ahristov

Senior Devvie


Projects: 7


Java games rock!


« Reply #7 - Posted 2007-04-12 12:15:08 »


200 - X + 5 does not equal 200 + 5 - X
200 - X + 5 equals 200 - (X + 5)


You are joking, aren't you?  Roll Eyes

Planetalia S.L. Cursos de Java
Offline OverKill

Junior Devvie




Java games rock!


« Reply #8 - Posted 2007-04-12 12:58:28 »

just for interest sake:

200 - X + 5 does not equal 200 + 5 - X

200 - X + 5 equals 200 - (X + 5)

The order of the operations matters...remember BODMAS at all times Smiley
You totally missed what I was trying to say.
The idea was to group together constant values so that the compiler would eliminate them during compile time.

The example given (which I said was bad!) was just to make clear the intentions.
Not for others to copy. Next people will complain that pseudo-code does not compile.
Offline Mr_Light

Senior Devvie


Medals: 1


shiny.


« Reply #9 - Posted 2007-04-12 14:11:37 »

just for interest sake:

200 - X + 5 does not equal 200 + 5 - X

200 - X + 5 equals 200 - (X + 5)

The order of the operations matters...remember BODMAS at all times Smiley
200 - X + 5 subtraction is not associative, (200-x)+5 addition is 5+(200-x) addition is also commutative 200+5 -X yields 205 - X ?

200 - (X+5) for (X = 1) 200 - 6 = 194
200 - X + 5 for (X = 1) 199 + 5 = 204
205 - 1 = 204

ok so I'm poor at explaining this... oh well if you don't believe me trust your JVM:

1  
2  
3  
4  
5  
6  
7  
8  
public class MathProgram {
  public static void main(String[] args) {
    int x = 1;
    System.out.println(200 - x + 5);
    System.out.println(200 - (x + 5));
    System.out.println(205 - x);
  }
}

Quote
204
194
204

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline drslinky1500

Senior Newbie





« Reply #10 - Posted 2007-04-13 20:19:45 »

Quote
public class MathProgram {
  public static void main(String[] args) {
    int x = 1;
    System.out.println(200 - x + 5);
    System.out.println(200 - (x + 5));
    System.out.println(205 - x);
  }
}

Your addition of parenthesis changes the problem completely because you are changing a negative x to a positive x.

200 - (x+ 5)
should read
200 + (-x + 5)
and can read
200 + 5 - x
because x is still negative

What you are actually doing is this.
200 + (-x) + 5

This is why you are getting different values. This is a common mistake. If you change the order of things, do not change a positive to a negative or visa versa.
Offline Mr_Light

Senior Devvie


Medals: 1


shiny.


« Reply #11 - Posted 2007-04-13 22:41:48 »

why does it sound like your explaining me that? Dark prophet is the one who introduced them  Huh

i know the program yields differend results, and I expected it too.

it's there to illustrate/proof that "200 - X + 5 equals 200 - (X + 5)" is false.

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline drslinky1500

Senior Newbie





« Reply #12 - Posted 2007-04-14 20:36:49 »

Quote
i know the program yields differend results, and I expected it too.

I know. I probably just got in a hurry and made it sound wrong.

Quote
ok so I'm poor at explaining this... oh well if you don't believe me trust your JVM:

The point of my post was to break down the explanation a little simpler than you had already done.
Offline Mr_Light

Senior Devvie


Medals: 1


shiny.


« Reply #13 - Posted 2007-04-15 11:59:51 »

yeah, sorry I'm afraid you just hit a sore spot. my bad.

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline malberts

Junior Devvie





« Reply #14 - Posted 2007-04-17 20:52:28 »

Is Java's HSB system correct? As far as I know, and I've tested it on Paintshop Pro and FreeHand, a Brightness of 100% should yield white and 0% black irrespective of the H and S values.

Basically I don't get white with 100% brightness, only the color on its brightest. At 0% I do get black but then using that grass/sand tile thing I get white specks at 0% brightness.

Anyone got an idea?

In space no-one can hear you System.out.println()
Offline ahristov

Senior Devvie


Projects: 7


Java games rock!


« Reply #15 - Posted 2007-04-17 21:41:19 »

Is Java's HSB system correct? As far as I know, and I've tested it on Paintshop Pro and FreeHand, a Brightness of 100% should yield white and 0% black irrespective of the H and S values.

Are you sure PSP uses HSB? My (very old) version uses HSL, which is not exactly the same. In HSL, 100% Luminance is white, but in HSB 100% Brightness is the specific colour at its brightest point. See here, for example.

Planetalia S.L. Cursos de Java
Offline malberts

Junior Devvie





« Reply #16 - Posted 2007-04-17 21:51:38 »

Ah, I see. Thanks. I thought they were the same.
PSP uses HSL as do FreeHand.

I'll have a look at Photoshop then.

In space no-one can hear you System.out.println()
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #17 - Posted 2007-04-18 02:26:17 »

Is Java's HSB system correct? As far as I know, and I've tested it on Paintshop Pro and FreeHand, a Brightness of 100% should yield white and 0% black irrespective of the H and S values.

Basically I don't get white with 100% brightness, only the color on its brightest. At 0% I do get black but then using that grass/sand tile thing I get white specks at 0% brightness.

Anyone got an idea?

The Gimp does it the same way Java does.  The saturation and the brightness control the colour.  I saturation is 0 with brightness to 100 then the colour is white.  As the saturation goes up the colour becomes fuller.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

Mr.CodeIt (10 views)
2014-12-23 03:34:11

rwatson462 (38 views)
2014-12-15 09:26:44

Mr.CodeIt (31 views)
2014-12-14 19:50:38

BurntPizza (62 views)
2014-12-09 22:41:13

BurntPizza (99 views)
2014-12-08 04:46:31

JscottyBieshaar (60 views)
2014-12-05 12:39:02

SHC (74 views)
2014-12-03 16:27:13

CopyableCougar4 (77 views)
2014-11-29 21:32:03

toopeicgaming1999 (138 views)
2014-11-26 15:22:04

toopeicgaming1999 (127 views)
2014-11-26 15:20:36
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
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!