📄 qc-lang.htm
字号:
<HTML><HEAD>
<TITLE>Quake-C Specificacions v1.0</TITLE>
<LINK REV="MADE" HREF="mailto:100625.2622@compuserve.com">
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<H1><FONT COLOR="#007F00"><A NAME="QC-LANG">The Quake-C Language</A></FONT></H1>
<p>This is a <b>very crude manual</b> of Quake-C. It is rather
<b>incomplete</b>.
<h2>Basic constructs of Quake-C</h2>
<h4>Comments</h4>
<ul>
<li> <b>//</b> followed by comments, until the next line.
<li> <b>/*</b> enclose a block comments </b>*/</b>
</ul>
Those comments are the same as in C++ (and many C languages).
<h4>Names</h4>
<p>Names of variable, fields, or functions have a <b>maximum of 64</b>
characters, must begin with A-Z,a-z, or _, and can continue with those
characters or 0-9.</p>
<h4>Definition of types</h4>
<p>You <b>cannot</b> define new types from the <a href="qc-types.htm#simpletype" target="content">existing</a>
ones. In particular, you cannot define new structure, new objects, and you cannot
affect a new name to a type (as does <b>typedef</b> in C).</p>
<p>These restrictions make Quake-C compare unfavourably even to <b>Basic</b>, and
sure it's about time the id software guys hired someone that already wrote a
compiler.</p>
<h4>Definition of variables</h4>
<p>
<pre>
<a href="qc-types.htm#simpletype" target="content">type</a> <i>variable1</i>, <i>variable2</i>;
</pre>
where <b>type</b> is one of the pre-defined
<a href="qc-types.htm#simpletype" target="content">simple types</a>.</p>
<p>
You can also affect default values to variables, for instance:
<pre>
<a href="qc-types.htm#simpletype" target="content">type</a> <i>variable1</i> = <i>value</i>;
</pre>
</p>
<p><b>Scoping of variables:</b> There are two levels of scoping.
By default all variables are global: they can be accessed by any functions,
and they are shared by all the functions (and all the clients of a given
network server, of course).
</p>
<p>But inside the functions, using the keyword <b>local</b> just before the
declaration of a variable, you can make this variable visible only the
the function itself (i.e. it will be allocated on the stack).
</p>
<p>Note that parameters of a functions are treated like local variables,
they are only visible to the function, but they can be modified.
</p>
<h4>Definitions of constants</h4>
<p>Any global variable that is initialised by setting a value to it is
actually assumed to be a constant.</p>
<p>Since a constant is in fact represented by immediate values, you should
<b>NEVER</b> attempt to modify a constant by giving it anothe value.
Otherwise the program might not function correctly.
</p>
<p>The constants are not saved to game files. Only regular variables are.
</p>
<h4>Definitions of functions</h4>
<p>
The general structure of a function definition is:
<pre>
<a href="qc-types.htm#simpletype" target="content">type</a> <b>(</b><a href="qc-types.htm#simpletype" target="content">type</a> <i>param1</i>, <a href="qc-types.htm#simpletype" target="content">type</a><i>param2</i>, ... <b>)</b> <i>function</i> =
{
<i>... code ...</i>
}<b>;</b>
</pre>
Don't forget the <b>;</b> after the brackets.
</p>
<p>Here are some examples:
<pre>
void() think = {...}<b>;</b>
entity() FindTarget = {...}<b>;</b>
void(vector destination, float speed, void() callback) SUB_CalcMove = {...}<b>;</b>
</pre>
</p>
<h4>Function declaration</h4>
<p>
If you want to use a function before defining it,
you must declare it, otherwise the Quake-C compiler
will not be able to use it.</p>
<p>
The general structure of a function declaration is:
<pre>
<a href="qc-types.htm#simpletype" target="content">type</a> <b>(</b><a href="qc-types.htm#simpletype" target="content">type</a> <i>param1</i>, <a href="qc-types.htm#simpletype" target="content">type</a><i>param2</i>, ... <b>)</b> <i>function</i><b>;</b>
</pre>
</p>
<h4>Definition of a frame function</h4>
<p>Frame functions (also called <i>States</i>) are special functions made for
convenience. They are meant to facilitate the definition of animation
frames, by making them more readable.</p>
<p>Here is an example:
<pre>
void() <i>framename</i> = [<i>$framenum</i>, <i>nextthink</i>] { <i>...code...</i>};
</pre>
It is strictly equivalent to:
<pre>
void() <i>framename</i> =
{
self.frame= <i>$framenum</i>; // the model frame to displayed
self.nextthink = time + 0.1; // next frame happens in 1/10 of second
self.think = <i>nextthink</i>; // the function to call at the next frame
<i>...code...</i>
};
</pre>
<hr>
<h2>Controling the flow of execution in Quake-C</h2>
<h4>Conditional construct</h4>
<pre>
<b>if</b>( <i>expression</i> )
{
<i>statements</i>
}
<b>else</b>
{
<i>statements</i>
}
</pre>
<h4>Loop construct</h4>
<pre>
<b>while</b>( <i>expression</i> )
{
<i>statements</i>
}
</pre>
or
<pre>
<b>do</b>
{
<i>statements</i>
}<b>while</b>( <i>expression</i> )
</pre>
<h4>Function calls</h4>
<p>Call a function:
<pre>
<i>function_name</i> ( <i>parameter1</i>, <i>parameter2</i>,... )
</pre>
The cannot be more than 8 parameters.
</p>
<p>Return a value:
<pre>
<b>return</b>( <i>expression</i> )
</pre>
</p>
<h4>Logical operations</h4>
<pre>
! // logical not
&& // logical and
|| // logical or
</pre>
<p>Take care that in <b>if()</b> conditional expressions containing two
or more logical clauses, all the clauses will be evaluated before the
condition test (like in Basic, and unlike C).
</p>
<p>That means that if one part of your condition is not always valid or defined,
you had better decompose your <b>if()</b> into two successive <b>if()</b>.
It should also make it faster.
</p>
<h4>Comparisons</h4>
<pre>
<= < >= >
== // equal, beware at the double <b>=</b> like in C.
!= // not equal, like in C.
</pre>
<h4>Operations on floats or integer</h4>
<p><pre>
* / - +
</pre>
Use parenthesis to remove ambiguities.</p>
<p>Those operators perform bitwise operations on integers:
<pre>
& // bitwise and
| // bitwise or
</pre>
These operators treat floats like integers, so they are usually
meant to be used with values made of bit masks.</p>
<hr>
</BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -