Jump to content

  • Log In with Google      Sign In   
  • Create Account


jmcomets

Member Since 04 Jul 2012
Offline Last Active Nov 17 2012 09:48 AM
-----

Topics I've Started

How to reduce 3rd party library dependencies?

03 November 2012 - 10:11 AM

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:

An Object class allows abstraction for game object updating.

An Input class represents a state of user input (keyboard, mouse, joystick).

A View class provides an interface for display, and will probably be extended by an Animation class.


Associated Observer classes update these Subjects' state (Observer pattern)


The idea is to do the 3rd party-specific operations in the Observer classes (events -> Listener, rendering -> Canvas).

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 Subject 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?

PARTNERS