1) Added calls to new render functions which are
called during the irrlicht rendering, so calls to directly print etc. to the screen are possible. 2) Time and ready/set/go of the race gui now work. 3) Code cleanup. 4) Removed compiler warnings. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3740 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
be331b0ed5
commit
88b4b3b041
@ -493,6 +493,78 @@ void IrrDriver::setAmbientLight(const video::SColor &light)
|
||||
m_scene_manager->setAmbientLight(light);
|
||||
} // setAmbientLight
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Renders the bullet debug view using glut.
|
||||
*/
|
||||
void IrrDriver::renderBulletDebugView()
|
||||
{
|
||||
#ifdef HAVE_GLUT
|
||||
// Use bullets debug drawer
|
||||
GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 };
|
||||
GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
|
||||
GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
|
||||
/* light_position is NOT default value */
|
||||
GLfloat light_position0[] = { 1.0, 1.0, 1.0, 0.0 };
|
||||
GLfloat light_position1[] = { -1.0, -1.0, -1.0, 0.0 };
|
||||
|
||||
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
|
||||
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
|
||||
|
||||
glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient);
|
||||
glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
|
||||
glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular);
|
||||
glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
|
||||
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
glEnable(GL_LIGHT1);
|
||||
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_LESS);
|
||||
|
||||
glClearColor(0.8f,0.8f,0.8f,0);
|
||||
|
||||
glCullFace(GL_BACK);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
float f=2.0f;
|
||||
glFrustum(-f, f, -f, f, 1.0, 1000.0);
|
||||
|
||||
Vec3 xyz = RaceManager::getKart(race_manager->getNumKarts()-1)->getXYZ();
|
||||
gluLookAt(xyz.getX(), xyz.getY()-5.f, xyz.getZ()+4,
|
||||
xyz.getX(), xyz.getY(), xyz.getZ(),
|
||||
0.0f, 0.0f, 1.0f);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
for (unsigned int i = 0 ; i < race_manager->getNumKarts(); ++i)
|
||||
{
|
||||
Kart *kart=RaceManager::getKart((int)i);
|
||||
if(!kart->isEliminated()) kart->draw();
|
||||
}
|
||||
RaceManager::getWorld()->getPhysics()->draw();
|
||||
#endif
|
||||
} // renderBulletDebugView
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Displays the FPS on the screen.
|
||||
*/
|
||||
void IrrDriver::displayFPS()
|
||||
{
|
||||
gui::IGUIFont* font = getRaceFont();
|
||||
const int fps = m_device->getVideoDriver()->getFPS();
|
||||
|
||||
static char buffer[32];
|
||||
sprintf(buffer, "FPS : %i", fps);
|
||||
|
||||
core::stringw fpsString = buffer;
|
||||
|
||||
static video::SColor fpsColor = video::SColor(255, 255, 0, 0);
|
||||
font->draw( fpsString.c_str(), core::rect< s32 >(0,0,600,200), fpsColor, true );
|
||||
} // updateFPS
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Update, called once per frame.
|
||||
* \param dt Time since last update
|
||||
@ -502,96 +574,32 @@ void IrrDriver::update(float dt)
|
||||
if(!m_device->run()) return;
|
||||
|
||||
m_device->getVideoDriver()->beginScene(true, true, video::SColor(255,100,101,140));
|
||||
|
||||
if(!StateManager::isGameState())
|
||||
{
|
||||
// this code needs to go outside beginScene() / endScene() since
|
||||
// the model view widget will do off-screen rendering there
|
||||
const int updateAmount = GUIEngine::needsUpdate.size();
|
||||
for(int n=0; n<updateAmount; n++)
|
||||
|
||||
{ // just to mark the beding/end scene block
|
||||
if(!StateManager::isGameState())
|
||||
{
|
||||
GUIEngine::needsUpdate[n].update(dt);
|
||||
// this code needs to go outside beginScene() / endScene() since
|
||||
// the model view widget will do off-screen rendering there
|
||||
const int updateAmount = GUIEngine::needsUpdate.size();
|
||||
for(int n=0; n<updateAmount; n++)
|
||||
{
|
||||
GUIEngine::needsUpdate[n].update(dt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAVE_GLUT
|
||||
if(UserConfigParams::m_bullet_debug && race_manager->raceIsActive())
|
||||
{
|
||||
// Use bullets debug drawer
|
||||
GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 };
|
||||
GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
|
||||
GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
|
||||
/* light_position is NOT default value */
|
||||
GLfloat light_position0[] = { 1.0, 1.0, 1.0, 0.0 };
|
||||
GLfloat light_position1[] = { -1.0, -1.0, -1.0, 0.0 };
|
||||
|
||||
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
|
||||
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
|
||||
|
||||
glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient);
|
||||
glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
|
||||
glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular);
|
||||
glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
|
||||
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
glEnable(GL_LIGHT1);
|
||||
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_LESS);
|
||||
|
||||
glClearColor(0.8f,0.8f,0.8f,0);
|
||||
|
||||
glCullFace(GL_BACK);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
float f=2.0f;
|
||||
glFrustum(-f, f, -f, f, 1.0, 1000.0);
|
||||
|
||||
Vec3 xyz = RaceManager::getKart(race_manager->getNumKarts()-1)->getXYZ();
|
||||
gluLookAt(xyz.getX(), xyz.getY()-5.f, xyz.getZ()+4,
|
||||
xyz.getX(), xyz.getY(), xyz.getZ(),
|
||||
0.0f, 0.0f, 1.0f);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
for (unsigned int i = 0 ; i < race_manager->getNumKarts(); ++i)
|
||||
if(race_manager->raceIsActive())
|
||||
{
|
||||
Kart *kart=RaceManager::getKart((int)i);
|
||||
if(!kart->isEliminated()) kart->draw();
|
||||
if(UserConfigParams::m_bullet_debug) renderBulletDebugView();
|
||||
m_scene_manager->drawAll();
|
||||
RaceManager::getWorld()->render();
|
||||
}
|
||||
RaceManager::getWorld()->getPhysics()->draw();
|
||||
else // GUI is active
|
||||
GUIEngine::render(dt);
|
||||
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
m_scene_manager->drawAll();
|
||||
GUIEngine::render(dt);
|
||||
}
|
||||
|
||||
// draw FPS if enabled
|
||||
if ( UserConfigParams::m_display_fps )
|
||||
{
|
||||
// TODO : don't re-create string every frame
|
||||
video::IVideoDriver* driver = irr_driver->getDevice()->getVideoDriver();
|
||||
gui::IGUIFont* font = irr_driver->getRaceFont();
|
||||
const int fps = driver->getFPS();
|
||||
|
||||
static char buffer[32];
|
||||
sprintf(buffer, "FPS : %i", fps);
|
||||
|
||||
core::stringw fpsString = buffer;
|
||||
|
||||
//std::cout << "===== Drawing FPS " << fpsString.c_str() << "=====\n";
|
||||
|
||||
static video::SColor fpsColor = video::SColor(255, 255, 0, 0);
|
||||
font->draw( fpsString.c_str(), core::rect< s32 >(0,0,600,200), fpsColor, true );
|
||||
}
|
||||
|
||||
// draw FPS if enabled
|
||||
if ( UserConfigParams::m_display_fps ) displayFPS();
|
||||
|
||||
} // just to makr the begin/end scene block
|
||||
m_device->getVideoDriver()->endScene();
|
||||
|
||||
} // update
|
||||
|
@ -49,6 +49,8 @@ private:
|
||||
void setAllMaterialFlags(scene::IAnimatedMesh *mesh) const;
|
||||
std::vector<VideoMode> m_modes;
|
||||
|
||||
void renderBulletDebugView();
|
||||
void displayFPS();
|
||||
public:
|
||||
IrrDriver();
|
||||
~IrrDriver();
|
||||
@ -90,7 +92,9 @@ public:
|
||||
void showPointer();
|
||||
void hidePointer();
|
||||
|
||||
void renderToTexture(ptr_vector<scene::IMesh, REF>& mesh, std::vector<Vec3>& mesh_location, video::ITexture* target, float angle);
|
||||
void renderToTexture(ptr_vector<scene::IMesh, REF>& mesh,
|
||||
std::vector<Vec3>& mesh_location,
|
||||
video::ITexture* target, float angle);
|
||||
}; // IrrDriver
|
||||
|
||||
extern IrrDriver *irr_driver;
|
||||
|
@ -214,47 +214,47 @@ namespace StateManager
|
||||
// move x towards target
|
||||
if (x < target_x)
|
||||
{
|
||||
x += move_step*x_speed;
|
||||
x += (int)(move_step*x_speed);
|
||||
if (x > target_x) x = target_x; // don't move to the other side of the target
|
||||
}
|
||||
else if (x > target_x)
|
||||
{
|
||||
x -= move_step*x_speed;
|
||||
x -= (int)(move_step*x_speed);
|
||||
if (x < target_x) x = target_x; // don't move to the other side of the target
|
||||
}
|
||||
|
||||
// move y towards target
|
||||
if (y < target_y)
|
||||
{
|
||||
y += move_step*y_speed;
|
||||
y += (int)(move_step*y_speed);
|
||||
if (y > target_y) y = target_y; // don't move to the other side of the target
|
||||
}
|
||||
else if (y > target_y)
|
||||
{
|
||||
y -= move_step*y_speed;
|
||||
y -= (int)(move_step*y_speed);
|
||||
if (y < target_y) y = target_y; // don't move to the other side of the target
|
||||
}
|
||||
|
||||
// move w towards target
|
||||
if (w < target_w)
|
||||
{
|
||||
w += move_step*w_speed;
|
||||
w += (int)(move_step*w_speed);
|
||||
if (w > target_w) w = target_w; // don't move to the other side of the target
|
||||
}
|
||||
else if (w > target_w)
|
||||
{
|
||||
w -= move_step*w_speed;
|
||||
w -= (int)(move_step*w_speed);
|
||||
if (w < target_w) w = target_w; // don't move to the other side of the target
|
||||
}
|
||||
// move h towards target
|
||||
if (h < target_h)
|
||||
{
|
||||
h += move_step*h_speed;
|
||||
h += (int)(move_step*h_speed);
|
||||
if (h > target_h) h = target_h; // don't move to the other side of the target
|
||||
}
|
||||
else if (h > target_h)
|
||||
{
|
||||
h -= move_step*h_speed;
|
||||
h -= (int)(move_step*h_speed);
|
||||
if (h < target_h) h = target_h; // don't move to the other side of the target
|
||||
}
|
||||
|
||||
@ -329,9 +329,9 @@ namespace StateManager
|
||||
if (h < 175)
|
||||
{
|
||||
const float factor = h / 175.0f;
|
||||
kart_name_h *= factor;
|
||||
player_name_h *= factor;
|
||||
player_id_h *= factor;
|
||||
kart_name_h = (int)(kart_name_h*factor);
|
||||
player_name_h = (int)(player_name_h*factor);
|
||||
player_id_h = (int)(player_id_h*factor);
|
||||
}
|
||||
|
||||
// --- layout
|
||||
@ -345,9 +345,9 @@ namespace StateManager
|
||||
const int modelMaxWidth = w;
|
||||
const int bestSize = std::min(modelMaxWidth, modelMaxHeight);
|
||||
const int modelY = y + player_name_h + player_id_h;
|
||||
model_x = x + w/2 - bestSize*1.2/2;
|
||||
model_x = x + w/2 - (int)(bestSize*1.2f/2);
|
||||
model_y = modelY + modelMaxHeight/2 - bestSize/2;
|
||||
model_w = bestSize*1.2; // FIXME : for some reason, it looks better this way, though full square should be ok
|
||||
model_w = (int)(bestSize*1.2f); // FIXME : for some reason, it looks better this way, though full square should be ok
|
||||
model_h = bestSize;
|
||||
|
||||
kart_name_x = x;
|
||||
|
@ -344,7 +344,7 @@ void startGame()
|
||||
|
||||
StateManager::enterGameState();
|
||||
//race_manager->setDifficulty(RaceManager::RD_HARD);
|
||||
race_manager->setTrack("beach");
|
||||
race_manager->setTrack("lighthouse");
|
||||
race_manager->setNumLaps( 3 );
|
||||
race_manager->setCoinTarget( 0 ); // Might still be set from a previous challenge
|
||||
//race_manager->setNumKarts( 1 );
|
||||
|
@ -36,28 +36,6 @@
|
||||
#include "irrlicht.h"
|
||||
using namespace irr;
|
||||
|
||||
RaceGUI* instance = NULL;
|
||||
RaceGUI* getRaceGUI()
|
||||
{
|
||||
if(instance == NULL) instance = new RaceGUI();
|
||||
return instance;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Converts a time into a string.
|
||||
* \param time Time in seconds.
|
||||
* \param s Output string.
|
||||
*/
|
||||
void XXtimeToString(const double TIME, char *s)
|
||||
{
|
||||
int min = (int) floor ( TIME / 60.0 ) ;
|
||||
int sec = (int) floor ( TIME - (double) ( 60 * min ) ) ;
|
||||
int tenths = (int) floor ( 10.0f * (TIME - (double)(sec + 60* min)));
|
||||
sprintf ( s, "%d:%02d:%d", min, sec, tenths ) ;
|
||||
} // TimeToString
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
RaceGUI::RaceGUI()
|
||||
{
|
||||
// FIXME: translation problem
|
||||
@ -73,12 +51,7 @@ RaceGUI::RaceGUI()
|
||||
m_pos_string[9] = "9th";
|
||||
m_pos_string[10] = "10th";
|
||||
|
||||
#ifdef HAVE_IRRLICHT
|
||||
gui::IGUIEnvironment *gui_env = irr_driver->getGUI();
|
||||
core::rect<s32> pos(UserConfigParams::m_width-60, 10,
|
||||
UserConfigParams::m_width, 50);
|
||||
m_time = gui_env->addStaticText(L"", pos);
|
||||
m_time->setOverrideFont(irr_driver->getRaceFont());
|
||||
|
||||
int icon_width=40;
|
||||
int icon_player_width=50;
|
||||
@ -88,19 +61,7 @@ RaceGUI::RaceGUI()
|
||||
icon_player_width = 35;
|
||||
}
|
||||
|
||||
m_icons = new gui::IGUIImage*[race_manager->getNumKarts()];
|
||||
for(unsigned int i=0; i<race_manager->getNumKarts(); i++)
|
||||
{
|
||||
core::position2d<s32> p(0, i*20);
|
||||
Kart *kart = race_manager->getKart(i);
|
||||
Material *m = kart->getKartProperties()->getIconMaterial();
|
||||
// FIXME: The icons needs to be resized.
|
||||
m_icons[i] = irr_driver->getGUI()->addImage(m->getTexture(), p);
|
||||
}
|
||||
core::rect<s32> p(UserConfigParams::m_width-10, 0,
|
||||
UserConfigParams::m_width+10, 10);
|
||||
m_attachment_icon = irr_driver->getGUI()->addImage(p);
|
||||
#else
|
||||
#ifndef HAVE_IRRLICHT
|
||||
m_speed_back_icon = material_manager->getMaterial("speedback.rgb");
|
||||
m_speed_back_icon->getState()->disable(GL_CULL_FACE);
|
||||
m_speed_fore_icon = material_manager->getMaterial("speedfore.rgb");
|
||||
@ -110,12 +71,6 @@ RaceGUI::RaceGUI()
|
||||
m_plunger_face->getState()->disable(GL_CULL_FACE);
|
||||
#endif
|
||||
|
||||
m_fps_counter = 0;
|
||||
m_fps_string[0]=0;
|
||||
//m_fps_timer.reset();
|
||||
//m_fps_timer.update();
|
||||
//m_fps_timer.setMaxDelta(1000);
|
||||
|
||||
} // RaceGUI
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -125,25 +80,26 @@ RaceGUI::~RaceGUI()
|
||||
} // ~Racegui
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void RaceGUI::resetFPSCounter()
|
||||
{
|
||||
// TODO - FPS
|
||||
//m_fps_timer.reset();
|
||||
//m_fps_timer.setMaxDelta(1000);
|
||||
m_fps_counter=0;
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/** Called before rendering, so no direct output to the screen can be done
|
||||
* here.
|
||||
* \param dt Time step size.
|
||||
*/
|
||||
void RaceGUI::update(float dt)
|
||||
{
|
||||
drawStatusText(dt);
|
||||
cleanupMessages(dt);
|
||||
|
||||
//BaseGUI::update( dt );
|
||||
} // update
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Displays the racing time on the screen.
|
||||
/** Render the race gui. Direct access to the screen is possible here, since
|
||||
* this is called during irrlicht rendering.
|
||||
*/
|
||||
void RaceGUI::render()
|
||||
{
|
||||
drawStatusText();
|
||||
} // render
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Displays the racing time on the screen.s
|
||||
*/
|
||||
void RaceGUI::drawTimer ()
|
||||
{
|
||||
@ -151,12 +107,13 @@ void RaceGUI::drawTimer ()
|
||||
|
||||
if(!RaceManager::getWorld()->shouldDrawTimer()) return;
|
||||
std::string s = StringUtils::timeToString(RaceManager::getWorld()->getTime());
|
||||
#ifdef HAVE_IRRLICHT
|
||||
m_time->setText(core::stringw(s.c_str()).c_str());
|
||||
#else
|
||||
font_race->PrintShadow(str, 60, UserConfigParams::m_width-260,
|
||||
UserConfigParams::m_height-64);
|
||||
#endif
|
||||
core::stringw sw(s.c_str());
|
||||
|
||||
static video::SColor time_color = video::SColor(255, 255, 255, 255);
|
||||
core::rect<s32> pos(UserConfigParams::m_width-120, 10,
|
||||
UserConfigParams::m_width, 50);
|
||||
gui::IGUIFont* font = irr_driver->getRaceFont();
|
||||
font->draw(sw.c_str(), pos, time_color);
|
||||
} // drawTimer
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -326,7 +283,7 @@ void RaceGUI::drawPowerupIcons ( Kart* player_kart, int offset_x,
|
||||
|
||||
int nSize=(int)(64.0f*std::min(ratio_x, ratio_y));
|
||||
#ifdef HAVE_IRRLICHT
|
||||
m_attachment_icon->setImage(powerup->getIcon()->getTexture());
|
||||
// m_attachment_icon->setImage(powerup->getIcon()->getTexture());
|
||||
#else
|
||||
powerup->getIcon()->apply();
|
||||
|
||||
@ -682,58 +639,42 @@ void RaceGUI::drawMusicDescription()
|
||||
} // drawMusicDescription
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void RaceGUI::drawStatusText(const float dt)
|
||||
void RaceGUI::drawStatusText()
|
||||
{
|
||||
assert(RaceManager::getWorld() != NULL);
|
||||
|
||||
glMatrixMode ( GL_MODELVIEW ) ;
|
||||
glPushMatrix () ;
|
||||
glLoadIdentity () ;
|
||||
|
||||
glMatrixMode ( GL_PROJECTION ) ;
|
||||
glPushMatrix () ;
|
||||
glLoadIdentity () ;
|
||||
|
||||
glPushAttrib ( GL_ENABLE_BIT | GL_LIGHTING_BIT ) ;
|
||||
glDisable ( GL_DEPTH_TEST );
|
||||
glDisable ( GL_LIGHTING );
|
||||
glDisable ( GL_FOG );
|
||||
glDisable ( GL_CULL_FACE );
|
||||
glEnable ( GL_ALPHA_TEST );
|
||||
glAlphaFunc ( GL_GREATER, 0.1f);
|
||||
glEnable ( GL_BLEND );
|
||||
|
||||
glOrtho ( 0, UserConfigParams::m_width, 0, UserConfigParams::m_height, 0, 100 ) ;
|
||||
switch (RaceManager::getWorld()->getPhase())
|
||||
{
|
||||
case READY_PHASE:
|
||||
{
|
||||
GLfloat const COLORS[] = { 0.9f, 0.66f, 0.62f, 1.0f };
|
||||
static video::SColor color = video::SColor(255, 230, 168, 158);
|
||||
core::rect<s32> pos(UserConfigParams::m_width>>1, UserConfigParams::m_height>>1,
|
||||
UserConfigParams::m_width>>1, UserConfigParams::m_height>>1);
|
||||
gui::IGUIFont* font = irr_driver->getRaceFont();
|
||||
//I18N: as in "ready, set, go", shown at the beginning of the race
|
||||
font_race->PrintShadow( _("Ready!"), 90,
|
||||
Font::CENTER_OF_SCREEN,
|
||||
Font::CENTER_OF_SCREEN,
|
||||
COLORS );
|
||||
core::stringw s=_("Ready!");
|
||||
font->draw(s.c_str(), pos, color, true, true);
|
||||
}
|
||||
break;
|
||||
case SET_PHASE:
|
||||
{
|
||||
GLfloat const COLORS[] = { 0.9f, 0.9f, 0.62f, 1.0f };
|
||||
static video::SColor color = video::SColor(255, 230, 230, 158);
|
||||
core::rect<s32> pos(UserConfigParams::m_width>>1, UserConfigParams::m_height>>1,
|
||||
UserConfigParams::m_width>>1, UserConfigParams::m_height>>1);
|
||||
gui::IGUIFont* font = irr_driver->getRaceFont();
|
||||
//I18N: as in "ready, set, go", shown at the beginning of the race
|
||||
font_race->PrintShadow( _("Set!"), 90,
|
||||
Font::CENTER_OF_SCREEN,
|
||||
Font::CENTER_OF_SCREEN,
|
||||
COLORS );
|
||||
core::stringw s=_("Set!");
|
||||
font->draw(s.c_str(), pos, color, true, true);
|
||||
}
|
||||
break;
|
||||
case GO_PHASE:
|
||||
{
|
||||
GLfloat const COLORS[] = { 0.39f, 0.82f, 0.39f, 1.0f };
|
||||
static video::SColor color = video::SColor(255, 100, 209, 100);
|
||||
core::rect<s32> pos(UserConfigParams::m_width>>1, UserConfigParams::m_height>>1,
|
||||
UserConfigParams::m_width>>1, UserConfigParams::m_height>>1);
|
||||
gui::IGUIFont* font = irr_driver->getRaceFont();
|
||||
//I18N: as in "ready, set, go", shown at the beginning of the race
|
||||
font_race->PrintShadow( _("Go!"), 90,
|
||||
Font::CENTER_OF_SCREEN,
|
||||
Font::CENTER_OF_SCREEN,
|
||||
COLORS );
|
||||
core::stringw s=_("Go!");
|
||||
font->draw(s.c_str(), pos, color, true, true);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -744,9 +685,10 @@ void RaceGUI::drawStatusText(const float dt)
|
||||
{
|
||||
if(RaceManager::getWorld()->m_debug_text[i] != "")
|
||||
{
|
||||
GLfloat const COLORS[] = { 0.39f, 0.82f, 0.39f, 1.0f };
|
||||
font_race->Print( RaceManager::getWorld()->m_debug_text[i].c_str(),
|
||||
20, 20, 200 -i*20, COLORS );
|
||||
static video::SColor color = video::SColor(255, 100, 209, 100);
|
||||
core::rect<s32> pos(20, i*20, 20, (i+1)*20);
|
||||
gui::IGUIFont* font = irr_driver->getRaceFont();
|
||||
font->draw(RaceManager::getWorld()->m_debug_text[i].c_str(), pos, color);
|
||||
}
|
||||
}
|
||||
|
||||
@ -760,111 +702,103 @@ void RaceGUI::drawStatusText(const float dt)
|
||||
// The penalty message needs to be displayed for up to one second
|
||||
// after the start of the race, otherwise it disappears if
|
||||
// "Go" is displayed and the race starts
|
||||
const unsigned int num_players = race_manager->getNumLocalPlayers();
|
||||
if(RaceManager::getWorld()->isStartPhase() || RaceManager::getWorld()->getTime()<1.0f)
|
||||
{
|
||||
for(unsigned int i=0; i<race_manager->getNumLocalPlayers(); i++)
|
||||
for(unsigned int i=0; i<num_players; i++)
|
||||
{
|
||||
if(RaceManager::getWorld()->getLocalPlayerKart(i)->earlyStartPenalty())
|
||||
{
|
||||
GLfloat const COLORS[] = { 0.78f, 0.025f, 0.025f, 1.0f };
|
||||
|
||||
font_race->PrintShadow( _("Penalty time!!"), 80,
|
||||
Font::CENTER_OF_SCREEN, 200,
|
||||
COLORS );
|
||||
static video::SColor color = video::SColor(255, 179, 6, 6);
|
||||
// FIXME: the position should take split screen into account!
|
||||
core::rect<s32> pos(UserConfigParams::m_width>>1, (UserConfigParams::m_height>>1)-40,
|
||||
UserConfigParams::m_width>>1, (UserConfigParams::m_height>>1)-40);
|
||||
gui::IGUIFont* font = irr_driver->getRaceFont();
|
||||
core::stringw s=_("Penalty time!!");
|
||||
font->draw(s.c_str(), pos, color, true, true);
|
||||
} // if penalty
|
||||
} // for i < getNumPlayers
|
||||
} // for i < getNum_players
|
||||
} // if not RACE_PHASE
|
||||
|
||||
|
||||
if ( RaceManager::getWorld()->isRacePhase() )
|
||||
if(!RaceManager::getWorld()->isRacePhase()) return;
|
||||
|
||||
|
||||
KartIconDisplayInfo* info = RaceManager::getWorld()->getKartsDisplayInfo();
|
||||
|
||||
for(int pla = 0; pla < num_players; pla++)
|
||||
{
|
||||
KartIconDisplayInfo* info = RaceManager::getWorld()->getKartsDisplayInfo(this);
|
||||
|
||||
const int numPlayers = race_manager->getNumLocalPlayers();
|
||||
int offset_x = 0, offset_y = 0;
|
||||
|
||||
for(int pla = 0; pla < numPlayers; pla++)
|
||||
if(num_players == 2)
|
||||
{
|
||||
int offset_x = 0, offset_y = 0;
|
||||
|
||||
if(numPlayers == 2)
|
||||
{
|
||||
if(pla == 0) offset_y = UserConfigParams::m_height/2;
|
||||
}
|
||||
else if (numPlayers == 3)
|
||||
{
|
||||
if (pla == 0 || pla == 1)
|
||||
if(pla == 0) offset_y = UserConfigParams::m_height/2;
|
||||
}
|
||||
else if (num_players == 3)
|
||||
{
|
||||
if (pla == 0 || pla == 1)
|
||||
offset_y = UserConfigParams::m_height/2;
|
||||
else
|
||||
{
|
||||
else
|
||||
{
|
||||
// Fixes width for player 3
|
||||
split_screen_ratio_x = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
if (pla == 1)
|
||||
if (pla == 1)
|
||||
offset_x = UserConfigParams::m_width/2;
|
||||
|
||||
}
|
||||
else if(numPlayers == 4)
|
||||
{
|
||||
if(pla == 0 || pla == 1)
|
||||
}
|
||||
else if(num_players == 4)
|
||||
{
|
||||
if(pla == 0 || pla == 1)
|
||||
offset_y = UserConfigParams::m_height/2;
|
||||
|
||||
if((pla == 1) || pla == 3)
|
||||
if((pla == 1) || pla == 3)
|
||||
offset_x = UserConfigParams::m_width/2;
|
||||
}
|
||||
|
||||
Kart* player_kart = RaceManager::getWorld()->getLocalPlayerKart(pla);
|
||||
drawPowerupIcons(player_kart, offset_x, offset_y,
|
||||
split_screen_ratio_x, split_screen_ratio_y );
|
||||
drawEnergyMeter (player_kart, offset_x, offset_y,
|
||||
split_screen_ratio_x, split_screen_ratio_y );
|
||||
drawSpeed (player_kart, offset_x, offset_y,
|
||||
split_screen_ratio_x, split_screen_ratio_y );
|
||||
drawLap (info, player_kart, offset_x, offset_y,
|
||||
split_screen_ratio_x, split_screen_ratio_y );
|
||||
drawAllMessages (player_kart, offset_x, offset_y,
|
||||
split_screen_ratio_x, split_screen_ratio_y );
|
||||
|
||||
if(player_kart->hasViewBlockedByPlunger())
|
||||
{
|
||||
const int screen_width = (numPlayers > 2) ? UserConfigParams::m_width/2 : UserConfigParams::m_width;
|
||||
const int plunger_size = (numPlayers > 1) ? UserConfigParams::m_height/2 : UserConfigParams::m_height;
|
||||
int plunger_x = offset_x + screen_width/2 - plunger_size/2;
|
||||
|
||||
if (numPlayers == 3 && pla > 1)
|
||||
plunger_x = offset_x + UserConfigParams::m_width/2 - plunger_size/2;
|
||||
|
||||
#ifndef HAVE_IRRLICHT
|
||||
m_plunger_face->getState()->force();
|
||||
#endif
|
||||
glBegin ( GL_QUADS ) ;
|
||||
glTexCoord2f(1, 0); glVertex2i(plunger_x+plunger_size, offset_y);
|
||||
glTexCoord2f(0, 0); glVertex2i(plunger_x, offset_y);
|
||||
glTexCoord2f(0, 1); glVertex2i(plunger_x, offset_y+plunger_size);
|
||||
glTexCoord2f(1, 1); glVertex2i(plunger_x+plunger_size, offset_y+plunger_size);
|
||||
glEnd () ;
|
||||
}
|
||||
} // next player
|
||||
|
||||
drawTimer();
|
||||
|
||||
if(RaceManager::getWorld()->getPhase() == GO_PHASE ||
|
||||
RaceManager::getWorld()->getPhase() == MUSIC_PHASE)
|
||||
{
|
||||
drawMusicDescription();
|
||||
}
|
||||
|
||||
|
||||
drawMap();
|
||||
|
||||
drawPlayerIcons(info);
|
||||
|
||||
} // if RACE_PHASE
|
||||
Kart* player_kart = RaceManager::getWorld()->getLocalPlayerKart(pla);
|
||||
// drawPowerupIcons(player_kart, offset_x, offset_y,
|
||||
// split_screen_ratio_x, split_screen_ratio_y );
|
||||
// drawEnergyMeter (player_kart, offset_x, offset_y,
|
||||
// split_screen_ratio_x, split_screen_ratio_y );
|
||||
// drawSpeed (player_kart, offset_x, offset_y,
|
||||
// split_screen_ratio_x, split_screen_ratio_y );
|
||||
// drawLap (info, player_kart, offset_x, offset_y,
|
||||
// split_screen_ratio_x, split_screen_ratio_y );
|
||||
// drawAllMessages (player_kart, offset_x, offset_y,
|
||||
// split_screen_ratio_x, split_screen_ratio_y );
|
||||
|
||||
if(player_kart->hasViewBlockedByPlunger())
|
||||
{
|
||||
const int screen_width = (num_players > 2) ? UserConfigParams::m_width/2 : UserConfigParams::m_width;
|
||||
const int plunger_size = (num_players > 1) ? UserConfigParams::m_height/2 : UserConfigParams::m_height;
|
||||
int plunger_x = offset_x + screen_width/2 - plunger_size/2;
|
||||
|
||||
if (num_players == 3 && pla > 1)
|
||||
plunger_x = offset_x + UserConfigParams::m_width/2 - plunger_size/2;
|
||||
|
||||
#ifndef HAVE_IRRLICHT
|
||||
m_plunger_face->getState()->force();
|
||||
#endif
|
||||
glBegin ( GL_QUADS ) ;
|
||||
glTexCoord2f(1, 0); glVertex2i(plunger_x+plunger_size, offset_y);
|
||||
glTexCoord2f(0, 0); glVertex2i(plunger_x, offset_y);
|
||||
glTexCoord2f(0, 1); glVertex2i(plunger_x, offset_y+plunger_size);
|
||||
glTexCoord2f(1, 1); glVertex2i(plunger_x+plunger_size, offset_y+plunger_size);
|
||||
glEnd () ;
|
||||
}
|
||||
} // next player
|
||||
|
||||
drawTimer();
|
||||
|
||||
if(RaceManager::getWorld()->getPhase() == GO_PHASE ||
|
||||
RaceManager::getWorld()->getPhase() == MUSIC_PHASE)
|
||||
{
|
||||
drawMusicDescription();
|
||||
}
|
||||
|
||||
//drawMap();
|
||||
//drawPlayerIcons(info);
|
||||
|
||||
glPopAttrib () ;
|
||||
glPopMatrix () ;
|
||||
glMatrixMode ( GL_MODELVIEW ) ;
|
||||
glPopMatrix () ;
|
||||
} // drawStatusText
|
||||
|
||||
/* EOF */
|
||||
|
@ -52,9 +52,6 @@ struct KartIconDisplayInfo
|
||||
int lap;
|
||||
};
|
||||
|
||||
extern RaceGUI* getRaceGUI();
|
||||
void timeToString(const double TIME, char *s);
|
||||
|
||||
class RaceGUI
|
||||
{
|
||||
private:
|
||||
@ -92,14 +89,6 @@ private:
|
||||
};
|
||||
|
||||
private:
|
||||
#ifdef HAVE_IRRLICHT
|
||||
gui::IGUIStaticText *m_time;
|
||||
gui::IGUIImage **m_icons;
|
||||
gui::IGUIImage *m_attachment_icon;
|
||||
#endif
|
||||
//ulClock m_fps_timer;
|
||||
int m_fps_counter;
|
||||
char m_fps_string[10];
|
||||
const char *m_pos_string [11];
|
||||
Material *m_speed_back_icon;
|
||||
Material *m_speed_fore_icon;
|
||||
@ -108,7 +97,7 @@ private:
|
||||
AllMessageType m_messages;
|
||||
|
||||
/* Display informat on screen */
|
||||
void drawStatusText (const float dt);
|
||||
void drawStatusText ();
|
||||
void drawEnergyMeter (Kart *player_kart,
|
||||
int offset_x, int offset_y,
|
||||
float ratio_x, float ratio_y );
|
||||
@ -130,15 +119,13 @@ private:
|
||||
int offset_y, float ratio_x, float ratio_y );
|
||||
public:
|
||||
|
||||
RaceGUI();
|
||||
~RaceGUI();
|
||||
RaceGUI();
|
||||
~RaceGUI();
|
||||
void render();
|
||||
void update(float dt);
|
||||
void select() {}
|
||||
void handleKartAction(PlayerAction ka, int value);
|
||||
void addMessage(const std::string &m, const Kart *kart, float time,
|
||||
int fonst_size, int red=255, int green=0, int blue=255);
|
||||
|
||||
void resetFPSCounter();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -33,7 +33,6 @@
|
||||
#include "gui/state_manager.hpp"
|
||||
#include "gui/modaldialog.hpp"
|
||||
#include "gui/engine.hpp"
|
||||
#include "gui/race_gui.hpp"
|
||||
#include "gui/screen.hpp"
|
||||
#include "input/device_manager.hpp"
|
||||
#include "input/input.hpp"
|
||||
@ -129,10 +128,6 @@ void InputManager::handleStaticAction(int key, int value)
|
||||
#endif
|
||||
case KEY_F12:
|
||||
UserConfigParams::m_display_fps = !UserConfigParams::m_display_fps;
|
||||
if(UserConfigParams::m_display_fps)
|
||||
{
|
||||
getRaceGUI()->resetFPSCounter();
|
||||
}
|
||||
break;
|
||||
case KEY_F11:
|
||||
glPolygonMode(GL_FRONT_AND_BACK, isWireframe ? GL_FILL : GL_LINE);
|
||||
|
@ -27,7 +27,6 @@
|
||||
#include "items/projectile_manager.hpp"
|
||||
#include "karts/kart.hpp"
|
||||
#include "modes/world.hpp"
|
||||
#include "modes/linear_world.hpp"
|
||||
#include "network/flyable_info.hpp"
|
||||
#include "race/race_manager.hpp"
|
||||
#include "tracks/track.hpp"
|
||||
|
@ -54,6 +54,95 @@ MainLoop::~MainLoop()
|
||||
{
|
||||
} // ~MainLoop
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Returns the current dt, which guarantees a limited frame rate. If dt is
|
||||
* too low (the frame rate too high), the process will sleep to reach the
|
||||
* maxium frame rate.
|
||||
*/
|
||||
float MainLoop::getLimitedDt()
|
||||
{
|
||||
IrrlichtDevice* device = irr_driver->getDevice();
|
||||
m_prev_time = m_curr_time;
|
||||
|
||||
float dt; // needed outside of the while loop
|
||||
while( 1 )
|
||||
{
|
||||
m_curr_time = device->getTimer()->getRealTime();
|
||||
dt = (float)(m_curr_time - m_prev_time);
|
||||
|
||||
// don't allow the game to run slower than a certain amount.
|
||||
// when the computer can't keep it up, slow down the shown time instead
|
||||
static const float max_elapsed_time = 3.0f*1.0f/60.0f*1000.0f; /* time 3 internal substeps take */
|
||||
if(dt > max_elapsed_time) dt=max_elapsed_time;
|
||||
|
||||
// Throttle fps if more than maximum, which can reduce
|
||||
// the noise the fan on a graphics card makes.
|
||||
// When in menus, reduce FPS much, it's not necessary to push to the maximum for plain menus
|
||||
const int max_fps = StateManager::isGameState() ? UserConfigParams::m_max_fps : 35;
|
||||
const int current_fps = (int)(1000.0f/dt);
|
||||
if( current_fps > max_fps )
|
||||
{
|
||||
int wait_time = 1000/max_fps - 1000/current_fps;
|
||||
if(wait_time < 1) wait_time = 1;
|
||||
|
||||
irr_driver->getDevice()->sleep(wait_time);
|
||||
}
|
||||
else break;
|
||||
}
|
||||
dt *= 0.001f;
|
||||
return dt;
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Updates the profiling frame counter, and if the end of the profiling
|
||||
* period is reached prints the results and aborts STK.
|
||||
*/
|
||||
void MainLoop::updateProfiling()
|
||||
{
|
||||
m_frame_count++;
|
||||
if (RaceManager::getWorld()->getTime()>UserConfigParams::m_profile)
|
||||
{
|
||||
IrrlichtDevice* device = irr_driver->getDevice();
|
||||
printf("Number of frames: %d time %f, Average FPS: %f\n",
|
||||
m_frame_count, device->getTimer()->getRealTime()*0.001,
|
||||
(float)m_frame_count/(device->getTimer()->getRealTime()));
|
||||
if(!history->replayHistory()) history->Save();
|
||||
std::exit(-2);
|
||||
} // if profile finished
|
||||
} // updateProfiling
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Updates all race related objects.
|
||||
* \param dt Time step size.
|
||||
*/
|
||||
void MainLoop::updateRace(float dt)
|
||||
{
|
||||
// Server: Send the current position and previous controls to all clients
|
||||
// Client: send current controls to server
|
||||
// But don't do this if the race is in finish phase (otherwise
|
||||
// messages can be mixed up in the race manager)
|
||||
if(!race_manager->getWorld()->isFinishPhase())
|
||||
network_manager->sendUpdates();
|
||||
if(UserConfigParams::m_profile) dt=1.0f/60.0f;
|
||||
// In the first call dt might be large (includes loading time),
|
||||
// which can cause the camera to significantly tilt
|
||||
stk_scene->draw(RaceManager::getWorld()->getPhase()==SETUP_PHASE ? 0.0f : dt);
|
||||
|
||||
// Again, only receive updates if the race isn't over - once the
|
||||
// race results are displayed (i.e. game is in finish phase)
|
||||
// messages must be handled by the normal update of the network
|
||||
// manager
|
||||
if(!race_manager->getWorld()->isFinishPhase())
|
||||
network_manager->receiveUpdates();
|
||||
|
||||
if ( RaceManager::getWorld()->getPhase() != LIMBO_PHASE)
|
||||
{
|
||||
history->update(dt);
|
||||
RaceManager::getWorld()->update(dt);
|
||||
|
||||
if(UserConfigParams::m_profile>0) updateProfiling();
|
||||
} // phase != limbo phase
|
||||
} // updateRace
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Run the actual main loop.
|
||||
*/
|
||||
@ -63,38 +152,10 @@ void MainLoop::run()
|
||||
|
||||
bool music_on = false;
|
||||
m_curr_time = device->getTimer()->getRealTime();
|
||||
float dt;
|
||||
while(!m_abort)
|
||||
{
|
||||
// input_manager->input();
|
||||
|
||||
m_prev_time = m_curr_time;
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
m_curr_time = device->getTimer()->getRealTime();
|
||||
dt = (float)(m_curr_time - m_prev_time);
|
||||
|
||||
// don't allow the game to run slower than a certain amount.
|
||||
// when the computer can't keep it up, slow down the shown time instead
|
||||
static const float max_elapsed_time = 3.0f*1.0f/60.0f*1000.0f; /* time 3 internal substeps take */
|
||||
if(dt > max_elapsed_time) dt=max_elapsed_time;
|
||||
|
||||
// Throttle fps if more than maximum, which can reduce
|
||||
// the noise the fan on a graphics card makes.
|
||||
// When in menus, reduce FPS much, it's not necessary to push to the maximum for plain menus
|
||||
const int max_fps = StateManager::isGameState() ? UserConfigParams::m_max_fps : 35;
|
||||
const int current_fps = (int)(1000.0f/dt);
|
||||
if( current_fps > max_fps )
|
||||
{
|
||||
int wait_time = 1000/max_fps - 1000/current_fps;
|
||||
if(wait_time < 1) wait_time = 1;
|
||||
|
||||
irr_driver->getDevice()->sleep(wait_time);
|
||||
}
|
||||
else break;
|
||||
}
|
||||
dt *= 0.001f;
|
||||
float dt = getLimitedDt();
|
||||
|
||||
if (!music_on && !race_manager->raceIsActive())
|
||||
{
|
||||
@ -102,7 +163,6 @@ void MainLoop::run()
|
||||
sound_manager->startMusic(stk_config->m_title_music);
|
||||
music_on = true;
|
||||
}
|
||||
|
||||
network_manager->update(dt);
|
||||
|
||||
if (race_manager->raceIsActive())
|
||||
@ -110,125 +170,15 @@ void MainLoop::run()
|
||||
// Busy wait if race_manager is active (i.e. creating of world is done)
|
||||
// till all clients have reached this state.
|
||||
if(network_manager->getState()==NetworkManager::NS_READY_SET_GO_BARRIER) continue;
|
||||
|
||||
// Server: Send the current position and previous controls to all clients
|
||||
// Client: send current controls to server
|
||||
// But don't do this if the race is in finish phase (otherwise
|
||||
// messages can be mixed up in the race manager)
|
||||
if(!race_manager->getWorld()->isFinishPhase())
|
||||
network_manager->sendUpdates();
|
||||
updateRace(dt);
|
||||
music_on = false;
|
||||
if(UserConfigParams::m_profile) dt=1.0f/60.0f;
|
||||
// In the first call dt might be large (includes loading time),
|
||||
// which can cause the camera to significantly tilt
|
||||
stk_scene->draw(RaceManager::getWorld()->getPhase()==SETUP_PHASE ? 0.0f : dt);
|
||||
|
||||
// Again, only receive updates if the race isn't over - once the
|
||||
// race results are displayed (i.e. game is in finish phase)
|
||||
// messages must be handled by the normal update of the network
|
||||
// manager
|
||||
if(!race_manager->getWorld()->isFinishPhase())
|
||||
network_manager->receiveUpdates();
|
||||
|
||||
if ( RaceManager::getWorld()->getPhase() != LIMBO_PHASE)
|
||||
{
|
||||
history->update(dt);
|
||||
RaceManager::getWorld()->update(dt);
|
||||
|
||||
if(UserConfigParams::m_profile>0)
|
||||
{
|
||||
m_frame_count++;
|
||||
if (RaceManager::getWorld()->getTime()>UserConfigParams::m_profile)
|
||||
{
|
||||
//FIXME: SDL_GetTicks() includes the loading time,
|
||||
//so the FPS will be skewed for now.
|
||||
printf("Number of frames: %d time %f, Average FPS: %f\n",
|
||||
m_frame_count, device->getTimer()->getRealTime()*0.001,
|
||||
(float)m_frame_count/(device->getTimer()->getRealTime()));
|
||||
if(!history->replayHistory()) history->Save();
|
||||
std::exit(-2);
|
||||
} // if profile finished
|
||||
} // if m_profile
|
||||
} // phase != limbo phase
|
||||
} // if race is active
|
||||
else
|
||||
{
|
||||
glMatrixMode ( GL_PROJECTION ) ;
|
||||
glLoadIdentity () ;
|
||||
glMatrixMode ( GL_MODELVIEW ) ;
|
||||
glLoadIdentity () ;
|
||||
glDisable ( GL_DEPTH_TEST ) ;
|
||||
glDisable ( GL_LIGHTING ) ;
|
||||
glDisable ( GL_FOG ) ;
|
||||
glDisable ( GL_CULL_FACE ) ;
|
||||
glDisable ( GL_ALPHA_TEST ) ;
|
||||
glEnable ( GL_TEXTURE_2D ) ;
|
||||
|
||||
// On at least one platform the X server apparently gets overloaded
|
||||
// by the large texture, resulting in buffering of key events. This
|
||||
// results in the menu being very unresponsive/slow - it can sometimes
|
||||
// take (say) half a second before the menu reacts to a pressed key.
|
||||
// This is caused by X buffering the key events, delivering them
|
||||
// later (and sometimes even several at the same frame). This issue
|
||||
// could either be solved by a lazy drawing of the background picture
|
||||
// (i.e. draw the background only if something has changed) - which is
|
||||
// a lot of implementation work ... or by sleeping for a little while,
|
||||
// which apparently reduces the load for the X server, so that no
|
||||
// buffering is done --> all key events are handled in time.
|
||||
#if !defined(WIN32) && !defined(__CYGWIN__)
|
||||
// usleep(2000);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
//Draw the splash screen
|
||||
/*
|
||||
if(menu_manager->isMainMenuActive())
|
||||
glBindTexture(GL_TEXTURE_2D, m_title_screen_texture);
|
||||
else
|
||||
glBindTexture(GL_TEXTURE_2D, m_bg_texture);
|
||||
*/
|
||||
glBegin ( GL_QUADS ) ;
|
||||
glColor3f (1, 1, 1 ) ;
|
||||
glTexCoord2f(0, 0); glVertex2i(-1, -1);
|
||||
glTexCoord2f(1, 0); glVertex2i( 1, -1);
|
||||
glTexCoord2f(1, 1); glVertex2i( 1, 1);
|
||||
glTexCoord2f(0, 1); glVertex2i(-1, 1);
|
||||
glEnd () ;
|
||||
}
|
||||
|
||||
sound_manager->update(dt);
|
||||
|
||||
input_manager->update(dt);
|
||||
|
||||
irr_driver->update(dt);
|
||||
|
||||
// FIXME hacky hacky FPS reporting
|
||||
// it should be moved to the right place when on screen display is done
|
||||
#if 0
|
||||
int fps = irr_driver->getDevice()->getVideoDriver()->getFPS();
|
||||
bool printFPS = false;
|
||||
// First reports seem to be always 1, so not useful
|
||||
if ((race_manager->raceIsActive()) && (fps > 1)) {
|
||||
// More than +-5 range is interesting to report (otherwise noise)
|
||||
if ((lastFPS+5 <= fps) || (lastFPS-5 >= fps)) {
|
||||
lastFPS = fps;
|
||||
printFPS = true;
|
||||
}
|
||||
// Min and max are worth updating any time they happen
|
||||
if (fps < minFPS) {
|
||||
minFPS = fps;
|
||||
printFPS = true;
|
||||
}
|
||||
if (fps > maxFPS) {
|
||||
maxFPS = fps;
|
||||
printFPS = true;
|
||||
}
|
||||
} // no else, or you get over 50 'printf ("FPS below 1!\n")' easily
|
||||
if (printFPS) printf("FPS %3d<%3d<%3d\n", minFPS, fps, maxFPS);
|
||||
#endif
|
||||
} // while !m_exit
|
||||
|
||||
} // run
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -42,15 +42,14 @@ private:
|
||||
int m_frame_count;
|
||||
Uint32 m_curr_time;
|
||||
Uint32 m_prev_time;
|
||||
// GLuint m_title_screen_texture;
|
||||
// GLuint m_bg_texture;
|
||||
|
||||
float getLimitedDt();
|
||||
void updateRace(float dt);
|
||||
void updateProfiling();
|
||||
public:
|
||||
MainLoop();
|
||||
~MainLoop();
|
||||
void run();
|
||||
void abort();
|
||||
// void loadBackgroundImages();
|
||||
}; // MainLoop
|
||||
|
||||
extern MainLoop* main_loop;
|
||||
|
@ -135,9 +135,9 @@ std::string FollowTheLeaderRace::getInternalCode() const
|
||||
return "FOLLOW_LEADER";
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
KartIconDisplayInfo* FollowTheLeaderRace::getKartsDisplayInfo(const RaceGUI* caller)
|
||||
KartIconDisplayInfo* FollowTheLeaderRace::getKartsDisplayInfo()
|
||||
{
|
||||
LinearWorld::getKartsDisplayInfo(caller);
|
||||
LinearWorld::getKartsDisplayInfo();
|
||||
m_kart_display_info[0].special_title = _("Leader");
|
||||
return m_kart_display_info;
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public:
|
||||
virtual void restartRace();
|
||||
virtual std::string getInternalCode() const;
|
||||
virtual bool useFastMusicNearEnd() const { return false; }
|
||||
virtual KartIconDisplayInfo* getKartsDisplayInfo(const RaceGUI* caller);
|
||||
virtual KartIconDisplayInfo* getKartsDisplayInfo();
|
||||
|
||||
virtual bool raceHasLaps(){ return false; }
|
||||
|
||||
|
@ -250,18 +250,14 @@ void LinearWorld::newLap(unsigned int kart_index)
|
||||
if(time_per_lap < getFastestLapTime() && raceHasLaps())
|
||||
{
|
||||
setFastestLap(kart, time_per_lap);
|
||||
RaceGUI* m=(RaceGUI*)getRaceGUI();
|
||||
if(m)
|
||||
{
|
||||
m->addMessage(_("New fastest lap"), NULL,
|
||||
2.0f, 40, 100, 210, 100);
|
||||
std::string s = StringUtils::timeToString(time_per_lap);
|
||||
m_race_gui->addMessage(_("New fastest lap"), NULL,
|
||||
2.0f, 40, 100, 210, 100);
|
||||
std::string s = StringUtils::timeToString(time_per_lap);
|
||||
|
||||
std::ostringstream m_fastest_lap_message;
|
||||
m_fastest_lap_message << s << ": " << kart->getName();
|
||||
m->addMessage(m_fastest_lap_message.str(), NULL,
|
||||
2.0f, 40, 100, 210, 100);
|
||||
} // if m
|
||||
std::ostringstream m_fastest_lap_message;
|
||||
m_fastest_lap_message << s << ": " << kart->getName();
|
||||
m_race_gui->addMessage(m_fastest_lap_message.str(), NULL,
|
||||
2.0f, 40, 100, 210, 100);
|
||||
} // end if new fastest lap
|
||||
}
|
||||
kart_info.m_lap_start_time = getTime();
|
||||
@ -314,7 +310,7 @@ float LinearWorld::getTimeAtLapForKart(const int kart_id) const
|
||||
} // getTimeAtLapForKart
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
KartIconDisplayInfo* LinearWorld::getKartsDisplayInfo(const RaceGUI* caller)
|
||||
KartIconDisplayInfo* LinearWorld::getKartsDisplayInfo()
|
||||
{
|
||||
int laps_of_leader = -1;
|
||||
float time_of_leader = -1;
|
||||
@ -565,10 +561,8 @@ void LinearWorld::checkForWrongDirection(unsigned int i)
|
||||
if(!m_kart[i]->isPlayerKart()) return;
|
||||
if(!m_kart_info[i].m_on_road) return;
|
||||
|
||||
RaceGUI* m = getRaceGUI();
|
||||
// This can happen if the option menu is called, since the
|
||||
// racegui gets deleted
|
||||
if(!m) return;
|
||||
// FIXME: Don't do this if the in-game option menu is on the screen!
|
||||
// if(option_menu) return;
|
||||
|
||||
const Kart *kart=m_kart[i];
|
||||
// If the kart can go in more than one directions from the current track
|
||||
@ -589,7 +583,7 @@ void LinearWorld::checkForWrongDirection(unsigned int i)
|
||||
kart->getVelocityLC().getY() > 0.0f &&
|
||||
!kart->hasFinishedRace() )
|
||||
{
|
||||
m->addMessage(_("WRONG WAY!"), kart, -1.0f, 60);
|
||||
m_race_gui->addMessage(_("WRONG WAY!"), kart, -1.0f, 60);
|
||||
} // if angle is too big
|
||||
} // checkForWrongDirection
|
||||
|
||||
|
@ -22,8 +22,6 @@
|
||||
#include <vector>
|
||||
|
||||
struct KartIconDisplayInfo;
|
||||
class RaceGUI;
|
||||
|
||||
|
||||
/*
|
||||
* A 'linear world' is a subcategory of world used in 'standard' races, i.e.
|
||||
@ -90,7 +88,7 @@ public:
|
||||
void setTimeAtLapForKart(float t, const int kart_id);
|
||||
float getTimeAtLapForKart(const int kart_id) const;
|
||||
|
||||
virtual KartIconDisplayInfo* getKartsDisplayInfo(const RaceGUI* caller);
|
||||
virtual KartIconDisplayInfo* getKartsDisplayInfo();
|
||||
virtual void moveKartAfterRescue(Kart* kart, btRigidBody* body);
|
||||
|
||||
virtual void terminateRace();
|
||||
|
@ -196,7 +196,7 @@ void ThreeStrikesBattle::restartRace()
|
||||
}
|
||||
//void ThreeStrikesBattle::getDefaultCollectibles(int& collectible_type, int& amount)
|
||||
//-----------------------------------------------------------------------------
|
||||
KartIconDisplayInfo* ThreeStrikesBattle::getKartsDisplayInfo(const RaceGUI* caller)
|
||||
KartIconDisplayInfo* ThreeStrikesBattle::getKartsDisplayInfo()
|
||||
{
|
||||
const unsigned int kart_amount = race_manager->getNumKarts();
|
||||
for(unsigned int i = 0; i < kart_amount ; i++)
|
||||
|
@ -52,7 +52,7 @@ public:
|
||||
//virtual void getDefaultCollectibles(int& collectible_type, int& amount);
|
||||
//virtual bool enableBonusBoxes();
|
||||
virtual bool useFastMusicNearEnd() const { return false; }
|
||||
virtual KartIconDisplayInfo* getKartsDisplayInfo(const RaceGUI* caller);
|
||||
virtual KartIconDisplayInfo* getKartsDisplayInfo();
|
||||
virtual bool raceHasLaps(){ return false; }
|
||||
virtual void moveKartAfterRescue(Kart* kart, btRigidBody* body);
|
||||
virtual bool acceptPowerup(const int type) const;
|
||||
|
@ -54,8 +54,11 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
World::World() : TimedRace()
|
||||
{
|
||||
m_physics = NULL;
|
||||
}
|
||||
m_physics = NULL;
|
||||
m_race_gui = NULL;
|
||||
} // World
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void World::init()
|
||||
{
|
||||
RaceManager::setWorld(this);
|
||||
@ -153,12 +156,8 @@ void World::init()
|
||||
// objects need to allocate data structures depending on the number
|
||||
// of karts.
|
||||
m_track->reset();
|
||||
#ifdef SSG_BACKFACE_COLLISIONS_SUPPORTED
|
||||
//ssgSetBackFaceCollisions ( !not defined! race_manager->mirror ) ;
|
||||
#endif
|
||||
|
||||
// TODO - race GUI
|
||||
//menu_manager->switchToRace();
|
||||
m_race_gui = new RaceGUI();
|
||||
|
||||
m_track->startMusic();
|
||||
|
||||
@ -169,6 +168,8 @@ void World::init()
|
||||
//-----------------------------------------------------------------------------
|
||||
World::~World()
|
||||
{
|
||||
delete m_race_gui;
|
||||
|
||||
item_manager->cleanup();
|
||||
delete race_state;
|
||||
// In case that a race is aborted (e.g. track not found) m_track is 0.
|
||||
@ -185,20 +186,8 @@ World::~World()
|
||||
delete m_physics;
|
||||
|
||||
sound_manager -> stopMusic();
|
||||
/*
|
||||
sgVec3 sun_pos;
|
||||
sgVec4 ambient_col, specular_col, diffuse_col;
|
||||
sgSetVec3 ( sun_pos, 0.0f, 0.0f, 1.0f );
|
||||
sgSetVec4 ( ambient_col , 0.2f, 0.2f, 0.2f, 1.0f );
|
||||
sgSetVec4 ( specular_col, 1.0f, 1.0f, 1.0f, 1.0f );
|
||||
sgSetVec4 ( diffuse_col , 1.0f, 1.0f, 1.0f, 1.0f );
|
||||
|
||||
ssgGetLight ( 0 ) -> setPosition ( sun_pos ) ;
|
||||
ssgGetLight ( 0 ) -> setColour ( GL_AMBIENT , ambient_col ) ;
|
||||
ssgGetLight ( 0 ) -> setColour ( GL_DIFFUSE , diffuse_col ) ;
|
||||
ssgGetLight ( 0 ) -> setColour ( GL_SPECULAR, specular_col ) ;
|
||||
*/
|
||||
} // ~World
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void World::terminateRace()
|
||||
{
|
||||
@ -266,6 +255,16 @@ void World::resetAllKarts()
|
||||
m_player_karts[i]->getCamera()->setInitialTransform();
|
||||
} // resetAllKarts
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Called during rendering. In this function direct calls to the graphics
|
||||
* are possible, e.g. using an irrlicht font object to directly print to
|
||||
* the screen, ...
|
||||
*/
|
||||
void World::render()
|
||||
{
|
||||
m_race_gui->render();
|
||||
} // render
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void World::update(float dt)
|
||||
{
|
||||
@ -290,7 +289,7 @@ void World::update(float dt)
|
||||
|
||||
projectile_manager->update(dt);
|
||||
item_manager->update(dt);
|
||||
|
||||
m_race_gui->update(dt);
|
||||
} // update
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -400,25 +399,22 @@ void World::printProfileResultAndExit()
|
||||
void World::removeKart(int kart_number)
|
||||
{
|
||||
Kart *kart = m_kart[kart_number];
|
||||
|
||||
// Display a message about the eliminated kart in the race gui
|
||||
RaceGUI* m=getRaceGUI();
|
||||
if(m)
|
||||
{
|
||||
for (std::vector<PlayerKart*>::iterator i = m_player_karts.begin();
|
||||
i != m_player_karts.end(); i++ )
|
||||
{
|
||||
if(*i==kart)
|
||||
{
|
||||
m->addMessage(_("You have been\neliminated!"), *i, 2.0f, 60);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string s = _("'%s' has\nbeen eliminated.");
|
||||
m->addMessage( StringUtils::insert_values(s, kart->getName()),
|
||||
*i, 2.0f, 60);
|
||||
}
|
||||
} // for i in kart
|
||||
} // if raceMenu exist
|
||||
for (std::vector<PlayerKart*>::iterator i = m_player_karts.begin();
|
||||
i != m_player_karts.end(); i++ )
|
||||
{
|
||||
if(*i==kart)
|
||||
{
|
||||
m_race_gui->addMessage(_("You have been\neliminated!"), *i, 2.0f, 60);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string s = _("'%s' has\nbeen eliminated.");
|
||||
m_race_gui->addMessage( StringUtils::insert_values(s, kart->getName()),
|
||||
*i, 2.0f, 60);
|
||||
}
|
||||
} // for i in kart
|
||||
if(kart->isPlayerKart())
|
||||
{
|
||||
// Change the camera so that it will be attached to the leader
|
||||
|
@ -64,7 +64,7 @@ class RaceGUI;
|
||||
* be passed into the world constructor, and world just calls functions in
|
||||
* this object.
|
||||
* \todo The handling of the FollowTheLeader mode should probably be changed
|
||||
* as well. Currently the leader kart is anormal AI kart (so it is
|
||||
* as well. Currently the leader kart is a normal AI kart (so it is
|
||||
* included in the number of karts selected), and this causes some
|
||||
* unnecessary handling of special cases everywhere (e.g. score
|
||||
* counting will subtract one from the rank, since the kart on position
|
||||
@ -98,7 +98,7 @@ protected:
|
||||
bool m_faster_music_active; // true if faster music was activated
|
||||
|
||||
/** Whether highscores should be used for this kind of race.
|
||||
* True by default, change to false in a child class to disable.
|
||||
* True by default, change to false in a child class to disable.
|
||||
*/
|
||||
bool m_use_highscores;
|
||||
|
||||
@ -111,12 +111,15 @@ protected:
|
||||
void printProfileResultAndExit();
|
||||
void estimateFinishTimes();
|
||||
|
||||
/** Pointer to the track. The track is managed by world. */
|
||||
Track* m_track;
|
||||
|
||||
/** Pointer to the race GUI. The race GUI is handedl by world. */
|
||||
RaceGUI *m_race_gui;
|
||||
|
||||
public:
|
||||
/** debug text that will be overlaid to the screen */
|
||||
std::string m_debug_text[10];
|
||||
core::stringw m_debug_text[10];
|
||||
|
||||
World();
|
||||
/** call just after instanciating. can't be moved to the contructor as child
|
||||
@ -126,6 +129,7 @@ public:
|
||||
|
||||
virtual ~World();
|
||||
virtual void update(float delta);
|
||||
virtual void render();
|
||||
virtual void restartRace();
|
||||
void disableRace(); // Put race into limbo phase
|
||||
|
||||
@ -186,7 +190,7 @@ public:
|
||||
/** Called by the code that draws the list of karts on the race GUI
|
||||
* to know what needs to be drawn in the current mode
|
||||
*/
|
||||
virtual KartIconDisplayInfo* getKartsDisplayInfo(const RaceGUI* caller) = 0;
|
||||
virtual KartIconDisplayInfo* getKartsDisplayInfo() = 0;
|
||||
|
||||
/** Since each mode will have a different way of deciding where a rescued
|
||||
* kart is dropped, this method will be called and each mode can implement it.
|
||||
|
@ -372,3 +372,18 @@ int QuadGraph::findOutOfRoadSector(const Vec3& xyz,
|
||||
return min_sector;
|
||||
} // findOutOfRoadSector
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Draws the mini map on the screen.
|
||||
* \param where the top left and lower right corner for the mini map.
|
||||
*/
|
||||
void QuadGraph::drawMiniMap(const core::rect<s32> &where)
|
||||
{
|
||||
int width = where.LowerRightCorner.X-where.UpperLeftCorner.X;
|
||||
int height = where.UpperLeftCorner.Y -where.LowerRightCorner.Y;
|
||||
|
||||
|
||||
for(unsigned int i=0; i<m_all_nodes.size(); i++)
|
||||
{
|
||||
const Quad &q=m_all_quads->getQuad(m_all_nodes[i]->getIndex());
|
||||
}
|
||||
} // drawMiniMap
|
||||
|
@ -60,6 +60,7 @@ public:
|
||||
const int curr_sector=UNKNOWN_SECTOR,
|
||||
std::vector<int> *all_sectors=NULL
|
||||
) const;
|
||||
void drawMiniMap(const core::rect<s32> &where);
|
||||
|
||||
/** Returns the number of nodes in the graph. */
|
||||
unsigned int getNumNodes() const { return m_all_nodes.size(); }
|
||||
|
@ -551,14 +551,6 @@ void Track::loadCurves(const XMLNode &node)
|
||||
{
|
||||
const XMLNode *curve = node.getNode(i);
|
||||
m_all_curves.push_back(new BezierCurve(*curve));
|
||||
float t=0;
|
||||
const BezierCurve &c=*m_all_curves[m_all_curves.size()-1];
|
||||
while(t<=c.getNumPoints()-0.9998) // allow for some rounding errors
|
||||
{
|
||||
Vec3 xyz = c.getXYZ(t);
|
||||
printf("t %f xyz %f %f %f\n", t, xyz.getX(),xyz.getY(),xyz.getZ());
|
||||
t=t+0.1f;
|
||||
}
|
||||
} // for i<node.getNumNodes
|
||||
} // loadCurves
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user