commit 068d19326d2098b413e30d4500439af80ec2c325
Author: Jon Bell <jondbell@protonmail.com>
AuthorDate: Sat Apr 25 15:06:22 2020 -0600
Commit: Jon Bell <jondbell@protonmail.com>
CommitDate: Sat Apr 25 15:06:22 2020 -0600
add time() and stubb music, sfx, and fillp
---
source/console.cpp | 15 ++++++++++++++-
source/console.h | 4 +++-
source/picoluaapi.cpp | 28 +++++++++++++++++++++++++++-
source/picoluaapi.h | 30 +++++++++++++++++-------------
4 files changed, 61 insertions(+), 16 deletions(-)
diff --git a/source/console.cpp b/source/console.cpp
index eb30251..63d4e2a 100644
--- a/source/console.cpp
+++ b/source/console.cpp
@@ -29,7 +29,7 @@ Console::Console(){
//this can probably go away when I'm loading actual carts and just have to expose api to lua
Logger::Write("Initializing global api\n");
- initPicoApi(_graphics, _input);
+ initPicoApi(_graphics, _input, this);
//initGlobalApi(_graphics);
_targetFps = 30;
@@ -89,10 +89,20 @@ void Console::LoadCart(std::string filename){
lua_register(_luaState, "mset", mset);
lua_register(_luaState, "map", map);
+ //stubbed in graphics:
+ lua_register(_luaState, "fillp", fillp);
+
//input
lua_register(_luaState, "btn", btn);
lua_register(_luaState, "btnp", btnp);
+ lua_register(_luaState, "time", time);
+ lua_register(_luaState, "t", time);
+
+ //stubbed in audio:
+ lua_register(_luaState, "music", music);
+ lua_register(_luaState, "sfx", sfx);
+
luaL_dostring(_luaState, _loadedCart->LuaString.c_str());
@@ -186,3 +196,6 @@ uint8_t Console::GetTargetFps() {
return _targetFps;
}
+int Console::GetFrameCount() {
+ return _picoFrameCount;
+}
diff --git a/source/console.h b/source/console.h
index 40fab7e..3994c78 100644
--- a/source/console.h
+++ b/source/console.h
@@ -18,7 +18,7 @@ class Console {
uint8_t _targetFps;
- uint16_t _picoFrameCount;
+ int _picoFrameCount;
bool _hasUpdate;
bool _hasDraw;
@@ -39,5 +39,7 @@ class Console {
void TurnOff();
uint8_t GetTargetFps();
+
+ int GetFrameCount();
};
diff --git a/source/picoluaapi.cpp b/source/picoluaapi.cpp
index baa80fa..20cdfa3 100644
--- a/source/picoluaapi.cpp
+++ b/source/picoluaapi.cpp
@@ -4,6 +4,7 @@
#include "picoluaapi.h"
#include "graphics.h"
#include "Input.h"
+#include "console.h"
extern "C" {
#include <lua.h>
@@ -13,10 +14,12 @@ extern "C" {
Graphics* _graphicsForLuaApi;
Input* _inputForLuaApi;
+Console* _consoleForLuaApi;
-void initPicoApi(Graphics* graphics, Input* input){
+void initPicoApi(Graphics* graphics, Input* input, Console* console){
_graphicsForLuaApi = graphics;
_inputForLuaApi = input;
+ _consoleForLuaApi = console;
}
int noop(const char * name) {
@@ -518,3 +521,26 @@ int btnp(lua_State *L){
return 1;
}
+
+
+//Audio
+
+int music(lua_State *L) {
+ return noop("music");
+}
+
+int sfx(lua_State *L) {
+ return noop("sfx");
+}
+
+//Time
+int time(lua_State *L) {
+ int frameCount = _consoleForLuaApi->GetFrameCount();
+ int targetFps = _consoleForLuaApi->GetTargetFps();
+
+ double seconds = (double)frameCount / (double)targetFps;
+
+ lua_pushnumber(L, seconds);
+
+ return 1;
+}
diff --git a/source/picoluaapi.h b/source/picoluaapi.h
index 0212427..94e2c89 100644
--- a/source/picoluaapi.h
+++ b/source/picoluaapi.h
@@ -10,9 +10,10 @@ extern "C" {
#include "graphics.h"
#include "Input.h"
+#include "console.h"
//this can probably go away when I'm loading actual carts and just have to expose api to lua
-void initPicoApi(Graphics* graphics, Input* input);
+void initPicoApi(Graphics* graphics, Input* input, Console* console);
//graphics api
int cls(lua_State *L);
@@ -43,23 +44,26 @@ int cursor(lua_State *L);
int fillp(lua_State *L);
//end todo
+//tables functions, maybe implemented in lua?
+//list from: https://pico-8.fandom.com/wiki/APIReference
+/*
+ add(t, v)
+ all(t)
+ del(t, v)
+ foreach(t, f)
+ pairs(t)
+*/
+
//input api
int btn(lua_State *L);
int btnp(lua_State *L);
+//audio api
+int music(lua_State *L);
+int sfx(lua_State *L);
-//TODO:
-//graphics
-//api.fillp(p)
-
-//map
-//api.map(cel_x, cel_y, sx, sy, cel_w, cel_h, bitmask)
-
-//api.mget(x, y)
-
-//api.mset(x, y, v)
-
-
+//time
+int time(lua_State *L);
//system functions
//api.time() and api.t()