Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (516)
Games in Android Showcase (122)
games submitted by our members
Games in WIP (577)
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 948 times)
0 Members and 1 Guest are viewing this topic.
Offline i30817

Junior Duke





« Posted 2012-06-20 15: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?
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 823
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2012-06-20 15: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 Duke





« Reply #2 - Posted 2012-06-20 16: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
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 823
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #3 - Posted 2012-06-20 16: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: 353
Projects: 3
Exp: 5 years


I'm the King!


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

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

Offline i30817

Junior Duke





« Reply #5 - Posted 2012-06-20 18: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.

TehJavaDev (31 views)
2014-10-27 03:28:38

TehJavaDev (26 views)
2014-10-27 03:27:51

DarkCart (40 views)
2014-10-26 19:37:11

Luminem (21 views)
2014-10-26 10:17:50

Luminem (26 views)
2014-10-26 10:14:04

theagentd (32 views)
2014-10-25 15:46:29

Longarmx (61 views)
2014-10-17 03:59:02

Norakomi (57 views)
2014-10-16 15:22:06

Norakomi (46 views)
2014-10-16 15:20:20

lcass (43 views)
2014-10-15 16:18:58
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!