守望者--AIR技术交流

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
热搜: ANE FlasCC 炼金术
查看: 3287|回复: 0
打印 上一主题 下一主题

[技术知识] Adobe FlasCC中 C++端与Flash端的函数参数(如数组和ByteArray)...

[复制链接]
  • TA的每日心情
    擦汗
    2018-4-10 15:18
  • 签到天数: 447 天

    [LV.9]以坛为家II

    1742

    主题

    2094

    帖子

    13万

    积分

    超级版主

    Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18

    威望
    562
    贡献
    29
    金币
    52694
    钢镚
    1422

    开源英雄守望者

    跳转到指定楼层
    楼主
    发表于 2015-4-7 09:47:21 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
    本帖最后由 破晓 于 2015-8-26 09:15 编辑

    节选自:Using C++ code forpath finding in your ActionScript game


    如下为C++端接口,as3api.cpp:

    1. <font color="#000"><font face="Arial">/*
    2. ** ADOBE SYSTEMS INCORPORATED
    3. ** Copyright 2012 Adobe Systems Incorporated
    4. ** All Rights Reserved.
    5. **
    6. ** NOTICE:  Adobe permits you to use, modify, and distribute this file in accordance with the
    7. ** terms of the Adobe license agreement accompanying it.  If you have received this file from a
    8. ** source other than Adobe, then your use, modification, or distribution of it requires the prior
    9. ** written permission of Adobe.
    10. */
    11. #include "pathfinder.h"
    12. #include "AS3/AS3.h"

    13. // First we mark the function declaration with a GCC attribute specifying the
    14. // AS3 signature

    15. ////** flascc_createPather **////
    16. void flascc_createPather() __attribute__((used,
    17.         annotate("as3sig:public function flascc_createPather():int"),
    18.         annotate("as3package:com.renaun.flascc_interface")));

    19. void flascc_createPather()
    20. {
    21.     // Create an instance of the Class
    22.     Pather *result;
    23.     result = (Pather *)new Pather();
    24.    
    25.     // Create int for the pointer into memory for this object instance
    26.     AS3_DeclareVar(asresult, int);
    27.     AS3_CopyScalarToVar(asresult, result);
    28.    
    29.     // return the pointer value of this object in memory
    30.     AS3_ReturnAS3Var(asresult);
    31. }

    32. ////** flascc_deletePather **////
    33. void flascc_deletePather() __attribute__((used,
    34.       annotate("as3sig:public function flascc_deletePather(self):void"),
    35.       annotate("as3package:com.renaun.flascc_interface")));

    36. void flascc_deletePather()
    37. {
    38.     Pather *arg1 = (Pather *) 0 ;
    39.     AS3_GetScalarFromVar(arg1, self);
    40.     delete arg1;
    41.     AS3_ReturnAS3Var(undefined);
    42. }


    43. ////** flascc_setMap **////
    44. void flascc_setMap() __attribute__((used,
    45.      annotate("as3sig:public function flascc_setMap(self, buffer:int, colSize:int, rowSize:int):void"),
    46.      annotate("as3package:com.renaun.flascc_interface")));

    47. void flascc_setMap()
    48. {
    49.     Pather *arg1 = (Pather *) 0 ;
    50.     unsigned char *arg2 = (unsigned char *) 0 ;
    51.     int arg3;
    52.     int arg4;
    53.     // convert arguments
    54.     AS3_GetScalarFromVar(arg1, self);
    55.     AS3_GetScalarFromVar(arg2, buffer);
    56.     AS3_GetScalarFromVar(arg3, colSize);
    57.     AS3_GetScalarFromVar(arg4, rowSize);
    58.     // apply to object
    59.     (arg1)->setMap((unsigned char *)arg2, arg3, arg4);
    60.     // return void
    61.     AS3_ReturnAS3Var(undefined);
    62. }



    63. ////** flascc_getPath **////
    64. void flascc_getPath() __attribute__((used,
    65.       annotate("as3sig:public function flascc_getPath(self, sx:int, sy:int, nx:int, ny:int):int"),
    66.       annotate("as3package:com.renaun.flascc_interface")));

    67. void flascc_getPath()
    68. {
    69.     Pather *arg1 = (Pather *) 0 ;
    70.     int arg2;
    71.     int arg3;
    72.     int arg4;
    73.     int arg5;
    74.     int* result;
    75.     // convert arguments
    76.     AS3_GetScalarFromVar(arg1, self);
    77.     AS3_GetScalarFromVar(arg2, sx);
    78.     AS3_GetScalarFromVar(arg3, sy);
    79.     AS3_GetScalarFromVar(arg4, nx);
    80.     AS3_GetScalarFromVar(arg5, ny);
    81.     // apply to object
    82.     result = (arg1)->getPath(arg2, arg3, arg4, arg5);
    83.     // return Number
    84.     AS3_DeclareVar(asresult, int);
    85.     AS3_CopyScalarToVar(asresult, result);
    86.     AS3_ReturnAS3Var(asresult);
    87. }
    88. </font></font>
    复制代码


    如下为AS3接口,详细给出了C++与Flash传递ByteArray及Array的步骤:


    1. <font color="#000"><font face="Arial">package com.renaun
    2. {
    3. import com.renaun.flascc_interface.*;

    4. import com.renaun.flascc.CModule;
    5. import com.renaun.flascc.ram;

    6. import flash.utils.ByteArray;

    7. public class PathFinder
    8. {
    9.         public function PathFinder(map:ByteArray, colSize:int, rowSize:int):void
    10.         {
    11.                 objectPtr = flascc_createPather();
    12.                 mapColSize = colSize;
    13.                 mapRowSize = rowSize;
    14.                 if (map.length != colSize * rowSize)
    15.                         throw new Error("Map size doesn't equal col * row size");
    16.                 // Setup bytes to be written to Flascc memory
    17.                 map.position = 0;
    18.                 mapByteArrayPtr = CModule.malloc(map.length);
    19.                 CModule.writeBytes(mapByteArrayPtr, map.length, map);
    20.                 flascc_setMap(objectPtr, mapByteArrayPtr, colSize, rowSize);
    21.         }
    22.         
    23.         public var mapColSize:int;
    24.         public var mapRowSize:int;
    25.         private var objectPtr:int;
    26.         public var mapByteArrayPtr:int;
    27.         
    28.         public function getMap():ByteArray
    29.         {
    30.                 var mapBytes:ByteArray = new ByteArray();
    31.                 ram.position = mapByteArrayPtr;
    32.                 ram.readBytes(mapBytes, 0, mapColSize * mapRowSize);
    33.                 return mapBytes;
    34.         }
    35.         
    36.         public function getPath(sx:int, sy:int, nx:int, ny:int):Array
    37.         {
    38.                 var pathPtr:int = flascc_getPath(objectPtr, sx, sy, nx, ny);
    39.                
    40.                 ram.position = pathPtr;
    41.                 var result:int = ram.readShort();
    42.                 var size:int = ram.readShort();
    43.                 var pathXYs:Array = [];
    44.                 if (size > 0)
    45.                 {
    46.                         ram.readShort();
    47.                         ram.readShort();
    48.                         for (var j:int = 1; j < size; j++)
    49.                         {
    50.                                 pathXYs.push(ram.readShort());
    51.                                 pathXYs.push(ram.readShort());
    52.                         }
    53.                 }
    54.                 //CModule.free(pathPtr);
    55.                 return pathXYs;
    56.         }
    57.         
    58.         public function destroy():void
    59.         {
    60.                 CModule.free(mapByteArrayPtr);
    61.                 flascc_deletePather(objectPtr);
    62.         }
    63.         
    64. }
    65. }</font></font>
    复制代码


    源码:








    本文来自:http://blog.csdn.net/xsolver/article/details/16839111


    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有帐号?立即注册

    x
    分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
    收藏收藏 分享分享 支持支持 反对反对 微信
    守望者AIR技术交流社区(www.airmyth.com)
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    
    关闭

    站长推荐上一条 /4 下一条

    QQ|手机版|Archiver|网站地图|小黑屋|守望者 ( 京ICP备14061876号

    GMT+8, 2024-4-20 06:47 , Processed in 0.118285 second(s), 37 queries .

    守望者AIR

    守望者AIR技术交流社区

    本站成立于 2014年12月31日

    快速回复 返回顶部 返回列表