Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (426)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (466)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2
  ignore  |  Print  
  How about some help, guys?  (Read 5959 times)
0 Members and 1 Guest are viewing this topic.
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Posted 2005-12-07 22:36:08 »

http://wiki.java.net/bin/view/Games/4KGamesDesign

I've got a few thoughts down already. This document has a LOOOOOOOooooooooonnnnnnggg way to go, however. I think I could write a book about this subject. Smiley

Java Game Console Project
Last Journal Entry: 12/17/04
Offline kappa
« League of Dukes »

JGO Kernel


Medals: 70
Projects: 15


★★★★★


« Reply #1 - Posted 2005-12-07 23:05:23 »

heres some i've got

1) Avoid initiating variables (e.g. int, double, float, etc) if they are gonna be 0 any way, saves about 9 bytes
2) don't initiate boolean as its false by default, use that instead, saves about 9 bytes
3) avoid creating methods as they are expensive on the bytes, even if you need to repeat stuff (repatition is caught when jaring & zipping)
4) if you need to catch exceptions, don't do it in side the method as it takes up quiet a bit of space to add the try{}catch{} part, instead add throw Exception to the methods
1  
public static void main(String argv[]) throws Exception

5) also using a few old depreciated methods some times saves a bit of space too like for a JFrame instead of "setVisible(true);" you can use "show();"
6) where possible avoid double, instead try use int instead if thats not possible then go for float, however only sometimes float help other times it becomes more expensive as it requires more casting
7) same thing for long, try use int instead
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #2 - Posted 2005-12-07 23:13:25 »

Don't tell me, tell the Wiki! Wink

1) Avoid initiating variables (e.g. int, double, float, etc) if they are gonna be 0 any way, saves about 9 bytes.
2) don't initiate boolean as its false by default, use that instead, saves about 9 bytes

Neither of these work unless the variable is global or part of an array. The former shouldn't be used (third tip under "General Tips") and the latter is  obvious enough not to warrant a tip.

Quote
3) avoid creating methods as they are expensive on the bytes, even if you need to repeat stuff (repatition is caught when jaring & zipping)

That's the second tip under the "general tips" section. Smiley

Java Game Console Project
Last Journal Entry: 12/17/04
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline kappa
« League of Dukes »

JGO Kernel


Medals: 70
Projects: 15


★★★★★


« Reply #3 - Posted 2005-12-07 23:16:32 »

oh quick reply, sorry was still adding more to the reply above.

Don't tell me, tell the Wiki! Wink

ah sorry can't seem to be find the edit option Grin besides i don't wanna mess it up.
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #4 - Posted 2005-12-07 23:24:23 »

Updates! Cool beans. Smiley

Most of the updates would be good to add to the Wiki. It would be nice if you could demystify a few of them (e.g. The use of deprecated methods aren't what saves space, it's the length of the method signature), but don't worry about getting it perfect. Being a Wiki, anyone can come around and correct you at any time. Feel free to correct my stuff as well, in case you spot any mistakes.

Edit:
Quote
ah sorry can't seem to be find the edit option 
The Edit link is at the bottom of the article, to the left of the list of versions. However, I think you need to be logged in to see it.

Quote
besides i don't wanna mess it up.
It's a Wiki. What's to mess up? Easy to change, easy to fix. Wink (Though I do wish we had MediaWiki instead of the CollabNet stuff.)

Java Game Console Project
Last Journal Entry: 12/17/04
Offline Morre

JGO Knight


Medals: 2
Projects: 10


I'm Dragonene on IRC.


« Reply #5 - Posted 2005-12-07 23:47:18 »

Very useful post for anyone with less programming experience, including myself. While some of the ideas are fairly obvious and/or self-explanatory, some of them really help. Thanks Cheesy

Offline f.l.x

Senior Member


Projects: 3


there is no place like 127.0.0.1


« Reply #6 - Posted 2005-12-08 01:06:49 »

Great resource!

a bit late for me, one game "finished"... i'll have to try another!! agh! my exams and my sleeping hours are gone!!!

Litterarum radices amaras, fructus dulces
http://flx.proyectoanonimo.com
figth spam!
Offline woogley
« Reply #7 - Posted 2005-12-08 06:51:44 »

this is excellent! a definite link to be added to java unlimited
Offline DonaldEKnuth

