Compiles and starts to run scripts.
This commit is contained in:
parent
9f44dc055c
commit
93481c1f66
3 changed files with 39 additions and 12 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -31,3 +31,4 @@ singe/thirdparty/SDL2_image/external/tiff-4.1.0/autom4te.cache/
|
|||
thirdparty-build/
|
||||
singe/extensions.h
|
||||
videotest/*.singe
|
||||
games/
|
||||
|
|
|
@ -178,6 +178,7 @@ static double _overlayScaleX = 1; // Difference between overlay
|
|||
static double _overlayScaleY = 1; // Difference between overlay and video
|
||||
static bool _pauseState = false; // by RDG2010
|
||||
static bool _pauseEnabled = true; // by RDG2010
|
||||
static bool _refreshDisplay = false;
|
||||
static bool _running = true;
|
||||
static bool _discStopped = true;
|
||||
static bool _mouseEnabled = true;
|
||||
|
@ -294,6 +295,7 @@ int apiSingeVersion(lua_State *L);
|
|||
int apiSingeSetGameName(lua_State *L);
|
||||
int apiSingeGetScriptPath(lua_State *L);
|
||||
void callLua(const char *func, const char *sig, ...);
|
||||
void channelFinished(int channel);
|
||||
int luaError(lua_State *L);
|
||||
void processKey(bool down, int keysym);
|
||||
|
||||
|
@ -487,6 +489,7 @@ int apiDiscPlay(lua_State *L) {
|
|||
(void)L;
|
||||
videoPlay(_videoHandle);
|
||||
_discStopped = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -584,6 +587,8 @@ int apiDiscStop(lua_State *L) {
|
|||
(void)L;
|
||||
videoPause(_videoHandle);
|
||||
_discStopped = true;
|
||||
_refreshDisplay = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -755,6 +760,7 @@ int apiOverlayClear(lua_State *L) {
|
|||
(void)L;
|
||||
SDL_SetRenderDrawColor(_renderer, _colorBackground.r, _colorBackground.g, _colorBackground.b, _colorBackground.a);
|
||||
SDL_RenderClear(_renderer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -835,6 +841,7 @@ int apiSoundPlay(lua_State *L) {
|
|||
// Get our sound structure
|
||||
HASH_FIND_INT(_soundList, &id, sound);
|
||||
if (!sound) utilDie("No sound at index %d in apiSoundPlay.", id);
|
||||
// Play it
|
||||
result = Mix_PlayChannel(-1, sound->chunk, 0);
|
||||
Mix_Volume(result, _effectsVolume * 2);
|
||||
}
|
||||
|
@ -1339,6 +1346,7 @@ int apiSingeDisablePauseKey(lua_State *L) {
|
|||
int apiSingeQuit(lua_State *L) {
|
||||
(void)L;
|
||||
_running = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1481,6 +1489,11 @@ void callLua(const char *func, const char *sig, ...) {
|
|||
}
|
||||
|
||||
|
||||
void channelFinished(int channel) {
|
||||
callLua("onSoundCompleted", "i", channel);
|
||||
}
|
||||
|
||||
|
||||
int luaError(lua_State *L) {
|
||||
lua_Debug ar;
|
||||
int level = 0;
|
||||
|
@ -1574,7 +1587,6 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) {
|
|||
int thisFrame = -1;
|
||||
int lastFrame = -1;
|
||||
int intReturn = 0;
|
||||
bool refresh = false;
|
||||
SDL_Texture *videoTexture = NULL;
|
||||
SpriteT *sprite = NULL;
|
||||
SpriteT *spriteTemp = NULL;
|
||||
|
@ -1602,7 +1614,6 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) {
|
|||
_luaContext = luaL_newstate();
|
||||
luaL_openlibs(_luaContext);
|
||||
lua_atpanic(_luaContext, luaError);
|
||||
if (luaL_dofile(_luaContext, _confScriptFile) != 0) utilDie("Error compiling script: %s", lua_tostring(_luaContext, -1));
|
||||
|
||||
// Lua API for Singe
|
||||
lua_register(_luaContext, "colorBackground", apiColorBackground);
|
||||
|
@ -1699,6 +1710,7 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) {
|
|||
_mice[x].y = videoGetHeight(_videoHandle) / 2;
|
||||
}
|
||||
SDL_SetWindowGrab(_window, SDL_TRUE);
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
|
||||
// Create overlay texture
|
||||
_overlay = SDL_CreateTexture(_renderer, SDL_PIXELFORMAT_BGRA32, SDL_TEXTUREACCESS_TARGET, videoGetWidth(_videoHandle), videoGetHeight(_videoHandle));
|
||||
|
@ -1712,11 +1724,16 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) {
|
|||
_effectsVolume = (int)((float)AUDIO_MAX_VOLUME * (float)_confVolumeNonVldp * (float)0.01);
|
||||
Mix_Volume(-1, _effectsVolume * 2);
|
||||
|
||||
// Start video
|
||||
// Let us know when sounds end
|
||||
Mix_ChannelFinished(channelFinished);
|
||||
|
||||
// Start video paused
|
||||
videoPlay(_videoHandle);
|
||||
videoPause(_videoHandle);
|
||||
_discStopped = false;
|
||||
|
||||
//***TODO*** Sound completed callback
|
||||
// Start script
|
||||
if (luaL_dofile(_luaContext, _confScriptFile) != 0) utilDie("Error compiling script: %s", lua_tostring(_luaContext, -1));
|
||||
|
||||
// Game Loop
|
||||
while (_running) {
|
||||
|
@ -1829,28 +1846,34 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) {
|
|||
SDL_SetRenderTarget(_renderer, _overlay);
|
||||
callLua("onOverlayUpdate", ">i", &intReturn);
|
||||
if (intReturn == 1) {
|
||||
refresh = true;
|
||||
_refreshDisplay = true;
|
||||
}
|
||||
|
||||
// Update video
|
||||
thisFrame = videoUpdate(_videoHandle, &videoTexture);
|
||||
if ((thisFrame != lastFrame) && (thisFrame>= 0)) {
|
||||
lastFrame = thisFrame;
|
||||
refresh = true;
|
||||
_refreshDisplay = true;
|
||||
}
|
||||
|
||||
// Update display
|
||||
if (refresh) {
|
||||
if (_refreshDisplay) {
|
||||
//***TODO*** Handle overlay and blank disk frames
|
||||
SDL_SetRenderTarget(_renderer, NULL);
|
||||
SDL_RenderCopy(_renderer, videoTexture, NULL, NULL);
|
||||
//SDL_RenderCopy(_renderer, _overlay, NULL, NULL);
|
||||
SDL_RenderPresent(_renderer);
|
||||
refresh = false;
|
||||
_refreshDisplay = false;
|
||||
}
|
||||
}
|
||||
|
||||
// End game
|
||||
callLua("onShutdown", "");
|
||||
|
||||
// Stop all sounds
|
||||
Mix_HaltChannel(-1);
|
||||
Mix_ChannelFinished(NULL);
|
||||
|
||||
// Stop Lua
|
||||
lua_close(_luaContext);
|
||||
|
||||
|
@ -1891,5 +1914,6 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) {
|
|||
videoUnload(_videoHandle);
|
||||
|
||||
// Stop mice
|
||||
SDL_ShowCursor(SDL_ENABLE);
|
||||
ManyMouse_Quit();
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#
|
||||
|
||||
TARGET = singeEmu
|
||||
|
||||
# We're just a boring old C app
|
||||
TEMPLATE = app
|
||||
CONFIG += console
|
||||
|
|
Loading…
Add table
Reference in a new issue