cleanup
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
#include <psyqo/soft-math.hh>
|
||||
#include <psyqo/trigonometry.hh>
|
||||
#include <psyqo/fixed-point.hh>
|
||||
#include <psyqo/xprintf.h>
|
||||
|
||||
|
||||
namespace psxsplash {
|
||||
|
||||
@@ -241,7 +241,7 @@ void LuaAPI::RegisterAll(psyqo::Lua& L, SceneManager* scene, CutscenePlayer* cut
|
||||
L.push(Math_Max);
|
||||
L.setField(-2, "Max");
|
||||
|
||||
L.setGlobal("Math");
|
||||
L.setGlobal("PSXMath");
|
||||
|
||||
// ========================================================================
|
||||
// SCENE API
|
||||
@@ -615,7 +615,8 @@ int LuaAPI::Entity_ForEach(lua_State* L) {
|
||||
lua.pop(2); // pop non-table + callback copy
|
||||
continue;
|
||||
}
|
||||
if (lua.pcall(1, 0) != LUA_OK) {
|
||||
lua.pushNumber(i); // push index as second argument
|
||||
if (lua.pcall(2, 0) != LUA_OK) {
|
||||
lua.pop(); // pop error message
|
||||
}
|
||||
}
|
||||
@@ -1179,28 +1180,27 @@ int LuaAPI::Camera_LookAt(lua_State* L) {
|
||||
// ============================================================================
|
||||
|
||||
int LuaAPI::Audio_Play(lua_State* L) {
|
||||
printf("[Audio_Play] ENTER top=%d\n", lua_gettop(L));
|
||||
psyqo::Lua lua(L);
|
||||
|
||||
if (!s_sceneManager) {
|
||||
lua.pushNumber(-1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int soundId = -1;
|
||||
|
||||
// Accept number (index) or string (name lookup) like Entity.Find
|
||||
// Check isNumber FIRST — in Lua, numbers pass isString too.
|
||||
// Check isNumber FIRST - in Lua, numbers pass isString too.
|
||||
if (lua.isNumber(1)) {
|
||||
soundId = static_cast<int>(lua.toNumber(1));
|
||||
printf("[Audio_Play] by index: %d\n", soundId);
|
||||
} else if (lua.isString(1)) {
|
||||
const char* name = lua.toString(1);
|
||||
printf("[Audio_Play] by name: '%s'\n", name ? name : "(null)");
|
||||
soundId = s_sceneManager->findAudioClipByName(name);
|
||||
if (soundId < 0) {
|
||||
printf("[Audio_Play] clip not found\n");
|
||||
lua.pushNumber(-1);
|
||||
return 1;
|
||||
}
|
||||
printf("[Audio_Play] found at index %d\n", soundId);
|
||||
} else {
|
||||
printf("[Audio_Play] invalid arg type\n");
|
||||
lua.pushNumber(-1);
|
||||
return 1;
|
||||
}
|
||||
@@ -1208,9 +1208,7 @@ int LuaAPI::Audio_Play(lua_State* L) {
|
||||
int volume = static_cast<int>(lua.optNumber(2, 100));
|
||||
int pan = static_cast<int>(lua.optNumber(3, 64));
|
||||
|
||||
printf("[Audio_Play] play(%d, vol=%d, pan=%d)\n", soundId, volume, pan);
|
||||
int voice = s_sceneManager->getAudio().play(soundId, volume, pan);
|
||||
printf("[Audio_Play] voice=%d OK\n", voice);
|
||||
lua.pushNumber(voice);
|
||||
return 1;
|
||||
}
|
||||
@@ -1236,6 +1234,7 @@ int LuaAPI::Audio_Find(lua_State* L) {
|
||||
|
||||
int LuaAPI::Audio_Stop(lua_State* L) {
|
||||
psyqo::Lua lua(L);
|
||||
if (!s_sceneManager) return 0;
|
||||
int channelId = static_cast<int>(lua.toNumber(1));
|
||||
s_sceneManager->getAudio().stopVoice(channelId);
|
||||
return 0;
|
||||
@@ -1243,6 +1242,7 @@ int LuaAPI::Audio_Stop(lua_State* L) {
|
||||
|
||||
int LuaAPI::Audio_SetVolume(lua_State* L) {
|
||||
psyqo::Lua lua(L);
|
||||
if (!s_sceneManager) return 0;
|
||||
int channelId = static_cast<int>(lua.toNumber(1));
|
||||
int volume = static_cast<int>(lua.toNumber(2));
|
||||
int pan = static_cast<int>(lua.optNumber(3, 64));
|
||||
@@ -1252,6 +1252,7 @@ int LuaAPI::Audio_SetVolume(lua_State* L) {
|
||||
|
||||
int LuaAPI::Audio_StopAll(lua_State* L) {
|
||||
psyqo::Lua lua(L);
|
||||
if (!s_sceneManager) return 0;
|
||||
s_sceneManager->getAudio().stopAll();
|
||||
return 0;
|
||||
}
|
||||
@@ -1263,9 +1264,8 @@ int LuaAPI::Audio_StopAll(lua_State* L) {
|
||||
int LuaAPI::Debug_Log(lua_State* L) {
|
||||
psyqo::Lua lua(L);
|
||||
|
||||
const char* msg = lua.optString(1, "");
|
||||
printf("[Lua] %s\n", msg);
|
||||
|
||||
// Debug.Log is a no-op on PS1 to avoid printf overhead.
|
||||
// Messages are only visible in emulator TTY builds.
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1280,12 +1280,6 @@ int LuaAPI::Debug_DrawLine(lua_State* L) {
|
||||
}
|
||||
|
||||
// TODO: Queue LINE_G2 primitive through Renderer
|
||||
// For now, log to debug console (visible in emulator)
|
||||
#ifdef PSXSPLASH_DEBUG_DRAW
|
||||
printf("[DebugDraw] Line (%d,%d,%d)->(%d,%d,%d)\n",
|
||||
sx.raw() >> 12, sy.raw() >> 12, sz.raw() >> 12,
|
||||
ex.raw() >> 12, ey.raw() >> 12, ez.raw() >> 12);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1300,11 +1294,6 @@ int LuaAPI::Debug_DrawBox(lua_State* L) {
|
||||
}
|
||||
|
||||
// TODO: Queue 12 LINE_G2 primitives (box wireframe) through Renderer
|
||||
#ifdef PSXSPLASH_DEBUG_DRAW
|
||||
printf("[DebugDraw] Box center(%d,%d,%d) size(%d,%d,%d)\n",
|
||||
cx.raw() >> 12, cy.raw() >> 12, cz.raw() >> 12,
|
||||
hx.raw() >> 12, hy.raw() >> 12, hz.raw() >> 12);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user