I'm creating an RPG/simulation game which is similar to the Uncharted Waters Series. The game allows the player to control a fleet to explore and navigate the world on the world map. My Game stores the world map as a tiled map into a 2158 * 1080 2D array.

The problem I'm facing is I want to simulate the ocean currents and trade winds on the world map so when the player is sailing on the map, the speed of the fleet will be affected by the current and the wind. It does not have to be a really accurate simulation because this is not a high-detailed simulation game but it should resonably simulate the ocean currents and the wind.


  • Need to come up with a data structre to represent the ocean currents
  • For each point (x,y) on the map, the data structure should provide a fast way to look up what is the strengh and direction of the current at that particular point
  • The current can have 8 directions (N W S E NW NE SW SE).
  • The strengh of the current is represented as an Int
  • Same requirements for trade wind so I think the solution should be the same

My thoughts:

I'm thinking about dividing the world into several regions and each region can be subdivided into smaller regions like a quad tree. For look up I can do a contains(x,y) and find out which region the point is in and then for sub-regions to the same thing until it arrives a leave of the tree which stores the strengh and direction of the current.

Is that a reasonable solution or there are better ways to do this? What are the gotchas for implementing it?

Thank you for you answers!


1 Answer 1


What I would do is copy Minecraft's habit of adding metadata. Basically, metadata is a method of adding additional data to your tiles (or blocks, continuing the Minecraft explanation) which confers non-essential information (essential information being things like tile type and location). What this would mean is that in the XML file where I presume you are storing your tile data, you would also store the direction (1-8) of your wind and current, and its strength, or possibly aggregate both for a lower memory footprint. You would then load this information at runtime and store it in a 2D array akin to your tile map. As a C++ struct this translates to:

struct MovementMetadata
    int oceanCurrentStrength;
    int tradeWindStrength;
    char oceanCurrentDirection;
    char tradeWindDirection;

Notice that (at least if in C++), your struct or equivalent should have the strengths first, then the directions - this is due to memory alignment issues (data is most efficiently read at boundaries divisible by its size).

  • \$\begingroup\$ I'd say the main advantage of this approach is that you avoid a second (needless) lookup into a possibly gigantic data structure. \$\endgroup\$ Commented Mar 17, 2013 at 23:33
  • \$\begingroup\$ @CongXu Yes, it does - I'll confess though, that didn't cross my mind late at night when I answered this question... I guess I'll just use the acting technique of claiming I meant it. \$\endgroup\$
    – Polar
    Commented Mar 18, 2013 at 17:51
  • \$\begingroup\$ Thank you @Polar! this sounds a good solution. However wouldn't it waste quite a lot of memory because land tiles don't need to store those information? \$\endgroup\$
    – Jackyjjc
    Commented Mar 19, 2013 at 5:03
  • \$\begingroup\$ @QQending The best part about metadata is that it's optional - a bool will suffice to signify if there is metadata, so it is not stored unnecessarily. \$\endgroup\$
    – Polar
    Commented Mar 19, 2013 at 13:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .