Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

232 Neutral

About BradSnobar

  • Rank
  1. It looks to me like you are operating on a single character at a time. That is a bigger bottleneck than converting the bytes. Try receiving a group of bytes and converting them all at once. Also, there is a a BufferedStream to help speed up the overall process. Here is an example: http://www.yoda.arachsys.com/csharp/readbinary.html
  2. Hello all, I'm trying to figure out how to draw a line using the inverse of the background color GDI in C#. I have a gradient background, and I'm using a Path object to draw a line between a couple of boxes. Is there a brush tha that will draw inverse of a color? Anybody know some tricks here? Thanks!
  3. BradSnobar

    [.net] C# and GUI threads

    I've done this. Don't use the Timer component. Instead use a Thread timer. See usage for a .Net render surface here and create your own OnPaint event. private System.Threading.Timer frameTimer; private System.Threading.TimerCallback frameTimerCallback; private int frameNumber = 0; //what number frame are we currently on? 0..60 private const int frameRate = 60; public RenderSurface() //constructor { InitializeComponent(); this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); this.SetStyle(ControlStyles.ResizeRedraw, true); this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); } public void Begin() { this.frameTimerCallback = new System.Threading.TimerCallback(frameCallBack); this.frameTimer = new System.Threading.Timer(this.frameTimerCallback); this.frameTimer.Change(0, 1000 / frameRate); //start immediatly. } private void frameCallBack(object obj) { this.frameNumber++; if (frameNumber >= frameRate) this.frameNumber = 0; this.Invalidate(); //calls Paint which triggers a render }
  4. In situations where I need a simple script language I often use an old style of basic script like gwbasic as my basis. The lines can be executed one line at a time, so they are perfect for fast interpreted langugae. The interpreter can be created in less than 1000 lines of code. Nesting can be almost completely avoided which makes the interpreter much easier to write and very simple to maintain. http://en.wikipedia.org/wiki/BASIC 10 INPUT "What is your name: ", U$ 20 PRINT "Hello "; U$ 30 INPUT "How many stars do you want: ", N 40 S$ = "" 50 FOR I = 1 TO N 60 S$ = S$ + "*" 70 NEXT I 80 PRINT S$ 90 INPUT "Do you want more stars? ", A$ 100 IF LEN(A$) = 0 THEN GOTO 90 110 A$ = LEFT$(A$, 1) 120 IF A$ = "Y" OR A$ = "y" THEN GOTO 30 130 PRINT "Goodbye "; U$ 140 END A start to a basic compiler in C#, so you can see how quickly this type of thing can go together using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace basic { class Program { static void Main(string[] args) { string[] lines = System.IO.File.ReadAllLines(args[0]); Dictionary<string, string> variables = new Dictionary<string,string>(); Dictionary<string, int> linePointer = new Dictionary<string, int>(); FillLinePointerTable(lines, linePointer); for (int cp = 0; cp < lines.Length; cp++) { string line = lines[cp].Trim(); string[] tokens = line.Split(new char[] { ' ' }); switch (tokens[1].ToLower().Trim()) { case "input": System.Console.WriteLine(tokens[2]); string result = System.Console.ReadLine(); string key = tokens[3]; variables[key] = result; break; case "print": System.Console.WriteLine(tokens[2]); break; case "goto": string c = tokens[2]; cp = linePointer[c]; break; case "if": //check condition //true --> exeucte statement //false --> move to else clause break; } } } private static void FillLinePointerTable(string[] lines, Dictionary<string, int> linePointer) { for (int cp = 0; cp < lines.Length; cp++) { string line = lines[cp]; string[] tokens = line.Split(new char[] { ' ' }); linePointer.Add(tokens[0], cp); } } } }
  5. You need to first make sure that you read all the bytes coming down the stream. Check the number of bytes returned by your read command and keep reading them until you get the number of bytes that you were supposed to get. There is a return value on your socket read method. More than likely, you are not doing that and consecutive reads are picking up bytes that were meant for an earlier stream. If that doesn't solve it then you'll need to post some code for us to look at.
  6. There is a good book on the subject here: TCP/IP Sockets in C#: Practical Guide for Programmers http://www.amazon.com/TCP-IP-Sockets-Practical-Programmers/dp/0124660517/ref=sr_1_6?ie=UTF8&s=books&qid=1242345884&sr=8-6
  7. Visaul C++ express is using the integrated shell already and has the support built in. You could have a user just download and use that instead. On another note, the shell is just a shell. Languages like F# can be custom added to it as is the case with the one that you donwloaded. You are probably looking for your own integrated solution. To do so you will want your own compiler or maybe use a free compiler. You could integrate it with the shell and then wrap up the executable inside. Execute the compiler using the System.Diagnostics.Process class to start the cc.exe or cl.exe for c++. If you want debugger support then you can research that and make wrap that up in the shell too. Actually this is usually how the compiler is called in your favorite tools. The window that pops up is just hidden with certain flags during startup.
  8. BradSnobar

    [java] benefits of Java question

    Thanks very much for the replies! They were very informative and helpful!
  9. I've been wondering about the main benefits of Java over other languages. I'm a C# developer for the most part but I've been finding Java somewhat intriguing for a while. So, I've been wondering what Java is best used for nowadays. What are its strongest benefits? I'm just curious and hopeful that some of the comments here will help me understand more about the Java culture and enlighten me. Afterwards, I want to perhaps make some useful Java applications so if you have some pet projects that you want to share ideas about, then I would be glad to hear about them for some inspiration. Thanks much!
  10. BradSnobar

    [.net] Test Record and Playback

    Thanks both for the help. I'll try that recorder tool. Also, I tend to agree with Capn Midnight's assesment, and I do have a fairly thin GUI with a large business logic layer and backend. It will mostly be tested through that layer. Mostly I'm just looking for some superficial GUI macro stuff to help me run through a very superficial set of sniff tests. It'll help speed up my dev cycle a little bit. Thanks much.
  11. Hello, I'm looking for a free record and playback tool to use for testing a standard windows gdi+ application. It can be pretty rudimentary, I just need it to record clicks and keystrokes and then be able to play them back. Any ideas out there? Thanks in advance.
  12. BradSnobar

    [.net] c# and increment operator

    Quote:Original post by mpipe Quote:Original post by Chrominium Just needed confirmation on something about c#. I have always been told that in C++, the pre-increment (++n) operator was the fastest operation for incrementing a integer. However, I've now been informed that this isn't the case anymore with c#. n = n + 1 is just as fast as n++ and ++n. Is this true? If you're THAT worried about performance I wouldn't be using C#. (C# programs aren't that much slower than C++ programs but there is a trivial gain.) This was true of .Net 1.1 and earlier. (I am the person that performed the benchmark comparisons between Native and Managed code when the first version of VS.Net was in development) Nowadays, most operations on Windows for managed and native code are exactly equivalent. I know this is surprising in some ways. I think that the reason is because the same system calls in most cases are being called. This would make the difference between a native call and a managed call differ by maybe a millisecond, but my benchmark did not even show that much difference. So, there is likely some other compiler or jit trickery going on back there. Anyway, just thought that was interesting. Still though just to be fair, C++ is easier to use when you want to do fast memory manipulation. C# will make you jump through some hurdles to accomplish some similar things. Differences in ease of implementation can make a more than trivial difference imho. Take care. Brad
  13. These are all good suggestions above. They are good for a certain class of problem. If you have all of the text already to be appended then that is the way to go, and then only if the text is fairly small. ie.) another problem arises if you are reading the text from a large file. If so, it is likely that you are bound by your disk IO time. And in that case, you'll be better off using a custom GUI control that does not block the process while you are reading text from the file and uploading it to the control. This is the same approach that Word and the VS.Net editors use. It might be overkill for your situation since it takes a lot of work to implement a control that does this task well. But, it's nice to know that the tools are there if this is what you need.
  14. It doesn't matter if you use backgroundworker, beginInvoke, or threads. They are all basically different implementations that wrap up the same functionality. They all boil down to threads at the end of the day. The backgroundWorker, and the event delegate model both use the threadpool. Anyway, moving on. Basically, you have the right idea. To link to different models like this, the best way is to surface some functionality from your ftp class by allowing the user to hoook some events. ie.) add an event to your ftp class. OnProgressChanged(object sender, ftpEventArgs e) Hook that event in the UI code, and then add the UI stuff in the event. If you think about it, this is what you do all day long with the other controls and classes available to you in .Net. Here is a link to view how to do some of this event stuff: http://www.akadia.com/services/dotnet_delegates_and_events.html
  15. Here is some guidance: How to make a windows application that uses a treeview. Open Visual Studio or Visual C# express. File --> New Project choose "Windows Forms Application" click OK button View --> ToolBox Find the treeview control and drag it onto the form. Here is some code below. You'll need to modify each piece a little bit to fit your circumstances but this gets you most of the way there. How to populate a treeview: TreeNode node = new TreeNode("Shortcuts"); TreeNode internet = new TreeNode("Internet"); TreeNode chat = new TreeNode("Chat"); internet.Nodes.Add(chat); node.Nodes.Add(internet); this.treeView1.Nodes.Add(node); this.treeView1.ExpandAll(); //open all the nodes so that you can see them. How to get the data out of the database: string connectionString = string.Format("server={0};database={1};Integrated Security=SSPI", "server", "MyDatabase"); System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(connectionString); con.Open(); string query = "select name from shortcuts where categoryId = 0 order by orderid"; System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(query, con); System.Data.SqlClient.SqlDataAdapter adapter = new System.Data.SqlClient.SqlDataAdapter(cmd); System.Data.DataSet data = new DataSet(); adapter.Fill(data); con.Close(); How to iterate over a dataset: DataSet data = new DataSet(); foreach (DataTable t in data.Tables) { foreach (DataRow dr in t.Rows) { string name = dr[0]; //add the node to the tree here. } }
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!