Exemple #1
0
	void CreateObjectModes(int dwTime)
	{
		//RECT rcDims={left, top, right, bottom};
		RECT rcDims;
		rcDims.top=36;
		rcDims.bottom=0;
		rcDims.left=-34;
		rcDims.right=34;
		bool bActiveSprites[MAX_SPRITES_PER_OBJECT];
		memset(&bActiveSprites, 0, sizeof(bActiveSprites));
		bActiveSprites[0]=true;
		CreateMode(bActiveSprites, rcDims, JC_GOOD|JC_NONDESTRUCT, TEXT("FLYING"));

		rcDims.top=30;
		rcDims.bottom=0;
		rcDims.left=-34;
		rcDims.right=34;

		bActiveSprites[0]=false;
		bActiveSprites[1]=true;

		CreateMode(bActiveSprites, rcDims, JC_NEUTRAL|JC_NONDESTRUCT, TEXT("DEAD"));

		SetObjectMode(1, dwTime);
	}
Exemple #2
0
	void CreateObjectModes(int dwTime)
	{
		RECT rcDims;
		rcDims.top=0;
		rcDims.bottom=0;
		rcDims.left=0;
		rcDims.right=0;
		bool bActiveSprites[MAX_SPRITES_PER_OBJECT];
		memset(&bActiveSprites, 0, sizeof(bActiveSprites));
		bActiveSprites[0]=true;
		CreateMode(bActiveSprites, rcDims, JC_NEUTRAL|JC_NONDESTRUCT, TEXT("EXPLODE"));
	
		SetObjectMode(1, dwTime);
	}
Exemple #3
0
	void CreateObjectModes(int dwTime)
	{
		RECT rcDims;
		rcDims.top=16;
		rcDims.bottom=0;
		rcDims.left=-20;
		rcDims.right=20;
		bool bActiveSprites[MAX_SPRITES_PER_OBJECT];
		memset(&bActiveSprites, 0, sizeof(bActiveSprites));
		bActiveSprites[0]=true;
		CreateMode(bActiveSprites, rcDims, JC_BAD|JC_DESTRUCT, TEXT("MISSILE"));
	
		SetObjectMode(1, dwTime);
	}
/***
	Open a file. If the file exists it is openned "rb+" else
	it is openned "wb+".
	Parameters:
		- szNameFile: Name of file (just the name or full path)
		- szMode
		- iShFlag
	Return:
		E_NOTOPEN or OK (errno e' setado)
***/
int
C_File::Open( const char *szNameFile, const char *szModePar, int iShFlagPar, BOOL bWait )
{
	C_FileCritSect	cCS0( this, CRITSECT0 );
	int		iMode;
	DWORD	dwShMode;
	DWORD	dwCreateMode;

	if( (_bIs32s && iFile != -1) || (!_bIs32s && hFile != INVALID_HANDLE_VALUE) ){
		return( !OK );
	}
	strcpy( szFileName, szNameFile ? szNameFile : "" );
	strcpy( szMode, szModePar ? szModePar : "" );
	iShFlag = iShFlagPar;
	do{
		iMode = Mode16( szModePar );
		dwAccess = Mode( szModePar );
		dwShMode = ShMode( iShFlagPar );
		dwCreateMode = szModePar ? CreateMode( szModePar ) : Exist( szFileName ) ? OPEN_EXISTING : CREATE_ALWAYS;
		if( _bIs32s ){
			if( szModePar != NULL ){
				if( iMode & O_CREAT ){
					iFile = sopen( szNameFile, iMode, iShFlagPar, S_IREAD | S_IWRITE );
				} else {
					iFile = sopen( szNameFile, iMode, iShFlagPar );
				}
			} else {
				if( Exist( szNameFile ) ){
					iFile = sopen( szNameFile, O_BINARY | O_RDWR, iShFlagPar );
				} else {
					iFile = sopen( szNameFile, O_BINARY | O_RDWR | O_CREAT, iShFlagPar, S_IREAD | S_IWRITE );
				}
			}
		} else {
			saSecurity.nLength = sizeof( SECURITY_ATTRIBUTES );
			saSecurity.lpSecurityDescriptor = NULL;
			saSecurity.bInheritHandle = TRUE;
			hFile = CreateFile( szNameFile, dwAccess, dwShMode, &saSecurity, dwCreateMode, 
						(DWORD) (FILE_ATTRIBUTE_ARCHIVE | FILE_FLAG_SEQUENTIAL_SCAN),
						NULL );
		}
		if( (_bIs32s && iFile == -1) || (!_bIs32s && hFile == INVALID_HANDLE_VALUE) ){
			if( _bIs32s ){
				if( errno == EEXIST && (iMode & O_EXCL) ){
					// ************************************************************
					// ATENCAO:
					// ************************************************************
					// nao tentar fechar outro arquivo para re-abrir este se 
					// errno == EEXIST && (iMode & O_EXCL)
					// ************************************************************
					iFile = -1;
					return( !OK );
				}
				if( errno == EACCES && bWait ){
					// o arquivo nao foi aberto porque estah sendo
					// usado por outro processo em modo exclusivo.
					// esperar um pouco e tentar novamente
					Sleep( 1000 );	// 1 segundo
					hFile = INVALID_HANDLE_VALUE;
					iFile = -1;

					// antes de continuar o loop, sair e entrar
					// novamente em regiao critica, para possibilitar
					// outros threads rodarem
					cCS0.LeaveCriticalSection();
					cCS0.EnterCriticalSection();
					continue;
				}
				if( errno != EMFILE ){
					iFile = -1;
					return( !OK );
				}
			} else {
				if( GetLastError() == ERROR_ALREADY_EXISTS && (dwCreateMode == CREATE_NEW) ){
					// ************************************************************
					// ATENCAO:
					// ************************************************************
					// nao tentar fechar outro arquivo para reabrir este se 
					// GetLastError() == ERROR_ALREADY_EXISTS && (dwCreateMode == CREATE_NEW)
					// ************************************************************
					return( !OK );
				}
				if( GetLastError() == ERROR_SHARING_VIOLATION && bWait ){
					// o arquivo nao foi aberto porque estah sendo
					// usado por outro processo em modo exclusivo.
					// esperar um pouco e tentar novamente
					Sleep( 1000 );	// 1 segundo
					hFile = INVALID_HANDLE_VALUE;
					iFile = -1;

					// antes de continuar o loop, sair e entrar
					// novamente em regiao critica, para possibilitar
					// outros threads rodarem
					cCS0.LeaveCriticalSection();
					cCS0.EnterCriticalSection();
					continue;
				}
				if( GetLastError() != ERROR_TOO_MANY_OPEN_FILES ){
#ifdef _USE_PRINTF_
					Printf( "C_File: Deu um erro doidao no Open." );
					Printf( "C_File: Fudeu em <%s>", szNameFile );
#endif
					hFile = INVALID_HANDLE_VALUE;
					iFile = -1;
					return( !OK );
				}
			}
#ifdef _USE_PRINTF_
			Printf( "C_File: Muitos arquivos abertos. Vou terminar." );
#endif
			return( !OK );
		}
	} while ( (_bIs32s && iFile == -1) || (!_bIs32s && hFile == INVALID_HANDLE_VALUE) );
	if( this == _xFile ){
		Seek( 0, SEEK_SET );
		char	szCaca[ 50 ];
		sprintf( szCaca, "%d", ++_iNumXDat );
		Write( szCaca, strlen( szCaca ) );
		Seek( 0, SEEK_SET );
		Lock( strlen( szCaca ) );
#ifdef _USE_PRINTF_
		Printf( "C_File: Abri o _xFile****************************" );
#endif
	}
	if( strstr( szMode, "a" ) != NULL ){
		Seek( 0L, SEEK_END );
	}
	Hash();
	_iNumOpenFiles++;
#ifdef _USE_PRINTF_
	Printf( "C_File: Abri o arquivo <%d> (nome = <%s> - handle = <%d>)", _iNumOpenFiles, szNameFile ? szNameFile : "NULL", _bIs32s ? iFile : (int) hFile );
#endif

	// MMF: apenas se nao for 32s e se iHeadSize estiver setado para um valor maior que 0
	if( !_bIs32s && iHeadSize > 0 ){
		// pegar o tamanho da janela no .ini
		char	szFullIniName[ MAXPATH ];

		GetAppFullPath( szFullIniName, MAXPATH );


		iMMFWinSize = GetPrivateProfileInt( CONFIG_SESSION, WINDOWSIZE_KEY, 
											WINDOWSIZE_DEFAULT, szFullIniName );

		// se o tamanho da janela for <= 0, significa que o usuario nao quer usar MMF
		hMMF = NULL;
		if( iMMFWinSize > 0 ){
			hMMF = CreateFileMapping( hFile, NULL,
				(dwAccess & GENERIC_WRITE) ? PAGE_READWRITE : PAGE_READONLY,
				0, 0, NULL );
		}
		pHeadView = NULL;
		pWinView = NULL;
		iWinNum = 0;
		iSeekWin = 0;
	}

	bRealLock = _bStaticRealLock;

	return( OK );
}