mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2025-02-17 01:22:18 +00:00
fixes
This commit is contained in:
parent
c6eb815811
commit
996f65c809
19 changed files with 266 additions and 105 deletions
|
@ -207,6 +207,7 @@
|
|||
<Compile Include="Rendering\FlatVertex.cs" />
|
||||
<Compile Include="Rendering\ID3DResource.cs" />
|
||||
<Compile Include="Rendering\PixelColor.cs" />
|
||||
<Compile Include="Rendering\PixelColorBlock.cs" />
|
||||
<Compile Include="Rendering\Plotter.cs" />
|
||||
<Compile Include="Rendering\Renderer.cs" />
|
||||
<Compile Include="Rendering\Renderer2D.cs" />
|
||||
|
|
|
@ -371,8 +371,9 @@ namespace CodeImp.DoomBuilder.Data
|
|||
// This loads the textures
|
||||
private void LoadTextures()
|
||||
{
|
||||
PatchNames pnames = new PatchNames();
|
||||
ICollection<ImageData> images;
|
||||
PatchNames pnames = new PatchNames();
|
||||
PatchNames newpnames;
|
||||
|
||||
// Go for all opened containers
|
||||
foreach(DataReader dr in containers)
|
||||
|
@ -381,20 +382,19 @@ namespace CodeImp.DoomBuilder.Data
|
|||
// Note that pnames is NOT set to null in the loop
|
||||
// because if a container has no pnames, the pnames
|
||||
// of the previous (higher) container should be used.
|
||||
pnames = dr.LoadPatchNames();
|
||||
if(pnames != null)
|
||||
newpnames = dr.LoadPatchNames();
|
||||
if(newpnames != null) pnames = newpnames;
|
||||
|
||||
// Load textures
|
||||
images = dr.LoadTextures(pnames);
|
||||
if(images != null)
|
||||
{
|
||||
// Load textures
|
||||
images = dr.LoadTextures(pnames);
|
||||
if(images != null)
|
||||
// Go for all textures
|
||||
foreach(ImageData img in images)
|
||||
{
|
||||
// Go for all textures
|
||||
foreach(ImageData img in images)
|
||||
{
|
||||
// Add or replace in textures list
|
||||
textures.Remove(img.LongName);
|
||||
textures.Add(img.LongName, img);
|
||||
}
|
||||
// Add or replace in textures list
|
||||
textures.Remove(img.LongName);
|
||||
textures.Add(img.LongName, img);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,7 +95,74 @@ namespace CodeImp.DoomBuilder.Data
|
|||
#endregion
|
||||
|
||||
#region ================== Textures
|
||||
|
||||
// This loads the textures
|
||||
public override ICollection<ImageData> LoadTextures(PatchNames pnames)
|
||||
{
|
||||
// Error when suspended
|
||||
if(issuspended) throw new Exception("Data reader is suspended");
|
||||
|
||||
// Should we load the images in this directory as textures?
|
||||
if(readtextures) return LoadDirectoryImages(); else return null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Flats
|
||||
|
||||
// This loads the textures
|
||||
public override ICollection<ImageData> LoadFlats()
|
||||
{
|
||||
// Error when suspended
|
||||
if(issuspended) throw new Exception("Data reader is suspended");
|
||||
|
||||
// Should we load the images in this directory as flats?
|
||||
if(readflats) return LoadDirectoryImages(); else return null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Methods
|
||||
|
||||
// This loads the images in this directory
|
||||
private ICollection<ImageData> LoadDirectoryImages()
|
||||
{
|
||||
List<ImageData> images = new List<ImageData>();
|
||||
string[] files;
|
||||
string name;
|
||||
|
||||
// Find all BMP files
|
||||
files = Directory.GetFiles(location.location, "*.bmp", SearchOption.TopDirectoryOnly);
|
||||
|
||||
// Find all GIF files and append to files array
|
||||
AddToArray(ref files, Directory.GetFiles(location.location, "*.gif", SearchOption.TopDirectoryOnly));
|
||||
|
||||
// Find all PNG files and append to files array
|
||||
AddToArray(ref files, Directory.GetFiles(location.location, "*.png", SearchOption.TopDirectoryOnly));
|
||||
|
||||
// Go for all files
|
||||
foreach(string f in files)
|
||||
{
|
||||
// Make the texture name from filename without extension
|
||||
name = Path.GetFileNameWithoutExtension(f).ToUpperInvariant();
|
||||
if(name.Length > 8) name = name.Substring(0, 8);
|
||||
|
||||
// Add image to list
|
||||
images.Add(new FileImage(name, f));
|
||||
}
|
||||
|
||||
// Return result
|
||||
return images;
|
||||
}
|
||||
|
||||
// This resizes a string array and adds to it
|
||||
private void AddToArray(ref string[] array, string[] add)
|
||||
{
|
||||
int insertindex = array.Length;
|
||||
Array.Resize<string>(ref array, array.Length + add.Length);
|
||||
add.CopyTo(array, insertindex);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,11 +40,11 @@ namespace CodeImp.DoomBuilder.Data
|
|||
#region ================== Constructor / Disposer
|
||||
|
||||
// Constructor
|
||||
public FileImage(string filepathname)
|
||||
public FileImage(string name, string filepathname)
|
||||
{
|
||||
// Initialize
|
||||
this.filepathname = filepathname;
|
||||
SetName(Path.GetFileNameWithoutExtension(filepathname));
|
||||
SetName(name);
|
||||
|
||||
// We have no destructor
|
||||
GC.SuppressFinalize(this);
|
||||
|
|
|
@ -52,8 +52,7 @@ namespace CodeImp.DoomBuilder.Data
|
|||
protected Bitmap bitmap;
|
||||
|
||||
// 2D rendering data
|
||||
private PixelColor* pixeldata = null;
|
||||
private uint pixeldatasize;
|
||||
private PixelColorBlock pixeldata;
|
||||
|
||||
// Direct3D texture
|
||||
private Texture texture;
|
||||
|
@ -67,7 +66,7 @@ namespace CodeImp.DoomBuilder.Data
|
|||
|
||||
public string Name { get { return name; } }
|
||||
public long LongName { get { return longname; } }
|
||||
public PixelColor* PixelData { get { lock(this) { return pixeldata; } } }
|
||||
public PixelColorBlock PixelData { get { lock(this) { return pixeldata; } } }
|
||||
public Bitmap Bitmap { get { lock(this) { return bitmap; } } }
|
||||
public Texture Texture { get { lock(this) { return texture; } } }
|
||||
public bool IsLoaded { get { return (bitmap != null); } }
|
||||
|
@ -99,13 +98,8 @@ namespace CodeImp.DoomBuilder.Data
|
|||
// Clean up
|
||||
if(bitmap != null) bitmap.Dispose();
|
||||
if(texture != null) texture.Dispose();
|
||||
if(pixeldata != null)
|
||||
{
|
||||
General.VirtualFree((void*)pixeldata, new UIntPtr(pixeldatasize), General.MEM_RELEASE);
|
||||
pixeldata = null;
|
||||
GC.RemoveMemoryPressure(pixeldatasize);
|
||||
}
|
||||
|
||||
pixeldata = null;
|
||||
|
||||
// Done
|
||||
isdisposed = true;
|
||||
}
|
||||
|
@ -138,21 +132,11 @@ namespace CodeImp.DoomBuilder.Data
|
|||
// Only do this when data is not created yet
|
||||
if((pixeldata == null) && IsLoaded)
|
||||
{
|
||||
// Clean up old memory if reserved
|
||||
if(pixeldata != null)
|
||||
{
|
||||
General.VirtualFree((void*)pixeldata, new UIntPtr(pixeldatasize), General.MEM_RELEASE);
|
||||
pixeldata = null;
|
||||
GC.RemoveMemoryPressure(pixeldatasize);
|
||||
}
|
||||
|
||||
// Make a data copy of the bits for the 2D renderer
|
||||
bmpdata = bitmap.LockBits(new Rectangle(0, 0, bitmap.Size.Width, bitmap.Size.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
|
||||
pixeldatasize = (uint)(bmpdata.Width * bmpdata.Height * sizeof(PixelColor));
|
||||
pixeldata = (PixelColor*)General.VirtualAlloc(IntPtr.Zero, new UIntPtr(pixeldatasize), General.MEM_COMMIT, General.PAGE_READWRITE);
|
||||
General.CopyMemory((void*)pixeldata, bmpdata.Scan0.ToPointer(), new UIntPtr(pixeldatasize));
|
||||
pixeldata = new PixelColorBlock(bitmap.Size.Width, bitmap.Size.Height);
|
||||
General.CopyMemory((void*)pixeldata.Pointer, bmpdata.Scan0.ToPointer(), new UIntPtr(pixeldata.Length));
|
||||
bitmap.UnlockBits(bmpdata);
|
||||
GC.AddMemoryPressure(pixeldatasize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,8 @@ namespace CodeImp.DoomBuilder.Data
|
|||
// Get resource from memory
|
||||
bitmapdata = General.ThisAssembly.GetManifestResourceStream("CodeImp.DoomBuilder.Resources." + Name);
|
||||
bitmap = (Bitmap)Image.FromStream(bitmapdata);
|
||||
|
||||
bitmapdata.Dispose();
|
||||
|
||||
// Pass on to base
|
||||
base.LoadImage();
|
||||
}
|
||||
|
|
|
@ -115,12 +115,13 @@ namespace CodeImp.DoomBuilder.Data
|
|||
// Data is in an unknown format!
|
||||
General.WriteLogLine("WARNING: Patch lump '" + p.lumpname + "' data format could not be read, while loading texture '" + this.Name + "'!");
|
||||
failed = true;
|
||||
break;
|
||||
}
|
||||
|
||||
// Draw the patch
|
||||
mem.Seek(0, SeekOrigin.Begin);
|
||||
reader.DrawToPixelData(mem, pixels, width, height, p.x, p.y);
|
||||
else
|
||||
{
|
||||
// Draw the patch
|
||||
mem.Seek(0, SeekOrigin.Begin);
|
||||
reader.DrawToPixelData(mem, pixels, width, height, p.x, p.y);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -133,7 +134,11 @@ namespace CodeImp.DoomBuilder.Data
|
|||
bitmap.UnlockBits(bitmapdata);
|
||||
|
||||
// When failed, use the error picture
|
||||
if(failed) bitmap = UnknownImageReader.ReadAsBitmap();
|
||||
if(failed)
|
||||
{
|
||||
bitmap.Dispose();
|
||||
bitmap = UnknownImageReader.ReadAsBitmap();
|
||||
}
|
||||
|
||||
// Pass on to base
|
||||
base.LoadImage();
|
||||
|
|
|
@ -131,7 +131,10 @@ namespace CodeImp.DoomBuilder.Data
|
|||
List<ImageData> images = new List<ImageData>();
|
||||
string rangestart, rangeend;
|
||||
Lump lump;
|
||||
|
||||
|
||||
// Error when suspended
|
||||
if(issuspended) throw new Exception("Data reader is suspended");
|
||||
|
||||
// Load two sets of textures, if available
|
||||
lump = file.FindLump("TEXTURE1");
|
||||
if(lump != null) LoadTextureSet(lump.Stream, ref images, pnames);
|
||||
|
@ -206,7 +209,7 @@ namespace CodeImp.DoomBuilder.Data
|
|||
byte[] namebytes;
|
||||
TextureImage image;
|
||||
bool strifedata;
|
||||
|
||||
|
||||
// Determine default scale
|
||||
defaultscale = General.Map.Config.DefaultTextureScale;
|
||||
|
||||
|
@ -310,7 +313,10 @@ namespace CodeImp.DoomBuilder.Data
|
|||
public override Stream GetPatchData(string pname)
|
||||
{
|
||||
Lump lump;
|
||||
|
||||
|
||||
// Error when suspended
|
||||
if(issuspended) throw new Exception("Data reader is suspended");
|
||||
|
||||
// Find the lump
|
||||
lump = file.FindLump(pname);
|
||||
if(lump != null) return lump.Stream; else return null;
|
||||
|
@ -326,6 +332,9 @@ namespace CodeImp.DoomBuilder.Data
|
|||
List<ImageData> images = new List<ImageData>();
|
||||
string rangestart, rangeend;
|
||||
|
||||
// Error when suspended
|
||||
if(issuspended) throw new Exception("Data reader is suspended");
|
||||
|
||||
// Read ranges from configuration
|
||||
foreach(DictionaryEntry r in General.Map.Config.FlatRanges)
|
||||
{
|
||||
|
@ -386,6 +395,9 @@ namespace CodeImp.DoomBuilder.Data
|
|||
{
|
||||
Lump lump;
|
||||
|
||||
// Error when suspended
|
||||
if(issuspended) throw new Exception("Data reader is suspended");
|
||||
|
||||
// Find the lump
|
||||
lump = file.FindLump(pname);
|
||||
if(lump != null) return lump.Stream; else return null;
|
||||
|
@ -400,6 +412,9 @@ namespace CodeImp.DoomBuilder.Data
|
|||
{
|
||||
Lump lump;
|
||||
|
||||
// Error when suspended
|
||||
if(issuspended) throw new Exception("Data reader is suspended");
|
||||
|
||||
// Find the lump
|
||||
lump = file.FindLump(pname);
|
||||
if(lump != null) return lump.Stream; else return null;
|
||||
|
|
|
@ -51,13 +51,6 @@ namespace CodeImp.DoomBuilder
|
|||
[DllImport("kernel32.dll", EntryPoint = "RtlMoveMemory", SetLastError = false)]
|
||||
public static extern unsafe void CopyMemory(void* dst, void* src, UIntPtr length);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
public static unsafe extern void* VirtualAlloc(IntPtr lpAddress, UIntPtr dwSize, uint flAllocationType, uint flProtect);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static unsafe extern bool VirtualFree(void* lpAddress, UIntPtr dwSize, uint dwFreeType);
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Constants
|
||||
|
|
|
@ -879,6 +879,13 @@ namespace CodeImp.DoomBuilder
|
|||
General.MainWindow.DisplayStatus("Reloading data resources...");
|
||||
Cursor.Current = Cursors.WaitCursor;
|
||||
|
||||
// Clean up
|
||||
config = null;
|
||||
configinfo = null;
|
||||
data.Dispose();
|
||||
data = null;
|
||||
GC.Collect();
|
||||
|
||||
// Reload game configuration
|
||||
General.WriteLogLine("Reloading game configuration...");
|
||||
configinfo = General.GetConfigurationInfo(options.ConfigFile);
|
||||
|
@ -886,7 +893,6 @@ namespace CodeImp.DoomBuilder
|
|||
|
||||
// Reload data resources
|
||||
General.WriteLogLine("Reloading data resources...");
|
||||
data.Dispose();
|
||||
data = new DataManager();
|
||||
maplocation = new DataLocation(DataLocation.RESOURCE_WAD, filepathname, false, false);
|
||||
data.Load(configinfo.Resources, options.Resources, maplocation);
|
||||
|
|
|
@ -197,6 +197,9 @@ namespace CodeImp.DoomBuilder.IO
|
|||
{
|
||||
// Standard new configuration
|
||||
NewConfiguration();
|
||||
|
||||
// We have no destructor
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
// Constructor
|
||||
|
@ -204,6 +207,9 @@ namespace CodeImp.DoomBuilder.IO
|
|||
{
|
||||
// Standard new configuration
|
||||
NewConfiguration(sorted);
|
||||
|
||||
// We have no destructor
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
// Constructor to load a file immediately
|
||||
|
@ -211,6 +217,9 @@ namespace CodeImp.DoomBuilder.IO
|
|||
{
|
||||
// Load configuration from file
|
||||
LoadConfiguration(filename);
|
||||
|
||||
// We have no destructor
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
// Constructor to load a file immediately
|
||||
|
@ -218,6 +227,9 @@ namespace CodeImp.DoomBuilder.IO
|
|||
{
|
||||
// Load configuration from file
|
||||
LoadConfiguration(filename, sorted);
|
||||
|
||||
// We have no destructor
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -86,7 +86,7 @@ namespace CodeImp.DoomBuilder.IO
|
|||
public Bitmap ReadAsBitmap(Stream stream)
|
||||
{
|
||||
BitmapData bitmapdata;
|
||||
PixelColor* pixeldata;
|
||||
PixelColorBlock pixeldata;
|
||||
PixelColor* targetdata;
|
||||
int width, height;
|
||||
Bitmap bmp;
|
||||
|
@ -101,13 +101,10 @@ namespace CodeImp.DoomBuilder.IO
|
|||
targetdata = (PixelColor*)bitmapdata.Scan0.ToPointer();
|
||||
|
||||
// Copy the pixels
|
||||
General.CopyMemory((void*)targetdata, (void*)pixeldata, new UIntPtr((uint)(width * height * sizeof(PixelColor))));
|
||||
General.CopyMemory((void*)targetdata, (void*)pixeldata.Pointer, new UIntPtr((uint)(width * height * sizeof(PixelColor))));
|
||||
|
||||
// Done
|
||||
bmp.UnlockBits(bitmapdata);
|
||||
|
||||
// Free memory
|
||||
General.VirtualFree((void*)pixeldata, new UIntPtr((uint)(width * height * sizeof(PixelColor))), General.MEM_RELEASE);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -157,17 +154,17 @@ namespace CodeImp.DoomBuilder.IO
|
|||
|
||||
// Done
|
||||
bmp.UnlockBits(bmpdata);
|
||||
bmp.Dispose();
|
||||
}
|
||||
|
||||
// This creates pixel color data from the given data
|
||||
// Returns null on failure
|
||||
private PixelColor* ReadAsPixelData(Stream stream, out int width, out int height)
|
||||
private PixelColorBlock ReadAsPixelData(Stream stream, out int width, out int height)
|
||||
{
|
||||
BinaryReader reader = new BinaryReader(stream);
|
||||
PixelColor* pixeldata = null;
|
||||
PixelColorBlock pixeldata = null;
|
||||
float sqrlength;
|
||||
byte[] bytes;
|
||||
uint datalength = 0;
|
||||
|
||||
// Check if the flat is square
|
||||
sqrlength = (float)Math.Sqrt(stream.Length);
|
||||
|
@ -201,16 +198,15 @@ namespace CodeImp.DoomBuilder.IO
|
|||
if((width <= 0) || (height <= 0)) return null;
|
||||
|
||||
// Allocate memory
|
||||
datalength = (uint)(sizeof(PixelColor) * width * height);
|
||||
pixeldata = (PixelColor*)General.VirtualAlloc(IntPtr.Zero, new UIntPtr(datalength), General.MEM_COMMIT, General.PAGE_READWRITE);
|
||||
General.ZeroMemory(new IntPtr(pixeldata), (int)datalength);
|
||||
pixeldata = new PixelColorBlock(width, height);
|
||||
pixeldata.Clear();
|
||||
|
||||
// Read flat bytes from stream
|
||||
bytes = new byte[width * height];
|
||||
stream.Read(bytes, 0, width * height);
|
||||
|
||||
// Convert bytes with palette
|
||||
for(uint i = 0; i < width * height; i++) pixeldata[i] = palette[bytes[i]];
|
||||
for(uint i = 0; i < width * height; i++) pixeldata.Pointer[i] = palette[bytes[i]];
|
||||
|
||||
// Return pointer
|
||||
return pixeldata;
|
||||
|
@ -219,9 +215,6 @@ namespace CodeImp.DoomBuilder.IO
|
|||
}
|
||||
catch(Exception)
|
||||
{
|
||||
// Free memory if allocated
|
||||
if(datalength > 0) General.VirtualFree((void*)pixeldata, new UIntPtr(datalength), General.MEM_RELEASE);
|
||||
|
||||
// Return nothing
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@ namespace CodeImp.DoomBuilder.IO
|
|||
public Bitmap ReadAsBitmap(Stream stream)
|
||||
{
|
||||
BitmapData bitmapdata;
|
||||
PixelColor* pixeldata;
|
||||
PixelColorBlock pixeldata;
|
||||
PixelColor* targetdata;
|
||||
int width, height, x, y;
|
||||
Bitmap bmp;
|
||||
|
@ -117,13 +117,10 @@ namespace CodeImp.DoomBuilder.IO
|
|||
targetdata = (PixelColor*)bitmapdata.Scan0.ToPointer();
|
||||
|
||||
// Copy the pixels
|
||||
General.CopyMemory((void*)targetdata, (void*)pixeldata, new UIntPtr((uint)(width * height * sizeof(PixelColor))));
|
||||
General.CopyMemory((void*)targetdata, (void*)pixeldata.Pointer, new UIntPtr((uint)(width * height * sizeof(PixelColor))));
|
||||
|
||||
// Done
|
||||
bmp.UnlockBits(bitmapdata);
|
||||
|
||||
// Free memory
|
||||
General.VirtualFree((void*)pixeldata, new UIntPtr((uint)(width * height * sizeof(PixelColor))), General.MEM_RELEASE);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -139,7 +136,7 @@ namespace CodeImp.DoomBuilder.IO
|
|||
// Throws exception on failure
|
||||
public void DrawToPixelData(Stream stream, PixelColor* target, int targetwidth, int targetheight, int x, int y)
|
||||
{
|
||||
PixelColor* pixeldata;
|
||||
PixelColorBlock pixeldata;
|
||||
int width, height, ox, oy, tx, ty;
|
||||
|
||||
// Read pixel data
|
||||
|
@ -153,29 +150,25 @@ namespace CodeImp.DoomBuilder.IO
|
|||
for(oy = 0; oy < height; oy++)
|
||||
{
|
||||
// Copy this pixel?
|
||||
if(pixeldata[oy * width + ox].a > 0.5f)
|
||||
if(pixeldata.Pointer[oy * width + ox].a > 0.5f)
|
||||
{
|
||||
// Calculate target pixel and copy when within bounds
|
||||
tx = x + ox;
|
||||
ty = y + oy;
|
||||
if((tx >= 0) && (tx < targetwidth) && (ty >= 0) && (ty < targetheight))
|
||||
target[ty * targetwidth + tx] = pixeldata[oy * width + ox];
|
||||
target[ty * targetwidth + tx] = pixeldata.Pointer[oy * width + ox];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Free memory
|
||||
General.VirtualFree((void*)pixeldata, new UIntPtr((uint)(width * height * sizeof(PixelColor))), General.MEM_RELEASE);
|
||||
}
|
||||
}
|
||||
|
||||
// This creates pixel color data from the given data
|
||||
// Returns null on failure
|
||||
private PixelColor* ReadAsPixelData(Stream stream, out int width, out int height, out int offsetx, out int offsety)
|
||||
private PixelColorBlock ReadAsPixelData(Stream stream, out int width, out int height, out int offsetx, out int offsety)
|
||||
{
|
||||
BinaryReader reader = new BinaryReader(stream);
|
||||
PixelColor* pixeldata = null;
|
||||
uint datalength = 0;
|
||||
PixelColorBlock pixeldata = null;
|
||||
int y, count, p;
|
||||
int[] columns;
|
||||
int dataoffset;
|
||||
|
@ -209,9 +202,8 @@ namespace CodeImp.DoomBuilder.IO
|
|||
for(int x = 0; x < width; x++) columns[x] = reader.ReadInt32();
|
||||
|
||||
// Allocate memory
|
||||
datalength = (uint)(sizeof(PixelColor) * width * height);
|
||||
pixeldata = (PixelColor*)General.VirtualAlloc(IntPtr.Zero, new UIntPtr(datalength), General.MEM_COMMIT, General.PAGE_READWRITE);
|
||||
General.ZeroMemory(new IntPtr(pixeldata), (int)datalength);
|
||||
pixeldata = new PixelColorBlock(width, height);
|
||||
pixeldata.Clear();
|
||||
|
||||
// Go for all columns
|
||||
for(int x = 0; x < width; x++)
|
||||
|
@ -238,7 +230,7 @@ namespace CodeImp.DoomBuilder.IO
|
|||
p = reader.ReadByte();
|
||||
|
||||
// Draw pixel
|
||||
pixeldata[(y + yo) * width + x] = palette[p];
|
||||
pixeldata.Pointer[(y + yo) * width + x] = palette[p];
|
||||
}
|
||||
|
||||
// Skip unused pixel
|
||||
|
@ -256,9 +248,6 @@ namespace CodeImp.DoomBuilder.IO
|
|||
}
|
||||
catch(Exception)
|
||||
{
|
||||
// Free memory if allocated
|
||||
if(datalength > 0) General.VirtualFree((void*)pixeldata, new UIntPtr(datalength), General.MEM_RELEASE);
|
||||
|
||||
// Return nothing
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -92,6 +92,7 @@ namespace CodeImp.DoomBuilder.IO
|
|||
|
||||
// Done
|
||||
bmp.UnlockBits(bmpdata);
|
||||
bmp.Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -98,6 +98,7 @@ namespace CodeImp.DoomBuilder.IO
|
|||
|
||||
// Done
|
||||
bmp.UnlockBits(bmpdata);
|
||||
bmp.Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -67,17 +67,11 @@ namespace CodeImp.DoomBuilder.Interface
|
|||
this.Opacity = 100;
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
// Block this
|
||||
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
|
||||
{
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// DelayedForm
|
||||
//
|
||||
this.ClientSize = new System.Drawing.Size(292, 273);
|
||||
this.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.Name = "DelayedForm";
|
||||
this.ResumeLayout(false);
|
||||
|
||||
//return base.ProcessCmdKey(ref msg, keyData);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
4
Source/Interface/MainForm.Designer.cs
generated
4
Source/Interface/MainForm.Designer.cs
generated
|
@ -147,7 +147,6 @@ namespace CodeImp.DoomBuilder.Interface
|
|||
this.menumain.Name = "menumain";
|
||||
this.menumain.Size = new System.Drawing.Size(839, 24);
|
||||
this.menumain.TabIndex = 0;
|
||||
this.menumain.Text = "menuStrip1";
|
||||
//
|
||||
// menufile
|
||||
//
|
||||
|
@ -363,7 +362,6 @@ namespace CodeImp.DoomBuilder.Interface
|
|||
this.toolbar.Name = "toolbar";
|
||||
this.toolbar.Size = new System.Drawing.Size(839, 25);
|
||||
this.toolbar.TabIndex = 1;
|
||||
this.toolbar.Text = "toolStrip1";
|
||||
//
|
||||
// buttonnewmap
|
||||
//
|
||||
|
@ -488,7 +486,7 @@ namespace CodeImp.DoomBuilder.Interface
|
|||
this.statuslabel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
|
||||
this.statuslabel.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None;
|
||||
this.statuslabel.Name = "statuslabel";
|
||||
this.statuslabel.Size = new System.Drawing.Size(597, 18);
|
||||
this.statuslabel.Size = new System.Drawing.Size(628, 18);
|
||||
this.statuslabel.Spring = true;
|
||||
this.statuslabel.Text = "Initializing user interface...";
|
||||
this.statuslabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
|
||||
|
|
|
@ -35,7 +35,7 @@ using CodeImp.DoomBuilder.Map;
|
|||
|
||||
namespace CodeImp.DoomBuilder.Interface
|
||||
{
|
||||
public partial class MainForm : Form
|
||||
public partial class MainForm : DelayedForm
|
||||
{
|
||||
#region ================== Constants
|
||||
|
||||
|
|
101
Source/Rendering/PixelColorBlock.cs
Normal file
101
Source/Rendering/PixelColorBlock.cs
Normal file
|
@ -0,0 +1,101 @@
|
|||
|
||||
#region ================== Copyright (c) 2007 Pascal vd Heiden
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
|
||||
* This program is released under GNU General Public License
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Namespaces
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Reflection;
|
||||
using System.Drawing;
|
||||
using SlimDX.Direct3D;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace CodeImp.DoomBuilder.Rendering
|
||||
{
|
||||
public unsafe class PixelColorBlock
|
||||
{
|
||||
#region ================== API Declarations
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
private static unsafe extern void* VirtualAlloc(IntPtr lpAddress, UIntPtr dwSize, uint flAllocationType, uint flProtect);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static unsafe extern bool VirtualFree(void* lpAddress, UIntPtr dwSize, uint dwFreeType);
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Variables
|
||||
|
||||
private int width;
|
||||
private int height;
|
||||
private uint memorysize;
|
||||
private PixelColor* memory;
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Properties
|
||||
|
||||
public int Width { get { return width; } }
|
||||
public int Height { get { return height; } }
|
||||
public uint Length { get { return memorysize; } }
|
||||
public PixelColor this[int index] { get { return memory[index]; } set { memory[index] = value; } }
|
||||
public PixelColor* Pointer { get { return memory; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Constructor / Destructor
|
||||
|
||||
// Constructor
|
||||
public PixelColorBlock(int width, int height)
|
||||
{
|
||||
// Check input
|
||||
if((width <= 0) || (height <= 0)) throw new ArgumentException("Cannot allocate a memory block of zero size!");
|
||||
|
||||
// Initialize
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.memorysize = (uint)width * (uint)height * (uint)sizeof(PixelColor);
|
||||
this.memory = (PixelColor*)VirtualAlloc(IntPtr.Zero, new UIntPtr(memorysize), General.MEM_COMMIT, General.PAGE_READWRITE);
|
||||
GC.AddMemoryPressure(memorysize);
|
||||
}
|
||||
|
||||
// Destructor
|
||||
~PixelColorBlock()
|
||||
{
|
||||
// Terminate
|
||||
VirtualFree((void*)memory, new UIntPtr(memorysize), General.MEM_RELEASE);
|
||||
GC.RemoveMemoryPressure(memorysize);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Methods
|
||||
|
||||
// This clears the memory black
|
||||
public void Clear()
|
||||
{
|
||||
General.ZeroMemory(new IntPtr(memory), (int)memorysize);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue