Skip to content

Commit

Permalink
v1.10.15
Browse files Browse the repository at this point in the history
  • Loading branch information
Klemmbaustein committed Jun 27, 2024
1 parent ae89aa7 commit 6e3e5a3
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 64 deletions.
15 changes: 15 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changes

## Version 1.10.15

### Changes

- The server port is no longer a constant.
- Added an error message to the crash handler if it crashes.
- Added `Sound::Enabled`.

### Fixes

- Fixed auto complete being in reverse alphabetical order.
- Fixed a server crash if the current port was already in use.
- Removed some unused #include-statements.
- Fixed `RenderSubsystem.h` being considered as a ClCompile item by msbuild.

## Version 1.10.14

### Changes
Expand Down
2 changes: 1 addition & 1 deletion EngineSource/Engine.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<ClCompile Include="Objects\Components\PhysicsComponent.cpp" />
<ClCompile Include="Rendering\RenderSubsystem\OcclusionCulling.cpp" />
<ClCompile Include="Rendering\RenderSubsystem\RenderSubsystem.cpp" />
<ClCompile Include="Rendering\RenderSubsystem\RenderSubsystem.h" />
<ClInclude Include="Rendering\RenderSubsystem\RenderSubsystem.h" />
<ClCompile Include="UI\Debug\ConsoleAutoComplete.cpp" />
<ClCompile Include="UI\EditorUI\AssetBrowser.cpp" />
<ClCompile Include="UI\EditorUI\ClassesBrowser.cpp" />
Expand Down
7 changes: 1 addition & 6 deletions EngineSource/Engine/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <Engine/EngineError.h>
#include <Engine/File/Assets.h>
#include <Engine/Stats.h>
#include <Engine/Gamepad.h>

#include <Engine/Subsystem/Console.h>
#include <Engine/Subsystem/Sound.h>
Expand Down Expand Up @@ -40,11 +39,7 @@
// STL includes
#include <iostream>
#include <thread>
#include <deque>
#include <cstdint>
#include <mutex>
#include <chrono>
#include <condition_variable>
#include <Rendering/RenderSubsystem/PostProcess.h>

static Vector2 GetMousePosition()
Expand Down Expand Up @@ -396,7 +391,7 @@ int Application::Initialize(int argc, char** argv)
#if !EDITOR
if (Project::UseNetworkFunctions)
{
Subsystem::Load(new NetworkSubsystem());
Subsystem::Load(new NetworkSubsystem(12345));
}
#endif

Expand Down
4 changes: 4 additions & 0 deletions EngineSource/Engine/EngineError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ static void HandleSignal(int SignalID)
{
if (Failed)
{
Log::Print("Crash handler crashed.", Log::LogColor::Red);
return;
}
Failed = true;

// Do not crash again due to the abort() call in AssertFailure()
signal(SIGABRT, nullptr);

Error::AssertFailure(SignalTypes[SignalID], Stats::EngineStatus);
}

Expand Down
2 changes: 1 addition & 1 deletion EngineSource/Engine/EngineProperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Project
void OnLaunch();
extern const char* ProjectName;
}
#define VERSION_STRING "1.10.14"
#define VERSION_STRING "1.10.15"
#define OPENGL_MIN_REQUIRED_VERSION "GL_VERSION_4_2"

