Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (535)
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  
  How to compress (lossly) longs into ints?  (Read 905 times)
0 Members and 1 Guest are viewing this topic.
Offline i30817

Junior Member





« Posted 2012-06-20 17:08:49 »

Upgraded to java 7, got a new problem:
java 7 introduced the URLConnection.getContentLengthLong() method, which i want to use (for those wonderful 2gb+ downloads)

Anyway, the problem is that jprogressbar and all the ancillary classes is only prepared to accept ints. This is not so critical considering it's almost all view classes (taking care to be careful around the edges since we don't want it to look "not started" or "done" when it's not) - but the long needs to be compressed into a int

I was thinking of something like:
0L is int 0
1L ...  (totalL -1L) is int mapping(1L) ... mapping(totalL -1L) where some number of contiguous mappings give the same int value
totalL is int mapping(total) that is unique (to make JProgressBar look full only at the end)


I'm terrible at maths. Help?
Online Riven
« League of Dukes »

JGO Overlord


Medals: 744
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2012-06-20 17:26:16 »

Unless you expect 2TB (!) files, you can divide all values by 1024 and cast them to ints.

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

Junior Member





« Reply #2 - Posted 2012-06-20 18:37:06 »

something like:
int map(long i, long max){
 if (max <= Integer.MAX_VALUE)//don't compress without need
   return (int) i;

 int newI = (int) i / 1024;
 if(newI == 0 && i != 0L) return 1;
 if(newI == ((int)max/1024) && i != max) return ((int)max/1024)-1;
 return newI;
}

?

hmmm screw this, 2gb+ downloads stay undetermined.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online Riven
« League of Dukes »

JGO Overlord


Medals: 744
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #3 - Posted 2012-06-20 18:55:49 »

No, always divide by 1024. Who cares about sub-1K amounts.

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

JGO Kernel


Medals: 337
Projects: 2
Exp: 5 years


I'm the King!


« Reply #4 - Posted 2012-06-20 19:33:39 »

Who needs to even map? You can simply multiply the percentage done by the range the JProgressBar goes Wink

Offline i30817

Junior Member





« Reply #5 - Posted 2012-06-20 20:42:53 »

Good idea thanks.
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.

E.R. Fleming (16 views)
2014-07-29 03:07:13

E.R. Fleming (5 views)
2014-07-29 03:06:25

pw (39 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (26 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21

Zero Volt (50 views)
2014-07-17 23:47:54

danieldean (42 views)
2014-07-17 23:41:23

MustardPeter (44 views)
2014-07-16 23:30:00
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!