annotate pytouhou/formats/anm0.pyx @ 551:0d7a16e0f834

Don’t display spellcard backgrounds either with the SDL backend.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 27 May 2014 17:41:52 +0200
parents 43ecf0f98f4d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
52
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
1 # -*- encoding: utf-8 -*-
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
2 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
3 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com>
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
4 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
5 ## This program is free software; you can redistribute it and/or modify
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
6 ## it under the terms of the GNU General Public License as published
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
7 ## by the Free Software Foundation; version 3 only.
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
8 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
9 ## This program is distributed in the hope that it will be useful,
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
12 ## GNU General Public License for more details.
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
13 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
14
204
88361534c77e Add some documentation (argh, so much left to document!)
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
15 """ANM0 files handling.
88361534c77e Add some documentation (argh, so much left to document!)
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
16
88361534c77e Add some documentation (argh, so much left to document!)
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
17 This module provides classes for handling the ANM0 file format.
88361534c77e Add some documentation (argh, so much left to document!)
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
18 The ANM0 format is a format used in Touhou 6: EoSD to describe sprites
88361534c77e Add some documentation (argh, so much left to document!)
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
19 and animations.
88361534c77e Add some documentation (argh, so much left to document!)
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
20 Almost everything rendered in the game is described by an ANM0 file.
88361534c77e Add some documentation (argh, so much left to document!)
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
21 """
88361534c77e Add some documentation (argh, so much left to document!)
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
22
2
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
23 from struct import pack, unpack
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
24 from pytouhou.utils.helpers import read_string, get_logger
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
25
377
70e2ed71b09c Add meaningful exceptions in format parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 300
diff changeset
26 from pytouhou.formats import WrongFormatError
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
27 from pytouhou.formats.thtx import Texture
377
70e2ed71b09c Add meaningful exceptions in format parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 300
diff changeset
28
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
29
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
30 logger = get_logger(__name__)
2
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
31
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
32 #TODO: refactor/clean up
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
33
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
34
236
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 204
diff changeset
35 class Script(list):
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 204
diff changeset
36 def __init__(self):
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 204
diff changeset
37 list.__init__(self)
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 204
diff changeset
38 self.interrupts = {}
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 204
diff changeset
39
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 204
diff changeset
40
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 204
diff changeset
41
525
43ecf0f98f4d Precalculate the inverse of the texture size at ANM load, to not recalculate at every sprite change.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
42 cdef class ANM:
43ecf0f98f4d Precalculate the inverse of the texture size at ANM load, to not recalculate at every sprite change.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
43 def __init__(self):
43ecf0f98f4d Precalculate the inverse of the texture size at ANM load, to not recalculate at every sprite change.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
44 self.version = 0
43ecf0f98f4d Precalculate the inverse of the texture size at ANM load, to not recalculate at every sprite change.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
45 self.size_inv[:] = [0, 0]
43ecf0f98f4d Precalculate the inverse of the texture size at ANM load, to not recalculate at every sprite change.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
46 self.first_name = None
43ecf0f98f4d Precalculate the inverse of the texture size at ANM load, to not recalculate at every sprite change.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
47 self.secondary_name = None
43ecf0f98f4d Precalculate the inverse of the texture size at ANM load, to not recalculate at every sprite change.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
48 self.sprites = {}
43ecf0f98f4d Precalculate the inverse of the texture size at ANM load, to not recalculate at every sprite change.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
49 self.scripts = {}
43ecf0f98f4d Precalculate the inverse of the texture size at ANM load, to not recalculate at every sprite change.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
50
43ecf0f98f4d Precalculate the inverse of the texture size at ANM load, to not recalculate at every sprite change.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
51 property size:
43ecf0f98f4d Precalculate the inverse of the texture size at ANM load, to not recalculate at every sprite change.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
52 def __set__(self, tuple value):
43ecf0f98f4d Precalculate the inverse of the texture size at ANM load, to not recalculate at every sprite change.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
53 width, height = value
43ecf0f98f4d Precalculate the inverse of the texture size at ANM load, to not recalculate at every sprite change.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
54 self.size_inv[:] = [1. / <double>width, 1. / <double>height]
43ecf0f98f4d Precalculate the inverse of the texture size at ANM load, to not recalculate at every sprite change.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
55
43ecf0f98f4d Precalculate the inverse of the texture size at ANM load, to not recalculate at every sprite change.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
56
43ecf0f98f4d Precalculate the inverse of the texture size at ANM load, to not recalculate at every sprite change.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
57
282
dbb1a86c0235 Rename Animations to ANM0 and prepare AnmWrapper for dialogs and interface.
Thibaut Girka <thib@sitedethib.com>
parents: 245
diff changeset
58 class ANM0(object):
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
59 _instructions = {0: {0: ('', 'delete'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
60 1: ('I', 'set_sprite'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
61 2: ('ff', 'set_scale'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
62 3: ('I', 'set_alpha'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
63 4: ('BBBx', 'set_color'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
64 5: ('I', 'jump'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
65 7: ('', 'toggle_mirrored'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
66 9: ('fff', 'set_3d_rotations'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
67 10: ('fff', 'set_3d_rotations_speed'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
68 11: ('ff', 'set_scale_speed'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
69 12: ('ii', 'fade'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
70 13: ('', 'set_blendmode_add'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
71 14: ('', 'set_blendmode_alphablend'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
72 15: ('', 'keep_still'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
73 16: ('ii', 'set_random_sprite'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
74 17: ('fff', 'set_3d_translation'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
75 18: ('fffi', 'move_to_linear'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
76 19: ('fffi', 'move_to_decel'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
77 20: ('fffi', 'move_to_accel'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
78 21: ('', 'wait'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
79 22: ('i', 'interrupt_label'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
80 23: ('', 'set_corner_relative_placement'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
81 24: ('', 'wait_ex'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
82 25: ('i', 'set_allow_offset'), #TODO: better name
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
83 26: ('i', 'set_automatic_orientation'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
84 27: ('f', 'shift_texture_x'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
85 28: ('f', 'shift_texture_y'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
86 29: ('i', 'set_visible'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
87 30: ('ffi', 'scale_in'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
88 31: ('i', None)},
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
89
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
90 2: {0: ('', 'noop'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
91 1: ('', 'delete'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
92 2: ('', 'keep_still'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
93 3: ('I', 'set_sprite'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
94 4: ('II', 'jump_bis'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
95 5: ('III', 'jump_ex'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
96 6: ('fff', 'set_3d_translation'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
97 7: ('ff', 'set_scale'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
98 8: ('I', 'set_alpha'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
99 9: ('BBBx', 'set_color'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
100 10: ('', 'toggle_mirrored'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
101 12: ('fff', 'set_3d_rotations'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
102 13: ('fff', 'set_3d_rotations_speed'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
103 14: ('ff', 'set_scale_speed'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
104 15: ('ii', 'fade'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
105 16: ('I', 'set_blendmode'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
106 17: ('fffi', 'move_to_linear'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
107 18: ('fffi', 'move_to_decel'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
108 19: ('fffi', 'move_to_accel'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
109 20: ('', 'wait'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
110 21: ('i', 'interrupt_label'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
111 22: ('', 'set_corner_relative_placement'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
112 23: ('', 'wait_ex'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
113 24: ('i', 'set_allow_offset'), #TODO: better name
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
114 25: ('i', 'set_automatic_orientation'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
115 26: ('f', 'shift_texture_x'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
116 27: ('f', 'shift_texture_y'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
117 28: ('i', 'set_visible'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
118 29: ('ffi', 'scale_in'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
119 30: ('i', None),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
120 31: ('I', None),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
121 32: ('IIfff', 'move_in_linear_bis'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
122 33: ('IIBBBx', 'change_color_in'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
123 34: ('III', 'fade_bis'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
124 35: ('IIfff', 'rotate_in_bis'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
125 36: ('IIff', 'scale_in_bis'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
126 37: ('II', 'set_int'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
127 38: ('ff', 'set_float'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
128 42: ('ff', 'decrement_float'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
129 50: ('fff', 'add_float'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
130 52: ('fff', 'substract_float'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
131 55: ('III', 'divide_int'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
132 59: ('II', 'set_random_int'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
133 60: ('ff', 'set_random_float'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
134 69: ('IIII', 'branch_if_not_equal'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
135 79: ('I', 'wait_duration'),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
136 80: ('I', None)}}
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
137
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
138
2
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
139 @classmethod
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
140 def read(cls, file):
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
141 anm_list = []
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
142 start_offset = 0
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
143 while True:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
144 file.seek(start_offset)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
145 nb_sprites, nb_scripts, zero1 = unpack('<III', file.read(12))
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
146 width, height, fmt, unknown1 = unpack('<IIII', file.read(16))
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
147 first_name_offset, unused, secondary_name_offset = unpack('<III', file.read(12))
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
148 version, unknown2, texture_offset, has_data, next_offset, unknown3 = unpack('<IIIIII', file.read(24))
2
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
149
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
150 if version == 0:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
151 assert zero1 == 0
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
152 assert unknown3 == 0
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
153 assert has_data == 0
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
154 elif version == 2:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
155 assert zero1 == 0
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
156 assert secondary_name_offset == 0
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
157 assert has_data == 1 # Can be false but we don’t support that yet.
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
158 else:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
159 raise WrongFormatError(version)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
160
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
161 instructions = cls._instructions[version]
2
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
162
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
163 sprite_offsets = [unpack('<I', file.read(4))[0] for i in range(nb_sprites)]
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
164 script_offsets = [unpack('<II', file.read(8)) for i in range(nb_scripts)]
2
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
165
525
43ecf0f98f4d Precalculate the inverse of the texture size at ANM load, to not recalculate at every sprite change.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
166 self = ANM()
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
167
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
168 self.size = (width, height)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
169 self.version = version
2
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
170
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
171 # Names
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
172 if first_name_offset:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
173 file.seek(start_offset + first_name_offset)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
174 self.first_name = read_string(file, 32, 'ascii') #TODO: 32, really?
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
175 if secondary_name_offset:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
176 file.seek(start_offset + secondary_name_offset)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
177 self.secondary_name = read_string(file, 32, 'ascii') #TODO: 32, really?
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
178
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
179
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
180 # Sprites
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
181 for offset in sprite_offsets:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
182 file.seek(start_offset + offset)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
183 idx, x, y, width, height = unpack('<Iffff', file.read(20))
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
184 self.sprites[idx] = x, y, width, height
2
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
185
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
186
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
187 # Scripts
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
188 for i, offset in script_offsets:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
189 self.scripts[i] = Script()
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
190 instruction_offsets = []
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
191 file.seek(start_offset + offset)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
192 while True:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
193 instruction_offsets.append(file.tell() - (start_offset + offset))
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
194 if version == 0:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
195 time, opcode, size = unpack('<HBB', file.read(4))
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
196 elif version == 2:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
197 opcode, size, time, mask = unpack('<HHHH', file.read(8))
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
198 if opcode == 0xffff:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
199 break
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
200 size -= 8
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
201 data = file.read(size)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
202 if opcode in instructions:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
203 args = unpack('<%s' % instructions[opcode][0], data)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
204 else:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
205 args = (data,)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
206 logger.warn('unknown opcode %d', opcode)
2
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
207
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
208 self.scripts[i].append((time, opcode, args))
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
209 if version == 0 and opcode == 0:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
210 break
2
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
211
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
212 # Translate offsets to instruction pointers and register interrupts
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
213 for instr_offset, (j, instr) in zip(instruction_offsets, enumerate(self.scripts[i])):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
214 time, opcode, args = instr
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
215 if version == 0:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
216 if opcode == 5:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
217 args = (instruction_offsets.index(args[0]),)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
218 elif opcode == 22:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
219 interrupt = args[0]
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
220 self.scripts[i].interrupts[interrupt] = j + 1
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
221 elif version == 2:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
222 if opcode == 4:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
223 args = (instruction_offsets.index(args[0]), args[1])
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
224 elif opcode == 5:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
225 args = (args[0], instruction_offsets.index(args[1]), args[2])
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
226 elif opcode == 21:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
227 interrupt = args[0]
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
228 self.scripts[i].interrupts[interrupt] = j + 1
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
229 elif opcode == 69:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
230 args = (args[0], args[1], instruction_offsets.index(args[2]), args[3])
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
231 self.scripts[i][j] = time, opcode, args
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
232
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
233 # Texture
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
234 if has_data:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
235 file.seek(start_offset + texture_offset)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
236 magic = file.read(4)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
237 assert magic == b'THTX'
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
238 zero, fmt, width, height, size = unpack('<HHHHI', file.read(12))
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
239 assert zero == 0
111
340fcda8e64a Fix a few, minor things
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
240 data = file.read(size)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
241 self.texture = Texture(width, height, fmt, data)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
242
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
243 anm_list.append(self)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
244
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
245 if next_offset:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
246 start_offset += next_offset
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
247 else:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
248 break
2
057cb96907e3 Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
249
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 402
diff changeset
250 return anm_list