Skip to content

Commit 5725076

Browse files
committed
Added more comments and fixed some warnings
1 parent 8973e7f commit 5725076

25 files changed

+2223
-229
lines changed

src/game/Maps/MapUpdater.cpp

+50-8
Original file line numberDiff line numberDiff line change
@@ -30,51 +30,80 @@
3030
#include <ace/Guard_T.h>
3131
#include <ace/Method_Request.h>
3232

33+
/**
34+
* @brief A request to update a map.
35+
*/
3336
class MapUpdateRequest : public ACE_Method_Request
3437
{
3538
private:
36-
37-
Map& m_map;
38-
MapUpdater& m_updater;
39-
ACE_UINT32 m_diff;
39+
Map& m_map; ///< Reference to the map to be updated.
40+
MapUpdater& m_updater; ///< Reference to the map updater.
41+
ACE_UINT32 m_diff; ///< Time difference for the update.
4042

4143
public:
42-
44+
/**
45+
* @brief Constructor for MapUpdateRequest.
46+
* @param m Reference to the map.
47+
* @param u Reference to the map updater.
48+
* @param d Time difference for the update.
49+
*/
4350
MapUpdateRequest(Map& m, MapUpdater& u, ACE_UINT32 d)
4451
: m_map(m), m_updater(u), m_diff(d)
4552
{
4653
}
4754

55+
/**
56+
* @brief Executes the map update request.
57+
* @return Always returns 0.
58+
*/
4859
virtual int call()
4960
{
50-
m_map.Update (m_diff);
61+
m_map.Update(m_diff);
5162
m_updater.update_finished();
5263
return 0;
5364
}
5465
};
5566

67+
/**
68+
* @brief Constructor for MapUpdater.
69+
*/
5670
MapUpdater::MapUpdater():
5771
m_executor(), m_mutex(), m_condition(m_mutex), pending_requests(0)
5872
{
5973
}
6074

75+
/**
76+
* @brief Destructor for MapUpdater.
77+
*/
6178
MapUpdater::~MapUpdater()
6279
{
6380
deactivate();
6481
}
6582

83+
/**
84+
* @brief Activates the map updater with the specified number of threads.
85+
* @param num_threads Number of threads to activate.
86+
* @return Result of the activation.
87+
*/
6688
int MapUpdater::activate(size_t num_threads)
6789
{
6890
return m_executor._activate((int)num_threads);
6991
}
7092

93+
/**
94+
* @brief Deactivates the map updater.
95+
* @return Result of the deactivation.
96+
*/
7197
int MapUpdater::deactivate()
7298
{
7399
wait();
74-
75100
return m_executor.deactivate();
76101
}
77102

103+
/**
104+
* @brief Waits for all pending requests to be processed.
105+
* @return Always returns 0.
106+
*/
78107
int MapUpdater::wait()
79108
{
80109
ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, m_mutex, -1);
@@ -85,6 +114,12 @@ int MapUpdater::wait()
85114
return 0;
86115
}
87116

117+
/**
118+
* @brief Schedules a map update.
119+
* @param map Reference to the map to be updated.
120+
* @param diff Time difference for the update.
121+
* @return Result of the scheduling.
122+
*/
88123
int MapUpdater::schedule_update(Map& map, ACE_UINT32 diff)
89124
{
90125
ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, m_mutex, -1);
@@ -102,11 +137,18 @@ int MapUpdater::schedule_update(Map& map, ACE_UINT32 diff)
102137
return 0;
103138
}
104139

140+
/**
141+
* @brief Checks if the map updater is activated.
142+
* @return True if activated, false otherwise.
143+
*/
105144
bool MapUpdater::activated()
106145
{
107146
return m_executor.activated();
108147
}
109148

149+
/**
150+
* @brief Called when a map update is finished.
151+
*/
110152
void MapUpdater::update_finished()
111153
{
112154
ACE_GUARD(ACE_Thread_Mutex, guard, m_mutex);
@@ -120,4 +162,4 @@ void MapUpdater::update_finished()
120162
--pending_requests;
121163

122164
m_condition.broadcast();
123-
}
165+
}

src/game/Maps/MapUpdater.h

