Opened 8 years ago

Last modified 5 years ago

#4034 new enhancement

Expose engine constants to random map libraries — at Version 2

Reported by: FeXoR Owned by: elexis
Priority: Should Have Milestone: Backlog
Component: Maps Keywords:
Cc: Patch:

Description (last modified by elexis)

As for example random maps need to take into account some engine parameters it would be nice if some would be added to globalscripts e.g. in a file EngineParameters.js in an dictionary like object g_EngineParameters.

The following parameters are needed by random maps (Most of them allready found at the beginning of library.js):

  • CELL_SIZE = 4 (The width of a terrain texture tile in horizontal engine space units)
  • HEIGHT_UNITS_PER_METRE = 92 (The number of vertical engine space units matching a horizontal engine space unit)
  • MAX_HEIGHT_RANGE = 0xFFFF / HEIGHT_UNITS_PER_METRE (The maximum value for vertical engine space in horizontal engine space units)
  • MAP_BORDER_WIDTH = 3 (The width in )

NOTE: Any space unit will do if the scaling is given as well.

Some other parameters would be nice to also have access to but I'm not sure if they are engine parameters or set in the mods:

  • MIN_MAP_SIZE = 128 (The map width of the smallest map as chosable in mapsetup/Atlas in terrain tiles)
  • MAX_MAP_SIZE = 512 (Same just the largest chosable map size)
  • BUILDING_ORIENTATION = - PI / 4 (The placement angle buildings should be placed by default. For random maps it's rotated and the direction changed, see map.js getMapData)

Other components like simulation/UnitAI/PlayerAI, Atlas might also need some parameters so further comments welcome!

This is basically for reducing hardcoding the same things at multiple places. However, it's also quite vital for mods if build from scratch.

Change History (2)

comment:1 by elexis, 7 years ago

Summary: Give some engine parameters to JavaScript shared functionsExpose engine constants to random map libraries

comment:2 by elexis, 7 years ago

Component: Core engineMaps
Description: modified (diff)
Milestone: BacklogAlpha 23
Owner: set to elexis
Priority: Nice to HaveShould Have

The simulation components are initialized prior to the map generator. So we can simply add getters to the map generator JS interface in MapGenerator.cpp.

MAP_BORDER_WIDTH is a special case because the simulation doesn't have a central place for this yet and instead hardcodes that magic number all over the place, see #4636.

Other components like simulation/UnitAI/PlayerAI, Atlas might also need some parameters so further comments welcome!

For the simulation people already take care not to copy magic numbers and it's easy to access C++ simulation constants from JS simulation components. Not aware of any existing hardcodings in the JS sim.

For atlas, we have

tools/atlas/AtlasUI/ScenarioEditor/Tools/PlaceObject.cpp:static float g_DefaultAngle = (float)(M_PI*3.0/4.0);

Not aware of any other atlas hardcodings. (One might or might not argue it doesn't have to be the same default angle for atlas and random maps.)

the direction changed, see ​map.js getMapData

Don't see anything changing angles there. Edit: it's in getFullEntityList

Last edited 7 years ago by elexis (previous) (diff)
Note: See TracTickets for help on using tickets.