Cosmetic changes only.
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@9939 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
7d7a6d29c0
commit
9410a9bf30
@ -14,9 +14,9 @@ InputDevice::InputDevice()
|
||||
m_player = NULL;
|
||||
m_configuration = NULL;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
/**
|
||||
* Sets which players uses this device; or pass NULL to say no player uses it.
|
||||
* Sets which players uses this device; or pass NULL to say no player uses it.
|
||||
*/
|
||||
void InputDevice::setPlayer(StateManager::ActivePlayer* owner)
|
||||
{
|
||||
@ -28,40 +28,44 @@ void InputDevice::setPlayer(StateManager::ActivePlayer* owner)
|
||||
#pragma mark Keyboard
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
KeyboardDevice::KeyboardDevice(KeyboardConfig *configuration)
|
||||
{
|
||||
m_configuration = configuration;
|
||||
m_type = DT_KEYBOARD;
|
||||
m_name = "Keyboard";
|
||||
m_player = NULL;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
} // KeyboardDevice
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
KeyboardDevice::KeyboardDevice()
|
||||
{
|
||||
m_configuration = new KeyboardConfig();
|
||||
m_type = DT_KEYBOARD;
|
||||
m_player = NULL;
|
||||
}
|
||||
} // KeyboardDevice
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool KeyboardDevice::processAndMapInput(const int id, InputManager::InputDriverMode mode,
|
||||
bool KeyboardDevice::processAndMapInput(const int id,
|
||||
InputManager::InputDriverMode mode,
|
||||
PlayerAction* action /* out */)
|
||||
{
|
||||
if (mode == InputManager::INGAME)
|
||||
{
|
||||
return m_configuration->getGameAction(Input::IT_KEYBOARD, id, 0, action);
|
||||
return m_configuration->getGameAction(Input::IT_KEYBOARD, id, 0,
|
||||
action);
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(mode == InputManager::MENU); // bindings can only be accessed in game and menu modes
|
||||
return m_configuration->getMenuAction(Input::IT_KEYBOARD, id, 0, action);
|
||||
// bindings can only be accessed in game and menu modes
|
||||
assert(mode == InputManager::MENU);
|
||||
return m_configuration->getMenuAction(Input::IT_KEYBOARD, id, 0,
|
||||
action);
|
||||
}
|
||||
}
|
||||
} // processAndMapInput
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------
|
||||
// ============================================================================
|
||||
|
||||
#if 0
|
||||
#pragma mark -
|
||||
@ -69,8 +73,9 @@ bool KeyboardDevice::processAndMapInput(const int id, InputManager::InputDriverM
|
||||
#endif
|
||||
|
||||
|
||||
GamePadDevice::GamePadDevice(const int irrIndex, const std::string name, const int axis_count,
|
||||
const int btnAmount, GamepadConfig *configuration)
|
||||
GamePadDevice::GamePadDevice(const int irrIndex, const std::string name,
|
||||
const int axis_count, const int btnAmount,
|
||||
GamepadConfig *configuration)
|
||||
{
|
||||
m_type = DT_GAMEPAD;
|
||||
m_deadzone = DEADZONE_JOYSTICK;
|
||||
@ -95,7 +100,7 @@ GamePadDevice::GamePadDevice(const int irrIndex, const std::string name, const i
|
||||
m_buttonPressed[n] = false;
|
||||
} // GamePadDevice
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Destructor for GamePadDevice.
|
||||
*/
|
||||
GamePadDevice::~GamePadDevice()
|
||||
@ -107,27 +112,28 @@ GamePadDevice::~GamePadDevice()
|
||||
// FIXME - any need to close devices?
|
||||
} // ~GamePadDevice
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool GamePadDevice::isButtonPressed(const int i)
|
||||
{
|
||||
return m_buttonPressed[i];
|
||||
} // isButtonPressed
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void GamePadDevice::setButtonPressed(const int i, bool isButtonPressed)
|
||||
{
|
||||
m_buttonPressed[i] = isButtonPressed;
|
||||
} // setButtonPressed
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void GamePadDevice::resetAxisDirection(const int axis,
|
||||
Input::AxisDirection direction,
|
||||
StateManager::ActivePlayer* player)
|
||||
{
|
||||
if (StateManager::get()->getGameState() != GUIEngine::GAME) return; // ignore this while in menus
|
||||
// ignore this while in menus
|
||||
if (StateManager::get()->getGameState() != GUIEngine::GAME) return;
|
||||
|
||||
Kart* pk = player->getKart();
|
||||
if (pk == NULL)
|
||||
@ -143,16 +149,18 @@ void GamePadDevice::resetAxisDirection(const int axis,
|
||||
bind.getId() == axis &&
|
||||
bind.getDirection()== direction)
|
||||
{
|
||||
((PlayerController*)(pk->getController()))->action((PlayerAction)n, 0);
|
||||
((PlayerController*)(pk->getController()))
|
||||
->action((PlayerAction)n, 0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
} // resetAxisDirection
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool GamePadDevice::processAndMapInput(Input::InputType type, const int id, const int value,
|
||||
bool GamePadDevice::processAndMapInput(Input::InputType type, const int id,
|
||||
const int value,
|
||||
InputManager::InputDriverMode mode,
|
||||
StateManager::ActivePlayer* player,
|
||||
PlayerAction* action /* out */)
|
||||
@ -164,7 +172,9 @@ bool GamePadDevice::processAndMapInput(Input::InputType type, const int id, cons
|
||||
|
||||
if (type == Input::IT_STICKMOTION)
|
||||
{
|
||||
if (id >= m_axis_count && id != Input::HAT_H_ID && id != Input::HAT_V_ID) return false; // this gamepad doesn't even have that many axes
|
||||
if (id >= m_axis_count && id != Input::HAT_H_ID &&
|
||||
id != Input::HAT_V_ID)
|
||||
return false; // this gamepad doesn't even have that many axes
|
||||
|
||||
if (player != NULL)
|
||||
{
|
||||
@ -175,7 +185,8 @@ bool GamePadDevice::processAndMapInput(Input::InputType type, const int id, cons
|
||||
resetAxisDirection(id, Input::AD_POSITIVE, player);
|
||||
}
|
||||
// going to positive from negative
|
||||
else if (value > 0 && m_prevAxisDirections[id] == Input::AD_NEGATIVE)
|
||||
else if (value > 0 &&
|
||||
m_prevAxisDirections[id] == Input::AD_NEGATIVE)
|
||||
{
|
||||
// set negative id to 0
|
||||
resetAxisDirection(id, Input::AD_NEGATIVE, player);
|
||||
@ -237,17 +248,19 @@ bool GamePadDevice::processAndMapInput(Input::InputType type, const int id, cons
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(mode == InputManager::MENU); // bindings can only be accessed in game and menu modes
|
||||
// bindings can only be accessed in game and menu modes
|
||||
assert(mode == InputManager::MENU);
|
||||
success = m_configuration->getMenuAction(type, id, value, action);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "processAndMapInput() called on improperly initialized GamePadDevice\n");
|
||||
fprintf(stderr, "processAndMapInput() called on improperly "
|
||||
"initialized GamePadDevice\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
return success;
|
||||
} // processAndMapInput
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -31,7 +31,9 @@ protected:
|
||||
DeviceConfig* m_configuration;
|
||||
|
||||
public:
|
||||
std::string m_name; //!< if device has a name; unused for keyboards since AFAIK we can't tell keyboards apart
|
||||
/** If device has a name; unused for keyboards since AFAIK we
|
||||
* can't tell keyboards apart. */
|
||||
std::string m_name;
|
||||
|
||||
InputDevice();
|
||||
void setConfiguration(DeviceConfig *config) {m_configuration = config;}
|
||||
@ -56,13 +58,17 @@ public:
|
||||
KeyboardDevice(KeyboardConfig *configuration);
|
||||
|
||||
/**
|
||||
* Checks if this key belongs to this device. if yes, sets action and returns true; otherwise returns false
|
||||
* Checks if this key belongs to this device. if yes, sets action and
|
||||
* returns true; otherwise returns false
|
||||
*
|
||||
* \param id ID of the key that was pressed
|
||||
* \param mode Used to determine whether to bind menu actions or game actions
|
||||
* \param[out] action The action associated to this input (only check this value if method returned true)
|
||||
* \param mode Used to determine whether to bind menu actions or
|
||||
* game actions
|
||||
* \param[out] action The action associated to this input (only check
|
||||
* this value if method returned true)
|
||||
*/
|
||||
bool processAndMapInput(const int id, InputManager::InputDriverMode mode, PlayerAction* action);
|
||||
bool processAndMapInput(const int id, InputManager::InputDriverMode mode,
|
||||
PlayerAction* action);
|
||||
|
||||
};
|
||||
|
||||
@ -72,17 +78,20 @@ public:
|
||||
*/
|
||||
class GamePadDevice : public InputDevice
|
||||
{
|
||||
void resetAxisDirection(const int axis, Input::AxisDirection direction, StateManager::ActivePlayer* player);
|
||||
void resetAxisDirection(const int axis, Input::AxisDirection direction,
|
||||
StateManager::ActivePlayer* player);
|
||||
bool m_buttonPressed[SEvent::SJoystickEvent::NUMBER_OF_BUTTONS];
|
||||
|
||||
public:
|
||||
Input::AxisDirection *m_prevAxisDirections;
|
||||
|
||||
/** used to determine if an axis is valid; an axis is considered valid when at least 2 different
|
||||
* values are read from this axis (if an axis keeps on sending the exact same value continuously,
|
||||
* chances are that it's not meant by the user - for instance some gamepads have hats or analog
|
||||
* switches that get reported as axis, we even had a report that on linux some hard disks may be
|
||||
* reported as gamepads with uninteresting axis values)
|
||||
/** used to determine if an axis is valid; an axis is considered valid
|
||||
* when at least 2 different values are read from this axis (if an axis
|
||||
* keeps on sending the exact same value continuously, chances are that
|
||||
* it's not meant by the user - for instance some gamepads have hats or
|
||||
* analog switches that get reported as axis, we even had a report that
|
||||
* on linux some hard disks may be reported as gamepads with
|
||||
* uninteresting axis values)
|
||||
*/
|
||||
int *m_prevAxisValue;
|
||||
/** \see m_prevAxisValue */
|
||||
@ -93,11 +102,12 @@ public:
|
||||
int m_axis_count;
|
||||
int m_button_count;
|
||||
|
||||
/** Constructor for GamePadDevice from a connected gamepad for which no configuration existed
|
||||
* (defaults will be used)
|
||||
/** Constructor for GamePadDevice from a connected gamepad for which no
|
||||
* configuration existed (defaults will be used)
|
||||
* \param irrIndex Index of stick as given by irrLicht.
|
||||
*/
|
||||
GamePadDevice(const int irrIndex, const std::string name, const int axis_number,
|
||||
GamePadDevice(const int irrIndex, const std::string name,
|
||||
const int axis_number,
|
||||
const int btnAmount, GamepadConfig *configuration);
|
||||
~GamePadDevice();
|
||||
|
||||
@ -105,18 +115,24 @@ public:
|
||||
void setButtonPressed(const int i, bool isButtonPressed);
|
||||
|
||||
/**
|
||||
* Invoked when this device it used. Verifies if the key/button that was pressed
|
||||
* is associated with a binding. If yes, sets action and returns true; otherwise returns false.
|
||||
* Invoked when this device it used. Verifies if the key/button that
|
||||
* was pressed is associated with a binding. If yes, sets action and
|
||||
* returns true; otherwise returns false.
|
||||
*
|
||||
* \param player Only passed to know where to send 'axis reset's when necessary
|
||||
* \param id ID of the key that was pressed or of the axis that was triggered (depending on
|
||||
* \param player Only passed to know where to send 'axis reset's
|
||||
* when necessary
|
||||
* \param id ID of the key that was pressed or of the axis
|
||||
* that was triggered (depending on
|
||||
* the value of the 'type' parameter)
|
||||
* \param mode Used to determine whether to map menu actions or game actions
|
||||
* \param[out] action The action associated to this input (only check this value if method returned true)
|
||||
* \param mode Used to determine whether to map menu actions or
|
||||
* game actions
|
||||
* \param[out] action The action associated to this input (only check
|
||||
* this value if method returned true)
|
||||
*
|
||||
* \return Whether the pressed key/button is bound with an action
|
||||
*/
|
||||
bool processAndMapInput(Input::InputType type, const int id, const int value,
|
||||
bool processAndMapInput(Input::InputType type, const int id,
|
||||
const int value,
|
||||
InputManager::InputDriverMode mode,
|
||||
StateManager::ActivePlayer* player,
|
||||
PlayerAction* action);
|
||||
@ -125,4 +141,3 @@ public:
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -30,9 +30,13 @@
|
||||
# ifdef _DEBUG
|
||||
# ifndef _DBG_NEW
|
||||
# include <crtdbg.h>
|
||||
inline void* __operator_new(size_t __n) { return ::operator new(__n,_NORMAL_BLOCK,__FILE__,__LINE__); }
|
||||
inline void* _cdecl operator new(size_t __n,const char* __fname,int __line) { return ::operator new(__n,_NORMAL_BLOCK,__fname,__line); }
|
||||
inline void _cdecl operator delete(void* __p,const char*,int) { ::operator delete(__p);}
|
||||
inline void* __operator_new(size_t __n) { return ::operator
|
||||
new(__n,_NORMAL_BLOCK,__FILE__,__LINE__); }
|
||||
inline void* _cdecl operator new(size_t __n,const char* __fname,
|
||||
int __line) {
|
||||
return ::operator new(__n,_NORMAL_BLOCK,__fname,__line); }
|
||||
inline void _cdecl operator delete(void* __p,const char*,int)
|
||||
{ ::operator delete(__p);}
|
||||
# define _DBG_NEW new(__FILE__,__LINE__)
|
||||
# define new _DBG_NEW
|
||||
# endif // _DBG_NEW
|
||||
@ -50,7 +54,8 @@ class ReplayBuffer
|
||||
friend class ReplayBufferArray<T>;
|
||||
|
||||
public:
|
||||
ReplayBuffer() : m_pp_blocks(NULL),m_number_blocks(0),m_block_size(0),m_number_objects_used(0),m_healthy(true) {}
|
||||
ReplayBuffer() : m_pp_blocks(NULL),m_number_blocks(0),m_block_size(0),
|
||||
m_number_objects_used(0),m_healthy(true) {}
|
||||
~ReplayBuffer() { destroy(); }
|
||||
|
||||
private:
|
||||
@ -68,8 +73,9 @@ public:
|
||||
// does not allocate memory, index must be < getNumberObjectsUsed()
|
||||
T const* getObjectAt( size_t index ) const;
|
||||
T* getObjectAt( size_t index );
|
||||
size_t getNumberObjectsUsed() const { return m_number_objects_used; }
|
||||
size_t getNumberBlocks() const { return m_number_blocks; }
|
||||
size_t getNumberObjectsUsed() const
|
||||
{ return m_number_objects_used; }
|
||||
size_t getNumberBlocks() const { return m_number_blocks; }
|
||||
|
||||
private:
|
||||
// adds a new block of objects to m_pp_blocks with a size of m_block_size
|
||||
@ -103,8 +109,8 @@ private:
|
||||
};
|
||||
|
||||
|
||||
// does the same as ReplayBuffer<T>, but it returns an array of objects, rather than just one
|
||||
// object ..
|
||||
// does the same as ReplayBuffer<T>, but it returns an array of objects,
|
||||
// rather than just one object ..
|
||||
template<typename T>
|
||||
class ReplayBufferArray
|
||||
{
|
||||
@ -113,16 +119,24 @@ public:
|
||||
~ReplayBufferArray() { destroy(); }
|
||||
|
||||
void destroy();
|
||||
bool init( size_t number_preallocated_arrays, size_t array_size );
|
||||
bool init( size_t number_preallocated_arrays,
|
||||
size_t array_size );
|
||||
// returns a new *free* array of objects with size of 2nd param in init
|
||||
T* getNewArray();
|
||||
// returs objects at given position, like usual array access,
|
||||
// does not allocate memory
|
||||
T const* getArrayAt( size_t index ) const { assert( m_array_size ); return m_Buffer.getObjectAt( m_array_size * index ); }
|
||||
T* getArrayAt( size_t index ) { assert( m_array_size ); return m_Buffer.getObjectAt( m_array_size * index ); }
|
||||
size_t getNumberArraysUsed() const { return m_Buffer.getNumberObjectsUsed() / m_array_size; }
|
||||
size_t getNumberBlocks() const { return m_Buffer.getNumberBlocks(); }
|
||||
bool isHealthy() const { return m_Buffer.isHealthy(); }
|
||||
T const* getArrayAt( size_t index ) const
|
||||
{ assert( m_array_size );
|
||||
return m_Buffer.getObjectAt( m_array_size * index ); }
|
||||
T* getArrayAt( size_t index )
|
||||
{ assert( m_array_size );
|
||||
return m_Buffer.getObjectAt( m_array_size * index ); }
|
||||
size_t getNumberArraysUsed() const
|
||||
{ return m_Buffer.getNumberObjectsUsed() / m_array_size; }
|
||||
size_t getNumberBlocks() const
|
||||
{ return m_Buffer.getNumberBlocks(); }
|
||||
bool isHealthy() const
|
||||
{ return m_Buffer.isHealthy(); }
|
||||
|
||||
private:
|
||||
ReplayBuffer<T> m_Buffer;
|
||||
@ -160,8 +174,8 @@ void ReplayBuffer<T>::destroy()
|
||||
}
|
||||
}
|
||||
|
||||
// returns a new *free* frame to be used to store the current frame-data into it
|
||||
// used to *record* the replay
|
||||
// returns a new *free* frame to be used to store the current frame-data into
|
||||
// it used to *record* the replay
|
||||
template<typename T>
|
||||
T* ReplayBuffer<T>::getNewObject()
|
||||
{
|
||||
@ -239,7 +253,8 @@ bool ReplayBuffer<T>::addNewBlock()
|
||||
// only the pointers, to blocks of objects, which is supposed
|
||||
// to be a very small number .. 2 is probably never reached
|
||||
size_t tmp;
|
||||
for( tmp = 0; tmp < m_number_blocks; ++tmp ) m_pp_blocks[tmp] = pp_blocks_old[tmp];
|
||||
for( tmp = 0; tmp < m_number_blocks; ++tmp )
|
||||
m_pp_blocks[tmp] = pp_blocks_old[tmp];
|
||||
|
||||
// create new objects at new block position
|
||||
m_pp_blocks[m_number_blocks] = buffer_new_array<T>( m_block_size );
|
||||
@ -268,7 +283,8 @@ void ReplayBufferArray<T>::destroy()
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool ReplayBufferArray<T>::init( size_t number_preallocated_arrays, size_t array_size )
|
||||
bool ReplayBufferArray<T>::init( size_t number_preallocated_arrays,
|
||||
size_t array_size )
|
||||
{
|
||||
assert( number_preallocated_arrays );
|
||||
assert( array_size );
|
||||
@ -283,7 +299,8 @@ T* ReplayBufferArray<T>::getNewArray()
|
||||
if( !isHealthy() ) return NULL;
|
||||
|
||||
// check, if we need a new block
|
||||
if( m_Buffer.m_number_objects_used == (m_Buffer.m_block_size*m_Buffer.m_number_blocks) )
|
||||
if( m_Buffer.m_number_objects_used ==
|
||||
(m_Buffer.m_block_size*m_Buffer.m_number_blocks) )
|
||||
{
|
||||
// we need a new block
|
||||
if( !m_Buffer.addNewBlock() ) return NULL;
|
||||
@ -291,10 +308,13 @@ T* ReplayBufferArray<T>::getNewArray()
|
||||
|
||||
// get current frame
|
||||
T* block_current = m_Buffer.m_pp_blocks[ m_Buffer.m_number_blocks-1 ];
|
||||
size_t new_in_block_idx = m_Buffer.m_number_objects_used % m_Buffer.m_block_size;
|
||||
size_t new_in_block_idx =
|
||||
m_Buffer.m_number_objects_used % m_Buffer.m_block_size;
|
||||
T* current = block_current + new_in_block_idx;
|
||||
|
||||
assert( (current + m_array_size) <= (m_Buffer.m_pp_blocks[ m_Buffer.m_number_blocks-1 ] + m_Buffer.m_block_size) );
|
||||
assert( (current + m_array_size) <= (m_Buffer
|
||||
.m_pp_blocks[ m_Buffer.m_number_blocks-1 ]
|
||||
+ m_Buffer.m_block_size) );
|
||||
|
||||
m_Buffer.m_number_objects_used += m_array_size;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user