-#include <stdio.h>
-#include <unistd.h>
#include <GL/glew.h>
#include <GL/gl.h>
#include <GLFW/glfw3.h>
+#include <stdio.h>
+#include <unistd.h>
#include "client/camera.h"
#include "client/client.h"
-#include "client/client_map.h"
+#include "client/client_entity.h"
+#include "client/client_inventory.h"
+#include "client/client_item.h"
#include "client/client_node.h"
#include "client/client_player.h"
+#include "client/client_terrain.h"
#include "client/debug_menu.h"
#include "client/font.h"
+#include "client/frustum.h"
+#include "client/game.h"
+#include "client/gl_debug.h"
#include "client/gui.h"
#include "client/input.h"
+#include "client/interact.h"
#include "client/sky.h"
#include "client/window.h"
-#include "day.h"
-#include "signal_handlers.h"
+#include "common/day.h"
+#include "common/interrupt.h"
+
+#ifdef _WIN32
+#include <pthread_time.h>
+#endif
+
+int game_fps = 0;
-static void crosshair_init()
+void game_render(f64 dtime)
{
- gui_add(&gui_root, (GUIElementDefinition) {
- .pos = {0.5f, 0.5f},
- .z_index = 0.0f,
- .offset = {0, 0},
- .margin = {0, 0},
- .align = {0.5f, 0.5f},
- .scale = {1.0f, 1.0f},
- .scale_type = GST_IMAGE,
- .affect_parent_scale = false,
- .text = NULL,
- .image = texture_get(RESSOURCEPATH "textures/crosshair.png"),
- .text_color = (v4f32) {0.0f, 0.0f, 0.0f, 0.0f},
- .bg_color = (v4f32) {0.0f, 0.0f, 0.0f, 0.0f},
- });
+ glEnable(GL_DEPTH_TEST); GL_DEBUG
+ glEnable(GL_BLEND); GL_DEBUG
+ glEnable(GL_MULTISAMPLE); GL_DEBUG
+ glEnable(GL_CULL_FACE); GL_DEBUG
+
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); GL_DEBUG
+ glCullFace(GL_BACK); GL_DEBUG
+ glFrontFace(GL_CCW); GL_DEBUG
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); GL_DEBUG
+
+ frustum_update();
+ terrain_gfx_update();
+ client_entity_gfx_update();
+ client_inventory_update();
+
+ sky_render();
+ model_scene_render(dtime);
+ interact_render();
+ gui_render();
}
-static void game_loop(Client *client)
+static void game_loop()
{
f64 fps_update_timer = 1.0f;
- int frames = 0;
+ unsigned int frames = 0;
struct timespec ts, ts_old;
clock_gettime(CLOCK_REALTIME, &ts_old);
- while (! glfwWindowShouldClose(window.handle) && client->state != CS_DISCONNECTED && ! interrupted) {
+ while (!glfwWindowShouldClose(window.handle) && !interrupt.set) {
clock_gettime(CLOCK_REALTIME, &ts);
f64 dtime = (f64) (ts.tv_sec - ts_old.tv_sec) + (f64) (ts.tv_nsec - ts_old.tv_nsec) / 1.0e9;
ts_old = ts;
if ((fps_update_timer -= dtime) <= 0.0) {
- debug_menu_update_fps(frames);
+ debug_menu_changed(ENTRY_FPS);
+ game_fps = frames;
fps_update_timer += 1.0;
frames = 0;
}
frames++;
- debug_menu_update_time();
- debug_menu_update_daylight();
- debug_menu_update_sun_angle();
-
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_ALPHA_TEST);
- glEnable(GL_BLEND);
- glEnable(GL_MULTISAMPLE);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glAlphaFunc(GL_GREATER, 0.0f);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- input_tick();
+ input_tick(dtime);
client_player_tick(dtime);
+ interact_tick();
+
+ debug_menu_changed(ENTRY_TIME);
+ debug_menu_changed(ENTRY_DAYLIGHT);
+ debug_menu_changed(ENTRY_SUN_ANGLE);
+ debug_menu_update();
- scene_render();
- sky_render();
- gui_render();
+ game_render(dtime);
glfwSwapBuffers(window.handle);
glfwPollEvents();
}
}
-bool game(Client *client)
+void game(Flag *gfx_init)
{
- int width, height;
- width = 1250;
- height = 750;
-
- if (! window_init(width, height))
- return false;
-
- if (! font_init())
- return false;
-
- if (! scene_init())
- return false;
-
- scene_on_resize(width, height);
-
- if (! sky_init())
- return false;
-
+ window_init();
+ font_init();
+ model_init();
+ sky_init();
+ terrain_gfx_init();
+ client_entity_gfx_init();
+ client_player_gfx_init();
+ camera_init();
+ gui_init();
+ interact_init();
+ client_item_init();
+ client_inventory_init();
client_node_init();
- client_map_start();
-
- camera_set_position((v3f32) {0.0f, 0.0f, 0.0f});
- camera_set_angle(0.0f, 0.0f);
-
- if (! gui_init())
- return false;
-
- gui_on_resize(width, height);
-
+ client_terrain_start();
debug_menu_init();
- debug_menu_toggle();
- debug_menu_update_fps(0);
- debug_menu_update_version();
- debug_menu_update_seed();
- debug_menu_update_flight();
- debug_menu_update_collision();
- debug_menu_update_timelapse();
- debug_menu_update_fullscreen();
- debug_menu_update_opengl();
- debug_menu_update_gpu();
-
- crosshair_init();
-
input_init();
- client_player_add_to_scene();
-
- game_loop(client);
-
- client_map_stop();
+ flag_set(gfx_init);
+ game_loop();
+ client_terrain_stop();
font_deinit();
gui_deinit();
- scene_deinit();
+ model_deinit();
sky_deinit();
-
- return true;
+ terrain_gfx_deinit();
+ client_entity_gfx_deinit();
+ client_player_gfx_deinit();
+ interact_deinit();
+ client_item_deinit();
+ client_inventory_deinit();
}
+