int main(int argc, char **argv) { int i, j, k, treeNo, sumLength; char ch; TTree **treeSet; FILE *text_fv; clock_t totalStart; double totalSecs, scale, sum; char *ancestor; totalStart = clock(); ReadParams(argc, argv); if (rateHetero == CodonRates && invariableSites) { fprintf(stderr, "Invariable sites model cannot be used with codon rate heterogeneity.\n"); exit(4); } if (writeAncestors && fileFormat == NEXUSFormat) { fprintf(stderr, "Warning - When writing ancestral sequences, relaxed PHYLIP format is used.\n"); } if (writeAncestors && maxPartitions > 1) { fprintf(stderr, "Writing ancestral sequences can only be used for a single partition.\n"); exit(4); } if (!userSeed) randomSeed = CreateSeed(); SetSeed(randomSeed); if (!quiet) PrintTitle(); numTrees = OpenTreeFile(); /* if (!treeFile) { */ ReadFileParams(); /*} */ if ((ancestorSeq>0 && !hasAlignment) || ancestorSeq>numSequences) { fprintf(stderr, "Bad ancestral sequence number: %d (%d sequences loaded)\n", ancestorSeq, numSequences); exit(4); } if (textFile) { if ( (text_fv=fopen(textFileName, "rt"))==NULL ) { fprintf(stderr, "Error opening text file for insertion into output: '%s'\n", textFileName); exit(4); } } ancestor=NULL; if (hasAlignment) { AllocateMemory(); ReadFile(); if (numSites<0) numSites=numAlignmentSites; if (ancestorSeq>0) { if (numSites!=numAlignmentSites) { fprintf(stderr, "Ancestral sequence is of a different length to the simulated sequences (%d)\n", numAlignmentSites); exit(4); } ancestor=sequences[ancestorSeq-1]; } } else if (numSites<0) numSites=1000; SetModel(model); numTaxa=-1; scale=1.0; treeSet = (TTree **)malloc(sizeof(TTree **) * maxPartitions); if (treeSet==NULL) { fprintf(stderr, "Out of memory\n"); exit(5); } partitionLengths = (int *)malloc(sizeof(int) * maxPartitions); if (partitionLengths==NULL) { fprintf(stderr, "Out of memory\n"); exit(5); } partitionRates = (double *)malloc(sizeof(double) * maxPartitions); if (partitionRates==NULL) { fprintf(stderr, "Out of memory\n"); exit(5); } for (i = 0; i < maxPartitions; i++) { if ((treeSet[i]=NewTree())==NULL) { fprintf(stderr, "Out of memory\n"); exit(5); } } CreateRates(); treeNo=0; do { partitionLengths[0] = -1; ReadTree(tree_fv, treeSet[0], treeNo+1, 0, NULL, &partitionLengths[0], &partitionRates[0]); if (treeNo==0) { numTaxa=treeSet[0]->numTips; if (!quiet) fprintf(stderr, "Random number generator seed: %ld\n\n", randomSeed); if (fileFormat == NEXUSFormat) { fprintf(stdout, "#NEXUS\n"); fprintf(stdout, "[\nGenerated by %s %s\n\n", PROGRAM_NAME, VERSION_NUMBER); PrintVerbose(stdout); fprintf(stdout, "]\n\n"); } } else if (treeSet[0]->numTips != numTaxa) { fprintf(stderr, "All trees must have the same number of tips.\n"); exit(4); } if (maxPartitions == 1) { if (partitionLengths[0] != -1) { fprintf(stderr, "\nWARNING: The treefile contained partion lengths but only one partition\n"); fprintf(stderr, "was specified.\n"); } partitionLengths[0] = numSites; } sumLength = partitionLengths[0]; i = 1; while (sumLength < numSites && i <= maxPartitions) { if (!IsTreeAvail(tree_fv)) { fprintf(stderr, "\nA set of trees number %d had less partition length (%d) than\n", treeNo + 1, sumLength); fprintf(stderr, "was required to make a sequence of length %d.\n", numSites); exit(4); } ReadTree(tree_fv, treeSet[i], treeNo+1, treeSet[0]->numTips, treeSet[0]->names, &partitionLengths[i], &partitionRates[i]); if (treeSet[i]->numTips != numTaxa) { fprintf(stderr, "All trees must have the same number of tips.\n"); exit(4); } sumLength += partitionLengths[i]; i++; } if (i > maxPartitions) { fprintf(stderr, "\nA set of trees number %d had more partitions (%d) than\n", treeNo + 1, i); fprintf(stderr, "was specified in the user options (%d).\n", maxPartitions); } numPartitions = i; if (sumLength != numSites) { fprintf(stderr, "The sum of the partition lengths in the treefile does not equal\n"); fprintf(stderr, "the specified number of sites.\n"); exit(4); } for (i = 0; i < numPartitions; i++) CreateSequences(treeSet[i], partitionLengths[i]); if (numPartitions > 1) { sum = 0.0; for (i = 0; i < numPartitions; i++) sum += partitionRates[i] * partitionLengths[i]; for (i = 0; i < numPartitions; i++) partitionRates[i] *= numSites / sum; } if (treeNo==0 && verbose && !quiet) { PrintVerbose(stderr); InitProgressBar(numTrees*numDatasets); DrawProgressBar(); } for (i=0; i<numDatasets; i++) { SetCategories(); k = 0; for (j = 0; j < numPartitions; j++) { scale = partitionRates[j]; if (scaleTrees) { if (!treeSet[j]->rooted) { fprintf(stderr, "To scale tree length, they must be rooted and ultrametric.\n"); exit(4); } scale *= treeScale/treeSet[j]->totalLength; } else if (scaleBranches) scale *= branchScale; EvolveSequences(treeSet[j], k, partitionLengths[j], scale, ancestor); k += partitionLengths[j]; } if (writeAncestors) WriteAncestralSequences(stdout, treeSet[0]); else WriteSequences(stdout, (numTrees > 1 ? treeNo+1 : -1), (numDatasets > 1 ? i+1 : -1), treeSet, partitionLengths); if (writeRates) { WriteRates(stderr); } if (textFile) { while (!feof(text_fv)) { ch = fgetc(text_fv); if (!feof(text_fv)) fputc(ch, stdout); } fputc('\n', stdout); rewind(text_fv); } if (verbose && !quiet) ProgressBar(); } for (i = 0; i < numPartitions; i++) DisposeTree(treeSet[i]); treeNo++; } while (IsTreeAvail(tree_fv)); /* for (i = 0; i < maxPartitions; i++) FreeTree(treeSet[i]); */ if (treeFile) fclose(tree_fv); if (textFile) fclose(text_fv); totalSecs = (double)(clock() - totalStart) / CLOCKS_PER_SEC; if (!quiet) { fprintf(stderr, "Time taken: %G seconds\n", totalSecs); if (verboseMemory) fprintf(stderr, "Total memory used: %ld\n", totalMem); } return 0; }
void ReadParams(int argc, char **argv) { int i, j, k; char ch, *P, st[4]; int modelTwoArgs = 0; model=NONE; scaleTrees=0; treeScale=0.0; scaleBranches=0; branchScale=0.0; maxPartitions=1; numPartitions=1; userSeed = 0; numCats=1; rateHetero=NoRates; catRate[0]=1.0; gammaShape=1.0; invariableSites=0; proportionInvariable = 0.0; equalFreqs = 1; equalTstv = 1; tstv=0.50002; for (i = 0; i < NUM_AA_REL_RATES; i++) { aaRelativeRate[i] = 1.0; } for (i = 0; i < NUM_AA; i++) { aaFreq[i] = 1.0; } aaFreqSet = 0; numSites=-1; numDatasets=1; ancestorSeq=0; writeAncestors=0; writeRates=0; verbose=1; fileFormat = PHYLIPFormat; quiet=0; treeFile=0; textFile=0; for (i=1; i<argc; i++) { P=argv[i]; if (*P=='-') { P++; ch=toupper(*P); P++; switch (ch) { case 'H': PrintTitle(); PrintUsage(); exit(0); break; case 'M': k = i; if (GetStrParam(argc, argv, &i, P, st, 3)) { fprintf(stderr, "Bad (or missing) Model Code: %s\n\n", argv[i]); exit(1); } P=st; if (i > k) { modelTwoArgs = 1; } model=-1; for (j=F84; j<numModels; j++) { if (strncmp(P, modelNames[j], 3)==0) { model=j; if (model <= GTR) { isNucModel = 1; numStates = 4; } else { isNucModel = 0; numStates = 20; } } else if (strncmp(P, "REV", 3)==0) { model=GTR; isNucModel = 1; numStates = 4; } } if (model==-1) { fprintf(stderr, "Unknown Model: %s\n\n", argv[i]); exit(1); } break; } } } if (model==NONE) { fprintf(stderr, "No model has been specified (use the -m option)\n\n"); PrintUsage(); exit(1); } for (i=1; i<argc; i++) { P=argv[i]; if (*P!='-') { if (treeFile) { fprintf(stderr, "Illegal command parameter: %s\n\n", argv[i]); PrintUsage(); exit(1); } treeFile=1; strcpy(treeFileName, argv[i]); } else if (*P=='-' && toupper(*(P+1))=='X') { P++; P++; if (*P=='\0') { i++; P = argv[i]; } textFile=1; strcpy(textFileName, P); } else { P++; ch=toupper(*P); P++; switch (ch) { case 'H': // already delt with break; case 'M': // already delt with if (modelTwoArgs) { // the model took two arguments so skip the second one. i++; } break; case 'L': if (GetIntParams(argc, argv, &i, P, 1, &numSites) || numSites<1) { fprintf(stderr, "Bad (or missing) sequence length: %s\n\n", argv[i]); exit(1); } break; case 'N': if (GetIntParams(argc, argv, &i, P, 1, &numDatasets) || numDatasets<1) { fprintf(stderr, "Bad (or missing) number of datasets: %s\n\n", argv[i]); exit(1); } break; case 'P': if (GetIntParams(argc, argv, &i, P, 1, &maxPartitions) || maxPartitions < 1) { fprintf(stderr, "Bad number of partitions: %s\n\n", argv[i]); exit(1); } break; case 'C': if (!isNucModel) { fprintf(stderr, "You can only have codon rates when using nucleotide models\n\n"); exit(1); } if (rateHetero==GammaRates) { fprintf(stderr, "You can only have codon rates or gamma rates not both\n\n"); exit(1); } numCats=3; rateHetero=CodonRates; if (GetDoubleParams(argc, argv, &i, P, 3, catRate) || catRate[0] <= 0.0 || catRate[1] <= 0.0 || catRate[2] <= 0.0 ) { fprintf(stderr, "Bad Category Rates: %s\n\n", argv[i]); exit(1); } break; case 'I': if (GetDoubleParams(argc, argv, &i, P, 1, &proportionInvariable) || proportionInvariable < 0.0 || proportionInvariable >= 1.0) { fprintf(stderr, "Bad Proportion of Invariable Sites: %s\n\n", argv[i]); exit(1); } invariableSites = 1; break; case 'A': if (rateHetero==CodonRates) { fprintf(stderr, "You can only have codon rates or gamma rates not both\n\n"); exit(1); } if (rateHetero==NoRates) rateHetero=GammaRates; if (GetDoubleParams(argc, argv, &i, P, 1, &gammaShape) || gammaShape<=0.0) { fprintf(stderr, "Bad Gamma Shape: %s\n\n", argv[i]); exit(1); } break; case 'G': if (rateHetero==CodonRates) { fprintf(stderr, "You can only have codon rates or gamma rates not both\n\n"); exit(1); } rateHetero=DiscreteGammaRates; if (GetIntParams(argc, argv, &i, P, 1, &numCats) || numCats<2 || numCats>MAX_RATE_CATS) { fprintf(stderr, "Bad number of Gamma Categories: %s\n\n", argv[i]); exit(1); } break; case 'F': if (isNucModel) { if (toupper(*P)=='E'){ /* do nothing - equal freqs is default for nucleotides */ } else { equalFreqs = 0; if (GetDoubleParams(argc, argv, &i, P, NUM_NUC, nucFreq)) { fprintf(stderr, "Bad Nucleotide Frequencies: %s\n\n", argv[i]); exit(1); } } } else { aaFreqSet = 1; if (toupper(*P)=='E'){ equalFreqs = 1; for(j=0;j<NUM_AA;j++) { aaFreq[j]=0.05; } } else { equalFreqs = 0; if (GetDoubleParams(argc, argv, &i, P, NUM_AA, aaFreq)) { fprintf(stderr, "Bad Amino Acid Frequencies: %s\n\n", argv[i]); exit(1); } } } break; case 'T': if (model != HKY && model != F84) { fprintf(stderr, "You can only have a transition/transversion ratio when using HKY or F84 models\n\n"); exit(1); } equalTstv = 0; if (GetDoubleParams(argc, argv, &i, P, 1, &tstv)) { fprintf(stderr, "Bad Transition-Transversion Ratio: %s\n\n", argv[i]); exit(1); } break; case 'R': if (model == GTR) { if (GetDoubleParams(argc, argv, &i, P, NUM_NUC_REL_RATES, nucRelativeRates)) { fprintf(stderr, "Bad General Nucleotide Rate Matrix: %s\n\n", argv[i]); exit(1); } if (nucRelativeRates[NUM_NUC_REL_RATES - 1]!=1.0) { for (j=0; j < NUM_NUC_REL_RATES - 1; j++) nucRelativeRates[j] /= nucRelativeRates[NUM_NUC_REL_RATES - 1]; nucRelativeRates[NUM_NUC_REL_RATES - 1] = 1.0; } } else if ( model == GENERAL) { if (GetDoubleParams(argc, argv, &i, P, NUM_AA_REL_RATES, aaRelativeRate)) { fprintf(stderr, "Bad General Amino Acid Rate Matrix: %s\n\n", argv[i]); exit(1); } } else { fprintf(stderr, "You can only have a general rate matrix when using GTR or GENERAL models\n\n"); exit(1); } break; case 'D': scaleTrees=1; if (GetDoubleParams(argc, argv, &i, P, 1, &treeScale) || treeScale<=0.0) { fprintf(stderr, "Bad Total Tree Scale: %s\n\n", argv[i]); exit(1); } if (scaleBranches) { fprintf(stderr, "You can't specify both the -d and -s options\n\n"); exit(1); } break; case 'S': scaleBranches=1; if (GetDoubleParams(argc, argv, &i, P, 1, &branchScale) || branchScale<=0.0) { fprintf(stderr, "Bad Branch Length Scale: %s\n\n", argv[i]); exit(1); } if (scaleTrees) { fprintf(stderr, "You can't specify both the -d and -s options\n\n"); exit(1); } break; case 'K': if (GetIntParams(argc, argv, &i, P, 1, &ancestorSeq) || ancestorSeq<1) { fprintf(stderr, "Bad ancestral sequence number: %s\n\n", argv[i]); exit(1); } break; case 'Z': userSeed = 1; if (GetUnsignedLongParams(argc, argv, &i, P, 1, &randomSeed)) { fprintf(stderr, "Bad random number generator seed: %s\n\n", argv[i]); exit(1); } break; case 'O': switch (toupper(*P)) { case 'P': fileFormat=PHYLIPFormat; break; case 'R': fileFormat=RelaxedFormat; break; case 'N': fileFormat=NEXUSFormat; break; case 'F': fileFormat=FASTAFormat; break; default: fprintf(stderr, "Unknown output format: %s\n\n", argv[i]); PrintUsage(); exit(1); } break; case 'W': switch (toupper(*P)) { case 'A': writeAncestors=1; break; case 'R': writeRates=1; break; default: fprintf(stderr, "Unknown write mode: %s\n\n", argv[i]); PrintUsage(); exit(1); } break; case 'Q': quiet=1; break; default: fprintf(stderr, "Illegal command parameter: %s\n\n", argv[i]); PrintUsage(); exit(1); break; } } } }
// ------------------------------------------------------------------------------------ int _tmain () { SetConsoleTitle(_T("- WiiYourself! - Demo: ")); HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE); // write the title PrintTitle(console); // let's load a couple of samples: wiimote_sample sine_sample, daisy_sample; // one .raw (just to demonstrate it) if(!wiimote::Load16BitMonoSampleRAW(_T("1kSine16 (3130).raw"), true, FREQ_3130HZ, sine_sample)) { _tprintf(_T("\r ** can't find 'Sine16 (3130).raw' - (sample won't work!) **")); Beep(100, 1000); Sleep(3000); _tprintf(_T("\r") BLANK_LINE); } // and one (more convenient) .wav if(!wiimote::Load16bitMonoSampleWAV(_T("Daisy16 (3130).wav"), daisy_sample)) { _tprintf(_T("\r ** can't find 'Daisy16 (3130).wav' - (sample won't work!) **")); Beep(100, 1000); Sleep(3000); _tprintf(_T("\r") BLANK_LINE); } // create a wiimote object wiimote remote; // in this demo we use a state-change callback to get notified of // extension-related events, and polling for everything else // (note you don't have to use both, use whatever suits your app): remote.ChangedCallback = on_state_change; // notify us only when the wiimote connected sucessfully, or something // related to extensions changes remote.CallbackTriggerFlags = (state_change_flags)(CONNECTED | EXTENSION_CHANGED | MOTIONPLUS_CHANGED); reconnect: COORD pos = { 0, 6 }; SetConsoleCursorPosition(console, pos); // try to connect the first available wiimote in the system // (available means 'installed, and currently Bluetooth-connected'): WHITE; _tprintf(_T(" Looking for a Wiimote ")); static const TCHAR* wait_str[] = { _T(". "), _T(".. "), _T("...") }; unsigned count = 0; while(!remote.Connect(wiimote::FIRST_AVAILABLE)) { _tprintf(_T("\b\b\b\b%s "), wait_str[count%3]); count++; #ifdef USE_BEEPS_AND_DELAYS Beep(500, 30); Sleep(1000); #endif } // connected - light all LEDs remote.SetLEDs(0x0f); BRIGHT_CYAN; _tprintf(_T("\b\b\b\b... connected!")); if(remote.IsBalanceBoard()) { BRIGHT_WHITE; _tprintf(_T(" (Balance Board)")); } #ifdef USE_BEEPS_AND_DELAYS Beep(1000, 300); Sleep(2000); #endif COORD cursor_pos = { 0, 6 }; #ifdef LOOK_FOR_ADDITIONAL_WIIMOTES // try to connect any additional wiimotes (just to show the code) _tprintf(_T("\n\n")); wiimote *extra_motes [7] = { NULL }; // 7 should cover it unsigned detected = 0; while(detected < 7) { wiimote *next = new wiimote; if(!next->Connect(wiimote::FIRST_AVAILABLE)) break; extra_motes[detected++] = next; WHITE ; _tprintf(_T(" also found wiimote ")); BRIGHT_GREEN; _tprintf(_T("%u"), detected+1); if(next->IsBalanceBoard()) { WHITE; _tprintf(_T(" (Balance Board)")); } _tprintf(_T("\n\n")); # ifdef USE_BEEPS_AND_DELAYS Beep(1000 + (detected*100), 100); Sleep(500); # endif } WHITE; _tprintf( ((detected == 7)? _T(" (can't detect any more).") : _T(" (no more found).")) ); # ifdef USE_BEEPS_AND_DELAYS Sleep(2000); # endif // clean up for(unsigned index=0; index<detected; index++) delete extra_motes[index]; SetConsoleCursorPosition(console, cursor_pos); #endif // LOOK_FOR_ADDITIONAL_WIIMOTES // print the button event instructions: BRIGHT_WHITE; _tprintf(_T("\r -- TRY: B = rumble, A = square, 1 = sine, 2 = daisy, Home = Exit --\n")); // (stuff for animations) DWORD last_rumble_time = timeGetTime(); // for rumble text animation DWORD last_led_time = timeGetTime(); // for led animation bool rumble_text = true; unsigned lit_led = 0; // display the wiimote state data until 'Home' is pressed: while(!remote.Button.Home())// && !GetAsyncKeyState(VK_ESCAPE)) { // IMPORTANT: the wiimote state needs to be refreshed each pass while(remote.RefreshState() == NO_CHANGE) Sleep(1); // // don't hog the CPU if nothing changed cursor_pos.Y = 8; SetConsoleCursorPosition(console, cursor_pos); // did we loose the connection? if(remote.ConnectionLost()) { BRIGHT_RED; _tprintf( _T(" *** connection lost! *** \n") BLANK_LINE BLANK_LINE BLANK_LINE BLANK_LINE BLANK_LINE BLANK_LINE BLANK_LINE BLANK_LINE BLANK_LINE BLANK_LINE BLANK_LINE BLANK_LINE BLANK_LINE BLANK_LINE BLANK_LINE); Beep(100, 1000); Sleep(2000); COORD pos = { 0, 6 }; SetConsoleCursorPosition(console, pos); _tprintf(BLANK_LINE BLANK_LINE BLANK_LINE); goto reconnect; } // rumble if 'B' (trigger) is pressed remote.SetRumble(remote.Button.B()); // TEMP: Minus button disables MotionPlus (if connected) to allow its // own extension port to work static bool last_minus = false; if(remote.Button.Minus() && !last_minus && (remote.ExtensionType == wiimote_state::MOTION_PLUS)) remote.DisableMotionPlus(); last_minus = remote.Button.Minus(); // actions for buttons just pressed/released: static bool last_A = false, last_One = false, last_Two = false; #define ON_PRESS_RELEASE(button, pressed_action, released_action) \ { bool pressed = remote.Button.button(); \ if(pressed) \ { /* just pressed? */ \ if(!last_##button) pressed_action; \ } \ else if(last_##button) /* just released */ \ released_action; \ /* remember the current button state for next time */ \ last_##button = pressed; } // play audio whilst certain buttons are held if(!remote.IsBalanceBoard()) { ON_PRESS_RELEASE( A, remote.PlaySquareWave(FREQ_3130HZ, 0x20), remote.EnableSpeaker (false)); ON_PRESS_RELEASE(One, remote.PlaySample (sine_sample), remote.EnableSpeaker (false)); ON_PRESS_RELEASE(Two, remote.PlaySample (daisy_sample), remote.EnableSpeaker (false)); } // Battery level: CYAN; _tprintf(_T(" Battery: ")); // (the green/yellow colour ranges are rough guesses - my wiimote // with rechargeable battery pack fails at around 15%) (remote.bBatteryDrained )? BRIGHT_RED : (remote.BatteryPercent >= 30)? BRIGHT_GREEN : BRIGHT_YELLOW; _tprintf(_T("%3u%% "), remote.BatteryPercent); DWORD current_time = timeGetTime(); // LEDs: // animate them every second if((current_time - last_led_time) >= 1000) { remote.SetLEDs((BYTE)(1<<lit_led)); lit_led = (++lit_led) % 4; last_led_time = timeGetTime(); } CYAN; _tprintf(_T("LEDs: ")); WHITE; _tprintf(_T("[")); for(unsigned led=0; led<4; led++) { if(remote.LED.Lit(led)) { BRIGHT_CYAN; _tprintf(_T("*")); } else { WHITE ; _tprintf(_T("-"));//_T("%c"), '0'+led); } } // Rumble WHITE; _tprintf(_T("] ")); if(remote.bRumble) { BRIGHT_WHITE; _tprintf(rumble_text? _T(" RUMBLE") : _T("RUMBLE ")); // animate the text if((current_time - last_rumble_time) >= 110) { rumble_text = !rumble_text; last_rumble_time = current_time; } } else _tprintf(_T(" ")); // Output method: CYAN; _tprintf( _T(" using %s\n"), (remote.IsUsingHIDwrites()? _T("HID writes") : _T("WriteFile()"))); // 'Unique' IDs (not guaranteed to be unique, check the variable // defintion for details) CYAN ; _tprintf(_T(" ID: ")); YELLOW; _tprintf(_T("%I64u") , remote.UniqueID); #ifdef ID2_FROM_DEVICEPATH // (see comments in header) CYAN; _tprintf(_T(" ID2: ")); WHITE; _tprintf(_T("%I64u\n"), remote.UniqueID2); #else _tprintf(_T("\n")); #endif // Buttons: CYAN; _tprintf(_T(" Buttons: ")); WHITE; _tprintf(_T("[")); for(unsigned bit=0; bit<16; bit++) { WORD mask = (WORD)(1 << bit); // skip unused bits if((wiimote_state::buttons::ALL & mask) == 0) continue; const TCHAR* button_name = wiimote::ButtonNameFromBit[bit]; bool pressed = ((remote.Button.Bits & mask) != 0); if(bit > 0) { CYAN; _tprintf(_T("|")); // seperator } if(pressed) { BRIGHT_WHITE; _tprintf(_T("%s") , button_name); } else { WHITE ; _tprintf(_T("%*s"), _tcslen(button_name), _T("")); } } WHITE; _tprintf(_T("]\n")); // Acceleration: CYAN ; _tprintf(_T(" Accel:")); remote.IsBalanceBoard()? RED : WHITE; _tprintf(_T(" X %+2.3f Y %+2.3f Z %+2.3f \n"), remote.Acceleration.X, remote.Acceleration.Y, remote.Acceleration.Z); // Orientation estimate (shown red if last valid update is aging): CYAN ; _tprintf(_T(" Orient:")); remote.IsBalanceBoard()? RED : WHITE; _tprintf(_T(" UpdateAge %3u "), remote.Acceleration.Orientation.UpdateAge); // show if the last orientation update is considered out-of-date // (using an arbitrary threshold) if(remote.Acceleration.Orientation.UpdateAge > 10) RED; _tprintf(_T("Pitch:%4ddeg Roll:%4ddeg \n") _T(" (X %+.3f Y %+.3f Z %+.3f) \n"), (int)remote.Acceleration.Orientation.Pitch, (int)remote.Acceleration.Orientation.Roll , remote.Acceleration.Orientation.X, remote.Acceleration.Orientation.Y, remote.Acceleration.Orientation.Z); // IR: CYAN ; _tprintf(_T(" IR:")); remote.IsBalanceBoard()? RED : WHITE; _tprintf(_T(" Mode %s "), ((remote.IR.Mode == wiimote_state::ir::OFF )? _T("OFF ") : (remote.IR.Mode == wiimote_state::ir::BASIC )? _T("BASIC") : (remote.IR.Mode == wiimote_state::ir::EXTENDED)? _T("EXT. ") : _T("FULL "))); // IR dot sizes are only reported in EXTENDED IR mode (FULL isn't supported yet) bool dot_sizes = (remote.IR.Mode == wiimote_state::ir::EXTENDED); for(unsigned index=0; index<4; index++) { wiimote_state::ir::dot &dot = remote.IR.Dot[index]; if(!remote.IsBalanceBoard()) WHITE; _tprintf(_T("%u: "), index); if(dot.bVisible) { WHITE; _tprintf(_T("Seen ")); } else { RED ; _tprintf(_T("Not seen ")); } _tprintf(_T("Size")); if(dot_sizes) _tprintf(_T("%3d "), dot.Size); else { RED; _tprintf(_T(" n/a")); if(dot.bVisible) WHITE; } _tprintf(_T(" X %.3f Y %.3f\n"), dot.X, dot.Y); if(index < 3) _tprintf(_T(" ")); } // Speaker: CYAN ; _tprintf(_T(" Speaker:")); remote.IsBalanceBoard()? RED : WHITE; _tprintf(_T(" %s | %s "), (remote.Speaker.bEnabled? _T("On ") : _T("Off")), (remote.Speaker.bMuted ? _T("Muted") : _T(" "))); if(!remote.Speaker.bEnabled || remote.Speaker.bMuted) RED; else//if(remote.IsPlayingAudio()) BRIGHT_WHITE; else WHITE; WHITE; _tprintf(_T("Frequency %4u Hz Volume 0x%02x\n"), wiimote::FreqLookup[remote.Speaker.Freq], remote.Speaker.Volume); // -- Extensions --: CYAN ; _tprintf(_T("__________\n Extnsn.: ")); switch(remote.ExtensionType) { case wiimote_state::NONE: { RED; _tprintf(_T("None \n")); _tprintf(BLANK_LINE BLANK_LINE BLANK_LINE); } break; case wiimote_state::PARTIALLY_INSERTED: { BRIGHT_RED; _tprintf(_T("Partially Inserted \n")); _tprintf(BLANK_LINE BLANK_LINE BLANK_LINE); } break; // -- Nunchuk -- case wiimote_state::NUNCHUK: { BRIGHT_WHITE; _tprintf(_T("Nunchuk ")); // Buttons: CYAN ; _tprintf(_T("Buttons: ")); WHITE; _tprintf(_T("[")); BRIGHT_WHITE; _tprintf(remote.Nunchuk.C? _T("C") : _T(" ")); CYAN ; _tprintf(_T("|")); BRIGHT_WHITE; _tprintf(remote.Nunchuk.Z? _T("Z") : _T(" ")); WHITE ; _tprintf(_T("] ")); // Joystick: CYAN ; _tprintf(_T("Joystick: ")); WHITE ; _tprintf(_T("X %+2.3f Y %+2.3f\n"), remote.Nunchuk.Joystick.X, remote.Nunchuk.Joystick.Y); // Acceleration: CYAN ; _tprintf(_T(" Accel:")); WHITE ; _tprintf(_T(" X %+2.3f Y %+2.3f Z %+2.3f \n"), remote.Nunchuk.Acceleration.X, remote.Nunchuk.Acceleration.Y, remote.Nunchuk.Acceleration.Z); // Orientation estimate (shown red if last valid update is aging): CYAN ; _tprintf(_T(" Orient:")); WHITE ; _tprintf(_T(" UpdateAge %3u "), remote.Nunchuk.Acceleration.Orientation.UpdateAge); // show if the last orientation update is aging if(remote.Nunchuk.Acceleration.Orientation.UpdateAge > 10) RED; _tprintf(_T("Pitch %4ddeg Roll %4ddeg \n") _T(" (X %+.2f Y %+.2f Z %+.2f) \n"), (int)remote.Nunchuk.Acceleration.Orientation.Pitch, (int)remote.Nunchuk.Acceleration.Orientation.Roll , remote.Nunchuk.Acceleration.Orientation.X, remote.Nunchuk.Acceleration.Orientation.Y, remote.Nunchuk.Acceleration.Orientation.Z); } break; // -- Classic Controller -- case wiimote_state::CLASSIC: case wiimote_state::GH3_GHWT_GUITAR: case wiimote_state::GHWT_DRUMS: { BRIGHT_WHITE; // the Guitar Hero controller is just a classic controller with // another ID if(remote.ExtensionType == wiimote_state::CLASSIC) _tprintf(_T("Classic Controller ")); else if(remote.ExtensionType == wiimote_state::GH3_GHWT_GUITAR) _tprintf(_T("GH3/GHWT Guitar ")); else _tprintf(_T("GHWT Drums ")); // L: Joystick/Trigger WHITE; _tprintf(_T("L: ")); CYAN ; _tprintf(_T("Joy ")); WHITE; _tprintf(_T("X %+2.3f Y %+2.3f "), remote.ClassicController.JoystickL.X, remote.ClassicController.JoystickL.Y); CYAN ; _tprintf(_T("Trig ")); WHITE; _tprintf(_T("%+2.3f\n"), remote.ClassicController.TriggerL); // R: Joystick/Trigger WHITE; _tprintf(_T(" R: ")); CYAN ; _tprintf(_T("Joy ")); WHITE; _tprintf(_T("X %+2.3f Y %+2.3f "), remote.ClassicController.JoystickR.X, remote.ClassicController.JoystickR.Y); CYAN ; _tprintf(_T("Trig ")); WHITE; _tprintf(_T("%+2.3f\n"), remote.ClassicController.TriggerR); // Buttons: CYAN; _tprintf(_T(" Buttons: ")); WHITE; _tprintf(_T("[")); for(unsigned bit=0; bit<16; bit++) { WORD mask = (WORD)(1 << bit); // skip unused bits if((wiimote_state::classic_controller::buttons::ALL & mask) == 0) continue; const TCHAR* button_name = wiimote::ClassicButtonNameFromBit[bit]; const TCHAR* seperator = (bit==0)? _T("") : _T("|"); bool pressed = ((remote.ClassicController.Button.Bits & mask) != 0); CYAN; _tprintf(seperator); if(pressed) { BRIGHT_WHITE; _tprintf(_T("%s") , button_name); } else { WHITE ; _tprintf(_T("%*s"), _tcslen(button_name), _T("")); } } WHITE; _tprintf(_T("]")); } break; case wiimote_state::BALANCE_BOARD: { BRIGHT_WHITE; _tprintf(_T("Balance Board")); // Weights: CYAN ; _tprintf(_T(" Weight: ")); WHITE; _tprintf(_T("TL ")); _tprintf(_T("%6.2f"), remote.BalanceBoard.Kg.TopL); CYAN ; _tprintf(_T(" kg")); WHITE; ; _tprintf(_T(" TR ")); _tprintf(_T("%6.2f"), remote.BalanceBoard.Kg.TopR); CYAN; _tprintf(_T(" kg\n")); WHITE; _tprintf(_T(" BL ")); _tprintf(_T("%6.2f"), remote.BalanceBoard.Kg.BottomL); CYAN; _tprintf(_T(" kg")); WHITE; _tprintf(_T(" BR ")); _tprintf(_T("%6.2f"), remote.BalanceBoard.Kg.BottomR); CYAN; _tprintf(_T(" kg \n")); WHITE; _tprintf(_T(" Total ")); _tprintf(_T("%6.2f"), remote.BalanceBoard.Kg.Total); CYAN; _tprintf(_T(" kg")); } break; case wiimote_state::MOTION_PLUS: { BRIGHT_WHITE; _tprintf(_T("Motion Plus")); CYAN ; _tprintf(_T(" Raw: ")); WHITE; _tprintf(_T("Yaw: %04hx ") , remote.MotionPlus.Raw.Yaw); WHITE; _tprintf(_T("Pitch: %04hx ") , remote.MotionPlus.Raw.Pitch); WHITE; _tprintf(_T("Roll: %04hx \n"), remote.MotionPlus.Raw.Roll); CYAN ; _tprintf(_T(" Float: ")); WHITE; _tprintf(_T(" %8.3fdeg") , remote.MotionPlus.Speed.Yaw); WHITE; _tprintf(_T(" %8.3fdeg") , remote.MotionPlus.Speed.Pitch); WHITE; _tprintf(_T(" %8.3fdeg\n") , remote.MotionPlus.Speed.Roll); _tprintf(BLANK_LINE BLANK_LINE); //Sleep(500); } break; } } // disconnect (auto-happens on wiimote destruction anyway, but let's play nice) remote.Disconnect(); Beep(1000, 200); BRIGHT_WHITE; // for automatic 'press any key to continue' msg CloseHandle(console); return 0; }
void CGame::ComputerRender(CDrawPort *pdp) { // if playing a demo if (_pNetwork->IsPlayingDemo()) { // never call computer cmp_ppenPlayer = NULL; } // disable netricsa for non-local players if (cmp_ppenPlayer!=NULL && !_pNetwork->IsPlayerLocal(cmp_ppenPlayer)) { cmp_ppenPlayer = NULL; } if (cmp_ppenDHPlayer!=NULL && !_pNetwork->IsPlayerLocal(cmp_ppenDHPlayer)) { cmp_ppenDHPlayer = NULL; } if (cmp_ppenDHPlayer!=NULL && !pdp->IsDualHead()) { cmp_ppenDHPlayer = NULL; } // initially - no player _ppenPlayer=NULL; // if player calls computer if (cmp_ppenPlayer!=NULL) { // use that player _ppenPlayer = cmp_ppenPlayer; // if computer is on in background if (_pGame->gm_csComputerState==CS_ONINBACKGROUND) { // just toggle to on _pGame->gm_csComputerState=CS_ON; // find group with some unread messages FindGroupWithUnread(); // force reinit _cmtCurrentType = (enum CompMsgType)-1; } // if using dualhead to render computer on second display } else if (cmp_ppenDHPlayer!=NULL) { // use that player _ppenPlayer = cmp_ppenDHPlayer; // clear dualhead request - it has to be reinitialized every frame cmp_ppenDHPlayer = NULL; // if viewing statistics if (_cmtWantedType == CMT_STATISTICS) { // fill in fresh player statistics _ppenPlayer->GetStats(_strStatsDetails, CST_DETAIL, _ctTextCharsPerRow); // force updating UpdateType(TRUE); } // if computer is not on or on in background if (_pGame->gm_csComputerState!=CS_ON && _pGame->gm_csComputerState!=CS_ONINBACKGROUND) { // switch on fast ComputerOn(); fComputerFadeValue = 1.0f; _pGame->gm_csComputerState = CS_ONINBACKGROUND; cmp_bInitialStart = FALSE; // end of eventual initial start } // if should update to new message if (cmp_bUpdateInBackground) { cmp_bUpdateInBackground = FALSE; FindGroupWithUnread(); // force reinit _cmtCurrentType = (enum CompMsgType)-1; } } // if no player if (_ppenPlayer==NULL) { // make sure computer is off _pGame->gm_csComputerState=CS_OFF; // do nothing more return; } // if computer is not active if (_pGame->gm_csComputerState==CS_OFF) { // just remember time tvComputerLast = _pTimer->GetHighPrecisionTimer(); // if a player wants computer if (_ppenPlayer!=NULL) { // start turning on _pGame->gm_csComputerState=CS_TURNINGON; ComputerOn(); } else { return; } } // calculate up-down speed to be independent of refresh speed CTimerValue tvNow = _pTimer->GetHighPrecisionTimer(); CTimerValue tvDelta = tvNow - tvComputerLast; tvComputerLast = tvNow; FLOAT fFadeSpeed = (FLOAT)(tvDelta.GetSeconds() / tmComputerFade); // if computer is dropping down if( _pGame->gm_csComputerState==CS_TURNINGON) { // move it down fComputerFadeValue += fFadeSpeed; // if finished moving if( fComputerFadeValue>1.0f) { // stop fComputerFadeValue = 1.0f; _pGame->gm_csComputerState = CS_ON; cmp_bInitialStart = FALSE; // end of eventual initial start } } // if computer is pulling up if( _pGame->gm_csComputerState==CS_TURNINGOFF) { // move it up fComputerFadeValue -= fFadeSpeed; // if finished moving if( fComputerFadeValue<0.0f) { // stop fComputerFadeValue = 0.0f; _pGame->gm_csComputerState = CS_OFF; ComputerOff(); cmp_ppenPlayer = NULL; // exit computer return; } } // safety check -> do not proceed if no player if (_ppenPlayer==NULL) { return; } // lock drawport CDrawPort dpComp(pdp, FALSE); if(!dpComp.Lock()) { // do nothing return; } // if in fullscreen CDisplayMode dmCurrent; _pGfx->GetCurrentDisplayMode(dmCurrent); if (dmCurrent.IsFullScreen() && dmCurrent.IsDualHead()) { // clamp mouse pointer _vpixMouse(1) = Clamp(_vpixMouse(1), 0L, dpComp.GetWidth()); _vpixMouse(2) = Clamp(_vpixMouse(2), 0L, dpComp.GetHeight()); // if in window } else { // use same mouse pointer as windows _vpixMouse = _vpixExternMouse; // if dualhead if (dpComp.dp_MinI>0) { // offset by half screen _vpixMouse(1) -= dpComp.GetWidth(); } // if widescreen if (dpComp.dp_MinJ>0) { // offset by screen top _vpixMouse(2) -= dpComp.dp_MinJ; } } TIME tmOld = _pTimer->CurrentTick(); FLOAT fLerpOld = _pTimer->GetLerpFactor(); FLOAT fSec = tvNow.GetSeconds(); TIME tmTick = floor(fSec/_pTimer->TickQuantum)*_pTimer->TickQuantum; FLOAT fLerp = (fSec-tmTick)/_pTimer->TickQuantum; _pTimer->SetCurrentTick(tmTick); _pTimer->SetLerp(fLerp); LCDPrepare(1.0f);//ClampUp(fComputerFadeValue*10,1.0f)); LCDSetDrawport(&dpComp); // if initial start if (cmp_bInitialStart) { // do not allow game to show through dpComp.Fill(C_BLACK|255); // if normal start } else { // fade over game view dpComp.Fill(LCDFadedColor(C_BLACK|255)); } dpComp.FillZBuffer(1.0f); // update screen geometry UpdateSize(&dpComp); // update scroll positions UpdateType(); UpdateFirstOnScreen(); // check for message change UpdateMessageAppearing(); // mark current message as read MarkCurrentRead(); // get current time and alpha value FLOAT tmNow = (FLOAT)tvNow.GetSeconds(); ULONG ulA = NormFloatToByte(fComputerFadeValue); _colLight = LCDFadedColor(C_WHITE|255); _colMedium = LCDFadedColor(SE_COL_BLUE_LIGHT|255); _colDark = LCDFadedColor(LerpColor(SE_COL_BLUE_DARK, SE_COL_BLUE_LIGHT, 0.5f)|255); _colBoxes = LCDFadedColor(LerpColor(SE_COL_BLUE_DARK, SE_COL_BLUE_LIGHT, 0.5f)|255); // background LCDRenderCloudsForComp(); // dpComp.DrawLine( 0, pixSizeJ-1, pixSizeI, pixSizeJ-1, C_GREEN|ulA); // all done dpComp.Unlock(); // print title CDrawPort dpTitle(&dpComp, _boxTitle); if (dpTitle.Lock()) { LCDSetDrawport(&dpTitle); LCDRenderCompGrid(); LCDRenderClouds2(); LCDScreenBoxOpenLeft(_colBoxes); PrintTitle(&dpTitle); dpTitle.Unlock(); } // print exit button CDrawPort dpExit(&dpComp, _boxExit); if (dpExit.Lock()) { LCDSetDrawport(&dpExit); LCDRenderCompGrid(); LCDRenderClouds2(); LCDScreenBoxOpenRight(_colBoxes); PrintExit(&dpExit); dpExit.Unlock(); } // print buttons for (INDEX i=0; i<CMT_COUNT; i++) { PrintButton(&dpComp, i); } // print list of messages CDrawPort dpMsgList(&dpComp, _boxMsgList); if (dpMsgList.Lock()) { LCDSetDrawport(&dpMsgList); LCDRenderCompGrid(); LCDRenderClouds2(); LCDScreenBox(_colBoxes); PrintMessageList(&dpMsgList); dpMsgList.Unlock(); } // print text of current message CDrawPort dpMsgText(&dpComp, _boxMsgText); if (dpMsgText.Lock()) { LCDSetDrawport(&dpMsgText); LCDRenderCompGrid(); LCDRenderClouds2(); LCDScreenBox(_colBoxes); PrintMessageText(&dpMsgText); dpMsgText.Unlock(); } // draw image of current message CDrawPort dpMsgImage(&dpComp, _boxMsgImage); if (dpMsgImage.Lock()) { LCDSetDrawport(&dpMsgImage); RenderMessageImage(&dpMsgImage); dpMsgImage.Unlock(); } // render mouse pointer on top of everything else if (_pGame->gm_csComputerState != CS_ONINBACKGROUND) { if (dpComp.Lock()) { LCDSetDrawport(&dpComp); LCDDrawPointer(_vpixMouse(1), _vpixMouse(2)); dpComp.Unlock(); } } _pTimer->SetCurrentTick(tmOld); _pTimer->SetLerp(fLerpOld); }
void ListWidget::Draw( void ) { CompositeWidget::Draw(); PrintTitle( surface->GetFGPen() ); surface->DrawBox( Rect(x,y,listboxw,h), BOX_RECESSED ); DrawNodes(); }