void NounShip::updateContacts() { PROFILE_FUNCTION(); m_Contacts.release(); Array< GameContext::NounCollision > contacts; context()->proximityCheck( worldPosition(), MAX_SCANNER_RANGE, contacts ); for(int j=0;j<contacts.size();j++) { Noun * pContact = contacts[j].pNoun; if ( canDetect( pContact ) ) { m_Contacts.push( pContact ); // we only bother with checking planet's for sub-contacts for now... if ( WidgetCast<NounPlanet>( pContact ) ) { // check if we can detect the children of this object for(int i=0;i<pContact->childCount();i++) { Noun * pChild = (Noun *)pContact->child(i); if ( canDetect( pChild ) ) m_Contacts.push( pChild ); } } } } // clear any invalid projectiles from the incoming list.. for(int i=0;i<m_Incoming.size();) { if (! m_Incoming[i].valid() ) m_Incoming.removeSwap( i ); else ++i; } }
void frame() { PROFILE_FUNCTION(); MT::SpinLock lock(g_instance.m_mutex); g_instance.frame_listeners.invoke(); float now = g_instance.timer->getTimeSinceStart(); for (auto* i : g_instance.threads) { if (!i->root_block) continue; i->root_block->frame(); auto* block = i->current_block; while (block) { auto& hit = block->m_hits.emplace(); hit.m_start = now; hit.m_length = 0; block = block->m_parent; } } }
void Texture::loaded(FS::IFile& file, bool success, FS::FileSystem& fs) { PROFILE_FUNCTION(); if (success) { const char* path = m_path.c_str(); size_t len = m_path.length(); bool loaded = false; if (len > 3 && strcmp(path + len - 4, ".dds") == 0) { loaded = loadDDS(file); } else if (len > 3 && strcmp(path + len - 4, ".raw") == 0) { loaded = loadRaw(file); } else { loaded = loadTGA(file); } if (!loaded) { g_log_warning.log("renderer") << "Error loading texture " << m_path.c_str(); onFailure(); } else { m_size = file.size(); decrementDepCount(); } } else { g_log_warning.log("renderer") << "Error loading texture " << m_path.c_str(); onFailure(); } }
void TSRParticleSystemManager::RenderParticles( std::vector< TSRParticlesSceneEntity* >& _aParticleSystems, bool _bDeffered ) { PROFILE_FUNCTION( "Render Particles" ); g_ParticlesSection.Begin(); TSRShaderEffect* pShader = _bDeffered ? m_pOffscreenParticlesShader : m_pForwardParticlesShader; if ( _bDeffered ) { Graphics()->SetRenderTarget( m_pRenderTarget, 0 ); ///TSRGlobalConstants.m_DepthTexture.Set( *( Graphics()->m_pDepthTarget ) ); Graphics()->SetClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); Graphics()->Clear( TWISTER_CLEARFLAGS_COLOR ); } TSRMaterial material; material.m_vDiffuseColor.Assign( 1.0f, 1.0f, 1.0f, 1.0f ); material.m_vSpecularColor.Assign( 0.24f, 0.2f, 0.22f, 1.0f ); material.m_vSpecularPowerBumpiness.Assign( 1024.0f, 1.0f ); TSRGlobalConstants.SetMaterial( material ); // enable alpha blending and disable z writing Graphics()->SetBlendState( Graphics()->m_BlendAdditiveColor ); Graphics()->SetDepthStencilState( Graphics()->m_DepthTestEnabledWriteDisabled ); for ( unsigned int i = 0; i < _aParticleSystems.size(); i++ ) { TSRParticlesSceneEntity* pCurr = _aParticleSystems[ i ]; pCurr->Render( pShader, m_pParticlesMesh ); } Graphics()->SetDepthStencilState( Graphics()->m_DefaultDepthStencilState ); Graphics()->SetBlendState( Graphics()->m_BlendDisabled ); if ( _bDeffered ) { Graphics()->RestoreDefaultRenderTarget(); } g_ParticlesSection.End(); }
void update(UniverseContext& context) override { PROFILE_FUNCTION(); float dt; ++m_fps_frame; if (m_fps_timer->getTimeSinceTick() > 0.5f) { m_fps = m_fps_frame / m_fps_timer->tick(); m_fps_frame = 0; } dt = m_timer->tick(); m_last_time_delta = dt; { PROFILE_BLOCK("update scenes"); for (int i = 0; i < context.m_scenes.size(); ++i) { context.m_scenes[i]->update(dt); } } m_plugin_manager->update(dt); m_input_system->update(dt); getFileSystem().updateAsyncTransactions(); }
//recalc if the controller is on ground void TCompCharacterController::RecalcOnGround() { PROFILE_FUNCTION("recalc: onground"); m_lastOnGround = m_OnGround; if (!m_affectGravity) return; if (m_flagsCollisions & PxControllerFlag::eCOLLISION_DOWN) { m_OnGround = true; m_physxOnground = true; } else { m_OnGround = false; m_physxOnground = false; } /*else { //raycast to look for down distance PxQueryFilterData filterData; filterData.data.word0 = ItLightensFilter::eSCENE | ItLightensFilter::eOBJECT; PxRaycastBuffer hit; bool hit_ground = g_PhysxManager->raycast(GetFootPosition(), PhysxConversion::PxVec3ToVec3(-m_pActor->getUpDirection()), 0.1f, hit, filterData); if (hit_ground) { auto h = PhysxConversion::GetEntityHandle(*hit.getAnyHit(0).actor); if (!h.isValid()) { return; } if (h.hasTag("platform")) { hit_ground = false; } else { if (h.hasTag("drone")) { hit_ground = false; } } } m_OnGround = hit_ground; m_physxOnground = false; }*/ }
int bt_scientist::actionWaitInWorkstation() { PROFILE_FUNCTION("scientist: waitinworkbench"); if (!myParent.isValid()) return false; stuck = false; stuck_time = 0.f; // Turn to the workstation if (!turnToYaw(ws_yaw)) { return STAY; } // Execute the workstation animation //animController.setAnim(ws_anim); // we add a randomly generated offset to the waiting time int sign = rand() % 100; int offset = rand() % (int)ws_wait_time_offset; float total_wait_time = ws_wait_time; if (sign < 50) total_wait_time -= offset; else total_wait_time += offset; if (ws_time_waited > total_wait_time) { ws_time_waited = 0.f; return OK; } else { ws_time_waited += getDeltaTime(); SET_ANIM_SCI_BT(AST_IDLE); return STAY; } return OK; }
int bt_scientist::actionSeekWpt() { PROFILE_FUNCTION("scientist: actionseekwpt"); SetMyEntity(); //needed in case address Entity moved by handle_manager if (!myEntity) return KO; TCompTransform *me_transform = myEntity->get<TCompTransform>(); VEC3 myPos = me_transform->getPosition(); VEC3 dest = keyPoints[curkpt].pos; //Go to waypoint if (keyPoints[curkpt].type == Seek) { //reach waypoint? if (simpleDistXZ(myPos, dest) < DIST_REACH_PNT) { curkpt = (curkpt + 1) % keyPoints.size(); return OK; } else { //getPath(myPos, dest); //animController.setState(AST_RUN); goTo(dest); SET_ANIM_SCI_BT(AST_MOVE); return STAY; } } //Look to waypoint else if (keyPoints[curkpt].type == Look) { //Look to waypoint if (turnTo(dest)) { curkpt = (curkpt + 1) % keyPoints.size(); return OK; } else { SET_ANIM_SCI_BT(AST_MOVE); return STAY; } } return OK; }
//recalc actual speed from acceleration void TCompCharacterController::RecalcSpeed(float dt) { PROFILE_FUNCTION("update: speed"); //update y speed based on y gravity if (m_affectGravity) { if (!m_OnGround) { assert(isValid(m_speed)); m_speed.y += m_gravitySpeed*dt; assert(isValid(m_speed)); } } //update final speed assert(isValid(m_speed)); m_speed += m_accel*dt; assert(isValid(m_speed)); //calc if there are some speed to sum at speed from own rigidbdy speed /*if (!m_OnGround && m_lastOnGround) { assert(isValid(m_speed)); VEC3 speed = PhysxConversion::PxVec3ToVec3(m_last_speed); speed.y = 0; m_speed += speed; assert(isValid(m_speed)); }*/ //calc if some speed is too low. if true, will be assigned at 0 float abs_x = abs(m_speed.x); float abs_z = abs(m_speed.z); if (abs_x < m_eOffsetSpeed) m_speed.x = 0; if (abs_z < m_eOffsetSpeed) m_speed.z = 0; }
bool Texture::loadRaw(FS::IFile& file) { PROFILE_FUNCTION(); size_t size = file.size(); m_BPP = 2; m_width = (int)sqrt(size / m_BPP); m_height = m_width; if (m_data_reference) { m_data.resize(size); file.read(&m_data[0], size); } const uint16_t* src_mem = (const uint16_t*)file.getBuffer(); const bgfx::Memory* mem = bgfx::alloc(m_width * m_height * sizeof(float)); float* dst_mem = (float*)mem->data; for (int i = 0; i < m_width * m_height; ++i) { dst_mem[i] = src_mem[i] / 65535.0f; } m_texture_handle = bgfx::createTexture2D( m_width, m_height, 1, bgfx::TextureFormat::R32F, m_flags, nullptr); bgfx::updateTexture2D( m_texture_handle, 0, 0, 0, m_width, m_height, mem); m_depth = 1; return bgfx::isValid(m_texture_handle); }
void SceneView::update() { PROFILE_FUNCTION(); if (ImGui::IsAnyItemActive()) return; if (!m_is_opened) return; if (ImGui::GetIO().KeyCtrl) return; int screen_x = int(ImGui::GetIO().MousePos.x); int screen_y = int(ImGui::GetIO().MousePos.y); bool is_inside = screen_x >= m_screen_x && screen_y >= m_screen_y && screen_x <= m_screen_x + m_width && screen_y <= m_screen_y + m_height; if (!is_inside) return; m_camera_speed = Lumix::Math::maximum(0.01f, m_camera_speed + ImGui::GetIO().MouseWheel / 20.0f); float speed = m_camera_speed; if (ImGui::GetIO().KeyShift) speed *= 10; if (m_move_forward_action->isActive()) m_editor->navigate(1.0f, 0, 0, speed); if (m_move_back_action->isActive()) m_editor->navigate(-1.0f, 0, 0, speed); if (m_move_left_action->isActive()) m_editor->navigate(0.0f, -1.0f, 0, speed); if (m_move_right_action->isActive()) m_editor->navigate(0.0f, 1.0f, 0, speed); if (m_move_down_action->isActive()) m_editor->navigate(0, 0, -1.0f, speed); if (m_move_up_action->isActive()) m_editor->navigate(0, 0, 1.0f, speed); }
void GameView::onGui() { PROFILE_FUNCTION(); if (!m_pipeline->isReady()) return; auto& io = ImGui::GetIO(); bool is_foreground_win = PlatformInterface::isWindowActive(); if (m_is_mouse_captured && (io.KeysDown[ImGui::GetKeyIndex(ImGuiKey_Escape)] || !m_editor->isGameMode() || !is_foreground_win)) { captureMouse(false); } const char* window_name = "Game View###game_view"; if (m_is_mouse_captured) window_name = "Game View (mouse captured)###game_view"; if (ImGui::BeginDock(window_name, &m_is_opened)) { m_is_mouse_hovering_window = ImGui::IsMouseHoveringWindow(); auto content_min = ImGui::GetCursorScreenPos(); auto size = ImGui::GetContentRegionAvail(); size.y -= ImGui::GetTextLineHeightWithSpacing(); ImVec2 content_max(content_min.x + size.x, content_min.y + size.y); if (size.x > 0 && size.y > 0) { auto pos = ImGui::GetWindowPos(); auto cp = ImGui::GetCursorPos(); m_pipeline->setViewport(0, 0, int(size.x), int(size.y)); auto* fb = m_pipeline->getFramebuffer("default"); m_texture_handle = fb->getRenderbufferHandle(0); ImGui::Image(&m_texture_handle, size); if (ImGui::Checkbox("Pause", &m_paused)) { m_editor->getEngine().pause(m_paused); } if (m_paused) { ImGui::SameLine(); if (ImGui::Button("Next frame")) { m_editor->getEngine().nextFrame(); } } ImGui::SameLine(); if (ImGui::DragFloat("m_time_multiplier", &m_time_multiplier, 0.01f, 0.01f, 30.0f)) { m_editor->getEngine().setTimeMultiplier(m_time_multiplier); } m_pipeline->render(); } if (m_is_mouse_captured) { PlatformInterface::clipCursor( content_min.x, content_min.y, content_max.x, content_max.y); if (io.KeysDown[ImGui::GetKeyIndex(ImGuiKey_Escape)] || !m_editor->isGameMode()) { captureMouse(false); } } if (ImGui::IsMouseHoveringRect(content_min, content_max) && m_is_mouse_hovering_window && ImGui::IsMouseClicked(0) && m_editor->isGameMode()) { captureMouse(true); } } ImGui::EndDock(); }
void TCompCharacterController::AddMovement(const VEC3& direction, float speed) { PROFILE_FUNCTION("add move"); assert(isValid(m_toMove)); m_toMove += direction*speed; assert(isValid(m_toMove)); }
bool Texture::loadTGA(FS::IFile& file) { PROFILE_FUNCTION(); TGAHeader header; file.read(&header, sizeof(header)); int color_mode = header.bitsPerPixel / 8; int image_size = header.width * header.height * 4; if (header.dataType != 2) { g_log_error.log("renderer") << "Unsupported texture format " << m_path.c_str(); return false; } if (color_mode < 3) { g_log_error.log("renderer") << "Unsupported color mode " << m_path.c_str(); return false; } m_width = header.width; m_height = header.height; TextureManager* manager = static_cast<TextureManager*>( getResourceManager().get(ResourceManager::TEXTURE)); if (m_data_reference) { m_data.resize(image_size); } uint8_t* image_dest = m_data_reference ? &m_data[0] : (uint8_t*)manager->getBuffer(image_size); // Targa is BGR, swap to RGB, add alpha and flip Y axis for (long y = 0; y < header.height; y++) { long read_index = y * header.width * color_mode; long write_index = ((header.imageDescriptor & 32) != 0) ? read_index : y * header.width * 4; for (long x = 0; x < header.width; x++) { file.read(&image_dest[write_index + 2], sizeof(uint8_t)); file.read(&image_dest[write_index + 1], sizeof(uint8_t)); file.read(&image_dest[write_index + 0], sizeof(uint8_t)); if (color_mode == 4) file.read(&image_dest[write_index + 3], sizeof(uint8_t)); else image_dest[write_index + 3] = 255; write_index += 4; } } m_BPP = 4; m_texture_handle = bgfx::createTexture2D( header.width, header.height, 1, bgfx::TextureFormat::RGBA8, m_flags, 0); bgfx::updateTexture2D( m_texture_handle, 0, 0, 0, header.width, header.height, bgfx::copy(image_dest, header.width * header.height * 4)); m_depth = 1; return bgfx::isValid(m_texture_handle); }
bool Material::load(FS::IFile& file) { PROFILE_FUNCTION(); m_render_states = BGFX_STATE_DEPTH_TEST_LEQUAL | BGFX_STATE_CULL_CW; m_uniforms.clear(); JsonSerializer serializer(file, JsonSerializer::READ, getPath().c_str(), m_allocator); serializer.deserializeObjectBegin(); char path[MAX_PATH_LENGTH]; char label[256]; char material_dir[MAX_PATH_LENGTH]; PathUtils::getDir(material_dir, MAX_PATH_LENGTH, getPath().c_str()); bool b_value; while (!serializer.isObjectEnd()) { serializer.deserializeLabel(label, 255); if (compareString(label, "uniforms") == 0) { deserializeUniforms(serializer); } else if (compareString(label, "texture") == 0) { if (!deserializeTexture(serializer, material_dir)) { return false; } } else if (compareString(label, "alpha_cutout") == 0) { bool b; serializer.deserialize(b, false); enableAlphaCutout(b); } else if (compareString(label, "alpha_blending") == 0) { if (serializer.isNextBoolean()) { bool is_alpha_blending; serializer.deserialize(is_alpha_blending, false); if (is_alpha_blending) { m_render_states |= BGFX_STATE_BLEND_ADD; } else { m_render_states &= ~BGFX_STATE_BLEND_MASK; } } else { serializer.deserialize(label, 255, "alpha"); if (compareString(label, "alpha") == 0) { m_render_states |= BGFX_STATE_BLEND_ALPHA; } else if (compareString(label, "add") == 0) { m_render_states |= BGFX_STATE_BLEND_ADD; } else if (compareString(label, "disabled") == 0) { m_render_states &= ~BGFX_STATE_BLEND_MASK; } } } else if (compareString(label, "specular") == 0) { serializer.deserializeArrayBegin(); serializer.deserializeArrayItem(m_specular.x, 1.0f); serializer.deserializeArrayItem(m_specular.y, 1.0f); serializer.deserializeArrayItem(m_specular.z, 1.0f); serializer.deserializeArrayEnd(); } else if (compareString(label, "shininess") == 0) { serializer.deserialize(m_shininess, 4.0f); } else if (compareString(label, "shadow_receiver") == 0) { bool b; serializer.deserialize(b, true); enableShadowReceiving(b); } else if (compareString(label, "shader") == 0) { serializer.deserialize(path, MAX_PATH_LENGTH, ""); setShader(static_cast<Shader*>( m_resource_manager.get(ResourceManager::SHADER)->load(Path(path)))); } else if (compareString(label, "z_test") == 0) { serializer.deserialize(b_value, true); enableZTest(b_value); } else if (compareString(label, "backface_culling") == 0) { serializer.deserialize(b_value, true); enableBackfaceCulling(b_value); } else { g_log_warning.log("renderer") << "Unknown parameter " << label << " in material " << getPath().c_str(); } } serializer.deserializeObjectEnd(); if (!m_shader) { g_log_error.log("renderer") << "Material " << getPath().c_str() << " without a shader"; return false; } m_size = file.size(); return true; }
void AssetBrowser::update() { PROFILE_FUNCTION(); auto* patch = m_editor.getEngine().getPatchFileDevice(); if ((patch && !Lumix::equalStrings(patch->getBasePath(), m_patch_base_path)) || (!patch && m_patch_base_path[0] != '\0')) { findResources(); } if (!m_is_update_enabled) return; bool is_empty; { Lumix::MT::SpinLock lock(m_changed_files_mutex); is_empty = m_changed_files.empty(); } while (!is_empty) { Lumix::Path path; { Lumix::MT::SpinLock lock(m_changed_files_mutex); path = m_changed_files.back(); m_changed_files.pop(); is_empty = m_changed_files.empty(); } char ext[10]; Lumix::PathUtils::getExtension(ext, Lumix::lengthOf(ext), path.c_str()); m_on_resource_changed.invoke(path, ext); Lumix::uint32 resource_type = getResourceType(path.c_str()); if (resource_type == 0) continue; if (m_autoreload_changed_resource) m_editor.getEngine().getResourceManager().reload(path); char tmp_path[Lumix::MAX_PATH_LENGTH]; if (m_editor.getEngine().getPatchFileDevice()) { Lumix::copyString(tmp_path, m_editor.getEngine().getPatchFileDevice()->getBasePath()); Lumix::catString(tmp_path, path.c_str()); } if (!m_editor.getEngine().getPatchFileDevice() || !PlatformInterface::fileExists(tmp_path)) { Lumix::copyString(tmp_path, m_editor.getEngine().getDiskFileDevice()->getBasePath()); Lumix::catString(tmp_path, path.c_str()); if (!PlatformInterface::fileExists(tmp_path)) { int index = getTypeIndexFromManagerType(resource_type); m_resources[index].eraseItemFast(path); continue; } } char dir[Lumix::MAX_PATH_LENGTH]; char filename[Lumix::MAX_PATH_LENGTH]; Lumix::PathUtils::getDir(dir, sizeof(dir), path.c_str()); Lumix::PathUtils::getFilename(filename, sizeof(filename), path.c_str()); addResource(dir, filename); } m_changed_files.clear(); }
void SceneView::onGUI() { PROFILE_FUNCTION(); m_is_opened = false; ImVec2 view_pos; const char* title = "Scene View###Scene View"; if (m_log_ui && m_log_ui->getUnreadErrorCount() > 0) { title = "Scene View | errors in log###Scene View"; } if (ImGui::BeginDock(title, nullptr, ImGuiWindowFlags_NoScrollWithMouse)) { m_is_opened = true; auto size = ImGui::GetContentRegionAvail(); size.y -= ImGui::GetTextLineHeightWithSpacing(); auto* fb = m_pipeline->getFramebuffer("default"); if (size.x > 0 && size.y > 0 && fb) { auto pos = ImGui::GetWindowPos(); m_pipeline->setViewport(0, 0, int(size.x), int(size.y)); m_texture_handle = fb->getRenderbufferHandle(0); auto cursor_pos = ImGui::GetCursorScreenPos(); m_screen_x = int(cursor_pos.x); m_screen_y = int(cursor_pos.y); m_width = int(size.x); m_height = int(size.y); auto content_min = ImGui::GetCursorScreenPos(); ImVec2 content_max(content_min.x + size.x, content_min.y + size.y); if (m_is_opengl) { ImGui::Image(&m_texture_handle, size, ImVec2(0, 1), ImVec2(1, 0)); } else { ImGui::Image(&m_texture_handle, size); } view_pos = content_min; auto rel_mp = ImGui::GetMousePos(); rel_mp.x -= m_screen_x; rel_mp.y -= m_screen_y; if (ImGui::IsItemHovered()) { m_editor->getGizmo().enableStep(m_toggle_gizmo_step_action->isActive()); for (int i = 0; i < 3; ++i) { if (ImGui::IsMouseClicked(i)) { ImGui::ResetActiveID(); if(i == 1) captureMouse(true); m_editor->onMouseDown((int)rel_mp.x, (int)rel_mp.y, (Lumix::MouseButton::Value)i); break; } } } if (m_is_mouse_captured || ImGui::IsItemHovered()) { auto& input = m_editor->getEngine().getInputSystem(); auto delta = Lumix::Vec2(input.getMouseXMove(), input.getMouseYMove()); if (delta.x != 0 || delta.y != 0) { m_editor->onMouseMove((int)rel_mp.x, (int)rel_mp.y, (int)delta.x, (int)delta.y); } } for (int i = 0; i < 3; ++i) { auto rel_mp = ImGui::GetMousePos(); rel_mp.x -= m_screen_x; rel_mp.y -= m_screen_y; if (ImGui::IsMouseReleased(i)) { if (i == 1) captureMouse(false); m_editor->onMouseUp((int)rel_mp.x, (int)rel_mp.y, (Lumix::MouseButton::Value)i); } } m_pipeline->render(); } ImGui::PushItemWidth(60); ImGui::DragFloat("Camera speed", &m_camera_speed, 0.1f, 0.01f, 999.0f, "%.2f"); ImGui::SameLine(); if (m_editor->isMeasureToolActive()) { ImGui::Text("| Measured distance: %f", m_editor->getMeasuredDistance()); } ImGui::SameLine(); int step = m_editor->getGizmo().getStep(); if (ImGui::DragInt("Gizmo step", &step, 1.0f, 0, 200)) { m_editor->getGizmo().setStep(step); } ImGui::SameLine(); ImGui::Checkbox("Stats", &m_show_stats); m_pipeline->callLuaFunction("onGUI"); } ImGui::EndDock(); if(m_show_stats) { view_pos.x += ImGui::GetStyle().FramePadding.x; view_pos.y += ImGui::GetStyle().FramePadding.y; ImGui::SetNextWindowPos(view_pos); auto col = ImGui::GetStyle().Colors[ImGuiCol_WindowBg]; col.w = 0.3f; ImGui::PushStyleColor(ImGuiCol_WindowBg, col); if (ImGui::Begin("###stats_overlay", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_ShowBorders)) { const auto& stats = m_pipeline->getStats(); ImGui::LabelText("Draw calls", "%d", stats.draw_call_count); ImGui::LabelText("Instances", "%d", stats.instance_count); char buf[30]; Lumix::toCStringPretty(stats.triangle_count, buf, Lumix::lengthOf(buf)); ImGui::LabelText("Triangles", "%s", buf); ImGui::LabelText("Resolution", "%dx%d", m_pipeline->getWidth(), m_pipeline->getHeight()); ImGui::LabelText("FPS", "%.2f", m_editor->getEngine().getFPS()); ImGui::LabelText("CPU time", "%.2f", m_pipeline->getCPUTime() * 1000.0f); ImGui::LabelText("GPU time", "%.2f", m_pipeline->getGPUTime() * 1000.0f); ImGui::LabelText("Waiting for submit", "%.2f", m_pipeline->getWaitSubmitTime() * 1000.0f); ImGui::LabelText("Waiting for render thread", "%.2f", m_pipeline->getGPUTime() * 1000.0f); } ImGui::End(); ImGui::PopStyleColor(); } }
void CPlayerBase::Falling() { PROFILE_FUNCTION("falling base"); updateFalling(); }
bool CPlayerBase::UpdateMovDirection() { PROFILE_FUNCTION("update direction base"); moving = false; bool horizontal = false; bool vertical = false; if (!GameController->GetFreeCamera() || io->keys[VK_CONTROL].isPressed()) { if (controller->IsMoveForward()) { float zzz = controller->MoveYNormalized(); directionForward = VEC3(0, 0, zzz); //TODO: xbobx moving = true; vertical = true; } if (controller->IsMoveBackWard()) { float zzz = controller->MoveYNormalized(); directionForward = VEC3(0, 0, zzz); //TODO: xbobx moving = true; vertical = true; } if (controller->IsMoveLeft()) { float zzz = controller->MoveXNormalized(); directionLateral = VEC3(zzz, 0, 0); //TODO: xbobx moving = true; horizontal = true; } if (controller->IsMoveRight()) { float zzz = controller->MoveXNormalized(); directionLateral = VEC3(zzz, 0, 0); //TODO: xbobx moving = true; horizontal = true; } if ((controller->IsImpulseUpButtonPressed()) && !gravity_active) { directionVertical = VEC3(0, 0.25, 0); //TODO: xbobx moving = true; vertical = true; } /* if ((io->keys[VK_MENU].isPressed() || io->joystick.button_A.isPressed()) && !gravity_active) { directionVertical = VEC3(0, -0.25, 0); //TODO: xbobx moving = true; vertical = true; } */ if (!vertical && moving) directionForward = VEC3(0, 0, 0); else if (!horizontal && moving) directionLateral = VEC3(0, 0, 0); else if (gravity_active) directionVertical = VEC3(0, 0, 0); } return moving; }
void EntityManager::UpdatePhysics( float frametime ) { PROFILE_FUNCTION(); // frametime *= 0.5f; Scalar total_time = frametime + m_PhysOverlapTime; if (total_time > 0.1f) total_time = 0.1f; // split the timestep into fixed size chunks int num_loops = (int) (total_time / m_PhysTimestep); Scalar timestep = m_PhysTimestep; if ( false /*m_allow_smaller_timesteps*/ ) { if (num_loops == 0) num_loops = 1; timestep = total_time / num_loops; } m_PhysOverlapTime = total_time - num_loops * timestep; // TCPreAllocDynamicLinkList<CJL_PhysicsActor>& rActorList = m_pStage->m_pPhysicsManager->GetActorList(); // TCPreAllocDynamicLinkList<CJL_PhysicsActor>::LinkListIterator itrActor; int i; for (i=0 ; i<num_loops ; ++i) { // m_physics_time += timestep; // apply gravity /* for( itrActor = rActorList.Begin(); itrActor != rActorList.End(); itrActor++ ) { if( !(itrActor->GetActorFlag() & JL_ACTOR_STATIC) ) itrActor->AddWorldForce( itrActor->GetMass() * Vector3(0,-9.8f,0) ); } */ ProfileBegin( "Entity Update (Physics)" ); // update physics properties that are specific to each entity // DO NOT CONFUSE THIS WITH CCopyEntity::UpdatePhysics() CCopyEntity *pEntity; for( pEntity = m_pEntityInUse.get(); pEntity != NULL; pEntity = pEntity->m_pNextRawPtr ) { if( pEntity->GetEntityFlags() & BETYPE_COPY_PARENT_POSE ) pEntity->CopyParentPose(); // if( pEntity->inuse && pEntity->pPhysicsActor ) if( pEntity->inuse && 0 < pEntity->m_vecpPhysicsActor.size() ) pEntity->pBaseEntity->UpdatePhysics( pEntity, timestep ); UpdateEntityAfterMoving( pEntity ); } ProfileEnd( "Entity Update (Physics)" ); { PROFILE_SCOPE( "Physics Simulation" ); // handle the motions and collisions of rigid body entities // m_pStage->m_pPhysicsManager->Integrate( timestep ); m_pStage->GetPhysicsScene()->Simulate( timestep ); while( !m_pStage->GetPhysicsScene()->FetchResults( physics::SimulationStatus::RigidBodyFinished ) ) {} } // clear forces on actors /* for( itrActor = rActorList.Begin(); itrActor != rActorList.End(); itrActor++ ) { itrActor->ClearForces(); } */ } }
virtual void frame() override { PROFILE_FUNCTION(); bgfx::frame(); m_view_counter = 0; }
void NounShip::updateShip( dword nTick ) { PROFILE_FUNCTION(); // update despawn/docking logic.. updateDespawn(); // update the ships gadgets updateGadgets( nTick ); // update high-level AI updateLogic( nTick ); // repair / reload ship when in orbit if ( nTick >= m_nRepairTick ) { m_nRepairTick = nTick + DEFAULT_REPAIR_RATE; if ( inOrbit() ) { // handle ship repairs when in orbit around friendly planet with a ship yard NounPlanet * pPlanet = WidgetCast<NounPlanet>( orbiting() ); if ( pPlanet != NULL ) { if ( pPlanet->isFriend( this ) ) { repair( pPlanet, PLANET_REPAIR_RATE, true ); reload( pPlanet ); } else if ( (pPlanet->flags() & NounPlanet::FLAG_HYDROGEN) != 0 ) { // if planet has hydrogen, then refuel the jump drive if ( jumpDrive() != NULL ) jumpDrive()->reload( pPlanet ); } } } } if ( nTick >= m_nUpdateTick ) { m_nUpdateTick = nTick + SHIP_UPDATE_RATE; // update characteristics updateCharacter(); // update low-level AI updateCommand(); // update the repair queue updateRepairQueue(); // update the contact list updateContacts(); // drain off some damage from the damage list updateThreats(); } if ( m_bIncoming ) { ASSERT( userId() == 0 ); avoidCollision(); m_bIncoming = false; } updatePointDefense(); updateFireCheck(); }
void TSRAlphaPass::SubmitRendering( vector< TSRSceneEntity* >& _renderables ) { PROFILE_FUNCTION( "Alpha Pass" ); Graphics()->SetDepthStencilState( Graphics()->m_DepthTestEnabledWriteDisabled ); Graphics()->CopyBackBufferToTexture( *m_pBackBufferTarget ); // now the screen texture is the back buffer copy TSRGlobalConstants.m_BackBuferTexture.Set( *m_pBackBufferTarget ); Graphics()->SetCurrentPass( TWISTER_PASS_ALPHA ); // LightsManager()->GenerateLightingContexts(); LightsManager()->SetShaderConstants(); // if ( KEYUP( 'P' ) ) { m_pWorld->RenderObjectsAlpha( m_pWorld->GetMainCamera() ); } //#define LINES_TEST #ifdef LINES_TEST Graphics()->SetBlendState( Graphics()->m_BlendAdditiveSrcAlphaInvSrcAlpha ); TSRMaterial whiteMaterial; TSRGlobalConstants.SetMaterial( whiteMaterial ); float fStartX = -400.0f; float fStartY = -400.0f; float fEndX = 400.0f; float fEndY = 400.0f; unsigned int iNumGridLinesX = 20; unsigned int iNumGridLinesY = 20; float fStepX = (fEndX - fStartX) / iNumGridLinesX; float fStepY = (fEndY - fStartY) / iNumGridLinesY; bool bRealLines = false; // Graphics()->SetRasterizerState( Graphics()->m_FillDoubleSidedState ); //Graphics()->SetDepthStencilState( Graphics()->m_DefaultDepthStencilState ); if ( bRealLines ) { TSRImmediateDraw::Begin( TWISTER_RENDERMODE_LINELIST ); TSRImmediateDraw::Color4f( 1.0f, 1.0f, 1.0f, 1.0f ); for (unsigned int i = 0; i < iNumGridLinesX; i++) { TSRImmediateDraw::Vertex3f( fStartX + (i)* fStepX, fStartY, 0.0f ); TSRImmediateDraw::Vertex3f( fStartX + (i)* fStepX, fEndY, 0.0f ); } for (unsigned int i = 0; i < iNumGridLinesY; i++) { TSRImmediateDraw::Vertex3f( fStartX, fStartY + i * fStepY, 0.0f ); TSRImmediateDraw::Vertex3f( fEndX, fStartY + i * fStepY, 0.0f ); } TSRImmediateDraw::End();//( Graphics()->m_pVertexColorShader ); } else { static float fLineWidth = 1.0f; TSRImmediateDraw::BeginLines( fLineWidth + 3.0f ); TSRImmediateDraw::LineColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); for (unsigned int i = 0; i < iNumGridLinesX; i++) { TSRImmediateDraw::LineVertex3f( fStartX + (i)* fStepX, fStartY, 0.0f ); TSRImmediateDraw::LineVertex3f( fStartX + (i)* fStepX, fEndY, 0.0f ); } for (unsigned int i = 0; i < iNumGridLinesY; i++) { TSRImmediateDraw::LineVertex3f( fStartX, fStartY + i * fStepY, 0.0f ); TSRImmediateDraw::LineVertex3f( fEndX, fStartY + i * fStepY, 0.0f ); } TSRImmediateDraw::EndLines();//( Graphics()->m_pVertexColorShader ); } #endif if ( Graphics()->GetCurrentPass() == TWISTER_PASS_ALPHA && m_pBackBufferTarget ) { // now the screen texture is the back buffer copy Graphics()->CopyBackBufferToTexture( *m_pBackBufferTarget ); TSRGlobalConstants.m_BackBuferTexture.Set( *m_pBackBufferTarget ); } }
void updateAsyncTransactions() override { PROFILE_FUNCTION(); while (!m_in_progress.empty()) { AsynTrans* tr = m_in_progress.front(); if (!tr->isCompleted()) break; PROFILE_BLOCK("processAsyncTransaction"); m_in_progress.pop(); if ((tr->data.m_flags & E_CANCELED) == 0) { tr->data.m_cb.invoke(*tr->data.m_file, !!(tr->data.m_flags & E_SUCCESS)); } if ((tr->data.m_flags & (E_SUCCESS | E_FAIL)) != 0) { closeAsync(*tr->data.m_file); } m_transaction_queue.dealoc(tr); } i32 can_add = C_MAX_TRANS - m_in_progress.size(); while (can_add && !m_pending.empty()) { AsynTrans* tr = m_transaction_queue.alloc(false); if (tr) { AsyncItem& item = m_pending[0]; tr->data.m_file = item.m_file; tr->data.m_cb = item.m_cb; tr->data.m_id = item.m_id; tr->data.m_mode = item.m_mode; copyString(tr->data.m_path, sizeof(tr->data.m_path), item.m_path); tr->data.m_flags = item.m_flags; tr->reset(); m_transaction_queue.push(tr, true); m_in_progress.push(tr); m_pending.erase(0); } can_add--; } #if LUMIX_SINGLE_THREAD() while (AsynTrans* tr = m_transaction_queue.pop(false)) { PROFILE_BLOCK("transaction"); if ((tr->data.m_flags & E_IS_OPEN) == E_IS_OPEN) { tr->data.m_flags |= tr->data.m_file->open(Path(tr->data.m_path), tr->data.m_mode) ? E_SUCCESS : E_FAIL; } else if ((tr->data.m_flags & E_CLOSE) == E_CLOSE) { tr->data.m_file->close(); tr->data.m_file->release(); tr->data.m_file = nullptr; } tr->setCompleted(); } #endif }