]> Chaos Git - vn/vndc.git/commitdiff
Control flow if statement fixed; blank lines in scripts do no segv
authorchaoskagami <chaos.kagami@gmail.com>
Sat, 23 Aug 2014 04:08:08 +0000 (00:08 -0400)
committerchaoskagami <chaos.kagami@gmail.com>
Sat, 23 Aug 2014 04:08:08 +0000 (00:08 -0400)
Format.vndc.txt [new file with mode: 0644]
build
vndc/include/Data.hpp
vndc/src/Parse.cpp
vndc/src/op_fi.cpp
vndc/src/op_if.cpp

diff --git a/Format.vndc.txt b/Format.vndc.txt
new file mode 100644 (file)
index 0000000..be01bc1
--- /dev/null
@@ -0,0 +1,307 @@
+======================================================
+======================================================
+
+Script format documentation      (VNDC and VNDS)
+
+======================================================
+======================================================
+
+Contents.
+       1a. bgload
+       2b. choice
+       3c. cleartext
+       4d. delay
+       5e. if and fi
+       6f. goto and label
+       7g. jump
+       8h. music
+       9i. random
+       10j. setimg
+       11k. setvar and gsetvar
+       12l. sound
+       13m. text
+       14n. debug commands
+               14n1. help
+               14n2. stop
+               14n3. quit
+               14n4. save
+       15o. Save format
+
+= 1a. ================================================
+
+bgload sets a background image.
+
+bgload takes two arguments, one of which is optional.
+
+       bgload bg [fadeout]
+
+The parameter 'bg' should be a file in backgrounds.
+
+The second parameter, 'fadeout', should be a length
+in frames to fade into the new background.
+
+The game always operates at 60fps.
+
+= 2b. ================================================
+
+choice presents choices to the user on screen.
+
+       choice ch1|ch2|ch3...
+
+Each choice is separated by a '|' (pipe) character.
+The result of the choice is stored into a variable
+named 'selected', which can be queried with if.
+
+Optionally, I implement an extension of this form:
+
+       choice ch1|ch2|... >var
+
+Instead of storing to selected, 'var' will be used
+instead.
+
+= 3c. ================================================
+
+cleartext clears all of the text on-screen.
+
+       cleartext [mod]
+
+A modifier can be specified with mod. This is supposed to
+be fadeout or something.
+
+Strangely, this command does not actually appear in the
+conversion of fate-stay night.
+
+Also, I ignore mod. It seems to be useless...maybe.
+
+= 4d. ================================================
+
+delay will sit around and wait a certain number of
+frames.
+
+       delay frames
+
+'frames' is the number of frames to delay. Again, we
+operate at 60fps.
+
+= 5e. ================================================
+
+Technically, two commands. if and fi are used for
+execution control. if the result of if is true,
+all statements are executed until a matching fi.
+
+       if var op val
+
+'var' is a variable name. This can be a setvar, choice
+etc.
+
+op should be one of the following:
+
+       <       - less than
+       <=      - less than or equal
+       ==      - equal
+       !=      - not equal
+       >=      - more than or equal
+       >       - more than
+
+I have no clue how many of these VNDS implements, but
+I do them all.
+
+       -       -       -
+
+fi simply ends an if statement.
+
+       fi
+
+Note that I am a bit smarter than vnds here. if and fi
+CAN be embedded. So this is valid:
+
+       if selected == 2
+       if previous >= 5
+       text 'You win!'
+       fi
+       if previous <= 5
+       text 'You lose!'
+       fi
+       fi
+
+The behavior of VNDS would be to 'if previous <= 5' on
+failure of selected == 2 This is really not proper:
+I keep an if-count instead of an in-if value.
+
+= 6f. ================================================
+
+goto finds a label and continues execution from
+there.
+
+       goto label
+
+In my implementations, label is actually completely
+non-existent as a script command. Instead, goto
+finds labels by re-seeking through the file.
+
+= 7g. ================================================
+
+jump transfers control to another script file:
+
+       jump script
+
+My implementation provides an extra form of jump:
+
+       jump script line
+
+Which goes directly to line in the file. This
+is utilized for saving.
+
+= 8h. ================================================
+
+music loads a audio file from sound, and plays it in
+a loop as music.
+
+       music file
+
+You can pass '~' as file to stop playing all music
+like so:
+
+       music ~
+
+= 9i. ================================================
+
+random saves a random number to a variable.
+
+       random var low high
+
+low and high are the range the random number is in,
+inclusive.
+
+= 10j. ===============================================
+
+setimg displays an image from foreground at a
+position specified.
+
+       setimage file x y
+
+= 11k. ===============================================
+
+setvar and gsetvar are used to set variables. gsetvar
+specifically sets the 'global' state, that is, common
+to all saves.
+
+       [g]setvar var mod value
+
+mod can be one of the following:
+
+       =       Set var to value
+       +       Add value to var
+       -       Subtract value from var
+
+Also, if value is not specified, you can also do this
+as the mod:
+
+       ~       Reset to 0.
+
+One more thing that was not all over the place in
+vnds, but typically at the beginning.
+
+       setvar ~ ~
+
+Which means reset all vars.
+
+= 12l. ===============================================
+
+sound plays a sound, and optionally a number of times.
+
+       sound file [times]
+
+times is implicitly 1 if not specified. Pass -1 for
+infinity.
+
+You can do
+
+       sound ~
+
+To stop all playing sounds.
+
+= 13m. ===============================================
+
+text is the meaty huge function. It outputs text,
+as you probably expect.
+
+       text This is text dee doo...
+
+There are a bunch of variants with special meaning.
+I don't know why, but there are:
+
+       text                    - (no params) Clear screen
+       text !                  - Wait for input and clear all.
+       text ~                  - Clears all text (like cleartext)
+       text @...               - Don't wait for click after text
+                                         is spit.
+
+I've implemented a few extensions that help generally
+with NVL games.
+
+       ---                     - At the beginning of a line,
+                                         clears before text output.
+       "                               - More on this once finished.
+                                         Will stop any previous sfx
+                                         if encountered. 'smart'
+                                         voice stop.
+
+= 14n. ===============================================
+
+I've implemented a few debug commands to help out
+and just generally be useful (cheats? :P)
+
+Make sure you start up with the -b parameter, and
+start it from a console. Send it a SIGINT (^C).
+
+The console should now prompt you with this;
+       [scr command] $
+
+You can enter any command above; I recommend against
+entering choice, since it can't possibly work in
+this mode. if may also not work as expected.
+
+No commands run in this state will advance the
+program, but flags set will affect it.
+
+= 14n1. ==============================================
+
+help will print everything available.
+
+= 14n2. ==============================================
+
+stop will disable debugging and kill the console.
+You can SIGINT again at any point to come back
+to the debug state.
+
+= 14n3. ==============================================
+
+quit sets the quit state - it's equivalent to ESC in
+the form of a console command.
+
+= 14n4. ==============================================
+
+save will save to a mandatory file specified;
+
+       save file
+
+See section 15 for info on what the a save
+actually is.
+
+= 15o. ===============================================
+
+Saves are actually a script generated by the save
+function. So, for example, this is a save:
+
+       setvar selected = 2
+       music bgm03.ogg
+       bgload qmrtb.jpg
+       jump fate01-00.scr 261
+
+It restores any variables needed, loads the current
+music and bg, and jumps to the location we were
+previously at in the script.
+
+Saves should be loaded with the -s parameter until
+I get better gui stuff in place.
diff --git a/build b/build
index 5591d58b663a4065545a6a79cc2941a4642f2317..e43af728d86f740d7be1c8ebdce73ffa25d4dd26 100755 (executable)
--- a/build
+++ b/build
@@ -5,6 +5,11 @@ SRC=$ROOT/
 LIB=$ROOT/external/lib
 BIN=$ROOT/bin
 
+mkdir $LIB
+mkdir $BIN
+
+CXXFLAGS=-g
+
 source mk
 
 INCLUDE="-I$ROOT/external/include/zero -I$ROOT/vndc/include"
index 75deede61223825324047dfeb482c5026d4b45e4..2577f0910bc2b2c3f4d0b1f5cb1fe5097a15b1fe 100644 (file)
@@ -7,7 +7,7 @@
 class DataContainer {
        public:
                ContextManager* ctx;
-               bool if_fail = false;
+               int if_fail = 0;
                bool wait_input = false;
                char current_scr[400], current_music[400], current_bg[400];
                int screen_w = 800;
index 6b6d7d9ed9d0626aeccd498e20ab5265b23eda09..b0396cfced54b45d3f2e1d18df595b986ee45b3d 100644 (file)
@@ -10,12 +10,6 @@ void ParseCmd(char* line) {
 
        char** tokens = NULL;
 
-       // Remove all '\n' from this string
-       for(int i=0; i < 400; i++) {
-               if (line[i] == '\n')
-                       line[i] = '\0';
-       }
-
        strncpy(passthru_line, line, sizeof(char)*400);
 
        if(GetData()->verbose) printf("[scr] %s\n", line);
@@ -231,7 +225,24 @@ void Parse() {
 
        fgets(line, 400, GetData()->accessScriptHandle);
 
-       ParseCmd(line);
+       char* line_copy = line;
+
+       while(line_copy[0] == ' ' || line_copy[0] == '\t') {
+               line_copy[0] = '\0';
+               line_copy = &line_copy[1];
+       }
+
+       // Remove all '\n' from this string
+       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);
+       }
 
        free(line);
 
index ec4af942e0b73a34652a5e65e2d80f2bfdcea326..20d8444ed24441ad2a6e8aa9f43091790dc90612 100644 (file)
@@ -8,5 +8,5 @@
  */
 
 void op_fi() {
-       GetData()->if_fail = false;
+       GetData()->if_fail -= 1;
 }
index e733ca27976547f4c5f2d59e4913c174df4d4142..cdc8a7877c60f359d96e719343f0a62be269b42c 100644 (file)
  */
 
 void op_if(char* var, int* op, int* val) {
-       if (GetData()->if_fail)
+       if (GetData()->if_fail > 0) {
+               GetData()->if_fail += 1;
                return;
+       }
 
        int var_val = GetData()->s_flags[0][std::string(var)];