• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 23:48
CEST 05:48
KST 12:48
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
Maestros of the Game: Week 1/Play-in Preview9[ASL20] Ro24 Preview Pt2: Take-Off7[ASL20] Ro24 Preview Pt1: Runway132v2 & SC: Evo Complete: Weekend Double Feature4Team Liquid Map Contest #21 - Presented by Monster Energy9
Community News
Weekly Cups (August 25-31): Clem's Last Straw?7Weekly Cups (Aug 18-24): herO dethrones MaxPax6Maestros of The Game—$20k event w/ live finals in Paris45Weekly Cups (Aug 11-17): MaxPax triples again!15Weekly Cups (Aug 4-10): MaxPax wins a triple6
StarCraft 2
General
Weekly Cups (August 25-31): Clem's Last Straw? #1: Maru - Greatest Players of All Time Maestros of the Game: Week 1/Play-in Preview Weekly Cups (Aug 11-17): MaxPax triples again! 2024/25 Off-Season Roster Moves
Tourneys
Maestros of The Game—$20k event w/ live finals in Paris Monday Nights Weeklies LiuLi Cup - September 2025 Tournaments 🏆 GTL Season 2 – StarCraft II Team League $5,100+ SEL Season 2 Championship (SC: Evo)
Strategy
Custom Maps
External Content
Mutation # 489 Bannable Offense Mutation # 488 What Goes Around Mutation # 487 Think Fast Mutation # 486 Watch the Skies
Brood War
General
ASL20 General Discussion No Rain in ASL20? Victoria gamers Starcraft at lower levels TvP BGH Auto Balance -> http://bghmmr.eu/
Tourneys
Is there English video for group selection for ASL [ASL20] Ro24 Group F [IPSL] CSLAN Review and CSLPRO Reimagined! Small VOD Thread 2.0
Strategy
Simple Questions, Simple Answers Muta micro map competition Fighting Spirit mining rates [G] Mineral Boosting
Other Games
General Games
Stormgate/Frost Giant Megathread General RTS Discussion Thread Nintendo Switch Thread Path of Exile Warcraft III: The Frozen Throne
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Canadian Politics Mega-thread Russo-Ukrainian War Thread YouTube Thread
Fan Clubs
The Happy Fan Club!
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Manga] One Piece [\m/] Heavy Metal Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread High temperatures on bridge(s) Gtx660 graphics card replacement
TL Community
The Automated Ban List TeamLiquid Team Shirt On Sale
Blogs
hello world
radishsoup
Lemme tell you a thing o…
JoinTheRain
How Culture and Conflict Imp…
TrAiDoS
RTS Design in Hypercoven
a11
Evil Gacha Games and the…
ffswowsucks
INDEPENDIENTE LA CTM
XenOsky
Customize Sidebar...

Website Feedback

Closed Threads



Active: 536 users

[Game Programming]Some of my code designs - Page 2

Blogs > Bill307
Post a Reply
Prev 1 2 All
Bill307
Profile Blog Joined October 2002
Canada9103 Posts
July 20 2009 00:37 GMT
#21
On July 17 2009 04:29 King K. Rool wrote:
How is C# for game programming?

As for C# and XNA, I think the fact that nearly-identical code can run on both a Windows PC and an XBox 360 is great. I also think Visual C# is a terrific IDE.

However, I have a number of gripes with the language and with XNA.


1. XNA's Matrix multiplication is backwards. Seriously. If you have two matrices A and B, and you want to transform A by B, then in linear algebra, you'd write "B * A", but in XNA, you'd write "A * B".

I have a strong math background, so for me, this is the biggest WTF by far.


2. The documentation is ass. A while ago, I was trying to figure out exactly when data was copied from your system's memory to your GPU's memory. Repeatedly, I ran into such detailed documentation as:

http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.vertexbuffer.aspx

VertexBuffer Class
Represents a list of 3D vertices to be streamed to the graphics device.

Useless.

Another example: I was trying to see how to load a custom Effect file on the XBox 360 without going through the ContentManager, or if this was even possible. I still don't know if this is possible or not, actually: after searching for hours I gave up and changed the way my code worked instead.

After learning much of my Java knowledge by reading its incredibly-detailed API documentation, XNA's documentation was hugely disappointing.


3. C# Properties. Properties in C# are used like variables, but they are accessed through "get" and "set" methods.

For example, suppose you want to change an enemy's hitpoints. In Java, you'd do something like this:

oldHP = enemy.GetHitpoints();
enemy.SetHitpoints(newHP);

Using a C# Property, you would instead write:

oldHP = enemy.Hitpoints;
enemy.Hitpoints = newHP;

When you access enemy.Hitpoints, you are actually calling the Property's "get" method, and when you assign it a new value, you are calling the Property's "set" method.

Maybe you can already start to see why Properties can cause problems...


3a. The naming convention for Properties.

Suppose my game class has a Camera variable. Naturally it'll be called "camera". Now suppose I want other classes to be able to access it. The C# way is to use a public Property, called "Camera". Great, a variable with the same name as a class!

In general, Properties look like classes or inner classes when you use them. The only visual cue is Visual C#'s syntax highlighting, where classes are written in teal while Properties are written in black.


3b. Properties are operator overloading.

The danger of using public variables is that somewhere down the road, you might want to run some additional code whenever a variable is changed, e.g. to send an event when an enemy loses hitpoints, but if the public variable is being changed directly, then you can't do that.

On the other hand, it's a lot easier to get and set public variables versus having to type GetValue() and SetValue() every time, not to mention having to write these methods. Indeed, it can get tiring to write these methods over and over when 99% of the time, all they do is set and get a variable.

At a glance, Properties seem like a solution to this problem. Syntactically, they're used just like a public variable, but they also allow you to run some additional code whenever a variable is set or retrieved, which is the benefit of writing GetValue() and SetValue() methods.

But they're really just operator overloading, complete with all the problems of it.

Operator overloading abuse aside, 99% of the time, when you see a Property it's going to be simple get/set one, that acts just like getting and setting a variable. So when that 1% case comes up, where the get/set does something else, it can be confusing for everyone, even the original author if he's away from his code for too long. In contrast, when you have to call GetValue() or SetValue(), it's a visual reminder that you might be doing more than just getting or setting the variable.



Needless to say, while I'm forced to use the Properties built into C# and XNA, I completely avoid using Properties myself.
FreeZEternal
Profile Joined January 2003
Korea (South)3396 Posts
Last Edited: 2009-07-20 02:00:06
July 20 2009 01:55 GMT
#22
Maybe this is just a gaming thing where every milliseconds count but from experience, object allocation is VERY cheap these days (at least in the JVM. I would assume the same in the CLR), in some cases even cheaper than in C++. Object pooling do have their uses but they can be error prone (memory leak, etc) because the scope the object gets bigger. I would say in the majority of cases, it's always better to narrow the scope of your objects. Anyways this is for general programming, but for gaming I may be completely wrong since every milliseconds count.
FreeZEternal
Profile Joined January 2003
Korea (South)3396 Posts
Last Edited: 2009-07-20 02:04:05
July 20 2009 02:03 GMT
#23
On July 17 2009 20:53 MasterOfChaos wrote:
Did you do any measurements to determine that object allocation limits performance?
And why do you have so many different managers?
@freelander
Simply compress it afterwards?


I think what Bill meant with "Object Allocation limit" is that when you start creating thousands of objects over and over, GC will take a toll. Usually the GC overhead is negligible in business apps as long as you avoid nasty Full GC, but for gaming I would assume everything counts.
MasterOfChaos
Profile Blog Joined April 2007
Germany2896 Posts
July 20 2009 07:34 GMT
#24
I think I have read almost every article about the .net GC in existance because I simply can't get myself to really trust such a beast. The problem is that my current game design uses lots(perhaps 100k) of small objects.
But I guess I'll simply hope that .net 4.0's background GC is good enough.

The one thing I fear the most is not deterministic behaviour. My networkcode(and replays) require that the game runs completly deterministic given the same input on different machines. For example this means I can't use any floats inside the gamelogic(I have implemented a fixedpoint struct). Other things which might get problematic are GetHashCode, iteration over the entries of a dictionary, weakreferences, and probably a lot of features I don't even know about yet -_-

Personally I like properties and the naming conventions of C# a lot, because it's basically the same as in Delphi.
The one thing where they are counter intuitive is if you have a property of a mutable struct type and call a method which modifies it. As the method is called on a copy of the struct(it is returned by value) the property will not be changed. But mutable structs are usually bad style anyways.
LiquipediaOne eye to kill. Two eyes to live.
evanthebouncy!
Profile Blog Joined June 2006
United States12796 Posts
July 20 2009 07:49 GMT
#25
haha learning java now.
Object oriented is fun

Before:
Is_A_equal_to_B(a,b);
After:
a.Do_I_look_Like_That_Other_Dude(b);
Life is run, it is dance, it is fast, passionate and BAM!, you dance and sing and booze while you can for now is the time and time is mine. Smile and laugh when still can for now is the time and soon you die!
MasterOfChaos
Profile Blog Joined April 2007
Germany2896 Posts
July 20 2009 08:52 GMT
#26
On July 20 2009 16:49 evanthebouncy! wrote:
haha learning java now.
Object oriented is fun

Before:
Is_A_equal_to_B(a,b);
After:
a.Do_I_look_Like_That_Other_Dude(b);

IMO the "Before" part is nicer. It reflects the symmetry of a comparison a lot better than the second one. And the second one has the additional disadvantage that it throws if a==null.
LiquipediaOne eye to kill. Two eyes to live.
FreeZEternal
Profile Joined January 2003
Korea (South)3396 Posts
July 20 2009 13:23 GMT
#27
Yeap but equals is a method that comes from the Object class. Usually your classes will override the equals method from the Object class so most projects you see will actually use the "Before" part.
Bill307
Profile Blog Joined October 2002
Canada9103 Posts
July 21 2009 04:40 GMT
#28
On July 20 2009 16:34 MasterOfChaos wrote:
The one thing I fear the most is not deterministic behaviour. My networkcode(and replays) require that the game runs completly deterministic given the same input on different machines. For example this means I can't use any floats inside the gamelogic(I have implemented a fixedpoint struct). Other things which might get problematic are GetHashCode, iteration over the entries of a dictionary, weakreferences, and probably a lot of features I don't even know about yet -_-

Wait... what are the odds that floats will be computed differently on different machines? o_Oa I guess it's not much of a problem for me, since our main target platform is the 360. And if a replay fails on someone else's computer, then at least you can always make a recording of the replay on your own computer.

I don't trust C#'s GetHashCode(), either. Java's hashCode() method will "typically" convert the object's reference address to an int, but the documentation for C#'s method was very vague (as usual -_-).

You could probably implement your own Dictionary without too much trouble, imo. At least then you could guarantee it'll always iterate over its entries in the same order.
Bill307
Profile Blog Joined October 2002
Canada9103 Posts
July 21 2009 04:43 GMT
#29
On July 20 2009 22:23 FreeZEternal wrote:
Yeap but equals is a method that comes from the Object class. Usually your classes will override the equals method from the Object class so most projects you see will actually use the "Before" part.

This reminds me of yet another case of bad C# documentation. -_-

Java's equals() method will return true iff the objects' references are equal. This is written explicitly in the documentation.

C#'s Equals() method, however, doesn't say anything about what it will return by default. (*sigh*)

C# does have a static ReferenceEquals() method for that purpose, though.
MasterOfChaos
Profile Blog Joined April 2007
Germany2896 Posts
July 21 2009 07:28 GMT
#30
If I recall correctly GetHashCode returns some strange SyncObjectID which is determined at allocation time for reference types and the hashcode of the first field for structs. And the predefined valuetypes use sensible overrides.

And the floatingpoint desyncs shouldn't be that uncommon since .net generates CPU dependent code, and the x87 and SSE commands return different results for many calculations. My research showed that it is possible to tweak c++ to get reproducible floatingpoint code, but not .net. So I wrote a 32bit fixedpoint struct.

I think Equals() checks the identity for all fields for valuetypes and reference equality by default for reference types. But I never used it myself except for overriding it in my valuetypes to get rid of some warnings.
I only used == operator, ReferenceEquals and equality comparers.

And if you haven't used it so far, check out redgate reflector. My favourite .net "documentation".
LiquipediaOne eye to kill. Two eyes to live.
evanthebouncy!
Profile Blog Joined June 2006
United States12796 Posts
July 21 2009 08:15 GMT
#31
On July 20 2009 17:52 MasterOfChaos wrote:
Show nested quote +
On July 20 2009 16:49 evanthebouncy! wrote:
haha learning java now.
Object oriented is fun

Before:
Is_A_equal_to_B(a,b);
After:
a.Do_I_look_Like_That_Other_Dude(b);

IMO the "Before" part is nicer. It reflects the symmetry of a comparison a lot better than the second one. And the second one has the additional disadvantage that it throws if a==null.


Hehe yeah but iono, recursion with objects are mad fun
Life is run, it is dance, it is fast, passionate and BAM!, you dance and sing and booze while you can for now is the time and time is mine. Smile and laugh when still can for now is the time and soon you die!
FreeZEternal
Profile Joined January 2003
Korea (South)3396 Posts
July 21 2009 14:59 GMT
#32
On July 21 2009 13:43 Bill307 wrote:
Show nested quote +
On July 20 2009 22:23 FreeZEternal wrote:
Yeap but equals is a method that comes from the Object class. Usually your classes will override the equals method from the Object class so most projects you see will actually use the "Before" part.

This reminds me of yet another case of bad C# documentation. -_-

Java's equals() method will return true iff the objects' references are equal. This is written explicitly in the documentation.

C#'s Equals() method, however, doesn't say anything about what it will return by default. (*sigh*)

C# does have a static ReferenceEquals() method for that purpose, though.


True, Sun did an amazing job documenting Java.
b3h47pte
Profile Blog Joined May 2007
United States1317 Posts
July 21 2009 15:36 GMT
#33
http://msdn.microsoft.com/en-us/library/w4hkze5k.aspx

Return Value
Type: System..::.Boolean
true if the instances are equal; otherwise false.



http://msdn.microsoft.com/en-us/library/bsc2ak47.aspx
Return Value
Type: System..::.Boolean
true if the specified Object is equal to the current Object; otherwise, false.


Not sure how it isn't clear
MasterOfChaos
Profile Blog Joined April 2007
Germany2896 Posts
July 21 2009 15:38 GMT
#34
On July 21 2009 13:43 Bill307 wrote:
C#'s Equals() method, however, doesn't say anything about what it will return by default. (*sigh*)

The Object.Equals documentation is not that bad:
The default implementation of Equals supports reference equality for reference types, and bitwise equality for value types. Reference equality means the object references that are compared refer to the same object. Bitwise equality means the objects that are compared have the same binary representation.
LiquipediaOne eye to kill. Two eyes to live.
Bill307
Profile Blog Joined October 2002
Canada9103 Posts
July 23 2009 12:59 GMT
#35
On July 22 2009 00:36 b3h47pte wrote:
http://msdn.microsoft.com/en-us/library/w4hkze5k.aspx
Show nested quote +

Return Value
Type: System..::.Boolean
true if the instances are equal; otherwise false.



http://msdn.microsoft.com/en-us/library/bsc2ak47.aspx
Show nested quote +
Return Value
Type: System..::.Boolean
true if the specified Object is equal to the current Object; otherwise, false.


Not sure how it isn't clear

Are you joking?!?!

I think I could have figured out from the name "Equals()" that it compares if two objects are equal. Those remarks are completely useless.

Anyone checking the documentation for a method like "Equals()" is wondering, how exactly does it determine whether two objects are equal? E.g. does it compare the references, or does it check every member variable?

On July 22 2009 00:38 MasterOfChaos wrote:
Show nested quote +
On July 21 2009 13:43 Bill307 wrote:
C#'s Equals() method, however, doesn't say anything about what it will return by default. (*sigh*)

The Object.Equals documentation is not that bad:
Show nested quote +
The default implementation of Equals supports reference equality for reference types, and bitwise equality for value types. Reference equality means the object references that are compared refer to the same object. Bitwise equality means the objects that are compared have the same binary representation.

I assume by "supports" they mean "implements". But to me, "supports" is just what it can or may do, whereas "implements" is what it actually does. As a result, I probably disregarded that info the first time I read it.
Prev 1 2 All
Please log in or register to reply.
Live Events Refresh
Replay Cast
00:00
SEL S2 Championship: Playoffs
Liquipedia
BSL Team Wars
21:30
Round 5
Team Dewalt vs Team Sziky
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
WinterStarcraft496
RuFF_SC2 150
Nina 146
NeuroSwarm 101
ProTech39
Ketroc 32
StarCraft: Brood War
Shuttle 873
sSak 747
Hyuk 184
Aegong 81
Noble 80
HiyA 51
ajuk12(nOOB) 37
NaDa 14
Snow 11
Icarus 5
Dota 2
monkeys_forever736
Counter-Strike
Stewie2K470
Super Smash Bros
hungrybox511
C9.Mang0490
Other Games
shahzam893
JimRising 540
Maynarde140
Mew2King60
Livibee49
Organizations
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 15 non-featured ]
StarCraft 2
• practicex 14
• intothetv
• AfreecaTV YouTube
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Rush820
• Lourlo713
• Stunt575
Other Games
• Scarra1017
Upcoming Events
Sparkling Tuna Cup
6h 12m
PiGosaur Monday
20h 12m
LiuLi Cup
1d 7h
Replay Cast
1d 20h
The PondCast
2 days
RSL Revival
2 days
Maru vs SHIN
MaNa vs MaxPax
OSC
2 days
MaNa vs SHIN
SKillous vs ShoWTimE
Bunny vs TBD
Cham vs TBD
RSL Revival
3 days
Reynor vs Astrea
Classic vs sOs
BSL Team Wars
3 days
Team Bonyth vs Team Dewalt
CranKy Ducklings
4 days
[ Show More ]
RSL Revival
4 days
GuMiho vs Cham
ByuN vs TriGGeR
Cosmonarchy
4 days
TriGGeR vs YoungYakov
YoungYakov vs HonMonO
HonMonO vs TriGGeR
[BSL 2025] Weekly
4 days
RSL Revival
5 days
Cure vs Bunny
Creator vs Zoun
BSL Team Wars
5 days
Team Hawk vs Team Sziky
Sparkling Tuna Cup
6 days
Liquipedia Results

Completed

CSL Season 18: Qualifier 2
SEL Season 2 Championship
HCC Europe

Ongoing

Copa Latinoamericana 4
BSL 20 Team Wars
KCM Race Survival 2025 Season 3
BSL 21 Qualifiers
ASL Season 20
CSL 2025 AUTUMN (S18)
Maestros of the Game
Sisters' Call Cup
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
BLAST.tv Austin Major 2025

Upcoming

LASL Season 20
2025 Chongqing Offline CUP
BSL Season 21
BSL 21 Team A
Chzzk MurlocKing SC1 vs SC2 Cup #2
RSL Revival: Season 2
EC S1
BLAST Rivals Fall 2025
Skyesports Masters 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
MESA Nomadic Masters Fall
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.