• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "proto/eng_tuningfork_extensions.pb.h"
2 #include <iostream>
3 #include <fstream>
4 #include <sstream>
5 #include "mocktuningfork.h"
6 #include "gameengine.h"
7 
8 using ::com::google::tuningfork::Annotation;
9 using ::com::google::tuningfork::Settings;
10 using ::com::google::tuningfork::FidelityParams;
11 
12 // Get the game engine to fill in loading state and level
setUsingGameEngine()13 void setUsingGameEngine() {
14   Annotation t;
15   t.SetExtension(boss_alive, true);
16   gameengine::set(t);
17 }
18 
19 // This is e.g. a Unity C# script setting an annotation
setUsingGameEngineAsIfAnotherLanguage()20 void setUsingGameEngineAsIfAnotherLanguage() {
21   Annotation t;
22   t.SetExtension(boss_alive, true);
23   std::string s;
24   t.SerializeToString(&s);
25   gameengine::set(s);
26 }
27 
28 FidelityParams fparams;
29 
fidelityParamsCallback(const FidelityParams & p)30 void fidelityParamsCallback(const FidelityParams& p) {
31   fparams = p;
32   std::cout << "Game engine got fidelity parameters from TF: "
33             << fparams.DebugString() << std::endl;
34 }
35 
runWithGameEngine(size_t iters=1,bool as_if_another_lang=false)36 void runWithGameEngine(size_t iters = 1, bool as_if_another_lang = false) {
37   Settings settings;
38   Annotation ann;
39   bool alive = false;
40   if(as_if_another_lang) {
41     gameengine::init(settings, fidelityParamsCallback);
42   } else {
43     std::stringstream settings_ser;
44     std::ifstream fstr("tuningfork_settings.txt");
45     settings_ser << fstr.rdbuf();
46     gameengine::init(settings_ser.str(), [&](const std::string& fp_ser) {
47                                      FidelityParams fp;
48                                      fp.ParseFromString(fp_ser);
49                                      fidelityParamsCallback(fp);}
50       );
51   }
52 
53   for(size_t i=0; i<iters; ++i) {
54     alive = !alive;
55     ann.SetExtension(boss_alive, alive);
56     if(as_if_another_lang) {
57       std::string str;
58       ann.SerializeToString(&str);
59       gameengine::set(str);
60     } else {
61       gameengine::set(ann);
62     }
63     gameengine::tick();
64   }
65 }
66 
main(int argc,char * argv[])67 int main(int argc, char * argv[]) {
68   GOOGLE_PROTOBUF_VERIFY_VERSION;
69 
70   std::cout << "** With Game engine ** \n";
71   runWithGameEngine(3);
72 
73   std::cout << "** With Game engine (we're not C++)** \n";
74   runWithGameEngine(3, true);
75 
76   return 0;
77 }
78