Implement Build Object Classes

NOTE: This exercise assumes you have completed the previous exercise.

In this exercise, you'll learn to implement two simple Scenome Scripting Language classes that manage build inputs and build outputs. Scenome Scripting Language supports classes with data members only. Class member functions are not supported. Data members can be plain old data such as ints and floats, or data members can be objects. If a data member is an object, you can leave it initialized as a nullptr (which means you need to set the pointer to a live object after the class is instantiated), or you can use auto to make it a live object at the time of instantiation.

Implement Class <BuildInputs>

  1. Go to the text editor and find the script app_octopus_workload_terrain_classes.ssl.
  2. Insert the following class declaration into the document, directly below the import statements.

    Copy Text To Clipboard

    ///////////////////////////////////////////////////////////////////////////////
    // class
    ///////////////////////////////////////////////////////////////////////////////
    
    class BuildInputs
    {
    Model3D m_oModel;
    Render3D m_oDevice;
    RenderInfo m_oRenderInfo;
    int m_eMinGlslVersion;
    
    FileNode m_oData;
    string m_sBuildFolder;
    
    StrList m_slMessages;
    
    auto FilePath m_oModelPath;
    auto FilePath m_oSourcePath;
    
    auto Int32Vector m_oLens;
    int m_iArraySlices;
    int m_iMaxBatchSize;
    
    auto GdalImageInfo m_oGdalImageInfo;
    auto GdalDataSet m_oGdalDataset;
    auto Int32Vector m_viDstRange;
    auto Int32Vector m_viMapInfo;
    
    int m_nScaleFactor;
    double m_dSpacingX;
    double m_dSpacingY;
    double m_dRangeX;
    double m_dRangeY;
    double m_dChunkRangeX;
    double m_dChunkRangeY;
    
    auto Float32Array m_afMinMaxElevation;
    auto Float32Array m_afMinMaxNormals;
    
    auto FilePath m_oArraysPath;
    auto FilePath m_oMapsPath;
    auto FilePath m_oAnalysisPath;
    auto FilePath m_oImagesPath;
    
    string m_sElevationMapFilePath;
    string m_sAspectMapFilePath;
    string m_sSlopeMapFilePath;
    string m_sOpennessMapFilePath;
    };
    

    This class has a variety of data members that are used to store data used throughout the build process. Note that there is a mix of plain old data such as ints and doubles, and objects declared with and without auto. The first important thing to know is that all object data members are pointers, whether they are declared with auto or not. For a C++ programmer, this means that the data member Model3D m_oModel; is equivalent to Model3D * m_oModel = nullptr;. The declaration auto GdalImageInfo m_oGdalImageInfo; is equivalent to the C++ GdalImageInfo m_oGdalImageInfo;, where you would expect m_oGdalImageInfo to be a live object you can use.

    You cannot initialize class members in the class itself. You must first instantiate the class and then you can initialize data members as needed. By default, class members that are plain old data will be zero initialized, object class members declared without auto will be nullptr initialized, and object class members declared with auto will be initialized to the constructor defaults specified in the underlying C++ code.

    This can seem limiting, but in practice, it works really well. It's worth mentioning that you can use Scenome Scripting Language functions to initialize objects, and if you want to have a custom 'constructor', you could write that function in this library.

    Like in C++, when an instance of a class goes out of scope, the destructors of its data members are executed. This means you can use RAII techniques when you write Scenome Scripting Language code, which is very convenient.

  3. Save changes to the script.

Implement Class <BuildOutputs>

  1. Go to the text editor and find the script app_octopus_workload_terrain_classes.ssl.
  2. Find the class named BuildInputs and insert the following class declaration immediately below it.

    Copy Text To Clipboard

    ///////////////////////////////////////////////////////////////////////////////
    // class
    ///////////////////////////////////////////////////////////////////////////////
    
    class BuildOutputs
    {
    auto TypeBuffer m_apArrayImages;
    auto TypeBuffer m_apMapImages;
    
    Image m_oAngleTiles;
    Image m_oSurfaceTiles;
    Image m_oSumTiles;
    
    auto TypeBuffer m_apElevationImages;
    auto StrList m_slElevationPaths;
    auto TypeBuffer m_apSlopeImages;
    auto StrList m_slSlopePaths;
    auto TypeBuffer m_apOpenImages;
    auto StrList m_slOpenPaths;
    auto TypeBuffer m_apAspectImages;
    auto StrList m_slAspectPaths;
    auto TypeBuffer m_apAreaImages;
    auto StrList m_slAreaPaths;
    auto TypeBuffer m_apAreaImagesFloat;
    auto StrList m_slAreaPathsFloat;
    auto TypeBuffer m_apSumImages;
    auto StrList m_slSumPaths;
    
    auto FilePath m_oReportPath;
    };
    

    We'll use an object of type <BuildOutputs> to manage the outputs of the build process. We'll store collections of <Image> objects in the <TypeBuffer> data members, and we'll store collections of file paths in the <StrList> objects. The <TypeBuffer> objects will own the <Image> objects, which means they will automatically be destroyed when the instance of <BuildOutputs> goes out of scope at the end of the build command.

  3. Save changes to the script.

Test Code Changes

  1. Return to the running Octopus app.
  2. Select Desktop » Refresh Scripts from the main menu. ( ALT + D + R )

    The application displays script compiler messages in the output window:

    Start loading scripts
    Done loading scripts; 10 loaded in 1.29 ms; avg 0.09
    

    If there are any script compiler errors, undo your changes in the text editor, go back to the previous step, and follow the instructions again. Here is an example of what error messages might look like:

    Start loading scripts
    D:\release6\scripts\app_shell_util.ssl(1770) : error: newline in constant
    Done loading scripts; 10 loaded in 1.29 ms; avg 0.09
    

    This exercise is complete. Please proceed to the next exercise.