changed a lot in resources loading, how unknown textures are displayed and how corrupt textures are handled

This commit is contained in:
codeimp 2009-01-24 14:48:43 +00:00
parent 0a0e68f6f6
commit 1ae7813fad
23 changed files with 311 additions and 188 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 646 B

View file

@ -124,7 +124,7 @@
<Compile Include="Data\FileImage.cs" />
<Compile Include="Data\FlatImage.cs" />
<Compile Include="Data\ImageLoadState.cs" />
<Compile Include="Data\NullImage.cs" />
<Compile Include="Data\UnknownImage.cs" />
<Compile Include="Data\PatchNames.cs" />
<Compile Include="Data\PK3Reader.cs" />
<Compile Include="Data\Playpal.cs" />
@ -672,6 +672,7 @@
<EmbeddedResource Include="Resources\Crosshair.png" />
<EmbeddedResource Include="Resources\CrosshairBusy.png" />
<Content Include="Resources\DB2.ico" />
<EmbeddedResource Include="Resources\UnknownTexture3D.png" />
<None Include="Resources\Monster3.png" />
<None Include="Resources\Monster2.png" />
<None Include="Resources\Prefab2.png" />

View file

@ -458,7 +458,8 @@ namespace CodeImp.DoomBuilder.BuilderModes
{
// Show sector edit dialog
General.Interface.ShowEditSectors(selected);
General.Map.Map.Update();
// When a single sector was selected, deselect it now
if(selected.Count == 1)
{

View file

@ -75,7 +75,13 @@ namespace CodeImp.DoomBuilder.BuilderModes
{
Vector2D t1 = new Vector2D();
Vector2D t2 = new Vector2D();
if(Sidedef.MiddleTexture == "FOOBAR")
{
int g = 5;
}
// Texture given?
if((Sidedef.MiddleTexture.Length > 0) && (Sidedef.MiddleTexture[0] != '-'))
{

View file

@ -83,7 +83,7 @@ namespace CodeImp.DoomBuilder.Controls
// Initialize
InitializeComponent();
items = new List<ImageBrowserItem>();
list.TileSize = new Size(General.Map.Data.Previews.ImageWidth + 26, General.Map.Data.Previews.ImageHeight + 26);
list.TileSize = new Size(General.Map.Data.Previews.MaxImageWidth + 26, General.Map.Data.Previews.MaxImageHeight + 26);
// Move textbox with label
objectname.Left = label.Right + label.Margin.Right + objectname.Margin.Left;

View file

@ -97,9 +97,9 @@ namespace CodeImp.DoomBuilder.Controls
// Determine coordinates
SizeF textsize = g.MeasureString(this.Text, this.ListView.Font, bounds.Width * 2);
Rectangle imagerect = new Rectangle(bounds.Left + ((bounds.Width - General.Map.Data.Previews.ImageWidth) >> 1),
bounds.Top + ((bounds.Height - General.Map.Data.Previews.ImageHeight - (int)textsize.Height) >> 1),
General.Map.Data.Previews.ImageWidth, General.Map.Data.Previews.ImageHeight);
Rectangle imagerect = new Rectangle(bounds.Left + ((bounds.Width - General.Map.Data.Previews.MaxImageWidth) >> 1),
bounds.Top + ((bounds.Height - General.Map.Data.Previews.MaxImageHeight - (int)textsize.Height) >> 1),
General.Map.Data.Previews.MaxImageWidth, General.Map.Data.Previews.MaxImageHeight);
PointF textpos = new PointF(bounds.Left + ((float)bounds.Width - textsize.Width) * 0.5f, bounds.Bottom - textsize.Height - 2);
// Determine colors

View file

@ -141,7 +141,7 @@ namespace CodeImp.DoomBuilder.Controls
if(ti.Sprite.ToLowerInvariant().StartsWith(DataManager.INTERNAL_PREFIX) && (ti.Sprite.Length > DataManager.INTERNAL_PREFIX.Length))
{
spritename.Text = "";
General.DisplayZoomedImage(spritetex, General.Map.Data.GetSpriteImage(ti.Sprite).Bitmap);
General.DisplayZoomedImage(spritetex, General.Map.Data.GetSpriteImage(ti.Sprite).GetBitmap());
}
else if(ti.Sprite.Length <= 8)
{

View file

@ -74,6 +74,7 @@ namespace CodeImp.DoomBuilder.Data
// Special images
private ImageData missingtexture3d;
private ImageData unknowntexture3d;
private ImageData hourglass3d;
private ImageData crosshair;
private ImageData crosshairbusy;
@ -102,6 +103,7 @@ namespace CodeImp.DoomBuilder.Data
public List<string> FlatNames { get { return flatnames; } }
public bool IsDisposed { get { return isdisposed; } }
public ImageData MissingTexture3D { get { return missingtexture3d; } }
public ImageData UnknownTexture3D { get { return unknowntexture3d; } }
public ImageData Hourglass3D { get { return hourglass3d; } }
public ImageData Crosshair3D { get { return crosshair; } }
public ImageData CrosshairBusy3D { get { return crosshairbusy; } }
@ -140,6 +142,8 @@ namespace CodeImp.DoomBuilder.Data
// Load special images
missingtexture3d = new ResourceImage("MissingTexture3D.png");
missingtexture3d.LoadImage();
unknowntexture3d = new ResourceImage("UnknownTexture3D.png");
unknowntexture3d.LoadImage();
hourglass3d = new ResourceImage("Hourglass3D.png");
hourglass3d.LoadImage();
crosshair = new ResourceImage("Crosshair.png");
@ -160,6 +164,8 @@ namespace CodeImp.DoomBuilder.Data
Unload();
missingtexture3d.Dispose();
missingtexture3d = null;
unknowntexture3d.Dispose();
unknowntexture3d = null;
hourglass3d.Dispose();
hourglass3d = null;
crosshair.Dispose();
@ -721,7 +727,7 @@ namespace CodeImp.DoomBuilder.Data
else
{
// Return null image
return new NullImage();
return new UnknownImage(Properties.Resources.UnknownImage);
}
}
@ -845,7 +851,7 @@ namespace CodeImp.DoomBuilder.Data
else
{
// Return null image
return new NullImage();
return new UnknownImage(Properties.Resources.UnknownImage);
}
}
@ -997,7 +1003,7 @@ namespace CodeImp.DoomBuilder.Data
}
else
{
return new NullImage();
return new UnknownImage(Properties.Resources.UnknownImage);
}
}
else
@ -1038,7 +1044,7 @@ namespace CodeImp.DoomBuilder.Data
else
{
// Return null image
return new NullImage();
return new UnknownImage(Properties.Resources.UnknownImage);
}
}
}

