JD2022-TU1/main/extern/Camcam/LIBS/Mixer/SCENE_Wiimote.cpp

237 lines
6.8 KiB
C++

#include "SCENE.h"
#ifdef WIIMOTE_SUPPORT
void on_state_change (wiimote &remote, state_change_flags changed)
{
{
u32 Type = (((u32)remote.Nunchuk.Raw6[0])>>6)&0x3;
remote.GunFiled[Type].FrameNum = (((u32)remote.Nunchuk.Raw6[0])>>3)&0x7;
remote.GunFiled[Type].FrameFinish = (((u32)remote.Nunchuk.Raw6[0]))&0x7;
remote.GunFiled[Type].DATA[0] = (u32)remote.Nunchuk.Raw6[1];
remote.GunFiled[Type].DATA[1] = (u32)remote.Nunchuk.Raw6[2];
remote.GunFiled[Type].DATA[2] = (u32)remote.Nunchuk.Raw6[3];
remote.GunFiled[Type].DATA[3] = (u32)remote.Nunchuk.Raw6[4];
}
// extension was just connected:
if(changed & EXTENSION_CONNECTED)
{
#ifdef USE_BEEPS_AND_DELAYS
Beep(1000, 200);
#endif
// switch to a report mode that includes the extension data (we will
// loose the IR dot sizes)
remote.SetReportType(wiimote::IN_BUTTONS_ACCEL_IR_EXT);
}
// extension was just disconnected:
else if(changed & EXTENSION_DISCONNECTED)
{
#ifdef USE_BEEPS_AND_DELAYS
Beep(200, 300);
#endif
// use a non-extension report mode (this gives us back the IR dot sizes)
remote.SetReportType(wiimote::IN_BUTTONS_ACCEL_IR);
}
}
void SetStrFieldFloat(lua_State *L, const char *index, float value) ;
void SetStrFieldString(lua_State *L, const char *index, char * value) ;
void SetStrFieldFunction(lua_State *L, const char *index, lua_CFunction function) ;
void SetStrFieldBoolean(lua_State *L, const char *index, bool function) ;
void SetStrFieldInteger(lua_State *L, const char *index, int value);
void lua_pushinteger (lua_State *L, lua_Integer n) ;
int PushWiiMote(u32 WiimoteIndex,lua_State *L, WORLD *pScene)
{
wiimote *premote;
premote = &pScene->remote[WiimoteIndex & 3];
if (premote && premote->IsConnected())
{
s8* ButtonNameFromBit [16] =
{ "Left" , "Right", "Down", "Up",
"Plus" , "?1" , "?2" , "?3" ,
"Two" , "One" , "B" , "A" ,
"Minus", "?4" , "?5" , "Home" };
lua_newtable(L);
for(unsigned bit=0; bit<16; bit++)
{
WORD mask = (WORD)(1 << bit);
bool pressed = ((premote->Button.Bits & mask) != 0);
SetStrFieldBoolean(L, ButtonNameFromBit[bit] , pressed);
}
SetStrFieldInteger(L, "Battery", premote->BatteryPercent);
lua_pushstring(L,"Acc");
lua_createtable(L,0,3);
SetStrFieldFloat(L, "x", premote->Acceleration.X);
SetStrFieldFloat(L, "y", premote->Acceleration.Y);
SetStrFieldFloat(L, "z", premote->Acceleration.Z);
lua_settable(L,-3);
lua_pushstring(L,"Pointer");
lua_createtable(L,0,4);
for (int YU = 0 ; YU < 4 ; YU ++)
{
lua_pushinteger(L, YU);
lua_createtable(L,0,7);
SetStrFieldBoolean(L, "bVisible", premote->IR.Dot[YU].bVisible?true:false);
SetStrFieldInteger(L, "bVisible2", premote->IR.Dot[YU].bVisible);
SetStrFieldInteger(L, "RawX", premote->IR.Dot[YU].RawX);
SetStrFieldInteger(L, "RawY", premote->IR.Dot[YU].RawY);
SetStrFieldFloat(L, "x", premote->IR.Dot[YU].X);
SetStrFieldFloat(L, "y", premote->IR.Dot[YU].Y);
SetStrFieldFloat(L, "Depth", premote->IR.Dot[YU].Size);
lua_settable(L,-3);
}
lua_settable(L,-3);
if (premote->ExtensionType == wiimote_state::NUNCHUK)
{
lua_pushstring(L,"NUNCHUK");
lua_createtable(L,0,6);
SetStrFieldBoolean(L, "BnC", premote->Nunchuk.C?true:false);
SetStrFieldBoolean(L, "BnZ", premote->Nunchuk.Z?true:false);
lua_pushstring(L,"Acc");
lua_createtable(L,0,3);
SetStrFieldFloat(L, "x", premote->Nunchuk.Acceleration.X);
SetStrFieldFloat(L, "y", premote->Nunchuk.Acceleration.Y);
SetStrFieldFloat(L, "z", premote->Nunchuk.Acceleration.Z);
lua_settable(L,-3);
lua_pushstring(L,"Joystick");
lua_createtable(L,0,2);
SetStrFieldFloat(L, "x", premote->Nunchuk.Joystick.X);
SetStrFieldFloat(L, "y", premote->Nunchuk.Joystick.Y);
lua_settable(L,-3);
lua_pushstring(L,"Raw6");
lua_createtable(L,0,6);
u32 K = 6;
while (K--)
{
lua_pushinteger(L, 5-K);
lua_pushinteger(L, premote->Nunchuk.Raw6[5-K]);
lua_rawset(L, -3);
}
lua_settable(L,-3);
lua_pushstring(L,"GUN");
lua_createtable(L,0,4);
u32 Type = 0;
lua_pushstring(L,"Last_Gun_RFU_00");
lua_createtable(L,0,6);
SetStrFieldFloat(L, "NbFrame", premote->GunFiled[Type].FrameNum);
SetStrFieldFloat(L, "#Frame", premote->GunFiled[Type].FrameFinish);
SetStrFieldFloat(L, "DATA0", premote->GunFiled[Type].DATA[0]);
SetStrFieldFloat(L, "DATA1", premote->GunFiled[Type].DATA[1]);
SetStrFieldFloat(L, "DATA2", premote->GunFiled[Type].DATA[2]);
SetStrFieldFloat(L, "DATA3", premote->GunFiled[Type].DATA[3]);
lua_settable(L,-3);
Type = 1;
lua_pushstring(L,"Last_Gun_Infrarouge");
lua_createtable(L,0,6);
SetStrFieldFloat(L, "NbFrame", premote->GunFiled[Type].FrameNum);
SetStrFieldFloat(L, "#Frame", premote->GunFiled[Type].FrameFinish);
SetStrFieldFloat(L, "TYPE0", (premote->GunFiled[Type].DATA[1]>>4)&0xf);
SetStrFieldFloat(L, "ID0", (premote->GunFiled[Type].DATA[1])&0xf);
SetStrFieldFloat(L, "TTL0", (premote->GunFiled[Type].DATA[2])&0xf);
SetStrFieldFloat(L, "SIDE0", (premote->GunFiled[Type].DATA[2]>>4)&0xf);
lua_settable(L,-3);
Type = 2;
lua_pushstring(L,"Last_Gun_TAG");
lua_createtable(L,0,6);
SetStrFieldFloat(L, "NbFrame", premote->GunFiled[Type].FrameNum);
SetStrFieldFloat(L, "#Frame", premote->GunFiled[Type].FrameFinish);
SetStrFieldFloat(L, "DATA0", premote->GunFiled[Type].DATA[0]);
SetStrFieldFloat(L, "DATA1", premote->GunFiled[Type].DATA[1]);
SetStrFieldFloat(L, "DATA2", premote->GunFiled[Type].DATA[2]);
SetStrFieldFloat(L, "DATA3", premote->GunFiled[Type].DATA[3]);
lua_settable(L,-3);
Type = 3;
lua_pushstring(L,"Last_Gun_RFU_11");
lua_createtable(L,0,6);
SetStrFieldFloat(L, "NbFrame", premote->GunFiled[Type].FrameNum);
SetStrFieldFloat(L, "#Frame", premote->GunFiled[Type].FrameFinish);
SetStrFieldFloat(L, "DATA0", premote->GunFiled[Type].DATA[0]);
SetStrFieldFloat(L, "DATA1", premote->GunFiled[Type].DATA[1]);
SetStrFieldFloat(L, "DATA2", premote->GunFiled[Type].DATA[2]);
SetStrFieldFloat(L, "DATA3", premote->GunFiled[Type].DATA[3]);
lua_settable(L,-3);
lua_settable(L,-3);
lua_settable(L,-3);
}
return 1;
}
return 0;
}
//#pragma optimize("",off)
wiimote_sample Wavs_sample[256];
u32 wiimoteBigCreateIndex = 0;
int WIIMOTE_LoadSound(char *pSoundName,lua_State *L, WORLD *pScene)
{
u32 LMastI = wiimoteBigCreateIndex;
if(!wiimote::Load16bitMonoSampleWAV(pSoundName, Wavs_sample[wiimoteBigCreateIndex]))
{
return -1;
}
wiimoteBigCreateIndex ++;
wiimoteBigCreateIndex &= 255;
return LMastI;
}
int WIIMOTE_PlaySound(int WiimoteIndex,int SoundIndex,lua_State *L, WORLD *pScene)
{
wiimote *premote;
premote = &pScene->remote[WiimoteIndex & 3];
premote->PlaySample (Wavs_sample[SoundIndex]);
//premote->PlaySquareWave(FREQ_3920HZ/* FREQ_2940HZ/*FREQ_4200HZ*/,10);
return 0;
}
#endif