Extended Object to get casted types

This commit is contained in:
KiritoDv 2025-03-12 02:07:37 -06:00
parent 4559b45055
commit 0c78d8452a
4 changed files with 8678 additions and 8605 deletions

View file

@ -133,11 +133,30 @@ typedef enum ObjectStatus {
/* 3 */ OBJ_DYING,
} ObjectStatus;
#ifdef __cplusplus
struct Actor;
struct Boss;
struct Scenery;
struct Scenery360;
struct Sprite;
struct Item;
struct Effect;
#endif
typedef struct Object {
/* 0x00 */ u8 status;
/* 0x02 */ u16 id;
/* 0x04 */ Vec3f pos;
/* 0x10 */ Vec3f rot;
#ifdef __cplusplus
Actor* asActor() { return (Actor*)this; }
Boss* asBoss() { return (Boss*)this; }
Scenery* asScenery() { return (Scenery*)this; }
Scenery360* asScenery360() { return (Scenery360*)this; }
Sprite* asSprite() { return (Sprite*)this; }
Item* asItem() { return (Item*)this; }
Effect* asEffect() { return (Effect*)this; }
#endif
} Object; // size = 0x1C
typedef void (*ObjectFunc)(Object*);

File diff suppressed because it is too large Load diff

View file

@ -17,6 +17,19 @@
#include <sol/sol.hpp>
#include <utility>
struct Asset {
const char* path;
template<typename T>
T* Get() {
return (T*) path;
}
std::string tostring() const {
return path;
}
};
namespace fs = std::filesystem;
ScriptingLayer* ScriptingLayer::Instance = new ScriptingLayer();
@ -98,6 +111,31 @@ void ScriptingLayer::Init() {
return lid;
};
lua.new_usertype<Asset>("Asset",
"Load8", &Asset::Get<u8>,
"Load16", &Asset::Get<u16>,
"Load32", &Asset::Get<u32>,
"LoadVtx", &Asset::Get<Vtx>,
"LoadGfx", &Asset::Get<Gfx>,
sol::meta_function::to_string, &Asset::tostring
);
lua["gNextMasterDisp"] = []() -> Gfx* {
return gMasterDisp++;
};
lua["gRefMasterDisp"] = []() -> Gfx* {
return (Gfx*) &gMasterDisp;
};
lua["gRefGfxMatrix"] = []() -> Matrix* {
return (Matrix*) &gGfxMatrix;
};
lua["gDPSetPrimColor"] = [](uint8_t m, uint8_t l, uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
gDPSetPrimColor(gMasterDisp++, m, l, r, g, b, a);
};
lua["Game"] = lua.create_table();
lua["Assets"] = lua.create_table();
lua["Events"] = lua.create_table();

View file

@ -142,6 +142,14 @@ def parse_structs(header):
for i, key in enumerate(members):
key = key.replace('*', '')
print(f' "{key}", sol::property(&{struct_name}::{key}, &{struct_name}::{key}){"," if i < len(members) - 1 else ""}')
if struct_name == 'Object':
print(f' ,"asActor", &{struct_name}::asActor,')
print(f' "asBoss", &{struct_name}::asBoss,')
print(f' "asScenery", &{struct_name}::asScenery,')
print(f' "asScenery360", &{struct_name}::asScenery360,')
print(f' "asSprite", &{struct_name}::asSprite,')
print(f' "asItem", &{struct_name}::asItem,')
print(f' "asEffect", &{struct_name}::asEffect')
print(');')
print('')
@ -227,7 +235,8 @@ def parse_externs(header):
elif '(' in line:
if 'ALIGN_ASSET' in line:
var_name = line.split('[')[0].split(' ')[-1]
print(f'lua["Assets"]["{var_name}"] = {var_name};')
# print(f'lua["Assets"]["{var_name}"] = {var_name};')
print(f'lua["Assets"]["{var_name}"] = Asset{{ {var_name} }};')
continue
if 'define' in line or '\\' in line or 'typedef' in line or '[' in line or 'OSMesg' in line or 'Framebuffer' in line or 'TimerAction' in line or 'TimerTask' in line:
continue