Hacky ingame video widget

This commit is contained in:
Paul Chote
2010-08-11 11:45:37 +12:00
parent bf8e3645cb
commit 44d7aa14a4
6 changed files with 88 additions and 31 deletions

View File

@@ -503,15 +503,7 @@ namespace OpenRA
// Load the default mod to access required files
LoadModPackages();
var video = new VqaReader(FileSystem.Open("crontest.vqa"));
video.FrameData().Save("test-0.bmp");
for (int i = 1; i < video.numFrames; i++)
{
video.AdvanceFrame();
video.FrameData().Save("test-{0}.bmp".F(i));
}
Renderer.SheetSize = Settings.SheetSize;
var resolution = GetResolution(settings, Game.Settings.WindowMode);

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -221,6 +221,7 @@
<Compile Include="Traits\Health.cs" />
<Compile Include="Traits\RepairableBuilding.cs" />
<Compile Include="Traits\Activities\Drag.cs" />
<Compile Include="Widgets\VqaPlayerWidget.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -0,0 +1,62 @@
#region Copyright & License Information
/*
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see LICENSE.
*/
#endregion
using System;
using System.Drawing;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Traits;
using OpenRA.Widgets;
using OpenRA.FileFormats;
namespace OpenRA.Widgets
{
public class VqaPlayerWidget : Widget
{
public string Video = "";
float timestep;
Sprite videoSprite;
Bitmap videoFrame;
VqaReader video = null;
public void LoadVideo(string filename)
{
video = new VqaReader(FileSystem.Open(filename));
timestep = 1e3f/video.framerate;
var size = OpenRA.Graphics.Util.NextPowerOf2(Math.Max(video.width, video.height));
videoFrame = new Bitmap(size,size);
video.FrameData(ref videoFrame);
videoSprite = new Sprite(new Sheet(new Size(size,size)), new Rectangle( 0, 0, video.width, video.height ), TextureChannel.Alpha);
videoSprite.sheet.Texture.SetData(videoFrame);
}
int lastTime;
public override void DrawInner(World world)
{
if (video == null)
LoadVideo(Video);
int t = Environment.TickCount;
int dt = t - lastTime;
if (dt > timestep)
{
lastTime = t;
video.AdvanceFrame();
video.FrameData(ref videoFrame);
videoSprite.sheet.Texture.SetData(videoFrame);
}
Game.Renderer.RgbaSpriteRenderer.DrawSprite(videoSprite, new int2(RenderBounds.X,RenderBounds.Y), "chrome");
}
}
}