Overlay resolution option, basic drawing primitives for debugging.

This commit is contained in:
Scott Duensing 2020-03-18 20:45:00 -05:00
parent 598b5eff5e
commit cc14222fcd
4 changed files with 418 additions and 17 deletions

View file

@ -78,7 +78,7 @@ CPPCOMPILER="g++"
EXTRA_CFLAGS="-O2"
EXTRA_OFILES=""
EXTRA_LD_FLAGS="-l:everything.a -lpthread -lXv -lX11 -lXext -lm -ldl -lrt"
#doBuild Singe-Linux-x86_64 linux 64
doBuild Singe-Linux-x86_64 linux 64
# 64 Bit Windows
echo -e "${G_L}\nWindows x86_64\n${G_L}"
@ -91,11 +91,10 @@ EXTRA_LD_FLAGS="-mwindows -static -lmingw32 -l:everything.a -lm -lbcrypt -ldinpu
xcf2png icon.xcf -o /tmp/icon.png
icotool -c -o /tmp/icon.ico /tmp/icon.png
x86_64-w64-mingw32-windres singe.rc -O coff -o /tmp/singe.res
#doBuild Singe-Windows-x86_64 mingw 64 .exe
doBuild Singe-Windows-x86_64 mingw 64 .exe
rm /tmp/icon.ico
rm /tmp/icon.png
rm /tmp/singe.res
#cp ../build/mingw/64/Singe-Windows-x86_64.exe ../test/.
# 32 Bit Raspbian
echo -e "${G_L}\nLinux armv6\n${G_L}"
@ -106,7 +105,7 @@ CPPCOMPILER="g++"
EXTRA_CFLAGS="-O2 --sysroot ${SYSROOT}"
EXTRA_OFILES=""
EXTRA_LD_FLAGS="--sysroot ${SYSROOT} -l:everything.a -Wl,-rpath-link,${SYSROOT}/opt/vc/lib -L${SYSROOT}/opt/vc/lib -lbcm_host -lasound -lpthread -lm -ldl -lsndio -lmmal_core -lmmal_util -lmmal_vc_client -lvdpau -ldrm -lgbm -lX11 -lsamplerate"
#doBuild Singe-Pi-armv6 pi 32
doBuild Singe-Pi-armv6 pi 32
# 64 Bit macOS
echo -e "${G_L}\nmacOS x86_64\n${G_L}"

View file

