Mercurial > otakunoraifu
view scn2k/scn2k_cmd.h @ 57:6d9146f56ccf
* Move some opcodes
* Merge last changes from xclannad
author | Thibaut GIRKA <thib@sitedethib.com> |
---|---|
date | Sat, 14 Nov 2009 23:31:51 +0100 |
parents | c7bcc0ec2267 |
children | 4416cfac86ae |
line wrap: on
line source
#ifndef __SCN2K_CMD_H__ #define __SCN2K_CMD_H__ #include <vector> #include <string> #include <map> #include "scn2k_flags.h" #define STRHEAP_SIZE 10000 enum Cmdtype { CMD_NOP, CMD_FLAGS, CMD_JMP, CMD_TEXT, CMD_OTHER, CMD_SYSVAR, CMD_TEXTEND, CMD_SAVECMDGRP, CMD_SAVECMDGRP_START, CMD_SAVECMDGRP_ONCE, CMD_SAVECMD_ONCE, CMD_WAITFRAMEUPDATE,CMD_SAVEPOINT, CMD_ROLLBACKPOINT, CMD_SAVEREQ, CMD_SAVE, CMD_LOADREQ, CMD_LOAD, CMD_MENUREQ, CMD_BACKLOGREQ, CMD_BACKLOGREQ_FWD, CMD_END}; enum SkipMode { SKIP_NO=0, SKIP_TEXT=1, SKIP_GRP_FAST=16, SKIP_GRP_NOEFFEC=32, SKIP_GRP_NODRAW=64, SKIPEND_TEXT=256, SKIPEND_KEY=512, SKIP_IN_MENU=1024 }; struct CmdSimplified { // Cmd ÊÝžÍÑ int type, cmd1, cmd2, cmd3, cmd4, argc; char* args; void Save(std::string& save); void Load(const char* save, char*& args_buffer); void copy(const CmdSimplified& from, char*& args_buffer); }; class SimpleCmd { public: SimpleCmd(int a, int b, int c); SimpleCmd(); bool operator==(const SimpleCmd& cmd) const; bool operator<(const SimpleCmd& cmd) const; public: int cmd1, cmd2, cmd3; }; class Cmd : public SimpleCmd{ public: Cmdtype cmd_type; int cmd4; int argc; int pos, scn; const char* rawdata; char cmdstr[1024]; std::vector<VarInfo> args; private: const Flags& flags; bool errorflag; int system_version; int GetArgs(const char*& d); int GetArgsSpecial(int normal_args,const char*& d); void GetSelection(const char*& d); int GetSwitch(const char*& d); int GetSimpleSwitch(const char*& d); int GetExpression(const char*& d, struct VarInfo* info = 0); int GetExpressionCond(const char*& d); int GetLeftToken(const char*& d, struct VarInfo& info); int GetString(const char*& d); int CopyString(const char* d); int StrVar(int type, int number); static char strtype[256]; static int StrType(const char* d) { return strtype[*(unsigned const char*)d];} public: const char* Str(const VarInfo& info) const; int AddStr(char* s); private: char strheap[STRHEAP_SIZE]; int strend; void SetError(void) { errorflag = true;} void ResetString(void) { strend = 0; } public: void GetCmd(Flags& f, const char*& d); void SetSysvar(int n, int v); void SetSysvar(int v) { SetSysvar(TYPE_SYS_SYS, v); } void SetFlagvar(VarInfo info, int v); void SetStrvar(VarInfo info, const std::string& s); bool IsError() { return errorflag;} void clear(void); virtual const char * CmdDescr(int, int, int, int) { return "Not supported"; } Cmd(const Flags& f, int _sys_ver); void read(const CmdSimplified& cmd); void write(CmdSimplified& cmd, char*& args_buffer) const; }; class CommandHandler { public: typedef void (CommandHandler::*CmdImpl)(Cmd& cmd); typedef struct { const char* descr; CmdImpl function; } CommandInfo; void RegisterCommand(int cmd1, int cmd2, int cmd3, const char* descr, CmdImpl func); bool Exec(Cmd& cmd); void PrintCmd(Cmd& cmd); private: typedef std::map<SimpleCmd, CommandInfo> CommandMap; CommandMap command_map; }; #endif