Pyrogenesis
13997
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
source
simulation2
scripting
ScriptComponent.h
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
#ifndef INCLUDED_SCRIPTCOMPONENT
19
#define INCLUDED_SCRIPTCOMPONENT
20
21
#include "
simulation2/system/Component.h
"
22
23
#include "
ps/CLogger.h
"
24
25
#include <boost/preprocessor/repetition/enum_params.hpp>
26
#include <boost/preprocessor/repetition/enum_trailing_params.hpp>
27
#include <boost/preprocessor/repetition/enum_trailing_binary_params.hpp>
28
29
class
CSimContext
;
30
class
CParamNode
;
31
class
ISerializer
;
32
class
IDeserializer
;
33
34
class
CComponentTypeScript
35
{
36
public
:
37
CComponentTypeScript
(
ScriptInterface
& scriptInterface, jsval instance);
38
39
jsval
GetInstance
()
const
{
return
m_Instance
.
get
(); }
40
41
void
Init
(
const
CParamNode
& paramNode,
entity_id_t
ent);
42
void
Deinit
();
43
void
HandleMessage
(
const
CMessage
& msg,
bool
global);
44
45
void
Serialize
(
ISerializer
& serialize);
46
void
Deserialize
(
const
CParamNode
& paramNode,
IDeserializer
& deserialize,
entity_id_t
ent);
47
48
// Use Boost.PP to define:
49
// template<typename R> R Call(const char* funcname);
50
// template<typename R, typename T0> R Call(const char* funcname, const T0& a0);
51
// ...
52
// void CallVoid(const char* funcname);
53
// template<typename T0> void CallVoid(const char* funcname, const T0& a0);
54
// ...
55
#define OVERLOADS(z, i, data) \
56
template<typename R BOOST_PP_ENUM_TRAILING_PARAMS(i, typename T)> \
57
R Call(const char* funcname BOOST_PP_ENUM_TRAILING_BINARY_PARAMS(i, const T, &a)) \
58
{ \
59
R ret; \
60
if (m_ScriptInterface.CallFunction(m_Instance.get(), funcname BOOST_PP_ENUM_TRAILING_PARAMS(i, a), ret)) \
61
return ret; \
62
LOGERROR(L"Error calling component script function %hs", funcname); \
63
return R(); \
64
} \
65
BOOST_PP_IF(i, template<, ) BOOST_PP_ENUM_PARAMS(i, typename T) BOOST_PP_IF(i, >, ) \
66
void CallVoid(const char* funcname BOOST_PP_ENUM_TRAILING_BINARY_PARAMS(i, const T, &a)) \
67
{ \
68
if (m_ScriptInterface.CallFunctionVoid(m_Instance.get(), funcname BOOST_PP_ENUM_TRAILING_PARAMS(i, a))) \
69
return; \
70
LOGERROR(L"Error calling component script function %hs", funcname); \
71
}
72
BOOST_PP_REPEAT(
SCRIPT_INTERFACE_MAX_ARGS
,
OVERLOADS
, ~)
73
#undef OVERLOADS
74
75
private
:
76
ScriptInterface
&
m_ScriptInterface
;
77
CScriptValRooted
m_Instance
;
78
bool
m_HasCustomSerialize
;
79
bool
m_HasCustomDeserialize
;
80
bool
m_HasNullSerialize
;
81
82
NONCOPYABLE
(
CComponentTypeScript
);
83
};
84
85
#endif // INCLUDED_SCRIPTCOMPONENT
CParamNode
An entity initialisation parameter node.
Definition:
ParamNode.h:112
CComponentTypeScript::NONCOPYABLE
NONCOPYABLE(CComponentTypeScript)
ISerializer
Serialization interface; see serialization overview.
Definition:
ISerializer.h:120
CComponentTypeScript::CComponentTypeScript
CComponentTypeScript(ScriptInterface &scriptInterface, jsval instance)
Definition:
ScriptComponent.cpp:25
CComponentTypeScript::m_HasCustomSerialize
bool m_HasCustomSerialize
Definition:
ScriptComponent.h:78
SCRIPT_INTERFACE_MAX_ARGS
#define SCRIPT_INTERFACE_MAX_ARGS
Definition:
ScriptInterface.h:41
Component.h
CSimContext
Contains pointers to various 'global' objects that are needed by the simulation code, to allow easy access without using real (evil) global variables.
Definition:
SimContext.h:32
CComponentTypeScript::Serialize
void Serialize(ISerializer &serialize)
Definition:
ScriptComponent.cpp:63
CComponentTypeScript::Deinit
void Deinit()
Definition:
ScriptComponent.cpp:48
CComponentTypeScript::Deserialize
void Deserialize(const CParamNode ¶mNode, IDeserializer &deserialize, entity_id_t ent)
Definition:
ScriptComponent.cpp:84
CComponentTypeScript
Definition:
ScriptComponent.h:34
CComponentTypeScript::m_HasCustomDeserialize
bool m_HasCustomDeserialize
Definition:
ScriptComponent.h:79
OVERLOADS
#define OVERLOADS(z, i, data)
Definition:
ScriptComponent.h:55
CComponentTypeScript::m_HasNullSerialize
bool m_HasNullSerialize
Definition:
ScriptComponent.h:80
CComponentTypeScript::m_ScriptInterface
ScriptInterface & m_ScriptInterface
Definition:
ScriptComponent.h:76
CScriptValRooted::get
jsval get() const
Returns the current value (or JSVAL_VOID if uninitialised).
Definition:
ScriptVal.cpp:45
ScriptInterface
Abstraction around a SpiderMonkey JSContext.
Definition:
ScriptInterface.h:60
CComponentTypeScript::m_Instance
CScriptValRooted m_Instance
Definition:
ScriptComponent.h:77
CComponentTypeScript::GetInstance
jsval GetInstance() const
Definition:
ScriptComponent.h:39
entity_id_t
u32 entity_id_t
Entity ID type.
Definition:
Entity.h:24
CComponentTypeScript::HandleMessage
void HandleMessage(const CMessage &msg, bool global)
Definition:
ScriptComponent.cpp:53
CLogger.h
CComponentTypeScript::Init
void Init(const CParamNode ¶mNode, entity_id_t ent)
Definition:
ScriptComponent.cpp:41
IDeserializer
Deserialization interface; see serialization overview.
Definition:
IDeserializer.h:34
CMessage
Definition:
Message.h:24
CScriptValRooted
Definition:
ScriptVal.h:49
Generated on Mon Oct 14 2013 00:58:09 for Pyrogenesis by
1.8.5