Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
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  
  2-to-1 mappings, Fractals and thanks for all the fish  (Read 4424 times)
0 Members and 1 Guest are viewing this topic.
Offline Roquen

JGO Kernel

Medals: 517

« Posted 2014-03-24 15:20:51 »

The first thing that comes to my mind when I think game programming is:  N-to-1 mappings and fractals.  And I'm sure you do too. (For improved cache accesses)

(P.S. I wouldn't have started a new thread...but what 'cha gonna do?)
Offline matheus23

JGO Kernel

Medals: 138
Projects: 3

You think about my Avatar right now!

« Reply #1 - Posted 2014-03-24 17:01:14 »

Would be cool if you had some kind of image(s) showing off the principle behind the mathematical symbol-magic (in other words: code). Smiley

Also, maybe a very tiny use-case example could help, too Cheesy

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline theagentd
« Reply #2 - Posted 2014-03-24 22:30:43 »

What are these for?

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Roquen

JGO Kernel

Medals: 517

« Reply #3 - Posted 2014-03-25 10:39:56 »

I've only stuck up Morton for the moment but:


CDF Player required (


Say you have a 2D data set which you flatten into an array or some other linear storage.  For simplicity it's a square with power-of-two height/width = D.  The common indexing will be
.  This is pretty good.  It's a 2-to-1 mapping that's compact (there's no wasted space).  I'll call this row-linear just to give it a name.

Now it's common if you examine some cell (x,y) that the next cell(s) you're going to visit are going to be close to cells you've already looked at recently.  With row-linear the next cell is going to be very close in memory if it's a horizontal displacement.  But it's not very hot if (say) you're walking vertically.  A simple alternate indexing scheme would be a reflected row-linear.  So the first row is (x), second is (2D-x-1), third is (2D+x), forth (4D-x-1), etc.  This simplifies but it's not a very interesting scheme.

So enter space-filling-curves and other 2-to-1 mappings.  Talking about exact properties of each actually isn't very useful because "to do the math" requires knowing average (or worst case) access patterns and details of the target hardware's memory architecture.  Pure PITA.  Schemes that are potentially worth considering will good locality.  Morton is nice and simple to compute...esp incrementally.  So basically you layout the data in some alternate indexing scheme in an attempt to move less memory.

What kind of gains can one expect?  Small.  You're explicitly reading and writing the same amount of memory and performing the same amount of work at each cell.  If you want real speed gains this isn't the place to look.  Any speed gains stem from moving less memory around in the memory architecture.  One thing to note is that all the gains are not local the "thread" where this is occurring...the reduced pressure on memory allows other threads to progress (assuming they're accessing).  What I'm only single threaded!  ORLY?  You at least have two more: GC and compiler.

I've added a few comments and I'll toss together a RayGrid2D example.

Offline princec

« JGO Spiffy Duke »

Medals: 1033
Projects: 3
Exp: 20 years

Eh? Who? What? ... Me?

« Reply #4 - Posted 2014-03-25 11:42:41 »

I might particularly have use for these mappings at some point... a way down the line, when I'm really scraping the barrel for performance optimisations. My 2D maps are 256x256 in size, and each cell is a long (packed bits representing 12 fields), and I've got say 4..8 threads accessing it, for maybe 6,000 entities or so, usually not in a random fashion but scanning. It'd be interesting if there was some sort of visual system to represent cache misses and so on with respect to the usage of a data structure.

Cas Smiley

Offline Roquen

JGO Kernel

Medals: 517

« Reply #5 - Posted 2014-03-25 12:08:23 »

...a way down the line, when I'm really scraping the barrel for performance...
That's the spirit!  And the exact use case.

Quickly banged out:

Pages: [1]
  ignore  |  Print  

EgonOlsen (76 views)
2018-06-10 19:43:48

EgonOlsen (56 views)
2018-06-10 19:43:44

EgonOlsen (76 views)
2018-06-10 19:43:20

DesertCoockie (258 views)
2018-05-13 18:23:11

nelsongames (156 views)
2018-04-24 18:15:36

nelsongames (155 views)
2018-04-24 18:14:32

ivj94 (896 views)
2018-03-24 14:47:39

ivj94 (160 views)
2018-03-24 14:46:31

ivj94 (809 views)
2018-03-24 14:43:53

Solater (173 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!