Example #1
0
// Renders the fade overlay, returning true on the frame the overlay
// is opaque.
bool FullScreenFader::Render(const WorldTime& time) {
  // The alpha is calculated using this mini-state machine so that there
  // is always at least one frame where the overlay is complete opaque.
  const float offset = CalculateOffset(time);
  const float alpha =
      fade_in_ ? std::min(offset, 1.0f) : std::max(1.0f - offset, 0.0f);
  const bool opaque = fade_in_ && alpha == 1.0f;
  if (opaque) {
    // At the mid point, start fading out.
    start_time_ = time;
    fade_in_ = false;
  }

  // Render the overlay in front on the screen.
  renderer_->set_model_view_projection(
      ortho_mat_ * mat4::FromTranslationVector(vec3(0.0f, 0.0f, 0.1f)));
  renderer_->set_color(vec4(0.0f, 0.0f, 0.0f, alpha));
  material_->Set(*renderer_);
  shader_->Set(*renderer_);
  fplbase::Mesh::RenderAAQuadAlongX(
        vec3(0.0f, static_cast<float>(extents_.y()), 0.0f),
        vec3(static_cast<float>(extents_.x()), 0.0f, 0.0f),
        vec2(0.0f, 1.0f), vec2(1.0f, 0.0f));
  return opaque;
}
Example #2
0
CFreeList* CMemory::GetOrAddFreeList(unsigned int iElementSize, int iAlignment, int iOffset)
{
	SFreeListDesc		sDesc;
	BOOL				bResult;
	int					iIndex;
	SFreeListDesc*		psDesc;
	CFreeList*		pcList;
	SMemoryFreeListParams*	psParams;
	int					iFinalOffset;
	int					iStride;

	iFinalOffset = CalculateOffset(iOffset - sizeof(SMemoryAllocation), iAlignment);
	psParams = GetFreeListParamsForSize(iElementSize);
	iStride = CalculateStride(psParams->iMaxElementSize, iAlignment);

	sDesc.Init(iStride, iAlignment, iOffset);
	bResult = mcOrder.FindInSorted(&sDesc, CompareFreeListDesc, &iIndex);
	if (bResult)
	{
		psDesc = mcOrder.Get(iIndex);
		return psDesc->pcFreeList;
	}
	else
	{
		pcList = mcFreeLists.InsertAfterTail();
		pcList->Init(psParams->iChunkSize, psParams->iMaxListSize, iAlignment);
		sDesc.pcFreeList = pcList;
		mcOrder.InsertAt(&sDesc, iIndex);
		return pcList;
	}
}
 void EnclosedRenderableContainerWidget::SetArea(const Vector2& Size)
 {
     Vector2 OldSize = WidgetBack->GetActualSize();
     Vector2 Position = WidgetBack->GetActualPosition();
     WidgetBack->SetActualSize(Size);
     for( AreaRenderableInfoIterator it = AreaRenderables.begin() ; it != AreaRenderables.end() ; it++ )
     {
         (*it).Offset = CalculateOffset(Size,OldSize,(*it).Offset,(*it).Anchor);
         if((*it).Tether != RT_TetherNone)
             (*it).Object->SetActualSize(CalculateSize(Size,OldSize,(*it).Object->GetActualSize(),(*it).Tether));
         (*it).Object->SetActualPosition(Position+(*it).Offset);
     }
     for( WidgetInfoIterator it = Widgets.begin() ; it != Widgets.end() ; it++ )
     {
         (*it).Offset = CalculateOffset(Size,OldSize,(*it).Offset,(*it).Anchor);
         if((*it).Tether != RT_TetherNone)
             (*it).Object->SetActualSize(CalculateSize(Size,OldSize,(*it).Object->GetActualSize(),(*it).Tether));
         (*it).Object->SetActualPosition(Position+(*it).Offset);
     }
 }
void BattleAnimationChara::Draw() {
	//If animation is targeted on the screen
	if (animation.scope == RPG::Animation::Scope_screen) {
		DrawAt(SCREEN_TARGET_WIDTH / 2, SCREEN_TARGET_HEIGHT / 2);
		return;
	}
	const int character_height = 24;
	int vertical_center = character.GetScreenY() - character_height/2;
	int offset = CalculateOffset(animation.position, character_height);
	DrawAt(character.GetScreenX(), vertical_center + offset);
}
Example #5
0
void BattleAnimationBattlers::Draw() {
	for (std::vector<Game_Battler*>::const_iterator it = battlers.begin();
	     it != battlers.end(); ++it) {
		const Game_Battler& battler = **it;
		const Sprite_Battler* sprite = Game_Battle::GetSpriteset().FindBattler(&battler);
		int offset = 0;
		if (sprite && sprite->GetBitmap()) {
			offset = CalculateOffset(animation.position, sprite->GetHeight());
		}
		DrawAt(battler.GetBattleX(), battler.GetBattleY() + offset);
	}
}
void BattleAnimationBattlers::Draw() {
	if (animation.scope == RPG::Animation::Scope_screen) {
		DrawAt(SCREEN_TARGET_WIDTH / 2, SCREEN_TARGET_HEIGHT / 3);
		return;
	}

	for (std::vector<Game_Battler*>::const_iterator it = battlers.begin();
	     it != battlers.end(); ++it) {
		const Game_Battler& battler = **it;
		const Sprite_Battler* sprite = Game_Battle::GetSpriteset().FindBattler(&battler);
		int offset = 0;
		if (sprite && sprite->GetBitmap()) {
			offset = CalculateOffset(animation.position, sprite->GetHeight());
		}
		DrawAt(battler.GetBattleX(), battler.GetBattleY() + offset);
	}
}
Example #7
0
CFreeList* CMemory::GetFreeList(unsigned int iElementSize, int iAlignment, int iOffset)
{
	SFreeListDesc		sDesc;
	BOOL				bResult;
	int					iIndex;
	SFreeListDesc*		psDesc;
	SMemoryFreeListParams*	psParams;
	int					iStride;
	int					iFinalOffset;

	iFinalOffset = CalculateOffset(iOffset - sizeof(SMemoryAllocation), iAlignment);
	psParams = GetFreeListParamsForSize(iElementSize);
	iStride = CalculateStride(psParams->iMaxElementSize, iAlignment);

	sDesc.Init(iStride, iAlignment, iOffset);
	bResult = mcOrder.FindInSorted(&sDesc, CompareFreeListDesc, &iIndex);
	if (bResult)
	{
		psDesc = mcOrder.Get(iIndex);
		return psDesc->pcFreeList;
	}
	return NULL;
}
Example #8
0
void BattleAnimationChara::Draw() {
	const int character_height = 24;
	int vertical_center = character.GetScreenY() - character_height/2;
	int offset = CalculateOffset(animation.position, character_height);
	DrawAt(character.GetScreenX(), vertical_center + offset);
}
Example #9
0
// Remove DC offset
float RemoveDCOffset(modplug::tracker::modsample_t& smp,
                                     SmpLength iStart,
                                     SmpLength iEnd,
                                     const MODTYPE modtype,
                                     module_renderer* const pSndFile)
//----------------------------------------------
{
    if(smp.sample_data == nullptr || smp.length < 1)
            return 0;

    modplug::tracker::modsample_t* const pSmp = &smp;

    if (iEnd > pSmp->length) iEnd = pSmp->length;
    if (iStart > iEnd) iStart = iEnd;
    if (iStart == iEnd)
    {
            iStart = 0;
            iEnd = pSmp->length;
    }

    iStart *= pSmp->GetNumChannels();
    iEnd *= pSmp->GetNumChannels();

    const double dMaxAmplitude = (pSmp->GetElementarySampleSize() == 2) ? GetMaxAmplitude<int16_t>() : GetMaxAmplitude<int8_t>();

    // step 1: Calculate offset.
    OffsetData oData = {0,0,0};
    if(pSmp->GetElementarySampleSize() == 2)
            oData = CalculateOffset(reinterpret_cast<int16_t*>(pSmp->sample_data) + iStart, iEnd - iStart);
    else if(pSmp->GetElementarySampleSize() == 1)
            oData = CalculateOffset(reinterpret_cast<int8_t*>(pSmp->sample_data) + iStart, iEnd - iStart);

    double dMin = oData.dMin, dMax = oData.dMax, dOffset = oData.dOffset;

    const float fReportOffset = (float)dOffset;

    if((int)(dOffset * dMaxAmplitude) == 0)
            return 0;

    // those will be changed...
    dMax += dOffset;
    dMin += dOffset;

    // ... and that might cause distortion, so we will normalize this.
    const double dAmplify = 1 / bad_max(dMax, -dMin);

    // step 2: centralize + normalize sample
    dOffset *= dMaxAmplitude * dAmplify;
    if(pSmp->GetElementarySampleSize() == 2)
            RemoveOffsetAndNormalize( reinterpret_cast<int16_t*>(pSmp->sample_data) + iStart, iEnd - iStart, dOffset, dAmplify);
    else if(pSmp->GetElementarySampleSize() == 1)
            RemoveOffsetAndNormalize( reinterpret_cast<int8_t*>(pSmp->sample_data) + iStart, iEnd - iStart, dOffset, dAmplify);

    // step 3: adjust global vol (if available)
    if((modtype & (MOD_TYPE_IT | MOD_TYPE_MPT)) && (iStart == 0) && (iEnd == pSmp->length * pSmp->GetNumChannels()))
    {
            BEGIN_CRITICAL();
            pSmp->global_volume = bad_min((uint16_t)(pSmp->global_volume / dAmplify), 64);
            for (modplug::tracker::chnindex_t i = 0; i < MAX_VIRTUAL_CHANNELS; i++)
            {
                    if(pSndFile->Chn[i].sample_data == pSmp->sample_data)
                    {
                            pSndFile->Chn[i].nGlobalVol = pSmp->global_volume;
                    }
            }
            END_CRITICAL();
    }

    AdjustEndOfSample(smp, pSndFile);

    return fReportOffset;
}
Example #10
0
// Remove DC offset
float RemoveDCOffset(ModSample &smp,
					 SmpLength iStart,
					 SmpLength iEnd,
					 const MODTYPE modtype,
					 CSoundFile &sndFile)
