dungeon_crawler

diff prototype/src/main.cc @ 24:e122ba214ee1

implementing the command console
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 23 Aug 2012 18:03:11 +0300
parents fa8f89d06f6f
children 527fede30057
line diff
     1.1 --- a/prototype/src/main.cc	Thu Aug 23 00:10:10 2012 +0300
     1.2 +++ b/prototype/src/main.cc	Thu Aug 23 18:03:11 2012 +0300
     1.3 @@ -8,6 +8,7 @@
     1.4  #include "datapath.h"
     1.5  #include "tileset.h"
     1.6  #include "renderer.h"
     1.7 +#include "cmdcon.h"
     1.8  #include "cfg.h"
     1.9  
    1.10  bool init(int xsz, int ysz);
    1.11 @@ -21,6 +22,7 @@
    1.12  void reshape(int x, int y);
    1.13  void keyb(unsigned char key, int x, int y);
    1.14  void key_release(unsigned char key, int x, int y);
    1.15 +void keyb_con(unsigned char key, int x, int y);
    1.16  void mouse(int bn, int state, int x, int y);
    1.17  void motion(int x, int y);
    1.18  
    1.19 @@ -33,6 +35,7 @@
    1.20  static float stereo_focus_dist = 0.25;
    1.21  static float stereo_eye_sep = stereo_focus_dist / 30.0;
    1.22  
    1.23 +static bool show_con;
    1.24  
    1.25  int main(int argc, char **argv)
    1.26  {
    1.27 @@ -128,7 +131,7 @@
    1.28  		glLoadIdentity();
    1.29  		view_matrix(-1);
    1.30  
    1.31 -		render_deferred(level);
    1.32 +		draw();
    1.33  
    1.34  		glDrawBuffer(GL_BACK_RIGHT);
    1.35  
    1.36 @@ -139,8 +142,7 @@
    1.37  		glLoadIdentity();
    1.38  		view_matrix(1);
    1.39  
    1.40 -		render_deferred(level);
    1.41 -
    1.42 +		draw();
    1.43  	} else {
    1.44  		glMatrixMode(GL_PROJECTION);
    1.45  		glLoadIdentity();
    1.46 @@ -149,7 +151,7 @@
    1.47  		glLoadIdentity();
    1.48  		view_matrix(0);
    1.49  
    1.50 -		render_deferred(level);
    1.51 +		draw();
    1.52  	}
    1.53  
    1.54  	glutSwapBuffers();
    1.55 @@ -158,6 +160,15 @@
    1.56  	usleep(10000);
    1.57  }
    1.58  
    1.59 +void draw()
    1.60 +{
    1.61 +	render_deferred(level);
    1.62 +
    1.63 +	if(show_con) {
    1.64 +		draw_cmdcon();
    1.65 +	}
    1.66 +}
    1.67 +
    1.68  void view_matrix(int eye)
    1.69  {
    1.70  	float offs = stereo_eye_sep * eye * 0.5;
    1.71 @@ -225,6 +236,13 @@
    1.72  	case 27:
    1.73  		exit(0);
    1.74  
    1.75 +	case '`':
    1.76 +		show_con = true;
    1.77 +		glutKeyboardFunc(keyb_con);
    1.78 +		glutKeyboardUpFunc(0);
    1.79 +		glutPostRedisplay();
    1.80 +		break;
    1.81 +
    1.82  	case 'z':
    1.83  		stereo_shift_pressed = true;
    1.84  		break;
    1.85 @@ -265,6 +283,18 @@
    1.86  	keystate[key] = false;
    1.87  }
    1.88  
    1.89 +void keyb_con(unsigned char key, int x, int y)
    1.90 +{
    1.91 +	if(key == '`' || key == 27) {
    1.92 +		show_con = false;
    1.93 +		glutKeyboardFunc(keyb);
    1.94 +		glutKeyboardUpFunc(key_release);
    1.95 +		glutPostRedisplay();
    1.96 +	} else {
    1.97 +		cmdcon_keypress(key);
    1.98 +	}
    1.99 +}
   1.100 +
   1.101  static int prev_x, prev_y;
   1.102  static bool bnstate[32];
   1.103