ChartWindow.h
by Pierre Raynaud-Richard.
*/
Copyright 1999, Be Incorporated. All Rights Reserved.
This file may be used under the terms of the Be Sample Code License.
*/
#ifndef CHART_WINDOW_H
#define CHART_WINDOW_H
#include <DirectWindow.h>
#include <OS.h>
#include <Locker.h>
#include <StringView.h>
#include <PictureButton.h>
#include "ChartRender.h"
#include "ChartView.h"
normal window (that you move and resize freely), fullscreen
resize the window to adjust its content area to the full
size of the screen. Demo mode resize the window to have the
animate part of it fit the full screen. */
enum {
WINDOW_MODE = 0,
FULLSCREEN_MODE = 1,
FULLDEMO_MODE = 2
};
randomaly. Novas add a couple start with flashing burst of
light. Battle was never implemented... */
enum {
SPECIAL_NONE = 0,
SPECIAL_COMET = 1,
SPECIAL_NOVAS = 2,
SPECIAL_BATTLE = 3
};
array to draw pixel (but is not currently implemented). Bitmap
use an offscreen BBitmap and DrawBitmap for each frame. Direct
use the DirectWindow API to draw directly on the screen. */
enum {
DISPLAY_OFF = 0,
DISPLAY_LINE = 1,
DISPLAY_BITMAP = 2,
DISPLAY_DIRECT = 3
};
rotation around the center of the starfield, slow straight
move, fast straight move, and a random move (flying around). */
enum {
ANIMATION_OFF = 0,
ANIMATION_ROTATE = 1,
ANIMATION_SLOW_MOVE = 2,
ANIMATION_FAST_MOVE = 3,
ANIMATION_FREE_MOVE = 4
};
everytime you change the starfield type. The first will just
put stars randomly in space. The second will concentrate
star in 10 places. The last one will put half the star in a
big spiral galaxy, and the other one in a few amas. */
enum {
SPACE_CHAOS = 0,
SPACE_AMAS = 1,
SPACE_SPIRAL = 2
};
enum {
ANIM_OFF_MSG = 1000,
ANIM_SLOW_ROT_MSG = 1001,
ANIM_SLOW_MOVE_MSG = 1002,
ANIM_FAST_MOVE_MSG = 1003,
ANIM_FREE_MOVE_MSG = 1004,
DISP_OFF_MSG = 2000,
DISP_LINE_MSG = 2001,
DISP_BITMAP_MSG = 2002,
DISP_DIRECT_MSG = 2003,
OPEN_COLOR_MSG = 3000,
OPEN_DENSITY_MSG = 3100,
OPEN_REFRESH_MSG = 3200,
SPACE_CHAOS_MSG = 3300,
SPACE_AMAS_MSG = 3301,
SPACE_SPIRAL_MSG = 3302,
FULL_SCREEN_MSG = 4000,
AUTO_DEMO_MSG = 4100,
BACK_DEMO_MSG = 4101,
SECOND_THREAD_MSG = 4200,
COLORS_RED_MSG = 5000,
COLORS_GREEN_MSG = 5001,
COLORS_BLUE_MSG = 5002,
COLORS_YELLOW_MSG = 5003,
COLORS_ORANGE_MSG = 5004,
COLORS_PINK_MSG = 5005,
COLORS_WHITE_MSG = 5006,
SPECIAL_NONE_MSG = 6000,
SPECIAL_COMET_MSG = 6001,
SPECIAL_NOVAS_MSG = 6002,
SPECIAL_BATTLE_MSG = 6003,
COLOR_PALETTE_MSG = 7000,
STAR_DENSITY_MSG = 8000,
REFRESH_RATE_MSG = 9000
};
enum {
SPECIAL_COUNT_MAX = 512,
KEY_POINT_MAX = 16
};
operations. */
class TPoint {
public:
float x;
float y;
float z;
TPoint operator* (const float k) const;
TPoint operator- (const TPoint& v2) const;
TPoint operator+ (const TPoint& v2) const;
TPoint operator^ (const TPoint& v2) const;
float Length() const;
};
class TMatrix {
public:
float m[3][3];
TPoint operator* (const TPoint& v) const;
TPoint Axis(int32 index);
TMatrix Transpose() const;
void Set(const float alpha, const float theta, const float phi);
};
class BBox;
class BView;
class ChartWindow : public BDirectWindow {
public:
ChartWindow(BRect frame, const char *name);
virtual ~ChartWindow();
virtual bool QuitRequested();
virtual void MessageReceived(BMessage *message);
virtual void ScreenChanged(BRect screen_size, color_space depth);
virtual void FrameResized(float new_width, float new_height);
can be set by the UI. The idea is to solve all possible
synchronisation problem between the UI settings and the
engine (when using DirectWindow mode) by defining a
current setting state and a next setting state. The UI
touches only the next setting state, never the one
currently use by the engine. This way the engine doesn't
have to be synchronised with the UI. */
struct setting {
bool second_thread;
bool colors[7];
int32 fullscreen_mode;
int32 special;
int32 display;
int32 space_model;
int32 animation;
model ? */
int32 star_density;
float refresh_rate;
view ? */
rgb_color back_color;
color_space depth;
the window ? */
int32 width, height;
void Set(setting *master);
};
that are defined per star. */
typedef union {
counters to define how long the star will
continue before disappearing. */
struct {
float dx;
float dy;
float dz;
int32 count;
int32 count0;
} comet;
pulse cycle of the star. */
struct {
float count;
int32 count0;
} nova;
struct {
int32 count;
} battle;
} special;
as display by the vue-meter. */
int32 fInstantLoadLevel;
BBitmap *fOffscreen;
setting fCurrentSettings;
private:
BBox *fStatusBox;
BBox *fColorsBox;
BBox *fSpecialBox;
BView *fLeftView;
BView *fTopView;
static BWindow *GetAppWindow(const char *name);
BPicture *ButtonPicture(bool active, int32 button_type);
floating windows, for the background color, the star
density and the refresh rate. */
void OpenColorPalette(BPoint here);
void OpenStarDensity(BPoint here);
void OpenRefresh(BPoint here);
void DrawInstantLoad(float frame_per_second);
void PrintStatNumbers(float fps);
void InitGeometry();
and the currently used one. */
void ChangeSetting(setting new_set);
void InitStars(int32 model);
void FillStarList(star *list, int32 count);
void InitSpecials(int32 code);
selected colors. */
void SetStarColors(int32 *color_list, int32 color_count);
viewing area is resized. */
void SetGeometry(int32 dh, int32 dv);
void SetColorSpace(buffer *buf, color_space depth);
bits pointer changes. */
void SetPatternBits(buffer *buf);
static int32 Animation(void *data);
static int32 Animation2(void *data);
cycle of the starfield to maintain the pyramid of vision
of the camera completly inside a 1x1x1 iteration of the
starfield. */
void SetCubeOffset();
void CameraAnimation(float time_factor);
void SelectNewTarget();
void FollowTarget();
void AnimSpecials(float time_step);
state (before calling the embedded C-engine in ChartRender.c */
void SyncGeo();
executed by the embedded C-engine in ChartRender.c */
void RefreshStars(buffer *buf, float time_step);
in sync with the current settings. */
void CheckBitmap(color_space depth, int32 width, int32 height);
visible) */
void SetBitmapClipping(int32 width, int32 height);
void SetBitmapBackGround();
frame buffer. */
void SwitchContext(direct_buffer_info *info);
public:
virtual void DirectConnected(direct_buffer_info *info);
private:
int32 fCrcAlea;
inline void CrcStep();
setting fNextSettings;
the DirectWindow buffer. */
buffer fBitmapBuffer;
buffer fDirectBuffer;
int32 fMaxWidth, fMaxHeight;
and window mode */
BRect fPreviousFrame;
int32 fPreviousFullscreenMode;
guarantees that the 1x1x1 sample will contain the full
pyramid of vision. */
TPoint fCut;
float fDepthRef;
int32 fBackColorIndex;
bigtime_t fFrameDelay;
BButton *fOffwindowButton;
ChartView *fChartView;
BStringView *fCpuLoadView, *fFramesView;
InstantView *fInstantLoad;
BPictureButton *fColorButton, *fDensityButton, *fRefreshButton;
and dynamic (in other case than free move). */
float fCameraAlpha, fCameraTheta, fCameraPhi;
float fDynamicAlpha;
float fDynamicTheta;
float fDynamicPhi;
int32 fCountAlpha, fCountTheta, fCountPhi;
TPoint fOrigin;
TMatrix fCamera;
TMatrix fCameraInvert;
C-engine (just a copy of part of the previous states) */
geometry fGeometry;
int32 fTrackingTarget;
int32 fKeyPointCount;
float fSpeed, fTargetSpeed;
float fLastDynamicDelay;
TPoint fKeyPoints[KEY_POINT_MAX];
star_packet fStars;
TPoint fComet[2];
TPoint fDeltaComet[2];
special *fSpecialList;
star_packet fSpecials;
thread_id fAnimationThread;
thread_id fSecondAnimationThread;
float fSecondThreadThreshold;
buffer *fSecondThreadBuffer;
sem_id fSecondThreadLock;
sem_id fSecondThreadRelease;
bigtime_t fSecondThreadDelay;
star_packet fStars2;
star_packet fSpecials2;
bool fKillThread;
bool fDirectConnected;
sem_id fDrawingLock;
};
#endif