+42-8
Original file line numberDiff line numberDiff line change
@@ -32,33 +32,67 @@
3232

3333
class Map;
3434

35+
/**
36+
* @brief The MapUpdater class is responsible for managing map update requests.
37+
*/
3538
class MapUpdater
3639
{
3740
public:
38-
41+
/**
42+
* @brief Constructor for MapUpdater.
43+
*/
3944
MapUpdater();
45+
46+
/**
47+
* @brief Destructor for MapUpdater.
48+
*/
4049
virtual ~MapUpdater();
4150

4251
friend class MapUpdateRequest;
4352

53+
/**
54+
* @brief Schedules a map update.
55+
* @param map Reference to the map to be updated.
56+
* @param diff Time difference for the update.
57+
* @return Result of the scheduling.
58+
*/
4459
int schedule_update(Map& map, ACE_UINT32 diff);
4560

61+
/**
62+
* @brief Waits for all pending requests to be processed.
63+
* @return Always returns 0.
64+
*/
4665
int wait();
4766

67+
/**
68+
* @brief Activates the map updater with the specified number of threads.
69+
* @param num_threads Number of threads to activate.
70+
* @return Result of the activation.
71+
*/
4872
int activate(size_t num_threads);
4973

74+
/**
75+
* @brief Deactivates the map updater.
76+
* @return Result of the deactivation.
77+
*/
5078
int deactivate();
5179

80+
/**
81+
* @brief Checks if the map updater is activated.
82+
* @return True if activated, false otherwise.
83+
*/
5284
bool activated();
5385

5486
private:
55-
56-
DelayExecutor m_executor;
57-
ACE_Thread_Mutex m_mutex;
58-
ACE_Condition_Thread_Mutex m_condition;
59-
size_t pending_requests;
60-
87+
DelayExecutor m_executor; ///< Executor for handling delayed tasks.
88+
ACE_Thread_Mutex m_mutex; ///< Mutex for synchronizing access to pending requests.
89+
ACE_Condition_Thread_Mutex m_condition; ///< Condition variable for signaling when requests are processed.
90+
size_t pending_requests; ///< Number of pending update requests.
91+
92+
/**
93+
* @brief Called when a map update is finished.
94+
*/
6195
void update_finished();
6296
};
6397

64-
#endif //_MAP_UPDATER_H_INCLUDED
98+
#endif //_MAP_UPDATER_H_INCLUDED

src/game/MotionGenerators/ConfusedMovementGenerator.cpp

+38-9
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,16 @@
2828
#include "movement/MoveSplineInit.h"
2929
#include "movement/MoveSpline.h"
3030

31+
/**
32+
* @brief Initializes the ConfusedMovementGenerator.
33+
* @param unit Reference to the unit.
34+
*/
3135
template<class T>
3236
void ConfusedMovementGenerator<T>::Initialize(T& unit)
3337
{
3438
unit.addUnitState(UNIT_STAT_CONFUSED);
3539

36-
// set initial position
40+
// Set initial position
3741
unit.GetPosition(i_x, i_y, i_z);
3842

3943
if (!unit.IsAlive() || unit.hasUnitState(UNIT_STAT_NOT_MOVE))
@@ -45,14 +49,22 @@ void ConfusedMovementGenerator<T>::Initialize(T& unit)
4549
unit.addUnitState(UNIT_STAT_CONFUSED_MOVE);
4650
}
4751

52+
/**
53+
* @brief Interrupts the ConfusedMovementGenerator.
54+
* @param unit Reference to the unit.
55+
*/
4856
template<class T>
4957
void ConfusedMovementGenerator<T>::Interrupt(T& unit)
5058
{
5159
unit.InterruptMoving();
52-
// confused state still applied while movegen disabled
60+
// Confused state still applied while movegen disabled
5361
unit.clearUnitState(UNIT_STAT_CONFUSED_MOVE);
5462
}
5563

64+
/**
65+
* @brief Resets the ConfusedMovementGenerator.
66+
* @param unit Reference to the unit.
67+
*/
5668
template<class T>
5769
void ConfusedMovementGenerator<T>::Reset(T& unit)
5870
{
@@ -67,18 +79,24 @@ void ConfusedMovementGenerator<T>::Reset(T& unit)
6779
unit.addUnitState(UNIT_STAT_CONFUSED | UNIT_STAT_CONFUSED_MOVE);
6880
}
6981

