From 04d5f63a02263a4b9e3aa41ce65ba0bd332723ef Mon Sep 17 00:00:00 2001 From: Thomas Pietrzak Date: Wed, 1 Jun 2011 14:16:19 +0000 Subject: [PATCH] SDL Uint types ; SDL_GetTicks ; fix some warnings ; fix keyboard log for speed/accuracy git-svn-id: svn+ssh://thomaspietrzak.com/var/svn/rep@19 47cf9a05-e0a8-4ed5-9e9b-101a649bc004 --- Haptic Metronome/Haptic Metronome.suo | Bin 31232 -> 31232 bytes .../Haptic Metronome/Haptic Metronome.vcxproj | 2 +- include/Config.hpp | 27 ++-- include/MIDIReader.hpp | 12 +- include/Metronome.hpp | 10 +- include/MetronomeAudio.hpp | 2 +- include/MetronomeHaptic.hpp | 6 +- include/PaintGame.h | 22 ++-- include/Tools.hpp | 7 + include/Track.hpp | 62 ++++----- include/Wiimote.hpp | 20 ++- src/Config.cpp | 4 +- src/MIDIReader.cpp | 84 ++++++------ src/Metronome.cpp | 2 +- src/MetronomeAudio.cpp | 44 ++----- src/MetronomeHaptic.cpp | 122 +++--------------- src/PaintGame.cpp | 107 ++++++++------- src/Track.cpp | 88 ++++++------- src/Wiimote.cpp | 19 +-- src/main.cpp | 11 +- 20 files changed, 277 insertions(+), 374 deletions(-) diff --git a/Haptic Metronome/Haptic Metronome.suo b/Haptic Metronome/Haptic Metronome.suo index a3b5701c4c8ad878db1c45df4247c567efc915b5..6db2e2cbbb797790d03d3691cb61c6e9c8307b08 100644 GIT binary patch delta 894 zcmZWnT}V@57(U!=AM3CN;hoF#fvMwTo)?E;kcp+s73Wva(>OF49n?86s@AG``^L*#~-Zv(am`Gj@ zP;Dibvl-T}5hcSgF&{+fN7jp}1mUx`6cPq1jH=d-u!YD}$Skkts9px5KFAgzFl7jV zKbcanRfuZk65bd9m(c@TtjB%nhe)-@S> z5YKb8Og@Wu%_*{c8ivVYmSOzDeVFl|gSWmnP~%;JsAnqs+F;MXaJcsh7l{lEo#}(1 zrwmrz(=hMeg5TbxmN0}cXFGQmW7ZzWfd$Em`|tgyo#z|{#dxy3q%KI^YsxrUV8vf3 zs9WZU;0QPrFwxpr_#N+;UgpFf%uh)5@9>c0G{UR>Yn=xh72sm7Oc2#!uA zQIW$^<)d6P@K@8V&C5uE@8YOU_7S_rl{#PU*BjlZp3m*RU%2G_X^3jj#|DX>$#kQ` zI9OpEtZ<5zUZL?o+Z$BvPmM=r__oGTI%xAutc zanr)A$95-iedn3R!t`&eq|Pr5Hxbr{dUwVH_>q8$X_gS)M-WG52|V-+!3^idchRWS SxTAyBW;>*sEB9la7X1ShAR}7< delta 808 zcmYjPZAepL6u$5Fy6)9w&UBesPTOGGls2&Zm^GWaO|9uLlVYuC>cXI}tB7H(6rvAA zJqG%(`eA?7H?#tAFoOue1^uX?pa_C~sKf<9=;LhOJ9^>rp65B|IrlvuVTpt#GJT1r zkL2a}v+|dTn&Y^z8~W*6-h*Zw!n<@cL<%YEOIgn4&B&A}tY~P3(M$_ShGzaRo+8=7 z#DbU#mW&5MGRD?}jK2=&QeON=)n$dd`p z8#Ja;p})ifPE+-4sgnw14|4nE01$0nfiob=k{Kr1MpA&5hu}v}Ce|gu?eYik^h`S# z+A_d=MLSmMglL)-#L5+c*ie|4cdan9 z_YjNJP{Nx~a#)subS%*wCOU^z+a9NKoQ9i+o323^@T`K}Jp_x56)@mhgzknYysm!% zrH$K(5>ZAp>}yj%1+hjmgiq*o!F~!l#8MpPfzkLS*z@hMKFLOFUt%uR&j-B*Z&jZ@hOn?iNq(>`Awp7RCY2 zo{8-@sIF@2^W?|WHah*X^V8b<; Level3 Disabled - _MBCS;%(PreprocessorDefinitions);WIN32 + _MBCS;%(PreprocessorDefinitions);WIN32;FULLSCREEN true diff --git a/include/Config.hpp b/include/Config.hpp index 54d0e54..5911026 100644 --- a/include/Config.hpp +++ b/include/Config.hpp @@ -16,7 +16,8 @@ enum keys { KEY0 = 0, KEY1 = 1, KEY2 = 2, KEY3 = 3, KEY4 = 4 }; #define NOTEDIST 5 #include -#include +#include +//#include #include using namespace std; @@ -26,9 +27,9 @@ using namespace std; class Config { public: - Config(uint8_t buttons, uint32_t timestamp=0, uint32_t endtimestamp=0, uint32_t time=0, uint32_t ticks=0); + Config(Uint8 buttons, Uint32 timestamp=0, Uint32 endtimestamp=0, Uint32 time=0, Uint32 ticks=0); - Config(uint32_t timestamp=0, uint32_t endtimestamp=0, uint32_t time=0, uint32_t ticks=0, + Config(Uint32 timestamp=0, Uint32 endtimestamp=0, Uint32 time=0, Uint32 ticks=0, bool a=false, bool b=false, bool c=false, bool d=false, bool e=false); Config(const Config &cf); @@ -39,17 +40,17 @@ class Config void remKey(keys k); void setKeys(bool a, bool b, bool c, bool d, bool e); - void setTimestamp(uint32_t t) { _timestamp = t; } - uint32_t getTimestamp() const { return _timestamp; } + void setTimestamp(Uint32 t) { _timestamp = t; } + Uint32 getTimestamp() const { return _timestamp; } - void setEndTimestamp(uint32_t t) { _endtimestamp = t; } - uint32_t getEndTimestamp() const { return _endtimestamp; } + void setEndTimestamp(Uint32 t) { _endtimestamp = t; } + Uint32 getEndTimestamp() const { return _endtimestamp; } - void setTime(uint32_t t) { _time = t; } - uint32_t getTime() const { return _time; } + void setTime(Uint32 t) { _time = t; } + Uint32 getTime() const { return _time; } - void setTicks(uint32_t t) { _ticks = t; } - uint32_t getTicks() const { return _ticks; } + void setTicks(Uint32 t) { _ticks = t; } + Uint32 getTicks() const { return _ticks; } void display() const; void log(const String &type, FILE *file) const; @@ -61,8 +62,8 @@ class Config bool isNone() const { return !(_a || _b || _c || _d || _e ); } private: - uint32_t _timestamp, _endtimestamp; - uint32_t _time, _ticks; + Uint32 _timestamp, _endtimestamp; + Uint32 _time, _ticks; bool _a, _b, _c, _d, _e; }; diff --git a/include/MIDIReader.hpp b/include/MIDIReader.hpp index 6c5da33..dc9e185 100644 --- a/include/MIDIReader.hpp +++ b/include/MIDIReader.hpp @@ -24,13 +24,13 @@ class MIDIReader MIDIReader(const MIDIReader &); FILE *_file; - uint16_t _nbtracks; - uint16_t _timedivision; + Uint16 _nbtracks; + Uint16 _timedivision; // unsigned long int _position; - uint8_t readVariableLength(uint32_t &); - void readBytes(void *, uint32_t); - void printBytes(uint8_t *data, uint32_t length); - uint32_t _position; + Uint8 readVariableLength(Uint32 &); + void readBytes(void *, Uint32); + void printBytes(Uint8 *data, Uint32 length); + Uint32 _position; }; #endif diff --git a/include/Metronome.hpp b/include/Metronome.hpp index 69a55e0..cbcd7b5 100644 --- a/include/Metronome.hpp +++ b/include/Metronome.hpp @@ -7,18 +7,18 @@ class Metronome { public: - Metronome(const Track *track, uint32_t nbbeats=4, uint32_t tempo=0, bool activated=false); + Metronome(const Track *track, Uint32 nbbeats=4, Uint32 tempo=0, bool activated=false); virtual ~Metronome(){} virtual void setActive(bool activated) { _activated = activated; } - virtual void setTempo(uint32_t tempo) { _tempo = tempo; } - virtual void setNbBeats(uint32_t nbbeats) {_nbbeats = nbbeats; } + virtual void setTempo(Uint32 tempo) { _tempo = tempo; } + virtual void setNbBeats(Uint32 nbbeats) {_nbbeats = nbbeats; } virtual void run()=0; protected: - uint32_t _nbbeats; - uint32_t _tempo; + Uint32 _nbbeats; + Uint32 _tempo; bool _activated; const Track *_track; }; diff --git a/include/MetronomeAudio.hpp b/include/MetronomeAudio.hpp index 8956755..7134ffc 100644 --- a/include/MetronomeAudio.hpp +++ b/include/MetronomeAudio.hpp @@ -13,7 +13,7 @@ class MetronomeAudio : public Metronome { public: - MetronomeAudio(const Track *track, uint32_t nbbeats=4, uint32_t tempo=0, bool activated=true); + MetronomeAudio(const Track *track, Uint32 nbbeats=4, Uint32 tempo=0, bool activated=true); ~MetronomeAudio(); diff --git a/include/MetronomeHaptic.hpp b/include/MetronomeHaptic.hpp index 72eff23..a8a7a98 100644 --- a/include/MetronomeHaptic.hpp +++ b/include/MetronomeHaptic.hpp @@ -15,12 +15,12 @@ class MetronomeHaptic : public Metronome { public: - MetronomeHaptic(const Track *track, uint32_t nbbeats=4, uint32_t tempo=0, bool activated=true); + MetronomeHaptic(const Track *track, Uint32 nbbeats=4, Uint32 tempo=0, bool activated=true); ~MetronomeHaptic(); - void setTempo(uint32_t tempo); - void setNbBeats(uint32_t nbbeats); + void setTempo(Uint32 tempo); + void setNbBeats(Uint32 nbbeats); void run(); diff --git a/include/PaintGame.h b/include/PaintGame.h index a223b76..c08af90 100644 --- a/include/PaintGame.h +++ b/include/PaintGame.h @@ -5,6 +5,8 @@ #define POSITION_EYE 45 #define POSITION_CENTER (-70) +#include + #include "Track.hpp" #include "String.hpp" @@ -16,11 +18,11 @@ void draw(const Track &t, char diff); void drawCube(float pos, float size, float colorx, float colory, float colorz); void drawLong(float pos, float size, float length, float colorx, float colory, float colorz); -void handleKeyOn(keys k, uint32_t currenttime); -void handleKeyOff(keys k, uint32_t currenttime); -void handleKeys(bool a, bool b, bool c, bool d, bool e, uint32_t currenttime); -void handleStrokeOn(uint32_t currenttime); -void handleStrokeOff(uint32_t currenttime); +void handleKeyOn(keys k, Uint32 currenttime); +void handleKeyOff(keys k, Uint32 currenttime); +void handleKeys(bool a, bool b, bool c, bool d, bool e, Uint32 currenttime); +void handleStrokeOn(Uint32 currenttime); +void handleStrokeOff(Uint32 currenttime); bool processEvents(); void loop(const Track &tr, const String &songname); @@ -29,11 +31,11 @@ class MyWiimote: public Wiimote public: MyWiimote():Wiimote(1){} - void handleStrumOn(uint32_t currenttime) { handleStrokeOn(currenttime); } - void handleStrumOff(uint32_t currenttime) { handleStrokeOff(currenttime); } - void handleButtonOn(int k, uint32_t currenttime) { handleKeyOn(keys(k), currenttime); } - void handleButtonOff(int k, uint32_t currenttime) { handleKeyOff(keys(k), currenttime); } - void handleButtons(bool a, bool b, bool c, bool d, bool e, uint32_t currenttime) { handleKeys(a, b, c, d, e, currenttime); } + void handleStrumOn(Uint32 currenttime) { handleStrokeOn(currenttime); } + void handleStrumOff(Uint32 currenttime) { handleStrokeOff(currenttime); } + void handleButtonOn(int k, Uint32 currenttime) { handleKeyOn(keys(k), currenttime); } + void handleButtonOff(int k, Uint32 currenttime) { handleKeyOff(keys(k), currenttime); } + void handleButtons(bool a, bool b, bool c, bool d, bool e, Uint32 currenttime) { handleKeys(a, b, c, d, e, currenttime); } }; #endif diff --git a/include/Tools.hpp b/include/Tools.hpp index 3dde2e4..aad0d5f 100644 --- a/include/Tools.hpp +++ b/include/Tools.hpp @@ -30,6 +30,13 @@ #include using namespace std; +typedef enum +{ + REGULAR, + TOMSLAW, + SPEEDACCURACY +} GameType; + #define MAX(X,Y) (X)>(Y)?(X):(Y) #define MIN(X,Y) (X)<(Y)?(X):(Y) diff --git a/include/Track.hpp b/include/Track.hpp index efcc702..03f272f 100644 --- a/include/Track.hpp +++ b/include/Track.hpp @@ -7,7 +7,7 @@ enum difficulties { EASY, NORMAL, HARD, EXPERT }; #include #include -#include +#include //temp #include @@ -41,45 +41,45 @@ class Track Track(); Track(const Track &); //create an empty track with the specified tempo and specified duration - Track(uint32_t tempo, uint32_t duration); + Track(Uint32 tempo, Uint32 duration); //create a track for speed/accuracy experiments - Track(uint8_t nbbuttons, uint8_t repetitions, uint8_t nbspeeds, uint32_t *speeds); + Track(Uint8 nbbuttons, Uint8 repetitions, Uint8 nbspeeds, Uint32 *speeds); ~Track(); - void addKey(uint32_t time, uint8_t note); - void remKey(uint32_t time, uint8_t note); + void addKey(Uint32 time, Uint8 note); + void remKey(Uint32 time, Uint8 note); - void addTempo(uint32_t tick, uint32_t timestamp, uint32_t t) { _tempo[tick] = Pair(timestamp, t); } - void addTimesignature(uint32_t tick, uint32_t timestamp, uint32_t t) { _timesignatures[tick] = Pair(timestamp, t); } - const map > *getTempos() const { return &_tempo; } - const map > *getTimeSignatures() const { return &_timesignatures; } + void addTempo(Uint32 tick, Uint32 timestamp, Uint32 t) { _tempo[tick] = Pair(timestamp, t); } + void addTimesignature(Uint32 tick, Uint32 timestamp, Uint32 t) { _timesignatures[tick] = Pair(timestamp, t); } + const map > *getTempos() const { return &_tempo; } + const map > *getTimeSignatures() const { return &_timesignatures; } // int getTempo() const { return _currenttempo; } // void setTempo(uint32 t) { _currenttempo = t; } // uint32 beatsToTicks(uint32 time) { return (time * _currenttempo * 480) / 60000.0; } -// uint32_t beatsToTicks(uint32_t time, uint32_t tempo) { return (time * tempo * 480) / 60000; } -// uint32_t ticksToBeats(uint32_t time) { return 60000000 / time; } +// Uint32 beatsToTicks(Uint32 time, Uint32 tempo) { return (time * tempo * 480) / 60000; } +// Uint32 ticksToBeats(Uint32 time) { return 60000000 / time; } void displayTracks(); - void drawFrets(uint32_t postime) const; - void drawNotes(uint32_t postime, uint8_t difficulty) const; + void drawFrets(Uint32 postime) const; + void drawNotes(Uint32 postime, Uint8 difficulty) const; // void checkMetronome(float postime, Metronome *m) const; - uint32_t getNbNotes(uint32_t k) const { return _nbnotes[k]; } - uint32_t getTotalLength(uint32_t k) const { return _totallength[k]; } - uint32_t getTotalNotes(uint32_t k) const { return _totalnotes[k]; } + Uint32 getNbNotes(Uint32 k) const { return _nbnotes[k]; } + Uint32 getTotalLength(Uint32 k) const { return _totallength[k]; } + Uint32 getTotalNotes(Uint32 k) const { return _totalnotes[k]; } - void setEndOfTrack(uint32_t length) { if (length > _trackSize) _trackSize = length; } - uint32_t getEndOfTrack() const { return _trackSize; } + void setEndOfTrack(Uint32 length) { if (length > _trackSize) _trackSize = length; } + Uint32 getEndOfTrack() const { return _trackSize; } - Config getNote(uint32_t pos, uint8_t difficulty); - uint32_t getTempo(uint32_t tick); - uint32_t getTimeSignature(uint32_t tick); + Config getNote(Uint32 pos, Uint8 difficulty); + Uint32 getTempo(Uint32 tick); + Uint32 getTimeSignature(Uint32 tick); - const list > * getBips() const { return &_bips; } - void addBip(uint32_t tick, uint32_t timestamp) { _bips.push_back(Pair(tick, timestamp)); } + const list > * getBips() const { return &_bips; } + void addBip(Uint32 tick, Uint32 timestamp) { _bips.push_back(Pair(tick, timestamp)); } //void computeBips(); @@ -87,19 +87,19 @@ class Track private: //notes : position ; configs - map _notes[NBDIFFICULTIES]; - map > _tempo; //microseconds per quarter-note - map > _timesignatures; + map _notes[NBDIFFICULTIES]; + map > _tempo; //microseconds per quarter-note + map > _timesignatures; // (beat, timestamp) - list > _bips; + list > _bips; Config _currentconfig[NBDIFFICULTIES]; - uint32_t _nbnotes[NBDIFFICULTIES]; - uint32_t _totallength[NBDIFFICULTIES]; - uint32_t _totalnotes[128]; - uint32_t _trackSize; + Uint32 _nbnotes[NBDIFFICULTIES]; + Uint32 _totallength[NBDIFFICULTIES]; + Uint32 _totalnotes[128]; + Uint32 _trackSize; bool _active; }; diff --git a/include/Wiimote.hpp b/include/Wiimote.hpp index 87b9a78..83e2963 100644 --- a/include/Wiimote.hpp +++ b/include/Wiimote.hpp @@ -1,14 +1,10 @@ #ifndef __WIIMOTE__ #define __WIIMOTE__ -#ifndef WIN32 - #include -#else - #include -#endif - #include +#include + #define MAX_WIIMOTES 4 @@ -20,14 +16,14 @@ class Wiimote{ void vibration(int wiimote, int time); - virtual void handleStrumOn(uint32_t currenttime) = 0; - virtual void handleStrumOff(uint32_t currenttime) = 0; - virtual void handleButtonOn(int k, uint32_t currenttime) = 0; - virtual void handleButtonOff(int k, uint32_t currenttime) = 0; - virtual void handleButtons(bool a, bool b, bool c, bool d, bool e, uint32_t currenttime) = 0; + virtual void handleStrumOn(Uint32 currenttime) = 0; + virtual void handleStrumOff(Uint32 currenttime) = 0; + virtual void handleButtonOn(int k, Uint32 currenttime) = 0; + virtual void handleButtonOff(int k, Uint32 currenttime) = 0; + virtual void handleButtons(bool a, bool b, bool c, bool d, bool e, Uint32 currenttime) = 0; private: - void handleKey(guitar_hero_3_t* gh3, int key, int button, uint32_t currenttime); + void handleKey(guitar_hero_3_t* gh3, int key, int button, Uint32 currenttime); wiimote **_wiimotes; int _nb; bool _strumstate, _keystate[5]; diff --git a/src/Config.cpp b/src/Config.cpp index fd0bb7e..a69d1e7 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -3,13 +3,13 @@ #include "PaintGame.h" -Config::Config(uint32_t timestamp, uint32_t endtimestamp, uint32_t time, uint32_t ticks, bool a, bool b, bool c, bool d, bool e) +Config::Config(Uint32 timestamp, Uint32 endtimestamp, Uint32 time, Uint32 ticks, bool a, bool b, bool c, bool d, bool e) :_timestamp(timestamp), _endtimestamp(endtimestamp), _time(time), _ticks(ticks), _a(a), _b(b), _c(c), _d(d), _e(e) { } -Config::Config(uint8_t buttons, uint32_t timestamp, uint32_t endtimestamp, uint32_t time, uint32_t ticks) +Config::Config(Uint8 buttons, Uint32 timestamp, Uint32 endtimestamp, Uint32 time, Uint32 ticks) :_timestamp(timestamp), _endtimestamp(endtimestamp), _time(time), _ticks(ticks), _a(buttons & 0x01), _b((buttons >> 1) & 0x01), _c((buttons >> 2) & 0x01), _d((buttons >> 3) & 0x01), _e((buttons >> 4) & 0x01) { diff --git a/src/MIDIReader.cpp b/src/MIDIReader.cpp index 9429c9d..4c45277 100644 --- a/src/MIDIReader.cpp +++ b/src/MIDIReader.cpp @@ -52,7 +52,7 @@ void MIDIReader::readHeader() if (!_file) return; - uint8_t temp[4]; + Uint8 temp[4]; //read the chunk ID fread((void *)(temp), 1, 4, _file); @@ -63,12 +63,12 @@ void MIDIReader::readHeader() } //read the chunk size - uint32_t chunksize; + Uint32 chunksize; readBytes(&chunksize, 4); SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Header size: %d\n", chunksize); //read the format - uint16_t format; + Uint16 format; readBytes(&format, 2); SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Format type: %d\n", format); @@ -87,7 +87,7 @@ void MIDIReader::readHeader() void MIDIReader::skipTrack() { - uint8_t temp[4]; + Uint8 temp[4]; //read the chunk ID fread((void *)(temp), 4, 1, _file); // cerr << temp << endl; @@ -98,7 +98,7 @@ void MIDIReader::skipTrack() } //read the chunk size - uint32_t chunksize; + Uint32 chunksize; readBytes(&chunksize, 4); SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Chunk size: %d\n", chunksize); fseek(_file, chunksize, SEEK_CUR); @@ -107,7 +107,7 @@ void MIDIReader::skipTrack() void MIDIReader::readTrack(Track &tr, bool addbips) { - uint8_t temp[4]; + Uint8 temp[4]; //read the chunk ID fread((void *)(temp), 4, 1, _file); // cerr << temp << endl; @@ -118,7 +118,7 @@ void MIDIReader::readTrack(Track &tr, bool addbips) } //read the chunk size - uint32_t chunksize; + Uint32 chunksize; readBytes(&chunksize, 4); SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Chunk size: %d\n", chunksize); @@ -131,17 +131,17 @@ void MIDIReader::readTrack(Track &tr, bool addbips) // readBytes((char *)(&temp2),4); // printf("TEMP : %0x %0x %0x %0x\n", temp2[0], temp2[1], temp2[2], temp2[3]); bool end = false; - uint8_t oldeventandchannel = 0; - uint32_t ticks = 0; - uint32_t timestamp = 0; - uint32_t currenttempo = 60000000/120; + Uint8 oldeventandchannel = 0; + Uint32 ticks = 0; + Uint32 timestamp = 0; + Uint32 currenttempo = 60000000/120; if (addbips) tr.addBip(0, 0); // Track example; - uint32_t delta = 0; + Uint32 delta = 0; //Read the events while (_position < chunksize) { @@ -153,9 +153,9 @@ void MIDIReader::readTrack(Track &tr, bool addbips) //add bips if (addbips) { - uint32_t lastbiptick = 0; + Uint32 lastbiptick = 0; lastbiptick = tr.getBips()->back().getX(); - uint32_t temptimestamp = timestamp; + Uint32 temptimestamp = timestamp; //manage 1st bip, taking into account the time elapsed since the last event if (lastbiptick > 0 && ticks >= lastbiptick + 480) { @@ -164,16 +164,16 @@ void MIDIReader::readTrack(Track &tr, bool addbips) tr.addBip(lastbiptick, temptimestamp); } //add bips with the current tempo - for (uint32_t i = lastbiptick + 480 ; i < ticks ; i += 480 ) + for (Uint32 i = lastbiptick + 480 ; i < ticks ; i += 480 ) { temptimestamp += currenttempo / 1000; tr.addBip(i, temptimestamp); } } - timestamp += static_cast(delta * (currenttempo / 480000.0)); + timestamp += static_cast(delta * (currenttempo / 480000.0)); - uint8_t eventandchannel, tempevt; + Uint8 eventandchannel, tempevt; // 4 bits for event type, and 4 others for the channel readBytes(&tempevt, 1); fseek(_file, -1, SEEK_CUR); @@ -195,15 +195,15 @@ void MIDIReader::readTrack(Track &tr, bool addbips) { if (end) SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "EXTRA EVT"); - uint8_t type; + Uint8 type; readBytes(&type, 1); - uint32_t length; - /*uint8_t nblus = */readVariableLength(length); + Uint32 length; + /*Uint8 nblus = */readVariableLength(length); - uint8_t *data = new uint8_t[length]; + Uint8 *data = new Uint8[length]; readBytes(data, length); - uint32_t tempo = 0; + Uint32 tempo = 0; switch(type) { @@ -247,18 +247,18 @@ void MIDIReader::readTrack(Track &tr, bool addbips) end = true; break; case 0x51: - tempo = ((uint32_t(data[2] & 0x000000ff) << 16) + (uint32_t(data[1] & 0x000000ff) << 8) + uint32_t(data[0] & 0x000000ff)); + tempo = ((Uint32(data[2] & 0x000000ff) << 16) + (Uint32(data[1] & 0x000000ff) << 8) + Uint32(data[0] & 0x000000ff)); SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Tempo at %d : x = %d = %d bpm\n", ticks, tempo, 60000000 / tempo); currenttempo = tempo; tr.addTempo(ticks, timestamp, tempo); break; case 0x58: SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Time signature at %d : %d|%d %d ticks %d x", - ticks, uint8_t(data[3]), int(pow(float(2), uint8_t(data[2]))), int(data[1]), int(data[0])); - tr.addTimesignature(ticks, timestamp, uint8_t(data[3])); + ticks, Uint8(data[3]), int(pow(float(2), Uint8(data[2]))), int(data[1]), int(data[0])); + tr.addTimesignature(ticks, timestamp, Uint8(data[3])); break; case 0x59: - SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Key signature: %d %d\n", uint8_t(data[1]), uint8_t(data[0])); + SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Key signature: %d %d\n", Uint8(data[1]), Uint8(data[0])); break; case 0x7F: SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Sequencer stuff!\n"); @@ -273,9 +273,9 @@ void MIDIReader::readTrack(Track &tr, bool addbips) else if ((eventandchannel & 0xf0) == 0xf0)// || (eventandchannel & 0xff) == 0xf7) { //May be something else - uint32_t length; + Uint32 length; readVariableLength(length); - uint8_t *data = new uint8_t[length]; + Uint8 *data = new Uint8[length]; readBytes(data, length); SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "System data\n"); delete []data; @@ -284,7 +284,7 @@ void MIDIReader::readTrack(Track &tr, bool addbips) else { // printf("Evt : %x %x %x\n", eventandchannel & 0xf0, eventandchannel & 0x0f, eventandchannel); - uint8_t par1, par2; + Uint8 par1, par2; // position += 2; // char *notenames[] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"}; switch(eventandchannel & 0xf0) @@ -346,19 +346,19 @@ void MIDIReader::readTrack(Track &tr, bool addbips) //these are needed if the notes track is longer than the time events track if (addbips) { - uint32_t lastbiptick = 0; + Uint32 lastbiptick = 0; if (!tr.getBips()->empty()) lastbiptick = tr.getBips()->back().getX(); - uint32_t temptimestamp = timestamp; + Uint32 temptimestamp = timestamp; //manage 1st bip, taking into account the time elapsed since the last event if (lastbiptick > 0) { lastbiptick += 480; - temptimestamp = timestamp + static_cast((lastbiptick - ticks) * (currenttempo / 480000.0)); + temptimestamp = timestamp + static_cast((lastbiptick - ticks) * (currenttempo / 480000.0)); tr.addBip(lastbiptick, temptimestamp); } //add 1000 bips with the current tempo - for (uint32_t i = lastbiptick ; i < lastbiptick + 480000 ; i += 480 ) + for (Uint32 i = lastbiptick ; i < lastbiptick + 480000 ; i += 480 ) { tr.addBip(i, temptimestamp); temptimestamp += currenttempo / 1000; @@ -405,11 +405,11 @@ void MIDIReader::readTracks(Track &t)//, int &nb) SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Total : %d\n"); } -uint8_t MIDIReader::readVariableLength(uint32_t &nb) +Uint8 MIDIReader::readVariableLength(Uint32 &nb) { - uint8_t nblus = 0; + Uint8 nblus = 0; nb = 0; - uint8_t temp; + Uint8 temp; do { fread((void *)(&temp), 1, 1, _file); @@ -421,19 +421,19 @@ uint8_t MIDIReader::readVariableLength(uint32_t &nb) return nblus; } -void MIDIReader::readBytes(void *data, uint32_t nb) +void MIDIReader::readBytes(void *data, Uint32 nb) { - uint8_t *temp = new uint8_t[nb]; + Uint8 *temp = new Uint8[nb]; fread((void *)(temp), nb, 1, _file); - for (uint32_t i=0 ; i -#include - extern struct { int tv_sec, tv_usec; } start; -#else -#include - extern struct timeval start; -#endif +extern Uint32 start; #define BIPLENGTH 10 extern FILE*logfile; -MetronomeAudio::MetronomeAudio(const Track *track, uint32_t nbbeats, uint32_t tempo, bool activated) +MetronomeAudio::MetronomeAudio(const Track *track, Uint32 nbbeats, Uint32 tempo, bool activated) :Metronome(track, nbbeats, tempo, activated), thread(NULL) { Mixer::getInstance()->addSound("bip","bip10.wav"); @@ -39,37 +32,20 @@ int MetronomeAudio::thread_func(void *obj) SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH); - const list > *bips = thismetronome->_track->getBips(); - //const map > *tempo = thismetronome->_track->getTempos(); - const map > *timesignatures = thismetronome->_track->getTimeSignatures(); - static list >::const_iterator cBips = bips->begin(); - //static map >::const_iterator cTempo = tempo->begin(); - static map >::const_iterator cTimesignature = timesignatures->begin(); + const list > *bips = thismetronome->_track->getBips(); + //const map > *tempo = thismetronome->_track->getTempos(); + const map > *timesignatures = thismetronome->_track->getTimeSignatures(); + static list >::const_iterator cBips = bips->begin(); + //static map >::const_iterator cTempo = tempo->begin(); + static map >::const_iterator cTimesignature = timesignatures->begin(); int currentbeat = 0; - -#ifdef WIN32 - struct { int tv_sec, tv_usec; } now;//, start; - DWORD t = timeGetTime (); -/* start.tv_sec = t / 1000; - start.tv_usec = (t % 1000) * 1000;*/ -#else - struct timeval now;/*, start; - gettimeofday(&start, NULL);*/ -#endif - uint32_t currenttime = 0; + Uint32 currenttime = 0; float lag = 0.0; while(thismetronome->_activated) { -#ifdef WIN32 - t = timeGetTime () + BIPLENGTH; - now.tv_sec = t / 1000; - now.tv_usec = (t % 1000) * 1000; -#else - gettimeofday(&now, NULL); -#endif - uint32_t currenttime = (now.tv_sec - start.tv_sec) * 1000 + (now.tv_usec - start.tv_usec) / 1000; + Uint32 currenttime = SDL_GetTicks() - start; while (cBips != bips->end() && currenttime >= BIPTIMESTAMP(*cBips)) { diff --git a/src/MetronomeHaptic.cpp b/src/MetronomeHaptic.cpp index 26f921f..70290ef 100644 --- a/src/MetronomeHaptic.cpp +++ b/src/MetronomeHaptic.cpp @@ -3,21 +3,17 @@ #include "Mixer.hpp" #ifdef WIN32 -#include -#include -#include "SerialWindows.hpp" - extern struct { int tv_sec, tv_usec; } start; + #include "SerialWindows.hpp" #else -#include -#include "SerialLinux.hpp" - extern struct timeval start; + #include "SerialLinux.hpp" #endif +extern Uint32 start; #define BEFOREDELAY 2000 extern FILE *logfile; -MetronomeHaptic::MetronomeHaptic(const Track *track, uint32_t nbbeats, uint32_t tempo, bool activated) +MetronomeHaptic::MetronomeHaptic(const Track *track, Uint32 nbbeats, Uint32 tempo, bool activated) :Metronome(track, nbbeats, tempo, activated), thread(NULL) { try @@ -41,45 +37,20 @@ MetronomeHaptic::MetronomeHaptic(const Track *track, uint32_t nbbeats, uint32_t _comport->WriteData(buffer1, 3); _comport->WriteData(buffer2, 6); -/* char INBUFFER[128]; - memset(INBUFFER, 0, 128); - int nbread = _comport->ReadData(INBUFFER, 128); - stringstream s; - s << nbread << " read:\n" << INBUFFER << endl; - OutputDebugString(s.str().c_str());*/ - //Tacton 2 buffer2[0] = 0x02; //pattern _comport->WriteData(buffer1, 3); _comport->WriteData(buffer2, 6); - -/* memset(INBUFFER, 0, 128); - nbread = _comport->ReadData(INBUFFER, 128); - stringstream s2; - s2 << nbread << " read:\n" << INBUFFER << endl; - OutputDebugString(s2.str().c_str());*/ - + //Tacton 3 buffer2[0] = 0x04; //pattern _comport->WriteData(buffer1, 3); _comport->WriteData(buffer2, 6); - -/* memset(INBUFFER, 0, 128); - nbread = _comport->ReadData(INBUFFER, 128); - stringstream s3; - s3 << nbread << " read:\n" << INBUFFER << endl; - OutputDebugString(s3.str().c_str());*/ - + //Tacton 4 buffer2[0] = 0x08; //pattern _comport->WriteData(buffer1, 3); _comport->WriteData(buffer2, 6); - -/* memset(INBUFFER, 0, 128); - nbread = _comport->ReadData(INBUFFER, 128); - stringstream s4; - s4 << nbread << " read:\n" << INBUFFER << endl; - OutputDebugString(s4.str().c_str());*/ } MetronomeHaptic::~MetronomeHaptic() @@ -90,51 +61,14 @@ MetronomeHaptic::~MetronomeHaptic() SDL_WaitThread(thread, NULL); } -void MetronomeHaptic::setTempo(uint32_t tempo) +void MetronomeHaptic::setTempo(Uint32 tempo) { Metronome::setTempo(tempo); - //send info to Serial Port - //char outBuffer[5]; - /*char outBuffer[5];// = {'T', 'A', 'B', 'C', 'D'}; - memset(outBuffer, 0, 5); - sprintf(OUTBUFFER, "T%3d\n", 60000000/tempo); - outBuffer[0] = 'T'; - outBuffer[1] = (tempo & 0xff000000) >> 24; - outBuffer[2] = (tempo & 0x00ff0000) >> 16; - outBuffer[3] = (tempo & 0x0000ff00) >> 8; - outBuffer[4] = tempo & 0x000000ff; - - bool written = _comport->WriteData(outBuffer, 5); - - char INBUFFER[128]; - memset(INBUFFER, 0, 128); - int nbread = _comport->ReadData(INBUFFER, 128); - stringstream s; - s << nbread << " read:\n" << INBUFFER << endl; - OutputDebugString(s.str().c_str());*/ } -void MetronomeHaptic::setNbBeats(uint32_t nbbeats) +void MetronomeHaptic::setNbBeats(Uint32 nbbeats) { Metronome::setNbBeats(nbbeats); - //send info to Serial Port -/* char outBuffer[5];// = {'B', '5', '6', '7', '8'}; - memset(outBuffer, 0, 5); - sprintf(OUTBUFFER, "B%3d\n", nbbeats); - outBuffer[0] = 'B'; - outBuffer[1] = (nbbeats & 0xff000000) >> 24; - outBuffer[2] = (nbbeats & 0x00ff0000) >> 16; - outBuffer[3] = (nbbeats & 0x0000ff00) >> 8; - outBuffer[4] = nbbeats & 0x000000ff; - - bool written = _comport->WriteData(outBuffer, 5); - - char INBUFFER[128]; - memset(INBUFFER, 0, 128); - int nbread = _comport->ReadData(INBUFFER, 128); - stringstream s; - s << nbread << " read:\n" << INBUFFER << endl; - OutputDebugString(s.str().c_str());*/ } void MetronomeHaptic::run() @@ -148,23 +82,12 @@ int MetronomeHaptic::thread_func(void *obj) SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH); - const list > *bips = thismetronome->_track->getBips(); - //const map > *tempo = thismetronome->_track->getTempos(); - const map > *timesignatures = thismetronome->_track->getTimeSignatures(); - static list >::const_iterator cBips = bips->begin(); - //static map >::const_iterator cTempo = tempo->begin(); - static map >::const_iterator cTimesignature = timesignatures->begin(); - -#ifdef WIN32 - struct { int tv_sec, tv_usec; } now;//, start - DWORD t = timeGetTime () + BEFOREDELAY; -/* start.tv_sec = t / 1000; - start.tv_usec = (t % 1000) * 1000;*/ -#else - struct timeval now;/*, start; - gettimeofday(&start, NULL);*/ -#endif*/ - //float currenttime = 0; + const list > *bips = thismetronome->_track->getBips(); + //const map > *tempo = thismetronome->_track->getTempos(); + const map > *timesignatures = thismetronome->_track->getTimeSignatures(); + static list >::const_iterator cBips = bips->begin(); + //static map >::const_iterator cTempo = tempo->begin(); + static map >::const_iterator cTimesignature = timesignatures->begin(); bool written = thismetronome->_comport->WriteData("S", 1); unsigned char outBuffer[6]; @@ -173,14 +96,7 @@ int MetronomeHaptic::thread_func(void *obj) while(thismetronome->_activated) { -#ifdef WIN32 - t = timeGetTime () + BEFOREDELAY; - now.tv_sec = t / 1000; - now.tv_usec = (t % 1000) * 1000; -#else - gettimeofday(&now, NULL); -#endif - uint32_t currenttime = (now.tv_sec - start.tv_sec) * 1000 + (now.tv_usec - start.tv_usec) / 1000; + Uint32 currenttime = SDL_GetTicks() - start; while (cBips != bips->end() && currenttime >= BIPTIMESTAMP(*cBips)) { @@ -241,10 +157,10 @@ int MetronomeHaptic::thread_func(void *obj) SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH); - const map > *tempo = thismetronome->_track->getTempos(); - const map > *timesignatures = thismetronome->_track->getTimeSignatures(); - static map >::const_iterator cTempo = tempo->begin(); - static map >::const_iterator cTimesignature = timesignatures->begin(); + const map > *tempo = thismetronome->_track->getTempos(); + const map > *timesignatures = thismetronome->_track->getTimeSignatures(); + static map >::const_iterator cTempo = tempo->begin(); + static map >::const_iterator cTimesignature = timesignatures->begin(); #ifdef WIN32 struct { int tv_sec, tv_usec; } now, start; diff --git a/src/PaintGame.cpp b/src/PaintGame.cpp index 40dbbfd..e2b3b27 100644 --- a/src/PaintGame.cpp +++ b/src/PaintGame.cpp @@ -5,22 +5,23 @@ #include "Metronome.hpp" #include "MetronomeAudio.hpp" #include "MetronomeHaptic.hpp" +#include "Tools.hpp" #include #include #include #include -#ifdef WIN32 - struct { int tv_sec, tv_usec; } start; -#else - struct timeval start; -#endif +#define KEY(X) ((keystate[(X)]) != 0) + +extern GameType gametype; + +Uint32 start; #include using namespace std; -int VIEWLENGTH = 250; +GLfloat VIEWLENGTH = 250.f; extern float SECONDSIZE; float posz = 0; Texture *texturebois, *texturefond, *texturesteel, *texturefrett; @@ -211,7 +212,7 @@ void initPaint() void draw(const Track &t, char diff) { -#ifdef WIN32 +/*#ifdef WIN32 struct { int tv_sec, tv_usec; } now; DWORD tim = timeGetTime (); now.tv_sec = tim / 1000; @@ -219,8 +220,9 @@ void draw(const Track &t, char diff) #else struct timeval now; gettimeofday(&now, NULL); -#endif - uint32_t currenttime = (now.tv_sec - start.tv_sec) * 1000 + (now.tv_usec - start.tv_usec) / 1000; +#endif*/ + Uint32 currenttime = SDL_GetTicks() - start; + //(now.tv_sec - start.tv_sec) * 1000 + (now.tv_usec - start.tv_usec) / 1000; posz = -SECONDSIZE * currenttime; @@ -286,14 +288,14 @@ void draw(const Track &t, char diff) glBegin(GL_QUADS); glColor3f(0.2f, 0.2f, 0.2f); glNormal3f(0, 1, 0); - glVertex3f(NOTEDIST*(i-2), 0, 1); - glVertex3f(NOTEDIST*(i-2)+.1f, 0.2f, 1); - glVertex3f(NOTEDIST*(i-2)+.1f, 0.2f,-VIEWLENGTH); - glVertex3f(NOTEDIST*(i-2), 0, -VIEWLENGTH); - glVertex3f(NOTEDIST*(i-2)+.1f, 0.2f, 1); - glVertex3f(NOTEDIST*(i-2)+.2f, 0, 1); - glVertex3f(NOTEDIST*(i-2)+.2f, 0,-VIEWLENGTH); - glVertex3f(NOTEDIST*(i-2)+.1f, 0.2f, -VIEWLENGTH); + glVertex3f(GLfloat(NOTEDIST*(i-2)), 0.f, 1.f); + glVertex3f(GLfloat(NOTEDIST*(i-2))+.1f, 0.2f, 1.f); + glVertex3f(GLfloat(NOTEDIST*(i-2))+.1f, 0.2f,-VIEWLENGTH); + glVertex3f(GLfloat(NOTEDIST*(i-2)), 0, -VIEWLENGTH); + glVertex3f(GLfloat(NOTEDIST*(i-2))+.1f, 0.2f, 1.f); + glVertex3f(GLfloat(NOTEDIST*(i-2))+.2f, 0.f, 1.f); + glVertex3f(GLfloat(NOTEDIST*(i-2))+.2f, 0.f, -VIEWLENGTH); + glVertex3f(GLfloat(NOTEDIST*(i-2))+.1f, 0.2f, -VIEWLENGTH); glEnd(); } //Draw the sides @@ -448,7 +450,7 @@ void drawLong(float pos, float size, float length, float colorx, float colory, f glEnd(); // Done Drawing The Quad } -void handleKeyOn(keys k, uint32_t currenttime) +void handleKeyOn(keys k, Uint32 currenttime) { fromKeyboard.addKey(k); /* switch(k) @@ -471,7 +473,7 @@ void handleKeyOn(keys k, uint32_t currenttime) }*/ } -void handleKeyOff(keys k, uint32_t currenttime) +void handleKeyOff(keys k, Uint32 currenttime) { // fromKeyboard.remKey(k); if (fromKeyboard.getTimestamp() == -1) @@ -484,14 +486,26 @@ void handleKeyOff(keys k, uint32_t currenttime) fromKeyboard.setEndTimestamp(-1); } -void handleKeys(bool a, bool b, bool c, bool d, bool e, uint32_t currenttime) +void handleKeys(bool a, bool b, bool c, bool d, bool e, Uint32 currenttime) { - if (fromKeyboard.isNone()) - fromKeyboard.setTimestamp(-1); - fromKeyboard.setKeys(a, b, c, d, e); + if (gametype == REGULAR) + { + if (fromKeyboard.isNone()) + fromKeyboard.setTimestamp(-1); + fromKeyboard.setKeys(a, b, c, d, e); + } + else if (gametype == SPEEDACCURACY) + { + fromKeyboard.setKeys(a, b, c, d, e); + if (fromKeyboard.getTimestamp() != currenttime) + { + fromKeyboard.setTimestamp(currenttime); + fromKeyboard.log("Play", logfile); + } + } } -void handleStrokeOn(uint32_t currenttime) +void handleStrokeOn(Uint32 currenttime) { if (fromKeyboard.getTimestamp() != -1) { @@ -503,13 +517,13 @@ void handleStrokeOn(uint32_t currenttime) fromKeyboard.setEndTimestamp(-1); } -void handleStrokeOff(uint32_t currenttime) +void handleStrokeOff(Uint32 currenttime) { } bool processEvents() { -#ifdef WIN32 +/*#ifdef WIN32 struct { int tv_sec, tv_usec; } now; DWORD tim = timeGetTime (); now.tv_sec = tim / 1000; @@ -517,8 +531,9 @@ bool processEvents() #else struct timeval now; gettimeofday(&now, NULL); -#endif - uint32_t currenttime = (now.tv_sec - start.tv_sec) * 1000 + (now.tv_usec - start.tv_usec) / 1000; +#endif*/ + Uint32 currenttime = SDL_GetTicks() - start; + //(now.tv_sec - start.tv_sec) * 1000 + (now.tv_usec - start.tv_usec) / 1000; SDL_Event event; // bool quitProgram = false; @@ -535,7 +550,10 @@ bool processEvents() case SDL_KEYDOWN: #if SDL_VERSION_ATLEAST(1,3,0) keystate = SDL_GetKeyboardState(NULL); - handleKeys(keystate[SDL_SCANCODE_F1], keystate[SDL_SCANCODE_F2], keystate[SDL_SCANCODE_F3], keystate[SDL_SCANCODE_F4], keystate[SDL_SCANCODE_F5], currenttime); + if (gametype == REGULAR) + handleKeys(KEY(SDL_SCANCODE_F1), KEY(SDL_SCANCODE_F2),KEY(SDL_SCANCODE_F3), KEY(SDL_SCANCODE_F4), KEY(SDL_SCANCODE_F5), currenttime); + else if (gametype == SPEEDACCURACY) + handleKeys(KEY(SDL_SCANCODE_A), KEY(SDL_SCANCODE_S), false, KEY(SDL_SCANCODE_K), KEY(SDL_SCANCODE_L), currenttime); #else keystate = SDL_GetKeyState(NULL); handleKeys(keystate[SDLK_F1], keystate[SDLK_F2], keystate[SDLK_F3], keystate[SDLK_F4], keystate[SDLK_F5], currenttime); @@ -583,7 +601,7 @@ bool processEvents() handleStrokeOn(currenttime); break; case SDLK_RCTRL: - if (logfile) + if (logfile && gametype == TOMSLAW) fprintf(logfile, "PRESS;%d\n", currenttime); break; default: @@ -617,7 +635,10 @@ bool processEvents() } #if SDL_VERSION_ATLEAST(1,3,0) keystate = SDL_GetKeyboardState(NULL); - handleKeys(keystate[SDL_SCANCODE_F1], keystate[SDL_SCANCODE_F2], keystate[SDL_SCANCODE_F3], keystate[SDL_SCANCODE_F4], keystate[SDL_SCANCODE_F5], currenttime); + if (gametype == REGULAR) + handleKeys(KEY(SDL_SCANCODE_F1), KEY(SDL_SCANCODE_F2),KEY(SDL_SCANCODE_F3), KEY(SDL_SCANCODE_F4), KEY(SDL_SCANCODE_F5), currenttime); + else if (gametype == SPEEDACCURACY) + handleKeys(KEY(SDL_SCANCODE_A), KEY(SDL_SCANCODE_S), false, KEY(SDL_SCANCODE_K), KEY(SDL_SCANCODE_L), currenttime); #else keystate = SDL_GetKeyState(NULL); handleKeys(keystate[SDLK_F1], keystate[SDLK_F2], keystate[SDLK_F3], keystate[SDLK_F4], keystate[SDLK_F5], currenttime); @@ -669,21 +690,24 @@ void loop(const Track &tr, const String &songname) SDL_LogDebug(SDL_LOG_CATEGORY_SYSTEM, "Init paint\n"); initPaint(); - Mixer::getInstance()->loadMusic(songname + "/tout.ogg"); + if (gametype == REGULAR) + Mixer::getInstance()->loadMusic(songname + "/tout.ogg"); //must be done before paint and metronomes -#ifdef WIN32 + start = SDL_GetTicks(); +/*#ifdef WIN32 DWORD t = timeGetTime (); start.tv_sec = t / 1000; start.tv_usec = (t % 1000) * 1000; #else gettimeofday(&start, NULL); -#endif +#endif*/ SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "LET'S ROCK!\n"); //m->setActive(true); - Mixer::getInstance()->playMusic(); + if (gametype == REGULAR) + Mixer::getInstance()->playMusic(); if (m) m->run(); /* Mixer::getInstance()->playSound("guitar"); @@ -711,18 +735,6 @@ void loop(const Track &tr, const String &songname) while(!quitProgram) { -/* //compute current time in the loop -#ifdef WIN32 - struct { int tv_sec, tv_usec; } now; - DWORD tim = timeGetTime (); - now.tv_sec = tim / 1000; - now.tv_usec = (tim % 1000) * 1000; -#else - struct timeval now; - gettimeofday(&now, NULL); -#endif - uint32_t currenttime = (now.tv_sec - start.tv_sec) * 1000 + (now.tv_usec - start.tv_usec) / 1000; - */ // cout << "draw" << endl; draw(tr, NORMAL); // cout << "events" << endl; @@ -732,7 +744,6 @@ void loop(const Track &tr, const String &songname) // cout << "pause" << endl; SDL_Delay(10); // check metronome events -// tr.checkMetronome(currenttime, m); } delete m; diff --git a/src/Track.cpp b/src/Track.cpp index 3c115a9..b5295a0 100644 --- a/src/Track.cpp +++ b/src/Track.cpp @@ -14,25 +14,25 @@ using namespace std; extern Texture* texturesteel, *texturefrett; extern FILE *logfile; extern float SECONDSIZE; -extern int VIEWLENGTH; +extern GLfloat VIEWLENGTH; Track::Track() :/*_currenttempo(120)*,_currentpos(0),*/ _trackSize(0), _active(true) { - for (uint8_t i = 0 ; i < NBDIFFICULTIES ; i++) + for (Uint8 i = 0 ; i < NBDIFFICULTIES ; i++) { - _currentconfig[i] = (uint8_t) 0; + _currentconfig[i] = (Uint8) 0; _nbnotes[i] = 0; _totallength[i] = 0; } - for (uint8_t i = 0 ; i < 128 ; i++) + for (Uint8 i = 0 ; i < 128 ; i++) _totalnotes[i] = 0; } Track::Track(const Track &tr) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "WARNING: COPYING THE TRACK!\n"); - for (uint8_t i = 0 ; i < NBDIFFICULTIES ; i++) + for (Uint8 i = 0 ; i < NBDIFFICULTIES ; i++) { _notes[i] = tr._notes[i]; _currentconfig[i] = tr._currentconfig[i]; @@ -46,14 +46,14 @@ Track::Track(const Track &tr) tempo: beats per minute duration: track length in ms */ -Track::Track(uint32_t tempo, uint32_t duration) +Track::Track(Uint32 tempo, Uint32 duration) { - uint32_t t = 60000000 / tempo; + Uint32 t = 60000000 / tempo; addTempo(0, 0, tempo); addTimesignature(0, 0, 1); - for (uint32_t i = 0 ; i < (duration * 1000) / t ; i++) - _bips.push_back(Pair(i, i * t / 1000 + 2000)); + for (Uint32 i = 0 ; i < (duration * 1000) / t ; i++) + _bips.push_back(Pair(i, i * t / 1000 + 2000)); } /** @@ -63,16 +63,16 @@ Track::Track(uint32_t tempo, uint32_t duration) nbspeeds: number of speeds speeds: */ -Track::Track(uint8_t nbbuttons, uint8_t repetitions, uint8_t nbspeeds, uint32_t *speeds) +Track::Track(Uint8 nbbuttons, Uint8 repetitions, Uint8 nbspeeds, Uint32 *speeds) { - uint32_t tick = 0, timestamp = 2000; + Uint32 tick = 0, timestamp = 2000; addTimesignature(0, 0, 1); for (int n = 0 ; n < nbspeeds ; n++) { - uint32_t tempo = 60000000 / speeds[n]; + Uint32 tempo = 60000000 / speeds[n]; addTempo(tick, timestamp, tempo); - vector configs; + vector configs; //creates a block with repetitions of all the patterns (excluding the empty pattern) for (int i = 1 ; i < (int)pow(2.0, (double)nbbuttons) ; i++) @@ -83,9 +83,9 @@ Track::Track(uint8_t nbbuttons, uint8_t repetitions, uint8_t nbspeeds, uint32_t random_shuffle(configs.begin(), configs.end()); //add the permutation to the note list - for (vector::iterator it = configs.begin() ; it != configs.end() ; it++) + for (vector::iterator it = configs.begin() ; it != configs.end() ; it++) { - uint8_t cfg = ((*it) & 0x03) | (((*it) & 0x0c) << 1); + Uint8 cfg = ((*it) & 0x03) | (((*it) & 0x0c) << 1); for (int d=0 ; d < NBDIFFICULTIES ; d++) _notes[d][tick] = Config(cfg, timestamp, timestamp+100, tick, 1); tick++; @@ -139,13 +139,13 @@ Track::~Track() 108: vocal track (C) */ -void Track::addKey(uint32_t time, uint8_t note) +void Track::addKey(Uint32 time, Uint8 note) { // _totalnotes[note]++; // cout << "addkey begin" << endl; - uint8_t difficulty = note / 12 - 5; - uint8_t key = note % 12; + Uint8 difficulty = note / 12 - 5; + Uint8 key = note % 12; // cout << "+ diff=" << difficulty+0 << " key=" << key+0 << " note=" << note+0 << endl; //could be note 108 for singer if (difficulty >= NBDIFFICULTIES || difficulty < 0) { @@ -199,12 +199,12 @@ void Track::addKey(uint32_t time, uint8_t note) // cout << "addkey end" << endl; } -void Track::remKey(uint32_t time, uint8_t note) +void Track::remKey(Uint32 time, Uint8 note) { _totalnotes[note]++; // cout << "remkey begin" << endl; - uint8_t difficulty = note / 12 - 5; - uint8_t key = note % 12; + Uint8 difficulty = note / 12 - 5; + Uint8 key = note % 12; // cout << "- diff=" << difficulty+0 << " key=" << key+0 << " note=" << note+0 << endl; if (difficulty >= NBDIFFICULTIES || difficulty + 0 < 0) { @@ -221,9 +221,9 @@ void Track::remKey(uint32_t time, uint8_t note) { _currentconfig[difficulty].setTicks(time - _currentconfig[difficulty].getTime()); //compute the note duration and position - uint32_t currenttempo = 0, lasttick = 0; - map >::iterator ti = _tempo.begin(); - uint32_t tickpos = _currentconfig[difficulty].getTime(); + Uint32 currenttempo = 0, lasttick = 0; + map >::iterator ti = _tempo.begin(); + Uint32 tickpos = _currentconfig[difficulty].getTime(); while (ti != _tempo.end() && TICK(*ti) <= tickpos) { // _currentconfig[difficulty].setPosition(_currentconfig[difficulty].getPosition() + (TICK(*ti) - lasttick) * (currenttempo / 480000.0)); @@ -234,7 +234,7 @@ void Track::remKey(uint32_t time, uint8_t note) } if (tickpos > lasttick) { - uint32_t delta = static_cast((tickpos - lasttick) * (currenttempo / 480000.0)); + Uint32 delta = static_cast((tickpos - lasttick) * (currenttempo / 480000.0)); _currentconfig[difficulty].setTimestamp(_currentconfig[difficulty].getTimestamp() + delta); } @@ -243,7 +243,7 @@ void Track::remKey(uint32_t time, uint8_t note) { if (ti != _tempo.end() && TICK(*ti) < time) { - uint32_t delta = static_cast((TICK(*ti) - tickpos) * (currenttempo / 480000.0)); + Uint32 delta = static_cast((TICK(*ti) - tickpos) * (currenttempo / 480000.0)); _currentconfig[difficulty].setEndTimestamp(_currentconfig[difficulty].getTimestamp() + delta); _currentconfig[difficulty].setEndTimestamp(TIMESTAMP(*ti)); tickpos = TICK(*ti); @@ -252,7 +252,7 @@ void Track::remKey(uint32_t time, uint8_t note) } else { - uint32_t delta = static_cast((time - tickpos) * (currenttempo / 480000.0)); + Uint32 delta = static_cast((time - tickpos) * (currenttempo / 480000.0)); _currentconfig[difficulty].setEndTimestamp(_currentconfig[difficulty].getTimestamp() + delta); tickpos = time; } @@ -303,21 +303,21 @@ void Track::remKey(uint32_t time, uint8_t note) // cout << "remkey end" << endl; } -Config Track::getNote(uint32_t pos, uint8_t difficulty) +Config Track::getNote(Uint32 pos, Uint8 difficulty) { if (_notes[difficulty].count(pos) == 0) throw 0; return _notes[difficulty][pos]; } -uint32_t Track::getTempo(uint32_t pos) +Uint32 Track::getTempo(Uint32 pos) { if (_tempo.count(pos) == 0) throw 0; return _tempo[pos].getY(); } -uint32_t Track::getTimeSignature(uint32_t pos) +Uint32 Track::getTimeSignature(Uint32 pos) { if (_timesignatures.count(pos) == 0) throw 0; @@ -328,9 +328,9 @@ uint32_t Track::getTimeSignature(uint32_t pos) void Track::computeBips() { double pos = 0; - uint32_t currenttempo = 120; - map::iterator p = _tempo.begin(); - for (uint32_t i = 0 ; i < getEndOfTrack() ; i += 480) + Uint32 currenttempo = 120; + map::iterator p = _tempo.begin(); + for (Uint32 i = 0 ; i < getEndOfTrack() ; i += 480) { //cout << "Bip @ " << pos << endl; _bips.push_back(pos); @@ -349,10 +349,10 @@ void Track::computeBips() void Track::displayTracks() { cout << "TRACK:" << endl; - for (uint8_t k=0 ; k < NBDIFFICULTIES ; k++) + for (Uint8 k=0 ; k < NBDIFFICULTIES ; k++) { cout << "Difficulty " << (k+0) << ":" << endl; - for(map::iterator i = _notes[k].begin(); i != _notes[k].end(); ++i) + for(map::iterator i = _notes[k].begin(); i != _notes[k].end(); ++i) cout << (*i).first << ": " << (*i).second << endl; } } @@ -360,14 +360,14 @@ void Track::displayTracks() void Track::debugTempo() { cout << "Tempo changes: " << endl; - for( map >::iterator ii=_tempo.begin(); ii!=_tempo.end(); ++ii) + for( map >::iterator ii=_tempo.begin(); ii!=_tempo.end(); ++ii) cout << TICK(*ii) << ": " << TIMESTAMP(*ii) << " (" << VALUE(*ii) << ")" << endl; //ticksToBeats((*ii).second) << ")" << endl; } -void Track::drawFrets(uint32_t postime) const +void Track::drawFrets(Uint32 postime) const { - static list >::const_iterator startingbips = _bips.begin(); + static list >::const_iterator startingbips = _bips.begin(); // on avance tant que les bips sont dépassées while (startingbips != _bips.end() && BIPTIMESTAMP(*startingbips) < postime) @@ -378,7 +378,7 @@ void Track::drawFrets(uint32_t postime) const startingbips++; } - list >::const_iterator b = startingbips; + list >::const_iterator b = startingbips; glMatrixMode(GL_MODELVIEW); //glDisable(GL_DEPTH_TEST); @@ -415,9 +415,9 @@ void Track::drawFrets(uint32_t postime) const } } -void Track::drawNotes(uint32_t postime, uint8_t diff) const +void Track::drawNotes(Uint32 postime, Uint8 diff) const { - static map::const_iterator startingn = _notes[diff].begin(); + static map::const_iterator startingn = _notes[diff].begin(); static double startingpos = 0.0; // cout << "startingpos=" << startingpos << " postime=" << postime << " first note at " << (*startingn).first << ":" << (*startingn).second.getPosition() << endl; @@ -435,7 +435,7 @@ void Track::drawNotes(uint32_t postime, uint8_t diff) const startingn++; } - map::const_iterator n = startingn; + map::const_iterator n = startingn; glMatrixMode(GL_MODELVIEW); //on dessine les notes jusqu'à 10s @@ -451,8 +451,8 @@ void Track::drawNotes(uint32_t postime, uint8_t diff) const /* void Track::checkMetronome(float postime, Metronome *m) const { - static map >::const_iterator cTempo = _tempo.begin(); - static map >::const_iterator cTimesignature = _timesignatures.begin(); + static map >::const_iterator cTempo = _tempo.begin(); + static map >::const_iterator cTimesignature = _timesignatures.begin(); static double startingpos = 0.0; // on avance tant que les tempos sont dépassées diff --git a/src/Wiimote.cpp b/src/Wiimote.cpp index eb500d9..328537b 100644 --- a/src/Wiimote.cpp +++ b/src/Wiimote.cpp @@ -6,11 +6,7 @@ using namespace std; #define MAX(X,Y) (((X)>(Y))?(X):(Y)) #define MIN(X,Y) (((X)<(Y))?(X):(Y)) -#ifdef WIN32 - extern struct { int tv_sec, tv_usec; } start; -#else - extern struct timeval start; -#endif +extern Uint32 start; Wiimote::Wiimote(int nb) :_wiimotes(wiiuse_init(nb)), _nb(nb), _strumstate(false) @@ -44,7 +40,7 @@ Wiimote::Wiimote(int nb) } } -void Wiimote::handleKey(guitar_hero_3_t* gh3, int key, int button, uint32_t currenttime) +void Wiimote::handleKey(guitar_hero_3_t* gh3, int key, int button, Uint32 currenttime) { if (_keystate[key]) { @@ -62,16 +58,7 @@ void Wiimote::handleKey(guitar_hero_3_t* gh3, int key, int button, uint32_t curr void Wiimote::handleEvents() { -#ifdef WIN32 - struct { int tv_sec, tv_usec; } now; - DWORD tim = timeGetTime (); - now.tv_sec = tim / 1000; - now.tv_usec = (tim % 1000) * 1000; -#else - struct timeval now; - gettimeofday(&now, NULL); -#endif - uint32_t currenttime = (now.tv_sec - start.tv_sec) * 1000 + (now.tv_usec - start.tv_usec) / 1000; + Uint32 currenttime = SDL_GetTicks() - start; if (!wiiuse_poll(_wiimotes, _nb)) return; diff --git a/src/main.cpp b/src/main.cpp index 6f6b4b8..44dd25c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,6 +4,7 @@ #include "Track.hpp" #include "Mixer.hpp" #include "PaintGame.h" +#include "Tools.hpp" #ifdef WIN32 #include @@ -15,6 +16,7 @@ #include #include +GameType gametype; #ifdef WIN32 #include @@ -47,7 +49,7 @@ int main(int argc, char *argv[]) time_t tim = time(NULL); struct tm *t = gmtime(&tim); - + SDL_LogSetAllPriority(SDL_LOG_PRIORITY_VERBOSE); SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Loading song\n"); @@ -60,6 +62,7 @@ int main(int argc, char *argv[]) // v5 = distance if (argc >= 6) { + gametype = TOMSLAW; Track tr(atoi(argv[3]), atoi(argv[4])); SECONDSIZE = atof(argv[5]); @@ -79,7 +82,9 @@ int main(int argc, char *argv[]) // v4 = nbrepetitions else if (argc >= 5) { - uint32_t speeds[] = {40, 80, 120, 160, 200}; + gametype = SPEEDACCURACY; + + Uint32 speeds[] = {40, 80, 120, 160, 200}; Track tr(atoi(argv[3]), atoi(argv[4]), 5, speeds); SECONDSIZE = 0.08; @@ -93,6 +98,8 @@ int main(int argc, char *argv[]) } else { + gametype = REGULAR; + if (argc >= 3) { String logfilename = String(argv[1]) + "-" + String(argv[2]) + "-" + String(1900 + t->tm_year) + "-" + String(t->tm_mon) + "-" + String(t->tm_mday) + "-" + String(t->tm_hour) + "-" + String(t->tm_min) + "-" + String(t->tm_sec); -- 2.30.2