Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


rip-off

Member Since 16 Mar 2005
Offline Last Active Today, 04:31 PM

#5230927 1 (interface) header with 2 cpp (implementation) files?

Posted by rip-off on 25 May 2015 - 04:43 PM

Generally, this would not be considered idiomatic and could be confusing. Where possible, classes should be small and focused - having to spread the implementation across multiple files suggests this is not the case.

For my case this is a good solution.

It could be a fine solution. You don't want to spend infinite time designing and implementing your game, so at some point you have to put the pencil down.

Peripheral code, like a menu system, doesn't deserve the same amount time and attention to the core, which you'll be iterating on more and where poor design will slow you down more and more over time.

Separating into another class will create extra complexity with interfacing and continously sending data around from one class to another.

This is the crux of design, can you come up with a way of decoupling this data that you currently feel you need to "send around"?

I'd have to see some code to understand exactly what is going on, but it isn't immediately obvious to me why the menu and application need to interact so heavily. If you were to show us the header file, and outline which functions would be implemented in the different source files, we would really start to see your design.

For very simple games, a simple menu enumeration can suffice. There is nothing wrong with a few switch statements to call your main menu rendering logic, your audio settings rendering logic and having another switch in your menu event loop dispatcher - it gets the job done.

For games with a bit more going on, I've also used a simple "game state" model, the application delegates to the current state, e.g. update, render, handle input. The current state can return a new state at the end of each loop. The state could be an PlayIntroState, a MainMenuState, various other menu states, a LevelLoadingState and a PlayLevelState. With such a design, you might end up with a lot more classes / files, but each one is very simple and does just one thing. The application can be largely ignorant of the actual details of the states it is cycling through, once it has the initial state.

