solilo1
21/04/2007, 13h42
Bonjour,
voici un programme pour joueur d'echec. Ce sont 2 horloges qui basculent de l'une vers l'autre en appuyant sur L ou R.
mon probleme est que le timer des noirs démarre a 255.
voici les resultats des osldebug du programme ci-dessous:
le N°1 donne correctement 60
le N°2 donne une valeur aléatoire ???
le N°3 aussi
l'osldebub dans le "CASE BLANC" donne 255.
je ne comprends pas les résultats. et encore moins le N°2 car entre le N°2 et le N°1 la seule différence est que je fait un appel à la fonction oslReadKeys.
#include <oslib/oslib.h>
PSP_MODULE_INFO("COUNTER PROGRAM", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
#define BLANC 1
#define NOIR 2
#define INACTIF 0
typedef struct {
int Trestant;
int PosX, PosY;
} Clock;
Clock Chessclock[1];
OSL_SOUND *sonFin;
int Ti=60;
void affiche (int PosiX, int PosiY, int minutes, int seconds) {
oslPrintf_xy (PosiX, PosiY,"heure %d:%d\n", minutes, seconds);
}
void initialisation () {
//init NOIR
Chessclock[1].Trestant=Ti;
Chessclock[1].PosX=1;
Chessclock[1].PosY=30;
//init BLANC
Chessclock[0].Trestant=Ti;
Chessclock[0].PosX=1;
Chessclock[0].PosY=35;
}
int boucle (void) {
time_t counter,startcounter;
int Temps;
int PosX,PosY;
int seconds, minutes;
int actif=BLANC;//timer blanc actif a démarrage
// initialisation
initialisation();
Temps=Chessclock[0].Trestant;
PosX=Chessclock[0].PosX;
PosY=Chessclock[0].PosY;
oslCls();
oslPrintf_xy(1,5,"Ti= %d\n", Ti);
oslPrintf("TBlanc= %d\n", Chessclock[0].Trestant);
oslPrintf("TNoir = %d\n", Chessclock[1].Trestant);
oslPrintf("cercle pour demarrer \n");
seconds = Ti % 60;
minutes = Ti / 60;
affiche (PosX, PosY+25,minutes,seconds);
oslSyncFrame();
oslDebug("N°1 temps noir:%d", Chessclock[1].Trestant);
// pour demarrer
while (!osl_keys->pressed.circle) {
oslReadKeys();
}
oslPrintf("cercle pressed \n");
oslDebug("N°2 temps noir:%d", Chessclock[1].Trestant);
oslCls();
oslSyncFrame();
oslDebug("N°3 temps noir:%d", Chessclock[1].Trestant);
startcounter=sceKernelLibcTime(NULL);
// boucle principale
while (actif!=INACTIF) {
oslReadKeys();
switch (actif) {
case BLANC :
if (osl_keys->pressed.L){
oslPrintf_xy(1,5,"L pressed");
Chessclock[0].Trestant=Temps; //sauve temps
oslPrintf_xy(1,40,"Temps blanc sauve %d",Chessclock[0].Trestant);
oslDebug("dans boucle temps noir:%d", Chessclock[1].Trestant);
actif=NOIR;// on tourne
Temps=Chessclock[1].Trestant;
oslPrintf_xy(1,45,"temp noir %d",Temps);
PosX=Chessclock[1].PosX;
PosY=Chessclock[1].PosY;
startcounter= sceKernelLibcTime(NULL); //redémarrage counter
}
break;
case NOIR :
if (osl_keys->pressed.R){
oslPrintf_xy(1,5,"R pressed");
Chessclock[1].Trestant=Temps; //sauve temps
oslPrintf_xy(1,50,"Temps noir sauve %d",Chessclock[1].Trestant);
actif=BLANC;// on tourne
Temps=Chessclock[0].Trestant;
PosX=Chessclock[0].PosX;
PosY=Chessclock[0].PosY;
startcounter= sceKernelLibcTime(NULL); //redémarrage counter
}
break;
}
if (osl_keys->pressed.square) actif=INACTIF;
counter = sceKernelLibcTime(NULL) - startcounter;
if (counter!=0) {
startcounter=sceKernelLibcTime(NULL);
Temps--;
oslPrintf_xy(PosX,PosY,"Timer %d",Temps);
}
seconds = Temps % 60;
minutes = Temps / 60;
affiche(PosX,PosY+15,minutes,seconds);
// fin
if (Temps<0) {
actif=INACTIF; // fin
oslPlaySound(sonFin, 1);
}
oslSyncFrame();
}
return 0;
}
int main(int argc, char* argv[])
{
//Initialization
oslInit(0); //The lib
oslInitGfx(OSL_PF_8888, 1); //Gfx
oslInitConsole(); //Text
//Initialiser l'audio
oslInitAudio();
sonFin = oslLoadSoundFile("chimes.wav", OSL_FMT_NONE);
//Configure the joypad
// oslSetKeyAutorepeatInit(40);
// oslSetKeyAutorepeatInterval(10);
//vérification
if (!sonFin)
oslDebug("Verifiez que tous les fichiers sont bien copiés dans le répertoire du jeu.");
while (!osl_quit)
{
oslStartDrawing();
boucle();
oslCls();
oslPrintf("Cercle pour recommencer, triangle pour arreter \n");
// on recommence ?
oslSyncFrame();
while (!osl_quit) {
oslReadKeys();
if (osl_keys->pressed.triangle) oslQuit();
if (osl_keys->pressed.circle) break;
}
oslSyncFrame();
oslEndDrawing();
//pour la mise en veille
oslAudioVSync();
}
oslEndGfx();
oslQuit();
return 0;
}
voici un programme pour joueur d'echec. Ce sont 2 horloges qui basculent de l'une vers l'autre en appuyant sur L ou R.
mon probleme est que le timer des noirs démarre a 255.
voici les resultats des osldebug du programme ci-dessous:
le N°1 donne correctement 60
le N°2 donne une valeur aléatoire ???
le N°3 aussi
l'osldebub dans le "CASE BLANC" donne 255.
je ne comprends pas les résultats. et encore moins le N°2 car entre le N°2 et le N°1 la seule différence est que je fait un appel à la fonction oslReadKeys.
#include <oslib/oslib.h>
PSP_MODULE_INFO("COUNTER PROGRAM", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
#define BLANC 1
#define NOIR 2
#define INACTIF 0
typedef struct {
int Trestant;
int PosX, PosY;
} Clock;
Clock Chessclock[1];
OSL_SOUND *sonFin;
int Ti=60;
void affiche (int PosiX, int PosiY, int minutes, int seconds) {
oslPrintf_xy (PosiX, PosiY,"heure %d:%d\n", minutes, seconds);
}
void initialisation () {
//init NOIR
Chessclock[1].Trestant=Ti;
Chessclock[1].PosX=1;
Chessclock[1].PosY=30;
//init BLANC
Chessclock[0].Trestant=Ti;
Chessclock[0].PosX=1;
Chessclock[0].PosY=35;
}
int boucle (void) {
time_t counter,startcounter;
int Temps;
int PosX,PosY;
int seconds, minutes;
int actif=BLANC;//timer blanc actif a démarrage
// initialisation
initialisation();
Temps=Chessclock[0].Trestant;
PosX=Chessclock[0].PosX;
PosY=Chessclock[0].PosY;
oslCls();
oslPrintf_xy(1,5,"Ti= %d\n", Ti);
oslPrintf("TBlanc= %d\n", Chessclock[0].Trestant);
oslPrintf("TNoir = %d\n", Chessclock[1].Trestant);
oslPrintf("cercle pour demarrer \n");
seconds = Ti % 60;
minutes = Ti / 60;
affiche (PosX, PosY+25,minutes,seconds);
oslSyncFrame();
oslDebug("N°1 temps noir:%d", Chessclock[1].Trestant);
// pour demarrer
while (!osl_keys->pressed.circle) {
oslReadKeys();
}
oslPrintf("cercle pressed \n");
oslDebug("N°2 temps noir:%d", Chessclock[1].Trestant);
oslCls();
oslSyncFrame();
oslDebug("N°3 temps noir:%d", Chessclock[1].Trestant);
startcounter=sceKernelLibcTime(NULL);
// boucle principale
while (actif!=INACTIF) {
oslReadKeys();
switch (actif) {
case BLANC :
if (osl_keys->pressed.L){
oslPrintf_xy(1,5,"L pressed");
Chessclock[0].Trestant=Temps; //sauve temps
oslPrintf_xy(1,40,"Temps blanc sauve %d",Chessclock[0].Trestant);
oslDebug("dans boucle temps noir:%d", Chessclock[1].Trestant);
actif=NOIR;// on tourne
Temps=Chessclock[1].Trestant;
oslPrintf_xy(1,45,"temp noir %d",Temps);
PosX=Chessclock[1].PosX;
PosY=Chessclock[1].PosY;
startcounter= sceKernelLibcTime(NULL); //redémarrage counter
}
break;
case NOIR :
if (osl_keys->pressed.R){
oslPrintf_xy(1,5,"R pressed");
Chessclock[1].Trestant=Temps; //sauve temps
oslPrintf_xy(1,50,"Temps noir sauve %d",Chessclock[1].Trestant);
actif=BLANC;// on tourne
Temps=Chessclock[0].Trestant;
PosX=Chessclock[0].PosX;
PosY=Chessclock[0].PosY;
startcounter= sceKernelLibcTime(NULL); //redémarrage counter
}
break;
}
if (osl_keys->pressed.square) actif=INACTIF;
counter = sceKernelLibcTime(NULL) - startcounter;
if (counter!=0) {
startcounter=sceKernelLibcTime(NULL);
Temps--;
oslPrintf_xy(PosX,PosY,"Timer %d",Temps);
}
seconds = Temps % 60;
minutes = Temps / 60;
affiche(PosX,PosY+15,minutes,seconds);
// fin
if (Temps<0) {
actif=INACTIF; // fin
oslPlaySound(sonFin, 1);
}
oslSyncFrame();
}
return 0;
}
int main(int argc, char* argv[])
{
//Initialization
oslInit(0); //The lib
oslInitGfx(OSL_PF_8888, 1); //Gfx
oslInitConsole(); //Text
//Initialiser l'audio
oslInitAudio();
sonFin = oslLoadSoundFile("chimes.wav", OSL_FMT_NONE);
//Configure the joypad
// oslSetKeyAutorepeatInit(40);
// oslSetKeyAutorepeatInterval(10);
//vérification
if (!sonFin)
oslDebug("Verifiez que tous les fichiers sont bien copiés dans le répertoire du jeu.");
while (!osl_quit)
{
oslStartDrawing();
boucle();
oslCls();
oslPrintf("Cercle pour recommencer, triangle pour arreter \n");
// on recommence ?
oslSyncFrame();
while (!osl_quit) {
oslReadKeys();
if (osl_keys->pressed.triangle) oslQuit();
if (osl_keys->pressed.circle) break;
}
oslSyncFrame();
oslEndDrawing();
//pour la mise en veille
oslAudioVSync();
}
oslEndGfx();
oslQuit();
return 0;
}