mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
.Developing TURTLE
git-svn-id: svn://ultimatepp.org/upp/trunk@6716 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
492d5c2d11
commit
4048bc884b
3 changed files with 40 additions and 33 deletions
|
|
@ -67,6 +67,7 @@ void Ctrl::InitTelpp()
|
|||
void Ctrl::Reply()
|
||||
{
|
||||
GuiLock __;
|
||||
LLOG("Reply");
|
||||
if(websocket.IsOpen()) {
|
||||
TimerProc(GetTickCount());
|
||||
DefferedFocusSync();
|
||||
|
|
@ -76,32 +77,36 @@ void Ctrl::Reply()
|
|||
DoPaint();
|
||||
// String s = GZCompress(content);
|
||||
String s = content;
|
||||
LLOG("About to send " << s.GetLength());
|
||||
websocket.SendBinary(s);
|
||||
content.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
String event_queue;
|
||||
|
||||
bool Ctrl::IsWaitingEvent()
|
||||
{
|
||||
GuiLock __;
|
||||
Reply();
|
||||
return socket.Timeout(0).Peek() >= 0;
|
||||
if(socket.Timeout(0).WaitRead()) {
|
||||
socket.Timeout(20000);
|
||||
event_queue.Cat(websocket.Recieve());
|
||||
return true; // TODO: Each recieved message needs a reply
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Ctrl::ProcessEvents(bool *quit)
|
||||
{
|
||||
GuiLock __;
|
||||
LLOG("ProcessEvents");
|
||||
if(!IsWaitingEvent())
|
||||
return false;
|
||||
|
||||
TimeStop tm;
|
||||
LLOG("Trying to read socket");
|
||||
String event_queue = websocket.Recieve();
|
||||
LLOG("---- Process events");
|
||||
if(event_queue.GetCount())
|
||||
LOG(event_queue);
|
||||
LLOG(event_queue);
|
||||
content.Clear();
|
||||
bool r = ProcessEventQueue(event_queue);
|
||||
event_queue.Clear();
|
||||
_TODO_ // Resolve eventloop exit issue
|
||||
Reply();
|
||||
return r;
|
||||
|
|
@ -110,11 +115,10 @@ bool Ctrl::ProcessEvents(bool *quit)
|
|||
void Ctrl::GuiSleep(int ms)
|
||||
{
|
||||
GuiLock __;
|
||||
Reply();
|
||||
ASSERT(IsMainThread());
|
||||
// LLOG("GuiSleep");
|
||||
int level = LeaveGuiMutexAll();
|
||||
Sleep(ms); _TODO_
|
||||
socket.Timeout(ms).WaitRead();
|
||||
EnterGuiMutex(level);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ Your browser does not support the HTML5 canvas tag.
|
|||
<script>
|
||||
function Log(msg)
|
||||
{
|
||||
// if (window.console && console.log)
|
||||
// console.log(msg); //for firebug
|
||||
if (window.console && console.log)
|
||||
console.log(msg); //for firebug
|
||||
}
|
||||
|
||||
function Char(p, ch)
|
||||
|
|
@ -73,7 +73,7 @@ function ProcessDraw(s)
|
|||
var ctx = canvas.getContext("2d");
|
||||
|
||||
while(p.pos < p.data.length) {
|
||||
Log(p.pos + ": " + p.data[p.pos]);
|
||||
// Log(p.pos + ": " + p.data[p.pos]);
|
||||
if(Char(p, 0)) {
|
||||
x = Get16(p);
|
||||
y = Get16(p);
|
||||
|
|
@ -82,10 +82,10 @@ function ProcessDraw(s)
|
|||
r = Get8(p);
|
||||
g = Get8(p);
|
||||
b = Get8(p);
|
||||
Log("rect: " + x + ", " + y + ", " + cx + ", " + cy);
|
||||
// Log("rect: " + x + ", " + y + ", " + cx + ", " + cy);
|
||||
var c = "rgb(" + r + "," + g + "," + b + ")";
|
||||
ctx.fillStyle = c;
|
||||
Log("color: " + c);
|
||||
// Log("color: " + c);
|
||||
ctx.fillRect(x, y, cx, cy);
|
||||
}
|
||||
else
|
||||
|
|
@ -94,7 +94,7 @@ function ProcessDraw(s)
|
|||
y = Get16(p);
|
||||
cx = Get16(p);
|
||||
cy = Get16(p);
|
||||
Log("irect: " + x + ", " + y + ", " + cx + ", " + cy);
|
||||
// Log("irect: " + x + ", " + y + ", " + cx + ", " + cy);
|
||||
var imageData = ctx.getImageData(x, y, cx, cy);
|
||||
var data = imageData.data;
|
||||
for(var i = 0; i < data.length; i += 4) {
|
||||
|
|
@ -118,7 +118,7 @@ function ProcessDraw(s)
|
|||
img.height = cy;
|
||||
img.getContext("2d").putImageData(imgData, 0, 0);
|
||||
window.img_cache[r] = img;
|
||||
Log("Set image: " + r);
|
||||
// Log("Set image: " + r);
|
||||
}
|
||||
else
|
||||
if(Char(p, 1)) {
|
||||
|
|
@ -131,7 +131,7 @@ function ProcessDraw(s)
|
|||
cx = Get16(p);
|
||||
cy = Get16(p);
|
||||
|
||||
Log("Draw image: " + n);
|
||||
// Log("Draw image: " + n);
|
||||
ctx.drawImage(window.img_cache[n], x, y, cx, cy, px, py, cx, cy);
|
||||
}
|
||||
else
|
||||
|
|
@ -165,7 +165,7 @@ function ProcessDraw(s)
|
|||
if(Char(p, 6)) {
|
||||
i = Get16(p);
|
||||
canvas.style.cursor = cursor_cache[i];
|
||||
Log(cursor_cache[i]);
|
||||
// Log(cursor_cache[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -257,37 +257,38 @@ ws.binaryType = "arraybuffer";
|
|||
|
||||
function Ping()
|
||||
{
|
||||
Log("Ping " + Processing);
|
||||
if(!Processing) {
|
||||
Processing = true;
|
||||
Log("Sending " + event_queue);
|
||||
ws.send(event_queue);
|
||||
event_queue = "";
|
||||
}
|
||||
if(timerID != undefined)
|
||||
clearTimeout(timerID);
|
||||
timerID = setTimeout(Ping, 20);
|
||||
// Log("Ping");
|
||||
}
|
||||
|
||||
ws.onopen = function() {
|
||||
ws.onopen = function()
|
||||
{
|
||||
ResizeCanvas();
|
||||
};
|
||||
|
||||
ws.onmessage = function(event) {
|
||||
if(event.data instanceof ArrayBuffer) {
|
||||
var a = new Uint8Array(event.data);
|
||||
ProcessDraw(a);
|
||||
}
|
||||
ws.onmessage = function(event)
|
||||
{
|
||||
Log("onmessage");
|
||||
if(event.data instanceof ArrayBuffer)
|
||||
ProcessDraw(new Uint8Array(event.data));
|
||||
Processing = false;
|
||||
if(event_queue.length > 0)
|
||||
Ping();
|
||||
};
|
||||
|
||||
ws.onclose = function(ev) {
|
||||
ws.onclose = function(ev)
|
||||
{
|
||||
alert("Connection closed");
|
||||
};
|
||||
|
||||
ws.onerror = function(ev) {
|
||||
alert("Connection error: " + ev.reason);
|
||||
};
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -298,9 +298,11 @@ struct EventsWnd : TopWindow {
|
|||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
//#ifdef _DEBUG
|
||||
StdLogSetup(LOG_COUT|LOG_FILE);
|
||||
#endif
|
||||
//#endif
|
||||
|
||||
LOG("Test");
|
||||
|
||||
SetLanguage(LNG_ENGLISH);
|
||||
SetDefaultCharset(CHARSET_UTF8);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue