~ubuntu-branches/ubuntu/lucid/sdlmame/lucid

« back to all changes in this revision

Viewing changes to src/osd/sdl/input.c

  • Committer: Bazaar Package Importer
  • Author(s): Cesare Falco
  • Date: 2009-11-03 17:10:15 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20091103171015-6hop4ory5lxnumpn
Tags: 0.135-0ubuntu1
* New upstream release - Closes (LP: #403212)
* debian/watch: unstable releases are no longer detected
* mame.ini: added the cheat subdirectories to cheatpath so zipped
  cheatfiles will be searched too
* renamed crsshair subdirectory to crosshair to reflect upstream change
* mame.ini: renamed references to crosshair subdirectory (see above)

Show diffs side-by-side

added added

removed removed

Lines of Context:
129
129
 
130
130
static sdl_window_info *        focus_window = NULL;
131
131
 
132
 
#if SDLMAME_EVENTS_IN_WORKER_THREAD
133
 
// input buffer
 
132
// input buffer - only for SDLMAME_EVENTS_IN_WORKER_THREAD
134
133
#define MAX_BUF_EVENTS          (500)           /* 100 not enough for SDL 1.3 */
135
134
static SDL_Event                        event_buf[MAX_BUF_EVENTS];
136
135
static int                                      event_buf_count;
137
 
#endif
138
136
 
139
137
// keyboard states
140
138
static device_info *            keyboard_list;
779
777
        
780
778
        mouse_enabled = options_get_bool(mame_options(), OPTION_MOUSE);
781
779
 
782
 
        devmap_init(&mouse_map, SDLOPTION_MOUSEINDEX, 8, "Mouse mapping");
 
780
        devmap_init(machine, &mouse_map, SDLOPTION_MOUSEINDEX, 8, "Mouse mapping");
783
781
 
784
782
        for (physical_mouse = 0; physical_mouse < SDL_GetNumMice(); physical_mouse++)
785
783
        {
786
 
                char *mouse_name = remove_spaces(SDL_GetMouseName(physical_mouse));
 
784
                char *mouse_name = remove_spaces(machine, SDL_GetMouseName(physical_mouse));
787
785
                
788
786
                devmap_register(&mouse_map, physical_mouse, mouse_name);
789
787
        }
989
987
        int index;
990
988
        kt_table *key_trans_table;
991
989
 
992
 
        key_trans_table = sdlinput_read_keymap();
 
990
        key_trans_table = sdlinput_read_keymap(machine);
993
991
 
994
 
        devmap_init(&keyboard_map, SDLOPTION_KEYBINDEX, 8, "Keyboard mapping");
 
992
        devmap_init(machine, &keyboard_map, SDLOPTION_KEYBINDEX, 8, "Keyboard mapping");
995
993
 
996
994
        for (physical_keyboard = 0; physical_keyboard < SDL_GetNumKeyboards(); physical_keyboard++)
997
995
        {
1176
1174
        }
1177
1175
        return NULL;
1178
1176
}
 
1177
 
 
1178
#if SDL13_COMBINE_RESIZE
 
1179
INLINE void resize_all_windows(void)
 
1180
{
 
1181
        sdl_window_info *w;
 
1182
        osd_ticks_t now = osd_ticks();
 
1183
        
 
1184
        for (w = sdl_window_list; w != NULL; w = w->next)
 
1185
        {
 
1186
                if (w->resize_width && w->resize_height && ((now - w->last_resize) > osd_ticks_per_second() / 10))
 
1187
                {
 
1188
                        sdlwindow_resize(w, w->resize_width, w->resize_height);
 
1189
                        w->resize_width = 0;
 
1190
                        w->resize_height = 0;
 
1191
                }
 
1192
        }
 
1193
}
 
1194
#endif
 
1195
 
1179
1196
#endif
1180
1197
 
1181
1198
void sdlinput_process_events_buf(running_machine *machine)
1182
1199
{
1183
 
#if SDLMAME_EVENTS_IN_WORKER_THREAD
1184
1200
        SDL_Event event;
1185
1201
 
1186
 
        osd_lock_acquire(input_lock);
1187
 
#if (SDL_VERSION_ATLEAST(1,3,0))
1188
 
        /* Make sure we get all pending events */
1189
 
        SDL_PumpEvents();
1190
 
#endif
1191
 
        while(SDL_PollEvent(&event)) 
 
1202
        if (SDLMAME_EVENTS_IN_WORKER_THREAD)
1192
1203
        {
1193
 
                if (event_buf_count < MAX_BUF_EVENTS)
1194
 
                        event_buf[event_buf_count++] = event;
1195
 
                else
1196
 
                        mame_printf_warning("Event Buffer Overflow!\n");        
 
1204
                osd_lock_acquire(input_lock);
 
1205
        #if (SDL_VERSION_ATLEAST(1,3,0))
 
1206
                /* Make sure we get all pending events */
 
1207
                SDL_PumpEvents();
 
1208
        #endif
 
1209
                while(SDL_PollEvent(&event)) 
 
1210
                {
 
1211
                        if (event_buf_count < MAX_BUF_EVENTS)
 
1212
                                event_buf[event_buf_count++] = event;
 
1213
                        else
 
1214
                                mame_printf_warning("Event Buffer Overflow!\n");        
 
1215
                }
 
1216
                osd_lock_release(input_lock);
1197
1217
        }
1198
 
        osd_lock_release(input_lock);
1199
 
#endif
1200
1218
}
1201
1219
 
1202
1220
 
1205
1223
        device_info *devinfo;
1206
1224
        SDL_Event event;
1207
1225
        int index;
1208
 
#if SDLMAME_EVENTS_IN_WORKER_THREAD
 
1226
 
 
1227
        // only for SDLMAME_EVENTS_IN_WORKER_THREAD
1209
1228
        SDL_Event                       loc_event_buf[MAX_BUF_EVENTS];
1210
1229
        int                                     loc_event_buf_count;
1211
1230
        int bufp;
1212
 
#endif
1213
1231
 
1214
1232
        for (index=0; ;index++)
1215
1233
        {
1220
1238
                devinfo->mouse.lY = 0;
1221
1239
        }
1222
1240
 
1223
 
#if SDLMAME_EVENTS_IN_WORKER_THREAD
1224
 
        osd_lock_acquire(input_lock);
1225
 
        memcpy(loc_event_buf, event_buf, sizeof(event_buf));
1226
 
        loc_event_buf_count = event_buf_count;
1227
 
        event_buf_count = 0;
1228
 
        osd_lock_release(input_lock);
1229
 
        bufp = 0;
1230
 
        while (bufp < loc_event_buf_count) {
1231
 
                event = loc_event_buf[bufp++];
1232
 
#else
1233
 
        while(SDL_PollEvent(&event)) {
1234
 
#endif
 
1241
        if (SDLMAME_EVENTS_IN_WORKER_THREAD)
 
1242
        {
 
1243
                osd_lock_acquire(input_lock);
 
1244
                memcpy(loc_event_buf, event_buf, sizeof(event_buf));
 
1245
                loc_event_buf_count = event_buf_count;
 
1246
                event_buf_count = 0;
 
1247
                osd_lock_release(input_lock);
 
1248
                bufp = 0;
 
1249
        }
 
1250
        
 
1251
        while (TRUE) 
 
1252
        {
 
1253
                if (SDLMAME_EVENTS_IN_WORKER_THREAD)
 
1254
                {
 
1255
                        if (bufp >= loc_event_buf_count)
 
1256
                                break;
 
1257
                        event = loc_event_buf[bufp++];
 
1258
                }
 
1259
                else
 
1260
                {
 
1261
                        if (!SDL_PollEvent(&event))
 
1262
                                break;
 
1263
                }
1235
1264
 
1236
1265
                if (event.type == SDL_KEYUP && 
1237
1266
                    event.key.keysym.sym == SDLK_CAPSLOCK)
1442
1471
                                focus_window = window;
1443
1472
                                break;
1444
1473
                        case SDL_WINDOWEVENT_RESIZED:
 
1474
#if SDL13_COMBINE_RESIZE
 
1475
                                window->resize_width = event.window.data1;
 
1476
                                window->resize_height = event.window.data2;
 
1477
                                window->last_resize = osd_ticks();
 
1478
#else
1445
1479
                                if (event.window.data1 != window->width || event.window.data2 != window->height)
1446
1480
                                        sdlwindow_resize(window, event.window.data1, event.window.data2);
 
1481
#endif
1447
1482
                                focus_window = window;
1448
1483
                                break;
1449
1484
                        case SDL_WINDOWEVENT_ENTER:
1461
1496
#endif
1462
1497
                }
1463
1498
        }
 
1499
#if SDL13_COMBINE_RESIZE
 
1500
        resize_all_windows();
 
1501
#endif
1464
1502
}
1465
1503
 
1466
1504