关于coco2d-x 3.8版的PhysicsEditor.exe1.09版的GB2ShapeCache-x.h.cpp中有些方法更新了和容器的使用方法,还有就是头文件include "CCNS.h"  以前在cocoa包中现在在base包中。

//GB2ShapeCache-x.h.cpp

#include "GB2ShapeCache-x.h"  
#include "Box2D/Box2D.h"  
#include "base/CCNS.h"

using namespace cocos2d;

/**
* Internal class to hold the fixtures
*/
class FixtureDef {
public:
    FixtureDef()
        : next(NULL) {}

~FixtureDef() {
        delete next;
        delete fixture.shape;
    }

FixtureDef *next;
    b2FixtureDef fixture;
    int callbackData;
};

class BodyDef {
public:
    BodyDef()
        : fixtures(NULL) {}

~BodyDef() {
        if (fixtures)
            delete fixtures;
    }

FixtureDef *fixtures;
    CCPoint anchorPoint;
};

static GB2ShapeCache *_sharedGB2ShapeCache = NULL;

GB2ShapeCache* GB2ShapeCache::sharedGB2ShapeCache(void) {
    if (!_sharedGB2ShapeCache) {
        _sharedGB2ShapeCache = new GB2ShapeCache();
        _sharedGB2ShapeCache->init();
    }

return _sharedGB2ShapeCache;
}

bool GB2ShapeCache::init() {
    return true;
}

void GB2ShapeCache::reset() {
    std::map<std::string, BodyDef *>::iterator iter;
    for (iter = shapeObjects.begin(); iter != shapeObjects.end(); ++iter) {
        delete iter->second;
    }
    shapeObjects.clear();
}

void GB2ShapeCache::addFixturesToBody(b2Body *body, const std::string &shape) {
    std::map<std::string, BodyDef *>::iterator pos = shapeObjects.find(shape);
    assert(pos != shapeObjects.end());

BodyDef *so = (*pos).second;

FixtureDef *fix = so->fixtures;
    while (fix) {
        body->CreateFixture(&fix->fixture);
        fix = fix->next;
    }
}

cocos2d::CCPoint GB2ShapeCache::anchorPointForShape(const std::string &shape) {
    std::map<std::string, BodyDef *>::iterator pos = shapeObjects.find(shape);
    assert(pos != shapeObjects.end());

BodyDef *bd = (*pos).second;
    return bd->anchorPoint;
}

