comparison scn2k/scn2k.h @ 52:15a18fbe6f21

* Known bugs added to the README * Code cleaning (0 -> NULL when needed, indentation, spaces, ...)
author thib
date Sat, 18 Apr 2009 18:35:39 +0000
parents f1fbe5b37a1e
children ddbcbd000206
comparison
equal deleted inserted replaced
51:cbb301016a4e 52:15a18fbe6f21
26 */ 26 */
27 27
28 #ifndef __SCN2k_H__ 28 #ifndef __SCN2k_H__
29 #define __SCN2k_H__ 29 #define __SCN2k_H__
30 30
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 /* 36 /*
37 namespace Widget { 37 namespace Widget {
38 class Text; 38 class Text;
39 class Button; 39 class Button;
41 class Label; 41 class Label;
42 class Dialog; 42 class Dialog;
43 class AnmTime; 43 class AnmTime;
44 } 44 }
45 */ 45 */
46 class WidText; 46 class WidText;
47 class WidButton; 47 class WidButton;
48 class WidTextButton; 48 class WidTextButton;
49 class WidLabel; 49 class WidLabel;
50 class WidDialog; 50 class WidDialog;
51 class WidAnmTime; 51 class WidAnmTime;
52
52 namespace Event { 53 namespace Event {
53 class Container; 54 class Container;
54 } 55 }
56
55 class PicBase; 57 class PicBase;
56 class PicContainer; 58 class PicContainer;
57 class AyuSysConfig; 59 class AyuSysConfig;
58 class Surface; 60 class Surface;
59 61
91 ** type 26-32, 51 : 1-bit access to 0-6, 25 93 ** type 26-32, 51 : 1-bit access to 0-6, 25
92 ** type 52-58, 77 : 2-bit access to 0-6, 25 94 ** type 52-58, 77 : 2-bit access to 0-6, 25
93 ** type 78-84, 103 : 4-bit access to 0-6, 25 95 ** type 78-84, 103 : 4-bit access to 0-6, 25
94 ** type 104-110, 129 : 8-bit access to 0-6, 25 96 ** type 104-110, 129 : 8-bit access to 0-6, 25
95 */ 97 */
96 typedef unsigned int uint; 98 private:
97 int sys; 99 typedef unsigned int uint;
98 int var[TYPE_VARMAX+1][2000]; 100 int sys;
99 std::string str[2000]; 101 int var[TYPE_VARMAX+1][2000];
100 std::string sys_str[2000]; 102 std::string str[2000];
101 std::string loc_str[3]; 103 std::string sys_str[2000];
102 public: 104 std::string loc_str[3];
103 Flags(void); 105 public:
104 int operator () () const; 106 Flags(void);
105 int operator () (VarInfo info) const; 107 int operator () () const;
106 void Str(int type, unsigned int number, char* buf, int sz) const; 108 int operator () (VarInfo info) const;
107 std::string Str(int type, unsigned int number) const; 109 void Str(int type, unsigned int number, char* buf, int sz) const;
108 std::set<int> cgm_data; 110 std::string Str(int type, unsigned int number) const;
109 111 std::set<int> cgm_data;
110 bool IsInt(int type) const; 112
111 int MaxIndex(int type) const; 113 bool IsInt(int type) const;
112 114 int MaxIndex(int type) const;
113 void Set(VarInfo info, int value); 115
114 int Get(int type, int number) const; 116 void Set(VarInfo info, int value);
115 void SetSys(int value); 117 int Get(int type, int number) const;
116 void SetStr(VarInfo info, std::string val); 118 void SetSys(int value);
117 119 void SetStr(VarInfo info, std::string val);
118 bool Exec(class Cmd& cmd); 120
119 121 bool Exec(class Cmd& cmd);
120 void Save(std::string& str); 122
121 void Load(const char* str); 123 void Save(std::string& str);
122 124 void Load(const char* str);
123 void SaveSys(std::string& str); 125
124 void LoadSys(const char* str); 126 void SaveSys(std::string& str);
127 void LoadSys(const char* str);
125 }; 128 };
126 129
127 /* commands */ 130 /* commands */
128 #define STRHEAP_SIZE 10000 131 #define STRHEAP_SIZE 10000
129 enum Cmdtype { 132 enum Cmdtype {
133 CMD_SAVEREQ, CMD_SAVE, 136 CMD_SAVEREQ, CMD_SAVE,
134 CMD_LOADREQ, CMD_LOAD, 137 CMD_LOADREQ, CMD_LOAD,
135 CMD_MENUREQ, 138 CMD_MENUREQ,
136 CMD_BACKLOGREQ, CMD_BACKLOGREQ_FWD, 139 CMD_BACKLOGREQ, CMD_BACKLOGREQ_FWD,
137 CMD_END}; 140 CMD_END};
141
138 struct CmdSimplified { // Cmd 保存用 142 struct CmdSimplified { // Cmd 保存用
139 int type, cmd1, cmd2, cmd3, cmd4, argc; 143 int type, cmd1, cmd2, cmd3, cmd4, argc;
140 char* args; 144 char* args;
141 void Save(std::string& save); 145 void Save(std::string& save);
142 void Load(const char* save, char*& args_buffer); 146 void Load(const char* save, char*& args_buffer);
143 void copy(const CmdSimplified& from, char*& args_buffer); 147 void copy(const CmdSimplified& from, char*& args_buffer);
144 }; 148 };
149
145 class Cmd { 150 class Cmd {
146 public: 151 public:
147 Cmdtype cmd_type; 152 Cmdtype cmd_type;
148 int cmd1, cmd2, cmd3, cmd4; 153 int cmd1, cmd2, cmd3, cmd4;
149 int argc; 154 int argc;
150 int pos, scn; 155 int pos, scn;
151 const char* rawdata; 156 const char* rawdata;
152 char cmdstr[1024]; 157 char cmdstr[1024];
153 std::vector<VarInfo> args; 158 std::vector<VarInfo> args;
154 159
155 private: 160 private:
156 const Flags& flags; 161 const Flags& flags;
157 bool errorflag; 162 bool errorflag;
158 int system_version; 163 int system_version;
159 164
160 int GetArgs(const char*& d); 165 int GetArgs(const char*& d);
161 int GetArgsSpecial(int normal_args,const char*& d); 166 int GetArgsSpecial(int normal_args,const char*& d);
162 void GetSelection(const char*& d); 167 void GetSelection(const char*& d);
163 int GetSwitch(const char*& d); 168 int GetSwitch(const char*& d);
164 int GetSimpleSwitch(const char*& d); 169 int GetSimpleSwitch(const char*& d);
165 int GetExpression(const char*& d, struct VarInfo* info = 0); 170 int GetExpression(const char*& d, struct VarInfo* info = 0);
166 int GetExpressionCond(const char*& d); 171 int GetExpressionCond(const char*& d);
167 int GetLeftToken(const char*& d, struct VarInfo& info); 172 int GetLeftToken(const char*& d, struct VarInfo& info);
168 int GetString(const char*& d); 173 int GetString(const char*& d);
169 int CopyString(const char* d); 174 int CopyString(const char* d);
170 int StrVar(int type, int number); 175 int StrVar(int type, int number);
171 static char strtype[256]; 176 static char strtype[256];
172 static int StrType(const char* d) { return strtype[*(unsigned const char*)d];} 177 static int StrType(const char* d) { return strtype[*(unsigned const char*)d];}
173 public: 178
174 const char* Str(const VarInfo& info) const { 179 public:
175 if (info.type != TYPE_STR && info.type != TYPE_VARSTR && info.type != TYPE_VARLOCSTR && info.type != TYPE_VARSYSSTR) return ""; 180 const char* Str(const VarInfo& info) const;
176 int pt = info.value; 181 int AddStr(char* s);
177 if (pt < 0 || pt >= STRHEAP_SIZE) return ""; 182 private:
178 return strheap + pt; 183 char strheap[STRHEAP_SIZE];
179 } 184 int strend;
180 int AddStr(char* s) { 185 void SetError(void) { errorflag = true;}
181 // 1-0a-0064 はこういうものが必要らしい 186 void ResetString(void) {
182 int start = strend; 187 strend = 0;
183 while (*s) strheap[strend++] = *s++; 188 }
184 strheap[strend++] = 0; 189 public:
185 return start; 190 void GetCmd(Flags& f, const char*& d);
186 } 191 void SetSysvar(int n, int v);
187 private: 192 void SetSysvar(int v) { SetSysvar(TYPE_SYS_SYS, v); }
188 char strheap[STRHEAP_SIZE]; 193 void SetFlagvar(VarInfo info, int v);
189 int strend; 194 void SetStrvar(VarInfo info, const std::string& s);
190 void SetError(void) { errorflag = true;} 195 bool IsError() { return errorflag;}
191 void ResetString(void) { 196 void clear(void);
192 strend = 0; 197 virtual const char * CmdDescr(int, int, int, int) { return "Not supported"; }
193 } 198 Cmd(const Flags& f, int _sys_ver);
194 public: 199 void read(const CmdSimplified& cmd);
195 void GetCmd(Flags& f, const char*& d); 200 void write(CmdSimplified& cmd, char*& args_buffer) const;
196 void SetSysvar(int n, int v); 201 };
197 void SetSysvar(int v) { SetSysvar(TYPE_SYS_SYS, v); } 202
198 void SetFlagvar(VarInfo info, int v); 203 enum SkipMode {
199 void SetStrvar(VarInfo info, const std::string& s); 204 SKIP_NO=0, SKIP_TEXT=1, SKIP_GRP_FAST=16, SKIP_GRP_NOEFFEC=32,
200 bool IsError() { return errorflag;} 205 SKIP_GRP_NODRAW=64, SKIPEND_TEXT=256, SKIPEND_KEY=512, SKIP_IN_MENU=1024
201 void clear(void); 206 };
202 virtual const char * CmdDescr(int, int, int, int) { return "Not supported"; } 207
203 Cmd(const Flags& f, int _sys_ver) : flags(f), system_version(_sys_ver) { cmd_type = CMD_NOP; argc = 0; errorflag = false; cmdstr[0] = 0; strend = 0; pos = -1;} 208 #include "font/text.h"
204 void read(const CmdSimplified& cmd);
205 void write(CmdSimplified& cmd, char*& args_buffer) const;
206 };
207
208 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,
209 SKIP_IN_MENU=1024};
210
211 #include"font/text.h"
212 209
213 struct BacklogItem { 210 struct BacklogItem {
214 enum {SaveSelect = -2}; 211 enum {SaveSelect = -2};
215 int scn, pos; 212 int scn, pos;
216 int koe; 213 int koe;
221 void AddTextPos(Cmd&); 218 void AddTextPos(Cmd&);
222 void DeleteTextPos(); 219 void DeleteTextPos();
223 void SetSavepos(int pos); 220 void SetSavepos(int pos);
224 BacklogItem& operator =(const BacklogItem&); 221 BacklogItem& operator =(const BacklogItem&);
225 }; 222 };
223
226 class Text { 224 class Text {
227 class TextImpl* pimpl; 225 private:
228 public: 226 class TextImpl* pimpl;
229 std::vector<BacklogItem> backlog; 227 public:
230 BacklogItem backlog_item; 228 std::vector<BacklogItem> backlog;
231 Text(Event::Container& _event, PicContainer& _parent, AyuSysConfig& config); 229 BacklogItem backlog_item;
232 ~Text(); 230 Text(Event::Container& _event, PicContainer& _parent, AyuSysConfig& config);
233 void InitWindow(void); 231 ~Text();
234 void Exec(Cmd& cmd); 232 void InitWindow(void);
235 bool Wait(unsigned int current_time, Cmd& cmd); 233 void Exec(Cmd& cmd);
236 void SetSkipMode(SkipMode mode); 234 bool Wait(unsigned int current_time, Cmd& cmd);
237 void hide(void); 235 void SetSkipMode(SkipMode mode);
238 void show(void); 236 void hide(void);
239 void show(int num); 237 void show(void);
240 void Save(std::string& str, bool rollback_save); 238 void show(int num);
241 void Load(const char* str); 239 void Save(std::string& str, bool rollback_save);
242 void DrawBacklog(BacklogItem& item, Cmd& cmd); 240 void Load(const char* str);
243 }; 241 void DrawBacklog(BacklogItem& item, Cmd& cmd);
244 242 };
245 #include"../window/rect.h" 243
244 #include "../window/rect.h"
246 245
247 class Grp { 246 class Grp {
248 class GrpImpl* pimpl; 247 private:
249 public: 248 class GrpImpl* pimpl;
250 Grp(Event::Container& _event, PicContainer& _parent, const Flags& f, std::set<int>& _cgm_data, class MuSys& mu, AyuSysConfig& config); 249 public:
251 ~Grp(); 250 Grp(Event::Container& _event, PicContainer& _parent, const Flags& f, std::set<int>& _cgm_data, class MuSys& mu, AyuSysConfig& config);
252 bool Wait(unsigned int current_time, Cmd& cmd); 251 ~Grp();
253 void Exec(Cmd& cmd); 252 bool Wait(unsigned int current_time, Cmd& cmd);
254 void SetSkipMode(SkipMode mode); 253 void Exec(Cmd& cmd);
255 void InitSel(AyuSysConfig& config); 254 void SetSkipMode(SkipMode mode);
256 void Save(std::string& str); 255 void InitSel(AyuSysConfig& config);
257 void Load(const char* str); 256 void Save(std::string& str);
258 void SaveSys(std::string& str); 257 void Load(const char* str);
259 void LoadSys(const char* str); 258 void SaveSys(std::string& str);
259 void LoadSys(const char* str);
260 }; 260 };
261 261
262 void dprintf(const char* fmt, ...); // debug 用 262 void dprintf(const char* fmt, ...); // debug 用
263 void eprintf(const char* fmt, ...); // コマンド実行(XXXexec)追跡用 263 void eprintf(const char* fmt, ...); // コマンド実行(XXXexec)追跡用
264 #endif 264 #endif