Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/DOF/DOF.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#define LIBDOF_VERSION_MAJOR 0 // X Digits
#define LIBDOF_VERSION_MINOR 4 // Max 2 Digits
#define LIBDOF_VERSION_PATCH 3 // Max 2 Digits
#define LIBDOF_VERSION_PATCH 4 // Max 2 Digits

#define _LIBDOF_STR(x) #x
#define LIBDOF_STR(x) _LIBDOF_STR(x)
Expand Down
32 changes: 28 additions & 4 deletions src/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ void Log::Init(bool enableLogging)
auto now = std::chrono::system_clock::now();
auto time_t = std::chrono::system_clock::to_time_t(now);
std::stringstream ss;
ss << std::put_time(std::localtime(&time_t), "%Y.%m.%d %H:%M");
struct tm localTime1;
#ifdef _WIN32
localtime_s(&localTime1, &time_t);
ss << std::put_time(&localTime1, "%Y.%m.%d %H:%M");
#else
ss << std::put_time(localtime_r(&time_t, &localTime1), "%Y.%m.%d %H:%M");
#endif

m_logger << StringExtensions::Build("libdof (DirectOutput Framework) - Version {0}, built {1}", LIBDOF_VERSION, ss.str()) << std::endl;
m_logger << "DOF created by SwissLizard / MIT License" << std::endl;
Expand All @@ -89,7 +95,13 @@ void Log::Init(bool enableLogging)
auto timeT = std::chrono::system_clock::to_time_t(nowMs);
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(nowMs.time_since_epoch()) % 1000;
std::stringstream timestamp;
timestamp << std::put_time(std::localtime(&timeT), "%Y.%m.%d %H:%M:%S");
struct tm localTime2;
#ifdef _WIN32
localtime_s(&localTime2, &timeT);
timestamp << std::put_time(&localTime2, "%Y.%m.%d %H:%M:%S");
#else
timestamp << std::put_time(localtime_r(&timeT, &localTime2), "%Y.%m.%d %H:%M:%S");
#endif
timestamp << "." << std::setfill('0') << std::setw(3) << ms.count();

