Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 12 Mar 2005
Offline Last Active Yesterday, 11:47 PM

#5312028 How to use Unit-Tests

Posted by on 22 September 2016 - 09:38 PM

Unit tests first and foremost are a way to ensure permanence.  They are there to ensure that when you provide an input, you get the expected output.  Normally it also checks correctness, but sometimes the tests don't test the correct thing.  Whatever they test for becomes permanent.


Therefore, testing mathematical calculations is probably not a thing that should be tested for every possible outcome.


Correct.  You want to test enough to ensure the function is doing the right thing, but you don't need to test every value.  Often that means testing both sides of boundary conditions, and perhaps an easy to verify value in the middle.


Generally in test writing you have a test that hits the happy path -- doing everything right -- then a bunch of tests that excercse all the error conditions.  


Also another key about unit tests is that they need to be fast.  If they hit a database, hit a file system, hit a network, they are not a unit test they are an integration test.  


I think, it would help a lot if you could show me a simple example on how to invoke unit testing into a tiny code example using a class and whatnot.


It is Java rather than C++, but I've seen this tutorial used several times for starting to build Tetris using test driven development.


You will need to adjust it to your preferred testing framework, but that is generally easy to do.


There's also this amazing book that is freely available as a web site, less of a tutorial and more of a reference, it works through common patterns and struggles in automated tests.

#5311921 Making a bot for a website in C++?

Posted by on 22 September 2016 - 09:13 AM

There are also tools like CURL and WGET that may satisfy your requirements.

#5311686 Serious Question needs serious logical feedback

Posted by on 20 September 2016 - 03:28 PM

Should I build a game for a bigger company that is already successful...


This translates to "should I get a job?"


If you have no experience in a game studio, starting your own studio is statistically destined to fail. There are a handful of exception, but you're looking at the scale of one-in-a-million odds. It's a lottery that you're (almost certainly) going to lose. Your odds really are better at government-run lotteries.  If your intention is to run a game development studio you should work in the industry first.


First option. ... {publisher funds idea and pays percent of revenue}
Second option. ... {kickstarter}


The first option only works if you have some startup money and a team of experienced developers. Among the first questions asked when businesses explore those deals is the list of key people on the project and their work history. If there aren't enough people with enough industry experience the bigger companies will move on to the next group.

The second option falls back in the lottery category.

You have more options, such as:

* get a job at a game studio and after several years pitching the game with the hope of making the game from the inside
* get a job at a game studio and after a few years leave with some like-minded co-workers to follow one of those options
* get rich some other way and hire experienced game developers

You might find this video enlightening, along with many others they have created as they are focused on game design. That specific video talks on the role of game designer, which isn't what many people think of.  

Finishing it up, Game Designer is not a beginner role. Usually it is a fairly senior role needing a decade or so of industry experience. There are design jobs that are early-career and mid-career like level designer and character designer, but the job title of Game Designer is a senior level role. The person with the Game Designer business card is in charge of millions of dollars or tens of millions of dollars of work. 

#5311539 C++ Angle bracket function

Posted by on 19 September 2016 - 10:01 PM

I sometimes feel invisible.


Probably because templates are fancy and shiny.  Pointers to base classes are old-school and ghetto.  :(

#5311495 Why do most people recommend Python

Posted by on 19 September 2016 - 03:04 PM

I recommend it because it is relatively simple to learn, doesn't require complex editors and projects and other steps that can cause problems, and is useful in the long run.


Python serves as a good language to cut your teeth on the basics of programming because the consequences of doing things wrong are not as difficult to deal with as they are in C and C++. Despite being approachable the language is fairly commonplace.


There is an enormous body of Python code out in the world. It is extremely common in build systems for games, and for tools at some shops. If you're looking to build a quick-and-dirty tool, Python is one of many tools that is convenient to have in your toolbox.


There are several languages that professional programmers should be comfortable with. Not necessarily expert-level, but good enough.  Right now those tend to include C++, Java, C#, Javascript+Html, and Python. Add SQL to that list if you're touching anything related to databases.  It is reasonable to expect that you could throw some code in those languages to any professional programmer today and expect them to understand it and be able to work with it. 




Further, programmers are expected to keep their skills current and learn new languages and tools, the same way doctors are expected to keep current on the latest medical tools and techniques, the same way lawyers are expected to keep current on current law and precedent, and mechanics are expected to keep current on modern vehicles tools and parts and techniques.  A good way to do that is learning a new language approximately once per year.

#5311490 Basic multithread question

Posted by on 19 September 2016 - 02:23 PM



Sleep() a solution for a different problem. Don't use it here. They tend to operate on large time slices, far larger than you want here. They'll make your game stutter.


Busy waits and spinlocks, which you see in the { while(no value) nop(); } solution, consume tons of CPU time and normally harm processing overall. Don't use them because they tend to make performance plummet.


Use the platform-specific wait command, such as WaitForSingleObject() or pthread_cont_wait() or similar.  These let the OS completely remove the thread from the run queue until the event is triggered, then the thread will immediately return to running state.

#5311474 Why C# all of a sudden?

Posted by on 19 September 2016 - 01:03 PM

While JohnnyCode's numbers are clearly made up and has some substantial factual errors, his comment is reflective of common beliefs.



When it comes to tools work I've seen Java stuff since it was introduced around 1995, and I've seen C# tools since about 2003. More recently I've also seen a ton of JavaScript tools relying on NodeJS and similar. 


Several game engines have used it for scripting, not just Unity.  The Sims 3 engine used C# for all gameplay scripting, and it incorporated C# about the same time Unity did, about 10 years ago.

#5311263 Over stepped at the start

Posted by on 18 September 2016 - 12:03 AM

As VildNinja suggests we need more information for an actual determination, but since this is in For Beginners we can make some guesses.




Cut the duplicates generally, but only if you really aren't using it.


Assuming you actually need SQL tools you don't need four versions of them; pick one version, probably the 2016 x64 version, and dump the earlier editions and 2016 32-bit version.  If you aren't using SQL databases for anything, dump all of them.


Duplicates for the redistributable runtimes aren't a big concern, lots of programs rely on those and they exist as independent versions for good reasons.  If you're using software that uses them, keep them.  If you aren't using programs that have them they won't seriously harm your computer apart from taking up a bit of space.  For example, with 4.6 and 4.6.1 and 4.6.2, x32 and x64 versions, if you have programs that need them then keep them, but if you installed them unnecessarily they aren't a problem. Remove them if you want and reinstall if you actually need them.


The compact edition versions should probably be removed unless you plan on targeting windows mobile. Again, they don't particularly hurt anything other than taking up space on your system.


The IIS stuff and web deploy stuff should probably be dumped unless you're building a web program that relies on IIS for the web server rather than the more standard (and free) Apache.  Running the servers will have a small impact as it takes CPU and memory.


I didn't notice it but it may be there, if you've got SQL Server running on the machine that will also take some memory and CPU as it runs, kill it off if you don't need it.


Several of them like Gtk#, OpenAL, and Silverlight only makes sense if you are developing with it or it is required for something you use.


If you don't remember what you actually need for the machine, and if it isn't a big issue for you, you might just consider wiping the box and re-installing. Removal of development tools can leave traces behind or have subtle issues based on the order you installed the earlier tools.  If the box is only used for software development and isn't your regular home machine, it may be worth the 2-4 hours of effort to reset everything and try again.

#5311261 Is this practical for a resource manager?

Posted by on 17 September 2016 - 11:46 PM

Again, this is a common pattern in bigger engines. In smaller code it may not make sense to fully implement. Your mileage my vary, etc.


The store is the factory, not the resource loader.  Some code tells the store: Give me this object. The store replies by immediately handing over a proxy object which will be filled out which is fully functional and may contain the final resource or a placeholder; that placeholder may be a cube or a pink box on debug builds, a zero-polygon mesh or alpha texture on release builds, or might actually contain the thing that was requested. :-)  Whenever the loader gets around to loading the resource the placeholder in the proxy gets swapped with the actual object.

The cache owns the lifetime.  That lifetime typically starts when the loader reports "I've loaded this object for you". Caches tend to use reference counting and may also have a registration system to help in debugging.  Any system using the resource can say "I'm done using this now" by calling a release method, but that system does not actually unload the resource, instead it typically just allows the cache to reduce the reference count.  The cache decides when the object referenced by the proxy should be created, and the cache decides when the object referenced by the proxy should be destroyed. 


Again, a store that serves as the external interface, a proxy that may contain the real item or a fake item but behaves the same with either, a loader that does the work of creating things and is never touched by externals, and a cache that is also never externally touched but decides when things live and when they die.  Each has their single responsibility.

#5311248 Is this practical for a resource manager?

Posted by on 17 September 2016 - 08:41 PM

It still equates all types of things in ways that probably aren't true.


You've got audio clips and image files. Texture resources generally live on graphics cards rather than main memory. Audio files are often streamed rather than stored in main memory.  Cache sizes for different objects will tend to be different sizes. Cache eviction patterns, loading patterns, and other features will likely be different for different objects. Trying to bundle them all into an all-inclusive resource system tends to not work out very well.  


Sometimes creating a resource system with unified names which is then completely specialized for a bunch of unique subtypes can work if that is the route you want to take. In C++ that tends to look like Resource<Texture>, Resource<Model>, Resource<SoundClip>, Resource<AudioStream> and so on. Even so, that is still unique systems for each one is specialized for the thing being held.


Although this is a frequently-discussed topic and I recall seeing it a few times already, I thought this was mentioned in your thread but I don't see it. Larger games tend to have a pattern of a store, cache, loader, and proxy.  Each one typically gets specialized for different types of resources because different resource types tend to have unique properties. These should not have anything static or singleton, code should be able to create any number of classes that they want, although sometimes code bases will follow the pattern of a "well known instance", a pointer to a lifetime-controlled object that can be modified at well-documented times and is stable and constant during other documented times.  The store is the external interface, providing access to the resource. The cache is the data backing that holds the ones currently loaded in memory and dumps them under various rules. The loader is what pulls resources off the disk or network or wherever they are coming from. The proxy is the conveyance object, which can contain a placeholder object or can contain details for the actual resource.



Your updates start toward that path.  

#5311239 Is fread considered a seek memory on disk operation?

Posted by on 17 September 2016 - 05:55 PM

There is some buffering that takes place behind your back, as covered somewhat above.  For reading small files there are buffers by the OS and by language libraries. The exact details vary by system and libraries, anywhere from a few kilobytes up to a megabyte or more.


But memory maps have an even cooler feature: since you are declaring broad intentions rather than tiny pieces, the OS can schedule and re-order disk reads for the entire range. This is even more significant on spindle-disks than SSD disks.  So if the OS knows data is scattered around in twenty different places the OS can read them in the order that is optimal for the drive, picking them up as it sweeps across rather than sequentially which may require jumping back and forth a few different times.


For large files memory maps are typically the best solution, even though they tend to require OS-specific functionality to implement (or the C++ Boost library that seems to have a little of everything).

#5310989 How many RAM on VDS server I need setup, then my fb game will support 1000 on...

Posted by on 15 September 2016 - 03:56 PM

Ultimately the only way to be sure is to start up a large number of (simulated) clients and see how the server responds.


Typically server performance graphs have a sharp turn.  They perform quite well for lower numbers, then when you add someone you hit the turn and suddenly performance becomes terrible.  You will want to know where that line is long before players ever hit it.

#5310960 How much money do you make with your games?

Posted by on 15 September 2016 - 12:50 PM

Every product is different.


How much a game made is not really enough information.  A game that makes $75,000 may sound impressive until you learn it cost $95,000, or it may be amazing if the person invested 400 hours and $50 in the project.

Those that operate professionally and do the important tasks of market research, of marketing to potential customers, and ensuring proper quality of the game tend to make quite a lot of money. The best product series I was on ended with a 62% profit over investment.  Other projects of this type tend to range from a moderate loss to a moderate profit, depending on more factors than anyone can account for, including a bit of luck.


Those that are amateur tend to make no revenue. Sadly, most games fit here. These tend to have no market research, simply jumping in because the project looks fun.  Marketing tends to be a few posts online about "I made a game!". Quality controls tend to be handing the game to a few people and asking for feedback.  These products will sometimes end up with a few sales from friends and family.  Considering the hours invested to make the game most of these tend to pay out at a few cents or a fraction of a cent per hour.


Products that work somewhat in-between the two tend to have different results.

#5310448 Mines here and there

Posted by on 12 September 2016 - 08:22 AM

In a human-versus-human game, how would the humans handle it?


Would humans continue to use the road and accept a few random casualties? Would humans find an alternate route? Would humans send an army of cheap disposable troops to trip all the mines?


The AI should probably do the same thing the humans would do in a similar situation.  Whatever makes sense for the game is for that game the AI should be doing.  If there are multiple strategies that are good in the game, the AI should pick between them roughly as players will.

#5310393 2.5d

Posted by on 11 September 2016 - 09:58 PM

2.5d graphic like this



Unfortunately the term 2.5d has been abused by enough people that it often no longer means what it originally meant and is beginning to lose all meaning in the field.  


Originally it was used for first-person-shooters that appeared to be 3D but were actually 2D maps with some visual tricks thrown in.  Wolfenstein 3D (1992) and the original Doom  (1993) both fit that description.  Today people use the term for the original meaning, and for isometric views, and for constrained views, and for anything that looks realistically rendered, and for more meanings besides.  This seems to be your case here.





What is a point of using 2.5d graphic like this



That specific game, Factorio, is a 2D game where the images are rendered and animated in a style that looks 3D.  The game appears to be made up of rectangular tiles, and each tile has artwork.


The art style happens to look like 3D pipes with fluid rushing through it, or as towers and buildings sticking from the ground, or as units standing up, but they could have made any art style they wanted.  Even so, they appear to be 2D images, basically the same as jpeg and gif and png files. (Games typically don't use those formats as there are more efficient graphics formats that can be transferred directly to the video card.)


As for the point of doing it, the way the game world works is often an important consideration.  By keeping the gameplay world flat the design stays close to many table-top games and card games. The design is laying tiles down on top of the game board, either replacing or augmenting existing tiles.


They have kept the game world effectively as a flat map where players interact from above with tiles of objects. Design-wise this means many other choices fall into place as a result of the decision. Keeping the game as effectively a tile-based board game allows for several common picking-based user interfaces, and allows worlds to be manipulated as grids and tiles. It has design implications to game strategy, to character pathfinding, to space usage, and more.  It also has non-design technical implications to how the world technology is built, how data files are manipulated, how rendering works, and so on.




I have to create 3d model and then cut it to 2d or there is another option?


If you are making the artwork you can use whatever you want.  You may choose to render it as views from a 3D rendering program.  You may choose to take photographs of real objects and edit them down as needed. You may choose to use carefully drawn 2D art. As these appear to be basic tiles you can draw the images using whatever method you choose, in whatever art style you choose, as long as you ultimately get them into the game in the required formats.


In this case they chose to make an art style that looks like 3D with a nearly top-down perspective.  Visual styles are important when building a brand and theme for a game. Some games incorporate multiple art styles and different tile or model sets, some games rely heavily on a specific look and feel for their brand.  That was a choice they made, if you aren't part of the company you can do whatever you wish.


They could have chosen any art style, but that's the one they chose for whatever artistic reasons they had.