Merge branch 'next' into more-platform-fixes

This commit is contained in:
lachwright 2020-06-17 01:47:08 +08:00
commit 2215505c2b
9 changed files with 80 additions and 39 deletions

View file

@ -11,6 +11,10 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "../doomdef.h"
#include "../lua_script.h"
#include "../w_wad.h"
#define lbaselib_c #define lbaselib_c
#define LUA_LIB #define LUA_LIB
@ -263,6 +267,27 @@ static int luaB_ipairs (lua_State *L) {
} }
// Edited to load PK3 entries instead
static int luaB_dofile (lua_State *L) {
const char *filename = luaL_checkstring(L, 1);
char fullfilename[256];
UINT16 lumpnum;
int n = lua_gettop(L);
if (wadfiles[numwadfiles - 1]->type != RET_PK3)
luaL_error(L, "dofile() only works with PK3 files");
snprintf(fullfilename, sizeof(fullfilename), "Lua/%s", filename);
lumpnum = W_CheckNumForFullNamePK3(fullfilename, numwadfiles - 1, 0);
if (lumpnum == INT16_MAX)
luaL_error(L, "can't find script " LUA_QS, fullfilename);
LUA_LoadLump(numwadfiles - 1, lumpnum, false);
return lua_gettop(L) - n;
}
static int luaB_assert (lua_State *L) { static int luaB_assert (lua_State *L) {
luaL_checkany(L, 1); luaL_checkany(L, 1);
if (!lua_toboolean(L, 1)) if (!lua_toboolean(L, 1))
@ -380,6 +405,7 @@ static const luaL_Reg base_funcs[] = {
{"assert", luaB_assert}, {"assert", luaB_assert},
{"collectgarbage", luaB_collectgarbage}, {"collectgarbage", luaB_collectgarbage},
{"error", luaB_error}, {"error", luaB_error},
{"dofile", luaB_dofile},
{"gcinfo", luaB_gcinfo}, {"gcinfo", luaB_gcinfo},
{"getfenv", luaB_getfenv}, {"getfenv", luaB_getfenv},
{"getmetatable", luaB_getmetatable}, {"getmetatable", luaB_getmetatable},

View file

@ -769,7 +769,8 @@ static void readthing(MYFILE *f, INT32 num)
static void readskincolor(MYFILE *f, INT32 num) static void readskincolor(MYFILE *f, INT32 num)
{ {
char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL); char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL);
char *word, *word2, *word3; char *word = s;
char *word2;
char *tmp; char *tmp;
Color_cons_t[num].value = num; Color_cons_t[num].value = num;
@ -781,32 +782,31 @@ static void readskincolor(MYFILE *f, INT32 num)
if (s[0] == '\n') if (s[0] == '\n')
break; break;
// First remove trailing newline, if there is one
tmp = strchr(s, '\n');
if (tmp)
*tmp = '\0';
tmp = strchr(s, '#'); tmp = strchr(s, '#');
if (tmp) if (tmp)
*tmp = '\0'; *tmp = '\0';
if (s == tmp) if (s == tmp)
continue; // Skip comment lines, but don't break. continue; // Skip comment lines, but don't break.
word = strtok(s, " "); // Get the part before the " = "
if (word) tmp = strchr(s, '=');
strupr(word); if (tmp)
*(tmp-1) = '\0';
else else
break; break;
strupr(word);
word2 = strtok(NULL, " = "); // Now get the part after
if (word2) { word2 = tmp += 2;
word3 = Z_StrDup(word2);
strupr(word2);
} else
break;
if (word2[strlen(word2)-1] == '\n')
word2[strlen(word2)-1] = '\0';
if (word3[strlen(word3)-1] == '\n')
word3[strlen(word3)-1] = '\0';
if (fastcmp(word, "NAME")) if (fastcmp(word, "NAME"))
{ {
deh_strlcpy(skincolors[num].name, word3, deh_strlcpy(skincolors[num].name, word2,
sizeof (skincolors[num].name), va("Skincolor %d: name", num)); sizeof (skincolors[num].name), va("Skincolor %d: name", num));
} }
else if (fastcmp(word, "RAMP")) else if (fastcmp(word, "RAMP"))

View file

@ -1924,7 +1924,7 @@ EXPORT void HWRAPI(CreateModelVBOs) (model_t *model)
} }
} }
#define BUFFER_OFFSET(i) ((char*)NULL + (i)) #define BUFFER_OFFSET(i) ((void*)(i))
static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 tics, INT32 nextFrameIndex, FTransform *pos, float scale, UINT8 flipped, UINT8 *color) static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 tics, INT32 nextFrameIndex, FTransform *pos, float scale, UINT8 flipped, UINT8 *color)
{ {

View file

@ -447,11 +447,13 @@ void LUA_ClearExtVars(void)
// Use this variable to prevent certain functions from running // Use this variable to prevent certain functions from running
// if they were not called on lump load // if they were not called on lump load
// (i.e. they were called in hooks or coroutines etc) // (i.e. they were called in hooks or coroutines etc)
boolean lua_lumploading = false; INT32 lua_lumploading = 0;
// Load a script from a MYFILE // Load a script from a MYFILE
static inline void LUA_LoadFile(MYFILE *f, char *name) static inline void LUA_LoadFile(MYFILE *f, char *name, boolean noresults)
{ {
int errorhandlerindex;
if (!name) if (!name)
name = wadfiles[f->wad]->filename; name = wadfiles[f->wad]->filename;
CONS_Printf("Loading Lua script from %s\n", name); CONS_Printf("Loading Lua script from %s\n", name);
@ -460,21 +462,22 @@ static inline void LUA_LoadFile(MYFILE *f, char *name)
lua_pushinteger(gL, f->wad); lua_pushinteger(gL, f->wad);
lua_setfield(gL, LUA_REGISTRYINDEX, "WAD"); lua_setfield(gL, LUA_REGISTRYINDEX, "WAD");
lua_lumploading = true; // turn on loading flag lua_lumploading++; // turn on loading flag
lua_pushcfunction(gL, LUA_GetErrorMessage); lua_pushcfunction(gL, LUA_GetErrorMessage);
if (luaL_loadbuffer(gL, f->data, f->size, va("@%s",name)) || lua_pcall(gL, 0, 0, lua_gettop(gL) - 1)) { errorhandlerindex = lua_gettop(gL);
if (luaL_loadbuffer(gL, f->data, f->size, va("@%s",name)) || lua_pcall(gL, 0, noresults ? 0 : LUA_MULTRET, lua_gettop(gL) - 1)) {
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL,-1)); CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL,-1));
lua_pop(gL,1); lua_pop(gL,1);
} }
lua_gc(gL, LUA_GCCOLLECT, 0); lua_gc(gL, LUA_GCCOLLECT, 0);
lua_pop(gL, 1); // Pop error handler lua_remove(gL, errorhandlerindex);
lua_lumploading = false; // turn off again lua_lumploading--; // turn off again
} }
// Load a script from a lump // Load a script from a lump
void LUA_LoadLump(UINT16 wad, UINT16 lump) void LUA_LoadLump(UINT16 wad, UINT16 lump, boolean noresults)
{ {
MYFILE f; MYFILE f;
char *name; char *name;
@ -501,7 +504,7 @@ void LUA_LoadLump(UINT16 wad, UINT16 lump)
name[len] = '\0'; name[len] = '\0';
} }
LUA_LoadFile(&f, name); // actually load file! LUA_LoadFile(&f, name, noresults); // actually load file!
free(name); free(name);
Z_Free(f.data); Z_Free(f.data);

View file

@ -37,10 +37,10 @@
void LUA_ClearExtVars(void); void LUA_ClearExtVars(void);
#endif #endif
extern boolean lua_lumploading; // is LUA_LoadLump being called? extern INT32 lua_lumploading; // is LUA_LoadLump being called?
int LUA_GetErrorMessage(lua_State *L); int LUA_GetErrorMessage(lua_State *L);
void LUA_LoadLump(UINT16 wad, UINT16 lump); void LUA_LoadLump(UINT16 wad, UINT16 lump, boolean noresults);
#ifdef LUA_ALLOW_BYTECODE #ifdef LUA_ALLOW_BYTECODE
void LUA_DumpFile(const char *filename); void LUA_DumpFile(const char *filename);
#endif #endif

View file

@ -5213,7 +5213,7 @@ void A_SignPlayer(mobj_t *actor)
actor->tracer->color = signcolor; actor->tracer->color = signcolor;
if (signcolor && signcolor < numskincolors) if (signcolor && signcolor < numskincolors)
signframe += (15 - skincolors[signcolor].invshade); signframe += (15 - skincolors[facecolor].invshade);
actor->tracer->frame = signframe; actor->tracer->frame = signframe;
} }

View file

@ -2291,7 +2291,6 @@ boolean P_InSpaceSector(mobj_t *mo) // Returns true if you are in space
boolean P_PlayerHitFloor(player_t *player, boolean dorollstuff) boolean P_PlayerHitFloor(player_t *player, boolean dorollstuff)
{ {
boolean clipmomz; boolean clipmomz;
CONS_Printf("Hit floor! %u\n", dorollstuff);
I_Assert(player->mo != NULL); I_Assert(player->mo != NULL);

View file

@ -880,13 +880,18 @@ boolean I_SetSongSpeed(float speed)
#ifdef HAVE_OPENMPT #ifdef HAVE_OPENMPT
if (openmpt_mhandle) if (openmpt_mhandle)
{ {
char modspd[13];
if (speed > 4.0f) if (speed > 4.0f)
speed = 4.0f; // Limit this to 4x to prevent crashing, stupid fix but... ~SteelT 27/9/19 speed = 4.0f; // Limit this to 4x to prevent crashing, stupid fix but... ~SteelT 27/9/19
#if OPENMPT_API_VERSION_MAJOR < 1 && OPENMPT_API_VERSION_MINOR < 5
sprintf(modspd, "%g", speed); {
openmpt_module_ctl_set(openmpt_mhandle, "play.tempo_factor", modspd); // deprecated in 0.5.0
char modspd[13];
sprintf(modspd, "%g", speed);
openmpt_module_ctl_set(openmpt_mhandle, "play.tempo_factor", modspd);
}
#else
openmpt_module_ctl_set_floatingpoint(openmpt_mhandle, "play.tempo_factor", (double)speed);
#endif
return true; return true;
} }
#else #else

View file

@ -199,12 +199,20 @@ static inline void W_LoadDehackedLumpsPK3(UINT16 wadnum, boolean mainfile)
{ {
UINT16 posStart, posEnd; UINT16 posStart, posEnd;
posStart = W_CheckNumForFolderStartPK3("Lua/", wadnum, 0); posStart = W_CheckNumForFullNamePK3("Init.lua", wadnum, 0);
if (posStart != INT16_MAX) if (posStart != INT16_MAX)
{ {
posEnd = W_CheckNumForFolderEndPK3("Lua/", wadnum, posStart); LUA_LoadLump(wadnum, posStart, true);
for (; posStart < posEnd; posStart++) }
LUA_LoadLump(wadnum, posStart); else
{
posStart = W_CheckNumForFolderStartPK3("Lua/", wadnum, 0);
if (posStart != INT16_MAX)
{
posEnd = W_CheckNumForFolderEndPK3("Lua/", wadnum, posStart);
for (; posStart < posEnd; posStart++)
LUA_LoadLump(wadnum, posStart, true);
}
} }
posStart = W_CheckNumForFolderStartPK3("SOC/", wadnum, 0); posStart = W_CheckNumForFolderStartPK3("SOC/", wadnum, 0);
@ -236,7 +244,7 @@ static inline void W_LoadDehackedLumps(UINT16 wadnum, boolean mainfile)
lumpinfo_t *lump_p = wadfiles[wadnum]->lumpinfo; lumpinfo_t *lump_p = wadfiles[wadnum]->lumpinfo;
for (lump = 0; lump < wadfiles[wadnum]->numlumps; lump++, lump_p++) for (lump = 0; lump < wadfiles[wadnum]->numlumps; lump++, lump_p++)
if (memcmp(lump_p->name,"LUA_",4)==0) if (memcmp(lump_p->name,"LUA_",4)==0)
LUA_LoadLump(wadnum, lump); LUA_LoadLump(wadnum, lump, true);
} }
{ {
@ -854,7 +862,7 @@ UINT16 W_InitFile(const char *filename, boolean mainfile, boolean startup)
DEH_LoadDehackedLumpPwad(numwadfiles - 1, 0, mainfile); DEH_LoadDehackedLumpPwad(numwadfiles - 1, 0, mainfile);
break; break;
case RET_LUA: case RET_LUA:
LUA_LoadLump(numwadfiles - 1, 0); LUA_LoadLump(numwadfiles - 1, 0, true);
break; break;
default: default:
break; break;