PK++ Progress 14/02/07

INTERPOLATION
=============

Firstly PCF did not write interpolation properly, on mouse, on animations, or anything. What they typically did was:

rotation = m_lastRotation + rotationDelta*0.33

where rotationDelta = m_lastRotation – m_nextRotation

Whereas what they should have is:

rotation = m_lastRotation + rotationDeltaRate*deltatime

where rotationDeltaRate = (m_lastRotation – m_nextRotation) / deltatimeperiod

They have made this mistake lots. Fixing interpolation in the bits we can see is straightforward. As I discussed with PeTjA, we can apply this interpolation to ALL items on the map, so that everything moves smoothly.

Typically linear interpolation is used for unpredictable items, and Catmull-Rom (cubic) splines for predictable movement (e.g. any mass subjected to constant or continuous accelerations.)

TIMING
======

Yikes! This is an important one. Ever since I improved item spawn times for PK++, I have always been suspicious of how accurate PKs timing is. We all know it has the ability to run too fast/slow at times. To test this I relied on the LUA os.clock() and os.time(). os.time() gives tick time (since 1982 or so) in seconds, whereas os.clock() gives seconds fractions since the code begins. It should be noted that math.floor(os.time()-os.clock()) is constant and remains constant.

The first problem is that PK works out time by adding deltas. This is CRAZY, since floating point (even double) will exhibit rounding errors quite quickly through any addition.

To test this, I set up the delta addition in comparison to os.time and os.clock. They were WAY off. Particularly because my machine is slow and does not always achieve the 45 FPS of the server. When the machine is slow it ASSUMES that the delta is 1.0/FPS regardless of whether it achieves that or not.

It gets worse though…

The MEASURED delta used varies by a huge amount, but dependent on it trying to hit a certain FPS. This is because they have imposed a minimum loop period of 30FPS or 0.0167secs. What this means is that loops can only occur in multiples of 30FPS, but such that over a second or so, they will meet the total FPS.

Say for example the desired FPS is 45. For PK this will run like this:

30,60,30,60,30,60,30,60,30,60,30,60,30,60 etc.

Of course the average delta for 45FPS is correct.

In other words the loops are not evenly spaced in time. What is terrible for netcode and interpolation and ANYTHING else.

This explains why 30 and 60 FPS seem to be smoothest. Iterations seem to only occur in 0-30, 30 or 62.5 FPS steps.

It is possible to stall the frames so they become evenly spaced (by setting FPS very very high and limiting within the LUA). But the issue is not that a frame goes too quickly, but too slowly, to average.

The maximum speed at which Havok can run is also set, at 62.5 FPS (or rather, this is the minimum time step it can accept).

Finally we can address these issues by setting the frame rate to zero (so max speed), then controlling the actual tickrate through the LUA. A suitable tickrate is 62.5 FPS providing one tick per physics iteration. This has already been tested for CPU usage and is very low.

Given this, the number of updates a client can recieve (q3s snaps) MUST be limited on the client. After testing, somewhere between 10 and 20 gives reasonable looking gameplay. As a current rule of thumb, the data is :

= number of players * update rate (serverframerate on client) * 30

So 32 players at 10fps is around 9KBps which is reasonable.

Additional work needs to be completed before reducing the update data further. This should be possible without access to the source code.

PK++ Progress 07/02/07

NETCODE
========

Interpolation FIXED! (finally)

What seems to be the case, is that part of the player animation was causing a glitch which resulted in the player location on receiving the player frame to be mislocated. This is now fixed by turning off animation until I get more time to look at it. Right now animation is synchronised, but I am considering having this predicted on the client.

What this means in real terms is that gameplay at low data rates will be smooth. Since PCF did not understand what interpolation was, it broke as you set serverframerate(client) less than the actual server frame rate. This meant that low serverframerate(client) looks very jerky/choppy. It should be noted too that enemyprediction also damages movement on the server.

Given this, I can now interpolate ALL moving items between frames, so everything is smooth.

The important part here is that serverframerate(client) can be much less than the server tick rate. It is considered that good physics occurs on servers set to 60 fps, but 60fps of data for ffa is too much. By lowering serverframerate(client) you can still have 60fps on the server, and still have smooth, low bandwidth gameplay.

By comparison, Q3 and CS both use 20 updates to the client per second (although due to server tickrate), although HPBs can lessen this if required. Gameplay is still smooth on both these games, and no one notices the additional latency caused by the interpolation. It is possible to correct for this using unlagged/anti-lag which PK has the foundations for already. Whether we go for full client-side anti-lag or not will be decided in due course.

Where PK loses out is hiding things you cannot see from the update. The way Q3 works is to only update players which you might be able to see/hear, and not ones way off in the distance. We cannot yet do this in PK, and cannot without the source code. I may have to think of other ways to reduce data if required. If the main issue is reducing data for COOP, then simply I can not update monsters which NO ONE can see or hear – they will still be there on the server though.

I also loaded up Q3 to compare upstream and downstream packet sizes, and PK and Q3 are now similar.

MAPS(!)
=======

SP maps are beautiful, and if in any doubt load up C2L5_Town or any and see how good they look on full detail. However, a number of the maps do not work on dedicated server – and in fact crash PK out completely. This is the reason, for example, why there are no conversions of City on the Water which is a great map.

The loading problem is now FIXED! (this is important!)

ALL SP maps can now be used on dedicated server, which should also fix some issues found by mappers 🙂

Also when loading SP maps in MP now, the items which do not belong in MP are not loaded (such as monster Ambush). Player respawning can now take place from monster respawn points which seem nicely distributed. The intention is that for SP maps which are obviously not set up for MP, items will be placed by code. Generally the level exit will be replaced by a teleport to start – much like Q1 did. This forms a loop of what is initially a linear map. Other item placement issues will be considered later – but what is most important is that the loading of ALL maps into MP works and makes sense.

COOP
=====

More work was completed on AI Brain, but essentially I need to work through each monster, making sure they do not assume a single SP player, and can instead attack one of a group of players. I am not worried about this at all.

I suggest that we have around three type of COOP: SP COOP (SP game with more than one player), MP COOP (ffa with monsters), and COOP Arena (all vs. monsters).

MOUSE
======

I have written my own mouse code, which reduces mouse lag, and adds mouse acceleration and smoothing as required.

MONSTER AND ITEM SCALING
========================

I added two more parameters to the \addthing and \addmonster commands, firstly the number of things/monsters added at once. This seems to lag out clients with larger numbers, so I may have to add them over several frames.

Secondly I added scale to both. It is great fun playing with the scale of various items. In fact our test map, DM_Boss, can quickly become too small, so Killua has made another test map without walls. A 200xscale Panzer_Demon for example is awesomely impressive. Even normal monsters resized to boss-size are worth seeing.

NEXT STEPS
==========

With interpolation out of the way, other fixes are relatively easy, so I should be quicker with them. There may be some hacks of the exe/dll I might want to do, but other than that you should see more progress soon!

PK++ Progress 15/01/07

NETCODE
========

Interpolation now works, although there is a small glitch I need to resolve which might be a rendering issue. Other than that play is smooth at 1 network frame per second, but much more reasonable at about 10-20. PCFs interpolation appears to be very wrong, and it is worth noting that it screws up servers to have it enabled too. Player pitch/yaw is also being interpolated but needs more work.

Extrapolation was added too, although we will need to play with this. It may be possible to auto-compensate for lag, both on the server and client. Extrapolation of course makes things slightly less smooth, but this can be controlled.

I have yet to play with item/weapon prediction.

I have to look at whether I can reduce the amount of data per player.

I also added all the netcode commands to console.

COOP
=====

Killua-chan provided an excellent map, although I believe PeTjA has some minor alterations.

It is possible to add a lot of the monsters already, but their code requires a listen server. Once I have perfected how to deal with multiple players using one monster, I will duplicate to all (probably via the AI Brain code).

My thoughts for COOP are basically either SP COOP or MP COOP, MP COOP perhaps more like ffa with monsters. I also thought about a COOP Arena gamemode.. where as a group of players you have to make it through progressively more difficult levels. Imagine DM_Boss with Thor to start, you have to kill him without you all dying, then level 2 is the same map, but with Thor and Panzer_Demon, and so on…

CODE
=====

Now is a good time to work on structuring the code better – so this is what I am doing, mainly the game and player code. I wish to use polymorphism rather than conditionals for custom gamemode responses (if you know what I mean). This will make thing a lot easier to make new custom gamemodes without screwing up existing code – an important method

PHYSICS
=======

At a glance it might be possible to try some new movement code, but we can try this later.

PKGUID
======

I am still yet to confirm whether I can obtain the CDKEY to MD5/RSA. Without it, making something unqiue generated from the game might be difficult.

DEMOS
======

Netcode improvements make writing this easier.

Progress on PK++

Guys, I thought it would be sensible to make more visable some of the progress being made on PK++. A small few were aware of the work going on, albeit slow, but there is no harm in making it more public.

My intention is to fix some of the issues as quickly as possible and update via PK++. My motivation is to add to the game as much as fix some of the important remaining issues.

If anyone is willing to help out, any contribution is more than welcome! Please contact me through kerberos99@hotmail.com or add me on msn from that address.

Progress on PK++

Guys, I thought it would be sensible to make more visable some of the progress being made on PK++. A small few were aware of the work going on, albeit slow, but there is no harm in making it more public.

My intention is to fix some of the issues as quickly as possible and update via PK++. My motivation is to add to the game as much as fix some of the important remaining issues.

If anyone is willing to help out, any contribution is more than welcome! Please contact me through kerberos99@hotmail.com or add me on msn from that address.