Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdbool.h>
- #include <inttypes.h>
- #include <stdint.h>
- #include <malloc.h>
- #include <string.h>
- #include <math.h>
- #include <pthread.h>
- typedef struct _element {
- uint64_t id;
- uint32_t coordX;
- uint32_t coordY;
- uint32_t h;
- uint32_t b;
- uint64_t level;
- uint64_t value;
- bool enabled;
- } element;
- typedef struct _elements_node {
- struct _elements_node *left;
- struct _elements_node *right;
- element *ele;
- } elementsNode;
- typedef struct _graph_node {
- struct _graph_node *left;
- struct _graph_node *right;
- element *ele;
- } graphNode;
- typedef struct _action_node {
- struct _action_node *right;
- } actionNode;
- typedef struct _scena {
- graphNode *drawTree;
- elementsNode *elemTree;
- actionNode* actionList;
- uint32_t width;
- uint32_t height;
- pthread_t inputThread;
- pthread_t outputThread;
- pthread_t logicThread;
- //mutex drawing, action;
- } scene;
- scene *newScene(uint32_t width, uint32_t height, char *file);
- void removeScene(scene* env);
- void drawScene(scene* env);
- void insertElement(scene* env, uint64_t id, uint32_t coordX, uint32_t coordY, uint32_t h, uint32_t b, uint64_t lv, uint64_t value);
- void moveElement(scene* env, uint64_t id, uint32_t newX, uint32_t newY);
- void disableElement(scene* env, uint64_t id);
- void enableElement(scene* env, uint64_t id);
- void *drawingThread(void *);
- void *inputThread(void *threadarg);
- void *editorThread(void *);
- int main(int argc, char** argv) {
- if (argc < 2) {
- printf("program infile.txt\n");
- return (EXIT_FAILURE);
- }
- char *nome_file = argv[1];
- FILE* inFile = fopen(nome_file, "r");
- uint32_t height, width;
- fscanf (inFile, "%" SCNi32 "", &height);
- fscanf (inFile, "%" SCNi32 "", &width);
- newScene (width, height, nome_file);
- //fclose(inFile);
- }
- struct args {
- char* nomefile;
- scene* currentScene;
- };
- scene *newScene(uint32_t width, uint32_t height, char *file) {
- scene *scena = (scene*)calloc(1, sizeof(scene));
- (*scena).height = height;
- (*scena).width = width;
- struct args *temp = (struct args*)calloc(1, sizeof(struct args));
- temp->currentScene = scena;
- temp->nomefile = file;
- pthread_attr_t attr;
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
- int rc = pthread_create(&scena->inputThread, &attr, &inputThread, (void *)temp);
- return scena;
- }
- void *inputThread(void *threadarg) {
- struct args *current = (struct args*)threadarg;
- FILE* inFile = fopen(current -> nomefile, "r");
- scene *scena = current -> currentScene;
- return NULL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement