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

https://github.com/roquendm/JGO-Grabbag/tree/master/src/roquen/math/sfc

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

JGO Kernel


Medals: 110
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?

Myomyomyo.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Roquen
« Reply #3 - Posted 2014-03-25 10:39:56 »

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

Pictures/Wikipedia:
http://en.wikipedia.org/wiki/Z-order_(curve)
http://en.wikipedia.org/wiki/Hilbert_curve

CDF Player required (https://www.wolfram.com/cdf-player/):
http://demonstrations.wolfram.com/HilbertAndMooreFractalCurves/
http://demonstrations.wolfram.com/Lebesgue3DCurves/
http://demonstrations.wolfram.com/WunderlichCurves/
http://demonstrations.wolfram.com/HilbertAndMoore3DFractalCurves/

Wolfram/Alpha:
http://www.wolframalpha.com/input/?i=hilbert+curve&lk=4&num=2


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
index=(D*y+x)
.  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 Kernel


Medals: 409
Projects: 3
Exp: 16 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
« Reply #5 - Posted 2014-03-25 12:08:23 »

Quote
...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: https://github.com/roquendm/JGO-Grabbag/blob/master/src/roquen/interp/IndexedRayGrid2D.java

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.

DarkCart (16 views)
2014-10-31 21:44:48

DarkCart (22 views)
2014-10-31 21:43:57

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

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

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

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

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

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

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

Norakomi (62 views)
2014-10-16 15:22:06
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!