remove duplicated NextPowerOf2 definition

This commit is contained in:
Chris Forbes
2011-07-12 20:49:15 +12:00
committed by Paul Chote
parent 2259a0e7a5
commit 2ec88a6f64
7 changed files with 55 additions and 75 deletions

View File

@@ -154,5 +154,16 @@ namespace OpenRA
{ {
for(;;) { yield return t; t = f(t); } for(;;) { yield return t; t = f(t); }
} }
public static int NextPowerOf2(int v)
{
--v;
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
++v;
return v;
}
} }
} }

View File

@@ -84,7 +84,7 @@ namespace OpenRA.FileFormats
/*var unknown3 = */reader.ReadChars(14); /*var unknown3 = */reader.ReadChars(14);
var frameSize = NextPowerOf2(Math.Max(Width,Height)); var frameSize = Exts.NextPowerOf2(Math.Max(Width,Height));
cbf = new byte[Width*Height]; cbf = new byte[Width*Height];
cbp = new byte[Width*Height]; cbp = new byte[Width*Height];
palette = new uint[numColors]; palette = new uint[numColors];
@@ -258,9 +258,8 @@ namespace OpenRA.FileFormats
} }
int cachedFrame = -1; int cachedFrame = -1;
public uint[,] FrameData { get
{ void DecodeFrameData( int frame )
if (cachedFrame != currentFrame)
{ {
cachedFrame = currentFrame; cachedFrame = currentFrame;
for (var y = 0; y < blocks.Y; y++) for (var y = 0; y < blocks.Y; y++)
@@ -277,18 +276,16 @@ namespace OpenRA.FileFormats
} }
} }
} }
return frameData;
}}
int NextPowerOf2(int v) public uint[,] FrameData
{ {
--v; get
v |= v >> 1; {
v |= v >> 2; if (cachedFrame != currentFrame)
v |= v >> 4; DecodeFrameData(currentFrame);
v |= v >> 8;
++v; return frameData;
return v; }
} }
} }
} }

View File

@@ -11,10 +11,10 @@
using System; using System;
using System.Drawing; using System.Drawing;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using System.IO;
using System.Linq; using System.Linq;
using OpenRA.FileFormats; using OpenRA.FileFormats;
using OpenRA.Traits; using OpenRA.Traits;
using System.IO;
namespace OpenRA.Graphics namespace OpenRA.Graphics
{ {
@@ -33,10 +33,10 @@ namespace OpenRA.Graphics
if (!actualSize) if (!actualSize)
{ {
width = height = Util.NextPowerOf2(Math.Max(map.Bounds.Width, map.Bounds.Height)); width = height = Exts.NextPowerOf2(Math.Max(map.Bounds.Width, map.Bounds.Height));
} }
Bitmap terrain = new Bitmap(width, height); var terrain = new Bitmap(width, height);
var bitmapData = terrain.LockBits(new Rectangle(0, 0, terrain.Width, terrain.Height), var bitmapData = terrain.LockBits(new Rectangle(0, 0, terrain.Width, terrain.Height),
ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
@@ -57,6 +57,7 @@ namespace OpenRA.Graphics
*(c + (y * bitmapData.Stride >> 2) + x) = tileset.Terrain[type].Color.ToArgb(); *(c + (y * bitmapData.Stride >> 2) + x) = tileset.Terrain[type].Color.ToArgb();
} }
} }
terrain.UnlockBits(bitmapData); terrain.UnlockBits(bitmapData);
return terrain; return terrain;
} }
@@ -92,6 +93,7 @@ namespace OpenRA.Graphics
*(c + (y * bitmapData.Stride >> 2) + x) = tileset.Terrain[res].Color.ToArgb(); *(c + (y * bitmapData.Stride >> 2) + x) = tileset.Terrain[res].Color.ToArgb();
} }
} }
terrain.UnlockBits(bitmapData); terrain.UnlockBits(bitmapData);
return terrain; return terrain;
@@ -100,8 +102,8 @@ namespace OpenRA.Graphics
public static Bitmap CustomTerrainBitmap(World world) public static Bitmap CustomTerrainBitmap(World world)
{ {
var map = world.Map; var map = world.Map;
var size = Util.NextPowerOf2(Math.Max(map.Bounds.Width, map.Bounds.Height)); var size = Exts.NextPowerOf2(Math.Max(map.Bounds.Width, map.Bounds.Height));
Bitmap bitmap = new Bitmap(size, size); var bitmap = new Bitmap(size, size);
var bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), var bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
@@ -120,6 +122,7 @@ namespace OpenRA.Graphics
*(c + (y * bitmapData.Stride >> 2) + x) = world.TileSet.Terrain[custom].Color.ToArgb(); *(c + (y * bitmapData.Stride >> 2) + x) = world.TileSet.Terrain[custom].Color.ToArgb();
} }
} }
bitmap.UnlockBits(bitmapData); bitmap.UnlockBits(bitmapData);
return bitmap; return bitmap;
} }
@@ -127,8 +130,8 @@ namespace OpenRA.Graphics
public static Bitmap ActorsBitmap(World world) public static Bitmap ActorsBitmap(World world)
{ {
var map = world.Map; var map = world.Map;
var size = Util.NextPowerOf2(Math.Max(map.Bounds.Width, map.Bounds.Height)); var size = Exts.NextPowerOf2(Math.Max(map.Bounds.Width, map.Bounds.Height));
Bitmap bitmap = new Bitmap(size, size); var bitmap = new Bitmap(size, size);
var bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), var bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
@@ -155,8 +158,8 @@ namespace OpenRA.Graphics
public static Bitmap ShroudBitmap(World world) public static Bitmap ShroudBitmap(World world)
{ {
var map = world.Map; var map = world.Map;
var size = Util.NextPowerOf2(Math.Max(map.Bounds.Width, map.Bounds.Height)); var size = Exts.NextPowerOf2(Math.Max(map.Bounds.Width, map.Bounds.Height));
Bitmap bitmap = new Bitmap(size, size); var bitmap = new Bitmap(size, size);
if (world.LocalShroud.Disabled) if (world.LocalShroud.Disabled)
return bitmap; return bitmap;

View File

@@ -102,16 +102,5 @@ namespace OpenRA.Graphics
{ {
return (int)((1 - t) * a + t * b); return (int)((1 - t) * a + t * b);
} }
public static int NextPowerOf2(int v)
{
--v;
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
++v;
return v;
}
} }
} }

