Exemple #1
0
void main_loop(void *data) {
  MainLoopData* loopData = (MainLoopData*)data;
  // TODO use registry to get love.update and love.draw?

  chdir("love");

  timer_step();
  graphics_clear();
  matrixstack_origin();
  lua_rawgeti(loopData->luaState, LUA_REGISTRYINDEX, loopData->errhand);
  lua_getglobal(loopData->luaState, "love");
  lua_pushstring(loopData->luaState, "update");

  lua_rawget(loopData->luaState, -2);
  lua_pushnumber(loopData->luaState, timer_getDelta());
  pcall(loopData->luaState, 1);

  lua_pushstring(loopData->luaState, "draw");
  lua_rawget(loopData->luaState, -2);

  pcall(loopData->luaState, 0);

  graphics_DisplayState curState = *graphics_getState();
  matrixstack_push();

  mouse_cursor_draw();

  matrixstack_pop();
  graphics_setState(&curState);

  graphics_swap();

  lua_pop(loopData->luaState, 1);

  SDL_Event event;
  while(SDL_PollEvent(&event)) {
    switch(event.type) {
    case SDL_KEYDOWN:
      keyboard_keypressed(event.key.keysym.sym);
      break;
    case SDL_KEYUP:
      keyboard_keyreleased(event.key.keysym.sym);
      break;
    case SDL_TEXTINPUT:
      keyboard_textInput(event.text.text);
      break;
    case SDL_MOUSEMOTION:
      mouse_mousemoved(event.motion.x, event.motion.y);
      break;
    case SDL_MOUSEBUTTONDOWN:
      mouse_mousepressed(event.button.x, event.button.y, event.button.button);
      break;
    case SDL_MOUSEBUTTONUP:
      mouse_mousereleased(event.button.x, event.button.y, event.button.button);
      break;
    case SDL_JOYDEVICEADDED:
      joystick_deviceAdded(event.jdevice.which);
      break;
    case SDL_JOYDEVICEREMOVED:
      joystick_deviceRemoved(event.jdevice.which);
      break;
    case SDL_JOYBUTTONUP:
      joystick_buttonReleased(event.jbutton.which, event.jbutton.button);
      break;
    case SDL_JOYBUTTONDOWN:
      joystick_buttonPressed(event.jbutton.which, event.jbutton.button);
      break;
    case SDL_JOYAXISMOTION:
      joystick_axisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value);
      break;
    case SDL_CONTROLLERBUTTONUP:
      joystick_controllerButtonReleased(event.jbutton.which, event.jbutton.button);
      break;
    case SDL_CONTROLLERBUTTONDOWN:
      joystick_controllerButtonPressed(event.jbutton.which, event.jbutton.button);
      break;
    case SDL_CONTROLLERAXISMOTION:
      joystick_controllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value);
      break;


#ifndef EMSCRIPTEN
    case SDL_QUIT:
      exit(0);
#endif
    }
  }

  audio_updateStreams();
  //lua_gc(loopData->luaState, LUA_GCCOLLECT, 0);
}
Exemple #2
0
void _qdgdfv_input_poll(void)
{
    keyboard_update();

    _qdgdfv_key_up = keyboard_keypressed(0x48);
    _qdgdfv_key_down = keyboard_keypressed(0x50);
    _qdgdfv_key_left = keyboard_keypressed(0x4b);
    _qdgdfv_key_right = keyboard_keypressed(0x4d);
    _qdgdfv_key_escape = keyboard_keypressed(0x01);
    _qdgdfv_key_space = keyboard_keypressed(0x39);
    _qdgdfv_key_enter = keyboard_keypressed(0x1c);
    _qdgdfv_key_control = keyboard_keypressed(0x1d);
    _qdgdfv_key_shift_l = keyboard_keypressed(0x2a);
    _qdgdfv_key_shift_r = keyboard_keypressed(0x36);
    _qdgdfv_key_pgup = keyboard_keypressed(0x49);
    _qdgdfv_key_pgdn = keyboard_keypressed(0x51);
    _qdgdfv_key_home = keyboard_keypressed(0x47);
    _qdgdfv_key_end = keyboard_keypressed(0x4f);

    _qdgdfv_key_f1 = keyboard_keypressed(0x3b);
    _qdgdfv_key_f2 = keyboard_keypressed(0x3c);
    _qdgdfv_key_f3 = keyboard_keypressed(0x3d);
    _qdgdfv_key_f4 = keyboard_keypressed(0x3e);
    _qdgdfv_key_f5 = keyboard_keypressed(0x3f);
    _qdgdfv_key_f6 = keyboard_keypressed(0x40);
    _qdgdfv_key_f7 = keyboard_keypressed(0x41);
    _qdgdfv_key_f8 = keyboard_keypressed(0x42);
    _qdgdfv_key_f9 = keyboard_keypressed(0x43);
    _qdgdfv_key_f10 = keyboard_keypressed(0x44);
}
Exemple #3
0
int player::move(){// obsluguje klawiature by sprawdzic co gracz chce zrobic
	bomba* b=0;
	int i=0;
	action a=none;

	if(!object::counter--){
		object::counter=speed;
/*	switch(getchar()){
		case 'w': a=p.move(up); face=down; break;
		case 'd': a=p.move(right); face=left; break;
		case 's': a=p.move(down); face=up; break;
		case 'a': a=p.move(left); face=right; break;
		case 'q': if(bombs && (b=p.spawnbomb(this,range))){
				  bombs--;
				  b->setid(list.add(b));
			  }
			  break;
	}*/
/**/		if(keyboard_keypressed(k.bomb) && bombs && (b=p.spawnbomb(this,range))){
			bombs--;
			b->setid(list.add(b)); // dodaje bombe do swojej listy bomb
/**/			mvprintw(40,90,"d");
			return none;
		 }
	}
		//else{
	/**/	mvprintw(40+x,90+y," ");
/**/			if(keyboard_keypressed(k.up)){
				if ( (--y) <= -speed ){ 
					a=p.move(up);
					y = speed;
				}
			}
/**/			else if(keyboard_keypressed(k.right)){
				if ( (++x) >= speed ){
					a=p.move(right);
					x = -speed;
				}
			}
/**/			else if(keyboard_keypressed(k.down)){
				if ( (++y) >= speed ){ 
					a=p.move(down);
					y = -speed;
				}
/**/			}
			else if(keyboard_keypressed(k.left)){
				if ( (--x) <= -speed ){
					a=p.move(left);
					x = speed;
				}
			}
	/**/	mvprintw(40+x,90+y,"*");

		if(a==kill)
			return kill;

	//}
//przelatuje cala liste bomb i sprawdza czy powinne juz wybuchnac, jezeli tak to ja wysadza
	while(b =list[i++]){
		if(!b->count()){ 
			b->setid(-1);
			list.remove(i-1);
			bombs++;
		}
		b->move();
	}
	if(a)
/**/	mvprintw(40,90,"%d",a);
	return (int)a;
}
void main(void)
{
    struct timeval timeout;
    fd_set inputs;
    char bitmap[16 * 16 * 4];	/* big enough for 10x10 bitmap in any mode */
    int vgamode, color, pipefd[2], x, y, button, event, cursorsize = 5;
    char loop = 1, drawcursor = 1;
#ifdef USE_RAWKEYBOARD
    char space_pressed = 0;
#endif

    puts("This is a demo showing the abilities of the new vga_waitevent() function\n"
	 "If something goes wrong it might hang your machine. Thus hit <ctrl>-C now\n"
	 "to bailout if in doubt.\n"
	 "Use mouse to move cursor. 1-9,0 to set the cursor size. Space to change the\n"
    "cursor color. Left button to draw. Right button or 'Q' to bailout.\n"
	 "The cursor goes on/off every half second by usage of a timeout passed to\n"
	 "vga_waitevent. Every 5 secs a string from a child process (the time) arrives\n"
	 "asynchronously and is displayed by the frontend.");
#ifdef USE_RAWKEYBOARD
    puts("\nBEWARE! This has been compiled to use the raw keyboard. A crash might\n"
	 "render the console unusable. (but shouldn't).");
#endif
    fputs("\nHit <Enter> if brave enough, else ^C to bailout: ", stdout);
    fflush(stdout);
    getchar();
    fflush(stdin);		/* clear I/O buffer */

    pipe(pipefd);
    if (fork() == 0) {		/* fork off b4 touching graphix to avoid side effects */
	close(pipefd[0]);	/* Important: close reading side, else it remains     */
	/* opened by child when parent exits and we don't get */
	/* a SIGPIPE!                                         */
	child(pipefd[1]);
    }
    vga_init();
    vgamode = vga_getdefaultmode();
    if (vgamode == -1)
	vgamode = G320x200x256;

    if (!vga_hasmode(vgamode)) {
	printf("Mode not available.\n");
	exit(-1);
    }
    /* Enable automatic mouse setup at mode set. */
    vga_setmousesupport(1);
    vga_setmode(vgamode);
    /* Disable wrapping (default). */
    /* mouse_setwrap(MOUSE_NOWRAP); */
    gl_setcontextvga(vgamode);
    gl_enableclipping();

    /* There might be some scrap data in the serial buffer
       from the mouse. It will make vga_waitevent block
       because it thinks the mouse wants to send data but
       then no mouse packet arrives. */
    color = newcolor();
    x = 0;
    y = 0;
    gl_setwritemode(WRITEMODE_OVERWRITE | FONT_COMPRESSED);
    gl_setfont(8, 8, gl_font8x8);
    gl_setfontcolors(0, newcolor());

#ifdef USE_RAWKEYBOARD
    if (keyboard_init()) {
	printf("Could not initialize keyboard.\n");
	exit(1);
    }
#endif

    while (loop) {
	gl_getbox(x, y, 10, 10, bitmap);
	if (drawcursor) {
	    gl_hline(x, y, x + cursorsize, color);
	    gl_hline(x, y + cursorsize, x + cursorsize, color);
	    gl_line(x, y, x, y + cursorsize, color);
	    gl_line(x + cursorsize, y, x + cursorsize, y + cursorsize, color);
	}
	FD_ZERO(&inputs);
	FD_SET(pipefd[0], &inputs);
	timeout.tv_sec = 0;
	timeout.tv_usec = 500000;	/* 0.5 second time out */
	event = vga_waitevent(VGA_MOUSEEVENT | VGA_KEYEVENT,
			      &inputs, NULL, NULL, &timeout);
	gl_putbox(x, y, 10, 10, bitmap);
	if (timeout.tv_sec || timeout.tv_usec) {
	    /* No timeout. An actual event occured. Reset to visible
	       cursor. Note:
	       This is actually a bug as the cursor will get visible on time
	       updates. However, it's better this way for demo/test
	       purposes. */
	    drawcursor = 1;
	} else {
	    drawcursor ^= 1;
	}
	if (FD_ISSET(pipefd[0], &inputs))
	    process_input(pipefd[0]);
	if (event & VGA_MOUSEEVENT) {
	    x = mouse_getx();
	    y = mouse_gety();
	    button = mouse_getbutton();
	    if (button & MOUSE_LEFTBUTTON)
		gl_fillbox(x, y, cursorsize + 1, cursorsize + 1, color);
	    if (button & MOUSE_RIGHTBUTTON)
		loop = 0;
	}
	if (event & VGA_KEYEVENT) {
#ifdef USE_RAWKEYBOARD
	    if (keyboard_keypressed(SCANCODE_1))
		cursorsize = 0;
	    if (keyboard_keypressed(SCANCODE_2))
		cursorsize = 1;
	    if (keyboard_keypressed(SCANCODE_3))
		cursorsize = 2;
	    if (keyboard_keypressed(SCANCODE_4))
		cursorsize = 3;
	    if (keyboard_keypressed(SCANCODE_5))
		cursorsize = 4;
	    if (keyboard_keypressed(SCANCODE_6))
		cursorsize = 5;
	    if (keyboard_keypressed(SCANCODE_7))
		cursorsize = 6;
	    if (keyboard_keypressed(SCANCODE_8))
		cursorsize = 7;
	    if (keyboard_keypressed(SCANCODE_9))
		cursorsize = 8;
	    if (keyboard_keypressed(SCANCODE_0))
		cursorsize = 9;
	    if (keyboard_keypressed(SCANCODE_Q))
		loop = 0;
	    if (keyboard_keypressed(SCANCODE_SPACE)) {
		if (!space_pressed) {
		    color = newcolor();
		    space_pressed = 1;
		}
	    } else {
		space_pressed = 0;
	    }
#else
	    switch (vga_getch()) {
	    case '1':
		cursorsize = 0;
		break;
	    case '2':
		cursorsize = 1;
		break;
	    case '3':
		cursorsize = 2;
		break;
	    case '4':
		cursorsize = 3;
		break;
	    case '5':
		cursorsize = 4;
		break;
	    case '6':
		cursorsize = 5;
		break;
	    case '7':
		cursorsize = 6;
		break;
	    case '8':
		cursorsize = 7;
		break;
	    case '9':
		cursorsize = 8;
		break;
	    case '0':
		cursorsize = 9;
		break;
	    case ' ':
		color = newcolor();
		break;
	    case 'q':
	    case 'Q':
		loop = 0;
		break;
	    default:
		ping();
		break;
	    }
#endif
	}
    }

#ifdef USE_RAWKEYBOARD
    keyboard_close();		/* Don't forget this! */
#endif
    vga_setmode(TEXT);
    exit(0);
}
Exemple #5
0
void main_loop(void *data) {
  MainLoopData* loopData = (MainLoopData*)data;

  timer_step();
  lua_rawgeti(loopData->luaState, LUA_REGISTRYINDEX, loopData->errhand);
  lua_getglobal(loopData->luaState, "love");
  lua_pushstring(loopData->luaState, "update");

  lua_rawget(loopData->luaState, -2);
  lua_pushnumber(loopData->luaState, timer_getDelta());
  if (swap_At == 1){
      if(luaL_dofile(loopData->luaState, "main.lua")) {
          printf("Error: %s\n", lua_tostring(loopData->luaState, -1));
        }
    }

  if(lua_pcall(loopData->luaState, 1, 0, 0)) {
      printf("Lua error: %s\n", lua_tostring(loopData->luaState, -1));
#ifdef EMSCRIPTEN
      quit_function(loopData->luaState);
      emscripten_force_exit(1);
#else
      exit(1);
#endif
    }

  graphics_clear();

  lua_pushstring(loopData->luaState, "draw");
  lua_rawget(loopData->luaState, -2);

  if(lua_pcall(loopData->luaState, 0, 0, 0)) {
      printf("Lua error: %s\n", lua_tostring(loopData->luaState, -1));
#ifdef EMSCRIPTEN
      quit_function(loopData->luaState);
      emscripten_force_exit(1);
      l_running = 0;
#else
      l_running = 0;
#endif
    }

  graphics_swap();

  // silly hack for love.event.quit()
#ifdef WINDOWS
  event_force_quit = graphics_stop_windows();
  if(!event_force_quit)
    l_running = 0;
#endif //This will affect only Windows users
  //

  lua_pop(loopData->luaState, 1);
#ifdef UNIX
  SDL_Event event;
  while(SDL_PollEvent(&event)) {
      if (event.type == SDL_WINDOWEVENT) {
          switch (event.window.event) {
            case SDL_WINDOWEVENT_ENTER:
              graphics_setMouseFocus(1);
              break;
            case SDL_WINDOWEVENT_LEAVE:
              graphics_setMouseFocus(0);
              break;
            case SDL_WINDOWEVENT_FOCUS_LOST:
              graphics_setFocus(0);
              break;
            case SDL_WINDOWEVENT_FOCUS_GAINED:
              graphics_setFocus(1);
              break;
            default:
              break;
            }
        }
      switch(event.wheel.type)
        {
        case SDL_MOUSEWHEEL:
          mouse_mousewheel(event.wheel.y);
          int _what = event.wheel.y == 1 ? SDL_BUTTON_WHEEL_UP : SDL_BUTTON_WHEEL_DOWN;
          mouse_mousepressed(event.button.x, event.button.y,
                             _what);
          break;
        default:
          break;
        }
      switch(event.type) {
        case SDL_KEYDOWN:
          keyboard_keypressed(event.key.keysym.sym);
          break;
        case SDL_KEYUP:
          keyboard_keyreleased(event.key.keysym.sym);
          break;
        case SDL_TEXTINPUT:
          keyboard_textInput(event.text.text);
          break;
        case SDL_MOUSEMOTION:
          mouse_mousemoved(event.motion.x, event.motion.y);
          break;
        case SDL_MOUSEBUTTONDOWN:
          mouse_mousepressed(event.button.x, event.button.y,
                             event.button.button);
          break;
        case SDL_MOUSEBUTTONUP:
          mouse_mousereleased(event.button.x, event.button.y,
                              event.button.button);
          break;
#ifndef EMSCRIPTEN
        case SDL_QUIT:
          quit_function(loopData->luaState);
          l_running = 0;
#endif
        }
    }
#endif
}
Exemple #6
0
Intent *read_input_devices(void)
{
     static Intent intent;


     intent.force_x = intent.force_y = intent.force_z = 0.0;
     intent.force_rotate = 0.0;
     intent.n_special = 0;

     keyboard_update();
     if (keyboard_keypressed(SCANCODE_CURSORBLOCKLEFT))
	  rotating_ccw = True;
     if (keyboard_keypressed(SCANCODE_CURSORBLOCKRIGHT))
	  rotating_cw = True;
     if (keyboard_keypressed(SCANCODE_CURSORBLOCKUP))
	  moving_forward = True;
     if (keyboard_keypressed(SCANCODE_CURSORBLOCKDOWN))
	  moving_backward= True;
     if (keyboard_keypressed(42) || keyboard_keypressed(54))
	  running= True;
     if (keyboard_keypressed(57))
	  add_special(&intent, INTENT_JUMP);
     if (keyboard_keypressed(56) || keyboard_keypressed(100))
	  strafing= True;

     if (!keyboard_keypressed(SCANCODE_CURSORBLOCKLEFT))
	  rotating_ccw = False;
     if (!keyboard_keypressed( SCANCODE_CURSORBLOCKRIGHT))
	  rotating_cw = False;
     if (!keyboard_keypressed(SCANCODE_CURSORBLOCKUP))
	  moving_forward = False;
     if (!keyboard_keypressed(SCANCODE_CURSORBLOCKDOWN))
	  moving_backward= False;
     if (!keyboard_keypressed(42) && !keyboard_keypressed(54))
	  running= False;
     if (!keyboard_keypressed(56) && !keyboard_keypressed(100))
	  strafing= False;
     if (keyboard_keypressed(SCANCODE_Q))
	  add_special(&intent, INTENT_END_GAME);

     if (rotating_cw) {
	  if (strafing)
	       intent.force_y -= 0.5;
	  else
	       intent.force_rotate -= 0.5;
     }
     if (rotating_ccw) {
	  if (strafing) {
	       intent.force_y += 0.5;
	  } else
	       intent.force_rotate += 0.5;
     }
     if (moving_forward)
	  intent.force_x += 0.5;
     if (moving_backward)
	  intent.force_x -= 0.5;
     if (running) {
	  intent.force_x *= 2.0;
	  intent.force_y *= 2.0;
	  intent.force_z *= 2.0;
	  intent.force_rotate *= 2.0;
     }

     return &intent;
}
Exemple #7
0
void main(void)
{
    int vgamode, color, leftpressed;
    int x, y;
    vga_init();
    vgamode = vga_getdefaultmode();
    if ((vgamode == -1) || (vga_getmodeinfo(vgamode)->bytesperpixel != 1))
        vgamode = G320x200x256;

    if (!vga_hasmode(vgamode)) {
        printf("Mode not available.\n");
        exit(1);
    }
    printf("\nWARNING: This program will set the keyboard to RAW mode.\n"
           "The keyboard routines in svgalib have not been tested\n"
           "very much. There may be no recovery if something goes\n"
           "wrong.\n\n"
           "Press ctrl-c now to bail out, enter to continue.\n"
           "In the test itself, use 'q' or Escape to quit.\n"
           "It will also terminate after 60 seconds.\n"
           "Use any cursor keys to move, keypad 0 or enter to change color.\n");

    getchar();

    vga_setmode(vgamode);
    gl_setcontextvga(vgamode);
    gl_enableclipping();

    signal(SIGALRM, timeout);

    /* This installs the default handler, which is good enough for most */
    /* purposes. */
    if (keyboard_init()) {
        printf("Could not initialize keyboard.\n");
        exit(1);
    }
    /* Translate to 4 keypad cursor keys, and unify enter key. */
    keyboard_translatekeys(TRANSLATE_CURSORKEYS | TRANSLATE_KEYPADENTER |
                           TRANSLATE_DIAGONAL);
    /* (TRANSLATE_DIAGONAL seems to give problems.) Michael: No doesn't...
       but might not do what you expect.. */

    alarm(60);			/* Terminate after 60 seconds for safety. */

    x = WIDTH / 2;
    y = HEIGHT / 2;
    color = newcolor();
    leftpressed = 0;
    for (;;) {
        /* Draw moving box. */
        gl_fillbox(x, y, 5, 5, color);

        /* Draw key status bar at top of screen. */
        gl_putbox(0, 0, 128, 1, keyboard_getstate());

        /* Wait about 1/100th of a second. */
        /* Note that use of this function makes things less */
        /* smooth because of timer latency. */
        usleep(10000);

        keyboard_update();

        /* Move. */
        if (keyboard_keypressed(SCANCODE_CURSORLEFT))
            x--;
        if (keyboard_keypressed(SCANCODE_CURSORRIGHT))
            x++;
        if (keyboard_keypressed(SCANCODE_CURSORUP))
            y--;
        if (keyboard_keypressed(SCANCODE_CURSORDOWN))
            y++;

        /* Boundary checks. */
        if (x < 0)
            x = 0;
        if (x >= WIDTH)
            x = WIDTH - 1;
        if (y < 1)
            y = 1;
        if (y >= HEIGHT)
            y = HEIGHT - 1;

        /* Check for color change. */
        if (keyboard_keypressed(SCANCODE_KEYPAD0) ||
                keyboard_keypressed(SCANCODE_ENTER)) {
            if (!leftpressed) {
                color = newcolor();
                leftpressed = 1;
            }
        } else
            leftpressed = 0;

        if (keyboard_keypressed(SCANCODE_Q) ||
                keyboard_keypressed(SCANCODE_ESCAPE))
            break;
    }

    keyboard_close();		/* Don't forget this! */
    vga_setmode(TEXT);
    exit(0);
}