Additional state handling cleanup

This commit is contained in:
Björn Ritzl 2020-07-14 14:53:42 +02:00
parent d5cb318c7d
commit 72ecd460d6
3 changed files with 37 additions and 25 deletions

View File

@ -37,9 +37,7 @@
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSCameraUsageDescription</key>
<string>App Needs to use camera to take Profile picture</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>App Needs to store your photos</string>
<string>{{project.title}} needs to use the camera</string>
{{#display.high_dpi}}
<key>NSHighResolutionCapable</key>
<true/>

View File

@ -34,7 +34,6 @@ struct DefoldCamera
DefoldCamera g_DefoldCamera;
void Camera_QueueMessage(CameraStatus status)
{
DM_MUTEX_SCOPED_LOCK(g_DefoldCamera.m_Mutex);
@ -58,6 +57,20 @@ static void Camera_ProcessQueue()
break;
}
CameraStatus status = g_DefoldCamera.m_MessageQueue[i];
if (status == STATUS_STARTED)
{
// Increase ref count
dmScript::LuaHBuffer luabuffer = {g_DefoldCamera.m_VideoBuffer, false};
dmScript::PushBuffer(L, luabuffer);
g_DefoldCamera.m_VideoBufferLuaRef = dmScript::Ref(L, LUA_REGISTRYINDEX);
}
else if (status == STATUS_STOPPED)
{
dmScript::Unref(L, LUA_REGISTRYINDEX, g_DefoldCamera.m_VideoBufferLuaRef); // We want it destroyed by the GC
g_DefoldCamera.m_VideoBufferLuaRef = 0;
}
lua_pushnumber(L, (lua_Number)status);
int ret = lua_pcall(L, 2, 0, 0);
if (ret != 0)
@ -90,11 +103,6 @@ static int StartCapture(lua_State* L)
CameraPlatform_StartCapture(&g_DefoldCamera.m_VideoBuffer, type, quality, g_DefoldCamera.m_Params);
// Increase ref count
dmScript::LuaHBuffer luabuffer = {g_DefoldCamera.m_VideoBuffer, false};
dmScript::PushBuffer(L, luabuffer);
g_DefoldCamera.m_VideoBufferLuaRef = dmScript::Ref(L, LUA_REGISTRYINDEX);
return 1;
}
@ -104,7 +112,6 @@ static int StopCapture(lua_State* L)
CameraPlatform_StopCapture();
dmScript::Unref(L, LUA_REGISTRYINDEX, g_DefoldCamera.m_VideoBufferLuaRef); // We want it destroyed by the GC
return 0;
}
@ -132,7 +139,14 @@ static int GetInfo(lua_State* L)
static int GetFrame(lua_State* L)
{
DM_LUA_STACK_CHECK(L, 1);
if (g_DefoldCamera.m_VideoBufferLuaRef != 0)
{
lua_rawgeti(L, LUA_REGISTRYINDEX, g_DefoldCamera.m_VideoBufferLuaRef);
}
else
{
lua_pushnil(L);
}
return 1;
}

View File

@ -17,11 +17,10 @@ local function start_capture(self)
return
end
local sysinfo = sys.get_sys_info()
local quality = camera.CAPTURE_QUALITY_HIGH
local type = camera.CAMERA_TYPE_FRONT
if sysinfo.system_name == 'iPhone OS' then
if sys.get_sys_info().system_name == 'iPhone OS' then
type = camera.CAMERA_TYPE_BACK
quality = camera.CAPTURE_QUALITY_MEDIUM
end
@ -30,11 +29,13 @@ local function start_capture(self)
if status == camera.STATUS_STARTED then
self.cameraframe = camera.get_frame()
self.camerainfo = camera.get_info()
self.cameratextureheader = {width=self.camerainfo.width,
self.cameratextureheader = {
width=self.camerainfo.width,
height=self.camerainfo.height,
type=resource.TEXTURE_TYPE_2D,
format=resource.TEXTURE_FORMAT_RGB,
num_mip_maps=1 }
num_mip_maps=1
}
label.set_text("logo#status", "Capture Status: ON")
else
label.set_text("logo#status", "Capture Status: ERROR")
@ -53,19 +54,18 @@ function init(self)
go.set("#sprite", "scale", vmath.vector3(scale_width, scale_height, 1) )
start_capture(self)
end
function final(self)
if self.cameraframe ~= nil then
if self.cameraframe then
camera.stop_capture()
end
end
function update(self, dt)
if self.cameraframe ~= nil then
if self.cameraframe then
local pathmodelcamera = go.get("#sprite", "texture0")
resource.set_texture(pathmodelcamera, self.cameratextureheader, self.cameraframe)
end
@ -74,10 +74,10 @@ end
function on_input(self, action_id, action)
if (action_id == hash("space") or action_id == hash("touch")) and action.pressed then
if self.cameraframe == nil then
start_capture(self)
else
if self.cameraframe then
stop_capture(self)
else
start_capture(self)
end
end
end