Mercurial > otakunoraifu
comparison scn2k/scn2k_textimpl.cc @ 58:0aaa5bb3dde5
Moved all opcodes from scn2k_text.cc to scn2k_textimpl.cc
author | Thibaut GIRKA <thib@sitedethib.com> |
---|---|
date | Fri, 18 Dec 2009 14:25:56 +0100 |
parents | 6d9146f56ccf |
children | 36d92d21300f |
comparison
equal
deleted
inserted
replaced
57:6d9146f56ccf | 58:0aaa5bb3dde5 |
---|---|
60 | 60 |
61 cmd.clear(); | 61 cmd.clear(); |
62 cmd.cmd_type = CMD_WAITFRAMEUPDATE; // 画像描画に戻る(skip時にテキストが描画されやすくするため) | 62 cmd.cmd_type = CMD_WAITFRAMEUPDATE; // 画像描画に戻る(skip時にテキストが描画されやすくするため) |
63 } | 63 } |
64 | 64 |
65 void Text::impl_PauseCursor(Cmd& cmd) | |
66 { | |
67 /* なんかよくわからないけどカーソル形状変更にしとく */ | |
68 SetCursor(cmd.args[0].value); | |
69 cmd.clear(); | |
70 } | |
71 | |
65 void Text::impl_br(Cmd& cmd) { | 72 void Text::impl_br(Cmd& cmd) { |
66 text_stream.AddReturn(); | 73 text_stream.AddReturn(); |
67 cur_backlog_item.DeleteTextPos(); | 74 cur_backlog_item.DeleteTextPos(); |
68 cmd.clear(); | 75 cmd.clear(); |
69 } | 76 } |
190 text->StartText(text_stream); | 197 text->StartText(text_stream); |
191 text->wid->Flush(); | 198 text->wid->Flush(); |
192 } | 199 } |
193 | 200 |
194 if (cmd.cmd3 == 111 || cmd.cmd3 == 112 || cmd.cmd3 == 121) | 201 if (cmd.cmd3 == 111 || cmd.cmd3 == 112 || cmd.cmd3 == 121) |
195 wait_time = base_time + cmd.args[0].value; //FIXME: second argument, counter. See ReadFrame for this | 202 { |
203 int index; | |
204 if (cmd.cmd4 == 1) | |
205 index = 0; | |
206 else | |
207 index = cmd.args[1].value; | |
208 wait_time = timer_var[index].start_time + cmd.args[0].value; | |
209 } | |
196 else | 210 else |
197 wait_time = old_time + cmd.args[0].value; | 211 wait_time = old_time + cmd.args[0].value; |
198 | 212 |
199 if (cmd.cmd3 == 101 || cmd.cmd3 == 112) | 213 if (cmd.cmd3 == 101 || cmd.cmd3 == 112) |
200 status = WAIT_CLICK; | 214 status = WAIT_CLICK; |
211 wait_savedvar[0] = cmd.args[0]; | 225 wait_savedvar[0] = cmd.args[0]; |
212 wait_savedvar[1] = cmd.args[1]; | 226 wait_savedvar[1] = cmd.args[1]; |
213 cmd.clear(); | 227 cmd.clear(); |
214 } | 228 } |
215 | 229 |
230 void Text::impl_ResetTimer(Cmd& cmd) { | |
231 int index; | |
232 | |
233 if (cmd.cmd4 == 1) | |
234 index = 0; | |
235 else | |
236 index = cmd.args[0].value; | |
237 | |
238 eprintf("set basetime (%d)\n",index); | |
239 //TODO: Handle EX timer set | |
240 TimerAtom& atom = timer_var[index]; | |
241 atom.start_time = old_time; | |
242 | |
243 cmd.clear(); | |
244 } | |
245 | |
246 void Text::impl_Timer(Cmd& cmd) { | |
247 int index; | |
248 | |
249 if (cmd.cmd4 == 1) | |
250 index = 0; | |
251 else | |
252 index = cmd.args[0].value; | |
253 | |
254 eprintf("get time %dth\n",index); | |
255 if (timer_var.find(index) == timer_var.end()) | |
256 cmd.SetSysvar(0); | |
257 else | |
258 cmd.SetSysvar(old_time - timer_var[index].start_time); | |
259 } | |
260 | |
216 void Text::impl_ReadFrame(Cmd& cmd) { | 261 void Text::impl_ReadFrame(Cmd& cmd) { |
217 eprintf("get timer value[%d]\n",cmd.args[0].value); | 262 eprintf("get timer value[%d]\n", cmd.args[0].value); |
218 if (timer_var.find(cmd.args[0].value) == timer_var.end()) | 263 if (frame_var.find(cmd.args[0].value) == frame_var.end()) |
219 cmd.SetSysvar(0); | 264 cmd.SetSysvar(0); |
220 else { | 265 else { |
221 TimerAtom& atom = timer_var[cmd.args[0].value]; | 266 FrameTimerAtom& atom = frame_var[cmd.args[0].value]; |
222 if (atom.total_time <= 0) atom.total_time = 1; | 267 if (atom.total_time <= 0) atom.total_time = 1; |
223 int cur_tm = old_time - atom.start_time; | 268 int cur_tm = old_time - atom.start_time; |
224 if (cur_tm < 0) cur_tm = atom.total_time; // エラーなら最終時間に合わせる | 269 if (cur_tm < 0) cur_tm = atom.total_time; // エラーなら最終時間に合わせる |
225 if (cur_tm > atom.total_time) cur_tm = atom.total_time; | 270 if (cur_tm > atom.total_time) cur_tm = atom.total_time; |
226 // use 'long long'(64bit) or 'double'(80bit) type, since total_time, to and from is 32 bit. | 271 // use 'long long'(64bit) or 'double'(80bit) type, since total_time, to and from is 32 bit. |
227 int v = atom.from + (long long)(atom.to-atom.from)*cur_tm/int(atom.total_time); | 272 int v = atom.from + (long long)(atom.to - atom.from)*cur_tm/int(atom.total_time); |
228 cmd.SetSysvar(v); | 273 cmd.SetSysvar(v); |
229 } | 274 } |
230 } | 275 } |
231 | 276 |
277 void Text::impl_InitFrame(Cmd& cmd) { | |
278 FrameTimerAtom& atom = frame_var[cmd.args[0].value]; | |
279 atom.from = cmd.args[1].value; | |
280 atom.to = cmd.args[2].value; | |
281 atom.total_time = cmd.args[3].value; | |
282 atom.start_time = old_time; | |
283 cmd.clear(); | |
284 } | |
285 | |
286 void Text::impl_InitFrames(Cmd& cmd) { | |
287 int i, j = 0; | |
288 for (i = 0; i < cmd.argc; i++) | |
289 { | |
290 int cnt = cmd.args[j++].value; // £³€Ê€Î€Ç̵»ë | |
291 int num = cmd.args[j++].value; | |
292 FrameTimerAtom& atom = frame_var[num]; | |
293 atom.from = cmd.args[j++].value; | |
294 atom.to = cmd.args[j++].value; | |
295 atom.total_time = cmd.args[j++].value; | |
296 atom.start_time = old_time; | |
297 } | |
298 cmd.clear(); | |
299 } | |
300 | |
301 void Text::impl_ReadFrames(Cmd& cmd) { | |
302 vector<VarInfo> args = cmd.args; | |
303 vector<VarInfo>::iterator it = args.begin(); | |
304 int argc = cmd.argc; | |
305 int timers_active = 0; | |
306 int i; | |
307 for (i=0; i < argc; i++) | |
308 { | |
309 int cnt = (it++)->value; | |
310 int num = (it++)->value; | |
311 | |
312 if (frame_var.find(num) == frame_var.end()) { | |
313 cmd.SetFlagvar(*it++, 0); | |
314 } | |
315 else | |
316 { | |
317 FrameTimerAtom& atom = frame_var[num]; | |
318 if (atom.total_time <= 0) | |
319 atom.total_time = 1; | |
320 int cur_tm = old_time - atom.start_time; | |
321 if (cur_tm < 0) | |
322 cur_tm = atom.total_time; // ¥š¥é¡Œ€Ê€éºÇœª»þŽÖ€Ë¹ç€ï€»€ë | |
323 if (cur_tm > atom.total_time) | |
324 cur_tm = atom.total_time; | |
325 // use 'long long'(64bit) or 'double'(80bit) type, since total_time, to and from is 32 bit. | |
326 int v = atom.from + (long long)(atom.to-atom.from)*cur_tm/int(atom.total_time); | |
327 cmd.SetFlagvar(*it++, v); | |
328 if (atom.total_time != -1 && cur_tm < atom.total_time) | |
329 timers_active = 1; | |
330 } | |
331 } | |
332 cmd.SetSysvar(timers_active); | |
333 } | |
334 | |
335 void Text::impl_rnd(Cmd& cmd) | |
336 { | |
337 /* rand() */ | |
338 int min, max; | |
339 if (cmd.args.size() == 2) | |
340 { | |
341 min = cmd.args[0].value; | |
342 max = cmd.args[1].value; | |
343 } | |
344 else | |
345 { | |
346 min = 0; | |
347 max = cmd.args[0].value; | |
348 } | |
349 if (min > max) | |
350 { | |
351 int tmp = max; | |
352 max = min; | |
353 min = tmp; | |
354 } | |
355 int r = random(); | |
356 if (min == max) | |
357 r = min; | |
358 else | |
359 r = (r % (max-min)) + min; | |
360 cmd.SetSysvar(r); | |
361 } | |
362 | |
363 void Text::impl_pcnt(Cmd& cmd) | |
364 { | |
365 cmd.SetSysvar(100 * cmd.args[0].value / cmd.args[1].value); | |
366 } | |
367 | |
368 void Text::impl_abs(Cmd& cmd) | |
369 { | |
370 cmd.SetSysvar(abs(cmd.args[0].value)); | |
371 } | |
372 | |
373 void Text::impl_power(Cmd& cmd) | |
374 { | |
375 //TODO | |
376 //cmd.SetSysvar(pow(cmd.args[0].value, cmd.args[1].value)); | |
377 } | |
378 | |
379 void Text::impl_min(Cmd& cmd) | |
380 { | |
381 int a = cmd.args[0].value; | |
382 int b = cmd.args[1].value; | |
383 cmd.SetSysvar((a < b) ? a : b); | |
384 } | |
385 | |
386 void Text::impl_max(Cmd& cmd) | |
387 { | |
388 int a = cmd.args[0].value; | |
389 int b = cmd.args[1].value; | |
390 cmd.SetSysvar((a > b) ? a : b); | |
391 } | |
392 | |
393 void Text::impl_index_series(Cmd& cmd) | |
394 { | |
395 //TODO: This one is not fully documented in | |
396 // http://dev.haeleth.net/rldev/manual.html | |
397 // Try to figure out what's it... | |
398 | |
399 /* range conversion : 比率に丸める */ | |
400 // アルゴリズムは間違えてるような気がする | |
401 // | |
402 if (cmd.args.size() >= 7) | |
403 { | |
404 int val = cmd.args[0].value; | |
405 int offset = cmd.args[1].value; | |
406 int r_min = cmd.args[2].value; | |
407 int v_min = cmd.args[3].value; | |
408 int v_max = cmd.args[4].value; | |
409 int r_max = cmd.args[5].value; | |
410 int mode = cmd.args[6].value; | |
411 // rldev : mode == 1,3 : 'acceralating curve', 2,3: 'decelerating curve' | |
412 // 複数の引数リスト(r_minからmodeまでのリスト)もつこともあり、その場合は | |
413 // "cancel out in some way" らしい | |
414 if (mode == 1 || mode == 3) | |
415 val += offset; | |
416 else if (mode == 2 || mode == 4) | |
417 val -= offset; | |
418 if (cmd.args.size() != 7) | |
419 fprintf(stderr,"\n%d/%d: cmd 01-04:0320 : XXXX NOT SUPPORTED LIST : DOUBLE RANGE CONVERSION! XXXXXXXXXXX\n",cmd.scn,cmd.pos); | |
420 if (val < v_min) | |
421 val = v_min; | |
422 if (val > v_max) | |
423 val = v_max; | |
424 val = (r_max-r_min)*(val-v_min)/(v_max-v_min) + r_min; | |
425 cmd.SetSysvar(val); | |
426 } | |
427 } | |
428 | |
429 void Text::impl_constrain(Cmd& cmd) | |
430 { | |
431 /* range 内に丸める */ | |
432 int min = cmd.args[0].value; | |
433 int val = cmd.args[1].value; | |
434 int max = cmd.args[2].value; | |
435 if (min > max) { | |
436 max = cmd.args[0].value; | |
437 min = cmd.args[2].value; | |
438 } | |
439 if (val < min) | |
440 val = min; | |
441 if (val > max) | |
442 val = max; | |
443 cmd.SetSysvar(val); | |
444 } | |
445 | |
446 | |
447 void Text::impl_load(Cmd& cmd) | |
448 { | |
449 // メニューからのロード | |
450 cmd.cmd_type = CMD_LOADREQ; | |
451 } | |
452 | |
453 void Text::impl_GetWindowAttr(Cmd& cmd) | |
454 { | |
455 // テキストウィンドウの色設定 | |
456 int r, g, b, a, flag; | |
457 | |
458 if (cmd.cmd3 == 2617) // 元設定を取り出す | |
459 config->GetOriginalParam("#WINDOW_ATTR", 5, &r, &g, &b, &a, &flag); | |
460 else | |
461 config->GetParam("#WINDOW_ATTR", 5, &r, &g, &b, &a, &flag); | |
462 | |
463 if (cmd.args.size() != 5) { | |
464 fprintf(stderr,"cmd 01-04:%4d : invalid arg size\n", cmd.cmd3); | |
465 } else { | |
466 vector<VarInfo> args(cmd.args); | |
467 cmd.SetFlagvar(args[0], r); | |
468 cmd.SetFlagvar(args[1], g); | |
469 cmd.SetFlagvar(args[2], b); | |
470 cmd.SetFlagvar(args[3], a); | |
471 cmd.SetFlagvar(args[4], flag); | |
472 } | |
473 } | |
474 | |
475 void Text::impl_SetWindowAttr(Cmd& cmd) | |
476 { | |
477 int r, g, b, a, flag; | |
478 config->GetParam("#WINDOW_ATTR", 5, &r, &g, &b, &a, &flag); | |
479 | |
480 switch(cmd.cmd3) { | |
481 case 2260: | |
482 r = cmd.args[0].value; | |
483 break; | |
484 case 2261: | |
485 g = cmd.args[0].value; | |
486 break; | |
487 case 2262: | |
488 b = cmd.args[0].value; | |
489 break; | |
490 case 2263: | |
491 a = cmd.args[0].value; | |
492 break; | |
493 case 2264: | |
494 flag = cmd.args[0].value; | |
495 break; | |
496 case 2267: | |
497 r = cmd.args[0].value; | |
498 g = cmd.args[1].value; | |
499 b = cmd.args[2].value; | |
500 a = cmd.args[3].value; | |
501 flag = cmd.args[4].value; | |
502 break; | |
503 } | |
504 config->SetParam("#WINDOW_ATTR", 5, r, g, b, a, flag); | |
505 SetWindowColor(r, g, b, a, flag); | |
506 cmd.clear(); | |
507 } | |
508 | |
509 void Text::impl_GetDefConfig(Cmd& cmd) | |
510 { | |
511 int v = 0; | |
512 switch(cmd.cmd3) { | |
513 case 2600: | |
514 case 2605: | |
515 config->GetOriginalParam("#INIT_MESSAGE_SPEED", 1, &v); | |
516 break; | |
517 case 2601: | |
518 config->GetOriginalParam("#INIT_MESSAGE_SPEED_MOD", 1, &v); | |
519 break; | |
520 case 2604: | |
521 config->GetOriginalParam("#MESSAGE_KEY_WAIT_USE", 1, &v); | |
522 break; | |
523 case 2606: | |
524 config->GetOriginalParam("#MESSAGE_KEY_WAIT_TIME", 1, &v); | |
525 break; | |
526 } | |
527 cmd.SetSysvar(v); | |
528 } | |
529 | |
530 void Text::impl_GetConfig(Cmd& cmd) | |
531 { | |
532 int v; | |
533 switch (cmd.cmd3) | |
534 { | |
535 case 2323: | |
536 case 2351: | |
537 config->GetParam("#INIT_MESSAGE_SPEED", 1, &v); | |
538 break; | |
539 case 2324: | |
540 config->GetParam("#INIT_MESSAGE_SPEED_MOD", 1, &v); | |
541 break; | |
542 case 2350: | |
543 config->GetParam("#MESSAGE_KEY_WAIT_USE", 1, &v); | |
544 break; | |
545 case 2352: | |
546 config->GetParam("#MESSAGE_KEY_WAIT_TIME", 1, &v); | |
547 break; | |
548 } | |
549 | |
550 cmd.SetSysvar(v); | |
551 } | |
552 | |
553 void Text::impl_SetConfig(Cmd& cmd) | |
554 { | |
555 int speed, use_speed_mod, wait, use_wait_mod; | |
556 config->GetParam("#INIT_MESSAGE_SPEED", 1, &speed); | |
557 config->GetParam("#INIT_MESSAGE_SPEED_MOD", 1, &use_speed_mod); | |
558 config->GetParam("#MESSAGE_KEY_WAIT_USE", 1, &use_wait_mod); | |
559 config->GetParam("#MESSAGE_KEY_WAIT_TIME", 1, &wait); | |
560 switch (cmd.cmd3) | |
561 { | |
562 case 2223: | |
563 case 2251: | |
564 speed = cmd.args[0].value; | |
565 if (speed < 10) //FIXME: ??? 0 ??? | |
566 speed = 10; | |
567 if (speed > 10000) //FIXME: ??? 255 ??? | |
568 speed = 10000; | |
569 config->SetParam("#INIT_MESSAGE_SPEED", 1, speed); | |
570 break; | |
571 case 2224: | |
572 use_speed_mod = cmd.args[0].value; | |
573 config->SetParam("#INIT_MESSAGE_SPEED_MOD", 1, use_speed_mod); | |
574 break; | |
575 case 2250: | |
576 use_wait_mod = cmd.args[0].value; | |
577 config->SetParam("#MESSAGE_KEY_WAIT_USE", 1, use_wait_mod); | |
578 break; | |
579 case 2252: | |
580 int wait = cmd.args[0].value; | |
581 if (wait < 0) | |
582 wait = 0; | |
583 else if (wait > 60000) | |
584 wait = 60000; | |
585 config->SetParam("#MESSAGE_KEY_WAIT_TIME", 1, wait); | |
586 break; | |
587 } | |
588 | |
589 if (use_speed_mod) // FIXME: Not the other way around? | |
590 SetTextSpeed(-1); | |
591 else | |
592 SetTextSpeed(speed); | |
593 | |
594 if (use_wait_mod) | |
595 SetTextWait(wait); | |
596 else | |
597 SetTextWait(-1); | |
598 | |
599 cmd.clear(); | |
600 } | |
601 | |
602 void Text::impl_GetName(Cmd& cmd) | |
603 { | |
604 // replace_name を得る | |
605 int n = cmd.args[0].value; | |
606 if (n >= 0 && n < 26) // FIXME: Should go up to 702, but otakunoraifu is not ready for that yet | |
607 cmd.SetStrvar(cmd.args[1], replace_name[n]); | |
608 else | |
609 cmd.SetStrvar(cmd.args[1], ""); | |
610 } | |
611 | |
612 void Text::impl_SetName(Cmd& cmd) | |
613 { | |
614 // replace_name を得る | |
615 int n = cmd.args[0].value; | |
616 if (n >= 0 && n < 26) // FIXME: Should go up to 702, but otakunoraifu is not ready for that yet | |
617 replace_name[n] = cmd.Str(cmd.args[1]); | |
618 } | |
619 | |
620 void Text::impl_GetLocalName(Cmd& cmd) | |
621 { | |
622 // replace_name2 を得る | |
623 int n = cmd.args[0].value; | |
624 if (n >= 0 && n < 26) // FIXME: Should go up to 702, but otakunoraifu is not ready for that yet | |
625 cmd.SetStrvar(cmd.args[1], replace_name2[n]); | |
626 else | |
627 cmd.SetStrvar(cmd.args[1], ""); | |
628 } | |
629 | |
630 void Text::impl_SetLocalName(Cmd& cmd) | |
631 { | |
632 // replace_name2 の設定 | |
633 int n = cmd.args[0].value; | |
634 if (n >= 0 && n < 26) // FIXME: Should go up to 702, but otakunoraifu is not ready for that yet | |
635 replace_name2[n] = cmd.Str(cmd.args[1]); | |
636 | |
637 cmd.clear(); | |
638 } | |
639 |