示例#1
0
void InteractiveState::Handle(const Packet::EntityUpdate &pack) {
	auto world_iter = world.Entities().begin();
	auto world_end = world.Entities().end();

	uint32_t count = 0;
	glm::ivec3 base;
	pack.ReadEntityCount(count);
	pack.ReadChunkBase(base);
	EntityState state;

	for (uint32_t i = 0; i < count; ++i) {
		uint32_t entity_id = 0;
		pack.ReadEntityID(entity_id, i);

		while (world_iter != world_end && world_iter->ID() < entity_id) {
			++world_iter;
		}
		if (world_iter == world_end) {
			// nothing can be done from here
			return;
		}
		if (world_iter->ID() == entity_id) {
			if (UpdateEntity(entity_id, pack.Seq())) {
				pack.ReadEntityState(state, base, i);
				world_iter->SetState(state);
			}
		}
	}
}
示例#2
0
//------------------------------------------------------------------------
void CVehiclePartEntity::Update(const float frameTime)
{
	CVehiclePartBase::Update(frameTime);

	if( m_createBuddyConstraint && GetPartEntity()) //Wait for part entity to be valid
	{
		//stop collision between vehicle and part
		if ( IPhysicalEntity *pVehiclePE = m_pVehicle->GetEntity()->GetPhysics() )
		{
			IPhysicalEntity *pPartPE = GetPartEntity()->GetPhysics();
			pe_action_add_constraint ic;
			ic.flags = constraint_inactive|constraint_ignore_buddy;
			ic.pBuddy = pPartPE;
			ic.pt[0].Set(0,0,0);
			m_constraintId = pVehiclePE->Action(&ic);
		}

		m_createBuddyConstraint = false;
	}

	if(m_entityAttached)
	{
		UpdateEntity();
	}
}
ERR InitTestController()
{
    ship = NewEntity("game/entities/ship.entity");
    if(ship == NULL)
        return 1;
    flames = NewEntity("game/entities/flames.entity");
    if(flames == NULL)
    {
        FreeEntity(ship);
        return 1;
    }
    yoshi = NewEntity("game/entities/test.entity");
    if(yoshi == NULL)
    {
        FreeEntity(ship);
        FreeEntity(flames);
        return 1;
    }

    bolt = NewEntity("game/entities/bolt.entity");

    ship->center_x          = 120;
    ship->center_y          = 120;
    ship->sprite->z_index   = 3;

    yoshi->center_x         = 220;
    yoshi->center_y         = 120;
    yoshi->a_speed          = 2;
    yoshi->x_speed          = 0;
    yoshi->y_speed          = 0;
    yoshi->sprite->z_index  = 4;
    
    UpdateEntity(ship);
    UpdateEntity(flames);
    UpdateEntity(yoshi);

    bolt->sprite->z_index   = 1;

    bolts = NewList();

    visual_debug = NewPixelMap(640, 480, (Vector){320, 240}, 10);
    ClearPMap(visual_debug);

    flags = (INITIALISED | CONTINUE | UPDATE | DRAW);
    return 0;
}
void QuadTree::Update()
{
	for(int i = 0; i < allEntitiesInQuadTree.size(); ++i)
	{
		if(allEntitiesInQuadTree[i]->NeedsUpdate())
			UpdateEntity(allEntitiesInQuadTree[i]);
	}
}
示例#5
0
void InteractiveState::Handle(const Packet::SpawnEntity &pack) {
	uint32_t entity_id;
	pack.ReadEntityID(entity_id);
	Entity &entity = world.ForceAddEntity(entity_id);
	UpdateEntity(entity_id, pack.Seq());
	pack.ReadEntity(entity);
	uint32_t model_id;
	pack.ReadModelID(model_id);
	if (model_id > 0 && model_id <= res.models.size()) {
		res.models.Get(model_id).Instantiate(entity.GetModel());
	}
}
示例#6
0
void CAreaManager::Update()
{
	FUNCTION_PROFILER(GetISystem(), PROFILE_ENTITY);

	// Update the area grid data structure.
	UpdateDirtyAreas();

	if (!m_mapEntitiesToUpdate.empty())
	{
#if defined(INCLUDE_ENTITYSYSTEM_PRODUCTION_CODE)
		float const debugPosX = 650.0f;
		float debugPosY = 500.0f;
		float const fColor[4] = {0.0f, 1.0f, 0.0f, 0.7f};
		bool const bDrawDebug = CVar::pDrawAreaDebug->GetIVal() != 0;

		if (bDrawDebug)
		{
			gEnv->pRenderer->Draw2dLabel(debugPosX, debugPosY, 1.35f, fColor, false, "Entities to update: %d\n",  static_cast<int>(m_mapEntitiesToUpdate.size()));
			debugPosY += 12.0f;
		}
#endif // INCLUDE_ENTITYSYSTEM_PRODUCTION_CODE

		TEntitiesToUpdateMap::iterator Iter(m_mapEntitiesToUpdate.begin());
		TEntitiesToUpdateMap::const_iterator const IterEnd(m_mapEntitiesToUpdate.end());

		for (; Iter != IterEnd; ++Iter)
		{
			assert(Iter->second > 0);
			--(Iter->second);

			IEntity const* const pEntity = g_pIEntitySystem->GetEntity(Iter->first);

			if (pEntity != NULL)
			{
				// Add a Z offset of at least 0.11 to be slightly above the offset of 0.1 set through "CShapeObject::GetShapeZOffset".
				Vec3 const oPos = pEntity->GetWorldPos() + Vec3(0.0f, 0.0f, 0.11f);
				UpdateEntity(oPos, pEntity);

#if defined(INCLUDE_ENTITYSYSTEM_PRODUCTION_CODE)
				if (bDrawDebug)
				{
					gEnv->pRenderer->Draw2dLabel(debugPosX + 10.0f, debugPosY, 1.35f, fColor, false, "Entity: %d (%s) Pos: (%.2f, %.2f, %.2f)\n", Iter->first, pEntity ? pEntity->GetName() : "NULL", oPos.x, oPos.y, oPos.z);
					debugPosY += 12.0f;
				}
#endif // INCLUDE_ENTITYSYSTEM_PRODUCTION_CODE
			}
		}

		m_mapEntitiesToUpdate.erase_if(IsDoneUpdating);
	}
}
示例#7
0
void MainScene::update(float dt)
{
   UpdateEntity();
   UpdateCamera();
   EntityScheduler::Instance().Update();
   // Update all the debug info
   Notifier::Instance().Notify(NE_UPDATE_DEBUG_INFO,true);
   // Update the physics.
   UpdatePhysics();
   // Clear out any old information
   GraphSensorManager::Instance().ClearChangedSensors();

   Viewport::Instance().Update();
#ifdef TEST_SEARCH_PERFORMANCE
   TestSearchPerformance();
#endif
}
示例#8
0
void World::Update()
{
	while (running)
	{
		if (!IN_BUFFER.Empty()) // was while
		{
			Message first_update(IN_BUFFER.Front());
			UpdateEntity(first_update);
			
			/*ent_itor it = std::find_if(entities.begin(), entities.end(),
			std::bind2nd(std::ptr_fun(CompareID), first_update.id));*/
			
			auto it = std::find_if(entities.begin(), entities.end(),  
				[&first_update](const entity_ptr ent) -> bool {
					return ent->ID() == first_update.id;
				});		

			if (it != entities.end())
				OUT_BUFFER.PushMessage((*it));
		}
	}
}
示例#9
0
void CScriptActorKeyframe::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) {
  if (msg == EScriptObjectMessage::Action) {
    if (GetActive()) {
      if (!x44_25_isPassive) {
        for (const SConnection& conn : x20_conns) {
          if (conn.x0_state != EScriptObjectState::Play || conn.x4_msg != EScriptObjectMessage::Play)
            continue;

          auto search = mgr.GetIdListForScript(conn.x8_objId);
          for (auto it = search.first; it != search.second; ++it)
            UpdateEntity(it->second, mgr);
        }
      }

      x44_28_playing = true;
      SendScriptMsgs(EScriptObjectState::Play, mgr, EScriptObjectMessage::None);
    }
  } else if (msg == EScriptObjectMessage::InitializedInArea) {
    if (x34_animationId == -1)
      x34_animationId = 0;
  }

  CEntity::AcceptScriptMsg(msg, uid, mgr);
}
void CGumpControlListDlg::OnBnClickedUnhide()
{
	UpdateEntity(VISIBLE, TRUE);
}
void CGumpControlListDlg::OnBnClickedHide()
{
	UpdateEntity(VISIBLE, FALSE);
}
void CGumpControlListDlg::OnBnClickedUnfreeze()
{
	UpdateEntity(FREEZE, FALSE);
}
void CGumpControlListDlg::OnBnClickedFreeze()
{
	UpdateEntity(FREEZE, TRUE);
}
void CGumpControlListDlg::OnBnClickedUnselect()
{
	UpdateEntity(SELECT, FALSE);
}
void CGumpControlListDlg::OnBnClickedSelect()
{
	UpdateEntity(SELECT, TRUE);
}
ERR TestControllerLoop()
{
    while(flags & CONTINUE)
    {
        //AddForce(ship->physics_object, 0.0, 10.0, ship->physics_object->cog_x, ship->physics_object->cog_y);        

        SDL_Event event;
        while(SDL_PollEvent(&event) != 0)
        {
            if(event.type == SDL_QUIT)
                 flags ^= CONTINUE;
            else if(event.type == SDL_KEYDOWN && event.key.repeat == 0)
                switch(event.key.keysym.sym)
                {
                case SDLK_UP: 
                    flames->sprite->data[CURRENT_LOOP] ^= 1;
                    flags ^= ENGINE;
                    break;
                case SDLK_DOWN:
                    ship->y_speed = 0.0;
                    ship->x_speed = 0.0;
                    break;
                case SDLK_LEFT: ship->a_speed   = -5.0; break;
                case SDLK_RIGHT: ship->a_speed  = 5.0; break;
                case SDLK_r :
                    yoshi->center_x = 220;
                    yoshi->center_y = 120;
                    yoshi->x_speed = 0;
                    yoshi->y_speed = 0;
                    ship->center_x = 520;
                    ship->center_y = 120;
                    ship->x_speed = 0;
                    ship->y_speed = 0;
                case SDLK_SPACE:
                    tmp = CopyEntity(bolt);
                    tmp->center_x = ship->center_x;
                    tmp->center_y = ship->center_y;
                    tmp->angle = ship->angle;
                    tmp->x_speed = RotateOffsetX(0.0, -10.0, ship->angle);
                    tmp->y_speed = RotateOffsetY(0.0, -10.0, ship->angle);
                    InsertValue(tmp, bolts, 0);
                    break;
                }
            else if(event.type == SDL_KEYUP)
                switch(event.key.keysym.sym)
                {
                case SDLK_UP:
                    flames->sprite->data[CURRENT_LOOP] ^= 1;
                    flags ^= ENGINE;
                    break;
                case SDLK_DOWN: break;
                case SDLK_LEFT: ship->a_speed   = 0.0; break;
                case SDLK_RIGHT: ship->a_speed  = 0.0; break;
                case SDLK_SPACE: 
                    break;
                }
        }

        if(flags & UPDATE)
        {
            if(flags & ENGINE)
                AddForce(ship->physics_object, RotateOffsetX(0.0, -20.0, ship->angle), RotateOffsetY(0.0, -20.0, ship->angle),
                        ship->physics_object->cog_x, ship->physics_object->cog_y);

            if(CheckCollision(ship->collision_object, yoshi->collision_object) != 0)
            {
                printf("BOOM\n");
                //flags ^= CONTINUE;
                AddForce(ship->physics_object, yoshi->x_speed * yoshi->physics_object->mass, yoshi->y_speed * yoshi->physics_object->mass,
                        ship->physics_object->cog_x, ship->physics_object->cog_y);
                AddForce(yoshi->physics_object, ship->x_speed * ship->physics_object->mass, ship->y_speed * ship->physics_object->mass,
                        yoshi->physics_object->cog_x, yoshi->physics_object->cog_y);
            }
            Element* el = bolts->start;
            Entity* tmp = NULL;
            int i = 0;
            while(el != NULL)
            {
                tmp = (Entity*)el->value;
                //if(CheckCollision(ship->collision_object, tmp->collision_object) != 0)
                //{
                //    printf("BOOM\n");
                //    flags ^= CONTINUE;
                //}
                if(CheckCollision(yoshi->collision_object, tmp->collision_object) != 0)
                {
                    AddForce(yoshi->physics_object, RotateOffsetX(0.0, -10.0, tmp->angle), RotateOffsetY(0.0, -10.0, tmp->angle),
                            yoshi->physics_object->cog_x, yoshi->physics_object->cog_y);
                    yoshi->sprite->zoom -= 0.5;
                    if(yoshi->sprite->zoom < 0.5)
                        yoshi->sprite->zoom = 0.5;
                    FreeEntity(tmp);
                    FreeElement(bolts, i);
                }
                i++;
                el = el->next;
            }

            UpdateEntity(ship);

            flames->angle = ship->angle;
            flames->center_x = ship->center_x + RotateOffsetX(0.0, ship->sprite->h * ship->sprite->zoom, ship->angle);
            flames->center_y = ship->center_y + RotateOffsetY(0.0, ship->sprite->h * ship->sprite->zoom, ship->angle);
            UpdateEntity(flames);

            UpdateEntity(yoshi);
            yoshi->sprite->zoom      += 0.01;
            yoshi->physics_object->mass = yoshi->sprite->zoom * 100;
            if(yoshi->physics_object->mass < 1)
                yoshi->physics_object->mass = 1;
            yoshi->collision_object->radius = 32*yoshi->sprite->zoom;
            if(yoshi->collision_object->radius < 1)
                yoshi->collision_object->radius = 1;

            for(i = 0; i < bolts->size; i++)
            {
                Entity* tmp = (Entity*)GetValue(bolts, i);
                if(tmp->center_x < -15 || tmp->center_y < -15 || tmp->center_x > 1000 || tmp->center_y > 500)
                {
                    FreeEntity(tmp);
                    FreeElement(bolts, i);
                }
                else
                    UpdateEntity(tmp);
            }
        }

        if(flags & DRAW)
        {
            ClearPMap(visual_debug);
            DrawEntity(ship);
            DrawEntityDebugInfo(visual_debug, ship);
            DrawEntity(flames);
            DrawEntity(yoshi);
            DrawEntityDebugInfo(visual_debug, yoshi);
            int i;
            for(i = 0; i < bolts->size; i++)
            {
                Entity* tmp = (Entity*)GetValue(bolts, i);
                DrawEntity(tmp);
                DrawEntityDebugInfo(visual_debug, tmp);
            }
            DrawPixelMap(visual_debug);
            Render();
        }
    }
    return ExitTestController();
}
示例#17
0
//------------------------------------------------------------------------
void CVehiclePartEntity::Reset()
{
	if(m_entityId && !gEnv->pEntitySystem->GetEntity(m_entityId))
	{
		m_entityId = 0;
	}

	if(!m_entityId)
	{
		SEntitySpawnParams	entitySpawnParams;

		entitySpawnParams.pArchetype = gEnv->pEntitySystem->LoadEntityArchetype(m_entityArchetype.c_str());

		if(entitySpawnParams.pArchetype)
		{
			entitySpawnParams.pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(m_entityName.c_str());

			if(entitySpawnParams.pClass)
			{
				entitySpawnParams.vPosition		= Vec3(0.0f, 0.0f, 0.0f);
				entitySpawnParams.sName				= m_entityName.c_str();
				entitySpawnParams.nFlags |= (m_pVehicle->GetEntity()->GetFlags() & (ENTITY_FLAG_CLIENT_ONLY|ENTITY_FLAG_SERVER_ONLY))|ENTITY_FLAG_NEVER_NETWORK_STATIC;

				//if the entity will be created by the server, don't create it on the clients
				//we will receive an entity spawn from the server and join it on later
				if( gEnv->bServer || ( entitySpawnParams.nFlags & ENTITY_FLAG_CLIENT_ONLY ) )
				{
					if(IEntity *pEntity = gEnv->pEntitySystem->SpawnEntity(entitySpawnParams))
					{
						m_entityId = pEntity->GetId();

						//Create an entity link so the entity can find the Vehicle if it needs to
						m_pLink = pEntity->AddEntityLink( "VehiclePartLink", m_pVehicle->GetEntityId() );

						m_pVehicle->SetObjectUpdate(this, IVehicle::eVOU_AlwaysUpdate);

						pEntity->Hide(m_hidden);

						if( m_CollideWithParent == false )
						{
							m_createBuddyConstraint = true;
						}

						INetContext* pNetContext = gEnv->pGame->GetIGameFramework()->GetNetContext();
						if (pNetContext)
						{
							SNetObjectID netId = pNetContext->GetNetID( m_entityId, false);
							m_entityNetId = netId.id;
						}

						UpdateEntity();
					}
				}
			}
		}
	}
	else
	{
		//this is required to handle resetting world in editor, should not be hit while running game
		if( IEntity *pEntity = gEnv->pEntitySystem->GetEntity(m_entityId) )
		{
			if( !m_entityAttached )
			{
				//Create an entity link so the entity can find the Vehicle if it needs to
				m_pLink = pEntity->AddEntityLink( "VehiclePartLink", m_pVehicle->GetEntityId() );

				m_pVehicle->SetObjectUpdate(this, IVehicle::eVOU_AlwaysUpdate);

				pEntity->Hide(m_hidden);

				if( m_CollideWithParent == false )
				{
					m_createBuddyConstraint = true;
				}

				INetContext* pNetContext = gEnv->pGame->GetIGameFramework()->GetNetContext();
				if (pNetContext)
				{
					SNetObjectID netId = pNetContext->GetNetID( m_entityId, false);
					m_entityNetId = netId.id;
				}

				UpdateEntity();
			}
			else
			{
				m_pVehicle->SetObjectUpdate(this, IVehicle::eVOU_AlwaysUpdate);

				if( m_constraintId )
				{
					if( m_CollideWithParent == false )
					{
						m_createBuddyConstraint = true;
					}
				}
			}
		}
	}

	m_entityAttached = !!m_entityId;
}
示例#18
0
    int CWorldDbmgr::FromRpcCall(CPluto& u, CDbOper& db)
    {
        //printf("CWorldDbmgr::from_rpc_call\n");
        //print_hex_pluto(u);

        pluto_msgid_t msg_id = -1;
        T_VECTOR_OBJECT* p = NULL;

        //这一段要加锁(2012/02/15改为不加锁)
        {
            //CMutexGuard _g(m_rpcMutex);

            msg_id = u.GetMsgId();
            if(!CheckClientRpc(u))
            {
                LogWarning("from_rpc_call", "invalid rpcall error.unknown msgid:%d\n", msg_id);
                return -1;
            }

            p = m_rpc.Decode(u);
            if(p == NULL)
            {
                LogWarning("from_rpc_call", "rpc Decode error.unknown msgid:%d\n", msg_id);
                return -1;
            }

            if(u.GetDecodeErrIdx() > 0)
            {
                ClearTListObject(p);
                //PrintHexPluto(u);
                LogWarning("from_rpc_call", "rpc Decode error.msgid:%d;pluto err idx=%d\n", msg_id, u.GetDecodeErrIdx());
                return -2;
            }
        }

        //这一段不用加锁
        int nRet = -1;
        switch(msg_id)
        {
            case MSGID_DBMGR_INSERT_ENTITY:
            {
                nRet = InsertDB(p, db);
                break;
            }
            case MSGID_DBMGR_SELECT_ENTITY:
            {
                nRet = LookupEntityByDbId(p, db);
                break;
            }
            case MSGID_DBMGR_UPDATE_ENTITY:
            {
                nRet = UpdateEntity(p, db);
                break;
            }
            case MSGID_DBMGR_UPDATE_ENTITY_REDIS:
            {
                nRet = UpdateEntityToRedis(p, db);
                break;
            }
            case MSGID_DBMGR_SELECT_ACCOUNT:
            {
                nRet = SelectAccount(p, db);
                break;
            }
            case MSGID_DBMGR_RAW_MODIFY_NORESP:
            {
                nRet = QueryModifyNoResp(p, db);
                break;
            }
            case MSGID_DBMGR_CREATEBASE_FROM_NAME:
            {
                nRet = LookupEntityByName(p, db);
                break;
            }
            case MSGID_DBMGR_LOAD_ALL_AVATAR:
            {
                nRet = LoadAllAvatars(p, db);
                break;
            }
            case MSGID_DBMGR_LOAD_ENTITIES_OF_TYPE:
            {
                nRet = LoadEntitiesOfType(p, db);
                break;
            }
            case MSGID_DBMGR_SHUTDOWN_SERVER:
            {
                nRet = ShutdownServer(p);
                break;
            }
            case MSGID_DBMGR_REDIS_HASH_LOAD:
            {
                nRet = RedisHashLoad(p, db);
                break;
            }
            case MSGID_DBMGR_REDIS_HASH_SET:
            {
                nRet = RedisHashSet(p, db);
                break;
            }
            case MSGID_DBMGR_REDIS_HASH_DEL:
            {
                nRet = RedisHashDel(p, db);
                break;
            }
            case MSGID_DBMGR_DEL_ACCOUNT_CACHE:
            {
                nRet = DestroyAccountCache(p);
                break;
            }

            case MSGID_DBMGR_UPDATE_ITEMS:
            {
                nRet = UpdateArrayItemsToDb(p, db);
                break;
            }
            case MSGID_DBMGR_LOADING_ITEMS:
            {
                nRet = LoadingArrayItemsToInventory(p, db);
                break;
            }
            case MSGID_DBMGR_INCREMENTAL_UPDATE_ITEMS:
            {
                nRet = IncremantalUpdateItems(p, db);
                break;
            }

            case MSGID_DBMGR_TABLE_SELECT:
            {
                nRet = TableSelect(p, db);
                break;
            }
            case MSGID_DBMGR_UPDATE_BATCH:
            {
                nRet = TableUpdateBatch(p, db);
                break;
            }
            case MSGID_DBMGR_TABLE_INSERT:
            {
                nRet = TableInsert(p, db);
                break;
            }
            case MSGID_DBMGR_TABLE_EXCUTE:
            {
                nRet = TableExcute(p, db);
                break;
            }
            case MSGID_DBMGR_TABLE2_SELECT:
            {
                nRet = Table2Select(p, db);
                break;
            }
            case MSGID_DBMGR_TABLE2_INSERT:
            {
                nRet = Table2Insert(p, db);
                break;
            }
            case MSGID_DBMGR_TABLE2_EXCUTE:
            {
                nRet = Table2Excute(p, db);
                break;
            }
            default:
            {
                break;
            }
        }

        if(nRet != 0)
        {
            LogWarning("from_rpc_call", "rpc error.msg_id=%d;ret=%d\n", msg_id, nRet);
        }

        ClearTListObject(p);

        return 0;
    }
