Advertisement
Ladies_Man

ccg cell_highlighting. still works

Nov 1st, 2015
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 18.38 KB | None | 0 0
  1. // glfw_30.cpp : Defines the entry point for the console application.
  2. //  http://www.glfw.org/docs/latest/quick.html
  3.  
  4. #include "stdafx.h"
  5. #include <time.h>
  6. #define _USE_MATH_DEFINES
  7. #include <cmath>
  8. #include <stdio.h>
  9. #include <iostream>
  10. #include <string>
  11. #include <ctime>
  12.  
  13. #include <GLAux.h>
  14. #pragma comment(lib,"glaux.lib")
  15.  
  16.  
  17. #define SCREEN_WIDTH 1000
  18. #define SCREEN_HEIGHT 1000
  19. #define SPLIT_X 10
  20. #define SPLIT_Y 10
  21. #define G_CONST 9.78
  22. #define MAXRANDID 99999
  23.  
  24. #define REVD(COORD_Y) ((SPLIT_Y - 1) - (COORD_Y))
  25.  
  26. using namespace std;
  27.  
  28. GLdouble A, B, C, D;
  29.  
  30.  
  31.  
  32. float t;
  33.  
  34. typedef struct {int x, y;} coord;
  35.  
  36. class cell;
  37. class map;
  38. class body;
  39.  
  40.  
  41. map *m;
  42.  
  43.  
  44.  
  45. class cell {
  46. public:
  47.     //encapsulation err
  48.     int id;
  49.     char type;
  50.     bool highlighted;
  51.  
  52.     void set_id(int);
  53.     void set_coord(int, int);
  54.     void set_type(char);
  55.     void draw_cell();
  56.  
  57.     cell() { this->type = 'e'; this->id = 0;
  58.              this->size_x = (int)(SCREEN_WIDTH / SPLIT_X);
  59.              this->size_y = (int)(SCREEN_HEIGHT / SPLIT_Y);
  60.              this->highlighted = false;
  61.     }
  62.  
  63. private:
  64.     int map_pos_x, map_pos_y;
  65.     coord botleft, topleft, topright, botright;
  66.     int size_y, size_x;
  67. };
  68.  
  69. void cell::set_id(int cid) {
  70.     this->id = cid;
  71.     //printf("id:%d ", this->id);
  72. }
  73.  
  74. void cell::set_type(char ctype) {
  75.     this->type = ctype;
  76.     //printf("t:%c ", this->type);
  77. }
  78.  
  79. void cell::set_coord(int x, int y) {
  80.     this->map_pos_x = x;
  81.     this->map_pos_y = y;
  82.  
  83.  
  84.     this->topleft.x = (int)(x * this->size_x);
  85.     this->topleft.y = (int)(REVD(y) * this->size_y);
  86.  
  87.     this->topright.x = (int)(x * this->size_x + this->size_x);
  88.     this->topright.y = (int)(REVD(y) * this->size_y);
  89.    
  90.     this->botright.x = (int)(x * this->size_x + this->size_x);
  91.     this->botright.y = (int)(REVD(y) * this->size_y + this->size_y);
  92.    
  93.     this->botleft.x = (int)(x * this->size_x);
  94.     this->botleft.y = (int)(REVD(y) * this->size_y + this->size_y);
  95.  
  96. }
  97.  
  98. void cell::draw_cell() {
  99.     if ('e' == this->type) {
  100.         glColor3f(0.5, 0.5, 0.5);
  101.     }
  102.     if ('c' == this->type) {
  103.         glColor3f(1, 0, 0);
  104.     }
  105.     if ('b' == this->type) {
  106.         glColor3f(0, 0, 1);
  107.     }
  108.     if (this->highlighted) {
  109.         glColor3f(1, 1, 1);
  110.     }
  111.  
  112.  
  113.     glBegin(GL_POLYGON);
  114.     glTexCoord2f(0.0f, 0.0f);
  115.     glVertex2f(this->botleft.x, this->botleft.y);
  116.     glTexCoord2f(0.0f, 1.0f);
  117.     glVertex2f(this->topleft.x, this->topleft.y);
  118.     glTexCoord2f(1.0f, 1.0f);
  119.     glVertex2f(this->topright.x, this->topright.y);
  120.     glTexCoord2f(1.0f, 0.0f);
  121.     glVertex2f(this->botright.x, this->botright.y);
  122.     glEnd();
  123.  
  124.     if ('b' == this->type) {
  125.         glColor3f(0.55, 0.55, 0.55);
  126.         glBegin(GL_POLYGON);
  127.             glVertex2f(this->topleft.x + 40, this->topleft.y + this->size_y / 2);
  128.             glVertex2f(this->topleft.x + 40, SCREEN_HEIGHT + 100);
  129.             glVertex2f(this->topright.x - 40, SCREEN_HEIGHT + 100);
  130.             glVertex2f(this->topright.x - 40, this->topright.y + this->size_y / 2);
  131.         glEnd();
  132.     }
  133. }
  134.  
  135.  
  136.  
  137. class map {
  138. public:
  139.     void set_map(int, int);
  140.     void clean_map();
  141.     void draw_net();
  142.     void draw_obj();
  143.     void print_map();
  144.     void dispell_map();
  145.  
  146.     void set_cell(int, int, int, char);
  147.     void highlight_cell(int, int);
  148.  
  149. private:
  150.     int arr_size_y;
  151.     int arr_size_x;
  152.  
  153.     cell** map_arr;
  154.     int cell_size_x;
  155.     int cell_size_y;
  156. };
  157.  
  158. void map::set_map(int rows, int cols) {
  159.     this->arr_size_y = rows;
  160.     this->arr_size_x = cols;
  161.  
  162.     this->cell_size_x = (int)(SCREEN_WIDTH / SPLIT_X);
  163.     this->cell_size_y = (int)(SCREEN_HEIGHT / SPLIT_Y);
  164.  
  165.     cell** map = new cell*[this->arr_size_y];
  166.     this->map_arr = map;
  167.     //this->map_arr = (cell **)malloc(this->arr_size_y * sizeof(cell *));
  168.     // a[0]
  169.     // a[1]
  170.     // a[2]
  171.  
  172.     int i, j;
  173.     /*for (i = 0; i < this->arr_size_y; i++) {
  174.         this->map_arr[i] = (cell *)malloc(this->arr_size_x * sizeof(cell));
  175.     }*/
  176.  
  177.     for (i = 0; i < this->arr_size_y; i++) {
  178.         this->map_arr[i] = new cell[this->arr_size_x];
  179.     }
  180.  
  181.     for (j = 0; j < this->arr_size_y; j++) {
  182.         for (i = 0; i < this->arr_size_x; i++) {
  183.  
  184.             this->map_arr[i][j].set_coord(i, j);
  185.  
  186.         }
  187.     }
  188.  
  189.     for (j = 0; j < this->arr_size_y; j++) {
  190.         for (i = 0; i < this->arr_size_x; i++) {
  191.  
  192.             printf("%d:%d ", i, j);
  193.  
  194.         }
  195.         printf("\n");
  196.     }
  197.  
  198. }
  199.  
  200. void map::clean_map() {
  201.     for (int i = 0; i < this->arr_size_y; i++) {
  202.         delete[] this->map_arr[i];
  203.     }
  204.     delete[] this->map_arr;
  205. }
  206.  
  207. void map::draw_net() {
  208.     int i, j;
  209.  
  210.     for (i = 0; i < SCREEN_WIDTH; i += SCREEN_WIDTH / this->arr_size_x) {
  211.         glColor3f(1, 1, 1);
  212.         for (j = 0; j < SCREEN_HEIGHT; j += SCREEN_HEIGHT / this->arr_size_y) {
  213.             glBegin(GL_LINES);
  214.             glVertex2f(i, 0);
  215.             glVertex2f(i, SCREEN_HEIGHT);
  216.             glEnd();
  217.  
  218.             glBegin(GL_LINES);
  219.             glVertex2f(0, j);
  220.             glVertex2f(SCREEN_WIDTH, j);
  221.             glEnd();
  222.         }
  223.     }
  224. }
  225.  
  226. void map::draw_obj() {
  227.     int i, j;
  228.  
  229.     for (j = 0; j < this->arr_size_y; j++) {
  230.         for (i = 0; i < this->arr_size_x; i++) {
  231.             //if ('e' != map_arr[i][j].type) {
  232.  
  233.                 map_arr[i][j].draw_cell();
  234.  
  235.             //}
  236.         }
  237.     }
  238. }
  239.  
  240. void map::print_map() {
  241.     int i, j;
  242.  
  243.     printf("\ncurrent map:\n");
  244.     for (j = 0; j < this->arr_size_y; j++) {
  245.         for (i = 0; i < this->arr_size_x; i++) {
  246.             if ('e' == this->map_arr[i][j].type) {
  247.                 printf("- ");
  248.             }
  249.             if ('c' == this->map_arr[i][j].type) {
  250.                 printf("C ");
  251.             }
  252.             if ('b' == this->map_arr[i][j].type) {
  253.                 printf("B ");
  254.             }
  255.         }
  256.         printf("\n");
  257.     }
  258.  
  259. }
  260.  
  261. void map::dispell_map() {
  262.     int i, j;
  263.    
  264.     for (j = 0; j < this->arr_size_y; j++) {
  265.         for (i = 0; i < this->arr_size_x; i++) {
  266.  
  267.             this->map_arr[i][j].highlighted = false;
  268.  
  269.         }
  270.     }
  271. }
  272.  
  273. void map::set_cell(int cid, int x, int y, char ctype) {
  274.  
  275.     this->map_arr[x][y].set_id(cid);
  276.     this->map_arr[x][y].set_type(ctype);
  277.     this->map_arr[x][y].set_coord(x, y);
  278.  
  279. }
  280.  
  281. void map::highlight_cell(int x, int y) {
  282.     this->map_arr[x][y].highlighted = true;
  283. }
  284.  
  285.  
  286.  
  287. class body {
  288. public:
  289.     char *name;
  290.     int id;
  291.     int type, num, mass;    // 1 - cargo, 2 - block
  292.     body *up;
  293.     body *down;
  294.     body *right;
  295.     body *left;
  296.  
  297.     void set(int, int, int, int, float, float);
  298.     void draw();
  299.  
  300. private:
  301.     float curr_x, curr_y;
  302.     float init_x, init_y;
  303.     float center_x, center_y;
  304.     int h, w;
  305.  
  306.  
  307. };
  308.  
  309. void body::set(int bid, int num, int type, int mass, float pos_x, float pos_y) {
  310.     this->id = bid;
  311.     this->init_x = pos_x;
  312.     this->init_y = pos_y;
  313.  
  314.     this->curr_x = pos_x;
  315.     this->curr_y = pos_y;
  316.  
  317.     this->type = type;
  318.     this->num = num;
  319.     this->mass = mass;
  320.  
  321.     this->up = NULL;
  322.     this->down = NULL;
  323.     this->right = NULL;
  324.     this->left = NULL;
  325.  
  326.     this->h = 20;
  327.     this->w = 20;
  328. }
  329.  
  330. void body::draw() {
  331.     float pos_x = this->curr_x;
  332.     float pos_y = this->curr_y;
  333.     // 1 = cargo, 2 = block
  334.  
  335.     glBegin(GL_POLYGON);
  336.         if (1 == this->type) glColor3f(1, 0, 0);
  337.         if (2 == this->type) glColor3f(0, 0, 1);
  338.         glVertex2i(pos_x, pos_y);
  339.         glVertex2i(pos_x + this->w, pos_y);
  340.         glVertex2i(pos_x + this->w, pos_y + this->h);
  341.         glVertex2i(pos_x, pos_y + this->h);
  342.     glEnd();
  343. }
  344.  
  345.  
  346.  
  347.  
  348.  
  349. struct node
  350. {
  351.     int value;
  352.     body obj;
  353.     node *next_r, *prev_l;
  354.  
  355.     node(int y) { value = y; next_r = prev_l = NULL; }
  356. };
  357.  
  358. class dll {
  359. public:
  360.  
  361.     void append_front(int, body);
  362.     void append_back(int, body);
  363.     node* get_front();
  364.     node* get_back();
  365.     void display_forward();
  366.     void display_backward();
  367.     void display_objects();
  368.     void draw_objects();
  369.     void destroy_list();
  370.  
  371.     dll() { front = NULL; back = NULL; }
  372.     ~dll() { destroy_list(); }
  373.  
  374.  
  375. private:
  376.  
  377.     node *front;
  378.     node *back;
  379.  
  380. };
  381.  
  382. void dll::append_front(int x, body b) {
  383.  
  384.     node *n = new node(x);
  385.  
  386.     n->obj = b;
  387.  
  388.     if (front == NULL) {
  389.         front = n;
  390.         back = n;
  391.     } else {
  392.         front->prev_l = n;
  393.         n->next_r = front;
  394.         front = n;
  395.     }
  396.  
  397.     cout << "fornt appended" << endl;
  398. }
  399.  
  400. void dll::append_back(int x, body b) {
  401.  
  402.     node *n = new node(x);
  403.  
  404.     n->obj = b;
  405.  
  406.     if (back == NULL) {
  407.         front = n;
  408.         back = n;
  409.     } else {
  410.         back->next_r = n;
  411.         n->prev_l = back;
  412.         back = n;
  413.     }
  414.  
  415.     cout << "back appended" << endl;
  416. }
  417.  
  418. node* dll::get_front() {
  419.     return this->front;
  420. }
  421.  
  422. node* dll::get_back() {
  423.     return this->back;
  424. }
  425.  
  426. void dll::display_forward() {
  427.     node *temp = front;
  428.  
  429.     cout << "\n\nnodes in forward order:" << endl;
  430.  
  431.     while (temp != NULL) {
  432.         cout << temp->value << "   ";
  433.         temp = temp->next_r;
  434.     }
  435. }
  436.  
  437. void dll::display_backward() {
  438.     node *temp = back;
  439.  
  440.     cout << "\n\nnodes in reverse order:" << endl;
  441.  
  442.     while (temp != NULL) {
  443.         cout << temp->value << "   ";
  444.         temp = temp->prev_l;
  445.     }
  446. }
  447.  
  448. void dll::display_objects() {
  449.     node *temp = front;
  450.  
  451.     cout << "\n\nobjects in forward order:" << endl;
  452.  
  453.     while (NULL != temp) {
  454.         printf("(%d", temp->value);
  455.         if (1 == temp->obj.type) printf("C ");
  456.         if (2 == temp->obj.type) printf("B ");
  457.         printf("[id:%d])   ", temp->obj.id);
  458.         temp = temp->next_r;
  459.     }
  460. }
  461.  
  462. void dll::draw_objects() {
  463.     node *temp = front;
  464.  
  465.     while (NULL != temp) {
  466.         temp->obj.draw();
  467.         if (temp->obj.down != NULL) temp->obj.down->draw();
  468.         temp = temp->next_r;
  469.     }
  470. }
  471.  
  472. void dll::destroy_list() {
  473.     node *T = back;
  474.  
  475.     while (T != NULL) {
  476.         node *T2 = T;
  477.         T = T->prev_l;
  478.         delete T2;
  479.     }
  480.  
  481.     front = NULL;
  482.     back = NULL;
  483. }
  484.  
  485.  
  486.  
  487.  
  488.  
  489. int count_command(string command, char type) {
  490.  
  491.     int i, comm_len = command.length();
  492.     int retval = 0;
  493.  
  494.  
  495.     if ('e' == type) {
  496.         for (i = 0; i < comm_len; i++) {
  497.             if ('b' == command[i] || 'c' == command[i]) {
  498.                 retval++;
  499.             }
  500.         }
  501.         return retval;
  502.     }
  503.  
  504.     for (i = 0; i < comm_len; i++) {
  505.         if (type == command[i]) {
  506.             retval++;
  507.         }
  508.     }
  509.  
  510.     return retval;
  511. }
  512.  
  513. int count_further(string command, int curr_pos) {
  514.  
  515.     int i, j, num_of_same_chars;
  516.     int seq_end_pos;
  517.     char curr_sym = command[curr_pos];
  518.  
  519.     if (curr_pos < command.length()) {
  520.  
  521.         num_of_same_chars = 1;
  522.         seq_end_pos = curr_pos;
  523.  
  524.         for (i = curr_pos; i < command.length(); i++) {
  525.             if (curr_sym == command[i] && curr_sym == command[i + 1]) {
  526.                 num_of_same_chars++;
  527.                 seq_end_pos = i;
  528.             }
  529.             if (curr_sym == command[i] && curr_sym != command[i + 1]) {
  530.                 seq_end_pos = i + 1;
  531.                 break;
  532.             }
  533.         }
  534.  
  535.         return seq_end_pos;
  536.     }
  537.     else {
  538.         printf("\ncount_further incorrect input!\n");
  539.         return -1;
  540.     }
  541.    
  542. }
  543.  
  544. bool lookup_next_sym(string command, int curr_pos) {
  545.  
  546.     int i;
  547.     char curr_sym = command[curr_pos];
  548.     char opposite;
  549.     if ('b' == curr_sym) opposite = 'c';
  550.     if ('c' == curr_sym) opposite = 'b';
  551.  
  552.     for (i = curr_pos; i < command.length(); i++) {
  553.         if (command[i] == curr_sym) continue;
  554.         if (command[i] == opposite) break;
  555.     }
  556.     int last_pos_of_curr_sym = i - 1;
  557.  
  558.     return true;
  559.  
  560. }
  561.  
  562. char nearest_next_sym(string command, int curr_pos) {
  563.  
  564.     char curr_sym = command[curr_pos];
  565.     int seq_len = count_further(command, curr_pos);
  566.  
  567.     if (curr_pos + seq_len < command.length()) {
  568.         return command[curr_pos + seq_len];
  569.     }
  570.     else
  571.     {
  572.         return 'x';
  573.     }
  574. }
  575.  
  576.  
  577.  
  578.  
  579. GLuint texture[1];
  580.  
  581. void load_textures()
  582. {
  583.  
  584.     AUX_RGBImageRec *texture1;
  585.     texture1 = auxDIBImageLoadA("tex_snoop.bmp");
  586.     glGenTextures(1, &texture[0]);
  587.     glBindTexture(GL_TEXTURE_2D, texture[0]);
  588.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  589.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  590.     glTexImage2D(GL_TEXTURE_2D, 0, 3, texture1->sizeX, texture1->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, texture1->data);
  591.  
  592.     glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  593. }
  594.  
  595.  
  596.  
  597. static void cursor_callback(GLFWwindow* window, double x, double y)
  598. {
  599.     //printf("%d\t%d\n", (int)x, (int)y);
  600.     int tmpx = (int)(x / (SCREEN_WIDTH / SPLIT_X));
  601.     int tmpy = (int)(y / (SCREEN_HEIGHT / SPLIT_Y));
  602.  
  603.     m->dispell_map();
  604.     m->highlight_cell(tmpx, tmpy);
  605. }
  606.  
  607. static void mouse_callback(GLFWwindow* window, int button, int action, int mods)
  608. {
  609.     if (button == GLFW_MOUSE_BUTTON_RIGHT)
  610.     {
  611.         if (action == GLFW_PRESS) glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
  612.         if (action == GLFW_RELEASE) glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
  613.     }
  614.  
  615.     if (button == GLFW_MOUSE_BUTTON_LEFT)
  616.     {
  617.  
  618.     }
  619. }
  620.  
  621. static void resize_callback(GLFWwindow* window, int width, int height)
  622. {
  623.     //      windowWidth = width;
  624.     //      windowHeight = height;
  625.  
  626.     glViewport(0, 0, width, height);
  627.     glMatrixMode(GL_PROJECTION);
  628.     glLoadIdentity();
  629.     glOrtho(0.0, (GLdouble)width, 0.0, (GLdouble)height, -1, 1);
  630.  
  631.     glMatrixMode(GL_MODELVIEW);
  632.     glLoadIdentity();
  633.  
  634.     A = width / 4.0;
  635.     B = 0.0;
  636.     C = D = height / 2.0;
  637.  
  638.     //printf("Reshape occured\n");
  639. }
  640.  
  641. static void keyboard_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
  642. {
  643.     if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
  644.         glfwSetWindowShouldClose(window, GL_TRUE);
  645.     //if (GLFW_KEY_T == key && action == GLFW_PRESS) { gravity(); }
  646. }
  647.  
  648. static void error_callback(int error, const char* description)
  649. {
  650.     fputs(description, stderr);
  651. }
  652.  
  653.  
  654.  
  655.  
  656. int main(int argc, _TCHAR* argv[])
  657. {
  658.     if (!glfwInit()) {
  659.         printf("glfwInit failed\n");
  660.         return -1;
  661.     }
  662.  
  663.     glfwSetErrorCallback(error_callback);
  664.  
  665.     GLFWwindow* window;
  666.  
  667.     //      glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 1);
  668.     //      glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
  669.     //glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE);
  670.     window = glfwCreateWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Anthony's Porject", NULL, NULL);
  671.     if (window == NULL) {
  672.         printf("glfwOpenWindow failed.\n");
  673.         glfwTerminate();
  674.         return -2;
  675.     }
  676.  
  677.     int i, j, k, attrib;
  678.     attrib = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MAJOR);
  679.     attrib = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MINOR);
  680.     attrib = glfwGetWindowAttrib(window, GLFW_OPENGL_PROFILE);
  681.  
  682.     glfwMakeContextCurrent(window);
  683.  
  684.     glfwSetKeyCallback(window, keyboard_callback);
  685.     glfwSetFramebufferSizeCallback(window, resize_callback);
  686.     glfwSetMouseButtonCallback(window, mouse_callback);
  687.     glfwSetCursorPosCallback(window, cursor_callback);
  688.     resize_callback(window, SCREEN_WIDTH, SCREEN_HEIGHT);
  689.  
  690.     srand(time(NULL));
  691.  
  692.  
  693.     dll *list = new dll();
  694.     body c, b;
  695.  
  696.     int id, id2;
  697.     char c_type = 'c', b_type = 'b', e_type = 'e';
  698.     int b_pos_x, b_pos_y, c_pos_x, c_pos_y, c_n, b_n;
  699.  
  700.     c_n = b_n = 0;
  701.  
  702.     m = new map();
  703.     m->set_map(SPLIT_X, SPLIT_Y);
  704.  
  705.  
  706.     printf("insert scheme:\n..........\n");
  707.  
  708.     string command;
  709.     back:
  710.     getline(cin, command);
  711.    
  712.  
  713.  
  714.  
  715.     c_pos_x = 0;
  716.     c_pos_y = 6;
  717.  
  718.     b_pos_x = 0;
  719.     b_pos_y = 3;
  720.    
  721.     char prev_sym = '0', curr_sym, next_sym;
  722.     int body_num, block_num, cargo_num;
  723.     int seq_start_pos, seq_end_pos, len_of_seq;
  724.  
  725.     //command = "b^bc^b^cc";
  726.     //command = "cbb(cc)bc";
  727.  
  728.     //body_num = count_command(command, 'e');
  729.     //cargo_num = count_command(command, c_type);
  730.     //block_num = count_command(command, b_type);
  731.     //printf("bodies:%d cargos:%d blocks:%d\n", body_num, cargo_num, block_num);
  732.    
  733.     for (i = 0; i < command.length(); i++) {
  734.  
  735.         if (i > 0)
  736.             prev_sym = command[i - 1];
  737.         curr_sym = command[i];
  738.         next_sym = command[i + 1];
  739.         seq_start_pos = i;
  740.         seq_end_pos = count_further(command, seq_start_pos);
  741.         len_of_seq = seq_end_pos - seq_start_pos;
  742.         char nearest_sym = command[seq_start_pos + len_of_seq];
  743.         printf("[%d_%d]%c:%d   .%c\n", seq_start_pos, seq_end_pos, curr_sym, len_of_seq, nearest_sym);
  744.        
  745.  
  746.         //i = seq_end_pos-1;
  747.        
  748.         if ('b' == curr_sym && len_of_seq > 1) {
  749.  
  750.             printf(" b.. ");
  751.  
  752.             if ('(' == nearest_sym || '^' == nearest_sym) {
  753.                 len_of_seq -= 1;
  754.             }
  755.            
  756.             for (j = 0; j < len_of_seq; j++) {
  757.                
  758.                 id = 100 + rand() % MAXRANDID;
  759.  
  760.                 if (0 == j % 2) {
  761.                     m->set_cell(id, b_pos_x++, b_pos_y, b_type);
  762.                 }
  763.                 else {
  764.                     m->set_cell(id, b_pos_x++, b_pos_y + 1, b_type);
  765.                 }
  766.                
  767.             }
  768.  
  769.             i = i + j - 1;
  770.  
  771.             continue;
  772.            
  773.         }
  774.         if ('b' == curr_sym && '(' == next_sym) {
  775.            
  776.             m->set_cell(1, b_pos_x, b_pos_y, b_type);
  777.  
  778.             int num_of_cargos = 2;
  779.             //int num_of_cargos = count_further(command, i + 2);
  780.             printf(" b(str[%d]=%c(n:%d)) ", i + 2, command[i + 2], num_of_cargos);
  781.  
  782.  
  783.             for (j = 0; j < num_of_cargos; j++) {
  784.  
  785.                 id = 100 + rand() % MAXRANDID;
  786.                 m->set_cell(id, b_pos_x, c_pos_y++, c_type);
  787.  
  788.             }
  789.  
  790.             b_pos_x++;
  791.             c_pos_x++;
  792.  
  793.             i = i + num_of_cargos;
  794.         }
  795.         /*
  796.         if ('b' == curr_sym && '^' == next_sym) {
  797.             id = 100 + rand() % MAXRANDID;
  798.             m->set_cell(id, b_pos_x++, b_pos_y, b_type);
  799.  
  800.             int tmp_seq_start = i;
  801.             int tmp_seq_end = count_further(command, tmp_seq_start, next_sym);
  802.            
  803.             int tmp_b_pos_y = b_pos_y;
  804.             for (j = 0; j < tmp_seq_end; j++) {
  805.                 tmp_b_pos_y++;
  806.             }
  807.  
  808.             id = 100 + rand() % MAXRANDID;
  809.             m->set_cell(id, b_pos_x++, tmp_b_pos_y, b_type);
  810.             i = tmp_seq_end;
  811.  
  812.             continue;
  813.         }*/
  814.         if ('c' == curr_sym && len_of_seq > 1 && len_of_seq <= 3) {
  815.             for (j = 0; j < len_of_seq; j++) {
  816.  
  817.                 id = 100 + rand() % MAXRANDID;
  818.                 m->set_cell(id, c_pos_x, c_pos_y + j, c_type);
  819.             }
  820.  
  821.             i = i + len_of_seq - 1;
  822.  
  823.             continue;
  824.         }
  825.     }
  826.  
  827.    
  828.     printf("\n");
  829.     /*
  830.     for (i = 0; i < command.length(); i++) {
  831.         // 1 = cargo, 2 = block
  832.  
  833.         id = 100 + rand() % MAXRANDID;
  834.         id2 = 100 + rand() % MAXRANDID;
  835.  
  836.         if ('c' == command[i]) {
  837.  
  838.             m->set_cell(id, c_pos_x++, c_pos_y, c_type); //======
  839.  
  840.             c.set(id, c_n, 1, 10, 50 + 70 * i, 150);
  841.             list->append_back(c_n, c);
  842.             c_n++;
  843.  
  844.             printf(" c ");
  845.             continue;
  846.            
  847.         }
  848.         if ('b' == command[i] && 'b' == command[i+1]) {
  849.  
  850.             m->set_cell(id, b_pos_x++, b_pos_y, b_type); //======
  851.  
  852.             b.set(id, b_n, 2, 0, 50 + 70 * i, 300);
  853.             list->append_back(b_n, b);
  854.             b_n++;
  855.  
  856.            
  857.             m->set_cell(id2, b_pos_x++, b_pos_y - 1, b_type);
  858.  
  859.             b.set(id2, b_n, 2, 0, 50 + 70 * (i + 1), 200);
  860.             list->append_back(b_n, b);
  861.             b_n++;
  862.  
  863.             i += 1;
  864.  
  865.             printf(" bb ");
  866.             continue;
  867.            
  868.         }
  869.         if ('b' == command[i] && '(' == command[i+1] && 'c' == command[i+2]) {
  870.  
  871.             m->set_cell(id, b_pos_x, b_pos_y, b_type); //======
  872.  
  873.             b.set(id, b_n, 2, 0, 50 + 70 * i, 300);
  874.             list->append_back(b_n, b);
  875.             b_n++;
  876.  
  877.             m->set_cell(id2, b_pos_x, c_pos_y - 2, c_type);
  878.             b_pos_x++;
  879.  
  880.             b.set(id2, c_n, 1, 10, 50 + 70 * i, 150);
  881.             list->append_back(c_n, b);
  882.             c_n++;
  883.  
  884.             i += 2;
  885.            
  886.             printf(" b(c ");
  887.             continue;
  888.         }
  889.        
  890.         if ('b' == command[i]) {
  891.  
  892.             m->set_cell(id, b_pos_x++, b_pos_y, b_type); //======
  893.  
  894.             b.set(id, b_n, 2, 0, 50 + 70 * i, 300);
  895.             list->append_back(b_n, b);
  896.             b_n++;
  897.  
  898.             printf(" b ");
  899.  
  900.             continue;
  901.         }
  902.        
  903.     }
  904.  
  905.     list->display_forward();
  906.     list->display_objects();
  907.     */
  908.  
  909.     t = 0;
  910.  
  911.     //load_textures();
  912.     //glEnable(GL_TEXTURE_2D);
  913.  
  914.     while (!glfwWindowShouldClose(window))
  915.     {
  916.         //glClearColor(0.5, 0.5, 0.5, 1);
  917.         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  918.  
  919.         if (glfwGetKey(window, GLFW_KEY_P) == GLFW_PRESS) {
  920.             m->print_map();
  921.         }
  922.         if (glfwGetKey(window, GLFW_KEY_DOWN) == GLFW_PRESS) {
  923.             i -= 5;
  924.         }
  925.  
  926.         m->draw_obj();
  927.         m->draw_net();
  928.  
  929.  
  930.         //list->draw_objects();
  931.  
  932.  
  933.  
  934.         glfwSwapBuffers(window);
  935.         glfwPollEvents();
  936.         //glfwWaitEvents();
  937.     }
  938.  
  939.     glfwDestroyWindow(window);
  940.     glfwTerminate();
  941.  
  942.     return 0;
  943. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement