What's new? | Help | Directory | Sign in
Google
                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
//////////////////////////////////////////////////////////////////////////////////////////
// Project description
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
// Name: nJoy
// Description: A Dolphin Compatible Input Plugin
//
// Author: Falcon4ever (nJoy@falcon4ever.com)
// Site: www.multigesture.net
// Copyright (C) 2003-2008 Dolphin Project.
//
//////////////////////////////////////////////////////////////////////////////////////////
//
// Licensetype: GNU General Public License (GPL)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
//
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
//
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
//
//////////////////////////////////////////////////////////////////////////////////////////



////////////////////////////////////////////////////////////////////////////////////////
// Issues
/* ¯¯¯¯¯¯¯¯¯

The StrangeHack in ConfigAdvanced.cpp doesn't work in Linux, it still wont resize the
window correctly. So currently in Linux you have to have advanced controls enabled when
you open the window to see them.

////////////////////////*/



////////////////////////////////////////////////////////////////////////////////////////
// Variables guide
/* ¯¯¯¯¯¯¯¯¯

The arrays joysticks[] and joystate[] are numbered 0 to 3 for the four different virtual
controllers. Joysticks[].ID will have the number of the inputs device mapped to that controller,
this value can be between 0 and the total number of connected physical devices. The mapping
is initially done by PAD_Initialize(), but for the configuration we can remap them, like in
ConfigBox::ChangeJoystick().

The joyinfo[] array is for a certain physical device. It's therefore used as
joyinfo[joysticks[controller].ID].

////////////////////////*/



//////////////////////////////////////////////////////////////////////////////////////////
// Include
// ¯¯¯¯¯¯¯¯¯
#include "nJoy.h"

// Declare config window so that we can write debugging info to it from functions in this file
#if defined(HAVE_WX) && HAVE_WX
ConfigBox* m_frame;
#endif
/////////////////////////


//////////////////////////////////////////////////////////////////////////////////////////
// Variables
// ¯¯¯¯¯¯¯¯¯

// Rumble in windows
#define _CONTROLLER_STATE_H // Avoid certain declarations in nJoy.h
FILE *pFile;
HINSTANCE nJoy_hInst = NULL;
CONTROLLER_INFO *joyinfo = 0;
CONTROLLER_STATE joystate[4];
CONTROLLER_MAPPING joysticks[4];
bool emulator_running = FALSE;
HWND m_hWnd; // Handle to window

// TODO: fix this dirty hack to stop missing symbols
void __Log(int log, const char *format, ...) {}
void __Logv(int log, int v, const char *format, ...) {}

// Rumble
#ifdef _WIN32

#elif defined(__linux__)
extern int fd;
#endif


//////////////////////////////////////////////////////////////////////////////////////////
// wxWidgets
// ¯¯¯¯¯¯¯¯¯
#if defined(HAVE_WX) && HAVE_WX
class wxDLLApp : public wxApp
{
bool OnInit()
{
return true;
}
};

IMPLEMENT_APP_NO_MAIN(wxDLLApp)
WXDLLIMPEXP_BASE void wxSetInstance(HINSTANCE hInst);
#endif


//////////////////////////////////////////////////////////////////////////////////////////
// DllMain
// ¯¯¯¯¯¯¯
#ifdef _WIN32
BOOL APIENTRY DllMain( HINSTANCE hinstDLL, // DLL module handle
DWORD dwReason, // reason called
LPVOID lpvReserved) // reserved
{
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
{
//use wxInitialize() if you don't want GUI instead of the following 12 lines
wxSetInstance((HINSTANCE)hinstDLL);
int argc = 0;
char **argv = NULL;
wxEntryStart(argc, argv);

if (!wxTheApp || !wxTheApp->CallOnInit() )
return FALSE;
}
break;

case DLL_PROCESS_DETACH:
wxEntryCleanup(); //use wxUninitialize() if you don't want GUI
break;

default:
break;
}

nJoy_hInst = hinstDLL;
return TRUE;
}
#endif

//////////////////////////////////////////////////////////////////////////////////////////
// Input Plugin Functions (from spec's)
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

