<commit_before>//
//  msgf_if.cpp
//
//	Musical Sound Generator Framework
//
//  Created by 長谷部 雅彦 on 2012/09/22.
//  Copyright (c) 2012年 長谷部 雅彦. All rights reserved.
//

#include "msgf_if.h"
#include "msgf_note.h"

using namespace msgf;

//---------------------------------------------------------
//		msgf Constructor/Destructor
//---------------------------------------------------------
Msgf::Msgf( void )
{
	for ( int i=0; i<MAX_PART_NUM; i++ ){
		_pt[i] = new Part(this);
	}
}
//---------------------------------------------------------
Msgf::~Msgf()
{
	for ( int i=0; i<MAX_PART_NUM; i++ ){
		delete _pt[i];
	}
}

//---------------------------------------------------------
//		msgf Entrance
//---------------------------------------------------------
void Msgf::sendMessage( int maxMessage, Uint8* message )
{
	if ( maxMessage	== 1 ) makeChMessage( *message );

	else {
		analyzePartOfChMessage( *message, *(message+1), *(message+2) );
	}
}

//---------------------------------------------------------
//		Make united MIDI Ch Message
//---------------------------------------------------------
void Msgf::makeChMessage( Uint8 byteData )
{
	//	if Exclusive, Don't do anything
	if (( byteData & 0xf0 ) == 0xf0 ) return;

	if (( _tempCounter == 0 ) && ( byteData & 0x80 )){
		_tempFirstByte = byteData;
		_tempCounter = 1;
	}
	else if (( _tempCounter == 1 ) && (( byteData & 0x80 ) == 0 )){
		_tempSecondByte = byteData;
		switch ( _tempFirstByte ) {
			case 0xd0:
			case 0xc0:
				_tempCounter = 0;
				analyzePartOfChMessage( _tempFirstByte, _tempSecondByte, DONT_CARE );
				break;

			default:
				_tempCounter = 2;
				break;
		}
	}
	else if (( _tempCounter == 2 ) && (( byteData & 0x80 ) == 0 )){
		_tempCounter = 0;
		analyzePartOfChMessage( _tempFirstByte, _tempSecondByte, byteData );
	}
}

//---------------------------------------------------------
//		Analyze & Call Part
//---------------------------------------------------------
void Msgf::analyzePartOfChMessage( Uint8 dt1, Uint8 dt2, Uint8 dt3 )
{
	int part =  dt1 & 0x0f;
	if ( part >= MAX_PART_NUM ) return;

	switch ( dt1 & 0xf0 ) {
		case 0x80:
			_pt[part]->keyOff( dt2, dt3 );
			break;
		case 0x90:
			if ( dt3 == 0 ) _pt[part]->keyOff( dt2, 0x40 );
			else _pt[part]->keyOn( dt2, dt3 );
			break;
		case 0xb0:
			_pt[part]->controlChange( dt2, dt3 );
			break;
		case 0xc0:
			_pt[part]->programChange( dt2 );
			break;
		case 0xe0:{
			int bendValue = dt3;
			bendValue += dt2*128;
			bendValue -= 8192;
			_pt[part]->pitchBend( bendValue );
			break;
		}
		case 0xf0:{
			_pt[part]->specialCommand( dt1, dt2, dt3 );
			break;
		}
		default:
			break;
	}
}

//---------------------------------------------------------
//		Analyze & Call Part
//---------------------------------------------------------
void Msgf::reduceResource( void )
{
	double	lvl = 1;
	Note*	ntRsc = 0;

	for ( int i=0; i<MAX_PART_NUM; i++ ){
		Note *ntPtr = 0;
		double ptLvl = _pt[i]->getInstrument()->searchMinimumLevelNote( &ntPtr );
		if ( ntPtr && ( ptLvl < lvl )){
			lvl = ptLvl;
			ntRsc = ntPtr;
		}
	}

	if ( ntRsc ) ntRsc->damp();
}

//---------------------------------------------------------
//		Audio Process Function
//---------------------------------------------------------
void Msgf::process( TgAudioBuffer& inputBuf )
{
	for ( int i=0; i<MAX_PART_NUM; i++ ){
		_pt[i]->process( inputBuf );
	}
}

<commit_msg>F0hのIFはパートの概念は無しにする<commit_after>//
//  msgf_if.cpp
//
//	Musical Sound Generator Framework
//
//  Created by 長谷部 雅彦 on 2012/09/22.
//  Copyright (c) 2012年 長谷部 雅彦. All rights reserved.
//

#include "msgf_if.h"
#include "msgf_note.h"

using namespace msgf;

//---------------------------------------------------------
//		msgf Constructor/Destructor
//---------------------------------------------------------
Msgf::Msgf( void )
{
	for ( int i=0; i<MAX_PART_NUM; i++ ){
		_pt[i] = new Part(this);
	}
}
//---------------------------------------------------------
Msgf::~Msgf()
{
	for ( int i=0; i<MAX_PART_NUM; i++ ){
		delete _pt[i];
	}
}

//---------------------------------------------------------
//		msgf Entrance
//---------------------------------------------------------
void Msgf::sendMessage( int maxMessage, Uint8* message )
{
	if ( maxMessage	== 1 ) makeChMessage( *message );

	else {
		analyzePartOfChMessage( *message, *(message+1), *(message+2) );
	}
}

//---------------------------------------------------------
//		Make united MIDI Ch Message
//---------------------------------------------------------
void Msgf::makeChMessage( Uint8 byteData )
{
	//	if Exclusive, Don't do anything
	if (( byteData & 0xf0 ) == 0xf0 ) return;

	if (( _tempCounter == 0 ) && ( byteData & 0x80 )){
		_tempFirstByte = byteData;
		_tempCounter = 1;
	}
	else if (( _tempCounter == 1 ) && (( byteData & 0x80 ) == 0 )){
		_tempSecondByte = byteData;
		switch ( _tempFirstByte ) {
			case 0xd0:
			case 0xc0:
				_tempCounter = 0;
				analyzePartOfChMessage( _tempFirstByte, _tempSecondByte, DONT_CARE );
				break;

			default:
				_tempCounter = 2;
				break;
		}
	}
	else if (( _tempCounter == 2 ) && (( byteData & 0x80 ) == 0 )){
		_tempCounter = 0;
		analyzePartOfChMessage( _tempFirstByte, _tempSecondByte, byteData );
	}
}

//---------------------------------------------------------
//		Analyze & Call Part
//---------------------------------------------------------
void Msgf::analyzePartOfChMessage( Uint8 dt1, Uint8 dt2, Uint8 dt3 )
{
	int part =  dt1 & 0x0f;

	if ((dt1 & 0xf0) == 0xf0 ) {
		for ( int i=0; i<MAX_PART_NUM; i++ ){
			_pt[i]->specialCommand( dt1, dt2, dt3 );
		}
	}

	if ( part >= MAX_PART_NUM ) return;

	switch ( dt1 & 0xf0 ) {
		case 0x80:
			_pt[part]->keyOff( dt2, dt3 );
			break;
		case 0x90:
			if ( dt3 == 0 ) _pt[part]->keyOff( dt2, 0x40 );
			else _pt[part]->keyOn( dt2, dt3 );
			break;
		case 0xb0:
			_pt[part]->controlChange( dt2, dt3 );
			break;
		case 0xc0:
			_pt[part]->programChange( dt2 );
			break;
		case 0xe0:{
			int bendValue = dt3;
			bendValue += dt2*128;
			bendValue -= 8192;
			_pt[part]->pitchBend( bendValue );
			break;
		}
		default:
			break;
	}
}

//---------------------------------------------------------
//		Analyze & Call Part
//---------------------------------------------------------
void Msgf::reduceResource( void )
{
	double	lvl = 1;
	Note*	ntRsc = 0;

	for ( int i=0; i<MAX_PART_NUM; i++ ){
		Note *ntPtr = 0;
		double ptLvl = _pt[i]->getInstrument()->searchMinimumLevelNote( &ntPtr );
		if ( ntPtr && ( ptLvl < lvl )){
			lvl = ptLvl;
			ntRsc = ntPtr;
		}
	}

	if ( ntRsc ) ntRsc->damp();
}

//---------------------------------------------------------
//		Audio Process Function
//---------------------------------------------------------
void Msgf::process( TgAudioBuffer& inputBuf )
{
	for ( int i=0; i<MAX_PART_NUM; i++ ){
		_pt[i]->process( inputBuf );
	}
}

<|endoftext|>


<commit_before>#include "gamelib/export.hpp"
#include "gamelib/core/ecs/EntityFactory.hpp"

namespace gamelib
{
    bool save(const std::string& fname)
    {
        return save(fname, [](Json::Value&, Entity&) { return true; });
    }

    bool saveToJson(Json::Value& node)
    {
        return saveToJson(node, [](Json::Value&, Entity&) { return true; });
    }

    bool loadSave(const std::string& fname, bool direct)
    {
        Json::Value node;
        if (!loadJsonFromFile(fname, node))
        {
            LOG_ERROR("Failed to load save from file ", fname);
            return false;
        }

        return loadSaveFromJson(node, direct);
    }

    bool loadSaveFromJson(const Json::Value& node, bool direct)
    {
        LOG("Loading game...");

        auto scene = Scene::getActive();
        if (scene)
            scene->loadFromJson(node["scene"]);

        auto entmgr = getSubsystem<EntityManager>();
        auto factory = getSubsystem<EntityFactory>();

        if (entmgr && factory)
        {
            const auto& mgrnode = node["entmgr"];
            entmgr->clear();

            if (!mgrnode.isArray())
            {
                LOG_WARN("No valid entity array in save file");
                return true;
            };

            if (direct)
                for (auto& i : mgrnode)
                    factory->createFromJson(i);
            else
                for (auto& i : mgrnode)
                    factory->createWithDelta(i["name"].asString(), i);
        }

        LOG("Loading finished");
        return true;
    }
}
<commit_msg>Output which entity is being loaded<commit_after>#include "gamelib/export.hpp"
#include "gamelib/core/ecs/EntityFactory.hpp"

namespace gamelib
{
    bool save(const std::string& fname)
    {
        return save(fname, [](Json::Value&, Entity&) { return true; });
    }

    bool saveToJson(Json::Value& node)
    {
        return saveToJson(node, [](Json::Value&, Entity&) { return true; });
    }

    bool loadSave(const std::string& fname, bool direct)
    {
        Json::Value node;
        if (!loadJsonFromFile(fname, node))
        {
            LOG_ERROR("Failed to load save from file ", fname);
            return false;
        }

        return loadSaveFromJson(node, direct);
    }

    bool loadSaveFromJson(const Json::Value& node, bool direct)
    {
        LOG("Loading game...");

        auto scene = Scene::getActive();
        if (scene)
            scene->loadFromJson(node["scene"]);

        auto entmgr = getSubsystem<EntityManager>();
        auto factory = getSubsystem<EntityFactory>();

        if (entmgr && factory)
        {
            const auto& mgrnode = node["entmgr"];
            entmgr->clear();

            if (!mgrnode.isArray())
            {
                LOG_WARN("No valid entity array in save file");
                return true;
            };

            for (auto& i : mgrnode)
            {
                LOG_DEBUG("Creating entity ", i["name"].asString());

                if (direct)
                    factory->createFromJson(i);
                else
                    factory->createWithDelta(i["name"].asString(), i);
            }
        }

        LOG("Loading finished");
        return true;
    }
}
<|endoftext|>


<commit_before>/*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <folly/detail/AtFork.h>

#include <atomic>
#include <mutex>
#include <thread>

#include <glog/logging.h>

#include <folly/portability/GTest.h>

TEST(ThreadLocal, AtFork) {
  int foo;
  bool forked = false;
  folly::detail::AtFork::registerHandler(
      &foo,
      [&] {
        forked = true;
        return true;
      },
      [] {},
      [] {});
  auto pid = folly::kIsSanitizeThread
      ? folly::detail::AtFork::forkInstrumented(fork)
      : fork();
  if (pid) {
    int status;
    auto pid2 = wait(&status);
    EXPECT_EQ(status, 0);
    EXPECT_EQ(pid, pid2);
  } else {
    exit(0);
  }
  EXPECT_TRUE(forked);
  forked = false;
  folly::detail::AtFork::unregisterHandler(&foo);
  pid = fork();
  if (pid) {
    int status;
    auto pid2 = wait(&status);
    EXPECT_EQ(status, 0);
    EXPECT_EQ(pid, pid2);
  } else {
    exit(0);
  }
  EXPECT_FALSE(forked);
}

TEST(ThreadLocal, AtForkOrdering) {
  std::atomic<bool> done{false};
  std::atomic<bool> started{false};
  std::mutex a;
  std::mutex b;
  int foo;
  int foo2;
  folly::detail::AtFork::registerHandler(
      &foo,
      [&] { return a.try_lock(); },
      [&] { a.unlock(); },
      [&] { a.unlock(); });
  folly::detail::AtFork::registerHandler(
      &foo2,
      [&] { return b.try_lock(); },
      [&] { b.unlock(); },
      [&] { b.unlock(); });

  auto thr = std::thread([&]() {
    std::lock_guard<std::mutex> g(a);
    started = true;
    usleep(100);
    std::lock_guard<std::mutex> g2(b);
  });
  while (!started) {
  }
  auto pid = folly::kIsSanitizeThread
      ? folly::detail::AtFork::forkInstrumented(fork)
      : fork();
  if (pid) {
    int status;
    auto pid2 = wait(&status);
    EXPECT_EQ(status, 0);
    EXPECT_EQ(pid, pid2);
  } else {
    exit(0);
  }
  done = true;
  thr.join();
}
<commit_msg>patch AtFork test under TSAN<commit_after>/*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <folly/detail/AtFork.h>

#include <atomic>
#include <mutex>
#include <thread>

#include <glog/logging.h>

#include <folly/portability/GMock.h>
#include <folly/portability/GTest.h>

TEST(ThreadLocal, AtFork) {
  int foo;
  bool forked = false;
  folly::detail::AtFork::registerHandler(
      &foo,
      [&] {
        forked = true;
        return true;
      },
      [] {},
      [] {});
  auto pid = folly::kIsSanitizeThread
      ? folly::detail::AtFork::forkInstrumented(fork)
      : fork();
  if (pid) {
    int status;
    auto pid2 = wait(&status);
    EXPECT_EQ(status, 0);
    EXPECT_EQ(pid, pid2);
  } else {
    exit(0);
  }
  EXPECT_TRUE(forked);
  forked = false;
  folly::detail::AtFork::unregisterHandler(&foo);
  pid = fork();
  if (pid) {
    int status;
    auto pid2 = wait(&status);
    EXPECT_EQ(status, 0);
    EXPECT_EQ(pid, pid2);
  } else {
    exit(0);
  }
  EXPECT_FALSE(forked);
}

TEST(ThreadLocal, AtForkOrdering) {
  std::atomic<bool> done{false};
  std::atomic<bool> started{false};
  std::mutex a;
  std::mutex b;
  int foo;
  int foo2;
  folly::detail::AtFork::registerHandler(
      &foo,
      [&] { return a.try_lock(); },
      [&] { a.unlock(); },
      [&] { a.unlock(); });
  folly::detail::AtFork::registerHandler(
      &foo2,
      [&] { return b.try_lock(); },
      [&] { b.unlock(); },
      [&] { b.unlock(); });

  auto thr = std::thread([&]() {
    std::lock_guard<std::mutex> g(a);
    started = true;
    usleep(100);
    std::lock_guard<std::mutex> g2(b);
  });
  while (!started) {
  }
  auto pid = folly::kIsSanitizeThread
      ? folly::detail::AtFork::forkInstrumented(fork)
      : fork();
  if (pid) {
    int status;
    auto pid2 = wait(&status);
    EXPECT_TRUE(WIFEXITED(status));
    EXPECT_THAT(
        WEXITSTATUS(status),
        folly::kIsSanitizeThread //
            ? testing::AnyOfArray({0, 66})
            : testing::AnyOfArray({0}));
    EXPECT_EQ(pid, pid2);
  } else {
    exit(0);
  }
  done = true;
  thr.join();
}
<|endoftext|>


<commit_before>#include "musicrightareawidget.h"
#include "ui_musicapplication.h"
#include "musicuiobject.h"
#include "musiclrccontainerfordesktop.h"
#include "musicvideoplayer.h"
#include "musicdownloadstatuslabel.h"
#include "musicsettingwidget.h"
#include "musicmessagebox.h"
#include "musicconnectionpool.h"

MusicRightAreaWidget::MusicRightAreaWidget(QWidget *parent)
    : QWidget(parent), m_videoPlayer(NULL)
{
    m_supperClass = parent;
    m_musiclrcfordesktop = new MusicLrcContainerForDesktop(parent);
    m_downloadStatusLabel = new MusicDownloadStatusLabel(parent);
    m_setting = new MusicSettingWidget(this);
    connect(m_setting, SIGNAL(parameterSettingChanged()), parent,
                       SLOT(getParameterSetting()));

    M_Connection->setValue("MusicRightAreaWidget", this);
    M_Connection->connect("MusicSongSearchOnlineTableWidget",
                          "MusicRightAreaWidget");
}

MusicRightAreaWidget::~MusicRightAreaWidget()
{
    delete m_setting;
    delete m_videoPlayer;
    delete m_downloadStatusLabel;
    delete m_musiclrcfordesktop;
}

void MusicRightAreaWidget::setupUi(Ui::MusicApplication* ui)
{
    m_ui = ui;
    m_downloadStatusLabel->setMovieLabel(m_ui->showDownloadGif);

    ui->musicSearchRefreshButton->setCursor(QCursor(Qt::PointingHandCursor));
    ui->musicSearchRefreshButton->setStyleSheet(MusicUIObject::MPushButtonStyle07);
    ui->musicSearchRefreshButton->setIconSize(QSize(25,25));
    ui->musicSearchRefreshButton->setIcon(QIcon(QString::fromUtf8(":/image/flash")));
    connect(ui->musicSearchRefreshButton,SIGNAL(clicked()), SLOT(musicSearchRefreshButtonRefreshed()));

    ui->musicIndexWidgetButton->setCursor(QCursor(Qt::PointingHandCursor));
    ui->musicIndexWidgetButton->setStyleSheet(MusicUIObject::MPushButtonStyle16);
    connect(ui->musicIndexWidgetButton,SIGNAL(clicked()), SLOT(musicIndexWidgetButtonSearched()));

    ui->musicSearchWidgetButton->setCursor(QCursor(Qt::PointingHandCursor));
    ui->musicSearchWidgetButton->setStyleSheet(MusicUIObject::MPushButtonStyle07);
    connect(ui->musicSearchWidgetButton,SIGNAL(clicked()), SLOT(musicSearchWidgetButtonSearched()));

    ui->musicLrcWidgetButton->setCursor(QCursor(Qt::PointingHandCursor));
    ui->musicLrcWidgetButton->setStyleSheet(MusicUIObject::MPushButtonStyle07);
    connect(ui->musicLrcWidgetButton,SIGNAL(clicked()), SLOT(musicLrcWidgetButtonSearched()));

    ui->vedioWidgetButton->setCursor(QCursor(Qt::PointingHandCursor));
    ui->vedioWidgetButton->setStyleSheet(MusicUIObject::MPushButtonStyle07);
    connect(ui->vedioWidgetButton,SIGNAL(clicked()), SLOT(musicVideoWidgetButtonSearched()));
    ///////////////////////////////////////////////////////
    connect(m_musiclrcfordesktop,SIGNAL(theCurrentLrcUpdated()), m_supperClass,
                 SLOT(musicCurrentLrcUpdated()));
    connect(m_musiclrcfordesktop,SIGNAL(changeCurrentLrcColorSetting()), m_supperClass,
                 SLOT(musicSetting()));
    connect(m_musiclrcfordesktop,SIGNAL(changeCurrentLrcColorCustom()), m_setting,
                 SLOT(changeDesktopLrcWidget()));
    connect(m_musiclrcfordesktop,SIGNAL(desktopLrcClosed()), SIGNAL(desktopLrcClosed()));
    connect(m_musiclrcfordesktop,SIGNAL(setWindowLockedChanged(bool)), SIGNAL(lockDesktopLrc(bool)));
    ///////////////////////////////////////////////////////
    connect(ui->musiclrccontainerforinline,SIGNAL(changeCurrentLrcColorCustom()), m_setting,
                 SLOT(changeInlineLrcWidget()));
    connect(ui->musiclrccontainerforinline,SIGNAL(theCurrentLrcUpdated()), m_supperClass,
                 SLOT(musicCurrentLrcUpdated()));
    connect(ui->musiclrccontainerforinline, SIGNAL(theArtBgHasChanged()),
                 SIGNAL(updateBgThemeDownload()));
    connect(ui->musiclrccontainerforinline,SIGNAL(changeCurrentLrcColorSetting()), m_supperClass,
                 SLOT(musicSetting()));
    connect(ui->musiclrccontainerforinline,SIGNAL(updateCurrentTime(qint64)), m_supperClass,
                 SLOT(updateCurrentTime(qint64)));
    ///////////////////////////////////////////////////////
}

void MusicRightAreaWidget::stopLrcMask() const
{
    if( checkSettingParameterValue() )
    {
       m_ui->musiclrccontainerforinline->stopLrcMask();
       m_musiclrcfordesktop->stopLrcMask();
    }
}

void MusicRightAreaWidget::startTimerClock() const
{
    if( checkSettingParameterValue() )
    {
       m_ui->musiclrccontainerforinline->startTimerClock();
       m_musiclrcfordesktop->startTimerClock();
    }
}

void MusicRightAreaWidget::showPlayStatus(bool status) const
{
    m_musiclrcfordesktop->showPlayStatus(status);
}

void MusicRightAreaWidget::setDestopLrcVisible(const QString &status) const
{
    setDestopLrcVisible( status == "true" ? true : false);
}

bool MusicRightAreaWidget::getDestopLrcVisible() const
{
    return m_musiclrcfordesktop->isVisible();
}

void MusicRightAreaWidget::setInlineLrcVisible(const QString &status) const
{
    m_ui->musiclrccontainerforinline->setVisible(status == "true" ? true : false);
}

void MusicRightAreaWidget::setSettingParameter() const
{
    m_musiclrcfordesktop->setSettingParameter();
    m_ui->musiclrccontainerforinline->setSettingParameter();
}

bool MusicRightAreaWidget::checkSettingParameterValue() const
{
    return ( M_SETTING->value(MusicSettingManager::ShowInlineLrcChoiced).toBool() ||
             M_SETTING->value(MusicSettingManager::ShowDesktopLrcChoiced).toBool() )
             ? true : false;
}

void MusicRightAreaWidget::updateCurrentLrc(qint64 current, qint64 total, bool playStatus) const
{
    m_ui->musiclrccontainerforinline->setCurrentPosition(current);
    //Direct access to the audio file is the total time, in milliseconds
    MIntStringMap lrcContainer(m_ui->musiclrccontainerforinline->getLrcContainer());
    //The corresponding access to current time lyrics
    if(!lrcContainer.isEmpty())
    {
        //After get the current time in the lyrics of the two time points
        qint64 previous = 0;
        qint64 later = 0;
        //Keys () method returns a list of lrcContainer
        foreach (qint64 value, lrcContainer.keys())
        {
            if(current >= value)
            {
                previous = value;
            }
            else
            {
                later = value;
                break;
            }
        }
        //To the last line, set the later to song total time value
        if(later == 0)
        {
            later = total;
        }
        //The lyrics content corresponds to obtain the current time
        QString currentLrc = lrcContainer.value(previous);
        QString laterLrc = lrcContainer.value(later);
        //If this is a new line of the lyrics, then restart lyrics display mask
        if(currentLrc != m_ui->musiclrccontainerforinline->text())
        {
            qint64 intervalTime = later - previous;
            if(!playStatus)
            {
                m_ui->musiclrccontainerforinline->updateCurrentLrc(intervalTime);
            }
            m_musiclrcfordesktop->updateCurrentLrc(currentLrc, laterLrc, intervalTime);
        }
    }
}

void MusicRightAreaWidget::loadCurrentSongLrc(const QString &name, const QString &path) const
{
    if( checkSettingParameterValue() )
    {
        m_ui->musiclrccontainerforinline->stopLrcMask();
        m_ui->musiclrccontainerforinline->setCurrentSongName( name );
        m_ui->musiclrccontainerforinline->transLrcFileToTime( path.trimmed() );
        m_musiclrcfordesktop->setCurrentSongName( name );
        m_musiclrcfordesktop->initCurrentLrc();
    }
}

void MusicRightAreaWidget::setSongSpeedAndSlow(qint64 time) const
{
    m_ui->musiclrccontainerforinline->setSongSpeedAndSlow(time);
}

void MusicRightAreaWidget::musicCheckHasLrcAlready() const
{
    m_downloadStatusLabel->musicCheckHasLrcAlready();
}

void MusicRightAreaWidget::showSettingWidget() const
{
    m_setting->initControllerParameter();
    m_setting->exec();
}

void MusicRightAreaWidget::getParameterSetting() const
{
    setSettingParameter();
    bool config = M_SETTING->value(MusicSettingManager::ShowInlineLrcChoiced).toBool();
    m_ui->musiclrccontainerforinline->setVisible(config);
         config = M_SETTING->value(MusicSettingManager::ShowDesktopLrcChoiced).toBool();
    m_musiclrcfordesktop->setVisible(config);
    m_ui->musicDesktopLrc->setChecked(config);
}

void MusicRightAreaWidget::setDestopLrcVisible(bool v) const
{
    m_ui->musicDesktopLrc->setChecked(v);
    m_musiclrcfordesktop->setVisible(v);
    M_SETTING->setValue(MusicSettingManager::ShowDesktopLrcChoiced, v);
}

void MusicRightAreaWidget::setWindowLockedChanged()
{
    m_musiclrcfordesktop->setWindowLockedChanged();
}

void MusicRightAreaWidget::musicSearchButtonSearched()
{
    QString searchedQString = m_ui->musicSongSearchLine->text().trimmed();
    //The string searched wouldn't allow to be none
    if( !searchedQString.isEmpty() &&
         searchedQString != tr("please input search text") )
    {
        musicButtonStyleClear();
        m_ui->musicSearchWidgetButton->setStyleSheet(MusicUIObject::MPushButtonStyle16);
        m_ui->SurfaceStackedWidget->setCurrentIndex(1);
        createVideoWidget(false);
        m_ui->songSearchWidget->startSearchQuery(searchedQString);
    }
    else
    {
        MusicMessageBox message;
        message.setText(tr("please input search text"));
        message.exec();
    }
}

void MusicRightAreaWidget::musicResearchButtonSearched(const QString &name)
{
    m_ui->musicSongSearchLine->setText(name);
    musicSearchButtonSearched();
}

void MusicRightAreaWidget::musicIndexWidgetButtonSearched()
{
    musicButtonStyleClear();
    m_ui->musicIndexWidgetButton->setStyleSheet(MusicUIObject::MPushButtonStyle16);
    //Show the first index of widget
    m_ui->SurfaceStackedWidget->setCurrentIndex(0);
    createVideoWidget(false);
}

void MusicRightAreaWidget::musicSearchWidgetButtonSearched()
{
    musicButtonStyleClear();
    m_ui->musicSearchWidgetButton->setStyleSheet(MusicUIObject::MPushButtonStyle16);
    //Show searched song lists
    m_ui->SurfaceStackedWidget->setCurrentIndex(1);
    createVideoWidget(false);
}

void MusicRightAreaWidget::musicLrcWidgetButtonSearched()
{
    musicButtonStyleClear();
    m_ui->musicLrcWidgetButton->setStyleSheet(MusicUIObject::MPushButtonStyle16);
    //Show lrc display widget
    m_ui->SurfaceStackedWidget->setCurrentIndex(2);
    createVideoWidget(false);
    emit updateBgThemeDownload();
}

void MusicRightAreaWidget::musicVideoWidgetButtonSearched()
{
    musicButtonStyleClear();
    m_ui->vedioWidgetButton->setStyleSheet(MusicUIObject::MPushButtonStyle16);
    createVideoWidget(true);
}

void MusicRightAreaWidget::musicSearchRefreshButtonRefreshed()
{
    createVideoWidget(false);
    //Refresh the search music song
    musicSearchButtonSearched();
}

void MusicRightAreaWidget::createVideoWidget(bool create)
{
    if(create)
    {
        if(m_videoPlayer)
        {
            return;
        }
        delete m_videoPlayer;
        m_videoPlayer = new MusicVideoPlayer(false);
        m_videoPlayer->blockMoveOption(true);
        m_ui->SurfaceStackedWidget->addWidget(m_videoPlayer);
        m_ui->SurfaceStackedWidget->setCurrentIndex(3);
    }
    else if(m_videoPlayer)
    {
        m_ui->SurfaceStackedWidget->removeWidget(m_videoPlayer);
        delete m_videoPlayer;
        m_videoPlayer = NULL;
    }
    emit updateBackgroundTheme();
}

void MusicRightAreaWidget::musicButtonStyleClear()
{
    m_ui->musicIndexWidgetButton->setStyleSheet(MusicUIObject::MPushButtonStyle07);
    m_ui->musicSearchWidgetButton->setStyleSheet(MusicUIObject::MPushButtonStyle07);
    m_ui->musicLrcWidgetButton->setStyleSheet(MusicUIObject::MPushButtonStyle07);
    m_ui->vedioWidgetButton->setStyleSheet(MusicUIObject::MPushButtonStyle07);
}

void MusicRightAreaWidget::musicVideoButtonSearched(const QString &name)
{
    musicVideoWidgetButtonSearched();
    if(m_videoPlayer)
    {
        m_videoPlayer->musicResearchButtonSearched(name);
    }
}

void MusicRightAreaWidget::musicVideoSetPopup(bool popup)
{
    if(popup)
    {
        createVideoWidget(false);
        musicButtonStyleClear();
        m_ui->vedioWidgetButton->setStyleSheet(MusicUIObject::MPushButtonStyle16);
        m_videoPlayer = new MusicVideoPlayer(true);
        m_videoPlayer->show();
    }
    else
    {
        createVideoWidget(false);
        createVideoWidget(true);
    }
}

void MusicRightAreaWidget::musicVideoFullscreen(bool full)
{
    m_videoPlayer->resizeWindow(full);
}
<commit_msg>block move option when the video widget is fullscreen mode[031656]<commit_after>#include "musicrightareawidget.h"
#include "ui_musicapplication.h"
#include "musicuiobject.h"
#include "musiclrccontainerfordesktop.h"
#include "musicvideoplayer.h"
#include "musicdownloadstatuslabel.h"
#include "musicsettingwidget.h"
#include "musicmessagebox.h"
#include "musicconnectionpool.h"

MusicRightAreaWidget::MusicRightAreaWidget(QWidget *parent)
    : QWidget(parent), m_videoPlayer(NULL)
{
    m_supperClass = parent;
    m_musiclrcfordesktop = new MusicLrcContainerForDesktop(parent);
    m_downloadStatusLabel = new MusicDownloadStatusLabel(parent);
    m_setting = new MusicSettingWidget(this);
    connect(m_setting, SIGNAL(parameterSettingChanged()), parent,
                       SLOT(getParameterSetting()));

    M_Connection->setValue("MusicRightAreaWidget", this);
    M_Connection->connect("MusicSongSearchOnlineTableWidget",
                          "MusicRightAreaWidget");
}

MusicRightAreaWidget::~MusicRightAreaWidget()
{
    delete m_setting;
    delete m_videoPlayer;
    delete m_downloadStatusLabel;
    delete m_musiclrcfordesktop;
}

void MusicRightAreaWidget::setupUi(Ui::MusicApplication* ui)
{
    m_ui = ui;
    m_downloadStatusLabel->setMovieLabel(m_ui->showDownloadGif);

    ui->musicSearchRefreshButton->setCursor(QCursor(Qt::PointingHandCursor));
    ui->musicSearchRefreshButton->setStyleSheet(MusicUIObject::MPushButtonStyle07);
    ui->musicSearchRefreshButton->setIconSize(QSize(25,25));
    ui->musicSearchRefreshButton->setIcon(QIcon(QString::fromUtf8(":/image/flash")));
    connect(ui->musicSearchRefreshButton,SIGNAL(clicked()), SLOT(musicSearchRefreshButtonRefreshed()));

    ui->musicIndexWidgetButton->setCursor(QCursor(Qt::PointingHandCursor));
    ui->musicIndexWidgetButton->setStyleSheet(MusicUIObject::MPushButtonStyle16);
    connect(ui->musicIndexWidgetButton,SIGNAL(clicked()), SLOT(musicIndexWidgetButtonSearched()));

    ui->musicSearchWidgetButton->setCursor(QCursor(Qt::PointingHandCursor));
    ui->musicSearchWidgetButton->setStyleSheet(MusicUIObject::MPushButtonStyle07);
    connect(ui->musicSearchWidgetButton,SIGNAL(clicked()), SLOT(musicSearchWidgetButtonSearched()));

    ui->musicLrcWidgetButton->setCursor(QCursor(Qt::PointingHandCursor));
    ui->musicLrcWidgetButton->setStyleSheet(MusicUIObject::MPushButtonStyle07);
    connect(ui->musicLrcWidgetButton,SIGNAL(clicked()), SLOT(musicLrcWidgetButtonSearched()));

    ui->vedioWidgetButton->setCursor(QCursor(Qt::PointingHandCursor));
    ui->vedioWidgetButton->setStyleSheet(MusicUIObject::MPushButtonStyle07);
    connect(ui->vedioWidgetButton,SIGNAL(clicked()), SLOT(musicVideoWidgetButtonSearched()));
    ///////////////////////////////////////////////////////
    connect(m_musiclrcfordesktop,SIGNAL(theCurrentLrcUpdated()), m_supperClass,
                 SLOT(musicCurrentLrcUpdated()));
    connect(m_musiclrcfordesktop,SIGNAL(changeCurrentLrcColorSetting()), m_supperClass,
                 SLOT(musicSetting()));
    connect(m_musiclrcfordesktop,SIGNAL(changeCurrentLrcColorCustom()), m_setting,
                 SLOT(changeDesktopLrcWidget()));
    connect(m_musiclrcfordesktop,SIGNAL(desktopLrcClosed()), SIGNAL(desktopLrcClosed()));
    connect(m_musiclrcfordesktop,SIGNAL(setWindowLockedChanged(bool)), SIGNAL(lockDesktopLrc(bool)));
    ///////////////////////////////////////////////////////
    connect(ui->musiclrccontainerforinline,SIGNAL(changeCurrentLrcColorCustom()), m_setting,
                 SLOT(changeInlineLrcWidget()));
    connect(ui->musiclrccontainerforinline,SIGNAL(theCurrentLrcUpdated()), m_supperClass,
                 SLOT(musicCurrentLrcUpdated()));
    connect(ui->musiclrccontainerforinline, SIGNAL(theArtBgHasChanged()),
                 SIGNAL(updateBgThemeDownload()));
    connect(ui->musiclrccontainerforinline,SIGNAL(changeCurrentLrcColorSetting()), m_supperClass,
                 SLOT(musicSetting()));
    connect(ui->musiclrccontainerforinline,SIGNAL(updateCurrentTime(qint64)), m_supperClass,
                 SLOT(updateCurrentTime(qint64)));
    ///////////////////////////////////////////////////////
}

void MusicRightAreaWidget::stopLrcMask() const
{
    if( checkSettingParameterValue() )
    {
       m_ui->musiclrccontainerforinline->stopLrcMask();
       m_musiclrcfordesktop->stopLrcMask();
    }
}

void MusicRightAreaWidget::startTimerClock() const
{
    if( checkSettingParameterValue() )
    {
       m_ui->musiclrccontainerforinline->startTimerClock();
       m_musiclrcfordesktop->startTimerClock();
    }
}

void MusicRightAreaWidget::showPlayStatus(bool status) const
{
    m_musiclrcfordesktop->showPlayStatus(status);
}

void MusicRightAreaWidget::setDestopLrcVisible(const QString &status) const
{
    setDestopLrcVisible( status == "true" ? true : false);
}

bool MusicRightAreaWidget::getDestopLrcVisible() const
{
    return m_musiclrcfordesktop->isVisible();
}

void MusicRightAreaWidget::setInlineLrcVisible(const QString &status) const
{
    m_ui->musiclrccontainerforinline->setVisible(status == "true" ? true : false);
}

void MusicRightAreaWidget::setSettingParameter() const
{
    m_musiclrcfordesktop->setSettingParameter();
    m_ui->musiclrccontainerforinline->setSettingParameter();
}

bool MusicRightAreaWidget::checkSettingParameterValue() const
{
    return ( M_SETTING->value(MusicSettingManager::ShowInlineLrcChoiced).toBool() ||
             M_SETTING->value(MusicSettingManager::ShowDesktopLrcChoiced).toBool() )
             ? true : false;
}

void MusicRightAreaWidget::updateCurrentLrc(qint64 current, qint64 total, bool playStatus) const
{
    m_ui->musiclrccontainerforinline->setCurrentPosition(current);
    //Direct access to the audio file is the total time, in milliseconds
    MIntStringMap lrcContainer(m_ui->musiclrccontainerforinline->getLrcContainer());
    //The corresponding access to current time lyrics
    if(!lrcContainer.isEmpty())
    {
        //After get the current time in the lyrics of the two time points
        qint64 previous = 0;
        qint64 later = 0;
        //Keys () method returns a list of lrcContainer
        foreach (qint64 value, lrcContainer.keys())
        {
            if(current >= value)
            {
                previous = value;
            }
            else
            {
                later = value;
                break;
            }
        }
        //To the last line, set the later to song total time value
        if(later == 0)
        {
            later = total;
        }
        //The lyrics content corresponds to obtain the current time
        QString currentLrc = lrcContainer.value(previous);
        QString laterLrc = lrcContainer.value(later);
        //If this is a new line of the lyrics, then restart lyrics display mask
        if(currentLrc != m_ui->musiclrccontainerforinline->text())
        {
            qint64 intervalTime = later - previous;
            if(!playStatus)
            {
                m_ui->musiclrccontainerforinline->updateCurrentLrc(intervalTime);
            }
            m_musiclrcfordesktop->updateCurrentLrc(currentLrc, laterLrc, intervalTime);
        }
    }
}

void MusicRightAreaWidget::loadCurrentSongLrc(const QString &name, const QString &path) const
{
    if( checkSettingParameterValue() )
    {
        m_ui->musiclrccontainerforinline->stopLrcMask();
        m_ui->musiclrccontainerforinline->setCurrentSongName( name );
        m_ui->musiclrccontainerforinline->transLrcFileToTime( path.trimmed() );
        m_musiclrcfordesktop->setCurrentSongName( name );
        m_musiclrcfordesktop->initCurrentLrc();
    }
}

void MusicRightAreaWidget::setSongSpeedAndSlow(qint64 time) const
{
    m_ui->musiclrccontainerforinline->setSongSpeedAndSlow(time);
}

void MusicRightAreaWidget::musicCheckHasLrcAlready() const
{
    m_downloadStatusLabel->musicCheckHasLrcAlready();
}

void MusicRightAreaWidget::showSettingWidget() const
{
    m_setting->initControllerParameter();
    m_setting->exec();
}

void MusicRightAreaWidget::getParameterSetting() const
{
    setSettingParameter();
    bool config = M_SETTING->value(MusicSettingManager::ShowInlineLrcChoiced).toBool();
    m_ui->musiclrccontainerforinline->setVisible(config);
         config = M_SETTING->value(MusicSettingManager::ShowDesktopLrcChoiced).toBool();
    m_musiclrcfordesktop->setVisible(config);
    m_ui->musicDesktopLrc->setChecked(config);
}

void MusicRightAreaWidget::setDestopLrcVisible(bool v) const
{
    m_ui->musicDesktopLrc->setChecked(v);
    m_musiclrcfordesktop->setVisible(v);
    M_SETTING->setValue(MusicSettingManager::ShowDesktopLrcChoiced, v);
}

void MusicRightAreaWidget::setWindowLockedChanged()
{
    m_musiclrcfordesktop->setWindowLockedChanged();
}

void MusicRightAreaWidget::musicSearchButtonSearched()
{
    QString searchedQString = m_ui->musicSongSearchLine->text().trimmed();
    //The string searched wouldn't allow to be none
    if( !searchedQString.isEmpty() &&
         searchedQString != tr("please input search text") )
    {
        musicButtonStyleClear();
        m_ui->musicSearchWidgetButton->setStyleSheet(MusicUIObject::MPushButtonStyle16);
        m_ui->SurfaceStackedWidget->setCurrentIndex(1);
        createVideoWidget(false);
        m_ui->songSearchWidget->startSearchQuery(searchedQString);
    }
    else
    {
        MusicMessageBox message;
        message.setText(tr("please input search text"));
        message.exec();
    }
}

void MusicRightAreaWidget::musicResearchButtonSearched(const QString &name)
{
    m_ui->musicSongSearchLine->setText(name);
    musicSearchButtonSearched();
}

void MusicRightAreaWidget::musicIndexWidgetButtonSearched()
{
    musicButtonStyleClear();
    m_ui->musicIndexWidgetButton->setStyleSheet(MusicUIObject::MPushButtonStyle16);
    //Show the first index of widget
    m_ui->SurfaceStackedWidget->setCurrentIndex(0);
    createVideoWidget(false);
}

void MusicRightAreaWidget::musicSearchWidgetButtonSearched()
{
    musicButtonStyleClear();
    m_ui->musicSearchWidgetButton->setStyleSheet(MusicUIObject::MPushButtonStyle16);
    //Show searched song lists
    m_ui->SurfaceStackedWidget->setCurrentIndex(1);
    createVideoWidget(false);
}

void MusicRightAreaWidget::musicLrcWidgetButtonSearched()
{
    musicButtonStyleClear();
    m_ui->musicLrcWidgetButton->setStyleSheet(MusicUIObject::MPushButtonStyle16);
    //Show lrc display widget
    m_ui->SurfaceStackedWidget->setCurrentIndex(2);
    createVideoWidget(false);
    emit updateBgThemeDownload();
}

void MusicRightAreaWidget::musicVideoWidgetButtonSearched()
{
    musicButtonStyleClear();
    m_ui->vedioWidgetButton->setStyleSheet(MusicUIObject::MPushButtonStyle16);
    createVideoWidget(true);
}

void MusicRightAreaWidget::musicSearchRefreshButtonRefreshed()
{
    createVideoWidget(false);
    //Refresh the search music song
    musicSearchButtonSearched();
}

void MusicRightAreaWidget::createVideoWidget(bool create)
{
    if(create)
    {
        if(m_videoPlayer)
        {
            return;
        }
        delete m_videoPlayer;
        m_videoPlayer = new MusicVideoPlayer(false);
        m_videoPlayer->blockMoveOption(true);
        m_ui->SurfaceStackedWidget->addWidget(m_videoPlayer);
        m_ui->SurfaceStackedWidget->setCurrentIndex(3);
    }
    else if(m_videoPlayer)
    {
        m_ui->SurfaceStackedWidget->removeWidget(m_videoPlayer);
        delete m_videoPlayer;
        m_videoPlayer = NULL;
    }
    emit updateBackgroundTheme();
}

void MusicRightAreaWidget::musicButtonStyleClear()
{
    m_ui->musicIndexWidgetButton->setStyleSheet(MusicUIObject::MPushButtonStyle07);
    m_ui->musicSearchWidgetButton->setStyleSheet(MusicUIObject::MPushButtonStyle07);
    m_ui->musicLrcWidgetButton->setStyleSheet(MusicUIObject::MPushButtonStyle07);
    m_ui->vedioWidgetButton->setStyleSheet(MusicUIObject::MPushButtonStyle07);
}

void MusicRightAreaWidget::musicVideoButtonSearched(const QString &name)
{
    musicVideoWidgetButtonSearched();
    if(m_videoPlayer)
    {
        m_videoPlayer->musicResearchButtonSearched(name);
    }
}

void MusicRightAreaWidget::musicVideoSetPopup(bool popup)
{
    if(popup)
    {
        createVideoWidget(false);
        musicButtonStyleClear();
        m_ui->vedioWidgetButton->setStyleSheet(MusicUIObject::MPushButtonStyle16);
        m_videoPlayer = new MusicVideoPlayer(true);
        m_videoPlayer->show();
    }
    else
    {
        createVideoWidget(false);
        createVideoWidget(true);
    }
}

void MusicRightAreaWidget::musicVideoFullscreen(bool full)
{
    m_videoPlayer->resizeWindow(full);
    m_videoPlayer->blockMoveOption(full);
}
<|endoftext|>


<commit_before>#include "barcode/ImporterMenu.hpp"

ImporterMenu::ImporterMenu()
{
	this->executableDir = "";
	this->root = nullptr;
}
ImporterMenu::ImporterMenu(Hydra::World::IWorld* world)
{
	this->executableDir = _getExecutableDir();
	this->root = nullptr;
	this->_world = world;
	refresh();
}
ImporterMenu::~ImporterMenu()
{
	if(root != nullptr)
	delete root;
}
void ImporterMenu::render(bool &closeBool)
{
	ImGui::SetNextWindowSize(ImVec2(480, 640), ImGuiSetCond_Once);
	ImGui::Begin("Static model", &closeBool);
	if(root != nullptr)
	root->render(0, _world);
	ImGui::End();
}
void ImporterMenu::refresh()
{
	if (root != nullptr)
	{
		delete root;
	}
	root = new Node(executableDir + "/assets");
	root->clean();
}

std::string ImporterMenu::_getExecutableDir()
{
	std::string path;
#ifdef _WIN32
	char unicodePath[MAX_PATH];
	int bytes = GetModuleFileName(NULL, unicodePath, 500);
#else
	char unicodePath[1000];
	char tempStr[32];
	sprintf(tempStr, "/proc/%d/exe", getpid());
	int bytes = std::min((int)readlink(tempStr, unicodePath, 500), 500 - 1);
	if (bytes >= 0)
		unicodePath[bytes] = '\0';
#endif
	if (bytes == 0)
		return "/";
	else
		path = std::string(unicodePath);
		std::replace(path.begin(), path.end(), '\\', '/');
		int index = path.find_last_of('/');
		path.erase(path.begin() + index, path.end());
	return path;
}
ImporterMenu::Node::Node()
{
	this->_name = "";
	this->subfolders = std::vector<Node*>(0);
	this->files = std::vector<Node*>(0);
	this->parent = nullptr;
}
ImporterMenu::Node::Node(std::string path, Node* parent, bool isFile)
{
	this->_name = pathToName(path);
	this->subfolders = std::vector<Node*>();
	this->files = std::vector<Node*>();
	this->parent = parent;
	this->isAllowedFile = isFile;

	std::vector<std::string> inFiles;
	std::vector<std::string> inFolders;
	_getContentsOfDir(path, inFiles, inFolders);
	for (int i = 0; i < inFolders.size(); i++)
	{
		this->subfolders.push_back(new Node(inFolders[i], this));
	}
	for (int i = 0; i < inFiles.size(); i++)
	{
		this->files.push_back(new Node(inFiles[i], this));
	}
}
ImporterMenu::Node::~Node()
{
	for (int i = 0; i < subfolders.size(); i++)
	{
		delete subfolders[i];
	}
	subfolders.clear();
	for (int i = 0; i < files.size(); i++)
	{
		delete files[i];
	}
	files.clear();
}
std::string ImporterMenu::Node::name()
{
	return _name;
}
std::string ImporterMenu::Node::pathToName(std::string path)
{
	unsigned int i = path.find_last_of('/');
	if (i == std::string::npos)
	{
		return path;
	}
	else
	{
		return path.substr(i + 1);
	}
}
std::string ImporterMenu::Node::reverseEngineerPath()
{
	std::string upperPath = "";
	if (this->parent != nullptr)
	{
		upperPath = parent->reverseEngineerPath();
		return upperPath + "/" + this->_name;
	}
	return this->_name;
}
//Returns all files in this folder and subfolders
int ImporterMenu::Node::numberOfFiles()
{
	if (!isAllowedFile)
	{
		int allFiles = files.size();
		for (int i = 0; i < subfolders.size(); i++)
		{
			allFiles += subfolders[i]->numberOfFiles();
		}
		return allFiles;
	}
	return -1;
}
//Removes all folders that do not have any files
void ImporterMenu::Node::clean()
{
	for (int i = 0; i < subfolders.size(); i++)
	{
		if (subfolders[i]->numberOfFiles() == 0)
		{
			delete subfolders[i];
			subfolders.erase(subfolders.begin() + i);
			i--;
		}
		else
		{
			subfolders[i]->clean();
		}
	}
}
void ImporterMenu::Node::render(int index, Hydra::World::IWorld* world)
{
	ImGuiTreeNodeFlags node_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick;
	//TODO: Folder icon opening
	if (ImGui::TreeNodeEx((void*)(intptr_t)index, node_flags, ICON_FA_FOLDER " %s", _name.c_str()))
	{
		for (int i = 0; i < this->subfolders.size(); i++)
		{
			subfolders[i]->render(i, world);
		}
		for (int i = 0; i < this->files.size(); i++)
		{
			if (ImGui::TreeNodeEx(files[i], node_flags | ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen, ICON_FA_CUBE " %s", files[i]->_name.c_str()))
			{
				if (ImGui::IsItemClicked() && ImGui::IsMouseDoubleClicked(0))
				{
					Hydra::World::IEntity* newEntity = world->createEntity(files[i]->name()).get();
					newEntity->addComponent<Hydra::Component::MeshComponent>(files[i]->reverseEngineerPath());
					newEntity->addComponent<Hydra::Component::TransformComponent>(glm::vec3(0, 0, 0));
				}
			}
		}
		ImGui::TreePop();
	}
}
void ImporterMenu::Node::_getContentsOfDir(const std::string &directory, std::vector<std::string> &files, std::vector<std::string> &folders) const
{
#ifdef _WIN32 ///Windows
	HANDLE dir;
	WIN32_FIND_DATA fileData;

	if ((dir = FindFirstFile((directory + "/*").c_str(), &fileData)) == INVALID_HANDLE_VALUE)
	{
		//No files found or is not directory
		files.empty();
		folders.empty();
		return;
	}
	do
	{
		const std::string fileName = fileData.cFileName;
		const std::string fullFilePath = directory + "/" + fileName;
		const bool is_directory = (fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;

		if (fileName[0] == '.')
		{
			//files.push_back(fullFileName);
		}
		else if (is_directory)
		{
			folders.push_back(fullFilePath);
		}
		else
		{
			int i = fileName.find_last_of('.');
			std::string fileExt = fileName.substr(i, fileName.size() - i);
			if (fileExt == ".ATTIC")
			{
				files.push_back(fullFilePath);
			}
		}
	}
	while (FindNextFile(dir, &fileData));

	FindClose(dir);
#else ///Unix
	DIR *dir;
	class dirent *ent;
	class stat st;

	dir = opendir(directory.c_str());
	while ((ent = readdir(dir)) != NULL)
	{
		const std::string fileName = ent->d_name;
		const std::string fullFileName = directory + "/" + fileName;

		if (fileName[0] == '.')
		{

		}
		else if(stat(fullFileName.c_str(), &st) != -1)
		{
			const bool isDir = (st.st_mode & S_IFDIR) != 0;
			if (isDir)
			{
				folders.push_back(fullFileName);
			}
			else
			{
				files.push_back(fullFileName);
			}
		}
	}
	closedir(dir);
#endif
}
<commit_msg>Show JSON files in Importer<commit_after>#include "barcode/ImporterMenu.hpp"

ImporterMenu::ImporterMenu()
{
	this->executableDir = "";
	this->root = nullptr;
}
ImporterMenu::ImporterMenu(Hydra::World::IWorld* world)
{
	this->executableDir = _getExecutableDir();
	this->root = nullptr;
	this->_world = world;
	refresh();
}
ImporterMenu::~ImporterMenu()
{
	if(root != nullptr)
	delete root;
}
void ImporterMenu::render(bool &closeBool)
{
	ImGui::SetNextWindowSize(ImVec2(480, 640), ImGuiSetCond_Once);
	ImGui::Begin("Static model", &closeBool);
	if(root != nullptr)
	root->render(0, _world);
	ImGui::End();
}
void ImporterMenu::refresh()
{
	if (root != nullptr)
	{
		delete root;
	}
	root = new Node(executableDir + "/assets");
	root->clean();
}

std::string ImporterMenu::_getExecutableDir()
{
	std::string path;
#ifdef _WIN32
	char unicodePath[MAX_PATH];
	int bytes = GetModuleFileName(NULL, unicodePath, 500);
#else
	char unicodePath[1000];
	char tempStr[32];
	sprintf(tempStr, "/proc/%d/exe", getpid());
	int bytes = std::min((int)readlink(tempStr, unicodePath, 500), 500 - 1);
	if (bytes >= 0)
		unicodePath[bytes] = '\0';
#endif
	if (bytes == 0)
		return "/";
	else
		path = std::string(unicodePath);
		std::replace(path.begin(), path.end(), '\\', '/');
		int index = path.find_last_of('/');
		path.erase(path.begin() + index, path.end());
	return path;
}
ImporterMenu::Node::Node()
{
	this->_name = "";
	this->subfolders = std::vector<Node*>(0);
	this->files = std::vector<Node*>(0);
	this->parent = nullptr;
}
ImporterMenu::Node::Node(std::string path, Node* parent, bool isFile)
{
	this->_name = pathToName(path);
	this->subfolders = std::vector<Node*>();
	this->files = std::vector<Node*>();
	this->parent = parent;
	this->isAllowedFile = isFile;

	std::vector<std::string> inFiles;
	std::vector<std::string> inFolders;
	_getContentsOfDir(path, inFiles, inFolders);
	for (int i = 0; i < inFolders.size(); i++)
	{
		this->subfolders.push_back(new Node(inFolders[i], this));
	}
	for (int i = 0; i < inFiles.size(); i++)
	{
		this->files.push_back(new Node(inFiles[i], this));
	}
}
ImporterMenu::Node::~Node()
{
	for (int i = 0; i < subfolders.size(); i++)
	{
		delete subfolders[i];
	}
	subfolders.clear();
	for (int i = 0; i < files.size(); i++)
	{
		delete files[i];
	}
	files.clear();
}
std::string ImporterMenu::Node::name()
{
	return _name;
}
std::string ImporterMenu::Node::pathToName(std::string path)
{
	unsigned int i = path.find_last_of('/');
	if (i == std::string::npos)
	{
		return path;
	}
	else
	{
		return path.substr(i + 1);
	}
}
std::string ImporterMenu::Node::reverseEngineerPath()
{
	std::string upperPath = "";
	if (this->parent != nullptr)
	{
		upperPath = parent->reverseEngineerPath();
		return upperPath + "/" + this->_name;
	}
	return this->_name;
}
//Returns all files in this folder and subfolders
int ImporterMenu::Node::numberOfFiles()
{
	if (!isAllowedFile)
	{
		int allFiles = files.size();
		for (int i = 0; i < subfolders.size(); i++)
		{
			allFiles += subfolders[i]->numberOfFiles();
		}
		return allFiles;
	}
	return -1;
}
//Removes all folders that do not have any files
void ImporterMenu::Node::clean()
{
	for (int i = 0; i < subfolders.size(); i++)
	{
		if (subfolders[i]->numberOfFiles() == 0)
		{
			delete subfolders[i];
			subfolders.erase(subfolders.begin() + i);
			i--;
		}
		else
		{
			subfolders[i]->clean();
		}
	}
}
void ImporterMenu::Node::render(int index, Hydra::World::IWorld* world)
{
	ImGuiTreeNodeFlags node_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick;
	//TODO: Folder icon opening
	if (ImGui::TreeNodeEx((void*)(intptr_t)index, node_flags, ICON_FA_FOLDER " %s", _name.c_str()))
	{
		for (int i = 0; i < this->subfolders.size(); i++)
		{
			subfolders[i]->render(i, world);
		}
		for (int i = 0; i < this->files.size(); i++)
		{
			if (ImGui::TreeNodeEx(files[i], node_flags | ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen, ICON_FA_CUBE " %s", files[i]->_name.c_str()))
			{
				if (ImGui::IsItemClicked() && ImGui::IsMouseDoubleClicked(0))
				{
					Hydra::World::IEntity* newEntity = world->createEntity(files[i]->name()).get();
					newEntity->addComponent<Hydra::Component::MeshComponent>(files[i]->reverseEngineerPath());
					newEntity->addComponent<Hydra::Component::TransformComponent>(glm::vec3(0, 0, 0));
				}
			}
		}
		ImGui::TreePop();
	}
}
void ImporterMenu::Node::_getContentsOfDir(const std::string &directory, std::vector<std::string> &files, std::vector<std::string> &folders) const
{
#ifdef _WIN32 ///Windows
	HANDLE dir;
	WIN32_FIND_DATA fileData;

	if ((dir = FindFirstFile((directory + "/*").c_str(), &fileData)) == INVALID_HANDLE_VALUE)
	{
		//No files found or is not directory
		files.empty();
		folders.empty();
		return;
	}
	do
	{
		const std::string fileName = fileData.cFileName;
		const std::string fullFilePath = directory + "/" + fileName;
		const bool is_directory = (fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;

		if (fileName[0] == '.')
		{
			//files.push_back(fullFileName);
		}
		else if (is_directory)
		{
			folders.push_back(fullFilePath);
		}
		else
		{
			int i = fileName.find_last_of('.');
			std::string fileExt = fileName.substr(i, fileName.size() - i);
			if (fileExt == ".ATTIC")
			{
				files.push_back(fullFilePath);
			}
			else if (fileExt == ".json")
			{
				files.push_back(fullFilePath);
			}
		}
	}
	while (FindNextFile(dir, &fileData));

	FindClose(dir);
#else ///Unix
	DIR *dir;
	class dirent *ent;
	class stat st;

	dir = opendir(directory.c_str());
	while ((ent = readdir(dir)) != NULL)
	{
		const std::string fileName = ent->d_name;
		const std::string fullFileName = directory + "/" + fileName;

		if (fileName[0] == '.')
		{

		}
		else if(stat(fullFileName.c_str(), &st) != -1)
		{
			const bool isDir = (st.st_mode & S_IFDIR) != 0;
			if (isDir)
			{
				folders.push_back(fullFileName);
			}
			else
			{
				files.push_back(fullFileName);
			}
		}
	}
	closedir(dir);
#endif
}
<|endoftext|>


<commit_before>#include "animation/animation.h"
#include "core/file_system.h"
#include "core/ifile.h"
#include "core/quat.h"
#include "core/vec3.h"
#include "graphics/pose.h"

namespace Lux
{

Resource* AnimationManager::createResource(const Path& path)
{
	return LUX_NEW(Animation)(path, getOwner());
}

void AnimationManager::destroyResource(Resource& resource)
{
	LUX_DELETE(static_cast<Animation*>(&resource));
}

Animation::Animation(const Path& path, ResourceManager& resource_manager)
	: Resource(path, resource_manager)
{
	m_rotations = NULL;
	m_positions = NULL;
	m_frame_count = 0;
}

Animation::~Animation()
{
	LUX_DELETE_ARRAY(m_positions);
	LUX_DELETE_ARRAY(m_rotations);
}

static const float ANIMATION_FPS = 30.0f;

void Animation::getPose(float time, Pose& pose) const
{
	int frame = (int)(time * ANIMATION_FPS);
	frame = frame >= m_frame_count ? m_frame_count - 1 : frame;
	Vec3* pos = pose.getPositions();
	Quat* rot = pose.getRotations();
	int off = frame * m_bone_count;
	int off2 = off + m_bone_count;
	float t = (time - frame / ANIMATION_FPS) / (1 / ANIMATION_FPS);

	if(frame < m_frame_count - 1)
	{
		for(int i = 0; i < m_bone_count; ++i)
		{
			lerp(m_positions[off + i], m_positions[off2 + i], &pos[i], t);
			nlerp(m_rotations[off + i], m_rotations[off2 + i], &rot[i], t);
		}
	}
	else
	{
		for(int i = 0; i < m_bone_count; ++i)
		{
			pos[i] = m_positions[off + i];
			rot[i] = m_rotations[off + i];
		}
	}
}

void Animation::loaded(FS::IFile* file, bool success, FS::FileSystem& fs)
{
	if (success)
	{
		TODO("Add same header to the animation file and check it.");
		LUX_DELETE_ARRAY(m_positions);
		LUX_DELETE_ARRAY(m_rotations);
		file->read(&m_frame_count, sizeof(m_frame_count));
		file->read(&m_bone_count, sizeof(m_bone_count));
		m_positions = LUX_NEW_ARRAY(Vec3, m_frame_count * m_bone_count);
		m_rotations = LUX_NEW_ARRAY(Quat, m_frame_count * m_bone_count);
		for (int i = 0; i < m_frame_count; ++i)
		{
			for (int j = 0; j < m_bone_count; ++j)
			{
				TODO("positions(rotations) in a row");
				file->read(&m_positions[i * m_bone_count + j], sizeof(Vec3));
				file->read(&m_rotations[i * m_bone_count + j], sizeof(Quat));
			}
		}

		m_size = file->size();
		onReady();
	}
	else
	{
		onFailure();
	}

	fs.close(file);
}

void Animation::doUnload(void)
{
	LUX_DELETE_ARRAY(m_positions);
	LUX_DELETE_ARRAY(m_rotations);
	m_rotations = NULL;
	m_positions = NULL;
	m_frame_count = 0;
	m_size = 0;
	onEmpty();
}

FS::ReadCallback Animation::getReadCallback(void)
{
	FS::ReadCallback cb;
	cb.bind<Animation, &Animation::loaded>(this);
	return cb;
}

} // ~namespace Lux
<commit_msg>animation header<commit_after>#include "animation/animation.h"
#include "core/file_system.h"
#include "core/ifile.h"
#include "core/log.h"
#include "core/quat.h"
#include "core/vec3.h"
#include "graphics/pose.h"

namespace Lux
{

static const uint32_t ANIMATION_HEADER_MAGIC = 0x5f4c4146; // '_LAF'

struct AnimationHeader
{
	uint32_t magic;
	uint32_t version;
};

Resource* AnimationManager::createResource(const Path& path)
{
	return LUX_NEW(Animation)(path, getOwner());
}

void AnimationManager::destroyResource(Resource& resource)
{
	LUX_DELETE(static_cast<Animation*>(&resource));
}

Animation::Animation(const Path& path, ResourceManager& resource_manager)
	: Resource(path, resource_manager)
{
	m_rotations = NULL;
	m_positions = NULL;
	m_frame_count = 0;
}

Animation::~Animation()
{
	LUX_DELETE_ARRAY(m_positions);
	LUX_DELETE_ARRAY(m_rotations);
}

static const float ANIMATION_FPS = 30.0f;

void Animation::getPose(float time, Pose& pose) const
{
	int frame = (int)(time * ANIMATION_FPS);
	frame = frame >= m_frame_count ? m_frame_count - 1 : frame;
	Vec3* pos = pose.getPositions();
	Quat* rot = pose.getRotations();
	int off = frame * m_bone_count;
	int off2 = off + m_bone_count;
	float t = (time - frame / ANIMATION_FPS) / (1 / ANIMATION_FPS);

	if(frame < m_frame_count - 1)
	{
		for(int i = 0; i < m_bone_count; ++i)
		{
			lerp(m_positions[off + i], m_positions[off2 + i], &pos[i], t);
			nlerp(m_rotations[off + i], m_rotations[off2 + i], &rot[i], t);
		}
	}
	else
	{
		for(int i = 0; i < m_bone_count; ++i)
		{
			pos[i] = m_positions[off + i];
			rot[i] = m_rotations[off + i];
		}
	}
}

void Animation::loaded(FS::IFile* file, bool success, FS::FileSystem& fs)
{
	if (success)
	{
		LUX_DELETE_ARRAY(m_positions);
		LUX_DELETE_ARRAY(m_rotations);
		m_positions = NULL;
		m_rotations = NULL;
		m_frame_count = m_bone_count = 0;
		AnimationHeader header;
		file->read(&header, sizeof(header));
		if (header.magic != ANIMATION_HEADER_MAGIC)
		{
			onFailure();
			g_log_error.log("animation", "%s is not an animation file", m_path.c_str());
			return;
		}
		if (header.version > 1)
		{
			onFailure();
			g_log_error.log("animation", "Unsupported animation version %d (%s)", header.version, m_path.c_str());
			return;
		}
		file->read(&m_frame_count, sizeof(m_frame_count));
		file->read(&m_bone_count, sizeof(m_bone_count));
		m_positions = LUX_NEW_ARRAY(Vec3, m_frame_count * m_bone_count);
		m_rotations = LUX_NEW_ARRAY(Quat, m_frame_count * m_bone_count);
		for (int i = 0; i < m_frame_count; ++i)
		{
			for (int j = 0; j < m_bone_count; ++j)
			{
				TODO("positions(rotations) in a row");
				file->read(&m_positions[i * m_bone_count + j], sizeof(Vec3));
				file->read(&m_rotations[i * m_bone_count + j], sizeof(Quat));
			}
		}

		m_size = file->size();
		onReady();
	}
	else
	{
		onFailure();
	}

	fs.close(file);
}

void Animation::doUnload(void)
{
	LUX_DELETE_ARRAY(m_positions);
	LUX_DELETE_ARRAY(m_rotations);
	m_rotations = NULL;
	m_positions = NULL;
	m_frame_count = 0;
	m_size = 0;
	onEmpty();
}

FS::ReadCallback Animation::getReadCallback(void)
{
	FS::ReadCallback cb;
	cb.bind<Animation, &Animation::loaded>(this);
	return cb;
}

} // ~namespace Lux
<|endoftext|>


<commit_before>#include "animation/animation.h"
#include "core/fs/file_system.h"
#include "core/fs/ifile.h"
#include "core/log.h"
#include "core/matrix.h"
#include "core/quat.h"
#include "core/vec3.h"
#include "graphics/model.h"
#include "graphics/pose.h"

namespace Lumix
{

static const uint32_t ANIMATION_HEADER_MAGIC = 0x5f4c4146; // '_LAF'

struct AnimationHeader
{
	uint32_t magic;
	uint32_t version;
};

Resource* AnimationManager::createResource(const Path& path)
{
	return LUMIX_NEW(Animation)(path, getOwner());
}

void AnimationManager::destroyResource(Resource& resource)
{
	LUX_DELETE(static_cast<Animation*>(&resource));
}

Animation::Animation(const Path& path, ResourceManager& resource_manager)
	: Resource(path, resource_manager)
{
	m_rotations = NULL;
	m_positions = NULL;
	m_frame_count = 0;
}

Animation::~Animation()
{
	LUX_DELETE_ARRAY(m_positions);
	LUX_DELETE_ARRAY(m_rotations);
}

static const float ANIMATION_FPS = 30.0f;

void Animation::getPose(float time, Pose& pose, Model& model) const
{
	int frame = (int)(time * ANIMATION_FPS);
	frame = frame >= m_frame_count ? m_frame_count - 1 : frame;
	Vec3* pos = pose.getPositions();
	Quat* rot = pose.getRotations();
	int off = frame * m_bone_count;
	int off2 = off + m_bone_count;
	float t = (time - frame / ANIMATION_FPS) / (1 / ANIMATION_FPS);

	if(frame < m_frame_count - 1)
	{
		for(int i = 0; i < m_bone_count; ++i)
		{
			lerp(m_positions[off + i], m_positions[off2 + i], &pos[i], t);
			nlerp(m_rotations[off + i], m_rotations[off2 + i], &rot[i], t);
			int parent = model.getBone(i).parent_idx;
			if (parent >= 0)
			{
				pos[i] = rot[parent] * pos[i] + pos[parent];
				rot[i] = rot[i] * rot[parent];
			}
		}
	}
	else
	{
		for(int i = 0; i < m_bone_count; ++i)
		{
			pos[i] = m_positions[off + i];
			rot[i] = m_rotations[off + i];
			int parent = model.getBone(i).parent_idx;
			if (parent >= 0)
			{
				pos[i] = rot[parent] * pos[i] + pos[parent];
				rot[i] = rot[i] * rot[parent];
			}
		}
	}
}

void Animation::loaded(FS::IFile* file, bool success, FS::FileSystem& fs)
{
	if (success)
	{
		LUX_DELETE_ARRAY(m_positions);
		LUX_DELETE_ARRAY(m_rotations);
		m_positions = NULL;
		m_rotations = NULL;
		m_frame_count = m_bone_count = 0;
		AnimationHeader header;
		file->read(&header, sizeof(header));
		if (header.magic != ANIMATION_HEADER_MAGIC)
		{
			fs.close(file);
			onFailure();
			g_log_error.log("animation", "%s is not an animation file", m_path.c_str());
			return;
		}
		if (header.version > 1)
		{
			fs.close(file);
			onFailure();
			g_log_error.log("animation", "Unsupported animation version %d (%s)", header.version, m_path.c_str());
			return;
		}
		file->read(&m_frame_count, sizeof(m_frame_count));
		file->read(&m_bone_count, sizeof(m_bone_count));

		m_positions = LUMIX_NEW_ARRAY(Vec3, m_frame_count * m_bone_count);
		m_rotations = LUMIX_NEW_ARRAY(Quat, m_frame_count * m_bone_count);
		file->read(&m_positions[0], sizeof(Vec3)* m_bone_count * m_frame_count);
		file->read(&m_rotations[0], sizeof(Quat)* m_bone_count * m_frame_count);

		m_size = file->size();
		decrementDepCount();
	}
	else
	{
		onFailure();
	}

	fs.close(file);
}

void Animation::doUnload(void)
{
	LUX_DELETE_ARRAY(m_positions);
	LUX_DELETE_ARRAY(m_rotations);
	m_rotations = NULL;
	m_positions = NULL;
	m_frame_count = 0;
	m_size = 0;
	onEmpty();
}

FS::ReadCallback Animation::getReadCallback(void)
{
	FS::ReadCallback cb;
	cb.bind<Animation, &Animation::loaded>(this);
	return cb;
}

} // ~namespace Lumix
<commit_msg>fixed crash when a model is reloaded during game mode and an animation is played<commit_after>#include "animation/animation.h"
#include "core/fs/file_system.h"
#include "core/fs/ifile.h"
#include "core/log.h"
#include "core/matrix.h"
#include "core/quat.h"
#include "core/vec3.h"
#include "graphics/model.h"
#include "graphics/pose.h"

namespace Lumix
{

static const uint32_t ANIMATION_HEADER_MAGIC = 0x5f4c4146; // '_LAF'

struct AnimationHeader
{
	uint32_t magic;
	uint32_t version;
};

Resource* AnimationManager::createResource(const Path& path)
{
	return LUMIX_NEW(Animation)(path, getOwner());
}

void AnimationManager::destroyResource(Resource& resource)
{
	LUX_DELETE(static_cast<Animation*>(&resource));
}

Animation::Animation(const Path& path, ResourceManager& resource_manager)
	: Resource(path, resource_manager)
{
	m_rotations = NULL;
	m_positions = NULL;
	m_frame_count = 0;
}

Animation::~Animation()
{
	LUX_DELETE_ARRAY(m_positions);
	LUX_DELETE_ARRAY(m_rotations);
}

static const float ANIMATION_FPS = 30.0f;

void Animation::getPose(float time, Pose& pose, Model& model) const
{
	if(model.isReady())
	{
		int frame = (int)(time * ANIMATION_FPS);
		frame = frame >= m_frame_count ? m_frame_count - 1 : frame;
		Vec3* pos = pose.getPositions();
		Quat* rot = pose.getRotations();
		int off = frame * m_bone_count;
		int off2 = off + m_bone_count;
		float t = (time - frame / ANIMATION_FPS) / (1 / ANIMATION_FPS);

		if(frame < m_frame_count - 1)
		{
			for(int i = 0; i < m_bone_count; ++i)
			{
				lerp(m_positions[off + i], m_positions[off2 + i], &pos[i], t);
				nlerp(m_rotations[off + i], m_rotations[off2 + i], &rot[i], t);
				int parent = model.getBone(i).parent_idx;
				if (parent >= 0)
				{
					pos[i] = rot[parent] * pos[i] + pos[parent];
					rot[i] = rot[i] * rot[parent];
				}
			}
		}
		else
		{
			for(int i = 0; i < m_bone_count; ++i)
			{
				pos[i] = m_positions[off + i];
				rot[i] = m_rotations[off + i];
				int parent = model.getBone(i).parent_idx;
				if (parent >= 0)
				{
					pos[i] = rot[parent] * pos[i] + pos[parent];
					rot[i] = rot[i] * rot[parent];
				}
			}
		}
	}
}

void Animation::loaded(FS::IFile* file, bool success, FS::FileSystem& fs)
{
	if (success)
	{
		LUX_DELETE_ARRAY(m_positions);
		LUX_DELETE_ARRAY(m_rotations);
		m_positions = NULL;
		m_rotations = NULL;
		m_frame_count = m_bone_count = 0;
		AnimationHeader header;
		file->read(&header, sizeof(header));
		if (header.magic != ANIMATION_HEADER_MAGIC)
		{
			fs.close(file);
			onFailure();
			g_log_error.log("animation", "%s is not an animation file", m_path.c_str());
			return;
		}
		if (header.version > 1)
		{
			fs.close(file);
			onFailure();
			g_log_error.log("animation", "Unsupported animation version %d (%s)", header.version, m_path.c_str());
			return;
		}
		file->read(&m_frame_count, sizeof(m_frame_count));
		file->read(&m_bone_count, sizeof(m_bone_count));

		m_positions = LUMIX_NEW_ARRAY(Vec3, m_frame_count * m_bone_count);
		m_rotations = LUMIX_NEW_ARRAY(Quat, m_frame_count * m_bone_count);
		file->read(&m_positions[0], sizeof(Vec3)* m_bone_count * m_frame_count);
		file->read(&m_rotations[0], sizeof(Quat)* m_bone_count * m_frame_count);

		m_size = file->size();
		decrementDepCount();
	}
	else
	{
		onFailure();
	}

	fs.close(file);
}

void Animation::doUnload(void)
{
	LUX_DELETE_ARRAY(m_positions);
	LUX_DELETE_ARRAY(m_rotations);
	m_rotations = NULL;
	m_positions = NULL;
	m_frame_count = 0;
	m_size = 0;
	onEmpty();
}

FS::ReadCallback Animation::getReadCallback(void)
{
	FS::ReadCallback cb;
	cb.bind<Animation, &Animation::loaded>(this);
	return cb;
}

} // ~namespace Lumix
<|endoftext|>


<commit_before>#include "FreeRTOSConfig.h"
#include "os/OS.hxx"

#include "stm32f10x.h"

#include "stm32f10x_gpio.h"
#include "stm32f10x_rcc.h"
#include "misc.h"

extern "C" {

extern void Reset_Handler(void);
extern void __libc_init_array(void);
extern int main(void);
extern void SystemInit(void);

extern uint32_t __start_ram;
extern uint32_t __end_ram;

extern uint32_t __data_start__;
extern uint32_t __data_end__;
extern uint32_t __data_init_start__;

extern uint32_t __bss_start__;
extern uint32_t __bss_end__;

void setup_blinker();
void setup_nvic();

void __attribute__((naked)) Reset_Handler(void) {
    // Takes care of hardware responses from the bootloader not showing up
    // anymore.
    __disable_irq();
    // Resets USB module
    RCC_APB2PeriphResetCmd(RCC_APB1Periph_USB, ENABLE);
    for (volatile int i = 0; i < 10; ++i);
    RCC_APB2PeriphResetCmd(RCC_APB1Periph_USB, DISABLE);
    RCC_APB2PeriphClockCmd(RCC_APB1Periph_USB, DISABLE);

    // Fills the memory with a debug pattern.
    for (uint32_t* d = &__start_ram; d < &__end_ram; ++d)
    {
        *d = 0xdbdbdbdb;
    }

    // Clears BSS
    for (uint32_t* d = &__bss_start__; d < &__bss_end__; ++d) {
        *d = 0;
    }

    // Copies initialized data from flash to RAM
    uint32_t* s = &__data_init_start__;
    for (uint32_t* d = &__data_start__; d < &__data_end__; ++d, ++s) {
        *d = *s;
    }

    // Sets up system clock.
    SystemInit();

    setup_nvic();
    setup_blinker();

    // Calls global constructors.
    __libc_init_array();
    main();
    while(1);
}

void setup_nvic() {
    extern uint32_t g_pfnVectors;
    SCB->VTOR = (uint32_t)&g_pfnVectors;
    // 4 bits of interrupt priority, 0 bits for subpriority.
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
    // Clears external and internal interrupt masks and software interrupt
    // request bits.
    EXTI->IMR = 0;
    EXTI->EMR = 0;
    EXTI->SWIER = 0;
    // Clears all NVIC interrupt enable and pending bits.
    for (unsigned i = 0; i < sizeof(NVIC->ICER) / sizeof(NVIC->ICER[0]); ++i) {
        NVIC->ICER[i] = NVIC_ICER_CLRENA;
        NVIC->ICPR[i] = NVIC_ICPR_CLRPEND;
    }
}

void setup_blinker() {
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

    GPIO_InitTypeDef gp;
    GPIO_StructInit(&gp);

    gp.GPIO_Pin = (1<<1) | (1<<5);
    gp.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(GPIOA, &gp);

    GPIOA->BSRR = (1<<1) | (1<<5); // Turns on both leds.
}

void setblink(uint32_t pattern);

const unsigned long cm3_cpu_clock_hz = 72000000;

void hw_init(void)
{
    // This is needed for proper bootup of the FreeRTOS scheduler.
    __disable_irq();
}

uint32_t blinker_pattern;
uint32_t current_pattern;
#define BLINK_GPIO GPIOA
#define BLINK_BIT 5

extern "C" {
extern void vPortClearInterruptMask( unsigned long ulNewMaskValue );
extern unsigned long ulPortSetInterruptMask( void );
}

void enable_fiq_only(void)
{
    /** @TODO(balazs.racz): we should call vPortClearInterruptMask(14) here,
     * assuming the blink-timer interrupt is set to priority 15. The code here
     * will block all FreeRTOS functions though. */
    ulPortSetInterruptMask();
    __enable_irq();
}

