Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ include_directories(
dependencies/nanogui/ext/nanovg/src
dependencies/optional-lite
dependencies/tinyobjloader
lib/include)
lib/include
include)

FILE(
GLOB SOURCE_FILES
Expand Down
8 changes: 4 additions & 4 deletions Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -415,19 +415,19 @@ EXTRACT_ALL = YES
# be included in the documentation.
# The default value is: NO.

EXTRACT_PRIVATE = NO
EXTRACT_PRIVATE = YES

# If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal
# scope will be included in the documentation.
# The default value is: NO.

EXTRACT_PACKAGE = NO
EXTRACT_PACKAGE = YES

# If the EXTRACT_STATIC tag is set to YES, all static members of a file will be
# included in the documentation.
# The default value is: NO.

EXTRACT_STATIC = NO
EXTRACT_STATIC = YES

# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined
# locally in source files will be included in the documentation. If set to NO,
Expand Down Expand Up @@ -758,7 +758,7 @@ WARN_LOGFILE =
# spaces.
# Note: If this tag is empty the current directory is searched.

INPUT = src/
INPUT = src/ include/ lib/src/ lib/include/

# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
Expand Down
32 changes: 32 additions & 0 deletions include/cli.h
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
88 changes: 88 additions & 0 deletions include/gui.h
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
149 changes: 149 additions & 0 deletions include/konstructs.h
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
79 changes: 79 additions & 0 deletions include/network.h
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);
Copy link
Member Author

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 :)

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
Loading