View previous topic :: View next topic |
Author |
Message |
goblinoid
Joined: 21 Mar 2008 Posts: 22
|
Posted: Thu Dec 17, 2009 9:07 pm Post subject: excution order |
|
|
Hi,
I have a doubt, in which order the engine executes the functions written in qc?
Thanks |
|
Back to top |
|
 |
ceriux

Joined: 06 Sep 2008 Posts: 969 Location: Florida, USA
|
|
Back to top |
|
 |
Urre

Joined: 05 Nov 2004 Posts: 1073 Location: Sweden
|
Posted: Thu Dec 17, 2009 10:59 pm Post subject: |
|
|
He's being pretty straightforward. I don't quite know the answer though, I'm also interested. _________________ Look out for Twigboy |
|
Back to top |
|
 |
metlslime
Joined: 05 Feb 2008 Posts: 177
|
Posted: Thu Dec 17, 2009 11:39 pm Post subject: |
|
|
He probably means like, touch functions, think functions, spawn functions, etc. I think the answers are (please someone correct me):
- spawn functions are executed in the order the entities are listed in the BSP file
- think functions, for all entities that need to think during the same server frame, are executed in order of edict number
- touch functions are executed like this: physics are run on entities in order of edict number, and if an entity touches another entity during the physics move, its touch function is called immediately, then the entity it touched is called right after that. |
|
Back to top |
|
 |
ceriux

Joined: 06 Sep 2008 Posts: 969 Location: Florida, USA
|
Posted: Fri Dec 18, 2009 12:15 am Post subject: |
|
|
wouldnt is problem be posted in the engine section then? _________________ QuakeDB - Quake ModDB Group |
|
Back to top |
|
 |
Wazat
Joined: 15 Oct 2004 Posts: 732 Location: Middle 'o the desert, USA
|
Posted: Fri Dec 18, 2009 2:26 am Post subject: |
|
|
Not really. This order is very relevant for qc coding. It's sometimes important to know what order certain QC functions will be called (for example, worldspawn always goes first, then other spawn functions). _________________ When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work. |
|
Back to top |
|
 |
