<commit_before>#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "scene.h"
#include "event.h"
#include "point.h"
#include "frame.h"
#include "solid.h"
#include "color.h"
#include "SDL/SDL.h"

#include <readline/readline.h>
#include <readline/history.h>

#define MAXLENGTH 128

static struct {
    Frame camera;
    Frame origin;

    Point light;

    Solid **solidBuffer;
    int nbSolid;
    int bufferSize;

    SDL_Surface *screen;
    int wfov;
    int hfov;
    int screenWidth;
    int screenHeight;
    float nearplan;
    float farplan;
    float *zBuffer;
    int *backBuffer;
} scene;

static void resetZBuffer(float *zBuffer)
{
    int size = scene.screenWidth * scene.screenHeight;
    for (int i = 0; i < size; i++)
	zBuffer[i] = -1.;
}

static void resetBackBuffer(int *backBuffer)
{
    int size = scene.screenWidth * scene.screenHeight;
    for (int i = 0; i < size; i++)
	backBuffer[i] = -1.;
}

static void initLight(Point *light, float x, float y, float z)
{
    setPoint(light, x, y, z);
    normalizePoint(light, light);
}

static void initSDL(void)
{
    if (SDL_Init(SDL_INIT_VIDEO) == -1) {
	fprintf(stderr, "Error SDL_Init: %s", SDL_GetError());
	exit(EXIT_FAILURE);
    }
    if ((scene.screen = SDL_SetVideoMode(scene.screenWidth, scene.screenHeight, 
					 32, SDL_HWSURFACE | SDL_DOUBLEBUF)) 
	== NULL) {
	fprintf(stderr, "Error SDL_SetVideoMode: %s", SDL_GetError());
	exit(EXIT_FAILURE);
    }
    SDL_WM_SetCaption("3Displayer", NULL);
    SDL_EnableKeyRepeat(1, 10);
}

/* static void cutNewLine(char *input) */
/* { */
/*     int i; */
/*     for (i = 0; input[i] && input[i] != '\n'; i++); */
/*     input[i] = '\0'; */
/* } */

void initScene(void)
{
    scene.nbSolid = 0;
    scene.bufferSize = 4;
    scene.wfov = 80;
    scene.hfov = 60;
    scene.screenWidth = 1200;
    scene.screenHeight = 900;
    scene.nearplan = 1.;
    scene.farplan = 20.;
    
    initLight(&scene.light, 1., -0.5, -2.);
    resetFrame(&scene.camera, 0., -5., 0.);
    resetFrame(&scene.origin, 0., 0., 0.);
    resetEvent();

    scene.solidBuffer = malloc(scene.bufferSize * sizeof(Solid*));
    scene.zBuffer = malloc(scene.screenWidth * scene.screenHeight * 
			   sizeof(float));
    scene.backBuffer = malloc(scene.screenWidth * scene.screenHeight * 
			      sizeof(int));
    initSDL();
}

void updateScene(int *stop)
{
    SDL_Event event;
    SDL_WaitEvent(&event);
    do {
	switch (event.type) {
	case SDL_QUIT:
	    *stop = 1;
	    break;
	case SDL_KEYDOWN:
	    handleKeyDownEvent(&event, stop);
	    break;
	case SDL_KEYUP:
	    handleKeyUpEvent(&event);
	    break;
	case SDL_MOUSEMOTION:
	    handleMouseMotionEvent(&event);
	    break;
	case SDL_MOUSEBUTTONUP:
	    handleMouseButtonUpEvent(&event);
	    break;
	case SDL_MOUSEBUTTONDOWN:
	    handleMouseButtonDownEvent(&event);
	    break;
	}
    } while (SDL_PollEvent(&event));
}

