Ejemplo n.º 1
0
void CCmpPathfinder::UpdateGrid()
{
	PROFILE3("UpdateGrid");

	CmpPtr<ICmpTerrain> cmpTerrain(GetSimContext(), SYSTEM_ENTITY);
	if (!cmpTerrain)
		return; // error

	if (!m_PreserveUpdateInformations)
		m_ObstructionsDirty.Clean();
	else
		m_PreserveUpdateInformations = false; // Next time will be a regular update

	// If the terrain was resized then delete the old grid data
	if (m_Grid && m_MapSize != cmpTerrain->GetTilesPerSide())
	{
		SAFE_DELETE(m_Grid);
		SAFE_DELETE(m_TerrainOnlyGrid);
	}

	// Initialise the terrain data when first needed
	if (!m_Grid)
	{
		m_MapSize = cmpTerrain->GetTilesPerSide();
		m_Grid = new Grid<NavcellData>(m_MapSize * Pathfinding::NAVCELLS_PER_TILE, m_MapSize * Pathfinding::NAVCELLS_PER_TILE);
		m_TerrainOnlyGrid = new Grid<NavcellData>(m_MapSize * Pathfinding::NAVCELLS_PER_TILE, m_MapSize * Pathfinding::NAVCELLS_PER_TILE);

		m_ObstructionsDirty.dirty = true;
		m_ObstructionsDirty.globallyDirty = true;
		m_ObstructionsDirty.globalRecompute = true;

		m_TerrainDirty = true;
	}

	CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSimContext(), SYSTEM_ENTITY);
	cmpObstructionManager->UpdateInformations(m_ObstructionsDirty);

	if (!m_ObstructionsDirty.dirty && !m_TerrainDirty)
		return;

	// If the terrain has changed, recompute m_Grid
	// Else, use data from m_TerrainOnlyGrid and add obstructions
	if (m_TerrainDirty)
	{
		Grid<u16> shoreGrid = ComputeShoreGrid();

		ComputeTerrainPassabilityGrid(shoreGrid);

		// Compute off-world passability
		// WARNING: CCmpRangeManager::LosIsOffWorld needs to be kept in sync with this

		const int edgeSize = 3 * Pathfinding::NAVCELLS_PER_TILE; // number of tiles around the edge that will be off-world

		NavcellData edgeMask = 0;
		for (PathfinderPassability& passability : m_PassClasses)
			edgeMask |= passability.m_Mask;

		int w = m_Grid->m_W;
		int h = m_Grid->m_H;

		if (cmpObstructionManager->GetPassabilityCircular())
		{
			for (int j = 0; j < h; ++j)
			{
				for (int i = 0; i < w; ++i)
				{
					// Based on CCmpRangeManager::LosIsOffWorld
					// but tweaked since it's tile-based instead.
					// (We double all the values so we can handle half-tile coordinates.)
					// This needs to be slightly tighter than the LOS circle,
					// else units might get themselves lost in the SoD around the edge.

					int dist2 = (i*2 + 1 - w)*(i*2 + 1 - w)
						+ (j*2 + 1 - h)*(j*2 + 1 - h);

					if (dist2 >= (w - 2*edgeSize) * (h - 2*edgeSize))
						m_Grid->set(i, j, m_Grid->get(i, j) | edgeMask);
				}
			}
		}
		else
		{
			for (u16 j = 0; j < h; ++j)
				for (u16 i = 0; i < edgeSize; ++i)
					m_Grid->set(i, j, m_Grid->get(i, j) | edgeMask);
			for (u16 j = 0; j < h; ++j)
				for (u16 i = w-edgeSize+1; i < w; ++i)
					m_Grid->set(i, j, m_Grid->get(i, j) | edgeMask);
			for (u16 j = 0; j < edgeSize; ++j)
				for (u16 i = edgeSize; i < w-edgeSize+1; ++i)
					m_Grid->set(i, j, m_Grid->get(i, j) | edgeMask);
			for (u16 j = h-edgeSize+1; j < h; ++j)
				for (u16 i = edgeSize; i < w-edgeSize+1; ++i)
					m_Grid->set(i, j, m_Grid->get(i, j) | edgeMask);
		}

		// Expand the impassability grid, for any class with non-zero clearance,
		// so that we can stop units getting too close to impassable navcells.
		// Note: It's not possible to perform this expansion once for all passabilities
		// with the same clearance, because the impassable cells are not necessarily the 
		// same for all these passabilities.
		for (PathfinderPassability& passability : m_PassClasses)
		{
			if (passability.m_Clearance == fixed::Zero())
				continue;

			int clearance = (passability.m_Clearance / Pathfinding::NAVCELL_SIZE).ToInt_RoundToInfinity();
			ExpandImpassableCells(*m_Grid, clearance, passability.m_Mask);
		}			

		// Store the updated terrain-only grid
		*m_TerrainOnlyGrid = *m_Grid;

		m_TerrainDirty = false;
		m_ObstructionsDirty.globalRecompute = true;
		m_ObstructionsDirty.globallyDirty = true;
	}
	else if (m_ObstructionsDirty.globalRecompute)
	{
		ENSURE(m_Grid->m_W == m_TerrainOnlyGrid->m_W && m_Grid->m_H == m_TerrainOnlyGrid->m_H);
		memcpy(m_Grid->m_Data, m_TerrainOnlyGrid->m_Data, (m_Grid->m_W)*(m_Grid->m_H)*sizeof(NavcellData));

		m_ObstructionsDirty.globallyDirty = true;
	}
	else
	{
		ENSURE(m_Grid->m_W == m_ObstructionsDirty.dirtinessGrid.m_W && m_Grid->m_H == m_ObstructionsDirty.dirtinessGrid.m_H);
		ENSURE(m_Grid->m_W == m_TerrainOnlyGrid->m_W && m_Grid->m_H == m_TerrainOnlyGrid->m_H);

		for (u16 i = 0; i < m_ObstructionsDirty.dirtinessGrid.m_W; ++i)
			for (u16 j = 0; j < m_ObstructionsDirty.dirtinessGrid.m_H; ++j)
				if (m_ObstructionsDirty.dirtinessGrid.get(i, j) == 1)
					m_Grid->set(i, j, m_TerrainOnlyGrid->get(i, j));
	}

	// Add obstructions onto the grid
	cmpObstructionManager->Rasterize(*m_Grid, m_PassClasses, m_ObstructionsDirty.globalRecompute);

	// Update the long-range pathfinder
	if (m_ObstructionsDirty.globallyDirty)
		m_LongPathfinder.Reload(GetPathfindingPassabilityClasses(), m_Grid);
	else
		m_LongPathfinder.Update(m_Grid, m_ObstructionsDirty.dirtinessGrid);
}
Ejemplo n.º 2
0
	BOOST_FOREACH( CPointSpriteManager* It, m_SandList )
	{
		SAFE_DELETE( It );
	}
