Hacky ingame video widget
This commit is contained in:
@@ -22,9 +22,10 @@ namespace OpenRA.FileFormats
|
||||
Stream stream;
|
||||
ushort flags;
|
||||
public readonly ushort numFrames;
|
||||
public readonly byte framerate;
|
||||
ushort numColors;
|
||||
ushort width;
|
||||
ushort height;
|
||||
public readonly ushort width;
|
||||
public readonly ushort height;
|
||||
ushort blockWidth;
|
||||
ushort blockHeight;
|
||||
byte cbParts;
|
||||
@@ -51,12 +52,12 @@ namespace OpenRA.FileFormats
|
||||
if (new String(reader.ReadChars(4)) != "FORM")
|
||||
throw new InvalidDataException("Invalid vqa (invalid FORM section)");
|
||||
|
||||
/*var formlength = */ reader.ReadUInt32();
|
||||
/*var length = */ reader.ReadUInt32();
|
||||
|
||||
if (new String(reader.ReadChars(8)) != "WVQAVQHD")
|
||||
throw new InvalidDataException("Invalid vqa (not WVQAVQHD)");
|
||||
|
||||
/* var len = */reader.ReadUInt32();
|
||||
/* var length = */reader.ReadUInt32();
|
||||
var version = reader.ReadUInt16();
|
||||
flags = reader.ReadUInt16();
|
||||
numFrames = reader.ReadUInt16();
|
||||
@@ -65,7 +66,7 @@ namespace OpenRA.FileFormats
|
||||
|
||||
blockWidth = reader.ReadByte();
|
||||
blockHeight = reader.ReadByte();
|
||||
var framerate = reader.ReadByte();
|
||||
framerate = reader.ReadByte();
|
||||
cbParts = reader.ReadByte();
|
||||
blocks = new int2(width / blockWidth, height / blockHeight);
|
||||
|
||||
@@ -74,7 +75,7 @@ namespace OpenRA.FileFormats
|
||||
/*var unknown1 = */reader.ReadUInt16();
|
||||
/*var unknown2 = */reader.ReadUInt32();
|
||||
|
||||
cbf = new byte[8*blocks.X*blocks.Y];
|
||||
cbf = new byte[width*height];
|
||||
palette = new Color[numColors];
|
||||
framedata = new byte[2*blocks.X*blocks.Y];
|
||||
|
||||
@@ -86,15 +87,6 @@ namespace OpenRA.FileFormats
|
||||
|
||||
/*var unknown3 = */reader.ReadChars(14);
|
||||
|
||||
Console.WriteLine("FORM Info");
|
||||
Console.WriteLine("\tVersion: {0}",version);
|
||||
Console.WriteLine("\tFlags: {0}",flags);
|
||||
Console.WriteLine("\tFrames: {0}",numFrames);
|
||||
Console.WriteLine("\tFramerate: {0}",framerate);
|
||||
Console.WriteLine("\tSize: {0}x{1}",width,height);
|
||||
Console.WriteLine("\tBlocksize: {0}x{1}",blockWidth,blockHeight);
|
||||
Console.WriteLine("\tAudio: {0}hz, {1} channel(s), {2} bit",freq, channels, bits);
|
||||
|
||||
// Decode FINF chunk
|
||||
if (new String(reader.ReadChars(4)) != "FINF")
|
||||
throw new InvalidDataException("Invalid vqa (invalid FINF section)");
|
||||
@@ -144,15 +136,14 @@ namespace OpenRA.FileFormats
|
||||
// Chunks are aligned on even bytes; advance by a byte if the next one is null
|
||||
if (reader.PeekChar() == 0) reader.ReadByte();
|
||||
}
|
||||
currentFrame++;
|
||||
if (++currentFrame == numFrames)
|
||||
currentFrame = 0;
|
||||
}
|
||||
|
||||
public Bitmap FrameData()
|
||||
public void FrameData(ref Bitmap frame)
|
||||
{
|
||||
Bitmap frame = new Bitmap(width, height);
|
||||
var bitmapData = frame.LockBits(new Rectangle(0, 0, width, height),
|
||||
ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
|
||||
|
||||
unsafe
|
||||
{
|
||||
int* c = (int*)bitmapData.Scan0;
|
||||
@@ -172,7 +163,6 @@ namespace OpenRA.FileFormats
|
||||
}
|
||||
}
|
||||
frame.UnlockBits(bitmapData);
|
||||
return frame;
|
||||
}
|
||||
|
||||
// VQA Frame
|
||||
|
||||
@@ -504,14 +504,6 @@ 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);
|
||||
|
||||
@@ -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">
|
||||
|
||||
62
OpenRA.Game/Widgets/VqaPlayerWidget.cs
Normal file
62
OpenRA.Game/Widgets/VqaPlayerWidget.cs
Normal 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,11 @@
|
||||
Container@ROOT:
|
||||
Children:
|
||||
VqaPlayer:
|
||||
X:WINDOW_RIGHT - 400
|
||||
Y:WINDOW_BOTTOM - 200
|
||||
Width:200
|
||||
Height:200
|
||||
Video:obel.vqa
|
||||
Background@MAINMENU_BG:
|
||||
Id:MAINMENU_BG
|
||||
X:(WINDOW_RIGHT - WIDTH)/2
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
VqaPlayer:
|
||||
X:WINDOW_RIGHT - 400
|
||||
Y:WINDOW_BOTTOM - 200
|
||||
Width:200
|
||||
Height:200
|
||||
Video:aagun.vqa
|
||||
Background@MAINMENU_BG:
|
||||
Id:MAINMENU_BG
|
||||
X:(WINDOW_RIGHT - WIDTH)/2
|
||||
|
||||
Reference in New Issue
Block a user