//---------------------------------------
{
	if(smp.pSample == nullptr || smp.nLength < 1)
		return 0;

	if (iEnd > smp.nLength) iEnd = smp.nLength;
	if (iStart > iEnd) iStart = iEnd;
	if (iStart == iEnd)
	{
		iStart = 0;
		iEnd = smp.nLength;
	}

	iStart *= smp.GetNumChannels();
	iEnd *= smp.GetNumChannels();

	const double dMaxAmplitude = (smp.GetElementarySampleSize() == 2) ? GetMaxAmplitude<int16>() : GetMaxAmplitude<int8>();

	// step 1: Calculate offset.
	OffsetData oData = {0,0,0};
	if(smp.GetElementarySampleSize() == 2)
		oData = CalculateOffset(static_cast<int16 *>(smp.pSample) + iStart, iEnd - iStart);
	else if(smp.GetElementarySampleSize() == 1)
		oData = CalculateOffset(static_cast<int8*>(smp.pSample) + iStart, iEnd - iStart);

	double dMin = oData.dMin, dMax = oData.dMax, dOffset = oData.dOffset;

	const float fReportOffset = (float)dOffset;

	if((int)(dOffset * dMaxAmplitude) == 0)
		return 0;

	// those will be changed...
	dMax += dOffset;
	dMin += dOffset;

	// ... and that might cause distortion, so we will normalize this.
	const double dAmplify = 1 / MAX(dMax, -dMin);

	// step 2: centralize + normalize sample
	dOffset *= dMaxAmplitude * dAmplify;
	if(smp.GetElementarySampleSize() == 2)
		RemoveOffsetAndNormalize( static_cast<int16 *>(smp.pSample) + iStart, iEnd - iStart, dOffset, dAmplify);
	else if(smp.GetElementarySampleSize() == 1)
		RemoveOffsetAndNormalize( static_cast<int8 *>(smp.pSample) + iStart, iEnd - iStart, dOffset, dAmplify);

	// step 3: adjust global vol (if available)
	if((modtype & (MOD_TYPE_IT | MOD_TYPE_MPT)) && (iStart == 0) && (iEnd == smp.nLength * smp.GetNumChannels()))
	{
		CriticalSection cs;

		smp.nGlobalVol = std::min((uint16)(smp.nGlobalVol / dAmplify), uint16(64));
		for (CHANNELINDEX i = 0; i < MAX_CHANNELS; i++)
		{
			if(sndFile.m_PlayState.Chn[i].pModSample == &smp)
			{
				sndFile.m_PlayState.Chn[i].nInsVol = smp.nGlobalVol;
				if(sndFile.m_PlayState.Chn[i].pModInstrument)
				{
					sndFile.m_PlayState.Chn[i].nInsVol = (smp.nGlobalVol * sndFile.m_PlayState.Chn[i].pModInstrument->nGlobalVol) >> 6;
				}
			}