• Content count

  • Joined

  • Last visited

Community Reputation

112 Neutral

About jmcomets

  • Rank
  1. Encapsulating the library is exactly my point, this was what I was going for at first, but in that case I would roughly need to write wrappers and callbacks for a bunch of classes. Is there a way to avoid this, or should I just shut up and code? Oh and Input used to be a namespace actually [img][/img], I can't remember why it was decided to change it to a struct though.
  2. Hi all, Currently working a school project which happens to be a multiplayer 2D platform / fighting game, I'm now organizing all the classes in different subgroups, mainly to allow a certain level of abstraction when handling game objects. Basically right now this is what worked out for object events / handling / viewing: [indent=1]An [i]Object [/i]class allows abstraction for game object updating.[/indent] [indent=1]An [i]Input[/i] class represents a state of user input (keyboard, mouse, joystick).[/indent] [indent=1]A [i]View[/i] class provides an interface for display, and will probably be extended by an [i]Animation[/i] class.[/indent] [indent=1]Associated [i]Observer[/i] classes update these [i]Subjects[/i]' state ([url=""]Observer pattern[/url])[/indent] The idea is to do the 3rd party-specific operations in the [i]Observer[/i] classes (events -> [i]Listener[/i], rendering -> [i]Canvas[/i]). For example, for the Input module: [source lang="cpp"] struct Input { class Mouse { public: enum Button { Any = 0, Left = 1, Right = 2, // etc... }; bool IsDown(Button = Any) const; protected: friend class Listener; void setDown(Button); void setPos(int, int); private: int btns_down_; int x_, y_; } mouse; class Keyboard { public: enum Key { A, B, C, // etc... }; bool IsDown(Key) const; protected: friend class Listener; void setDown(Key); private: std::set<Key> keys_down_; } keyboard; // similar for joystick }; [/source] But so far I can't figure out how to do this specifically in the observers, without introducing dependencies in the [i]Subject[/i] classes. This problem is mainly present concerning an object's view: concrete classes need knowledge about camera, alpha blending, coloring, etc... Besides the obvious impossible solutions like "code up SFML / SDL / Allegro / whatever", what options do I have? Is it actually possible (in practical cases) to separate these APIs from the game core, and if so, is this overkill?