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  
  Multi-Dimensional Generic Arrays  (Read 3584 times)
0 Members and 1 Guest are viewing this topic.
Offline UprightPath
« Posted 2012-01-29 01:56:50 »

This here's a conundrum I've been trying to slog through for some time now. Part of it is a decided dislike of List type objects and part of it is issues with the way Generics work in Java. Here's the problem:

The game I'm designing is going to use an map using X dimensions (Where X >= 1). This base map is most easily described as a dense rectangular array (For X == 2), or a dense cubic array (For X == 3), etc. On "Top" of this is a very sparse map, with the same dimensions of the previous map, and on top of that can be another sparse map, and on top of that can be another, ad nauseum.

Here's a cobbled together example:
Layer 1 (Dense): Physical description of world
Layer 2 (Sparse): Location of hidden items
Layer 3 (Sparse): Location of special ground effects (Think this area is on fire/occupied by poison gas)
Layer 4 (Sparse): Location of Entities

For the most part, the Sparse maps are fairly simple to use Generics for. A HashMap<Position, T> takes care of it. For the Dense map on the bottom, it becomes more difficult to use Generics for, since
T[][] map = new T[x][];
is a violation. However, using ArrayList<ArrayList<T>> leads to problems with replacement/excess size issues. HashMap<Position, T> may work, but again, since there's going to be a static number of values in the map it seems like a waste.

Are there already any 'good', for a given value of good or reason, replacement for dense two-dimensional staticly sized arrays?

Offline Danny02
« Reply #1 - Posted 2012-01-29 18:45:52 »

why do you want to use a generic array anyway. You said that u wanted 1 dens map and then many sparse ones, so having a generic sparse map makes sense.
But why not just have dense map take a class or an interface if you need to
Offline Waterwolf

Junior Devvie

Medals: 3

« Reply #2 - Posted 2012-01-29 19:41:51 »,%20int[])
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline UprightPath
« Reply #3 - Posted 2012-01-30 02:04:00 »

Well, the reason for the generics is because I want to reuse the code that I'm writing for the dense map in other places without having to change it too drastically between uses.

Waterwolf's suggestion should work, better than my current choice (Which is to have an object array and control the insertion/retrieval directly through methods, a la Java's ArrayList).

Pages: [1]
  ignore  |  Print  

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

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

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

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

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

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

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

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

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

Solater (174 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!