// Get properties of plugin
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void GetDllInfo(PLUGIN_INFO* _PluginInfo)
{
_PluginInfo->Version = 0x0100;
_PluginInfo->Type = PLUGIN_TYPE_PAD;

#ifdef DEBUGFAST
sprintf(_PluginInfo->Name, "nJoy v"INPUT_VERSION" (DebugFast) by Falcon4ever");
#else
#ifndef _DEBUG
sprintf(_PluginInfo->Name, "nJoy v"INPUT_VERSION " by Falcon4ever");
#else
sprintf(_PluginInfo->Name, "nJoy v"INPUT_VERSION" (Debug) by Falcon4ever");
#endif
#endif
}

void SetDllGlobals(PLUGIN_GLOBALS* _pPluginGlobals) {
}

// Call config dialog
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void DllConfig(HWND _hParent)
{
#ifdef _WIN32
if (SDL_Init(SDL_INIT_JOYSTICK ) < 0)
{
MessageBox(NULL, SDL_GetError(), "Could not initialize SDL!", MB_ICONERROR);
return;
}

// Start the pads so we can use them in the configuration and advanced controls
if(!emulator_running)
{
SPADInitialize _PADInitialize;
_PADInitialize.hWnd = NULL;
_PADInitialize.pLog = NULL;
PAD_Initialize(_PADInitialize);
emulator_running = FALSE; // Set it back to false
}

g_Config.Load(); // Load settings

// We don't need a parent for this wxDialog
//wxWindow win;
//win.SetHWND(_hParent);
//ConfigBox frame(&win);
//win.SetHWND(0);

m_frame = new ConfigBox(NULL);
m_frame->ShowModal();

#else
if (SDL_Init(SDL_INIT_JOYSTICK ) < 0)
{
printf("Could not initialize SDL! (%s)\n", SDL_GetError());
return;
}

g_Config.Load(); // load settings

#if defined(HAVE_WX) && HAVE_WX
ConfigBox frame(NULL);
frame.ShowModal();
#endif

#endif
}

void DllDebugger(HWND _hParent, bool Show) {
}


// Init PAD (start emulation)
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void PAD_Initialize(SPADInitialize _PADInitialize)
{
emulator_running = TRUE;
#ifdef _DEBUG
DEBUG_INIT();
#endif

if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
{
#ifdef _WIN32
MessageBox(NULL, SDL_GetError(), "Could not initialize SDL!", MB_ICONERROR);
#else
printf("Could not initialize SDL! (%s)\n", SDL_GetError());
#endif
return;
}

#ifdef _WIN32
m_hWnd = (HWND)_PADInitialize.hWnd;
#endif

Search_Devices(); // Populate joyinfo for all attached devices
g_Config.Load(); // Load joystick mapping, joysticks[].ID etc
if (joysticks[0].enabled)
joystate[0].joy = SDL_JoystickOpen(joysticks[0].ID);
if (joysticks[1].enabled)
joystate[1].joy = SDL_JoystickOpen(joysticks[1].ID);
if (joysticks[2].enabled)
joystate[2].joy = SDL_JoystickOpen(joysticks[2].ID);
if (joysticks[3].enabled)
joystate[3].joy = SDL_JoystickOpen(joysticks[3].ID);
}


