不起作用:
var b:ByteArray = new ByteArray();
b.writeFloat(-50.000000);
b.position = 0;
cpp.processFloat(b,b.bytesAvailable);
CPP:
static AS3_Val processFloat(void* self, AS3_Val args){
unsigned iTestSize;
AS3_Val sOrigFile = AS3_Undefined();
AS3_ArrayValue( args, "AS3ValType, IntType", &sOrigFile, &iTestSize );
float * sFile = (float *)malloc(sizeof(float) * (iTestSize + 1));
int res = AS3_ByteArray_readBytes(sFile, sOrigFile, iTestSize);
fprintf( stderr, "** processFloat() size: %i sFile: %.03f, res:%i\n", iTestSize, sFile, res );
fprintf ouput: ** processFloat size:4 sFile:0.000,res:4
怎么了?如何从闪存中将浮点数组传递给swc?
答案 0 :(得分:0)
您的问题是字节顺序(更多详情here)。您需要将ByteArray设置为Little Endian:
var b:ByteArray = new ByteArray();
b.endian= Endian.LITTLE_ENDIAN;
b.writeFloat(-50.000000);
b.position = 0;
cpp.processFloat(b,b.bytesAvailable);
此外,您的iTestSize
感到困惑。您传入bytesAvailable
但是然后将其乘以sizeof(float)
(并添加1 ??)。