| @@ -26,12 +26,9 @@ namespace lol | |||||
| #if EMSCRIPTEN | #if EMSCRIPTEN | ||||
| extern "C" | extern "C" | ||||
| { | { | ||||
| int C_Send(int id, const char* message) | |||||
| { | |||||
| return (int)MessageService::Send(id, message); | |||||
| } | |||||
| int C_Send(const char* message) { return (int)MessageService::Send(MessageBucket::In, message); } | |||||
| //NOT IMPLEMENTED | //NOT IMPLEMENTED | ||||
| //bool C_FetchFirst(int id, String& message); | |||||
| //bool C_FetchFirst(String& message); | |||||
| } | } | ||||
| #endif //EMSCRIPTEN | #endif //EMSCRIPTEN | ||||
| @@ -53,10 +50,10 @@ MessageService::~MessageService() | |||||
| } | } | ||||
| //Setup/Destroy | //Setup/Destroy | ||||
| void MessageService::Setup(int bucket_size) | |||||
| void MessageService::Setup() | |||||
| { | { | ||||
| g_messageservice = new MessageService(); | g_messageservice = new MessageService(); | ||||
| g_messageservice->m_bucket.Resize(bucket_size); | |||||
| g_messageservice->m_bucket.Resize(MessageBucket::Max); | |||||
| } | } | ||||
| void MessageService::Destroy() | void MessageService::Destroy() | ||||
| @@ -66,7 +63,7 @@ void MessageService::Destroy() | |||||
| } | } | ||||
| //----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
| bool MessageService::Send(int id, const String& message) | |||||
| bool MessageService::Send(MessageBucket id, const String& message) | |||||
| { | { | ||||
| if (g_messageservice) | if (g_messageservice) | ||||
| { | { | ||||
| @@ -76,7 +73,7 @@ bool MessageService::Send(int id, const String& message) | |||||
| return false; | return false; | ||||
| } | } | ||||
| bool MessageService::Send(int id, const char* message) | |||||
| bool MessageService::Send(MessageBucket id, const char* message) | |||||
| { | { | ||||
| if (g_messageservice) | if (g_messageservice) | ||||
| { | { | ||||
| @@ -90,7 +87,7 @@ bool MessageService::Send(int id, const char* message) | |||||
| } | } | ||||
| //---- | //---- | ||||
| bool MessageService::FetchFirst(int id, String& message) | |||||
| bool MessageService::FetchFirst(MessageBucket id, String& message) | |||||
| { | { | ||||
| if (g_messageservice) | if (g_messageservice) | ||||
| { | { | ||||
| @@ -101,7 +98,7 @@ bool MessageService::FetchFirst(int id, String& message) | |||||
| return false; | return false; | ||||
| } | } | ||||
| bool MessageService::FetchFirst(int id, String& message, time_t& timestamp) | |||||
| bool MessageService::FetchFirst(MessageBucket id, String& message, time_t& timestamp) | |||||
| { | { | ||||
| if (g_messageservice) | if (g_messageservice) | ||||
| { | { | ||||
| @@ -121,7 +118,7 @@ bool MessageService::FetchFirst(int id, String& message, time_t& timestamp) | |||||
| } | } | ||||
| //---- | //---- | ||||
| bool MessageService::FetchAll(int id, String& message) | |||||
| bool MessageService::FetchAll(MessageBucket id, String& message) | |||||
| { | { | ||||
| if (g_messageservice) | if (g_messageservice) | ||||
| { | { | ||||
| @@ -132,7 +129,7 @@ bool MessageService::FetchAll(int id, String& message) | |||||
| return false; | return false; | ||||
| } | } | ||||
| bool MessageService::FetchAll(int id, String& message, time_t& first_timestamp) | |||||
| bool MessageService::FetchAll(MessageBucket id, String& message, time_t& first_timestamp) | |||||
| { | { | ||||
| if (g_messageservice) | if (g_messageservice) | ||||
| { | { | ||||
| @@ -20,6 +20,35 @@ | |||||
| namespace lol | namespace lol | ||||
| { | { | ||||
| //Utility enum for message service | |||||
| struct MessageBucket | |||||
| { | |||||
| enum Value | |||||
| { | |||||
| AppIn = 0, | |||||
| AppOut, | |||||
| Bckt0, | |||||
| Bckt1, | |||||
| Bckt2, | |||||
| Bckt3, | |||||
| Bckt4, | |||||
| Bckt5, | |||||
| Bckt6, | |||||
| Bckt7, | |||||
| Bckt8, | |||||
| Bckt9, | |||||
| Max | |||||
| } | |||||
| m_value; | |||||
| inline MessageBucket(Value v) : m_value(v) {} | |||||
| inline MessageBucket() : m_value(AppIn) {} | |||||
| inline operator Value() { return m_value; } | |||||
| }; | |||||
| //Message list container with time in it | |||||
| struct MessageList | struct MessageList | ||||
| { | { | ||||
| MessageList(time_t timestamp, const String& message) | MessageList(time_t timestamp, const String& message) | ||||
| @@ -45,16 +74,16 @@ public: | |||||
| static char const *GetName() { return "<messageservice>"; } | static char const *GetName() { return "<messageservice>"; } | ||||
| //Setup/Destroy | //Setup/Destroy | ||||
| static void Setup(int bucket_size); | |||||
| static void Setup(); | |||||
| static void Destroy(); | static void Destroy(); | ||||
| //Common interactions | //Common interactions | ||||
| static bool Send(int id, const String& message); | |||||
| static bool Send(int id, const char* message); | |||||
| static bool FetchFirst(int id, String& message); | |||||
| static bool FetchFirst(int id, String& message, time_t ×tamp); | |||||
| static bool FetchAll(int id, String& message); | |||||
| static bool FetchAll(int id, String& message, time_t &first_timestamp); | |||||
| static bool Send(MessageBucket id, const String& message); | |||||
| static bool Send(MessageBucket id, const char* message); | |||||
| static bool FetchFirst(MessageBucket id, String& message); | |||||
| static bool FetchFirst(MessageBucket id, String& message, time_t ×tamp); | |||||
| static bool FetchAll(MessageBucket id, String& message); | |||||
| static bool FetchAll(MessageBucket id, String& message, time_t &first_timestamp); | |||||
| private: | private: | ||||
| Array<Array<MessageList> > m_bucket; | Array<Array<MessageList> > m_bucket; | ||||
| @@ -142,7 +142,7 @@ canvas.emscripten | |||||
| Module.setStatus('All downloads complete.', 1, 1); | Module.setStatus('All downloads complete.', 1, 1); | ||||
| }, | }, | ||||
| //IMPORTANT : This is the C -> Javascript wraping, add your functions list here. | //IMPORTANT : This is the C -> Javascript wraping, add your functions list here. | ||||
| wrapup_list: [ {src_obj: null, func_name: 'DoSendMessage', c_func_name: 'C_Send', return_var: 'number', args: ['number', 'string'] } ], | |||||
| wrapup_list: [ {src_obj: null, func_name: 'DoSendMessage', c_func_name: 'C_Send', return_var: 'number', args: ['string'] } ], | |||||
| do_wrapup: function() | do_wrapup: function() | ||||
| { | { | ||||
| for (var i = 0; i < this.wrapup_list.length; i++) | for (var i = 0; i < this.wrapup_list.length; i++) | ||||
| @@ -158,7 +158,7 @@ canvas.emscripten | |||||
| //Module <-> Page communication setup | //Module <-> Page communication setup | ||||
| SendMessage:function(message) | SendMessage:function(message) | ||||
| { | { | ||||
| this.DoSendMessage(0, message); | |||||
| this.DoSendMessage(message); | |||||
| }, | }, | ||||
| ModuleSendMessage:function(message) | ModuleSendMessage:function(message) | ||||
| { | { | ||||
| @@ -137,7 +137,7 @@ void NaClInstance::HandleMessage(const pp::Var& message) | |||||
| return; | return; | ||||
| /* FIXME: do some shit here */ | /* FIXME: do some shit here */ | ||||
| MessageService::Send(0/*MSG_IN*/, message.AsString().c_str()); | |||||
| MessageService::Send(MessageBucket::AppIn, message.AsString().c_str()); | |||||
| } | } | ||||
| void NaClInstance::DidChangeView(const pp::Rect& position, const pp::Rect& clip) | void NaClInstance::DidChangeView(const pp::Rect& position, const pp::Rect& clip) | ||||
| @@ -1,4 +1,4 @@ | |||||
| sc#fff ab 2 | |||||
| sc#fff ab 4 | |||||
| //splt 0 | //splt 0 | ||||
| //test | //test | ||||
| @@ -194,7 +194,7 @@ public: | |||||
| #endif //NO_NACL_EM | #endif //NO_NACL_EM | ||||
| // Message Service | // Message Service | ||||
| MessageService::Setup(MSG_MAX); | |||||
| MessageService::Setup(); | |||||
| // Mesh Setup | // Mesh Setup | ||||
| m_render_max = vec2(-.9f, 6.1f); | m_render_max = vec2(-.9f, 6.1f); | ||||
| @@ -428,7 +428,7 @@ public: | |||||
| //-- | //-- | ||||
| String mesh(""); | String mesh(""); | ||||
| int u = 4; | int u = 4; | ||||
| while (u-- > 0 && MessageService::FetchFirst(MSG_IN, mesh)) | |||||
| while (u-- > 0 && MessageService::FetchFirst(MessageBucket::AppIn, mesh)) | |||||
| { | { | ||||
| int o = 1; | int o = 1; | ||||
| while (o-- > 0) | while (o-- > 0) | ||||
| @@ -448,10 +448,10 @@ public: | |||||
| if (m_stream_update_time > .0f) | if (m_stream_update_time > .0f) | ||||
| { | { | ||||
| m_stream_update_time = -1.f; | m_stream_update_time = -1.f; | ||||
| MessageService::Send(MSG_IN, "[sc#f8f ab 1]"); | |||||
| // MessageService::Send(MSG_IN, "[sc#f8f ab 1 splt 4 twy 90]"); | |||||
| // MessageService::Send(MSG_IN, "[sc#8ff afcb 1 1 1 0]"); | |||||
| // MessageService::Send(MSG_IN, "[sc#ff8 afcb 1 1 1 0]"); | |||||
| MessageService::Send(MessageBucket::AppIn, "[sc#f8f ab 1]"); | |||||
| // MessageService::Send(MessageBucket::AppIn, "[sc#f8f ab 1 splt 4 twy 90]"); | |||||
| // MessageService::Send(MessageBucket::AppIn, "[sc#8ff afcb 1 1 1 0]"); | |||||
| // MessageService::Send(MessageBucket::AppIn, "[sc#ff8 afcb 1 1 1 0]"); | |||||
| } | } | ||||
| #elif WIN32 | #elif WIN32 | ||||
| //-- | //-- | ||||
| @@ -491,7 +491,7 @@ public: | |||||
| && (!m_cmdlist.Count() || cmd != m_cmdlist.Last())) | && (!m_cmdlist.Count() || cmd != m_cmdlist.Last())) | ||||
| { | { | ||||
| m_cmdlist << cmd; | m_cmdlist << cmd; | ||||
| MessageService::Send(MSG_IN, cmd); | |||||
| MessageService::Send(MessageBucket::AppIn, cmd); | |||||
| } | } | ||||
| } | } | ||||
| #endif //WINDOWS | #endif //WINDOWS | ||||
| @@ -1,3 +1,6 @@ | |||||
| //------------------------------------------------------------------------- | |||||
| // MODULE INIT FUNCTIONS | |||||
| //------------------------------------------------------------------------- | |||||
| function RegisterListener() | function RegisterListener() | ||||
| { | { | ||||
| //Register all the correct functions to the listener | //Register all the correct functions to the listener | ||||