by FrikaC » Wed Dec 20, 2006 6:21 am
To answer the question of the topic (QuakeMatt's methods are ideal for counting entities, so ignoring the problem and answering the question) you can be sure that all map entities that will be spawned and kept are done by the second frame, and all have been spawned by the first frame.
When Quake initializes a map, it runs all the spawn functions for each map entity, then it runs two server frames back to back. This allows all entities to 'settle': items will droptofloor(), doors will link and so forth.
After these two frames, Quake makes baselines of all entities (used for the network 'delta' compression: Quake sends the baselines to connecting clients, and then only sends differences from these baselines in entity update packets).
So after two server frames one should be assured that everything is in it's final state. The first server frame begins just after the entities are all spawned, so that's useful as well. The problem becomes when to trap it. Quake's frames, as described in the FrikBot dissection, each begin with a call to StartFrame then a call to the .think() function of each entity in turn provided the .nextthink value is greater than zero and less than the current time.
The easiest way therefore is to tap into StartFrame(), and keep an eye on the framecount var id set up there (or make one if you code doesn't already have one). Upon entering the first server frame, after every entity has spawned, framecount will be 0. After the first frame and beginning on the second, framecount should be 1.
You could also trap the second frame using a .think function (not the first for reasons I will discuss).
When Quake runs the two first frames it locks in the frametime to 0.1, but time (the variable) doesn't update untill the end of a frame, thus the first frame runs at a time value of 0 and the second at time 0.1. Since the restriction on nextthink is it must be a value greater than 0, you can make the nextthink of an entity equal 0.001 (or any value between 0 and 0.1) when it is first spawned in the map, and it will occur in the second server frame.
The reason you can't trap the first frame, then, is that you need to have a nextthink between 0 and the current time, which would also be 0.
I know this is a far more technical description than you probably wanted or needed, but the subject of how to trap the first two frames is something people who are doing more advanced QuakeC need to know if they don't already, and I thought I'd take the time to explain it as best I can.