<commit_before>#include "cinder/app/AppNative.h"
#include "cinder/gl/gl.h"
#include "pockets/SpriteSheet.h"
#include "pockets/SimpleRenderer.h"
#include "pockets/Sprite.h"

using namespace ci;
using namespace ci::app;
using namespace std;

class SpriteRendererApp : public AppNative {
public:
	void setup();
	void mouseDown( MouseEvent event );
  void update();
private:
  pk::SpriteSheetRef      mSpriteSheet;
  pk::SpriteRef           mSprite;
  pk::SpriteAnimationRef  mSpriteAnimation;
  pk::SimpleRendererRef   mRenderer;
  float                   mLastUpdate;
};

void SpriteRendererApp::setup()
{
  mSpriteSheet = pk::SpriteSheet::load( getAssetPath( "sprite_sheet.json" ) );
  auto sprites = mSpriteSheet->getSpriteNames();

  mSprite = pk::SpriteRef( new pk::Sprite( mSpriteSheet->getSpriteData("wood_cracked") ) );
  mSprite->getLocus().setLoc( getWindowSize() / 2 );
  mSprite->setLayer( 2 ); // an arbitrary number > 0 to be in front of other content

  mSpriteAnimation = pk::SpriteAnimationRef( new pk::SpriteAnimation );
  mSpriteAnimation->getLocus().setLoc( getWindowSize() / 2 );
  for( const string &name : sprites )
  {
    mSpriteAnimation->addFrame( mSpriteSheet->getSpriteData(name), 2.0f / 24.0f );
  }

  mRenderer = pk::SimpleRenderer::create();
  mRenderer->add( mSprite );
  mRenderer->add( mSpriteAnimation );
  mRenderer->setPreDrawFn( [=](){ mSpriteSheet->enableAndBind(); } );
  mRenderer->setPostDrawFn( [=](){ mSpriteSheet->unbind(); } );

  getSignalUpdate().connect( [this](){ mRenderer->update(); } );
  getWindow()->getSignalDraw().connect( [this](){
                                        gl::clear( Color::black() );
                                        mRenderer->draw();
                                        } );
  mLastUpdate = getElapsedSeconds();
}

void SpriteRendererApp::mouseDown( MouseEvent event )
{
  mSprite->getLocus().setLoc( event.getPos() );
}

void SpriteRendererApp::update()
{
  float now = getElapsedSeconds();
  float deltaTime = now - mLastUpdate;
  mLastUpdate = now;
  mSpriteAnimation->update( deltaTime );
}

CINDER_APP_NATIVE( SpriteRendererApp, RendererGl )<commit_msg>Mouse move for interaction makes it easier to see.<commit_after>#include "cinder/app/AppNative.h"
#include "cinder/gl/gl.h"
#include "pockets/SpriteSheet.h"
#include "pockets/SimpleRenderer.h"
#include "pockets/Sprite.h"

using namespace ci;
using namespace ci::app;
using namespace std;

class SpriteRendererApp : public AppNative {
public:
	void setup();
  void mouseMove( MouseEvent event );
  void update();
private:
  pk::SpriteSheetRef      mSpriteSheet;
  pk::SpriteRef           mSprite;
  pk::SpriteAnimationRef  mSpriteAnimation;
  pk::SimpleRendererRef   mRenderer;
  float                   mLastUpdate;
};

void SpriteRendererApp::setup()
{
  mSpriteSheet = pk::SpriteSheet::load( getAssetPath( "sprite_sheet.json" ) );
  auto sprites = mSpriteSheet->getSpriteNames();

  mSprite = pk::SpriteRef( new pk::Sprite( mSpriteSheet->getSpriteData("wood_cracked") ) );
  mSprite->getLocus().setLoc( getWindowSize() / 2 );
  mSprite->setLayer( 2 ); // an arbitrary number > 0 to be in front of other content

  mSpriteAnimation = pk::SpriteAnimationRef( new pk::SpriteAnimation );
  mSpriteAnimation->getLocus().setLoc( getWindowSize() / 2 );
  for( const string &name : sprites )
  {
    mSpriteAnimation->addFrame( mSpriteSheet->getSpriteData(name), 2.0f / 24.0f );
  }

  mRenderer = pk::SimpleRenderer::create();
  mRenderer->add( mSprite );
  mRenderer->add( mSpriteAnimation );
  mRenderer->setPreDrawFn( [=](){ mSpriteSheet->enableAndBind(); } );
  mRenderer->setPostDrawFn( [=](){ mSpriteSheet->unbind(); } );

  getSignalUpdate().connect( [this](){ mRenderer->update(); } );
  getWindow()->getSignalDraw().connect( [this](){
                                        gl::clear( Color::black() );
                                        mRenderer->draw();
                                        } );
  mLastUpdate = getElapsedSeconds();
}

void SpriteRendererApp::mouseMove( MouseEvent event )
{
  mSprite->getLocus().setLoc( event.getPos() );
}

void SpriteRendererApp::update()
{
  float now = getElapsedSeconds();
  float deltaTime = now - mLastUpdate;
  mLastUpdate = now;
  mSpriteAnimation->update( deltaTime );
}

CINDER_APP_NATIVE( SpriteRendererApp, RendererGl )
{'fraction_non_alphanumeric': 0.1407116451016636, 'fraction_numerical': 0.004158964879852125, 'mean_word_length': 3.6498388829215895, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2972981', 'n_tokens_mistral': 1355, 'n_tokens_neox': 1380, 'n_words': 270}