From 1b2cf61587599bae81170f798c18232b02e51ac2 Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Wed, 20 Apr 2016 22:29:24 +0300 Subject: [PATCH] you can type commands in console now --- render.d | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++------ xmain_d2d.d | 7 +++++- 2 files changed, 78 insertions(+), 8 deletions(-) diff --git a/render.d b/render.d index 70548cf..647e546 100644 --- a/render.d +++ b/render.d @@ -85,6 +85,7 @@ public @property bool inEditMode () nothrow @trusted @nogc { import core.atomic; @property void inEditMode (bool v) nothrow @trusted @nogc { import core.atomic; atomicStore(editMode, v); } public @property bool quitRequested () nothrow @trusted @nogc { import core.atomic; return atomicLoad(vquitRequested); } +public @property bool conVisible () nothrow @trusted @nogc { return rConsoleVisible; } // ////////////////////////////////////////////////////////////////////////// // @@ -94,6 +95,9 @@ private import core.sync.mutex : Mutex; __gshared Mutex concmdbufLock; shared static this () { concmdbuf.length = 65536; concmdbufLock = new Mutex(); } +__gshared char[4096] concli = 0; +__gshared uint conclilen = 0; + void concmdAdd (const(char)[] s) { if (s.length) { @@ -129,6 +133,29 @@ void concmdDoAll () { } +void concliChar (char ch) { + concmdbufLock.lock(); + scope(exit) concmdbufLock.unlock(); + conLastChange = 0; + if (ch == 8) { + if (conclilen > 0) { conLastChange = 0; --conclilen; } + return; + } + if (ch == 13) { + if (conclilen > 0) { + conLastChange = 0; + concmdAdd(concli[0..conclilen]); + conclilen = 0; + } + return; + } + if (ch < ' ' || ch > 127) return; + if (conclilen >= concli.length) return; + concli.ptr[conclilen++] = ch; + conLastChange = 0; +} + + // ////////////////////////////////////////////////////////////////////////// // shared static this () { conRegVar!doLighting("r_lighting", "dynamic lighting"); @@ -281,12 +308,15 @@ public void initOpenGL () { // ////////////////////////////////////////////////////////////////////////// // +__gshared ulong conLastChange = 0; + void renderConsoleFBO () { enum XOfs = 2; - __gshared ulong lastChange = 0; - if (lastChange == cbufLastChange) return; + if (conLastChange == cbufLastChange) return; + concmdbufLock.lock(); + scope(exit) concmdbufLock.unlock(); // rerender console - lastChange = cbufLastChange; + conLastChange = cbufLastChange; //foreach (auto s; conbufLinesRev) stdout.writeln(s, "|"); fboConsole.exec((FBO me) { bindTexture(0); @@ -305,11 +335,32 @@ void renderConsoleFBO () { // draw sigil glColor4f(1.0f, 1.0f, 1.0f, 0.2f); drawAtXY(texSigil, (me.width-texSigil.width)/2, (vlHeight-rConsoleHeight)/2+(me.height-texSigil.height)/2); - // draw text - glColor4f(0.0f, 1.0f, 0.0f, 1.0f); + // draw command line int y = me.height-conCharHeight-2; - //glPushAttrib(GL_LIST_BIT/*|GL_TEXTURE_BIT*/); - //scope(exit) glPopAttrib(); + { + glPushMatrix(); + scope(exit) glPopMatrix(); + glTranslatef(XOfs, y, 0); + int w = conCharWidth('>'); + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + conDrawChar('>'); + uint spos = conclilen; + while (spos > 0) { + char ch = concli.ptr[spos-1]; + if (w+conCharWidth(ch) > me.width-XOfs*2-12) break; + w += conCharWidth(ch); + --spos; + } + glColor4f(1.0f, 1.0f, 0.0f, 1.0f); + foreach (char ch; concli[spos..conclilen]) conDrawChar(ch); + // cursor + bindTexture(0); + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + glRectf(0, 0, 12, 16); + y -= conCharHeight; + } + // draw console text + glColor4f(0.0f, 1.0f, 0.0f, 1.0f); glPushMatrix(); scope(exit) glPopMatrix(); glTranslatef(XOfs, y, 0); @@ -1244,6 +1295,7 @@ public void renderThread (Tid starterTid) { }, (TMsgMouseEvent msg) { editorMouseEvent(msg); }, (TMsgKeyEvent msg) { editorKeyEvent(msg); }, + (TMsgChar msg) { concliChar(msg.ch); }, (Variant v) { conwriteln("WARNING: unknown thread message received and ignored"); }, @@ -1536,6 +1588,19 @@ public void postAddMessage (const(char)[] msgtext, int pauseMsecs=3000, bool nor // ////////////////////////////////////////////////////////////////////////// // +struct TMsgChar { + char ch; +} + +public void postChar (char ch) { + if (!atomicLoad(renderThreadStarted)) return; + TMsgChar msg; + msg.ch = ch; + send(renderTid, msg); +} + + +// ////////////////////////////////////////////////////////////////////////// // public void concmd (const(char)[] cmd) { //if (!atomicLoad(renderThreadStarted)) return; concmdbufLock.lock(); diff --git a/xmain_d2d.d b/xmain_d2d.d index 8ded848..d765a19 100644 --- a/xmain_d2d.d +++ b/xmain_d2d.d @@ -275,7 +275,7 @@ void main (string[] args) { case Key.Alt: plrKeyUpDown(0, PLK_JUMP, event.pressed); break; case Key.Ctrl: plrKeyUpDown(0, PLK_FIRE, event.pressed); break; case Key.Shift: plrKeyUpDown(0, PLK_USE, event.pressed); break; - case Key.Grave: if (event.pressed) concmd("r_console toggle"); break; + //case Key.Grave: if (event.pressed) concmd("r_console toggle"); break; default: } } @@ -291,6 +291,11 @@ void main (string[] args) { if (!testLightLocked) postTestLightMove(event.x, event.y); }, delegate (dchar ch) { + if (ch == '`') { concmd("r_console toggle"); return; } + if (conVisible) { + if (ch == 13 || ch == 8 || ch == 9 || (ch >= 32 && ch < 128)) postChar(cast(char)ch); + return; + } if (inEditMode) return; if (ch == 'q') concmd("quit"); //{ closeWindow(); return; } //if (ch == 's') scanlines = !scanlines; -- 2.11.4.GIT