Jacksonmj: Move console functions into seperate file

This commit is contained in:
jacksonmj 2011-04-23 13:41:08 +01:00 committed by Simon Robertshaw
parent aef09292ee
commit 7b82eae82e
6 changed files with 1461 additions and 1441 deletions

27
includes/console.h Normal file
View File

@ -0,0 +1,27 @@
#ifndef CONSOLE_H
#define CONSOLE_H
#include <defines.h>
#ifdef PYCONSOLE
#include "Python.h"
//#include "pystdlib.h"
#include <marshal.h>
#endif
extern char pyready, pygood, console_more;
extern char console_error[];
extern int file_script;
#ifdef PYCONSOLE
extern PyMethodDef EmbMethods[];
#endif
int console_parse_coords(char *txt, int *x, int *y, char *err);
int console_parse_type(char *txt, int *element, char *err);
int console_parse_partref(char *txt, int *which, char *err);
#ifdef PYCONSOLE
int process_command(pixel *vid_buf, char *console, char *console_error, PyObject *pfunc);
#endif
int process_command_old(pixel *vid_buf, char *console, char *console_error);
#endif

View File

@ -16,8 +16,6 @@
#define THUMB_CACHE_SIZE 256
//#define pyconsole
#ifndef M_PI
#define M_PI 3.14159265f
#endif
@ -173,8 +171,6 @@ int player2spawn;
int death2;
int ISSPAWN1;
int ISSPAWN2;
extern char pyready;
extern char pygood;
extern sign signs[MAXSIGNS];
extern stamp stamps[STAMP_MAX];
extern int stamp_count;
@ -183,8 +179,10 @@ extern char itc_msg[64];
extern int do_open;
extern int sys_pause;
extern int sys_shortcuts;
extern int legacy_enable; //Used to disable new features such as heat, will be set by commandline or save.
extern int death, death2, framerender;
extern pixel *vid_buf;
extern unsigned char last_major, last_minor, update_flag;
@ -200,5 +198,5 @@ int parse_save(void *save, int size, int replace, int x0, int y0, unsigned char
void clear_sim(void);
void del_stamp(int d);
void sdl_seticon(void);
//int process_command(pixel *vid_buf, char *console, char *console_error, PyObject *pfunc);
void play_sound(char *file);
#endif

View File

@ -240,9 +240,6 @@ void open_link(char *uri);
int report_ui(pixel *vid_buf, char *save_id);
char *console_ui(pixel *vid_buf, char error[255],char console_more);
int console_parse_coords(char *txt, int *x, int *y, char *err);
int console_parse_type(char *txt, int *element, char *err);
int console_parse_partref(char *txt, int *which, char *err);
void decorations_ui(pixel *vid_buf,pixel *decorations,int *bsx,int *bsy);
#endif

1425
src/console.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -14,9 +14,8 @@
#include <powder.h>
#include <interface.h>
#include <misc.h>
#include <console.h>
//char pyready=1;
SDLMod sdl_mod;
int sdl_key, sdl_wheel, sdl_caps=0, sdl_ascii, sdl_zoom_trig=0;
@ -4204,78 +4203,6 @@ char *console_ui(pixel *vid_buf,char error[255],char console_more) {
return NULL;
}
//takes a a string and compares it to element names, and puts it value into element.
int console_parse_type(char *txt, int *element, char *err)
{
int i = -1;
// alternative names for some elements
if (strcasecmp(txt,"C4")==0) i = PT_PLEX;
else if (strcasecmp(txt,"C5")==0) i = PT_C5;
else if (strcasecmp(txt,"NONE")==0) i = PT_NONE;
if (i>=0)
{
*element = i;
strcpy(err,"");
return 1;
}
for (i=1; i<PT_NUM; i++) {
if (strcasecmp(txt,ptypes[i].name)==0)
{
*element = i;
strcpy(err,"");
return 1;
}
}
strcpy(err, "Particle type not recognised");
return 0;
}
//takes a string of coords "x,y" and puts the values into x and y.
int console_parse_coords(char *txt, int *x, int *y, char *err)
{
// TODO: use regex?
int nx = -1, ny = -1;
if (sscanf(txt,"%d,%d",&nx,&ny)!=2 || nx<0 || nx>=XRES || ny<0 || ny>=YRES)
{
strcpy(err,"Invalid coordinates");
return 0;
}
*x = nx;
*y = ny;
return 1;
}
//takes a string of either coords or a particle number, and puts the particle number into *which
int console_parse_partref(char *txt, int *which, char *err)
{
int i = -1, nx, ny;
strcpy(err,"");
// TODO: use regex?
if (strchr(txt,',') && console_parse_coords(txt, &nx, &ny, err))
{
i = pmap[ny][nx];
if (!i || (i>>8)>=NPART)
i = -1;
else
i = i>>8;
}
else if (txt)
{
char *num = (char*)malloc(strlen(txt)+3);
i = atoi(txt);
sprintf(num,"%d",i);
if (!txt || strcmp(txt,num)!=0)
i = -1;
free(num);
}
if (i>=0 && i<NPART && parts[i].type)
{
*which = i;
strcpy(err,"");
return 1;
}
if (strcmp(err,"")==0) strcpy(err,"Particle does not exist");
return 0;
}
void decorations_ui(pixel *vid_buf,pixel *decorations,int *bsx,int *bsy)
{
int i,ss,hh,vv,cr=127,cg=0,cb=0,b = 0,mx,my,bq = 0,j, lb=0,lx=0,ly=0,lm=0;

1364
src/main.c

File diff suppressed because it is too large Load Diff