Inside3D!
     

countdown in the center of the screen

 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming
View previous topic :: View next topic  
Author Message
Batman!]ZFA[



Joined: 20 Nov 2008
Posts: 32
Location: Pennsylvania

PostPosted: Thu May 14, 2009 1:33 pm    Post subject: countdown in the center of the screen Reply with quote

Anyone understand how this works?

Quote:
Okay I was looking through some old source code and came across this. It prints countdown in the center of the screen to everybody on the server.

My question is how does this work? How do you get the word countdown from these numbers.

WriteShort (MSG_ALL, 49930); // \nC
WriteShort (MSG_ALL, 62959); // ou how is this the letters o and u ??
WriteShort (MSG_ALL, 62702); // nt
WriteShort (MSG_ALL, 61412); // do
WriteShort (MSG_ALL, 61175); // wn

Does anybody have an idea of how this works?
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Lardarse



Joined: 05 Nov 2005
Posts: 243
Location: Bristol, UK

PostPosted: Thu May 14, 2009 4:34 pm    Post subject: Reply with quote

Aaaaah... WriteByte() abuse.

Short version: It's doing a certerprint 2 characters at a time.

Long version: Somewhere preceeding that, is a line that probably says WriteByte(MSG_ALL, SVC_CENTERPRINT); This tells it that there is a centerprint being sent to all clients.

Technical note: The centerprint() builtin only sends to one client usually, so it's already doing for centerprint() what bprint() is for sprint()

When doing this, there are things to note. Firstly, the centerprint message will only end with a null byte (sometimes referred to as \0), so that will have to be sent at some point. Secondly, WriteString() will send any string followed by a null (for reasons I won't go into, strings have to have a null at the end). This means that if you need to send multiple strings, you can only use WriteString() for the last one.

This isn't an issue with centerprint(), because you can use upto 7 strings with the builtin, either by creating multiple definitions each with a different number pf strings, or by using the varargs feature of FrikQCC or FTEQCC. But as mentioned perviously, there are other reasons why we can't use the builtin.

The main reason for needing WriteByte() abuse, though, is that because strings are actually handled as pointers, and you generally only get one temporary string, you can't print two numbers in the same centerprint. There are workarounds to this issue that are easier to use, but they involve changes to the engine code, which is not easily possible to guarantee.

Which brings us to the part that you quoted. WriteShort() is being used instead of WriteByte() to send two characters at a time, for a slight increase in speed, at a cost of readability. Converting 62959 to hexadecimal gives F5EF, which gives u and o. For reasons that I won't go to, large numbers are sent "big endian", meaning that this is sent as ou.

That's the basic idea of what it's doing.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming All times are GMT
Page 1 of 1

 
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