Ejemplo n.º 3
0
//--------------------------------------------------------------------------------------------------------
void UnregisterAllVars()
{
	g_pCmdProc->Release();
	SAFE_DELETE( g_pCmdProc );
}
void OOOperatorDescriptorList::initializeWithDefaultOperators()
{
	using OD = OOOperatorDescriptor;
	// Unary operators
	add(new OD("preincrement", "++ expr", 1, 2, OD::RightAssociative,	OD::unary<UnaryOperation::PREINCREMENT>));
	add(new OD("predecrement", "-- expr", 1, 2, OD::RightAssociative,	OD::unary<UnaryOperation::PREDECREMENT>));
	add(new OD("postincrement", "expr ++", 1, 2, OD::LeftAssociative, OD::unary<UnaryOperation::POSTINCREMENT>));
	add(new OD("postdecrement", "expr --", 1, 2, OD::LeftAssociative, OD::unary<UnaryOperation::POSTDECREMENT>));
	add(new OD("unary plus", "+ expr", 1, 2, OD::RightAssociative,	OD::unary<UnaryOperation::PLUS>));
	add(new OD("unary minus", "- expr", 1, 2, OD::RightAssociative, OD::unary<UnaryOperation::MINUS>));
	add(new OD("not", "! expr", 1, 2, OD::RightAssociative, OD::unary<UnaryOperation::NOT>));
	add(new OD("complement", "~ expr", 1, 2, OD::RightAssociative, OD::unary<UnaryOperation::COMPLEMENT>));
	add(new OD("parenthesis", "( expr )", 1, 1, OD::NotAssociative, OD::unary<UnaryOperation::PARENTHESIS>));
	add(new OD("dereference", "* expr", 1, 2, OD::RightAssociative, OD::unary<UnaryOperation::DEREFERENCE>));
	add(new OD("addressof", "& expr", 1, 2, OD::RightAssociative, OD::unary<UnaryOperation::ADDRESSOF>));

	// Binary operators
	add(new OD("times", "expr * expr", 2, 3, OD::LeftAssociative, OD::binary<BinaryOperation::TIMES>));
	add(new OD("divide", "expr / expr", 2, 3, OD::LeftAssociative, OD::binary<BinaryOperation::DIVIDE>));
	add(new OD("remainder", "expr % expr", 2, 3, OD::LeftAssociative, OD::binary<BinaryOperation::REMAINDER>));
	add(new OD("plus", "expr + expr", 2, 4, OD::LeftAssociative, OD::binary<BinaryOperation::PLUS>));
	add(new OD("minus", "expr - expr", 2, 4, OD::LeftAssociative, OD::binary<BinaryOperation::MINUS>));
	add(new OD("left shift", "expr << expr", 2, 5, OD::LeftAssociative, OD::binary<BinaryOperation::LEFT_SHIFT>));
	add(new OD("right shift signed", "expr >> expr", 2, 5, OD::LeftAssociative,
			OD::binary<BinaryOperation::RIGHT_SHIFT_SIGNED>));
	add(new OD("righ shift unsigned", "expr >>> expr", 2, 5, OD::LeftAssociative,
			OD::binary<BinaryOperation::RIGHT_SHIFT_UNSIGNED>));
	add(new OD("less", "expr < expr", 2, 6, OD::LeftAssociative, OD::binary<BinaryOperation::LESS>));
	add(new OD("greater", "expr > expr", 2, 6, OD::LeftAssociative, OD::binary<BinaryOperation::GREATER>));
	add(new OD("less equals", "expr <= expr", 2, 6, OD::LeftAssociative, OD::binary<BinaryOperation::LESS_EQUALS>));
	add(new OD("greater equals", "expr >= expr", 2, 6, OD::LeftAssociative,
			OD::binary<BinaryOperation::GREATER_EQUALS>));
	add(new OD("equals", "expr == expr", 2, 7, OD::LeftAssociative, OD::binary<BinaryOperation::EQUALS>));
	add(new OD("not equals", "expr != expr", 2, 7, OD::LeftAssociative, OD::binary<BinaryOperation::NOT_EQUALS>));
	add(new OD("bitwise xor", "expr ^ expr", 2, 9, OD::LeftAssociative, OD::binary<BinaryOperation::XOR>));
	add(new OD("bitwise and", "expr & expr", 2, 8, OD::LeftAssociative, OD::binary<BinaryOperation::AND>));
	add(new OD("bitwise or", "expr | expr", 2, 10, OD::LeftAssociative, OD::binary<BinaryOperation::OR>));
	add(new OD("conditional and", "expr && expr", 2, 11, OD::LeftAssociative,
			OD::binary<BinaryOperation::CONDITIONAL_AND>));
	add(new OD("conditional or", "expr || expr", 2, 12, OD::LeftAssociative,
			OD::binary<BinaryOperation::CONDITIONAL_OR>));
	add(new OD("array index", "expr [ expr ]", 2, 1, OD::LeftAssociative, OD::binary<BinaryOperation::ARRAY_INDEX>));

	// Ternary operator
	add(new OD("conditional expression", "expr ? expr : expr", 3, 13, OD::RightAssociative,
			[](const QList<Expression*>& operands) -> Expression* {
		auto opr = new ConditionalExpression();
		opr->setCondition(operands.first());
		opr->setTrueExpression(operands.at(1));
		opr->setFalseExpression(operands.last());
		return opr;
	}));

	// Assignment
	add(new OD("assign", "expr = expr", 2, 14, OD::RightAssociative,
			OD::assignment<AssignmentExpression::ASSIGN>));
	add(new OD("assign", "expr += expr", 2, 14, OD::RightAssociative,
			OD::assignment<AssignmentExpression::PLUS_ASSIGN>));
	add(new OD("assign", "expr -= expr", 2, 14, OD::RightAssociative,
			OD::assignment<AssignmentExpression::MINUS_ASSIGN>));
	add(new OD("assign", "expr *= expr", 2, 14, OD::RightAssociative,
			OD::assignment<AssignmentExpression::TIMES_ASSIGN>));
	add(new OD("assign", "expr /= expr", 2, 14, OD::RightAssociative,
			OD::assignment<AssignmentExpression::DIVIDE_ASSIGN>));
	add(new OD("assign", "expr &= expr", 2, 14, OD::RightAssociative,
			OD::assignment<AssignmentExpression::BIT_AND_ASSIGN>));
	add(new OD("assign", "expr |= expr", 2, 14, OD::RightAssociative,
			OD::assignment<AssignmentExpression::BIT_OR_ASSIGN>));
	add(new OD("assign", "expr ^= expr", 2, 14, OD::RightAssociative,
			OD::assignment<AssignmentExpression::BIT_XOR_ASSIGN>));
	add(new OD("assign", "expr %= expr", 2, 14, OD::RightAssociative,
			OD::assignment<AssignmentExpression::REMAINDER_ASSIGN>));
	add(new OD("assign", "expr <<= expr", 2, 14, OD::RightAssociative,
			OD::assignment<AssignmentExpression::LEFT_SHIFT_ASSIGN>));
	add(new OD("assign", "expr >>= expr", 2, 14, OD::RightAssociative,
			OD::assignment<AssignmentExpression::RIGHT_SHIFT_SIGNED_ASSIGN>));
	add(new OD("assign", "expr >>>= expr", 2, 14, OD::RightAssociative,
			OD::assignment<AssignmentExpression::RIGHT_SHIFT_UNSIGNED_ASSIGN>));

	// Others
	add(new OD( "cast", "( expr ) expr", 2, 2, OD::RightAssociative,
			[](const QList<Expression*>& operands) -> Expression* {
		auto opr = new OOModel::CastExpression();
		opr->setType(operands.first());
		opr->setExpr(operands.last());
		return opr;
	}));

	add(new OD( "comma", "expr , expr", 2, 50, OD::LeftAssociative,
			[](const QList<Expression*>& operands) -> Expression* {
		auto opr = new OOModel::CommaExpression();
		opr->setLeft(operands.first());
		opr->setRight(operands.last());
		return opr;
	}));

	add(new OD( "initializer", "{ expr }", 1, 0, OD::NotAssociative,
			[](const QList<Expression*>& operands) -> Expression* {
		auto opr = new OOModel::ArrayInitializer();

		for(auto e: operands)
		{
			if (auto comma = dynamic_cast<OOModel::CommaExpression*>(e))
			{
				for(auto ee : comma->allSubOperands(true))
					opr->values()->append(ee);

				SAFE_DELETE(comma);
			}
			else
				opr->values()->append(e);
		}

		return opr;
	}));

	add(new OD( "new object", "new SPACE expr", 1, 2, OD::RightAssociative,
			[](const QList<Expression*>& operands) -> Expression* {
		auto opr = new OOModel::NewExpression();
		opr->setNewType( operands.first());
		return opr;
	}));

	add(new OD( "new array", "new SPACE expr [ expr ]", 2, 2, OD::RightAssociative,
			[](const QList<Expression*>& operands) -> Expression* {
		auto opr = new OOModel::NewExpression();
		opr->setNewType( operands.first());
		opr->setAmount(operands.last());
		return opr;
	}));

	add(new OD( "delete object", "delete SPACE expr", 1, 2, OD::RightAssociative,
			[](const QList<Expression*>& operands) -> Expression* {
		auto expr = new OOModel::DeleteExpression();
		expr->setExpr( operands.first());
		return expr;
	}));

	add(new OD( "delete array", "delete [] SPACE expr", 1, 2, OD::RightAssociative,
			[](const QList<Expression*>& operands) -> Expression* {
		auto expr = new OOModel::DeleteExpression();
		expr->setIsArray(true);
		expr->setExpr( operands.first());
		return expr;
	}));

	add(new OD( "member", "expr . id", 2, 1, OD::LeftAssociative,
			[](const QList<Expression*>& operands) -> Expression* {
		Q_ASSERT(operands.size() == 2);
		auto ref = dynamic_cast<OOModel::ReferenceExpression*>( operands[1]);
		Q_ASSERT(ref);

		auto r = new OOModel::ReferenceExpression( ref->name(), operands.first() );
		SAFE_DELETE(ref);
		return r;
	}));

	add(new OD( "member", "expr . id < expr >", 3, 1, OD::LeftAssociative,
			[](const QList<Expression*>& operands) -> Expression* {
		Q_ASSERT(operands.size() == 3 );
		auto ref = dynamic_cast<OOModel::ReferenceExpression*>( operands[1]);
		Q_ASSERT(ref);

		auto r = new OOModel::ReferenceExpression( ref->name(), operands.first() );
		SAFE_DELETE(ref);

		if (auto comma = dynamic_cast<OOModel::CommaExpression*>(operands.last()))
		{
			for(auto arg : comma->allSubOperands(true))
				r->typeArguments()->append(arg);

			SAFE_DELETE(comma);
		}
		else
			if (!dynamic_cast<OOModel::EmptyExpression*>(operands.last()) )
				r->typeArguments()->append(operands.last());

		return r;
	}));

	add(new OD( "call", "expr ( expr )", 2, 1, OD::LeftAssociative,
			[](const QList<Expression*>& operands) -> Expression* {
		Q_ASSERT(operands.size() == 2);
		auto ref = dynamic_cast<OOModel::ReferenceExpression*>( operands.first());
		Q_ASSERT(ref);

		auto opr = new OOModel::MethodCallExpression();
		opr->setRef(ref);

		if (auto comma = dynamic_cast<OOModel::CommaExpression*>(operands.last()))
		{
			for(auto arg : comma->allSubOperands(true))
				opr->arguments()->append(arg);

			SAFE_DELETE(comma);
		}
		else
			if (!dynamic_cast<OOModel::EmptyExpression*>(operands.last()) )
					opr->arguments()->append(operands.last());

		return opr;
	}));

	add(new OD( "type arguments", "id < expr >", 2, 0, OD::LeftAssociative,
			[](const QList<Expression*>& operands) -> Expression* {
		Q_ASSERT(operands.size() == 2);
		auto ref = dynamic_cast<OOModel::ReferenceExpression*>( operands.first());
		Q_ASSERT(ref);

		if (auto comma = dynamic_cast<OOModel::CommaExpression*>(operands.last()))
		{
			for(auto arg : comma->allSubOperands(true))
				ref->typeArguments()->append(arg);

			SAFE_DELETE(comma);
		}
		else
			if (!dynamic_cast<OOModel::EmptyExpression*>(operands.last()) )
					ref->typeArguments()->append(operands.last());

		return ref;
	}));

	add(new OD( "array type", "expr []", 1, 1, OD::LeftAssociative,
			[](const QList<Expression*>& operands) -> Expression* {
		auto at = new OOModel::ArrayTypeExpression();
		at->setTypeExpression(operands.first());
		return at;
	}));

	add(new OD( "pointer type", "expr *", 1, 1, OD::LeftAssociative,
			[](const QList<Expression*>& operands) -> Expression* {
		auto at = new OOModel::PointerTypeExpression();
		at->setTypeExpression(operands.first());
		return at;
	}));

	add(new OD( "reference type", "expr &", 1, 1, OD::LeftAssociative,
			[](const QList<Expression*>& operands) -> Expression* {
		auto at = new OOModel::ReferenceTypeExpression();
		at->setTypeExpression(operands.first());
		return at;
	}));

	add(new OD( "const qualifier", "const SPACE expr", 1, 1, OD::RightAssociative,
			[](const QList<Expression*>& operands) -> Expression* {
		auto at = new OOModel::TypeQualifierExpression();
		at->setQualifier(OOModel::Type::CONST);
		at->setTypeExpression(operands.first());
		return at;
	}));

	add(new OD( "volatile qualifier", "volatile SPACE expr", 1, 1, OD::RightAssociative,
			[](const QList<Expression*>& operands) -> Expression* {
		auto at = new OOModel::TypeQualifierExpression();
		at->setQualifier(OOModel::Type::VOLATILE);
		at->setTypeExpression(operands.first());
		return at;
	}));

	// Variable declaration
	auto varDeclFunction = [](const QList<Expression*>& operands) -> Expression*
	{
		auto vd = new OOModel::VariableDeclarationExpression();

		vd->decl()->setTypeExpression( operands.first() );
		auto ref = dynamic_cast<OOModel::ReferenceExpression*>(operands[1]);
		vd->decl()->setName( ref->name());
		SAFE_DELETE(ref);

		if (operands.size() > 2) vd->decl()->setInitialValue(operands[2]);
		return vd;
	};
	add(new OD( "variable decl", "expr SPACE id", 2, 40, OD::RightAssociative, varDeclFunction));
	add(new OD( "variable decl and initialization", "expr SPACE id = expr", 3, 40,
			OD::RightAssociative, varDeclFunction));

	add(new OD( "throw", "throw SPACE expr", 1, 30, OD::RightAssociative,
			[](const QList<Expression*>& operands) -> Expression* {
		auto expr = new OOModel::ThrowExpression();
		expr->setExpr( operands.first());
		return expr;
	}));

	// Command descriptors
	add(new CommandDescriptor( "command without params", "\\ id SPACE", 1, 0, OD::NotAssociative));
	add(new CommandDescriptor( "command with params", "\\ id ( expr )", 2, 0, OD::NotAssociative));

	add(new CompoundObjectDescriptor( "compound object",
			CompoundObjectDescriptor::compoundSignature(), 1, 0, OD::NotAssociative));
}
Ejemplo n.º 5
0
	//-------------------------------------------------------------------------
	// Allows the test state to preform any post-processing destruction.
	//-------------------------------------------------------------------------
	virtual void Close()
	{
		SAFE_DELETE( m_font );

		SAFE_DELETE( m_sound );
	}
Ejemplo n.º 6
0
//-----------------------------------------------------------------------------
// Name: OnPlaySound()
// Desc: User hit the "Play" button
//-----------------------------------------------------------------------------
HRESULT OnPlaySound( HWND hDlg ) 
{
    HRESULT hr;
    DWORD dwCreationFlags;

    BOOL bLooped      = ( IsDlgButtonChecked( hDlg, IDC_LOOP_CHECK )      == BST_CHECKED );
    BOOL bFocusSticky = ( IsDlgButtonChecked( hDlg, IDC_FOCUS_STICKY )    == BST_CHECKED );
    BOOL bFocusGlobal = ( IsDlgButtonChecked( hDlg, IDC_FOCUS_GLOBAL )    == BST_CHECKED );
    BOOL bMixHardware = ( IsDlgButtonChecked( hDlg, IDC_MIX_HARDWARE ) == BST_CHECKED );
    BOOL bMixSoftware = ( IsDlgButtonChecked( hDlg, IDC_MIX_SOFTWARE ) == BST_CHECKED );

    // Detrimine the creation flags to use based on the radio buttons
    dwCreationFlags = 0;
    if( bFocusGlobal )
        dwCreationFlags |= DSBCAPS_GLOBALFOCUS;

    if( bFocusSticky )
        dwCreationFlags |= DSBCAPS_STICKYFOCUS;

    if( bMixHardware )
        dwCreationFlags |= DSBCAPS_LOCHARDWARE;

    if( bMixSoftware )
        dwCreationFlags |= DSBCAPS_LOCSOFTWARE;

    // Add extra flags needed for the UI
    dwCreationFlags |= DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY;

    // Free any previous sound
    SAFE_DELETE( g_pSound );

    // Since the user can change the focus before the sound is played, 
    // we need to create the sound buffer every time the play button is pressed 

    // Load the wave file into a DirectSound buffer
    if( FAILED( hr = g_pSoundManager->Create( &g_pSound, m_strWaveFileName, dwCreationFlags, GUID_NULL ) ) )
    {
        // Not a critical failure, so just update the status
        DXTRACE_ERR( TEXT("Create"), hr );
        SetDlgItemText( hDlg, IDC_STATUS, TEXT("Could not create sound buffer.") );
        return S_FALSE; 
    }

    // Set the buffer options to what the sliders are set to
    OnSliderChanged( hDlg );

    // Only if the sound buffer was created perfectly should we update the UI 
    // and play the sound

    // Get the position of the sliders
    HWND hFreqSlider   = GetDlgItem( hDlg, IDC_FREQUENCY_SLIDER );
    HWND hPanSlider    = GetDlgItem( hDlg, IDC_PAN_SLIDER );
    HWND hVolumeSlider = GetDlgItem( hDlg, IDC_VOLUME_SLIDER );
    LONG lFrequency = (LONG)SendMessage( hFreqSlider,   TBM_GETPOS, 0, 0 ) * 1L;
    LONG lPan       = (LONG)SendMessage( hPanSlider,    TBM_GETPOS, 0, 0 ) * 500L;
    LONG lVolume    = (LONG)SendMessage( hVolumeSlider, TBM_GETPOS, 0, 0 ) * 100L;

    // Play the sound
    DWORD dwLooped = bLooped ? DSBPLAY_LOOPING : 0L;

    if( FAILED( hr = g_pSound->Play( 0, dwLooped, lVolume, lFrequency, lPan ) ) )
        return DXTRACE_ERR( TEXT("Play"), hr );

    // Update the UI controls to show the sound as playing
    EnablePlayUI( hDlg, FALSE );
    SetDlgItemText( hDlg, IDC_STATUS, TEXT("Sound playing.") );

    return S_OK;
}
Ejemplo n.º 7
0
Sun::~Sun()
{
   SAFE_DELETE( mLight );
   SAFE_DELETE( mCoronaMatInst );
   dFree_aligned(mMatrixSet);
}
Ejemplo n.º 8
0
CText::~CText()
{
	SAFE_DELETE(pString);
}
Ejemplo n.º 9
0
Archivo: Net.cpp Proyecto: xeon2007/b
void CNet::close(SOCKET sock)
{
	Packet * pCmd = removePacketBuff(sock);
	SAFE_DELETE(pCmd);
	_closeReturn(sock);
}
Ejemplo n.º 10
0
Trigger::~Trigger()
{
   delete mConvexList;
   mConvexList = NULL;
   SAFE_DELETE( mPhysicsRep );
}
Ejemplo n.º 11
0
BOOL CEITTable::Decode( BYTE* data, DWORD dataSize, DWORD* decodeReadSize )
{
	if( InitDecode(data, dataSize, decodeReadSize, TRUE) == FALSE ){
		return FALSE;
	}
	Clear();

	if( section_syntax_indicator != 1 ){
		//固定値がおかしい
		_OutputDebugString( L"++CEITTable:: section_syntax err" );
		return FALSE;
	}
	if( table_id < 0x4E || table_id > 0x6F ){
		//table_idがおかしい
		_OutputDebugString( L"++CEITTable:: table_id err 0x%02X", table_id );
		return FALSE;
	}

	if( section_length - 4 > 10 ){
		service_id = ((WORD)data[readSize])<<8 | data[readSize+1];
		version_number = (data[readSize+2]&0x3E)>>1;
		current_next_indicator = data[readSize+2]&0x01;
		section_number = data[readSize+3];
		last_section_number = data[readSize+4];
		transport_stream_id = ((WORD)data[readSize+5])<<8 | data[readSize+6];
		original_network_id = ((WORD)data[readSize+7])<<8 | data[readSize+8];
		segment_last_section_number = data[readSize+9];
		last_table_id = data[readSize+10];
		readSize += 11;
		while( readSize+11 < (DWORD)section_length+3-4 ){
			EVENT_INFO_DATA* item = new EVENT_INFO_DATA;
			item->event_id = ((WORD)data[readSize])<<8 | data[readSize+1];
			if( data[readSize+2] == 0xFF && data[readSize+3] == 0xFF && data[readSize+4] == 0xFF &&
				data[readSize+5] == 0xFF && data[readSize+6] == 0xFF )
			{
				item->StartTimeFlag = FALSE;
			}else{
				item->StartTimeFlag = TRUE;
				DWORD mjd = ((DWORD)data[readSize+2])<<8 | data[readSize+3];
				_MJDtoSYSTEMTIME(mjd, &(item->start_time));
				item->start_time.wHour = (WORD)_BCDtoDWORD(data+readSize+4, 1, 2);
				item->start_time.wMinute = (WORD)_BCDtoDWORD(data+readSize+5, 1, 2);
				item->start_time.wSecond = (WORD)_BCDtoDWORD(data+readSize+6, 1, 2);
			}
			readSize+=7;
			if( data[readSize] == 0xFF && data[readSize+1] == 0xFF && data[readSize+2] == 0xFF)
			{
				item->DurationFlag = FALSE;
			}else{
				item->DurationFlag = TRUE;
				item->durationHH = (WORD)_BCDtoDWORD(data+readSize, 1, 2);
				item->durationMM = (WORD)_BCDtoDWORD(data+readSize+1, 1, 2);
				item->durationSS = (WORD)_BCDtoDWORD(data+readSize+2, 1, 2);
			}
			readSize+=3;
			item->running_status = (data[readSize]&0xE0)>>5;
			item->free_CA_mode = (data[readSize]&0x10)>>4;
			item->descriptors_loop_length = ((WORD)data[readSize]&0x0F)<<8 | data[readSize+1];
			readSize += 2;
			if( readSize+item->descriptors_loop_length <= (DWORD)section_length+3-4 && item->descriptors_loop_length > 0){
				if( original_network_id == 0x0001 || original_network_id == 0x0003 ){
					SDDecode( data+readSize, item->descriptors_loop_length, &(item->descriptorList), NULL );
				}else{
					if( AribDescriptor::CreateDescriptors( data+readSize, item->descriptors_loop_length, &(item->descriptorList), NULL ) == FALSE ){
						_OutputDebugString( L"++CEITTable:: descriptor2 err" );
						SAFE_DELETE(item);
						return FALSE;
					}
				}
			}

			readSize+=item->descriptors_loop_length;

			eventInfoList.push_back(item);
		}
	}else{
Ejemplo n.º 12
0
PlantPatch::~PlantPatch()
{
	SAFE_DELETE(plantPatchTexture);
}
Ejemplo n.º 13
0
CWOBackendReq::~CWOBackendReq()
{
	SAFE_DELETE(resp_);
}
Ejemplo n.º 14
0
void GlobalObjectIndex::delInstance()
{
	SAFE_DELETE(onlyme);
}
Ejemplo n.º 15
0
CNiImage::~CNiImage(void)
{
	if (mn_texture_id!=-1)	gpc_texturemanager->ReleaseTexture(mn_texture_id);
	SAFE_DELETE(mp_texturename);
}
Ejemplo n.º 16
0
Archivo: Net.cpp Proyecto: xeon2007/b
bool CNet::recv(SOCKET sock, char * data, int size)
{
	if( size <= 0 || !data )
	{
		LOGGER_ERROR("[CNet] Error:%s:%d", __FILE__, __LINE__);
		return false;
	}

	bool bOldPacket = false;
	bool bFinish = false;

	Packet * pCmd = getPacketBuff(sock);
	if( pCmd )
		bOldPacket = true;

	int lsize = 0;
	UINT nReadPtr = 0;
	while( (lsize = size - nReadPtr) > 0 )
	{
		if( !pCmd )
		{
			//开始构建一个新的数据包
			pCmd = new Packet;
			if( !pCmd )
			{
				LOGGER_ERROR("[CNet] Error:%s:%d, new PACKET_COMMAN failed", __FILE__, __LINE__);
				return false;
			}

			bFinish = false;
		}
		pCmd->SetNetID(sock);

		int wsize = 0;
		if( pCmd->GetHeadLeftSize() > 0 )	//包头未满,把包头写满
		{
			wsize = pCmd->GetHeadLeftSize() < lsize ? pCmd->GetHeadLeftSize() : lsize;
		}
		else if( pCmd->GetLeftSize() > 0 )	//包数据未满,把整个包写满
		{
			wsize = pCmd->GetLeftSize() < lsize ? pCmd->GetLeftSize() : lsize;
		}

		pCmd->recvData(data + nReadPtr, wsize);
		nReadPtr += wsize;
		
		if( pCmd->GetLeftSize() == 0 )		//已摘出一个完整包
		{
			//数据校验
			if( !pCmd->crcCheck() )
			{
				LOGGER_ERROR("[CNet] crcCheck() sock=%d size=%d lsize=%d nReadPtr=%d failed", sock, size, lsize, nReadPtr);
				removePacketBuff(sock);
				SAFE_DELETE(pCmd);
				return false;
			}
			else
			{
				//设置其它参数
				pCmd->SetNetID(sock);

				//存入链表
				handlePacket(pCmd);
				updateRecvPacket(1);

				//清空缓存
				if( bOldPacket )
				{
					removePacketBuff(sock);
					bOldPacket = false;
				}

				pCmd = NULL;
				bFinish = true;
			}
		} 
		else if (pCmd->GetLeftSize() < 0) 
		{
			LOGGER_ERROR("[CNet] (pCmd->GetLeftSize() < 0 sock=%d", sock);
			removePacketBuff(sock);
			SAFE_DELETE(pCmd);
			return false;
	   }
	}

	//当前数据包没有构建完整,缓存下来,等待下次网络数据
	if( !bFinish )
	{
		insertPacketBuff( sock, pCmd );
	}
	
	return true;
}
Ejemplo n.º 17
0
//-----------------------------------------------------------------------------
// Name: 
// Desc: 
//-----------------------------------------------------------------------------
HRESULT CDPlay8Client::StartSessionEnum( const TCHAR* ipaddress )
{
    if( NULL == m_pDPlay )
        return E_FAIL;

    DPN_APPLICATION_DESC   dpnAppDesc;
    IDirectPlay8Address*   pDP8AddressHost  = NULL;
    IDirectPlay8Address*   pDP8AddressLocal = NULL;
    WCHAR*                 wszHostName      = NULL;
    HRESULT                hr;
    DWORD                  dwPort;

    m_dwNumSessions = 0;

    if( m_dpnhEnum != NULL )
    {
        // If an enumeration is already running, cancel 
        // it and start a new one.  Ignore any errors from CancelAsyncOperation
        m_pDPlay->CancelAsyncOperation( m_dpnhEnum, 0 );
        m_dpnhEnum = NULL;
    }

    // Create the local device address object
    if( FAILED( hr = CoCreateInstance( CLSID_DirectPlay8Address, NULL, 
                                       CLSCTX_ALL, IID_IDirectPlay8Address,
                                       (LPVOID*) &pDP8AddressLocal ) ) )
    {
        DXTRACE_ERR( TEXT("CoCreateInstance"), hr );
        goto LCleanup;
    }

    // Set IP service provider
    if( FAILED( hr = pDP8AddressLocal->SetSP( &CLSID_DP8SP_TCPIP ) ) )
    {
        DXTRACE_ERR( TEXT("SetSP"), hr );
        goto LCleanup;
    }


    // Create the remote host address object
    if( FAILED( hr = CoCreateInstance( CLSID_DirectPlay8Address, NULL, 
                                       CLSCTX_ALL, IID_IDirectPlay8Address,
                                       (LPVOID*) &pDP8AddressHost ) ) )
    {
        DXTRACE_ERR( TEXT("CoCreateInstance"), hr );
        goto LCleanup;
    }

    // Set IP service provider
    if( FAILED( hr = pDP8AddressHost->SetSP( &CLSID_DP8SP_TCPIP ) ) )
    {
        DXTRACE_ERR( TEXT("SetSP"), hr );
        goto LCleanup;
    }

    // Maze uses a fixed port, so add it to the host address
    dwPort = DPMAZESERVER_PORT;
    hr = pDP8AddressHost->AddComponent( DPNA_KEY_PORT, 
                                      &dwPort, sizeof(dwPort),
                                      DPNA_DATATYPE_DWORD );
    if( FAILED(hr) )
    {
        DXTRACE_ERR( TEXT("AddComponent"), hr );
        goto LCleanup;
    }

    // Set the remote host name (if provided)
    if( ipaddress != NULL && ipaddress[0] != 0 )
    {
        wszHostName = new WCHAR[_tcslen(ipaddress)+1];

        DXUtil_ConvertGenericStringToWide( wszHostName, ipaddress );

        hr = pDP8AddressHost->AddComponent( DPNA_KEY_HOSTNAME, wszHostName, 
                                            (wcslen(wszHostName)+1)*sizeof(WCHAR), 
                                            DPNA_DATATYPE_STRING );
        if( FAILED(hr) )
        {
            DXTRACE_ERR( TEXT("AddComponent"), hr );
            goto LCleanup;
        }
    }

    ZeroMemory( &dpnAppDesc, sizeof( DPN_APPLICATION_DESC ) );
    dpnAppDesc.dwSize = sizeof( DPN_APPLICATION_DESC );
    dpnAppDesc.guidApplication = StressMazeAppGUID;

    // Enumerate all StressMazeApp hosts running on IP service providers
    hr = m_pDPlay->EnumHosts( &dpnAppDesc, pDP8AddressHost, 
                              pDP8AddressLocal, NULL, 
                              0, INFINITE, 0, INFINITE, NULL, 
                              &m_dpnhEnum, 0 );
    if( hr != DPNERR_PENDING && FAILED(hr) )
    {
        DXTRACE_ERR_NOMSGBOX( TEXT("EnumHosts"), hr );
        goto LCleanup;
    }

LCleanup:
    SAFE_RELEASE( pDP8AddressHost);
    SAFE_RELEASE( pDP8AddressLocal );
    SAFE_DELETE( wszHostName );

    return hr;
}
Ejemplo n.º 18
0
Engine::~Engine()
{
	SAFE_DELETE(g_pAndroidTestApp);
}
Ejemplo n.º 19
0
//-----------------------------------------------------------------------------
// Name: MainDlgProc()
// Desc: Handles dialog messages
//-----------------------------------------------------------------------------
INT_PTR CALLBACK MainDlgProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam )
{
    HRESULT hr;

    switch( msg ) 
    {
        case WM_COMMAND:
            switch( LOWORD(wParam) )
            {
                case IDCANCEL:
                    EndDialog( hDlg, IDCANCEL );
                    break;

                case IDC_SOUNDFILE:
                    OnOpenSoundFile( hDlg );
                    break;

                case IDC_PLAY:
                    if( FAILED( hr = OnPlaySound( hDlg ) ) )
                    {
                        DXTRACE_ERR_MSGBOX( TEXT("OnPlaySound"), hr );
                        MessageBox( hDlg, "Error playing DirectSound buffer."
                                    "Sample will now exit.", "DirectSound Sample", 
                                    MB_OK | MB_ICONERROR );
                        EndDialog( hDlg, IDABORT );
                    }

                    break;

                case IDC_STOP:
                    if( g_pSound )
                    {
                        g_pSound->Stop();
                        g_pSound->Reset();
                    }
                    break;

                case IDC_MIX_DEFAULT:
                case IDC_MIX_HARDWARE:
                case IDC_MIX_SOFTWARE:
                case IDC_FOCUS_GLOBAL:
                case IDC_FOCUS_STICKY:
                case IDC_FOCUS_NORMAL:
                    UpdateBehaviorText( hDlg );
                    break;

                case IDHELP:
                    DXUtil_LaunchReadme( hDlg );
                    break;

                default:
                    return FALSE; // Didn't handle message
            }
            break;

        case WM_TIMER:
            OnTimer( hDlg );
            break;

        case WM_INITDIALOG:
            OnInitDialog( hDlg );
            break;

        case WM_NOTIFY:
            OnSliderChanged( hDlg );
            break;

        case WM_DESTROY:
            // Cleanup everything
            KillTimer( hDlg, 1 );    
            SAFE_DELETE( g_pSound );
            SAFE_DELETE( g_pSoundManager );
            break; 

        default:
            return FALSE; // Didn't handle message
    }

    return TRUE; // Handled message
}
Ejemplo n.º 20
0
CDiagramItem::~CDiagramItem()
{
	SAFE_DELETE(m_label);
}
CSMExport::~CSMExport() 
{
	SAFE_DELETE( m_Opts );
}
cArgoniteFemaleMagician::~cArgoniteFemaleMagician()
{
	SAFE_DELETE(m_pBody);
}
void Nuke::RenderGroundMarker()
{
    glEnable        (GL_TEXTURE_2D);
	glEnable        (GL_BLEND);
    glDisable       (GL_CULL_FACE );
    glDepthMask     (false);
    glDisable       (GL_DEPTH_TEST);

    Vector3 pos = m_targetPos;
    pos.y = g_app->m_location->m_landscape.m_heightMap->GetValue( pos.x, pos.z );

    float scale = 40.0f + 25.0f * sin(GetHighResTime());
    /*float camDist = ( g_app->m_camera->GetPos() - pos ).Mag();
    scale *= sqrtf(camDist) / 40.0f;*/

    Vector3 front(1,0,0);
    Vector3 up = g_app->m_location->m_landscape.m_normalMap->GetValue( pos.x, pos.z );
    Vector3 rightAngle = (front ^ up).Normalise();

    pos -= 0.5f * rightAngle * scale;
    pos += 0.5f * front * scale;
    pos += up * 3.0f;

    RGBAColour colour(200,20,20,255);

    char filename[256];
    char shadow[256];

    sprintf( filename, "icons/nukesymbol.bmp" );
    sprintf(shadow, "shadow_%s", filename);

    if( !g_app->m_resource->DoesTextureExist( shadow ) )
    {
        BinaryReader *binReader = g_app->m_resource->GetBinaryReader( filename );
        BitmapRGBA bmp( binReader, "bmp" );
	    SAFE_DELETE(binReader);

        bmp.ApplyBlurFilter( 10.0f );
	    g_app->m_resource->AddBitmap(shadow, bmp);
    }

    glBindTexture   (GL_TEXTURE_2D, g_app->m_resource->GetTexture(shadow));
    glBlendFunc     (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_COLOR);
    glColor4f       (1.0f, 1.0f, 1.0f, 0.0f);

    glBegin( GL_QUADS );
        glTexCoord2f(0,1);      glVertex3dv( (pos).GetData() );
        glTexCoord2f(1,1);      glVertex3dv( (pos + rightAngle * scale).GetData() );
        glTexCoord2f(1,0);      glVertex3dv( (pos - front * scale + rightAngle * scale).GetData() );
        glTexCoord2f(0,0);      glVertex3dv( (pos - front * scale).GetData() );
    glEnd();

    glColor4ubv     (colour.GetData());
	glBindTexture   (GL_TEXTURE_2D, g_app->m_resource->GetTexture( filename ));
	glBlendFunc     (GL_SRC_ALPHA, GL_ONE);							

    glBegin( GL_QUADS );
        glTexCoord2i(0,1);      glVertex3dv( (pos).GetData() );
        glTexCoord2i(1,1);      glVertex3dv( (pos + rightAngle * scale).GetData() );
        glTexCoord2i(1,0);      glVertex3dv( (pos - front * scale + rightAngle * scale).GetData() );
        glTexCoord2i(0,0);      glVertex3dv( (pos - front * scale).GetData() );
    glEnd();

    glDepthMask     (true);
    glEnable        (GL_DEPTH_TEST );    
    glDisable       (GL_BLEND);
	glBlendFunc     (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);							
	glDisable       (GL_TEXTURE_2D);
    glEnable        (GL_CULL_FACE);
}
Ejemplo n.º 24
0
TOKEN_DEF_END
//////////////////////////////////////////////////////////////////////////
HRESULT CAdItem::LoadBuffer(BYTE* Buffer, bool Complete)
{
	TOKEN_TABLE_START(commands)
		TOKEN_TABLE (ITEM)
		TOKEN_TABLE (TEMPLATE)
		TOKEN_TABLE (CURSOR_HOVER)
		TOKEN_TABLE (CURSOR_COMBINED)
		TOKEN_TABLE (CURSOR)
		TOKEN_TABLE (NAME)
		TOKEN_TABLE (IMAGE_HOVER)
		TOKEN_TABLE (IMAGE)
		TOKEN_TABLE (EVENTS)
		TOKEN_TABLE (SCRIPT)
		TOKEN_TABLE (CAPTION)
		TOKEN_TABLE (PROPERTY)
		TOKEN_TABLE (EDITOR_PROPERTY)
		TOKEN_TABLE (FONT)
		TOKEN_TABLE (ALPHA_COLOR)
		TOKEN_TABLE (ALPHA)
		TOKEN_TABLE (TALK_SPECIAL)
		TOKEN_TABLE (TALK)
		TOKEN_TABLE (SPRITE_HOVER)
		TOKEN_TABLE (SPRITE)
		TOKEN_TABLE (DISPLAY_AMOUNT)
		TOKEN_TABLE (AMOUNT_OFFSET_X)
		TOKEN_TABLE (AMOUNT_OFFSET_Y)
		TOKEN_TABLE (AMOUNT_ALIGN)
		TOKEN_TABLE (AMOUNT_STRING)
		TOKEN_TABLE (AMOUNT)
	TOKEN_TABLE_END
	
	BYTE* params;
	int cmd=2;
	CBParser parser(Game);

	if(Complete){
		if(parser.GetCommand ((char**)&Buffer, commands, (char**)&params)!=TOKEN_ITEM){
			Game->LOG(0, "'ITEM' keyword expected.");
			return E_FAIL;
		}
		Buffer = params;
	}

	int ar=0, ag=0, ab=0, alpha=255;
	while (cmd>0 && (cmd = parser.GetCommand ((char**)&Buffer, commands, (char**)&params)) > 0)
	{
		switch (cmd)
		{
			case TOKEN_TEMPLATE:
				if(FAILED(LoadFile((char*)params))) cmd = PARSERR_GENERIC;
			break;

			case TOKEN_NAME:
				SetName((char*)params);
			break;

			case TOKEN_FONT:
				SetFont((char*)params);
			break;

			case TOKEN_CAPTION:
				SetCaption((char*)params);
			break;

			case TOKEN_IMAGE:
			case TOKEN_SPRITE:
				SAFE_DELETE(m_Sprite);
				m_Sprite = new CBSprite(Game, this);
				if(!m_Sprite || FAILED(m_Sprite->LoadFile((char*)params, ((CAdGame*)Game)->m_TexItemLifeTime))){
					SAFE_DELETE(m_Sprite);
					cmd = PARSERR_GENERIC;
				}
			break;

			case TOKEN_IMAGE_HOVER:
			case TOKEN_SPRITE_HOVER:
				SAFE_DELETE(m_SpriteHover);
				m_SpriteHover = new CBSprite(Game, this);
				if(!m_SpriteHover || FAILED(m_SpriteHover->LoadFile((char*)params, ((CAdGame*)Game)->m_TexItemLifeTime))){
					SAFE_DELETE(m_SpriteHover);
					cmd = PARSERR_GENERIC;
				}
			break;

			case TOKEN_AMOUNT:
				parser.ScanStr((char*)params, "%d", &m_Amount);
			break;

			case TOKEN_DISPLAY_AMOUNT:
				parser.ScanStr((char*)params, "%b", &m_DisplayAmount);
			break;

			case TOKEN_AMOUNT_OFFSET_X:
				parser.ScanStr((char*)params, "%d", &m_AmountOffsetX);
			break;

			case TOKEN_AMOUNT_OFFSET_Y:
				parser.ScanStr((char*)params, "%d", &m_AmountOffsetY);
			break;

			case TOKEN_AMOUNT_ALIGN:
				if(CBPlatform::stricmp((char*)params, "left")==0) m_AmountAlign = TAL_LEFT;
				else if(CBPlatform::stricmp((char*)params, "right")==0) m_AmountAlign = TAL_RIGHT;
				else m_AmountAlign = TAL_CENTER;
			break;

			case TOKEN_AMOUNT_STRING:
				CBUtils::SetString(&m_AmountString, (char*)params);
			break;

			case TOKEN_TALK:
			{
				CBSprite* spr = new CBSprite(Game, this);
				if(!spr || FAILED(spr->LoadFile((char*)params, ((CAdGame*)Game)->m_TexTalkLifeTime))) cmd = PARSERR_GENERIC;
				else m_TalkSprites.Add(spr);
			}
			break;

			case TOKEN_TALK_SPECIAL:
			{
				CBSprite* spr = new CBSprite(Game, this);
				if(!spr || FAILED(spr->LoadFile((char*)params, ((CAdGame*)Game)->m_TexTalkLifeTime))) cmd = PARSERR_GENERIC;
				else m_TalkSpritesEx.Add(spr);
			}
			break;

			case TOKEN_CURSOR:
				SAFE_DELETE(m_CursorNormal);
				m_CursorNormal = new CBSprite(Game);
				if(!m_CursorNormal || FAILED(m_CursorNormal->LoadFile((char*)params, ((CAdGame*)Game)->m_TexItemLifeTime))){
					SAFE_DELETE(m_CursorNormal);
					cmd = PARSERR_GENERIC;
				}
			break;

			case TOKEN_CURSOR_HOVER:
				SAFE_DELETE(m_CursorHover);
				m_CursorHover = new CBSprite(Game);
				if(!m_CursorHover || FAILED(m_CursorHover->LoadFile((char*)params, ((CAdGame*)Game)->m_TexItemLifeTime))){
					SAFE_DELETE(m_CursorHover);
					cmd = PARSERR_GENERIC;
				}
			break;

			case TOKEN_CURSOR_COMBINED:
				parser.ScanStr((char*)params, "%b", &m_CursorCombined);
			break;

			case TOKEN_SCRIPT:
				AddScript((char*)params);
			break;

			case TOKEN_PROPERTY:
				ParseProperty(params, false);
			break;

			case TOKEN_ALPHA_COLOR:
				parser.ScanStr((char*)params, "%d,%d,%d", &ar, &ag, &ab);
				break;

			case TOKEN_ALPHA:
				parser.ScanStr((char*)params, "%d", &alpha);
			break;

			case TOKEN_EDITOR_PROPERTY:
				ParseEditorProperty(params, false);
			break;
		}
	}
	if (cmd == PARSERR_TOKENNOTFOUND){
		Game->LOG(0, "Syntax error in ITEM definition");
		return E_FAIL;
	}
	if (cmd == PARSERR_GENERIC){
		Game->LOG(0, "Error loading ITEM definition");
		return E_FAIL;
	}

	if(alpha != 0 && ar==0 && ag == 0 && ab == 0){
		ar = ag = ab = 255;
	}
	m_AlphaColor = DRGBA(ar, ag, ab, alpha);

	return S_OK;
}
Ejemplo n.º 25
0
void CSMPackageInstallDlg::OnOK()
{
    // TODO: Add extra validation here

    int ProgressInit = 0;

    m_comboDir.EnableWindow( FALSE );
    m_buttonEdit.EnableWindow( FALSE );

    RString sInstallDir;
    {
        CString s;
        m_comboDir.GetWindowText( s );
        sInstallDir = s;
    }

    // selected install dir becomes the new default
    int iSelectedInstallDirIndex = m_comboDir.GetCurSel();
    if( iSelectedInstallDirIndex == -1 )
    {
        Dialog::OK( NO_INSTALLATIONS.GetValue() );
        return;
    }

    SMPackageUtil::SetDefaultInstallDir( iSelectedInstallDirIndex );


    // mount the zip
    RageFileOsAbsolute file;
    if( !file.Open(m_sPackagePath) )
    {
        Dialog::OK( ssprintf(COULD_NOT_OPEN_FILE.GetValue(),m_sPackagePath.c_str()) );
        exit(1);	// better way to abort?
    }

    RageFileDriverZip zip;
    if( !zip.Load(&file) )
    {
        Dialog::OK( ssprintf(IS_NOT_A_VALID_ZIP.GetValue(),m_sPackagePath.c_str()) );
        exit(1);	// better way to abort?
    }

    RageFileDriverDirect dir( sInstallDir );
    // handle error?

    // Show comment (if any)
    {
        RString sComment = zip.GetGlobalComment();
        bool DontShowComment;
        if( sComment != "" && (!SMPackageUtil::GetPref("DontShowComment", DontShowComment) || !DontShowComment) )
        {
            ShowComment commentDlg;
            commentDlg.m_sComment = sComment;
            int nResponse = commentDlg.DoModal();
            if( nResponse != IDOK )
                return;	// cancelled
            if( commentDlg.m_bDontShow )
                SMPackageUtil::SetPref( "DontShowComment", true );
        }
    }

    /* Check for installed packages that should be deleted before installing. */
    if( !CheckPackages(zip) )
        return;	// cancelled


    // Unzip the SMzip package into the installation folder
    vector<RString> vs;
    GetSmzipFilesToExtract( zip, vs );
    for( unsigned i=0; i<vs.size(); i++ )
    {
        // Throw some text up so the user has something to look at during the long pause.
        CEdit* pEdit1 = (CEdit*)GetDlgItem(IDC_STATIC_MESSAGE1);
        pEdit1->SetWindowText( ssprintf(INSTALLING_PLEASE_WAIT.GetValue(), m_sPackagePath.c_str()) );
        CEdit* pEdit2 = (CEdit*)GetDlgItem(IDC_EDIT_MESSAGE2);
        pEdit2->SetWindowText( "" );
        GetDlgItem(IDC_STATIC_MESSAGE2)->ShowWindow( SW_HIDE );
        CProgressCtrl* pProgress1 = (CProgressCtrl*)GetDlgItem(IDC_PROGRESS1);
        //Show the hided progress bar
        if(!pProgress1->IsWindowVisible())
        {
            pProgress1->ShowWindow(SW_SHOWNORMAL);
        }
        //Initialize the progress bar and update the window 1 time (it's enough)
        if(!ProgressInit)
        {
            pProgress1->SetRange( 0, (short)vs.size() );
            pProgress1->SetStep(1);
            pProgress1->SetPos(0);
            SendMessage( WM_PAINT );
            UpdateWindow();		// Force the silly thing to hadle WM_PAINT now!
            ProgressInit = 1;
        }

        Dialog::Result result;
        do
        {
            // Extract the files
            const RString sFile = vs[i];
            LOG->Trace( "Extracting: "+sFile );

            RString sError;
            {
                int iErr;
                RageFileBasic *pFileFrom = zip.Open( sFile, RageFile::READ, iErr );
                if( pFileFrom == NULL )
                {
                    sError = ssprintf( ERROR_OPENING_SOURCE_FILE.GetValue(), sFile.c_str(), ssprintf("%d",iErr).c_str() );
                    goto show_error;
                }

                int iError;
                RageFileBasic *pFileTo = dir.Open( sFile, RageFile::WRITE, iError );
                if( pFileTo == NULL )
                {
                    sError = ssprintf( ERROR_OPENING_DESTINATION_FILE.GetValue(), sFile.c_str(), pFileTo->GetError().c_str() );
                    goto show_error;
                }

                RString sErr;
                if( !FileCopy(*pFileFrom, *pFileTo, sErr) )
                {
                    sError = ssprintf( ERROR_COPYING_FILE.GetValue(), sFile.c_str(), sErr.c_str() );
                    goto show_error;
                }

                SAFE_DELETE( pFileFrom );
                SAFE_DELETE( pFileTo );
            }

            break;

show_error:
            Dialog::Result result = Dialog::AbortRetryIgnore(sError);
            switch( result )
            {
            case Dialog::abort:
                exit(1);	// better way to exit?
                break;
            case Dialog::retry:
                break;
            case Dialog::ignore:
                // do nothing
                break;
            }
        } while( result == Dialog::retry );

        pProgress1->StepIt(); //increase the progress bar of 1 step
    }

    Dialog::OK( PACKAGE_INSTALLED_SUCCESSFULLY.GetValue() );

    // close the dialog
    CDialog::OnOK();
}
Ejemplo n.º 26
0
HRESULT CAdItem::Update()
{
	m_CurrentSprite = NULL;

	if(m_State==STATE_READY && m_AnimSprite){
		SAFE_DELETE(m_AnimSprite);
	}

	// finished playing animation?
	if(m_State==STATE_PLAYING_ANIM && m_AnimSprite!=NULL && m_AnimSprite->m_Finished){		
		m_State = STATE_READY;
		m_CurrentSprite = m_AnimSprite;
	}

	if(m_Sentence && m_State!=STATE_TALKING) m_Sentence->Finish();

	// default: stand animation
	if(!m_CurrentSprite) m_CurrentSprite = m_Sprite;

	switch(m_State){
		//////////////////////////////////////////////////////////////////////////
		case STATE_PLAYING_ANIM:
			m_CurrentSprite = m_AnimSprite;
		break;

		//////////////////////////////////////////////////////////////////////////
		case STATE_READY:
			if(!m_AnimSprite){
				if(Game->m_ActiveObject==this && m_SpriteHover)	m_CurrentSprite = m_SpriteHover;
				else m_CurrentSprite = m_Sprite;
			}
		break;

		//////////////////////////////////////////////////////////////////////////
		case STATE_TALKING:
			{
				m_Sentence->Update();
				if(m_Sentence->m_CurrentSprite) m_TempSprite2 = m_Sentence->m_CurrentSprite;

				bool TimeIsUp = (m_Sentence->m_Sound && m_Sentence->m_SoundStarted && (!m_Sentence->m_Sound->IsPlaying()&&!m_Sentence->m_Sound->IsPaused())) || (!m_Sentence->m_Sound && m_Sentence->m_Duration <= Game->m_Timer - m_Sentence->m_StartTime);
				if(m_TempSprite2==NULL || m_TempSprite2->m_Finished || (/*m_TempSprite2->m_Looping &&*/ TimeIsUp)){
					if(TimeIsUp){
						m_Sentence->Finish();
						m_TempSprite2 = NULL;
						m_State = STATE_READY;
					}
					else{
						m_TempSprite2 = GetTalkStance(m_Sentence->GetNextStance());
						if(m_TempSprite2){
							m_TempSprite2->Reset();
							m_CurrentSprite = m_TempSprite2;						
						}
						((CAdGame*)Game)->AddSentence(m_Sentence);
					}
				}
				else{
					m_CurrentSprite = m_TempSprite2;
					((CAdGame*)Game)->AddSentence(m_Sentence);
				}
			}
		break;
	}
	m_Ready = (m_State == STATE_READY);

	return S_OK;
}
Ejemplo n.º 27
0
SkyBox::~SkyBox()
{
    SAFE_DELETE(m_pSkyboxTechnique);
    SAFE_DELETE(m_pCubemapTex);
    SAFE_DELETE(m_pMesh);
}
Ejemplo n.º 28
0
//////////////////////////////////////////////////////////////////////////
// high level scripting interface
//////////////////////////////////////////////////////////////////////////
HRESULT CAdItem::ScCallMethod(CScScript* Script, CScStack *Stack, CScStack *ThisStack, char *Name)
{
	//////////////////////////////////////////////////////////////////////////
	// SetHoverSprite
	//////////////////////////////////////////////////////////////////////////
	if(strcmp(Name, "SetHoverSprite")==0){
		Stack->CorrectParams(1);

		bool SetCurrent = false;
		if(m_CurrentSprite && m_CurrentSprite == m_SpriteHover) SetCurrent = true;

		char* Filename = Stack->Pop()->GetString();

		SAFE_DELETE(m_SpriteHover);
		CBSprite* spr = new CBSprite(Game, this);
		if(!spr || FAILED(spr->LoadFile(Filename))){
			Stack->PushBool(false);
			Script->RuntimeError("Item.SetHoverSprite failed for file '%s'", Filename);
		}
		else {
			m_SpriteHover = spr;
			if(SetCurrent) m_CurrentSprite = m_SpriteHover;
			Stack->PushBool(true);
		}
		return S_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// GetHoverSprite
	//////////////////////////////////////////////////////////////////////////
	else if(strcmp(Name, "GetHoverSprite")==0){
		Stack->CorrectParams(0);

		if(!m_SpriteHover || !m_SpriteHover->m_Filename) Stack->PushNULL();
		else Stack->PushString(m_SpriteHover->m_Filename);
		return S_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// GetHoverSpriteObject
	//////////////////////////////////////////////////////////////////////////
	else if(strcmp(Name, "GetHoverSpriteObject")==0){
		Stack->CorrectParams(0);
		if(!m_SpriteHover) Stack->PushNULL();
		else Stack->PushNative(m_SpriteHover, true);
		return S_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// SetNormalCursor
	//////////////////////////////////////////////////////////////////////////
	if(strcmp(Name, "SetNormalCursor")==0){
		Stack->CorrectParams(1);

		char* Filename = Stack->Pop()->GetString();

		SAFE_DELETE(m_CursorNormal);
		CBSprite* spr = new CBSprite(Game);
		if(!spr || FAILED(spr->LoadFile(Filename)))
		{
			Stack->PushBool(false);
			Script->RuntimeError("Item.SetNormalCursor failed for file '%s'", Filename);
		}
		else {
			m_CursorNormal = spr;
			Stack->PushBool(true);			
		}
		return S_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// GetNormalCursor
	//////////////////////////////////////////////////////////////////////////
	else if(strcmp(Name, "GetNormalCursor")==0){
		Stack->CorrectParams(0);

		if(!m_CursorNormal || !m_CursorNormal->m_Filename) Stack->PushNULL();
		else Stack->PushString(m_CursorNormal->m_Filename);
		return S_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// GetNormalCursorObject
	//////////////////////////////////////////////////////////////////////////
	else if(strcmp(Name, "GetNormalCursorObject")==0){
		Stack->CorrectParams(0);

		if(!m_CursorNormal) Stack->PushNULL();
		else Stack->PushNative(m_CursorNormal, true);
		return S_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// SetHoverCursor
	//////////////////////////////////////////////////////////////////////////
	if(strcmp(Name, "SetHoverCursor")==0){
		Stack->CorrectParams(1);

		char* Filename = Stack->Pop()->GetString();

		SAFE_DELETE(m_CursorHover);
		CBSprite* spr = new CBSprite(Game);
		if(!spr || FAILED(spr->LoadFile(Filename)))
		{
			Stack->PushBool(false);
			Script->RuntimeError("Item.SetHoverCursor failed for file '%s'", Filename);
		}
		else {
			m_CursorHover = spr;
			Stack->PushBool(true);			
		}
		return S_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// GetHoverCursor
	//////////////////////////////////////////////////////////////////////////
	else if(strcmp(Name, "GetHoverCursor")==0){
		Stack->CorrectParams(0);

		if(!m_CursorHover || !m_CursorHover->m_Filename) Stack->PushNULL();
		else Stack->PushString(m_CursorHover->m_Filename);
		return S_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// GetHoverCursorObject
	//////////////////////////////////////////////////////////////////////////
	else if(strcmp(Name, "GetHoverCursorObject")==0){
		Stack->CorrectParams(0);

		if(!m_CursorHover) Stack->PushNULL();
		else Stack->PushNative(m_CursorHover, true);
		return S_OK;
	}

	else return CAdTalkHolder::ScCallMethod(Script, Stack, ThisStack, Name);
}
Ejemplo n.º 29
0
//-----------------------------------------------------------------------------
// GuiInspectorMountingGroup - inspectGroup override
//-----------------------------------------------------------------------------
bool GuiInspectorMountingGroup::inspectGroup()
{
   // We can't inspect a group without a target!
   if( !mParent->getNumInspectObjects() )
      return false;

   // to prevent crazy resizing, we'll just freeze our stack for a sec..
   mStack->freeze(true);

   bool bNoGroup = false;

   // Un-grouped fields are all sorted into the 'general' group
   if ( dStricmp( mCaption, "General" ) == 0 )
      bNoGroup = true;
      
   // Just delete all fields and recreate them (like the dynamicGroup)
   // because that makes creating controls for array fields a lot easier
   clearFields();
   
   bool bNewItems = false;
   bool bMakingArray = false;
   GuiStackControl *pArrayStack = NULL;
   GuiRolloutCtrl *pArrayRollout = NULL;
   bool bGrabItems = false;

   AbstractClassRep* commonAncestorClass = findCommonAncestorClass();
   AbstractClassRep::FieldList& fieldList = commonAncestorClass->mFieldList;
   for( AbstractClassRep::FieldList::iterator itr = fieldList.begin();
        itr != fieldList.end(); ++ itr )
   {
      AbstractClassRep::Field* field = &( *itr );
      if( field->type == AbstractClassRep::StartGroupFieldType )
      {
         // If we're dealing with general fields, always set grabItems to true (to skip them)
         if( bNoGroup == true )
            bGrabItems = true;
         else if( dStricmp( field->pGroupname, mCaption ) == 0 )
            bGrabItems = true;
         continue;
      }
      else if ( field->type == AbstractClassRep::EndGroupFieldType )
      {
         // If we're dealing with general fields, always set grabItems to false (to grab them)
         if( bNoGroup == true )
            bGrabItems = false;
         else if( dStricmp( field->pGroupname, mCaption ) == 0 )
            bGrabItems = false;
         continue;
      }
      
      // Skip field if it has the HideInInspectors flag set.
      
      if( field->flag.test( AbstractClassRep::FIELD_HideInInspectors ) )
         continue;

      if( ( bGrabItems == true || ( bNoGroup == true && bGrabItems == false ) ) && itr->type != AbstractClassRep::DeprecatedFieldType )
      {
         if( bNoGroup == true && bGrabItems == true )
            continue;

         // If the field already exists, just update it
			GuiInspectorField *fieldGui = findField( field->pFieldname );
			if ( fieldGui != NULL )
			{
				fieldGui->updateValue();
				continue;
			}
            
			bNewItems = true;
            
			if(field->pFieldname == StringTable->insert("mountNode"))
			{
				fieldGui = new GuiInspectorNodeListField();

				Entity* e = dynamic_cast<Entity*>(mParent->getInspectObject(0));
				if(e)
					(dynamic_cast<GuiInspectorNodeListField*>(fieldGui))->setTargetEntity(e);
			}
			else
			{
				fieldGui = constructField( field->type );
				if ( fieldGui == NULL )
					fieldGui = new GuiInspectorField();
			}

			fieldGui->init( mParent, this );            
			fieldGui->setInspectorField( field );
                     
			if( fieldGui->registerObject() )
			{
				#ifdef DEBUG_SPEW
				Platform::outputDebugString( "[GuiInspectorGroup] Adding field '%s'",
					field->pFieldname );
				#endif

				mChildren.push_back( fieldGui );
				mStack->addObject( fieldGui );
			}
			else
			{
				SAFE_DELETE( fieldGui );
			}
      }
   }
   mStack->freeze(false);
   mStack->updatePanes();

   // If we've no new items, there's no need to resize anything!
   if( bNewItems == false && !mChildren.empty() )
      return true;

   sizeToContents();

   setUpdate();

   return true;
}
//-----------------------------------------------------------------------------
void CPUTAssetLibrary::DeleteAssetLibrary()
{
    SAFE_DELETE(mpAssetLibrary);
}