← Home SEEBIE90 DOCS
Download PDF
The GTG Thermal Framework mod is published under the Arma Public License (APL)Example code is free to useSuggestions: Discord to the author

Build it into your mod

Several displays, one state

A player looks through a sight, puts it down and watches the same picture on a screen. The mode should not jump back. And a screen shows a camera that is not the player’s.

In plain wordsA sight, a handheld screen and a remote camera can all use the same component. The mode, palette and gain are shared; each display keeps its own temperature window. You can also draw your own readout.

The shared state

Mode, palette, night-vision gain and zoom are the same everywhere for one player. Whoever leaves a sight in thermal continues in thermal on the screen. The state is one static class, local to each client. It is written only by a real operation – a key, the wheel, a menu – never by the reset that happens when a sight is left. Otherwise the shared state would be gone after every use.

Example code – free to useGTG_SOFLAM_VisionShared.c (excerpt)
class GTG_SOFLAM_VisionShared
{
	protected static bool s_bModeSet;
	protected static int  s_iMode;
	protected static int  s_iGain = -1;			// -1 = never set by hand
	protected static int  s_iPalette;
	protected static int  s_iLevelSight = -1;	// -1 = never set by hand: the infantry window of the time of day
	protected static int  s_iLevelTablet = -1;
	protected static int  s_iZoom = 1;

	static int GetMode()     { return s_iMode; }
	static void SetMode(int mode) { s_bModeSet = true; s_iMode = mode; }
	static int GetPalette()  { return s_iPalette; }
	static void SetPalette(int palette) { s_iPalette = palette; }

	// the temperature window is per DISPLAY: tablet = true for the screen, false for the sight
	static int GetLevel(bool tablet)  { if (tablet) return s_iLevelTablet; return s_iLevelSight; }
	static void SetLevel(bool tablet, int level) { if (tablet) s_iLevelTablet = level; else s_iLevelSight = level; }
}
SharedPer display
Vision mode, palette, night-vision gain, zoomThe temperature window. A sight and a screen can look at different slices of the range at the same time.

When a view is entered, GTG_ApplyShared() reads the state: palette and window first, because switching to thermal reads them when it turns the effect on.

A camera of your own

By default the effects go on the camera the player sees through. A remote screen, a drone feed or a tablet has a camera of its own, and the picture there should be tinted while the world around the player is not. Tell the component which camera that is with SetTargetCamera(index); a negative index means the player camera again. This is the real setup of the SOFLAM tablet, shortened and with neutral names:

Example code – free to useMyOptic_Feed.c (pattern from the SOFLAM tablet)
protected static const int MYOPTIC_FEED_CAMERA = 28;		// pick an index others do not use

protected void MyOptic_StartFeed(BaseWorld world, RenderTargetWidget feed, GTG_SOFLAM_VisionModeComponent vision)
{
	ScriptCamera camera = ScriptCamera.Cast(GetGame().SpawnEntity(ScriptCamera, world));
	camera.Index = MYOPTIC_FEED_CAMERA;

	world.SetCameraVerticalFOV(MYOPTIC_FEED_CAMERA, 5.7);
	world.SetCameraNearPlane(MYOPTIC_FEED_CAMERA, 0.3);
	world.SetCameraFarPlane(MYOPTIC_FEED_CAMERA, 4000);

	feed.SetWorld(world, MYOPTIC_FEED_CAMERA);		// the widget shows this camera

	vision.SetTargetCamera(MYOPTIC_FEED_CAMERA);	// effects now go on THIS camera
	vision.SetInputEnabled(true);					// keys active while the feed runs
}

protected void MyOptic_StopFeed(GTG_SOFLAM_VisionModeComponent vision)
{
	vision.SetInputEnabled(false);
	vision.SetTargetCamera(-1);						// back to the player camera
}

The component remembers the camera index it used when it switched an effect on and clears exactly that one when it switches it off. See the camera-id trap on Night vision and the infrared gate.

Full screenSetFeedFullscreen(true) says that the feed covers the whole screen. Only then may night vision on that feed make infrared light visible: otherwise the player would see an infrared beam in the world with the naked eye while looking at a small screen.

Your own readout

The framework draws nothing. A sight decides where and whether it shows the mode. What it offers is a small set of questions, cheap enough to ask on every refresh of your display:

MethodAnswer
GetVisionMode(), GetVisionModeLabel()The mode as enum, and as short text: NORM, NV, THER.
HasThermalInfo()true only in thermal and only with the built-in materials: a list of your own materials has no windows to show.
GetThermalPaletteName()WHITE HOT, BLACK HOT, IRONBOW, RAINBOW.
GetThermalWindowMin(), GetThermalWindowMax()The window in degrees Celsius, already on the calibrated scale.
GetThermalWindowTag()WIDE, INF, VEH or empty.
GetThermalRampTexture()The colour ramp of the current palette, for a colour bar: left = lower limit, right = upper limit.
GetThermalInfoKey()One number from palette and window. Ask it every refresh and redraw only when it changed.
GetGainValue()Since 1.1.0. The current night vision gain, the value that sits on the camera as its brightness. Only meaningful in night vision; it returns 1 when no gain steps are set.
GetGainFraction()Since 1.1.0. The gain step as a number from 0 (weakest step) to 1 (strongest), made for a bar or a row of cells.
GetOnVisionModeChanged()A ScriptInvoker that fires with (component, newMode) on every mode change, so that a display need not ask every frame.
Example code – free to useMyOptic_ReadoutComponent.c
class MyOptic_ReadoutComponent : ScriptComponent
{
	protected GTG_SOFLAM_VisionModeComponent m_Vision;
	protected TextWidget m_wText;
	protected int m_iShownKey = -1;

	// called from your refresh, e.g. a few times per second while the display is visible
	protected void MyOptic_Refresh()
	{
		if (!m_Vision || !m_wText)
			return;

		if (!m_Vision.HasThermalInfo())
		{
			m_wText.SetText(m_Vision.GetVisionModeLabel());
			m_iShownKey = -1;
			return;
		}

		int key = m_Vision.GetThermalInfoKey();		// palette * 100 + window: changes only when something changed
		if (key == m_iShownKey)
			return;

		m_iShownKey = key;
		string tag = m_Vision.GetThermalWindowTag();
		m_wText.SetText(m_Vision.GetThermalPaletteName() + "  " + m_Vision.GetThermalWindowMin() + "-" + m_Vision.GetThermalWindowMax() + " C  " + tag);
	}
}
Stale readoutsGetThermalInfoKey() also lets the infantry window follow the clock: while nobody set a window by hand, it moves to the window of the new time of day when you ask. If your display only redraws on an event, it never sees that change. Ask the key on a timer, and redraw when it differs. A screen that is drawn into a render target and only redrawn when its content changed needs the key in its change signature, or the readout stays stale.
Example code on this page is free to use in your own projects (credit appreciated). The GTG Thermal Framework mod is published under the Arma Public License (APL). Suggestions: Discord. Arma Reforger / Enfusion are trademarks of Bohemia Interactive.
Impressum · Privacy Policy