コード例 #1
0
ファイル: events.c プロジェクト: AntonioModer/luasdl2
static int
eventAddFilter(lua_State *L, int type)
{
	Filter *f;

	luaL_checktype(L, 1, LUA_TFUNCTION);

	if ((f = malloc(sizeof (Filter))) == NULL)
		return commonPushErrno(L, 1);

	f->L = L;
	f->type = type;

	/* Push the function and ref it */
	lua_pushvalue(L, 1);
	f->ref = luaL_ref(L, LUA_REGISTRYINDEX);

	if (type == EventTypeWatcher)
		SDL_AddEventWatch((SDL_EventFilter)eventFilter, f);
	else if (type == EventTypeFilter)
		SDL_SetEventFilter((SDL_EventFilter)eventFilter, f);

	/* Push the object to the user */
	commonPushUserdata(L, EventFilterName, f);

	return 1;
}
コード例 #2
0
ファイル: main.cpp プロジェクト: suenting/ProjectWalker
int main(int argc, char **argv) 
{
	ResourceManager::Instance();
	FontManager::Instance().InitGlyphTable();
	SDL_AddEventWatch(exitEventFilter, NULL);
	while(true)
	{
		MainLoop();
	}
	exit(0);
	return 0;
}
コード例 #3
0
ファイル: Input.cpp プロジェクト: Tkachov/Square
Input::Input() {
 if(input) throw "Unable to construct Input: Input is a singletone.";
 input = this;

 _app_paused = false;
 _paused = false;
 _quit = false;
 _mx = _my = 0;
 _wx = _wy = 0;

 filter = new Filter(this);
 SDL_AddEventWatch(watch_filter, filter);
}
コード例 #4
0
ファイル: main.cpp プロジェクト: suenting/ProjectFairy
int main(int argc, char **argv) 
{
	ResourceManager::Instance();
	AudioManager::Instance().PlayMusic("The Stage is Set.ogg");
	SDL_AddEventWatch(exitEventFilter, NULL);
	FontManager::Instance().InitGlyphTable();
	while(true)
	{
		MainLoop();
	}
	exit(0);
	return 0;
}
コード例 #5
0
ファイル: Engine.cpp プロジェクト: 100GPing100/hyphus
    Engine::Engine() {
        if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) != 0) {
            std::string err = "Failed to initialise SDL: ";
            err += SDL_GetError();

            SDL_Log(err.c_str());
            throw std::runtime_error(err.c_str());
        }

        _window.reset(new OpenGLWindow("hyphus_window", 800, 600));
        _graphics = _window->graphics();
        _lua.reset(new LuaState());

        _lua->load("test.lua");
        _lua->reg(set_background, "set_background");

        SDL_AddEventWatch(Engine::_watch, this);
    }
コード例 #6
0
/**
 * @brief Adds and deletes an event watch function with userdata
 *
 * @sa http://wiki.libsdl.org/moin.cgi/SDL_AddEventWatch
 * @sa http://wiki.libsdl.org/moin.cgi/SDL_DelEventWatch
 *
 */
int
events_addDelEventWatchWithUserdata(void *arg)
{
   SDL_Event event;

   /* Create user event */
   event.type = SDL_USEREVENT;
   event.user.code = SDLTest_RandomSint32();
   event.user.data1 = (void *)&_userdataValue1;
   event.user.data2 = (void *)&_userdataValue2;

   /* Enable userdata check and set a value to check */
   _userdataCheck = 1;
   _userdataValue = SDLTest_RandomIntegerInRange(-1024, 1024);

   /* Reset event filter call tracker */
   _eventFilterCalled = 0;

   /* Add watch */
   SDL_AddEventWatch(_events_sampleNullEventFilter, (void *)&_userdataValue);
   SDLTest_AssertPass("Call to SDL_AddEventWatch()");

   /* Push a user event onto the queue and force queue update */
   SDL_PushEvent(&event);
   SDLTest_AssertPass("Call to SDL_PushEvent()");
   SDL_PumpEvents();
   SDLTest_AssertPass("Call to SDL_PumpEvents()");
   SDLTest_AssertCheck(_eventFilterCalled == 1, "Check that event filter was called");

   /* Delete watch */
   SDL_DelEventWatch(_events_sampleNullEventFilter, (void *)&_userdataValue);
   SDLTest_AssertPass("Call to SDL_DelEventWatch()");

   /* Push a user event onto the queue and force queue update */
   _eventFilterCalled = 0;
   SDL_PushEvent(&event);
   SDLTest_AssertPass("Call to SDL_PushEvent()");
   SDL_PumpEvents();
   SDLTest_AssertPass("Call to SDL_PumpEvents()");
   SDLTest_AssertCheck(_eventFilterCalled == 0, "Check that event filter was NOT called");

   return TEST_COMPLETED;
}
コード例 #7
0
void FDeviceSDL::Init()
{ 
	UE_LOG(JoystickPluginLog, Log, TEXT("DeviceSDL Starting"));

	if (SDL_WasInit(0) != 0)
	{
		UE_LOG(JoystickPluginLog, Log, TEXT("SDL already loaded"));
		bOwnsSDL = false;
	}
	else
	{
		UE_LOG(JoystickPluginLog, Log, TEXT("DeviceSDL::InitSDL() SDL init 0"));
		SDL_Init(0);
		bOwnsSDL = true;
	}

	int result = SDL_InitSubSystem(SDL_INIT_HAPTIC);
	if (result == 0)
	{
		UE_LOG(JoystickPluginLog, Log, TEXT("DeviceSDL::InitSDL() SDL init subsystem haptic"));
	}

	result = SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER);
	if (result == 0)
	{
		UE_LOG(JoystickPluginLog, Log, TEXT("DeviceSDL::InitSDL() SDL init subsystem joystick"));
	}

	result = SDL_InitSubSystem(SDL_INIT_JOYSTICK);
	if (result == 0)
	{
		UE_LOG(JoystickPluginLog, Log, TEXT("DeviceSDL::InitSDL() SDL init subsystem joystick"));
	}

	int Joysticks = SDL_NumJoysticks();
	for (int i = 0; i < Joysticks; i++)
	{
		AddDevice(FDeviceIndex(i));
	}

	SDL_AddEventWatch(HandleSDLEvent, this);
}
コード例 #8
0
/*
 * Initialize the game controller system, mostly load our DB of controller config mappings
 */