static void remove_space(char *buf)
{
    while (*buf) {
	if (*buf == ' ') {
	    *buf = 0;
	    return;
	}
	++buf;
    }
}
void askSolidForScene(void)
{
    Solid *solid;
    char *buf, *objstr;
    
    buf = readline("obj path: ");
    remove_space(buf);
    objstr = strdup(buf);
    add_history(buf);
    buf = readline("bmp path: ");
    remove_space(buf);    

    if ((solid = loadSolid(objstr, buf)))
	addSolidToScene(solid);
    free(objstr);
    add_history(buf);<commit_msg>Supprime la fonction cutNewLine désormais inutile<commit_after>#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "scene.h"
#include "event.h"
#include "point.h"
#include "frame.h"
#include "solid.h"
#include "color.h"
#include "SDL/SDL.h"

#include <readline/readline.h>
#include <readline/history.h>

#define MAXLENGTH 128

static struct {
    Frame camera;
    Frame origin;

    Point light;

    Solid **solidBuffer;
    int nbSolid;
    int bufferSize;

    SDL_Surface *screen;
    int wfov;
    int hfov;
    int screenWidth;
    int screenHeight;
    float nearplan;
    float farplan;
    float *zBuffer;
    int *backBuffer;
} scene;

static void resetZBuffer(float *zBuffer)
{
    int size = scene.screenWidth * scene.screenHeight;
    for (int i = 0; i < size; i++)
	zBuffer[i] = -1.;
}

static void resetBackBuffer(int *backBuffer)
{
    int size = scene.screenWidth * scene.screenHeight;
    for (int i = 0; i < size; i++)
	backBuffer[i] = -1.;
}

static void initLight(Point *light, float x, float y, float z)
{
    setPoint(light, x, y, z);
    normalizePoint(light, light);
}

static void initSDL(void)
{
    if (SDL_Init(SDL_INIT_VIDEO) == -1) {
	fprintf(stderr, "Error SDL_Init: %s", SDL_GetError());
	exit(EXIT_FAILURE);
    }
    if ((scene.screen = SDL_SetVideoMode(scene.screenWidth, scene.screenHeight, 
					 32, SDL_HWSURFACE | SDL_DOUBLEBUF)) 
	== NULL) {
	fprintf(stderr, "Error SDL_SetVideoMode: %s", SDL_GetError());
	exit(EXIT_FAILURE);
    }
    SDL_WM_SetCaption("3Displayer", NULL);
    SDL_EnableKeyRepeat(1, 10);
}

void initScene(void)
{
    scene.nbSolid = 0;
    scene.bufferSize = 4;
    scene.wfov = 80;
    scene.hfov = 60;
    scene.screenWidth = 1200;
    scene.screenHeight = 900;
    scene.nearplan = 1.;
    scene.farplan = 20.;
    
    initLight(&scene.light, 1., -0.5, -2.);
    resetFrame(&scene.camera, 0., -5., 0.);
    resetFrame(&scene.origin, 0., 0., 0.);
    resetEvent();

    scene.solidBuffer = malloc(scene.bufferSize * sizeof(Solid*));
    scene.zBuffer = malloc(scene.screenWidth * scene.screenHeight * 
			   sizeof(float));
    scene.backBuffer = malloc(scene.screenWidth * scene.screenHeight * 
			      sizeof(int));
    initSDL();
}

void updateScene(int *stop)
{
    SDL_Event event;
    SDL_WaitEvent(&event);
    do {
	switch (event.type) {
	case SDL_QUIT:
	    *stop = 1;
	    break;
	case SDL_KEYDOWN:
	    handleKeyDownEvent(&event, stop);
	    break;
	case SDL_KEYUP:
	    handleKeyUpEvent(&event);
	    break;
	case SDL_MOUSEMOTION:
	    handleMouseMotionEvent(&event);
	    break;
	case SDL_MOUSEBUTTONUP:
	    handleMouseButtonUpEvent(&event);
	    break;
	case SDL_MOUSEBUTTONDOWN:
	    handleMouseButtonDownEvent(&event);
	    break;
	}
    } while (SDL_PollEvent(&event));
}

static void remove_space(char *buf)
{
    while (*buf) {
	if (*buf == ' ') {
	    *buf = 0;
	    return;
	}
	++buf;
    }
}

void askSolidForScene(void)
{
    Solid *solid;
    char *buf, *objstr;
    
    buf = readline("obj path: ");
    remove_space(buf);
    objstr = strdup(buf);
    add_history(buf);
    buf = readline("bmp path: ");
    remove_space(buf);    

    if ((solid = loadSolid(objstr, buf)))
	addSolidToScene(solid);
    free(objstr);
    add_history(buf);
{'fraction_non_alphanumeric': 0.14578931482040447, 'fraction_numerical': 0.012979172955025656, 'mean_word_length': 3.1187072715972652, 'pattern_counts': {'":': 0, '<': 17, '<?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': '6218583', 'n_tokens_mistral': 2595, 'n_tokens_neox': 2403, 'n_words': 533}