diff --git a/cgame/Makefile b/cgame/Makefile index bc8a7e8..fed1507 100644 --- a/cgame/Makefile +++ b/cgame/Makefile @@ -59,6 +59,8 @@ OBJ = \ cg_lua.o \ lua_vector.o \ lua_qmath.o \ + lua_cfx.o \ + lua_cent.o \ # depency objects from game OBJDEP = \ @@ -151,6 +153,8 @@ fx_tetrion.o : fx_tetrion.c; $(DO_CC) fx_transporter.o : fx_transporter.c; $(DO_CC) lua_qmath.o: ../game/lua_qmath.c; $(DO_CC) lua_vector.o: ../game/lua_vector.c; $(DO_CC) +lua_cfx.o: lua_cfx.c; $(DO_CC) +lua_cent.o: lua_cent.c; $(DO_CC) # dependencies from game q_shared.o: ../game/q_shared.c; $(DO_CC) diff --git a/cgame/cg_lua.c b/cgame/cg_lua.c index 4f4a301..1281e63 100644 --- a/cgame/cg_lua.c +++ b/cgame/cg_lua.c @@ -2,13 +2,7 @@ #include "cg_lua.h" -#ifdef G_LUA - -#if defined(__linux__) || defined(__WIN32__) || defined(__APPLE__) || 1 /* linux, mingw32, OS X - the 1 is temporary*/ -#include /* Note the MSVC project assumes mingw is installed at C:\MinGW\include */ -#else // MSVC -// TODO: I don't care much about MSVC as I user mingw on Windows to compile :P -#endif +#ifdef CG_LUA lvm_t *lVM[NUM_VMS]; fileHandle_t lualog; @@ -105,24 +99,17 @@ qboolean LoadLuaFile(char *path, int num_vm) qboolean CG_LuaInit() { - #if defined(__linux__) || defined(__WIN32__) || defined(__APPLE__) || 1 /* linux, mingw32, OS X - the 1 is temporary*/ - DIR *pdir = NULL; - struct dirent *pent = NULL; - #else // MSVC - - #endif - + char fxfilename[MAX_QPATH]; + fileHandle_t fxfile; + CG_Printf("------- CG_LuaInit -------\n"); - #if defined(__linux__) || defined(__WIN32__) || defined(__APPLE__) || 1 /* linux, mingw32, OS X - the 1 is temporary*/ + // read map fx file - #else // MSVC - #endif - - // not much to do for now + // open log file if(cg_logLua.integer) { - trap_FS_FOpenFile("./cg_lua.log", &lualog, FS_APPEND); + trap_FS_FOpenFile("cg_lua.log", &lualog, FS_APPEND); } CG_Printf("------- CG_LuaInit Finish -------\n"); diff --git a/cgame/cg_lua.h b/cgame/cg_lua.h index a11ebaa..50de858 100644 --- a/cgame/cg_lua.h +++ b/cgame/cg_lua.h @@ -66,4 +66,36 @@ void Lua_PushVector(lua_State *L, vec3_t v); vec_t *Lua_GetVector(lua_State *L, int argNum); int Lua_IsVector(lua_State *L, int index); vec3_t *Lua_GetVectorMisc(lua_State *L, int *index); + +// lua_cfx.c +typedef struct { + char luaFunc[MAX_QPATH]; +} cfx_t; + +#ifdef QVM +#define MAX_CFX_CNT 32 + +typedef struct { + cfx_t *cfx[MAX_CFX_CNT]; + int cnt; +} cfxList_t; +#else +typedef struct { + cfx_t **cfx; + int cnt; +} cfxList_t; +#endif + +void Lua_CFX_LoadMapFxFile(void); + +// lua_cent.c +typedef struct { + centity_t *e; +} cent_t; + +int Luaopen_Cent(lua_State *L); +void Lua_PushCent(lua_State *L, centity_t *ent); +cent_t *Lua_GetCent(lua_State *L, int argNum); +// lua_refent.c + #endif diff --git a/cgame/lua_cent.c b/cgame/lua_cent.c new file mode 100644 index 0000000..77f4e1f --- /dev/null +++ b/cgame/lua_cent.c @@ -0,0 +1,75 @@ +#include "cg_lua.h" + +#ifdef CG_LUA +static int Cent_GC(lua_State * L) +{ + + return 0; +} + +static int Cent_ToString(lua_State * L) +{ + cent_t *cent; + centity_t *ent; + char buf[MAX_STRING_CHARS]; + + cent = Lua_GetCent(L, 1); + ent = cent->e; + Com_sprintf(buf, sizeof(buf), "centity: id=%d pointer=%p\n", ent - cg_entities, ent); + lua_pushstring(L, buf); + + return 1; +} + +static const luaL_Reg Centity_ctor[] = { + {NULL, NULL} +}; + +static const luaL_Reg Centity_meta[] = { + {"__gc", Cent_GC}, + {"__tostring", Cent_ToString}, + + {NULL, NULL} +}; + +/*void dummy(gentity_t *ent) { + ent->timestamp; +}*/ + +int Luaopen_Cent(lua_State * L) +{ + luaL_newmetatable(L, "cgame.centity"); + + lua_pushstring(L, "__index"); + lua_pushvalue(L, -2); + lua_settable(L, -3); + + luaL_register(L, NULL, Centity_meta); + luaL_register(L, "centity", Centity_ctor); + + return 1; +} + +void Lua_PushCent(lua_State * L, centity_t * ent) +{ + cent_t *cent; + + if(!ent) + lua_pushnil(L); + else { + cent = (cent_t *)lua_newuserdata(L, sizeof(cent_t)); + luaL_getmetatable(L, "cgame.centity"); + lua_setmetatable(L, -2); + cent->e = ent; + } +} + +cent_t *Lua_GetCent(lua_State * L, int argNum) +{ + void *ud; + + ud = luaL_checkudata(L, argNum, "cgame.centity"); + luaL_argcheck(L, ud != NULL, argNum, "\'centity\' expected"); + return (cent_t *) ud; +} +#endif diff --git a/cgame/lua_cfx.c b/cgame/lua_cfx.c new file mode 100644 index 0000000..bb269a6 --- /dev/null +++ b/cgame/lua_cfx.c @@ -0,0 +1,19 @@ +#include "cg_lua.h" + +#ifdef CG_LUA + +void Lua_CFX_ParseMapFxFile(fileHandle_t *f) { + // TODO +} + +void Lua_CFX_LoadMapFxFile(void) { + char filename[MAX_QPATH]; + fileHandle_t file; + + sprintf(filename, "maps/%s.fx", cgs.mapname); + trap_FS_FOpenFile(filename, &file, FS_READ); + if(!file) return; + + Lua_CFX_ParseMapFxFile(&file); +} +#endif diff --git a/stefgame.suo b/stefgame.suo index 5a07a27..d0f655b 100644 Binary files a/stefgame.suo and b/stefgame.suo differ