diff --git a/mcommon/animation/timer.cpp b/mcommon/animation/timer.cpp index 7850679..3d9a4d3 100644 --- a/mcommon/animation/timer.cpp +++ b/mcommon/animation/timer.cpp @@ -18,18 +18,15 @@ float Timer::GetTime() const return float(time / 1000000.0); } -void Timer::Restart() -{ - m_startTime = std::chrono::duration_cast(std::chrono::high_resolution_clock::now().time_since_epoch()).count(); -} - -float Timer::GetDelta(TimerSample sample) +float Timer::GetDelta() const { auto now = std::chrono::duration_cast(std::chrono::high_resolution_clock::now().time_since_epoch()).count(); auto diff = now - m_startTime; - if (sample == TimerSample::Restart) - { - Restart(); - } return float(diff / 1000000.0); } + +void Timer::Restart() +{ + m_startTime = std::chrono::duration_cast(std::chrono::high_resolution_clock::now().time_since_epoch()).count(); +} + diff --git a/mcommon/animation/timer.h b/mcommon/animation/timer.h index 12b8c23..a960bbd 100644 --- a/mcommon/animation/timer.h +++ b/mcommon/animation/timer.h @@ -11,11 +11,11 @@ class Timer public: Timer(); static Timer& GlobalTimer(); - float GetTime() const; void Restart(); - float GetDelta(TimerSample sample = TimerSample::Restart); + float GetTime() const; + float GetDelta() const; private: int64_t m_startTime; diff --git a/mcommon/file/fileutils.cpp b/mcommon/file/fileutils.cpp index 7ce128b..80618e2 100644 --- a/mcommon/file/fileutils.cpp +++ b/mcommon/file/fileutils.cpp @@ -1,6 +1,15 @@ #include "mcommon.h" + +#if TARGET_PC +#include +#include +#endif + #include "fileutils.h" -#include "sdl/include/SDL_filesystem.h" +#include + +#include +#include namespace FileUtils { @@ -66,4 +75,101 @@ fs::path RelativeTo(fs::path from, fs::path to) return finalPath; } +fs::path GetDocumentsPath() +{ +#if TARGET_PC + PWSTR path; + HRESULT hr = SHGetKnownFolderPath(FOLDERID_Documents, 0, NULL, &path); + if (SUCCEEDED(hr)) + { + fs::path ret = StringUtils::makeStr(path); + CoTaskMemFree(path); + return ret; + } + return fs::path(); +#else + auto pszHome = getenv("HOME"); + return fs::path(std::string(pszHome) + "/Documents"); +#endif +} + +std::vector GatherFiles(const fs::path& root) +{ + std::vector ret; + + tinydir_dir dir; + if (tinydir_open(&dir, root.string().c_str()) == -1) + { + LOG(ERROR) << "Gather Files, Start Path Invalid: " << root.string(); + return ret; + } + + std::set checkedPaths; + std::queue dirs; + dirs.push(dir); + while (!dirs.empty()) + { + tinydir_dir thisDir = dirs.front(); + dirs.pop(); + + while (thisDir.has_next) + { + tinydir_file file; + if (tinydir_readfile(&thisDir, &file) == -1) + { + LOG(ERROR) << "Couldn't read: " << thisDir.path; + tinydir_next(&thisDir); + continue; + } + + try + { + fs::path filePath(file.path); + + // Ignore . and .. + // Otherwise we walk forever. Do this before absolute path! + if (filePath.string().find("\\.") != std::string::npos || + filePath.string().find("..") != std::string::npos) + { + //LOG(INFO) << "Skipping: " << filePath.string(); + tinydir_next(&thisDir); + continue; + } + + // Keep paths nice and absolute/canonical + filePath = fs::canonical(fs::absolute(filePath)); + if (checkedPaths.find(filePath) != checkedPaths.end()) + { + LOG(INFO) << "Already checked: " << filePath.string(); + tinydir_next(&thisDir); + continue; + } + checkedPaths.insert(filePath); + + if (fs::is_directory(filePath)) + { + tinydir_dir subDir; + if (tinydir_open(&subDir, filePath.string().c_str()) != -1) + { + fs::path newPath(subDir.path); + newPath = fs::canonical(fs::absolute(newPath)); + dirs.push(subDir); + } + } + else + { + ret.push_back(filePath); + } + } + catch (fs::filesystem_error& err) + { + LOG(ERROR) << err.what(); + } + + tinydir_next(&thisDir); + } + } + return ret; +} + } // FileUtils \ No newline at end of file diff --git a/mcommon/file/fileutils.h b/mcommon/file/fileutils.h index 9b8eb90..fda44de 100644 --- a/mcommon/file/fileutils.h +++ b/mcommon/file/fileutils.h @@ -17,4 +17,7 @@ namespace FileUtils std::string ReadFile(const fs::path& fileName); bool WriteFile(const fs::path& fileName, const void* pData, size_t size); fs::path RelativeTo(fs::path from, fs::path to); +fs::path GetDocumentsPath(); +std::vector GatherFiles(const fs::path& root); } + diff --git a/mcommon/file/media_manager.cpp b/mcommon/file/media_manager.cpp index 25cd398..299db90 100644 --- a/mcommon/file/media_manager.cpp +++ b/mcommon/file/media_manager.cpp @@ -1,6 +1,9 @@ #include "mcommon.h" #include "file/media_manager.h" #include "file/fileutils.h" +#include "config_app.h" + +std::string g_AppFriendlyName = APPLICATION_NAME; MediaManager& MediaManager::Instance() { @@ -8,32 +11,68 @@ MediaManager& MediaManager::Instance() return manager; } -MediaManager::MediaManager() +bool MediaManager::SetAssetPath(const fs::path& assetPath) { - fs::path basePath(SDL_GetBasePath()); - basePath = basePath / "assets"; - if (fs::exists(basePath)) - { - m_mediaPath = fs::canonical(fs::absolute(basePath)); - } - else - { - m_mediaPath = fs::canonical(fs::absolute(basePath)); - } + m_documentsPath = FileUtils::GetDocumentsPath() / fs::path(g_AppFriendlyName); + m_mediaPath = fs::canonical(fs::absolute(assetPath)); + LOG(INFO) << "Media Path: " << m_mediaPath.string(); m_texturePaths.push_back(fs::path("textures")); m_shaderPaths.push_back(fs::path("shaders")); m_shaderPaths.push_back(fs::path("shaders") / fs::path("GL")); - m_shaderPaths.push_back(fs::path("shaders") / fs::path("DX12")); m_modelPaths.push_back(fs::path("models")); + m_docPaths.push_back(fs::path("documents")); m_modelPaths.push_back(fs::path("test") / fs::path("models")); + m_fontPaths.push_back(fs::path("fonts")); + m_textureExtensions.push_back(".dds"); m_textureExtensions.push_back(".png"); m_textureSubstringReplacements["_bump"] = "_normal"; + return true; +} + +bool MediaManager::SetProjectPath(const fs::path& project) +{ + if (fs::exists(project)) + { + m_projectPath = fs::canonical(fs::absolute(project)); + return true; + } + + try + { + fs::path newPath; + if (project.is_relative()) + { + newPath = m_documentsPath / project; + } + else + { + newPath = project; + } + + if (!fs::exists(newPath)) + { + if (!fs::create_directories(newPath)) + { + return false; + } + } + m_projectPath = fs::canonical(fs::absolute(newPath)); + return true; + } + catch (fs::filesystem_error& err) + { + LOG(ERROR) << err.what(); + } + return false; +} +MediaManager::MediaManager() +{ } std::string MediaManager::LoadAsset(const char* pszPath, uint32_t mediaType, const fs::path* assetBase) @@ -175,6 +214,25 @@ fs::path MediaManager::FindAssetInternal(const char* pszPath, uint32_t mediaType } } + if (mediaType & MediaType::Document) + { + fs::path found = searchPaths(parent, searchPath, m_docPaths); + if (!found.empty()) + { + LOG(DEBUG) << "Found document: " << found.string(); + return found; + } + } + + if (mediaType & MediaType::Font) + { + fs::path found = searchPaths(parent, searchPath, m_fontPaths); + if (!found.empty()) + { + LOG(DEBUG) << "Found font: " << found.string(); + return found; + } + } if (mediaType & MediaType::Shader) { fs::path found = searchPaths(parent, searchPath, m_shaderPaths); @@ -185,7 +243,6 @@ fs::path MediaManager::FindAssetInternal(const char* pszPath, uint32_t mediaType } } - LOG(DEBUG) << "** File not found: " << searchPath.string(); return fs::path(); } diff --git a/mcommon/file/media_manager.h b/mcommon/file/media_manager.h index c20267e..6cbb235 100644 --- a/mcommon/file/media_manager.h +++ b/mcommon/file/media_manager.h @@ -1,5 +1,6 @@ #pragma once + namespace MediaType { enum : uint32_t @@ -7,8 +8,10 @@ enum : uint32_t Texture = (1 << 0), Model = (1 << 1), Shader = (1 << 2), - Local = (1 << 3), - All = (0xFFFFFFFF) + Local = (1 << 3), + Document = (1 << 4), + Project = (1 << 5), + Font = (1 << 6) }; } @@ -20,21 +23,33 @@ class MediaManager const MediaManager& operator= (const MediaManager& rhs) = delete; MediaManager(const MediaManager& rhs) = delete; - fs::path FindAsset(const char* pszAssetName, uint32_t type = MediaType::All, const fs::path* assetBase = nullptr); - std::string LoadAsset(const char* pszPath, uint32_t mediaType = MediaType::All, const fs::path* assetBase = nullptr); + bool SetAssetPath(const fs::path& asset); + bool SetProjectPath(const fs::path& asset); + + const fs::path& GetProjectPath() { return m_projectPath; } + + fs::path GetDocumentsPath() { return m_documentsPath; } + + fs::path FindAsset(const char* pszAssetName, uint32_t type = MediaType::Document, const fs::path* assetBase = nullptr); + std::string LoadAsset(const char* pszPath, uint32_t mediaType = MediaType::Document, const fs::path* assetBase = nullptr); private: - fs::path FindAssetInternal(const char* pszAssetName, uint32_t type = MediaType::All, const fs::path* assetBase = nullptr); + fs::path FindAssetInternal(const char* pszAssetName, uint32_t type, const fs::path* assetBase = nullptr); MediaManager(); fs::path m_mediaPath; std::vector m_texturePaths; std::vector m_modelPaths; + std::vector m_docPaths; std::vector m_shaderPaths; + std::vector m_fontPaths; std::vector m_textureExtensions; std::map m_textureSubstringReplacements; std::map m_foundAssets; + + fs::path m_documentsPath; + fs::path m_projectPath; }; \ No newline at end of file diff --git a/mcommon/list.cmake b/mcommon/list.cmake index 3b93064..c17ec47 100644 --- a/mcommon/list.cmake +++ b/mcommon/list.cmake @@ -19,6 +19,7 @@ mcommon/file/media_manager.h mcommon/math/mathutils.h mcommon/math/mathutils.cpp +mcommon/math/rectstack.h mcommon/string/stringutils.cpp mcommon/string/stringutils.h @@ -33,4 +34,7 @@ mcommon/graphics/primitives2d.cpp mcommon/graphics/primitives2d.h mcommon/mcommon.h +mcommon/mcommon.cpp + ) +set(MCOMMON_ROOT ${CMAKE_CURRENT_LIST_DIR} CACHE STRING "" FORCE) diff --git a/mcommon/math/mathutils.h b/mcommon/math/mathutils.h index e19830c..436aacc 100644 --- a/mcommon/math/mathutils.h +++ b/mcommon/math/mathutils.h @@ -8,7 +8,7 @@ bool IsRectEmpty(const T& rect) return (rect.z == 0 || rect.w == 0); } -template +template bool RectContains(const T& rect, const P& point) { return ((rect.x <= point.x && (rect.x + rect.z) >= point.x) && @@ -34,18 +34,133 @@ T Clamp(const T &val, const T &min, const T &max) return std::max(min, std::min(max, val)); } -#define IM_VEC2_CLASS_EXTRA \ -ImVec2(const glm::vec2& f) { x = f.x; y = f.y; } \ -operator glm::vec2() const { return glm::vec2(x, y); } +struct Rect4f : glm::vec4 +{ + Rect4f(float x, float y, float width, float height) + : glm::vec4(x, y, width, height) {} + Rect4f(float v) + : glm::vec4(v) {} + Rect4f() {} -#define IM_VEC3_CLASS_EXTRA \ -ImVec3(const glm::vec3& f) { x = f.x; y = f.y; z = f.z;} \ -operator glm::vec3() const { return glm::vec3(x,y,z); } + Rect4f Adjust(float x1, float y1, float z1, float w1) + { + return Rect4f(x + x1, y + y1, z + z1, w + w1); + } + + Rect4f Inflate(float d) + { + return Rect4f(x - d, y - d, z + d * 2.0f, w + d * 2.0f); + } + + bool Empty() const + { + return (z == 0.0f || w == 0.0f); + } + + bool Outside(const Rect4f& r) const + { + return (x > r.Right() || + y > r.Bottom() || + x < r.Left() || + y < r.Top()); + } + + void Clamp(const Rect4f& r) + { + if (x > r.Right()) + { + x = r.Right(); + z = 0.0; + } + else if (x < r.Left()) + { + z = (x + z) - r.Left(); + x = r.Left(); + z = std::max(0.0f, z); + } + + if (y > r.Bottom()) + { + y = r.Bottom(); + w = 0.0; + } + else if (y < r.Top()) + { + w = (y + w) - r.Top(); + y = r.Top(); + w = std::max(0.0f, w); + } + + if ((x + z) >= r.Right()) + { + z = r.Right() - x; + z = std::max(0.0f, z); + } + + if ((y + w) >= r.Bottom()) + { + w = r.Bottom() - y; + w = std::max(0.0f, w); + } + } + glm::vec2 Middle() const { return glm::vec2(x + (z / 2), y + (w / 2)); } + float Width() const { return z; } + float Height() const { return w; } + float Bottom() const { return y + w; } + float Right() const { return x + z; } + float Left() const { return x; } + float Top() const { return y; } + glm::vec2 TopLeft() const { return glm::vec2(x, y); } + glm::vec2 TopRight() const { return glm::vec2(x + z, y); } + glm::vec2 BottomRight() const { return glm::vec2(x + z, y + w); } + glm::vec2 BottomLeft() const { return glm::vec2(x, y + w); } + + bool Contains(const glm::vec2& vec) const + { + return Contains(vec.x, vec.y); + } + + bool Contains(float xP, float yP) const + { + if (x <= xP && Right() > xP && + y <= yP && Bottom() > yP) + { + return true; + } + return false; + } +}; + +inline Rect4f AddRects(const Rect4f& r1, const Rect4f& r2) +{ + auto bottomRight = glm::max(r1.BottomRight(), r2.BottomRight()); + auto topLeft = glm::min(r1.TopLeft(), r2.TopLeft()); + + return Rect4f(topLeft.x, topLeft.y, bottomRight.x - topLeft.x, bottomRight.y - topLeft.y); +} + +inline float Manhatten(const glm::vec2& lhs, const glm::vec2& rhs) +{ + return abs(rhs - lhs).x + abs(rhs - lhs).y; +} + +inline glm::vec2 MaxVec(const glm::vec2& lhs, const glm::vec2& rhs) +{ + return glm::vec2(std::max(lhs.x, rhs.x), std::max(lhs.y, rhs.y)); +} #define IM_VEC4_CLASS_EXTRA \ ImVec4(const glm::vec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \ operator glm::vec4() const { return glm::vec4(x,y,z,w); } +#define IM_VEC2_CLASS_EXTRA \ +ImVec2(const glm::vec2& f) { x = f.x; y = f.y; } \ +operator glm::vec2() const { return glm::vec2(x, y); } + #define IM_QUAT_CLASS_EXTRA \ ImQuat(const glm::quat& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \ operator glm::quat() const { return glm::quat(w,x,y,z); } + +#define IM_VEC3_CLASS_EXTRA \ +ImVec3(const glm::vec3& f) { x = f.x; y = f.y; z = f.z;} \ +operator glm::vec3() const { return glm::vec3(x,y,z); } diff --git a/mcommon/math/rectstack.h b/mcommon/math/rectstack.h new file mode 100644 index 0000000..66ec8a3 --- /dev/null +++ b/mcommon/math/rectstack.h @@ -0,0 +1,116 @@ +#pragma once +#include +#include + +namespace RectStackFlags +{ +enum +{ + FixedSize = (1 << 0) +}; + +} + +struct RectStackItem +{ + Rect4f rc; // Current position + float ratio; // Ratio + float fixedSize; // Preferred size + uint32_t flags; // Flags + std::shared_ptr spChildStack; +}; + +class RectStack +{ + +public: + RectStack(bool vertical) + : m_vertical(vertical) + { + + } + + uint32_t GetNumRectItems() const + { + return uint32_t(m_rects.size()); + } + std::shared_ptr GetRectItem(uint32_t index) const + { + return m_rects[index]; + } + + void AddRectItem(std::shared_ptr pRC) { m_rects.push_back(pRC); }; + void Layout(const Rect4f& boundary) + { + auto totalSize = (m_vertical) ? boundary.Height() : boundary.Width(); + + auto totalRatio = 0.0f; + for (auto& pRect : m_rects) + { + if (pRect->flags & RectStackFlags::FixedSize) + { + totalSize -= pRect->fixedSize; + } + else + { + totalRatio += pRect->ratio; + } + } + + glm::vec2 current = boundary.TopLeft(); + for (auto& pRect : m_rects) + { + pRect->rc.x = current.x; + pRect->rc.y = current.y; + if (pRect->flags & RectStackFlags::FixedSize) + { + if (m_vertical) + { + pRect->rc.w = pRect->fixedSize; + pRect->rc.z = boundary.Width(); + } + else + { + pRect->rc.z = pRect->fixedSize; + pRect->rc.w = boundary.Height(); + } + } + else + { + if (m_vertical) + { + pRect->rc.w = totalSize * (pRect->ratio / totalRatio); + pRect->rc.z = boundary.Width(); + } + else + { + pRect->rc.z = totalSize * (pRect->ratio / totalRatio); + pRect->rc.w = boundary.Height(); + } + } + + if (m_vertical) + { + current.y = pRect->rc.Bottom(); + current.x = boundary.Left(); + } + else + { + current.x = pRect->rc.Right(); + current.y = boundary.Top(); + } + } + + for (auto& pRect : m_rects) + { + if (pRect->spChildStack) + { + pRect->spChildStack->Layout(pRect->rc); + } + } + } + +private: + std::vector> m_rects; + bool m_vertical = true; +}; diff --git a/mcommon/mcommon.cpp b/mcommon/mcommon.cpp new file mode 100644 index 0000000..a2c990d --- /dev/null +++ b/mcommon/mcommon.cpp @@ -0,0 +1 @@ +#include "mcommon.h" \ No newline at end of file diff --git a/mcommon/mcommon.h b/mcommon/mcommon.h index a4d782c..d1db0f8 100644 --- a/mcommon/mcommon.h +++ b/mcommon/mcommon.h @@ -16,4 +16,5 @@ // UI/ Messages #include "ui/ui_manager.h" +#include "threadutils.h" diff --git a/mcommon/string/stringutils.cpp b/mcommon/string/stringutils.cpp index ebfe9e2..2f8910e 100644 --- a/mcommon/string/stringutils.cpp +++ b/mcommon/string/stringutils.cpp @@ -1,9 +1,17 @@ #include "mcommon.h" #include "stringutils.h" +#include namespace StringUtils { +std::string toLower(const std::string& str) +{ + std::string copy = str; + std::transform(copy.begin(),copy.end(),copy.begin(),::tolower); + return copy; +} + std::string ReplaceString(std::string subject, const std::string& search, const std::string& replace) { @@ -180,4 +188,16 @@ uint64_t murmur_hash_64(const void * key, uint32_t len, uint64_t seed) return h; } + +//https://stackoverflow.com/questions/4804298/how-to-convert-wstring-into-string +std::string makeStr(const std::wstring& str) +{ + using convert_type = std::codecvt_utf8; + std::wstring_convert converter; + + //use converter (.to_bytes: wstr->str, .from_bytes: str->wstr) + std::string converted_str = converter.to_bytes(str); + return converted_str; +} + } \ No newline at end of file diff --git a/mcommon/string/stringutils.h b/mcommon/string/stringutils.h index c7405fd..60ec787 100644 --- a/mcommon/string/stringutils.h +++ b/mcommon/string/stringutils.h @@ -1,8 +1,28 @@ #pragma once - +#include namespace StringUtils { +inline size_t CountUtf8BytesFromChar(const char c) +{ + if (c < 0x80) return 1; + if (c < 0x800) return 2; + if (c >= 0xdc00 && c < 0xe000) return 0; + if (c >= 0xd800 && c < 0xdc00) return 4; + return 3; +} + +inline size_t Utf8Length(const char* s, char*& pEnd) +{ + size_t len = 1; + while (len <= 4 && *s) + { + if ((*s++ & 0xc0) != 0x80) + break; + len++; + } + return len; +} std::string ReplaceString(std::string subject, const std::string& search, const std::string& replace); std::vector Split(const std::string& text, const std::string& delims); @@ -34,6 +54,12 @@ std::string toString(const T &t) { return oss.str(); } +template +std::string toString(const T &t, int precision) { + std::ostringstream oss; + oss << std::setprecision(precision) << t; + return oss.str(); +} template T fromString(const std::string& s) { std::istringstream stream(s); @@ -41,4 +67,14 @@ T fromString(const std::string& s) { stream >> t; return t; } -} \ No newline at end of file + +inline std::wstring makeWStr(const std::string& str) +{ + return std::wstring(str.begin(), str.end()); +} + +std::string makeStr(const std::wstring& str); + +std::string toLower(const std::string& str); + +} // StringUtils \ No newline at end of file diff --git a/mcommon/threadutils.h b/mcommon/threadutils.h new file mode 100644 index 0000000..af5bf3b --- /dev/null +++ b/mcommon/threadutils.h @@ -0,0 +1,12 @@ +#pragma once + +#include +#include +#include + +template +bool is_future_ready(std::future const& f) +{ + return f.wait_for(std::chrono::seconds(0)) == std::future_status::ready; +} + diff --git a/mcommon/ui/rectstack.h b/mcommon/ui/rectstack.h new file mode 100644 index 0000000..51742d1 --- /dev/null +++ b/mcommon/ui/rectstack.h @@ -0,0 +1,32 @@ +#pragma once +#include + +namespace RectStackFlags +{ +enum +{ + Fixed = (1 << 0), + Relative = (1 << 1) +} + +}; + +}; +struct RectStack +{ + Rect4f rc; + float ratio; + Rect4f preferredSize; +}; + +class GraphVerticalStack +{ + +public: + GraphVerticalStack(); + void AddRect(uint32_t id, const GraphRect& rc) { rc.ratio + + +private: + std::map rc; +}; \ No newline at end of file diff --git a/mgfx/app/Asteroids.cpp b/mgfx/app/Asteroids.cpp index 57375a0..3d3a902 100644 --- a/mgfx/app/Asteroids.cpp +++ b/mgfx/app/Asteroids.cpp @@ -518,7 +518,7 @@ void Asteroids::WrapAtBorders() // Special handling for UFO - kill it inside boundary if (wrapped && entity == m_pUFO) { - if (m_ufoTimer.GetDelta(TimerSample::None) > properties.UFOLifeTime) + if (m_ufoTimer.GetDelta() > properties.UFOLifeTime) { // Force UFO death inside the boundary m_pUFO->death = .1f; @@ -532,6 +532,7 @@ void Asteroids::WrapAtBorders() void Asteroids::HandleInput() { auto timeDelta = m_inputTimer.GetDelta(); + m_inputTimer.Restart(); if (m_gameState != GameState::Playing && m_gameState != GameState::Spawning) @@ -549,7 +550,7 @@ void Asteroids::HandleInput() m_pShip->acceleration = glm::vec2(0.0f); } - float angleDelta = std::min(m_keyholdTimer.GetDelta(TimerSample::None) * 2000.0f, 300.0f); + float angleDelta = std::min(m_keyholdTimer.GetDelta() * 2000.0f, 300.0f); if (ImGui::GetIO().KeysDown[SDLK_a]) { m_pShip->angle -= angleDelta * timeDelta; @@ -588,7 +589,7 @@ void Asteroids::StepPhysics() const float MaxAcceleration = 1000.0f; const float MaxVelocity = 1000.0f; - auto timeDelta = m_physicsTimer.GetDelta(TimerSample::None); + auto timeDelta = m_physicsTimer.GetDelta(); // Update physics 50fps if (timeDelta < 0.02f) @@ -776,7 +777,7 @@ void Asteroids::UpdateGameState() break; case GameState::Spawning: { - auto delta = m_spawnTimer.GetDelta(TimerSample::None); + auto delta = m_spawnTimer.GetDelta(); if (delta > 3.0f) { m_gameState = GameState::Playing; @@ -801,7 +802,7 @@ void Asteroids::UpdateGameState() } // Spawn the UFO if appropriate - auto ufoTime = m_ufoTimer.GetDelta(TimerSample::None); + auto ufoTime = m_ufoTimer.GetDelta(); if (m_pUFO == nullptr) { if (ufoTime > properties.UFOSpawnTime) diff --git a/mgfx/app/GeometryTest.cpp b/mgfx/app/GeometryTest.cpp index 0cef651..359b158 100644 --- a/mgfx/app/GeometryTest.cpp +++ b/mgfx/app/GeometryTest.cpp @@ -162,7 +162,7 @@ void GeometryTest::Render(Mgfx::Window* pWindow) m_totalVerts += m_numQuads * verticesPerQuad; - auto diff = timer.GetDelta(TimerSample::None); + auto diff = timer.GetDelta(); if (diff > 2.0f) { m_verticesPerSecond = m_totalVerts / diff; diff --git a/mgfx/app/main.cpp b/mgfx/app/main.cpp index 05f01da..b74cd08 100644 --- a/mgfx/app/main.cpp +++ b/mgfx/app/main.cpp @@ -224,6 +224,14 @@ int main(int argc, char** argv) el::Configurations conf((basePath / "logger.conf").string().c_str()); el::Loggers::reconfigureAllLoggers(conf); + basePath = basePath / "assets"; + basePath = fs::absolute(basePath); + if (fs::exists(basePath)) + { + basePath = fs::canonical(basePath); + } + MediaManager::Instance().SetAssetPath(basePath); + int exitCode = 0; if (!ReadCommandLine(argc, argv, exitCode)) { @@ -237,6 +245,7 @@ int main(int argc, char** argv) return -1; } + MgfxSettings::Instance().AddRenderer(std::make_shared()); MgfxSettings::Instance().AddRenderer(std::make_shared()); MgfxSettings::Instance().AddRenderer(std::make_shared()); @@ -339,6 +348,7 @@ int main(int argc, char** argv) } auto frameDelta = frameTimer.GetDelta(); + frameTimer.Restart(); // No more events, lets do some drawing // Walk the list of windows currently drawing diff --git a/mgfx_core/graphics3d/camera/camera.cpp b/mgfx_core/graphics3d/camera/camera.cpp index c298baa..0a21f2a 100644 --- a/mgfx_core/graphics3d/camera/camera.cpp +++ b/mgfx_core/graphics3d/camera/camera.cpp @@ -46,7 +46,7 @@ bool Camera::Update() bool changed = false; - auto delta = m_timer.GetDelta(TimerSample::None); + auto delta = m_timer.GetDelta(); if (delta >= .001f) { if (m_orbitDelta != glm::vec2(0.0f)) diff --git a/mgfx_core/graphics3d/device/DX12/miniengine/FileUtility.cpp b/mgfx_core/graphics3d/device/DX12/miniengine/FileUtility.cpp index 5e3f014..cd0a575 100644 --- a/mgfx_core/graphics3d/device/DX12/miniengine/FileUtility.cpp +++ b/mgfx_core/graphics3d/device/DX12/miniengine/FileUtility.cpp @@ -22,7 +22,7 @@ using namespace Utility; namespace Utility { - ByteArray NullFile = make_shared > (vector() ); + ByteArray NullFile = make_shared > (vector() ); } //ByteArray DecompressZippedFile( wstring& fileName ); @@ -38,7 +38,7 @@ ByteArray ReadFileHelper(const wstring& fileName) if (!file) return NullFile; - Utility::ByteArray byteArray = make_shared >( file.seekg(0, ios::end).tellg() ); + Utility::ByteArray byteArray = make_shared >( file.seekg(0, ios::end).tellg() ); file.seekg(0, ios::beg).read( (char*)byteArray->data(), byteArray->size() ); file.close(); diff --git a/mgfx_core/graphics3d/device/DX12/miniengine/FileUtility.h b/mgfx_core/graphics3d/device/DX12/miniengine/FileUtility.h index 0fdd5f6..217d092 100644 --- a/mgfx_core/graphics3d/device/DX12/miniengine/FileUtility.h +++ b/mgfx_core/graphics3d/device/DX12/miniengine/FileUtility.h @@ -23,7 +23,7 @@ namespace Utility using namespace std; using namespace concurrency; - typedef shared_ptr > ByteArray; + typedef shared_ptr> ByteArray; extern ByteArray NullFile; // Reads the entire contents of a binary file. If the file with the same name except with an additional diff --git a/mgfx_core/graphics3d/device/DX12/miniengine/Utility.cpp b/mgfx_core/graphics3d/device/DX12/miniengine/Utility.cpp index 46cf5e3..4d51dd6 100644 --- a/mgfx_core/graphics3d/device/DX12/miniengine/Utility.cpp +++ b/mgfx_core/graphics3d/device/DX12/miniengine/Utility.cpp @@ -99,7 +99,7 @@ void SIMDMemFill( void* __restrict _Dest, __m128 FillVector, size_t NumQuadwords { ASSERT(Math::IsAligned(_Dest, 16)); - register const __m128i Source = _mm_castps_si128(FillVector); + const __m128i Source = _mm_castps_si128(FillVector); __m128i* __restrict Dest = (__m128i* __restrict)_Dest; switch (((size_t)Dest >> 4) & 3)