lscript_byteconvert.h
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:28k
源码类别:
游戏引擎
开发平台:
C++ Builder
- /**
- * @file lscript_byteconvert.h
- * @brief Shared code for compiler and assembler for LSL
- *
- * $LicenseInfo:firstyear=2002&license=viewergpl$
- *
- * Copyright (c) 2002-2010, Linden Research, Inc.
- *
- * Second Life Viewer Source Code
- * The source code in this file ("Source Code") is provided by Linden Lab
- * to you under the terms of the GNU General Public License, version 2.0
- * ("GPL"), unless you have obtained a separate licensing agreement
- * ("Other License"), formally executed by you and Linden Lab. Terms of
- * the GPL can be found in doc/GPL-license.txt in this distribution, or
- * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
- *
- * There are special exceptions to the terms and conditions of the GPL as
- * it is applied to this Source Code. View the full text of the exception
- * in the file doc/FLOSS-exception.txt in this software distribution, or
- * online at
- * http://secondlifegrid.net/programs/open_source/licensing/flossexception
- *
- * By copying, modifying or distributing this software, you acknowledge
- * that you have read and understood your obligations described above,
- * and agree to abide by those obligations.
- *
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
- * $/LicenseInfo$
- */
- // data shared between compiler/assembler
- // used to convert data between byte stream and outside data types
- #ifndef LL_LSCRIPT_BYTECONVERT_H
- #define LL_LSCRIPT_BYTECONVERT_H
- #include "stdtypes.h"
- #include "v3math.h"
- #include "llquaternion.h"
- #include "lscript_byteformat.h"
- #include "lluuid.h"
- void reset_hp_to_safe_spot(const U8 *buffer);
- // remember that LScript byte stream is BigEndian
- void set_fault(const U8 *stream, LSCRIPTRunTimeFaults fault);
- inline S32 bytestream2integer(const U8 *stream, S32 &offset)
- {
- stream += offset;
- offset += 4;
- return (*stream<<24) | (*(stream + 1)<<16) | (*(stream + 2)<<8) | *(stream + 3);
- }
- inline U32 bytestream2unsigned_integer(const U8 *stream, S32 &offset)
- {
- stream += offset;
- offset += 4;
- return (*stream<<24) | (*(stream + 1)<<16) | (*(stream + 2)<<8) | *(stream + 3);
- }
- inline U64 bytestream2u64(const U8 *stream, S32 &offset)
- {
- stream += offset;
- offset += 8;
- return ((U64)(*stream)<<56)| ((U64)(*(stream + 1))<<48) | ((U64)(*(stream + 2))<<40) | ((U64)(*(stream + 3))<<32) |
- ((U64)(*(stream + 4))<<24) | ((U64)(*(stream + 5))<<16) | ((U64)(*(stream + 6))<<8) | (U64)(*(stream + 7));
- }
- inline void integer2bytestream(U8 *stream, S32 &offset, S32 integer)
- {
- stream += offset;
- offset += 4;
- *(stream) = (integer >> 24);
- *(stream + 1) = (integer >> 16) & 0xff;
- *(stream + 2) = (integer >> 8) & 0xff;
- *(stream + 3) = (integer) & 0xff;
- }
- inline void unsigned_integer2bytestream(U8 *stream, S32 &offset, U32 integer)
- {
- stream += offset;
- offset += 4;
- *(stream) = (integer >> 24);
- *(stream + 1) = (integer >> 16) & 0xff;
- *(stream + 2) = (integer >> 8) & 0xff;
- *(stream + 3) = (integer) & 0xff;
- }
- inline void u642bytestream(U8 *stream, S32 &offset, U64 integer)
- {
- stream += offset;
- offset += 8;
- *(stream) = (U8)(integer >> 56);
- *(stream + 1) = (U8)((integer >> 48) & 0xff);
- *(stream + 2) = (U8)((integer >> 40) & 0xff);
- *(stream + 3) = (U8)((integer >> 32) & 0xff);
- *(stream + 4) = (U8)((integer >> 24) & 0xff);
- *(stream + 5) = (U8)((integer >> 16) & 0xff);
- *(stream + 6) = (U8)((integer >> 8) & 0xff);
- *(stream + 7) = (U8)((integer) & 0xff);
- }
- inline S16 bytestream2s16(const U8 *stream, S32 &offset)
- {
- stream += offset;
- offset += 2;
- return (*stream<<8) | *(stream + 1);
- }
- inline void s162bytestream(U8 *stream, S32 &offset, S16 integer)
- {
- stream += offset;
- offset += 2;
- *(stream) = (integer >> 8);
- *(stream + 1) = (integer) & 0xff;
- }
- inline U16 bytestream2u16(const U8 *stream, S32 &offset)
- {
- stream += offset;
- offset += 2;
- return (*stream<<8) | *(stream + 1);
- }
- inline void u162bytestream(U8 *stream, S32 &offset, U16 integer)
- {
- stream += offset;
- offset += 2;
- *(stream) = (integer >> 8);
- *(stream + 1) = (integer) & 0xff;
- }
- inline F32 bytestream2float(const U8 *stream, S32 &offset)
- {
- S32 value = bytestream2integer(stream, offset);
- F32 fpvalue = *(F32 *)&value;
- if (!llfinite(fpvalue))
- {
- fpvalue = 0;
- set_fault(stream, LSRF_MATH);
- }
- return fpvalue;
- }
- inline void float2bytestream(U8 *stream, S32 &offset, F32 floatingpoint)
- {
- S32 value = *(S32 *)&floatingpoint;
- integer2bytestream(stream, offset, value);
- }
- inline void bytestream_int2float(U8 *stream, S32 &offset)
- {
- S32 value = bytestream2integer(stream, offset);
- offset -= 4;
- F32 fpvalue = (F32)value;
- if (!llfinite(fpvalue))
- {
- fpvalue = 0;
- set_fault(stream, LSRF_MATH);
- }
- float2bytestream(stream, offset, fpvalue);
- }
- // Returns true on success, return false and clip copy on buffer overflow
- inline bool bytestream2char(char *buffer, const U8 *stream, S32 &offset, S32 buffsize)
- {
- S32 source_len = strlen( (const char *)stream+offset );
- S32 copy_len = buffsize - 1;
- if( copy_len > source_len )
- {
- copy_len = source_len;
- }
- // strncpy without