Index | FAQ | Search | Memberlist | Usergroups | Profile | Log in to check your private messages | Log in | Register

Spawning entities in CSQC Goto page 1, 2 Next

| Inside3d Forums Forum Index -> QuakeC Programming

View previous topic :: View next topic
Author | Message
--- | ---
daemon Joined: 07 Nov 2007 Posts: 62 |

Posted: Sun Nov 11, 2007 10:49 pm Post subject: Spawning entities in CSQC |

I would like to know how to do this properly. I THINK I am spawning them, but it appears as if they are not being drawn. All of my SSQC entities draw, but not the ones spawned inside CSQC. I also can't tell if I'm setting their origin correctly because there is no setorigin() function. I have resorted to using "entity.origin = org;" but I do not know if that even does anything at all.
Also, is there an alternative method of drawing sprites in CSQC other than spawning an entity with the model set as the sprite? I origionally tried using drawpic(), but it seems as if .spr is not supported. I'm assuming it's because sprites can have frames.
_________________
-daemon [ daemonforge.org ]

Back to top |

Spike Joined: 05 Nov 2004 Posts: 944 Location: UK |

Posted: Mon Nov 12, 2007 7:43 pm Post subject: |

setorigin should exist. void(entity e, vector org) setorigin = #2; exactly the same as the server, except that it doesn't affect visibility, only physics. one of the key features of csqc is that the ssqc builtins be available where practical to provide consistancy between game modules, facilitating the creation of shared code, for prediction purposes, as well as consistancy.
To make an entity visible, you need to do a few things.
1: spawn it (or get an ssqc->csqc ent spawned by the engine for you).
2: set its origin/angles
3: set its model
4: set its alpha if you're paranoid (0 == 1 like in ssqc, so shouldn't be required - only if you're paranoid)
5: set its draw mask. this is the only additional requirement from ssqc. if you set it to 1, then it'll be drawn at the same time as any csqc-invisible entities from the server.
6: optionally you can set the predraw callback on the entity. This will give you the chance to update features of the entity (smooth rotation, strange animation, making it bob up and down, etc).
as an alternative to step 5, you can use void(entity e) r_addentity = #301; instead.
That'll make your csqc entity visible, assuming you gave it the right origin and model.
drawpic doesn't support sprites. its intended to be 2d-overlay only, drawn after the game scene. you can add 'sprites' with it (in the form of tga/jpeg/png), but they're not depth tested (there are some perspective projection functions which can do funky maths to calculate where to draw it).
_________________
What's a signature?

Back to top |

Electro Joined: 29 Dec 2004 Posts: 241 Location: Brisbane, Australia |

Posted: Tue Nov 13, 2007 1:10 am Post subject: |

I think that could very well be the most documentation anyone has ever done for CSQC... and it looks like it's a forum post typed out in 5 minutes (because it is). Kudos to Spike for being the first. Consider yourself honoured daemon. _________________
Unit reporting!
http://www.bendarling.net/

Back to top |

daemon Joined: 07 Nov 2007 Posts: 62 |

Posted: Tue Nov 13, 2007 3:37 am Post subject: |

awesome. thank you. I didn't expect an answer so fast

Spike wrote:
one of the key features of csqc is that the ssqc builtins be available where practical to provide consistancy between game modules, facilitating the creation of shared code, for prediction purposes, as well as consistancy.

that's cool. I was wondering about that as well. you must have read my mind.

Spike wrote:
drawpic doesn't support sprites. its intended to be 2d-overlay only, drawn after the game scene. you can add 'sprites' with it (in the form of tga/jpeg/png), but they're not depth tested (there are some perspective projection functions which can do funky maths to calculate where to draw it).

I actually want to display spr/spr32 images, because I will be using multiple frames in some cases.
_________________
-daemon [ daemonforge.org ]

Back to top |

daemon Joined: 07 Nov 2007 Posts: 62 |

Posted: Tue Nov 13, 2007 4:56 am Post subject: |

hmm... does it make any difference that I'm using darkplaces? because I still can't get my entity to become visible. I've tried everything other than the optional step 6. _________________ -daemon [ daemonforge.org ]

