Skip to content

Commit

Permalink
Feature: Local Multiplayer Support (#2)
Browse files Browse the repository at this point in the history
* conformed to updated EmulatorBridging protocol to allow for local multiplayer support, and implements sending per-player inputs to the emulator core

* updates based on PR feedback

---------

Co-authored-by: Ian Clawson <ianclawson@Ians-MBP-2.guidecx>
  • Loading branch information
ianclawson and Ian Clawson committed Nov 17, 2023
1 parent 5ffdc3b commit 7dae837
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
8 changes: 4 additions & 4 deletions NESDeltaCore/Bridge/NESEmulatorBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,11 @@ public extension NESEmulatorBridge
}
}

func activateInput(_ input: Int, value: Double)
func activateInput(_ input: Int, value: Double, playerIndex: Int)
{
#if NATIVE

NESActivateInput(Int32(input))
NESActivateInput(Int32(input), Int32(playerIndex))

#else

Expand All @@ -345,11 +345,11 @@ public extension NESEmulatorBridge
#endif
}

func deactivateInput(_ input: Int)
func deactivateInput(_ input: Int, playerIndex: Int)
{
#if NATIVE

NESDeactivateInput(Int32(input))
NESDeactivateInput(Int32(input), Int32(playerIndex))

#else

Expand Down
13 changes: 8 additions & 5 deletions NestopiaJS/NESEmulatorBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,19 +174,22 @@ void NESRunFrame()

#pragma mark - Inputs -

void NESActivateInput(int input)
void NESActivateInput(int input, int playerIndex)
{
nes_controllers.pad[0].buttons |= input;
nes_controllers.pad[playerIndex].buttons |= input;
}

void NESDeactivateInput(int input)
void NESDeactivateInput(int input, int playerIndex)
{
nes_controllers.pad[0].buttons &= ~input;
nes_controllers.pad[playerIndex].buttons &= ~input;
}

void NESResetInputs()
{
nes_controllers.pad[0].buttons = 0;
for (int index = 0; index < Nes::Api::Input::NUM_PADS ; index++)
{
nes_controllers.pad[index].buttons = 0;
}
}

#pragma mark - Save States -
Expand Down
4 changes: 2 additions & 2 deletions NestopiaJS/NESEmulatorBridge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ extern "C"

void NESRunFrame();

void NESActivateInput(int input);
void NESDeactivateInput(int input);
void NESActivateInput(int input, int playerIndex);
void NESDeactivateInput(int input, int playerIndex);
void NESResetInputs();

void NESSaveSaveState(const char *_Nonnull saveStatePath);
Expand Down

0 comments on commit 7dae837

Please sign in to comment.