Esempio n. 1
0
        public Video(GraphicsDevice graphicsDevice, SoundManager soundManager, string filename, uint width, uint height)
        {
            Init();

            mutex = new object();
            sound = new VideoSound(soundManager, filename, 44100, this);
            videos.Add(latestVideoId, this);
            videoId = latestVideoId; latestVideoId++;

            /*using (var stream = File.OpenRead(filename))
             * {*/
            byte[] filenameBytes = Encoding.UTF8.GetBytes(filename + "\0");
            byte[] filenameBytesNullTerminated = new byte[filenameBytes.Length + 1];
            filenameBytesNullTerminated[filenameBytes.Length] = 0;
            Array.Copy(filenameBytes, filenameBytesNullTerminated, filenameBytes.Length);
            media = LibVlcWrapper.LibVlcMethods.libvlc_media_new_path(lib, filenameBytesNullTerminated);
            LibVlcWrapper.LibVlcMethods.libvlc_media_parse(media);

            mediaPlayer = LibVlcWrapper.LibVlcMethods.libvlc_media_player_new(lib);
            LibVlcWrapper.LibVlcMethods.libvlc_media_player_set_media(mediaPlayer, media);
            //LibVlcWrapper.LibVlcMethods.libvlc_media_release(media);

            //LibVlcWrapper.LibVlcMethods.libvlc_video_get_size(mediaPlayer, 0, out width, out height);
            CrossThread.RequestExecutionOnMainThread(() =>
            {
                texture = new Texture2D(graphicsDevice, (int)width, (int)height);
            });
            Width = width; Height = height;

            unmanagedData = Marshal.AllocHGlobal(sizeof(int) * 2 + (int)(width * height * 3));
            int[] arr = { videoId, 1 };
            Marshal.Copy(arr, 0, unmanagedData, 2);
            textureData = new byte[width * height * 3];
            for (int i = 0; i < width * height * 3; i++)
            {
                textureData[i] = 0;
            }

            IntPtr videoLockDelegatePtr    = Marshal.GetFunctionPointerForDelegate(VideoLockDelegate);
            IntPtr videoUnlockDelegatePtr  = Marshal.GetFunctionPointerForDelegate(VideoUnlockDelegate);
            IntPtr videoDisplayDelegatePtr = Marshal.GetFunctionPointerForDelegate(VideoDisplayDelegate);

            LibVlcWrapper.LibVlcMethods.libvlc_video_set_callbacks(mediaPlayer, videoLockDelegatePtr, videoUnlockDelegatePtr, videoDisplayDelegatePtr, unmanagedData);
            LibVlcWrapper.LibVlcMethods.libvlc_video_set_format(mediaPlayer, Encoding.UTF8.GetBytes("RV24\0"), (int)width, (int)height, (int)width * 3);

            IntPtr audioPlayDelegatePtr   = Marshal.GetFunctionPointerForDelegate(AudioPlayDelegate);
            IntPtr audioPauseDelegatePtr  = Marshal.GetFunctionPointerForDelegate(AudioPauseDelegate);
            IntPtr audioResumeDelegatePtr = Marshal.GetFunctionPointerForDelegate(AudioResumeDelegate);
            IntPtr audioFlushDelegatePtr  = Marshal.GetFunctionPointerForDelegate(AudioFlushDelegate);
            IntPtr audioDrainDelegatePtr  = Marshal.GetFunctionPointerForDelegate(AudioDrainDelegate);

            LibVlcWrapper.LibVlcMethods.libvlc_audio_set_callbacks(mediaPlayer, audioPlayDelegatePtr, audioPauseDelegatePtr, audioResumeDelegatePtr, audioFlushDelegatePtr, audioDrainDelegatePtr, unmanagedData);
            LibVlcWrapper.LibVlcMethods.libvlc_audio_set_format(mediaPlayer, Encoding.UTF8.GetBytes("S16N\0"), 44100, 2);

            LibVlcWrapper.LibVlcMethods.libvlc_audio_set_delay(mediaPlayer, 0);

            LibVlcWrapper.LibVlcMethods.libvlc_media_player_play(mediaPlayer);

            //}
        }
Esempio n. 2
0
        public Texture2D GetTexture()
        {
            Monitor.Enter(mutex);

            int[]  arr        = { -1 };
            IntPtr changedPtr = (IntPtr)(unmanagedData.ToInt64() + sizeof(int));

            Marshal.Copy(changedPtr, arr, 0, 1);

            if (arr[0] != 0)
            {
                IntPtr colorLocation = (IntPtr)(unmanagedData.ToInt64() + sizeof(int) * 2);
                Marshal.Copy(colorLocation, textureData, 0, (int)(Width * Height * 3));
                Color[] colors = new Color[Width * Height];
                for (int y = 0; y < Height; y++)
                {
                    for (int x = 0; x < Width; x++)
                    {
                        colors[x + y * Width] = new Color(textureData[3 * (x + y * Width) + 0],
                                                          textureData[3 * (x + y * Width) + 1],
                                                          textureData[3 * (x + y * Width) + 2],
                                                          (byte)255);
                    }
                }
                CrossThread.RequestExecutionOnMainThread(() =>
                {
                    texture.SetData(colors);
                });
                arr[0] = 0;
                Marshal.Copy(arr, 0, changedPtr, 1);
            }

            if (!sound.IsPlaying())
            {
                videos[videoId].sound.Play();
            }

            Monitor.Exit(mutex);

            return(texture);
        }
Esempio n. 3
0
        public LightManager(GraphicsDevice graphics, ContentManager content)
        {
            lights = new List <LightSource>();

            AmbientLight = new Color(20, 20, 20, 255);

            visionCircle    = Sprite.LoadTexture("Content/Lights/visioncircle.png", preMultiplyAlpha: false);
            highlightRaster = Sprite.LoadTexture("Content/UI/HighlightRaster.png", preMultiplyAlpha: false);

            GameMain.Instance.OnResolutionChanged += () =>
            {
                CreateRenderTargets(graphics);
            };

            CrossThread.RequestExecutionOnMainThread(() =>
            {
                CreateRenderTargets(graphics);

#if WINDOWS
                LosEffect        = content.Load <Effect>("Effects/losshader");
                SolidColorEffect = content.Load <Effect>("Effects/solidcolor");
#else
                LosEffect        = content.Load <Effect>("Effects/losshader_opengl");
                SolidColorEffect = content.Load <Effect>("Effects/solidcolor_opengl");
#endif

                if (lightEffect == null)
                {
                    lightEffect = new BasicEffect(GameMain.Instance.GraphicsDevice)
                    {
                        VertexColorEnabled = true,
                        TextureEnabled     = true,
                        Texture            = LightSource.LightTexture
                    };
                }
            });

            hullAmbientLights         = new Dictionary <Hull, Color>();
            smoothedHullAmbientLights = new Dictionary <Hull, Color>();
        }
Esempio n. 4
0
        public void QueryLiveInfo(Action <Networking.ServerInfo> onServerRulesReceived)
        {
            if (!SteamManager.IsInitialized)
            {
                return;
            }

            if (int.TryParse(QueryPort, out int parsedPort) && IPAddress.TryParse(IP, out IPAddress parsedIP))
            {
                if (MatchmakingPingResponse?.QueryActive ?? false)
                {
                    MatchmakingPingResponse.Cancel();
                }

                MatchmakingPingResponse = new Steamworks.ISteamMatchmakingPingResponse(
                    (server) =>
                {
                    ServerName            = server.Name;
                    RespondedToSteamQuery = true;
                    PlayerCount           = server.Players;
                    MaxPlayers            = server.MaxPlayers;
                    HasPassword           = server.Passworded;
                    PingChecked           = true;
                    Ping    = server.Ping;
                    LobbyID = 0;
                    TaskPool.Add(server.QueryRulesAsync(),
                                 (t) =>
                    {
                        if (t.Status == TaskStatus.Faulted)
                        {
                            TaskPool.PrintTaskExceptions(t, "Failed to retrieve rules for " + ServerName);
                            return;
                        }

                        var rules = t.Result;
                        SteamManager.AssignServerRulesToServerInfo(rules, this);

                        CrossThread.RequestExecutionOnMainThread(() =>
                        {
                            onServerRulesReceived(this);
                        });
                    });
                },
                    () =>
                {
                    RespondedToSteamQuery = false;
                });

                MatchmakingPingResponse.HQueryPing(parsedIP, parsedPort);
            }
            else if (OwnerID != 0)
            {
                if (SteamFriend == null)
                {
                    SteamFriend = new Steamworks.Friend(OwnerID);
                }
                if (LobbyID == 0)
                {
                    TaskPool.Add(SteamFriend?.RequestInfoAsync(),
                                 (t) =>
                    {
                        if ((SteamFriend?.IsPlayingThisGame ?? false) && ((SteamFriend?.GameInfo?.Lobby?.Id ?? 0) != 0))
                        {
                            LobbyID = SteamFriend?.GameInfo?.Lobby?.Id.Value ?? 0;
                            Steamworks.SteamMatchmaking.OnLobbyDataChanged += UpdateInfoFromSteamworksLobby;
                            SteamFriend?.GameInfo?.Lobby?.Refresh();
                        }
                        else
                        {
                            RespondedToSteamQuery = false;
                        }
                    });
                }
            }
        }