init commit

This commit is contained in:
2024-11-12 17:41:10 +01:00
parent 1e4f1f955b
commit 20bc9108d3
146 changed files with 24465 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
#ifndef __SDLCOMMON_H
#define __SDLCOMMON_H
#include <SDL.h>
#include <SDL_image.h>
#ifndef PI
#define PI 3.141592
#endif
#ifndef NULLCOL
#define NULLCOL 0x00FF00FF
#define NULLCOLA 0xFF
#define NULLCOLR 0xFF
#define NULLCOLG 0x00
#define NULLCOLB 0xFF
#endif
void setpixel(SDL_Surface*, int, int, Uint8, Uint8, Uint8);
int getpixel(SDL_Surface*, int, int);
void DrawLine(SDL_Surface*, int , int , int , int , char , char, char);
void rotatesurface(SDL_Surface*, SDL_Surface*, int);
void interpole(SDL_Surface* , SDL_Surface* , Uint32 );
bool inCarArea(SDL_Surface* , int , int );
#endif

View File

@@ -0,0 +1,11 @@
/bg1.bmp/1.1/Wed Apr 13 15:04:02 2005//
/bg1.dia/1.1/Wed Apr 13 15:04:03 2005//
/bg2.bmp/1.1/Wed Apr 13 15:04:03 2005//
/bg2.dia/1.1/Wed Apr 13 15:04:02 2005//
/bg3.bmp/1.1/Wed Apr 13 15:04:03 2005//
/bg3.dia/1.1/Wed Apr 13 15:04:03 2005//
/bg4.bmp/1.1/Wed Apr 13 15:04:03 2005//
/bg4.dia/1.1/Wed Apr 13 15:04:03 2005//
/bg5.bmp/1.2/Wed Apr 13 15:04:03 2005//
/bg5.dia/1.2/Wed Apr 13 15:04:03 2005//
D

View File

@@ -0,0 +1 @@
ia2005/InterfaceCpp/Back

View File

@@ -0,0 +1 @@
:pserver:feeling@jfroche.be:/opt/cvsroot

BIN
InterfaceCpp/Back/bg1.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

BIN
InterfaceCpp/Back/bg1.dia Normal file

Binary file not shown.

BIN
InterfaceCpp/Back/bg2.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

BIN
InterfaceCpp/Back/bg2.dia Normal file

Binary file not shown.

BIN
InterfaceCpp/Back/bg3.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

BIN
InterfaceCpp/Back/bg3.dia Normal file

Binary file not shown.

BIN
InterfaceCpp/Back/bg4.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

BIN
InterfaceCpp/Back/bg4.dia Normal file

Binary file not shown.

BIN
InterfaceCpp/Back/bg5.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

BIN
InterfaceCpp/Back/bg5.dia Normal file

Binary file not shown.

View File

@@ -0,0 +1 @@
D

View File

@@ -0,0 +1 @@
ia2005/InterfaceCpp/CVS

View File

@@ -0,0 +1 @@
:pserver:feeling@jfroche.be:/opt/cvsroot

15
InterfaceCpp/CVS/Entries Normal file
View File

@@ -0,0 +1,15 @@
D/CVS////
D/Cars////
D/Back////
/Makefile/1.4/Wed Apr 13 15:04:03 2005//
/SFont.c/1.2/Wed Apr 13 15:04:03 2005//
/SFont.h/1.1/Wed Apr 13 15:04:03 2005//
/fenetre.h/1.4/Wed Apr 13 15:04:03 2005//
/font.png/1.1/Wed Apr 13 15:04:03 2005//
/main.cpp/1.3/Wed Apr 13 15:04:03 2005//
/sdlcommon.cpp/1.5/Thu Apr 14 17:40:11 2005//
/sdlcommon.h/1.4/Thu Apr 14 17:38:15 2005//
/car.cpp/1.20/Thu Apr 14 17:36:20 2005//
/car.h/1.11/Thu Apr 14 17:34:22 2005//
/shmdata.h/1.8/Thu Apr 14 16:59:58 2005//
/fenetre.cpp/1.22/Thu Apr 14 18:45:30 2005//

View File

@@ -0,0 +1 @@
ia2005/InterfaceCpp

1
InterfaceCpp/CVS/Root Normal file
View File

@@ -0,0 +1 @@
:pserver:feeling@jfroche.be:/opt/cvsroot

View File

@@ -0,0 +1,5 @@
/voiture1.bmp/1.1/Wed Apr 13 15:04:03 2005//
/voiture2.bmp/1.1/Wed Apr 13 15:04:03 2005//
/voiture3.bmp/1.1/Wed Apr 13 15:04:03 2005//
/voiture4.bmp/1.1/Wed Apr 13 15:04:03 2005//
D

View File

@@ -0,0 +1 @@
ia2005/InterfaceCpp/Cars

View File

@@ -0,0 +1 @@
:pserver:feeling@jfroche.be:/opt/cvsroot

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

BIN
InterfaceCpp/Cars/top.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 188 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

40
InterfaceCpp/Makefile Normal file
View File

@@ -0,0 +1,40 @@
#$Id: Makefile,v 1.4 2005/04/10 11:46:45 feeling Exp $'
CFLAGS= -Wno-deprecated -std=c++14
CPP= g++
GCC= gcc
INCLUDES= -L/usr/lib -I/usr/include/SDL
LIBS= -L/usr/lib -lSDL -lpthread -lSDL_image
all : interface
interface : fenetre.o main.o car.o sdlcommon.o SFont.o
$(CPP) fenetre.o main.o car.o sdlcommon.o SFont.o -o iface -L/usr/lib -lSDL -lpthread -lSDL_image -Wno-deprecated -std=c++14
fenetre.o : fenetre.cpp
$(CPP) -c fenetre.cpp -L/usr/lib -I/usr/include/SDL -Wno-deprecated -std=c++14
main.o : main.cpp
$(CPP) -c main.cpp -L/usr/lib -I/usr/include/SDL -Wno-deprecated -std=c++14
car.o : car.cpp
$(CPP) -c car.cpp -L/usr/lib -I/usr/include/SDL -Wno-deprecated -std=c++14
sdlcommon.o : sdlcommon.cpp
$(CPP) -c sdlcommon.cpp -L/usr/lib -I/usr/include/SDL -Wno-deprecated -std=c++14
SFont.o : SFont.c
$(GCC) -c SFont.c -L/usr/lib -I/usr/include/SDL
# g++ -c fenetre.cpp -L/usr/lib -I/usr/include/SDL -Wno-deprecated -std=c++14
# g++ -c main.cpp -L/usr/lib -I/usr/include/SDL -Wno-deprecated -std=c++14
# g++ -c car.cpp -L/usr/lib -I/usr/include/SDL -Wno-deprecated -std=c++14
# g++ -c sdlcommon.cpp -L/usr/lib -I/usr/include/SDL -Wno-deprecated -std=c++14
# gcc -c SFont.c -L/usr/lib -I/usr/include/SDL
# g++ fenetre.o main.o car.o sdlcommon.o SFont.o -o iface -L/usr/lib -lSDL -lpthread -lSDL_image -Wno-deprecated -std=c++14
# g++ -c fenetre.cpp -L/usr/lib -I/usr/include/SDL -Wno-deprecated
# g++ -c main.cpp -L/usr/lib -I/usr/include/SDL -Wno-deprecated
# g++ -c car.cpp -L/usr/lib -I/usr/include/SDL -Wno-deprecated
# g++ -c sdlcommon.cpp -L/usr/lib -I/usr/include/SDL -Wno-deprecated
# gcc -c SFont.c -L/usr/lib -I/usr/include/SDL
# g++ fenetre.o main.o car.o sdlcommon.o SFont.o -o iface -L/usr/lib -lSDL -lpthread -lSDL_image -Wno-deprecated
mrproper:
rm -rf *.o
rm -rf iface
clean:
rm -rf *.o

32
InterfaceCpp/Makefile_ Normal file
View File

@@ -0,0 +1,32 @@
#$Id: Makefile,v 1.4 2005/04/10 11:46:45 feeling Exp $'
CFLAGS= -Wall -g -Wno-deprecated -std=c++14
CPP= g++
GCC= gcc
INCLUDES= -I/usr/include/SDL
LIBS= -L/usr/lib -lSDL -lpthread -lSDL_image
all : interface
interface : fenetre.o main.o car.o sdlcommon.o SFont.o
$(CPP) $(CFLAGS) $(LIBS) -o iface fenetre.o main.o car.o sdlcommon.o SFont.o
fenetre.o : fenetre.cpp
$(CPP) $(CFLAGS) $(INCLUDES) -c fenetre.cpp
main.o : main.cpp
$(CPP) $(CFLAGS) $(INCLUDES) -c main.cpp
car.o : car.cpp
$(CPP) $(CFLAGS) $(INCLUDES) -c car.cpp
sdlcommon.o : sdlcommon.cpp
$(CPP) $(CFLAGS) $(INCLUDES) -c sdlcommon.cpp
SFont.o : SFont.c
$(CPP) $(CFLAGS) $(INCLUDES) -c SFont.c
# g++ -c fenetre.cpp -L/usr/lib -I/usr/include/SDL -Wno-deprecated
# g++ -c main.cpp -L/usr/lib -I/usr/include/SDL -Wno-deprecated
# g++ -c car.cpp -L/usr/lib -I/usr/include/SDL -Wno-deprecated
# g++ -c sdlcommon.cpp -L/usr/lib -I/usr/include/SDL -Wno-deprecated
# gcc -c SFont.c -L/usr/lib -I/usr/include/SDL
# g++ fenetre.o main.o car.o sdlcommon.o SFont.o -o iface -L/usr/lib -lSDL -lpthread -lSDL_image -Wno-deprecated
mrproper:
rm -rf *.o
rm -rf iface
clean:
rm -rf *.o

189
InterfaceCpp/SFont.c Normal file
View File

@@ -0,0 +1,189 @@
/* SFont: a simple font-library that uses special .pngs as fonts
Copyright (C) 2003 Karl Bartel
License: GPL or LGPL (at your choice)
WWW: http://www.linux-games.com/sfont/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Karl Bartel
Cecilienstr. 14
12307 Berlin
GERMANY
karlb@gmx.net
*/
#include <SDL.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "SFont.h"
static Uint32 GetPixel(SDL_Surface *Surface, Sint32 X, Sint32 Y)
{
Uint8 *bits;
Uint32 Bpp;
assert(X>=0);
assert(X<Surface->w);
Bpp = Surface->format->BytesPerPixel;
bits = ((Uint8 *)Surface->pixels)+Y*Surface->pitch+X*Bpp;
switch(Bpp) {
case 1:
return *((Uint8 *)Surface->pixels + Y * Surface->pitch + X);
break;
case 2:
return *((Uint16 *)Surface->pixels + Y * Surface->pitch/2 + X);
break;
case 3: {
Uint8 r, g, b;
r = *((bits)+Surface->format->Rshift/8);
g = *((bits)+Surface->format->Gshift/8);
b = *((bits)+Surface->format->Bshift/8);
return SDL_MapRGB(Surface->format, r, g, b);
}
break;
case 4:
return *((Uint32 *)Surface->pixels + Y * Surface->pitch/4 + X);
break;
}
return 0;
}
SFont_Font* SFont_InitFont(SDL_Surface* Surface)
{
int x = 0, i = 0;
Uint32 pixel;
SFont_Font* Font;
Uint32 pink;
if (Surface == NULL)
return NULL;
Font = (SFont_Font *) malloc(sizeof(SFont_Font));
Font->Surface = Surface;
SDL_LockSurface(Surface);
pink = SDL_MapRGB(Surface->format, 255, 0, 255);
while (x < Surface->w) {
if (GetPixel(Surface, x, 0) == pink) {
Font->CharPos[i++]=x;
while((x < Surface->w) && (GetPixel(Surface, x, 0)== pink))
x++;
Font->CharPos[i++]=x;
}
x++;
}
Font->MaxPos = x-1;
pixel = GetPixel(Surface, 0, Surface->h-1);
SDL_UnlockSurface(Surface);
SDL_SetColorKey(Surface, SDL_SRCCOLORKEY, pixel);
return Font;
}
void SFont_FreeFont(SFont_Font* FontInfo)
{
SDL_FreeSurface(FontInfo->Surface);
free(FontInfo);
}
void SFont_Write(SDL_Surface *Surface, const SFont_Font *Font,
int x, int y, const char *text)
{
const char* c;
int charoffset;
SDL_Rect srcrect, dstrect;
if(text == NULL)
return;
/* these values won't change in the loop */
srcrect.y = 1;
dstrect.y = y;
srcrect.h = dstrect.h = Font->Surface->h - 1;
for(c = text; *c != '\0' && x <= Surface->w ; c++) {
charoffset = ((int) (*c - 33)) * 2 + 1;
/* skip spaces and nonprintable characters */
if (*c == ' ' || charoffset < 0 || charoffset > Font->MaxPos) {
x += Font->CharPos[2]-Font->CharPos[1];
continue;
}
srcrect.w = dstrect.w =
(Font->CharPos[charoffset+2] + Font->CharPos[charoffset+1])/2 -
(Font->CharPos[charoffset] + Font->CharPos[charoffset-1])/2;
srcrect.x = (Font->CharPos[charoffset]+Font->CharPos[charoffset-1])/2;
dstrect.x = (Sint16)(x - (float)(Font->CharPos[charoffset] - Font->CharPos[charoffset-1])/2);
SDL_BlitSurface(Font->Surface, &srcrect, Surface, &dstrect);
x += Font->CharPos[charoffset+1] - Font->CharPos[charoffset];
}
}
int SFont_TextWidth(const SFont_Font *Font, const char *text)
{
const char* c;
int charoffset=0;
int width = 0;
if(text == NULL)
return 0;
for(c = text; *c != '\0'; c++) {
charoffset = ((int) *c - 33) * 2 + 1;
/* skip spaces and nonprintable characters */
if (*c == ' ' || charoffset < 0 || charoffset > Font->MaxPos) {
width += Font->CharPos[2]-Font->CharPos[1];
continue;
}
width += Font->CharPos[charoffset+1] - Font->CharPos[charoffset];
}
return width;
}
int SFont_TextHeight(const SFont_Font* Font)
{
return Font->Surface->h - 1;
}
void SFont_WriteCenter(SDL_Surface *Surface, const SFont_Font *Font,
int y, const char *text)
{
SFont_Write(Surface, Font, Surface->w/2 - SFont_TextWidth(Font, text)/2,
y, text);
}
void SFont_Write_V(SDL_Surface *Surface, const SFont_Font *Font, int x, int y,
const char *text)
{
int i,ph;
char bf[4];
ph=SFont_TextHeight(Font);
for(i=0;i<((int)strlen(text));i++)
{
sprintf(bf,"%c",text[i]);
SFont_Write(Surface,Font, x-(SFont_TextWidth(Font,bf)/2) , y+(i*ph) , bf);
}
}

85
InterfaceCpp/SFont.h Normal file
View File

@@ -0,0 +1,85 @@
/* SFont: a simple font-library that uses special bitmaps as fonts
Copyright (C) 2003 Karl Bartel
License: GPL or LGPL (at your choice)
WWW: http://www.linux-games.com/sfont/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Karl Bartel
Cecilienstr. 14
12307 Berlin
GERMANY
karlb@gmx.net
*/
/************************************************************************
* SFONT - SDL Font Library by Karl Bartel <karlb@gmx.net> *
* *
* All functions are explained below. There are two versions of each *
* funtction. The first is the normal one, the function with the *
* 2 at the end can be used when you want to handle more than one font *
* in your program. *
* *
************************************************************************/
#ifndef SFONT_H
#define SFONT_H
#include <SDL.h>
#ifdef __cplusplus
extern "C" {
#endif
/*Delcare one variable of this type for each font you are using.
To load the fonts, load the font image into YourFont->Surface
and call InitFont( YourFont );
*/
typedef struct {
SDL_Surface *Surface;
int CharPos[512];
int MaxPos;
} SFont_Font;
/* Initializes the font
Font: this contains the suface with the font.
The font must be loaded before using this function.
*/
SFont_Font* SFont_InitFont (SDL_Surface *Font);
void SFont_FreeFont(SFont_Font* Font);
/* Blits a string to a surface
Destination: the suface you want to blit to
text: a string containing the text you want to blit.
*/
void SFont_Write(SDL_Surface *Surface, const SFont_Font *Font, int x, int y,
const char *text);
void SFont_Write_V(SDL_Surface *Surface, const SFont_Font *Font, int x, int y,
const char *text);
/* Returns the width of "text" in pixels */
int SFont_TextWidth(const SFont_Font* Font, const char *text);
/* Returns the height of "text" in pixels (which is always equal to Font->Surface->h) */
int SFont_TextHeight(const SFont_Font* Font);
/* Blits a string to Surface with centered x position */
void SFont_WriteCenter(SDL_Surface *Surface, const SFont_Font* Font, int y,
const char *text);
#ifdef __cplusplus
}
#endif
#endif /* SFONT_H */

BIN
InterfaceCpp/SFont.o Normal file

Binary file not shown.

313
InterfaceCpp/car.cpp Normal file
View File

@@ -0,0 +1,313 @@
#include <iostream>
#include <unistd.h>
#include <SDL.h>
#include <math.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include "sdlcommon.h"
#include "car.h"
#include "shmdata.h"
using namespace std;
Car::Car()
{
initShm();
reset();
showbar=1;
angstep=5;
for(int i=0;i<CAMVECT;i++) camera[i]=0;
carimage=0;
for(int i=0;i<TRAINEESIZE;i++) { trainee[i][0]=0; trainee[i][1]=0; }
traineepos=0;
traineesize=1;
}
void Car::loadImage(char *imagefile)
{
SDL_Surface *voitsurf;
Uint32 cur=SDL_GetTicks();
voitsurf=SDL_LoadBMP(imagefile);
printf("Precaching Surfaces ..... \n");
for(int i=0;i<360;i++)
{
Surface_car[i]=SDL_CreateRGBSurface(SDL_HWSURFACE, voitsurf->w, voitsurf->h, 32, 0,0,0,0);
if(SDL_SetColorKey(Surface_car[i], SDL_SRCCOLORKEY | SDL_RLEACCEL, SDL_MapRGB(Surface_car[i]->format, 255,0,255)) == -1)
fprintf(stderr, "Warning: colorkey will not be used, reason: %s\n", SDL_GetError());
rotatesurface(voitsurf,Surface_car[i],i);
}
carimage=1;
printf("Done ... (%d ms)\n",SDL_GetTicks()-cur);
}
void Car::updateCar(SDL_Surface* screen)
{
int i;
for(i=0;(SData->read!=0) && i<200;i++) usleep(5); // on attends 1 seconde
if(i==200)
{
cout << "AutoPilot Timed Out ...";
exit(0);
}
if(SData->Res[0]) decAngle();
if(SData->Res[1]) incAngle();
SData->Res[0]=0;
SData->Res[1]=0;
SData->pos_x+=getSpeed()*(cos(SData->angle*PI/180));
SData->pos_y+=getSpeed()*(sin(SData->angle*PI/180));
showTrainee(screen);
showCamera(screen); /* obligé pour avoir les pixels :-) */
// CAMERASIZE // CAMERASTEP
if(carimage) /* on blit la voiture */
{
SDL_Rect r;
r.w=Surface_car[SData->angle]->w;
r.h=Surface_car[SData->angle]->h;
r.x=(int)SData->pos_x-(r.w/2);
r.y=(int)SData->pos_y-(r.h/2);
SDL_BlitSurface( Surface_car[SData->angle], NULL, screen, &r);
}
else for(int i=0;i<20;i++) /* affichage de la voiture simplifiée (ligne rouge) */
{
setpixel(screen,(int)(SData->pos_x-(cos(SData->angle*PI/180)*i)),(int)( SData->pos_y-(sin(SData->angle*PI/180)*i)),255,0,0);
}
for(int i=0;i<CAMVECT;i++)
{
// cout << camera[i];
SData->V[i]=camera[i];
}
SData->read=1; /* on a lu :D */
//cout << endl;
}
void Car::showTrainee(SDL_Surface* screen)
{
int k;
trainee[traineepos][0]=(int)SData->pos_x;
trainee[traineepos][1]=(int)SData->pos_y;
traineepos=(traineepos+1)%traineesize;
k=traineepos;
k=(k+1)%traineesize;
for(int i=0; /*i < traineesize &&*/ k!=traineepos;i++) /* affichage de la trainée */
{
//setpixel(screen,trainee[k][0],trainee[k][1],0,(int)(i*(256.0/traineesize))%256,255);
int x0,y0,x1,y1;
x0=trainee[(k+traineesize-1)%traineesize][0];
y0=trainee[(k+traineesize-1)%traineesize][1];
x1=trainee[k][0];
y1=trainee[k][1];
if(x0==0) x0=x1;
if(y0==0) y0=y1;
if(x1==0) x1=x0;
if(y1==0) y1=y0;
DrawLine(screen,x0,y0,x1,y1,0,0,255);
k=(k+1)%traineesize;
}
}
void Car::showCamera(SDL_Surface* screen)
{
double x,y;
int k,ang;
x=SData->pos_x + ( cos(SData->angle*PI/180) * CAMERADISTANCE );
y=SData->pos_y + ( sin(SData->angle*PI/180) * CAMERADISTANCE );
ang=(SData->angle+90)%360;
x-=CAMERASIZE/2*cos(ang*PI/180);
y-=CAMERASIZE/2*sin(ang*PI/180);
k=0;
for(int i=0;i<CAMERASIZE;i++)
{
x+=cos(ang*PI/180);
y+=sin(ang*PI/180);
if(!(i%CAMERASTEP))
{
camera[k]=1;
if(inCarArea(screen,(int)x,(int)y)) //if(x>0 && x<screen->w && y>0 && y<screen->h)
camera[k]=(((getpixel(screen,(int)x,(int)y))%2)+1)%2;
else camera[k]=0;
if(camera[k] && showbar)
{
setpixel(screen, (int)x, (int)y,255,0,0);
//setpixel(screen, (int)x, (int)y-1,255,0,0);
//setpixel(screen, (int)x-1, (int)y,255,0,0);
//setpixel(screen, (int)x-1, (int)y-1,255,0,0);
}
else if(showbar)
{
setpixel(screen, (int)x, (int)y,0,255,0);
//setpixel(screen, (int)x, (int)y-1,0,255,0);
//setpixel(screen, (int)x-1, (int)y,0,255,0);
//setpixel(screen, (int)x-1, (int)y-1,0,255,0);
}
k++;
}
else
{
if(showbar) setpixel(screen, (int)x, (int)y,0,0,255);
}
}
}
void Car::incAngle()
{
SData->angle=(SData->angle+angstep)%360;
}
void Car::decAngle()
{
SData->angle=(SData->angle+360-angstep)%360;
}
int Car::incAngleStep(int i)
{
angstep+=i;
return angstep;
}
void Car::incSpeed()
{
if(SData->Res[2]==0)
{
SData->Res[0]=0;
SData->Res[1]=0;
SData->Res[2]=1;
if(SData->speed==0) SData->speed=1;
}
SData->speed++;
}
void Car::decSpeed()
{
SData->speed--;
}
bool Car::APToggle()
{
SData->APon=(SData->APon+1)%2;
return SData->APon;
}
bool Car::APState() const
{
return SData->APon;
}
bool Car::neurToggle()
{
SData->Neuron=(SData->Neuron+1)%2;
return SData->Neuron;
}
bool Car::neurState() const
{
return SData->Neuron;
}
void Car::initShm()
{
if ((shmid = shmget(SHMKEY, sizeof(struct shmdata), 0666)) < 0)
{
perror("shmget");
exit(1);
}
if (( SData = (struct shmdata *)shmat(shmid, NULL, 0)) == (struct shmdata *) -1)
{
perror("shmat");
exit(1);
}
}
int Car::getSpeed() const
{
if(SData->Res[2])
return SData->speed;
return 0;
}
int Car::getAngle() const
{
return SData->angle;
}
bool Car::showBar(int i)
{
showbar=(showbar+i)%2;
return showbar;
}
bool* Car::getVect()
{
return SData->Res;
}
bool* Car::getView()
{
return SData->V;
}
void Car::reset()
{
SData->pos_x=200;
SData->pos_y=200;
SData->speed=1;
SData->angle=0;
SData->Res[2]=1;
}
void Car::turn180()
{
SData->angle=(SData->angle+180)%360;
}
int Car::incTraineeSize(int s)
{
int i,k;
if(s==0) return traineesize;
if(traineesize==1 && s<0) return traineesize;
if(traineesize+s > TRAINEESIZE) s=TRAINEESIZE-traineesize-1;
if(traineesize+s < 0) s=1-TRAINEESIZE;
int tmp[traineesize+s][2];
k=traineepos;
if(s<0) k=(traineesize+traineepos-s)%traineesize;
for(i=0;i<(traineesize+s);i++)
{
if(i>traineesize)
{
tmp[i][0]=0;
tmp[i][1]=0;
}
else
{
tmp[i][0]=trainee[k][0];
tmp[i][1]=trainee[k][1];
}
k=(k+1)%traineesize;
}
for(i=0;i<traineesize+s;i++)
{
trainee[i][0]=tmp[i][0];
trainee[i][1]=tmp[i][1];
}
traineepos=traineesize-1;
// if(traineesize<1) { traineesize=1; traineepos=0; }
if(s<0)traineepos=0;
traineesize+=s;
return traineesize;
}
void Car::setDelay(int del)
{
SData->delay=del;
}
void Car::harakiri()
{
cout << " EXIT INTERFACE ...\n";
SData->read=666;
usleep(100);
SData->read=666;
usleep(100);
SData->read=666;
}
void Car::saveState()
{
SData->action=SAVE_STATE;
}
void Car::loadState()
{
SData->action=RELOAD_STATE;
}
void Car::showNetwork(bool a)
{
SData->viewNetwork=a;
}
bool Car::showNetworkState()
{
return SData->viewNetwork;
}

312
InterfaceCpp/car.cpp~ Normal file
View File

