Performance suggestions to reduce lag

Discuss Chaos Strikes Back for Windows and Linux, an unofficial port of Chaos Strikes Back to PC by Paul Stevens, as well as CSBuild, an associated dungeon editor.

Moderator: Zyx

Forum rules
Please read the Forum rules and policies before posting.
Post Reply
User avatar
Crash.
Adept
Posts: 228
Joined: Fri Jun 20, 2008 3:15 am

Performance suggestions to reduce lag

Post by Crash. »

Hi,

I am wondering if perhaps I'm doing something wrong, as I am finding CSBWin to be somewhat laggy on my 3.8ghz P4 with WindowsXP. The main problem is when trying to move quickly, extra keys get buffered or something, and I end up hitting a lot of walls. I have tried to kill background applications and increase the priority of the CSBWin application, which has not helped.

Any suggestions would be appreciated,

Thanks
User avatar
beowuuf
Archmastiff
Posts: 20687
Joined: Sat Sep 16, 2000 2:00 pm
Location: Basingstoke, UK

Re: Performance suggestions to reduce lag

Post by beowuuf »

If this is under conflux III< it will be because there may be quite a large amount of checks happening in the background (there are designer specified actuators, or DSAs, that are constantly firing to check the party status). Some areas like the mines have a large amount of things happening in some places.

If this is under CSBwin in general, then that sounds odd.
User avatar
Paul Stevens
CSBwin Guru
Posts: 4318
Joined: Sun Apr 08, 2001 6:00 pm
Location: Madison, Wisconsin, USA

Re: Performance suggestions to reduce lag

Post by Paul Stevens »

Indeed, You can play Dungeon Master using CSBwin
on a 166MHz Pentium without any problem whatsoever.
In fact, while I was developing it, I slowed it to half that
just to be sure that it was not hogging CPU.

Remember, the original ran on an 8 MHz 68000 with
half the cycles taken by the video controller!!!!!

There is a maximum speed that you can move around
the dungeon. If you are injured, that can be quite slow.
So, if you are entering several movement keys very quickly,
the second (and perhaps more) keys could very well be queued
until the after the party takes the first step. Is this
perhaps what is happening to you?
User avatar
Crash.
Adept
Posts: 228
Joined: Fri Jun 20, 2008 3:15 am

Re: Performance suggestions to reduce lag

Post by Crash. »

Hi,

My characters were not injured or overburdened, and I'm not playing Conflux yet, but just keep slamming into walls when going around corners. On an ST, I can navigate very quickly without this problem, so either Windows is buffering keys differently, or there is something going on with my system. I don't know what some of the CSBWin features are such as "extra ticks" and player clock, in case one of these is relevant. It almost seems like there is a larger than expected delay between hitting a key and the on screen movement, so if I am moving quickly, it is easy for an extra keypress to get into the queue. I don't know if this is the game, or a problem with Windows introducing a delay betwen keystrokes and the game. I'm inclined to blame Windows.

Cheers
User avatar
beowuuf
Archmastiff
Posts: 20687
Joined: Sat Sep 16, 2000 2:00 pm
Location: Basingstoke, UK

Re: Performance suggestions to reduce lag

Post by beowuuf »

Ah, I think it's just the effect of the engine speed (which was desighed for a slower computer). Certainly esure the 'extra ticks' is on, as this ensures that the game is taking input faster (PaulS can say exactly what it does, but I believe it allows for more than the six 'ticks' per secodn the original engine used). You can also try increasign the speed to your play style. Just tried it just now, and while none of the key strokes are lost in 'normal' with extra ticks (you can go aroudn a room in a circle without coming astray unless your fingers fail) there is a feeling of buffered movement. Swap the speed to fast, and it seems to run perfectly.

Althoguh note this affects everything, so food/water consumption and monsters would also be faster.
User avatar
Crash.
Adept
Posts: 228
Joined: Fri Jun 20, 2008 3:15 am

Re: Performance suggestions to reduce lag

Post by Crash. »

At the normal speed setting, I am finding CSBWin to be quite slow on my system. I tried DMPC on DOSbox which is much more responsive. Is there any parameter or setting that could be causing this problem?

Thanks!
User avatar
Paul Stevens
CSBwin Guru
Posts: 4318
Joined: Sun Apr 08, 2001 6:00 pm
Location: Madison, Wisconsin, USA

Re: Performance suggestions to reduce lag

Post by Paul Stevens »

You are the fellow trying to run CSBwin in a
kind of full-screen mode on a huge monitor,
are you not?

Perhaps the graphics handling is the
bottleneck.

CSBwin uses no graphic card help. It does
everything with the CPU. I wonder if putting
your screen back to natural setting and using
CSBwin in a normal window might make a
difference. You may not like playing the
game that way but it would be a good
experiment to try.
User avatar
beowuuf
Archmastiff
Posts: 20687
Joined: Sat Sep 16, 2000 2:00 pm
Location: Basingstoke, UK

Re: Performance suggestions to reduce lag

Post by beowuuf »

Ah, iff that's the issue, you can try the (annoying) shortcut of forcing your screen resoilution to be tiny, so that CSN is doing less work to full screen too (I would imagine)
User avatar
Crash.
Adept
Posts: 228
Joined: Fri Jun 20, 2008 3:15 am

Re: Performance suggestions to reduce lag

Post by Crash. »

I am using a program to switch the desktop resolution to 640x480 before running CSBWin in full screen so running the game at 4x is not necessary. I'm not sure if the DirectX switch or some other issue may be a problem. I did try running at the small size in a window, and the lag seems to be the same. There is just a little delay between pressing an arrow key and the on screen action that is not present on DMPC in Dosbox, and I expected the opposite.

Thanks
User avatar
beowuuf
Archmastiff
Posts: 20687
Joined: Sat Sep 16, 2000 2:00 pm
Location: Basingstoke, UK

Re: Performance suggestions to reduce lag

Post by beowuuf »

AS I said before, try the 'fast' game speed, check the extra player ticks are on, and you certainly need the directX option ticked. With all those checked, see how the game smoothness is for you.
User avatar
Crash.
Adept
Posts: 228
Joined: Fri Jun 20, 2008 3:15 am

Re: Performance suggestions to reduce lag

Post by Crash. »

Running with the Fast game speed appears to help navigation only, but it is a double edged sword, since things like Fireball traps go faster too. Shouldn't it be possible for the screen to update more quickly without the game loop running faster? I wonder what it is about my system that causes this lag not present on an 8mhz st. I've tried to kill many of the background apps and services, but it is never possible to get rid of them all.
User avatar
beowuuf
Archmastiff
Posts: 20687
Joined: Sat Sep 16, 2000 2:00 pm
Location: Basingstoke, UK

Re: Performance suggestions to reduce lag

Post by beowuuf »

The extra player ticks I think (paul can correct me) was for faster computers?
User avatar
Paul Stevens
CSBwin Guru
Posts: 4318
Joined: Sun Apr 08, 2001 6:00 pm
Location: Madison, Wisconsin, USA

Re: Performance suggestions to reduce lag

Post by Paul Stevens »

If I understand......
Setting "Quick as a bunny" makes things
better for you.

If this is the case then the problem is not
in the updating of the screen. The problem
is that the engine is INTENTIONALLY forcing
a delay between party moves.

If I understand, your problem is that you can
press the forward key faster than the party
can move forward. This happens to me, too.
I expect it. It is the way the engine was
designed. If I enter a long hallway and press
forward rapidly five times, I finish entering
the keystrokes about a half second before the
party makes the last step.

At any rate, I am preparing some experiments
for you to try. I'll have the first ready later
today. It will discriminate between the time
required to update the screen and the time
intentionally inserted to keep the party from
going infinitely fast.
User avatar
beowuuf
Archmastiff
Posts: 20687
Joined: Sat Sep 16, 2000 2:00 pm
Location: Basingstoke, UK

Re: Performance suggestions to reduce lag

Post by beowuuf »

I experienced this too, and those settigns I suggested smoothed it out to where the engine respnded as quick as my fingers. You can always slow down the sections where this is a problem.

I would say that the key buffer issue was one that was toyed with in RTC, and you could indeed get in to a stupid situation where holdign down a key slammed you in to a wall, and holding all the keys in a buffer did odd things. RTC went off of 'natural' DM movement because fo the niggles by various people, and if I recall correctly doens't quite have the same keystroke response as pure Dm / CSBwin has.
User avatar
Crash.
Adept
Posts: 228
Joined: Fri Jun 20, 2008 3:15 am

Re: Performance suggestions to reduce lag

Post by Crash. »

Time for me to fire up an ST for comparison...
User avatar
Paul Stevens
CSBwin Guru
Posts: 4318
Joined: Sun Apr 08, 2001 6:00 pm
Location: Madison, Wisconsin, USA

Re: Performance suggestions to reduce lag

Post by Paul Stevens »

http://dianneandpaul.net/CSBwin/CSB-TheGame.zip

Experiments to incriminate/exonerate the graphics
and CPU utilization. Eliminate any key-queueing
problems. Eliminate any delays for x-y motion.
(The party just twirls in place).

Put the files by themselves in a folder.
In parentheses are results from my computer.

Experiment 1
Run the .exe. "Dungeon'. Then select
Playback. Record total time until credits
appear. Record CPU time from task manager.
(9 minutes 2 seconds. 00:00:01)

Experiment 2
Same except select 'Extra Ticks' immediately
after starting playback.
(1 minute 22 seconds. 00:00:03)

Experiment 3
Same as 1) except select "Quick Play"
immediately after starting playback.
(52 seconds. 00:00:03)

Experiment 4
Run executable. Dungeon. Resume.
CSBGAME3. You are in a long hallway.
Run up and down the hallway --- Press
forward five times as quickly as possible.
Estimate the time between last key and
end of party motion. (1 second)
User avatar
Crash.
Adept
Posts: 228
Joined: Fri Jun 20, 2008 3:15 am

Re: Performance suggestions to reduce lag

Post by Crash. »

Hi, just to be clear - do I get out a stopwatch and time Experiment 1 then also record the CPU time in the task manager? When I display the CPU time in the task manager, it stays at 0:00:00 for CSBwin
User avatar
Paul Stevens
CSBwin Guru
Posts: 4318
Joined: Sun Apr 08, 2001 6:00 pm
Location: Madison, Wisconsin, USA

Re: Performance suggestions to reduce lag

Post by Paul Stevens »

do I get out a stopwatch and time Experiment 1

yes

it stays at 0:00:00 for CSBwin

Indeed. It was only one second for me......
CSBwin uses very little CPU time. The program
was designed for an 8 MHz 68000 that ran much
slower because of cycle stealing by video processor.
User avatar
Crash.
Adept
Posts: 228
Joined: Fri Jun 20, 2008 3:15 am

Re: Performance suggestions to reduce lag

Post by Crash. »

My Results:

Experiment 1
Run the .exe. "Dungeon'. Then select
Playback. Record total time until credits
appear. Record CPU time from task manager.
(9 minutes 2 seconds. 00:00:00)

Experiment 2
Same except select 'Extra Ticks' immediately
after starting playback.
(1 minute 22 seconds. 00:00:00)

Experiment 3
Same as 1) except select "Quick Play"
immediately after starting playback.
(1:14 seconds. 00:00:00)

Experiment 4
Run executable. Dungeon. Resume.
CSBGAME3. You are in a long hallway.
Run up and down the hallway --- Press
forward five times as quickly as possible.
Estimate the time between last key and
end of party motion.

It is hard to tell whether it is 1 or 2 seconds, but three steps take place after I finish pressing the keys. That is, five keys are buffered in the time it takes for the game to display three steps.

Thanks!
User avatar
Paul Stevens
CSBwin Guru
Posts: 4318
Joined: Sun Apr 08, 2001 6:00 pm
Location: Madison, Wisconsin, USA

Re: Performance suggestions to reduce lag

Post by Paul Stevens »

This proves a lot!

