|
1- Forgive my ignorance, but what is SDL?
2- Do you have the source code of game.Respond()?
3- SDL.Net is that another language? How does it handle events?
4- The speed control of the game. Did you write its algorithm or is it a 3rd party library?
5- Even in C++ events were simply messages sent to the game. If so then your C++ code should still be able to process these messages or otherwise you simply kick these messages to it manually.
Regards
|
|
|
|
|
|
So I guess that when the user presses a key, there is an SDL event that will be fired? Well, I still don't see aproblem:
1- Make a thread fro the game loop
2- Make flags for each Key to be pressed
3- Raise that flag in the KeyDown, and make it false in KeyUp events -whether windows or SDL events-
4- On each loop render the game accordingly -change the position of the spirit if the key is pressed otherwise stay on course for example-
5- You will still be able to control the speed of excution in the thread by many ways includeing the Thread.Sleep() and specify the interval of sleep based on the speed of excution -you can get the speed of excution by many ways like Timers-.
I hope that was what you were looking for, but somehow i think you already did all this. Where is your problem?
Regards
|
|
|
|
|
|
Why do you make things complicated for yourself. Simply use the KeyUp/KeyDown events to raise flags. Omit the CanRespond flag as it is very error brone. Now only raise flags in the KeyUp/KeyDown event and process them when you can in the loop thread. Of course you put this loop on another thread right? And why is Loop() public? It should be a private method in your form.
Anyway all I'm saying that omit the canResond totally. If the user presses a key while you are rendering it won't really hurt. Process that key when you see fit.
Regards
|
|
|
|
|
|
Well, I don't understand much of the code as it's a library that I haven't worked with. Yet about the timer issue and about the processing speed you can make something like a speed factor. Make a few statements, say a while loop that makes a small computation. Now make a long variable that will take the DateTime.Ticks before excuting the loops, and another one after excuting that loop. Take the excution speed as the speed factor of your machine and determine the sleep interval of each target machine dynamically at runtime using the speed factor of each machine. I hope I make sense here!!
To sum up.
1- Make the loop to work best on your computer.
2- Take the SpeedFactor of you computer and the sleep interval as default values in the code.
3- Make that dummy speed test loop -with any statments-, to test the speed of excution.
4- Depending on the SpeedFactor at runtime the sleep interval should be changed -along with any other time dependant factor-.
I hope that worked.
Regards
|
|
|
|
|
|
Lord Kixdemp wrote: But now in C# they have events, so I can't do that...
Why can't you ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
|
But I don't see any events being handled here ? A game rendering loop looks like this precisely so that it renders as many FPS as the processor can handle.
You can handle the WndProc in .NET if you want to. You can also set event handlers on your window which store the result for your main rendering loop, or call that loop.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
|
i have a dataset it includes one table ,i would like to add a computed column in this table to calculate 2 fields
thanks for help
MD_NADA
|
|
|
|
|
Hello
md_nada wrote: i would like to add a computed column in this table
Use DataTable.Columns.Add() method to add columns to your DataTable.
md_nada wrote: to calculate 2 fields
What do you mean by fields? Maybe you mean the values in another two columns of the same row like MyColumn = Column1 + Column2?
Regards
|
|
|
|
|
|
Sounds like the LPARAM contains two values. The way to get the part you want is to use LOWORD and HIWORD.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hello
What's the integer value you get in your lParam?
Regards
|
|
|
|
|
Hi,
I am new to C# and trying to develop an app that communicates through the serial port. I found some sample code on the net that seems to work, but when i use the same code in my app it throws an exception. Currently I am developing using .NET version 2.0 on a Windows XP SP2 machine.
Am I doing something wrong? Is there a setting that I have to set or include?
Here is the code I have, which is run when I click on a "Start" button:
using System.IO.Ports;
private static void SendSampleData()
{
SerialPort port = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
port.Open();
port.Write("Hello World");
port.Write(new byte[] {0x0A, 0xE2, 0xFF}, 0, 3);
port.Close();
}
I don't know how much more simple I can get with this.
Here is the exception I get when I try and execute the port.Open():
System.Security.SecurityException was unhandled
Message="Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."
Source="mscorlib"
StackTrace:
at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
at System.IO.Ports.SerialPort.Open()
at CITDataRecorder.CITDataRecorder.Start_Stop_Button_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at CITDataRecorder.Program.Main()
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
thanks in advance!
|
|
|
|
|
Fairly obvious from your exception, you don't have permissions on your computer to open the port. Are you a normal (i.e. non-admin) user by any chance?
Just Google it.
Failing that try phoning
|
|
|
|
|
that is what I thought the problem was.....BUT I did run other sample code which I found at http://msmvps.com/blogs/coad/archive/2005/03/23/39466.aspx (the SerialPortTerminal.zip) and it opens up the COM port fine. Its just when i put this code in my sln that it returns that exception.
Did I now include some dll or project property that has me throw this exception in my sln only?
|
|
|
|
|
OK, I solved the problem although I do not understand why. The problem was that I was working under a network drive. As soon as I made the project reside on my local hard drive it worked fine.
So now my new question is, how do I make it so that my project can reside on the networked drive and still execute correctly?
|
|
|
|
|
Hmm, all I can suggest is look through your code carefully to see where it differs (in operation) from the sample code.
Another possibility is are you running your code off a mapped drive? If so you'll have to setup the permissions to trust that mapped drive. Even if it's mapped to a drive on your computer.
Just Google it.
Failing that try phoning
|
|
|
|
|
Greetz!
Can anyone tell me how to save objects in a file?
e.g. combobox is filled with objects form a class (name, which is displayed and value which includes IPEndPoints)
I want to save all Items of the combobox in a file, and load it later again.
All information is stored in the combobox.Text and combobox.Tag.
Other examle given: name is the name of a specific mode, and three string values define the parameters of the modes. This should be saved in a file as well.
Thx in advance,
Ezazazel
|
|
|
|
|
Since you havn't made it very clear how your data is represented / stored on the form, might I suggest you look into Serialization in the System.Serialization namespace?
Alternatively you can create your own file format and read and write data using the stream classes (System.IO namespace)
Or if you want to save it as Xml then take a look at the XmlTextReader, XmlTextWriter and XmlDocument classes in the System.Xml namespace.
Just Google it.
Failing that try phoning
|
|
|
|
|
You can use binary serialization and also you can use xml serialization for it.
For eg,
using System.Runtime;
using System.Runtime.Serialization.Formatters;
//Serilization//
Object s=new Object(textBox1.Text,textBox2.Text,textBox3.Text);
System.Runtime.Serialization.IFormatter f;
f=new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
System.IO.FileStream outf=new System.IO.FileStrea(@"d:\s.bin",System.IO.FileMode.Create,System.IO.FileAccess.Write);
f.Serialize(outf,s);
//Deserializeation//
System.Runtime.Serialization.IFormatter f;
f=new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
System.IO.FileStream fin=new System.IO.FileStream(@"d:\s.bin",System.IO.FileMode.Open,System.IO.FileAccess.Read);
Object s=(Object)f.Deserialize(fin);
Enjoy!!!!
<marquee>nishu
|
|
|
|