@@ -0,0 +1,312 @@
#include <iostream>
#include <SDL.h>
#include <math.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include "sdlcommon.h"
#include "car.h"
#include "shmdata.h"
using namespace std;
Car::Car()
{
initShm();
reset();
showbar=1;
angstep=5;
for(int i=0;i<CAMVECT;i++) camera[i]=0;
carimage=0;
for(int i=0;i<TRAINEESIZE;i++) { trainee[i][0]=0; trainee[i][1]=0; }
traineepos=0;
traineesize=1;
}
void Car::loadImage(char *imagefile)
{
SDL_Surface *voitsurf;
Uint32 cur=SDL_GetTicks();
voitsurf=SDL_LoadBMP(imagefile);
printf("Precaching Surfaces ..... \n");
for(int i=0;i<360;i++)
{
Surface_car[i]=SDL_CreateRGBSurface(SDL_HWSURFACE, voitsurf->w, voitsurf->h, 32, 0,0,0,0);
if(SDL_SetColorKey(Surface_car[i], SDL_SRCCOLORKEY | SDL_RLEACCEL, SDL_MapRGB(Surface_car[i]->format, 255,0,255)) == -1)
fprintf(stderr, "Warning: colorkey will not be used, reason: %s\n", SDL_GetError());
rotatesurface(voitsurf,Surface_car[i],i);
}
carimage=1;
printf("Done ... (%d ms)\n",SDL_GetTicks()-cur);
}
void Car::updateCar(SDL_Surface* screen)
{
int i;
for(i=0;(SData->read!=0) && i<200;i++) usleep(5); // on attends 1 seconde
if(i==200)
{
cout << "AutoPilot Timed Out ...";
exit(0);
}
if(SData->Res[0]) decAngle();
if(SData->Res[1]) incAngle();
SData->Res[0]=0;
SData->Res[1]=0;
SData->pos_x+=getSpeed()*(cos(SData->angle*PI/180));
SData->pos_y+=getSpeed()*(sin(SData->angle*PI/180));
showTrainee(screen);
showCamera(screen); /* obligé pour avoir les pixels :-) */
// CAMERASIZE // CAMERASTEP
if(carimage) /* on blit la voiture */
{
SDL_Rect r;
r.w=Surface_car[SData->angle]->w;
r.h=Surface_car[SData->angle]->h;
r.x=(int)SData->pos_x-(r.w/2);
r.y=(int)SData->pos_y-(r.h/2);
SDL_BlitSurface( Surface_car[SData->angle], NULL, screen, &r);
}
else for(int i=0;i<20;i++) /* affichage de la voiture simplifiée (ligne rouge) */
{
setpixel(screen,(int)(SData->pos_x-(cos(SData->angle*PI/180)*i)),(int)( SData->pos_y-(sin(SData->angle*PI/180)*i)),255,0,0);
}
for(int i=0;i<CAMVECT;i++)
{
// cout << camera[i];
SData->V[i]=camera[i];
}
SData->read=1; /* on a lu :D */
//cout << endl;
}
void Car::showTrainee(SDL_Surface* screen)
{
int k;
trainee[traineepos][0]=(int)SData->pos_x;
trainee[traineepos][1]=(int)SData->pos_y;
traineepos=(traineepos+1)%traineesize;
k=traineepos;
k=(k+1)%traineesize;
for(int i=0; /*i < traineesize &&*/ k!=traineepos;i++) /* affichage de la trainée */
{
//setpixel(screen,trainee[k][0],trainee[k][1],0,(int)(i*(256.0/traineesize))%256,255);
int x0,y0,x1,y1;
x0=trainee[(k+traineesize-1)%traineesize][0];
y0=trainee[(k+traineesize-1)%traineesize][1];
x1=trainee[k][0];
y1=trainee[k][1];
if(x0==0) x0=x1;
if(y0==0) y0=y1;
if(x1==0) x1=x0;
if(y1==0) y1=y0;
DrawLine(screen,x0,y0,x1,y1,0,0,255);
k=(k+1)%traineesize;
}
}
void Car::showCamera(SDL_Surface* screen)
{
double x,y;
int k,ang;
x=SData->pos_x + ( cos(SData->angle*PI/180) * CAMERADISTANCE );
y=SData->pos_y + ( sin(SData->angle*PI/180) * CAMERADISTANCE );
ang=(SData->angle+90)%360;
x-=CAMERASIZE/2*cos(ang*PI/180);
y-=CAMERASIZE/2*sin(ang*PI/180);
k=0;
for(int i=0;i<CAMERASIZE;i++)
{
x+=cos(ang*PI/180);
y+=sin(ang*PI/180);
if(!(i%CAMERASTEP))
{
camera[k]=1;
if(inCarArea(screen,(int)x,(int)y)) //if(x>0 && x<screen->w && y>0 && y<screen->h)
camera[k]=(((getpixel(screen,(int)x,(int)y))%2)+1)%2;
else camera[k]=0;
if(camera[k] && showbar)
{
setpixel(screen, (int)x, (int)y,255,0,0);
//setpixel(screen, (int)x, (int)y-1,255,0,0);
//setpixel(screen, (int)x-1, (int)y,255,0,0);
//setpixel(screen, (int)x-1, (int)y-1,255,0,0);
}
else if(showbar)
{
setpixel(screen, (int)x, (int)y,0,255,0);
//setpixel(screen, (int)x, (int)y-1,0,255,0);
//setpixel(screen, (int)x-1, (int)y,0,255,0);
//setpixel(screen, (int)x-1, (int)y-1,0,255,0);
}
k++;
}
else
{
if(showbar) setpixel(screen, (int)x, (int)y,0,0,255);
}
}
}
void Car::incAngle()
{
SData->angle=(SData->angle+angstep)%360;
}
void Car::decAngle()
{
SData->angle=(SData->angle+360-angstep)%360;
}
int Car::incAngleStep(int i)
{
angstep+=i;
return angstep;
}
void Car::incSpeed()
{
if(SData->Res[2]==0)
{
SData->Res[0]=0;
SData->Res[1]=0;
SData->Res[2]=1;
if(SData->speed==0) SData->speed=1;
}
SData->speed++;
}
void Car::decSpeed()
{
SData->speed--;
}
bool Car::APToggle()
{
SData->APon=(SData->APon+1)%2;
return SData->APon;
}
bool Car::APState() const
{
return SData->APon;
}
bool Car::neurToggle()
{
SData->Neuron=(SData->Neuron+1)%2;
return SData->Neuron;
}
bool Car::neurState() const
{
return SData->Neuron;
}
void Car::initShm()
{
if ((shmid = shmget(SHMKEY, sizeof(struct shmdata), 0666)) < 0)
{
perror("shmget");
exit(1);
}
if (( SData = (struct shmdata *)shmat(shmid, NULL, 0)) == (struct shmdata *) -1)
{
perror("shmat");
exit(1);
}
}
int Car::getSpeed() const
{
if(SData->Res[2])
return SData->speed;
return 0;
}
int Car::getAngle() const
{
return SData->angle;
}
bool Car::showBar(int i)
{
showbar=(showbar+i)%2;
return showbar;
}
bool* Car::getVect()
{
return SData->Res;
}
bool* Car::getView()
{
return SData->V;
}
void Car::reset()
{
SData->pos_x=200;
SData->pos_y=200;
SData->speed=1;
SData->angle=0;
SData->Res[2]=1;
}
void Car::turn180()
{
SData->angle=(SData->angle+180)%360;
}
int Car::incTraineeSize(int s)
{
int i,k;
if(s==0) return traineesize;
if(traineesize==1 && s<0) return traineesize;
if(traineesize+s > TRAINEESIZE) s=TRAINEESIZE-traineesize-1;
if(traineesize+s < 0) s=1-TRAINEESIZE;
int tmp[traineesize+s][2];
k=traineepos;
if(s<0) k=(traineesize+traineepos-s)%traineesize;
for(i=0;i<(traineesize+s);i++)
{
if(i>traineesize)
{
tmp[i][0]=0;
tmp[i][1]=0;
}
else
{
tmp[i][0]=trainee[k][0];
tmp[i][1]=trainee[k][1];
}
k=(k+1)%traineesize;
}
for(i=0;i<traineesize+s;i++)
{
trainee[i][0]=tmp[i][0];
trainee[i][1]=tmp[i][1];
}
traineepos=traineesize-1;
// if(traineesize<1) { traineesize=1; traineepos=0; }
if(s<0)traineepos=0;
traineesize+=s;
return traineesize;
}
void Car::setDelay(int del)
{
SData->delay=del;
}
void Car::harakiri()
{
cout << " EXIT INTERFACE ...\n";
SData->read=666;
usleep(100);
SData->read=666;
usleep(100);
SData->read=666;
}
void Car::saveState()
{
SData->action=SAVE_STATE;
}
void Car::loadState()
{
SData->action=RELOAD_STATE;
}
void Car::showNetwork(bool a)
{
SData->viewNetwork=a;
}
bool Car::showNetworkState()
{
return SData->viewNetwork;
}

57
InterfaceCpp/car.h Normal file
View File

@@ -0,0 +1,57 @@
#ifndef __CAR_H
#define __CAR_H
#define PI 3.141592
#define ANGLESTEP 5
#define TRAINEESIZE 8192
#include "shmdata.h"
class Car
{
private :
SDL_Surface *Surface_car[360];
SDL_Rect rect;
bool carimage;
bool showbar;
bool camera[CAMVECT];
struct shmdata *SData;
int shmid;
int angstep;
int trainee[TRAINEESIZE][2];
int traineepos;
int traineesize;
public :
Car();
void updateCar(SDL_Surface* screen);
void loadImage(char *imagefile);
void initShm();
int incTraineeSize(int);
void incAngle();
void decAngle();
void incSpeed();
void decSpeed();
int incAngleStep(int);
bool APToggle();
bool APState() const;
bool neurToggle();
bool neurState() const;
int getSpeed() const;
int getAngle() const;
bool showBar(int i);
bool* getVect();
bool* getView();
void reset();
void turn180();
void showCamera(SDL_Surface* screen);
void showTrainee(SDL_Surface* screen);
void loadState();
void saveState();
void harakiri();
void setDelay(int del);
void showNetwork(bool a);
bool showNetworkState();
};
#endif

57
InterfaceCpp/car.h~ Normal file
View File

@@ -0,0 +1,57 @@
#ifndef __CAR_H
#define __CAR_H
#define PI 3.141592
#define ANGLESTEP 5
#define TRAINEESIZE 8192
#include "shmdata.h"
class Car
{
private :
SDL_Surface *Surface_car[360];
SDL_Rect rect;
bool carimage;
bool showbar;
bool camera[CAMVECT];
struct shmdata *SData;
int shmid;
int angstep;
int trainee[TRAINEESIZE][2];
int traineepos;
int traineesize;
public :
Car();
void updateCar(SDL_Surface* screen);
void loadImage(char *imagefile);
void initShm();
int incTraineeSize(int);
void incAngle();
void decAngle();
void incSpeed();
void decSpeed();
int incAngleStep(int);
bool APToggle();
bool APState() const;
bool neurToggle();
bool neurState() const;
int getSpeed() const;
int getAngle() const;
bool showBar(int i);
bool* getVect();
bool* getView();
void reset();
void turn180();
void showCamera(SDL_Surface* screen);
void showTrainee(SDL_Surface* screen);
void loadState();
void saveState();
void harakiri();
void setDelay(int del);
bool showNetwork(bool a);
bool showNetworkState();
};
#endif

BIN
InterfaceCpp/car.o Normal file

Binary file not shown.

376
InterfaceCpp/fenetre.cpp Normal file
View File

