void LexerConf::FromJSON(const JSONElement& json)
{
    m_name = json.namedObject("Name").toString();
    m_lexerId = json.namedObject("Id").toInt();
    m_themeName = json.namedObject("Theme").toString();
    if(json.hasNamedObject("Flags")) {
        m_flags = json.namedObject("Flags").toSize_t();
    } else {
        SetIsActive(json.namedObject("IsActive").toBool());
        SetUseCustomTextSelectionFgColour(json.namedObject("UseCustomTextSelFgColour").toBool());
        SetStyleWithinPreProcessor(json.namedObject("StylingWithinPreProcessor").toBool());
    }
    SetKeyWords(json.namedObject("KeyWords0").toString(), 0);
    SetKeyWords(json.namedObject("KeyWords1").toString(), 1);
    SetKeyWords(json.namedObject("KeyWords2").toString(), 2);
    SetKeyWords(json.namedObject("KeyWords3").toString(), 3);
    SetKeyWords(json.namedObject("KeyWords4").toString(), 4);
    SetFileSpec(json.namedObject("Extensions").toString());

    m_properties.clear();
    JSONElement properties = json.namedObject("Properties");
    int arrSize = properties.arraySize();
    for(int i = 0; i < arrSize; ++i) {
        // Construct a style property
        StyleProperty p;
        p.FromJSON(properties.arrayItem(i));
        m_properties.insert(std::make_pair(p.GetId(), p));
    }
}
Example #2
0
Item World::RetrieveItemAtPos(const Position &position)
{
	for (auto item = itemsInCurrentLevel.begin(); item != itemsInCurrentLevel.end(); ++item)
	{
		if (item->GetPosition().IsEqual(position))
		{
			item->SetIsActive(false);
			return (*item);
		}
	}

	Report::Error("Item not found at position", __LINE__, __FILE__);
	return Item("", -1, -1, -1, ATTRIB_NONE, Position(-1, -1), false, false);
}
Example #3
0
void
ScrollbarActivity::ActivityStarted()
{
  mNestedActivityCounter++;
  CancelFadeBeginTimer();
  if (!SetIsFading(false)) {
    return;
  }
  UnregisterFromRefreshDriver();
  StartListeningForScrollbarEvents();
  StartListeningForScrollAreaEvents();
  SetIsActive(true);

  NS_ASSERTION(mIsActive, "need to be active during activity");
  NS_ASSERTION(!mIsFading, "must not be fading during activity");
}
Example #4
0
void
ScrollbarActivity::EndFade()
{
  NS_ASSERTION(mIsActive, "still need to be active at this point");
  NS_ASSERTION(!IsActivityOngoing(), "why wasn't the fade end timer cancelled when scrollbar activity started?");

  if (!SetIsFading(false)) {
    return;
  }
  SetIsActive(false);
  UnregisterFromRefreshDriver();
  StopListeningForScrollbarEvents();
  if (!mDisplayOnMouseMove) {
    StopListeningForScrollAreaEvents();
  }

  NS_ASSERTION(!mIsActive, "should have gone inactive after fade end");
  NS_ASSERTION(!mIsFading, "shouldn't be fading anymore");
}
Example #5
0
void Entity::Initialize(const luabind::object& script)
{
  _script = script;
  if (!_script.is_valid())
  {
    SetType((boost::format("entity")).str());
    SetName((boost::format("entity-%d") % GetId()).str());

    SetIsActive(true);

    return;
  }

  try
  {
    luabind::call_function<void>(_script["initialize"], _script, this);
  }
  catch (const std::exception& e)
  {
    ReportCallFunctionException("initialize", e);
    throw;
  }
}
Example #6
0
void InputSpace::ApplyPattern(PatternInfo *_pattern, int _time)
{
	// If there is no pattern to apply, do nothing.
	if (_pattern->type == PATTERN_NONE) {
		return;
	}

	// Advance to next trial if necessary.
	if (_time >= _pattern->nextTrialStartTime)
	{
		_pattern->trialCount++;
		_pattern->curTrialStartTime = _time;
		
		if (_pattern->minTrialDuration == _pattern->maxTrialDuration) {
			_pattern->nextTrialStartTime = _time + _pattern->minTrialDuration;
		} else {
			_pattern->nextTrialStartTime = _time + _pattern->minTrialDuration + (rand() % (_pattern->maxTrialDuration - _pattern->minTrialDuration + 1));
		}
	}

	int x, y, x1, y1, i, numSteps, step;
	float scale;
	int* bitmap;
	ImageInfo *imageInfo;
	
	switch (_pattern->type)
	{
	case PATTERN_STRIPE:
		// Apply stripe test pattern.

		// If this isn't the start of a new trial, no need to update activity.
		if (_time != _pattern->curTrialStartTime) {
			break;
		}

		// Start by clearing all activity.
		DeactivateAll();

		numSteps = (sizeX + sizeY - 1);
		step = (_pattern->trialCount - 1) % numSteps;

		for (x = 0; x < sizeX; x++)
		{
			y = step - x;

			if (y < 0) break;
			if (y >= sizeY) continue;

			for (i = 0; i < numValues; i++) {
				SetIsActive(x, y, i, true);
			}
		}
		break;

	case PATTERN_BOUNCING_STRIPE:
		// Apply stripe test pattern.

		// If this isn't the start of a new trial, no need to update activity.
		if (_time != _pattern->curTrialStartTime) {
			break;
		}

		// Start by clearing all activity.
		DeactivateAll();

		numSteps = (sizeX + sizeY - 2);
		step = (_pattern->trialCount - 1) % (numSteps * 2);

		// Reverse direction of stripe if appropriate.
		if (step >= numSteps) {
			step = numSteps - (step - numSteps);
		}

		for (x = 0; x < sizeX; x++)
		{
			y = step - x;

			if (y < 0) break;
			if (y >= sizeY) continue;

			for (i = 0; i < numValues; i++) {
				SetIsActive(x, y, i, true);
			}
		}
		break;
	
	case PATTERN_BAR:
		// Apply bar test pattern.

		// If this isn't the start of a new trial, no need to update activity.
		if (_time != _pattern->curTrialStartTime) {
			break;
		}

		// Start by clearing all activity.
		DeactivateAll();

		numSteps = sizeX;
		step = (_pattern->trialCount - 1) % numSteps;

		for (y = 0; y < sizeY; y++)
		{
			for (i = 0; i < numValues; i++) {
				SetIsActive(step, y, i, true);
			}
		}
		break;

	case PATTERN_BOUNCING_BAR:
		// Apply bouncing bar test pattern.
	
		// If this isn't the start of a new trial, no need to update activity.
		if (_time != _pattern->curTrialStartTime) {
			break;
		}

		// Start by clearing all activity.
		DeactivateAll();

		numSteps = sizeX - 1;
		step = (_pattern->trialCount - 1) % (numSteps * 2);

		// Reverse direction of bar if appropriate.
		if (step >= numSteps) {
			step = numSteps - (step - numSteps);
		}

		for (y = 0; y < sizeY; y++)
		{
			for (i = 0; i < numValues; i++) {
				SetIsActive(step, y, i, true);
			}
		}
		break;

	case PATTERN_TEXT:
		// Apply text test pattern.

		// If this isn't the start of a new trial, no need to update activity.
		if (_time != _pattern->curTrialStartTime) {
			break;
		}

		// Start by clearing all activity.
		DeactivateAll();

		numSteps = _pattern->string.length();
		step = (numSteps > 0) ? ((_pattern->trialCount - 1) % numSteps) : 0;
		scale = 0.8 * ((float)sizeY / 8.0f);

		// Initialize image and painter if not yet done.
		if (image == NULL) 
		{
			image = new QImage(sizeX, sizeY, QImage::Format_Mono);
			painter = new QPainter(image);
			painter->setPen(QColor(255,255,255));
			painter->setFont(QFont("Times", 10, QFont::Bold));
			painter->scale(scale, scale);
		}

		// Draw the text to the image.
		image->fill(0);
		painter->drawText(QRect(0, 0, (float)sizeX / scale, (float)sizeY / scale), Qt::AlignCenter, _pattern->string.mid(step, 1)); 

		for (y = 0; y < sizeY; y++)
		{
			for (x = 0; x < sizeX; x++)
			{
				if (QColor(image->pixel(x,y)).lightness() >= 128) 
				{
					for (i = 0; i < numValues; i++) {
						SetIsActive(x, y, i, true);
					}
				}				
			}
		}
		break;

	case PATTERN_BITMAP:
		// Apply bitmap test pattern.

		// If this isn't the start of a new trial, no need to update activity.
		if (_time != _pattern->curTrialStartTime) {
			break;
		}

		// Start by clearing all activity.
		DeactivateAll();

		// If there are no bitmaps given for this TestPattern, do nothing.
		if (_pattern->bitmaps.size() == 0) {
			break;
		}

		numSteps = (int)(_pattern->bitmaps.size());
		step = (numSteps > 0) ? ((_pattern->trialCount - 1) % numSteps) : 0;
		
		// Get a pointer to the current bitmap array.
		bitmap = _pattern->bitmaps[step];

		for (y = 0; y < sizeY; y++)
		{
			for (x = 0; x < sizeX; x++)
			{
				if (bitmap[y * sizeX + x] != 0) 
				{
					for (i = 0; i < numValues; i++) {
						SetIsActive(x, y, i, true);
					}
				}				
			}
		}
		break;
	case PATTERN_IMAGE:
		// Apply image test pattern.

		// If there are no images given for this Pattern, do nothing.
		if (_pattern->images.size() == 0) {
			break;
		}

		numSteps = (int)(_pattern->images.size());
		step = (numSteps > 0) ? ((_pattern->trialCount - 1) % numSteps) : 0;
		
		// Get a pointer to the current ImageInfo.
		imageInfo = _pattern->images[step];

		// If this is the start of a new trial...
		if (_time == _pattern->curTrialStartTime) 
		{
			if (_pattern->imageMotion == PATTERN_IMAGE_MOTION_ACROSS)
			{
				// Determine start and end coordinates.
				if ((rand() % 2) == 0)
				{
					// Horizontal movement.

					if ((rand() % 2) == 0)  
					{
						// Left to right
						_pattern->startX = 0;
						_pattern->endX = sizeX - imageInfo->contentWidth;
					} 
					else 
					{
						// Right to left
						_pattern->startX = sizeX - imageInfo->contentWidth;
						_pattern->endX = 0;
					}

					// Choose start and end Y positions.
					_pattern->startY = (sizeY <= imageInfo->contentHeight) ? 0 : (rand() % (sizeY - imageInfo->contentHeight));
					_pattern->endY = (sizeY <= imageInfo->contentHeight) ? 0 : (rand() % (sizeY - imageInfo->contentHeight));
				}
				else
				{
					// Vertical movement.

					if ((rand() % 2) == 0)  
					{
						// Top to bottom
						_pattern->startY = 0;
						_pattern->endY = sizeY - imageInfo->contentHeight;
					} 
					else 
					{
						// Bottom to top
						_pattern->startY = sizeY - imageInfo->contentHeight;
						_pattern->endY = 0;
					}

					// Choose start and end X positions.
					_pattern->startX = (sizeX <= imageInfo->contentWidth) ? 0 : (rand() % (sizeX - imageInfo->contentWidth));
					_pattern->endX = (sizeX <= imageInfo->contentWidth) ? 0 : (rand() % (sizeX - imageInfo->contentWidth));
				}
			}
			else if (_pattern->imageMotion == PATTERN_IMAGE_MOTION_ACROSS2)
			{
				// Determine start and end coordinates.
				if ((rand() % 2) == 0)
				{
					// Horizontal movement.

					if ((rand() % 2) == 0)  
					{
						// Left to right
						_pattern->startX = 0;
						_pattern->endX = sizeX - imageInfo->contentWidth;
					} 
					else 
					{
						// Right to left
						_pattern->startX = sizeX - imageInfo->contentWidth;
						_pattern->endX = 0;
					}

					// Choose start and end Y position.
					_pattern->startY = _pattern->endY = (sizeY <= imageInfo->contentHeight) ? 0 : (rand() % (sizeY - imageInfo->contentHeight));
				}
				else
				{
					// Vertical movement.

					if ((rand() % 2) == 0)  
					{
						// Top to bottom
						_pattern->startY = 0;
						_pattern->endY = sizeY - imageInfo->contentHeight;
					} 
					else 
					{
						// Bottom to top
						_pattern->startY = sizeY - imageInfo->contentHeight;
						_pattern->endY = 0;
					}

					// Choose start and end X position.
					_pattern->startX = _pattern->endX = (sizeX <= imageInfo->contentWidth) ? 0 : (rand() % (sizeX - imageInfo->contentWidth));
				}
			}
			else
			{
				// Image doesn't move.
				_pattern->startX = _pattern->startY = _pattern->endX = _pattern->endY = 0;
			}
		}

		// Start by clearing all activity.
		DeactivateAll();

		// Clear the image processing buffer.
		memset(buffer, 0, sizeX * sizeY * sizeof(int));

		// Determine current image position.
		int posX, posY;
		if (_pattern->imageMotion == PATTERN_IMAGE_MOTION_ACROSS)
		{
			posX = (int)(((float)(_pattern->endX - _pattern->startX)) / ((float)(_pattern->nextTrialStartTime - _pattern->curTrialStartTime - 1)) * ((float)(_time - _pattern->curTrialStartTime)) + _pattern->startX + 0.5f);
			posY = (int)(((float)(_pattern->endY - _pattern->startY)) / ((float)(_pattern->nextTrialStartTime - _pattern->curTrialStartTime - 1)) * ((float)(_time - _pattern->curTrialStartTime)) + _pattern->startY + 0.5f);
		}
		else if (_pattern->imageMotion == PATTERN_IMAGE_MOTION_ACROSS2)
		{
			if (_pattern->endX > _pattern->startX)
			{
				posY = _pattern->startY;
				posX = _pattern->startX + (_time - _pattern->curTrialStartTime);
				if (posX > _pattern->endX) posX = _pattern->endX - (posX - _pattern->endX);
			}
			else if (_pattern->endX < _pattern->startX)
			{
				posY = _pattern->startY;
				posX = _pattern->startX - (_time - _pattern->curTrialStartTime);
				if (posX < _pattern->endX) posX = _pattern->endX + (_pattern->endX - posX);
			}
			if (_pattern->endY > _pattern->startY)
			{
				posX = _pattern->startX;
				posY = _pattern->startY + (_time - _pattern->curTrialStartTime);
				if (posY > _pattern->endY) posY = _pattern->endY - (posY - _pattern->endY);
			}
			else if (_pattern->endY < _pattern->startY)
			{
				posX = _pattern->startX;
				posY = _pattern->startY - (_time - _pattern->curTrialStartTime);
				if (posY < _pattern->endY) posY = _pattern->endY + (_pattern->endY - posY);
			}
		}
		else
		{
			posX = _pattern->startX;
			posY = _pattern->startY;
		}

		int destX, destY, srcX, srcY;

		for (y = 0; y < imageInfo->contentHeight; y++)
		{
			destY = posY + y;

			if (destY < 0) continue;
			if (destY >= sizeY) break;

			srcY = imageInfo->contentY + y;

			for (x = 0; x < imageInfo->contentWidth; x++)
			{
				destX = posX + x;

				if (destX < 0) continue;
				if (destX >= sizeX) break;

				srcX = imageInfo->contentX + x;	

				if (imageInfo->data[srcY * imageInfo->width + srcX] > 0) 
				{
					buffer[destX + (destY * sizeX)] = 1;
				}				
			}
		}

		bool cur_on, center_on;
		int surround_on_count, surround_off_count;

		for (x = 0; x < sizeX; x++)
		{
			for (y = 0; y < sizeY; y++)
			{
				surround_on_count = 0;
				surround_off_count = 0;

				for (x1 = Max(0, x - 1); x1 < Min(sizeX, x + 2); x1++)
				{
					for (y1 = Max(0, y - 1); y1 < Min(sizeY, y + 2); y1++)
					{
						cur_on = (buffer[x1 + (y1 * sizeX)] == 1);

						if ((x1 == x) && (y1 == y))
						{
							center_on = cur_on;
						}
						else
						{
							if (cur_on) {
								surround_on_count++;
							} else {
								surround_off_count++;
							}
						}
					}
				}

				// On-center, off-surround in value 0.
				if (center_on && (surround_off_count >= 2)) {
					SetIsActive(x, y, 0, true);
				}

				// Off-center, on-surround in value 1.
				if ((GetNumValues() > 1) && (center_on == false) && (surround_on_count >= 2)) {
					SetIsActive(x, y, 1, true);
				}
			}
		}

		break;
	}
}
Example #7
0
void CBurnBot::Update(float fDelta)
{
	if(m_fDying)
	{
		m_fDying += fDelta;

		if( m_fDying > m_fDieTime )
		{
			CGame::GetInstance()->GetOF()->Destroy(this);
			SetIsActive(false);
		}
		float animTime = GetAnimationTime();
		animTime += fDelta;
		if(animTime > m_fDieTime)
			animTime = m_fDieTime;
		CAnimationProcessor::UpdateTime(GetCurrentAnimation(), animTime);
		CAnimationProcessor::Interpolator(GetCurrentAnimation(), animTime, PassCurrFrame());
		SetAnimationTime(animTime);
		return;
	}

	if(m_bDontDropPool && m_fDropWait > 0.0f)
	{
		m_fDropWait -= fDelta;
		if(m_fDropWait <= 0.0f)
		{
			m_fDropWait = 0.0f;
			m_bDontDropPool = false;
		}
	}

	KillCurrFrame();

	if(GetWasHit() == true)
	{
		float ftemp = GetHitDuration();
		ftemp += fDelta;
		SetHitDuration(ftemp);
		SetBeingHit(1);
		
		SetColor(COLOR_PATROLBOT_HIT);

		if(HIT_CAP < ftemp)
		{
			SetWasHit(false);
			SetHitDuration(0.0f);
			SetBeingHit(0);
			SetColor(COLOR_PATROLBOT);
		}
	}

	m_cAI.Update(fDelta);

	if( GetHealth() <= 0 )
	{
		WwiseNS::PlaySFX(WwiseNS::EVENT_SOUND_EXPLOSION);
		CGameplayState::GetInstance()->GetFX()->CreateEffect(EFFECT_DMGEXPLOSION,GetMatrix());
		if(!m_bDontDropPool)
		{
			CMoltenPool* pMoltenPool = nullptr;
			if(CGame::GetInstance()->GetOF()->Create(OBJ_POOL, (IBaseObject**)&pMoltenPool))
			{
				pMoltenPool->SetMatrix(GetMatrix());
				pMoltenPool->SetOriginalMatrix(GetMatrix());
				pMoltenPool->SetRadius(1.0f);
				pMoltenPool->SetScale(1.25f);
				pMoltenPool->SetScaleMod(1.4f);
				pMoltenPool->SetScaleTimer(1.0f);
				pMoltenPool->SetPoolStage(1);
				pMoltenPool->SetScalingMod(0.0f);
				pMoltenPool->SetDroppedID(1);
			}
		}
		CGameplayState::GetInstance()->GetFX()->CreateEffect(EFFECT_SMALLEXP,GetMatrix());
		SetBeingHit(0);
		TAnimation* tempAnim = CAssetManager::GetInstance()->GetAnimation(GetID(), 1);
		m_fDieTime = tempAnim->m_fDuration;
		m_fDying = .00001f;
		ChangeAnimation(1);
		SetAlive(false);
	}

	if(m_bCloseToTarget)
	{
		int nTemp = ((int)(m_fExplodeTimer*10)%2);

		float animTime = GetAnimationTime();
		animTime += fDelta;
		CAnimationProcessor::UpdateTime(GetCurrentAnimation(), animTime);
		CAnimationProcessor::Interpolator(GetCurrentAnimation(), animTime, PassCurrFrame());
		SetAnimationTime(animTime);

		if(nTemp)
			SetBeingHit(NOTHIT);
		else
			SetBeingHit(BURNEXPLODE);
	}
}