Last active
August 29, 2015 14:04
-
-
Save Veedrac/85da58f789bd84fc5693 to your computer and use it in GitHub Desktop.
Getter-Setter vs Properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// | |
/// The class to hold an object's information so that the Engine can | |
/// manipulate it. | |
/// | |
/// | |
/// | |
class Object { | |
protected: | |
/// | |
/// The object's renderable component | |
/// | |
RenderableComponent renderable_component; | |
public: | |
Object(); | |
// = default not supported in g++-4.8 | |
virtual ~Object(); | |
/// | |
/// Walkable: determine if the object can be walked over | |
/// | |
Accessor<Walkability> walkability; | |
/// | |
/// The x position of the object | |
/// | |
Accessor<double> x_position; | |
/// | |
/// The y position of the object | |
/// | |
Accessor<double> y_position; | |
/// | |
/// The object's id | |
/// | |
/// @warning | |
/// Do not mutate! Only non-mutating access is supported! | |
/// | |
Accessor<int> id; | |
/// | |
/// The name of the object | |
/// | |
Accessor<std::string> name; | |
/// | |
/// Boolean to indicate if the object has set itself to be renderable | |
/// | |
Accessor<bool> renderable; | |
/// | |
/// Get the renderable component | |
/// @return the renderable component for this object | |
/// | |
RenderableComponent *get_renderable_component() { return &renderable_component; } | |
std::unique_ptr<LockableEntityThread> daemon; | |
bool moving = false; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// | |
/// The class to hold an object's information so that the Engine can | |
/// manipulate it. | |
/// | |
/// | |
/// | |
class Object { | |
private: | |
/// | |
/// Boolean to indicate if the object has set itself to be renderable | |
/// | |
bool renderable = true; | |
/// | |
/// The object's id | |
/// | |
int id = 0; | |
/// | |
/// The name of the object | |
/// | |
std::string name = ""; | |
/// | |
/// Walkable: determine if the object can be walked over | |
/// | |
Walkability walkability = Walkability::WALKABLE; | |
protected: | |
/// | |
/// The object's renderable component | |
/// | |
RenderableComponent renderable_component; | |
/// | |
/// The x position of the object | |
/// | |
double x_position = 0; | |
/// | |
/// The y position of the object | |
/// | |
double y_position = 0; | |
public: | |
Object(); | |
//= default not supported in g++-4.8 | |
virtual ~Object(); | |
/// | |
/// DO NOT USE THIS! ONLY THE ENGINE SHOULD USE THIS FUNCTION | |
/// Set the id of the object | |
/// @param new_id the object's id | |
/// | |
void set_id(int new_id); | |
/// | |
/// Get the object's walkability | |
/// | |
Walkability get_walkability() { return walkability; } | |
/// | |
/// Set the object's walkability | |
/// @param _walkability the walkability of the object | |
/// | |
void set_walkability(Walkability _walkability) { walkability = _walkability; } | |
/// | |
/// Set the object's x position in tiles | |
/// @param x_pos the new x position in tiles | |
/// | |
void set_x_position(int x_pos); | |
void set_x_position(double x_pos); | |
/// | |
/// Get the object's x position in tiles | |
/// @return the object's x position in tiles | |
/// | |
double get_x_position() { return x_position; } | |
/// | |
/// Set the object's y position in tiles | |
/// @param y_pos | |
/// | |
void set_y_position(int y_pos); | |
void set_y_position(double y_pos); | |
/// | |
/// Get the object's y position in tiles | |
/// @return the object's y position in tiles | |
/// | |
double get_y_position() { return y_position; } | |
/// | |
/// Get the id of the object | |
/// @return the id of the object | |
/// | |
int get_id() { return id; } | |
/// | |
/// Set the object's name | |
/// @param new_name the name of the object | |
/// | |
void set_name(std::string new_name); | |
/// | |
/// Get the name of the object | |
/// @return the name of the object | |
std::string get_name() { return name; } | |
/// | |
/// Get the renderable component | |
/// @return the renderable component for this object | |
/// | |
RenderableComponent* get_renderable_component() { return &renderable_component; } | |
/// | |
/// Determine if the object can be rendered | |
/// @return boolean value: true if the object can be rendered and false if not | |
/// | |
bool is_renderable() { return renderable; } | |
/// | |
/// Set whether the object can be rendered | |
/// @param can_render true if the object can be rendered and false if not | |
/// | |
void set_renderable(bool can_render) { renderable = can_render; } | |
std::unique_ptr<LockableEntityThread> daemon; | |
bool moving = false; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment