Thread Tools
Old September 17, 2002, 01:26   #1
nbarclay
PtWDG Gathering StormInterSite Democracy Game: Apolyton TeamApolyton UniversityC4DG Gathering Storm
Emperor
 
nbarclay's Avatar
 
Local Time: 02:08
Local Date: November 1, 2010
Join Date: Dec 1999
Location: Huntsville, Alabama
Posts: 6,676
Cleaver, or Wasteful Programming?
Others may have caught this before, but I just noticed what looks like either something cleaver or a serious case of wasteful, impolite programming. I just upgraded my system's memory (Athlon 900, Windows 2000, going from 256 megs to 768) and decided to look at the performance measurement display in the Win2K task manager to see whether it looks like the extra memory is making a difference. When I looked at the "CPU Usage" part of the dispaly, I got a surprise. Even now while I'm typing this on Internet Explorer, Civ 3 has my CPU utilization pegged at 100%, and the program is just waiting for me to hit Enter to end the turn. (CPU utilization is also maxed out during the turn, but it drops down a bit at times during the "new turn" routine when the CPU has to wait for other resources.)

If the 100% CPU utilization reflects the AI thinking about strategy during the human player's turn, that might be regarded as a cleaver use of resources. But otherwise, it seems just plain sloppy. Windows operating systems are designed to support multitasking, and it's hard to find an excuse in this day and age for a professional development outfit's failing to recognize that someone might want to switch back and forth between their game and something else (like writing about their game?). But with Civ 3 always competing for CPU power, anything else running at the same time gets slowed down - a phenomenon I'd noticed before but hadn't realized was caused by something so obvious.

By the way, I'm almost positive I was right that with Win2K, having more than 256 megs of RAM will come in pretty handy (and Windows XP would almost certainly be worse). Large-map games in the modern era can get in the 256 meg range all by themselves even without a lot of players, and huge maps could get worse. And even with standard maps, when I have Outlook Express, several Internet Explorer Windows, and maybe another thing or three running alongside Civ 3, 256 megs isn't enough to fit everything. (In the latter case, the main effect would probably be on the speed of switching between programs rather than on the speed a particular program runs at once it gets going, since Windows can swap to disk to pretend it has more memory than it really does.)

Nathan
nbarclay is offline  
Old September 17, 2002, 01:42   #2
Wormwood
Warlord
 
Wormwood's Avatar
 
Local Time: 00:08
Local Date: November 1, 2010
Join Date: Jul 2002
Location: Terminal Island
Posts: 181
Clever, not cleaver. The post sounded so intriguing. I run Civ3 on XP with 128MB, and it gets pretty bad sometimes. Thankfully 512 are on their way. There is a lot you can do to tweak Xp and ME, to help with the performance on larger maps of Civ3.
Wormwood is offline  
Old September 17, 2002, 01:50   #3
vmxa1
PtWDG Gathering StormC4DG Gathering Storm
Deity
 
vmxa1's Avatar
 
Local Time: 04:08
Local Date: November 1, 2010
Join Date: Nov 2001
Location: Oviedo, Fl
Posts: 14,103
I do not know why, but most games show up at 100% on my XP PRO running on AMD 1900+. I think it is the use and control of the mouse/vid that makes the kernnel report it busy.
vmxa1 is offline  
Old September 17, 2002, 02:46   #4
nbarclay
PtWDG Gathering StormInterSite Democracy Game: Apolyton TeamApolyton UniversityC4DG Gathering Storm
Emperor
 
nbarclay's Avatar
 
Local Time: 02:08
Local Date: November 1, 2010
Join Date: Dec 1999
Location: Huntsville, Alabama
Posts: 6,676
Quote:
Originally posted by vmxa1
I do not know why, but most games show up at 100% on my XP PRO running on AMD 1900+. I think it is the use and control of the mouse/vid that makes the kernnel report it busy.
Usually, that kind of behavior is due to "polling loops" where a program keeps asking "Has such-and-such happened yet?" as quickly as it can. Under some circumstances, such a loop might execute the same half dozen lines of code millions of times per second.

I can even see some possible sense in using such an approach in fast-paced arcade (or some types of RTS) games where rapid response to user inputs is critical. If the operating system forces the designers to choose between waiting "too long" between polling cycles or not waiting at all, not waiting at all may be the best option.

But in a game like Civ 3, unless the Windows 95/98/ME series is a lot more limited than I think it is, I see no good reason not to build in a delay of 1/100 of a second or so between loop cycles - especially after the game has been idle for a few seconds. In a turn-based game, that would still detect movement quickly enough to make the delay unnoticeable to human senses, but would reduce CPU utilization to near zero when the game is idle.

Unfortunately, from what you've written, it sounds like a lot of game developers are either ignorant or apathetic regarding how to write a program to play nicely with others. Maybe too many of them got their start when they could pretty much count on having the whole system to themselves and they just haven't adjusted to the realities of modern hardware and operating systems yet. Fortunately for Firaxis, Civ 3 is good enough that I'm willing to tolerate poor marks in the "plays well with others" category.

Nathan
nbarclay is offline  
Old September 17, 2002, 05:31   #5
bongo
lifer
PtWDG2 Mohammed Al-SahafPtWDG Neu DemogypticaCivilization III PBEMC3CDG Blood Oath HordeIron CiversC4DG The HordeC4WDG éirich tuireann
Emperor
 
bongo's Avatar
 
Local Time: 09:08
Local Date: November 1, 2010
Join Date: Sep 1999
Location: MOOHOOHO
Posts: 4,737
Civ2 behaved in the same manner, 100% CPU all the time.

It could be doing something clever while it waits for a key-press but I doubt it.

Most programmers learn the difference between constant polling and events within the first couple of minths at school.
__________________
Don't eat the yellow snow.
bongo is offline  
Old September 17, 2002, 09:07   #6
Moonsinger
Warlord
 
Local Time: 02:08
Local Date: November 1, 2010
Join Date: Dec 2001
Posts: 298
Quote:
Originally posted by bongo
Civ2 behaved in the same manner, 100% CPU all the time.
I also notice that too. I usually run it on my laptop and it never power down to save battery when it's not being used.
Moonsinger is offline  
Old September 17, 2002, 12:16   #7
vmxa1
PtWDG Gathering StormC4DG Gathering Storm
Deity
 
vmxa1's Avatar
 
Local Time: 04:08
Local Date: November 1, 2010
Join Date: Nov 2001
Location: Oviedo, Fl
Posts: 14,103
Note that it occurs even when I exit the game to the main menu? Several TBS games behave this for meon XP. I can not recall if that was the case in 98se.
vmxa1 is offline  
Old September 17, 2002, 13:07   #8
Fitz
King
 
Fitz's Avatar
 
Local Time: 00:08
Local Date: November 1, 2010
Join Date: Mar 2000
Location: & Anarchist
Posts: 1,689
Send a little message to Firaxis asking why this is the case. If they can get it to Soren (and he is willing to take the time) you might get an interesting answer.

The real question is, while it looks like 100%, can other programs take away the processing power they need at will? In other words, if another program needs 25% processing power, is the Civ3 coding going to limit that?
__________________
Fitz. (n.) Old English
1. Child born out of wedlock.
2. Bastard.
Fitz is offline  
Old September 17, 2002, 15:02   #9
Wormwood
Warlord
 
Wormwood's Avatar
 
Local Time: 00:08
Local Date: November 1, 2010
Join Date: Jul 2002
Location: Terminal Island
Posts: 181
This is something you can do in XP, so maybe you can do it in 2K.

In the control panel, go to system, then the advanced tab, then the button for performance. Go to it's advanced tab, and you can select whether programs or background services get priority. Another and probably better way is to Ctrl+Alt+Del, go to services, and right click on a service. You can then set a priority level to a service, and see if Civ3 still goes at 100%.
Wormwood is offline  
Old September 17, 2002, 15:07   #10
Myrddin
Warlord
 
Myrddin's Avatar
 
Local Time: 08:08
Local Date: November 1, 2010
Join Date: Jun 2001
Location: Aberystwyth
Posts: 232
On an earlier thread memory usage of 700+ was seen - mostly due to the path-finding algorithm. This is why large maps are so slow and why it is not recommended to have other programs running.
Myrddin is offline  
Old September 17, 2002, 20:51   #11
nbarclay
PtWDG Gathering StormInterSite Democracy Game: Apolyton TeamApolyton UniversityC4DG Gathering Storm
Emperor
 
nbarclay's Avatar
 
Local Time: 02:08
Local Date: November 1, 2010
Join Date: Dec 1999
Location: Huntsville, Alabama
Posts: 6,676
Quote:
Originally posted by bongo
Most programmers learn the difference between constant polling and events within the first couple of minths at school.
Even assuming that that's true today, programmers with 10 years of professional experience or more "grew up" as programmers in a different era. Back when I was in college (mid-to-late 80's), practically everything we did was text-based, which made the concept of event-driven programming generally irrelevant. On almost all personal computers (Amiga being an exception, but how many colleges used those?), there was no such thing as multitasking, and thus no need to worry about wasting resources someone else's program might need. And on big multiuser systems, the system calls we used isolated us from the underlying event mechanisms that protected against wasting computing power. GUI programming was still relatively new, and certainly not something simple enough to include in a typical freshman course (if a college offered a course in it at all). So no, we definitely did not learn about polling versus event-driven programming in the first two weeks.

I certainly hope that today's college students are being indoctrinated in good, multitasking-friendly programming practices from the beginning. But that still leaves the problem of experienced developers who spent their early programming careers not having to worry about playing nicely with other programs and who haven't made the adjustment to today's multitasking systems yet.

Nathan
nbarclay is offline  
Old September 17, 2002, 21:05   #12
Frugal_Gourmet
Warlord
 
Local Time: 03:08
Local Date: November 1, 2010
Join Date: Dec 1969
Location: New York City, NY, USA
Posts: 158
You'll find that a great many Windows games do this, and it isn't bad programming.

The game simply makes use of whatever CPU time isn't being used by other parts of the system.

You should have no problems multitasking with Civ3 in the background...
Frugal_Gourmet is offline  
Old September 17, 2002, 21:51   #13
nbarclay
PtWDG Gathering StormInterSite Democracy Game: Apolyton TeamApolyton UniversityC4DG Gathering Storm
Emperor
 
nbarclay's Avatar
 
Local Time: 02:08
Local Date: November 1, 2010
Join Date: Dec 1999
Location: Huntsville, Alabama
Posts: 6,676
Quote:
Originally posted by Fitz
The real question is, while it looks like 100%, can other programs take away the processing power they need at will? In other words, if another program needs 25% processing power, is the Civ3 coding going to limit that?
With Civ 3 wanting to use as much processing power as the operating system is willing to let it, the big question becomes how much power the OS is willing to give it when another program also wants processing power. Under Windows NT 4.0, if "foreground boost" was set to none, Civ 3 could expect a minimum of about half the CPU cycles, leaving whatever else you're running limited to the other half (assuming two programs competing for cycles). With a higher foreground boost (the default), the program you're actively using would get a higher percentage of the available processing power. I imagine the settings to optimize for foreground or background processing in Windows 2000 and XP serve a similar purpose.

I'd have to do some experimenting to find out the point at which Civ 3's desire for processing cycles would interfere significantly with another program with Civ 3 running in the background. But unless a program pushes the CPU fairly close to its limit, Civ 3's polling loop probably won't be a big deal as long as optimization favors the foreground program. (Of course competition for memory may be another matter).