// Search attached devices. Populate joyinfo for all attached physical devices.
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
int Search_Devices()
{
// load config
#ifdef _DEBUG
DEBUG_INIT();
#endif

int numjoy = SDL_NumJoysticks();

if (joyinfo)
{
delete [] joyinfo;
joyinfo = new CONTROLLER_INFO [numjoy];
}
else
{
joyinfo = new CONTROLLER_INFO [numjoy];
}

// Warn the user if no joysticks are detected
if (numjoy == 0)
{
#ifdef _WIN32
//MessageBox(NULL, "No Joystick detected!", NULL, MB_ICONWARNING);
#else
printf("No Joystick detected!\n");
#endif
return 0;
}

#ifdef _DEBUG
fprintf(pFile, "Scanning for devices\n");
fprintf(pFile, "¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯\n");
#endif

for(int i = 0; i < numjoy; i++ )
{
// Open the device to be able to read the values
joyinfo[i].joy = SDL_JoystickOpen(i);
joyinfo[i].ID = i;
joyinfo[i].NumAxes = SDL_JoystickNumAxes(joyinfo[i].joy);
joyinfo[i].NumButtons = SDL_JoystickNumButtons(joyinfo[i].joy);
joyinfo[i].NumBalls = SDL_JoystickNumBalls(joyinfo[i].joy);
joyinfo[i].NumHats = SDL_JoystickNumHats(joyinfo[i].joy);
joyinfo[i].Name = SDL_JoystickName(i);

#ifdef _DEBUG
fprintf(pFile, "ID: %d\n", i);
fprintf(pFile, "Name: %s\n", joyinfo[i].Name);
fprintf(pFile, "Buttons: %d\n", joyinfo[i].NumButtons);
fprintf(pFile, "Axes: %d\n", joyinfo[i].NumAxes);
fprintf(pFile, "Hats: %d\n", joyinfo[i].NumHats);
fprintf(pFile, "Balls: %d\n\n", joyinfo[i].NumBalls);
#endif

// We have now read the values we need so we close the device
if (SDL_JoystickOpened(i)) SDL_JoystickClose(joyinfo[i].joy);
}

return numjoy;
}


// Shutdown PAD (stop emulation)
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void PAD_Shutdown()
{
if (joysticks[0].enabled)
SDL_JoystickClose(joystate[0].joy);
if (joysticks[1].enabled)
SDL_JoystickClose(joystate[1].joy);
if (joysticks[2].enabled)
SDL_JoystickClose(joystate[2].joy);
if (joysticks[3].enabled)
SDL_JoystickClose(joystate[3].joy);

SDL_Quit();

#ifdef _DEBUG
DEBUG_QUIT();
#endif

delete [] joyinfo;

emulator_running = FALSE;

#ifdef _WIN32
#ifdef USE_RUMBLE_DINPUT_HACK
FreeDirectInput();
#endif
#elif defined(__linux__)
close(fd);
#endif
}


// Set buttons status from wxWidgets in the main application
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void PAD_Input(u8 _Key, u8 _UpDown)
{
// Check if the keys are interesting, and then update it
for(int i = 0; i < 4; i++)
{
for(int j = CTL_L_SHOULDER; j <= CTL_START; j++)
{
if (joysticks[i].buttons[j] == _Key)
{ joystate[i].buttons[j] = _UpDown; break; }
}
}
}


