示例#1
0
文件: PCA.cpp 项目: dmead/sc2bot
void PCA<T>::Transform(Vector<T> &Result, const Vector<T> &Input, UINT ReducedDimension)
{
    if(Result.Length() != ReducedDimension)
    {
	    Result.Allocate(ReducedDimension);
    }
	Transform(Result.CArray(), Input.CArray(), ReducedDimension);
}
示例#2
0
void Compression::DecompressStreamFromFile(const String &filename, Vector<BYTE> &stream)
{
    Vector<BYTE> input;
    Utility::GetFileData(filename, input);
    UINT32 decompressedByteCount = ((UINT32*)input.CArray())[0];
    stream.Allocate(decompressedByteCount);

    uLongf finalByteCount = decompressedByteCount;
    int result = uncompress(stream.CArray(), &finalByteCount, input.CArray() + sizeof(UINT32), input.Length() - sizeof(UINT32));
    PersistentAssert(result == Z_OK, "Decompression failed");
    PersistentAssert(finalByteCount == decompressedByteCount, "Decompression returned invalid length");
}
示例#3
0
文件: Pipe.cpp 项目: dmead/sc2bot
bool Pipe::ReadMessage(Vector<BYTE> &Message)
{
    Assert(_Handle != NULL, "Pipe invalid in Pipe::ReadMessage");
    DWORD BytesReady  = 0;
    BOOL Success = PeekNamedPipe(
        _Handle,
        NULL,
        0,
        NULL,
        &BytesReady,
        NULL);
    Assert(Success != FALSE, "PeekNamedPipe failed in Pipe::ReadMessage");
    Message.Allocate(BytesReady);
    if(BytesReady == 0)
    {
        return false;
    }

    DWORD BytesRead;
    Success = ReadFile( 
        _Handle,                // handle to pipe 
        Message.CArray(),       // buffer to receive data 
        Message.Length(),       // size of buffer 
        &BytesRead,             // number of bytes read 
        NULL);                  // not overlapped I/O 
    Assert(Success != FALSE && BytesRead > 0, "ReadFile failed in Pipe::ReadMessage");
    return true;
}
示例#4
0
 void CopyFile(const String &SourceFile, const String &DestFile)
 {
     Vector<BYTE> Data;
     GetFileData(SourceFile, Data);
     FILE *File = Utility::CheckedFOpen(DestFile.CString(), "wb");
     Utility::CheckedFWrite(Data.CArray(), sizeof(BYTE), Data.Length(), File);
     fclose(File);
 }
示例#5
0
 void GetFileData(const String &Filename, Vector<BYTE> &Output)
 {
     FILE *InputFile = Utility::CheckedFOpen(Filename.CString(), "rb");
     UINT FileSize = Utility::GetFileSize(Filename);
     Output.Allocate(FileSize);
     Utility::CheckedFRead(Output.CArray(), sizeof(BYTE), FileSize, InputFile);
     fclose(InputFile);
 }
示例#6
0
void FileCollection::MuddleData(Vector<BYTE> &Data)
{
    BYTE *DataArray = Data.CArray();
    UINT DataLength = Data.Length();
    for(UINT Index = 0; Index < DataLength; Index++)
    {
        DataArray[Index] = 255 - DataArray[Index];
    }
}
示例#7
0
void RayIntersectorKDTree::Init(const BaseMesh &M)
{
    Console::WriteString("Building RayIntersectorKDTree...");
    FreeMemory();

    _VertexCount = M.VertexCount();
    _TriangleCount = M.FaceCount();

    Console::WriteString(String(_TriangleCount) + String(" base triangles, "));
    

    _Vertices = new Vec3f[_VertexCount];
    _Indices = new UINT[_TriangleCount * 3];
    
    const MeshVertex *MeshVertices = M.Vertices();
    const DWORD *MeshIndices = M.Indices();
    
    for(UINT VertexIndex = 0; VertexIndex < _VertexCount; VertexIndex++)
    {
        _Vertices[VertexIndex] = MeshVertices[VertexIndex].Pos;
    }

    for(UINT IndexIndex = 0; IndexIndex < _TriangleCount * 3; IndexIndex++)
    {
        _Indices[IndexIndex] = MeshIndices[IndexIndex];
    }

    Vector<UINT> TriangleIndices(_TriangleCount);
    for(UINT TriangleIndex = 0; TriangleIndex < _TriangleCount; TriangleIndex++)
    {
        TriangleIndices[TriangleIndex] = TriangleIndex;
    }
    
    Vector<UINT> LeafTrianglesVector;
    _Root = new RayIntersectorKDTreeNode(TriangleIndices, *this, 0, LeafTrianglesVector);
    _LeafTriangleCount = LeafTrianglesVector.Length();
    _LeafTriangles = new UINT[_LeafTriangleCount];
    memcpy(_LeafTriangles, LeafTrianglesVector.CArray(), sizeof(UINT) * _LeafTriangleCount);
    Console::WriteLine(String(_LeafTriangleCount) + String(" leaf triangles."));
}
示例#8
0
void InputDataStream::WrapMemory(const Vector<BYTE> &stream)
{
    _data = stream.CArray();
    _dataLength = stream.Length();
    _readPtr = 0;
}
示例#9
0
void Compression::CompressStreamToFile(const Vector<BYTE> &stream, const String &filename)
{
    CompressStreamToFile(stream.CArray(), stream.Length(), filename);
}
示例#10
0
void Compression::DecompressStreamFromMemory(const Vector<BYTE> &compressedStream, Vector<BYTE> &decompressedStream)
{
    DecompressStreamFromMemory(compressedStream.CArray(), compressedStream.Length(), decompressedStream.CArray(), decompressedStream.Length());
}
示例#11
0
文件: Pipe.cpp 项目: dmead/sc2bot
void Pipe::SendMessage(const Vector<BYTE> &Message)
{
    SendMessage(Message.CArray(), Message.Length());
}
示例#12
0
    void GetUnicodeFileLines(const String &Filename, Vector<UnicodeString> &Output, UINT LineLimit)
    {
        Vector<BYTE> Data;
        Utility::GetFileData(Filename, Data);

        const UINT Length = Data.Length() / 2;
        const unsigned short *CArray = (unsigned short *)Data.CArray();
        
        UINT StringCount = 0;
        if(LineLimit == 0)
        {
            for(UINT Index = 0; Index < Length; Index++)
            {
                unsigned short CurCharacter = CArray[Index];
                if(CurCharacter == 0x000D || CurCharacter == 0x000A)
                {
                    if(Index < Length - 1 && (CArray[Index + 1] == 0x000D || CArray[Index + 1] == 0x000A))
                    {
                        Index++;
                    }
                    StringCount++;
                }
            }
            Output.Allocate(StringCount);
        }
        else
        {
            Output.Allocate(LineLimit);
        }
        
        UINT StringIndex = 0;
        UnicodeString *CurString = &(Output[0]);

        bool Done = false;
        for(UINT Index = 0; Index < Length && !Done; Index++)
        {
            unsigned short CurCharacter = CArray[Index];
            if(CurCharacter == 0x000D || CurCharacter == 0x000A)
            {
                if(Index < Length - 1 && (CArray[Index + 1] == 0x000D || CArray[Index + 1] == 0x000A))
                {
                    Index++;
                }
                if(StringIndex == LineLimit - 1)
                {
                    Done = true;
                }
                else
                {
                    StringIndex++;
                    if(StringIndex != Output.Length())
                    {
                        CurString = &(Output[StringIndex]);
                    }
                }
            }
            else if(CurCharacter != 0xFEFF)
            {
                //Console::WriteString(String::UnsignedIntAsHex(CurCharacter) + String(" "));
                CurString->PushEnd(CurCharacter);
            }
        }
        if(LineLimit != 0)
        {
            Output.ReSize(StringIndex + 1);
        }
    }
示例#13
0
文件: PCA.cpp 项目: dmead/sc2bot
void PCA<T>::InverseTransform(Vector<T> &Result, const Vector<T> &Input)
{
	const UINT Dimension = _Means.Length();
	Result.Allocate(Dimension);
	InverseTransform(Result.CArray(), Input.CArray(), Input.Length());
}
示例#14
0
void D3D9Mesh::GenerateAdj(Vector<DWORD> &Adjacency)
{
    Adjacency.Allocate(IndexCount());
    D3DAlwaysValidate(_Mesh->GenerateAdjacency(0.0f, Adjacency.CArray()), "GenerateAdjacency");
}