I'm calling this SharpLife, since it's implemented using C#. It isn't limited to that language since it uses Dot Net but that is what i'm working with.
The goal is to port the SDK to C# and then upgrade it with Half-Life Enhanced's bug fixes and additions. Once that's done i can complete the planned changes for that.
Here's a diagram showing the overall design of the framework itself: Here are some examples of how it's easier to work with C# than C++:
[quote]
//Save restoring a field in a class in the SDK:
CBaseEntity* m_pGoalEnt;
static TYPEDESCRIPTION m_SaveData[];
TYPEDESCRIPTION CBaseEntity::m_SaveData[] =
{
DEFINE_FIELD( CBaseEntity, m_pGoalEnt, FIELD_CLASSPTR )
};//Save restoring a field in a class in C#:
[Persist]
public CBaseEntity m_pGoalEnt;
[/quote]
//Getting the name of a class in the SDK:[quote]
const char* pszClassName = STRING( pEntity->pev->classname );
//Getting the name of a class in C#:
var className = pEntity.ClassName;
//Loading an XML file in HLEnhanced:
https://github.com/SamVanheer/HLEnhanced/blob/346a9889f7da589f72cc66a71ee1202fc434714a/game/shared/CWeaponInfoCache.cpp#L154
//Loading an XML file in C#:
try
{
using (var stream = new FileStream("SharpLife/cfg/SharpLife-Wrapper-Managed.xml", FileMode.Open))
{
var serializer = new XmlSerializer(typeof(ServerWrapperConfiguration));
var config = (ServerWrapperConfiguration)serializer.Deserialize(stream);
LoadMod(config.ModInfo);
return true;
}
}catch(Exception e)
{
Log.Message($"{e.GetType().Name} - {e.Message}");
Log.Message(e.StackTrace);
return false;
}[/quote]
It's much easier to manage dependencies than in C++ as well. To use XercesC in HLE you need to download, extract, compile and install it before referencing it in your CMake configuration.
In C# you only need to reference the NuGet package System.Xml.XmlSerializer. Once that's done everybody who checks out the codebase will be able to get the packages by restoring all NuGet packages for the solution.
For less experienced programmers (most modders) the language is easier to use as well. One mistake i've seen made a lot is string comparisons:
const char* somestring = ...;This compares memory addresses, which will always be false.
if("ON" == somestring )
{
//Do something if ON
}
In C# it works like it does in most modern languages:
string somestring = ...;And it does what you'd expect.
if( "ON" == somestring )
{
//Do something if ON
}
For scripting there's no need for Angelscript because you can just load assemblies that can directly access mod code. A simple plugin system would be a list of Dot Net assemblies that are loaded on mod startup that then behave as though they were part of the mod itself.
The language is very similar to Angelscript which is intentional, since Angelscript is based off of both C# and C++.
In addition, there's a scripting language called CSharpScript that is essentially C# code compiled at runtime, much like Angelscript: https://github.com/dotnet/roslyn/wiki/Scripting-API-Samples
By moving to this it'll be easier and faster to continue development, modders can focus on implementing game logic instead of working around language limitations and quirks.
It will take some time to implement, but right now the biggest issue is getting the native<->managed code interop working. I have the necessarily functionality done for that, so it's just getting the interfaces for the server done, then re-implementing everything piece by piece.
The priority is making sure the game can load and run with a minimal codebase, so most entities won't work yet for some time.
I'm hoping once that's done i can implement the physics code re-implementation, which will allow for parenting, and then if i have time and motivation implementing a new networking system to transfer data to clients. The client itself will also need to be converted, but it's a bit smaller than the server so that should be simpler.
Best case scenario i can skip the engine entirely and just do everything in C#, which would really make things easy but that's a lot of work and i don't know if i'll still have time and motivation for that.