Skip to content

Commit

Permalink
fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
Watson1978 committed Dec 3, 2016
1 parent 3ac696c commit df05c12
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 180 deletions.
52 changes: 26 additions & 26 deletions src/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ static VALUE
tint_by_new(VALUE rcv, SEL sel, VALUE delta_red, VALUE delta_green, VALUE delta_blue, VALUE interval)
{
auto action = cocos2d::TintBy::create(NUM2DBL(interval),
NUM2BYTE(delta_red), NUM2BYTE(delta_green), NUM2BYTE(delta_blue));
NUM2BYTE(delta_red), NUM2BYTE(delta_green), NUM2BYTE(delta_blue));
return rb_class_wrap_new((void *)action, rb_cAction);
}

Expand Down Expand Up @@ -315,7 +315,7 @@ sequence_new(VALUE rcv, SEL sel, VALUE actions)
cocos2d::Vector<cocos2d::FiniteTimeAction *> actionsVector;

for (int i = 0, count = RARRAY_LEN(actions); i < count; i++) {
actionsVector.pushBack(FINITE_TIME_ACTION(RARRAY_AT(actions, i)));
actionsVector.pushBack(FINITE_TIME_ACTION(RARRAY_AT(actions, i)));
}

auto action = cocos2d::Sequence::create(actionsVector);
Expand All @@ -334,7 +334,7 @@ spawn_new(VALUE rcv, SEL sel, VALUE actions)
cocos2d::Vector<cocos2d::FiniteTimeAction *> actionsVector;

for (int i = 0, count = RARRAY_LEN(actions); i < count; i++) {
actionsVector.pushBack(FINITE_TIME_ACTION(RARRAY_AT(actions, i)));
actionsVector.pushBack(FINITE_TIME_ACTION(RARRAY_AT(actions, i)));
}

auto action = cocos2d::Spawn::create(actionsVector);
Expand Down Expand Up @@ -434,40 +434,40 @@ animate_new(VALUE rcv, SEL sel, int argc, VALUE *argv)
cocos2d::Vector<cocos2d::SpriteFrame *> frames;
auto texture_cache = cocos2d::Director::getInstance()->getTextureCache();
for (int i = 0, count = RARRAY_LEN(frame_names); i < count; i++) {
VALUE name = RARRAY_AT(frame_names, i);
std::string frame_name = RSTRING_PTR(StringValue(name));
auto texture = texture_cache->addImage(frame_name);
cocos2d::SpriteFrame *frame = NULL;
if (texture != NULL) {
cocos2d::Rect rect = cocos2d::Rect::ZERO;
rect.size = texture->getContentSize();
frame = cocos2d::SpriteFrame::createWithTexture(texture,
rect);
}
else {
frame = cocos2d::SpriteFrameCache::getInstance()->getSpriteFrameByName(frame_name);
}
assert(frame != NULL);
frames.pushBack(frame);
VALUE name = RARRAY_AT(frame_names, i);
std::string frame_name = RSTRING_PTR(StringValue(name));
auto texture = texture_cache->addImage(frame_name);
cocos2d::SpriteFrame *frame = NULL;
if (texture != NULL) {
cocos2d::Rect rect = cocos2d::Rect::ZERO;
rect.size = texture->getContentSize();
frame = cocos2d::SpriteFrame::createWithTexture(texture,
rect);
}
else {
frame = cocos2d::SpriteFrameCache::getInstance()->getSpriteFrameByName(frame_name);
}
assert(frame != NULL);
frames.pushBack(frame);
}

int loops_i = 1;
bool forever = false;
if (loops != Qnil) {
if (rb_obj_is_kind_of(loops, rb_cInteger)) {
loops_i = NUM2LONG(loops);
}
else if (loops == rb_name2sym("forever")) {
forever = true;
}
if (rb_obj_is_kind_of(loops, rb_cInteger)) {
loops_i = NUM2LONG(loops);
}
else if (loops == rb_name2sym("forever")) {
forever = true;
}
}

auto animation = cocos2d::Animation::createWithSpriteFrames(frames,
NUM2DBL(delay), loops_i);
NUM2DBL(delay), loops_i);
cocos2d::ActionInterval *action = cocos2d::Animate::create(animation);

if (forever) {
action = cocos2d::RepeatForever::create(action);
action = cocos2d::RepeatForever::create(action);
}

