-
Notifications
You must be signed in to change notification settings - Fork 8
Split main #247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nsg
wants to merge
10
commits into
master
Choose a base branch
from
split-main
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Split main #247
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ac9ae2a
Move Konstructs class to konstructs.cpp/h.
nsg ee5594f
More refactoring.
nsg a199b22
Actually update the settings settings struct.
nsg 2d27abd
Got tired of all warnings from nano/eigen.
nsg 71fa306
Use new GUI class, grey screen.
nsg 088d199
Load more of the old program.
nsg a266672
Main menu is back (no interactions)
nsg 24a5072
Menu interaction works.
nsg 95de612
Better manage connection and the login UI.
nsg 30c6bdc
Move over mouseButtonEvent to GUI.
nsg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| #ifndef KONSTRUCTS_CLI_H | ||
| #define KONSTRUCTS_CLI_H | ||
|
|
||
| #include "settings.h" | ||
|
|
||
| namespace konstructs { | ||
|
|
||
| /** | ||
| * This class contains cli logic | ||
| */ | ||
| class Cli { | ||
|
|
||
| public: | ||
|
|
||
| /** | ||
| * Print the cli command line options to stdout | ||
| */ | ||
| static void print_usage(); | ||
|
|
||
| /** | ||
| * Simple argument parser that updates the settings struct | ||
| * @param argc From main() | ||
| * @param argv From main() | ||
| * @param settings The settings object to update | ||
| */ | ||
| static void argument_parser(int argc, char **argv, Settings *settings); | ||
| }; | ||
|
|
||
| } | ||
|
|
||
|
|
||
| #endif //KONSTRUCTS_CLI_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| #ifndef KONSTRUCTS_GUI_H | ||
| #define KONSTRUCTS_GUI_H | ||
|
|
||
| #pragma GCC diagnostic push | ||
| #pragma GCC diagnostic ignored "-Wignored-attributes" | ||
| #include <nanogui/nanogui.h> | ||
| #pragma GCC diagnostic pop | ||
|
|
||
| #include "settings.h" | ||
| #include "konstructs.h" | ||
|
|
||
| using Eigen::Vector2i; | ||
| using Eigen::Vector2f; | ||
| using nanogui::Screen; | ||
|
|
||
| #define KONSTRUCTS_GUI_MENU_NORMAL 0 | ||
| #define KONSTRUCTS_GUI_MENU_POPUP 1 | ||
| #define KONSTRUCTS_GUI_MENU_RECONNECT 2 | ||
|
|
||
| namespace konstructs { | ||
|
|
||
| class GUI: public nanogui::Screen { | ||
| public: | ||
| GUI(Settings settings); | ||
|
|
||
| /** | ||
| * Called by GLFW when the mouse scroll wheel is used. | ||
| */ | ||
| virtual bool scrollEvent(const Vector2i &p, const Vector2f &rel); | ||
|
|
||
| /** | ||
| * Called by GLFW when a mouse button is pressed | ||
| */ | ||
| virtual bool mouseButtonEvent(const Vector2i &p, int button, bool down, int modifiers); | ||
|
|
||
| /** | ||
| * Called by GLEW when a keyboard button is pressed | ||
| */ | ||
| virtual bool keyboardEvent(int key, int scancode, int action, int modifiers); | ||
|
|
||
| virtual void draw(NVGcontext *ctx); | ||
| virtual void drawContents(); | ||
|
|
||
| private: | ||
|
|
||
| /** | ||
| * Display the main menu | ||
| * @param state KONSTRUCTS_GUI_MENU_NORMAL = No extra popups | ||
| * KONSTRUCTS_GUI_MENU_POPUP = A popup message | ||
| * KONSTRUCTS_GUI_MENU_RECONNECT = Server connection retry dialog | ||
| * @param message A message to be displayed | ||
| */ | ||
| void show_menu(int state, string message); | ||
|
|
||
| /** | ||
| * Holds various konstructs data like for example shaders | ||
| * and the chunk processing facility. This is mainly here | ||
| * for legacy reasons and may be removed in the future. | ||
| */ | ||
| Konstructs konstructs_data; | ||
|
|
||
| /** | ||
| * Show or hide the mouse pointer. | ||
| * @param state Mouse pointer state | ||
| */ | ||
| void show_pointer(bool state); | ||
|
|
||
| /** | ||
| * Connect to the server, this is a convenience method wrapping | ||
| * network.setup_connection(..). | ||
| */ | ||
| bool connect(); | ||
|
|
||
| /** | ||
| * Translate GLFW mouse button presses to 1 to 3 | ||
| * @param button The GLFW mouse button ID | ||
| */ | ||
| int translate_button(int button); | ||
|
|
||
| bool menu_state; | ||
| Settings settings; | ||
| Network network; | ||
| nanogui::Window *window; | ||
| }; | ||
| } | ||
|
|
||
|
|
||
| #endif //KONSTRUCTS_GUI_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| #ifndef KONSTRUCTS_KONSTRUCTS_H | ||
| #define KONSTRUCTS_KONSTRUCTS_H | ||
|
|
||
| #pragma GCC diagnostic push | ||
| #pragma GCC diagnostic ignored "-Wignored-attributes" | ||
| #include <nanogui/nanogui.h> | ||
| #pragma GCC diagnostic pop | ||
|
|
||
| #if defined(WIN32) | ||
| #define _WINSOCKAPI_ | ||
| #include <windows.h> | ||
| #include <winsock2.h> | ||
| #else | ||
| #include <arpa/inet.h> | ||
| #endif | ||
| #include <nanogui/glutil.h> | ||
| #include <iostream> | ||
| #include <iomanip> | ||
| #include <memory> | ||
| #include "tiny_obj_loader.h" | ||
| #include "optional.hpp" | ||
| #include "matrix.h" | ||
| #include "shader.h" | ||
| #include "crosshair_shader.h" | ||
| #include "block.h" | ||
| #include "chunk.h" | ||
| #include "world.h" | ||
| #include "chunk_shader.h" | ||
| #include "sky_shader.h" | ||
| #include "selection_shader.h" | ||
| #include "hud.h" | ||
| #include "hud_shader.h" | ||
| #include "player_shader.h" | ||
| #include "textures.h" | ||
| #include "util.h" | ||
| #include "settings.h" | ||
| #include "network.h" | ||
|
|
||
| #define KONSTRUCTS_APP_TITLE "Konstructs" | ||
| #define MOUSE_CLICK_DELAY_IN_FRAMES 15 | ||
|
|
||
| namespace konstructs { | ||
| class Konstructs: public nanogui::Screen { | ||
| public: | ||
|
|
||
| Konstructs(Settings settings); | ||
| ~Konstructs(); | ||
|
|
||
| /** | ||
| * Called by GLFW when the mouse scroll wheel is used. | ||
| */ | ||
| virtual bool scrollEvent(const Vector2i &p, const Vector2f &rel); | ||
|
|
||
| /** | ||
| * Called by GLFW when a mouse button is pressed | ||
| */ | ||
| virtual bool mouseButtonEvent(const Vector2i &p, int button, bool down, int modifiers); | ||
|
|
||
| /** | ||
| * Called by GLEW when a keyboard button is pressed | ||
| */ | ||
| virtual bool keyboardEvent(int key, int scancode, int action, int modifiers); | ||
|
|
||
| virtual void draw(NVGcontext *ctx); | ||
| virtual void drawContents(); | ||
|
|
||
| // Members that are called from gui.cpp | ||
| Hud hud; | ||
| HudShader hud_shader; | ||
|
|
||
| private: | ||
|
|
||
| /** This function uses nanovg to print text on top of the screen. This is | ||
| * used for both the debug screen and messages sent from the server. | ||
| */ | ||
| void print_top_text(); | ||
|
|
||
| /** | ||
| * Update view distance variable dependent on your framerate. | ||
| */ | ||
| bool update_view_distance(); | ||
|
|
||
| /** | ||
| * If view distance has updated, set a new view radius. | ||
| */ | ||
| void update_radius(); | ||
|
|
||
| /** | ||
| * Manage the mouse pointer. | ||
| */ | ||
| void handle_mouse(); | ||
|
|
||
| /** | ||
| * Manage the keyboard. | ||
| */ | ||
| void handle_keys(); | ||
|
|
||
| /** | ||
| * Close the hud and send a message to the server. | ||
| */ | ||
| void close_hud(); | ||
|
|
||
| /** | ||
| * Returns the time of day | ||
| */ | ||
| float time_of_day(); | ||
|
|
||
| /** | ||
| * TODO: What do this? | ||
| */ | ||
| float daylight(); | ||
|
|
||
| /** | ||
| * Open and display the nanogui main menu | ||
| */ | ||
| void show_menu(int state, string message); | ||
|
|
||
| BlockTypeInfo blocks; | ||
| CrosshairShader crosshair_shader; | ||
| int radius; | ||
| float view_distance; | ||
| float near_distance; | ||
| int day_length; | ||
| World world; | ||
| SkyShader sky_shader; | ||
| ChunkShader chunk_shader; | ||
| SelectionShader selection_shader; | ||
| PlayerShader *player_shader; | ||
| ChunkModelFactory model_factory; | ||
| Player player; | ||
| Vector3i player_chunk; | ||
| optional<pair<konstructs::Block, konstructs::Block>> looking_at; | ||
| double px; | ||
| double py; | ||
| FPS fps; | ||
| double last_frame; | ||
| bool debug_text_enabled; | ||
| nanogui::Window *window; | ||
| uint32_t frame; | ||
| uint32_t faces; | ||
| uint32_t max_faces; | ||
| double frame_time; | ||
| uint32_t click_delay; | ||
| Settings settings; | ||
| Network network; | ||
| }; | ||
| }; | ||
|
|
||
| #endif //KONSTRUCTS_KONSTRUCTS_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| #ifndef KONSTRUCTS_NETWORK_H | ||
| #define KONSTRUCTS_NETWORK_H | ||
|
|
||
| #if defined(WIN32) | ||
| #define _WINSOCKAPI_ | ||
| #include <windows.h> | ||
| #include <winsock2.h> | ||
| #else | ||
| #include <arpa/inet.h> | ||
| #endif | ||
| #include <nanogui/glutil.h> | ||
| #include <iostream> | ||
| #include <iomanip> | ||
| #include <memory> | ||
| #include "tiny_obj_loader.h" | ||
| #include "optional.hpp" | ||
| #include "matrix.h" | ||
| #include "shader.h" | ||
| #include "crosshair_shader.h" | ||
| #include "block.h" | ||
| #include "chunk.h" | ||
| #include "world.h" | ||
| #include "client.h" | ||
| #include "chunk_shader.h" | ||
| #include "sky_shader.h" | ||
| #include "selection_shader.h" | ||
| #include "hud.h" | ||
| #include "hud_shader.h" | ||
| #include "player_shader.h" | ||
| #include "textures.h" | ||
| #include "util.h" | ||
| #include "settings.h" | ||
|
|
||
| namespace konstructs { | ||
| class Network { | ||
| public: | ||
| Network(Settings settings); | ||
| void handle_network(Player player, | ||
| ChunkModelFactory *model_factory, | ||
| World world, | ||
| int radius, | ||
| uint32_t frame, | ||
| Hud hud, | ||
| GLFWwindow *mGLFWWindow, | ||
| PlayerShader *player_shader, | ||
| Vector3i player_chunk, | ||
| BlockTypeInfo blocks); | ||
| bool setup_connection(Settings::Server server, GLFWwindow *mGLFWWindow); | ||
| Client* get_client(); | ||
|
|
||
| private: | ||
| void handle_packet(konstructs::Packet *packet, | ||
| Hud hud, | ||
| GLFWwindow *mGLFWWindow, | ||
| PlayerShader *player_shader, | ||
| Player player, | ||
| Vector3i player_chunk, | ||
| int radius, | ||
| BlockTypeInfo blocks); | ||
| void handle_player_packet(const string &str, | ||
| Player player, | ||
| Vector3i player_chunk, | ||
| int radius); | ||
| void handle_other_player_packet(const string &str, | ||
| PlayerShader *player_shader); | ||
| void handle_delete_other_player_packet(const string &str, | ||
| PlayerShader *player_shader); | ||
| void handle_block_type(const string &str, BlockTypeInfo blocks); | ||
| void handle_texture(konstructs::Packet *packet); | ||
| void handle_belt(const string &str, Hud hud); | ||
| void handle_inventory(const string &str, Hud hud); | ||
| void handle_held_stack(const string &str, Hud hud); | ||
| void handle_time(const string &str); | ||
|
|
||
| Client client; | ||
| }; | ||
| }; | ||
|
|
||
| #endif //KONSTRUCTS_NETWORK_H | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is of course horrible, but at the moment I just like to get things running again :)