Back to top |

Urre Joined: 05 Nov 2004 Posts: 1073 Location: Sweden |

Posted: Tue Nov 13, 2007 7:20 am Post subject: |

Spike, you da man. Feels good to hear these things from the boys and girls who were there to design the entire system, since then it should atleast in theory be correct. Hopefully either daemon gets it working, or Spike notes that he forgot something
Haven't personally dwelved into this yet, but it will certainly be interesting, as well as probably frustrating.
Spike: you said setorigin only affects physics, not visibility, then why do you in your 5(6) step program say one should set the entitys origin in step 2? Does that mean it's enough with ent.origin = blah; ?
daemon: for multiple frames using drawpic i'd say you just do your own animation system, using multiple images.
_________________
Look out for Twigboy

Back to top |

Spike Joined: 05 Nov 2004 Posts: 944 Location: UK |

Posted: Tue Nov 13, 2007 4:32 pm Post subject: |

Quote:
Spike: you said setorigin only affects physics, not visibility, then why do you in your 5(6) step program say one should set the entitys origin in step 2? Does that mean it's enough with ent.origin = blah; ?

setorigin changes the origin, yes. it does ent.origin = blah; inside, yes.
It also relinks the entity for more efficient clipping exactly the same as on the server. Its really up to the engine to decide if it affects visiblility, but really the engine just loops through the ents that are known about and links them in regardless of wether they're in the pvs. This is true of FTE at least. One reason to do it this way is because of possible attachments in the predraw function that could be in the pvs.
I can't remember how spr32 actually works... But you can extract the images and drawpic them, although blending between one frame and annother is not nice that way. Alternativly you could set up a second scene and draw them there (not reliable in DP last time I checked) but then you're back to the original problem.

Quote:
I think that could very well be the most documentation anyone has ever done for CSQC... and it looks like it's a forum post typed out in 5 minutes (because it is).

