Forum

time, timing, timey-wimey

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

time, timing, timey-wimey

Postby ajay » Tue Nov 11, 2008 8:21 pm

This is coming from another thread, where I had an idea to dynamically affect a torchlight over time, e.g. it will get duller as the battery runs out. I've two problems
1) I've always struggled with using time in quakeC, e.g. getting something to happen after a certain amount of time, without messing up everything
2) Also I've realised that it'll have to stop/start when the player turns off the torch

Any suggestions/thoughts would be nice. Ta, Andy.
User avatar
ajay
 
Posts: 559
Joined: Fri Oct 29, 2004 6:44 am
Location: Swindon, UK

Postby MauveBib » Wed Nov 12, 2008 12:20 am

Not too hard.

First, set up:


Code: Select all
.float torch_dim_time;
.float brightness;


in defs.qc or wherever. Then. assuming self.brightness is the torch brightness, set it to 100 or whatever when the torch is turned on, then do something like this is a function run every frame (W_WeaponFrame is where I normally stick things like this)

Code: Select all
if ((self.brightness > 0) && (self.torch_dim_time < time))
{
     self.brightness = self.brightness - 1;
     self.torch_dim_time = time + 10;
}


That'll dim by one brightness point every ten seconds, adjust as you see fit.

For the turning off and on functions, just set brightness to 0 or 100 or whatever.
Apathy Now!
User avatar
MauveBib
 
Posts: 634
Joined: Thu Nov 04, 2004 1:22 am

Postby r00k » Wed Nov 12, 2008 12:29 am

self.torchtime = time + 30;

void () LightTorch =
{

if (time > self.torchtime) return;

...

I cant remember the dynamic light command in QuakeC, not EF_DIMLIGHT, but the one darkplaces supports that has a radius parameter.... you could lower the radius based on time..

radius = ((self.torchtime - time)/self.torchtime) * units;

units can be your preference of how bright 10 maybe good enough..
r00k
 
Posts: 1110
Joined: Sat Nov 13, 2004 10:39 pm

Postby MauveBib » Wed Nov 12, 2008 12:59 am

r00k: he's using a cubemap torch, so no need for the radus etc.
Apathy Now!
User avatar
MauveBib
 
Posts: 634
Joined: Thu Nov 04, 2004 1:22 am

Postby ajay » Wed Nov 12, 2008 2:29 pm

Thanks a lot, thats brilliant help, cheers :D
User avatar
ajay
 
Posts: 559
Joined: Fri Oct 29, 2004 6:44 am
Location: Swindon, UK

Postby ajay » Wed Nov 12, 2008 7:58 pm

However it doesn't seem to be working. The light's not getting any dimmer. Is it the light cannot be changed after being spawned, and therefore is just remaining at its initial value?
User avatar
ajay
 
Posts: 559
Joined: Fri Oct 29, 2004 6:44 am
Location: Swindon, UK

Postby Wazat » Wed Nov 12, 2008 8:32 pm

I don't know if it works with dynamic lights, but if somehow you could apply a lightstyle that would be one way to dim it without reducing the radius. I doubt you can do it though.

Actually, it may be a mistake with the timer, or with how you're setting its brightness in code. Try creating an impulse that will reduce the light's brightness by 10 each time, so you can just tap a key to test its brightness reduction. That way you can narrow it down to the timer or brightness code, to see which is the problem.
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.
Wazat
 
Posts: 771
Joined: Fri Oct 15, 2004 9:50 pm
Location: Middle 'o the desert, USA

Postby r00k » Thu Nov 13, 2008 5:35 am

Maybe you can yell obscenities at the tourch and it will coward in fright :P
ya well that didnt work with my acne either! :(
r00k
 
Posts: 1110
Joined: Sat Nov 13, 2004 10:39 pm

Postby Chris » Thu Nov 13, 2008 8:14 pm

grow up.
Chris
 
Posts: 79
Joined: Sat Aug 05, 2006 5:31 am


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest