Advertisement
Guest User

es_b2

a guest
Apr 27th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdbool.h>
  4. #include <inttypes.h>
  5. #include <stdint.h>
  6. #include <malloc.h>
  7. #include <string.h>
  8. #include <math.h>
  9. #include <pthread.h>
  10.  
  11. typedef struct _element {
  12.     uint64_t id;
  13.     uint32_t coordX;
  14.     uint32_t coordY;
  15.     uint32_t h;
  16.     uint32_t b;
  17.     uint64_t level;
  18.     uint64_t value;
  19.     bool enabled;
  20. } element;
  21.  
  22. typedef struct _elements_node {
  23.     struct _elements_node *left;
  24.     struct _elements_node *right;
  25.     element *ele;
  26. } elementsNode;
  27.  
  28. typedef struct _graph_node {
  29.     struct _graph_node *left;
  30.     struct _graph_node *right;
  31.     element *ele;
  32. } graphNode;
  33.  
  34. typedef struct _action_node {
  35.     struct _action_node *right;
  36.    
  37. } actionNode;
  38.  
  39. typedef struct _scena {
  40.     graphNode *drawTree;
  41.     elementsNode *elemTree;
  42.     actionNode* actionList;
  43.    
  44.     uint32_t width;
  45.     uint32_t height;
  46.    
  47.     pthread_t inputThread;
  48.     pthread_t outputThread;
  49.     pthread_t logicThread;
  50.  
  51.     //mutex drawing, action;
  52. } scene;
  53.  
  54. scene *newScene(uint32_t width, uint32_t height, char *file);
  55. void removeScene(scene* env);
  56.  
  57. void drawScene(scene* env);
  58.  
  59. 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);
  60. void moveElement(scene* env, uint64_t id, uint32_t newX, uint32_t newY);
  61. void disableElement(scene* env, uint64_t id);
  62. void enableElement(scene* env, uint64_t id);
  63.  
  64. void *drawingThread(void *);
  65. void *inputThread(void *threadarg);
  66. void *editorThread(void *);
  67.  
  68. int main(int argc, char** argv) {
  69.        
  70.     if (argc < 2) {
  71.         printf("program infile.txt\n");
  72.         return (EXIT_FAILURE);
  73.     }
  74.    
  75.     char *nome_file = argv[1];
  76.     FILE* inFile = fopen(nome_file, "r");
  77.     uint32_t height, width;
  78.     fscanf (inFile, "%" SCNi32 "", &height);
  79.     fscanf (inFile, "%" SCNi32 "", &width);
  80.    
  81.     newScene (width, height, nome_file);
  82.    
  83.     //fclose(inFile);
  84. }
  85.  
  86. struct args {
  87.     char* nomefile;
  88.     scene* currentScene;
  89. };
  90.  
  91. scene *newScene(uint32_t width, uint32_t height, char *file) {
  92.     scene *scena = (scene*)calloc(1, sizeof(scene));
  93.     (*scena).height = height;
  94.     (*scena).width = width;
  95.     struct args *temp = (struct args*)calloc(1, sizeof(struct args));
  96.     temp->currentScene = scena;
  97.     temp->nomefile = file;
  98.    
  99.     pthread_attr_t attr;
  100.     pthread_attr_init(&attr);
  101.     pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
  102.     int rc = pthread_create(&scena->inputThread, &attr, &inputThread, (void *)temp);
  103.    
  104.     return scena;
  105. }
  106.  
  107. void *inputThread(void *threadarg) {
  108.     struct args *current = (struct args*)threadarg;
  109.     FILE* inFile = fopen(current -> nomefile, "r");
  110.     scene *scena = current -> currentScene;
  111.    
  112.     return NULL;
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement