Skip to content

Commit

Permalink
Mark functions and variables as static (#185)
Browse files Browse the repository at this point in the history
* Begin by marking functions and variables as static when needed.

* More work.

* More work.

* More pokes.

* More work.

* More work.

* Initial work on the netgames.

* Revert changes to the license header on source files.

* clutter.cpp poke.

* One final poke.

* Move some declarations to headers:

Move paged_in_count and paged_in_num to gamesequence.h
Move DoneLightInstance and StartLightInstance to polymodel.h

* Look over the AI script/plug-ins.

* Going over the changes one last time.

* Fix rebase errors.

* More migration from bare statics to static inlines.
  • Loading branch information
MaddTheSane committed May 7, 2024
1 parent aaa0d21 commit c6da74b
Show file tree
Hide file tree
Showing 154 changed files with 2,082 additions and 1,678 deletions.
7 changes: 7 additions & 0 deletions 2dlib/font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@

typedef CFILE *FONTFILE;

static inline int READ_FONT_INT(FONTFILE ffile);
static inline short READ_FONT_SHORT(FONTFILE ffile);
static inline ubyte READ_FONT_BYTE(FONTFILE ffile);
static inline int READ_FONT_DATA(FONTFILE ffile, void *buf, int size, int nelem);
static inline FONTFILE OPEN_FONT(char *filename, bool &success);
static inline void CLOSE_FONT(FONTFILE ffile);

#define BITS_TO_BYTES(_c) (((_c) + 7) >> 3)
#define BITS_TO_SHORTS(_c) (((_c) + 15) >> 4)

Expand Down
2 changes: 1 addition & 1 deletion 2dlib/surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
#include "texture.h"
#include "renderer.h"

inline unsigned XLAT_RGB_TO_16(ddgr_color c) {
static inline unsigned XLAT_RGB_TO_16(ddgr_color c) {
unsigned char r, g, b;
r = (unsigned char)((c & 0x00ff0000) >> 16);
g = (unsigned char)((c & 0x0000ff00) >> 8);
Expand Down
3 changes: 3 additions & 0 deletions Descent3/AIGoal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,9 @@

extern int AI_unique_goal_id;

static void GoalInitWanderAround(object *obj, goal *goal_ptr);
static int GoalAllocSlot(object *obj, int level, float influence);

#define BASH_TO_ANIM_SCALER 10.0f
#define MAX_BASH_TO_FLINCH_TIME 2.5f

Expand Down
81 changes: 56 additions & 25 deletions Descent3/AImain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1563,7 +1563,40 @@ bool AI_debug_robot_do = false;
int AI_debug_robot_index = -2;
#endif

bool compute_dodge_dir(/* vector *dodge_dir, */ object *obj, object *dodge_obj);
static bool compute_dodge_dir(/* vector *dodge_dir, */ object *obj, object *dodge_obj);
static float AIDetermineObjVisLevel(object *obj, object *target);
static bool move_relative_object_vec(object *obj, vector *vec, object *target, float circle_dist, float scalar,
bool f_toward, vector *mdir, bool *f_moved);
static void move_away_from_position(object *obj, vector *pos /*, bool random_evade*/, float scale, vector *mdir,
bool *f_moved);
static bool goal_do_dodge(object *obj, int goal_index);
static bool goal_do_avoid_walls(object *obj, vector *mdir);
static bool MeleeHitOk(object *obj);
static bool AiMelee(object *obj);
static void do_ranged_attack(object *obj);
static bool AIDetermineAimPoint(object *robot, object *target, vector *aim_pt, float weapon_speed = 0.0f);
static vector *AIDetermineFovVec(object *obj, vector *fov);
static void AISeeTarget(object *obj, bool f_see);
static void ai_do_animation(object *obj, float anim_time);
static void ObjSetAIInfo(object *objp);
static void AICheckTargetVis(object *obj);
static void ai_update_registers(object *obj);
static bool AiGoalAvoid(vector *adir, object *obj, object *a_obj, float dist);
static void AIGoalDoRepulse(object *obj, float dist, vector *dir, goal *goal, vector *mdir);
static void AIGoalDoCohesion(object *obj, object *g_obj, float dist, goal *goal, vector *mdir);
static void AIGoalDoAlignment(object *obj, float dist, vector *fvec, goal *goal, vector *mdir);
static void AIDoTrackFrame(object *obj);
static void AIDoOrientVelocity(object *obj);
static void AIDoOrientDefault(object *obj);
static void AIDoOrient(object *obj, int g_index);
static void AIDetermineSpeed(object *obj, int flags, float *speed);
static void ai_move(object *obj);
static void ai_fire(object *obj);
static int AIGetTeam(object *obj);
static void AITargetCheck(object *obj, object *target, object **best_obj, float *best_dot, float *best_dist);
static void AIDetermineTarget(object *obj);
static void AIDoFreud(object *obj);
static void AIDoMemFrame(object *obj);

// chrishack -- AI problems

Expand Down Expand Up @@ -1598,14 +1631,14 @@ int AI_NumHostileAlert = 0;

int Buddy_handle[MAX_PLAYERS];

int AI_FriendNumNear = 0; // Number of friends found
object *AI_FriendObj[2]; // Friend objects
float AI_FriendDist[2]; // Distances to the friends
vector AI_FriendDir[2]; // Direction to the friends
int AI_EnemyNumNear = 0; // Number of enemies found
object *AI_EnemyObj[2]; // Enemy objects
float AI_EnemyDist[2]; // Distances to the enemies
vector AI_EnemyDir[2]; // Direction to the enemies
static int AI_FriendNumNear = 0; // Number of friends found
static object *AI_FriendObj[2]; // Friend objects
static float AI_FriendDist[2]; // Distances to the friends
static vector AI_FriendDir[2]; // Direction to the friends
static int AI_EnemyNumNear = 0; // Number of enemies found
static object *AI_EnemyObj[2]; // Enemy objects
static float AI_EnemyDist[2]; // Distances to the enemies
static vector AI_EnemyDir[2]; // Direction to the enemies

#define AIVIS_NONE 0.0f
#define AIVIS_BARELY 1.0f
Expand Down Expand Up @@ -1648,7 +1681,7 @@ float AIDetermineObjVisLevel(object *obj, object *target) {
return vis_level;
}

inline bool ai_target_valid(object *obj) {
static inline bool ai_target_valid(object *obj) {
ai_frame *ai_info = obj->ai_info;
bool f_valid = false;

Expand Down Expand Up @@ -1917,8 +1950,6 @@ bool goal_do_dodge(object *obj, int goal_index) {
return false;
}

extern uint check_point_to_face(vector *colp, vector *face_normal, int nv, vector **vertex_ptr_list);

#define MAX_WALL_AVOID_INFLUENCE 0.9f
#define MAX_TERRAIN_AVOID_INFLUENCE 0.9f
#define GB_WALL_PULSE_INTERVAL 7
Expand Down Expand Up @@ -2224,6 +2255,7 @@ bool AITurnTowardsMatrix(object *obj, float turn_rate, matrix *g_orient) {
return false;
}

// MTS: Unused?
void AITurnTowardsPosition(object *obj, /*velocity *new_vel,*/ vector *pos /*, bool remain_level*/) {
vector goal_dir = *pos - obj->pos;
ai_frame *ai_info = obj->ai_info;
Expand Down Expand Up @@ -2734,7 +2766,7 @@ void AIUpdateAnim(object *obj) {
}
}

inline void ApplyConstantForce(object *objp, vector *new_pos, vector *force, float delta_time) {
static inline void ApplyConstantForce(object *objp, vector *new_pos, vector *force, float delta_time) {
const vector velocity = objp->mtype.phys_info.velocity;
const float drag = objp->mtype.phys_info.drag;
const float mass = objp->mtype.phys_info.mass;
Expand All @@ -2744,7 +2776,7 @@ inline void ApplyConstantForce(object *objp, vector *new_pos, vector *force, flo
(mass / drag) * (velocity - (*force / drag)) * (1 - exp(-(drag / mass) * delta_time));
}

bool AIDetermineAimPoint(object *robot, object *target, vector *aim_pt, float weapon_speed = 0.0f) {
bool AIDetermineAimPoint(object *robot, object *target, vector *aim_pt, float weapon_speed) {
if (DIFF_LEVEL == DIFFICULTY_TRAINEE && ((robot->ai_info->flags & AIF_TEAM_MASK) != AIF_TEAM_REBEL)) {
*aim_pt = target->pos;
return true;
Expand Down Expand Up @@ -3470,6 +3502,7 @@ void ai_do_animation(object *obj, float anim_time) {

#define FRR_MAX_TRIES 15

// MTS: Unused?
int AIGoalGotoRandomRoom() { return -1; }

int AIFindRandomRoom(object *obj, ai_frame *ai_info, goal *goal_ptr, int avoid_room, int min_depth, int max_depth,
Expand Down Expand Up @@ -4076,8 +4109,10 @@ bool AIStatusCircleFrame(object *obj, object *g_obj, float dist, float c_dist, i
}
}

// MTS: Unused?
bool ai_target_need_path(object *obj) { return true; }

// MTS: Unused?
bool ai_move_need_path(object *obj, vector *pos, int roomnum) {
if (obj->roomnum == roomnum) {
return false;
Expand Down Expand Up @@ -4146,7 +4181,7 @@ bool AiGoalAvoid(vector *adir, object *obj, object *a_obj, float dist) {
return true;
}

inline bool IsTargetLocal(object *obj, object *target) {
static inline bool IsTargetLocal(object *obj, object *target) {
int target_room = target->roomnum;
int cur_room = obj->roomnum;
int i;
Expand Down Expand Up @@ -4181,6 +4216,7 @@ inline bool IsTargetLocal(object *obj, object *target) {
#define COHESION_OPTI2_DIST 90.0f
#define COHESION_FALL_OFF 110.0f

// MTS: commented out/returns a bool instead of a float
float AIGoalIsEnabledForDist(goal *goal, float dist) {
return true; // chrishack -- test code -- temp
}
Expand Down Expand Up @@ -4332,6 +4368,7 @@ void AIDoTrackFrame(object *obj) {
}
}

// MTS: unused?
float AIDetermineGoalInfluence(object *obj, goal *goal) {
float influence = goal->influence;
int g_index = goal - obj->ai_info->goals;
Expand Down Expand Up @@ -4405,12 +4442,6 @@ void AIDoOrientDefault(object *obj) {
}
}

extern bool AIPathAtEnd(ai_path_info *aip);
extern bool AIPathAtStart(ai_path_info *aip);
extern bool AIPathGetNextNodePos(ai_path_info *aip, vector *pos, int *room = NULL);
extern bool AIPathGetPrevNodePos(ai_path_info *aip, vector *pos, int *room = NULL);
extern bool AIPathGetCurrentNodePos(ai_path_info *aip, vector *pos, int *room = NULL);

void AIDoOrient(object *obj, int g_index) {
ai_frame *ai_info = obj->ai_info;
goal *goal_ptr = &ai_info->goals[g_index];
Expand Down Expand Up @@ -5512,7 +5543,7 @@ void ai_fire(object *obj) {
#define PERCENT_QUIRK_PER_SEC .1
#define PERCENT_TAUNT_PER_SEC .1

inline void do_awareness_based_anim_stuff(object *obj) {
static inline void do_awareness_based_anim_stuff(object *obj) {
int next_anim;
ai_frame *ai_info = obj->ai_info;

Expand Down Expand Up @@ -5557,7 +5588,7 @@ inline void do_awareness_based_anim_stuff(object *obj) {
}
}

inline void ai_decrease_awareness(object *obj) {
static inline void ai_decrease_awareness(object *obj) {
ai_frame *ai_info = obj->ai_info;

if (ai_info->awareness == AWARE_NONE && !(ai_info->flags & AIF_PERSISTANT)) {
Expand All @@ -5583,15 +5614,15 @@ inline void ai_decrease_awareness(object *obj) {
// mprintf((0, "Awareness %f", ai_info->awareness));
}

inline bool ai_do_script_stuff(object *obj) {
static inline bool ai_do_script_stuff(object *obj) {
tOSIRISEventInfo ei;
Osiris_CallEvent(obj, EVT_AI_FRAME, &ei);
//@$-D3XExecScript(obj, EVT_AI_FRAME, NULL, REF_OBJTYPE, NULL);

return true;
}

inline void ai_walker_stuff(object *obj) {
static inline void ai_walker_stuff(object *obj) {
ai_frame *ai_info = obj->ai_info;

// Do standing->walking and walking->standing stuff
Expand Down
80 changes: 48 additions & 32 deletions Descent3/BOA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,33 +141,33 @@

#define BOA_VERSION 25

const ubyte bbf_lookup[27] = {(0),
(0x01),
(0x02),
(0x04),
(0x08),
(0x10),
(0x20),
(0x01 | 0x02),
(0x01 | 0x04),
(0x01 | 0x10),
(0x01 | 0x20),
(0x02 | 0x04),
(0x02 | 0x08),
(0x02 | 0x20),
(0x04 | 0x08),
(0x04 | 0x10),
(0x08 | 0x10),
(0x08 | 0x20),
(0x10 | 0x20),
(0x01 | 0x02 | 0x04),
(0x01 | 0x02 | 0x20),
(0x01 | 0x04 | 0x10),
(0x01 | 0x10 | 0x20),
(0x08 | 0x02 | 0x04),
(0x08 | 0x02 | 0x20),
(0x08 | 0x04 | 0x10),
(0x08 | 0x10 | 0x20)};
static const ubyte bbf_lookup[27] = {(0),
(0x01),
(0x02),
(0x04),
(0x08),
(0x10),
(0x20),
(0x01 | 0x02),
(0x01 | 0x04),
(0x01 | 0x10),
(0x01 | 0x20),
(0x02 | 0x04),
(0x02 | 0x08),
(0x02 | 0x20),
(0x04 | 0x08),
(0x04 | 0x10),
(0x08 | 0x10),
(0x08 | 0x20),
(0x10 | 0x20),
(0x01 | 0x02 | 0x04),
(0x01 | 0x02 | 0x20),
(0x01 | 0x04 | 0x10),
(0x01 | 0x10 | 0x20),
(0x08 | 0x02 | 0x04),
(0x08 | 0x02 | 0x20),
(0x08 | 0x04 | 0x10),
(0x08 | 0x10 | 0x20)};

unsigned short BOA_Array[MAX_ROOMS + MAX_BOA_TERRAIN_REGIONS][MAX_ROOMS + MAX_BOA_TERRAIN_REGIONS];
float BOA_cost_array[MAX_ROOMS + MAX_BOA_TERRAIN_REGIONS][MAX_PATH_PORTALS];
Expand All @@ -177,15 +177,33 @@ bool BOA_vis_valid = 0; // Is the vis table up to date and valid to use?
int BOA_AABB_checksum = 0;
int BOA_AABB_ROOM_checksum[MAX_ROOMS + MAX_BOA_TERRAIN_REGIONS];

bool BOA_f_making_boa = false;
static bool BOA_f_making_boa = false;

int BOA_num_mines = 0;
int BOA_num_terrain_regions = 0;

int BOA_num_connect[MAX_BOA_TERRAIN_REGIONS];
connect_data BOA_connect[MAX_BOA_TERRAIN_REGIONS][MAX_PATH_PORTALS];

void ComputeBOAVisFaceUpperLeft(room *rp, face *fp, vector *upper_left, float *xdiff, float *ydiff, vector *center);
static void add_mine_room(int room, int mine, char *checked);
static void compute_mine_info();
static void add_terrain_cell(int cell, int t_region, char *checked);
static void compute_terrain_region_info();
static void compute_sound_dist_info();
static void clear_BOA();
static void compute_costs();
static void update_path_info(q_item *node_list[MAX_ROOMS], int start, int end);
static void FindPath(int i, int j);
static void compute_next_segs();
static void compute_blockage_info();
static void ComputeBOAVisFaceUpperLeft(room *rp, face *fp, vector *upper_left, float *xdiff, float *ydiff,
vector *center);
static int BOAGetRoomChecksum(int i);
static bool IsPathPointValid(int room, vector *pos);
static void ValidateRoomPathPoint(int room, char *message, int len);
static void verify_connections();
static void find_small_portals();
static void compute_robot_path_info();

bool BOA_PassablePortal(int room, int portal_index, bool f_for_sound, bool f_making_robot_path_invalid_list) {
if (room == -1) {
Expand Down Expand Up @@ -1483,8 +1501,6 @@ void ComputeBOAVisFaceUpperLeft(room *rp, face *fp, vector *upper_left, float *x
*center = avg_vert;
}

extern uint check_point_to_face(vector *colp, vector *face_normal, int nv, vector **vertex_ptr_list);

#if (defined(EDITOR) || defined(NEWEDITOR))

#ifdef NEWEDITOR
Expand Down Expand Up @@ -2082,7 +2098,7 @@ void MakeBOA(void) {
mprintf((0, "BOA is done\n"));
}

int Current_sort_room;
static int Current_sort_room;

static int face_sort_func1(const short *a, const short *b) {
if (Rooms[Current_sort_room].faces[*a].min_xyz.y > Rooms[Current_sort_room].faces[*b].min_xyz.y)
Expand Down

0 comments on commit c6da74b

Please sign in to comment.