when
- 23.06.16 20:30 ~ 21:30
- 23.06.17 22:00 ~ 24:00
- 23.06.21 19:30 ~ 01:00
- 23.07.01 19:30 ~ 05:00
- 23.07.02 11:00 ~ 17:00
- 23.07.05 19:00 ~ 02:20
- 23.07.08 13:15 ~ 17:30
- 23.07.12 20:00 ~ 02:30
내용 | |
---|---|
제출 파일 | Makefile, .h, .c, maps, textures |
Makefile | NAME, all, clean, fclean, re |
외부 함수 | open, close, read, write, malloc, free, perror, strerror, exit + MinilibX 라이브러리 내 모든 함수, math library |
매개변수 | 읽어들일 파일의 descriptor (서술자) |
인자 | \*.ber 형태의 맵 |
libft 사용 | 허용 |
norm error 금지
segmetation fault, bus error, double free 금지
heap에 동적 할당된 메모리 해제 (메모리 누수 방지)
Makefile 제출
libft 사용
MiniLibX 사용
ESC
: 창을 닫고 게임을 정상적으로 종료좌상단의 빨간 버튼 (mac)
: 창을 닫고 게임 정상 종료 1111111111111
10010000000C1
1000011111001
1P0011E000001
1111111111111
"Error\n"
+ 직접 정한 에러 메시지를 출력 후 종료1111111111111111111111111111111111
1E0000000000000C00000C000000000001
1010010100100000101001000000010101
1010010010101010001001000000010101
1P0000000C00C0000000000000000000C1
1111111111111111111111111111111111
#include <mlx.h>
void *mlx_init ();
void *mlx_new_window (void *mlx_ptr, int size_x, int size_y, char *title);
int mlx_clear_window (void *mlx_ptr, void *win_ptr);
int mlx_destroy_window (void *mlx_ptr, void *win_ptr);
int mlx_pixel_put (void *mlx_ptr, void *win_ptr, int x, int y, int color);
int mlx_string_put (void *mlx_ptr, void *win_ptr, int x, int y, int color, char *string);
void *mlx_xpm_file_to_image(void *mlx_ptr, char *filename, int *width, int *height);
int mlx_put_image_to_window(void *mlx_ptr, void *win_ptr, void *img_ptr, int x, int y);
char *mlx_get_data_addr(void *img_ptr, int *bits_per_pixel, int *size_line, int *endian);
int *mlx_destroy_image(void *mlx_ptr, void *img_ptr);
int mlx_loop(void *mlx_ptr);
int mlx_key_hook(void *win_ptr, int x_event, int x_mask, int (*funct)(), void *param);
mlx_loop_hook(par.mlx, &draw, &par);
📖 참고 📖 X-Window
X-Window는 유닉스 용 네트워크 지향 그래픽 시스템이다. 원격 데스크톱에 연결할 때 사용된다. 이러한 구현의 가장 일반적인 것은 TeamViewer이다.
📖 참고 📖 X11 Events
02: KeyPress
03: KeyRelease
04: ButtonPress
05: ButtonRelease
06: MotionNotify
07: EnterNotify
08: LeaveNotify
09: FocusIn
10: FocusOut
11: KeymapNotify
12: Expose
13: GraphicsExpose
14: NoExpose
15: VisibilityNotify
16: CreateNotify
17: DestroyNotify
18: UnmapNotify
19: MapNotify
20: MapRequest
21: ReparentNotify
22: ConfigureNotify
23: ConfigureRequest
24: GravityNotify
25: ResizeRequest
26: CirculateNotify
27: CirculateRequest
28: PropertyNotify
29: SelectionClear
30: SelectionRequest
31: SelectionNotify
32: ColormapNotify
33: ClientMessage
34: MappingNotify
35: GenericEvent
36: LASTEvent
📖 참고 📖 X11 masks
- 이벤트가 trigger될 때 한가지 키만 등록할 수 있고, 모든 키 등록 가능
- 키 마스크는 이벤트 목록으로부터 whitelist/blacklist 나눌 수 있음
NoEventMask 0L
KeyPressMask (1L<<0)
KeyReleaseMask (1L<<1)
ButtonPressMask (1L<<2)
ButtonReleaseMask (1L<<3)
EnterWindowMask (1L<<4)
LeaveWindowMask (1L<<5)
PointerMotionMask (1L<<6)
PointerMotionHintMask (1L<<7)
Button1MotionMask (1L<<8)
Button2MotionMask (1L<<9)
Button3MotionMask (1L<<10)
Button4MotionMask (1L<<11)
Button5MotionMask (1L<<12)
ButtonMotionMask (1L<<13)
KeymapStateMask (1L<<14)
ExposureMask (1L<<15)
VisibilityChangeMask (1L<<16)
StructureNotifyMask (1L<<17)
ResizeRedirectMask (1L<<18)
SubstructureNotifyMask (1L<<19)
SubstructureRedirectMask (1L<<20)
FocusChangeMask (1L<<21)
PropertyChangeMask (1L<<22)
ColormapChangeMask (1L<<23)
OwnerGrabButtonMask (1L<<24)
#include "mlx/mlx.h" / int main(void) { void *mlx; void *win; / mlx = mlx_init(); win = mlx_new_window(mlx, 500, 500, "so_long"); mlx_loop(mlx); }
#include <stdio.h> #include <stdlib.h> #include "mlx/mlx.h" / #define KEY_ESC 53 #define KEY_W 13 #define KEY_S 1 #define PRESS_RED_BUTTON 17 / typedef struct s_param{ int x; int y; } t_param; / void param_init(t_param *pa) { pa->x = 3; pa->y = 4; } / int key_press(int keycode, t_param *pa) { if (keycode == KEY_W) pa->x++; else if (keycode == KEY_S) pa->x--; else if (keycode == KEY_ESC) exit(0); printf("x: %d\n", pa->x); return (0); } / int close(void) { exit(0); return (0); } / int main(void) { void *mlx; void *win; t_param pa; / param_init(&pa); mlx = mlx_init(); win = mlx_new_window(mlx, 500, 500, "key test"); printf("-------------------------------\n"); printf("Start x = 3\n"); mlx_key_hook(win, &key_press, &pa); mlx_hook(win, PRESS_RED_BUTTON, 0, &close, &pa); mlx_loop(mlx); }
#include <stdio.h> #include "mlx/mlx.h" / int main(void) { void *mlx; void *win; void *img; int img_width; int img_height; / mlx = mlx_init(); win = mlx_new_window(mlx, 500, 500, "putImage"); img = mlx_xpm_file_to_image(mlx, "img/mario.xpm", &img_width, &img_height); mlx_put_image_to_window(mlx, win, img, 50, 50); mlx_loop(mlx); return (0); }
#include <stdio.h> #include "mlx/mlx.h" / typedef struct s_param { void *mlx; void *win; void *c; int fd; int play_x; int play_y; int img_x; int img_y; int win_x; int win_y; } t_param; / # define UP_W 13 # define DOWN_S 1 # define LEFT_A 0 # define RIGHT_D 2 # define EXIT_ESC 53 # define EXIT_BUTTON 17 / int key_press(int keycode, t_param *p) { if (keycode == UP_W && p->play_y != 0) p->play_y -= p->img_y; if (keycode == DOWN_S && p->play_y != 480) p->play_y += p->img_y; else if (keycode == LEFT_A && p->play_x != 0) p->play_x -= p->img_x; else if (keycode == RIGHT_D && p->play_x != 480) p->play_x += p->img_x; else if (keycode == EXIT_ESC) exit(0); else if (keycode == EXIT_BUTTON) exit(0); printf("x: %d y : %d\n", p->play_x, p->play_y); return (0); } / int draw(t_param *p) { mlx_clear_window(p->mlx, p->win); mlx_put_image_to_window(p->mlx, p->win, p->c, p->play_x, p->play_y); return (0); } / int main(void) { t_param par; / par.mlx = mlx_init(); par.c = mlx_xpm_file_to_image(par.mlx, "img/mario.xpm", &par.img_x, &par.img_y); par.win = mlx_new_window(par.mlx, 1000, 1000, "DrawMap"); par.play_x = 0; par.play_y = 0; mlx_key_hook(par.win, &key_press, &par); mlx_loop_hook(par.mlx, &draw, &par); mlx_loop(par.mlx); return (0); }
void perror(const char *s);
사용자 메시지 + 오류 메시지를 출력한다.
전역 변수 errno 의 값을 해석하여 이에 해당하는 시스템 오류 메세지를 표준 오류 출력 스트림(stderr) 에 출력한다.
헤더 : stdio.h
매개변수
반환값
char *strerror(int errnum);
const offset =
[
[0, 1], // 상
[0, -1], // 하
[-1, 0] // 좌
[1, 0] // 우
]
void find_path(maps, visited, pos)
{
if (pos == [4, 4]) // 종료 조건
return ;
else
{
visited[pos] = true; // 현재 위치를 방문한 것으로 표시
stack.push(pos); // 현재 위치를 스택에 넣기
for (i = 0; i < 4; i++) // 상하좌우 이동 여부 탐색
{
next = pos + offset[i]; // 다음 좌표 저장
if (is_movable(maps, next) // 이동 가능 여부 판단
find_path(maps, visited, next); // 다음 경로로 이동
}
stack.pop(pos); // 탐색에 실패하면 스택에서 현재 위치 제거
}
}
📖 참고 📖 백트래킹 (backtracking)
- 개념
- 진행중인 경로가 아니면 더이상 경로를 가지 않고 되돌아가며 해를 찾는 과정
- 목적
- 불필요한 탐색을 줄이고, 올바른 쪽으로 동작
- 모든 가능한 경우의 수 중에서 특정한 조건을 만족하는 경우만 보기
#include <stdlib.h>
system("leaks a.out")
사용system("leaks a.out")
실행하는 함수)export MallocStackLogging=1
입력system("leaks --list -- a.out")
make -p
: 내부 매크로 확인make -r
: 내부 매크로 제거 # 매크로 정의
RM = rm -f # default. 생략 가능
CC = cc # default. 생략 가능
AR = ar # default. 생략 가능
CFLAGS = -Wall -Wextra -Werror
ARFLAGS = rsc
SRCS = main.c read.c write.c
OBJS = $(SRCS:.c=.o) # 치환 참조
NAME = test.a
# 타겟 정의
all: $(NAME)
$(NAME): $(OBJS)
$(AR) $(ARFLAGS) $@ $^
clean:
$(RM) $(OBJS)
fclean: clean
$(RM) $(NAME)
re: fclean
$(MAKE) all
.PHONY: all clean fclean re
CFLAGS
: C컴파일시 사용된 플래그 (ex. -Wall -Wextra -Werror)# 기본 값
CC = cc
CFLAGS = -Wall -Wextra -Werror
CPPFLAGS = -I.
TARGET_ARCH =
OUTPUT_OPTION = -o $@
COMPILE.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
%.o: %.c
$(COMPILE.c) $(OUTPUT_OPTION) $<
.c.o:
$(COMPILE.c) $(OUTPUT_OPTION) $<
ARFLAGS
: ar 실행 시 사용할 플래그 (ex. rcs)# 기본 값
AR = ar
ARFLAGS = rv
%.a:
(%) : %
$(AR) $(ARFLAGS) $@ $<
LDFLAGS
: 링커 ld를 호출할 때 사용될 플래그 (ex. -L./lift)LDLIBS
: 링커 ld를 호출할 때 사용될 플래그 또는 이름 (ex. -lft)CC = cc
LDFLAGS = -L.
TARGET_ARCH =
LDLIBS = -lft
LINK.o = $(CC) $(LDFLAGS) $(TARGET_ARCH)
%: %.o
$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
.o:
$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
make -f
: 한번의 make를 통해 2개 이상의 결과물 생성all: server client
server:
$(MAKE) -f Makefile.server
client:
$(MAKE) -f Makefile.client
make -C
: 하위 디렉토리의 Makefile 수행시 사용SERVER = server
CLIENT = client
all bonus clean fclean re:
$(MAKE) -C lib $@
$(MAKE) -C src $@
$(SERVER) $(CLIENT):
$(MAKE) -C lib
$(MAKE) -C src $@
.PHONY: all clean fclean re bonus
.DEFAULT_GOAL = all
CFLAGS = -Wall -Wextra -Werror -MMD -MP
CPPFLAGS = -I./include
LDFLAGS = -L./lib
LDLIBS = -lftprintf -lft
LIBFT = libft/libft.a
$(LIBFT):
$(MAKE) -C $(@D)
##################################################################
PUSHSWAP = push_swap
PUSHSWAP_SRCS = common.c push_swap.c
PUSHSWAP_OBJS = $(PUSHSWAP_SRCS:.c=.o)
PUSHSWAP_DEPS = $(PUSHSWAP_SRCS:.c=.d)
-include $(PUSHSWAP_DEPS)
$(PUSHSWAP): $(PUSHSWAP_OBJS)
$(PUSHSWAP_OBJS): $(LIBFT)
##################################################################
CHECKER = checker
CHECKER_SRCS = common.c checker.c
CHECKER_OBJS = $(CHECKER_SRCS:.c=.o)
CHECKER_DEPS = $(CHECKER_SRCS:.c=.d)
-include $(CHECKER_DEPS)
$(CHECKER): $(CHECKER_OBJS)
$(CHECKER_OBJS): $(LIBFT)
##################################################################
all:
$(MAKE) -C $(dir $(LIBFT))
$(MAKE) $(PUSHSWAP)
bonus:
$(MAKE) -C $(dir $(LIBFT))
$(MAKE) $(CHECKER)
clean:
$(MAKE) -C $(dir $(LIBFT)) clean
$(RM) $(wildcard *.o) $(wildcard *d)
fclean: clean
$(RM) $(LIBFT) $(PUSHSWAP) $(CHECKER)
re: fclean
$(MAKE) all
.PHONY: all clean fclean re bonus