Junior Member





« Reply #8 - Posted 2005-12-08 20:08:44 »

OnYx wrote this in [url http://www.java-gaming.org/forums/index.php?topic=11694.msg92988#msg92988]my thread[/url]:
Quote
-one class
-as few methods as possible
-as few class variables as possible (move them to the constructor)
-use obfuscators (progruard, jax, jarg, joga...) in different combinations (eg jax->jarg or joga->jarg)
-try different zip programs (7zip/kzip)
-?: is smaller than if/else
-decompile your stuff occassionaly to check if the obfuscators do their job
-use enableEvents instead of listeners
-look around in the lib for stuff you can (ab)use
Some of these are not in the Wiki yet, I thought I would paste them in at first but changed my mind and wanted to run them by you guys (so that one of you can put those in that you agree on).

One thing which would be great on the wiki would be if there were a pointer to the smallest way of creating a sound (procedurally, feeding some function a waveform I would guess) and playing it.

My 4k 2006 Entry: Sokoban4k
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #9 - Posted 2005-12-08 21:28:46 »

Some of these are not in the Wiki yet, I thought I would paste them in at first but changed my mind and wanted to run them by you guys (so that one of you can put those in that you agree on).

As I said before. Just go ahead and modify it. Worst case, someone else will fix it or remove it. Best case, everyone will improve upon your work. I just wrote what I did to blow off a little stress. I don't have the time to see this article completed all by myself. So if you have tips, throw them in there. Smiley

Quote
One thing which would be great on the wiki would be if there were a pointer to the smallest way of creating a sound (procedurally, feeding some function a waveform I would guess) and playing it.

There is no "smallest way". Like with all engineering, there are only tradeoffs. With MIDI, you can save gobs of space, but you are at the whims of the MIDI harware/software/soundbank. With procedural synthesis you can replicate more realistic sounds. However, the more realistic the function, the more space it takes. QED.

Java Game Console Project
Last Journal Entry: 12/17/04
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #10 - Posted 2005-12-08 22:32:09 »

I wrote:

"look around in the lib for stuff you can (ab)use"

I used Rectangle.Float objects in fuzetsu for tracking the particle/bullet positions (x and y fields) and velocities (width and height fields). Worked a lot bettern than expected. Smiley

edit: In jm4k I used arrays, which was a) a pain b) horrible inefficient and c) most likely not smaller at all.

弾幕 ☆ @mahonnaiseblog
Offline Riven
Showcase Moderator

JGO Overlord


Medals: 611
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #11 - Posted 2005-12-10 15:53:44 »

Wiki sucks, sometimes...

I added 8 tips! 5 of them got removed by somebody...

What a bunch of crap.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #12 - Posted 2005-12-10 17:06:21 »

Maybe they sucked?  Grin

...kidding

Offline f.l.x

Senior Member


Projects: 3


there is no place like 127.0.0.1


« Reply #13 - Posted 2005-12-10 18:05:59 »

double post them, here and on the wiki.

maybe a sticky with the most valuable hints?

Litterarum radices amaras, fructus dulces
http://flx.proyectoanonimo.com
figth spam!
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #14 - Posted 2005-12-10 19:06:05 »

Wiki sucks, sometimes...

I added 8 tips! 5 of them got removed by somebody...

What a bunch of crap.

Riven, none of them got removed. I moved them up to the "General Tips" area and did a bit of rewording to be consistent with the rest of the tips. Check for yourself. The tips should look very familiar.

Cooperation in improving the document is how Wikis are supposed to work. (Though it is a bit weird at first.) If it looks like something has been removed, use the DIFF tool to figure out if it hasn't just been shuffled around a bit. Smiley

Edit: *sigh* I wish you hadn't gone and deleted the tips in the Misc area. This Wiki doesn't show the original formatting, meaning that I'm going to have to spend some time recreating it. Again, your other tips weren't deleted. They were promoted.

Java Game Console Project
Last Journal Entry: 12/17/04
Offline Riven
Showcase Moderator

JGO Overlord


Medals: 611
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #15 - Posted 2005-12-11 00:49:49 »

Whoops...  Roll Eyes

I did a very quick search to find my tips elsewhere but could not find it.

I'll dig the other tips out of rivision-history then.



