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) void gbSoundEvent(register u16 address, register int data)
{ {
int freq = 0;
gbMemory[address] = data; gbMemory[address] = data;
if ( gb_apu && address >= NR10 && address <= 0xFF3F ) if ( gb_apu && address >= NR10 && address <= 0xFF3F )

View File

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

View File

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