Merge remote-tracking branch 'origin/master' into Sound

# Conflicts:
#	src/Engine/Sound/SoundSystem.cpp
This commit is contained in:
stiffly
2016-02-02 13:38:49 +01:00
40 changed files with 521 additions and 146 deletions
+1
View File
@@ -16,6 +16,7 @@ if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
elseif(MSVC) elseif(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif() endif()
#set(BUILD_SHARED_LIBS FALSE) #set(BUILD_SHARED_LIBS FALSE)
@@ -9,9 +9,9 @@
class CollidableOctreeSystem : public ImpureSystem, public PureSystem class CollidableOctreeSystem : public ImpureSystem, public PureSystem
{ {
public: public:
CollidableOctreeSystem(World* world, EventBroker* eventBroker, Octree<EntityAABB>* octree) CollidableOctreeSystem(World* world, EventBroker* eventBroker, Octree<EntityAABB>* octree, const std::string& componentType)
: System(world, eventBroker) : System(world, eventBroker)
, PureSystem("Collidable") , PureSystem(componentType)
, m_Octree(octree) , m_Octree(octree)
{ } { }
+1 -1
View File
@@ -81,7 +81,7 @@ class ComponentWrapperFactory
{ {
public: public:
ComponentWrapperFactory() = default; ComponentWrapperFactory() = default;
ComponentWrapperFactory(std::string componentTypeName, std::size_t allocation = 0) ComponentWrapperFactory(std::string componentTypeName, unsigned int allocation = 0)
{ {
m_ComponentInfo.Name = componentTypeName; m_ComponentInfo.Name = componentTypeName;
m_ComponentInfo.Meta->Allocation = allocation; m_ComponentInfo.Meta->Allocation = allocation;
+1 -1
View File
@@ -143,7 +143,7 @@ private:
~EntityFile(); ~EntityFile();
public: public:
static std::size_t GetTypeStride(std::string typeName); static unsigned int GetTypeStride(std::string typeName);
static void WriteAttributeData(char* outData, const ComponentInfo::Field_t& field, const std::map<std::string, std::string>& attributes); static void WriteAttributeData(char* outData, const ComponentInfo::Field_t& field, const std::map<std::string, std::string>& attributes);
static void WriteValueData(char* outData, const ComponentInfo::Field_t& field, const char* valueData); static void WriteValueData(char* outData, const ComponentInfo::Field_t& field, const char* valueData);
+1 -1
View File
@@ -149,7 +149,7 @@ template<typename T>
template<typename Box> template<typename Box>
void Octree<T>::ObjectsInSameRegion(const Box& box, std::vector<T>& outObjects) void Octree<T>::ObjectsInSameRegion(const Box& box, std::vector<T>& outObjects)
{ {
//static_assert(std::is_base_of<AABB, Box>::value, "template argument type Box in Octree<T>::ObjectsInSameRegion must be a subclass of AABB."); static_assert(std::is_base_of<AABB, Box>::value, "template argument type Box in Octree<T>::ObjectsInSameRegion must be a subclass of AABB.");
falsifyObjectChecks(); falsifyObjectChecks();
m_Root->ObjectsInSameRegion(box, outObjects); m_Root->ObjectsInSameRegion(box, outObjects);
} }
+2 -2
View File
@@ -42,7 +42,7 @@ enum class FileWatcher::FileEventFlags
}; };
inline FileWatcher::FileEventFlags operator|(FileWatcher::FileEventFlags a, FileWatcher::FileEventFlags b) { return static_cast<FileWatcher::FileEventFlags>(static_cast<int>(a) | static_cast<int>(b)); } inline FileWatcher::FileEventFlags operator|(FileWatcher::FileEventFlags a, FileWatcher::FileEventFlags b) { return static_cast<FileWatcher::FileEventFlags>(static_cast<int>(a) | static_cast<int>(b)); }
inline bool operator&(FileWatcher::FileEventFlags a, FileWatcher::FileEventFlags b) { return static_cast<int>(a)& static_cast<int>(b); } inline bool operator&(FileWatcher::FileEventFlags a, FileWatcher::FileEventFlags b) { return (static_cast<int>(a) & static_cast<int>(b)) != 0; }
class FileWatcher::Worker class FileWatcher::Worker
{ {
@@ -54,7 +54,7 @@ public:
private: private:
struct FileInfo struct FileInfo
{ {
int Size; std::size_t Size;
std::time_t Timestamp; std::time_t Timestamp;
}; };
@@ -23,7 +23,7 @@ public:
m_SpeedMultiplier = m_Config->Get<float>("Editor.CameraSpeed", 3.f); m_SpeedMultiplier = m_Config->Get<float>("Editor.CameraSpeed", 3.f);
} }
virtual const glm::vec3 Movement() const override { return m_Movement * m_SpeedMultiplier; } virtual const glm::vec3 Movement() const override { return m_Movement * static_cast<float>(m_SpeedMultiplier); }
void Enable() { m_Enabled = true; } void Enable() { m_Enabled = true; }
void Disable() { m_Enabled = false; } void Disable() { m_Enabled = false; }
@@ -69,7 +69,7 @@ public:
protected: protected:
ConfigFile* m_Config; ConfigFile* m_Config;
bool m_Enabled = false; bool m_Enabled = false;
float m_SpeedMultiplier = 1.f; double m_SpeedMultiplier = 1.f;
EventRelay<EventContext, Events::MousePress> m_EMousePress; EventRelay<EventContext, Events::MousePress> m_EMousePress;
bool OnMousePress(const Events::MousePress& e) bool OnMousePress(const Events::MousePress& e)
@@ -105,7 +105,7 @@ protected:
return false; return false;
} }
m_SpeedMultiplier += e.DeltaY * (0.1f * m_SpeedMultiplier); m_SpeedMultiplier += e.DeltaY * (0.1 * m_SpeedMultiplier);
m_Config->Set("Editor.CameraSpeed", m_SpeedMultiplier); m_Config->Set("Editor.CameraSpeed", m_SpeedMultiplier);
m_Config->SaveToDisk(); m_Config->SaveToDisk();
return true; return true;
+30
View File
@@ -7,6 +7,7 @@
#include <nativefiledialog/nfd.h> #include <nativefiledialog/nfd.h>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/any.hpp> #include <boost/any.hpp>
#include <boost/algorithm/string/replace.hpp>
#include "../Common.h" #include "../Common.h"
#include "../GLM.h" #include "../GLM.h"
#include <glm/gtx/common.hpp> #include <glm/gtx/common.hpp>
@@ -18,6 +19,8 @@
#include "../Core/ResourceManager.h" #include "../Core/ResourceManager.h"
#include "../Core/EPause.h" #include "../Core/EPause.h"
#include "../Core/EKeyDown.h" #include "../Core/EKeyDown.h"
#include "../Core/ELockMouse.h"
#include "../Core/EFileDropped.h"
#include "../Rendering/Texture.h" #include "../Rendering/Texture.h"
class EditorGUI class EditorGUI
@@ -32,6 +35,12 @@ public:
Scale Scale
}; };
enum class WidgetSpace
{
Global,
Local
};
void Draw(); void Draw();
void SelectEntity(EntityWrapper entity); void SelectEntity(EntityWrapper entity);
@@ -73,6 +82,9 @@ public:
// Called when the user selects a widget mode. // Called when the user selects a widget mode.
typedef std::function<void(WidgetMode)> OnWidgetMode_t; typedef std::function<void(WidgetMode)> OnWidgetMode_t;
void SetWidgetModeCallback(OnWidgetMode_t f) { m_OnWidgetMode = f; } void SetWidgetModeCallback(OnWidgetMode_t f) { m_OnWidgetMode = f; }
// Called when the user selects a widget space.
typedef std::function<void(WidgetSpace)> OnWidgetSpace_t;
void SetWidgetSpaceCallback(OnWidgetSpace_t f) { m_OnWidgetSpace = f; }
private: private:
World* m_World; World* m_World;
@@ -93,8 +105,12 @@ private:
EntityWrapper m_CurrentlyDragging = EntityWrapper::Invalid; EntityWrapper m_CurrentlyDragging = EntityWrapper::Invalid;
std::string m_LastErrorMessage; std::string m_LastErrorMessage;
WidgetMode m_CurrentWidgetMode = WidgetMode::Translate; WidgetMode m_CurrentWidgetMode = WidgetMode::Translate;
WidgetSpace m_CurrentWidgetSpace = WidgetSpace::Global;
std::set<std::string> m_ModalsToOpen; std::set<std::string> m_ModalsToOpen;
std::map<std::string, boost::any> m_ModalData; std::map<std::string, boost::any> m_ModalData;
std::string m_DroppedFile = "";
bool m_Paused = false;
bool m_MouseLocked = false;
// Callbacks // Callbacks
OnEntitySelectedCallback_t m_OnEntitySelected = nullptr; OnEntitySelectedCallback_t m_OnEntitySelected = nullptr;
@@ -107,10 +123,21 @@ private:
OnComponentAttach_t m_OnComponentAttach = nullptr; OnComponentAttach_t m_OnComponentAttach = nullptr;
OnComponentDelete_t m_OnComponentDelete = nullptr; OnComponentDelete_t m_OnComponentDelete = nullptr;
OnWidgetMode_t m_OnWidgetMode = nullptr; OnWidgetMode_t m_OnWidgetMode = nullptr;
OnWidgetSpace_t m_OnWidgetSpace = nullptr;
// Events // Events
EventRelay<EditorGUI, Events::KeyDown> m_EKeyDown; EventRelay<EditorGUI, Events::KeyDown> m_EKeyDown;
bool OnKeyDown(const Events::KeyDown& e); bool OnKeyDown(const Events::KeyDown& e);
EventRelay<EditorGUI, Events::FileDropped> m_EFileDropped;
bool OnFileDropped(const Events::FileDropped& e);
EventRelay<EditorGUI, Events::Pause> m_EPause;
bool OnPause(const Events::Pause& e);
EventRelay<EditorGUI, Events::Resume> m_EResume;
bool OnResume(const Events::Resume& e);
EventRelay<EditorGUI, Events::LockMouse> m_ELockMouse;
bool OnLockMouse(const Events::LockMouse& e);
EventRelay<EditorGUI, Events::UnlockMouse> m_EUnlockMouse;
bool OnUnlockMouse(const Events::UnlockMouse& e);
// Utility functions // Utility functions
boost::filesystem::path fileOpenDialog(); boost::filesystem::path fileOpenDialog();
@@ -118,6 +145,9 @@ private:
const std::string formatEntityName(EntityWrapper entity); const std::string formatEntityName(EntityWrapper entity);
GLuint tryLoadTexture(std::string filePath); GLuint tryLoadTexture(std::string filePath);
void openModal(const std::string& modal); void openModal(const std::string& modal);
void setWidgetMode(WidgetMode mode);
void toggleWidgetSpace();
static bool compareCharArray(const char* c1, const char* c2);
// Entity file handling methods // Entity file handling methods
void entityImport(World* world); void entityImport(World* world);
+2
View File
@@ -41,6 +41,7 @@ private:
double m_LastTime = 0.f; double m_LastTime = 0.f;
bool m_Enabled = true; bool m_Enabled = true;
EditorGUI::WidgetMode m_WidgetMode = EditorGUI::WidgetMode::Translate; EditorGUI::WidgetMode m_WidgetMode = EditorGUI::WidgetMode::Translate;
EditorGUI::WidgetSpace m_WidgetSpace = EditorGUI::WidgetSpace::Global;
EntityWrapper m_Widget = EntityWrapper::Invalid; EntityWrapper m_Widget = EntityWrapper::Invalid;
EntityWrapper m_CurrentSelection = EntityWrapper::Invalid; EntityWrapper m_CurrentSelection = EntityWrapper::Invalid;
@@ -57,6 +58,7 @@ private:
void OnEntityChangeName(EntityWrapper entity, const std::string& name); void OnEntityChangeName(EntityWrapper entity, const std::string& name);
void OnComponentAttach(EntityWrapper entity, const std::string& componentType); void OnComponentAttach(EntityWrapper entity, const std::string& componentType);
void OnComponentDelete(EntityWrapper entity, const std::string& componentType); void OnComponentDelete(EntityWrapper entity, const std::string& componentType);
void OnWidgetSpace(EditorGUI::WidgetSpace widgetSpace);
// Events // Events
EventRelay<EditorSystem, Events::MousePress> m_EMousePress; EventRelay<EditorSystem, Events::MousePress> m_EMousePress;
+7 -11
View File
@@ -25,27 +25,23 @@ class IRenderer
{ {
public: public:
GLFWwindow* Window() const { return m_Window; } GLFWwindow* Window() const { return m_Window; }
//Returns screensize including window border and header //Returns screen size including window border and header
Rectangle Resolution() const { return m_Resolution; } Rectangle Resolution() const { return m_Resolution; }
void SetResolution(const Rectangle& resolution) { m_Resolution = resolution; } virtual void SetResolution(const Rectangle& resolution) { m_Resolution = resolution; }
bool Fullscreen() { return m_Fullscreen; } bool Fullscreen() { return m_Fullscreen; }
void SetFullscreen(bool fullscreen) { m_Fullscreen = fullscreen; } virtual void SetFullscreen(bool fullscreen) { m_Fullscreen = fullscreen; }
bool VSYNC() const { return m_VSYNC; } bool VSYNC() const { return m_VSYNC; }
void SetVSYNC(bool vsync) { m_VSYNC = vsync; } virtual void SetVSYNC(bool vsync) { m_VSYNC = vsync; }
//Returns screensize excluding window border and header //Returns screen size excluding window border and header
Rectangle GetViewPortSize() const { return m_ViewPortWidth; } Rectangle GetViewportSize() const { return m_ViewportSize; }
void SetViewPortSize(const Rectangle& viewportWidth) { m_ViewPortWidth = viewportWidth; }
virtual void Initialize() = 0; virtual void Initialize() = 0;
virtual void Update(double dt) = 0; virtual void Update(double dt) = 0;
virtual void Draw(RenderFrame& rq) = 0; virtual void Draw(RenderFrame& rq) = 0;
virtual PickData Pick(glm::vec2 screenCord) = 0; virtual PickData Pick(glm::vec2 screenCord) = 0;
World* m_World; //Temp world, untill viktor merge.
protected: protected:
Rectangle m_Resolution = Rectangle::Rectangle(1280, 720); Rectangle m_Resolution = Rectangle::Rectangle(1280, 720);
Rectangle m_ViewPortWidth = Rectangle::Rectangle(1280, 720); Rectangle m_ViewportSize = Rectangle::Rectangle(1280, 720);
bool m_Fullscreen = false; bool m_Fullscreen = false;
bool m_VSYNC = false; bool m_VSYNC = false;
int m_GLVersion[2]; int m_GLVersion[2];
+11 -11
View File
@@ -75,21 +75,21 @@ private:
void ReadMeshFile(std::string filePath); void ReadMeshFile(std::string filePath);
void ReadMeshFileHeader(unsigned int& offset, char* fileData, unsigned int& fileByteSize); void ReadMeshFileHeader(std::size_t& offset, char* fileData);
void ReadMesh(unsigned int& offset, char* fileData, unsigned int& fileByteSize); void ReadMesh(std::size_t& offset, char* fileData, const unsigned int& fileByteSize);
void ReadVertices(unsigned int& offset, char* fileData, unsigned int& fileByteSize); void ReadVertices(std::size_t& offset, char* fileData, const unsigned int& fileByteSize);
void ReadIndices(unsigned int& offset, char* fileData, unsigned int& fileByteSize); void ReadIndices(std::size_t& offset, char* fileData, const unsigned int& fileByteSize);
void ReadMaterialFile(std::string filePath); void ReadMaterialFile(std::string filePath);
void ReadMaterials(unsigned int &offset, char* fileData, unsigned int& fileByteSize); void ReadMaterials(std::size_t& offset, char* fileData, const unsigned int& fileByteSize);
void ReadMaterialSingle(unsigned int &offset, char* fileData, unsigned int& fileByteSize); void ReadMaterialSingle(std::size_t& offset, char* fileData, const unsigned int& fileByteSize);
void ReadAnimationFile(std::string filePath); void ReadAnimationFile(std::string filePath);
void ReadAnimationBindPoses(unsigned int &offset, char* fileData, unsigned int& fileByteSize); void ReadAnimationBindPoses(std::size_t& offset, char* fileData, const unsigned int& fileByteSize);
void ReadAnimationJoint(unsigned int &offset, char* fileData, unsigned int& fileByteSize); void ReadAnimationJoint(std::size_t& offset, char* fileData, const unsigned int& fileByteSize);
void ReadAnimationClips(unsigned int &offset, char* fileData, unsigned int& fileByteSize, unsigned int numberOfClips); void ReadAnimationClips(std::size_t& offset, char* fileData, const unsigned int& fileByteSize, unsigned int numberOfClips);
void ReadAnimationClipSingle(unsigned int &offset, char* fileData, unsigned int& fileByteSize, unsigned int clipIndex); void ReadAnimationClipSingle(std::size_t& offset, char* fileData, const unsigned int& fileByteSize, unsigned int clipIndex);
void ReadAnimationKeyFrame(unsigned int &offset, char* fileData, unsigned int& fileByteSize, unsigned int numberOfJoints, Skeleton::Animation& animation); void ReadAnimationKeyFrame(std::size_t& offset, char* fileData, const unsigned int& fileByteSize, unsigned int numberOfJoints, Skeleton::Animation& animation);
//void CreateSkeleton(std::vector<std::tuple<std::string, glm::mat4>> &boneInfo, std::map<std::string, int> &boneNameMapping, aiNode* node, int parentID); //void CreateSkeleton(std::vector<std::tuple<std::string, glm::mat4>> &boneInfo, std::map<std::string, int> &boneNameMapping, aiNode* node, int parentID);
}; };
+1
View File
@@ -51,6 +51,7 @@ private:
GUI::Frame* m_FrameStack; GUI::Frame* m_FrameStack;
World* m_World; World* m_World;
Octree<EntityAABB>* m_OctreeCollision; Octree<EntityAABB>* m_OctreeCollision;
Octree<EntityAABB>* m_OctreeTrigger;
Octree<EntityAABB>* m_OctreeFrustrumCulling; Octree<EntityAABB>* m_OctreeFrustrumCulling;
SystemPipeline* m_SystemPipeline; SystemPipeline* m_SystemPipeline;
RenderFrame* m_RenderFrame; RenderFrame* m_RenderFrame;
-4
View File
@@ -15,10 +15,6 @@ Space=Jump
LeftControl=Crouch LeftControl=Crouch
LeftShift=Sprint LeftShift=Sprint
F1=ToggleEditor F1=ToggleEditor
1=EditorToolMove
2=EditorToolRotate
3=EditorToolScale
X=EditorToggleTransformSpace
C=ConnectToServer C=ConnectToServer
N=SwitchToServer N=SwitchToServer
M=SwitchToClient M=SwitchToClient
+1 -1
View File
@@ -6,7 +6,7 @@
<xs:element name="CapturePoint"> <xs:element name="CapturePoint">
<xs:annotation> <xs:annotation>
<xs:documentation>A Capture Point. Add a Team Component to specify who currently owns it</xs:documentation> <xs:documentation>A Capture Point. Make sure to update the HomePoint,CapturePointNumber,Team for each</xs:documentation>
</xs:annotation> </xs:annotation>
<xs:complexType> <xs:complexType>
<xs:all> <xs:all>
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:AABB/>
<c:CapturePoint/>
<c:Model>
<Resource>C:\Users\123456\Workspace\TacticalZ\assets\Models\Core\UnitSphere.mesh</Resource>
</c:Model>
<c:Team/>
<c:Transform/>
<c:Trigger/>
</Components>
<Children/>
</Entity>
@@ -0,0 +1,173 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:Transform>
<Position X="0.340887427" Y="0" Z="0"/>
</c:Transform>
</Components>
<Children>
<Entity>
<Components>
<c:AABB/>
<c:CapturePoint>
<HomePointForTeam>
<Red/>
</HomePointForTeam>
</c:CapturePoint>
<c:Model>
<Resource>C:\Users\123456\Workspace\TacticalZ\assets\Models\Core\UnitSphere.mesh</Resource>
<Color A="1" B="0" G="0.200000003" R="1"/>
</c:Model>
<c:Team>
<Team>
<Red/>
</Team>
</c:Team>
<c:Transform>
<Position X="6.60000038" Y="0" Z="0"/>
</c:Transform>
<c:Trigger/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:AABB/>
<c:CapturePoint>
<CapturePointNumber>1</CapturePointNumber>
</c:CapturePoint>
<c:Model>
<Resource>C:\Users\123456\Workspace\TacticalZ\assets\Models\Core\UnitSphere.mesh</Resource>
<Color A="1" B="1" G="1" R="0"/>
</c:Model>
<c:Team/>
<c:Transform>
<Position X="4.46673203" Y="0" Z="3.50259304"/>
</c:Transform>
<c:Trigger/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:AABB/>
<c:CapturePoint>
<CapturePointNumber>2</CapturePointNumber>
</c:CapturePoint>
<c:Model>
<Resource>C:\Users\123456\Workspace\TacticalZ\assets\Models\Core\UnitSphere.mesh</Resource>
<Color A="1" B="1" G="0.200000003" R="0"/>
</c:Model>
<c:Team>
<Team>
<Blue/>
</Team>
</c:Team>
<c:Transform>
<Position X="3.00000024" Y="0" Z="0.113596022"/>
</c:Transform>
<c:Trigger/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:AABB/>
<c:CapturePoint>
<CapturePointNumber>3</CapturePointNumber>
</c:CapturePoint>
<c:Model>
<Resource>C:\Users\123456\Workspace\TacticalZ\assets\Models\Core\UnitSphere.mesh</Resource>
<Color A="1" B="1" G="0.200000003" R="0"/>
</c:Model>
<c:Team>
<Team>
<Blue/>
</Team>
</c:Team>
<c:Transform>
<Position X="1.75382805" Y="0" Z="0.0895374417"/>
</c:Transform>
<c:Trigger/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:AABB/>
<c:CapturePoint>
<HomePointForTeam>
<Blue/>
</HomePointForTeam>
<CapturePointNumber>4</CapturePointNumber>
</c:CapturePoint>
<c:Model>
<Resource>C:\Users\123456\Workspace\TacticalZ\assets\Models\Core\UnitSphere.mesh</Resource>
<Color A="1" B="1" G="0.200000003" R="0"/>
</c:Model>
<c:Team>
<Team>
<Blue/>
</Team>
</c:Team>
<c:Transform>
<Position X="0.56674248" Y="0" Z="0"/>
</c:Transform>
<c:Trigger/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:AABB/>
<c:Health/>
<c:Model>
<Resource>C:\Users\123456\Workspace\TacticalZ\assets\Models\Core\UnitCube.mesh</Resource>
</c:Model>
<c:Player/>
<c:Team>
<Team>
<Blue/>
</Team>
</c:Team>
<c:Transform>
<Position X="4.29100037" Y="-0.08556436" Z="1.29717529"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:AABB/>
<c:Health/>
<c:Model>
<Resource>C:\Users\123456\Workspace\TacticalZ\assets\Models\Core\UnitCube.mesh</Resource>
</c:Model>
<c:Player/>
<c:Team>
<Team>
<Red/>
</Team>
</c:Team>
<c:Transform>
<Position X="5.43557501" Y="0.888866663" Z="1.55849135"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Model>
<Resource>C:\Users\123456\Workspace\TacticalZ\assets\Models\DummyScene.mesh</Resource>
</c:Model>
<c:Transform>
<Position X="-0.600000024" Y="0" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
+3 -3
View File
@@ -76,18 +76,18 @@ bool TriggerSystem::throwLeaveIfWasInTrigger(std::unordered_set<EntityWrapper>&
bool TriggerSystem::OnTouch(const Events::TriggerTouch &event) bool TriggerSystem::OnTouch(const Events::TriggerTouch &event)
{ {
LOG_INFO("Player entity %i touched trigger entity %i.", event.Entity, event.Trigger); LOG_INFO("Player entity %i touched trigger entity %i.", event.Entity.ID, event.Trigger.ID);
return true; return true;
} }
bool TriggerSystem::OnEnter(const Events::TriggerEnter &event) bool TriggerSystem::OnEnter(const Events::TriggerEnter &event)
{ {
LOG_INFO("Player entity %i entered trigger entity %i.", event.Entity, event.Trigger); LOG_INFO("Player entity %i entered trigger entity %i.", event.Entity.ID, event.Trigger.ID);
return true; return true;
} }
bool TriggerSystem::OnLeave(const Events::TriggerLeave &event) bool TriggerSystem::OnLeave(const Events::TriggerLeave &event)
{ {
LOG_INFO("Player entity %i left trigger entity %i.", event.Entity, event.Trigger); LOG_INFO("Player entity %i left trigger entity %i.", event.Entity.ID, event.Trigger.ID);
return true; return true;
} }
+2 -2
View File
@@ -40,9 +40,9 @@ void EntityFile::setReaderFeatures(xercesc::SAX2XMLReader* reader)
reader->setFeature(XMLUni::fgXercesCalculateSrcOfs, true); reader->setFeature(XMLUni::fgXercesCalculateSrcOfs, true);
} }
std::size_t EntityFile::GetTypeStride(std::string typeName) unsigned int EntityFile::GetTypeStride(std::string typeName)
{ {
std::map<std::string, size_t> typeStrides{ std::map<std::string, unsigned int> typeStrides{
{ "bool", sizeof(bool) }, { "bool", sizeof(bool) },
{ "int", sizeof(int) }, { "int", sizeof(int) },
{ "float", sizeof(float) }, { "float", sizeof(float) },
+1 -1
View File
@@ -114,7 +114,7 @@ void EntityFilePreprocessor::parseComponentInfo()
std::string baseType = XS::ToString(elementDeclaration->getTypeDefinition()->getBaseType()->getName()); std::string baseType = XS::ToString(elementDeclaration->getTypeDefinition()->getBaseType()->getName());
std::string effectiveType = type; std::string effectiveType = type;
size_t stride = EntityFile::GetTypeStride(type); unsigned int stride = EntityFile::GetTypeStride(type);
if (stride == 0) { if (stride == 0) {
stride = EntityFile::GetTypeStride(baseType); stride = EntityFile::GetTypeStride(baseType);
if (stride == 0) { if (stride == 0) {
+1 -1
View File
@@ -218,7 +218,7 @@ void InputManager::PublishGamepadAxisIfChanged(int gamepadID, Gamepad::Axis axis
void InputManager::PublishGamepadButtonIfChanged(int gamepadID, Gamepad::Button button) void InputManager::PublishGamepadButtonIfChanged(int gamepadID, Gamepad::Button button)
{ {
bool currentState = m_CurrentGamepadButtonState[gamepadID][static_cast<int>(button)]; bool currentState = m_CurrentGamepadButtonState[gamepadID][static_cast<int>(button)];
float lastState = m_LastGamepadButtonState[gamepadID][static_cast<int>(button)]; bool lastState = m_LastGamepadButtonState[gamepadID][static_cast<int>(button)];
if (currentState != lastState) { if (currentState != lastState) {
if (currentState == true) { if (currentState == true) {
Events::GamepadButtonDown e; Events::GamepadButtonDown e;
+7
View File
@@ -96,6 +96,13 @@ EntityID World::GetParent(EntityID entity)
void World::SetParent(EntityID entity, EntityID parent) void World::SetParent(EntityID entity, EntityID parent)
{ {
// Don't allow an entity to be a child to itself!
if (entity == parent) {
// HACK: We purposely don't check the whole hierarchy of children here, since it would be way too slow.
// This might result in infinite loops if an entity somehow ends up as a child.
return;
}
EntityID lastParent = m_EntityParents.at(entity); EntityID lastParent = m_EntityParents.at(entity);
auto parentChildren = m_EntityChildren.equal_range(lastParent); auto parentChildren = m_EntityChildren.equal_range(lastParent);
for (auto it = parentChildren.first; it != parentChildren.second; it++) { for (auto it = parentChildren.first; it != parentChildren.second; it++) {
+141 -26
View File
@@ -6,6 +6,11 @@ EditorGUI::EditorGUI(World* world, EventBroker* eventBroker)
, m_EventBroker(eventBroker) , m_EventBroker(eventBroker)
{ {
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &EditorGUI::OnKeyDown); EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &EditorGUI::OnKeyDown);
EVENT_SUBSCRIBE_MEMBER(m_EFileDropped, &EditorGUI::OnFileDropped);
EVENT_SUBSCRIBE_MEMBER(m_EPause, &EditorGUI::OnPause);
EVENT_SUBSCRIBE_MEMBER(m_EResume, &EditorGUI::OnResume);
EVENT_SUBSCRIBE_MEMBER(m_ELockMouse, &EditorGUI::OnLockMouse);
EVENT_SUBSCRIBE_MEMBER(m_EUnlockMouse, &EditorGUI::OnUnlockMouse);
} }
void EditorGUI::Draw() void EditorGUI::Draw()
@@ -37,39 +42,60 @@ void EditorGUI::drawTools()
return; return;
} }
// Widget modes
createWidgetToolButton(WidgetMode::Translate); createWidgetToolButton(WidgetMode::Translate);
if (ImGui::IsItemHovered()) { if (ImGui::IsItemHovered()) {
ImGui::SetTooltip("Translate"); ImGui::SetTooltip("Translate (W)");
} }
ImGui::SameLine(); ImGui::SameLine();
createWidgetToolButton(WidgetMode::Rotate); createWidgetToolButton(WidgetMode::Rotate);
if (ImGui::IsItemHovered()) { if (ImGui::IsItemHovered()) {
ImGui::SetTooltip("Rotate"); ImGui::SetTooltip("Rotate (E)");
} }
ImGui::SameLine(); ImGui::SameLine();
createWidgetToolButton(WidgetMode::Scale); createWidgetToolButton(WidgetMode::Scale);
if (ImGui::IsItemHovered()) { if (ImGui::IsItemHovered()) {
ImGui::SetTooltip("Scale"); ImGui::SetTooltip("Scale (R)");
} }
ImGui::SameLine();
ImGui::ItemSize(ImVec2(5, 0));
// Widget space
ImGui::SameLine();
GLuint spaceTexture = 0;
if (m_CurrentWidgetSpace == WidgetSpace::Global) {
spaceTexture = tryLoadTexture("Textures/Icons/Global.png");
} else if (m_CurrentWidgetSpace == WidgetSpace::Local) {
spaceTexture = tryLoadTexture("Textures/Icons/Local.png");
}
if (ImGui::ImageButton(reinterpret_cast<void*>(spaceTexture), ImVec2(24, 24), ImVec2(0, 1), ImVec2(1, 0), -1, ImVec4(0, 0, 0, 0), ImVec4(1, 1, 1, 1))) {
toggleWidgetSpace();
}
if (ImGui::IsItemHovered()) {
if (m_CurrentWidgetSpace == WidgetSpace::Global) {
ImGui::SetTooltip("Widget space: Global (X)");
} else if (m_CurrentWidgetSpace == WidgetSpace::Local) {
ImGui::SetTooltip("Widget space: Local (X)");
}
}
ImGui::SameLine(); ImGui::SameLine();
ImGui::ItemSize(ImVec2(5, 0)); ImGui::ItemSize(ImVec2(5, 0));
// Play button // Play button
ImGui::SameLine(); ImGui::SameLine();
static bool paused = false; if (ImGui::ImageButton(reinterpret_cast<void*>(tryLoadTexture("Textures/Icons/Play.png")), ImVec2(24, 24), ImVec2(0, 1), ImVec2(1, 0), -1, ImVec4(0, 0, 0, 0), (!m_Paused) ? ImVec4(0, 1, 0, 1) : ImVec4(1, 1, 1, 1))) {
if (ImGui::ImageButton((void*)tryLoadTexture("Textures/Icons/Play.png"), ImVec2(24, 24), ImVec2(0, 1), ImVec2(1, 0), -1, ImVec4(0, 0, 0, 0), (!paused) ? ImVec4(0, 1, 0, 1) : ImVec4(1, 1, 1, 1))) {
Events::Resume e; Events::Resume e;
e.World = m_World; e.World = m_World;
m_EventBroker->Publish(e); m_EventBroker->Publish(e);
paused = false;
} }
// Pause button // Pause button
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::ImageButton((void*)tryLoadTexture("Textures/Icons/Pause.png"), ImVec2(24, 24), ImVec2(0, 1), ImVec2(1, 0), -1, ImVec4(0, 0, 0, 0), (paused) ? ImVec4(0, 1, 0, 1) : ImVec4(1, 1, 1, 1))) { if (ImGui::ImageButton(reinterpret_cast<void*>(tryLoadTexture("Textures/Icons/Pause.png")), ImVec2(24, 24), ImVec2(0, 1), ImVec2(1, 0), -1, ImVec4(0, 0, 0, 0), (m_Paused) ? ImVec4(0, 1, 0, 1) : ImVec4(1, 1, 1, 1))) {
Events::Pause e; Events::Pause e;
e.World = m_World; e.World = m_World;
m_EventBroker->Publish(e); m_EventBroker->Publish(e);
paused = true;
} }
ImGui::End(); ImGui::End();
@@ -168,10 +194,7 @@ bool EditorGUI::drawEntityNode(EntityWrapper entity)
ImGui::Text(formatEntityName(entity).c_str()); ImGui::Text(formatEntityName(entity).c_str());
ImGui::End(); ImGui::End();
} }
}/* else if (m_CurrentlyDragging == entity) { }
LOG_DEBUG("Stopped dragging %i", entity.ID);
m_CurrentlyDragging = EntityWrapper::Invalid;
}*/
// Entity context menu // Entity context menu
std::string contextMenuUniqueID = std::string("EntityContextMenu") + std::to_string(entity.ID); std::string contextMenuUniqueID = std::string("EntityContextMenu") + std::to_string(entity.ID);
if (hovered && ImGui::IsMouseClicked(1)) { if (hovered && ImGui::IsMouseClicked(1)) {
@@ -234,10 +257,12 @@ void EditorGUI::drawComponents(EntityWrapper entity)
componentTypes.push_back(pair.first.c_str()); componentTypes.push_back(pair.first.c_str());
} }
} }
// Sort components in alphabetical order
std::sort(componentTypes.begin(), componentTypes.end(), compareCharArray);
// Draw combo box // Draw combo box
ImGui::PushItemWidth(ImGui::GetContentRegionAvailWidth() - 10.f); ImGui::PushItemWidth(ImGui::GetContentRegionAvailWidth() - 10.f);
int selectedItem = -1; int selectedItem = -1;
if (ImGui::Combo("", &selectedItem, componentTypes.data(), componentTypes.size())) { if (ImGui::Combo("", &selectedItem, componentTypes.data(), static_cast<int>(componentTypes.size()), static_cast<int>(componentTypes.size()))) {
if (selectedItem != -1) { if (selectedItem != -1) {
if (m_OnComponentAttach != nullptr) { if (m_OnComponentAttach != nullptr) {
std::string chosenComponentType(componentTypes.at(selectedItem)); std::string chosenComponentType(componentTypes.at(selectedItem));
@@ -283,9 +308,8 @@ bool EditorGUI::drawComponentNode(EntityWrapper entity, const ComponentInfo& ci)
// Draw component fields // Draw component fields
ComponentWrapper& component = entity.World->GetComponent(entity.ID, ci.Name); ComponentWrapper& component = entity.World->GetComponent(entity.ID, ci.Name);
for (auto& kv : ci.Fields) { for (auto& fieldName : ci.FieldsInOrder) {
const std::string& fieldName = kv.first; const ComponentInfo::Field_t& field = ci.Fields.at(fieldName);
const ComponentInfo::Field_t& field = kv.second;
// Draw the field widget based on its type // Draw the field widget based on its type
bool dirty = drawComponentField(component, field); bool dirty = drawComponentField(component, field);
@@ -435,18 +459,31 @@ bool EditorGUI::drawComponentField_bool(ComponentWrapper &c, const ComponentInfo
bool EditorGUI::drawComponentField_string(ComponentWrapper &c, const ComponentInfo::Field_t &field) bool EditorGUI::drawComponentField_string(ComponentWrapper &c, const ComponentInfo::Field_t &field)
{ {
bool result = false;
auto& val = c.Field<std::string>(field.Name); auto& val = c.Field<std::string>(field.Name);
char tempString[1024]; // Let's just hope this is an sufficiently large buffer for strings :) char tempString[1024]; // Let's just hope this is an sufficiently large buffer for strings :)
tempString[1023] = '\0'; // Null terminator just in case the string is larger than the buffer tempString[1023] = '\0'; // Null terminator just in case the string is larger than the buffer
// Copy the string into the buffer, taking the null terminator into account // Copy the string into the buffer, taking the null terminator into account
memcpy(tempString, val.c_str(), std::min(val.length() + 1, sizeof(tempString) - 1)); memcpy(tempString, val.c_str(), std::min(val.length() + 1, sizeof(tempString) - 1));
if (ImGui::InputText("", tempString, sizeof(tempString))) { if (ImGui::InputText("", tempString, sizeof(tempString))) {
val = std::string(tempString); val = std::string(tempString);
return true; result = true;
} else {
return false;
} }
// TODO: Handle drag and drop of files
// Handle file drag and drop
if (ImGui::IsItemHovered() && !m_DroppedFile.empty()) {
// Unset potential input focus or our newly set value will be overwritten!
if (ImGui::IsItemActive()) {
ImGui::SetActiveID(0, nullptr);
}
// Set the actual dropped value
val = m_DroppedFile;
m_DroppedFile = "";
}
return result;
} }
void EditorGUI::drawModals() void EditorGUI::drawModals()
@@ -528,7 +565,7 @@ void EditorGUI::createWidgetToolButton(WidgetMode mode)
break; break;
} }
if (ImGui::ImageButton( if (ImGui::ImageButton(
(void*)texture, reinterpret_cast<void*>(texture),
ImVec2(24, 24), ImVec2(24, 24),
ImVec2(0, 1), ImVec2(0, 1),
ImVec2(1, 0), ImVec2(1, 0),
@@ -537,10 +574,7 @@ void EditorGUI::createWidgetToolButton(WidgetMode mode)
(m_CurrentWidgetMode == mode) ? ImVec4(0, 1, 0, 1) : ImVec4(1, 1, 1, 1) (m_CurrentWidgetMode == mode) ? ImVec4(0, 1, 0, 1) : ImVec4(1, 1, 1, 1)
) )
) { ) {
if (m_OnWidgetMode != nullptr) { setWidgetMode(mode);
m_OnWidgetMode(mode);
}
m_CurrentWidgetMode = mode;
} }
} }
@@ -570,6 +604,61 @@ bool EditorGUI::OnKeyDown(const Events::KeyDown& e)
} }
} }
if (!m_MouseLocked) {
if (e.KeyCode == GLFW_KEY_W) {
setWidgetMode(WidgetMode::Translate);
}
if (e.KeyCode == GLFW_KEY_E) {
setWidgetMode(WidgetMode::Rotate);
}
if (e.KeyCode == GLFW_KEY_R) {
setWidgetMode(WidgetMode::Scale);
}
if (e.KeyCode == GLFW_KEY_X) {
toggleWidgetSpace();
}
}
return true;
}
bool EditorGUI::OnFileDropped(const Events::FileDropped& e)
{
// Make a best effort to make the path relative to the working directory of the executable
m_DroppedFile = boost::filesystem::path(e.Path).lexically_relative(boost::filesystem::current_path()).string();
// Compensate for Windows retardedness
std::replace(m_DroppedFile.begin(), m_DroppedFile.end(), '\\', '/');
// Special case for when people drop from the asset folder instead of from the symlink to the asset folders in bin
boost::algorithm::replace_first(m_DroppedFile, "../assets/", "");
return true;
}
bool EditorGUI::OnPause(const Events::Pause& e)
{
if (e.World == m_World) {
m_Paused = true;
}
return true;
}
bool EditorGUI::OnResume(const Events::Resume& e)
{
if (e.World == m_World) {
m_Paused = false;
}
return true;
}
bool EditorGUI::OnLockMouse(const Events::LockMouse& e)
{
m_MouseLocked = true;
return true;
}
bool EditorGUI::OnUnlockMouse(const Events::UnlockMouse& e)
{
m_MouseLocked = false;
return true; return true;
} }
@@ -644,6 +733,32 @@ void EditorGUI::openModal(const std::string& modal)
m_ModalsToOpen.insert(modal); m_ModalsToOpen.insert(modal);
} }
void EditorGUI::setWidgetMode(WidgetMode mode)
{
if (m_OnWidgetMode != nullptr) {
m_OnWidgetMode(mode);
}
m_CurrentWidgetMode = mode;
}
void EditorGUI::toggleWidgetSpace()
{
if (m_CurrentWidgetSpace == WidgetSpace::Global) {
m_CurrentWidgetSpace = WidgetSpace::Local;
} else if (m_CurrentWidgetSpace == WidgetSpace::Local) {
m_CurrentWidgetSpace = WidgetSpace::Global;
}
if (m_OnWidgetSpace != nullptr) {
m_OnWidgetSpace(m_CurrentWidgetSpace);
}
}
bool EditorGUI::compareCharArray(const char* c1, const char* c2)
{
return strcmp(c1, c2) < 0;
}
void EditorGUI::SetDirty(EntityWrapper entity) void EditorGUI::SetDirty(EntityWrapper entity)
{ {
EntityWrapper baseParent = entity; EntityWrapper baseParent = entity;
@@ -731,7 +846,7 @@ void EditorGUI::entityDelete(EntityWrapper entity)
void EditorGUI::entityChangeParent(EntityWrapper entity, EntityWrapper parent) void EditorGUI::entityChangeParent(EntityWrapper entity, EntityWrapper parent)
{ {
if (entity == parent) { if (entity == parent || parent.IsChildOf(entity)) {
return; return;
} }
+3 -3
View File
@@ -80,9 +80,9 @@ bool EditorRenderSystem::OnSetCamera(Events::SetCamera& e)
{ {
ComponentWrapper cTransform = e.CameraEntity["Transform"]; ComponentWrapper cTransform = e.CameraEntity["Transform"];
ComponentWrapper cCamera = e.CameraEntity["Camera"]; ComponentWrapper cCamera = e.CameraEntity["Camera"];
m_EditorCamera->SetFOV((double)cCamera["FOV"]); m_EditorCamera->SetFOV(static_cast<float>((double)cCamera["FOV"]));
m_EditorCamera->SetNearClip((double)cCamera["NearClip"]); m_EditorCamera->SetNearClip(static_cast<float>((double)cCamera["NearClip"]));
m_EditorCamera->SetFarClip((double)cCamera["FarClip"]); m_EditorCamera->SetFarClip(static_cast<float>((double)cCamera["FarClip"]));
m_EditorCamera->SetPosition(cTransform["Position"]); m_EditorCamera->SetPosition(cTransform["Position"]);
m_EditorCamera->SetOrientation(glm::quat((const glm::vec3&)cTransform["Orientation"])); m_EditorCamera->SetOrientation(glm::quat((const glm::vec3&)cTransform["Orientation"]));
m_CurrentCamera = e.CameraEntity; m_CurrentCamera = e.CameraEntity;
+38 -10
View File
@@ -31,6 +31,7 @@ EditorSystem::EditorSystem(World* world, EventBroker* eventBroker, IRenderer* re
m_EditorGUI->SetComponentAttachCallback(std::bind(&EditorSystem::OnComponentAttach, this, std::placeholders::_1, std::placeholders::_2)); m_EditorGUI->SetComponentAttachCallback(std::bind(&EditorSystem::OnComponentAttach, this, std::placeholders::_1, std::placeholders::_2));
m_EditorGUI->SetComponentDeleteCallback(std::bind(&EditorSystem::OnComponentDelete, this, std::placeholders::_1, std::placeholders::_2)); m_EditorGUI->SetComponentDeleteCallback(std::bind(&EditorSystem::OnComponentDelete, this, std::placeholders::_1, std::placeholders::_2));
m_EditorGUI->SetWidgetModeCallback(std::bind(&EditorSystem::setWidgetMode, this, std::placeholders::_1)); m_EditorGUI->SetWidgetModeCallback(std::bind(&EditorSystem::setWidgetMode, this, std::placeholders::_1));
m_EditorGUI->SetWidgetSpaceCallback(std::bind(&EditorSystem::OnWidgetSpace, this, std::placeholders::_1));
EVENT_SUBSCRIBE_MEMBER(m_EMousePress, &EditorSystem::OnMousePress); EVENT_SUBSCRIBE_MEMBER(m_EMousePress, &EditorSystem::OnMousePress);
EVENT_SUBSCRIBE_MEMBER(m_EWidgetDelta, &EditorSystem::OnWidgetDelta); EVENT_SUBSCRIBE_MEMBER(m_EWidgetDelta, &EditorSystem::OnWidgetDelta);
@@ -65,7 +66,12 @@ void EditorSystem::Update(double dt)
m_EditorStats->Draw(actualDelta); m_EditorStats->Draw(actualDelta);
if (m_CurrentSelection.Valid() && m_Widget.Valid()) { if (m_CurrentSelection.Valid() && m_Widget.Valid()) {
(glm::vec3&)m_Widget["Transform"]["Position"] = Transform::AbsolutePosition(m_CurrentSelection.World, m_CurrentSelection.ID); (glm::vec3&)m_Widget["Transform"]["Position"] = Transform::AbsolutePosition(m_CurrentSelection);
if (m_WidgetSpace == EditorGUI::WidgetSpace::Local) {
(glm::vec3&)m_Widget["Transform"]["Orientation"] = Transform::AbsoluteOrientationEuler(m_CurrentSelection);
} else {
(glm::vec3&)m_Widget["Transform"]["Orientation"] = glm::vec3(0, 0, 0);
}
} }
m_EditorWorldSystemPipeline->Update(actualDelta); m_EditorWorldSystemPipeline->Update(actualDelta);
@@ -82,11 +88,22 @@ void EditorSystem::Update(double dt)
void EditorSystem::Enable() void EditorSystem::Enable()
{ {
m_EditorCameraInputController->Enable(); m_EditorCameraInputController->Enable();
m_EventBroker->Publish(Events::UnlockMouse()); m_EventBroker->Publish(Events::UnlockMouse());
Events::SetCamera e;
e.CameraEntity = m_EditorCamera; // Enable editor camera
m_EventBroker->Publish(e); Events::SetCamera eSetCamera;
(glm::vec3&)m_EditorCamera["Transform"]["Position"] = Transform::AbsolutePosition(m_ActualCamera); eSetCamera.CameraEntity = m_EditorCamera;
m_EventBroker->Publish(eSetCamera);
if (m_ActualCamera.Valid()) {
(glm::vec3&)m_EditorCamera["Transform"]["Position"] = Transform::AbsolutePosition(m_ActualCamera);
}
// Pause the world we're editing
Events::Pause ePause;
ePause.World = m_World;
m_EventBroker->Publish(ePause);
m_Enabled = true; m_Enabled = true;
} }
@@ -154,6 +171,11 @@ void EditorSystem::OnComponentDelete(EntityWrapper entity, const std::string& co
} }
} }
void EditorSystem::OnWidgetSpace(EditorGUI::WidgetSpace widgetSpace)
{
m_WidgetSpace = widgetSpace;
}
bool EditorSystem::OnMousePress(const Events::MousePress& e) bool EditorSystem::OnMousePress(const Events::MousePress& e)
{ {
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
@@ -170,12 +192,18 @@ bool EditorSystem::OnMousePress(const Events::MousePress& e)
bool EditorSystem::OnWidgetDelta(const Events::WidgetDelta& e) bool EditorSystem::OnWidgetDelta(const Events::WidgetDelta& e)
{ {
if (m_CurrentSelection.Valid()) { if (m_CurrentSelection.Valid()) {
glm::quat parentOrientation; if (m_WidgetSpace == EditorGUI::WidgetSpace::Global) {
EntityWrapper parent = m_CurrentSelection.Parent(); glm::quat parentOrientation;
if (parent.Valid()) { EntityWrapper parent = m_CurrentSelection.Parent();
parentOrientation = glm::inverse(Transform::AbsoluteOrientation(parent.World, parent.ID)); if (parent.Valid()) {
parentOrientation = glm::inverse(Transform::AbsoluteOrientation(parent));
}
(glm::vec3&)m_CurrentSelection["Transform"]["Position"] += parentOrientation * e.Translation;
} else if (m_WidgetSpace == EditorGUI::WidgetSpace::Local) {
glm::quat selectionOri = glm::quat((glm::vec3)m_CurrentSelection["Transform"]["Orientation"]);
glm::vec3 localTranslation = selectionOri * e.Translation;
(glm::vec3&)m_CurrentSelection["Transform"]["Position"] += localTranslation;
} }
(glm::vec3&)m_CurrentSelection["Transform"]["Position"] += parentOrientation * e.Translation;
m_EditorGUI->SetDirty(m_CurrentSelection); m_EditorGUI->SetDirty(m_CurrentSelection);
} }
return true; return true;
+9 -5
View File
@@ -23,14 +23,18 @@ void EditorWidgetSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper
Events::WidgetDelta e; Events::WidgetDelta e;
EntityWrapper moveEntity = entity.Parent(); // Widget axes should have a common parent
if (!moveEntity.Valid()) { EntityWrapper widgetBase = entity.Parent();
moveEntity = entity; if (!widgetBase.Valid()) {
widgetBase = entity;
} }
glm::vec3 widgetBasePos = widgetBase["Transform"]["Position"];
glm::quat widgetBaseOri = glm::quat((glm::vec3)widgetBase["Transform"]["Orientation"]);
auto camera = m_PickData.Camera; auto camera = m_PickData.Camera;
glm::vec3 axis = cEditorWidget["Axis"]; glm::vec3 axis = (glm::vec3)cEditorWidget["Axis"];
glm::vec2 axisScreen = camera->WorldToScreen(axis, m_Renderer->GetViewPortSize()) - camera->WorldToScreen(glm::vec3(0, 0, 0), m_Renderer->GetViewPortSize()); glm::vec3 axisOriented = widgetBaseOri * axis;
glm::vec2 axisScreen = camera->WorldToScreen(widgetBasePos + axisOriented, m_Renderer->GetViewportSize()) - camera->WorldToScreen(widgetBasePos, m_Renderer->GetViewportSize());
float dot = glm::dot(m_MouseDelta, glm::normalize(axisScreen)) / glm::length(axisScreen); float dot = glm::dot(m_MouseDelta, glm::normalize(axisScreen)) / glm::length(axisScreen);
glm::vec3 worldMovement = dot * axis; glm::vec3 worldMovement = dot * axis;
+2 -2
View File
@@ -98,7 +98,7 @@ bool MouseInputHandler::OnMouseMove(const Events::MouseMove& e)
Events::InputCommand ic; Events::InputCommand ic;
ic.PlayerID = -1; ic.PlayerID = -1;
std::tie(ic.Command, ic.Value) = it->second; std::tie(ic.Command, ic.Value) = it->second;
ic.Value *= e.DeltaX; ic.Value *= static_cast<float>(e.DeltaX);
m_InputProxy->Publish(ic); m_InputProxy->Publish(ic);
} }
} }
@@ -109,7 +109,7 @@ bool MouseInputHandler::OnMouseMove(const Events::MouseMove& e)
Events::InputCommand ic; Events::InputCommand ic;
ic.PlayerID = -1; ic.PlayerID = -1;
std::tie(ic.Command, ic.Value) = it->second; std::tie(ic.Command, ic.Value) = it->second;
ic.Value *= e.DeltaY; ic.Value *= static_cast<float>(e.DeltaY);
m_InputProxy->Publish(ic); m_InputProxy->Publish(ic);
} }
} }
+2 -2
View File
@@ -34,12 +34,12 @@ void DrawBloomPass::InitializeShaderPrograms()
void DrawBloomPass::InitializeBuffers() void DrawBloomPass::InitializeBuffers()
{ {
GenerateTexture(&m_GaussianTexture_horiz, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); GenerateTexture(&m_GaussianTexture_horiz, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
m_GaussianFrameBuffer_horiz.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_GaussianTexture_horiz, GL_COLOR_ATTACHMENT0))); m_GaussianFrameBuffer_horiz.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_GaussianTexture_horiz, GL_COLOR_ATTACHMENT0)));
m_GaussianFrameBuffer_horiz.Generate(); m_GaussianFrameBuffer_horiz.Generate();
GenerateTexture(&m_GaussianTexture_vert, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); GenerateTexture(&m_GaussianTexture_vert, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
m_GaussianFrameBuffer_vert.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_GaussianTexture_vert, GL_COLOR_ATTACHMENT0))); m_GaussianFrameBuffer_vert.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_GaussianTexture_vert, GL_COLOR_ATTACHMENT0)));
m_GaussianFrameBuffer_vert.Generate(); m_GaussianFrameBuffer_vert.Generate();
+4 -3
View File
@@ -21,11 +21,11 @@ void DrawFinalPass::InitializeFrameBuffers()
{ {
glGenRenderbuffers(1, &m_DepthBuffer); glGenRenderbuffers(1, &m_DepthBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, m_DepthBuffer); glBindRenderbuffer(GL_RENDERBUFFER, m_DepthBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
GenerateTexture(&m_SceneTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); GenerateTexture(&m_SceneTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
//GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); //GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
//GenerateMipMapTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RGB16F, GL_FLOAT, 4); //GenerateMipMapTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RGB16F, GL_FLOAT, 4);
m_FinalPassFrameBuffer.AddResource(std::shared_ptr<BufferResource>(new RenderBuffer(&m_DepthBuffer, GL_DEPTH_ATTACHMENT))); m_FinalPassFrameBuffer.AddResource(std::shared_ptr<BufferResource>(new RenderBuffer(&m_DepthBuffer, GL_DEPTH_ATTACHMENT)));
@@ -147,6 +147,7 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
if (modelJob) { if (modelJob) {
//bind forward program //bind forward program
m_ForwardPlusProgram->Bind(); m_ForwardPlusProgram->Bind();
glUniform2f(glGetUniformLocation(forwardHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
//bind uniforms //bind uniforms
BindModelUniforms(forwardHandle, modelJob, scene); BindModelUniforms(forwardHandle, modelJob, scene);
+4 -4
View File
@@ -134,8 +134,8 @@ bool ImGuiRenderPass::OnMouseRelease(const Events::MouseRelease& e)
bool ImGuiRenderPass::OnMouseMove(const Events::MouseMove& e) bool ImGuiRenderPass::OnMouseMove(const Events::MouseMove& e)
{ {
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
io.MousePos.x = e.X; io.MousePos.x = static_cast<float>(e.X);
io.MousePos.y = e.Y; io.MousePos.y = static_cast<float>(e.Y);
return true; return true;
} }
@@ -271,7 +271,7 @@ bool ImGuiRenderPass::createFontsTexture()
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
// Store our identifier // Store our identifier
io.Fonts->TexID = (void*)g_FontTexture; io.Fonts->TexID = reinterpret_cast<void*>(g_FontTexture);
// Restore state // Restore state
glBindTexture(GL_TEXTURE_2D, last_texture); glBindTexture(GL_TEXTURE_2D, last_texture);
@@ -291,7 +291,7 @@ void ImGuiRenderPass::newFrame()
io.DisplaySize = ImVec2((float)w, (float)h); io.DisplaySize = ImVec2((float)w, (float)h);
io.DisplayFramebufferScale = ImVec2((float)display_w / w, (float)display_h / h); io.DisplayFramebufferScale = ImVec2((float)display_w / w, (float)display_h / h);
io.DeltaTime = g_DeltaTime; io.DeltaTime = static_cast<float>(g_DeltaTime);
io.KeyCtrl = glfwGetKey(g_Window, GLFW_KEY_LEFT_CONTROL) || glfwGetKey(g_Window, GLFW_KEY_RIGHT_CONTROL); io.KeyCtrl = glfwGetKey(g_Window, GLFW_KEY_LEFT_CONTROL) || glfwGetKey(g_Window, GLFW_KEY_RIGHT_CONTROL);
io.KeyShift = glfwGetKey(g_Window, GLFW_KEY_LEFT_SHIFT) || glfwGetKey(g_Window, GLFW_KEY_RIGHT_SHIFT); io.KeyShift = glfwGetKey(g_Window, GLFW_KEY_LEFT_SHIFT) || glfwGetKey(g_Window, GLFW_KEY_RIGHT_SHIFT);
+5 -5
View File
@@ -25,8 +25,8 @@ void LightCullingPass::GenerateNewFrustum(RenderScene& scene)
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, m_FrustumSSBO); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, m_FrustumSSBO);
glUniformMatrix4fv(glGetUniformLocation(m_CalculateFrustumProgram->GetHandle(), "P"), 1, false, glm::value_ptr(scene.Camera->ProjectionMatrix())); glUniformMatrix4fv(glGetUniformLocation(m_CalculateFrustumProgram->GetHandle(), "P"), 1, false, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(m_CalculateFrustumProgram->GetHandle(), "ScreenDimensions"), m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height); glUniform2f(glGetUniformLocation(m_CalculateFrustumProgram->GetHandle(), "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glDispatchCompute((int)(m_Renderer->GetViewPortSize().Width/(TILE_SIZE*TILE_SIZE) + 1), (int)(m_Renderer->GetViewPortSize().Height/(TILE_SIZE*TILE_SIZE) + 1), 1); glDispatchCompute((int)(m_Renderer->GetViewportSize().Width/(TILE_SIZE*TILE_SIZE) + 1), (int)(m_Renderer->GetViewportSize().Height/(TILE_SIZE*TILE_SIZE) + 1), 1);
GLERROR("CalculateFrustum Error: End"); GLERROR("CalculateFrustum Error: End");
} }
@@ -40,7 +40,7 @@ void LightCullingPass::OnResolutionChange()
void LightCullingPass::SetSSBOSizes() void LightCullingPass::SetSSBOSizes()
{ {
m_NumberOfTiles = (int)(m_Renderer->GetViewPortSize().Width/TILE_SIZE) * (int)(m_Renderer->GetViewPortSize().Height/TILE_SIZE); m_NumberOfTiles = (int)(m_Renderer->GetViewportSize().Width/TILE_SIZE) * (int)(m_Renderer->GetViewportSize().Height/TILE_SIZE);
m_Frustums = new Frustum[m_NumberOfTiles]; m_Frustums = new Frustum[m_NumberOfTiles];
m_LightGrid = new LightGrid[m_NumberOfTiles]; m_LightGrid = new LightGrid[m_NumberOfTiles];
@@ -67,14 +67,14 @@ void LightCullingPass::CullLights(RenderScene& scene)
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
m_LightCullProgram->Bind(); m_LightCullProgram->Bind();
glUniform2f(glGetUniformLocation(m_LightCullProgram->GetHandle(), "ScreenDimensions"), m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height); glUniform2f(glGetUniformLocation(m_LightCullProgram->GetHandle(), "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniformMatrix4fv(glGetUniformLocation(m_LightCullProgram->GetHandle(), "V"), 1, false, glm::value_ptr(scene.Camera->ViewMatrix())); glUniformMatrix4fv(glGetUniformLocation(m_LightCullProgram->GetHandle(), "V"), 1, false, glm::value_ptr(scene.Camera->ViewMatrix()));
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, m_FrustumSSBO); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, m_FrustumSSBO);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, m_LightSSBO); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, m_LightSSBO);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, m_LightGridSSBO); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, m_LightGridSSBO);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, m_LightOffsetSSBO); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, m_LightOffsetSSBO);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, m_LightIndexSSBO); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, m_LightIndexSSBO);
glDispatchCompute(glm::ceil(m_Renderer->GetViewPortSize().Width/ TILE_SIZE), glm::ceil(m_Renderer->GetViewPortSize().Height / TILE_SIZE), 1); glDispatchCompute(glm::ceil(m_Renderer->GetViewportSize().Width/ TILE_SIZE), glm::ceil(m_Renderer->GetViewportSize().Height / TILE_SIZE), 1);
GLERROR("CullLights Error: End"); GLERROR("CullLights Error: End");
} }
+2 -2
View File
@@ -71,12 +71,12 @@ PNG::PNG(std::string path)
png_read_update_info(png_ptr, info_ptr); png_read_update_info(png_ptr, info_ptr);
} }
unsigned int row_bytes = png_get_rowbytes(png_ptr, info_ptr); std::size_t row_bytes = png_get_rowbytes(png_ptr, info_ptr);
this->Data = new unsigned char[height * row_bytes]; this->Data = new unsigned char[height * row_bytes];
png_bytep* row_pointers = new png_bytep[height]; png_bytep* row_pointers = new png_bytep[height];
// Point each row to the continuous data array // Point each row to the continuous data array
for (int i = 0; i < height; ++i) { for (unsigned int i = 0; i < height; ++i) {
// Invert Y for OpenGL // Invert Y for OpenGL
row_pointers[height - 1 - i] = this->Data + i * row_bytes; row_pointers[height - 1 - i] = this->Data + i * row_bytes;
} }
+2 -2
View File
@@ -18,14 +18,14 @@ PickingPass::~PickingPass()
void PickingPass::InitializeTextures() void PickingPass::InitializeTextures()
{ {
GenerateTexture(&m_PickingTexture, GL_CLAMP_TO_BORDER, GL_LINEAR, GenerateTexture(&m_PickingTexture, GL_CLAMP_TO_BORDER, GL_LINEAR,
glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RG8, GL_RG, GL_UNSIGNED_BYTE); glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RG8, GL_RG, GL_UNSIGNED_BYTE);
} }
void PickingPass::InitializeFrameBuffers() void PickingPass::InitializeFrameBuffers()
{ {
glGenRenderbuffers(1, &m_DepthBuffer); glGenRenderbuffers(1, &m_DepthBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, m_DepthBuffer); glBindRenderbuffer(GL_RENDERBUFFER, m_DepthBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
m_PickingBuffer.AddResource(std::shared_ptr<BufferResource>(new RenderBuffer(&m_DepthBuffer, GL_DEPTH_ATTACHMENT))); m_PickingBuffer.AddResource(std::shared_ptr<BufferResource>(new RenderBuffer(&m_DepthBuffer, GL_DEPTH_ATTACHMENT)));
m_PickingBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_PickingTexture, GL_COLOR_ATTACHMENT0))); m_PickingBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_PickingTexture, GL_COLOR_ATTACHMENT0)));
+25 -24
View File
@@ -22,42 +22,42 @@ void RawModelCustom::ReadMeshFile(std::string filePath)
if (!in.is_open()) { if (!in.is_open()) {
throw Resource::FailedLoadingException("Open mesh file failed"); throw Resource::FailedLoadingException("Open mesh file failed");
} }
unsigned int fileByteSize = in.tellg(); unsigned int fileByteSize = static_cast<unsigned int>(in.tellg());
in.seekg(0, std::ios_base::beg); in.seekg(0, std::ios_base::beg);
fileData = new char[fileByteSize]; fileData = new char[fileByteSize];
in.read(fileData, fileByteSize); in.read(fileData, fileByteSize);
in.close(); in.close();
unsigned int offset = 0; std::size_t offset = 0;
if (fileByteSize > 0) { if (fileByteSize > 0) {
ReadMeshFileHeader(offset, fileData, fileByteSize); ReadMeshFileHeader(offset, fileData);
ReadMesh(offset, fileData, fileByteSize); ReadMesh(offset, fileData, fileByteSize);
} }
delete fileData; delete fileData;
} }
void RawModelCustom::ReadMeshFileHeader(unsigned int& offset, char* fileData, unsigned int& fileByteSize) void RawModelCustom::ReadMeshFileHeader(std::size_t& offset, char* fileData)
{ {
#ifdef BOOST_LITTLE_ENDIAN #ifdef BOOST_LITTLE_ENDIAN
m_Vertices.resize(*(unsigned int*)(fileData + offset)); m_Vertices.resize(static_cast<std::size_t>(*(unsigned int*)(fileData + offset)));
offset += sizeof(unsigned int); offset += sizeof(unsigned int);
m_Indices.resize(*(unsigned int*)(fileData + offset)); m_Indices.resize(static_cast<std::size_t>(*(unsigned int*)(fileData + offset)));
offset += sizeof(unsigned int); offset += sizeof(unsigned int);
#else #else
#endif #endif
} }
void RawModelCustom::ReadMesh(unsigned int& offset, char* fileData, unsigned int& fileByteSize) void RawModelCustom::ReadMesh(std::size_t& offset, char* fileData, const unsigned int& fileByteSize)
{ {
ReadVertices(offset, fileData, fileByteSize); ReadVertices(offset, fileData, fileByteSize);
ReadIndices(offset, fileData, fileByteSize); ReadIndices(offset, fileData, fileByteSize);
} }
void RawModelCustom::ReadVertices(unsigned int& offset, char* fileData, unsigned int& fileByteSize) void RawModelCustom::ReadVertices(std::size_t& offset, char* fileData, const unsigned int& fileByteSize)
{ {
#ifdef BOOST_LITTLE_ENDIAN #ifdef BOOST_LITTLE_ENDIAN
if (offset + m_Vertices.size() * sizeof(Vertex) > fileByteSize) { if (offset + m_Vertices.size() * sizeof(Vertex) > fileByteSize) {
throw Resource::FailedLoadingException("Reading vertices failed"); throw Resource::FailedLoadingException("Reading vertices failed");
} }
@@ -67,7 +67,7 @@ void RawModelCustom::ReadVertices(unsigned int& offset, char* fileData, unsigned
#endif #endif
} }
void RawModelCustom::ReadIndices(unsigned int& offset, char* fileData, unsigned int& fileByteSize) void RawModelCustom::ReadIndices(std::size_t& offset, char* fileData, const unsigned int& fileByteSize)
{ {
#ifdef BOOST_LITTLE_ENDIAN #ifdef BOOST_LITTLE_ENDIAN
if (offset + m_Indices.size() * sizeof(unsigned int) > fileByteSize) { if (offset + m_Indices.size() * sizeof(unsigned int) > fileByteSize) {
@@ -90,35 +90,36 @@ void RawModelCustom::ReadMaterialFile(std::string filePath)
if (!in.is_open()) { if (!in.is_open()) {
throw Resource::FailedLoadingException("Open material file failed"); throw Resource::FailedLoadingException("Open material file failed");
} }
unsigned int fileByteSize = in.tellg();
unsigned int fileByteSize = static_cast<unsigned int>(in.tellg());
in.seekg(0, std::ios_base::beg); in.seekg(0, std::ios_base::beg);
fileData = new char[fileByteSize]; fileData = new char[fileByteSize];
in.read(fileData, fileByteSize); in.read(fileData, fileByteSize);
in.close(); in.close();
unsigned int offset = 0; std::size_t offset = 0;
if (fileByteSize > 0) { if (fileByteSize > 0) {
ReadMaterials(offset, fileData, fileByteSize); ReadMaterials(offset, fileData, fileByteSize);
} }
delete fileData; delete fileData;
} }
void RawModelCustom::ReadMaterials(unsigned int& offset, char* fileData, unsigned int& fileByteSize) void RawModelCustom::ReadMaterials(std::size_t& offset, char* fileData, const unsigned int& fileByteSize)
{ {
#ifdef BOOST_LITTLE_ENDIAN #ifdef BOOST_LITTLE_ENDIAN
unsigned int* numMaterials = (unsigned int*)(fileData); unsigned int* numMaterials = (unsigned int*)(fileData);
MaterialGroups.reserve(*numMaterials); MaterialGroups.reserve(*numMaterials);
offset += sizeof(unsigned int); offset += sizeof(unsigned int);
for (int i = 0; i < *numMaterials; i++) { for (unsigned int i = 0; i < *numMaterials; i++) {
ReadMaterialSingle(offset, fileData, fileByteSize); ReadMaterialSingle(offset, fileData, fileByteSize);
} }
#else #else
#endif #endif
} }
void RawModelCustom::ReadMaterialSingle(unsigned int &offset, char* fileData, unsigned int& fileByteSize) void RawModelCustom::ReadMaterialSingle(std::size_t& offset, char* fileData, const unsigned int& fileByteSize)
{ {
MaterialGroup newMaterial; MaterialGroup newMaterial;
@@ -210,14 +211,14 @@ void RawModelCustom::ReadAnimationFile(std::string filePath)
return; return;
} }
unsigned int fileByteSize = in.tellg(); unsigned int fileByteSize = static_cast<unsigned int>(in.tellg());
in.seekg(0, std::ios_base::beg); in.seekg(0, std::ios_base::beg);
fileData = new char[fileByteSize]; fileData = new char[fileByteSize];
in.read(fileData, fileByteSize); in.read(fileData, fileByteSize);
in.close(); in.close();
unsigned int offset = 0; std::size_t offset = 0;
if (fileByteSize > 0) { if (fileByteSize > 0) {
m_Skeleton = new Skeleton(); m_Skeleton = new Skeleton();
@@ -235,7 +236,7 @@ void RawModelCustom::ReadAnimationFile(std::string filePath)
delete fileData; delete fileData;
} }
void RawModelCustom::ReadAnimationBindPoses(unsigned int &offset, char* fileData, unsigned int& fileByteSize) void RawModelCustom::ReadAnimationBindPoses(std::size_t& offset, char* fileData, const unsigned int& fileByteSize)
{ {
#ifdef BOOST_LITTLE_ENDIAN #ifdef BOOST_LITTLE_ENDIAN
unsigned int* numBones = (unsigned int*)(fileData + offset); unsigned int* numBones = (unsigned int*)(fileData + offset);
@@ -248,7 +249,7 @@ void RawModelCustom::ReadAnimationBindPoses(unsigned int &offset, char* fileData
#endif #endif
} }
void RawModelCustom::ReadAnimationJoint(unsigned int &offset, char* fileData, unsigned int& fileByteSize) void RawModelCustom::ReadAnimationJoint(std::size_t& offset, char* fileData, const unsigned int& fileByteSize)
{ {
#ifdef BOOST_LITTLE_ENDIAN #ifdef BOOST_LITTLE_ENDIAN
if (offset + sizeof(unsigned int) > fileByteSize) { if (offset + sizeof(unsigned int) > fileByteSize) {
@@ -290,14 +291,14 @@ void RawModelCustom::ReadAnimationJoint(unsigned int &offset, char* fileData, un
#endif #endif
} }
void RawModelCustom::ReadAnimationClips(unsigned int &offset, char* fileData, unsigned int& fileByteSize, unsigned int numberOfClips) void RawModelCustom::ReadAnimationClips(std::size_t& offset, char* fileData, const unsigned int& fileByteSize, unsigned int numberOfClips)
{ {
for (unsigned int i = 0; i < numberOfClips; i++) { for (unsigned int i = 0; i < numberOfClips; i++) {
ReadAnimationClipSingle(offset, fileData, fileByteSize, i); ReadAnimationClipSingle(offset, fileData, fileByteSize, i);
} }
} }
void RawModelCustom::ReadAnimationClipSingle(unsigned int &offset, char* fileData, unsigned int& fileByteSize, unsigned int clipIndex) void RawModelCustom::ReadAnimationClipSingle(std::size_t& offset, char* fileData, const unsigned int& fileByteSize, unsigned int clipIndex)
{ {
#ifdef BOOST_LITTLE_ENDIAN #ifdef BOOST_LITTLE_ENDIAN
Skeleton::Animation newAnimation; Skeleton::Animation newAnimation;
@@ -342,7 +343,7 @@ void RawModelCustom::ReadAnimationClipSingle(unsigned int &offset, char* fileDat
#endif #endif
} }
void RawModelCustom::ReadAnimationKeyFrame(unsigned int &offset, char* fileData, unsigned int& fileByteSize, unsigned int nrOfJoints, Skeleton::Animation& animation) void RawModelCustom::ReadAnimationKeyFrame(std::size_t& offset, char* fileData, const unsigned int& fileByteSize, unsigned int numberOfJoints, Skeleton::Animation& animation)
{ {
Skeleton::Animation::Keyframe newKeyFrame; Skeleton::Animation::Keyframe newKeyFrame;
@@ -358,12 +359,12 @@ void RawModelCustom::ReadAnimationKeyFrame(unsigned int &offset, char* fileData,
newKeyFrame.Time = *(float*)(fileData + offset); newKeyFrame.Time = *(float*)(fileData + offset);
offset += sizeof(float); offset += sizeof(float);
if (offset + sizeof(Skeleton::Animation::Keyframe::BoneProperty) * nrOfJoints> fileByteSize) { if (offset + sizeof(Skeleton::Animation::Keyframe::BoneProperty) * numberOfJoints> fileByteSize) {
throw Resource::FailedLoadingException("Reading AnimationKeyFrame joints failed"); throw Resource::FailedLoadingException("Reading AnimationKeyFrame joints failed");
} }
Skeleton::Animation::Keyframe::BoneProperty newBone; Skeleton::Animation::Keyframe::BoneProperty newBone;
for (unsigned int i = 0; i < nrOfJoints; i++) { for (unsigned int i = 0; i < numberOfJoints; i++) {
memcpy(&newBone, (fileData + offset), sizeof(Skeleton::Animation::Keyframe::BoneProperty)); memcpy(&newBone, (fileData + offset), sizeof(Skeleton::Animation::Keyframe::BoneProperty));
offset += sizeof(Skeleton::Animation::Keyframe::BoneProperty); offset += sizeof(Skeleton::Animation::Keyframe::BoneProperty);
newKeyFrame.BoneProperties[newBone.ID] = newBone; newKeyFrame.BoneProperties[newBone.ID] = newBone;
+3 -4
View File
@@ -59,10 +59,9 @@ void Renderer::InitializeWindow()
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
int res[2]; int windowSize[2];
glfwGetWindowSize(m_Window, &res[0], &res[1]); glfwGetWindowSize(m_Window, &windowSize[0], &windowSize[1]);
SetViewPortSize(Rectangle::Rectangle(res[0], res[1])); m_ViewportSize = Rectangle(windowSize[0], windowSize[1]);
} }
void Renderer::InitializeShaders() void Renderer::InitializeShaders()
+1 -1
View File
@@ -21,7 +21,7 @@ GLuint Shader::CompileShader(GLenum shaderType, std::string fileName)
return 0; return 0;
const GLchar* shaderFiles = shaderFile.c_str(); const GLchar* shaderFiles = shaderFile.c_str();
const GLint length = shaderFile.length(); const GLint length = static_cast<GLint>(shaderFile.length());
glShaderSource(shader, 1, &shaderFiles, &length); glShaderSource(shader, 1, &shaderFiles, &length);
if (GLERROR("glShaderSource")) if (GLERROR("glShaderSource"))
return 0; return 0;
+2 -2
View File
@@ -53,11 +53,11 @@ std::vector<glm::mat4> Skeleton::GetFrameBones(const Animation& animation, doubl
const Animation::Keyframe& currentFrame = animation.Keyframes[currentKeyframeIndex]; const Animation::Keyframe& currentFrame = animation.Keyframes[currentKeyframeIndex];
const Animation::Keyframe& nextFrame = animation.Keyframes[(currentKeyframeIndex + 1) % animation.Keyframes.size()]; const Animation::Keyframe& nextFrame = animation.Keyframes[(currentKeyframeIndex + 1) % animation.Keyframes.size()];
float alpha = (time - currentFrame.Time) / (nextFrame.Time - currentFrame.Time); double alpha = (time - currentFrame.Time) / (nextFrame.Time - currentFrame.Time);
//auto animationFrame = Animations[""].Keyframes[frame]; //auto animationFrame = Animations[""].Keyframes[frame];
std::map<int, glm::mat4> frameBones; std::map<int, glm::mat4> frameBones;
AccumulateBoneTransforms(noRootMotion, currentFrame, nextFrame, alpha, frameBones, RootBone, glm::mat4(1)); AccumulateBoneTransforms(noRootMotion, currentFrame, nextFrame, static_cast<float>(alpha), frameBones, RootBone, glm::mat4(1));
std::vector<glm::mat4> finalMatrices; std::vector<glm::mat4> finalMatrices;
for (auto &kv : frameBones) { for (auto &kv : frameBones) {
+5 -2
View File
@@ -74,6 +74,7 @@ Game::Game(int argc, char* argv[])
// Create Octrees // Create Octrees
m_OctreeCollision = new Octree<EntityAABB>(AABB(glm::vec3(-100), glm::vec3(100)), 4); m_OctreeCollision = new Octree<EntityAABB>(AABB(glm::vec3(-100), glm::vec3(100)), 4);
m_OctreeTrigger = new Octree<EntityAABB>(AABB(glm::vec3(-100), glm::vec3(100)), 4);
m_OctreeFrustrumCulling = new Octree<EntityAABB>(AABB(glm::vec3(-100), glm::vec3(100)), 4); m_OctreeFrustrumCulling = new Octree<EntityAABB>(AABB(glm::vec3(-100), glm::vec3(100)), 4);
// Create system pipeline // Create system pipeline
m_SystemPipeline = new SystemPipeline(m_World, m_EventBroker); m_SystemPipeline = new SystemPipeline(m_World, m_EventBroker);
@@ -92,14 +93,15 @@ Game::Game(int argc, char* argv[])
m_SystemPipeline->AddSystem<CapturePointSystem>(updateOrderLevel); m_SystemPipeline->AddSystem<CapturePointSystem>(updateOrderLevel);
// Populate Octree with collidables // Populate Octree with collidables
++updateOrderLevel; ++updateOrderLevel;
m_SystemPipeline->AddSystem<CollidableOctreeSystem>(updateOrderLevel, m_OctreeCollision); m_SystemPipeline->AddSystem<CollidableOctreeSystem>(updateOrderLevel, m_OctreeCollision, "Collidable");
m_SystemPipeline->AddSystem<CollidableOctreeSystem>(updateOrderLevel, m_OctreeTrigger, "Player");
m_SystemPipeline->AddSystem<PlayerHUD>(updateOrderLevel); m_SystemPipeline->AddSystem<PlayerHUD>(updateOrderLevel);
m_SystemPipeline->AddSystem<AnimationSystem>(updateOrderLevel); m_SystemPipeline->AddSystem<AnimationSystem>(updateOrderLevel);
// Collision and TriggerSystem should update after player. // Collision and TriggerSystem should update after player.
++updateOrderLevel; ++updateOrderLevel;
m_SystemPipeline->AddSystem<CollisionSystem>(updateOrderLevel, m_OctreeCollision); m_SystemPipeline->AddSystem<CollisionSystem>(updateOrderLevel, m_OctreeCollision);
m_SystemPipeline->AddSystem<TriggerSystem>(updateOrderLevel, m_OctreeCollision); m_SystemPipeline->AddSystem<TriggerSystem>(updateOrderLevel, m_OctreeTrigger);
++updateOrderLevel; ++updateOrderLevel;
m_SystemPipeline->AddSystem<RenderSystem>(updateOrderLevel, m_Renderer, m_RenderFrame); m_SystemPipeline->AddSystem<RenderSystem>(updateOrderLevel, m_Renderer, m_RenderFrame);
++updateOrderLevel; ++updateOrderLevel;
@@ -123,6 +125,7 @@ Game::~Game()
delete m_SoundSystem; delete m_SoundSystem;
delete m_OctreeFrustrumCulling; delete m_OctreeFrustrumCulling;
delete m_OctreeCollision; delete m_OctreeCollision;
delete m_OctreeTrigger;
delete m_World; delete m_World;
delete m_FrameStack; delete m_FrameStack;
delete m_InputProxy; delete m_InputProxy;
+4 -3
View File
@@ -64,9 +64,9 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp
std::map<std::string, int> nextPossibleCapturePoint; std::map<std::string, int> nextPossibleCapturePoint;
nextPossibleCapturePoint["Red"] = -1; nextPossibleCapturePoint["Red"] = -1;
nextPossibleCapturePoint["Blue"] = -1; nextPossibleCapturePoint["Blue"] = -1;
for (size_t i = 0; i < m_NumberOfCapturePoints; i++) for (int i = 0; i < m_NumberOfCapturePoints; i++)
{ {
if (m_CapturePointNumberToEntityMap[i].HasComponent("Team")) { if (!m_CapturePointNumberToEntityMap[i].HasComponent("Team")) {
continue; continue;
} }
ComponentWrapper& capturePointOwnedBy = m_CapturePointNumberToEntityMap[i]["Team"]; ComponentWrapper& capturePointOwnedBy = m_CapturePointNumberToEntityMap[i]["Team"];
@@ -93,7 +93,7 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp
//reset timers and reset the bool that triggers this //reset timers and reset the bool that triggers this
if (m_ResetTimers) { if (m_ResetTimers) {
for (size_t i = 0; i < m_NumberOfCapturePoints; i++) for (int i = 0; i < m_NumberOfCapturePoints; i++)
{ {
ComponentWrapper& capturePoint = m_CapturePointNumberToEntityMap[i]["CapturePoint"]; ComponentWrapper& capturePoint = m_CapturePointNumberToEntityMap[i]["CapturePoint"];
if ((int)capturePoint["CapturePointNumber"] != nextPossibleCapturePoint["Red"] && if ((int)capturePoint["CapturePointNumber"] != nextPossibleCapturePoint["Red"] &&
@@ -119,6 +119,7 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp
if (std::get<1>(triggerTouched) == capturePointEntity) { if (std::get<1>(triggerTouched) == capturePointEntity) {
//some player has touched this - lets figure out: what team, health //some player has touched this - lets figure out: what team, health
EntityWrapper player = std::get<0>(triggerTouched); EntityWrapper player = std::get<0>(triggerTouched);
//check if its really a player that has triggered the touch
if (!player.HasComponent("Player")) { if (!player.HasComponent("Player")) {
//if a non-player has entered the capturePoint, just erase that event and continue //if a non-player has entered the capturePoint, just erase that event and continue
m_ETriggerTouchVector.erase(m_ETriggerTouchVector.begin() + i - 1); m_ETriggerTouchVector.erase(m_ETriggerTouchVector.begin() + i - 1);
+1 -1
View File
@@ -30,7 +30,7 @@ EntityWrapper SpawnerSystem::Spawn(EntityWrapper spawner, EntityWrapper parent /
if (spawnPoints.size() > 1) { if (spawnPoints.size() > 1) {
static std::random_device randomDevice; static std::random_device randomDevice;
static std::mt19937 randomGenerator(randomDevice()); static std::mt19937 randomGenerator(randomDevice());
std::uniform_int_distribution<> distribution(0, std::distance(spawnPoints.begin(), spawnPoints.end()) - 1); std::uniform_int_distribution<> distribution(0, static_cast<int>(std::distance(spawnPoints.begin(), spawnPoints.end())) - 1);
auto randomSpawnPointIt = spawnPoints.begin(); auto randomSpawnPointIt = spawnPoints.begin();
std::advance(randomSpawnPointIt, distribution(randomGenerator)); std::advance(randomSpawnPointIt, distribution(randomGenerator));
spawnPoint = *randomSpawnPointIt; spawnPoint = *randomSpawnPointIt;
+1 -1
View File
@@ -104,7 +104,7 @@ bool WeaponSystem::OnShoot(Events::Shoot& eShoot)
// Screen center, based on current resolution! // Screen center, based on current resolution!
// TODO: check if player has enough ammo and if weapon has a cooldown or not // TODO: check if player has enough ammo and if weapon has a cooldown or not
Rectangle screenResolution = m_Renderer->GetViewPortSize(); Rectangle screenResolution = m_Renderer->GetViewportSize();
glm::vec2 centerScreen = glm::vec2(screenResolution.Width / 2, screenResolution.Height / 2); glm::vec2 centerScreen = glm::vec2(screenResolution.Width / 2, screenResolution.Height / 2);
// TODO: check if player has enough ammo and if weapon has a cooldown or not // TODO: check if player has enough ammo and if weapon has a cooldown or not