Strategic Icon Internals

From Planetary Annihilation Titans & Classic PA Wiki
Jump to navigation Jump to search

Titans-icon.png Strategic Icon Internals

Most of the internal implementation details are speculation by wondible.

Strategic icons are based on a few related features: a 1xN texture mapped from an icon atlas HTML output, an icon list that associates icon names with each index in that texture, and shaders that render the specified section of the texture.

Platinum-rank-icon.png Icon Texture

The image created by the HTML page in an icon atlas is captured by the game used as a texture map. The image updates while the game runs (in earlier versions of PA, the image would cease updating if the icon list was updated). The game organizes the icons in a one-wide by N-high arrangement. (2D grids are possible with matching shader changes, but this appears to offer no benefits.)

Platinum-rank-icon.png Icon Limit; Black Squares

The size of the icon texture appears to be limited by the system's graphics hardware. If too many icons are added, all icons will become black squares. Most systems will cap out at 315 icons; 315x52 is suspiciously close to 2^14, which is why a hardware limit is suspected. Some systems have issues at half that size, max 158 icons.

The WebGL render buffer size appears to correlate with this limit, and can be used as an indicator of the system's icon limit. Sample detection code:

var canvas = document.createElement('canvas')
var gl = canvas.getContext("webgl");
gl.viewportWidth = canvas.width;
gl.viewportHeight = canvas.height;
var max_renderbuffer_size = gl.getParameter(gl.MAX_RENDERBUFFER_SIZE)
var maxIcons = Math.floor(max_renderbuffer_size / 52)
gl = canvas = undefined

Platinum-rank-icon.png Icon List

The engine call handle_icon_list sends an array of icon names the engine, along with the icon size (width and height, since there is only one number, icons must be square). The position of each name corresponds to the position of the in the icon texture (atlas page)'handle_icon_list', list, 52);

The engine appears to enter these names into a name-to-index map in order to associate the unit name or si_name with the proper icon index or texture offset (we aren't really sure which it stores) Name-to-index lookups are preformed at unit creation time which means that once a unit is exists, it's icon index is locked. Thereafter, the unit will reflect changes in the icon texture at that index/offset, but will not respond to changes in the icon list.

Empirically, the name-to-index map is not re-initialized each time handle_icon_list is called. This means that is possible to create alias names for an index/offset by sending the icon list multiple times. Each name will then lookup to the same icon index, and have the same icon image in-game.

Platinum-rank-icon.png Icon Shaders

Platinum-rank-icon.png particle_icon.vs

Decodes the texture-encoded icon data, calculates the current screen position, and applies the icon-specific texture offset into the icon texture.

Still supports a global icon scale parameter, which is not currently exposed in the UI settings.

Platinum-rank-icon.png particle_icon.fs

Looks up the master icon texture data, and maps specific colors to primary and outline colors. Secondary player color is available but unused. Also uses encoded state data to apply the currently-selected-units icon color effect.