The simulation engine generated by vsTASKER can be controlled from another application using the shared-memory.
Refer to the detailed document in the Developer Guide.
In this sample, the database must match the UI counterpart, on the Catalog side (although this could be automatically done if the UI is able to load the database itself, but this would be more an integration than a connection).
Start vsTASKER and open the database Data/Db/Qt/simple_remote/simple_remote.db
The database seems empty but it contains 3 entities in Catalog (default, car and truck) and one Logic (load) which is attached on the car and truck and displays on the console basic information about the entity (name, position, heading, speed).
Start Qt and load the project in /Runtime/Qt/simple_remote/simple_remote.pro
In Qt, a very simple UI has been design for the purpose of this demo.
On the left, a Catalog list (prefilled) and below, fields to setup the initial values of an entity before instantiation.
On the right, a Runtime list with all instantiated entities and below, the actual values for any selected entity of the list.

to instantiate a new entity if one in Catalog selected and a Name given. If none selected, the button will update the named entity (must be instantiated first).

to delete the selected entity.
To simply connect to the shared memory segment of vsTASKER, one library is enough: vcc_gui.lib. Use the correct one according to your compiler (x86 or x64, vc10 or vc14).
The library vcc_util.lib provides some useful libraries, although it is not mandatory.
Connection
These includes are mandatory for the connection. Runtime.h (refer to the Developer Manual for a detailed description) is also requested by some types and API.
#include "runtime.h"
#include "shdmem.h"
#include "shmcomm.h"
|
These pointers give access to some specific segments of the shared memory.
The classes are defined in shmcomm.h.
RtcSharedMem* rtc_shm = NULL;
UpdSharedMem* upd_shm = NULL;
ShmKeyList shm_keys; // all shared-memory keys used. Def in shdmem.h
RtEvents gui_events; // gui -> sim
RtEvents sim_events; // sim -> gui
RtEntities rtent_pool; // sim <-> gui
RtSharedMem shared_memory;
|
Now, let's connect these pointers to the shared memory. If not created, the initSharedMem call will create, otherwise, it will simply connect to.
// get the access key
int shmkey;
if (getenv("VST_RTC_SHMKEY")) shmkey = strtol(getenv("VST_RTC_SHMKEY"),0,16);
else shmkey = VST_RTC_SHMKEY;
// Create/Connect the shared memory
rtc_shm = (RtcSharedMem*) shared_memory.initSharedMem(shmkey, sizeof(RtcSharedMem));
shm_keys.add(shmkey, "rtc", (long)rtc_shm);
if (!rtc_shm->sim_mode) rtc_shm->sim_mode = RTC_Idle;
rtc_shm->gui = ON;
// get the access key
if (getenv("VST_UPD_SHMKEY")) shmkey = strtol(getenv("VST_UPD_SHMKEY"),0,16);
else shmkey = VST_UPD_SHMKEY;
// Create/Connect the shared memory
upd_shm = (UpdSharedMem*) shared_memory.initSharedMem(shmkey, sizeof(UpdSharedMem));
shm_keys.add(shmkey, "upd", (long)upd_shm);
upd_shm->entities.on = true;
// Runtime Moving Entities dynamic shared-memory segment
if (!rtent_pool.initialized()) rtent_pool.init(upd_shm, 100); // 100 slots
// SIM -> GUI Runtime Event dynamic shared-memory segment
if (!sim_events.initialized()) sim_events.init(upd_shm, "sim", 50); // 50 slots
// GUI -> SIM Runtime Event dynamic shared-memory segment
if (!gui_events.initialized()) gui_events.init(upd_shm, "gui", 10); // 10 slots
|
The UI will send commands by using a unique function with a specific data structure defined in runtime.h
The list of all commands is available in the Developer Manual.
Let's see here how to create an entity using a remote command, and how to set speed and heading.
How to create an entity from a remote command.
EvtData edata; // the main structure. ill use the new_ent union part
WCoord npos(WC_LLA, lat, lon, 0); // position of the entity on the gaming area
npos.convertToXYZ(); // must be converted into XYZ
strcpy(edata.new_ent.base, "Entity"); // class name (see Entity classes)
strcpy(edata.new_ent.catg, "car"); // catalog name
strcpy(edata.new_ent.name, "my car"); // name of the instance
edata.new_ent.x = npos.x; // position x
edata.new_ent.y = npos.y; // position y
edata.new_ent.z = 0; // altitude
// Send the event to the sim
gui_events.push("_NewEnt", "", edata);
|
How to change the speed of a runtime entity
How to change the altitude of a runtime entity
The simulation engine can also send messages to the remote UI. These messages can result of UI commands but also from the normal course of the simulation.
The UI must react to the most important of them in order to remain in sync with the engine.
New entity creation
Entity deletion