Mercurial > touhou
comparison pytouhou/game/eclrunner.py @ 43:7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Thu, 18 Aug 2011 22:24:32 +0200 |
parents | 1b0ca2fb89f9 |
children | 1f1793e7ec8e |
comparison
equal
deleted
inserted
replaced
42:1b0ca2fb89f9 | 43:7195aaf95f6e |
---|---|
1 class ECLRunner(object): | 1 class ECLRunner(object): |
2 def __init__(self, ecl, sub, frame=0, instruction_pointer=0, implementation=None): | 2 def __init__(self, ecl, sub, frame=0, instruction_pointer=0, implementation=None): |
3 self.ecl = ecl | 3 self.ecl = ecl |
4 | 4 |
5 self.labels = {} | 5 self.counters = {} |
6 self.implementation = {4: (self.set_label), | 6 self.implementation = {4: (self.set_counter), |
7 3: (self.goto)} | 7 2: (self.relative_jump), |
8 3: (self.relative_jump_ex)} | |
8 if implementation: | 9 if implementation: |
9 self.implementation.update(implementation) | 10 self.implementation.update(implementation) |
10 | 11 |
11 self.sub = sub | 12 self.sub = sub |
12 self.frame = frame | 13 self.frame = frame |
13 self.instruction_pointer = instruction_pointer | 14 self.instruction_pointer = instruction_pointer |
14 | 15 |
15 | 16 |
16 def set_label(self, label, count): | 17 def set_counter(self, counter_id, count): |
17 self.labels[label & 0xffff] = (self.sub, self.instruction_pointer, count) | 18 self.counters[counter_id & 0xffff] = count |
18 | 19 |
19 | 20 |
20 def goto(self, frame, instruction_pointer, label): | 21 def relative_jump(self, frame, instruction_pointer): |
21 try: | 22 self.frame, self.instruction_pointer = frame, instruction_pointer |
22 sub, instruction_pointer, count = self.labels[label & 0xffff] | 23 |
23 except KeyError: | 24 |
24 pass | 25 def relative_jump_ex(self, frame, instruction_pointer, counter_id): |
25 else: | 26 if self.counters[counter_id & 0xffff]: |
26 count -= 1 | 27 self.counters[counter_id & 0xffff] -= 1 |
27 if count: | 28 self.frame, self.instruction_pointer = frame, instruction_pointer |
28 self.labels[label & 0xffff] = sub, instruction_pointer, count | |
29 else: | |
30 del self.labels[label & 0xffff] | |
31 self.frame = frame | |
32 self.sub, self.instruction_pointer = sub, instruction_pointer | |
33 | 29 |
34 | 30 |
35 def update(self): | 31 def update(self): |
36 frame = self.frame | 32 frame = self.frame |
37 try: | 33 try: |