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
|
#include <allegro5/allegro.h>
#include <allegro5/allegro_native_dialog.h>
#include <windows.h>
#include <winsock2.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "buffer.h"
#include "graph.h"
#include "graph_data.h"
#include "net_utils.h"
#include "init.h"
#include "cmd.h"
#include "free_all.h"
#include "init_graph.h"
#include "rendering.h"
int check_events(void)
{
static int run;
run += 1;
if (run == 10000)
return (0);
return (1);
}
int main_loop(t_env *env, t_mynet *net)
{
char *cmd;
int run;
run = 1;
while (run)
{
if ((cmd = receive_cmd(net)) != NULL)
interp_cmd(net, env, cmd);
if (env->map_width > 0 && env->map_height > 0)
rendering_loop(env);
run = check_events();
}
free_env(env);
return (EXIT_SUCCESS);
}
int begin_exchange(t_env *env, t_mynet *net)
{
int begin_time;
int cur_time;
char *begin_str;
begin_time = time(NULL);
cur_time = begin_time;
while ((begin_str = receive_cmd(net)) == NULL
&& (cur_time - begin_time) < 20)
{
Sleep(2);
cur_time = time(NULL);
}
if (begin_str == NULL)
return (EXIT_FAILURE);
if (strcmp(begin_str, "BIENVENUE"))
return (EXIT_FAILURE);
write_buffer(net->write_buf, "GRAPHIC\n", 8);
send_buffer(net->socket, &(net->write_buf));
return (EXIT_SUCCESS);
}
int main(void)
{
t_env env;
t_mynet net;
if (init_net(&net, "192.168.254.42", 4242) == EXIT_FAILURE)
return (EXIT_FAILURE);
init_env(&env);
if (begin_exchange(&env, &net) == EXIT_FAILURE)
return (EXIT_FAILURE);
if (init_graph(&env) == EXIT_FAILURE)
return (EXIT_FAILURE);
main_loop(&env, &net);
return (EXIT_SUCCESS);
} |
Partager