本文整理汇总了C++中ObjectPtr::AddComponent方法的典型用法代码示例。如果您正苦于以下问题:C++ ObjectPtr::AddComponent方法的具体用法?C++ ObjectPtr::AddComponent怎么用?C++ ObjectPtr::AddComponent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObjectPtr
的用法示例。
在下文中一共展示了ObjectPtr::AddComponent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char** argv)
{
typedef std::unique_ptr<Object> ObjectPtr;
std::vector<ObjectPtr> objects;
World theWorld;
std::shared_ptr<RenderSystem> render;
render.reset(new RenderSystem());
theWorld.AddSystem(render);
std::shared_ptr<System> input;
input.reset(new InputSystem());
theWorld.AddSystem(std::static_pointer_cast<System>(input));
render->LoadDataFile("data/data.txt");
//create an object
{
ObjectPtr myObject;
myObject.reset(new Object(&theWorld));
std::unique_ptr<Component> component;
component.reset(new LivingComponent(myObject.get()));
myObject->AddComponent(component);
std::unique_ptr<Component> component2;
component2.reset(new HealingEffect(myObject.get()));
Event buffness("set_property");
buffness.SetValueString("property", "duration");
buffness.SetValueString("value", "5");
component2->HandleEvent(buffness);
buffness.SetValueString("property", "quantity");
buffness.SetValueString("value", "20");
component2->HandleEvent(buffness);
myObject->AddComponent(component2);
std::unique_ptr<Component> component3;
component3.reset(new RenderComponent(myObject.get()));
myObject->AddComponent(component3);
objects.emplace_back(std::move(myObject));
}
//create an object 2
{
ObjectPtr myObject;
myObject.reset(new Object(&theWorld));
std::unique_ptr<Component> component;
component.reset(new LivingComponent(myObject.get()));
myObject->AddComponent(component);
std::unique_ptr<Component> component2;
component2.reset(new DamageReductionEffect(myObject.get()));
Event buffness("set_property");
buffness.SetValueString("property", "max_health");
buffness.SetValueString("value", "150");
component2->HandleEvent(buffness);
buffness.SetValueString("property", "health");
buffness.SetValueString("value", "150");
component2->HandleEvent(buffness);
myObject->AddComponent(component2);
objects.emplace_back(std::move(myObject));
}
Event debug("debug");
for(auto &obj : objects)
{
obj->HandleEvent(debug);
}
Event startFrame("event_start_frame");
for(uint32_t ii=0; ii<2000; ++ii)
{
printf("==========[ %5d ]==========\n", ii);
for(auto& object : objects)
{
Event damage("take_damage");
damage.SetValueInteger("damage", 20);
object->HandleEvent(startFrame);
object->HandleEvent(damage);
//object->HandleEvent(debug);
}
theWorld.Update(ii, 1.0/60.0);
//.........这里部分代码省略.........