Somebody show me a components system that is NOT implemented with an object-oriented paradigm? I don't think you can. The mere fact that we are attaching "components" to "entities"--both of which are "objects" that have encapsulated attributes (the definition of an object-oriented paradigm) makes my point look even stronger.
What about the method through which you guys are registering your components?
That is clearly a factory design pattern. The mere fact that you can't (prettily) implement a component without utilizing one or more other object-oriented design patterns also proves my point. By the way, that looks pretty good, K-Bal. It's essentially what we're doing. We have a little bit of cheap-assedness going on so that our client components auto register themselves (without having to do it at program initialization. I was planning on covering that in my article that I was going to submit to our newsletter...K-Bal wrote:Code: Select all
int main() { sf::RenderWindow window( sf::VideoMode( 300, 200 ), "Test", sf::Style::Close ); window.UseVerticalSync(true); ComponentFactory factory; factory.RegisterComponent( "Movement", &MovementComp::Create ); factory.RegisterComponent( "Rendering", &RenderComp::Create ); factory.RegisterComponent( "Collision", &CollisionComp::Create ); GameObject player( factory ); player.AddComponent( "Movement" ); player.AddComponent( "Rendering" ); player.AddComponent( "Collision" ); GameObject stick( factory ); stick.AddComponent( "Movement" ); stick.AddComponent( "Rendering" ); stick.AddComponent( "Collision" ); while( window.IsOpened() ) { float delta = window.GetFrameTime(); player.UpdateComponents( delta ); player.UpdateProperties( delta ); stick.UpdateComponents( delta ); stick.UpdateProperties( delta ); sf::Event event; while( window.GetEvent( event ) ) { switch( event.Type ) { case sf::Event::Closed: window.Close(); break; default: break; } } const sf::Input& input = window.GetInput(); player.GetProperty< sf::Vector2f >("Movement:Velocity").Set(sf::Vector2f(0.f, 0.f)); if(input.IsKeyDown(sf::Key::Down)) { player.GetProperty< sf::Vector2f >("Movement:Velocity").Set(sf::Vector2f(0.f, 50.f)); } if(input.IsKeyDown(sf::Key::Up)) { player.GetProperty< sf::Vector2f >("Movement:Velocity").Set(sf::Vector2f(0.f, -50.f)); } if(input.IsKeyDown(sf::Key::Left)) { player.GetProperty< sf::Vector2f >("Movement:Velocity").Set(sf::Vector2f(-50.f, 0.f)); } if(input.IsKeyDown(sf::Key::Right)) { player.GetProperty< sf::Vector2f >("Movement:Velocity").Set(sf::Vector2f(50.f, 0.f)); } window.Clear(); window.Draw(player.GetProperty< sf::Sprite >("Rendering:Shape").Get()); window.Display(); } return 0; }
But yeah, I challenge anybody to prove that a "component system" can be a programming paradigm, rather than an object-oriented design pattern.