本文整理汇总了C++中EntityManager::create方法的典型用法代码示例。如果您正苦于以下问题:C++ EntityManager::create方法的具体用法?C++ EntityManager::create怎么用?C++ EntityManager::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EntityManager
的用法示例。
在下文中一共展示了EntityManager::create方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createTestWorld
void createTestWorld() {
entities.create(
makeTeapot(netSystem.makeNetEntityId(), vec3(0, 0, 0),
vec3(0, 0, 0)));
entities.create(
makeTeapot(netSystem.makeNetEntityId(), vec3(-3, 0, 0),
vec3(0, 0, 0)));
entities.create(
makeTeapot(netSystem.makeNetEntityId(), vec3(3, 0, 0),
vec3(0, 0, 0)));
}
示例2: onPlayerInputWish
void onPlayerInputWish(ClientId clientId, PlayerInput const& playerInput) {
auto client = clients.get(clientId);
auto entity = client->entity;
if (entity) {
auto input = entity->component<PlayerInputComponent>();
auto physics = entity->component<PhysicsComponent>();
ASSERT(input);
ASSERT(physics);
input->onPlayerInput(playerInput);
if (playerInput.shoot) {
auto origin = physics->getPosition() +
physics->getOrientation() * 0.65f;
auto orientation =
vec3(playerInput.orientation.x, 0,
playerInput.orientation.y);
auto components =
makeProjectile(netSystem.makeNetEntityId(),
clientId,
origin,
orientation);
entities.create(std::move(components));
}
#ifdef USE_PREDICTION
vec3 newPosition = physics->getPosition();
sendEvent<PlayerPositionOrder>(client->peer, newPosition);
#endif
}
}
示例3: createArena
Entity* EntityFactory::createArena()
{
EntityManager* entityMgr = engine_->entityMgr_;
Entity* entity = entityMgr->create();
float arenaHalfX = 150.f;
float arenaHalfY = 75.f;
b2BodyDef bd;
bd.type = b2_staticBody;
b2Body* body = engine_->sysPhysics_->getWorld()->CreateBody(&bd);
b2EdgeShape shape;
b2FixtureDef sd;
sd.shape = &shape;
sd.density = 0;
sd.restitution = 0.4f;
sd.filter.categoryBits = ComPhysics::CollisionCategory::CATEG_Wall;
sd.filter.maskBits = ComPhysics::CollisionMask::MASK_Wall;
// Left vertical
shape.Set(b2Vec2(-arenaHalfX, -arenaHalfY), b2Vec2(-arenaHalfX, arenaHalfY));
body->CreateFixture(&sd);
// Right vertical
shape.Set(b2Vec2(arenaHalfX, -arenaHalfY), b2Vec2(arenaHalfX, arenaHalfY));
body->CreateFixture(&sd);
// Top horizontal
shape.Set(b2Vec2(-arenaHalfX, arenaHalfY), b2Vec2(arenaHalfX, arenaHalfY));
body->CreateFixture(&sd);
// Bottom horizontal
shape.Set(b2Vec2(-arenaHalfX, -arenaHalfY), b2Vec2(arenaHalfX, -arenaHalfY));
body->CreateFixture(&sd);
ComPhysics* comPhysics = entityMgr->assignComponent<ComPhysics>(entity);
comPhysics->setMainBody(body, entity);
Ogre::SceneManager* sceneMgr = engine_->sysGraphics_->getSceneManager();
//Ogre::ManualObject* manual = sceneMgr->createManualObject();
//manual->begin("white", Ogre::RenderOperation::OT_LINE_STRIP);
//manual->position(-arenaHalfX, -arenaHalfY, 0);
//manual->position(arenaHalfX, -arenaHalfY, 0);
//manual->position(arenaHalfX, arenaHalfY, 0);
//manual->position(-arenaHalfX, arenaHalfY, 0);
//manual->index(0);
//manual->index(1);
//manual->index(2);
//manual->index(3);
//manual->index(0);
//manual->end();
Ogre::Entity* meshEntity = sceneMgr->createEntity("ArenaPlane.mesh");
Ogre::SceneNode* node = engine_->sysGraphics_->getSceneRoot()->createChildSceneNode(
Ogre::Vector3(0, 0, 0));
ComGraphics* comGraphics = entityMgr->assignComponent<ComGraphics>(entity);
comGraphics->sceneNode_ = node;
comGraphics->attachMovableObject(meshEntity);
return entity;
}
示例4: createShip
Entity* EntityFactory::createShip(const ShipConfig& config)
{
EntityManager* entityMgr = engine_->entityMgr_;
Entity* entity = entityMgr->create();
float boxHalfX = 0.7f;
b2BodyDef bd;
bd.type = b2_dynamicBody;
bd.position.Set(config.posX_, config.posY_);
b2Body* body = engine_->sysPhysics_->getWorld()->CreateBody(&bd);
b2PolygonShape shape;
shape.SetAsBox(boxHalfX, boxHalfX);
b2FixtureDef sd;
sd.shape = &shape;
sd.density = 1.f;
sd.filter.categoryBits = config.collisionCateg_;
sd.filter.maskBits = config.collisionMask_;
body->CreateFixture(&sd);
ComPhysics* comPhysics = entityMgr->assignComponent<ComPhysics>(entity);
comPhysics->setMainBody(body, entity);
Ogre::SceneManager* sceneMgr = engine_->sysGraphics_->getSceneManager();
//Ogre::ManualObject* manual = sceneMgr->createManualObject();
//manual->begin("green", Ogre::RenderOperation::OT_LINE_STRIP);
//manual->position(-boxHalfX, -boxHalfX, 0);
//manual->position(boxHalfX, -boxHalfX, 0);
//manual->position(boxHalfX, boxHalfX, 0);
//manual->position(-boxHalfX, boxHalfX, 0);
//manual->position(-boxHalfX, -boxHalfX, 0);
//manual->end();
Ogre::Entity* meshEntity = sceneMgr->createEntity("Ship.mesh");
Ogre::SceneNode* node = engine_->sysGraphics_->getSceneRoot()->createChildSceneNode(
Ogre::Vector3(config.posX_, config.posY_, 0));
ComGraphics* comGraphics = entityMgr->assignComponent<ComGraphics>(entity);
comGraphics->sceneNode_ = node;
comGraphics->attachMovableObject(meshEntity);
if (config.hasAI_)
{
ComAI* comAI = entityMgr->assignComponent<ComAI>(entity);
comAI->entity_ = entity;
comAI->type_ = config.AIType_;
}
return entity;
}
示例5: createBeamGun
Entity* EntityFactory::createBeamGun(const BeamGunConfig& config)
{
EntityManager* entityMgr = engine_->entityMgr_;
Entity* entity = entityMgr->create();
float y = 0.1f;
b2BodyDef bd;
bd.type = b2_dynamicBody;
bd.position.Set(config.posX_, config.posY_);
b2Body* body = engine_->sysPhysics_->getWorld()->CreateBody(&bd);
b2PolygonShape shape;
b2Vec2 vertices[4];
vertices[0].Set(0, y);
vertices[1].Set(0, -y);
vertices[2].Set(config.beamRange_, -y);
vertices[3].Set(config.beamRange_, y);
shape.Set(vertices, 4);
b2FixtureDef sd;
sd.shape = &shape;
sd.density = 0;
sd.filter.categoryBits = ComPhysics::CATEG_PlayerBeam;
sd.filter.maskBits = ComPhysics::MASK_PlayerBeam;
body->CreateFixture(&sd);
ComPhysics* comPhysics = entityMgr->assignComponent<ComPhysics>(entity);
comPhysics->setMainBody(body, entity);
Ogre::SceneManager* sceneMgr = engine_->sysGraphics_->getSceneManager();
Ogre::ManualObject* manual = sceneMgr->createManualObject();
manual->begin("beam", Ogre::RenderOperation::OT_LINE_STRIP);
manual->position(0, y, 0);
manual->position(0, -y, 0);
manual->position(config.beamRange_, -y, 0);
manual->position(config.beamRange_, y, 0);
manual->position(0, y, 0);
manual->end();
Ogre::SceneNode* node = engine_->sysGraphics_->getSceneRoot()->createChildSceneNode(
Ogre::Vector3(config.posX_, config.posY_, 0));
node->attachObject(manual);
ComGraphics* comGraphics = entityMgr->assignComponent<ComGraphics>(entity);
comGraphics->sceneNode_ = node;
return entity;
}
示例6: onConnect
// Implement ENetReceiver
void onConnect(ENetPeer* peer) {
auto newClient = clients.add(peer);
INFO(server) << "Client " << (int)newClient->id << " connected";
// Tell the client its id. This needs to happen before sending
// the CreateEntityMessages, so that the client can identify what
// entities belong to it.
sendEvent<LoggedInOrder>(peer, newClient->id);
// Create player entity for the client
newClient->entity = entities.create(
makePlayer(netSystem.makeNetEntityId(),
newClient->id,
vec3(0, 0, 0),
vec3(0, 0, 0)));
// Send messages to create our net objects on the client side
netSystem.sendCreateEntityOrders(newClient);
// Tell everyone about the new client
clients.broadcast<ClientConnectedOrder>(newClient->id, "dummy");
}