Jump to content

Home

Open Slots in the playerstate_t


razorace

Recommended Posts

Posted

Starting this thread to collect information on what varibles in the playerstate_t are open. This is critical since the playerstate_t (gentity_t->ps) is the best way to transfer data to the clients.

 

Slots that ARE Transmitted to the Clients:

 

ints:

 

7 in ps->stats

 

Definitions:

Search for "statIndex_t" in bg_public.c

 

1 in ps->persistant

 

Definitions:

Search for "persEnum_t" in bg_public.c

 

 

Flags/Buttons:

 

5 in ps->eFlags

 

Definitions:

Search for "#define EF_DEAD" in bg_public.c

 

 

 

Slots that AREN'T Transmitted to the Clients:

 

ints:

 

1 in fullAnimExecute

 

 

 

Special thanks to Code for providing information on this.

Posted

ASk stole mine :)

 

Also, some of the EF_FLAGS aren't used (at least 4, if i remember right).

 

Also, any free int == 16 new flags. Bitwise operations are a beautiful thing. :)

Posted

You know, after thinking about the IEEE 754 float, I just had an idea: if you can change a 32 bit word into a float, then surely you could change the float back into a word?

 

What I'm trying to say is that if you have an array of 20 floats, you could have up to 640 flags. Maybe I'm going crazy...

Posted

Well, float bits aren't stored in the same manner as ints are, so you can't use integer bitwise operators on them directly.

But i think you could cast the floats as WORDs or int to use them as Commodus suggested.

Posted

Well, it's not complicated. Just create a float[20] array inside the gentity_s and then just refer to that new array instead of the array in the playerstate for all the references.

  • 2 weeks later...
  • 3 weeks later...
Posted

Shazbot! looks like a bunch of the "open" slots we have discussed aren't transmitted over the network. Heck, 75% of the structure doesn't from my new reading of the playerstate structure. :(

 

Meaning, we need a system to convert a float into a int (and back) to be able to send float data over the network. Anyone got any ideas?

Posted

The whole playerstate is transmitted only for each individual client, received as a snapshot ("cg.snap" on the client's end).

 

But only a small number of variables from each client's playerstate is sent to each player.

I don't know if any of those variables are open, and many of them are used for multiple things within the clientside code (often not coinciding with the displayed name).

Posted

int IeeeToWord(float number) {
//first of all: get the sign.
int sign;
float fractional;
int exponent, wholeno, finalword;
if (number > 0.0f) {
	sign = 0;
}
else if (number < 0.0f) {
	sign = 1;
}
else {
	printf("number is zero!\n");
}

fractional = fabs(number);

if (((fractional * power(2, 126)) < 1.0f) && ((fractional * power(2, 126)) > 0.0f)) {
	exponent = 0;
	fractional *= power(2, 126);
}
else if (number > 0) {
	while (fractional > 2.0f) {
		fractional /= 2;
		exponent++;
	}
	exponent += 127;
	fractional -= 1.0f;
}
else if (number < 0) {
	while (fractional < 0.0f) {
		fractional *= 2;
		exponent--;
	}
	exponent += 127;
}
else {
	printf("number is zero! yet again! \n");
}

fractional *= power(2, 23);
wholeno = fractional;
finalword = (sign << 31) | (exponent << 23) | wholeno;

return finalword;

}

 

Does this come any close to solving your problem?

Posted

float fabs(float number) {
if (number > 0) {
	return number;
}
else if (number < 0) {
	return number * -1;
}
else {
	return number;
}
}

float power (int x, int y) {
int i;
int n;
float result = 1.0f;
float placeholder;
if (!y) {
	return 0;
}
else if (y == 1) {
	return x;
}
else if (y > 1) {
	for (i = 1; i <= y; i++) {
		result *= x;
	}
}
else if (y < 0) {
	n = -y;
	for (i = 1; i <= n; i++) {
		result *= x;
	}
	placeholder = result;
	result = 1 / placeholder;
}
else {
	printf("something went wrong. oops \n");
}
return result;
}

int main() {
int word;
int sign;
int exponent;
int presign;
double fractional;
float number;
float powertest;
int tobeginwith;

powertest = power(2,-23);
printf("powertest is %.20f \n", powertest);

word = 25; // 01111111111100000000000000000000
presign = word >> 31;

//First get the sign
if (presign) {
sign = -1;
}
else {
	sign = 1;
}

// There is another way, of course - just do -1 to the power of the sign bit

//Now get the exponent

exponent = word & 2139095040;
   exponent = exponent >> 23;
// kills off the 23 fractional bits, then it switches off the sign bit
printf("exponent is %d \n", exponent);

//Now get fractional part

fractional = (word & 8388607) / power(2, 23);
printf("word & 8388607 is %d \n", word & 8388607);
printf("fractional is %f \n", fractional);

//The next bit checks out the fractional and exponent parts.

if (fractional) {
	if (exponent < 255 && exponent > 0) {
		number = sign * (power(2, (exponent - 127))) * (1.0f + fractional);
		printf("number is %8.20f \n", number);
		tobeginwith = IeeeToWord(number);
		printf("to begin with we had %d\n", tobeginwith);
		return 0;
	}
	else if (exponent == 255) {
		//CHECK - if exponent is completely full and fractional is non-zero 
		//then the float is NaN (Not a Number)
		printf("Word is NaN! \n");
		return 0;
	}
	else {
		number = sign * power(2, -126) * fractional;
		printf("number is %5.15f \n", number);
		tobeginwith = IeeeToWord(number);
		printf("to begin with we had %d\n", tobeginwith);

	}
}
else {
	if (!exponent) {
		number = 0;
	}
	if (exponent == 255) {
		//CHECK - if exponent is completely full then number = infinity * sign 
		//(so possible values are +infinity or -infinity)
		printf("Word is infinite!\n");
		return 0;
	}
}

return 0;
}

 

I wrote this for wudan so you'll have to adapt it slightly...

Posted

great job Commodus. Looks good but has it been tested?

 

Also, how do you want to be credited for this work? I'm definately going to be using it. :D

Posted

Well if it doesn't work, then... make it work.

 

It should work though, I checked it ages ago (it was because of the floats and this thread that i made it in the first place). The only problem I can foresee is that numbers might lose accuracy and therefore important bits might be lost (which could be devastating).

 

As for why Neo needs it, well wudan's compiler has problems reading numbers as floats so he needed something to read it.

Posted

Perhaps everyone knows where we're determining what variables get transfered and what do not, but it's from the function in bg_misc.c ~line2250:

 

BG_PlayerStateToEntityState()

 

You can see what weird uses they made for variables in there (i.e. bolt2 == dualBlade, clientside...in some areas).

There's also another function responsible for the inverse, bringing the entity state back to the ps.

Posted

Im no expert programmer, but shouldn't:

Originally posted by Commodus

float fabs(float number) {
if (number > 0) {
	return number;
}
else if (number < 0) {
	return number * -1;
}
else {
	return number;
}
}

be:

float fabs(float number) {
if (number < 0) {
	return number * -1;
}
else {
	return number;
}
}

:D

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...