diff options
author | pk33 <pk33@pk33.space> | 2024-11-04 21:42:06 +0100 |
---|---|---|
committer | pk33 <pk33@pk33.space> | 2024-11-04 21:42:06 +0100 |
commit | 146a683b8d8315ef15dc1c9286f0983834f48d88 (patch) | |
tree | 44124fbaf1d49c25de8422ed29c7bade0bc11963 | |
parent | 0ffb4f8463e3e06e8d88b7be22f5cb7adb702361 (diff) | |
download | engine33-146a683b8d8315ef15dc1c9286f0983834f48d88.tar.gz |
-rw-r--r-- | README.html | 6 | ||||
-rw-r--r-- | src/font33.c | 5 | ||||
-rw-r--r-- | src/logger.c | 27 | ||||
-rw-r--r-- | src/main.c | 2 | ||||
-rw-r--r-- | src/strings33.c | 19 | ||||
-rw-r--r-- | src/ui33.c | 2 |
6 files changed, 46 insertions, 15 deletions
diff --git a/README.html b/README.html index cdb5234..d5f93c6 100644 --- a/README.html +++ b/README.html @@ -1,5 +1,5 @@ <h2>engine33</h2> -<p>WIP 3D game engine for linux in C.</p> +<p>WIP 3D game engine for Linux in C.</p> <hr><hr> <br><br><br> @@ -19,8 +19,8 @@ Run ./bin/engine33 on a TTY.<br> <h3>TODO</h3> <hr> <ol> -<li>labeled and coloured on-screen messages</li> -<li>*draw some graphics</li> +<li>tidying up and abiding by naming conventions</li> +<li>*Input</li> </ol> <br><br> diff --git a/src/font33.c b/src/font33.c index 43e2145..d40700a 100644 --- a/src/font33.c +++ b/src/font33.c @@ -13,7 +13,7 @@ Font33 bigFont = { /* h, ngly, mwid */ Font33 defFont = { - 4, 0x0F, 16, 96, 13, + 4, 0x0F, 16, 95, 13, { /* */{ 0, 3, {0} }, /* ! */{ 9, 3, {0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1B,0x1C} }, @@ -109,8 +109,7 @@ Font33 defFont = { /* { */{ 13, 5, {0x32,0x42,0x23,0x24,0x25,0x16,0x07,0x18,0x29,0x2A,0x2B,0x3C,0x4C} }, /* | */{ 12, 3, {0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B} }, /* } */{ 13, 5, {0x02,0x12,0x23,0x24,0x25,0x36,0x47,0x38,0x29,0x2A,0x2B,0x0C,0x1C} }, - /* ~ */{ 9, 11, {0x17,0x26,0x35,0x45,0x55,0x66,0x77,0x87,0x96} }, - /* :) */{ 0, 0, {0} } + /* ~ */{ 9, 11, {0x17,0x26,0x35,0x45,0x55,0x66,0x77,0x87,0x96} } } }; diff --git a/src/logger.c b/src/logger.c index d6bf3f9..c90f364 100644 --- a/src/logger.c +++ b/src/logger.c @@ -15,7 +15,7 @@ Logger __logger; -static char *colours[5] = { +static char *ansiColourPrefix[5] = { "[\x1b[36mD\x1b[37m]", "[\x1b[32mI\x1b[37m]", "[\x1b[35mW\x1b[37m]", @@ -23,6 +23,14 @@ static char *colours[5] = { "[\x1b[31mFl\x1b[37m]", }; +static char uiColourPrefix[5][11] = { + { 6, '[', 'D', 'e', 'b', 'u', 'g', ']', ' ', 1, '\0' }, + { 3, '[', 'I', 'n', 'f', 'o', ']', ' ', 1, '\0', ' ' }, + { 5, '[', 'W', 'a', 'r', 'n', ']', ' ', 1, '\0', ' ' }, + { 8, '[', 'E', 'r', 'r', 'o', 'r', ']', ' ', 1, '\0' }, + { 2, '[', 'F', 'a', 't', 'a', 'l', ']', ' ', 1, '\0' } +}; + Size logger_init( void ) { String logfile[512]; @@ -58,6 +66,8 @@ void logger_term( void ) void logger( Size level, const char *fmt, ... ) { + static char uiString[256]; + time_t currentTime; struct tm *m_time; @@ -68,23 +78,26 @@ void logger( Size level, const char *fmt, ... ) time(¤tTime); m_time = localtime(¤tTime); - - ui_add_message( fmt, args ); /* XXX */ - + snprintf( uiString, 256, "%s%s", uiColourPrefix[level], fmt ); dprintf( __logger.fd, "Engine33 [%02d:%02d:%02d] -", m_time->tm_hour, m_time->tm_min, m_time->tm_sec ); - dprintf( __logger.fd, " %s ", colours[level] ); + dprintf( __logger.fd, " %s ", ansiColourPrefix[level] ); vdprintf(__logger.fd, fmt, args); - if( (level > LOG_INFO) && errno ) { - dprintf( __logger.fd, ". Reason: %s", strerror(errno) ); + if( (level > LOG_INFO) && errno ) + { + String strerr = strerror(errno); + dprintf( __logger.fd, ". Reason: %s", strerr ); + snprintf( uiString, 256, "%s >> %s", uiString, strerr ); errno = 0; } dprintf( __logger.fd, ".\r\n" ); + ui_add_message( uiString, args ); + va_end(args); } @@ -31,6 +31,8 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } + logd( "This is a test." ); + while(1) { display_vtswitcher_poll(1); diff --git a/src/strings33.c b/src/strings33.c index 0bb7ea0..8613c02 100644 --- a/src/strings33.c +++ b/src/strings33.c @@ -14,6 +14,18 @@ static Font33 *fonts[2] = { }; +static u32 textColours[9] = { + 0xff000000, + 0xffffffff, + 0xffff0000, + 0xff00ff00, + 0xff0000ff, + 0xffffff00, + 0xff00ffff, + 0xffff00ff, + 0xffffaa00, +}; + void e33_uprintf( Surface *surf, Size f, u32 col, Size x, Size y, const char *fmt, ... ) { @@ -43,6 +55,7 @@ void e33_uprint( Surface *surf, Size f, u32 col, Size x, Size y, const char *str Size strWid = 0; for( i = 0; i < slen; ++i ) { + if( str[i] < 0x20 ) continue; strWid += glyphs[ str[i] - 0x20 ].width; } @@ -59,6 +72,12 @@ void e33_uprint( Surface *surf, Size f, u32 col, Size x, Size y, const char *str for( i = 0, ofs = 0; i < slen; ++i ) { + if( str[i] < 0x20 ) + { + col = textColours[str[i]]; + continue; + } + FontGlyph33 *glyph = &glyphs[ str[i] - 0x20 ]; Size numPlots = glyph->num_plots; Size gWidth = glyph->width; @@ -33,8 +33,6 @@ void ui_draw_messages( void ) Size start = __display.surface.h - 5 - 8; Size i = P-1; - qsuprintf( 300, 40, "A(%d), P(%d)", A, P ); - do { if( i < 0 ) i = MB_MAX-1; qsuprint( messageBox[i], 5, start ); |