Opened 8 years ago
Last modified 5 years ago
#4034 new enhancement
Expose engine constants to random map libraries
Reported by: | FeXoR | Owned by: | |
---|---|---|---|
Priority: | Should Have | Milestone: | Backlog |
Component: | Maps | Keywords: | |
Cc: | Patch: | Phab:D1059 |
Description (last modified by )
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 (13)
comment:1 by , 8 years ago
Summary: | Give some engine parameters to JavaScript shared functions → Expose engine constants to random map libraries |
---|
comment:2 by , 7 years ago
Component: | Core engine → Maps |
---|---|
Description: | modified (diff) |
Milestone: | Backlog → Alpha 23 |
Owner: | set to |
Priority: | Nice to Have → Should Have |
comment:3 by , 7 years ago
These two constants are not engine limits but a choice by the GUI of the launched mod (map_sizes.json
). One can change them in that file and it still works.
const MIN_MAP_SIZE = 128; const MAX_MAP_SIZE = 512;
They are only used here:
function scaleByMapSize(min, max) { return min + (max - min) * (g_Map.size - MIN_MAP_SIZE) / (MAX_MAP_SIZE - MIN_MAP_SIZE); }
If there was a map using these constants as an out-of-bounds check, it would break if the mod changes the mapsize. So no map should refer to these constants.
There are two use cases for mods to change these constants: 1) Use all existing maps but change the mapsize choices 2) Replace all existing maps and change the mapsize choices
For (1), replacing the constants with a reference to map_sizes.json
is wrong, because the numbers passed to scaleByMapSize
are optimized for the current range. Moving 128 and 512 to the scale function would perfectly work for arbitrary mapsizes.
For (2), the map could provide or overwrite the scaleByMapSize
function and be done with it.
So the best solution for the two constants seems to be to inline the magic numbers and explain them.
comment:4 by , 7 years ago
I agree removing MIN_MAP_SIZE
and
MAX_MAP_SIZE
and make the parameters of
scaleByMapSize
optional with the default being 128 to 512.
comment:7 by , 7 years ago
Patch: | → Phab:D1059 |
---|
comment:10 by , 7 years ago
Milestone: | Alpha 23 → Backlog |
---|---|
Owner: | removed |
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.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
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.)
Don't see anything changing angles there. Edit: it's in
getFullEntityList