void diewith(unsigned long);

void Default_Handler() {
    diewith(BLINK_DIE_UNEXPIRQ);
}

/** Initializes the timer responsible for the blinking hardware and sets
 *   initial pattern.
 *
 *  \param pattern is a blinking pattern, each bit will be shifted to the
 *  output LED every 125 ms.
 */
void setblink(uint32_t pattern)
{
    GPIOA->BSRR = pattern ? (1<<17) : (1<<1);
    //gpio_write_bit(ERROR_LED_PORT, ERROR_LED_PIN, );
/*    blinker_pattern = pattern;
    current_pattern = 0;
    BLINK_GPIO->FIODIR |= BLINK_BIT;
    BLINK_GPIO->FIOCLR = BLINK_BIT;

    // clock = raw clock
    LPC_SC->PCLKSEL0 = (LPC_SC->PCLKSEL0 & (~(0x3 << 4))) | (0x01 << 4);
    LPC_TIM1->TCR = 2;  // stop & reset timer
    LPC_TIM1->CTCR = 0; // timer mode
    // prescale to 1 ms per tick
    LPC_TIM1->PR = configCPU_CLOCK_HZ / 1000;
    LPC_TIM1->MR0 = 125;
    LPC_TIM1->MCR = 3; // reset and interrupt on match 0

    NVIC_SetPriority(TIMER1_IRQn, 0);
    NVIC_EnableIRQ(TIMER1_IRQn);

    LPC_TIM1->TCR = 1; // Timer go.*/
}

/** Updates the blinking pattern.
 *
 *  \param pattern is a blinking pattern, each bit will be shifted to the
 *  output LED every 125 ms.
 */
void resetblink(uint32_t pattern)
{
    blinker_pattern = pattern;
    setblink(pattern);
    // Makes a timer event trigger immediately.
    //LPC_TIM1->TC = LPC_TIM1->MR0 - 2;
}

/** Aborts the program execution and sets a particular blinking pattern.
 *
 *  \param pattern is a blinking pattern, each bit will be shifted to the
 *  output LED every 125 ms.
 *
 *  Never returns.
 */
void diewith(unsigned long pattern)
{
    __disable_irq();
    while(1) {
        GPIOA->BSRR = current_pattern & 1 ? ((1<<5)|(1<<1)) : ((1<<5)|(1<<1)) << 16;
        current_pattern >>= 1;
        if (!current_pattern)
        {
            current_pattern = pattern;
        }
        for (volatile int i = 0; i < 450000; i++);
    }

    enable_fiq_only();
    setblink(pattern);
    for (;;)
    {
    }
}

void TIMER1_IRQHandler(void)
{
    if (current_pattern & 1)
    {
//        BLINK_GPIO->FIOSET = BLINK_BIT;
    }
    else
    {
//     BLINK_GPIO->FIOCLR = BLINK_BIT;
    }
    current_pattern >>= 1;
    if (!current_pattern)
    {
        current_pattern = blinker_pattern;
    }

    // Clears IRQ.
//    LPC_TIM1->IR = 1;
//    NVIC_ClearPendingIRQ(TIMER1_IRQn);
}

