|
Background:
Iam on writing a little game to get familiar with Managed DirectX.
The logic part (eg. Updating GameObjects World Position) has to be hardware independent,
which means that it will run in a separate thread with an own timer logic.
Implementation
bool gameRunning = true;
while (gameRunning)
{
using (new ExecutionTimer(100))
{
}
}
ExecutionTimer Code:
public class ExecutionTimer : IDisposable
{
private DateTime endTime;
public ExecutionTimer(double milliseconds)
{
this.endTime = DateTime.Now.AddMilliseconds(milliseconds);
}
#region IDisposable Member
public void Dispose()
{
var remainingTime = endTime - DateTime.Now;
if(remainingTime.TotalMilliseconds > 0)
System.Threading.Thread.Sleep((int)remainingTime.TotalMilliseconds);
}
#endregion
}
What do you think about this implementation?
I know that it will create a new instance of ExecutionTimer in every step,
but on the other hand the syntax looks very smooth in my opinion.
Is there any alternative or best practice?
Greetings DustPuppy
|
|
|
|
|
I like it, quite a slick implementation. Wouldn't worry about creating a new ExecutionTimer each timeframe - so what?
Regards,
Rob Philpott.
|
|
|
|
|
what happens if your game logic takes over 100ms?
why not just record time at start of logic and sleep at end if need be, then you dont need to create and dispose a class that really does very little
If only MySelf.Visible was more than just a getter...
A person can produce over 5 times there own body weight in excrement each year... please re-read your questions before posting
|
|
|
|
|
If the logic takes longer than 100 ms your cpu is to slow for the game.
I saw such a behavior in supreme commander for example,
the movement speed of all units was slowed down if there where +XXX Units on my screen,
but in the meanwhile I still had +50 frames.
I just did a performance check with the StopWatch (System.Diagnostics),
Disposing and Creating virtually takes no time in this case.
Greetings DustPuppy
|
|
|
|
|
The Dust Puppy wrote: If the logic takes longer than 100 ms your cpu is to slow for the game.
what i mean is you will end up passing a negative value to the Thread.Sleep funtions, which will cause an exception
If only MySelf.Visible was more than just a getter...
A person can produce over 5 times there own body weight in excrement each year... please re-read your questions before posting
|
|
|
|
|
This case is already handled in the Dispose Method, isnt it?
if(remainingTime.TotalMilliseconds > 0)
System.Threading.Thread.Sleep((int)remainingTime.TotalMilliseconds);
|
|
|
|
|
Correct - just testing you
my mistake, sorry
If only MySelf.Visible was more than just a getter...
A person can produce over 5 times there own body weight in excrement each year... please re-read your questions before posting
|
|
|
|
|
I'm using ZedGraph to draw a PieChart.
You know, A PieChart is composed with several PieItems.
But, I don't know how to determine which pieitem is selected when you click or double click in the ZedGraphControl(Here is a PieChart).
Anyone knows about this?
And samples?
Thanks!
|
|
|
|
|
A quick google shows there are loads of sites with info about zedgraph, including samples. Have you tried any of them?
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
|
|
Got it.Yah, Thank you very much.
|
|
|
|
|
I created a small application using c#.net in vs2003.
I used a combox control at top and a tab control in which there are 3 tabs,
On these tab pages having some textboxes, listviews etc.
now on the combobox_SelectedIndexChange event i am retriving data from DB and binding on to these tab pages.
Here problem occurs, After main form load, if i select an item from combobox,
It saying "Object refrence not set"
On the other hand, when main form load and i click/view each tab then select item from combobox its working fine,
No error .
What can be the reason,
might be controls of each tab page loaded when they got clicked or viewed,
Any help woulb be appreciated,
Thanks & regards.
|
|
|
|
|
Some code in your selected index changed event is fixing your bug. Hard to say more, without seeing the lines of code involved.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Christian Graus wrote: Some code in your selected index changed event is fixing your bug. Hard to say more, without seeing the lines of code involved.
as i said before select index event works fine if i view/click each tab page, it creates problem only when user select item from combo box without viewing each page.
Here is approach i m using.
After IntializeComponent method,
->calling a method in which, i am doing DB retrives operation, then
->Binding these data to controls on each tab page using control.DataBinding.Add method
I want to know what event occur when user click a tab page, so that i can call that before user selects an item from combo box.( tab_click event occurs, but what's happening, Is it loading/validating each control on each page)
if user view each page, then select item no problem, all fine.
but choose an item from combo box before viewing pages error yells.
any comment/help?
|
|
|
|
|
WTF why where you 1 voted???
|
|
|
|
|
hi experts,
I hav create a COM DLL using VC++6.0 application.which has a function :
[id(13), helpstring("method LngGenSuggW")] HRESULT LngGenSuggW([in]BSTR pwIpIscii,[out]VARIANT *pawSuggArray);
and my client application is in C# 2005.
which is as follows:
COM_INSPELLLib.ComInSpell objCom = new COM_INSPELLLib.ComInSpell();
String sIpWord;
object sSuggArray = new object() ;
objCom.LngGenSuggW( sIpWord, out sSuggArray);
and I got the sSuggArray with the answer return by COM DLL.
which contains "3 strings" means string array.
but the problem is object does not contain any method to get these string back.
Is there any method or solution??
that converts or parse this object array sSuggArray into String array and
so that I can use it for further procedure.
please help me..
I try it.. but cant done..
waiting for ur valuable reply..
thanx & regards,
Victory.Thumbs Up
|
|
|
|
|
have you tried casting it directly?
COM_INSPELLLib.ComInSpell objCom = new COM_INSPELLLib.ComInSpell();
String sIpWord;
object sSuggArray = new object() ;
objCom.LngGenSuggW( sIpWord, out sSuggArray);
string [] arr = (string[])sSuggArray;
|
|
|
|
|
Is there anyone could give some idea about this question.
|
|
|
|
|
.NET controls have dock and anchor properties. Why on earth would you be using a flexgrid ?
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
For some reasons,user need adjust the form size,thus,need the form's content(flexgrid) adjust with the change of resizing,Suchu as row wrap. the issue had been fixed, thanks.
|
|
|
|
|
private const int LB_GETCOUNT = 0x018B;
private const int LB_SETCOUNT = 0x01A7;
Can some body please tell me what does these values mean. Secondly can i define my own values for e.g
private const int LB_SETITEMHEIGHT = 100-> i want to set item height to 100;
|
|
|
|
|
netJP12L wrote: private const int LB_GETCOUNT = 0x018B;
private const int LB_SETCOUNT = 0x01A7;
They look to be contants. Whats the confusion ? You can search through your code for "LB_GETCOUNT"/"LB_SETCOUNT" to know what are they meant for.
But looking at the names they seem familiar to Windows listbox commands [^]
netJP12L wrote: can i define my own values
Yes, you can declare your own constants. It's good to declare constants instead of having "magic values" all over the code. Hopefully you are aware when something should be declared as a constant or else google could help you.
|
|
|
|
|
netJP12L wrote: Can some body please tell me what does these values mean
They almost certainly mean that some p/invoke calls are being made and these constants are needed for that.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
private const int LB_GETCOUNT = 0x018B;
private const int LB_SETCOUNT = 0x01A7;
If a number starts with 0x it means you are dealing with a hexadecimal value.
0x018B = decimal 395
0x01A7 = decimal 423
|
|
|
|