Compare commits
62
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa27dfe325 | ||
|
|
74efc7ffe2 | ||
|
|
f52bd1df3f | ||
|
|
09942ec48f | ||
|
|
14c63c28b1 | ||
|
|
709c0dc69a | ||
|
|
b9036384d5 | ||
|
|
6b9730bf49 | ||
|
|
4e235ddb0c | ||
|
|
2ee97c6395 | ||
|
|
dd1042e68b | ||
|
|
7684e6aa07 | ||
|
|
0fb752b745 | ||
|
|
c418fe3ef8 | ||
|
|
fdccc80260 | ||
|
|
84be9096b1 | ||
|
|
e4e51f0f80 | ||
|
|
7c0f296fcf | ||
|
|
11f78bc21f | ||
|
|
b84e3cdb7c | ||
|
|
e551c1c1ff | ||
|
|
9cadd991f9 | ||
|
|
fed7020da1 | ||
|
|
1a4255d9df | ||
|
|
f6ead71f0c | ||
|
|
966f60f590 | ||
|
|
9afc018a45 | ||
|
|
43608810da | ||
|
|
90b5f9050a | ||
|
|
edc10a35a1 | ||
|
|
91435fe1b2 | ||
|
|
a7ebc7e745 | ||
|
|
ce0bddcbec | ||
|
|
9af6fc3b33 | ||
|
|
467ecf8224 | ||
|
|
2077315f24 | ||
|
|
9bea6eddbd | ||
|
|
f4e5f7249c | ||
|
|
a05413d925 | ||
|
|
8a8cbffd12 | ||
|
|
1fb6c63097 | ||
|
|
c312380944 | ||
|
|
b5bb2b42bf | ||
|
|
d074f375ca | ||
|
|
6fd14f0a80 | ||
|
|
d6bbb2c1b3 | ||
|
|
fa66b87965 | ||
|
|
c59d5db03e | ||
|
|
b6edc90553 | ||
|
|
23735121ff | ||
|
|
20950b698f | ||
|
|
44df85d6a4 | ||
|
|
42d53f1f6f | ||
|
|
48f2d0ff83 | ||
|
|
517723f9c1 | ||
|
|
6915077e0f | ||
|
|
406dbf333d | ||
|
|
a730dfd212 | ||
|
|
3058d365f3 | ||
|
|
ccc453e0b0 | ||
|
|
c3d02090e4 | ||
|
|
20cd7621c3 |
No files matched your search
+38
-17
@@ -519,6 +519,23 @@ LUA_API int lua_pushthread (lua_State *L) {
|
||||
** get functions (Lua -> stack)
|
||||
*/
|
||||
|
||||
static void auxgetstr (lua_State *L, TValue *t, const char *k) {
|
||||
TValue *slot;
|
||||
TValue key;
|
||||
TString *str = luaS_new(L, k);
|
||||
api_checkvalidindex(L, t);
|
||||
if (luaV_fastget(L, t, str, slot, luaH_getstr)) {
|
||||
setobj2s(L, L->top, slot);
|
||||
api_incr_top(L);
|
||||
}
|
||||
else {
|
||||
setsvalue(L, &key, str);
|
||||
luaV_finishget(L, t, L->top, L->top, slot);
|
||||
api_incr_top(L);
|
||||
}
|
||||
lua_unlock(L);
|
||||
}
|
||||
|
||||
|
||||
LUA_API void lua_gettable (lua_State *L, int idx) {
|
||||
StkId t;
|
||||
@@ -531,15 +548,8 @@ LUA_API void lua_gettable (lua_State *L, int idx) {
|
||||
|
||||
|
||||
LUA_API void lua_getfield (lua_State *L, int idx, const char *k) {
|
||||
StkId t;
|
||||
TValue key;
|
||||
lua_lock(L);
|
||||
t = index2adr(L, idx);
|
||||
api_checkvalidindex(L, t);
|
||||
setsvalue(L, &key, luaS_new(L, k));
|
||||
luaV_gettable(L, t, &key, L->top);
|
||||
api_incr_top(L);
|
||||
lua_unlock(L);
|
||||
auxgetstr(L, index2adr(L, idx), k);
|
||||
}
|
||||
|
||||
|
||||
@@ -631,6 +641,25 @@ LUA_API void lua_getfenv (lua_State *L, int idx) {
|
||||
*/
|
||||
|
||||
|
||||
static void auxsetstr (lua_State *L, TValue *t, const char *k) {
|
||||
TValue key;
|
||||
TValue *slot;
|
||||
TString *str = luaS_new(L, k);
|
||||
api_checknelems(L, 1);
|
||||
api_checkvalidindex(L, t);
|
||||
if (luaV_fastset(L, t, str, slot, luaH_setstr, L->top)) {
|
||||
setobj2t(L, cast(TValue *, slot), L->top - 1);
|
||||
L->top--; /* pop value */
|
||||
}
|
||||
else {
|
||||
setsvalue2s(L, &key, str);
|
||||
luaV_finishset(L, t, &key, L->top - 1, slot);
|
||||
L->top--; /* pop value */
|
||||
}
|
||||
lua_unlock(L);
|
||||
}
|
||||
|
||||
|
||||
LUA_API void lua_settable (lua_State *L, int idx) {
|
||||
StkId t;
|
||||
lua_lock(L);
|
||||
@@ -644,16 +673,8 @@ LUA_API void lua_settable (lua_State *L, int idx) {
|
||||
|
||||
|
||||
LUA_API void lua_setfield (lua_State *L, int idx, const char *k) {
|
||||
StkId t;
|
||||
TValue key;
|
||||
lua_lock(L);
|
||||
api_checknelems(L, 1);
|
||||
t = index2adr(L, idx);
|
||||
api_checkvalidindex(L, t);
|
||||
setsvalue(L, &key, luaS_new(L, k));
|
||||
luaV_settable(L, t, &key, L->top - 1);
|
||||
L->top--; /* pop value */
|
||||
lua_unlock(L);
|
||||
auxsetstr(L, index2adr(L, idx), k);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+15
-3
@@ -20,6 +20,7 @@
|
||||
#define lauxlib_c
|
||||
#define LUA_LIB
|
||||
|
||||
#include "ldebug.h"
|
||||
#include "lua.h"
|
||||
|
||||
#include "lauxlib.h"
|
||||
@@ -468,8 +469,19 @@ LUALIB_API char *luaL_prepbuffer (luaL_Buffer *B) {
|
||||
|
||||
|
||||
LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) {
|
||||
while (l--)
|
||||
luaL_addchar(B, *s++);
|
||||
while (l) {
|
||||
size_t space = bufffree(B);
|
||||
if (space == 0) {
|
||||
luaL_prepbuffer(B);
|
||||
lua_assert(bufffree(B) == LUAL_BUFFERSIZE);
|
||||
space = LUAL_BUFFERSIZE;
|
||||
}
|
||||
if (space > l) space = l;
|
||||
memcpy(B->p, s, space);
|
||||
B->p += space;
|
||||
s += space;
|
||||
l -= space;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -686,6 +698,6 @@ static int panic (lua_State *L) {
|
||||
|
||||
LUALIB_API lua_State *luaL_newstate (void) {
|
||||
lua_State *L = lua_newstate(l_alloc, NULL);
|
||||
if (L) lua_atpanic(L, &panic);
|
||||
if (l_likely(L)) lua_atpanic(L, &panic);
|
||||
return L;
|
||||
}
|
||||
+25
-12
@@ -626,8 +626,20 @@ static void codenot (FuncState *fs, expdesc *e) {
|
||||
removevalues(fs, e->t);
|
||||
}
|
||||
|
||||
/*
|
||||
** Check whether expression 'e' is a literal string
|
||||
*/
|
||||
static int isKstr (FuncState *fs, expdesc *e) {
|
||||
return (e->k == VK && ttisstring(&fs->f->k[e->u.s.info]));
|
||||
}
|
||||
|
||||
/*
|
||||
** Create expression 't[k]'. 't' must have its final result already in a
|
||||
** register or upvalue. Upvalues can only be indexed by literal strings.
|
||||
*/
|
||||
void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {
|
||||
if (t->k == VUPVAL && !isKstr(fs, k)) /* upvalue indexed by non string? */
|
||||
luaK_exp2anyreg(fs, t); /* put it in a register */
|
||||
t->u.s.aux = luaK_exp2RK(fs, k);
|
||||
t->k = VINDEXED;
|
||||
}
|
||||
@@ -790,18 +802,19 @@ void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) {
|
||||
case OPR_BXOR: codearith(fs, OP_BXOR, e1, e2); break;
|
||||
case OPR_BSHL: codearith(fs, OP_BSHL, e1, e2); break;
|
||||
case OPR_BSHR: codearith(fs, OP_BSHR, e1, e2); break;
|
||||
case OPR_ADD: codearith(fs, OP_ADD, e1, e2); break;
|
||||
case OPR_SUB: codearith(fs, OP_SUB, e1, e2); break;
|
||||
case OPR_MUL: codearith(fs, OP_MUL, e1, e2); break;
|
||||
case OPR_DIV: codearith(fs, OP_DIV, e1, e2); break;
|
||||
case OPR_MOD: codearith(fs, OP_MOD, e1, e2); break;
|
||||
case OPR_POW: codearith(fs, OP_POW, e1, e2); break;
|
||||
case OPR_EQ: codecomp(fs, OP_EQ, 1, e1, e2); break;
|
||||
case OPR_NE: codecomp(fs, OP_EQ, 0, e1, e2); break;
|
||||
case OPR_LT: codecomp(fs, OP_LT, 1, e1, e2); break;
|
||||
case OPR_LE: codecomp(fs, OP_LE, 1, e1, e2); break;
|
||||
case OPR_GT: codecomp(fs, OP_LT, 0, e1, e2); break;
|
||||
case OPR_GE: codecomp(fs, OP_LE, 0, e1, e2); break;
|
||||
case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:
|
||||
case OPR_MOD: case OPR_POW: {
|
||||
codearith(fs, op - OPR_ADD + OP_ADD, e1, e2);
|
||||
break;
|
||||
}
|
||||
case OPR_EQ: case OPR_LT: case OPR_LE: {
|
||||
codecomp(fs, op - OPR_EQ + OP_EQ, 1, e1, e2);
|
||||
break;
|
||||
}
|
||||
case OPR_NE: case OPR_GT: case OPR_GE: {
|
||||
codecomp(fs, op - OPR_NE + OP_EQ, 0, e1, e2);
|
||||
break;
|
||||
}
|
||||
default: lua_assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -21,13 +21,13 @@
|
||||
|
||||
|
||||
/*
|
||||
** grep "ORDER OPR" if you change these enums
|
||||
** grep "ORDER OPR" if you change these enums (ORDER OP)
|
||||
*/
|
||||
typedef enum BinOpr {
|
||||
OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW,
|
||||
OPR_CONCAT,
|
||||
OPR_NE, OPR_EQ,
|
||||
OPR_LT, OPR_LE, OPR_GT, OPR_GE,
|
||||
OPR_EQ, OPR_LT, OPR_LE,
|
||||
OPR_NE, OPR_GT, OPR_GE,
|
||||
OPR_AND, OPR_OR,
|
||||
OPR_BAND, OPR_BOR, OPR_BXOR,
|
||||
OPR_BSHL, OPR_BSHR,
|
||||
|
||||
+28
-5
@@ -542,16 +542,39 @@ static const char *getobjname (lua_State *L, CallInfo *ci, int stackpos,
|
||||
|
||||
|
||||
static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) {
|
||||
TMS tm = 0;
|
||||
Instruction i;
|
||||
if ((isLua(ci) && ci->tailcalls > 0) || !isLua(ci - 1))
|
||||
return NULL; /* calling function is not Lua (or is unknown) */
|
||||
ci--; /* calling function */
|
||||
i = ci_func(ci)->l.p->code[currentpc(L, ci)];
|
||||
if (GET_OPCODE(i) == OP_CALL || GET_OPCODE(i) == OP_TAILCALL ||
|
||||
GET_OPCODE(i) == OP_TFORLOOP)
|
||||
return getobjname(L, ci, GETARG_A(i), name);
|
||||
else
|
||||
return NULL; /* no useful name can be found */
|
||||
switch (GET_OPCODE(i)) {
|
||||
case OP_CALL:
|
||||
case OP_TAILCALL:
|
||||
case OP_TFORLOOP:
|
||||
return getobjname(L, ci, GETARG_A(i), name);
|
||||
case OP_GETGLOBAL:
|
||||
case OP_SELF:
|
||||
case OP_GETTABLE: tm = TM_INDEX; break;
|
||||
case OP_SETGLOBAL:
|
||||
case OP_SETTABLE: tm = TM_NEWINDEX; break;
|
||||
case OP_EQ: tm = TM_EQ; break;
|
||||
case OP_ADD: tm = TM_ADD; break;
|
||||
case OP_SUB: tm = TM_SUB; break;
|
||||
case OP_MUL: tm = TM_MUL; break;
|
||||
case OP_DIV: tm = TM_DIV; break;
|
||||
case OP_MOD: tm = TM_MOD; break;
|
||||
case OP_POW: tm = TM_POW; break;
|
||||
case OP_UNM: tm = TM_UNM; break;
|
||||
case OP_LEN: tm = TM_LEN; break;
|
||||
case OP_LT: tm = TM_LT; break;
|
||||
case OP_LE: tm = TM_LE; break;
|
||||
case OP_CONCAT: tm = TM_CONCAT; break;
|
||||
default:
|
||||
return NULL; /* else no useful name can be found */
|
||||
}
|
||||
*name = getstr(G(L)->tmname[tm]);
|
||||
return "metamethod";
|
||||
}
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -164,7 +164,7 @@ void luaD_reallocCI (lua_State *L, int newsize) {
|
||||
|
||||
|
||||
void luaD_growstack (lua_State *L, int n) {
|
||||
if (l_likely(n <= L->stacksize)) /* double size is enough? */
|
||||
if (n <= L->stacksize) /* double size is enough? */
|
||||
luaD_reallocstack(L, 2*L->stacksize);
|
||||
else
|
||||
luaD_reallocstack(L, L->stacksize + n);
|
||||
@@ -318,7 +318,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) {
|
||||
ci->top = L->top + LUA_MINSTACK;
|
||||
lua_assert(ci->top <= L->stack_last);
|
||||
ci->nresults = nresults;
|
||||
if (L->hookmask & LUA_MASKCALL)
|
||||
if (l_unlikely(L->hookmask & LUA_MASKCALL))
|
||||
luaD_callhook(L, LUA_HOOKCALL, -1);
|
||||
lua_unlock(L);
|
||||
n = (*curr_func(L)->c.f)(L); /* do the actual call */
|
||||
|
||||
+10
-9
@@ -356,20 +356,21 @@ static int read_line (lua_State *L, FILE *f) {
|
||||
|
||||
|
||||
static int read_chars (lua_State *L, FILE *f, size_t n) {
|
||||
size_t rlen; /* how much to read */
|
||||
size_t nr; /* number of chars actually read */
|
||||
size_t tbr = n; /* number of chars to be read */
|
||||
size_t rlen; /* how much to read in each cycle */
|
||||
size_t nr; /* number of chars actually read in each cycle */
|
||||
luaL_Buffer b;
|
||||
luaL_buffinit(L, &b);
|
||||
rlen = LUAL_BUFFERSIZE; /* try to read that much each time */
|
||||
do {
|
||||
char *p = luaL_prepbuffer(&b);
|
||||
if (rlen > n) rlen = n; /* cannot read more than asked */
|
||||
if (rlen > tbr) rlen = tbr; /* cannot read more than asked */
|
||||
nr = fread(p, sizeof(char), rlen, f);
|
||||
luaL_addsize(&b, nr);
|
||||
n -= nr; /* still have to read `n' chars */
|
||||
} while (n > 0 && nr == rlen); /* until end of count or eof */
|
||||
tbr -= nr; /* still have to read 'tbr' chars */
|
||||
} while (tbr > 0 && nr == rlen); /* until end of count or eof */
|
||||
luaL_pushresult(&b); /* close buffer */
|
||||
return (n == 0 || lua_objlen(L, -1) > 0);
|
||||
return (tbr == 0 || tbr < n); /* true iff read something */
|
||||
}
|
||||
|
||||
|
||||
@@ -432,13 +433,13 @@ static int f_read (lua_State *L) {
|
||||
|
||||
static int io_readline (lua_State *L) {
|
||||
FILE *f = *(FILE **)lua_touserdata(L, lua_upvalueindex(1));
|
||||
int sucess;
|
||||
int success;
|
||||
if (f == NULL) /* file is already closed? */
|
||||
luaL_error(L, "file is already closed");
|
||||
sucess = read_line(L, f);
|
||||
success = read_line(L, f);
|
||||
if (ferror(f))
|
||||
return luaL_error(L, "%s", strerror(errno));
|
||||
if (sucess) return 1;
|
||||
if (success) return 1;
|
||||
else { /* EOF */
|
||||
if (lua_toboolean(L, lua_upvalueindex(2))) { /* generator created file? */
|
||||
lua_settop(L, 0);
|
||||
|
||||
@@ -232,6 +232,8 @@ OP_VARARG/* A B R(A), R(A+1), ..., R(A+B-1) = vararg */
|
||||
(*) In OP_SETLIST, if (B == 0) then B = `top';
|
||||
if (C == 0) then next `instruction' is real C
|
||||
|
||||
(*) In OP_SELF, the index must be a string.
|
||||
|
||||
(*) For comparisons, A specifies what condition the test should accept
|
||||
(true or false).
|
||||
|
||||
|
||||
+4
-4
@@ -881,10 +881,10 @@ static const struct {
|
||||
lu_byte right; /* right priority */
|
||||
} priority[] = { /* ORDER OPR */
|
||||
{6, 6}, {6, 6}, {7, 7}, {7, 7}, {7, 7}, /* `+' `-' `/' `%' */
|
||||
{10, 9}, {5, 4}, /* power and concat (right associative) */
|
||||
{3, 3}, {3, 3}, /* equality and inequality */
|
||||
{3, 3}, {3, 3}, {3, 3}, {3, 3}, /* order */
|
||||
{2, 2}, {1, 1} /* logical (and/or) */
|
||||
{10, 9}, {5, 4}, /* ^, .. (right associative) */
|
||||
{3, 3}, {3, 3}, {3, 3}, /* ==, <, <= */
|
||||
{3, 3}, {3, 3}, {3, 3}, /* ~=, >, >= */
|
||||
{2, 2}, {1, 1} /* and, or */
|
||||
,{6, 6}, {6, 6}, {6, 6}, /* bit-wise (band/bor/bxor) */
|
||||
{7, 7}, {7, 7} /* shl/shr */
|
||||
};
|
||||
|
||||
+58
-4
@@ -51,7 +51,7 @@ static TString *newlstr (lua_State *L, const char *str, size_t l,
|
||||
unsigned int h) {
|
||||
TString *ts;
|
||||
stringtable *tb;
|
||||
if (l+1 > (MAX_SIZET - sizeof(TString))/sizeof(char))
|
||||
if (l_unlikely(l+1 > (MAX_SIZET - sizeof(TString))/sizeof(char)))
|
||||
luaM_toobig(L);
|
||||
ts = cast(TString *, luaM_malloc(L, (l+1)*sizeof(char)+sizeof(TString)));
|
||||
ts->tsv.len = l;
|
||||
@@ -72,18 +72,72 @@ static TString *newlstr (lua_State *L, const char *str, size_t l,
|
||||
}
|
||||
|
||||
|
||||
TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
|
||||
GCObject *o;
|
||||
// string hash taken from luaJIT
|
||||
|
||||
/* Unaligned load of uint32_t. */
|
||||
static inline __attribute__((always_inline)) uint32_t getu32(const void* ptr)
|
||||
{
|
||||
uint32_t result;
|
||||
memcpy(&result, ptr, 4);
|
||||
return result;
|
||||
}
|
||||
|
||||
// smol macro to look a little less messy lul
|
||||
#define getu8(p) *cast(const uint8_t *, p)
|
||||
|
||||
/* Keyed sparse ARX string hash. Constant time. */
|
||||
static unsigned hash_sparse(const char *str, size_t len)
|
||||
{
|
||||
/* Constants taken from lookup3 hash by Bob Jenkins. */
|
||||
unsigned int a, b, h = cast(unsigned int, len);
|
||||
#define rol(x, n) (((x)<<(n)) | ((x)>>(-cast(int, n)&(8*sizeof(x)-1))))
|
||||
if (len >= 4) { /* Caveat: unaligned access! */
|
||||
a = getu32(str);
|
||||
h ^= getu32(str+len-4);
|
||||
b = getu32(str+(len>>1)-2);
|
||||
h ^= b; h -= rol(b, 14);
|
||||
b += getu32(str+(len>>2)-1);
|
||||
} else if (len > 0) {
|
||||
a = getu8(str);
|
||||
h ^= getu8(str+len-1);
|
||||
b = getu8(str+(len>>1));
|
||||
h ^= b; h -= rol(b, 14);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
a ^= h; a -= rol(h, 11);
|
||||
b ^= a; b -= rol(a, 25);
|
||||
h ^= b; h -= rol(b, 16);
|
||||
#undef rol
|
||||
return h;
|
||||
}
|
||||
|
||||
#undef getu8
|
||||
|
||||
|
||||
static inline __attribute__((always_inline)) unsigned luaS_hash (const char *str, size_t l) {
|
||||
#if 0
|
||||
unsigned int h = cast(unsigned int, l); /* seed */
|
||||
size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */
|
||||
size_t l1;
|
||||
for (l1=l; l1>=step; l1-=step) /* compute hash */
|
||||
h = h ^ ((h<<5)+(h>>2)+cast(unsigned char, str[l1-1]));
|
||||
return h;
|
||||
#else
|
||||
return hash_sparse(str, l);
|
||||
#endif
|
||||
}
|
||||
|
||||
TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
|
||||
GCObject *o;
|
||||
unsigned int h = luaS_hash(str, l);
|
||||
for (o = G(L)->strt.hash[lmod(h, G(L)->strt.size)];
|
||||
o != NULL;
|
||||
o = o->gch.next) {
|
||||
TString *ts = rawgco2ts(o);
|
||||
if (l_unlikely(ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0))) {
|
||||
if (ts->tsv.hash == h &&
|
||||
ts->tsv.len == l &&
|
||||
(memcmp(str, getstr(ts), l) == 0)) {
|
||||
/* string may be dead */
|
||||
if (isdead(G(L), o)) changewhite(o);
|
||||
return ts;
|
||||
|
||||
+135
-51
@@ -28,7 +28,7 @@
|
||||
|
||||
|
||||
|
||||
/* limit for table tag-method chains (to avoid loops) */
|
||||
/* limit for table tag-method chains (to avoid infinite loops) */
|
||||
#define MAXTAGLOOP 100
|
||||
|
||||
|
||||
@@ -105,57 +105,88 @@ static void callTM (lua_State *L, const TValue *f, const TValue *p1,
|
||||
}
|
||||
|
||||
|
||||
void luaV_gettable (lua_State *L, TValue *t, TValue *key, StkId val) {
|
||||
int loop;
|
||||
/*
|
||||
** Finish the table access 'val = t[key]'.
|
||||
** if 'slot' is NULL, 't' is not a table; otherwise, 'slot' points to
|
||||
** t[k] entry (which must be nil).
|
||||
*/
|
||||
void luaV_finishget (lua_State *L, TValue *t, TValue *key, StkId val,
|
||||
TValue *slot) {
|
||||
int loop; /* counter to avoid infinite loops */
|
||||
TValue *tm; /* metamethod */
|
||||
for (loop = 0; loop < MAXTAGLOOP; loop++) {
|
||||
TValue *tm;
|
||||
if (ttistable(t)) { /* `t' is a table? */
|
||||
Table *h = hvalue(t);
|
||||
const TValue *res = luaH_get(h, key); /* do a primitive get */
|
||||
if (!ttisnil(res) || /* result is no nil? */
|
||||
(tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */
|
||||
setobj2s(L, val, res);
|
||||
if (slot == NULL) { /* 't' is not a table? */
|
||||
lua_assert(!ttistable(t));
|
||||
tm = luaT_gettmbyobj(L, t, TM_INDEX);
|
||||
if (l_unlikely(ttisnil(tm)))
|
||||
luaG_typeerror(L, t, "index"); /* no metamethod */
|
||||
/* else will try the metamethod */
|
||||
}
|
||||
else { /* 't' is a table */
|
||||
lua_assert(ttisnil(slot));
|
||||
tm = fasttm(L, hvalue(t)->metatable, TM_INDEX); /* table's metamethod */
|
||||
if (tm == NULL) { /* no metamethod? */
|
||||
setnilvalue(val); /* result is nil */
|
||||
return;
|
||||
}
|
||||
/* else will try the tag method */
|
||||
/* else will try the metamethod */
|
||||
}
|
||||
else if (l_unlikely(ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX))))
|
||||
luaG_typeerror(L, t, "index");
|
||||
if (ttisfunction(tm)) {
|
||||
callTMres(L, val, tm, t, key);
|
||||
if (ttisfunction(tm)) { /* is metamethod a function? */
|
||||
callTMres(L, val, tm, t, key); /* call it */
|
||||
return;
|
||||
}
|
||||
t = tm; /* else repeat with `tm' */
|
||||
t = tm; /* else try to access 'tm[key]' */
|
||||
if (luaV_fastget(L,t,key,slot,luaH_get)) { /* fast track? */
|
||||
setobj2s(L, val, slot); /* done */
|
||||
return;
|
||||
}
|
||||
/* else repeat (tail call 'luaV_finishget') */
|
||||
}
|
||||
luaG_runerror(L, "loop in gettable");
|
||||
luaG_runerror(L, "'__index' chain too long; possible loop");
|
||||
}
|
||||
|
||||
|
||||
void luaV_settable (lua_State *L, TValue *t, TValue *key, StkId val) {
|
||||
int loop;
|
||||
/*
|
||||
** Finish a table assignment 't[key] = val'.
|
||||
** If 'slot' is NULL, 't' is not a table. Otherwise, 'slot' points
|
||||
** to the entry 't[key]', or to 'luaO_nilobject' if there is no such
|
||||
** entry. (The value at 'slot' must be nil, otherwise 'luaV_fastset'
|
||||
** would have done the job.)
|
||||
*/
|
||||
void luaV_finishset (lua_State *L, TValue *t, TValue *key,
|
||||
StkId val, TValue *slot) {
|
||||
int loop; /* counter to avoid infinite loops */
|
||||
for (loop = 0; loop < MAXTAGLOOP; loop++) {
|
||||
TValue *tm = NULL;
|
||||
if (ttistable(t)) { /* `t' is a table? */
|
||||
TValue *tm;
|
||||
if (slot != NULL) {
|
||||
lua_assert(ttistable(t) && ttisnil(slot));
|
||||
Table *h = hvalue(t);
|
||||
TValue *oldval = luaH_set(L, h, key); /* do a primitive set */
|
||||
/* oldval is nil=> look for newindex, oldval is not nil => look for usedindex */
|
||||
if (!((ttisnil(oldval) && ((tm = fasttm(L, h->metatable, TM_NEWINDEX)) != NULL)) ||
|
||||
((!ttisnil(oldval)) && ((tm = fasttm(L, h->metatable, TM_USEDINDEX)) != NULL)))) {
|
||||
setobj2t(L, oldval, val);
|
||||
/* must check the metamethod */
|
||||
/* slot is nil=> look for newindex, slot is not nil => look for usedindex */
|
||||
if (!((ttisnil(slot) && ((tm = fasttm(L, h->metatable, TM_NEWINDEX)) != NULL)) ||
|
||||
((!ttisnil(slot)) && ((tm = fasttm(L, h->metatable, TM_USEDINDEX)) != NULL)))) {
|
||||
/* no metamethod and (now) there is an entry with given key */
|
||||
setobj2t(L, cast(TValue *, slot), val);
|
||||
luaC_barriert(L, h, val);
|
||||
return;
|
||||
}
|
||||
/* else will try the tag method */
|
||||
/* else will try the metamethod */
|
||||
}
|
||||
else if (l_unlikely(ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX))))
|
||||
luaG_typeerror(L, t, "index");
|
||||
else { /* not a table; check metamethod */
|
||||
if (l_unlikely(ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX))))
|
||||
luaG_typeerror(L, t, "index");
|
||||
}
|
||||
/* try the metamethod */
|
||||
if (ttisfunction(tm)) {
|
||||
callTM(L, tm, t, key, val);
|
||||
return;
|
||||
}
|
||||
t = tm; /* else repeat with `tm' */
|
||||
t = tm; /* else repeat assignment over 'tm' */
|
||||
if (luaV_fastset(L, t, key, slot, luaH_set, val))
|
||||
return; /* done */
|
||||
/* else loop */
|
||||
}
|
||||
luaG_runerror(L, "loop in settable");
|
||||
luaG_runerror(L, "settable chain too long; possible loop");
|
||||
}
|
||||
|
||||
|
||||
@@ -366,6 +397,7 @@ static void Arith (lua_State *L, StkId ra, TValue *rb,
|
||||
|
||||
|
||||
#define arith_op(op,tm) { \
|
||||
StkId ra = RA(i); \
|
||||
TValue *rb = RKB(i); \
|
||||
TValue *rc = RKC(i); \
|
||||
if (ttisnumber(rb) && ttisnumber(rc)) { \
|
||||
@@ -377,6 +409,21 @@ static void Arith (lua_State *L, StkId ra, TValue *rb,
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** copy of 'luaV_gettable', but protecting call to potential metamethod
|
||||
** (which can reallocate the stack)
|
||||
*/
|
||||
#define gettableProtected(L,t,k,v) { TValue *slot; \
|
||||
if (luaV_fastget(L,t,k,slot,luaH_get)) { setobj2s(L, v, slot); } \
|
||||
else Protect(luaV_finishget(L,t,k,v,slot)); }
|
||||
|
||||
|
||||
/* same for 'luaV_settable' */
|
||||
#define settableProtected(L,t,k,v) { TValue *slot; \
|
||||
if (!luaV_fastset(L,t,k,slot,luaH_set,v)) \
|
||||
Protect(luaV_finishset(L,t,k,v,slot)); }
|
||||
|
||||
|
||||
|
||||
void luaV_execute (lua_State *L, int nexeccalls) {
|
||||
LClosure *cl;
|
||||
@@ -386,13 +433,12 @@ void luaV_execute (lua_State *L, int nexeccalls) {
|
||||
reentry: /* entry point */
|
||||
lua_assert(isLua(L->ci));
|
||||
pc = L->savedpc;
|
||||
cl = &clvalue(L->ci->func)->l;
|
||||
base = L->base;
|
||||
k = cl->p->k;
|
||||
cl = &clvalue(L->ci->func)->l; /* local reference to function's closure */
|
||||
k = cl->p->k; /* local reference to function's constant table */
|
||||
base = L->base; /* local copy of function's base */
|
||||
/* main loop of interpreter */
|
||||
for (;;) {
|
||||
const Instruction i = *pc++;
|
||||
StkId ra;
|
||||
if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) &&
|
||||
(--L->hookcount == 0 || L->hookmask & LUA_MASKLINE)) {
|
||||
traceexec(L, pc);
|
||||
@@ -402,26 +448,28 @@ void luaV_execute (lua_State *L, int nexeccalls) {
|
||||
}
|
||||
base = L->base;
|
||||
}
|
||||
/* warning!! several calls may realloc the stack and invalidate `ra' */
|
||||
ra = RA(i);
|
||||
lua_assert(base == L->base && L->base == L->ci->base);
|
||||
lua_assert(base <= L->top && L->top <= L->stack + L->stacksize);
|
||||
lua_assert(L->top == L->ci->top || luaG_checkopenop(i));
|
||||
switch (GET_OPCODE(i)) {
|
||||
case OP_MOVE: {
|
||||
StkId ra = RA(i);
|
||||
setobjs2s(L, ra, RB(i));
|
||||
continue;
|
||||
}
|
||||
case OP_LOADK: {
|
||||
StkId ra = RA(i);
|
||||
setobj2s(L, ra, KBx(i));
|
||||
continue;
|
||||
}
|
||||
case OP_LOADBOOL: {
|
||||
StkId ra = RA(i);
|
||||
setbvalue(ra, GETARG_B(i));
|
||||
if (GETARG_C(i)) pc++; /* skip next instruction (if C) */
|
||||
continue;
|
||||
}
|
||||
case OP_LOADNIL: {
|
||||
StkId ra = RA(i);
|
||||
TValue *rb = RB(i);
|
||||
do {
|
||||
setnilvalue(rb--);
|
||||
@@ -429,11 +477,13 @@ void luaV_execute (lua_State *L, int nexeccalls) {
|
||||
continue;
|
||||
}
|
||||
case OP_GETUPVAL: {
|
||||
StkId ra = RA(i);
|
||||
int b = GETARG_B(i);
|
||||
setobj2s(L, ra, cl->upvals[b]->v);
|
||||
continue;
|
||||
}
|
||||
case OP_GETGLOBAL: {
|
||||
StkId ra = RA(i);
|
||||
TValue g;
|
||||
TValue *rb = KBx(i);
|
||||
sethvalue(L, &g, cl->env);
|
||||
@@ -442,10 +492,14 @@ void luaV_execute (lua_State *L, int nexeccalls) {
|
||||
continue;
|
||||
}
|
||||
case OP_GETTABLE: {
|
||||
Protect(luaV_gettable(L, RB(i), RKC(i), ra));
|
||||
StkId ra = RA(i);
|
||||
StkId rb = RB(i);
|
||||
TValue *rc = RKC(i);
|
||||
gettableProtected(L, rb, rc, ra);
|
||||
continue;
|
||||
}
|
||||
case OP_SETGLOBAL: {
|
||||
StkId ra = RA(i);
|
||||
TValue g;
|
||||
sethvalue(L, &g, cl->env);
|
||||
lua_assert(ttisstring(KBx(i)));
|
||||
@@ -453,16 +507,21 @@ void luaV_execute (lua_State *L, int nexeccalls) {
|
||||
continue;
|
||||
}
|
||||
case OP_SETUPVAL: {
|
||||
StkId ra = RA(i);
|
||||
UpVal *uv = cl->upvals[GETARG_B(i)];
|
||||
setobj(L, uv->v, ra);
|
||||
luaC_barrier(L, uv, ra);
|
||||
continue;
|
||||
}
|
||||
case OP_SETTABLE: {
|
||||
Protect(luaV_settable(L, ra, RKB(i), RKC(i)));
|
||||
StkId ra = RA(i);
|
||||
TValue *rb = RKB(i);
|
||||
TValue *rc = RKC(i);
|
||||
settableProtected(L, ra, rb, rc);
|
||||
continue;
|
||||
}
|
||||
case OP_NEWTABLE: {
|
||||
StkId ra = RA(i);
|
||||
int b = GETARG_B(i);
|
||||
int c = GETARG_C(i);
|
||||
sethvalue(L, ra, luaH_new(L, luaO_fb2int(b), luaO_fb2int(c)));
|
||||
@@ -470,9 +529,16 @@ void luaV_execute (lua_State *L, int nexeccalls) {
|
||||
continue;
|
||||
}
|
||||
case OP_SELF: {
|
||||
TValue *slot;
|
||||
StkId ra = RA(i);
|
||||
StkId rb = RB(i);
|
||||
setobjs2s(L, ra+1, rb);
|
||||
Protect(luaV_gettable(L, rb, RKC(i), ra));
|
||||
TValue *rc = RKC(i);
|
||||
TString *key = rawtsvalue(rc); /* key must be a string */
|
||||
setobjs2s(L, ra + 1, rb);
|
||||
if (luaV_fastget(L, rb, key, slot, luaH_getstr)) {
|
||||
setobj2s(L, ra, slot);
|
||||
}
|
||||
else Protect(luaV_finishget(L, rb, rc, ra, slot));
|
||||
continue;
|
||||
}
|
||||
case OP_ADD: {
|
||||
@@ -488,6 +554,7 @@ void luaV_execute (lua_State *L, int nexeccalls) {
|
||||
continue;
|
||||
}
|
||||
case OP_DIV: {
|
||||
StkId ra = RA(i);
|
||||
TValue *rb = RKB(i);
|
||||
TValue *rc = RKC(i);
|
||||
if (ttisnumber(rb) && ttisnumber(rc)) {
|
||||
@@ -503,6 +570,7 @@ void luaV_execute (lua_State *L, int nexeccalls) {
|
||||
continue;
|
||||
}
|
||||
case OP_MOD: {
|
||||
StkId ra = RA(i);
|
||||
TValue *rb = RKB(i);
|
||||
TValue *rc = RKC(i);
|
||||
if (ttisnumber(rb) && ttisnumber(rc)) {
|
||||
@@ -522,26 +590,27 @@ void luaV_execute (lua_State *L, int nexeccalls) {
|
||||
continue;
|
||||
}
|
||||
case OP_BAND: {
|
||||
arith_op(luai_numand, TM_AND);
|
||||
continue;
|
||||
arith_op(luai_numand, TM_AND);
|
||||
continue;
|
||||
}
|
||||
case OP_BOR: {
|
||||
arith_op(luai_numor, TM_OR);
|
||||
continue;
|
||||
arith_op(luai_numor, TM_OR);
|
||||
continue;
|
||||
}
|
||||
case OP_BXOR: {
|
||||
arith_op(luai_numxor, TM_XOR);
|
||||
continue;
|
||||
arith_op(luai_numxor, TM_XOR);
|
||||
continue;
|
||||
}
|
||||
case OP_BSHL: {
|
||||
arith_op(luai_numshl, TM_SHL);
|
||||
continue;
|
||||
arith_op(luai_numshl, TM_SHL);
|
||||
continue;
|
||||
}
|
||||
case OP_BSHR: {
|
||||
arith_op(luai_numshr, TM_SHR);
|
||||
continue;
|
||||
arith_op(luai_numshr, TM_SHR);
|
||||
continue;
|
||||
}
|
||||
case OP_BNOT: {
|
||||
StkId ra = RA(i);
|
||||
TValue *rb = RB(i);
|
||||
if (ttisnumber(rb)) {
|
||||
lua_Number nb = nvalue(rb);
|
||||
@@ -553,6 +622,7 @@ void luaV_execute (lua_State *L, int nexeccalls) {
|
||||
continue;
|
||||
}
|
||||
case OP_UNM: {
|
||||
StkId ra = RA(i);
|
||||
TValue *rb = RB(i);
|
||||
if (ttisnumber(rb)) {
|
||||
lua_Number nb = nvalue(rb);
|
||||
@@ -564,11 +634,13 @@ void luaV_execute (lua_State *L, int nexeccalls) {
|
||||
continue;
|
||||
}
|
||||
case OP_NOT: {
|
||||
StkId ra = RA(i);
|
||||
int res = l_isfalse(RB(i)); /* next assignment may change this value */
|
||||
setbvalue(ra, res);
|
||||
continue;
|
||||
}
|
||||
case OP_LEN: {
|
||||
StkId ra = RA(i);
|
||||
TValue *rb = RB(i);
|
||||
switch (ttype(rb)) {
|
||||
case LUA_TTABLE: {
|
||||
@@ -626,12 +698,14 @@ void luaV_execute (lua_State *L, int nexeccalls) {
|
||||
continue;
|
||||
}
|
||||
case OP_TEST: {
|
||||
StkId ra = RA(i);
|
||||
if (l_isfalse(ra) != GETARG_C(i))
|
||||
dojump(L, pc, GETARG_sBx(*pc));
|
||||
pc++;
|
||||
continue;
|
||||
}
|
||||
case OP_TESTSET: {
|
||||
StkId ra = RA(i);
|
||||
TValue *rb = RB(i);
|
||||
if (l_isfalse(rb) != GETARG_C(i)) {
|
||||
setobjs2s(L, ra, rb);
|
||||
@@ -641,6 +715,7 @@ void luaV_execute (lua_State *L, int nexeccalls) {
|
||||
continue;
|
||||
}
|
||||
case OP_CALL: {
|
||||
StkId ra = RA(i);
|
||||
int b = GETARG_B(i);
|
||||
int nresults = GETARG_C(i) - 1;
|
||||
if (b != 0) L->top = ra+b; /* else previous instruction set top */
|
||||
@@ -662,6 +737,7 @@ void luaV_execute (lua_State *L, int nexeccalls) {
|
||||
}
|
||||
}
|
||||
case OP_TAILCALL: {
|
||||
StkId ra = RA(i);
|
||||
int b = GETARG_B(i);
|
||||
if (b != 0) L->top = ra+b; /* else previous instruction set top */
|
||||
L->savedpc = pc;
|
||||
@@ -694,6 +770,7 @@ void luaV_execute (lua_State *L, int nexeccalls) {
|
||||
}
|
||||
}
|
||||
case OP_RETURN: {
|
||||
StkId ra = RA(i);
|
||||
int b = GETARG_B(i);
|
||||
if (b != 0) L->top = ra+b-1;
|
||||
if (L->openupval) luaF_close(L, base);
|
||||
@@ -709,6 +786,7 @@ void luaV_execute (lua_State *L, int nexeccalls) {
|
||||
}
|
||||
}
|
||||
case OP_FORLOOP: {
|
||||
StkId ra = RA(i);
|
||||
lua_Number step = nvalue(ra+2);
|
||||
lua_Number idx = luai_numadd(nvalue(ra), step); /* increment index */
|
||||
lua_Number limit = nvalue(ra+1);
|
||||
@@ -721,6 +799,7 @@ void luaV_execute (lua_State *L, int nexeccalls) {
|
||||
continue;
|
||||
}
|
||||
case OP_FORPREP: {
|
||||
StkId ra = RA(i);
|
||||
const TValue *init = ra;
|
||||
const TValue *plimit = ra+1;
|
||||
const TValue *pstep = ra+2;
|
||||
@@ -737,6 +816,7 @@ void luaV_execute (lua_State *L, int nexeccalls) {
|
||||
continue;
|
||||
}
|
||||
case OP_TFORLOOP: {
|
||||
StkId ra = RA(i);
|
||||
StkId cb = ra + 3; /* call base */
|
||||
setobjs2s(L, cb+2, ra+2);
|
||||
setobjs2s(L, cb+1, ra+1);
|
||||
@@ -753,6 +833,7 @@ void luaV_execute (lua_State *L, int nexeccalls) {
|
||||
continue;
|
||||
}
|
||||
case OP_SETLIST: {
|
||||
StkId ra = RA(i);
|
||||
int n = GETARG_B(i);
|
||||
int c = GETARG_C(i);
|
||||
int last;
|
||||
@@ -775,10 +856,12 @@ void luaV_execute (lua_State *L, int nexeccalls) {
|
||||
continue;
|
||||
}
|
||||
case OP_CLOSE: {
|
||||
StkId ra = RA(i);
|
||||
luaF_close(L, ra);
|
||||
continue;
|
||||
}
|
||||
case OP_CLOSURE: {
|
||||
StkId ra = RA(i);
|
||||
Proto *p;
|
||||
Closure *ncl;
|
||||
int nup, j;
|
||||
@@ -799,6 +882,7 @@ void luaV_execute (lua_State *L, int nexeccalls) {
|
||||
continue;
|
||||
}
|
||||
case OP_VARARG: {
|
||||
StkId ra = RA(i);
|
||||
int b = GETARG_B(i) - 1;
|
||||
int j;
|
||||
CallInfo *ci = L->ci;
|
||||
|
||||
+52
-4
@@ -22,14 +22,62 @@
|
||||
(ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2))
|
||||
|
||||
|
||||
/*
|
||||
** fast track for 'gettable': if 't' is a table and 't[k]' is not nil,
|
||||
** return 1 with 'slot' pointing to 't[k]' (final result). Otherwise,
|
||||
** return 0 (meaning it will have to check metamethod) with 'slot'
|
||||
** pointing to a nil 't[k]' (if 't' is a table) or NULL (otherwise).
|
||||
** 'f' is the raw get function to use.
|
||||
*/
|
||||
#define luaV_fastget(L,t,k,slot,f) \
|
||||
(!ttistable(t) \
|
||||
? (slot = NULL, 0) /* not a table; 'slot' is NULL and result is 0 */ \
|
||||
: (slot = f(hvalue(t), k), /* else, do raw access */ \
|
||||
!ttisnil(slot))) /* result not nil? */
|
||||
|
||||
/*
|
||||
** standard implementation for 'gettable'
|
||||
*/
|
||||
#define luaV_gettable(L,t,k,v) { TValue *slot; \
|
||||
if (luaV_fastget(L,t,k,slot,luaH_get)) { setobj2s(L, v, slot); } \
|
||||
else luaV_finishget(L,t,k,v,slot); }
|
||||
|
||||
|
||||
/*
|
||||
** Fast track for set table. If 't' is a table and 't[k]' is not nil,
|
||||
** call GC barrier, do a raw 't[k]=v', and return true; otherwise,
|
||||
** return false with 'slot' equal to NULL (if 't' is not a table) or
|
||||
** 'nil'. (This is needed by 'luaV_finishget'.) Note that, if the macro
|
||||
** returns true, there is no need to 'invalidateTMcache', because the
|
||||
** call is not creating a new entry.
|
||||
*/
|
||||
#define luaV_fastset(L,t,k,slot,f,v) \
|
||||
(!ttistable(t) \
|
||||
? (slot = NULL, 0) \
|
||||
: (slot = f(L, hvalue(t), k), \
|
||||
ttisnil(slot) ? 0 \
|
||||
: (__extension__ ({ \
|
||||
if (valiswhite(v) && isblack(obj2gco(hvalue(t)))) \
|
||||
luaC_barrierback(L, hvalue(t)); \
|
||||
setobj2t(L, cast(TValue *,slot), v); \
|
||||
1; \
|
||||
}))))
|
||||
|
||||
|
||||
#define luaV_settable(L,t,k,v) { TValue *slot; \
|
||||
if (!luaV_fastset(L,t,k,slot,luaH_set,v)) \
|
||||
luaV_finishset(L,t,k,v,slot); }
|
||||
|
||||
|
||||
|
||||
LUAI_FUNC int luaV_lessthan (lua_State *L, TValue *l, TValue *r);
|
||||
LUAI_FUNC int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2);
|
||||
LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n);
|
||||
LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj);
|
||||
LUAI_FUNC void luaV_gettable (lua_State *L, TValue *t, TValue *key,
|
||||
StkId val);
|
||||
LUAI_FUNC void luaV_settable (lua_State *L, TValue *t, TValue *key,
|
||||
StkId val);
|
||||
LUAI_FUNC void luaV_finishget (lua_State *L, TValue *t, TValue *key,
|
||||
StkId val, TValue *tm);
|
||||
LUAI_FUNC void luaV_finishset (lua_State *L, TValue *t, TValue *key,
|
||||
StkId val, TValue *oldval);
|
||||
LUAI_FUNC void luaV_execute (lua_State *L, int nexeccalls);
|
||||
LUAI_FUNC void luaV_concat (lua_State *L, int total, int last);
|
||||
|
||||
|
||||
@@ -115,6 +115,10 @@ INT32 VID_GetModeForSize(INT32 w, INT32 h)
|
||||
return -1;
|
||||
}
|
||||
|
||||
void VID_RefreshModeList(void)
|
||||
{
|
||||
}
|
||||
|
||||
void VID_PrepareModeList(void)
|
||||
{
|
||||
}
|
||||
@@ -125,6 +129,13 @@ INT32 VID_SetMode(INT32 modeNum)
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean I_CheckAboveDesktopRes(INT32 width, INT32 height)
|
||||
{
|
||||
(void)width;
|
||||
(void)height;
|
||||
return false;
|
||||
}
|
||||
|
||||
void I_StartupGraphics(void)
|
||||
{
|
||||
}
|
||||
|
||||
+2
-2
@@ -130,8 +130,8 @@ extern char logfilename[1024];
|
||||
#else
|
||||
#define VERSION 1 // Game version
|
||||
#define SUBVERSION 6 // more precise version number
|
||||
#define VERSIONSTRING "Saturn v9.2"
|
||||
#define VERSIONSTRINGW L"Saturn v9.2"
|
||||
#define VERSIONSTRING "Saturn v9.3 - Testing"
|
||||
#define VERSIONSTRINGW L"Saturn v9.3 - Testing"
|
||||
|
||||
#define SATURN_TESTING // comment out for saturn release builds!
|
||||
|
||||
|
||||
@@ -95,6 +95,7 @@ INT32 VID_SetMode(INT32 modenum);
|
||||
*/
|
||||
const char *VID_GetModeName(INT32 modenum);
|
||||
|
||||
void VID_RefreshModeList(void);
|
||||
void VID_PrepareModeList(void);
|
||||
|
||||
/** \brief can video system do fullscreen
|
||||
@@ -121,6 +122,7 @@ void I_ReadScreen(UINT8 * restrict scr, INT32 scale);
|
||||
|
||||
UINT32 I_GetRefreshRate(void);
|
||||
|
||||
boolean I_CheckAboveDesktopRes(INT32 width, INT32 height);
|
||||
boolean I_CheckNativeRes(void);
|
||||
|
||||
void I_SetBorderlessWindow(void);
|
||||
|
||||
+43
-50
@@ -308,7 +308,6 @@ static void M_SetupMultiHandler(INT32 choice);
|
||||
|
||||
// Options
|
||||
// Split into multiple parts due to size
|
||||
static void M_VideoModeMenu(INT32 choice);
|
||||
static void M_Setup1PControlsMenu(void);
|
||||
static void M_Setup2PControlsMenu(void);
|
||||
static void M_Setup3PControlsMenu(void);
|
||||
@@ -9748,14 +9747,11 @@ static void M_ResetControls(INT32 choice)
|
||||
// ===============
|
||||
|
||||
//added : 30-01-98:
|
||||
#define MAXCOLUMNMODES 12 //max modes displayed in one column
|
||||
#define MAXMODEDESCS (MAXCOLUMNMODES*3)
|
||||
|
||||
static modedesc_t modedescs[MAXMODEDESCS];
|
||||
|
||||
static void M_VideoModeMenu(INT32 choice)
|
||||
void M_VideoModeMenu(INT32 choice)
|
||||
{
|
||||
INT32 i, j, vdup, nummodes, width, height;
|
||||
INT32 i, nummodes, width, height;
|
||||
const char *desc;
|
||||
|
||||
(void)choice;
|
||||
@@ -9769,54 +9765,30 @@ static void M_VideoModeMenu(INT32 choice)
|
||||
nummodes = VID_NumModes();
|
||||
|
||||
// DOS does not skip mode 0, because mode 0 is ALWAYS present
|
||||
i = 0;
|
||||
for (; i < nummodes && vidm_nummodes < MAXMODEDESCS; i++)
|
||||
for (i = 0; i < nummodes && vidm_nummodes < MAXMODEDESCS; i++)
|
||||
{
|
||||
desc = VID_GetModeName(i);
|
||||
if (desc)
|
||||
{
|
||||
vdup = 0;
|
||||
|
||||
// when a resolution exists both under VGA and VESA, keep the
|
||||
// VESA mode, which is always a higher modenum
|
||||
for (j = 0; j < vidm_nummodes; j++)
|
||||
{
|
||||
if (fastcmp(modedescs[j].desc, desc))
|
||||
{
|
||||
// mode(0): 320x200 is always standard VGA, not vesa
|
||||
if (modedescs[j].modenum)
|
||||
{
|
||||
modedescs[j].modenum = i;
|
||||
vdup = 1;
|
||||
if (!desc)
|
||||
continue;
|
||||
|
||||
if (i == vid.modenum)
|
||||
vidm_selected = j;
|
||||
}
|
||||
else
|
||||
vdup = 1;
|
||||
modedescs[vidm_nummodes].modenum = i;
|
||||
modedescs[vidm_nummodes].desc = desc;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == vid.modenum)
|
||||
vidm_selected = vidm_nummodes;
|
||||
|
||||
if (!vdup)
|
||||
{
|
||||
modedescs[vidm_nummodes].modenum = i;
|
||||
modedescs[vidm_nummodes].desc = desc;
|
||||
// Pull out the width and height
|
||||
sscanf(desc, "%u%*c%u", &width, &height);
|
||||
|
||||
if (i == vid.modenum)
|
||||
vidm_selected = vidm_nummodes;
|
||||
// Show resolutions above desktop res as red.
|
||||
if (I_CheckAboveDesktopRes(width, height))
|
||||
modedescs[vidm_nummodes].goodratio = 2;
|
||||
// Show multiples of 320x200 as green.
|
||||
else if (SCR_IsAspectCorrect(width, height))
|
||||
modedescs[vidm_nummodes].goodratio = 1;
|
||||
|
||||
// Pull out the width and height
|
||||
sscanf(desc, "%u%*c%u", &width, &height);
|
||||
|
||||
// Show multiples of 320x200 as green.
|
||||
if (SCR_IsAspectCorrect(width, height))
|
||||
modedescs[vidm_nummodes].goodratio = 1;
|
||||
|
||||
vidm_nummodes++;
|
||||
}
|
||||
}
|
||||
vidm_nummodes++;
|
||||
}
|
||||
|
||||
vidm_column_size = (vidm_nummodes+2) / 3;
|
||||
@@ -10033,7 +10005,11 @@ static void M_DrawVideoMode(void)
|
||||
V_DrawString(row, col, highlightflags|MENUCAPS, modedescs[i].desc);
|
||||
// Show multiples of 320x200 as green.
|
||||
else
|
||||
V_DrawString(row, col, ((modedescs[i].goodratio) ? recommendedflags : 0)|MENUCAPS, modedescs[i].desc);
|
||||
{
|
||||
const UINT8 goodratio = modedescs[i].goodratio;
|
||||
const INT32 goodflag = ((goodratio == 2) ? warningflags : (goodratio == 1) ? recommendedflags : 0);
|
||||
V_DrawString(row, col, goodflag|MENUCAPS, modedescs[i].desc);
|
||||
}
|
||||
|
||||
col += 8;
|
||||
if ((i % vidm_column_size) == (vidm_column_size-1))
|
||||
@@ -10072,9 +10048,26 @@ static void M_DrawVideoMode(void)
|
||||
V_DrawCenteredString(BASEVIDWIDTH/2, OP_VideoModeDef.y + 138,
|
||||
recommendedflags|MENUCAPS, "Marked modes are recommended.");
|
||||
V_DrawCenteredString(BASEVIDWIDTH/2, OP_VideoModeDef.y + 146,
|
||||
highlightflags|MENUCAPS, "Other modes may have visual errors.");
|
||||
V_DrawCenteredString(BASEVIDWIDTH/2, OP_VideoModeDef.y + 158,
|
||||
highlightflags|MENUCAPS, "Larger modes may have performance issues.");
|
||||
warningflags|MENUCAPS, "Marked modes are above Desktop resolution");
|
||||
|
||||
if (rendermode == render_opengl)
|
||||
{
|
||||
#ifdef USE_FBO_OGL
|
||||
if (!cv_glframebuffer.value)
|
||||
#endif
|
||||
V_DrawCenteredString(BASEVIDWIDTH/2, OP_VideoModeDef.y + 154,
|
||||
warningflags|MENUCAPS, "and will have visual errors in OpenGL mode.");
|
||||
|
||||
V_DrawCenteredString(BASEVIDWIDTH/2, OP_VideoModeDef.y + 166,
|
||||
highlightflags|MENUCAPS, "Other modes may have visual errors.");
|
||||
}
|
||||
else
|
||||
{
|
||||
V_DrawCenteredString(BASEVIDWIDTH/2, OP_VideoModeDef.y + 154,
|
||||
highlightflags|MENUCAPS, "Other modes may have visual errors.");
|
||||
V_DrawCenteredString(BASEVIDWIDTH/2, OP_VideoModeDef.y + 166,
|
||||
highlightflags|MENUCAPS, "Larger modes may have performance issues.");
|
||||
}
|
||||
}
|
||||
|
||||
// Draw the cursor for the VidMode menu
|
||||
|
||||
@@ -223,6 +223,11 @@ extern menu_t *currentMenu;
|
||||
extern menu_t MainDef;
|
||||
extern menu_t SP_LoadDef;
|
||||
|
||||
#define MAXCOLUMNMODES 12 //max modes displayed in one column
|
||||
#define MAXMODEDESCS (MAXCOLUMNMODES*3)
|
||||
extern menu_t OP_VideoModeDef;
|
||||
void M_VideoModeMenu(INT32 choice);
|
||||
|
||||
// Call upon joystick hotplug
|
||||
void M_SetupJoystickMenu(INT32 choice);
|
||||
extern menu_t OP_JoystickSetDef;
|
||||
|
||||
+2
-1
@@ -2586,7 +2586,8 @@ void P_FreeLevelState(void)
|
||||
}
|
||||
|
||||
// Clear pointers that would be left dangling by the purge
|
||||
R_FlushTranslationColormapCache();
|
||||
// Pointers are now PU_STATIC so they won't be freed :)
|
||||
//R_FlushTranslationColormapCache();
|
||||
|
||||
#ifdef HWRENDER
|
||||
// Free GPU textures before freeing patches.
|
||||
|
||||
+6
-1
@@ -419,7 +419,7 @@ static UINT8* RGetTranslationColormap(INT32 skinnum, skincolors_t color, UINT8 f
|
||||
// Generate the colormap if necessary
|
||||
if (!ret)
|
||||
{
|
||||
ret = static_cast<UINT8*>(Z_Malloc(NUM_PALETTE_ENTRIES, (flags & GTC_CACHE) ? PU_LEVEL : PU_STATIC, NULL));
|
||||
ret = static_cast<UINT8*>(Z_Malloc(NUM_PALETTE_ENTRIES, PU_STATIC, NULL));
|
||||
K_GenerateKartColormap(ret, skinnum, color, local); //R_GenerateTranslationColormap(ret, skinnum, color); // SRB2kart
|
||||
|
||||
// Cache the colormap if desired
|
||||
@@ -487,6 +487,10 @@ patch_t* R_GetSkinFaceMini(player_t* ply)
|
||||
|
||||
\return void
|
||||
*/
|
||||
|
||||
/* There seems to be no reason to free cached colormaps tho? Not like they can change :ChonkBunckle: */
|
||||
|
||||
/*
|
||||
void R_FlushTranslationColormapCache(void)
|
||||
{
|
||||
INT32 i;
|
||||
@@ -499,6 +503,7 @@ void R_FlushTranslationColormapCache(void)
|
||||
if (localtranslationtablecache[i])
|
||||
memset(localtranslationtablecache[i], 0, MAXTRANSLATIONS * sizeof(UINT8**));
|
||||
}
|
||||
*/
|
||||
|
||||
// ==========================================================================
|
||||
// COMMON DRAWER FOR 8 AND 16 BIT COLOR MODES
|
||||
|
||||
+1
-1
@@ -774,7 +774,7 @@ void R_AddSkins(UINT16 wadnum, boolean local)
|
||||
// So just let the function in the while loop take care of it for us.
|
||||
}
|
||||
|
||||
R_FlushTranslationColormapCache();
|
||||
//R_FlushTranslationColormapCache();
|
||||
|
||||
CONS_Printf(M_GetText("Added skin '%s'\n"), skin->name);
|
||||
#ifdef SKINVALUES
|
||||
|
||||
+5
-4
@@ -42,8 +42,8 @@ INT32 setmodeneeded = 0; // video mode change needed if > 0 (the mode number to
|
||||
static CV_PossibleValue_t shittyscreen_cons_t[] = {{0, "Okay"}, {1, "Shitty"}, {2, "Extra Shitty"}, {0, NULL}};
|
||||
|
||||
//added : 03-02-98: default screen mode, as loaded/saved in config
|
||||
consvar_t cv_scr_width = {"scr_width", "1280", CV_SAVE, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL};
|
||||
consvar_t cv_scr_height = {"scr_height", "800", CV_SAVE, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL};
|
||||
consvar_t cv_scr_width = {"scr_width", "1280", CV_SAVE|CV_CALL, CV_Unsigned, VID_RefreshModeList, 0, NULL, NULL, 0, 0, NULL};
|
||||
consvar_t cv_scr_height = {"scr_height", "800", CV_SAVE|CV_CALL, CV_Unsigned, VID_RefreshModeList, 0, NULL, NULL, 0, 0, NULL};
|
||||
consvar_t cv_renderview = {"renderview", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL};
|
||||
|
||||
consvar_t cv_frameskip = {"frameskip", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL};
|
||||
@@ -315,8 +315,9 @@ void SCR_CheckDefaultMode(void)
|
||||
void SCR_SetDefaultMode(void)
|
||||
{
|
||||
// remember the default screen size
|
||||
CV_SetValue(&cv_scr_width, vid.width);
|
||||
CV_SetValue(&cv_scr_height, vid.height);
|
||||
CV_StealthSetValue(&cv_scr_width, vid.width);
|
||||
CV_StealthSetValue(&cv_scr_height, vid.height);
|
||||
VID_RefreshModeList(); // probably not needed but justin käs
|
||||
}
|
||||
|
||||
// Change fullscreen on/off according to cv_fullscreen
|
||||
|
||||
+254
-84
@@ -84,15 +84,20 @@
|
||||
#endif
|
||||
|
||||
// maximum number of windowed modes (see windowedModes[][])
|
||||
#define MAXWINMODES (22)
|
||||
#define MAXWINMODES (128)
|
||||
|
||||
/** \brief
|
||||
*/
|
||||
static INT32 numVidModes = -1;
|
||||
static void I_FillScreenResolutionsList(boolean force);
|
||||
|
||||
/** \brief
|
||||
*/
|
||||
static char vidModeName[33][32]; // allow 33 different modes
|
||||
typedef struct
|
||||
{
|
||||
char name[10];
|
||||
INT32 w;
|
||||
INT32 h;
|
||||
} video_mode_t;
|
||||
|
||||
static video_mode_t windowedModes[MAXWINMODES] = {{"320x200", 320, 200}}; // make sure the default mode exists
|
||||
static const char *fallback_resolution_name = "Fallback";
|
||||
static int vid_nummodes = 1;
|
||||
|
||||
rendermode_t rendermode = render_none;
|
||||
|
||||
@@ -139,9 +144,6 @@ static SDL_bool disable_mouse = SDL_FALSE;
|
||||
#define MOUSE_MENU false //(!disable_mouse && cv_usemouse.value && menuactive && !USE_FULLSCREEN)
|
||||
#define MOUSEBUTTONS_MAX MOUSEBUTTONS
|
||||
|
||||
// first entry in the modelist which is not bigger than MAXVIDWIDTHxMAXVIDHEIGHT
|
||||
static INT32 firstEntry = 0;
|
||||
|
||||
// Total mouse motion X/Y offsets
|
||||
static INT32 mousemovex = 0, mousemovey = 0;
|
||||
|
||||
@@ -162,38 +164,6 @@ static SDL_Texture *texture = NULL;
|
||||
static SDL_GLContext sdlglcontext = NULL;
|
||||
#endif
|
||||
static SDL_bool havefocus = SDL_TRUE;
|
||||
static const char *fallback_resolution_name = "Fallback";
|
||||
|
||||
// windowed video modes from which to choose from.
|
||||
static INT32 windowedModes[MAXWINMODES][2] =
|
||||
{
|
||||
{2560,1440}, // 1.66
|
||||
{1920,1200}, // 1.60,6.00
|
||||
{1920,1080}, // 1.66
|
||||
{1680,1050}, // 1.60,5.25
|
||||
{1600,1200}, // 1.33
|
||||
{1600, 900}, // 1.66
|
||||
{1366, 768}, // 1.66
|
||||
{1440, 900}, // 1.60,4.50
|
||||
{1280,1024}, // 1.33?
|
||||
{1280, 960}, // 1.33,4.00
|
||||
{1280, 800}, // 1.60,4.00
|
||||
{1280, 720}, // 1.66
|
||||
{1152, 864}, // 1.33,3.60
|
||||
{1024, 768}, // 1.33,3.20
|
||||
{ 960, 600}, // 1.33,3.20
|
||||
{ 800, 600}, // 1.33,2.50
|
||||
{ 735, 415}, // 1.33,2.50
|
||||
{ 640, 480}, // 1.33,2.00
|
||||
{ 640, 400}, // 1.60,2.00
|
||||
{ 500, 300}, // 1.33
|
||||
{ 320, 240}, // 1.33,1.00
|
||||
{ 320, 200}, // 1.60,1.00
|
||||
};
|
||||
|
||||
#define CUSTOMMODENUM 9999
|
||||
static INT32 custom_width = 0;
|
||||
static INT32 custom_height = 0;
|
||||
|
||||
static SDL_bool Impl_CreateWindow(SDL_bool fullscreen);
|
||||
static void Impl_SetWindowIcon(void);
|
||||
@@ -519,11 +489,20 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt)
|
||||
return;
|
||||
}
|
||||
|
||||
if (windowmoved && rendermode == render_opengl)
|
||||
if (windowmoved)
|
||||
{
|
||||
I_CheckDesktopRes();
|
||||
|
||||
// if we say moved our game window to a different screen
|
||||
// refetch our resolutions
|
||||
I_FillScreenResolutionsList(false);
|
||||
#ifdef HWRENDER
|
||||
#ifdef USE_FBO_OGL
|
||||
I_DownSample();
|
||||
if (rendermode == render_opengl)
|
||||
{
|
||||
I_DownSample();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
windowmoved = SDL_FALSE;
|
||||
}
|
||||
@@ -540,7 +519,8 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt)
|
||||
|
||||
if (!firsttimeonmouse)
|
||||
{
|
||||
if (cv_usemouse.value) I_StartupMouse();
|
||||
if (cv_usemouse.value)
|
||||
I_StartupMouse();
|
||||
}
|
||||
}
|
||||
else if (!mousefocus && !kbfocus)
|
||||
@@ -1234,9 +1214,9 @@ static void VID_Command_ModeList_f(void)
|
||||
"Under opengl, fullscreen only supports native desktop resolution.\n"
|
||||
"Under software, the mode is stretched up to desktop resolution.\n");
|
||||
|
||||
for (i = 0; i < MAXWINMODES; i++)
|
||||
for (i = 0; i < vid_nummodes; i++)
|
||||
{
|
||||
CONS_Printf("%2d: %dx%d\n", i, windowedModes[i][0], windowedModes[i][1]);
|
||||
CONS_Printf("%2d: %dx%d\n", i, windowedModes[i].w, windowedModes[i].h);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1275,7 +1255,7 @@ static void I_CheckDesktopRes(void)
|
||||
return;
|
||||
}
|
||||
|
||||
if (SDL_GetDesktopDisplayMode(currentDisplayIndex, &curmode) != 0)
|
||||
if (SDL_GetCurrentDisplayMode(currentDisplayIndex, &curmode) != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -1290,6 +1270,11 @@ boolean I_CheckNativeRes(void)
|
||||
return (vid.width == desktopwidth && vid.height == desktopheight);
|
||||
}
|
||||
|
||||
boolean I_CheckAboveDesktopRes(INT32 width, INT32 height)
|
||||
{
|
||||
return (width > desktopwidth || height > desktopheight);
|
||||
}
|
||||
|
||||
#ifdef USE_FBO_OGL
|
||||
|
||||
void RefreshOGLSDLSurface(void)
|
||||
@@ -1520,13 +1505,207 @@ void I_SetPalette(RGBA_t *palette)
|
||||
}
|
||||
}
|
||||
|
||||
// make sure the canonical resolutions are always available
|
||||
static const struct {
|
||||
const int w, h;
|
||||
} canonicals[] = {
|
||||
{1920, 1200}, // 16:10
|
||||
{1280, 800}, // 16:10
|
||||
{ 960, 600}, // 16:10
|
||||
{ 640, 400}, // 16:10
|
||||
{ 320, 200}, // Vanilla Doom
|
||||
};
|
||||
static const int num_canonicals = sizeof(canonicals)/sizeof(*canonicals);
|
||||
|
||||
// [FG] sort resolutions by width first and height second
|
||||
static int cmp_resolutions(const void *a, const void *b)
|
||||
{
|
||||
const video_mode_t *ma = (const video_mode_t *) a;
|
||||
const video_mode_t *mb = (const video_mode_t *) b;
|
||||
|
||||
return (ma->w == mb->w) ? mb->h - ma->h : mb->w - ma->w;
|
||||
}
|
||||
|
||||
static void I_AppendResolution(SDL_DisplayMode *mode, int *list_size)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < *list_size; i++)
|
||||
if (windowedModes[i].w == mode->w
|
||||
&& windowedModes[i].h == mode->h)
|
||||
return;
|
||||
|
||||
snprintf(windowedModes[*list_size].name,
|
||||
sizeof(windowedModes[*list_size].name),
|
||||
"%dx%d", mode->w, mode->h);
|
||||
windowedModes[*list_size].w = mode->w;
|
||||
windowedModes[*list_size].h = mode->h;
|
||||
|
||||
(*list_size)++;
|
||||
}
|
||||
|
||||
// small helper to check if a video mode is canonical
|
||||
static boolean IsModeCanonical(int w, int h)
|
||||
{
|
||||
for (int i = 0; i < num_canonicals; i++)
|
||||
{
|
||||
if (canonicals[i].w == w && canonicals[i].h == h)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// check if our desired resolution already is in the videomode list
|
||||
static int IsCustomResolutionInList(int list_size)
|
||||
{
|
||||
INT32 custom_w = cv_scr_width.value;
|
||||
INT32 custom_h = cv_scr_height.value;
|
||||
|
||||
// startup
|
||||
if (!custom_w || !custom_h)
|
||||
return -2;
|
||||
|
||||
// invalid resolution
|
||||
// dont even attempt to add it
|
||||
if (custom_w < BASEVIDWIDTH || custom_w > MAXVIDWIDTH
|
||||
|| custom_h < BASEVIDHEIGHT || custom_h > MAXVIDHEIGHT)
|
||||
return -1;
|
||||
|
||||
for (int i = 0; i < list_size; i++)
|
||||
{
|
||||
if (windowedModes[i].w == custom_w && windowedModes[i].h == custom_h)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// I_FillScreenResolutionsList
|
||||
// Get all the supported screen resolutions
|
||||
// and fill the list with them
|
||||
//
|
||||
static void I_FillScreenResolutionsList(boolean force)
|
||||
{
|
||||
int currentDisplayIndex = -1;
|
||||
static int oldDisplayIndex = -1;
|
||||
SDL_DisplayMode mode;
|
||||
int i = 0, list_size = 0;
|
||||
int count = 0;
|
||||
char custom_resolution[10];
|
||||
|
||||
currentDisplayIndex = SDL_GetWindowDisplayIndex(window);
|
||||
|
||||
// No valid index
|
||||
if (currentDisplayIndex < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// didnt change screen, no need to redo the list
|
||||
if (!force && currentDisplayIndex == oldDisplayIndex)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
oldDisplayIndex = currentDisplayIndex;
|
||||
|
||||
// Don't call SDL_ListModes if SDL has not been initialized
|
||||
count = SDL_GetNumDisplayModes(currentDisplayIndex);
|
||||
|
||||
list_size = 0;
|
||||
|
||||
// on success, SDL_GetNumDisplayModes() always returns at least 1
|
||||
if (count > 0)
|
||||
{
|
||||
// -2 for the desired resolution and for NULL
|
||||
count = min(count, MAXWINMODES - 2 - num_canonicals);
|
||||
|
||||
for (i = count - 1 + num_canonicals; i >= 0; i--)
|
||||
{
|
||||
// make sure the canonical resolutions are always available
|
||||
if (i > count - 1)
|
||||
{
|
||||
mode.w = canonicals[i - count].w;
|
||||
mode.h = canonicals[i - count].h;
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_GetDisplayMode(currentDisplayIndex, i, &mode);
|
||||
}
|
||||
|
||||
I_AppendResolution(&mode, &list_size);
|
||||
}
|
||||
|
||||
windowedModes[list_size].name[0] = '\0';
|
||||
}
|
||||
|
||||
const int customresinlist = IsCustomResolutionInList(list_size);
|
||||
|
||||
if (customresinlist == 0)
|
||||
{
|
||||
// did not find mode from list, make custom resolution if the values somewhat make sense
|
||||
if (list_size < MAXWINMODES)
|
||||
{
|
||||
snprintf(custom_resolution, sizeof(custom_resolution), "%dx%d", cv_scr_width.value, cv_scr_height.value);
|
||||
|
||||
// [FG] if the desired resolution not in the list, append it
|
||||
snprintf(windowedModes[list_size].name,
|
||||
sizeof(windowedModes[list_size].name),
|
||||
"%dx%d", cv_scr_width.value, cv_scr_height.value);
|
||||
windowedModes[list_size].w = cv_scr_width.value;
|
||||
windowedModes[list_size].h = cv_scr_height.value;
|
||||
list_size++;
|
||||
}
|
||||
else
|
||||
CONS_Alert(CONS_ERROR, "Could not set custom resolution!\n");
|
||||
}
|
||||
else if (customresinlist == -1)
|
||||
CONS_Alert(CONS_ERROR, "Could not set custom resolution!\n");
|
||||
|
||||
// [FG] sort the list
|
||||
SDL_qsort(windowedModes, list_size, sizeof(*windowedModes), cmp_resolutions);
|
||||
|
||||
// if we have more video modes than we can list
|
||||
// try to shrink the list, lowest resolutions first
|
||||
// whilst keeping the canonicals
|
||||
if (list_size > MAXMODEDESCS)
|
||||
{
|
||||
// list is sorted from largest to smallest, so start at the end
|
||||
for (i = list_size - 1; i >= 0 && list_size > MAXMODEDESCS; i--)
|
||||
{
|
||||
if (IsModeCanonical(windowedModes[i].w, windowedModes[i].h))
|
||||
continue;
|
||||
|
||||
// Should we like, instead prioritize checking for non aspect correct resolutions to remove?
|
||||
|
||||
// we gotta shift everything
|
||||
// due to canonicals we cant just shrink the list
|
||||
for (int k = i; k < list_size - 1; k++)
|
||||
{
|
||||
windowedModes[k] = windowedModes[k + 1];
|
||||
}
|
||||
|
||||
list_size--;
|
||||
}
|
||||
}
|
||||
|
||||
windowedModes[list_size].name[0] = '\0';
|
||||
vid_nummodes = list_size;
|
||||
|
||||
// be sure to update the video menu
|
||||
if (menuactive &&
|
||||
currentMenu == &OP_VideoModeDef)
|
||||
M_VideoModeMenu(0);
|
||||
}
|
||||
|
||||
// return number of fullscreen + X11 modes
|
||||
INT32 VID_NumModes(void)
|
||||
{
|
||||
if (USE_FULLSCREEN && numVidModes != -1)
|
||||
return numVidModes - firstEntry;
|
||||
else
|
||||
return MAXWINMODES;
|
||||
return vid_nummodes;
|
||||
}
|
||||
|
||||
const char *VID_GetModeName(INT32 modeNum)
|
||||
@@ -1536,42 +1715,34 @@ const char *VID_GetModeName(INT32 modeNum)
|
||||
return fallback_resolution_name;
|
||||
}
|
||||
|
||||
if (modeNum > MAXWINMODES)
|
||||
if (modeNum > vid_nummodes)
|
||||
return NULL;
|
||||
|
||||
sprintf(&vidModeName[modeNum][0], "%dx%d",
|
||||
windowedModes[modeNum][0],
|
||||
windowedModes[modeNum][1]);
|
||||
|
||||
return &vidModeName[modeNum][0];
|
||||
return windowedModes[modeNum].name;
|
||||
}
|
||||
|
||||
INT32 VID_GetModeForSize(INT32 w, INT32 h)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < MAXWINMODES; i++)
|
||||
for (i = 0; i < vid_nummodes; i++)
|
||||
{
|
||||
if (windowedModes[i][0] == w && windowedModes[i][1] == h)
|
||||
if (windowedModes[i].w == w && windowedModes[i].h == h)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
// did not find mode from list, make custom resolution if the values somewhat make sense
|
||||
// opengl mode does not mind about max resolution defined in screen.h
|
||||
// if not using opengl, check against the maximum as well
|
||||
if ((w >= BASEVIDWIDTH && h >= BASEVIDHEIGHT) &&
|
||||
(rendermode == render_opengl || (w <= MAXVIDWIDTH && h <= MAXVIDHEIGHT)))
|
||||
{
|
||||
custom_width = w;
|
||||
custom_height = h;
|
||||
return CUSTOMMODENUM;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void VID_RefreshModeList(void)
|
||||
{
|
||||
// check if we even need to rebuild the list
|
||||
if (IsCustomResolutionInList(vid_nummodes) == 0)
|
||||
I_FillScreenResolutionsList(true);
|
||||
}
|
||||
|
||||
void VID_PrepareModeList(void)
|
||||
{
|
||||
// Under SDL2, we just use the windowed modes list, and scale in windowed fullscreen.
|
||||
@@ -1603,17 +1774,10 @@ INT32 VID_SetMode(INT32 modeNum)
|
||||
{
|
||||
vid.recalc = true;
|
||||
|
||||
if (modeNum >= 0 && modeNum < MAXWINMODES)
|
||||
if (modeNum >= 0 && modeNum < vid_nummodes)
|
||||
{
|
||||
vid.width = windowedModes[modeNum][0];
|
||||
vid.height = windowedModes[modeNum][1];
|
||||
vid.modenum = modeNum;
|
||||
}
|
||||
else if (modeNum == CUSTOMMODENUM && custom_width && custom_height)
|
||||
{
|
||||
// at this point these values are assumed to be okay
|
||||
vid.width = custom_width;
|
||||
vid.height = custom_height;
|
||||
vid.width = windowedModes[modeNum].w;
|
||||
vid.height = windowedModes[modeNum].h;
|
||||
vid.modenum = modeNum;
|
||||
}
|
||||
else
|
||||
@@ -1646,7 +1810,6 @@ INT32 VID_SetMode(INT32 modeNum)
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
|
||||
static SDL_bool Impl_CreateContext(void)
|
||||
{
|
||||
// Renderer-specific stuff
|
||||
@@ -1669,6 +1832,9 @@ static SDL_bool Impl_CreateContext(void)
|
||||
I_Error("Failed to set up GL context: %s\n", SDL_GetError());
|
||||
}
|
||||
|
||||
// be sure to fill the resolution list the moment we have a window
|
||||
I_FillScreenResolutionsList(false);
|
||||
|
||||
return SDL_TRUE;
|
||||
}
|
||||
#endif
|
||||
@@ -1710,6 +1876,9 @@ static SDL_bool Impl_CreateContext(void)
|
||||
|
||||
SDL_RenderSetLogicalSize(renderer, BASEVIDWIDTH, BASEVIDHEIGHT);
|
||||
|
||||
// be sure to fill the resolution list the moment we have a window
|
||||
I_FillScreenResolutionsList(false);
|
||||
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
@@ -1947,8 +2116,6 @@ void I_StartupGraphics(void)
|
||||
usesdl2soft = M_CheckParm("-softblit");
|
||||
borderlesswindow = M_CheckParm("-borderless");
|
||||
|
||||
VID_Command_ModeList_f();
|
||||
|
||||
#ifdef HWRENDER
|
||||
if (rendermode == render_opengl)
|
||||
{
|
||||
@@ -1972,6 +2139,9 @@ void I_StartupGraphics(void)
|
||||
vid.height = BASEVIDHEIGHT; // BitsPerPixel is the SDL interface's
|
||||
vid.recalc = true; // Set up the console stufff
|
||||
|
||||
// be sure to print AFTER window creation
|
||||
VID_Command_ModeList_f();
|
||||
|
||||
#ifdef HAVE_TTF
|
||||
I_ShutdownTTF();
|
||||
#endif
|
||||
|
||||
Reference in new issue
Block a user