MZ How does the Engine work?

This is more of a general question, but i wanted to know how the main game loop works, because all i could basically find were prototype functions.

For example, this is the code for the textPicture Plugin and most of it are just overwritten prototype functions(i think?), where i dont know when they get called and from what. Only main.js constist of multiple functions, but i dont know what exactly they are doing. It all looks like lose code, that doesnt do anything and is controlled from a presence in the shadows i cant see.

Code:
(() => {
    const pluginName = "TextPicture";
    let textPictureText = "";
    PluginManager.registerCommand(pluginName, "set", (args) => {
        textPictureText = String(args.text);
    });
    const _Game_Picture_show = Game_Picture.prototype.show;
    Game_Picture.prototype.show = function () {
        _Game_Picture_show.apply(this, arguments);
        console.log(this._name, textPictureText);
        if (this._name === "" && textPictureText) {
            this.mzkp_text = textPictureText;
            this.mzkp_textChanged = true;
            textPictureText = "";
        }
    };
    const _Sprite_Picture_destroy = Sprite_Picture.prototype.destroy;
    Sprite_Picture.prototype.destroy = function () {
        destroyTextPictureBitmap(this.bitmap);
        _Sprite_Picture_destroy.apply(this, arguments);
    };
    const _Sprite_Picture_updateBitmap = Sprite_Picture.prototype.updateBitmap;
    Sprite_Picture.prototype.updateBitmap = function () {
        _Sprite_Picture_updateBitmap.apply(this, arguments);
        if (this.visible && this._pictureName === "") {
            const picture = this.picture();
            const text = picture ? picture.mzkp_text || "" : "";
            const textChanged = picture && picture.mzkp_textChanged;
            if (this.mzkp_text !== text || textChanged) {
                this.mzkp_text = text;
                destroyTextPictureBitmap(this.bitmap);
                this.bitmap = createTextPictureBitmap(text);
                picture.mzkp_textChanged = false;
            }
        } else {
            this.mzkp_text = "";
        }
    };
    function createTextPictureBitmap(text) {
        const tempWindow = new Window_Base(new Rectangle());
        const size = tempWindow.textSizeEx(text);
        tempWindow.padding = 0;
        tempWindow.move(0, 0, size.width, size.height);
        tempWindow.createContents();
        tempWindow.drawTextEx(text, 0, 0, 0);
        const bitmap = tempWindow.contents;
        tempWindow.contents = null;
        tempWindow.destroy();
        bitmap.mzkp_isTextPicture = true;
        return bitmap;
    }
    function destroyTextPictureBitmap(bitmap) {
        if (bitmap && bitmap.mzkp_isTextPicture) {
            bitmap.destroy();
        }
    }
})();
Are you asking how the base engine works or how plugins work?

Plugins often overwrite functions or objects from the core engine to modify or add new commands so new or different things happen from the base engine. Sometimes they don't overwrite anything and just add new functions or objects.
Yeah i want to know how the base engine works. i just took the plugin as an example, becuase i think, that somehow the bas engine is also responsible for executing the plugins code, but i am not sure and want clarification.
The game loads its scripts as per usual HTML rules. main.js loads all scripts then launches the static SceneManager update loop. This attaches SceneManager.update to a new PIXI Ticker. The ticker is basically a render hook: it repeatedly invokes the callback in tandem with the parent app's render cycle, similar to requestAnimationFrame. Each scene updates its children, which update their children, etc.

Standalone deployments (and playtest) run through NWJS, which is a wrapper for Node.
i think, that somehow the bas engine is also responsible for executing the plugins code
No - plugins are included in your project via the editor software. You don't need to touch anything in the main code (and nothing is changed in it) when you add plugin files.

If they overwrite one of the default functions, then that will be executed instead via normal rules for JavaScript prototype inheritance.

where i dont know when they get called and from what.
It's pretty easy to grep for stuff in your js directory. If I do a search in the contents for "updateBitmap", I find it has 18 instances in rmmz_sprites and 3 in rmmz_core. You'll have to do a bit of actual looking (and perhaps backtracking) because multiple classes have an updateBitmap() method, so you'll need to narrow down which are the specific function calls you're looking for.

But 21 lines (and some of those are the function declarations you can skip past) is not a daunting task 😉
No - plugins are included in your project via the editor software. You don't need to touch anything in the main code (and nothing is changed in it) when you add plugin files.

If they overwrite one of the default functions, then that will be executed instead via normal rules for JavaScript prototype inheritance.


It's pretty easy to grep for stuff in your js directory. If I do a search in the contents for "updateBitmap", I find it has 18 instances in rmmz_sprites and 3 in rmmz_core. You'll have to do a bit of actual looking (and perhaps backtracking) because multiple classes have an updateBitmap() method, so you'll need to narrow down which are the specific function calls you're looking for.

But 21 lines (and some of those are the function declarations you can skip past) is not a daunting task 😉
Yeah i am actually looking, but i can't find what i am looking for, because i don't recognize it when i see it. I think i am not that deep into javascript or object oriented Js

Original thread: https://forums.rpgmakerweb.com/threads/how-does-the-engine-work.159594/