stephen-hqxu / superterrainplus

SuperTerrain+: A real-time procedural 3D infinite terrain engine with geographical features and photorealistic rendering.
MIT License
12 stars 1 forks source link

Do not use class when not necessary #52

Closed stephen-hqxu closed 1 year ago

stephen-hqxu commented 2 years ago

Problem

It is redundant to use a class for something like this:


class Foo {
private:
    Precondition precond;
    Intermediate interm;
    Bar result;
public:
    //store precondition
    Foo(...) {
        //do something
        // ...
        //store
        this->precond = precondition_data;
    }
    //store intermediate states
    void addData(const Intermediate& middle) {
        this->interm = middle;
    }
    void finalise() {
        //use precondition and intermediate data to do stuff
        // ...
        //store
        this->result = result_data;
    }
    const Bar& get() const noexcept {
        return this->bar;
    }
};

Which can be generally simplified to:


namespace Foo {
    Bar doStuff(const Precondition& precond, const Intermediate& interm) {
        //do something with precondition and intermediate data
        // ...
        //finish
        return result;
    }
}

Task

Remove class design and turn it into non-OOP if the only member function in the class is a getter function to the result, for the following files:

stephen-hqxu commented 2 years ago

Class refactor and improvement for source code in SuperAlgorithm+Device are done.

stephen-hqxu commented 2 years ago

The majority of tasks are done, only left with a few parser libraries, for which I may do it together with #51.