Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (481)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (548)
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  
  Help?  (Read 2940 times)
0 Members and 1 Guest are viewing this topic.
Offline EnderGT

Junior Member





« Posted 2008-12-08 03:57:06 »

The posts on 4KJO seem to have disappeared. Can the author please contact me? I'm getting a lot of exceptions that are telling me that the jar file is corrupt... but yet it runs just fine.

Also, I thought I'd followed all the "rules" for making the code as small as possible, and my code isn't really doing THAT much, but I've only just now been able to get it under 7 kb. I'm hoping one of the wizards here can take a look and point out any obvious mistakes I'm making.

I'm trying to make an online poker game (server and client in the same jar). Currently it's Omaha Hi-Lo 8, I will probably change it to Hold 'Em to save a few more bytes.

Thanks in advance.

Edit: No, it doesn't yet work, there's a few bugs I still need to fix. I just thought I'd take a look at how I was doing on size, and realized the crisis.
Offline moogie

JGO Knight


Medals: 12
Projects: 6
Exp: 10 years


Java games rock!


« Reply #1 - Posted 2008-12-08 04:46:53 »

refer to the first post of the Links, tips and goodies thread. It has links to the 4KJO tool I created Smiley

Offline moogie

JGO Knight


Medals: 12
Projects: 6
Exp: 10 years


Java games rock!


« Reply #2 - Posted 2008-12-08 05:26:56 »

Some suggestions:

I think most of your class size bloat comes from the different API classes you make use of all of which add to the class's symbol table size.

i would suggest try using only one array and use different Index offsets for logically different instead of many different arrays each representing a different logical component.

Try reducing the number of local variables used. If you can, reuse a local variable for different logical purposes.

try using the ? opertor when conditionally assigning values... e.g for

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
option = FOLD;
              if (active > 1 && raises < 4) {
                if ((bet+raise) < cash[action]) {
                  if (bet == 0) {
                    option |= BET;
                  } else {
                     option |= RAISE;
                  }
                } else {
                  option |= ALLIN;
                }
              }


make it:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
option = (active > 1 && raises < 4) ?
  option |= ((bet+raise) < cash[action])?
     (bet == 0) ?
       BET
     :
       RAISE
   :
      ALLIN
:
   FOLD



replace all division where possible by bitwise operation... i.e.
1  
 /2 
  to
1  
 >> 1 

 
if possible convert all for loops to loop backward. The comaprision to 0 test will therefore occur often and be more easily compressable.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Markus_Persson

JGO Wizard


Medals: 14
Projects: 19


Mojang Specifications


« Reply #3 - Posted 2008-12-08 08:18:52 »

replace all division where possible by bitwise operation... i.e.
1  
 /2 
  to
1  
 >> 1 

Those two take up exactly the same number of bytes..

Play Minecraft!
Offline moogie

JGO Knight


Medals: 12
Projects: 6
Exp: 10 years


Java games rock!


« Reply #4 - Posted 2008-12-08 09:24:31 »

hmm, in my previous entry it gained me a couple of bytes... perhaps the different bytes used to represent >> 1 was more favorable when compressing my JAR entry?
Offline Markus_Persson

JGO Wizard


Medals: 14
Projects: 19


Mojang Specifications


« Reply #5 - Posted 2008-12-08 10:11:24 »

I was mostly being a smartass. Wink

/2 and >>1 happen to use the same amount of bytes, and so does /4 and >>2.
But for divisions by 8, 16, and 32, you save one byte by using >> instead.
Divisions by 64 uses the same number of bytes as >> since iconst_N doesn't go higher than 5, and /64 is >>6.
Using right shift instead of divisions by 128 through 16384 saves one byte.
Over 16384, you're using the constant pool, so now you're saving even more by using >>.

So in general, it's (probably) a good idea to use >>, but for the /2 case, any benefit you saw probably just came from compression randomness. =)

Play Minecraft!
Offline Abuse

JGO Knight


Medals: 12


falling into the abyss of reality


« Reply #6 - Posted 2008-12-08 14:22:24 »

For completeness, it's worth mentioning proguard automatically replaces all multiplication by powers of 2 with the equivalent shift, as it's a safe speed & size optimisation.

It doesn't do the same for division because it's an unsafe optimisation, due to the 2 operations not being entirely equivalent (/2 rounds toward 0, >>1 rounds toward -ive infinity)
So, adding the shifts manually (where safe to do so) may well save you some bytes.

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline EnderGT

Junior Member





« Reply #7 - Posted 2008-12-08 14:47:20 »

refer to the first post of the Links, tips and goodies thread. It has links to the 4KJO tool I created Smiley
Funny, I looked right at it at didn't see it. I also searched for "4KJO" and got no results. Odd.

Anyway, is there any chance you could take a look at the exceptions I'm seeing? I'll post the jar file I used if you need.
Offline EnderGT

Junior Member





« Reply #8 - Posted 2008-12-08 14:54:37 »

I think most of your class size bloat comes from the different API classes you make use of all of which add to the class's symbol table size.
I'll take a look and see if there's any way I can trim this down.

i would suggest try using only one array and use different Index offsets for logically different instead of many different arrays each representing a different logical component.
I was going to have a single array with different indices being the different variables I needed (for the singleton variables) but it seemed that that would actually add to the size. There's only a couple of other arrays that I could do this for, but I'll keep this in mind.

Try reducing the number of local variables used. If you can, reuse a local variable for different logical purposes.
I've been trying to reuse wherever possible, but I'll look harder for more opportunities.

try using the ? opertor when conditionally assigning values...
Is this true? I thought someone, way back when, said that this way actually took more bytes...

if possible convert all for loops to loop backward. The comaprision to 0 test will therefore occur often and be more easily compressable.
Will do.

Thanks for taking a look!
Offline moogie

JGO Knight


Medals: 12
Projects: 6
Exp: 10 years


Java games rock!


« Reply #9 - Posted 2008-12-08 19:00:42 »

I'll take a look and see if there's any way I can trim this down.
I was going to have a single array with different indices being the different variables I needed (for the singleton variables) but it seemed that that would actually add to the size. There's only a couple of other arrays that I could do this for, but I'll keep this in mind.
I've been trying to reuse wherever possible, but I'll look harder for more opportunities.
Is this true? I thought someone, way back when, said that this way actually took more bytes...
Will do.

Thanks for taking a look!
[/quote

I had thought the same about using one monolithic array, but it did end up better as it reduced the symbol table and i was able to use/abuse the monolithic array to perform some game logic by carefully ordering the array and thus reducing the number of conditional statements i needed.

I thought about writing a tool that would parse a java/class file and list potential local variables that could be reused at different points in the execution... perhaps i should do this.

it might be the case that the ? operator takes more bytes, however in the example listed above, it also reduce the number of |= operators... so it may give a reduction.

Your game logic seems very complex with many conditions and states... with out simplifying the logic or abusing some behavior of java or math to represent your game logic I do not think you will be able to fit it with in 4k Sad
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline EnderGT

Junior Member





« Reply #10 - Posted 2008-12-08 19:19:57 »

Your game logic seems very complex with many conditions and states... with out simplifying the logic or abusing some behavior of java or math to represent your game logic I do not think you will be able to fit it with in 4k Sad
I'm starting to think the same... I've gotten it down to 6037 bytes by inlining the network code instead of using DataInput/OutputStreams, and by removing a few unnecessary states and combining a few others, but I'm not sure what else I'll be able to remove without making it simply unplayable.

Edit: now 5750 bytes... a few more trouble spots to attack before I switch from Omaha to Hold'Em to save another chunk. I'd rather stay with Omaha if I can - limit hold'em is somewhat boring IMO.
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.

atombrot (27 views)
2014-08-19 09:29:53

Tekkerue (25 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (15 views)
2014-08-16 06:20:21

Tekkerue (22 views)
2014-08-16 06:12:11

Rayexar (61 views)
2014-08-11 02:49:23

BurntPizza (39 views)
2014-08-09 21:09:32

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38

BurntPizza (67 views)
2014-08-03 02:57:17
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!