mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2025-01-22 23:52:15 -05:00
Added BehaviorScript pointer handling to Lua API
This commit is contained in:
parent
091a859104
commit
44fca9aede
8 changed files with 843 additions and 812 deletions
|
@ -2,6 +2,7 @@ import os
|
|||
|
||||
usf_types = ['u8', 'u16', 'u32', 'u64', 's8', 's16', 's32', 's64', 'f32']
|
||||
vec3_types = ['Vec3s', 'Vec3f']
|
||||
typedef_pointers = ['BehaviorScript']
|
||||
|
||||
exclude_structs = [
|
||||
'SPTask',
|
||||
|
@ -54,7 +55,7 @@ def translate_type_to_lvt(ptype):
|
|||
|
||||
if ptype.count('*') == 1 and '(' not in ptype and '[' not in ptype:
|
||||
ptype = ptype.replace('const', '').replace('*', '').strip()
|
||||
if ptype in usf_types:
|
||||
if ptype in usf_types or ptype in typedef_pointers:
|
||||
return 'LVT_%s_P' % ptype.upper()
|
||||
|
||||
return 'LVT_???'
|
||||
|
@ -92,10 +93,13 @@ def translate_type_to_lot(ptype):
|
|||
|
||||
if 'struct' in ptype:
|
||||
if ptype.count('*') > 1:
|
||||
return 'LVT_???'
|
||||
return 'LOT_???'
|
||||
|
||||
struct_id = ptype.split(' ')[1].replace('*', '')
|
||||
|
||||
if struct_id in exclude_structs:
|
||||
return 'LOT_???'
|
||||
|
||||
return 'LOT_' + struct_id.upper()
|
||||
|
||||
if ptype.count('*') == 1 and '???' not in translate_type_to_lvt(ptype):
|
||||
|
|
|
@ -51,7 +51,7 @@ override_disallowed_functions = {
|
|||
"src/engine/surface_collision.h": [ " debug_", "f32_find_wall_collision" ],
|
||||
"src/game/mario_actions_airborne.c": [ "^[us]32 act_.*" ],
|
||||
"src/game/mario_actions_automatic.c": [ "^[us]32 act_.*" ],
|
||||
"src/game/mario_actions_cutscene.c": [ "^[us]32 act_.*", " geo_" ],
|
||||
"src/game/mario_actions_cutscene.c": [ "^[us]32 act_.*", " geo_", "spawn_obj" ],
|
||||
"src/game/mario_actions_moving.c": [ "^[us]32 act_.*" ],
|
||||
"src/game/mario_actions_object.c": [ "^[us]32 act_.*" ],
|
||||
"src/game/mario_actions_stationary.c": [ "^[us]32 act_.*" ],
|
||||
|
@ -213,6 +213,9 @@ def build_call(function):
|
|||
lfunc = 'lua_pushstring'
|
||||
elif ftype == 'const char*':
|
||||
lfunc = 'lua_pushstring'
|
||||
elif translate_type_to_lot(ftype) == 'LOT_POINTER':
|
||||
lvt = translate_type_to_lvt(ftype)
|
||||
return ' smlua_push_pointer(L, %s, (void*)%s);\n' % (lvt, ccall)
|
||||
elif '???' not in flot and flot != 'LOT_NONE':
|
||||
return ' smlua_push_object(L, %s, %s);\n' % (flot, ccall)
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
# Supported Functions
|
||||
- behavior_table.h
|
||||
- [get_behavior_from_id](#get_behavior_from_id)
|
||||
- [get_id_from_behavior](#get_id_from_behavior)
|
||||
|
||||
<br />
|
||||
|
||||
|
@ -357,6 +359,46 @@
|
|||
<br />
|
||||
|
||||
|
||||
## [get_behavior_from_id](#get_behavior_from_id)
|
||||
|
||||
### Lua Example
|
||||
`local Pointer <BehaviorScript>Value = get_behavior_from_id(id)`
|
||||
|
||||
### Parameters
|
||||
| Field | Type |
|
||||
| ----- | ---- |
|
||||
| id | integer |
|
||||
|
||||
### Returns
|
||||
- Pointer <BehaviorScript>
|
||||
|
||||
### C Prototype
|
||||
`const BehaviorScript* get_behavior_from_id(enum BehaviorId id);`
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
<br />
|
||||
|
||||
## [get_id_from_behavior](#get_id_from_behavior)
|
||||
|
||||
### Lua Example
|
||||
`local integerValue = get_id_from_behavior(behavior)`
|
||||
|
||||
### Parameters
|
||||
| Field | Type |
|
||||
| ----- | ---- |
|
||||
| behavior | Pointer <BehaviorScript> |
|
||||
|
||||
### Returns
|
||||
- integer
|
||||
|
||||
### C Prototype
|
||||
`enum BehaviorId get_id_from_behavior(const BehaviorScript* behavior);`
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
<br />
|
||||
|
||||
---
|
||||
# functions from camera.h
|
||||
|
||||
|
|
|
@ -662,10 +662,12 @@
|
|||
| areaTimer | integer | |
|
||||
| areaTimerDuration | integer | |
|
||||
| areaTimerType | integer | |
|
||||
| behavior | Pointer <BehaviorScript> | read-only |
|
||||
| bhvDelayTimer | integer | |
|
||||
| bhvStackIndex | integer | |
|
||||
| collidedObjInteractTypes | integer | |
|
||||
| createdThroughNetwork | integer | |
|
||||
| curBhvCommand | Pointer <BehaviorScript> | read-only |
|
||||
| globalPlayerIndex | integer | |
|
||||
| header | [ObjectNode](#ObjectNode) | read-only |
|
||||
| heldByPlayerIndex | integer | |
|
||||
|
@ -1712,6 +1714,7 @@
|
|||
|
||||
| Field | Type | Access |
|
||||
| ----- | ---- | ------ |
|
||||
| behavior | Pointer <BehaviorScript> | read-only |
|
||||
| flags | integer | |
|
||||
| model | integer | |
|
||||
| moveAngleRange | integer | |
|
||||
|
|
|
@ -115,6 +115,7 @@ static int smlua__get_field(lua_State* L) {
|
|||
case LVT_COBJECT_P: smlua_push_object(L, data->lot, *(u8**)p); break;
|
||||
case LVT_STRING: lua_pushstring(L, (char*)p); break;
|
||||
case LVT_STRING_P: lua_pushstring(L, *(char**)p); break;
|
||||
case LVT_BEHAVIORSCRIPT: lua_pushinteger(L, *(s32*)p); break;
|
||||
|
||||
// pointers
|
||||
case LVT_U8_P:
|
||||
|
@ -124,6 +125,7 @@ static int smlua__get_field(lua_State* L) {
|
|||
case LVT_S16_P:
|
||||
case LVT_S32_P:
|
||||
case LVT_F32_P:
|
||||
case LVT_BEHAVIORSCRIPT_P:
|
||||
smlua_push_pointer(L, data->valueType, *(u8**)p);
|
||||
break;
|
||||
|
||||
|
|
|
@ -21,6 +21,8 @@ enum LuaValueType {
|
|||
LVT_COBJECT_P,
|
||||
LVT_STRING,
|
||||
LVT_STRING_P,
|
||||
LVT_BEHAVIORSCRIPT,
|
||||
LVT_BEHAVIORSCRIPT_P,
|
||||
LVT_POINTER,
|
||||
};
|
||||
|
||||
|
|
|
@ -500,14 +500,14 @@ static struct LuaObjectField sNetworkPlayerFields[LUA_NETWORK_PLAYER_FIELD_COUNT
|
|||
{ "type", LVT_U8, offsetof(struct NetworkPlayer, type), true, LOT_NONE },
|
||||
};
|
||||
|
||||
#define LUA_OBJECT_FIELD_COUNT 746
|
||||
#define LUA_OBJECT_FIELD_COUNT 748
|
||||
static struct LuaObjectField sObjectFields[LUA_OBJECT_FIELD_COUNT] = {
|
||||
{ "activeFlags", LVT_S16, offsetof(struct Object, activeFlags), false, LOT_NONE },
|
||||
{ "areaTimer", LVT_U32, offsetof(struct Object, areaTimer), false, LOT_NONE },
|
||||
{ "areaTimerDuration", LVT_U32, offsetof(struct Object, areaTimerDuration), false, LOT_NONE },
|
||||
// { "areaTimerRunOnceCallback)(void)", LVT_???, offsetof(struct Object, areaTimerRunOnceCallback)(void)), false, LOT_??? }, <--- UNIMPLEMENTED
|
||||
{ "areaTimerType", LVT_S32, offsetof(struct Object, areaTimerType), false, LOT_NONE },
|
||||
// { "behavior", LVT_???, offsetof(struct Object, behavior), true, LOT_??? }, <--- UNIMPLEMENTED
|
||||
{ "behavior", LVT_BEHAVIORSCRIPT_P, offsetof(struct Object, behavior), true, LOT_POINTER },
|
||||
{ "bhvDelayTimer", LVT_S16, offsetof(struct Object, bhvDelayTimer), false, LOT_NONE },
|
||||
// { "bhvStack", LOT_???, offsetof(struct Object, bhvStack), false, LOT_??? }, <--- UNIMPLEMENTED
|
||||
{ "bhvStackIndex", LVT_U32, offsetof(struct Object, bhvStackIndex), false, LOT_NONE },
|
||||
|
@ -515,7 +515,7 @@ static struct LuaObjectField sObjectFields[LUA_OBJECT_FIELD_COUNT] = {
|
|||
// { "collidedObjs", LOT_???, offsetof(struct Object, collidedObjs), false, LOT_??? }, <--- UNIMPLEMENTED
|
||||
// { "collisionData", LVT_???, offsetof(struct Object, collisionData), false, LOT_??? }, <--- UNIMPLEMENTED
|
||||
{ "createdThroughNetwork", LVT_U8, offsetof(struct Object, createdThroughNetwork), false, LOT_NONE },
|
||||
// { "curBhvCommand", LVT_???, offsetof(struct Object, curBhvCommand), true, LOT_??? }, <--- UNIMPLEMENTED
|
||||
{ "curBhvCommand", LVT_BEHAVIORSCRIPT_P, offsetof(struct Object, curBhvCommand), true, LOT_POINTER },
|
||||
{ "globalPlayerIndex", LVT_U8, offsetof(struct Object, globalPlayerIndex), false, LOT_NONE },
|
||||
{ "header", LVT_COBJECT, offsetof(struct Object, header), true, LOT_OBJECTNODE },
|
||||
{ "heldByPlayerIndex", LVT_U32, offsetof(struct Object, heldByPlayerIndex), false, LOT_NONE },
|
||||
|
@ -544,7 +544,7 @@ static struct LuaObjectField sObjectFields[LUA_OBJECT_FIELD_COUNT] = {
|
|||
{ "oAngleVelRoll", LVT_S32, offsetof(struct Object, oAngleVelRoll), false, LOT_NONE },
|
||||
{ "oAngleVelYaw", LVT_S32, offsetof(struct Object, oAngleVelYaw), false, LOT_NONE },
|
||||
{ "oAnimState", LVT_S32, offsetof(struct Object, oAnimState), false, LOT_NONE },
|
||||
// { "oAnimations", LVT_???, offsetof(struct Object, oAnimations), false, LVT_??? }, <--- UNIMPLEMENTED
|
||||
// { "oAnimations", LVT_???, offsetof(struct Object, oAnimations), false, LOT_??? }, <--- UNIMPLEMENTED
|
||||
{ "oArrowLiftDisplacement", LVT_F32, offsetof(struct Object, oArrowLiftDisplacement), false, LOT_NONE },
|
||||
{ "oArrowLiftUnk100", LVT_S32, offsetof(struct Object, oArrowLiftUnk100), false, LOT_NONE },
|
||||
{ "oBBallSpawnerMaxSpawnDist", LVT_F32, offsetof(struct Object, oBBallSpawnerMaxSpawnDist), false, LOT_NONE },
|
||||
|
@ -1450,9 +1450,9 @@ static struct LuaObjectField sWarpTransitionDataFields[LUA_WARP_TRANSITION_DATA_
|
|||
{ "texTimer", LVT_S16, offsetof(struct WarpTransitionData, texTimer), false, LOT_NONE },
|
||||
};
|
||||
|
||||
#define LUA_WATER_DROPLET_PARAMS_FIELD_COUNT 10
|
||||
#define LUA_WATER_DROPLET_PARAMS_FIELD_COUNT 11
|
||||
static struct LuaObjectField sWaterDropletParamsFields[LUA_WATER_DROPLET_PARAMS_FIELD_COUNT] = {
|
||||
// { "behavior", LVT_???, offsetof(struct WaterDropletParams, behavior), true, LOT_??? }, <--- UNIMPLEMENTED
|
||||
{ "behavior", LVT_BEHAVIORSCRIPT_P, offsetof(struct WaterDropletParams, behavior), true, LOT_POINTER },
|
||||
{ "flags", LVT_S16, offsetof(struct WaterDropletParams, flags), false, LOT_NONE },
|
||||
{ "model", LVT_S16, offsetof(struct WaterDropletParams, model), false, LOT_NONE },
|
||||
{ "moveAngleRange", LVT_S16, offsetof(struct WaterDropletParams, moveAngleRange), false, LOT_NONE },
|
||||
|
|
|
@ -26,31 +26,27 @@
|
|||
// behavior_table.h //
|
||||
//////////////////////
|
||||
|
||||
/*
|
||||
int smlua_func_get_behavior_from_id(lua_State* L) {
|
||||
if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
|
||||
|
||||
int id = smlua_to_integer(L, 1);
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
|
||||
UNIMPLEMENTED -->(L, get_behavior_from_id(id));
|
||||
smlua_push_pointer(L, LVT_BEHAVIORSCRIPT_P, (void*)get_behavior_from_id(id));
|
||||
|
||||
return 1;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
int smlua_func_get_id_from_behavior(lua_State* L) {
|
||||
if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
|
||||
|
||||
// const BehaviorScript* behavior = (const BehaviorScript*)smlua_to_cobject(L, 1, LOT_???); <--- UNIMPLEMENTED
|
||||
const BehaviorScript* behavior = (const BehaviorScript*)smlua_to_cpointer(L, 1, LVT_BEHAVIORSCRIPT_P);
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
|
||||
lua_pushinteger(L, get_id_from_behavior(behavior));
|
||||
|
||||
return 1;
|
||||
}
|
||||
*/
|
||||
|
||||
//////////////
|
||||
// camera.h //
|
||||
|
@ -1346,7 +1342,7 @@ int smlua_func_vec3f_find_ceil(lua_State* L) {
|
|||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
f32 height = smlua_to_number(L, 2);
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
// struct Surface** ceil = (struct Surface**)smlua_to_cobject(L, 3, LVT_???); <--- UNIMPLEMENTED
|
||||
// struct Surface** ceil = (struct Surface**)smlua_to_cobject(L, 3, LOT_???); <--- UNIMPLEMENTED
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
|
||||
lua_pushnumber(L, vec3f_find_ceil(pos, height, ceil));
|
||||
|
@ -1995,26 +1991,6 @@ int smlua_func_should_start_or_continue_dialog(lua_State* L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
int smlua_func_spawn_obj_at_mario_rel_yaw(lua_State* L) {
|
||||
if(!smlua_functions_valid_param_count(L, 4)) { return 0; }
|
||||
|
||||
struct MarioState* m = (struct MarioState*)smlua_to_cobject(L, 1, LOT_MARIOSTATE);
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
s32 model = smlua_to_integer(L, 2);
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
// const BehaviorScript* behavior = (const BehaviorScript*)smlua_to_cobject(L, 3, LOT_???); <--- UNIMPLEMENTED
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
s16 relYaw = smlua_to_integer(L, 4);
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
|
||||
extern struct Object *spawn_obj_at_mario_rel_yaw(struct MarioState *m, s32 model, const BehaviorScript *behavior, s16 relYaw);
|
||||
smlua_push_object(L, LOT_OBJECT, spawn_obj_at_mario_rel_yaw(m, model, behavior, relYaw));
|
||||
|
||||
return 1;
|
||||
}
|
||||
*/
|
||||
|
||||
int smlua_func_stuck_in_ground_handler(lua_State* L) {
|
||||
if(!smlua_functions_valid_param_count(L, 6)) { return 0; }
|
||||
|
||||
|
@ -2251,7 +2227,7 @@ int smlua_func_common_landing_cancels(lua_State* L) {
|
|||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
struct LandingAction* landingAction = (struct LandingAction*)smlua_to_cobject(L, 2, LOT_LANDINGACTION);
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
// s32 (*setAPressAction)(structMarioState* arg2 = (s32 (*setAPressAction)(structMarioState*)smlua_to_cobject(L, 3, LVT_???); <--- UNIMPLEMENTED
|
||||
// s32 (*setAPressAction)(structMarioState* arg2 = (s32 (*setAPressAction)(structMarioState*)smlua_to_cobject(L, 3, LOT_???); <--- UNIMPLEMENTED
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
u32 arg3 = smlua_to_integer(L, 4);
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
|
@ -3416,7 +3392,7 @@ int smlua_func_find_ceil(lua_State* L) {
|
|||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
f32 posZ = smlua_to_number(L, 3);
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
// struct Surface** pceil = (struct Surface**)smlua_to_cobject(L, 4, LVT_???); <--- UNIMPLEMENTED
|
||||
// struct Surface** pceil = (struct Surface**)smlua_to_cobject(L, 4, LOT_???); <--- UNIMPLEMENTED
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
|
||||
lua_pushnumber(L, find_ceil(posX, posY, posZ, pceil));
|
||||
|
@ -3435,7 +3411,7 @@ int smlua_func_find_floor(lua_State* L) {
|
|||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
f32 zPos = smlua_to_number(L, 3);
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
// struct Surface** pfloor = (struct Surface**)smlua_to_cobject(L, 4, LVT_???); <--- UNIMPLEMENTED
|
||||
// struct Surface** pfloor = (struct Surface**)smlua_to_cobject(L, 4, LOT_???); <--- UNIMPLEMENTED
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
|
||||
lua_pushnumber(L, find_floor(xPos, yPos, zPos, pfloor));
|
||||
|
@ -3469,7 +3445,7 @@ int smlua_func_find_floor_height_and_data(lua_State* L) {
|
|||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
f32 zPos = smlua_to_number(L, 3);
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
// struct FloorGeometry** floorGeo = (struct FloorGeometry**)smlua_to_cobject(L, 4, LVT_???); <--- UNIMPLEMENTED
|
||||
// struct FloorGeometry** floorGeo = (struct FloorGeometry**)smlua_to_cobject(L, 4, LOT_???); <--- UNIMPLEMENTED
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
|
||||
lua_pushnumber(L, find_floor_height_and_data(xPos, yPos, zPos, floorGeo));
|
||||
|
@ -3511,7 +3487,7 @@ int smlua_func_find_surface_on_ray(lua_State* L) {
|
|||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
dir[2] = smlua_get_number_field(2, "z");
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
// struct Surface** hit_surface = (struct Surface**)smlua_to_cobject(L, 3, LVT_???); <--- UNIMPLEMENTED
|
||||
// struct Surface** hit_surface = (struct Surface**)smlua_to_cobject(L, 3, LOT_???); <--- UNIMPLEMENTED
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
|
||||
f32* hit_pos = smlua_get_vec3f_from_buffer();
|
||||
|
@ -3620,8 +3596,8 @@ void smlua_bind_functions_autogen(void) {
|
|||
lua_State* L = gLuaState;
|
||||
|
||||
// behavior_table.h
|
||||
//smlua_bind_function(L, "get_behavior_from_id", smlua_func_get_behavior_from_id); <--- UNIMPLEMENTED
|
||||
//smlua_bind_function(L, "get_id_from_behavior", smlua_func_get_id_from_behavior); <--- UNIMPLEMENTED
|
||||
smlua_bind_function(L, "get_behavior_from_id", smlua_func_get_behavior_from_id);
|
||||
smlua_bind_function(L, "get_id_from_behavior", smlua_func_get_id_from_behavior);
|
||||
|
||||
// camera.h
|
||||
smlua_bind_function(L, "set_camera_pitch_shake", smlua_func_set_camera_pitch_shake);
|
||||
|
@ -3790,7 +3766,6 @@ void smlua_bind_functions_autogen(void) {
|
|||
smlua_bind_function(L, "mario_ready_to_speak", smlua_func_mario_ready_to_speak);
|
||||
smlua_bind_function(L, "print_displaying_credits_entry", smlua_func_print_displaying_credits_entry);
|
||||
smlua_bind_function(L, "should_start_or_continue_dialog", smlua_func_should_start_or_continue_dialog);
|
||||
//smlua_bind_function(L, "spawn_obj_at_mario_rel_yaw", smlua_func_spawn_obj_at_mario_rel_yaw); <--- UNIMPLEMENTED
|
||||
smlua_bind_function(L, "stuck_in_ground_handler", smlua_func_stuck_in_ground_handler);
|
||||
|
||||
// mario_actions_moving.c
|
||||
|
|
Loading…
Reference in a new issue