<commit_before>#include <GL/gl.h>
#include <GL/glu.h>
#include <SDL/SDL.h>
#include <list>
#include <algorithm>
#include <functional>

#include "scene/GraphNode.h"
#include "animations/Animation.h"

GraphNode* scene = NULL;
std::list<Animation*> animations;

class TestTriangle : public GraphNode
{
private:

public:
	virtual void doRender()
	{
		glBegin(GL_TRIANGLES);					
			glColor3f(0.0f,0.0f,1.0f);			
			glVertex3f( 0.0f, 1.0f, 0.0f);		
			glColor3f(0.0f,1.0f,0.0f);			
			glVertex3f(-1.0f,-1.0f, 0.0f);		
			glColor3f(1.0f,0.0f,0.0f);			
			glVertex3f( 1.0f,-1.0f, 0.0f);		
		glEnd();
	}
};

class TestSceneRotation : public Animation
{
private:
	float rotation;
	GraphNode* subject;

public:
	TestSceneRotation(GraphNode* subject) : subject(subject) 
	{
		rotation = 0;
	};

	virtual void update(float timestep)
	{
		subject->setRotation(40.0f, rotation++, 0.0f);
	}
};

void reshape(int width, int height)
{
	GLfloat ratio = (GLfloat) width / (GLfloat) height;

	glViewport(0, 0, (GLint) width, (GLint) height);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(60.0f, ratio, 1.0f, 10.0f);
}

/// Sets up rendering and creates the initial scene graph.
void init_scene()
{
	/*static GLfloat pos[4] =
	{5.0, 5.0, 10.0, 0.0};
	glLightfv(GL_LIGHT0, GL_POSITION, pos);
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);*/
	glEnable(GL_NORMALIZE);
	glEnable(GL_CULL_FACE);
	glEnable(GL_DEPTH_TEST);

	scene = new GraphNode;
	TestTriangle *tt = new TestTriangle;
	scene->addMember(tt);

	animations.push_back(new TestSceneRotation(scene));
}

/// Sets up a new frame and renders the scene.
void draw_scene()
{
	static float rotation = 0;
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	scene->setPosition(0.0f, 0.0f, -3.0f);

	scene->render();
	glFlush();
	SDL_GL_SwapBuffers();
}

/// Updates scene state
void update_scene()
{
	float timestep = 0.1f;
	std::for_each(
			animations.begin(),
			animations.end(),
			std::bind2nd(std::mem_fun(&Animation::update), timestep));
}

