Creating the Server
Shell
The Server Shell, if implemented, is responsible for handling AI,
physics, and generally maintaining the state of the simulatoin. More detail is
available in the LithTech Programming Guide.
This page will lead you through the creation of this class, although
our implementation will be quite simple.
To get started, create a new file in Visual Studio and save it as ltservershell.h. Add the necessary
multiple-inclusion protection, and include the engine header.
#ifndef
__LT_SERVER_SHELL_H__ |
#define
__LT_SERVER_SHELL_H__ |
|
// Engine includes |
#include
<iservershell.h> |
|
As we did for the client shell, we declare the CLTServerShell class, include
the constructor and destructor, and declare it to the interface manager.
class CLTServerShell
: public IServerShellStub { |
public: |
CLTServerShell(); |
~CLTServerShell(); |
|
declare_interface(CLTServerShell); |
|
We now override two necessary LithTech functions. OnClientEnterWorld
and OnClientExitWorld are called automatically by the engine whenever a client
enters or exits the world, respectively. This is the end of our simple server
shell class declaration.
// LithTech defined functions |
LPBASECLASS OnClientEnterWorld(HCLIENT hClient, void *pClientData, uint32
nClientDataLen); |
void OnClientExitWorld(HCLIENT
hClient); |
|
}; |
|
#endif
//__LT_SERVER_SHELL_H__ |
Save the ltservershell.h file in the following directory:
<your project directory>\sshell\src
Now, create another file in Visual Studio and save it as ltservershell.cpp. Include the class header
file along with some engine headers.
#include "ltservershell.h" |
#include <iltserver.h> |
#include <ltbasedefs.h> |
|
Several macros need to be called to set up various components of the
server shell. We also initialize the global server shell pointer.
SETUP_SERVERSHELL() |
DEFINE_CLASSES() |
|
define_interface(CLTServerShell, IServerShell); |
|
CLTServerShell *g_pSShell = NULL; |
|
The constructor and destructor do nothing in this basic sample.
CLTServerShell::CLTServerShell() { |
} |
|
CLTServerShell::~CLTServerShell() { |
} |
|
These two functions are called after any client enters or exits the
world. In an actual LithTech application, these functions are where player
objects are created and deleted.
LPBASECLASS CLTServerShell::OnClientEnterWorld(HCLIENT
hClient, |
void *pClientData, uint32 nClientDataLen) { |
return
NULL; |
} |
|
void CLTServerShell::OnClientExitWorld(HCLIENT
hClient) { |
} |
That’s it for the basic server shell implementation. Save the ltservershell.cpp file in the following directory:
<your project directory>\sshell\src