MCPcopy Create free account
hub / github.com/SimHacker/micropolis / n_ball

Method n_ball

MicropolisCore/src/CellEngine/src/cellengine.cpp:2064–2181  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2062
2063
2064void CellEngine::n_ball()
2065{
2066 // This spatio temporal phase synchronization is busted.
2067 // It stays in synch for vertical and horizontal movement,
2068 // but gets out of phase for diagonal movement,
2069 // and I can't figure out how to keep it in phase
2070 // regardless of position.
2071 char p = ((phase ^ x ^ y) & 1);
2072 long xx, yy, r = Rand16();
2073 Byte *front = frontMem;
2074 Byte *back = backMem +
2075 (backBorder - 1) +
2076 ((backBorder - 1) * backRowBytes);
2077
2078 if (!p) {
2079 back += 1 + backRowBytes;
2080 }
2081
2082 for (yy = p + (height >>1);
2083 yy > 0;
2084 yy--) {
2085 for (xx = p + (width >>1);
2086 xx > 0;
2087 xx--) {
2088 Byte nw = back[0], nw0 = nw >> 6,
2089 ne = back[1], ne0 = ne >> 6,
2090 sw = back[backRowBytes], sw0 = sw >> 6,
2091 se = back[backRowBytes+1], se0 = se >> 6;
2092
2093// r += nw + ne + sw + sw; r >>= 1;
2094 r += (nw0&1) + (ne0&1) + (sw0&1) + (se0&1); r >>= 1;
2095
2096 if ((nw0 | ne0 | sw0 | se0) & 2) {
2097 if (nw0 == 1) {
2098 back[0] |= 128;
2099 }
2100 if (ne0 == 1) {
2101 back[1] |= 128;
2102 }
2103 if (sw0 == 1) {
2104 back[backRowBytes] |= 128;
2105 }
2106 if (se0 == 1) {
2107 back[backRowBytes+1] |= 128;
2108 }
2109 } else {
2110
2111 switch ((nw0&1) + (ne0&1) + (sw0&1) + (se0&1)) {
2112
2113 case 0:
2114 case 3:
2115 case 4:
2116 // same
2117 back[0] = nw; back[1] = ne;
2118 back[backRowBytes] = sw;
2119 back[backRowBytes+1] = se;
2120 break;
2121

Callers

nothing calls this directly

Calls 1

Rand16Function · 0.70

Tested by

no test coverage detected