return rb_class_wrap_new((void *)action, rb_cAction);
Expand Down
8 changes: 3 additions & 5 deletions src/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ application_screen_size_changed(VALUE rcv, SEL sel)
if (glview != NULL) {
cocos2d::Size size = glview->getFrameSize();
cocos2d::Application::getInstance()->applicationScreenSizeChanged(
size.width, size.height);
size.width, size.height);
}
return rcv;
}
Expand All @@ -102,15 +102,13 @@ Init_Application(void)
{
rb_cApplication = rb_define_class_under(rb_mMC, "Application", rb_cObject);

rb_define_singleton_method(rb_cApplication, "shared",
application_instance, 0);
rb_define_singleton_method(rb_cApplication, "shared", application_instance, 0);
rb_define_singleton_method(rb_cApplication, "alloc", application_alloc, 0);
rb_define_method(rb_cApplication, "run", application_run, 0);
rb_define_method(rb_cApplication, "start", application_start, 0);

// Internal.
rb_define_method(rb_cApplication, "_screen_size_changed",
application_screen_size_changed, 0);
rb_define_method(rb_cApplication, "_screen_size_changed", application_screen_size_changed, 0);
}

#if CC_TARGET_OS_ANDROID
Expand Down
7 changes: 3 additions & 4 deletions src/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ audio_play(VALUE rcv, SEL sel, int argc, VALUE *argv)

auto audio = new struct mc_Audio();
audio->audio_id = AUDIO_ENGINE::play2d(str,
loop == Qnil ? false : RTEST(loop),
volume == Qnil ? 1.0 : NUM2DBL(volume));
loop == Qnil ? false : RTEST(loop),
volume == Qnil ? 1.0 : NUM2DBL(volume));
return rb_class_wrap_new((void *)audio, rb_cAudio);
}

