Engine puzzle completed

This commit is contained in:
sippeangelo
2015-11-30 17:02:24 +01:00
parent 52278d7bc2
commit 872879c013
62 changed files with 5344 additions and 113 deletions
+10 -1
View File
@@ -1,7 +1,7 @@
project(TacticalZ-Engine)
find_package(OpenGL REQUIRED)
#find_package(GLEW REQUIRED)
find_package(GLEW REQUIRED)
find_package(GLFW REQUIRED)
find_package(Boost REQUIRED COMPONENTS system filesystem thread chrono)
find_package(assimp REQUIRED)
@@ -50,10 +50,17 @@ file(GLOB SOURCE_FILES_Rendering
)
source_group(Rendering FILES ${SOURCE_FILES_Rendering})
file(GLOB SOURCE_FILES_GUI
"${INCLUDE_PATH}/GUI/*.h"
"GUI/*.cpp"
)
source_group(GUI FILES ${SOURCE_FILES_GUI})
set(SOURCE_FILES
${SOURCE_FILES_Core}
${SOURCE_FILES_Core_Util}
#${SOURCE_FILES_Input}
${SOURCE_FILES_GUI}
${SOURCE_FILES_Rendering}
)
@@ -78,3 +85,5 @@ add_library(Engine ${SOURCE_FILES})
target_link_libraries(Engine
${LIBRARIES}
)
#set_target_properties(Engine PROPERTIES COTIRE_CXX_PREFIX_HEADER_INIT "${INCLUDE_PATH}/PrecompiledHeader.h")
#cotire(Engine)
-1
View File
@@ -1,4 +1,3 @@
#include "PrecompiledHeader.h"
#include "Core/ConfigFile.h"
ConfigFile::ConfigFile(std::string path)
-1
View File
@@ -1,4 +1,3 @@
#include "PrecompiledHeader.h"
#include "Core/EventBroker.h"
BaseEventRelay::~BaseEventRelay()
+9 -10
View File
@@ -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
View File
@@ -1,4 +1,3 @@
#include "PrecompiledHeader.h"
#include "Core/ResourceManager.h"
std::unordered_map<std::string, std::string> ResourceManager::m_CompilerTypenameToResourceType;
+134
View File
@@ -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;
}
View File
-1
View File
@@ -1 +0,0 @@
#include "PrecompiledHeader.h"
+101
View File
@@ -0,0 +1,101 @@
#include "Rendering/Camera.h"
Camera::Camera(float aspectRatio, float yFOV, float nearClip, float farClip)
{
m_AspectRatio = aspectRatio;
m_FOV = yFOV;
m_NearClip = nearClip;
m_FarClip = farClip;
m_Position = glm::vec3(0.0);
UpdateProjectionMatrix();
UpdateViewMatrix();
}
glm::vec3 Camera::Forward()
{
return m_Orientation * glm::vec3(0, 0, -1);
}
//
//glm::vec3 Camera::Right()
//{
// return glm::rotate(glm::vec3(1.f, 0.f, 0.f), -m_Yaw, glm::vec3(0.f, 1.f, 0.f));
//}
//glm::mat4 Camera::Orientation()
//{
// glm::mat4 orientation(1.f);
// orientation = glm::rotate(orientation, m_Pitch, glm::vec3(1.f, 0.f, 0.f));
// orientation = glm::rotate(orientation, m_Yaw, glm::vec3(0.f, 1.f, 0.f));
// return orientation;
//}
void Camera::SetPosition(glm::vec3 val)
{
m_Position = val;
UpdateViewMatrix();
}
void Camera::SetOrientation(glm::quat val)
{
m_Orientation = val;
UpdateViewMatrix();
}
//void Camera::Pitch(float val)
//{
// m_Pitch = val;
// UpdateViewMatrix();
//}
//
//void Camera::Yaw(float val)
//{
// m_Yaw = val;
// UpdateViewMatrix();
//}
void Camera::UpdateProjectionMatrix()
{
// m_ProjectionMatrix = glm::ortho(
// -16.f,
// 16.f,
// -9.f,
// 9.f,
// m_NearClip,
// m_FarClip
// );
m_ProjectionMatrix = glm::perspective(m_FOV, m_AspectRatio, m_NearClip, m_FarClip);
}
void Camera::UpdateViewMatrix()
{
m_ViewMatrix = glm::toMat4(glm::inverse(m_Orientation))
* glm::translate(-m_Position);
}
void Camera::SetAspectRatio(float val)
{
m_AspectRatio = val;
UpdateProjectionMatrix();
}
void Camera::SetFOV(float val)
{
m_FOV = val;
UpdateProjectionMatrix();
}
void Camera::SetNearClip(float val)
{
m_NearClip = val;
UpdateProjectionMatrix();
}
void Camera::SetFarClip(float val)
{
m_FarClip = val;
UpdateProjectionMatrix();
}
+56
View File
@@ -0,0 +1,56 @@
#include "Rendering/DummyRenderer.h"
void DummyRenderer::Initialize()
{
// Initialize GLFW
if (!glfwInit()) {
LOG_ERROR("GLFW: Initialization failed");
exit(EXIT_FAILURE);
}
// Create a window
GLFWmonitor* monitor = nullptr;
if (m_Fullscreen) {
monitor = glfwGetPrimaryMonitor();
}
//glfwWindowHint(GLFW_SAMPLES, 8);
m_Window = glfwCreateWindow(m_Resolution.Width, m_Resolution.Height, "daydream", monitor, nullptr);
if (!m_Window) {
LOG_ERROR("GLFW: Failed to create window");
exit(EXIT_FAILURE);
}
glfwMakeContextCurrent(m_Window);
// GL version info
glGetIntegerv(GL_MAJOR_VERSION, &m_GLVersion[0]);
glGetIntegerv(GL_MINOR_VERSION, &m_GLVersion[1]);
m_GLVendor = (GLchar*)glGetString(GL_VENDOR);
std::stringstream ss;
ss << m_GLVendor << " OpenGL " << m_GLVersion[0] << "." << m_GLVersion[1];
#ifdef DEBUG
ss << " DEBUG";
#endif
LOG_INFO(ss.str().c_str());
glfwSetWindowTitle(m_Window, ss.str().c_str());
// Initialize GLEW
if (glewInit() != GLEW_OK) {
LOG_ERROR("GLEW: Initialization failed");
exit(EXIT_FAILURE);
}
// Create default camera
m_DefaultCamera = new ::Camera((float)m_Resolution.Width / m_Resolution.Height, glm::radians(45.f), 0.01f, 5000.f);
m_DefaultCamera->SetPosition(glm::vec3(0, 0, 0));
if (m_Camera == nullptr) {
m_Camera = m_DefaultCamera;
}
glfwSwapInterval(m_VSYNC);
}
void DummyRenderer::Draw(RenderQueueCollection& rq)
{
glfwSwapBuffers(m_Window);
}
-1
View File
@@ -1,4 +1,3 @@
#include "PrecompiledHeader.h"
#include "Rendering/Model.h"
Model::Model(std::string fileName)
-1
View File
@@ -1,4 +1,3 @@
#include "PrecompiledHeader.h"
#include "Rendering/PNG.h"
PNG::PNG(std::string path)
-1
View File
@@ -1,4 +1,3 @@
#include "PrecompiledHeader.h"
#include "Rendering/RawModel.h"
RawModel::RawModel(std::string fileName)
-1
View File
@@ -1,4 +1,3 @@
#include "PrecompiledHeader.h"
#include "Rendering/Skeleton.h"
int Skeleton::CreateBone(int ID, int parentID, std::string name, glm::mat4 offsetMatrix)
-1
View File
@@ -1,4 +1,3 @@
#include "PrecompiledHeader.h"
#include "Rendering/Texture.h"
Texture::Texture(std::string path)