Skip to content

Commit

Permalink
Multiplayer (part 10)
Browse files Browse the repository at this point in the history
  • Loading branch information
deathkiller committed Dec 17, 2023
1 parent 9f8827d commit 717776b
Show file tree
Hide file tree
Showing 19 changed files with 488 additions and 349 deletions.
1 change: 0 additions & 1 deletion Sources/Jazz2.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@
<ClInclude Include="Jazz2\UI\Menu\AboutSection.h" />
<ClInclude Include="Jazz2\UI\Menu\BeginSection.h" />
<ClInclude Include="Jazz2\UI\Menu\ControlsOptionsSection.h" />
<ClInclude Include="Jazz2\UI\Menu\ControlsSection.h" />
<ClInclude Include="Jazz2\UI\Menu\CreateServerOptionsSection.h" />
<ClInclude Include="Jazz2\UI\Menu\CustomLevelSelectSection.h" />
<ClInclude Include="Jazz2\UI\Menu\EpisodeSelectSection.h" />
Expand Down
12 changes: 9 additions & 3 deletions Sources/Jazz2.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -963,9 +963,6 @@
<ClInclude Include="Jazz2\UI\ControlScheme.h">
<Filter>Header Files\Jazz2\UI</Filter>
</ClInclude>
<ClInclude Include="Jazz2\UI\Menu\ControlsSection.h">
<Filter>Header Files\Jazz2\UI\Menu</Filter>
</ClInclude>
<ClInclude Include="Jazz2\Actors\Enemies\TurtleTough.h">
<Filter>Header Files\Jazz2\Actors\Enemies</Filter>
</ClInclude>
Expand Down Expand Up @@ -1458,6 +1455,12 @@
<ClInclude Include="Jazz2\UI\Menu\PlayCustomSection.h">
<Filter>Header Files\Jazz2\UI\Menu</Filter>
</ClInclude>
<ClInclude Include="Jazz2\Multiplayer\MultiplayerGameMode.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Jazz2\UI\Menu\MultiplayerGameModeSelectSection.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Main.cpp">
Expand Down Expand Up @@ -2420,6 +2423,9 @@
<ClCompile Include="Jazz2\UI\Menu\PlayCustomSection.cpp">
<Filter>Source Files\Jazz2\UI\Menu</Filter>
</ClCompile>
<ClCompile Include="Jazz2\UI\Menu\MultiplayerGameModeSelectSection.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Resources.rc">
Expand Down
5 changes: 3 additions & 2 deletions Sources/Jazz2/Actors/Multiplayer/RemoteActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace Jazz2::Actors::Multiplayer
pos = _stateBuffer[nextIdx].Pos;
}

MoveInstantly(pos, MoveType::Absolute);
MoveInstantly(pos, MoveType::Absolute | MoveType::Force);
}

ActorBase::OnUpdate(timeMult);
Expand All @@ -78,13 +78,14 @@ namespace Jazz2::Actors::Multiplayer
SetState((GetState() & ~RemotedFlags) | (state & RemotedFlags));
}

void RemoteActor::SyncWithServer(const Vector2f& pos, AnimState anim, float rotation, bool isVisible, bool isFacingLeft, Actors::ActorRendererType rendererType)
void RemoteActor::SyncWithServer(const Vector2f& pos, AnimState anim, float rotation, bool isVisible, bool isFacingLeft, bool animPaused, Actors::ActorRendererType rendererType)
{
Clock& c = nCine::clock();
std::int64_t now = c.now() * 1000 / c.frequency();

bool wasVisible = _renderer.isDrawEnabled();
_renderer.setDrawEnabled(isVisible);
_renderer.AnimPaused = animPaused;
SetFacingLeft(isFacingLeft);

if (_lastAnim != anim) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Jazz2/Actors/Multiplayer/RemoteActor.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Jazz2::Actors::Multiplayer
RemoteActor();

void AssignMetadata(const StringView& path, AnimState anim, ActorState state);
void SyncWithServer(const Vector2f& pos, AnimState anim, float rotation, bool isVisible, bool isFacingLeft, Actors::ActorRendererType rendererType);
void SyncWithServer(const Vector2f& pos, AnimState anim, float rotation, bool isVisible, bool isFacingLeft, bool animPaused, Actors::ActorRendererType rendererType);

protected:
struct StateFrame {
Expand Down
7 changes: 6 additions & 1 deletion Sources/Jazz2/Events/EventMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ namespace Jazz2::Events
_generators[generatorIdx].SpawnedActor = nullptr;
}

const EventMap::EventTile& EventMap::GetEventTile(std::int32_t x, std::int32_t y) const
{
return _eventLayout[x + y * _layoutSize.X];
}

EventType EventMap::GetEventByPosition(float x, float y, std::uint8_t** eventParams)
{
return GetEventByPosition((std::int32_t)x / Tiles::TileSet::DefaultTileSize, (std::int32_t)y / Tiles::TileSet::DefaultTileSize, eventParams);
Expand Down Expand Up @@ -332,7 +337,7 @@ namespace Jazz2::Events
memset(eventParams, 0, sizeof(eventParams));
}

Actors::ActorState actorFlags = (Actors::ActorState)(eventFlags & 0x04);
Actors::ActorState actorFlags = (Actors::ActorState)(eventFlags & /*Illuminated*/0x04);

// Flag 0x02: Generator
if ((eventFlags & 0x02) != 0) {
Expand Down
17 changes: 9 additions & 8 deletions Sources/Jazz2/Events/EventMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ namespace Jazz2::Events
class EventMap
{
public:
struct EventTile {
EventType Event;
Actors::ActorState EventFlags;
std::uint8_t EventParams[EventSpawner::SpawnParamsSize];
bool IsEventActive;
};

EventMap(const Vector2i& layoutSize);

void SetLevelHandler(ILevelHandler* levelHandler);
Expand All @@ -37,6 +44,7 @@ namespace Jazz2::Events
void Deactivate(std::int32_t x, std::int32_t y);
void ResetGenerator(std::int32_t tx, std::int32_t ty);

const EventTile& GetEventTile(std::int32_t x, std::int32_t y) const;
EventType GetEventByPosition(float x, float y, std::uint8_t** eventParams);
EventType GetEventByPosition(std::int32_t x, std::int32_t y, std::uint8_t** eventParams);
bool HasEventByPosition(std::int32_t x, std::int32_t y);
Expand All @@ -51,18 +59,11 @@ namespace Jazz2::Events
void SerializeResumableToStream(Stream& dest);

private:
struct EventTile {
EventType Event;
Actors::ActorState EventFlags;
std::uint8_t EventParams[16];
bool IsEventActive;
};

struct GeneratorInfo {
std::int32_t EventPos;

EventType Event;
std::uint8_t EventParams[16];
std::uint8_t EventParams[EventSpawner::SpawnParamsSize];
std::uint8_t Delay;
float TimeLeft;

Expand Down
Loading

0 comments on commit 717776b

Please sign in to comment.