void Wavefunction<Rank>::AllocateData() { blitz::TinyVector<int, Rank> shape = Repr->GetInitialShape(); int name = AllocateData(shape); SetActiveBuffer(name); }
int SensorConnection::PrepareDataListening(void* aNewDataObjects, int aDataCount, void*& aOldDataObject, int aDataType) { JELOG2(ESensor); if (!iParams) { iParams = new DataFillerParams(); if (!iParams) { return ERROR_NOMEMORY; } iParams->iDataCount = aDataCount; iParams->iJavaPeer = iJavaPeer; iParams->iDatas = AllocateData(KMax_buffersize, aDataType); if (!iParams->iDatas) { delete iParams; iParams = 0; return ERROR_NOMEMORY; } } aOldDataObject = iParams->iDataObjects; iParams->iDataObjects = aNewDataObjects; return ERROR_NONE; }
/** Load from raw color array */ void FColorVertexBuffer::InitFromColorArray( const FColor *InColors, const uint32 Count, const uint32 InStride ) { check( Count > 0 ); NumVertices = Count; // Allocate the vertex data storage type. AllocateData(); // Copy the colors { VertexData->AddUninitialized(Count); const uint8 *Src = (const uint8 *)InColors; FColor *Dst = (FColor *)VertexData->GetDataPointer(); for( uint32 i = 0; i < Count; ++i) { *Dst++ = *(const FColor*)Src; Src += InStride; } } // Make a copy of the vertex data pointer. Data = VertexData->GetDataPointer(); }
//----------------------------------------------------------------------------- // Name : iwfEntity () (Alternate Constructor) // Desc : iwfEntity Class Constructor, allocates specified amount of data //----------------------------------------------------------------------------- iwfEntity::iwfEntity( ULONG Size ) { // Reset / Cleare required vars EntityTypeID = 0; Name = NULL; DataSize = 0; DataArea = NULL; // Allocate memory AllocateData( Size ); }
//----------------------------------------------------------------------------- // Name : iwfScriptRef () (Alternate Constructor) // Desc : iwfScriptRef Class Constructor, allocates specified amount of data //----------------------------------------------------------------------------- iwfScriptRef::iwfScriptRef( ULONG Size ) { // Reset / Clear required vars ScriptSource = 0; Name = NULL; ScriptSource = 0; ScriptSize = 0; ScriptData = NULL; // Allocate memory AllocateData( Size ); }
//----------------------------------------------------------------------------- // Name : iwfTexture () (Alternate Constructor) // Desc : iwfTexture Class Constructor, allocates specified amount of data //----------------------------------------------------------------------------- iwfTexture::iwfTexture( ULONG Size ) { // Reset / Clear required vars TextureSource = 0; Name = NULL; TextureFormat = 0; TextureSize = 0; TextureData = NULL; // Allocate memory AllocateData( Size ); }
void FPositionVertexBuffer::Init(const TArray<FVector>& InPositions) { NumVertices = InPositions.Num(); if ( NumVertices ) { AllocateData(); check( Stride == InPositions.GetTypeSize() ); VertexData->ResizeBuffer(NumVertices); Data = VertexData->GetDataPointer(); FMemory::Memcpy( Data, InPositions.GetData(), Stride * NumVertices ); } }
/** * Initializes this vertex buffer with the contents of the given vertex buffer. * @param InVertexBuffer - The vertex buffer to initialize from. */ void FPositionVertexBuffer::Init(const FPositionVertexBuffer& InVertexBuffer) { NumVertices = InVertexBuffer.GetNumVertices(); if ( NumVertices ) { AllocateData(); check( Stride == InVertexBuffer.GetStride() ); VertexData->ResizeBuffer(NumVertices); Data = VertexData->GetDataPointer(); const uint8* InData = InVertexBuffer.Data; FMemory::Memcpy( Data, InData, Stride * NumVertices ); } }
float * DataLoader::LoadData(string fileName, float * & pData, float * & pLabel) { /* Coding logic: Read text file Arrange data into floating number array format. */ cout << "Loading data from: " << fileName << endl; // Hard code mFeatureLen mFeatureLen = 54; FILE * f = fopen(fileName.c_str(), "r"); fpos_t * startPos = new fpos_t; fgetpos(f, startPos); try { if (f==NULL) { throw fileName; } } catch(string fileName) { cout << "Cannot open file: " << fileName << endl; } // go through the file once // to count the number of floats // and return some important parameters RunThroughFile(f); float * pNewData = new float[(mNumFloats/mNumFeatures-1) * mNumFeatures]; //pData = new float[mNumFloats]; float * pNewLabel = new float[mNumFeatures]; pData = pNewData; pLabel = pNewLabel; fsetpos(f, startPos); AllocateData(f, pData, pLabel); }
/** Export the data from a string, used for editor Copy&Paste. */ void FColorVertexBuffer::ImportText(const TCHAR* SourceText) { check(SourceText); check(!VertexData); uint32 VertexCount; if (FParse::Value(SourceText, TEXT("ColorVertexData("), VertexCount)) { while(*SourceText && *SourceText != TEXT(')')) { ++SourceText; } while(*SourceText && *SourceText != TEXT('(')) { ++SourceText; } check(*SourceText == TEXT('(')); ++SourceText; NumVertices = VertexCount; AllocateData(); VertexData->ResizeBuffer(NumVertices); uint8 *Dst = (uint8 *)VertexData->GetDataPointer(); // 9 characters per color (ARGB in hex plus comma) for( uint32 i = 0; i < NumVertices; ++i) { // does not handle endianess or malformed input *Dst++ = FParse::HexDigit(SourceText[6]) * 16 + FParse::HexDigit(SourceText[7]); *Dst++ = FParse::HexDigit(SourceText[4]) * 16 + FParse::HexDigit(SourceText[5]); *Dst++ = FParse::HexDigit(SourceText[2]) * 16 + FParse::HexDigit(SourceText[3]); *Dst++ = FParse::HexDigit(SourceText[0]) * 16 + FParse::HexDigit(SourceText[1]); SourceText += 9; } check(*(SourceText - 1) == TCHAR(')')); // Make a copy of the vertex data pointer. Data = VertexData->GetDataPointer(); BeginInitResource(this); } }
/** * Initializes the buffer with the given vertices, used to convert legacy layouts. * @param InVertices - The vertices to initialize the buffer with. */ void FPositionVertexBuffer::Init(const TArray<FStaticMeshBuildVertex>& InVertices) { NumVertices = InVertices.Num(); // Allocate the vertex data storage type. AllocateData(); // Allocate the vertex data buffer. VertexData->ResizeBuffer(NumVertices); Data = VertexData->GetDataPointer(); // Copy the vertices into the buffer. for(int32 VertexIndex = 0;VertexIndex < InVertices.Num();VertexIndex++) { const FStaticMeshBuildVertex& SourceVertex = InVertices[VertexIndex]; const uint32 DestVertexIndex = VertexIndex; VertexPosition(DestVertexIndex) = SourceVertex.Position; } }
/** * Serializer * * @param Ar Archive to serialize with * @param bNeedsCPUAccess Whether the elements need to be accessed by the CPU */ void FPositionVertexBuffer::Serialize( FArchive& Ar, bool bNeedsCPUAccess ) { Ar << Stride << NumVertices; if(Ar.IsLoading()) { // Allocate the vertex data storage type. AllocateData( bNeedsCPUAccess ); } if(VertexData != NULL) { // Serialize the vertex data. VertexData->Serialize(Ar); // Make a copy of the vertex data pointer. Data = VertexData->GetDataPointer(); } }
/** * Serializer * * @param Ar Archive to serialize with * @param bNeedsCPUAccess Whether the elements need to be accessed by the CPU */ void FColorVertexBuffer::Serialize( FArchive& Ar, bool bNeedsCPUAccess ) { FStripDataFlags StripFlags(Ar, 0, VER_UE4_STATIC_SKELETAL_MESH_SERIALIZATION_FIX); if (Ar.IsSaving() && NumVertices > 0 && VertexData == NULL) { // ...serialize as if the vertex count were zero. Else on load serialization breaks. // This situation should never occur because VertexData should not be null if NumVertices // is greater than zero. So really this should be a checkf but I don't want to crash // the Editor when saving a package. UE_LOG(LogStaticMesh, Warning, TEXT("Color vertex buffer being saved with NumVertices=%d Stride=%d VertexData=NULL. This should never happen."), NumVertices, Stride ); int32 SerializedStride = 0; int32 SerializedNumVertices = 0; Ar << SerializedStride << SerializedNumVertices; } else { Ar << Stride << NumVertices; if (Ar.IsLoading() && NumVertices > 0) { // Allocate the vertex data storage type. AllocateData(bNeedsCPUAccess); } if (!StripFlags.IsDataStrippedForServer() || Ar.IsCountingMemory()) { if (VertexData != NULL) { // Serialize the vertex data. VertexData->Serialize(Ar); if (VertexData->Num() > 0) { // Make a copy of the vertex data pointer. Data = VertexData->GetDataPointer(); } } } } }
int main(int argc, char **argv) { glutInit(&argc, argv); if (argc != 1 && argc != 8) { fprintf(stderr, "usage : %s GridSize Dt Diff Visc Force Source\n", argv[0]); fprintf(stderr, "where:\n"); fprintf(stderr, "\t GridSize : Grid width/height\n"); fprintf(stderr, "\t Dt : Time step\n"); fprintf(stderr, "\t Diff : Diffusion rate of the density\n"); fprintf(stderr, "\t Visc : Viscosity of the fluid\n"); fprintf(stderr, "\t Force : Scales the mouse movement that generate a force\n"); fprintf(stderr, "\t Source : Amount of density that will be deposited\n"); fprintf(stderr, "\t Temp : The temperature of the fluid\n"); exit(1); } InitValues(); if (argc == 1) { fprintf(stderr, "Using defaults : GridSize=%d Dt=%g Diff=%g Visc=%g Force=%g Source=%g Temp=%g\n", GridSize, Dt, Diff, Visc, Force, Source, Temp); } else { GridSize = atoi(argv[1]); TotalGridCells = GridSize * GridSize; Dt = atof(argv[2]); Diff = atof(argv[3]); Visc = atof(argv[4]); Force = atof(argv[5]); Source = atof(argv[6]); Temp = atof(argv[7]); } printf("\n\nHow to use this demo:\n\n"); printf("\t Add density and temperature with the right mouse button\n"); printf("\t Change color of density being by toggling the r, g, and b keys\n"); printf("\t Add velocities with the left mouse button and dragging the mouse\n"); printf("\t Toggle density/velocity display with the 'v' key\n"); printf("\t Clear the simulation by pressing the 'c' key\n"); printf("\t Quit by pressing the 'q' key\n"); fflush(stdout); if (!AllocateData()) { exit(1); } ClearData(); WinX = 512; WinY = 512; OpenGlutWindow(); glutMainLoop(); exit(0); }
BOOL CChannels::EndChange(void) { int i; SChannel* psAddedChannel; SChannel* psRemovedChannel; CChannel* psChannel; int iSize; int iOffset; BOOL bAnyAdded; int iOldBitStride; int iAddedBitStride; int iOldByteStride; BOOL bResult; //I don't think this handles the case where the channels have been re-ordered... //Which as there *IS* no way of re-ordering them shouldn't be a problem. bResult = TRUE; if (IsChanging()) { if (mpvUserData != mpsChangingDesc->pvUserData) { //Switch between using mabData and mpvUserData. if ((mpvUserData == NULL) && (mpsChangingDesc->pvUserData != NULL)) { FreeData(); } else if ((mpvUserData != NULL) && (mpsChangingDesc->pvUserData == NULL)) { AllocateData(); //should copy from mpvUserData } mpvUserData = (char*)mpsChangingDesc->pvUserData; } if (!IsUserAllocated()) { //We're using mabData and have already allocated it. if ((miBitStride != 0) && (miSize != 0)) { //Remove for (i = 0; i < mpsChangingDesc->asRemovedChannels.NumElements(); i++) { psRemovedChannel = mpsChangingDesc->asRemovedChannels.Get(i); psChannel = GetChannel(psRemovedChannel->iChannel); if (psChannel->Is8BitAligned()) { iOffset = psChannel->miByteOffset; iSize = psChannel->miByteSize; mabData.BatchRemoveElements(iOffset, iSize, miSize, miByteStride); } else { //Deal with bitty removal. } masChannelOffsets.RemoveAt(masChannelOffsets.GetIndex(psChannel), TRUE); Recalculate(); } } //Add bAnyAdded = FALSE; for (i = 0; i < mpsChangingDesc->asAddedChannels.NumElements(); i++) { psAddedChannel = mpsChangingDesc->asAddedChannels.Get(i); psChannel = masChannelOffsets.Add(); psChannel->Init(psAddedChannel->iChannel, psAddedChannel->eType, psAddedChannel->bReverse); bAnyAdded = TRUE; } if (bAnyAdded) { iOldBitStride = miBitStride; iOldByteStride = miByteStride; Recalculate(); iAddedBitStride = miBitStride - iOldBitStride; if ((iAddedBitStride != 0) && (miSize != 0)) { if (Is8BitAligned(iOldBitStride, iAddedBitStride)) { iOffset = iOldByteStride; iSize = iAddedBitStride / 8; mabData.BatchInsertElements(iOffset, iSize, miSize, iOldByteStride); } else { //Deal with bitty addition. } } } //Change size due to size change. if (mpsChangingDesc->iSize != miSize) { miSize = mpsChangingDesc->iSize; iSize = CalculateByteSize(miBitStride, miSize); mabData.GrowToNumElements(iSize); } } else //Using user allocated memory. { //This assumes the mpvUserData is *already* in the form being specified. for (i = 0; i < mpsChangingDesc->asRemovedChannels.NumElements(); i++) { psRemovedChannel = mpsChangingDesc->asRemovedChannels.Get(i); psChannel = GetChannel(psRemovedChannel->iChannel); masChannelOffsets.RemoveAt(masChannelOffsets.GetIndex(psChannel), TRUE); } for (i = 0; i < mpsChangingDesc->asAddedChannels.NumElements(); i++) { psAddedChannel = mpsChangingDesc->asAddedChannels.Get(i); psChannel = masChannelOffsets.Add(); psChannel->Init(psAddedChannel->iChannel, psAddedChannel->eType, psAddedChannel->bReverse); } miSize = mpsChangingDesc->iSize; Recalculate(); } mpsChangingDesc->Kill(); free(mpsChangingDesc); mpsChangingDesc = NULL; } if (IsUserAllocated()) { mpvDataCache = mpvUserData; } else { mpvDataCache = mabData.GetData(); } return bResult; }
/** * Initializes the buffer with the given vertices, used to convert legacy layouts. * @param InVertices - The vertices to initialize the buffer with. */ void FColorVertexBuffer::Init(const TArray<FStaticMeshBuildVertex>& InVertices) { // First, make sure that there is at least one non-default vertex color in the original data. const int32 InVertexCount = InVertices.Num(); bool bAllColorsAreOpaqueWhite = true; bool bAllColorsAreEqual = true; if( InVertexCount > 0 ) { const FColor FirstColor = InVertices[ 0 ].Color; for( int32 CurVertexIndex = 0; CurVertexIndex < InVertexCount; ++CurVertexIndex ) { const FColor CurColor = InVertices[ CurVertexIndex ].Color; if( CurColor.R != 255 || CurColor.G != 255 || CurColor.B != 255 || CurColor.A != 255 ) { bAllColorsAreOpaqueWhite = false; } if( CurColor.R != FirstColor.R || CurColor.G != FirstColor.G || CurColor.B != FirstColor.B || CurColor.A != FirstColor.A ) { bAllColorsAreEqual = false; } if( !bAllColorsAreEqual && !bAllColorsAreOpaqueWhite ) { break; } } } if( bAllColorsAreOpaqueWhite ) { // Ensure no vertex data is allocated. CleanUp(); // Clear the vertex count and stride. Stride = 0; NumVertices = 0; } else { NumVertices = InVertexCount; // Allocate the vertex data storage type. AllocateData(); // Allocate the vertex data buffer. VertexData->ResizeBuffer(NumVertices); Data = VertexData->GetDataPointer(); // Copy the vertices into the buffer. for(int32 VertexIndex = 0;VertexIndex < InVertices.Num();VertexIndex++) { const FStaticMeshBuildVertex& SourceVertex = InVertices[VertexIndex]; const uint32 DestVertexIndex = VertexIndex; VertexColor(DestVertexIndex) = SourceVertex.Color; } } }