Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

# JoystickState.cpp

Go to the documentation of this file.

    00001 //------------------------------------------------------------------------------
    00002 // Lamp : Open source game middleware
    00003 // Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
    00004 //
    00005 // This library is free software; you can redistribute it and/or
    00006 // modify it under the terms of the GNU Lesser General Public
    00007 // License as published by the Free Software Foundation; either
    00008 // version 2.1 of the License, or (at your option) any later version.
    00009 //
    00010 // This library is distributed in the hope that it will be useful,
    00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013 // Lesser General Public License for more details.
    00014 //
    00015 // You should have received a copy of the GNU Lesser General Public
    00016 // License along with this library; if not, write to the Free Software
    00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00018 //------------------------------------------------------------------------------
    00019
    00020 /** @file
    00021  * ジョイスティックステート実装
    00022  * @author Junpee
    00023  */
    00024
    00025 #include "LampBasic.h"
    00026 #include "Input/Joystick/JoystickState.h"
    00027 #include "Core/InputOutput/BinaryWriter.h"
    00028 #include "Core/InputOutput/BinaryReader.h"
    00029
    00030 namespace Lamp{
    00031
    00032 //------------------------------------------------------------------------------
    00033 // バイナリ書き出し
    00034 void JoystickState::writeBinary(BinaryWriter* binaryWriter) const{
    00035     Assert(Limit::inShortRange(getXAxis()));
    00036     Assert(Limit::inShortRange(getYAxis()));
    00037     Assert(Limit::inShortRange(getZAxis()));
    00038     Assert(Limit::inShortRange(getXRotation()));
    00039     Assert(Limit::inShortRange(getYRotation()));
    00040     Assert(Limit::inShortRange(getZRotation()));
    00041     Assert(Limit::inShortRange(getSlider(0)));
    00042     Assert(Limit::inShortRange(getSlider(1)));
    00043     binaryWriter->writeShort(getXAxis());
    00044     binaryWriter->writeShort(getYAxis());
    00045     binaryWriter->writeShort(getZAxis());
    00046     binaryWriter->writeShort(getXRotation());
    00047     binaryWriter->writeShort(getYRotation());
    00048     binaryWriter->writeShort(getZRotation());
    00049     for(int i = 0; i < maxPOVCount; i++){ binaryWriter->writeInt(getPOV(i)); }
    00050     for(int i = 0; i < maxSliderCount; i++){
    00051         binaryWriter->writeShort(getSlider(i));
    00052     }
    00053     BitSet<u_int> buttonBit(0);
    00054     for(int i = 0; i < maxButtonCount; i++){
    00055         buttonBit.setIndexedBit(i, buttonPressed(i));
    00056     }
    00057     binaryWriter->writeUInt(buttonBit.getBits());
    00058 }
    00059 //------------------------------------------------------------------------------
    00060 // バイナリ読み込み
    00061 void JoystickState::readBinary(BinaryReader* binaryReader){
    00062     setXAxis(binaryReader->readShort());
    00063     setYAxis(binaryReader->readShort());
    00064     setZAxis(binaryReader->readShort());
    00065     setXRotation(binaryReader->readShort());
    00066     setYRotation(binaryReader->readShort());
    00067     setZRotation(binaryReader->readShort());
    00068     for(int i = 0; i < maxPOVCount; i++){ setPOV(i, binaryReader->readInt()); }
    00069     for(int i = 0; i < maxSliderCount; i++){
    00070         setSlider(i, binaryReader->readShort());
    00071     }
    00072     BitSet<u_int> buttonBit(binaryReader->readUInt());
    00073     for(int i = 0; i < maxButtonCount; i++){
    00074         setButtonPressed(i, buttonBit.getIndexedBit(i));
    00075     }
    00076 }
    00077 //------------------------------------------------------------------------------
    00078 } // End of namespace Lamp
    00079 //------------------------------------------------------------------------------