ProjectXV4 - Custom Source

01/12/2015 22:02 Super Aids#1
About ProjectX
ProjectX was the name I used for one of my first "successful" server.
It has now been 4 years since I created the first version of ProjectX in which has become a custom C# source over the years (Since V3.)
ProjectX V4 is the latest version and is a complete custom source written from scratch using the D programming language.
It's not build upon a specific model, but rather my own structure similar to the one used in ProjectX V3.

[Only registered and activated users can see links. Click Here To Register...]

Why D?
D has an excellent implementation of conditional compilation and templates, making dynamic code so much easier and flexible.
D compiles to asm thus able to have an excellent performance and speed.
D gives you the freedom to produce OOP when needed and not forced to wrap everything in classes/namespaces.
D comes with a GC which manages the memory great and a game server can easily leak memory places where you wouldn't expect it,
problems like that are avoided because of the GC.

Source Information
Patch: 5017 (This may change through time, although original patch supports will always be available still.)
Language(s): D
Database: Flatfile (Will be MySql later on.)

About The Source:
This is my first Conquer source in D to ever be written past the auth server. I chose flat file for the database as a start,
because I've never used any real database management systems along with D. However I plan to implement MySql once I finish the base.
I started this source 01-10-2015.

Features: (This will be updated over time.)
[Only registered and activated users can see links. Click Here To Register...]

Installment / Compilation:
[Only registered and activated users can see links. Click Here To Register...]

Source:
[Only registered and activated users can see links. Click Here To Register...]

Wiki/Guides:
[Only registered and activated users can see links. Click Here To Register...]

News/Update Log/TODO:
[Only registered and activated users can see links. Click Here To Register...]

I will update this thread with news about the source and what development has been done.

Thank you! :)
01/14/2015 09:07 .Ocularis#2
Looks really cool.
Compilation was painless with dmd for ubuntu. Didn't log in, though, after launching both services the proverbial lights definitely seem to be on :D

Good work. I'm interested in seeing your D project vs. a couple thousand clientless bots down the road.
01/14/2015 10:03 Super Aids#3
Quote:
Originally Posted by .Ocularis View Post
Looks really cool.
Compilation was painless with dmd for ubuntu. Didn't log in, though, after launching both services the proverbial lights definitely seem to be on :D
Yeah the compilation should be pretty straight forward. Wrote my own tool to just compile the thing myself by dropping an ini file with settings into it. It's really handy for this kind of projects as I'm not using any IDE, but just Notepad++ due to that I don't have a computer of my own and just borrowing one, else I'd probably have went with Visual-D. It's a bit of a pain in the ass to not be able to debug properly, but luckily I'm able to navigate my source with ease.

Ex.
Code:
out=ProjectXV4_Game.exe
cmd={0} -m32 -unittest {1}
extensions=*.d
exclude=out,auth
And yeah same, I wonder how it would seem in a real world usage.

Quote:
Originally Posted by .Ocularis View Post
Good work. I'm interested in seeing your D project vs. a couple thousand clientless bots down the road.
Same, might need some more optimizing too. It's my first server done in D where I've come past the auth server, so I'd say I've done a pretty good job so far as it works smoothly with everything implemented so far.
01/14/2015 15:59 turk55#4
It is unlike you to willingly use MySQL. Perhaps it is because of the support for multi-platform ?
01/14/2015 17:08 Super Aids#5
Quote:
Originally Posted by turk55 View Post
It is unlike you to willingly use MySQL. Perhaps it is because of the support for multi-platform ?
Yeah pretty much.

#Update
Added a wiki page to the GitHub which contains pretty much any information about the source, installation and features. (More to come!)
[Only registered and activated users can see links. Click Here To Register...]
01/14/2015 23:11 dragsh#6
looks awesome cant wait:D!btw when its the release date?
01/15/2015 03:22 turk55#7
Quote:
Originally Posted by Super Aids View Post
Yeah pretty much.

#Update
Added a wiki page to the GitHub which contains pretty much any information about the source, installation and features. (More to come!)
[Only registered and activated users can see links. Click Here To Register...]
If you need some help with database designing, you know where to find me ;)
01/15/2015 08:03 InfamousNoone#8
Quote:
Originally Posted by Super Aids View Post
Why D?
just cuz
ftfy
01/15/2015 15:20 Super Aids#9
Quote:
Originally Posted by turk55 View Post
If you need some help with database designing, you know where to find me ;)
Uhmm nope. That's the least of my problems, considering the database design will pretty much follow the existing one, but just tweaked to use mysql and not ini files. I won't have to edit a lot to implement it tbh.