Expand Down Expand Up @@ -175,8 +175,7 @@ Init_Audio(void)
rb_define_method(rb_cAudio, "volume", audio_volume, 0);
rb_define_method(rb_cAudio, "volume=", audio_volume_set, 1);
rb_define_method(rb_cAudio, "current_position", audio_current_position, 0);
rb_define_method(rb_cAudio, "current_position=",
audio_current_position_set, 1);
rb_define_method(rb_cAudio, "current_position=", audio_current_position_set, 1);
rb_define_method(rb_cAudio, "duration", audio_duration, 0);
rb_define_method(rb_cAudio, "resume", audio_resume, 0);
rb_define_method(rb_cAudio, "pause", audio_pause, 0);
Expand Down
2 changes: 1 addition & 1 deletion src/director.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ director_instance(VALUE rcv, SEL sel)
{
if (mc_director_instance == Qnil) {
VALUE obj = rb_class_wrap_new(
(void *)cocos2d::Director::getInstance(), rb_cDirector);
(void *)cocos2d::Director::getInstance(), rb_cDirector);
mc_director_instance = rb_retain(obj);
}
return mc_director_instance;
Expand Down
6 changes: 2 additions & 4 deletions src/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,14 @@ Init_Events(void)
{
rb_mEvents = rb_define_module_under(rb_mMC, "Events");

rb_cAcceleration = rb_define_class_under(rb_mEvents, "Acceleration",
rb_cObject);
rb_cAcceleration = rb_define_class_under(rb_mEvents, "Acceleration", rb_cObject);

rb_define_method(rb_cAcceleration, "x", acc_x, 0);
rb_define_method(rb_cAcceleration, "y", acc_y, 0);
rb_define_method(rb_cAcceleration, "z", acc_z, 0);
rb_define_method(rb_cAcceleration, "timestamp", acc_timestamp, 0);

rb_cTouch = rb_define_class_under(rb_mEvents, "Touch",
rb_cObject);
rb_cTouch = rb_define_class_under(rb_mEvents, "Touch", rb_cObject);

rb_define_method(rb_cTouch, "location", touch_location, 0);
}
44 changes: 24 additions & 20 deletions src/layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class mc_Scene : public cocos2d::LayerColor {

mc_Scene() {
obj = Qnil;
touch_listener = NULL;
touch_listener = NULL;
#if CC_TARGET_OS_IPHONE || CC_TARGET_OS_APPLETV
update_sel = rb_selector("update:");
#else
Expand Down Expand Up @@ -175,8 +175,7 @@ scene_schedule(VALUE rcv, SEL sel, int argc, VALUE *argv)
char key[100];
snprintf(key, sizeof key, "schedule_lambda_%p", (void *)block);

SCENE(rcv)->schedule(
[block](float delta) {
SCENE(rcv)->schedule([block](float delta) {
VALUE delta_obj = DBL2NUM(delta);
rb_block_call(block, 1, &delta_obj);
},
Expand Down Expand Up @@ -214,28 +213,35 @@ scene_on_touch_event(VALUE rcv, SEL sel, mc_Scene_EventType type)
{
VALUE block = rb_current_block();
if (block == Qnil) {
rb_raise(rb_eArgError, "block not given");
rb_raise(rb_eArgError, "block not given");
}
block = rb_retain(block); // FIXME need release...

auto scene = SCENE(rcv);
if (scene->touch_listener == NULL) {
scene->touch_listener = cocos2d::EventListenerTouchOneByOne::create();
scene->touch_listener = cocos2d::EventListenerTouchOneByOne::create();
}
else {
scene->getEventDispatcher()->removeEventListener(scene->touch_listener);
scene->getEventDispatcher()->removeEventListener(scene->touch_listener);
}
auto lambda = [block](cocos2d::Touch *touch,
cocos2d::Event *event) -> bool {
VALUE touch_obj = rb_class_wrap_new((void *)touch,
rb_cTouch);
return RTEST(rb_block_call(block, 1, &touch_obj));
auto lambda = [block](cocos2d::Touch *touch, cocos2d::Event *event) -> bool {
VALUE touch_obj = rb_class_wrap_new((void *)touch, rb_cTouch);
return RTEST(rb_block_call(block, 1, &touch_obj));
};

switch (type) {
case ON_BEGIN: scene->touch_listener->onTouchBegan = lambda; break;
case ON_MOVE: scene->touch_listener->onTouchMoved = lambda; break;
case ON_END: scene->touch_listener->onTouchEnded = lambda; break;
case ON_CANCEL: scene->touch_listener->onTouchCancelled = lambda; break;
case ON_BEGIN:
scene->touch_listener->onTouchBegan = lambda;
break;
case ON_MOVE:
scene->touch_listener->onTouchMoved = lambda;
break;
case ON_END:
scene->touch_listener->onTouchEnded = lambda;
break;
case ON_CANCEL:
scene->touch_listener->onTouchCancelled = lambda;
break;
}

return scene_add_listener(rcv, scene->touch_listener);
Expand Down Expand Up @@ -308,9 +314,8 @@ scene_on_accelerate(VALUE rcv, SEL sel)

cocos2d::Device::setAccelerometerEnabled(true);
auto listener = cocos2d::EventListenerAcceleration::create(
[block](cocos2d::Acceleration *acc, cocos2d::Event *event) {
VALUE acc_obj = rb_class_wrap_new((void *)acc,
rb_cAcceleration);
[block](cocos2d::Acceleration *acc, cocos2d::Event *event) {
VALUE acc_obj = rb_class_wrap_new((void *)acc, rb_cAcceleration);
rb_block_call(block, 1, &acc_obj);
});

Expand All @@ -334,8 +339,7 @@ scene_on_contact_begin(VALUE rcv, SEL sel)
block = rb_retain(block); // FIXME need release...

auto listener = cocos2d::EventListenerPhysicsContact::create();
listener->onContactBegin = [block](cocos2d::PhysicsContact &contact)
-> bool {
listener->onContactBegin = [block](cocos2d::PhysicsContact &contact) -> bool {
// VALUE touch_obj = rb_class_wrap_new((void *)touch,
// rb_cTouch);
return RTEST(rb_block_call(block, 0, NULL));
Expand Down
22 changes: 12 additions & 10 deletions src/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ menu_align_items_vertically(VALUE rcv, SEL sel, int argc, VALUE *argv)
rb_scan_args(argc, argv, "01", &padding);

if (padding != Qnil) {
MENU(rcv)->alignItemsVerticallyWithPadding(NUM2LONG(padding));
} else {
MENU(rcv)->alignItemsVertically();
MENU(rcv)->alignItemsVerticallyWithPadding(NUM2LONG(padding));
}
else {
MENU(rcv)->alignItemsVertically();
}

return rcv;
Expand All @@ -47,9 +48,10 @@ menu_align_items_horizontally(VALUE rcv, SEL sel, int argc, VALUE *argv)
rb_scan_args(argc, argv, "01", &padding);

if (padding != Qnil) {
MENU(rcv)->alignItemsHorizontallyWithPadding(NUM2LONG(padding));
} else {
MENU(rcv)->alignItemsHorizontally();
MENU(rcv)->alignItemsHorizontallyWithPadding(NUM2LONG(padding));
}
else {
MENU(rcv)->alignItemsHorizontally();
}

return rcv;
Expand Down Expand Up @@ -84,10 +86,10 @@ menu_image_item(VALUE rcv, SEL sel, VALUE normal_image, VALUE selected_image)
block = rb_retain(block); // FIXME need release...

cocos2d::MenuItemImage *item = cocos2d::MenuItemImage::create(
RSTRING_PTR(StringValue(normal_image)), RSTRING_PTR(StringValue(selected_image)),
[block](cocos2d::Ref *sender) {
rb_block_call(block, 0, NULL);
});
RSTRING_PTR(StringValue(normal_image)), RSTRING_PTR(StringValue(selected_image)),
[block](cocos2d::Ref *sender) {
rb_block_call(block, 0, NULL);
});
MENU(rcv)->addChild(item);
return rcv;
}
Expand Down
20 changes: 10 additions & 10 deletions src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,16 @@ node_run_action(VALUE rcv, SEL sel, VALUE action)
{
VALUE block = rb_current_block();
if (block != Qnil) {
block = rb_retain(block); // FIXME need release...
auto call_funcn =
cocos2d::CallFuncN::create([block](cocos2d::Node *node) {
rb_block_call(block, 0, NULL);
});
NODE(rcv)->runAction(cocos2d::Sequence::create(FINITE_TIME_ACTION(action), call_funcn, (void *)0));
block = rb_retain(block); // FIXME need release...
auto call_funcn =
cocos2d::CallFuncN::create(
[block](cocos2d::Node *node) {
rb_block_call(block, 0, NULL);
});
NODE(rcv)->runAction(cocos2d::Sequence::create(FINITE_TIME_ACTION(action), call_funcn, (void *)0));
}
else {
NODE(rcv)->runAction(ACTION(action));
NODE(rcv)->runAction(ACTION(action));
}

return rcv;
Expand Down Expand Up @@ -244,7 +245,7 @@ static VALUE
node_intersects(VALUE rcv, SEL sel, VALUE node)
{
return NODE(rcv)->getBoundingBox().intersectsRect(
NODE(node)->getBoundingBox()) ? Qtrue : Qfalse;
NODE(node)->getBoundingBox()) ? Qtrue : Qfalse;
}

/// @group Container
Expand Down Expand Up @@ -517,8 +518,7 @@ Init_Node(void)
rb_define_method(rb_cNode, "delete", node_delete, -1);
rb_define_method(rb_cNode, "parent", node_parent, 0);
rb_define_method(rb_cNode, "children", node_children, 0);
rb_define_method(rb_cNode, "delete_from_parent", node_delete_from_parent,
-1);
rb_define_method(rb_cNode, "delete_from_parent", node_delete_from_parent, -1);
rb_define_method(rb_cNode, "run_action", node_run_action, 1);
rb_define_method(rb_cNode, "stop_all_actions", node_stop_all_actions, 0);

Expand Down
12 changes: 4 additions & 8 deletions src/particle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,10 @@ Init_Particle(void)
rb_define_method(rb_cParticle, "angle_range=", particle_angle_range_set, 1);
rb_define_method(rb_cParticle, "duration", particle_duration, 0);
rb_define_method(rb_cParticle, "duration=", particle_duration_set, 1);
rb_define_method(rb_cParticle, "position_range",
particle_position_range, 0);
rb_define_method(rb_cParticle, "position_range=",
particle_position_range_set, 1);
rb_define_method(rb_cParticle, "particle_count",
particle_particle_count, 0);
rb_define_method(rb_cParticle, "particle_count=",
particle_particle_count_set, 1);
rb_define_method(rb_cParticle, "position_range", particle_position_range, 0);
rb_define_method(rb_cParticle, "position_range=", particle_position_range_set, 1);
rb_define_method(rb_cParticle, "particle_count", particle_particle_count, 0);
rb_define_method(rb_cParticle, "particle_count=", particle_particle_count_set, 1);
rb_define_method(rb_cParticle, "start_color", particle_start_color, 0);
rb_define_method(rb_cParticle, "start_color=", particle_start_color_set, 1);
rb_define_method(rb_cParticle, "end_color", particle_end_color, 0);
Expand Down
Loading

0 comments on commit df05c12

Please sign in to comment.