Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 20 May 2009
Offline Last Active Sep 11 2015 04:10 PM

#4877931 Can someone give me the exact definition/usage of Stack/Heap and Reference Ty...

Posted by on 28 October 2011 - 12:08 PM

I think a source of much of the confusion is the stack in C++, where the programmer had much more implicit control. In C# to be honest, I don't really know why they even made the distinguishment. They should have probably ignored the concept completely and made it something only the compiler developers were really aware of. Worst case scenario, for those few edge cases where the developer needed to optimize for stack usage, it could have been exposed as an attribute. Actually, there is already the stackalloc method, so even this wouldn't be need.

Yes, this tripped me at first when moving from C++ (along with a few other memory related details) - the best thing for me (from a practical viewpoint) was to just forget about the hows and whys of memory in .net and trust the framework to take care of it all. I still get a twinge of, er, guilt maybe?, every now and then when tossing around a ton of instanced objects. Old habits, I suppose.

Not to say these things aren't important to know, and some of the wonderful replies here have filled in the rough spots of my understanding.

#4876536 Super efficient tile engine design?

Posted by on 24 October 2011 - 06:12 PM

By large number of tiles, I assume you mean size of map dimensions (not the number of different textures)?

I'm not sure why anyone would bother trying to write a "super efficient" tile engine these days. Just make a tile engine, and if you run into memory issues, partition the world into "chunks" and stream the chunks from disk as needed. A modern computer can handle very large amounts of memory very quickly, so I think the more difficult task would be the actual generation of these large maps.

In general, efficiency is probably the last thing you should be worrying about at this stage. Follow Nick's tutorial (or any of the other many tile engine tutorials available) and get something working first.

#4873050 Using XNA RenderTargets

Posted by on 15 October 2011 - 11:42 PM

Rendertarget usage can get a bit tricky, if you haven't already you should probably read this and this. If you were more specific (e.g. show some code) you may get some more specific help.

#4872705 Seeking Beginner Advice for Text-Only Dungeon Game in C# and Python

Posted by on 14 October 2011 - 05:40 PM

I'm going to work through the beginner examples rather than just reading them. It's humbling, and I'd much rather pick up in C# where I was in Python, but I realize that's just not happening.

You may already have some good learning resources lined up, but there was a thread not too long back which may have some beginner-friendly challenge ideas for you to try, here. It seems like there was another one around at about the same time, but I can't seem to find it...

#4870646 [C#] Checking the amount of items in a List?

Posted by on 08 October 2011 - 06:36 PM

Its not a neat solution, for the first item just write it, then for subsequent items write a comma then write the item. Maybe:

bool first = true;
foreach (string items in mInventory.List)
        Console.WriteLine(" \"{0}\"", items);
        first = false;
        Console.WriteLine(", \"{0}\"", items);

To add more solutions to the mix, Jon Skeet wrote a smart enumerable class that supports IsFirst and IsLast queries (among a couple others), which can be found here if looking for a general purpose way of doing the above. However, for the specific OP, String.Join might be the most simple.

#4869645 Seeking Beginner Advice for Text-Only Dungeon Game in C# and Python

Posted by on 05 October 2011 - 10:23 PM

WindowsError: [Error 193] %1 is not a valid Win32 application

I don't know python very well, but this error message makes we wonder if there is a 32/64 bit incompatibility issue. From the tutorial link:

(Note for Windows 7 64-bits users: install the 32-bits version, since the 64-bits version of Python seems to cause problems with libtcod.)

It looks like libtcod is not compatible with 64 bit Python, maybe this is the problem?

#4869630 XNA Sprite performance problem with Matrix's

Posted by on 05 October 2011 - 08:28 PM

I don't know of anything that you could be doing with Matrix calculations that would affect performance so drastically (unless you are doing it 10000+ times a frame). You can try posting some more code, there's probably something else affecting performance here.

#4868181 Seeking Beginner Advice for Text-Only Dungeon Game in C# and Python

Posted by on 02 October 2011 - 12:04 AM

For an in-depth tutorial making a roguelike game using Python, you can look try here: http://roguebasin.roguelikedevelopment.org/index.php/Complete_Roguelike_Tutorial,_using_python%2Blibtcod

I have not done much with Python, and I've only glanced at the above tutorial, but it seems to go through just about everything for a simple roguelike game, including dungeon generation, items, exploration, monsters, etc.

#4865001 XNA C# Help with HUD

Posted by on 22 September 2011 - 09:09 PM

You need to set the HUD.player member to the Player parameter you pass to it, like so:

public HUD(Game game, GameStateManager manager, Player player)
        	: base(game, manager)
              this.player = player;

This way, the HUD.player references the same Player object as the one you create in your GamePlayState object. This way they are the same object (the same chunk of memory), so anything you do to HUD.player will be the same as doing it to the Player instance you pass into the HUD constructor (and vice versa).

Sorry if I'm not explaining it well enough - you would probably do better to read up on classes (reference types) and structs (value types) and what their differences are. While you are at it, look into pass-by-reference and pass-by-value, since despite the similar names these are different concepts, and are important to understand up-front.

#4864985 XNA C# Help with HUD

Posted by on 22 September 2011 - 08:18 PM

Pass the player instance from your GamePlayScreen to your HUD instance so that they are both using the same player.camera object. You could modify the constructor for HUD so it takes a Player as a parameter, then store that in your HUD instance instead of creating a new one. Then you'd do something like this

public GamePlayScreen(Game game, GameStateManager manager)
 	: base(game, manager)
        	player = new Player(game);
        	hud = new HUD(game, manager, player);

Do you understand why this must done?

#4864967 XNA C# Help with HUD

Posted by on 22 September 2011 - 07:34 PM

Some thoughts:

Where is the Camera position being updated? I see the HUD class creates a Player, but doesn't expose it as a public property (or field), so how/where does the Player.Camera get used? Are you sure you don't have 2 separate Player instances floating around somewhere, and are updating the wrong one?

When you put a breakpoint here

     				new Rectangle((int)player.Camera.Position.X + 150, (int)player.Camera.Position.Y + 630, 150, 15),

what value does player.Camera.Position.X have (and what are you expecting it to have)?

Put a breakpoint at "set" here

        public Camera Camera
                get { return camera; }
----> 		set { camera = value; }

Does this get called when you predict it to?

Have you tried just stepping through your logic with the Debugger? These types of bugs are usually easy to find just by stepping through code, examining variables, etc, especially in a language like C# which has few surprises.

#4860233 Looking for some "best practices" advice

Posted by on 10 September 2011 - 11:53 PM

Yea, I know everything doesn't need to be global. But I'm noticing as I am creating a simple text-based RPG (as an exercise), I am needing to "see" various classes within my code and am having a tough time doing it sometimes.

This seems to be a common "hump" to get over when learning OOP. It seems so much easier to just have a global collection of objects that can be accessed when we want them - but we are told that globals are "evil". Also, we are told that encapsulation is good, but it's sometimes difficult to decide which class members to hide, and which to expose. Another early difficulty is over-designing classes - it often seems nice to add all of this functionality that we think may need for a class, but then we are told about KISS and YAGNI.

Experience, especially in the form of having the above mentioned things bite you in the ass, is probably the best way to learn.

So I gave each weapon its own struct with its own stats already initialized when the code was compiled. I wasn't satisfied with that either.

Why weren't you satisfied with this? All weapons are going to share a set of stats, so make a Weapon object (class or struct, whatever is appropriate for the language). If a particular weapon type never changes its state (stats) during the game, then you will not need a separate instance for each weapon - just keep a master list of weapon types and their stats, and index into it as needed. If weapons can change state during the game (their stats can change, such as current ammo, upgrades, wear and tear), then each weapon will have its own instance. In this case, the master list of weapon types is like a collection of blueprints, and is used to initialize a weapon instance.

