Ejemplo n.º 1
0
        /// <summary>
        /// Retrieves system info and stores it in this class
        /// </summary>
        public SystemInfo()
        {
            CPUCacheSize = SDL.SDL_GetCPUCacheLineSize();
            RAMSizeMB    = SDL.SDL_GetSystemRAM();
            CPUFeatures feat = CPUFeatures.Null;

            if (SDLUtil.ToBool(SDL.SDL_Has3DNow()))
            {
                feat |= CPUFeatures.Has3DNow;
            }
            if (SDLUtil.ToBool(SDL.SDL_HasAVX()))
            {
                feat |= CPUFeatures.HasAVX;
            }
            if (SDLUtil.ToBool(SDL.SDL_HasAVX2()))
            {
                feat |= CPUFeatures.HasAVX2;
            }
            if (SDLUtil.ToBool(SDL.SDL_HasAltiVec()))
            {
                feat |= CPUFeatures.HasAltiVec;
            }
            if (SDLUtil.ToBool(SDL.SDL_HasMMX()))
            {
                feat |= CPUFeatures.HasMMX;
            }
            if (SDLUtil.ToBool(SDL.SDL_HasRDTSC()))
            {
                feat |= CPUFeatures.HasRDTSC;
            }
            if (SDLUtil.ToBool(SDL.SDL_HasSSE()))
            {
                feat |= CPUFeatures.HasSSE;
            }
            if (SDLUtil.ToBool(SDL.SDL_HasSSE2()))
            {
                feat |= CPUFeatures.HasSSE2;
            }
            if (SDLUtil.ToBool(SDL.SDL_HasSSE3()))
            {
                feat |= CPUFeatures.HasSSE3;
            }
            if (SDLUtil.ToBool(SDL.SDL_HasSSE41()))
            {
                feat |= CPUFeatures.HasSSE41;
            }
            if (SDLUtil.ToBool(SDL.SDL_HasSSE42()))
            {
                feat |= CPUFeatures.HasSSE42;
            }
            ProcessorFeatures = feat;
            UpdatePowerInfo();
            // Find current display driver index
            VideoDriverIndex   = -1;
            CurrentVideoDriver = SDL.SDL_GetCurrentVideoDriver();
            List <string> tmpVideoDrivers = new List <string>();

            for (int i = 0; i < SDL.SDL_GetNumVideoDrivers(); i++)
            {
                string cVidDri = SDL.SDL_GetVideoDriver(i);
                if (cVidDri == CurrentVideoDriver)
                {
                    VideoDriverIndex = i;
                }
                tmpVideoDrivers.Add(cVidDri);
            }
            InstalledVideoDrivers = tmpVideoDrivers.ToArray();
            // DPI
            if (SDL.SDL_GetDisplayDPI(VideoDriverIndex, out float ddpi, out float hdpi, out float vdpi) == 0)
            {
                HorizontalDPI = hdpi;
                VerticalDPI   = vdpi;
                DiagonalDPI   = ddpi;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Runs the main event loop.
        /// </summary>
        /// <remarks>
        /// Note that this function does not return
        /// until the SDL_QUIT message is recieved. If you want to run
        /// a game tick loop, it should run on a separate thread.
        /// </remarks>
        public void RunWindowLoop()
        {
            try
            {
                bool quit = false;
                while (!quit)
                {
                    SDL.SDL_Event e;
                    if (SDL.SDL_PollEvent(out e) != 0)
                    {
                        switch (e.type)
                        {
                        // Quit
                        case SDL.SDL_EventType.SDL_QUIT:
                        {
                            foreach (var wnd in windows)
                            {
                                wnd.Value.OnQuit();
                            }
                            quit = true;
                            break;
                        }

                        // File dropping
                        case SDL.SDL_EventType.SDL_DROPFILE:
                        case SDL.SDL_EventType.SDL_DROPTEXT:
                        {
                            string   data = SDLUtil.NullTerminatedUTF8String(e.drop.file);
                            DataDrop drop = new DataDrop(e.type == SDL.SDL_EventType.SDL_DROPFILE, data);
                            windows[e.drop.windowID].OnDataDrop(drop);
                            ExtraSDLBindings.SDL_free(e.drop.file);
                            // Note to SDL devs (or SDL2# dev): This is not ok
                            // Either give SDL_free in SDL2# or have SDL free the pointer itself
                            // Or have the binding return a string here
                            break;
                        }

                        case SDL.SDL_EventType.SDL_DROPBEGIN:
                        {
                            windows[e.drop.windowID].OnBeginDrop();
                            break;
                        }

                        case SDL.SDL_EventType.SDL_DROPCOMPLETE:
                        {
                            windows[e.drop.windowID].OnEndDrop();
                            break;
                        }

                        // Key actions
                        case SDL.SDL_EventType.SDL_KEYDOWN:
                        {
                            KeyAction action = new KeyAction(e.key);
                            windows[e.key.windowID].OnKeyDown(action);
                            break;
                        }

                        case SDL.SDL_EventType.SDL_KEYUP:
                        {
                            KeyAction action = new KeyAction(e.key);
                            windows[e.key.windowID].OnKeyUp(action);
                            break;
                        }

                        // Mouse Actions
                        case SDL.SDL_EventType.SDL_MOUSEMOTION:
                        {
                            windows[e.motion.windowID].OnMouseMove(e.motion.x, e.motion.y, e.motion.xrel, e.motion.yrel);
                            break;
                        }

                        case SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN:
                        {
                            windows[e.button.windowID].OnMouseDown(new MouseAction(e.button));
                            break;
                        }

                        case SDL.SDL_EventType.SDL_MOUSEBUTTONUP:
                        {
                            windows[e.button.windowID].OnMouseUp(new MouseAction(e.button));
                            break;
                        }

                        case SDL.SDL_EventType.SDL_TEXTEDITING:
                        {
                            windows[e.edit.windowID].OnTextEdit(new TextEditingAction(e.edit));
                            break;
                        }

                        case SDL.SDL_EventType.SDL_TEXTINPUT:
                        {
                            unsafe
                            {
                                windows[e.text.windowID].OnTextInput(SDLUtil.NullTerminatedUTF8String(new IntPtr(e.text.text)));
                            }
                            break;
                        }
                        }
                    }
                    foreach (var wnd in windows)
                    {
                        wnd.Value.OnPaint();
                    }
                }
            }catch (Exception ex)
            {
                MessageBox.ShowMessageBox(MessageBoxFlags.Error, "Unhandled Exception", ex.ToString());
                throw;
            }
        }