Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

Remove unused TTimer

Tact Yoshidabf36c70d1e54
diff --git a/toonz/sources/common/tapptools/ttimer.cpp b/toonz/sources/common/tapptools/ttimer.cpp
deleted file mode 100644
index e56fcaf6c..000000000
--- a/toonz/sources/common/tapptools/ttimer.cpp
+++ /dev/null
@@ -1,300 +0,0 @@
-
-
-#include "ttimer.h"
-#include "tthreadmessage.h"
-#include "texception.h"
-
-#ifdef _WIN32
-
-#include <windows.h>
-#include <mmsystem.h>
-#include <cstdlib>
-
-// moto strano: se togliamo l'include della glut non linka
-#include <GL/glut.h>
-
-//------------------------------------------------------------------------------
-
-namespace {
-
-void CALLBACK ElapsedTimeCB(UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1,
- DWORD dw2);
-};
-
-//------------------------------------------------------------------------------
-
-class TTimer::Imp {
-public:
- Imp(std::string name, UINT timerRes, TTimer::Type type, TTimer *timer);
- ~Imp();
-
- void start(UINT delay) {
- if (m_started) throw TException("The timer is already started");
-
- m_timerID = timeSetEvent(delay, m_timerRes, (LPTIMECALLBACK)ElapsedTimeCB,
- (DWORD)this, m_type | TIME_CALLBACK_FUNCTION);
-
- m_delay = delay;
- m_ticks = 0;
- if (m_timerID == NULL) throw TException("Unable to start timer");
-
- m_started = true;
- }
-
- void stop() {
- if (m_started) timeKillEvent(m_timerID);
- m_started = false;
- }
-
- std::string getName() { return m_name; }
- TUINT64 getTicks() { return m_ticks; }
- UINT getDelay() { return m_delay; }
-
- std::string m_name;
-
- UINT m_timerRes;
- UINT m_type;
- TTimer *m_timer;
-
- UINT m_timerID;
- UINT m_delay;
- TUINT64 m_ticks;
- bool m_started;
-
- TGenericTimerAction *m_action;
-};
-
-//------------------------------------------------------------------------------
-
-TTimer::Imp::Imp(std::string name, UINT timerRes, TTimer::Type type,
- TTimer *timer)
- : m_name(name)
- , m_timerRes(timerRes)
- , m_timer(timer)
- , m_type(type)
- , m_timerID(NULL)
- , m_ticks(0)
- , m_delay(0)
- , m_started(false)
- , m_action(0) {
- TIMECAPS tc;
-
- if (timeGetDevCaps(&tc, sizeof(TIMECAPS)) != TIMERR_NOERROR) {
- throw TException("Unable to create timer");
- }
-
- m_timerRes = std::min((int)std::max((int)tc.wPeriodMin, (int)m_timerRes),
- (int)tc.wPeriodMax);
- timeBeginPeriod(m_timerRes);
-
- switch (type) {
- case TTimer::OneShot:
- m_type = TIME_ONESHOT;
- break;
-
- case TTimer::Periodic:
- m_type = TIME_PERIODIC;
- break;
-
- default:
- throw TException("Unexpected timer type");
- break;
- }
-}
-
-//------------------------------------------------------------------------------
-
-TTimer::Imp::~Imp() {
- stop();
- timeEndPeriod(m_timerRes);
-
- if (m_action) delete m_action;
-}
-
-//------------------------------------------------------------------------------
-
-namespace {
-
-void CALLBACK ElapsedTimeCB(UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1,
- DWORD dw2) {
- TTimer::Imp *imp = reinterpret_cast<TTimer::Imp *>(dwUser);
- imp->m_ticks++;
- if (imp->m_action) imp->m_action->sendCommand(imp->m_ticks);
-}
-};
-#elif defined(LINUX)
-
-#include <SDL_timer.h>
-#include <SDL.h>
-#include "tthread.h"
-namespace {
-Uint32 ElapsedTimeCB(Uint32 interval, void *param);
-}
-
-class TTimer::Imp {
-public:
- Imp(std::string name, UINT timerRes, TTimer::Type type, TTimer *timer)
- : m_action(0), m_ticks(0) {}
- ~Imp() {}
-
- void start(UINT delay) {
- static bool first = true;
- if (first) {
- SDL_Init(SDL_INIT_TIMER);
- first = false;
- }
- m_timerID = SDL_AddTimer(delay, ElapsedTimeCB, this);
- }
-
- void stop() { SDL_RemoveTimer(m_timerID); }
-
- std::string getName() { return m_name; }
- TUINT64 getTicks() { return m_ticks; }
- UINT getDelay() { return m_delay; }
-
- std::string m_name;
-
- UINT m_timerRes;
- UINT m_type;
- TTimer *m_timer;
-
- SDL_TimerID m_timerID;
- UINT m_delay;
- TUINT64 m_ticks;
- bool m_started;
-
- TGenericTimerAction *m_action;
-};
-
-class SendCommandMSG final : public TThread::Message {
- TTimer::Imp *m_ztimp;
-
-public:
- SendCommandMSG(TTimer::Imp *ztimp) : TThread::Message(), m_ztimp(ztimp) {}
- ~SendCommandMSG() {}
- TThread::Message *clone() const { return new SendCommandMSG(*this); }
- void onDeliver() {
- if (m_ztimp->m_action) m_ztimp->m_action->sendCommand(m_ztimp->m_ticks);
- }
-};
-
-namespace {
-Uint32 ElapsedTimeCB(Uint32 interval, void *param) {
- TTimer::Imp *imp = reinterpret_cast<TTimer::Imp *>(param);
- imp->m_ticks++;
- SendCommandMSG(imp).send();
- return interval;
-}
-}
-
-#elif defined(__sgi)
-class TTimer::Imp {
-public:
- Imp(std::string name, UINT timerRes, TTimer::Type type, TTimer *timer)
- : m_action(0) {}
- ~Imp() {}
-
- void start(UINT delay) {
- if (m_started) throw TException("The timer is already started");
-
- m_started = true;
- }
-
- void stop() { m_started = false; }
-
- std::string getName() { return m_name; }
- TUINT64 getTicks() { return m_ticks; }
- UINT getDelay() { return m_delay; }
-
- std::string m_name;
-
- UINT m_timerRes;
- UINT m_type;
- TTimer *m_timer;
-
- UINT m_timerID;
- UINT m_delay;
- TUINT64 m_ticks;
- bool m_started;
-
- TGenericTimerAction *m_action;
-};
-#elif defined(MACOSX)
-class TTimer::Imp {
-public:
- Imp(std::string name, UINT timerRes, TTimer::Type type, TTimer *timer)
- : m_action(0) {}
- ~Imp() {}
-
- void start(UINT delay) {
- if (m_started) throw TException("The timer is already started");
- throw TException("The timer is not yet available under MAC :(");
- m_started = true;
- }
-
- void stop() { m_started = false; }
-
- std::string getName() { return m_name; }
- TUINT64 getTicks() { return m_ticks; }
- UINT getDelay() { return m_delay; }
-
- std::string m_name;
-
- UINT m_timerRes;
- UINT m_type;
- TTimer *m_timer;
-
- UINT m_timerID;
- UINT m_delay;
- TUINT64 m_ticks;
- bool m_started;
-
- TGenericTimerAction *m_action;
-};
-
-#endif
-
-//===============================================================================
-//
-// TTimer
-//
-//===============================================================================
-
-TTimer::TTimer(const std::string &name, UINT timerRes, Type type)
- : m_imp(new TTimer::Imp(name, timerRes, type, this)) {}
-
-//--------------------------------------------------------------------------------
-
-TTimer::~TTimer() {}
-
-//--------------------------------------------------------------------------------
-
-void TTimer::start(UINT delay) { m_imp->start(delay); }
-
-//--------------------------------------------------------------------------------
-
-bool TTimer::isStarted() const { return m_imp->m_started; }
-
-//--------------------------------------------------------------------------------
-
-void TTimer::stop() { m_imp->stop(); }
-
-//--------------------------------------------------------------------------------
-
-std::string TTimer::getName() const { return m_imp->getName(); }
-
-//--------------------------------------------------------------------------------
-
-TUINT64 TTimer::getTicks() const { return m_imp->getTicks(); }
-
-//--------------------------------------------------------------------------------
-
-UINT TTimer::getDelay() const { return m_imp->getDelay(); }
-
-//--------------------------------------------------------------------------------
-
-void TTimer::setAction(TGenericTimerAction *action) {
- if (m_imp->m_action) delete m_imp->m_action;
-
- m_imp->m_action = action;
-}
diff --git a/toonz/sources/include/ttimer.h b/toonz/sources/include/ttimer.h
deleted file mode 100644
index c44892664..000000000
--- a/toonz/sources/include/ttimer.h
+++ /dev/null
@@ -1,111 +0,0 @@
-#pragma once
-
-#ifndef TTIMER_INCLUDED
-#define TTIMER_INCLUDED
-
-#include <memory>
-
-#include "tcommon.h"
-
-#undef DVAPI
-#undef DVVAR
-#ifdef TAPPTOOLS_EXPORTS
-#define DVAPI DV_EXPORT_API
-#define DVVAR DV_EXPORT_VAR
-#else
-#define DVAPI DV_IMPORT_API
-#define DVVAR DV_IMPORT_VAR
-#endif
-
-//-------------------------------------------------------------------
-
-class DVAPI TGenericTimerAction {
-public:
- virtual ~TGenericTimerAction() {}
- virtual void sendCommand(TUINT64 tick) = 0;
-};
-
-//-------------------------------------------------------------------
-
-template <class T>
-class TTimerAction final : public TGenericTimerAction {
-public:
- typedef void (T::*Method)(TUINT64 tick);
- TTimerAction(T *target, Method method) : m_target(target), m_method(method) {}
- void sendCommand(TUINT64 tick) override { (m_target->*m_method)(tick); }
-
-private:
- T *m_target;
- Method m_method;
-};
-
-//------------------------------------------------------------------------------
-//! THis class is manages general time events.
-/*!
- This class defines a timer,
- i.e a system which, at user defined time steps, sends events
- through a callback function.
- */
-class DVAPI TTimer {
-public:
- /*!
- Specifies which is the type of timer of this object.
- */
- enum Type {
- OneShot, /*!< This type of timer sends timer events only at a single time.
- */
- Periodic /*!< This type of timer sends timer events periodically. */
- };
-
- /*!
- Creates a timer with name \p name, resolution \p timerRes and type \p
- type.
- Resolution is expressed in milliseconds.
- */
- TTimer(const std::string &name, UINT timerRes, Type type);
- /*!
- Deletes the timer.
- */
- ~TTimer();
-
- /*!
- Starts the timer after \p delay milliseconds.
- */
- void start(UINT delay); // delay expressed in milliseconds
- /*!
-Stops the timer immediately.
-Doesn't delete the timer.
-*/
- void stop();
- /*!
- Returns \p true if the timer is started.
- */
- bool isStarted() const;
- /*!
- Returns the name of the timer.
- */
- std::string getName() const;
- /*!
- Asks the timer for number of events so far.
- */
- TUINT64 getTicks() const;
- /*!
- Returns the initial start delay of the timer.
- */
- UINT getDelay() const;
- /*!
- Sets the callback function, i.e. the function to be called every
- timer's shot.
- */
- void setAction(TGenericTimerAction *action);
-
- class Imp;
-
-private:
- std::unique_ptr<Imp> m_imp;
-
- TTimer(const TTimer &);
- void operator=(const TTimer &);
-};
-
-#endif
diff --git a/toonz/sources/include/tw/valuefield.h b/toonz/sources/include/tw/valuefield.h
index 0c6815d4d..1ed3e6161 100644
--- a/toonz/sources/include/tw/valuefield.h
+++ b/toonz/sources/include/tw/valuefield.h
@@ -4,7 +4,6 @@
#define TNZ_VALUEFIELD_INCLUDED
#include "tw/tw.h"
-#include "ttimer.h"
#undef DVAPI
#undef DVVAR
@@ -132,7 +131,6 @@ protected:
// servono nel drag
int m_deltaPos;
int m_flags;
- TTimer m_timer;
TRect m_sliderRect, m_arrow0Rect, m_arrow1Rect;
TNumField *m_textField0, *m_textField1;
bool m_arrowEnabled, m_sliderEnabled;
diff --git a/toonz/sources/tnzbase/CMakeLists.txt b/toonz/sources/tnzbase/CMakeLists.txt
index f7cbc45b6..006538966 100644
--- a/toonz/sources/tnzbase/CMakeLists.txt
+++ b/toonz/sources/tnzbase/CMakeLists.txt
@@ -55,7 +55,6 @@ set(HEADERS ${MOC_HEADERS}
../include/tcli.h
../include/tcolorutils.h
../include/tparamundo.h
- ../include/ttimer.h
../include/ttest.h
../include/texpression.h
../include/tgrammar.h
@@ -103,7 +102,6 @@ set(SOURCES
../common/tapptools/tcli.cpp
../common/tapptools/tcolorutils.cpp
../common/tapptools/tparamundo.cpp
- ../common/tapptools/ttimer.cpp
../common/ttest/ttest.cpp
../common/expressions/texpression.cpp
../common/expressions/tgrammar.cpp
diff --git a/toonz/sources/toonz/flipbook.cpp b/toonz/sources/toonz/flipbook.cpp
index 3ec293ca3..0808df058 100644
--- a/toonz/sources/toonz/flipbook.cpp
+++ b/toonz/sources/toonz/flipbook.cpp
@@ -3,7 +3,6 @@
// System includes
#include "tsystem.h"
#include "timagecache.h"
-#include "ttimer.h"
// Geometry
#include "tgeometry.h"
diff --git a/toonz/sources/toonz/previewer.cpp b/toonz/sources/toonz/previewer.cpp
index 6ace624d7..797caa7c0 100644
--- a/toonz/sources/toonz/previewer.cpp
+++ b/toonz/sources/toonz/previewer.cpp
@@ -6,7 +6,6 @@
#include "timagecache.h"
#include "tstopwatch.h"
#include "tfiletype.h"
-#include "ttimer.h"
// Images includes
#include "trasterimage.h"