Example #1
0
int countPeopleOutFunc () {

	int x = getPinValue(GPIO_PIN2);

	if (x == 0 )
		{
			idleCount = 0;
			if (flagIn == 0)
			{
				flagOut = 1;
				countPeopleOut += 1;
			}
			else {
				countPeopleIn -= 1;
				count += 1;
				if(countPeopleIn ==0 )
					 flagIn = 0;
			}
		}
	else
	{
		idleCount +=1;
		if(idleCount >= 40 )
		{
			countUpdate();
		}
	}
//printf(" countOut: %d\n", countPeopleOut);
	}
Example #2
0
/* The main game loop */
GAMECODE gameLoop()
{
	static uint32_t lastFlushTime = 0;

	static int renderBudget = 0;  // Scaled time spent rendering minus scaled time spent updating.
	static bool previousUpdateWasRender = false;
	const Rational renderFraction(2, 5);  // Minimum fraction of time spent rendering.
	const Rational updateFraction = Rational(1) - renderFraction;

	countUpdate(false); // kick off with correct counts

	while (true)
	{
		// Receive NET_BLAH messages.
		// Receive GAME_BLAH messages, and if it's time, process exactly as many GAME_BLAH messages as required to be able to tick the gameTime.
		recvMessage();

		// Update gameTime and graphicsTime, and corresponding deltas. Note that gameTime and graphicsTime pause, if we aren't getting our GAME_GAME_TIME messages.
		gameTimeUpdate(renderBudget > 0 || previousUpdateWasRender);

		if (deltaGameTime == 0)
		{
			break;  // Not doing a game state update.
		}

		ASSERT(!paused && !gameUpdatePaused(), "Nonsensical pause values.");

		unsigned before = wzGetTicks();
		syncDebug("Begin game state update, gameTime = %d", gameTime);
		gameStateUpdate();
		syncDebug("End game state update, gameTime = %d", gameTime);
		unsigned after = wzGetTicks();

		renderBudget -= (after - before) * renderFraction.n;
		renderBudget = std::max(renderBudget, (-updateFraction * 500).floor());
		previousUpdateWasRender = false;

		ASSERT(deltaGraphicsTime == 0, "Shouldn't update graphics and game state at once.");
	}

	if (realTime - lastFlushTime >= 400u)
	{
		lastFlushTime = realTime;
		NETflush();  // Make sure that we aren't waiting too long to send data.
	}

	unsigned before = wzGetTicks();
	GAMECODE renderReturn = renderLoop();
	unsigned after = wzGetTicks();

	renderBudget += (after - before) * updateFraction.n;
	renderBudget = std::min(renderBudget, (renderFraction * 500).floor());
	previousUpdateWasRender = true;

	return renderReturn;
}
Example #3
0
static void gameStateUpdate()
{
	syncDebug("map = \"%s\", pseudorandom 32-bit integer = 0x%08X, allocated = %d %d %d %d %d %d %d %d %d %d, position = %d %d %d %d %d %d %d %d %d %d", game.map, gameRandU32(),
	          NetPlay.players[0].allocated, NetPlay.players[1].allocated, NetPlay.players[2].allocated, NetPlay.players[3].allocated, NetPlay.players[4].allocated, NetPlay.players[5].allocated, NetPlay.players[6].allocated, NetPlay.players[7].allocated, NetPlay.players[8].allocated, NetPlay.players[9].allocated,
	          NetPlay.players[0].position, NetPlay.players[1].position, NetPlay.players[2].position, NetPlay.players[3].position, NetPlay.players[4].position, NetPlay.players[5].position, NetPlay.players[6].position, NetPlay.players[7].position, NetPlay.players[8].position, NetPlay.players[9].position
	         );
	for (unsigned n = 0; n < MAX_PLAYERS; ++n)
	{
		syncDebug("Player %d = \"%s\"", n, NetPlay.players[n].name);
	}

	// Add version string to desynch logs. Different version strings will not trigger a desynch dump per se, due to the syncDebug{Get, Set}Crc guard.
	auto crc = syncDebugGetCrc();
	syncDebug("My client version = %s", version_getVersionString());
	syncDebugSetCrc(crc);

	// Actually send pending droid orders.
	sendQueuedDroidInfo();

	sendPlayerGameTime();
	NETflush();  // Make sure the game time tick message is really sent over the network.

	if (!paused && !scriptPaused())
	{
		/* Update the event system */
		if (!bInTutorial)
		{
			eventProcessTriggers(gameTime / SCR_TICKRATE);
		}
		else
		{
			eventProcessTriggers(realTime / SCR_TICKRATE);
		}
		updateScripts();
	}

	// Update abandoned structures
	handleAbandonedStructures();

	// Update the visibility change stuff
	visUpdateLevel();

	// Put all droids/structures/features into the grid.
	gridReset();

	// Check which objects are visible.
	processVisibility();

	// Update the map.
	mapUpdate();

	//update the findpath system
	fpathUpdate();

	// update the command droids
	cmdDroidUpdate();

	fireWaitingCallbacks(); //Now is the good time to fire waiting callbacks (since interpreter is off now)

	for (unsigned i = 0; i < MAX_PLAYERS; i++)
	{
		//update the current power available for a player
		updatePlayerPower(i);

		DROID *psNext;
		for (DROID *psCurr = apsDroidLists[i]; psCurr != nullptr; psCurr = psNext)
		{
			// Copy the next pointer - not 100% sure if the droid could get destroyed but this covers us anyway
			psNext = psCurr->psNext;
			droidUpdate(psCurr);
		}

		for (DROID *psCurr = mission.apsDroidLists[i]; psCurr != nullptr; psCurr = psNext)
		{
			/* Copy the next pointer - not 100% sure if the droid could
			get destroyed but this covers us anyway */
			psNext = psCurr->psNext;
			missionDroidUpdate(psCurr);
		}

		// FIXME: These for-loops are code duplicationo
		STRUCTURE *psNBuilding;
		for (STRUCTURE *psCBuilding = apsStructLists[i]; psCBuilding != nullptr; psCBuilding = psNBuilding)
		{
			/* Copy the next pointer - not 100% sure if the structure could get destroyed but this covers us anyway */
			psNBuilding = psCBuilding->psNext;
			structureUpdate(psCBuilding, false);
		}
		for (STRUCTURE *psCBuilding = mission.apsStructLists[i]; psCBuilding != nullptr; psCBuilding = psNBuilding)
		{
			/* Copy the next pointer - not 100% sure if the structure could get destroyed but this covers us anyway. It shouldn't do since its not even on the map!*/
			psNBuilding = psCBuilding->psNext;
			structureUpdate(psCBuilding, true); // update for mission
		}
	}

	missionTimerUpdate();

	proj_UpdateAll();

	FEATURE *psNFeat;
	for (FEATURE *psCFeat = apsFeatureLists[0]; psCFeat; psCFeat = psNFeat)
	{
		psNFeat = psCFeat->psNext;
		featureUpdate(psCFeat);
	}

	// Clean up dead droid pointers in UI.
	hciUpdate();

	// Free dead droid memory.
	objmemUpdate();

	// Must end update, since we may or may not have ticked, and some message queue processing code may vary depending on whether it's in an update.
	gameTimeUpdateEnd();

	// Must be at the beginning or end of each tick, since countUpdate is also called randomly (unsynchronised) between ticks.
	countUpdate(true);

	static int i = 0;
	if (i++ % 10 == 0) // trigger every second
	{
		jsDebugUpdate();
	}
}
void Kinect2Manager::Update(unsigned int options) {

#ifdef _USE_KINECT

    IColorFrame * pColorFrame = NULL;
    IDepthFrame * pDepthFrame = NULL;
    IBodyFrame * pBodyFrame = NULL;
    IBodyIndexFrame * pBodyIndexFrame = NULL;
    IMultiSourceFrame * pMultiSourceFrame = NULL;

    m_nColorWidth = 0;
    m_nColorHeight = 0;
    m_nDepthWidth = 0;
    m_nDepthHeight = 0;

    m_bCalculateDepthRGBX = options & Update::DepthRGBX;

    int numUpdate = countUpdate(options);

    HRESULT hr = 1;

    if (numUpdate > 1) {
        hr = m_pMultiSourceFrameReader->AcquireLatestFrame(&pMultiSourceFrame);
    }

    if (SUCCEEDED(hr)) {

        if (options & Update::Color) {
            IColorFrameReference* pColorFrameReference = NULL;

            if (numUpdate > 1) {
                hr = pMultiSourceFrame->get_ColorFrameReference(&pColorFrameReference);

                if (SUCCEEDED(hr))
                {
                    hr = pColorFrameReference->AcquireFrame(&pColorFrame);
                }
            }
            else {
                hr = m_pColorFrameReader->AcquireLatestFrame(&pColorFrame);
            }

            if (SUCCEEDED(hr)) {
                m_bMapColorToDepth = options & Update::MapColorToDepth;
            }
            else {
                options &= ~Update::Color;
            }

            SafeRelease(pColorFrameReference);
        }
        if (options & Update::Depth) {
            IDepthFrameReference* pDepthFrameReference = NULL;

            if (numUpdate > 1) {

                hr = pMultiSourceFrame->get_DepthFrameReference(&pDepthFrameReference);
                if (SUCCEEDED(hr))
                {
                    hr = pDepthFrameReference->AcquireFrame(&pDepthFrame);
                }
            }
            else {
                hr = m_pDepthFrameReader->AcquireLatestFrame(&pDepthFrame);
            }

            if (SUCCEEDED(hr)) {

                m_bMapDepthToColor = options & Update::MapDepthToColor;
            }
            else {
                options &= ~Update::Depth;
            }

            SafeRelease(pDepthFrameReference);
        }
        if (options & Update::Body) {
            IBodyFrameReference* pBodyFrameReference = NULL;

            if (numUpdate > 1) {

                hr = pMultiSourceFrame->get_BodyFrameReference(&pBodyFrameReference);
                if (SUCCEEDED(hr))
                {
                    hr = pBodyFrameReference->AcquireFrame(&pBodyFrame);
                }
            }
            else {
                hr = m_pBodyFrameReader->AcquireLatestFrame(&pBodyFrame);
            }
            SafeRelease(pBodyFrameReference);
        }



        if (options & Update::Color && options & Update::Depth) {




            if (options & Update::BodyIndex && options & Update::MapColorToDepth) {
                if (m_bDepthColorMapCalculated) {
                    IBodyIndexFrameReference* pBodyIndexFrameReference = NULL;

                    hr = pMultiSourceFrame->get_BodyIndexFrameReference(&pBodyIndexFrameReference);
                    if (SUCCEEDED(hr))
                    {
                        hr = pBodyIndexFrameReference->AcquireFrame(&pBodyIndexFrame);
                    }

                    SafeRelease(pBodyIndexFrameReference);
                }
            }
        }
    }

    if (pBodyFrame) {
        UpdateBody(pBodyFrame);

    }
    if (pColorFrame) {
        UpdateColor(pColorFrame);
    }

    if (pDepthFrame) {
        UpdateDepth(pDepthFrame);


        if (options & Update::MapDepthToColor) {
            CalculateColorDepthMap();
            if (m_bColorDepthMapCalculated)
                ProcessDepthToColor(m_pDepth, m_nDepthWidth, m_nDepthHeight, m_pColorDepthMap, m_nColorWidth, m_nColorHeight);
        }

        if (options & Update::MapColorToDepth) {
            CalculateDepthColorMap();
            if (m_bDepthColorMapCalculated) {
                ProcessColorToDepth(m_pColorRGBX, m_nColorWidth, m_nColorHeight, m_pDepthColorMap, m_nDepthWidth, m_nDepthHeight);

                if (pBodyIndexFrame) {
                    UpdateBodyIndex(pBodyIndexFrame);
                }
            }

        }
    }


    SafeRelease(pColorFrame);
    SafeRelease(pDepthFrame);
    SafeRelease(pBodyFrame);
    SafeRelease(pBodyIndexFrame);
    SafeRelease(pMultiSourceFrame);
#else

    m_nDepthWidth = CAPTURE_SIZE_X_DEPTH;
    m_nDepthHeight = CAPTURE_SIZE_Y_DEPTH;

    m_nColorWidth = CAPTURE_SIZE_X_COLOR;
    m_nColorHeight = CAPTURE_SIZE_Y_COLOR;

    if (options & Update::MapDepthToColor) {
        CalculateColorDepthMap();
        if (m_bColorDepthMapCalculated)
            ProcessDepthToColor(m_pDepth, m_nDepthWidth, m_nDepthHeight, m_pColorDepthMap, m_nColorWidth, m_nColorHeight);
    }

    if (options & Update::MapColorToDepth) {
        CalculateDepthColorMap();
        if (m_bDepthColorMapCalculated) {
            ProcessColorToDepth(m_pColorRGBX, m_nColorWidth, m_nColorHeight, m_pDepthColorMap, m_nDepthWidth, m_nDepthHeight);

        }

    }

    UpdateBodyIndex(NULL);

#endif
}
Example #5
0
bool stageThreeInitialise()
{
	STRUCTURE *psStr;
	UDWORD i;
	DROID *psDroid;
	bool fromSave = (getSaveGameType() == GTYPE_SAVE_START || getSaveGameType() == GTYPE_SAVE_MIDMISSION);

	debug(LOG_WZ, "== stageThreeInitialise ==");

	loopMissionState = LMS_NORMAL;

	if (!InitRadar()) 	// After resLoad cause it needs the game palette initialised.
	{
		return false;
	}

	// reset the clock to normal speed
	gameTimeResetMod();

	if (!init3DView())	// Initialise 3d view stuff. After resLoad cause it needs the game palette initialised.
	{
		return false;
	}

	effectResetUpdates();
	initLighting(0, 0, mapWidth, mapHeight);
	pie_InitLighting();

	if (fromSave)
	{
		// these two lines are the biggest hack in the world.
		// the reticule seems to get detached from 'reticuleup'
		// this forces it back in sync...
		intRemoveReticule();
		intAddReticule();
	}

	if (bMultiPlayer)
	{
		if (!fromSave)
		{
			multiGameInit();
		}
		initTemplates();
	}

	preProcessVisibility();

	prepareScripts(getLevelLoadType() == GTYPE_SAVE_MIDMISSION || getLevelLoadType() == GTYPE_SAVE_START);

	if (!fpathInitialise())
	{
		return false;
	}

	mapInit();
	gridReset();

	//if mission screen is up, close it.
	if (MissionResUp)
	{
		intRemoveMissionResultNoAnim();
	}

	// Re-inititialise some static variables.

	resizeRadar();

	setAllPauseStates(false);

	/* decide if we have to create teams, ONLY in multiplayer mode!*/
	if (bMultiPlayer && alliancesSharedVision(game.alliance))
	{
		createTeamAlliances();

		/* Update ally vision for pre-placed structures and droids */
		for (i = 0; i < MAX_PLAYERS; i++)
		{
			if (i != selectedPlayer)
			{
				/* Structures */
				for (psStr = apsStructLists[i]; psStr; psStr = psStr->psNext)
				{
					if (aiCheckAlliances(psStr->player, selectedPlayer))
					{
						visTilesUpdate((BASE_OBJECT *)psStr);
					}
				}

				/* Droids */
				for (psDroid = apsDroidLists[i]; psDroid; psDroid = psDroid->psNext)
				{
					if (aiCheckAlliances(psDroid->player, selectedPlayer))
					{
						visTilesUpdate((BASE_OBJECT *)psDroid);
					}
				}
			}
		}
	}

	countUpdate();
	if (getLevelLoadType() != GTYPE_SAVE_MIDMISSION)
	{
		if (getDebugMappingStatus())
		{
			triggerEventCheatMode(true);
		}
		eventFireCallbackTrigger((TRIGGER_TYPE)CALL_GAMEINIT);
		triggerEvent(TRIGGER_GAME_INIT);
	}

	return true;
}