Entirely remove player iterate loops from getting the dedicated server player
This was very annoying for writing lua and kind of redundent when you can already get the serverplayer from server
This commit is contained in:
parent
6bd5159e83
commit
63c244b381
3 changed files with 5 additions and 44 deletions
|
|
@ -28,43 +28,25 @@
|
|||
static int lib_iteratePlayers(lua_State *L)
|
||||
{
|
||||
INT32 i = -1;
|
||||
|
||||
if (lua_gettop(L) < 2)
|
||||
{
|
||||
//return luaL_error(L, "Don't call players.iterate() directly, use it as 'for player in players.iterate do <block> end'.");
|
||||
lua_pushcfunction(L, lib_iteratePlayers);
|
||||
return 1;
|
||||
}
|
||||
|
||||
lua_settop(L, 2);
|
||||
lua_remove(L, 1); // state is unused.
|
||||
|
||||
if (!lua_isnil(L, 1))
|
||||
i = (INT32)(*((player_t **)luaL_checkudata(L, 1, META_PLAYER)) - players);
|
||||
|
||||
i++;
|
||||
|
||||
if (!lua_compatmode)
|
||||
{
|
||||
if (i == serverplayer)
|
||||
{
|
||||
return LUA_PushServerPlayer(L);
|
||||
}
|
||||
}
|
||||
|
||||
for (; i < MAXPLAYERS; i++)
|
||||
for (i++; i < MAXPLAYERS; i++)
|
||||
{
|
||||
if (!playeringame[i])
|
||||
continue;
|
||||
if (lua_compatmode)
|
||||
{
|
||||
if (!players[i].mo)
|
||||
continue;
|
||||
}
|
||||
if (!players[i].mo)
|
||||
continue;
|
||||
LUA_PushUserdata(L, &players[i], META_PLAYER);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -78,21 +60,10 @@ static int lib_getPlayer(lua_State *L)
|
|||
if (i < 0 || i >= MAXPLAYERS)
|
||||
return luaL_error(L, "players[] index %d out of range (0 - %d)", i, MAXPLAYERS-1);
|
||||
|
||||
|
||||
if (!lua_compatmode)
|
||||
{
|
||||
if (i == serverplayer)
|
||||
return LUA_PushServerPlayer(L);
|
||||
}
|
||||
|
||||
if (!playeringame[i])
|
||||
return 0;
|
||||
|
||||
if (lua_compatmode)
|
||||
{
|
||||
if (!players[i].mo)
|
||||
return 0;
|
||||
}
|
||||
if (!players[i].mo)
|
||||
return 0;
|
||||
LUA_PushUserdata(L, &players[i], META_PLAYER);
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -920,14 +920,6 @@ lpushed_t LUA_RawPushUserdata(lua_State *L, void *data)
|
|||
return status;
|
||||
}
|
||||
|
||||
int LUA_PushServerPlayer(lua_State *L)
|
||||
{
|
||||
if ((!multiplayer || !(netgame || demo.playback)) && !playeringame[serverplayer])
|
||||
return 0;
|
||||
LUA_PushUserdata(L, &players[serverplayer], META_PLAYER);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// When userdata is freed, use this function to remove it from Lua.
|
||||
void LUA_InvalidateUserdata(void *data)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -99,8 +99,6 @@ typedef enum {
|
|||
void LUA_PushUserdata(lua_State *L, void *data, const char *meta);
|
||||
lpushed_t LUA_RawPushUserdata(lua_State *L, void *data);
|
||||
|
||||
int LUA_PushServerPlayer(lua_State *L);
|
||||
|
||||
void LUA_InvalidateUserdata(void *data);
|
||||
|
||||
void LUA_InvalidateLevel(void);
|
||||
|
|
|
|||
Loading…
Reference in a new issue