[BUILD] Removed cpp20 modules. As no IDE supports them they will not be used.
This should be re-evluated later when both VScode and Clion has support for them.
This commit is contained in:
parent
b4d27c8b39
commit
87e7c7d202
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -3,3 +3,6 @@ obj/
|
|||
/packages/
|
||||
riderModule.iml
|
||||
/_ReSharper.Caches/
|
||||
|
||||
*.user
|
||||
projs/shadow-file-format/shadow-file-format.vcxproj.user
|
|
@ -10,6 +10,13 @@
|
|||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{47591591-E091-4B88-8418-74D3CBEC5712}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup>
|
||||
<PreferredToolArchitecture>x64</PreferredToolArchitecture>
|
||||
|
@ -47,8 +54,6 @@
|
|||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<EnableModules>true</EnableModules>
|
||||
|
||||
<AdditionalIncludeDirectories>%(AdditionalIncludes.Split(';'));asd;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
|
|
16
projs/docs/diagrams/project-layout.plantuml
Normal file
16
projs/docs/diagrams/project-layout.plantuml
Normal file
|
@ -0,0 +1,16 @@
|
|||
@startuml
|
||||
[shadow-engine] <<static lib>> as engine
|
||||
[shadow-light] <<exe>> as editor
|
||||
[shadow-runner] <<exe>> as runner
|
||||
|
||||
[test-game] <<dll>> as game
|
||||
|
||||
engine <-editor
|
||||
runner -> engine
|
||||
|
||||
game ..> engine
|
||||
|
||||
runner --> game : loads
|
||||
editor --> game : loads
|
||||
|
||||
@enduml
|
|
@ -1,7 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
|
||||
<ImportGroup Label="PropertySheets">
|
||||
<Import Project="../../Umbra.CPP.props" />
|
||||
</ImportGroup>
|
||||
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
|
@ -17,11 +19,8 @@
|
|||
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
|
||||
<ImportGroup Label="ExtensionSettings" />
|
||||
<ImportGroup Label="Shared"/>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -1,47 +1,9 @@
|
|||
#include "pch.h"
|
||||
|
||||
import Shadow.FileFormat;
|
||||
|
||||
std::string example_empty = "ShadowFileFormat_1_0_0";
|
||||
|
||||
std::string example_simple = "ShadowFileFormat_1_0_0 \n\
|
||||
Assets:{ \
|
||||
9:Content_9, \
|
||||
10 : Content_10, \
|
||||
11: Content_11, \
|
||||
}, \
|
||||
";
|
||||
|
||||
std::string example_multi_root =
|
||||
"ShadowFileFormat_1_0_0 \n \
|
||||
Assets:{ \
|
||||
9:Content_9, \
|
||||
}, \
|
||||
Texture:{ \
|
||||
texture:checker_board.png, \
|
||||
}, \
|
||||
";
|
||||
|
||||
|
||||
std::string example_multi_level = "ShadowFileFormat_1_0_0 \n\
|
||||
Assets:{ \
|
||||
9: { \
|
||||
\
|
||||
}, \
|
||||
}, \
|
||||
";
|
||||
|
||||
std::string example_multi_level_content = "ShadowFileFormat_1_0_0 \n\
|
||||
Assets:{ \
|
||||
a: { \
|
||||
0: ContentContent0, \
|
||||
1: ContentContent1, \
|
||||
2: ContentContent2, \
|
||||
}, \
|
||||
b: ContentB, \
|
||||
}, \
|
||||
";
|
||||
//import Shadow.FileFormat;
|
||||
#include "SFFWriter.h"
|
||||
|
||||
/*
|
||||
std::stringstream streamFrom(std::string str) {
|
||||
std::stringstream ss;
|
||||
ss << str;
|
||||
|
@ -49,9 +11,9 @@ std::stringstream streamFrom(std::string str) {
|
|||
return ss;
|
||||
}
|
||||
|
||||
TEST(EmptyFile, HasHeader) {
|
||||
TEST(Write_EmptyFile, HasHeader) {
|
||||
|
||||
std::stringstream ss = streamFrom(example_empty);
|
||||
//std::stringstream ss = streamFrom(example_empty);
|
||||
|
||||
//auto a = Shadow::SFF::SFFWriter::
|
||||
|
||||
|
@ -59,3 +21,5 @@ TEST(EmptyFile, HasHeader) {
|
|||
|
||||
//EXPECT_EQ(assets, nullptr);
|
||||
}
|
||||
|
||||
*/
|
|
@ -1,7 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ImportGroup Label="PropertySheets">
|
||||
<Import Project="../../Umbra.CPP.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{3b7d6797-cc0c-43fa-8866-f438032e1c67}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<WindowsTargetPlatformVersion>10.0.19041.0</WindowsTargetPlatformVersion>
|
||||
|
@ -14,8 +17,14 @@
|
|||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings" />
|
||||
<ImportGroup Label="Shared" />
|
||||
<ImportGroup Label="PropertySheets" />
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)\projs\shadow-file-format\src\; %(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ClInclude Include="pch.h" />
|
||||
</ItemGroup>
|
||||
|
@ -23,8 +32,7 @@
|
|||
<ClCompile Include="test.cpp" />
|
||||
<ClCompile Include="sff_writer_tests.cpp" />
|
||||
<ClCompile Include="pch.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader>Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "pch.h"
|
||||
#include "../shadow-file-format/src/SFFParser.h"
|
||||
|
||||
import Shadow.FileFormat;
|
||||
//import Shadow.FileFormat;
|
||||
|
||||
std::string example_empty = "ShadowFileFormat_1_0_0";
|
||||
|
||||
|
|
|
@ -1,50 +1,45 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ImportGroup Label="PropertySheets">
|
||||
<Import Project="../../Umbra.CPP.props" />
|
||||
</ImportGroup>
|
||||
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{B2E3515C-3FE0-44B9-9ABE-8584A836230F}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>shadow_file_format</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
<ProjectName>shadow-file-format</ProjectName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="ExtensionSettings" />
|
||||
<ImportGroup Label="Shared" />
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<CompileAs>CompileAsCppModule</CompileAs>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)\projs\shadow-utility\src\; %(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src/SFFWriter.ixx" />
|
||||
<!--<ClCompile Include="src/SFFElement.cpp" />-->
|
||||
<!--<ClCompile Include="src/SFFParser.cpp" />-->
|
||||
<ClCompile Include="src/SFFElement.ixx" />
|
||||
<ClCompile Include="src/Shadow.FileFormat.ixx" />
|
||||
<ClCompile Include="src/SFFParser.ixx" />
|
||||
<ClCompile Include="src/SFFVersion.ixx" />
|
||||
<ClCompile Include="src/SFFElement.cpp" />
|
||||
<ClCompile Include="src\SFFParser.cpp" />
|
||||
<ClCompile Include="src\SFFWriter.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src/SFFElement.h" />
|
||||
<ClInclude Include="src\SFFParser.h" />
|
||||
<ClInclude Include="src\SFFVersion.h" />
|
||||
<ClInclude Include="src\SFFWriter.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Natvis Include="SFFElement.natvis" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\shadow-utility\shadow-utility.vcxproj">
|
||||
<Project>{7b9e6056-e4fb-411b-9612-a2fd679c2b69}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Natvis Include="SFFElement.natvis" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="ExtensionTargets" />
|
||||
</Project>
|
|
@ -15,35 +15,45 @@
|
|||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\SFFParser.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src/SFFElement.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src/SFFParser.cpp">
|
||||
<ClCompile Include="src\SFFParser.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\SFFWriter.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src/SFFElement.ixx" />
|
||||
<ClCompile Include="src/Shadow.FileFormat.ixx" />
|
||||
<ClCompile Include="src/SFFParser.ixx" />
|
||||
<ClCompile Include="src/SFFVersion.ixx" />
|
||||
<ClCompile Include="SFFWriter.ixx" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src/**/*.h">
|
||||
<ClInclude Include="src\SFFParser.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src/**/*.h">
|
||||
<ClInclude Include="src\SFFVersion.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src/**/*.h">
|
||||
<ClInclude Include="src\SFFWriter.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src/**/*.h">
|
||||
<ClInclude Include="src\SFFParser.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src/**/*.h">
|
||||
<ClInclude Include="src\SFFVersion.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\SFFWriter.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src/SFFElement.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\SFFParser.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\SFFVersion.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\SFFWriter.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup />
|
||||
</Project>
|
|
@ -1,15 +1,35 @@
|
|||
/*
|
||||
module;
|
||||
|
||||
module Shadow.FileFormat:SFFElement;
|
||||
|
||||
import <string>;
|
||||
import shadow_utils;
|
||||
|
||||
namespace Shadow::SFF {
|
||||
#include "SFFElement.h"
|
||||
|
||||
|
||||
namespace Shadow::SFF {
|
||||
|
||||
SFFElement* SFFElement::GetFirstChild()
|
||||
{
|
||||
return children.size() > 0 ? children.begin()->second : nullptr;
|
||||
}
|
||||
|
||||
SFFElement* SFFElement::GetChildByIndex(int index)
|
||||
{
|
||||
SFFElement::ChildrenMap::iterator it = children.begin();
|
||||
if (it == children.end())
|
||||
return nullptr;
|
||||
|
||||
for (size_t i = 0; i < index; i++)
|
||||
{
|
||||
it++;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
SFFElement* SFFElement::GetChildByName(std::string name)
|
||||
{
|
||||
SFFElement::ChildrenMap::iterator it = children.find(name);
|
||||
if (it != children.end()) {
|
||||
return it->second;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SFFElement::~SFFElement(){}
|
||||
|
||||
}
|
||||
*/
|
36
projs/shadow-file-format/src/SFFElement.h
Normal file
36
projs/shadow-file-format/src/SFFElement.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <list>
|
||||
|
||||
|
||||
namespace Shadow::SFF {
|
||||
|
||||
class SFFElement
|
||||
{
|
||||
public:
|
||||
SFFElement* parent;
|
||||
|
||||
std::string name;
|
||||
|
||||
bool isBlock;
|
||||
|
||||
std::string value;
|
||||
typedef std::map<std::string, SFFElement*> ChildrenMap;
|
||||
|
||||
ChildrenMap children;
|
||||
|
||||
std::string GetStringProperty(std::string name);
|
||||
|
||||
SFFElement* GetFirstChild();
|
||||
|
||||
SFFElement* GetChildByIndex(int index);
|
||||
|
||||
SFFElement* GetChildByName(std::string name);
|
||||
|
||||
~SFFElement();
|
||||
|
||||
};
|
||||
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
module;
|
||||
|
||||
export module Shadow.FileFormat:SFFElement;
|
||||
|
||||
import <string>;
|
||||
import <map>;
|
||||
import <list>;
|
||||
|
||||
namespace Shadow::SFF {
|
||||
|
||||
export class SFFElement
|
||||
{
|
||||
public:
|
||||
SFFElement* parent;
|
||||
|
||||
std::string name;
|
||||
|
||||
bool isBlock;
|
||||
|
||||
std::string value;
|
||||
typedef std::map<std::string, SFFElement*> ChildrenMap;
|
||||
|
||||
ChildrenMap children;
|
||||
|
||||
std::string GetStringProperty(std::string name);
|
||||
|
||||
SFFElement* GetFirstChild()
|
||||
{
|
||||
return children.size() > 0 ? children.begin()->second : nullptr;
|
||||
}
|
||||
|
||||
SFFElement* GetChildByIndex(int index)
|
||||
{
|
||||
ChildrenMap::iterator it = children.begin();
|
||||
if (it == children.end())
|
||||
return nullptr;
|
||||
|
||||
for (size_t i = 0; i < index; i++)
|
||||
{
|
||||
it++;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
SFFElement* GetChildByName(std::string name)
|
||||
{
|
||||
ChildrenMap::iterator it = children.find(name);
|
||||
if (it != children.end()) {
|
||||
return it->second;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
~SFFElement();
|
||||
|
||||
};
|
||||
|
||||
}
|
|
@ -1,18 +1,129 @@
|
|||
/*
|
||||
module;
|
||||
import <string>;
|
||||
import <iostream>;
|
||||
import <string>;
|
||||
#include "SFFParser.h"
|
||||
|
||||
import shadow_utils;
|
||||
|
||||
module Shadow.FileFormat:SFFParser;
|
||||
|
||||
import :SFFElement;
|
||||
import :SFFVersion;
|
||||
#include <fstream>
|
||||
|
||||
#include "string-helpers.h"
|
||||
|
||||
namespace Shadow::SFF {
|
||||
|
||||
SFFElement* SFFParser::ReadFromStream(std::istream& stream)
|
||||
{
|
||||
auto version = ReadVersionFromHeader(stream);
|
||||
if (version.invalid) {
|
||||
//SH_CORE_WARN("Shadow File is invalid");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
//The current node that we are building
|
||||
auto* context = new SFFElement;
|
||||
context->name = "root";
|
||||
|
||||
//Top level Element
|
||||
SFFElement* base = context;
|
||||
|
||||
//The new node that will be a child of the context
|
||||
SFFElement* current = nullptr;
|
||||
|
||||
|
||||
std::string buffer;
|
||||
|
||||
char c;
|
||||
while (!stream.eof())
|
||||
{
|
||||
stream.get(c);
|
||||
|
||||
switch (c) {
|
||||
case ':':
|
||||
//The stuff in the buffer is a parameter name
|
||||
//std::cout << "Name: " << buffer;
|
||||
current = new SFFElement;
|
||||
current->name = buffer;
|
||||
current->parent = context;
|
||||
|
||||
buffer = "";
|
||||
break;
|
||||
|
||||
case '{':
|
||||
//Start of a new block
|
||||
current->isBlock = true;
|
||||
context = current;
|
||||
|
||||
current = nullptr;
|
||||
break;
|
||||
|
||||
case ',':
|
||||
// End of a property
|
||||
if (!current->isBlock) {
|
||||
//The stuff is the value
|
||||
current->value = buffer;
|
||||
current->parent = context;
|
||||
current->isBlock = false;
|
||||
}
|
||||
buffer = "";
|
||||
|
||||
context->children[current->name] = current;
|
||||
|
||||
current = nullptr;
|
||||
break;
|
||||
|
||||
case '}':
|
||||
if (current != nullptr) {
|
||||
// End of a block
|
||||
current->parent = context;
|
||||
context->children[current->name] = current;
|
||||
}
|
||||
current = context;
|
||||
context = current->parent;
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
if (std::isspace(c) == 0)
|
||||
{
|
||||
buffer += c;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//std::cout << "END" << std::endl;
|
||||
|
||||
return base;
|
||||
}
|
||||
|
||||
SFFVersion SFFParser::ReadVersionFromHeader(std::istream& stream) {
|
||||
std::string line;
|
||||
std::getline(stream, line);
|
||||
auto parts = explode(line, '_');
|
||||
if (parts[0] != "ShadowFileFormat") {
|
||||
return SFFVersion(-1, -1, -1);
|
||||
}
|
||||
else {
|
||||
int mayor = std::stoi(parts[1]);
|
||||
int minor = std::stoi(parts[2]);
|
||||
int patch = std::stoi(parts[3]);
|
||||
return SFFVersion(mayor, minor, patch);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
SFFElement* SFFParser::ReadFromFile(std::string path)
|
||||
{
|
||||
std::ifstream inputFileStream(path);
|
||||
|
||||
if (errno)
|
||||
{
|
||||
//SH_CORE_ERROR("Error: {0} | File: {1}", strerror(errno), path);
|
||||
//std::cerr << "Error: " << strerror(errno) << std::endl;
|
||||
//std::cerr << "File: " << path << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return ReadFromStream(inputFileStream);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
|
22
projs/shadow-file-format/src/SFFParser.h
Normal file
22
projs/shadow-file-format/src/SFFParser.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include "SFFElement.h"
|
||||
#include "SFFVersion.h"
|
||||
|
||||
namespace Shadow::SFF {
|
||||
|
||||
class SFFParser
|
||||
{
|
||||
public:
|
||||
|
||||
static SFFElement* ReadFromStream(std::istream& stream);
|
||||
|
||||
static SFFVersion ReadVersionFromHeader(std::istream& stream);
|
||||
|
||||
static SFFElement* ReadFromFile(std::string path);
|
||||
};
|
||||
|
||||
}
|
|
@ -1,142 +0,0 @@
|
|||
module;
|
||||
|
||||
export module Shadow.FileFormat:SFFParser;
|
||||
|
||||
import <string>;
|
||||
import <iostream>;
|
||||
import <fstream>;
|
||||
import <string>;
|
||||
import shadow_utils;
|
||||
|
||||
import :SFFElement;
|
||||
import :SFFVersion;
|
||||
|
||||
namespace Shadow::SFF {
|
||||
|
||||
export class SFFParser
|
||||
{
|
||||
public:
|
||||
|
||||
static SFFElement* ReadFromStream(std::istream& stream)
|
||||
{
|
||||
auto version = ReadVersionFromHeader(stream);
|
||||
if (version.invalid) {
|
||||
//SH_CORE_WARN("Shadow File is invalid");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
//The current node that we are building
|
||||
auto* context = new SFFElement;
|
||||
context->name = "root";
|
||||
|
||||
//Top level Element
|
||||
SFFElement* base = context;
|
||||
|
||||
//The new node that will be a child of the context
|
||||
SFFElement* current = nullptr;
|
||||
|
||||
|
||||
std::string buffer;
|
||||
|
||||
char c;
|
||||
while (!stream.eof())
|
||||
{
|
||||
stream.get(c);
|
||||
|
||||
switch (c) {
|
||||
case ':':
|
||||
//The stuff in the buffer is a parameter name
|
||||
//std::cout << "Name: " << buffer;
|
||||
current = new SFFElement;
|
||||
current->name = buffer;
|
||||
current->parent = context;
|
||||
|
||||
buffer = "";
|
||||
break;
|
||||
|
||||
case '{':
|
||||
//Start of a new block
|
||||
current->isBlock = true;
|
||||
context = current;
|
||||
|
||||
current = nullptr;
|
||||
break;
|
||||
|
||||
case ',':
|
||||
// End of a property
|
||||
if (!current->isBlock) {
|
||||
//The stuff is the value
|
||||
current->value = buffer;
|
||||
current->parent = context;
|
||||
current->isBlock = false;
|
||||
}
|
||||
buffer = "";
|
||||
|
||||
context->children[current->name] = current;
|
||||
|
||||
current = nullptr;
|
||||
break;
|
||||
|
||||
case '}':
|
||||
if (current != nullptr) {
|
||||
// End of a block
|
||||
current->parent = context;
|
||||
context->children[current->name] = current;
|
||||
}
|
||||
current = context;
|
||||
context = current->parent;
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
if (std::isspace(c) == 0)
|
||||
{
|
||||
buffer += c;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//std::cout << "END" << std::endl;
|
||||
|
||||
return base;
|
||||
}
|
||||
|
||||
static SFFVersion ReadVersionFromHeader(std::istream& stream) {
|
||||
std::string line;
|
||||
std::getline(stream, line);
|
||||
auto parts = explode(line, '_');
|
||||
if (parts[0] != "ShadowFileFormat") {
|
||||
return SFFVersion(-1, -1, -1);
|
||||
}
|
||||
else {
|
||||
int mayor = std::stoi(parts[1]);
|
||||
int minor = std::stoi(parts[2]);
|
||||
int patch = std::stoi(parts[3]);
|
||||
return SFFVersion(mayor, minor, patch);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
static SFFElement* ReadFromFile(std::string path)
|
||||
{
|
||||
std::ifstream inputFileStream(path);
|
||||
|
||||
if (errno)
|
||||
{
|
||||
//SH_CORE_ERROR("Error: {0} | File: {1}", strerror(errno), path);
|
||||
//std::cerr << "Error: " << strerror(errno) << std::endl;
|
||||
//std::cerr << "File: " << path << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return ReadFromStream(inputFileStream);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
export module Shadow.FileFormat:SFFVersion;
|
||||
#pragma once
|
||||
|
||||
export namespace Shadow::SFF {
|
||||
namespace Shadow::SFF {
|
||||
|
||||
struct SFFVersion {
|
||||
public:
|
48
projs/shadow-file-format/src/SFFWriter.cpp
Normal file
48
projs/shadow-file-format/src/SFFWriter.cpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
#include "SFFWriter.h"
|
||||
|
||||
|
||||
namespace Shadow::SFF {
|
||||
|
||||
void SFFWriter::WriteFile(SFFElement& root, std::string path)
|
||||
{
|
||||
std::ofstream writer(path);
|
||||
writer << "ShadowFileFormat_1_0_0" << std::endl;
|
||||
|
||||
int depth = 0;
|
||||
WriteElement(writer, root, depth);
|
||||
|
||||
writer.flush();
|
||||
}
|
||||
|
||||
void SFFWriter::WriteElement(std::ostream& w, SFFElement& e, int &depth)
|
||||
{
|
||||
std::string head = (e.name + (e.isBlock ? ":{" : ":"));
|
||||
//head = head.PadLeft(depth + head.Length, '\t');
|
||||
head.insert(head.begin(), depth, '\t');
|
||||
w << head << std::endl;
|
||||
|
||||
if (e.isBlock)
|
||||
{
|
||||
depth += 1;
|
||||
w << std::endl;
|
||||
for(auto& prop : e.children)
|
||||
{
|
||||
WriteElement(w, *prop.second, depth);
|
||||
}
|
||||
|
||||
std::string close = "}";
|
||||
close.insert(head.begin(), depth, '\t');
|
||||
w << close;
|
||||
depth -= 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
w << e.value << ",";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
26
projs/shadow-file-format/src/SFFWriter.h
Normal file
26
projs/shadow-file-format/src/SFFWriter.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include "SFFElement.h"
|
||||
#include "SFFVersion.h"
|
||||
|
||||
namespace Shadow::SFF {
|
||||
|
||||
class SFFWriter
|
||||
{
|
||||
public:
|
||||
|
||||
static void WriteFile(SFFElement& root, std::string path);
|
||||
|
||||
static void WriteElement(std::ostream& w, SFFElement& e, int &depth);
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1,68 +0,0 @@
|
|||
module;
|
||||
|
||||
//#include <iostream>;
|
||||
//#include <fstream>;
|
||||
|
||||
export module Shadow.FileFormat:SFFWriter;
|
||||
|
||||
import <string>;
|
||||
import <iostream>;
|
||||
import <fstream>;
|
||||
import shadow_utils;
|
||||
|
||||
import :SFFElement;
|
||||
import :SFFVersion;
|
||||
|
||||
namespace Shadow::SFF {
|
||||
|
||||
export class SFFParser
|
||||
{
|
||||
public:
|
||||
|
||||
static void WriteFile(SFFElement& root, std::string path)
|
||||
{
|
||||
std::ofstream writer(path);
|
||||
writer << "ShadowFileFormat_1_0_0" << std::endl;
|
||||
|
||||
int depth = 0;
|
||||
WriteElement(writer, root, depth);
|
||||
|
||||
writer.flush();
|
||||
}
|
||||
|
||||
static void WriteElement(std::ostream& w, SFFElement& e, int &depth)
|
||||
{
|
||||
std::string head = (e.name + (e.isBlock ? ":{" : ":"));
|
||||
//head = head.PadLeft(depth + head.Length, '\t');
|
||||
head.insert(head.begin(), depth, '\t');
|
||||
w << head << std::endl;
|
||||
|
||||
if (e.isBlock)
|
||||
{
|
||||
depth += 1;
|
||||
w << std::endl;
|
||||
for(auto& prop : e.properties)
|
||||
{
|
||||
WriteElement(w, prop.Value, depth);
|
||||
}
|
||||
|
||||
std::string close = "}";
|
||||
close.insert(head.begin(), depth, '\t');
|
||||
w << close;
|
||||
depth -= 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
w << e.value << ",";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ImportGroup Label="PropertySheets">
|
||||
<Import Project="../../Umbra.CPP.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{7B9E6056-E4FB-411B-9612-A2FD679C2B69}</ProjectGuid>
|
||||
|
@ -13,27 +15,21 @@
|
|||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="ExtensionSettings"/>
|
||||
<ImportGroup Label="Shared"/>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<CompileAs>CompileAsCppModule</CompileAs>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<CompileAs>CompileAsCppModule</CompileAs>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\string-helpers.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="shadow-utils.ixx" />
|
||||
<ClCompile Include="string-helpers.cpp" />
|
||||
<ClCompile Include="src\string-helpers.cpp" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\shadow-entity\shadow-entity.vcxproj">
|
||||
<Project>{47591591-e091-4b88-8418-74d3cbec5712}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="shadow-utils.ixx" />
|
||||
<ClCompile Include="string-helpers.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
module;
|
||||
|
||||
module shadow_utils;
|
||||
#include "string-helpers.h"
|
||||
|
||||
import <string>;
|
||||
import <vector>;
|
||||
|
||||
inline std::vector<std::string> explode(const std::string& s, const char& c)
|
||||
std::vector<std::string> explode(const std::string& s, const char& c)
|
||||
{
|
||||
std::string buff;
|
||||
std::vector<std::string> v;
|
|
@ -1,2 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
std::vector<std::string> explode(const std::string& s, const char& c);
|
12
umbra.sln
12
umbra.sln
|
@ -9,12 +9,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "shadow-entity", "projs\shad
|
|||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "vendor", "vendor", "{D53EF63D-47DE-4936-8707-CE5E59FC0F7A}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "shadow-file-format", "projs\shadow-file-format\shadow-file-format.vcxproj", "{B2E3515C-3FE0-44B9-9ABE-8584A836230F}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "shadow-file-format-test", "projs\shadow-file-format-test\shadow-file-format-test.vcxproj", "{3B7D6797-CC0C-43FA-8866-F438032E1C67}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "shadow-utility", "projs\shadow-utility\shadow-utility.vcxproj", "{7B9E6056-E4FB-411B-9612-A2FD679C2B69}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "shadow-file-format", "projs\shadow-file-format\shadow-file-format.vcxproj", "{B2E3515C-3FE0-44B9-9ABE-8584A836230F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
|
@ -29,10 +29,6 @@ Global
|
|||
{47591591-E091-4B88-8418-74D3CBEC5712}.Debug|x64.Build.0 = Debug|x64
|
||||
{47591591-E091-4B88-8418-74D3CBEC5712}.Release|x64.ActiveCfg = Release|x64
|
||||
{47591591-E091-4B88-8418-74D3CBEC5712}.Release|x64.Build.0 = Release|x64
|
||||
{B2E3515C-3FE0-44B9-9ABE-8584A836230F}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{B2E3515C-3FE0-44B9-9ABE-8584A836230F}.Debug|x64.Build.0 = Debug|x64
|
||||
{B2E3515C-3FE0-44B9-9ABE-8584A836230F}.Release|x64.ActiveCfg = Release|x64
|
||||
{B2E3515C-3FE0-44B9-9ABE-8584A836230F}.Release|x64.Build.0 = Release|x64
|
||||
{3B7D6797-CC0C-43FA-8866-F438032E1C67}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{3B7D6797-CC0C-43FA-8866-F438032E1C67}.Debug|x64.Build.0 = Debug|x64
|
||||
{3B7D6797-CC0C-43FA-8866-F438032E1C67}.Release|x64.ActiveCfg = Release|x64
|
||||
|
@ -41,6 +37,10 @@ Global
|
|||
{7B9E6056-E4FB-411B-9612-A2FD679C2B69}.Debug|x64.Build.0 = Debug|x64
|
||||
{7B9E6056-E4FB-411B-9612-A2FD679C2B69}.Release|x64.ActiveCfg = Release|x64
|
||||
{7B9E6056-E4FB-411B-9612-A2FD679C2B69}.Release|x64.Build.0 = Release|x64
|
||||
{B2E3515C-3FE0-44B9-9ABE-8584A836230F}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{B2E3515C-3FE0-44B9-9ABE-8584A836230F}.Debug|x64.Build.0 = Debug|x64
|
||||
{B2E3515C-3FE0-44B9-9ABE-8584A836230F}.Release|x64.ActiveCfg = Release|x64
|
||||
{B2E3515C-3FE0-44B9-9ABE-8584A836230F}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
1
vendor/sdl2/sdl2.props
vendored
1
vendor/sdl2/sdl2.props
vendored
|
@ -8,6 +8,7 @@
|
|||
$(SolutionDir)vendor/sdl2/SDL2-2.0.22/include/
|
||||
</Item>
|
||||
</ItemGroup>
|
||||
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)vendor/sdl2/SDL2-2.0.22/include/; %(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
|
|
Loading…
Reference in New Issue
Block a user