goblinoid
Joined: 21 Mar 2008 Posts: 22
|
Posted: Fri Dec 18, 2009 8:40 pm Post subject: |
|
|
ceriux wrote: | um explain your problem more please... |
I'll try...
In C programs there's the main function that's the first to be called and dictates when/if the other functions are called (well, I'm not really a programmer, so this can be incorrect). In QC, we define lots of functions, that usually call or are called by other functions, but I can't realize which one is the first to be called. Is there a main function anywhere? Is there a standard order of function calls?
Thanks!
Last edited by goblinoid on Sat Dec 19, 2009 4:03 am; edited 1 time in total |
|
Back to top |
|
 |
MeTcHsteekle
Joined: 15 May 2008 Posts: 397 Location: its a secret
|
Posted: Sat Dec 19, 2009 3:35 am Post subject: |
|
|
i always imagined it as a action/reaction thing where the first one gets called and fires off others which fire of others and they all branch out
kinda like nuclear power i suppose
but that's just what i thought _________________ bah |
|
Back to top |
|
 |
goblinoid
Joined: 21 Mar 2008 Posts: 22
|
Posted: Sat Dec 19, 2009 4:17 am Post subject: |
|
|
MeTcHsteekle wrote: | i always imagined it as a action/reaction thing where the first one gets called and fires off others which fire of others and they all branch out
kinda like nuclear power i suppose
but that's just what i thought |
So do I. And that's probably true for most of the functions, but I don't think the engine calls only one function that starts it all, I also think there might be some sort of loop that executes PlayerPreThink and PlayerPostThink, and probably other functions, over and over again. But that's only my hypothesis. I hope someone can make this clear... |
|
Back to top |
|
 |
ceriux

Joined: 06 Sep 2008 Posts: 969 Location: Florida, USA
|
Posted: Sat Dec 19, 2009 5:15 am Post subject: |
|
|
i look at it like a list.
the order in which they're called are in the progs.src and i imagine most functions are just called as the game reads out the order of the qc files listed in that progs.src minus a few like client connect, and playerpost(pre?)think.
basically i feel they're called either when they're told to, when they're supposed to or as they're hit in the list specified in the progs.src although i may be wrong. but thinking like that has helped me so far when coding for my mods. _________________ QuakeDB - Quake ModDB Group |
|
Back to top |
|
 |
goblinoid
Joined: 21 Mar 2008 Posts: 22
|
Posted: Sat Dec 19, 2009 2:02 pm Post subject: |
|
|
I think progs.src just tells the compiler in which order it should read the .qc files...
Ok, found that on QuakeC Specs:
Quote: | 7.3 Mandatory functions
These functions must be defined in Quake C, since they are invoked by Quake under certain conditions.
Misc
void main();
Only used for testing progs.
void StartFrame();
Called at the start of each frame.
Behavior of players
void PlayerPreThink();
Called with self=player, for every frame, before physics are run.
void PlayerPostThink();
Called with self=player, for every frame, after physics are run.
Management of network game clients
void ClientKill();
Called when a player suicides.
void ClientConnect();
Called when a player connects to a server, but also, for every player, when a new level starts.
It is used to announces the new player to every other players.
void PutClientInServer();
Call after setting the parm1... parm16.
void ClientDisconnect();
Called when a player disconnects from a server
Announce that the player has left the game.
void SetNewParms();
Called when a client first connects to a server. Sets parm1...parm16 so that they can be saved off for restarts.
void SetChangeParms();
Call to set parms for self so they can? |
I think they forgot worldspawn here.
Also:
Quote: | 4.1 Running Quake-C code
Here are some more remarks from John Carmack:
Code execution is initiated by C code in quake from two main places: the timed think routines for periodic control, and the touch function when two objects impact each other.
Execution is also caused by a few uncommon events, like the addition of a new client to an existing server. |
So I supposed the order's like this:
ClientConnect
Worldspawn
Entities spawn functions (or would it come after parm functions?)
SetNewParms
PutClientInServer
StartFrame
PlayerPreThink
everything else
PlayerPostThink
repeat the last 4 for every frame
and eventually
ClientKill
ClientDisconnect
SetNewParms
Is this right? Perhaps an engine coder can answer. |
|
Back to top |
|
 |
Spike
Joined: 05 Nov 2004 Posts: 944 Location: UK
|
Posted: Sat Dec 19, 2009 3:00 pm Post subject: |
|
|
if you depend upon the order, you're doing something wrong, tbh.
Okay, so you can depend upon prethink being called before think before postthink, but you can't depend upon one player's postthink being called before the next player's prethink if you care about DP compatibility.
ClientConnect happens after the world has spawned and run its first physics frame. Even without seperate client+server.
SetNewParms should *NEVER* do anything that even remotely depends upon execution order.
Touch functions happen when other entities touch self. That is, you cannot depend upon touch/think ordering.
For players:
SetNewParms
ClientConnect
PutClientInServer
repeat:
PlayerPreThink
think
PlayerPostThink
with periodic:
ClientKill / KRIMZON_SV_CLIENT_COMMAND stuff.
when they leave:
ClientDisconnect
In NQ, players get thier think functions called before other ents in the frame, but that's not often relevent unless perhaps you want to make a bot that works with mods that depend upon that ordering. Players will have their think functions called between the think functions of other ents - but only if the nextthink times are always the same. Unless the server supports prediction, in which case any assumptions based upon player/non-player thinks will break your mod.
Simply put, if the ordering of function calls is not given by the names of the functions themselves, then you're doing something wrong which will break at some point. _________________ What's a signature? |
|
Back to top |
|
 |
goblinoid
Joined: 21 Mar 2008 Posts: 22
|
Posted: Sat Dec 19, 2009 4:26 pm Post subject: |
|
|
Thanks Spike, that explains pretty much everything
I'm not doing anything that really depends on the execution order, I'm just trying to figure out where the code brakes. Apparently it's somewhere near PlayerPostThink, but I've read the code hundreds of times and couldn't find the error. I don't know if the problem is in PlayerPostThink itself, one of the functions called by it, or the next function executed by the engine (that would be StartFrame, right?). So I decided to read the code following the execution order (I also got curious about how the engine operates). That's probably not the best way to find the problem, but it's the best I can do with my (in)experience. |
|
Back to top |
|
 |
Spike
Joined: 05 Nov 2004 Posts: 944 Location: UK
|
Posted: Sat Dec 19, 2009 9:59 pm Post subject: |
|
|
for players specifically, you have:
if(retouch)triggers.touch
playerprethink
self.think
solids.touch
triggers.touch
playerpostthink
order obtained from fte, but from the NQ pathways, so it should match up closely enough with NQ engines. _________________ What's a signature? |
|
Back to top |
|
 |
Sajt
Joined: 16 Oct 2004 Posts: 1026
|
Posted: Mon Dec 21, 2009 9:45 am Post subject: |
|
|
The other entrypoint for QC code are the entity spawn functions. monster_army, info_player_start, and the like. When the engine loads a map, it takes each entity defined in the map, and looks for and executes a QC function with the same name as the entity's classname field.
The spawn functions are (like metlslime said) called in the order that the entities are defined in the map, that is, the order should be treated as 'undefined' by the programmer. If you have an entity that needs to find another entity at the start of the map (i.e. a teleport looking up its destination), you have to delay that by 0.1 or 0.2 seconds, when it's ensured that all entities will have been spawned (the Quake progs do this often).
The exception is the worldspawn entity (yes, worldspawn is not a special function, just another entity). worldspawn is (I THINK) always the first entity in the map, so its spawn function is always executed before those of any other entities. In fact, it should be the very first QC code executed in all cases (except loading a savegame). Which means that you can do all 'initialization' stuff in worldspawn.
And the entity spawn functions are only called on the 'map entities'. They aren't called when you spawn an entity with code (using the spawn() function). _________________ F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe. |
|
Back to top |
|
 |
|