Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
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  
  Is there a logical reason to stuff 2D array data into one?  (Read 3996 times)
0 Members and 1 Guest are viewing this topic.
Offline Roquen
« Reply #30 - Posted 2014-05-06 11:51:59 »

Have I ever mentioned that table-lookups for random numbers is crazy slow and horrible quality?

Food for thought: What expectation do you have of the compiler doing the right thing before it runs?  Are these data set sizes reasonable?  Are the tests representative of expected time consuming functions?  How does the memory architecture behavior when pounding on writes?
Offline Abuse

JGO Knight


Medals: 13


falling into the abyss of reality


« Reply #31 - Posted 2014-05-06 12:26:17 »

Going back to the original question...

Quote
Is there a logical reason to stuff 2D array data into one?

If your game logic can be implemented more simply with a 1D array, then there is most definitely a good reason.

Pixel operations for example, can often be performed irrespective of axis coordinates, thus the algorithm will look a lot neater if the data is manipulated as a flat array (avoiding the need for nested loops).

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline Roquen
« Reply #32 - Posted 2014-05-06 13:45:25 »

I quickly hacked Riven's test bed: http://pastebin.java-gaming.org/8aa10911f92

Data sizes are smaller (tweak pow at top of the file).  Removed some test that are basically repeats, tweaked a few and added a couple.  Run and look at how numbers evolve.  If too fast tweak trialPrintRate up and down if too slow.

Then try again with:

java -server -cp bin -XX:+UnlockDiagnosticVMOptions -XX:+PrintCompilation -XX:+PrintInlining CacheGrid
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline GoToLoop
« Reply #33 - Posted 2014-05-06 15:17:35 »

Still you're not taking into consideration my tiny optimizations:   Lips Sealed  

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
public static void fill_2d_random() {
  for (int y = 0; y != DIM;) {
    int yi = randX[y++], ry[] = rows[yi], x = 0;

    while (x != DIM) {
      int xi = randX[x++];
      ry[xi] = yi^xi;
    }
  }
}
Offline BurntPizza
« Reply #34 - Posted 2014-05-06 15:22:06 »

Still you're not taking into consideration my tiny optimizations:   Lips Sealed  

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
public static void fill_2d_random() {
  for (int y = 0; y != DIM;) {
    int yi = randX[y++], ry[] = rows[yi], x = 0;

    while (x != DIM) {
      int xi = randX[x++];
      ry[xi] = yi^xi;
    }
  }
}


I'm not in a position to test right now, but do those really do much? Sure you save a couple of array lookups I guess, but I don't think the ry[] would assist much with caching (it's still a pointer).
Offline GoToLoop
« Reply #35 - Posted 2014-05-06 16:04:55 »

Sure you save a couple of array lookups I guess, but I don't think the ry[] would assist much with caching (it's still a pointer).

That's the point, 1 pointer rather than 2! Moreover, values which don't change later in the inner loop are cached right in the outer loop!   Tongue  
Offline Roquen
« Reply #36 - Posted 2014-05-06 17:08:09 »

Look up tables are slow.  You have to be cutting a large number of operations for them to be a win.
Offline ctomni231

JGO Wizard


Medals: 99
Projects: 1
Exp: 7 years


Not a glitch. Just have a lil' pixelexia...


« Reply #37 - Posted 2014-05-07 07:12:49 »

I had to sort 2d array tiles, so that was one instance where it was logical for me. As said before, it is also a little bit more memory efficient (RAM and physical). Actually, I find it very hard to use 2d arrays outside of tables or tile based games.  persecutioncomplex

Offline Rayvolution

JGO Kernel


Medals: 216
Projects: 2
Exp: 1 year


Resident Crazyman


« Reply #38 - Posted 2014-05-08 00:31:13 »

my, now this has become a thread. Shocked

Well, as an update, I have used several Array[256][256] arrays in my new pathfinding algorithm, the finalized (for now) pathfinding class can now pathfind over complex/convoluted mazed-terrain on a 256x256 map at a rate of 0-1ms/calc for short, and 8-10ms/calc for long distances. (Average long distances check around 35,000 tiles before finalizing the path, pathing over a complicated maze from around 0,0 on the map to 256,256).

My pathfinding is my own take on A*, that removes almost all of the terrain/heuristic data and actually seeks the path backwards from destination to start. It also finds shortest path A* would have found every time. Wink

I currently have over 5,000 entities picking random spots all over a 256x256 map and pathfinding to them, and keeping a solid 60FPS.

I'll share the code later, when I'm done cleaning it up and announce the second project that this is a part of.

- Raymond "Rayvolution" Doerr.
Retro-Pixel Castles - Survival Sim/Builder/Roguelike!
LIVE-STREAMING DEVELOPMENT: http://www.twitch.tv/SG_Rayvolution
Offline princec

JGO Kernel


Medals: 404
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #39 - Posted 2014-05-08 08:16:12 »

I currently have over 5,000 entities picking random spots all over a 256x256 map and pathfinding to them, and keeping a solid 60FPS
That's rather impressive... I have to max out a 2.6GHz i7 to achieve that :| (admittedly I'm also drawing 100k sprites)

Cas Smiley

Pages: 1 [2]
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

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

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

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

lcass (28 views)
2014-10-15 16:18:58

TehJavaDev (53 views)
2014-10-14 00:39:48

TehJavaDev (54 views)
2014-10-14 00:35:47

TehJavaDev (43 views)
2014-10-14 00:32:37

BurntPizza (64 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (78 views)
2014-10-11 22:30:10
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!