int main(int argc, char const *argv[])
{
	SDL_Surface *screen;
	Uint8 *keys;

	if (0 != SDL_Init(SDL_INIT_EVERYTHING)) return 1;

	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
	screen = SDL_SetVideoMode(640, 480, 32, SDL_OPENGL|SDL_RESIZABLE);
	if ( ! screen ) {
		puts(SDL_GetError());
		SDL_Quit();
		exit(2);
	}
	SDL_WM_SetCaption("Mech", "mech");
	reshape(screen->w, screen->h);
	init_scene();

	int done = 0;
	SDL_Event event;
	while (!done) {
		while (SDL_PollEvent(&event)) {
			switch(event.type) {
				case SDL_VIDEORESIZE:
					screen = SDL_SetVideoMode(event.resize.w, event.resize.h, 16,
							SDL_OPENGL|SDL_RESIZABLE);
					if (screen)
						reshape(screen->w, screen->h);
					break;

				case SDL_QUIT:
					done = 1;
					break;
			}
		}
		keys = SDL_GetKeyState(NULL);

		if (keys[SDLK_ESCAPE]) {
			done = 1;
		}

		// update
		update_scene();

		// render
		draw_scene();
	}
	SDL_Quit();<commit_msg>Give update_scene the actual timestep.<commit_after>#include <GL/gl.h>
#include <GL/glu.h>
#include <SDL/SDL.h>
#include <list>
#include <algorithm>
#include <functional>

#include "scene/GraphNode.h"
#include "animations/Animation.h"

GraphNode* scene = NULL;
std::list<Animation*> animations;

class TestTriangle : public GraphNode
{
private:

public:
	virtual void doRender()
	{
		glBegin(GL_TRIANGLES);					
			glColor3f(0.0f,0.0f,1.0f);			
			glVertex3f( 0.0f, 1.0f, 0.0f);		
			glColor3f(0.0f,1.0f,0.0f);			
			glVertex3f(-1.0f,-1.0f, 0.0f);		
			glColor3f(1.0f,0.0f,0.0f);			
			glVertex3f( 1.0f,-1.0f, 0.0f);		
		glEnd();
	}
};

class TestSceneRotation : public Animation
{
private:
	float rotation;
	GraphNode* subject;

public:
	TestSceneRotation(GraphNode* subject) : subject(subject) 
	{
		rotation = 0;
	};

	virtual void update(float timestep)
	{
		subject->setRotation(40.0f, rotation += timestep, 0.0f);
	}
};

void reshape(int width, int height)
{
	GLfloat ratio = (GLfloat) width / (GLfloat) height;

	glViewport(0, 0, (GLint) width, (GLint) height);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(60.0f, ratio, 1.0f, 10.0f);
}

/// Sets up rendering and creates the initial scene graph.
void init_scene()
{
	/*static GLfloat pos[4] =
	{5.0, 5.0, 10.0, 0.0};
	glLightfv(GL_LIGHT0, GL_POSITION, pos);
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);*/
	glEnable(GL_NORMALIZE);
	glEnable(GL_CULL_FACE);
	glEnable(GL_DEPTH_TEST);

	scene = new GraphNode;
	TestTriangle *tt = new TestTriangle;
	scene->addMember(tt);

	animations.push_back(new TestSceneRotation(scene));
}

/// Sets up a new frame and renders the scene.
void draw_scene()
{
	static float rotation = 0;
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	scene->setPosition(0.0f, 0.0f, -3.0f);

	scene->render();
	glFlush();
	SDL_GL_SwapBuffers();
}

/// Updates scene state
void update_scene(float timestep)
{
	std::for_each(
			animations.begin(),
			animations.end(),
			std::bind2nd(std::mem_fun(&Animation::update), timestep));
}

int main(int argc, char const *argv[])
{
	SDL_Surface *screen;
	Uint8 *keys;

	if (0 != SDL_Init(SDL_INIT_EVERYTHING)) return 1;

	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
	screen = SDL_SetVideoMode(640, 480, 32, SDL_OPENGL|SDL_RESIZABLE);
	if ( ! screen ) {
		puts(SDL_GetError());
		SDL_Quit();
		exit(2);
	}
	SDL_WM_SetCaption("Mech", "mech");
	reshape(screen->w, screen->h);
	init_scene();

	Uint32 previous_ticks = SDL_GetTicks();

	int done = 0;
	SDL_Event event;
	while (!done) {
		while (SDL_PollEvent(&event)) {
			switch(event.type) {
				case SDL_VIDEORESIZE:
					screen = SDL_SetVideoMode(event.resize.w, event.resize.h, 16,
							SDL_OPENGL|SDL_RESIZABLE);
					if (screen)
						reshape(screen->w, screen->h);
					break;

				case SDL_QUIT:
					done = 1;
					break;
			}
		}
		keys = SDL_GetKeyState(NULL);

		if (keys[SDLK_ESCAPE]) {
			done = 1;
		}

		// update
		Uint32 t = SDL_GetTicks();
		update_scene((float)(t - previous_ticks) / 1000);
		previous_ticks = t;

		// render
		draw_scene();
	}
	SDL_Quit();
{'fraction_non_alphanumeric': 0.14973918379871126, 'fraction_numerical': 0.03283215710340595, 'mean_word_length': 4.361019736842105, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '148118', 'n_tokens_mistral': 3078, 'n_tokens_neox': 2687, 'n_words': 498}