Exec_info play_game() { static int delay_t, sound_t; char pc_s[10]; uint16_t next_instruction; int id_opcode; int debug = 0, key_menu = 0; Exec_info exec_info = {0,0,0}; exec_info.tick_start = time_getTicks(); while(!keydown(47)) { if(debug) { memset(pc_s, '*', 10); itoa(machine.pc, pc_s + 3); PrintXY(2, 8, pc_s, 0, 0); Bdisp_PutDisp_DD(); OS_InnerWait_ms(800); } if(keydown(78)) debug ^= 1; if(keydown(48)) { while(key_menu != KEY_CTRL_MENU) { GetKey(&key_menu); } } next_instruction = (machine.memory[machine.pc])<<8 | machine.memory[machine.pc+1]; id_opcode = get_opcode(next_instruction); (*do_opcode[id_opcode])(next_instruction); exec_info.cycles_count++; if(machine.delay > 0 && time_getTicks() - delay_t > TIMER_TICKS_PERIOD) { machine.delay --; delay_t = time_getTicks(); } if(machine.sound > 0 && time_getTicks() - sound_t > TIMER_TICKS_PERIOD) { machine.sound --; sound_t = time_getTicks(); } if(id_opcode == 28) delay_t == time_getTicks(); else if(id_opcode == 29) sound_t == time_getTicks(); if(machine.draw_state) { display(); machine.draw_state = 0; } } exec_info.tick_end = time_getTicks(); return exec_info; }
void loop(void *arg, long period){ int c; hal_u32_t scan = 0; kb_inst_t *inst = arg; if (inst->scan){ //scanning request for (c = 0; c < inst->ncols; c++){ scan += ((*inst->hal.cols[c] != inst->param.invert) << c); } if (scan == inst->now[inst->row] && scan != inst->then[inst->row]){ // debounced and changed for (c = 0; c < inst->ncols; c++){ int mask = 1 << c; if ((inst->then[inst->row] & mask) && !(scan & mask)){ //keyup *inst->hal.keycode = inst->keyup + (inst->row << inst->rowshift) + c; keyup(inst); } else if (!(inst->then[inst->row] & mask) && (scan & mask)){//keydown *inst->hal.keycode = inst->keydown + (inst->row << inst->rowshift) + c; keydown(inst); } } } inst->then[inst->row] = inst->now[inst->row]; inst->now[inst->row] = scan; *inst->hal.rows[inst->row] = inst->param.invert; inst->row++; if (inst->row >= inst->nrows) inst->row = 0; *inst->hal.rows[inst->row] = !inst->param.invert; } else { if (*inst->hal.keycode == 0x40) return; if ((*inst->hal.keycode & inst->keydown) == inst->keydown){ keydown(inst); } else if ((*inst->hal.keycode & inst->keydown) == inst->keyup) { keyup(inst); } } }
main() { uchar m; P0=0xFF; //置P0口 P1=0xFF; //置P1口 delay(10); //延时 lcd_init(); //初始化LCD lcd_pos(0); //设置显示位置为第一行的第1个字符 m = 0; while(cdis1[m] != '\0') { //显示字符 lcd_wdat(cdis1[m]); m++; } lcd_pos(0x40); //设置显示位置为第二行第1个字符 m = 0; while(cdis2[m] != '\0') { lcd_wdat(cdis2[m]); //显示字符 m++; } dis_buf = 0x2d; //显示字符"-" while(1) { keydown(); lcd_pos(0x4c); lcd_wdat(dis_buf); //第一位数显示 } }
bool execCommand(Command *cmd) { double x, y; int key; if (strcmp(cmd->cmd, "mm") == 0) { x = strtod(cmd->arg1, NULL); y = strtod(cmd->arg2, NULL); mousemove(x, y); return true; } else if (strcmp(cmd->cmd, "kd") == 0) { key = (int) strtol(cmd->arg1, NULL, 10); keydown(key); } else if (strcmp(cmd->cmd, "ku") == 0) { key = (int)strtol(cmd->arg1, NULL, 10); keyup(key); } else if (strcmp(cmd->cmd, "md") == 0) { mousedown(cmd->arg1[0]); } else if (strcmp(cmd->cmd, "mu") == 0) { mouseup(cmd->arg1[0]); } else if (strcmp(cmd->cmd, "sy") == 0) { scrollY(strtod(cmd->arg1, NULL)); } else if (strcmp(cmd->cmd, "sx") == 0) { scrollX(strtod(cmd->arg1, NULL)); } return false; }
void gere_event(t_graph *g, int *cont, int i, int dec) { Uint32 pause; Uint32 to; SDL_Event event; pause = SDL_GetTicks(); if (dec) set_cursor(g); to = SDL_GetTicks(); while ((to - pause < 1 && *cont) || (i && *cont)) { if (g->key) iterate(g); aff(g, i); while (SDL_PollEvent(&event)) { if (event.type == SDL_KEYDOWN) keydown(g, event, cont); if (event.type == SDL_KEYUP) keyup(g, event); if (event.type == SDL_MOUSEMOTION) mousemove(g, event); } to = SDL_GetTicks(); } if (i) *cont = -1; }
/* thoingggg!! "message for you sir!!!" */ static LRESULT CALLBACK patsy(HWND wh, UINT msg, WPARAM wp, LPARAM lp) /* "WndProc" */ { /* printf("msg %d\n", msg); */ switch (msg) { case WM_DESTROY: PostQuitMessage(0); return 0; case WM_MOUSEMOVE: if (wp & (MK_LBUTTON|MK_MBUTTON|MK_RBUTTON)) { #ifdef SWITCH_CURSORS if (ws_lp_x == -1 && !display_tablet) SetCursor(cross); #endif mousepos(lp); } #ifdef SWITCH_CURSORS else if (ws_lp_x != -1 && !display_tablet) SetCursor(arrow); #endif break; /* return?? */ case WM_LBUTTONDOWN: display_lp_sw = 1; case WM_MBUTTONDOWN: case WM_RBUTTONDOWN: #ifdef SWITCH_CURSORS if (!display_tablet) SetCursor(cross); #endif mousepos(lp); break; /* return?? */ case WM_LBUTTONUP: display_lp_sw = 0; case WM_MBUTTONUP: case WM_RBUTTONUP: #ifdef SWITCH_CURSORS if (!display_tablet) SetCursor(arrow); #endif ws_lp_x = ws_lp_y = -1; break; /* return?? */ case WM_KEYDOWN: keydown(wp); break; case WM_KEYUP: keyup(wp); break; case WM_PAINT: display_repaint(); break; /* return?? */ } return DefWindowProc(wh, msg, wp, lp); }
/********************************************************** 主函数 **********************************************************/ main() { P0 = 0xbf; P2 = 0x7f; //数码管显示"-" P1 = 0xff; while(1) { keydown(); } }
void TreeCtrlTestCase::KeyDown() { EventCounter keydown(m_tree, wxEVT_TREE_KEY_DOWN); wxUIActionSimulator sim; m_tree->SetFocus(); sim.Text("aAbB"); wxYield(); CPPUNIT_ASSERT_EQUAL(6, keydown.GetCount()); }
void ListBaseTestCase::KeyDown() { #if wxUSE_UIACTIONSIMULATOR wxListCtrl* const list = GetList(); EventCounter keydown(list, wxEVT_LIST_KEY_DOWN); wxUIActionSimulator sim; list->SetFocus(); sim.Text("aAbB"); wxYield(); CPPUNIT_ASSERT_EQUAL(6, keydown.GetCount()); #endif }
END_TEST /* Test passes!*/ START_TEST(test_keydown){ SDL_Event event; GameData gameData; SDL_Init(SDL_INIT_VIDEO); /* see startGame in game.c */ event.type = SDL_KEYDOWN; event.key.type = SDL_KEYDOWN; event.key.state = SDL_PRESSED; fail_unless(keydown(&gameData.controlsData, &gameData.gameObjectData,&gameData.graphicsData, &gameData.uiData,&event) == 1, "keydown function failed."); SDL_Quit(); }
void WindowTestCase::KeyEvent() { #if wxUSE_UIACTIONSIMULATOR EventCounter keydown(m_window, wxEVT_KEY_DOWN); EventCounter keyup(m_window, wxEVT_KEY_UP); EventCounter keychar(m_window, wxEVT_CHAR); wxUIActionSimulator sim; m_window->SetFocus(); sim.Text("text"); sim.Char(WXK_SHIFT); wxYield(); CPPUNIT_ASSERT_EQUAL(5, keydown.GetCount()); CPPUNIT_ASSERT_EQUAL(5, keyup.GetCount()); CPPUNIT_ASSERT_EQUAL(4, keychar.GetCount()); #endif }
void draw(void) { glDisable(GL_TEXTURE_2D); up_sider = up_sider + .05; sx = carx + (x_sl*cos(-temp) - 0.5*sin(-temp)); sy = cary + (x_sl*sin(-temp) + 0.5*cos(-temp)); tx = carx + (0.6*cos(temp) - 0.5*sin(-temp)); ty = cary + (0.6*sin(temp) + 0.5*cos(-temp)); r_tx = carx + (0.8*cos(temp) - 0.5*sin(-temp)); r_ty = cary + (0.8*sin(temp) + 0.5*cos(-temp)); keydown(); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glLoadIdentity(); if(FLAG==1) gluLookAt(R*cos(alpha)*sin(theta),R*sin(alpha)*sin(theta),-4 +R*cos(theta),0,0,-4,0,0,-1); if(FLAG==2) gluLookAt(carx - 3*sin(temp),cary - 3*cos(temp) ,-5.5,carx + 5*sin(temp) ,cary + 5*cos(temp) ,-4,0,0,-1); if(FLAG==3) { gluLookAt(carx + 0.14*sin(temp) ,cary + 0.14*cos(temp) ,-5.02,carx + 2*sin(temp) ,cary + 2*cos(temp) ,-4.9,0,0,-1); } if(FLAG==4) { gluLookAt(sx ,sy ,-5.51,sx + 3*sin(temp) ,sy + 3*cos(temp) ,-4.6,0,0,-1); } if(FLAG==5) { gluLookAt(sx ,sy,-6.00,sx + 2*sin(up_sider),sy + 2*cos(up_sider) ,-5.3,0,0,-1); } if(FLAG==6) { gluLookAt(tx,ty,-4.5,r_tx ,r_ty,-4.5,0,0,-1); } if(FLAG==7) { gluLookAt(car1x - 3*cos(temp1),car1y - 3*sin(temp1) ,-5.5,car1x + 5*cos(temp1) ,car1y + 5*sin(temp1) ,-4,0,0,-1); } glPushMatrix(); glColor3f(1.0,1.0,1.0); glTranslatef(0,0,-4); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,texture_id[1]); // glTexCoord2i(0,0); // glEnable(GL_TEXTURE_2D); glBegin(GL_QUADS); // glEnable(GL_TEXTURE_2D); // glBindTexture(GL_TEXTURE_2D,texture_id[1]); for(i=-200; i<200; i++) { for(p=-200; p<200; p++) { glTexCoord2i(0,0); glVertex3f(i,p,0.0); glTexCoord2i(1,0); glVertex3f(i+1,p,0.0); glTexCoord2i(1,1); glVertex3f(i+1,p+1,0.0); glTexCoord2i(0,1); glVertex3f(i,p+1,0.0); } } // glDisable(GL_TEXTURE_2D); glEnd(); glDisable(GL_TEXTURE_2D); car(); car1(); glPushMatrix(); sun(); // ******new track formation*********** glColor3f(1.0,1.0,1.0); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,texture_id[2]); // glEnable(GL_TEXTURE_2D); glBegin(GL_QUADS); // glBindTexture(GL_TEXTURE_2D,texture_id[2]); glTexCoord2i(0,0); glVertex3f(-17.0,-27.0,-0.1); glTexCoord2i(0,1); glVertex3f(-11.0,-27.0,-0.1); glTexCoord2i(1,1); glVertex3f(-11.0,20.0,-0.1); glTexCoord2i(1,0); glVertex3f(-17.0,20.0,-0.1); glTexCoord2i(0,0); glVertex3f(-14.0,-13.0,-0.05); glTexCoord2i(0,1); glVertex3f(-14.0,-7.0,-0.05); glTexCoord2i(1,1); glVertex3f(10.0,-7.0,-0.05); glTexCoord2i(1,0); glVertex3f(10.0,-13.0,-0.05); /// elvated roof //****upper surface***** glColor3f(0.0,0.0,0.0); glVertex3f(-8.0,-12.5,-3.1); glVertex3f(-8.0,-7.5,-3.1); glVertex3f(7.0,-7.5,-3.1); glVertex3f(7.0,-12.5,-3.1); //*****side surfaces***** glVertex3f(-8.0,-7,-0.1); glVertex3f(-8.0,-7.5,-3.1); glVertex3f(7.0,-7.5,-3.1); glVertex3f(7.0,-7,-0.1); glVertex3f(-8.0,-13,-0.1); glVertex3f(-8.0,-12.5,-3.1); glVertex3f(7.0,-12.5,-3.1); glVertex3f(7.0,-13,-0.1); ///done glColor3f(1.0,1.0,1.0); glTexCoord2i(0,0); glVertex3f(16.0,-7.3,-0.1); glTexCoord2i(0,1); glVertex3f(10.0,-7.3,-0.1); glTexCoord2i(1,1); glVertex3f(10.0,20.4,-0.1); glTexCoord2i(1,0); glVertex3f(16.0,20.4,-0.1); glTexCoord2i(0,0); glVertex3f(16.0,20,-0.1); glTexCoord2i(0,1); glVertex3f(16.0,26.0,-0.1); glTexCoord2i(1,1); glVertex3f(26.0,26.0,-0.1); glTexCoord2i(1,0); glVertex3f(26.0,20.0,-0.1); glTexCoord2i(0,0); glVertex3f(29.0,20,-0.1); glTexCoord2i(0,1); glVertex3f(23.0,20.0,-0.1); glTexCoord2i(1,1); glVertex3f(23.0,-30.0,-0.1); glTexCoord2i(1,0); glVertex3f(29.0,-30.0,-0.1); glTexCoord2i(0,0); glVertex3f(23.0,-30,-0.1); glTexCoord2i(0,1); glVertex3f(23.0,-24,-0.1); glTexCoord2i(1,1); glVertex3f(-12.0,-24.0,-0.1); glTexCoord2i(1,0); glVertex3f(-12.0,-30.0,-0.1); glEnd(); glColor3f(0.0,0.0,0.0); glDisable(GL_TEXTURE_2D); glPushMatrix(); //turn glTranslatef(-14.0,-10.0,-0.01); glBegin(GL_TRIANGLE_FAN); for(i=0; i<360; i++) { glVertex3f(6*cos(i*3.14/180),6*sin(i*3.14/180),-0.0); } glEnd(); glPopMatrix(); glPushMatrix(); //turn glTranslatef(10.0,-7.0,-0.01); glBegin(GL_TRIANGLE_FAN); for(i=0; i<180; i++) { glVertex3f(6*cos(i*3.14/180),-6*sin(i*3.14/180),-0.0); } glEnd(); glPopMatrix(); glPushMatrix(); //turn glTranslatef(16.0,20.0,-0.01); glBegin(GL_TRIANGLE_FAN); for(i=0; i<180; i++) { glVertex3f(-6*cos(i*3.14/180),6*sin(i*3.14/180),-0.0); } glEnd(); glPopMatrix(); glPushMatrix(); //turn glTranslatef(26.0,20.3,-0.01); glBegin(GL_TRIANGLE_FAN); for(i=0; i<180; i++) { glVertex3f(6*cos(i*3.14/180),-6*sin(i*3.14/180),-0.0); } glEnd(); glPopMatrix(); glPushMatrix(); //turn glTranslatef(26.0,25.7,-0.01); glBegin(GL_TRIANGLE_FAN); for(i=0; i<180; i++) { glVertex3f(-6*cos(i*3.14/180),6*sin(i*3.14/180),-0.0); } glEnd(); glPopMatrix(); glPushMatrix(); //turn glTranslatef(-11.0,-26,-0.01); glBegin(GL_TRIANGLE_FAN); for(i=0; i<180; i++) { glVertex3f(6*cos(i*3.14/180),-6*sin(i*3.14/180),-0.0); } glEnd(); glPopMatrix(); glLineWidth(5.0); glPushMatrix(); glTranslatef(10.0,-30.0,-0.01); while(M<6.0) { glBegin(GL_LINE_LOOP); for(i=0; i<180; i++) { glVertex3f((13+M)*cos(i*3.14/180),-(13+M)*sin(i*3.14/180),0.0); } glEnd(); M = M + .005; } glPopMatrix(); M=0; glLineWidth(1.0); // glTranslatef(0,0,-4); glPopMatrix(); //glRotatef(-60,1,0,0); //glRotatef(t,0,0,1); glPopMatrix(); // pc(); //t+=0.01; glutSwapBuffers(); }
int main(void) { asteroids.lives = START_LIVES; asteroids.display = NULL; asteroids.timer = NULL; asteroids.event_queue = NULL; SHIP *ship; bool redraw = true; bool quit = false; bool key[7] = { false }; seed_rand(); atexit(shutdown); if(!init()) exit(EXIT_FAILURE); if((asteroids.high_score = get_config_value("high_score")) == NULL) asteroids.high_score = "0"; asteroids.level = level_create(0, 0); if(!(ship = ship_create())) exit(EXIT_FAILURE); al_flip_display(); al_start_timer(asteroids.timer); while(!quit) { ALLEGRO_EVENT ev; al_wait_for_event(asteroids.event_queue, &ev); if(ev.type == ALLEGRO_EVENT_TIMER) { /* start game */ if(asteroids.level->number == 0 && key[KEY_S]) { start(); continue; } /* are we out of asteroids to destroy? */ if(list_length(asteroids.level->asteroids) == 0) asteroids.level = level_next(asteroids.level); /* update objects */ ship = ship_update(ship, key, asteroids.timer); explosions_update(); asteroids.level = level_update(asteroids.level, ship, key, asteroids.timer); /* ship->asteroid collisions. */ check_ship_asteroid_collisions(ship, asteroids.level->asteroids); /* ship[missile] -> asteroid collisions. */ check_ship_missile_asteroid_collisions(asteroids.level, ship); /* ship[missile] -> saucer collisions. */ check_ship_missile_saucer_collisions(asteroids.level, ship); /* saucer[missile] -> ship collisions. */ check_saucer_missile_ship_collisions(asteroids.level, ship); /* saucer[missile] -> asteroid collisions. */ check_saucer_missile_asteroids_collisions(asteroids.level); /* saucer->asteroid collisions. */ check_saucer_asteroid_collisions(asteroids.level); redraw = true; } else if(ev.type == ALLEGRO_EVENT_KEY_DOWN) { keydown(ev, key); quit = key[KEY_ESCAPE]; } else if(ev.type == ALLEGRO_EVENT_KEY_UP) { keyup(ev, key); ship->fire_debounce = key[KEY_SPACE]; ship->hyper_debounce = key[KEY_LCONTROL]; } if(redraw && al_is_event_queue_empty(asteroids.event_queue)) { redraw = false; al_clear_to_color(al_map_rgb(BLACK)); level_draw(asteroids.level); draw_lives(); draw_high_score(); animation_draw_list(asteroids.explosions); if(asteroids.level->number == 0) { draw_home(); al_flip_display(); continue; } if(asteroids.lives > 0) { ship_draw(ship, key[KEY_UP]); missile_draw_list(ship->missiles); } else { if(ship->explosion) ship_draw(ship, false); draw_gameover(); } al_flip_display(); } }; /* FIXME: cleanup */ if(asteroids.timer != NULL) al_destroy_timer(asteroids.timer); if(asteroids.event_queue != NULL) al_destroy_event_queue(asteroids.event_queue); if(asteroids.display != NULL) al_destroy_display(asteroids.display); LIST *head = list_first(asteroids.level->asteroids); while(head != NULL) { ASTEROID *rock = (ASTEROID *) head->data; asteroid_free(rock); head = head->next; } ship_free(ship); al_destroy_bitmap(asteroids.lives_sprite); ship_shutdown(); missile_shutdown(); asteroid_shutdown(); explosion_shutdown(); al_uninstall_keyboard(); exit(EXIT_SUCCESS); }
// The main Allegro loop, all input handling, animation and drawing is done here _Bool main_loop(void) { // Flag for drawing _Bool needredraw = true; // Declare primitive data types float old_time = 0.0, current_time = 0, dt = 0; while(!data->exit) { if(needredraw && al_event_queue_is_empty(data->queue) && al_event_queue_is_empty(data->queue2)) { // Clear, draw, flip al_clear_to_color(data->background_color); render(); if(get_fps_status()) al_draw_textf(data->font, data->text_color, 0, res_height-30, 0, "fps: %.2f", 1/dt); al_flip_display(); needredraw = false; } // Block until an event enters the queue al_wait_for_event(data->queue, &(data->event)); while(!al_event_queue_is_empty(data->queue2)) { al_get_next_event(data->queue2, &(data->event2)); switch(data->event2.type) { case ALLEGRO_EVENT_DISPLAY_CLOSE: { // If x button is pressed on window data->exit = true; data->gamestarted = false; } break; case ALLEGRO_EVENT_DISPLAY_RESIZE: { al_acknowledge_resize(data->event2.display.source); scale(res_width, res_height); } break; case ALLEGRO_EVENT_MOUSE_AXES: { // Stores the mouse's new position and change in position mouseaxes(&(data->event2.mouse)); } case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN: { // Stores the mouse button pressed mousedown(&(data->event2.mouse)); } break; case ALLEGRO_EVENT_MOUSE_BUTTON_UP: { // Stores the mouse button released mouseup(&(data->event2.mouse)); } break; case ALLEGRO_EVENT_KEY_DOWN: { // Stores keydown keycode into keycode array for processing keydown(&(data->event2.keyboard)); } break; case ALLEGRO_EVENT_KEY_UP: { // Stores keycode into keycode array for processing keyup(&(data->event2.keyboard)); } break; default: break; } } switch (data->event.type) { case ALLEGRO_EVENT_TIMER: { // Determine the change in time between frames, in seconds current_time = al_current_time(); dt = current_time-old_time; // If the computer lags for some reason, don't penalize the player // Cap dt at 0.5 seconds if(dt > 0.25) { dt = 0.25; } // Handle Mouse and Keyboard events and Button Events buttoncheck(&buttonhandler, data); keycheck(&keyhandler, data); mousecheck(&mousehandler, data); keyupdate(); mouseupdate(); // Check if data->quit has been set before updating and drawing if(data->exit) break; // Update the game, always update(); // Skip drawing frames if computer lags if(current_time - data->event.timer.timestamp <= 1.0/al_get_display_refresh_rate(data->display)) { needredraw = true; } // Make the time at this frame the old time, for the next frame old_time = current_time; } break; default: break; } } return true; }
static void g15_process_keys(g15daemon_t *masterlist, unsigned int currentkeys, unsigned int lastkeys) { /* 'G' keys */ if((currentkeys & G15_KEY_G1) && !(lastkeys & G15_KEY_G1)) keydown(GKEY_OFFSET); else if(!(currentkeys & G15_KEY_G1) && (lastkeys & G15_KEY_G1)) keyup(GKEY_OFFSET); if((currentkeys & G15_KEY_G2) && !(lastkeys & G15_KEY_G2)) keydown(GKEY_OFFSET+1); else if(!(currentkeys & G15_KEY_G2) && (lastkeys & G15_KEY_G2)) keyup(GKEY_OFFSET+1); if((currentkeys & G15_KEY_G3) && !(lastkeys & G15_KEY_G3)) keydown(GKEY_OFFSET+2); else if(!(currentkeys & G15_KEY_G3) && (lastkeys & G15_KEY_G3)) keyup(GKEY_OFFSET+2); if((currentkeys & G15_KEY_G4) && !(lastkeys & G15_KEY_G4)) keydown(GKEY_OFFSET+3); else if(!(currentkeys & G15_KEY_G4) && (lastkeys & G15_KEY_G4)) keyup(GKEY_OFFSET+3); if((currentkeys & G15_KEY_G5) && !(lastkeys & G15_KEY_G5)) keydown(GKEY_OFFSET+4); else if(!(currentkeys & G15_KEY_G5) && (lastkeys & G15_KEY_G5)) keyup(GKEY_OFFSET+4); if((currentkeys & G15_KEY_G6) && !(lastkeys & G15_KEY_G6)) keydown(GKEY_OFFSET+5); else if(!(currentkeys & G15_KEY_G6) && (lastkeys & G15_KEY_G6)) keyup(GKEY_OFFSET+5); if((currentkeys & G15_KEY_G7) && !(lastkeys & G15_KEY_G7)) keydown(GKEY_OFFSET+6); else if(!(currentkeys & G15_KEY_G7) && (lastkeys & G15_KEY_G7)) keyup(GKEY_OFFSET+6); if((currentkeys & G15_KEY_G8) && !(lastkeys & G15_KEY_G8)) keydown(GKEY_OFFSET+7); else if(!(currentkeys & G15_KEY_G8) && (lastkeys & G15_KEY_G8)) keyup(GKEY_OFFSET+7); if((currentkeys & G15_KEY_G9) && !(lastkeys & G15_KEY_G9)) keydown(GKEY_OFFSET+8); else if(!(currentkeys & G15_KEY_G9) && (lastkeys & G15_KEY_G9)) keyup(GKEY_OFFSET+8); if((currentkeys & G15_KEY_G10) && !(lastkeys & G15_KEY_G10)) keydown(GKEY_OFFSET+9); else if(!(currentkeys & G15_KEY_G10) && (lastkeys & G15_KEY_G10)) keyup(GKEY_OFFSET+9); if((currentkeys & G15_KEY_G11) && !(lastkeys & G15_KEY_G11)) keydown(GKEY_OFFSET+10); else if(!(currentkeys & G15_KEY_G11) && (lastkeys & G15_KEY_G11)) keyup(GKEY_OFFSET+10); if((currentkeys & G15_KEY_G12) && !(lastkeys & G15_KEY_G12)) keydown(GKEY_OFFSET+11); else if(!(currentkeys & G15_KEY_G12) && (lastkeys & G15_KEY_G12)) keyup(GKEY_OFFSET+11); if((currentkeys & G15_KEY_G13) && !(lastkeys & G15_KEY_G13)) keydown(GKEY_OFFSET+12); else if(!(currentkeys & G15_KEY_G13) && (lastkeys & G15_KEY_G13)) keyup(GKEY_OFFSET+12); if((currentkeys & G15_KEY_G14) && !(lastkeys & G15_KEY_G14)) keydown(GKEY_OFFSET+13); else if(!(currentkeys & G15_KEY_G14) && (lastkeys & G15_KEY_G14)) keyup(GKEY_OFFSET+13); if((currentkeys & G15_KEY_G15) && !(lastkeys & G15_KEY_G15)) keydown(GKEY_OFFSET+14); else if(!(currentkeys & G15_KEY_G15) && (lastkeys & G15_KEY_G15)) keyup(GKEY_OFFSET+14); if((currentkeys & G15_KEY_G16) && !(lastkeys & G15_KEY_G16)) keydown(GKEY_OFFSET+15); else if(!(currentkeys & G15_KEY_G16) && (lastkeys & G15_KEY_G16)) keyup(GKEY_OFFSET+15); if((currentkeys & G15_KEY_G17) && !(lastkeys & G15_KEY_G17)) keydown(GKEY_OFFSET+16); else if(!(currentkeys & G15_KEY_G17) && (lastkeys & G15_KEY_G17)) keyup(GKEY_OFFSET+16); if((currentkeys & G15_KEY_G18) && !(lastkeys & G15_KEY_G18)) keydown(GKEY_OFFSET+17); else if(!(currentkeys & G15_KEY_G18) && (lastkeys & G15_KEY_G18)) keyup(GKEY_OFFSET+17); /* 'M' keys */ if((currentkeys & G15_KEY_M1) && !(lastkeys & G15_KEY_M1)) keydown(MKEY_OFFSET); else if(!(currentkeys & G15_KEY_M1) && (lastkeys & G15_KEY_M1)) keyup(MKEY_OFFSET); if((currentkeys & G15_KEY_M2) && !(lastkeys & G15_KEY_M2)) keydown(MKEY_OFFSET+1); else if(!(currentkeys & G15_KEY_M2) && (lastkeys & G15_KEY_M2)) keyup(MKEY_OFFSET+1); if((currentkeys & G15_KEY_M3) && !(lastkeys & G15_KEY_M3)) keydown(MKEY_OFFSET+2); else if(!(currentkeys & G15_KEY_M3) && (lastkeys & G15_KEY_M3)) keyup(MKEY_OFFSET+2); if((currentkeys & G15_KEY_MR) && !(lastkeys & G15_KEY_MR)) keydown(MKEY_OFFSET+3); else if(!(currentkeys & G15_KEY_MR) && (lastkeys & G15_KEY_MR)) keyup(MKEY_OFFSET+3); if(map_Lkeys){ /* 'L' keys... */ if((currentkeys & G15_KEY_L1) && !(lastkeys & G15_KEY_L1)) keydown(LKEY_OFFSET); else if(!(currentkeys & G15_KEY_L1) && (lastkeys & G15_KEY_L1)) keyup(LKEY_OFFSET); if((currentkeys & G15_KEY_L2) && !(lastkeys & G15_KEY_L2)) keydown(LKEY_OFFSET+1); else if(!(currentkeys & G15_KEY_L2) && (lastkeys & G15_KEY_L2)) keyup(LKEY_OFFSET+1); if((currentkeys & G15_KEY_L3) && !(lastkeys & G15_KEY_L3)) keydown(LKEY_OFFSET+2); else if(!(currentkeys & G15_KEY_L3) && (lastkeys & G15_KEY_L3)) keyup(LKEY_OFFSET+2); if((currentkeys & G15_KEY_L4) && !(lastkeys & G15_KEY_L4)) keydown(LKEY_OFFSET+3); else if(!(currentkeys & G15_KEY_L4) && (lastkeys & G15_KEY_L4)) keyup(LKEY_OFFSET+3); if((currentkeys & G15_KEY_L5) && !(lastkeys & G15_KEY_L5)) keydown(LKEY_OFFSET+4); else if(!(currentkeys & G15_KEY_L5) && (lastkeys & G15_KEY_L5)) keyup(LKEY_OFFSET+4); } }
void window::main_loop() { SDL_Event event; while(true) { while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_KEYDOWN: switch(event.key.keysym.sym) { case SDLK_ESCAPE: exit(0); break; default: keydown(event.key.keysym.sym); break; } break; case SDL_KEYUP: keyup(event.key.keysym.sym); break; case SDL_MOUSEBUTTONDOWN: switch(event.button.button) { case SDL_BUTTON_LEFT: { const float x_screen = static_cast<float>(event.button.x); const float y_screen = static_cast<float>(event.button.y); // scaling from <0,width> to <-1,1> const float x_scaled = 2.0 * (x_screen - static_cast<float>(width) / 2.0) / static_cast<float>(width); const float y_scaled = 2.0 * (y_screen - static_cast<float>(height) / 2.0) / static_cast<float>(height); mousedown(x_scaled, y_scaled); } break; case SDL_BUTTON_WHEELUP: mousewheelup(); break; case SDL_BUTTON_WHEELDOWN: mousewheeldown(); break; } break; case SDL_MOUSEBUTTONUP: if(event.button.button == SDL_BUTTON_LEFT) mouseup(); break; case SDL_MOUSEMOTION: { const float x_screen = static_cast<float>(event.motion.x); const float y_screen = static_cast<float>(event.motion.y); // scaling from <0,width> to <-1,1> const float x_scaled = 2.0 * (x_screen - static_cast<float>(width) / 2.0) / static_cast<float>(width); const float y_scaled = 2.0 * (y_screen - static_cast<float>(height) / 2.0) / static_cast<float>(height); mousemotion(x_scaled, y_scaled); } break; case SDL_VIDEORESIZE: handle_resize(event.resize.w, event.resize.h); break; case SDL_QUIT: exit(0); break; } } frame(); } }
void speed() { int keyboard = _open("/dev/keyboard", 0, 0); int stdin = _open("/dev/stdin", 0, 0); char ch; int fd = _open(active_proc->name, 0, 0); int size = _seek(fd, 0, SEEK_END); size++; //terminating '\0' _seek(fd, 0, SEEK_SET); char* str = _malloc(size); bzero(str, size); _read(fd, str, size); line *startline = _malloc(sizeof(line)); startline->num_chars=0; startline->offset=0; startline->next = NULL; startline->prev = NULL; line * actualline = startline; int pos = 0; while (str[pos]!='\0') { _printf("%c", str[pos]); if(str[pos] == '\n' || str[pos] == '\t') { NEXT_LINE } else { actualline->num_chars++; } pos++; if(pos == size - 1) { //terminating \0 size*=2; str = resize_buf(size, str); } } _close(fd); //flush stdin while (_read(stdin, &ch, sizeof(ch)) != 0) ; while (!keydown(ESCAPE, keyboard)) { if(pos == size - 1) { //terminating \0 size *= 2; str = resize_buf(size, str); } ch = _fgetch(stdin); switch(ch){ case '\a': break; case '\b': if(actualline == startline && startline->num_chars == 0) { //nothing to erase break; } if(str[pos - 1]=='\n' || str[pos - 1]=='\t') { //erase '\n' or '\t' PREV_LINE } else { //erase 1 character actualline->num_chars--; _printf("%c", ch); } str[--pos] = '\0'; if (pos == size / 4 - 1) { size /= 2; str = resize_buf(size, str); } break; default: _printf("%c", ch); str[pos] = ch; if(ch == '\n' || ch == '\t') { NEXT_LINE } else { actualline->num_chars++; } pos++; } } //flush stdin while (_read(stdin, &ch, sizeof(ch)) != 0) ; //DUMP_LINES _unlink(active_proc->name); // fd = _open(active_proc->name, 0, 0); // int fsize = _seek(fd, 0, SEEK_END); // _close(fd); // fd = _open(active_proc->name, 0, 0); // char* nullstring = _malloc(fsize); // bzero(nullstring, fsize); // _free(nullstring); // _write(fd, nullstring, fsize); // _close(fd); fd = _open(active_proc->name, O_CREAT, 0); _write(fd, str, strlen(str)); for(line *temp = startline; temp != NULL; temp = temp->next) { _free(temp); } _free(str); _close(keyboard); _close(stdin); _close(fd); _exit(0); }
void Object::sys_keydown(unsigned char key, int x, int y){ if(chk_hit(x,y)){ keydown(key,x,y); } }
int handleEvent(SDL_Event *event, GameObjectData *gameObjectData, UIData *uiData, ControlsData *controlsData, GraphicsData *graphicsData){ uiData->event = event; switch (event->type) { /* Closing the Window will exit the program */ case SDL_WINDOWEVENT: switch (event->window.event){ case SDL_WINDOWEVENT_RESIZED: UIRoot_Execute(uiData,WINDOW_RESIZE,0); break; } break; case SDL_MOUSEMOTION: UIRoot_Execute(uiData,MOTION,0); break; case SDL_MOUSEBUTTONDOWN: if(isMouseFree(controlsData)){ /* We only want to catch new mouse clicks if the mouse is not having a button held down */ /* trust me */ if(event->button.button == SDL_BUTTON_LEFT){ UIRoot_ExecuteUpwards(uiData,LEFT_CLICK,1); selectGameObject(gameObjectData,graphicsData,event); } else if(event->button.button == SDL_BUTTON_RIGHT){ UIRoot_ExecuteUpwards(uiData,RIGHT_CLICK,1); } } break; case SDL_MOUSEBUTTONUP: if(event->button.button == SDL_BUTTON_LEFT){ UIRoot_Execute(uiData,LEFT_RELEASE,0); controlsData->mouseButtons[LEFT_CLICK_BUTTON] = 0; } else if(event->button.button == SDL_BUTTON_RIGHT){ UIRoot_Execute(uiData,RIGHT_RELEASE,0); controlsData->mouseButtons[RIGHT_CLICK_BUTTON] = 0; } break; case SDL_KEYDOWN: return keydown(controlsData,gameObjectData, graphicsData, uiData,event); break; case SDL_KEYUP: return keyup(controlsData,gameObjectData, uiData,event); break; case SDL_QUIT: return 0; case SDL_MOUSEWHEEL: UIRoot_Execute(uiData,MOUSEWHEEL,0); break; default: if(gameObjectData->gameOverEventNum == event->type){ UIRoot_Execute(uiData,GAME_OVER,0); }else if(gameObjectData->objectDisplayEventNum == event->type){ UIRoot_Execute(uiData,OBJECT_DISPLAY,0); } break; } return 1; }
void viewer::update(const float delta_time) { const float speed = 0.001; if(keydown('w')) { offx -= cosf(rot_x) * sinf(rot_y) * speed * delta_time; offz += cosf(rot_x) * cosf(rot_y) * speed * delta_time; offy += sinf(rot_x) * speed * delta_time; } if(keydown('s')) { offx += cosf(rot_x) * sinf(rot_y) * speed * delta_time; offz -= cosf(rot_x) * cosf(rot_y) * speed * delta_time; offy -= sinf(rot_x) * speed * delta_time; } if(keydown('a')) { offx += cosf(rot_y) * speed * delta_time; offz += sinf(rot_y) * speed * delta_time; } if(keydown('d')) { offx -= cosf(rot_y) * speed * delta_time; offz -= sinf(rot_y) * speed * delta_time; } const float rot_speed = 0.0005; if(keydown('q')) rot_y -= rot_speed * delta_time; if(keydown('e')) rot_y += rot_speed * delta_time; if(keydown('z')) rot_x -= rot_speed * delta_time; if(keydown('x')) rot_x += rot_speed * delta_time; if(keydown('c')) rot_z -= rot_speed * delta_time; if(keydown('v')) rot_z += rot_speed * delta_time; if(mouse_click) { const float mouse_rot_speed = 0.001; rot_y += mouse_move_x * mouse_rot_speed * delta_time; rot_x += mouse_move_y * mouse_rot_speed * delta_time; } if(keydown('1')) active_shader_set = ShaderSet::all_white; if(keydown('2')) active_shader_set = ShaderSet::normals; if(keydown('3')) active_shader_set = ShaderSet::height_map; }