/*
=================================================================================
This file is part of Cafu, the open-source game engine and graphics engine
for multiplayer, cross-platform, real-time 3D action.
Copyright (C) 2002-2014 Carsten Fuchs Software.
Cafu 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 3 of the License, or (at your option) any later version.
Cafu 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 Cafu. If not, see .
For support and more information about Cafu, visit us at .
=================================================================================
*/
#include "CompTeam.hpp"
#include "AllComponents.hpp"
#include "Entity.hpp"
#include "String.hpp"
extern "C"
{
#include
#include
#include
}
#if defined(_WIN32) && defined(_MSC_VER)
// Turn off warning C4355: 'this' : used in base member initializer list.
#pragma warning(disable:4355)
#endif
using namespace cf::GameSys;
ComponentTeamT::ComponentTeamT()
: ComponentBaseT(),
m_TeamNum("TeamNum", 4)
{
FillMemberVars();
}
ComponentTeamT::ComponentTeamT(const ComponentTeam& Comp)
: ComponentBaseT(Comp),
m_TeamNum(Comp.m_TeamNum)
{
FillMemberVars();
}
void ComponentTeamT::FillMemberVars()
{
GetMemberVars().Add(&m_TeamNum);
}
/*************************************/
/*** ComponentTeam::EntityTeamT ***/
/*************************************/
ComponentTeamT::EntityTeamT::EntityTeamT(const char* Name, const int Value, const char* Flags[], ComponentTeamT& CompTeam)
: TypeSys::VarT(Name, Value, Flags),
m_CompTeam(CompTeam)
{
}
// The compiler-written copy constructor would copy m_CompBasics from Var.m_CompBasics,
// but we must obviously use the reference to the proper parent instance instead.
ComponentTeamT::EntityTeamT::EntityTeamT(const EntityNameT& Var, ComponentTeamT& CompTeam)
: TypeSys::VarT(Var),
m_CompTeam(CompTeam)
{
}
// The deserialization of network messages on the client can cause a member variable
// of a component to be `Set()` very frequently, and often to the same value as before.
//
// Consequently, setting a variable to the same value must be dealt with as efficiently
// as possible (for performance), and free of unwanted side effects (for correctness).
void ComponentTeamT::EntityTeamT::Set(const int v)
{
// Make sure that m_CompTeam actually refers to the ComponentTeam instance that contains us!
assert(this == &m_CompTeam.m_TeamNum);
// No change? Then skip re-establishing that the name is valid.
// Note that this is deliberately tricked in the EntityT::AddChild() methods...
if (Get() == v) return;
const int NewTeam = v;
TypeSys::VarT::Set(NewTeam);
}
/************************/
/*** ComponentTeamT ***/
/************************/
const char* ComponentTeamT::DocClass =
"This component adds a team number to the entity.";
const cf::TypeSys::VarsDocT ComponentTeamT::DocVars[] =
{
{ "TeamNum", "The Team Number of the entity" },
{ NULL, NULL }
};
ComponentTeamT:ComponentTeamT()
: ComponentBaseT(),
m_TeamNum("TeamNumber", "Entity", NULL, *this)
{
GetMemberVars().Add(&m_TeamNum;
}
ComponentTeamT::ComponentTeamT(const ComponentTeamT& Comp)
: ComponentBaseT(Comp),
m_TeamNum(Comp.m_TeamNum *this)
{
GetMemberVars().Add(&m_TeamNum);
}
ComponentTeamT* ComponentTeamT:Clone() const
{
return new ComponentTeamT(*this);
}
unsigned int ComponentTeamT::GetTeamNumber(lua_State* LuaState)
{
lua_pushinteger(LuaState, m_TeamNum);
return 1;
}
int ComponentTeamT::SetTeamNumber(lua_State* LuaState)
{
if (lua_isnumber(LuaState, 4))
{
comp->SetTeamNum(lua_integer(LuaState, 4))
}
}
static const cf::TypeSys::MethsDocT META_toString =
{
"__tostring",
"This method returns a readable string representation of this object.",
"string", "()"
};
int ComponentTeamT::toString(lua_State* LuaState)
{
// ScriptBinderT Binder(LuaState);
// IntrusivePtrT Comp = Binder.GetCheckedObjectParam< IntrusivePtrT >(1);
lua_pushfstring(LuaState, "Team number component");
return 1;
}
/***********************************/
/*** TypeSys-related definitions ***/
/***********************************/
void* ComponentTeamT::CreateInstance(const cf::TypeSys::CreateParamsT& Params)
{
return new ComponentTeamT();
}
const luaL_Reg ComponentTeamT::MethodsList[] =
{
{ "GetTeamNumber", GetTeamNumber },
{ "__tostring", toString },
{ NULL, NULL }
};
const cf::TypeSys::MethsDocT ComponentTeamT::DocMethods[] =
{
META_toString,
{ NULL, NULL, NULL, NULL }
};
const cf::TypeSys::TypeInfoT ComponentTeamT:TypeInfo(GetComponentTIM(), "GameSys::ComponentTeamT", "GameSys::ComponentBaseT", ComponentTeamT::CreateInstance, MethodsList, DocClass, DocMethods, DocVars);