mirror of
https://github.com/UberGames/RPG-X2.git
synced 2024-11-15 01:11:46 +00:00
Started work on lua library for trace_t.
Started work on lua library for weapons.
This commit is contained in:
parent
8af8e25a22
commit
0564166919
9 changed files with 176 additions and 4 deletions
|
@ -73,7 +73,9 @@ OBJ = \
|
|||
lua_mover.o \
|
||||
lua_qmath.o \
|
||||
lua_cinematic.o \
|
||||
lua_sound.o
|
||||
lua_sound.o \
|
||||
lua_weapons.o \
|
||||
lua_trace.o
|
||||
|
||||
# game object for syscalls to the engine
|
||||
SOOBJ = \
|
||||
|
@ -172,6 +174,8 @@ lua_qmath.o: lua_qmath.c; $(DO_CC)
|
|||
lua_vector.o: lua_vector.c; $(DO_CC)
|
||||
lua_cinematic.o: lua_cinematic.c; $(DO_CC)
|
||||
lua_sound.o: lua_sound.c; $(DO_CC)
|
||||
lua_weapons.o: lua_weapons.c; $(DO_CC)
|
||||
lua_trace.o: lua_trace.c; $(DO_CC)
|
||||
|
||||
# game syscalls
|
||||
g_syscalls.o : g_syscalls.c; $(DO_CC)
|
||||
|
|
12
game/g_lua.h
12
game/g_lua.h
|
@ -58,6 +58,18 @@ int Luaopen_Entity(lua_State *L);
|
|||
void Lua_PushEntity(lua_State *L, gentity_t *ent);
|
||||
lent_t *Lua_GetEntity(lua_State *L, int argNum);
|
||||
|
||||
// lua_weapons.c
|
||||
int Luaopen_Weapons(lua_State *L);
|
||||
|
||||
// lua_trace.c
|
||||
typedef struct {
|
||||
trace_t *tr;
|
||||
} ltrace_t;
|
||||
|
||||
void Lua_PushTrace(lua_State * L, trace_t * tr);
|
||||
ltrace_t *Lua_GetTrace(lua_State * L, int argNum);
|
||||
int Luaopen_Trace(lua_State *L);
|
||||
|
||||
// lua_game.c
|
||||
int Luaopen_Game(lua_State *L);
|
||||
|
||||
|
|
|
@ -450,6 +450,8 @@
|
|||
<ClCompile Include="lua_mover.c" />
|
||||
<ClCompile Include="lua_qmath.c" />
|
||||
<ClCompile Include="lua_sound.c" />
|
||||
<ClCompile Include="lua_trace.c" />
|
||||
<ClCompile Include="lua_weapons.c" />
|
||||
<ClCompile Include="lundump.c" />
|
||||
<ClCompile Include="lvm.c" />
|
||||
<ClCompile Include="lzio.c" />
|
||||
|
|
|
@ -267,6 +267,12 @@
|
|||
<ClCompile Include="lua_sound.c">
|
||||
<Filter>Source Files\lua</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="lua_weapons.c">
|
||||
<Filter>Source Files\lua</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="lua_trace.c">
|
||||
<Filter>Source Files\lua</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="ai_chat.h">
|
||||
|
|
|
@ -879,7 +879,7 @@ void Lua_PushEntity(lua_State * L, gentity_t * ent)
|
|||
{
|
||||
lent_t *lent;
|
||||
|
||||
lent = lua_newuserdata(L, sizeof(lent_t));
|
||||
lent = (lent_t *)lua_newuserdata(L, sizeof(lent_t));
|
||||
|
||||
luaL_getmetatable(L, "game.entity");
|
||||
lua_setmetatable(L, -2);
|
||||
|
|
85
game/lua_trace.c
Normal file
85
game/lua_trace.c
Normal file
|
@ -0,0 +1,85 @@
|
|||
// lua library for trace_t
|
||||
|
||||
#include "g_lua.h"
|
||||
|
||||
#ifdef G_LUA
|
||||
static int Trace_GC(lua_State * L)
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int Trace_ToString(lua_State * L)
|
||||
{
|
||||
ltrace_t *ltrace;
|
||||
trace_t *trace;
|
||||
char buf[MAX_STRING_CHARS];
|
||||
|
||||
ltrace = Lua_GetTrace(L, 1);
|
||||
trace = ltrace->tr;
|
||||
Com_sprintf(buf, sizeof(buf), "trace: entity=%i fraction=%f allsolid=%i contents=%i endpos=\"%s\" startsolid=%i surfaceFlags=%i pointer=%p\n",
|
||||
trace->entityNum,
|
||||
trace->fraction,
|
||||
trace->allsolid,
|
||||
trace->contents,
|
||||
vtos(trace->endpos),
|
||||
trace->startsolid,
|
||||
trace->surfaceFlags,
|
||||
trace);
|
||||
lua_pushstring(L, buf);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg lib_trace[] = {
|
||||
//{"DoTrace", Trace_DoTrace},
|
||||
{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},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
int Luaopen_Trace(lua_State *L) {
|
||||
luaL_newmetatable(L, "game.trace");
|
||||
|
||||
lua_pushstring(L, "__index");
|
||||
lua_pushvalue(L, -2);
|
||||
lua_settable(L, -3);
|
||||
|
||||
luaL_register(L, NULL, Trace_meta);
|
||||
luaL_register(L, "trace", lib_trace);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void Lua_PushTrace(lua_State * L, trace_t * tr)
|
||||
{
|
||||
ltrace_t *trace;
|
||||
|
||||
trace = (ltrace_t *)lua_newuserdata(L, sizeof(ltrace_t));
|
||||
|
||||
luaL_getmetatable(L, "game.trace");
|
||||
lua_setmetatable(L, -2);
|
||||
|
||||
trace->tr = tr;
|
||||
}
|
||||
|
||||
ltrace_t *Lua_GetTrace(lua_State * L, int argNum)
|
||||
{
|
||||
void *ud;
|
||||
|
||||
ud = luaL_checkudata(L, argNum, "game.trace");
|
||||
luaL_argcheck(L, ud != NULL, argNum, "\'trace\' expected");
|
||||
return (ltrace_t *) ud;
|
||||
}
|
||||
#endif
|
|
@ -13,7 +13,7 @@
|
|||
static int Vector_New(lua_State *L) {
|
||||
vec_t *v;
|
||||
|
||||
v = lua_newuserdata(L, sizeof(vec3_t));
|
||||
v = (vec_t *)lua_newuserdata(L, sizeof(vec3_t));
|
||||
|
||||
luaL_getmetatable(L, "vector");
|
||||
lua_setmetatable(L, -2);
|
||||
|
@ -28,7 +28,7 @@ static int Vector_New(lua_State *L) {
|
|||
static int Vector_Construct(lua_State *L) {
|
||||
vec_t *v;
|
||||
|
||||
v = lua_newuserdata(L, sizeof(vec3_t));
|
||||
v = (vec_t *)lua_newuserdata(L, sizeof(vec3_t));
|
||||
|
||||
luaL_getmetatable(L, "vector");
|
||||
lua_setmetatable(L, -2);
|
||||
|
@ -177,6 +177,30 @@ static int Vector_Perpendicular(lua_State *L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int Vector_VecToAngles(lua_State *L) {
|
||||
vec_t *v, *t;
|
||||
|
||||
v = Lua_GetVector(L, 1);
|
||||
t = Lua_GetVector(L, 2);
|
||||
|
||||
vectoangles(v, t);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int Vector_AngleVectors(lua_State *L) {
|
||||
vec_t *v, *fwd, *right, *up;
|
||||
|
||||
v = Lua_GetVector(L, 1);
|
||||
fwd = Lua_GetVector(L, 2);
|
||||
right = Lua_GetVector(L, 3);
|
||||
up = Lua_GetVector(L, 4);
|
||||
|
||||
AngleVectors(v, fwd, right, up);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int Vector_Index(lua_State *L) {
|
||||
vec_t *v;
|
||||
const char *i;
|
||||
|
@ -290,6 +314,8 @@ static const luaL_Reg vector_ctor[] = {
|
|||
{"NormalizeFast", Vector_NormalizeFast},
|
||||
{"RotatePointAround", Vector_RotatePointAround},
|
||||
{"Perpendicular", Vector_Perpendicular},
|
||||
{"VecToAngles", Vector_VecToAngles },
|
||||
{"AngleVectors", Vector_AngleVectors },
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
|
|
37
game/lua_weapons.c
Normal file
37
game/lua_weapons.c
Normal file
|
@ -0,0 +1,37 @@
|
|||
// lua library for weapons
|
||||
|
||||
#include "g_lua.h"
|
||||
|
||||
#ifdef G_LUA
|
||||
static int Weapons_DoTrace(lua_State *L) {
|
||||
/*
|
||||
things that should be returned/set by this:
|
||||
* tr.entityNum
|
||||
* tr.fraction
|
||||
*/
|
||||
/*trace_t tr;
|
||||
vec_t *start, *mins, *maxs, *end;
|
||||
int passEntNum, contentMask;
|
||||
|
||||
start = Lua_GetVector(L, 1);
|
||||
mins = Lua_GetVector(L, 2);
|
||||
maxs = Lua_GetVector(L, 3);
|
||||
end = Lua_GetVector(L, 4);
|
||||
passEntNum = luaL_checknumber(L, 5);
|
||||
|
||||
trap_Trace(&tr, start, mins, maxs, end, passEntNum, contentMask);*/
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg lib_weapons[] = {
|
||||
{"DoTrace", Weapons_DoTrace},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
int Luaopen_Weapons(lua_State *L) {
|
||||
luaL_register(L, "weapons", lib_weapons);
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif
|
BIN
stefgame.suo
BIN
stefgame.suo
Binary file not shown.
Loading…
Reference in a new issue