For other modders
Picture sources for the tablet Changed
Since 3.1.0 the tablet shows more than a SOFLAM. A mod that has a camera on a drone or a vehicle registers a picture source, and the tablet gives it the screen, the zoom, the thermal and night vision, the heads-up display, the settings menu and the full-screen control. This page is the whole contract.
What you get, and what you provide
The tablet already does everything that is the same for every source: the list in the source menu (TAB → Source → UAV or UGV), the camera on the screen with the same five-step zoom as the SOFLAM, night vision and thermal with every palette and window of the GTG Thermal Framework, a HUD with compass, horizon and status lines, the settings menu, and the full-screen control with mouse, W A S D or the right stick. A source provides three things:
The class is GTG_SOFLAM_TabletFeedSource. You derive from it and override what you can; everything you leave out stays off, and the screen drops the matching field. That is how one HUD fits a drone with missiles and a ground vehicle with none.
The registry of sources is GTG_SOFLAM_TabletSources. Register once at game start, on every machine: the source runs on the viewer’s machine, because that is where the tablet is.
class MyBridge_DroneSource : GTG_SOFLAM_TabletFeedSource
{
protected IEntity m_Drone;
override GTG_ETabletSourceKind GetKind() { return GTG_ETabletSourceKind.UAV; } // or UGV
override string GetTitle() { return "MY DRONE"; }
// asked often (the list and every frame): keep it cheap. false ends a running picture cleanly
override bool IsAvailable() { return m_Drone != null; }
// mat[3] = position, mat[2] = viewing direction. false = no position, the picture stays as it is
override bool GetCameraTransform(out vector mat[4])
{
if (!m_Drone)
return false;
m_Drone.GetWorldTransform(mat);
return true;
}
override void FillStatus(GTG_SOFLAM_TabletFeedStatus status)
{
status.m_sTitle = "MY DRONE";
status.m_fAltitude = m_Drone.GetOrigin()[1];
status.m_iSignal = 5; // 0..5 bars, -1 = hide
status.m_sLinkName = "SATCOM";
}
}
// at game start, on every machine:
GTG_SOFLAM_TabletSources.Register(new MyBridge_DroneSource());
Register ignores the same instance twice. A source is a plain script object, not an entity: it is yours to create when your drone appears and to Unregister when it is gone.
The hooks
| Hook | What it is for |
|---|---|
GetKind(), GetTitle() | Which tile of the menu the source appears on (UAV or UGV), and its name in the list. With several sources in the air, the blue LINK key switches between them. |
IsAvailable() | May this player see the source now? Asked often. false ends a running picture. |
GetCameraTransform(out vector mat[4]) | Where the camera stands and where it looks. |
OnFeedStart(), OnFeedStop() | The viewer starts or stops looking. Ask for the streaming of the area around the camera here and give it back. |
FillStatus(status) | The values of the HUD, asked every frame. Only changed texts are rewritten. |
GetSettings(list), OnSettingChanged(setting), OnAction(id) | The settings menu and what a change does. |
SupportsPointCommands(), OnPointPicked(action, worldPos) | May the player pick a point in the picture (“look” = hold the camera there, “orbit” = a new circle point)? The tablet remembers the last point (RememberPoint, GetLastPoint). |
OnFeedUpdate(dt) | Every frame while the picture is open. A source can hold its remembered point here. |
GetZoomLevels(levels), GetDefaultZoomLevel() | Your own zoom steps, ascending (the drone: 2, 5, 10, 20, 30, 40, 50). Left empty, the five steps of the SOFLAM apply, up to 20x. |
GetViewRange() | How far objects are drawn in the picture, see below. Default 3000 m. |
IsCameraLocked() | true while the camera belongs to the source itself (a drone that attacks and guides its ball). The tablet then shows the real view, and point commands rest. |
ShowsContacts() | Should the tablet mark enemies and own forces in this picture? See below. |
PopMessage() | The source puts a line in m_sMessage (“Return home ordered”); the tablet asks for it once per frame and shows it in its message line. |
Settings
A source fills a list of GTG_SOFLAM_TabletSetting each time the menu opens and after every change. Six kinds exist, each with a factory method:
| Kind | Factory | How the player uses it |
|---|---|---|
| Step | Step(id, label, value, min, max, step, unit) | Left and right change the value by one step. |
| Number | Number(id, label, value, min, max, step, unit) | A window opens; the player types digits with the keys 0 to 9. Minimum and maximum show as a hint, the value is rounded to the step. Made for an altitude. |
| Toggle | Toggle(id, label, on) | On / off. |
| Choice | Choice(id, label, choices, current) | A pick from a list, for example the attack mode. |
| Digits | Digits(id, label, text, digits) | A row of digits, 1 to 8 per place, for a laser code. |
| Button | Button(id, label, confirm) | An action. With text in confirm the player has to press ENTER a second time (“Return to home”). |
A setting can be shown but not changeable: m_bEnabled = false (the laser code while laser on call is off). The menu shows (NOT NOW) behind it. Labels are English and short.
override void GetSettings(notnull array<ref GTG_SOFLAM_TabletSetting> list)
{
list.Insert(GTG_SOFLAM_TabletSetting.Number("altitude", "ALTITUDE", m_fAltitude, 100, 3000, 50, "M"));
list.Insert(GTG_SOFLAM_TabletSetting.Button("return_home", "RETURN HOME", "RETURN HOME?"));
}
override void OnSettingChanged(GTG_SOFLAM_TabletSetting setting)
{
// the new value is already in the object; carry the command to the server
if (setting.m_sId == "altitude")
MyBridge_Send(MyCommand.ALTITUDE, setting.m_fValue);
}
override void OnAction(string id)
{
if (id == "return_home")
MyBridge_Send(MyCommand.RETURN_HOME, 0);
}
Commands go to the server through your own relay
Everything in a source runs on the viewer’s machine. The tablet belongs to the player, the drone does not. A client that does not own the drone cannot send an RPC on it: the server drops it silently. This is the lesson of Who may send once more, and the answer is the same: send
through the player’s own character, and let the server find the drone by its RplId.
modded class SCR_CharacterControllerComponent
{
[RplRpc(RplChannel.Reliable, RplRcver.Server)]
void MyBridge_RelayCommand(RplId drone, int command, float number)
{
// on the server: resolve the drone, check the command, then do it
IEntity entity = IEntity.Cast(Replication.FindItem(drone));
if (!entity)
return;
MyBridge_Execute(entity, command, number);
}
void MyBridge_SendCommand(RplId drone, int command, float number)
{
Rpc(MyBridge_RelayCommand, drone, command, number);
}
}
The server must check what arrives: range of the number, whether the command is allowed now. The tablet shows a value as soon as the player changes it, but the drone is the source of truth. The drone bridge shows the changed value for a few seconds and then reads the real one back.
The area around the camera must exist on the viewer’s machine
EnableSpatialRelevancy(true) and EnableStreamingConNode(identity, false) on its RplComponent), from the moment it spawns and for players that join later. Do it for the one drone only; it is a single object. The AH-64 mod does the same for the operator’s character.Units far from the viewerNew
The drone is one object and easy to keep. The soldiers and vehicles in its picture are not: they can be kilometres from the player with the tablet, the game does not stream them to him, and the picture shows empty ground. Since 3.1.1 the Core does three things, all of them only while a picture is open.
- The server holds what the camera sees. Every 1.5 seconds the tablet sends the camera position, the viewing direction, the width of the field of view and the observed point to the server, through the relay of the player’s character (unreliable, a lost message heals with the next). The server queries soldiers and vehicles in a sphere around the observed point, keeps those inside the view cone with
EnableStreamingConNode(identity, false)for this player only, and lets go withtruethree seconds after they leave the picture. At most 80 objects per player. A request expires after 5 seconds without a message (picture closed, connection gone), and the message that ends the picture releases everything at once. - Observers stand at the observed point. The engine simulates soldiers and vehicles only near observers (cameras and players). The drone camera is a camera of the tablet and does not count. Our working explanation, which fits what we saw but is not proven: what arrives far from every observer arrives half made, without
VISIBLEandACTIVE, soldiers drawn as arms and heads only, a truck without its cargo bed, an armoured vehicle without wheels. AI agents are even switched off at the highest level of detail (AIAgent: “AIAgents get disabled in MaxLOD by default”; the vanilla AI group comments give about 1000 m to the nearest observer as the default). So the Core registers observers withObserversSystem: one local at the observed point, one far observer along the sight line (the call a scope or binoculars make every frame), and one on the server for the player’s connection. All three are removed when the picture ends. What they achieve: the AI agents in view run (level 0, active) about two seconds after the picture opens. On their own they did not complete the drawing of the soldiers; that took step 3. - The tablet wakes what arrives. Every half second, on the viewer’s machine, for the soldiers and vehicles in the observed sphere:
VISIBLEandACTIVEon the root if one is missing,Update(), a physics body that sleeps is set active, and the pose of the skeleton is requested by reading a bone matrix.
// client: the observed point, with every request (1.5 s)
ObserversSystem observers = ObserversSystem.Cast(GetGame().GetWorld().FindSystem(ObserversSystem));
observers.InsertObserverSP(KEY, point[0], point[2], null);
// client: every frame, from the camera of the source (like SCR_2DOpticsComponent.UpdateFarObserver)
observers.AddFarObserver(viewer, tabletEntity, cameraPos, viewDirection, viewRange, timeSlice);
// server: with every request, for this player's connection
observers.InsertObserverMP(identity, point[0], point[2], null);
// the end of the picture: RemoveObserverSP(KEY), DelFarObserver(), RemoveObserverMP(identity)
// client, every 0.5 s, for each soldier and vehicle (root entity) in the observed sphere
if ((entity.GetFlags() & needed) != needed)
entity.SetFlags(needed, false); // VISIBLE | ACTIVE -- the root only
entity.Update();
Physics physics = entity.GetPhysics();
if (physics && !physics.IsActive())
physics.SetActive(ActiveState.ACTIVE);
// reading a bone matrix makes the engine compute the pose
Animation anim = entity.GetAnimation();
TNodeId head = anim.GetBoneIndex("Head");
if (head >= 0)
anim.GetBoneMatrix(head, mat);
Update() and the physics alone changed nothing, and neither did the bone read alone. Why the three work together is not understood; the code keeps all of them and says so.What does not work, so you can spare yourself the detour:
| Tried | Result |
|---|---|
VISIBLE on all children of every soldier and vehicle | Soldiers appeared, but so did things that are hidden on purpose: an ambulance stood in a large grey cylinder, the area mesh of its support station (SCR_SupportStationAreaMeshComponent). Touch the root only. |
AIAgent.PreventMaxLOD | Does nothing for an agent that is already on the highest level (the API says so). |
SetPermanentLOD(0) and ActivateAI() on every agent in view | The agents were switched off again before the next request. The observers fixed it: the agents stood on level 0, active, about two seconds after the picture opened. |
The SET_RENDERED flag on all children, the third-person animation layer, the Object Draw Distance and Geometric Detail settings | No effect. The flag stays set, the picture does not change; the settings were already at their maximum and their limits cannot be read from script. |
| Flying lower, zooming, waiting | No difference: it is not the distance to the camera. |
RplComponent.InsertMPObserver | Obsolete. Use ObserversSystem.InsertObserverMP. |
A Game Master as the operatorNew
When the Game Master opens the editor, the game streams all editable entities to him. When he closes it, SCR_DynamicSimulationEditorComponent.EOnEditorDeactivateServer calls EnableStreamingConNode(identity, true) for all of them and so cancels every “never stream out” you set. A drone that flies outside the streaming range disappears from his machine, the source unregisters, and the tablet says NO FEED. The client log shows it: the drone is created on his machine exactly when he opens the editor, and gone when he closes it.
The Core keeps its sources: it overrides the one function that frees an entity and leaves it out for entities that carry the component of a known source. The component is looked up by name ("UAV_OrbitComponent".ToType()), so the Core compiles without the drone mod and does nothing when it is absent.
modded class SCR_DynamicSimulationEditorComponent
{
override protected void EnableStreamingForEntity(SCR_EditableEntityComponent entity, bool enable)
{
if (enable && entity && GTG_SOFLAM_StreamKeep.IsKept(entity.GetOwner()))
return; // a picture source stays streamed
super.EnableStreamingForEntity(entity, enable);
}
}
If your source holds its entity with EnableStreamingConNode(identity, false), do the same after the editor closes. The same trap applies to anything you stream for a Game Master who also uses the editor, and to the units the Core holds for the picture: it sets the flag again with every request.
Where the camera looks firstNew
When a picture of a source with point commands is opened for the first time, and the player has not chosen a point yet, the tablet looks for a default: for a drone the centre of its circle, the loiter point. The Core finds the drone by the camera position (a 15 m sphere around it), its orbit component by name, and reads the centre by reflection, because the field is protected (typename.GetVariableValue). The source then holds the point like any remembered point. After that the camera stays on the point the player used last.
For your own source: set it in OnFeedStart, when nothing has been remembered.
override void OnFeedStart()
{
vector known;
if (!GetLastPoint(known))
RememberPoint(MyDefaultPoint()); // the camera looks here at the first opening
}
View range: what the drone sees, not how far it may look
GetViewRange() (default 3000 m) is how far objects are drawn in the picture. While the picture is open, the tablet raises the game’s view distance to that value and sets the far plane of the camera; when the picture closes, it gives the player’s own setting back. It is not a limit for the
distance between tablet and drone, and not a limit for the point that is observed.
What the tablet draws for you
- Laser spots. Every point in the registry is drawn as an upright diamond line with its code to the right: green when the code equals
status.m_sLaserCodeof the source, red for any other code. Fill the field, and the marks follow. - Contacts (
ShowsContacts()returnstrue). The tablet scans the units near the camera on the viewer’s machine: enemy infantry and vehicles are red, own forces blue (your faction) and green (your group). Enemy infantry forms a group when it stands within 10 m of the centre of that group, labelled INF 3; vehicles are labelled VEH. (Until 3.1.0 neighbours were chained, A near B, B near C, and squads standing next to each other merged into one marker such as INF 18.) The scan runs on the viewer’s machine and sees what is loaded there. There is no line-of-sight check: a unit behind a wall can be marked. - Map markers. The player can have the enemies a source sees put on his map, refreshed every 15 seconds (Settings → Auto map marking, off by default, local to him). The markers in the picture do not depend on it.
- Grid readout. Under the range the tablet shows the point under the crosshair as
GRID 01305 02817 ELEV 38 M: world X and Z in whole metres, five digits per axis (a 1 m raster; the first three digits equal the 100 m grid of the map), and the terrain height. It is meant to be read out for a fire mission.
Pitfalls
| Symptom | Cause | Fix |
|---|---|---|
| The list shows no source | Not registered on this machine, or IsAvailable() returns false. | Register on every machine, not only on the server. Check what IsAvailable() tests. |
| The picture shows nothing but sky and the HUD works | The drone is not streamed to this client. | Force the streaming (see above). |
| A command changes nothing | It was sent on an entity the client does not own: the server drops it silently. | Send through the player’s character. |
| The HUD lacks a field | The field stayed at its default, and the HUD drops it on purpose. | Set it in FillStatus. |
| The setting jumps back | The tablet shows the new value, then the source reads the old one from the drone. | Hold the pending value for a few seconds, as the drone bridge does, until the drone has confirmed it. |
| The menu is slow | FillStatus and IsAvailable are asked every frame. | Do no searches in them; keep the entities in fields. |
| Soldiers in the picture are only arms and heads, a truck has no cargo bed | The units are far from every observer and arrive half made. | Observers and the wake-up of the roots (see Units far from the viewer above). |
| The tablet says NO FEED for a Game Master right after he closed the editor | The editor frees every editable entity to stream out, and the drone is gone from his machine. | Keep the source streamed after the editor closes (see A Game Master as the operator). |
| A large grey cylinder (or another helper) stands around a unit in the picture | VISIBLE was forced on all children, including those that are hidden on purpose. | Touch the root only. |