Understanding Windows and Scenes process

Discussion in 'RPG Maker MV' started by WickedWolfy, Dec 5, 2017.

    Tags:
  1. WickedWolfy

    WickedWolfy Touch Fluffy Tail! Veteran

    Messages:
    105
    Likes Received:
    43
    Location:
    East Coast, USA
    First Language:
    En, De, Ru
    Primarily Uses:
    RMMV
    Dear Colleagues,

    I've spent the past four days traversing the Scenes and Windows js files in MV maker and I have to say that I thought I understood the works better before I started reading... I am not sure I grasp even the basics by now.
    I apologize in advance, if this topic was asked... I am sure it was... But to my searching I can not find any concrete tutorial and compiled in a single place.
    My dilemma is the following...

    I don't get how windows work in RPG Maker MV. What is the process of "creating" a window. As in how does code make one, which functions are executed in which order? I am really trying to _understand_ the process, not just solve a particular problem. (well technically its a problem I am trying to solve =])

    Now... that being said... I have over 15 years of computer programming (writing professional code) experience, 10 of which in JavaScript - I am not a complete newcomer to creating code... And I am grasping at straws when it comes to the RPG Maker MV. Maybe if I would have a decent place to start?
    I've traced most of the Window classes and have a decent understanding of their purpose, but not their operation.
    Example: "Window_TitleCommand" responds for managing/creating the title menu/options for "New Game"... But how does the process actually flow? What is called when? How is the action delegated to the next item?
    There is something very simple I am missing, I bet...

    I've seen some great plugins by GALV and SRD, but I can't make heads or tails of t he code. It doesn't click in my head. I can't follow the process and really struggling with it.

    I can try to see other people's code and try to mimic it, but it will be a bad of cheap and dirty tricks instead of good code... and that's not good enough for me. =(
    I would really appreciate if someone could share some knowledge and experience on the topic.

    Please halp!

    Thank you in advance.
    ~Wolfy
     
    #1
  2. dbchest

    dbchest Beast Master Veteran

    Messages:
    434
    Likes Received:
    296
    Location:
    Pennsylvania
    First Language:
    English
    Primarily Uses:
    RMMV
    as a general rule, windows are initialized within the scene class that they appear; if you want to view the function that initializes an instance of the menu command window, then you would look to the Scene_Menu class within the rpg_scenes file and so forth.

    some windows however, like the gold window or the choices window are initialized at the same time the message window is initialized, and the initialization is actually performed from within the parent window, Window_Message. this is more uncommon, but nice to know.
     
    #2
  3. WickedWolfy

    WickedWolfy Touch Fluffy Tail! Veteran

    Messages:
    105
    Likes Received:
    43
    Location:
    East Coast, USA
    First Language:
    En, De, Ru
    Primarily Uses:
    RMMV
    Thanks for posting, dbchest

    But you see, that's the issue... With 3-4 levels of inheritance and the classes split through multiple files with nearly zero documentation, it is very hard to understand the process... but there has to be an absolute starting point.
    For example, with standard WEB DOM model, that MV is, technically, trying to imitate, there are actions that fire that you can kind of trace to get the idea of what's going on. For example, adding a "window" (a div) to a page, you would create it with code and then attach it to the page.
    In comparison, MV splits the process into million pieces and gives each one to a stranger function to execute in a random order, it seems.
    Well fine, its not that bad exactly... I can see the hooks and actions firing, but they still rely on a lot of inherited processes that make the task of understanding this process more complicated than it should be.
    In my case, I am trying to figure out the actions that would need to fire to create a window - the starting point. I took "Title Screen" as an example, since it is attached to "boot" actions and is not called by a user, but rather by the system... making it simpler to trace completely.

    Technically, yes and no. They are initiated together, but they are initiated with a single hook that calls window creation and addition. That one is easy. In this case its the "esc" button press. And then you would run "refresh" to change the data.
    For this example, I am trying to figure out how the window is "drawn" - think in terms of "canvas" elements. To my poking - all text is loaded as bitmap images... which is a little overly complicated.

    I am also generally confused about why in particular this "model" was used. I am not seeing anything MVC about it. Is this legacy translation for Mobile Version of the previous code?
     
    #3
  4. dbchest

    dbchest Beast Master Veteran

    Messages:
    434
    Likes Received:
    296
    Location:
    Pennsylvania
    First Language:
    English
    Primarily Uses:
    RMMV
    if you open rpg_scenes and find the Scene_Title class, the first this you will see is the class' constructor:
    Code:
    function Scene_Title() {
        this.initialize.apply(this, arguments);
    }
    so wherever you see the following code:
    Code:
    SceneManager.push(Scene_Title)
    this constructor builds an instance of Scene_Title and applies any arguments through the initialize function.

    scenes have a built-in system that they follow: initialize, create, start, update, and terminate. i think some of those have pre and post functions for wiggle room, but these are your basic considerations. typically, the create function will perform the initialization of all windows to be used in that scene. open up any scene and navigate to its create method for a practical example.

    edit
    oh, try looking in rpg_core and run a search for Window.prototype. also, RPGMV uses pixi.js, so take a gander in there for Canvas related information.
     
    #4
    WickedWolfy likes this.
  5. WickedWolfy

    WickedWolfy Touch Fluffy Tail! Veteran

    Messages:
    105
    Likes Received:
    43
    Location:
    East Coast, USA
    First Language:
    En, De, Ru
    Primarily Uses:
    RMMV
    I can't look at the actual code right now, unfortunately, but that sounds very reasonable. I will definitely try to explore that line of execution. Thank you very much.

    While we are on topic of this... You've mentioned that there are "initialize, create, start, update, and terminate". By "terminate" do you mean "execution" or "destructor"? That's my other curiosity. For what I am trying to create, destructors might be a very useful thing.
    I've explored the cache/image/bitmap class (they are separate, but kind of work together) and found an interesting reusability pattern. Pretty cool. I've made another ticket for "Load/Reserve/Request" thread (https://forums.rpgmakerweb.com/index.php?threads/imagemanager-load-vs-reserve-vs-request.88008/) which unfortunately went unanswered. But after posting, I was able to trace down the differences to cache and how it functions differently. Would be interesting to see how scenes clean up (read "destructor" function) after themselves.
    I think that is another part of my question - I've seen content pushed to certain values... again, can't check right now, but one of the examples was with the Dialog/Message system (condition101), where the image is pushed to system part, from where it is rendered... And those parts are reused.
    One of the thing I am trying to do is try and change dialog box for something more custom. To take simple example, I would like separate boxes (read "gray boxes with borders") around each separate thing: face separate, text separate. Essentially, that is what lead me to exploring how windows work.

    If you have any insight into that, I would gladly listen, poke around and share my findings.
    But regardless, thank you very much for taking the time to educate me and share your experience.
     
    #5
  6. dbchest

    dbchest Beast Master Veteran

    Messages:
    434
    Likes Received:
    296
    Location:
    Pennsylvania
    First Language:
    English
    Primarily Uses:
    RMMV
    start is for execution and terminate is for destruction. the terminate method is going to free all your bitmaps, etc.

    i have asked the same question about Load, Reserver, and Request, and the best answer i got is that the Reserve and Request functions were introduced as a way of providing a working caching system in v1.5.1 and later. i still do not fully understand the caching at this time, so i will not speak for right now.

    yeah, when you get the chance, open rpg_core and find Window.prototype. this is the true base window that all windows inherit from and if memory serves right, the function you are looking for is Window.prototype.createAllParts. that being said, i do not recommend aliasing or redefining anything from Window.prototype; if you want to make a custom message window, i would recommend creating a new window class (Window_MessageAlt, for instance) and redefining every relevant function in there, starting with Window.prototype.

    i hope you find exactly what you are looking for man, and if you succeed i would like to see screenshots of your new window.
     
    #6
  7. WickedWolfy

    WickedWolfy Touch Fluffy Tail! Veteran

    Messages:
    105
    Likes Received:
    43
    Location:
    East Coast, USA
    First Language:
    En, De, Ru
    Primarily Uses:
    RMMV
    I think I have a decent understanding of the model and yes, what you've been answered seems about right. I am still poking around the subject and plan to write up my findings once I have a full view of the functionality. My main confusion was the "reserve" and "request" (why are there two reservations), but the caching does seem different... sooo....
    I'll tag you once I have the full model plotted out.
    One of the cases I've seen the "reserve" used is (drumroll) TITLE SCREEN! Haha, full circle! =) There was a request for extra title image in the "boot" while the title is loading. I think if you are ever to use "external" items (think web/mobile game), then requesting images becomes a much more timely deal, based on your connection. It is everything from an exe where loading is instantaneous.

    My main issue with the "sequence" of events is that, at least it seems so to me, that the resources are prepped, polled, put into some predefined container... Than unknown magic happens and BOOM you have windows and things. Its that "magical part" that I am trying to get a firm grasp on. I will definitely follow from the boot and take a look at "Window.prototype.createAllParts", per your suggestion. It sounds ominous, since we should probably not create "all the things" with one function (judging by name), but it definitely warrants an investigation.
     
    #7
    dbchest likes this.

Share This Page