Commit b0598b21 authored by Guillaume Lozenguez's avatar Guillaume Lozenguez

merge from dev

parents 8593c4e8 fb1f6986
......@@ -2,6 +2,8 @@
build
raylib
doc/html
.vscode/
# Generated files:
......
......@@ -11,14 +11,15 @@ set(CMAKE_CXX_FLAGS_RELEASE_INIT "-Wall")
include_directories(${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/src)
# RayLib:
find_package(raylib 2.6 REQUIRED)
#find_package(raylib 3.0 REQUIRED)
#set(raylib_VERBOSE 1)
add_executable(nw-hello src/main-hello.c)
target_link_libraries(nw-hello raylib)
# Local dependency: (RayLib) :
include_directories( ${PROJECT_SOURCE_DIR}/dpd/include )
link_directories( ${PROJECT_SOURCE_DIR}/dpd )
add_executable(nw-viewer src/main-viewer.c src/networld.c)
target_link_libraries(nw-viewer raylib)
add_executable(nw-viewer src/main-viewer.c src/networld.c src/controlpanel.c src/entity.c)
target_link_libraries(nw-viewer raylib pthread dl rt X11 m)
#without cmake package...
#include_directories(${PROJECT_SOURCE_DIR}/raylib/src)
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -23,3 +23,7 @@ windows:
clean:
@make -C src clean
docs:
@doxygen Doxyfile
......@@ -9,8 +9,8 @@ La particularité du projet est de modéliser le monde comme un réseau de posit
Projet conçu pour une compilation avec GCC et la librairie Raylib. De par la nature de la procédure d'installation et de linkage, Linux est le système d'exploitation à préférer.
⚠️ Bien prendre le temps de lire la section d'installation qui vous concerne ⚠️
⚠️ Bien prendre le temps de lire la section d'installation qui vous concerne ⚠️
### Linux (Debian based, *e.g.* Ubuntu) - Fortement recommandé
---
......@@ -156,7 +156,6 @@ Et voilà !
## Organisation du répertoire
Répertoire:
......
#!/bin/bash
if [ ! -d "build" ];then
mkdir build
fi
cd build
cmake ..
make
# Outputs
cp nw-viewer ..
#!/bin/bash
# Dependencies:
sudo apt update
sudo apt install -y build-essential git cmake
sudo apt install -y libasound2-dev mesa-common-dev \
libx11-dev libxrandr-dev libxi-dev xorg-dev \
libgl1-mesa-dev libglu1-mesa-dev
# Raylib:
git clone https://github.com/raysan5/raylib.git raylib
cd raylib
git checkout '3.0.0'
mkdir build && cd build
cmake -DSHARED=ON -DSTATIC=ON ..
make
sudo make install
cd ..
# NetWorld:
bin/build
\ No newline at end of file
# NetWorld - Documentation
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
File added
```mermaid
graph TD;
Antho-->Bobby;
Antho-->Clariss;
Bobby-->Dede;
Clariss-->Dede;
```
## ToDo :
- Inclure IGraph
......@@ -31,8 +31,8 @@ This functionality cover a framework for the team of developers.
NetWorld represent the center piece of the game engine. It is the programme component that glue all the others.
It is an environment for the game entities, viewed as a planar graph modelling all the possible movements.
- A NetWorld is composed of nodes at specific position (x,y).
- Nodes are connected to other with edges.
- A NetWorld is composed of nodes at specific position (x,y). **DONE**
- Nodes are connected to other with edges. **DONE**
- Nodes can contain entities.
- It is possible to generate NetWorld randomly (example: random nodes and Gabriel graph).
- An algorithm provides paths in the NetWorld between two positions (A*).
......@@ -105,4 +105,7 @@ The goal here is to distribute the game process.
## Fct.7 - Tanks
Nodes are defined with a collection of tanks where resources can be placed. (water for instance)
Nodes are defined with a collection of digital tanks where resources can be placed. (water for instance)
- Digit represent a discrete value in a fixed capacity tank.
- Node contain a collection of tanks as Digit.
#include "controlpanel.h"
#include "raylib.h"
#include "raymath.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
// Tools
void printVector2( Vector2 v )
{
printf( "[%3f, %3f]", v.x, v.y );
}
// Constructor / Destructor
Panel * Panel_new()
{
Panel * p = malloc( sizeof(Panel) );
return p;
}
void Panel_delete(Panel * self)
{
free(self);
}
// Initialization
void Panel_initialize(Panel * self, NetWorld * world)
{
self->world= world;
self->camera.x= 0.f;
self->camera.y= 0.f;
self->screenCenter.x= 400.f;
self->screenCenter.y= 300.f;
self->scale= 10.f; //pixel per meters
}
// To String
void Panel_print(Panel * self)
{
printf( "Panel camera(x-%f, y-%f, scale-%f)\n",
self->camera.x,
self->camera.y,
self->scale);
}
// Rendering
void Panel_draw(Panel * self)
{
BeginDrawing();
ClearBackground(RAYWHITE);
// Draw the edges for each nodes:
for(int i= 0 ; i < self->world->size ; ++i )
{
Node * n= &(self->world->nodes[i]);
for(int j= 0 ; j < n->card ; ++j )
Panel_drawEdge( self, &(n->edges[j]) );
}
// Draw the nodes
for(int i= 0 ; i < self->world->size ; ++i )
{
Panel_drawNode( self, &(self->world->nodes[i]) );
}
Panel_drawBasis(self);
EndDrawing();
}
void Panel_drawBasis(Panel * self)
{
Vector2 screen00= {0.f, 0.f};
screen00= Panel_pixelFromPosition(self, &( screen00 ) );
Vector2 screen10= {1.f, 0.f};
screen10= Panel_pixelFromPosition(self, &( screen10 ) );
Vector2 screen01= {0.f, 1.f};
screen01= Panel_pixelFromPosition(self, &( screen01 ) );
DrawCircleV( screen00, 4, BLUE );
DrawLineV( screen00, screen10, RED );
DrawLineV( screen00, screen01, BLUE );
}
void Panel_drawNode(Panel * self, Node * n)
{
Vector2 screenPosition= Panel_pixelFromPosition(self, &(n->position) );
DrawCircleV(screenPosition, 24, n->color);
DrawCircleV(screenPosition, 20, RAYWHITE);
DrawText(n->name, (int)(screenPosition.x), (int)(screenPosition.y), 20, n->color);
}
void Panel_drawEdge(Panel * self, Edge * e)
{
Vector2 source= Panel_pixelFromPosition(self, &(e->_source->position) );
Vector2 target= Panel_pixelFromPosition(self, &(e->_target->position) );
Vector2 ortho= (Vector2){ target.x-source.x, target.y-source.y }; // Vector from Source to Target
float ratio= 10.f / Vector2Length( ortho );
ortho= (Vector2){ -ortho.y*ratio, ortho.x*ratio };// 10 ortho-normal vector from v
Vector2 source1= (Vector2){source.x-ortho.x, source.y-ortho.y};
Vector2 source2= (Vector2){source.x+ortho.x, source.y+ortho.y};
DrawTriangle(source1, source2, target, e->color);
}
Vector2 Panel_pixelFromPosition(Panel * self, Vector2 * p)
{
Vector2 pixel= {
self->screenCenter.x + (p->x - self->camera.x ) * self->scale,
self->screenCenter.y - (p->y - self->camera.y ) * self->scale
};
return pixel;
}
Vector2 Panel_positionFromPixel(Panel * self, Vector2 * p)
{
Vector2 position= { p->x, p->y };
return position;
}
void Panel_control(Panel * self)
{
Panel_controlCamera(self);
}
void Panel_controlCamera(Panel * self)
{
// KEYBOARD Control:
float step= 3.0f / self->scale;
if (IsKeyDown(KEY_RIGHT)) self->camera.x += step;
if (IsKeyDown(KEY_LEFT)) self->camera.x -= step;
if (IsKeyDown(KEY_UP)) self->camera.y += step;
if (IsKeyDown(KEY_DOWN)) self->camera.y -= step;
self->scale += (GetMouseWheelMove()*1.f);
self->scale = fmaxf( self->scale, 0.001f );
}
\ No newline at end of file
#ifndef CONTROLPANEL_H
#define CONTROLPANEL_H
#include "networld.h"
// Tools
void printVector2( Vector2 v );
//-----------------------------------//
//-- Cotrol Panel --//
//-----------------------------------//
struct Str_Panel {
Vector2 camera, screenCenter;
float scale; // meter per pixel
NetWorld * world;
};
typedef struct Str_Panel Panel;
// Constructor / Destructor
Panel * Panel_new();
void Panel_delete(Panel * self);
// Initialization
void Panel_initialize(Panel * self, NetWorld * world);
// To String
void Panel_print(Panel * self);
// Rendering
void Panel_draw(Panel * self);
void Panel_drawBasis(Panel * self);
void Panel_drawNode(Panel * self, Node * n);
void Panel_drawEdge(Panel * self, Edge * e);
Vector2 Panel_pixelFromPosition(Panel * self, Vector2 * p);
Vector2 Panel_positionFromPixel(Panel * self, Vector2 * p);
// Control
void Panel_control(Panel * self);
void Panel_controlCamera(Panel * self);
#endif //CONTROLPANEL_H
\ No newline at end of file
#include "entity.h"
#ifndef ENTITY_H
#define ENTITY_H
#include "raylib.h"
//-----------------------------------//
//-- Entity Descriptor --//
//-----------------------------------//
struct Str_EntityDsc {
Color color;
};
typedef struct Str_EntityDsc EntityDsc;
struct Str_Entity {
//! Owner of the Entity (classically the player Id)
int owner;
EntityDsc descriptor;
};
typedef struct Str_Entity Entity;
#endif // ENTITY_H
\ No newline at end of file
......@@ -5,19 +5,21 @@
*
********************************************************************************************/
#include "networld.h"
#include "raylib.h"
#include <stdlib.h>
#include <stdio.h>
#include "networld.h"
#include "controlpanel.h"
// Program attributes
//-------------------
const int screenWidth = 800;
const int screenHeight = 450;
const int screenHeight = 600;
const int targetFPS = 60;
void game_update(NetWorld * world);
void game_draw(NetWorld * world);
// Game attributes
//-----------------
......@@ -29,9 +31,16 @@ int main(int nbArg, char ** arg)
//--------------------
game_end= false;
NetWorld * world= NetWorld_new(3);
NetWorld_initNodePosition( world, 0, 10.4, 12.8 );
NetWorld_initNodePosition( world, 1, 110.4, 52.8 );
NetWorld_initNodePosition( world, 2, 384.5, 422.2 );
Node_set( &(world->nodes[0]), (Vector2){1.4f, 1.28f}, RED );
Node_set( &(world->nodes[1]), (Vector2){21.0f, 22.8f}, MAGENTA );
Node_set( &(world->nodes[2]), (Vector2){18.4f, -12.2f}, GRAY );
NetWorld_connect(world, 0, 1);
NetWorld_connect(world, 1, 2);
NetWorld_biconnect(world, 2, 0);
Panel * panel= Panel_new();
Panel_initialize(panel, world);
// Raylib Initialization
//----------------------
......@@ -43,12 +52,17 @@ int main(int nbArg, char ** arg)
puts("world variable:");
NetWorld_print(world);
puts("world expected:\n[10.4, 12.8]\n[110.4, 52.8]\n[384.5, 422.2]");
Panel_print(panel);
Vector2 position= {1.f, 1.f};
position= Panel_pixelFromPosition( panel, &position );
printf("[%.2f,%.2f]\n", position.x, position.y);
// Main game loop
while (!game_end && !WindowShouldClose()) // Detect window close button or ESC key
{
Panel_control(panel);
game_update(world);
game_draw(world);
Panel_draw(panel);
}
// proper closing
......@@ -63,15 +77,3 @@ void game_update(NetWorld * world)
{
}
void game_draw(NetWorld * world)
{
BeginDrawing();
ClearBackground(RAYWHITE);
for(int i= 0 ; i < world->size ; ++i )
{
Vector2 nodePosition= { world->nodes[i].x, world->nodes[i].y };
DrawCircleV(nodePosition, 24, MAROON);
}
EndDrawing();
}
#include "networld.h"
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <math.h>
#include <string.h>
//-----------------------------------//
//-- Node --//
//-----------------------------------//
// Constructor / Destructor
void Node_construct(Node * self)
{
Node_set( self, (Vector2){0.f, 0.f}, GRAY );
self->card= 0;
self->edges= Edge_newArray( 0 );
self->name= malloc( sizeof(char)*32 );
strcpy( self->name, "Node" );
}
Node * Node_new()
{
Node * p= malloc( sizeof(Node) );
Node_construct(p);
return p;
}
Node * Node_newArray(int size)
{
size= fmaxf(1, size);
Node * p= malloc( sizeof(Node)*size );
for(int i=0 ; i < size ; ++i )
{
Node_construct( &(p[i]) );
}
return p;
}
void Node_delete( Node * node )
{
Edge_deleteArray( node->card, node->edges );
free( node );
}
/**
* @brief Destructor of an array of nodes.
*/
void Node_deleteArray( int n, Node * array )
{
for(int i= 0 ; i < n ; ++i )
Edge_deleteArray( array[i].card, array[i].edges );
free( array );
}
/**
* @brief initialize a node with a number of edges
*/
void Node_initialize( Node * self, int card )
{
for(int i= 0 ; i < self->card ; ++i )
Edge_deleteArray( self->card, self->edges );
self->edges= Edge_newArray( card );
self->card= card;
}
/**
* @brief Resize
*/
void Node_resize( Node * self, int card )
{
Edge * newEdges= Edge_newArray(card);
int minCard= fminf(self->card, card);
for( int i = 0 ; i < minCard ; ++i )
{
Edge_copy( &newEdges[i], &(self->edges[i]) );
}
Edge_deleteArray( self->card, self->edges );
self->edges= newEdges;
self->card= card;
}
void Node_set( Node * self, Vector2 position, Color color )
{
self->position= position;
self->color= color;
}
int Node_connect( Node * self, Node * target )
{
int i= self->card;
Node_resize( self, i+1 );
self->edges[i]._source= self;
self->edges[i]._target= target;
self->edges[i].color= self->color;
self->edges[i]._twin= NULL;
return i;
}
int Node_biconnect( Node * node1, Node * node2 )
{
int i1= Node_connect(node1, node2);
int i2= Node_connect(node2, node1);
node1->edges[i1]._twin= &(node2->edges[i2]);
node2->edges[i2]._twin= &(node1->edges[i1]);
return i1;
}
//-----------------------------------//
//-- Edge --//
//-----------------------------------//
// Constructor / Destructor
void Edge_construct( Edge * self, Node * source, Node * target )
{
self->_source= source;
self->_target= target;
self->_twin= NULL;
self->color= GRAY;
}
Edge * Edge_new( Node * source, Node * target )
{
Edge * p = malloc( sizeof(Edge) );
Edge_construct( p, source, target );
return p;
}
/**
* @brief Destructor.
*/
void Edge_delete( Edge * self )
{
free( self );
}
/**
* @brief Allocate 'size' Edges (with NULL target)
* @return The pointer to the new array of 'size' Edges.
*/
Edge * Edge_newArray(int size)
{
size= fmaxf(1, size);
Edge * p = malloc( sizeof(Edge)*size );
for( int i = 0 ; i < size ; ++i )
{
Edge_construct( &(p[i]), NULL, NULL );
}
return p;
}
/**
* @brief Destructor.
*/
void Edge_deleteArray( int n, Edge * array )
{
free(array);
}
/**
* @brief Copy an edge from another
*/
void Edge_copy( Edge * copy, Edge * model )
{
copy->_source= model->_source;
copy->_target= model->_target;
copy->_twin= model->_twin;
}
//-----------------------------------//
//-- NetWorld --//
//-----------------------------------//
// Constructor / Destructor
NetWorld * NetWorld_new(int size)
{
NetWorld * p = malloc( sizeof(NetWorld) );
p->size= size;
p->nodes= malloc( p->size * sizeof(Node) );
p->nodes= Node_newArray( p->size );
return p;
}
void NetWorld_delete(NetWorld * self)
{
free( self->nodes );
Node_deleteArray( self->size, self->nodes );
free( self );
}
// Initialization
void NetWorld_initNodePosition(
NetWorld * self, int iNode,
double x, double y)
{
self->nodes[iNode].x= x;
self->nodes[iNode].y= y;
}
// To String
void NetWorld_print(NetWorld * self)
{
for(int i= 0 ; i < self->size ; ++i )
printf("[%lf, %lf]\n", self->nodes[i].x, self->nodes[i].y);
printf("[%.2f, %.2f]%d\n",
self->nodes[i].position.x,
self->nodes[i].position.y,
self->nodes[i].card);
}
// Managment :
int NetWorld_connect( NetWorld * self, int source, int target )
{
return Node_connect( &(self->nodes[source]), &(self->nodes[target]) );
}
int NetWorld_biconnect( NetWorld * self, int source, int target )
{
return Node_biconnect( &(self->nodes[source]), &(self->nodes[target]) );
}
#ifndef NETWORLD_H
#define NETWORLD_H
#include "raylib.h"
//-----------------------------------//
//-- Node --//
//-----------------------------------//
struct Str_Edge;
struct Str_Node {
double x, y;
//! position (x, y) of the node
Vector2 position;
//! color (r, g, b, a) of the node
Color color;
struct Str_Edge * edges;
//! cardinality of the node (i.e. number of edges)
int card;
// Content:
//! name of the node
char* name;
};
/**
* @brief NetWorld Node.
*/
typedef struct Str_Node Node;
// Constructor / Destructor
/**
* @brief Construc all the element of an empty Node.
* @param self an empty Node ot yet constructed.
* @return The pointer to the new NetWorld.
*/
void Node_construct(Node * self);
/**
* @brief Allocate the memory to store a Node
* @return The pointer to the new NetWorld.
*/
Node * Node_new();
/**
* @brief Allocate 'size' Nodes.
* @return The pointer to the new array of 'size' Nodes.
*/
Node * Node_newArray(int size);
/**
* @brief Destructor.
*/
void Node_delete(
//! the NetWorld to delete
Node * self
);
/**
* @brief Destructor of an array of nodes.
*/
void Node_deleteArray(
//! the number of nodes to delete
int n,
//! the Nodes
Node * array
);
/**
* @brief initialize a node with a number of edges
*/
void Node_initialize(
//! the node to initialize
Node * self,
//! the number of outgoing edges
int card
);
/**
* @brief Resize
*/
void Node_resize(
//! the node to resize
Node * self,
//! the new number of outgoing edges
int card
);
// Managment :
/**
* @brief set
*/
void Node_set(
//! the node to set
Node * self,
//! position
Vector2 position,
//! color
Color color
);
/**
* @brief connect tow node together
* @return the index of the edge in the node edges' array
*/
int Node_connect(
//! the source Node to modify
Node * self,
//! the target node
Node * target
);
/**
* @brief connect tow node together (bidirectional)
* @return the index of the edge in the node edges' array
*/
int Node_biconnect(
//! the source Node to modify
Node * node1,
//! the target node
Node * node2
);
//-----------------------------------//
//-- Edge --//
//-----------------------------------//
struct Str_Edge {
//! pointer to the source node.
Node * _source;
//! pointer to the connected node.
Node * _target;
//! pointer to the twin edge in case of bidirectional edge.
struct Str_Edge * _twin;
//! color (r, g, b, a) of the node
Color color;
};
/**
* @brief NetWorld Edge.
*/
typedef struct Str_Edge Edge;
// Constructor / Destructor
/**
* @brief Construc all the element of an empty Edge.
* @param self an empty Edge ot yet constructed.
* @param source the source Node the edge start from (default NULL)
* @param target the target Node to connect (default NULL)
* @return The pointer to the new NetWorld.
*/
void Edge_construct( Edge * self, Node * source, Node * target );
/**
* @brief Allocate the memory to store a NetWorld.
* @return The pointer to the new NetWorld.
*/
Edge * Edge_new(
//! the source Node to connect
Node * source,
//! the target Node to connect (NULL if unknown)
Node * target
);
/**
* @brief Destructor.
*/
void Edge_delete(
//! the NetWorld to delete
Edge * self
);
/**
* @brief Allocate 'size' Edges (with NULL target)
* @return The pointer to the new array of 'size' Edges.
*/
Edge * Edge_newArray(int size);
/**
* @brief Destructor.
*/
void Edge_deleteArray(
//! the number of edges
int n,
//! the NetWorld to delete
Edge * array
);
// Copying
/**
* @brief Copy an edge from another
*/
void Edge_copy(
//! the edge to modify
Edge * copy,
//! the edge to copy
Edge * model
);
//-----------------------------------//
//-- NetWorld --//
//-----------------------------------//
struct Str_NetWorld {
//! number of nodes composing the NetWorld
int size;
//! Array of 'size' nodes
Node * nodes;
};
typedef struct Str_NetWorld NetWorld;
// Constructor / Destructor
NetWorld * NetWorld_new(int aSize);
void NetWorld_delete(NetWorld * self);
/**
* @brief Allocate the memory to store a NetWorld.
* @return The pointer to the new NetWorld.
*/
NetWorld * NetWorld_new(
//! the number of Nodes composing the new NetWorld
int aSize
);
// Initialization
void NetWorld_initNodePosition(NetWorld * self, int iNode, double x, double y); // position must be an float[size][2] array...
/**
* @brief Destructor.
*/
void NetWorld_delete(
//! the NetWorld to delete
NetWorld * self
);
// To String
void NetWorld_print(NetWorld * self);
/**
* @brief print
*/
void NetWorld_print(
//! the NetWorld to modify
NetWorld * self
);
// Managment :
/**
* @brief connect tow node together
* @return the index of the edge in the node edges' array
*/
int NetWorld_connect(
//! the NetWorld to modify
NetWorld * self,
//! index of the source node
int source,
//! index of the target node
int target
);
/**
* @brief connect tow node together (bidirectional)
* @return the index of the edge in the node edges' array
*/
int NetWorld_biconnect(
//! the NetWorld to modify
NetWorld * self,
//! index of the source node
int source,
//! index of the target node
int target
);
#endif //NETWORLD_H
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment