- Main Page
- Modules
- Data Structures
- Files

- Search for |

# controller.c

    00001 /*
    00002
    00003   Velocity  v1.5
    00004   Copyright 2006, 2007 Gabriel Anderson
    00005
    00006   This program is free software; you can redistribute it and/or modify
    00007     it under the terms of the GNU General Public License as published by
    00008     the Free Software Foundation; either version 2 of the License, or
    00009     (at your option) any later version.
    00010
    00011     This program is distributed in the hope that it will be useful,
    00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00014     GNU General Public License for more details.
    00015
    00016     You should have received a copy of the GNU General Public License
    00017     along with this program; if not, write to the Free Software
    00018     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    00019
    00020 */
    00021
    00022 //---------------------------------------------------------------------------------//
    00023 // Includes                                                                        //
    00024 //---------------------------------------------------------------------------------//
    00025
    00026 #include "vlib.h"
    00027
    00028 //---------------------------------------------------------------------------------//
    00029 // Controller                                                                      //
    00030 //---------------------------------------------------------------------------------//
    00031
    00032 CONTROLLER *button;
    00033
    00034 CONTROLLER *read_input ( int masked, int init, int interval ) {
    00035   // Get the buttons currently being pressed
    00036   sceCtrlPeekBufferPositive ( &ctrl, 1 );
    00037
    00038   button->repeatMask = masked; // Assign the buttons masks
    00039   button->repeatInit = init; // assign the repeat init
    00040   button->repeatInterval = interval; // assign the repeat intervals
    00041
    00042   // if repeat counter is greater then or equal to the repeat interval and th repeat counter is equal to the button init
    00043   if ( button->repeatCounter >= button->repeatInterval && button->repeatCounter == button->repeatInit ) {
    00044     button->repeatMask = MASK_NONE; // Remove masked buttons for the rest of the frame
    00045     button->repeatCounter -= button->repeatInterval; // subtract repeat interval from repeat counter so we get that fun little sped up effect(like with menu's)
    00046     // if the masked buttons are the same as the held buttons, then increament the counter
    00047   } else if ( button->repeatMask & ctrl.Buttons ) {
    00048     if ( button->repeatCounter == 0 ) button->repeatMask = MASK_NONE;
    00049     button->repeatCounter++;
    00050     // otherwise, set the counter to 0
    00051   } else
    00052     button->repeatCounter = 0;
    00053
    00054   button->released.value = button->held.value & ~ctrl.Buttons; // assign the released buttons
    00055   button->pressed.value = ~button->held.value & ctrl.Buttons; // assign the pressed buttons
    00056   button->held.value = ctrl.Buttons & ~button->repeatMask; // assign the held buttons
    00057
    00058   button->analogX = ( short ) ctrl.Lx - 128; // assign the analog x value
    00059   button->analogY = ( short ) ctrl.Ly - 128; // assign the anolog y value
    00060
    00061   return button; // return all the button info
    00062 }