- Main Page
- Classes
- Files

- File List
- File Members

# flInput.c

Go to the documentation of this file.

    00001 #include "flGlobal.h"
    00002 #if FL_INPUT != 0
    00003 #include <stdio.h>
    00004 #include <stdlib.h>
    00005 #include <pspctrl.h>
    00006
    00007 #if FL_INCLUDE_ALL_C == 0
    00008 #include "flInput.h"
    00009
    00010 #if FL_TIMER != 0
    00011 #include "flTimer.h"
    00012 #endif
    00013 #endif
    00014
    00015 u8          inputStates[32];
    00016 SceCtrlData inputData[2];
    00017
    00018 #if FL_TIMER != 0
    00019 Timer* inputTimer;
    00020 #endif
    00021 float  inputLockTime = 0;
    00022
    00023 void       (*inputPause)() = NULL;
    00024 u8         inputPauseButton = 0;
    00025 u8         inputPauseState = 0;
    00026
    00027 void inputInit() {
    00028      sceCtrlReadBufferPositive(&inputData[0], 1);
    00029      #if FL_TIMER != 0
    00030      inputTimer = timerCreate();
    00031      #endif
    00032 }
    00033
    00034 u8 inputCheck(u8 inInput) {
    00035      if(inputLockTime > 0)
    00036           return 0;
    00037      return inputStates[inInput];
    00038 }
    00039
    00040 bool inputDown(u8 inInput) {
    00041      if(inputLockTime > 0)
    00042           return 0;
    00043      return (inputStates[inInput] & 1);
    00044 }
    00045
    00046 void inputPoll() {
    00047      if(inputLockTime > 0.0f) {
    00048           #if FL_TIMER != 0
    00049           inputLockTime -= timerGetDeltaTime(inputTimer);
    00050           #else
    00051           inputLockTime--;
    00052           #endif
    00053           if(inputLockTime < 0.0f)
    00054                inputLockTime = 0.0f;
    00055      } else {
    00056           timerGetDeltaTime(inputTimer);
    00057      }
    00058      inputData[0] = inputData[1];
    00059      sceCtrlPeekBufferPositive(&inputData[1], 1);
    00060      int i;
    00061      for(i = 0; i < 32; i++) {
    00062           if(inputData[1].Buttons & (1 << i))
    00063                inputStates[i] = 1;
    00064           else
    00065                inputStates[i] = 0;
    00066           if((inputData[0].Buttons & (1 << i)) != (inputData[1].Buttons & (1 << i)))
    00067                inputStates[i] |= 2;
    00068      }
    00069      if(inputPause && (inputLockTime <= 0.0f)) {
    00070           if(inputStates[inputPauseButton] == inputPauseState) {
    00071                (*inputPause)();
    00072                inputLock(0.0625);
    00073           }
    00074      }
    00075 }
    00076
    00077 void inputLock(float inTime) {
    00078      if(inputLockTime == 0)
    00079           timerGetDeltaTime(inputTimer);
    00080      inputLockTime += inTime;
    00081 }
    00082
    00083 void inputPauseFunc(u8 inInput, u8 inState, void (*inFunc)()) {
    00084      inputPause = inFunc;
    00085      inputPauseButton = inInput;
    00086      inputPauseState = (inState & 3);
    00087 }
    00088
    00089 #endif