Giter VIP home page Giter VIP logo

async_load's Introduction

Async Load

This crate contains functionality to trigger GMS2 async events and pass data into them by using a ds_map structure inside a global async_load variable.

About

GMS2 (Game Maker Studio 2) is an engine for building games on all kind of platforms that uses GML (Game Maker Language).

It's possible to enhance its functionality with extensions (custom libraries).
This crate helps with building one that can "call GML from Rust".

How To Use

In order to be able to perform any kind of operation, it's necessary to define an external RegisterCallbacks function.
It can be found in src/lib.rs.

To activate it simply enable the extension feature:

[dependencies.ds_map]
version = "1.0.2"
features = [
    "extension",
]

(You can also keep the feature disabled and define RegisterCallbacks manually)

Then while inside of your GMS2 project, open your extension and add a new function as seen on the image bellow:

Do not call this function, it will be executed automatically by the GMS2.

This will register all the necessary callbacks and allow you to use the DSMap structure.

Example

Rust:

#[no_mangle]
#[allow(non_snake_case, unused_variables)]
pub unsafe extern "C" fn MyFunction() -> GMLDouble {
    use std::thread::*;
    use std::time::Duration;

    // Spawn new thread.
    spawn(|| {
        // Wait for 1 second.
        sleep(Duration::from_secs(1));

        // Create and dispatch the map.
        let mut map = DSMap::new();
        map.add_double("key1", 21.37);
        map.add_string("key2", "Hello from Rust!");
        map.dispatch(EventType::Social);
    });

    GMLDouble::none()
}

GMS2 object Create event:

show_debug_message("[*] Start");
MyFunction();
show_debug_message("[*] Finished");

GMS2 object Async - Social event:

show_debug_message("[*] Async - Social");
show_debug_message(async_load[? "key1"]);
show_debug_message(async_load[? "key2"]);

Output:

[*] Start
[*] Finished

(...) <some other info>

[*] Async - Social
21.37
Hello from Rust!

async_load's People

Contributors

fssay avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.