This was my first encounter with Wikis, so please bare with me... *kuch*

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Riven
Showcase Moderator

JGO Overlord


Medals: 611
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #16 - Posted 2005-12-11 00:57:41 »

Err, I meant:I didn't find it the first time, but ofcourse I found them when you told me where to look.

Anyway, I clearified the lined marked by a (?) and I hope it's clear now.

That's all for today..

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #17 - Posted 2005-12-11 01:27:40 »

Excellent! Good job Riven! Smiley Now if we could just get a few more people following your lead...  Wink

Java Game Console Project
Last Journal Entry: 12/17/04
Offline [ERROR]

Senior Newbie


Projects: 1



« Reply #18 - Posted 2005-12-26 06:41:43 »

Great! very helpful.  how abt a "Links" section?

found this useful for procedural sound ->  http://fivedots.coe.psu.ac.th/~ad/jg/ch05/index.html

Offline Markus_Persson

JGO Wizard


Medals: 12
Projects: 19


Mojang Specifications


« Reply #19 - Posted 2006-01-01 16:39:52 »

EDIT: This post is wrong. After compression, the first way is smaller.



It requires me to log in to edit, and I'm far too lazy to sign up, but:

1  
2  
3  
4  
5  
6  
7  
8  
public void main(String[] args) 
{
    int[] badguy_x = new int[256];
    int[] badguy_y = new int[256];
    int[] badguy_type = new int[256];
   
    draw(badguy_x[0], badguy_y[0], badguy_type[0]);
}


takes more space than

1  
2  
3  
4  
5  
6  
public void main(String[] args) 
{
    int[][] badguy = new int[256][3];

    draw(badguy[0][0], badguy[0][1], badguy[0][2]);
}



Play Minecraft!
Offline Riven
Showcase Moderator

JGO Overlord


Medals: 611
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #20 - Posted 2006-01-01 17:48:15 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
public void main(String[] args)
{
    int[] badguy = new int[768]; // 256*3

    // random lookup
   for(int i=0; i<768; i+=3)
       draw(badguy[i], badguy[i+1], badguy[i+2]);

    // sequence lookup
   for(int i=0; i<768;)
       draw(badguy[i++], badguy[i++], badguy[i++]);
}


I can't compile on this machine, but my gutt-feeling tells me it's smaller Smiley

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #21 - Posted 2006-01-01 17:53:05 »

1  
       draw(badguy[i++], badguy[i++], badguy[i++]);

Are the values for i well defined for this usage?
What order does Java evaluate the parameters?

Offline Anon666

Junior Member




aka Abuse/AbU5e/TehJumpingJawa


« Reply #22 - Posted 2006-01-01 18:05:43 »

1  
       draw(badguy[i++], badguy[i++], badguy[i++]);

Are the values for i well defined for this usage?
What order does Java evaluate the parameters?

That's fine, they are evaluated left to right, with the value of i being updated immediately after each array dereference.
Offline Markus_Persson

JGO Wizard


Medals: 12
Projects: 19


Mojang Specifications


« Reply #23 - Posted 2006-01-01 18:48:20 »

I put all four ways into my base code for my new 4k game.
Results after proguard and kzip, sorted by size:

Interlaced sequential: 893 bytes
1  
2  
3  
4  
int[] badguy = new int[768]; // 256*3

for(int i=0; i<768;)
   pixels[badguy[i++]+badguy[i++]*640]=badguy[i++];


One array per variable: 898 bytes
1  
2  
3  
4  
5  
6  
int[] badguy_x = new int[256];
int[] badguy_y = new int[256];
int[] badguy_t = new int[256];

for(int i=0; i<256; i++)
   pixels[badguy_x[i]+badguy_y[i]*640]=badguy_t[i];


Interlaced random: 899 bytes
1  
2  
3  
4  
int[] badguy = new int[768]; // 256*3

for(int i=0; i<768; i+=3)
   pixels[badguy[i]+badguy[i+1]*640]=badguy[i+2];


2d array: 908 bytes
1  
2  
3  
4  
int[][] badguy = new int[256][3];

for(int i=0; i<256; i++)
   pixels[badguy[i][0]+badguy[i][1]*640]=badguy[i][2];


The biggest downside of 2d array and interlaced random is that it requires a numerical constant in the constant pool for each variable you have.
Interlaced sequential is by far the most repetetive/easy to compress, but it could be hard to work with.

