Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
NetWorld
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LAIRD Timothy
NetWorld
Commits
4afeeea5
Commit
4afeeea5
authored
Apr 29, 2021
by
ewen.madec
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix memory leak
parent
2d0a1477
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
28 additions
and
45 deletions
+28
-45
main-viewer.c
src/main-viewer.c
+5
-3
mission.c
src/mission.c
+8
-6
mission.h
src/mission.h
+2
-2
networld.c
src/networld.c
+4
-12
networld.h
src/networld.h
+1
-8
player.c
src/player.c
+3
-8
random-map.c
src/random-map.c
+5
-6
No files found.
src/main-viewer.c
View file @
4afeeea5
...
...
@@ -161,16 +161,18 @@ int main(int nbArg, char ** arg)
// proper closing
//---------------
NetWorld_delete
(
world
);
Players_delete
(
players
,
playerCount
);
Mission_delete
(
missions
);
Mission_deleteArray
(
missions
,
playerCount
);
NetWorld_delete
(
world
);
Main_Menu_delete
(
menu
);
Main_Menu_delete
(
rulesMenu
);
Menu_Button_delete
(
gameReturn
);
Options_Menu_delete
(
optionsMenu
);
Window_Manager_delete
(
manager
);
Panel_delete
(
panel
);
UnloadFont
(
gameFont
);
CloseWindow
();
// Close window and OpenGL context
return
0
;
...
...
src/mission.c
View file @
4afeeea5
...
...
@@ -11,8 +11,7 @@ bool Player_eliminated(NetWorld * world, Player * players, const int playerID, c
}
Mission
*
Mission_init
(
const
int
playerID
,
NetWorld
*
world
){
Mission
*
self
=
malloc
(
sizeof
(
Mission
));
void
Mission_init
(
Mission
*
self
,
const
int
playerID
,
NetWorld
*
world
){
char
*
displayText
=
malloc
(
sizeof
(
char
)
*
50
);
self
->
playerID
=
playerID
;
...
...
@@ -34,13 +33,13 @@ Mission * Mission_init(const int playerID, NetWorld * world){
self
->
displayText
=
displayText
;
break
;
}
return
self
;
//
return self;
}
Mission
*
Mission_newArray
(
const
int
playerCount
,
NetWorld
*
world
){
Mission
*
missionArray
=
malloc
(
sizeof
(
Mission
)
*
playerCount
);
for
(
int
i
=
0
;
i
<
playerCount
;
i
++
){
missionArray
[
i
]
=
*
Mission_init
(
i
,
world
);
Mission_init
((
missionArray
+
i
),
i
,
world
);
}
return
missionArray
;
}
...
...
@@ -51,6 +50,9 @@ bool Mission_check(Mission * self, NetWorld * world, Player * players){
return
self
->
mission
(
world
,
players
,
self
->
playerID
,
self
->
target
);
}
void
Mission_delete
(
Mission
*
self
){
free
(
self
);
void
Mission_deleteArray
(
Mission
*
array
,
int
playerCount
){
for
(
int
i
=
0
;
i
<
playerCount
;
i
++
){
free
((
array
+
i
)
->
displayText
);
}
free
(
array
);
}
\ No newline at end of file
src/mission.h
View file @
4afeeea5
...
...
@@ -13,11 +13,11 @@ struct Str_Mission{
typedef
struct
Str_Mission
Mission
;
Mission
*
Mission_init
(
const
int
playerID
,
NetWorld
*
world
);
void
Mission_init
(
Mission
*
self
,
const
int
playerID
,
NetWorld
*
world
);
bool
Mission_check
(
Mission
*
self
,
NetWorld
*
world
,
Player
*
players
);
void
Mission_delete
(
Mission
*
self
);
void
Mission_delete
Array
(
Mission
*
array
,
int
playerCount
);
Mission
*
Mission_newArray
(
const
int
playerCount
,
NetWorld
*
world
);
...
...
src/networld.c
View file @
4afeeea5
...
...
@@ -12,18 +12,14 @@
// Constructor / Destructor
void
Node_construct
(
Node
*
self
)
{
Node_set
(
self
,
(
Vector2
){
0
.
f
,
0
.
f
},
GRAY
,
""
);
Node_set
(
self
,
(
Vector2
){
0
.
f
,
0
.
f
},
GRAY
);
self
->
card
=
0
;
self
->
edges
=
Edge_newArray
(
0
);
self
->
name
=
malloc
(
sizeof
(
char
)
*
32
);
self
->
continent
=
malloc
(
sizeof
(
char
)
*
32
);
self
->
soldiers
=
1
;
self
->
soldiersToAdd
=
0
;
self
->
playerID
=
-
1
;
Rectangle
tmp
=
{
0
,
0
,
48
,
48
};
self
->
collisionHitbox
=
tmp
;
self
->
continent
=
"None"
;
self
->
name
=
"Node"
;
self
->
canAttack
=
true
;
}
...
...
@@ -47,10 +43,7 @@ Node * Node_newArray(int size)
void
Node_delete
(
Node
*
node
)
{
free
(
node
->
continent
);
free
(
node
->
name
);
Edge_deleteArray
(
node
->
card
,
node
->
edges
);
free
(
node
);
}
/**
...
...
@@ -58,9 +51,9 @@ void Node_delete( Node * node )
*/
void
Node_deleteArray
(
int
n
,
Node
*
array
)
{
for
(
int
i
=
0
;
i
<
n
;
++
i
)
for
(
int
i
=
0
;
i
<
n
;
++
i
)
{
Node_delete
((
array
+
i
));
//Edge_deleteArray( array[i].card, array[i].edges );
}
free
(
array
);
}
...
...
@@ -93,11 +86,10 @@ void Node_resize( Node * self, int card )
self
->
card
=
card
;
}
void
Node_set
(
Node
*
self
,
Vector2
position
,
Color
color
,
char
*
name
)
void
Node_set
(
Node
*
self
,
Vector2
position
,
Color
color
)
{
self
->
position
=
position
;
self
->
color
=
color
;
self
->
name
=
name
;
}
int
Node_connect
(
Node
*
self
,
Node
*
target
)
...
...
src/networld.h
View file @
4afeeea5
...
...
@@ -18,14 +18,10 @@ struct Str_Node {
//! cardinality of the node (i.e. number of edges)
int
card
;
// Content:
//! name of the node
char
*
name
;
//! Number of soldiers at the node
int
soldiers
;
//! Buffer variable to stop players from removing soldiers from their nodes
int
soldiersToAdd
;
//! Continent the node belongs to
char
*
continent
;
//! Player the node belongs to
int
playerID
;
//! Click hitbox for the node
...
...
@@ -110,10 +106,7 @@ void Node_set(
//! position
Vector2
position
,
//! color
Color
color
,
//!
char
*
name
Color
color
);
/**
...
...
src/player.c
View file @
4afeeea5
...
...
@@ -36,8 +36,8 @@ Player * Player_newArray(int size, Color color[])
void
Players_delete
(
Player
*
player
,
int
size
)
{
for
(
int
i
=
0
;
i
<
size
;
i
++
){
free
((
player
+
i
)
->
nodes
);
free
((
player
+
i
)
->
selectedNode
);
//
free((player+i)->nodes);
//
free((player+i)->selectedNode);
}
free
(
player
);
}
...
...
@@ -56,6 +56,7 @@ void Player_add_Node( Player * self, Node * node )
node
->
playerID
=
self
->
ID
;
newNodes
[
self
->
nodeCount
]
=
node
;
free
(
self
->
nodes
);
self
->
nodes
=
NULL
;
self
->
nodes
=
newNodes
;
self
->
nodeCount
+=
1
;
}
...
...
@@ -161,9 +162,6 @@ int * Player_attack_Node(Player * self, Player * defender, Node * originNode, No
int
attDiceRolls
[
attackersCount
];
int
defDiceRolls
[
defendersCount
];
printf
(
"%i attackers
\n
"
,
attackersCount
);
printf
(
"%i defenders
\n
"
,
defendersCount
);
for
(
int
index
=
0
;
index
<
attackersCount
;
index
++
){
attDiceRolls
[
index
]
=
(
rand
()
%
6
)
+
1
;
}
...
...
@@ -230,9 +228,6 @@ int * Player_attack_Node(Player * self, Player * defender, Node * originNode, No
}
originNode
->
canAttack
=
false
;
for
(
int
i
=
0
;
i
<
defendersCount
+
attackersCount
;
i
++
){
printf
(
"listOfdices2 [%d] : %d
\n
"
,
i
,
listOfDices
[
i
]);
}
return
listOfDices
;
}
...
...
src/random-map.c
View file @
4afeeea5
...
...
@@ -63,17 +63,16 @@ void Random_map(NetWorld *world)
}
}
}
c
har
*
name
;
name
=
malloc
(
20
*
sizeof
(
char
));
sprintf
(
name
,
"name : %d"
,
i
);
Node_set
(
&
(
world
->
nodes
[
i
]),
(
Vector2
){
randomX
,
randomY
},
RED
,
name
);
free
(
name
);
//
har *name; name = malloc(20*sizeof(char)); sprintf(name, "name : %d", i);
Node_set
(
&
(
world
->
nodes
[
i
]),
(
Vector2
){
randomX
,
randomY
},
RED
);
//
free(name);
}
else
{
randomX
=
randfrom
(
-
15
.
0
,
15
.
0
);
randomY
=
randfrom
(
-
15
.
0
,
15
.
0
);
char
*
name
;
name
=
malloc
(
20
*
sizeof
(
char
));
sprintf
(
name
,
"name : %d"
,
i
);
Node_set
(
&
(
world
->
nodes
[
i
]),
(
Vector2
){
randomX
,
randomY
},
RED
,
name
);
free
(
name
);
//char name[20]; sprintf(name, "name : %d", i);
Node_set
(
&
(
world
->
nodes
[
i
]),
(
Vector2
){
randomX
,
randomY
},
RED
);
}
}
//Gabriel graph sort
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment