As part of familiarizing myself with the Win32 API, I wrote a simple animation program in C. The program has a struct for each bitmap, holding information such as its location, visibility, mask (for transparency), etc. Then I have a separate thread running that has a WHILE loop that looks like this: -
WHILE (TRUE)
-
{
-
/* update all structs (bitmap locations, etc) */
-
SleepEx(iSpeed, FALSE);
-
InvalidateRect(hwnd, lpRect, TRUE);
-
}
-
In my WM_PAINT case in the window procedure, I'm simply drawing all my bitmaps based on their updated attributes.
The animation on my home computer seemed smooth and reasonable (it looked good), but then I copied the EXE to my work computer, and when I tried it at work, it seems to run in slow motion. It's still smooth, not skipping 'frames' and not showing any graphical problems, but it runs in slow motion. I do notice that every now and then the animation speeds up to its normal pace for a few seconds, but then it slows down again.
I know the problem is not with my work computer. I've run simple games on it before and their animation speeds are normal.
Any advice?
8 5531 Savage 1,764
Recognized Expert Top Contributor @DelphiCoder
Probably has to do something with iSpeed, how do you calculate it?
I discovered the problem was with SleepEx(). I ran a diagnostics program that I wrote. It takes 157 ms to execute a loop containing 100 ms worth of SleepEx() calls on my work computer. On my home computer, it's exactly 100 ms.
JosAH 11,448
Recognized Expert MVP @DelphiCoder
Timers aren't very accurate on a Microsoft Windows PC. It is not a real time operating system by far.
kind regards,
Jos
@JosAH
So how do they make games that run on Windows?
@Savage
Thanks so much! This is a great article. I will rewrite my app accordingly.
Banfa 9,065
Recognized Expert Moderator Expert @DelphiCoder
Also you don't use Sleep (or SleepEx) which only has ms resolution if that (DOS and therefore Windows 2.xxx and 3 and 95 had a maximum timer resolution of 50ms IIRC).
Use wait-able timers which are OS objects with much better resolution and accuracy.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Simena Dinas |
last post by:
KToon: 2D Animation Toolkit
KToon is a 2D Animation Toolkit designed by animators (Toonka Films)
for animators, focused to the Cartoon's industry.
This project is covered by the GPL License using G++, OpenGL and QT as
programming resources from KDevelop as the development platform.
One year later of production, it is a pleasure for Toonka Films
announces to the Free Software community the release of the KToon
|
by: Darren |
last post by:
X-No-Archive
Hi all,
Can anyone help me with structuring the data in a small tool I have to
build? I'm trying to work out if there's a design pattern or data
structure that would remove some of the dependencies.
I am designing an animation tool.
|
by: billrdio |
last post by:
I am trying to make a JavaScript animation of real-time images - i.e.
images that will periodically change on the server. The problem I am
having is that the JavaScript animation I have created is always using
the images from the cache, even though I have set the HTTP response
header on the server (via .htaccess) so that the browser should
validate the image in the cache against the image on the server for
freshness. I have tested the...
|
by: Miyra |
last post by:
Hi. I'm working with an app that uses exceptions for control flow.
These are code blocks where exceptions are thrown/caught regularly. A
couple hundred exceptions occur per hour and they're caught close to
the point of origination. I'm trying to decide whether to refactor...
What is the cost of throwing an exception in the CLR - relative to,
say, a conditional statement? Are we taking talking 1+ orders of
magnitude? Is there...
|
by: Bob |
last post by:
I want to create a GUI using VS .NET. For now I just want to input
some parameters used by the algorithms I've written in C++. Maybe
later I want to access a database to load the data from and plot
figures if it isn't too hard to do.
I haven't done any GUI's before so what should I use? Do you think I
should use the MFC library, or go with building a GUI using .NET, or
something else? If I use .NET then I need to write it using a...
| |
by: Robert Skidmore |
last post by:
Take a look at this new JS function I made. It is really simple but
very powerful. You can animate any stylesheet numeric value (top left
width height have been tested), and works for both % and px values.
Works in both ie and firefox.
Parameters
styleType = top | left | width | height
toNumber = the new value of the style
then you pass in as many ids as you would like.
|
by: rdemyan via AccessMonster.com |
last post by:
My application has a lot of complicated SQL statements, calculations,
processing that takes time. I've created a custom form to act like a
messagebox. It has 10 small rectangles on it that change color sequentially
to let the user know that processing is occurring. This 'animation' occurs
via the form timer event.
However, I'm having trouble getting the animation to occur for all types of
processing events. It appears that I have to...
|
by: |
last post by:
Can someone point me to some good info on how to do somoe simple animation on a form.
Specifically, I want to have some tiles that when they are clicked, they flip over in place and reveal a number. Obviously the flipping part should be animated and the user interface should not have to wait for the tile animation to complete before another tile can be selected.
Thanks.
J
|
by: Sin Jeong-hun |
last post by:
Most applications, including Windows Explorer, show some sort of
'wait' dialog with animation when a lengthy operation is going on. For
example, When the Windows Explorer is searching for something, it
shows a small dialog with a moving flashlight. I examined the
explorer.exe and found that that was an avi file.
Now that, I would like to do similar thing in my C# application. But
what is the most efficient way to do so?
1)Manually...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |