GMS 2 Accessing/Modifying values of extensions with best performance

Mert

Member
Hi.

As of now, I have developed my Firestore extension and it is ready to be published(Free and Open Source as usual).

My issue is that I am not sure if it's performance efficient with the way it works, unfortunately. One example would be query operations. In Java, a programmer can simply do the following code to query the database:

I am putting different parts together here to show it as simple as possible
Code:
private FirebaseFirestore db;
//...
db = FirebaseFirestore.getInstance();
//...
//Query smthing
db.collection(argument).whereGreaterThan(argument, argument).limit(argument).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() //....(and it is followed by things etc.)

In game maker, it is a bit different. Now, I have two options:
  • I can craft a long string/JSON string in Game Maker and pass it to the extension, then I'll parse this string to fill the blanks. In this case, overhead is on actually creating the data on Game Maker and passing to to extension, parsing the data & putting them in a switch case to determine what they mean. (Also remember that I'd have to change their datatypes from string to int, double etc(If it's a plain string))
In Game Maker, it would look like this(JSON string example):

Code:
var a = ds_map_create();
var b = ds_list_create();
ds_list_add(b,"whereGreaterThan","song_length",180); //Longer than 180 seconds.
var c = ds_list_create();
ds_list_add(c,"whereEqualTo","song_artist","Phil Collins"); //Only query his songs.

//Now add the lists to the map.
ds_map_add(a,b);
ds_map_add_list(a,"query0",b);
ds_map_add_list(a,"query1",c);
ds_map_add(a,"limit",10); ///Only get 10 songs of him.
ds_map_add(a,"collection","good_songs"); //from this collection
var str = json_encode(a);
passToExtension(str);
  • Second option is to create a global variable in extension(in this case, it's java), and fill it with functions from Game Maker (I use this one)
Code:
query_create();
query_whereGreaterThan("song_length",180);
query_whereEqualTo("song_artist","Phil Collins");
query_limit(10);
query_finish();

In the extension, I tie this data as:
Code:
///...
public static Query QUERY_REF = null;

///...
public void query_whereGreaterThan(String arg0, double arg1) {

        QUERY_REF = QUERY_REF.whereGreaterThan(arg0, arg1);
    }

///...
public void query_limit(double arg0) {

        int val = (int) arg0;
        QUERY_REF = QUERY_REF.limit(val);

    }
///... etc
Now the issue is, I don't know whether this is performance efficient. My previous Firebase extensions work exactly like the second option. I am looking for the best solution. Any strategies, any tactics are appreciated.
Thanks.
 
Last edited:

Mert

Member
#Update (on HTML5 extensions)

Passing a reference to a ds_list to Javascript actually passes its reference. You can directly access to a ds_list from Javascript. Example

In Game Maker
Code:
var list = ds_list_create();
ds_list_add(list, "hello","hi","what");

passToJavascript(list);
In Javascript
Code:
function passToJavascript(list) {

var size = GMS_API.ds_list_size(list);

for (var i = 0; i < size; i++)
        {
            var value = GMS_API.ds_list_find_value(list, i);
        }
}
I will check if we have more functions like GMS_API.ds_list_create, which allow us to create ds_list from Javascript and pass its reference to Game Maker.

--

You can also pass ds_map to Javascript in the same way.

In Game Maker
Code:
var map = ds_map_create();
map[? "hello"] = "World";
map[? "yo"] = "Hey man!";

passToJavascript(map);
In Javascript - Receive ds_map
Code:
function passToJavascript(map) {

//Converts it to JSON string
var JsonString = GMS_API.json_encode( map);
//Converts it to Javascript Object
var JsonObj = JSON.parse( jsonString );

//Access to a value in our (what previously was ds_map)
var Hello = JsonObj.hello;

}
In Javascript - Send ds_map (To Social Async Event)
Below code is from my Firestore Database Extension
Code:
var map = {};
    map["id"] = FIREWEBASYNCID;
    map["category"] = docCategory;
    map["location"] = docLocation;
    map["status"] = docStatus;
    GMS_API.send_async_event_social(map);
 
Top