Advertisement
Guest User

Untitled

a guest
Mar 29th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. class Event_Queue
  2. {
  3. private:
  4.  
  5. SDL_Event input;
  6.  
  7. std::queue<Event> event_queue;
  8. std::vector<Event_Receiver*> receiver_list;
  9. public:
  10. void add_receiver(Event_Receiver* receiver_ptr);
  11. bool remove_receiver(Event_Receiver* receiver_ptr);
  12.  
  13. void push_event(Event e);
  14.  
  15. void poll_input();
  16. void poll_event();
  17.  
  18. };
  19.  
  20. class Event_Receivable
  21. {
  22. public:
  23. virtual ~Event_Receivable() = 0;
  24. virtual void on_notify(Event* e) = 0;
  25.  
  26. };
  27.  
  28. class Event_Receiver
  29. {
  30. public:
  31. Event_Receiver(Event_Receivable* owner_obj);
  32. ~Event_Receiver();
  33.  
  34. void receive_event(Event* e);
  35. void notify_owner(Event* e);
  36. void set_owner(Event_Receivable* owner_obj) {owner = owner_obj;}
  37.  
  38. Event_Receivable* get_owner_obj() {return owner;}
  39.  
  40. private:
  41. Event_Receivable* owner;
  42.  
  43. };
  44.  
  45. #include "Common.h"
  46. #include "boost/any.hpp"
  47.  
  48. /*
  49. * Event is used extensively within the program.
  50. * It is the basis for all messages in the event system.
  51. * Objects will send and receive events.
  52. *
  53. * It uses boost::any in order to be able to
  54. * attach any kind of data to be read.
  55. *
  56. * Event is meant to be extremely flexible in order to
  57. * be extensible to many different types of games.
  58. */
  59. class Event
  60.  
  61. {
  62. private:
  63. std::string name;
  64. std::string type;
  65. std::vector<boost::any> info;
  66. public:
  67. Event(std::string name_str, std::string type_str)
  68. {
  69. name = name_str;
  70. type = type_str;
  71. }
  72.  
  73. void set_name(std::string str) {name = str;}
  74. void set_type(std::string str) {type = str;}
  75. void attach_data(boost::any data) {info.push_back(data);}
  76.  
  77. std::string get_name() {return name;}
  78. std::string get_type() {return type;}
  79. boost::any get_info() {return info;}
  80. };
  81.  
  82. class Event_Sender
  83. {
  84. public:
  85. void send_event(Event e);
  86. void send_event(Event e, Event_Queue q);
  87.  
  88. void set_event_queue(Event_Queue e_queue) {event_queue = &e_queue;}
  89.  
  90. Event_Queue* get_event_queue() {return event_queue;}
  91.  
  92. private:
  93. Event_Queue* event_queue;
  94. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement