TEST(AbilitySpawn, LoadAndAttatch) { ECS::World* world = CreateWorld(); g_world = world; g_networkEntityMap.clear(); ECS::Entity* testity = world->GetEntityManager()->CreateEntity(); world->GetGroupManager()->RegisterEntity("AbilitySpawnPoint", testity); RootForce::AbilitySpawnSystem* system = new RootForce::AbilitySpawnSystem(world, &g_engineContext, g_engineContext.m_resourceManager->GetWorkingDirectory()); world->GetSystemManager()->AddSystem<RootForce::AbilitySpawnSystem>(system); g_engineContext.m_resourceManager->LoadScript("AbilityBall"); g_engineContext.m_resourceManager->LoadScript("AbilitySpawnPoint"); //Test so that loading an ability pack works { system->LoadAbilities("Fake"); //Load a fake pack, should give a logg message but no crash system->LoadAbilities("Standard"); //Load existing pack } { system->AttachComponentToPoints(); RootForce::AbilitySpawnComponent* component = world->GetEntityManager()->GetComponent<RootForce::AbilitySpawnComponent>(testity); EXPECT_NE(component, nullptr); //Make sure that the component was attached correctly by checking so that it is not null } world->GetEntityManager()->RemoveAllEntitiesAndComponents(); world->GetTagManager()->UnregisterAll(); world->GetGroupManager()->UnregisterAll(); g_engineContext.m_physics->RemoveAll(); delete world; }
TEST(ECS, NullComponent) { // Initialize a world and some components ECS::World* world = CreateWorld(); // Create an entity ECS::Entity* e = world->GetEntityManager()->CreateEntity(); // Assert that trying to get a component returns null ASSERT_EQ(world->GetEntityManager()->GetComponent<RootForce::Transform>(e), nullptr); // Add component and test again world->GetEntityManager()->CreateComponent<RootForce::Transform>(e); ASSERT_NE(world->GetEntityManager()->GetComponent<RootForce::Transform>(e), nullptr); }
TEST(ECS, GettingAllComponents) { // Initialize a world and some components ECS::World* world = CreateWorld(); g_world = world; // Create entities with different permutations of components ECS::Entity* e12 = world->GetEntityManager()->CreateEntity(); ECS::Entity* e1 = world->GetEntityManager()->CreateEntity(); ECS::Entity* e2 = world->GetEntityManager()->CreateEntity(); world->GetEntityManager()->CreateComponent<RootForce::Transform>(e12); world->GetEntityManager()->CreateComponent<RootForce::HealthComponent>(e12); world->GetEntityManager()->CreateComponent<RootForce::Transform>(e1); world->GetEntityManager()->CreateComponent<RootForce::HealthComponent>(e2); // Retrieve all components auto r12 = world->GetEntityManager()->GetAllComponents(e12); auto r1 = world->GetEntityManager()->GetAllComponents(e1); auto r2 = world->GetEntityManager()->GetAllComponents(e2); // Make sure we get the correct number of components ASSERT_EQ(r12.size(), 2); ASSERT_EQ(r1.size(), 1); ASSERT_EQ(r2.size(), 1); // Make sure the components are of the proper type ASSERT_EQ(r12[0].first, RootForce::Transform::GetTypeId()); ASSERT_EQ(r12[1].first, RootForce::HealthComponent::GetTypeId()); ASSERT_EQ(r1[0].first, RootForce::Transform::GetTypeId()); ASSERT_EQ(r2[0].first, RootForce::HealthComponent::GetTypeId()); }
TEST(AbilitySpawn, ProcessEntity) { ECS::World* world = CreateWorld(); g_world = world; g_networkEntityMap.clear(); ECS::Entity* testity = world->GetEntityManager()->CreateEntity(); world->GetGroupManager()->RegisterEntity("AbilitySpawnPoint", testity); RootForce::AbilitySpawnSystem* system = new RootForce::AbilitySpawnSystem(world, &g_engineContext, g_engineContext.m_resourceManager->GetWorkingDirectory()); world->GetSystemManager()->AddSystem<RootForce::AbilitySpawnSystem>(system); g_engineContext.m_resourceManager->LoadScript("AbilityBall"); g_engineContext.m_resourceManager->LoadScript("AbilitySpawnPoint"); system->LoadAbilities("Standard"); //Load existing pack system->AttachComponentToPoints(); RootForce::Renderable* rendcomp; RootForce::AbilitySpawnComponent* spawncomp; { system->Process(); rendcomp = world->GetEntityManager()->GetComponent<RootForce::Renderable>(testity); spawncomp = world->GetEntityManager()->GetComponent<RootForce::AbilitySpawnComponent>(testity); EXPECT_NE(rendcomp, nullptr); //Make sure that a new render component was created in the process since the point had no active ability EXPECT_NE(spawncomp->CurrentAbility.Name, ""); //Check that we got an ability to spawn, if the name is empty there is no ability } { spawncomp->Claimed = true; system->Process(); rendcomp = world->GetEntityManager()->GetComponent<RootForce::Renderable>(testity); EXPECT_EQ(spawncomp->Timer, 30.0f); //Check that the timer has been set after the ability was claimed EXPECT_EQ(spawncomp->CurrentAbility.Name, ""); //Check that there is no ability present at the point EXPECT_EQ(rendcomp, nullptr); //Check that the render component has been removed correctly } world->GetEntityManager()->RemoveAllEntitiesAndComponents(); world->GetTagManager()->UnregisterAll(); world->GetGroupManager()->UnregisterAll(); g_engineContext.m_physics->RemoveAll(); delete world; }
TEST(ECS, GetAllEntities) { // Initialize a world and some entities ECS::World* world = CreateWorld(); // Create a few entities const int NUM_ENTITIES = 5; ECS::Entity* e[NUM_ENTITIES]; for (int i = 0; i < NUM_ENTITIES; ++i) { e[i] = world->GetEntityManager()->CreateEntity(); } // Assert that we get the right entities std::vector<ECS::Entity*> entities = world->GetEntityManager()->GetAllEntities(); ASSERT_EQ(entities.size(), NUM_ENTITIES); for (int i = 0; i < NUM_ENTITIES; ++i) { ASSERT_EQ(entities[i], e[i]); } }
TEST(AbilitySpawn, ProcessEmptyEntity) { ECS::World* world = CreateWorld(); g_world = world; g_networkEntityMap.clear(); ECS::Entity* testity = world->GetEntityManager()->CreateEntity(); RootForce::AbilitySpawnSystem* system = new RootForce::AbilitySpawnSystem(world, &g_engineContext, g_engineContext.m_resourceManager->GetWorkingDirectory()); world->GetSystemManager()->AddSystem<RootForce::AbilitySpawnSystem>(system); // Will test that an empty entity (an entity missing the necessary components does not crash the system system->Process(); world->GetEntityManager()->RemoveAllEntitiesAndComponents(); world->GetTagManager()->UnregisterAll(); world->GetGroupManager()->UnregisterAll(); g_engineContext.m_physics->RemoveAll(); delete world; }
TEST(PlayerControlSystem, Process) { ECS::World* world = CreateWorld(); world->SetDelta(1.0f); g_world = world; g_networkEntityMap.clear(); // Initialize the keybindings we need for the test(not the complete list that is normally used) std::vector<RootForce::Keybinding> keybindings(6); keybindings[0].Bindings.push_back(SDL_SCANCODE_UP); keybindings[0].Bindings.push_back(SDL_SCANCODE_W); keybindings[0].Action = RootForce::PlayerAction::MOVE_FORWARDS; keybindings[0].Edge = true; keybindings[1].Bindings.push_back(SDL_SCANCODE_DOWN); keybindings[1].Bindings.push_back(SDL_SCANCODE_S); keybindings[1].Action = RootForce::PlayerAction::MOVE_BACKWARDS; keybindings[1].Edge = true; keybindings[4].Bindings.push_back(SDL_SCANCODE_SPACE); keybindings[4].Action = RootForce::PlayerAction::JUMP_PRESSED; keybindings[4].ActionUp = RootForce::PlayerAction::JUMP_RELEASED; keybindings[4].Edge = true; keybindings[5].Bindings.push_back((SDL_Scancode)RootEngine::InputManager::MouseButton::LEFT); keybindings[5].Action = RootForce::PlayerAction::ACTIVATE_ABILITY_PRESSED; keybindings[5].ActionUp = RootForce::PlayerAction::ACTIVATE_ABILITY_RELEASED; keybindings[5].Edge = true; keybindings.push_back(RootForce::Keybinding()); keybindings[keybindings.size()-1].Bindings.push_back(SDL_SCANCODE_1); keybindings[keybindings.size()-1].Action = RootForce::PlayerAction::SELECT_ABILITY1; keybindings[keybindings.size()-1].Edge = true; keybindings.push_back(RootForce::Keybinding()); keybindings[keybindings.size()-1].Bindings.push_back(SDL_SCANCODE_2); keybindings[keybindings.size()-1].Action = RootForce::PlayerAction::SELECT_ABILITY2; keybindings[keybindings.size()-1].Edge = true; keybindings.push_back(RootForce::Keybinding()); keybindings[keybindings.size()-1].Bindings.push_back(SDL_SCANCODE_3); keybindings[keybindings.size()-1].Action = RootForce::PlayerAction::SELECT_ABILITY3; keybindings[keybindings.size()-1].Edge = true; RootForce::PlayerControlSystem* system = new RootForce::PlayerControlSystem(world); system->SetInputInterface(g_engineContext.m_inputSys); system->SetLoggingInterface(g_engineContext.m_logger); system->SetPhysicsInterface(g_engineContext.m_physics); system->SetKeybindings(keybindings); // Call the OnCreate script g_engineContext.m_script->SetGlobalNumber("UserID", 0); g_engineContext.m_script->SetGlobalNumber("IsClient", true); g_engineContext.m_script->SetFunction(g_engineContext.m_resourceManager->LoadScript("Player"), "OnCreate"); //g_engineContext.m_script->AddParameterUserData(testity, sizeof(ECS::Entity*), "Entity"); g_engineContext.m_script->AddParameterNumber(0); g_engineContext.m_script->AddParameterNumber(RootForce::Network::ReservedActionID::CONNECT); g_engineContext.m_script->ExecuteScript(); ECS::Entity* testity = world->GetTagManager()->GetEntityByTag("Player"); RootEngine::InputManager::InputInterface* ii = g_engineContext.m_inputSys; RootForce::PlayerActionComponent* action = world->GetEntityManager()->GetComponent<RootForce::PlayerActionComponent>(testity); //Fake event to test different keys SDL_Event falseevent; falseevent.type = SDL_KEYDOWN; falseevent.key.repeat = false; //Movement test { falseevent.key.keysym.scancode = SDL_SCANCODE_UP; ii->HandleInput(falseevent); system->Process(); //Pushing just forward should set movepower to 1 EXPECT_EQ(action->MovePower, 1); falseevent.key.keysym.scancode = SDL_SCANCODE_DOWN; ii->HandleInput(falseevent); falseevent.key.keysym.scancode = SDL_SCANCODE_UP; ii->HandleInput(falseevent); system->Process(); //Pushing back and forth at the same time should cancel each other out EXPECT_EQ(action->MovePower, 0); falseevent.key.keysym.scancode = SDL_SCANCODE_DOWN; ii->HandleInput(falseevent); system->Process(); //We have now released the up key and should be moving backwards EXPECT_EQ(action->MovePower, -1); } //Jump test { falseevent.key.keysym.scancode = SDL_SCANCODE_SPACE; falseevent.type = SDL_KEYDOWN; ii->HandleInput(falseevent); system->Process(); EXPECT_GT(action->JumpTime, 0); } //Orientation test { SDL_Event falseMouseEvent; falseMouseEvent.type = SDL_MOUSEMOTION; falseMouseEvent.motion.x = 5; falseMouseEvent.motion.y = 140; falseMouseEvent.motion.xrel = 5; falseMouseEvent.motion.yrel = 140; ii->HandleInput(falseMouseEvent); system->Process(); EXPECT_LT(action->Angle.y, 0); EXPECT_GT(action->Angle.x, 0); } world->GetEntityManager()->RemoveAllEntitiesAndComponents(); world->GetTagManager()->UnregisterAll(); world->GetGroupManager()->UnregisterAll(); g_engineContext.m_physics->RemoveAll(); delete world; }