remove engine/client.cc and engine/server.cc

master
Daniel Kolesa 2020-04-26 00:20:00 +02:00
parent 311f09270a
commit 4c0496c07a
9 changed files with 51 additions and 263 deletions

View File

@ -8,7 +8,6 @@ client_src = [
'../engine/aa.cc', '../engine/aa.cc',
'../engine/bih.cc', '../engine/bih.cc',
'../engine/blend.cc', '../engine/blend.cc',
'../engine/client.cc',
'../engine/command.cc', '../engine/command.cc',
'../engine/console.cc', '../engine/console.cc',
'../engine/dynlight.cc', '../engine/dynlight.cc',
@ -31,7 +30,6 @@ client_src = [
'../engine/rendersky.cc', '../engine/rendersky.cc',
'../engine/rendertext.cc', '../engine/rendertext.cc',
'../engine/renderva.cc', '../engine/renderva.cc',
'../engine/server.cc',
'../engine/shader.cc', '../engine/shader.cc',
'../engine/stain.cc', '../engine/stain.cc',
'../engine/texture.cc', '../engine/texture.cc',

View File

@ -1,33 +0,0 @@
// client.cpp, mostly network related client game code
#include "engine.hh"
bool multiplayer(bool msg)
{
return false;
}
bool isconnected(bool attempt, bool local)
{
return haslocalclients();
}
void trydisconnect()
{
if(haslocalclients()) localdisconnect();
else conoutf("not connected");
}
ICOMMAND(disconnect, "", (), trydisconnect());
ICOMMAND(localconnect, "", (), { if(!isconnected()) localconnect(); });
ICOMMAND(localdisconnect, "", (), { if(haslocalclients()) localdisconnect(); });
void clientkeepalive() {}
void gets2c() {}
void neterr(const char *s, bool disc)
{
conoutf(CON_ERROR, "\f3illegal network message (%s)", s);
if(disc) localdisconnect();
}

View File

@ -31,7 +31,7 @@ void conoutfv(int type, const char *fmt, va_list args)
static char buf[CONSTRLEN]; static char buf[CONSTRLEN];
vformatstring(buf, fmt, args, sizeof(buf)); vformatstring(buf, fmt, args, sizeof(buf));
conline(type, buf); conline(type, buf);
logoutf("%s", buf); printf("%s\n", buf);
} }
void conoutf(const char *fmt, ...) void conoutf(const char *fmt, ...)

View File

@ -525,12 +525,6 @@ extern void loadcaustics(bool force = false);
extern void renderwaterfog(int mat, float blend); extern void renderwaterfog(int mat, float blend);
extern void preloadwatershaders(bool force = false); extern void preloadwatershaders(bool force = false);
// server
extern void initserver();
extern void cleanupserver();
extern void updatetime();
extern void localconnect();
// client // client
extern void localdisconnect(bool cleanup = true); extern void localdisconnect(bool cleanup = true);
extern void clientkeepalive(); extern void clientkeepalive();

View File

@ -4,12 +4,37 @@
#include "engine.hh" #include "engine.hh"
void clientkeepalive() {}
bool multiplayer(bool msg)
{
return false;
}
bool isconnected(bool attempt, bool local)
{
return haslocalclients();
}
void localdisconnect(bool cleanup)
{
game::gamedisconnect(cleanup);
mainmenu = 1;
}
void trydisconnect()
{
if(haslocalclients()) localdisconnect();
else conoutf("not connected");
}
ICOMMAND(disconnect, "", (), trydisconnect());
extern void cleargamma(); extern void cleargamma();
void cleanup() void cleanup()
{ {
recorder::stop(); recorder::stop();
cleanupserver();
SDL_ShowCursor(SDL_TRUE); SDL_ShowCursor(SDL_TRUE);
SDL_SetRelativeMouseMode(SDL_FALSE); SDL_SetRelativeMouseMode(SDL_FALSE);
if(screen) SDL_SetWindowGrab(screen, SDL_FALSE); if(screen) SDL_SetWindowGrab(screen, SDL_FALSE);
@ -20,7 +45,6 @@ void cleanup()
extern void clear_console(); clear_console(); extern void clear_console(); clear_console();
extern void clear_models(); clear_models(); extern void clear_models(); clear_models();
//extern void clear_sound(); clear_sound(); //extern void clear_sound(); clear_sound();
closelogfile();
#ifdef __APPLE__ #ifdef __APPLE__
if(screen) SDL_SetWindowFullscreen(screen, 0); if(screen) SDL_SetWindowFullscreen(screen, 0);
#endif #endif
@ -46,7 +70,7 @@ void fatal(const char *s, ...) // failure exit
if(errors <= 2) // print up to one extra recursive error if(errors <= 2) // print up to one extra recursive error
{ {
defvformatstring(msg,s,s); defvformatstring(msg,s,s);
logoutf("%s", msg); printf("%s\n", msg);
if(errors <= 1) // avoid recursion if(errors <= 1) // avoid recursion
{ {
@ -1018,21 +1042,11 @@ int main(int argc, char **argv)
#endif #endif
#endif #endif
setlogfile(NULL); char *initscript = NULL;
char *load = NULL, *initscript = NULL;
initing = INIT_RESET; initing = INIT_RESET;
// set home dir first // set home dir first
sethomedir("$HOME/.octacore"); sethomedir("$HOME/.octacore");
// set log after home dir, but before anything else
for(int i = 1; i<argc; i++) if(argv[i][0]=='-' && argv[i][1] == 'g')
{
const char *file = argv[i][2] ? &argv[i][2] : "log.txt";
setlogfile(file);
logoutf("Setting log file: %s", file);
break;
}
execfile("config/init.cfg", false); execfile("config/init.cfg", false);
for(int i = 1; i<argc; i++) for(int i = 1; i<argc; i++)
{ {
@ -1041,21 +1055,13 @@ int main(int argc, char **argv)
case 'k': case 'k':
{ {
const char *dir = addpackagedir(&argv[i][2]); const char *dir = addpackagedir(&argv[i][2]);
if(dir) logoutf("Adding package directory: %s", dir); if(dir) printf("Adding package directory: %s\n", dir);
break; break;
} }
case 'g': break; case 'g': break;
case 'w': scr_w = clamp(atoi(&argv[i][2]), SCR_MINW, SCR_MAXW); if(!findarg(argc, argv, "-h")) scr_h = -1; break; case 'w': scr_w = clamp(atoi(&argv[i][2]), SCR_MINW, SCR_MAXW); if(!findarg(argc, argv, "-h")) scr_h = -1; break;
case 'h': scr_h = clamp(atoi(&argv[i][2]), SCR_MINH, SCR_MAXH); if(!findarg(argc, argv, "-w")) scr_w = -1; break; case 'h': scr_h = clamp(atoi(&argv[i][2]), SCR_MINH, SCR_MAXH); if(!findarg(argc, argv, "-w")) scr_w = -1; break;
case 'f': fullscreen = atoi(&argv[i][2]); break; case 'f': fullscreen = atoi(&argv[i][2]); break;
case 'l':
{
char pkgdir[] = "media/";
load = strstr(path(&argv[i][2]), path(pkgdir));
if(load) load += sizeof(pkgdir)-1;
else load = &argv[i][2];
break;
}
case 'x': initscript = &argv[i][2]; break; case 'x': initscript = &argv[i][2]; break;
default: break; default: break;
} }
@ -1063,15 +1069,14 @@ int main(int argc, char **argv)
numcpus = clamp(SDL_GetCPUCount(), 1, 16); numcpus = clamp(SDL_GetCPUCount(), 1, 16);
logoutf("init: sdl"); printf("init: sdl\n");
if(SDL_Init(SDL_INIT_TIMER|SDL_INIT_VIDEO|SDL_INIT_AUDIO)<0) fatal("Unable to initialize SDL: %s", SDL_GetError()); if(SDL_Init(SDL_INIT_TIMER|SDL_INIT_VIDEO|SDL_INIT_AUDIO)<0) fatal("Unable to initialize SDL: %s", SDL_GetError());
logoutf("init: game"); printf("init: game\n");
initserver();
game::initclient(); game::initclient();
logoutf("init: video"); printf("init: video\n");
SDL_SetHint(SDL_HINT_GRAB_KEYBOARD, "0"); SDL_SetHint(SDL_HINT_GRAB_KEYBOARD, "0");
#if !defined(WIN32) && !defined(__APPLE__) #if !defined(WIN32) && !defined(__APPLE__)
SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0"); SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0");
@ -1080,13 +1085,13 @@ int main(int argc, char **argv)
SDL_ShowCursor(SDL_FALSE); SDL_ShowCursor(SDL_FALSE);
SDL_StopTextInput(); // workaround for spurious text-input events getting sent on first text input toggle? SDL_StopTextInput(); // workaround for spurious text-input events getting sent on first text input toggle?
logoutf("init: gl"); printf("init: gl\n");
gl_checkextensions(); gl_checkextensions();
gl_init(); gl_init();
notexture = textureload("media/texture/game/notexture.png"); notexture = textureload("media/texture/game/notexture.png");
if(!notexture) fatal("could not find core textures"); if(!notexture) fatal("could not find core textures");
logoutf("init: console"); printf("init: console\n");
if(!execfile("config/stdlib.cfg", false)) fatal("cannot find data files (you are running from the wrong folder, try .bat file in the main folder)"); // this is the first file we load. if(!execfile("config/stdlib.cfg", false)) fatal("cannot find data files (you are running from the wrong folder, try .bat file in the main folder)"); // this is the first file we load.
if(!execfile("config/font.cfg", false)) fatal("cannot find font definitions"); if(!execfile("config/font.cfg", false)) fatal("cannot find font definitions");
if(!setfont("default")) fatal("no default font specified"); if(!setfont("default")) fatal("no default font specified");
@ -1096,14 +1101,14 @@ int main(int argc, char **argv)
inbetweenframes = true; inbetweenframes = true;
renderbackground("initializing..."); renderbackground("initializing...");
logoutf("init: world"); printf("init: world\n");
camera1 = player = game::iterdynents(0); camera1 = player = game::iterdynents(0);
emptymap(0, true, NULL, false); emptymap(0, true, NULL, false);
logoutf("init: sound"); printf("init: sound\n");
//initsound(); //initsound();
logoutf("init: cfg"); printf("init: cfg\n");
initing = INIT_LOAD; initing = INIT_LOAD;
execfile("config/keymap.cfg"); execfile("config/keymap.cfg");
execfile("config/stdedit.cfg"); execfile("config/stdedit.cfg");
@ -1128,7 +1133,7 @@ int main(int argc, char **argv)
initing = NOT_INITING; initing = NOT_INITING;
logoutf("init: render"); printf("init: render\n");
restoregamma(); restoregamma();
restorevsync(); restorevsync();
initgbuffer(); initgbuffer();
@ -1138,17 +1143,10 @@ int main(int argc, char **argv)
identflags |= IDF_PERSIST; identflags |= IDF_PERSIST;
logoutf("init: mainloop"); printf("init: mainloop\n");
if(execfile("once.cfg", false)) remove(findfile("once.cfg", "rb")); if(execfile("once.cfg", false)) remove(findfile("once.cfg", "rb"));
if(load)
{
logoutf("init: localconnect");
//localconnect();
game::changemap(load);
}
if(initscript) execute(initscript); if(initscript) execute(initscript);
//initmumble(); //initmumble();
@ -1171,7 +1169,6 @@ int main(int argc, char **argv)
if(game::ispaused()) curtime = 0; if(game::ispaused()) curtime = 0;
lastmillis += curtime; lastmillis += curtime;
totalmillis = millis; totalmillis = millis;
updatetime();
checkinput(); checkinput();
//UI::update(); //UI::update();

View File

@ -1,159 +0,0 @@
// server.cpp: little more than enhanced multicaster
// runs dedicated or as client coroutine
#include "engine.hh"
#define LOGSTRLEN 512
static FILE *logfile = NULL;
void closelogfile()
{
if(logfile)
{
fclose(logfile);
logfile = NULL;
}
}
FILE *getlogfile()
{
#ifdef WIN32
return logfile;
#else
return logfile ? logfile : stdout;
#endif
}
void setlogfile(const char *fname)
{
closelogfile();
if(fname && fname[0])
{
fname = findfile(fname, "w");
if(fname) logfile = fopen(fname, "w");
}
FILE *f = getlogfile();
if(f) setvbuf(f, NULL, _IOLBF, BUFSIZ);
}
void logoutf(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
logoutfv(fmt, args);
va_end(args);
}
static void writelog(FILE *file, const char *buf)
{
static uchar ubuf[512];
size_t len = strlen(buf), carry = 0;
while(carry < len)
{
size_t numu = encodeutf8(ubuf, sizeof(ubuf)-1, &((const uchar *)buf)[carry], len - carry, &carry);
if(carry >= len) ubuf[numu++] = '\n';
fwrite(ubuf, 1, numu, file);
}
}
static void writelogv(FILE *file, const char *fmt, va_list args)
{
static char buf[LOGSTRLEN];
vformatstring(buf, fmt, args, sizeof(buf));
writelog(file, buf);
}
#define DEFAULTCLIENTS 8
enum { ST_EMPTY, ST_LOCAL, ST_TCPIP };
struct client // server side version of "dynent" type
{
int type;
int num;
string hostname;
void *info;
};
vector<client *> clients;
int laststatus = 0;
int localclients = 0;
bool hasnonlocalclients() { return false; }
bool haslocalclients() { return localclients!=0; }
client &addclient(int type)
{
client *c = NULL;
loopv(clients) if(clients[i]->type==ST_EMPTY)
{
c = clients[i];
break;
}
if(!c)
{
c = new client;
c->num = clients.length();
clients.add(c);
}
c->type = type;
switch(type)
{
case ST_LOCAL: localclients++; break;
}
return *c;
}
void delclient(client *c)
{
if(!c) return;
switch(c->type)
{
case ST_LOCAL: localclients--; break;
case ST_EMPTY: return;
}
c->type = ST_EMPTY;
}
void cleanupserver()
{
}
void updatetime()
{
}
void localdisconnect(bool cleanup)
{
bool disconnected = false;
loopv(clients) if(clients[i]->type==ST_LOCAL)
{
delclient(clients[i]);
disconnected = true;
}
if(!disconnected) return;
game::gamedisconnect(cleanup);
mainmenu = 1;
}
void localconnect()
{
if(initing) return;
client &c = addclient(ST_LOCAL);
copystring(c.hostname, "local");
game::gameconnect(false);
}
void logoutfv(const char *fmt, va_list args)
{
FILE *f = getlogfile();
if(f) writelogv(f, fmt, args);
}
void initserver()
{
}

View File

@ -80,7 +80,7 @@ static void showglslinfo(GLenum type, GLuint obj, const char *name, const char *
if(length > 1) if(length > 1)
{ {
conoutf(CON_ERROR, "GLSL ERROR (%s:%s)", type == GL_VERTEX_SHADER ? "VS" : (type == GL_FRAGMENT_SHADER ? "FS" : "PROG"), name); conoutf(CON_ERROR, "GLSL ERROR (%s:%s)", type == GL_VERTEX_SHADER ? "VS" : (type == GL_FRAGMENT_SHADER ? "FS" : "PROG"), name);
FILE *l = getlogfile(); FILE *l = stdout;
if(l) if(l)
{ {
GLchar *log = new GLchar[length]; GLchar *log = new GLchar[length];
@ -1281,7 +1281,7 @@ bool shouldreuseparams(Slot &s, VSlot &p)
ICOMMAND(dumpshader, "sbi", (const char *name, int *col, int *row), ICOMMAND(dumpshader, "sbi", (const char *name, int *col, int *row),
{ {
Shader *s = lookupshaderbyname(name); Shader *s = lookupshaderbyname(name);
FILE *l = getlogfile(); FILE *l = stdout;
if(!s || !l) return; if(!s || !l) return;
if(*col >= 0) if(*col >= 0)
{ {

View File

@ -37,7 +37,7 @@ namespace game
settexture("media/interface/radar/radar.png", 3); settexture("media/interface/radar/radar.png", 3);
} }
bool connected = false, remote = false; bool connected = false;
int sessionid = 0; int sessionid = 0;
string servdesc = "", servauth = ""; string servdesc = "", servauth = "";
@ -78,9 +78,8 @@ namespace game
void changemap(const char *name, int mode) // request map change, server may ignore void changemap(const char *name, int mode) // request map change, server may ignore
{ {
changemapserv(name, 0); changemapserv(name, 0);
localconnect();
clearmainmenu(); /* XXX hack */
connected = true; connected = true;
clearmainmenu(); /* XXX hack */
} }
void changemap(const char *name) void changemap(const char *name)
{ {
@ -97,7 +96,6 @@ namespace game
{ {
if(size>=0) emptymap(size, true, NULL); if(size>=0) emptymap(size, true, NULL);
else enlargemap(true); else enlargemap(true);
localconnect();
connected = true; connected = true;
} }
@ -118,14 +116,16 @@ namespace game
{ {
} }
void gameconnect(bool _remote) void gameconnect()
{ {
remote = _remote;
} }
void gamedisconnect(bool cleanup) void gamedisconnect(bool cleanup)
{ {
connected = remote = false; if (!connected) {
return;
}
connected = false;
player1->clientnum = -1; player1->clientnum = -1;
if(editmode) toggleedit(); if(editmode) toggleedit();
sessionid = 0; sessionid = 0;
@ -140,3 +140,4 @@ namespace game
void toserver(char *text) { conoutf(CON_CHAT, "%s", text); } void toserver(char *text) { conoutf(CON_CHAT, "%s", text); }
} }
bool haslocalclients() { return game::connected; }

View File

@ -195,12 +195,6 @@ extern void conoutf(const char *s, ...) PRINTFARGS(1, 2);
extern void conoutf(int type, const char *s, ...) PRINTFARGS(2, 3); extern void conoutf(int type, const char *s, ...) PRINTFARGS(2, 3);
extern void conoutfv(int type, const char *fmt, va_list args); extern void conoutfv(int type, const char *fmt, va_list args);
extern FILE *getlogfile();
extern void setlogfile(const char *fname);
extern void closelogfile();
extern void logoutfv(const char *fmt, va_list args);
extern void logoutf(const char *fmt, ...) PRINTFARGS(1, 2);
// octa // octa
extern int lookupmaterial(const vec &o); extern int lookupmaterial(const vec &o);
@ -449,11 +443,7 @@ extern bool matchanim(const char *name, const char *pattern);
extern void moveragdoll(dynent *d); extern void moveragdoll(dynent *d);
extern void cleanragdoll(dynent *d); extern void cleanragdoll(dynent *d);
// server
extern void localconnect();
extern bool haslocalclients();
// client // client
extern bool haslocalclients();
extern bool isconnected(bool attempt = false, bool local = true); extern bool isconnected(bool attempt = false, bool local = true);
extern bool multiplayer(bool msg = true); extern bool multiplayer(bool msg = true);