Skip to content

Commit 8c39274

Browse files
committed
Added stamp tracker
1 parent 5369908 commit 8c39274

File tree

5 files changed

+71
-13
lines changed

5 files changed

+71
-13
lines changed

samples/sandbox/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ add_shaders(sandbox OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/shaders
2222
shaders/fs_poly.sc
2323
)
2424

25-
add_assets(sandbox .igneous)
25+
add_assets(sandbox ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
2626

2727
set_target_properties(sandbox PROPERTIES FOLDER "igneous/samples")
2828
set_property(DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT sandbox)

tools/ziggurat/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ add_executable(ziggurat
33
ziggurat.hpp
44
model.cpp
55
copy.cpp
6+
stampList.cpp
67
)
78

89
target_link_libraries(ziggurat
@@ -18,10 +19,10 @@ target_include_directories(ziggurat PUBLIC
1819

1920
set_target_properties(ziggurat PROPERTIES FOLDER "igneous/tools")
2021

21-
macro(add_assets ARG_TARGET ARG_CONFIG_FILE)
22+
macro(add_assets ARG_TARGET ARG_SOURCE_DIR ARG_BINARY_DIR)
2223
add_custom_target(
2324
${ARG_TARGET}_ziggurat ALL
24-
"$<TARGET_FILE:ziggurat>" ${ARG_CONFIG_FILE} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}
25+
"$<TARGET_FILE:ziggurat>" ${ARG_SOURCE_DIR} ${ARG_BINARY_DIR}
2526
DEPENDS ziggurat
2627
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
2728
)

tools/ziggurat/stampList.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include "ziggurat.hpp"
2+
3+
#include <fstream>
4+
#include <string>
5+
6+
StampList::StampList(const std::filesystem::path& stampFilePath)
7+
: dataPath(stampFilePath)
8+
{
9+
std::ifstream stampFile(dataPath, std::ios::in);
10+
11+
if (stampFile.good())
12+
{
13+
std::string filePath, timestamp;
14+
while (stampFile >> filePath >> timestamp)
15+
{
16+
stamps[filePath] = std::stoll(timestamp);
17+
}
18+
}
19+
}
20+
21+
StampList::~StampList()
22+
{
23+
std::ofstream stampFile(dataPath, std::ios::out | std::ofstream::trunc);
24+
25+
for (auto it = stamps.begin(); it != stamps.end(); it++)
26+
{
27+
stampFile << it->first << " " << it->second << "\n";
28+
}
29+
}
30+
31+
bool StampList::isOutOfDate(const std::filesystem::path& file)
32+
{
33+
long long current = std::filesystem::last_write_time(file).time_since_epoch().count();
34+
if (!stamps.count(file.string()) || stamps.at(file.string()) < current)
35+
{
36+
stamps[file.string()] = current;
37+
return true;
38+
}
39+
return false;
40+
}

tools/ziggurat/ziggurat.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,25 @@
88

99
int main(int argc, char** argv)
1010
{
11-
if (argc != 4)
11+
if (argc != 3)
1212
{
1313
std::cerr << "A config file, source directory, and binary directory must be provided." << std::endl;
1414
return 1;
1515
}
1616

17-
std::string config = argv[1];
18-
std::filesystem::path sourceDir(argv[2]);
17+
std::filesystem::path sourceDir(argv[1]);
1918
std::filesystem::path sourceResDir = sourceDir / "res";
20-
std::filesystem::path binaryDir(argv[3]);
19+
std::filesystem::path binaryDir(argv[2]);
2120
std::filesystem::path binaryResDir = binaryDir / "res";
21+
std::filesystem::path configPath = sourceDir / ".igneous";
22+
std::filesystem::path stampPath = binaryDir / ".igneous.stamp";
2223

23-
std::ifstream configFile(config, std::ios::in);
24+
std::ifstream configFile(configPath, std::ios::in);
25+
StampList stampList(stampPath);
2426

2527
if (configFile.fail())
2628
{
27-
std::cerr << "Could not load the config file: " << config << std::endl;
29+
std::cerr << "Could not load the config file: " << configPath << std::endl;
2830
return 1;
2931
}
3032

@@ -54,11 +56,14 @@ int main(int argc, char** argv)
5456

5557
std::filesystem::path vertexPath = sourceResDir / "vertex" / vertex;
5658
std::filesystem::path modelPath = sourceResDir / "models" / model;
57-
std::filesystem::path modelBinPath = binaryResDir / "models" / (model.substr(0, model.find_first_of('.')) + ".bin");
59+
std::filesystem::path modelBinPath = (binaryResDir / "models" / model).replace_extension(".bin");
5860

59-
if (!compileModel(vertexPath, modelPath, modelBinPath))
61+
if (stampList.isOutOfDate(modelPath))
6062
{
61-
return 1;
63+
if (!compileModel(vertexPath, modelPath, modelBinPath))
64+
{
65+
return 1;
66+
}
6267
}
6368
}
6469
else if (command == "COPY")

tools/ziggurat/ziggurat.hpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
#pragma once
22

33
#include <filesystem>
4-
#include <string>
4+
#include <unordered_map>
55

66
bool copyDir(const std::filesystem::path& from, const std::filesystem::path& to);
77

88
bool compileModel(const std::filesystem::path& vertexFilePath, const std::filesystem::path& modelFilePath, const std::filesystem::path& outputFilePath);
9+
10+
class StampList
11+
{
12+
public:
13+
StampList(const std::filesystem::path& stampFilePath);
14+
~StampList();
15+
16+
bool isOutOfDate(const std::filesystem::path& file);
17+
private:
18+
std::unordered_map<std::string, long long> stamps;
19+
std::filesystem::path dataPath;
20+
};

0 commit comments

Comments
 (0)