Overview
Comment: | Implement the rest of the phases of the turn; still not working perfectly though |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
f4f4383c4e8467310a6b082a796241e7 |
User & Date: | user on 2020-12-17 22:10:04 |
Other Links: | manifest | tags |
Context
2020-12-18
| ||
02:00 | Correct the implementation of sink() so that the objects above and below the ones being switched are linked correctly; also, objtrash() does not need to reset the up/down links check-in: 3aa2e5e3bd user: user tags: trunk | |
2020-12-17
| ||
22:10 | Implement the rest of the phases of the turn; still not working perfectly though check-in: f4f4383c4e user: user tags: trunk | |
06:33 | Some more implementation of diagonal move check-in: 0090f92a2f user: user tags: trunk | |
Changes
Modified class.doc from [6e4182cde7] to [55564e04dc].
︙ | ︙ | |||
842 843 844 845 846 847 848 | object; objects which no longer exist still compare correctly. Values of two different types are never equal to each other. FlushClass ( class -- ) ** Resets the Arrived, Busy, Departed, Inertia, Moved, and UserSignal flags of all objects of the specified class to zero. If the class is -1, then all objects are flushed in this way, and during the input phase, it also | | | 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 | object; objects which no longer exist still compare correctly. Values of two different types are never equal to each other. FlushClass ( class -- ) ** Resets the Arrived, Busy, Departed, Inertia, Moved, and UserSignal flags of all objects of the specified class to zero. If the class is -1, then all objects are flushed in this way, and during the input phase, it also skips the beginning and ending phases if the class is -1. FlushObj ( -- ) ** Resets this object's Arrived, Departed, Inertia, Moved, and UserSignal. ,FlushObj ( obj -- ) ** Resets the Arrived, Busy, Departed, Inertia, Moved, and UserSignal flags of the specified object only. |
︙ | ︙ | |||
946 947 948 949 950 951 952 | lor ( in1 in2 -- out ) Logical OR. LoseLevel ( -- ) Ends all execution and results in loss of game. lsh ( in shift -- out ) | | > | 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 | lor ( in1 in2 -- out ) Logical OR. LoseLevel ( -- ) Ends all execution and results in loss of game. lsh ( in shift -- out ) Left shift. If the shift amount is out of range 0-31, all bits are shifted out, and the result is zero. lt ( in1 in2 -- bool ) Test if first input is less than second input (unsigned). ,lt ( in1 in2 -- bool ) Test if first input is less than second input (signed). |
︙ | ︙ | |||
1093 1094 1095 1096 1097 1098 1099 | at the end of a code block.) rot ( x y z -- y z x ) -rot ( x y z -- z x y ) rsh ( in shift -- out ) | | > | > > | 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 | at the end of a code block.) rot ( x y z -- y z x ) -rot ( x y z -- z x y ) rsh ( in shift -- out ) Logical right shift. If the shift amount is out of the range 0-31, then all bits are shifted out and the result is zero. ,rsh ( in shift -- out ) Arithmetic right shift. If the shift amount is out of the range 0-31, then all bits are shifted out; the result will be -1 if the input is negative, or 0 otherwise. Self ( -- obj ) The reference to the current object. Send ( message arg1 arg2 -- value ) Similar to ,Send but this object sends the message to itself. |
︙ | ︙ | |||
1480 1481 1482 1483 1484 1485 1486 1487 | that Inertia is not reset. * Some bits are masked out of the return value from HIT and HITBY. * Many variables are limited to 16-bits. * Moving objects is not allowed during LASTIMAGE processing. | > > | 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 | that Inertia is not reset. * Some bits are masked out of the return value from HIT and HITBY. * Many variables are limited to 16-bits. * Moving objects is not allowed during LASTIMAGE processing. * The way that the trigger phase works is different. |
Modified exec.c from [b606dc980d] to [bcf1e42af2].
︙ | ︙ | |||
611 612 613 614 615 616 617 | Uint32 m; int i,xx,yy; Object*o; Object*p; Value v; if(n==VOIDLINK || (objects[n]->oflags&OF_DESTROYED)) return 0; o=objects[n]; | | | 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 | Uint32 m; int i,xx,yy; Object*o; Object*p; Value v; if(n==VOIDLINK || (objects[n]->oflags&OF_DESTROYED)) return 0; o=objects[n]; if(lastimage_processing) Throw("Can't move during animation processing"); if(x<1 || y<1 || x>pfwidth || y>pfheight) return 0; if(v_bool(send_message(from,n,MSG_MOVING,NVALUE(x),NVALUE(y),NVALUE(0)))) return 0; if(classes[o->class]->cflags&CF_PLAYER) { m=lastobj; while(m!=VOIDLINK) { if(v_bool(send_message(n,m,MSG_PLAYERMOVING,NVALUE(x),NVALUE(y),OVALUE(from)))) return 0; m=objects[m]->prev; |
︙ | ︙ | |||
829 830 831 832 833 834 835 | o=objects[obj]; printf(" : %u %u [$%s %d %d]",o->generation,obj,classes[o->class]->name,o->x,o->y); printf(" : %u %u : %u %u\n",t1.t,t1.u,t2.t,t2.u); } static void flush_object(Uint32 n) { Object*o=objects[n]; | | | | 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 | o=objects[obj]; printf(" : %u %u [$%s %d %d]",o->generation,obj,classes[o->class]->name,o->x,o->y); printf(" : %u %u : %u %u\n",t1.t,t1.u,t2.t,t2.u); } static void flush_object(Uint32 n) { Object*o=objects[n]; o->arrived=o->departed=0; o->oflags&=~(OF_MOVED|OF_BUSY|OF_USERSIGNAL); o->inertia=0; } static void flush_class(Uint16 c) { Uint32 n,p; Object*o; if(lastobj==VOIDLINK) return; n=lastobj; while(o=objects[n]) { p=o->prev; if(!c || o->class==c) { o->arrived=o->departed=0; o->oflags&=~(OF_MOVED|OF_BUSY|OF_USERSIGNAL); o->inertia=0; } if(p==VOIDLINK) break; n=p; } } |
︙ | ︙ | |||
1062 1063 1064 1065 1066 1067 1068 | Uint32 i,j; Object*o=objects[obj]; Value t1,t2; static Value t3,t4,t5; if(StackProtection()) Throw("Call stack overflow"); // Note about bit shifting: At least when running Hero Mesh in DOSBOX, out of range bit shifts produce zero. // I don't know if this is true on all computers that Hero Mesh runs on, though. (Some documents suggest that x86 doesn't work this way) | | | 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 | Uint32 i,j; Object*o=objects[obj]; Value t1,t2; static Value t3,t4,t5; if(StackProtection()) Throw("Call stack overflow"); // Note about bit shifting: At least when running Hero Mesh in DOSBOX, out of range bit shifts produce zero. // I don't know if this is true on all computers that Hero Mesh runs on, though. (Some documents suggest that x86 doesn't work this way) // The below code assumes that signed right shifting is available on the computer that Free Hero Mesh runs on. for(;;) switch(code[ptr++]) { case 0x0000 ... 0x00FF: StackReq(0,1); Push(NVALUE(code[ptr-1])); break; case 0x0100 ... 0x01FF: StackReq(0,1); Push(NVALUE(code[ptr-1]-0x200)); break; case 0x0200 ... 0x02FF: StackReq(0,1); Push(MVALUE(code[ptr-1]&255)); break; case 0x0300 ... 0x03FF: StackReq(0,1); Push(UVALUE(code[ptr-1]&255,TY_SOUND)); break; case 0x0400 ... 0x04FF: StackReq(0,1); Push(UVALUE(code[ptr-1]&255,TY_USOUND)); break; case 0x1000 ... 0x107F: StackReq(1,1); t1=Pop(); Numeric(t1); t1.u+=code[ptr-1]&0x7F; Push(t1); break; // + |
︙ | ︙ | |||
1490 1491 1492 1493 1494 1495 1496 1497 1498 | free(objects[i]); } nobjects=0; free(objects); objects=0; gameover=0; } const char*execute_turn(int key) { | > > > > > > > > > > > > > > > > > > > > > | > | | | | | > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > | > > > > > > > > > > > | > > > > > | 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 | free(objects[i]); } nobjects=0; free(objects); objects=0; gameover=0; } static Uint8 execute_animation(Uint8 clock,Uint32 obj) { Object*o=objects[obj]; Animation*a=o->anim; if(!(a->step[a->lstep].flag&ANI_ONCE)) return clock; if(a->ltime>=a->step[a->lstep].speed) { a->ltime=0; if(o->image==a->step[a->lstep].end) { a->status&=~ANISTAT_LOGICAL; if(classes[o->class]->cflags&CF_COMPATIBLE) lastimage_processing=1; send_message(VOIDLINK,obj,MSG_LASTIMAGE,NVALUE(0),NVALUE(0),NVALUE(0)); lastimage_processing=0; } else { if(a->step[a->lstep].start>a->step[a->lstep].end) --o->image; else ++o->image; } } if(!(a->status&ANISTAT_LOGICAL) || !(a->step[a->lstep].flag&ANI_ONCE)) return clock; if(clock>a->step[a->lstep].speed-a->ltime) return a->step[a->lstep].speed-a->ltime; return clock; } const char*execute_turn(int key) { Uint8 busy,clock; Uint32 m,n,turn; Object*o; Value v; int i; if(!key) return 0; if(setjmp(my_env)) return my_error; if(quiz_text) { sqlite3_free(quiz_text); quiz_text=0; if(key_ignored) { if(quiz_obj.t) quiz_obj=NVALUE(0); else return 0; } else if(!quiz_obj.t) { move_number++; return 0; } } changed=0; key_ignored=0; all_flushed=0; lastimage_processing=0; vstackptr=0; current_key=key; for(n=0;n<nobjects;n++) if(o=objects[n]) { o->distance=0; o->oflags&=~(OF_KEYCLEARED|OF_DONE); if(o->anim) o->anim->count=0; } // Input phase m=VOIDLINK; v=NVALUE(0); if(!quiz_obj.t) { n=lastobj; while(n!=VOIDLINK) { i=classes[objects[n]->class]->cflags; if(i&CF_INPUT) v=send_message(VOIDLINK,n,MSG_KEY,NVALUE(key),v,NVALUE(0)); if(i&CF_PLAYER) m=n; n=objects[n]->prev; } } else { n=quiz_obj.u; if(objects[n]->generation!=quiz_obj.t) n=VOIDLINK; quiz_obj=NVALUE(0); if(classes[objects[n]->class]->cflags&CF_COMPATIBLE) all_flushed=1; v=send_message(VOIDLINK,n,MSG_KEY,NVALUE(key),NVALUE(0),NVALUE(1)); } current_key=0; if(key_ignored) { quiz_obj=NVALUE(0); return changed?"Invalid use of IgnoreKey":0; } move_number++; // Beginning phase if(!all_flushed) broadcast(m,0,MSG_BEGIN_TURN,m==VOIDLINK?NVALUE(objects[m]->x):NVALUE(0),m==VOIDLINK?NVALUE(objects[m]->y):NVALUE(0),v,0); turn=0; // Trigger phase trig: busy=0; clock=255; for(i=0;i<64*pfheight;i++) { n=playfield[i]; while(n!=VOIDLINK) { o=objects[n]; m=o->up; if(o->oflags&OF_DESTROYED) { objtrash(n); } else if(classes[o->class]->cflags&CF_COMPATIBLE) { if(o->oflags&OF_MOVED) { o->oflags&=~OF_MOVED; send_message(VOIDLINK,n,MSG_MOVED,NVALUE(0),NVALUE(0),NVALUE(turn)); busy=1; } if(o->departed) { send_message(VOIDLINK,n,MSG_DEPARTED,NVALUE(0),NVALUE(0),NVALUE(turn)); o->departed=0; busy=1; } if(o->arrived) { send_message(VOIDLINK,n,MSG_ARRIVED,NVALUE(0),NVALUE(0),NVALUE(turn)); o->arrived=0; busy=1; } if(o->anim && (o->anim->status&ANISTAT_LOGICAL)) clock=execute_animation(clock,n); if(o->oflags&(OF_BUSY|OF_USERSIGNAL)) busy=1; } else { o->departed2=o->departed; o->departed=0; o->arrived2=o->arrived; o->arrived=0; if(o->oflags&OF_MOVED) o->oflags=(o->oflags|OF_MOVED2)&~OF_MOVED; } n=m; } } n=lastobj; while(n!=VOIDLINK) { o=objects[n]; if(!(classes[o->class]->cflags&CF_COMPATIBLE)) { if(o->oflags&OF_MOVED2) send_message(VOIDLINK,n,MSG_MOVED,NVALUE(0),NVALUE(0),NVALUE(turn)),busy=1; if(o->departed2) send_message(VOIDLINK,n,MSG_DEPARTED,NVALUE(o->departed2),NVALUE(0),NVALUE(turn)),busy=1; if(o->arrived2) send_message(VOIDLINK,n,MSG_ARRIVED,NVALUE(o->arrived2),NVALUE(0),NVALUE(turn)),busy=1; o->oflags&=~OF_MOVED2; o->arrived2=o->departed2=0; if(o->anim && (o->anim->status&ANISTAT_LOGICAL)) clock=execute_animation(clock,n); if(o->oflags&(OF_BUSY|OF_USERSIGNAL)) busy=1; } n=o->prev; } // Ending phase if(!busy && !all_flushed) { n=lastobj; while(n!=VOIDLINK) { v=send_message(VOIDLINK,n,MSG_END_TURN,NVALUE(turn),NVALUE(0),NVALUE(0)); if(v_bool(v) || objects[n]->arrived || objects[n]->departed) busy=1; if(objects[n]->oflags&(OF_BUSY|OF_USERSIGNAL|OF_MOVED)) busy=1; n=objects[n]->prev; } turn++; if(!busy) all_flushed=1; } // Clock phase if(!clock) clock=1; n=lastobj; while(n!=VOIDLINK) { o=objects[n]; if(o->oflags&(OF_BUSY|OF_USERSIGNAL|OF_MOVED)) busy=1; if(o->arrived || o->departed) busy=1; if(o->anim && (o->anim->status&ANISTAT_LOGICAL)) { if(o->anim->step[o->anim->lstep].flag&ANI_ONCE) { i=o->anim->ltime+clock; o->anim->ltime=i>255?255:i; busy=1; } } n=o->prev; } if(busy) goto trig; // Cleanup phase for(n=0;n<nobjects;n++) if(objects[n] && (objects[n]->oflags&OF_DESTROYED)) objtrash(n); if(generation_number<=TY_MAXTYPE) return "Too many generations of objects"; // Finished return 0; } const char*init_level(void) { if(setjmp(my_env)) return my_error; if(main_options['t']) printf("[Level %d restarted]\n",level_id); memcpy(globals,initglobals,sizeof(globals)); |
︙ | ︙ |
Modified heromesh.h from [cae8174e03] to [34bcd17910].
︙ | ︙ | |||
117 118 119 120 121 122 123 124 125 126 127 128 129 130 | #define OF_USERSTATE 0x0010 #define OF_USERSIGNAL 0x0020 #define OF_MOVED 0x0040 #define OF_DONE 0x0080 #define OF_KEYCLEARED 0x0100 #define OF_DESTROYED 0x0200 #define OF_BIZARRO 0x0400 typedef struct { const char*name; const char*edithelp; // not present if CF_GROUP const char*gamehelp; // not present if CF_GROUP Uint16*codes; // if this is CF_GROUP, then instead a zero-terminated list of classes Uint16*messages; // use 0xFFFF if no such message block; not present if CF_GROUP | > | 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | #define OF_USERSTATE 0x0010 #define OF_USERSIGNAL 0x0020 #define OF_MOVED 0x0040 #define OF_DONE 0x0080 #define OF_KEYCLEARED 0x0100 #define OF_DESTROYED 0x0200 #define OF_BIZARRO 0x0400 #define OF_MOVED2 0x0800 typedef struct { const char*name; const char*edithelp; // not present if CF_GROUP const char*gamehelp; // not present if CF_GROUP Uint16*codes; // if this is CF_GROUP, then instead a zero-terminated list of classes Uint16*messages; // use 0xFFFF if no such message block; not present if CF_GROUP |
︙ | ︙ |