Added --trace

This commit is contained in:
Scott Duensing 2019-12-10 20:29:29 -06:00
parent 93481c1f66
commit 1ccc25d337
5 changed files with 423 additions and 55 deletions

View file

@ -85,6 +85,7 @@ void showUsage(char *name, char *message) {
utilSay(" -u, --stretch use ugly stretched video");
utilSay(" -x, --xresolution=VALUE specify horizontal resolution");
utilSay(" -y, --yresolution=VALUE specify vertical resolution");
utilSay(" -t, --trace trace script execution to screen and file");
utilSay(" -h, --help this display");
utilSay("");
if (message) {
@ -130,6 +131,7 @@ int main(int argc, char *argv[]) {
{ "xresolution", optional_argument, NULL, 'x' },
{ "yresolution", optional_argument, NULL, 'y' },
{ "help", no_argument, NULL, 'h' },
{ "trace", no_argument, NULL, 't' },
{ NULL, 0, NULL, 0 }
};
static ModeT modes[] = {
@ -250,6 +252,11 @@ int main(int argc, char *argv[]) {
showUsage(argv[0], NULL);
break;
// Trace
case 't':
utilTraceStart("trace.txt");
break;
case '?':
showUsage(argv[0], "Unknown option.");
break;
@ -491,6 +498,7 @@ int main(int argc, char *argv[]) {
if (_confDataDir) free(_confDataDir);
if (_confVideoFile) free(_confVideoFile);
if (_confScriptFile) free(_confScriptFile);
utilTraceEnd();
return 0;
}

View file

@ -33,7 +33,6 @@
#include "thirdparty/uthash.h"
#include "thirdparty/manymouse/manymouse.h"
#include "common.h"
#include "util.h"
#include "videoPlayer.h"
#include "singe.h"
@ -144,12 +143,12 @@ enum {
char *_confVideoFile = NULL;
char *_confScriptFile = NULL;
char *_confDataDir = NULL;
int _confStretchVideo = false;
int _confNoMouse = false;
int _confNoStats = false;
int _confNoSound = false;
int _confFullScreen = false;
int _confFullScreenWindow = false;
bool _confStretchVideo = false;
bool _confNoMouse = false;
bool _confNoStats = false;
bool _confNoSound = false;
bool _confFullScreen = false;
bool _confFullScreenWindow = false;
int _confVolumeVldp = 100;
int _confVolumeNonVldp = 100;
int _confScaleFactor = 100;
@ -297,11 +296,36 @@ int apiSingeGetScriptPath(lua_State *L);
void callLua(const char *func, const char *sig, ...);
void channelFinished(int channel);
int luaError(lua_State *L);
void luaTrace(lua_State *L, char *method, char *fmt, ...);
void processKey(bool down, int keysym);
void luaTrace(lua_State *L, char *method, char *fmt, ...) {
va_list args;
lua_Debug ar;
char *string1 = NULL;
char *string2 = NULL;
if (utilTraceFile) {
lua_getstack(L, 1, &ar);
lua_getinfo(L, "nSl", &ar);
string1 = utilCreateString("%d:%s: ", ar.currentline, method);
if (!string1) utilDie("Unable to allocate first trace string.");
va_start(args, fmt);
string2 = utilCreateStringVArgs(fmt, args);
if (!string2) utilDie("Unable to allocate second trace string.");
va_end(args);
utilSay("%s%s", string1, string2);
utilTrace("%s%s", string1, string2);
free(string2);
free(string1);
}
}
int apiColorBackground(lua_State *L) {
int n = lua_gettop(L);
int n = lua_gettop(L);
bool result = false;
if ((n == 3) || (n == 4)) {
if (lua_isinteger(L, 1)) {
@ -319,17 +343,25 @@ int apiColorBackground(lua_State *L) {
_colorBackground.a = (byte)255;
}
}
result = true;
}
}
}
}
if (result) {
luaTrace(L, "colorBackground", "%d %d %d %d", _colorBackground.r, _colorBackground.g, _colorBackground.b, _colorBackground.a);
} else {
luaTrace(L, "colorBackground", "Failed!");
}
return 0;
}
int apiColorForeground(lua_State *L) {
int n = lua_gettop(L);
int n = lua_gettop(L);
bool result = false;
if ((n == 3) || (n == 4)) {
if (lua_isinteger(L, 1)) {
@ -347,11 +379,18 @@ int apiColorForeground(lua_State *L) {
_colorForeground.a = (byte)255;
}
}
result = true;
}
}
}
}
if (result) {
luaTrace(L, "colorForeground", "%d %d %d %d", _colorForeground.r, _colorForeground.g, _colorForeground.b, _colorForeground.a);
} else {
luaTrace(L, "colorForeground", "Failed!");
}
return 0;
}
@ -359,6 +398,7 @@ int apiColorForeground(lua_State *L) {
int apiDaphneGetHeight(lua_State *L) {
int y;
SDL_GetWindowSize(_window, NULL, &y);
luaTrace(L, "DaphneGetHeight", "%d", y);
lua_pushinteger(L, y);
return 1;
}
@ -367,6 +407,7 @@ int apiDaphneGetHeight(lua_State *L) {
int apiDaphneGetWidth(lua_State *L) {
int x;
SDL_GetWindowSize(_window, &x, NULL);
luaTrace(L, "DaphneGetWidth", "%d", x);
lua_pushinteger(L, x);
return 1;
}
@ -390,6 +431,8 @@ int apiDaphneScreenshot(lua_State *L) {
}
if (x > 999) utilDie("Seriously? You have 1000 screenshots in this folder? Remove some.");
luaTrace(L, "DaphneScreenshot", "%s", filename);
SDL_SetRenderTarget(_renderer, NULL);
texture = SDL_GetRenderTarget(_renderer);
SDL_QueryTexture(texture, &format, NULL, &x, &y);
@ -412,6 +455,7 @@ int apiDebugPrint(lua_State *L) {
if (n == 1) {
if (lua_isstring(L, 1)) {
luaTrace(L, "DebugPrint", "%s", lua_tostring(L, 1));
utilSay("%s", lua_tostring(L, 1));
}
}
@ -426,6 +470,7 @@ int apiDiscAudio(lua_State *L) {
int left = 0;
int right = 0;
bool onOff = false;
bool result = false;
if (n == 2) {
if (lua_isinteger(L, 1)) {
@ -435,10 +480,17 @@ int apiDiscAudio(lua_State *L) {
if ((channel == 1) && onOff) left = _confVolumeVldp;
if ((channel == 2) && onOff) right = _confVolumeVldp;
videoSetVolume(_videoHandle, left, right);
result = true;
}
}
}
if (result) {
luaTrace(L, "discAudio", "%d %d", left, right);
} else {
luaTrace(L, "discAudio", "Failed!");
}
return 0;
}
@ -446,16 +498,21 @@ int apiDiscAudio(lua_State *L) {
int apiDiscChangeSpeed(lua_State *L) {
(void)L;
//***REMOVED***
luaTrace(L, "discChangeSpeed", "Unimplemented");
return 0;
}
int apiDiscGetFrame(lua_State *L) {
if (_discStopped) {
lua_pushinteger(L, 0);
} else {
lua_pushinteger(L, videoGetFrame(_videoHandle));
int frame = 0;
if (!_discStopped) {
frame = videoGetFrame(_videoHandle);
}
luaTrace(L, "discGetFrame", "%d", frame);
lua_pushinteger(L, frame);
return 1;
}
@ -464,21 +521,37 @@ int apiDiscPause(lua_State *L) {
(void)L;
if (!_discStopped) {
videoPause(_videoHandle);
luaTrace(L, "discPause", "");
} else {
luaTrace(L, "discPause", "Failed! Disc is stopped.");
}
return 0;
}
int apiDiscPauseAtFrame(lua_State *L) {
int n = lua_gettop(L);
int n = lua_gettop(L);
int frame = 0;
bool result = false;
if (!_discStopped) {
if (n == 1) {
if (lua_isinteger(L, 1)) {
videoSeek(_videoHandle, (int)lua_tointeger(L, 1));
frame = (int)lua_tointeger(L, 1);
videoSeek(_videoHandle, frame);
videoPause(_videoHandle);
result = true;
}
}
} else {
luaTrace(L, "discPauseAtFrame", "Failed! Disc is stopped.");
return 0;
}
if (result) {
luaTrace(L, "discPauseAtFrame", "%d", frame);
} else {
luaTrace(L, "discPauseAtFrame", "Failed!");
}
return 0;
@ -487,21 +560,39 @@ int apiDiscPauseAtFrame(lua_State *L) {
int apiDiscPlay(lua_State *L) {
(void)L;
videoPlay(_videoHandle);
_discStopped = false;
if (_discStopped) {
videoPlay(_videoHandle);
_discStopped = false;
luaTrace(L, "discPlay", "");
} else {
luaTrace(L, "discPlay", "Failed! Disc is stopped.");
}
return 0;
}
int apiDiscSearch(lua_State *L) {
int n = lua_gettop(L);
int n = lua_gettop(L);
int frame = 0;
bool result = false;
if (!_discStopped) {
if (n == 1) {
if (lua_isinteger(L, 1)) {
videoSeek(_videoHandle, (int)lua_tointeger(L, 1));
frame = (int)lua_tointeger(L, 1);
videoSeek(_videoHandle, frame);
result = true;
}
}
} else {
luaTrace(L, "discSearch", "Failed! Disc is stopped.");
return 0;
}
if (result) {
luaTrace(L, "discSearch", "%d", frame);
} else {
luaTrace(L, "discSearch", "Failed!");
}
return 0;
@ -511,6 +602,7 @@ int apiDiscSearch(lua_State *L) {
int apiDiscSearchBlanking(lua_State *L) {
(void)L;
//***REMOVED***
luaTrace(L, "discSearchBlanking", "Unimplemented");
return 0;
}
@ -518,19 +610,33 @@ int apiDiscSearchBlanking(lua_State *L) {
int apiDiscSetFps(lua_State *L) {
(void)L;
//***REMOVED***
luaTrace(L, "discSetFPS", "Unimplemented");
return 0;
}
int apiDiscSkipBackward(lua_State *L) {
int n = lua_gettop(L);
int n = lua_gettop(L);
int frame = 0;
bool result = false;
if (!_discStopped) {
if (n == 1) {
if (lua_isinteger(L, 1)) {
videoSeek(_videoHandle, videoGetFrame(_videoHandle) - (int)lua_tointeger(L, 1));
frame = videoGetFrame(_videoHandle) - (int)lua_tointeger(L, 1);
videoSeek(_videoHandle, frame);
result = true;
}
}
} else {
luaTrace(L, "discSkipBackward", "Failed! Disc is stopped.");
return 0;
}
if (result) {
luaTrace(L, "discSkipBackward", "%d", frame);
} else {
luaTrace(L, "discSkipBackward", "Failed!");
}
return 0;
@ -540,19 +646,33 @@ int apiDiscSkipBackward(lua_State *L) {
int apiDiscSkipBlanking(lua_State *L) {
(void)L;
//***REMOVED***
luaTrace(L, "discSkipBlanking", "Unimplemented");
return 0;
}
int apiDiscSkipForward(lua_State *L) {
int n = lua_gettop(L);
int n = lua_gettop(L);
int frame = 0;
bool result = false;
if (!_discStopped) {
if (n == 1) {
if (lua_isinteger(L, 1)) {
videoSeek(_videoHandle, videoGetFrame(_videoHandle) + (int)lua_tointeger(L, 1));
frame = videoGetFrame(_videoHandle) + (int)lua_tointeger(L, 1);
videoSeek(_videoHandle, frame);
result = true;
}
}
} else {
luaTrace(L, "discSkipForward", "Failed! Disc is stopped.");
return 0;
}
if (result) {
luaTrace(L, "discSkipForward", "%d", frame);
} else {
luaTrace(L, "discSkipForward", "Failed!");
}
return 0;
@ -561,23 +681,38 @@ int apiDiscSkipForward(lua_State *L) {
int apiDiscSkipToFrame(lua_State *L) {
// Not really sure what this is, so just seek to a new frame.
luaTrace(L, "discSkipToFrame", "Forwarding to discSearch.");
return apiDiscSearch(L);
}
int apiDiscStepBackward(lua_State *L) {
int frame = 0;
(void)L;
if (!_discStopped) {
videoSeek(_videoHandle, videoGetFrame(_videoHandle) - 1);
frame = videoGetFrame(_videoHandle) - 1;
videoSeek(_videoHandle, frame);
luaTrace(L, "discStepBackward", "%d", frame);
} else {
luaTrace(L, "discStepBackward", "Failed! Disc is stopped.");
}
return 0;
}
int apiDiscStepForward(lua_State *L) {
int frame = 0;
(void)L;
if (!_discStopped) {
videoSeek(_videoHandle, videoGetFrame(_videoHandle) + 1);
frame = videoGetFrame(_videoHandle) + 1;
videoSeek(_videoHandle, frame);
luaTrace(L, "discStepForward", "%d", frame);
} else {
luaTrace(L, "discStepForward", "Failed! Disc is stopped.");
}
return 0;
}
@ -585,9 +720,14 @@ int apiDiscStepForward(lua_State *L) {
int apiDiscStop(lua_State *L) {
(void)L;
videoPause(_videoHandle);
_discStopped = true;
_refreshDisplay = true;
if (!_discStopped) {
videoPause(_videoHandle);
_discStopped = true;
_refreshDisplay = true;
luaTrace(L, "discStop", "");
} else {
luaTrace(L, "discStop", "Failed! Disc is stopped.");
}
return 0;
}
@ -618,6 +758,12 @@ int apiFontLoad(lua_State *L) {
}
}
if (result >= 0) {
luaTrace(L, "fontLoad", "%s %d", name, result);
} else {
luaTrace(L, "fontLoad", "Failed!");
}
lua_pushnumber(L, result);
return 1;
}
@ -670,27 +816,42 @@ int apiFontPrint(lua_State *L) {
}
}
if (textSurface) {
luaTrace(L, "fontPrint", "%s", message);
} else {
luaTrace(L, "fontPrint", "Failed!");
}
return 0;
}
int apiFontQuality(lua_State *L) {
int n = lua_gettop(L);
int n = lua_gettop(L);
bool result = false;
if (n == 1) {
if (lua_isinteger(L, 1)) {
_fontQuality = (int)lua_tointeger(L, 1);
result = true;
}
}
if (result) {
luaTrace(L, "fontQuality", "%d", _fontQuality);
} else {
luaTrace(L, "fontQuality", "Failed!");
}
return 0;
}
int apiFontSelect(lua_State *L) {
int n = lua_gettop(L);
int id = -1;
FontT *font = NULL;
int n = lua_gettop(L);
int id = -1;
bool result = false;
FontT *font = NULL;
if (n == 1) {
if (lua_isinteger(L, 1)) {
@ -698,9 +859,16 @@ int apiFontSelect(lua_State *L) {
HASH_FIND_INT(_fontList, &id, font);
if (!font) utilDie("No font at index %d in apiSpriteGetWidth.", id);
_fontCurrent = font;
result = true;
}
}
if (result) {
luaTrace(L, "fontSelect", "%d", _fontCurrent);
} else {
luaTrace(L, "fontSelect", "Failed!");
}
return 0;
}
@ -751,6 +919,12 @@ int apiFontToSprite(lua_State *L) {
}
}
if (textSurface) {
luaTrace(L, "fontToSprite", "%d %s", result, message);
} else {
luaTrace(L, "fontToSprite", "Failed!");
}
lua_pushinteger(L, result);
return 1;
}
@ -760,6 +934,7 @@ int apiOverlayClear(lua_State *L) {
(void)L;
SDL_SetRenderDrawColor(_renderer, _colorBackground.r, _colorBackground.g, _colorBackground.b, _colorBackground.a);
SDL_RenderClear(_renderer);
luaTrace(L, "overlayClear", "");
return 0;
}
@ -772,6 +947,8 @@ int apiOverlayGetHeight(lua_State *L) {
if (SDL_QueryTexture(_overlay, &format, &access, &x, &y) < 0) utilDie("%s", SDL_GetError());
luaTrace(L, "overlayGetHeight", "%d", y);
lua_pushinteger(L, y);
return 1;
}
@ -785,6 +962,8 @@ int apiOverlayGetWidth(lua_State *L) {
if (SDL_QueryTexture(_overlay, &format, &access, &x, &y) < 0) utilDie("%s", SDL_GetError());
luaTrace(L, "overlayGetWidth", "%d", x);
lua_pushinteger(L, x);
return 1;
}
@ -808,15 +987,17 @@ int apiOverlayPrint(lua_State *L) {
int apiSoundLoad(lua_State *L) {
int n = lua_gettop(L);
int result = -1;
SoundT *sound = NULL;
int n = lua_gettop(L);
int result = -1;
const char *name = NULL;
SoundT *sound = NULL;
if (n == 1) {
if (lua_isstring(L, 1)) {
sound = (SoundT *)calloc(1, sizeof(SoundT));
if (!sound) utilDie("Unable to allocate new sound.");
sound->chunk = Mix_LoadWAV(lua_tostring(L, 1));
name = lua_tostring(L, 1);
sound->chunk = Mix_LoadWAV(name);
if (!sound->chunk) utilDie("%s", Mix_GetError());
sound->id = _nextSoundId;
result = _nextSoundId++;
@ -824,6 +1005,12 @@ int apiSoundLoad(lua_State *L) {
}
}
if (sound) {
luaTrace(L, "soundLoad", "%d %s", result, name);
} else {
luaTrace(L, "soundLoad", "Failed!");
}
lua_pushnumber(L, result);
return 1;
}
@ -846,6 +1033,13 @@ int apiSoundPlay(lua_State *L) {
Mix_Volume(result, _effectsVolume * 2);
}
}
if (sound) {
luaTrace(L, "soundPlay", "%d", result);
} else {
luaTrace(L, "soundPlay", "Failed!");
}
lua_pushnumber(L, result);
return 1;
}
@ -875,6 +1069,12 @@ int apiSoundPause(lua_State *L) {
}
}
if (result) {
luaTrace(L, "soundPause", "%d", channel);
} else {
luaTrace(L, "soundPause", "Failed!");
}
lua_pushboolean(L, result);
return 1;
}
@ -905,6 +1105,12 @@ int apiSoundResume(lua_State *L) {
}
}
if (result) {
luaTrace(L, "soundResume", "%d", channel);
} else {
luaTrace(L, "soundResume", "Failed!");
}
lua_pushboolean(L, result);
return 1;
}
@ -933,6 +1139,12 @@ int apiSoundIsPlaying(lua_State *L) {
}
}
if (result) {
luaTrace(L, "soundIsPlaying", "%d %d", channel, result);
} else {
luaTrace(L, "soundIsPlaying", "Failed!");
}
lua_pushboolean(L, result);
return 1;
}
@ -965,6 +1177,12 @@ int apiSoundStop(lua_State *L) {
}
}
if (result) {
luaTrace(L, "soundStop", "%d", channel);
} else {
luaTrace(L, "soundStop", "Failed!");
}
lua_pushboolean(L, result);
return 1;
}
@ -997,6 +1215,12 @@ int apiSoundSetVolume(lua_State *L) {
}
}
if (result) {
luaTrace(L, "soundSetVolume", "%d", _effectsVolume);
} else {
luaTrace(L, "soundSetVolume", "Failed!");
}
lua_pushboolean(L, result);
return 0;
}
@ -1012,6 +1236,8 @@ int apiSoundGetVolume(lua_State *L) {
//
// --rdg
luaTrace(L, "soundGetVolume", "%d", _effectsVolume);
lua_pushinteger(L, _effectsVolume);
return 1;
}
@ -1025,6 +1251,9 @@ int apiSoundFullStop(lua_State *L) {
// soundFullStop()
(void)L;
luaTrace(L, "soundFullStop", "");
Mix_HaltChannel(-1);
return 0;
}
@ -1052,6 +1281,12 @@ int apiSpriteDraw(lua_State *L) {
}
}
if (id >= 0) {
luaTrace(L, "spriteDraw", "%d %d %d %d %d", id, dest.x, dest.y, dest.w, dest.h);
} else {
luaTrace(L, "spriteDraw", "Failed!");
}
return 0;
}
@ -1077,6 +1312,12 @@ int apiSpriteGetHeight(lua_State *L) {
}
}
if (result >= 0) {
luaTrace(L, "spriteGetHeight", "%d", result);
} else {
luaTrace(L, "spriteGetHeight", "Failed!");
}
lua_pushinteger(L, result);
return 1;
}
@ -1103,6 +1344,12 @@ int apiSpriteGetWidth(lua_State *L) {
}
}
if (result >= 0) {
luaTrace(L, "spriteGetWidth", "%d", result);
} else {
luaTrace(L, "spriteGetWidth", "Failed!");
}
lua_pushinteger(L, result);
return 1;
}
@ -1111,12 +1358,14 @@ int apiSpriteGetWidth(lua_State *L) {
int apiSpriteLoad(lua_State *L) {
int n = lua_gettop(L);
int result = -1;
const char *name = NULL;
SpriteT *sprite = NULL;
SDL_Surface *image = NULL;
SDL_Surface *image = NULL;
if (n == 1) {
if (lua_isstring(L, 1)) {
image = IMG_Load(lua_tostring(L, 1));
name = lua_tostring(L, 1);
image = IMG_Load(name);
if (!image) utilDie("%s", IMG_GetError());
sprite = (SpriteT *)calloc(1, sizeof(SpriteT));
if (!sprite) utilDie("Unable to allocate new sprite.");
@ -1129,13 +1378,21 @@ int apiSpriteLoad(lua_State *L) {
}
}
if (sprite) {
luaTrace(L, "spriteLoad", "%d %s", result, name);
} else {
luaTrace(L, "spriteLoad", "Failed!");
}
lua_pushnumber(L, result);
return 1;
}
int apiVldpGetHeight(lua_State *L) {
lua_pushinteger(L, videoGetHeight(_videoHandle));
int height = videoGetHeight(_videoHandle);
luaTrace(L, "vldpGetHeight", "%d", height);
lua_pushinteger(L, height);
return 1;
}
@ -1162,10 +1419,12 @@ int apiVldpGetPixel(lua_State *L) {
}
if (result) {
luaTrace(L, "vldpGetPixel", "%d %d %d %d %d", rect.x, rect.y, pixel[2], pixel[1], pixel[0]);
lua_pushinteger(L, (int)pixel[2]); // R
lua_pushinteger(L, (int)pixel[1]); // G
lua_pushinteger(L, (int)pixel[0]); // B
} else {
luaTrace(L, "vldpGetPixel", "Failed!");
lua_pushinteger(L, -1);
lua_pushinteger(L, -1);
lua_pushinteger(L, -1);
@ -1176,7 +1435,9 @@ int apiVldpGetPixel(lua_State *L) {
int apiVldpGetWidth(lua_State *L) {
lua_pushinteger(L, videoGetWidth(_videoHandle));
int width = videoGetWidth(_videoHandle);
luaTrace(L, "vldpGetHeight", "%d", width);
lua_pushinteger(L, width);
return 1;
}
@ -1189,18 +1450,23 @@ int apiVldpVerbose(lua_State *L) {
(void)L;
//***REMOVED***
luaTrace(L, "vldpVerbose", "Unimplemented");
return 0;
}
int apiKeyboardGetMode(lua_State *L) {
luaTrace(L, "keyboardGetMode", "%d", _keyboardMode);
lua_pushinteger(L, _keyboardMode);
return 1;
}
int apiKeyboardSetMode(lua_State *L) {
bool result = false;
/*
* Singe can scan keyboard input in two ways:
*
@ -1216,9 +1482,16 @@ int apiKeyboardSetMode(lua_State *L) {
if (n == 1) {
if (lua_isinteger(L, 1)) {
_keyboardMode = (int)lua_tointeger(L, 1);
result = true;
}
}
if (result) {
luaTrace(L, "keyboardSetMode", "%d", _keyboardMode);
} else {
luaTrace(L, "keyboardSetMode", "Failed!");
}
return 0;
}
@ -1226,6 +1499,7 @@ int apiKeyboardSetMode(lua_State *L) {
int apiMouseEnable(lua_State *L) {
// Enables mouse monitoring
(void)L;
luaTrace(L, "mouseEnable", "%d", _confNoMouse);
_mouseEnabled = (bool)!_confNoMouse;
return 0;
}
@ -1234,6 +1508,7 @@ int apiMouseEnable(lua_State *L) {
int apiMouseDisable(lua_State *L) {
// Disables mouse monitoring
(void)L;
luaTrace(L, "mouseDisable", "");
_mouseEnabled = false;
return 0;
}
@ -1267,18 +1542,27 @@ int apiMouseSetMode(lua_State *L) {
}
}
if (result) {
luaTrace(L, "mouseSetMode", "%d", _mouseMode);
} else {
luaTrace(L, "mouseSetMode", "Failed!");
}
lua_pushboolean(L, result);
return 1;
}
int apiMouseHowMany(lua_State *L) {
luaTrace(L, "mouseHowMany", "%d", _mouseCount);
lua_pushinteger(L, _mouseCount);
return 1;
}
int apiDiscGetState(lua_State *L) {
int isPlaying = -1;
/*
* Returns the status of the vldp
* Values returned are
@ -1293,7 +1577,9 @@ int apiDiscGetState(lua_State *L) {
*/
// Our player isn't as sophisticated as the one in Daphne
lua_pushinteger(L, _discStopped ? LDP_STOPPED : (videoIsPlaying(_videoHandle) ? LDP_PLAYING : LDP_PAUSE));
isPlaying = videoIsPlaying(_videoHandle);
luaTrace(L, "discGetState", "%s", _discStopped ? "Stopped" : (isPlaying ? "Playing" : "Paused"));
lua_pushinteger(L, _discStopped ? LDP_STOPPED : (isPlaying ? LDP_PLAYING : LDP_PAUSE));
return 1;
}
@ -1311,26 +1597,36 @@ int apiSingeGetPauseFlag(lua_State *L) {
*
* A lua programmer can use this to prevent resuming playback accidentally.
*/
luaTrace(L, "singeGetPauseFlag", "%d", _pauseState);
lua_pushboolean(L, _pauseState);
return 1;
}
int apiSingeSetPauseFlag(lua_State *L) {
int n = lua_gettop(L);
int n = lua_gettop(L);
bool result = false;
if (n == 1) {
if (lua_isboolean(L, 1)) {
_pauseState = (bool)lua_toboolean(L, 1);
result = true;
}
}
if (result) {
luaTrace(L, "singeSetPauseFlag", "%d", _pauseState);
} else {
luaTrace(L, "singeSetPauseFlag", "Failed!");
}
return 0;
}
int apiSingeEnablePauseKey(lua_State *L) {
(void)L;
luaTrace(L, "singeEnablePauseKey", "");
_pauseEnabled = true;
return 0;
}
@ -1338,6 +1634,7 @@ int apiSingeEnablePauseKey(lua_State *L) {
int apiSingeDisablePauseKey(lua_State *L) {
(void)L;
luaTrace(L, "singeDisablePauseKey", "");
_pauseEnabled = false;
return 0;
}
@ -1345,12 +1642,14 @@ int apiSingeDisablePauseKey(lua_State *L) {
int apiSingeQuit(lua_State *L) {
(void)L;
luaTrace(L, "singeQuit", "");
_running = false;
return 0;
}
int apiSingeVersion(lua_State *L) {
luaTrace(L, "singeVersion", "%f", SINGE_VERSION);
lua_pushnumber(L, SINGE_VERSION);
return 1;
}
@ -1373,12 +1672,18 @@ int apiSingeSetGameName(lua_State *L) {
if (n == 1) {
if (lua_isstring(L, 1)) {
sprintf(thisName,"%.40s",lua_tostring(L, 1)); // Need a better way to do this...
sprintf(thisName,"%.40s", lua_tostring(L, 1)); // Need a better way to do this...
SDL_SetWindowTitle(_window, thisName);
result = true;
}
}
if (result) {
luaTrace(L, "singeSetGameName", "%s", thisName);
} else {
luaTrace(L, "singeSetGameName", "Failed!");
}
lua_pushboolean(L, result);
return 0;
}
@ -1391,6 +1696,7 @@ int apiSingeGetScriptPath(lua_State *L) {
// sGameDirectory = singeGetScriptPath()
//
luaTrace(L, "singeSetScriptPath", "%s", _confScriptFile);
lua_pushstring(L, _confScriptFile);
return 1;
}
@ -1414,6 +1720,8 @@ void callLua(const char *func, const char *sig, ...) {
return;
}
utilTrace("%s", func);
// Push Arguments
narg = 0;
while ((*sig) && (!done)) {

View file

@ -26,6 +26,8 @@
#include <SDL2/SDL.h>
#include "common.h"
#define SINGE_VERSION 2.00
#define VERSION_STRING "v2.00"
@ -36,12 +38,12 @@
extern char *_confVideoFile;
extern char *_confScriptFile;
extern char *_confDataDir;
extern int _confStretchVideo;
extern int _confNoMouse;
extern int _confNoStats;
extern int _confNoSound;
extern int _confFullScreen;
extern int _confFullScreenWindow;
extern bool _confStretchVideo;
extern bool _confNoMouse;
extern bool _confNoStats;
extern bool _confNoSound;
extern bool _confFullScreen;
extern bool _confFullScreenWindow;
extern int _confVolumeVldp;
extern int _confVolumeNonVldp;
extern int _confScaleFactor;

View file

@ -20,23 +20,34 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <string.h>
#include <stdarg.h>
#include "util.h"
__attribute__((__format__(__printf__, 1, 0)))
FILE *utilTraceFile = NULL;
char *utilCreateString(char *format, ...) {
va_list args;
char *string;
va_start(args, format);
string = utilCreateStringVArgs(format, args);
va_end(args);
return string;
}
__attribute__((__format__(__printf__, 1, 0)))
char *utilCreateStringVArgs(char *format, va_list args) {
va_list argsCopy;
int size = 0;
char *buffer = NULL;
va_start(args, format);
va_copy(argsCopy, args);
size = vsnprintf(NULL, 0, format, argsCopy) + 1;
va_end(argsCopy);
@ -44,7 +55,6 @@ char *utilCreateString(char *format, ...) {
if (buffer) {
vsnprintf(buffer, (size_t)size, format, args);
}
va_end(args);
return buffer;
}
@ -137,3 +147,32 @@ void utilSay(char *fmt, ...) {
}
void utilTrace(char *fmt, ...) {
va_list args;
if (utilTraceFile) {
va_start(args, fmt);
utilTraceVArgs(fmt, args);
va_end(args);
}
}
void utilTraceEnd(void) {
if (utilTraceFile) fclose(utilTraceFile);
}
void utilTraceStart(char *filename) {
utilTraceFile = fopen(filename, "wt");
if (!utilTraceFile) utilDie("Unable to create trace file: %s", filename);
}
__attribute__((__format__(__printf__, 1, 0)))
void utilTraceVArgs(char *fmt, va_list args) {
if (utilTraceFile) {
vfprintf(utilTraceFile, fmt, args);
fprintf(utilTraceFile, "\n");
fflush(utilTraceFile);
}
}

View file

@ -24,10 +24,18 @@
#define UTIL_H
#include <stdio.h>
#include <stdarg.h>
#include "common.h"
extern FILE *utilTraceFile;
char *utilCreateString(char *format, ...);
char *utilCreateStringVArgs(char *format, va_list args);
void utilDie(char *fmt, ...);
bool utilFileExists(char *filename);
char *utilGetFileExtension(char *filename);
@ -35,6 +43,9 @@ char *utilGetLastPathComponent(char *pathname);
char utilGetPathSeparator(void);
bool utilPathExists(char *pathname);
void utilSay(char *fmt, ...);
void utilTrace(char *fmt, ...);
void utilTraceEnd(void);
void utilTraceStart(char *filename);
void utilTraceVArgs(char *fmt, va_list args);
#endif // UTIL_H