Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#Actualmathew_653

Posted 25 January 2013 - 08:49 AM

Gonna get on with decuppleing the code to produce a minimal build example.
But first i will clarify some more on my code.

Colors[] defined as
float Colors[4];
it is initalised in CEffectFade's constructor.

pAppState is a pointer from the main thread, passed as an argument.

It is incremented from a saperate thread, like so(excuse the mess, the project is still prealpha and i have been tinkering around with stuff).
	const int TICKS_PER_SECOND = 950;
	const int SKIP_TICKS = 1000 / TICKS_PER_SECOND;
	const int MAX_FRAMESKIP = 5;
	DWORD NextFrame = timeGetTime();	//Get our current timeing.	
	DWORD LastFrame = timeGetTime();	//
	int loops=0;
	float interpolation=0.0f;
	while (pAppState->status & STATUS_ACTIVE)	{
		CPlayerEntity *pPlayer = (CPlayerEntity *)pAppState->SharedTable[ID_PLAYER];
		CEffectFade *pFade = (CEffectFade *)pAppState->SharedTable[ID_OVERLAY];
		CLoadAnimation *pLoadAnim = (CLoadAnimation *)pAppState->SharedTable[ID_LOADANIMATION];
		//loops=0;
		if (timeGetTime() > NextFrame && loops < MAX_FRAMESKIP)	{
			if (pAppState->status & STATUS_LOADING)	{
				if (pLoadAnim != NULL)	{
					//printf("LoadThink.\n");
					pLoadAnim->Tick();
				}
			}
			else
			{
				pFade->SetRate(0.0002);
				pFade->TransitionIn();
				if (pPlayer != NULL) { pPlayer->Think(); }
			}
					NextFrame += SKIP_TICKS;
			if (abs(LastFrame-NextFrame) > 1) {
				printf("Warning : delta is %i, game might be lagging.\n", abs(LastFrame-NextFrame));
			}
			LastFrame = NextFrame;
			//loops++;
		}
		else
		{
			//Give our time to something else.
			SwitchToThread();
		}
		interpolation = (float) timeGetTime() + SKIP_TICKS - NextFrame / (float)SKIP_TICKS;
		pAppState->Interp = interpolation;
		//printf("Interpolation : %i\n", interpolation);
		// Old approach(Replaced with a high resolution timer)
		//Sleep(1);	
	}
Two two refrenced functions here SetRate and TransitionIn are as so(raterate is a float).
void CEffectFade::TransitionIn(){
	//printf("Fade : %f\n", Colors[4]);
	Colors[4]+= RateRate;
	//Colors[4]=0.5f;
	if (Colors[4] > 1.0) { Colors[4] = 1.0; }
	if (Colors[4] < 0.0) { Colors[4] = 0.0; }
}
void CEffectFade::SetRate(float Rate){	RateRate = Rate;}
I removed GL_ALPHA_TEST while cleaning code up.

I draw the screen and map prior to the call to pfade->draw(); inbetween the glEnable block and the glBindTexture(GL_TEXTURE_2D, 0) call.

#2mathew_653

Posted 25 January 2013 - 08:42 AM

Gonna get on with decuppleing the code to produce a minimal build example.
But first i will clarify some more on my code.

Colors[] defined as
float Colors[4];
it is initalised in CEffectFade's constructor.

pAppState is a pointer from the main thread, passed as an argument.

It is incremented from a saperate thread, like so(excuse the mess, the project is still prealpha and i have been tinkering around with stuff).
const int TICKS_PER_SECOND = 950;	const int SKIP_TICKS = 1000 / TICKS_PER_SECOND;	const int MAX_FRAMESKIP = 5;		DWORD NextFrame = timeGetTime();	//Get our current timeing.	DWORD LastFrame = timeGetTime();	//int loops=0;	float interpolation=0.0f;	while (pAppState->status & STATUS_ACTIVE)	{		CPlayerEntity *pPlayer = (CPlayerEntity *)pAppState->SharedTable[ID_PLAYER];		CEffectFade *pFade = (CEffectFade *)pAppState->SharedTable[ID_OVERLAY];		CLoadAnimation *pLoadAnim = (CLoadAnimation *)pAppState->SharedTable[ID_LOADANIMATION];				//loops=0;		if (timeGetTime() > NextFrame && loops < MAX_FRAMESKIP)		{			if (pAppState->status & STATUS_LOADING)			{				if (pLoadAnim != NULL)				{					//printf("LoadThink.\n");					pLoadAnim->Tick();				}			}			else			{				pFade->SetRate(0.0002);				pFade->TransitionIn();				if (pPlayer != NULL) { pPlayer->Think(); }			}					NextFrame += SKIP_TICKS;			if (abs(LastFrame-NextFrame) > 1)			{				printf("Warning : delta is %i, game might be lagging.\n", abs(LastFrame-NextFrame));			}			LastFrame = NextFrame;						//loops++;		}		else		{			//Give our time to something else.			SwitchToThread();		}				interpolation = (float) timeGetTime() + SKIP_TICKS - NextFrame / (float)SKIP_TICKS;		pAppState->Interp = interpolation;		//printf("Interpolation : %i\n", interpolation);				// Old approach(Replaced with a high resolution timer)		//Sleep(1);	}
Two two refrenced functions here SetRate and TransitionIn are as so(raterate is a float).
void CEffectFade::TransitionIn(){	//printf("Fade : %f\n", Colors[4]);	Colors[4]+= RateRate;	//Colors[4]=0.5f;	if (Colors[4] > 1.0) { Colors[4] = 1.0; }	if (Colors[4] < 0.0) { Colors[4] = 0.0; }}void CEffectFade::SetRate(float Rate){	RateRate = Rate;}

I removed GL_ALPHA_TEST while cleaning code up.

I draw the screen and map prior to the call to pfade->draw(); inbetween the glEnable block and the glBindTexture(GL_TEXTURE_2D, 0) call.

#1mathew_653

Posted 25 January 2013 - 08:40 AM

Gonna get on with decuppleing the code to produce a minimal build example.

But first i will clarify some more on my code.

 

Colors[] defined as

float Colors[4];

it is initalised in CEffectFade's constructor.

 

It is incremented from a saperate thread, like so(excuse the mess, the project is still prealpha and i have been tinkering around with stuff).

	const int TICKS_PER_SECOND = 950;
	const int SKIP_TICKS = 1000 / TICKS_PER_SECOND;
	const int MAX_FRAMESKIP = 5;
	
	DWORD NextFrame = timeGetTime();	//Get our current timeing.
	DWORD LastFrame = timeGetTime();
	//int loops=0;
	float interpolation=0.0f;

	while (pAppState->status & STATUS_ACTIVE)
	{
		CPlayerEntity *pPlayer = (CPlayerEntity *)pAppState->SharedTable[ID_PLAYER];
		CEffectFade *pFade = (CEffectFade *)pAppState->SharedTable[ID_OVERLAY];
		CLoadAnimation *pLoadAnim = (CLoadAnimation *)pAppState->SharedTable[ID_LOADANIMATION];
		
		//loops=0;
		if (timeGetTime() > NextFrame && loops < MAX_FRAMESKIP)
		{
			if (pAppState->status & STATUS_LOADING)
			{
				if (pLoadAnim != NULL)
				{
					//printf("LoadThink.\n");
					pLoadAnim->Tick();
				}
			}
			else
			{
				pFade->SetRate(0.0002);
				pFade->TransitionIn();
				if (pPlayer != NULL) { pPlayer->Think(); }
			}
		
			NextFrame += SKIP_TICKS;
			if (abs(LastFrame-NextFrame) > 1)
			{
				printf("Warning : delta is %i, game might be lagging.\n", abs(LastFrame-NextFrame));
			}
			LastFrame = NextFrame;
			
			//loops++;
		}
		else
		{
			//Give our time to something else.
			SwitchToThread();
		}
		
		interpolation = (float) timeGetTime() + SKIP_TICKS - NextFrame / (float)SKIP_TICKS;
		pAppState->Interp = interpolation;
		//printf("Interpolation : %i\n", interpolation);
		
		// Old approach(Replaced with a high resolution timer)
		//Sleep(1);
	}

Two two refrenced functions here SetRate and TransitionIn are as so(raterate is a float).

void CEffectFade::TransitionIn()
{
	//printf("Fade : %f\n", Colors[4]);
	Colors[4]+= RateRate;
	//Colors[4]=0.5f;
	if (Colors[4] > 1.0) { Colors[4] = 1.0; }
	if (Colors[4] < 0.0) { Colors[4] = 0.0; }
}

void CEffectFade::SetRate(float Rate)
{
	RateRate = Rate;
}

 

I removed GL_ALPHA_TEST while cleaning code up.

 

I draw the screen and map prior to the call to pfade->draw(); inbetween the glEnable block and the glBindTexture(GL_TEXTURE_2D, 0) call.


PARTNERS