<commit_before>/* clutter-box2d - Clutter box2d integration
 *
 * This file implements a the ClutterBox2DActor class which tracks the
 * physics simulation state of an actor. Every actor in a ClutterBox2D
 * container has an assoicated such object for synchronizing visual/physical state.
 *
 * Copyright 2008 OpenedHand Ltd
 * Authored by <NAME> <<EMAIL>>
 * Licensed under the LGPL v2 or greater.
 */

#define SCALE_FACTOR        0.05
#define INV_SCALE_FACTOR    (1.0/SCALE_FACTOR)
#define SYNCLOG(argv...)    if (0) g_print (argv)

#include "Box2D.h"
#include <clutter/clutter.h>
#include "clutter-box2d-actor.h"
#include "clutter-box2d.h"
#include "math.h"
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "clutter-box2d-marshal.h"

/* defined in clutter-box2d-actor.h */
void _clutter_box2d_sync_body (ClutterBox2DActor *box2d_actor);

G_DEFINE_TYPE (ClutterBox2DActor, clutter_box2d_actor, CLUTTER_TYPE_CHILD_META);

#define CLUTTER_BOX2D_ACTOR_GET_PRIVATE(obj) \
      (G_TYPE_INSTANCE_GET_PRIVATE ((obj),   \
       CLUTTER_TYPE_BOX2D_ACTOR,             \
       ClutterBox2DActorPrivate))

enum
{
  PROP_0,
  PROP_IS_BULLET,
  PROP_IS_CIRCLE,
  PROP_LINEAR_VELOCITY,
  PROP_ANGULAR_VELOCITY,
  PROP_MODE,
  PROP_MANIPULATABLE,
};

enum
{
  COLLISION,
  LAST_SIGNAL
};

static gint box2d_actor_signals[LAST_SIGNAL];

struct _ClutterBox2DActorPrivate {
  gboolean manipulatable;
  guint    press_handler;
  guint    captured_handler;
  gboolean was_reactive;

  gint               device_id;
  ClutterBox2DJoint *mouse_joint;
  gfloat        start_x, start_y;
};

static void     dispose                     (GObject      *object);
static void     clutter_box2d_actor_constructed (GObject *object);
static gboolean clutter_box2d_actor_press   (ClutterActor *actor,
                                             ClutterEvent *event,
                                             gpointer      data);
static gboolean clutter_box2d_actor_captured_event (ClutterActor *stage,
                                                    ClutterEvent *event,
                                                    gpointer      data);


ClutterBox2DActor *
clutter_box2d_get_actor (ClutterBox2D *box2d,
                         ClutterActor *actor)
{
  ClutterChildMeta *meta;

  g_return_val_if_fail (CLUTTER_IS_BOX2D (box2d), NULL);
  g_return_val_if_fail (CLUTTER_IS_ACTOR (actor), NULL);

  meta = clutter_container_get_child_meta (CLUTTER_CONTAINER (box2d), actor);
  if (!meta)
    return NULL;

  return CLUTTER_BOX2D_ACTOR (meta);
}


static gboolean
clutter_box2d_actor_is_bullet (ClutterBox2DActor *box2d_actor)
{
  return box2d_actor->body->IsBullet ();
}

static void
clutter_box2d_actor_set_type2 (ClutterBox2DActor *box2d_actor,
                               ClutterBox2DType   type)
{
  ClutterBox2D *box2d = CLUTTER_BOX2D(clutter_child_meta_get_container (CLUTTER_CHILD_META(box2d_actor)));
  b2World *world = ((b2World*)(box2d->world));

  if (box2d_actor->type == type)
    return;
  g_assert (!(type == 0 && box2d_actor->type != 0));

  if (box2d_actor->type != CLUTTER_BOX2D_NONE)
    {
      g_assert (box2d_actor->body);

      g_hash_table_remove (box2d->bodies, box2d_actor->body);
      world->DestroyBody (box2d_actor->body);
      box2d_actor->body = NULL;
      box2d_actor->shape = NULL;
      box2d_actor->type = CLUTTER_BOX2D_NONE;
    }

  if (type == CLUTTER_BOX2D_DYNAMIC ||
      type == CLUTTER_BOX2D_STATIC)
    {
      b2BodyDef bodyDef;

      bodyDef.linearDamping = 0.5f;
      bodyDef.angularDamping = 0.5f;


      SYNCLOG ("making an actor to be %s\n",
               type == CLUTTER_BOX2D_STATIC ? "static" : "dynamic");

      box2d_actor->type = type;

      if (type == CLUTTER_BOX2D_DYNAMIC)
        {
          box2d_actor->body = world->CreateBody (&bodyDef);
        }
      else if (type == CLUTTER_BOX2D_STATIC)
        {

          box2d_actor->body = world->CreateBody (&bodyDef);
        }
      _clutter_box2d_sync_body (box2d_actor);


      if (type == CLUTTER_BOX2D_DYNAMIC)
        {
          box2d_actor->body->SetMassFromShapes ();
        }
    }
  g_hash_table_insert (box2d->bodies, box2d_actor->body, box2d_actor);
}

/* Set the type of physical object an actor in a Box2D group is of.
 */
