§ ¶I game on Advanced Server
Larry Osterman's blog entry about using a server version of Windows as a desktop OS reminds me of a post I once saw on a forum:
A: I'm having trouble running Half Life on my gaming rig. Can anyone help me?
B: Maybe. What OS are you running?
A: Windows 2000 Advanced Server
Hopefully from the Microsoft company store....
Truth be told, it probably should have worked fine. I got NT4 Server as a gift and used to run it as my desktop OS, because for development it was much better than Windows 98. The only real downside, IIRC, was that a whole bunch of programs detected the Server version and refused to run because you were supposed to buy the far more expensive edition (which did pretty much the same thing).
(Read more....)§ ¶Wine's DirectDraw implementation
I had a support question about VirtualDub blanking out screens again in Wine, so I decided to take another look out of curiosity.
A long time ago, when I released VirtualDub 1.5.5, I started receiving reports of issues with Wine. Specifically, as soon as VirtualDub tried to display any video, the entire screen would be overwritten. Wine was fairly immature at the time and still had a lot of major problems with commercial applications, so I wasn't surprised to determine that it was an issue with Wine and left it as such. That was the first version that had full support for DirectDraw video display, and so the workaround was to disable it in Options and fall back to GDI.
Surprisingly, there are still display compatibility issues with VirtualDub running under Wine.
VirtualDub doesn't do anything too fancy in its default DirectDraw mode. It creates a single off-screen surface in default memory (usually video, can be system) and then calls Blt() to draw it onto the primary surface through a clipper. I use the older DirectDraw 3 API, because that was the highest version supported by Windows NT 4.0 and there isn't anything in DirectDraw 6 or 7 that I need. There was a problem with Windows Vista where the panes sometimes wouldn't update (mixed DX and GDI in the same window no longer allowed, first I'd ever heard of it), but I fixed that by splitting off the display minidrivers to a child window, at the cost of flickering at mode switches. As far as I know, everything works now, both in XP and Vista. But it doesn't work in Wine, at least not so well.
In Wine 1.0, the current stable release, the old screen blanking problem is still around. I didn't have a debugging setup that I could use to check the Wine code -- realistically, I shouldn't even have been installing and running Wine on a running MythTV box -- but as best as I could tell from behavior and the Wine source, here's what's going on:
- In the default configuration and on that system, Wine needs to emulate the blit.
- Like in the Microsoft HEL (hardware emulation layer), the blit is emulated by locking both the primary and the off-screen buffer, and copying the surface data over using the CPU.
- X doesn't support locking the primary buffer, so that must be emulated by maintaining a backing store and updating the screen from it.
- The other programs don't know about the backing store, so the backing store for the primary is black everywhere except for where the blit happened.
- The emulated Blt() routine locks the entire primary surface, thus causing the whole screen to be updated -- and turn black everywhere except for the video panes.
Note that VirtualDub is blitting with both a destination subrect and a clipper attached, so the entire screen should definitely not be getting overwritten in this way.
In the current alpha release -- I think it was Wine-1.1.2 that I tested -- the situation is a bit better, as the video panes no longer blank the screen. There appear to be two changes possibly involved, although I'm not sure which are in the mainline:
- CodeWeavers had a hack to better emulate locking the primary by blitting from the screen into the backing store. That sort of works, I guess, but boy is it slooooooowwww, and it's also extraneous if the data is going to be overwritten anyway.
- Blt() was changed to lock only the pertinent subrect of the destination. I'm guessing this was the change that made the real difference.
The clipping situation is still pretty bad in the current version, as blits that are partially outside of the primary surface still fail, even if a clipper is attached. It seems that the top-level Blt() function immediately rejects any blits where the destination rect overlaps the right or bottom boundary, clipper or not. The underlying blit code in wined3d seems to be able to handle clipping to some extent, but unfortunately it lacks the ability to clip a stretchblt. It's a relatively minor issue, but it looks like the fractional stepping on the stretchblt case is also off by half a pixel.
How hard would it be to fix? I'm not sure. It's easy to be an armchair programmer, and I've never worked on Wine before. The clip and stretch problems, I'd say, shouldn't be too bad. As far as I know, the real DirectDraw only clips blits to pixel precision on both destination and source, which is easier but leads to seam artifacts. There is a path that does clip properly, but it's only used by Direct3D Present() calls. A more worrisome problem is that the old Microsoft DirectDraw Test (ddtest.exe) program doesn't work at all under Wine, as it displays garbage in its status panes and crashes out as soon as you try to create the primary surface. I suspect the reason might be that the DX3 interfaces aren't implemented properly and are expecting and returning DX7 structures, which would require a much bigger fix than just a few tweaks to the clipping and scaling routines.
So, if you're wondering why VirtualDub has drawing problems on Wine... there's your answer.
(Read more....)§ ¶Undoing indentation hell
Have you ever looked at a piece of code and seen something like this?
if (...) {
if (...) {
...
} else {
if (...) {
...
} else if (...) {
...
} else {
...
}
}
...
I'm going into style matters again and I know this is going to be contentious, but personally, I find that code is hard to read when it looks like a big tree view. You have to mentally match the braces or highlight them individually to have the editor show the matching, and that's hard to do when there are so many of them. It's even harder when the top-level statements don't even fit on one screen. The worst case I ever saw had something like 12 levels of indenting and was more than 17 pages long... and I use a small font size. Most of the time this happens because a routine snowballs until it grows out of control, and no one has the time/experience/constitution to refactor it. This happens to me as well, and eventually I get annoyed enough that I have to perform a nesting exorcism.
I attack such monstrosities by a series of small, incremental transformations. This increases the chances that the code will actually still work by the time I'm done with it. I should note that these are best done only if you own the code or already have to do major work on it for other reasons; doing transformations like this willy-nilly is a good way to completely scramble history in a source code control system and nuke any chances of your team members successfully merging your changes with theirs.
(Read more....)§ ¶VirtualDub 1.8.8 released
1.8.8/stable is now up on SourceForge. It fixes the /r command-line regression, as well as a couple of bugs in the plugin API support that affected some input drivers. I fixed a couple of Ctrl+C/Break glitches too while I was at it (more cases where WM_QUIT was being eaten).
The /r regression was caused by the change I had made to allow backoff-and-retry for the distributed job case. In doing so I had failed to update the command-line path, which expects to be able to call the run-all command in the job system as a single function call. This led to a classic problem where an event driven system couldn't be driven by a non-event-driven code path. I ended up fixing this by adding a modal loop, as rewriting the command-line logic to be event driven would have been too much work and too risky. Some had suggested that the bug was that the autostart flag in the job control window wasn't being set, but that's actually a different function -- that can't be used anyway as it doesn't suspend command-line processing and thus won't stall app exit (/x). Ultimately converting everything to use commands and a command queue is the Right Way(tm), but I'm a bit far from that.
(Read more....)