Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental SDL Console #5027

Draft
wants to merge 25 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8bb0241
Initial
dhthwy Nov 15, 2024
9941d07
Initial
dhthwy Nov 15, 2024
9537846
sdlconsole: trying to compile
dhthwy Nov 15, 2024
2e9432b
sdlconsole: fix compile
dhthwy Nov 15, 2024
48993df
sdlconsole: fix inconsistent use of class vs struct
dhthwy Nov 15, 2024
5024de4
sdlconsole: use DFSDL to resolve symbols
dhthwy Nov 16, 2024
63ac52b
Merge branch 'develop' into sdl_console
dhthwy Nov 16, 2024
60e5739
sdlconsole: fix msleep
dhthwy Nov 16, 2024
1f14688
sdlconsole: some cleaning
dhthwy Nov 16, 2024
16f2bde
sdlconsole: support two click select word, three click select line mo…
dhthwy Nov 16, 2024
29a0550
cleanup some scrollbar, and fix nassy bug in SignalEmitter disconnect()
dhthwy Nov 18, 2024
433879e
sdlconsole: some housekeeping. some performance tweaks.
dhthwy Nov 18, 2024
42a4da1
Merge branch 'develop' into sdl_console
dhthwy Nov 18, 2024
58d95ab
sdlconsole: inform SDL to pass mouse clicks when gaining window focus
dhthwy Nov 19, 2024
06363e2
sdlconsole: safer text processing. add more comments. make ctrl-C int…
dhthwy Nov 19, 2024
b5015b5
sdlconsole: support load from saved command history
dhthwy Nov 19, 2024
b7fe35b
sdlconsole: cleanup text_selection and some other bits
dhthwy Nov 20, 2024
b44a35a
sdlconsole: fix disabled cursor on focus gain. plus tweaks to prompt.
dhthwy Nov 20, 2024
8ddaa80
sdlconsole: attempt to fix glyph rendering
dhthwy Nov 20, 2024
6f43361
sdlconsole: test remove fringe pixel artifacts from font. By creating…
dhthwy Nov 21, 2024
2648864
more housekeeping
dhthwy Nov 23, 2024
81eaeb9
sdlconsole: refactoring
dhthwy Nov 27, 2024
8a53e3c
try to fix tests
dhthwy Nov 27, 2024
293d203
Merge branch 'develop' into sdl_console
dhthwy Nov 27, 2024
2d35963
sdlconsole: Console overhaul. Hacks.
dhthwy Nov 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ endif(CMAKE_CONFIGURATION_TYPES)
option(BUILD_DOCS "Choose whether to build the documentation (requires python and Sphinx)." OFF)
option(BUILD_DOCS_NO_HTML "Don't build the HTML docs, only the in-game docs." OFF)
option(REMOVE_SYMBOLS_FROM_DF_STUBS "Remove debug symbols from DF stubs. (Reduces libdfhack size to about half but removes a few useful symbols)" ON)
option(DFHACK_SDL_CONSOLE "Use experimental SDL console" ON)

macro(CHECK_GCC compiler_path)
execute_process(COMMAND ${compiler_path} -dumpversion OUTPUT_VARIABLE GCC_VERSION_OUT)
Expand Down
24 changes: 20 additions & 4 deletions library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ if(UNIX)
option(CONSOLE_NO_CATCH "Make the console not catch 'CTRL+C' events for easier debugging." OFF)
endif()

option(DFHACK_SDL_CONSOLE "Use experimental SDL console" ON)

# Generation
set(CODEGEN_OUT ${dfapi_SOURCE_DIR}/include/df/codegen.out.xml)

Expand Down Expand Up @@ -117,12 +119,24 @@ set(MAIN_SOURCES
file(GLOB_RECURSE TEST_SOURCES
LIST_DIRECTORIES false
*test.cpp)
list(APPEND TEST_SOURCES Console-posix.cpp SDLConsole_impl.cpp)
dfhack_test(dfhack-test "${TEST_SOURCES}")

if(WIN32)
set(CONSOLE_SOURCES Console-windows.cpp)
if (NOT DFHACK_SDL_CONSOLE)
if(WIN32)
set(CONSOLE_SOURCES Console-windows.cpp)
else()
set(CONSOLE_SOURCES Console-posix.cpp)
endif()
set(DFCLIENT_CONSOLE_SOURCES ${CONSOLE_SOURCES})
else()
set(CONSOLE_SOURCES Console-posix.cpp)
if(WIN32)
set(DFCLIENT_CONSOLE_SOURCES Console-windows.cpp)
else()
set(DFCLIENT_CONSOLE_SOURCES Console-posix.cpp)
endif()
set(CONSOLE_SOURCES ${DFCLIENT_CONSOLE_SOURCES})
list(APPEND CONSOLE_SOURCES Console-sdl.cpp SDLConsole_impl.cpp)
endif()

set(MAIN_SOURCES_WINDOWS
Expand Down Expand Up @@ -372,7 +386,9 @@ add_library(dfhack SHARED ${PROJECT_SOURCES})
add_dependencies(dfhack generate_proto_core)
add_dependencies(dfhack generate_headers)

add_library(dfhack-client SHARED RemoteClient.cpp ColorText.cpp MiscUtils.cpp Error.cpp ${PROJECT_PROTO_SRCS} ${CONSOLE_SOURCES})
add_library(dfhack-client SHARED RemoteClient.cpp ColorText.cpp MiscUtils.cpp Error.cpp ${PROJECT_PROTO_SRCS} ${DFCLIENT_CONSOLE_SOURCES})
# SDLConsole requires to be run with df
target_compile_definitions(dfhack-client PUBLIC DISABLE_SDL_CONSOLE)
add_dependencies(dfhack-client dfhack)

add_executable(dfhack-run dfhack-run.cpp)
Expand Down
43 changes: 24 additions & 19 deletions library/Console-posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
_res; })
#endif

#include "Console.h"
#include "PosixConsole.h"
#include "Hooks.h"
using namespace DFHack;

Expand Down Expand Up @@ -833,14 +833,14 @@ namespace DFHack
};
}

Console::Console()
PosixConsole::PosixConsole()
{
d = 0;
d = nullptr;
inited = false;
// we can't create the mutex at this time. the SDL functions aren't hooked yet.
wlock = new std::recursive_mutex();
}
Console::~Console()
PosixConsole::~PosixConsole()
{
assert(!inited);
if(wlock)
Expand All @@ -849,7 +849,7 @@ Console::~Console()
delete d;
}

bool Console::init(bool dont_redirect)
bool PosixConsole::init(bool dont_redirect)
{
d = new Private();
// make our own weird streams so our IO isn't redirected
Expand Down Expand Up @@ -882,7 +882,12 @@ bool Console::init(bool dont_redirect)
return true;
}

bool Console::shutdown(void)
bool PosixConsole::is_supported()
{
return !isUnsupportedTerm() && isatty(STDIN_FILENO);
}

bool PosixConsole::shutdown(void)
{
if(!d)
return true;
Expand All @@ -894,7 +899,7 @@ bool Console::shutdown(void)
return true;
}

void Console::begin_batch()
void PosixConsole::begin_batch()
{
//color_ostream::begin_batch();

Expand All @@ -904,22 +909,22 @@ void Console::begin_batch()
d->begin_batch();
}

void Console::end_batch()
void PosixConsole::end_batch()
{
if (inited)
d->end_batch();

wlock->unlock();
}

void Console::flush_proxy()
void PosixConsole::flush_proxy()
{
std::lock_guard<std::recursive_mutex> lock{*wlock};
if (inited)
d->flush();
}

void Console::add_text(color_value color, const std::string &text)
void PosixConsole::add_text(color_value color, const std::string &text)
{
std::lock_guard<std::recursive_mutex> lock{*wlock};
if (inited)
Expand All @@ -928,7 +933,7 @@ void Console::add_text(color_value color, const std::string &text)
fwrite(text.data(), 1, text.size(), stderr);
}

int Console::get_columns(void)
int PosixConsole::get_columns(void)
{
std::lock_guard<std::recursive_mutex> lock{*wlock};
int ret = Console::FAILURE;
Expand All @@ -937,7 +942,7 @@ int Console::get_columns(void)
return ret;
}

int Console::get_rows(void)
int PosixConsole::get_rows(void)
{
std::lock_guard<std::recursive_mutex> lock{*wlock};
int ret = Console::FAILURE;
Expand All @@ -946,28 +951,28 @@ int Console::get_rows(void)
return ret;
}

void Console::clear()
void PosixConsole::clear()
{
std::lock_guard<std::recursive_mutex> lock{*wlock};
if(inited)
d->clear();
}

void Console::gotoxy(int x, int y)
void PosixConsole::gotoxy(int x, int y)
{
std::lock_guard<std::recursive_mutex> lock{*wlock};
if(inited)
d->gotoxy(x,y);
}

void Console::cursor(bool enable)
void PosixConsole::cursor(bool enable)
{
std::lock_guard<std::recursive_mutex> lock{*wlock};
if(inited)
d->cursor(enable);
}

int Console::lineedit(const std::string & prompt, std::string & output, CommandHistory & ch)
int PosixConsole::lineedit(const std::string & prompt, std::string & output, CommandHistory & ch)
{
std::lock_guard<std::recursive_mutex> lock{*wlock};
int ret = Console::SHUTDOWN;
Expand All @@ -984,19 +989,19 @@ int Console::lineedit(const std::string & prompt, std::string & output, CommandH
return ret;
}

void Console::msleep (unsigned int msec)
void PosixConsole::msleep (unsigned int msec)
{
if (msec > 1000) sleep(msec/1000000);
usleep((msec % 1000000) * 1000);
}

bool Console::hide()
bool PosixConsole::hide()
{
//Warmist: don't know if it's possible...
return false;
}

bool Console::show()
bool PosixConsole::show()
{
//Warmist: don't know if it's possible...
return false;
Expand Down
Loading