int
SDL_GameControllerInit(void)
{
    int i = 0;
    const char *pMappingString = NULL;
    s_pSupportedControllers = NULL;
    pMappingString = s_ControllerMappings[i];
    while ( pMappingString )
    {
        SDL_GameControllerAddMapping( pMappingString );

        i++;
        pMappingString = s_ControllerMappings[i];
    }

    /* load in any user supplied config */
    SDL_GameControllerLoadHints();

    /* watch for joy events and fire controller ones if needed */
    SDL_AddEventWatch( SDL_GameControllerEventWatcher, NULL );

    return (0);
}
コード例 #9
0
ファイル: events.c プロジェクト: foobar99/sdl
void AddEventWatch(void *data)
{
	SDL_AddEventWatch(eventFilter, data);
}
コード例 #10
0
ファイル: SDL_render.c プロジェクト: ryanzhao006/IOSAVDecode
SDL_Renderer *
SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags)
{
    SDL_Renderer *renderer = NULL;
    int n = SDL_GetNumRenderDrivers();
    const char *hint;

    if (!window) {
        SDL_SetError("Invalid window");
        return NULL;
    }

    if (SDL_GetRenderer(window)) {
        SDL_SetError("Renderer already associated with window");
        return NULL;
    }

    hint = SDL_GetHint(SDL_HINT_RENDER_VSYNC);
    if (hint) {
        if (*hint == '0') {
            flags &= ~SDL_RENDERER_PRESENTVSYNC;
        } else {
            flags |= SDL_RENDERER_PRESENTVSYNC;
        }
    }

    if (index < 0) {
        hint = SDL_GetHint(SDL_HINT_RENDER_DRIVER);
        if (hint) {
            for (index = 0; index < n; ++index) {
                const SDL_RenderDriver *driver = render_drivers[index];

                if (SDL_strcasecmp(hint, driver->info.name) == 0) {
                    /* Create a new renderer instance */
                    renderer = driver->CreateRenderer(window, flags);
                    break;
                }
            }
        }

        if (!renderer) {
            for (index = 0; index < n; ++index) {
                const SDL_RenderDriver *driver = render_drivers[index];

                if ((driver->info.flags & flags) == flags) {
                    /* Create a new renderer instance */
                    renderer = driver->CreateRenderer(window, flags);
                    if (renderer) {
                        /* Yay, we got one! */
                        break;
                    }
                }
            }
        }
        if (index == n) {
            SDL_SetError("Couldn't find matching render driver");
            return NULL;
        }
    } else {
        if (index >= SDL_GetNumRenderDrivers()) {
            SDL_SetError("index must be -1 or in the range of 0 - %d",
                         SDL_GetNumRenderDrivers() - 1);
            return NULL;
        }
        /* Create a new renderer instance */
        renderer = render_drivers[index]->CreateRenderer(window, flags);
    }

    if (renderer) {
        renderer->magic = &renderer_magic;
        renderer->window = window;

        if (SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED) {
            renderer->minimized = SDL_TRUE;
        } else {
            renderer->minimized = SDL_FALSE;
        }

        SDL_SetWindowData(window, SDL_WINDOWRENDERDATA, renderer);

        SDL_RenderSetViewport(renderer, NULL);

        SDL_AddEventWatch(SDL_RendererEventWatch, renderer);

        SDL_LogInfo(SDL_LOG_CATEGORY_RENDER,
                    "Created renderer: %s", renderer->info.name);
    }
    return renderer;
}
コード例 #11
0
ファイル: kmouse.cpp プロジェクト: MrMilad/Kite2D
	void KMouse::initeMouse() {
		Internal::initeSDL();
		// add our watcher for handling mouse wheel
		DSDL_CALL(SDL_AddEventWatch(KMouse::_eventWatcher, NULL));
	}
コード例 #12
0
int CBPlatform::Initialize(CBGame* inGame, int argc, char* argv[])
{
	setlocale(LC_CTYPE, "");

	Game = inGame;
	if(!Game) return 1;

	

	bool windowedMode = false;
	
	int videoDevice = 0;

	// parse command linex	
	char* SaveGame = NULL;
    
	char param[512];
	
	bool enableDebug = false;
	bool showFps = false;

	for(int i = 0; i < argc; i++)
	{
		strcpy(param, argv[i]);

		// this is so we can use this from project manager
		if(CBPlatform::stricmp(param, "-detect")==0)
		{
			windowedMode = true;
			enableDebug = true;
			showFps = true;
		}
		else if(CBPlatform::stricmp(param, "-project")==0)
		{
			if (argc > i) strcpy(param, argv[i + 1]);
			else param[0] = '\0';

			if(strcmp(param, "") != 0)
			{
				char* IniDir = CBUtils::GetPath(param);
				char* IniName = CBUtils::GetFilename(param);
			
				chdir(IniDir);


				// set ini name
				sprintf(param, "./%s", IniName);
				Game->m_Registry->SetIniName(param);

				delete [] IniDir;
				delete [] IniName;
			}
		}
		else if(CBPlatform::stricmp(param, "-ignore")==0)
		{
			if (argc > i) strcpy(param, argv[i + 1]);
			else param[0] = '\0';

			if(strcmp(param, "") != 0)
			{
				Game->m_OmitPackageMask = param;
			}
		}

		else if(CBPlatform::stricmp(param, "-videodevice")==0)
		{
			if (argc > i) strcpy(param, argv[i + 1]);
			else param[0] = '\0';

			if(strcmp(param, "") != 0)
			{
				videoDevice = std::atoi(param);
			}
		}
		else if(CBPlatform::stricmp(param, "-windowed")==0) windowedMode = true;
	}

	videoDevice = 0;

	if (!enableDebug)
		Game->DEBUG_JustLogEnable("./wme.log");
	else
		Game->DEBUG_DebugEnable("./wme.log");


	// if(Game->m_Registry->ReadBool("Debug", "DebugMode")) Game->DEBUG_DebugEnable("./wme.log");

//	Game->m_DEBUG_ShowFPS = Game->m_Registry->ReadBool("Debug", "ShowFPS");

//	if(Game->m_Registry->ReadBool("Debug", "DisableSmartCache"))
//	{
//		Game->LOG(0, "Smart cache is DISABLED");
//		Game->m_SmartCache = false;
//	}

	//bool AllowDirectDraw = Game->m_Registry->ReadBool("Debug", "AllowDirectDraw", false);

	// load general game settings
	Game->Initialize1();


	if(FAILED(Game->LoadSettings("startup.settings")))
	{
		Game->LOG(0, "Error loading game settings.");
		SAFE_DELETE(Game);

#ifdef __WIN32__
		::MessageBox(NULL, "Some of the essential files are missing. Please reinstall.", NULL, MB_OK|MB_ICONERROR);
#endif
		return 2;
	}

	Game->Initialize2();

//	Game->GetDebugMgr()->OnGameInit();
//	Game->m_ScEngine->LoadBreakpoints();

	// read values for up- and downscale stepping from registry
	float upScalingStepping = (float) (((float) Game->m_Registry->ReadInt("Scaling", "UpScalingStepping", 0)) / 100.0);
	float downScalingStepping = (float) (((float) Game->m_Registry->ReadInt("Scaling", "DownScalingStepping", 0)) / 100.0);

	Game->LOG(0, "Scaling steppings found up=%.02f down=%.02f.", upScalingStepping, downScalingStepping);

	bool pixelPerfectRendering = Game->m_Registry->ReadBool("Rendering", "PixelPerfect");

	HRESULT ret;

	// initialize the renderer
	ret = Game->m_Renderer->InitRenderer(Game->m_SettingsResWidth, Game->m_SettingsResHeight, windowedMode, upScalingStepping, downScalingStepping, pixelPerfectRendering,videoDevice);
	if (FAILED(ret))
	{
		Game->LOG(ret, "Error initializing renderer. Exiting.");
		SAFE_DELETE(Game);
		return 3;
	}

	Game->Initialize3();	
	Game->m_DEBUG_ShowFPS = showFps;

#if defined(__IPHONEOS__) || defined(__ANDROID__)
	SDL_AddEventWatch(CBPlatform::SDLEventWatcher, NULL);
#endif
	
	// initialize sound manager (non-fatal if we fail)
	ret = Game->m_SoundMgr->Initialize();
	if(FAILED(ret))
	{
		Game->LOG(ret, "Sound is NOT available.");
	}
		

	// load game
	DWORD DataInitStart = GetTime();

	if(FAILED(Game->LoadFile(Game->m_SettingsGameFile?Game->m_SettingsGameFile:"default.game")))
	{
		Game->LOG(ret, "Error loading game file. Exiting.");
		SAFE_DELETE(Game);
		return false;
	}
	Game->SetWindowTitle();
	Game->m_Renderer->m_Ready = true;
	Game->m_MiniUpdateEnabled = true;

	Game->LOG(0, "Engine initialized in %d ms", GetTime() - DataInitStart);
	Game->LOG(0, "");

	
	if(SaveGame)
	{
		Game->LoadGame(SaveGame);
		delete [] SaveGame;
	}

	// all set, ready to go
	return 0;
}
コード例 #13
0
ファイル: port.c プロジェクト: CecilHarvey/tailtale
SDL_Surface * SCREEN_SetVideoMode (int width, int height, Uint32 flags) {
	Uint32 window_flags;

	if (SCREEN_IsVideoModeSet ()) {
        SCREEN_ShutdownVideo ();
    }

#if !defined(ANDROID) && !defined(WINPHONE)
    SDL_DisplayMode display_mode;
    if (SDL_GetDesktopDisplayMode (0, &display_mode) != 0) {
        SCREEN_ShutdownVideo ();
        return NULL;
    }
#endif

    window_flags = 0;
    if (flags & SCREEN_FULLSCREEN) {
        window_flags |= SDL_WINDOW_FULLSCREEN;
    }
    if (flags & SCREEN_RESIZABLE) {
        window_flags |= SDL_WINDOW_RESIZABLE;
    }

#ifdef ANDROID
    video_window = SDL_CreateWindow ("TailTale", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 480, 272, window_flags);
#elif WINPHONE
    video_window = SDL_CreateWindow ("TailTale", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 800, 640, window_flags);
#elif MACOSX
    video_window = SDL_CreateWindow ("TailTale", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, window_flags);
#else
    video_window = SDL_CreateWindow ("TailTale", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, display_mode.w, display_mode.h, window_flags);
#endif
    if (!video_window) {
        SCREEN_ShutdownVideo ();
        return NULL;
    }

    video_renderer = SDL_CreateRenderer (video_window, -1, SDL_RENDERER_ACCELERATED);
    if (!video_renderer) {
        SCREEN_ShutdownVideo ();
        return NULL;
    }

#ifdef MACOSX

#ifdef TAILTALE_HD
    width = 480;
    height = 272;
#else
    width = 320;
    height = 240;
#endif

#endif

    video_texture = SDL_CreateTexture (video_renderer, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STREAMING, width, height);
    if (!video_texture) {
        SCREEN_ShutdownVideo ();
        return NULL;
    }

    video_surface = SDL_CreateRGBSurface (0, width, height, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
    if (!video_surface) {
        SCREEN_ShutdownVideo ();
        return NULL;
    }

    video_flags = flags;

#if !defined(ANDROID) || !defined(WINPHONE)
    SDL_AddEventWatch (SCREEN_EventWatch, NULL);
#endif

    return video_surface;
}
コード例 #14
-1
/*
 * Initialize the game controller system, mostly load our DB of controller config mappings
 */
int
SDL_GameControllerInit(void)
{
    int i = 0;
    const char *pMappingString = NULL;
    s_pSupportedControllers = NULL;
    pMappingString = s_ControllerMappings[i];
    while (pMappingString) {
        SDL_GameControllerAddMapping(pMappingString);

        i++;
        pMappingString = s_ControllerMappings[i];
    }

    /* load in any user supplied config */
    SDL_GameControllerLoadHints();

    /* watch for joy events and fire controller ones if needed */
    SDL_AddEventWatch(SDL_GameControllerEventWatcher, NULL);

    /* Send added events for controllers currently attached */
    for (i = 0; i < SDL_NumJoysticks(); ++i) {
        if (SDL_IsGameController(i)) {
            SDL_Event deviceevent;
            deviceevent.type = SDL_CONTROLLERDEVICEADDED;
            deviceevent.cdevice.which = i;
            SDL_PushEvent(&deviceevent);
        }
    }

    return (0);
}