To provide some background, as I'm sure the dev team is well aware at this point, Yuurand's global is constantly brushing up against the ZASM line count limit. Today, we ran into an interesting issue where Moosh was getting global crashes when compiling, but I wasn't. We eventually traced this down to std.zh. I'm on a slightly older build of ZC with an std.zh version behind the current. Updating to the new one caused the global crash. I was curious and dug a little deeper to see what was changed and why this would've suddenly pushed us over. The offending functions here are the Get/SetLayerComboX functions. I've pasted here GetLayerComboD from 2.5.2 (for reference), 2.53.1 from earlier this year, and current 2.53.1.
2.5.2:
int GetLayerComboD(int layer, int pos) { if (layer==0) return Screen->ComboD[pos]; else return Game->GetComboData(Screen->LayerMap(layer), Screen->LayerScreen(layer), pos); }
Earlier this year:
int GetLayerComboD(int layer, int pos) { if (layer < 0 ) { int err[]="Invalid layer passed to GetLayerComboD"; TraceError(err,layer); return -1; } if (layer > 6 ) { int err[]="Invalid layer passed to GetLayerComboD"; TraceError(err,layer); return -1; } if (!layer) //layer 0 { if ( !SETLAYERCOMBO_ALWAYS_USE_SETCOMBO ) { return Screen->ComboD[pos]; } else return Game->GetComboData(Game->GetCurMap(), Game->GetCurScreen(), pos); } return Game->GetComboData(Screen->LayerMap(layer), Screen->LayerScreen(layer), pos); }
Current:
int GetLayerComboD(int layer, int pos) { if (layer < 0 ) { int err[]="Invalid layer passed to GetLayerComboD"; TraceError(err,layer); return -1; } if (layer > 6 ) { int err[]="Invalid layer passed to GetLayerComboD"; TraceError(err,layer); return -1; } if (!layer) //layer 0 { if ( !SETLAYERCOMBO_ALWAYS_USE_SETCOMBO ) { return Screen->ComboD[pos]; } else return Game->GetComboData(Game->GetCurMap(), Game->GetCurScreen(), pos); } else { if ( Screen->LayerMap(layer) != -1 && Screen->LayerScreen(layer) != -1 ) { return Game->GetComboData(Screen->LayerMap(layer), Screen->LayerScreen(layer), pos); } else { int err[]="The layer (%d) used by GetLayerComboD for the current screen are not properly configured.\n"; printf(err, layer); return -1; } } }
On the one hand, the function has several sanity checks added (one of which happened as a result of a bug on our end I believe), which is good. On the other hand, declaring three separate strings within the function makes it quite a bit heavier. These are useful for debugging, but increase the ZASM count of the functions, and therefore the count of any script that makes use of them, by an unacceptable amount.
What I propose is using standardized error codes instead. A single string could be declared in std.zh, such as
int err[] = "Error. Please consult the documentation and look for the following error code:\n";
The function could then be reduced to something like this:
int GetLayerComboD(int layer, int pos) { if (layer < 0 || layer > 6){ printf(err); Trace(100); return -1; } if (!layer) //layer 0{ if ( !SETLAYERCOMBO_ALWAYS_USE_SETCOMBO ){ return Screen->ComboD[pos]; } else return Game->GetComboData(Game->GetCurMap(), Game->GetCurScreen(), pos); } else{ if ( Screen->LayerMap(layer) != -1 && Screen->LayerScreen(layer) != -1 ){ return Game->GetComboData(Screen->LayerMap(layer), Screen->LayerScreen(layer), pos); } else{ printf(err); Trace(101); return -1; } } }
This still retains its usefulness in debugging errors while being significantly more lightweight.