Starting to patch games that leak memory.
This commit is contained in:
parent
36ea0b4d7e
commit
ea544996f1
5 changed files with 609 additions and 36 deletions
|
@ -187,6 +187,22 @@ ELSE()
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
|
|
||||||
|
set(LUASEC_SOURCE
|
||||||
|
thirdparty/luasec/src/compat.h
|
||||||
|
thirdparty/luasec/src/config.c
|
||||||
|
${BUILD_DIR}/generated/luasec_options.c
|
||||||
|
thirdparty/luasec/src/context.c
|
||||||
|
thirdparty/luasec/src/context.h
|
||||||
|
thirdparty/luasec/src/ec.c
|
||||||
|
thirdparty/luasec/src/ec.h
|
||||||
|
thirdparty/luasec/src/options.h
|
||||||
|
thirdparty/luasec/src/ssl.c
|
||||||
|
thirdparty/luasec/src/ssl.h
|
||||||
|
thirdparty/luasec/src/x509.c
|
||||||
|
thirdparty/luasec/src/x509.h
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
set(LUA_RS232_SOURCE
|
set(LUA_RS232_SOURCE
|
||||||
thirdparty/librs232/bindings/lua/luars232.c
|
thirdparty/librs232/bindings/lua/luars232.c
|
||||||
thirdparty/librs232/src/rs232.c
|
thirdparty/librs232/src/rs232.c
|
||||||
|
@ -228,6 +244,7 @@ add_executable(${CMAKE_PROJECT_NAME}
|
||||||
${LUA_SOURCE}
|
${LUA_SOURCE}
|
||||||
${LUA_FILESYSTEM_SOURCE}
|
${LUA_FILESYSTEM_SOURCE}
|
||||||
${LUA_SOCKET_SOURCE}
|
${LUA_SOCKET_SOURCE}
|
||||||
|
${LUASEC_SOURCE}
|
||||||
${LUA_RS232_SOURCE}
|
${LUA_RS232_SOURCE}
|
||||||
${UTHASH_SOURCE}
|
${UTHASH_SOURCE}
|
||||||
${MANYMOUSE_SOURCE}
|
${MANYMOUSE_SOURCE}
|
||||||
|
@ -257,6 +274,7 @@ target_compile_options(${CMAKE_PROJECT_NAME} PUBLIC
|
||||||
${DEFINE_LIST}
|
${DEFINE_LIST}
|
||||||
-DRS232_STATIC
|
-DRS232_STATIC
|
||||||
-DFFMS_STATIC
|
-DFFMS_STATIC
|
||||||
|
-Wno-deprecated-declarations
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -264,6 +282,7 @@ target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC
|
||||||
${BUILD_DIR}
|
${BUILD_DIR}
|
||||||
${BUILD_DIR}/include
|
${BUILD_DIR}/include
|
||||||
thirdparty/lua/src
|
thirdparty/lua/src
|
||||||
|
thirdparty/luasec/src
|
||||||
thirdparty/librs232/include
|
thirdparty/librs232/include
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -359,6 +378,8 @@ set(LIB_LIST
|
||||||
${BUILD_DIR}/lib/libz.a
|
${BUILD_DIR}/lib/libz.a
|
||||||
${BUILD_DIR}/lib/libzstd.a
|
${BUILD_DIR}/lib/libzstd.a
|
||||||
${BUILD_DIR}/lib/libarchive.a
|
${BUILD_DIR}/lib/libarchive.a
|
||||||
|
${BUILD_DIR}/lib/libcrypto.a
|
||||||
|
${BUILD_DIR}/lib/libssl.a
|
||||||
)
|
)
|
||||||
target_link_libraries(${CMAKE_PROJECT_NAME}
|
target_link_libraries(${CMAKE_PROJECT_NAME}
|
||||||
-Wl,--start-group
|
-Wl,--start-group
|
||||||
|
|
|
@ -31,19 +31,7 @@ function compareTitles(a, b)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function loadGameAssets(firstGame)
|
function loadGameAssets()
|
||||||
|
|
||||||
if not firstGame then
|
|
||||||
spriteUnload(SPRITE_CABINET)
|
|
||||||
spriteUnload(SPRITE_MARQUEE)
|
|
||||||
videoUnload(VIDEO_ATTRACT)
|
|
||||||
for _, handle in ipairs(TEXT_SPRITE_LIST) do
|
|
||||||
if handle >= 0 then
|
|
||||||
spriteUnload(handle)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
TEXT_SPRITE_LIST = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
SPRITE_CABINET = spriteLoad(GAME_LIST[GAME_SELECTED].CABINET)
|
SPRITE_CABINET = spriteLoad(GAME_LIST[GAME_SELECTED].CABINET)
|
||||||
SPRITE_MARQUEE = spriteLoad(GAME_LIST[GAME_SELECTED].MARQUEE)
|
SPRITE_MARQUEE = spriteLoad(GAME_LIST[GAME_SELECTED].MARQUEE)
|
||||||
|
@ -91,7 +79,8 @@ function onInputPressed(what)
|
||||||
if GAME_SELECTED < 1 then
|
if GAME_SELECTED < 1 then
|
||||||
GAME_SELECTED = GAME_COUNT
|
GAME_SELECTED = GAME_COUNT
|
||||||
end
|
end
|
||||||
loadGameAssets(false)
|
unloadGameAssets()
|
||||||
|
loadGameAssets()
|
||||||
end
|
end
|
||||||
|
|
||||||
if what == SWITCH_RIGHT then
|
if what == SWITCH_RIGHT then
|
||||||
|
@ -99,7 +88,8 @@ function onInputPressed(what)
|
||||||
if GAME_SELECTED > GAME_COUNT then
|
if GAME_SELECTED > GAME_COUNT then
|
||||||
GAME_SELECTED = 1
|
GAME_SELECTED = 1
|
||||||
end
|
end
|
||||||
loadGameAssets(false)
|
unloadGameAssets()
|
||||||
|
loadGameAssets()
|
||||||
end
|
end
|
||||||
|
|
||||||
if what == SWITCH_START1 or what == SWITCH_START2 or what == SWITCH_BUTTON1 or what == SWITCH_BUTTON2 or what == SWITCH_BUTTON3 or what == SWITCH_BUTTON4 then
|
if what == SWITCH_START1 or what == SWITCH_START2 or what == SWITCH_BUTTON1 or what == SWITCH_BUTTON2 or what == SWITCH_BUTTON3 or what == SWITCH_BUTTON4 then
|
||||||
|
@ -179,6 +169,7 @@ end
|
||||||
|
|
||||||
|
|
||||||
function onShutdown()
|
function onShutdown()
|
||||||
|
unloadGameAssets()
|
||||||
saveConfig(not SHUTDOWN_FROM_PUSH)
|
saveConfig(not SHUTDOWN_FROM_PUSH)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -194,6 +185,19 @@ function saveConfig(showIntro)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function unloadGameAssets()
|
||||||
|
spriteUnload(SPRITE_CABINET)
|
||||||
|
spriteUnload(SPRITE_MARQUEE)
|
||||||
|
videoUnload(VIDEO_ATTRACT)
|
||||||
|
for _, handle in ipairs(TEXT_SPRITE_LIST) do
|
||||||
|
if handle >= 0 then
|
||||||
|
spriteUnload(handle)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
TEXT_SPRITE_LIST = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function wrapText(text, maxWidth)
|
function wrapText(text, maxWidth)
|
||||||
local words = {}
|
local words = {}
|
||||||
local toWrap = ""
|
local toWrap = ""
|
||||||
|
@ -357,5 +361,5 @@ else
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Prime the pump
|
-- Prime the pump
|
||||||
loadGameAssets(true)
|
loadGameAssets()
|
||||||
end
|
end
|
||||||
|
|
34
build-all.sh
34
build-all.sh
|
@ -174,6 +174,34 @@ if [[ 0 == 1 ]]; then
|
||||||
..
|
..
|
||||||
popd
|
popd
|
||||||
|
|
||||||
|
pushd thirdparty/openssl
|
||||||
|
clearAndEnterBuild
|
||||||
|
# --cross-compile-prefix="${TRIPLE}-" \
|
||||||
|
../Configure \
|
||||||
|
--prefix="${G_TARGET}" \
|
||||||
|
--libdir=lib \
|
||||||
|
--with-zlib-include="${G_TARGET}/include" \
|
||||||
|
--with-zlib-lib="${G_TARGET}/lib" \
|
||||||
|
--with-zstd-include="${G_TARGET}/include" \
|
||||||
|
--with-zstd-lib="${G_TARGET}/lib" \
|
||||||
|
no-apps \
|
||||||
|
no-docs \
|
||||||
|
no-dso \
|
||||||
|
no-dynamic-engine \
|
||||||
|
no-module \
|
||||||
|
no-shared \
|
||||||
|
no-tests \
|
||||||
|
zlib \
|
||||||
|
enable-zstd
|
||||||
|
make install
|
||||||
|
popd
|
||||||
|
|
||||||
|
lua thirdparty/luasec/src/options.lua -g "${G_TARGET}/include/openssl/ssl.h" > "${G_TARGET}/generated/luasec_options.c"
|
||||||
|
mkdir -p "${G_TARGET}/include/luasocket"
|
||||||
|
cp -f \
|
||||||
|
thirdparty/luasocket/src/*.h \
|
||||||
|
"${G_TARGET}/include/luasocket/."
|
||||||
|
|
||||||
pushd thirdparty/ffmpeg
|
pushd thirdparty/ffmpeg
|
||||||
clearAndEnterBuild
|
clearAndEnterBuild
|
||||||
# https://trac.ffmpeg.org/wiki/CompilationGuide/CrossCompilingForWindows
|
# https://trac.ffmpeg.org/wiki/CompilationGuide/CrossCompilingForWindows
|
||||||
|
@ -200,8 +228,8 @@ if [[ 0 == 1 ]]; then
|
||||||
--cxx="${CXX}" \
|
--cxx="${CXX}" \
|
||||||
--ranlib="${RANLIB}"
|
--ranlib="${RANLIB}"
|
||||||
#" -l:libz.a -l:liblzma.a" \
|
#" -l:libz.a -l:liblzma.a" \
|
||||||
make install
|
make install
|
||||||
popd
|
popd
|
||||||
|
|
||||||
pushd thirdparty/ffms2
|
pushd thirdparty/ffms2
|
||||||
#libtoolize --force
|
#libtoolize --force
|
||||||
|
@ -223,7 +251,6 @@ if [[ 0 == 1 ]]; then
|
||||||
--build=x86_64-linux
|
--build=x86_64-linux
|
||||||
make install-libLTLIBRARIES # This weird target prevents building the command line tools.
|
make install-libLTLIBRARIES # This weird target prevents building the command line tools.
|
||||||
popd
|
popd
|
||||||
fi
|
|
||||||
|
|
||||||
# === Known FFMPEG Types ===
|
# === Known FFMPEG Types ===
|
||||||
createExtensionHeader ffmpeg > ${G_GENERATED}/extensions.h
|
createExtensionHeader ffmpeg > ${G_GENERATED}/extensions.h
|
||||||
|
@ -276,6 +303,7 @@ fi
|
||||||
createEmbeddedBinary ${G_TARGET}/Manual.pdf ${G_GENERATED}/Manual_pdf.h MANUAL_H
|
createEmbeddedBinary ${G_TARGET}/Manual.pdf ${G_GENERATED}/Manual_pdf.h MANUAL_H
|
||||||
rm ${G_TARGET}/Manual.pdf
|
rm ${G_TARGET}/Manual.pdf
|
||||||
UNUSED
|
UNUSED
|
||||||
|
fi
|
||||||
|
|
||||||
pushd ${G_TARGET}
|
pushd ${G_TARGET}
|
||||||
clearAndEnterBuild
|
clearAndEnterBuild
|
||||||
|
|
521
patches/ActionMax/Emulator.singe
Executable file
521
patches/ActionMax/Emulator.singe
Executable file
|
@ -0,0 +1,521 @@
|
||||||
|
dofile("Singe/Framework.singe")
|
||||||
|
|
||||||
|
stateStartup = 0
|
||||||
|
stateSetup = 1
|
||||||
|
stateTitle = 2
|
||||||
|
stateMenu = 3
|
||||||
|
stateIntro = 4
|
||||||
|
statePlaying = 5
|
||||||
|
stateGameOver = 6
|
||||||
|
|
||||||
|
gameStandard = 0
|
||||||
|
gameLimited = 1
|
||||||
|
|
||||||
|
pixelLow = 0
|
||||||
|
pixelHigh = 1
|
||||||
|
pixelUnknown = 2
|
||||||
|
|
||||||
|
sprLightOn = spriteLoad("ActionMax/sprite_LightOn.png")
|
||||||
|
sprLightOff = spriteLoad("ActionMax/sprite_LightOff.png")
|
||||||
|
sprActionMax = spriteLoad("ActionMax/sprite_ActionMax.png")
|
||||||
|
sprCrosshair = spriteLoad("ActionMax/sprite_Crosshair.png")
|
||||||
|
sprBullet = spriteLoad("ActionMax/sprite_Bullet.png")
|
||||||
|
sprBoxArt = spriteLoad("ActionMax/sprite_" .. gameID .. ".png")
|
||||||
|
|
||||||
|
sndActionMax = soundLoad("ActionMax/sound_ActionMax.wav")
|
||||||
|
sndSteadyAim = soundLoad("ActionMax/sound_ASteadyAimIsCritical.wav")
|
||||||
|
sndGetReady = soundLoad("ActionMax/sound_GetReadyForAction.wav")
|
||||||
|
sndGunShot = soundLoad("ActionMax/sound_Gunshot.wav")
|
||||||
|
sndGoodHit = soundLoad("ActionMax/sound_GoodHit.wav")
|
||||||
|
sndBadHit = soundLoad("ActionMax/sound_BadHit.wav")
|
||||||
|
sndGameOver = soundLoad("ActionMax/sound_GameOver.wav")
|
||||||
|
|
||||||
|
mouseX = 0
|
||||||
|
mouseY = 0
|
||||||
|
|
||||||
|
halfWidth = 0
|
||||||
|
|
||||||
|
crosshairCenterX = spriteGetWidth(sprCrosshair) / 2
|
||||||
|
crosshairCenterY = spriteGetHeight(sprCrosshair) / 2
|
||||||
|
|
||||||
|
currentState = stateStartup
|
||||||
|
gameMode = gameStandard
|
||||||
|
|
||||||
|
shotsFired = 0 -- Total Fired
|
||||||
|
shotsGood = 0 -- Hit our target
|
||||||
|
shotsBad = 0 -- Hit our friends
|
||||||
|
|
||||||
|
scoreDisplay = 0 -- How long the score is yet to be displayed
|
||||||
|
scoreTimer = 4 -- How long to display the score + 1
|
||||||
|
|
||||||
|
lightDisplay = 0 -- How long the light is yet to be displayed
|
||||||
|
lightTimer = 2 -- How long to display the light + 1
|
||||||
|
|
||||||
|
triggerPulled = 0 -- This isn't quite a boolean. It counts down so we can get multiple pixel samples across frames.
|
||||||
|
|
||||||
|
ammoLeft = 0 -- Number of misses remaining in limited ammo mode
|
||||||
|
ammoCount = 5 -- Number of misses allowed in limited ammo mode
|
||||||
|
|
||||||
|
gunLastState = pixelUnknown
|
||||||
|
sensorLastState = pixelUnknown
|
||||||
|
|
||||||
|
thisSeconds = 0
|
||||||
|
lastSeconds = 0
|
||||||
|
heartbeat = false
|
||||||
|
|
||||||
|
fntBlueStone20 = fontLoad("ActionMax/font_BlueStone.ttf", 20)
|
||||||
|
fntChemRea16 = fontLoad("ActionMax/font_chemrea.ttf", 16)
|
||||||
|
fntChemRea32 = fontLoad("ActionMax/font_chemrea.ttf", 32)
|
||||||
|
fntChemRea48 = fontLoad("ActionMax/font_chemrea.ttf", 48)
|
||||||
|
fntLEDReal32 = fontLoad("ActionMax/font_LED_Real.ttf", 32)
|
||||||
|
|
||||||
|
colorBackground(0, 0, 0, 0)
|
||||||
|
fontQuality(FONT_QUALITY_BLENDED)
|
||||||
|
|
||||||
|
colorForeground(255, 255, 0)
|
||||||
|
fontSelect(fntBlueStone20)
|
||||||
|
sprPullToStart = fontToSprite("Pull Trigger to Start!")
|
||||||
|
sprGetReady = fontToSprite("Get Ready!")
|
||||||
|
|
||||||
|
colorForeground(255, 255, 255)
|
||||||
|
fontSelect(fntChemRea16)
|
||||||
|
sprLastGame = fontToSprite("LAST GAME SCORE")
|
||||||
|
|
||||||
|
colorForeground(255, 255, 0)
|
||||||
|
fontSelect(fntChemRea32)
|
||||||
|
sprSelectGameType = fontToSprite("Select Game Type")
|
||||||
|
sprStandard1 = fontToSprite("Standard")
|
||||||
|
sprStandard2 = fontToSprite("Game")
|
||||||
|
sprLimited1 = fontToSprite("Limited")
|
||||||
|
sprLimited2 = fontToSprite("Ammo")
|
||||||
|
|
||||||
|
colorForeground(255, 0, 0)
|
||||||
|
fontSelect(fntChemRea48)
|
||||||
|
sprGameOver = fontToSprite("GAME OVER")
|
||||||
|
|
||||||
|
discSearch(backgroundFrame)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function getPixelState(intX, intY)
|
||||||
|
|
||||||
|
r1, g1, b1 = vldpGetPixel(intX, intY)
|
||||||
|
|
||||||
|
-- Determine pixel state
|
||||||
|
if ((255 - r1 < highThreshold) and (255 - g1 < highThreshold) and (255 - b1 < highThreshold)) then
|
||||||
|
pixelState = pixelHigh
|
||||||
|
elseif ((r1 < lowThreshold) and (g1 < lowThreshold) and (b1 < lowThreshold)) then
|
||||||
|
pixelState = pixelLow
|
||||||
|
else
|
||||||
|
pixelState = pixelUnknown
|
||||||
|
end
|
||||||
|
|
||||||
|
return pixelState
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function onInputPressed(intWhat)
|
||||||
|
|
||||||
|
--dr, dg, db = vldpGetPixel(mouseX, mouseY)
|
||||||
|
--debugPrint("Current Frame: " .. discGetFrame() .. " X: " .. mouseX .. " Y: " .. mouseY .. " R: " .. dr .. " G: " .. dg .. " B: " .. db)
|
||||||
|
|
||||||
|
-- They fired!
|
||||||
|
if (intWhat == SWITCH_BUTTON3) then
|
||||||
|
|
||||||
|
if (currentState == stateTitle) then
|
||||||
|
|
||||||
|
discSearch(lengthIntro + lengthGame + 2)
|
||||||
|
discPlay()
|
||||||
|
currentState = stateMenu
|
||||||
|
|
||||||
|
elseif (currentState == stateMenu) then
|
||||||
|
|
||||||
|
if (mouseX < halfWidth) then
|
||||||
|
gameMode = gameStandard
|
||||||
|
else
|
||||||
|
ammoLeft = ammoCount
|
||||||
|
gameMode = gameLimited
|
||||||
|
end
|
||||||
|
|
||||||
|
shotsFired = 0
|
||||||
|
shotsGood = 0
|
||||||
|
shotsBad = 0
|
||||||
|
colorForeground(255, 0, 0)
|
||||||
|
fontSelect(fntLEDReal32)
|
||||||
|
discSearch(1)
|
||||||
|
discPlay()
|
||||||
|
soundPlay(sndGetReady)
|
||||||
|
currentState = stateIntro
|
||||||
|
|
||||||
|
elseif (currentState == statePlaying) then
|
||||||
|
|
||||||
|
-- Make gunshot noise
|
||||||
|
soundPlay(sndGunShot)
|
||||||
|
|
||||||
|
-- We want to sample across two frames
|
||||||
|
triggerPulled = 2
|
||||||
|
|
||||||
|
shotsFired = shotsFired + 1
|
||||||
|
|
||||||
|
-- No matter what, we subtract ammo. On good hits, we add it back to make it look like nothing changed.
|
||||||
|
if (gameMode == gameLimited) then
|
||||||
|
ammoLeft = ammoLeft - 1
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--dbgPaused = 0
|
||||||
|
--dbgSpeed = 1
|
||||||
|
|
||||||
|
function onInputReleased(intWhat)
|
||||||
|
|
||||||
|
--[[ We don't use this. All this is debug stuff.
|
||||||
|
|
||||||
|
if (intWhat == SWITCH_BUTTON1) then
|
||||||
|
if (currentState == statePlaying) then
|
||||||
|
discSearch(lengthIntro + lengthGame - 60)
|
||||||
|
discPlay()
|
||||||
|
else
|
||||||
|
if (dbgPaused == 1) then
|
||||||
|
discPlay()
|
||||||
|
dbgPaused = 0
|
||||||
|
else
|
||||||
|
discPause()
|
||||||
|
dbgPaused = 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if (intWhat == SWITCH_RIGHT) then
|
||||||
|
if (dbgSpeed < 4) then
|
||||||
|
dbgSpeed = dbgSpeed + 1
|
||||||
|
end
|
||||||
|
discChangeSpeed(dbgSpeed, 1)
|
||||||
|
end
|
||||||
|
if (intWhat == SWITCH_LEFT) then
|
||||||
|
if (dbgSpeed > 1) then
|
||||||
|
dbgSpeed = dbgSpeed - 1
|
||||||
|
end
|
||||||
|
discChangeSpeed(dbgSpeed, 1)
|
||||||
|
end
|
||||||
|
if (intWhat == SWITCH_UP) then
|
||||||
|
discStepBackward()
|
||||||
|
end
|
||||||
|
if (intWhat == SWITCH_DOWN) then
|
||||||
|
discStepForward()
|
||||||
|
end
|
||||||
|
|
||||||
|
--]]
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function onMouseMoved(intX, intY, intXrel, intYrel)
|
||||||
|
|
||||||
|
-- Remember the mouse location for use later.
|
||||||
|
mouseX = intX
|
||||||
|
mouseY = intY
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function onOverlayUpdate()
|
||||||
|
|
||||||
|
overlayClear()
|
||||||
|
|
||||||
|
currentFrame = discGetFrame()
|
||||||
|
|
||||||
|
-- Give us a 1 second heartbeat for overlay element timing
|
||||||
|
thisSeconds = os.time(os.date('*t'))
|
||||||
|
if (thisSeconds ~= lastSeconds) then
|
||||||
|
heartbeat = not heartbeat
|
||||||
|
lastSeconds = thisSeconds
|
||||||
|
-- Tick off floating score display
|
||||||
|
if (scoreDisplay > 0) then
|
||||||
|
scoreDisplay = scoreDisplay - 1
|
||||||
|
end
|
||||||
|
-- Tick off light timer
|
||||||
|
if (lightDisplay > 0) then
|
||||||
|
lightDisplay = lightDisplay - 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if (currentState == stateStartup) then
|
||||||
|
|
||||||
|
-- We run this state to cause the overlay to update once before we use the dimensions to build the menu
|
||||||
|
overlayClear()
|
||||||
|
currentState = stateSetup
|
||||||
|
|
||||||
|
elseif (currentState == stateSetup) then
|
||||||
|
|
||||||
|
-- We do all the math to draw the menu here, one time.
|
||||||
|
halfWidth = (overlayGetWidth() / 2)
|
||||||
|
|
||||||
|
logoTop = 5
|
||||||
|
logoLeft = halfWidth - (spriteGetWidth(sprActionMax) / 2)
|
||||||
|
logoHeight = logoTop + spriteGetHeight(sprActionMax)
|
||||||
|
|
||||||
|
pullToStartHeight = spriteGetHeight(sprPullToStart)
|
||||||
|
pullToStartTop = overlayGetHeight() - pullToStartHeight
|
||||||
|
pullToStartLeft = halfWidth - (spriteGetWidth(sprPullToStart) / 2)
|
||||||
|
|
||||||
|
getReadyHeight = spriteGetHeight(sprGetReady)
|
||||||
|
getReadyTop = overlayGetHeight() - getReadyHeight
|
||||||
|
getReadyLeft = halfWidth - (spriteGetWidth(sprGetReady) / 2)
|
||||||
|
|
||||||
|
boxLeft = (halfWidth / 2) - spriteGetWidth(sprBoxArt) / 2 + halfWidth
|
||||||
|
boxTop = (overlayGetHeight() - (logoHeight + pullToStartHeight)) / 2 - spriteGetHeight(sprBoxArt) / 2 + logoHeight
|
||||||
|
|
||||||
|
lastGameLeft = (halfWidth / 2) - spriteGetWidth(sprLastGame) / 2
|
||||||
|
lastGameTop = logoHeight + logoTop
|
||||||
|
|
||||||
|
scoreHeight = 13 -- Point size + 1 instead of spriteGetHeight(sprLastGame)
|
||||||
|
scoreTop = lastGameTop + scoreHeight + 10
|
||||||
|
scoreLeft = lastGameLeft
|
||||||
|
|
||||||
|
lightLeft = overlayGetWidth() - spriteGetWidth(sprLightOff)
|
||||||
|
lightTop = overlayGetHeight() - spriteGetHeight(sprLightOff)
|
||||||
|
|
||||||
|
bulletWidth = spriteGetWidth(sprBullet)
|
||||||
|
|
||||||
|
selectGameTypeLeft = halfWidth - spriteGetWidth(sprSelectGameType) / 2
|
||||||
|
selectGameTypeTop = 25
|
||||||
|
|
||||||
|
standard1Left = halfWidth / 2 - spriteGetWidth(sprStandard1) / 2
|
||||||
|
standard2Left = halfWidth / 2 - spriteGetWidth(sprStandard2) / 2
|
||||||
|
|
||||||
|
limited1Left = halfWidth + (halfWidth / 2) - spriteGetWidth(sprLimited1) / 2
|
||||||
|
limited2Left = halfWidth + (halfWidth / 2) - spriteGetWidth(sprLimited2) / 2
|
||||||
|
|
||||||
|
standardLimited1Top = (overlayGetHeight() / 2) - spriteGetHeight(sprStandard1) + 2
|
||||||
|
standardLimited2Top = (overlayGetHeight() / 2) + 2
|
||||||
|
|
||||||
|
gameOverLeft = halfWidth - spriteGetWidth(sprGameOver) / 2
|
||||||
|
gameOverTop = (overlayGetHeight() / 2) - spriteGetHeight(sprGameOver)
|
||||||
|
|
||||||
|
colorForeground(200, 200, 200)
|
||||||
|
fontSelect(fntChemRea16)
|
||||||
|
|
||||||
|
hndActionMaxSound = soundPlay(sndActionMax)
|
||||||
|
|
||||||
|
currentState = stateTitle
|
||||||
|
|
||||||
|
elseif (currentState == stateTitle) then
|
||||||
|
|
||||||
|
spriteDraw(logoLeft, logoTop, sprActionMax)
|
||||||
|
spriteDraw(boxLeft, boxTop, sprBoxArt)
|
||||||
|
spriteDraw(lastGameLeft, lastGameTop, sprLastGame)
|
||||||
|
y = scoreTop
|
||||||
|
fontPrint(scoreLeft, y, " Shots Fired: " .. shotsFired)
|
||||||
|
y = y + scoreHeight
|
||||||
|
fontPrint(scoreLeft, y, " Good Hits: " .. shotsGood)
|
||||||
|
y = y + scoreHeight
|
||||||
|
fontPrint(scoreLeft, y, " Bad Hits: " .. shotsBad)
|
||||||
|
y = y + scoreHeight
|
||||||
|
fontPrint(scoreLeft, y, " Shot Score: " .. shotsGood - shotsBad)
|
||||||
|
y = y + scoreHeight * 2
|
||||||
|
if (shotsFired > 0) then
|
||||||
|
scorePercent = math.floor((shotsGood - shotsBad) / shotsFired * 100)
|
||||||
|
else
|
||||||
|
scorePercent = 0
|
||||||
|
end
|
||||||
|
fontPrint(scoreLeft, y, " Game Score: " .. scorePercent .. "%")
|
||||||
|
if (heartbeat) then
|
||||||
|
spriteDraw(pullToStartLeft, pullToStartTop, sprPullToStart)
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif (currentState == stateMenu) then
|
||||||
|
|
||||||
|
spriteDraw(selectGameTypeLeft, selectGameTypeTop, sprSelectGameType)
|
||||||
|
spriteDraw(standard1Left, standardLimited1Top, sprStandard1)
|
||||||
|
spriteDraw(standard2Left, standardLimited2Top, sprStandard2)
|
||||||
|
spriteDraw(limited1Left, standardLimited1Top, sprLimited1)
|
||||||
|
spriteDraw(limited2Left, standardLimited2Top, sprLimited2)
|
||||||
|
|
||||||
|
if (currentFrame >= lengthIntro + lengthGame + lengthMenu) then
|
||||||
|
discSearch(lengthIntro + lengthGame + 2)
|
||||||
|
discPlay()
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif (currentState == stateIntro) then
|
||||||
|
|
||||||
|
if (heartbeat) then
|
||||||
|
spriteDraw(getReadyLeft, getReadyTop, sprGetReady)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Skip into game video when the intro is over.
|
||||||
|
if (currentFrame >= lengthIntro) then
|
||||||
|
discSearch(lengthIntro + 1)
|
||||||
|
discPlay()
|
||||||
|
currentState = statePlaying
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif (currentState == statePlaying) then
|
||||||
|
|
||||||
|
-- Read Sucton Cup Sensor.
|
||||||
|
sensorLastState = sensorState
|
||||||
|
sensorState = getPixelState(sensorX, sensorY)
|
||||||
|
-- Are they firing?
|
||||||
|
if (triggerPulled > 0) then
|
||||||
|
-- New frame (according to the sensor)?
|
||||||
|
if (sensorLastState ~= sensorState) then
|
||||||
|
-- Did they aim outside the suction cup sensor area?
|
||||||
|
if ((mouseX < sensorLeft) or (mouseY < sensorTop)) then
|
||||||
|
-- Yes. Process shot.
|
||||||
|
gunState = getPixelState(mouseX, mouseY)
|
||||||
|
else
|
||||||
|
-- No. They shot the sensor area. Bad user.
|
||||||
|
gunState = pixelUnknown
|
||||||
|
end
|
||||||
|
-- Are we doing the first or second frame sample?
|
||||||
|
if (triggerPulled == 1) then
|
||||||
|
--debugPrint("S1: " .. sensorLastState .. " S2: " .. sensorState .. " G1: " .. gunLastState .. " G2: " .. gunState)
|
||||||
|
-- Decide what happened. Do we have two good samples of each sensor?
|
||||||
|
if ((gunState ~= pixelUnknown) and (sensorState ~= pixelUnknown) and (gunLastState ~= pixelUnknown) and (sensorLastState ~= pixelUnknown)) then
|
||||||
|
-- If the sensor and gun states didn't change between frames, then this makes no sense.
|
||||||
|
if (gunLastState ~= gunState) then
|
||||||
|
-- Does the gun match the sensor?
|
||||||
|
if (gunState == sensorState) then
|
||||||
|
-- Yes! Hit bad guy!
|
||||||
|
soundPlay(sndGoodHit)
|
||||||
|
shotsGood = shotsGood + 1
|
||||||
|
lightDisplay = lightTimer
|
||||||
|
-- Add it back to make it look like nothing changed.
|
||||||
|
if (gameMode == gameLimited) then
|
||||||
|
ammoLeft = ammoLeft + 1
|
||||||
|
end
|
||||||
|
else
|
||||||
|
-- No. Crap - shot a good guy!
|
||||||
|
soundPlay(sndBadHit)
|
||||||
|
shotsBad = shotsBad + 1
|
||||||
|
end
|
||||||
|
-- Float the score for a bit
|
||||||
|
scoreDisplay = scoreTimer
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
-- Remember this info for next pass
|
||||||
|
gunLastState = gunState
|
||||||
|
end
|
||||||
|
-- Get ready for next pass
|
||||||
|
triggerPulled = triggerPulled - 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- When the game is over, return to the menu.
|
||||||
|
if (currentFrame >= lengthIntro + lengthGame) then
|
||||||
|
discPause()
|
||||||
|
discSearch(backgroundFrame)
|
||||||
|
colorForeground(255, 255, 255)
|
||||||
|
fontSelect(fntChemRea16)
|
||||||
|
currentState = stateTitle
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Do we need to show the score?
|
||||||
|
if (scoreDisplay > 0) then
|
||||||
|
fontPrint(5, 5, "SCORE: " .. (shotsGood - shotsBad))
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Do we need to light the light?
|
||||||
|
if (lightDisplay > 0) then
|
||||||
|
spriteDraw(lightLeft, lightTop, sprLightOn)
|
||||||
|
else
|
||||||
|
spriteDraw(lightLeft, lightTop, sprLightOff)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Do we need to draw the ammo display?
|
||||||
|
if (gameMode == gameLimited) then
|
||||||
|
-- Are they out of ammo?
|
||||||
|
if (ammoLeft < 0) then
|
||||||
|
discSearch(lengthIntro + lengthGame + 2)
|
||||||
|
discPlay()
|
||||||
|
soundPlay(sndGameOver)
|
||||||
|
currentState = stateGameOver
|
||||||
|
end
|
||||||
|
if (ammoLeft > 0) then
|
||||||
|
bulletStart = overlayGetWidth() - bulletWidth - 5
|
||||||
|
for i=1,ammoLeft do
|
||||||
|
spriteDraw(bulletStart, 0, sprBullet)
|
||||||
|
bulletStart = bulletStart - bulletWidth
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif (currentState == stateGameOver) then
|
||||||
|
|
||||||
|
spriteDraw(gameOverLeft, gameOverTop, sprGameOver)
|
||||||
|
|
||||||
|
if (currentFrame >= lengthIntro + lengthGame + lengthMenu) then
|
||||||
|
discPause()
|
||||||
|
discSearch(backgroundFrame)
|
||||||
|
colorForeground(255, 255, 255)
|
||||||
|
fontSelect(fntChemRea16)
|
||||||
|
currentState = stateTitle
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Draw gun crosshair (This must be the last thing we draw so it's on top.)
|
||||||
|
if (singeWantsCrosshairs()) then
|
||||||
|
spriteDraw(mouseX - crosshairCenterX, mouseY - crosshairCenterY, sprCrosshair)
|
||||||
|
end
|
||||||
|
|
||||||
|
return(OVERLAY_UPDATED)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function onShutdown()
|
||||||
|
|
||||||
|
discStop()
|
||||||
|
|
||||||
|
-- Unload our resources.
|
||||||
|
|
||||||
|
fontUnload(fntBlueStone20)
|
||||||
|
fontUnload(fntChemRea16)
|
||||||
|
fontUnload(fntChemRea32)
|
||||||
|
fontUnload(fntChemRea48)
|
||||||
|
fontUnload(fntLEDReal32)
|
||||||
|
|
||||||
|
soundUnload(sndActionMax)
|
||||||
|
soundUnload(sndSteadyAim)
|
||||||
|
soundUnload(sndGetReady)
|
||||||
|
soundUnload(sndGunShot)
|
||||||
|
soundUnload(sndGoodHit)
|
||||||
|
soundUnload(sndBadHit)
|
||||||
|
soundUnload(sndGameOver)
|
||||||
|
|
||||||
|
spriteUnload(sprLightOn)
|
||||||
|
spriteUnload(sprLightOff)
|
||||||
|
spriteUnload(sprActionMax)
|
||||||
|
spriteUnload(sprCrosshair)
|
||||||
|
spriteUnload(sprBullet)
|
||||||
|
spriteUnload(sprBoxArt)
|
||||||
|
|
||||||
|
spriteUnload(sprPullToStart)
|
||||||
|
spriteUnload(sprGetReady)
|
||||||
|
spriteUnload(sprLastGame)
|
||||||
|
spriteUnload(sprSelectGameType)
|
||||||
|
spriteUnload(sprStandard1)
|
||||||
|
spriteUnload(sprStandard2)
|
||||||
|
spriteUnload(sprLimited1)
|
||||||
|
spriteUnload(sprLimited2)
|
||||||
|
spriteUnload(sprGameOver)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function onSoundCompleted(intWhich)
|
||||||
|
|
||||||
|
-- Play the "A Steady Aim is Critical" sound after "ActionMax" is finished.
|
||||||
|
if (intWhich == hndActionMaxSound) then
|
||||||
|
soundPlay(sndSteadyAim)
|
||||||
|
hndActionMaxSound = SOUND_REMOVE_HANDLE
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
33
src/singe.c
33
src/singe.c
|
@ -29,10 +29,12 @@
|
||||||
#include "../thirdparty/lua/src/lua.h"
|
#include "../thirdparty/lua/src/lua.h"
|
||||||
#include "../thirdparty/lua/src/lualib.h"
|
#include "../thirdparty/lua/src/lualib.h"
|
||||||
#include "../thirdparty/lua/src/lauxlib.h"
|
#include "../thirdparty/lua/src/lauxlib.h"
|
||||||
|
|
||||||
#include "../thirdparty/uthash/src/uthash.h"
|
#include "../thirdparty/uthash/src/uthash.h"
|
||||||
#include "../thirdparty/manymouse/manymouse.h"
|
#include "../thirdparty/manymouse/manymouse.h"
|
||||||
#include "../thirdparty/luafilesystem/src/lfs.h"
|
#include "../thirdparty/luafilesystem/src/lfs.h"
|
||||||
|
#include "../thirdparty/luasec/src/context.h"
|
||||||
|
#include "../thirdparty/luasec/src/ssl.h"
|
||||||
|
#include "../thirdparty/luasec/src/x509.h"
|
||||||
#include "../thirdparty/luasocket/src/luasocket.h"
|
#include "../thirdparty/luasocket/src/luasocket.h"
|
||||||
#include "../thirdparty/luasocket/src/mime.h"
|
#include "../thirdparty/luasocket/src/mime.h"
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
|
@ -42,6 +44,8 @@ LUASOCKET_API int luaopen_socket_serial(lua_State *L);
|
||||||
#endif
|
#endif
|
||||||
// There is no header for rs232 binding. Make our own.
|
// There is no header for rs232 binding. Make our own.
|
||||||
int luaopen_luars232(lua_State *L);
|
int luaopen_luars232(lua_State *L);
|
||||||
|
// There is no header for ssl.config binding. Make our own.
|
||||||
|
LSEC_API int luaopen_ssl_config(lua_State *L);
|
||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
@ -2804,30 +2808,18 @@ int32_t apiSingeGetDataPath(lua_State *L) {
|
||||||
|
|
||||||
|
|
||||||
int32_t apiSingeSetGameName(lua_State *L) {
|
int32_t apiSingeSetGameName(lua_State *L) {
|
||||||
// Adds the name of the singe game to the window's title bar.
|
|
||||||
// Valid value is a string no longer than 25 characters.
|
|
||||||
// e.g. lua code,
|
|
||||||
//
|
|
||||||
// singeSetGameName("My FMV game")
|
|
||||||
//
|
|
||||||
// Function returns nothing.
|
|
||||||
//
|
|
||||||
// --rdg
|
|
||||||
|
|
||||||
int32_t n = lua_gettop(L);
|
int32_t n = lua_gettop(L);
|
||||||
bool result = false;
|
bool result = false;
|
||||||
char thisName[MAX_TITLE_LENGTH];
|
|
||||||
|
|
||||||
if (n == 1) {
|
if (n == 1) {
|
||||||
if (lua_isstring(L, 1)) {
|
if (lua_isstring(L, 1)) {
|
||||||
sprintf(thisName,"%.40s", lua_tostring(L, 1)); // Need a better way to do this...?
|
SDL_SetWindowTitle(_global.window, lua_tostring(L, 1));
|
||||||
SDL_SetWindowTitle(_global.window, thisName);
|
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
luaTrace(L, "singeSetGameName", "%s", thisName);
|
luaTrace(L, "singeSetGameName", "%s", lua_tostring(L, 1));
|
||||||
} else {
|
} else {
|
||||||
luaDie(L, "singeSetGameName", "Failed!");
|
luaDie(L, "singeSetGameName", "Failed!");
|
||||||
}
|
}
|
||||||
|
@ -4025,7 +4017,6 @@ void singe(SDL_Window *window, SDL_Renderer *renderer, ConfigT *conf) {
|
||||||
|
|
||||||
case SDL_CONTROLLERDEVICEADDED:
|
case SDL_CONTROLLERDEVICEADDED:
|
||||||
case SDL_CONTROLLERDEVICEREMOVED:
|
case SDL_CONTROLLERDEVICEREMOVED:
|
||||||
progTrace("Updating connected controllers list");
|
|
||||||
stopControllers();
|
stopControllers();
|
||||||
startControllers();
|
startControllers();
|
||||||
break;
|
break;
|
||||||
|
@ -4161,7 +4152,7 @@ void singe(SDL_Window *window, SDL_Renderer *renderer, ConfigT *conf) {
|
||||||
// Fire event
|
// Fire event
|
||||||
callLua("onMouseMoved", "iiiii", x, y, xr, yr, mouseEvent.device);
|
callLua("onMouseMoved", "iiiii", x, y, xr, yr, mouseEvent.device);
|
||||||
*/
|
*/
|
||||||
progTrace("Unimplemented MANYMOUSE_EVENT_ABSMOTION called");
|
//progTrace("Unimplemented MANYMOUSE_EVENT_ABSMOTION called");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MANYMOUSE_EVENT_BUTTON:
|
case MANYMOUSE_EVENT_BUTTON:
|
||||||
|
@ -4409,6 +4400,10 @@ void startLuaContext(lua_State *L) {
|
||||||
luaPreload(L, "socket.unix", luaopen_socket_unix);
|
luaPreload(L, "socket.unix", luaopen_socket_unix);
|
||||||
luaPreload(L, "socket.serial", luaopen_socket_serial);
|
luaPreload(L, "socket.serial", luaopen_socket_serial);
|
||||||
#endif
|
#endif
|
||||||
|
luaPreload(L, "ssl.core", luaopen_ssl_core);
|
||||||
|
luaPreload(L, "ssl.context", luaopen_ssl_context);
|
||||||
|
luaPreload(L, "ssl.x509", luaopen_ssl_x509);
|
||||||
|
luaPreload(L, "ssl.config", luaopen_ssl_config);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
***TODO*** Load these Lua modules:
|
***TODO*** Load these Lua modules:
|
||||||
|
@ -4425,6 +4420,10 @@ void startLuaContext(lua_State *L) {
|
||||||
tp.lua
|
tp.lua
|
||||||
url.lua
|
url.lua
|
||||||
|
|
||||||
|
luasec:
|
||||||
|
https.lua
|
||||||
|
ssl.lua
|
||||||
|
|
||||||
librs232:
|
librs232:
|
||||||
rs232.lua
|
rs232.lua
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue