Skip to content

Commit

Permalink
- fix FFMpeg3 deprecated warnings
Browse files Browse the repository at this point in the history
- fix trim
- update focused buttons code
- update physfs
  • Loading branch information
demo committed Sep 10, 2017
1 parent 59f7c0c commit 38e2a3b
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 79 deletions.
2 changes: 1 addition & 1 deletion DGEngine.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@
<GenerateDebugInformation>No</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>flac.lib;freetype.lib;gdi32.lib;jpeg.lib;ogg.lib;openal32.lib;opengl32.lib;winmm.lib;ws2_32.lib;sfml-audio-s.lib;sfml-graphics-s.lib;sfml-main.lib;sfml-network-s.lib;sfml-system-s.lib;sfml-window-s.lib;vorbis.lib;vorbisenc.lib;vorbisfile.lib;physfs-s.lib;avcodec.lib;avdevice.lib;avfilter.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>flac.lib;freetype.lib;gdi32.lib;jpeg.lib;ogg.lib;openal32.lib;opengl32.lib;winmm.lib;ws2_32.lib;sfml-audio-s.lib;sfml-graphics-s.lib;sfml-main.lib;sfml-network-s.lib;sfml-system-s.lib;sfml-window-s.lib;vorbis.lib;vorbisenc.lib;vorbisfile.lib;physfs-static.lib;avcodec.lib;avdevice.lib;avfilter.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>.\SFML\lib;.\PhysicsFS\MinSizeRel;.\FFmpeg\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<SubSystem>Windows</SubSystem>
</Link>
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ See the wiki for more information.

https://github.com/dgengin/DGEngine/wiki

![DGEngine Running Diablo](https://cloud.githubusercontent.com/assets/20025614/16467025/4bd77ef0-3e3d-11e6-872a-38ca8eb2c9f8.gif)
![DGEngine Running Diablo](https://user-images.githubusercontent.com/20025614/30250613-4033a546-9649-11e7-86d7-97a718d0f119.gif)
20 changes: 10 additions & 10 deletions src/FileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ namespace FileUtils

bool deleteAll(const char* filePath)
{
#if (PHYSFS_VER_MAJOR >= 2 && PHYSFS_VER_MINOR >= 1)
#if (PHYSFS_VER_MAJOR > 2 || (PHYSFS_VER_MAJOR == 2 && PHYSFS_VER_MINOR >= 1))
PHYSFS_Stat fileStat;
if (PHYSFS_stat(filePath, &fileStat) == 0)
{
return false;
}
#endif
bool ret = false;
#if (PHYSFS_VER_MAJOR >= 2 && PHYSFS_VER_MINOR >= 1)
#if (PHYSFS_VER_MAJOR > 2 || (PHYSFS_VER_MAJOR == 2 && PHYSFS_VER_MINOR >= 1))
if (fileStat.filetype == PHYSFS_FILETYPE_DIRECTORY)
#else
if (PHYSFS_isDirectory(filePath) != 0)
Expand All @@ -36,7 +36,7 @@ namespace FileUtils
for (char** path = paths; *path != NULL; path++)
{
auto fullPath = std::string(filePath) + '/' + *path;
#if (PHYSFS_VER_MAJOR >= 2 && PHYSFS_VER_MINOR >= 1)
#if (PHYSFS_VER_MAJOR > 2 || (PHYSFS_VER_MAJOR == 2 && PHYSFS_VER_MINOR >= 1))
if (PHYSFS_stat(fullPath.c_str(), &fileStat) == 0)
{
continue;
Expand Down Expand Up @@ -93,7 +93,7 @@ namespace FileUtils
auto files = PHYSFS_enumerateFiles(filePath.c_str());
if (files != NULL)
{
#if (PHYSFS_VER_MAJOR >= 2 && PHYSFS_VER_MINOR >= 1)
#if (PHYSFS_VER_MAJOR > 2 || (PHYSFS_VER_MAJOR == 2 && PHYSFS_VER_MINOR >= 1))
PHYSFS_Stat fileStat;
#endif
for (char** file = files; *file != NULL; file++)
Expand All @@ -104,7 +104,7 @@ namespace FileUtils
{
continue;
}
#if (PHYSFS_VER_MAJOR >= 2 && PHYSFS_VER_MINOR >= 1)
#if (PHYSFS_VER_MAJOR > 2 || (PHYSFS_VER_MAJOR == 2 && PHYSFS_VER_MINOR >= 1))
if (PHYSFS_stat(file2.c_str(), &fileStat) == 0)
{
continue;
Expand Down Expand Up @@ -157,12 +157,12 @@ namespace FileUtils
auto writeDir = PHYSFS_getWriteDir();
if (writeDir != NULL)
{
#if (PHYSFS_VER_MAJOR >= 2 && PHYSFS_VER_MINOR >= 1)
#if (PHYSFS_VER_MAJOR > 2 || (PHYSFS_VER_MAJOR == 2 && PHYSFS_VER_MINOR >= 1))
PHYSFS_Stat fileStat;
#endif
for (char** dir = dirs; *dir != NULL; dir++)
{
#if (PHYSFS_VER_MAJOR >= 2 && PHYSFS_VER_MINOR >= 1)
#if (PHYSFS_VER_MAJOR > 2 || (PHYSFS_VER_MAJOR == 2 && PHYSFS_VER_MINOR >= 1))
if (PHYSFS_stat(*dir, &fileStat) == 0)
{
continue;
Expand Down Expand Up @@ -240,13 +240,13 @@ namespace FileUtils
#ifdef __ANDROID__
auto userDir = "data/data/com.dgengine/files/";
#else
#if (PHYSFS_VER_MAJOR >= 2 && PHYSFS_VER_MINOR >= 1)
#if (PHYSFS_VER_MAJOR > 2 || (PHYSFS_VER_MAJOR == 2 && PHYSFS_VER_MINOR >= 1))
auto userDir = PHYSFS_getPrefDir("DGEngine", dirName);
#else
auto userDir = PHYSFS_getUserDir();
#endif
#endif
#if (__ANDROID__) || (!(PHYSFS_VER_MAJOR >= 2 && PHYSFS_VER_MINOR >= 1))
#if (__ANDROID__) || (!(PHYSFS_VER_MAJOR > 2 || (PHYSFS_VER_MAJOR == 2 && PHYSFS_VER_MINOR >= 1)))
if (PHYSFS_setWriteDir(userDir) != 0)
{
if (PHYSFS_mkdir(dirName) != 0)
Expand All @@ -270,7 +270,7 @@ namespace FileUtils
auto file = PHYSFS_openWrite(filePath);
if (file != NULL)
{
#if (PHYSFS_VER_MAJOR >= 2 && PHYSFS_VER_MINOR >= 1)
#if (PHYSFS_VER_MAJOR > 2 || (PHYSFS_VER_MAJOR == 2 && PHYSFS_VER_MINOR >= 1))
PHYSFS_writeBytes(file, str, strLen);
#else
PHYSFS_write(file, str, 1, strLen);
Expand Down
6 changes: 5 additions & 1 deletion src/Parser/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ namespace Parser
{
if (PHYSFS_mount(filePath.c_str(), NULL, 0) == 0)
{
#if (PHYSFS_VER_MAJOR > 2 || (PHYSFS_VER_MAJOR == 2 && PHYSFS_VER_MINOR >= 1))
throw std::runtime_error(PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
#else
throw std::runtime_error(PHYSFS_getLastError());
#endif
}

rapidjson::Document doc; // Default template parameter uses UTF8 and MemoryPoolAllocator.

if (doc.Parse(FileUtils::readText(fileName.c_str()).c_str()).HasParseError())
{
#if (PHYSFS_VER_MAJOR >= 2 && PHYSFS_VER_MINOR >= 1)
#if (PHYSFS_VER_MAJOR > 2 || (PHYSFS_VER_MAJOR == 2 && PHYSFS_VER_MINOR >= 1))
PHYSFS_unmount(filePath.c_str());
#else
PHYSFS_removeFromSearchPath(filePath.c_str());
Expand Down
6 changes: 2 additions & 4 deletions src/PhysFSStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
//distribution.

#include "PhysFSStream.h"
#include <iostream>
#include <memory>

sf::PhysFSStream::PhysFSStream(const char* fileName)
{
Expand All @@ -38,8 +36,8 @@ sf::PhysFSStream::~PhysFSStream()

sf::Int64 sf::PhysFSStream::read(void* data, sf::Int64 size)
{
#if (PHYSFS_VER_MAJOR >= 2 && PHYSFS_VER_MINOR >= 1)
return PHYSFS_readBytes(file, data, (PHYSFS_uint32)size);
#if (PHYSFS_VER_MAJOR > 2 || (PHYSFS_VER_MAJOR == 2 && PHYSFS_VER_MINOR >= 1))
return PHYSFS_readBytes(file, data, (PHYSFS_uint64)size);
#else
return PHYSFS_read(file, data, 1, (PHYSFS_uint32)size);
#endif
Expand Down
12 changes: 9 additions & 3 deletions src/PhysFSStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <physfs.h>
#include <SFML/System.hpp>
#include <string>
#include <vector>

namespace sf
{
Expand All @@ -34,7 +33,7 @@ namespace sf
PHYSFS_File* file;

public:
PhysFSStream(std::string fileName) : PhysFSStream(fileName.c_str()) {}
PhysFSStream(const std::string& fileName) : PhysFSStream(fileName.c_str()) {}
PhysFSStream(const char* fileName);
virtual ~PhysFSStream();

Expand All @@ -45,6 +44,13 @@ namespace sf

bool hasError() const { return file == NULL; }

const char* getLastError() { return PHYSFS_getLastError(); }
const char* getLastError()
{
#if (PHYSFS_VER_MAJOR > 2 || (PHYSFS_VER_MAJOR == 2 && PHYSFS_VER_MINOR >= 1))
return PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode());
#else
return PHYSFS_getLastError();
#endif
}
};
}
118 changes: 82 additions & 36 deletions src/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,47 +556,94 @@ void ResourceManager::addFocused(const std::shared_ptr<Button>& obj)

void ResourceManager::clickFocused(Game& game, bool playSound)
{
const auto& vec = resources.back().focusButtons;
auto focusIdx = resources.back().focusIdx;
if (focusIdx < vec.size())
for (const auto& res : reverse(resources))
{
vec[focusIdx]->click(game, playSound);
if (res.ignore != IgnoreResource::None)
{
continue;
}
const auto& vec = res.focusButtons;
auto size = vec.size();
if (size == 0)
{
continue;
}
auto focusIdx = res.focusIdx;
if (focusIdx < size)
{
vec[focusIdx]->click(game, playSound);
}
break;
}
}

const Button* ResourceManager::getFocused() const
{
const auto& vec = resources.back().focusButtons;
auto focusIdx = resources.back().focusIdx;
if (focusIdx < vec.size())
for (const auto& res : reverse(resources))
{
return vec[focusIdx].get();
if (res.ignore != IgnoreResource::None)
{
continue;
}
const auto& vec = res.focusButtons;
auto size = vec.size();
if (size == 0)
{
continue;
}
auto focusIdx = res.focusIdx;
if (focusIdx < size)
{
return vec[focusIdx].get();
}
break;
}
return nullptr;
}

void ResourceManager::setFocused(const Button* obj)
{
const auto& vec = resources.back().focusButtons;
auto size = vec.size();
for (size_t i = 0; i < size; i++)
for (auto& res : reverse(resources))
{
if (vec[i].get() == obj)
if (res.ignore != IgnoreResource::None)
{
resources.back().focusIdx = i;
return;
continue;
}
const auto& vec = res.focusButtons;
auto size = vec.size();
if (size == 0)
{
continue;
}
for (size_t i = 0; i < size; i++)
{
if (vec[i].get() == obj)
{
res.focusIdx = i;
return;
}
}
break;
}
}

void ResourceManager::moveFocusDown(Game& game)
{
const auto& vec = resources.back().focusButtons;
auto& focusIdx = resources.back().focusIdx;
auto idx = focusIdx;
auto size = vec.size();
if (size > 0)
for (auto& res : reverse(resources))
{
if (res.ignore != IgnoreResource::None)
{
continue;
}
const auto& vec = res.focusButtons;
auto size = vec.size();
if (size == 0)
{
continue;
}
auto& focusIdx = res.focusIdx;
auto idx = focusIdx;

while (true)
{
if (idx + 1 < size)
Expand All @@ -617,17 +664,27 @@ void ResourceManager::moveFocusDown(Game& game)
focusIdx = idx;
vec[idx]->focus(game);
}
break;
}
}

void ResourceManager::moveFocusUp(Game& game)
{
const auto& vec = resources.back().focusButtons;
auto& focusIdx = resources.back().focusIdx;
auto idx = focusIdx;
auto size = vec.size();
if (size > 0)
for (auto& res : reverse(resources))
{
if (res.ignore != IgnoreResource::None)
{
continue;
}
const auto& vec = res.focusButtons;
auto size = vec.size();
if (size == 0)
{
continue;
}
auto& focusIdx = res.focusIdx;
auto idx = focusIdx;

while (true)
{
if (idx > 0)
Expand All @@ -648,17 +705,6 @@ void ResourceManager::moveFocusUp(Game& game)
focusIdx = idx;
vec[idx]->focus(game);
}
}
}

void ResourceManager::setFocusIdx(const Button* obj)
{
const auto& vec = resources.back().focusButtons;
for (size_t i = 0; i < vec.size(); i++)
{
if (vec[i].get() == obj)
{
resources.back().focusIdx = i;
}
break;
}
}
2 changes: 0 additions & 2 deletions src/ResourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,4 @@ class ResourceManager

void moveFocusDown(Game& game);
void moveFocusUp(Game& game);

void setFocusIdx(const Button* obj);
};
18 changes: 6 additions & 12 deletions src/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,22 +111,16 @@ namespace Utils

std::string trimStart(const std::string& str, const std::string& chars)
{
auto startPos = str.find_first_not_of(chars);
if (startPos != std::string::npos)
{
return str.substr(startPos);
}
return str;
auto ret(str);
ret.erase(ret.find_last_not_of(chars) + 1);
return ret;
}

std::string trimEnd(const std::string& str, const std::string& chars)
{
auto endPos = str.find_last_not_of(chars);
if (endPos != std::string::npos)
{
return str.substr(0, endPos + 1);
}
return str;
auto ret(str);
ret.erase(0, ret.find_first_not_of(chars));
return ret;
}

std::string trim(const std::string& str, const std::string& chars)
Expand Down
Loading

0 comments on commit 38e2a3b

Please sign in to comment.