Nathan
nbarclay is offline  
Old September 17, 2002, 23:15   #14
nbarclay
PtWDG Gathering StormInterSite Democracy Game: Apolyton TeamApolyton UniversityC4DG Gathering Storm
Emperor
 
nbarclay's Avatar
 
Local Time: 02:08
Local Date: November 1, 2010
Join Date: Dec 1999
Location: Huntsville, Alabama
Posts: 6,676
Quote:
Originally posted by Frugal_Gourmet
You'll find that a great many Windows games do this, and it isn't bad programming.

The game simply makes use of whatever CPU time isn't being used by other parts of the system.

You should have no problems multitasking with Civ3 in the background...
Rather than keep speculating, I downloaded and built a copy of the Dhrystone benchmark and ran it to see how Civ 3 affects its performance. Dhrystone is a bit obsolete for most purposes these days, but it should be fine for this one.

Without Civ 3 running, Dhrystone took 36-38 seconds to complete 50 million iterations. With Civ 3 running, it took 51-53 seconds. So having Civ 3 running in the background saps in the neighborhood of 30% of a Win2K system's performance. The game isn't just sitting back using cycles no one else wants.

I did, however, figure out what it does with at least some of those cycles. There's some eye candy (related to cities celebrating, in the case of the game I loaded for the test) that the game keeps going whether anyone is watching or not. It would be nice if they turned that off when their program loses focus, but at least it's not quite as bad as doing absolutely nothing.

Nathan
nbarclay is offline  
Old September 18, 2002, 00:55   #15
lateralis
Chieftain
 
lateralis's Avatar
 
Local Time: 03:08
Local Date: November 1, 2010
Join Date: Jun 2002
Posts: 61
Quote:
I did, however, figure out what it does with at least some of those cycles. There's some eye candy (related to cities celebrating, in the case of the game I loaded for the test) that the game keeps going whether anyone is watching or not.
nbarclay hit it right on the head. I play on a powerbook g4 (yes a mac ) and for those who are unfamiliar with these laptops, they get hot when being used alot. like hot enough to burn your legs. and the internal fan has 3 audibly different settings. While actively playing civ3 the fan is ALWAYS on high and the bottom is ALWAYS too hot to touch. I arrived at the same conclusion that nbarclay did, that there is always SOMETHING going on that needs cycles. like your rifleman sneezing or WLTKD fireworks, but also, workers. remember that workers are ALWAYS in motion unless garrisoned in a city or fortified out in the open (which happens often, I know )

even though I'm not on windows but mac os X (which has some of the best multi-tasking available on a desktop) I though some of you might want to know that it is not just on the evil empire's machines that display this behavior but us underdogs have it too. which seems that it falls squarely in the Wasteful Programming arena.

lateralis
__________________
"As far as I'm concerned, humans have yet to come up with a belief worth believing." --George Carlin
lateralis is offline  
Old September 18, 2002, 03:39   #16
bongo
lifer
PtWDG2 Mohammed Al-SahafPtWDG Neu DemogypticaCivilization III PBEMC3CDG Blood Oath HordeIron CiversC4DG The HordeC4WDG éirich tuireann
Emperor
 
bongo's Avatar
 
Local Time: 09:08
Local Date: November 1, 2010
Join Date: Sep 1999
Location: MOOHOOHO
Posts: 4,737
lateralis , have you tried to turn off animations? Maybe that will cool your computer down. When those workers stop sweating so will wou

