headset: forward declarations;

This commit is contained in:
bjorn 2019-04-05 05:08:03 -07:00
parent ee27af1a85
commit 941fc1717f
9 changed files with 33 additions and 28 deletions

View File

@ -1,4 +1,5 @@
#include "luax.h"
#include "util.h"
// Module loaders
LOVR_EXPORT int luaopen_lovr(lua_State* L);

View File

@ -426,7 +426,8 @@ static int l_lovrGraphicsGetBackgroundColor(lua_State* L) {
}
static int l_lovrGraphicsSetBackgroundColor(lua_State* L) {
Color color = luax_checkcolor(L, 1);
Color color;
luax_readcolor(L, 1, &color);
lovrGraphicsSetBackgroundColor(color);
return 0;
}
@ -469,7 +470,8 @@ static int l_lovrGraphicsGetColor(lua_State* L) {
}
static int l_lovrGraphicsSetColor(lua_State* L) {
Color color = luax_checkcolor(L, 1);
Color color;
luax_readcolor(L, 1, &color);
lovrGraphicsSetColor(color);
return 0;
}
@ -1116,7 +1118,8 @@ static int l_lovrGraphicsNewMaterial(lua_State* L) {
}
if (lua_isnumber(L, index)) {
Color color = luax_checkcolor(L, index);
Color color;
luax_readcolor(L, index, &color);
lovrMaterialSetColor(material, COLOR_DIFFUSE, color);
}

View File

@ -1,6 +1,7 @@
#include "api.h"
#include "data/audioStream.h"
#include "data/soundData.h"
#include <string.h>
static int l_lovrAudioStreamDecode(lua_State* L) {
AudioStream* stream = luax_checktype(L, 1, AudioStream);

View File

@ -21,7 +21,8 @@ static int l_lovrMaterialSetColor(lua_State* L) {
colorType = luaL_checkoption(L, index, NULL, MaterialColors);
index++;
}
Color color = luax_checkcolor(L, index);
Color color;
luax_readcolor(L, index, &color);
lovrMaterialSetColor(material, colorType, color);
return 0;
}

View File

@ -1,5 +1,5 @@
#include "headset/headset.h"
#include "event/event.h"
#include "util.h"
HeadsetInterface* lovrHeadsetDriver = NULL;
static bool initialized = false;

View File

@ -1,11 +1,13 @@
#include "data/modelData.h"
#include "lib/vec/vec.h"
#include "util.h"
#include "types.h"
#include <stdbool.h>
#include "graphics/texture.h"
#include <stdint.h>
#pragma once
struct ModelData;
struct Texture;
typedef enum {
EYE_BOTH = -1,
EYE_LEFT,
@ -67,8 +69,6 @@ typedef struct Controller {
typedef vec_t(Controller*) vec_controller_t;
struct Texture;
typedef struct {
HeadsetDriver driverType;
bool (*init)(float offset, int msaa);
@ -94,9 +94,9 @@ typedef struct {
bool (*controllerIsDown)(Controller* controller, ControllerButton button);
bool (*controllerIsTouched)(Controller* controller, ControllerButton button);
void (*controllerVibrate)(Controller* controller, float duration, float power);
ModelData* (*controllerNewModelData)(Controller* controller);
struct ModelData* (*controllerNewModelData)(Controller* controller);
void (*renderTo)(void (*callback)(void*), void* userdata);
Texture* (*getMirrorTexture)(void);
struct Texture* (*getMirrorTexture)(void);
void (*update)(float dt);
} HeadsetInterface;

View File

@ -258,26 +258,24 @@ int luax_setconf(lua_State* L) {
return 0;
}
Color luax_checkcolor(lua_State* L, int index) {
Color color = { 1., 1., 1., 1. };
void luax_readcolor(lua_State* L, int index, Color* color) {
color->r = color->g = color->b = color->a = 1.f;
if (lua_istable(L, 1)) {
for (int i = 1; i <= 4; i++) {
lua_rawgeti(L, 1, i);
}
color.r = luax_checkfloat(L, -4);
color.g = luax_checkfloat(L, -3);
color.b = luax_checkfloat(L, -2);
color.a = luax_optfloat(L, -1, 1.);
color->r = luax_checkfloat(L, -4);
color->g = luax_checkfloat(L, -3);
color->b = luax_checkfloat(L, -2);
color->a = luax_optfloat(L, -1, 1.);
lua_pop(L, 4);
} else if (lua_gettop(L) >= index + 2) {
color.r = luax_checkfloat(L, index);
color.g = luax_checkfloat(L, index + 1);
color.b = luax_checkfloat(L, index + 2);
color.a = luax_optfloat(L, index + 3, 1.);
color->r = luax_checkfloat(L, index);
color->g = luax_checkfloat(L, index + 1);
color->b = luax_checkfloat(L, index + 2);
color->a = luax_optfloat(L, index + 3, 1.);
} else {
luaL_error(L, "Invalid color, expected 3 numbers, 4 numbers, or a table");
}
return color;
}

View File

@ -1,11 +1,12 @@
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#include "lib/map/map.h"
#include "util.h"
#include "types.h"
#pragma once
struct Color;
#ifndef LUA_RIDX_MAINTHERAD
#define LUA_RIDX_MAINTHREAD 1
#endif
@ -37,4 +38,4 @@ int luax_getstack(lua_State* L);
int luax_getstack_panic(lua_State *L);
void luax_pushconf(lua_State* L);
int luax_setconf(lua_State* L);
Color luax_checkcolor(lua_State* L, int index);
void luax_readcolor(lua_State* L, int index, struct Color* color);

View File

@ -37,7 +37,7 @@
#define M_PI 3.14159265358979323846264f
#endif
typedef struct { float r, g, b, a; } Color;
typedef struct Color { float r, g, b, a; } Color;
typedef void (*lovrErrorHandler)(void* userdata, const char* format, va_list args);
extern _Thread_local lovrErrorHandler lovrErrorCallback;