While I've only read the core and managers parts of the default RMMZ 0.9.5 codebase, the following's some of the good and bad parts I've found(by no way exhaustive and in my opinion of course):
There are actually a lot more bad parts I've found, but they're rather minor, at least compared to what I've included here, and I don't want this post to be just overwhelmed with all the bad parts, thus giving the wrong impression that the default RMMZ codebase's just an utterly pathetic mess and hurt the sales before it's even released, so I've also emphasized the good parts to make thing more fair.
I'd like to know what you've found about the good and bad parts in the default RMMZ 0.9.5 codebase as well, and I hope we can make a collection here to praise the MZ devs on one hand, and request them to make the codebase even better on the other.
Of course, with just 10 days before launch, it's just impossible to fix all these issues, but I still hope at least the most severe ones will be noticed and fixing them several days/weeks after release's still way better than nothing 🙂
P.S.: I hope the MZ devs will eventually read this, as I think the MZ improvements, while already quite drastic and in the right directions, can have some further works as additional quality of lives for many plugin developers, and I'm opening this post as a hobbyist, who needs a high quality codebase to work effectively and efficiently, so I think the risks of scaring off many hobbyists isn't so high that any more significant improvements will only do more harm than good, not to mention that not all hobbyists will remain hobbyists forever, and a very, very high quality codebase can help them grow.
Core -
1. The adaptation of Pixi v5.2.4 in MZ from v4.5.4 in MV(performance boost)
2. The use of GLSL in MZ instead of doing the same by the JavaScript in MV(performance boost)
3. The existence of Graphics.FSPCounter and Video classes in MZ instead of having so many functionality included by Graphics in MV(significantly reducing complexity of Graphics class while only slighlty increasing complexity for trying to keep the whole codebase inside the head)
4. The existence of Utils.checkRMVersion in MZ having no equivalent in MV(making version checking easier, simpler and smaller tasks)
5. The removal of many low level implementation details from many core classes in MZ unlike many MV codes that seems to be doing the Pixi works(To be fair, some of those low level implementations come from the fact that MV natively supports Canvas mode while MZ doesn't natively support this outdated mode anymore, which is another good parts in MZ)
6. The removal of the Html5Audio class in MZ, which is mostly unused in most MV projects anyway, and nowsdays only IE doesn't support the Web Audio API, and it's unlikely that anyone will still use IE, let alone for playing MZ games(might be bad for those minority though)
Managers -
1. The existence of FontManager in MZ extracting the similar functionality from Graphics in MV(significantly reducing complexity of Graphics class while only slighlty increasing complexity for trying to keep the whole codebase inside the head)
2. The existence of ColorManager in MZ extracting what should be independent functionality from Window_Base in MV(now getting window colors doesn't have to do weird hacks like new Window_Base().normalColor() and the codebase makes it clear that windows aren't the only ones that are supposed to use window colors)
3. No more status window injection from Scene_Battle to BattleManager in MZ, unlike what's done in MV(that MV design flaw causes inherently duplicated codes among refreshStatus in BattleManager and Scene_Battle, as they're essentially the identical knowledge just with different timings, meaning that MV should've injected Scene_Battle.prototype.refreshStatus into the BattleManager instead)
4. The existence of BattleManager.updatePhase in MZ extracted from BattleManager.update in MV(this makes adding/editing/removing battle phases much, much easier, simpler and smaller tasks in MZ as BattleManager.updateEvent has side effects that should only occur at most once per frame)
5. The existence of _currentActor in BattleManager in MZ(at least a slight performance boost and boilerplate reduction)
1. The adaptation of Pixi v5.2.4 in MZ from v4.5.4 in MV(performance boost)
2. The use of GLSL in MZ instead of doing the same by the JavaScript in MV(performance boost)
3. The existence of Graphics.FSPCounter and Video classes in MZ instead of having so many functionality included by Graphics in MV(significantly reducing complexity of Graphics class while only slighlty increasing complexity for trying to keep the whole codebase inside the head)
4. The existence of Utils.checkRMVersion in MZ having no equivalent in MV(making version checking easier, simpler and smaller tasks)
5. The removal of many low level implementation details from many core classes in MZ unlike many MV codes that seems to be doing the Pixi works(To be fair, some of those low level implementations come from the fact that MV natively supports Canvas mode while MZ doesn't natively support this outdated mode anymore, which is another good parts in MZ)
6. The removal of the Html5Audio class in MZ, which is mostly unused in most MV projects anyway, and nowsdays only IE doesn't support the Web Audio API, and it's unlikely that anyone will still use IE, let alone for playing MZ games(might be bad for those minority though)
Managers -
1. The existence of FontManager in MZ extracting the similar functionality from Graphics in MV(significantly reducing complexity of Graphics class while only slighlty increasing complexity for trying to keep the whole codebase inside the head)
2. The existence of ColorManager in MZ extracting what should be independent functionality from Window_Base in MV(now getting window colors doesn't have to do weird hacks like new Window_Base().normalColor() and the codebase makes it clear that windows aren't the only ones that are supposed to use window colors)
3. No more status window injection from Scene_Battle to BattleManager in MZ, unlike what's done in MV(that MV design flaw causes inherently duplicated codes among refreshStatus in BattleManager and Scene_Battle, as they're essentially the identical knowledge just with different timings, meaning that MV should've injected Scene_Battle.prototype.refreshStatus into the BattleManager instead)
4. The existence of BattleManager.updatePhase in MZ extracted from BattleManager.update in MV(this makes adding/editing/removing battle phases much, much easier, simpler and smaller tasks in MZ as BattleManager.updateEvent has side effects that should only occur at most once per frame)
5. The existence of _currentActor in BattleManager in MZ(at least a slight performance boost and boilerplate reduction)
1. No native TypeScript support(even though @nio kasgami is burning his/her life to help plugin developers write TypeScript plugins), which further tightens the plugin development feedback loop by letting the compiler complain about careless but common mistakes right after they're made instead of in run time, and helps those writing automated tests to test their plugins by setting up test fixtures and mock dependencies, with the additional information from TypeScript so they'll always know exactly the data type of the dependency to be mocked(also, some tests are asserting a variable/parameter/arguement's of the right data type, and the importance of these tests will be much, much lower with TypeScript)
2. Not fully utilizing ES6 constructs in many places actually improving codebase quality(it's different from forcing the whole codebase into the ES6 standard though), and nowadays most JavaScript programmers know ES6 as it's long become the mainstream years ago, and actually there will be more not knowing ES5(like some of those learnt JavaScript after ES6 becomes the mainstream) than those not knowing ES6(like some of those learning JavaScript for MV and nothing more)
3. It's very, very challenging to write MZ plugins with testability in mind, let alone a fully automated test suite with almost entirely of meaningful tests, high code and state coverage, as the default RMMZ codebase isn't very testable in itself(I'm not demanding ECS with TDD though), mainly because of the fact that many classes(many of them should be broken down into several smaller classes in my opinion) have too many interdependent shared mutable states, which should be broken down into smaller and more independent pieces(right now it's hard to mock or setup test fixtures effectively and efficiently without a commercial level testing framework, and the need of these things usually means the testability of the codebase's far from ideal), and shoehorning testable codes into such a codebase will probably lead to tons of unreadable codes(having too many seams just to rescue testability will make codes hard to reason and dry-run in details), tautological tests or those with unclear implications when they fail(i.e., you can't immediately tell which parts of nontrivial business logic's compromised), meaning that the ROI of automated test suites of plugins is generally too low to be worth, but manually testing plugins clearly undesirable for those plugin developers and users either
4. No automated test suite(public to plugin developers) in the default RMMZ codebase, causing plugin developers to have one less tool to help them catch unknowing functionality breaks in the default RMMZ codebase and/or compatibility issues steming from plugin A relying on some assumptions in the default RMMZ codebase and plugin B has broken that unknowingly(I know I'm asking too much here, but still it'd be nice if plugin developers do have access to the automated test suite in the default RMMZ codebase), and sometimes such an automated test suite can even help plugin users report bugs/compatibility issues more effectively and efficiently
5. Still using rmmz_core.js, rmmz_managers.js, rmmz_objects.js, rmmz_scenes.js, rmmz_sprites.js and rmmz_windows.js instead of core/Graphics.js, core/Input.js, managers/BattleManager.js, managers/DataManager.js, etc, causing those files being too big to navigate effectively nor efficiently, and any decent IDE lets you search across all files in the same folder(including those in subfolders), so breaking those big files into smaller ones grouped by folders should do way more good than harm
2. Not fully utilizing ES6 constructs in many places actually improving codebase quality(it's different from forcing the whole codebase into the ES6 standard though), and nowadays most JavaScript programmers know ES6 as it's long become the mainstream years ago, and actually there will be more not knowing ES5(like some of those learnt JavaScript after ES6 becomes the mainstream) than those not knowing ES6(like some of those learning JavaScript for MV and nothing more)
3. It's very, very challenging to write MZ plugins with testability in mind, let alone a fully automated test suite with almost entirely of meaningful tests, high code and state coverage, as the default RMMZ codebase isn't very testable in itself(I'm not demanding ECS with TDD though), mainly because of the fact that many classes(many of them should be broken down into several smaller classes in my opinion) have too many interdependent shared mutable states, which should be broken down into smaller and more independent pieces(right now it's hard to mock or setup test fixtures effectively and efficiently without a commercial level testing framework, and the need of these things usually means the testability of the codebase's far from ideal), and shoehorning testable codes into such a codebase will probably lead to tons of unreadable codes(having too many seams just to rescue testability will make codes hard to reason and dry-run in details), tautological tests or those with unclear implications when they fail(i.e., you can't immediately tell which parts of nontrivial business logic's compromised), meaning that the ROI of automated test suites of plugins is generally too low to be worth, but manually testing plugins clearly undesirable for those plugin developers and users either
4. No automated test suite(public to plugin developers) in the default RMMZ codebase, causing plugin developers to have one less tool to help them catch unknowing functionality breaks in the default RMMZ codebase and/or compatibility issues steming from plugin A relying on some assumptions in the default RMMZ codebase and plugin B has broken that unknowingly(I know I'm asking too much here, but still it'd be nice if plugin developers do have access to the automated test suite in the default RMMZ codebase), and sometimes such an automated test suite can even help plugin users report bugs/compatibility issues more effectively and efficiently
5. Still using rmmz_core.js, rmmz_managers.js, rmmz_objects.js, rmmz_scenes.js, rmmz_sprites.js and rmmz_windows.js instead of core/Graphics.js, core/Input.js, managers/BattleManager.js, managers/DataManager.js, etc, causing those files being too big to navigate effectively nor efficiently, and any decent IDE lets you search across all files in the same folder(including those in subfolders), so breaking those big files into smaller ones grouped by folders should do way more good than harm
1. The way Graphics._onKeyDown is rewritten has effectively hardcoded F2, F3 and F4 as switching FPS counter, switching stretch mode and switching full screen respectively, and there can be some plugins(like those letting players bind the keys themselves) that want to change these functionality to be triggered by some other keys, so that function should be rewritten to at least something like this:
Instead of just hardcoding 113(F2), 114(F3) and 115(F4) there.
2. There's no way to change the XHR in Bitmap.prototype._startDecrypting without rewriting that instance method, and fixing that's easy, simple and small task:
Clearly there's no reason to exclude the option to let plugins change that XHR, especially when including it costs next to nothing.
3. It's clear that Tilemap.Renderer.prototype._createShader doesn't want plugin developers to change the vertex and fragment GLSL, otherwise there's no reason for it to be written this way, but there are and/or will be plugin developers being familiar with GLSL and wanting to change the GLSL, so that instance method should be rewritten into something like this:
Again, such a rewrite costs next to nothing.
4. TilingSprite.prototype._refresh has some redundant allocations, because if texture's falsy or its base texture's falsy, the cloned frame won't be used at all, so that instance method should be rewritten into at least something like this:
While such redundant allocations don't have much performance impact as that instance method's not a hotspot, it's still slightly sloppy codes nonetheless.
5. WindowLayer.prototype.render doesn't let plugins change how each child's rendered, and can become a serious obstacle when Pixi releases a new version(stable or not) and some plugins want to test it out before the default RMMZ codebase adapts to that new version, so that instance method should be rewritten into at least something like this:
Now changing how each child's rendered just need to change WindowLayer.prototype._renderChild.
6. WebAudio.prototype._startXhrLoading has the same issues as Bitmap.prototype._startDecrypting and the similar cures:
7. Input still doesn't have an API to detect whether a key's just released in a given frame, and this API's very, very useful to some plugins triggering some events when a key's just released(I'm still writing 1 such MV plugin and I've to add the API into Input myself).
8. Input._onKeyDown hardcodes the numlock key to clear all input states, and some plugins might want to change that(perhaps for similar reasons to the issues in Graphics._onKeyDown), so that static function should be rewritten into at least something like this:
9. Graphics.pageToCanvasX(eventTouch.pageX) and Graphics.pageToCanvasY(eventTouch.pageY) are needlessly repeated in many functions in TouchInput, as those duplications are inherently identical knowledge - Converting the event/touch page X and Y into the canvas X and Y, so these redundant codes can be removed by something like this:
And not keeping thing DRY here can lead to changes of the aforementioned conversions to have troubles involving finding all the places using those conversions.
JavaScript:
Graphics._onKeyDown = function(event) {
if (!event.ctrlKey && !event.altKey) {
const { keyCode } = event;
if (this._switchFPSCounterKey(keyCode)) {
event.preventDefault();
this._switchFPSCounter();
} else if (this._switchStretchModeKey(keyCode)) {
event.preventDefault();
this._switchStretchMode();
} else if (this._switchFullScreenKey(keyCode)) {
event.preventDefault();
this._switchFullScreen();
}
}
};
2. There's no way to change the XHR in Bitmap.prototype._startDecrypting without rewriting that instance method, and fixing that's easy, simple and small task:
Code:
Bitmap.prototype._startDecrypting = function() {
this._newDecryptingXhr().send();
}
3. It's clear that Tilemap.Renderer.prototype._createShader doesn't want plugin developers to change the vertex and fragment GLSL, otherwise there's no reason for it to be written this way, but there are and/or will be plugin developers being familiar with GLSL and wanting to change the GLSL, so that instance method should be rewritten into something like this:
JavaScript:
Tilemap.Renderer.prototype._createShader = function()
const vertexSrc = this._shaderVertexSrc();
const fragmentSrc = this._shaderFragmentSrc();
return new PIXI.Shader(PIXI.Program.from(vertexSrc, fragmentSrc), {
uSampler0: 0,
uSampler1: 1,
uSampler2: 2,
uProjectionMatrix: new PIXI.Matrix()
});
};
4. TilingSprite.prototype._refresh has some redundant allocations, because if texture's falsy or its base texture's falsy, the cloned frame won't be used at all, so that instance method should be rewritten into at least something like this:
JavaScript:
TilingSprite.prototype._refresh = function() {
const texture = this.texture;
if (texture) {
if (texture.baseTexture) {
try {
const frame = this._frame.clone();
if (frame.width === 0 && frame.height === 0 && this._bitmap) {
frame.width = this._bitmap.width;
frame.height = this._bitmap.height;
}
texture.frame = frame;
} catch (e) {
texture.frame = new Rectangle();
}
}
texture._updateID++;
}
};
5. WindowLayer.prototype.render doesn't let plugins change how each child's rendered, and can become a serious obstacle when Pixi releases a new version(stable or not) and some plugins want to test it out before the default RMMZ codebase adapts to that new version, so that instance method should be rewritten into at least something like this:
JavaScript:
WindowLayer.prototype.render = function render(renderer) {
if (!this.visible) {
return;
}
const graphics = new PIXI.Graphics();
const gl = renderer.gl;
const children = this.children.clone();
renderer.framebuffer.forceStencil();
graphics.transform = this.transform;
renderer.batch.flush();
gl.enable(gl.STENCIL_TEST);
while (children.length > 0) {
const win = children.pop();
if (win._isWindow && win.visible && win.openness > 0) {
this._renderChild(renderer, graphics, gl, win);
}
}
gl.disable(gl.STENCIL_TEST);
gl.clear(gl.STENCIL_BUFFER_BIT);
gl.clearStencil(0);
renderer.batch.flush();
for (const child of this.children) {
if (!child._isWindow && child.visible) {
child.render(renderer);
}
}
renderer.batch.flush();
};
6. WebAudio.prototype._startXhrLoading has the same issues as Bitmap.prototype._startDecrypting and the similar cures:
JavaScript:
WebAudio.prototype._startXhrLoading = function(url) {
this._newLoadingXhr(url).send();
};
7. Input still doesn't have an API to detect whether a key's just released in a given frame, and this API's very, very useful to some plugins triggering some events when a key's just released(I'm still writing 1 such MV plugin and I've to add the API into Input myself).
8. Input._onKeyDown hardcodes the numlock key to clear all input states, and some plugins might want to change that(perhaps for similar reasons to the issues in Graphics._onKeyDown), so that static function should be rewritten into at least something like this:
JavaScript:
Input._onKeyDown = function(event) {
if (this._shouldPreventDefault(event.keyCode)) {
event.preventDefault();
}
if (this._shouldClear(event)) {
this.clear();
}
const buttonName = this.keyMapper[event.keyCode];
if (buttonName) {
this._currentState[buttonName] = true;
}
};
9. Graphics.pageToCanvasX(eventTouch.pageX) and Graphics.pageToCanvasY(eventTouch.pageY) are needlessly repeated in many functions in TouchInput, as those duplications are inherently identical knowledge - Converting the event/touch page X and Y into the canvas X and Y, so these redundant codes can be removed by something like this:
JavaScript:
TouchInput._onLeftButtonDown = function(event) {
const xy = this._pageToCanvasXY(event);
if (Graphics.isInsideCanvas(...xy)) {
this._mousePressed = true;
this._pressedTime = 0;
this._onTrigger(...xy);
}
};
TouchInput._onRightButtonDown = function(event) {
const xy = this._pageToCanvasXY(event);
if (Graphics.isInsideCanvas(...xy)) {
this._onCancel(...xy);
}
};
TouchInput._onMouseMove = function(event) {
const xy = this._pageToCanvasXY(event);
if (this._mousePressed) {
this._onMove(...xy);
} else if (Graphics.isInsideCanvas(...xy)) {
this._onHover(...xy);
}
};
TouchInput._onMouseUp = function(event) {
if (event.button === 0) {
this._mousePressed = false;
this._onRelease(...this._pageToCanvasXY(event));
}
};
TouchInput._onTouchStart = function(event) {
for (const touch of event.changedTouches) {
const xy = this._pageToCanvasXY(touch);
if (Graphics.isInsideCanvas(...xy)) {
this._screenPressed = true;
this._pressedTime = 0;
if (event.touches.length >= 2) {
this._onCancel(...xy);
} else {
this._onTrigger(...xy);
}
event.preventDefault();
}
}
if (window.cordova || window.navigator.standalone) {
event.preventDefault();
}
};
TouchInput._onTouchMove = function(event) {
for (const touch of event.changedTouches) {
this._onMove(...this._pageToCanvasXY(touch));
}
};
TouchInput._onTouchEnd = function(event) {
for (const touch of event.changedTouches) {
this._screenPressed = false;
this._onRelease(...this._pageToCanvasXY(touch));
}
};
TouchInput._pageToCanvasXY(eventTouch) {
return [
Graphics.pageToCanvasX(eventTouch.pageX),
Graphics.pageToCanvasY(eventTouch.pageY)
];
}
1. DataManager.loadDataFile has the same issues as Bitmap.prototype._startDecrypting and the similar cures:
2. BattleManager.invokeAction hardcodes the assumption that cnt and mrf will always be used when applying an action to its targets, which is simply false for some plugins setting some special cases to bypass them, and asking those plugins to change the value of cnt and mrf in those cases can create compatibility issues for some other plugins using cnt and mrf for anything other than their intended uses, so that static function should be rewritten into at least something like this:
Now bypassing cnt and mrf can be done by changing BattleManager._isInvokeCnt and BattleManager._isInvokeMrf, all without having to change the cnt and mrf values themselves.
3. BattleManager.onEscapeFailure hardcodes the escape ratio increment upon failed party escape attempts as 0.1, and there will definitely be plugins wanting to change that, so that static function should be rewritten into at least something like this:
Now changing the escape ratio increment just involves changing BattleManager._escRatioIncrement.
4. BattleManager.changeCurrentActor uses an algorithm that's less readable and performant as it could be, and solving these issues can be done by rewriting that static function into at least something like this:
It's because the original function access indexOf every time in the loop, leading to O(n ^ 2) algorithmic complexity, while this rewritten version just access it once, leading to O(n) algorithmic complexity.
While the performance impact doesn't matter in this case as n is always small the a large n itself will create even greater performance issues than what's created in this static function, it's still slightly sloppy codes nonetheless.
Also, the real intention of BattleManager.changeCurrentActor is to examine the next/prior actors(next is forward is true and prior if otherwise) to find an inputable actor, so the rewritten version can reflect that intention more accurately, thus increasing code readability.
5. SceneManager.onKeyDown has the similar issues as that in Graphics._onKeyDown, and that static function can be rewritten into something like this:
JavaScript:
DataManager.loadDataFile = function(name, src) {
window[name] = null;
this._loadDataFileXhr(name, src).send();
}
2. BattleManager.invokeAction hardcodes the assumption that cnt and mrf will always be used when applying an action to its targets, which is simply false for some plugins setting some special cases to bypass them, and asking those plugins to change the value of cnt and mrf in those cases can create compatibility issues for some other plugins using cnt and mrf for anything other than their intended uses, so that static function should be rewritten into at least something like this:
JavaScript:
BattleManager.invokeAction = function(subject, target) {
this._logWindow.push("pushBaseLine");
if (this._isInvokeCnt(target)) {
this.invokeCounterAttack(subject, target);
} else if (this._isInvokeMrf(target)) {
this.invokeMagicReflection(subject, target);
} else {
this.invokeNormalAction(subject, target);
}
subject.setLastTarget(target);
this._logWindow.push("popBaseLine");
};
3. BattleManager.onEscapeFailure hardcodes the escape ratio increment upon failed party escape attempts as 0.1, and there will definitely be plugins wanting to change that, so that static function should be rewritten into at least something like this:
JavaScript:
BattleManager.onEscapeFailure = function() {
$gameParty.onEscapeFailure();
this.displayEscapeFailureMessage();
this._escapeRatio += this._escRatioIncrement();;
if (!this.isTpb()) {
this.startTurn();
}
};
4. BattleManager.changeCurrentActor uses an algorithm that's less readable and performant as it could be, and solving these issues can be done by rewriting that static function into at least something like this:
JavaScript:
BattleManager.changeCurrentActor = function(forward) {
this._currentActor = this._newCurActor_(forward);
this.startActorInput();
};
BattleManager._newCurActor_ = function(forward) {
const members = $gameParty.battleMembers();
const iIncrement = forward ? 1 : -1;
let currentI = members.indexOf(this._currentActor);
for (;;) {
currentI += iIncrement;
const actor = members[currentI];
if (!actor) return null;
if (actor.canInput()) return actor;
}
};
While the performance impact doesn't matter in this case as n is always small the a large n itself will create even greater performance issues than what's created in this static function, it's still slightly sloppy codes nonetheless.
Also, the real intention of BattleManager.changeCurrentActor is to examine the next/prior actors(next is forward is true and prior if otherwise) to find an inputable actor, so the rewritten version can reflect that intention more accurately, thus increasing code readability.
5. SceneManager.onKeyDown has the similar issues as that in Graphics._onKeyDown, and that static function can be rewritten into something like this:
JavaScript:
SceneManager.onKeyDown = function(event) {
if (!event.ctrlKey && !event.altKey) {
const { keyCode } = event;
if (this._reloadGameKey(keyCode)) return this.reloadGame();
if (this._showevToolsKey(keyCode)) return this.showDevTools();
}
};
I'd like to know what you've found about the good and bad parts in the default RMMZ 0.9.5 codebase as well, and I hope we can make a collection here to praise the MZ devs on one hand, and request them to make the codebase even better on the other.
Of course, with just 10 days before launch, it's just impossible to fix all these issues, but I still hope at least the most severe ones will be noticed and fixing them several days/weeks after release's still way better than nothing 🙂
P.S.: I hope the MZ devs will eventually read this, as I think the MZ improvements, while already quite drastic and in the right directions, can have some further works as additional quality of lives for many plugin developers, and I'm opening this post as a hobbyist, who needs a high quality codebase to work effectively and efficiently, so I think the risks of scaring off many hobbyists isn't so high that any more significant improvements will only do more harm than good, not to mention that not all hobbyists will remain hobbyists forever, and a very, very high quality codebase can help them grow.