// Set PAD status. This is called from SerialInterface_Devices.cpp
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
{
if (!joysticks[_numPAD].enabled)
return;

// Clear pad status
memset(_pPADStatus, 0, sizeof(SPADStatus));

// Get pad status
GetJoyState(_numPAD);


///////////////////////////////////////////////////
// Set analog controllers
// -----------

// Read values
int i_main_stick_x = joystate[_numPAD].axis[CTL_MAIN_X];
int i_main_stick_y = -joystate[_numPAD].axis[CTL_MAIN_Y];
int i_sub_stick_x = joystate[_numPAD].axis[CTL_SUB_X];
int i_sub_stick_y = -joystate[_numPAD].axis[CTL_SUB_Y];

// Check if we should make adjustments
if(g_Config.bSquareToCircle.at(_numPAD))
{
std::vector<int> main_xy = Pad_Square_to_Circle(i_main_stick_x, i_main_stick_y);
i_main_stick_x = main_xy.at(0);
i_main_stick_y = main_xy.at(1);
}

// Convert button values from 0xffff to 0xff
u8 main_stick_x = Pad_Convert(i_main_stick_x);
u8 main_stick_y = Pad_Convert(i_main_stick_y);
u8 sub_stick_x = Pad_Convert(i_sub_stick_x);
u8 sub_stick_y = Pad_Convert(i_sub_stick_y);

// Set Deadzones perhaps out of function
int deadzone = (int)(((float)(128.00/100.00)) * (float)(joysticks[_numPAD].deadzone + 1));
int deadzone2 = (int)(((float)(-128.00/100.00)) * (float)(joysticks[_numPAD].deadzone + 1));

// Send values to Dolpin if they are outside the deadzone
if ((main_stick_x < deadzone2) || (main_stick_x > deadzone)) _pPADStatus->stickX = main_stick_x;
if ((main_stick_y < deadzone2) || (main_stick_y > deadzone)) _pPADStatus->stickY = main_stick_y;
if ((sub_stick_x < deadzone2) || (sub_stick_x > deadzone)) _pPADStatus->substickX = sub_stick_x;
if ((sub_stick_y < deadzone2) || (sub_stick_y > deadzone)) _pPADStatus->substickY = sub_stick_y;


///////////////////////////////////////////////////
// Set buttons
// -----------

// The L and R trigger values
int triggervalue = 255;
if (joystate[_numPAD].halfpress) triggervalue = 100;

// Neutral button value, no button pressed
_pPADStatus->button |= PAD_USE_ORIGIN;

if (joystate[_numPAD].buttons[CTL_L_SHOULDER])
{
_pPADStatus->button|=PAD_TRIGGER_L;
_pPADStatus->triggerLeft = triggervalue;
}
if (joystate[_numPAD].buttons[CTL_R_SHOULDER])
{
_pPADStatus->button|=PAD_TRIGGER_R;
_pPADStatus->triggerRight = triggervalue;
}

if (joystate[_numPAD].buttons[CTL_A_BUTTON])
{
_pPADStatus->button|=PAD_BUTTON_A;
_pPADStatus->analogA = 255; // Perhaps support pressure?
}
if (joystate[_numPAD].buttons[CTL_B_BUTTON])
{
_pPADStatus->button|=PAD_BUTTON_B;
_pPADStatus->analogB = 255; // Perhaps support pressure?
}
if (joystate[_numPAD].buttons[CTL_X_BUTTON]) _pPADStatus->button|=PAD_BUTTON_X;
if (joystate[_numPAD].buttons[CTL_Y_BUTTON]) _pPADStatus->button|=PAD_BUTTON_Y;
if (joystate[_numPAD].buttons[CTL_Z_TRIGGER]) _pPADStatus->button|=PAD_TRIGGER_Z;
if (joystate[_numPAD].buttons[CTL_START]) _pPADStatus->button|=PAD_BUTTON_START;

// Set D-pad
if (joysticks[_numPAD].controllertype == CTL_TYPE_JOYSTICK)
{
if (joystate[_numPAD].dpad == SDL_HAT_LEFTUP || joystate[_numPAD].dpad == SDL_HAT_UP || joystate[_numPAD].dpad == SDL_HAT_RIGHTUP ) _pPADStatus->button|=PAD_BUTTON_UP;
if (joystate[_numPAD].dpad == SDL_HAT_LEFTUP || joystate[_numPAD].dpad == SDL_HAT_LEFT || joystate[_numPAD].dpad == SDL_HAT_LEFTDOWN ) _pPADStatus->button|=PAD_BUTTON_LEFT;
if (joystate[_numPAD].dpad == SDL_HAT_LEFTDOWN || joystate[_numPAD].dpad == SDL_HAT_DOWN || joystate[_numPAD].dpad == SDL_HAT_RIGHTDOWN ) _pPADStatus->button|=PAD_BUTTON_DOWN;
if (joystate[_numPAD].dpad == SDL_HAT_RIGHTUP || joystate[_numPAD].dpad == SDL_HAT_RIGHT || joystate[_numPAD].dpad == SDL_HAT_RIGHTDOWN ) _pPADStatus->button|=PAD_BUTTON_RIGHT;
}
else
{
if (joystate[_numPAD].dpad2[CTL_D_PAD_UP])
_pPADStatus->button |= PAD_BUTTON_UP;
if (joystate[_numPAD].dpad2[CTL_D_PAD_DOWN])
_pPADStatus->button |= PAD_BUTTON_DOWN;
if (joystate[_numPAD].dpad2[CTL_D_PAD_LEFT])
_pPADStatus->button |= PAD_BUTTON_LEFT;
if (joystate[_numPAD].dpad2[CTL_D_PAD_RIGHT])
_pPADStatus->button |= PAD_BUTTON_RIGHT;
}

//
_pPADStatus->err = PAD_ERR_NONE;

// Use rumble
Pad_Use_Rumble(_numPAD, _pPADStatus);
}


//////////////////////////////////////////////////////////////////////////////////////////
// Convert stick values, for example from circle to square analog stick radius
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

/* Convert stick values.

The value returned by SDL_JoystickGetAxis is a signed integer s16
(-32768 to 32767). The value used for the gamecube controller is an unsigned
char u8 (0 to 255) with neutral at 0x80 (128), so that it's equivalent to a signed
-128 to 127. */
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
u8 Pad_Convert(int _val)
{
/* If the limits on joystate[].axis[] actually is a u16 then we don't need this
but if it's not actually limited to that we need to apply these limits */
if(_val > 32767) _val = 32767; // upper limit
if(_val < -32768) _val = -32768; // lower limit

// Convert (-32768 to 32767) to (-128 to 127)
_val = _val >> 8;

// Convert (-128 to 127) to (0 to 255)
u8 val = 0x80 + _val;

return val;
}


/* Convert the stick raidus from a circular to a square. I don't know what input values
the actual GC controller produce for the GC, it may be a square, a circle or something
in between. But one thing that is certain is that PC pads differ in their output (as
shown in the list below), so it may be beneficiary to convert whatever radius they
produce to the radius the GC games expect. This is the first implementation of this
that convert a square radius to a circual radius. Use the advanced settings to enable
and calibrate it.

Observed diagonals:
Perfect circle: 71% = sin(45)
Logitech Dual Action: 100%
Dual Shock 2 (Original) with Super Dual Box Pro: 90%
XBox 360 Wireless: 85%
GameCube Controller (Third Party) with EMS TrioLinker Plus II: 60%
*/
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
float SquareDistance(float deg)
{
// See if we have to adjust the angle
deg = abs(deg);
if( (deg > 45 && deg < 135) ) deg = deg - 90;

float rad = deg * M_PI / 180;

float val = abs(cos(rad));
float dist = 1 / val; // Calculate distance from center

//m_frame->m_pStatusBar2->SetLabel(wxString::Format("Deg:%f Val:%f Dist:%f", deg, val, dist));

return dist;
}
std::vector<int> Pad_Square_to_Circle(int _x, int _y)
{
/* Do we need this? */
if(_x > 32767) _x = 32767; if(_y > 32767) _y = 32767; // upper limit
if(_x < -32768) _x = -32768; if(_y > 32767) _y = 32767; // lower limit

///////////////////////////////////////////////////
// Convert to circle
// -----------
int Tmp = atoi (g_Config.SDiagonal.substr(0, g_Config.SDiagonal.length() - 1).c_str());
float Diagonal = Tmp / 100.0;

// First make a perfect square in case we don't have one already
float OrigDist = sqrt( pow((float)_y, 2) + pow((float)_x, 2) ); // Get current distance
float rad = atan2((float)_y, (float)_x); // Get current angle
float deg = rad * 180 / M_PI;

// A diagonal of 85% means a distance of 1.20
float corner_circle_dist = ( Diagonal / sin(45 * M_PI / 180) );
float SquareDist = SquareDistance(deg);
float adj_ratio1; // The original-to-square distance adjustment
float adj_ratio2 = SquareDist; // The circle-to-square distance adjustment
float final_ratio; // The final adjustment to the current distance
float result_dist; // The resulting distance

// Calculate the corner-to-square adjustment ratio
if(corner_circle_dist < SquareDist) adj_ratio1 = SquareDist / corner_circle_dist;
else adj_ratio1 = 1;

// Calculate the resulting distance
result_dist = OrigDist * adj_ratio1 / adj_ratio2;

float x = result_dist * cos(rad); // calculate x
float y = result_dist * sin(rad); // calculate y

int int_x = (int)floor(x);
int int_y = (int)floor(y);

// Debugging
//m_frame->m_pStatusBar2->SetLabel(wxString::Format("%f %f %i", corner_circle_dist, Diagonal, Tmp));

std::vector<int> vec;
vec.push_back(int_x);
vec.push_back(int_y);
return vec;
}
//////////////////////////////////////////////////////////////////////////////////////////


// Set PAD attached pads
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
unsigned int PAD_GetAttachedPads()
{
unsigned int connected = 0;

g_Config.Load();

if (joysticks[0].enabled) connected |= 1;
if (joysticks[1].enabled) connected |= 2;
if (joysticks[2].enabled) connected |= 4;
if (joysticks[3].enabled) connected |= 8;

return connected;
}



//////////////////////////////////////////////////////////////////////////////////////////
// Read current joystick status
/* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
The value joysticks[].buttons[] is the number of the assigned joypad button,
joystate[].buttons[] is the status of the button, it becomes 0 (no pressed) or 1 (pressed) */

// Read buttons status. Called from GetJoyState().
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void ReadButton(int controller, int button)
{
int ctl_button = joysticks[controller].buttons[button];
if (ctl_button < joyinfo[joysticks[controller].ID].NumButtons)
{
joystate[controller].buttons[button] = SDL_JoystickGetButton(joystate[controller].joy, ctl_button);
}
}

// Request joystick state. The input value "controller" is for a virtual controller 0 to 3.
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void GetJoyState(int controller)
{
SDL_JoystickUpdate();

joystate[controller].axis[CTL_MAIN_X] = SDL_JoystickGetAxis(joystate[controller].joy, joysticks[controller].axis[CTL_MAIN_X]);
joystate[controller].axis[CTL_MAIN_Y] = SDL_JoystickGetAxis(joystate[controller].joy, joysticks[controller].axis[CTL_MAIN_Y]);
joystate[controller].axis[CTL_SUB_X] = SDL_JoystickGetAxis(joystate[controller].joy, joysticks[controller].axis[CTL_SUB_X]);
joystate[controller].axis[CTL_SUB_Y] = SDL_JoystickGetAxis(joystate[controller].joy, joysticks[controller].axis[CTL_SUB_Y]);

ReadButton(controller, CTL_L_SHOULDER);
ReadButton(controller, CTL_R_SHOULDER);
ReadButton(controller, CTL_A_BUTTON);
ReadButton(controller, CTL_B_BUTTON);
ReadButton(controller, CTL_X_BUTTON);
ReadButton(controller, CTL_Y_BUTTON);
ReadButton(controller, CTL_Z_TRIGGER);
ReadButton(controller, CTL_START);

//
if (joysticks[controller].halfpress < joyinfo[controller].NumButtons)
joystate[controller].halfpress = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].halfpress);

// Check if we have an analog or digital joypad
if (joysticks[controller].controllertype == CTL_TYPE_JOYSTICK)
{
joystate[controller].dpad = SDL_JoystickGetHat(joystate[controller].joy, joysticks[controller].dpad);
}
else
{
joystate[controller].dpad2[CTL_D_PAD_UP] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].dpad2[CTL_D_PAD_UP]);
joystate[controller].dpad2[CTL_D_PAD_DOWN] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].dpad2[CTL_D_PAD_DOWN]);
joystate[controller].dpad2[CTL_D_PAD_LEFT] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].dpad2[CTL_D_PAD_LEFT]);
joystate[controller].dpad2[CTL_D_PAD_RIGHT] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].dpad2[CTL_D_PAD_RIGHT]);
}
}
//////////////////////////////////////////////////////////////////////////////////////////
Show details Hide details

Change log

r1828 by nakeee on Yesterday (20 hours ago)   Diff
ADding functions
Go to: 
Project members, sign in to write a code review

Older revisions

r1791 by jpeterson57 on Jan 04 (4 days ago)   Diff
nJoy: Config fix
r1708 by jpeterson57 on Dec 28, 2008   Diff
nJoy: Typo
r1707 by jpeterson57 on Dec 28, 2008   Diff
nJoy: Changed comment
All revisions of this file

File info

Size: 20855 bytes, 676 lines

File properties

svn:eol-style
native