Skip to content

Commit b9cb028

Browse files
committed
Merge branch 'vfs_normalized_path_12' into 'master'
Store Lua script path as VFS normalized (#8138) See merge request OpenMW/openmw!4373
2 parents 96ec3a8 + b4f77e8 commit b9cb028

14 files changed

+203
-123
lines changed

apps/components_tests/fx/technique.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99

1010
namespace
1111
{
12+
constexpr VFS::Path::NormalizedView techniquePropertiesPath("shaders/technique_properties.omwfx");
1213

13-
TestingOpenMW::VFSTestFile technique_properties(R"(
14+
TestingOpenMW::VFSTestFile techniqueProperties(R"(
1415
fragment main {}
1516
vertex main {}
1617
technique {
@@ -26,7 +27,9 @@ namespace
2627
}
2728
)");
2829

29-
TestingOpenMW::VFSTestFile rendertarget_properties{ R"(
30+
constexpr VFS::Path::NormalizedView rendertargetPropertiesPath("shaders/rendertarget_properties.omwfx");
31+
32+
TestingOpenMW::VFSTestFile rendertargetProperties{ R"(
3033
render_target rendertarget {
3134
width_ratio = 0.5;
3235
height_ratio = 0.5;
@@ -52,7 +55,9 @@ namespace
5255
technique { passes = downsample2x, main; }
5356
)" };
5457

55-
TestingOpenMW::VFSTestFile uniform_properties{ R"(
58+
constexpr VFS::Path::NormalizedView uniformPropertiesPath("shaders/uniform_properties.omwfx");
59+
60+
TestingOpenMW::VFSTestFile uniformProperties{ R"(
5661
uniform_vec4 uVec4 {
5762
default = vec4(0,0,0,0);
5863
min = vec4(0,1,0,0);
@@ -66,13 +71,17 @@ namespace
6671
technique { passes = main; }
6772
)" };
6873

69-
TestingOpenMW::VFSTestFile missing_sampler_source{ R"(
74+
constexpr VFS::Path::NormalizedView missingSamplerSourcePath("shaders/missing_sampler_source.omwfx");
75+
76+
TestingOpenMW::VFSTestFile missingSamplerSource{ R"(
7077
sampler_1d mysampler1d { }
7178
fragment main { }
7279
technique { passes = main; }
7380
)" };
7481

75-
TestingOpenMW::VFSTestFile repeated_shared_block{ R"(
82+
constexpr VFS::Path::NormalizedView repeatedSharedBlockPath("shaders/repeated_shared_block.omwfx");
83+
84+
TestingOpenMW::VFSTestFile repeatedSharedBlock{ R"(
7685
shared {
7786
float myfloat = 1.0;
7887
}
@@ -92,11 +101,11 @@ namespace
92101

93102
TechniqueTest()
94103
: mVFS(TestingOpenMW::createTestVFS({
95-
{ "shaders/technique_properties.omwfx", &technique_properties },
96-
{ "shaders/rendertarget_properties.omwfx", &rendertarget_properties },
97-
{ "shaders/uniform_properties.omwfx", &uniform_properties },
98-
{ "shaders/missing_sampler_source.omwfx", &missing_sampler_source },
99-
{ "shaders/repeated_shared_block.omwfx", &repeated_shared_block },
104+
{ techniquePropertiesPath, &techniqueProperties },
105+
{ rendertargetPropertiesPath, &rendertargetProperties },
106+
{ uniformPropertiesPath, &uniformProperties },
107+
{ missingSamplerSourcePath, &missingSamplerSource },
108+
{ repeatedSharedBlockPath, &repeatedSharedBlock },
100109
}))
101110
, mImageManager(mVFS.get(), 0)
102111
{

apps/components_tests/lua/test_configuration.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ namespace
4444
EXPECT_EQ(LuaUtil::scriptCfgToString(cfg.mScripts[1]), "PLAYER : my_mod/player.lua");
4545
EXPECT_EQ(LuaUtil::scriptCfgToString(cfg.mScripts[2]), "CUSTOM : my_mod/some_other_script.lua");
4646
EXPECT_EQ(LuaUtil::scriptCfgToString(cfg.mScripts[3]), "PLAYER NPC CREATURE : my_mod/some_other_script.lua");
47-
EXPECT_EQ(LuaUtil::scriptCfgToString(cfg.mScripts[4]), ": my_mod/player.LUA");
47+
EXPECT_EQ(LuaUtil::scriptCfgToString(cfg.mScripts[4]), ": my_mod/player.lua");
4848
EXPECT_EQ(LuaUtil::scriptCfgToString(cfg.mScripts[5]), "CUSTOM CREATURE : my_mod/creature.lua");
4949

5050
LuaUtil::ScriptsConfiguration conf;
@@ -54,7 +54,7 @@ namespace
5454
// cfg.mScripts[1] is overridden by cfg.mScripts[4]
5555
// cfg.mScripts[2] is overridden by cfg.mScripts[3]
5656
EXPECT_EQ(LuaUtil::scriptCfgToString(conf[1]), "PLAYER NPC CREATURE : my_mod/some_other_script.lua");
57-
EXPECT_EQ(LuaUtil::scriptCfgToString(conf[2]), ": my_mod/player.LUA");
57+
EXPECT_EQ(LuaUtil::scriptCfgToString(conf[2]), ": my_mod/player.lua");
5858
EXPECT_EQ(LuaUtil::scriptCfgToString(conf[3]), "CUSTOM CREATURE : my_mod/creature.lua");
5959

6060
EXPECT_THAT(asVector(conf.getGlobalConf()), ElementsAre(Pair(0, "")));
@@ -89,7 +89,7 @@ namespace
8989
{
9090
ESM::LuaScriptsCfg cfg;
9191
ESM::LuaScriptCfg& script1 = cfg.mScripts.emplace_back();
92-
script1.mScriptPath = "Script1.lua";
92+
script1.mScriptPath = VFS::Path::Normalized("Script1.lua");
9393
script1.mInitializationData = "data1";
9494
script1.mFlags = ESM::LuaScriptCfg::sPlayer;
9595
script1.mTypes.push_back(ESM::REC_CREA);
@@ -98,12 +98,12 @@ namespace
9898
script1.mRefs.push_back({ true, 2, 4, "" });
9999

100100
ESM::LuaScriptCfg& script2 = cfg.mScripts.emplace_back();
101-
script2.mScriptPath = "Script2.lua";
101+
script2.mScriptPath = VFS::Path::Normalized("Script2.lua");
102102
script2.mFlags = ESM::LuaScriptCfg::sCustom;
103103
script2.mTypes.push_back(ESM::REC_CONT);
104104

105105
ESM::LuaScriptCfg& script1Extra = cfg.mScripts.emplace_back();
106-
script1Extra.mScriptPath = "script1.LUA";
106+
script1Extra.mScriptPath = VFS::Path::Normalized("script1.LUA");
107107
script1Extra.mFlags = ESM::LuaScriptCfg::sCustom | ESM::LuaScriptCfg::sMerge;
108108
script1Extra.mTypes.push_back(ESM::REC_NPC_);
109109
script1Extra.mRecords.push_back({ false, ESM::RefId::stringRefId("rat"), "" });
@@ -115,8 +115,8 @@ namespace
115115
conf.init(cfg);
116116
ASSERT_EQ(conf.size(), 2);
117117
EXPECT_EQ(LuaUtil::scriptCfgToString(conf[0]),
118-
"CUSTOM PLAYER CREATURE NPC : Script1.lua ; data 5 bytes ; 3 records ; 4 objects");
119-
EXPECT_EQ(LuaUtil::scriptCfgToString(conf[1]), "CUSTOM CONTAINER : Script2.lua");
118+
"CUSTOM PLAYER CREATURE NPC : script1.lua ; data 5 bytes ; 3 records ; 4 objects");
119+
EXPECT_EQ(LuaUtil::scriptCfgToString(conf[1]), "CUSTOM CONTAINER : script2.lua");
120120

121121
EXPECT_THAT(asVector(conf.getPlayerConf()), ElementsAre(Pair(0, "data1")));
122122
EXPECT_THAT(asVector(conf.getLocalConf(ESM::REC_CONT, ESM::RefId::stringRefId("something"), ESM::RefNum())),
@@ -139,7 +139,7 @@ namespace
139139
ElementsAre(Pair(0, "data1"), Pair(1, "")));
140140

141141
ESM::LuaScriptCfg& script3 = cfg.mScripts.emplace_back();
142-
script3.mScriptPath = "script1.lua";
142+
script3.mScriptPath = VFS::Path::Normalized("script1.lua");
143143
script3.mFlags = ESM::LuaScriptCfg::sGlobal;
144144
EXPECT_ERROR(conf.init(cfg), "Flags mismatch for script1.lua");
145145
}
@@ -168,13 +168,13 @@ namespace
168168
}
169169
{
170170
ESM::LuaScriptCfg& script = cfg.mScripts.emplace_back();
171-
script.mScriptPath = "test_global.lua";
171+
script.mScriptPath = VFS::Path::Normalized("test_global.lua");
172172
script.mFlags = ESM::LuaScriptCfg::sGlobal;
173173
script.mInitializationData = luaData;
174174
}
175175
{
176176
ESM::LuaScriptCfg& script = cfg.mScripts.emplace_back();
177-
script.mScriptPath = "test_local.lua";
177+
script.mScriptPath = VFS::Path::Normalized("test_local.lua");
178178
script.mFlags = ESM::LuaScriptCfg::sMerge;
179179
script.mTypes.push_back(ESM::REC_DOOR);
180180
script.mTypes.push_back(ESM::REC_MISC);

apps/components_tests/lua/test_l10n.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ namespace
1818
return lua.safe_script("return " + luaCode).get<T>();
1919
}
2020

21+
constexpr VFS::Path::NormalizedView test1EnPath("l10n/test1/en.yaml");
22+
constexpr VFS::Path::NormalizedView test1EnUsPath("l10n/test1/en_us.yaml");
23+
constexpr VFS::Path::NormalizedView test1DePath("l10n/test1/de.yaml");
24+
constexpr VFS::Path::NormalizedView test2EnPath("l10n/test2/en.yaml");
25+
constexpr VFS::Path::NormalizedView test3EnPath("l10n/test3/en.yaml");
26+
constexpr VFS::Path::NormalizedView test3DePath("l10n/test3/de.yaml");
27+
2128
VFSTestFile invalidScript("not a script");
2229
VFSTestFile incorrectScript(
2330
"return { incorrectSection = {}, engineHandlers = { incorrectHandler = function() end } }");
@@ -67,12 +74,12 @@ you_have_arrows: "Arrows count: {count}"
6774
struct LuaL10nTest : Test
6875
{
6976
std::unique_ptr<VFS::Manager> mVFS = createTestVFS({
70-
{ "l10n/Test1/en.yaml", &test1En },
71-
{ "l10n/Test1/en_US.yaml", &test1EnUS },
72-
{ "l10n/Test1/de.yaml", &test1De },
73-
{ "l10n/Test2/en.yaml", &test2En },
74-
{ "l10n/Test3/en.yaml", &test1En },
75-
{ "l10n/Test3/de.yaml", &test1De },
77+
{ test1EnPath, &test1En },
78+
{ test1EnUsPath, &test1EnUS },
79+
{ test1DePath, &test1De },
80+
{ test2EnPath, &test2En },
81+
{ test3EnPath, &test1En },
82+
{ test3DePath, &test1De },
7683
});
7784

7885
LuaUtil::ScriptsConfiguration mCfg;

apps/components_tests/lua/test_lua.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ namespace
99
{
1010
using namespace testing;
1111

12+
constexpr VFS::Path::NormalizedView counterPath("aaa/counter.lua");
13+
1214
TestingOpenMW::VFSTestFile counterFile(R"X(
1315
x = 42
1416
return {
@@ -17,8 +19,12 @@ return {
1719
}
1820
)X");
1921

22+
constexpr VFS::Path::NormalizedView invalidPath("invalid.lua");
23+
2024
TestingOpenMW::VFSTestFile invalidScriptFile("Invalid script");
2125

26+
constexpr VFS::Path::NormalizedView testsPath("bbb/tests.lua");
27+
2228
TestingOpenMW::VFSTestFile testsFile(R"X(
2329
return {
2430
-- should work
@@ -51,6 +57,8 @@ return {
5157
}
5258
)X");
5359

60+
constexpr VFS::Path::NormalizedView metaIndexErrorPath("metaindexerror.lua");
61+
5462
TestingOpenMW::VFSTestFile metaIndexErrorFile(
5563
"return setmetatable({}, { __index = function(t, key) error('meta index error') end })");
5664

@@ -66,22 +74,32 @@ return {
6674
return buf.str();
6775
}
6876

77+
constexpr VFS::Path::NormalizedView bigPath("big.lua");
78+
6979
TestingOpenMW::VFSTestFile bigScriptFile(genBigScript());
80+
81+
constexpr VFS::Path::NormalizedView requireBigPath("requirebig.lua");
82+
7083
TestingOpenMW::VFSTestFile requireBigScriptFile("local x = require('big') ; return {x}");
7184

7285
struct LuaStateTest : Test
7386
{
74-
std::unique_ptr<VFS::Manager> mVFS = TestingOpenMW::createTestVFS({ { "aaa/counter.lua", &counterFile },
75-
{ "bbb/tests.lua", &testsFile }, { "invalid.lua", &invalidScriptFile }, { "big.lua", &bigScriptFile },
76-
{ "requireBig.lua", &requireBigScriptFile }, { "metaIndexError.lua", &metaIndexErrorFile } });
87+
std::unique_ptr<VFS::Manager> mVFS = TestingOpenMW::createTestVFS({
88+
{ counterPath, &counterFile },
89+
{ testsPath, &testsFile },
90+
{ invalidPath, &invalidScriptFile },
91+
{ bigPath, &bigScriptFile },
92+
{ requireBigPath, &requireBigScriptFile },
93+
{ metaIndexErrorPath, &metaIndexErrorFile },
94+
});
7795

7896
LuaUtil::ScriptsConfiguration mCfg;
7997
LuaUtil::LuaState mLua{ mVFS.get(), &mCfg };
8098
};
8199

82100
TEST_F(LuaStateTest, Sandbox)
83101
{
84-
const VFS::Path::Normalized path("aaa/counter.lua");
102+
const VFS::Path::Normalized path(counterPath);
85103
sol::table script1 = mLua.runInNewSandbox(path);
86104

87105
EXPECT_EQ(LuaUtil::call(script1["get"]).get<int>(), 42);

0 commit comments

Comments
 (0)