82+
/**
83+
* @brief Updates the ConfusedMovementGenerator.
84+
* @param unit Reference to the unit.
85+
* @param diff Time difference.
86+
* @return True if the update was successful, false otherwise.
87+
*/
7088
template<class T>
7189
bool ConfusedMovementGenerator<T>::Update(T& unit, const uint32& diff)
7290
{
73-
// ignore in case other no reaction state
91+
// Ignore in case other no reaction state
7492
if (unit.hasUnitState(UNIT_STAT_CAN_NOT_REACT & ~UNIT_STAT_CONFUSED))
7593
{
7694
return true;
7795
}
7896

7997
if (i_nextMoveTime.Passed())
8098
{
81-
// currently moving, update location
99+
// Currently moving, update location
82100
unit.addUnitState(UNIT_STAT_CONFUSED_MOVE);
83101

84102
if (unit.movespline->Finalized())
@@ -88,51 +106,62 @@ bool ConfusedMovementGenerator<T>::Update(T& unit, const uint32& diff)
88106
}
89107
else
90108
{
91-
// waiting for next move
109+
// Waiting for next move
92110
i_nextMoveTime.Update(diff);
93111
if (i_nextMoveTime.Passed())
94112
{
95-
// start moving
113+
// Start moving
96114
unit.addUnitState(UNIT_STAT_CONFUSED_MOVE);
97115

98116
float destX = i_x;
99117
float destY = i_y;
100118
float destZ = i_z;
101119

102-
// check if new random position is assigned, GetReachableRandomPosition may fail
120+
// Check if new random position is assigned, GetReachableRandomPosition may fail
103121
if (unit.GetMap()->GetReachableRandomPosition(&unit, destX, destY, destZ, 10.0f))
104122
{
105123
Movement::MoveSplineInit init(unit);
106124
init.MoveTo(destX, destY, destZ, true);
107125
init.SetWalk(true);
108126
init.Launch();
109-
i_nextMoveTime.Reset(urand(800, 1000)); // Keep a short wait time
127+
i_nextMoveTime.Reset(urand(800, 1000)); // Keep a short wait time
110128
}
111129
else
112130
{
113-
i_nextMoveTime.Reset(50); // Retry later
131+
i_nextMoveTime.Reset(50); // Retry later
114132
}
115133
}
116134
}
117135

118136
return true;
119137
}
120138

139+
/**
140+
* @brief Finalizes the ConfusedMovementGenerator for a Player.
141+
* @param unit Reference to the player.
142+
*/
121143
template<>
122144
void ConfusedMovementGenerator<Player>::Finalize(Player& unit)
123145
{
124146
unit.clearUnitState(UNIT_STAT_CONFUSED | UNIT_STAT_CONFUSED_MOVE);
125147
unit.StopMoving(true);
126148
}
127149

150+
/**
151+
* @brief Finalizes the ConfusedMovementGenerator for a Creature.
152+
* @param unit Reference to the creature.
153+
*/
128154
template<>
129155
void ConfusedMovementGenerator<Creature>::Finalize(Creature& unit)
130156
{
131157
unit.clearUnitState(UNIT_STAT_CONFUSED | UNIT_STAT_CONFUSED_MOVE);
132158
}
133159

160+
// Template instantiations for Player and Creature
134161
template void ConfusedMovementGenerator<Player>::Initialize(Player& player);
135162
template void ConfusedMovementGenerator<Creature>::Initialize(Creature& creature);
163+
template void ConfusedMovementGenerator<Player>::Finalize(Player& player);
164+
template void ConfusedMovementGenerator<Creature>::Finalize(Creature& creature);
136165
template void ConfusedMovementGenerator<Player>::Interrupt(Player& player);
137166
template void ConfusedMovementGenerator<Creature>::Interrupt(Creature& creature);
138167
template void ConfusedMovementGenerator<Player>::Reset(Player& player);

0 commit comments

Comments
 (0)