• FlashCC学习笔记


    前段时间项目中有一个功能模块用到了FlashCC,将C++的代码编译成swc文件,以便在Flash工程中使用。开发过程中遇到一些问题,现在记录下来,以便日后查阅。

    一、开发环境搭建

    说明:本文所使用的FlashCC版本为1.0.1, 操作系统为Windows7 Professional 32位

    相对于FlashCC的前身Alchemy来说,FlashCC的开发环境搭建已经简化了许多,一些开发过程中依赖的组件已经默认集成到官方提供的定制Cygwin当中。首先需要注意最小系统需求,下面是官方给出的标准:

    • Flash Player 11 or higher
    • Flex SDK 4.6 or higher
    • Java Virtual Machine (64-bit)
    • Window平台需要:Microsoft® Windows® 7 (64-bit edition)

    其中前两点必须要满足。至于后两点,我的开发机器用的是Win7 32位系统,装的Java虚拟机也是32位的,实际操作中也没有发现太大问题(不过建议有条件的话最好还是使用官方标准)。

    了解基本需求后到各个网站上下载Flex SDKJREFlashCC开发包(1.0.1版本),下载完成后继续下面的步骤:

    1、解压FlexSDK(本文中解压路径为F:Flexflex_sdk_4.6)

    2、安装JRE

    3、解压FlashCC开发包(已经内置了定制版的cygwin) (本文中解压路径为F:FlashFlasCC_1.0.1)

    4、使用文本编辑器打开F:FlashFlasCC_1.0.1samplesMakefile.common, 修改FLASCC及FLEX变量为下面的值:

    FLASCC:=/cygdrive/f/Flash/FlasCC_1.0.1/sdk
    FLEX:=/cygdrive/c/flex

    至此,FlashCC的开发环境就搭建好了,下面来尝试编译FlashCC开发包中自带的示例程序。

    二、编译样例程序

    直接运行F:FlashFlasCC_1.0.1 un.bat,切换工作目录到01_HelloWorld下:

    注意:如果使用的是32位Java虚拟机,则需要修改一下01_HelloWorld下的Makefile, 在编译命令后加上-jvmopt=-Xmx1G

    否则会报下面的错误:

    “LLVM ERROR: Error: Unable to launch the Java Virtual Machine.
    This usually means you have a 32bit JVM installed or have set your Java heap siz
    e too large.
    Try lowering the Java heap size by passing "-jvmopt=-Xmx1G" to gcc/g++.”

    在cygwin窗口中输入make:

    一切顺利的话,会在01_HelloWorld目录下多出hello.exe和hello.swf两个文件,使用FlashPlayer打开hello.swf,效果如下:

    三、开发中遇到的问题

    1、FlashCC使用cygwin编译代码,而cygwin是一个linux环境的模拟器,所以要求被编译的代码要使用标准C/C++。或者是做一些跨平台处理。

    2、一开始在项目中编译C++代码成swc文件之后,使用Flash Professional CS5.5建立以一个测试项目,实际运行的时候发现有个地方总是分配不到内存,后来在FlashCC官方论坛上提问,才发现是由于编译时指定的flash版本过低所致(FlashCC要求编译时flash版本最低为11), 论坛上的提问

    3、以前安装的Flash Professional CS5.5发布swf时flash版本最高只能指定到10.2,可以参考下面的文章来添加更高版本的flash支持

    Adding Flash Player 11 support to Flash Pro CS5 and CS5.5

    4、关于从AS3代码中向C++中传递ByteArray参数的方法,一开始参考了这篇文章,实际测试中发现这种方法在我编写的功能模块中并不能正确工作。后来采用官方Demo中的数据传递方法成功解决了ByteArray传参问题。贴出参考代码:

    AS3
     1 // First lets fill a ByteArray like we normally would in ActionScript 
     2 var bytes:ByteArray = new ByteArray(); 
     3 bytes.endian = "littleEndian"; 
     4 for (var j:int = 0; j < 10; j++) 
     5    bytes.writeInt(j);
     6 
     7 bytes.position = 0;
     8 
     9 // Now we want a pointer to that ByteArray 
    10 var bytesPtr:int = CModule.malloc(bytes.length);
    11 
    12 // Use CModule.writeBytes() to write the ByteArray we created into flascc's 
    13 // main memory.  The parameters of writeBytes() are first the pointer in flascc 
    14 // memory, the length of the ByteArray, and the ByteArray itself 
    15 CModule.writeBytes(bytesPtr, bytes.length, bytes); 
    16 printLine("Checksum: " + MyLib.examineBytes(bytesPtr, bytes.length)); 
    17 CModule.free(bytesPtr);
    C
     1 __attribute__((annotate("as3sig:public function _wrap_examineBytes(buffer:int, bufferSize:int):int"))) 
     2 void _wrap_examineBytes() { 
     3   unsigned char *arg1 = (unsigned char *) 0 ; 
     4   int arg2 ; 
     5   int result ; 
     6   { 
     7     AS3_GetScalarFromVar(arg1, buffer); 
     8   } 
     9   { 
    10     AS3_GetScalarFromVar(arg2, bufferSize); 
    11   } 
    12   result = (int)examineBytes((unsigned char const *)arg1,arg2); 
    13   { 
    14     AS3_DeclareVar(asresult, int); 
    15     AS3_CopyScalarToVar(asresult, result); 
    16   } 
    17   { 
    18     AS3_ReturnAS3Var(asresult); 
    19   } 
    20 }

    PS:附上FlashCC 官方论坛地址

    http://forums.adobe.com/community/game_developers/flascc

  • 相关阅读:
    pip几个国内速度非常快的源
    【模型推理】ncnn 模型转换及量化流程
    Could not load library cudnn_cnn_infer64_8.dll. Error code 126 Please make sure cudnn_cnn_infer64_8.
    基于ncnn的iOS端深度学习算法部署及应用
    AlexNet网络结构与pytorch代码实现
    tensorflow 转coreml
    模型转换工具
    Mac Ideal 操作快捷键
    pom 添加远程镜像源
    java wrapper
  • 原文地址:https://www.cnblogs.com/eaststar/p/3140169.html
Copyright © 2020-2023  润新知