Giter Site home page Giter Site logo

destructors's Introduction

GML2.3 Destructors

This library adds destructors to GameMaker: Studio 2.3's release. This allows you to use ds_* types such as lists and maps inside of structs without fear of leaking memory when they're deleted.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Installation via Local Package (.yymps)

GameMaker Studio 2 allows you to import assets, including scripts and shaders, directly into your project via the "Local Package" system. From the Releases tab for this repo, download the .yymp file for the latest version. In the GMS2 IDE, load up your project and click on "Tools" on the main window toolbar. Select "Import Local Package" from the drop-down menu then import all scripts from the Destructors package.

Installation via Copy/Paste

You can simply copy and paste the contents of Destructors.gml into a new Script in your project.

Usage

Destructors are registered via the dtor_track(type, value, [option]) function. This function can be called multiple times on the same struct instance to registered multiple destructors.

In order to register a destructor callback,

Note that struct members cannot be accessed inside of the callback.

function foo() constructor {
	name = "Zach";
	
	dtor_track(DtorType.Function, function () {
		show_debug_message("Destructed!");
	});
}

var a = new foo();
delete a;           // "Destructed!"

In order to register a destructor to clean an allocated ds_*,

function test1() constructor {
    list = ds_list_create();

    dtor_track(DtorType.List, list);
}

var a = new test1();  // foo.list exists
delete a;             // foo.list has been destroyed

Additionally, Sprite, Surface, VertexBuffer, VertexFormat, Path, AnimCurve and Instance types can be destroyed via dtor_track.

Running the Example

Clone this repo and open and run the project in GameMaker: Studio. Follow the on screen instructions for a demonstration of the library.

Authors

  • Zach Reedy - Developed first implementation. Finalized codebase. - DatZach
  • Juju Adams - Second draft implementation. Examples. - JujuAdams
  • Torin Freimiller - Initial discoveries related to tracking objects. - Nommiin

License

This project is licensed under the MIT License - see the LICENSE file for details

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.