void VUINodeRotator::OnDragEnd(VWindowBase *pOver) { VString szLog; szLog.Format("OnDragEnd"); Text().SetText( szLog ); return; }
void VAppBase::SetupBaseDataDirectories() { VString sRoot; sRoot.Format(":%s", m_appConfig.m_sFileSystemRootName.AsChar()); VFileAccessManager::GetInstance()->ClearSearchPaths(); VFileAccessManager::GetInstance()->AddSearchPath(sRoot); VFileAccessManager::GetInstance()->AddSearchPath(sRoot + "/Data/Vision/Base"); VFileAccessManager::GetInstance()->AddSearchPath(":app_data", VSearchPathFlags::WRITABLE); }
void VUINodeRotator::OnDragBegin(const hkvVec2 &vMousePos, int iButtonMask) { VString szLog; szLog.Format("OnDragBegin %d %d", (int)vMousePos.x , (int)vMousePos.y ); Text().SetText( szLog ); m_vPivotPoint = vMousePos; m_vEndPoint = vMousePos; m_fPivotAngle = m_fAngle; return; }
VScalefromModelPreview::VScalefromModelPreview(VScaleformMovieInstance * pMainMovieInstance, VisBaseEntity_cl *pPreviewEntity, const char * szTextureName, const char * szMoviePathAndName, int iSizeX, int iSizeY, float fFovH, float fFovV) : m_pMainMovieInstance(pMainMovieInstance), m_sTextureName(szTextureName), m_sMoviePathAndName(szMoviePathAndName) { VASSERT_MSG(pMainMovieInstance!=NULL, "The main movie is required for VScalefromModelPreview!"); VASSERT_MSG(pPreviewEntity!=NULL, "Specify an entity for the VScalefromModelPreview!"); VASSERT_MSG(szTextureName!=NULL, "Specify a texture for the VScalefromModelPreview!"); //Scaleform::StringBuffer buffer2; //Scaleform::Memory::pGlobalHeap->MemReport(buffer2, Scaleform::MemoryHeap::MemReportFull); //Vision::Error.Warning("\n-----------------\n1st report:\n\n%s\n-----------------\n", buffer2.ToCStr()); VString sTargetName; sTargetName.Format("ScaleformModelPreviewComponent:%p", pPreviewEntity); m_spModelPreview = new VModelPreviewComponent(sTargetName.AsChar()); m_spModelPreview->CreateEmptyLightGrid(); m_spModelPreview->SetPreviewEntity(pPreviewEntity); #ifdef _VR_DX11 //this switch is required for Scaleform DX11, because it cannot handle typeless textures so far! bool bTypedRenderTargetsActive = Vision::Renderer.GetUseTypedRenderTargets()!=0; if(!bTypedRenderTargetsActive) Vision::Renderer.SetUseTypedRenderTargets(true); #endif #ifdef HK_DEBUG_SLOW bool bSuccess = #endif m_spModelPreview->InitComponent(iSizeX, iSizeY, fFovH, fFovV); #ifdef HK_DEBUG_SLOW VASSERT_MSG(bSuccess, "Failed to initialize internal model preview component!"); #endif #ifdef _VR_DX11 if(!bTypedRenderTargetsActive) Vision::Renderer.SetUseTypedRenderTargets(false); #endif Reassign(); //Scaleform::StringBuffer buffer; //Scaleform::Memory::pGlobalHeap->MemReport(buffer, Scaleform::MemoryHeap::MemReportFull); //Vision::Error.Warning("\n-----------------\n2nd report:\n\n%s\n-----------------\n", buffer.ToCStr()); Vision::Callbacks.OnEnterForeground += this; }
void RPG_CharacterStats::DebugPrintLastCharacterEventLogged() const { #ifdef _DEBUG if (m_recentCharacterEvents.GetSize() > 0) { VString msg; const RPG_CharacterEvent event = m_recentCharacterEvents.GetLast(); msg.Format("Event Logged: Type: %i, Time: %f, Value: %i, Message: %s\n", event.m_eventType, event.m_eventTime, event.m_eventValue, "<FIXME: NO MESSAGE>"); hkvLog::Info(msg.AsChar()); } #endif }
bool Channel::CreatePendingEvents(HANDLE serverMessagesEvent, HANDLE clientMessagesEvent) { VString serverEventname; serverEventname.Format("events.webvision.server.%u", m_id); VString clientEventname; clientEventname.Format("events.webvision.client.%u", m_id); if (m_mode == MODE_SERVER) { SECURITY_ATTRIBUTES securityAttributes; securityAttributes.nLength = sizeof(securityAttributes); securityAttributes.lpSecurityDescriptor = NULL; securityAttributes.bInheritHandle = TRUE; m_pendingServerMessagesEvent = serverMessagesEvent != NULL ? serverMessagesEvent : CreateEvent(&securityAttributes, TRUE, FALSE, serverEventname); m_pendingClientMessagesEvent = clientMessagesEvent != NULL ? clientMessagesEvent : CreateEvent(&securityAttributes, TRUE, FALSE, clientEventname); } else { m_pendingServerMessagesEvent = serverMessagesEvent != NULL ? serverMessagesEvent : OpenEvent(EVENT_ALL_ACCESS, FALSE, serverEventname); m_pendingClientMessagesEvent = clientMessagesEvent != NULL ? clientMessagesEvent : OpenEvent(EVENT_ALL_ACCESS, FALSE, clientEventname); } if (m_pendingServerMessagesEvent == NULL || m_pendingClientMessagesEvent == NULL) { return false; } return true; }
void RPG_CharacterStats::DebugPrintCharacterEventLog() const { #ifdef _DEBUG VString msg; for (unsigned int i = 0; i < m_recentCharacterEvents.GetSize(); ++i) { const RPG_CharacterEvent event = m_recentCharacterEvents[i]; msg.Format("EventType: %i, Time: %f, Value: %i, Message: %s\n", event.m_eventType, event.m_eventTime, event.m_eventValue, "<FIXME: NO MESSAGE>"); hkvLog::Info(msg.AsChar()); } msg = "-------------------------------------------------------"; hkvLog::Info(msg.AsChar()); #endif }
void VAppAndroid::SetupPlatformRootFileSystem() { VAppMobile::SetupPlatformRootFileSystem(); VString sDataDirPrefix; sDataDirPrefix.Format("%s?assets/", m_sApkDirectory.AsChar()); const VString& sRoot = m_appConfig.m_sFileSystemRootName; if(VFileServeDaemon::IsInitialized()) VFileAccessManager::GetInstance()->SetRoot(sRoot, VFileServeDaemon::GetInstance()->CreateFileSystem(sRoot, sDataDirPrefix)); else VFileAccessManager::GetInstance()->SetRoot(sRoot, sDataDirPrefix); VFileAccessManager::GetInstance()->SetRoot("app_data", GetApplicationDataDirectory(), VFileSystemFlags::WRITABLE); }
void RPG_Effect::Create(RPG_EffectDefinition const& effectDefinition, VisBaseEntity_cl* parentEntity) { VASSERT(parentEntity); m_parentEntity = parentEntity; bool validBone = false; if (!effectDefinition.m_vfxBoneName.IsEmpty()) { if (m_parentEntity->GetMesh()->GetSkeleton()->GetBoneIndexByName(effectDefinition.m_vfxBoneName.AsChar()) != -1) { validBone = true; } else { // warn the user if a bad bone name has been supplied. VString msg; msg.Format("Trying to spawn an RPG_Effect on character %s, at a nonexistent bone: %s.", parentEntity->GetTypeId()->m_lpszClassName, effectDefinition.m_vfxBoneName.AsChar()); hkvLog::Warning(msg.AsChar()); } } // attach this effect object to its parent entity, either at a bone or at its root if (validBone) { // valid bone. // create a proxy to attach the particle system to the named bone if none already exists if (!m_attachment) { m_attachment = new RPG_Attachment(m_parentEntity); } VASSERT(m_attachment); // attach the proxy to the parent bone m_attachment->Attach(this, effectDefinition.m_vfxBoneName, effectDefinition.m_vfxPositionOffset, effectDefinition.m_vfxOrientationOffset); } else { // attach this effect to its owning entity generally AttachToParent(m_parentEntity); ResetLocalTransformation(); // Set this RPG_Effect's local space position and orientation to (0/0/0) } UpdateBinding(); // Recompute the world space transformation from the current local space transformation // Create the effect. Sound and visual components will attach to this effect object, which is already attached to its parent. Create(effectDefinition, GetPosition(), GetOrientation()); }
void Vehicle::CacheEntities() { m_chassis = Vision::Game.SearchEntity("Cruiser"); VASSERT(m_chassis); m_camera = Vision::Game.SearchEntity("Camera"); VASSERT(m_camera); for (int wi = 0; wi < 4; wi ++) { VString entityName; entityName.Format("CruiserWheel%d", wi); m_wheel[wi] = Vision::Game.SearchEntity(entityName); VASSERT(m_wheel[wi]); } m_shadowLight = Vision::Game.SearchLightSource("CruiserShadow"); VASSERT(m_shadowLight); m_shadowLightOffset = m_shadowLight->GetRotationMatrix().transformDirection(hkvVec3(2500.0f, 0.0f, 0.0f)); }
void VUINodeRotator::OnDragging(const hkvVec2 &vMouseDelta) { const VRectanglef rect = GetClientRect(); hkvVec2 vCenter = ( rect.m_vMin + rect.m_vMax ) / 2.0f; hkvVec2 vMousePos = VUINodeMananger_cl::GlobalManager()->GetGUIContext()->GetCurrentMousePos(); hkvVec2 vDirection = vCenter - vMousePos; float fNewAngle = m_fAngle; if ( vDirection.y > 0 ) { fNewAngle -= vMouseDelta.x ; } else { fNewAngle += vMouseDelta.x; } if ( vDirection.x > 0 ) { fNewAngle += vMouseDelta.y; } else { fNewAngle -= vMouseDelta.y; } m_fAngleDelta = fNewAngle - m_fAngle; m_fAngle = fNewAngle; VString szLog; szLog.Format("OnDragging %.2f %.2f", vMouseDelta.x , vMouseDelta.y ); Text().SetText( szLog ); return; }
bool VRSDClientLuaImplementation::GetSubSymbolsForGlobal(char* GlobalName, DynArray_cl<VRSDScriptSymbol>& SubSymbols, unsigned int& SubSymbolCount) { VASSERT(m_pLuaState); if(!m_pLuaState || !m_pActivationRecord) return false; SubSymbolCount = 0; // we can only get local symbols without a crash if we are really in a Lua code execution path if(strcmp(m_pActivationRecord->what, "Lua")) return true; ScopedBooleanToTrue disableDebugCallback(m_bDebuggerRetrievingValues); VLuaStackCleaner stackCleaner(m_pLuaState); VMemoryTempBuffer<512> copyBuffer(GlobalName); // operate on a copy string in the tokenizer VStringTokenizerInPlace Tokenizer(copyBuffer.AsChar(), '.'); lua_getfield(m_pLuaState, LUA_GLOBALSINDEX, Tokenizer.Next()); if(LookupPath(Tokenizer) != HKV_SUCCESS) return false; // now the variable should be at the top of the stack and we can get the subvariables of it // first key for the iteration lua_pushnil(m_pLuaState); while (lua_next(m_pLuaState, -2) != 0) { // after this the key is at -2 and the value at -1 // we only want string fields and numeric fields // (lua_isstring returns also true for numbers, using // tostring later on will cast the number to a string) int iKeyType = lua_type(m_pLuaState, -2); if (iKeyType==LUA_TNUMBER || iKeyType==LUA_TSTRING) { VString sKeyBuffer; //this if prevents a conversion of number on the Lua stack if(iKeyType==LUA_TNUMBER) sKeyBuffer.Format("%1.0f", lua_tonumber(m_pLuaState, -2)); else sKeyBuffer = lua_tostring(m_pLuaState, -2); const char* pSymbolName = sKeyBuffer.AsChar(); if(pSymbolName) { // table member variable if(lua_istable(m_pLuaState, -1)) { // add a symbol for the table AddSymbol(SubSymbols, SubSymbolCount, pSymbolName, "table", VRSDScriptSymbol::SYMBOL_TABLE); } // numeric member variable else if(lua_type(m_pLuaState, -1) == LUA_TNUMBER) { char buffer[32]; sprintf(buffer, "%f", lua_tonumber(m_pLuaState, -1)); AddSymbol(SubSymbols, SubSymbolCount, pSymbolName, buffer, VRSDScriptSymbol::SYMBOL_NUMBER); } // string member variable else if(lua_type(m_pLuaState, -1) == LUA_TSTRING) { AddSymbol(SubSymbols, SubSymbolCount, pSymbolName, lua_tostring(m_pLuaState, -1), VRSDScriptSymbol::SYMBOL_STRING); } // function member variable else if(lua_isfunction(m_pLuaState, -1)) { AddSymbol(SubSymbols, SubSymbolCount, pSymbolName, "function", VRSDScriptSymbol::SYMBOL_FUNCTION); } // userdata member variable else if(lua_isuserdata(m_pLuaState, -1)) { char buffer[128]; swig_type_info* type = (swig_type_info *)LUA_GetSwigType(m_pLuaState, -1); void * pUserData = lua_touserdata(m_pLuaState, -1); if(type) { vis_snprintf(buffer, 128, "userdata:0x%p [%s: 0x%p]", pUserData, type->str, ((swig_lua_userdata*)pUserData)->ptr); } else { vis_snprintf(buffer, 128, "userdata:0x%p", lua_touserdata(m_pLuaState, -1)); } AddSymbol(SubSymbols, SubSymbolCount, pSymbolName, buffer, VRSDScriptSymbol::SYMBOL_USERDATA); } else if(lua_isboolean(m_pLuaState, -1)) { int iBoolVal = lua_toboolean(m_pLuaState, -1); AddSymbol(SubSymbols, SubSymbolCount, pSymbolName, iBoolVal ? "true" : "false", VRSDScriptSymbol::SYMBOL_BOOLEAN); } else if(lua_isnil(m_pLuaState, -1)) { AddSymbol(SubSymbols, SubSymbolCount, pSymbolName, "nil", VRSDScriptSymbol::SYMBOL_CLASS); } } } lua_pop(m_pLuaState, 1); // remove the value, keep the key for the next iteration } return true; }
bool VRSDClientLuaImplementation::GetSubSymbolsForLocal(char* LocalName, DynArray_cl<VRSDScriptSymbol>& SubSymbols, unsigned int& SubSymbolCount) { VASSERT(m_pLuaState); if(!m_pLuaState || !m_pActivationRecord) return false; SubSymbolCount = 0; // we can only get local symbols without a crash if we are really in a Lua code execution path if(strcmp(m_pActivationRecord->what, "Lua")) return true; VLuaStackCleaner stackCleaner(m_pLuaState); ScopedBooleanToTrue disableDebugCallback(m_bDebuggerRetrievingValues); char* pSymbolName = NULL; int iLocalIndex = 1; VMemoryTempBuffer<512> copyBuffer(LocalName); // operate on a copy string in the tokenizer VStringTokenizerInPlace Tokenizer(copyBuffer.AsChar(), '.'); char* pCurrent = Tokenizer.Next(); while((pSymbolName = (char*)lua_getlocal(m_pLuaState, m_pActivationRecord, iLocalIndex)) != NULL) { //stack: .., localX, TOP // check if this local variable is the one we want if(!strcmp(pSymbolName, pCurrent)) { //the local is already on the stack if(LookupPath(Tokenizer) != HKV_SUCCESS) return false; // now we can iterate over the contents of the table // first key for the iteration lua_pushnil(m_pLuaState); //stack: .., localX, {field}, nil, TOP //access the last field while (lua_next(m_pLuaState, -2) != 0) //stack: .., localX, {field}, key, value TOP { // we only want string fields and numeric fields // (lua_isstring returns also true for numbers, using // tostring later on will cast the number to a string) int iKeyType = lua_type(m_pLuaState, -2); if (iKeyType==LUA_TNUMBER || iKeyType==LUA_TSTRING) { VString sKeyBuffer; //this if prevents a conversion of number on the Lua stack if(iKeyType==LUA_TNUMBER) sKeyBuffer.Format("%1.0f", lua_tonumber(m_pLuaState, -2)); else sKeyBuffer = lua_tostring(m_pLuaState, -2); if(!sKeyBuffer.IsEmpty()) { int iValueType = lua_type(m_pLuaState, -1); VString sValueBuffer; // table member variable switch (iValueType) { case LUA_TTABLE: // add a symbol for the table AddSymbol(SubSymbols, SubSymbolCount, sKeyBuffer.AsChar(), "table", VRSDScriptSymbol::SYMBOL_TABLE); break; case LUA_TNUMBER: // numeric member variable sValueBuffer.Format("%f", lua_tonumber(m_pLuaState, -1)); AddSymbol(SubSymbols, SubSymbolCount, sKeyBuffer.AsChar(), sValueBuffer.AsChar(), VRSDScriptSymbol::SYMBOL_NUMBER); break; case LUA_TSTRING: AddSymbol(SubSymbols, SubSymbolCount, sKeyBuffer.AsChar(), lua_tostring(m_pLuaState, -1), VRSDScriptSymbol::SYMBOL_STRING); break; case LUA_TFUNCTION: sValueBuffer.Format("function:0x%p", lua_tocfunction(m_pLuaState, -1)); AddSymbol(SubSymbols, SubSymbolCount, sKeyBuffer.AsChar(), sValueBuffer.AsChar(), VRSDScriptSymbol::SYMBOL_FUNCTION); break; case LUA_TBOOLEAN: AddSymbol(SubSymbols, SubSymbolCount, sKeyBuffer.AsChar(), lua_toboolean(m_pLuaState, -1) ? "true" : "false", VRSDScriptSymbol::SYMBOL_BOOLEAN); break; case LUA_TNIL: AddSymbol(SubSymbols, SubSymbolCount, sKeyBuffer.AsChar(), "nil", VRSDScriptSymbol::SYMBOL_CLASS); break; case LUA_TTHREAD: sValueBuffer.Format("thread:0x%p", lua_tothread(m_pLuaState, -1)); AddSymbol(SubSymbols, SubSymbolCount, sKeyBuffer.AsChar(), sValueBuffer.AsChar(), VRSDScriptSymbol::SYMBOL_CLASS); break; case LUA_TUSERDATA: sValueBuffer.Format("userdata:0x%p", lua_touserdata(m_pLuaState, -1)); AddSymbol(SubSymbols, SubSymbolCount, sKeyBuffer.AsChar(), sValueBuffer.AsChar(), VRSDScriptSymbol::SYMBOL_USERDATA); break; default: AddSymbol(SubSymbols, SubSymbolCount, sKeyBuffer.AsChar(), "unknown", VRSDScriptSymbol::SYMBOL_STRING); break; } } } // remove the value, keep the key for the next iteration lua_pop(m_pLuaState, 1); //stack: .., localX, {field}, key, TOP } return true; } // clean up the stack and increment the index to get the next local variable lua_pop(m_pLuaState, 1); //stack: .., TOP iLocalIndex++; } return true; }
bool RPG_Effect::CreateVisualEffect(RPG_EffectDefinition const& effectDefinition, hkvVec3 const& position /*= hkvVec3(0.f, 0.f, 0.f)*/, hkvVec3 const& orientation /*= hkvVec3(0.f, 0.f, 0.f)*/) { VString vfxFilename = effectDefinition.m_vfxFilename; if (m_debugDisplay) { VString msg; if (m_parentEntity) { msg += m_parentEntity->GetTypeId()->m_lpszClassName; msg += " --> "; } msg += "Creating Particle FX: "; msg += vfxFilename.AsChar(); hkvLog::Info(msg.AsChar()); Vision::Message.Add(1, msg.AsChar()); } VisParticleEffect_cl* particleEffect = RPG_VisionEffectHelper::CreateParticleEffect(vfxFilename, position, orientation); if (!particleEffect) { hkvLog::Warning("Create Particle Effect failed: %s", vfxFilename.AsChar()); return false; } particleEffect->AttachToParent(this); // apply position offset, relative to the RPG_Effect object's transform if (!effectDefinition.m_vfxPositionOffset.isZero()) { particleEffect->SetLocalPosition(effectDefinition.m_vfxPositionOffset); } // apply orientation offset if (!effectDefinition.m_vfxOrientationOffset.isZero()) { particleEffect->SetLocalOrientation(effectDefinition.m_vfxOrientationOffset); } // by default, emitters update their position over time. We need to call TeleportSpawnPosition() to force them to update immediately. particleEffect->TeleportSpawnPosition(); // if this is a persistent effect, add it to the character's effect list. if (particleEffect && RPG_VisionEffectHelper::IsPersistentEffect(particleEffect)) { if (GetParent()) { particleEffect->SetRemoveWhenFinished(false); // if we're storing an effect here, we want to be responsible for its removal. m_persistentParticleEffect = particleEffect; } else { // a persistent effect was created, but not attached to a parent entity. Make some noise about this and shut it down. VString msg; msg.Format("Effect: %s is a looping effect, which must be attached to an entity capable of cleaning it up.", vfxFilename.AsChar()); hkvLog::Warning(msg.AsChar()); //VASSERT_MSG(false, "Effects containing looping particle systems MUST be parented to an entity which can manage their shutdown and cleanup."); particleEffect->SetFinished(); } } DebugDisplayParticleInformation(particleEffect); return true; }
VString SceneLoader::GetLastError() const { VSceneLoader& loader = VAppBase::Get()->GetAppImpl()->GetSceneLoader(); // If the scene wasn't found, attempt to figure out why and display something useful to the user. Do this // here (rather than at a lower level) because the vPlayer knows that all search paths _should_ be there - usually // search path don't have to exist, so it's difficult to generally find out WHY a file wasn't found. if(loader.IsNotFound()) { if(m_sceneListEntry.sSearchPaths.GetLength() == 0) { return "The list of search paths is empty"; } // Check all search paths - this is the most likely source when the scene wasn't found for(int i = 0; i < m_sceneListEntry.sSearchPaths.GetLength(); i++) { const VString& sSearchPath = m_sceneListEntry.sSearchPaths[i]; VStaticString<VFileAccessManager::MAX_ROOT_NAME_LENGTH> sSearchPathRoot; VFileAccessManager::SplitOffRoot(sSearchPath, sSearchPathRoot); if(VFileAccessManager::GetInstance()->GetRoot(sSearchPathRoot) == NULL) { VString error; error.Format("The root named '%s' is not mounted.", sSearchPathRoot.AsChar()); return error; } VStaticString<VFileAccessManager::MAX_ROOT_NAME_LENGTH> sSearchPathTopLevelDir; sSearchPathTopLevelDir.Format(":%s/", sSearchPathRoot.AsChar()); if(!VFileAccessManager::GetInstance()->DirectoryExists(sSearchPathTopLevelDir)) { VString error; if(VFileServeDaemon::IsInitialized()) { if(VFileServeDaemon::GetInstance()->IsConnected()) { error.Format("The root named '%s' is not accessible. Is this root mapped in vFileServe?", sSearchPathRoot.AsChar()); } else { error.Format("The root named '%s' is not accessible. The scene does not seem to be in the cache.", sSearchPathRoot.AsChar()); } } else { error.Format("The root named '%s' is not accessible.", sSearchPathRoot.AsChar()); } return error; } if(!VFileAccessManager::GetInstance()->DirectoryExists(sSearchPath)) { VString error; if(VFileServeDaemon::IsInitialized()) { if(VFileServeDaemon::GetInstance()->IsConnected()) { error.Format("The search path '%s' could not be found. Is vFileServe configured correctly?", sSearchPath.AsChar()); } else { error.Format("The search path '%s' could not be found. The scene does not seem to be in the cache.", sSearchPath.AsChar()); } } else { error.Format("The search path '%s' could not be found.", sSearchPath.AsChar()); } return error; } } // All search paths are okay, but the scene was not in any of them. It should usually be found in the first (= project dir), so display that one VString error; error.Format("The scene file was not found in '%s' or any other search directory.", m_sceneListEntry.sSearchPaths[0].AsChar()); return error; } return loader.GetLastError(); }
void RPG_Action_RangedAttack::Tick(float const deltaTime) { RPG_Action_AttackBase::Tick(deltaTime); if(m_attacking) { // RangedAttacking was set to true when the action was initiated. Is reset to false by Behavior when the attack anim finishes. vHavokBehaviorComponent *const behaviorComponent = m_characterOwner->GetBehaviorComponent(); VVERIFY_OR_RET(behaviorComponent); VASSERT(!m_behaviorTriggerVarName.IsEmpty()); if (!RPG_VisionHavokBehaviorHelper::BehaviorGetVarNamed<bool>(*behaviorComponent, m_behaviorTriggerVarName.AsChar())) { if (m_flags == 1) { if(m_updatedInteraction) { m_updatedInteraction = false; if(!m_updatedInteractionEntity && m_interactionEntity) { // Do not lose the player's intended target ValidateInteractionEntity(); if(!m_interactionEntity->Components().GetComponentOfType(V_RUNTIME_CLASS(RPG_AttackableComponent))) { m_interactionEntity = NULL; } else { if(m_interactionEntity->GetPosition().getDistanceToSquared(m_updatedInteractionPosition) > s_retargetingRadius * s_retargetingRadius) { m_interactionEntity = NULL; } } } else { m_interactionEntity = m_updatedInteractionEntity; ValidateInteractionEntity(); } m_interactionPosition = m_updatedInteractionPosition; } m_startTime = Vision::GetTimer()->GetTime(); StartAttack(); } else { // if we've gotten to the end and haven't fired the projectile, fire it now if (!m_hasFired) { VString msg; msg.Format("RPG_Action_RangedAttack never received expected %s event from Behavior.", m_behaviorFireEventName.AsChar()); Vision::Error.Warning(msg.AsChar()); //VASSERT_MSG(false, msg.AsChar()); FireAttack(); } End(); } } else { // we're currently attacking hkvVec3 const targetPosition = m_interactionEntity ? m_interactionEntity->GetPosition() : m_interactionPosition; FaceTargetPoint(targetPosition); #ifdef _DEBUG if (m_debugDisplayInfo) { Vision::Game.DrawSingleLine(m_characterOwner->GetPosition(), targetPosition, VColorRef(255, 0, 255)); } #endif } } else { StartAttack(); } }
void VCameraHandling::BuildCameraList() { VAppMenu* pMainMenu = GetParent()->GetAppModule<VAppMenu>(); if (pMainMenu == NULL) return; int iActionIndex = 0; VAppMenuItems menuItems; menuItems.Add(VAppMenuItem("<Switch to Free Camera>", iActionIndex++, 0, false)); #if defined(WIN32) && !defined(_VISION_WINRT) // Add option to disable WASD controls. m_iWASDActionIndex = iActionIndex++; menuItems.Add(VAppMenuItem("<Toggle Free Camera WASD Controls>", m_iWASDActionIndex, 1, true, m_bWASDEnabled)); #endif // Find camera objects in the scene. // Only store element manager indices in order to be able to detect removed objects. unsigned int uiNumOrbitCameras = 0; unsigned int uiNumCameraPositions = 0; unsigned int uiNumPathCameras = 0; const unsigned int uiNumEntities = VisBaseEntity_cl::ElementManagerGetSize(); for (unsigned int uiElementIndex = 0; uiElementIndex < uiNumEntities; uiElementIndex++) { VisBaseEntity_cl* pEntity = VisBaseEntity_cl::ElementManagerGet(uiElementIndex); if (pEntity == NULL) continue; // Try to convert the entity to all of the supported camera types. VOrbitCamera* pOrbitCamera = pEntity->Components().GetComponentOfBaseType<VOrbitCamera>(); CameraPositionEntity* pCameraPosition = vdynamic_cast<CameraPositionEntity*>(pEntity); PathCameraEntity* pPathCamera = vdynamic_cast<PathCameraEntity*>(pEntity); // Menu name data const char* szKey = ""; const char* szCameraType = ""; unsigned int uiSortingKey = 0; unsigned int uiCameraIndex = 0; if (pOrbitCamera != NULL) { // If the owner entity's key is not set, use the model's file name. const char* szKey = pEntity->GetObjectKey(); if (VStringUtil::IsEmpty(szKey)) szKey = (pEntity->GetMesh() ? pEntity->GetMesh()->GetFilename() : ""); szCameraType = "OrbitCamera"; uiSortingKey = 2; uiCameraIndex = uiNumOrbitCameras++; } else if (pCameraPosition != NULL) { szKey = pEntity->GetObjectKey(); szCameraType = "CameraPosition"; uiSortingKey = 3; uiCameraIndex = uiNumCameraPositions++; } else if (pPathCamera != NULL) { szKey = pEntity->GetObjectKey(); szCameraType = "PathCamera"; uiSortingKey = 4; uiCameraIndex = uiNumPathCameras++; } else { // If we haven't found a free camera entity yet, try to store this one. if (m_spFreeCamera == NULL) m_spFreeCamera = vdynamic_cast<VFreeCamera*>(pEntity); // No camera found. continue; } // Generate menu name. VString sMenuName; if (VStringUtil::IsEmpty(szKey)) sMenuName.Format("%s%02d", szCameraType, uiCameraIndex + 1); else sMenuName.Format("%s%02d (%s)", szCameraType, uiCameraIndex + 1, szKey); menuItems.Add(VAppMenuItem(sMenuName, iActionIndex, uiSortingKey, false)); m_actionMap.SetAt(iActionIndex++, EntityAccessor(pEntity, sMenuName)); } m_callbacks.Append(pMainMenu->RegisterGroup(m_sMenuGroupName, menuItems, NULL, VAPP_DEFAULT_SORTING_2 + 1)); RegisterCallbacks(); }
void MyGameManager::OnHandleCallback(IVisCallbackDataObject_cl *pData) { if (pData->m_pSender == &Vision::Callbacks.OnUpdateSceneBegin) { //This callback will be triggered at the beginning of every frame //You can add your own per frame logic here // [...] if (m_bPlayingTheGame) { Vision::Message.Print(1, 200, 100, "The game is running"); } return; } if (pData->m_pSender == &Vision::Callbacks.OnEditorModeChanged) { // when vForge switches back from EDITORMODE_PLAYING_IN_GAME, turn off our play the game mode if (((VisEditorModeChangedDataObject_cl *) pData)->m_eNewMode != VisEditorManager_cl::EDITORMODE_PLAYING_IN_GAME) SetPlayTheGame(false); return; } if (pData->m_pSender == &Vision::Callbacks.OnBeforeSceneLoaded) { //here you can add you specific code before the scene is loaded return; } if (pData->m_pSender == &Vision::Callbacks.OnAfterSceneLoaded) { //gets triggered when the play-the-game vForge is started or outside vForge after loading the scene if (Vision::Editor.IsPlayingTheGame()) SetPlayTheGame(true); /* spGUIContext = new VGUIMainContext(NULL); // Load some default resource (like the image for our cursor) VGUIManager::GlobalManager().LoadResourceFile("Dialogs\\MenuSystem.xml"); spGUIContext->SetActivate(true); spMainDlg = spGUIContext->ShowDialog("Dialogs\\MainMenu.xml"); VASSERT(spMainDlg); */ return; } if (pData->m_pSender == &Vision::Callbacks.OnWorldDeInit) { // this is important when running outside vForge SetPlayTheGame(false); return; } if (pData->m_pSender == &Vision::Callbacks.OnBeforeSceneUnloaded) { /* spMainDlg = NULL; // destroy the MainDlg Object spGUIContext->SetActivate(false); // Don't forget to deinit the GUI context spGUIContext = NULL; // destroy the GUI context */ return; } if (pData->m_pSender == &Vision::Callbacks.OnFrameUpdatePreRender) { // Holds packets RakNet::Packet* p; for (p=client->Receive(); p; client->DeallocatePacket(p), p=client->Receive()) { // We got a packet, get the identifier with our handy function auto packetIdentifier = GetPacketIdentifier(p); VString str; // Check if this is a network message packet switch (packetIdentifier) { case ID_DISCONNECTION_NOTIFICATION: // Connection lost normally Vision::Message.Add("ID_DISCONNECTION_NOTIFICATION\n"); break; case ID_INCOMPATIBLE_PROTOCOL_VERSION: Vision::Message.Add("ID_INCOMPATIBLE_PROTOCOL_VERSION\n"); break; case ID_REMOTE_DISCONNECTION_NOTIFICATION: // Server telling the clients of another client disconnecting gracefully. You can manually broadcast this in a peer to peer enviroment if you want. Vision::Message.Add("ID_REMOTE_DISCONNECTION_NOTIFICATION\n"); break; case ID_REMOTE_CONNECTION_LOST: // Server telling the clients of another client disconnecting forcefully. You can manually broadcast this in a peer to peer enviroment if you want. Vision::Message.Add("ID_REMOTE_CONNECTION_LOST\n"); break; case ID_REMOTE_NEW_INCOMING_CONNECTION: // Server telling the clients of another client connecting. You can manually broadcast this in a peer to peer enviroment if you want. Vision::Message.Add("ID_REMOTE_NEW_INCOMING_CONNECTION\n"); break; case ID_CONNECTION_BANNED: // Banned from this server Vision::Message.Add("We are banned from this server.\n"); break; case ID_CONNECTION_ATTEMPT_FAILED: Vision::Message.Add("Connection attempt failed\n"); break; case ID_NO_FREE_INCOMING_CONNECTIONS: // Sorry, the server is full. I don't do anything here but // A real app should tell the user Vision::Message.Add("ID_NO_FREE_INCOMING_CONNECTIONS\n"); break; case ID_INVALID_PASSWORD: Vision::Message.Add("ID_INVALID_PASSWORD\n"); break; case ID_CONNECTION_LOST: // Couldn't deliver a reliable packet - i.e. the other system was abnormally // terminated Vision::Message.Add("ID_CONNECTION_LOST\n"); break; case ID_CONNECTION_REQUEST_ACCEPTED: // This tells the client they have connected str.Format("ID_CONNECTION_REQUEST_ACCEPTED to %s with GUID %s\n",p->systemAddress.ToString(true), p->guid.ToString()); Vision::Message.Add(str); str.Format("My external address is %s\n", client->GetExternalID(p->systemAddress).ToString(true)); Vision::Message.Add(str); break; default: // It's a client, so just show the message //printf("%s\n", p->data); str.Format("Incoming message: %s",p->data); Vision::Message.Add(str); break; } } return; } }
void VDataDirectoryHelper::SelectAssetProfile(const char* szScene, bool bAllowFallbackProfile) { if (!bAllowFallbackProfile || (szScene == NULL) || !AssetProfile::IsProfileNameSet()) { return; } // Find the data directory of a scene file with the base name of the scene to open. It doesn't matter whether // that file is for a profile we're interested in - we just need it to find out the correct data directory. char szSceneBaseName[FS_MAX_PATH]; VPathHelper::GetFilenameNoExt(szSceneBaseName, szScene); VString sSearchPath; for (int i = -1; i < TARGETDEVICE_COUNT; ++i) { VString sSceneFileName; sSceneFileName.Format("%s%s%s.vscene", szSceneBaseName, i >= 0 ? "." : "", i >= 0 ? VTargetDeviceName[i] : ""); VScopedFileStream<IVFileInStream> fileStream(Vision::File.Open(sSceneFileName)); if (fileStream == NULL) { continue; } sSearchPath = fileStream->GetInitialSearchPath(); if (!sSearchPath.IsEmpty()) { break; } } // If we couldn't find out the data directory, give up. if (sSearchPath.IsEmpty()) { return; } // If we support the asset profile we intend to open, no further action is required. if (VFileAccessManager::GetInstance()->IsAssetProfileSupported(AssetProfile::GetProfileName(), sSearchPath)) { return; } // Are we on a platform that can fall back to DX9? If yes, try to do so. if ((VStringHelper::SafeCompare(AssetProfile::GetProfileName(), VTargetDeviceName[TARGETDEVICE_DX11]) == 0) || (VStringHelper::SafeCompare(AssetProfile::GetProfileName(), VTargetDeviceName[TARGETDEVICE_PS3]) == 0) || (VStringHelper::SafeCompare(AssetProfile::GetProfileName(), VTargetDeviceName[TARGETDEVICE_XBOX360]) == 0) || (VStringHelper::SafeCompare(AssetProfile::GetProfileName(), VTargetDeviceName[TARGETDEVICE_PSP2]) == 0) || (VStringHelper::SafeCompare(AssetProfile::GetProfileName(), VTargetDeviceName[TARGETDEVICE_WIIU]) == 0)) { if (VFileAccessManager::GetInstance()->IsAssetProfileSupported(VTargetDeviceName[TARGETDEVICE_DX9], sSearchPath)) { Vision::File.SetAssetProfile(VTargetDeviceName[TARGETDEVICE_DX9]); return; } } // Tizen may fall back to Android if ((VStringHelper::SafeCompare(AssetProfile::GetProfileName(), VTargetDeviceName[TARGETDEVICE_TIZEN]) == 0)) { if (VFileAccessManager::GetInstance()->IsAssetProfileSupported(VTargetDeviceName[TARGETDEVICE_ANDROID], sSearchPath)) { printf("Falling back to Android profile!"); // Set the corresponding variant keys for Android first... const int numVariantKeys = AssetVariantKeys::GetCount(); for (int i = 0; i < numVariantKeys; ++i) { if (VStringHelper::SafeCompare(AssetVariantKeys::Get(i), "Tizen-Default") == 0) { AssetVariantKeys::Add("Android-Default"); } else if (VStringHelper::SafeCompare(AssetVariantKeys::Get(i), "Tizen-PVR") == 0) { AssetVariantKeys::Add("Android-PVR"); } } // ...then switch the profile over. Vision::File.SetAssetProfile(VTargetDeviceName[TARGETDEVICE_ANDROID]); return; } } // if this is any other platform, just stick with the default profile, even though we did not find any aidlt file }
void VPostProcessFXAA::InitializePostProcessor() { if (m_bIsInitialized || !m_bActive) return; SetupContext(); // Load glow shader library BOOL bResult = Vision::Shaders.LoadShaderLibrary("\\Shaders\\FXAA.ShaderLib", SHADERLIBFLAG_HIDDEN) != NULL; VASSERT(bResult); // file not found? GetTargetContext()->GetSize(m_iWidth, m_iHeight); m_spMask = new VisScreenMask_cl(); m_spMask->SetPos(0,0); m_spMask->SetTargetSize((float)m_iWidth,(float)m_iHeight); m_spMask->SetTextureRange(0.0f, 0.0f, (float)m_iWidth, (float)m_iHeight); #ifdef _VR_DX9 m_spMask->SetUseOpenGLTexelShift(TRUE); #else m_spMask->SetUseOpenGLTexelShift(FALSE); #endif //m_spMask->SetUseOpenGLTexelShift(FALSE); m_spMask->SetTransparency(VIS_TRANSP_NONE); m_spMask->SetVisible(FALSE); m_spMask->SetDepthWrite(FALSE); m_spMask->SetWrapping(FALSE, FALSE); m_spMask->SetVisibleBitmask(0); // this mask is rendered manually via a collection // no wireframe for this mask VSimpleRenderState_t s = m_spMask->GetRenderState(); s.SetFlag(RENDERSTATEFLAG_NOWIREFRAME); m_spMask->SetRenderState(s); VTechniqueConfig vc; VString tags; tags.Format("FXAA_PRESET=%d", (int)Quality); vc.SetInclusionTags(tags); VCompiledTechnique *pTech = Vision::Shaders.CreateTechnique("FXAA", NULL, &vc, EFFECTFLAGS_FORCEUNIQUE); VASSERT(pTech!=NULL && "Could not create technique for FXAA postprocessor!"); m_spMask->SetTechnique(pTech); m_spMask->SetTransparency(VIS_TRANSP_NONE); VShaderConstantBuffer *pPS = pTech->GetShader(0)->GetConstantBuffer(VSS_PixelShader); m_iRegScreenSize = pPS->GetRegisterByName("rcpFrame"); // make frame copy only if this is not the last PP bool bFrameCopy = !IsLastComponent(); if (bFrameCopy && GetTargetContext()->GetRenderTarget() == m_spSourceTextures[0]) { m_spFrameCopyTexture = ScratchTexturePool_cl::GlobalManager().GetScratchTexture(m_iWidth, m_iHeight, m_spSourceTextures[0]->GetTextureFormat(), 0); m_spMask->SetTextureObject(m_spFrameCopyTexture); } else { m_spFrameCopyTexture = NULL; m_spMask->SetTextureObject(m_spSourceTextures[0]); } m_bIsInitialized = true; }