-
Notifications
You must be signed in to change notification settings - Fork 0
/
Node.h
113 lines (99 loc) · 2.52 KB
/
Node.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#ifndef HOMEWORK_NODE_H
#define HOMEWORK_NODE_H
/**
* @file Node.h
* @brief Structures and functions related to the Logic Node system
* @version 0.1
* @date 2019-11-05
*
* @copyright Copyright (c) 2019
*
*/
#include "Component.h"
#include "Input.h"
#include "Wire.h"
struct Node;
typedef struct Wire Wire;
/**
* @brief Data about a single node in the logic diagram
*
*/
typedef struct Node {
ComponentData component; /**< Component in the node */
Wire *wires; /**< Wires coming out of the out pins */
bool *inValues; /**< Current input values */
bool *nextInValues; /**< Input values for the next frame */
bool *outValues; /**< Output values */
SDL_Renderer *renderer; /**< Renderer associated with the node */
} Node;
/**
* @brief Create a generic node given a name
*
* @param compName Component name to use
* @param pos Position of the node
* @param font Font to render the component with
* @param renderer Renderer to associate the node with
* @return Node Resulting node
*/
Node node_create(char *compName, Point pos, TTF_Font *font, SDL_Renderer *renderer);
/**
* @brief Connect node to given node
*
* @param node Output node
* @param pinA Output pin
* @param other Input node
* @param pinB Input pin
* @param nodes Array of nodes
*/
void node_add_connection(Node *node, int pinA, int other, int pinB, Node *nodes);
/**
* @brief Set the input value of the node for the next frame
*
* @param node Node to set input value for
* @param pinIn Pin id
* @param value Value to set
*/
void node_set_inval(Node *node, int pinIn, bool value);
/**
* @brief Load input values for the next frame
*
* @param node Node to update
*/
void node_update_values(Node *node);
/**
* @brief Simulate node
*
* @param node Node to simulate
* @param nodes Array of nodes
*/
void node_run(Node *node, Node *nodes);
/**
* @brief Render node
*
* @param node Node to render
* @param camPos Position to render at
*/
void node_render(Node *node, Point camPos);
/**
* @brief Free node
*
* @param node Node to free
*/
void node_free(Node *node);
/**
* @brief Is a point over a node
*
* @param node Node to check
* @param p Point to check
* @return true The point is over the node
* @return false The point isn't over the node
*/
bool node_is_over(Node *node, Point p);
/**
* @brief Repositions the wires of the node after moving it
*
* @param node Node to repositions the wire for
* @param nodes Array of the nodes
*/
void node_reposition_wires(Node *node, Node *nodes);
#endif //HOMEWORK_NODE_H