void GB2ShapeCache::addShapesWithFile(const std::string &plist) {

CCDictionary *dict = CCDictionary::createWithContentsOfFileThreadSafe(plist.c_str());
    CCAssert(dict != NULL, "Shape-file not found"); // not triggered - cocos2dx delivers empty dict if non was found  
    CCAssert(dict->count() != 0, "plist file empty or not existing");

CCDictionary *metadataDict = (CCDictionary *)dict->objectForKey("metadata");
    int format = static_cast<CCString *>(metadataDict->objectForKey("format"))->intValue();
    ptmRatio = static_cast<CCString *>(metadataDict->objectForKey("ptm_ratio"))->floatValue();
    CCAssert(format == 1, "Format not supported");

CCDictionary *bodyDict = (CCDictionary *)dict->objectForKey("bodies");

b2Vec2 vertices[b2_maxPolygonVertices];

DictElement* pElement = NULL;
    CCDICT_FOREACH(bodyDict, pElement)
    {
        BodyDef *bodyDef = new BodyDef();

CCString *bodyName = ccs(pElement->getStrKey());

CCDictionary *bodyData = (CCDictionary *)pElement->getObject();
        bodyDef->anchorPoint = PointFromString(static_cast<CCString *>(bodyData->objectForKey("anchorpoint"))->getCString());

CCArray *fixtureList = (CCArray *)bodyData->objectForKey("fixtures");
        FixtureDef **nextFixtureDef = &(bodyDef->fixtures);

CCObject *fixture = NULL;
        CCARRAY_FOREACH(fixtureList, fixture)
        {

b2FixtureDef basicData;
            CCDictionary *fixtureData = (CCDictionary *)fixture;
            int callbackData = 0;

basicData.filter.categoryBits = static_cast<CCString *>(fixtureData->objectForKey("filter_categoryBits"))->intValue();
            basicData.filter.maskBits = static_cast<CCString *>(fixtureData->objectForKey("filter_maskBits"))->intValue();
            basicData.filter.groupIndex = static_cast<CCString *>(fixtureData->objectForKey("filter_groupIndex"))->intValue();
            basicData.friction = static_cast<CCString *>(fixtureData->objectForKey("friction"))->floatValue();
            basicData.density = static_cast<CCString *>(fixtureData->objectForKey("density"))->floatValue();
            basicData.restitution = static_cast<CCString *>(fixtureData->objectForKey("restitution"))->floatValue();
            basicData.isSensor = (bool)static_cast<CCString *>(fixtureData->objectForKey("isSensor"))->intValue();
            if (fixtureData->objectForKey("id")){
                basicData.userData = static_cast<CCString *>(fixtureData->objectForKey("id"));
                callbackData = static_cast<CCString *>(fixtureData->objectForKey("id"))->intValue();
            }

std::string fixtureType = static_cast<CCString *>(fixtureData->objectForKey("fixture_type"))->getCString();
            //CCString *fixtureType = static_cast<CCString *>(fixtureData->objectForKey("fixture_type"))->getCString();

if (fixtureType == "POLYGON") {
                //CCDictionary *polygons = (CCDictionary *)fixtureData->objectForKey("polygons");  
                CCArray *polygons = (CCArray *)fixtureData->objectForKey("polygons");
                //CCDictElement *polygon = NULL;  
                CCObject *polygon = NULL;
                //CCDICT_FOREACH(polygons, polygon)  
                CCARRAY_FOREACH(polygons, polygon)
                {
                    FixtureDef *fix = new FixtureDef();
                    fix->fixture = basicData; // copy basic data  
                    fix->callbackData = callbackData;

b2PolygonShape *polyshape = new b2PolygonShape();
                    int vindex = 0;

//CCDictionary *polygonData = (CCDictionary *)polygon->getObject();  
                    CCArray *polygonData = (CCArray *)polygon;

assert(polygonData->count() <= b2_maxPolygonVertices);

//CCDictElement *offset = NULL;  
                    CCObject *offset = NULL;
                    //CCDICT_FOREACH(polygonData, offset)  
                    CCARRAY_FOREACH(polygonData, offset)
                    {

CCString *pStr = (CCString *)offset;
                        CCPoint p = PointFromString(pStr->getCString());

vertices[vindex].x = (p.x / ptmRatio);
                        vertices[vindex].y = (p.y / ptmRatio);
                        vindex++;

}

polyshape->Set(vertices, vindex);
                    fix->fixture.shape = polyshape;

*nextFixtureDef = fix;
                    nextFixtureDef = &(fix->next);
                }

}
            else if (fixtureType == "CIRCLE") {
                FixtureDef *fix = new FixtureDef();
                fix->fixture = basicData; // copy basic data  
                fix->callbackData = callbackData;

CCDictionary *circleData = (CCDictionary *)fixtureData->objectForKey("circle");

b2CircleShape *circleShape = new b2CircleShape();

circleShape->m_radius = static_cast<CCString *>(circleData->objectForKey("radius"))->floatValue() / ptmRatio;
                CCPoint p = PointFromString(static_cast<CCString *>(circleData->objectForKey("position"))->getCString());
                circleShape->m_p = b2Vec2(p.x / ptmRatio, p.y / ptmRatio);
                fix->fixture.shape = circleShape;

// create a list  
                *nextFixtureDef = fix;
                nextFixtureDef = &(fix->next);

}
            else {
                CCAssert(0, "Unknown fixtureType");
            }

// add the body element to the hash  
            shapeObjects[bodyName->getCString()] = bodyDef;
        }
    }
}

//GB2ShapeCache-x.h

#ifndef __CCSHAPECACHE_H__  
#define __CCSHAPECACHE_H__  
#include "cocos2d.h"  
USING_NS_CC;
class BodyDef;
class b2Body;
namespace cocos2d {
    class GB2ShapeCache : public CCObject{
    public:
        static GB2ShapeCache* sharedGB2ShapeCache(void);
    public:
        bool init();
        void addShapesWithFile(const std::string &plist);
        void addFixturesToBody(b2Body *body, const std::string &shape);
        cocos2d::CCPoint anchorPointForShape(const std::string &shape);
        void reset();
        float getPtmRatio() { return ptmRatio; }
        ~GB2ShapeCache() {}
    private:
        std::map<std::string, BodyDef *> shapeObjects;
        GB2ShapeCache(void) {}
        float ptmRatio;
    };
}
#endif /* defined(__CCSHAPECACHE_H__) */

cocos2dx 3.8版关于#include "GB2ShapeCache-x.h"的更多相关文章

  1. cocos2d-x 新建项目 Cannot open include file: ‘cocos2d.h’

    新建cocos2d-x 项目分这么几步. 1. 下载最新的cocos2d-x 2. 安装 vs2010 3. 解压cocos2d-x 压缩包,并双击"install-templates-ms ...

  2. Cocos2d-x 3.x版2048游戏开发

    Cocos2d-x 3.x版2048游戏开发 本篇博客给大家介绍怎样高速开发2048这样一款休闲游戏,理解整个2048游戏的开发流程.从本篇博客你将能够学习到下面内容: 这里注明一下,本教程来自极客学 ...

  3. (转)win7 64 安装mysql-python:_mysql.c(42) : fatal error C1083: Cannot open include file: 'config-win.h': No such file or directory

    原文地址:http://www.cnblogs.com/fnng/p/4115607.html 作者:虫师 今天想在在win7 64位环境下使用python 操作mysql 在安装MySQL-pyth ...

  4. win7 64 安装mysql-python:_mysql.c(42) : fatal error C1083: Cannot open include file: 'config-win.h': No such file or directory

    今天想在在win7 64位环境下使用python 操作mysql 在安装MySQL-python 时报错: _mysql.c _mysql.c(42) : fatal error C1083: Can ...

  5. include/asm/dma.h

    /* $Id: dma.h,v 1.7 1992/12/14 00:29:34 root Exp root $ * linux/include/asm/dma.h: Defines for using ...

  6. Winpcap安装,Cannot open include file 'pcap.h'

    VC报错 fatal error C1083: Cannot open include file: 'pcap.h': No such file or directory Winpcap是window ...

  7. /usr/include/sys/types.h:62: error: conflicting types for ‘dev_t’

    /usr/include/sys/types.h:62: error: conflicting types for ‘dev_t’/usr/include/linux/types.h:13: erro ...

  8. _mysql.c(42) : fatal error C1083: Cannot open include file: 'config-win.h':问题的解决 mysql安装python

    在win7下安装了Python后,想安装python-MySQL,使用pip安装出现如下问题: >pip install MySQL-python _mysql.c(42) : fatal er ...

  9. 用ioctl获取无线网络信息 /usr//include/linux/wireless.h

    1.UNIX Network Programming环境搭建 Unix NetWork Programming――环境搭建(解决unp.h等源码编译问题) http://blog.csdn.net/a ...

随机推荐

  1. dotfiles管理

    刚刚知道dotfiles这个东西,百度也没发现什么太有价值的讲解,还都是英文,所以自己立志来好好屡屡清楚 1.dotfiles是什么?我自己的理解:linux下(mac下)有各种app,每个人会根据自 ...

  2. EF获取一个或者多个字段

    有时候直接查询出一个实体,比较浪费性能,对于字段比较少的表来说差异不大,但是如果一个表有几十个字段,你只要取出一个字段或者几个字段,而取出整个实体,性能就会有差异了. /// <summary& ...

  3. 解决Jenkins console输出乱码

    背景 Jenkins console输出乱码,如 ������������� 1 解决办法 Jenkins Master 设置utf8 encoding Tomcat 启动脚本 export JAVA ...

  4. Linux IO实时监控iostat命令详解

    简介 iostat主要用于监控系统设备的IO负载情况,iostat首次运行时显示自系统启动开始的各项统计信息,之后运行iostat将显示自上次运行该命令以后的统计信息.用户可以通过指定统计的次数和时间 ...

  5. JAVA利用JXL导出/生成 EXCEL

    /** * 导出导出采暖市场部收入.成本.利润明细表 * @author JIA-G-Y */ public String exporExcel(String str) { String str=Se ...

  6. php注意事项

    1. 不要使用mysql_函数 这一天终于来了,从此你不仅仅"不应该"使用mysql_函数.PHP 7 已经把它们从核心中全部移除了,也就是说你需要迁移到好得多的mysqli_函数 ...

  7. css学习笔记 1

    对于一个页面,如何控制页面的结构就看如何去理解css的各个属性了,只有了解了css的各个属性后才能更有效的让css控制页面的任何一个结构. css的结构:选择符:{属性名1:属性值; 属性名2:属性值 ...

  8. 20150514Linux下rpm包安装错误及解决方案

    (1)用rpm -ivh ***.rpm解压RedHat自带boost出现错误如下: warning: /media/RHEL_6.3 i386 Disc 1/Packages/boost-1.41. ...

  9. IE11里边form拦截失效,永远被弹回登录页

    现象描述: 1.在某些服务器上发布了程序以后,用IE11去浏览程序(试了多台电脑都一样),发现总是登录不进去,因为登录之后总是被立即反弹回登录页面,就像是登录后写入的票据瞬间丢失一样. 2.但是同一套 ...

  10. Rest接口测试,巧用firebug插件

    两年前开始做软件测试,刚接触的是关于rest接口的测试.作为一个刚进职场的测试小菜鸟,当时对接口的理解并不是很充分,具体是怎么实现的也不清楚.在进行接口测试时,只是设置接口入参,调用接口,查看接口是否 ...