FS2_Open
Open source remastering of the Freespace 2 engine
starfield.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) Volition, Inc. 1999. All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell
5  * or otherwise commercially exploit the source or things you created based on the
6  * source.
7  *
8 */
9 
10 
11 
12 #ifndef _STARFIELD_H
13 #define _STARFIELD_H
14 
15 #include "globalincs/globals.h"
16 #include "globalincs/pstypes.h"
17 #include "graphics/2d.h"
18 #include "model/model.h"
19 
20 #define DEFAULT_NMODEL_FLAGS (MR_NO_ZBUFFER | MR_NO_CULL | MR_ALL_XPARENT | MR_NO_LIGHTING)
21 
22 #define MAX_STARFIELD_BITMAP_LISTS 1
23 #define MAX_ASTEROID_FIELDS 4
24 
25 // nice low polygon background
26 #define BACKGROUND_MODEL_FILENAME "spherec.pof"
27 
28 
29 // starfield list
30 typedef struct starfield_list_entry {
31  char filename[MAX_FILENAME_LEN]; // bitmap filename
32  float scale_x, scale_y; // x and y scale
33  int div_x, div_y; // # of x and y divisions
34  angles ang; // angles from FRED
36 
37 // backgrounds
38 typedef struct background_t {
41 } background_t;
42 
43 #define MAX_BACKGROUNDS 2
44 
45 extern int Num_backgrounds;
46 extern int Cur_background;
48 extern int Nmodel_flags;
49 
50 extern bool Dynamic_environment;
51 extern bool Motion_debris_override;
52 
53 void stars_swap_backgrounds(int idx1, int idx2);
56 
57 
58 // add a new sun or bitmap instance
61 
62 // get the number of entries that each vector contains
63 // "is_a_sun" will get sun instance counts, otherwise it gets normal starfield bitmap instance counts
64 // "bitmap_count" will get number of starfield_bitmap entries rather than starfield_bitmap_instance entries
65 int stars_get_num_entries(bool is_a_sun, bool bitmap_count);
66 
67 // macros to get the number of sun or starfield bitmap *instances* available
68 #define stars_get_num_bitmaps() stars_get_num_entries(false, false)
69 #define stars_get_num_suns() stars_get_num_entries(true, false)
70 
71 // make a bitmap or sun instance as unusable (doesn't free anything but does prevent rendering)
72 void stars_mark_instance_unused(int index, bool is_a_sun);
73 // macros to easily mark a sun or bitmap as unused
74 #define stars_mark_sun_unused(x) stars_mark_instance_unused((x),true)
75 #define stars_mark_bitmap_unused(x) stars_mark_instance_unused((x),false)
76 
77 // get a name from an instance index
78 const char *stars_get_name_from_instance(int index, bool is_a_sun);
79 // macros to easily get a sun or a bitmap name
80 #define stars_get_sun_name(x) stars_get_name_from_instance((x),true)
81 #define stars_get_bitmap_name(x) stars_get_name_from_instance((x),false)
82 
83 extern const int MAX_STARS;
84 extern int Num_stars;
85 
86 // call on game startup
87 void stars_init();
88 // call on game shutdown
89 void stars_close();
90 
91 // call this before mission parse to reset all data to a sane state
92 void stars_pre_level_init(bool clear_backgrounds = true);
93 
94 // call this in game_post_level_init() so we know whether we're running in full nebula mode or not
96 
97 // draw background bitmaps
99 
100 // This *must* be called to initialize the lighting.
101 // You can turn off all the stars and suns and nebulas, though.
102 void stars_draw(int show_stars, int show_suns, int show_nebulas, int show_subspace, int env);
103 // void calculate_bitmap_matrix(starfield_bitmaps *bm, vec3d *v);
104 // void calculate_bitmap_points(starfield_bitmaps *bm, float bank = 0.0f);
105 
106 // draw the corresponding glow for sun_n
107 void stars_draw_sun_glow(int sun_n);
108 
109 // Call when the viewer camera "cuts" so stars and debris
110 // don't draw incorrect blurs between last frame and this frame.
111 void stars_camera_cut();
112 
113 // call this to set a specific model as the background model
114 void stars_set_background_model(char *model_name, char *texture_name, int flags = DEFAULT_NMODEL_FLAGS);
116 
117 // lookup a starfield bitmap, return index or -1 on fail
118 int stars_find_bitmap(char *name);
119 
120 // lookup a sun by bitmap filename, return index or -1 on fail
121 int stars_find_sun(char *name);
122 
123 // get the world coords of the sun pos on the unit sphere.
124 void stars_get_sun_pos(int sun_n, vec3d *pos);
125 
126 // for SEXP stuff so that we can mark a bitmap as being used regardless of whether
127 // or not there is an instance for it yet
128 void stars_preload_sun_bitmap(char *fname);
129 void stars_preload_background_bitmap(char *fname);
130 
131 void stars_set_nebula(bool activate);
132 
133 // Starfield functions that should be used only by FRED ...
134 
135 // get a name based on the index into starfield_bitmap, only FRED should ever need this
136 const char *stars_get_name_FRED(int index, bool is_a_sun);
137 // erase an instance, note that this is very slow so it should only be done in FRED
138 void stars_delete_entry_FRED(int index, bool is_a_sun);
139 // modify an existing starfield bitmap instance, or add a new one if needed
140 void stars_modify_entry_FRED(int index, const char *name, starfield_list_entry *sbi_new, bool is_a_sun);
141 
142 
143 // Goober5000
146 void stars_load_background(int background_idx);
147 
148 #endif
#define MAX_FILENAME_LEN
Definition: pstypes.h:324
void stars_camera_cut()
Definition: starfield.cpp:1005
SCP_vector< starfield_list_entry > suns
Definition: starfield.h:40
void stars_load_first_valid_background()
Definition: starfield.cpp:2636
int div_y
Definition: starfield.h:33
GLuint index
Definition: Glext.h:5608
bool Motion_debris_override
Definition: starfield.cpp:176
#define DEFAULT_NMODEL_FLAGS
Definition: starfield.h:20
Definition: pstypes.h:88
background_t Backgrounds[MAX_BACKGROUNDS]
Definition: starfield.cpp:125
void stars_get_sun_pos(int sun_n, vec3d *pos)
Definition: starfield.cpp:1016
hull_check orient
Definition: lua.cpp:5049
int div_x
Definition: starfield.h:33
void stars_post_level_init()
Definition: starfield.cpp:782
void stars_draw(int show_stars, int show_suns, int show_nebulas, int show_subspace, int env)
Definition: starfield.cpp:1813
const int MAX_STARS
Definition: starfield.cpp:47
void stars_pack_backgrounds()
Definition: starfield.cpp:2750
float scale_x
Definition: starfield.h:32
void stars_set_background_orientation(matrix *orient=NULL)
Definition: starfield.cpp:2207
void stars_delete_entry_FRED(int index, bool is_a_sun)
Definition: starfield.cpp:2616
angles ang
Definition: starfield.h:34
void stars_modify_entry_FRED(int index, const char *name, starfield_list_entry *sbi_new, bool is_a_sun)
Definition: starfield.cpp:2563
#define MAX_BACKGROUNDS
Definition: starfield.h:43
void stars_draw_sun_glow(int sun_n)
Definition: starfield.cpp:1154
void stars_init()
Definition: starfield.cpp:693
void stars_set_background_model(char *model_name, char *texture_name, int flags=DEFAULT_NMODEL_FLAGS)
Definition: starfield.cpp:2172
Definition: bmpman.h:101
void stars_pre_level_init(bool clear_backgrounds=true)
Definition: starfield.cpp:714
void stars_close()
Definition: starfield.cpp:706
const char * stars_get_name_FRED(int index, bool is_a_sun)
Definition: starfield.cpp:2543
int stars_get_num_entries(bool is_a_sun, bool bitmap_count)
Definition: starfield.cpp:2407
int stars_add_bitmap_entry(starfield_list_entry *bitmap)
Definition: starfield.cpp:2347
void stars_set_nebula(bool activate)
Definition: starfield.cpp:2514
bool stars_background_empty()
void stars_swap_backgrounds(int idx1, int idx2)
Definition: starfield.cpp:2735
void stars_mark_instance_unused(int index, bool is_a_sun)
Definition: starfield.cpp:2472
int Nmodel_flags
Definition: starfield.cpp:169
GLbitfield flags
Definition: Glext.h:6722
void stars_preload_sun_bitmap(char *fname)
Definition: starfield.cpp:1873
GLuint const GLchar * name
Definition: Glext.h:5608
int stars_get_first_valid_background()
Definition: starfield.cpp:2643
void stars_draw_background()
Definition: starfield.cpp:2153
float scale_y
Definition: starfield.h:32
struct background_t background_t
hull_check pos
Definition: lua.cpp:5050
const char * stars_get_name_from_instance(int index, bool is_a_sun)
Definition: starfield.cpp:2495
struct starfield_list_entry starfield_list_entry
bool Dynamic_environment
Definition: starfield.cpp:175
int Cur_background
Definition: starfield.cpp:124
SCP_vector< starfield_list_entry > bitmaps
Definition: starfield.h:39
cmdline_parm env("-noenv", NULL, AT_NONE)
int Num_backgrounds
Definition: starfield.cpp:123
Definition: starfield.h:30
char filename[MAX_FILENAME_LEN]
Definition: starfield.h:31
void stars_preload_background_bitmap(char *fname)
Definition: starfield.cpp:1889
int stars_find_bitmap(char *name)
Definition: starfield.cpp:2217
int Num_stars
Definition: starfield.cpp:58
int stars_find_sun(char *name)
Definition: starfield.cpp:2236
void stars_load_background(int background_idx)
Definition: starfield.cpp:2690
int stars_add_sun_entry(starfield_list_entry *sun_ptr)
Definition: starfield.cpp:2256