2010-01-09 20:20:14 +01:00
|
|
|
/* Copyright (C) 2010 Wildfire Games.
|
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
|
|
#include "simulation2/system/Component.h"
|
|
|
|
#include "ICmpTest.h"
|
|
|
|
|
|
|
|
#include "simulation2/scripting/ScriptComponent.h"
|
|
|
|
#include "simulation2/MessageTypes.h"
|
|
|
|
|
|
|
|
class CCmpTest1A : public ICmpTest1
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static void ClassInit(CComponentManager& componentManager)
|
|
|
|
{
|
2010-01-22 21:03:14 +01:00
|
|
|
componentManager.SubscribeToMessageType(MT_TurnStart);
|
|
|
|
componentManager.SubscribeToMessageType(MT_Interpolate);
|
2010-01-09 20:20:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DEFAULT_COMPONENT_ALLOCATOR(Test1A)
|
|
|
|
|
|
|
|
int32_t m_x;
|
|
|
|
|
2010-04-14 19:22:32 +02:00
|
|
|
static std::string GetSchema()
|
|
|
|
{
|
2010-04-23 18:09:03 +02:00
|
|
|
return "<a:component type='test'/><ref name='anything'/>";
|
2010-04-14 19:22:32 +02:00
|
|
|
}
|
|
|
|
|
2010-01-09 20:20:14 +01:00
|
|
|
virtual void Init(const CSimContext&, const CParamNode& paramNode)
|
|
|
|
{
|
2010-02-03 00:01:17 +01:00
|
|
|
if (paramNode.GetChild("x").IsOk())
|
|
|
|
m_x = paramNode.GetChild("x").ToInt();
|
2010-01-09 20:20:14 +01:00
|
|
|
else
|
|
|
|
m_x = 11000;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Deinit(const CSimContext&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Serialize(ISerializer& serialize)
|
|
|
|
{
|
|
|
|
serialize.NumberI32_Unbounded("x", m_x);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Deserialize(const CSimContext& UNUSED(context), const CParamNode& UNUSED(paramNode), IDeserializer& deserialize)
|
|
|
|
{
|
2010-09-17 19:53:26 +02:00
|
|
|
deserialize.NumberI32_Unbounded("x", m_x);
|
2010-01-09 20:20:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual int GetX()
|
|
|
|
{
|
|
|
|
return m_x;
|
|
|
|
}
|
|
|
|
|
2010-01-22 21:03:14 +01:00
|
|
|
virtual void HandleMessage(const CSimContext&, const CMessage& msg, bool UNUSED(global))
|
2010-01-09 20:20:14 +01:00
|
|
|
{
|
|
|
|
switch (msg.GetType())
|
|
|
|
{
|
|
|
|
case MT_TurnStart:
|
|
|
|
m_x += 1;
|
|
|
|
break;
|
2010-01-22 21:03:14 +01:00
|
|
|
case MT_Interpolate:
|
|
|
|
m_x += 2;
|
|
|
|
break;
|
2010-01-09 20:20:14 +01:00
|
|
|
default:
|
|
|
|
m_x = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
REGISTER_COMPONENT_TYPE(Test1A)
|
|
|
|
|
|
|
|
class CCmpTest1B : public ICmpTest1
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static void ClassInit(CComponentManager& componentManager)
|
|
|
|
{
|
2010-01-22 21:03:14 +01:00
|
|
|
componentManager.SubscribeToMessageType(MT_Update);
|
|
|
|
componentManager.SubscribeGloballyToMessageType(MT_Interpolate);
|
2010-01-09 20:20:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DEFAULT_COMPONENT_ALLOCATOR(Test1B)
|
|
|
|
|
|
|
|
int32_t m_x;
|
|
|
|
|
2010-04-23 18:09:03 +02:00
|
|
|
static std::string GetSchema()
|
|
|
|
{
|
|
|
|
return "<a:component type='test'/><empty/>";
|
|
|
|
}
|
|
|
|
|
2010-01-09 20:20:14 +01:00
|
|
|
virtual void Init(const CSimContext&, const CParamNode&)
|
|
|
|
{
|
|
|
|
m_x = 12000;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Deinit(const CSimContext&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Serialize(ISerializer& serialize)
|
|
|
|
{
|
|
|
|
serialize.NumberI32_Unbounded("x", m_x);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Deserialize(const CSimContext& UNUSED(context), const CParamNode& UNUSED(paramNode), IDeserializer& deserialize)
|
|
|
|
{
|
2010-09-17 19:53:26 +02:00
|
|
|
deserialize.NumberI32_Unbounded("x", m_x);
|
2010-01-09 20:20:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual int GetX()
|
|
|
|
{
|
|
|
|
return m_x;
|
|
|
|
}
|
|
|
|
|
2010-01-22 21:03:14 +01:00
|
|
|
virtual void HandleMessage(const CSimContext&, const CMessage& msg, bool UNUSED(global))
|
2010-01-09 20:20:14 +01:00
|
|
|
{
|
|
|
|
switch (msg.GetType())
|
|
|
|
{
|
|
|
|
case MT_Update:
|
|
|
|
m_x += 10;
|
|
|
|
break;
|
2010-01-22 21:03:14 +01:00
|
|
|
case MT_Interpolate:
|
|
|
|
m_x += 20;
|
|
|
|
break;
|
2010-01-09 20:20:14 +01:00
|
|
|
default:
|
|
|
|
m_x = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
REGISTER_COMPONENT_TYPE(Test1B)
|
|
|
|
|
|
|
|
class CCmpTest2A : public ICmpTest2
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static void ClassInit(CComponentManager& componentManager)
|
|
|
|
{
|
2010-01-22 21:03:14 +01:00
|
|
|
componentManager.SubscribeToMessageType(MT_TurnStart);
|
|
|
|
componentManager.SubscribeToMessageType(MT_Update);
|
2010-01-09 20:20:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DEFAULT_COMPONENT_ALLOCATOR(Test2A)
|
|
|
|
|
|
|
|
int32_t m_x;
|
|
|
|
|
2010-04-23 18:09:03 +02:00
|
|
|
static std::string GetSchema()
|
|
|
|
{
|
|
|
|
return "<a:component type='test'/><empty/>";
|
|
|
|
}
|
|
|
|
|
2010-01-09 20:20:14 +01:00
|
|
|
virtual void Init(const CSimContext&, const CParamNode&)
|
|
|
|
{
|
|
|
|
m_x = 21000;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Deinit(const CSimContext&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Serialize(ISerializer& serialize)
|
|
|
|
{
|
|
|
|
serialize.NumberI32_Unbounded("x", m_x);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Deserialize(const CSimContext& UNUSED(context), const CParamNode& UNUSED(paramNode), IDeserializer& deserialize)
|
|
|
|
{
|
2010-09-17 19:53:26 +02:00
|
|
|
deserialize.NumberI32_Unbounded("x", m_x);
|
2010-01-09 20:20:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual int GetX()
|
|
|
|
{
|
|
|
|
return m_x;
|
|
|
|
}
|
|
|
|
|
2010-01-22 21:03:14 +01:00
|
|
|
virtual void HandleMessage(const CSimContext&, const CMessage& msg, bool UNUSED(global))
|
2010-01-09 20:20:14 +01:00
|
|
|
{
|
|
|
|
switch (msg.GetType())
|
|
|
|
{
|
|
|
|
case MT_TurnStart:
|
|
|
|
m_x += 50;
|
|
|
|
break;
|
|
|
|
case MT_Update:
|
|
|
|
m_x += static_cast<const CMessageUpdate&> (msg).turnLength.ToInt_RoundToZero();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
m_x = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
REGISTER_COMPONENT_TYPE(Test2A)
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class CCmpTest1Scripted : public ICmpTest1
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DEFAULT_SCRIPT_WRAPPER(Test1Scripted)
|
|
|
|
|
|
|
|
virtual int GetX()
|
|
|
|
{
|
|
|
|
return m_Script.Call<int> ("GetX");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
REGISTER_COMPONENT_SCRIPT_WRAPPER(Test1Scripted)
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class CCmpTest2Scripted : public ICmpTest2
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DEFAULT_SCRIPT_WRAPPER(Test2Scripted)
|
|
|
|
|
|
|
|
virtual int GetX()
|
|
|
|
{
|
|
|
|
return m_Script.Call<int> ("GetX");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
REGISTER_COMPONENT_SCRIPT_WRAPPER(Test2Scripted)
|