m_logger << timestamp.str() << "\t" << StringExtensions::Build("DirectOutput logger initialized{0}", instrumentationsEnabledNote) << std::endl;
Expand Down Expand Up @@ -173,7 +185,13 @@ void Log::WriteToFile(const std::string& message)
auto timeT = std::chrono::system_clock::to_time_t(nowMs);
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(nowMs.time_since_epoch()) % 1000;
std::stringstream timestamp;
timestamp << std::put_time(std::localtime(&timeT), "%Y.%m.%d %H:%M:%S");
struct tm localTime3;
#ifdef _WIN32
localtime_s(&localTime3, &timeT);
timestamp << std::put_time(&localTime3, "%Y.%m.%d %H:%M:%S");
#else
timestamp << std::put_time(localtime_r(&timeT, &localTime3), "%Y.%m.%d %H:%M:%S");
#endif
timestamp << "." << std::setfill('0') << std::setw(3) << ms.count();
WriteRaw(timestamp.str() + "\t");
}
Expand All @@ -190,7 +208,13 @@ void Log::WriteToFile(const std::string& message)
auto timeT = std::chrono::system_clock::to_time_t(nowMs);
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(nowMs.time_since_epoch()) % 1000;
std::stringstream timestamp;
timestamp << std::put_time(std::localtime(&timeT), "%Y.%m.%d %H:%M:%S");
struct tm localTime4;
#ifdef _WIN32
localtime_s(&localTime4, &timeT);
timestamp << std::put_time(&localTime4, "%Y.%m.%d %H:%M:%S");
#else
timestamp << std::put_time(localtime_r(&timeT, &localTime4), "%Y.%m.%d %H:%M:%S");
#endif
timestamp << "." << std::setfill('0') << std::setw(3) << ms.count();
WriteRaw(timestamp.str() + "\t" + line);
}
Expand Down
38 changes: 36 additions & 2 deletions src/cab/out/pac/PacDriveSingleton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,41 @@ void PacDriveSingleton::EnumerateDevices()
if (currentDevice->serial_number)
{
std::wstring wserial(currentDevice->serial_number);
info.serial = std::string(wserial.begin(), wserial.end());
#ifdef _WIN32
int size = WideCharToMultiByte(CP_UTF8, 0, wserial.c_str(), -1, nullptr, 0, nullptr, nullptr);
if (size > 0)
{
info.serial.resize(size - 1);
WideCharToMultiByte(CP_UTF8, 0, wserial.c_str(), -1, &info.serial[0], size, nullptr, nullptr);
}
#else
info.serial.clear();
for (wchar_t wc : wserial)
{
if (wc <= 0x7F)
{
info.serial.push_back(static_cast<char>(wc));
}
else if (wc <= 0x7FF)
{
info.serial.push_back(static_cast<char>(0xC0 | ((wc >> 6) & 0x1F)));
info.serial.push_back(static_cast<char>(0x80 | (wc & 0x3F)));
}
else if (wc <= 0xFFFF)
{
info.serial.push_back(static_cast<char>(0xE0 | ((wc >> 12) & 0x0F)));
info.serial.push_back(static_cast<char>(0x80 | ((wc >> 6) & 0x3F)));
info.serial.push_back(static_cast<char>(0x80 | (wc & 0x3F)));
}
else
{
info.serial.push_back(static_cast<char>(0xF0 | ((wc >> 18) & 0x07)));
info.serial.push_back(static_cast<char>(0x80 | ((wc >> 12) & 0x3F)));
info.serial.push_back(static_cast<char>(0x80 | ((wc >> 6) & 0x3F)));
info.serial.push_back(static_cast<char>(0x80 | (wc & 0x3F)));
}
}
#endif
}
else
{
Expand Down Expand Up @@ -580,4 +614,4 @@ void PacDriveSingleton::CloseUsbDevice(int index)
}
}

}
}
5 changes: 3 additions & 2 deletions src/fx/matrixfx/MatrixBitmapAnimationEffectBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "../../general/StringExtensions.h"
#include "../../Log.h"
#include "../../pinballsupport/AlarmHandler.h"
#include "../../pinballsupport/Action.h"
#include "../../general/bitmap/PixelData.h"
#include <chrono>
#include <vector>
Expand Down Expand Up @@ -95,7 +96,7 @@ template <typename MatrixElementType> void MatrixBitmapAnimationEffectBase<Matri
{
m_animationStep = 0;
}
this->m_table->GetPinball()->GetAlarms()->RegisterIntervalAlarm(m_animationFrameDurationMs, this, [this]() { this->Animate(); });
this->m_table->GetPinball()->GetAlarms()->RegisterIntervalAlarm(m_animationFrameDurationMs, Action(this, &MatrixBitmapAnimationEffectBase<MatrixElementType>::Animate));