Quote:
Originally Posted by InfamousNoone View Post
ftfy
Pretty much
01/15/2015 17:19 turk55#10
Quote:
Originally Posted by Super Aids View Post
Uhmm nope. That's the least of my problems, considering the database design will pretty much follow the existing one, but just tweaked to use mysql and not ini files. I won't have to edit a lot to implement it tbh.
There are some features that you could use though, get online at skype and we can talk.
01/15/2015 18:23 ScorpioN[Timur]#11
i need video man :(
01/15/2015 18:28 Super Aids#12
Quote:
Originally Posted by ScorpioN[Timur] View Post
i need video man :(
No you don't.

[Only registered and activated users can see links. Click Here To Register...]
01/15/2015 20:09 .John#13
You seem to like the D.


Jokes aside, not sure why you would choose it though, it has no benefits over C#. Sure, cross-platform is nice... but you can already do it with Mono (with very little penalty to performance). The only reason that comes to mind is you just wanted to fuck with a new language and see what comes out which is pretty insane. Then again, I've done shit like that too because why not.
01/15/2015 20:33 Super Aids#14
Quote:
Originally Posted by .John View Post
You seem to like the D.


Jokes aside, not sure why you would choose it though, it has no benefits over C#. Sure, cross-platform is nice... but you can already do it with Mono (with very little penalty to performance). The only reason that comes to mind is you just wanted to fuck with a new language and see what comes out which is pretty insane. Then again, I've done shit like that too because why not.
I chose it for the template and generic programming implementation, the conditional compilation, fast compile time, not too platform specific within its library such as relying on OS apis and having to write a tons different methods for each platform (The standard library already handles this pretty well with the conditonal compilation / version implementation.) Also because C# requires you to encapsulate everything, which is meh because everything doesn't need to be wrapped in classes etc. with D I only have to use OOP when I really need it, which helps me produce code way faster. I didn't choose it because it might have a slightly better performance, but because I could produce more elegant code faster.

Let me give you an example.
Code:
bool inRange(T)(T x1, T y1, T x2, T y2, T distance) {
	return (getDistance!T(x1, y1, x2, y2) <= distance);
}
Code:
auto findEntitiesInRange(ushort x, ushort y, ushort distance) {
		synchronized {
			MapObject[] res;
			foreach (e; entities.values) {
				if (inRange!ushort(e.x, e.y, x, y, distance))
					res ~= e;
			}
			return res;
		}
	}
If I had to do something like that. First of all I couldn't just have inRange() stored alone for itself in a module like I currently have. I'd have to actually encapsulate it in a class and most likely a static one. That's already a waste of encapsulation, typing and unwanted indent.

Secondly arrays are not dynamic in C# and I'd have to copy arrays for resizing or appending, which I won't need to in D hence why I can just append using "res ~= e". A list does that under the hood too.

This is what the code would look like in C#.
Code:
namespace ConquerSource
{
	public static class Space
	{
		// GetDistance() etc.

		public static bool InRange<T>(T x1, T y1, T x2, T y2, ushort distance) // distance can't be as dynamic in C# as it can be in D...
		{
			return (GetDistance<T>(x1, y1, x2, y2) <= distance);
		}
	}
}
Code:
MapObject[] FindEntitiesInRange(ushort x, ushort y, ushort distance)
{
	lock // If using concurrent dictionaries for entities, not necessary ...
	{
		List<MapObject> res = new List<MapObject>();
		foreach (var e in entities.Values)
		{
			if (Space.InRange<ushort>(e.X, e.Y, x, y, distance))
				res.Add(e); // Copies all the data into a new array with a new capacity, since C# doesn't have dynamic arrays; as below what a waste.
		}
		return res.ToArray(); // Copies all the data rather than just returning the underlying array... lol what a waste
	}
}
Just to find entities in the screen and returning them ex. for 10 players in the screen. It would take 11 array copies. 10 for adding them and 1 for returning the array.

Of course you can just return the list, but still a copy of the array every time you search for players in the screen.

Let's say 10 players in the screen moves 1 space at the same time. That means over a 100 array copies just for that. In D there would be no copies and only 10 arrays returned.

I know it's not something noticable or whatever, but the point remains. I'd write more code for useless operations, no thanks.
01/15/2015 23:17 .John#15
That is ONE way it could look like in c#. It's very poorly done.

Here is another c# source, with a completely different syntax/style that works fast and looks good.

[Only registered and activated users can see links. Click Here To Register...]

It's not 2000 anymore - most devs should take advantage of LINQ and Enuerables. It's a core part of high level logic.

Edit: And to clarify how that code works - a map is split into quandrants (ex: 32x32). Players are split into these quadrants based on their position. When enumerating, this allows us to enumerate over a far smaller range of enitities versus the whole map.

The flatten well... flattens the quadrants so I can select from multiple quadrants at once (as many as i want based on x/y). SelectMany simply selects all the objects based on the given entity types in that quadrant (and once again flattens it), then fiters it down to the radius I need.

No need for synchronization , less looping, and more abstract in terms of what it returns.

Here's an example of usage - very simple, straight forward and easy to understand. It's fast, don't worry.
Code:
                var candidates = Map
                    .Around(Position, ViewRange, MapObjectType.Player)
                    .Cast<IEntity>()
                    .Where(x => !x.Dead)
                    .ToArray();

                if (candidates.Length > 0)
                {
                    Target = candidates.ElementAt(_rand.Next(candidates.Length));
                    LastAttacked = DateTime.UtcNow;
                }