__attribute__((__naked__)) void hard_fault_handler_c( unsigned long *hardfault_args )
{
    /* These are volatile to try and prevent the compiler/linker optimising them
    away as the variables never actually get used.  If the debugger won't show the
    values of the variables, make them global my moving their declaration outside
    of this function. */
    volatile unsigned long stacked_r0 ;
    volatile unsigned long stacked_r1 ;
    volatile unsigned long stacked_r2 ;
    volatile unsigned long stacked_r3 ;
    volatile unsigned long stacked_r12 ;
    volatile unsigned long stacked_lr ;
    volatile unsigned long stacked_pc ;
    volatile unsigned long stacked_psr ;
    volatile unsigned long _CFSR ;
    volatile unsigned long _HFSR ;
    volatile unsigned long _DFSR ;
    volatile unsigned long _AFSR ;
    volatile unsigned long _BFAR ;
    volatile unsigned long _MMAR ;

    stacked_r0 = ((unsigned long)hardfault_args[0]) ;
    stacked_r1 = ((unsigned long)hardfault_args[1]) ;
    stacked_r2 = ((unsigned long)hardfault_args[2]) ;
    stacked_r3 = ((unsigned long)hardfault_args[3]) ;
    stacked_r12 = ((unsigned long)hardfault_args[4]) ;
    stacked_lr = ((unsigned long)hardfault_args[5]) ;
    stacked_pc = ((unsigned long)hardfault_args[6]) ;
    stacked_psr = ((unsigned long)hardfault_args[7]) ;

    // Configurable Fault Status Register
    // Consists of MMSR, BFSR and UFSR
    _CFSR = (*((volatile unsigned long *)(0xE000ED28))) ;

    // Hard Fault Status Register
    _HFSR = (*((volatile unsigned long *)(0xE000ED2C))) ;

    // Debug Fault Status Register
    _DFSR = (*((volatile unsigned long *)(0xE000ED30))) ;

    // Auxiliary Fault Status Register
    _AFSR = (*((volatile unsigned long *)(0xE000ED3C))) ;

    // Read the Fault Address Registers. These may not contain valid values.
    // Check BFARVALID/MMARVALID to see if they are valid values
    // MemManage Fault Address Register
    _MMAR = (*((volatile unsigned long *)(0xE000ED34))) ;
    // Bus Fault Address Register
    _BFAR = (*((volatile unsigned long *)(0xE000ED38))) ;

    __asm("BKPT #0\n") ; // Break into the debugger

    /* When the following line is hit, the variables contain the register values. */
    if (stacked_r0 || stacked_r1 || stacked_r2 || stacked_r3 || stacked_r12 ||
        stacked_lr || stacked_pc || stacked_psr || _CFSR || _HFSR || _DFSR ||
        _AFSR || _MMAR || _BFAR)
    {
        resetblink(BLINK_DIE_HARDFAULT);
        for( ;; );
    }
}

