Skip to content

Commit 59efe83

Browse files
author
Patrick Rye
committed
Update to v1.2.7-Beta
## [1.2.7-Beta] - 2015-11-18 ### Fixed * Copy Paste Error that caused the pixel texture to remain in memory * Spelling and grammar mistakes ### Added * More comments
1 parent d190c37 commit 59efe83

File tree

12 files changed

+96
-66
lines changed

12 files changed

+96
-66
lines changed

ChangesLog.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
All notable changes to this project will be documented here.
44
This project adheres to [Semantic Versioning](http://semver.org/)
55

6+
## [1.2.7-Beta] - 2015-11-18
7+
### Fixed
8+
* Copy Paste Error that caused the pixel texture to remain in memory
9+
* Spelling and grammar mistakes
10+
11+
### Added
12+
* More comments
13+
14+
615
## [1.2.6-Beta] - 2015-09-24
716
### Updated
817
* Cleanup.bat to include doxygen files (also added wildcard support for some files)

project/SDL-Cannon-Simulation.cbp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<Add option="-Os" />
4646
<Add option="-std=c++11" />
4747
<Add option="-w" />
48+
<Add option="-D__NO_INLINE__" />
4849
<Add directory="src/" />
4950
</Compiler>
5051
<Linker>

project/doxygen/Doxyfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ PROJECT_NAME = Cannon-Simulation
3838
# could be handy for archiving the generated documentation or if some version
3939
# control system is used.
4040

41-
PROJECT_NUMBER = v1.2.6-Beta
41+
PROJECT_NUMBER = v1.2.7-Beta
4242

4343
# Using the PROJECT_BRIEF tag one can provide an optional one line description
4444
# for a project that appears at the top of each page and should give viewer a
@@ -51,7 +51,7 @@ PROJECT_BRIEF = "Simulation of Cannonballs hitting each other"
5151
# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy
5252
# the logo to the output directory.
5353

54-
PROJECT_LOGO = C:/Users/Patrick.Rye/Documents/GitHub/Cannon-Simulation/res/logo.png
54+
PROJECT_LOGO = C:/Users/Patrick/Documents/GitHub/SDL-Cannon-Simulation/res/logo.png
5555

5656
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path
5757
# into which the generated documentation will be written. If a relative path is

src/cannonball.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ clsCannonball::clsCannonball() {
1616
/// * Vel = 0
1717
/////////////////////////////////////////////////
1818

19-
//Put some default values in; on the off chance I forget to set them later
19+
//Put some default values in; on the off chance I forget to set them later.
2020
blnDragEnabled = false;
2121
blnstarted = false;
2222
deltat = (1.00 / 60.00) ;
@@ -39,7 +39,7 @@ clsCannonball::clsCannonball() {
3939
/*****************************************************************************/
4040
void clsCannonball::Drag_calcvalues(void) {
4141
/////////////////////////////////////////////////
42-
/// @brief This will calculate addionational properties of the cannonball based on its radius.
42+
/// @brief This will calculate additional properties of the cannonball based on its radius.
4343
/// These include:
4444
/// * area
4545
/// * volume
@@ -114,13 +114,15 @@ void clsCannonball::update(double newdeltat) {
114114

115115
dblLOC.x = dblLOC.x + vel.x * deltat + 0.5 * acc.x * pow(deltat,2);
116116
vel.x = (vel.x + acc.x * deltat);
117+
//Recoil the ball if it is past an edge
117118
if (dblLOC.x <= 0.0 || dblLOC.x >= window.width - Screen_place.w) {
118119
vel.x *= Global::Physics::fRecoil;
119120
dblLOC.x += dblLOC.x <= 0.0 ? 1.0 : -1.0;
120121
} //end if hitting x edges
121122

122123
dblLOC.y = dblLOC.y + vel.y * deltat + 0.5 * acc.y * pow(deltat,2);
123124
vel.y = (vel.y + acc.y * deltat);
125+
//Recoil the ball if it is past an edge
124126
if (dblLOC.y <= Screen_place.h || dblLOC.y >= window.height) {
125127
vel.y *= Global::Physics::fRecoil;
126128
dblLOC.y += dblLOC.y <= Screen_place.y ? 1.0 : -1.0;
@@ -150,14 +152,15 @@ void clsCannonball::update(double newdeltat) {
150152
else {printf("Ball moving too slow; killing it\n");}
151153
} //end if debug mode
152154
} //end if should kill
153-
show();
155+
show(); //show the ball on the screen
154156
}
155157
/*****************************************************************************/
156158
void clsCannonball::setSDLScreen(SDL_Texture* SDLball,
157159
SDL_Texture* SDLpxel,
158160
WINATT SDLwindow, uint newID) {
159161
/////////////////////////////////////////////////
160-
/// @brief This will set certain values for the ball based on the screen. It will also randomly generate a color for the ball.
162+
/// @brief This will set certain values for the ball based on the screen.
163+
/// It will also randomly generate a color for the ball.
161164
///
162165
/// @param SDLball = Pointer to clsScreen::ball
163166
/// @param SDLpxel = Pointer to clsScreen::pixel
@@ -169,7 +172,6 @@ void clsCannonball::setSDLScreen(SDL_Texture* SDLball,
169172

170173
ballID = newID;
171174
//set the color of the ball
172-
//Set some ID's to have specific colors, but otherwise randomize them
173175
Color.Red = rand() % 255;
174176
Color.Green = rand() % 255;
175177
Color.Blue = rand() % 255;
@@ -218,12 +220,12 @@ void clsCannonball::show() {
218220
void clsCannonball::setValues(double r, LOC init_place,
219221
double init_vel, double init_angle) {
220222
/////////////////////////////////////////////////
221-
/// @brief Changes the values of the ball to whatever is entered
223+
/// @brief Changes the values of the ball to whatever is entered.
222224
///
223-
/// @param r = radius of the ball
224-
/// @param init_place = its starting location
225-
/// @param init_vel = its starting velocity
226-
/// @param init_angle = its starting angle (in radians)
225+
/// @param r = radius of the ball.
226+
/// @param init_place = its starting location.
227+
/// @param init_vel = its starting velocity.
228+
/// @param init_angle = its starting angle (in radians).
227229
/// @return void
228230
///
229231
/////////////////////////////////////////////////

src/cannonball.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
/** This is the max number of points that are recorded and then shown if
1313
Global::Config.values.blnDrawPathOnScreen is true. I had issues of no more than
14-
5 showing up, so 5 is the default value */
14+
5 showing up, so 5 is the default value. */
1515
#define DEFINED_MAXNUMPASTPOINTS 5
1616
/*****************************************************************************/
1717
/** Holds X and Y values that are related together, the values are doubles

src/config.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
#include "version.h"
44
/*****************************************************************************/
55
/*
6-
This holds all the functions related to the config file, its loading, making, and holding the values pulled from the config.
6+
This holds all the functions related to the config file, its loading, making,
7+
and holding the values pulled from the config.
78
*/
89
/*****************************************************************************/
910
clsConfig::clsConfig() {

src/global.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ class clsConfig;
77
/*****************************************************************************/
88
//global typedefs
99
typedef unsigned char uchar;
10-
/**< Rename unsigned char to uchar because I'm lazy */
10+
/**< Rename unsigned char to uchar because I'm lazy. */
1111

1212
typedef unsigned int uint;
13-
/**< Rename unsigned int to uint because I'm lazy */
13+
/**< Rename unsigned int to uint because I'm lazy. */
1414

1515
typedef unsigned long ulong;
16-
/**< Rename unsigned long to ulong because I'm lazy */
16+
/**< Rename unsigned long to ulong because I'm lazy. */
1717

1818
/*****************************************************************************/
1919
//Global namespace

src/main.cpp

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/**< The maximum number of cannonballs allowed. This is because the cannonballs
1313
are stored in an array; but later versions might allow dynamically allocated number.*/
1414

15-
#define DEFINED_USE_R2_VEL_MODDER
15+
//j#define DEFINED_USE_R2_VEL_MODDER
1616
/**< If this is defined, then program will use unrealistic method that will
1717
increase the velocity of two colliding balls the closer they are together
1818
it will reduce the number of times that the balls stick together,
@@ -31,13 +31,13 @@ namespace Cannonballs {
3131
/*****************************************************************************/
3232
/** The method of the collision (I just wanted to play around with some options.) */
3333
enum Collisions {
34-
CollideElastic = 0, /**< This is normal collision in a perfect would without
35-
friction, they hit and bounce off, no energy is lost */
34+
CollideElastic = 0, /**< This is normal collision in a perfect world without
35+
friction, they hit and bounce off, no energy is lost. */
3636
CollideInelastic, /**< This is the normal way things collide, Balls collide and
3737
bounce off of each other losing some energy. */
3838
CollidePerfectInelastic, /**< In this method the balls collide and then
39-
stick together */
40-
CollideNone /**< No collisions */
39+
stick together. */
40+
CollideNone /**< No collisions, balls pass through each other. */
4141
};
4242
/*****************************************************************************/
4343
namespace Global {
@@ -94,13 +94,15 @@ namespace Global {
9494
} //end namespace Global
9595
/*****************************************************************************/
9696
int main(int argc, char *argv[]) {
97-
/** @brief The main function
98-
*
99-
* @param argc = Something required by SDL
100-
* @param argv = Something required by SDL
101-
* @return 0 for successfully ran, or 1 for an error happened.
102-
*
103-
*/
97+
/////////////////////////////////////////////////
98+
/// @brief The main function
99+
///
100+
/// @param argc = Something required by SDL
101+
/// @param argv = Something required by SDL
102+
/// @return 0 for successfully ran, or 1 for an error happened.
103+
///
104+
/////////////////////////////////////////////////
105+
104106

105107
Global::Config.Check(); //Load Config file and all its values.
106108
if (Global::Config.values.blnLogging) { //Open log file to clear it, if it exists
@@ -185,15 +187,16 @@ int main(int argc, char *argv[]) {
185187
}
186188
/*****************************************************************************/
187189
void Cannonballs::addNew(LOC mouseC, LOC mouseO, double HoldTime ) {
188-
/** @brief Will add a new cannonball based on the mouse start and mouse end.
189-
* Mass of the ball will vary based on Hold Time
190-
*
191-
* @param mouseC = Current Mouse Location in X and Y
192-
* @param mouseO = Old (start of mouse click) Mouse Location in X and Y
193-
* @param HoldTime = Time (in seconds) that the mouse button was held down for
194-
* @return void
195-
*
196-
*/
190+
/////////////////////////////////////////////////
191+
/// @brief Will add a new cannonball based on the mouse start and mouse end.
192+
/// Mass of the ball will vary based on Hold Time
193+
///
194+
/// @param mouseC = Current Mouse Location in X and Y
195+
/// @param mouseO = Old (start of mouse click) Mouse Location in X and Y
196+
/// @param HoldTime = Time (in seconds) that the mouse button was held down for
197+
/// @return void
198+
///
199+
/////////////////////////////////////////////////
197200

198201
//Get location, vel, and angle
199202
double fire_v;
@@ -204,7 +207,7 @@ void Cannonballs::addNew(LOC mouseC, LOC mouseO, double HoldTime ) {
204207
fire_v = -1 * sqrt( pow(mouseC.x - mouseO.x, 2) + pow(mouseC.y - mouseO.y, 2) );
205208
fire_v /= (double) Global::Equations::fVelocityScalar;
206209

207-
//if the mouse if pointing straight up or straight down make the angle 90
210+
//If the mouse if pointing straight up or straight down make the angle 90
208211
//Otherwise calculate the angle with atan.
209212
if (mouseC.x == mouseO.x) {
210213
angle = (PI / 2.0) * ( (mouseC.y > mouseO.y) ? -1.0 : 1.0 );
@@ -233,10 +236,10 @@ void Cannonballs::addNew(LOC mouseC, LOC mouseO, double HoldTime ) {
233236
void Cannonballs::checkCollisons(uint j) {
234237

235238
/////////////////////////////////////////////////
236-
/// @brief Checks ball number j is colliding with another ball and then do collisions
239+
/// @brief Checks ball number j is colliding with another ball and then do collisions.
237240
///
238-
/// @param j = the number in the array that ball we are checking is
239-
/// @return void (all changes if they are colliding is handled in this function)
241+
/// @param j = the number in the array that ball we are checking is.
242+
/// @return void (all changes if they are colliding is handled in this function).
240243
///
241244
/////////////////////////////////////////////////
242245

src/screen.cpp

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ clsScreen::clsScreen() {
1010
/// @brief The default constructor for the SDL screen
1111
/// it will try start SDL, and create and window and a renderer,
1212
/// then try to load the textures it will need, if any of these fail
13-
/// it will set bln_SDL_Started to false and return void, when main in main.cpp
14-
/// checks bln_SDL_Started and ends the entire program will it is false.
13+
/// it will set bln_SDL_Started to false and return void, when main in main.cpp it
14+
/// checks bln_SDL_Started and will end the entire program if it is false.
1515
/// If, however, bln_SDL_Started is true it will continue on with the rest of the program.
1616
/////////////////////////////////////////////////
1717

@@ -22,32 +22,41 @@ clsScreen::clsScreen() {
2222
blnBall = blnPixel = false;
2323
bln_SDL_started = false;
2424

25+
//Start SDL
2526
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
27+
//SDL returned a non-zero which means there was an error
2628
bln_SDL_started = false;
2729
error();
2830
return;
2931
} else {
32+
//SDL started without error
3033
bln_SDL_started = true;
3134
if (Global::blnDebugMode) {printf("SDL init successful\n");}
3235
}
3336

37+
//Create the window.
3438
window.win = SDL_CreateWindow("Cannon Simulation",100,100,
3539
window.width, window.height, SDL_WINDOW_SHOWN);
3640

41+
//Check if the window was created properly
3742
if (window.win == nullptr) {
43+
//Window was not created
3844
printf("SDL Failed to create window.\n");
3945
cleanup();
4046
error();
4147
bln_SDL_started = false;
4248
return;
4349
} else {
50+
//Window was created
4451
blnWindow = true;
4552
if (Global::blnDebugMode) {printf("Window creation successful\n");}
4653
}
4754

55+
//Try to create the renderer
4856
window.ren = SDL_CreateRenderer(window.win, -1,
4957
SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
5058

59+
//Check if renderer was created.
5160
if (window.ren == nullptr) {
5261
printf("SDL Failed to create renderer.\n");
5362
cleanup();
@@ -59,9 +68,10 @@ clsScreen::clsScreen() {
5968
if (Global::blnDebugMode) {printf("Renderer creation successful\n");}
6069
}
6170

62-
//Set the background color of the render to black
71+
//Set the background color of the renderer to black
6372
SDL_SetRenderDrawColor(window.ren, 0x00, 0x00, 0x00, 0xFF );
6473

74+
//Load the ball texture
6575
ball = loadIMG("ball");
6676
if (bln_SDL_started == false) {return;}
6777
else {
@@ -71,14 +81,15 @@ clsScreen::clsScreen() {
7181
SDL_SetTextureBlendMode(ball, SDL_BLENDMODE_BLEND );
7282
}
7383

84+
//Load the pixel texture
7485
pixel = loadIMG("pixel");
7586
if (bln_SDL_started == false) {return;}
7687
else {
7788
blnPixel = true;
7889
if (Global::blnDebugMode) {printf("Pixel loading successful\n");}
7990
}
8091

81-
}
92+
} //end of constructor
8293
/*****************************************************************************/
8394
clsScreen::~clsScreen() {
8495
/////////////////////////////////////////////////
@@ -129,10 +140,11 @@ void clsScreen::cleanup() {
129140
blnBall = false;
130141
if (Global::blnDebugMode) {printf("Ball texture destroyed\n");}
131142
}
132-
if (blnBall) {
143+
144+
if (blnPixel) {
133145
SDL_DestroyTexture(pixel);
134146
blnPixel = false;
135-
if (Global::blnDebugMode) {printf("Ball texture destroyed\n");}
147+
if (Global::blnDebugMode) {printf("Pixel texture destroyed\n");}
136148
}
137149
if (blnRenderer) {
138150
SDL_DestroyRenderer(window.ren);
@@ -160,11 +172,13 @@ SDL_Texture* clsScreen::loadIMG(std::string filename) {
160172
/////////////////////////////////////////////////
161173
/// @brief Will load a specified image into a texture.
162174
/// It will first load it from the XPM array that it is embedded as into a surface,
163-
/// then will will convert the surface into a texture, if that fails it will set bln_SDL_started to false
175+
/// then will will convert the surface into a texture, if that fails
176+
/// it will set bln_SDL_started to false
164177
/// and return nullptr, otherwise returns texture.
165178
///
166-
/// @param filename = The texture to load (currently only supports "ball" or "pixel" as those are the only two textures needed)
167-
/// @return Pointer to the texture in memory
179+
/// @param filename = The texture to load (currently only supports "ball"
180+
/// or "pixel" as those are the only two textures needed).
181+
/// @return Pointer to the texture in memory.
168182
/////////////////////////////////////////////////
169183

170184
SDL_Surface* temp;

0 commit comments

Comments
 (0)