Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
SRB2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Galactice
SRB2
Commits
a54d3a27
Commit
a54d3a27
authored
1 year ago
by
Lactozilla
Browse files
Options
Downloads
Patches
Plain Diff
Remove assignment by table
parent
0e2b6a94
Branches
lua-extracolormap
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/lua_colorlib.c
+6
-53
6 additions, 53 deletions
src/lua_colorlib.c
with
6 additions
and
53 deletions
src/lua_colorlib.c
+
6
−
53
View file @
a54d3a27
...
@@ -17,48 +17,6 @@
...
@@ -17,48 +17,6 @@
#include
"lua_script.h"
#include
"lua_script.h"
#include
"lua_libs.h"
#include
"lua_libs.h"
static
UINT8
GetRGBAColorsFromTable
(
lua_State
*
L
,
UINT32
index
,
UINT8
*
rgba
,
boolean
useAlpha
)
{
UINT8
num
=
0
;
lua_pushnil
(
L
);
while
(
lua_next
(
L
,
index
))
{
lua_Integer
i
=
0
;
const
char
*
field
=
NULL
;
if
(
lua_isnumber
(
L
,
-
2
))
i
=
lua_tointeger
(
L
,
-
2
);
else
field
=
luaL_checkstring
(
L
,
-
2
);
#define CHECKFIELD(p, c) (i == p || (field && fastcmp(field, c)))
#define RGBASET(p, c) { \
INT32 color = luaL_checkinteger(L, -1); \
if (color < 0 || color > 255) \
luaL_error(L, c " channel %d out of range (0 - 255)", color); \
rgba[p] = (UINT8)color; \
num++; \
}
if
(
CHECKFIELD
(
1
,
"r"
))
{
RGBASET
(
0
,
"red color"
);
}
else
if
(
CHECKFIELD
(
2
,
"g"
))
{
RGBASET
(
1
,
"green color"
);
}
else
if
(
CHECKFIELD
(
3
,
"b"
))
{
RGBASET
(
2
,
"blue color"
);
}
else
if
(
useAlpha
&&
CHECKFIELD
(
4
,
"a"
))
{
RGBASET
(
3
,
"alpha"
);
}
#undef CHECKFIELD
#undef RGBASET
lua_pop
(
L
,
1
);
}
return
num
;
}
#define IS_HEX_CHAR(x) ((x >= '0' && x <= '9') || (x >= 'a' && x <= 'f') || (x >= 'A' && x <= 'F'))
#define IS_HEX_CHAR(x) ((x >= '0' && x <= '9') || (x >= 'a' && x <= 'f') || (x >= 'A' && x <= 'F'))
#define ARE_HEX_CHARS(str, i) IS_HEX_CHAR(str[i]) && IS_HEX_CHAR(str[i + 1])
#define ARE_HEX_CHARS(str, i) IS_HEX_CHAR(str[i]) && IS_HEX_CHAR(str[i + 1])
...
@@ -205,29 +163,24 @@ static int extracolormap_get(lua_State *L)
...
@@ -205,29 +163,24 @@ static int extracolormap_get(lua_State *L)
lua_pushinteger
(
L
,
exc
->
fadeend
);
lua_pushinteger
(
L
,
exc
->
fadeend
);
break
;
break
;
case
extracolormap_colormap
:
case
extracolormap_colormap
:
// I'm not sure if making the colormap available makes sense.
// It's a read-only field, only used by one of the renderers, and
// the only way to manipulate it is by modifying the other fields.
LUA_PushUserdata
(
L
,
exc
->
colormap
,
META_LIGHTTABLE
);
LUA_PushUserdata
(
L
,
exc
->
colormap
,
META_LIGHTTABLE
);
break
;
break
;
}
}
return
1
;
return
1
;
}
}
static
void
GetExtraColormapRGBA
(
lua_State
*
L
,
UINT8
*
rgba
)
static
void
GetExtraColormapRGBA
(
lua_State
*
L
,
UINT8
*
rgba
,
int
arg
)
{
{
if
(
lua_type
(
L
,
3
)
==
LUA_TSTRING
)
if
(
lua_type
(
L
,
arg
)
==
LUA_TSTRING
)
{
{
const
char
*
str
=
lua_tostring
(
L
,
3
);
const
char
*
str
=
lua_tostring
(
L
,
arg
);
UINT8
parsed
=
ParseHTMLColor
(
str
,
rgba
,
4
);
UINT8
parsed
=
ParseHTMLColor
(
str
,
rgba
,
4
);
if
(
!
parsed
)
if
(
!
parsed
)
luaL_error
(
L
,
"Malformed HTML color '%s'"
,
str
);
luaL_error
(
L
,
"Malformed HTML color '%s'"
,
str
);
}
}
else
if
(
lua_type
(
L
,
3
)
==
LUA_TTABLE
)
GetRGBAColorsFromTable
(
L
,
3
,
rgba
,
true
);
else
else
{
{
UINT32
colors
=
lua_tointeger
(
L
,
3
);
UINT32
colors
=
lua_tointeger
(
L
,
arg
);
if
(
colors
>
0xFFFFFF
)
if
(
colors
>
0xFFFFFF
)
{
{
rgba
[
0
]
=
(
colors
>>
24
)
&
0xFF
;
rgba
[
0
]
=
(
colors
>>
24
)
&
0xFF
;
...
@@ -286,7 +239,7 @@ static int extracolormap_set(lua_State *L)
...
@@ -286,7 +239,7 @@ static int extracolormap_set(lua_State *L)
rgba
[
1
]
=
g
;
rgba
[
1
]
=
g
;
rgba
[
2
]
=
b
;
rgba
[
2
]
=
b
;
rgba
[
3
]
=
a
;
rgba
[
3
]
=
a
;
GetExtraColormapRGBA
(
L
,
rgba
);
GetExtraColormapRGBA
(
L
,
rgba
,
3
);
exc
->
rgba
=
R_PutRgbaRGBA
(
rgba
[
0
],
rgba
[
1
],
rgba
[
2
],
rgba
[
3
]);
exc
->
rgba
=
R_PutRgbaRGBA
(
rgba
[
0
],
rgba
[
1
],
rgba
[
2
],
rgba
[
3
]);
break
;
break
;
case
extracolormap_fade_red
:
case
extracolormap_fade_red
:
...
@@ -306,7 +259,7 @@ static int extracolormap_set(lua_State *L)
...
@@ -306,7 +259,7 @@ static int extracolormap_set(lua_State *L)
rgba
[
1
]
=
fg
;
rgba
[
1
]
=
fg
;
rgba
[
2
]
=
fb
;
rgba
[
2
]
=
fb
;
rgba
[
3
]
=
fa
;
rgba
[
3
]
=
fa
;
GetExtraColormapRGBA
(
L
,
rgba
);
GetExtraColormapRGBA
(
L
,
rgba
,
3
);
exc
->
fadergba
=
R_PutRgbaRGBA
(
rgba
[
0
],
rgba
[
1
],
rgba
[
2
],
rgba
[
3
]);
exc
->
fadergba
=
R_PutRgbaRGBA
(
rgba
[
0
],
rgba
[
1
],
rgba
[
2
],
rgba
[
3
]);
break
;
break
;
case
extracolormap_fade_start
:
case
extracolormap_fade_start
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment