diff --git a/src/messageservice.cpp b/src/messageservice.cpp index b6619045..437d0382 100644 --- a/src/messageservice.cpp +++ b/src/messageservice.cpp @@ -26,12 +26,9 @@ namespace lol #if EMSCRIPTEN 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 - //bool C_FetchFirst(int id, String& message); + //bool C_FetchFirst(String& message); } #endif //EMSCRIPTEN @@ -53,10 +50,10 @@ MessageService::~MessageService() } //Setup/Destroy -void MessageService::Setup(int bucket_size) +void MessageService::Setup() { g_messageservice = new MessageService(); - g_messageservice->m_bucket.Resize(bucket_size); + g_messageservice->m_bucket.Resize(MessageBucket::Max); } 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) { @@ -76,7 +73,7 @@ bool MessageService::Send(int id, const String& message) return false; } -bool MessageService::Send(int id, const char* message) +bool MessageService::Send(MessageBucket id, const char* message) { 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) { @@ -101,7 +98,7 @@ bool MessageService::FetchFirst(int id, String& message) 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) { @@ -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) { @@ -132,7 +129,7 @@ bool MessageService::FetchAll(int id, String& message) 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) { diff --git a/src/messageservice.h b/src/messageservice.h index aa19d97e..28548ea6 100644 --- a/src/messageservice.h +++ b/src/messageservice.h @@ -20,6 +20,35 @@ 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 { MessageList(time_t timestamp, const String& message) @@ -45,16 +74,16 @@ public: static char const *GetName() { return ""; } //Setup/Destroy - static void Setup(int bucket_size); + static void Setup(); static void Destroy(); //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: Array > m_bucket; diff --git a/src/platform/emscripten/lol_shell.html b/src/platform/emscripten/lol_shell.html index e6aabacd..98578851 100644 --- a/src/platform/emscripten/lol_shell.html +++ b/src/platform/emscripten/lol_shell.html @@ -142,7 +142,7 @@ canvas.emscripten Module.setStatus('All downloads complete.', 1, 1); }, //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() { for (var i = 0; i < this.wrapup_list.length; i++) @@ -158,7 +158,7 @@ canvas.emscripten //Module <-> Page communication setup SendMessage:function(message) { - this.DoSendMessage(0, message); + this.DoSendMessage(message); }, ModuleSendMessage:function(message) { diff --git a/src/platform/nacl/nacl-instance.cpp b/src/platform/nacl/nacl-instance.cpp index e8757787..0c54056b 100644 --- a/src/platform/nacl/nacl-instance.cpp +++ b/src/platform/nacl/nacl-instance.cpp @@ -137,7 +137,7 @@ void NaClInstance::HandleMessage(const pp::Var& message) return; /* 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) diff --git a/test/data/mesh-buffer.txt b/test/data/mesh-buffer.txt index 7513af44..b1b6254c 100644 --- a/test/data/mesh-buffer.txt +++ b/test/data/mesh-buffer.txt @@ -1,4 +1,4 @@ -sc#fff ab 2 +sc#fff ab 4 //splt 0 //test diff --git a/test/meshviewer.cpp b/test/meshviewer.cpp index 2555a407..1fa869e4 100644 --- a/test/meshviewer.cpp +++ b/test/meshviewer.cpp @@ -194,7 +194,7 @@ public: #endif //NO_NACL_EM // Message Service - MessageService::Setup(MSG_MAX); + MessageService::Setup(); // Mesh Setup m_render_max = vec2(-.9f, 6.1f); @@ -428,7 +428,7 @@ public: //-- String mesh(""); int u = 4; - while (u-- > 0 && MessageService::FetchFirst(MSG_IN, mesh)) + while (u-- > 0 && MessageService::FetchFirst(MessageBucket::AppIn, mesh)) { int o = 1; while (o-- > 0) @@ -448,10 +448,10 @@ public: if (m_stream_update_time > .0f) { 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 //-- @@ -491,7 +491,7 @@ public: && (!m_cmdlist.Count() || cmd != m_cmdlist.Last())) { m_cmdlist << cmd; - MessageService::Send(MSG_IN, cmd); + MessageService::Send(MessageBucket::AppIn, cmd); } } #endif //WINDOWS diff --git a/test/nacl_loading.js b/test/nacl_loading.js index 2acfb5c0..58056af9 100644 --- a/test/nacl_loading.js +++ b/test/nacl_loading.js @@ -1,3 +1,6 @@ +//------------------------------------------------------------------------- +// MODULE INIT FUNCTIONS +//------------------------------------------------------------------------- function RegisterListener() { //Register all the correct functions to the listener