Skip to content

Commit

Permalink
clean up config file and placement of executables
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler-Lentz committed Jun 9, 2024
1 parent aea58f5 commit 36542ee
Show file tree
Hide file tree
Showing 16 changed files with 91 additions and 177 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ docs/*
!docs/.gitkeep

maps/generated/**
!maps/generated/.gitkeep
!maps/generated/.gitkeep

client
server
client.exe
server.exe
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ endif()

# CMake Variables
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/build/bin)
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR})

# Generate a "compile_commands.json" file for VScode to use
set(CMAKE_EXPORT_COMPILE_COMMANDS True)
Expand All @@ -36,7 +36,7 @@ add_subdirectory(dependencies/google-test)


# If we need any compiler / linker flags, add them here
SET(GCC_COMPILE_FLAGS "")
SET(GCC_COMPILE_FLAGS "")
SET(GCC_LINK_FLAGS "")

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COMPILE_FLAGS}")
Expand All @@ -47,6 +47,7 @@ project(game VERSION 1.0)
# Custom Variables
SET(INCLUDE_DIRECTORY ${PROJECT_SOURCE_DIR}/include)


# Dependencies

# For some reason I had to add this in two places to make it work on certain lab computers???
Expand Down
47 changes: 20 additions & 27 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
{
"game": {
"maze": {
"directory": "maps",
"procedural": false,
"maze_file": "demo/game1_player_pov.maze"
"server": {
"port": 2355,
"lobby_name": "Funny Lobby Name Here",
"lobby_broadcast": true,
"max_players": 1,
"disable_dm": false,
"skip_intro": false,
"disable_enemies": false,
"maze": {
"directory": "maps",
"procedural": true,
"maze_file": "demo/game1_player_pov.maze"
}
},
"disable_enemies": false
},
"network": {
"server_ip": "localhost",
"server_port": 2355
},
"server": {
"lobby_name": "Funny Lobby Name Here",
"lobby_broadcast": true,
"max_players": 4,
"disable_dm": false,
"skip_intro": false
},
"client": {
"default_name": "Conan O'Brien",
"lobby_discovery": true,
"fullscreen": true,
"draw_bboxes": false,
"fps_counter": true,
"presentation": false,
"render": 80
}
"client": {
"lobby_discovery": true,
"fullscreen": true,
"fps_counter": true,
"presentation": false,
"render": 80
}
}
4 changes: 2 additions & 2 deletions dependencies/json/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
include(FetchContent)
include(FetchContent)

# orignally used the snippet from here
# https://github.com/ArthurSonzogni/nlohmann_json_cmake_fetchcontent
# but this has a bug in MSVS, so I used the line from this GitHub issue instead
# https://github.com/owodzeg/V4Hero/issues/91
FetchContent_Declare(json GIT_REPOSITORY https://github.com/nlohmann/json GIT_TAG v3.11.2)

FetchContent_MakeAvailable(json)
FetchContent_MakeAvailable(json)
14 changes: 0 additions & 14 deletions include/server/game/servergamestate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,6 @@ class ServerGameState {
*/
std::unique_ptr<Spawner> spawner;

/**
* @brief Creates a ServerGameState instance. The intial GamePhase is set to
* Lobby.
*/
ServerGameState();

/**
* @brief Creats a ServerGameState instance and sets the initial game phase
* to the given GamePhase.
* @param start_phase GamePhase that the new ServerGameState instance will
* start in.
*/
explicit ServerGameState(GamePhase start_phase);

ServerGameState(GamePhase start_phase, const GameConfig& config);

/**
Expand Down
48 changes: 15 additions & 33 deletions include/shared/utilities/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,20 @@
* to know the exact string indices to use to index into the nlohmann::json object.
*/
struct GameConfig {
/// @brief Game config options
/// @brief Config settings for the server
struct {
/// @brief port the server should run on
int port;
/// @brief Name of the server's lobby
std::string lobby_name;
/// @brief Whether or not the server should broadcast that the server is
bool lobby_broadcast;
/// @brief max number of players this server allows
int max_players;
/// @brief whether or not the server will spawn a DM
bool disable_dm;
/// @brief whether or not to skip the intro cutscene
bool skip_intro;
struct {
/**
* @brief Path of the directory (contained in the repository
Expand All @@ -31,37 +43,15 @@ struct GameConfig {
std::string maze_file;

} maze;
/// @brief whether or not to disable enemy spawns
bool disable_enemies;
} game;
/// @brief Shared config settings for the network
struct {
/// @brief IP that the server is being hosted on. E.g. "127.0.0.1" for localhost.
std::string server_ip;
/// @brief Port that the server is running on. This should be a value between
/// 2302-2400, or 6073 so that it can be accepted through the firewall on lab computers
int server_port;
} network;
/// @brief Config settings for the server
struct {
/// @brief Name of the server's lobby
std::string lobby_name;
/// @brief Whether or not the server should broadcast that the server is
bool lobby_broadcast;
/// @brief max number of players this server allows
int max_players;
/// @brief whether or not the server will spawn a DM
bool disable_dm;
/// @brief whether or not to skip the intro cutscene
bool skip_intro;
} server;
/// @brief Config settings for the client
struct {
/// @brief Default name of the client
std::string default_name;
/// @brief Whether or not the client should listen for server lobby broadcasts
bool lobby_discovery;
/// @brief whether or not the client should open in fullscreen
bool fullscreen;
bool draw_bboxes;
bool fps_counter;
bool presentation;
int render;
Expand Down Expand Up @@ -89,11 +79,3 @@ struct GameConfig {
*/
static GameConfig parse(int argc, char** argv);
};


/**
* @brief Generates a GameConfig with default values.
* Note: Not using a constructor as then aggregate initialization will not be
* possible for GameConfig structs
*/
GameConfig getDefaultConfig();
1 change: 1 addition & 0 deletions src/client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ set(FILES
bone.cpp
)


# OpenGL
set(OpenGL_GL_PREFERENCE GLVND)
find_package(OpenGL REQUIRED)
Expand Down
42 changes: 20 additions & 22 deletions src/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,16 @@ AudioManager* Client::getAudioManager() {
}

bool Client::connect(std::string ip_addr) {
this->endpoints = resolver.resolve(ip_addr, std::to_string(config.network.server_port));
this->endpoints = resolver.resolve(ip_addr, std::to_string(config.server.port));
this->session = std::make_shared<Session>(std::move(this->socket),
SessionInfo(this->config.client.default_name, {}, {}));
SessionInfo("name", {}, {}));

if (!this->session->connectTo(this->endpoints)) {
return false;
}

auto name = this->gui.getCapturedKeyboardInput();
if (name == "") {
name = config.client.default_name;
}

auto packet = PackagedPacket::make_shared(PacketType::ClientDeclareInfo,
ClientDeclareInfoPacket { .player_name = name });
ClientDeclareInfoPacket { .player_name = "name" });

this->session->sendPacket(packet);

Expand Down Expand Up @@ -1518,20 +1513,23 @@ void Client::lightingPass() {
}

void Client::drawBbox(boost::optional<SharedObject> object) {
if (this->config.client.draw_bboxes) {
auto bbox_pos = object->physics.corner;
// for some reason the y axis of the bbox is off by half
// the dimension of the object. when trying getCenterPosition
// it was off on the x axis.
bbox_pos.y += object->physics.dimensions.y / 2.0f;

item_model->setDimensions(object->physics.dimensions);
item_model->translateAbsolute(bbox_pos);
item_model->rotateAbsolute(glm::normalize(object->physics.facing), true);
item_model->draw(this->deferred_geometry_shader.get(),
this->cam->getPos(),
true);
}
// disabled because it doesn't really render the bboxes in the right location
// so no real reason to users to want to turn this on

// if (this->config.client.draw_bboxes) {
// auto bbox_pos = object->physics.corner;
// // for some reason the y axis of the bbox is off by half
// // the dimension of the object. when trying getCenterPosition
// // it was off on the x axis.
// bbox_pos.y += object->physics.dimensions.y / 2.0f;

// item_model->setDimensions(object->physics.dimensions);
// item_model->translateAbsolute(bbox_pos);
// item_model->rotateAbsolute(glm::normalize(object->physics.facing), true);
// item_model->draw(this->deferred_geometry_shader.get(),
// this->cam->getPos(),
// true);
// }
}

// callbacks - for Interaction
Expand Down
2 changes: 1 addition & 1 deletion src/client/lobbyfinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

LobbyFinder::LobbyFinder(boost::asio::io_context& io_context, const GameConfig& config):
lobby_discovery_socket(io_context,
udp::endpoint(address_v4::any(), config.network.server_port)),
udp::endpoint(address_v4::any(), config.server.port)),
keep_searching(false),
lobby_info_buf()
{
Expand Down
7 changes: 4 additions & 3 deletions src/server/game/introcutscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@


GameConfig getCutsceneConfig() {
GameConfig config = getDefaultConfig();
config.game.maze.maze_file = "cutscene/intro.maze";
config.game.maze.procedural = false;
GameConfig config = GameConfig {};
config.server.maze.directory = "maps";
config.server.maze.maze_file = "cutscene/intro.maze";
config.server.maze.procedural = false;
return config;
}

Expand Down
4 changes: 2 additions & 2 deletions src/server/game/mazegenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ MazeGenerator::MazeGenerator(GameConfig config) {
}

// has to happen after the for loop loading in the type vectors
if (!config.game.maze.procedural) {
auto path = getRepoRoot() / config.game.maze.directory / config.game.maze.maze_file;
if (!config.server.maze.procedural) {
auto path = getRepoRoot() / config.server.maze.directory / config.server.maze.maze_file;
this->_loadRoom(path, false);
return;
}
Expand Down
17 changes: 5 additions & 12 deletions src/server/game/servergamestate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,15 @@

/* Constructors and Destructors */

ServerGameState::ServerGameState() : ServerGameState(getDefaultConfig()) {}

ServerGameState::ServerGameState(GameConfig config) : config(config) {
this->phase = GamePhase::LOBBY;
this->timestep = FIRST_TIMESTEP;
this->lobby = Lobby(config.server.max_players);
this->lobby.max_players = config.server.max_players;
this->lobby.name = config.server.lobby_name;

this->maps_directory = config.game.maze.directory;
this->maze_file = config.game.maze.maze_file;
this->maps_directory = config.server.maze.directory;
this->maze_file = config.server.maze.maze_file;

// Initialize game instance match phase data
// Match begins in MazeExploration phase (no timer)
Expand Down Expand Up @@ -85,10 +83,10 @@ ServerGameState::ServerGameState(GameConfig config) : config(config) {
attempts++;
}

if (config.game.maze.procedural) {
if (config.server.maze.procedural) {
std::cout << "Took " << attempts << " attempts to generate a full procedural maze\n";
std::string filename = std::to_string(getMsSinceEpoch()) + ".maze";
auto path = getRepoRoot() / config.game.maze.directory / "generated" / filename;
auto path = getRepoRoot() / config.server.maze.directory / "generated" / filename;
std::cout << "Saving procedural maze to " << path << std::endl;
grid->writeToFile(path.string());
}
Expand All @@ -99,11 +97,6 @@ ServerGameState::ServerGameState(GameConfig config) : config(config) {
this->loadMaze(*grid);
}

ServerGameState::ServerGameState(GamePhase start_phase)
: ServerGameState(getDefaultConfig()) {
this->phase = start_phase;
}

ServerGameState::ServerGameState(GamePhase start_phase, const GameConfig& config)
: ServerGameState(config) {
this->phase = start_phase;
Expand Down Expand Up @@ -739,7 +732,7 @@ void ServerGameState::update(const EventList& events) {
handleDeaths();
handleRespawns();
deleteEntities();
if (!this->config.game.disable_enemies) {
if (!this->config.server.disable_enemies) {
spawnEnemies();
}
handleTickVelocity();
Expand Down
2 changes: 1 addition & 1 deletion src/server/lobbybroadcaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void LobbyBroadcaster::_lobbyBroadcastWorker() {
this->socket.set_option(udp::socket::reuse_address(true));
this->socket.set_option(boost::asio::socket_base::broadcast(true));

udp::endpoint endpt(address_v4::broadcast(), this->config.network.server_port);
udp::endpoint endpt(address_v4::broadcast(), this->config.server.port);

// Don't bother with packet headers here, because there is only one packet being sent over UDP
// so we don't need to distinguish them.
Expand Down
2 changes: 1 addition & 1 deletion src/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ using namespace boost::asio::ip;

Server::Server(boost::asio::io_context& io_context, GameConfig config)
:lobby_broadcaster(io_context, config),
acceptor(io_context, tcp::endpoint(tcp::v4(), config.network.server_port)),
acceptor(io_context, tcp::endpoint(tcp::v4(), config.server.port)),
socket(io_context),
world_eid(0),
state(ServerGameState(GamePhase::LOBBY, config)),
Expand Down
Loading

0 comments on commit 36542ee

Please sign in to comment.