本文整理汇总了C++中timer::until_now方法的典型用法代码示例。如果您正苦于以下问题:C++ timer::until_now方法的具体用法?C++ timer::until_now怎么用?C++ timer::until_now使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类timer
的用法示例。
在下文中一共展示了timer::until_now方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update
void gs_playing::update(StringHash eventType,VariantMap& eventData)
{
if(globals::instance()->game_states.size()>1)
return;
Input* input=GetSubsystem<Input>();
float timeStep=eventData[Update::P_TIMESTEP].GetFloat();
timer_playing+=timeStep;
// check if there should be rocks spawned due to a distance trigger
for(level_rock_spawn& rs:current_level.rock_spawns)
if(!rs.rocks_spawned&&rs.trigger_area.IsInside(player_->node->GetPosition()))
{
rs.rocks_spawned=true;
for(int i=0;i<rs.rock_count;i++)
{
auto node_stone=globals::instance()->scene->CreateChild("Stone");
nodes.push_back(node_stone);
StaticModel* boxObject=node_stone->CreateComponent<StaticModel>();
boxObject->SetModel(globals::instance()->cache->GetResource<Model>("Models/rock.mdl"));
boxObject->SetMaterial(globals::instance()->cache->GetResource<Material>("Materials/rock.xml"));
boxObject->SetCastShadows(true);
float s=1.0+Random(3.0f);
node_stone->SetScale(s);
boxObject->SetOccludee(true);
boxObject->SetDrawDistance(200);
boxObject->SetShadowDistance(200);
PhysicsRaycastResult result;
Vector3 pos;
pos.x_=Random(rs.spawn_area.min_.x_,rs.spawn_area.max_.x_);
pos.y_=Random(rs.spawn_area.min_.y_,rs.spawn_area.max_.y_);
pos.z_=Random(rs.spawn_area.min_.z_,rs.spawn_area.max_.z_);
Ray ray(pos,Vector3(0,-1,0));
globals::instance()->physical_world->SphereCast(result,ray,2,100);
if(result.distance_<=1000)
pos=result.position_+Vector3(0,5,0);
auto body_stone=node_stone->CreateComponent<RigidBody>();
body_stone->SetPosition(pos);
body_stone->SetCollisionLayer(2);
body_stone->SetMass(50.0*s*s);
body_stone->SetLinearDamping(0.2f);
body_stone->SetAngularDamping(0.2f);
//body_stone->SetAngularFactor(Vector3(0,1,0));
body_stone->SetFriction(0.6);
CollisionShape* shape=node_stone->CreateComponent<CollisionShape>();
//shape->SetCapsule(1,1.2);
shape->SetConvexHull(globals::instance()->cache->GetResource<Model>("Models/rock.mdl"));
}
}
std::string str;
{
static double last_second=0;
static double last_second_frames=1;
static timer this_second;
static double this_second_frames=0;
this_second_frames++;
if(this_second.until_now()>=1)
{
last_second=this_second.until_now();
last_second_frames=this_second_frames;
this_second.reset();
this_second_frames=0;
}
if(last_second!=0)
str.append(std::to_string(last_second_frames/last_second).substr(0,6));
str.append(" FPS Position: ");
str.append(std::to_string(player_->node->GetPosition().x_).substr(0,6));
str.append(", ");
str.append(std::to_string(player_->node->GetPosition().y_).substr(0,6));
str.append(", ");
str.append(std::to_string(player_->node->GetPosition().z_).substr(0,6));
str.append("\nLevel Time: ");
if(goal_time>0)
str.append(std::to_string(goal_time));
else
str.append(std::to_string(timer_playing));
str.append("s Remaining Flags: ");
str.append(std::to_string(flag_nodes.size()));
str.append("/");
str.append(std::to_string(current_level.flag_positions.size()));
str.append("\nUse WASD and shift to move and F to toggle flashlight.");
if(goal_time>0)
str.append("\nFinished!");
String s(str.c_str(),str.size());
window_text->SetText(s);
}
player_->update(input,timeStep);
Vector3 player_pos=player_->node->GetPosition();
for(int i=0;i<flag_nodes.size();i++)
{
auto n=flag_nodes[i];
n->Yaw(64*timeStep);
//.........这里部分代码省略.........
示例2: update
void gs_main_menu::update(StringHash eventType,VariantMap& eventData)
{
float timeStep=eventData[Update::P_TIMESTEP].GetFloat();
static double last_second=0;
static double last_second_frames=1;
static timer this_second;
static double this_second_frames=0;
this_second_frames++;
if(this_second.until_now()>=1)
{
last_second=this_second.until_now();
last_second_frames=this_second_frames;
this_second.reset();
this_second_frames=0;
}
std::string str="WASD, mouse and shift to move. T to toggle fill mode,\nG to toggle GUI, Tab to toggle mouse mode, Esc to quit.\n";
if(last_second!=0)
{
str.append(std::to_string(last_second_frames/last_second).substr(0,6));
str.append(" FPS ");
}
String s(str.c_str(),str.size());
window_text->SetText(s);
// Movement speed as world units per second
float MOVE_SPEED=10.0f;
// Mouse sensitivity as degrees per pixel
const float MOUSE_SENSITIVITY=0.1f;
// camera movement
Input* input=GetSubsystem<Input>();
Node* cameraNode_=globals::instance()->camera->GetNode();
if(input->GetQualifierDown(1)) // 1 is shift, 2 is ctrl, 4 is alt
MOVE_SPEED*=10;
if(input->GetKeyDown('W'))
cameraNode_->Translate(Vector3(0,0, 1)*MOVE_SPEED*timeStep);
if(input->GetKeyDown('S'))
cameraNode_->Translate(Vector3(0,0,-1)*MOVE_SPEED*timeStep);
if(input->GetKeyDown('A'))
cameraNode_->Translate(Vector3(-1,0,0)*MOVE_SPEED*timeStep);
if(input->GetKeyDown('D'))
cameraNode_->Translate(Vector3( 1,0,0)*MOVE_SPEED*timeStep);
if(!GetSubsystem<Input>()->IsMouseVisible())
{
IntVector2 mouseMove=input->GetMouseMove();
if(mouseMove.x_>-2000000000&&mouseMove.y_>-2000000000)
{
static float yaw_=84;
static float pitch_=64;
yaw_+=MOUSE_SENSITIVITY*mouseMove.x_;
pitch_+=MOUSE_SENSITIVITY*mouseMove.y_;
pitch_=Clamp(pitch_,-90.0f,90.0f);
// Reset rotation and set yaw and pitch again
cameraNode_->SetDirection(Vector3::FORWARD);
cameraNode_->Yaw(yaw_);
cameraNode_->Pitch(pitch_);
}
}
}