News | Forum | People | FAQ | Links | Search | Register | Log in
Coding Help
This is a counterpart to the "Mapping Help" thread. If you need help with QuakeC coding, or questions about how to do some engine modification, this is the place for you! We've got a few coders here on the forum and hopefully someone knows the answer.
First | Previous | Next | Last
 
Hmmmmm. I kinda suspected that. I guess I'm mis-understanding the for part. I can't help but think of it as an if.

The excercise which has gotten me confused is the following:

int i, j;
bool isprime;
for(i=1; i<100; i++){
isprime = true;
// see if the number is evenly divisible
for(j=2; j<= i/2; j++)
// if it is then it is not prime
if ((i%j) == 0) isprime = false;
if (isprime) cout << i << " is prime. \n";


It's the modulus test part, and my understanding of prime numbers which has gotten me confused.

I inserted this after the second last 'if':

cout << "i=" << i << ", j=" << j << " ";


This way it shows me what the two variables are. I don't understand why the test works. 
 
cout << "i=" << i << ", j=" << j << " ";

looks suspiciously like some of the stuff i've been learning about linux and input redirection... 
 
What exactly don't you understand?
The if (isprime)? If you test a variable without explictly writing eg isprime == 42 it will test if the variable is true (or not false or something like that). 
 
%

% is what i dont understand lol.

Why is 2%3 equal to 2 ?

Why is 45%89 equal to 45 ? 
 
Yeah - I Just Read That, Incidentally. 
The most useful bit of information I could find on that page was:

^ ISO/IEC 14882:2003 : Programming languages -- C++. 5.6.4: ISO, IEC. 2003. "the binary % operator yields the remainder from the division of the first expression by the second. .... If both operands are nonnegative then the remainder is nonnegative; if not, the sign of the remainder is implementation-defined".

The word "nonnegative" scares me a bit TBH. 
 
modulus is basically the remainder. like you do long division and stop before going into decimals.

so 2%3 is 2 because 2 can't fit into 3 at all, so you have 2 as the remained.
same with 45%89.

otoh, if you had 3%2, it's 1, because 2 fits into 3 once, and you have 1 left over. 
Necros 
I'm sure you meant to say: 3 can't fit into 2 at all, that's why 2 % 3 = 2. Look at this, Ricky:

0 % 3 = 0
1 % 3 = 1
2 % 3 = 2
3 % 3 = 0
4 % 3 = 1

etc.

Just try a few examples and you'll get a feel for what the modulo operator does. 
Thanks Necros & SleepwalkR 
I also figured he meant a three, but I was pretty cross-eyed already ;)

I think I'm starting to understand it. C++ is weird though, because sometimes you get a negative short. Which is weird. BUT I'm beginning to get my head round it. Which means I'm learning :D 
Sleep 
haha, apparently math doesn't fit at all into my head. :P 
Ricky 
You're probably messing up the types (using signed short instead of unsigned or something). 
Shoutouts To Awesome Lines Of QC Code #1 
A real gem from the walkmonster_start_go code I've never noticed before today:

self.ideal_yaw = self.angles * '0 1 0';


Why not just use self.angles_y? Because that wouldn't be vectorised and involve lots of awesome multiplication! 
Why Not Just Use Self.angles_y? 
...because then self.ideal_yaw_x and self.ideal_yaw_z may not be set to 0. 
 
ideal_yaw is a float though 
Yeah 
It's the dot product, so it returns the sum of all three components once you do the componentwise multiplication. Very handy some of the time, but a bit of a waste here. 
Rocket Trails 
What is it that gives rocket (and grenades) their flight trails? 
Model Flags 
There are flags you can set on models which select which (if any) effect that applies. If you open one with QMe it gives you a nice tickbox interface if you bring up the model properties box. 
Flags 
Thanks Preach 
Just To Clarify 
This is distinct from the QC .flags field - you can't change the particle effects from QC (other than having multiple models and switching between them). 
Flags 
Understood: I found the flag on the model immediately and was able to change them as required.

Is there any effect on performance if I suddenly add lots of these 'particle' effects? 
 
i don't think you'll feel it on an engine with the original particles (or even fitz' circular ones) but DP and other engines with 'fancy' particles can start to chug. i know some players using DP found the lava splash effects in ne_ruins would just kill their framerate, for example but i wouldn't even notice it in quakespasm. 
 
I think older engines have a maximum number of particles they will show. 
 
even glquake had -particles though and i always used to use -particles 20000. these days, i use -200000, but i think modern engines don't even use that anymore? i just leave it because it's in a batch file. :P 
Five Particles 
A hell knight fires 5 projectiles with trails in a single attack. Launching 1 projectile with five trail should be within scope. 
I Forget... 
is:

val = random();
val = val + random();
val = val + random();
val = val + random();

the same as:

val = random() + random() + random() + random();

First | Previous | Next | Last
You must be logged in to post in this thread.
Website copyright © 2002-2024 John Fitzgibbons. All posts are copyright their respective authors.