|
Ditto, I'm a newb when it comes to XNA, but somewhat experienced in general game dev.
I was involved a bit in Managed DirectX before they deprecated all of it: there were some good MDX sites like mdxinfo.com and thezbuffer.com. I think those sites have adapted to XNA now, they might be useful. For general game development, gameDev.net and gamasutra.com are the two mainstream ones.
|
|
|
|
|
|
I asked this question last week, but with the high wheat/chaff ratio it probably got missed...
I've run into an FxCop warning that I'm having a difficult time understanding how to get around it (other than simply supressing the message).
I have a class that implements multiple interfaces. These interfaces are:
public interface IHistoryService
{
bool Supported { get; }
Document Document { get; }
}
public interface IValidationService
{
bool Supported { get; }
ReadOnlyCollection ValidationErrors { get; }
} Since the interfaces both define bool Supported { get; } , I need to implement them explicitly. It is possible that, given different internal states, the IHistoryService functionality might be supported while the IValidationService functionality isn't (or vice versa).
For the sake of simplicity, here is a much slimmed down version of my implemenation class:
public class DocumentViewer : Form, IHistoryService, IValidationService
{
bool IHistoryService.Supported
{
get { return true; }
}
bool IValidationService.Supported
{
get { return true; }
}
} When I run FxCop against this assembly, I get the following warning:CA1033 : Microsoft.Design : Make 'DocumentViewer' sealed (a breaking change if this class has previously shipped), implement the method non-explicitly, or implement a new method that exposes the functionality of 'IDocumentInformationService.get_DocumentTemplateFullName():String' and is visible to derived classes. From the description on MSDN, it tells me:Consider a base type that explicitly implements a public interface method. A type that derives from the base type can only access the inherited interface method through a reference to the current instance (this in C#) that is cast to the interface. If the derived type re-implements (explicitly) the inherited interface method, the base implementation is no longer accessible. The call through the current instance reference will invoke the derived implementation; this results in recursion and an eventual stack overflow. So...I know I could implement
public bool Supported
{
get { return true; }
} which would satisfy the warning. The problem here is that this property doesn't make sense on the DocumentViewer, so it would be completely useless (other than to satisfy the warning).
How would I implement this so it satisfies the warning, or is this really even something to worry about?
|
|
|
|
|
I'm sure this won't help, but I'll put it out there. What if you just didn't have the Supported property?
If something doesn't support that interface, then just don't implement it on the object? Then, when you cast it to the interface, it just won't cast, thereby telling you that its not supported.
Granted, this assumes you do not have run time reasons for this property, but just wanted to throw that out there as a possibility.
As an aside, if FoxCop isn't telling you something you care to listen to, then..don't
|
|
|
|
|
Andrew Rissing wrote: What if you just didn't have the Supported property?
While this would work, it doesn't actually solve my problem. I need the interface implemented because the object in question always has the ability to provide those services but, because of internal state, might not support it at that moment in time.
Andrew Rissing wrote: As an aside, if FoxCop isn't telling you something you care to listen to, then..don't
I completely agree with you on this one and am actually ignoring the warning, but I still want to understand what it is really telling me and see if there is a "right" way to implement this.
|
|
|
|
|
Scott Dorman wrote: When I run FxCop against this assembly, I get the following warning:
CA1033 : Microsoft.Design : Make 'DocumentViewer' sealed
Can't you do that?
---
single minded; short sighted; long gone;
|
|
|
|
|
Yes, I can seal the class but I was trying to avoid doing that. I don't like sealing classes for what can only be termed an arbitrary reason.
|
|
|
|
|
I've had this one before, and frankly, I don't think it really is a problem. It seems to be a problem only if
1) you've got a class derived from DocumentViewer
and
2) that class needs to implement IDocumentInformationService outside of DocumentViewer's implementation.
I think that's a rare case to say the least. (I could be misunderstanding FxCop's warning, but that's my take on it.)
Perhaps one way to fix this is to create a protected method that exposes the functionality of DocumentTemplateFullName. Then this warning can essentially go away: either FxCop will be smart enough to recognize this, or you'd just throw a SurpressMessageAttribute on the DocumentViewer class.
|
|
|
|
|
I think you're right in that it will probably be a rare case where something does need to derive from DocumentViewer and needs to implement IDocumentInformationService itself. I may just go ahead and seal the class (as Guffa suggested) or add some SupressMessage attributes.
|
|
|
|
|
Hey,
I currently have a datagrid that is displaying items in an inventory. The user is able to modify inventory contents, and then there is a button to save the changes back to the SQL database.
What I would like to implement is something that will change the color of each row that the user has updated.
How do i do that? Need help ASAP.....
Im using C# with visual studio 2005
|
|
|
|
|
i think u cant get the changed rows from the datagrid.
u have to work with dataset
anyway may be the following link help u out
http://www.gridviewguy.com/ArticleDetails.aspx?articleID=92
|
|
|
|
|
http://msdn2.microsoft.com/en-us/library/thc1eetk(VS.80).aspx
|
|
|
|
|
Hello!
I have an interesting idea, I would like to read through a 24 bit JPEG image and determine the amount of a color is in the image. In this case I would like to analyze just how much red is in an image based on how many of the pixels are mostly red and return a value based on how many pixels are mostly red.
I need it to be fairly quick (~ 1 second) so I know that locking the bitmap and using unsafe code is the way to go. The problem is that I am having a hard time figuring out how to get the pixel data I want to get using the unsafe code method. I know that with the GetPixel method, it would be something like:
for (int h = 0; h < bmp.Height; h++)
{
for (int w = 0; w < bmp.Width; w++)
{
Color pixelColor = bmp.GetPixel(w, h);
int red = pixelColor.R;
int green = pixelColor.G;
int blue = pixelColor.B;
sumred += red;
How do I do this same procedure using the unsafe/locked bitmap method? Also, how do I do the logic/math to determine from this the amount of red data in the image?
Thank you in advance!!
Mike
|
|
|
|
|
Read my image processing articles. Basically, the bytes are laid out BGR, and there's a padding at the end of each scanline that you have to skip, which makes it WORD aligned.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Additionally, don't do for (int w = 0; w < bmp.Width; w++) , instead do:
int wid=bmp.Width;
for (int w=0; w<wid; w++)
This avoids bmp.Width to be calculated for every pixel, and results in a significant
speed gain (that is once you did everything else correctly, with lockbits, unsafe,
a pointer, etc. it will make a noticable difference in debug mode, not sure about
release mode).
-- modified at 18:11 Thursday 9th August, 2007: added debug/release nuance.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Dont use getpixel, it's slow. use lockbits instead and iterate trough the image.
http://www.codersource.net/csharp_image_processing.aspx
(look for Iterating through the Image header ;) )
one easy. probably not correct way to calc the amount of red would be to
have three variables, Red,Green and Blue and add the r, g and b value to them for each pixel.
red / (red+green+blue)=percentage of red..
hmm. staring at that makes me doubt it would produce correct numbers.
red would be 33.nnn% in grayscale image
hope it helps. may i ask what you're doing?
If it's stuck, DO NOT pull harder!
|
|
|
|
|
I wonder ... Maybe someone has an idear about this problem . . .
I have created a listview with 12 columns. When I select say 100 rows it takes about 2-3 seconds to copy them to the clipboard (for copying them to excel):
string sClipBoard = "";
for (int i = 0; i < listView1.SelectedItems.Count; i++)
{
sClipBoard = sClipBoard + listView1.SelectedItems[i].SubItems[1].Text + "\t" +
sClipBoard = sClipBoard + listView1.SelectedItems[i].SubItems[2].Text + "\t" +
etc.
}
finally: Clipboard.SetDataObject(sClipBoard, true);
OK. That works fine with 100 lines except: 200 l=9s 300l=20s 400l=35s 1000l= 3m30s
Replacing the string with a stringbuilder does not effect the speed.
Splitting the action in numbers of 100 does not effect the speed (neither different strings)
There has to be a better way ?
Any suggestion is welcome Thanks
|
|
|
|
|
First, figure out where your bottleneck is. If you comment out the Clipboard.SetDataObject call, is it still slow?
Here's my guess: all that string concatenation is killing performance. I'd try something like this:
StringBuilder builder = new StringBuilder(listView1.SelectedItems.Count * 50);
foreach (ListViewItem currentItem in listView1.SelectedItems)
{
builder.Append(currentItem.SubItems[1]);
builder.Append("\t");
builder.Append(currentItem.SubItems[2]);
}
finally: Clipboard.SetDataObject(builder.ToString(), true);
|
|
|
|
|
well the bottleneck seems to be the adding of the subitems.
If i leave out the clipboard the speed does not change.
If I just select subitems[1] it takes about 20 seconds for 1000 rows . . .
|
|
|
|
|
The string concatenation has to be the problem. Did you try this?
StringBuilder builder = new StringBuilder(listView1.SelectedItems.Count * 50);
foreach (ListViewItem currentItem in listView1.SelectedItems)
{
builder.Append(currentItem.SubItems[1]);
builder.Append("\t");
builder.Append(currentItem.SubItems[2]);
}
Clipboard.SetDataObject(builder.ToString(), true);
|
|
|
|
|
thanks for the quick reply, just built it in, for 400 rows it took 34 sec (-1)
For 1000 rows 3m43 (+13)
|
|
|
|
|
My mistake ... amazing ...
I took your last source but used the:
for(i=0; i< listview1 etc )
to correct it for a proper comparrising, i used the foreach routine
it takes for a 1000 rows about 1 second ??? for 3000 a second ???
WOW
and THANKS!!! i was 'rumbling' (if that's a correct word) with it for a couple of weeks
|
|
|
|
|
Interesting, however I'm a bit skeptical. Unless the listView.SelectedItems[index] makes some calls into native code, the for(...) loop should be just as fast -- if not slightly faster -- than foreach. You're sure the for(...) loop was slow even with the StringBuilder? I'd be really surprised if this was the case.
|
|
|
|
|
Actually it all depends on the cost of the termination test in the for loop;
that test gets executed for each iteration, if it entails a method or property lookup,
even when we know the result is or should be constant, it does not get optimized
and moved outside the loop, so it is executed over and over.
The biggest performance mistake in image processing is writing
for (int i=0; i<bitmap.Width; i++) for (int j=0; j<bitmap.Height; j++) ...
since that will probably spend more time interrogating the bitmap's boundaries
size than it does dealing with the actual pixels.
Another big victim is RichTextBox when looping over the text, testing for Text.Length,
which would recalculate the text over and over (and that's why I guess they also offer RichTextBox.TextLength).
-- modified at 17:50 Thursday 9th August, 2007 (patched the less-than sign)
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Luc,
I've been told by people smarter than myself that the JIT compiler will optimize out things like that which can be determined to not changed for the duration of the loop. Seems like this would be one of those cases...
|
|
|
|
|