View File

@@ -55,7 +55,7 @@ namespace OpenRA.Widgets
invLength = video.Framerate*1f/video.Frames; invLength = video.Framerate*1f/video.Frames;
var size = Math.Max(video.Width, video.Height); var size = Math.Max(video.Width, video.Height);
var textureSize = OpenRA.Graphics.Util.NextPowerOf2(size); var textureSize = Exts.NextPowerOf2(size);
videoSprite = new Sprite(new Sheet(new Size(textureSize,textureSize)), new Rectangle( 0, 0, video.Width, video.Height ), TextureChannel.Alpha); videoSprite = new Sprite(new Sheet(new Size(textureSize,textureSize)), new Rectangle( 0, 0, video.Width, video.Height ), TextureChannel.Alpha);
videoSprite.sheet.Texture.SetData(video.FrameData); videoSprite.sheet.Texture.SetData(video.FrameData);

View File

@@ -12,6 +12,7 @@ using System;
using System.Drawing; using System.Drawing;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using System.IO; using System.IO;
using OpenRA.FileFormats;
using OpenRA.FileFormats.Graphics; using OpenRA.FileFormats.Graphics;
using Tao.OpenGl; using Tao.OpenGl;
@@ -94,7 +95,7 @@ namespace OpenRA.Renderer.Cg
if (!IsPowerOf2(bitmap.Width) || !IsPowerOf2(bitmap.Height)) if (!IsPowerOf2(bitmap.Width) || !IsPowerOf2(bitmap.Height))
{ {
//throw new InvalidOperationException( "non-power-of-2-texture" ); //throw new InvalidOperationException( "non-power-of-2-texture" );
bitmap = new Bitmap(bitmap, new Size(NextPowerOf2(bitmap.Width), NextPowerOf2(bitmap.Height))); bitmap = new Bitmap(bitmap, new Size(Exts.NextPowerOf2(bitmap.Width), Exts.NextPowerOf2(bitmap.Height)));
} }
var bits = bitmap.LockBits( var bits = bitmap.LockBits(
@@ -114,16 +115,5 @@ namespace OpenRA.Renderer.Cg
{ {
return (v & (v - 1)) == 0; return (v & (v - 1)) == 0;
} }
int NextPowerOf2(int v)
{
--v;
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
++v;
return v;
}
} }
} }

View File

@@ -12,6 +12,7 @@ using System;
using System.Drawing; using System.Drawing;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using System.IO; using System.IO;
using OpenRA.FileFormats;
using OpenRA.FileFormats.Graphics; using OpenRA.FileFormats.Graphics;
using Tao.OpenGl; using Tao.OpenGl;
@@ -120,7 +121,7 @@ namespace OpenRA.Renderer.Glsl
if (!IsPowerOf2(bitmap.Width) || !IsPowerOf2(bitmap.Height)) if (!IsPowerOf2(bitmap.Width) || !IsPowerOf2(bitmap.Height))
{ {
//throw new InvalidOperationException( "non-power-of-2-texture" ); //throw new InvalidOperationException( "non-power-of-2-texture" );
bitmap = new Bitmap(bitmap, new Size(NextPowerOf2(bitmap.Width), NextPowerOf2(bitmap.Height))); bitmap = new Bitmap(bitmap, new Size(Exts.NextPowerOf2(bitmap.Width), Exts.NextPowerOf2(bitmap.Height)));
} }
var bits = bitmap.LockBits( var bits = bitmap.LockBits(
@@ -141,16 +142,5 @@ namespace OpenRA.Renderer.Glsl
{ {
return (v & (v - 1)) == 0; return (v & (v - 1)) == 0;
} }
int NextPowerOf2(int v)
{
--v;
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
++v;
return v;
}
} }
} }