@@ -0,0 +1,376 @@
#include <SDL.h>
#include <SDL_image.h>
#include <time.h>
#include <iostream>
#include "sdlcommon.h"
#include "fenetre.h"
#include "shmdata.h"
using namespace std;
Fenetre::Fenetre ()
{
obstacle=0;
SHOWcamera=1;
SHOWpilot=1;
fps=0;
font=SFont_InitFont(IMG_Load(FONT_PATH));
if( SDL_Init(SDL_INIT_VIDEO) < 0 )
{
fprintf(stderr, "Could not initialize SDL: %s\n", SDL_GetError());
return ;
}
atexit(SDL_Quit);
screen = SDL_SetVideoMode(800,600, 32, SDL_HWSURFACE);
/* SDL_HWSURFACE / SDL_SWSURFACE */
/*|SDL_ANYFORMAT*/
if( screen==NULL )
{
fprintf(stderr, "Could not create surface: %s\n", SDL_GetError());
return ;
}
return ;
Voiture.loadImage("Cars/voiture4.bmp");
circuit=1;
}
Fenetre::Fenetre (int largeur = 800, int hauteur = 600, int nb_couleurs = 16, char *titre = "Fenetre SDL", char *background=NULL)
{
obstacle=0;
SHOWcamera=1;
SHOWpilot=1;
fps=0;
font=SFont_InitFont(IMG_Load(FONT_PATH));
if (SDL_Init (SDL_INIT_VIDEO) < 0)
{
cerr << "Erreur dans l'initialisation de la librairie" << endl;
}
screen = SDL_SetVideoMode (largeur, hauteur, nb_couleurs, SDL_HWSURFACE | SDL_DOUBLEBUF);
//SDL_CreateRGBSurface(SDL_HWSURFACE, largeur,hauteur,32,0,0,0,0);
if (screen == NULL)
{
cerr << "Erreur dans l'initialisation des modes vidéos:" <<
SDL_GetError ();
SDL_Quit ();
}
SDL_WM_SetCaption (titre, NULL);
fond = SDL_LoadBMP (background);
SDL_BlitSurface (fond, NULL, screen, NULL);
SDL_Flip (screen);
HardBG=SDL_CreateRGBSurface(SDL_HWSURFACE, largeur, hauteur, 32, 0,0,0,0);
SDL_BlitSurface( fond, NULL, HardBG, NULL);
Voiture.loadImage("Cars/voiture4.bmp");
circuit=1;
}
void Fenetre::loadBG(char *background)
{
fond = SDL_LoadBMP (background);
SDL_BlitSurface (fond, NULL, /*screen*/HardBG, NULL);
SDL_BlitSurface( fond, NULL, HardBG, NULL);
SDL_Flip (screen);
}
Fenetre::~Fenetre ()
{
/*
if(fond) SDL_FreeSurface (fond);
if(screen) SDL_FreeSurface (screen);
*/
SDL_Quit ();
}
void Fenetre::showView(int x,int y)
{
bool* v=Voiture.getView();
SDL_Rect r;
r.x=x; r.y=y-1; r.h=1; r.w=4*CAMVECT;
SDL_FillRect(screen,&r, SDL_MapRGB(screen->format, 255,0,0));
r.x=x; r.y=y+4; r.h=1; r.w=4*CAMVECT;
SDL_FillRect(screen,&r, SDL_MapRGB(screen->format, 255,0,0));
for(int i=0;i<CAMVECT;i++)
{
if(v[i])
{
r.x=x+(4*i);
r.y=y;
r.w=4;
r.h=4;
SDL_FillRect(screen,&r, SDL_MapRGB(screen->format, 0,0,0));
}
}
}
void Fenetre::showObstacle()
{
SDL_Rect r;
r.x=400;
r.y=20;
r.w=40;
r.h=screen->h-40;
SDL_FillRect(screen,&r, SDL_MapRGB(screen->format, 255,0,0));
}
void Fenetre::showPilot(int x,int y)
{
if(Voiture.getVect()[0])
for(int i=0;i<16;i++)
{
for(int j=y-i;j<y+i;j++)
putPixel(x+i,j,0,0,0);
}
if(Voiture.getVect()[1])
for(int i=0;i<16;i++)
{
for(int j=y-i;j<y+i;j++)
putPixel(x+64-i,j,0,0,0);
}
if(Voiture.getVect()[2]==1)
for(int i=0;i<16;i++)
{
for(int j=x-i+32;j<x+i+32;j++)
putPixel(j,y+i-32,0,0,0);
}
if(Voiture.getVect()[2]==0)
for(int i=0;i<16;i++)
{
for(int j=x-i+32;j<x+i+32;j++)
putPixel(j,y-i+32,0,0,0);
}
}
void Fenetre::drawText()
{
char *bf=(char*)malloc(256);
sprintf(bf,": %d",Voiture.APState());
SFont_Write(screen,font,10,10,"AutoPilot (a)");
SFont_Write(screen,font,120,10,bf);
sprintf(bf,": %d",Voiture.neurState());
SFont_Write(screen,font,10,25,"NeuronPilot (n)");
SFont_Write(screen,font,120,25,bf);
sprintf(bf,": %d",Voiture.getSpeed());
SFont_Write(screen,font,10,40,"Speed");
SFont_Write(screen,font,120,40,bf);
sprintf(bf,": %d",Voiture.getAngle());
SFont_Write(screen,font,10,55,"Angle");
SFont_Write(screen,font,120,55,bf);
sprintf(bf,": %d",fps);
SFont_Write(screen,font,10,70,"Framerate");
SFont_Write(screen,font,120,70,bf);
sprintf(bf,": %d",Voiture.incTraineeSize(0));
SFont_Write(screen,font,10,85,"trainee(F8,F9)");
SFont_Write(screen,font,120,85,bf);
sprintf(bf,": %d",Voiture.showBar(0));
SFont_Write(screen,font,200,10,"Showbar (b)");
SFont_Write(screen,font,300,10,bf);
sprintf(bf,": %d",SHOWcamera);
SFont_Write(screen,font,200,25,"Showcam (c)");
SFont_Write(screen,font,300,25,bf);
sprintf(bf,": %d",SHOWpilot);
SFont_Write(screen,font,200,40,"Showpilot (p)");
SFont_Write(screen,font,300,40,bf);
sprintf(bf,": %d",obstacle);
SFont_Write(screen,font,200,55,"Obstacle (o)");
SFont_Write(screen,font,300,55,bf);
sprintf(bf,": %d",Voiture.incAngleStep(0));
SFont_Write(screen,font,200,70,"AStep (pgU-D)");
SFont_Write(screen,font,300,70,bf);
sprintf(bf,": %d",Voiture.showNetworkState());
SFont_Write(screen,font,200,85,"NeuronIface(i)");
SFont_Write(screen,font,300,85,bf);
DrawLine(screen,0,99,319,99,0,0,128);
}
void Fenetre::redraw()
{
#ifdef __DEBUG_TIME
Uint32 deltatime;
#endif
if(sec!=time(NULL)) { sec=time(NULL); fps=frame; frame=0; }
frame++;
#ifdef __DEBUG_TIME
deltatime=SDL_GetTicks();
#endif
/* SDL_BlitSurface( fond, NULL, screen, NULL); Software Mode */
SDL_BlitSurface( HardBG, NULL, screen , NULL); /* Hardware Mode */
#ifdef __DEBUG_TIME
printf("Background Blit : %d ms, ",SDL_GetTicks()-deltatime);
deltatime=SDL_GetTicks();
#endif
drawText();
if(SHOWpilot) showPilot(440,50);
if(SHOWcamera) showView(350,10);
if(obstacle) showObstacle();
Voiture.updateCar(screen);
#ifdef __DEBUG_TIME
printf("Car Update : %d ms, ",SDL_GetTicks()-deltatime);
deltatime=SDL_GetTicks();
#endif
SDL_Flip (screen);
#ifdef __DEBUG_TIME
printf("Screen Refresh : %d ms\n",SDL_GetTicks()-deltatime);
#endif
}
void Fenetre::putPixel(int x, int y, char r, char g, char b)
{
setpixel(screen,x,y,r,g,b);
}
void Fenetre::handle()
{
int exitkey = 0;
bool shownet= 0;
int waitdel = 20;
SDL_Event event;
while (!exitkey)
{
SDL_Delay (waitdel);
redraw();
while (SDL_PollEvent (&event))
{
switch (event.type)
{
case SDL_QUIT:
Voiture.harakiri();
exitkey = 1;
break;
case SDL_KEYDOWN:
switch (event.key.keysym.sym)
{
case SDLK_ESCAPE:
Voiture.harakiri();
exitkey = 1;
break;
case SDLK_LEFT:
Voiture.decAngle();
break;
case SDLK_RIGHT:
Voiture.incAngle();
break;
case SDLK_DOWN:
Voiture.decSpeed();
break;
case SDLK_UP:
Voiture.incSpeed();
break;
case SDLK_a:
Voiture.APToggle();
break;
case SDLK_b:
Voiture.showBar(1);
break;
case SDLK_c:
SHOWcamera=(SHOWcamera+1)%2;
break;
case SDLK_i:
shownet=(shownet+1)%2;
Voiture.showNetwork(shownet);
break;
case SDLK_n:
Voiture.neurToggle();
break;
case SDLK_o:
obstacle=(obstacle+1)%2;
break;
case SDLK_p:
SHOWpilot=(SHOWpilot+1)%2;
break;
case SDLK_r:
Voiture.reset();
break;
case SDLK_t:
Voiture.turn180();
break;
case SDLK_w:
Voiture.saveState();
//SData->action=SAVE_STATE;
break;
case SDLK_x:
Voiture.loadState();
//SData->action=RELOAD_STATE;
break;
case SDLK_F1:
printf("Chargement Circuit 1\n");
circuit=1;
loadBG("Back/bg1.bmp");
break;
case SDLK_F2:
printf("Chargement Circuit 2\n");
circuit=2;
loadBG("Back/bg2.bmp");
break;
case SDLK_F3:
printf("Chargement Circuit 3\n");
circuit=3;
loadBG("Back/bg3.bmp");
break;
case SDLK_F4:
printf("Chargement Circuit 4\n");
circuit=4;
loadBG("Back/bg4.bmp");
break;
case SDLK_F5:
printf("Chargement Circuit 5\n");
circuit=5;
loadBG("Back/bg5.bmp");
break;
case SDLK_F6:
printf("Chargement Circuit 6\n");
circuit=6;
loadBG("Back/bg6.bmp");
break;
case SDLK_F7:
Voiture.incTraineeSize(-256);
break;
case SDLK_F8:
Voiture.incTraineeSize(256);
break;
case SDLK_F9:
printf("Chargement Voiture 1\n");
Voiture.loadImage("Cars/voiture1.bmp");
break;
case SDLK_F10:
printf("Chargement Voiture 2\n");
Voiture.loadImage("Cars/voiture2.bmp");
break;
case SDLK_F11:
printf("Chargement Voiture 3\n");
Voiture.loadImage("Cars/voiture3.bmp");
break;
case SDLK_F12:
printf("Chargement Voiture 4\n");
Voiture.loadImage("Cars/voiture4.bmp");
break;
case SDLK_PAGEUP:
Voiture.incAngleStep(1);
break;
case SDLK_PAGEDOWN:
Voiture.incAngleStep(-1);
break;
case SDLK_HOME:
waitdel+=5;
break;
case SDLK_END:
waitdel-=5;
if(waitdel<0) waitdel=0;
break;
default :
break;
}
break;
}
break;
}
}
}

376
InterfaceCpp/fenetre.cpp~ Normal file
View File

@@ -0,0 +1,376 @@
#include <SDL.h>
#include <SDL_image.h>
#include <time.h>
#include <iostream>
#include "sdlcommon.h"
#include "fenetre.h"
#include "shmdata.h"
using namespace std;
Fenetre::Fenetre ()
{
obstacle=0;
SHOWcamera=1;
SHOWpilot=1;
fps=0;
font=SFont_InitFont(IMG_Load(FONT_PATH));
if( SDL_Init(SDL_INIT_VIDEO) < 0 )
{
fprintf(stderr, "Could not initialize SDL: %s\n", SDL_GetError());
return ;
}
atexit(SDL_Quit);
screen = SDL_SetVideoMode(800,600, 32, SDL_HWSURFACE);
/* SDL_HWSURFACE / SDL_SWSURFACE */
/*|SDL_ANYFORMAT*/
if( screen==NULL )
{
fprintf(stderr, "Could not create surface: %s\n", SDL_GetError());
return ;
}
return ;
Voiture.loadImage("Cars/voiture4.bmp");
circuit=1;
}
Fenetre::Fenetre (int largeur = 800, int hauteur = 600, int nb_couleurs = 16, char *titre = "Fenetre SDL", char *background=NULL)
{
obstacle=0;
SHOWcamera=1;
SHOWpilot=1;
fps=0;
font=SFont_InitFont(IMG_Load(FONT_PATH));
if (SDL_Init (SDL_INIT_VIDEO) < 0)
{
cerr << "Erreur dans l'initialisation de la librairie" << endl;
}
screen = SDL_SetVideoMode (largeur, hauteur, nb_couleurs, SDL_HWSURFACE | SDL_DOUBLEBUF);
//SDL_CreateRGBSurface(SDL_HWSURFACE, largeur,hauteur,32,0,0,0,0);
if (screen == NULL)
{
cerr << "Erreur dans l'initialisation des modes vidéos:" <<
SDL_GetError ();
SDL_Quit ();
}
SDL_WM_SetCaption (titre, NULL);
fond = SDL_LoadBMP (background);
SDL_BlitSurface (fond, NULL, screen, NULL);
SDL_Flip (screen);
HardBG=SDL_CreateRGBSurface(SDL_HWSURFACE, largeur, hauteur, 32, 0,0,0,0);
SDL_BlitSurface( fond, NULL, HardBG, NULL);
Voiture.loadImage("Cars/voiture4.bmp");
circuit=1;
}
void Fenetre::loadBG(char *background)
{
fond = SDL_LoadBMP (background);
SDL_BlitSurface (fond, NULL, /*screen*/HardBG, NULL);
SDL_BlitSurface( fond, NULL, HardBG, NULL);
SDL_Flip (screen);
}
Fenetre::~Fenetre ()
{
/*
if(fond) SDL_FreeSurface (fond);
if(screen) SDL_FreeSurface (screen);
*/
SDL_Quit ();
}
void Fenetre::showView(int x,int y)
{
bool* v=Voiture.getView();
SDL_Rect r;
r.x=x; r.y=y-1; r.h=1; r.w=4*CAMVECT;
SDL_FillRect(screen,&r, SDL_MapRGB(screen->format, 255,0,0));
r.x=x; r.y=y+4; r.h=1; r.w=4*CAMVECT;
SDL_FillRect(screen,&r, SDL_MapRGB(screen->format, 255,0,0));
for(int i=0;i<CAMVECT;i++)
{
if(v[i])
{
r.x=x+(4*i);
r.y=y;
r.w=4;
r.h=4;
SDL_FillRect(screen,&r, SDL_MapRGB(screen->format, 0,0,0));
}
}
}
void Fenetre::showObstacle()
{
SDL_Rect r;
r.x=400;
r.y=20;
r.w=40;
r.h=screen->h-40;
SDL_FillRect(screen,&r, SDL_MapRGB(screen->format, 255,0,0));
}
void Fenetre::showPilot(int x,int y)
{
if(Voiture.getVect()[0])
for(int i=0;i<16;i++)
{
for(int j=y-i;j<y+i;j++)
putPixel(x+i,j,0,0,0);
}
if(Voiture.getVect()[1])
for(int i=0;i<16;i++)
{
for(int j=y-i;j<y+i;j++)
putPixel(x+64-i,j,0,0,0);
}
if(Voiture.getVect()[2]==1)
for(int i=0;i<16;i++)
{
for(int j=x-i+32;j<x+i+32;j++)
putPixel(j,y+i-32,0,0,0);
}
if(Voiture.getVect()[2]==0)
for(int i=0;i<16;i++)
{
for(int j=x-i+32;j<x+i+32;j++)
putPixel(j,y-i+32,0,0,0);
}
}
void Fenetre::drawText()
{
char *bf=(char*)malloc(256);
sprintf(bf,": %d",Voiture.APState());
SFont_Write(screen,font,10,10,"AutoPilot (a)");
SFont_Write(screen,font,120,10,bf);
sprintf(bf,": %d",Voiture.neurState());
SFont_Write(screen,font,10,25,"NeuronPilot (n)");
SFont_Write(screen,font,120,25,bf);
sprintf(bf,": %d",Voiture.getSpeed());
SFont_Write(screen,font,10,40,"Speed");
SFont_Write(screen,font,120,40,bf);
sprintf(bf,": %d",Voiture.getAngle());
SFont_Write(screen,font,10,55,"Angle");
SFont_Write(screen,font,120,55,bf);
sprintf(bf,": %d",fps);
SFont_Write(screen,font,10,70,"Framerate");
SFont_Write(screen,font,120,70,bf);
sprintf(bf,": %d",Voiture.incTraineeSize(0));
SFont_Write(screen,font,10,85,"trainee(F8,F9)");
SFont_Write(screen,font,120,85,bf);
sprintf(bf,": %d",Voiture.showBar(0));
SFont_Write(screen,font,200,10,"Showbar (b)");
SFont_Write(screen,font,300,10,bf);
sprintf(bf,": %d",SHOWcamera);
SFont_Write(screen,font,200,25,"Showcam (c)");
SFont_Write(screen,font,300,25,bf);
sprintf(bf,": %d",SHOWpilot);
SFont_Write(screen,font,200,40,"Showpilot (p)");
SFont_Write(screen,font,300,40,bf);
sprintf(bf,": %d",obstacle);
SFont_Write(screen,font,200,55,"Obstacle (o)");
SFont_Write(screen,font,300,55,bf);
sprintf(bf,": %d",Voiture.incAngleStep(0));
SFont_Write(screen,font,200,70,"AStep (pgU-D)");
SFont_Write(screen,font,300,70,bf);
sprintf(bf,": %d",Voiture.showNetworkState());
SFont_Write(screen,font,200,85,"NeuronIface(i)");
SFont_Write(screen,font,300,85,bf);
DrawLine(screen,0,99,319,99,0,0,128);
}
void Fenetre::redraw()
{
#ifdef __DEBUG_TIME
Uint32 deltatime;
#endif
if(sec!=time(NULL)) { sec=time(NULL); fps=frame; frame=0; }
frame++;
#ifdef __DEBUG_TIME
deltatime=SDL_GetTicks();
#endif
/* SDL_BlitSurface( fond, NULL, screen, NULL); Software Mode */
SDL_BlitSurface( HardBG, NULL, screen , NULL); /* Hardware Mode */
#ifdef __DEBUG_TIME
printf("Background Blit : %d ms, ",SDL_GetTicks()-deltatime);
deltatime=SDL_GetTicks();
#endif
drawText();
if(SHOWpilot) showPilot(440,50);
if(SHOWcamera) showView(350,10);
if(obstacle) showObstacle();
Voiture.updateCar(screen);
#ifdef __DEBUG_TIME
printf("Car Update : %d ms, ",SDL_GetTicks()-deltatime);
deltatime=SDL_GetTicks();
#endif
SDL_Flip (screen);
#ifdef __DEBUG_TIME
printf("Screen Refresh : %d ms\n",SDL_GetTicks()-deltatime);
#endif
}
void Fenetre::putPixel(int x, int y, char r, char g, char b)
{
setpixel(screen,x,y,r,g,b);
}
void Fenetre::handle()
{
int exitkey = 0;
bool shownet= 0;
int waitdel = 20;
SDL_Event event;
while (!exitkey)
{
SDL_Delay (waitdel);
redraw();
while (SDL_PollEvent (&event))
{
switch (event.type)
{
case SDL_QUIT:
exitkey = 1;
printf ("Quit!\n");
break;
case SDL_KEYDOWN:
switch (event.key.keysym.sym)
{
case SDLK_ESCAPE:
Voiture.harakiri();
exitkey = 1;
break;
case SDLK_LEFT:
Voiture.decAngle();
break;
case SDLK_RIGHT:
Voiture.incAngle();
break;
case SDLK_DOWN:
Voiture.decSpeed();
break;
case SDLK_UP:
Voiture.incSpeed();
break;
case SDLK_a:
Voiture.APToggle();
break;
case SDLK_b:
Voiture.showBar(1);
break;
case SDLK_c:
SHOWcamera=(SHOWcamera+1)%2;
break;
case SDLK_i:
shownet=(shownet+1)%2;
Voiture.showNetwork(shownet);
break;
case SDLK_n:
Voiture.neurToggle();
break;
case SDLK_o:
obstacle=(obstacle+1)%2;
break;
case SDLK_p:
SHOWpilot=(SHOWpilot+1)%2;
break;
case SDLK_r:
Voiture.reset();
break;
case SDLK_t:
Voiture.turn180();
break;
case SDLK_w:
Voiture.saveState();
//SData->action=SAVE_STATE;
break;
case SDLK_x:
Voiture.loadState();
//SData->action=RELOAD_STATE;
break;
case SDLK_F1:
printf("Chargement Circuit 1\n");
circuit=1;
loadBG("Back/bg1.bmp");
break;
case SDLK_F2:
printf("Chargement Circuit 2\n");
circuit=2;
loadBG("Back/bg2.bmp");
break;
case SDLK_F3:
printf("Chargement Circuit 3\n");
circuit=3;
loadBG("Back/bg3.bmp");
break;
case SDLK_F4:
printf("Chargement Circuit 4\n");
circuit=4;
loadBG("Back/bg4.bmp");
break;
case SDLK_F5:
printf("Chargement Circuit 5\n");
circuit=5;
loadBG("Back/bg5.bmp");
break;
case SDLK_F6:
printf("Chargement Circuit 6\n");
circuit=6;
loadBG("Back/bg6.bmp");
break;
case SDLK_F7:
Voiture.incTraineeSize(-256);
break;
case SDLK_F8:
Voiture.incTraineeSize(256);
break;
case SDLK_F9:
printf("Chargement Voiture 1\n");
Voiture.loadImage("Cars/voiture1.bmp");
break;
case SDLK_F10:
printf("Chargement Voiture 2\n");
Voiture.loadImage("Cars/voiture2.bmp");
break;
case SDLK_F11:
printf("Chargement Voiture 3\n");
Voiture.loadImage("Cars/voiture3.bmp");
break;
case SDLK_F12:
printf("Chargement Voiture 4\n");
Voiture.loadImage("Cars/voiture4.bmp");
break;
case SDLK_PAGEUP:
Voiture.incAngleStep(1);
break;
case SDLK_PAGEDOWN:
Voiture.incAngleStep(-1);
break;
case SDLK_HOME:
waitdel+=5;
break;
case SDLK_END:
waitdel-=5;
if(waitdel<0) waitdel=0;
break;
default :
break;
}
break;
}
break;
}
}
}

34
InterfaceCpp/fenetre.h Normal file
View File

@@ -0,0 +1,34 @@
#ifndef __FENETRE_H
#define __FENETRE_H
#include "car.h"
#include "SFont.h"
#define FONT_PATH "font.png"
class Fenetre
{
private:
SDL_Surface* screen;
SDL_Surface* fond;
SDL_Surface* HardBG;
SFont_Font* font;
Car Voiture;
int frame,sec,fps,circuit;
bool SHOWpilot,SHOWcamera,obstacle;
public:
Fenetre();
Fenetre (int , int , int , char *, char *);
~Fenetre();
void loadBG(char *);
void redraw();
void handle();
void putPixel(int , int , char, char, char);
void showView(int ,int);
void showPilot(int,int);
void showObstacle();
void drawText();
};
#endif

34
InterfaceCpp/fenetre.h~ Normal file
View File

@@ -0,0 +1,34 @@
#ifndef __FENETRE_H
#define __FENETRE_H
#include "car.h"
#include "SFont.h"
#define FONT_PATH "font.png"
class Fenetre
{
private:
SDL_Surface* screen;
SDL_Surface* fond;
SDL_Surface* HardBG;
SFont_Font* font;
car Voiture;
int frame,sec,fps,circuit;
bool SHOWpilot,SHOWcamera,obstacle;
public:
Fenetre();
Fenetre (int , int , int , char *, char *);
~Fenetre();
void loadBG(char *);
void redraw();
void handle();
void putPixel(int , int , char, char, char);
void showView(int ,int);
void showPilot(int,int);
void showObstacle();
void drawText();
};
#endif

BIN
InterfaceCpp/fenetre.o Normal file

Binary file not shown.

BIN
InterfaceCpp/font.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

BIN
InterfaceCpp/iface Executable file

Binary file not shown.

17
InterfaceCpp/main.cpp Normal file
View File

@@ -0,0 +1,17 @@
#include <iostream>
#include <SDL.h>
#include "fenetre.h"
using namespace std;
int main()
{
Fenetre f(800,600,32,"Auto Pilot","Back/bg1.bmp");
f.redraw();
f.handle();
return 1;
}

BIN
InterfaceCpp/main.o Normal file

Binary file not shown.

238
InterfaceCpp/sdlcommon.cpp Normal file
View File

@@ -0,0 +1,238 @@
#include <stdio.h>
#include <stdlib.h>
#include <SDL.h>
#include <math.h>
#include "sdlcommon.h"
bool inCarArea(SDL_Surface *screen, int x, int y)
{
if(x<0 || y<0 || x>screen->w || y>screen->h) return 0;
if(x<320 && y<100) return 0;
//DrawLine(screen,0,100,320,100,0,0,128);
return 1;
}
void setpixel(SDL_Surface *screen, int x, int y, Uint8 r, Uint8 g, Uint8 b)
{
Uint8 *ubuff8;
Uint16 *ubuff16;
Uint32 *ubuff32;
Uint32 color;
char c1, c2, c3;
if(x >= screen->w || x < 0 || y >= screen->h || y <0 ) return;
if(SDL_MUSTLOCK(screen))
{
if(SDL_LockSurface(screen) < 0)
return;
}
color = SDL_MapRGB( screen->format, r, g, b );
switch(screen->format->BytesPerPixel)
{
case 1:
ubuff8 = (Uint8*) screen->pixels;
ubuff8 += (y * screen->pitch) + x;
*ubuff8 = (Uint8) color;
break;
case 2:
ubuff8 = (Uint8*) screen->pixels;
ubuff8 += (y * screen->pitch) + (x*2);
ubuff16 = (Uint16*) ubuff8;
*ubuff16 = (Uint16) color;
break;
case 3:
ubuff8 = (Uint8*) screen->pixels;
ubuff8 += (y * screen->pitch) + (x*3);
if(SDL_BYTEORDER == SDL_LIL_ENDIAN)
{
c1 = (color & 0xFF0000) >> 16;
c2 = (color & 0x00FF00) >> 8;
c3 = (color & 0x0000FF);
}
else {
c3 = (color & 0xFF0000) >> 16;
c2 = (color & 0x00FF00) >> 8;
c1 = (color & 0x0000FF);
}
ubuff8[0] = c3;
ubuff8[1] = c2;
ubuff8[2] = c1;
break;
case 4:
ubuff8 = (Uint8*) screen->pixels;
ubuff8 += (y*screen->pitch) + (x*4);
ubuff32 = (Uint32*)ubuff8;
*ubuff32 = color;
break;
default:
fprintf(stderr, "Error: Unknown bitdepth!\n");
}
if(SDL_MUSTLOCK(screen))
{
SDL_UnlockSurface(screen);
}
}
int getpixel(SDL_Surface *screen, int x, int y)
{
int bpp = screen->format->BytesPerPixel;
Uint8 *p = (Uint8 *)screen->pixels + y * screen->pitch + x * bpp;
switch(bpp)
{
case 1:
return *p;
case 2:
return *(Uint16 *)p;
case 3:
if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
return p[0] << 16 | p[1] << 8 | p[2];
else
return p[0] | p[1] << 8 | p[2] << 16;
case 4:
return *(Uint32 *)p;
default:
return 0;
}
}
void interpole(SDL_Surface* src, SDL_Surface* dst, Uint32 nulcol)
{
/* Interpolation */
Uint32 ipol;
for(int i=1;i< (src->w-1) ;i++)
for(int j=1;j< (src->h-1);j++)
{
if((ipol=getpixel(src,i,j))==nulcol)
{
Uint32 ir=0,ig=0,ib=0;
int tot=0;
if((ipol=getpixel(src,i-1,j-1))!=NULLCOL){
ir+=(ipol>>16)%256; ig+=(ipol>>8)%256; ib+=(ipol)%256;
tot++;
}
if((ipol=getpixel(src,i-1,j-1))!=NULLCOL){
ir+=(ipol>>16)%256; ig+=(ipol>>8)%256; ib+=(ipol)%256;
tot++;
}
if((ipol=getpixel(src,i-1,j-1))!=NULLCOL){
ir+=(ipol>>16)%256; ig+=(ipol>>8)%256; ib+=(ipol)%256;
tot++;
}
if((ipol=getpixel(src,i-1,j-1))!=NULLCOL){
ir+=(ipol>>16)%256; ig+=(ipol>>8)%256; ib+=(ipol)%256;
tot++;
}
if((ipol=getpixel(src,i-1,j-1))!=NULLCOL){
ir+=(ipol>>16)%256; ig+=(ipol>>8)%256; ib+=(ipol)%256;
tot++;
}
if((ipol=getpixel(src,i-1,j-1))!=NULLCOL){
ir+=(ipol>>16)%256; ig+=(ipol>>8)%256; ib+=(ipol)%256;
tot++;
}
if((ipol=getpixel(src,i-1,j-1))!=NULLCOL){
ir+=(ipol>>16)%256; ig+=(ipol>>8)%256; ib+=(ipol)%256;
tot++;
}
if((ipol=getpixel(src,i-1,j-1))!=NULLCOL){
ir+=(ipol>>16)%256; ig+=(ipol>>8)%256; ib+=(ipol)%256;
tot++;
}
if((ipol=getpixel(src,i,j-2))!=NULLCOL){
ir+=(ipol>>16)%256; ig+=(ipol>>8)%256; ib+=(ipol)%256;
tot++;
}
if((ipol=getpixel(src,i,j+1))!=NULLCOL){
ir+=(ipol>>16)%256; ig+=(ipol>>8)%256; ib+=(ipol)%256;
tot++;
}
if((ipol=getpixel(src,i-2,j))!=NULLCOL){
ir+=(ipol>>16)%256; ig+=(ipol>>8)%256; ib+=(ipol)%256;
tot++;
}
if((ipol=getpixel(src,i+2,j))!=NULLCOL){
ir+=(ipol>>16)%256; ig+=(ipol>>8)%256; ib+=(ipol)%256;
tot++;
}
if(tot>3)
{
ir/=tot;
ig/=tot;
ib/=tot;
//printf("interpol pixel %d,%d, with %d,%d,%d (%d)\n",i,j,ir,ig,ib,tot);
setpixel(dst,i,j,(Uint8)ir,(Uint8)ig,(Uint8)ib);
//setpixel(dst,i,j,255,0,0);
}
// else pixel à interpolé entouré de rien ...
}
else {
setpixel(dst,i,j,(Uint8)(ipol>>16),(Uint8)(ipol>>8),(Uint8)(ipol));
//setpixel(dst,i,j,0,255,0);
}
}
}
void DrawLine(SDL_Surface* screen, int x1, int y1, int x2, int y2, char r, char g, char b)
{
double dx,dy,x,y;
int step,i;
if(abs(x2-x1)>abs(y2-y1)) step=abs(x2-x1);
else step=abs(y2-y1);
dx=(x2-x1);
dy=(y2-y1);
dx/=step;
dy/=step;
x=x1;
y=y1;
for(i=0;i<step;i++)
{
x=x+dx;
y=y+dy;
setpixel(screen,(int)x,(int)y,r,g,b);
}
}
void rotatesurface(SDL_Surface *src, SDL_Surface *dst, int anginc)
{
Uint32 pix,x,y;
double angle,ba,ca,norm;
Uint8 r,g,b;
SDL_Surface *tmp;
SDL_Rect rec;
rec.h=src->h;
rec.w=src->w;
rec.x=0;
rec.y=0;
tmp=SDL_CreateRGBSurface(SDL_HWSURFACE, src->w, src->h, 32, 0,0,0,0);
SDL_FillRect(tmp,&rec, SDL_MapRGB(tmp->format,NULLCOLR,NULLCOLG,NULLCOLB/**/));
SDL_FillRect(dst,&rec, SDL_MapRGB(tmp->format,NULLCOLR,NULLCOLG,NULLCOLB/**/));
for(int i=0;i<src->w;i++)
for(int j=0;j<src->h;j++)
{
pix=getpixel(src,i,j);
r=pix>>16; // couleur R
g=pix>>8; // couleur G
b=pix; // couleur B
ba=(src->w/2)-i; // base
ca=(src->h/2)-j; // cote adjascent
norm=sqrt(ba*ba+ca*ca); // norme
angle=atan(ca/ba); // angle
if(i>(src->w)/2) angle+=(PI);
angle+=(anginc*PI/180); // angle tourné
x=(int)round((src->w/2)-(norm*cos(angle)));
y=(int)round((src->h/2)-(norm*sin(angle)));
setpixel(tmp, x,y, r,g,b);
}
pix=getpixel(src,(src->w/2),(src->h/2));
setpixel(tmp, (src->w/2),(src->h/2), pix>>16,pix>>8,pix);
//SDL_BlitSurface(tmp , NULL, dst, NULL);
interpole(tmp,dst, NULLCOL);
}

28
InterfaceCpp/sdlcommon.h Normal file
View File

@@ -0,0 +1,28 @@
#ifndef __SDLCOMMON_H
#define __SDLCOMMON_H
#include <SDL.h>
#include <SDL_image.h>
#ifndef PI
#define PI 3.141592
#endif
#ifndef NULLCOL
#define NULLCOL 0x00FF00FF
#define NULLCOLA 0xFF
#define NULLCOLR 0xFF
#define NULLCOLG 0x00
#define NULLCOLB 0xFF
#endif
void setpixel(SDL_Surface*, int, int, Uint8, Uint8, Uint8);
int getpixel(SDL_Surface*, int, int);
void DrawLine(SDL_Surface*, int , int , int , int , char , char, char);
void rotatesurface(SDL_Surface*, SDL_Surface*, int);
void interpole(SDL_Surface* , SDL_Surface* , Uint32 );
bool inCarArea(SDL_Surface* , int , int );
#endif

26
InterfaceCpp/sdlcommon.h~ Normal file
View File

@@ -0,0 +1,26 @@
#ifndef __SDLCOMMON_H
#define __SDLCOMMON_H
#ifndef PI
#define PI 3.141592
#endif
#ifndef NULLCOL
#define NULLCOL 0x00FF00FF
#define NULLCOLA 0xFF
#define NULLCOLR 0xFF
#define NULLCOLG 0x00
#define NULLCOLB 0xFF
#endif
void setpixel(SDL_Surface*, int, int, Uint8, Uint8, Uint8);
int getpixel(SDL_Surface*, int, int);
void DrawLine(SDL_Surface*, int , int , int , int , char , char, char);
void rotatesurface(SDL_Surface*, SDL_Surface*, int);
void interpole(SDL_Surface* , SDL_Surface* , Uint32 );
bool inCarArea(SDL_Surface* , int , int );
#endif

BIN
InterfaceCpp/sdlcommon.o Normal file

Binary file not shown.

34
InterfaceCpp/shmdata.h Normal file
View File

@@ -0,0 +1,34 @@
#ifndef __SHMDATA_H
#define __SHMDATA_H
#define SHMKEY 5678
#define CAMERASIZE 128
#define CAMERASTEP 2
#define CAMERADISTANCE 50
#define CAMVECT (CAMERASIZE/CAMERASTEP)
#define NOMBRE_NEURONES_INTERMEDIAIRES 8
#define TAILLERESULTAT 3
#define SAVE_STATE 1
#define RELOAD_STATE 2
#define STATE_FILE "State.network"
struct shmdata
{
bool V[CAMVECT]; /* vecteur camera */
bool Res[3]; /* 0 gauche 1 droite 2 avancer 3 stop*/
int read; /* 1 = info a ete traitée */
int angle; /* angle de la voiture 0->359 */
int speed; /* vitesse */
int APon; /* pilote automatique (mode apprentissage) (0/1) */
int Neuron; /* activer le reseau de neurone (0/1) */
double pos_x; /* position x de la voiture */
double pos_y; /* position y de la voiture */
int action; /* action a executer (genre sauvegarde) */
int delay; /* delai entre les frames */
bool viewNetwork; /* afficher le reseau */
};
#endif

33
InterfaceCpp/shmdata.h~ Normal file
View File

@@ -0,0 +1,33 @@
#ifndef __SHMDATA_H
#define __SHMDATA_H
#define SHMKEY 5678
#define CAMERASIZE 128
#define CAMERASTEP 2
#define CAMERADISTANCE 50
#define CAMVECT (CAMERASIZE/CAMERASTEP)
#define NOMBRE_NEURONES_INTERMEDIAIRES 8
#define TAILLERESULTAT 3
#define SAVE_STATE 1
#define RELOAD_STATE 2
#define STATE_FILE "State.network"
struct shmdata
{
bool V[CAMVECT]; /* vecteur camera */
bool Res[3]; /* 0 gauche 1 droite 2 avancer 3 stop*/
int read; /* 1 = info a ete traitée */
int angle; /* angle de la voiture 0->359 */
int speed; /* vitesse */
int APon; /* pilote automatique (mode apprentissage) (0/1) */
int Neuron; /* activer le reseau de neurone (0/1) */
double pos_x; /* position x de la voiture */
double pos_y; /* position y de la voiture */
int action; /* action a executer (genre sauvegarde) */
int delay; /* delai entre les frames */
};
#endif