-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.c
124 lines (107 loc) · 2.69 KB
/
client.c
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include "common.h"
#include "client.h"
#include "map.h"
#include "network.h"
void client_net_block_set(map_t *map, s32 x, s32 y, tile_t tile)
{
printf("client_net_block_set: %d,%d\n", x, y);
if(net_player.sockfd != FD_LOCAL_IMMEDIATE)
{
net_pack(NULL, PKT_BLOCK_SET,
x, y,
tile.type, tile.col, tile.chr);
} else {
map_set_tile(map, x, y, tile);
}
}
void client_net_block_push(map_t *map, s32 x, s32 y, tile_t tile)
{
printf("client_net_block_push: %d,%d\n", x, y);
if(net_player.sockfd != FD_LOCAL_IMMEDIATE)
{
net_pack(NULL, PKT_BLOCK_PUSH,
x, y,
tile.type, tile.col, tile.chr);
} else {
map_push_tile(map, x, y, tile);
}
}
void client_net_block_pop(map_t *map, s32 x, s32 y)
{
printf("client_net_block_pop: %d,%d\n", x, y);
if(net_player.sockfd != FD_LOCAL_IMMEDIATE)
{
net_pack(NULL, PKT_BLOCK_POP,
x, y);
} else {
map_pop_tile(map, x, y);
}
}
void client_load_chunk(map_t *map, s32 x, s32 y)
{
s32 px = divneg(x,LAYER_WIDTH);
s32 py = divneg(y,LAYER_HEIGHT);
if(!map_get_existing_layer(map, px,py))
map_get_net_layer(map, px,py);
}
void client_set_tile(map_t *map, s32 x, s32 y, tile_t tile)
{
client_load_chunk(map, x, y);
client_net_block_set(map, x, y, tile);
}
void client_set_tile_ext(map_t *map, s32 x, s32 y, u8 uidx, tile_t tile, int sendflag)
{
client_load_chunk(map, x, y);
if(sendflag)
/* TODO! */;
else
map_set_tile_ext(map, x, y, uidx, tile);
}
void client_alloc_tile_data(map_t *map, s32 x, s32 y, u8 uidx, u16 datalen, int sendflag)
{
client_load_chunk(map, x, y);
if(sendflag)
/* TODO! */;
else
map_alloc_tile_data(map, x, y, uidx, datalen);
}
void client_set_tile_data(map_t *map, s32 x, s32 y, u8 uidx, u8 datalen, u16 datapos, u8 *data, int sendflag)
{
client_load_chunk(map, x, y);
if(sendflag)
/* TODO! */;
else
map_set_tile_data(map, x, y, uidx, datalen, datapos, data);
}
tile_t client_get_tile(map_t *map, s32 x, s32 y)
{
client_load_chunk(map, x, y);
return map_get_tile(map, x, y);
}
void client_push_tile(map_t *map, s32 x, s32 y, tile_t tile)
{
client_load_chunk(map, x, y);
client_net_block_push(map, x, y, tile);
}
void client_pop_tile(map_t *map, s32 x, s32 y)
{
client_load_chunk(map, x, y);
client_net_block_pop(map, x, y);
}
u8 client_get_next_update(map_t *map, int *lidx, s32 *x, s32 *y)
{
return map_get_next_update(map, lidx, x, y);
}
void client_set_update(map_t *map, s32 x, s32 y, u8 tonew)
{
client_load_chunk(map, x, y);
map_set_update(map, x,y, tonew);
}
void client_set_update_n(map_t *map, s32 x, s32 y, u8 tonew)
{
client_set_update(map,x,y,tonew);
client_set_update(map,x-1,y,tonew);
client_set_update(map,x+1,y,tonew);
client_set_update(map,x,y-1,tonew);
client_set_update(map,x,y+1,tonew);
}