|
becuase its 400 times more work....
you need less calls
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
you should cache your whole "world".
i.e. make your buffer as big as the world, and only redraw those in the 400 that have changed.
this way you should only have to do a few redraws..
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
World = 200x200 tiles.
Tile = 128x64 pixels.
As they overlap (isometric view),
let say it's 100x100 tiles.
That's still 81 920 000 pixels... Isn't it to much to store the whole background?
|
|
|
|
|
yes that is pretty big...
maybe you need to reconsider how you draw your world - maybe tiles are not a good idea...
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
Before I did this
graphics.DrawImage(backgroundSprite.Canvas.PictureFile,destinationRectangle,backgroundSprite.SourceRect,GraphicsUnit.Pixel);
and I had in memory one file with 9x9 tiles. I selected the tile from the source rectangle, and copied it in my PictureBox.
Now I have that :
graphics.DrawImage(backgroundCanvasArray[BackgroundCanvas].TilesArray[line,column],offsetX,offsetY);
and I have an array of tile 9x9.
Initialization is a bit longer, as I have to break my 9x9 tiles images into 81 images in an array.
But then, for the rendering I simply draw the tiles directly at the offset, without specifying a source and destination rectangle.
Result : rendering time for a 20x20 tiles world has dropped from 950 ms to 30 ms.
What took time was the resampling of the image to fit the new size, EVEN IF IT WAS THE SAME SIZE.
Now it works well enough
|
|
|
|
|
glad to here you fixed it!
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
Well your first and biggest mistake is not using direct x as a window in your application. GDI sucks for that type of application
Second you need to redraw based on regions.
My advice:
get rid of gdi+ dont even bother with it.
learn direct x and set up the buffered pages
one for the map, cities, and the objects then flip the pages and you ll get plenty of speed
nick
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
Beware of creating a large bitmap buffer every time you re-paint. Instead, create a new buffer bitmap when the window is resized. (You might already be doing this, but just checking.)
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
hi, I want to add grid control in my project as given in MS Project.
1. the problem is i couldn't find how to add no. of blank rows and columns like excel sheet. so, when i open new project it should be appeared blank sheet on the screen.
2.another thing how can i give functionality of tree view on clik on indent and outdent.
3. is there any ocx for network diagram, calendar control and gantt chart??
pls reply me soon.
-bhavin
|
|
|
|
|
if i have a string with multiple lines in it like this:
0 @IQLNP-M7@ INDI
1 NAME Benoni /THOMPSON/
2 GIVN Benoni
2 SURN THOMPSON
1 AFN QLNP-M7
1 SEX M
1 SOUR @S01@
1 BIRT
2 DATE 14 Apr 1782
2 PLAC Alstead, N.h.
1 DEAT
2 DATE 24 Oct 1857
2 PLAC Shalersville, N.h.
1 FAMS @F6073064@
1 FAMC @F6073065@
0 @IQLNP-KV@ INDI
1 NAME Job /THOMPSON/
2 GIVN Job
2 SURN THOMPSON
1 AFN QLNP-KV
1 SEX M
1 SOUR @S01@
1 FAMS @F6073065@
0 @IQLNP-L2@ INDI
1 NAME Lovice /CRANE/
2 GIVN Lovice
2 SURN CRANE
1 AFN QLNP-L2
1 SEX F
1 SOUR @S01@
1 FAMS @F6073065@
...
how would i split it into chunks from the '0' lines to the '0' lines, like this:
**Chunk 1**
0 @IQLNP-M7@ INDI
1 NAME Benoni /THOMPSON/
2 GIVN Benoni
2 SURN THOMPSON
1 AFN QLNP-M7
1 SEX M
1 SOUR @S01@
1 BIRT
2 DATE 14 Apr 1782
2 PLAC Alstead, N.h.
1 DEAT
2 DATE 24 Oct 1857
2 PLAC Shalersville, N.h.
1 FAMS @F6073064@
1 FAMC @F6073065@
**Chunk 2**
0 @IQLNP-KV@ INDI
1 NAME Job /THOMPSON/
2 GIVN Job
2 SURN THOMPSON
1 AFN QLNP-KV
1 SEX M
1 SOUR @S01@
1 FAMS @F6073065@
**Chunk 3**
0 @IQLNP-L2@ INDI
1 NAME Lovice /CRANE/
2 GIVN Lovice
2 SURN CRANE
1 AFN QLNP-L2
1 SEX F
1 SOUR @S01@
1 FAMS @F6073065@
...
etc.
thanks,
Rob
--
There are 10 kinds of people. Those who understand binary and those who don't.
|
|
|
|
|
When reading one line at a time check the value of the first character, if it is '0' you have reached your break point, else append it (a StringBuilder object would work nicely here). There are articles available for reading files in C# if this is what you are asking about. HTH.
-Nick Parker
|
|
|
|
|
i started out by reading each line one by one with a streamreader but i didn't want to access the file everytime i needed it so i read the whole thing at once and dumped it into a string. now i just need to figure out how to split the string up. i'll look into the stringbuilder class though.
thanks,
Rob
--
There are 10 kinds of people. Those who understand binary and those who don't.
|
|
|
|
|
Search for "\n0 @" in string (or use something faster like StringBuilder). Like this (check syntax, not tested):
string multiple=" ... ";
ArrayList chunks=new ArrayList(1);
while(multiple!="")
{
int p=multiple.IndexOf("\n0 @");
if(p<0)
{
chunks.Add(multiple);
break;
}
chunks.Add(multiple.Substring(0,p));
multiple=multiple.Substring(p+1);
}
Hi,
AW
|
|
|
|
|
could i use the string.split method and use "\n0 @" as the delimeter? btw, what does the @ mean in '\n0 @'?
thanks for the help,
Rob
--
There are 10 kinds of people. Those who understand binary and those who don't.
|
|
|
|
|
1. No. Unfortunately Split method uses chars ... You must use above one character "\n0"
2. All Your "0" groups starts with " @" after "0". It is unnecessary, new line and zero will be enough.
Hi,
AW
|
|
|
|
|
use RegExp
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
This seems to work - i'm sure it can be optimised though:
string s = "0 @IQLNP-M7@ INDI" + Environment.NewLine;
s += "1 NAME Benoni /THOMPSON/" + Environment.NewLine;
s += "2 GIVN Benoni" + Environment.NewLine;
s += "2 SURN THOMPSON" + Environment.NewLine;
s += "1 AFN QLNP-M7" + Environment.NewLine;
s += "1 SEX M" + Environment.NewLine;
s += "1 SOUR @S01@" + Environment.NewLine;
s += "1 BIRT" + Environment.NewLine;
s += "2 DATE 14 Apr 1782" + Environment.NewLine;
s += "2 PLAC Alstead, N.h." + Environment.NewLine;
s += "1 DEAT" + Environment.NewLine;
s += "2 DATE 24 Oct 1857" + Environment.NewLine;
s += "2 PLAC Shalersville, N.h." + Environment.NewLine;
s += "1 FAMS @F6073064@" + Environment.NewLine;
s += "1 FAMC @F6073065@" + Environment.NewLine;
s += "0 @IQLNP-KV@ INDI" + Environment.NewLine;
s += "1 NAME Job /THOMPSON/" + Environment.NewLine;
s += "2 GIVN Job" + Environment.NewLine;
s += "2 SURN THOMPSON" + Environment.NewLine;
s += "1 AFN QLNP-KV" + Environment.NewLine;
s += "1 SEX M" + Environment.NewLine;
s += "1 SOUR @S01@" + Environment.NewLine;
s += "1 FAMS @F6073065@" + Environment.NewLine;
s += "0 @IQLNP-L2@ INDI" + Environment.NewLine;
s += "1 NAME Lovice /CRANE/" + Environment.NewLine;
s += "2 GIVN Lovice" + Environment.NewLine;
s += "2 SURN CRANE" + Environment.NewLine;
s += "1 AFN QLNP-L2" + Environment.NewLine;
s += "1 SEX F" + Environment.NewLine;
s += "1 SOUR @S01@" + Environment.NewLine;
s += "1 FAMS @F6073065@" + Environment.NewLine;
int index = 0;
System.Collections.ArrayList indexList = new System.Collections.ArrayList();
indexList.Add(0);
while (index != -1)
{
index = s.IndexOf(Environment.NewLine + "0 ", index + 1, s.Length - (index + 1));
if(index != -1)
{
indexList.Add(index);
}
}
string[] splitStrings = new string[indexList.Count];
for(int i = 0 ; i < indexList.Count ; i++)
{
if(i == indexList.Count - 1)
{
splitStrings[i] = s.Substring(Convert.ToInt32(indexList[i]), s.Length - Convert.ToInt32(indexList[i]));
}
else
{
splitStrings[i] = s.Substring(Convert.ToInt32(indexList[i]), Convert.ToInt32(indexList[i+1])-Convert.ToInt32(indexList[i]));
}
if(splitStrings[i].StartsWith(Environment.NewLine))
{
splitStrings[i] = splitStrings[i].Substring(Environment.NewLine.Length, splitStrings[i].Length - Environment.NewLine.Length);
}
}
foreach(string newString in splitStrings)
{
MessageBox.Show(newString);
}
|
|
|
|
|
I created a Bitmap object like so
private void FOrm1_Paint( object sender, PaintEventArgs e )
{
Bitmap bmp = new Bitmap(100, 100, e.Grpahics);
}
what I want to do is draw rectangles and things like that inside. But inorder to do that I need to get a graphics object of its surface.
Anyone know how or pointers or links?
Maybe I have to convert it to a HBitmap, I font know!
nick
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
Ista wrote:
what I want to do is draw rectangles and things like that inside. But inorder to do that I need to get a graphics object of its surface.
You already have a Graphics object embedded within the PaintEventArgs, you are using it when you are creating the Bitmap object above when you access it like e.Graphics . You can continue using this object such as
e.Graphics.DrawLine(0, 0, this.Width, this.Height);
or
Graphics grfx = e.Graphics;
grfx.DrawLine(0, 0, this.Width, this.Height);
Either way works. HTH
-Nick Parker
|
|
|
|
|
yeah but its not contained within the bitmap. I want the bitmap to be a container so to speak. It will eventually be moved outside this after testing and then just draw the bitmap
nick
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
Ista wrote:
yeah but its not contained within the bitmap. I want the bitmap to be a container so to speak. It will eventually be moved outside this after testing and then just draw the bitmap
Not exactly sure what you mean by this Ista, check out my article Web Graphics On The Fly in ASP.NET[^] if you are still having questions about drawing to a Bitmap object. This articles covers the concept under ASP.NET but the idea is still the same whether or not it is for the web or a Windows application.
-Nick Parker
|
|
|
|
|
Like take MFC. to draw within a bitmap object you get a CDC object then call FillRect and such commands. Graphics object is just a context anyhow so how would I get a context to the bitmap?
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
Ista wrote:
Graphics object is just a context anyhow so how would I get a context to the bitmap?
Not exactly sure what you mean, are you having a problem with the following (which is within the article)? This ties the Graphics object to your Bitmap object.
Bitmap bmp = new Bitmap(this.Width, this.Height, PixelFormat.Format24bppRgb);
Graphics g = Graphics.FromImage(bmp);
-Nick Parker
|
|
|
|
|
Your my hero Nick
thanks,
nick
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
I got this sample from:
http://samples.gotdotnet.com/quickstart/util/srcview.aspx?path=/quickstart/howto/samples/cryptography/fileencrypt/encrypt.src&file=CS\fileencrypt.cs&font=3
Just wondering why there isn't a "key" in the code: You need a key for DES encryption don't you?
Here's the code snippet:
FileStream fs = new FileStream("EncryptedFile.txt",FileMode.Create,FileAccess.Write);
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
ICryptoTransform desencrypt = des.CreateEncryptor();
CryptoStream cryptostream = new CryptoStream(fs,desencrypt,CryptoStreamMode.Write);
cryptostream.Write(bytearrayinput,0,bytearrayinput.Length);
cryptostream.Close();
Thanks.
norm
|
|
|
|