#include "gameoflife.h" GameOfLife::GameOfLife(int _x, int _y) { init(); x = _x; y = _y; allocate(); } GameOfLife::GameOfLife(std::string file) { init(); load(file); } GameOfLife::GameOfLife(int _x, int _y, int r_life, int r_dead) { init(); fillRandom(_x, _y, r_life, r_dead); } void GameOfLife::init() { view3d = true; feld = 0; x = y = 0; generation = 0; thickness = 0.5f; cellwidth = 1.0f; torus = true; fullcelluse = true; radius = 0.3f; height = 1.0f; parts = 12; sectobuild = 0.91f; b_secdone = 0.0f; secpertick = 1.0f; t_secdone = 0.0f; editmode = false; // Calc cylinder sinvals sinval = new float[parts]; cosval = new float[parts]; for(int i=0; i> x; data >> y; data >> torus; if(x<=0 || y <=0) return false; cleanup(); allocate(); int j=0; getline(data, tmp); // Remove \n while(getline(data, tmp) && j=0 && _x=0 && _y0) setpos.y = ((int)setpos.y+y+1)%y; else if(up<0) setpos.y = ((int)setpos.y+y-1)%y; if(right>0) setpos.x = ((int)setpos.x+x+1)%x; else if(right<0) setpos.x = ((int)setpos.x+x-1)%x; } void GameOfLife::toggle() { if(feld[(int)setpos.x][(int)setpos.y]==born||feld[(int)setpos.x][(int)setpos.y]==alife) { feld[(int)setpos.x][(int)setpos.y] = dead; } else { feld[(int)setpos.x][(int)setpos.y] = alife; } } void GameOfLife::render(float sec) { if(!feld) return; // Cylinder-building-timer if(b_secdone<=sectobuild) { b_secdone += sec; if(b_secdone>=sectobuild) { lockStates(); } } // Tick-timer t_secdone += sec; if(t_secdone>=secpertick) { tick(); t_secdone = 0.0f; b_secdone = 0.0f; } if(view3d) { renderBrett(); for(int j=0; jw /(float)x; float hperp = screen->h /(float)y; float border; glPushMatrix(); if(wperpsecpertick) lockStates(); int near; int x1, y1; for(int i=0; i=x || b>=y))) continue; if(torus) { x1 = (a+x)%x; y1 = (b+y)%y; } else { x1 = a; y1 = b; } if(feld[x1][y1]==alife || (fullcelluse && (feld[x1][y1]==dies))) near++; } } if(feld[i][j]==alife) { if(near!=2 && near!=3) feld[i][j] = dies; } else if(feld[i][j]==dead) { if(near==3) feld[i][j] = born; } } } if(sectobuild<0.1f) lockStates(); generation++; } void GameOfLife::clear() { for(int i=0; i