mirror of
https://github.com/UberGames/RPG-X2.git
synced 2024-11-23 04:42:06 +00:00
Finished lua trace library. Needs testing ...
This commit is contained in:
parent
0564166919
commit
93df28e396
1 changed files with 122 additions and 8 deletions
130
game/lua_trace.c
130
game/lua_trace.c
|
@ -31,21 +31,135 @@ static int Trace_ToString(lua_State * L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int Trace_DoTrace(lua_State *L) {
|
||||
trace_t *tr;
|
||||
vec_t *start, *end, *mins = NULL, *maxs = NULL;
|
||||
int passEnt, contents;
|
||||
|
||||
start = Lua_GetVector(L, 1);
|
||||
if(!lua_isnil(L, 2))
|
||||
mins = Lua_GetVector(L, 2);
|
||||
if(!lua_isnil(L, 3))
|
||||
maxs = Lua_GetVector(L, 3);
|
||||
end = Lua_GetVector(L, 4);
|
||||
passEnt = (int)luaL_checknumber(L, 5);
|
||||
contents = (int) luaL_checknumber(L, 6);
|
||||
|
||||
tr = (trace_t *)malloc(sizeof(trace_t));
|
||||
if(!tr) {
|
||||
LUA_DEBUG("Trace_DoTrace - was unable to allocate a trace_t.\n");
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
trap_Trace(tr, start, mins, maxs, end, passEnt, contents);
|
||||
|
||||
Lua_PushTrace(L, tr);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int Trace_FreeTrace(lua_State *L) {
|
||||
ltrace_t *tr;
|
||||
|
||||
tr = Lua_GetTrace(L, 1);
|
||||
if(tr && tr->tr)
|
||||
free(tr->tr);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int Trace_GetAllsolid(lua_State *L) {
|
||||
ltrace_t *tr;
|
||||
|
||||
tr = Lua_GetTrace(L, 1);
|
||||
lua_pushboolean(L, (int)tr->tr->allsolid);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int Trace_GetStartsolid(lua_State *L) {
|
||||
ltrace_t *tr;
|
||||
|
||||
tr = Lua_GetTrace(L, 1);
|
||||
lua_pushboolean(L, (int)tr->tr->startsolid);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int Trace_GetFraction(lua_State *L) {
|
||||
ltrace_t *tr;
|
||||
|
||||
tr = Lua_GetTrace(L, 1);
|
||||
lua_pushnumber(L, tr->tr->fraction);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int Trace_GetEndpos(lua_State *L) {
|
||||
ltrace_t *tr;
|
||||
|
||||
tr = Lua_GetTrace(L, 1);
|
||||
Lua_PushVector(L, tr->tr->endpos);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int Trace_GetSurfaceFlags(lua_State *L) {
|
||||
ltrace_t *tr;
|
||||
|
||||
tr = Lua_GetTrace(L, 1);
|
||||
lua_pushnumber(L, tr->tr->surfaceFlags);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int Trace_GetContents(lua_State *L) {
|
||||
ltrace_t *tr;
|
||||
|
||||
tr = Lua_GetTrace(L, 1);
|
||||
lua_pushnumber(L, tr->tr->contents);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int Trace_GetEntityNum(lua_State *L) {
|
||||
ltrace_t *tr;
|
||||
|
||||
tr = Lua_GetTrace(L, 1);
|
||||
lua_pushnumber(L, tr->tr->entityNum);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int Trace_GetEntity(lua_State *L) {
|
||||
ltrace_t *tr;
|
||||
gentity_t *ent;
|
||||
|
||||
tr = Lua_GetTrace(L, 1);
|
||||
ent = &g_entities[tr->tr->entityNum];
|
||||
Lua_PushEntity(L, ent);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg lib_trace[] = {
|
||||
//{"DoTrace", Trace_DoTrace},
|
||||
{"DoTrace", Trace_DoTrace},
|
||||
{"FreeTrace", Trace_FreeTrace},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
static const luaL_Reg Trace_meta[] = {
|
||||
{"__gc", Trace_GC},
|
||||
{"__tostring", Trace_ToString},
|
||||
//{"GetAllsolid", Trace_GetAllsolid},
|
||||
//{"GetStartsolid", Trace_GetStartsolid},
|
||||
//{"GetFraction", Trace_GetFraction},
|
||||
//{"GetEndpos", Trace_GetEndpos},
|
||||
//{"GetSurfaceFlags", Trace_GetSurfaceFlags},
|
||||
//{"GetContents", Trace_GetContents},
|
||||
//{"GetEntityNum", Trace_GetEntityNum},
|
||||
{"GetAllsolid", Trace_GetAllsolid},
|
||||
{"GetStartsolid", Trace_GetStartsolid},
|
||||
{"GetFraction", Trace_GetFraction},
|
||||
{"GetEndpos", Trace_GetEndpos},
|
||||
{"GetSurfaceFlags", Trace_GetSurfaceFlags},
|
||||
{"GetContents", Trace_GetContents},
|
||||
{"GetEntityNum", Trace_GetEntityNum},
|
||||
{"GetEntity", Trace_GetEntity},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue