Skip to content

Commit

Permalink
network optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
Nightenom authored Aug 13, 2019
1 parent 7f47983 commit 8060625
Showing 1 changed file with 89 additions and 96 deletions.
185 changes: 89 additions & 96 deletions src/main/java/com/minecolonies/coremod/network/NetworkChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,120 +45,113 @@ public NetworkChannel(final String channelName)
public void registerCommonMessages()
{
int idx = 0;
registerMessage(++idx, ServerUUIDMessage.class);
registerMessage(++idx, ServerUUIDMessage.class, ServerUUIDMessage::new);

// ColonyView messages
registerMessage(++idx, ColonyViewMessage.class);
registerMessage(++idx, ColonyViewCitizenViewMessage.class);
registerMessage(++idx, ColonyViewRemoveCitizenMessage.class);
registerMessage(++idx, ColonyViewBuildingViewMessage.class);
registerMessage(++idx, ColonyViewRemoveBuildingMessage.class);
registerMessage(++idx, PermissionsMessage.View.class);
registerMessage(++idx, ColonyStylesMessage.class);
registerMessage(++idx, ColonyViewWorkOrderMessage.class);
registerMessage(++idx, ColonyViewRemoveWorkOrderMessage.class);
registerMessage(++idx, UpdateChunkCapabilityMessage.class);
registerMessage(++idx, GuardMobAttackListMessage.class);
registerMessage(++idx, HappinessDataMessage.class);
registerMessage(++idx, ColonyViewMessage.class, ColonyViewMessage::new);
registerMessage(++idx, ColonyViewCitizenViewMessage.class, ColonyViewCitizenViewMessage::new);
registerMessage(++idx, ColonyViewRemoveCitizenMessage.class, ColonyViewRemoveCitizenMessage::new);
registerMessage(++idx, ColonyViewBuildingViewMessage.class, ColonyViewBuildingViewMessage::new);
registerMessage(++idx, ColonyViewRemoveBuildingMessage.class, ColonyViewRemoveBuildingMessage::new);
registerMessage(++idx, PermissionsMessage.View.class, PermissionsMessage::new);
registerMessage(++idx, ColonyStylesMessage.class, ColonyStylesMessage::new);
registerMessage(++idx, ColonyViewWorkOrderMessage.class, ColonyViewWorkOrderMessage::new);
registerMessage(++idx, ColonyViewRemoveWorkOrderMessage.class, ColonyViewRemoveWorkOrderMessage::new);
registerMessage(++idx, UpdateChunkCapabilityMessage.class, UpdateChunkCapabilityMessage::new);
registerMessage(++idx, GuardMobAttackListMessage.class, GuardMobAttackListMessage::new);
registerMessage(++idx, HappinessDataMessage.class, HappinessDataMessage::new);

// Permission Request messages
registerMessage(++idx, PermissionsMessage.Permission.class);
registerMessage(++idx, PermissionsMessage.AddPlayer.class);
registerMessage(++idx, PermissionsMessage.RemovePlayer.class);
registerMessage(++idx, PermissionsMessage.ChangePlayerRank.class);
registerMessage(++idx, PermissionsMessage.AddPlayerOrFakePlayer.class);
registerMessage(++idx, PermissionsMessage.Permission.class, PermissionsMessage.Permission::new);
registerMessage(++idx, PermissionsMessage.AddPlayer.class, PermissionsMessage.AddPlayer::new);
registerMessage(++idx, PermissionsMessage.RemovePlayer.class, PermissionsMessage.RemovePlayer::new);
registerMessage(++idx, PermissionsMessage.ChangePlayerRank.class, PermissionsMessage.ChangePlayerRank::new);
registerMessage(++idx, PermissionsMessage.AddPlayerOrFakePlayer.class, PermissionsMessage.AddPlayerOrFakePlayer::new);

// Colony Request messages
registerMessage(++idx, BuildRequestMessage.class);
registerMessage(++idx, OpenInventoryMessage.class);
registerMessage(++idx, TownHallRenameMessage.class);
registerMessage(++idx, MinerSetLevelMessage.class);
registerMessage(++idx, RecallCitizenMessage.class);
registerMessage(++idx, BuildToolPlaceMessage.class);
registerMessage(++idx, ToggleJobMessage.class);
registerMessage(++idx, HireFireMessage.class);
registerMessage(++idx, WorkOrderChangeMessage.class);
registerMessage(++idx, AssignFieldMessage.class);
registerMessage(++idx, AssignmentModeMessage.class);
registerMessage(++idx, GuardTaskMessage.class);
registerMessage(++idx, GuardRecalculateMessage.class);
registerMessage(++idx, MobEntryChangeMessage.class);
registerMessage(++idx, GuardScepterMessage.class);
registerMessage(++idx, RecallTownhallMessage.class);
registerMessage(++idx, TransferItemsRequestMessage.class);
registerMessage(++idx, MarkBuildingDirtyMessage.class);
registerMessage(++idx, ChangeFreeToInteractBlockMessage.class);
registerMessage(++idx, LumberjackReplantSaplingToggleMessage.class);
registerMessage(++idx, ToggleHousingMessage.class);
registerMessage(++idx, ToggleMoveInMessage.class);
registerMessage(++idx, AssignUnassignMessage.class);
registerMessage(++idx, OpenCraftingGUIMessage.class);
registerMessage(++idx, AddRemoveRecipeMessage.class);
registerMessage(++idx, ChangeRecipePriorityMessage.class);
registerMessage(++idx, ChangeDeliveryPriorityMessage.class);
registerMessage(++idx, ChangeDeliveryPriorityStateMessage.class);
registerMessage(++idx, UpgradeWarehouseMessage.class);
registerMessage(++idx, BuildToolPasteMessage.class);
registerMessage(++idx, TransferItemsToCitizenRequestMessage.class);
registerMessage(++idx, UpdateRequestStateMessage.class);
registerMessage(++idx, BuildingSetStyleMessage.class);
registerMessage(++idx, CowboySetMilkCowsMessage.class);
registerMessage(++idx, BuildingMoveMessage.class);
registerMessage(++idx, RecallSingleCitizenMessage.class);
registerMessage(++idx, RemoveEntityMessage.class);
registerMessage(++idx, AssignFilterableItemMessage.class);
registerMessage(++idx, TeamColonyColorChangeMessage.class);
registerMessage(++idx, ToggleHelpMessage.class);
registerMessage(++idx, PauseCitizenMessage.class);
registerMessage(++idx, RestartCitizenMessage.class);
registerMessage(++idx, SortWarehouseMessage.class);
registerMessage(++idx, PostBoxRequestMessage.class);
registerMessage(++idx, ComposterRetrievalMessage.class);
registerMessage(++idx, CrusherSetModeMessage.class);
registerMessage(++idx, BuyCitizenMessage.class);
registerMessage(++idx, HireMercenaryMessage.class);
registerMessage(++idx, ShepherdSetDyeSheepsMessage.class);
registerMessage(++idx, SifterSettingsMessage.class);
registerMessage(++idx, HutRenameMessage.class);
registerMessage(++idx, BuildingHiringModeMessage.class);
registerMessage(++idx, DecorationBuildRequestMessage.class);
registerMessage(++idx, DecorationControllUpdateMessage.class);
registerMessage(++idx, DirectPlaceMessage.class);
registerMessage(++idx, BuildRequestMessage.class, BuildRequestMessage::new);
registerMessage(++idx, OpenInventoryMessage.class, OpenInventoryMessage::new);
registerMessage(++idx, TownHallRenameMessage.class, TownHallRenameMessage::new);
registerMessage(++idx, MinerSetLevelMessage.class, MinerSetLevelMessage::new);
registerMessage(++idx, RecallCitizenMessage.class, RecallCitizenMessage::new);
registerMessage(++idx, BuildToolPlaceMessage.class, BuildToolPlaceMessage::new);
registerMessage(++idx, ToggleJobMessage.class, ToggleJobMessage::new);
registerMessage(++idx, HireFireMessage.class, HireFireMessage::new);
registerMessage(++idx, WorkOrderChangeMessage.class, WorkOrderChangeMessage::new);
registerMessage(++idx, AssignFieldMessage.class, AssignFieldMessage::new);
registerMessage(++idx, AssignmentModeMessage.class, AssignmentModeMessage::new);
registerMessage(++idx, GuardTaskMessage.class, GuardTaskMessage::new);
registerMessage(++idx, GuardRecalculateMessage.class, GuardRecalculateMessage::new);
registerMessage(++idx, MobEntryChangeMessage.class, MobEntryChangeMessage::new);
registerMessage(++idx, GuardScepterMessage.class, GuardScepterMessage::new);
registerMessage(++idx, RecallTownhallMessage.class, RecallTownhallMessage::new);
registerMessage(++idx, TransferItemsRequestMessage.class, TransferItemsRequestMessage::new);
registerMessage(++idx, MarkBuildingDirtyMessage.class, MarkBuildingDirtyMessage::new);
registerMessage(++idx, ChangeFreeToInteractBlockMessage.class, ChangeFreeToInteractBlockMessage::new);
registerMessage(++idx, LumberjackReplantSaplingToggleMessage.class, LumberjackReplantSaplingToggleMessage::new);
registerMessage(++idx, ToggleHousingMessage.class, ToggleHousingMessage::new);
registerMessage(++idx, ToggleMoveInMessage.class, ToggleMoveInMessage::new);
registerMessage(++idx, AssignUnassignMessage.class, AssignUnassignMessage::new);
registerMessage(++idx, OpenCraftingGUIMessage.class, OpenCraftingGUIMessage::new);
registerMessage(++idx, AddRemoveRecipeMessage.class, AddRemoveRecipeMessage::new);
registerMessage(++idx, ChangeRecipePriorityMessage.class, ChangeRecipePriorityMessage::new);
registerMessage(++idx, ChangeDeliveryPriorityMessage.class, ChangeDeliveryPriorityMessage::new);
registerMessage(++idx, ChangeDeliveryPriorityStateMessage.class, ChangeDeliveryPriorityStateMessage::new);
registerMessage(++idx, UpgradeWarehouseMessage.class, UpgradeWarehouseMessage::new);
registerMessage(++idx, BuildToolPasteMessage.class, BuildToolPasteMessage::new);
registerMessage(++idx, TransferItemsToCitizenRequestMessage.class, TransferItemsToCitizenRequestMessage::new);
registerMessage(++idx, UpdateRequestStateMessage.class, UpdateRequestStateMessage::new);
registerMessage(++idx, BuildingSetStyleMessage.class, BuildingSetStyleMessage::new);
registerMessage(++idx, CowboySetMilkCowsMessage.class, CowboySetMilkCowsMessage::new);
registerMessage(++idx, BuildingMoveMessage.class, BuildingMoveMessage::new);
registerMessage(++idx, RecallSingleCitizenMessage.class, RecallSingleCitizenMessage::new);
registerMessage(++idx, RemoveEntityMessage.class, RemoveEntityMessage::new);
registerMessage(++idx, AssignFilterableItemMessage.class, AssignFilterableItemMessage::new);
registerMessage(++idx, TeamColonyColorChangeMessage.class, TeamColonyColorChangeMessage::new);
registerMessage(++idx, ToggleHelpMessage.class, ToggleHelpMessage::new);
registerMessage(++idx, PauseCitizenMessage.class, PauseCitizenMessage::new);
registerMessage(++idx, RestartCitizenMessage.class, RestartCitizenMessage::new);
registerMessage(++idx, SortWarehouseMessage.class, SortWarehouseMessage::new);
registerMessage(++idx, PostBoxRequestMessage.class, PostBoxRequestMessage::new);
registerMessage(++idx, ComposterRetrievalMessage.class, ComposterRetrievalMessage::new);
registerMessage(++idx, CrusherSetModeMessage.class, CrusherSetModeMessage::new);
registerMessage(++idx, BuyCitizenMessage.class, BuyCitizenMessage::new);
registerMessage(++idx, HireMercenaryMessage.class, HireMercenaryMessage::new);
registerMessage(++idx, ShepherdSetDyeSheepsMessage.class, ShepherdSetDyeSheepsMessage::new);
registerMessage(++idx, SifterSettingsMessage.class, SifterSettingsMessage::new);
registerMessage(++idx, HutRenameMessage.class, HutRenameMessage::new);
registerMessage(++idx, BuildingHiringModeMessage.class, BuildingHiringModeMessage::new);
registerMessage(++idx, DecorationBuildRequestMessage.class, DecorationBuildRequestMessage::new);
registerMessage(++idx, DecorationControllUpdateMessage.class, DecorationControllUpdateMessage::new);
registerMessage(++idx, DirectPlaceMessage.class, DirectPlaceMessage::new);

//Client side only
registerMessage(++idx, BlockParticleEffectMessage.class);
registerMessage(++idx, CompostParticleMessage.class);
registerMessage(++idx, ItemParticleEffectMessage.class);
registerMessage(++idx, LocalizedParticleEffectMessage.class);
registerMessage(++idx, UpdateChunkRangeCapabilityMessage.class);
registerMessage(++idx, OpenSuggestionWindowMessage.class);
registerMessage(++idx, UpdateClientWithRecipesMessage.class);
registerMessage(++idx, BlockParticleEffectMessage.class, BlockParticleEffectMessage::new);
registerMessage(++idx, CompostParticleMessage.class, CompostParticleMessage::new);
registerMessage(++idx, ItemParticleEffectMessage.class, ItemParticleEffectMessage::new);
registerMessage(++idx, LocalizedParticleEffectMessage.class, LocalizedParticleEffectMessage::new);
registerMessage(++idx, UpdateChunkRangeCapabilityMessage.class, UpdateChunkRangeCapabilityMessage::new);
registerMessage(++idx, OpenSuggestionWindowMessage.class, OpenSuggestionWindowMessage::new);
registerMessage(++idx, UpdateClientWithRecipesMessage.class, UpdateClientWithRecipesMessage::new);

//JEI Messages
registerMessage(++idx, TransferRecipeCrafingTeachingMessage.class);
registerMessage(++idx, TransferRecipeCrafingTeachingMessage.class, TransferRecipeCrafingTeachingMessage::new);
}

/**
* Register a message into rawChannel.
*
* @param <MSG> message class type
* @param id network id
* @param msgClazz message class
* @param <MSG> message class type
* @param id network id
* @param msgClazz message class
* @param msgCreator supplier with new instance of msgClazz
*/
private <MSG extends IMessage> void registerMessage(final int id, final Class<MSG> msgClazz)
private <MSG extends IMessage> void registerMessage(final int id, final Class<MSG> msgClazz, final Supplier<MSG> msgCreator)
{
rawChannel.registerMessage(id, msgClazz, (msg, buf) -> msg.toBytes(buf), (buf) -> {
try
{
final MSG msg = msgClazz.newInstance();
msg.fromBytes(buf);
return msg;
}
catch (final InstantiationException | IllegalAccessException e)
{
e.printStackTrace();
}
return null;
final MSG msg = msgCreator.get();
msg.fromBytes(buf);
return msg;
}, (msg, ctxIn) -> {
final Context ctx = ctxIn.get();
final LogicalSide packetOrigin = ctx.getDirection().getOriginationSide();
Expand Down

0 comments on commit 8060625

Please sign in to comment.