Engine puzzle completed
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Core/ConfigFile.h"
|
||||
|
||||
ConfigFile::ConfigFile(std::string path)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Core/EventBroker.h"
|
||||
|
||||
BaseEventRelay::~BaseEventRelay()
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Core/InputManager.h"
|
||||
|
||||
void InputManager::Initialize()
|
||||
@@ -13,7 +12,7 @@ void InputManager::Initialize()
|
||||
|
||||
void InputManager::Update(double dt)
|
||||
{
|
||||
EventBroker->Process<InputManager>();
|
||||
m_EventBroker->Process<InputManager>();
|
||||
|
||||
m_LastKeyState = m_CurrentKeyState;
|
||||
m_LastMouseState = m_CurrentMouseState;
|
||||
@@ -28,11 +27,11 @@ void InputManager::Update(double dt)
|
||||
if (m_CurrentKeyState[i]) {
|
||||
Events::KeyDown e;
|
||||
e.KeyCode = i;
|
||||
EventBroker->Publish(e);
|
||||
m_EventBroker->Publish(e);
|
||||
} else {
|
||||
Events::KeyUp e;
|
||||
e.KeyCode = i;
|
||||
EventBroker->Publish(e);
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,13 +48,13 @@ void InputManager::Update(double dt)
|
||||
e.Button = i;
|
||||
e.X = x;
|
||||
e.Y = y;
|
||||
EventBroker->Publish(e);
|
||||
m_EventBroker->Publish(e);
|
||||
} else {
|
||||
Events::MouseRelease e;
|
||||
e.Button = i;
|
||||
e.X = x;
|
||||
e.Y = y;
|
||||
EventBroker->Publish(e);
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -71,7 +70,7 @@ void InputManager::Update(double dt)
|
||||
e.Y = m_CurrentMouseY;
|
||||
e.DeltaX = m_CurrentMouseDeltaX;
|
||||
e.DeltaY = m_CurrentMouseDeltaY;
|
||||
EventBroker->Publish(e);
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
|
||||
// // Lock mouse while holding LMB
|
||||
@@ -174,7 +173,7 @@ void InputManager::PublishGamepadAxisIfChanged(int gamepadID, Gamepad::Axis axis
|
||||
e.GamepadID = gamepadID;
|
||||
e.Axis = axis;
|
||||
e.Value = currentValue;
|
||||
EventBroker->Publish(e);
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,12 +186,12 @@ void InputManager::PublishGamepadButtonIfChanged(int gamepadID, Gamepad::Button
|
||||
Events::GamepadButtonDown e;
|
||||
e.GamepadID = gamepadID;
|
||||
e.Button = button;
|
||||
EventBroker->Publish(e);
|
||||
m_EventBroker->Publish(e);
|
||||
} else {
|
||||
Events::GamepadButtonUp e;
|
||||
e.GamepadID = gamepadID;
|
||||
e.Button = button;
|
||||
EventBroker->Publish(e);
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Core/ResourceManager.h"
|
||||
|
||||
std::unordered_map<std::string, std::string> ResourceManager::m_CompilerTypenameToResourceType;
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
#include "Core/Util/FileWatcher.h"
|
||||
|
||||
FileWatcher::FileWatcher()
|
||||
{
|
||||
m_Worker = new Worker;
|
||||
}
|
||||
|
||||
FileWatcher::FileWatcher(std::string rootPath)
|
||||
{
|
||||
m_RootPath = rootPath;
|
||||
m_Worker = new Worker;
|
||||
}
|
||||
|
||||
FileWatcher::~FileWatcher()
|
||||
{
|
||||
m_Thread.interrupt();
|
||||
if (m_Worker != nullptr)
|
||||
{
|
||||
delete m_Worker;
|
||||
}
|
||||
}
|
||||
|
||||
void FileWatcher::AddWatch(std::string path, FileEventCallback_t callback)
|
||||
{
|
||||
m_Worker->AddWatch(path, callback);
|
||||
}
|
||||
|
||||
void FileWatcher::Start()
|
||||
{
|
||||
m_Thread.interrupt();
|
||||
m_Thread = boost::thread(boost::ref(*m_Worker));
|
||||
m_IsRunning = true;
|
||||
}
|
||||
|
||||
void FileWatcher::Stop()
|
||||
{
|
||||
m_Thread.interrupt();
|
||||
m_IsRunning = false;
|
||||
}
|
||||
|
||||
void FileWatcher::Check()
|
||||
{
|
||||
m_Worker->Check();
|
||||
}
|
||||
|
||||
|
||||
void FileWatcher::Worker::operator()()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
boost::this_thread::interruption_point();
|
||||
Check();
|
||||
boost::this_thread::sleep_for(boost::chrono::milliseconds(1000));
|
||||
}
|
||||
}
|
||||
|
||||
void FileWatcher::Worker::AddWatch(std::string path, FileEventCallback_t callback)
|
||||
{
|
||||
m_Mutex.lock();
|
||||
boost::filesystem::path bpath(path);
|
||||
m_FileCallbacks[bpath] = callback;
|
||||
if (boost::filesystem::exists(bpath))
|
||||
{
|
||||
m_FileInfo[bpath] = GetFileInfo(bpath);
|
||||
}
|
||||
m_Mutex.unlock();
|
||||
}
|
||||
|
||||
void FileWatcher::Worker::Check()
|
||||
{
|
||||
m_Mutex.lock();
|
||||
for (auto &kv : m_FileCallbacks)
|
||||
{
|
||||
boost::filesystem::path path = kv.first;
|
||||
FileEventCallback_t& callback = kv.second;
|
||||
FileEventFlags flags = UpdateFileInfo(path);
|
||||
if (flags != FileEventFlags::Nothing && callback != nullptr)
|
||||
{
|
||||
callback(path.string(), flags);
|
||||
}
|
||||
}
|
||||
m_Mutex.unlock();
|
||||
}
|
||||
|
||||
FileWatcher::Worker::FileInfo FileWatcher::Worker::GetFileInfo(boost::filesystem::path path)
|
||||
{
|
||||
FileInfo fi;
|
||||
fi.Size = boost::filesystem::file_size(path);
|
||||
fi.Timestamp = boost::filesystem::last_write_time(path);
|
||||
return fi;
|
||||
}
|
||||
|
||||
FileWatcher::FileEventFlags FileWatcher::Worker::UpdateFileInfo(boost::filesystem::path path)
|
||||
{
|
||||
FileEventFlags flags = FileEventFlags::Nothing;
|
||||
if (boost::filesystem::exists(path))
|
||||
{
|
||||
FileInfo fi = GetFileInfo(path);
|
||||
auto lastFileInfoIt = m_FileInfo.find(path);
|
||||
if (lastFileInfoIt != m_FileInfo.end())
|
||||
{
|
||||
FileInfo lastFileInfo = lastFileInfoIt->second;
|
||||
|
||||
if (fi.Size != lastFileInfo.Size)
|
||||
{
|
||||
LOG_DEBUG("FileWatcher: \"%s\" size changed!", path.string().c_str());
|
||||
flags = flags | FileEventFlags::SizeChanged;
|
||||
}
|
||||
if (fi.Timestamp != lastFileInfo.Timestamp)
|
||||
{
|
||||
LOG_DEBUG("FileWatcher: \"%s\" timestamp changed!", path.string().c_str());
|
||||
flags = flags | FileEventFlags::TimestampChanged;
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_DEBUG("FileWatcher: \"%s\" was created!", path.string().c_str());
|
||||
flags = flags | FileEventFlags::Created;
|
||||
}
|
||||
m_FileInfo[path] = GetFileInfo(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto fileInfoIt = m_FileInfo.find(path);
|
||||
if (fileInfoIt != m_FileInfo.end())
|
||||
{
|
||||
m_FileInfo.erase(fileInfoIt);
|
||||
LOG_DEBUG("FileWatcher: \"%s\" was deleted!", path.string().c_str());
|
||||
flags = flags | FileEventFlags::Deleted;
|
||||
}
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
Reference in New Issue
Block a user