/// <summary> /// /// </summary> /// <param name="iField"></param> /// <returns></returns> public float GetFloat(uint iField) { if (iField >= m_DBCFile.FieldCount) { Debug.WriteLine("DBCRecord.GetFloat(...) - iField >= m_DBCFile.FieldCount error!"); return(0); } CONVERT_FLOAT_INT_UINT returnConvert = new CONVERT_FLOAT_INT_UINT(); returnConvert.uiUint = GetUInt(iField); return(returnConvert.fFloat); }
/// <summary> /// Retrieves the cell data for the specified co-ordinates from the file and sets it in the CellInformation array. /// </summary> /// <param name="x">x co-ordinate of the cell information to load.</param> /// <param name="y">y co-ordinate of the cell information to load.</param> /// <returns>Returns true if the cell information exists and was loaded, false if not.</returns> bool LoadCellInformation(uint x, uint y) { // Make sure that we're not already loaded. if (m_CellInformation[x, y] != null) { return(true); } // Find our offset in our cached header. uint Offset = m_CellOffsets[x, y]; // If our offset = 0, it means we don't have cell information for // these coords. if (Offset == 0) { return(false); } // Lock the mutex to prevent double reading. //mutex.Acquire(); // Check that we haven't been loaded by another thread. if (m_CellInformation[x, y] != null) { //mutex.Release(); return(true); } // Seek to our specified offset. m_FileDescriptor.Seek(Offset, SeekOrigin.Begin); { // Allocate the cell information. m_CellInformation[x, y] = new TerrainInfo(); // Read from our file into this newly created struct. byte[] byteArray = new byte[(2 * 2 * 2) + (2 * 2 * 1) + (2 * 2 * 4) + (32 * 32 * 4)]; m_FileDescriptor.Read(byteArray, 0, byteArray.Length); int iIndexArray = 0; for (int iIndex = 0; iIndex < 2; iIndex++) { for (int iIndex2 = 0; iIndex2 < 2; iIndex2++) { m_CellInformation[x, y].AreaID[iIndex, iIndex2] = (ushort)(byteArray[iIndexArray] | byteArray[++iIndexArray] << 8); iIndexArray++; } } for (int iIndex = 0; iIndex < 2; iIndex++) { for (int iIndex2 = 0; iIndex2 < 2; iIndex2++) { m_CellInformation[x, y].LiquidType[iIndex, iIndex2] = byteArray[iIndexArray]; iIndexArray++; } } for (int iIndex = 0; iIndex < 2; iIndex++) { for (int iIndex2 = 0; iIndex2 < 2; iIndex2++) { CONVERT_FLOAT_INT_UINT convert = new CONVERT_FLOAT_INT_UINT(); convert.uiUint = (uint)(byteArray[iIndexArray] | byteArray[++iIndexArray] << 8 | byteArray[++iIndexArray] << 16 | byteArray[++iIndexArray] << 24); iIndexArray++; m_CellInformation[x, y].LiquidLevel[iIndex, iIndex2] = convert.fFloat; } } for (int iIndex = 0; iIndex < 32; iIndex++) { for (int iIndex2 = 0; iIndex2 < 32; iIndex2++) { CONVERT_FLOAT_INT_UINT convert = new CONVERT_FLOAT_INT_UINT(); convert.uiUint = (uint)(byteArray[iIndexArray] | byteArray[++iIndexArray] << 8 | byteArray[++iIndexArray] << 16 | byteArray[++iIndexArray] << 24); iIndexArray++; m_CellInformation[x, y].Z[iIndex, iIndex2] = convert.fFloat; } } } // Release the mutex. //mutex.Release(); // If we don't equal 0, it means the load was successful. if (m_CellInformation[x, y] != null) { return(true); } else { return(false); } }