summaryrefslogtreecommitdiffstats
path: root/matchblox/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'matchblox/main.cpp')
-rw-r--r--matchblox/main.cpp126
1 files changed, 49 insertions, 77 deletions
diff --git a/matchblox/main.cpp b/matchblox/main.cpp
index 466c418..cedaa0c 100644
--- a/matchblox/main.cpp
+++ b/matchblox/main.cpp
@@ -6,15 +6,11 @@
#define TRUE !FALSE
#endif
-
-//#include <wiimote.h>
-#include <wiiuse.h>
#include <GL/glew.h>
#include <GL/glut.h>
#include <iostream>
#include <math.h>
-#include <GL/glut.h>
#include "message_queue.h"
#include "message_input.h"
@@ -23,6 +19,7 @@
#include "textfile.h"
#include "C_MatchBloxEngine.h"
+#include "wiimote_utils.h"
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
@@ -35,61 +32,37 @@ C_MatchBloxEngine *g_pEngine;
bool InitWiiMotes()
{
//connect to the wiimote(s)
- g_GameState.m_ppWiimotes = wiiuse_init(1);
-#ifdef WIN32
- wiiuse_set_bluetooth_stack(g_GameState.m_ppWiimotes, 1, WIIUSE_STACK_MS);
-#endif //WIN32
+ //create an abstract wiimote interface
+#ifdef USE_WIIYOURSELF
+ g_GameState.m_pWiimote[0] = new WiiYourselfWiimote();
+#endif //USE_WIIYOURSELF
- int found = wiiuse_find(g_GameState.m_ppWiimotes, 1, 30);
- int connected = wiiuse_connect(g_GameState.m_ppWiimotes , 1);
- if (connected)
+ printf("connecting:\n");
+ int retries = 10;
+ while(!g_GameState.m_pWiimote[0]->Connect() && retries > 0)
{
- printf("Connected to %i wiimotes (of %i found).\n", connected, found);
-
- wiiuse_set_leds(g_GameState.m_ppWiimotes[0], WIIMOTE_LED_1 | WIIMOTE_LED_2 | WIIMOTE_LED_3 | WIIMOTE_LED_4);
- wiiuse_rumble(g_GameState.m_ppWiimotes[0], 1);
- //wiiuse_motion_sensing(g_GameState.m_ppWiimotes[0], 1);
- wiiuse_set_ir(g_GameState.m_ppWiimotes[0], 1);
- Sleep(200);
- wiiuse_rumble(g_GameState.m_ppWiimotes[0], 0);
- }
- else
- {
- printf("Failed to connect to any wiimote.\n");
- return 0;
+ Sleep(100);
+ printf(".");
+ //retries--;
}
- // g_GameState.m_pTrackingWiimote = new wiimote();
-
- // g_GameState.m_pTrackingWiimote->ChangedCallback = NULL; //no callbacks, we just poll...
- //g_GameState.m_pTrackingWiimote->CallbackTriggerFlags = NO_CHANGE;
-
- // printf("connecting:\n");
- // int retries = 10;
- // while(!g_GameState.m_pTrackingWiimote->Connect(wiimote::FIRST_AVAILABLE) && retries > 10)
- // {
- // Sleep(100);
- // printf(".");
- // retries--;
- // }
- //if (g_GameState.m_pTrackingWiimote->IsConnected())
- //{
- // printf("connected\n");
-
- // g_GameState.m_pTrackingWiimote->SetLEDs(0x0f);
- //
- // g_GameState.m_pTrackingWiimote->SetReportType(wiimote::IN_BUTTONS_ACCEL_IR, true); // IR dots
- // g_GameState.m_pTrackingWiimote->SetRumble(true);
- // Sleep(500);
- // g_GameState.m_pTrackingWiimote->SetRumble(false);
-
- // return true;
- //}
- //else
- //{
- // return false;
- //}
+ if (g_GameState.m_pWiimote[0]->IsConnected())
+ {
+ printf("connected\n");
+
+ g_GameState.m_pWiimote[0]->SetLeds(0x0f);
+
+ g_GameState.m_pWiimote[0]->StartRumble();
+ Sleep(500);
+ g_GameState.m_pWiimote[0]->StopRumble();
+
+ return true;
+ }
+ else
+ {
+ return false;
+ }
}
bool LoadGreyScaleShader()
@@ -168,32 +141,21 @@ void init_gl(void)
void idle_func(void)
{
- //g_GameState.m_pTrackingWiimote->RefreshState();
+ struct input_payload_wiimote wiimote_payload;
- if (wiiuse_poll(g_GameState.m_ppWiimotes, 1))
- {
-
- ////put wiimote data in message queue
- input_payload_wiimote payload;
- payload.btns = g_GameState.m_ppWiimotes[0]->btns;
- payload.ir = g_GameState.m_ppWiimotes[0]->ir;
- ////copy buttons bitmask
- //payload.Button.Bits = g_GameState.m_pTrackingWiimote->Button.Bits;
- ////copy the 4 ir dots
- //memcpy((void*)payload.Dot, g_GameState.m_pTrackingWiimote->IR.Dot, 4*sizeof(wiimote::ir::dot));
-
- struct messageq_s message;
- message.recipient = MESSAGE_MENU | MESSAGE_RENDERER;
- message.sender = MESSAGE_INPUT_WIIMOTE;
- message.payload = &payload;
- message.payload_size = sizeof(input_payload_wiimote);
- messageq_send(&message);
- }
+ g_GameState.m_pWiimote[0]->FillWiimoteMsgPayload(wiimote_payload, 205.0); // << should be a sensor bar led distance
+
+ struct messageq_s message;
+ message.recipient = MESSAGE_MENU | MESSAGE_RENDERER;
+ message.sender = MESSAGE_INPUT_WIIMOTE;
+ message.payload = &wiimote_payload;
+ message.payload_size = sizeof(input_payload_wiimote);
+ messageq_send(&message);
g_pEngine->ProcessMsgs();
//call engine idle func
- //MenuRun();
+ MenuRun();
glutPostRedisplay();
}
@@ -205,7 +167,9 @@ void render_scene(void)
g_pEngine->Render(glutGet(GLUT_ELAPSED_TIME));
glDisable(GL_LIGHTING);
+ glPushMatrix();
MenuRender();
+ glPopMatrix();
glEnable(GL_LIGHTING);
glutSwapBuffers();
@@ -239,8 +203,14 @@ void process_normal_keys(unsigned char key, int x, int y)
break;
case 'n':
g_pEngine->Abort();
- g_pEngine->NewGame(0, 0, BS_LARGE);
+ g_pEngine->NewGame(0, 0, BS_SMALL);
break;
+ case 'p':
+ if (!g_pEngine->Pause())
+ {
+ g_pEngine->Resume();
+ }
+ break;
}
payload.specialkey = FALSE;
@@ -307,9 +277,11 @@ int main(int argc, char **argv)
MenuInit(SCREEN_WIDTH, SCREEN_HEIGHT);
InitWiiMotes();
- GameSettings l_set = {10, 2, 2};
+ GameSettings l_set = {10, 1.1, 2};
g_pEngine = new C_MatchBloxEngine("models", "", l_set);
+ //glutFullScreen();
+
glutMainLoop();
return 0;