Skip to main content
added 71 characters in body
Source Link
Aldo
  • 309
  • 6
  • 11

Handling How to handle player actions in a multithreaded gameserver

I'm working on a multiplayer game, and today I implemented basic "spatial hashing" in my entity-component-system.

Before implementing that algorithm, I was sending players actions to all connected players :

public void onPlayerMovement()(auto ref PlayerMovementMessage message, ClientSocket socket) { this.m_gameServer.sendToAll(message); } 

My code is now :

public void onPlayerMovement()(auto ref PlayerMovementMessage message, ClientSocket socket) { auto entity = this.m_gameServer.findEntity(socket); auto nearbyEntities = this.m_gameServer.world.getNearbyEntities(entity.get!PositionComponent().bucket) .filter!(e => e.hasComponent!PlayerComponent()).array(); if(nearbyEntities.length) { this.m_gameServer.sendTo(nearbyEntities, message); } } 

As you can see im now calling this.m_gameServer.world.getNearbyEntities() from SpatialHashingSystem.d to get nearby players.

onPlayerMovement function is called by class GameServer.d in a new thread, so it might be called before SpatialHashingSystem.d executes his algorithm, therefore calling getNearbyEntities() directly returns invalid data.

What can I do at this point ? Event system ? isnt that bad for a real time game ?

Thanks

Handling player actions in a multithreaded gameserver

I'm working on a multiplayer game, and today I implemented basic "spatial hashing" in my entity-component-system.

Before implementing that algorithm, I was sending players actions to all connected players :

public void onPlayerMovement()(auto ref PlayerMovementMessage message, ClientSocket socket) { this.m_gameServer.sendToAll(message); } 

My code is now :

public void onPlayerMovement()(auto ref PlayerMovementMessage message, ClientSocket socket) { auto entity = this.m_gameServer.findEntity(socket); auto nearbyEntities = this.m_gameServer.world.getNearbyEntities(entity.get!PositionComponent().bucket) .filter!(e => e.hasComponent!PlayerComponent()).array(); if(nearbyEntities.length) { this.m_gameServer.sendTo(nearbyEntities, message); } } 

As you can see im now calling this.m_gameServer.world.getNearbyEntities() from SpatialHashingSystem.d to get nearby players.

onPlayerMovement function is called by class GameServer.d in a new thread, so it might be called before SpatialHashingSystem.d executes his algorithm.

What can I do at this point ? Event system ? isnt that bad for a real time game ?

Thanks

How to handle player actions in a multithreaded gameserver

I'm working on a multiplayer game, and today I implemented basic "spatial hashing" in my entity-component-system.

Before implementing that algorithm, I was sending players actions to all connected players :

public void onPlayerMovement()(auto ref PlayerMovementMessage message, ClientSocket socket) { this.m_gameServer.sendToAll(message); } 

My code is now :

public void onPlayerMovement()(auto ref PlayerMovementMessage message, ClientSocket socket) { auto entity = this.m_gameServer.findEntity(socket); auto nearbyEntities = this.m_gameServer.world.getNearbyEntities(entity.get!PositionComponent().bucket) .filter!(e => e.hasComponent!PlayerComponent()).array(); if(nearbyEntities.length) { this.m_gameServer.sendTo(nearbyEntities, message); } } 

As you can see im now calling this.m_gameServer.world.getNearbyEntities() from SpatialHashingSystem.d to get nearby players.

onPlayerMovement function is called by class GameServer.d in a new thread, so it might be called before SpatialHashingSystem.d executes his algorithm, therefore calling getNearbyEntities() directly returns invalid data.

What can I do at this point ? Event system ? isnt that bad for a real time game ?

Thanks

added 23 characters in body
Source Link
Aldo
  • 309
  • 6
  • 11

I'm working on a multiplayer game, and today I implemented basic "spatial hashing" in my entity-component-system.

Before implementing that algorithm, I was sending players actions to all connected players :

public void onPlayerMovement()(auto ref PlayerMovementMessage message, ClientSocket socket) { this.m_gameServer.sendToAll(message); } 

My code is now :

public void onPlayerMovement()(auto ref PlayerMovementMessage message, ClientSocket socket) { auto entity = this.m_gameServer.findEntity(socket); auto nearbyEntities = this.m_gameServer.world.getNearbyEntities(entity.get!PositionComponent().bucket) .filter!(e => e.hasComponent!PlayerComponent()).array(); if(nearbyEntities.length) { this.m_gameServer.sendTo(nearbyEntities, message); } } 

As you can see im now calling this.m_gameServer.world.getNearbyEntities() from SpatialHashingSystem.d to get nearby players.

onPlayerMovement function is called by class GameServer.d in a new thread, so it might be called before SpatialHashingSystem.d executes his algorithm.

HowWhat can I do at this point ? Event system ? isnt that bad for a real time game ?

Thanks

I'm working on a multiplayer game, and today I implemented basic "spatial hashing" in my entity-component-system.

Before implementing that algorithm, I was sending players actions to all connected players :

public void onPlayerMovement()(auto ref PlayerMovementMessage message, ClientSocket socket) { this.m_gameServer.sendToAll(message); } 

My code is now :

public void onPlayerMovement()(auto ref PlayerMovementMessage message, ClientSocket socket) { auto entity = this.m_gameServer.findEntity(socket); auto nearbyEntities = this.m_gameServer.world.getNearbyEntities(entity.get!PositionComponent().bucket) .filter!(e => e.hasComponent!PlayerComponent()).array(); if(nearbyEntities.length) { this.m_gameServer.sendTo(nearbyEntities, message); } } 

As you can see im now calling this.m_gameServer.world.getNearbyEntities() from SpatialHashingSystem.d.

onPlayerMovement function is called by class GameServer.d in a new thread, so it might be called before SpatialHashingSystem.d executes his algorithm.

How can I do at this point ? Event system ? isnt that bad for a real time game ?

Thanks

I'm working on a multiplayer game, and today I implemented basic "spatial hashing" in my entity-component-system.

Before implementing that algorithm, I was sending players actions to all connected players :

public void onPlayerMovement()(auto ref PlayerMovementMessage message, ClientSocket socket) { this.m_gameServer.sendToAll(message); } 

My code is now :

public void onPlayerMovement()(auto ref PlayerMovementMessage message, ClientSocket socket) { auto entity = this.m_gameServer.findEntity(socket); auto nearbyEntities = this.m_gameServer.world.getNearbyEntities(entity.get!PositionComponent().bucket) .filter!(e => e.hasComponent!PlayerComponent()).array(); if(nearbyEntities.length) { this.m_gameServer.sendTo(nearbyEntities, message); } } 

As you can see im now calling this.m_gameServer.world.getNearbyEntities() from SpatialHashingSystem.d to get nearby players.

onPlayerMovement function is called by class GameServer.d in a new thread, so it might be called before SpatialHashingSystem.d executes his algorithm.

What can I do at this point ? Event system ? isnt that bad for a real time game ?

Thanks

Source Link
Aldo
  • 309
  • 6
  • 11

Handling player actions in a multithreaded gameserver

I'm working on a multiplayer game, and today I implemented basic "spatial hashing" in my entity-component-system.

Before implementing that algorithm, I was sending players actions to all connected players :

public void onPlayerMovement()(auto ref PlayerMovementMessage message, ClientSocket socket) { this.m_gameServer.sendToAll(message); } 

My code is now :

public void onPlayerMovement()(auto ref PlayerMovementMessage message, ClientSocket socket) { auto entity = this.m_gameServer.findEntity(socket); auto nearbyEntities = this.m_gameServer.world.getNearbyEntities(entity.get!PositionComponent().bucket) .filter!(e => e.hasComponent!PlayerComponent()).array(); if(nearbyEntities.length) { this.m_gameServer.sendTo(nearbyEntities, message); } } 

As you can see im now calling this.m_gameServer.world.getNearbyEntities() from SpatialHashingSystem.d.

onPlayerMovement function is called by class GameServer.d in a new thread, so it might be called before SpatialHashingSystem.d executes his algorithm.

How can I do at this point ? Event system ? isnt that bad for a real time game ?

Thanks