⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qc-types.htm

📁 Quake 的 各 种 文 档 格 式 说 明
💻 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-TYPES">The Quake-C Basic Types</A></FONT></H1>


<h2><A NAME="simpletype">Simple Types</A></h2>

<h4>Type: <a name="void">void</a></h4>

An empty result, mostly used for definition of procedures (i.e. functions 
that return no result at all).

<h4>Type: <a name="float">float</a></h4>

<p>A floating point value.</p>
<p>Floats are also used to store booleans (TRUE, FALSE) or integer values
linke counters, or bit flags.</p>
<pre>
    Valid syntax: <b>12</b>  <b>1.6</b>   <b>0.5</b>   <b>-100</b>  
    Invalid syntax: <b>.5</b>
</pre>
</p>
<p>A parsing ambiguity is present with negative constants. "a-5" will be parsed 
as "a", then "-5", causing an error.  Separate the - from the digits with a 
space "a - 5" to get the proper behavior.
</p>

<h4>Type: <a name="vector">vector</a></h4>

<p>A vector, made of 3 <a href="qc-types.htm#float" target="content">float</a> coordinates.
<br>
Used to represent positions or directions in 3D space.
<br>
Valid syntax: <b>'0 0 0'</b>  or <b>'20.5 -10 0.00001'</b>
<br>
</p>
<p>Note the simple quotes around the vector. Do not use
double quotes, they are reserved for strings.</p>

<p>If you declare a vector <b>foobar</b>, then you can
access it's x, y and z fields with: <b>foobar_x</b>,
<b>foobar_y</b>,<b>foobar_z</b>.
</p>

<h4>Type: <a name="string">string</a></h4>

<p>Represents a character string.
<br>
Used to indicate file names, or messages to be broadcast to players.
<br>
Valid syntax: <b>"maps/jrwiz1.bsp"</b> or <b>"ouch!\n"</b>
<br>
Use <b>\n</b> for newline.
</p>


<h4>Type: <a name="entity">entity</a></h4>

<p>The reference of an entity in the game, like things, players, monsters.<br>
For instance, this is the type of the entities <a href="qc-glob.htm#self" target="content">self</a>
and <a href="qc-glob.htm#other" target="content">other</a>.
</p> 
<p>The entity type is a structured type, made of <a href="qc-types.htm#fieldtypes" target="content">fields</a>.<br>
A <a href="qc-enty.htm#dot_chain" target="content">description</a> of each field is available.
</p>

 
<hr>
<h2><A NAME="fieldtypes">Field types</A></h2>

<p>Countrary to the other types, the <a href="qc-types.htm#entity" target="content">entity</a> type 
is a reference to an instance of a structured object, that contains
many informations of totally different kinds.</p>

<p>To access all these informations conveniently, they are stored as
fields of the entity object, and each field is given a name and a type,
that makes it distinct of the others.</p>

<p>Some of the fields do not store value, but instead they store the
function to be executed in certain conditions. They are called the
<b>methods</b> that can be aplied to the object.</p>

<p>If Quake-C was an object oriented programming language, those method
functions and would be distinguished from the other fields. And, above
all, you would be able to create new object types, with their own fields.</p>

<p>As Quake-C stands currently, <b>all the field definitions</b> are
definitions of entity fields. So anywhere in your code you could add
definition of new fields, and the compiler would interpret them
as an extension of the entity definition.</p>


<p>Here are all the possible definitions of entity fields, with their <a href="qc-types.htm#simpletype" target="content">types</a>:
<pre>
    <a name="dot_float">.float</a> <i>field_name</i>;
    <a name="dot_string">.string</a> <i>field_name</i>;
    <a name="dot_vector">.vector</a> <i>field_name</i>;
    <a name="dot_entity">.entity</a> <i>field_name</i>;
</pre>
</p>

<h4>Reserved field types (beware of the hack!)</h4>

<p>In the first file read by the Quake-C compiler, <b>defs.qc</b>,
there must be a definition for the entity fields, and world fields.
This definition is hard coded. You had better not touch it,
or you will have to recompile Quake itself.
<p>

<p>The globals are defined before the special definition
<b>void end_sys_globals;</b><br>
The entity fields are defined before the special
definition <b>void end_sys_fields;</b></p>

<p>It's not important if you don't understand the nonsense
above. It's an ugly hack. Just <b>don't modify defs.qc</b> 
before those two tags, and you won't be in trouble.</p>

<hr>

<h2>Compilation of Quake-C</h2>

<p>The language is strongly typed and there are no casts.</p>

<p>Source files are processed sequentially without dumping any 
state, so if a defs file is the first one processed, the 
definitions will be available to all other files.</p>

<p>Error recovery during compilation is minimal.  It will skip 
to the next global definition, so you will never see more 
than one error at a time in a given function.  All compilation
aborts after ten error messages.</p>

<p>Names can be defined multiple times until they are defined 
with an initialization, allowing functions to be prototyped 
before their definition.
<pre>
    // in headers
    void()	MyFunction;	        // the prototype
    // later
    void()	MyFunction =		// the initialization
    { dprint ("we're here\n"); };
</pre>
</p>


<h3>Beware of the Quake-C compiler</h3>

<p><i>Here are some remarks by Adnan Zafar (zafar@hal-pc.org)</i></p>

<p>The compiler only catches syntax and other language-style errors.  It will 
not warn you of things that generate run-time errors.. and definitely doesn't guarantee that things will
work the way you want.  It's been my experience that I have to compile and test
something 6 or 8 times; the first few times it doesn't work at all, and the last
few it doesn't work exactly right.  [...] I just don't want you to think
that all the code that compiles will have a good chance of working. In all
likelihood, it won't.
</p>
 

<hr>
<h2>Execution of Quake-C</h2>

<p>Code execution is initiated by C code in quake from two main places:  
the timed think routines for periodic control, and the touch function when 
two objects impact each other.
</p>
<p>Execution is also caused by a few uncommon events, like the 
addition of a new client to an existing server.
</p>	
<p>There is a runnaway counter that stops a program if 100000 
statements are executed, assuming it is in an infinite loop.
</p>
<p>It is acceptable to change the system set global variables.  
This is usually done to pose as another entity by changing 
self and calling a function.
</p>
<p>The interpretation is fairly efficient, but it is still over 
an order of magnitude slower than compiled C code.  All time 
consuming operations should be made into built in functions.
</p>
<p>A profile counter is kept for each function, and incremented 
for each interpreted instruction inside that function.  The 
"profile" console command in Quake will dump out the top 10 
functions, then clear all the counters.  The "profile all" 
command will dump sorted stats for every function that has 
been executed.
</p>





</BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -