/// <summary>Begins the game by performing the following cycle events in this order: Initialize, LoadContent, /// CheckInputs, Update, Draw, UnloadContent. /// </summary> public void Start(GameEngineInitializeType types) { PerformInitialize(types); PerformLoadContent(); while (!IsExiting) { SDL.SDL_Event rawEvent = new SDL.SDL_Event(); while (SDL.SDL_PollEvent(out rawEvent) == 1) { logger?.LogTrace($"SDL_Event: {rawEvent.type.ToString()}"); EventManager.RaiseEvent(rawEvent); } Tick(); } PerformUnloadContent(); Dispose(); }
/// <summary>Initializes the game by calling initialize on the SDL2 instance with the passed flags /// or "EVERYTHING" if 0. Additionally, this method will initialize SDL_ttf and SDL_image to load fonts and images. /// </summary> /// <param name="types">Bit flags indicating the way in which SDL should be initialized</param> private void InitializeBase(GameEngineInitializeType types) { if (SDL.SDL_Init((uint)types) != 0) { throw new InvalidOperationException($"SDL_Init: {SDL.SDL_GetError()}"); } if (SDL_ttf.TTF_Init() != 0) { throw new InvalidOperationException($"TTF_Init: {SDL.SDL_GetError()}"); } SDL_image.IMG_InitFlags initImageFlags = SDL_image.IMG_InitFlags.IMG_INIT_JPG | SDL_image.IMG_InitFlags.IMG_INIT_PNG | SDL_image.IMG_InitFlags.IMG_INIT_TIF | SDL_image.IMG_InitFlags.IMG_INIT_WEBP; int initImageResult = SDL_image.IMG_Init(initImageFlags); if ((initImageResult & (int)initImageFlags) != (int)initImageFlags) { throw new InvalidOperationException($"IMG_Init: {SDL.SDL_GetError()}"); } }
/// <summary>Override to initialize any custom objects or large helpers that are required by the game. /// </summary> private void PerformInitialize(GameEngineInitializeType types) { InitializeBase(types); Initialize(); }