• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
greeniekin

Shared code on console server and graphical client

5 posts in this topic

I have read a lot about handling network communication. What I have not read is how to structure objects. I am thinking for c++ specifically.

for instance a server and client share the same entity behavior. Some may be disabled if it is considered authoritative or not. Which the client could be authoritative in single player or when hosting a game, but not when connecting to another server. Also some entities may be predictive like player where it will still run the authorative code. The behavior part is easy enough to account for.

 

An entity will of course contain a graphical part and a behavior part.

A console server will only need the behavior part.

 

 

I can only think of 2 ways.

Have preprocessor  statements in every entity to remove all graphics code. Which is a bit annoying as I will need to access model animations and it's transformations. 

 

The other is have completely separate server and client code and if they run in the same app have the server and client code run.  Problem being is there will be some duplication of information and also any predictive code will need to be written in the client object as well as the server. I suppose it could inherit the code from the server side.

 

So I was just wondering what methods you have seen used and which s the best and why.

 

 

I am pretty tired so sorry if this seems a bit silly. I was just wondering if there is a better way.

 

0

Share this post


Link to post
Share on other sites

Another way to do it is to always have a server process which is authoritative, even when running a single-player game locally. You can even continue communicating over sockets between the two, by using the local loopback address. IIRC, quake worked this way. You also have plenty of other communication channels available locally -- IPC, named pipes, or just adding a layer of abstraction between the "client" and the "server"--one implementation could implement the logic locally, and other could just be a conduit to an actual server across the network.

 

This isn't a direct answer to your question, but would allow you to re-use your code without resorting to conditionally-enabling or disabling code statements, and it should make using the authoritative code in two different apps (the client and stand-alone server) easier (via static library or DLL) easier if you go that route.

0

Share this post


Link to post
Share on other sites

This is easy to solve with a little bit of composition. I'll demonstrate two options in a single source snippet:

 

// SharedLogic.h
class Berzerker
{
public:
    Matrix4x4 Transform;
    unsigned Health;
 
private:
    bool IsAngry;
 
 
    void MakeAngry()
    {
        IsAngry = true;
        Health += 10;
    }
 
    friend class ServerLogic;
 
 
 
public:
    bool CheckAngry() const
    {
        return IsAngry;
    }
};
 
// Server.cpp
#include "SharedLogic.h"
 
class ServerLogic
{
public:
    void Run()
    {
 
       Berzerker b;
 
       while(ServerActive())
       {
           if(PlayerShotBerzerker(b))
               b.MakeAngry();
 
           // etc. 
       }
 
    }
};
 
int main()
{
    ServerLogic sl;
    sl.Run();
}
 
// Client.cpp
#include "SharedLogic.h"
 
template<typename T>
class Renderable
{
private:
    T SharedLogicObject;
 
public:
    T& GetObject() { return SharedLogicObject; }
    const T& GetObject() const  { return SharedLogicObject; }
 
public:
    void Draw(const Model& model)
    {
        GraphicsApi::DrawModelWithTransform(model, SharedLogicObject.Transform);
    }
};
 
class ServerLogic
{
public:
    static void Update(Berzerker& b)
    {
        if(NetworkSaysBerzerkerIsAngry(b))
            b.MakeAngry();
    }
};
 
int main()
{
    Model happyBerzerker("some.mesh");
    Model angryBerzerker("other.mesh");
 
    Renderable<Berzerker> rb;
 
    while(ClientActive())
    {
        if(PlayerFiredWeapon())
            NotifyServer();
 
        CollectServerResponse();
 
        ServerLogic::Update(rb);
 
        if(rb.GetObject().CheckAngry())
            rb.Draw(angryBerzerker);
        else
            rb.Draw(happyBerzerker);
    }
}

 

 

[b]Option One[/b]

Your shared logic lives in a file that both client and server can access. Stats which are visible to both can be public; stats which need to be purely server-authoritative can be private with access controlled via friendship. Your ServerLogic class depends on which code you build; on the server, it's the actual authoritative logic, whereas on the client, it simply polls the network for updated state.

 

[b]Option Two[/b]

The way I deal with separating the rendering shows a similar but alternative form of composition. In this case, you build the special logic in terms of the different [i]pieces[/i] the client or server needs to work with. In this example, the client has a Renderable<> template which holds the shared logic object as well as enables drawing via a model. The template isn't strictly necessary, but it shows how you can apply broad swaths of rendering logic to all of your shared "entity" code with a simple construct.

 

 

Basically neither option is inherently superior, and as above, a blend may work nicely as well. But in general, the idea is you should build your code in small, reusable chunks, and then use (or reuse) them where appropriate on client and server. No need for #ifdefs or other evilness :-)

0

Share this post


Link to post
Share on other sites

Ravyne That method is the second method I mentioned. I suppose writing it that way is easiest in that it always works the same as server client, or the one. Though will double up on memory and resources that could be shared. Like models and there animations

 

ApochPiQ I do like that the only problem is animation needs to be available both for client and server. The server may need it for collision detection stuff.

 

I suppose the completely separate client & server model might be the simplest method and where prediction is needed just inherit for the server. Even if there is some duplication.

0

Share this post


Link to post
Share on other sites
If the "server code" and "client code" within the game process shares the same asset manager object, then you won't be duplicating the memory use. If you split "server" and "client" into separate processes even for single player, then that's harder to do, although with the magic of memory mapped read-only files, you could actually still make that happen (!)
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0