Maybe if you focus on one particular aspect, and post some code, you will get some more specific suggestions.

#4860213 Odd memory problems with classes

Posted by on 10 September 2011 - 09:11 PM

I took my program to my professor and he recommended getting Visual Studio 2010 Professional.


Pretty much my reaction. The only way this recommendation would make any sense might be better ways of debugging memory issues with the Professional version.

Also keep in mind that even professors teaching computer science can be worthless as programmers (pointing out that computer science isn't programming). I could probably point at a few that are so deep into the theoretical side that they haven't touched any programming language for decades.

I don't understand your reactions. He teaches C and C++, and he solved my problem. His suggestion was spot on.

From the previous information you've provided in this thread, your issue seems to be the dreaded "undefined behavior" that makes C++ programmers cringe (unpleasant memories of long, exasperating debugging sessions). These bugs are often caused by memory issues, as has been pointed out. Also, as has been pointed out, the particular version of Visual Studio almost most certainly has nothing to do with it. The fact that the problem seems "fixed" is because it is undefined behavior - your program may still fail, under seemingly random conditions, and it may fail in seemingly random ways. Because of this, these types of bugs are dangerous, since they may not get caught until its too late, and understanding them is presumably extremely important for a programmer to know.

The fact that a C++ professor would gloss over this very important detail, and instead jump to the most-likely wrong "solution", is what prompted my reply.

Of course, it is entirely possible that I do not know the whole story.

#4859350 Entity Screen bound checking

Posted by on 08 September 2011 - 11:00 PM

If they move slow enough, they stop right at the X(0), and stay. if I up their velocity a little bit higher, they slow down at the 0, but continue to move on past the screen space until their out-of-bounds check erases them.

Why is velocity decreasing when X approaches 0? Is this by design? If not, then xVel must be getting modifying somewhere else in the code. Either that, or "dt" is being calculated incorrectly. You can try running the debugger through the Move() method to see how xVel is being calculated, or set a conditional breakpoint, or log the velocity calcs to debug window, depending on you development environment.

#4858914 RPG Weapon Stats

Posted by on 07 September 2011 - 10:06 PM

I have a weapon generator for a 2D roguelike RPG I am developing. It has variables that store the name of the weapon, the base damage output, the base attack speed, the required strength to equip, and the gold value of the weapon. For example.... A Short Sword could have 5 base damage, and 3 attack speed with 10 required strength to equip and a gold value of 200. But what would be a good way to add weapon "levels"? So the damage would be greater if the level was higher. I don't want the attack speed to change but what would be a good equation to use to increase the damage, required strength, and gold value of the weaon if the weapon is of a higher level?

There are numerous ways this can (and has) been done. One way is as suggested above to simply multiply the level by a value and add it to the base stat. You could have different multipliers for each stat, or you can base certain stats (such as gold) off the others.

Instead of a simple level, you can have descriptive tags that get added to items, each tag having its own modifiers. Examples include material ("Mithril knife", where "mithril" has +2 damage and +500 gold), a quality ("Well-balanced cudgel", +1 speed, +1 damage, +20 gold), or magical ("Katana of Destruction", +10 damage, +10 min strength). Certain tags can get mixed for powerful items: "Epic Dragonbone Spear of Slaying Rodents". In this scenario, tags are statically defined, but added randomly to items during generation.

Expanding on the "tag" system, you could have special items ("runes", "enchantments", etc.) that get added to items to enhance their effect. Items only get a certain number of "slots" for enhancements. This could be a form of rudimentary crafting, where enhancements can only be added to items at special places (e.g. a forge) or by certain NPCs.

Whichever path you choose, you are going to want it to be easily tweakable - balancing these types of games can be a major (oft times seemingly impossible!) task. Keep all multipliers, tag modifier data, etc. in a single place, separate from your logic that uses them, and somewhere that it can be easily changed, like a config file or a section of static code.