1 /* -*- c++ -*-
2 FILE: MagicCubeObj.h
3 RCS REVISION: $Revision: 1.10 $
4 
5 COPYRIGHT: (c) 1999 -- 2003 Melinda Green, Don Hatch, and Jay Berkenbilt - Superliminal Software
6 
7 LICENSE: Free to use and modify for non-commercial purposes as long as the
8     following conditions are adhered to:
9     1) Obvious credit for the source of this code and the designs it embodies
10        are clearly made, and
11     2) Ports and derived versions of 4D Magic Cube programs are not distributed
12        without the express written permission of the authors.
13 
14 DESCRIPTION:
15     This class is the primary event handling class for the Windows
16     portion of the MagicCube4d code.
17 */
18 
19 #ifndef MAGICCUBEOBJ_H
20 #define MAGICCUBEOBJ_H
21 
22 #include "Preferences.h"
23 #include "Flexible.h"
24 #include "MagicCube.h"
25 #include "Polymgr.h"
26 #include "Puzzlest.h"
27 #include "History.h"
28 #include <stdio.h>
29 
30 
31 // The MagicCubeObject class represents the displayable geometric
32 // representation of a puzzle.
33 
34 typedef real Vert3[3];
35 typedef real Vert4[4];
36 typedef int Quad[4];
37 
38 class MagicCubeObject:public Flexible
39 {
40   public:
41     MagicCubeObject (int nslices, FILE *fp, const double colors[][3],
42                      LPDIRECT3DRMDEVICE d, LPDIRECT3DRM lpd3drm);
43     virtual ~MagicCubeObject ();
44     virtual int UpdateVertexData(D3DVERTEX v[]);
45     void        Reset();
46     int         TwistAbout(int stickerid, int dir, int depth);
47     int         RotateFaceToCenter(int sticker_geom_id);
48     bool        Undo(bool across_scramble_boundary_ok = false);
49     void        Cheat();
50     void        Scramble(int n_scramblechens);
51     int         IsSolved() const;
IsValid()52     int         IsValid() const { return m_is_valid; }
IsAnimating()53     int         IsAnimating() const { return m_twist_dir; }
54     void        SaveTo(FILE *) const;
55     int         ReadFrom(FILE *);
56     struct IdColor
57     {
58         int         id;
59         int         color;
60     };
61   private:
62     void set_vert_colors(D3DVERTEX v[]);
63     void        update_sticker_map();
64     Preferences m_preferences;
65     PolygonManager4D *m_polymgr; // source of polygons representing puzzle state
66     History    *m_history;
67     PuzzleState *m_puzzle_state;
68     int         m_nslices;
69     int         m_nstickers;    // m_nslices^3 * 8
70     int         m_nverts;       // 8 * m_nstickers
71     int         m_nquads;       // 6 * m_nstickers
72     Vert3      *m_verts3;       // [m_nverts][3]
73     Quad       *m_quads;        // [m_nquads][4]
74     int        *m_culled;       // [m_nquads]
75     int        *m_stickerids;   // [m_nquads]
76     int         m_is_valid;
77     real        m_faceshrink;
78     real        m_stickershrink;
79     struct stickerspec m_twist_grip;    // grip currently twisting about
80     int         m_twist_dir;    // direction
81     int         m_twist_slicemask;  // which slices to twist (0x1 == top slice, etc.)
82     real        m_twist_inc;    // additional twisting per frame
83     int         m_twist_nframes;    // number of frames in twist animation
84     int         m_twist_frame_number;   // current twist frame in animation
85     IdColor    *m_geom2id;      // sticker pos in display list to puzzle state id map
86     int         m_undoing;      // set to non-zero when starting an undo animation
87     int         m_cheating;     // set to non-zero when playing history back to start
88 };
89 
90 #endif
91 
92 // Local Variables:
93 // c-basic-offset: 4
94 // c-comment-only-line-offset: 0
95 // c-file-offsets: ((defun-block-intro . +) (block-open . 0) (substatement-open . 0) (statement-cont . +) (statement-case-open . +4) (arglist-intro . +) (arglist-close . +) (inline-open . 0))
96 // indent-tabs-mode: nil
97 // End:
98