Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
APO_sem
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pelech, Ondřej
APO_sem
Commits
7d490e19
Commit
7d490e19
authored
1 year ago
by
phamthit
Browse files
Options
Downloads
Patches
Plain Diff
Add freeing objects at the end of the program
parent
89ce5366
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
main/draw.c
+6
-0
6 additions, 0 deletions
main/draw.c
main/draw.h
+8
-0
8 additions, 0 deletions
main/draw.h
main/enemy.h
+2
-0
2 additions, 0 deletions
main/enemy.h
main/main.c
+37
-6
37 additions, 6 deletions
main/main.c
with
53 additions
and
6 deletions
main/draw.c
+
6
−
0
View file @
7d490e19
...
...
@@ -67,6 +67,7 @@ int16_t frame_buffer_init(struct frame_buffer* self, FBUF_DTYPE h, FBUF_DTYPE w)
self
->
color_background
=
color_background
;
self
->
null_buffer
=
null_buffer
;
self
->
draw_letter
=
draw_letter
;
self
->
free
=
free_buffer
;
info
(
"draw.c : FRAME BUFFER INIT DONE"
);
}
...
...
@@ -421,6 +422,11 @@ void multiply_letter(uint16_t ret_buffer[],uint16_t buffer[],const uint16_t widt
}
}
void
free_buffer
(
struct
frame_buffer
*
self
)
{
free
(
self
->
buffer
);
free
(
self
);
}
/*
Picture canvas
...
...
This diff is collapsed.
Click to expand it.
main/draw.h
+
8
−
0
View file @
7d490e19
...
...
@@ -99,6 +99,9 @@ typedef struct frame_buffer{
// Method mull_buffer
int16_t
(
*
null_buffer
)(
struct
frame_buffer
*
self
);
// frees buffer
void
(
*
free
)(
struct
frame_buffer
*
self
);
}
frame_buffer_t
;
...
...
@@ -180,4 +183,9 @@ void multiply_buffer(uint16_t ret_buffer[],uint16_t buffer[],const uint16_t pict
**/
void
multiply_letter
(
uint16_t
ret_buffer
[],
uint16_t
buffer
[],
const
uint16_t
width
,
const
uint16_t
height
,
uint16_t
multipliactor
);
/**
* frees buffer struct
**/
void
free_buffer
(
struct
frame_buffer
*
self
);
#endif
This diff is collapsed.
Click to expand it.
main/enemy.h
+
2
−
0
View file @
7d490e19
...
...
@@ -21,6 +21,8 @@
//defalut enemy cooldown
#define ENEMY_COOLDOWN 200
#define ENEMY_DISTANCE 70
#endif
...
...
This diff is collapsed.
Click to expand it.
main/main.c
+
37
−
6
View file @
7d490e19
...
...
@@ -77,14 +77,15 @@ int main(int argc, char *argv[]) {
void
*
spiled_base
=
map_phys_address
(
SPILED_REG_BASE_PHYS
,
SPILED_REG_SIZE
,
0
);
// ENEMIES
int
row
=
3
;
int
col
=
7
;
int
enemy_row
=
3
;
int
enemy_col
=
7
;
int
max_enemies
=
enemy_row
*
enemy_col
;
enemy_t
**
enemies
=
my_malloc
(
30
*
sizeof
(
enemy_t
*
));
enemy_t
**
enemies
=
my_malloc
(
max_enemies
*
sizeof
(
enemy_t
*
));
int
num_enemy
=
0
;
for
(
int
i
=
0
;
i
<
row
;
i
++
)
{
for
(
int
j
=
0
;
j
<
col
;
j
++
)
{
enemies
[
num_enemy
]
=
get_enemy
(
j
*
70
,
i
*
DEFAULT_PICTURE_SIZE
*
3
,
3
);
// set the enemy distance
for
(
int
i
=
0
;
i
<
enemy_
row
;
i
++
)
{
for
(
int
j
=
0
;
j
<
enemy_
col
;
j
++
)
{
enemies
[
num_enemy
]
=
get_enemy
(
j
*
ENEMY_DISTANCE
,
i
*
DEFAULT_PICTURE_SIZE
*
3
,
3
);
// set the enemy distance
num_enemy
++
;
}
}
...
...
@@ -122,6 +123,9 @@ int main(int argc, char *argv[]) {
player
->
draw
(
player
,
frame_buffer
);
update_health_rgb1
(
spiled_base
,
player
->
max_hp
,
player
->
hp
);
if
(
player
->
hp
<=
0
||
player
->
ammo
<
10
)
{
break
;
}
for
(
int
i
=
0
;
i
<
num_enemy
;
i
++
)
{
enemy_t
*
enemy
=
enemies
[
i
];
...
...
@@ -191,6 +195,33 @@ int main(int argc, char *argv[]) {
frame_buffer
->
null_buffer
(
frame_buffer
);
}
// FREE OBJECTS
info
(
"free"
);
debug
(
"free projectiles"
);
for
(
int
i
=
0
;
i
<
max_projectiles
;
i
++
)
{
if
(
projectiles
[
i
]
!=
NULL
)
projectiles
[
i
]
->
free
(
projectiles
[
i
]);
}
free
(
projectiles
);
debug
(
"free enemies"
);
for
(
int
i
=
0
;
i
<
num_enemy
;
i
++
)
{
printf
(
"%d
\n
"
,
i
);
if
(
enemies
[
i
]
!=
NULL
)
enemies
[
i
]
->
free
(
enemies
[
i
]);
}
free
(
enemies
);
debug
(
"free obstacles"
);
for
(
int
i
=
0
;
i
<
max_obstacles
;
i
++
)
{
if
(
obstacles
[
i
]
!=
NULL
)
obstacles
[
i
]
->
free
(
obstacles
[
i
]);
}
free
(
obstacles
);
debug
(
"free player"
);
player
->
free
(
player
);
debug
(
"free buffer"
);
frame_buffer
->
free
(
frame_buffer
);
printf
(
"Goodbye world
\n
"
);
serialize_unlock
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment