Handle library incompatibilities

Add a mechanism for libraries to resolve incompatibilities between
library versions before linking.

This is currently used for ChipmunkSpriteEngine and GoatGUIEngine,
where early versions used integer IDs when loading CGs (later versions
use strings).
This commit is contained in:
Nunuhara Cabbage
2022-06-06 08:49:12 -07:00
parent 19ac7e6935
commit eaa0baad7f
12 changed files with 279 additions and 34 deletions
+87 -6
View File
@@ -14,15 +14,23 @@
* along with this program; if not, see <http://gnu.org/licenses/>.
*/
#include <assert.h>
#include "system4/ain.h"
#include "asset_manager.h"
#include "parts.h"
#include "hll.h"
static void GoatGUIEngine_PreLink(void);
HLL_LIBRARY(GoatGUIEngine,
HLL_EXPORT(_PreLink, GoatGUIEngine_PreLink),
HLL_EXPORT(Init, PE_Init),
HLL_EXPORT(Update, PE_Update),
HLL_EXPORT(SetPartsCG, PE_SetPartsCG_by_index),
HLL_EXPORT(SetPartsCG, PE_SetPartsCG),
HLL_EXPORT(GetPartsCGNumber, PE_GetPartsCGNumber),
HLL_EXPORT(SetLoopCG, PE_SetLoopCG),
HLL_TODO_EXPORT(SetLoopCG, PE_SetLoopCG),
HLL_EXPORT(SetText, PE_SetText),
HLL_EXPORT(AddPartsText, PE_AddPartsText),
HLL_TODO_EXPORT(DeletePartsTopTextLine, PE_DeletePartsTopTextLine),
@@ -39,8 +47,8 @@ HLL_LIBRARY(GoatGUIEngine,
HLL_EXPORT(SetHGaugeRate, PE_SetHGaugeRate),
HLL_EXPORT(SetVGaugeCG, PE_SetVGaugeCG),
HLL_EXPORT(SetVGaugeRate, PE_SetVGaugeRate),
HLL_EXPORT(SetNumeralCG, PE_SetNumeralCG),
HLL_EXPORT(SetNumeralLinkedCGNumberWidthWidthList, PE_SetNumeralLinkedCGNumberWidthWidthList),
HLL_TODO_EXPORT(SetNumeralCG, PE_SetNumeralCG),
HLL_TODO_EXPORT(SetNumeralLinkedCGNumberWidthWidthList, PE_SetNumeralLinkedCGNumberWidthWidthList),
HLL_EXPORT(SetNumeralNumber, PE_SetNumeralNumber),
HLL_EXPORT(SetNumeralShowComma, PE_SetNumeralShowComma),
HLL_EXPORT(SetNumeralSpace, PE_SetNumeralSpace),
@@ -58,12 +66,16 @@ HLL_LIBRARY(GoatGUIEngine,
HLL_EXPORT(SetShow, PE_SetShow),
HLL_EXPORT(SetAlpha, PE_SetAlpha),
HLL_TODO_EXPORT(SetPartsDrawFilter, PE_SetPartsDrawFilter),
HLL_TODO_EXPORT(SetAddColor, PE_SetAddColor),
HLL_TODO_EXPORT(SetMultiplyColor, PE_SetMultiplyColor),
HLL_EXPORT(SetClickable, PE_SetClickable),
HLL_EXPORT(GetPartsX, PE_GetPartsX),
HLL_EXPORT(GetPartsY, PE_GetPartsY),
HLL_EXPORT(GetPartsZ, PE_GetPartsZ),
HLL_EXPORT(GetPartsShow, PE_GetPartsShow),
HLL_EXPORT(GetPartsAlpha, PE_GetPartsAlpha),
HLL_TODO_EXPORT(GetAddColor, PE_GetAddColor),
HLL_TODO_EXPORT(GetMultiplyColor, PE_GetMultiplyColor),
HLL_EXPORT(GetPartsClickable, PE_GetPartsClickable),
HLL_EXPORT(SetPartsOriginPosMode, PE_SetPartsOriginPosMode),
HLL_EXPORT(GetPartsOriginPosMode, PE_GetPartsOriginPosMode),
@@ -82,7 +94,7 @@ HLL_LIBRARY(GoatGUIEngine,
HLL_EXPORT(GetClickPartsNumber, PE_GetClickPartsNumber),
HLL_EXPORT(AddMotionPos, PE_AddMotionPos),
HLL_EXPORT(AddMotionAlpha, PE_AddMotionAlpha),
HLL_EXPORT(AddMotionCG, PE_AddMotionCG),
HLL_TODO_EXPORT(AddMotionCG, PE_AddMotionCG),
HLL_EXPORT(AddMotionHGaugeRate, PE_AddMotionHGaugeRate),
HLL_EXPORT(AddMotionVGaugeRate, PE_AddMotionVGaugeRate),
HLL_EXPORT(AddMotionNumeralNumber, PE_AddMotionNumeralNumber),
@@ -92,6 +104,7 @@ HLL_LIBRARY(GoatGUIEngine,
HLL_EXPORT(AddMotionRotateY, PE_AddMotionRotateY),
HLL_EXPORT(AddMotionRotateZ, PE_AddMotionRotateZ),
HLL_EXPORT(AddMotionVibrationSize, PE_AddMotionVibrationSize),
HLL_TODO_EXPORT(AddWholeMotionVibrationSize, PE_AddWholeMotionVibrationSize),
HLL_EXPORT(AddMotionSound, PE_AddMotionSound),
HLL_EXPORT(BeginMotion, PE_BeginMotion),
HLL_EXPORT(EndMotion, PE_EndMotion),
@@ -108,4 +121,72 @@ HLL_LIBRARY(GoatGUIEngine,
HLL_TODO_EXPORT(SetThumbnailReductionSize, PE_SetThumbnailReductionSize),
HLL_TODO_EXPORT(SetThumbnailMode, PE_SetThumbnailMode),
HLL_EXPORT(Save, PE_Save),
HLL_EXPORT(Load, PE_Load));
HLL_EXPORT(Load, PE_Load),
HLL_TODO_EXPORT(SetPartsFlashAndStop, PE_SetPartsFlashAndStop),
HLL_TODO_EXPORT(StopPartsFlash, PE_StopPartsFlash),
HLL_TODO_EXPORT(StartPartsFlash, PE_StartPartsFlash),
HLL_TODO_EXPORT(GoFramePartsFlash, PE_GoFramePartsFlash),
HLL_TODO_EXPORT(GetPartsFlashEndFrame, PE_GetPartsFlashEndFrame),
HLL_TODO_EXPORT(ClearPartsConstructionProcess, PE_ClearPartsConstructionProcess),
HLL_TODO_EXPORT(AddCreateToPartsConstructionProcess, PE_AddCreateToPartsConstructionProcess),
HLL_TODO_EXPORT(AddCreatePixelOnlyToPartsConstructionProcess, PE_AddCreatePixelOnlyToPartsConstructionProcess),
HLL_TODO_EXPORT(AddFillToPartsConstructionProcess, PE_AddFillToPartsConstructionProcess),
HLL_EXPORT(AddFillAlphaColorToPartsConstructionProcess, PE_AddFillAlphaColorToPartsConstructionProcess),
HLL_TODO_EXPORT(AddFillAMapToPartsConstructionProcess, PE_AddFillAMapToPartsConstructionProcess),
HLL_TODO_EXPORT(AddFillWithAlphaToPartsConstructionProcess, PE_AddFillWithAlphaToPartsConstructionProcess),
HLL_TODO_EXPORT(AddFillGradationHorizonToPartsConstructionProcess, PE_AddFillGradationHorizonToPartsConstructionProcess),
HLL_TODO_EXPORT(AddDrawRectToPartsConstructionProcess, PE_AddDrawRectToPartsConstructionProcess),
HLL_EXPORT(BuildPartsConstructionProcess, PE_BuildPartsConstructionProcess),
HLL_TODO_EXPORT(AddDrawTextToPartsConstructionProcess, PE_AddDrawTextToPartsConstructionProcess));
static struct ain_hll_function *get_fun(int libno, const char *name)
{
int fno = ain_get_library_function(ain, libno, name);
return fno >= 0 ? &ain->libraries[libno].functions[fno] : NULL;
}
// Daiteikoku and Shaman's Sanctuary have different interface than later versions
static void GoatGUIEngine_PreLink(void)
{
struct ain_hll_function *fun;
int libno = ain_get_library(ain, "GoatGUIEngine");
assert(libno >= 0);
fun = get_fun(libno, "SetPartsCG");
if (fun && fun->arguments[1].type.data == AIN_INT) {
static_library_replace(&lib_GoatGUIEngine, "SetPartsCG", PE_SetPartsCG_by_index);
}
fun = get_fun(libno, "SetLoopCG");
if (fun && fun->arguments[1].type.data == AIN_INT) {
static_library_replace(&lib_GoatGUIEngine, "SetLoopCG", PE_SetLoopCG_by_index);
}
fun = get_fun(libno, "SetHGaugeCG");
if (fun && fun->arguments[1].type.data == AIN_INT) {
static_library_replace(&lib_GoatGUIEngine, "SetHGaugeCG", PE_SetHGaugeCG_by_index);
}
fun = get_fun(libno, "SetVGaugeCG");
if (fun && fun->arguments[1].type.data == AIN_INT) {
static_library_replace(&lib_GoatGUIEngine, "SetVGaugeCG", PE_SetVGaugeCG_by_index);
}
fun = get_fun(libno, "SetNumeralCG");
if (fun && fun->arguments[1].type.data == AIN_INT) {
static_library_replace(&lib_GoatGUIEngine, "SetNumeralCG", PE_SetNumeralCG_by_index);
}
fun = get_fun(libno, "SetNumeralLinkedCGNumberWidthWidthList");
if (fun && fun->arguments[1].type.data == AIN_INT) {
static_library_replace(&lib_GoatGUIEngine, "SetNumeralLinkedCGNumberWidthWidthList",
PE_SetNumeralLinkedCGNumberWidthWidthList_by_index);
}
fun = get_fun(libno, "AddMotionCG");
if (fun && fun->arguments[1].type.data == AIN_INT) {
static_library_replace(&lib_GoatGUIEngine, "AddMotionCG", PE_AddMotionCG_by_index);
}
}