• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 07:17
CET 13:17
KST 21:17
  • 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
RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10[ASL20] Finals Preview: Arrival13
Community News
[TLMC] Fall/Winter 2025 Ladder Map Rotation12Weekly Cups (Nov 3-9): Clem Conquers in Canada4SC: Evo Complete - Ranked Ladder OPEN ALPHA8StarCraft, SC2, HotS, WC3, Returning to Blizzcon!45$5,000+ WardiTV 2025 Championship7
StarCraft 2
General
Mech is the composition that needs teleportation t RotterdaM "Serral is the GOAT, and it's not close" RSL Season 3 - RO16 Groups C & D Preview [TLMC] Fall/Winter 2025 Ladder Map Rotation TL.net Map Contest #21: Winners
Tourneys
RSL Revival: Season 3 Sparkling Tuna Cup - Weekly Open Tournament Constellation Cup - Main Event - Stellar Fest Tenacious Turtle Tussle Master Swan Open (Global Bronze-Master 2)
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 499 Chilling Adaptation Mutation # 498 Wheel of Misfortune|Cradle of Death Mutation # 497 Battle Haredened Mutation # 496 Endless Infection
Brood War
General
FlaSh on: Biggest Problem With SnOw's Playstyle BW General Discussion What happened to TvZ on Retro? Brood War web app to calculate unit interactions [ASL20] Ask the mapmakers — Drop your questions
Tourneys
[Megathread] Daily Proleagues Small VOD Thread 2.0 [BSL21] RO32 Group D - Sunday 21:00 CET [BSL21] RO32 Group C - Saturday 21:00 CET
Strategy
PvZ map balance Current Meta Simple Questions, Simple Answers How to stay on top of macro?
Other Games
General Games
Path of Exile Stormgate/Frost Giant Megathread Nintendo Switch Thread Clair Obscur - Expedition 33 Beyond All Reason
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
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
Things Aren’t Peaceful in Palestine US Politics Mega-thread Russo-Ukrainian War Thread Artificial Intelligence Thread Canadian Politics Mega-thread
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
[Manga] One Piece Anime Discussion Thread Movie Discussion! Korean Music Discussion Series you have seen recently...
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
Dyadica Gospel – a Pulp No…
Hildegard
Coffee x Performance in Espo…
TrAiDoS
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Reality "theory" prov…
perfectspheres
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2253 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
Kung Fu Cup
12:00
2025 Monthly #3: Day 4
Cure vs Reynor
Classic vs herO
RotterdaM385
IndyStarCraft 179
IntoTheiNu 46
SteadfastSC36
Liquipedia
RSL Revival
10:00
Group C
SHIN vs ByuN
Crank 1192
Tasteless826
ComeBackTV 797
Rex125
3DClanTV 68
Liquipedia
CranKy Ducklings
10:00
Master Swan Open #98
CranKy Ducklings41
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Crank 1192
Tasteless 826
RotterdaM 385
IndyStarCraft 179
Reynor 138
Rex 125
SteadfastSC 36
Railgan 35
StarCraft: Brood War
Britney 34679
Rain 3837
Hyuk 1331
Horang2 1325
firebathero 1306
Jaedong 886
Shuttle 597
Mini 440
Stork 332
BeSt 259
[ Show more ]
Last 196
PianO 168
EffOrt 166
Leta 163
Hm[arnc] 156
Pusan 133
Shine 131
Hyun 87
Mong 86
sorry 67
Barracks 66
Shinee 63
ggaemo 52
JYJ47
JulyZerg 29
soO 27
Bale 19
Movie 18
Noble 13
HiyA 12
ajuk12(nOOB) 9
Dota 2
Gorgc4605
singsing2264
XaKoH 429
XcaliburYe243
Dendi126
Counter-Strike
fl0m3292
zeus396
Other Games
FrodaN4033
B2W.Neo1686
KnowMe207
Fuzer 163
Lowko108
Mew2King64
MindelVK11
Organizations
Dota 2
PGL Dota 2 - Main Stream7851
PGL Dota 2 - Secondary Stream1604
Other Games
gamesdonequick575
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 13 non-featured ]
StarCraft 2
• Berry_CruncH138
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• C_a_k_e 1006
League of Legends
• Stunt1248
Upcoming Events
IPSL
4h 43m
ZZZero vs rasowy
Napoleon vs KameZerg
OSC
6h 43m
BSL 21
7h 43m
Tarson vs Julia
Doodle vs OldBoy
eOnzErG vs WolFix
StRyKeR vs Aeternum
Sparkling Tuna Cup
21h 43m
RSL Revival
21h 43m
Reynor vs sOs
Maru vs Ryung
Kung Fu Cup
23h 43m
WardiTV Korean Royale
23h 43m
BSL 21
1d 7h
JDConan vs Semih
Dragon vs Dienmax
Tech vs NewOcean
TerrOr vs Artosis
IPSL
1d 7h
Dewalt vs WolFix
eOnzErG vs Bonyth
Replay Cast
1d 10h
[ Show More ]
Wardi Open
1d 23h
Monday Night Weeklies
2 days
WardiTV Korean Royale
2 days
BSL: GosuLeague
3 days
The PondCast
3 days
Replay Cast
4 days
RSL Revival
4 days
BSL: GosuLeague
5 days
RSL Revival
5 days
WardiTV Korean Royale
5 days
RSL Revival
6 days
WardiTV Korean Royale
6 days
Liquipedia Results

Completed

Proleague 2025-11-07
Stellar Fest: Constellation Cup
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
YSL S2
BSL Season 21
CSCL: Masked Kings S3
SLON Tour Season 2
RSL Revival: Season 3
META Madness #9
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 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.