.qc (dot qc) - the group for quake c coders of all denominations. If you make quake one mods and write code in quake c, join our group! I'll try to answer any quake c questions - please post your inquiry in the forums...

Forum Thread
  Posts  
This is a "wrap" - coding smarter, not harder (Groups : qc : Forum : vault() : This is a "wrap" - coding smarter, not harder) Locked
Thread Options
numbersix
numbersix quake-c coder++
Oct 26 2014 Anchor

We're having a wrap party!

What you say?

A "wrapper" is a qc (or C) function that envelops or wraps another function.

In quake-c if you call precache after map load the engine will crash.

If you start coding dynamic items, random monsters and the like, you will be fixing this over and over.
You will have to find _all_ offending precache functions and put some kind of logic test around them.
Or you could do this -

Here is a one shot "wrap" fix...

Much quake-c code calls "precache_model" - we can wrap that by coding our own function.

// first - rename the built-in function call for precache - in defs.qc
// you can do the same with precache_sound

//string (string s) precache_model = #20;
string (string s) precache_model__ = #20;

// now make our wrapper function
// the great thing about this code is that precache is not called very often so it has minimal execution cost

string (string s) precache_model =
{
// if we want to take advantage of darkplaces dynamic precache - just uncomment the next line
// if (0) // note - we could devise a darkplaces engine test in place of 0, so this code would work for engines that need precache
if (time < 5) // only do this for map load items
{
return(precache_model__(s));
}
};

I used 5 seconds just to be on the safe side. Really calling precache after 1 second will usually cause the server to bomb out.
We just fixed every single precache_model call - they will not crash the server if called after map load!

That is what I call working smarter.

Edited by: numbersix

Reply to thread
click to sign in and post

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.