Ejemplo n.º 1
0
void CharacterController::skipActivity() {
    // Some activities can't be cancelled, such as the final phase of entering a
    // vehicle
    // or jumping.
    if (getCurrentActivity() != nullptr &&
        getCurrentActivity()->canSkip(character, this))
        setActivity(nullptr);
}
Ejemplo n.º 2
0
/* Update Activity */
void dvmSystemUpdateActivity(){
    //ALOGD("Current Activity %s", getCurrentActivity().c_str());
    if (getCurrentActivity().find("still") != std::string::npos){
    	gCurOperatingpoint.curActivity = ACTIVITY_MASK_STILL;
    }
    else if (getCurrentActivity().find("walk") != std::string::npos){
    	gCurOperatingpoint.curActivity = ACTIVITY_MASK_WALK;
    }
    else if (getCurrentActivity().find("run") != std::string::npos){
    	gCurOperatingpoint.curActivity = ACTIVITY_MASK_RUN;
    }

}
Ejemplo n.º 3
0
/**
 * calculate start, end and duration for current valve operation
 *
 * @param sleeperState
 * @param setMode request mode (MANUAL or AUTO)
 * @param startTime start time for MANUAL, ignored for AUTO
 * @param duration duration for MANUAL, ignored for AUTO
 */
LOCAL uint8 ICACHE_FLASH_ATTR calculateValveTiming(SleeperStateT* sleeperState, uint8 setMode, uint64 startTime, uint16 duration)
{
  valveTiming.start = 0;
  valveTiming.end   = 0;
  valveTiming.duration  = 0;

  switch (setMode)
  {
    case MODE_AUTO:
    {
      // find current activity
      int index = getCurrentActivity(sleeperState);
      if (index >= 0)
      {
        // create start and end times
        ActivityT* activity = &sleeperState->rtcMem.activities[index];
        uint16 hour   = activity->startTime/60;
        uint16 minute = activity->startTime%60;
        tms.tm_hour = hour;
        tms.tm_min  = minute;
        tms.tm_sec  = 0;
        tms.tm_msec = 0;
        valveTiming.duration = 1000UL*effectiveDuration(activity->duration);
        valveTiming.start    = esp_mktime(&tms);
        valveTiming.end      = valveTiming.start + valveTiming.duration;
      }
      break;
    }

    case MODE_MANUAL:
    {
      valveTiming.duration = 1000UL*duration;
      valveTiming.start    = startTime;
      valveTiming.end      = valveTiming.start + valveTiming.duration;
      break;
    }
  }

  return valveTiming.duration > 0;
}
Ejemplo n.º 4
0
void RWGame::renderDebugStats(float time, Renderer::ProfileInfo& worldRenderTime)
{
	// Turn time into milliseconds
	float time_ms = time * 1000.f;
	constexpr size_t average_every_frame = 15;
	static float times[average_every_frame];
	static size_t times_index = 0;
	static float time_average = 0;
	times[times_index++] = time_ms;
	if (times_index >= average_every_frame) {
		times_index = 0;
		time_average = 0;

		for (int i = 0; i < average_every_frame; ++i) {
			time_average += times[i];
		}
		time_average /= average_every_frame;
	}

	std::map<std::string, Renderer::ProfileInfo*> profGroups {
		{"Objects", &renderer->profObjects},
		{"Effects", &renderer->profEffects},
		{"Sky", &renderer->profSky},
		{"Water", &renderer->profWater},
	};

	std::stringstream ss;
	ss << "Frametime: " << time_ms << " (FPS " << (1.f/time) << ")\n";
	ss << "Average (per " << average_every_frame << " frames); Frametime: " << time_average << " (FPS " << (1000.f/time_average) << ")\n";
	ss << "Draws: " << lastDraws << " (" << renderer->culled << " Culls)\n";
	ss << " Texture binds: " << renderer->getRenderer()->getTextureCount() << "\n";
	ss << " Buffer binds: " << renderer->getRenderer()->getBufferCount() << "\n";
	ss << " World time: " << (worldRenderTime.duration/1000000) << "ms\n";
	for(auto& perf : profGroups)
	{
		ss << "  " << perf.first << ": "
		<< perf.second->draws << " draws " << perf.second->primitives << " prims "
		<< (perf.second->duration/1000000) << "ms\n";
	}
	
	// Count the number of interesting objects.
	int peds = 0, cars = 0;
	for( auto& object : world->allObjects )
	{
		switch ( object->type() )
		{
			case GameObject::Character: peds++; break;
			case GameObject::Vehicle: cars++; break;
			default: break;
		}
	}
	
	ss << "P " << peds << " V " << cars << "\n";
	
	if( state->playerObject ) {
		ss << "Player (" << state->playerObject << ")\n";
		auto object = world->pedestrianPool.find(state->playerObject);
		auto player = static_cast<CharacterObject*>(object)->controller;
		ss << "Player Activity: ";
		if( player->getCurrentActivity() ) {
			ss << player->getCurrentActivity()->name();
		}
		else {
			ss << "Idle";
		}
		ss << std::endl;
	}
	
	TextRenderer::TextInfo ti;
	ti.text = ss.str();
	ti.font = 2;
	ti.screenPosition = glm::vec2( 10.f, 10.f );
	ti.size = 15.f;
	ti.baseColour = glm::u8vec3(255);
	renderer->text.renderText(ti);

	/*while( engine->log.size() > 0 && engine->log.front().time + 10.f < engine->gameTime ) {
		engine->log.pop_front();
	}

	ti.screenPosition = glm::vec2( 10.f, 500.f );
	ti.size = 15.f;
	for(auto it = engine->log.begin(); it != engine->log.end(); ++it) {
		ti.text = it->message;
		switch(it->type) {
		case GameWorld::LogEntry::Error:
			ti.baseColour = glm::vec3(1.f, 0.f, 0.f);
			break;
		case GameWorld::LogEntry::Warning:
			ti.baseColour = glm::vec3(1.f, 1.f, 0.f);
			break;
		default:
			ti.baseColour = glm::vec3(1.f, 1.f, 1.f);
			break;
		}

		// Interpolate the color
		// c.a = (engine->gameTime - it->time > 5.f) ? 255 - (((engine->gameTime - it->time) - 5.f)/5.f) * 255 : 255;
		// text.setColor(c);

		engine->renderer.text.renderText(ti);
		ti.screenPosition.y -= ti.size;
	}*/
}
Ejemplo n.º 5
0
void DefaultAIController::update(float dt) {
    switch (currentGoal) {
        case FollowLeader: {
            if (!leader) break;
            if (getCharacter()->getCurrentVehicle()) {
                if (leader->getCurrentVehicle() !=
                    getCharacter()->getCurrentVehicle()) {
                    skipActivity();
                    setNextActivity(std::make_unique<Activities::ExitVehicle>());
                }
                // else we're already in the right spot.
            } else {
                if (leader->getCurrentVehicle()) {
                    setNextActivity(std::make_unique<Activities::EnterVehicle>(
                        leader->getCurrentVehicle(), 1));
                } else {
                    glm::vec3 dir =
                        leader->getPosition() - getCharacter()->getPosition();
                    if (glm::length(dir) > followRadius) {
                        if (glm::distance(gotoPos, leader->getPosition()) >
                            followRadius) {
                            gotoPos =
                                leader->getPosition() +
                                (glm::normalize(-dir) * followRadius * 0.7f);
                            skipActivity();
                            setNextActivity(std::make_unique<Activities::GoTo>(gotoPos));
                        }
                    }
                }
            }
        } break;
        case TrafficWander: {
            if (targetNode) {
                auto targetDistance =
                    glm::vec2(character->getPosition() - targetNode->position);
                if (glm::length(targetDistance) <= 0.1f) {
                    // Assign the next target node
                    auto lastTarget = targetNode;
                    std::random_device rd;
                    std::default_random_engine re(rd());
                    std::uniform_int_distribution<> d(
                        0, lastTarget->connections.size() - 1);
                    targetNode = lastTarget->connections.at(d(re));
                    setNextActivity(std::make_unique<Activities::GoTo>(
                        targetNode->position));
                } else if (getCurrentActivity() == nullptr) {
                    setNextActivity(std::make_unique<Activities::GoTo>(
                        targetNode->position));
                }
            } else {
                // We need to pick an initial node
                auto& graph = getCharacter()->engine->aigraph;
                AIGraphNode* node = nullptr;
                float mindist = std::numeric_limits<float>::max();
                for (auto n : graph.nodes) {
                    float d = glm::distance(n->position,
                                            getCharacter()->getPosition());
                    if (d < mindist) {
                        node = n;
                        mindist = d;
                    }
                }
                targetNode = node;
            }
        } break;
        default:
            break;
    }

    CharacterController::update(dt);
}
Ejemplo n.º 6
0
bool CharacterController::isCurrentActivity(const std::string &activity) const {
    if (getCurrentActivity() == nullptr) return false;
    return getCurrentActivity()->name() == activity;
}