Register for your free account! | Forgot your password?

You last visited: Today at 02:41

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



ProjectXV4 - Custom Source

Discussion on ProjectXV4 - Custom Source within the CO2 PServer Guides & Releases forum part of the CO2 Private Server category.

Reply
 
Old 01/16/2015, 18:04   #16
 
Super Aids's Avatar
 
elite*gold: 0
Join Date: Dec 2012
Posts: 1,761
Received Thanks: 950
Quote:
Originally Posted by .John View Post
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.



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;
                }
It exists in D too though.





Super Aids is offline  
Old 01/16/2015, 21:46   #17
 
elite*gold: 0
Join Date: Feb 2010
Posts: 43
Received Thanks: 43
I understand it exists in D... so back to the original question - why D if C# provides all this, and more. Like I said... the only valid reason I see is you just wanted to experiment with it.

Also, while I'm not sure, nor do I have data - I think C# actually compiles just as fast, if not faster than D, and generic programming patterns in C# are far better than D. Also D looks pretty ugly from a syntax / design point of view.
.John is offline  
Thanks
1 User
Old 01/17/2015, 12:56   #18
 
Super Aids's Avatar
 
elite*gold: 0
Join Date: Dec 2012
Posts: 1,761
Received Thanks: 950
Quote:
Originally Posted by .John View Post
I understand it exists in D... so back to the original question - why D if C# provides all this, and more. Like I said... the only valid reason I see is you just wanted to experiment with it.

Also, while I'm not sure, nor do I have data - I think C# actually compiles just as fast, if not faster than D, and generic programming patterns in C# are far better than D. Also D looks pretty ugly from a syntax / design point of view.
That's your opinion. Also what does C# provide that D doesn't? Generic programming paterns in C# are not better than D, since D can access variables and any types of functions pretty much at compile time, then D templates beats C# generics and even C++ templates. You can write in the exact same syntax as C# if you want to, however there is a standard guideline of course which most people follow. I can't see how D has an ugly syntax when it pretty much follows a traditional C syntax except for the way templates are accessed using !template_params rather than <template_params>. D has conditional programming, contracts and unittesting implemented in the language. C# has neither of them, except for maybe some preprocessor, but that again sucks IMO.

Let's do some comparisons with D and C#.

Appending to an array in C#
Code:
Array.Resize(a, a.Length + 1);
a[a.Length - 1] = value;
Appending to an array in D
Code:
a ~= value;
Creating a hash map in C#.
Code:
Dictionary<TKey,TValue> dict = new Dictionary<TKey,TVvalue>();
Creating a hash map in D.
Code:
TValue[TKey] dict;
Variadic parameters in C#.
Code:
MyFunction(int param1, int param2, params T[] variadicParams)
Variadic parameters in D.
Code:
myFunction(int param1, int param2, ...)
The usage seem to be better in C# as it handles the actual parameter retrieving where you have to do it yourself using va_start and va_args in D.

Properties in C#.
Code:
int myInt;
int MyInt
{
	get { return myInt; }
	set
	{
		if (value > 100)
			value = 100;
		myInt = value;
	}
}
Properties in D.
Code:
int _myInt;
@property {
	int myInt() { return m_myInt; }
	void myInt(int value) {
		m_myInt = value;
	}
}
The layout is better in C#, but the abstraction is better in D as you can choose the get and set types yourself. In C# the get and set type has to be equal.

Constructors in C#.
Code:
public class MyBaseClass
{
	int MyBaseValue;
	public MyBaseClass(int value)
	{
		MyBaseValue = value;
	}
}
public class MyClass : MyBaseClass
{
	public MyBaseClass(int value)
		: base(value)
	{
	}
}
Constructors in D.
Code:
class MyBaseClass {
	int myBaseValue;
	this(int value) {
		myBaseValue = value;
	}
}
class MyClass : MyBaseClass {
	this(int value) {
		super(value);
	}
}
D constructors are superior in the sense that you can call base (super) constructors anywhere within your constructor body and you can call other constructors too wherever you want.
This makes sense if you want to do some stuff before initializing the base class.

