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