예제 #1
0
void TCOD_sys_flush(bool render) {
	static uint32 old_time,new_time=0, elapsed=0;
	int32 frame_time,time_to_wait;
	if ( render ) {
		TCOD_sys_console_to_bitmap(screen,TCOD_console_get_width(NULL),TCOD_console_get_height(NULL),consoleBuffer, prevConsoleBuffer);
		if ( TCOD_sdl_renderer ) {
			TCOD_sdl_renderer((void *)screen);
		}
		SDL_Flip(screen);
	}
	old_time=new_time;
	new_time=TCOD_sys_elapsed_milli();
	if ( new_time / 1000 != elapsed ) {
		/* update fps every second */
		fps=cur_fps;
		cur_fps=0;
		elapsed=new_time/1000;
	}
	/* if too fast, wait */
	frame_time=(new_time - old_time);
	last_frame_length = frame_time * 0.001f;
	cur_fps++;
	time_to_wait=min_frame_length-frame_time;
	if (old_time > 0 && time_to_wait > 0) {
		TCOD_sys_sleep_milli(time_to_wait);
		new_time = TCOD_sys_elapsed_milli();
		frame_time=(new_time - old_time);
	}
	last_frame_length = frame_time * 0.001f;
}
예제 #2
0
void TCOD_sys_flush(bool render) {
	static uint32 old_time,new_time=0, elapsed=0;
	int32 frame_time,time_to_wait;
	if ( render ) {
		TCOD_sys_console_to_bitmap(renderWindow,TCOD_console_get_width(NULL),TCOD_console_get_height(NULL),consoleBuffer,prevConsoleBuffer);
		sfRenderWindow_Display(renderWindow);
	}
	old_time=new_time;
	new_time=TCOD_sys_elapsed_milli();
	if ( new_time / 1000 != elapsed ) {
		/* update fps every second */
		fps=cur_fps;
		cur_fps=0;
		elapsed=new_time/1000;
printf ("nbBlit : %d\n",(int)(nbBlit/fps));nbBlit=0;
	}
	/* if too fast, wait */
	frame_time=(new_time - old_time);
	last_frame_length = frame_time * 0.001f;
	cur_fps++;
	time_to_wait=min_frame_length-frame_time;
	if (old_time > 0 && time_to_wait > 0) {
		TCOD_sys_sleep_milli(time_to_wait);
		new_time = TCOD_sys_elapsed_milli();
		frame_time=(new_time - old_time);
	} 
	last_frame_length = frame_time * 0.001f;
}
예제 #3
0
void *TCOD_sys_create_bitmap_for_console(TCOD_console_t console) {
	int w,h;
	sfImage *bitmap;
	w = TCOD_console_get_width(console) * fontWidth;
	h = TCOD_console_get_height(console) * fontHeight;
	bitmap=sfImage_CreateFromColor(w,h,sfBlack);
	return (void *)bitmap;
}
예제 #4
0
TCOD_image_t TCOD_image_from_console(TCOD_console_t console) {
	image_data_t *ret;
	void *bitmap=TCOD_sys_create_bitmap_for_console(console);
	TCOD_sys_console_to_bitmap(bitmap, TCOD_console_get_width(console), TCOD_console_get_height(console),
		TCOD_console_get_buf(console),NULL);
	ret=(image_data_t *)calloc(sizeof(image_data_t),1);
	ret->sys_img=bitmap;
	return (TCOD_image_t)ret;
}
예제 #5
0
static void TCOD_noteye_render() {
  TCOD_noteye_init();
  int sx = TCOD_console_get_width(NULL);
  int sy = TCOD_console_get_height(NULL);
  scr->setSize(sx, sy);
  char_t *buffer = tbuffer;
  for(int y=0; y<sy; y++) for(int x=0; x<sx; x++) {
    scr->get(x,y) = 
      addMerge(
//      addFill(0), addRecolor(fnt->ti[buffer->c], 0xFFFFFF)
        addFill(noteyecolor(buffer->back), 0xFFFFFF), addRecolor(ourfont[buffer->c], noteyecolor(buffer->fore), recDefault),
        false
        );
    buffer++;
    }
  lastframe = SDL_GetTicks();
  }
예제 #6
0
static TCOD_key_t TCOD_sys_SDLtoTCOD(SDL_Event *ev, int flags) {
	static TCOD_key_t ret;
	ret.vk=TCODK_NONE;
	ret.c=0;
	ret.pressed=0;
	switch (ev->type) {
		case SDL_QUIT :
			TCOD_console_set_window_closed();
		break;
		case SDL_VIDEOEXPOSE :
			TCOD_sys_console_to_bitmap(screen,TCOD_console_get_width(NULL),TCOD_console_get_height(NULL),consoleBuffer,prevConsoleBuffer);
		break;
		case SDL_MOUSEBUTTONDOWN : {
			SDL_MouseButtonEvent *mev=&ev->button;
			switch (mev->button) {
				case 1 : mousebl=true; break;
				case 2 : mousebm=true; break;
				case 3 : mousebr=true; break;
			}
		}
		break;
		case SDL_MOUSEBUTTONUP : {
			SDL_MouseButtonEvent *mev=&ev->button;
			switch (mev->button) {
				case 1 : if (mousebl) mouse_force_bl=true; mousebl=false; break;
				case 2 : if (mousebm) mouse_force_bm=true; mousebm=false; break;
				case 3 : if (mousebr) mouse_force_br=true; mousebr=false; break;
			}
		}
		break;
		case SDL_KEYUP : {
			SDL_KeyboardEvent *kev=&ev->key;
			TCOD_key_t tmpkey;
			switch(kev->keysym.sym) {
				case SDLK_LALT : ret.lalt=0; break;
				case SDLK_RALT : ret.ralt=0; break;
				case SDLK_LCTRL : ret.lctrl=0; break;
				case SDLK_RCTRL : ret.rctrl=0; break;
				case SDLK_LSHIFT : ret.shift=0; break;
				case SDLK_RSHIFT : ret.shift=0; break;
				default:break;
			}
			TCOD_sys_convert_event(ev,&tmpkey);
			key_status[tmpkey.vk]=false;
			if ( flags & TCOD_KEY_RELEASED ) {
				ret.vk=tmpkey.vk;
				ret.c=tmpkey.c;
				ret.pressed=0;
			}
		}
		break;
		case SDL_KEYDOWN : {
			SDL_KeyboardEvent *kev=&ev->key;
			TCOD_key_t tmpkey;
			switch(kev->keysym.sym) {
				case SDLK_LALT : ret.lalt=1; break;
				case SDLK_RALT : ret.ralt=1; break;
				case SDLK_LCTRL : ret.lctrl=1; break;
				case SDLK_RCTRL : ret.rctrl=1; break;
				case SDLK_LSHIFT : ret.shift=1; break;
				case SDLK_RSHIFT : ret.shift=1; break;
				default : break;
			}
			TCOD_sys_convert_event(ev,&tmpkey);
			key_status[tmpkey.vk]=true;
			if ( flags & TCOD_KEY_PRESSED ) {
				ret.vk=tmpkey.vk;
				ret.c=tmpkey.c;
				ret.pressed=1;
			}
		}
		break;
	}
	return ret;
}
예제 #7
0
void *TCOD_sys_create_bitmap_for_console(TCOD_console_t console) {
	int w,h;
	w = TCOD_console_get_width(console) * fontWidth;
	h = TCOD_console_get_height(console) * fontHeight;
	return TCOD_sys_get_surface(w,h,false);
}
예제 #8
0
void TCOD_image_refresh_console(TCOD_image_t image, TCOD_console_t console) {
	image_data_t *img=(image_data_t *)image;
	TCOD_sys_console_to_bitmap(img->sys_img, TCOD_console_get_width(console), TCOD_console_get_height(console),
		TCOD_console_get_buf(console),NULL);
}
예제 #9
0
void TCOD_image_blit(TCOD_image_t image, TCOD_console_t console, float x, float y,
	TCOD_bkgnd_flag_t bkgnd_flag, float scalex, float scaley, float angle) {
	int width,height;
	image_data_t *img=(image_data_t *)image;
	if ( scalex == 0.0f || scaley == 0.0f || bkgnd_flag == TCOD_BKGND_NONE ) return;
	TCOD_image_get_size(image,&width,&height);
	if ( scalex == 1.0f && scaley == 1.0f && angle == 0.0f && x-((int)x) == 0.0f && y-((int)y)==0.0f) {
		// clip the image
		int ix = (int)(x - width*0.5f);
		int iy = (int)(y - height*0.5f);
		int minx=MAX(ix,0);
		int miny=MAX(iy,0);
		int maxx=MIN(ix+width,TCOD_console_get_width(console));
		int maxy=MIN(iy+height,TCOD_console_get_height(console));
		int offx=0,offy=0;
		int cx,cy;
		if ( ix < 0 ) offx=-ix;
		if ( iy < 0 ) offy=-iy;
		for (cx=minx; cx < maxx; cx ++) {
			for (cy=miny; cy < maxy; cy ++) {
				TCOD_color_t col=TCOD_image_get_pixel(image,cx-minx+offx,cy-miny+offy);
				if ( !img->has_key_color || img->key_color.r != col.r
					|| img->key_color.g != col.g || img->key_color.b != col.b ) {
					TCOD_console_set_back(console,cx,cy,col,bkgnd_flag);
				}
			}
		}
	} else {
		float iw=width/2*scalex;
		float ih=height/2*scaley;
		// get the coordinates of the image corners in the console
		float newx_x = cosf(angle);
		float newx_y = -sinf(angle);
		float newy_x = newx_y;
		float newy_y = -newx_x;
		float x0,y0,x1,y1,x2,y2,x3,y3; // image corners coordinates
		int rx,ry,rw,rh; // rectangular area in the console
		int cx,cy;
		int minx,miny,maxx,maxy;
		float invscalex,invscaley;
		// 0 = P - w/2 x' +h/2 y'
		x0 = x-iw*newx_x+ih*newy_x;
		y0 = y-iw*newx_y+ih*newy_y;
		// 1 = P + w/2 x' + h/2 y'
		x1 = x+iw*newx_x+ih*newy_x;
		y1 = y+iw*newx_y+ih*newy_y;
		// 2 = P + w/2 x' - h/2 y'
		x2 = x+iw*newx_x-ih*newy_x;
		y2 = y+iw*newx_y-ih*newy_y;
		// 3 = P - w/2 x' - h/2 y'
		x3 = x-iw*newx_x-ih*newy_x;
		y3 = y-iw*newx_y-ih*newy_y;
		// get the affected rectangular area in the console
		rx=(int)(MIN(MIN(x0,x1),MIN(x2,x3)));
		ry=(int)(MIN(MIN(y0,y1),MIN(y2,y3)));
		rw=(int)(MAX(MAX(x0,x1),MAX(x2,x3))) - rx;
		rh=(int)(MAX(MAX(y0,y1),MAX(y2,y3))) - ry;
		// clip it
		minx=MAX(rx,0);
		miny=MAX(ry,0);
		maxx=MIN(rx+rw,TCOD_console_get_width(console));
		maxy=MIN(ry+rh,TCOD_console_get_height(console));
		invscalex=1.0f / scalex;
		invscaley=1.0f / scaley;
		for (cx=minx; cx < maxx; cx ++) {
			for (cy=miny; cy < maxy; cy ++) {
				float ix,iy;
				TCOD_color_t col;
				// map the console pixel to the image world
				ix = (iw+ (cx-x) * newx_x + (cy-y) *(-newy_x))*invscalex;
				iy = (ih + (cx-x) * (newx_y) - (cy-y)*newy_y)*invscaley;
				col = TCOD_image_get_pixel(image,(int)(ix),(int)(iy));
				if ( !img->has_key_color || img->key_color.r != col.r
					|| img->key_color.g != col.g || img->key_color.b != col.b ) {
					if ( scalex < 1.0f || scaley < 1.0f ) {
						col = TCOD_image_get_mipmap_pixel(image,ix,iy,ix+1.0f,iy+1.0f);
					}
					TCOD_console_set_back(console,cx,cy,col,bkgnd_flag);
				}
			}
		}
	}
}
예제 #10
0
static TCOD_event_t TCOD_sys_handle_event(SDL_Event *ev,TCOD_event_t eventMask, TCOD_key_t *key, TCOD_mouse_t *mouse) {
	TCOD_event_t retMask=0;
	switch(ev->type) {
		case SDL_KEYDOWN : {		 
			TCOD_key_t tmpKey=TCOD_sys_SDLtoTCOD(ev,TCOD_KEY_PRESSED);
			if ( (TCOD_EVENT_KEY_PRESS & eventMask) != 0) {
				retMask|=TCOD_EVENT_KEY_PRESS; 
				if ( key ) *key = tmpKey; 
				return retMask;					
			}
		}
		break;
		case SDL_KEYUP : { 
			TCOD_key_t tmpKey=TCOD_sys_SDLtoTCOD(ev,TCOD_KEY_RELEASED);
			if ( (TCOD_EVENT_KEY_RELEASE & eventMask) != 0) {
				retMask|=TCOD_EVENT_KEY_RELEASE; 
				if ( key ) *key = tmpKey;
				return retMask;					
			}
		}
		break;
		case SDL_MOUSEMOTION : 
			if ( (TCOD_EVENT_MOUSE_MOVE & eventMask) != 0) {
				SDL_MouseMotionEvent *mme=&ev->motion;
				int charWidth, charHeight;
				/*SDL_GetMouseState(&mouse->x,&mouse->y);*/
				/*SDL_GetRelativeMouseState(&mouse->dx,&mouse->dy);*/
				retMask|=TCOD_EVENT_MOUSE_MOVE;
				mouse->dx += mme->xrel;
				mouse->dy += mme->yrel;
				mouse->x=mme->x;
				mouse->y=mme->y;				
				TCOD_sys_get_char_size(&charWidth,&charHeight);
				mouse->cx = (mouse->x - TCOD_ctx.fullscreen_offsetx) / charWidth;
				mouse->cy = (mouse->y - TCOD_ctx.fullscreen_offsety) / charHeight;
				mouse->dcx = mouse->dx / charWidth;
				mouse->dcy = mouse->dy / charHeight;
				return retMask;
			}
		break; 
		case SDL_MOUSEBUTTONDOWN : 
			if ( (TCOD_EVENT_MOUSE_PRESS & eventMask) != 0) {
				SDL_MouseButtonEvent *mev=&ev->button;
				retMask|=TCOD_EVENT_MOUSE_PRESS;
				switch (mev->button) {
					case SDL_BUTTON_LEFT : mouse->lbutton=mousebl=true; break;
					case SDL_BUTTON_MIDDLE : mouse->mbutton=mousebm=true; break;
					case SDL_BUTTON_RIGHT : mouse->rbutton=mousebr=true; break;
					case SDL_BUTTON_WHEELUP : mouse->wheel_up=true; break;
					case SDL_BUTTON_WHEELDOWN : mouse->wheel_down=true;break;
				}
				return retMask;
			}
		break; 
		case SDL_MOUSEBUTTONUP : 
			if ( (TCOD_EVENT_MOUSE_RELEASE & eventMask) != 0) {
				SDL_MouseButtonEvent *mev=&ev->button;
				retMask|=TCOD_EVENT_MOUSE_RELEASE;
				switch (mev->button) {
					case SDL_BUTTON_LEFT : if (mousebl) mouse->lbutton_pressed = mouse_force_bl=true; mouse->lbutton = mousebl=false; break;
					case SDL_BUTTON_MIDDLE : if (mousebm) mouse->mbutton_pressed = mouse_force_bm=true; mouse->mbutton = mousebm=false; break;
					case SDL_BUTTON_RIGHT : if (mousebr) mouse->rbutton_pressed = mouse_force_br=true; mouse->rbutton = mousebr=false; break;
				}
				return retMask;
			}
		break;
		case SDL_QUIT :
			TCOD_console_set_window_closed();
		break;
		case SDL_VIDEOEXPOSE :
			TCOD_sys_console_to_bitmap(screen,TCOD_console_get_width(NULL),TCOD_console_get_height(NULL),consoleBuffer,prevConsoleBuffer);
		break;			
		default : break; 
	}
	return retMask;
}
예제 #11
0
int TCODConsole::getWidth() const {
	return TCOD_console_get_width(data);
}