//---------------------------------------------------------------------------------------------------------------------- void Tornado::createParticleSystem() { //creates new particle systems if the particle systems count hasn't reached the treshold if (m_particleSystemCount < m_particleSystemTreshold) { //changing the every 50 frames how often the radius should change if(m_frame%50==0) { //gets a random change value from 10 to 100 frames std::random_device rd2; std::mt19937_64 gen(rd2()); std::uniform_int_distribution<int> distribution2(10,100); m_radiusChange = (float)distribution2(gen); //gets a random value from the range of 2-4 that controlls how much the diffrent of the radius should be std::uniform_int_distribution<int> distribution3(2,4); m_radiusDiffrence=distribution3(gen); } //creating particle systems int diffrence=m_particleSystemTreshold - m_particleSystemCount; for (int i=0; i<diffrence;i++) { //gets a random radius from the radius range std::random_device rd; std::mt19937_64 gen(rd()); std::uniform_real_distribution<float> distribution(m_radiusRange[0],m_radiusRange[1]); float radius = distribution(gen); // caclucaltes the radius the is added on top of the original radius to create a ring type shape radius+= sqrt(pow((m_radiusDiffrence*sin((1.0/m_radiusChange)*(float)m_frame)),2)); // gets a random offset value std::uniform_real_distribution<float> distribution1(0.0,20.0); float offset = distribution1(gen); m_particleSystemList.push_back(std::unique_ptr<ParticleSystem>(new ParticleSystem(radius,offset,m_particleState,m_cloudHeight,m_particleProdutionRate,m_particleLifeRange))); m_particleSystemCount++; if (m_particleSystemCount >= m_particleSystemTreshold){ return;} if (i >= m_maxProductionRate){return;} } } }
int main() { try { // test the ringbuffer m_buffer_t rb(4); m_reader_t rd(rb); m_reader_t rd2(rb); assert(!rd.read_space()); std::size_t n = rb.write("abcd", 5); assert(n==3); assert(!rb.write_space()); // simulate impossible write assert(!rb.write("xyz", 4)); { assert(rd.read_space() == 3); rd.peak_max(3); assert(rd.read_space() == 3); auto s = rd.read_max(3); assert(s[0] == 97 && s[1] == 98 && s[2] == 99); assert(s.first_half_size() == 3 && !s.second_half_size()); } assert(!rd.read_space()); assert(!rb.write_space()); // reader 2 is still missing { rd2.read_max(3); } // rb = rd1 = rd2 = 3 assert(rb.write("ab", 2) == 2); assert(!rb.write_space()); { assert(rd.read_space() == 2); auto s = rd.read_max(1); assert(s.first_half_size() == 1); assert( !s.second_half_size()); assert(s[0] == 97); } { assert(rd.read_space() == 1); auto s2 = rd.read_max(1); assert(s2[0] == 98); } assert(!rb.write_space()); { rd2.read_max(2); } // rb = rd1 = rd2 = 1 assert(rb.write_space() == 2); assert(!rd.read_space()); rb.write("x", 1); assert(rb.write_space() == 1); { assert(rd2.read_space() == 1); auto s = rd2.read_max(1); assert(s.first_half_size() == 1 && !s.second_half_size()); assert(s[0] == 120); } assert(rb.write_space() == 1); { rd.read_max(2); } assert(rb.write_space() == 3); assert(!rd.read_space()); // rb = rd1 = rd2 = 2 assert(rb.write("abc", 3) == 3); assert(!rb.write_space()); { auto s = rd.read_max(3); assert(s.size()==3); //assert(s.first_half_size() == 2); //assert(s.second_half_size() == 1); assert_equal(s.first_half_ptr()[0], 'a'); assert(s.first_half_ptr()[1] == 'b'); assert(s.second_half_ptr()[0] == 'c'); } } catch (const char* s) { std::cerr << s << std::endl; return 1; } std::cerr << "SUCCESS!" << std::endl; return 0; }
DWORD WINAPI netGameLoop(void *param) { int len, c, x, y; Psquare p; TnetGameSettings *b; char *m, *u, *a; hostent *h; char buf[256]; if(!param){ buf[0]=(BYTE)C_INIT1; buf[1]=NETGAME_VERSION; wr(buf, 2); c=rd1(); if(c!=C_INIT2) goto le; c=rd1(); if(c<1) goto le; netGameVersion=c; SetForegroundWindow(hWin); h= gethostbyaddr((char*)&netGameIP.sin_addr, 4, netGameIP.sin_family); a= inet_ntoa(netGameIP.sin_addr); if(msg1(MB_YESNO|MB_ICONQUESTION, lng(868, "Do you want to play with %s [%s] ?"), (h && h->h_name) ? h->h_name : "???", a ? a : "???")!=IDYES){ wr1(C_INIT_DENY); goto le; } buf[0]=(BYTE)C_INFO; buf[1]=sizeof(TnetGameSettings); b= (TnetGameSettings*)(buf+2); b->width=(char)width; b->height=(char)height; b->begin= (player==1); b->rule5=(char)ruleFive; b->cont=(char)continuous; if(netGameVersion<2) b->rule5=b->cont=0; wr(buf, 2+sizeof(TnetGameSettings)); if(rd1()!=C_INFO_OK) goto le; b->begin= !b->begin; } else{ buf[0]=(BYTE)C_INIT2; buf[1]=NETGAME_VERSION; wr(buf, 2); c=rd1(); if(c==C_BUSY) wrLog(lng(874, "The other player is already playing with someone else")); if(c!=C_INIT1) goto le; c=rd1(); if(c<1) goto le; netGameVersion=c; wrLog(lng(871, "Connection established. Waiting for response...")); c=rd1(); if(c==C_INIT_DENY) wrLog(lng(870, "The other player doesn't want to play with you !")); if(c!=C_INFO) goto le; len=rd1(); b= (TnetGameSettings*)buf; memset(buf, 0, sizeof(TnetGameSettings)); if(len<2 || rd(buf, len)<0) goto le; wr1(C_INFO_OK); } SendMessage(hWin, WM_COMMAND, 992, (LPARAM)b); undoRequest=0; for(;;){ x=rd1(); switch(x){ case C_MSG: //message len=rd2(); if(len<=0) goto le; u=new char[2*len]; if(rd(u, 2*len)>=0){ m=new char[len+1]; WideCharToMultiByte(CP_ACP, 0, (WCHAR*)u, len, m, len, 0, 0); m[len]='\0'; wrLog("---> %s", m); delete[] m; SetWindowPos(logDlg, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_ASYNCWINDOWPOS|SWP_NOACTIVATE|SWP_SHOWWINDOW); } delete[] u; break; case C_UNDO_REQUEST: y=rd2(); if(y<=0 || y>moves) goto le; if(undoRequest){ //both players pressed undo simultaneously if(undoRequest<0) undoRequest=y; amax(undoRequest, y); postUndo(); } else{ c=msg1(MB_YESNO|MB_ICONQUESTION, lng(876, "The other player wants to UNDO the last move.\r\nDo you agree ?")); if(c==IDYES){ undoRequest=y; wr1(C_UNDO_YES); postUndo(); } else{ wr1(C_UNDO_NO); } } break; case C_NEW_REQUEST: if(undoRequest){ if(undoRequest<0){ //both players pressed NewGame simultaneously postNewGame(); } else{ postUndo(); } } else{ c=msg1(MB_YESNO|MB_ICONQUESTION, lng(877, "The other player wants to start a NEW game.\r\nDo you agree ?")); if(c==IDYES){ undoRequest=-1; wr1(C_NEW_YES); postNewGame(); } else{ wr1(C_NEW_NO); } } break; case C_UNDO_YES: if(undoRequest<=0) goto le; postUndo(); break; case C_UNDO_NO: if(undoRequest>0){ msglng(878, "Sorry, the other player does not allow to UNDO your move."); undoRequest=0; } break; case C_NEW_YES: if(undoRequest>=0) goto le; postNewGame(); break; case C_NEW_NO: if(undoRequest<0){ msglng(879, "Sorry, the other player does not allow to start a NEW game."); undoRequest=0; } break; default: //move or error if(x<0 || x>=width){ show(logDlg); goto le; } while(finished && (getTickCount()-lastTick<5000 || saveLock)){ Sleep(200); } if(finished) SendMessage(hWin, WM_COMMAND, 101, 0); y=rd1(); if(y<0 || y>=height) goto le; p=Square(x, y); p->time=rd4(); PostMessage(hWin, WM_COMMAND, 991, (LPARAM)p); } } le: EnterCriticalSection(&netLock); netGameDone(); LeaveCriticalSection(&netLock); return 0; }
int main(int argc, const char * argv[] ) { // setting up GLFW process glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // initialize the window with GLFW GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "Assignment1", nullptr, nullptr); //make the program listen to the key input glfwSetKeyCallback(window, key_exit); // Handle window not created successfully if(window == nullptr) { cout << "Failed to create a window" << endl; glfwTerminate(); return -1; } glfwMakeContextCurrent(window); // setting up the GLEW glewInit(); glewExperimental = GL_TRUE; if(glewInit() != GLEW_OK) { cout << "Failed to initialize GLEW" << endl; return -1; } //random colors vector vector<glm::vec4> colors = generateColor(); //color iterator auto j = colors.begin(); //randome rectangles vector vector<validRectangle> rectangles; rectangles.push_back(generateRectanle()); for(int i = RECNUM;i>=0;--i) { rectangles.push_back(generateRectanle()); } int width, height; glfwGetFramebufferSize(window, &width, &height); glViewport(0, 0, width, height); // compile the shader GLuint vertexShader; vertexShader = glCreateShader(GL_VERTEX_SHADER); //Next we attach the shader source code to the shader object and compile the shader: glShaderSource(vertexShader, 1, &vertexShaderSource2, NULL); glCompileShader(vertexShader); //check if the complication is sucessful GLint success; GLchar infoLog[512]; glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success); if(!success) { glGetShaderInfoLog(vertexShader, 512, NULL, infoLog); std::cout << "ERROR::SHADER::VERTEX::COMPILATION_FAILED\n" << infoLog << std::endl; } //compile the fragmentShader GLuint fragmentShader; fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(fragmentShader,1,&fragmentShaderSource2,NULL); glCompileShader(fragmentShader); // Shader Program GLuint shaderProgram; shaderProgram = glCreateProgram(); // attch the shader to program created glAttachShader(shaderProgram,vertexShader); glAttachShader(shaderProgram,fragmentShader); glLinkProgram(shaderProgram); // check if the link is succesfful glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success); if(!success) { glGetProgramInfoLog(shaderProgram, 512, NULL, infoLog); } // glUseProgram(shaderProgram); // we can delete them after the link glDeleteShader(vertexShader); glDeleteShader(fragmentShader); // draw indices GLuint indices[] = { 0, 2, 3, 1, 2, 3 }; // GLuint indices[] = { // 3, 3, 2, // 1, 2, 3 // }; // // setting up buffer and attribute objects GLuint VBOs[RECNUM],VAOs[RECNUM],EBOs[RECNUM]; glGenVertexArrays(RECNUM,VAOs); // Generate multiple VAOs glGenBuffers(RECNUM,VBOs); glGenBuffers(RECNUM,EBOs); //testing more random std::random_device rd2; // obtain a random number from hardware std::mt19937 eng(rd2()); // seed the generator std::uniform_real_distribution<> distr_1(-0.25, 0.25); std::uniform_real_distribution<> distr_2(-0.25, 0.25 );// define the range float xChange = distr_1(eng); float yChange = distr_2(eng); float zChange = distr_1(eng); float wChange = distr_1(eng); //generate rectangles store them into VAOs and VBOs int counter = 0; for(auto i = rectangles.begin();i!=rectangles.end();i++) { //originally z should be 1.0f but now we're making it random // and the x and y is just the point values GLfloat vertices[] { i->firstPoint.x + xChange,i->firstPoint.y + xChange,xChange, i->secondPoint.x + yChange,i->secondPoint.y + yChange,yChange, i->thirdPoint.x + zChange,i->thirdPoint.y + zChange,zChange, i->fouthPoint.x + wChange, i->fouthPoint.y + wChange,wChange, }; glBindVertexArray(VAOs[counter]); glBindBuffer(GL_ARRAY_BUFFER,VBOs[counter]); glBufferData(GL_ARRAY_BUFFER,sizeof(vertices),vertices,GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,EBOs[1]); glBufferData(GL_ELEMENT_ARRAY_BUFFER,sizeof(indices),indices,GL_STATIC_DRAW); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0); glEnableVertexAttribArray(0); glBindVertexArray(0); counter++; } vector<glm::mat4> transforms; // generate random transform matrix for each rectangles and store them into a vector so // that we'd be to change them and acess them for(int j = 0 ; j < RECNUM;j++) { glm::mat4 transform; transforms.push_back(transform); }; //drawing process while(!glfwWindowShouldClose(window)) { // Check if any events have been activiated (key pressed, mouse moved etc.) and call corresponding response functions glfwPollEvents(); //rendering commands here glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); //test random color std::random_device rd; // obtain a random number from hardware std::mt19937 eng(rd()); // seed the generator std::uniform_int_distribution<> distr(1, 2000); std::uniform_int_distribution<> distr2(1, 2000);// define the range GLint vertexColorLocation = glGetUniformLocation(shaderProgram,"ourColor"); // Draw our first rectangle glUseProgram(shaderProgram); // Create transformations // glm::mat4 transform; glm::mat4 reverse; // Get matrix's uniform location and set matrix GLint transformLoc = glGetUniformLocation(shaderProgram, "transform"); GLint reverseLoc = glGetUniformLocation(shaderProgram,"reverse"); //drawing multiples for (int i = 0 ; i < RECNUM ;i ++ ) { if(start) { glm::mat4 transform = transforms[i]; int xscale = distr(eng); int yscale = distr2(eng); if(i%2==0) { transforms[i]= glm::scale(transform,glm::vec3(1.0f - cos((GLfloat)glfwGetTime())/xscale/10,1.0f,1.0f)); transform = transforms[i]; transforms[i] = glm::rotate(transform,xscale*1.0f/50000,glm::vec3(yscale/100.0,yscale/100.0 ,sin(yscale/100.0))); transform = transforms[i]; transforms[i] = glm::translate(transform, glm::vec3(cos(xscale)/50*sin(yscale/100),cos(xscale)/50*sin(yscale/100),cos(xscale)/100*sin(yscale/100))); } else { transforms[i]= glm::scale(transform,glm::vec3(1.0f,1.0f - cos((GLfloat)glfwGetTime())/xscale/10,1.0f)); transform = transforms[i]; transforms[i] = glm::rotate(transform,xscale*1.0f/50000,glm::vec3(-yscale/100.0,-yscale/100.0,-yscale/100.0)); transform = transforms[i]; transforms[i] = glm::translate(transform, glm::vec3(sin(xscale)/30*cos(yscale/40),sin(xscale)/20*cos(yscale/10),0.0f)); } } glUniformMatrix4fv(transformLoc, 1, GL_FALSE, glm::value_ptr(transforms[i])); glUniformMatrix4fv(reverseLoc,1,GL_FALSE,glm::value_ptr(reverse)); glUniform4f(vertexColorLocation,j[i].x,j[i].y,j[i].z,j[i].w); glBindVertexArray(VAOs[i]); glDrawElements(GL_TRIANGLES, 6,GL_UNSIGNED_INT, 0); } glBindVertexArray(0); // Swap the screen buffers glfwSwapBuffers(window); } // Properly de-allocate all resources once they've outlived their purpose glDeleteVertexArrays(RECNUM, VAOs); glDeleteBuffers(RECNUM, VBOs); // Terminate GLFW, clearing any resources allocated by GLFW. glfwTerminate(); return 0; }
int main() { // Create the main window sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Hello World - SFML"); CollisionRectangle r1(glm::vec2(5,5), glm::vec2(100, 40)), r2(glm::vec2(200, 100), glm::vec2(50, 120)); r1.setOrigin(glm::vec2(50, 20)); r2.setOrigin(glm::vec2(10, 30)); r1.setRotation(DEG2RAD(138.f)); bool choose = false; bool r1Col(false), r2Col(false); // Start the main loop while (App.isOpen()) { // Process events sf::Event Event; while (App.pollEvent(Event)) { // Close window : exit if (Event.type == sf::Event::Closed || (Event.type == sf::Event::KeyPressed && Event.key.code == sf::Keyboard::Escape)) App.close(); if (Event.type == sf::Event::KeyPressed && Event.key.code == sf::Keyboard::Space) { choose = !choose; } if (Event.type == sf::Event::KeyPressed && Event.key.code == sf::Keyboard::Return) { r1Col = r1.checkCollision(r2); r2Col = r2.checkCollision(r1); std::cout<<"\n"; } if (Event.type == sf::Event::MouseWheelMoved) { if (choose) r1.rotate(DEG2RAD(Event.mouseWheel.delta)*5.f); else r2.rotate(DEG2RAD(Event.mouseWheel.delta)); } } if (choose) r1.setPosition(glm::vec2(sf::Mouse::getPosition(App).x, sf::Mouse::getPosition(App).y)); else r2.setPosition(glm::vec2(sf::Mouse::getPosition(App).x, sf::Mouse::getPosition(App).y)); // Clear screen, and fill it with blue App.clear(sf::Color::Black); sf::ConvexShape rd1(4), rd2(4); rd1.setOutlineColor(sf::Color::Blue); rd1.setFillColor(sf::Color(0.f, 0.f, 0.f, 0.f)); rd1.setOutlineThickness(2.f); rd2.setOutlineColor(sf::Color::Blue); rd2.setFillColor(sf::Color(0.f, 0.f, 0.f, 0.f)); rd2.setOutlineThickness(2.f); r1Col = r1.checkCollision(r2); r2Col = r2.checkCollision(r1); if (r1Col || r1.isPointInside(glm::vec2(0.f, 0.f))) rd1.setOutlineColor(sf::Color::Green); if (r2Col) rd2.setOutlineColor(sf::Color::Green); for (int i = 0; i < 4; i++) { rd1.setPoint(i, sf::Vector2f(r1.getVertex(i).x, r1.getVertex(i).y)); rd2.setPoint(i, sf::Vector2f(r2.getVertex(i).x, r2.getVertex(i).y)); } App.draw(rd1); App.draw(rd2); // Display the content of the window on screen App.display(); } return 0; }