Exemplo n.º 1
0
void InputManager::init()
{
	if(initialized())
		deinit();

	SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, 
		Settings::getInstance()->getBool("BackgroundJoystickInput") ? "1" : "0");
	SDL_InitSubSystem(SDL_INIT_JOYSTICK);
	SDL_JoystickEventState(SDL_ENABLE);

	// first, open all currently present joysticks
	int numJoysticks = SDL_NumJoysticks();
	for(int i = 0; i < numJoysticks; i++)
	{
		addJoystickByDeviceIndex(i);
	}

	mKeyboardInputConfig = new InputConfig(DEVICE_KEYBOARD, "Keyboard", KEYBOARD_GUID_STRING);
	loadInputConfig(mKeyboardInputConfig);

	SDL_USER_CECBUTTONDOWN = SDL_RegisterEvents(2);
	SDL_USER_CECBUTTONUP   = SDL_USER_CECBUTTONDOWN + 1;
	CECInput::init();
	mCECInputConfig = new InputConfig(DEVICE_CEC, "CEC", CEC_GUID_STRING);
	loadInputConfig(mCECInputConfig);
}
Exemplo n.º 2
0
void ColeButton::onEvent(SDL_Event *e)
{
    ColeScene::onEvent(e);
    
    if (e->type == SDL_MOUSEBUTTONDOWN && e->button.button == SDL_BUTTON_LEFT)
    {
        SDL_Point coords = getAbsoluteCoords();
        if (e->button.x >= coords.x && e->button.y >= coords.y && e->button.x <= coords.x+rect.w
            && e->button.y <= coords.y+rect.h)
        {
            depress();
        }
    }
    
    if (e->type == SDL_MOUSEBUTTONUP && e->button.button == SDL_BUTTON_LEFT)
    {
        SDL_Point coords = getAbsoluteCoords();
        if (e->button.x >= coords.x && e->button.y >= coords.y && e->button.x <= coords.x+rect.w
            && e->button.y <= coords.y+rect.h && depressed)
        {
            Uint32 myEventType = SDL_RegisterEvents(1); //TODO: Should probably only call this once
            if (myEventType != ((Uint32)-1)) {
                SDL_Event event;
                SDL_zero(event);
                event.type = myEventType;
                event.user.code = BUTTON_PRESSED;
                event.user.data1 = &tag;
                SDL_PushEvent(&event);
            }
        }
        release();
    }
}
Exemplo n.º 3
0
void
interface_static_init()
{
	interface_event_base = SDL_RegisterEvents(INTERFACE_NUM_EVENTS);
	if(interface_event_base == (uint32_t)-1)
		fail("Could not register interface events with SDL2");
}
Exemplo n.º 4
0
static mrb_value
mrb_sdl2_input_register(mrb_state *mrb, mrb_value self)
{
  mrb_int num;
  mrb_get_args(mrb, "i", &num);
  return mrb_fixnum_value(SDL_RegisterEvents(num));
}
Exemplo n.º 5
0
void EventsManager::init() {
	if (!GfxMan.ready())
		throw Common::Exception("The GraphicsManager needs to be initialized first");

	RequestMan.init();
	NotificationMan.init();
	TimerMan.init();

	_fullQueue = false;
	_queueSize = 0;

	_ready = true;

	initJoysticks();

	SDL_RegisterEvents(1);

	std::srand(getTimestamp());

	// Forcing enableTextInput to be disabled requires _textInputCounter = 1 to not underrun the counter.
	_textInputCounter = 1;
	enableTextInput(false);

	_repeatCounter = 0;
}
Exemplo n.º 6
0
int GerenciadorDeEventos::registrarEventoDeUsuario()
{
	Uint32 tipo = SDL_RegisterEvents(1);
	if (tipo == ((Uint32)-1))
		return -1;

	return tipo;
}
Exemplo n.º 7
0
bool EventThread::allocUserEvents()
{
	usrIdStart = SDL_RegisterEvents(EVENT_COUNT);

	if (usrIdStart == (uint32_t) -1)
		return false;

	return true;
}
Exemplo n.º 8
0
void Game::TriggerAIEvent()
{
    Uint32 gameStateChanged = SDL_RegisterEvents(1);
    if (gameStateChanged != ((Uint32)-1)) {
        SDL_Event event;
        SDL_memset(&event, 0, sizeof(event));
        event.type = gameStateChanged;
        SDL_PushEvent(&event);
    }
}
Exemplo n.º 9
0
	Timer(Uint32 interval){
		this->interval = interval;
		this->running = false;
		this->timer_id = 0;

		this->type = SDL_RegisterEvents(1);
		if(this->type == ((Uint32)-1)){
			printf("shit something went waayyy wrong\n");
		}
	}
Exemplo n.º 10
0
/**
 * This is where the magic happens.
 */
int main(int argc, char **argv) {
	pthread_t game_thread;

	srand (static_cast <unsigned> (time(0)));
	
	//Run a cleanup function on quit
	signal(SIGABRT, quit);
	signal(SIGTERM, quit);
	signal(SIGSEGV, handler);
	
	//Enable X11 multi threaded support.
	//XInitThreads();
	
	//The game state contains all the abstracted information about that game.
	//The game engine and the GL engine each get a reference to do with as needed.
	GameState *game_state = new GameState();
	
	ThreadArgs args;
	args.game_state = game_state;
	args.game_event_id = SDL_RegisterEvents(2);
	args.GL_event_id = args.game_event_id+1;
	
	//The GL engine will run in the main thread.
	//It will simply render the game state as a 3d environment.
	gl_engine = new GLEngine(game_state, args.game_event_id, args.GL_event_id);
	
	//Initialise SQL and GL scene.
	if(gl_engine->initialise()) {
		
		//The game engine will run in it's own thread.
		//It will manage the state of the game and compute positions etc.
		//(Must run after gl_engine.initialise()!!
		
		int ret = pthread_create( &game_thread, NULL, &runGameEngine, (void *)&args);
		if(ret != 0) {
			std::cout << "Couldn't create game thread, Error number: " << ret << std::endl;
			quit(EXIT_FAILURE);
			return EXIT_FAILURE;
		}
		
	
		//After the game engine has started, run the GL engine.
		gl_engine->run();
		
		//if(game_thread.joinable())
		//	game_thread.join();
		pthread_join(game_thread, NULL);
		
		quit(EXIT_SUCCESS);
	} else {
		quit(EXIT_FAILURE);
	}
	
	return EXIT_SUCCESS;
}
Exemplo n.º 11
0
/*
 * SDL.registerEvents(num)
 *
 * Arguments:
 *	num the number of events to register
 *
 * Returns:
 *	The beginning number
 */
static int
l_event_registerEvents(lua_State *L)
{
	int num = luaL_checkinteger(L, 1);
	Uint32 ret;

	if ((ret = SDL_RegisterEvents(num)) == (Uint32)-1)
		return commonPushSDLError(L, 1);

	return commonPush(L, "i", ret);
}
Exemplo n.º 12
0
bool EventThread::allocUserEvents()
{
	uint32_t first = SDL_RegisterEvents(EVENT_COUNT);

	if (first == (uint32_t) -1)
		return false;

	for (size_t i = 0; i < EVENT_COUNT; ++i)
		usrId[i] = first + i;

	return true;
}
Exemplo n.º 13
0
EventHandler::EventHandler(SDL_Window *pWindow, b2World& world, Ships& ships, Walls& walls):
    m_bQuit(false),
    m_pWindow(pWindow),
    m_ships(ships),
    m_timeStep(1.0f / 60.0f),
    m_velocityIterations(6),
    m_positionIterations(2),
    m_world(world),
    m_walls(walls)
{
    //Setup a new SDL event to handle controls from whatever source
    //currently, WiiMote
    m_controlEvent = SDL_RegisterEvents(1);
    SDL_zero(m_templateEvent);
    m_templateEvent.type = SDL_USEREVENT; 
    m_templateEvent.user.type = m_controlEvent;
}
Exemplo n.º 14
0
void EventsManager::init() {
	if (!GfxMan.ready())
		throw Common::Exception("The GraphicsManager needs to be initialized first");

	RequestMan.init();
	NotificationMan.init();
	TimerMan.init();

	_fullQueue = false;
	_queueSize = 0;

	_ready = true;

	initJoysticks();

	SDL_RegisterEvents(1);

	std::srand(getTimestamp());
	SDL_StopTextInput();
}
Exemplo n.º 15
0
#include "Events.h"

//const Uint32 nextSceneEvent = SDL_RegisterEvents(1);
const Uint32 newGameEvent = SDL_RegisterEvents(1);
const Uint32 backEvent = SDL_RegisterEvents(1);
const Uint32 pauseGameEvent = SDL_RegisterEvents(1);
const Uint32 loadGameEvent = SDL_RegisterEvents(1);
const Uint32 toggleDebugEvent = SDL_RegisterEvents(1);
Exemplo n.º 16
0
int register_sdl_user_event()
{
  return SDL_RegisterEvents(1);
}
Exemplo n.º 17
0
int
main(int argc, char *argv[])
{
    int success;

	/* Enable standard application logging */
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);

    success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
                "Simple MessageBox",
                "This is a simple error MessageBox",
                NULL);
    if (success == -1) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
        quit(1);
    }

    success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
                "Simple MessageBox",
                "This is a simple MessageBox with a newline:\r\nHello world!",
                NULL);
    if (success == -1) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
        quit(1);
    }

    /* Google says this is Traditional Chinese for "beef with broccoli" */
    success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
                "UTF-8 Simple MessageBox",
                "Unicode text: '牛肉西蘭花' ...",
                NULL);
    if (success == -1) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
        quit(1);
    }

    /* Google says this is Traditional Chinese for "beef with broccoli" */
    success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
                "UTF-8 Simple MessageBox",
                "Unicode text and newline:\r\n'牛肉西蘭花'\n'牛肉西蘭花'",
                NULL);
    if (success == -1) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
        quit(1);
    }

    button_messagebox(NULL);

    /* Test showing a message box from a background thread.

       On Mac OS X, the video subsystem needs to be initialized for this
       to work, since the message box events are dispatched by the Cocoa
       subsystem on the main thread.
     */
    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL video subsystem: %s\n", SDL_GetError());
        return (1);
    }
    {
        int status = 0;
        SDL_Event event;
        intptr_t eventNumber = SDL_RegisterEvents(1);
        SDL_Thread* thread = SDL_CreateThread(&button_messagebox, "MessageBox", (void*)eventNumber);

        while (SDL_WaitEvent(&event))
        {
            if (event.type == eventNumber) {
                break;
            }
        }

        SDL_WaitThread(thread, &status);

        SDL_Log("Message box thread return %i\n", status);
    }

    /* Test showing a message box with a parent window */
    {
        SDL_Event event;
        SDL_Window *window = SDL_CreateWindow("Test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, 0);

        success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
                    "Simple MessageBox",
                    "This is a simple error MessageBox with a parent window",
                    window);
        if (success == -1) {
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
            quit(1);
        }

        while (SDL_WaitEvent(&event))
        {
            if (event.type == SDL_QUIT || event.type == SDL_KEYUP) {
                break;
            }
        }
    }

    SDL_Quit();
    return (0);
}
Exemplo n.º 18
0
Uint32 EngineApp::RegisterEvent( int eventNum )
   {
   Uint32 eventID = SDL_RegisterEvents( eventNum );
   ENG_ASSERT( eventID != ( ( Uint32 ) -1 ) );
   return eventID;
   }
Exemplo n.º 19
0
int main(int argc, char *argv[]){
	int i;
	struct timerparams tparams;
	SDL_Event e;
	sim_Sim *mysim;
	SDL_Renderer *ren;
	int temp;
	SDL_Surface *iconSurf, *isoSurf;
	SDL_TimerID timerid;
	Uint32 updatetime;
	int tickspersecond;
	int droppedframes;

	gridviewport.x = 0;
	gridviewport.y = 0;
	gridviewport.w = WIDTH * CELLSIZE;
	gridviewport.h = HEIGHT * CELLSIZE;

	isoviewport.x = 500;
	isoviewport.y = 700;

	toolbox.x = 0;
	toolbox.y = 400;
	toolbox.w = 400;
	toolbox.h = 400;

	uistate.toolselected = TOOL_ADD;
	uistate.demoselected = MODE_NONE;
	uistate.paused = 0;
	uistate.mouseinwindow = 1;

	ren = setupWindow();

	SDL_SetRenderDrawBlendMode(ren, SDL_BLENDMODE_BLEND);

	if((iconSurf = SDL_LoadBMP("icons.bmp")) == NULL) {
		printf("Failed to load icons.bmp");
		exit(-1);
	}
	iconText = SDL_CreateTextureFromSurface(ren, iconSurf);

	isoSurf = SDL_LoadBMP("tile.bmp");
	isoText = SDL_CreateTextureFromSurface(ren, isoSurf);

	if((tparams.CustomTimerEvent = SDL_RegisterEvents(1)) == -1){
		printf("Failed to register customevent\n");
		exit(-1);
	}
	tparams.timerlock = 0;

	if((timerid = SDL_AddTimer(TIMERINTERVAL, timercallback, (void *) &tparams)))
		;
	else
		fprintf(stderr,"Timer failed to start\n");


	mysim = sim_CreateSimulation(WIDTH, HEIGHT, 50.5);

	int quit = 0;

	updatetime = SDL_GetTicks();
	tickspersecond = 0;
	

	while (!quit) {
		droppedframes = MAXDROPPEDFRAMES;

		doMouseEvent(&uistate, mysim);
			
		drawGrid(ren, mysim, &gridviewport);
		drawIso(ren, mysim, &isoviewport);
		drawTools(ren, &uistate, &toolbox);
		SDL_RenderPresent(ren);

		
		//fprintf(stderr, "b");
		if(SDL_GetTicks() - updatetime > 1000) {
			updatetime = SDL_GetTicks();
			if(DEBUGPRINT)
				fprintf(stderr, "%d\n", tickspersecond);
			tickspersecond = 0;
		}


		while ((temp = SDL_PollEvent(&e)) != 0 && !quit) {
			switch (e.type) {
				case SDL_QUIT:
					quit = 1;
					break;
				case SDL_USEREVENT:
					if(!droppedframes || uistate.paused)
						break; //If it drops too many frames, clear the event queue
					droppedframes--;
					//fprintf(stderr, "c");
					tickspersecond++;
					for(i = 0; i < STEPSPERTICK; i++) {
						doDemos(uistate.demoselected, mysim);
						sim_step(mysim, TICKTIME);
					}
					//printGrid(mysim);
					tparams.timerlock = 0;
					break;
				case SDL_MOUSEMOTION:
				case SDL_MOUSEBUTTONDOWN:
				case SDL_MOUSEBUTTONUP:
					//doMouseEvent(&e, &selected, &hovered, mysim);
					break;
				case SDL_WINDOWEVENT:
					switch (e.window.event) {
						case SDL_WINDOWEVENT_ENTER:
							uistate.mouseinwindow = 1;
						case SDL_WINDOWEVENT_LEAVE:
							uistate.mouseinwindow = 0;
							break;
					}
					break;
				default:
					if(DEBUGPRINT) 
						fprintf(stderr, "UNKNOWN EVENT TYPE\n");
					break;
			}
		}
	}

	cleanup();
	return 0;
}