#include "CDrawableEntity.h" #include "CEngine.h" #include "CTransformable.h" #include "CDrawable3D.h" #include "CDrawableModel.h" #include "CScenesManager.h" #include "U_ShortAPI.h" void CDrawableEntity::V_Init() { auto entity = GetEntity(); auto transformable = entity->Components.GetComponentTyped(); if(!transformable) { entity->Components.CreateComponent(); transformable = entity->Components.GetComponentTyped(); } Log::Instance() << "CDrawableEntity::V_Init()\n"; transformable->Transform.OnTransformChanged += [this](CTransformBase::CMeasurePack oldprs, CTransformBase* _this) { auto drawable3d = std::dynamic_pointer_cast(Drawable); //Log::Instance() << "transformable->Transform.OnTransformChanged\n"; if(drawable3d) { //Log::Instance() << "drawable3d->Transform.SetPRS(_this->GetPRS());\n"; drawable3d->Transform.SetPRS(_this->GetPRS()); } }; } void CDrawableEntity::FullPack(CBufferWrapper& packet) //let client to decide in what space to put this drawable { auto drmodel = dynamic_cast(Drawable.get()); packet.WriteLenString(drmodel->GetModel()->Name); //packet.Write(SpaceID); } void CDrawableEntity::FullUnpack(CBufferWrapper& packet) { std::string mdlName = packet.ReadLenString(); SetEntityDrawable(GetEntity(), mdlName + ".emdl"); //TODO good workaround with adding an extension. Try to avoid using it AddDrawableToSpace(Drawable, 0); //TODO find an actual space (or multiple) for drawable } LINK_ENTITY_COMPONENT_TO_CLASS(CDrawableEntity, drawable);