The virtual machine is running at the
proper rate. The party turns to the right
about 2250 times. It took you 9 minutes and
2 seconds = 542 seconds. That is 4.15 turns
per second. At normal speed it should be
about 4 per second. This is significantly
slower than I originally set it because people
complained that it was too fast. The 'Speed'
menu allows you to increase this speed.

At any rate, your machine and my code agree
on how fast the virtual game clock should
go.

Now the party cannot move faster than 1
step per 1/4 second. The engine will not
work otherwise because two things could
happen in the same tick of the clock. Without
any load, the party can move a maximum
of once every two ticks of the clock. Otherwise
the boots of speed would have no effect.
But the 'Extra Ticks' throws in one tick so you
should be able to move once per 1/4 second.

I modified CSBwin to record 'world time' at each
move and found that during experiment 4 the party
was able to move every 250 milli-seconds....exactly
as they should. And my experience was identical to
yours...about 3 moves took place after pressing
the keys five times. So I think everything is
working exactly as it should.

I have posted a new CSBGAME3.dat which includes
a par of 'Boots of Speed'. Putting them on
eliminates the 1/4 second intentional delay..
But there are other delays. Flashing the movement
buttons takes at least 20 milliseconds. At least
one vertical black interval must elapse and that
is 16 milliseconds. There appear to be other
delays but I have not pinpointed them.

http://dianneandpaul.net/CSBwin/csbgame3.zip

Try the Boots of Speed. That is as fast as the
engine will carry you without eliminating the
button flash delay and such. If it seems about
right to you then we will have proved that
the delays you see are intentional....the party
cannot move infinitely fast. If the Boots of
Speed don't do the trick for you then I will
provide an instrumented CSBwin with a way to
bypass all button flash delays and such. Then
we can look at the traces to see what is
happening.
User avatar
Crash.
Adept
Posts: 228
Joined: Fri Jun 20, 2008 3:15 am

Re: Performance suggestions to reduce lag

Post by Crash. »

