void DTextParser::ExtractBlock( DTextBlock& Block, tchar *pBufferTarget ) { if( pBufferTarget==NULL || m_pBuffer==NULL || Block.Size()==0 ) return; appMemcpy( pBufferTarget, (void*)(m_pBuffer+Block.Start()), Block.Size() ); }
FD3D9VertexBufferPtr FD3D9DynamicDrv::CreateVertexBuffer(UINT Size, void* ResourceData, UBOOL bIsDynamic) { check(Size > 0); const DWORD Usage = bIsDynamic ? (D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY) : 0; const D3DPOOL Pool = bIsDynamic ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED; IDirect3DVertexBuffer9* D3DVertexBuffer; VERIFYD3DRESULT(_Direct3DDevice->CreateVertexBuffer( Size, Usage, 0, Pool, (IDirect3DVertexBuffer9**)&D3DVertexBuffer, NULL)); FD3D9VertexBuffer* VertexBuffer = new FD3D9VertexBuffer(D3DVertexBuffer); if( ResourceData ) { void* Buffer = LockVertexBuffer(VertexBuffer, 0, Size, FALSE); check(Buffer); appMemcpy(Buffer, ResourceData, Size); UnlockVertexBuffer(VertexBuffer); } return VertexBuffer; }
void FArchiveFileWriterWindows::Serialize( void* V, INT Length ) { Pos += Length; INT Copy; while( Length > (Copy=ARRAY_COUNT(Buffer)-BufferCount) ) { appMemcpy( Buffer+BufferCount, V, Copy ); BufferCount += Copy; Length -= Copy; V = (BYTE*)V + Copy; Flush(); } if( Length ) { appMemcpy( Buffer+BufferCount, V, Length ); BufferCount += Length; } }
/** * Captures the current stack and updates stack tracking information. * optionally stores a user data pointer that the tracker will take ownership of and delete upon reset * you must allocate the memory with appMalloc() */ void FStackTracker::CaptureStackTrace(INT EntriesToIgnore /*=2*/, void* UserData /*=NULL*/) { // Avoid re-rentrancy as the code uses TArray/TMap. if( !bAvoidCapturing && bIsEnabled ) { // Scoped TRUE/ FALSE. bAvoidCapturing = TRUE; // Capture callstack and create CRC. QWORD* FullBackTrace = NULL; FullBackTrace = static_cast<QWORD*>(appAlloca((MAX_BACKTRACE_DEPTH + EntriesToIgnore) * sizeof(QWORD))); appCaptureStackBackTrace( FullBackTrace, MAX_BACKTRACE_DEPTH + EntriesToIgnore ); // Skip first NUM_ENTRIES_TO_SKIP entries as they are inside this code QWORD* BackTrace = &FullBackTrace[EntriesToIgnore]; DWORD CRC = appMemCrc( BackTrace, MAX_BACKTRACE_DEPTH * sizeof(QWORD), 0 ); // Use index if found INT* IndexPtr = CRCToCallStackIndexMap.Find( CRC ); if( IndexPtr ) { // Increase stack count for existing callstack. CallStacks(*IndexPtr).StackCount++; if (UpdateFn) { UpdateFn(CallStacks(*IndexPtr), UserData); } //We can delete this since the user gives ownership at the beginning of this call //and had a chance to update their data inside the above callback if (UserData) { appFree(UserData); } } // Encountered new call stack, add to array and set index mapping. else { // Add to array and set mapping for future use. INT Index = CallStacks.Add(); CRCToCallStackIndexMap.Set( CRC, Index ); // Fill in callstack and count. FCallStack& CallStack = CallStacks(Index); appMemcpy( CallStack.Addresses, BackTrace, sizeof(QWORD) * MAX_BACKTRACE_DEPTH ); CallStack.StackCount = 1; CallStack.UserData = UserData; } // We're done capturing. bAvoidCapturing = FALSE; } }
bool DTextParser::BindIndirect( lpctstr pBuffer, dword dwSize ) { if( pBuffer==NULL || dwSize==0 ) return false; SAFE_DELETE_ARRAY( m_pBuffer ); m_pBuffer = new char[dwSize]; appMemcpy( m_pBuffer, pBuffer, sizeof(char)*dwSize ); return true; }
void CHorAngle::ResizeBorder( unsigned int nBorders ) { if( nBorders==0 ) {// just clear SAFE_DELETE_ARRAY( m_aBorderAngle ); m_nNumBorders = 0; return; } // allocate new one float *pNewArray = new float[nBorders]; appMemcpy( m_aBorderAngle, pNewArray, Min( nBorders, m_nNumBorders ) ); SAFE_DELETE_ARRAY( m_aBorderAngle ); m_aBorderAngle = pNewArray; m_nNumBorders = nBorders; }
bool DTextParser::Bind( SString strBuffer ) { if( strBuffer.IsEmpty() ) return false; DTextParser::Release(); DTextParser::InitMembers(); m_lBufSize = strBuffer.Len()+1; // buffer init. SAFE_DELETE_ARRAY( m_pBuffer ); m_pBuffer = new char[m_lBufSize]; appMemzero( m_pBuffer, m_lBufSize*sizeof(char) ); // buffer assignment appMemcpy( m_pBuffer, (lpctstr)strBuffer, m_lBufSize-1 ); return true; }
void FArchiveFileReaderWindows::Serialize( void* V, INT Length ) { while( Length>0 ) { INT Copy = Min( Length, BufferBase+BufferCount-Pos ); if( Copy<=0 ) { if( Length >= ARRAY_COUNT(Buffer) ) { INT Count=0; // Read data from device via Win32 ReadFile API. { SCOPED_FILE_IO_READ_STATS( StatsHandle, Length, Pos ); ReadFile( Handle, V, Length, (DWORD*)&Count, NULL ); } if( Count!=Length ) { ArIsError = 1; Error->Logf( TEXT("ReadFile failed: Count=%i Length=%i Error=%s for file %s"), Count, Length, appGetSystemErrorMessage(), *Filename ); } Pos += Length; BufferBase += Length; return; } InternalPrecache( Pos, MAXINT ); Copy = Min( Length, BufferBase+BufferCount-Pos ); if( Copy<=0 ) { ArIsError = 1; Error->Logf( TEXT("ReadFile beyond EOF %i+%i/%i for file %s"), Pos, Length, Size, *Filename ); } if( ArIsError ) { return; } } appMemcpy( V, Buffer+Pos-BufferBase, Copy ); Pos += Copy; Length -= Copy; V = (BYTE*)V + Copy; } }
void DConsoleWindow::AddLine( lpctstr lpszLine, dword dwParam ) { if( m_apLines==NULL ) return; ++m_nCurrentEditLine; if( m_nCurrentEditLine >= m_nMaxLines ) { DConsoleLine *pFirst = m_apLines[0]; appMemcpy( &m_apLines[0], &m_apLines[1], sizeof(DConsoleLine*)*(m_nMaxLines-1) ); // shift to left m_apLines[m_nMaxLines-1] = pFirst;// rotate left m_nCurrentEditLine = m_nMaxLines-1; } DConsoleLine *pLine = m_apLines[m_nCurrentEditLine]; // assign text of line pLine->SetText( lpszLine ); }
void* DoSound(void* Arguments) { // Allocate the mixing buffer. ALock; MixBuffer = appMalloc(BufferSize, TEXT("Mixing Buffer")); AUnlock; INT Task = SOUND_MIXING, i; while (MixingThread.Valid) { switch (Task) { case SOUND_MIXING: ALock; // Empty the mixing buffer. appMemset(MixBuffer, 0, BufferSize); for (i=0; i<AUDIO_TOTALVOICES; i++) { // Get an enabled and active voice. if ((Voices[i].State&VOICE_ENABLED) && (Voices[i].State&VOICE_ACTIVE) && !AudioPaused) { // Mix a buffer's worth of sound. INT Format = Voices[i].pSample->Type & SAMPLE_16BIT ? SAMPLE_16BIT : SAMPLE_8BIT; switch (Format) { case SAMPLE_8BIT: if (AudioFormat & AUDIO_16BIT) MixVoice8to16( i ); break; case SAMPLE_16BIT: if (AudioFormat & AUDIO_16BIT) MixVoice16to16( i ); break; } } } AUnlock; Task = SOUND_PLAYING; break; case SOUND_PLAYING: // Block until the audio device is writable. if (!AudioPaused) { if (AudioWait() == 0) break; } else break; ALock; // Silence the audio buffer. appMemset(AudioBuffer, 0, BufferSize); // Ready the most recently mixed audio. appMemcpy(AudioBuffer, MixBuffer, BufferSize); // Play it. if (!AudioPaused) { PlayAudio(); } AUnlock; Task = SOUND_MIXING; break; } } // Free the mixing buffer. ALock; if (MixBuffer != NULL) appFree(MixBuffer); AUnlock; ExitAudioThread(&MixingThread); }
static UBOOL D3D9CompileShaderWrapper( const TCHAR* ShaderFilename, const TCHAR* FunctionName, const TCHAR* ShaderProfile, DWORD CompileFlags, const FShaderCompilerEnvironment& InEnvironment, const vector<D3DXMACRO>& Macros, FShaderCompilerOutput& Output, vector<FD3D9ConstantDesc>& Constants, FString& DisassemblyString, FString& ErrorString ) { const FString& SourceFile = LoadShaderSourceFile(ShaderFilename); TRefCountPtr<ID3DXBuffer> Shader; TRefCountPtr<ID3DXBuffer> Errors; FD3DIncludeEnvironment Environment(InEnvironment); TRefCountPtr<ID3DXConstantTable> ConstantTable; FTCHARToANSI AnsiSourceFile(SourceFile.c_str()); HRESULT Result = D3DXCompileShader( AnsiSourceFile, SourceFile.size(), &Macros[0], &Environment, TCHAR_TO_ANSI(FunctionName), TCHAR_TO_ANSI(ShaderProfile), CompileFlags, Shader.GetInitReference(), Errors.GetInitReference(), ConstantTable.GetInitReference()); if( FAILED(Result) ) { ErrorString = TEXT("Compile Failed without warnings!"); void* ErrorBuffer = Errors ? Errors->GetBufferPointer() : NULL; if( ErrorBuffer ) { FANSIToTCHAR Convert((ANSICHAR*)ErrorBuffer); ErrorString = Convert; } } else { // get the ShaderCode INT NumShaderBytes = Shader->GetBufferSize(); Output.ShaderCode.resize(NumShaderBytes); appMemcpy(&Output.ShaderCode[0], Shader->GetBufferPointer(), NumShaderBytes); // collect the constant table D3DXCONSTANTTABLE_DESC ConstantTableDesc; VERIFYD3DRESULT(ConstantTable->GetDesc(&ConstantTableDesc)); for(UINT ConstantIndex = 0; ConstantIndex < ConstantTableDesc.Constants; ++ConstantIndex) { D3DXHANDLE ConstantHandle = ConstantTable->GetConstant(NULL, ConstantIndex); D3DXCONSTANT_DESC ConstantDesc; UINT NumConstants = 1; VERIFYD3DRESULT(ConstantTable->GetConstantDesc(ConstantHandle, &ConstantDesc, &NumConstants)); FD3D9ConstantDesc NamedConstantDesc; appStrcpyANSI(NamedConstantDesc.Name, ConstantDesc.Name); NamedConstantDesc.bIsSampler = ConstantDesc.RegisterSet == D3DXRS_SAMPLER; NamedConstantDesc.RegisterIndex = ConstantDesc.RegisterIndex; NamedConstantDesc.RegisterCount = ConstantDesc.RegisterCount; Constants.push_back(NamedConstantDesc); } // disassemble a shader TRefCountPtr<ID3DXBuffer> DisassemblyBuffer; VERIFYD3DRESULT(D3DXDisassembleShader((const DWORD*)Shader->GetBufferPointer(), FALSE, NULL, DisassemblyBuffer.GetInitReference())); DisassemblyString = ANSI_TO_TCHAR((ANSICHAR*)DisassemblyBuffer->GetBufferPointer()); } return TRUE; }