go look on wiki.quakesrc.org for EXT_CSQC for how csqc was originally designed. Says what every builtin does, but I admit that it doesn't say how any of it works, only what each builtin does.
This means there's more 'official' documentation for csqc than there ever was for ssqc.
I'm hesitant to write a tutorial about csqc myself, because I know I suck at writing to explain. Then again, I need the practise.
The key thing to note is that csqc is exactly like ssqc... (hah!)
Both code modules build entity state which is sent towards the renderer. The difference is how they do it. With ssqc, the server itterates over the entity lists, sending the state to the clients as it is. With csqc, the client says to the qc 'hey, draw stuff', and the csqc is expected to say how things are to be drawn.
A key thing to note is that renderer state is seperate from csqc state. That is, once a csqc entity is added to the renderer state, you can change the csqc entity and add a new copy to the list.
The 3d scene is entirly state based. You set up the view properties/flags (this includes the view width, height, x, y coords, fov), you add your entities, then you tell the renderer to do its thing and render the scene. You then have a choice of resetting the view properties and drawing annother scene the same frame (again, doesn't work too well in DP), or you can move on to drawing the hud. Note that you can draw a 3d scene as part of the hud.
The problem here is how you specify which entities to draw. If you're going to draw a model on the hud, then you really don't want any of the entities from the server being visible or your hud is going to get weeeird with a capital 'we'. Thus, to add entities to the renderer's list, there are two seperate builtins to do it with. r_addentity(entity ent) will add a single entity to the scene. This bypasses that entity's drawflags, and will ensure that it is shown. The other way is with r_addentities(float mask) which draws all entities with a specific drawflags mask - there is a quirk here that if you specify a mask including '1', you will ask the engine to add the entities it is keeping secret, and '2' will add the default viewmodel also. Hopefully...
But yeah, if you've got csqc drawing any part of your scene, and you get entities from the server shown, then r_addentity(myenthere) is guarenteed to bypass all pvs checks - remember that there is no pvs possible in the worldless scenes on huds. The rest is just making sure that it has a valid model and origin.
You should use setorigin where possible as you'll regret it if you decide to add proper physics later, plus you'll remember to do it for ssqc too. But for the purposes of visilibity, setorigin is equivelent to just setting the origin.
_________________
What's a signature?

Back to top |

daemon Joined: 07 Nov 2007 Posts: 62 |

Posted: Tue Nov 13, 2007 5:35 pm Post subject: |

Urre wrote:
daemon: for multiple frames using drawpic i'd say you just do your own animation system, using multiple images.

I really want to stick with actual sprites just to keep things less cluttered. I'm going to be using a LOT of them.
_________________
-daemon [ daemonforge.org ]

Back to top |

daemon Joined: 07 Nov 2007 Posts: 62 |

Posted: Wed Nov 14, 2007 4:17 am Post subject: |

Thanks to Spike and Dresk! It works now. Even though I had the model precached inside CSQC, it would not draw until it was precached inside SSQC. It also seems as though it is not required to precache inside CSQC, but I'm curious if it affects anything.
_________________
-daemon [ daemonforge.org ]

Back to top |

Urre Joined: 05 Nov 2004 Posts: 1073 Location: Sweden |

Posted: Wed Nov 14, 2007 7:21 am Post subject: |

Yeah I heard something about that in a chat once... Spike: want to confirm that this is the way it's supposed to work? Does this mean I could not have entirely clientside models which are not at all present on the server? If so, why does CSQC require something being precached on the server?
Also, as I understand it, those steps describe CSQC entities which aren't linked to SSQC. What about those that are, namely predicted entities (not limited to clients, which I assume is also a different matter)?
_________________
Look out for Twigboy

Back to top |

daemon Joined: 07 Nov 2007 Posts: 62 |

Posted: Wed Nov 14, 2007 7:36 am Post subject: |

the irritating thing about this is that you can't precache a model in SSQC and immediately use it in CSQC. you have to wait until it's done precaching before you try to use the model. _________________ -daemon [ daemonforge.org ]

Back to top |

Spike Joined: 05 Nov 2004 Posts: 944 Location: UK |

Posted: Wed Nov 14, 2007 2:18 pm Post subject: |

daemon wrote:
the irritating thing about this is that you can't precache a model in SSQC and immediately use it in CSQC. you have to wait until it's done precaching before you try to use the model.

CSQC is meant to have two seperate sets of precached models.
Indexes above 0 match the precaches sent from the server.
Indexes below 0 match the precaches performed inside the csqc.
If you precache a model at csqc startup, it gets a negative index. if the server then precaches it, setmodel starts applying the >0 version instead, but the <0 version is still valid. Names are first matched to the server's precaches.
This is how its meant to work in FTE at least. Which provides compatability with the modelindexes sent from the server and the capability to precache them yourself.
Sounds like a DP bug to me.
_________________
What's a signature?

Back to top |

Urre Joined: 05 Nov 2004 Posts: 1073 Location: Sweden |

Posted: Wed Nov 14, 2007 10:44 pm Post subject: |

Good, good... _________________ Look out for Twigboy

Back to top |

LordHavoc Joined: 05 Nov 2004 Posts: 243 Location: western Oregon, USA |

Posted: Thu Nov 15, 2007 11:36 am Post subject: |

Spike wrote:
But yeah, if you've got csqc drawing any part of your scene, and you get entities from the server shown, then r_addentity(myenthere) is guarenteed to bypass all pvs checks - remember that there is no pvs possible in the worldless scenes on huds. The rest is just making sure that it has a valid model and origin.

Actually darkplaces pvs checks all entities in the renderer, so adding entities that are not seen is not very harmful to performance, saves some effort for csqc coders who might otherwise worry about having a thousand tree models being drawn behind walls unnecessarily or something like that.

Back to top |

LordHavoc Joined: 05 Nov 2004 Posts: 243 Location: western Oregon, USA |

Posted: Thu Nov 15, 2007 11:38 am Post subject: |

Spike wrote:
Sounds like a DP bug to me.

You always use emoticons in regard to DP bugs it seems...
I have no csqc mods to test for such things, hence it remains buggy.

Back to top |

Display posts from previous:

| Inside3d Forums Forum Index -> QuakeC Programming | All times are GMT Goto page 1, 2 Next
Page 1 of 2

Jump to:

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2004 phpBB Group