static void
clutter_box2d_actor_set_type (ClutterBox2D      *box2d,
                              ClutterActor      *actor,
                              ClutterBox2DType   type)
{
  ClutterBox2DActor *box2d_actor;
  
  box2d_actor =
    CLUTTER_BOX2D_ACTOR (clutter_container_get_child_meta (CLUTTER_CONTAINER (box2d), actor));<commit_msg>box2d-actor: Add support for disabling physics<commit_after>/* clutter-box2d - Clutter box2d integration
 *
 * This file implements a the ClutterBox2DActor class which tracks the
 * physics simulation state of an actor. Every actor in a ClutterBox2D
 * container has an assoicated such object for synchronizing visual/physical state.
 *
 * Copyright 2008 OpenedHand Ltd
 * Authored by <NAME> <<EMAIL>>
 * Licensed under the LGPL v2 or greater.
 */

#define SCALE_FACTOR        0.05
#define INV_SCALE_FACTOR    (1.0/SCALE_FACTOR)
#define SYNCLOG(argv...)    if (0) g_print (argv)

#include "Box2D.h"
#include <clutter/clutter.h>
#include "clutter-box2d-actor.h"
#include "clutter-box2d.h"
#include "math.h"
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "clutter-box2d-marshal.h"

/* defined in clutter-box2d-actor.h */
void _clutter_box2d_sync_body (ClutterBox2DActor *box2d_actor);

G_DEFINE_TYPE (ClutterBox2DActor, clutter_box2d_actor, CLUTTER_TYPE_CHILD_META);

#define CLUTTER_BOX2D_ACTOR_GET_PRIVATE(obj) \
      (G_TYPE_INSTANCE_GET_PRIVATE ((obj),   \
       CLUTTER_TYPE_BOX2D_ACTOR,             \
       ClutterBox2DActorPrivate))

enum
{
  PROP_0,
  PROP_IS_BULLET,
  PROP_IS_CIRCLE,
  PROP_LINEAR_VELOCITY,
  PROP_ANGULAR_VELOCITY,
  PROP_MODE,
  PROP_MANIPULATABLE,
};

enum
{
  COLLISION,
  LAST_SIGNAL
};

static gint box2d_actor_signals[LAST_SIGNAL];

struct _ClutterBox2DActorPrivate {
  gboolean manipulatable;
  guint    press_handler;
  guint    captured_handler;
  gboolean was_reactive;

  gint               device_id;
  ClutterBox2DJoint *mouse_joint;
  gfloat        start_x, start_y;
};

static void     dispose                     (GObject      *object);
static void     clutter_box2d_actor_constructed (GObject *object);
static gboolean clutter_box2d_actor_press   (ClutterActor *actor,
                                             ClutterEvent *event,
                                             gpointer      data);
static gboolean clutter_box2d_actor_captured_event (ClutterActor *stage,
                                                    ClutterEvent *event,
                                                    gpointer      data);


ClutterBox2DActor *
clutter_box2d_get_actor (ClutterBox2D *box2d,
                         ClutterActor *actor)
{
  ClutterChildMeta *meta;

  g_return_val_if_fail (CLUTTER_IS_BOX2D (box2d), NULL);
  g_return_val_if_fail (CLUTTER_IS_ACTOR (actor), NULL);

  meta = clutter_container_get_child_meta (CLUTTER_CONTAINER (box2d), actor);
  if (!meta)
    return NULL;

  return CLUTTER_BOX2D_ACTOR (meta);
}


static gboolean
clutter_box2d_actor_is_bullet (ClutterBox2DActor *box2d_actor)
{
  return box2d_actor->body->IsBullet ();
}

static void
clutter_box2d_actor_set_type2 (ClutterBox2DActor *box2d_actor,
                               ClutterBox2DType   type)
{
  ClutterBox2D *box2d = CLUTTER_BOX2D(clutter_child_meta_get_container (CLUTTER_CHILD_META(box2d_actor)));
  b2World *world = ((b2World*)(box2d->world));

  if (box2d_actor->type == type)
    return;

  if (box2d_actor->type != CLUTTER_BOX2D_NONE)
    {
      g_assert (box2d_actor->body);

      g_hash_table_remove (box2d->bodies, box2d_actor->body);
      world->DestroyBody (box2d_actor->body);
      box2d_actor->body = NULL;
      box2d_actor->shape = NULL;
      box2d_actor->type = CLUTTER_BOX2D_NONE;
    }

  if (type == CLUTTER_BOX2D_DYNAMIC ||
      type == CLUTTER_BOX2D_STATIC)
    {
      b2BodyDef bodyDef;

      bodyDef.linearDamping = 0.5f;
      bodyDef.angularDamping = 0.5f;


      SYNCLOG ("making an actor to be %s\n",
               type == CLUTTER_BOX2D_STATIC ? "static" : "dynamic");

      box2d_actor->type = type;

      if (type == CLUTTER_BOX2D_DYNAMIC)
        {
          box2d_actor->body = world->CreateBody (&bodyDef);
        }
      else if (type == CLUTTER_BOX2D_STATIC)
        {

          box2d_actor->body = world->CreateBody (&bodyDef);
        }
      _clutter_box2d_sync_body (box2d_actor);


      if (type == CLUTTER_BOX2D_DYNAMIC)
        {
          box2d_actor->body->SetMassFromShapes ();
        }

      g_hash_table_insert (box2d->bodies, box2d_actor->body, box2d_actor);
    }
}

/* Set the type of physical object an actor in a Box2D group is of.
 */
static void
clutter_box2d_actor_set_type (ClutterBox2D      *box2d,
                              ClutterActor      *actor,
                              ClutterBox2DType   type)
{
  ClutterBox2DActor *box2d_actor;
  
  box2d_actor =
    CLUTTER_BOX2D_ACTOR (clutter_container_get_child_meta (CLUTTER_CONTAINER (box2d), actor));
{'fraction_non_alphanumeric': 0.08999021845451581, 'fraction_numerical': 0.022171503097489404, 'mean_word_length': 2.7883902840675177, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 62, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2872059', 'n_tokens_mistral': 3387, 'n_tokens_neox': 3284, 'n_words': 617}