/**
Expand Down
12 changes: 0 additions & 12 deletions EngineSource/Engine/Subsystem/Console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,18 +232,6 @@ Console::Console()
}, { Command::Argument("pack_file", NativeType::String) }));


RegisterCommand(Command("find",
[]() {
std::string File = Assets::GetAsset(ConsoleSystem->CommandArgs()[0]);
if (File.empty())
{
ConsoleSystem->Print("Could not find " + ConsoleSystem->CommandArgs()[0], ErrorLevel::Error);
return;
}
ConsoleSystem->Print(ConsoleSystem->CommandArgs()[0] + " -> " + File);

}, { Command::Argument("file", NativeType::String) }));

RegisterCommand(Command("open", []() {
if (std::filesystem::exists(Assets::GetAsset(ConsoleSystem->CommandArgs()[0] + +".jscn")))
{
Expand Down
4 changes: 2 additions & 2 deletions EngineSource/Engine/Subsystem/NetworkSubsystem.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "NetworkSubsystem.h"
#include <Networking/Networking.h>

NetworkSubsystem::NetworkSubsystem()
NetworkSubsystem::NetworkSubsystem(uint16_t DefaultServerPort)
{
Name = "Network";
#if !EDITOR
Networking::Init();
Networking::Init(DefaultServerPort);
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion EngineSource/Engine/Subsystem/NetworkSubsystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class NetworkSubsystem : public Subsystem
{
public:
NetworkSubsystem();
NetworkSubsystem(uint16_t DefaultServerPort);
~NetworkSubsystem();

void Update() override;
Expand Down
11 changes: 4 additions & 7 deletions EngineSource/Engine/Subsystem/Sound.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
#include "Sound.h"
#if !SERVER
#include <AL/al.h>
#include <Engine/Utility/FileUtility.h>
#include <AL/alc.h>
#include "AL/alext.h"
#include <fstream>
#include <sstream>
#include <cmath>
#include <Engine/Log.h>
#include <Rendering/Camera/Camera.h>
#include <Engine/File/Assets.h>
#include <fstream>
#include <iostream>
#include <Rendering/Graphics.h>
#include <filesystem>
Expand Down Expand Up @@ -156,7 +152,7 @@ void Sound::Update()
ForwardVec = Vector3(0, 0, 1);
}
Vector3 Forward[2] = { ForwardVec, Vector3(0, 1, 0) };
alListenerf(AL_GAIN, MasterVolume);
alListenerf(AL_GAIN, MasterVolume * float(Enabled));
alListenerfv(AL_POSITION, &PositionVec.X);
alListenerfv(AL_ORIENTATION, &Forward[0].X);
for (int i = 0; i < CurrentSources.size(); i++)
Expand Down Expand Up @@ -193,7 +189,7 @@ Sound::Sound()
alcMakeContextCurrent(context);
alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED);
alListenerf(AL_GAIN, 1.1f);
Console::ConsoleSystem->RegisterCommand(Console::Command("play_sound", []()
Console::ConsoleSystem->RegisterCommand(Console::Command("sound_play", []()
{
auto LoadedBuffer = new SoundBuffer(Console::ConsoleSystem->CommandArgs()[0]);
if (LoadedBuffer)
Expand All @@ -205,6 +201,7 @@ Sound::Sound()
Console::ConsoleSystem->Print("Sound " + Console::ConsoleSystem->CommandArgs()[0] + " doesn't exist!", ErrorLevel::Error);
}, { Console::Command::Argument("sound", NativeType::String) }));
Console::ConsoleSystem->RegisterConVar(Console::Variable("sound_volume", NativeType::Float, &MasterVolume, nullptr));
Console::ConsoleSystem->RegisterConVar(Console::Variable("sound_enabled", NativeType::Bool, &Enabled, nullptr));

Update();
#endif
Expand Down
1 change: 1 addition & 0 deletions EngineSource/Engine/Subsystem/Sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Sound : public Subsystem
};

float MasterVolume = 1.0f;
bool Enabled = true;

Sound();
virtual ~Sound() override;
Expand Down
57 changes: 31 additions & 26 deletions EngineSource/Networking/Networking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

namespace Networking
{
constexpr uint16_t DEFAULT_PORT = 1234;
constexpr uint32_t TICK_RATE = 64;

void InitPacket(IPaddress* Target);
Expand All @@ -43,52 +42,53 @@ namespace Networking
uint64_t GameTick = 0;
bool IsServerTickFrame = false;
uint64_t NetIDCounter = 0;

static uint16_t DefaultPort = 0;
}

void Networking::InitPacket(IPaddress* Target)
{
SentPacket = SDLNet_AllocPacket(Packet::MAX_PACKET_SIZE);
if (!SentPacket)
{
printf("Could not allocate receiving packet\n");
exit(3);
Log::Print("Could not allocate receiving packet", Log::LogColor::Red);
}
}

void Networking::InitSockets(uint16_t Port)
{
if (!(Socket = SDLNet_UDP_Open(Port)))
{
printf("Could not create socket\n");
exit(1);
Log::Print(StrUtil::Format("Could not create socket on port '%i'", int(Port)), Log::LogColor::Red);
return;
}

IPaddress* CurrentAddress = SDLNet_UDP_GetPeerAddress(Socket, -1);
if (!CurrentAddress)
{
printf("Could not get own port\n");
exit(2);
Log::Print("Could not get own port", Log::LogColor::Red);
return;
}

SocketSet = SDLNet_AllocSocketSet(2);
if (SocketSet == NULL)
{
fprintf(stderr, "Couldn't create socket set: %s\n", SDLNet_GetError());
exit(2);
Log::Print(StrUtil::Format("Couldn't create socket set: %s\n", SDLNet_GetError()), Log::LogColor::Red);
return;
}

auto UsedSockets = SDLNet_UDP_AddSocket(SocketSet, Socket);
if (UsedSockets == -1)
{
printf("SDLNet_AddSocket: %s\n", SDLNet_GetError());
exit(2);
Log::Print(StrUtil::Format("SDLNet_AddSocket: %s\n", SDLNet_GetError()), Log::LogColor::Red);
return;
}

SentPacket = SDLNet_AllocPacket(Packet::MAX_PACKET_SIZE);
if (!SentPacket)
{
printf("Could not allocate packet\n");
exit(2);
Log::Print("Could not allocate packet", Log::LogColor::Red);
return;
}
Log::Print(StrUtil::Format("[Net]: Listening on port %i", Port), Log::LogColor::Blue);
}
Expand All @@ -98,25 +98,25 @@ UDPsocket Networking::InitSocketFrom(IPaddress* Target)
UDPsocket fret;
if (!(fret = SDLNet_UDP_Open(0)))
{
printf("Could not create socket\n");
Log::Print("Could not create socket", Log::LogColor::Red);
SDLNet_Quit();
SDL_Quit();
exit(1);
return nullptr;
}

IPaddress* CurrentAddress = SDLNet_UDP_GetPeerAddress(fret, -1);
if (!CurrentAddress)
{
printf("Could not get own port\n");
exit(2);
Log::Print("Could not get own port", Log::LogColor::Red);
return nullptr;
}

UDPsocket rcvS;
rcvS = SDLNet_UDP_Open(CurrentAddress->port);
if (!rcvS)
{
printf("Could not allocate receiving socket\n");
exit(4);
Log::Print(StrUtil::Format("Could not allocate receiving socket: %s\n", SDLNet_GetError()), Log::LogColor::Red);
return nullptr;
}

//resolve the address of the server
Expand All @@ -126,14 +126,14 @@ UDPsocket Networking::InitSocketFrom(IPaddress* Target)
SocketSet = SDLNet_AllocSocketSet(2);
if (SocketSet == NULL)
{
fprintf(stderr, "Couldn't create socket set: %s\n", SDLNet_GetError());
exit(2);
Log::Print(StrUtil::Format("Couldn't create socket set: %s\n", SDLNet_GetError()), Log::LogColor::Red);
return nullptr;
}
auto UsedSockets = SDLNet_UDP_AddSocket(SocketSet, fret);
if (UsedSockets == -1)
{
printf("SDLNet_AddSocket: %s\n", SDLNet_GetError());
exit(2);
Log::Print(StrUtil::Format("SDLNet_AddSocket: %s\n", SDLNet_GetError()), Log::LogColor::Red);
return nullptr;
}
InitPacket(&srvHost);
return fret;
Expand Down Expand Up @@ -201,16 +201,17 @@ void Networking::SendObjectInfo(WorldObject* obj, void* TargetAddr)
}
}

void Networking::Init()
void Networking::Init(uint16_t DefaultPort)
{
Networking::DefaultPort = DefaultPort;
SDLNet_Init();

#if SERVER
InitSockets(DEFAULT_PORT);
InitSockets(DefaultPort);
#else
Console::ConsoleSystem->RegisterCommand(Console::Command("connect", []()
{
uint16_t Port = DEFAULT_PORT;
uint16_t Port = Networking::DefaultPort;

if (Console::ConsoleSystem->CommandArgs().size() > 1)
{
Expand Down Expand Up @@ -345,6 +346,10 @@ std::string Networking::ClientIDToString(uint64_t ID)
}
return "Client " + std::to_string(ID);
}
uint16_t Networking::GetDefaultPort()
{
return DefaultPort;
}
#endif

// TODO: Have a map of all replicated objects to speed this up.
Expand Down
3 changes: 2 additions & 1 deletion EngineSource/Networking/Networking.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class WorldObject;

namespace Networking
{
void Init();
void Init(uint16_t DefaultPort);
void HandleTick();
void ReceivePackets();
void Update();
Expand All @@ -27,6 +27,7 @@ namespace Networking

std::string ClientIDToString(uint64_t ID);

uint16_t GetDefaultPort();
}
#endif

Expand Down
9 changes: 6 additions & 3 deletions EngineSource/Networking/Packet.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
#if !EDITOR
#include "Packet.h"
#include <Engine/Log.h>
#include "Networking.h"
#include "NetworkEvent.h"
#include "NetworkingInternal.h"
#include <iostream>
#include <Networking/Server.h>
#include <Networking/Client.h>
#include <Engine/Utility/StringUtility.h>
#include <Objects/WorldObject.h>
#include <Engine/Subsystem/Scene.h>
#include <thread>
#include <mutex>
#include <condition_variable>
#include "Networking.h"

const int Packet::MAX_PACKET_SIZE = 512;
uint64_t Packet::PacketID = 0;
Expand Down Expand Up @@ -185,6 +183,10 @@ void PacketReceive()
{
while (true)
{
if (!Networking::SocketSet)
{
return;
}
int ret = SDLNet_CheckSockets(Networking::SocketSet, 150);
if (ret == -1)
{
Expand Down Expand Up @@ -277,4 +279,5 @@ void Packet::SetReceivePackets(bool NewRecv)
{
RecvPacket = true;
}

#endif
Loading

0 comments on commit 6e3e5a3

Please sign in to comment.