Ported Windowing, Input and Texturing systems from SDL to SFML2
Remaining problem: SFML loads textures vertically flipped. Thus, HUD speed display isn't correct yet. git-svn-id: https://svn.code.sf.net/p/extremetuxracer/code/branches/SFML2@467 0420edf4-82e4-42fc-9478-35b55e6d67a3master
parent
c904a766f7
commit
3a0be9d384
|
@ -92,7 +92,7 @@
|
|||
<PrecompiledHeaderFile>bh.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>freetype.lib;sdl.lib;sfml-audio-d.lib;sdl_image.lib;sdlmain.lib;opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>freetype.lib;sfml-system-d.lib;sfml-window-d.lib;sfml-graphics-d.lib;sfml-audio-d.lib;opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<IgnoreSpecificDefaultLibraries>libcmtd.lib;libcmt.lib;msvcrt.lib</IgnoreSpecificDefaultLibraries>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
|
@ -109,7 +109,7 @@
|
|||
<PrecompiledHeaderFile>bh.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>freetype.lib;sdl.lib;sfml-audio-d-64.lib;sdl_image.lib;sdlmain.lib;opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>freetype.lib;sfml-main-d-64.lib;sfml-system-d-64.lib;sfml-window-d-64.lib;sfml-graphics-d-64.lib;sfml-audio-d-64.lib;opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<IgnoreSpecificDefaultLibraries>libcmtd.lib;libcmt.lib;msvcrt.lib</IgnoreSpecificDefaultLibraries>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
|
@ -132,7 +132,7 @@
|
|||
<PrecompiledHeaderFile>bh.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>freetype.lib;sdl.lib;sfml-audio.lib;sdl_image.lib;sdlmain.lib;opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>freetype.lib;sfml-system.lib;sfml-window.lib;sfml-graphics.lib;sfml-audio.lib;opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<IgnoreSpecificDefaultLibraries>libcmt.lib</IgnoreSpecificDefaultLibraries>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
|
@ -157,7 +157,7 @@
|
|||
<PrecompiledHeaderFile>bh.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>freetype.lib;sdl.lib;sfml-audio-64.lib;sdl_image.lib;sdlmain.lib;opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>freetype.lib;sfml-system-64.lib;sfml-window-64.lib;sfml-graphics-64.lib;sfml-audio-64.lib;opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<IgnoreSpecificDefaultLibraries>libcmt.lib</IgnoreSpecificDefaultLibraries>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
|
|
|
@ -30,8 +30,7 @@ CMusic Music;
|
|||
struct TSound {
|
||||
sf::SoundBuffer data;
|
||||
sf::Sound player;
|
||||
TSound(int volume)
|
||||
{
|
||||
TSound(int volume) {
|
||||
setVolume(volume);
|
||||
}
|
||||
void setVolume(int volume) {
|
||||
|
@ -49,8 +48,7 @@ struct TSound {
|
|||
// class CSound
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
CSound::~CSound()
|
||||
{
|
||||
CSound::~CSound() {
|
||||
FreeSounds();
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ enum ESituation {
|
|||
};
|
||||
|
||||
namespace sf {
|
||||
class Music;
|
||||
class Music;
|
||||
};
|
||||
|
||||
class CMusic {
|
||||
|
|
3
src/bh.h
3
src/bh.h
|
@ -27,6 +27,9 @@ GNU General Public License for more details.
|
|||
#include <string>
|
||||
|
||||
#include <GL/gl.h>
|
||||
#include <SFML/System.hpp>
|
||||
#include <SFML/Window.hpp>
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
#ifndef HAVE_CONFIG_H
|
||||
# ifdef _WIN32 // Windows platform
|
||||
|
|
|
@ -103,28 +103,28 @@ void SetConfig () {
|
|||
State::manager.RequestEnterState(*State::manager.PreviousState());
|
||||
}
|
||||
|
||||
void CGameConfig::Keyb (unsigned int key, bool special, bool release, int x, int y) {
|
||||
void CGameConfig::Keyb (sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
if (release) return;
|
||||
|
||||
if (key != SDLK_UP && key != SDLK_DOWN)
|
||||
if (key != sf::Keyboard::Up && key != sf::Keyboard::Down)
|
||||
KeyGUI(key, 0, release);
|
||||
switch (key) {
|
||||
case SDLK_q:
|
||||
case sf::Keyboard::Q:
|
||||
State::manager.RequestQuit();
|
||||
break;
|
||||
case SDLK_ESCAPE:
|
||||
case sf::Keyboard::Escape:
|
||||
State::manager.RequestEnterState (*State::manager.PreviousState());
|
||||
break;
|
||||
case SDLK_RETURN:
|
||||
case sf::Keyboard::Return:
|
||||
if (textbuttons[0]->focussed())
|
||||
State::manager.RequestEnterState (*State::manager.PreviousState());
|
||||
else if (textbuttons[1]->focussed())
|
||||
SetConfig ();
|
||||
break;
|
||||
case SDLK_UP:
|
||||
case sf::Keyboard::Up:
|
||||
DecreaseFocus();
|
||||
break;
|
||||
case SDLK_DOWN:
|
||||
case sf::Keyboard::Down:
|
||||
IncreaseFocus();
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ GNU General Public License for more details.
|
|||
class CGameConfig : public State {
|
||||
void Enter();
|
||||
void Loop(double time_step);
|
||||
void Keyb(unsigned int key, bool special, bool release, int x, int y);
|
||||
void Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y);
|
||||
void Mouse(int button, int state, int x, int y);
|
||||
void Motion(int x, int y);
|
||||
void Exit();
|
||||
|
|
|
@ -337,15 +337,16 @@ void CCourse::FreeObjectTextures () {
|
|||
// --------------------------------------------------------------------
|
||||
|
||||
bool CCourse::LoadElevMap () {
|
||||
CImage img;
|
||||
sf::Image img;
|
||||
|
||||
if (!img.LoadPng (CourseDir.c_str(), "elev.png", true)) {
|
||||
if (!img.loadFromFile(CourseDir + SEP + "elev.png")) {
|
||||
Message ("unable to open elev.png");
|
||||
return false;
|
||||
}
|
||||
img.flipVertically();
|
||||
|
||||
nx = img.nx;
|
||||
ny = img.ny;
|
||||
nx = img.getSize().x;
|
||||
ny = img.getSize().y;
|
||||
try {
|
||||
elevation = new double[nx * ny];
|
||||
} catch (...) {
|
||||
|
@ -355,14 +356,16 @@ bool CCourse::LoadElevMap () {
|
|||
|
||||
double slope = tan (ANGLES_TO_RADIANS (curr_course->angle));
|
||||
int pad = 0;
|
||||
int depth = 4;
|
||||
const uint8_t* data = img.getPixelsPtr();
|
||||
for (int y=0; y<ny; y++) {
|
||||
for (int x=0; x<nx; x++) {
|
||||
elevation [(nx-1-x) + nx * (ny-1-y)] =
|
||||
((img.data [(x+nx*y) * img.depth + pad]
|
||||
((data[(x + nx*y) * depth + pad]
|
||||
- base_height_value) / 255.0) * curr_course->scale
|
||||
- (double)(ny-1-y) / ny * curr_course->size.y * slope;
|
||||
}
|
||||
pad += (nx * img.depth) % 4;
|
||||
pad += (nx * depth) % 4;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -424,7 +427,7 @@ void CCourse::LoadItemList () {
|
|||
// -------------------- LoadObjectMap ---------------------------------
|
||||
|
||||
|
||||
static int GetObject (unsigned char pixel[]) {
|
||||
static int GetObject (const unsigned char* pixel) {
|
||||
int r = pixel[0];
|
||||
int g = pixel[1];
|
||||
int b = pixel[2];
|
||||
|
@ -460,15 +463,18 @@ static void CalcRandomTrees (double baseheight, double basediam, double &height,
|
|||
}
|
||||
|
||||
bool CCourse::LoadAndConvertObjectMap () {
|
||||
CImage treeImg;
|
||||
sf::Image treeImg;
|
||||
|
||||
if (!treeImg.LoadPng (CourseDir.c_str(), "trees.png", true)) {
|
||||
if (!treeImg.loadFromFile (CourseDir + SEP + "trees.png")) {
|
||||
Message ("unable to open trees.png");
|
||||
return false;
|
||||
}
|
||||
treeImg.flipVertically();
|
||||
|
||||
int pad = 0;
|
||||
int cnt = 0;
|
||||
int depth = 4;
|
||||
const unsigned char* data = (unsigned char*)treeImg.getPixelsPtr();
|
||||
double height, diam;
|
||||
CSPList savelist (10000);
|
||||
|
||||
|
@ -476,8 +482,8 @@ bool CCourse::LoadAndConvertObjectMap () {
|
|||
NocollArr.clear();
|
||||
for (int y=0; y<ny; y++) {
|
||||
for (int x=0; x<nx; x++) {
|
||||
int imgidx = (x + nx * y) * treeImg.depth + pad;
|
||||
int type = GetObject (&treeImg.data[imgidx]);
|
||||
int imgidx = (x + nx * y) * depth + pad;
|
||||
int type = GetObject (&data[imgidx]);
|
||||
if (type >= 0) {
|
||||
cnt++;
|
||||
double xx = (nx - x) / (double)(nx - 1.0) * curr_course->size.x;
|
||||
|
@ -543,7 +549,7 @@ bool CCourse::LoadAndConvertObjectMap () {
|
|||
savelist.Add (line);
|
||||
}
|
||||
}
|
||||
pad += (nx * treeImg.depth) % 4;
|
||||
pad += (nx * depth) % 4;
|
||||
}
|
||||
string itemfile = CourseDir + SEP + "items.lst";
|
||||
savelist.Save (itemfile); // Convert trees.png to items.lst
|
||||
|
@ -597,7 +603,7 @@ bool CCourse::LoadObjectTypes () {
|
|||
// Terrain
|
||||
// ====================================================================
|
||||
|
||||
int CCourse::GetTerrain (unsigned char pixel[]) const {
|
||||
int CCourse::GetTerrain (const unsigned char* pixel) const {
|
||||
for (size_t i=0; i<TerrList.size(); i++) {
|
||||
if (abs(pixel[0]-(int)(TerrList[i].col.r)) < 30
|
||||
&& abs(pixel[1]-(int)(TerrList[i].col.g)) < 30
|
||||
|
@ -645,13 +651,14 @@ bool CCourse::LoadTerrainTypes () {
|
|||
// --------------------------------------------------------------------
|
||||
|
||||
bool CCourse::LoadTerrainMap () {
|
||||
CImage terrImage;
|
||||
sf::Image terrImage;
|
||||
|
||||
if (!terrImage.LoadPng (CourseDir.c_str(), "terrain.png", true)) {
|
||||
if (!terrImage.loadFromFile (CourseDir + SEP + "terrain.png")) {
|
||||
Message ("unable to open terrain.png");
|
||||
return false;
|
||||
}
|
||||
if (nx != terrImage.nx || ny != terrImage.ny) {
|
||||
terrImage.flipVertically();
|
||||
if (nx != terrImage.getSize().x || ny != terrImage.getSize().y) {
|
||||
Message ("wrong terrain size");
|
||||
}
|
||||
|
||||
|
@ -660,19 +667,21 @@ bool CCourse::LoadTerrainMap () {
|
|||
} catch (...) {
|
||||
Message ("Allocation failed in LoadTerrainMap");
|
||||
}
|
||||
int depth = 4;
|
||||
const unsigned char* data = (const unsigned char*) terrImage.getPixelsPtr();
|
||||
int pad = 0;
|
||||
for (int y=0; y<ny; y++) {
|
||||
for (int x=0; x<nx; x++) {
|
||||
int imgidx = (x+nx*y) * terrImage.depth + pad;
|
||||
int imgidx = (x+nx*y) * depth + pad;
|
||||
int arridx = (nx-1-x) + nx * (ny-1-y);
|
||||
int terr = GetTerrain (&terrImage.data[imgidx]);
|
||||
int terr = GetTerrain (&data[imgidx]);
|
||||
terrain[arridx] = terr;
|
||||
if (TerrList[terr].texture == NULL) {
|
||||
TerrList[terr].texture = new TTexture();
|
||||
TerrList[terr].texture->LoadMipmap(param.terr_dir, TerrList[terr].textureFile, true);
|
||||
}
|
||||
}
|
||||
pad += (nx * terrImage.depth) % 4;
|
||||
pad += (nx * depth) % 4;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ private:
|
|||
void LoadItemList ();
|
||||
bool LoadAndConvertObjectMap ();
|
||||
bool LoadTerrainMap ();
|
||||
int GetTerrain (unsigned char pixel[]) const;
|
||||
int GetTerrain (const unsigned char* pixel) const;
|
||||
|
||||
void MirrorCourseData ();
|
||||
public:
|
||||
|
|
|
@ -93,14 +93,14 @@ void DrawTrees() {
|
|||
glNormal3i(0, 0, 1);
|
||||
|
||||
static const GLshort tex[] = {
|
||||
0, 0,
|
||||
1, 0,
|
||||
1, 1,
|
||||
0, 1,
|
||||
0, 0,
|
||||
1, 0,
|
||||
1, 1,
|
||||
0, 1
|
||||
1, 0,
|
||||
0, 0,
|
||||
0, 1,
|
||||
1, 1,
|
||||
1, 0,
|
||||
0, 0
|
||||
};
|
||||
|
||||
const GLfloat vtx[] = {
|
||||
|
@ -160,10 +160,10 @@ void DrawTrees() {
|
|||
normal.Norm();
|
||||
|
||||
static const GLshort tex[] = {
|
||||
0, 0,
|
||||
1, 0,
|
||||
0, 1,
|
||||
1, 1,
|
||||
0, 1
|
||||
1, 0,
|
||||
0, 0
|
||||
};
|
||||
|
||||
const GLfloat vtx[] = {
|
||||
|
|
|
@ -110,13 +110,13 @@ void CCredits::DrawCreditsText (double time_step) {
|
|||
if (offs < TOP_Y) y_offset = 0;
|
||||
}
|
||||
|
||||
void CCredits::Keyb (unsigned int key, bool special, bool release, int x, int y) {
|
||||
void CCredits::Keyb (sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
if (release) return;
|
||||
switch (key) {
|
||||
case SDLK_m:
|
||||
case sf::Keyboard::M:
|
||||
moving = !moving;
|
||||
break;
|
||||
case SDLK_u:
|
||||
case sf::Keyboard::U:
|
||||
param.ui_snow = !param.ui_snow;
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -37,7 +37,7 @@ class CCredits : public State {
|
|||
void DrawCreditsText(double time_step);
|
||||
void Enter();
|
||||
void Loop(double time_step);
|
||||
void Keyb(unsigned int key, bool special, bool release, int x, int y);
|
||||
void Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y);
|
||||
void Mouse(int button, int state, int x, int y);
|
||||
void Motion(int x, int y);
|
||||
public:
|
||||
|
|
13
src/env.cpp
13
src/env.cpp
|
@ -209,11 +209,12 @@ void CEnvironment::DrawSkybox (const TVector3d& pos) {
|
|||
glTranslate(pos);
|
||||
|
||||
static const GLfloat tex[] = {
|
||||
aa, aa,
|
||||
bb, aa,
|
||||
aa, bb,
|
||||
bb, bb,
|
||||
aa, bb
|
||||
bb, aa,
|
||||
aa, aa
|
||||
};
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, tex);
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
@ -227,7 +228,6 @@ void CEnvironment::DrawSkybox (const TVector3d& pos) {
|
|||
|
||||
Skybox[0].Bind();
|
||||
glVertexPointer(3, GL_SHORT, 0, front);
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, tex);
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
|
||||
// left
|
||||
|
@ -239,7 +239,6 @@ void CEnvironment::DrawSkybox (const TVector3d& pos) {
|
|||
};
|
||||
Skybox[1].Bind();
|
||||
glVertexPointer(3, GL_SHORT, 0, left);
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, tex);
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
|
||||
// right
|
||||
|
@ -251,7 +250,6 @@ void CEnvironment::DrawSkybox (const TVector3d& pos) {
|
|||
};
|
||||
Skybox[2].Bind();
|
||||
glVertexPointer(3, GL_SHORT, 0, right);
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, tex);
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
|
||||
// normally, the following textures are unvisible
|
||||
|
@ -266,7 +264,6 @@ void CEnvironment::DrawSkybox (const TVector3d& pos) {
|
|||
};
|
||||
Skybox[3].Bind();
|
||||
glVertexPointer(3, GL_SHORT, 0, top);
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, tex);
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
|
||||
// bottom
|
||||
|
@ -278,7 +275,6 @@ void CEnvironment::DrawSkybox (const TVector3d& pos) {
|
|||
};
|
||||
Skybox[4].Bind();
|
||||
glVertexPointer(3, GL_SHORT, 0, bottom);
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, tex);
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
|
||||
// back
|
||||
|
@ -290,7 +286,6 @@ void CEnvironment::DrawSkybox (const TVector3d& pos) {
|
|||
};
|
||||
Skybox[5].Bind();
|
||||
glVertexPointer(3, GL_SHORT, 0, back);
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, tex);
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
}
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
|
|
@ -63,17 +63,17 @@ void StartRace () {
|
|||
State::manager.RequestEnterState (Loading);
|
||||
}
|
||||
|
||||
void CEvent::Keyb (unsigned int key, bool special, bool release, int x, int y) {
|
||||
void CEvent::Keyb (sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
if (release) return;
|
||||
switch (key) {
|
||||
case SDLK_RETURN:
|
||||
case sf::Keyboard::Return:
|
||||
if (curr_focus == textbuttons[0] && ready < 1) StartRace ();
|
||||
else State::manager.RequestEnterState (EventSelect);
|
||||
break;
|
||||
case SDLK_ESCAPE:
|
||||
case sf::Keyboard::Escape:
|
||||
State::manager.RequestEnterState (EventSelect);
|
||||
break;
|
||||
case SDLK_TAB:
|
||||
case sf::Keyboard::Tab:
|
||||
if (ready > 0) {
|
||||
curr_focus = textbuttons[2];
|
||||
} else {
|
||||
|
@ -81,13 +81,13 @@ void CEvent::Keyb (unsigned int key, bool special, bool release, int x, int y) {
|
|||
else curr_focus = textbuttons[0];
|
||||
}
|
||||
break;
|
||||
case SDLK_LEFT:
|
||||
case sf::Keyboard::Left:
|
||||
if (curr_focus == textbuttons[0]) curr_focus = textbuttons[1];
|
||||
break;
|
||||
case SDLK_RIGHT:
|
||||
case sf::Keyboard::Right:
|
||||
if (curr_focus == textbuttons[1]) curr_focus = textbuttons[0];
|
||||
break;
|
||||
case SDLK_u:
|
||||
case sf::Keyboard::U:
|
||||
param.ui_snow = !param.ui_snow;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ GNU General Public License for more details.
|
|||
class CEvent : public State {
|
||||
void Enter();
|
||||
void Loop(double time_step);
|
||||
void Keyb(unsigned int key, bool special, bool release, int x, int y);
|
||||
void Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y);
|
||||
void Mouse(int button, int state, int x, int y);
|
||||
void Motion(int x, int y);
|
||||
public:
|
||||
|
|
|
@ -47,20 +47,20 @@ void EnterEvent () {
|
|||
State::manager.RequestEnterState(Event);
|
||||
}
|
||||
|
||||
void CEventSelect::Keyb (unsigned int key, bool special, bool release, int x, int y) {
|
||||
void CEventSelect::Keyb (sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
if (release) return;
|
||||
switch (key) {
|
||||
case SDLK_ESCAPE:
|
||||
case sf::Keyboard::Escape:
|
||||
State::manager.RequestEnterState (GameTypeSelect);
|
||||
break;
|
||||
case SDLK_q:
|
||||
case sf::Keyboard::Q:
|
||||
State::manager.RequestQuit();
|
||||
break;
|
||||
case SDLK_RETURN:
|
||||
case sf::Keyboard::Return:
|
||||
if (textbuttons[1]->focussed()) State::manager.RequestEnterState (GameTypeSelect);
|
||||
else if (Events.IsUnlocked (event->GetValue(), cup->GetValue())) EnterEvent();
|
||||
break;
|
||||
case SDLK_u:
|
||||
case sf::Keyboard::U:
|
||||
param.ui_snow = !param.ui_snow;
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -24,7 +24,7 @@ GNU General Public License for more details.
|
|||
class CEventSelect : public State {
|
||||
void Enter();
|
||||
void Loop(double time_step);
|
||||
void Keyb(unsigned int key, bool special, bool release, int x, int y);
|
||||
void Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y);
|
||||
void Mouse(int button, int state, int x, int y);
|
||||
void Motion(int x, int y);
|
||||
public:
|
||||
|
|
|
@ -52,9 +52,9 @@ void QuitGameOver () {
|
|||
}
|
||||
}
|
||||
|
||||
void CGameOver::Keyb (unsigned int key, bool special, bool release, int x, int y) {
|
||||
void CGameOver::Keyb (sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
if (release) return;
|
||||
if (key == 13 || key == SDLK_ESCAPE) QuitGameOver ();
|
||||
if (key == 13 || key == sf::Keyboard::Escape) QuitGameOver ();
|
||||
}
|
||||
|
||||
void CGameOver::Mouse (int button, int state, int x, int y) {
|
||||
|
|
|
@ -24,7 +24,7 @@ GNU General Public License for more details.
|
|||
class CGameOver : public State {
|
||||
void Enter();
|
||||
void Loop(double time_step);
|
||||
void Keyb(unsigned int key, bool special, bool release, int x, int y);
|
||||
void Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y);
|
||||
void Mouse(int button, int state, int x, int y);
|
||||
public:
|
||||
};
|
||||
|
|
|
@ -68,27 +68,27 @@ void CGameTypeSelect::Mouse (int button, int state, int x, int y) {
|
|||
}
|
||||
}
|
||||
|
||||
void CGameTypeSelect::Keyb (unsigned int key, bool special, bool release, int x, int y) {
|
||||
void CGameTypeSelect::Keyb (sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
if (release) return;
|
||||
|
||||
KeyGUI(key, 0, release);
|
||||
switch (key) {
|
||||
case SDLK_u:
|
||||
case sf::Keyboard::U:
|
||||
param.ui_snow = !param.ui_snow;
|
||||
break;
|
||||
case SDLK_ESCAPE:
|
||||
case sf::Keyboard::Escape:
|
||||
State::manager.RequestQuit();
|
||||
break;
|
||||
case SDLK_DOWN:
|
||||
case sf::Keyboard::Down:
|
||||
IncreaseFocus();
|
||||
break;
|
||||
case SDLK_UP:
|
||||
case sf::Keyboard::Up:
|
||||
DecreaseFocus();
|
||||
break;
|
||||
case SDLK_RETURN:
|
||||
case sf::Keyboard::Return:
|
||||
QuitGameType();
|
||||
break;
|
||||
case SDLK_w:
|
||||
case sf::Keyboard::W:
|
||||
Music.FreeMusics();
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ GNU General Public License for more details.
|
|||
class CGameTypeSelect : public State {
|
||||
void Enter();
|
||||
void Loop(double time_step);
|
||||
void Keyb(unsigned int key, bool special, bool release, int x, int y);
|
||||
void Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y);
|
||||
void Mouse(int button, int state, int x, int y);
|
||||
void Motion(int x, int y);
|
||||
public:
|
||||
|
|
121
src/gui.cpp
121
src/gui.cpp
|
@ -136,43 +136,31 @@ void TTextField::Draw() const {
|
|||
}
|
||||
}
|
||||
|
||||
void TTextField::Key(unsigned int key, unsigned int mod, bool released) {
|
||||
if (islower (key)) {
|
||||
if (text.size() < maxLng) {
|
||||
if (mod & KMOD_SHIFT) text.insert(cursorPos, 1, toupper(key));
|
||||
else text.insert(cursorPos, 1, key);
|
||||
cursorPos++;
|
||||
}
|
||||
} else if (isdigit (key)) {
|
||||
if (text.size() < maxLng) {
|
||||
text.insert(cursorPos, 1, key);
|
||||
cursorPos++;
|
||||
}
|
||||
} else {
|
||||
switch (key) {
|
||||
case SDLK_DELETE:
|
||||
if (cursorPos < text.size()) text.erase (cursorPos, 1);
|
||||
break;
|
||||
case SDLK_BACKSPACE:
|
||||
if (cursorPos > 0) { text.erase (cursorPos-1, 1); cursorPos--; }
|
||||
break;
|
||||
case SDLK_RIGHT:
|
||||
if (cursorPos < text.size()) cursorPos++;
|
||||
break;
|
||||
case SDLK_LEFT:
|
||||
if (cursorPos > 0) cursorPos--;
|
||||
break;
|
||||
case SDLK_HOME:
|
||||
cursorPos = 0;
|
||||
break;
|
||||
case SDLK_END:
|
||||
cursorPos = text.size();
|
||||
break;
|
||||
case SDLK_SPACE:
|
||||
text.insert(cursorPos, 1, 21);
|
||||
cursorPos++;
|
||||
break;
|
||||
}
|
||||
void TTextField::TextEnter(char key) {
|
||||
text.insert(cursorPos, 1, key);
|
||||
cursorPos++;
|
||||
}
|
||||
|
||||
void TTextField::Key(sf::Keyboard::Key key, unsigned int mod, bool released) {
|
||||
switch (key) {
|
||||
case sf::Keyboard::Delete:
|
||||
if (cursorPos < text.size()) text.erase (cursorPos, 1);
|
||||
break;
|
||||
case sf::Keyboard::BackSpace:
|
||||
if (cursorPos > 0) { text.erase (cursorPos-1, 1); cursorPos--; }
|
||||
break;
|
||||
case sf::Keyboard::Right:
|
||||
if (cursorPos < text.size()) cursorPos++;
|
||||
break;
|
||||
case sf::Keyboard::Left:
|
||||
if (cursorPos > 0) cursorPos--;
|
||||
break;
|
||||
case sf::Keyboard::Home:
|
||||
cursorPos = 0;
|
||||
break;
|
||||
case sf::Keyboard::End:
|
||||
cursorPos = text.size();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -208,10 +196,10 @@ bool TCheckbox::Click(int x, int y) {
|
|||
return false;
|
||||
}
|
||||
|
||||
void TCheckbox::Key(unsigned int key, unsigned int mod, bool released) {
|
||||
void TCheckbox::Key(sf::Keyboard::Key key, unsigned int mod, bool released) {
|
||||
if (released) return;
|
||||
|
||||
if (key == SDLK_SPACE || key == SDLK_RIGHT || key == SDLK_LEFT) {
|
||||
if (key == sf::Keyboard::Space || key == sf::Keyboard::Right || key == sf::Keyboard::Left) {
|
||||
checked = !checked;
|
||||
}
|
||||
}
|
||||
|
@ -256,21 +244,21 @@ void TIconButton::Draw () const {
|
|||
{
|
||||
0, 0.5,
|
||||
0.5, 0.5,
|
||||
0.5, 1,
|
||||
0, 1
|
||||
0.5, 0,
|
||||
0, 0
|
||||
}, {
|
||||
0.5, 0.5,
|
||||
1, 0.5,
|
||||
1, 1,
|
||||
0.5, 1
|
||||
1, 0,
|
||||
0.5, 0
|
||||
}, {
|
||||
0, 0,
|
||||
0.5, 0,
|
||||
0, 1,
|
||||
0.5, 1,
|
||||
0.5, 0.5,
|
||||
0, 0.5
|
||||
}, {
|
||||
0.5, 0,
|
||||
1, 0,
|
||||
0.5, 1,
|
||||
1, 1,
|
||||
1, 0.5,
|
||||
0.5, 0.5
|
||||
}
|
||||
|
@ -296,14 +284,14 @@ bool TIconButton::Click(int x, int y) {
|
|||
return false;
|
||||
}
|
||||
|
||||
void TIconButton::Key(unsigned int key, unsigned int mod, bool released) {
|
||||
void TIconButton::Key(sf::Keyboard::Key key, unsigned int mod, bool released) {
|
||||
if (released) return;
|
||||
|
||||
if (key == SDLK_DOWN || key == SDLK_LEFT) { // Arrow down/left
|
||||
if (key == sf::Keyboard::Down || key == sf::Keyboard::Left) { // Arrow down/left
|
||||
value--;
|
||||
if (value < 0)
|
||||
value = maximum;
|
||||
} else if (key == SDLK_UP || key == SDLK_RIGHT) { // Arrow up/right
|
||||
} else if (key == sf::Keyboard::Up || key == sf::Keyboard::Right) { // Arrow up/right
|
||||
value++;
|
||||
if (value > maximum)
|
||||
value = 0;
|
||||
|
@ -318,8 +306,8 @@ TIconButton* AddIconButton(int x, int y, TTexture* texture, double size, int max
|
|||
void TArrow::Draw() const {
|
||||
static const float textl[6] = { 0.5, 0.0, 0.5, 0.5, 0.0, 0.5 };
|
||||
static const float textr[6] = { 1.0, 0.5, 1.0, 1.0, 0.5, 1.0 };
|
||||
static const float texbl[6] = { 0.25, 0.25, 0.75, 0.00, 0.00, 0.50 };
|
||||
static const float texbr[6] = {0.50, 0.50, 1.00, 0.25, 0.25, 0.75};
|
||||
static const float texbl[6] = { 0.75, 0.75, 0.25, 1.00, 1.00, 0.50 };
|
||||
static const float texbr[6] = {0.50, 0.50, 0.00, 0.75, 0.75, 0.25};
|
||||
|
||||
int type = 0;
|
||||
if (active)
|
||||
|
@ -397,17 +385,17 @@ bool TUpDown::Click(int x, int y) {
|
|||
return false;
|
||||
}
|
||||
|
||||
void TUpDown::Key(unsigned int key, unsigned int mod, bool released) {
|
||||
void TUpDown::Key(sf::Keyboard::Key key, unsigned int mod, bool released) {
|
||||
if (released) return;
|
||||
|
||||
if (key == SDLK_UP || key == SDLK_RIGHT) { // Arrow down/left
|
||||
if (key == sf::Keyboard::Up || key == sf::Keyboard::Right) { // Arrow down/left
|
||||
if (value > minimum) {
|
||||
value--;
|
||||
up.SetActive(true);
|
||||
if (value == minimum)
|
||||
down.SetActive(false);
|
||||
}
|
||||
} else if (key == SDLK_DOWN || key == SDLK_LEFT) { // Arrow up/right
|
||||
} else if (key == sf::Keyboard::Down || key == sf::Keyboard::Left) { // Arrow up/right
|
||||
if (value < maximum) {
|
||||
value++;
|
||||
down.SetActive(true);
|
||||
|
@ -494,10 +482,10 @@ void DrawLevel (int x, int y, int level, double fact) {
|
|||
glColor4f (1.0, 1.0, 1.0, 1.0);
|
||||
|
||||
const GLfloat tex[] = {
|
||||
0, bott,
|
||||
0.75, bott,
|
||||
0, top,
|
||||
0.75, top,
|
||||
0, top
|
||||
0.75, bott,
|
||||
0, bott
|
||||
};
|
||||
const GLshort vtx[] = {
|
||||
x, Winsys.resolution.height - y - 32,
|
||||
|
@ -566,10 +554,10 @@ void DrawBonusExt (int y, size_t numraces, size_t num) {
|
|||
float top = 1.0;
|
||||
|
||||
const GLfloat tex[] = {
|
||||
0, bott,
|
||||
1, bott,
|
||||
0, top,
|
||||
1, top,
|
||||
0, top
|
||||
1, bott,
|
||||
0, bott
|
||||
};
|
||||
const GLshort vtx[] = {
|
||||
bl.x, bl.y,
|
||||
|
@ -626,10 +614,10 @@ TWidget* MouseMoveGUI(int x, int y) {
|
|||
return Widgets[focussed];
|
||||
}
|
||||
|
||||
TWidget* KeyGUI(unsigned int key, unsigned int mod, bool released) {
|
||||
TWidget* KeyGUI(sf::Keyboard::Key key, unsigned int mod, bool released) {
|
||||
if (!released) {
|
||||
switch (key) {
|
||||
case SDLK_TAB:
|
||||
case sf::Keyboard::Tab:
|
||||
IncreaseFocus();
|
||||
break;
|
||||
default:
|
||||
|
@ -642,6 +630,13 @@ TWidget* KeyGUI(unsigned int key, unsigned int mod, bool released) {
|
|||
return Widgets[focussed];
|
||||
}
|
||||
|
||||
TWidget* TextEnterGUI(char text) {
|
||||
if (focussed == -1)
|
||||
return 0;
|
||||
Widgets[focussed]->TextEnter(text);
|
||||
return Widgets[focussed];
|
||||
}
|
||||
|
||||
void SetFocus(TWidget* widget) {
|
||||
if (!widget)
|
||||
focussed = -1;
|
||||
|
|
15
src/gui.h
15
src/gui.h
|
@ -54,7 +54,8 @@ public:
|
|||
TWidget(int x, int y, int width, int height);
|
||||
virtual void Draw() const = 0;
|
||||
virtual bool Click(int x, int y);
|
||||
virtual void Key(unsigned int key, unsigned int mod, bool released) {}
|
||||
virtual void TextEnter(char text) {}
|
||||
virtual void Key(sf::Keyboard::Key key, unsigned int mod, bool released) {}
|
||||
virtual void MouseMove(int x, int y);
|
||||
bool focussed() const { return focus; }
|
||||
void SetActive(bool a) { active = a; if (!a) focus = false; }
|
||||
|
@ -82,7 +83,8 @@ class TTextField : public TWidget {
|
|||
public:
|
||||
TTextField(int x, int y, int width, int height, const string& text_);
|
||||
void Draw() const;
|
||||
void Key(unsigned int key, unsigned int mod, bool released);
|
||||
void TextEnter(char text);
|
||||
void Key(sf::Keyboard::Key key, unsigned int mod, bool released);
|
||||
void UpdateCursor(double timestep);
|
||||
const string& Text() const { return text; }
|
||||
};
|
||||
|
@ -103,7 +105,7 @@ public:
|
|||
}
|
||||
void Draw() const;
|
||||
bool Click(int x, int y);
|
||||
void Key(unsigned int key, unsigned int mod, bool released);
|
||||
void Key(sf::Keyboard::Key key, unsigned int mod, bool released);
|
||||
};
|
||||
TCheckbox* AddCheckbox (int x, int y, int width, const string& tag);
|
||||
|
||||
|
@ -124,7 +126,7 @@ public:
|
|||
void SetValue(int _value);
|
||||
void Draw() const;
|
||||
bool Click(int x, int y);
|
||||
void Key(unsigned int key, unsigned int mod, bool released);
|
||||
void Key(sf::Keyboard::Key key, unsigned int mod, bool released);
|
||||
};
|
||||
TIconButton* AddIconButton (int x, int y, TTexture* texture, double size, int maximum, int value);
|
||||
|
||||
|
@ -153,7 +155,7 @@ public:
|
|||
void SetMaximum(int max_);
|
||||
void Draw() const;
|
||||
bool Click(int x, int y);
|
||||
void Key(unsigned int key, unsigned int mod, bool released);
|
||||
void Key(sf::Keyboard::Key key, unsigned int mod, bool released);
|
||||
void MouseMove(int x, int y);
|
||||
};
|
||||
TUpDown* AddUpDown(int x, int y, int minimum, int maximum, int value, int distance = 2);
|
||||
|
@ -163,7 +165,8 @@ TUpDown* AddUpDown(int x, int y, int minimum, int maximum, int value, int distan
|
|||
void DrawGUI();
|
||||
TWidget* ClickGUI(int x, int y);
|
||||
TWidget* MouseMoveGUI(int x, int y);
|
||||
TWidget* KeyGUI(unsigned int key, unsigned int mod, bool released);
|
||||
TWidget* KeyGUI(sf::Keyboard::Key key, unsigned int mod, bool released);
|
||||
TWidget* TextEnterGUI(char text);
|
||||
void SetFocus(TWidget* widget);
|
||||
void IncreaseFocus();
|
||||
void DecreaseFocus();
|
||||
|
|
|
@ -33,7 +33,7 @@ CHelp Help;
|
|||
|
||||
static int ytop;
|
||||
|
||||
void CHelp::Keyb(unsigned int key, bool special, bool release, int x, int y) {
|
||||
void CHelp::Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
State::manager.RequestEnterState (GameTypeSelect);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ GNU General Public License for more details.
|
|||
class CHelp : public State {
|
||||
void Enter();
|
||||
void Loop(double time_step);
|
||||
void Keyb(unsigned int key, bool special, bool release, int x, int y);
|
||||
void Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y);
|
||||
void Mouse(int button, int state, int x, int y);
|
||||
void Motion(int x, int y);
|
||||
void Exit();
|
||||
|
|
|
@ -366,10 +366,10 @@ void DrawPercentBar (float fact, float x, float y) {
|
|||
glColor4f (1.0, 1.0, 1.0, 1.0);
|
||||
|
||||
const GLfloat tex[] = {
|
||||
0, 0,
|
||||
1, 0,
|
||||
1, fact,
|
||||
0, fact
|
||||
0, 1,
|
||||
1, 1,
|
||||
1, 1 - fact,
|
||||
0, 1 - fact
|
||||
};
|
||||
const GLfloat vtx[] = {
|
||||
x, y,
|
||||
|
|
|
@ -129,7 +129,7 @@ void CIntro::Loop (double time_step) {
|
|||
}
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
void CIntro::Keyb (unsigned int key, bool special, bool release, int x, int y) {
|
||||
void CIntro::Keyb (sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
CControl *ctrl = Players.GetCtrl (g_game.player_id);
|
||||
if (release) return;
|
||||
abort_intro (ctrl);
|
||||
|
|
|
@ -24,7 +24,7 @@ GNU General Public License for more details.
|
|||
class CIntro : public State {
|
||||
void Enter();
|
||||
void Loop(double time_step);
|
||||
void Keyb(unsigned int key, bool special, bool release, int x, int y);
|
||||
void Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y);
|
||||
public:
|
||||
};
|
||||
|
||||
|
|
|
@ -65,18 +65,15 @@ void InitGame (int argc, char **argv) {
|
|||
// main
|
||||
// ====================================================================
|
||||
|
||||
#if defined ( OS_WIN32_MINGW )
|
||||
#undef main
|
||||
#endif
|
||||
|
||||
int main( int argc, char **argv ) {
|
||||
int main(/* int argc, char **argv*/) {
|
||||
// ****************************************************************
|
||||
cout << "\n----------- Extreme Tux Racer " ETR_VERSION_STRING " ----------------";
|
||||
cout << "\n----------- (C) 2010-2013 Extreme Tuxracer Team --------\n\n";
|
||||
|
||||
srand (time (NULL));
|
||||
InitConfig (argv[0]);
|
||||
InitGame (argc, argv);
|
||||
InitConfig(0);// argv[0]);
|
||||
InitGame(0, 0);// argc, argv);
|
||||
Winsys.Init ();
|
||||
InitOpenglExtensions ();
|
||||
// for checking the joystick and the OpgenGL version (the info is
|
||||
|
|
|
@ -45,23 +45,27 @@ void QuitAndAddPlayer () {
|
|||
State::manager.RequestEnterState (Regist);
|
||||
}
|
||||
|
||||
void CNewPlayer::Keyb_spec (SDL_keysym sym, bool release) {
|
||||
void CNewPlayer::Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
if (release) return;
|
||||
|
||||
KeyGUI(sym.sym, sym.mod, release);
|
||||
switch (sym.sym) {
|
||||
case SDLK_ESCAPE:
|
||||
State::manager.RequestEnterState (Regist);
|
||||
KeyGUI(key, 0, release);
|
||||
switch (key) {
|
||||
case sf::Keyboard::Escape:
|
||||
State::manager.RequestEnterState(Regist);
|
||||
break;
|
||||
case SDLK_RETURN:
|
||||
if (textbuttons[0]->focussed()) State::manager.RequestEnterState (Regist);
|
||||
else QuitAndAddPlayer ();
|
||||
case sf::Keyboard::Return:
|
||||
if (textbuttons[0]->focussed()) State::manager.RequestEnterState(Regist);
|
||||
else QuitAndAddPlayer();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void CNewPlayer::TextEntered(char text) {
|
||||
TextEnterGUI(text);
|
||||
}
|
||||
|
||||
void CNewPlayer::Mouse (int button, int state, int x, int y) {
|
||||
if (state == 1) {
|
||||
TWidget* clicked = ClickGUI(x, y);
|
||||
|
|
|
@ -24,7 +24,8 @@ GNU General Public License for more details.
|
|||
class CNewPlayer : public State {
|
||||
void Enter();
|
||||
void Loop(double time_step);
|
||||
void Keyb_spec(SDL_keysym sym, bool release);
|
||||
void Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y);
|
||||
void TextEntered(char text);
|
||||
void Mouse(int button, int state, int x, int y);
|
||||
void Motion(int x, int y);
|
||||
public:
|
||||
|
|
|
@ -54,11 +54,15 @@ void check_gl_error() {
|
|||
PFNGLLOCKARRAYSEXTPROC glLockArraysEXT_p = NULL;
|
||||
PFNGLUNLOCKARRAYSEXTPROC glUnlockArraysEXT_p = NULL;
|
||||
|
||||
|
||||
typedef void (*(*get_gl_proc_fptr_t)(const GLubyte *))();
|
||||
void InitOpenglExtensions () {
|
||||
get_gl_proc_fptr_t get_gl_proc;
|
||||
|
||||
get_gl_proc = (get_gl_proc_fptr_t) SDL_GL_GetProcAddress;
|
||||
#ifdef OS_WIN32_MSC
|
||||
get_gl_proc = (get_gl_proc_fptr_t) wglGetProcAddress;//(get_gl_proc_fptr_t) SDL_GL_GetProcAddress;
|
||||
#else
|
||||
get_gl_proc = 0;
|
||||
#endif
|
||||
|
||||
if (get_gl_proc) {
|
||||
glLockArraysEXT_p = (PFNGLLOCKARRAYSEXTPROC)
|
||||
|
|
|
@ -43,10 +43,10 @@ void SetTestLight () {
|
|||
}
|
||||
|
||||
|
||||
void COglTest::Keyb(unsigned int key, bool special, bool release, int x, int y) {
|
||||
void COglTest::Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
if (release) return;
|
||||
switch (key) {
|
||||
case SDLK_ESCAPE:
|
||||
case sf::Keyboard::Escape:
|
||||
State::manager.RequestQuit();
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ GNU General Public License for more details.
|
|||
class COglTest : public State {
|
||||
void Enter();
|
||||
void Loop(double time_step);
|
||||
void Keyb(unsigned int key, bool special, bool release, int x, int y);
|
||||
void Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y);
|
||||
public:
|
||||
};
|
||||
|
||||
|
|
|
@ -65,7 +65,6 @@ struct TGuiParticle {
|
|||
static list<TGuiParticle> particles_2d;
|
||||
static TVector2d push_position(0, 0);
|
||||
static TVector2d last_push_position;
|
||||
static double last_update_time = -1;
|
||||
static bool push_position_initialized = false;
|
||||
|
||||
TGuiParticle::TGuiParticle(double x, double y) {
|
||||
|
@ -79,25 +78,25 @@ TGuiParticle::TGuiParticle(double x, double y) {
|
|||
|
||||
static const GLfloat tex_coords[4][8] = {
|
||||
{
|
||||
0.0, 0.0,
|
||||
0.0, 0.5,
|
||||
0.5, 0.5,
|
||||
0.5, 0.0,
|
||||
0.0, 0.0
|
||||
}, {
|
||||
0.5, 0.5,
|
||||
1.0, 0.5,
|
||||
1.0, 0.0,
|
||||
0.5, 0.0
|
||||
}, {
|
||||
0.0, 1.0,
|
||||
0.5, 1.0,
|
||||
0.5, 0.5,
|
||||
0.0, 0.5
|
||||
}, {
|
||||
0.5, 0.0,
|
||||
1.0, 0.0,
|
||||
0.5, 1.0,
|
||||
1.0, 1.0,
|
||||
1.0, 0.5,
|
||||
0.5, 0.5
|
||||
}, {
|
||||
0.0, 0.5,
|
||||
0.5, 0.5,
|
||||
0.5, 1.0,
|
||||
0.0, 1.0
|
||||
}, {
|
||||
0.5, 0.5,
|
||||
1.0, 0.5,
|
||||
1.0, 1.0,
|
||||
0.5, 1.0
|
||||
}
|
||||
};
|
||||
int type = rand() % 4;
|
||||
|
@ -152,18 +151,19 @@ void init_ui_snow () {
|
|||
}
|
||||
|
||||
void update_ui_snow(double time_step) {
|
||||
double time = Winsys.ClockTime ();
|
||||
static sf::Clock timer;
|
||||
float time = timer.getElapsedTime().asSeconds();
|
||||
timer.restart();
|
||||
|
||||
TVector2d push_vector;
|
||||
double push_timestep = 0;
|
||||
float push_timestep = 0;
|
||||
|
||||
if (push_position_initialized) {
|
||||
push_vector.x = push_position.x - last_push_position.x;
|
||||
push_vector.y = push_position.y - last_push_position.y;
|
||||
push_timestep = time - last_update_time;
|
||||
push_timestep = time;
|
||||
}
|
||||
last_push_position = push_position;
|
||||
last_update_time = time;
|
||||
|
||||
for (list<TGuiParticle>::iterator p = particles_2d.begin(); p != particles_2d.end(); ++p) {
|
||||
p->Update(time_step, push_timestep, push_vector);
|
||||
|
@ -266,25 +266,25 @@ static list<Particle> particles;
|
|||
void Particle::Draw(const CControl* ctrl) const {
|
||||
static const GLfloat tex_coords[4][8] = {
|
||||
{
|
||||
0.0, 0.0,
|
||||
0.0, 0.5,
|
||||
0.5, 0.5,
|
||||
0.5, 0.0,
|
||||
0.0, 0.0
|
||||
}, {
|
||||
0.5, 0.5,
|
||||
1.0, 0.5,
|
||||
1.0, 0.0,
|
||||
0.5, 0.0
|
||||
}, {
|
||||
0.0, 1.0,
|
||||
0.5, 1.0,
|
||||
0.5, 0.5,
|
||||
0.0, 0.5
|
||||
}, {
|
||||
0.5, 0.0,
|
||||
1.0, 0.0,
|
||||
0.5, 1.0,
|
||||
1.0, 1.0,
|
||||
1.0, 0.5,
|
||||
0.5, 0.5
|
||||
}, {
|
||||
0.0, 0.5,
|
||||
0.5, 0.5,
|
||||
0.5, 1.0,
|
||||
0.0, 1.0
|
||||
}, {
|
||||
0.5, 0.5,
|
||||
1.0, 0.5,
|
||||
1.0, 1.0,
|
||||
0.5, 1.0
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -581,25 +581,25 @@ void CFlakes::MakeSnowFlake (size_t ar, size_t i) {
|
|||
|
||||
static const GLfloat tex_coords[4][8] = {
|
||||
{
|
||||
0.0, 0.875,
|
||||
0.125, 0.875,
|
||||
0.125, 1.0,
|
||||
0.0, 1.0
|
||||
0.0, 0.125,
|
||||
0.125, 0.125,
|
||||
0.125, 0.0,
|
||||
0.0, 0.0
|
||||
}, {
|
||||
0.125, 0.875,
|
||||
0.25, 0.875,
|
||||
0.25, 1.0,
|
||||
0.125, 1.0
|
||||
0.125, 0.125,
|
||||
0.25, 0.125,
|
||||
0.25, 0.0,
|
||||
0.125, 0.0
|
||||
}, {
|
||||
0.0, 0.75,
|
||||
0.125, 0.75,
|
||||
0.125, 0.875,
|
||||
0.0, 0.875
|
||||
0.0, 0.25,
|
||||
0.125, 0.25,
|
||||
0.125, 0.125,
|
||||
0.0, 0.125
|
||||
}, {
|
||||
0.125, 0.75,
|
||||
0.25, 0.75,
|
||||
0.25, 0.875,
|
||||
0.125, 0.875
|
||||
0.125, 0.25,
|
||||
0.25, 0.25,
|
||||
0.25, 0.125,
|
||||
0.125, 0.125
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -799,10 +799,10 @@ void TCurtain::Draw() const {
|
|||
glRotatef (-curtains[co][row].angle, 0, 1, 0);
|
||||
|
||||
static const GLshort tex[] = {
|
||||
0, 0,
|
||||
1, 0,
|
||||
0, 1,
|
||||
1, 1,
|
||||
0, 1
|
||||
1, 0,
|
||||
0, 0
|
||||
};
|
||||
const GLfloat vtx[] = {
|
||||
-halfsize, -halfsize, 0,
|
||||
|
|
|
@ -41,22 +41,22 @@ static bool fog = true;
|
|||
static bool terr = true;
|
||||
static bool trees = true;
|
||||
|
||||
void CPaused::Keyb (unsigned int key, bool special, bool release, int x, int y) {
|
||||
void CPaused::Keyb (sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
if (release) return;
|
||||
switch (key) {
|
||||
case SDLK_s:
|
||||
case sf::Keyboard::S:
|
||||
ScreenshotN ();
|
||||
break;
|
||||
case SDLK_F5:
|
||||
case sf::Keyboard::F5:
|
||||
sky = !sky;
|
||||
break;
|
||||
case SDLK_F6:
|
||||
case sf::Keyboard::F6:
|
||||
fog = !fog;
|
||||
break;
|
||||
case SDLK_F7:
|
||||
case sf::Keyboard::F7:
|
||||
terr = !terr;
|
||||
break;
|
||||
case SDLK_F8:
|
||||
case sf::Keyboard::F8:
|
||||
trees = !trees;
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -23,7 +23,7 @@ GNU General Public License for more details.
|
|||
|
||||
class CPaused : public State {
|
||||
void Loop(double time_step);
|
||||
void Keyb(unsigned int key, bool special, bool release, int x, int y);
|
||||
void Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y);
|
||||
void Mouse(int button, int state, int x, int y);
|
||||
public:
|
||||
};
|
||||
|
|
|
@ -102,28 +102,28 @@ void CRaceSelect::Mouse (int button, int state, int x, int y) {
|
|||
}
|
||||
}
|
||||
|
||||
void CRaceSelect::Keyb(unsigned int key, bool special, bool release, int x, int y) {
|
||||
void CRaceSelect::Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
if (release) return;
|
||||
KeyGUI(key, 0, release);
|
||||
switch (key) {
|
||||
case SDLK_ESCAPE:
|
||||
case sf::Keyboard::Escape:
|
||||
State::manager.RequestEnterState (GameTypeSelect);
|
||||
break;
|
||||
case SDLK_u:
|
||||
case sf::Keyboard::U:
|
||||
param.ui_snow = !param.ui_snow;
|
||||
break;
|
||||
case SDLK_t:
|
||||
case sf::Keyboard::T:
|
||||
g_game.force_treemap = !g_game.force_treemap;
|
||||
break;
|
||||
case SDLK_c:
|
||||
case sf::Keyboard::C:
|
||||
g_game.treesize++;
|
||||
if (g_game.treesize > 5) g_game.treesize = 1;
|
||||
break;
|
||||
case SDLK_v:
|
||||
case sf::Keyboard::V:
|
||||
g_game.treevar++;
|
||||
if (g_game.treevar > 5) g_game.treevar = 1;
|
||||
break;
|
||||
case SDLK_RETURN:
|
||||
case sf::Keyboard::Return:
|
||||
if (textbuttons[1]->focussed())
|
||||
State::manager.RequestEnterState (GameTypeSelect);
|
||||
else
|
||||
|
|
|
@ -24,7 +24,7 @@ GNU General Public License for more details.
|
|||
class CRaceSelect : public State {
|
||||
void Enter();
|
||||
void Loop(double time_step);
|
||||
void Keyb(unsigned int key, bool special, bool release, int x, int y);
|
||||
void Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y);
|
||||
void Mouse(int button, int state, int x, int y);
|
||||
void Motion(int x, int y);
|
||||
public:
|
||||
|
|
|
@ -65,59 +65,59 @@ static bool trees = true;
|
|||
static int newsound = -1;
|
||||
static int lastsound = -1;
|
||||
|
||||
void CRacing::Keyb (unsigned int key, bool special, bool release, int x, int y) {
|
||||
void CRacing::Keyb (sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
switch (key) {
|
||||
// steering flipflops
|
||||
case SDLK_UP:
|
||||
case sf::Keyboard::Up:
|
||||
key_paddling = !release;
|
||||
break;
|
||||
case SDLK_DOWN:
|
||||
case sf::Keyboard::Down:
|
||||
key_braking = !release;
|
||||
break;
|
||||
case SDLK_LEFT:
|
||||
case sf::Keyboard::Left:
|
||||
left_turn = !release;
|
||||
break;
|
||||
case SDLK_RIGHT:
|
||||
case sf::Keyboard::Right:
|
||||
right_turn = !release;
|
||||
break;
|
||||
case SDLK_SPACE:
|
||||
case sf::Keyboard::Space:
|
||||
key_charging = !release;
|
||||
break;
|
||||
case SDLK_t:
|
||||
case sf::Keyboard::T:
|
||||
trick_modifier = !release;
|
||||
break;
|
||||
// mode changing and other actions
|
||||
case SDLK_ESCAPE:
|
||||
case sf::Keyboard::Escape:
|
||||
if (!release) {
|
||||
g_game.raceaborted = true;
|
||||
g_game.race_result = -1;
|
||||
State::manager.RequestEnterState (GameOver);
|
||||
}
|
||||
break;
|
||||
case SDLK_p:
|
||||
case sf::Keyboard::P:
|
||||
if (!release) State::manager.RequestEnterState (Paused);
|
||||
break;
|
||||
case SDLK_r:
|
||||
case sf::Keyboard::R:
|
||||
if (!release) State::manager.RequestEnterState (Reset);
|
||||
break;
|
||||
case SDLK_s:
|
||||
case sf::Keyboard::S:
|
||||
if (!release) ScreenshotN ();
|
||||
break;
|
||||
|
||||
// view changing
|
||||
case SDLK_1:
|
||||
case sf::Keyboard::Num1:
|
||||
if (!release) {
|
||||
set_view_mode (Players.GetCtrl (g_game.player_id), ABOVE);
|
||||
param.view_mode = ABOVE;
|
||||
}
|
||||
break;
|
||||
case SDLK_2:
|
||||
case sf::Keyboard::Num2:
|
||||
if (!release) {
|
||||
set_view_mode (Players.GetCtrl (g_game.player_id), FOLLOW);
|
||||
param.view_mode = FOLLOW;
|
||||
}
|
||||
break;
|
||||
case SDLK_3:
|
||||
case sf::Keyboard::Num3:
|
||||
if (!release) {
|
||||
set_view_mode (Players.GetCtrl (g_game.player_id), BEHIND);
|
||||
param.view_mode = BEHIND;
|
||||
|
@ -125,22 +125,22 @@ void CRacing::Keyb (unsigned int key, bool special, bool release, int x, int y)
|
|||
break;
|
||||
|
||||
// toggle
|
||||
case SDLK_h:
|
||||
case sf::Keyboard::H:
|
||||
if (!release) param.show_hud = !param.show_hud;
|
||||
break;
|
||||
case SDLK_f:
|
||||
case sf::Keyboard::F:
|
||||
if (!release) param.display_fps = !param.display_fps;
|
||||
break;
|
||||
case SDLK_F5:
|
||||
case sf::Keyboard::F5:
|
||||
if (!release) sky = !sky;
|
||||
break;
|
||||
case SDLK_F6:
|
||||
case sf::Keyboard::F6:
|
||||
if (!release) fog = !fog;
|
||||
break;
|
||||
case SDLK_F7:
|
||||
case sf::Keyboard::F7:
|
||||
if (!release) terr = !terr;
|
||||
break;
|
||||
case SDLK_F8:
|
||||
case sf::Keyboard::F8:
|
||||
if (!release) trees = !trees;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ GNU General Public License for more details.
|
|||
class CRacing : public State {
|
||||
void Enter();
|
||||
void Loop(double time_step);
|
||||
void Keyb(unsigned int key, bool special, bool release, int x, int y);
|
||||
void Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y);
|
||||
void Jaxis(int axis, float value);
|
||||
void Jbutt(int button, int state);
|
||||
void Exit();
|
||||
|
|
|
@ -47,14 +47,14 @@ void QuitRegistration () {
|
|||
State::manager.RequestEnterState (GameTypeSelect);
|
||||
}
|
||||
|
||||
void CRegist::Keyb (unsigned int key, bool special, bool release, int x, int y) {
|
||||
void CRegist::Keyb (sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
TWidget* focussed = KeyGUI(key, 0, release);
|
||||
if (release) return;
|
||||
switch (key) {
|
||||
case SDLK_ESCAPE:
|
||||
case sf::Keyboard::Escape:
|
||||
State::manager.RequestQuit();
|
||||
break;
|
||||
case SDLK_RETURN:
|
||||
case sf::Keyboard::Return:
|
||||
if (focussed == textbuttons[1]) {
|
||||
g_game.player_id = player->GetValue();
|
||||
State::manager.RequestEnterState (NewPlayer);
|
||||
|
|
|
@ -24,7 +24,7 @@ GNU General Public License for more details.
|
|||
class CRegist : public State {
|
||||
void Enter();
|
||||
void Loop(double time_step);
|
||||
void Keyb(unsigned int key, bool special, bool release, int x, int y);
|
||||
void Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y);
|
||||
void Mouse(int button, int state, int x, int y);
|
||||
void Motion(int x, int y);
|
||||
public:
|
||||
|
|
|
@ -38,19 +38,19 @@ GNU General Public License for more details.
|
|||
|
||||
CReset Reset;
|
||||
|
||||
static double reset_start_time;
|
||||
static sf::Clock reset_timer;
|
||||
static bool position_reset;
|
||||
|
||||
|
||||
//=====================================================================
|
||||
void CReset::Enter() {
|
||||
reset_start_time = Winsys.ClockTime ();
|
||||
reset_timer.restart();
|
||||
position_reset = false;
|
||||
}
|
||||
|
||||
void CReset::Loop(double time_step) {
|
||||
CControl *ctrl = Players.GetCtrl (g_game.player_id);
|
||||
double elapsed_time = Winsys.ClockTime () - reset_start_time;
|
||||
float elapsed_time = reset_timer.getElapsedTime().asSeconds();
|
||||
static bool tux_visible = true;
|
||||
static int tux_visible_count = 0;
|
||||
|
||||
|
|
|
@ -171,23 +171,23 @@ static TCourse *CourseList;
|
|||
static TUpDown* course;
|
||||
static TWidget* textbutton;
|
||||
|
||||
void CScore::Keyb (unsigned int key, bool special, bool release, int x, int y) {
|
||||
void CScore::Keyb (sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
KeyGUI(key, 0, release);
|
||||
if (release) return;
|
||||
switch (key) {
|
||||
case SDLK_ESCAPE:
|
||||
case sf::Keyboard::Escape:
|
||||
State::manager.RequestEnterState (GameTypeSelect);
|
||||
break;
|
||||
case SDLK_q:
|
||||
case sf::Keyboard::Q:
|
||||
State::manager.RequestQuit();
|
||||
break;
|
||||
case SDLK_s:
|
||||
case sf::Keyboard::S:
|
||||
Score.SaveHighScore ();
|
||||
break;
|
||||
case SDLK_l:
|
||||
case sf::Keyboard::L:
|
||||
Score.LoadHighScore ();
|
||||
break;
|
||||
case SDLK_RETURN:
|
||||
case sf::Keyboard::Return:
|
||||
State::manager.RequestEnterState (GameTypeSelect);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ private:
|
|||
|
||||
void Enter();
|
||||
void Loop(double time_step);
|
||||
void Keyb(unsigned int key, bool special, bool release, int x, int y);
|
||||
void Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y);
|
||||
void Mouse(int button, int state, int x, int y);
|
||||
void Motion(int x, int y);
|
||||
public:
|
||||
|
|
|
@ -38,13 +38,13 @@ GNU General Public License for more details.
|
|||
|
||||
CSplashScreen SplashScreen;
|
||||
|
||||
void CSplashScreen::Keyb(unsigned int key, bool special, bool release, int x, int y) {
|
||||
void CSplashScreen::Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
if (release) return;
|
||||
switch (key) {
|
||||
case SDLK_ESCAPE:
|
||||
case sf::Keyboard::Escape:
|
||||
State::manager.RequestQuit();
|
||||
break;
|
||||
case SDLK_RETURN:
|
||||
case sf::Keyboard::Return:
|
||||
State::manager.RequestEnterState (Regist);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ GNU General Public License for more details.
|
|||
class CSplashScreen : public State {
|
||||
void Enter();
|
||||
void Loop(double time_step);
|
||||
void Keyb(unsigned int key, bool special, bool release, int x, int y);
|
||||
void Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y);
|
||||
public:
|
||||
};
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ GNU General Public License for more details.
|
|||
#include "states.h"
|
||||
#include "ogl.h"
|
||||
#include "winsys.h"
|
||||
#include <ctime>
|
||||
#include <SFML/Window.hpp>
|
||||
|
||||
State::Manager State::manager(Winsys);
|
||||
|
||||
|
@ -34,19 +34,11 @@ State::Manager::~Manager() {
|
|||
void State::Manager::Run(State& entranceState) {
|
||||
current = &entranceState;
|
||||
current->Enter();
|
||||
clock_t ticks = clock();
|
||||
while (!quit) {
|
||||
PollEvent();
|
||||
if (next)
|
||||
EnterNextState();
|
||||
CallLoopFunction();
|
||||
if (param.framerate != 0) {
|
||||
clock_t nticks = clock();
|
||||
int32_t sleeptime = CLOCKS_PER_SEC/param.framerate - (nticks-ticks);
|
||||
if (sleeptime > 0)
|
||||
SDL_Delay(sleeptime);
|
||||
ticks = nticks;
|
||||
}
|
||||
}
|
||||
current->Exit();
|
||||
previous = current;
|
||||
|
@ -62,66 +54,62 @@ void State::Manager::EnterNextState() {
|
|||
}
|
||||
|
||||
void State::Manager::PollEvent() {
|
||||
SDL_Event event;
|
||||
unsigned int key;
|
||||
int x, y;
|
||||
sf::Event event;
|
||||
sf::Keyboard::Key key;
|
||||
|
||||
while (SDL_PollEvent (&event)) {
|
||||
while (Winsys.PollEvent(event)) {
|
||||
if (!next) {
|
||||
switch (event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
SDL_GetMouseState(&x, &y);
|
||||
key = event.key.keysym.sym;
|
||||
current->Keyb(key, key >= 256, false, x, y);
|
||||
current->Keyb_spec(event.key.keysym, false);
|
||||
case sf::Event::KeyPressed:
|
||||
key = event.key.code;
|
||||
current->Keyb(key, key >= 256, false, sf::Mouse::getPosition().x, sf::Mouse::getPosition().y);
|
||||
break;
|
||||
|
||||
case SDL_KEYUP:
|
||||
SDL_GetMouseState(&x, &y);
|
||||
key = event.key.keysym.sym;
|
||||
current->Keyb(key, key >= 256, true, x, y);
|
||||
current->Keyb_spec(event.key.keysym, true);
|
||||
case sf::Event::KeyReleased:
|
||||
key = event.key.code;
|
||||
current->Keyb(key, key >= 256, true, sf::Mouse::getPosition().x, sf::Mouse::getPosition().y);
|
||||
break;
|
||||
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
current->Mouse(event.button.button, event.button.state, event.button.x, event.button.y);
|
||||
case sf::Event::TextEntered:
|
||||
current->TextEntered(static_cast<char>(event.text.unicode));
|
||||
break;
|
||||
|
||||
case SDL_MOUSEMOTION: {
|
||||
case sf::Event::MouseButtonPressed:
|
||||
case sf::Event::MouseButtonReleased:
|
||||
current->Mouse(event.mouseButton.button, event.type == sf::Event::MouseButtonPressed, event.mouseButton.x, event.mouseButton.y);
|
||||
break;
|
||||
|
||||
case sf::Event::MouseMoved: {
|
||||
TVector2i old = cursor_pos;
|
||||
cursor_pos.x = event.motion.x;
|
||||
cursor_pos.y = event.motion.y;
|
||||
current->Motion(event.motion.x-old.x, event.motion.y-old.y);
|
||||
cursor_pos.x = event.mouseMove.x;
|
||||
cursor_pos.y = event.mouseMove.y;
|
||||
current->Motion(event.mouseMove.x - old.x, event.mouseMove.y - old.y);
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_JOYAXISMOTION:
|
||||
case sf::Event::JoystickMoved:
|
||||
if (Winsys.joystick_isActive()) {
|
||||
unsigned int axis = event.jaxis.axis;
|
||||
if (axis < 2) {
|
||||
float val = (float)event.jaxis.value / 32768.f;
|
||||
current->Jaxis(axis, val);
|
||||
}
|
||||
float val = event.joystickMove.position / 32768.f;
|
||||
current->Jaxis(event.joystickMove.axis == sf::Joystick::X ? 0 : 1, val);
|
||||
}
|
||||
break;
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
case SDL_JOYBUTTONUP:
|
||||
case sf::Event::JoystickButtonPressed:
|
||||
case sf::Event::JoystickButtonReleased:
|
||||
if (Winsys.joystick_isActive()) {
|
||||
current->Jbutt(event.jbutton.button, event.jbutton.state);
|
||||
current->Jbutt(event.joystickButton.button, event.type == sf::Event::JoystickButtonPressed);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_VIDEORESIZE:
|
||||
if (Winsys.resolution.width != event.resize.w || Winsys.resolution.height != event.resize.h) {
|
||||
Winsys.resolution.width = event.resize.w;
|
||||
Winsys.resolution.height = event.resize.h;
|
||||
case sf::Event::Resized:
|
||||
if (Winsys.resolution.width != event.size.width || Winsys.resolution.height != event.size.height) {
|
||||
Winsys.resolution.width = event.size.width;
|
||||
Winsys.resolution.height = event.size.height;
|
||||
Winsys.SetupVideoMode (param.res_type);
|
||||
Reshape(event.resize.w, event.resize.h);
|
||||
Reshape(event.size.width, event.size.height);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_QUIT:
|
||||
case sf::Event::Closed:
|
||||
quit = true;
|
||||
break;
|
||||
}
|
||||
|
@ -130,10 +118,7 @@ void State::Manager::PollEvent() {
|
|||
}
|
||||
|
||||
void State::Manager::CallLoopFunction() {
|
||||
float cur_time = SDL_GetTicks() * 1.e-3;
|
||||
g_game.time_step = cur_time - clock_time;
|
||||
if (g_game.time_step < 0.0001) g_game.time_step = 0.0001;
|
||||
clock_time = cur_time;
|
||||
|
||||
g_game.time_step = max(0.0001, timer.getElapsedTime().asSeconds());
|
||||
timer.restart();
|
||||
current->Loop(g_game.time_step);
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ GNU General Public License for more details.
|
|||
#define STATES_H
|
||||
|
||||
#include "bh.h"
|
||||
#include <SDL/SDL.h>
|
||||
|
||||
|
||||
class CWinsys;
|
||||
|
@ -38,8 +37,8 @@ public:
|
|||
State* current;
|
||||
State* next;
|
||||
bool quit;
|
||||
float clock_time;
|
||||
Manager(CWinsys& winsys) : Winsys(winsys), previous(NULL), current(NULL), next(NULL), quit(false), clock_time(0.f) {}
|
||||
sf::Clock timer;
|
||||
Manager(CWinsys& winsys) : Winsys(winsys), previous(NULL), current(NULL), next(NULL), quit(false) {}
|
||||
Manager(const Manager&);
|
||||
Manager& operator=(const Manager&);
|
||||
~Manager();
|
||||
|
@ -58,12 +57,12 @@ public:
|
|||
|
||||
virtual void Enter() {}
|
||||
virtual void Loop(double time_step) {}
|
||||
virtual void Keyb(unsigned int key, bool special, bool release, int x, int y) {}
|
||||
virtual void Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y) {}
|
||||
virtual void Mouse(int button, int state, int x, int y) {}
|
||||
virtual void Motion(int x, int y) {}
|
||||
virtual void Jaxis(int axis, float value) {}
|
||||
virtual void Jbutt(int button, int state) {}
|
||||
virtual void Keyb_spec(SDL_keysym sym, bool release) {}
|
||||
virtual void TextEntered(char text) {}
|
||||
virtual void Exit() {}
|
||||
};
|
||||
|
||||
|
|
349
src/textures.cpp
349
src/textures.cpp
|
@ -24,334 +24,38 @@ GNU General Public License for more details.
|
|||
#include "course.h"
|
||||
#include "winsys.h"
|
||||
#include "ogl.h"
|
||||
#include <SDL/SDL_image.h>
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <GL/glu.h>
|
||||
#include <fstream>
|
||||
#include <cctype>
|
||||
|
||||
|
||||
static const GLshort fullsize_texture[] = {
|
||||
0, 0,
|
||||
1, 0,
|
||||
0, 1,
|
||||
1, 1,
|
||||
0, 1
|
||||
1, 0,
|
||||
0, 0
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// class CImage
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
CImage::CImage () {
|
||||
data = NULL;
|
||||
nx = 0;
|
||||
ny = 0;
|
||||
depth = 0;
|
||||
pitch = 0;
|
||||
}
|
||||
|
||||
CImage::~CImage () {
|
||||
DisposeData ();
|
||||
}
|
||||
|
||||
void CImage::DisposeData () {
|
||||
delete[] data;
|
||||
data = NULL;
|
||||
}
|
||||
|
||||
bool CImage::LoadPng (const char *filepath, bool mirroring) {
|
||||
SDL_Surface *sdlImage;
|
||||
unsigned char *sdlData;
|
||||
|
||||
sdlImage = IMG_Load (filepath);
|
||||
if (sdlImage == 0) {
|
||||
Message ("could not load image", filepath);
|
||||
return false;
|
||||
}
|
||||
|
||||
nx = sdlImage->w;
|
||||
ny = sdlImage->h;
|
||||
depth = sdlImage->format->BytesPerPixel;
|
||||
pitch = sdlImage->pitch;
|
||||
DisposeData ();
|
||||
data = new unsigned char[pitch * ny];
|
||||
|
||||
if (SDL_MUSTLOCK (sdlImage)) {
|
||||
if (SDL_LockSurface (sdlImage) < 0) {
|
||||
SDL_FreeSurface (sdlImage);
|
||||
Message ("mustlock error");
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
sdlData = (unsigned char *) sdlImage->pixels;
|
||||
|
||||
if (mirroring) {
|
||||
for (int y=0; y<ny; y++) {
|
||||
memcpy(data + y*pitch, sdlData + (ny-1-y)*pitch, pitch);
|
||||
}
|
||||
} else {
|
||||
memcpy(data, sdlData, ny*pitch);
|
||||
}
|
||||
|
||||
if (SDL_MUSTLOCK (sdlImage)) SDL_UnlockSurface (sdlImage);
|
||||
SDL_FreeSurface (sdlImage);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CImage::LoadPng (const char *dir, const char *filename, bool mirroring) {
|
||||
string path = dir;
|
||||
path += SEP;
|
||||
path += filename;
|
||||
return LoadPng (path.c_str(), mirroring);
|
||||
}
|
||||
|
||||
// ------------------ read framebuffer --------------------------------
|
||||
|
||||
bool CImage::ReadFrameBuffer_PPM () {
|
||||
int viewport[4];
|
||||
glGetIntegerv (GL_VIEWPORT, viewport);
|
||||
|
||||
nx = viewport[2];
|
||||
ny = viewport[3];
|
||||
depth = 3;
|
||||
|
||||
DisposeData ();
|
||||
data = new unsigned char[nx * ny * depth];
|
||||
|
||||
glReadBuffer (GL_FRONT);
|
||||
|
||||
for (int i=0; i<viewport[3]; i++) {
|
||||
glReadPixels (viewport[0], viewport[1] + viewport[3] - 1 - i,
|
||||
viewport[2], 1, GL_RGB, GL_UNSIGNED_BYTE, data + viewport[2] * i * 3);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CImage::ReadFrameBuffer_TGA () {
|
||||
nx = Winsys.resolution.width;
|
||||
ny = Winsys.resolution.height;
|
||||
depth = 3;
|
||||
|
||||
DisposeData ();
|
||||
data = new unsigned char[nx * ny * depth];
|
||||
|
||||
glReadBuffer (GL_FRONT);
|
||||
glReadPixels (0, 0, nx, ny, GL_BGR, GL_UNSIGNED_BYTE, data);
|
||||
}
|
||||
|
||||
void CImage::ReadFrameBuffer_BMP () {
|
||||
nx = Winsys.resolution.width;
|
||||
ny = Winsys.resolution.height;
|
||||
depth = 4;
|
||||
|
||||
DisposeData ();
|
||||
data = new unsigned char[nx * ny * depth];
|
||||
glReadBuffer (GL_FRONT);
|
||||
glReadPixels (0, 0, nx, ny, GL_BGRA, GL_UNSIGNED_BYTE, data);
|
||||
}
|
||||
|
||||
// ---------------------------
|
||||
|
||||
void CImage::WritePPM (const char *filepath) {
|
||||
if (data == NULL)
|
||||
return;
|
||||
|
||||
std::ofstream file(filepath);
|
||||
|
||||
file << "P6\n# A Raw PPM file"
|
||||
<< "\n# width\n" << nx
|
||||
<< "\n# height\n" << ny
|
||||
<< "\n# max component value\n255"<< std::endl;
|
||||
|
||||
file.write(reinterpret_cast<char*>(data), depth * nx * ny);
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma pack(push, 1)
|
||||
#endif
|
||||
struct TTgaHeader {
|
||||
int8_t tfType;
|
||||
int8_t tfColorMapType;
|
||||
int8_t tfImageType;
|
||||
int8_t tfColorMapSpec[5];
|
||||
int16_t tfOrigX;
|
||||
int16_t tfOrigY;
|
||||
int16_t tfWidth;
|
||||
int16_t tfHeight;
|
||||
int8_t tfBpp;
|
||||
int8_t tfImageDes;
|
||||
#ifdef _MSC_VER
|
||||
};
|
||||
#pragma pack(pop)
|
||||
#else
|
||||
} __attribute__((packed));
|
||||
#endif
|
||||
|
||||
void CImage::WriteTGA (const char *filepath) {
|
||||
if (data == NULL)
|
||||
return;
|
||||
|
||||
TTgaHeader header;
|
||||
|
||||
header.tfType = 0;
|
||||
header.tfColorMapType = 0;
|
||||
header.tfImageType = 2;
|
||||
for (int i=0; i<5; i++) header.tfColorMapSpec[i] = 0;
|
||||
header.tfOrigX = 0;
|
||||
header.tfOrigY = 0;
|
||||
header.tfWidth = static_cast<int16_t>(nx);
|
||||
header.tfHeight = static_cast<int16_t>(ny);
|
||||
header.tfBpp = 24;
|
||||
header.tfImageDes = 0;
|
||||
|
||||
std::ofstream out(filepath, std::ios_base::out|std::ios_base::binary);
|
||||
out.write(reinterpret_cast<char*>(&header), sizeof(TTgaHeader));
|
||||
out.write(reinterpret_cast<char*>(data), 3 * nx * ny);
|
||||
}
|
||||
|
||||
#define BF_TYPE 0x4D42 // "MB"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma pack(push, 1)
|
||||
#endif
|
||||
struct TBmpHeader {
|
||||
uint16_t bfType; // identifier of bmp format
|
||||
uint32_t bfSize; // size of file, including the headers
|
||||
uint16_t bfReserved1; // reserved, always 0
|
||||
uint16_t bfReserved2; // reserved, always 0
|
||||
uint32_t bfOffBits; // offset to bitmap data
|
||||
#ifdef _MSC_VER
|
||||
};
|
||||
#else
|
||||
} __attribute__((packed));
|
||||
#endif
|
||||
|
||||
struct TBmpInfo {
|
||||
uint32_t biSize; // size of info header, normally 40
|
||||
int32_t biWidth; // width
|
||||
int32_t biHeight; // height
|
||||
uint16_t biPlanes; // number of color planes, normally 1
|
||||
uint16_t biBitCount; // Number of bits per pixel (8 * depth)
|
||||
uint32_t biCompression; // type of compression, normally 0 = no compr.
|
||||
uint32_t biSizeImage; // size of data
|
||||
int32_t biXPelsPerMeter; // normally 0
|
||||
int32_t biYPelsPerMeter; // normally 0
|
||||
uint32_t biClrUsed; // normally 0
|
||||
uint32_t biClrImportant; // normally 0
|
||||
#ifdef _MSC_VER
|
||||
};
|
||||
#pragma pack(pop)
|
||||
#else
|
||||
} __attribute__((packed));
|
||||
#endif
|
||||
|
||||
void CImage::WriteBMP (const char *filepath) {
|
||||
if (data == NULL)
|
||||
return;
|
||||
|
||||
int infosize = 40;
|
||||
int width = nx;
|
||||
int height = ny;
|
||||
int imgsize = nx * ny * depth;
|
||||
int bitcnt = 8 * depth; // 24 or 32
|
||||
unsigned int bitsize;
|
||||
// (width * bitcnt + 7) / 8 = width * depth
|
||||
if (imgsize == 0) bitsize = (width * bitcnt + 7) / 8 * height;
|
||||
else bitsize = imgsize;
|
||||
|
||||
TBmpHeader header;
|
||||
header.bfType = BF_TYPE;
|
||||
header.bfSize = 14 + infosize + bitsize;
|
||||
header.bfReserved1 = 0;
|
||||
header.bfReserved2 = 0;
|
||||
header.bfOffBits = sizeof(TBmpHeader) + sizeof(TBmpInfo);
|
||||
|
||||
TBmpInfo info;
|
||||
info.biSize = infosize;
|
||||
info.biWidth = width;
|
||||
info.biHeight = height;
|
||||
info.biPlanes = 1;
|
||||
info.biBitCount = bitcnt;
|
||||
info.biCompression = 0;
|
||||
info.biSizeImage = imgsize;
|
||||
info.biXPelsPerMeter = 0;
|
||||
info.biYPelsPerMeter= 0;
|
||||
info.biClrUsed = 0;
|
||||
info.biClrImportant = 0;
|
||||
|
||||
std::ofstream out(filepath, std::ios_base::out|std::ios_base::binary);
|
||||
if (!out) {
|
||||
Message ("could not open bmp file", filepath);
|
||||
return;
|
||||
}
|
||||
|
||||
out.write(reinterpret_cast<char*>(&header), sizeof(TBmpHeader));
|
||||
out.write(reinterpret_cast<char*>(&info), sizeof(TBmpInfo));
|
||||
|
||||
out.write(reinterpret_cast<char*>(data), bitsize);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// class TTexture
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
TTexture::~TTexture() {
|
||||
glDeleteTextures (1, &id);
|
||||
}
|
||||
|
||||
bool TTexture::Load(const string& filename) {
|
||||
CImage texImage;
|
||||
|
||||
if (texImage.LoadPng (filename.c_str(), true) == false)
|
||||
return false;
|
||||
glGenTextures (1, &id);
|
||||
glBindTexture (GL_TEXTURE_2D, id);
|
||||
glPixelStorei (GL_UNPACK_ALIGNMENT, 4);
|
||||
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
||||
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
||||
|
||||
GLenum format;
|
||||
if (texImage.depth == 3) format = GL_RGB;
|
||||
else format = GL_RGBA;
|
||||
|
||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
|
||||
glTexImage2D
|
||||
(GL_TEXTURE_2D, 0, texImage.depth, texImage.nx,
|
||||
texImage.ny, 0, format, GL_UNSIGNED_BYTE, texImage.data);
|
||||
return true;
|
||||
texture = new sf::Texture();
|
||||
return texture->loadFromFile(filename);
|
||||
}
|
||||
bool TTexture::Load(const string& dir, const string& filename) {
|
||||
return Load(dir + SEP + filename);
|
||||
}
|
||||
|
||||
bool TTexture::LoadMipmap(const string& filename, bool repeatable) {
|
||||
CImage texImage;
|
||||
if (texImage.LoadPng (filename.c_str(), true) == false)
|
||||
texture = new sf::Texture();
|
||||
texture->setRepeated(repeatable);
|
||||
if (!texture->loadFromFile(filename))
|
||||
return false;
|
||||
|
||||
glGenTextures (1, &id);
|
||||
glBindTexture (GL_TEXTURE_2D, id);
|
||||
glPixelStorei (GL_UNPACK_ALIGNMENT, 4);
|
||||
|
||||
if (repeatable) {
|
||||
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
} else {
|
||||
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
||||
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
||||
}
|
||||
|
||||
GLenum format;
|
||||
if (texImage.depth == 3) format = GL_RGB;
|
||||
else format = GL_RGBA;
|
||||
|
||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
|
||||
|
||||
gluBuild2DMipmaps(GL_TEXTURE_2D, texImage.depth, texImage.nx, texImage.ny, format, GL_UNSIGNED_BYTE, texImage.data);
|
||||
///gluBuild2DMipmaps(GL_TEXTURE_2D, 4, texture->getSize().x, texture->getSize().y, GL_RGBA, GL_UNSIGNED_BYTE, texture->);
|
||||
return true;
|
||||
}
|
||||
bool TTexture::LoadMipmap(const string& dir, const string& filename, bool repeatable) {
|
||||
|
@ -359,7 +63,7 @@ bool TTexture::LoadMipmap(const string& dir, const string& filename, bool repeat
|
|||
}
|
||||
|
||||
void TTexture::Bind() {
|
||||
glBindTexture (GL_TEXTURE_2D, id);
|
||||
sf::Texture::bind(texture);
|
||||
}
|
||||
|
||||
void TTexture::Draw() {
|
||||
|
@ -367,7 +71,7 @@ void TTexture::Draw() {
|
|||
|
||||
glEnable (GL_TEXTURE_2D);
|
||||
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glBindTexture (GL_TEXTURE_2D, id);
|
||||
Bind();
|
||||
|
||||
glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
|
||||
glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h);
|
||||
|
@ -396,7 +100,7 @@ void TTexture::Draw(int x, int y, float size, Orientation orientation) {
|
|||
|
||||
glEnable (GL_TEXTURE_2D);
|
||||
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glBindTexture (GL_TEXTURE_2D, id);
|
||||
Bind();
|
||||
|
||||
glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
|
||||
glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h);
|
||||
|
@ -439,7 +143,7 @@ void TTexture::Draw(int x, int y, float width, float height, Orientation orienta
|
|||
|
||||
glEnable (GL_TEXTURE_2D);
|
||||
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glBindTexture (GL_TEXTURE_2D, id);
|
||||
Bind();
|
||||
|
||||
if (orientation == OR_TOP) {
|
||||
top = Winsys.resolution.height - y;
|
||||
|
@ -471,7 +175,7 @@ void TTexture::Draw(int x, int y, float width, float height, Orientation orienta
|
|||
}
|
||||
|
||||
void TTexture::DrawFrame(int x, int y, double w, double h, int frame, const TColor& col) {
|
||||
if (id < 1)
|
||||
if (!texture)
|
||||
return;
|
||||
|
||||
GLint ww = GLint(w);
|
||||
|
@ -479,7 +183,7 @@ void TTexture::DrawFrame(int x, int y, double w, double h, int frame, const TCol
|
|||
GLint xx = x;
|
||||
GLint yy = Winsys.resolution.height - hh - y;
|
||||
|
||||
glBindTexture (GL_TEXTURE_2D, id);
|
||||
Bind();
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
@ -652,10 +356,10 @@ void CTexture::DrawNumChr (char c, int x, int y, int w, int h, const TColor& col
|
|||
float texright = (idx + 1) * texw;
|
||||
|
||||
const GLfloat tex[] = {
|
||||
texleft, 0,
|
||||
texright, 0,
|
||||
texleft, 1,
|
||||
texright, 1,
|
||||
texleft, 1
|
||||
texright, 0,
|
||||
texleft, 0
|
||||
};
|
||||
const GLfloat vtx[] = {
|
||||
x, Winsys.resolution.height - y - h,
|
||||
|
@ -690,6 +394,7 @@ void CTexture::DrawNumStr (const string& s, int x, int y, float size, const TCol
|
|||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
// screenshot
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
|
@ -697,7 +402,10 @@ void CTexture::DrawNumStr (const string& s, int x, int y, float size, const TCol
|
|||
#define SCREENSHOT_PROC 2
|
||||
|
||||
void ScreenshotN () {
|
||||
CImage image;
|
||||
sf::Texture tex;
|
||||
tex.update(Winsys.window);
|
||||
sf::Image img = tex.copyToImage();
|
||||
|
||||
string path = param.screenshot_dir;
|
||||
path += SEP;
|
||||
path += Course.CourseList[g_game.course_id].dir;
|
||||
|
@ -708,18 +416,15 @@ void ScreenshotN () {
|
|||
switch (type) {
|
||||
case 0:
|
||||
path += ".ppm";
|
||||
image.ReadFrameBuffer_PPM ();
|
||||
image.WritePPM (path.c_str());
|
||||
img.saveToFile(path);
|
||||
break;
|
||||
case 1:
|
||||
path += ".tga";
|
||||
image.ReadFrameBuffer_TGA ();
|
||||
image.WriteTGA (path.c_str());
|
||||
img.saveToFile(path);
|
||||
break;
|
||||
case 2:
|
||||
path += ".bmp";
|
||||
image.ReadFrameBuffer_BMP ();
|
||||
image.WriteBMP (path.c_str());
|
||||
img.saveToFile(path);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,50 +66,18 @@ GNU General Public License for more details.
|
|||
#define T_SNOW3 43
|
||||
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// class CImage
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
class CImage {
|
||||
private:
|
||||
public:
|
||||
CImage ();
|
||||
~CImage ();
|
||||
|
||||
unsigned char *data;
|
||||
int nx;
|
||||
int ny;
|
||||
int depth;
|
||||
int pitch;
|
||||
|
||||
void DisposeData ();
|
||||
|
||||
// load:
|
||||
bool LoadPng (const char *filepath, bool mirroring);
|
||||
bool LoadPng (const char *dir, const char *filepath, bool mirroring);
|
||||
|
||||
// write:
|
||||
bool ReadFrameBuffer_PPM ();
|
||||
void ReadFrameBuffer_TGA ();
|
||||
void ReadFrameBuffer_BMP ();
|
||||
void WritePPM (const char *filepath);
|
||||
void WriteTGA (const char *filepath);
|
||||
void WriteBMP (const char *filepath);
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// class CTexture
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
class TTexture {
|
||||
sf::Texture* texture;
|
||||
|
||||
TTexture(const TTexture&);
|
||||
TTexture& operator=(const TTexture&);
|
||||
|
||||
GLuint id;
|
||||
public:
|
||||
|
||||
TTexture() : id(0) {}
|
||||
~TTexture();
|
||||
TTexture() : texture(NULL) {}
|
||||
~TTexture() { delete texture; }
|
||||
bool Load(const string& filename);
|
||||
bool Load(const string& dir, const string& filename);
|
||||
bool LoadMipmap(const string& filename, bool repeatable);
|
||||
|
|
|
@ -120,15 +120,15 @@ void SetRotation (double x, double y, double z) {
|
|||
zrotation = z;
|
||||
}
|
||||
|
||||
void CharKeys (unsigned int key, bool special, bool release, int x, int y) {
|
||||
void CharKeys (sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
must_render = true;
|
||||
|
||||
if (ToolsFinalStage ()) {
|
||||
if (key == SDLK_y || key == SDLK_j) {
|
||||
if (key == sf::Keyboard::Y || key == sf::Keyboard::J) {
|
||||
SaveToolCharacter ();
|
||||
SaveToolFrame ();
|
||||
State::manager.RequestQuit();
|
||||
} else if (key == SDLK_n) State::manager.RequestQuit();
|
||||
} else if (key == sf::Keyboard::N) State::manager.RequestQuit();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -140,97 +140,97 @@ void CharKeys (unsigned int key, bool special, bool release, int x, int y) {
|
|||
|
||||
int type = action->type[curr_act];
|
||||
switch (key) {
|
||||
case SDLK_TAB:
|
||||
case sf::Keyboard::Tab:
|
||||
SetToolMode (1);
|
||||
break;
|
||||
case SDLK_ESCAPE:
|
||||
case SDLK_q:
|
||||
case sf::Keyboard::Escape:
|
||||
case sf::Keyboard::Q:
|
||||
QuitTool ();
|
||||
break;
|
||||
case SDLK_F10:
|
||||
case sf::Keyboard::F10:
|
||||
ScreenshotN ();
|
||||
break;
|
||||
case SDLK_s:
|
||||
case sf::Keyboard::S:
|
||||
SaveToolCharacter ();
|
||||
break;
|
||||
case SDLK_c:
|
||||
case sf::Keyboard::C:
|
||||
ScreenshotN ();
|
||||
break;
|
||||
case SDLK_m:
|
||||
case sf::Keyboard::M:
|
||||
TestChar.useMaterials = !TestChar.useMaterials;
|
||||
break;
|
||||
case SDLK_h:
|
||||
case sf::Keyboard::H:
|
||||
TestChar.useHighlighting = !TestChar.useHighlighting;
|
||||
break;
|
||||
case SDLK_r:
|
||||
case sf::Keyboard::R:
|
||||
TestChar.Reset ();
|
||||
ReloadToolCharacter ();
|
||||
Tools.Enter ();
|
||||
break;
|
||||
case SDLK_u:
|
||||
case sf::Keyboard::U:
|
||||
if (action != NULL) {
|
||||
RecallAction (action);
|
||||
TestChar.RefreshNode (curr_node);
|
||||
}
|
||||
break;
|
||||
case SDLK_PLUS:
|
||||
case SDLK_EQUALS: // zoom in
|
||||
case sf::Keyboard::Add:
|
||||
case sf::Keyboard::Equal: // zoom in
|
||||
zposition += 0.1;
|
||||
xposition -= 0.03;
|
||||
break;
|
||||
case SDLK_MINUS: // zoom out
|
||||
case sf::Keyboard::Dash: // zoom out
|
||||
zposition -= 0.1;
|
||||
xposition += 0.03;
|
||||
break;
|
||||
|
||||
// set rotations for view
|
||||
case SDLK_1:
|
||||
case sf::Keyboard::Num1:
|
||||
SetRotation (0, 0, 0);
|
||||
break;
|
||||
case SDLK_2:
|
||||
case sf::Keyboard::Num2:
|
||||
SetRotation (-50, 180, 15);
|
||||
break;
|
||||
case SDLK_3:
|
||||
case sf::Keyboard::Num3:
|
||||
SetRotation (0, 180, 0);
|
||||
break;
|
||||
case SDLK_4:
|
||||
case sf::Keyboard::Num4:
|
||||
SetRotation (0, -80, 0);
|
||||
break;
|
||||
|
||||
// select node
|
||||
case SDLK_PAGEUP:
|
||||
case sf::Keyboard::PageUp:
|
||||
ChangeNode (-1);
|
||||
break;
|
||||
case SDLK_PAGEDOWN:
|
||||
case sf::Keyboard::PageDown:
|
||||
ChangeNode (1);
|
||||
break;
|
||||
case SDLK_END:
|
||||
case sf::Keyboard::End:
|
||||
ChangeNode (charbase);
|
||||
break;
|
||||
case SDLK_HOME:
|
||||
case sf::Keyboard::Home:
|
||||
ChangeNode (-charbase);
|
||||
break;
|
||||
|
||||
// select action
|
||||
case SDLK_DOWN:
|
||||
case sf::Keyboard::Down:
|
||||
if (curr_act < lastact) curr_act++;
|
||||
if (action->type[curr_act] == 4) comp = 0;
|
||||
else comp = 1;
|
||||
break;
|
||||
case SDLK_UP:
|
||||
case sf::Keyboard::Up:
|
||||
if (curr_act > 0) curr_act--;
|
||||
if (action->type[curr_act] == 4) comp = 0;
|
||||
else comp = 1;
|
||||
break;
|
||||
case SDLK_LEFT:
|
||||
case sf::Keyboard::Left:
|
||||
ChangeValue (type, -1);
|
||||
break;
|
||||
case SDLK_RIGHT:
|
||||
case sf::Keyboard::Right:
|
||||
ChangeValue (type, 1);
|
||||
break;
|
||||
|
||||
// select value
|
||||
case SDLK_SPACE:
|
||||
case sf::Keyboard::Space:
|
||||
if (type == 0 || type == 4) {
|
||||
comp++;
|
||||
if (comp > 3) comp = 0;
|
||||
|
|
|
@ -23,7 +23,7 @@ GNU General Public License for more details.
|
|||
struct TCharAction;
|
||||
|
||||
void InitCharTools ();
|
||||
void CharKeys (unsigned int key, bool special, bool release, int x, int y);
|
||||
void CharKeys (sf::Keyboard::Key key, bool special, bool release, int x, int y);
|
||||
void CharMouse (int button, int state, int x, int y);
|
||||
void CharMotion (int x, int y);
|
||||
void RenderChar (double timestep);
|
||||
|
|
|
@ -49,7 +49,7 @@ void InitFrameTools () {
|
|||
last_joint = TestFrame.GetNumJoints () -1;
|
||||
}
|
||||
|
||||
void SingleFrameKeys (unsigned int key, bool special, bool release, int x, int y) {
|
||||
void SingleFrameKeys (sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
//PrintInt (key);
|
||||
must_render = true;
|
||||
int keyfact;
|
||||
|
@ -57,139 +57,139 @@ void SingleFrameKeys (unsigned int key, bool special, bool release, int x, int y
|
|||
TKeyframe *frame = TestFrame.GetFrame (curr_frame);
|
||||
|
||||
// setting the camera change state
|
||||
if (key == SDLK_F1) {GluCamera.turnright = !release; return;}
|
||||
else if (key == SDLK_F2) {GluCamera.turnleft = !release; return;}
|
||||
if (key == SDLK_F3) {GluCamera.nearer = !release; return;}
|
||||
else if (key == SDLK_F4) {GluCamera.farther = !release; return;}
|
||||
if (key == sf::Keyboard::F1) {GluCamera.turnright = !release; return;}
|
||||
else if (key == sf::Keyboard::F2) { GluCamera.turnleft = !release; return; }
|
||||
if (key == sf::Keyboard::F3) { GluCamera.nearer = !release; return; }
|
||||
else if (key == sf::Keyboard::F4) { GluCamera.farther = !release; return; }
|
||||
|
||||
// additional keys if needed
|
||||
if (key == SDLK_LSHIFT) shift = !release;
|
||||
if (key == SDLK_LCTRL) control = !release;
|
||||
if (key == SDLK_LALT) alt = !release;
|
||||
if (key == sf::Keyboard::LShift || key == sf::Keyboard::RShift) shift = !release;
|
||||
if (key == sf::Keyboard::LControl) control = !release;
|
||||
if (key == sf::Keyboard::LAlt) alt = !release;
|
||||
if (shift) keyfact = -1;
|
||||
else keyfact = 1;
|
||||
|
||||
if (release) return;
|
||||
|
||||
switch (key) {
|
||||
case SDLK_y:
|
||||
case SDLK_j:
|
||||
case sf::Keyboard::Y:
|
||||
case sf::Keyboard::J:
|
||||
if (ToolsFinalStage ()) {
|
||||
SaveToolCharacter ();
|
||||
SaveToolFrame ();
|
||||
State::manager.RequestQuit();
|
||||
}
|
||||
break;
|
||||
case SDLK_n:
|
||||
case sf::Keyboard::N:
|
||||
if (ToolsFinalStage ()) State::manager.RequestQuit();
|
||||
break;
|
||||
|
||||
case SDLK_ESCAPE:
|
||||
case SDLK_q:
|
||||
case sf::Keyboard::Escape:
|
||||
case sf::Keyboard::Q:
|
||||
QuitTool ();
|
||||
break;
|
||||
case SDLK_s:
|
||||
case sf::Keyboard::S:
|
||||
SaveToolFrame ();
|
||||
break;
|
||||
case SDLK_TAB:
|
||||
case sf::Keyboard::Tab:
|
||||
SetToolMode (0);
|
||||
break;
|
||||
|
||||
case SDLK_a:
|
||||
case sf::Keyboard::A:
|
||||
TestFrame.AddFrame ();
|
||||
SetFrameChanged (true);
|
||||
break;
|
||||
case SDLK_INSERT:
|
||||
case sf::Keyboard::Insert:
|
||||
TestFrame.InsertFrame (curr_frame);
|
||||
SetFrameChanged (true);
|
||||
break;
|
||||
case SDLK_DELETE:
|
||||
case sf::Keyboard::Delete:
|
||||
curr_frame = TestFrame.DeleteFrame (curr_frame);
|
||||
SetFrameChanged (true);
|
||||
break;
|
||||
case SDLK_PAGEDOWN:
|
||||
case sf::Keyboard::PageDown:
|
||||
if (curr_frame < TestFrame.numFrames()-1) curr_frame++;
|
||||
break;
|
||||
case SDLK_PAGEUP:
|
||||
case sf::Keyboard::PageUp:
|
||||
if (curr_frame > 0) curr_frame--;
|
||||
break;
|
||||
case SDLK_UP:
|
||||
case sf::Keyboard::Up:
|
||||
if (curr_joint > 0) curr_joint--;
|
||||
break;
|
||||
case SDLK_DOWN:
|
||||
case sf::Keyboard::Down:
|
||||
if (curr_joint < last_joint) curr_joint++;
|
||||
break;
|
||||
case SDLK_RIGHT:
|
||||
case sf::Keyboard::Right:
|
||||
if (curr_joint < 4) frame->val[curr_joint] += 0.05;
|
||||
else frame->val[curr_joint] += 1;
|
||||
SetFrameChanged (true);
|
||||
break;
|
||||
case SDLK_LEFT:
|
||||
case sf::Keyboard::Left:
|
||||
if (curr_joint < 4) frame->val[curr_joint] -= 0.05;
|
||||
else frame->val[curr_joint] -= 1;
|
||||
SetFrameChanged (true);
|
||||
break;
|
||||
case SDLK_0:
|
||||
case sf::Keyboard::Num0:
|
||||
frame->val[curr_joint] = 0.0;
|
||||
SetFrameChanged (true);
|
||||
break;
|
||||
case SDLK_SPACE:
|
||||
case sf::Keyboard::Space:
|
||||
if (curr_joint < 4) frame->val[curr_joint] += 0.05 * keyfact;
|
||||
else frame->val[curr_joint] += 1 * keyfact;
|
||||
SetFrameChanged (true);
|
||||
break;
|
||||
|
||||
case SDLK_RETURN:
|
||||
case sf::Keyboard::Return:
|
||||
TestFrame.InitTest (ref_position, &TestChar);
|
||||
SetToolMode (2);
|
||||
must_render = true;
|
||||
break;
|
||||
|
||||
case SDLK_m:
|
||||
case sf::Keyboard::M :
|
||||
TestChar.useMaterials = !TestChar.useMaterials;
|
||||
break;
|
||||
case SDLK_h:
|
||||
case sf::Keyboard::H:
|
||||
TestChar.useHighlighting = !TestChar.useHighlighting;
|
||||
break;
|
||||
case SDLK_c:
|
||||
case sf::Keyboard::C:
|
||||
if (control) TestFrame.CopyToClipboard (curr_frame);
|
||||
else TestFrame.ClearFrame (curr_frame);
|
||||
SetFrameChanged (true);
|
||||
break;
|
||||
case SDLK_v:
|
||||
case sf::Keyboard::V:
|
||||
if (control) TestFrame.PasteFromClipboard (curr_frame);
|
||||
SetFrameChanged (true);
|
||||
break;
|
||||
case SDLK_p:
|
||||
case sf::Keyboard::P:
|
||||
if (curr_frame>0)
|
||||
TestFrame.CopyFrame (curr_frame-1, curr_frame);
|
||||
break;
|
||||
case SDLK_F10:
|
||||
case sf::Keyboard::F10:
|
||||
ScreenshotN ();
|
||||
break;
|
||||
|
||||
case SDLK_1:
|
||||
case sf::Keyboard::Num1:
|
||||
GluCamera.angle = 0;
|
||||
break;
|
||||
case SDLK_2:
|
||||
case sf::Keyboard::Num2:
|
||||
GluCamera.angle = 45;
|
||||
break;
|
||||
case SDLK_3:
|
||||
case sf::Keyboard::Num3:
|
||||
GluCamera.angle = 90;
|
||||
break;
|
||||
case SDLK_4:
|
||||
case sf::Keyboard::Num4:
|
||||
GluCamera.angle = 135;
|
||||
break;
|
||||
case SDLK_5:
|
||||
case sf::Keyboard::Num5:
|
||||
GluCamera.angle = 180;
|
||||
break;
|
||||
case SDLK_6:
|
||||
case sf::Keyboard::Num6:
|
||||
GluCamera.angle = 225;
|
||||
break;
|
||||
case SDLK_7:
|
||||
case sf::Keyboard::Num7:
|
||||
GluCamera.angle = 270;
|
||||
break;
|
||||
case SDLK_8:
|
||||
case sf::Keyboard::Num8:
|
||||
GluCamera.angle = 315;
|
||||
break;
|
||||
}
|
||||
|
@ -287,17 +287,17 @@ void RenderSingleFrame (double timestep) {
|
|||
// frame sequence
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
void SequenceKeys (unsigned int key, bool special, bool release, int x, int y) {
|
||||
void SequenceKeys (sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
if (release) return;
|
||||
switch (key) {
|
||||
case SDLK_RETURN:
|
||||
case sf::Keyboard::Return:
|
||||
keyrun = true;
|
||||
break;
|
||||
case SDLK_ESCAPE:
|
||||
case SDLK_TAB:
|
||||
case sf::Keyboard::Escape:
|
||||
case sf::Keyboard::Tab:
|
||||
SetToolMode (1);
|
||||
break;
|
||||
case SDLK_q:
|
||||
case sf::Keyboard::Q:
|
||||
QuitTool ();
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ GNU General Public License for more details.
|
|||
#include "bh.h"
|
||||
|
||||
void InitFrameTools ();
|
||||
void SingleFrameKeys (unsigned int key, bool special, bool release, int x, int y);
|
||||
void SingleFrameKeys (sf::Keyboard::Key key, bool special, bool release, int x, int y);
|
||||
void SingleFrameMouse (int button, int state, int x, int y);
|
||||
void SingleFrameMotion (int x, int y);
|
||||
void RenderSingleFrame (double timestep);
|
||||
|
@ -30,7 +30,7 @@ void RenderSingleFrame (double timestep);
|
|||
// frame sequence
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
void SequenceKeys (unsigned int key, bool special, bool release, int x, int y);
|
||||
void SequenceKeys (sf::Keyboard::Key key, bool special, bool release, int x, int y);
|
||||
void SequenceMouse (int button, int state, int x, int y);
|
||||
void SequenceMotion (int x, int y);
|
||||
void RenderSequence (double timestep);
|
||||
|
|
|
@ -239,7 +239,7 @@ void CTools::Enter() {
|
|||
Winsys.KeyRepeat (true);
|
||||
}
|
||||
|
||||
void CTools::Keyb(unsigned int key, bool special, bool release, int x, int y) {
|
||||
void CTools::Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
switch (tool_mode) {
|
||||
case 0:
|
||||
CharKeys (key, special, release, x, y);
|
||||
|
|
|
@ -88,7 +88,7 @@ void DrawChanged ();
|
|||
|
||||
class CTools : public State {
|
||||
void Loop(double time_step);
|
||||
void Keyb(unsigned int key, bool special, bool release, int x, int y);
|
||||
void Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y);
|
||||
void Mouse(int button, int state, int x, int y);
|
||||
void Motion(int x, int y);
|
||||
public:
|
||||
|
|
142
src/winsys.cpp
142
src/winsys.cpp
|
@ -28,7 +28,7 @@ GNU General Public License for more details.
|
|||
#include "textures.h"
|
||||
#include "spx.h"
|
||||
#include "course.h"
|
||||
#include <SDL/SDL_syswm.h>
|
||||
#include <SFML/Window.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#define USE_JOYSTICK true
|
||||
|
@ -39,10 +39,12 @@ CWinsys Winsys;
|
|||
|
||||
CWinsys::CWinsys ()
|
||||
: auto_resolution(800, 600) {
|
||||
screen = NULL;
|
||||
|
||||
joystick = NULL;
|
||||
numJoysticks = 0;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if (sf::Joystick::isConnected(i))
|
||||
numJoysticks++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
joystick_active = false;
|
||||
|
||||
resolutions[0] = TScreenRes(0, 0);
|
||||
|
@ -77,12 +79,10 @@ double CWinsys::CalcScreenScale () const {
|
|||
}
|
||||
|
||||
void CWinsys::SetupVideoMode (const TScreenRes& resolution_) {
|
||||
int bpp = 0;
|
||||
Uint32 video_flags = SDL_OPENGL;
|
||||
if (param.fullscreen) video_flags |= SDL_FULLSCREEN;
|
||||
int bpp = 32;
|
||||
switch (param.bpp_mode) {
|
||||
case 0:
|
||||
bpp = 0;
|
||||
bpp = 32;
|
||||
break;
|
||||
case 1:
|
||||
bpp = 16;
|
||||
|
@ -92,41 +92,23 @@ void CWinsys::SetupVideoMode (const TScreenRes& resolution_) {
|
|||
break;
|
||||
default:
|
||||
param.bpp_mode = 0;
|
||||
bpp = 0;
|
||||
bpp = 32;
|
||||
}
|
||||
sf::Uint32 style = sf::Style::Close | sf::Style::Titlebar;
|
||||
if (param.fullscreen)
|
||||
style |= sf::Style::Fullscreen;
|
||||
|
||||
#ifdef _WIN32
|
||||
SDL_SysWMinfo info;
|
||||
SDL_VERSION(&info.version);
|
||||
SDL_GetWMInfo(&info);
|
||||
HDC tempDC = GetDC(info.window);
|
||||
HGLRC tempRC = wglCreateContext(tempDC);
|
||||
SetLastError(0);
|
||||
wglShareLists(info.hglrc, tempRC); // Share resources with old context
|
||||
resolution = resolution_;
|
||||
|
||||
#ifdef USE_STENCIL_BUFFER
|
||||
sf::ContextSettings ctx(bpp, 8, 0, 1, 2);
|
||||
#else
|
||||
sf::ContextSettings ctx(bpp, 0, 0, 1, 2);
|
||||
#endif
|
||||
window.create(sf::VideoMode(resolution.width, resolution.height, bpp), WINDOW_TITLE, style, ctx);
|
||||
if (param.framerate)
|
||||
window.setFramerateLimit(param.framerate);
|
||||
|
||||
if ((screen = SDL_SetVideoMode
|
||||
(resolution_.width, resolution_.height, bpp, video_flags)) == NULL) {
|
||||
Message ("couldn't initialize video", SDL_GetError());
|
||||
Message ("set to 800 x 600");
|
||||
screen = SDL_SetVideoMode (800, 600, bpp, video_flags);
|
||||
param.res_type = 1;
|
||||
SaveConfigFile ();
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
SDL_VERSION(&info.version);
|
||||
SDL_GetWMInfo(&info);
|
||||
wglShareLists(tempRC, info.hglrc); // Share resources with new context
|
||||
wglDeleteContext(tempRC);
|
||||
#endif
|
||||
|
||||
SDL_Surface *surf = SDL_GetVideoSurface ();
|
||||
resolution.width = surf->w;
|
||||
resolution.height = surf->h;
|
||||
if (resolution.width == 0 && resolution.height == 0) {
|
||||
auto_resolution = resolution;
|
||||
}
|
||||
scale = CalcScreenScale ();
|
||||
if (param.use_quad_scale) scale = sqrt (scale);
|
||||
}
|
||||
|
@ -139,47 +121,14 @@ void CWinsys::SetupVideoMode (int width, int height) {
|
|||
SetupVideoMode (TScreenRes(width, height));
|
||||
}
|
||||
|
||||
void CWinsys::InitJoystick () {
|
||||
if (SDL_InitSubSystem (SDL_INIT_JOYSTICK) < 0) {
|
||||
Message ("Could not initialize SDL_joystick: %s", SDL_GetError());
|
||||
return;
|
||||
}
|
||||
numJoysticks = SDL_NumJoysticks ();
|
||||
if (numJoysticks < 1) {
|
||||
joystick = NULL;
|
||||
return;
|
||||
}
|
||||
SDL_JoystickEventState (SDL_ENABLE);
|
||||
joystick = SDL_JoystickOpen (0); // first stick with number 0
|
||||
if (joystick == NULL) {
|
||||
Message ("Cannot open joystick %s", SDL_GetError ());
|
||||
return;
|
||||
}
|
||||
joystick_active = true;
|
||||
}
|
||||
|
||||
void CWinsys::Init () {
|
||||
Uint32 sdl_flags = SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE | SDL_INIT_TIMER;
|
||||
if (SDL_Init (sdl_flags) < 0) Message ("Could not initialize SDL");
|
||||
SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
|
||||
SetupVideoMode(GetResolution(param.res_type));
|
||||
|
||||
#if defined (USE_STENCIL_BUFFER)
|
||||
SDL_GL_SetAttribute (SDL_GL_STENCIL_SIZE, 8);
|
||||
#endif
|
||||
|
||||
SetupVideoMode (GetResolution (param.res_type));
|
||||
Reshape (resolution.width, resolution.height);
|
||||
|
||||
SDL_WM_SetCaption (WINDOW_TITLE, WINDOW_TITLE);
|
||||
KeyRepeat (false);
|
||||
if (USE_JOYSTICK) InitJoystick ();
|
||||
// SDL_EnableUNICODE (1);
|
||||
}
|
||||
|
||||
void CWinsys::KeyRepeat (bool repeat) {
|
||||
if (repeat)
|
||||
SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
|
||||
else SDL_EnableKeyRepeat (0, 0);
|
||||
window.setKeyRepeatEnabled(repeat);
|
||||
}
|
||||
|
||||
void CWinsys::SetFonttype () {
|
||||
|
@ -190,17 +139,12 @@ void CWinsys::SetFonttype () {
|
|||
}
|
||||
}
|
||||
|
||||
void CWinsys::CloseJoystick () {
|
||||
if (joystick_active) SDL_JoystickClose (joystick);
|
||||
}
|
||||
|
||||
void CWinsys::Quit () {
|
||||
CloseJoystick ();
|
||||
Score.SaveHighScore ();
|
||||
SaveMessages ();
|
||||
FT.Clear ();
|
||||
if (g_game.argument < 1) Players.SavePlayers ();
|
||||
SDL_Quit ();
|
||||
window.close();
|
||||
}
|
||||
|
||||
void CWinsys::Terminate () {
|
||||
|
@ -209,18 +153,34 @@ void CWinsys::Terminate () {
|
|||
}
|
||||
|
||||
void CWinsys::PrintJoystickInfo () const {
|
||||
if (joystick_active == false) {
|
||||
Message ("No joystick found");
|
||||
if (numJoysticks == 0) {
|
||||
cout << "No joystick found\n";
|
||||
return;
|
||||
}
|
||||
PrintStr ("");
|
||||
PrintStr (SDL_JoystickName (0));
|
||||
int num_buttons = SDL_JoystickNumButtons (joystick);
|
||||
cout << "Joystick has " << num_buttons << " button" << (num_buttons == 1 ? "" : "s") << '\n';
|
||||
int num_axes = SDL_JoystickNumAxes (joystick);
|
||||
cout << "Joystick has " << num_axes << " ax" << (num_axes == 1 ? "i" : "e") << "s\n\n";
|
||||
cout << '\n';
|
||||
for (int i = 0; i < numJoysticks; i++) {
|
||||
cout << "Joystick " << i << '\n';
|
||||
int buttons = sf::Joystick::getButtonCount(i);
|
||||
cout << "Joystick has " << buttons << " button" << (buttons == 1 ? "" : "s") << '\n';
|
||||
cout << "Axes: ";
|
||||
if (sf::Joystick::hasAxis(i, sf::Joystick::R)) cout << "R ";
|
||||
if (sf::Joystick::hasAxis(i, sf::Joystick::U)) cout << "U ";
|
||||
if (sf::Joystick::hasAxis(i, sf::Joystick::V)) cout << "V ";
|
||||
if (sf::Joystick::hasAxis(i, sf::Joystick::X)) cout << "X ";
|
||||
if (sf::Joystick::hasAxis(i, sf::Joystick::Y)) cout << "Y ";
|
||||
if (sf::Joystick::hasAxis(i, sf::Joystick::Z)) cout << "Z ";
|
||||
cout << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char *CWinsys::GetSurfaceData () const {
|
||||
return (unsigned char*)screen->pixels;
|
||||
void CWinsys::ShowCursor(bool visible) {
|
||||
window.setMouseCursorVisible(visible);
|
||||
}
|
||||
|
||||
void CWinsys::SwapBuffers() {
|
||||
window.display();
|
||||
}
|
||||
|
||||
bool CWinsys::PollEvent(sf::Event& event) {
|
||||
return window.pollEvent(event);
|
||||
}
|
||||
|
|
17
src/winsys.h
17
src/winsys.h
|
@ -19,10 +19,13 @@ GNU General Public License for more details.
|
|||
#define WINSYS_H
|
||||
|
||||
#include "bh.h"
|
||||
#include <SDL/SDL.h>
|
||||
|
||||
#define NUM_RESOLUTIONS 10
|
||||
|
||||
namespace sf {
|
||||
class Window;
|
||||
class Event;
|
||||
}
|
||||
extern TVector2i cursor_pos;
|
||||
|
||||
struct TScreenRes {
|
||||
|
@ -32,17 +35,16 @@ struct TScreenRes {
|
|||
|
||||
class CWinsys {
|
||||
private:
|
||||
// joystick
|
||||
SDL_Joystick *joystick;
|
||||
size_t numJoysticks;
|
||||
bool joystick_active;
|
||||
|
||||
// sdl window
|
||||
TScreenRes resolutions[NUM_RESOLUTIONS];
|
||||
TScreenRes auto_resolution;
|
||||
SDL_Surface *screen;
|
||||
sf::ContextSettings ctx;
|
||||
double CalcScreenScale () const;
|
||||
public:
|
||||
sf::Window window;
|
||||
TScreenRes resolution;
|
||||
double scale; // scale factor for screen, see 'use_quad_scale'
|
||||
|
||||
|
@ -58,15 +60,14 @@ public:
|
|||
void KeyRepeat (bool repeat);
|
||||
void SetFonttype ();
|
||||
void PrintJoystickInfo () const;
|
||||
void ShowCursor (bool visible) {SDL_ShowCursor (visible);}
|
||||
void SwapBuffers () {SDL_GL_SwapBuffers ();}
|
||||
void ShowCursor(bool visible);
|
||||
void SwapBuffers();
|
||||
void Quit ();
|
||||
void Terminate ();
|
||||
void InitJoystick ();
|
||||
void CloseJoystick ();
|
||||
bool joystick_isActive() const { return joystick_active; }
|
||||
double ClockTime () const {return SDL_GetTicks() * 1.e-3; }
|
||||
unsigned char *GetSurfaceData () const;
|
||||
bool PollEvent(sf::Event& event);
|
||||
};
|
||||
|
||||
extern CWinsys Winsys;
|
||||
|
|
Loading…
Reference in New Issue