void GameHandler::processMessage(NetComputer *comp, MessageIn &message) { GameClient &computer = *static_cast< GameClient * >(comp); MessageOut result; if (computer.status == CLIENT_LOGIN) { if (message.getId() != PGMSG_CONNECT) return; std::string magic_token = message.readString(MAGIC_TOKEN_LENGTH); computer.status = CLIENT_QUEUED; // Before the addPendingClient mTokenCollector.addPendingClient(magic_token, &computer); return; } else if (computer.status != CLIENT_CONNECTED) { return; } switch (message.getId()) { case PGMSG_SAY: { std::string say = message.readString(); if (say.empty()) break; if (say[0] == '@') { CommandHandler::handleCommand(computer.character, say); break; } GameState::sayAround(computer.character, say); std::string msg = computer.character->getName() + " said " + say; accountHandler->sendTransaction(computer.character->getDatabaseID(), TRANS_MSG_PUBLIC, msg); } break; case PGMSG_NPC_TALK: case PGMSG_NPC_TALK_NEXT: case PGMSG_NPC_SELECT: case PGMSG_NPC_NUMBER: case PGMSG_NPC_STRING: { int id = message.readShort(); Actor *o = findActorNear(computer.character, id); if (!o || o->getType() != OBJECT_NPC) { sendError(comp, id, "Not close enough to NPC\n"); break; } NPC *q = static_cast< NPC * >(o); if (message.getId() == PGMSG_NPC_SELECT) { q->select(computer.character, message.readByte()); } else if (message.getId() == PGMSG_NPC_NUMBER) { q->integerReceived(computer.character, message.readLong()); } else if (message.getId() == PGMSG_NPC_STRING) { q->stringReceived(computer.character, message.readString()); } else { q->prompt(computer.character, message.getId() == PGMSG_NPC_TALK); } } break; case PGMSG_PICKUP: { int x = message.readShort(); int y = message.readShort(); Point ppos = computer.character->getPosition(); // TODO: use a less arbitrary value. if (std::abs(x - ppos.x) + std::abs(y - ppos.y) < 48) { MapComposite *map = computer.character->getMap(); Point ipos(x, y); for (FixedActorIterator i(map->getAroundPointIterator(ipos, 0)); i; ++i) { Actor *o = *i; Point opos = o->getPosition(); if (o->getType() == OBJECT_ITEM && opos.x == x && opos.y == y) { Item *item = static_cast< Item * >(o); ItemClass *ic = item->getItemClass(); Inventory(computer.character) .insert(ic->getDatabaseID(), item->getAmount()); GameState::remove(item); // log transaction std::stringstream str; str << "User picked up item " << ic->getDatabaseID() << " at " << opos.x << "x" << opos.y; accountHandler->sendTransaction(computer.character->getDatabaseID(), TRANS_ITEM_PICKUP, str.str()); break; } } } } break; case PGMSG_USE_ITEM: { int slot = message.readByte(); Inventory inv(computer.character); if (ItemClass *ic = ItemManager::getItem(inv.getItem(slot))) { if (ic->use(computer.character)) { inv.removeFromSlot(slot, 1); // log transaction std::stringstream str; str << "User used item " << ic->getDatabaseID() << " from slot " << slot; accountHandler->sendTransaction(computer.character->getDatabaseID(), TRANS_ITEM_USED, str.str()); } } } break; case PGMSG_DROP: { int slot = message.readByte(); int amount = message.readByte(); Inventory inv(computer.character); if (ItemClass *ic = ItemManager::getItem(inv.getItem(slot))) { int nb = inv.removeFromSlot(slot, amount); Item *item = new Item(ic, amount - nb); item->setMap(computer.character->getMap()); item->setPosition(computer.character->getPosition()); if (!GameState::insert(item)) { // The map is full. Put back into inventory. inv.insert(ic->getDatabaseID(), amount - nb); delete item; break; } // log transaction Point pt = computer.character->getPosition(); std::stringstream str; str << "User dropped item " << ic->getDatabaseID() << " at " << pt.x << "x" << pt.y; accountHandler->sendTransaction(computer.character->getDatabaseID(), TRANS_ITEM_DROP, str.str()); } } break; case PGMSG_WALK: { handleWalk(&computer, message); } break; case PGMSG_EQUIP: { int slot = message.readByte(); Inventory(computer.character).equip(slot); } break; case PGMSG_UNEQUIP: { int slot = message.readByte(); if (slot >= 0 && slot < EQUIP_PROJECTILE_SLOT) { Inventory(computer.character).unequip(slot); } } break; case PGMSG_MOVE_ITEM: { int slot1 = message.readByte(); int slot2 = message.readByte(); int amount = message.readByte(); Inventory(computer.character).move(slot1, slot2, amount); // log transaction std::stringstream str; str << "User moved item " << " from slot " << slot1 << " to slot " << slot2; accountHandler->sendTransaction(computer.character->getDatabaseID(), TRANS_ITEM_MOVE, str.str()); } break; case PGMSG_ATTACK: { int id = message.readShort(); LOG_DEBUG("Character " << computer.character->getPublicID() << " attacked being " << id); Actor *o = findActorNear(computer.character, id); if (o && o->getType() != OBJECT_NPC) { Being *being = static_cast<Being*>(o); computer.character->setTarget(being); computer.character->setAction(Being::ATTACK); } } break; case PGMSG_USE_SPECIAL: { int specialID = message.readByte(); LOG_DEBUG("Character " << computer.character->getPublicID() << " tries to use his special attack "<<specialID); computer.character->useSpecial(specialID); } case PGMSG_ACTION_CHANGE: { Being::Action action = (Being::Action)message.readByte(); Being::Action current = (Being::Action)computer.character->getAction(); bool logActionChange = true; switch (action) { case Being::STAND: { if (current == Being::SIT) { computer.character->setAction(Being::STAND); logActionChange = false; } } break; case Being::SIT: { if (current == Being::STAND) { computer.character->setAction(Being::SIT); logActionChange = false; } } break; default: break; } // Log the action change only when this is relevant. if (logActionChange) { // log transaction std::stringstream str; str << "User changed action from " << current << " to " << action; accountHandler->sendTransaction( computer.character->getDatabaseID(), TRANS_ACTION_CHANGE, str.str()); } } break; case PGMSG_DIRECTION_CHANGE: { computer.character->setDirection(message.readByte()); } break; case PGMSG_DISCONNECT: { bool reconnectAccount = (bool) message.readByte(); result.writeShort(GPMSG_DISCONNECT_RESPONSE); result.writeByte(ERRMSG_OK); // It is, when control reaches here if (reconnectAccount) { std::string magic_token(utils::getMagicToken()); result.writeString(magic_token, MAGIC_TOKEN_LENGTH); // No accountserver data, the client should remember that accountHandler->playerReconnectAccount( computer.character->getDatabaseID(), magic_token); } // TODO: implement a delayed remove GameState::remove(computer.character); accountHandler->sendCharacterData(computer.character); // Done with the character computer.character->disconnected(); delete computer.character; computer.character = NULL; computer.status = CLIENT_LOGIN; } break; case PGMSG_TRADE_REQUEST: { int id = message.readShort(); if (Trade *t = computer.character->getTrading()) { if (t->request(computer.character, id)) break; } Character *q = findCharacterNear(computer.character, id); if (!q || q->isBusy()) { result.writeShort(GPMSG_TRADE_CANCEL); break; } new Trade(computer.character, q); // log transaction std::string str; str = "User requested trade with " + q->getName(); accountHandler->sendTransaction(computer.character->getDatabaseID(), TRANS_TRADE_REQUEST, str); } break; case PGMSG_TRADE_CANCEL: case PGMSG_TRADE_AGREED: case PGMSG_TRADE_CONFIRM: case PGMSG_TRADE_ADD_ITEM: case PGMSG_TRADE_SET_MONEY: { std::stringstream str; Trade *t = computer.character->getTrading(); if (!t) break; switch (message.getId()) { case PGMSG_TRADE_CANCEL: t->cancel(); break; case PGMSG_TRADE_CONFIRM: t->confirm(computer.character); break; case PGMSG_TRADE_AGREED: t->agree(computer.character); // log transaction accountHandler->sendTransaction(computer.character->getDatabaseID(), TRANS_TRADE_END, "User finished trading"); break; case PGMSG_TRADE_SET_MONEY: { int money = message.readLong(); t->setMoney(computer.character, money); // log transaction str << "User added " << money << " money to trade."; accountHandler->sendTransaction(computer.character->getDatabaseID(), TRANS_TRADE_MONEY, str.str()); } break; case PGMSG_TRADE_ADD_ITEM: { int slot = message.readByte(); t->addItem(computer.character, slot, message.readByte()); // log transaction str << "User add item from slot " << slot; accountHandler->sendTransaction(computer.character->getDatabaseID(), TRANS_TRADE_ITEM, str.str()); } break; } } break; case PGMSG_NPC_BUYSELL: { BuySell *t = computer.character->getBuySell(); if (!t) break; int id = message.readShort(); int amount = message.readShort(); t->perform(id, amount); } break; case PGMSG_RAISE_ATTRIBUTE: { int attribute = message.readByte(); AttribmodResponseCode retCode; retCode = computer.character->useCharacterPoint(attribute); result.writeShort(GPMSG_RAISE_ATTRIBUTE_RESPONSE); result.writeByte(retCode); result.writeByte(attribute); if (retCode == ATTRIBMOD_OK ) { accountHandler->updateCharacterPoints( computer.character->getDatabaseID(), computer.character->getCharacterPoints(), computer.character->getCorrectionPoints(), attribute, computer.character->getAttribute(attribute)); // log transaction std::stringstream str; str << "User increased attribute " << attribute; accountHandler->sendTransaction(computer.character->getDatabaseID(), TRANS_ATTR_INCREASE, str.str()); } } break; case PGMSG_LOWER_ATTRIBUTE: { int attribute = message.readByte(); AttribmodResponseCode retCode; retCode = computer.character->useCorrectionPoint(attribute); result.writeShort(GPMSG_LOWER_ATTRIBUTE_RESPONSE); result.writeByte(retCode); result.writeByte(attribute); if (retCode == ATTRIBMOD_OK ) { accountHandler->updateCharacterPoints( computer.character->getDatabaseID(), computer.character->getCharacterPoints(), computer.character->getCorrectionPoints(), attribute, computer.character->getAttribute(attribute)); // log transaction std::stringstream str; str << "User decreased attribute " << attribute; accountHandler->sendTransaction(computer.character->getDatabaseID(), TRANS_ATTR_DECREASE, str.str()); } } break; case PGMSG_RESPAWN: { computer.character->respawn(); // plausibility check is done by character class } break; case PGMSG_NPC_POST_SEND: { handleSendPost(&computer, message); } break; default: LOG_WARN("Invalid message type"); result.writeShort(XXMSG_INVALID); break; } if (result.getLength() > 0) computer.send(result); }
/* returns actors that match the [x.y.z] expression */ static Targets* EvaluateObject(Map *map, Scriptable* Sender, Object* oC, int ga_flags) { // if you ActionOverride a global actor, they might not have a map :( // TODO: don't allow this to happen? if (!map) { return NULL; } if (oC->objectName[0]) { //We want the object by its name... Scriptable* aC = map->GetActor( oC->objectName, ga_flags ); /*if (!aC && (ga_flags&GA_GLOBAL) ) { aC = FindActorNearby(oC->objectName, map, ga_flags ); }*/ //This order is the same as in GetActorObject //TODO:merge them if (!aC) { aC = map->GetTileMap()->GetDoor(oC->objectName); } if (!aC) { aC = map->GetTileMap()->GetContainer(oC->objectName); } if (!aC) { aC = map->GetTileMap()->GetInfoPoint(oC->objectName); } //return here because object name/IDS targeting are mutually exclusive return ReturnScriptableAsTarget(aC); } if (oC->objectFields[0]==-1) { // this is an internal hack, allowing us to pass actor ids around as objects Actor* aC = map->GetActorByGlobalID( (ieDword) oC->objectFields[1] ); if (aC) { if (!aC->ValidTarget(ga_flags)) { return NULL; } return ReturnScriptableAsTarget(aC); } Door *door = map->GetDoorByGlobalID( (ieDword) oC->objectFields[1]); if (door) { return ReturnScriptableAsTarget(door); } Container* cont = map->GetContainerByGlobalID((ieDword) oC->objectFields[1]); if (cont) { return ReturnScriptableAsTarget(cont); } InfoPoint* trap = map->GetInfoPointByGlobalID((ieDword) oC->objectFields[1]); if (trap) { return ReturnScriptableAsTarget(trap); } return NULL; } Targets *tgts = NULL; //we need to get a subset of actors from the large array //if this gets slow, we will need some index tables int i = map->GetActorCount(true); while (i--) { Actor *ac = map->GetActor(i, true); if (!ac) continue; // is this check really needed? // don't return Sender in IDS targeting! // unless it's pst, which relies on it in 3012cut2-3012cut7.bcs // FIXME: do we need more fine-grained control? // FIXME: stop abusing old GF flags if (!core->HasFeature(GF_AREA_OVERRIDE)) { if (ac == Sender) continue; } bool filtered = false; if (DoObjectIDSCheck(oC, ac, &filtered)) { // this is needed so eg. Range trigger gets a good object // HACK: our parsing of Attack([0]) is broken if (!filtered) { // if no filters were applied.. assert(!tgts); return NULL; } int dist; if (DoObjectChecks(map, Sender, ac, dist, (ga_flags & GA_DETECT) != 0)) { if (!tgts) tgts = new Targets(); tgts->AddTarget((Scriptable *) ac, dist, ga_flags); } } } return tgts; }
void ExitPoint::collide(Actor& otherActor) { if (otherActor.isPlayer()) { printf("You are victorious! (But we don't have a victory UI.)\n"); } }
void ObjectWidget::QueryState(TESObjectREFR * reference, bool * isVisible, bool * isFriendly) { bool isHidden = false; bool isHostileToActor = false; bool isHostile = false; UInt8 unk1 = 0; if((flags & kFlag_UseLineOfSight) == kFlag_UseLineOfSight) isHidden = !HasLOS((*g_thePlayer), reference, &unk1); Actor * actor = DYNAMIC_CAST(reference, TESObjectREFR, Actor); if(actor) { if ((flags & kFlag_UpdatePercent) == kFlag_UpdatePercent) { // Get values from Tes5Mod Actor Value Indices. // http://www.uesp.net/wiki/Tes5Mod:Actor_Value_Indices params[kProperty_HealthCurrentValue].SetNumber(actor->actorValueOwner.GetCurrent(24)); params[kProperty_HealthMaximumValue].SetNumber(actor->actorValueOwner.GetMaximum(24)); params[kProperty_MagickaCurrentValue].SetNumber(actor->actorValueOwner.GetCurrent(25)); params[kProperty_MagickaMaximumValue].SetNumber(actor->actorValueOwner.GetMaximum(25)); params[kProperty_StaminaCurrentValue].SetNumber(actor->actorValueOwner.GetCurrent(26)); params[kProperty_StaminaMaximumValue].SetNumber(actor->actorValueOwner.GetMaximum(26)); // Checks if at health is at 100%+ and hides if true. double percent = params[kProperty_HealthCurrentValue].GetNumber() / params[kProperty_HealthMaximumValue].GetNumber(); if (percent >= 1.0 && (g_hudExtension->hudFlags & HUDExtension::kFlags_HideAtFull) == HUDExtension::kFlags_HideAtFull) isHidden = true; } if((flags & kFlag_ShowInCombat) == kFlag_ShowInCombat) if(actor->IsInCombat()) isHidden = !isHidden; if((flags & kFlag_HideOutOfCombat) == kFlag_HideOutOfCombat) // When these are not flagged, hide instead if(!actor->IsInCombat()) isHidden = true; if((flags & kFlag_HideOnDeath) == kFlag_HideOnDeath) if(actor->IsDead(1)) isHidden = true; if ((flags & kFlag_HideOnInvisibility) == kFlag_HideOnInvisibility) if (actor->actorValueOwner.GetCurrent(54) > 0) isHidden = true; if ((flags & kFlag_UseHostility) == kFlag_UseHostility || g_hudExtension->hudFlags != HUDExtension::kFlags_None) { isHostileToActor = CALL_MEMBER_FN(*g_thePlayer, IsHostileToActor)(actor); if ((flags & kFlag_UseHostility) == kFlag_UseHostility) isHostile = isHostileToActor; } if (g_hudExtension->hudFlags != HUDExtension::kFlags_None) { if (isHostileToActor && (g_hudExtension->hudFlags & HUDExtension::kFlags_HideEnemies) == HUDExtension::kFlags_HideEnemies) isHidden = true; else if (!isHostileToActor) { SInt32 relationshipRank = RelationshipRanks::GetRelationshipRank(actor->baseForm, (*g_thePlayer)->baseForm); if ((g_hudExtension->hudFlags & HUDExtension::kFlags_HideAllies) == HUDExtension::kFlags_HideAllies && relationshipRank >= 3) isHidden = true; if ((g_hudExtension->hudFlags & HUDExtension::kFlags_HideFriendly) == HUDExtension::kFlags_HideFriendly && relationshipRank >= 1 && relationshipRank < 3) isHidden = true; if ((g_hudExtension->hudFlags & HUDExtension::kFlags_HideNonHostile) == HUDExtension::kFlags_HideNonHostile && relationshipRank < 1) isHidden = true; } } } *isVisible = !isHidden; *isFriendly = !isHostile; }
int UtcDaliScriptingNewActorProperties(void) { TestApplication application; Property::Map map; map[ "type" ] = "Actor"; map[ "size" ] = Vector3::ONE; map[ "position" ] = Vector3::XAXIS; map[ "scale" ] = Vector3::ONE; map[ "visible" ] = false; map[ "color" ] = Color::MAGENTA; map[ "name" ] = "MyActor"; map[ "color-mode" ] = "USE_PARENT_COLOR"; map[ "inherit-shader-effect" ] = false; map[ "sensitive" ] = false; map[ "leave-required" ] = true; map[ "position-inheritance" ] = "DONT_INHERIT_POSITION"; map[ "draw-mode" ] = "STENCIL"; map[ "inherit-orientation" ] = false; map[ "inherit-scale" ] = false; // Default properties { Actor handle = NewActor( map ); DALI_TEST_CHECK( handle ); Stage::GetCurrent().Add( handle ); application.SendNotification(); application.Render(); DALI_TEST_EQUALS( handle.GetCurrentSize(), Vector3::ONE, TEST_LOCATION ); DALI_TEST_EQUALS( handle.GetCurrentPosition(), Vector3::XAXIS, TEST_LOCATION ); DALI_TEST_EQUALS( handle.GetCurrentScale(), Vector3::ONE, TEST_LOCATION ); DALI_TEST_EQUALS( handle.IsVisible(), false, TEST_LOCATION ); DALI_TEST_EQUALS( handle.GetCurrentColor(), Color::MAGENTA, TEST_LOCATION ); DALI_TEST_EQUALS( handle.GetName(), "MyActor", TEST_LOCATION ); DALI_TEST_EQUALS( handle.GetColorMode(), USE_PARENT_COLOR, TEST_LOCATION ); DALI_TEST_EQUALS( handle.IsSensitive(), false, TEST_LOCATION ); DALI_TEST_EQUALS( handle.GetLeaveRequired(), true, TEST_LOCATION ); DALI_TEST_EQUALS( handle.GetPositionInheritanceMode(), DONT_INHERIT_POSITION, TEST_LOCATION ); DALI_TEST_EQUALS( handle.GetDrawMode(), DrawMode::STENCIL, TEST_LOCATION ); DALI_TEST_EQUALS( handle.IsOrientationInherited(), false, TEST_LOCATION ); DALI_TEST_EQUALS( handle.IsScaleInherited(), false, TEST_LOCATION ); Stage::GetCurrent().Remove( handle ); } // Check Anchor point and parent origin vector3s map[ "parent-origin" ] = ParentOrigin::TOP_CENTER; map[ "anchor-point" ] = AnchorPoint::TOP_LEFT; { Actor handle = NewActor( map ); DALI_TEST_CHECK( handle ); Stage::GetCurrent().Add( handle ); application.SendNotification(); application.Render(); DALI_TEST_EQUALS( handle.GetCurrentParentOrigin(), ParentOrigin::TOP_CENTER, TEST_LOCATION ); DALI_TEST_EQUALS( handle.GetCurrentAnchorPoint(), AnchorPoint::TOP_LEFT, TEST_LOCATION ); Stage::GetCurrent().Remove( handle ); } // Check Anchor point and parent origin STRINGS map[ "parent-origin" ] = "TOP_LEFT"; map[ "anchor-point" ] = "CENTER_LEFT"; { Actor handle = NewActor( map ); DALI_TEST_CHECK( handle ); Stage::GetCurrent().Add( handle ); application.SendNotification(); application.Render(); DALI_TEST_EQUALS( handle.GetCurrentParentOrigin(), ParentOrigin::TOP_LEFT, TEST_LOCATION ); DALI_TEST_EQUALS( handle.GetCurrentAnchorPoint(), AnchorPoint::CENTER_LEFT, TEST_LOCATION ); Stage::GetCurrent().Remove( handle ); } END_TEST; }
void Grafkit::SceneLoader::SceneLoaderHelper::Load(Archive &ar, IResourceManager * const & resman) { Persist(ar, resman); LOGGER(Log::Logger().Info("-- ASSIGN --")); // 5. material -> mesh relation LOGGER(Log::Logger().Info("Materials: %d", m_materials_to_meshes.size())); for (auto it = m_materials_to_meshes.begin(); it != m_materials_to_meshes.end(); ++it) { USHORT key = it->first; USHORT val = it->second; Material * material = m_materials[key]; Model *model = dynamic_cast<Model *>(m_entities[val]); if (model && material) { model->SetMaterial(material); LOGGER(Log::Logger().Info("%hu (\"%s\") -> %hu (\"%s\")", key, material->GetName().c_str(), val, model->GetName().c_str())); } } // ... // 6. entitiy -> actor relation LOGGER(Log::Logger().Info("Entities: %d", m_entities_to_actors.size())); for (auto it = m_entities_to_actors.begin(); it != m_entities_to_actors.end(); ++it) { USHORT key = it->first; USHORT val = it->second; Entity3D *entity = m_entities[key]; Actor *actor = m_actors[val]; if (actor && entity) { actor->AddEntity(entity); LOGGER(Log::Logger().Info("%hu (\"%s\") -> %hu (\"%s\")", key, entity->GetName().c_str()), val, actor->GetName().c_str()); } } // ... // 7. actor -> actor relation - scenegraph LOGGER(Log::Logger().Info("Actors: %d", m_actor_to_actor.size())); for (auto it = m_actor_to_actor.begin(); it != m_actor_to_actor.end(); ++it) { USHORT key = it->first; USHORT val = it->second; Actor *child = m_actors[val]; Actor *parent = m_actors[key]; if (parent && child) { parent->AddChild(child); LOGGER(Log::Logger().Info("%hu (\"%s\") -> %hu (\"%s\")", key, parent->GetName().c_str(), val, child->GetName().c_str())); } } //8, 9 animation -> actor, entity LOGGER(Log::Logger().Info("Animations: %d", m_animation_to_actor.size() + m_animation_to_entity.size())); for (auto it = m_animation_to_actor.cbegin(); it != m_animation_to_actor.cend(); ++it) { USHORT key = it->first; USHORT value = it->second; ActorAnimation *actor_animation = dynamic_cast<ActorAnimation *>(m_Animations[key]); if (actor_animation) { Actor* actor = m_actors[value]; if (actor) { actor_animation->SetActor(ActorRef(actor)); m_scene->AddAnimation(actor_animation); LOGGER(Log::Logger().Info("Actor %hu (\"%s\") -> %hu (\"%s\")", key, actor->GetName().c_str(), value, actor_animation->GetName().c_str())); } } } for (auto it = m_animation_to_entity.cbegin(); it != m_animation_to_entity.cend(); ++it) { USHORT key = it->first; USHORT value = it->second; EntityAnimation *entity_animation = dynamic_cast<EntityAnimation*>(m_Animations[key]); if (entity_animation) { Entity3D* entity = m_entities[value]; if (entity) { entity_animation->SetEntity(Ref<Entity3D>(entity)); m_scene->AddAnimation(entity_animation); LOGGER(Log::Logger().Info("Entity %hu -> %hu", key, value)); } } } if (m_actors.empty()) throw new EX_DETAILS(SceneLoadException, "Actors are empty for some reason"); Actor * root = m_actors[0]; m_scene->Initialize(root); }
/// Step forward the simulation void Box2DSystem::update(const Time& deltaTime) { mSimulation->Step(deltaTime.seconds(), 8, 8); // Compute stuff with the world ComponentManager* colliderBoxManager = mWorld->getComponentManager<CColliderBox>(); ComponentManager* transformManager = mWorld->getComponentManager<CTransform>(); for (std::size_t i = 0; i < colliderBoxManager->getInstanceCount(); ++i) { CColliderBox* boxCollider = (CColliderBox*)colliderBoxManager->getInstance(i); CTransform* transform = (CTransform*)transformManager->getComponentFromEntity(colliderBoxManager->getInstanceEntity(i)); if (!transform) { mWorld->createComponent(CTransform(), colliderBoxManager->getInstanceEntity(i)); transform = (CTransform*)transformManager->getComponentFromEntity(colliderBoxManager->getInstanceEntity(i)); } if (!boxCollider->userData) { b2BodyDef groundBodyDef2; groundBodyDef2.type = boxCollider->_isDynamic ? b2_dynamicBody : b2_staticBody; groundBodyDef2.position = b2Vec2(transform->getPosition().x, transform->getPosition().y); b2Body* groundBody2 = mSimulation->CreateBody(&groundBodyDef2); b2PolygonShape groundShape2; groundShape2.SetAsBox(10.f, 10.f); groundBody2->CreateFixture(&groundShape2, 1.f); groundBody2->SetUserData(boxCollider); boxCollider->userData = groundBody2; } else { b2Body* boxColliderBody = (b2Body*)boxCollider->userData; transform->position.x = boxColliderBody->GetPosition().x; transform->position.y = boxColliderBody->GetPosition().y; transform->rotation = Quaternion::fromMatrix(mat4::rotatez(boxColliderBody->GetAngle())); } } // Now let's go through the actors to find stuff in them for (std::size_t i = 0; i < mWorld->actors.size(); ++i) { Actor* actor = mWorld->actors[i]; SCColliderBox* box = dynamic_cast<SCColliderBox*>(actor->getRootComponent()); if (box) { if (!box->userData) { b2BodyDef groundBodyDef2; groundBodyDef2.type = box->_isDynamic ? b2_dynamicBody : b2_staticBody; groundBodyDef2.position = b2Vec2(actor->getActorLocation().x, actor->getActorLocation().y); b2Body* groundBody2 = mSimulation->CreateBody(&groundBodyDef2); b2PolygonShape groundShape2; groundShape2.SetAsBox(10.f, 10.f); groundBody2->CreateFixture(&groundShape2, 1.f); groundBody2->SetUserData(box); box->userData = groundBody2; box->rigidBody = new RigidBodyBox2D(groundBody2); } // Apply manual forces b2Body* boxColliderBody = (b2Body*)box->userData; CTransform transform = box->t; transform.position.x = boxColliderBody->GetPosition().x; transform.position.y = boxColliderBody->GetPosition().y; transform.rotation = Quaternion::fromMatrix(mat4::rotatez(boxColliderBody->GetAngle())); // Push the new physics transform back to the actor actor->setTransform(transform); } } }
int UtcDaliFocusManagerFocusGroup(void) { ToolkitTestApplication application; tet_infoline(" UtcDaliFocusManagerFocusGroup"); FocusManager manager = FocusManager::Get(); DALI_TEST_CHECK(manager); // Create an actor with two child actors and add it to the stage Actor parent = Actor::New(); Actor firstChild = Actor::New(); Actor secondChild = Actor::New(); parent.Add(firstChild); parent.Add(secondChild); Stage::GetCurrent().Add(parent); // Create three actors and add them as the children of the first child actor Actor firstGrandChild = Actor::New(); Actor secondGrandChild = Actor::New(); Actor thirdGrandChild = Actor::New(); firstChild.Add(firstGrandChild); firstChild.Add(secondGrandChild); firstChild.Add(thirdGrandChild); // Set focus order to the actors manager.SetFocusOrder(parent, 1); manager.SetFocusOrder(firstChild, 2); manager.SetFocusOrder(firstGrandChild, 3); manager.SetFocusOrder(secondGrandChild, 4); manager.SetFocusOrder(thirdGrandChild, 5); manager.SetFocusOrder(secondChild, 6); // Set the parent and the first child actor as focus groups manager.SetFocusGroup(parent, true); DALI_TEST_CHECK(manager.IsFocusGroup(parent) == true); // The focus group of the parent should be itself, as it is set to be a focus group. DALI_TEST_CHECK(manager.GetFocusGroup(parent) == parent); // The focus group of the firstChild should be its parent, as it is the immediate parent which is also a group. DALI_TEST_CHECK(manager.GetFocusGroup(firstChild) == parent); manager.SetFocusGroup(firstChild, true); DALI_TEST_CHECK(manager.IsFocusGroup(firstChild) == true); // The focus group of the firstChild should be itself, as it is set to be a focus group now. DALI_TEST_CHECK(manager.GetFocusGroup(firstChild) == firstChild); // Enable wrap mode for focus movement. manager.SetWrapMode(true); DALI_TEST_CHECK(manager.GetWrapMode() == true); // Check that no actor is being focused yet. DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor()); // Check that the focus is set on the parent actor. DALI_TEST_CHECK(manager.SetCurrentFocusActor(parent) == true); DALI_TEST_CHECK(manager.GetCurrentFocusActor() == parent); // Check that group mode is disabled. DALI_TEST_CHECK(manager.GetGroupMode() == false); // Check that the focus movement is wrapped as normal. DALI_TEST_CHECK(manager.MoveFocusForward() == true); DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstChild); DALI_TEST_CHECK(manager.MoveFocusForward() == true); DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstGrandChild); DALI_TEST_CHECK(manager.MoveFocusForward() == true); DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondGrandChild); DALI_TEST_CHECK(manager.MoveFocusForward() == true); DALI_TEST_CHECK(manager.GetCurrentFocusActor() == thirdGrandChild); DALI_TEST_CHECK(manager.MoveFocusForward() == true); DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondChild); DALI_TEST_CHECK(manager.MoveFocusForward() == true); DALI_TEST_CHECK(manager.GetCurrentFocusActor() == parent); DALI_TEST_CHECK(manager.MoveFocusForward() == true); DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstChild); DALI_TEST_CHECK(manager.MoveFocusForward() == true); DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstGrandChild); // Enable the group mode. manager.SetGroupMode(true); DALI_TEST_CHECK(manager.GetGroupMode() == true); // Check that the focus movement is now limited to the current focus group. DALI_TEST_CHECK(manager.MoveFocusForward() == true); DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondGrandChild); DALI_TEST_CHECK(manager.MoveFocusForward() == true); DALI_TEST_CHECK(manager.GetCurrentFocusActor() == thirdGrandChild); DALI_TEST_CHECK(manager.MoveFocusForward() == true); DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstChild); DALI_TEST_CHECK(manager.MoveFocusForward() == true); DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstGrandChild); END_TEST; }
void BattleManager::implementAction(Action theAction) { Actor *movingActor; Actor *target; if(whoseTurn == 1) { movingActor = first; target = second; if(firstActorExtraDefense > 0) { //Defending wears off. first->setDefense(first->getCurrentDefense() - firstActorExtraDefense); firstActorExtraDefense = 0; } } else { movingActor = second; target = first; if(secondActorExtraDefense > 0) { //Defending wears off. second->setDefense(second->getCurrentDefense() - secondActorExtraDefense); secondActorExtraDefense = 0; } } //Only permit action if there's enough MP to do the action - otherwise do nothing. if(movingActor->getCurrentMP() >= theAction.magicCost) { movingActor->setMP(movingActor->getCurrentMP() - theAction.magicCost); if(theAction.theType == DAMAGE) { int damageAmount = theAction.data - target->getCurrentDefense(); if(damageAmount > 0) { target->setHealth(target->getCurrentHealth() - damageAmount); } } else if(theAction.theType == DEFEND) { int oldDefense = movingActor->getCurrentDefense(); movingActor->setDefense(oldDefense + theAction.data); if(whoseTurn == 1) { firstActorExtraDefense = theAction.data; } else { secondActorExtraDefense = theAction.data; } } else if(theAction.theType == HEAL) { //Cap healing at max HP. movingActor->setHealth(movingActor->getCurrentHealth() + theAction.data); if(movingActor->getCurrentHealth() > movingActor->getMaxHealth()) { movingActor->setHealth(movingActor->getMaxHealth()); } } else { //other things, like charging mana, taunting, etc. } } else { //some sort of "out of magic" error } //Finished implementing action: change whose turn it is. if(whoseTurn == 1) { whoseTurn = 2; } else { whoseTurn = 1; } }
int UtcDaliFocusManagerGetCurrentFocusGroup(void) { ToolkitTestApplication application; tet_infoline(" UtcDaliFocusManagerGetCurrentFocusGroup"); FocusManager manager = FocusManager::Get(); DALI_TEST_CHECK(manager); // Create an actor with two child actors and add it to the stage Actor parent = Actor::New(); Actor firstChild = Actor::New(); Actor secondChild = Actor::New(); parent.Add(firstChild); parent.Add(secondChild); Stage::GetCurrent().Add(parent); // Create three actors and add them as the children of the first child actor Actor firstGrandChild = Actor::New(); Actor secondGrandChild = Actor::New(); Actor thirdGrandChild = Actor::New(); firstChild.Add(firstGrandChild); firstChild.Add(secondGrandChild); firstChild.Add(thirdGrandChild); // Set focus order to the actors manager.SetFocusOrder(parent, 1); manager.SetFocusOrder(firstChild, 2); manager.SetFocusOrder(firstGrandChild, 3); manager.SetFocusOrder(secondGrandChild, 4); manager.SetFocusOrder(thirdGrandChild, 5); manager.SetFocusOrder(secondChild, 6); // Set the parent and the first child actor as focus groups manager.SetFocusGroup(parent, true); DALI_TEST_CHECK(manager.IsFocusGroup(parent) == true); // Set focus to the first grand child actor DALI_TEST_CHECK(manager.SetCurrentFocusActor(firstGrandChild) == true); DALI_TEST_CHECK(manager.GetCurrentFocusActor() == firstGrandChild); // The current focus group should be the parent, As it is the immediate parent which is also a focus group. DALI_TEST_CHECK(manager.GetCurrentFocusGroup() == parent); manager.SetFocusGroup(firstChild, true); DALI_TEST_CHECK(manager.IsFocusGroup(firstChild) == true); // The current focus group should be the firstChild, As it is the immediate parent which is also a focus group. DALI_TEST_CHECK(manager.GetCurrentFocusGroup() == firstChild); manager.SetFocusGroup(firstGrandChild, true); DALI_TEST_CHECK(manager.IsFocusGroup(firstGrandChild) == true); // The current focus group should be itself, As it is also a focus group. DALI_TEST_CHECK(manager.GetCurrentFocusGroup() == firstGrandChild); // Set focus to the second grand child actor DALI_TEST_CHECK(manager.SetCurrentFocusActor(secondGrandChild) == true); DALI_TEST_CHECK(manager.GetCurrentFocusActor() == secondGrandChild); // The current focus group should be the firstChild, As it is the immediate parent which is also a // focus group for the current focus actor. DALI_TEST_CHECK(manager.GetCurrentFocusGroup() == firstChild); END_TEST; }
int UtcDaliFocusManagerMoveFocusBackward(void) { ToolkitTestApplication application; tet_infoline(" UtcDaliFocusManagerMoveFocusBackward"); FocusManager manager = FocusManager::Get(); DALI_TEST_CHECK(manager); Actor first = Actor::New(); Stage::GetCurrent().Add(first); Actor second = Actor::New(); Stage::GetCurrent().Add(second); Actor third = Actor::New(); Stage::GetCurrent().Add(third); // Set the focus order and description for the first actor manager.SetFocusOrder(first, 1); manager.SetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL, "first"); DALI_TEST_CHECK(manager.GetFocusOrder(first) == 1); DALI_TEST_CHECK(manager.GetAccessibilityAttribute(first, FocusManager::ACCESSIBILITY_LABEL) == "first"); // Set the focus order and description for the second actor manager.SetFocusOrder(second, 2); manager.SetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL, "second"); DALI_TEST_CHECK(manager.GetFocusOrder(second) == 2); DALI_TEST_CHECK(manager.GetAccessibilityAttribute(second, FocusManager::ACCESSIBILITY_LABEL) == "second"); // Set the focus order and description for the second actor manager.SetFocusOrder(third, 3); manager.SetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL, "third"); DALI_TEST_CHECK(manager.GetFocusOrder(third) == 3); DALI_TEST_CHECK(manager.GetAccessibilityAttribute(third, FocusManager::ACCESSIBILITY_LABEL) == "third"); // Check that no actor is being focused yet. DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor()); // Set the focus on the third actor DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true); DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third); DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third"); // Test the non-wrapped move first manager.SetWrapMode(false); DALI_TEST_CHECK(manager.GetWrapMode() == false); // Move the focus backward to the second actor manager.MoveFocusBackward(); DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second); DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "second"); // Move the focus backward to the first actor manager.MoveFocusBackward(); DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first); DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first"); // Check that it will fail to move the focus backward again as the first actor is the first // focusable actor in the focus chain manager.MoveFocusBackward(); // The focus should still be set on the first actor DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first); DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first"); // Now test the wrapped move manager.SetWrapMode(true); DALI_TEST_CHECK(manager.GetWrapMode() == true); // Move the focus backward recursively and this time the third actor should be focused manager.MoveFocusBackward(); DALI_TEST_CHECK(manager.GetCurrentFocusActor() == third); DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "third"); // Make the second actor not focusable Property::Index propertyActorFocusable = second.GetPropertyIndex("focusable"); second.SetProperty(propertyActorFocusable, false); // flush the queue and render once application.SendNotification(); application.Render(); // Move the focus backward and check that the second actor should be skipped and // the first actor should be focused now. manager.MoveFocusBackward(); DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first); DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first"); // Make the third actor invisible third.SetVisible(false); // flush the queue and render once application.SendNotification(); application.Render(); // Move the focus backward and check that the third actor should be skipped as it's // invisible and the second actor should also be skipped as it's not focusable, // so the focus will still be on the first actor manager.MoveFocusBackward(); DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first); DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first"); // Make the first actor invisible so that no actor can be focused. first.SetVisible(false); // flush the queue and render once application.SendNotification(); application.Render(); // Check that the focus move is failed as all the three actors can not be focused manager.MoveFocusBackward(); DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first); DALI_TEST_CHECK(manager.GetAccessibilityAttribute(manager.GetCurrentFocusActor(), FocusManager::ACCESSIBILITY_LABEL) == "first"); END_TEST; }
int UtcDaliFocusManagerSetAndGetCurrentFocusActor(void) { ToolkitTestApplication application; tet_infoline(" UtcDaliFocusManagerSetAndGetCurrentFocusActor"); FocusManager manager = FocusManager::Get(); DALI_TEST_CHECK(manager); // Create the first actor and add it to the stage Actor first = Actor::New(); manager.SetFocusOrder(first, 1); Stage::GetCurrent().Add(first); // Create the second actor and add it to the stage Actor second = Actor::New(); manager.SetFocusOrder(second, 2); Stage::GetCurrent().Add(second); // Create the third actor but don't add it to the stage Actor third = Actor::New(); manager.SetFocusOrder(third, 3); // Check that no actor is being focused yet. DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor()); // Check that it will fail to set focus on an invalid actor DALI_TEST_CHECK(manager.SetCurrentFocusActor(Actor()) == false); // Check that the focus is set on the first actor DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true); DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first); // Check that the focus is set on the second actor DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true); DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second); // Check that it will fail to set focus on the third actor as it's not in the stage DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false); // Add the third actor to the stage Stage::GetCurrent().Add(third); // make the third actor invisible third.SetVisible(false); // flush the queue and render once application.SendNotification(); application.Render(); // Check that it will fail to set focus on the third actor as it's invisible DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false); // Make the third actor visible third.SetVisible(true); // flush the queue and render once application.SendNotification(); application.Render(); // Make the third actor not focusable Property::Index propertyActorFocusable = third.GetPropertyIndex("focusable"); third.SetProperty(propertyActorFocusable, false); // flush the queue and render once application.SendNotification(); application.Render(); // Check that it will fail to set focus on the third actor as it's not focusable DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == false); // Make the third actor focusable third.SetProperty(propertyActorFocusable, true); // flush the queue and render once application.SendNotification(); application.Render(); // Check that the focus is successfully moved to the third actor DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true); // Make the current focused actor to be not focusable by setting its focus order to be 0 manager.SetFocusOrder(third, 0); // Check that the focus is automatically cleared DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor()); // Set the focus order of the third actor again manager.SetFocusOrder(third, 3); // Check that the third actor can be focused successfully now DALI_TEST_CHECK(manager.SetCurrentFocusActor(third) == true); END_TEST; }
/* virtual */ void Attack::operator()() { if (fObject == NULL) std::cerr << "NULL OBJECT" << std::endl; Actor* actor = dynamic_cast<Actor*>(fObject); if (actor == NULL) return; Actor* target = dynamic_cast<Actor*>(Script::FindTargetObject(fObject, fActionParams)); if (target == NULL){ SetCompleted(); return; } if (!Initiated()) { IE::point point = target->NearestPoint(actor->Position()); if (!PointSufficientlyClose(actor->Position(), point)) actor->SetDestination(point); SetInitiated(); } if (actor->Position() != actor->Destination()) { actor->SetAnimationAction(ACT_WALKING); actor->MoveToNextPointInPath(actor->IsFlying()); } else { actor->SetAnimationAction(ACT_ATTACKING); actor->AttackTarget(target); SetCompleted(); } }
void NoteDisplay::DrawHoldHead( const TapNote& tn, int iCol, int iRow, bool bIsBeingHeld, float fYHead, float fPercentFadeToFail, float fColorScale, bool bGlow, float fYStartOffset, float fYEndOffset ) { // // Draw the head // Actor* pActor = GetHoldHeadActor( NoteRowToBeat(iRow), tn.subType == TapNote::hold_head_roll, bIsBeingHeld ); pActor->SetZoom( ArrowEffects::GetZoom( m_pPlayerState ) ); // draw with normal Sprite const float fY = fYHead; const float fYOffset = ArrowEffects::GetYOffsetFromYPos( m_pPlayerState, iCol, fY, m_fYReverseOffsetPixels ); if( fYOffset < fYStartOffset || fYOffset > fYEndOffset ) return; // TRICKY: skew the rotation by a few pixels so this lines up with the start of the twirly hold. const float fRotationY = ArrowEffects::GetRotationY( m_pPlayerState, fYOffset+16 ); const float fX = ArrowEffects::GetXPos( m_pPlayerState, iCol, fYOffset ); const float fZ = ArrowEffects::GetZPos( m_pPlayerState, iCol, fYOffset ); const float fAlpha = ArrowEffects::GetAlpha( m_pPlayerState, iCol, fYOffset, fPercentFadeToFail, m_fYReverseOffsetPixels ); const float fGlow = ArrowEffects::GetGlow( m_pPlayerState, iCol, fYOffset, fPercentFadeToFail, m_fYReverseOffsetPixels ); const RageColor colorDiffuse= RageColor(fColorScale,fColorScale,fColorScale,fAlpha); const RageColor colorGlow = RageColor(1,1,1,fGlow); pActor->SetRotationY( fRotationY ); pActor->SetRotationZ( 0 ); pActor->SetXY( fX, fY ); pActor->SetZ( fZ ); if( bGlow ) { pActor->SetDiffuse( RageColor(1,1,1,0) ); pActor->SetGlow( colorGlow ); } else { pActor->SetDiffuse( colorDiffuse ); pActor->SetGlow( RageColor(0,0,0,0) ); } if( cache->m_bHoldHeadUseLighting ) { DISPLAY->SetLighting( true ); DISPLAY->SetLightDirectional( 0, RageColor(1,1,1,1), RageColor(1,1,1,1), RageColor(1,1,1,1), RageVector3(1, 0, +1) ); } pActor->Draw(); if( cache->m_bHoldHeadUseLighting ) { DISPLAY->SetLightOff( 0 ); DISPLAY->SetLighting( false ); } }
/*********************************************************** update with external info ***********************************************************/ void ExternalPlayer::UpdateGhost(const LbaNet::GhostActorInfo & ainfo) { std::map<int, Actor *>::iterator it = _ghosts.find(ainfo.GhostId); if(it == _ghosts.end()) { //create new actor Actor * tmp = new Actor(0.6); tmp->SetRenderer(DataLoader ::getInstance()->CreateSpriteRenderer(ainfo.SpriteId)); tmp->SetPosition(ainfo.X, ainfo.Y, ainfo.Z); tmp->SetRotation(ainfo.Rotation); // add missing attached for(size_t i=0; i<ainfo.AttachedToActors.size(); ++i) ThreadSafeWorkpile::getInstance()->AddEvent(new AttachActorToActorEvent(_renderer, ainfo.AttachedToActors[i])); if(ainfo.AttachedToPlayer) _renderer->Attach(tmp); _ghosts[ainfo.GhostId] = tmp; } else { //update existing actor Actor * tmp = it->second; tmp->SetPosition(ainfo.X, ainfo.Y, ainfo.Z); tmp->SetRotation(ainfo.Rotation); const std::vector<Actor *> & attachingacts = tmp->GetAttaching(); // add missing attached for(size_t i=0; i<ainfo.AttachedToActors.size(); ++i) { bool found = false; for(size_t j=0; j<attachingacts.size(); ++j) { if( attachingacts[j]->GetId() == ainfo.AttachedToActors[i]) { found = true; break; } } if(!found) ThreadSafeWorkpile::getInstance()->AddEvent(new AttachActorToActorEvent(tmp, ainfo.AttachedToActors[i])); } // remove old attached for(size_t j=0; j<attachingacts.size(); ++j) { bool found = false; for(size_t i=0; i<ainfo.AttachedToActors.size(); ++i) { if( attachingacts[j]->GetId() == ainfo.AttachedToActors[i]) { found = true; break; } } if(!found) tmp->RemoveAttaching(attachingacts[j]); } if(ainfo.AttachedToPlayer) _renderer->Attach(tmp); else _renderer->Dettach(tmp); } }
void RegionLoad::DefineActors() { //Creates a list with actors that intercept the region regionActors.Clear(); KrVector2T< GlFixed > screen, axis; Axis *pAxis = GameControl::Get()->GetAxis(); //Get region bounds (Solve the bug "Game behavior differ based on editor grid position when uses regions", ALPHA_1_1_4.ged) getImage()->CalcTransform(); KrRect rectRegion = getImage()->Bounds(); rectRegion.Translate(-rectRegion.xmin, -rectRegion.ymin); //To axis coordinate (Solve the bug "Game behavior differ based on editor grid position when uses regions", ALPHA_1_1_4.ged) getImage()->ObjectToScreen(0, 0, &screen); pAxis->getImage()->ScreenToObject( screen.x.ToInt(), screen.y.ToInt(), &axis ); rectRegion.Translate(axis.x.ToInt(), axis.y.ToInt()); MapActorIterator it(mapActors); for(it.Begin(); !it.Done(); it.Next()) { ListActor *listActor = it.Value(); for(int il = 0; il < listActor->Count(); il++) { Actor *actor = (*listActor)[il]; if( actor->EditMode() && !actor->isRegion() && !actor->isView() && actor != pAxis ) { //Get actor bounds (Solve the bug "Game behavior differ based on editor grid position when uses regions", ALPHA_1_1_4.ged, abuse2.ged) actor->getImage()->CalcCompositeTransform(); KrRect rectActor = actor->Bounds(); if(actor->getTextActor() && !rectActor.IsValid()) { //Solve the bug "Text actors aren't load after use the LoadGame function without Activation Regions" engine->Tree()->Walk(actor->getImage(), true, true); rectActor = actor->Bounds(); } if(actor->getTile() && !rectActor.IsValid()) { //Solve the bug "Text actors aren't load after use the LoadGame function without Activation Regions" engine->Tree()->Walk(actor->getImage(), true, true); rectActor = actor->Bounds(); } rectActor.Translate(-rectActor.xmin, -rectActor.ymin); //To axis coordinate (Solve the bug "Game behavior differ based on editor grid position when uses regions", ALPHA_1_1_4.ged, abuse2.ged) actor->getImage()->ObjectToScreen(0, 0, &screen); pAxis->getImage()->ScreenToObject( screen.x.ToInt(), screen.y.ToInt(), &axis ); rectActor.Translate(axis.x.ToInt(), axis.y.ToInt()); if(rectActor.IsValid() && rectRegion.Intersect(rectActor)) { regionActors.Add(actor->getCloneName(), 1); } } } } viewPosAnt.Set(-123, 456, 0, 0); bRegionInView = false; }
void GrimEngine::updateDisplayScene() { _doFlip = true; if (_mode == ENGINE_MODE_SMUSH) { if (g_smush->isPlaying()) { //_mode = ENGINE_MODE_NORMAL; ??? _movieTime = g_smush->getMovieTime(); if (g_smush->isUpdateNeeded()) { g_driver->prepareSmushFrame(g_smush->getWidth(), g_smush->getHeight(), g_smush->getDstPtr()); g_smush->clearUpdateNeeded(); } int frame = g_smush->getFrame(); if (frame > 0) { if (frame != _prevSmushFrame) { _prevSmushFrame = g_smush->getFrame(); g_driver->drawSmushFrame(g_smush->getX(), g_smush->getY()); if (_showFps) g_driver->drawEmergString(550, 25, _fps, Color(255, 255, 255)); } else _doFlip = false; } else g_driver->releaseSmushFrame(); } drawPrimitives(); } else if (_mode == ENGINE_MODE_NORMAL) { if (!_currScene) return; cameraPostChangeHandle(_currScene->setup()); g_driver->clearScreen(); _prevSmushFrame = 0; _currScene->drawBackground(); // Draw underlying scene components // Background objects are drawn underneath everything except the background // There are a bunch of these, especially in the tube-switcher room _currScene->drawBitmaps(ObjectState::OBJSTATE_BACKGROUND); // Underlay objects are just above the background _currScene->drawBitmaps(ObjectState::OBJSTATE_UNDERLAY); // State objects are drawn on top of other things, such as the flag // on Manny's message tube _currScene->drawBitmaps(ObjectState::OBJSTATE_STATE); // Play SMUSH Animations // This should occur on top of all underlying scene objects, // a good example is the tube switcher room where some state objects // need to render underneath the animation or you can't see what's going on // This should not occur on top of everything though or Manny gets covered // up when he's next to Glottis's service room if (g_smush->isPlaying()) { _movieTime = g_smush->getMovieTime(); if (g_smush->isUpdateNeeded()) { g_driver->prepareSmushFrame(g_smush->getWidth(), g_smush->getHeight(), g_smush->getDstPtr()); g_smush->clearUpdateNeeded(); } if (g_smush->getFrame() > 0) g_driver->drawSmushFrame(g_smush->getX(), g_smush->getY()); else g_driver->releaseSmushFrame(); } _currScene->setupCamera(); g_driver->set3DMode(); _currScene->setupLights(); // Update actor costumes & sets for (ActorListType::iterator i = _actors.begin(); i != _actors.end(); ++i) { Actor *a = *i; // Update the actor's costumes & chores g_currentUpdatedActor = *i; // Note that the actor need not be visible to update chores, for example: // when Manny has just brought Meche back he is offscreen several times // when he needs to perform certain chores if (a->inSet(_currScene->name())) a->update(); } g_currentUpdatedActor = NULL; // Draw actors for (ActorListType::iterator i = _actors.begin(); i != _actors.end(); ++i) { Actor *a = *i; if (a->inSet(_currScene->name()) && a->visible()) a->draw(); a->undraw(a->inSet(_currScene->name()) && a->visible()); } flagRefreshShadowMask(false); // Draw overlying scene components // The overlay objects should be drawn on top of everything else, // including 3D objects such as Manny and the message tube _currScene->drawBitmaps(ObjectState::OBJSTATE_OVERLAY); g_driver->storeDisplay(); drawPrimitives(); } else if (_mode == ENGINE_MODE_DRAW) { if (_refreshDrawNeeded) { handleUserPaint(); g_driver->flipBuffer(); } _refreshDrawNeeded = false; return; } }
int UtcDaliScriptingNewActorProperties(void) { TestApplication application; Property::Map map; map.push_back( Property::StringValuePair( "type", "Actor" ) ); map.push_back( Property::StringValuePair( "size", Vector3::ONE ) ); map.push_back( Property::StringValuePair( "position", Vector3::XAXIS ) ); map.push_back( Property::StringValuePair( "scale", Vector3::ONE ) ); map.push_back( Property::StringValuePair( "visible", false ) ); map.push_back( Property::StringValuePair( "color", Color::MAGENTA ) ); map.push_back( Property::StringValuePair( "name", "MyActor" ) ); map.push_back( Property::StringValuePair( "color-mode", "USE_PARENT_COLOR" ) ); map.push_back( Property::StringValuePair( "inherit-shader-effect", false ) ); map.push_back( Property::StringValuePair( "sensitive", false ) ); map.push_back( Property::StringValuePair( "leave-required", true ) ); map.push_back( Property::StringValuePair( "position-inheritance", "DONT_INHERIT_POSITION" ) ); map.push_back( Property::StringValuePair( "draw-mode", "STENCIL" ) ); map.push_back( Property::StringValuePair( "inherit-rotation", false ) ); map.push_back( Property::StringValuePair( "inherit-scale", false ) ); // Default properties { Actor handle = NewActor( map ); DALI_TEST_CHECK( handle ); Stage::GetCurrent().Add( handle ); application.SendNotification(); application.Render(); DALI_TEST_EQUALS( handle.GetCurrentSize(), Vector3::ONE, TEST_LOCATION ); DALI_TEST_EQUALS( handle.GetCurrentPosition(), Vector3::XAXIS, TEST_LOCATION ); DALI_TEST_EQUALS( handle.GetCurrentScale(), Vector3::ONE, TEST_LOCATION ); DALI_TEST_EQUALS( handle.IsVisible(), false, TEST_LOCATION ); DALI_TEST_EQUALS( handle.GetCurrentColor(), Color::MAGENTA, TEST_LOCATION ); DALI_TEST_EQUALS( handle.GetName(), "MyActor", TEST_LOCATION ); DALI_TEST_EQUALS( handle.GetColorMode(), USE_PARENT_COLOR, TEST_LOCATION ); DALI_TEST_EQUALS( handle.GetInheritShaderEffect(), false, TEST_LOCATION ); DALI_TEST_EQUALS( handle.IsSensitive(), false, TEST_LOCATION ); DALI_TEST_EQUALS( handle.GetLeaveRequired(), true, TEST_LOCATION ); DALI_TEST_EQUALS( handle.GetPositionInheritanceMode(), DONT_INHERIT_POSITION, TEST_LOCATION ); DALI_TEST_EQUALS( handle.GetDrawMode(), DrawMode::STENCIL, TEST_LOCATION ); DALI_TEST_EQUALS( handle.IsRotationInherited(), false, TEST_LOCATION ); DALI_TEST_EQUALS( handle.IsScaleInherited(), false, TEST_LOCATION ); Stage::GetCurrent().Remove( handle ); } // Check Anchor point and parent origin vector3s map.push_back( Property::StringValuePair( "parent-origin", ParentOrigin::TOP_CENTER ) ); map.push_back( Property::StringValuePair( "anchor-point", AnchorPoint::TOP_LEFT ) ); { Actor handle = NewActor( map ); DALI_TEST_CHECK( handle ); Stage::GetCurrent().Add( handle ); application.SendNotification(); application.Render(); DALI_TEST_EQUALS( handle.GetCurrentParentOrigin(), ParentOrigin::TOP_CENTER, TEST_LOCATION ); DALI_TEST_EQUALS( handle.GetCurrentAnchorPoint(), AnchorPoint::TOP_LEFT, TEST_LOCATION ); Stage::GetCurrent().Remove( handle ); } // Check Anchor point and parent origin STRINGS map.erase( map.end() - 2, map.end() ); // delete previously added parent origin and anchor point map.push_back( Property::StringValuePair( "parent-origin", "BACK_TOP_LEFT" ) ); map.push_back( Property::StringValuePair( "anchor-point", "FRONT_CENTER_LEFT" ) ); { Actor handle = NewActor( map ); DALI_TEST_CHECK( handle ); Stage::GetCurrent().Add( handle ); application.SendNotification(); application.Render(); DALI_TEST_EQUALS( handle.GetCurrentParentOrigin(), ParentOrigin::BACK_TOP_LEFT, TEST_LOCATION ); DALI_TEST_EQUALS( handle.GetCurrentAnchorPoint(), AnchorPoint::FRONT_CENTER_LEFT, TEST_LOCATION ); Stage::GetCurrent().Remove( handle ); } END_TEST; }
static void UtcDaliPushButtonInterruptEventWhenInsensitive() { ToolkitTestApplication application; tet_infoline(" UtcDaliPushButtonInterruptEventWhenInsensitive"); // * Creates an actor which contains a button. // * The size of the actor is bigger than the button. // * The button's boundary is contained in the actor's one. Actor actor = Actor::New(); TETButton tetButton= Toolkit::TETButton::New(); actor.SetName( "Actor" ); tetButton.SetName( "TETButton" ); actor.SetAnchorPoint( AnchorPoint::TOP_LEFT ); actor.SetParentOrigin( ParentOrigin::TOP_LEFT ); actor.SetPosition( 0, 0 ); actor.SetSize( 400, 800 ); tetButton.SetAnchorPoint( AnchorPoint::TOP_LEFT ); tetButton.SetParentOrigin( ParentOrigin::TOP_LEFT ); tetButton.SetPosition( 240, 400 ); tetButton.SetSize( 100, 100 ); actor.Add( tetButton ); Stage::GetCurrent().Add( actor ); // * Actor's touch event is connected to a callback function // and this callback function consumes the event. actor.TouchedSignal().Connect( &TestCallback ); // * Button's pressed signal is connected to a callback function // which also consumes the event. // * Changes the sensitiveness of the button to false. TETButtonPressed tetButtonPressed( actor, TETButtonPressed::SENSITIVENESS ); tetButton.PressedSignal().Connect( &tetButtonPressed, &TETButtonPressed::Callback ); // Initializes TET state. gOnTouchPointInterrupted = false; tetButton.SetSensitive( true ); Dali::Integration::TouchEvent event; // TET starts. // Test a down point inside the button which is also consumed by the actor, and an up point // consumed only by the actor. gOnTouchPointInterrupted should be true (Button receives an // interrupt event. application.SendNotification(); application.Render(); // A down event is sent inside the button's boundary. event = Dali::Integration::TouchEvent(); event.AddPoint( pointDownInside ); // flush the queue and render once application.SendNotification(); application.Render(); application.ProcessEvent( event ); // An up event is sent outside the button's boundary but inside the actor's one. event = Dali::Integration::TouchEvent(); event.AddPoint( pointUpOutside ); // flush the queue and render once application.SendNotification(); application.Render(); application.ProcessEvent( event ); DALI_TEST_CHECK( gOnTouchPointInterrupted ); // Test a down point inside the button which is also consumed by the actor, and a motion point // consumed only by the actor. gOnTouchPointInterrupted should be true (Button receives an // interrupt event. // Initializes TET state. gOnTouchPointInterrupted = false; actor.SetSensitive( true ); tetButton.SetSensitive( true ); application.SendNotification(); application.Render(); // A down event is sent inside the button's boundary. event = Dali::Integration::TouchEvent(); event.AddPoint( pointDownInside ); // flush the queue and render once application.SendNotification(); application.Render(); application.ProcessEvent( event ); // A motion event is sent outside the button's boundary but inside the actor's one. event = Dali::Integration::TouchEvent(); event.AddPoint( pointMotionOut ); // flush the queue and render once application.SendNotification(); application.Render(); application.ProcessEvent( event ); DALI_TEST_CHECK( gOnTouchPointInterrupted ); // Test a down point inside the button which is also consumed by the actor, and an up point // also inside the button and consumed by the actor. gOnTouchPointInterrupted should be false. // Initializes TET state. gOnTouchPointInterrupted = false; actor.SetSensitive( true ); tetButton.SetSensitive( true ); // A down event is sent inside the button's boundary. event = Dali::Integration::TouchEvent(); event.AddPoint( pointDownInside ); // flush the queue and render once application.SendNotification(); application.Render(); application.ProcessEvent( event ); actor.SetSensitive( true ); // An up event is sent inside the button's boundary. event = Dali::Integration::TouchEvent(); event.AddPoint( pointUpInside ); // flush the queue and render once application.SendNotification(); application.Render(); application.ProcessEvent( event ); DALI_TEST_CHECK( !gOnTouchPointInterrupted ); }
int UtcDaliScriptingNewActorChildren(void) { TestApplication application; Property::Map map; map.push_back( Property::StringValuePair( "type", "Actor" ) ); map.push_back( Property::StringValuePair( "position", Vector3::XAXIS ) ); Property::Map child1Map; child1Map.push_back( Property::StringValuePair( "type", "ImageActor" ) ); child1Map.push_back( Property::StringValuePair( "position", Vector3::YAXIS ) ); Property::Map child2Map; child2Map.push_back( Property::StringValuePair( "type", "TextActor" ) ); child2Map.push_back( Property::StringValuePair( "position", Vector3::ZAXIS ) ); Property::Map grandChildMap; grandChildMap.push_back( Property::StringValuePair( "type", "LightActor" ) ); grandChildMap.push_back( Property::StringValuePair( "position", Vector3::ONE ) ); // Add arrays to appropriate maps Property::Array grandChildArray; grandChildArray.push_back( grandChildMap ); Property::Array childArray; child1Map.push_back( Property::StringValuePair( "actors", grandChildArray ) ); childArray.push_back( child1Map ); childArray.push_back( child2Map ); map.push_back( Property::StringValuePair( "actors", childArray ) ); // Create Actor handle = NewActor( map ); DALI_TEST_CHECK( handle ); Stage::GetCurrent().Add( handle ); application.SendNotification(); application.Render(); DALI_TEST_EQUALS( handle.GetCurrentPosition(), Vector3::XAXIS, TEST_LOCATION ); DALI_TEST_EQUALS( handle.GetChildCount(), 2u, TEST_LOCATION ); Actor child1 = handle.GetChildAt(0); DALI_TEST_CHECK( child1 ); DALI_TEST_CHECK( ImageActor::DownCast( child1 ) ); DALI_TEST_EQUALS( child1.GetCurrentPosition(), Vector3::YAXIS, TEST_LOCATION ); DALI_TEST_EQUALS( child1.GetChildCount(), 1u, TEST_LOCATION ); Actor child2 = handle.GetChildAt(1); DALI_TEST_CHECK( child2 ); DALI_TEST_CHECK( TextActor::DownCast( child2 ) ); DALI_TEST_EQUALS( child2.GetCurrentPosition(), Vector3::ZAXIS, TEST_LOCATION ); DALI_TEST_EQUALS( child2.GetChildCount(), 0u, TEST_LOCATION ); Actor grandChild = child1.GetChildAt( 0 ); DALI_TEST_CHECK( grandChild ); DALI_TEST_CHECK( LightActor::DownCast( grandChild ) ); DALI_TEST_EQUALS( grandChild.GetCurrentPosition(), Vector3::ONE, TEST_LOCATION ); DALI_TEST_EQUALS( grandChild.GetChildCount(), 0u, TEST_LOCATION ); Stage::GetCurrent().Remove( handle ); END_TEST; }
int UtcDaliModelBuildAnimation01(void) { TestApplication application; TestPlatformAbstraction& platform = application.GetPlatform(); tet_infoline("Testing Dali::MeshActor::New()"); Dali::ModelData modelData = BuildTreeModel(); // Raise a request Model model = Model::New("Tree"); application.SendNotification(); application.Render(); Integration::ResourceRequest* request = platform.GetRequest(); // Return modelData if(request) { platform.SetResourceLoaded(request->GetId(), request->GetType()->id, Integration::ResourcePointer(&(modelData.GetBaseObject()))); } application.Render(); application.SendNotification(); Actor actor = ModelActorFactory::BuildActorTree(model, ""); // model should be loaded Stage::GetCurrent().Add(actor); DALI_TEST_CHECK(model.GetLoadingState() == ResourceLoadingSucceeded); DALI_TEST_CHECK(actor); DALI_TEST_CHECK(actor.GetName().compare("root") == 0); DALI_TEST_EQUALS(model.NumberOfAnimations(), static_cast<size_t>(1), TEST_LOCATION); unsigned int animIndex=0; bool found = model.FindAnimation("Anim1", animIndex); DALI_TEST_CHECK(found); Animation twigAnim = ModelActorFactory::BuildAnimation(model, actor, animIndex); DALI_TEST_CHECK(twigAnim); DALI_TEST_EQUALS(twigAnim.GetDuration(), 10.0f, 0.001, TEST_LOCATION); DALI_TEST_CHECK(twigAnim.GetDefaultAlphaFunction() == Dali::AlphaFunctions::Linear); Actor twigActor = actor.FindChildByName("twig"); DALI_TEST_CHECK(twigActor); // Start the animation twigAnim.Play(); float durationSeconds = 10.0f; bool signalReceived(false); AnimationFinishCheck finishCheck(signalReceived); twigAnim.FinishedSignal().Connect(&application, finishCheck); application.SendNotification(); application.Render(); finishCheck.CheckSignalNotReceived(); DALI_TEST_EQUALS( twigActor.GetCurrentPosition(), Vector3(2.0f, 1.0f, 0.0f), 0.01f, TEST_LOCATION ); application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 25% progress */); application.SendNotification(); DALI_TEST_EQUALS( twigActor.GetCurrentPosition(), Vector3(2.5f, 1.0f, 2.5f), 0.01f, TEST_LOCATION ); application.Render(static_cast<unsigned int>(durationSeconds*500.0f)/* 75% progress */); application.SendNotification(); DALI_TEST_EQUALS( twigActor.GetCurrentPosition(), Vector3(3.5f, 1.0f, 7.5f), 0.01f, TEST_LOCATION ); application.Render(static_cast<unsigned int>(durationSeconds*500.0f)/* Past Finished */); application.SendNotification(); DALI_TEST_EQUALS( twigActor.GetCurrentPosition(), Vector3(4.0f, 1.0f, 10.0f), 0.01f, TEST_LOCATION ); finishCheck.CheckSignalReceived(); END_TEST; }
/** * @brief Handles the end of a match * @param[in] team The winning team number * @param[in] nextmap Is there a follow-up map within the same match ? * @sa G_RunFrame * @sa CL_ParseResults */ static void G_MatchSendResults (int team, bool nextmap) { Edict* attacker = nullptr; Actor* actor = nullptr; /* Calculate new scores/skills for the soldiers. */ while ((actor = G_EdictsGetNextLivingActor(actor))) { if (!G_IsAI(actor)) G_UpdateCharacterExperience(actor); else if (actor->getTeam() == team) attacker = actor; } /* if aliens won, make sure every soldier that is not in the rescue zone dies */ if (team == TEAM_ALIEN) { actor = nullptr; while ((actor = G_EdictsGetNextLivingActor(actor))) if (actor->getTeam() != team && !actor->isInRescueZone()) { actor->HP = 0; G_ActorDieOrStun(actor, attacker); } } G_VisMakeEverythingVisible(); /* send results */ G_EventAdd(PM_ALL, EV_RESULTS, -1); gi.WriteByte(MAX_TEAMS); gi.WriteByte(team); gi.WriteByte(nextmap); for (int i = 0; i < MAX_TEAMS; i++) { gi.WriteByte(level.num_spawned[i]); gi.WriteByte(level.num_alive[i]); } for (int i = 0; i <= MAX_TEAMS; i++) for (int j = 0; j < MAX_TEAMS; j++) gi.WriteByte(level.num_kills[i][j]); for (int i = 0; i <= MAX_TEAMS; i++) for (int j = 0; j < MAX_TEAMS; j++) gi.WriteByte(level.num_stuns[i][j]); /* how many actors */ int n = 0; actor = nullptr; while ((actor = G_EdictsGetNextActor(actor))) if (!G_IsAI(actor)) n++; /* number of soldiers */ gi.WriteByte(n); if (n) { actor = nullptr; while ((actor = G_EdictsGetNextActor(actor))) { if (!G_IsAI(actor)) { G_SendCharacterData(actor); } } } G_EventEnd(); }
void MoveLeftCommand::execute(Actor& actor) noexcept{ actor.move_left(); }
// move to point on screen that was tapped void OnTap( Actor actor, const TapGesture& tapGesture ) { Vector3 destPos; float originOffsetX, originOffsetY; // rotate offset (from top left origin to centre) into actor space Vector2 stageSize = Dali::Stage::GetCurrent().GetSize(); actor.ScreenToLocal(originOffsetX, originOffsetY, stageSize.width * 0.5f, stageSize.height * 0.5f); // get dest point in local actor space destPos.x = tapGesture.localPoint.x - originOffsetX; destPos.y = tapGesture.localPoint.y - originOffsetY; destPos.z = 0.0f; float animDuration = 0.5f; mActorTapMovementAnimation = Animation::New( animDuration ); if ( mMotionBlurImageView ) { mActorTapMovementAnimation.AnimateTo( Property(mMotionBlurImageView, Actor::Property::POSITION), destPos, AlphaFunction::EASE_IN_OUT_SINE, TimePeriod(animDuration) ); } mActorTapMovementAnimation.SetEndAction( Animation::Bake ); mActorTapMovementAnimation.Play(); // perform some spinning etc if(mActorEffectsEnabled) { switch(mCurrentActorAnimation) { // spin around y case 0: { float animDuration = 1.0f; mActorAnimation = Animation::New(animDuration); mActorAnimation.AnimateBy( Property( mMotionBlurImageView, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f) ), Vector3::YAXIS ), AlphaFunction::EASE_IN_OUT ); mActorAnimation.SetEndAction( Animation::Bake ); mActorAnimation.Play(); } break; // spin around z case 1: { float animDuration = 1.0f; mActorAnimation = Animation::New(animDuration); mActorAnimation.AnimateBy( Property( mMotionBlurImageView, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f) ), Vector3::ZAXIS ), AlphaFunction::EASE_IN_OUT ); mActorAnimation.SetEndAction( Animation::Bake ); mActorAnimation.Play(); } break; // spin around y and z case 2: { float animDuration = 1.0f; mActorAnimation = Animation::New(animDuration); mActorAnimation.AnimateBy( Property( mMotionBlurImageView, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f) ), Vector3::YAXIS ), AlphaFunction::EASE_IN_OUT ); mActorAnimation.AnimateBy( Property( mMotionBlurImageView, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f) ), Vector3::ZAXIS ), AlphaFunction::EASE_IN_OUT ); mActorAnimation.SetEndAction( Animation::Bake ); mActorAnimation.Play(); } break; // scale case 3: { float animDuration = 1.0f; mActorAnimation = Animation::New(animDuration); mActorAnimation.AnimateBy( Property( mMotionBlurImageView, Actor::Property::SCALE ), Vector3(2.0f, 2.0f, 2.0f), AlphaFunction::BOUNCE, TimePeriod( 0.0f, 1.0f ) ); mActorAnimation.SetEndAction( Animation::Bake ); mActorAnimation.Play(); } break; default: break; } mCurrentActorAnimation++; if(NUM_ACTOR_ANIMATIONS == mCurrentActorAnimation) { mCurrentActorAnimation = 0; } } }
int UtcDaliScriptingCreatePropertyMapActor(void) { TestApplication application; // Actor Type { Actor actor = Actor::New(); Property::Map map; CreatePropertyMap( actor, map ); DALI_TEST_CHECK( !map.Empty() ); DALI_TEST_CHECK( NULL != map.Find( "type" ) ); DALI_TEST_EQUALS( map.Find( "type")->Get< std::string >(), "Actor", TEST_LOCATION ); Stage::GetCurrent().Remove( actor ); } // ImageActor Type { Actor actor = ImageActor::New(); Property::Map map; CreatePropertyMap( actor, map ); DALI_TEST_CHECK( !map.Empty() ); DALI_TEST_CHECK( NULL != map.Find( "type" ) ); DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "ImageActor", TEST_LOCATION ); Stage::GetCurrent().Remove( actor ); } // Default properties { Actor actor = Actor::New(); actor.SetSize( Vector3::ONE ); actor.SetPosition( Vector3::XAXIS ); actor.SetScale( Vector3::ZAXIS ); actor.SetVisible( false ); actor.SetColor( Color::MAGENTA ); actor.SetName( "MyActor" ); actor.SetAnchorPoint( AnchorPoint::CENTER_LEFT ); actor.SetParentOrigin( ParentOrigin::TOP_RIGHT ); actor.SetSensitive( false ); actor.SetLeaveRequired( true ); actor.SetInheritOrientation( false ); actor.SetInheritScale( false ); actor.SetSizeModeFactor( Vector3::ONE ); Stage::GetCurrent().Add( actor ); application.SendNotification(); application.Render(); Property::Map map; CreatePropertyMap( actor, map ); DALI_TEST_CHECK( !map.Empty() ); DALI_TEST_CHECK( NULL != map.Find( "size" ) ); DALI_TEST_EQUALS( map.Find( "size" )->Get< Vector3 >(), Vector3::ONE, TEST_LOCATION ); DALI_TEST_CHECK( NULL != map.Find( "position" ) ); DALI_TEST_EQUALS( map.Find( "position" )->Get< Vector3 >(), Vector3::XAXIS, TEST_LOCATION ); DALI_TEST_CHECK( NULL != map.Find( "scale" ) ); DALI_TEST_EQUALS( map.Find( "scale" )->Get< Vector3 >(), Vector3::ZAXIS, TEST_LOCATION ); DALI_TEST_CHECK( NULL != map.Find( "visible" ) ); DALI_TEST_EQUALS( map.Find( "visible" )->Get< bool >(), false, TEST_LOCATION ); DALI_TEST_CHECK( NULL != map.Find( "color" ) ); DALI_TEST_EQUALS( map.Find( "color" )->Get< Vector4 >(), Color::MAGENTA, TEST_LOCATION ); DALI_TEST_CHECK( NULL != map.Find( "name" ) ); DALI_TEST_EQUALS( map.Find( "name")->Get< std::string >(), "MyActor", TEST_LOCATION ); DALI_TEST_CHECK( NULL != map.Find( "anchor-point" ) ); DALI_TEST_EQUALS( map.Find( "anchor-point" )->Get< Vector3 >(), AnchorPoint::CENTER_LEFT, TEST_LOCATION ); DALI_TEST_CHECK( NULL != map.Find( "parent-origin" ) ); DALI_TEST_EQUALS( map.Find( "parent-origin" )->Get< Vector3 >(), ParentOrigin::TOP_RIGHT, TEST_LOCATION ); DALI_TEST_CHECK( NULL != map.Find( "sensitive" ) ); DALI_TEST_EQUALS( map.Find( "sensitive" )->Get< bool >(), false, TEST_LOCATION ); DALI_TEST_CHECK( NULL != map.Find( "leave-required" ) ); DALI_TEST_EQUALS( map.Find( "leave-required" )->Get< bool >(), true, TEST_LOCATION ); DALI_TEST_CHECK( NULL != map.Find( "inherit-orientation" ) ); DALI_TEST_EQUALS( map.Find( "inherit-orientation" )->Get< bool >(), false, TEST_LOCATION ); DALI_TEST_CHECK( NULL != map.Find( "inherit-scale" ) ); DALI_TEST_EQUALS( map.Find( "inherit-scale" )->Get< bool >(), false, TEST_LOCATION ); DALI_TEST_CHECK( NULL != map.Find( "size-mode-factor" ) ); DALI_TEST_EQUALS( map.Find( "size-mode-factor" )->Get< Vector3 >(), Vector3::ONE, TEST_LOCATION ); Stage::GetCurrent().Remove( actor ); } // ColorMode TestEnumStrings< ColorMode >( "color-mode", application, COLOR_MODE_VALUES, COLOR_MODE_VALUES_COUNT, &Actor::SetColorMode ); // PositionInheritanceMode TestEnumStrings< PositionInheritanceMode >( "position-inheritance", application, POSITION_INHERITANCE_MODE_VALUES, POSITION_INHERITANCE_MODE_VALUES_COUNT, &Actor::SetPositionInheritanceMode ); // DrawMode TestEnumStrings< DrawMode::Type >( "draw-mode", application, DRAW_MODE_VALUES, DRAW_MODE_VALUES_COUNT, &Actor::SetDrawMode ); // Children { Actor actor = Actor::New(); Actor child = ImageActor::New(); actor.Add( child ); Stage::GetCurrent().Add( actor ); application.SendNotification(); application.Render(); Property::Map map; CreatePropertyMap( actor, map ); DALI_TEST_CHECK( !map.Empty() ); DALI_TEST_CHECK( NULL != map.Find( "type" ) ); DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "Actor", TEST_LOCATION ); DALI_TEST_CHECK( NULL != map.Find( "actors" ) ); Property::Array children( map.Find( "actors")->Get< Property::Array >() ); DALI_TEST_CHECK( !children.Empty() ); Property::Map childMap( children[0].Get< Property::Map >() ); DALI_TEST_CHECK( !childMap.Empty() ); DALI_TEST_CHECK( childMap.Find( "type" ) ); DALI_TEST_EQUALS( childMap.Find( "type" )->Get< std::string >(), "ImageActor", TEST_LOCATION ); Stage::GetCurrent().Remove( actor ); } END_TEST; }
/** * @brief Deals damage of a give type and amount to a target. * @param[in,out] target What we want to damage. * @param[in] fd The fire definition that defines what type of damage is dealt. * @param[in] damage The value of the damage. * @param[in] attacker The attacker. * @param[in] mock pseudo shooting - only for calculating mock values - nullptr for real shots * @param[in] impact impact location - @c nullptr for splash damage * @return @c true if damage could be dealt (even if it was 0) @c false otherwise * @sa G_SplashDamage * @sa G_TakeDamage * @sa G_PrintActorStats */ static bool G_Damage (Edict* target, const fireDef_t* fd, int damage, Actor* attacker, shot_mock_t* mock, const vec3_t impact) { assert(target); const bool stunEl = (fd->obj->dmgtype == gi.csi->damStunElectro); const bool stunGas = (fd->obj->dmgtype == gi.csi->damStunGas); const bool shock = (fd->obj->dmgtype == gi.csi->damShock); const bool smoke = (fd->obj->dmgtype == gi.csi->damSmoke); /* Breakables */ if (G_IsBrushModel(target) && G_IsBreakable(target)) { /* Breakables are immune to stun & shock damage. */ if (stunEl || stunGas || shock || mock || smoke) return false; if (damage >= target->HP) { /* don't reset the HP value here, this value is used to distinguish * between triggered destroy and a shoot */ assert(target->destroy); target->destroy(target); /* maybe the attacker is seeing something new? */ G_CheckVisTeamAll(attacker->getTeam(), 0, attacker); /* check if attacker appears/perishes for any other team */ G_CheckVis(attacker); } else { G_TakeDamage(target, damage); } return true; } /* Actors don't die again. */ if (!G_IsLivingActor(target)) return false; /* Now we know that the target is an actor */ Actor* victim = makeActor(target); /* only actors after this point - and they must have a teamdef */ assert(victim->chr.teamDef); const bool isRobot = CHRSH_IsTeamDefRobot(victim->chr.teamDef); /* Apply armour effects. */ if (damage > 0) { damage = G_ApplyProtection(victim, fd->dmgweight, damage); } else if (damage < 0) { /* Robots can't be healed. */ if (isRobot) return false; } Com_DPrintf(DEBUG_GAME, " Total damage: %d\n", damage); /* Apply difficulty settings. */ if (G_IsSinglePlayer()) { if (G_IsAlien(attacker) && !G_IsAlien(victim)) damage *= pow(1.18f, g_difficulty->value); else if (!G_IsAlien(attacker) && G_IsAlien(victim)) damage *= pow(1.18f, -g_difficulty->value); } assert(attacker->getTeam() >= 0 && attacker->getTeam() < MAX_TEAMS); assert(victim->getTeam() >= 0 && victim->getTeam() < MAX_TEAMS); if ((g_nodamage != nullptr && !g_nodamage->integer) || mock) { /* hit */ if (mock) { G_UpdateShotMock(mock, attacker, victim, damage); } else if (stunEl) { victim->addStun(damage); } else if (stunGas) { if (!isRobot) /* Can't stun robots with gas */ victim->addStun(damage); } else if (shock) { /* Only do this if it's not one from our own team ... they should have known that there was a flashbang coming. */ if (!isRobot && !victim->isSameTeamAs(attacker)) { /** @todo there should be a possible protection, too */ /* dazed entity wont reaction fire */ victim->removeReaction(); G_ActorReserveTUs(victim, 0, victim->chr.reservedTus.shot, victim->chr.reservedTus.crouch); /* flashbangs kill TUs */ G_ActorSetTU(victim, 0); G_SendStats(*victim); /* entity is dazed */ victim->setDazed(); G_EventSendState(G_VisToPM(victim->visflags), *victim); return !mock; } else { return false; } } else { if (damage < 0) { /* The 'attacker' is healing the victim. */ G_TreatActor(victim, fd, damage, attacker->getTeam()); } else { /* Real damage was dealt. */ G_DamageActor(victim, damage, impact); /* Update overall splash damage for stats/score. */ if (!mock && damage > 0 && fd->splrad) /**< Check for >0 and splrad to not count this as direct hit. */ G_UpdateHitScore(attacker, victim, fd, damage); } } } if (mock) return false; G_CheckDeathOrKnockout(victim, attacker, fd, damage); return true; }
bool MatchActor(Scriptable *Sender, ieDword actorID, Object* oC) { if (!Sender) { return false; } Actor *ac = Sender->GetCurrentArea()->GetActorByGlobalID(actorID); if (!ac) { return false; } // [0]/[ANYONE] can match all actors if (!oC) { return true; } bool filtered = false; // name matching if (oC->objectName[0]) { if (strnicmp(ac->GetScriptName(), oC->objectName, 32) != 0) { return false; } filtered = true; } // IDS targeting // (if we already matched by name, we don't do this) // TODO: check distance? area? visibility? if (!filtered && !DoObjectIDSCheck(oC, ac, &filtered)) return false; // globalID hack should never get here assert(oC->objectFilters[0] != -1); // object filters if (oC->objectFilters[0]) { // object filters insist on having a stupid targets list, // so we waste a lot of time here Targets *tgts = new Targets(); int ga_flags = 0; // TODO: correct? // handle already-filtered vs not-yet-filtered cases // e.g. LastTalkedToBy(Myself) vs LastTalkedToBy if (filtered) tgts->AddTarget(ac, 0, ga_flags); tgts = DoObjectFiltering(Sender, tgts, oC, ga_flags); if (!tgts) return false; // and sometimes object filters are lazy and not only don't filter // what we give them, they clear it and return a list :( // so we have to search the whole list.. bool ret = false; targetlist::iterator m; const targettype *tt = tgts->GetFirstTarget(m, ST_ACTOR); while (tt) { Actor *actor = (Actor *) tt->actor; if (actor->GetGlobalID() == actorID) { ret = true; break; } tt = tgts->GetNextTarget(m, ST_ACTOR); } delete tgts; if (!ret) return false; } return true; }
/** * @brief Applies morale changes to actors around a wounded or killed actor. * @note only called when mor_panic is not zero * @param[in] type Type of morale modifier (@sa morale_modifiers) * @param[in] victim An actor being a victim of the attack. * @param[in] attacker An actor being attacker in this attack. * @param[in] param Used to modify morale changes, for G_Damage() it is value of damage. * @sa G_Damage */ static void G_Morale (morale_modifiers type, const Edict* victim, const Edict* attacker, int param) { Actor* actor = nullptr; while ((actor = G_EdictsGetNextLivingActor(actor))) { /* this only applies to ET_ACTOR but not ET_ACTOR2x2 */ if (actor->type != ET_ACTOR) continue; if (G_IsCivilian(actor)) continue; /* morale damage depends on the damage */ float mod = mob_wound->value * param; if (type == ML_SHOOT) mod *= mob_shoot->value; /* death hurts morale even more than just damage */ if (type == ML_DEATH) mod += mob_death->value; /* seeing how someone gets shot increases the morale change */ if (actor == victim || (G_FrustumVis(actor, victim->origin) && G_ActorVis(actor, victim, false))) mod *= mof_watching->value; if (attacker != nullptr && actor->isSameTeamAs(attacker)) { /* teamkills are considered to be bad form, but won't cause an increased morale boost for the enemy */ /* morale boost isn't equal to morale loss (it's lower, but morale gets regenerated) */ if (victim->isSameTeamAs(attacker)) mod *= mof_teamkill->value; else mod *= mof_enemy->value; } /* seeing a civilian die is more "acceptable" */ if (G_IsCivilian(victim)) mod *= mof_civilian->value; /* if an ally (or in singleplayermode, as human, a civilian) got shot, lower the morale, don't heighten it. */ if (victim->isSameTeamAs(actor) || (G_IsCivilian(victim) && !G_IsAlien(actor) && G_IsSinglePlayer())) mod *= -1; if (attacker != nullptr) { /* if you stand near to the attacker or the victim, the morale change is higher. */ mod *= mor_default->value + pow(0.5f, VectorDist(actor->origin, victim->origin) / mor_distance->value) * mor_victim->value + pow(0.5f, VectorDist(actor->origin, attacker->origin) / mor_distance->value) * mor_attacker->value; } else { mod *= mor_default->value + pow(0.5f, VectorDist(actor->origin, victim->origin) / mor_distance->value) * mor_victim->value; } /* morale damage depends on the number of living allies */ mod *= (1 - mon_teamfactor->value) + mon_teamfactor->value * (level.num_spawned[victim->getTeam()] + 1) / (level.num_alive[victim->getTeam()] + 1); /* being hit isn't fun */ if (actor == victim) mod *= mor_pain->value; /* clamp new morale */ /*+0.9 to allow weapons like flamethrowers to inflict panic (typecast rounding) */ const int newMorale = actor->morale + (int) (MORALE_RANDOM(mod) + 0.9); if (newMorale > GET_MORALE(actor->chr.score.skills[ABILITY_MIND])) actor->setMorale(GET_MORALE(actor->chr.score.skills[ABILITY_MIND])); else if (newMorale < 0) actor->setMorale(0); else actor->setMorale(newMorale); /* send phys data */ G_SendStats(*actor); } }
void ActorView::display_actor_stats() { Actor *actor; char buf[10]; int x_off = 0; int y_off = 0; uint8 hp_text_color = 0; //standard text color if(in_party) actor = party->get_actor(cur_party_member); else actor = Game::get_game()->get_player()->get_actor(); if (MD) { x_off = -1; } else if(Game::get_game()->get_game_type()==NUVIE_GAME_SE) { x_off = 2; y_off = - 6; } hp_text_color = actor->get_hp_text_color(); sprintf(buf,"%d", Game::get_game()->get_script()->call_actor_str_adj(actor));//actor->get_strength()); uint8 str_len = font->drawString(screen, "STR:", area.x + 5 * 16 + x_off, area.y + y_off + 16); font->drawString(screen, buf, area.x + 5 * 16 + x_off + str_len, area.y + y_off + 16, actor->get_str_text_color(), 0); sprintf(buf,"%d",Game::get_game()->get_script()->call_actor_dex_adj(actor)); str_len = font->drawString(screen, "DEX:", area.x + 5 * 16 + x_off, area.y + y_off + 16 + 8); font->drawString(screen, buf, area.x + 5 * 16 + x_off + str_len, area.y + y_off + 16 + 8, actor->get_dex_text_color(), 0); sprintf(buf,"INT:%d",Game::get_game()->get_script()->call_actor_int_adj(actor)); font->drawString(screen, buf, area.x + 5 * 16 + x_off, area.y + y_off + 16 + 2 * 8); if (MD || Game::get_game()->get_game_type()==NUVIE_GAME_SE) { sprintf(buf,"%3d",actor->get_hp()); str_len = font->drawString(screen, "HP:", area.x + 5 * 16 + x_off, area.y + y_off + 16 + 3 * 8); font->drawString(screen, buf, strlen(buf), area.x + 5 * 16 + x_off + str_len, area.y + y_off + 16 + 3 * 8, hp_text_color, 0); sprintf(buf,"HM:%3d",actor->get_maxhp()); font->drawString(screen, buf, area.x + 5 * 16 + x_off, area.y + y_off + 16 + 4 * 8); sprintf(buf,"Lev:%2d",actor->get_level()); font->drawString(screen, buf, area.x + 5 * 16 + x_off, area.y + y_off + 16 + 5 * 8); font->drawString(screen, "Exper:", area.x + 5 * 16 + x_off, area.y + y_off + 16 + 6 * 8); sprintf(buf,"%6d",actor->get_exp()); font->drawString(screen, buf, area.x + 5 * 16 + x_off, area.y + y_off + 16 + 7 * 8); return; } font->drawString(screen, "Magic", area.x + 5 * 16, area.y + 16 + 4 * 8); sprintf(buf,"%d/%d",actor->get_magic(),actor->get_maxmagic()); font->drawString(screen, buf, area.x + 5 * 16, area.y + 16 + 5 * 8); font->drawString(screen, "Health", area.x + 5 * 16, area.y + 16 + 6 * 8); sprintf(buf,"%3d",actor->get_hp()); font->drawString(screen, buf, strlen(buf), area.x + 5 * 16, area.y + 16 + 7 * 8, hp_text_color, 0); sprintf(buf," /%d",actor->get_maxhp()); font->drawString(screen, buf, area.x + 5 * 16, area.y + 16 + 7 * 8); font->drawString(screen, "Lev/Exp", area.x + 5 * 16, area.y + 16 + 8 * 8); sprintf(buf,"%d/%d",actor->get_level(),actor->get_exp()); font->drawString(screen, buf, area.x + 5 * 16, area.y + 16 + 9 * 8); return; }
bool OBB::CheckForCollision(Actor &i_actorA,Actor & i_actorB, float deltaTime) { collided=false; float rotation=i_actorA.getActorRotation(); float mat1[]={ cos(rotation),sin(rotation),0.0,0.0, -sin(rotation),cos(rotation),0.0,0.0, 0.0,0.0,1.0,0.0, i_actorA.getActorPreviousPosition()->getx(), i_actorA.getActorPreviousPosition()->gety(),0.0,1.0 }; Matrix *M_A_to_World=new Matrix(4,4); M_A_to_World->SetMatrix(mat1,16); Matrix *M_World_to_A=M_A_to_World->Inverse(); delete M_A_to_World; float rotationB=i_actorB.getActorRotation(); float mat2[]={ cos(rotationB),sin(rotationB),0.0,0.0, -sin(rotationB),cos(rotationB),0.0,0.0, 0.0,0.0,1.0,0.0, i_actorB.getActorPreviousPosition()->getx(), i_actorB.getActorPreviousPosition()->gety(),0.0,1.0 }; Matrix *M_B_to_World=new Matrix(4,4); M_B_to_World->SetMatrix(mat2,16); Matrix *M_World_to_B=M_B_to_World->Inverse(); delete M_B_to_World; //Calculating position and velocity //position of object B in Model space of A float mat5[]={i_actorB.getActorPreviousPosition()->getx(), i_actorB.getActorPreviousPosition()->gety(),0.0,1}; Matrix *actorBposition=new Matrix(1,4); actorBposition->SetMatrix(mat5,4); Matrix *M_Bposition_in_A=actorBposition->MultilpyByMatrix(*M_World_to_A); //Dividing by xyz by w Vector3 BpositioninA=Vector3( M_Bposition_in_A->getMatrix()[0][0]/ M_Bposition_in_A->getMatrix()[0][3], M_Bposition_in_A->getMatrix()[0][1]/ M_Bposition_in_A->getMatrix()[0][3], M_Bposition_in_A->getMatrix()[0][2]/ M_Bposition_in_A->getMatrix()[0][3]); Matrix *M_Bposition_in_B=actorBposition->MultilpyByMatrix(*M_World_to_B); //Dividing by xyz by w Vector3 BpositioninB=Vector3( M_Bposition_in_B->getMatrix()[0][0]/ M_Bposition_in_B->getMatrix()[0][3], M_Bposition_in_B->getMatrix()[0][1]/ M_Bposition_in_B->getMatrix()[0][3], M_Bposition_in_B->getMatrix()[0][2]/ M_Bposition_in_B->getMatrix()[0][3]); delete actorBposition; delete M_Bposition_in_A; delete M_Bposition_in_B; //calculating velocity in model space of A float mat6[]={i_actorB.getActorPreviousVelocity()->getx(), i_actorB.getActorPreviousVelocity()->gety(), 0,0}; Matrix *actorBvelocity=new Matrix(1,4); actorBvelocity->SetMatrix(mat6,4); Matrix *M_Bvelocity_in_A=actorBvelocity->MultilpyByMatrix(*M_World_to_A); //Dividing by xyz by w Vector3 BvelocityinA=Vector3( M_Bvelocity_in_A->getMatrix()[0][0], M_Bvelocity_in_A->getMatrix()[0][1], M_Bvelocity_in_A->getMatrix()[0][2]); Matrix *M_Bvelocity_in_B=actorBvelocity->MultilpyByMatrix(*M_World_to_B); //Dividing by xyz by w Vector3 BvelocityinB=Vector3( M_Bvelocity_in_B->getMatrix()[0][0], M_Bvelocity_in_B->getMatrix()[0][1], M_Bvelocity_in_B->getMatrix()[0][2]); delete actorBvelocity; delete M_Bvelocity_in_A; delete M_Bvelocity_in_B; //Calculating bounding box for object B float theta= i_actorA.getActorRotation()-i_actorB.getActorRotation(); float widthOfB= (i_actorB.getBox()->GetWidth()*fabs(cos(theta)) ) + (i_actorB.getBox()->GetHeight()*fabs(sin( theta)) ); float heightOfB= (i_actorB.getBox()->GetHeight()*fabs(cos(theta)) ) + (i_actorB.getBox()->GetWidth()*fabs(sin( theta)) ); //position of object A in Model space of B float mat7[]={i_actorA.getActorPreviousPosition()->getx(), i_actorA.getActorPreviousPosition()->gety(), 0,1}; Matrix *actorAposition=new Matrix(1,4); actorAposition->SetMatrix(mat7,4); Matrix *M_Aposition_in_B=actorAposition->MultilpyByMatrix(*M_World_to_B); //Dividing by xyz by w Vector3 ApositioninB=Vector3( M_Aposition_in_B->getMatrix()[0][0]/ M_Aposition_in_B->getMatrix()[0][3] , M_Aposition_in_B->getMatrix()[0][1]/ M_Aposition_in_B->getMatrix()[0][3], M_Aposition_in_B->getMatrix()[0][2]/ M_Aposition_in_B->getMatrix()[0][3]); Matrix *M_Aposition_in_A=actorAposition->MultilpyByMatrix(*M_World_to_A); //Dividing by xyz by w Vector3 ApositioninA=Vector3( M_Aposition_in_A->getMatrix()[0][0]/ M_Aposition_in_A->getMatrix()[0][3], M_Aposition_in_A->getMatrix()[0][1]/ M_Aposition_in_A->getMatrix()[0][3], M_Aposition_in_A->getMatrix()[0][2]/ M_Aposition_in_A->getMatrix()[0][3]); delete actorAposition; delete M_Aposition_in_B; delete M_Aposition_in_A; //calculating velocity in model space of B float mat8[]={i_actorA.getActorPreviousVelocity()->getx(), i_actorA.getActorPreviousVelocity()->gety(), 0,0}; Matrix *actorAvelocity=new Matrix(1,4); actorAvelocity->SetMatrix(mat8,4); Matrix *M_Avelocity_in_B=actorAvelocity->MultilpyByMatrix(*M_World_to_B); //Dividing by xyz by w Vector3 AvelocityinB=Vector3( M_Avelocity_in_B->getMatrix()[0][0], M_Avelocity_in_B->getMatrix()[0][1], M_Avelocity_in_B->getMatrix()[0][2]); Matrix *M_Avelocity_in_A=actorAvelocity->MultilpyByMatrix(*M_World_to_A); //Dividing by xyz by w Vector3 AvelocityinA=Vector3( M_Avelocity_in_A->getMatrix()[0][0], M_Avelocity_in_A->getMatrix()[0][1], M_Avelocity_in_A->getMatrix()[0][2]); delete actorAvelocity; delete M_Avelocity_in_B; delete M_Avelocity_in_A; delete M_World_to_B; delete M_World_to_A; //Calculating bounding box for object A float widthOfA= (i_actorA.getBox()->GetWidth()*fabs(cos(theta)) ) + (i_actorA.getBox()->GetHeight()*fabs(sin( theta)) ); float heightOfA= (i_actorA.getBox()->GetHeight()*fabs(cos(theta)) ) + (i_actorA.getBox()->GetWidth()*fabs(sin( theta)) ); bool firstCheck=false; bool secondCheck=false; firstCheck=AABB::CheckForCollision(i_actorB,BpositioninB,ApositioninB,BvelocityinB,AvelocityinB,widthOfA,heightOfA,deltaTime); Vector3 normal1=AABB::checkNormal(); secondCheck=AABB::CheckForCollision(i_actorA,ApositioninA,BpositioninA,AvelocityinA,BvelocityinA,widthOfB,heightOfB,deltaTime); Vector3 normal2=AABB::checkNormal(); float rotationA=i_actorA.getActorRotation(); float matRotation[]={ cos(rotation),sin(rotation),0.0, -sin(rotation),cos(rotation),0.0, 0.0,0.0,1.0 }; Matrix *M_Arotation=new Matrix(3,3); M_Arotation->SetMatrix(matRotation,9); float matAnormal[]={normal2.getx(), normal2.gety(), 0}; Matrix *actorAnormal=new Matrix(1,3); actorAnormal->SetMatrix(matAnormal,3); Matrix *M_normal2=actorAnormal->MultilpyByMatrix(*M_Arotation); normal2=Vector3(M_normal2->getMatrix()[0][0], M_normal2->getMatrix()[0][1], M_normal2->getMatrix()[0][2]); delete M_Arotation; delete actorAnormal; delete M_normal2; //Multiplying the normal with rotation matrix //calculating normal in world space float rotation_B=i_actorB.getActorRotation(); float matRotation_B[]={ cos(rotation_B),sin(rotation_B),0.0, -sin(rotation_B),cos(rotation_B),0.0, 0.0,0.0,1.0 }; Matrix *M_Brotation=new Matrix(3,3); M_Brotation->SetMatrix(matRotation_B,9); float matBnormal[]={normal2.getx(), normal2.gety(),0}; Matrix *actorBnormal=new Matrix(1,3); actorBnormal->SetMatrix(matAnormal,3); Matrix *M_normal1=actorBnormal->MultilpyByMatrix(*M_Brotation); normal1=Vector3(M_normal1->getMatrix()[0][0], M_normal1->getMatrix()[0][1], M_normal1->getMatrix()[0][2]); delete M_Brotation; delete actorBnormal; delete M_normal1; if(firstCheck==true && secondCheck==true) { OBB::collided=true; //i_actorA.getBox()->getTrigger()->OnCollision(i_actorA); // i_actorB.getBox()->getTrigger()->OnCollision(i_actorB); } return 0; }