Skip to content

Commit

Permalink
merge w/ dev for lobby changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler-Lentz committed Apr 21, 2024
2 parents c38797a + e8eeb04 commit b744ba9
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Install OpenGL
run: sudo apt-get update && sudo apt-get install cmake pkg-config && sudo apt-get install mesa-utils libglu1-mesa-dev freeglut3-dev mesa-common-dev && sudo apt-get install libglew-dev libglfw3-dev libglm-dev && sudo apt-get install libao-dev libmpg123-dev
run: sudo apt-get update && sudo apt-get install --fix-missing cmake pkg-config mesa-utils libgl1-mesa-dev libglu1-mesa-dev freeglut3-dev mesa-common-dev libglew-dev libglfw3-dev libglm-dev libao-dev libmpg123-dev libxkbcommon-dev libxinerama-dev libxcursor-dev libxi-dev xvfb
- uses: actions/checkout@v4
- name: Create build dir
run: mkdir -p build
Expand All @@ -49,7 +49,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Install OpenGL
run: sudo apt-get update && sudo apt-get install cmake pkg-config && sudo apt-get install mesa-utils libglu1-mesa-dev freeglut3-dev mesa-common-dev && sudo apt-get install libglew-dev libglfw3-dev libglm-dev && sudo apt-get install libao-dev libmpg123-dev
run: sudo apt-get update && sudo apt-get install --fix-missing cmake pkg-config mesa-utils libgl1-mesa-dev libglu1-mesa-dev freeglut3-dev mesa-common-dev libglew-dev libglfw3-dev libglm-dev libao-dev libmpg123-dev libxkbcommon-dev libxinerama-dev libxcursor-dev libxi-dev xvfb
- uses: actions/checkout@v4
- name: Create build dir
run: mkdir -p build
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
name: Client on Linux (Ubuntu)
runs-on: ubuntu-latest
steps:
- name: Install OpenGL
run: sudo apt-get update && sudo apt-get install --fix-missing cmake pkg-config mesa-utils libgl1-mesa-dev libglu1-mesa-dev freeglut3-dev mesa-common-dev libglew-dev libglfw3-dev libglm-dev libao-dev libmpg123-dev libxkbcommon-dev libxinerama-dev libxcursor-dev libxi-dev xvfb
- uses: actions/checkout@v4
- name: Create build dir
run: mkdir -p build
Expand All @@ -46,6 +48,8 @@ jobs:
name: Server on Linux (Ubuntu)
runs-on: ubuntu-latest
steps:
- name: Install OpenGL
run: sudo apt-get update && sudo apt-get install --fix-missing cmake pkg-config mesa-utils libgl1-mesa-dev libglu1-mesa-dev freeglut3-dev mesa-common-dev libglew-dev libglfw3-dev libglm-dev libao-dev libmpg123-dev libxkbcommon-dev libxinerama-dev libxcursor-dev libxi-dev xvfb
- uses: actions/checkout@v4
- name: Create build dir
run: mkdir -p build
Expand All @@ -69,6 +73,8 @@ jobs:
name: Shared on Linux (Ubuntu)
runs-on: ubuntu-latest
steps:
- name: Install OpenGL
run: sudo apt-get update && sudo apt-get install --fix-missing cmake pkg-config mesa-utils libgl1-mesa-dev libglu1-mesa-dev freeglut3-dev mesa-common-dev libglew-dev libglfw3-dev libglm-dev libao-dev libmpg123-dev libxkbcommon-dev libxinerama-dev libxcursor-dev libxi-dev xvfb
- uses: actions/checkout@v4
- name: Create build dir
run: mkdir -p build
Expand Down
4 changes: 4 additions & 0 deletions include/shared/game/gamestate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ class GameState {

GamePhase getPhase() const;

void setPhase(GamePhase phase);

bool enoughPlayers();

/**
* Reassign id to the specified name in the mapping. This is okay to call if the
* player is already in the mapping, as nothing will happen. If a player's name
Expand Down
7 changes: 6 additions & 1 deletion src/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,16 @@ int Client::start(boost::asio::io_context& context) {
glClearColor(0.8f, 0.8f, 0.8f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

this->draw();
if (this->gameState.getPhase() == GamePhase::GAME) {
this->draw();
}

/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();

// std::this_thread::sleep_for(std::chrono::seconds(1));
}

glfwTerminate();
Expand Down Expand Up @@ -148,6 +152,7 @@ void Client::processServerInput(boost::asio::io_context& context) {
std::cout << "Event Received: " << event << std::endl;
if (event.type == EventType::LoadGameState) {
this->gameState = boost::get<LoadGameStateEvent>(event.data).state;

// for (const auto& [eid, player] : data.state.getLobbyPlayers()) {
// std::cout << "\tPlayer " << eid << ": " << player << "\n";
// }
Expand Down
4 changes: 2 additions & 2 deletions src/client/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ target_link_libraries(${TARGET_NAME}
Boost::serialization
nlohmann_json::nlohmann_json
)
target_include_directories(${TARGET_NAME} PRIVATE ${GLM_LIBRARY_INCLUDES})
target_link_libraries(${TARGET_NAME} PRIVATE glm::glm)
target_include_directories(${TARGET_NAME} PRIVATE ${OPENGL_INCLUDE_DIRS} glfw glm ${imgui-directory} "${CMAKE_BINARY_DIR}/_deps/glew-src/include")
target_link_libraries(${TARGET_NAME} PRIVATE glm glfw libglew_static)

# setup make target
set(RUN_TESTS_TARGET "run_${TARGET_NAME}")
Expand Down
2 changes: 2 additions & 0 deletions src/server/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ int main(int argc, char** argv) {

// Wait until next tick
context.run_for(wait_time);

// std::this_thread::sleep_for(std::chrono::seconds(1));
}
}
14 changes: 13 additions & 1 deletion src/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Server::Server(boost::asio::io_context& io_context, GameConfig config)
acceptor(io_context, tcp::endpoint(tcp::v4(), config.network.server_port)),
socket(io_context),
world_eid(0),
state(GameState(GamePhase::GAME, config))
state(GameState(GamePhase::LOBBY, config))
{
Object* obj = state.createObject();
obj->position = glm::vec3(0.0f, 0.0f, 0.0f);
Expand Down Expand Up @@ -101,13 +101,25 @@ std::chrono::milliseconds Server::doTick() {
this->state.removePlayerFromLobby(eid);
}
}

if (this->state.enoughPlayers()) {
this->state.setPhase(GamePhase::GAME);
}

sendUpdateToAllClients(Event(this->world_eid, EventType::LoadGameState, LoadGameStateEvent(this->state)));

std::cout << "in LOBBY phase!" << std::endl;
std::cout << "max num players: " << this->state.getLobbyMaxPlayers() << std::endl;

break;
case GamePhase::GAME: {
std::vector<Event> allClientEvents = getAllClientEvents();

updateGameState(allClientEvents);

sendUpdateToAllClients(Event(this->world_eid, EventType::LoadGameState, LoadGameStateEvent(this->state)));

std::cout << "in GAME phase!" << std::endl;
break;
}
default:
Expand Down
8 changes: 8 additions & 0 deletions src/shared/game/gamestate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,18 @@ std::string GameState::to_string() {
return representation;
}

bool GameState::enoughPlayers() {
return this->lobby.players.size() == getLobbyMaxPlayers();
}

GamePhase GameState::getPhase() const {
return this->phase;
}

void GameState::setPhase(GamePhase phase) {
this->phase = phase;
}

void GameState::addPlayerToLobby(EntityID id, std::string name) {
this->lobby.players[id] = name;
}
Expand Down

0 comments on commit b744ba9

Please sign in to comment.