Branimir Karadžić 9 лет назад
Родитель
Сommit
8541d8d16b

+ 2 - 2
3rdparty/remotery/readme.md

@@ -54,14 +54,14 @@ See the sample directory for further examples. A quick example:
 
         // Explicit begin/end for C
         {
-            rmt_BeginCPUSample(LogText);
+            rmt_BeginCPUSample(LogText, 0);
             rmt_LogText("Time me, please!");
             rmt_EndCPUSample();
         }
 
         // Scoped begin/end for C++
         {
-            rmt_ScopedCPUSample(LogText);
+            rmt_ScopedCPUSample(LogText, 0);
             rmt_LogText("Time me, too!");
         }
 

+ 15 - 3
3rdparty/remotery/sample/sample.c

@@ -1,12 +1,14 @@
 #include <stdlib.h>
 #include <math.h>
+#include <signal.h>
+#include <stdio.h>
 #include "Remotery.h"
 
 double delay() {
     int i, end;
     double j = 0;
 
-    rmt_BeginCPUSample(delay);
+    rmt_BeginCPUSample(delay, 0);
     for( i = 0, end = rand()/100; i < end; ++i ) {
         j += sin(i);
     }
@@ -14,20 +16,30 @@ double delay() {
     return j;
 }
 
+int sig = 0;
+
+/// Allow to close cleanly with ctrl + c
+void sigintHandler(int sig_num) {
+    sig = sig_num;
+    printf("Interrupted\n");
+}
+
+int main( ) {
+    signal(SIGINT, sigintHandler);
 
-int main( int argc, const char **argv ) {
     Remotery *rmt;
 
     if( RMT_ERROR_NONE != rmt_CreateGlobalInstance(&rmt) ) {
         return -1;
     }
 
-    for(;;) {
+    while (sig == 0) {
         rmt_LogText("start profiling");
         delay();
         rmt_LogText("end profiling");
     }
 
     rmt_DestroyGlobalInstance(rmt);
+    printf("Cleaned up and quit\n");
     return 0;
 }

+ 82 - 7
3rdparty/remotery/vis/Code/Console.js

@@ -19,7 +19,16 @@ Console = (function()
 
 		// This accumulates log text as fast as is required
 		this.PageTextBuffer = "";
+		this.LastPageTextBufferLen = 0;
 		this.AppTextBuffer = "";
+		this.LastAppTextBufferLen = 0;
+
+		// Setup command history control
+		this.CommandHistory = LocalStore.Get("App", "Global", "CommandHistory", [ ]);
+		this.CommandIndex = 0;
+		this.MaxNbCommands = 200;
+		DOM.Event.AddHandler(this.UserInput.EditNode, "keydown", Bind(OnKeyPress, this));
+		DOM.Event.AddHandler(this.UserInput.EditNode, "focus", Bind(OnFocus, this));
 
 		// At a much lower frequency this will update the console window
 		window.setInterval(Bind(UpdateHTML, this), 500);
@@ -91,13 +100,21 @@ Console = (function()
 	{
 		// Reset the current text buffer as html
 
-		var page_node = self.PageContainer.Node;
-		page_node.innerHTML = self.PageTextBuffer;
-		page_node.scrollTop = page_node.scrollHeight;
-
-		var app_node = self.AppContainer.Node;
-		app_node.innerHTML = self.AppTextBuffer;
-		app_node.scrollTop = app_node.scrollHeight;
+		if (self.LastPageTextBufferLen != self.PageTextBuffer.length)
+		{
+			var page_node = self.PageContainer.Node;
+			page_node.innerHTML = self.PageTextBuffer;
+			page_node.scrollTop = page_node.scrollHeight;
+			self.LastPageTextBufferLen = self.PageTextBuffer.length;
+		}
+
+		if (self.LastAppTextBufferLen != self.AppTextBuffer.length)
+		{		
+			var app_node = self.AppContainer.Node;
+			app_node.innerHTML = self.AppTextBuffer;
+			app_node.scrollTop = app_node.scrollHeight;
+			self.LastAppTextBufferLen = self.AppTextBuffer.length;
+		}
 	}
 
 
@@ -110,6 +127,64 @@ Console = (function()
 		// Emit to console and clear
 		self.Log("> " + msg);
 		self.UserInput.SetValue("");
+
+		// Keep track of recently issued commands, with an upper bound
+		self.CommandHistory.push(msg);
+		var extra_commands = self.CommandHistory.length - self.MaxNbCommands;
+		if (extra_commands > 0)
+			self.CommandHistory.splice(0, extra_commands);
+
+		// Set command history index to the most recent command
+		self.CommandIndex = self.CommandHistory.length;
+
+		// Backup to local store
+		LocalStore.Set("App", "Global", "CommandHistory", self.CommandHistory);
+
+		// Keep focus with the edit box
+		return true;
+	}
+
+
+	function OnKeyPress(self, evt)
+	{
+		evt = DOM.Event.Get(evt);
+
+		if (evt.keyCode == Keyboard.Codes.UP)
+		{
+			if (self.CommandHistory.length > 0)
+			{
+				// Cycle backwards through the command history
+				self.CommandIndex--;
+				if (self.CommandIndex < 0)
+					self.CommandIndex = self.CommandHistory.length - 1;
+				var command = self.CommandHistory[self.CommandIndex];
+				self.UserInput.SetValue(command);
+			}
+
+			// Stops default behaviour of moving cursor to the beginning
+			DOM.Event.StopDefaultAction(evt);
+		}
+
+		else if (evt.keyCode == Keyboard.Codes.DOWN)
+		{
+			if (self.CommandHistory.length > 0)
+			{
+				// Cycle fowards through the command history
+				self.CommandIndex = (self.CommandIndex + 1) % self.CommandHistory.length;
+				var command = self.CommandHistory[self.CommandIndex];
+				self.UserInput.SetValue(command);
+			}
+
+			// Stops default behaviour of moving cursor to the end
+			DOM.Event.StopDefaultAction(evt);
+		}
+	}
+
+
+	function OnFocus(self)
+	{
+		// Reset command index on focus
+		self.CommandIndex = self.CommandHistory.length;
 	}
 
 

+ 3 - 0
3rdparty/remotery/vis/Code/Remotery.js

@@ -92,6 +92,9 @@ Remotery = (function()
 		// Update and disconnect, relying on auto-connect to reconnect
 		self.ConnectionAddress = node.value;
 		self.Server.Disconnect();
+
+		// Give input focus away
+		return false;
 	}
 
 

+ 1 - 0
3rdparty/remotery/vis/Styles/Remotery.css

@@ -67,6 +67,7 @@ body
     color: #BBB;
     font: 9px Verdana;
     margin: 2px;
+    white-space: pre;
 }
 
 

+ 13 - 11
3rdparty/remotery/vis/extern/BrowserLib/WindowManager/Code/EditBox.js

@@ -27,11 +27,12 @@ WM.EditBox = (function()
 		this.SetPosition(x, y);
 		this.SetSize(w, h);
 
+		this.PreviousValue = "";
+
 		// Hook up the event handlers
 		DOM.Event.AddHandler(this.EditNode, "focus", Bind(OnFocus, this));
 		DOM.Event.AddHandler(this.EditNode, "keypress", Bind(OnKeyPress, this));
 		DOM.Event.AddHandler(this.EditNode, "keydown", Bind(OnKeyDown, this));
-		DOM.Event.AddHandler(this.EditNode, "change", Bind(OnChange, this));
 	}
 
 
@@ -88,9 +89,12 @@ WM.EditBox = (function()
 	function OnKeyPress(self, evt)
 	{
 		// Allow enter to confirm the text only when there's data
-		if (evt.keyCode == 13 && self.EditNode.value != "")
+		if (evt.keyCode == 13 && self.EditNode.value != "" && self.ChangeHandler)
 		{
-			self.EditNode.blur();
+			var focus = self.ChangeHandler(self.EditNode);
+			if (!focus)
+				self.EditNode.blur();
+			self.PreviousValue = "";
 		}
 	}
 
@@ -100,18 +104,16 @@ WM.EditBox = (function()
 		// Allow escape to cancel any text changes
 		if (evt.keyCode == 27)
 		{
-			self.EditNode.value = self.PreviousValue;
+			// On initial edit of the input, escape should NOT replace with the empty string
+			if (self.PreviousValue != "")
+			{
+				self.EditNode.value = self.PreviousValue;
+			}
+
 			self.EditNode.blur();
 		}
 	}
 
 
-	function OnChange(self, evt)
-	{
-		if (self.ChangeHandler)
-			self.ChangeHandler(self.EditNode);
-	}
-
-
 	return EditBox;
 })();

+ 1 - 0
3rdparty/remotery/vis/index.html

@@ -17,6 +17,7 @@
 		<script type="text/javascript" src="extern/BrowserLib/Core/Code/Convert.js"></script>
 		<script type="text/javascript" src="extern/BrowserLib/Core/Code/LocalStore.js"></script>
 		<script type="text/javascript" src="extern/BrowserLib/Core/Code/Mouse.js"></script>
+		<script type="text/javascript" src="extern/BrowserLib/Core/Code/Keyboard.js"></script>
 
 		<!-- User Interface Window Manager -->
 		<script type="text/javascript" src="extern/BrowserLib/WindowManager/Code/WindowManager.js"></script>