Main Menu Video Background#838
Conversation
Added a new video background to the main menu, developed mostly for RA2 YR
|
Nightly build for this pull request:
|
| using DTAClient.DXGUI.Multiplayer.CnCNet; | ||
| using DTAClient.DXGUI.Multiplayer.GameLobby; | ||
| using DTAClient.Online; | ||
| //using DTAConfig; |
There was a problem hiding this comment.
Remove this line, DTAConfig project has been removed from client's code base.
| namespace DXMainClient.Domain | ||
| { | ||
| public class VideoBackground : IDisposable |
There was a problem hiding this comment.
This is a generic UI class. Move it to the ClientGUI please.
removed a commented code (" using DTAConfig; ")
moved VideoBackground.cs from Domain into DXGUI\Generic
|
Remaining works:
|
There was a problem hiding this comment.
Pull request overview
This PR adds video background support to the main menu, primarily developed for Red Alert 2: Yuri's Revenge. The implementation uses LibVLC to play MP4 video files as an animated background, falling back to the static PNG background if the video file is not found.
Key changes:
- Integrated LibVLCSharp and VideoLAN.LibVLC.Windows packages for video playback
- Created a new
VideoBackgroundclass to handle video decoding and texture updates - Modified
MainMenuto optionally load and display video backgrounds
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 15 comments.
Show a summary per file
| File | Description |
|---|---|
| Directory.Packages.props | Added LibVLCSharp (3.9.4) and VideoLAN.LibVLC.Windows (3.0.21) package references |
| DXMainClient/DXMainClient.csproj | Added VideoLAN.LibVLC.Windows package reference to the main client project |
| ClientGUI/ClientGUI.csproj | Added LibVLCSharp package reference to the GUI library |
| ClientGUI/VideoBackground.cs | New class implementing video playback using LibVLC with XNA/MonoGame texture integration |
| DXMainClient/DXGUI/Generic/MainMenu.cs | Integrated video background loading with fallback to static image, added LibVLC cleanup on exit |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| _texture = new Texture2D(graphicsDevice, (int)_videoWidth, (int)_videoHeight, false, SurfaceFormat.Color); | ||
|
|
||
| _mediaPlayer.SetVideoCallbacks(Lock, Unlock, Display); | ||
| _mediaPlayer.SetVideoFormat("RGBA", (uint)_videoWidth, (uint)_videoHeight, (uint)_videoWidth * 4); // do not use RV32, use RGBA instead, else the color will be messed up as if it were blue |
There was a problem hiding this comment.
[nitpick] The comment contains grammatical errors and unclear explanation. Consider rephrasing to: "// Use RGBA format instead of RV32 to ensure correct color channel mapping"
| _mediaPlayer.SetVideoFormat("RGBA", (uint)_videoWidth, (uint)_videoHeight, (uint)_videoWidth * 4); // do not use RV32, use RGBA instead, else the color will be messed up as if it were blue | |
| _mediaPlayer.SetVideoFormat("RGBA", (uint)_videoWidth, (uint)_videoHeight, (uint)_videoWidth * 4); // Use RGBA format instead of RV32 to ensure correct color channel mapping |
| _media = new Media(_libVLC, videoPath, FromType.FromPath); | ||
|
|
||
| // add more option if you want to edit the video via VLC | ||
| _media.AddOption(":scale=0.5"); // compress the video (a little help with the lower end devices.||_ ps. its a 50/50 in the lower end device) |
There was a problem hiding this comment.
[nitpick] The comment contains grammatical errors and is unclear. The phrase "a little help with the lower end devices.||_ ps. its a 50/50 in the lower end device" should be rephrased more professionally, e.g., "// Reduce video quality to improve performance on lower-end devices (may have variable results)"
| _media.AddOption(":scale=0.5"); // compress the video (a little help with the lower end devices.||_ ps. its a 50/50 in the lower end device) | |
| _media.AddOption(":scale=0.5"); // Reduce video quality to improve performance on lower-end devices (may have variable results) |
| _media = new Media(_libVLC, videoPath, FromType.FromPath); | ||
|
|
||
| // add more option if you want to edit the video via VLC | ||
| _media.AddOption(":scale=0.5"); // compress the video (a little help with the lower end devices.||_ ps. its a 50/50 in the lower end device) |
There was a problem hiding this comment.
The :scale=0.5 option compresses/scales the video to 50%, but the texture buffer is allocated at full size (_videoWidth * _videoHeight * 4). This mismatch could cause rendering issues or leave parts of the texture uninitialized. Either remove the scale option or adjust the buffer and texture size accordingly.
| private void Display(IntPtr opaque, IntPtr picture) | ||
| { | ||
| lock (_lock) | ||
| { | ||
| _texture.SetData(_videoBuffer); | ||
| } |
There was a problem hiding this comment.
The Display callback writes to _texture from the VLC thread, but Texture2D.SetData in XNA/MonoGame is not thread-safe and should only be called from the main/game thread. This can cause crashes or rendering corruption.
Consider using a flag to indicate new data is ready and perform the SetData call from the main thread's update or draw method instead.
There was a problem hiding this comment.
Good thought. I'll leave this conversation open.
| // add more option if you want to edit the video via VLC | ||
| _media.AddOption(":scale=0.5"); // compress the video (a little help with the lower end devices.||_ ps. its a 50/50 in the lower end device) | ||
| _media.AddOption(":no-audio"); // disables the audio | ||
| _media.AddOption(":input-repeat=65535"); // this means looping the video 65.535 times, its stupid but it works |
There was a problem hiding this comment.
[nitpick] The comment "its stupid but it works" is unprofessional and doesn't add value. Consider rephrasing to explain why this approach was chosen, e.g., ":input-repeat=65535 // Loop video continuously (maximum repeat count)"
| _media.AddOption(":input-repeat=65535"); // this means looping the video 65.535 times, its stupid but it works | |
| _media.AddOption(":input-repeat=65535"); // Loop video continuously (maximum repeat count supported by VLC) |
| public VideoBackground(GraphicsDevice graphicsDevice, string videoPath, int width, int height) | ||
| { | ||
| if (_libVLC == null) | ||
| _libVLC = new LibVLC("--no-xlib", "--drop-late-frames", "--skip-frames"); |
There was a problem hiding this comment.
Write to static field from instance method, property, or constructor.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Added a new video background to the main menu, developed mostly for RA2 YR