Closed richelbilderbeek closed 5 years ago
Is your feature request related to a problem? Please describe.
Currently, sfml_resources::get_agent_sprite needs an agent as a function argument to return a texture:
sfml_resources::get_agent_sprite
agent
sf::Texture &sfml_resources::get_agent_sprite(const agent &a) noexcept
Taking a look into the function, only the agent_type is used:
agent_type
sf::Texture &sfml_resources::get_agent_sprite(const agent &a) noexcept { switch (a.get_type()) { // ... } }
If the function only needs the agent_type of an agent, then that should be supported.
Describe the solution you'd like
get_agent_sprite
sf::Texture &sfml_resources::get_agent_sprite(const agent_type t) noexcept { // Most of the code here }
Yes, functions can have identical names, as long as the compiler can figure out which one is which.
sf::Texture &sfml_resources::get_agent_sprite(const agent &a) noexcept { return get_agent_sprite(a.get_type()); }
This ensures nothing will break.
There is a test written:
//#define FIX_ISSUE_537 #ifdef FIX_ISSUE_537 // Can get the sprite of an agent_type { assert(resources.get_agent_sprite(agent_type::cow).getSize().x > 0); assert(resources.get_agent_sprite(agent_type::crocodile).getSize().x > 0); assert(resources.get_agent_sprite(agent_type::fish).getSize().x > 0); assert(resources.get_agent_sprite(agent_type::goat).getSize().x > 0); assert(resources.get_agent_sprite(agent_type::grass).getSize().x > 0); assert(resources.get_agent_sprite(agent_type::plankton).getSize().x > 0); assert(resources.get_agent_sprite(agent_type::tree).getSize().x > 0); } #endif // FIX_ISSUE_537
Remove the lines with preprocessor directives (#define, #ifdef and #endif).
#define
#ifdef
#endif
If these compile, you did it :+1:
Describe alternatives you've considered
None.
Additional context
You should only work within sfml_resources.cpp and sfml_resources.h: this is an easy Issue :+1:
sfml_resources.cpp
sfml_resources.h
Well done!
Is your feature request related to a problem? Please describe.
Currently,
sfml_resources::get_agent_sprite
needs anagent
as a function argument to return a texture:Taking a look into the function, only the
agent_type
is used:If the function only needs the
agent_type
of anagent
, then that should be supported.Describe the solution you'd like
get_agent_sprite
that uses anagent_type
:Yes, functions can have identical names, as long as the compiler can figure out which one is which.
This ensures nothing will break.
There is a test written:
Remove the lines with preprocessor directives (
#define
,#ifdef
and#endif
).If these compile, you did it :+1:
Describe alternatives you've considered
None.
Additional context
You should only work within
sfml_resources.cpp
andsfml_resources.h
: this is an easy Issue :+1: