Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (568)
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  
  Resource Loading Percentage Formula [SOLVED]  (Read 375 times)
0 Members and 1 Guest are viewing this topic.
Offline GabrielBailey74
« Posted 2013-06-02 21:04:59 »

Hello JGO, since my last help topic (Where I couldn't remember how to divide properly..) i've continued to work on a "Loader" for my project ^_^

The issue I'm having is once my ImageIcon[] array's size hits a certain cap my percentage formula fails.
(Percentage formula meaning what percentage out of 100 is increased per resource loaded)

Here is how I'm "Test Loading" a ImageIcon[] array:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
      imgs1 = new ImageIcon[2000000]; // if array[] size is > 2000000 + (another zero) formula fails.
     int objects2Load = imgs1.length;
      double increment_formula = totalPercent / objects2Load;
      boolean accurate_formula = Boolean.valueOf((increment_formula * objects2Load) == totalPercent);
      print("At this rate (Loading " + objects2Load + " objects).");
      print("Each object will increment the % by " + increment_formula);
      if (!accurate_formula) {
         System.err.println("Formula is not accurate");
         System.exit(0);
      }
      print("Formula's accurate!");
      sleep(1000);

      /* Loading process */
      while (percent < totalPercent) {
         for (int i = 0; i < imgs1.length; i++) {
            imgs1[i] = loadSprite("tiles/floor/tile_" + MathUtils.random(5) + ".png",
                  increment_formula, i);
         }
      }

The above code (Loading 2000000 ImageIcons) works properly, however if I add 1 more 0 "Zero" to the ImageIcon[]'s size my percentage formula does not function Sad

Here is the method LoadSprite(String, int, int) for those who were wondering:
1  
2  
3  
4  
5  
6  
   private ImageIcon loadSprite(String path, double percent_increment, int imgCount) {
      percent += percent_increment;
      progressBar.setValue((int) percent);
      System.out.println("Image "+imgCount+" loaded"); // for debugging.
     return new ImageIcon("res/sprite/" + path);
   }

I believe this has to do with the data type I am using although I am not 100% sure / confused.

If somebody could help me that would be great :>
Or at least push me in the right direction.

Offline GabrielBailey74
« Reply #1 - Posted 2013-06-02 21:18:27 »

Solved, apparently I can't allocate that many ImageIcons on startup T_T (For testing purposes)
1  
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

So the reason it was saying my formula was inaccurate was because it wasn't printing out the exception.
(Thus the ImageIcon[] array was never initialized)

Offline davedes
« Reply #2 - Posted 2013-06-02 21:18:49 »

I think there is a serious problem if you are loading 20,000,000 image icons into memory. Why do you need more than 5?


To get the percentage:
1  
2  
3  
for (int i = 0; i < imgs1.length; i++) {
    float p = i / (float)imgs1.length * 100f;
}

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline GabrielBailey74
« Reply #3 - Posted 2013-06-02 21:20:11 »

I think there is a serious problem if you are loading 20,000,000 image icons into memory. Why do you need more than 5?

That would be a serious issue if I were truly doing that in my project yes lol.
However in this case 20,000,000 was just a number I popped in during Testing :>

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.

Pippogeek (40 views)
2014-09-24 16:13:29

Pippogeek (31 views)
2014-09-24 16:12:22

Pippogeek (21 views)
2014-09-24 16:12:06

Grunnt (47 views)
2014-09-23 14:38:19

radar3301 (29 views)
2014-09-21 23:33:17

BurntPizza (65 views)
2014-09-21 02:42:18

BurntPizza (37 views)
2014-09-21 01:30:30

moogie (44 views)
2014-09-21 00:26:15

UprightPath (53 views)
2014-09-20 20:14:06

BurntPizza (55 views)
2014-09-19 03:14:18
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!