EDIT:
Forgot *640 in 2d array, adding two more bytes

Play Minecraft!
Offline appel

JGO Wizard


Medals: 49
Projects: 4


I always win!


« Reply #24 - Posted 2006-01-02 00:52:38 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
final int X = 0;
final int Y = 1;
final int TYPE = 2;
final int HEALTH = 3;

int[] badguys = new int[256][4];

// then you can *read* the bad guys like this:
badguys[i][X]
badguys[i][Y]
badguys[i][TYPE]
badguys[i][HEALTH]


The compiler or the obfuscators should delete the final variables declerations and insert their values where they are referenced.

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline Anon666

Junior Member




aka Abuse/AbU5e/TehJumpingJawa


« Reply #25 - Posted 2006-01-02 01:13:12 »

But obviously not doing the double dereferencing of the array every time you access it.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
final int BADGUY_COUNT = 256;

final int X = 0;
final int Y = 1;
final int TYPE = 2;
final int HEALTH = 3;
final int BADGUY_ATTRIBUTE_COUNT = 4;

int[] badguys = new int[BADGUY_COUNT][BADGUY_ATTRIBUTE_COUNT];

for(int i = 0;i < BADGUY_COUNT;i++)
{
   final int [] currentBadguy = badguys[i];

   // then you can *read* the bad guys like this:
  currentBadguy[X]
   currentBadguy[Y]
   currentBadguy[TYPE]
   currentBadguy[HEALTH]
}
Offline Markus_Persson

JGO Wizard


Medals: 12
Projects: 19


Mojang Specifications


« Reply #26 - Posted 2006-01-02 01:14:59 »

That still takes up more space than to just have one array per variable.

Skipping the double dereferencing doesn't actually save you that much (it didn't save a single byte for me when I tried it in Miners4k) after compression.

Play Minecraft!
Offline Anon666

Junior Member




aka Abuse/AbU5e/TehJumpingJawa


« Reply #27 - Posted 2006-01-02 01:29:47 »

Indeed, I can imagine it depends a great deal on the structure of your code, and what you are doing with the arrays.

Keeping just one int[][] within scope may allow more efficient use of the direct access local variables.
However this may not help at all if you have a smart bytecode optimiser that can reorder local variable usage for optimum size.

also, if the object you are representing with the int [] has *alot* of attributes,
Is it safe to assume zip compression will compress :-

int [] a = new int[200];
int [] b = new int[200];
...
int [] y = new int[200];
int [] z = new int[200];

Down to less than :-

int [][] aa = new int[26][200];

Perhaps it is a safe assumption, perhaps not.

Either way, I would imagine the difference between the 2 approaches will be less than 30bytes in the vast majority of cases.
Algorithmic optimisations are always a better place to start =)

:edit:

The Interlaced sequential is kinda funky, and is better for that simplistic test case - however I can't think when I would ever want to access every element of the array sequencially (and only once!)

More often than not you will be accessing the elements randomly.
Offline appel

JGO Wizard


Medals: 49
Projects: 4


I always win!


« Reply #28 - Posted 2006-01-02 01:33:28 »

FYI markus I took your source for the Miners4k game and was able to compact it about 50 bytes more.

I used a combination of JoGa, Proguard and JShrink...and also BJWFlate for compression.

edit: link removed at request.

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline Markus_Persson

JGO Wizard


Medals: 12
Projects: 19


Mojang Specifications


« Reply #29 - Posted 2006-01-02 10:00:42 »

Cool, but could you please not distribute any binaries (or modified source code versions) of it?

Play Minecraft!
Pages: [1] 2
  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.

xsi3rr4x (73 views)
2014-04-15 18:08:23

BurntPizza (68 views)
2014-04-15 03:46:01

UprightPath (79 views)
2014-04-14 17:39:50

UprightPath (65 views)
2014-04-14 17:35:47

Porlus (80 views)
2014-04-14 15:48:38

tom_mai78101 (104 views)
2014-04-10 04:04:31

BurntPizza (164 views)
2014-04-08 23:06:04

tom_mai78101 (260 views)
2014-04-05 13:34:39

trollwarrior1 (210 views)
2014-04-04 12:06:45

CJLetsGame (220 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!