First of all, I wasn’t really sure if I wanted to write this post or not. The data creation framework I made is mostly hacked without proper/formal scripting architectural design. But if this article could help anyone out there in some ways in their programming tasks, even just a little bit, then this blog wouldn’t be a waste. With this in mind, this article will be very brief with very little explanation for its implementation.
This data creation framework I will present enables a data driven architectural design to deliver game data/assets to your game. Since this is a data creation framework, its main purpose is only to bring data; nothing more, nothing less. That means that although the script looks like a full blown scripting language, it is not. This is not like LUA or any other scripting languages that you can define procedural-scripting or gameplay code. This framework simply defines a set of data with an assigned values for the framework to easily read in the data.
If you take a look at the class definition[1], you’ll see lots of containers supporting each data type that the framework supports. Let’s say for example you have a sample script code that looks something like in Code listing 1.
- Vector3 vec3 = ( 1.0, 3.0, 2.578 ); // 3D Vectors
Code Listing 1: An example of declaring a Vector3 data with a defined value of (1.0, 3.0, 2.578)
vec3, as Vector3 as its data type, will be stored in the Vector3Array container.
So this framework is very simple and straightforward. It doesn’t do anything else other than declare data and this will do fine for the system I’m currently working towards on. The main methods that does the main string parsing and reading are in the GetLine, LoadFromFile, ReadSection, and ReadValue methods.
Here’s the implementation for the framework[1][2]. And a demo script on what the framework can do(Code Listing 2).
- // This is a sample script used to test Pulse Engine's PulseScript system.
- // Below shows some of the features already available.
- // A comment. An empty space follows below.
- /* MULTI-LINE COMMENT
- This is a multi-line comment. Multi-line comments
- can span multiple lines and PulseScript will strip
- it all out until it hits the closing mult-line comment character.
- */
- // Another comment
- Section pass // Comment in the same line as the code.
- {
- String string = "PulseScript can take in strings!!!!";
- String multiLineSting = "PulseScript can also take in multi-line strings!!!!\\par This is the second line of a multi-line string.\\par Third line of the multi-line string. Another string in the third line. \\par Fourth line of the multi-string. This is the end of a multi-line string. ";
- // Supports boolean values
- Bool bool1 = true;
- // Supports scalar types (i.e. int and float)
- Float f = 3.987654321;
- Int n1 = 5;
- Int n2 = 10.9257; // This will automatically convert the value to int(floor, so the value will be 10).
- // Supports section comments
- Bool /*Yup, this is a section comment*/ bool2 = false;
- /*Another section comment*/ Bool bool2 = false;
- Bool /* section comment */bool3 /*another section comment*/ = true/*yet another section comment*/; /*and another*/ // And another…
- // Supports vectors too!!!
- Vector2 vec2 = ( 1.0, 3.0f /*appending 'f' is optional*/ ); // 2D Vectors
- Vector3 vec3 = ( 1.0, 3.0, 2.578 ); // 3D Vectors
- Vector4 vec4 = ( 1.0, 3.0 , 2.578, 3.14159265 ); // 4D Vectors or Quaternions
- /* If you haven't noticed I just pulled a pi there. lolz */
- /* Supports recursive sections (sections inside a section) */
- Section Mesh
- {
- Section Material
- {
- String mergeMode = "Blend";
- String bumpMap = "bump.tga";
- String textureName = "MeshTexture.tga";
- };
- String meshName = "tiny.x"; // The infamouse DX character
- };
- // Array of ints.
- Int[5] indices1 = { 1, 2, 3, 4, 5 }; // We can explicitly define the size of an array
- Int[9] indices2 = { 1, 2, 3, \\par 4, 5, 6, \\par 7, 8, 9, \\tab \\ comma at the end is optional
- };
- // NOTE: Another important thing is that only arrays and strings can define values in multiple lines.
- Float[3] floatArray = { 3.256, 1.23, 456.789 }; // Float arrays
- Vector2[2] vert2dArray1 = { (3.0, 2.0), (2.56, 1.23) };
- Vector2[3] vert2dArray2 = { (3, 2.0), (2.56, 1.23), \\par (1.23, 4.56) };
- /*
- You can't do things like this though:
- Vector3[2] bla = { ( 1.2, 2.2, \ // <— Incomplete
- 2.1 ), (1,2,3 )};
- */
- // TODO: We still need to implement these…
- // Same variable name implicitly overrides the older one. Do something about this.
- // Int[] indices3 = { 6,7,8,9,10 }; // We can probably do something like this in the future…
- };
Code Listing 2: Sample data creation script. Download it here[3]
Bibliography:
1. PulseScript.h, http://codaset.com/codesushi/pulse-tec/source/master/blob/Source/Engine/Include/PulseScript.h
2. PulseScript.cpp, http://codaset.com/codesushi/pulse-tec/source/master/blob/Source/Engine/Source/PulseScript.cpp
3. Sample PulseScript script code, http://codaset.com/codesushi/pulse-tec/source/master/blob/Source/Engine/Demo/SampleScript.ps
– MrCodeSushi