-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboard.h
88 lines (66 loc) · 1.65 KB
/
board.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#ifndef BOARD_H_INCLUDED
#define BOARD_H_INCLUDED
#include <stdio.h>
#include <sys/types.h>
typedef enum Instruction_code
{
INSTRUCTION_NOP,
INSTRUCTION_DESTROY,
INSTRUCTION_ADD_CELL,
INSTRUCTION_WRITE_SCANLINE,
INSTRUCTION_READ_SCANLINE,
INSTRUCTION_UPDATE_INNER_BORDERS,
INSTRUCTION_UPDATE_OUTER_BORDERS,
INSTRUCTION_CALCULATE,
INSTRUCTION_CLEAR
} Instruction_code;
enum
{
CHUNK_NUM_ANY = 0xFFFFFFFF
};
typedef struct Instruction
{
Instruction_code id;
unsigned chunk_num_x;
unsigned chunk_num_y;
unsigned param1;
unsigned param2;
} Instruction;
typedef struct Border_ids
{
int top;
int left;
int right;
int bottom;
//shared memory for communication with father
//it can be top, bottom, or, if field consists of 1 chunk, special area
int special;
} Border_ids;
typedef struct Board
{
pid_t **chunks;
Border_ids ***border_ids;
char ***special_pointers;
unsigned width;
unsigned height;
unsigned chunks_count;
unsigned chunks_hor_count;
unsigned chunks_ver_count;
unsigned chunk_size;
unsigned last_width;
unsigned last_height;
unsigned long long generation_num;
int sem_id;
int shm_id;
Instruction *cur_instruction;
} Board;
Board *board_create(unsigned, unsigned, unsigned);
void board_destroy(Board *);
bool board_add_cell(Board *, unsigned, unsigned);
void board_next_turn(Board *);
void board_clear(Board *);
char *board_get_scanline(Board *, unsigned);
bool board_set_scanline(Board *, unsigned, char *);
bool board_load_from_file(Board *, FILE *);
bool board_save_to_file(Board *, FILE *);
#endif //BOARD_H_INCLUDED