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

View file

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

View file

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

View file

@ -83,7 +83,7 @@ namespace CodeImp.DoomBuilder.Controls
// Initialize // Initialize
InitializeComponent(); InitializeComponent();
items = new List<ImageBrowserItem>(); 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 // Move textbox with label
objectname.Left = label.Right + label.Margin.Right + objectname.Margin.Left; objectname.Left = label.Right + label.Margin.Right + objectname.Margin.Left;

View file

@ -97,9 +97,9 @@ namespace CodeImp.DoomBuilder.Controls
// Determine coordinates // Determine coordinates
SizeF textsize = g.MeasureString(this.Text, this.ListView.Font, bounds.Width * 2); 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), Rectangle imagerect = new Rectangle(bounds.Left + ((bounds.Width - General.Map.Data.Previews.MaxImageWidth) >> 1),
bounds.Top + ((bounds.Height - General.Map.Data.Previews.ImageHeight - (int)textsize.Height) >> 1), bounds.Top + ((bounds.Height - General.Map.Data.Previews.MaxImageHeight - (int)textsize.Height) >> 1),
General.Map.Data.Previews.ImageWidth, General.Map.Data.Previews.ImageHeight); 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); PointF textpos = new PointF(bounds.Left + ((float)bounds.Width - textsize.Width) * 0.5f, bounds.Bottom - textsize.Height - 2);
// Determine colors // 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)) if(ti.Sprite.ToLowerInvariant().StartsWith(DataManager.INTERNAL_PREFIX) && (ti.Sprite.Length > DataManager.INTERNAL_PREFIX.Length))
{ {
spritename.Text = ""; 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) else if(ti.Sprite.Length <= 8)
{ {

View file

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

View file

@ -118,17 +118,17 @@ namespace CodeImp.DoomBuilder.Data
// Not loaded? // Not loaded?
if(bitmap == null) 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; loadfailed = true;
filedata.Dispose();
return;
} }
else
// Get width and height from image {
width = bitmap.Size.Width; // Get width and height from image
height = bitmap.Size.Height; width = bitmap.Size.Width;
scaledwidth = (float)bitmap.Size.Width * scalex; height = bitmap.Size.Height;
scaledheight = (float)bitmap.Size.Height * scaley; scaledwidth = (float)bitmap.Size.Width * scalex;
scaledheight = (float)bitmap.Size.Height * scaley;
}
// Pass on to base // Pass on to base
filedata.Dispose(); filedata.Dispose();

View file

@ -77,28 +77,38 @@ namespace CodeImp.DoomBuilder.Data
if(reader is UnknownImageReader) if(reader is UnknownImageReader)
{ {
// Data is in an unknown format! // 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 // Done
mem.Dispose(); mem.Dispose();
// Get width and height from image if(bitmap != null)
width = bitmap.Size.Width; {
height = bitmap.Size.Height; // Get width and height from image
scaledwidth = (float)width * General.Map.Config.DefaultFlatScale; width = bitmap.Size.Width;
scaledheight = (float)height * General.Map.Config.DefaultFlatScale; height = bitmap.Size.Height;
scaledwidth = (float)width * General.Map.Config.DefaultFlatScale;
scaledheight = (float)height * General.Map.Config.DefaultFlatScale;
}
else
{
loadfailed = true;
}
} }
else else
{ {
// Missing a patch lump! // Missing a patch lump!
General.WriteLogLine("WARNING: Missing flat lump '" + Name + "'!"); General.WriteLogLine("ERROR: Missing flat lump '" + Name + "'!");
loadfailed = true;
} }
// Pass on to base // Pass on to base

View file

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

View file

@ -102,17 +102,17 @@ namespace CodeImp.DoomBuilder.Data
// Not loaded? // Not loaded?
if(bitmap == null) 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; loadfailed = true;
filedata.Dispose();
return;
} }
else
// Get width and height from image {
width = bitmap.Size.Width; // Get width and height from image
height = bitmap.Size.Height; width = bitmap.Size.Width;
scaledwidth = (float)bitmap.Size.Width * scalex; height = bitmap.Size.Height;
scaledheight = (float)bitmap.Size.Height * scaley; scaledwidth = (float)bitmap.Size.Width * scalex;
scaledheight = (float)bitmap.Size.Height * scaley;
}
// Pass on to base // Pass on to base
filedata.Dispose(); filedata.Dispose();

View file

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

View file

@ -70,6 +70,9 @@ namespace CodeImp.DoomBuilder.Data
lock(this) 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 // Get resource from memory
bitmapdata = General.ThisAssembly.GetManifestResourceStream("CodeImp.DoomBuilder.Resources." + Name); bitmapdata = General.ThisAssembly.GetManifestResourceStream("CodeImp.DoomBuilder.Resources." + Name);
if(bitmap != null) bitmap.Dispose(); if(bitmap != null) bitmap.Dispose();

View file

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

View file

@ -78,28 +78,37 @@ namespace CodeImp.DoomBuilder.Data
if(reader is UnknownImageReader) if(reader is UnknownImageReader)
{ {
// Data is in an unknown format! // 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 // Done
mem.Dispose(); mem.Dispose();
// Get width and height from image if(bitmap != null)
width = bitmap.Size.Width; {
height = bitmap.Size.Height; // Get width and height from image
scaledwidth = (float)bitmap.Size.Width; width = bitmap.Size.Width;
scaledheight = (float)bitmap.Size.Height; height = bitmap.Size.Height;
scaledwidth = (float)bitmap.Size.Width;
scaledheight = (float)bitmap.Size.Height;
}
else
{
loadfailed = true;
}
} }
else else
{ {
// Missing a patch lump! // Missing a patch lump!
General.WriteLogLine("WARNING: Missing sprite lump '" + Name + "'!"); General.WriteLogLine("ERROR: Missing sprite lump '" + Name + "'!");
} }
// Pass on to base // Pass on to base

View file

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

View file

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

View file

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

View file

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

View file

@ -517,7 +517,9 @@ namespace CodeImp.DoomBuilder.Rendering
ImageData curtexture; ImageData curtexture;
// What texture to use? // 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; curtexture = group.Key;
else else
curtexture = General.Map.Data.Hourglass3D; curtexture = General.Map.Data.Hourglass3D;
@ -571,43 +573,46 @@ namespace CodeImp.DoomBuilder.Rendering
foreach(KeyValuePair<ImageData, List<VisualThing>> group in thingspass) foreach(KeyValuePair<ImageData, List<VisualThing>> group in thingspass)
{ {
ImageData curtexture; ImageData curtexture;
// What texture to use? if(!(group.Key is UnknownImage))
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)
{ {
// Update buffer if needed // What texture to use?
t.Update(); if((group.Key != null) && group.Key.IsImageLoaded && !group.Key.IsDisposed)
curtexture = group.Key;
// Only do this sector when a vertexbuffer is created else
if(t.GeometryBuffer != null) 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 // Update buffer if needed
world = t.Orientation; t.Update();
if(t.Billboard) world = Matrix.Multiply(world, billboard);
world = Matrix.Multiply(world, t.Position); // Only do this sector when a vertexbuffer is created
ApplyMatrices3D(); if(t.GeometryBuffer != null)
graphics.Shaders.World3D.ApplySettings(); {
// Create the matrix for positioning / rotation
// Apply buffer world = t.Orientation;
graphics.Device.SetStreamSource(0, t.GeometryBuffer, 0, WorldVertex.Stride); if(t.Billboard) world = Matrix.Multiply(world, billboard);
world = Matrix.Multiply(world, t.Position);
// Render! ApplyMatrices3D();
graphics.Device.DrawPrimitives(PrimitiveType.TriangleList, 0, t.Triangles); 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? // Background image?
if((General.Map.Grid.Background != null) && if((General.Map.Grid.Background != null) &&
!(General.Map.Grid.Background is NullImage)) !(General.Map.Grid.Background is UnknownImage))
{ {
// Show background image // Show background image
showbackground.Checked = true; showbackground.Checked = true;
backgroundname = General.Map.Grid.BackgroundName; backgroundname = General.Map.Grid.BackgroundName;
backgroundsource = General.Map.Grid.BackgroundSource; backgroundsource = General.Map.Grid.BackgroundSource;
General.DisplayZoomedImage(backgroundimage, General.Map.Grid.Background.Bitmap); General.DisplayZoomedImage(backgroundimage, General.Map.Grid.Background.GetBitmap());
} }
else else
{ {
@ -101,7 +101,7 @@ namespace CodeImp.DoomBuilder.Windows
backgroundsource = GridSetup.SOURCE_TEXTURES; backgroundsource = GridSetup.SOURCE_TEXTURES;
ImageData img = General.Map.Data.GetTextureImage(result); ImageData img = General.Map.Data.GetTextureImage(result);
img.LoadImage(); img.LoadImage();
General.DisplayZoomedImage(backgroundimage, img.Bitmap); General.DisplayZoomedImage(backgroundimage, img.GetBitmap());
} }
} }
@ -119,7 +119,7 @@ namespace CodeImp.DoomBuilder.Windows
backgroundsource = GridSetup.SOURCE_FLATS; backgroundsource = GridSetup.SOURCE_FLATS;
ImageData img = General.Map.Data.GetFlatImage(result); ImageData img = General.Map.Data.GetFlatImage(result);
img.LoadImage(); img.LoadImage();
General.DisplayZoomedImage(backgroundimage, img.Bitmap); General.DisplayZoomedImage(backgroundimage, img.GetBitmap());
} }
} }
@ -134,7 +134,7 @@ namespace CodeImp.DoomBuilder.Windows
backgroundsource = GridSetup.SOURCE_FILE; backgroundsource = GridSetup.SOURCE_FILE;
ImageData img = new FileImage(backgroundname, backgroundname, false, 1.0f, 1.0f); ImageData img = new FileImage(backgroundname, backgroundname, false, 1.0f, 1.0f);
img.LoadImage(); img.LoadImage();
General.DisplayZoomedImage(backgroundimage, new Bitmap(img.Bitmap)); General.DisplayZoomedImage(backgroundimage, new Bitmap(img.GetBitmap()));
img.Dispose(); img.Dispose();
} }
} }