nbarclay , thinking back, I remember that I had event-driven programming at school in 94-95. But I also recall using interrupts to avoid polling at least five years ahead of that(with my good ol' cbm64). BTW, interesting test
__________________
Don't eat the yellow snow.
bongo is offline  
Old September 18, 2002, 03:49   #17
nbarclay
PtWDG Gathering StormInterSite Democracy Game: Apolyton TeamApolyton UniversityC4DG Gathering Storm
Emperor
 
nbarclay's Avatar
 
Local Time: 02:08
Local Date: November 1, 2010
Join Date: Dec 1999
Location: Huntsville, Alabama
Posts: 6,676
I hadn't really thought that much about the effect on notebooks running off a battery, but that does provide another very good reason for programmers not to waste CPU cycles. The better notebook CPUs get at throttling back to provide only the processing power (and associated energy expenditure) needed at any given time, the more wasteful it is for programs to use every CPU cycle available whether they truly need it or not. Within a year or two, notebooks with ten times Civ 3's official minimum processing requirement (a 300MHz Pentium II) should be available!

Another issue that occurs to me is, what happens if someone with a relatively powerful machine wants to play Civ 3 in the foreground while doing something time-consuming and CPU-intensive (like re-encoding a long video clip) in the background? In theory, every cycle not truly needed by Civ 3 should be available for the other program. But in practice, the fact that Civ 3 is in the foreground and wants every cycle the OS is willing to give it can get nasty. (I did another Dhrystone run with Civ 3 idling in the foreground and Dhrystone in the background, and Dhrystone took a little over four times as long as it did running by itself.) Granted, not many machines could do that sort of multitasking very well when Civ 3 first came out even if Civ 3 were friendlier toward it. But if past history is any indication, by the time Civ 3's life cycle ends, cheap entry-level computers will be more powerful than today's newest, most powerful machines.

Nathan
nbarclay is offline  
Old September 18, 2002, 04:52   #18
nbarclay
PtWDG Gathering StormInterSite Democracy Game: Apolyton TeamApolyton UniversityC4DG Gathering Storm
Emperor
 
nbarclay's Avatar
 
Local Time: 02:08
Local Date: November 1, 2010
Join Date: Dec 1999
Location: Huntsville, Alabama
Posts: 6,676
Quote:
Originally posted by bongo
nbarclay , thinking back, I remember that I had event-driven programming at school in 94-95. But I also recall using interrupts to avoid polling at least five years ahead of that(with my good ol' cbm64). BTW, interesting test
I agree that the polling vs. interrupts issue provided some background in that sort of efficiency concern, but it wasn't a "first two weeks" type of thing and it wasn't necessarily a type of thing most students got much chance to deal with in practice. Also, even though you used interrupts to avoid polling on that C64, I wouldn't be shocked if you wasted CPU cycles right and left using delay loops to control timing. (I don't remember whether the C64 had a sleep routine with sub-second granularity or not.)

I do have interesting memories of an assembly language class where we used delay loops on Apple IIs to control how quickly the system made its soft little clicking sound. That's how you made musical tones on those machines: by making them click at a given frequency. And it's indicative of the philosophy of programming on personal computers at the time: your program owns the computer, so if you don't need the CPU for something else, it's just fine to sit and spin.

Nathan
nbarclay is offline  
Old September 18, 2002, 06:26   #19
bongo
lifer
PtWDG2 Mohammed Al-SahafPtWDG Neu DemogypticaCivilization III PBEMC3CDG Blood Oath HordeIron CiversC4DG The HordeC4WDG éirich tuireann
Emperor
 
bongo's Avatar
 
Local Time: 09:08
Local Date: November 1, 2010
Join Date: Sep 1999
Location: MOOHOOHO
Posts: 4,737
If you want to do other work in the background while playing civ3 you need a multi-CPU system. Multitasking were possible under win3.x but it improved much with win9x(including ME). The biggest improvement though came with NT (including w2k and xp). It's still possible for a program to use 100% of CPU power and in effect cripple the computer. At least make it a single-tasking comuper. If you have a multi-processor system that program will use 100% of _one_ cpu, the rest will be available for other tasks.
__________________
Don't eat the yellow snow.
bongo is offline  
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 04:08.


Design by Vjacheslav Trushkin, color scheme by ColorizeIt!.
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Apolyton Civilization Site | Copyright © The Apolyton Team