From: chaoskagami Date: Mon, 25 Aug 2014 00:47:15 +0000 (-0400) Subject: Miscellaneous tweaks. Mainly, added a line of lookahead so I can determine whether... X-Git-Tag: stable-2~12 X-Git-Url: https://chaos.moe/g/?a=commitdiff_plain;h=54b4aac53b9a04b944b00cc4dab4a4a953b17be8;p=vn%2Fvndc.git Miscellaneous tweaks. Mainly, added a line of lookahead so I can determine whether to stop voices. --- diff --git a/bin/vndc.x86_64 b/bin/vndc.x86_64 index ffa7312..abae162 100755 Binary files a/bin/vndc.x86_64 and b/bin/vndc.x86_64 differ diff --git a/vndc/include/Data.hpp b/vndc/include/Data.hpp index f17a569..48883a0 100644 --- a/vndc/include/Data.hpp +++ b/vndc/include/Data.hpp @@ -35,6 +35,8 @@ class DataContainer { int currentLine = 0; bool skip_key_on = false; char* window_name; + char* next_line = NULL; // Used for voice-detect. + // It's impossible to parse without lookahead. }; DataContainer* GetData(); diff --git a/vndc/src/Loop.cpp b/vndc/src/Loop.cpp index 7be1d01..aa7c8a6 100644 --- a/vndc/src/Loop.cpp +++ b/vndc/src/Loop.cpp @@ -9,7 +9,7 @@ void Wait() { // If the line is spoken, then halt previous spoken lines. // If the skip key is held, just gogogo - bool stop_voice = GetData()->wait_input && GetData()->vndc_enabled; + // bool stop_voice = GetData()->wait_input && GetData()->vndc_enabled && GetData()->is_spoken_line; while((GetData()->wait_input && !GetData()->ctx->GetQuit())) { GetData()->ctx->Input(); @@ -21,10 +21,6 @@ void Wait() { if(GetData()->ctx->GetInput(1)) break; } - - if(stop_voice) - op_sound((char*)"~", NULL); - } void Loop() { diff --git a/vndc/src/Parse.cpp b/vndc/src/Parse.cpp index b0396cf..a4accd4 100644 --- a/vndc/src/Parse.cpp +++ b/vndc/src/Parse.cpp @@ -221,33 +221,42 @@ void Parse() { exit(-8); } - char *line = (char*)calloc(sizeof(char), 400); + // Load the next line to this one. + char* line = GetData()->next_line; - fgets(line, 400, GetData()->accessScriptHandle); + if(line == NULL) { + // We've reached EOF. + op_jump(GetData()->main_scr[0], NULL, true); + } + + GetData()->next_line = (char*)calloc(sizeof(char), 400); + // Load the next line. + fgets(GetData()->next_line, 400, GetData()->accessScriptHandle); - char* line_copy = line; + char* line_copy = GetData()->next_line; while(line_copy[0] == ' ' || line_copy[0] == '\t') { line_copy[0] = '\0'; line_copy = &line_copy[1]; } - // Remove all '\n' from this string + // Remove all '\n' from the buffer line for(int i=0; i < (int)strlen(line_copy); i++) { if (line_copy[i] == '\n') line_copy[i] = '\0'; } - //printf("%lu\n", strlen(line_copy)); - - if(strlen(line_copy) != 0) { - ParseCmd(line_copy); + // Execute the current line. + if(strlen(line) != 0) { + ParseCmd(line); } free(line); + // The next line is null, because the file is finished. if(feof(GetData()->accessScriptHandle)) { - op_jump(GetData()->main_scr[0], NULL, true); + free(GetData()->next_line); + GetData()->next_line = NULL; } return; diff --git a/vndc/src/op_choice.cpp b/vndc/src/op_choice.cpp index fa3182c..08000bb 100644 --- a/vndc/src/op_choice.cpp +++ b/vndc/src/op_choice.cpp @@ -58,6 +58,8 @@ void op_choice(char* line) { strncpy(varname, "selected", 400); } + op_cleartext(); + // For each choice, we need to print text and make a click area. This will use the text function. int *choices = (int*)calloc(sizeof(int), num * 2); diff --git a/vndc/src/op_jump.cpp b/vndc/src/op_jump.cpp index 3770ff3..a58b4d9 100644 --- a/vndc/src/op_jump.cpp +++ b/vndc/src/op_jump.cpp @@ -44,4 +44,22 @@ void op_jump(char* file, int* lineTo, bool isSave) { else { GetData()->currentLine = 0; } + + // Read the first line into next_line. + GetData()->next_line = (char*)calloc(sizeof(char), 400); + // Load the next line. + fgets(GetData()->next_line, 400, GetData()->accessScriptHandle); + + char* line_copy = GetData()->next_line; + + while(line_copy[0] == ' ' || line_copy[0] == '\t') { + line_copy[0] = '\0'; + line_copy = &line_copy[1]; + } + + // Remove all '\n' from the buffer line + for(int i=0; i < (int)strlen(line_copy); i++) { + if (line_copy[i] == '\n') + line_copy[i] = '\0'; + } } diff --git a/vndc/src/op_text.cpp b/vndc/src/op_text.cpp index 647dddb..4bf8f7b 100644 --- a/vndc/src/op_text.cpp +++ b/vndc/src/op_text.cpp @@ -22,20 +22,24 @@ void op_text(char* string) { // Improvised linebreak. Also, an extension. if(GetData()->vndc_enabled && string[1] == '-' && string[2] == '-' && string[3] == '-') { - op_cleartext(); + op_cleartext(); } - // Improvised voice detect. Extension. - // This is based on toggling. - // If the quote is incomplete, it will be stopped on end. - // If not, it will continue voice until the next quoted line. - if(GetData()->vndc_enabled) { - GetData()->is_spoken_line = false; - - int quotes = 0; - for(int i=0; i < (int)strlen(string); i++) { - if(string[i] == '"') quotes++; - } - if(quotes > 0) GetData()->is_spoken_line = true; + // Improvised Tag display. Extension. + if(GetData()->vndc_enabled && string[0] == '<' && string[strlen(string)-1] == '>') { + string[strlen(string)-1] = '\0'; + string = &string[1]; + + GetData()->ctx->ClearOverlay(); + + TextManager* txt = GetData()->ctx->Text(); + + int xloc = ( GetData()->screen_w - txt->TestLen(string) - GetData()->render_x1 ); + + txt->Render(string, xloc, GetData()->render_y1); + + Wait(); + + op_cleartext(); } // Wait for input, then blank if(!strcmp(string, "!")) {