comparison scn2k/scn2k.h @ 54:d7cde171a1de

* scn2k_grp.cc now handles commands in a cleanier way \o/ * some cleaning
author thib
date Mon, 20 Apr 2009 16:18:55 +0000
parents ddbcbd000206
children f1a27ee7e03c
comparison
equal deleted inserted replaced
53:ddbcbd000206 54:d7cde171a1de
80 int value; 80 int value;
81 VarInfo() { type = TYPE_VAL; value = 0;} 81 VarInfo() { type = TYPE_VAL; value = 0;}
82 VarInfo(int n) { type = TYPE_VAL; value = n;} 82 VarInfo(int n) { type = TYPE_VAL; value = n;}
83 VarInfo(const VarInfo& i) { type = i.type; number = i.number; value = i.value;} 83 VarInfo(const VarInfo& i) { type = i.type; number = i.number; value = i.value;}
84 }; 84 };
85
86
85 class Flags { 87 class Flags {
86 /* flag: 88 /* flag:
87 ** type 0-5 : ローカル整数、各2000個 89 ** type 0-5 : ローカル整数、各2000個
88 ** type 6, 25 : グローバル整数、2000個 90 ** type 6, 25 : グローバル整数、2000個
89 ** type 10,11: ローカル整数??、各2000個 91 ** type 10,11: ローカル整数??、各2000個
145 void Save(std::string& save); 147 void Save(std::string& save);
146 void Load(const char* save, char*& args_buffer); 148 void Load(const char* save, char*& args_buffer);
147 void copy(const CmdSimplified& from, char*& args_buffer); 149 void copy(const CmdSimplified& from, char*& args_buffer);
148 }; 150 };
149 151
150 class Cmd { 152 class SimpleCmd {
153 public:
154 SimpleCmd(int a, int b, int c);
155 SimpleCmd();
156
157 bool operator==(const SimpleCmd& cmd) const;
158 bool operator<(const SimpleCmd& cmd) const;
159
160 public:
161 int cmd1, cmd2, cmd3;
162 };
163
164 class Cmd : public SimpleCmd{
151 public: 165 public:
152 Cmdtype cmd_type; 166 Cmdtype cmd_type;
153 int cmd1, cmd2, cmd3, cmd4; 167 int cmd4;
154 int argc; 168 int argc;
155 int pos, scn; 169 int pos, scn;
156 const char* rawdata; 170 const char* rawdata;
157 char cmdstr[1024]; 171 char cmdstr[1024];
158 std::vector<VarInfo> args; 172 std::vector<VarInfo> args;
177 static int StrType(const char* d) { return strtype[*(unsigned const char*)d];} 191 static int StrType(const char* d) { return strtype[*(unsigned const char*)d];}
178 192
179 public: 193 public:
180 const char* Str(const VarInfo& info) const; 194 const char* Str(const VarInfo& info) const;
181 int AddStr(char* s); 195 int AddStr(char* s);
196
182 private: 197 private:
183 char strheap[STRHEAP_SIZE]; 198 char strheap[STRHEAP_SIZE];
184 int strend; 199 int strend;
185 void SetError(void) { errorflag = true;} 200 void SetError(void) { errorflag = true;}
186 void ResetString(void) { 201 void ResetString(void) {
187 strend = 0; 202 strend = 0;
188 } 203 }
204
189 public: 205 public:
190 void GetCmd(Flags& f, const char*& d); 206 void GetCmd(Flags& f, const char*& d);
191 void SetSysvar(int n, int v); 207 void SetSysvar(int n, int v);
192 void SetSysvar(int v) { SetSysvar(TYPE_SYS_SYS, v); } 208 void SetSysvar(int v) { SetSysvar(TYPE_SYS_SYS, v); }
193 void SetFlagvar(VarInfo info, int v); 209 void SetFlagvar(VarInfo info, int v);
196 void clear(void); 212 void clear(void);
197 virtual const char * CmdDescr(int, int, int, int) { return "Not supported"; } 213 virtual const char * CmdDescr(int, int, int, int) { return "Not supported"; }
198 Cmd(const Flags& f, int _sys_ver); 214 Cmd(const Flags& f, int _sys_ver);
199 void read(const CmdSimplified& cmd); 215 void read(const CmdSimplified& cmd);
200 void write(CmdSimplified& cmd, char*& args_buffer) const; 216 void write(CmdSimplified& cmd, char*& args_buffer) const;
217 };
218
219 class CommandHandler {
220 public:
221 typedef void (CommandHandler::*CmdImpl)(Cmd& cmd);
222 typedef struct {
223 const char* descr;
224 CmdImpl function;
225 } CommandInfo;
226 void RegisterCommand(int cmd1, int cmd2, int cmd3, const char* descr, CmdImpl func);
227 bool Exec(Cmd& cmd);
228
229 private:
230 typedef std::map<SimpleCmd, CommandInfo> CommandMap;
231 CommandMap command_map;
201 }; 232 };
202 233
203 enum SkipMode { 234 enum SkipMode {
204 SKIP_NO=0, SKIP_TEXT=1, SKIP_GRP_FAST=16, SKIP_GRP_NOEFFEC=32, 235 SKIP_NO=0, SKIP_TEXT=1, SKIP_GRP_FAST=16, SKIP_GRP_NOEFFEC=32,
205 SKIP_GRP_NODRAW=64, SKIPEND_TEXT=256, SKIPEND_KEY=512, SKIP_IN_MENU=1024 236 SKIP_GRP_NODRAW=64, SKIPEND_TEXT=256, SKIPEND_KEY=512, SKIP_IN_MENU=1024