Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ICmpFootprint.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2010 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "precompiled.h"
19 
20 #include "ICmpFootprint.h"
21 
23 
25 #include "maths/FixedVector3D.h"
26 
28 {
29  EShape shape;
30  entity_pos_t size0, size1, height;
31  GetShape(shape, size0, size1, height);
32 
33  JSContext* cx = GetSimContext().GetScriptInterface().GetContext();
34 
35  JSObject* obj = JS_NewObject(cx, NULL, NULL, NULL);
36  if (!obj)
37  return JSVAL_VOID;
38 
39  if (shape == CIRCLE)
40  {
41  jsval ptype = ScriptInterface::ToJSVal<std::string>(cx, "circle");
42  jsval pradius = ScriptInterface::ToJSVal(cx, size0);
43  jsval pheight = ScriptInterface::ToJSVal(cx, height);
44  JS_SetProperty(cx, obj, "type", &ptype);
45  JS_SetProperty(cx, obj, "radius", &pradius);
46  JS_SetProperty(cx, obj, "height", &pheight);
47  }
48  else
49  {
50  jsval ptype = ScriptInterface::ToJSVal<std::string>(cx, "square");
51  jsval pwidth = ScriptInterface::ToJSVal(cx, size0);
52  jsval pdepth = ScriptInterface::ToJSVal(cx, size1);
53  jsval pheight = ScriptInterface::ToJSVal(cx, height);
54  JS_SetProperty(cx, obj, "type", &ptype);
55  JS_SetProperty(cx, obj, "width", &pwidth);
56  JS_SetProperty(cx, obj, "depth", &pdepth);
57  JS_SetProperty(cx, obj, "height", &pheight);
58  }
59 
60  return OBJECT_TO_JSVAL(obj);
61 }
62 
63 BEGIN_INTERFACE_WRAPPER(Footprint)
64 DEFINE_INTERFACE_METHOD_1("PickSpawnPoint", CFixedVector3D, ICmpFootprint, PickSpawnPoint, entity_id_t)
65 DEFINE_INTERFACE_METHOD_0("GetShape", CScriptVal, ICmpFootprint, GetShape_wrapper)
66 END_INTERFACE_WRAPPER(Footprint)
A simple fixed-point number class.
Definition: Fixed.h:115
#define END_INTERFACE_WRAPPER(iname)
#define DEFINE_INTERFACE_METHOD_1(scriptname, rettype, classname, methodname, arg1)
A trivial wrapper around a jsval.
Definition: ScriptVal.h:29
CScriptVal GetShape_wrapper()
GetShape wrapper for script calls.
ScriptInterface & GetScriptInterface() const
Definition: SimContext.cpp:63
#define DEFINE_INTERFACE_METHOD_0(scriptname, rettype, classname, methodname)
static jsval ToJSVal(JSContext *cx, T const &val)
Convert a C++ type to a jsval.
const CSimContext & GetSimContext() const
Definition: IComponent.h:52
Footprints - an approximation of the entity&#39;s shape, used for collision detection and for rendering s...
Definition: ICmpFootprint.h:33
virtual void GetShape(EShape &shape, entity_pos_t &size0, entity_pos_t &size1, entity_pos_t &height)=0
Return the shape of this footprint.
#define BEGIN_INTERFACE_WRAPPER(iname)
u32 entity_id_t
Entity ID type.
Definition: Entity.h:24
JSContext * GetContext() const