Back to index

supertuxkart  0.5+dfsg1
actionmap.cpp
Go to the documentation of this file.
00001 //  $Id: actionmap.cpp 1259 2007-09-24 12:28:19Z thebohemian $
00002 //
00003 //  SuperTuxKart - a fun racing game with go-kart
00004 //  Copyright (C) 2007 Robert Schuster
00005 //
00006 //  This program is free software; you can redistribute it and/or
00007 //  modify it under the terms of the GNU General Public License
00008 //  as published by the Free Software Foundation; either version 2
00009 //  of the License, or (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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 
00020 #include <map>
00021 
00022 #include "input.hpp"
00023 #include "actionmap.hpp"
00024 
00025 using namespace std;
00026 
00027 void
00028 ActionMap::putEntry(Input input, GameAction ga)
00029 {
00030        inputMap[key(input)] = ga;
00031 }
00032 
00033 GameAction
00034 ActionMap::getEntry(Input input)
00035 {
00036        return inputMap[key(input)];
00037 }
00038 
00039 GameAction
00040 ActionMap::getEntry(InputType type, int id0, int id1, int id2)
00041 {
00042        return inputMap[key(type, id0, id1, id2)];
00043 }
00044 
00045 void
00046 ActionMap::clear()
00047 {
00048     inputMap.clear();
00049 }
00050 
00051 ActionMap::Key
00052 ActionMap::key(Input input)
00053 {
00054        return key(input.type, input.id0, input.id1, input.id2);
00055 }
00056 
00057 ActionMap::Key
00058 ActionMap::key(InputType it, int id0, int id1, int id2)
00059 {
00060     /*
00061      * A short reminder on the bit distribution and their usage:
00062      * it gets 8 bits (InputType)
00063      * id1 gets 16 bits (button, hat or axis number)
00064      * id2 gets 8 bits (direction bit)
00065      * id0 gets 32 bits (That is because id0 can be the keyboard key ids and
00066      * those are unicode and unicode 4.0 is 32 bit)
00067      *
00068      * Assumption: int is (at least) 32 bit
00069      */
00070     return Key(it << 24 | id1 << 8 | id2, id0);
00071 }
00072