void RealGamePlayLayer::update(float delta){
    
	if (mRunner->mModel->finish() && !mCanRate)
	{
		this->mDelegate->realUpdateTime(0);
		long upTime = time * 1000;
		mCanRate = true;
		//mRunner->mModel->setFinish(false);
		rateLayer = new RateHUDLayer(this->mParentLayer, time);
		rateLayer->setDelegate(this);
		//this->removeChild(menu);
		this->addChild(rateLayer);

		if (stol(mMapInfo.playTime) == 0 || stol(mMapInfo.playTime) > upTime)
		{
			std::vector<HttpRequestParameter> resData{ HttpRequestParameter(phoneKey, "test"), HttpRequestParameter("mid", mMapInfo.mid), HttpRequestParameter("playTime", StringUtils::format("%ld", upTime)) };
			HttpServices::inst->sendRequest(rateLayer, resData, HttpRequestMethod::UP_TIME);
			HttpServices::inst->setDelegate(this);
		}
	}
	else
	{
		time += delta;
		this->mDelegate->realUpdateTime(time);
		updateQuadTree();
		if (!mRunner->mView->isRollingBack()){

			b2Layer::update(delta);
		}
	}
}
Exemple #2
0
void Gource::logic(float t, float dt) {

    if(draw_loading) return;

    if(message_timer>0.0f) message_timer -= dt;
    if(splash>0.0f)        splash -= dt;

    //init log file
    if(commitlog == 0) {

        try {

            commitlog = determineFormat(logfile);

        } catch(SeekLogException& exception) {
            throw SDLAppException("unable to read log file");
        }

        if(commitlog == 0) {
            //if not in a git dir and no log file, show help
            if(logfile.size() == 0 || logfile == ".") {
                SDL_Quit();

                SDLAppException exception("");
                exception.setShowHelp(true);
                throw exception;
            } else if(SDLAppDirExists(logfile)) {
                throw SDLAppException("directory not supported");
            } else {
                throw SDLAppException("unsupported log format (you may need to regenerate your log file)");
            }
        }

        if(gGourceSettings.start_position>0.0) {
            seekTo(gGourceSettings.start_position);
        }
    }

    slider.logic(dt);

    //apply rotation
    if(rotate_angle != 0.0f) {

        float s = sinf(rotate_angle);
        float c = cosf(rotate_angle);

        root->rotate(s, c);

        for(std::map<std::string,RUser*>::iterator it = users.begin(); it!=users.end(); it++) {
            RUser* user = it->second;

            vec2f userpos = user->getPos();

            user->setPos(userpos.rotate(s, c));
        }

        rotate_angle = 0.0f;
    }

    //still want to update camera while paused
    if(paused) {
        updateBounds();
        updateQuadTree();
        updateCamera(dt);
        return;
    }

    // get more entries
    if(commitqueue.size() == 0) {
        readLog();
    }

    //loop in attempt to find commits
    if(commitqueue.size()==0 && commitlog->isSeekable() && gGourceSettings.loop) {
        first_read=true;
        seekTo(0.0);
        readLog();
    }

    if(currtime==0 && commitqueue.size()) {
        currtime   = lasttime = commitqueue[0].timestamp;
        subseconds = 0.0;
    }

    //set current time
    float time_inc = (dt * 86400.0 * gGourceSettings.days_per_second);
    int seconds    = (int) time_inc;

    subseconds += time_inc - ((float) seconds);

    if(subseconds >= 1.0) {
        currtime   += (int) subseconds;
        subseconds -= (int) subseconds;
    }

    currtime += seconds;

    // delete files
    for(std::vector<RFile*>::iterator it = gGourceRemovedFiles.begin(); it != gGourceRemovedFiles.end(); it++) {
        deleteFile(*it);
    }

    gGourceRemovedFiles.clear();


    //add commits up until the current time
    while(commitqueue.size() > 0) {

        RCommit commit = commitqueue[0];

        //auto skip ahead, unless stop_position_reached
        if(gGourceSettings.auto_skip_seconds>=0.0 && idle_time >= gGourceSettings.auto_skip_seconds && !stop_position_reached) {
            currtime = lasttime = commit.timestamp;
            idle_time = 0.0;
        }

        if(commit.timestamp > currtime) break;

        processCommit(commit, t);

        currtime = lasttime = commit.timestamp;
        subseconds = 0.0;

        commitqueue.pop_front();
    }

    //reset loop counters
    gGourceUserInnerLoops = 0;
    gGourceDirNodeInnerLoops = 0;
    gGourceFileInnerLoops = 0;

    interactUsers();
    updateUsers(t, dt);

    updateQuadTree();
    updateBounds();
    updateDirs(dt);

    updateCamera(dt);

    updateTime(commitqueue.size() > 0 ? currtime : lasttime);
}
// on "init" you need to initialize your instance
bool RealGamePlayLayer::init(std::string map, Layer *parentLayer, HttpShortMapInfo mapInfo)
{
	if (!b2Layer::init())
	{
		//		return false;
	}

	mMapInfo = mapInfo;
	time = 0;
	mCanRate = false;
	Size visibleSize = Director::getInstance()->getVisibleSize();
    this->mParentLayer = parentLayer;
	this->mMap = map;
	mRunner = Runner::create();
	mRunner->mModel->setb2Position(50, 300);
	mRunner->setPosition(50, 300);
	this->addChild(mRunner);
	mRunner->mModel->setVelocityX(15.0f);
	vector<int>* t = new vector<int>();
	t->push_back(0);
	t->push_back(0);
	t->at(0) = 0;
	t->at(1) = 0;

	quadTree = new QuadNode(map, t);
	currentObjectList = new set<string>();
	currentQuadNode = new vector<QuadNode*>();
	quadtreeUpdateCounter = 10;
	updateQuadTree();

	/*std::vector<std::string> part = Utility::splitString(map, "dm");

	std::vector<std::string> widthHeight = Utility::splitString(part.at(0), "\n");
	int nTilesWidth = std::stoi(widthHeight.at(0));
	int nTilesHeight = std::stoi(widthHeight.at(1));

	float x, y;
	float tileSize = 70 / GameConfig::scale;
	std::vector<std::string> objectData = Utility::splitString(part.at(1), "\n");
	for (int i = 0; i < nTilesHeight; i++){
	y = (int)(nTilesHeight - i - 1) * tileSize;
	int tmp = y;
	y = tmp;
	std::vector<std::string> currentLineData = Utility::splitString(objectData.at(i), ";");
	for (int j = 0; j < nTilesWidth; j++){
	std::string tileName = currentLineData.at(j);
	if (tileName == "0")
	continue;
	x = j * tileSize ;
	addTile(tileName, x, y);
	}
	}
	this->runAction(cocos2d::Follow::create(mRunner, Rect(0, 0, x / GameConfig::scale,
	y / GameConfig::scale)));
	*/

	auto listener = EventListenerTouchOneByOne::create();

	listener->onTouchBegan = CC_CALLBACK_2(RealGamePlayLayer::onTouchBegan, this);
	listener->onTouchMoved = CC_CALLBACK_2(RealGamePlayLayer::onTouchMoved, this);
	listener->onTouchEnded = CC_CALLBACK_2(RealGamePlayLayer::onTouchEnded, this);
	_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);

	this->scheduleUpdate();


	this->runAction(cocos2d::Follow::create(mRunner, Rect(0 - 53, 0 - 18, quadTree->nodeRect.right / GameConfig::scale,
		quadTree->nodeRect.top / GameConfig::scale)));

	this->setTag(TAG_NORMAL_LAYER);
	return true;
}