Mercurial > otakunoraifu
comparison scn2k/scn2k.h @ 56:c7bcc0ec2267
* replaced Grp and Text classes by the TextImpl and GrpImpl ones
* splitted scn2k.h into smaller header files
* moved some definitions from scn2k_*.cc to the header files
* moved opcode implementation to scn2k_*impl.cc
author | thib |
---|---|
date | Thu, 30 Apr 2009 19:05:09 +0000 |
parents | f1a27ee7e03c |
children | 4416cfac86ae |
comparison
equal
deleted
inserted
replaced
55:f1a27ee7e03c | 56:c7bcc0ec2267 |
---|---|
31 #include <vector> | 31 #include <vector> |
32 #include <string> | 32 #include <string> |
33 #include <map> | 33 #include <map> |
34 #include <set> | 34 #include <set> |
35 | 35 |
36 #include "scn2k_cmd.h" | |
37 #include "scn2k_grp.h" | |
38 #include "scn2k_text.h" | |
39 | |
36 /* | 40 /* |
37 namespace Widget { | 41 namespace Widget { |
38 class Text; | 42 class Text; |
39 class Button; | 43 class Button; |
40 class TextButton; | 44 class TextButton; |
57 class PicBase; | 61 class PicBase; |
58 class PicContainer; | 62 class PicContainer; |
59 class AyuSysConfig; | 63 class AyuSysConfig; |
60 class Surface; | 64 class Surface; |
61 | 65 |
62 void dprintf(const char* fmt, ...); | |
63 void eprintf(const char* fmt, ...); | |
64 | |
65 struct VarInfo { | |
66 #define TYPE_NONSYSVARMAX 5 | |
67 #define TYPE_VARMAX 9 | |
68 #define TYPE_VARLOCSTR 10 | |
69 #define TYPE_VARSYSSTR 12 | |
70 #define TYPE_VARSTR 18 | |
71 #define TYPE_STR 58 | |
72 #define TYPE_VAL 68 | |
73 #define TYPE_SYS 0xc8 | |
74 #define TYPE_END 0x7f | |
75 | |
76 #define TYPE_SYS_SYS 0 | |
77 #define TYPE_SYS_SKIPMODE 1 | |
78 int type; | |
79 int number; | |
80 int value; | |
81 VarInfo() { type = TYPE_VAL; value = 0;} | |
82 VarInfo(int n) { type = TYPE_VAL; value = n;} | |
83 VarInfo(const VarInfo& i) { type = i.type; number = i.number; value = i.value;} | |
84 }; | |
85 | |
86 | |
87 class Flags { | |
88 /* flag: | |
89 ** type 0-5 : ローカル整数、各2000個 | |
90 ** type 6, 25 : グローバル整数、2000個 | |
91 ** type 10,11: ローカル整数??、各2000個 | |
92 ** type 12 : グローバル文字列、2000個 (今は無視しても良いが) | |
93 ** type 18 : ローカル文字列、2000個 | |
94 ** type 25: システム変数(マウス座標など?) 1000 個? | |
95 ** type 26-32, 51 : 1-bit access to 0-6, 25 | |
96 ** type 52-58, 77 : 2-bit access to 0-6, 25 | |
97 ** type 78-84, 103 : 4-bit access to 0-6, 25 | |
98 ** type 104-110, 129 : 8-bit access to 0-6, 25 | |
99 */ | |
100 private: | |
101 typedef unsigned int uint; | |
102 int sys; | |
103 int var[TYPE_VARMAX+1][2000]; | |
104 std::string str[2000]; | |
105 std::string sys_str[2000]; | |
106 std::string loc_str[3]; | |
107 public: | |
108 Flags(void); | |
109 int operator () () const; | |
110 int operator () (VarInfo info) const; | |
111 void Str(int type, unsigned int number, char* buf, int sz) const; | |
112 std::string Str(int type, unsigned int number) const; | |
113 std::set<int> cgm_data; | |
114 | |
115 bool IsInt(int type) const; | |
116 int MaxIndex(int type) const; | |
117 | |
118 void Set(VarInfo info, int value); | |
119 int Get(int type, int number) const; | |
120 void SetSys(int value); | |
121 void SetStr(VarInfo info, std::string val); | |
122 | |
123 bool Exec(class Cmd& cmd); | |
124 | |
125 void Save(std::string& str); | |
126 void Load(const char* str); | |
127 | |
128 void SaveSys(std::string& str); | |
129 void LoadSys(const char* str); | |
130 }; | |
131 | |
132 /* commands */ | |
133 #define STRHEAP_SIZE 10000 | |
134 enum Cmdtype { | |
135 CMD_NOP, CMD_FLAGS, CMD_JMP, CMD_TEXT, CMD_OTHER, CMD_SYSVAR, | |
136 CMD_TEXTEND, | |
137 CMD_SAVECMDGRP, CMD_SAVECMDGRP_START, CMD_SAVECMDGRP_ONCE, CMD_SAVECMD_ONCE, CMD_WAITFRAMEUPDATE,CMD_SAVEPOINT, CMD_ROLLBACKPOINT, | |
138 CMD_SAVEREQ, CMD_SAVE, | |
139 CMD_LOADREQ, CMD_LOAD, | |
140 CMD_MENUREQ, | |
141 CMD_BACKLOGREQ, CMD_BACKLOGREQ_FWD, | |
142 CMD_END}; | |
143 | |
144 struct CmdSimplified { // Cmd 保存用 | |
145 int type, cmd1, cmd2, cmd3, cmd4, argc; | |
146 char* args; | |
147 void Save(std::string& save); | |
148 void Load(const char* save, char*& args_buffer); | |
149 void copy(const CmdSimplified& from, char*& args_buffer); | |
150 }; | |
151 | |
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{ | |
165 public: | |
166 Cmdtype cmd_type; | |
167 int cmd4; | |
168 int argc; | |
169 int pos, scn; | |
170 const char* rawdata; | |
171 char cmdstr[1024]; | |
172 std::vector<VarInfo> args; | |
173 | |
174 private: | |
175 const Flags& flags; | |
176 bool errorflag; | |
177 int system_version; | |
178 | |
179 int GetArgs(const char*& d); | |
180 int GetArgsSpecial(int normal_args,const char*& d); | |
181 void GetSelection(const char*& d); | |
182 int GetSwitch(const char*& d); | |
183 int GetSimpleSwitch(const char*& d); | |
184 int GetExpression(const char*& d, struct VarInfo* info = 0); | |
185 int GetExpressionCond(const char*& d); | |
186 int GetLeftToken(const char*& d, struct VarInfo& info); | |
187 int GetString(const char*& d); | |
188 int CopyString(const char* d); | |
189 int StrVar(int type, int number); | |
190 static char strtype[256]; | |
191 static int StrType(const char* d) { return strtype[*(unsigned const char*)d];} | |
192 | |
193 public: | |
194 const char* Str(const VarInfo& info) const; | |
195 int AddStr(char* s); | |
196 | |
197 private: | |
198 char strheap[STRHEAP_SIZE]; | |
199 int strend; | |
200 void SetError(void) { errorflag = true;} | |
201 void ResetString(void) { | |
202 strend = 0; | |
203 } | |
204 | |
205 public: | |
206 void GetCmd(Flags& f, const char*& d); | |
207 void SetSysvar(int n, int v); | |
208 void SetSysvar(int v) { SetSysvar(TYPE_SYS_SYS, v); } | |
209 void SetFlagvar(VarInfo info, int v); | |
210 void SetStrvar(VarInfo info, const std::string& s); | |
211 bool IsError() { return errorflag;} | |
212 void clear(void); | |
213 virtual const char * CmdDescr(int, int, int, int) { return "Not supported"; } | |
214 Cmd(const Flags& f, int _sys_ver); | |
215 void read(const CmdSimplified& cmd); | |
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 void PrintCmd(Cmd& cmd); | |
229 | |
230 private: | |
231 typedef std::map<SimpleCmd, CommandInfo> CommandMap; | |
232 CommandMap command_map; | |
233 }; | |
234 | |
235 enum SkipMode { | |
236 SKIP_NO=0, SKIP_TEXT=1, SKIP_GRP_FAST=16, SKIP_GRP_NOEFFEC=32, | |
237 SKIP_GRP_NODRAW=64, SKIPEND_TEXT=256, SKIPEND_KEY=512, SKIP_IN_MENU=1024 | |
238 }; | |
239 | |
240 #include "font/text.h" | |
241 | |
242 struct BacklogItem { | |
243 enum {SaveSelect = -2}; | |
244 int scn, pos; | |
245 int koe; | |
246 std::string face; | |
247 struct TextStream text; | |
248 BacklogItem(void); | |
249 void Clear(void); | |
250 void AddTextPos(Cmd&); | |
251 void DeleteTextPos(); | |
252 void SetSavepos(int pos); | |
253 BacklogItem& operator =(const BacklogItem&); | |
254 }; | |
255 | |
256 class Text { | |
257 private: | |
258 class TextImpl* pimpl; | |
259 public: | |
260 std::vector<BacklogItem> backlog; | |
261 BacklogItem backlog_item; | |
262 Text(Event::Container& _event, PicContainer& _parent); | |
263 ~Text(); | |
264 void InitWindow(void); | |
265 void Exec(Cmd& cmd); | |
266 bool Wait(unsigned int current_time, Cmd& cmd); | |
267 void SetSkipMode(SkipMode mode); | |
268 void hide(void); | |
269 void show(void); | |
270 void show(int num); | |
271 void Save(std::string& str, bool rollback_save); | |
272 void Load(const char* str); | |
273 void DrawBacklog(BacklogItem& item, Cmd& cmd); | |
274 }; | |
275 | |
276 #include "../window/rect.h" | |
277 | |
278 class Grp { | |
279 private: | |
280 class GrpImpl* pimpl; | |
281 public: | |
282 Grp(Event::Container& _event, PicContainer& _parent, const Flags& f, std::set<int>& _cgm_data); | |
283 ~Grp(); | |
284 bool Wait(unsigned int current_time, Cmd& cmd); | |
285 void Exec(Cmd& cmd); | |
286 void SetSkipMode(SkipMode mode); | |
287 void InitSel(void); | |
288 void Save(std::string& str); | |
289 void Load(const char* str); | |
290 void SaveSys(std::string& str); | |
291 void LoadSys(const char* str); | |
292 }; | |
293 | |
294 void dprintf(const char* fmt, ...); // debug 用 | 66 void dprintf(const char* fmt, ...); // debug 用 |
295 void eprintf(const char* fmt, ...); // コマンド実行(XXXexec)追跡用 | 67 void eprintf(const char* fmt, ...); // コマンド実行(XXXexec)追跡用 |
296 #endif | 68 #endif |