Пример #1
0
// glut display callback function.
// This function gets called every time the scene gets redisplayed 
void display()
{

   glUseProgram(shader_program);

   glBindFramebuffer(GL_FRAMEBUFFER, fbo_id); // Render to FBO.
   glDrawBuffer(GL_COLOR_ATTACHMENT0); //Out variable in frag shader will be written to the texture attached to GL_COLOR_ATTACHMENT0.

   //Make the viewport match the FBO texture size.
   int tex_w, tex_h;
   glBindTexture(GL_TEXTURE_2D, fbo_texture);
   glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &tex_w);
   glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &tex_h);
   glViewport(0, 0, tex_w, tex_h);

   //clear the FBO
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   draw_pass_1();
         
   glBindFramebuffer(GL_FRAMEBUFFER, 0); // Do not render the next pass to FBO.
   glDrawBuffer(GL_BACK); // Render to back buffer.

   const int w = glutGet(GLUT_WINDOW_WIDTH);
   const int h = glutGet(GLUT_WINDOW_HEIGHT);
   glViewport(0, 0, w, h); //Render to the full viewport
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Clear the back buffer

   draw_pass_2();

   draw_gui();

   glutSwapBuffers();
}
Пример #2
0
void redraw_creature_view(void)
{
    SYNCDBG(6,"Starting");
    TbGraphicsWindow ewnd;
    struct PlayerInfo *player;
    struct Thing *thing;
    //_DK_redraw_creature_view(); return;
    player = get_my_player();
    if (player->field_45F != 2)
      player->field_45F = 2;
    update_explored_flags_for_power_sight(player);
    thing = thing_get(player->controlled_thing_idx);
    TRACE_THING(thing);
    if (!thing_is_invalid(thing))
      draw_creature_view(thing);
    if (smooth_on)
    {
      store_engine_window(&ewnd,pixel_size);
      smooth_screen_area(lbDisplay.WScreen, ewnd.x, ewnd.y,
          ewnd.width, ewnd.height, lbDisplay.GraphicsScreenWidth);
    }
    remove_explored_flags_for_power_sight(player);
    draw_swipe_graphic();
    if ((game.numfield_C & 0x20) != 0) {
        draw_whole_status_panel();
    }
    draw_gui();
    if ((game.numfield_C & 0x20) != 0) {
        draw_overlay_compass(player->minimap_pos_x, player->minimap_pos_y);
    }
    message_draw();
    gui_draw_all_boxes();
    draw_tooltip();
}
Пример #3
0
void sound_gui() {
//	SDL_Event ev;
    u32 keys; 
	int action;
	
	set_yesno_string(quiet_data, quiet);
	set_dsp_string();
	set_sq_string();
	
	exit_sound = 0;
	while( !exit_sound ) {
		status_timer = 0;

		sprintf(msg, "Sound Options");
		draw_gui(sound_gui_items, sound_current);
		
//		SDL_WaitEvent(&ev);	/* TODO: respond to SDL_QUIT events */
		hidScanInput();
		while(!hidKeysHeld()) hidScanInput();
		keys = hidKeysHeld();
		action = gui_navigation(keys); //&ev);
		if(action == GUI_NO_ACTION) continue;
		
		sound_current = gui_handle_action(action, &exit_sound, sound_gui_items, sound_current);
	}
}
Пример #4
0
void tweaks_gui() {
//	SDL_Event ev;
    u32 keys; 
	int action;
	
	set_mpx_string();
	set_mpy_string();
	set_paddle_sensitivity_string();
	set_paddle_adjust_string();
	set_lightgun_cycles_string();
	set_lightgun_scanlines_string();
	
	exit_tweaks = 0;
	while( !exit_tweaks ) {
		status_timer = 0;

		sprintf(msg, "Controller Tweaks");
		draw_gui(tweaks_gui_items, tweaks_current);
		
//		SDL_WaitEvent(&ev);	/* TODO: respond to SDL_QUIT events */
		hidScanInput();
		while(!hidKeysHeld()) hidScanInput();
		keys = hidKeysHeld();
		action = gui_navigation(keys); //&ev);
		if(action == GUI_NO_ACTION) continue;
		
		tweaks_current = gui_handle_action(action, &exit_tweaks, tweaks_gui_items, tweaks_current);
	}
}
Пример #5
0
void interface_gui() {
	SDL_Event ev;
	int action;
	
	set_yesno_string(enable_keyboard_data, KeyboardEnabled);
	set_yesno_string(enable_mouse_data, MouseEnabled);
	set_yesno_string(enable_joystick_data, UserJoystickEnabled);
	set_yesno_string(enable_stelladaptor_data, StelladaptorEnabled);
	set_yesno_string(show_fps_data, ShowLineCount);
	set_yesno_string(mouse_rude_data, MouseRude);
	set_yesno_string(grab_input_data, GrabInput);
	set_theme_string();
	
	exit_interface = 0;
	while( !exit_interface ) {
		status_timer = 0;

		sprintf(msg, "Interface Options");
		draw_gui(interface_gui_items, interface_current);
		
		SDL_WaitEvent(&ev);	/* TODO: respond to SDL_QUIT events */
		action = gui_navigation(&ev);
		if(action == GUI_NO_ACTION) continue;
		
		interface_current = gui_handle_action(action, &exit_interface, interface_gui_items, interface_current);
	}
}
Пример #6
0
void redraw(gui_t *g, core_t *c) {
    destroy_window(g->mainwindow);
    destroy_window(g->content);
    destroy_window(g->user_list);
    g->mainwindow = create_window(LINES-3,COLS-16-2,1,1);
    g->content = create_window(LINES-3, COLS-16-2, 1, 1);
    g->user_list = create_window(LINES-3,16,1,COLS-16-1);
    c->cursor_y = LINES-1;
    //int len = strlen(c->room);
    wrefresh(g->content); // tu się sypie [nie wiedzieć czemu :x]
    wrefresh(g->user_list);
    wmove(g->mainwindow, c->cursor_y, strlen(c->room)+3+c->cursor_x);
    draw_gui(g->mainwindow, c);
    wrefresh(g->mainwindow);
    refresh();
}
Пример #7
0
static void draw()
{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  apply_projection();

  glPushMatrix();
  glLoadIdentity();

  if (camera_type == 1 || camera_type == 2)
    cm_apply_target_camera(tcamera);
  else
    cm_apply_fps_camera(fcamera);

  /* +/-X Cubes */
  rh_draw_cube((VEC3){ 3, 0, 0 }, (VEC3){ 1, 1, 1 }, (VEC3){ 0, cuberot, 0 });
  rh_draw_cube((VEC3){ -3, 0, 0 }, (VEC3){ 1, 1, 1 }, (VEC3){ 0, cuberot, 0 });
  /* +/-Z Cubes */
  rh_draw_cube((VEC3){ 0, 0, 3 }, (VEC3){ 1.25, 1.25, 1.25 }, (VEC3){ 0, -cuberot, 0 });
  rh_draw_cube((VEC3){ 0, 0, -3 }, (VEC3){ 1.25, 1.25, 1.25 }, (VEC3){ 0, -cuberot, 0 });

  /* Sphere stack of varing sizes and qualities */
  rh_draw_sphere((VEC3){ 0, 0, 0 }, (VEC3){ 1, 1, 1 }, (VEC3){ spherot, 0, 0 }, 3);
  rh_draw_sphere((VEC3){ 0, -1, 0 }, (VEC3){ .5, .5, .5 }, (VEC3){ -spherot, 0, 0 }, 2);
  rh_draw_sphere((VEC3){ 0, -1.5, 0 }, (VEC3){ .25, .25, .25 }, (VEC3){ spherot, 0, 0 }, 1);

  /* Polygon stack of various edge counts and rotations */
  rh_draw_extended_polygon((VEC3){ 0, 1, 0 }, (VEC3){ 1, .25, 1 }, (VEC3){ 0, polyrot, 0 }, 3);
  rh_draw_extended_polygon((VEC3){ 0, 1.75, 0 }, (VEC3){ 1, .25, 1 }, (VEC3){ 0, -polyrot, 0 }, 4);
  rh_draw_extended_polygon((VEC3){ 0, 2.5, 0 }, (VEC3){ 1, .25, 1 }, (VEC3){ 0, polyrot, 0 }, 5);
  rh_draw_extended_polygon((VEC3){ 0, 3.25, 0 }, (VEC3){ 1, .25, 1 }, (VEC3){ 0, -polyrot, 0 }, 7);
  rh_draw_extended_polygon((VEC3){ 0, 4, 0 }, (VEC3){ 1, .25, 1 }, (VEC3){ 0, polyrot, 0 }, 10);

  draw_gui();
  glPopMatrix();

  glFlush();
  glutSwapBuffers();
}
Пример #8
0
void screen_redraw()
{
  //d3dmgr->EndShapesBatching(); //If called inside bound surface we need to finish drawing
  d3dmgr->BeginScene();
  // Clean up any textures that ENIGMA may still think are binded but actually are not
  d3d_set_zwriteenable(true);
  if (!view_enabled)
  {
    screen_set_viewport(0, 0, window_get_region_width_scaled(), window_get_region_height_scaled());
    
    clear_view(0, 0, room_width, room_height, 0, background_showcolor);
    draw_back();
    draw_insts();
    draw_tiles();
  }
  else
  {
    //TODO: Possibly implement view option from Stupido to control which view clears the background
    // Only clear the background on the first visible view by checking if it hasn't been cleared yet
    bool draw_backs = true;
    bool background_allviews = true; // FIXME: Create a setting for this.
    for (view_current = 0; view_current < 8; view_current++)
    {
      int vc = (int)view_current;
      if (!view_visible[vc])
        continue;
      
      int vob = (int)view_object[vc];
      if (vob != -1)
        follow_object(vob, vc);

      screen_set_viewport(view_xport[vc], view_yport[vc], view_wport[vc], view_hport[vc]);
	  
      clear_view(view_xview[vc], view_yview[vc], view_wview[vc], view_hview[vc], view_angle[vc], background_showcolor && draw_backs);

      if (draw_backs)
        draw_back();
      
      draw_insts();
      
      if (draw_tiles())
        break;
      draw_backs = background_allviews;
    }
    view_current = 0;
  }

  // Now process the sub event of draw called draw gui
  // It is for drawing GUI elements without view scaling and transformation
  if (enigma::gui_used)
  {
    screen_set_viewport(0, 0, window_get_region_width_scaled(), window_get_region_height_scaled());
    d3d_set_projection_ortho(0, 0, enigma::gui_width, enigma::gui_height, 0);
	
    // Clear the depth buffer if hidden surface removal is on at the beginning of the draw step.
    if (enigma::d3dMode)
      d3dmgr->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

    draw_gui();
  }

  d3dmgr->EndScene();

  ///TODO: screen_refresh() shouldn't be in screen_redraw(). They are separate functions for a reason.
  screen_refresh();
}
Пример #9
0
void screen_redraw()
{
  // Clean up any textures that ENIGMA may still think are binded but actually are not
  d3d_set_zwriteenable(true);
  if (!view_enabled)
  {
    if (bound_framebuffer != 0) //This fixes off-by-one error when rendering on surfaces. This should be checked to see if other GPU's have the same effect
      screen_set_viewport(1, 1, window_get_region_width_scaled(), window_get_region_height_scaled());
    else
      screen_set_viewport(0, 0, window_get_region_width_scaled(), window_get_region_height_scaled());
    
    clear_view(0, 0, room_width, room_height, background_showcolor);
    draw_back();
    draw_insts();
    draw_tiles();
  }
  else
  {
    //TODO: Possibly implement view option from Stupido to control which view clears the background
    // Only clear the background on the first visible view by checking if it hasn't been cleared yet
    bool draw_backs = true;
    bool background_allviews = true; // FIXME: Create a setting for this.
    for (view_current = 0; view_current < 8; view_current++)
    {
      int vc = (int)view_current;
      if (!view_visible[vc])
        continue;
      
      int vob = (int)view_object[vc];
      if (vob != -1)
        follow_object(vob, vc);

      if (bound_framebuffer != 0) //This fixes off-by-one error when rendering on surfaces. This should be checked to see if other GPU's have the same effect
        screen_set_viewport(view_xport[vc]+1, view_yport[vc]+1, view_wport[vc], view_hport[vc]);
      else
        printf("%d %d %d %d\n", (int)view_xport[vc], (int)view_yport[vc], (int)view_wport[vc], (int)view_hport[vc]),
        screen_set_viewport(view_xport[vc], view_yport[vc], view_wport[vc], view_hport[vc]);
	  
      clear_view(view_xview[vc], view_yview[vc], view_wview[vc], view_hview[vc], background_showcolor && draw_backs);

      if (draw_backs)
        draw_back();
      
      draw_insts();
      
      if (draw_tiles())
        break;
      draw_backs = background_allviews;
    }
    view_current = 0;
  }

  // Now process the sub event of draw called draw gui
  // It is for drawing GUI elements without view scaling and transformation
  if (enigma::gui_used)
  {
    screen_set_viewport(0, 0, window_get_region_width_scaled(), window_get_region_height_scaled());
	d3d_set_projection_ortho(0, 0, enigma::gui_width, enigma::gui_height, 0);
	
    // Clear the depth buffer if hidden surface removal is on at the beginning of the draw step.
    if (enigma::d3dMode)
      glClear(GL_DEPTH_BUFFER_BIT);

    draw_gui();
  }

  if (enigma::msaa_fbo != 0) {
    GLint fbo;
    glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &fbo);
    glBindFramebuffer(GL_READ_FRAMEBUFFER, enigma::msaa_fbo);
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
    //TODO: Change the code below to fix this to size properly to views
    glBlitFramebuffer(0, 0, window_get_region_width_scaled(), window_get_region_height_scaled(), 0, 0, window_get_region_width_scaled(), window_get_region_height_scaled(), GL_COLOR_BUFFER_BIT, GL_NEAREST);
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
    // glReadPixels(0, 0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, pixels);
  }

  ///TODO: screen_refresh() shouldn't be in screen_redraw(). They are separate functions for a reason.
  if (bound_framebuffer==0 || enigma::msaa_fbo != 0) { screen_refresh(); }
}
Пример #10
0
int main(int argc, char ** argv) {
	setlocale(LC_ALL, "");
	setlocale(LC_CTYPE, "C-UTF-8");	
	initscr();
	cbreak();

	//keypad(stdscr, TRUE);

	refresh();

	gui_t gui;
	core_t core;

	gui.mainwindow = create_window(LINES, COLS, 0, 0);
	gui.content = create_window(LINES-3, COLS-16-2, 1, 1);
	gui.user_list = create_window(LINES-3, 16, 1, COLS-16-1);

	strncpy(core.room, "(status)", 9);
	core.room[8] = '\0';
	core.cur_line = 0;
	core.cur_user_pos = 0;
	init_colors();
	draw_gui(gui.mainwindow, &core);

	core.cursor_x = 0;
	core.cursor_y = LINES-1;
	//core.serverkey = 0;
	char /*cur_time[9], userlist_buffer[1024],*/ buffer[1024];
	time_t now;
	//strftime(cur_time, 9, "%H:%M:%S", localtime(&now));
	//cur_time[8] = '\0';
	//char buf[512];
	add_info(&core, gui.content, "OS-Chat wystartowal", &now);
	add_info(&core, gui.content, "wpisz /help aby uzyskac pomoc", &now);
	//add_msg(&core, gui.content, "hun7er", "czesc", &now, 1);
	//add_msg(&core, gui.content, "hun7er", "]:>", &now, 1);
	//add_msg(&core, gui.content, "bot", "yo", &now, 0);

	//add_user_to_list(&core, "hun7er");
	//add_user_to_list(&core, "testowy");
	//add_content_line(&core, gui.content, 0, "-!- uzytkownik mescam dolaczyl do #global");
	
	scrollok(gui.content, 1);
	
	refresh();
	int int_queue_in, int_queue_out, ext_queue; // internal queue, external queue
	
	struct mq_attr attr;
	attr.mq_msgsize = MAX_MSG_SIZE;
	attr.mq_maxmsg = 10;
	//char buf[128];
	int e1 = 1, e2 = 1;
	
	do {
		sprintf(res.q_in, "/internal_in%d", e1);
		res.int_in_fd = mq_open(res.q_in, O_RDWR|O_CREAT|O_EXCL, 0777, &attr);
		e1++;
	} while(res.int_in_fd == -1);
	do {
		sprintf(res.q_out, "/internal_out%d", e2);
		res.int_out_fd = mq_open(res.q_out, O_RDWR|O_CREAT|O_EXCL, 0777, &attr);
		e2++;
	} while(res.int_out_fd == -1);

	int_queue_in = res.int_in_fd;
	int_queue_out = res.int_out_fd;

	if(int_queue_in == -1 || int_queue_out == -1) {
		endwin();
		printf("max msg size: %lu\n", MAX_MSG_SIZE);
		perror("Nie mozna utworzyc wewnetrznych kolejek komunikatow");
		printf("Numer bledu: %d\n", errno);
		return -1;
	}
	//sprintf(buf, "Kolejki: %s (in), %s (out)", res.q_in, res.q_out);
	//add_info(&core, gui.content, buf, &now);
	now = time(NULL);
	//add_private(&core, gui.content, "hun7er", "psssst. Kolego, masz na ziarno?", &now);

	int ret = pipe(server_key);
	if(ret == -1) {
		add_content_line(&core, gui.content, 0, "-!- Blad: nie mozna utworzyc potoku");
	}
	ret = pipe(room);
	if(ret == -1) {
		add_info(&core, gui.content, "BLAD: nie mozna utworzyc potoku", &now);
	}
	fcntl(server_key[0], F_SETFL, O_NDELAY);
	fcntl(server_key[1], F_SETFL, O_NDELAY);
	fcntl(room[0], F_SETFL, O_NDELAY);
	fcntl(room[1], F_SETFL, O_NDELAY);

	// internal: obrobione dane do wyswietlenia
	// external: "surowe" dane do obrobienia przez forki

	ext_queue = DEFAULT_QUEUE_KEY;
	get_key(&ext_queue);
	core.mykey = res.queue_key = ext_queue;
	core.serverkey = 0;
	//sprintf(buf, "DEBUG moj klucz kolejki: %d", ext_queue);
	//add_content_line(&core, gui.content, 0, buf);
	signal(SIGINT, SIG_DFL);
	//int child1 = 0, child2 = 0;
	if(!(res.child_id1 = fork())) {
		signal(SIGINT, SIG_DFL);
		int queue_in = mq_open(res.q_in, O_RDWR), skey = 0, queue_out = mq_open(res.q_out, O_RDWR);
		if(queue_in == -1) {
			perror("Nie mozna otworzyc wewnetrznej kolejki komunikatow (in)");
			return -1;
		}
		compact_message cmg; // m.in. do odpowiadania na HEARTBEAT
		standard_message smg; // m.in. wiadomosci prywatne/kanalowe
		user_list usr;
		message msg;
		// odbieranie
		
		struct timespec tim;
		tim.tv_sec = 0;
		tim.tv_nsec = 1000;	

		//close(server_key[1]);
		char roomname[512];
		close(room[1]);
		while(1) {
			int mid = msgget(ext_queue, 0777);
			char buf[16];
			if(mid == -1) {
				// wyslij komunikat do GUI że się posypała kolejka
				// spróbuj zaalokować nową
			} else {	
				if(receive(ext_queue, &cmg, /*member_size(compact_message, content)*/sizeof(compact_message), MSG_HEARTBEAT) != -1) {
					msg.type = M_HEARTBEAT;
					msg.source = cmg.content.value;
					int rcpt = msgget(cmg.content.value, 0777);
					cmg.content.value = core.mykey;
					msgsnd(rcpt, &cmg, sizeof(compact_message), IPC_NOWAIT);
					//mq_send(queue_out, (char*)&msg, MAX_MSG_SIZE, M_HEARTBEAT);
					mq_send(queue_in, (char*)&msg, MAX_MSG_SIZE, M_HEARTBEAT);
				}
				if(receive(ext_queue, &cmg, /*member_size(compact_message, content)*/sizeof(compact_message), MSG_JOIN) != -1) {
					int ret = 0;
					do {
						ret = read(room[0], &roomname, 512);
					} while(ret == 0);
					msg.type = M_JOIN;
					strcpy(msg.content.room, roomname);
					mq_send(queue_in, (char*)&msg, MAX_MSG_SIZE, M_JOIN);
				}
				if(receive(ext_queue, &cmg, /*member_size(compact_message, content)*/sizeof(compact_message), MSG_REGISTER) != -1) {
					int /*mid = -1, */len = -1, val;
					switch(cmg.content.value) {
						case 0:
							msg.type = M_REGISTER;
							strcpy(msg.content.name, cmg.content.sender);
							mq_send(queue_in, (char*)&msg, MAX_MSG_SIZE, M_REGISTER);
							//printf("ret = %d\n", ret);
							msg.type = M_JOIN;
							strcpy(msg.content.room, GLOBAL_ROOM_NAME);
							mq_send(queue_in, (char*)&msg, MAX_MSG_SIZE, M_JOIN);
							msg.type = M_USERLIST;
							msg.source = core.mykey;
							len = 0;
							do {
								len = read(server_key[0], &buf, 16);
							} while (len == 0);
							write(server_key[1], &buf, 16);
							
							val = atoi(buf);
							if(skey != val) skey = val;
							if(skey != 0) {
								msg.dest = skey;
								mq_send(queue_out, (char*)&msg, MAX_MSG_SIZE, M_USERLIST);
							}
								//msgsnd(mid, &cmg, /*member_size(compact_message, content)*/sizeof(compact_message), IPC_NOWAIT);
						break;
						case -1: // nick istnieje
							msg.type = M_ERROR;
							strcpy(msg.content.message, "Blad rejestracji: nick uzywany");
							mq_send(queue_in, (char*)&msg, MAX_MSG_SIZE, M_ERROR);
						break;
						case -2: // serwer pelen
							msg.type = M_ERROR;
							strcpy(msg.content.message, "Blad rejestracji: serwer pelen");
							mq_send(queue_in, (char*)&msg, MAX_MSG_SIZE, M_ERROR);
						break;
					}
				}
				if(receive(ext_queue, &smg, /*member_size(standard_message, content)*/sizeof(standard_message), MSG_ROOM) != -1) {
					msg.type = M_MESSAGE;
					strcpy(msg.content.message, smg.content.message);
					strcpy(msg.content.name, smg.content.sender);
					msg.content.date = smg.content.send_date;
					mq_send(queue_in, (char*)&msg, MAX_MSG_SIZE, M_MESSAGE);
				}
				if(receive(ext_queue, &smg, /*member_size(standard_message, content)*/sizeof(standard_message), MSG_PRIVATE) != -1) {
					msg.type = M_PRIVATE;
					strcpy(msg.content.message, smg.content.message);
					strcpy(msg.content.name, smg.content.sender);
					mq_send(queue_in, (char*)&msg, MAX_MSG_SIZE, M_PRIVATE);
				}
				if(receive(ext_queue, &usr, /*member_size(user_list, content)*/sizeof(user_list), MSG_LIST) != -1) {
					msg.type = M_USERLIST;
					int i = 0;
					for(; i < MAX_USER_LIST_LENGTH; i++) {
						strcpy(msg.content.list[i], usr.content.list[i]);
					}
					mq_send(queue_in, (char*)&msg, MAX_MSG_SIZE, M_USERLIST);
				}
				if(receive(ext_queue, &cmg, sizeof(compact_message), MSG_LEAVE) != -1) {
					msg.type = M_LEAVE;
					mq_send(queue_in, (char*)&msg, MAX_MSG_SIZE, M_LEAVE);
				}
			}
			nanosleep(&tim, NULL);
		}
		// tu będzie odbieranie msgrcv() komunikatów zwykłych (najlepiej w jakiejś zewnętrznej funkcji) + wysyłanie danych do kolejki wewnętrznej w razie potrzeby
		//}
	} else {	// interfejs uzytkownika
		if(!(res.child_id2 = fork())) {
			signal(SIGINT, SIG_DFL);
			struct pollfd ufds;
			int queue_out = mq_open(res.q_out, O_RDWR);
			if(queue_out == -1) {
				perror("Nie mozna otworzyc wewnetrznej kolejki komunikatow (out)");
				return -1;
			}
			ufds.fd = queue_out;
			ufds.events = POLLIN;
			while(1) {
				switch(poll(&ufds, 1, 10)) {
					default:
					if(ufds.revents && POLLIN)	// tu jakis callback do wysyłania np. get_and_send() w out_callback
						out_callback(queue_out);
						//key_callback(&gui, &core, buffer);
				}
				
			}
			// wysylanie
		} else {
			if(!(res.child_id3 = fork())) {
				int queue_out = mq_open(res.q_out, O_RDWR);
				if(queue_out == -1) {
					endwin();
					perror("Nie mozna otworzyc wewnetrznej kolejki");
					kill(getppid(), SIGKILL);
					exit(-1);
				}
				struct timespec tim;
				tim.tv_sec = 2;
				tim.tv_nsec = 0;
				//char buf[512];
				int skey = 0;
				//close(server_key[1]);
				while(1) {
					//sprintf(buf, "[DEBUG] core.serverkey: %d", core.serverkey);
					//add_content_line(&core, gui.content, 1, buf);
					char buf[16];
					read(server_key[0], &buf, 16);
					int val = atoi(buf);
					if(val != skey && skey > 0)	skey = val;
					if(skey > 0) {
						endwin();
						printf("skey: %d\n", skey);
						exit(-1);
						message msg;
						msg.type = M_USERLIST;
						msg.source = core.mykey;
						msg.dest = skey;
						mq_send(queue_out, (char*)&msg, MAX_MSG_SIZE, M_USERLIST);
						sprintf(buf, "%d", skey);
						write(server_key[1], &buf, 16);
						//add_content_line(&core, gui.content, 1, "[DEBUG] Trying to reach server...");
					}
					nanosleep(&tim, NULL);
				}
			} else {
			signal(SIGINT, sighandler);
			int /*i = 0, */ufds_size = 2;
			struct pollfd ufds[2];

			ufds[0].fd = STDIN_FILENO;
			ufds[0].events = POLLIN;
			ufds[1].fd = int_queue_in;
			ufds[1].events = POLLIN;
	
			while(1) {
				//mvwprintw(gui.user_list, 0, 0, "%s", userlist_buffer);
				/*for(i = 0; i < LINES; i++) { // naprawic zeby tylko wyswietlalo gdy jest jakas zmiana
					mvwprintw(gui.user_list, i, 0, "%s", core.userlist[i]);
				}
				wrefresh(gui.user_list);*/
				wmove(gui.mainwindow, core.cursor_y, (strcmp(core.room, "(status)") == 0 ? strlen(core.room)+3+core.cursor_x : strlen(core.room)+4+core.cursor_x));
				wrefresh(gui.mainwindow);
				//refresh();
	
				switch(poll(ufds, ufds_size, 10)) {
					case -1: // np. resize terminala
						redraw(&gui, &core);
						//refresh();
					break;
					default:
						if(ufds[0].revents && POLLIN)
							key_callback(&gui, &core, buffer, int_queue_out);
						if(ufds[1].revents && POLLIN)
							in_callback(&gui, &core, int_queue_in);
				}
			} // while(1)
			}
		} // else
	} // else forka
	return 0;
}