//
// Main
//
int main()
{

	sf::RenderWindow window(sf::VideoMode(1024, 768, 32), "main_testGameEntity");

	// Loading a picture with anims.
	sf::Image img;
	if (!img.LoadFromFile("../../resources/images/truck/canon.png"))
		return EXIT_FAILURE;

	Anim anim = GetAnimFromImage(img, 146.0f, 146.0f, 18);

	GameEntity gameEntity(anim, 0.03f);
	gameEntity.SetPosition(900.0f, 500.0f);

	ScrollingManager::getInstance()->insertEntity(&gameEntity);
	ScrollingManager::getInstance()->setVelocity(-200.0f);
	ScrollingManager::getInstance()->setActive(true);

	unsigned int Seed = 10;
	sf::Randomizer::SetSeed(Seed);

	// Main loop.
	sf::Event event;
	bool running = true;
	while (running)
	{

		// Events loop.
		while (window.GetEvent(event))
		{

			// Here we just deal with close event.
			// Moving is handle by sf::Input.
			switch (event.Type)
			{

			case sf::Event::Closed:
				running = false;
				break;

			default:
				break;
			}

		}


		UpdateEntity(gameEntity);


		int Random = sf::Randomizer::Random(-600, 600);
		ScrollingManager::getInstance()->setVelocity(float(Random));
		ScrollingManager::getInstance()->update(window.GetFrameTime());

			// Draw everything.
		window.Clear(); 
		window.Draw(gameEntity);
		window.Display();

	}

	return 0;

}