@ -232,6 +232,12 @@ int main(int argc, char *argv[]) {
utilDie("%s", ap_error(&parser));
}
// Default configuration values
memset(&_conf, 0, sizeof(ConfigT));
_conf.volumeVldp = 100;
_conf.volumeNonVldp = 100;
_conf.scaleFactor = 100;
// Parse command line
argCount = ap_arguments(&parser);
for (argIndex=0; argIndex < ap_arguments(&parser); ++argIndex) {

View file

@ -212,14 +212,19 @@ GlobalT _global;
int32_t apiColorBackground(lua_State *L);
int32_t apiColorForeground(lua_State *L);
int32_t apiControllerGetAxis(lua_State *L);
int32_t apiDaphneGetHeight(lua_State *L);
int32_t apiDaphneGetWidth(lua_State *L);
int32_t apiDaphneScreenshot(lua_State *L);
int32_t apiDebugPrint32_t(lua_State *L);
int32_t apiDiscAudio(lua_State *L);
int32_t apiDiscChangeSpeed(lua_State *L);
int32_t apiDiscGetFrame(lua_State *L);
int32_t apiDiscGetState(lua_State *L);
int32_t apiDiscPause(lua_State *L);
int32_t apiDiscPauseAtFrame(lua_State *L);
int32_t apiDiscPlay(lua_State *L);
@ -233,16 +238,32 @@ int32_t apiDiscSkipToFrame(lua_State *L);
int32_t apiDiscStepBackward(lua_State *L);
int32_t apiDiscStepForward(lua_State *L);
int32_t apiDiscStop(lua_State *L);
int32_t apiFontLoad(lua_State *L);
int32_t apiFontPrint32_t(lua_State *L);
int32_t apiFontQuality(lua_State *L);
int32_t apiFontSelect(lua_State *L);
int32_t apiFontToSprite(lua_State *L);
int32_t apiKeyboardGetMode(lua_State *L);
int32_t apiKeyboardSetMode(lua_State *L);
int32_t apiMouseDisable(lua_State *L);
int32_t apiMouseEnable(lua_State *L);
int32_t apiMouseGetPosition(lua_State *L);
int32_t apiMouseHowMany(lua_State *L);
int32_t apiMouseSetMode(lua_State *L);
int32_t apiOverlayCircle(lua_State *L);
int32_t apiOverlayClear(lua_State *L);
int32_t apiOverlayEllipse(lua_State *L);
int32_t apiOverlayGetHeight(lua_State *L);
int32_t apiOverlayGetWidth(lua_State *L);
int32_t apiOverlayPrint32_t(lua_State *L);
int32_t apiOverlayLine(lua_State *L);
int32_t apiOverlayPlot(lua_State *L);
int32_t apiOverlayPrint(lua_State *L);
int32_t apiOverlaySetResolution(lua_State *L);
int32_t apiSoundLoad(lua_State *L);
int32_t apiSoundPlay(lua_State *L);
int32_t apiSoundPause(lua_State *L);
@ -252,29 +273,26 @@ int32_t apiSoundStop(lua_State *L);
int32_t apiSoundSetVolume(lua_State *L);
int32_t apiSoundGetVolume(lua_State *L);
int32_t apiSoundFullStop(lua_State *L);
int32_t apiSpriteDraw(lua_State *L);
int32_t apiSpriteGetHeight(lua_State *L);
int32_t apiSpriteGetWidth(lua_State *L);
int32_t apiSpriteLoad(lua_State *L);
int32_t apiVldpGetHeight(lua_State *L);
int32_t apiVldpGetPixel(lua_State *L);
int32_t apiVldpGetWidth(lua_State *L);
int32_t apiVldpVerbose(lua_State *L);
int32_t apiKeyboardGetMode(lua_State *L);
int32_t apiKeyboardSetMode(lua_State *L);
int32_t apiMouseEnable(lua_State *L);
int32_t apiMouseDisable(lua_State *L);
int32_t apiMouseSetMode(lua_State *L);
int32_t apiMouseHowMany(lua_State *L);
int32_t apiDiscGetState(lua_State *L);
int32_t apiSingeGetPauseFlag(lua_State *L);
int32_t apiSingeSetPauseFlag(lua_State *L);
int32_t apiSingeEnablePauseKey(lua_State *L);
int32_t apiSingeDisablePauseKey(lua_State *L);
int32_t apiSingeEnablePauseKey(lua_State *L);
int32_t apiSingeGetPauseFlag(lua_State *L);
int32_t apiSingeGetScriptPath(lua_State *L);
int32_t apiSingeSetGameName(lua_State *L);
int32_t apiSingeSetPauseFlag(lua_State *L);
int32_t apiSingeQuit(lua_State *L);
int32_t apiSingeVersion(lua_State *L);
int32_t apiSingeSetGameName(lua_State *L);
int32_t apiSingeGetScriptPath(lua_State *L);
void doIndexDisplay(int32_t percent);
void doLogos(void);
void callLua(const char *func, const char *sig, ...);
@ -283,6 +301,7 @@ void luaDie(lua_State *L, char *method, char *fmt, ...);
int32_t luaError(lua_State *L);
void luaTrace(lua_State *L, char *method, char *fmt, ...);
void processKey(bool down, int keysym, int32_t scancode);
void putPixel(int32_t x, int32_t y);
void startControllers(void);
void stopControllers(void);
void takeScreenshot(void);
@ -944,6 +963,77 @@ int32_t apiFontToSprite(lua_State *L) {
}
int32_t apiOverlayCircle(lua_State *L) {
int32_t n = lua_gettop(L);
int32_t x0 = 0;
int32_t y0 = 0;
int32_t r = 0;
int32_t x = 0;
int32_t y = 0;
int32_t ro = 0;
int32_t xo = 0;
int32_t yo = 0;
int32_t dx = 1;
int32_t dy = 1;
int32_t err = 0;
double d = 0;
bool result = false;
if (n == 3) {
if (lua_isnumber(L, 1)) {
if (lua_isnumber(L, 2)) {
if (lua_isnumber(L, 3)) {
d = lua_tonumber(L, 1); xo = x = (int32_t)d;
d = lua_tonumber(L, 2); yo = y = (int32_t)d;
d = lua_tonumber(L, 3); ro = r = (int32_t)d;
x = r - 1;
err = dx - (int32_t)(r << 1);
SDL_LockSurface(_global.overlay);
while (x >= y) {
putPixel(x0 + x, y0 + y);
putPixel(x0 + y, y0 + x);
putPixel(x0 - y, y0 + x);
putPixel(x0 - x, y0 + y);
putPixel(x0 - x, y0 - y);
putPixel(x0 - y, y0 - x);
putPixel(x0 + y, y0 - x);
putPixel(x0 + x, y0 - y);
if (err <= 0) {
y++;
err += dy;
dy += 2;
}
if (err > 0) {
x--;
dx += 2;
err += dx - (r << 1);
}
}
SDL_UnlockSurface(_global.overlay);
result = true;
}
}
}
}
if (result) {
luaTrace(L, "overlayCircle", "%d %d %d", xo, yo, ro);
} else {
luaTrace(L, "overlayCircle", "Failed!");
}
return 0;
}
int32_t apiOverlayClear(lua_State *L) {
(void)L;
SDL_FillRect(_global.overlay, NULL, SDL_MapRGBA(_global.overlay->format, _global.colorBackground.r, _global.colorBackground.g, _global.colorBackground.b, _global.colorBackground.a));
@ -952,6 +1042,103 @@ int32_t apiOverlayClear(lua_State *L) {
}
int32_t apiOverlayEllipse(lua_State *L) {
int32_t n = lua_gettop(L);
int32_t x0 = 0;
int32_t y0 = 0;
int32_t x1 = 0;
int32_t y1 = 0;
int32_t x0o = 0;
int32_t y0o = 0;
int32_t x1o = 0;
int32_t y1o = 0;
int32_t a = 0;
int32_t b = 0;
int32_t b1 = 0;
int32_t dx = 0;
int32_t dy = 0;
int32_t err = 0;
int32_t e2 = 0;
double d = 0;
bool result = false;
if (n == 4) {
if (lua_isnumber(L, 1)) {
if (lua_isnumber(L, 2)) {
if (lua_isnumber(L, 3)) {
if (lua_isnumber(L, 4)) {
d = lua_tonumber(L, 1); x0o = x0 = (int32_t)d;
d = lua_tonumber(L, 2); y0o = y0 = (int32_t)d;
d = lua_tonumber(L, 3); x1o = x1 = (int32_t)d;
d = lua_tonumber(L, 4); y1o = y1 = (int32_t)d;
SDL_LockSurface(_global.overlay);
a = abs(x1 - x0);
b = abs(y1 - y0);
b1 = b & 1; // values of diameter
dx = 4 * (1 - a) * b * b;
dy = 4 * (b1 + 1) * a * a; // error increment
err = dx + dy + b1 * a * a;
if (x0 > x1) { // if called with swapped points
x0 = x1;
x1 += a;
}
if (y0 > y1) { //exchange them
y0 = y1;
}
y0 += (b + 1) / 2; // starting pixel
y1 = y0 - b1;
a *= 8 * a;
b1 = 8 * b * b;
do {
putPixel(x1, y0); // I. Quadrant
putPixel(x0, y0); // II. Quadrant
putPixel(x0, y1); // III. Quadrant
putPixel(x1, y1); // IV. Quadrant
e2 = 2 * err;
if (e2 <= dy) { // y step
y0++;
y1--;
err += dy += a;
}
if (e2 >= dx || 2*err > dy) { // x step
x0++;
x1--;
err += dx += b1;
}
} while (x0 <= x1);
while (y0-y1 < b) { // too early stop of flat ellipses a = 1
putPixel(x0-1, y0); // -> finish tip of ellipse
putPixel(x1+1, y0++);
putPixel(x0-1, y1);
putPixel(x1+1, y1--);
}
SDL_UnlockSurface(_global.overlay);
result = true;
}
}
}
}
}
if (result) {
luaTrace(L, "overlayEllipse", "%d %d %d %d", x0o, y0o, x1o, y1o);
} else {
luaTrace(L, "overlayEllipse", "Failed!");
}
return 0;
}
int32_t apiOverlayGetHeight(lua_State *L) {
luaTrace(L, "overlayGetHeight", "%d", _global.overlay->h);
lua_pushinteger(L, _global.overlay->h);
@ -966,6 +1153,134 @@ int32_t apiOverlayGetWidth(lua_State *L) {
}
int32_t apiOverlayLine(lua_State *L) {
int32_t n = lua_gettop(L);
int32_t x1 = 0;
int32_t y1 = 0;
int32_t x2 = 0;
int32_t y2 = 0;
int32_t x = 0;
int32_t y = 0;
int32_t dx = 0;
int32_t dy = 0;
int32_t incX = 0;
int32_t incY = 0;
int32_t balance = 0;
double d = 0;
bool result = false;
if (n == 4) {
if (lua_isnumber(L, 1)) {
if (lua_isnumber(L, 2)) {
if (lua_isnumber(L, 3)) {
if (lua_isnumber(L, 4)) {
d = lua_tonumber(L, 1); x1 = (int32_t)d;
d = lua_tonumber(L, 2); y1 = (int32_t)d;
d = lua_tonumber(L, 3); x2 = (int32_t)d;
d = lua_tonumber(L, 4); y2 = (int32_t)d;
SDL_LockSurface(_global.overlay);
if (x2 >= x1) {
dx = x2 - x1;
incX = 1;
} else {
dx = x1 - x2;
incX = -1;
}
if (y2 >= y1) {
dy = y2 - y1;
incY = 1;
} else {
dy = y1 - y2;
incY = -1;
}
x = x1;
y = y1;
if (dx >= dy) {
dy <<= 1;
balance = dy - dx;
dx <<= 1;
while (x != x2) {
putPixel(x, y);
if (balance >= 0) {
y += incY;
balance -= dx;
}
balance += dy;
x += incX;
}
putPixel(x, y);
} else {
dx <<= 1;
balance = dx - dy;
dy <<= 1;
while (y != y2) {
putPixel(x, y);
if (balance >= 0) {
x += incX;
balance -= dy;
}
balance += dx;
y += incY;
}
putPixel(x, y);
}
SDL_UnlockSurface(_global.overlay);
result = true;
}
}
}
}
}
if (result) {
luaTrace(L, "overlayLine", "%d %d %d %d", x1, y1, x2, y2);
} else {
luaTrace(L, "overlayLine", "Failed!");
}
return 0;
}
int32_t apiOverlayPlot(lua_State *L) {
int32_t n = lua_gettop(L);
int32_t x1 = 0;
int32_t y1 = 0;
double d = 0;
bool result = false;
if (n == 2) {
if (lua_isnumber(L, 1)) {
if (lua_isnumber(L, 2)) {
d = lua_tonumber(L, 1); x1 = (int32_t)d;
d = lua_tonumber(L, 2); y1 = (int32_t)d;
SDL_LockSurface(_global.overlay);
putPixel(x1, y1);
SDL_UnlockSurface(_global.overlay);
result = true;
}
}
}
if (result) {
luaTrace(L, "overlayPlot", "%d %d", x1, y1);
} else {
luaTrace(L, "overlayPlot", "Failed!");
}
return 0;
}
int32_t apiOverlayPrint(lua_State *L) {
int32_t n = lua_gettop(L);
int32_t i = 0;
@ -1005,6 +1320,43 @@ int32_t apiOverlayPrint(lua_State *L) {
}
int32_t apiOverlaySetResolution(lua_State *L) {
int32_t n = lua_gettop(L);
int32_t x = 0;
int32_t y = 0;
double d = 0;
bool result = false;
if (n == 2) {
if (lua_isnumber(L, 1)) {
if (lua_isnumber(L, 2)) {
// New resolution. We don't check it. Might go boom.
d = lua_tonumber(L, 1); x = (int32_t)d;
d = lua_tonumber(L, 2); y = (int32_t)d;
// Release existing surface.
SDL_FreeSurface(_global.overlay);
// Create the new one.
_global.overlay = SDL_CreateRGBSurfaceWithFormat(0, x, y, 32, SDL_PIXELFORMAT_BGRA32);
if (_global.overlay == NULL) utilDie("%s", SDL_GetError());
SDL_SetColorKey(_global.overlay, true, 0);
// Update some variables.
_global.overlayScaleX = x / videoGetWidth(_global.videoHandle);
_global.overlayScaleY = y / videoGetHeight(_global.videoHandle);
result = true;
}
}
}
if (result) {
luaTrace(L, "overlaySetResolution", "%d %d", x, y);
} else {
luaTrace(L, "overlaySetResolution", "Failed!");
}
return 0;
}
int32_t apiSoundLoad(lua_State *L) {
int32_t n = lua_gettop(L);
int32_t result = -1;
@ -2191,6 +2543,43 @@ void processKey(bool down, int32_t keysym, int32_t scancode) {
}
void putPixel(int32_t x, int32_t y) {
SDL_Surface *surface = _global.overlay;
int32_t bpp = surface->format->BytesPerPixel;
Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
Uint32 pixel = SDL_MapRGBA(surface->format, _global.colorForeground.r, _global.colorForeground.g, _global.colorForeground.b, _global.colorForeground.a);
if ((x < 0) || (x >= _global.overlay->w) || (y < 0) || (y >= _global.overlay->h)) return;
switch (bpp) {
case 1:
*p = (Uint8)pixel;
break;
case 2:
*(Uint16 *)p = (Uint16)pixel;
break;
case 3:
if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
p[0] = (pixel >> 16) & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = pixel & 0xff;
} else {
p[0] = pixel & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = (pixel >> 16) & 0xff;
}
break;
case 4:
*(Uint32 *)p = pixel;
break;
}
}
void singe(SDL_Window *window, SDL_Renderer *renderer) {
int32_t x = 0;
int32_t y = 0;
@ -2398,10 +2787,15 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) {
lua_register(_global.luaContext, "mouseHowMany", apiMouseHowMany);
lua_register(_global.luaContext, "mouseSetMode", apiMouseSetMode);
lua_register(_global.luaContext, "overlayCircle", apiOverlayCircle);
lua_register(_global.luaContext, "overlayClear", apiOverlayClear);
lua_register(_global.luaContext, "overlayEllipse", apiOverlayEllipse);
lua_register(_global.luaContext, "overlayGetHeight", apiOverlayGetHeight);
lua_register(_global.luaContext, "overlayGetWidth", apiOverlayGetWidth);
lua_register(_global.luaContext, "overlayLine", apiOverlayLine);
lua_register(_global.luaContext, "overlayPlot", apiOverlayPlot);
lua_register(_global.luaContext, "overlayPrint", apiOverlayPrint);
lua_register(_global.luaContext, "overlaySetResolution", apiOverlaySetResolution);
lua_register(_global.luaContext, "singeGetPauseFlag", apiSingeGetPauseFlag);
lua_register(_global.luaContext, "singeSetPauseFlag", apiSingeSetPauseFlag);

View file

@ -253,3 +253,5 @@ platformLinux {
write_file("source.inc.sh", FILEINFO)
}
debug:message("Debugging")