Skip to content

Commit

Permalink
* NAEV now also prints everything to it's internal console.
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbens committed Oct 9, 2010
1 parent 0e15c1b commit 09c3da4
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 26 deletions.
4 changes: 2 additions & 2 deletions configure.ac
Expand Up @@ -375,8 +375,8 @@ esac

AC_SUBST([LIBLUA_CFLAGS])

# utils/pack
PACK_CFLAGS="$GLOBAL_CFLAGS $SDL_CFLAGS $SDLIMAGE_CFLAGS"

PACK_CFLAGS="$GLOBAL_CFLAGS $SDL_CFLAGS $SDLIMAGE_CFLAGS -DNOLOGPRINTFCONSOLE"
PACK_LIBS="$GLOBAL_LIBS $SDL_LIBS $SDLIMAGE_LIBS"

AC_SUBST([PACK_CFLAGS])
Expand Down
1 change: 1 addition & 0 deletions src/Makefile.am
Expand Up @@ -47,6 +47,7 @@ naev_SOURCES = \
land.c \
land_outfits.c \
land_shipyard.c \
log.c \
map.c \
map_overlay.c \
md5.c \
Expand Down
11 changes: 7 additions & 4 deletions src/console.c
Expand Up @@ -68,7 +68,6 @@ static int cli_firstline = 1; /**< Is this the first line? */
/*
* CLI stuff.
*/
static int cli_print( lua_State *L );
static int cli_script( lua_State *L );
static const luaL_Reg cli_methods[] = {
{ "print", cli_print },
Expand All @@ -82,14 +81,14 @@ static const luaL_Reg cli_methods[] = {
* Prototypes.
*/
static int cli_keyhandler( unsigned int wid, SDLKey key, SDLMod mod );
static void cli_addMessage( const char *msg );
static void cli_render( double bx, double by, double w, double h, void *data );


/**
* @brief Replacement for the internal Lua print to print to console instead of terminal.
*/
static int cli_print( lua_State *L ) {
int cli_print( lua_State *L )
{
int n = lua_gettop(L); /* number of arguments */
int i;
char buf[LINE_LENGTH];
Expand Down Expand Up @@ -159,10 +158,14 @@ static int cli_script( lua_State *L )
*
* @param msg Message to add.
*/
static void cli_addMessage( const char *msg )
void cli_addMessage( const char *msg )
{
int n;

/* Not initialized. */
if (cli_state == NULL)
return;

if (msg != NULL)
strncpy( cli_buffer[cli_cursor], msg, LINE_LENGTH );
else
Expand Down
1 change: 1 addition & 0 deletions src/console.h
Expand Up @@ -17,6 +17,7 @@ void cli_exit (void);
* Misc.
*/
void cli_open (void);
void cli_addMessage( const char *msg );


#endif /* CONSOLE_H */
Expand Down
34 changes: 18 additions & 16 deletions src/font.c
Expand Up @@ -886,22 +886,24 @@ static int gl_fontRenderCharacter( const glFont* font, int ch, const glColour *c
return 0;
}

/*
* Global Local
* 0--1 0--1 4
* | /| => | / /|
* |/ | |/ / |
* 3--2 2 3--5
*/
ind[0] = 4*ch + 0;
ind[1] = 4*ch + 1;
ind[2] = 4*ch + 3;
ind[3] = 4*ch + 1;
ind[4] = 4*ch + 3;
ind[5] = 4*ch + 2;

/* Draw the element. */
glDrawElements( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, ind );
if (!isspace(ch)) {
/*
* Global Local
* 0--1 0--1 4
* | /| => | / /|
* |/ | |/ / |
* 3--2 2 3--5
*/
ind[0] = 4*ch + 0;
ind[1] = 4*ch + 1;
ind[2] = 4*ch + 3;
ind[3] = 4*ch + 1;
ind[4] = 4*ch + 3;
ind[5] = 4*ch + 2;

/* Draw the element. */
glDrawElements( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, ind );
}

/* Translate matrix. */
gl_matrixTranslate( font->chars[ch].adv_x, font->chars[ch].adv_y );
Expand Down
17 changes: 13 additions & 4 deletions src/log.h
Expand Up @@ -8,16 +8,18 @@
#ifndef LOG_H
# define LOG_H


#include <stdio.h>
#include <signal.h>

#define LOG(str, args...) (fprintf(stdout,str"\n", ## args))

#define LOG(str, args...) (logprintf(stdout,str"\n", ## args))
#ifdef DEBUG_PARANOID /* Will cause WARNs to blow up */
#define WARN(str, args...) (fprintf(stderr,"Warning: [%s] "str"\n", __func__, ## args), abort())
#define WARN(str, args...) (logprintf(stderr,"Warning: [%s] "str"\n", __func__, ## args), abort())
#else /* DEBUG_PARANOID */
#define WARN(str, args...) (fprintf(stderr,"Warning: [%s] "str"\n", __func__, ## args))
#define WARN(str, args...) (logprintf(stderr,"Warning: [%s] "str"\n", __func__, ## args))
#endif /* DEBUG_PARANOID */
#define ERR(str, args...) (fprintf(stderr,"ERROR %s:%d [%s]: "str"\n", __FILE__, __LINE__, __func__, ## args), abort())
#define ERR(str, args...) (logprintf(stderr,"ERROR %s:%d [%s]: "str"\n", __FILE__, __LINE__, __func__, ## args), abort())
#ifdef DEBUG
# undef DEBUG
# define DEBUG(str, args...) LOG(str, ## args)
Expand All @@ -29,4 +31,11 @@
#endif /* DEBUG */


#ifdef NOLOGPRINTFCONSOLE
#define logprintf fprintf
#else /* NOLOGPRINTFCONSOLE */
int logprintf( FILE *stream, const char *fmt, ... );
#endif /* NOLOGPRINTFCONSOLE */


#endif /* LOG_H */
1 change: 1 addition & 0 deletions src/naev.c
Expand Up @@ -288,6 +288,7 @@ int main( int argc, char** argv )
toolkit_init(); /* initializes the toolkit */
map_init(); /* initializes the map. */
cond_init(); /* Initialize conditional subsystem. */
cli_init(); /* Initialize console. */

/* Data loading */
load_all();
Expand Down
4 changes: 4 additions & 0 deletions src/nlua.c
Expand Up @@ -27,6 +27,7 @@
#include "nlua_pilot.h"
#include "nlua_vec2.h"
#include "nlua_diff.h"
#include "nlua_cli.h"


/*
Expand Down Expand Up @@ -105,6 +106,9 @@ int nlua_loadBasic( lua_State* L )
lua_setglobal(L, override[i]);
}

/* Override print to print in the console. */
lua_register(L, "print", cli_print);

nlua_load(L,luaopen_math); /* open math. */
nlua_load(L,luaopen_table); /* open table. */
nlua_load(L, luaopen_string); /* open string. */
Expand Down
2 changes: 2 additions & 0 deletions src/nlua_cli.h
Expand Up @@ -11,6 +11,8 @@


int nlua_loadCLI( lua_State *L ); /* always write only */
int cli_print( lua_State *L );
int nlua_regPrint( lua_State *L );


#endif /* NLUA_CLI_H */
Expand Down

0 comments on commit 09c3da4

Please sign in to comment.