yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Ellie Hermaszewskaformatf65d756bf

master
2.4 KiB106 linesraw
1#include "../../source/core/slang-io.h"
2
3#include <memory>
4#include <replay/json-consumer.h>
5#include <replay/recordFile-processor.h>
6#include <replay/replay-consumer.h>
7#include <replay/slang-decoder.h>
8#include <stdio.h>
9
10struct Options
11{
12    bool convertToJson{false};
13    Slang::String recordFileName;
14};
15
16void printUsage()
17{
18    printf("Usage: slang-replay [options] <record-file>\n");
19    printf("Options:\n");
20    printf(
21        "  --convert-json, -cj: Convert the record file to a JSON file in the same directory with record file.\n\
22                       When this option is set, it won't replay the record file.\n");
23}
24
25Options parseOption(int argc, char* argv[])
26{
27    Options option;
28    char const* arg{};
29    if (argc <= 1)
30    {
31        printUsage();
32        exit(1);
33    }
34
35    int argIndex = 1;
36    while (argIndex < argc)
37    {
38        arg = argv[argIndex];
39
40        // For anything not starting with a '-', it is a file name
41        if (arg[0] != '-')
42        {
43            option.recordFileName = arg;
44            argIndex++;
45        }
46        else if ((strcmp("--convert-json", arg) == 0) || (strcmp("-cj", arg) == 0))
47        {
48            option.convertToJson = true;
49            argIndex++;
50        }
51        else if ((strcmp("--help", arg) == 0) || (strcmp("-h", arg) == 0))
52        {
53            printUsage();
54            exit(0);
55        }
56        else
57        {
58            // Unknown option
59            printf("Unknown option: %s\n", arg);
60            printUsage();
61            exit(1);
62        }
63    }
64
65    if (option.recordFileName.getLength() == 0)
66    {
67        printUsage();
68        exit(1);
69    }
70
71    return option;
72}
73
74int main(int argc, char* argv[])
75{
76    Options options = parseOption(argc, argv);
77
78    SlangRecord::RecordFileProcessor recordFileProcessor(options.recordFileName);
79
80    Slang::String jsonPath = Slang::Path::replaceExt(options.recordFileName, "json");
81    Slang::RefPtr<SlangRecord::JsonConsumer> jsonConsumer;
82    SlangRecord::ReplayConsumer replayConsumer;
83
84    SlangRecord::SlangDecoder decoder;
85
86    if (options.convertToJson)
87    {
88        jsonConsumer = new SlangRecord::JsonConsumer(jsonPath);
89        decoder.addConsumer(jsonConsumer.get());
90    }
91    else
92    {
93        decoder.addConsumer(&replayConsumer);
94    }
95
96    recordFileProcessor.addDecoder(&decoder);
97
98    while (true)
99    {
100        if (!recordFileProcessor.processNextBlock())
101        {
102            break;
103        }
104    }
105    return 0;
106}