xref: /haiku/src/tests/kits/game/direct_window_test/StarWindow.h (revision c237c4ce593ee823d9867fd997e51e4c447f5623)
1 /*
2 
3 	StarWindow.h
4 
5 	by Pierre Raynaud-Richard.
6 
7 */
8 
9 /*
10 	Copyright 1999, Be Incorporated.   All Rights Reserved.
11 	This file may be used under the terms of the Be Sample Code License.
12 */
13 
14 #ifndef STAR_WINDOW_H
15 #define STAR_WINDOW_H
16 
17 #include <DirectWindow.h>
18 #include <OS.h>
19 
20 
21 class StarWindow : public BDirectWindow {
22 
23 public:
24 		// standard constructor and destrcutor
25 				StarWindow(BRect frame, const char *name);
26 virtual			~StarWindow();
27 
28 		// standard window member
29 virtual	bool	QuitRequested();
30 virtual	void	MessageReceived(BMessage *message);
31 
32 		// this is the hook controling direct screen connection
33 virtual void	DirectConnected(direct_buffer_info *info);
34 
35 
36 
37 private:
38 		// this function is used to inforce a direct access context
39 		// modification.
40 		void	SwitchContext(direct_buffer_info *info);
41 
42 		// function used to increment the pseudo_random generator
43 inline	void	CrcStep();
44 
45 		// the drawing thread function.
46 static	status_t	StarAnimation(void *data);
47 
48 		// struct used to control each star.
49 		typedef struct {
50 			// current position (fixed point 16:16).
51 			int32		x;
52 			int32		y;
53 			// current speed vector (16:16).
54 			int32		dx;
55 			int32		dy;
56 			// starting speed vector, define only at init time (16:16).
57 			int32		dx0;
58 			int32		dy0;
59 			// how many moves left before restarting from the center.
60 			uint16		count;
61 			// minimal moves count between two restarts from the center.
62 			uint16		count0;
63 			// offset from the base of the buffer, in pixel, of the
64 			// last drawn position of the star, or INVALID if not
65 			// drawn.
66 			uint32		last_draw;
67 		} star;
68 
69 
70 		enum {
71 		// used for star->last_draw
72 			INVALID					= 0xffffffff,
73 		// used for the local copy of the clipping region
74 			MAX_CLIPPING_RECT_COUNT = 64
75 		};
76 
77 
78 		// flag used to force the drawing thread to quit.
79 		bool				kill_my_thread;
80 		// the drawing thread doing the star animation.
81 		thread_id			my_thread;
82 		// used to synchronise the star animation drawing.
83 		sem_id				drawing_lock;
84 
85 
86 		// array used for star animation.
87 		star				*star_list;
88 		// count of star currently animated.
89 		uint32				star_count;
90 		// maximal count of star in the array.
91 		uint32				star_count_max;
92 
93 
94 		// the pixel drawing can be done in 3 depth : 8, 16 or 32.
95 		int32				pixel_depth;
96 
97 		// base pointer of the screen, one per pixel_depth
98 		uint8				*draw_ptr8;
99 		uint16				*draw_ptr16;
100 		uint32				*draw_ptr32;
101 
102 		// pixel data, one per pixel_depth (for the same pixel_depth,
103 		// the value depends of the color and the specific color encoding).
104 		uint8				pixel8;
105 		uint16				pixel16;
106 		uint32				pixel32;
107 
108 		// offset, in bytes, between two lines of the frame buffer.
109 		uint32				row_bytes;
110 
111 		// offset, in bytes, between the base of the screen and the base
112 		// of the content area of the window (top left corner).
113 		uint32				window_offset;
114 
115 		// clipping region, defined as a list of rectangle, including the
116 		// smaller possible bounding box. This application will draw only
117 		// in the 64 first rectangles of the region. Region more complex
118 		// than that won't be completly used. This is a valid approximation
119 		// with the current clipping architecture. If a region more complex
120 		// than that is passed to your application, that just means that
121 		// the user is doing something really, really weird.
122 		clipping_rect		clipping_bound;
123 		clipping_rect		clipping_list[MAX_CLIPPING_RECT_COUNT];
124 		uint32				clipping_list_count;
125 
126 		// used for dynamic resizing.
127 		int32				cx_old, cy_old;
128 
129 		// pseudo-random generator base
130 		int32				crc_alea;
131 
132 		// enable/disable a work around needed for R3.0
133 		bool				need_r3_buffer_reset_work_around;
134 };
135 
136 #endif
137