diff --git a/.gitignore b/.gitignore index ee5600e7..da677729 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,12 @@ docs/* !docs/.gitkeep maps/generated/** -!maps/generated/.gitkeep \ No newline at end of file +!maps/generated/.gitkeep + +client +server +client.exe +server.exe +*.ilk +*.dll +*.pdb \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 099bfccc..ff6608bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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}") @@ -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??? diff --git a/README.md b/README.md index c874c93c..fa8ba696 100644 --- a/README.md +++ b/README.md @@ -2,25 +2,110 @@ ![Docs](https://github.com/ucsd-cse125-sp24/group3/actions/workflows/docs.yml/badge.svg) -TODO: Game description here, with screenshots. +![Title Logo](./assets/imgs/title.png) + +[Wrath of Zeus](https://cse125.ucsd.edu/2024/cse125g3/wrath-of-zeus/) is a 3v1 asymmetric maze escape game where 3 players attempt to escape a maze while Zeus tries to stop them from above. It was entirely developed through the course of 10 weeks as a project for UCSD's [CSE 125 course](https://cse125.ucsd.edu/), run by Professor [Geoffrey Voelker](https://cseweb.ucsd.edu/~voelker/). + +The players have to find a magical orb and escape within a time limit, while Zeus can use lightning bolts, dim the lights, and place various traps in order to stop them. + +The players win when one player escapes with the orb. However, picking up the orb for the first time starts a 5 minute timer. If after 5 minutes the players have not escaped the maze, then Zeus wins. In addition, Zeus can prematurely start the timer before the players pick up the orb if the players die 3 times. + +An important thing to keep in mind while playing is that the color of the torchlights is your guide through the maze. If you see the torches start to turn more blue, then you are getting closer to the orb, and if they start to turn more white, then you are getting closer to the exit. This is crucial for both the players and Zeus as they navigate around the maze and try to find their way out / smite those pesky mortals. + +Made by +- Edward Jin +- Gil Keidar +- Tyler Lentz +- David Min +- Ted Park +- Anthony Tarbinian +- Jiawen (Coco) Wang + +## Download + +Click [here](https://cse125.ucsd.edu/2024/cse125g3/wrath-of-zeus/download.html) + +## Screenshots + +![Entrance to the maze](./screenshots/entrance.png) +![A hallway in the maze](./screenshots/hallway.png) +![The Orb](./screenshots/orb.png) +![A lightning strike](./screenshots/lightning.png) +![A player walking up to the exit](./screenshots/exit.png) +![Entrance to the maze, from Zeus's view](./screenshots/entrance_zeus.png) +![Zeus smiting a player](./screenshots/zeus_attack.png) +![The view from above](./screenshots/god_view.png) + +## Important Notes Before Playing + +### General + +1. By default the game will load in configuration options from the file titled "Config" or "Config.json" +2. If your client or server fails to open with no explanation, it is likely that you have a malformed config file. For an error message you can try running the program in the command line. If you are unsure how to do that, then I would recommend you revert your config file back to the default. +3. The UI is optimized to work on 1920x1080p monitors. On any other resolution it will attempt to scale UI, but it will likely look very off. +4. The networking code will likely be unplayable on anything other than a LAN, and even on Wi-Fi it will be suboptimal. +5. You can increase the number of players in a lobby, but certain elements of the UI may break and we cannot make any promises about performance! Anecdotally, however, the game + still plays well with 5 total players. + +### Config Options Explanations + +``` +{ + "port"------------------> port that the server runs on and the client connects to + "server": { + "lobby_name"--------> name of the server lobby + "lobby_broadcast"---> whether or not the server sends discovery packets on the LAN + "max_players"-------> how many players must connect to the server before the game can start + "disable_zeus"------> whether or not a player should be allowed to play as Zeus + "skip_intro"--------> whether or not the intro cutscene should be skipped + "disable_enemies"---> whether or not enemies should spawn in the maze + "maze": { + "directory"-----> high level directory that all of the maps are in + "procedural"----> whether or not to use a procedurally generated maze + "maze_file"-----> filepath (relative to the above directory) of a maze file to load in, if procedural is false + } + }, + "client": { + "lobby_discovery"---> whether or not the client listens for servers that are broadcasting discovery packets + "fullscreen"--------> whether or not the window should be fullscreen, or a 1920x1080p window + "fps_counter"-------> whether or not to display the current FPS in the top left of the screen + "presentation"------> shifts the hotbar UI up slightly, for use during the CSE 125 demo to make sure the UI could be seen by audience members in the auditorium + "render"------------> beyond this distance, for players no objects will be rendered, and for Zeus certain traps will not be rendered + } +} +``` + +### Custom Map Generation + +If you would like to try your hand at creating some custom mazes or rooms which will be used in the procedural generation algorithm, you can create appropriate maze files in the "maps" directory. If you just want to load in an entirely custom maze then it doesn't matter where it is placed (as long as you put the appropriate path in your configuration file), but if you want the procedural algorithm to use your rooms then you should place them in the directories called "10x10" and "20x20". There is also a directory called "40x40" and the game will attempt to use these 40x40 rooms in the game, but I cannot promise that they will totally work as they are very much untested as we found it was too much effort to make engaging 40x40 rooms and you did not gain much from it. But maybe you will have better luck with it! + +Rules When Designing Rooms: +1. A room must be fully connected, which means that entering from any entryway you should be able to exit from any other entryway in that room. +2. Room door placements must be along the midpoints of the 10x10 sections of each room, as shown in the .empty template maze files. +3. You CAN block entryways into a room, but for 20x20 and 40x40 rooms if you block off one entryway you must also block off all of the other entryways on that side. +4. I think the game will let you make a room with no entrances, but you shouldn't do that for obvious reasons. ## Attributions TomMusic's [Free Fantasy 200 SFX Pack](https://tommusic.itch.io/free-fantasy-200-sfx-pack). -## Documentation +## Development + +All of the following sections are aimed towards development + +### Code Documentation View deployed documentation [here](https://cse125.ucsd.edu/2024/cse125g3/docs/html/) -### Build Docs Locally +#### Build Docs Locally 1. We are using Doxygen which you can install locally from [here](https://www.doxygen.nl/download.html) 2. Run `doxygen` from the root of the directory 3. Open the `html` files in the `docs` directory of the repo -## Setup +### Setup -### Windows (In Visual Studio) +#### Windows (In Visual Studio) 1. Download Visual Studio (if you are on a lab computer, it will already be installed) 2. Clone the repo @@ -30,7 +115,7 @@ View deployed documentation [here](https://cse125.ucsd.edu/2024/cse125g3/docs/ht - `git clone https://github.com/ucsd-cse125-sp24/group3.git` 3. Everything should just work�. To run the program, you can click on the green arrow at the top bar that says "Select Startup Item." There is a dropdown arrow on the right side which will let you select between running the client and the server. -### Linux / Mac +#### Linux / Mac Note: If you work locally this way, you should make sure that before you merge anything into main that it also compiles on a lab computer running Visual Studio. There might be some small differences between how the microsoft compiler handles things, and how `g++` handles things, and we always want to make sure it compiles on a lab computer. @@ -75,34 +160,6 @@ Note: If you work locally this way, you should make sure that before you merge a - `bin/server` (to run the server) - Note that the full filepaths for the executables are `build/bin/server` and `build/bin/client`, so if you are outside of the build directory you will need to give the full path. -### Windows (Without Visual Studio) - -I'm keeping this more for legacy reasons since this doesn't work on the lab computers, but if you want to use windows but don't want to use the Visual Studio IDE, then this is one way you can get it to work. - -This also has the same caveat as above, in that before merging anything in you should verify it compiles on a lab computer running Visual Studio. - -This also is relatively janky. On my Desktop computer, for some reason if you try and compile a C++ program using g++ from Powershell it works fine, but if you try and do it from Git Bash it seg faults (even in a simple Hello World program). - -1. Download Dependencies - 1. `cmake` - - Minimum version 3.13 - - [Install Instructions](https://cgold.readthedocs.io/en/latest/first-step/installation.html) - 2. `g++` - - Follow [this](https://www.freecodecamp.org/news/how-to-install-c-and-cpp-compiler-on-windows/) tutorial. - 3. `make` - - Inside of the `msys2 MINGW64` terminal (the above tutorial should have had you install it), enter `pacman -S make`. - - Then, go back to your environment variable settings and add `C:\msys64\usr\bin` to your system path. - - (This is at `View Advanced System Settings` > `Environment Variables` > Double Click on System Path at the bottom) - - Make sure that in powershell if you type in `make` it recognizes the command. That is how you know it is installed correctly. - 4. OpenGL - - TODO: decide on version - - TODO: link install instructions here -2. Follow the same steps as the Linux / Mac instructions. You may need to add some extra information when you run `CMake`. - - Instead of running `cmake ..`, you might have to run `cmake -G "Unix Makefiles" ..` - -I would generally recommend using Visual Studio if you are working on Windows, since it seems to just work, but I was also able to get this working. - -## Development ### Code Structure @@ -141,18 +198,16 @@ For example, if you want to add a file somewhere in the shared library section o Depending on where you need to link the library (client, server, shared), you will need to go to that `CMakeLists.txt` file and include the relevant CMake incantations/spells/general wizardry to link that library into the specific target. This will likely vary depending on what you are trying to add. -## Useful VSCode Extensions +### Useful VSCode Extensions - [C++ Intellisense](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) - [General Productivity](https://marketplace.visualstudio.com/items?itemName=jirkavrba.subway-surfers) -## Models +### Models You can download models from our Google Drive folder [here](https://drive.google.com/drive/folders/1N7a5cDgMcXbPO0RtgznnEo-1XUfdMScM?usp=sharing) and place them in `src/client/models`. Alternatively, you can install [gdown](https://github.com/wkentaro/gdown) and run `make pull_models` to automatically pull them. - - -## Testing +### Testing We are using [GoogleTest](https://google.github.io/googletest/) for unit testing. They run automatically in GitHub actions or can also be done manually. @@ -188,11 +243,11 @@ TEST(FactorialTest, HandlesPositiveInput) { ``` 3. Run the tests locally with the steps above or with GitHub actions -## Linting +### Linting We are using [cppcheck](https://github.com/danmar/cppcheck) for linting and static code analysis. They run automatically with GitHub actions. -### Suppressing errors +#### Suppressing errors You can suppress a single error by adding comments in the following format after the lint in question: @@ -202,15 +257,15 @@ int x = 5; // cppcheck-suppress unusedVariable You can also pass in `--suppress ` to cppcheck. You can modify the flags that `make lint` uses by modifying the lint target's definition in the root level CMakeLists.txt. -### Linting locally +#### Linting locally -#### Linux/macOS +##### Linux/macOS Install cppcheck on your system based on instructions [here](https://cppcheck.sourceforge.io/) -#### Windows +##### Windows Visual Studio supports a [cppcheck plugin](https://github.com/VioletGiraffe/cppcheck-vs-addin/tree/1.5) -#### Run +### Run From inside the build directory run: diff --git a/config.json b/config.json index 2359dd97..c2a361c4 100644 --- a/config.json +++ b/config.json @@ -1,30 +1,23 @@ { - "game": { - "maze": { - "directory": "maps", - "procedural": false, - "maze_file": "demo/game1_player_pov.maze" + "port": 2355, + "server": { + "lobby_name": "Funny Lobby Name Here", + "lobby_broadcast": true, + "max_players": 4, + "disable_zeus": 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 + } } diff --git a/dependencies/json/CMakeLists.txt b/dependencies/json/CMakeLists.txt index 7d962626..a05ef9a0 100644 --- a/dependencies/json/CMakeLists.txt +++ b/dependencies/json/CMakeLists.txt @@ -1,4 +1,4 @@ - include(FetchContent) +include(FetchContent) # orignally used the snippet from here # https://github.com/ArthurSonzogni/nlohmann_json_cmake_fetchcontent @@ -6,4 +6,4 @@ # 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) \ No newline at end of file +FetchContent_MakeAvailable(json) \ No newline at end of file diff --git a/include/server/game/servergamestate.hpp b/include/server/game/servergamestate.hpp index 0151f522..433383d1 100644 --- a/include/server/game/servergamestate.hpp +++ b/include/server/game/servergamestate.hpp @@ -53,20 +53,6 @@ class ServerGameState { */ std::unique_ptr 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); /** diff --git a/include/shared/utilities/config.hpp b/include/shared/utilities/config.hpp index 5a7f0c8d..2b0993d0 100644 --- a/include/shared/utilities/config.hpp +++ b/include/shared/utilities/config.hpp @@ -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 port the server should run on & client should connect to + int port; + /// @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; struct { /** * @brief Path of the directory (contained in the repository @@ -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; @@ -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(); diff --git a/screenshots/entrance.png b/screenshots/entrance.png new file mode 100644 index 00000000..846346b1 Binary files /dev/null and b/screenshots/entrance.png differ diff --git a/screenshots/entrance_zeus.png b/screenshots/entrance_zeus.png new file mode 100644 index 00000000..108f0307 Binary files /dev/null and b/screenshots/entrance_zeus.png differ diff --git a/screenshots/exit.png b/screenshots/exit.png new file mode 100644 index 00000000..c2e5e510 Binary files /dev/null and b/screenshots/exit.png differ diff --git a/screenshots/god_view.png b/screenshots/god_view.png new file mode 100644 index 00000000..0f7790e8 Binary files /dev/null and b/screenshots/god_view.png differ diff --git a/screenshots/hallway.png b/screenshots/hallway.png new file mode 100644 index 00000000..ee201070 Binary files /dev/null and b/screenshots/hallway.png differ diff --git a/screenshots/lightning.png b/screenshots/lightning.png new file mode 100644 index 00000000..0734db55 Binary files /dev/null and b/screenshots/lightning.png differ diff --git a/screenshots/orb.png b/screenshots/orb.png new file mode 100644 index 00000000..b89f8533 Binary files /dev/null and b/screenshots/orb.png differ diff --git a/screenshots/zeus_attack.png b/screenshots/zeus_attack.png new file mode 100644 index 00000000..70927fb7 Binary files /dev/null and b/screenshots/zeus_attack.png differ diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index b96b8351..36670b40 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -29,6 +29,7 @@ set(FILES bone.cpp ) + # OpenGL set(OpenGL_GL_PREFERENCE GLVND) find_package(OpenGL REQUIRED) diff --git a/src/client/client.cpp b/src/client/client.cpp index 4de23bec..d54c7089 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -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.port)); this->session = std::make_shared(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); @@ -1518,20 +1513,23 @@ void Client::lightingPass() { } void Client::drawBbox(boost::optional 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 diff --git a/src/client/lobbyfinder.cpp b/src/client/lobbyfinder.cpp index ce2e88c9..727dcdcc 100644 --- a/src/client/lobbyfinder.cpp +++ b/src/client/lobbyfinder.cpp @@ -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.port)), keep_searching(false), lobby_info_buf() { diff --git a/src/server/game/introcutscene.cpp b/src/server/game/introcutscene.cpp index 791679fb..c45d26a9 100644 --- a/src/server/game/introcutscene.cpp +++ b/src/server/game/introcutscene.cpp @@ -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; } diff --git a/src/server/game/mazegenerator.cpp b/src/server/game/mazegenerator.cpp index 794fce7b..e6315bfc 100644 --- a/src/server/game/mazegenerator.cpp +++ b/src/server/game/mazegenerator.cpp @@ -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; } diff --git a/src/server/game/servergamestate.cpp b/src/server/game/servergamestate.cpp index ef9687d3..5d275f47 100644 --- a/src/server/game/servergamestate.cpp +++ b/src/server/game/servergamestate.cpp @@ -39,8 +39,6 @@ /* Constructors and Destructors */ -ServerGameState::ServerGameState() : ServerGameState(getDefaultConfig()) {} - ServerGameState::ServerGameState(GameConfig config) : config(config) { this->phase = GamePhase::LOBBY; this->timestep = FIRST_TIMESTEP; @@ -48,8 +46,8 @@ ServerGameState::ServerGameState(GameConfig config) : config(config) { 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) @@ -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()); } @@ -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; @@ -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(); diff --git a/src/server/lobbybroadcaster.cpp b/src/server/lobbybroadcaster.cpp index fb737f97..dabfc155 100644 --- a/src/server/lobbybroadcaster.cpp +++ b/src/server/lobbybroadcaster.cpp @@ -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.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. diff --git a/src/server/server.cpp b/src/server/server.cpp index 87e103d5..7c2d5f9d 100644 --- a/src/server/server.cpp +++ b/src/server/server.cpp @@ -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.port)), socket(io_context), world_eid(0), state(ServerGameState(GamePhase::LOBBY, config)), diff --git a/src/shared/utilities/config.cpp b/src/shared/utilities/config.cpp index 25c9f614..5bd9d06c 100644 --- a/src/shared/utilities/config.cpp +++ b/src/shared/utilities/config.cpp @@ -16,7 +16,7 @@ GameConfig GameConfig::parse(int argc, char** argv) { // cppcheck-suppress const exit(1); } - boost::filesystem::path filepath = getRepoRoot() / "config.json"; + boost::filesystem::path filepath = "config.json"; if (argc == 2) { filepath = argv[1]; } @@ -36,30 +36,23 @@ GameConfig GameConfig::parse(int argc, char** argv) { // cppcheck-suppress const try { return GameConfig { - .game = { - .maze = { - .directory = json.at("game").at("maze").at("directory"), - .procedural = json.at("game").at("maze").at("procedural"), - .maze_file = json.at("game").at("maze").at("maze_file") - }, - .disable_enemies = json.at("game").at("disable_enemies") - }, - .network = { - .server_ip = json.at("network").at("server_ip"), - .server_port = json.at("network").at("server_port") - }, + .port = json.at("port"), .server = { .lobby_name = json.at("server").at("lobby_name"), .lobby_broadcast = json.at("server").at("lobby_broadcast"), .max_players = json.at("server").at("max_players"), - .disable_dm = json.at("server").at("disable_dm"), - .skip_intro = json.at("server").at("skip_intro") + .disable_dm = json.at("server").at("disable_zeus"), + .skip_intro = json.at("server").at("skip_intro"), + .maze = { + .directory = json.at("server").at("maze").at("directory"), + .procedural = json.at("server").at("maze").at("procedural"), + .maze_file = json.at("server").at("maze").at("maze_file") + }, + .disable_enemies = json.at("server").at("disable_enemies") }, .client = { - .default_name = json.at("client").at("default_name"), .lobby_discovery = json.at("client").at("lobby_discovery"), .fullscreen = json.at("client").at("fullscreen"), - .draw_bboxes = json.at("client").at("draw_bboxes"), .fps_counter = json.at("client").at("fps_counter"), .presentation = json.at("client").at("presentation"), .render = json.at("client").at("render") @@ -70,35 +63,3 @@ GameConfig GameConfig::parse(int argc, char** argv) { // cppcheck-suppress const std::exit(1); } } - -GameConfig getDefaultConfig() { - return GameConfig{ - .game = { - .maze = { - .directory = "maps", - .procedural = true, - .maze_file = "default_maze.maze" - }, - .disable_enemies = false - }, - .network = { - .server_ip = "localhost", - .server_port = 2355 - }, - .server = { - .lobby_name = "My Test Lobby", - .lobby_broadcast = false, - .max_players = 1, - .disable_dm = false, - .skip_intro = false - }, - .client = { - .default_name = "Player", - .lobby_discovery = false, - .fullscreen = false, - .draw_bboxes = false, - .fps_counter = false, - .presentation = false - } - }; -} \ No newline at end of file diff --git a/src/shared/utilities/root_path.cpp b/src/shared/utilities/root_path.cpp index 3a28f7ed..e24370c7 100644 --- a/src/shared/utilities/root_path.cpp +++ b/src/shared/utilities/root_path.cpp @@ -4,12 +4,5 @@ #include boost::filesystem::path getRepoRoot() { - /** - * build - * bin - * client - * server - * ... - */ - return boost::dll::program_location().parent_path().parent_path().parent_path(); + return boost::dll::program_location().parent_path(); } \ No newline at end of file