• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 12:55
CEST 18:55
KST 01:55
  • 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
Serral wins Maestros of the Game 227ByuL, and the Limitations of Standard Play3Team Liquid Map Contest #22: Results and Winners7Code S Season 2 (2026): RO4 and Finals Preview12TL.net Map Contest #22 - Voting & Ladder Map Selection7
Community News
Weekly Cups (June 29-July 5): Solar Doubles0MC vs IdrA, Boxer vs Nal_rA to be Legacy Matches @ BlizzCon415.0.16 Hotfix (June 30) - Balance + Bug Fixes40Weekly Cups (June 22-28): Zergs thrive in new patch5[TLMC] Summer 2026 Ladder Map Rotation0
StarCraft 2
General
Serral wins Maestros of the Game 2 Is the larve respawn broken? 5.0.16 patch for SC2 goes live (8 worker start) 5.0.16 Hotfix (June 30) - Balance + Bug Fixes Weekly Cups (June 29-July 5): Solar Doubles
Tourneys
Crank Gathers Season 4: BW vs SC2 Team League GSL CK #5 Race War HomeStory Cup 29 RSL Revival: Season 6 - Qualifiers and Main Event Vespene Cup #1 — $300+ USD, July 10
Strategy
[G] Having the right mentality to improve
Custom Maps
New Map Maker - Looking for Advice - Love or Hate Work In Progress Melee Maps [D]RTS in all its shapes and glory <3
External Content
Mutation # 533 Die Together The PondCast: SC2 News & Results Mutation # 532 Nuclear Family Mutation # 531 Experimental Artillery
Brood War
General
Snow On New ASL S22 Map, Zerg Nerf BW General Discussion BGH Auto Balance -> http://bghmmr.eu/ Starcraft vs Retro Category on Twitch Data needed
Tourneys
CSLAN 4 is Coming! Escore Tournament StarCraft Season 2 The Casual Games of the Week Thread [Megathread] Daily Proleagues
Strategy
Simple Questions, Simple Answers Creating a full chart of Zerg builds Relatively freeroll strategies Why doesn't anyone use restoration?
Other Games
General Games
Dawn of War IV Nintendo Switch Thread Stormgate/Frost Giant Megathread Summer Games Done Quick 2026! ZeroSpace at Steam NextFest - Last free demo
Dota 2
Looking for a Dota Mentor Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
NeO.D_StephenKing vs This Guy From 1 Million Dance TL Mafia Community Thread TL Mafia Power Rank Vanilla Mini Mafia
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread UK Politics Mega-thread YouTube Thread Canadian Politics Mega-thread
Fan Clubs
The HerO Fan Club!
Media & Entertainment
Anime Discussion Thread Movie Discussion! Series you have seen recently... [Req][Books] Good Fantasy/SciFi books [TV/BOOK] *SPOILERS* Game of Thrones Discussion
Sports
2024 - 2026 Football Thread McBoner: A hockey love story Tennis[sport] Formula 1 Discussion TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
FPS when play League Of Legend on laptop How to clean a TTe Thermaltake keyboard? Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
Major Shifts in the Gaming I…
TrAiDoS
An Exploration of th…
waywardstrategy
Gauntlet SC2: A Retrospectiv…
Ctone23
ramps on octagon
StaticNine
Funny Nicknames
LUCKY_NOOB
Evil Gacha Games and the…
ffswowsucks
Customize Sidebar...

Website Feedback

Closed Threads



Active: 7969 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
BSL: GosuLeague
14:00
S22 - Final Stream
Spine vs OctZerg
Radley vs WIZARD
ZZZero.O117
Liquipedia
CrankTV Team League
11:00
Crank Gathers S4: Group Stage
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RushiSC 104
MindelVK 8
StarCraft: Brood War
Shuttle 1876
Calm 1167
Sea 1047
Jaedong 944
Mini 623
EffOrt 521
Soma 440
Hyuk 355
firebathero 312
BeSt 276
[ Show more ]
Light 268
Stork 242
Larva 231
Snow 185
ggaemo 177
Mong 167
ZZZero.O 117
Rush 93
Hyun 77
hero 73
Sharp 69
Zeus 61
JYJ 56
910 30
ToSsGirL 28
Free 24
Hm[arnc] 21
sorry 20
Barracks 18
Bale 18
Sexy 15
IntoTheRainbow 12
Sacsri 10
Terrorterran 8
Dota 2
Gorgc7989
qojqva1610
Counter-Strike
fl0m1611
x6flipin451
edward70
kRYSTAL_36
Super Smash Bros
Mew2King113
Heroes of the Storm
XaKoH 176
Other Games
FrodaN1316
B2W.Neo667
ArmadaUGS102
C9.Mang046
Organizations
Other Games
gamesdonequick31634
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 16 non-featured ]
StarCraft 2
• StrangeGG 96
• mYiSmile140
• intothetv
• AfreecaTV YouTube
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• WagamamaTV419
League of Legends
• Nemesis3529
• TFBlade995
Other Games
• Shiphtur349
Upcoming Events
OSC
5m
Cure vs SKillous
Lambo vs goblin
Cham vs YoungYakov
ArT vs Harstem
Krystianer vs Iba
Replay Cast
7h 5m
Replay Cast
17h 5m
CrankTV Team League
18h 5m
OSC
20h 5m
Big Brain Bouts
23h 5m
Replay Cast
1d 7h
RSL Revival
1d 16h
Serral vs Bunny
ByuN vs GgMaChine
CranKy Ducklings
1d 17h
Afreeca Starleague
1d 17h
Snow vs Jaedong
YSC vs hero
[ Show More ]
RSL Revival
2 days
Solar vs Rogue
Maru vs NightMare
Sparkling Tuna Cup
2 days
GSL
3 days
Replay Cast
4 days
WardiTV Weekly
4 days
The PondCast
5 days
Replay Cast
6 days
CrankTV Team League
6 days
Liquipedia Results

Completed

CSL Season 21: Qualifier 2
HSC XXIX
Eternal Conflict S2 E1

Ongoing

IPSL Spring 2026
Acropolis #4
YSL S3
CSL 2026 Summer (S21)
CranK Gathers Season 4: BW vs SC2 Team League
SCTL 2026 Spring
Heroes Pulsing #3
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026
BLAST Rivals Spring 2026

Upcoming

Escore Tournament S3: W2
ASL Season 22: Wild Card Qualifier
CSLAN 4
Blizzard Classic Cup 2026
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
RSL Revival: Season 6
Light Tournament 2026
Eternal Conflict S2 Finale
Eternal Conflict S2 E3
Eternal Conflict S2 E2
Logitech G Connect 2026
StarSeries Fall 2026
FISSURE Playground #5
BLAST Open Fall 2026
Esports World Cup 2026
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual
Stake Ranked Episode 3
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.