root/deus/StoryTracer.cpp
| Revision 8, 4.0 kB (checked in by pantley2, 4 years ago) |
|---|
| Line | |
|---|---|
| 1 | #include "StoryTracer.h" |
| 2 | |
| 3 | int StoryTracer::NoMoreKeyFrames(void) |
| 4 | { |
| 5 | if (!story_root->frame) return -1; |
| 6 | return story_root->frame->conditions.satisfied == 1; |
| 7 | } |
| 8 | |
| 9 | |
| 10 | int StoryTracer::Trace(bool next_keyframe) |
| 11 | { |
| 12 | if(!next_keyframe) // stay here |
| 13 | { |
| 14 | if (!story_root->frame) return 0; |
| 15 | |
| 16 | // traverse down to the shallowest satisfied frame |
| 17 | // resatisfy it and load plan into the executor's queue |
| 18 | Seeker.Resatisfy(); |
| 19 | } |
| 20 | else |
| 21 | { |
| 22 | if(NoMoreKeyFrames() == 1) |
| 23 | { |
| 24 | if(story_root->next.empty()) return 1; |
| 25 | story_root = story_root->next[rand()%story_root->next.size()]; |
| 26 | Seeker.NewSeek(story_root); |
| 27 | } |
| 28 | else if (NoMoreKeyFrames() == -1) |
| 29 | { |
| 30 | if(story_root->next.empty()) return 1; |
| 31 | story_root = story_root->next[rand()%story_root->next.size()]; |
| 32 | } |
| 33 | else |
| 34 | { |
| 35 | Seeker.ContinueSeek(story_root); |
| 36 | } |
| 37 | } |
| 38 | return 0; |
| 39 | } |
| 40 | |
| 41 | |
| 42 | |
| 43 | // returns 1 iff all nodes executed |
| 44 | /*int StoryTracer::Trace(bool next_keyframe) |
| 45 | { |
| 46 | int n = 0; |
| 47 | bool Continue = false; |
| 48 | |
| 49 | if(next_keyframe && OutOfKeyFrames()) |
| 50 | { |
| 51 | |
| 52 | } |
| 53 | if(!next_keyframe) // just keep planning for the working_on node |
| 54 | { |
| 55 | |
| 56 | } |
| 57 | else |
| 58 | { |
| 59 | if(working_on->next.empty()) return 1; |
| 60 | do |
| 61 | { |
| 62 | try |
| 63 | { |
| 64 | if(WorkOnNode(n)) |
| 65 | { |
| 66 | working_on->visited = 1; |
| 67 | working-on = working_on->next[n % working_on->next.size()]; |
| 68 | Continue = false; |
| 69 | } |
| 70 | else Continue = true; |
| 71 | }catch(TimeOutException tout) { |
| 72 | working_on->visited = -1; |
| 73 | return 0; |
| 74 | } |
| 75 | }while(Continue); |
| 76 | } |
| 77 | |
| 78 | |
| 79 | |
| 80 | ///~ only do one branch in final execution |
| 81 | return 0; |
| 82 | } |
| 83 | */ |
| 84 | /* |
| 85 | int StoryTracer::Trace(bool dont_replan) |
| 86 | { |
| 87 | bool Continue = false; |
| 88 | |
| 89 | while(!nodes.empty()) |
| 90 | { |
| 91 | try { |
| 92 | if(WorkOnNode()) |
| 93 | { // succeeded in achieving node |
| 94 | working_on->visited = true; |
| 95 | |
| 96 | for(int b=0; b<working_on->next.size(); ++b) |
| 97 | nodes.push_back(working_on->next[b]); |
| 98 | } |
| 99 | else |
| 100 | { |
| 101 | nodes.push_back(working_on); // come back to it later |
| 102 | } |
| 103 | |
| 104 | }catch(TimeOutException tout) { return 0; } |
| 105 | } |
| 106 | if(working_on->next.empty()) return 1; |
| 107 | do |
| 108 | { |
| 109 | try |
| 110 | { |
| 111 | if(WorkOnNode(n)) |
| 112 | { |
| 113 | working_on->visited = 1; |
| 114 | working-on = working_on->next[n % working_on->next.size()]; |
| 115 | Continue = false; |
| 116 | } |
| 117 | else Continue = true; |
| 118 | }catch(TimeOutException tout) { |
| 119 | working_on->visited = -1; |
| 120 | return 0; |
| 121 | } |
| 122 | }while(Continue); |
| 123 | } |
| 124 | |
| 125 | |
| 126 | |
| 127 | ///~ only do one branch in final execution |
| 128 | return 0; |
| 129 | }*/ |
| 130 | |
| 131 | |
| 132 | /*int StoryTracer::WorkOnNode(int n) |
| 133 | { |
| 134 | StoryNode* node = working_on->visited[n % working_on->visited.size()]; |
| 135 | int ret = 0; |
| 136 | |
| 137 | try{ |
| 138 | if(node == working_on) |
| 139 | { |
| 140 | if(Seeker.ContinueSeek(node)) ret = 1; |
| 141 | |
| 142 | } |
| 143 | else |
| 144 | { |
| 145 | working_on = node; |
| 146 | if(Seeker.NewSeek(node)) ret = 1; |
| 147 | |
| 148 | } |
| 149 | if(!Seeker.MoreToPlanFor() && next_keyframe) |
| 150 | { |
| 151 | |
| 152 | } |
| 153 | }catch(TimeOutException tout) { throw tout; } |
| 154 | nodes.pop_front(); |
| 155 | return ret; |
| 156 | }*/ |
| 157 | |
| 158 | /*while(!nodes.empty()) |
| 159 | { |
| 160 | try { |
| 161 | if(WorkOnNode()) |
| 162 | { // succeeded in achieving node |
| 163 | working_on->visited = true; |
| 164 | for(int b=0; b<working_on->next.size(); ++b) |
| 165 | nodes.push_back(working_on->next[b]); |
| 166 | } |
| 167 | else |
| 168 | nodes.push_back(working_on); // come back to it later |
| 169 | |
| 170 | }catch(TimeOutException tout) { return 0; } |
| 171 | }*/ |
Note: See TracBrowser for help on using the browser.