/** The fault handler implementation.  This code is inspired by FreeRTOS.
 */
void HardFault_Handler(void)
{
    __asm volatile
    (
        "BKPT  #0 \n"
        "MOVS   R0, #4                  \n"
        "MOV    R1, LR                  \n"
        "TST    R0, R1                  \n"
        "BEQ    _MSP                    \n"
        "MRS    R0, PSP                 \n"
        "B      hard_fault_handler_c    \n"
        "_MSP:                          \n"
        "MRS    R0, MSP                 \n"
        "B      hard_fault_handler_c    \n"
        "BX    LR\n"
    );
}

}  // extern C
<commit_msg>Fixes big in blink handler that caused the blinking to be inverted.<commit_after>#include "FreeRTOSConfig.h"
#include "os/OS.hxx"

#include "stm32f10x.h"

#include "stm32f10x_gpio.h"
#include "stm32f10x_rcc.h"
#include "misc.h"

extern "C" {

extern void Reset_Handler(void);
extern void __libc_init_array(void);
extern int main(void);
extern void SystemInit(void);

extern uint32_t __start_ram;
extern uint32_t __end_ram;

extern uint32_t __data_start__;
extern uint32_t __data_end__;
extern uint32_t __data_init_start__;

extern uint32_t __bss_start__;
extern uint32_t __bss_end__;

void setup_blinker();
void setup_nvic();

void __attribute__((naked)) Reset_Handler(void) {
    // Takes care of hardware responses from the bootloader not showing up
    // anymore.
    __disable_irq();
    // Resets USB module
    RCC_APB2PeriphResetCmd(RCC_APB1Periph_USB, ENABLE);
    for (volatile int i = 0; i < 10; ++i);
    RCC_APB2PeriphResetCmd(RCC_APB1Periph_USB, DISABLE);
    RCC_APB2PeriphClockCmd(RCC_APB1Periph_USB, DISABLE);

    // Fills the memory with a debug pattern.
    for (uint32_t* d = &__start_ram; d < &__end_ram; ++d)
    {
        *d = 0xdbdbdbdb;
    }

    // Clears BSS
    for (uint32_t* d = &__bss_start__; d < &__bss_end__; ++d) {
        *d = 0;
    }

    // Copies initialized data from flash to RAM
    uint32_t* s = &__data_init_start__;
    for (uint32_t* d = &__data_start__; d < &__data_end__; ++d, ++s) {
        *d = *s;
    }

    // Sets up system clock.
    SystemInit();

    setup_nvic();
    setup_blinker();

    // Calls global constructors.
    __libc_init_array();
    main();
    while(1);
}

void setup_nvic() {
    extern uint32_t g_pfnVectors;
    SCB->VTOR = (uint32_t)&g_pfnVectors;
    // 4 bits of interrupt priority, 0 bits for subpriority.
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
    // Clears external and internal interrupt masks and software interrupt
    // request bits.
    EXTI->IMR = 0;
    EXTI->EMR = 0;
    EXTI->SWIER = 0;
    // Clears all NVIC interrupt enable and pending bits.
    for (unsigned i = 0; i < sizeof(NVIC->ICER) / sizeof(NVIC->ICER[0]); ++i) {
        NVIC->ICER[i] = NVIC_ICER_CLRENA;
        NVIC->ICPR[i] = NVIC_ICPR_CLRPEND;
    }
}

void setup_blinker() {
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

    GPIO_InitTypeDef gp;
    GPIO_StructInit(&gp);

    gp.GPIO_Pin = (1<<1) | (1<<5);
    gp.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(GPIOA, &gp);

    GPIOA->BSRR = (1<<1) | (1<<5); // Turns on both leds.
}

void setblink(uint32_t pattern);

const unsigned long cm3_cpu_clock_hz = 72000000;

void hw_init(void)
{
    // This is needed for proper bootup of the FreeRTOS scheduler.
    __disable_irq();
}

uint32_t blinker_pattern;
uint32_t current_pattern;
#define BLINK_GPIO GPIOA
#define BLINK_BIT 5

extern "C" {
extern void vPortClearInterruptMask( unsigned long ulNewMaskValue );
extern unsigned long ulPortSetInterruptMask( void );
}

void enable_fiq_only(void)
{
    /** @TODO(balazs.racz): we should call vPortClearInterruptMask(14) here,
     * assuming the blink-timer interrupt is set to priority 15. The code here
     * will block all FreeRTOS functions though. */
    ulPortSetInterruptMask();
    __enable_irq();
}

void diewith(unsigned long);

void Default_Handler() {
    diewith(BLINK_DIE_UNEXPIRQ);
}

/** Initializes the timer responsible for the blinking hardware and sets
 *   initial pattern.
 *
 *  \param pattern is a blinking pattern, each bit will be shifted to the
 *  output LED every 125 ms.
 */
void setblink(uint32_t pattern)
{
    GPIOA->BSRR = pattern ? (1<<1) : (1<<17);
    //gpio_write_bit(ERROR_LED_PORT, ERROR_LED_PIN, );
/*    blinker_pattern = pattern;
    current_pattern = 0;
    BLINK_GPIO->FIODIR |= BLINK_BIT;
    BLINK_GPIO->FIOCLR = BLINK_BIT;

    // clock = raw clock
    LPC_SC->PCLKSEL0 = (LPC_SC->PCLKSEL0 & (~(0x3 << 4))) | (0x01 << 4);
    LPC_TIM1->TCR = 2;  // stop & reset timer
    LPC_TIM1->CTCR = 0; // timer mode
    // prescale to 1 ms per tick
    LPC_TIM1->PR = configCPU_CLOCK_HZ / 1000;
    LPC_TIM1->MR0 = 125;
    LPC_TIM1->MCR = 3; // reset and interrupt on match 0

    NVIC_SetPriority(TIMER1_IRQn, 0);
    NVIC_EnableIRQ(TIMER1_IRQn);

    LPC_TIM1->TCR = 1; // Timer go.*/
}

/** Updates the blinking pattern.
 *
 *  \param pattern is a blinking pattern, each bit will be shifted to the
 *  output LED every 125 ms.
 */
void resetblink(uint32_t pattern)
{
    blinker_pattern = pattern;
    setblink(pattern);
    // Makes a timer event trigger immediately.
    //LPC_TIM1->TC = LPC_TIM1->MR0 - 2;
}

/** Aborts the program execution and sets a particular blinking pattern.
 *
 *  \param pattern is a blinking pattern, each bit will be shifted to the
 *  output LED every 125 ms.
 *
 *  Never returns.
 */
void diewith(unsigned long pattern)
{
    __disable_irq();
    while(1) {
        GPIOA->BSRR = current_pattern & 1 ? ((1<<5)|(1<<1)) : ((1<<5)|(1<<1)) << 16;
        current_pattern >>= 1;
        if (!current_pattern)
        {
            current_pattern = pattern;
        }
        for (volatile int i = 0; i < 450000; i++);
    }

    enable_fiq_only();
    setblink(pattern);
    for (;;)
    {
    }
}

void TIMER1_IRQHandler(void)
{
    if (current_pattern & 1)
    {
//        BLINK_GPIO->FIOSET = BLINK_BIT;
    }
    else
    {
//     BLINK_GPIO->FIOCLR = BLINK_BIT;
    }
    current_pattern >>= 1;
    if (!current_pattern)
    {
        current_pattern = blinker_pattern;
    }

    // Clears IRQ.
//    LPC_TIM1->IR = 1;
//    NVIC_ClearPendingIRQ(TIMER1_IRQn);
}

__attribute__((__naked__)) void hard_fault_handler_c( unsigned long *hardfault_args )
{
    /* These are volatile to try and prevent the compiler/linker optimising them
    away as the variables never actually get used.  If the debugger won't show the
    values of the variables, make them global my moving their declaration outside
    of this function. */
    volatile unsigned long stacked_r0 ;
    volatile unsigned long stacked_r1 ;
    volatile unsigned long stacked_r2 ;
    volatile unsigned long stacked_r3 ;
    volatile unsigned long stacked_r12 ;
    volatile unsigned long stacked_lr ;
    volatile unsigned long stacked_pc ;
    volatile unsigned long stacked_psr ;
    volatile unsigned long _CFSR ;
    volatile unsigned long _HFSR ;
    volatile unsigned long _DFSR ;
    volatile unsigned long _AFSR ;
    volatile unsigned long _BFAR ;
    volatile unsigned long _MMAR ;

    stacked_r0 = ((unsigned long)hardfault_args[0]) ;
    stacked_r1 = ((unsigned long)hardfault_args[1]) ;
    stacked_r2 = ((unsigned long)hardfault_args[2]) ;
    stacked_r3 = ((unsigned long)hardfault_args[3]) ;
    stacked_r12 = ((unsigned long)hardfault_args[4]) ;
    stacked_lr = ((unsigned long)hardfault_args[5]) ;
    stacked_pc = ((unsigned long)hardfault_args[6]) ;
    stacked_psr = ((unsigned long)hardfault_args[7]) ;

    // Configurable Fault Status Register
    // Consists of MMSR, BFSR and UFSR
    _CFSR = (*((volatile unsigned long *)(0xE000ED28))) ;

    // Hard Fault Status Register
    _HFSR = (*((volatile unsigned long *)(0xE000ED2C))) ;

    // Debug Fault Status Register
    _DFSR = (*((volatile unsigned long *)(0xE000ED30))) ;

    // Auxiliary Fault Status Register
    _AFSR = (*((volatile unsigned long *)(0xE000ED3C))) ;

    // Read the Fault Address Registers. These may not contain valid values.
    // Check BFARVALID/MMARVALID to see if they are valid values
    // MemManage Fault Address Register
    _MMAR = (*((volatile unsigned long *)(0xE000ED34))) ;
    // Bus Fault Address Register
    _BFAR = (*((volatile unsigned long *)(0xE000ED38))) ;

    __asm("BKPT #0\n") ; // Break into the debugger

    /* When the following line is hit, the variables contain the register values. */
    if (stacked_r0 || stacked_r1 || stacked_r2 || stacked_r3 || stacked_r12 ||
        stacked_lr || stacked_pc || stacked_psr || _CFSR || _HFSR || _DFSR ||
        _AFSR || _MMAR || _BFAR)
    {
        resetblink(BLINK_DIE_HARDFAULT);
        for( ;; );
    }
}

/** The fault handler implementation.  This code is inspired by FreeRTOS.
 */
void HardFault_Handler(void)
{
    __asm volatile
    (
        "BKPT  #0 \n"
        "MOVS   R0, #4                  \n"
        "MOV    R1, LR                  \n"
        "TST    R0, R1                  \n"
        "BEQ    _MSP                    \n"
        "MRS    R0, PSP                 \n"
        "B      hard_fault_handler_c    \n"
        "_MSP:                          \n"
        "MRS    R0, MSP                 \n"
        "B      hard_fault_handler_c    \n"
        "BX    LR\n"
    );
}

}  // extern C
<|endoftext|>


<commit_before>//  (C) Copyright Gennadiy Rozental 2001-2003.
//  Permission to copy, use, modify, sell and distribute this software
//  is granted provided this copyright notice appears in all copies.
//  This software is provided "as is" without express or implied warranty,
//  and with no claim as to its suitability for any purpose.

//  See http://www.boost.org for most recent version including documentation.
//
//  File        : $RCSfile$
//
//  Version     : $Revision$
//
//  Description : storage for unit test framework parameters information
// ***************************************************************************

#ifndef BOOST_UNIT_TEST_PARAMETERS_HPP
#define BOOST_UNIT_TEST_PARAMETERS_HPP

// STL
#include <string>   // std::string

#include <boost/test/detail/unit_test_config.hpp>

namespace boost {

namespace unit_test_framework {

// framework parameters and there corresponding command-line arguments
c_string_literal const LOG_LEVEL         = "BOOST_TEST_LOG_LEVEL";              // --log_level
c_string_literal const NO_RESULT_CODE    = "BOOST_TEST_RESULT_CODE";            // --result_code
c_string_literal const REPORT_LEVEL      = "BOOST_TEST_REPORT_LEVEL";           // --report_level
c_string_literal const TESTS_TO_RUN      = "BOOST_TESTS_TO_RUN";                // --run_test
c_string_literal const SAVE_TEST_PATTERN = "BOOST_TEST_SAVE_PATTERN";           // --save_pattern
c_string_literal const BUILD_INFO        = "BOOST_TEST_BUILD_INFO";             // --build_info
c_string_literal const CATCH_SYS_ERRORS  = "BOOST_TEST_CATCH_SYSTEM_ERRORS";    // --catch_system_errors
c_string_literal const REPORT_FORMAT     = "BOOST_TEST_REPORT_FORMAT";          // --report_format
c_string_literal const LOG_FORMAT        = "BOOST_TEST_LOG_FORMAT";             // --log_format
c_string_literal const OUTPUT_FORMAT     = "BOOST_TEST_OUTPUT_FORMAT";          // --output_format

enum report_level                             { CONFIRMATION_REPORT, SHORT_REPORT, DETAILED_REPORT, NO_REPORT };
c_string_literal const report_level_names[] = { "confirm"          , "short"     , "detailed"     , "no"      };

enum output_format { HRF /* human readable format */, XML /* XML */ };

std::string retrieve_framework_parameter( c_string_literal parameter_name_, int* argc_, char** argv_ );

} // namespace unit_test_framework

} // namespace boost

// ***************************************************************************
//  Revision History :
//
//  $Log$
//  Revision 1.8  2003/06/09 08:39:28  rogeeff
//  1.30.beta1
//

// ***************************************************************************

#endif // BOOST_UNIT_TEST_CONFIG_HPP
<commit_msg>UNDEF report level introduced<commit_after>//  (C) Copyright Gennadiy Rozental 2001-2003.
//  Permission to copy, use, modify, sell and distribute this software
//  is granted provided this copyright notice appears in all copies.
//  This software is provided "as is" without express or implied warranty,
//  and with no claim as to its suitability for any purpose.

//  See http://www.boost.org for most recent version including documentation.
//
//  File        : $RCSfile$
//
//  Version     : $Revision$
//
//  Description : storage for unit test framework parameters information
// ***************************************************************************

#ifndef BOOST_UNIT_TEST_PARAMETERS_HPP
#define BOOST_UNIT_TEST_PARAMETERS_HPP

// STL
#include <string>   // std::string

#include <boost/test/detail/unit_test_config.hpp>

namespace boost {

namespace unit_test_framework {

// framework parameters and there corresponding command-line arguments
c_string_literal const LOG_LEVEL         = "BOOST_TEST_LOG_LEVEL";              // --log_level
c_string_literal const NO_RESULT_CODE    = "BOOST_TEST_RESULT_CODE";            // --result_code
c_string_literal const REPORT_LEVEL      = "BOOST_TEST_REPORT_LEVEL";           // --report_level
c_string_literal const TESTS_TO_RUN      = "BOOST_TESTS_TO_RUN";                // --run_test
c_string_literal const SAVE_TEST_PATTERN = "BOOST_TEST_SAVE_PATTERN";           // --save_pattern
c_string_literal const BUILD_INFO        = "BOOST_TEST_BUILD_INFO";             // --build_info
c_string_literal const CATCH_SYS_ERRORS  = "BOOST_TEST_CATCH_SYSTEM_ERRORS";    // --catch_system_errors
c_string_literal const REPORT_FORMAT     = "BOOST_TEST_REPORT_FORMAT";          // --report_format
c_string_literal const LOG_FORMAT        = "BOOST_TEST_LOG_FORMAT";             // --log_format
c_string_literal const OUTPUT_FORMAT     = "BOOST_TEST_OUTPUT_FORMAT";          // --output_format

enum report_level                             { CONFIRMATION_REPORT, SHORT_REPORT, DETAILED_REPORT, NO_REPORT, UNDEF_REPORT };
c_string_literal const report_level_names[] = { "confirm"          , "short"     , "detailed"     , "no"     };

enum output_format { HRF /* human readable format */, XML /* XML */ };

std::string retrieve_framework_parameter( c_string_literal parameter_name_, int* argc_, char** argv_ );

} // namespace unit_test_framework

} // namespace boost

// ***************************************************************************
//  Revision History :
//
//  $Log$
//  Revision 1.9  2003/06/10 03:36:51  rogeeff
//  UNDEF report level introduced
//
//  Revision 1.8  2003/06/09 08:39:28  rogeeff
//  1.30.beta1
//

// ***************************************************************************

#endif // BOOST_UNIT_TEST_CONFIG_HPP
<|endoftext|>