Permalink
Browse files

Merge branch 'deadking' of https://github.com/superjer/SPARToR into d…

…eadking
  • Loading branch information...
2 parents 3f1db7a + e6b36ef commit 0928d9fbd6eba93c6496686a1a3d1556c367cdf3 @superjer superjer committed May 29, 2012
Showing with 450 additions and 101 deletions.
  1. +1 −0 Makefile
  2. +119 −15 engine/command.c
  3. +1 −0 engine/command.h
  4. +16 −16 engine/font.c
  5. +12 −16 engine/input.c
  6. +3 −0 engine/input.h
  7. +142 −0 engine/keynames.c
  8. +5 −0 engine/keynames.h
  9. +1 −1 engine/main.h
  10. +37 −8 engine/saveload.c
  11. +3 −0 engine/saveload.h
  12. +34 −0 game/console/defaults.txt
  13. +57 −42 game/mod.c
  14. +1 −0 game/mod.h
  15. +3 −1 game/mod_private.h
  16. +13 −2 game/obj_ghost.c
  17. +2 −0 platforms/scripts/version.sh
View
@@ -23,6 +23,7 @@ OBJS = engine/main.o \
engine/projection.o \
engine/sjglob.o \
engine/helpers.o \
+ engine/keynames.o \
engine/mt19937ar/mt19937ar.o
FLAGS = --std=c99 -g -Wall -Wextra -Wno-unused-parameter -Wno-overlength-strings -pedantic -DGLEW_STATIC
INC = -Iengine -Igame
View
@@ -10,6 +10,8 @@
** http://github.com/superjer/SPARToR
**/
+#include <limits.h>
+
#include "SDL.h"
#include "SDL_net.h"
#include "mod.h"
@@ -23,36 +25,57 @@
#include "input.h"
#include "saveload.h"
#include "sprite.h"
+#include "keynames.h"
+static void bind( char *dev_sym, char *press_cmdname );
void command(const char *s)
{
char *p, *q;
- p = malloc(strlen(s)+1);
+ q = p = malloc(strlen(s)+1);
strcpy(p,s);
+
+ while( *q ) {
+ if( isspace(*q) ) *q = ' ';
+ q++;
+ }
+
q = strtok(p," ");
+
do {
if( q==NULL ) {
;
+
+ }else if( strcmp(q,"exec")==0 ) {
+ char *file = strtok(NULL," ");
+ if( !file ) { SJC_Write("You must specify a name in game/console/*.txt"); return; }
+ exec_commands(file);
+
}else if( strcmp(q,"redetect")==0 ) {
inputinit();
+
}else if( strcmp(q,"realtime")==0 ) {
eng_realtime = eng_realtime ? 0 : 1;
SJC_Write("Realtime mode %s",eng_realtime?"on":"off");
+
}else if( strcmp(q,"watch")==0 ) {
i_watch = i_watch ? 0 : 1;
SJC_Write("Input watch %s",i_watch?"on":"off");
+
}else if( strcmp(q,"exit")==0 || strcmp(q,"quit")==0 ) {
cleanup();
+
}else if( strcmp(q,"listen")==0 ) {
char *port = strtok(NULL," ");
host_start(port?atoi(port):0);
+
}else if( strcmp(q,"connect")==0 ) {
char *hostname = strtok(NULL," :");
char *port = strtok(NULL," :");
char *clientport = strtok(NULL," ");
client_start(hostname,(port?atoi(port):0),(clientport?atoi(clientport):0));
+
}else if( strcmp(q,"disconnect")==0 ) {
if( hostsock ) {
host_stop();
@@ -62,12 +85,16 @@ void command(const char *s)
SJC_Write("Disconnected from host.");
}else
SJC_Write("Nothing to disconnect from.");
+
}else if( strcmp(q,"reconnect")==0 ) {
SJC_Write("Not implemented."); //TODO
+
}else if( strcmp(q,"hulls")==0 ) {
v_drawhulls = v_drawhulls ? 0 : 1;
+
}else if( strcmp(q,"stats")==0 ) {
v_showstats = v_showstats ? 0 : 1;
+
}else if( strcmp(q,"fullscreen")==0 || strncmp(q,"window",6)==0 ) {
char *sw = strtok(NULL," x");
char *sh = strtok(NULL," ");
@@ -80,29 +107,22 @@ void command(const char *s)
setvideosoon(NATIVEW*w,NATIVEH*w,full,1);
else
setvideosoon(0,0,full,1);
+
}else if( strcmp(q,"bind")==0 ) {
- int i;
- char *cmdname = strtok(NULL," ");
- if( cmdname==NULL ) {
- SJC_Write("Please specify command: left, right, up, down, fire, jump");
- break;
- }
- for(i=0; i<numinputnames; i++)
- if( strcmp(inputnames[i].name,cmdname)==0 ) {
- input_bindsoon( inputnames[i].presscmd, inputnames[i].releasecmd );
- SJC_Write("Press a key, button, or stick to use for [%s] ...",cmdname);
- break;
- }
- if( i==numinputnames )
- SJC_Write("Not a command: %s",cmdname);
+ char *arg0 = strtok(NULL," ");
+ char *arg1 = strtok(NULL," ");
+ bind( arg0, arg1 );
+
}else if( strcmp(q,"slow")==0 ) {
SJC_Write("Speed is now slow");
ticksaframe = 300;
jogframebuffer(metafr,surefr);
+
}else if( strcmp(q,"fast")==0 ) {
SJC_Write("Speed is now fast");
ticksaframe = 30;
jogframebuffer(metafr,surefr);
+
}else if( strcmp(q,"help")==0 ) {
SJC_Write("Press your ~ key to open and close this console. Commands you can type:");
SJC_Write(" \\#08Flisten \\#FFFstart a server");
@@ -112,27 +132,31 @@ void command(const char *s)
SJC_Write(" \\#08Fwindow 3x \\#FFFgo windowed at 3x up-scale");
SJC_Write(" \\#08Fbind \\#FFFchoose input keys");
SJC_Write("See commands.txt for more commands");
+
}else if( strcmp(q,"report")==0 ) {
int i;
for( i=0; i<maxobjs; i++ ) {
OBJ_t *o = fr[surefr%maxframes].objs+i;
if( o->type )
SJC_Write( "#%-3i %-20s C:%-3i F:%-5x", i, flexer[o->type].name, o->context, o->flags );
}
+
}else if( strcmp(q,"save")==0 ) {
char *name = strtok(NULL," ");
if( name==NULL ) {
SJC_Write("Please specify a file name to save");
break;
}
save_context( name, mycontext, hotfr );
+
}else if( strcmp(q,"load")==0 ) {
char *name = strtok(NULL," ");
if( name==NULL ) {
SJC_Write("Please specify a file name to load");
break;
}
load_context( name, mycontext, hotfr );
+
}else if( strcmp(q,"spr")==0 ) {
char *num = strtok(NULL," ");
if( num==NULL ) {
@@ -153,13 +177,93 @@ void command(const char *s)
sprites[n].more->gridwide,sprites[n].more->gridlast,
sprites[n].more->piping,sprites[n].more->stretch,
sprites[n].more->stretch_t,sprites[n].more->stretch_r,sprites[n].more->stretch_b,sprites[n].more->stretch_l);
+
}else if( mod_command(q) ) {
SJC_Write("Huh?");
+
}
} while(0);
free(p);
}
+static void parse_dev_sym( int *devnum, int *sym, char *dev_sym )
+{
+ *devnum = INP_KEYB;
+
+ for( *sym=0; *sym<KEYNAMECOUNT; (*sym)++ )
+ if( keynames[*sym] && 0==strcmp(keynames[*sym],dev_sym) )
+ return;
+
+ *sym = atoi(dev_sym);
+ if( *sym )
+ return;
+
+ for( *devnum=0; *devnum<=INP_MAX; (*devnum)++ ) {
+ char *p = inputdevicenames[*devnum];
+ int plen = strlen(p);
+ if( 0==strncmp(p,dev_sym,plen) ) {
+ *sym = atoi(dev_sym+plen);
+ return;
+ }
+ }
+
+ *devnum = 0;
+}
+
+static void bind( char *dev_sym, char *press_cmdname )
+{
+ char *cmdname;
+ int press;
+ int device = 0;
+ int sym;
+ int cmd;
+
+ if( dev_sym==NULL ) {
+ mod_showbinds();
+ return;
+ }
+ if( press_cmdname==NULL )
+ cmdname = dev_sym;
+ else {
+ parse_dev_sym(&device,&sym,dev_sym);
+ if( !device ) { SJC_Write("Unrecognized key, button, or stick!"); return; }
+
+ if( press_cmdname[0]=='+' ) { press = 1; cmdname = press_cmdname+1; }
+ else if( press_cmdname[0]=='-' ) { press = 0; cmdname = press_cmdname+1; }
+ else { press =-1; cmdname = press_cmdname; }
+ }
+
+ for( cmd=0; cmd<numinputnames; cmd++ )
+ if( 0==strcmp(inputnames[cmd].name,cmdname) )
+ break;
+
+ if( cmd==numinputnames ) { SJC_Write("Not a command: %s",cmdname); return; }
+
+ if( !device ) {
+ input_bindsoon( inputnames[cmd].presscmd, inputnames[cmd].releasecmd );
+ SJC_Write("Press a key, button, or stick to use for [%s] ...",cmdname);
+ return;
+ }
+
+ if( press!=0 ) mod_keybind( device, sym, 1, inputnames[cmd].presscmd );
+ if( press!=1 ) mod_keybind( device, sym, 0, inputnames[cmd].releasecmd );
+}
+
+void exec_commands( char *name )
+{
+ char path[PATH_MAX];
+ int printed = snprintf( path, PATH_MAX, "game/console/%s.txt", name );
+ if( printed<0 ) { SJC_Write("Error making path from %s",path); return; }
+
+ FILE *f = fopen(path, "r");
+ if( !f ) { SJC_Write("Couldn't open %s",path); return; }
+
+ char line[1000];
+ while( fgets(line,1000,f) )
+ command(line);
+
+ fclose(f);
+}
View
@@ -3,6 +3,7 @@
#define SPARTOR_COMMAND_H_
void command(const char *s);
+void exec_commands( char *file );
#endif
View
@@ -19,8 +19,8 @@
SJF_t SJF = {0,8,12,128,
- {14, 7, 7,14,14,14,14,14,14,14,14,14,14,14,14,14, //non-printable
- 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14, //non-printable
+ { 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, //non-printable
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, //non-printable
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, //<space> - </>
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, //<0> - <?>
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, //<@> - <O>
@@ -30,26 +30,26 @@ SJF_t SJF = {0,8,12,128,
{
" "
" "
-" OOOO OOOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO "
-" O O OOOOO O O O O O O O O O O O O O O O O O O O O O O O O O O "
-" O O OOO OOOOO O O O O O O O O O O O O O O O O O O O O O O O O O O "
-" O O OOO OOOOO O O O O O O O O O O O O O O O O O O O O O O O O O O "
-" O O OOO OOOOO O O O O O O O O O O O O O O O O O O O O O O O O O O "
-" O O OOOOO O O O O O O O O O O O O O O O O O O O O O O O O O O "
-" OOOO OOOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO "
+" OOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO "
+" O O OOOOO O O O OO O O O O O O O O O O O OOO O O O O O OOO O O O O O O O "
+" O O OOO OOOOO O OOO O O O O OOO O OOO O OOO O O O OO OO OOO O O O O O OOO O O O O O O O O "
+" O O OOO OOOOO O OOO O O O O O O OO O O O O O OO OO OOO O O OO O OOO O O O O O O O O "
+" O O OOO OOOOO O OOO O O O O OOO O OOO O O O O O O OO OO O O O O O O O OOO O O O O O O O O O "
+" O O OOOOO O O O OO O O O OOO O O O O O O O O O O O O O O O O O O O O O O "
+" OOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO "
" "
" "
" "
// -------------------------------------------------------------------------------------------------------------------------------
" "
" "
-" OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO "
-" O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O "
-" O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O "
-" O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O "
-" O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O "
-" O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O "
-" OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO "
+" OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO "
+" O O O O O O O O O O O O O O O O O O O O O O O O O O O O OO O OOO OO O OO OO OOOOO "
+" O O O O O O O O O O OOO OO OO O O O O O O O O O O O O O O O OOO O O OOO O OOO OOO O O O O OOOOO "
+" O O O O O O O O O OO OO O O O O O O O O OO OO O O OO OO O OOO OO OO OOO O OOOOO OOOOO "
+" O OOO O O O OO OOO O OO OO O O O O O O O O O O O OOO O O OOO O OOO OOO O OOO O OOOOO OOOOO "
+" O OOO OO OO O O O O O OO OO O O OO OO O O O O O O O O O O O OO OOO O OO O OOOOO O O "
+" OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO "
" "
" "
" "
Oops, something went wrong.

0 comments on commit 0928d9f

Please sign in to comment.