I am pleased to publish a solution to define global data within Outerra with the ability to write and read them from any vehicle or aircraft model file in Javascript.
Obviously you must use the C ++ language and create a DLL.
I state that I am not a C ++ expert at all.
I only paused to read some manuals and learned the grammar of the language and some rudiments ...
The great fortune was the willingness of Microsoft to make available, for free, the possibility of using Visual Studio at a basic level (and without time limitations) and, above all, the publication of the Example_Plugin of our "great" Uriah (it will not be never thanked enough).
Having this complete and fully functional solution available, it is quite simple to add functions, compile everything, copy the Dll to the program's "plugins" folder and use the new functions by calling them from Javascript.
We think, for example, that we want to have global variables available, useful for transferring data between models, that represent "flags" (integers), numbers (double) and positional data (pos).
Possibly also other data, of any other type ...
In Visual Studio we add, in the
plugin.hpp file, the declaration of functions:
ifc_fn int read_flag( int index);
ifc_fn double read_dat(int index);
ifc_fn double3 read_pos(int index);
ecc..ecc...
ifc_fn void wri_flag(int flag, int index);
ifc_fn void wri_dat(double dat, int index);
ifc_fn void wri_pos(double3 pos, int index);ecc..ecc...
Then, in the
plugin.cpp file we declare the global data Arrays (for example 100 variables per type):
int Global_flag [100];
double3 Global_pos [100];
double Global_dat [100];etc. etc...
(It is useful to declare Arrays because we will retrieve the data by means of their index.)
Then we define the functions (always in
plugin.cpp)
//Function read_flag
int example_plugin::read_flag(int index) {
return Global_flag[index];
}
//Function read_dat
double example_plugin::read_dat(int index) {
return Global_dat[index];
}
//Function read_pos
double3 example_plugin::read_pos(int index) {
return Global_pos[index];
}
ecc..ecc...
//Function wri_flag
void example_plugin::wri_flag(int flag,int index) {
Global_flag[index]=flag;
}
//Function wri_dat
void example_plugin::wri_dat(double dat,int index) {
Global_dat[index]=dat;
}
// Function wri_pos
void example_plugin::wri_pos(double3 pos,int index) {
Global_pos[index]=pos;
}ecc.. ecc...
At this point, in Javascript, we call our plugin interface (within the function init_vehicle () or initialize ()):
$plugin = this.$query_interface('my::js::example_plugin_interface.get');Within the update_frame () function we can write or read the value of our global variables with these commands:
$plugin.wri_flag(val,index);
$plugin.wri_dat(val,index);
$plugin.wri_pos(val,index);
val=$plugin.read_flag(index);
val=$plugin.read_dat(index);
val=$plugin.read_pos(index);
Extremely simple ...
So simple that it will make C ++ experts smile for its elementality.
But ... it's not my intention to do programming lessons ...
Simply share a possibility that can widely expand the interaction between the models and their playability.
Since, then, "the appetite comes with eating", once experienced the mechanism ... we will surely want to add more functions, commonly used or personal, that we will always have available.
I hope I have done something pleasant.