better
This commit is contained in:
parent
9dd2e6acd6
commit
6b4602a984
5 changed files with 42 additions and 13 deletions
12
client/gl.c
12
client/gl.c
|
|
@ -9,8 +9,8 @@ double gl_cam_z;
|
|||
int gl_scene = AF_SCENE_MAIN;
|
||||
|
||||
gl_scene_t gl_scenes[] = {
|
||||
{gl_main_changed, gl_main_init, gl_main_draw}, /**/
|
||||
{gl_connecting_changed, gl_connecting_init, gl_connecting_draw} /**/
|
||||
{gl_main_changed, gl_main_init, gl_main_draw}, /**/
|
||||
{NULL, NULL, NULL} /**/
|
||||
};
|
||||
|
||||
void gl_resize(int width, int height) {
|
||||
|
|
@ -31,7 +31,7 @@ void gl_init(void) {
|
|||
void gl_render(void) {
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
gl_scenes[gl_scene].init();
|
||||
if(gl_scenes[gl_scene].init != NULL) gl_scenes[gl_scene].init();
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
|
|
@ -41,5 +41,9 @@ void gl_render(void) {
|
|||
glLoadIdentity();
|
||||
gluLookAt(gl_cam_x, gl_cam_y, gl_cam_z, gl_cam_x + cos(gl_cam_lr / 180.0 * M_PI), gl_cam_y + sin(gl_cam_ud / 180.0 * M_PI), gl_cam_z + sin(gl_cam_lr / 180.0 * M_PI), 0, 1, 0);
|
||||
|
||||
gl_scenes[gl_scene].draw();
|
||||
if(gl_scenes[gl_scene].draw != NULL) gl_scenes[gl_scene].draw();
|
||||
}
|
||||
|
||||
void gl_scene_change(void) {
|
||||
if(gl_scenes[gl_scene].changed != NULL) gl_scenes[gl_scene].changed();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,8 +36,8 @@ static void* gl_load(const char* name) {
|
|||
void scene_change(int scene) {
|
||||
gl_scene = scene;
|
||||
|
||||
gl_scenes[gl_scene].changed();
|
||||
ui_scene();
|
||||
gl_scene_change();
|
||||
ui_scene_change();
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
|
|
|||
29
client/net.c
Normal file
29
client/net.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#include <af_common.h>
|
||||
|
||||
static fishsoup_client_t* client = NULL;
|
||||
|
||||
static void net_return(MwWidget handle, void* user, void* client) {
|
||||
scene_change(AF_SCENE_MAIN);
|
||||
}
|
||||
|
||||
void net_connect(const char* username, const char* hostname, int port) {
|
||||
scene_change(AF_SCENE_CONNECTING);
|
||||
client = fishsoup_client(hostname, port == 0 ? AF_DEFAULT_PORT : port);
|
||||
if(client == NULL) {
|
||||
MwAddUserHandler(ui_message("Failed to connect"), MwNactivateHandler, net_return, NULL);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void net_poll(void) {
|
||||
int ret;
|
||||
if(client == NULL) return;
|
||||
|
||||
while((ret = fishsoup_client_poll(client)) > 0);
|
||||
if(ret < 0) {
|
||||
MwAddUserHandler(ui_message("Connection destroyed"), MwNactivateHandler, net_return, NULL);
|
||||
fishsoup_client_destroy(client);
|
||||
client = NULL;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -114,7 +114,7 @@ MwWidget ui_message(const char* message) {
|
|||
return wnd;
|
||||
}
|
||||
|
||||
void ui_scene(void) {
|
||||
void ui_scene_change(void) {
|
||||
if(gl_scene == AF_SCENE_MAIN) {
|
||||
ui_login();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ extern double gl_cam_z;
|
|||
void gl_init(void);
|
||||
void gl_render(void);
|
||||
void gl_resize(int width, int height);
|
||||
void gl_scene_change(void);
|
||||
|
||||
/* gl_font.c */
|
||||
void gl_font_init(void);
|
||||
|
|
@ -49,11 +50,6 @@ void gl_main_changed(void);
|
|||
void gl_main_init(void);
|
||||
void gl_main_draw(void);
|
||||
|
||||
/* gl_connecting.c */
|
||||
void gl_connecting_changed(void);
|
||||
void gl_connecting_init(void);
|
||||
void gl_connecting_draw(void);
|
||||
|
||||
/* net.c */
|
||||
void net_connect(const char* username, const char* hostname, int port);
|
||||
void net_poll(void);
|
||||
|
|
@ -62,7 +58,7 @@ void net_poll(void);
|
|||
MwWidget ui_notice(int width, int height);
|
||||
void ui_notice_destroy(MwWidget widget);
|
||||
void ui_init(void);
|
||||
void ui_scene(void);
|
||||
void ui_scene_change(void);
|
||||
MwWidget ui_message(const char* message);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue