<commit_before>// Copyright (C) 2016 <NAME>
// This file is part of the Ouzel engine.

#import "OpenGLView.h"
#include "Engine.h"
#include "RendererOGL.h"
#include "Input.h"

static CVReturn renderCallback(CVDisplayLinkRef displayLink,
                               const CVTimeStamp *inNow,
                               const CVTimeStamp *inOutputTime,
                               CVOptionFlags flagsIn,
                               CVOptionFlags *flagsOut,
                               void *displayLinkContext)
{
    [(__bridge OpenGLView*)displayLinkContext draw];
    
    return kCVReturnSuccess;
}

using namespace ouzel;

@implementation OpenGLView

-(id)initWithFrame:(NSRect)frameRect
{
    // Create pixel format
    NSOpenGLPixelFormatAttribute attributes[] =
    {
        NSOpenGLPFADoubleBuffer,
        NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core, // ensure we're using 3.2
        NSOpenGLPFAColorSize, 24,
        NSOpenGLPFAAlphaSize, 8,
        NSOpenGLPFADepthSize, 32, // set depth buffer size
        0
    };
    
    NSOpenGLPixelFormat* pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
    
    self = [super initWithFrame:frameRect pixelFormat:pixelFormat];
    if (self != nil)
    {
        _running = NO;
        _resized = NO;
        
        // Create OpenGL context
        self.openGLContext = [[NSOpenGLContext alloc] initWithFormat:self.pixelFormat shareContext:NULL];
        [self.openGLContext setView:self];
        [self.openGLContext makeCurrentContext];
        
        NSMenu* mainMenu = [[NSMenu alloc] initWithTitle:@"Main Menu"];
        
        NSMenuItem* mainMenuItem = [[NSMenuItem alloc] initWithTitle:@"Ouzel" action:nil keyEquivalent:@""];
        [mainMenu addItem:mainMenuItem];
        
        NSMenu* subMenu = [[NSMenu alloc] initWithTitle:@"Ouzel"];
        [mainMenuItem setSubmenu:subMenu];
        
        NSMenuItem* quitItem = [[NSMenuItem alloc] initWithTitle:@"Quit" action:@selector(handleQuit:) keyEquivalent:@"q"];
        [subMenu addItem:quitItem];
        
        [NSApplication sharedApplication].mainMenu = mainMenu;
    }
    
    return self;
}

-(void)dealloc
{
    CVDisplayLinkRelease(_displayLink);
}

-(BOOL)isFlipped
{
    return YES;
}

-(BOOL)acceptsFirstMouse:(NSEvent*)theEvent
{
    return YES;
}

-(void)prepareOpenGL
{
    std::shared_ptr<RendererOGL> renderer = std::static_pointer_cast<RendererOGL>(Engine::getInstance()->getRenderer());
    renderer->initOpenGL(_frame.size.width, _frame.size.height, 0);
    
    GLint swapInt = 1;
    [self.openGLContext setValues:&swapInt forParameter:NSOpenGLCPSwapInterval];
    
    _displayId = (CGDirectDisplayID)[[[[_window screen] deviceDescription]objectForKey:@"NSScreenNumber"] intValue];
    
    CVDisplayLinkCreateWithCGDisplay(_displayId, &_displayLink);
    CVDisplayLinkSetOutputCallback(_displayLink, renderCallback, (__bridge void *)self);
    
    CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(_displayLink, [self.openGLContext CGLContextObj], [self.pixelFormat CGLPixelFormatObj]);
    
    CVDisplayLinkStart(_displayLink);
    _running = YES;
}

-(void)close
{
    _running = NO;
    
    CGLLockContext([self.openGLContext CGLContextObj]);
    [self.openGLContext makeCurrentContext];
    
    CVDisplayLinkStop(_displayLink);
    
    CGLUnlockContext([self.openGLContext CGLContextObj]);
}

-(void)changeDisplay
{
    CGDirectDisplayID displayId = (CGDirectDisplayID)[[[[_window screen] deviceDescription] objectForKey:@"NSScreenNumber"] intValue];
    
    if(displayId != 0 && _displayId != displayId)<commit_msg>Use unsignedIntValue instead of intValue<commit_after>// Copyright (C) 2016 <NAME>
// This file is part of the Ouzel engine.

#import "OpenGLView.h"
#include "Engine.h"
#include "RendererOGL.h"
#include "Input.h"

static CVReturn renderCallback(CVDisplayLinkRef displayLink,
                               const CVTimeStamp *inNow,
                               const CVTimeStamp *inOutputTime,
                               CVOptionFlags flagsIn,
                               CVOptionFlags *flagsOut,
                               void *displayLinkContext)
{
    [(__bridge OpenGLView*)displayLinkContext draw];
    
    return kCVReturnSuccess;
}

using namespace ouzel;

@implementation OpenGLView

-(id)initWithFrame:(NSRect)frameRect
{
    // Create pixel format
    NSOpenGLPixelFormatAttribute attributes[] =
    {
        NSOpenGLPFADoubleBuffer,
        NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core, // ensure we're using 3.2
        NSOpenGLPFAColorSize, 24,
        NSOpenGLPFAAlphaSize, 8,
        NSOpenGLPFADepthSize, 32, // set depth buffer size
        0
    };
    
    NSOpenGLPixelFormat* pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
    
    self = [super initWithFrame:frameRect pixelFormat:pixelFormat];
    if (self != nil)
    {
        _running = NO;
        _resized = NO;
        
        // Create OpenGL context
        self.openGLContext = [[NSOpenGLContext alloc] initWithFormat:self.pixelFormat shareContext:NULL];
        [self.openGLContext setView:self];
        [self.openGLContext makeCurrentContext];
        
        NSMenu* mainMenu = [[NSMenu alloc] initWithTitle:@"Main Menu"];
        
        NSMenuItem* mainMenuItem = [[NSMenuItem alloc] initWithTitle:@"Ouzel" action:nil keyEquivalent:@""];
        [mainMenu addItem:mainMenuItem];
        
        NSMenu* subMenu = [[NSMenu alloc] initWithTitle:@"Ouzel"];
        [mainMenuItem setSubmenu:subMenu];
        
        NSMenuItem* quitItem = [[NSMenuItem alloc] initWithTitle:@"Quit" action:@selector(handleQuit:) keyEquivalent:@"q"];
        [subMenu addItem:quitItem];
        
        [NSApplication sharedApplication].mainMenu = mainMenu;
    }
    
    return self;
}

-(void)dealloc
{
    CVDisplayLinkRelease(_displayLink);
}

-(BOOL)isFlipped
{
    return YES;
}

-(BOOL)acceptsFirstMouse:(NSEvent*)theEvent
{
    return YES;
}

-(void)prepareOpenGL
{
    std::shared_ptr<RendererOGL> renderer = std::static_pointer_cast<RendererOGL>(Engine::getInstance()->getRenderer());
    renderer->initOpenGL(_frame.size.width, _frame.size.height, 0);
    
    GLint swapInt = 1;
    [self.openGLContext setValues:&swapInt forParameter:NSOpenGLCPSwapInterval];
    
    _displayId = (CGDirectDisplayID)[[[[_window screen] deviceDescription]objectForKey:@"NSScreenNumber"] unsignedIntValue];
    
    CVDisplayLinkCreateWithCGDisplay(_displayId, &_displayLink);
    CVDisplayLinkSetOutputCallback(_displayLink, renderCallback, (__bridge void *)self);
    
    CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(_displayLink, [self.openGLContext CGLContextObj], [self.pixelFormat CGLPixelFormatObj]);
    
    CVDisplayLinkStart(_displayLink);
    _running = YES;
}

-(void)close
{
    _running = NO;
    
    CGLLockContext([self.openGLContext CGLContextObj]);
    [self.openGLContext makeCurrentContext];
    
    CVDisplayLinkStop(_displayLink);
    
    CGLUnlockContext([self.openGLContext CGLContextObj]);
}

-(void)changeDisplay
{
    CGDirectDisplayID displayId = (CGDirectDisplayID)[[[[_window screen] deviceDescription] objectForKey:@"NSScreenNumber"] unsignedIntValue];
    
    if(displayId != 0 && _displayId != displayId)
{'fraction_non_alphanumeric': 0.10138375119879435, 'fraction_numerical': 0.004658172352377038, 'mean_word_length': 3.246655031995346, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '4518033', 'n_tokens_mistral': 2220, 'n_tokens_neox': 2112, 'n_words': 399}