void TCompCharacterController::onCreate(const TMsgEntityCreated &) { m_pActor = g_PhysxManager->CreateCharacterController(m_radius, m_height); m_affectGravity = true; m_gravitySpeed = -10.0f; m_maxSpeed = 7.0f; CEntity *e = CHandle(this).getOwner(); if (e) { //update position from CC to match the render transform TCompName *nameComp = e->get<TCompName>(); if (nameComp) name = std::string(nameComp->name); TCompTransform *mtx = e->get<TCompTransform>(); PxExtendedVec3 p = Vec3ToPxExVec3(mtx->getPosition()); p.y += m_height + m_radius; //add height value from capsule, center from collider at center of the shape m_pActor->setPosition(p); //save parent handle m_pActor->getActor()->userData = (void*)CHandle(this).getOwner().asUnsigned(); //default flags for character controllers m_filter = DEFAULT_DATA_CC; UpdateTags(); } InitAABB(); }
void TCompLightDirShadowsDynamic::generateShadowMap() { if (!enabled) return; if (!is_inRoom) return; assert(rt_shadows); PROFILE_FUNCTION("shadows: generateShadowMap"); // Vamos a empezar a pintar en el shadow map rt_shadows->clearZ(); //rt_shadows->setZ(rt_shadows_base->getZ(), rt_shadows_base->getRT()); // rt_shadows->activateRT(); activateRS(RSCFG_SHADOWS); // Desde MI punto de vista, el pt de vista de la luz direccional // que genera sombras activateCamera(this); // activar la tech de shadow map generation Resources.get("shadow_gen.tech")->as<CRenderTechnique>()->activate(); // Pintar los shadow casters RenderManager.renderShadowCasters(CHandle(this).getOwner(), SBB::readSala(), true); // activar la tech de shadow map generation Resources.get("shadow_gen_skin.tech")->as<CRenderTechnique>()->activate(); // Pintar los shadow casters RenderManager.renderShadowCastersSkin(CHandle(this).getOwner(), SBB::readSala()); activateRS(RSCFG_DEFAULT); }
bool TCompHierarchy::load(MKeyValue& atts) { TCompTransform::load(atts); parent_id = atts.getInt("parent", 0); h_parent_transform = CHandle(); h_my_transform = CHandle(); return true; }
void SkelControllerMole::ungrabPila() { GET_COMP(pila, grabbedPila, TCompPila); TMsgAttach msg; msg.handle = CHandle(); grabbedPila.sendMsg(msg); pila->setFalling(); grabbedPila = CHandle(); //disableIK(SK_RHAND, SK_MOLE_TIME_TO_UNGRAB, ungrabbed); //(SK_RHAND, SK_MOLE_TIME_TO_UNGRAB, ); }
IK_IMPL_SOLVER(ungrabbedPila, info, result) { GET_COMP(skc, info.handle, SkelControllerMole); TMsgAttach msg; msg.handle = CHandle(); skc->getGrabbedPila().sendMsg(msg); skc->removePila(); }
bool TCompBoneTracker::load(MKeyValue& atts) { strcpy(bone_name, atts.getString("bone", "").c_str()); strcpy(entity_name, atts.getString("entity", "").c_str()); bone_id = -1; h_entity = CHandle(); return true; }
void TCompLightDirShadowsDynamic::init() { PROFILE_FUNCTION("shadows: update"); debug_render = true; CHandle owner = CHandle(this).getOwner(); updateFromEntityTransform(owner); setCameraHandle(); is_inRoom = true; }
void TCompHierarchy::linkTo(CHandle h_entity) { CEntity* e = h_entity; if (!e) { h_parent_transform = CHandle(); return; } h_parent_transform = e->get<TCompTransform>(); }
// Resolve parent void TCompHierarchy::onGetParentById(const TMsgHierarchySolver&) { CHandle h_entity = IdEntities::findById(parent_id); linkTo(h_entity); // Get access to my comp transform CHandle h_my_entity = CHandle(this).getOwner(); CEntity* e_my_entity = h_my_entity; h_my_transform = e_my_entity->get<TCompTransform>(); }
void TCompLightDirShadowsDynamic::activate() { PROFILE_FUNCTION("shadows: activate"); if (!is_inRoom) return; if (!enabled) return; CHandle owner = CHandle(this).getOwner(); activateWorldMatrix(getViewProjection().Invert()); rt_shadows->getZTexture()->activate(TEXTURE_SLOT_SHADOWMAP); uploadShaderCtes(owner); }
/** * Install the SendTo item. */ HRESULT UpdateSendToFromProject(LPCWSTR pstrDisplayName, LPCWSTR pstrProgId, BOOL bRegister) { CCoTaskString strPath; HR( ::SHGetKnownFolderPath(FOLDERID_SendTo, 0, NULL, &strPath) ); WCHAR wszFilename[MAX_PATH] = { 0 }; ::wnsprintf(wszFilename, lengthof(wszFilename) - 1, L"%s\\%s.%s", static_cast<LPCWSTR>(strPath), pstrDisplayName, pstrProgId); if( bRegister ) CHandle( ::CreateFileW(wszFilename, GENERIC_WRITE, NULL, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL) ); else ::DeleteFileW(wszFilename); return S_OK; }
void bootstrapper::update_save() { global_routing_params* routing_params = this->routing_params; global_routing_params default_params; create_default_params(default_params); if(!routing_params) routing_params = &default_params; // serialize params const size_t routing_params_size = global_size(routing_params); assert(routing_params_size > 0); if(routing_params_size == 0) throw std::wstring(L"The internal state of saved routings is corrupted.\n"); // update the file and create a view this->implicit_params.Close(); this->local_file.Close(); // TODO: do not loop infinitely do { this->local_file = CHandle(NULL); this->local_file.Attach(CreateFile(LOCAL_PARAMS_FILE, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)); } while(this->local_file == INVALID_HANDLE_VALUE && GetLastError() == ERROR_USER_MAPPED_FILE); if(this->local_file == INVALID_HANDLE_VALUE) { throw std::wstring(L"Could not open file " LOCAL_PARAMS_FILE L" while saving routing. " \ L"Audio Router is left in an invalid state and must be restarted.\n"); } this->implicit_params.Attach(CreateFileMapping(this->local_file, NULL, PAGE_READWRITE, 0, (DWORD)routing_params_size, NULL)); if(!this->implicit_params) { this->local_file.Close(); throw std::wstring(L"Unexpected error occured. Old routed savings data is lost. " \ L"Audio Router is left in an invalid state and must be restarted.\n"); } unsigned char* view_of_file = (unsigned char*)MapViewOfFile(this->implicit_params, FILE_MAP_ALL_ACCESS, 0, 0, 0); if(!view_of_file) { this->implicit_params.Close(); this->local_file.Close(); throw std::wstring(L"Unexpected error occured while mapping. Old routed savings data " \ L"is lost. Audio Router is left in an invalid state and must be restarted.\n"); } serialize(routing_params, view_of_file); FlushViewOfFile(view_of_file, 0); UnmapViewOfFile(view_of_file); this->implicit_params.Close(); this->local_file.Close(); }
CHandle CHFServer::GetProcessId(std::string& sProcessName, DWORD& dwProcessID ) { DWORD aProcesses[2048], cbNeeded, cProcesses; if(!sProcessName.length()) return CHandle(); dwProcessID = 0; unsigned int i; std::string sUpperCaseProcessName = utils::upcase(sProcessName); if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) ) return CHandle(); // Calculate how many process identifiers were returned. cProcesses = cbNeeded / sizeof(DWORD); // Print the name and process identifier for each process. for ( i = 0; i < cProcesses; i++ ) { char szProcessName[MAX_PATH] ={0}; CHandle hProcess(OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, aProcesses[i] )); if (NULL != (HANDLE)hProcess ) { HMODULE hMod; DWORD cbNeeded; if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod), &cbNeeded) ) { GetModuleBaseName( hProcess, hMod, szProcessName, sizeof(szProcessName)); if(utils::upcase(std::string(szProcessName)) == sProcessName && aProcesses[i] != ::GetCurrentProcessId()) { dwProcessID = aProcesses[i]; return hProcess; } } } } return CHandle(); }
//update position from render mesh void TCompCharacterController::UpdateMeshTransform() { PROFILE_FUNCTION("update: transform"); PxExtendedVec3 curr_pos = m_pActor->getFootPosition(); //PxVec3 up_v = pActor->getUpDirection(); //get rotation CEntity *e = CHandle(this).getOwner(); if (!e) return; TCompTransform *tmx = e->get<TCompTransform>(); tmx->setPosition(PxExVec3ToVec3(curr_pos)); //tmx->setRotation(PxQuatToCQuaternion(curr_pose.q)); }
void CMagneticBomb::Explode() { myHandle = CHandle(this); myParent = myHandle.getOwner(); dbg("MAGNETIC BOMB -> I am going to explode\n"); if (myHandle.isValid() && myParent.isValid()) { SendMsg(); //TODO: animation dbg("MAGNETIC BOMB -> exploded\n"); myParent.destroy(); } }
void TCompBoneTracker::update(float dt) { CEntity* e = h_entity; CEntity* my_e = CHandle(this).getOwner(); if (!e || !my_e) return; TCompSkeleton* skel = e->get<TCompSkeleton>(); if (!skel || bone_id == -1) return; auto bone = skel->model->getSkeleton()->getBone(bone_id); auto rot = Cal2Engine(bone->getRotationAbsolute()); auto trans = Cal2Engine(bone->getTranslationAbsolute()); TCompTransform* tmx = my_e->get<TCompTransform>(); assert(tmx); //if (local_tmx_saved) { MAT44 bone_world = MAT44::CreateFromQuaternion(rot); bone_world.Translation(trans); MAT44 new_tmx = local_tmx * bone_world; VEC3 scale; new_tmx.Decompose(scale, rot, trans); //} tmx->setPosition(trans); tmx->setRotation(rot); GET_COMP(physics, CHandle(this).getOwner(), TCompPhysics); if (physics) { physics->setPosition(trans, rot); } //PxRigidDynamic *rd; //if (rd = physics->getActor()->isRigidDynamic()) { // rd->setGlobalPose(PhysxConversion::ToPxTransform(trans, rot)); //} ////If I follow a bone and other bone is following me IK needs an extra update! //GET_COMP(comp_ik, h_entity, TCompSkeletonIK); //if (comp_ik) comp_ik->update(dt); }
void workbench_controller::readIniFileAttr() { CHandle h = CHandle(this).getOwner(); if (h.isValid()) { if (h.hasTag("workbench")) { CApp &app = CApp::get(); std::string file_ini = app.file_initAttr_json; map<std::string, float> fields = readIniAtrData(file_ini, "ai_workbench"); assignValueToVar(range, fields); assignValueToVar(rot_speed_sonar, fields); assignValueToVar(rot_speed_disable, fields); } } }
void TCompGuiButton::notifyOver(bool over) { // Cursor Message (for something?) TMsgOverButton msg; msg.button = CHandle(this).getOwner(); msg.is_over = over; cursor.sendMsg(msg); if (over) { logic_manager->throwEvent(CLogicManagerModule::EVENT::OnMouseOver, MY_NAME, MY_OWNER); } else { logic_manager->throwEvent(CLogicManagerModule::EVENT::OnMouseUnover, MY_NAME, MY_OWNER); } }
void bt_scientist::update(float elapsed) { // If we become possessed, reset the tree and stop all actions SetMyEntity(); if (!myEntity) return; if (first_update && !isInRoom(myParent))return; first_update = true; if (possessing) setCurrent(NULL); if (possessed) return; if (stunned) SET_ANIM_SCI_BT(AST_STUNNED); updateStuck(); updateTalk("Scientist", CHandle(this).getOwner()); Recalc(); }
void bt_scientist::Init() { getUpdateInfoBase(CHandle(this).getOwner()); //read main attributes from file readIniFileAttr(); om = getHandleManager<bt_scientist>(); myHandle = om->getHandleFromObjAddr(this); myParent = myHandle.getOwner(); if (tree.empty()) { addBtPossStates(); addChild("possessable", "scientist", PRIORITY, (btcondition)&bt_scientist::npcAvailable, NULL); // formation toggle addChild("scientist", "busystate", SEQUENCE, (btcondition)&bt_scientist::checkBusy, NULL); addChild("busystate", "selectworkstation", ACTION, NULL, (btaction)&bt_scientist::actionSelectWorkstation); addChild("busystate", "gotoworkstation", ACTION, NULL, (btaction)&bt_scientist::actionGoToWorkstation); addChild("busystate", "waitinworkstation", ACTION, NULL, (btaction)&bt_scientist::actionWaitInWorkstation); // create beacon sequence addChild("scientist", "createbeacon", SEQUENCE, (btcondition)&bt_scientist::workbenchAvailable, NULL); addChild("createbeacon", "aimcreate", ACTION, NULL, (btaction)&bt_scientist::actionAimToPos); addChild("createbeacon", "gocreate", ACTION, NULL, (btaction)&bt_scientist::actionMoveToPos); // patrol sequence addChild("scientist", "patrol", SEQUENCE, NULL, NULL); addChild("patrol", "nextwpt", ACTION, NULL, (btaction)&bt_scientist::actionNextWpt); addChild("patrol", "seekwpt", ACTION, NULL, (btaction)&bt_scientist::actionSeekWpt); addChild("patrol", "waitwpt", ACTION, NULL, (btaction)&bt_scientist::actionWaitWpt); } // transforms for the player SetMyEntity(); out[IDLE] = "IDLE"; out[WANDER] = "WANDER"; actual_action = IDLE; SetHandleMeInit(); //need to be initialized after all handles, ¿awake/init? ____TIMER_REDEFINE_(timerStunt, 15); t_waitInPos = 0; if (animController) { animController->setState(AST_IDLE); } SET_ANIM_SCI_BT(AST_IDLE); curkpt = 0; initParent(); }
bool CPlayerBase::getUpdateInfo() { myEntity = compBaseEntity; cc = compBaseEntity->get<TCompCharacterController>(); if (!cc) return false; transform = compBaseEntity->get<TCompTransform>(); if (!transform) return false; if (!h_sense_vision.isValid()) h_sense_vision = tags_manager.getFirstHavingTag("game_controller"); if (!h_sense_vision.isValid()) return false; sense_vision = GETH_COMP(h_sense_vision, TCompSenseVision); if (!sense_vision) return false; //Cache handle player CHandle myHandle = CHandle(compBaseEntity); if (myHandle.hasTag("player")) handle_player = myHandle; return true; }
void TCompLightDirShadowsDynamic::update(float dt) { PROFILE_FUNCTION("shadows: update"); if (io->keys['0'].becomesPressed()) { offset++; } if (io->keys['9'].becomesPressed()) { offset--; } if (!h_main_camera.isValid()) { if(!setCameraHandle()) return; } CHandle owner = CHandle(this).getOwner(); GET_COMP(t_camera, h_main_camera, TCompCameraMain); //check if component same room as player CEntity *e = owner; if (!e) return; TCompRoom* cam_room = e->get<TCompRoom>(); is_inRoom = ROOM_IS_IN(cam_room, SBB::readSala()); if (!is_inRoom) return; if (t_camera) { VEC3 target = t_camera->getPosition(); target += t_camera->getFront()*offset; if (last_position_target != target) { //check if there are changes between frames updateFromEntityTransform(owner); this->lookAt(getPosition(), target); last_position_target = target; } } //updateFromEntityTransform(owner); }
void TCompCharacterController::UpdateTags() { //PROFILE_FUNCTION("update tags"); CHandle h = CHandle(this).getOwner(); if (h.isValid()) { if (h.hasTag("player")) { //player m_filter.word0 |= ItLightensFilter::ePLAYER_BASE; m_filter.word0 |= ItLightensFilter::ePLAYER_CONTROLLED; m_filter.word1 &= ~ItLightensFilter::eTHROW; m_mass = 50.0f; } if (h.hasTag("AI_guard")) { m_filter.word0 |= ItLightensFilter::eGUARD; } if (h.hasTag("AI_poss")) m_filter.word0 |= ItLightensFilter::ePOSSESSABLE; } g_PhysxManager->setupFiltering(m_pActor->getActor(), m_filter); }
void bt_scientist::readIniFileAttr() { CHandle h = CHandle(this).getOwner(); if (h.isValid()) { if (h.hasTag("AI_cientifico")) { CApp &app = CApp::get(); std::string file_ini = app.file_initAttr_json; map<std::string, float> fields = readIniAtrData(file_ini, "bt_scientist"); readNpcIni(fields); //assignValueToVar(move_speed, fields); //assignValueToVar(rot_speed, fields); assignValueToVar(square_range_action, fields); assignValueToVar(max_wb_distance, fields); assignValueToVar(max_beacon_distance, fields); assignValueToVar(d_beacon_simple, fields); assignValueToVar(waiting_time, fields); assignValueToVar(t_waitInPos, fields); assignValueToVar(ws_wait_time, fields); assignValueToVar(ws_wait_time_offset, fields); } } }
void CThrowBomb::Explode() { logic_manager->throwEvent(CLogicManagerModule::EVENT::OnExplode, "throw_bomb", CHandle(this).getOwner()); SendMsg(); ChangeState("dead"); }
#include "mcv_platform.h" #include "comp_culling.h" #include "comp_aabb.h" #include "comp_camera.h" #include "comp_msgs.h" #include "entity.h" #include "handle/handle.h" #include "comp_room.h" #include "logic\sbb.h" #include "player_controllers/player_controller_base.h" int TCompCulling::next_to_update = 0; CHandle TCompCulling::camera_main = CHandle(); bool TCompCulling::cull_camera = true; void TCompCulling::renderInMenu() { // Show how many AABB's we are seeing... auto hm = getHandleManager<TCompAbsAABB>(); ImGui::Text("%d / %d AABB's visible", bits.count(), hm->size()); } // Si algun plano tiene la caja en la parte negativa // completamente, el aabb no esta dentro del set de planos bool TCompCulling::VPlanes::isVisible(const AABB* aabb) const { PROFILE_FUNCTION("TCompCulling: isVisible func"); if (empty()) return true; auto it = begin(); while (it != end()) { if (it->isCulled(aabb)) return false; ++it;
bool SkelControllerMole::getUpdateInfo() { owner = CHandle(this).getOwner(); if (!owner.isValid()) return false; return true; }
VEC3 TCompCharacterController::GetCameraPointFocus() const { CEntity *e = CHandle(this).getOwner(); TCompTransform *t = e->get<TCompTransform>(); return VEC3(0, m_height, 0) + (-t->getLeft()*m_radius); }
void CThrowBomb::Dead() { CHandle(this).getOwner().destroy(); return; //Nothing to do }
#include "components/comp_life.h" #include "components/entity.h" #include "components/entity_tags.h" #include "components/comp_msgs.h" #include "components/comp_camera_main.h" #include "components/comp_sense_vision.h" #include "app_modules/io/input_wrapper.h" #include "app_modules/logic_manager/logic_manager.h" #include "utils/utils.h" #include "components/comp_charactercontroller.h" map<int, string> CPlayerBase::out = {}; CHandle CPlayerBase::handle_player = CHandle(); CPlayerBase::CPlayerBase() { } void CPlayerBase::addBasicStates() { AddState("idle", (statehandler)&CPlayerBase::Idle); AddState("moving", (statehandler)&CPlayerBase::Moving); AddState("start_falling", (statehandler)&CPlayerBase::StartFalling); AddState("falling", (statehandler)&CPlayerBase::Falling); AddState("jumping", (statehandler)&CPlayerBase::Jumping); AddState("die", (statehandler)&CPlayerBase::Die); AddState("win", (statehandler)&CPlayerBase::Win); initBaseAttributes(); }