Added gNetworkPlayers to lua api

This commit is contained in:
MysterD 2022-02-02 19:24:51 -08:00
parent fcb459d095
commit c59aeedf78
10 changed files with 105 additions and 3 deletions

View File

@ -17,8 +17,10 @@ def get_path(p):
def translate_type_to_lvt(ptype):
if '[' in ptype or '{' in ptype:
return 'LOT_???'
if 'enum' in ptype:
if 'enum ' in ptype:
return 'LVT_S32'
if ptype == 'bool':
return 'LVT_U8'
if ptype in usf_types:
return 'LVT_' + ptype.upper()
if ptype in vec3_types:
@ -36,7 +38,9 @@ def translate_type_to_lvt(ptype):
def translate_type_to_lot(ptype):
if '[' in ptype or '{' in ptype:
return 'LOT_???'
if 'enum' in ptype:
if 'enum ' in ptype:
return 'LOT_NONE'
if ptype == 'bool':
return 'LOT_NONE'
if ptype in usf_types:
return 'LOT_NONE'

View File

@ -100,6 +100,8 @@ def normalize_type(t):
def alter_type(t):
if t.startswith('enum '):
return 'int'
if t == 'bool':
return 'u8'
return t

View File

@ -9,7 +9,8 @@ in_files = [
'src/game/area.h',
'src/game/camera.h',
'src/game/characters.h',
'src/engine/surface_collision.h'
'src/engine/surface_collision.h',
'src/pc/network/network_player.h'
]
smlua_cobject_autogen = 'src/pc/lua/smlua_cobject_autogen'
@ -55,6 +56,7 @@ override_field_types = {
override_field_immutable = {
"MarioState": [ "playerIndex" ],
"Character": [ "*" ],
"NetworkPlayer": [ "*" ],
}
sLuaManuallyDefinedStructs = [

View File

@ -537,6 +537,19 @@
- CT_WALUIGI
- CT_MAX
<br />
- NPT_UNKNOWN
- NPT_LOCAL
- NPT_SERVER
- NPT_CLIENT
<br />
- UNKNOWN_LOCAL_INDEX
- UNKNOWN_GLOBAL_INDEX
- UNKNOWN_NETWORK_INDEX
[:arrow_up_small:](#)
<br />

View File

@ -14,6 +14,15 @@ It is indexed by the local `playerIndex`, so `gMarioStates[0]` is always the loc
<br />
## [gNetworkPlayers](#gNetworkPlayers)
The `gNetworkPlayers[]` table is an array from `0` to `(MAX_PLAYERS - 1)` that contains a [NetworkPlayer](structs.md#NetworkPlayer) struct for each possible player.
It is indexed by the local `playerIndex`, so `gNetworkPlayers[0]` is always the local player.
[:arrow_up_small:](#)
<br />
## [gCharacter](#gCharacter)
The `gCharacter[]` table is an array from `0` to `(CT_MAX - 1)` that contains a [Character](structs.md#Character) struct for each possible character.

View File

@ -25,6 +25,7 @@
- [MarioBodyState](#MarioBodyState)
- [MarioState](#MarioState)
- [ModeTransitionInfo](#ModeTransitionInfo)
- [NetworkPlayer](#NetworkPlayer)
- [Object](#Object)
- [ObjectHitbox](#ObjectHitbox)
- [ObjectNode](#ObjectNode)
@ -557,6 +558,32 @@
<br />
## [NetworkPlayer](#NetworkPlayer)
| Field | Type |
| ----- | ---- |
| connected | bool |
| currActNum | integer |
| currAreaIndex | integer |
| currAreaSyncValid | bool |
| currCourseNum | integer |
| currLevelAreaSeqId | integer |
| currLevelNum | integer |
| currLevelSyncValid | bool |
| fadeOpacity | integer |
| globalIndex | integer |
| lastReceived | number |
| lastSent | number |
| localIndex | integer |
| modelIndex | integer |
| onRxSeqId | integer |
| paletteIndex | integer |
| type | integer |
[:arrow_up_small:](#)
<br />
## [Object](#Object)
| Field | Type |

View File

@ -172,6 +172,17 @@ void smlua_cobject_init_globals(void) {
lua_setglobal(L, "gMarioStates");
}
{
lua_newtable(L);
int t = lua_gettop(gLuaState);
for (int i = 0; i < MAX_PLAYERS; i++) {
lua_pushinteger(L, i);
smlua_push_object(L, LOT_NETWORKPLAYER, &gNetworkPlayers[i]);
lua_settable(L, t);
}
lua_setglobal(L, "gNetworkPlayers");
}
{
lua_newtable(L);
int t = lua_gettop(gLuaState);

View File

@ -6,6 +6,7 @@
#include "src/game/camera.h"
#include "src/game/characters.h"
#include "src/engine/surface_collision.h"
#include "src/pc/network/network_player.h"
#define LUA_ANIMATION_FIELD_COUNT 7
static struct LuaObjectField sAnimationFields[LUA_ANIMATION_FIELD_COUNT] = {
@ -433,6 +434,30 @@ static struct LuaObjectField sModeTransitionInfoFields[LUA_MODE_TRANSITION_INFO_
{ "transitionStart", LVT_COBJECT, offsetof(struct ModeTransitionInfo, transitionStart), true, LOT_LINEARTRANSITIONPOINT },
};
#define LUA_NETWORK_PLAYER_FIELD_COUNT 17
static struct LuaObjectField sNetworkPlayerFields[LUA_NETWORK_PLAYER_FIELD_COUNT] = {
{ "connected", LVT_U8, offsetof(struct NetworkPlayer, connected), true, LOT_NONE },
{ "currActNum", LVT_S16, offsetof(struct NetworkPlayer, currActNum), true, LOT_NONE },
{ "currAreaIndex", LVT_S16, offsetof(struct NetworkPlayer, currAreaIndex), true, LOT_NONE },
{ "currAreaSyncValid", LVT_U8, offsetof(struct NetworkPlayer, currAreaSyncValid), true, LOT_NONE },
{ "currCourseNum", LVT_S16, offsetof(struct NetworkPlayer, currCourseNum), true, LOT_NONE },
{ "currLevelAreaSeqId", LVT_U16, offsetof(struct NetworkPlayer, currLevelAreaSeqId), true, LOT_NONE },
{ "currLevelNum", LVT_S16, offsetof(struct NetworkPlayer, currLevelNum), true, LOT_NONE },
{ "currLevelSyncValid", LVT_U8, offsetof(struct NetworkPlayer, currLevelSyncValid), true, LOT_NONE },
{ "fadeOpacity", LVT_U8, offsetof(struct NetworkPlayer, fadeOpacity), true, LOT_NONE },
{ "globalIndex", LVT_U8, offsetof(struct NetworkPlayer, globalIndex), true, LOT_NONE },
{ "lastReceived", LVT_F32, offsetof(struct NetworkPlayer, lastReceived), true, LOT_NONE },
{ "lastSent", LVT_F32, offsetof(struct NetworkPlayer, lastSent), true, LOT_NONE },
{ "localIndex", LVT_U8, offsetof(struct NetworkPlayer, localIndex), true, LOT_NONE },
{ "modelIndex", LVT_U8, offsetof(struct NetworkPlayer, modelIndex), true, LOT_NONE },
// { "name", LOT_???, offsetof(struct NetworkPlayer, name), true, LOT_??? }, <--- UNIMPLEMENTED
{ "onRxSeqId", LVT_U8, offsetof(struct NetworkPlayer, onRxSeqId), true, LOT_NONE },
{ "paletteIndex", LVT_U8, offsetof(struct NetworkPlayer, paletteIndex), true, LOT_NONE },
// { "rxPacketHash", LOT_???, offsetof(struct NetworkPlayer, rxPacketHash), true, LOT_??? }, <--- UNIMPLEMENTED
// { "rxSeqIds", LOT_???, offsetof(struct NetworkPlayer, rxSeqIds), true, LOT_??? }, <--- UNIMPLEMENTED
{ "type", LVT_U8, offsetof(struct NetworkPlayer, type), true, LOT_NONE },
};
#define LUA_OBJECT_FIELD_COUNT 22
static struct LuaObjectField sObjectFields[LUA_OBJECT_FIELD_COUNT] = {
{ "activeFlags", LVT_S16, offsetof(struct Object, activeFlags), false, LOT_NONE },
@ -660,6 +685,7 @@ struct LuaObjectTable sLuaObjectAutogenTable[LOT_AUTOGEN_MAX - LOT_AUTOGEN_MIN]
{ LOT_MARIOBODYSTATE, sMarioBodyStateFields, LUA_MARIO_BODY_STATE_FIELD_COUNT },
{ LOT_MARIOSTATE, sMarioStateFields, LUA_MARIO_STATE_FIELD_COUNT },
{ LOT_MODETRANSITIONINFO, sModeTransitionInfoFields, LUA_MODE_TRANSITION_INFO_FIELD_COUNT },
{ LOT_NETWORKPLAYER, sNetworkPlayerFields, LUA_NETWORK_PLAYER_FIELD_COUNT },
{ LOT_OBJECT, sObjectFields, LUA_OBJECT_FIELD_COUNT },
{ LOT_OBJECTHITBOX, sObjectHitboxFields, LUA_OBJECT_HITBOX_FIELD_COUNT },
{ LOT_OBJECTNODE, sObjectNodeFields, LUA_OBJECT_NODE_FIELD_COUNT },

View File

@ -28,6 +28,7 @@ enum LuaObjectAutogenType {
LOT_MARIOBODYSTATE,
LOT_MARIOSTATE,
LOT_MODETRANSITIONINFO,
LOT_NETWORKPLAYER,
LOT_OBJECT,
LOT_OBJECTHITBOX,
LOT_OBJECTNODE,

View File

@ -115,6 +115,13 @@ char gSmluaConstants[] = "HOOK_UPDATE = 0\n"
"CT_TOAD = 2\n"
"CT_WALUIGI = 3\n"
"CT_MAX = 4\n"
"NPT_UNKNOWN = 0\n"
"NPT_LOCAL = 1\n"
"NPT_SERVER = 2\n"
"NPT_CLIENT = 3\n"
"UNKNOWN_LOCAL_INDEX = -1\n"
"UNKNOWN_GLOBAL_INDEX = -1\n"
"UNKNOWN_NETWORK_INDEX = -1\n"
"LAYER_FORCE = 0\n"
"LAYER_OPAQUE = 1\n"
"LAYER_OPAQUE_DECAL = 2\n"