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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
|
#include <string.h>
#include <engine/e_client_interface.h>
extern "C" {
#include <engine/client/ec_font.h>
};
#include <game/generated/gc_data.hpp>
#include <game/gamecore.hpp>
#include <game/version.hpp>
#include <game/layers.hpp>
#include "gameclient.hpp"
#include "components/skins.hpp"
#include "gc_client.hpp"
#include "gc_render.hpp"
#include "gc_map_image.hpp"
extern unsigned char internal_data[];
extern void menu_init();
extern bool menu_active;
extern bool menu_game_active;
static float load_total;
static float load_current;
extern "C" void modc_console_init()
{
//client_console_init();
}
//binds_save()
static void load_sounds_thread(void *do_render)
{
// load sounds
for(int s = 0; s < data->num_sounds; s++)
{
//if(do_render) // TODO: repair me
//render_loading(load_current/load_total);
for(int i = 0; i < data->sounds[s].num_sounds; i++)
{
int id = snd_load_wv(data->sounds[s].sounds[i].filename);
data->sounds[s].sounds[i].id = id;
}
if(do_render)
load_current++;
}
}
extern "C" void modc_init()
{
for(int i = 0; i < NUM_NETOBJTYPES; i++)
snap_set_staticsize(i, netobj_get_size(i));
gameclient.on_init();
static FONT_SET default_font;
int64 start = time_get();
int before = gfx_memory_usage();
font_set_load(&default_font, "data/fonts/default_font%d.tfnt", "data/fonts/default_font%d.png", "data/fonts/default_font%d_b.png", 14, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 36);
dbg_msg("font", "gfx memory used for font textures: %d", gfx_memory_usage()-before);
gfx_text_set_default_font(&default_font);
//particle_reset();
//menu_init();
// setup sound channels
snd_set_channel(CHN_GUI, 1.0f, 0.0f);
snd_set_channel(CHN_MUSIC, 1.0f, 0.0f);
snd_set_channel(CHN_WORLD, 0.9f, 1.0f);
snd_set_channel(CHN_GLOBAL, 1.0f, 0.0f);
// load the data container
//data = load_data_from_memory(internal_data);
// TODO: should be removed
snd_set_listener_pos(0.0f, 0.0f);
// setup load amount
load_total = data->num_images;
load_current = 0;
if(!config.cl_threadsoundloading)
load_total += data->num_sounds;
// load textures
for(int i = 0; i < data->num_images; i++)
{
// TODO: repair me
//render_loading(load_current/load_total);
data->images[i].id = gfx_load_texture(data->images[i].filename, IMG_AUTO, 0);
load_current++;
}
gameclient.skins->init();
//skin_init();
if(config.cl_threadsoundloading)
thread_create(load_sounds_thread, 0);
else
load_sounds_thread((void*)1);
int64 end = time_get();
dbg_msg("", "%f.2ms", ((end-start)*1000)/(float)time_freq());
}
extern "C" void modc_save_config()
{
//binds_save();
}
CHARACTER_CORE predicted_prev_char;
CHARACTER_CORE predicted_char;
extern "C" void modc_entergame() {}
extern "C" void modc_shutdown() {}
extern "C" void modc_predict() { gameclient.on_predict(); }
extern "C" void modc_newsnapshot() { gameclient.on_snapshot(); }
extern "C" int modc_snap_input(int *data) { return gameclient.on_snapinput(data); }
extern "C" void modc_statechange(int state, int old) { gameclient.on_statechange(state, old); }
extern "C" void modc_render() { gameclient.on_render(); }
extern "C" void modc_rcon_line(const char *line)
{
//console_rcon_print(line);
}
/*
NETOBJ_PROJECTILE extraproj_projectiles[MAX_EXTRA_PROJECTILES];
int extraproj_num;
void extraproj_reset()
{
extraproj_num = 0;
}*/
extern "C" void modc_message(int msgtype)
{
// special messages
if(msgtype == NETMSGTYPE_SV_EXTRAPROJECTILE)
{
/*
int num = msg_unpack_int();
for(int k = 0; k < num; k++)
{
NETOBJ_PROJECTILE proj;
for(unsigned i = 0; i < sizeof(NETOBJ_PROJECTILE)/sizeof(int); i++)
((int *)&proj)[i] = msg_unpack_int();
if(msg_unpack_error())
return;
if(extraproj_num != MAX_EXTRA_PROJECTILES)
{
extraproj_projectiles[extraproj_num] = proj;
extraproj_num++;
}
}
return;*/
}
else if(msgtype == NETMSGTYPE_SV_TUNEPARAMS)
{
// unpack the new tuning
TUNING_PARAMS new_tuning;
int *params = (int *)&new_tuning;
for(unsigned i = 0; i < sizeof(TUNING_PARAMS)/sizeof(int); i++)
params[i] = msg_unpack_int();
// check for unpacking errors
if(msg_unpack_error())
return;
// apply new tuning
tuning = new_tuning;
return;
}
gameclient.on_message(msgtype);
#if 0
// normal
void *rawmsg = netmsg_secure_unpack(msgtype);
if(!rawmsg)
{
dbg_msg("client", "dropped weird message '%s' (%d), failed on '%s'", netmsg_get_name(msgtype), msgtype, netmsg_failed_on());
return;
}
if(msgtype == NETMSGTYPE_SV_CHAT)
{
}
else if(msgtype == NETMSGTYPE_SV_BROADCAST)
{
/*
NETMSG_SV_BROADCAST *msg = (NETMSG_SV_BROADCAST *)rawmsg;
str_copy(broadcast_text, msg->message, sizeof(broadcast_text));
broadcast_time = time_get()+time_freq()*10;
*/
}
else if(msgtype == NETMSGTYPE_SV_MOTD)
{
/*
NETMSG_SV_MOTD *msg = (NETMSG_SV_MOTD *)rawmsg;
// process escaping
str_copy(server_motd, msg->message, sizeof(server_motd));
for(int i = 0; server_motd[i]; i++)
{
if(server_motd[i] == '\\')
{
if(server_motd[i+1] == 'n')
{
server_motd[i] = ' ';
server_motd[i+1] = '\n';
i++;
}
}
}
if(server_motd[0] && config.cl_motd_time)
server_motd_time = time_get()+time_freq()*config.cl_motd_time;
else
server_motd_time = 0;
*/
}
else if(msgtype == NETMSGTYPE_SV_SETINFO)
{
dbg_msg("DEBUG", "got info");
NETMSG_SV_SETINFO *msg = (NETMSG_SV_SETINFO *)rawmsg;
str_copy(gameclient.clients[msg->cid].name, msg->name, 64);
str_copy(gameclient.clients[msg->cid].skin_name, msg->skin, 64);
// make sure that we don't set a special skin on the client
if(gameclient.clients[msg->cid].skin_name[0] == 'x' || gameclient.clients[msg->cid].skin_name[1] == '_')
str_copy(gameclient.clients[msg->cid].skin_name, "default", 64);
gameclient.clients[msg->cid].skin_info.color_body = gameclient.skins->get_color(msg->color_body);
gameclient.clients[msg->cid].skin_info.color_feet = gameclient.skins->get_color(msg->color_feet);
gameclient.clients[msg->cid].skin_info.size = 64;
// find new skin
gameclient.clients[msg->cid].skin_id = gameclient.skins->find(gameclient.clients[msg->cid].skin_name);
if(gameclient.clients[msg->cid].skin_id < 0)
gameclient.clients[msg->cid].skin_id = 0;
if(msg->use_custom_color)
gameclient.clients[msg->cid].skin_info.texture = gameclient.skins->get(gameclient.clients[msg->cid].skin_id)->color_texture;
else
{
gameclient.clients[msg->cid].skin_info.texture = gameclient.skins->get(gameclient.clients[msg->cid].skin_id)->org_texture;
gameclient.clients[msg->cid].skin_info.color_body = vec4(1,1,1,1);
gameclient.clients[msg->cid].skin_info.color_feet = vec4(1,1,1,1);
}
gameclient.clients[msg->cid].update_render_info();
}
else if(msgtype == NETMSGTYPE_SV_WEAPONPICKUP)
{
// TODO: repair me
/*NETMSG_SV_WEAPONPICKUP *msg = (NETMSG_SV_WEAPONPICKUP *)rawmsg;
if(config.cl_autoswitch_weapons)
input_data.wanted_weapon = msg->weapon+1;*/
}
else if(msgtype == NETMSGTYPE_SV_READYTOENTER)
{
client_entergame();
}
else if(msgtype == NETMSGTYPE_SV_KILLMSG)
{
/*
NETMSG_SV_KILLMSG *msg = (NETMSG_SV_KILLMSG *)rawmsg;
gameclient.killmsgs.handle_message((NETMSG_SV_KILLMSG *)rawmsg);
// unpack messages
KILLMSG kill;
kill.killer = msg->killer;
kill.victim = msg->victim;
kill.weapon = msg->weapon;
kill.mode_special = msg->mode_special;
kill.tick = client_tick();
// add the message
killmsg_current = (killmsg_current+1)%killmsg_max;
killmsgs[killmsg_current] = kill;*/
}
else if (msgtype == NETMSGTYPE_SV_EMOTICON)
{
NETMSG_SV_EMOTICON *msg = (NETMSG_SV_EMOTICON *)rawmsg;
// apply
gameclient.clients[msg->cid].emoticon = msg->emoticon;
gameclient.clients[msg->cid].emoticon_start = client_tick();
}
else if(msgtype == NETMSGTYPE_SV_SOUNDGLOBAL)
{
NETMSG_SV_SOUNDGLOBAL *msg = (NETMSG_SV_SOUNDGLOBAL *)rawmsg;
snd_play_random(CHN_GLOBAL, msg->soundid, 1.0f, vec2(0,0));
}
#endif
}
extern "C" void modc_connected()
{
// init some stuff
layers_init();
col_init();
img_init();
//flow_init();
render_tilemap_generate_skip();
gameclient.on_connected();
//tilemap_init();
//particle_reset();
//extraproj_reset();
//last_new_predicted_tick = -1;
}
extern "C" const char *modc_net_version() { return GAME_NETVERSION; }
extern "C" const char *modc_getitemname(int type) { return netobj_get_name(type); }
|