View file

@ -118,17 +118,17 @@ namespace CodeImp.DoomBuilder.Data
// Not loaded?
if(bitmap == null)
{
General.WriteLogLine("WARNING: Image file '" + filepathname + "' data format could not be read, while loading texture '" + this.Name + "'!");
General.WriteLogLine("ERROR: Image file '" + filepathname + "' data format could not be read, while loading texture '" + this.Name + "'!");
loadfailed = true;
filedata.Dispose();
return;
}
// Get width and height from image
width = bitmap.Size.Width;
height = bitmap.Size.Height;
scaledwidth = (float)bitmap.Size.Width * scalex;
scaledheight = (float)bitmap.Size.Height * scaley;
else
{
// Get width and height from image
width = bitmap.Size.Width;
height = bitmap.Size.Height;
scaledwidth = (float)bitmap.Size.Width * scalex;
scaledheight = (float)bitmap.Size.Height * scaley;
}
// Pass on to base
filedata.Dispose();

View file

@ -77,28 +77,38 @@ namespace CodeImp.DoomBuilder.Data
if(reader is UnknownImageReader)
{
// Data is in an unknown format!
General.WriteLogLine("WARNING: Flat lump '" + Name + "' data format could not be read!");
General.WriteLogLine("ERROR: Flat lump '" + Name + "' data format could not be read!");
bitmap = null;
}
else
{
// Read data as bitmap
mem.Seek(0, SeekOrigin.Begin);
if(bitmap != null) bitmap.Dispose();
bitmap = reader.ReadAsBitmap(mem);
}
// Read data as bitmap
mem.Seek(0, SeekOrigin.Begin);
if(bitmap != null) bitmap.Dispose();
bitmap = reader.ReadAsBitmap(mem);
if(bitmap == null) return;
// Done
mem.Dispose();
// Get width and height from image
width = bitmap.Size.Width;
height = bitmap.Size.Height;
scaledwidth = (float)width * General.Map.Config.DefaultFlatScale;
scaledheight = (float)height * General.Map.Config.DefaultFlatScale;
if(bitmap != null)
{
// Get width and height from image
width = bitmap.Size.Width;
height = bitmap.Size.Height;
scaledwidth = (float)width * General.Map.Config.DefaultFlatScale;
scaledheight = (float)height * General.Map.Config.DefaultFlatScale;
}
else
{
loadfailed = true;
}
}
else
{
// Missing a patch lump!
General.WriteLogLine("WARNING: Missing flat lump '" + Name + "'!");
General.WriteLogLine("ERROR: Missing flat lump '" + Name + "'!");
loadfailed = true;
}
// Pass on to base

View file

@ -80,8 +80,6 @@ namespace CodeImp.DoomBuilder.Data
public string Name { get { return name; } }
public long LongName { get { return longname; } }
public bool UseColorCorrection { get { return usecolorcorrection; } set { usecolorcorrection = value; } }
//public Bitmap Bitmap { get { lock(this) { if(bitmap != null) return new Bitmap(bitmap); else return CodeImp.DoomBuilder.Properties.Resources.Hourglass; } } }
public Bitmap Bitmap { get { lock(this) { if(bitmap != null) return bitmap; else return CodeImp.DoomBuilder.Properties.Resources.Hourglass; } } }
public Texture Texture { get { lock(this) { return texture; } } }
public bool IsPreviewLoaded { get { return (previewstate == ImageLoadState.Ready); } }
public bool IsImageLoaded { get { return (imagestate == ImageLoadState.Ready); } }
@ -184,8 +182,30 @@ namespace CodeImp.DoomBuilder.Data
imagestate = ImageLoadState.None;
}
}
// This returns the bitmap image
public Bitmap GetBitmap()
{
lock(this)
{
// Image loaded successfully?
if(!loadfailed && (imagestate == ImageLoadState.Ready) && (bitmap != null))
{
return bitmap;
}
// Image loading failed?
else if(loadfailed)
{
return Properties.Resources.Failed;
}
else
{
return Properties.Resources.Hourglass;
}
}
}
// This loads theimage
// This loads the image
public void LoadImage()
{
// Keep original dimensions
@ -240,7 +260,7 @@ namespace CodeImp.DoomBuilder.Data
catch(Exception e)
{
bitmap = oldbitmap;
General.WriteLogLine("ERROR: Cannot lock image '" + name + "' for pixel format conversion. " + e.GetType().Name + ": " + e.Message);
General.WriteLogLine("WARNING: Cannot lock image '" + name + "' for pixel format conversion. " + e.GetType().Name + ": " + e.Message);
}
}
@ -254,7 +274,7 @@ namespace CodeImp.DoomBuilder.Data
}
catch(Exception e)
{
General.WriteLogLine("ERROR: Cannot lock image '" + name + "' for color correction. " + e.GetType().Name + ": " + e.Message);
General.WriteLogLine("WARNING: Cannot lock image '" + name + "' for color correction. " + e.GetType().Name + ": " + e.Message);
}
// Bitmap locked?
@ -274,10 +294,22 @@ namespace CodeImp.DoomBuilder.Data
// not try loading again until Reload Resources is used
loadfailed = true;
bitmap = new Bitmap(Properties.Resources.Failed);
}
if(bitmap != null)
{
width = bitmap.Size.Width;
height = bitmap.Size.Height;
scaledwidth = (float)bitmap.Size.Width * General.Map.Config.DefaultTextureScale;
scaledheight = (float)bitmap.Size.Height * General.Map.Config.DefaultTextureScale;
if((General.Map != null) && (General.Map.Config != null))
{
scaledwidth = (float)bitmap.Size.Width * General.Map.Config.DefaultTextureScale;
scaledheight = (float)bitmap.Size.Height * General.Map.Config.DefaultTextureScale;
}
else
{
scaledwidth = (float)bitmap.Size.Width;
scaledheight = (float)bitmap.Size.Height;
}
}
// Image is ready
@ -293,7 +325,7 @@ namespace CodeImp.DoomBuilder.Data
lock(this)
{
// Only do this when texture is not created yet
if(((texture == null) || (texture.Disposed)) && this.IsImageLoaded)
if(((texture == null) || (texture.Disposed)) && this.IsImageLoaded && !loadfailed)
{
Image img = bitmap;
if(loadfailed) img = Properties.Resources.Failed;
@ -327,7 +359,7 @@ namespace CodeImp.DoomBuilder.Data
lock(this)
{
// Preview ready?
if(previewstate == ImageLoadState.Ready)
if(!loadfailed && (previewstate == ImageLoadState.Ready))
{
// Draw preview
General.Map.Data.Previews.DrawPreview(previewindex, target, targetpos);
@ -336,15 +368,15 @@ namespace CodeImp.DoomBuilder.Data
else if(loadfailed)
{
// Draw error bitmap
targetpos = new Point(targetpos.X + ((General.Map.Data.Previews.ImageWidth - Properties.Resources.Hourglass.Width) >> 1),
targetpos.Y + ((General.Map.Data.Previews.ImageHeight - Properties.Resources.Hourglass.Height) >> 1));
targetpos = new Point(targetpos.X + ((General.Map.Data.Previews.MaxImageWidth - Properties.Resources.Hourglass.Width) >> 1),
targetpos.Y + ((General.Map.Data.Previews.MaxImageHeight - Properties.Resources.Hourglass.Height) >> 1));
target.DrawImageUnscaled(Properties.Resources.Failed, targetpos);
}
else
{
// Draw loading bitmap
targetpos = new Point(targetpos.X + ((General.Map.Data.Previews.ImageWidth - Properties.Resources.Hourglass.Width) >> 1),
targetpos.Y + ((General.Map.Data.Previews.ImageHeight - Properties.Resources.Hourglass.Height) >> 1));
targetpos = new Point(targetpos.X + ((General.Map.Data.Previews.MaxImageWidth - Properties.Resources.Hourglass.Width) >> 1),
targetpos.Y + ((General.Map.Data.Previews.MaxImageHeight - Properties.Resources.Hourglass.Height) >> 1));
target.DrawImageUnscaled(Properties.Resources.Hourglass, targetpos);
}
}

View file

@ -102,17 +102,17 @@ namespace CodeImp.DoomBuilder.Data
// Not loaded?
if(bitmap == null)
{
General.WriteLogLine("WARNING: Image file '" + filepathname + "' data format could not be read, while loading texture '" + this.Name + "'!");
General.WriteLogLine("ERROR: Image file '" + filepathname + "' data format could not be read, while loading texture '" + this.Name + "'!");
loadfailed = true;
filedata.Dispose();
return;
}
// Get width and height from image
width = bitmap.Size.Width;
height = bitmap.Size.Height;
scaledwidth = (float)bitmap.Size.Width * scalex;
scaledheight = (float)bitmap.Size.Height * scaley;
else
{
// Get width and height from image
width = bitmap.Size.Width;
height = bitmap.Size.Height;
scaledwidth = (float)bitmap.Size.Width * scalex;
scaledheight = (float)bitmap.Size.Height * scaley;
}
// Pass on to base
filedata.Dispose();

View file

@ -47,8 +47,8 @@ namespace CodeImp.DoomBuilder.Data
#region ================== Variables
// Dimensions of a single preview image
private int imagewidth = 64;
private int imageheight = 64;
private int maxpreviewwidth = 64;
private int maxpreviewheight = 64;
// Images
private List<Bitmap> images;
@ -64,8 +64,8 @@ namespace CodeImp.DoomBuilder.Data
#region ================== Properties
// Constants
public int ImageWidth { get { return imagewidth; } }
public int ImageHeight { get { return imageheight; } }
public int MaxImageWidth { get { return maxpreviewwidth; } }
public int MaxImageHeight { get { return maxpreviewheight; } }
// Disposing
internal bool IsDisposed { get { return isdisposed; } }
@ -89,8 +89,8 @@ namespace CodeImp.DoomBuilder.Data
// Initialize
images = new List<Bitmap>();
imageque = new Queue<ImageData>();
imagewidth = PREVIEW_SIZES[General.Settings.PreviewImageSize];
imageheight = PREVIEW_SIZES[General.Settings.PreviewImageSize];
maxpreviewwidth = PREVIEW_SIZES[General.Settings.PreviewImageSize];
maxpreviewheight = PREVIEW_SIZES[General.Settings.PreviewImageSize];
// We have no destructor
GC.SuppressFinalize(this);
@ -118,6 +118,8 @@ namespace CodeImp.DoomBuilder.Data
// This makes a preview for the given image and updates the image settings
private void MakeImagePreview(ImageData img)
{
int previewwidth, previewheight;
int imagewidth, imageheight;
Bitmap preview;
Graphics g;
@ -125,13 +127,23 @@ namespace CodeImp.DoomBuilder.Data
{
// Load image if needed
if(!img.IsImageLoaded) img.LoadImage();
if(!img.LoadFailed)
{
imagewidth = img.Width;
imageheight = img.Height;
}
else
{
imagewidth = img.GetBitmap().Size.Width;
imageheight = img.GetBitmap().Size.Height;
}
// Determine preview size
float scalex = (img.Width > imagewidth) ? ((float)imagewidth / (float)img.Width) : 1.0f;
float scaley = (img.Height > imageheight) ? ((float)imageheight / (float)img.Height) : 1.0f;
float scalex = (img.Width > maxpreviewwidth) ? ((float)maxpreviewwidth / (float)imagewidth) : 1.0f;
float scaley = (img.Height > maxpreviewheight) ? ((float)maxpreviewheight / (float)imageheight) : 1.0f;
float scale = Math.Min(scalex, scaley);
int previewwidth = (int)((float)img.Width * scale);
int previewheight = (int)((float)img.Height * scale);
previewwidth = (int)((float)imagewidth * scale);
previewheight = (int)((float)imageheight * scale);
// Make new image
preview = new Bitmap(previewwidth, previewheight, IMAGE_FORMAT);
@ -145,8 +157,8 @@ namespace CodeImp.DoomBuilder.Data
// Draw image onto atlas
Rectangle atlasrect = new Rectangle(0, 0, previewwidth, previewheight);
RectangleF imgrect = General.MakeZoomedRect(new Size(img.Width, img.Height), atlasrect);
g.DrawImage(img.Bitmap, imgrect);
RectangleF imgrect = General.MakeZoomedRect(new Size(imagewidth, imageheight), atlasrect);
g.DrawImage(img.GetBitmap(), imgrect);
g.Dispose();
// Unload image if no longer needed
@ -177,8 +189,8 @@ namespace CodeImp.DoomBuilder.Data
lock(images) { image = images[previewindex]; }
// Adjust offset for the size of the preview image
targetpos.X += (imagewidth - image.Width) >> 1;
targetpos.Y += (imageheight - image.Height) >> 1;
targetpos.X += (maxpreviewwidth - image.Width) >> 1;
targetpos.Y += (maxpreviewheight - image.Height) >> 1;
// Draw from atlas to target
lock(image)

View file

@ -70,6 +70,9 @@ namespace CodeImp.DoomBuilder.Data
lock(this)
{
// No failure checking here. I anything fails here, it is not the user's fault,
// because the resources this loads are in the assembly.
// Get resource from memory
bitmapdata = General.ThisAssembly.GetManifestResourceStream("CodeImp.DoomBuilder.Resources." + Name);
if(bitmap != null) bitmap.Dispose();

View file

@ -104,25 +104,31 @@ namespace CodeImp.DoomBuilder.Data
bitmap = null;
}
}
// Not loaded?
if(bitmap == null)
{
General.WriteLogLine("WARNING: Image lump '" + lumpname + "' data format could not be read, while loading texture '" + this.Name + "'!");
General.WriteLogLine("ERROR: Image lump '" + lumpname + "' data format could not be read, while loading texture '" + this.Name + "'!");
loadfailed = true;
return;
}
// Get width and height from image
width = bitmap.Size.Width;
height = bitmap.Size.Height;
scaledwidth = (float)width * scalex;
scaledheight = (float)height * scaley;
else
{
// Get width and height from image
width = bitmap.Size.Width;
height = bitmap.Size.Height;
scaledwidth = (float)width * scalex;
scaledheight = (float)height * scaley;
}
// Done
mem.Dispose();
}
else
{
General.WriteLogLine("ERROR: Image lump '" + lumpname + "' could not be found, while loading texture '" + this.Name + "'!");
loadfailed = true;
}
// Pass on to base
base.LocalLoadImage();
}

View file

@ -78,28 +78,37 @@ namespace CodeImp.DoomBuilder.Data
if(reader is UnknownImageReader)
{
// Data is in an unknown format!
General.WriteLogLine("WARNING: Sprite lump '" + Name + "' data format could not be read!");
General.WriteLogLine("ERROR: Sprite lump '" + Name + "' data format could not be read!");
bitmap = null;
}
else
{
// Read data as bitmap
mem.Seek(0, SeekOrigin.Begin);
if(bitmap != null) bitmap.Dispose();
bitmap = reader.ReadAsBitmap(mem);
}
// Read data as bitmap
mem.Seek(0, SeekOrigin.Begin);
if(bitmap != null) bitmap.Dispose();
bitmap = reader.ReadAsBitmap(mem);
if(bitmap == null) return;
// Done
mem.Dispose();
// Get width and height from image
width = bitmap.Size.Width;
height = bitmap.Size.Height;
scaledwidth = (float)bitmap.Size.Width;
scaledheight = (float)bitmap.Size.Height;
if(bitmap != null)
{
// Get width and height from image
width = bitmap.Size.Width;
height = bitmap.Size.Height;
scaledwidth = (float)bitmap.Size.Width;
scaledheight = (float)bitmap.Size.Height;
}
else
{
loadfailed = true;
}
}
else
{
// Missing a patch lump!
General.WriteLogLine("WARNING: Missing sprite lump '" + Name + "'!");
General.WriteLogLine("ERROR: Missing sprite lump '" + Name + "'!");
}
// Pass on to base

View file

@ -76,9 +76,9 @@ namespace CodeImp.DoomBuilder.Data
{
uint datalength = (uint)(width * height * sizeof(PixelColor));
IImageReader reader;
BitmapData bitmapdata;
BitmapData bitmapdata = null;
MemoryStream mem;
PixelColor* pixels;
PixelColor* pixels = (PixelColor*)0;
Stream patchdata;
byte[] membytes;
@ -101,57 +101,61 @@ namespace CodeImp.DoomBuilder.Data
{
// Unable to make bitmap
General.WriteLogLine("ERROR: Unable to load texture image '" + this.Name + "'. " + e.GetType().Name + ": " + e.Message);
return;
loadfailed = true;
}
// Go for all patches
foreach(TexturePatch p in patches)
if(!loadfailed)
{
// Get the patch data stream
patchdata = General.Map.Data.GetPatchData(p.lumpname);
if(patchdata != null)
// Go for all patches
foreach(TexturePatch p in patches)
{
// Copy patch data to memory
patchdata.Seek(0, SeekOrigin.Begin);
membytes = new byte[(int)patchdata.Length];
patchdata.Read(membytes, 0, (int)patchdata.Length);
mem = new MemoryStream(membytes);
mem.Seek(0, SeekOrigin.Begin);
// Get a reader for the data
reader = ImageDataFormat.GetImageReader(mem, ImageDataFormat.DOOMPICTURE, General.Map.Data.Palette);
if(reader is UnknownImageReader)
// Get the patch data stream
patchdata = General.Map.Data.GetPatchData(p.lumpname);
if(patchdata != null)
{
// Data is in an unknown format!
General.WriteLogLine("WARNING: Patch lump '" + p.lumpname + "' data format could not be read, while loading texture '" + this.Name + "'!");
loadfailed = true;
// Copy patch data to memory
patchdata.Seek(0, SeekOrigin.Begin);
membytes = new byte[(int)patchdata.Length];
patchdata.Read(membytes, 0, (int)patchdata.Length);
mem = new MemoryStream(membytes);
mem.Seek(0, SeekOrigin.Begin);
// Get a reader for the data
reader = ImageDataFormat.GetImageReader(mem, ImageDataFormat.DOOMPICTURE, General.Map.Data.Palette);
if(reader is UnknownImageReader)
{
// Data is in an unknown format!
General.WriteLogLine("ERROR: Patch lump '" + p.lumpname + "' data format could not be read, while loading texture '" + this.Name + "'!");
loadfailed = true;
}
else
{
// Draw the patch
mem.Seek(0, SeekOrigin.Begin);
try { reader.DrawToPixelData(mem, pixels, width, height, p.x, p.y); }
catch(InvalidDataException)
{
// Data cannot be read!
General.WriteLogLine("ERROR: Patch lump '" + p.lumpname + "' data format could not be read, while loading texture '" + this.Name + "'!");
loadfailed = true;
}
}
// Done
mem.Dispose();
}
else
{
// Draw the patch
mem.Seek(0, SeekOrigin.Begin);
try { reader.DrawToPixelData(mem, pixels, width, height, p.x, p.y); }
catch(InvalidDataException)
{
// Data cannot be read!
General.WriteLogLine("WARNING: Patch lump '" + p.lumpname + "' data format could not be read, while loading texture '" + this.Name + "'!");
loadfailed = true;
}
// Missing a patch lump!
General.WriteLogLine("ERROR: Missing patch lump '" + p.lumpname + "' while loading texture '" + this.Name + "'!");
loadfailed = true;
}
// Done
mem.Dispose();
}
else
{
// Missing a patch lump!
General.WriteLogLine("WARNING: Missing patch lump '" + p.lumpname + "' while loading texture '" + this.Name + "'!");
}
// Done
bitmap.UnlockBits(bitmapdata);
}
// Done
bitmap.UnlockBits(bitmapdata);
// Dispose bitmap if load failed
if(loadfailed && (bitmap != null))
{

View file

@ -31,18 +31,27 @@ using System.IO;
namespace CodeImp.DoomBuilder.Data
{
public sealed class NullImage : ImageData
public sealed class UnknownImage : ImageData
{
#region ================== Variables
private Bitmap loadbitmap = null;
#endregion
#region ================== Constructor / Disposer
// Constructor
public NullImage()
public UnknownImage(Bitmap image)
{
// Initialize
this.width = 0;
this.height = 0;
this.loadbitmap = image;
SetName("");
LocalLoadImage();
// We have no destructor
GC.SuppressFinalize(this);
}
@ -51,9 +60,22 @@ namespace CodeImp.DoomBuilder.Data
#region ================== Methods
// Dont do anything
protected override void LocalLoadImage() { bitmap = CodeImp.DoomBuilder.Properties.Resources.UnknownImage; }
internal override void CreateTexture() { }
// This 'loads' the image
protected override void LocalLoadImage()
{
bitmap = loadbitmap;
base.LocalLoadImage();
}
// This returns a preview image
public override Image GetPreview()
{
lock(this)
{
// Make a copy
return new Bitmap(loadbitmap);
}
}
#endregion
}

View file

@ -60,7 +60,7 @@ namespace CodeImp.DoomBuilder.Editing
// Background
private string background = "";
private int backsource;
private ImageData backimage = new NullImage();
private ImageData backimage = new UnknownImage(null);
private int backoffsetx, backoffsety;
private float backscalex, backscaley;

View file

@ -741,7 +741,7 @@ namespace CodeImp.DoomBuilder.Rendering
// Only if a background image is set
if((General.Map.Grid.Background != null) &&
!(General.Map.Grid.Background is NullImage))
!(General.Map.Grid.Background is UnknownImage))
{
// Make vertices
backimageverts = CreateScreenVerts(windowsize);
@ -1201,8 +1201,14 @@ namespace CodeImp.DoomBuilder.Rendering
ImageData img = General.Map.Data.GetFlatImage(longimagename);
if(img != null)
{
// Texture unknown?
if(img is UnknownImage)
{
General.Map.Data.UnknownTexture3D.CreateTexture();
t = General.Map.Data.UnknownTexture3D.Texture;
}
// Is the texture loaded?
if(img.IsImageLoaded)
else if(img.IsImageLoaded && !img.LoadFailed)
{
if(img.Texture == null) img.CreateTexture();
t = img.Texture;

View file

@ -517,7 +517,9 @@ namespace CodeImp.DoomBuilder.Rendering
ImageData curtexture;
// What texture to use?
if((group.Key != null) && group.Key.IsImageLoaded && !group.Key.IsDisposed)
if(group.Key is UnknownImage)
curtexture = General.Map.Data.UnknownTexture3D;
else if((group.Key != null) && group.Key.IsImageLoaded && !group.Key.IsDisposed)
curtexture = group.Key;
else
curtexture = General.Map.Data.Hourglass3D;
@ -571,43 +573,46 @@ namespace CodeImp.DoomBuilder.Rendering
foreach(KeyValuePair<ImageData, List<VisualThing>> group in thingspass)
{
ImageData curtexture;
// What texture to use?
if((group.Key != null) && group.Key.IsImageLoaded && !group.Key.IsDisposed)
curtexture = group.Key;
else
curtexture = General.Map.Data.Hourglass3D;
// Create Direct3D texture if still needed
if((curtexture.Texture == null) || curtexture.Texture.Disposed)
curtexture.CreateTexture();
// Apply texture
graphics.Device.SetTexture(0, curtexture.Texture);
graphics.Shaders.World3D.Texture1 = curtexture.Texture;
graphics.Shaders.World3D.ApplySettings();
// Render all things with this texture
foreach(VisualThing t in group.Value)
if(!(group.Key is UnknownImage))
{
// Update buffer if needed
t.Update();
// Only do this sector when a vertexbuffer is created
if(t.GeometryBuffer != null)
// What texture to use?
if((group.Key != null) && group.Key.IsImageLoaded && !group.Key.IsDisposed)
curtexture = group.Key;
else
curtexture = General.Map.Data.Hourglass3D;
// Create Direct3D texture if still needed
if((curtexture.Texture == null) || curtexture.Texture.Disposed)
curtexture.CreateTexture();
// Apply texture
graphics.Device.SetTexture(0, curtexture.Texture);
graphics.Shaders.World3D.Texture1 = curtexture.Texture;
graphics.Shaders.World3D.ApplySettings();
// Render all things with this texture
foreach(VisualThing t in group.Value)
{
// Create the matrix for positioning / rotation
world = t.Orientation;
if(t.Billboard) world = Matrix.Multiply(world, billboard);
world = Matrix.Multiply(world, t.Position);
ApplyMatrices3D();
graphics.Shaders.World3D.ApplySettings();
// Apply buffer
graphics.Device.SetStreamSource(0, t.GeometryBuffer, 0, WorldVertex.Stride);
// Render!
graphics.Device.DrawPrimitives(PrimitiveType.TriangleList, 0, t.Triangles);
// Update buffer if needed
t.Update();
// Only do this sector when a vertexbuffer is created
if(t.GeometryBuffer != null)
{
// Create the matrix for positioning / rotation
world = t.Orientation;
if(t.Billboard) world = Matrix.Multiply(world, billboard);
world = Matrix.Multiply(world, t.Position);
ApplyMatrices3D();
graphics.Shaders.World3D.ApplySettings();
// Apply buffer
graphics.Device.SetStreamSource(0, t.GeometryBuffer, 0, WorldVertex.Stride);
// Render!
graphics.Device.DrawPrimitives(PrimitiveType.TriangleList, 0, t.Triangles);
}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 646 B

View file

@ -51,13 +51,13 @@ namespace CodeImp.DoomBuilder.Windows
// Background image?
if((General.Map.Grid.Background != null) &&
!(General.Map.Grid.Background is NullImage))
!(General.Map.Grid.Background is UnknownImage))
{
// Show background image
showbackground.Checked = true;
backgroundname = General.Map.Grid.BackgroundName;
backgroundsource = General.Map.Grid.BackgroundSource;
General.DisplayZoomedImage(backgroundimage, General.Map.Grid.Background.Bitmap);
General.DisplayZoomedImage(backgroundimage, General.Map.Grid.Background.GetBitmap());
}
else
{
@ -101,7 +101,7 @@ namespace CodeImp.DoomBuilder.Windows
backgroundsource = GridSetup.SOURCE_TEXTURES;
ImageData img = General.Map.Data.GetTextureImage(result);
img.LoadImage();
General.DisplayZoomedImage(backgroundimage, img.Bitmap);
General.DisplayZoomedImage(backgroundimage, img.GetBitmap());
}
}
@ -119,7 +119,7 @@ namespace CodeImp.DoomBuilder.Windows
backgroundsource = GridSetup.SOURCE_FLATS;
ImageData img = General.Map.Data.GetFlatImage(result);
img.LoadImage();
General.DisplayZoomedImage(backgroundimage, img.Bitmap);
General.DisplayZoomedImage(backgroundimage, img.GetBitmap());
}
}
@ -134,7 +134,7 @@ namespace CodeImp.DoomBuilder.Windows
backgroundsource = GridSetup.SOURCE_FILE;
ImageData img = new FileImage(backgroundname, backgroundname, false, 1.0f, 1.0f);
img.LoadImage();
General.DisplayZoomedImage(backgroundimage, new Bitmap(img.Bitmap));
General.DisplayZoomedImage(backgroundimage, new Bitmap(img.GetBitmap()));
img.Dispose();
}
}