The keymap now uses a std::map instead of a glib map
This commit is contained in:
bgk 2008-08-30 08:27:17 +00:00
parent 0c037c3998
commit 4a3420f16c
3 changed files with 9 additions and 23 deletions

View File

@ -57,8 +57,6 @@ u8 gbSoundRead( u16 address )
void gbSoundEvent(register u16 address, register int data)
{
int freq = 0;
gbMemory[address] = data;
if ( gb_apu && address >= NR10 && address <= 0xFF3F )

View File

@ -18,36 +18,25 @@
#include "input.h"
#include <new>
namespace VBA
{
Keymap::Keymap()
{
m_pstTable = g_hash_table_new(g_direct_hash, g_direct_equal);
if (m_pstTable == NULL)
{
throw std::bad_alloc();
}
}
Keymap::~Keymap()
{
g_hash_table_destroy(m_pstTable);
}
void Keymap::vRegister(guint _uiVal, EKey _eKey)
void Keymap::vRegister(int _iVal, EKey _eKey)
{
g_hash_table_insert(m_pstTable,
GUINT_TO_POINTER(_uiVal),
GUINT_TO_POINTER(_eKey));
m_oTable[_iVal] = _eKey;
}
void Keymap::vClear()
{
g_hash_table_destroy(m_pstTable);
m_pstTable = g_hash_table_new(g_direct_hash, g_direct_equal);
m_oTable.clear();
}
} // namespace VBA

View File

@ -20,7 +20,7 @@
#ifndef __VBA_INPUT_H__
#define __VBA_INPUT_H__
#include <glib.h>
#include <map>
namespace VBA
{
@ -68,22 +68,21 @@ class Keymap
Keymap();
~Keymap();
void vRegister(guint _uiVal, EKey _eKey);
void vRegister(int _iVal, EKey _eKey);
void vClear();
inline EKey eGetKey(guint _uiVal);
inline EKey eGetKey(int _iVal);
private:
GHashTable * m_pstTable;
std::map<int, EKey> m_oTable;
// noncopyable
Keymap(const Keymap &);
Keymap & operator=(const Keymap &);
};
inline EKey Keymap::eGetKey(guint _uiVal)
inline EKey Keymap::eGetKey(int _iVal)
{
return (EKey)GPOINTER_TO_UINT(g_hash_table_lookup(m_pstTable,
GUINT_TO_POINTER(_uiVal)));
return m_oTable[_iVal];
}
} // namespace VBA