For complex games (which I don't write), I imagine you'll probably be configuring / scripting / skinning whatever menu systems the game engine provides you.


#5229303 Another basic array C problem

Posted by rip-off on 16 May 2015 - 08:40 AM

It is important not to be intimidated by the more complex interface of a modern and full-featured IDE like Visual Studio. It was a mistake I made when I was starting out. Having good tools is vital.

As for your program, there are definitely a few things the compiler should be noticing for you. Look into configuring your build tools to have a very high warning level (ideally, all warnings) and also to treat warnings as errors. Particularly as a beginner, any warning is very likely to be an issue you should fix.

When I compile your program (slightly modified for Linux), I get the following output:
$ gcc gamedev.c -Wall -Werror
gamedev.c: In function ‘main’:
gamedev.c:16:1: error: statement with no effect [-Werror=unused-value]
 temp[day][city];
 ^
gamedev.c:19:1: error: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘double *’ [-Werror=format=]
 scanf("%d",&temp[day][city]);
 ^
gamedev.c:37:8: error: character constant too long for its type [-Werror]
 switch('select'){
        ^
gamedev.c:38:1: error: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘double’ [-Werror=format=]
 case 'H':printf("\nHighest temperature is  %d in %d city in %d day",temp[1][1],j,i);
 ^
gamedev.c:40:1: error: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘double’ [-Werror=format=]
 case 'L':printf("\nLowest temperature is %d in %d city in %d day ",temp[5][3],j,i);
 ^
cc1: all warnings being treated as errors
These should be simple enough to fix, but see if you can configure your environment to give you a similar set of warnings - the exact warnings offered vary between compilers, do don't worry if you don't get them all or see other ones.

Be consistent with your formatting and indentation. It is hard to know because without the proper [code=auto:0] tags, much of the indentation was lost, but a simple example is where you place the curly braces after a loop or conditional statement. The two most common conventions are on the same line (possibly with whitespace preceding it), or on the next line. It doesn't matter which one you pick, but it does matter that you pick one and be consistent.

Also, another thing that will make your code easier to read is to use more whitespace around expressions. Again, the exact details can vary, but almost everyone would agree that this:
for(i=1;i<=MAXDAY;i++)
{
    for(j=1;j<=MAXCITY;j++)
    {
        if(temp[i][j]>=temp[i+1][j+1])
        {
            swap=0;
            swap=temp[i][j];
            temp[i][j]=temp[i+1][j+1];
            temp[i+1][j+1]=swap;
        }
    }
}
Is a bit harder to read than this:
for (i = 1; i <= MAXDAY; i++)
{
    for (j = 1; j <= MAXCITY; j++)
    {
        if (temp[i][j] >= temp[i + 1][j + 1])
        {
            swap = 0;
            swap = temp[i][j];
            temp[i][j] = temp[i + 1][j + 1];
            temp[i + 1][j + 1] = swap;
        }
    }
}
Typically I'd put a space between function parameters too, for example:
// Instead of:
printf("Day= %d City=%d ",day,city);
// Consider
printf("Day= %d City=%d ", day, city);
Even with all this, you won't have fixed everything, but you'll be much better placed to solve the remaining issue.


#5228125 Terrible Broken Age sales...!? (steamspy)

Posted by rip-off on 09 May 2015 - 09:47 AM

Have you watched the "Double Fine Adventure" documentary series? It is now available for free on Youtube, and there are entries that cover the initial release (in particular towards the end of EP 16 and start of EP 17). It's a fascinating documentary, worth a watch I think.

I believe humble bundles include DRM free versions, which could mean that not every HB sale can be counted against the Steam numbers - and the game is available on a bunch of other platforms too.


#5221706 please help with SDL

Posted by rip-off on 06 April 2015 - 03:39 PM

Please note that text is the preferred communication mechanism between programmers. You can include or link to images to aid understanding, but usually just copying and pasting the error message(s) and any offending code as text is a better approach.

The problem with images is that even if I can see code it in, I cannot easily edit / compile / run. I would have to type it out again. Likewise, with error messages, I cannot easily throw them into Google, I would have to re-type them.

Generally, I'd recommend not including images unless you're having difficulty explaining the issue without it.


#5218931 Future proof scoreboard server design pattern

Posted by rip-off on 24 March 2015 - 05:37 PM

I'd recommend including a version identifier in client requests, preferably in the URL.

Yep. What do you mean by "preferably in the URL"? Do you mean that my PHP scripts shall have a version ID in their name?
 
This will allow multiple versions of my app to access the same database. It will for instance be possible to rename a variable. Is that the reason for this version ID?

Something like yourgame.yoursite.com/v1/scoreboard

If you need to create a new version of the API, just point them at /v2/whatever instead. This way, it is very easy to distinguish requests using the older version. In particular, it is each to configure front-facing servers to match on URLs and forward requests to different back-end servers.

This may not be a concern right now, but this gives flexibility in future.

Another thing to consider is to specify a couple of response types now that all client versions can understand. For example, a particular HTTP status and/or payload might indicate that the client is out of date, so the client could display a "please update" message to the user.


#5218640 Future proof scoreboard server design pattern

Posted by rip-off on 23 March 2015 - 04:38 PM

I'd recommend including a version identifier in client requests, preferably in the URL.


#5215182 C# Linked List implementation review

Posted by rip-off on 07 March 2015 - 02:47 PM

Try to delay the declaration of variables until you actually need them. I think some of the complexity of the InsertNode comes from feeling like you have to make use of the temporaries you declared.

The DeleteNode seems to be handling a lot of special cases. I think you can get away with only one special case, and that is for the "head" node.

For example, look at this bit:
if (current.next != null)
{
    list = current.next;
}
else
{
    list = null;
}
We assign current.next to list if it is not null, otherwise we explicitly assign null. That block is functionally equivalent to:
list = current.next;
In addition, don't be afraid to write helper methods to split out some of the logic.

I think they could be simplified to something not unlike this:
public void InsertNode(string stringIn, uint index)
{
    if (IndexOutOfUpperBounds(index))
    {
        return;
    }

    StringNode newNode = new StringNode(stringIn);

    if (index == 0)
    {
        newNode.next = list;
        list = newNode;
    }
    else
    {
        StringNode node = GetNodeAt(index - 1);
        newNode.next = node.next;
        node.next = newNode;
    }

    this.Count++;
}

public bool DeleteNode(uint index)
{
    if (IndexOutOfUpperBounds(index))
    {
        return false;
    }

    if (index == 0)
    {
        list = list.next;
    }
    else
    {
        StringNode node = GetNodeAt(index - 1);
        node.next = node.next.next;
    }

    this.Count--;
    return true;
}

private StringNode GetNodeAt(uint index)
{
    // TODO: decide how to handle bounds checking

    StringNode current = list;
    for (uint i = 0 ; i < index ; ++i) {
        current = current.next;
    }
    return current;
}
I haven't tested this.


#5213660 I think I don't understand dynamic memory

Posted by rip-off on 01 March 2015 - 08:55 AM

I don't know if this constitutes a "theory", but maybe a good way to answer your qusetion is to illustrate some common scenarios, with examples, where a programmer might reach for dynamic memory allocation.

The programmer cannot predict the number of objects to run computations at compile time. Knowing the exact number of objects in advance is rare, in fact. There are two primary exceptions:
  • The domain itself has hard limits in place. For example, Chess is played on an 8 x 8 board with 16 pieces per player, so a program for playing chess can avoid dynamic allocation for storing the state of the board. However, the number of moves during the game is not known in advance, so dynamic memory would be required to provide a full game log.
  • The designer chooses an arbitrary limitation on some aspect of the program. This can be for a number of reasons, including not wanting to design a flexible UI that can cope with arbitrary amounts of data (thus avoiding complex workflows like search, sort and paging) or to achieve soft real time performance goals( in a game context this could be trying to ensure that no frame takes more than 16.6 milliseconds).
Another reason is that the lifetime of an object is unknown at compile time. It will almost certainly outlast the function that creates it, it may even outlast the object or objects it is first stored in. An example might be a particular map texture in a multi-player FPS client. Provided the server's map rotation continues to require that texture, it would be preferable to avoid unloading and reloading it. However, once the texture is no longer required, it can be remove to make way for the new textures the next map needs instead. Thus any given texture might be stored for the duration of one map, or several.

Another is the behaviour of the object cannot be precisely determined at compile time. Most object oriented languages implement polymorphism by allocating a dynamic amount of memory, and returning some kind of reference to this memory. Other parts of the code might take a more generic reference, e.g. a pointer to a super class in C++, and without knowing the exact size or layout of the object it can be made use of. Some simple games can be implemented such that every game object inherits from a very simple base class with a virtual function for updating itself (e.g. Asteroids). Most people find that this approach typically doesn't scale well once the number of object types starts to grow.

Finally, a programmer may be forced to use dynamic memory because the language or library they are using make use of it. In particular, it is common in C APIs not to expose the definition of a data structure, which provides maximum freedom for the library implementor when making changes. For example, the Simple Directmedia Library (SDL) is a C API which does this. Some of the API calls wouldn't necessarily require dynamic amounts of memory, but by hiding the details the library implementation can change the size of it's data structures without changing the public API. It also makes the API consistent, as now there is a common pattern for interacting with all parts of the API.


#5213502 I think I don't understand dynamic memory

Posted by rip-off on 28 February 2015 - 10:21 AM

Dynamic memory means that the memory lifetime isn't managed automatically by the language - like how when you call a function, memory is automatically provided for the various local variables you need.

Dynamic memory is, by default, managed explicitly by the programmer. This is the familiar new / delete or new[] / delete[] calls.

However, by using the other features of the language, namely destructors, this can be automated again - the explicit memory management is done by the implicitly called destructors. So the std::make_shared<> will dynamically allocate the object, and the destructor deallocates it.

Now, to come to your Student class. It may in fact use dynamic memory, as std::string is dynamically sized (though some implementations can avoid allocations for short strings). However, this is irrelevant, as any object can be dynamically allocated - you can dynamically allocate an "int" if you want.


#5212291 which psyhics engine should i use for arhery game in java?

Posted by rip-off on 22 February 2015 - 11:19 AM

Can you tell us a little more about your game? What are your requirements? Is it going to be a realistic simulation game, or would a good-enough "arcade" feel work fine?


#5210138 Exception while loading a file with content in Java

Posted by rip-off on 11 February 2015 - 04:32 PM

In addition, your code doesn't close the scanner in the event of an exception.

Note that in recent versions of Java you should be able to write:
try (Scanner loadScanner = new Scanner(loadPath)) {
    // Use the scanner
} catch (IOException e) {
    e.printStackTrace();
}
This is called "try with resources", and the resource specified is automatically closed, whether an exception occurs or not - you don't have to write such code yourself.


#5210029 Sending Messages To Multiple Clients

Posted by rip-off on 11 February 2015 - 08:16 AM

You're using threading, are you sure the object's lifetime persists until the callback executes? How are you ensuring your "Clients" collection is not being accessed by two threads at once?




#5210006 Exception while loading a file with content in Java

Posted by rip-off on 11 February 2015 - 06:17 AM

The error is thrown by the Scanner. Can you post the file you're using?




#5209411 Does games that were writen in "c" will be processed faster then...

Posted by rip-off on 08 February 2015 - 08:38 AM

If you're posting in "For Beginners", the choice of programming language will certainly not be the thing that limits your game's performance. To get maximum speed from a low level systems language requires lots of experience and understanding of how modern machines work. For lots of programs, getting the correct algorithms and data structures is far more important and far more likely to be the bottleneck.

Low level languages like C and C++ are extremely unforgiving to beginners, as they were designed with the maxim "The programmer is always right". Even master programmers make mistakes on occasion, but beginners are certain to make lots of mistakes that are going to be frustrating to understand, debug and finally fix.

As mentioned, the biggest risk to a project is that it will not be completed - and choosing a complicated and challenging language certainly increases that risk. Again, as a beginner, you might be better off making a few smaller games first to gain experience - not trying to take on something that will push computers to their limits. Think smaller games, maybe 2D, not necessarily the larger 3D ones you want to sell. Once you've built up the basic skills you need, then tackling that bigger, more commercially viable, game becomes a more realistic goal, and you'll do a far better job having learned some necessary lessons in those smaller, safer ventures that you got out of the way first.

To be absolutely clear: if you're not sure what language to use, it is clear that you haven't yet built up the necessary skills to develop and release a real, polished, commercially viable game. So focus on building up those skills now.

You might be asking the wrong question. Consider experimenting with existing technology, rather than making a large investment building your own. You will likely be far more productive scripting something like Unity than trying to build a game from scratch using, for example, C or C++ and OpenGL. You can lean on the expertise of the engine programmers, and really concentrate on building a compelling game.


#5208392 SDL2 and Linux [RANT]

Posted by rip-off on 03 February 2015 - 07:41 AM

Generally, I've found SDL to be a fantastic piece of software.






PARTNERS