<commit_before>#include "main.h"

Point _resolution;
Point _windowSize;
int _pixel_scale;
Rectangle _drawRect;
bool _shouldClose;
ImageID _nextImage;
bool _heldInputs[INPUT_MAX];
bool _pressedInputs[INPUT_MAX];

typedef struct
{
  GLuint gluint;
  Point size;
} Image;
Image _images[IMAGE_MAX];
#define NULL_IMAGE {0, NULL_POINT}

int GLFWCALL _sys_close_callback();

void sys_init(Point resolution, int pixel_scale)
{
  bool result;
  int i;
  GLuint image_ids[IMAGE_MAX];
  _resolution = resolution;
  _pixel_scale = pixel_scale;
  _shouldClose = false;
  _nextImage = 0;
  
  LOG("Initialize GLFW");

  result = glfwInit();
  if(!result)
  {
    LOG("Failed to initialize GLFW");
    exit( EXIT_FAILURE );
  }
  result = glfwOpenWindow( _resolution.x*_pixel_scale, _resolution.y*_pixel_scale,
                           0,0,0,0, 0,0, GLFW_WINDOW );
  if(!result)
  {
    LOG("Failed to open GLFW window");
    exit( EXIT_FAILURE );
  }
  
  // Detect key presses between calls to GetKey
  glfwEnable( GLFW_STICKY_KEYS );
  
  // Enable vertical sync (on cards that support it)
  glfwSwapInterval( 1 );
  
  glfwSetWindowCloseCallback(_sys_close_callback);
  
  LOG("Initialize DevIL");
  
  // devil init  
  ilInit();
  
  glGenTextures(IMAGE_MAX, image_ids);
  Image nullImage = NULL_IMAGE;
  for(i=0; i<IMAGE_MAX; i++)
  {
    _images[i] = nullImage;
    _images[i].gluint = image_ids[i];
  }

  srand(time(NULL));
}

int GLFWCALL _sys_close_callback()
{
  _shouldClose = true;
  return true;
}

bool sys_shouldClose()
{
  return _shouldClose;
}

void sys_close()
{
  glfwTerminate();
}

double sys_getTime()
{
  return glfwGetTime();
}

void sys_drawInit(Color col)
{
  Point maxPixelSize = NULL_POINT;
  Point drawRectSize = NULL_POINT;
  
  glfwGetWindowSize( &_windowSize.x, &_windowSize.y);  
  glViewport( 0, 0, _windowSize.x, _windowSize.y ); 
  
  glClearColor((float)col.r/255.0f, (float)col.g/255.0f, (float)col.b/255.0f, (float)col.a/255.0f);
  glClear( GL_COLOR_BUFFER_BIT );
  
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluOrtho2D(0, _windowSize.x, _windowSize.y,0);
  
  maxPixelSize.x = _windowSize.x/_resolution.x;
  maxPixelSize.y = _windowSize.y/_resolution.y;
  _pixel_scale = min(maxPixelSize.x, maxPixelSize.y);
  drawRectSize.x = _pixel_scale*_resolution.x;
  drawRectSize.y = _pixel_scale*_resolution.y;
  _drawRect.a.x = (_windowSize.x-drawRectSize.x)/2;
  _drawRect.a.y = (_windowSize.y-drawRectSize.y)/2;
  _drawRect.b.x = _drawRect.a.x+drawRectSize.x;
  _drawRect.b.y = _drawRect.a.y+drawRectSize.y;
  
  if (glfwGetKey(GLFW_KEY_ESC) == GLFW_PRESS)
    _shouldClose = true;
}

Point _sys_worldPointToScreenPoint(Point p)
{
  p.x *= _pixel_scale;
  p.y *= _pixel_scale;
  p.x += _drawRect.a.x;
  p.y += _drawRect.a.y;
  return p;
}

Rectangle _sys_worldRectangleToScreenRectangle(Rectangle r)
{
  r.a = _sys_worldPointToScreenPoint(r.a);
  r.b = _sys_worldPointToScreenPoint(r.b);
  return r;
}

void _sys_drawRectangle(Rectangle rect, Color col)
{
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  glColor4f((float)col.r/255.0f, (float)col.g/255.0f, (float)col.b/255.0f, (float)col.a/255.0f);
  glBegin(GL_QUADS);
  glVertex3f(rect.a.x, rect.a.y,1.0f);
  glVertex3f(rect.b.x, rect.a.y,1.0f);<commit_msg>Don't quit when pressing esc<commit_after>#include "main.h"

Point _resolution;
Point _windowSize;
int _pixel_scale;
Rectangle _drawRect;
bool _shouldClose;
ImageID _nextImage;
bool _heldInputs[INPUT_MAX];
bool _pressedInputs[INPUT_MAX];

typedef struct
{
  GLuint gluint;
  Point size;
} Image;
Image _images[IMAGE_MAX];
#define NULL_IMAGE {0, NULL_POINT}

int GLFWCALL _sys_close_callback();

void sys_init(Point resolution, int pixel_scale)
{
  bool result;
  int i;
  GLuint image_ids[IMAGE_MAX];
  _resolution = resolution;
  _pixel_scale = pixel_scale;
  _shouldClose = false;
  _nextImage = 0;
  
  LOG("Initialize GLFW");

  result = glfwInit();
  if(!result)
  {
    LOG("Failed to initialize GLFW");
    exit( EXIT_FAILURE );
  }
  result = glfwOpenWindow( _resolution.x*_pixel_scale, _resolution.y*_pixel_scale,
                           0,0,0,0, 0,0, GLFW_WINDOW );
  if(!result)
  {
    LOG("Failed to open GLFW window");
    exit( EXIT_FAILURE );
  }
  
  // Detect key presses between calls to GetKey
  glfwEnable( GLFW_STICKY_KEYS );
  
  // Enable vertical sync (on cards that support it)
  glfwSwapInterval( 1 );
  
  glfwSetWindowCloseCallback(_sys_close_callback);
  
  LOG("Initialize DevIL");
  
  // devil init  
  ilInit();
  
  glGenTextures(IMAGE_MAX, image_ids);
  Image nullImage = NULL_IMAGE;
  for(i=0; i<IMAGE_MAX; i++)
  {
    _images[i] = nullImage;
    _images[i].gluint = image_ids[i];
  }

  srand(time(NULL));
}

int GLFWCALL _sys_close_callback()
{
  _shouldClose = true;
  return true;
}

bool sys_shouldClose()
{
  return _shouldClose;
}

void sys_close()
{
  glfwTerminate();
}

double sys_getTime()
{
  return glfwGetTime();
}

void sys_drawInit(Color col)
{
  Point maxPixelSize = NULL_POINT;
  Point drawRectSize = NULL_POINT;
  
  glfwGetWindowSize( &_windowSize.x, &_windowSize.y);  
  glViewport( 0, 0, _windowSize.x, _windowSize.y ); 
  
  glClearColor((float)col.r/255.0f, (float)col.g/255.0f, (float)col.b/255.0f, (float)col.a/255.0f);
  glClear( GL_COLOR_BUFFER_BIT );
  
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluOrtho2D(0, _windowSize.x, _windowSize.y,0);
  
  maxPixelSize.x = _windowSize.x/_resolution.x;
  maxPixelSize.y = _windowSize.y/_resolution.y;
  _pixel_scale = min(maxPixelSize.x, maxPixelSize.y);
  drawRectSize.x = _pixel_scale*_resolution.x;
  drawRectSize.y = _pixel_scale*_resolution.y;
  _drawRect.a.x = (_windowSize.x-drawRectSize.x)/2;
  _drawRect.a.y = (_windowSize.y-drawRectSize.y)/2;
  _drawRect.b.x = _drawRect.a.x+drawRectSize.x;
  _drawRect.b.y = _drawRect.a.y+drawRectSize.y;
}

Point _sys_worldPointToScreenPoint(Point p)
{
  p.x *= _pixel_scale;
  p.y *= _pixel_scale;
  p.x += _drawRect.a.x;
  p.y += _drawRect.a.y;
  return p;
}

Rectangle _sys_worldRectangleToScreenRectangle(Rectangle r)
{
  r.a = _sys_worldPointToScreenPoint(r.a);
  r.b = _sys_worldPointToScreenPoint(r.b);
  return r;
}

void _sys_drawRectangle(Rectangle rect, Color col)
{
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  glColor4f((float)col.r/255.0f, (float)col.g/255.0f, (float)col.b/255.0f, (float)col.a/255.0f);
  glBegin(GL_QUADS);
  glVertex3f(rect.a.x, rect.a.y,1.0f);
  glVertex3f(rect.b.x, rect.a.y,1.0f);
{'fraction_non_alphanumeric': 0.13087713889317096, 'fraction_numerical': 0.01726529983043009, 'mean_word_length': 4.145122918318795, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '5165311', 'n_tokens_mistral': 2716, 'n_tokens_neox': 2648, 'n_words': 448}