Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am making a game in C# and XNA and will be porting it using MonoGame. I would like to know which is a better option for performance.
Should I write and type out my maps in the code of the game itself, or should I create an XML file and store it in their?
By map I mean the layout of the tile-map. It looks like this if I type it in the code:
map.Generate(new int[,]{
{0,0,0,0,0,0,0,0,0,0,0,0,},
{0,0,0,0,0,0,0,0,0,0,0,0,},
{0,0,0,0,0,0,0,0,0,0,0,0,},
{0,0,0,0,0,0,0,0,0,0,0,0,},
{0,0,0,0,0,0,0,0,0,0,0,0,},
}, 64);
I am new as a programmer and any advice should help?
Thanks, BlazeCrate
There will be neglagable performance difference between the two as no matter which you use they both will end up being stored as some kind of in memory object. The only potential difference in "performance" is how long it will take to make that in memory object once at the start of the level loading (for something that simple it would only take a few ms extra to load, likely unnoticeable)
Do whatever is easier for you to implement and develop for.
Doing it in XML would allow you to design an editor, so that you can use your own GUI to design your content, allowing you to more easily generate much more complex content. It also allows you to modify your content without recompiling your game.
That said, it depends on the scale of your project, and your goals. You should choose the simpler approach if possible, if you want to eventually release it. If you choose the more complex yet more scalable approach, you run the risk of making the project too complex to finish. If your goal is to eventually release, then stay as simple as possible, but if your goal is more along the lines of learning to be a good software engineer, then choosing the more complex approach could be the way to go.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I've learnt just a few basic programs in C# but that much of knowledge might not be enough to program with unity. Can I jump directly to graphics in C#, learn more about control structures, data types, functions, and looping or is there more I need to learn about in order to make my own basic game in Unity 3d? What kinda concepts do I basically need to know in C# to program in Unity? My current knowledge in C# is simply too basic.
For Unity, you user either C# or UnityScript (A sort of JavaScript variant) for programming game logic, and Cg (Very similar to HLSL) for shaders. If you want to spend some money, though, you can also get node based programming tools (Sort of like Unreal Engine 4's Blueprints) from the Unity Asset Store for both.
As for actual concepts, knowing most of the general use aspects of C# is a must (The different loops, Lists and Dictionaries etc), but you also need to learn that Unity has added some things of it's own like coroutines, as well as the fact that Unity is a game engine and how game engine flow works (ie, don't put a loop in the Update method that runs for a long time or the entire game will lag, etc). Reading up on component based architectures is also important, as instead of just having one class per game object, you can have multiple components. This way, you can say add a behaviour (Unity's name for a component) that gives something the ability to pathfind, and another that gives that same object the ability to shoot at the player, etc.
Finally, have a look at Unity's documentation on serialization. Serialization is extremely important in many aspects of Unity, including recompiling your code without restarting the editor, as well as saving/loading and networking if you want to get into such things. It's handy to know how this works though to make sure what you're doing is both efficient and that the engine is treating your data how you expect it to do.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
This question is actually a theoretical one, not about specific coding, but of the approach.
In my video game, there are a lot of phrases that protagonist is supposed to say. Now, I want to add a voiceover, so that someone will read those phrases aloud, so I can add them as sounds, not just plain text.
There are many different phrases.
So, the main question is, what's better, to have each phrase as separate sound file, or to have those phrases divided by sections (like game areas, or game actions or whatever), where each large file will contain a number of phrases. Then, in code, I'll order to play the large file not completely, but from specific time, to specific time (is it possible in WPF?).
What is important:
Time - which approach is easier to do?
Resources - which approach is easier for computer and\or visual studio compiler?
Copyright - I want to limit the possibility of end users stealing sound files.
I personally think that having a thousand of files is crazy, so it's better to use larger files that contain smaller ones. However, my friend highly recommended against it, claiming that playing large files from the middle is harder for computer and will cause problems, maybe slow down the game.
What option will you recommend? Or maybe there is another approach I didn't think of?
Thank you in advance,
Evgenie
I would imagine that using seperate sound files would be easier. Then within c#, add them all to a list.
From that I think it should just be possible to call the index of each sound file, which would be easy if you keep them organised, and labeled well.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
If I've some common functionality that I've to keep in a class, so will I go for static, sealed or abstract class...Does all these types of classes serve the purpose of keeping the common functionality together...where actually the difference lies when I've to go for one
abstract, sealed, static has nothing to do with real time development. It has to do with bring structure within your software, so that the functionality implemented in classes can and should be used in the right way.
After some comments i think this:
I think you can only learn this, by doing it. There isn't a book or epub that will explain you how to do programming. They will show the syntax and some examples. It will be trial and error. Every day you'll face a new challenge.
You'll have to practice it. The best advise is, look what others already created and try to imagine why did they wrote/solve it that way.
I can explain what a static/sealed/abstract class is/does, but it doesn't learn you when to use it.
Back to the question: Define 'real time'.. I think that static/abstract/sealed should NOT be decisive on how you write your 'real-time' software. If you are 'scared' about performance on this level, C# should not be your choise. I would write c++ or if you want a real challenge, try to beat the compilers with asm ;-)
I think you won't measure the 'overhead'
So, use abstract/static/sealed in a right way, so your future collega's/you can read/maintain it.
I use C# for communication (tcp/ip) between a windows computer and a PLC (with delta robots). But it's far from realtime. It's fast enough to keep many robot working with > 100 messages per second.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
In C#, how expensive it is to create a new class instance?
I'm speaking in context of using C# in unity3d. Meaning that stuff continuously gets called many times per second.
In C++, generally speaking (while making games) you may want to reuse anything you created with new/smart pointers, you would want to keep allocated resizeable buffers/lists/fifos and you may want to avoid that uses dynamic memory allocation (and stick to local variables) if code is getting performance critical.
So, what is the recommended way to do it in C#? Is it a very bad idea to create a new List, return it from the function and then "forget" about it, never using it again?
P.S. I'm aware of profiling and "premature optimizations", but I'd like to know some generic guidelines for the language before I (possibly) make a big mess because I used the wrong approach.
I remember reading a fun post Performance numbers in the pub by Ayendy Rahien.
How many CLR objects can you create in one second?
And here was the result back in 2011
Created 7,715,305 in 00:00:01
Jokes aside. Create is pretty cheap operation but GC is not. So while you can create really many objects, it is the collect that will hurt performance. So a rule of objects reuse can apply to C# as well.
I'd assume, but can be wrong, implementation of a new operator is located in JIT
aloc.h
aloc.cpp
As usual, avoid premature optimisation till you need it.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I'm looking to create a bot like program and I'm looking to use a screen-scraper to retrieve data such as health which is numerical.
I have no idea how to accomplish this as most screen-scrapers are programmed in c++ as directx is most popular within that.
Is it possible to create a well working c# screen scraper for a directx program?
Thanks.
Outside of kernel mode, anything that can be done in C++ can be done in C#.
With that disclaimer out of the way please know that client-side bots don't work by actually screen-scraping and performing OCR. Instead they hook into DirectX's functions and record copies of the string text sent to DrawText, for example, or the vertices in the current world view graph and then work from there.
I've never really gotten into this area of programming so I can't give you any more specific advice, but I can tell you that you're in for an uphill struggle.
The alternative is just to use common Trainer/debugger techniques and map the memory of your target process. I assume you're targeting a game of some description, however said games often feature very heavy cheat-detection and prevention techniques and trying things out on a public server can get you banned for life (e.g. Steam's VAC).