Changing the string length in C#.
Code:
// Way 1
var sb = new StringBuilder(myString);
sb.Length = newLength;
myString = sb.ToString();

// Way 2
myString = myString.SubString(0, newLength);
Changing the string length in D.
Code:
myString.length = newLength;
D strings are superior to C# strings, because they're treated exactly as arrays and not as an object type. Which means resizing an array in D is the same way, unlike C# where you have to call a Array.Resize() etc.
also C# requires a lot of copying to do such things, which isn't necessary in D.

Slicing an array in C#
Code:
// Way 1
var sliced = new T[sliceSize];
Array.Copy(myArray, sliceStart, sliced, 0, sliceLength);

// Way 2
var sliced = myArray.Take(sliceLength); // Forced at offset 0 I think so...

// Way 3
var segment = new ArraySegment<T>(myArray, sliceStart, sliceLength);
Slicing an array in D
Code:
auto sliced = myArray[sliceStart .. sliceEnd];
Note: The $ symbol equals the length of the identifier ex.
Code:
auto sliced = myArray[0 .. $];
Creates a slice of the whole array.

D slices are superior to C# slices because it doesn't create a new array, it points directly to the original data. So if you modify the slice you also modify the original array.
If you want to copy you can use .dup which duplicates the array to a mutable array or .idup which duplicates the array to an immutable (read only) array.

Ref/Out parameters in C#
Code:
// Declaration
MyFunction(ref myRef)
// Call
MyFunction(ref passedVar);
Ref/Out parameters in D
Code:
// Declaration
myFunction(ref myRef)
// Call
myFunction(passedVar);
String enums in C#
Code:
N/A unless you do some "hacking" using attributes, but the enumeration value still need a primitive type.
String enums in D
Code:
enum MyEnum {
	value1 = "Hello",
	value2 = "World!"
}
C# LINQ VS D
Code:
// C# | D
// Set
Distinct | uniq
Except | setDifference
Intersect | setIntersection
Union | setUnion
// Aggregration
Aggregrate | reduce
Average | N/A
Count | count
Min | min
Max | max
// Sorting
OrderBy | sort
OrderByDescending | sort
ThenBy | N/A
ThenByDescending | N/A
Reverse | reverse
// Other
Where | filter
GroupBy | group
Contains | canFind
Repeat | fill
SequenceEqual | equal
Concat | join
LINQ seems to be more complete in C#, but it has also existed far longer. D is a relative new language, but has expanded so much in the past few years.

IMO I chose D because I can produce codes faster in D and it's more obvious what my code does. The whole .NET library is so ugh, it does so many illogical operations behind the scene and IMO I'd like to know what's going on.
An example is Array.Resize() the logical explanation for it is that it resizes an array. However it doesn't really resize. It just makes a new array with a new size and copies the data from the old array into the new array.
Also I like the fact that I don't have to encapsulate everything and only when needed. There is a lot other things that made me choose D over C#.

Notice: I left out some features in D that C# doesn't have as it had to be a comparison like C# can't do inline asm, contracts as build in, conditional compliation (static if, version etc.) I tried to compare common things with C# and D that they do differently.

IMO the only things I think are better in C# than D is properties and variadic parameters.

#Edit got another thing to compare
Looping a hash map in C#
Code:
foreach (var keyValue in dict)
{
	keyValue.Key // Key
	keyValue.Value // Value
}
Looping a hash map in D
Code:
foreach (key, value; dict) {
	// ...
}
Looping by range in C#
Code:
for (int i = 0; i < 10; i++)
{
	// ...
}
Looping by range in D (Of course there is for loops too.
Code:
foreach (i; 0 .. 10) {
	// ...
}
Parallele foreach in C#
Code:
Parallel.ForEach(a, elem =>
{
    // ... use elem
});
Parallele foreach in D
Code:
foreach (i, ref elem; taskPool.parallel(a)) {
    // ... use elem OR i
}
Okay I think that's it. I'm not saying D does these things better, this is merely a comparison, but IMO I like the way D does the things better.

As a last thing I think you should read this
Super Aids is offline  
Old 01/17/2015, 20:36   #19
 
elite*gold: 0
Join Date: Feb 2010
Posts: 43
Received Thanks: 43
Quote:
Originally Posted by Super Aids View Post
Appending to an array in C#
Code:
Array.Resize(a, a.Length + 1);
a[a.Length - 1] = value;
Appending to an array in D
Code:
a ~= value;
This is such bad design. We have lists for this very reason. The simple fact that you have to resort to resizing an array (by 1 especially) shows that you really don't know much about c#, or D, or programming. Arrays should rarely be used within higher level logic. Let the API handle that for you through lists.

Quote:
Originally Posted by Super Aids View Post
Creating a hash map in C#.
Code:
Dictionary<TKey,TValue> dict = new Dictionary<TKey,TVvalue>();
Creating a hash map in D.
Code:
TValue[TKey] dict;
What are you trying to prove here? I can go ahead and give you another example, which proves nothing.

Code:
var monsters = Database.Monsters.ToDictionary(x => x.Id);
Quote:
Originally Posted by Super Aids View Post
Variadic parameters in C#.
Code:
MyFunction(int param1, int param2, params T[] variadicParams)
Variadic parameters in D.
Code:
myFunction(int param1, int param2, ...)
The usage seem to be better in C# as it handles the actual parameter retrieving where you have to do it yourself using va_start and va_args in D.
They're called var args (variable arguments), not variable dictionaries. And they are awesome in c# (constraints and it's an array)

Quote:
Originally Posted by Super Aids View Post
Properties in C#.
Code:
int myInt;
int MyInt
{
	get { return myInt; }
	set
	{
		if (value > 100)
			value = 100;
		myInt = value;
	}
}
Properties in D.
Code:
int _myInt;
@property {
	int myInt() { return m_myInt; }
	void myInt(int value) {
		m_myInt = value;
	}
}
Your C# could use a bit better formatting / design

Code:
public PropertyType SomeProperty { get; private set; }

//better yet
private PropertyType _propertyType;

public PropertyType PropertyType { get { return _propertyType ?? (_propertyType = new PropertyType()); } }
Quote:
Originally Posted by Super Aids View Post
The layout is better in C#, but the abstraction is better in D as you can choose the get and set types yourself. In C# the get and set type has to be equal.
And C# does it right. A property should not be using multiple types. That creates confusion and could potentially cause issues for those who aren't fully familiar with the code.

Also, C# has implicit / explicit conversion if you really want to use properties with different types

Quote:
Originally Posted by Super Aids View Post
Constructors in C#.
Code:
public class MyBaseClass
{
	int MyBaseValue;
	public MyBaseClass(int value)
	{
		MyBaseValue = value;
	}
}
public class MyClass : MyBaseClass
{
	public MyBaseClass(int value)
		: base(value)
	{
	}
}
Constructors in D.
Code:
class MyBaseClass {
	int myBaseValue;
	this(int value) {
		myBaseValue = value;
	}
}
class MyClass : MyBaseClass {
	this(int value) {
		super(value);
	}
}
D constructors are superior in the sense that you can call base (super) constructors anywhere within your constructor body and you can call other constructors too wherever you want.
This makes sense if you want to do some stuff before initializing the base class.
I've never found a reason to do this. When I build a class it seems logical that constructor initialization follows a hierarchy of the base classes always being implemented before the super class. Pretty good standards imo. Sure you could initialize it later on, but once again for someone not familiar with the code, this could cause potential issues.

Quote:
Originally Posted by Super Aids View Post
Changing the string length in C#.
Code:
// Way 1
var sb = new StringBuilder(myString);
sb.Length = newLength;
myString = sb.ToString();

// Way 2
myString = myString.SubString(0, newLength);
Changing the string length in D.
Code:
myString.length = newLength;
D strings are superior to C# strings, because they're treated exactly as arrays and not as an object type. Which means resizing an array in D is the same way, unlike C# where you have to call a Array.Resize() etc.
also C# requires a lot of copying to do such things, which isn't necessary in D.
This is such a bad example I actually laughed out loud. Strings are immutable. They should NOT give you the ability to change the length without re-creating the string. I cant believe D actually implemented this.... You might want to remove this example... I've already had quite a few devs laugh at this.

Quote:
Originally Posted by Super Aids View Post
Slicing an array in C#
Code:
// Way 1
var sliced = new T[sliceSize];
Array.Copy(myArray, sliceStart, sliced, 0, sliceLength);

// Way 2
var sliced = myArray.Take(sliceLength); // Forced at offset 0 I think so...

// Way 3
var segment = new ArraySegment<T>(myArray, sliceStart, sliceLength);
Slicing an array in D
Code:
auto sliced = myArray[sliceStart .. sliceEnd];
Note: The $ symbol equals the length of the identifier ex.
Code:
auto sliced = myArray[0 .. $];
Creates a slice of the whole array.

D slices are superior to C# slices because it doesn't create a new array, it points directly to the original data. So if you modify the slice you also modify the original array.
If you want to copy you can use .dup which duplicates the array to a mutable array or .idup which duplicates the array to an immutable (read only) array.
I'll give you this one, c# doesn't have the synthatic sugar to do this. However.... it does have extensions, which would make it look very close to your D example.

Code:
var splices = someArray.Slice(start,length);

Quote:
Originally Posted by Super Aids View Post
Ref/Out parameters in C#
Code:
// Declaration
MyFunction(ref myRef)
// Call
MyFunction(ref passedVar);
Ref/Out parameters in D
Code:
// Declaration
myFunction(ref myRef)
// Call
myFunction(passedVar);
I've had to use refs a total of 4-5 times in projects with 50k + lines of code. So.... not sure what you're trying to prove here either.

Quote:
Originally Posted by Super Aids View Post
String enums in C#
Code:
N/A unless you do some "hacking" using attributes, but the enumeration value still need a primitive type.
String enums in D
Code:
enum MyEnum {
	value1 = "Hello",
	value2 = "World!"
}
C# enums follow a pretty nice standard... if you want string enums, there's always constants. That, and you can switch on a string.

Quote:
Originally Posted by Super Aids View Post
C# LINQ VS D
Code:
// C# | D
// Set
Distinct | uniq
Except | setDifference
Intersect | setIntersection
Union | setUnion
// Aggregration
Aggregrate | reduce
Average | N/A
Count | count
Min | min
Max | max
// Sorting
OrderBy | sort
OrderByDescending | sort
ThenBy | N/A
ThenByDescending | N/A
Reverse | reverse
// Other
Where | filter
GroupBy | group
Contains | canFind
Repeat | fill
SequenceEqual | equal
Concat | join
LINQ seems to be more complete in C#, but it has also existed far longer. D is a relative new language, but has expanded so much in the past few years.
Except I barely saw any LINQ like usage in your project (at least from the few files I looked through). It should be pretty big part.

Quote:
Originally Posted by Super Aids View Post
IMO I chose D because I can produce codes faster in D and it's more obvious what my code does. The whole .NET library is so ugh, it does so many illogical operations behind the scene and IMO I'd like to know what's going on.
An example is Array.Resize() the logical explanation for it is that it resizes an array. However it doesn't really resize. It just makes a new array with a new size and copies the data from the old array into the new array.
Also I like the fact that I don't have to encapsulate everything and only when needed. There is a lot other things that made me choose D over C#.

Notice: I left out some features in D that C# doesn't have as it had to be a comparison like C# can't do inline asm, contracts as build in, conditional compliation (static if, version etc.) I tried to compare common things with C# and D that they do differently.
Your reasoning is pretty flawed. You don't seem to have a very good understanding of C#, or .NET. I've looked into D for quite a few years, all the way back when it was up and rising (when .NET was in it's infancy, 1.0 and 2.0). Sure it might've looked appealing then... but it stagnated and hasn't shown any real promise. Even Java had a better prospect than D did.

.NET Doesn't do illogical operations behind the scenes - the opposite actually. It often covers all cases in terms of error checking, it follows standards, it's both maintainable and efficient code. I've looked at a LOT of .NET source code over the past few years, and I've personally learned quite a bit about it.

The problem here is, you may know how to code, but you have no concept of design. You mistake good design for flaws in C#. This is a prime example of a 'bad user'. Just because you don't know why it's like that, doesn't mean it's bad. Take strings and arrays, something that have been around for AGES, and you seem to strike up arguments about them. Why don't you look into the ideas, design and principles behind them first.

I would suggest looking at open source .Net projects out there (NOT on epvp). Hell, take a look at corefx (.NET Core - part of .NET 5.0). You could learn a lot about C#.
.John is offline  
Thanks
5 Users
Old 01/17/2015, 21:39   #20
 
Super Aids's Avatar
 
elite*gold: 0
Join Date: Dec 2012
Posts: 1,761
Received Thanks: 950
Quote:
Originally Posted by .John View Post
...
This was all just examples, not practical usage. You seem to misunderstand my point too, as I never claimed D to be better than C#, but rather that I liked to code in D better. Neither of them are better, all depends on what you're doing. This was nothing, but comparisons. Not a "D does this better way" but a "D does it this way which I like better"

Why did you take the code examples literal? You seem to be pretty judgemental towards this. I appreciate your constructive feed back though.

I never really judged the design over all of C#.

Also about the LINQ part, this is my first source ever written in D and I have only worked on it for a week. Over time I'll implement such features, so far it's implemented in my screen system and map system.

Why are we having this biased argument anyway? Kind of pointless.
Super Aids is offline  
Old 01/17/2015, 22:30   #21
 
elite*gold: 0
Join Date: Feb 2010
Posts: 43
Received Thanks: 43
Well, you did open source your project - naturally I had to critique it. That, and I was linked to this thread by someone else. I don't generally go on ePVP very much.
.John is offline  
Old 07/21/2015, 17:56   #22
 
elite*gold: 0
Join Date: Jul 2015
Posts: 3
Received Thanks: 0
download client pls >.<
lksilva2 is offline  
Reply


Similar Threads Similar Threads
[Selling] Custom Source
09/13/2014 - Flyff Trading - 2 Replies
Preview Auto Fooder : https://www.facebook.com/video.php?v=6024555765335 50 Resize Character : https://www.facebook.com/video.php?v=6020283232429 42 CTRL Wing System : https://www.facebook.com/video.php?v=6019933932464 35 Auto Fooder : 40euro Resize Character : 25euro Flying Wing System : 50euro Vip System + User Custom Title : 100euro
[Selling] V19/Custom Source
08/28/2013 - Flyff Trading - 18 Replies
Da MM meine FP gerettet hat verkaufe ich hier nun meine ganze source + datenbank. Was ist drin? V19 Interface -mit v19navi komplett offi actionslot etc. -V19 Coupon System -Madrigal Gift System(official) -V19 Consignment Market -Wing System -Glow System -Pet System
Custom source
04/03/2012 - CO2 Private Server - 4 Replies
#Never mind, solved. To those who replied, thanks.
problem with custom source
11/11/2011 - CO2 Private Server - 0 Replies
based on these 2 guides http://www.elitepvpers.com/forum/co2-pserver-guid es-releases/1531960-guide-coding-your-own-source.h tml http://www.elitepvpers.com/forum/co2-pserver-guid es-releases/776370-guide-faq-lets-make-custom-sour ce.html i coded a base but for some reason i get login freeze what could be causing that



All times are GMT +1. The time now is 02:44.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.