• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 13:59
CET 19:59
KST 03:59
  • 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
Team Liquid Map Contest #2312[ASL22] Finals Preview: Sweet Victory!12[ASL22] Ro4 Preview: Mirror Mirror6[ASL22] Ro8 Preview: Within Reach5[ASL22] Ro8 Preview: In A Tizzy11
Community News
Weekly Cups (Nov 9-15): Clem and herO take over6Dark completes military service, returns to SC217[BSL23] RO16 Group Stage20Weekly Cups (Nov 2-8): herO back on top?2Weekly Cups (Oct 26 - Nov 1): MaxPax, herO, Solar win0
StarCraft 2
General
Weekly Cups (Nov 9-15): Clem and herO take over SC4ALL: II Indiegogo Campaign Announcement No more SC2 streamers on team liquid? Team Liquid Map Contest #23 StarCraft open world shooter announced at BlizzCon
Tourneys
RSL goes to London! 2026 Offline Finals Nov 21-22 soO & FanTaSy return! SC2 Kevin Scrim 4v4 (Nov 16) Sparkling Tuna Cup - Weekly Open Tournament Sea Duckling Open (Global, Bronze-Diamond) Dark returns! GSL CK #7 4v4 Team Battle (Nov 19)
Strategy
[H] ZvP Mid-Late Game: Stalkers Collossi HT
Custom Maps
[G] How to playtest arcade maps Starcraft 2 Advance [D] the control group Simple Questions/Answers
External Content
Mutation # 552 Secret Storm The PondCast: SC2 News & Results Mutation # 551 Robotic Revival Mutation # 550 Graveyard Shift
Brood War
General
List of top players active on ShieldBattery SC4ALL: II Indiegogo Campaign Announcement XUN appreciation thread Shield Battery Server New Patch Light introduces ShieldBattery on his YouTube
Tourneys
2v2v2v2 Tournament Stage 2: Players [BSL23] Ro16 Group B - Saturday 21:00 CET KCM Race Survival 2026 Season 4 SC1 Kevin Scrim hosted by SOOP (Nov 18-19)
Strategy
Pluto's TvP 5Marine 2Medic Push Simple Questions, Simple Answers Infested Terran strategies in 2026 Nuke strategy worked in K-League 2026-11-09
Other Games
General Games
The PlayStation 5 Nintendo Switch Thread Stormgate/Frost Giant Megathread Warcraft III: The Frozen Throne Free Space RTS Game, optimised f. Phone/Tablet etc
Dota 2
League of Legends
[TL LoL EUW IHs] Teemo shall perish
Heroes of the Storm
Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
TL Mafia Community Thread
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Trading/Investing Thread Artificial Intelligence Thread The Big Programming Thread
Fan Clubs
Fan Club Resource Thread Reynor Fan Club The Flash Fan Club
Media & Entertainment
Movie Discussion! Anime Discussion Thread [Manga] One Piece
Sports
Football (Soccer) Thread TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Recent Gifted Posts
Blogs
The time I organised my…
AssyrianKing
Why I built Repalyzer (1.1.…
BlueStar
Innovate or Game Over?
TrAiDoS
ShieldBattery on Mac
Kraekkling
Can Bots Beat Pros?? Starcr…
namkraft
James Bond movies ranking - pa…
Topin
StarCraft improvement
iopq
Customize Sidebar...

Website Feedback

Closed Threads



Active: 16055 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 States12816 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 States12816 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
RSL Revival
21:00
Offline Finals: Open Bracket
Tasteless1330
ComeBackTV 937
IndyStarCraft 221
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Tasteless 1330
IndyStarCraft 221
EmSc Tv 13
JuggernautJason0
StarCraft: Brood War
Leta 767
Shuttle 484
BeSt 294
firebathero 120
Dewaltoss 103
Hyun 43
Aegong 24
zelot 11
Dota 2
Gorgc9011
qojqva1513
420jenkins251
BananaSlamJamma57
Counter-Strike
gobbtv220
Heroes of the Storm
Khaldor422
Liquid`Hasu85
Trikslyr49
MindelVK9
Other Games
tarik_tv3457
singsing2441
FrodaN1037
ScreaM768
B2W.Neo478
mouzStarbuck324
Fuzer 183
ArmadaUGS170
Grubby103
KnowMe100
UpATreeSC31
Organizations
Other Games
EGCTV940
gamesdonequick854
BasetradeTV134
StarCraft 2
EmSc Tv 13
[ Show 18 non-featured ]
StarCraft 2
• printf 52
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• Migwel
StarCraft: Brood War
• Airneanach80
• 80smullet 12
• Pr0nogo 8
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Nemesis2821
Other Games
• imaqtpie657
• Shiphtur460
• WagamamaTV232
• tFFMrPink 9
• Scarra7
Upcoming Events
BSL
1h 1m
eOnzErG vs StRyKeR
Cross vs JDConan
RSL Revival
18h 1m
OSC
18h 1m
IPSL
22h 1m
Ret vs ggnore13
nOmaD vs Aether
BSL
1d 1h
Bonyth vs Doodle
Kyrie vs Jimin
Replay Cast
1d 4h
WardiTV Weekly
1d 17h
Kung Fu Cup
2 days
Solar vs Classic
ByuN vs SHIN
PiGosaur Cup
3 days
The PondCast
4 days
[ Show More ]
KCM Race Survival
4 days
Liquipedia Results

Completed

Proleague 2026-11-17
Blizzard Classic Cup 2026
HCC Season 3

Ongoing

Acropolis #5
KCM Race Survival 2026 Season 4
International ShieldBattery League
BSL Season 23
IPSL Winter 2026-27
RSL Offline Finals
Calamity Cup Div. A Season 8
Underdog Cup 2026 Div 2-3
Stake Ranked Episode 6
BLAST Rivals Fall 2026
IEM Beijing 2026
PGL Masters Bucharest 2026
Stake Ranked Episode 5
1win Private Club #2
Thunderpick World Champ. '26
ESL Pro League Season 24
Stake Ranked Episode 4
1win Private Club #1
Logitech G Play Connect 2026
SL StarSeries Fall 2026
FISSURE Playground #3

Upcoming

CSL Season 23: Qualifier 1
Sector 591
YSL S4
SC4ALL II: Brood War
CSL 2026 Winter (S23) - 3v3
CSL 2026 Winter (S23)
NBSL 2026 Xiamen LAN
HSC XXX
Stellar Fest 2: Lunar Cup
StarCraft2 Weekly Open Tournament 2026 Grand Finals
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
IEM Kraków 2027
PGL Bucharest 2027
BLAST Bounty Winter 2027
PGL Major Singapore 2026
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 © 2026 TLnet. All Rights Reserved.