Skip to content

Commit

Permalink
Merge pull request #194 from ucsd-cse125-sp24/fix/tick-rate
Browse files Browse the repository at this point in the history
Fix/tick rate
  • Loading branch information
Tyler-Lentz authored Jun 4, 2024
2 parents dd85620 + 610d726 commit fa42aa9
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"game": {
"maze": {
"directory": "maps",
"procedural": false,
"procedural": true,
"maze_file": "test/itemRoom.maze"
}
},
Expand Down
2 changes: 1 addition & 1 deletion dependencies/freetype/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

FetchContent_Declare(
freetype
GIT_REPOSITORY https://gitlab.freedesktop.org/freetype/freetype.git
GIT_REPOSITORY https://github.com/freetype/freetype.git
GIT_TAG VER-2-13-2
)

Expand Down
2 changes: 1 addition & 1 deletion include/shared/network/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
// How many objects we send in one LoadGameState packet
// If there are more objects that need to be sent, then
// they are split up into multiple LoadGameState packets
#define OBJECTS_PER_UPDATE 80
#define OBJECTS_PER_UPDATE 250
1 change: 1 addition & 0 deletions src/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Client::Client(boost::asio::io_context& io_context, GameConfig config):
lobby_finder(io_context, config),
cam(new Camera()) {


// Initialize Client's GUIState::Lobby related state
// Initial lobby player state is set to connected (this assumes that whenever
// GUIState is set to GUIState::Lobby, the client is connected to a lobby)
Expand Down
12 changes: 10 additions & 2 deletions src/server/game/servergamestate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ ServerGameState::~ServerGameState() {}
/* SharedGameState generation */
std::vector<SharedGameState> ServerGameState::generateSharedGameState(bool send_all) {
std::vector<SharedGameState> partial_updates;
auto all_objects = this->objects.toShared();

auto getUpdateTemplate = [this]() {
SharedGameState curr_update;
Expand All @@ -122,6 +121,8 @@ std::vector<SharedGameState> ServerGameState::generateSharedGameState(bool send_
};

if (send_all) {
auto all_objects = this->objects.toShared();

for (int i = 0; i < all_objects.size(); i += OBJECTS_PER_UPDATE) {
SharedGameState curr_update = getUpdateTemplate();

Expand All @@ -137,7 +138,14 @@ std::vector<SharedGameState> ServerGameState::generateSharedGameState(bool send_

int num_in_curr_update = 0;
for (EntityID id : this->updated_entities) {
curr_update.objects.insert({id, all_objects.at(id)});

Object* obj = this->objects.getObject(id);
if (obj == nullptr) {
curr_update.objects.insert({ id, boost::none });
} else {
curr_update.objects.insert({ id, obj->toShared() });
}

num_in_curr_update++;

if (num_in_curr_update >= OBJECTS_PER_UPDATE) {
Expand Down
1 change: 1 addition & 0 deletions src/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ void Server::_doAccept() {
this->acceptor.async_accept(this->socket,
[this](boost::system::error_code ec) {
if (!ec) {
this->socket.set_option(boost::asio::ip::tcp::no_delay(true));
auto addr = this->socket.remote_endpoint().address();
auto new_session = this->_handleNewSession(addr);

Expand Down

0 comments on commit fa42aa9

Please sign in to comment.