Thanks for all this help. I will try this out and get back to you. Maybe it is my memory being faulty, but I don't recall this kind of lag or delay from the Atari ST, but I doubt is it CSBWin since I'm the only one complaining, so that is why I assumed it might be Windows, my keyboard, monitor input lag, or something else (such as the dungeon I'm playing). Probably the best thing for me to do is get out an ST and a copy of DM to do direct comparisons. Do you still have an ST?

Cheers
User avatar
Paul Stevens
CSBwin Guru
Posts: 4318
Joined: Sun Apr 08, 2001 6:00 pm
Location: Madison, Wisconsin, USA

Re: Performance suggestions to reduce lag

Post by Paul Stevens »

Sorry.....My ST died a decade ago.

I think the ST was faster......My original translation
copied the ST - Chaos Strikes Back code. But people
complained that it was too fast. Well, it probably
was too fast. For two reasons that I can think of.
First, the PC required essentially zero CPU time to
update the screen. The ST was rather slow in
comparison. Second, a lot of folks lived where
electric power came in 50 Hertz. They were
accustomed to 50 vertical blanks per second.
CSBwin pumped out vertical blanks at 60 per
second. That's a 20 percent difference. These
two effects made CSBwin seem too fast. So
I slowed it down. The 'Speed' menu can undo this
change and even go much faster than the original.
But you don't like the fact that the monsters go
faster, too. SO I think you need to wear a
'Boots of Speed' to make it work more to your
liking. Other than that (I could provide an
automatic 'Boots of Speed' menu option) there
is no way, short of massive rewrite, to make the
party go faster without making everything go
faster.

So far, I am convinced of these things based
on the results of your experiments.
User avatar
Crash.
Adept
Posts: 228
Joined: Fri Jun 20, 2008 3:15 am

Re: Performance suggestions to reduce lag

Post by Crash. »

I do have a character wearing boots of speed, but I was never clear on whether all characters needed them, in case that makes any difference. I originally played DM and CSB with 60hz, in case that clarifies things. If I could choose, I would prefer to have things be a little more speedy with regard to movement, without having the monsters and other things speed up, but understand this may be too much to ask. Would it help your analysis if you had an ST? More than likely, I have an extra one and the accompanying monitor.

Cheers
User avatar
Paul Stevens
CSBwin Guru
Posts: 4318
Joined: Sun Apr 08, 2001 6:00 pm
Location: Madison, Wisconsin, USA

Re: Performance suggestions to reduce lag

Post by Paul Stevens »

Would it help your analysis if you had an ST?
No, Thank you. You should sell it on eBay. Someone
will want it.

The ST emulators work so perfectly on our current generation
of fast CPUs that I would trust them as a comparison.

But the code is very clear.....The ratio of the speed of
the party versus the speed of the rest of the game seems
to be quite correct. Fireballs move at one step per tick
of the clock. The party moves at one step per tick of
the clock. That is how it is. That is how it is supposed
to be. And your CSBwin seems to be doing exactly this.

The boots need to be on every party member, as I recall.
I'm sure someone will correct me quickly if I am wrong.
User avatar
Crash.
Adept
Posts: 228
Joined: Fri Jun 20, 2008 3:15 am

Re: Performance suggestions to reduce lag

Post by Crash. »

Well the need for more boots could be it, but again I suspect that my problem may be less to do with any possible timing issue with your code, than with the way that Windows buffers keys or is updating the display. There is some subtle difference that I haven't figured out yet, which could be something as simple as input lag on my 24 inch LCD monitor, video drivers, keyboard latency, or some combination of these or other factors specific to my setup.

I did notice that my "quick play" experiment was quite a bit slower than yours (74 seconds vs 52 seconds). Does this mean anything?
User avatar
Crash.
Adept
Posts: 228
Joined: Fri Jun 20, 2008 3:15 am

Re: Performance suggestions to reduce lag

Post by Crash. »

Paul Stevens wrote:This proves a lot!
Try the Boots of Speed. That is as fast as the
engine will carry you without eliminating the
button flash delay and such. If it seems about
right to you then we will have proved that
the delays you see are intentional....the party
Hi,

The boots of speed seem remove the delay that I was experiencing.

I noticed that the speed on another computer (dual core vs. single core) was different and wanted to ask if that should be expected. I would also like to know if the timing for CSBWin is related to the screen refresh rate. Before LCDs, I would run CSBWin on a CRT up to 120hz, although now it runs at 60hz. The machine that seemed a bit faster had a screen capable of 75hz.

The only other thing I can think of is that this computer may have some kind of CPU speed management like Speedstep, which is throttleing down the CPU speed since CSBWin requires so little CPU power. I'm wondering if the responsiveness may be connected to CPU speed.

I'm still curious about the "quick play" experiment was quite a bit slower than yours (74 seconds vs 52 seconds). Does this mean anything?

Thanks very much for your consideration
User avatar
Paul Stevens
CSBwin Guru
Posts: 4318
Joined: Sun Apr 08, 2001 6:00 pm
Location: Madison, Wisconsin, USA

Re: Performance suggestions to reduce lag

Post by Paul Stevens »

The "Quick Play' should constrained by the
CPU. At least that is the idea. The CPU includes
any system time/delay for graphics. The time for
nine minutes of play was 74 seconds for you and 52
seconds for me. So that puts a upper limit on
the delay due to the CPU and graphics processing.
There were 2250 steps in 74 seconds so that puts
an upper limit of 74/2250 = .032 seconds per step.
This is insignificant and changing it to 52 seconds
would only reduce that to .023 seconds.....again
insignificant compared to the 250 ms per tick
of the internal clock. I cannot explain the 74 versus
the 52 except if the graphics is somehow faster
on my machine. But I have a rather primitive machine.
I can only say that it is not significant.
The boots of speed seem remove the delay that I was experiencing.
Therefore, the delay you are experiencing is due to
the intentional movement delay of the engine.
timing for CSBWin is related to the screen refresh rate.
Certainly and absolutely not. CSBwin is trying to
emulate the vertical refresh of the Atari. It does
this with a kind of 'phase-lock-loop' using the
system's 'real-time' clock as a reference.
(dual core vs. single core)
I would not expect this....the cpu usage is too
small to be significant to any delays you
experienced. Did you do the experiments
on a different machine or just a feeling?

You need to use the Speed menu to run CSBwin
a little bit faster. Or I can edit your savegame
to provide four pairs of Boots-of-Speed. Or you
can play the game with RTC.....it might be a bit
different.
User avatar
Crash.
Adept
Posts: 228
Joined: Fri Jun 20, 2008 3:15 am

Re: Performance suggestions to reduce lag

Post by Crash. »

Hi,

My machine is a single core P4 3.9ghz, so I don't know if that should be faster or slower than yours. If yours is more modern, that could explain something - but if yours is older, then something is fishy here.

Is there any other intentional delay other than the one affected by Boots of Speed? If so, is the delay (or are any of the delays) related to any other things that could cause them to vary from system to system?

I was wondering if maybe different monitors were changing the speed of CSBWin as seems to be the case with 50hz vs 60hz ST monitors. If the emulated refresh is based on the clock rather than the monitor refresh, that wouldn't be the issue.

It is my intention to play a number of the custom dungeons in CSBwin, and I don't think they are available for RTC (I plan to play those dungeons later). Running the game at higher speed doesn't work well for me as I have a hard enough time keeping up with the combat at normal, but for whatever reason navigating the corridors just seems a bit off for me so I spend a lot of time feeling my way around with my character's heads. I appreciate the offer on my save game files, although this would need to be accomplished for each dungeon I plan to play, so that would become tedious quickly. I still feel that there may be a problem with my system; I played one night on a faster machine and didn't have the problems running into walls. The computers have different CPUs, monitor types, refresh rates, video cards, etc... Just for the sake of it, I ran at 8-bit color with a 75hz refresh rate that did not result in any change in performance on my system. It is just a feeling from playing for a few hours on a faster system, since I didn't do the experiments, but the play felt normal, which points to a problem with this computer. I will do the experiments soon.

As a comparison, I tried DM PC both in and out of Dosbox, and it seems to be more responsive, but I think also the monsters are attacking much more quickly so I'm not sure that scales properly on current systems.

The only other thing I can think of is that perhaps the ST didn't buffer as many as three keys in addition to the current movement, so maybe I made fewer accidents. Hopefully soon I will get out an ST and a copy of DM to test and compare. Maybe it is just my imagination.

Thanks!
User avatar
Paul Stevens
CSBwin Guru
Posts: 4318
Joined: Sun Apr 08, 2001 6:00 pm
Location: Madison, Wisconsin, USA

Re: Performance suggestions to reduce lag

Post by Paul Stevens »

The only other thing I can think of is that perhaps the ST didn't buffer as many as three keys
I would bet on that. The ST operating system
is a bit different from Windows. In the ST you
asked the operating system for things like
keypresses.....in Windows it forces them upon
you whether you are ready or not. I added code
to save them up until needed.

I have a dual-core 3GHz machine on my desktop.
But I also have a PIII 900 MHz laptop that runs
CSBwin just as well. And, As I said before, CSBwin was
developed on a PI 166MHz machine and worked
just fine. I cannot believe the speed
of the CPU has any influence on your experience
with CSBwin.
Dosbox, and it seems to be more responsive, but I think also the monsters are attacking much more quickly
As I said before, I slowed CSBwin to accomodate folks
who thought the monsters and fireballs were going too
fast. So what you see makes total sense.

In summary....you can speed up the party but the
rest of the game will speed up, too. You can slow
the monsters but the party will slow, too. If you press the
'forward' button four times the party will attempt to
move forward four spaces. It all seems to be working right.
User avatar
Paul Stevens
CSBwin Guru
Posts: 4318
Joined: Sun Apr 08, 2001 6:00 pm
Location: Madison, Wisconsin, USA

Re: Performance suggestions to reduce lag

Post by Paul Stevens »

I made a CSBwin with minimal key queuing. Well, maybe not
'minimal'. It does queue up one keystroke. I can press the
forward key five times in our little experimental game and
only take four steps.

We could add this as an option if anyone likes it better
than the standard CSBwin.

http://dianneandpaul.net/CSBwin/CSBwin1 ... KeyQue.zip
Post Reply

Return to “Chaos Strikes Back for Windows & Linux (CSBWin) / CSBuild”