I am writing a little game (for school, hence the mandatory nonsensical design choices). The top-level component is a Winforms C# application. This is just supposed to provide a window, some basic menus and redirect input events to a C++ dll that does all the rendering and game logic processing.
I'm trying to see where I'm supposed to put my game loop in there. I assume the basic loop has to be in C#, and call native methods like update() and draw(). Since I don't want to stall the GUI, I created a background worker and passed it this method:
... where CycleTimer is my own class that I've used in a previous game entirely in C# and it was working really well. However I wasn't hosting it in a WinForms app. Now in this situation, I've noticed Update() is called every 25 milliseconds. This is completely unacceptable. It should be called at least every millisecond (and it should even be MUCH faster than that on my pc). Even when I comment out its body entirely so that it is merely called and exit, doing nothing, it is still called no more often than once every 25 milliseconds.
I suppose this is due to backgroundWorker being a somewhat low priority thread? Where is my approach wrong? I'm open to suggestions that deviate a lot from what I've did there. For instance if there was a way to manage the game loop in the C++ dll only, without stalling the WinForms host, that would be great.
It is silly there is no simple way to check whether this profile has been activated. CFRs are normal, but trying to even hide the fact if it's on / off seems silly, especially for something so user-facing.
Surely Microsoft is "proud" of their engineering efforts on this one and ought to display it somwhere in the GUI.
Many Linux distros are not known for excellent battery life, so I'm not sure that is the best example.
A more apt example may be Apple, but Apple's CPUs are simply far more efficient than Intel & AMD at single-threaded tasks like these, so "boosting" is not as power-hungry and less heat-inducing. Not to mention Apple will hardly engage P-cores for basic UI tasks; they use a pretty complicated QoS scheme to only activate P-cores for more serious workloads like HTML / JS execution or decompression or application launch.
Microsoft is (smartly) doing it for launch, but also for UI tasks, which is the more nonsensical part: why ... do Windows 11's UIs need modern CPUs to boost? It should load so quickly that there's not even time for the CPU to boost.
I've not seen any controlled testing and, judging by Microsoft's mentality, within a year, they'll have added so much more bloat, it'll undo any perceptible latency benefit and we'll have boosted the CPU clocks for nothing.
It depends: heat soak is a thing.
Initially on cold boot-up, the heatsinks & heatpipes are at ambient temp. After heatsinks & heatpipes warm up (through normal usage), they don't immediately cool to ambient temp when the load goes away. So their baseline is higher and the trigger point for fans is much less stress.
Add a few more CPU spikes → it's too hot to stay at the same fan RPM → fans get triggered to start up up much sooner / get triggered to ramp much more quickly.
Question
Andre S. Veteran
I am writing a little game (for school, hence the mandatory nonsensical design choices). The top-level component is a Winforms C# application. This is just supposed to provide a window, some basic menus and redirect input events to a C++ dll that does all the rendering and game logic processing.
I'm trying to see where I'm supposed to put my game loop in there. I assume the basic loop has to be in C#, and call native methods like update() and draw(). Since I don't want to stall the GUI, I created a background worker and passed it this method:
void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { CycleTimer.TriggerUpdate += CycleTimer_TriggerUpdate; CycleTimer.TriggerDraw += CycleTimer_TriggerDraw; CycleTimer.Start(30); while (true) { CycleTimer.Update(); } }... where CycleTimer is my own class that I've used in a previous game entirely in C# and it was working really well. However I wasn't hosting it in a WinForms app. Now in this situation, I've noticed Update() is called every 25 milliseconds. This is completely unacceptable. It should be called at least every millisecond (and it should even be MUCH faster than that on my pc). Even when I comment out its body entirely so that it is merely called and exit, doing nothing, it is still called no more often than once every 25 milliseconds.
I suppose this is due to backgroundWorker being a somewhat low priority thread? Where is my approach wrong? I'm open to suggestions that deviate a lot from what I've did there. For instance if there was a way to manage the game loop in the C++ dll only, without stalling the WinForms host, that would be great.
Edited by Dr_AsikLink to comment
https://www.neowin.net/forum/topic/934610-backgroundworker-issue/Share on other sites
7 answers to this question
Recommended Posts