1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Created by texi2html 1.64 -->
<!--
Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author)
Karl Berry <karl@freefriends.org>
Olaf Bachmann <obachman@mathematik.uni-kl.de>
and many others.
Maintained by: Olaf Bachmann <obachman@mathematik.uni-kl.de>
Send bugs and suggestions to <texi2html@mathematik.uni-kl.de>
-->
<HTML>
<HEAD>
<TITLE>Crystal Space: map2cs.cfg Game-Specific Data</TITLE>
<META NAME="description" CONTENT="Crystal Space: map2cs.cfg Game-Specific Data">
<META NAME="keywords" CONTENT="Crystal Space: map2cs.cfg Game-Specific Data">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META NAME="Generator" CONTENT="texi2html 1.64">
</HEAD>
<BODY LANG="" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000">
<A NAME="SEC150"></A>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_66.html#SEC149"> < </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_68.html#SEC154"> > </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_55.html#SEC136"> << </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_63.html#SEC144"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_68.html#SEC154"> >> </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="index.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_285.html#SEC711">Index</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<HR SIZE=1>
<H3> 4.3.4 Game-Specific Data </H3>
<!--docid::SEC150::-->
<P>
This section describes how to access game-specific data from the Crytal Space
engine.
</P><P>
<A NAME="SEC151"></A>
<H4> Support in the Crystal Space "map format" </H4>
<!--docid::SEC151::-->
<P>
To support game-specific data, the Crystal Space map format has been
extended, thus allowing you to embed the required data directly in the map
file.
</P><P>
You can add key / value pairs to the map file itself; both to <EM>things</EM>
and <EM>sectors</EM>. To do this, just add `<SAMP>KEY("<VAR>keyname</VAR>",
"<VAR>keyvalue</VAR>")</SAMP>' to the appropriate sections. You can use any number of
keys. Because not all game-specific information can be bound to actual
geometry, (like `<SAMP>info_deathmatchstart</SAMP>', for example) there is also an
element called `<SAMP>NODE</SAMP>'.
</P><P>
A node looks like this:
</P><P>
<TABLE><tr><td> </td><td class=example><pre>NODE 'nodename' (
POSITION(x,y,z)
KEY("keyname1", "keyvalue1")
KEY("keyname2", "keyvalue2")
KEY("keyname3", "keyvalue3")
)
</pre></td></tr></table></P><P>
<A NAME="SEC152"></A>
<H4> How Does `<TT>map2cs</TT>' Support Game-Specific Data? </H4>
<!--docid::SEC152::-->
<P>
`<TT>map2cs</TT>' takes all key / value pairs found in the original map and
attaches them to the appropriate Crystal Space object. So if you have a brush
based entity, `<TT>map2cs</TT>' will store the data with the "thing" that is
generated from the entity. (Every entity corresponds to exactly one
"thing". If there are several sectors, the entity will be split and the
appropriate "things" all get the same data.)
</P><P>
If you have a point based entity (lights for example), `<TT>map2cs</TT>' will
generate a node in the appropriate sector, and store all data there.
</P><P>
If you have a manual sector, all data stored with the defining brush gets
stored in the sector.
</P><P>
For informational purposes, `<TT>map2cs</TT>' stores the scaling factor in the
Crystal Space world. (Because otherwise a game could not interpret
positions.)
</P><P>
<A NAME="SEC153"></A>
<H4> How Does Crystal Space Support Game-Specific Data? </H4>
<!--docid::SEC153::-->
<P>
`<SAMP>csLoader</SAMP>' generates an instance of `<SAMP>csKeyValuePair</SAMP>' for every
<EM>key</EM> found in the map file and attaches it to the appropriate Crystal
Space object by calling <CODE>ObjAdd()</CODE>. Each nodes generates an instance of
`<SAMP>csMapNode</SAMP>', and this is added to the sector with <CODE>ObjAdd()</CODE> as
well.
</P><P>
To make access to game-specific data simpler, there are some convenience
classes and some convenience functions.
</P><P>
To get the value of a game-specific key you can call:
</P><P>
<TABLE><tr><td> </td><td class=example><pre>csKeyValuePair::GetValue(csObject* pObject, char const* key);
</pre></td></tr></table></P><P>
For example:
</P><P>
<TABLE><tr><td> </td><td class=example><pre>csSector* pSector = GetCurrentSector();
char const* gravitystr =
csKeyValuePair::GetValue(pSector, "gravity");
int gravity = atoi(gravitystr);
</pre></td></tr></table></P><P>
Please note that these operations are pretty expensive, so you should
<EM>not</EM> invoke them every frame. For frequently needed data, you should
read the values once, and store them in some game-specific data fields. (But
it is still okay, to read the values once in a while; for example reading a
message to be printed, when the user tries to open a locked door without
having first unlocked it.)
</P><P>
To get a specific node you can call:
</P><P>
<TABLE><tr><td> </td><td class=example><pre>csMapNode::GetNode(csSector* pSector, char const* name,
char const* classname=NULL);
</pre></td></tr></table></P><P>
For example:
</P><P>
<TABLE><tr><td> </td><td class=example><pre>csSector* pSector = GetCurrentSector();
csMapNode* pNode = csMapNode::GetNode(
pSector, "central", "cs_dynlight");
csVector3 pos = pNode->GetPosition();
CreateDynLight(<small>...</small>);
</pre></td></tr></table></P><P>
A more frequent case for nodes will be to iterate over all nodes in a sector
(for example to place monsters or weapons).
</P><P>
For example:
</P><P>
<TABLE><tr><td> </td><td class=example><pre>csSector* pSector = GetCurrentSector();
csNodeIterator iter(pSector,"cs_medikit");
for ( ; !iter.IsFinished(); iter.Next())
{
csMapNode* pNode = iter.GetNode();
csVector3 pos = pNode->GetPosition();
CreateMedikit(pos);
}
</pre></td></tr></table><A NAME="mdl2spr"></A>
<HR SIZE=1>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_66.html#SEC149"> < </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_68.html#SEC154"> > </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_55.html#SEC136"> << </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_63.html#SEC144"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_68.html#SEC154"> >> </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="index.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_285.html#SEC711">Index</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<BR>
<FONT SIZE="-1">
This document was generated
using <A HREF="http://www.mathematik.uni-kl.de/~obachman/Texi2html
"><I>texi2html</I></A>
</BODY>
</HTML>
|