Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/tick rate #194

Merged
merged 5 commits into from
Jun 4, 2024
Merged
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
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
Loading