Animate();
}
Expand All @@ -112,7 +113,7 @@ template <typename MatrixElementType> void MatrixBitmapAnimationEffectBase<Matri
{
try
{
this->m_table->GetPinball()->GetAlarms()->UnregisterIntervalAlarm(this);
this->m_table->GetPinball()->GetAlarms()->UnregisterIntervalAlarm(Action(this, &MatrixBitmapAnimationEffectBase<MatrixElementType>::Animate));
}
catch (...)
{
Expand Down
13 changes: 7 additions & 6 deletions src/fx/matrixfx/MatrixFlickerEffectBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "../../table/Table.h"
#include "../../Pinball.h"
#include "../../pinballsupport/AlarmHandler.h"
#include "../../pinballsupport/Action.h"
#include <random>
#include <chrono>
#include <functional>
Expand Down Expand Up @@ -58,7 +59,7 @@ template <typename MatrixElementType> class MatrixFlickerEffectBase : public Mat
int m_currentValue;
TableElementData* m_flickerTableElementData;
std::mt19937 m_randomGenerator;
std::function<void()> m_intervalAlarmCallback;
Action m_intervalAlarmCallback;

struct FlickerObject
{
Expand All @@ -85,7 +86,7 @@ MatrixFlickerEffectBase<MatrixElementType>::MatrixFlickerEffectBase()
, m_currentValue(0)
, m_flickerTableElementData(nullptr)
, m_randomGenerator(std::random_device {}())
, m_intervalAlarmCallback(nullptr)
, m_intervalAlarmCallback()
{
}

Expand Down Expand Up @@ -137,9 +138,9 @@ template <typename MatrixElementType> void MatrixFlickerEffectBase<MatrixElement
{
if (!m_intervalAlarmCallback)
{
m_intervalAlarmCallback = [this]() { this->DoFlicker(); };
m_intervalAlarmCallback = Action(this, &MatrixFlickerEffectBase<MatrixElementType>::DoFlicker);
}
this->m_table->GetPinball()->GetAlarms()->RegisterIntervalAlarm(30, this, m_intervalAlarmCallback);
this->m_table->GetPinball()->GetAlarms()->RegisterIntervalAlarm(30, m_intervalAlarmCallback);
m_active = true;
}

Expand Down Expand Up @@ -240,8 +241,8 @@ template <typename MatrixElementType> void MatrixFlickerEffectBase<MatrixElement

if (m_intervalAlarmCallback)
{
this->m_table->GetPinball()->GetAlarms()->UnregisterIntervalAlarm(this);
m_intervalAlarmCallback = nullptr;
this->m_table->GetPinball()->GetAlarms()->UnregisterIntervalAlarm(m_intervalAlarmCallback);
m_intervalAlarmCallback = Action();
}
m_active = false;
}
Expand Down
3 changes: 2 additions & 1 deletion src/fx/matrixfx/MatrixPlasmaEffectBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "../../table/Table.h"
#include "../../Pinball.h"
#include "../../pinballsupport/AlarmHandler.h"
#include "../../pinballsupport/Action.h"
#include <cmath>
#include <chrono>

Expand Down Expand Up @@ -120,7 +121,7 @@ template <typename MatrixElementType> void MatrixPlasmaEffectBase<MatrixElementT


int stepDelayMs = MathExtensions::Limit(110 - m_plasmaSpeed, 10, 100);
this->m_table->GetPinball()->GetAlarms()->RegisterAlarm(stepDelayMs, [this]() { this->PlasmaStep(); }, false);
this->m_table->GetPinball()->GetAlarms()->RegisterAlarm(stepDelayMs, Action(this, &MatrixPlasmaEffectBase<MatrixElementType>::PlasmaStep), false);
}

template <typename MatrixElementType> void MatrixPlasmaEffectBase<MatrixElementType>::UpdateMatrix()
Expand Down
9 changes: 6 additions & 3 deletions src/fx/matrixfx/MatrixShiftEffectBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "../../table/Table.h"
#include "../../Pinball.h"
#include "../../pinballsupport/AlarmHandler.h"
#include "../../pinballsupport/Action.h"
#include <vector>
#include <map>

Expand Down Expand Up @@ -51,6 +52,7 @@ template <typename MatrixElementType> class MatrixShiftEffectBase : public Matri
int m_lastDiscardedValue;
int m_currentStep;
bool m_active;
Action m_stepCallback;
};


Expand All @@ -63,6 +65,7 @@ MatrixShiftEffectBase<MatrixElementType>::MatrixShiftEffectBase()
, m_lastDiscardedValue(0)
, m_currentStep(0)
, m_active(false)
, m_stepCallback(this, &MatrixShiftEffectBase<MatrixElementType>::DoStep)
{
}

Expand Down Expand Up @@ -91,7 +94,7 @@ template <typename MatrixElementType> void MatrixShiftEffectBase<MatrixElementTy
{
if (!m_active)
{
this->m_table->GetPinball()->GetAlarms()->RegisterIntervalAlarm(RefreshIntervalMs, this, [this]() { this->DoStep(); });
this->m_table->GetPinball()->GetAlarms()->RegisterIntervalAlarm(RefreshIntervalMs, m_stepCallback);
m_active = true;
}

Expand Down Expand Up @@ -215,7 +218,7 @@ template <typename MatrixElementType> void MatrixShiftEffectBase<MatrixElementTy
m_currentStep++;
else
{
this->m_table->GetPinball()->GetAlarms()->UnregisterIntervalAlarm(this);
this->m_table->GetPinball()->GetAlarms()->UnregisterIntervalAlarm(m_stepCallback);
m_lastDiscardedValue = 0;
m_currentStep = 0;
m_active = false;
Expand Down Expand Up @@ -245,7 +248,7 @@ template <typename MatrixElementType> void MatrixShiftEffectBase<MatrixElementTy
{
try
{
this->m_table->GetPinball()->GetAlarms()->UnregisterIntervalAlarm(this);
this->m_table->GetPinball()->GetAlarms()->UnregisterIntervalAlarm(m_stepCallback);
}
catch (...)
{
Expand Down
2 changes: 1 addition & 1 deletion src/fx/timmedfx/BlinkEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ BlinkEffect::BlinkEffect()
, m_blinkState(false)
, m_blinkOrgTableElementDataValue(1)
, m_blinkTableElementData()
, m_alarmCallback(this, &BlinkEffect::DoBlink)
{
m_alarmCallback = [this]() { this->DoBlink(); };
}

BlinkEffect::~BlinkEffect() { }
Expand Down
3 changes: 2 additions & 1 deletion src/fx/timmedfx/BlinkEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "../EffectEffectBase.h"
#include "BlinkEffectUntriggerBehaviourEnum.h"
#include "../../table/TableElementData.h"
#include "../../pinballsupport/Action.h"
#include <functional>

namespace DOF
Expand Down Expand Up @@ -47,7 +48,7 @@ class BlinkEffect : public EffectEffectBase
int m_blinkOrgTableElementDataValue;
TableElementData m_blinkTableElementData;

std::function<void()> m_alarmCallback;
Action m_alarmCallback;
};

}
4 changes: 2 additions & 2 deletions src/fx/timmedfx/DelayEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace DOF
DelayEffect::DelayEffect()
: m_delayMs(0)
, m_delayTableElementData()
, m_afterDelayCallback(this, &DelayEffect::AfterDelay)
{
}

Expand All @@ -24,7 +25,6 @@ void DelayEffect::Trigger(TableElementData* tableElementData)
if (m_delayMs > 0)
{
m_delayTableElementData = *tableElementData;
m_afterDelayCallback = [this]() { this->AfterDelay(&m_delayTableElementData); };
m_table->GetPinball()->GetAlarms()->RegisterAlarm(m_delayMs, m_afterDelayCallback, true);
}
else
Expand All @@ -34,7 +34,7 @@ void DelayEffect::Trigger(TableElementData* tableElementData)
}
}

void DelayEffect::AfterDelay(TableElementData* data) { TriggerTargetEffect(data); }
void DelayEffect::AfterDelay() { TriggerTargetEffect(&m_delayTableElementData); }

void DelayEffect::Init(Table* table) { EffectEffectBase::Init(table); }

Expand Down
5 changes: 3 additions & 2 deletions src/fx/timmedfx/DelayEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "../EffectEffectBase.h"
#include "../../table/TableElementData.h"
#include "../../pinballsupport/Action.h"
#include <functional>

namespace DOF
Expand All @@ -22,10 +23,10 @@ class DelayEffect : public EffectEffectBase
virtual std::string GetXmlElementName() const override { return "DelayEffect"; }

private:
void AfterDelay(TableElementData* data);
void AfterDelay();

int m_delayMs;
std::function<void()> m_afterDelayCallback;
Action m_afterDelayCallback;
TableElementData m_delayTableElementData;
};

Expand Down
5 changes: 3 additions & 2 deletions src/fx/timmedfx/DurationEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ DurationEffect::DurationEffect()
, m_durationMs(500)
, m_active(false)
, m_durationTableElementData()
, m_durationEndCallback(this, &DurationEffect::DurationEnd)
{
}

Expand All @@ -23,13 +24,13 @@ void DurationEffect::Trigger(TableElementData* tableElementData)
{
TriggerTargetEffect(tableElementData);
m_durationTableElementData = *tableElementData;
m_table->GetPinball()->GetAlarms()->RegisterAlarm(m_durationMs, [this]() { this->DurationEnd(); });
m_table->GetPinball()->GetAlarms()->RegisterAlarm(m_durationMs, m_durationEndCallback);
m_active = true;
}
else if (m_retriggerBehaviour == RetriggerBehaviourEnum::Restart)
{
m_durationTableElementData = *tableElementData;
m_table->GetPinball()->GetAlarms()->RegisterAlarm(m_durationMs, [this]() { this->DurationEnd(); });
m_table->GetPinball()->GetAlarms()->RegisterAlarm(m_durationMs, m_durationEndCallback);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/fx/timmedfx/DurationEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "../EffectEffectBase.h"
#include "../RetriggerBehaviourEnum.h"
#include "../../table/TableElementData.h"
#include "../../pinballsupport/Action.h"

namespace DOF
{
Expand Down Expand Up @@ -33,6 +34,7 @@ class DurationEffect : public EffectEffectBase
int m_durationMs;
bool m_active;
TableElementData m_durationTableElementData;
Action m_durationEndCallback;
};

}
Loading