1) Started to add split screen (though not all parts of the race gui are displayed correctly yet).

2) The name of an AI kart will now only get the AI name added if it's profile mode (to prevent
   the name with AI name to be displayed in game)
3) Some code cleanup.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@4226 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2009-11-23 05:20:05 +00:00
parent f80dc3a26b
commit a5a90be806
20 changed files with 382 additions and 333 deletions

View File

@ -34,7 +34,7 @@ Camera::Camera(int camera_index, const Kart* kart)
{ {
m_mode = CM_NORMAL; m_mode = CM_NORMAL;
m_index = camera_index; m_index = camera_index;
m_camera = irr_driver->addCamera(); m_camera = irr_driver->addCameraSceneNode();
m_distance = kart->getKartProperties()->getCameraDistance() * 0.5f; m_distance = kart->getKartProperties()->getCameraDistance() * 0.5f;
m_kart = kart; m_kart = kart;
m_angle_up = 0.0f; m_angle_up = 0.0f;
@ -49,63 +49,15 @@ Camera::Camera(int camera_index, const Kart* kart)
m_target_speed = 10.0f; m_target_speed = 10.0f;
m_rotation_range = 0.4f; m_rotation_range = 0.4f;
// TODO: Set fog distance and clipping planes
setScreenPosition(camera_index);
} // Camera } // Camera
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/** Removes the camera scene node from the scene.
*/
Camera::~Camera() Camera::~Camera()
{ {
irr_driver->removeCamera(m_camera); irr_driver->removeCamera(this);
m_camera=NULL; } // ~Camera
}
// ----------------------------------------------------------------------------
void Camera::setScreenPosition(int camera_index)
{
const int num_players = race_manager->getNumLocalPlayers();
assert(camera_index >= 0 && camera_index <= 3);
if (num_players == 1)
{
// m_camera->setFOV( DEGREE_TO_RAD(75.0f) ) ;
m_x = 0.0f; m_y = 0.0f; m_w = 1.0f; m_h = 1.0f ;
}
else if (num_players == 2)
{
// m_context -> setFOV ( 85.0f, 85.0f*3.0f/8.0f ) ;
switch ( camera_index )
{
case 0 : m_x = 0.0f; m_y = 0.5f; m_w = 1.0f; m_h = 0.5f; break;
case 1 : m_x = 0.0f; m_y = 0.0f; m_w = 1.0f; m_h = 0.5f; break;
}
}
else if (num_players == 3)
{
// m_context -> setFOV ( 50.0f, 0.0f );
switch ( camera_index )
{
case 0 : m_x = 0.0f; m_y = 0.5f; m_w = 0.5f; m_h = 0.5f; break;
case 1 : m_x = 0.5f; m_y = 0.5f; m_w = 0.5f; m_h = 0.5f; break;
case 2 : m_x = 0.0f; m_y = 0.0f; m_w = 1.0f; m_h = 0.5f;
// m_context -> setFOV ( 85.0f, 85.0f*3.0f/8.0f );
break;
}
}
else if (num_players == 4)
{
// m_context -> setFOV ( 50.0f, 0.0f );
switch ( camera_index )
{
case 0 : m_x = 0.0f; m_y = 0.5f; m_w = 0.5f; m_h = 0.5f; break;
case 1 : m_x = 0.5f; m_y = 0.5f; m_w = 0.5f; m_h = 0.5f; break;
case 2 : m_x = 0.0f; m_y = 0.0f; m_w = 0.5f; m_h = 0.5f; break;
case 3 : m_x = 0.5f; m_y = 0.0f; m_w = 0.5f; m_h = 0.5f; break;
}
}
} // setScreenPosition
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void Camera::setMode(Mode mode) void Camera::setMode(Mode mode)

View File

@ -58,8 +58,6 @@ private:
float m_target_speed; // The speed at which the camera changes targets float m_target_speed; // The speed at which the camera changes targets
float m_rotation_range; // Factor of the effects of steering in camera aim float m_rotation_range; // Factor of the effects of steering in camera aim
float m_x, m_y, m_w, m_h;
const Kart *m_kart; // The kart that the camera follows const Kart *m_kart; // The kart that the camera follows
private: private:
@ -69,10 +67,13 @@ public:
~Camera (); ~Camera ();
void setMode (Mode mode_); /** Set the camera to the given mode */ void setMode (Mode mode_); /** Set the camera to the given mode */
Mode getMode(); Mode getMode();
void setScreenPosition (int pos);
void reset (); void reset ();
void setInitialTransform(); void setInitialTransform();
void update (float dt); void update (float dt);
scene::ICameraSceneNode *getCameraSceneNode()
{
return m_camera;
}
} ; } ;
#endif #endif

View File

@ -28,6 +28,7 @@
#endif #endif
#include "config/user_config.hpp" #include "config/user_config.hpp"
#include "graphics/camera.hpp"
#include "graphics/material_manager.hpp" #include "graphics/material_manager.hpp"
#include "guiengine/engine.hpp" #include "guiengine/engine.hpp"
#include "guiengine/modaldialog.hpp" #include "guiengine/modaldialog.hpp"
@ -40,6 +41,7 @@
#include "items/projectile_manager.hpp" #include "items/projectile_manager.hpp"
#include "karts/kart_properties_manager.hpp" #include "karts/kart_properties_manager.hpp"
#include "modes/world.hpp" #include "modes/world.hpp"
#include "utils/constants.hpp"
using namespace irr::core; using namespace irr::core;
using namespace irr::scene; using namespace irr::scene;
@ -488,10 +490,43 @@ scene::ISceneNode *IrrDriver::addSkyBox(const std::vector<std::string> &texture_
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/** Adds a camera to the scene. /** Adds a camera to the scene.
*/ */
scene::ICameraSceneNode *IrrDriver::addCamera() scene::ICameraSceneNode *IrrDriver::addCameraSceneNode()
{ {
return m_scene_manager->addCameraSceneNode(); return m_scene_manager->addCameraSceneNode();
} // addCamera } // addCameraSceneNode
//-----------------------------------------------------------------------------
/** Adds a camera (as in STK Camera object, not an irrlicht camera). The number
* of cameras determines e.g. if split screen is used.
*/
Camera *IrrDriver::addCamera(unsigned int index, Kart *kart)
{
Camera *camera = new Camera(index, kart);
m_stk_cameras.push_back(camera);
m_viewports.push_back(core::recti());
m_scaling.push_back(core::vector2df());
m_fov.push_back(DEGREE_TO_RAD*75.0f);
m_aspect.push_back(((float)UserConfigParams::m_width)/UserConfigParams::m_height);
setupViewports();
return camera;
} // addCamera
// ----------------------------------------------------------------------------
void IrrDriver::removeCamera(Camera *camera)
{
unsigned index;
for(index=0; index<m_stk_cameras.size(); index++)
{
if(m_stk_cameras[index]==camera) break;
}
assert(index!=m_stk_cameras.size());
m_stk_cameras.erase(m_stk_cameras.begin()+index);
m_viewports.erase(m_viewports.begin()+index);
m_scaling.erase(m_scaling.begin()+index);
m_fov.erase(m_fov.begin()+index);
m_aspect.erase(m_aspect.begin()+index);
removeCameraSceneNode(camera->getCameraSceneNode());
} // removeCamera
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/** Removes a camera. This can't be done with removeNode() since the camera /** Removes a camera. This can't be done with removeNode() since the camera
@ -500,12 +535,12 @@ scene::ICameraSceneNode *IrrDriver::addCamera()
* a camera is added), it's a bit cleaner and easier to check for memory * a camera is added), it's a bit cleaner and easier to check for memory
* leaks, since the scene root should now always be empty. * leaks, since the scene root should now always be empty.
*/ */
void IrrDriver::removeCamera(scene::ICameraSceneNode *camera) void IrrDriver::removeCameraSceneNode(scene::ICameraSceneNode *camera)
{ {
if(camera==m_scene_manager->getActiveCamera()) if(camera==m_scene_manager->getActiveCamera())
m_scene_manager->setActiveCamera(NULL); // basically causes a drop m_scene_manager->setActiveCamera(NULL); // basically causes a drop
camera->remove(); camera->remove();
} // removeCamera } // removeCameraSceneNode
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/** Loads a texture from a file and returns the texture object. /** Loads a texture from a file and returns the texture object.
@ -516,6 +551,88 @@ video::ITexture *IrrDriver::getTexture(const std::string &filename)
return m_scene_manager->getVideoDriver()->getTexture(filename.c_str()); return m_scene_manager->getVideoDriver()->getTexture(filename.c_str());
} // getTexture } // getTexture
// ----------------------------------------------------------------------------
/** Determines the viewports and scaling for the cameras.
*/
void IrrDriver::setupViewports()
{
assert(m_stk_cameras.size()==m_viewports.size());
switch(m_stk_cameras.size())
{
case 1: m_viewports[0] = core::recti(0, 0,
UserConfigParams::m_width,
UserConfigParams::m_height);
m_scaling[0] = core::vector2df(1.0f, 1.0f);
break;
case 2: m_viewports[0] = core::recti(0, 0,
UserConfigParams::m_width,
UserConfigParams::m_height>>1);
m_scaling[0] = core::vector2df(1.0f, 0.5f);
m_aspect[0] *= 2.0f;
m_fov[0] = DEGREE_TO_RAD*85.0f;
m_viewports[1] = core::recti(0, UserConfigParams::m_height>>1,
UserConfigParams::m_width,
UserConfigParams::m_height);
m_scaling[1] = core::vector2df(1.0f, 0.5f);
m_aspect[1] *= 2.0f;
m_fov[1] = DEGREE_TO_RAD*85.0f;
break;
case 3: m_viewports[0] = core::recti(0, 0,
UserConfigParams::m_width>>1,
UserConfigParams::m_height>>1);
m_scaling[0] = core::vector2df(0.5f, 0.5f);
m_fov[1] = DEGREE_TO_RAD*50.0f;
m_viewports[1] = core::recti(UserConfigParams::m_width>>1,
0,
UserConfigParams::m_width,
UserConfigParams::m_height>>1);
m_scaling[1] = core::vector2df(0.5f, 0.5f);
m_fov[1] = DEGREE_TO_RAD*50.0f;
m_viewports[2] = core::recti(0, UserConfigParams::m_height>>1,
UserConfigParams::m_width,
UserConfigParams::m_height);
m_scaling[2] = core::vector2df(1.0f, 0.5f);
m_fov[1] = DEGREE_TO_RAD*85.0f;
m_aspect[2] *= 2.0f;
break;
case 4: m_viewports[0] = core::recti(0, 0,
UserConfigParams::m_width>>1,
UserConfigParams::m_height>>1);
m_scaling[0] = core::vector2df(0.5f, 0.5f);
m_fov[0] = DEGREE_TO_RAD*50.0f;
m_viewports[1] = core::recti(UserConfigParams::m_width>>1,
0,
UserConfigParams::m_width,
UserConfigParams::m_height>>1);
m_scaling[1] = core::vector2df(0.5f, 0.5f);
m_fov[1] = DEGREE_TO_RAD*50.0f;
m_viewports[2] = core::recti(0, UserConfigParams::m_height>>1,
UserConfigParams::m_width>>1,
UserConfigParams::m_height);
m_scaling[2] = core::vector2df(0.5f, 0.5f);
m_fov[2] = DEGREE_TO_RAD*50.0f;
m_viewports[3] = core::recti(UserConfigParams::m_width>>1,
UserConfigParams::m_height>>1,
UserConfigParams::m_width,
UserConfigParams::m_height);
m_scaling[3] = core::vector2df(0.5f, 0.5f);
m_fov[3] = DEGREE_TO_RAD*50.0f;
break;
default:fprintf(stderr, "Incorrect number of players: '%d' - assuming 1.\n",
m_stk_cameras.size());
m_viewports[0] = core::recti(0, 0,
UserConfigParams::m_width,
UserConfigParams::m_height);
m_scaling[0] = core::vector2df(1.0f, 1.0f);
break;
} // switch
for(unsigned int i=0; i<m_stk_cameras.size(); i++)
{
m_stk_cameras[i]->getCameraSceneNode()->setFOV(m_fov[i]);
m_stk_cameras[i]->getCameraSceneNode()->setAspectRatio(m_aspect[i]);
}
} // setupViewports
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/** Sets the ambient light. /** Sets the ambient light.
* \param light The colour of the light to set. * \param light The colour of the light to set.
@ -625,15 +742,20 @@ void IrrDriver::displayFPS()
*/ */
void IrrDriver::update(float dt) void IrrDriver::update(float dt)
{ {
// First update all cameras
std::vector<Camera*>::iterator i;
for(i=m_stk_cameras.begin(); i!=m_stk_cameras.end(); i++)
(*i)->update(dt);
if(!m_device->run()) return; if(!m_device->run()) return;
m_device->getVideoDriver()->beginScene(false, true, video::SColor(255,100,101,140)); m_device->getVideoDriver()->beginScene(false, true, video::SColor(255,100,101,140));
{ // just to mark the beding/end scene block { // Just to mark the beding/end scene block
GUIEngine::GameState state = StateManager::get()->getGameState(); GUIEngine::GameState state = StateManager::get()->getGameState();
if (state != GUIEngine::GAME) if (state != GUIEngine::GAME)
{ {
// this code needs to go outside beginScene() / endScene() since // This code needs to go outside beginScene() / endScene() since
// the model view widget will do off-screen rendering there // the model view widget will do off-screen rendering there
const int updateAmount = GUIEngine::needsUpdate.size(); const int updateAmount = GUIEngine::needsUpdate.size();
for(int n=0; n<updateAmount; n++) for(int n=0; n<updateAmount; n++)
@ -651,21 +773,32 @@ void IrrDriver::update(float dt)
} }
else else
{ {
m_scene_manager->drawAll(); RaceGUI *rg = RaceManager::getWorld()->getRaceGUI();
} for(unsigned int i=0; i<m_stk_cameras.size(); i++)
{
m_scene_manager->setActiveCamera(m_stk_cameras[i]->getCameraSceneNode());
m_video_driver->setViewPort(m_viewports[i]);
m_scene_manager->drawAll();
}
// To draw the race gui we set the viewport back to the full
// screen.
m_video_driver->setViewPort(core::recti(0, 0,
UserConfigParams::m_width,
UserConfigParams::m_height));
for(unsigned int i=0; i<m_stk_cameras.size(); i++)
{
rg->renderPlayerView(i, m_viewports[i], m_scaling[i]);
} // for i <m_stk_cameras.size()
} // !bullet_debug
} }
else
if (inRace || GUIEngine::getCurrentScreen()->needs3D())
{ {
// render 3D stuff in cutscenes too // render 3D stuff in cutscenes too
m_scene_manager->drawAll(); m_scene_manager->drawAll();
} }
// GUI is active // Either render the gui, or the global elements of the race gui.
//if (!inRace || GUIEngine::ModalDialog::isADialogActive()) GUIEngine::render(dt);
{
GUIEngine::render(dt);
}
// draw FPS if enabled // draw FPS if enabled
if ( UserConfigParams::m_display_fps ) displayFPS(); if ( UserConfigParams::m_display_fps ) displayFPS();

View File

@ -29,6 +29,9 @@
#include "irrlicht.h" #include "irrlicht.h"
using namespace irr; using namespace irr;
class Camera;
class Kart;
struct VideoMode struct VideoMode
{ {
int width, height; int width, height;
@ -48,13 +51,28 @@ private:
/** Irrlicht race font. */ /** Irrlicht race font. */
irr::gui::IGUIFont *m_race_font; irr::gui::IGUIFont *m_race_font;
/** The list of all cameras. */
std::vector<Camera*> m_stk_cameras;
/** The list of viewports for all cameras. */
std::vector<core::recti> m_viewports;
/** The scaling necessary for each axis for each camera. */
std::vector<core::vector2df> m_scaling;
/** Field of view for camera. */
std::vector<float> m_fov;
/** Aspect ratio for camera. */
std::vector<float> m_aspect;
void setAllMaterialFlags(scene::IAnimatedMesh *mesh) const; void setAllMaterialFlags(scene::IAnimatedMesh *mesh) const;
std::vector<VideoMode> m_modes; std::vector<VideoMode> m_modes;
void renderBulletDebugView(); void renderBulletDebugView();
void displayFPS(); void displayFPS();
video::E_DRIVER_TYPE getEngineDriverType(int index); void setupViewports();
video::E_DRIVER_TYPE getEngineDriverType(int index);
public: public:
IrrDriver(); IrrDriver();
~IrrDriver(); ~IrrDriver();
@ -102,8 +120,10 @@ public:
scene::IAnimatedMeshSceneNode scene::IAnimatedMeshSceneNode
*addAnimatedMesh(scene::IAnimatedMesh *mesh); *addAnimatedMesh(scene::IAnimatedMesh *mesh);
scene::ICameraSceneNode scene::ICameraSceneNode
*addCamera(); *addCameraSceneNode();
void removeCamera(scene::ICameraSceneNode *camera); Camera *addCamera(unsigned int index, Kart *kart);
void removeCameraSceneNode(scene::ICameraSceneNode *camera);
void removeCamera(Camera *camera);
void update(float dt); void update(float dt);
void changeResolution(); void changeResolution();

View File

@ -236,9 +236,10 @@ void render(float elapsed_time)
} }
else else
{ {
RaceManager::getWorld()->getRaceGUI()->render(); RaceManager::getWorld()->getRaceGUI()->renderGlobal(elapsed_time);
} }
} } // render
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
Widget* getWidget(const char* name) Widget* getWidget(const char* name)
{ {

View File

@ -21,6 +21,7 @@
#include "graphics/irr_driver.hpp" #include "graphics/irr_driver.hpp"
#include "karts/kart.hpp" #include "karts/kart.hpp"
#include "utils/constants.hpp"
#include "utils/coord.hpp" #include "utils/coord.hpp"
#include "utils/vec3.hpp" #include "utils/vec3.hpp"

View File

@ -34,14 +34,7 @@ public:
Kart(kart_name, position, init_pos) {} Kart(kart_name, position, init_pos) {}
bool isPlayerKart() const {return false;} bool isPlayerKart() const {return false;}
virtual const irr::core::stringw& getName() const }; // AutoKart
{
// Static to avoid returning the address of a temporary
// string.
static irr::core::stringw name = Kart::getName()+"(auto)";
return name;
} // getName
};
#endif #endif

View File

@ -24,6 +24,7 @@
#include "audio/sfx_manager.hpp" #include "audio/sfx_manager.hpp"
#include "config/player.hpp" #include "config/player.hpp"
#include "graphics/camera.hpp" #include "graphics/camera.hpp"
#include "graphics/irr_driver.hpp"
#include "input/input_manager.hpp" #include "input/input_manager.hpp"
#include "items/item.hpp" #include "items/item.hpp"
#include "modes/world.hpp" #include "modes/world.hpp"
@ -39,7 +40,7 @@ PlayerKart::PlayerKart(const std::string& kart_name, int position,
{ {
m_player = player; m_player = player;
m_penalty_time = 0.0f; m_penalty_time = 0.0f;
m_camera = RaceManager::getWorld()->getRaceGUI()->addCamera(player_index, this); m_camera = irr_driver->addCamera(player_index, this);
m_camera->setMode(Camera::CM_NORMAL); m_camera->setMode(Camera::CM_NORMAL);
m_bzzt_sound = sfx_manager->newSFX(SFXManager::SOUND_BZZT ); m_bzzt_sound = sfx_manager->newSFX(SFXManager::SOUND_BZZT );
@ -54,6 +55,7 @@ PlayerKart::PlayerKart(const std::string& kart_name, int position,
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
PlayerKart::~PlayerKart() PlayerKart::~PlayerKart()
{ {
irr_driver->removeCamera(m_camera);
sfx_manager->deleteSFX(m_bzzt_sound); sfx_manager->deleteSFX(m_bzzt_sound);
sfx_manager->deleteSFX(m_wee_sound ); sfx_manager->deleteSFX(m_wee_sound );
sfx_manager->deleteSFX(m_ugh_sound ); sfx_manager->deleteSFX(m_ugh_sound );

View File

@ -87,7 +87,7 @@ Kart *ProfileWorld::createKart(const std::string &kart_ident, int index,
{ {
// The pointer to the camera does not have to be stored, since it // The pointer to the camera does not have to be stored, since it
// the camera for robots is not modified. // the camera for robots is not modified.
RaceManager::getWorld()->getRaceGUI()->addCamera(index, newkart); irr_driver->addCamera(index, newkart);
} }
//m_local_player_karts[index] = static_cast<PlayerKart*>(newkart); //m_local_player_karts[index] = static_cast<PlayerKart*>(newkart);
//m_player_karts[index] = static_cast<PlayerKart*>(newkart); //m_player_karts[index] = static_cast<PlayerKart*>(newkart);

View File

@ -316,16 +316,6 @@ void World::resetAllKarts()
m_player_karts[i]->getCamera()->setInitialTransform(); m_player_karts[i]->getCamera()->setInitialTransform();
} // resetAllKarts } // 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) void World::update(float dt)
{ {
@ -362,7 +352,6 @@ void World::update(float dt)
m_track->update(dt); m_track->update(dt);
projectile_manager->update(dt); projectile_manager->update(dt);
m_race_gui->update(dt);
} // update } // update
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@ -128,7 +128,6 @@ public:
virtual ~World(); virtual ~World();
virtual void update(float delta); virtual void update(float delta);
virtual void render();
/** Returns true if the race is over. Must be defined by all modes. */ /** Returns true if the race is over. Must be defined by all modes. */
virtual bool isRaceOver() = 0; virtual bool isRaceOver() = 0;
virtual void restartRace(); virtual void restartRace();

View File

@ -30,6 +30,7 @@ using namespace irr;
#include "io/xml_node.hpp" #include "io/xml_node.hpp"
#include "modes/world.hpp" #include "modes/world.hpp"
#include "tracks/track.hpp" #include "tracks/track.hpp"
#include "utils/constants.hpp"
#include "utils/coord.hpp" #include "utils/coord.hpp"
#include "utils/string_utils.hpp" #include "utils/string_utils.hpp"

View File

@ -20,6 +20,7 @@
#define HEADER_DEFAULT_HPP #define HEADER_DEFAULT_HPP
#include "karts/auto_kart.hpp" #include "karts/auto_kart.hpp"
#include "modes/profile_world.hpp"
#include "utils/vec3.hpp" #include "utils/vec3.hpp"
/* third coord won't be used */ /* third coord won't be used */
@ -194,8 +195,12 @@ public:
virtual void crashed (Kart *k) {if(k) m_collided = true;}; virtual void crashed (Kart *k) {if(k) m_collided = true;};
virtual const irr::core::stringw& getName() const virtual const irr::core::stringw& getName() const
{ {
// Static to avoid returning the address of a temporary string // Static to avoid returning the address of a temporary stringq
static irr::core::stringw name=m_kart_properties->getName()+"(default)"; static irr::core::stringw name=m_kart_properties->getName();
// Add the name of the AI in case of profile mode, to make it
// easier to compare AIs
if(ProfileWorld::isProfileMode())
name+="(default)";
return name; return name;
} }
}; };

View File

@ -26,7 +26,7 @@ void FeatureUnlockedCutScene::init()
m_sky = irr_driver->addSkyDome(file_manager->getTextureFile("lscales.png"), 16 /* hori_res */, 16 /* vert_res */, m_sky = irr_driver->addSkyDome(file_manager->getTextureFile("lscales.png"), 16 /* hori_res */, 16 /* vert_res */,
1.0f /* texture_percent */, 2.0f /* sphere_percent */); 1.0f /* texture_percent */, 2.0f /* sphere_percent */);
m_camera = irr_driver->addCamera(); m_camera = irr_driver->addCameraSceneNode();
m_camera->setPosition( core::vector3df(0.0, 30.0f, 70.0f) ); m_camera->setPosition( core::vector3df(0.0, 30.0f, 70.0f) );
m_camera->setUpVector( core::vector3df(0.0, 1.0, 0.0) ); m_camera->setUpVector( core::vector3df(0.0, 1.0, 0.0) );
m_camera->setTarget( core::vector3df(0, 10, 0.0f) ); m_camera->setTarget( core::vector3df(0, 10, 0.0f) );
@ -92,7 +92,7 @@ void FeatureUnlockedCutScene::tearDown()
irr_driver->removeNode(m_sky); irr_driver->removeNode(m_sky);
m_sky = NULL; m_sky = NULL;
irr_driver->removeCamera(m_camera); irr_driver->removeCameraSceneNode(m_camera);
m_camera = NULL; m_camera = NULL;
irr_driver->removeNode(m_chest); irr_driver->removeNode(m_chest);

View File

@ -90,7 +90,7 @@ void RaceGUI::createMarkerTexture()
m_marker_rendered_size), m_marker_rendered_size),
"RaceGUI::markers"); "RaceGUI::markers");
#endif #endif
scene::ICameraSceneNode *camera = irr_driver->addCamera(); scene::ICameraSceneNode *camera = irr_driver->addCameraSceneNode();
core::matrix4 projection; core::matrix4 projection;
projection.buildProjectionMatrixOrthoLH((float)(m_marker_rendered_size*npower2), projection.buildProjectionMatrixOrthoLH((float)(m_marker_rendered_size*npower2),
(float)(m_marker_rendered_size), -1.0f, 1.0f); (float)(m_marker_rendered_size), -1.0f, 1.0f);
@ -128,7 +128,7 @@ void RaceGUI::createMarkerTexture()
} }
m_marker = rttProvider.renderToTexture(-1, /*is_2d_render*/true); m_marker = rttProvider.renderToTexture(-1, /*is_2d_render*/true);
irr_driver->removeCamera(camera); irr_driver->removeCameraSceneNode(camera);
} // createMarkerTexture } // createMarkerTexture
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -155,43 +155,94 @@ void RaceGUI::createRegularPolygon(unsigned int n, float radius,
} }
} // createRegularPolygon } // createRegularPolygon
//-----------------------------------------------------------------------------
/** Adds a camera. The number of cameras determines e.g. if split screen is
* used.
*/
Camera *RaceGUI::addCamera(unsigned int index, Kart *kart)
{
Camera *camera = new Camera(index, kart);
m_cameras.push_back(camera);
return camera;
} // addCamera
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/** Called before rendering, so no direct output to the screen can be done /** Render all global parts of the race gui, i.e. things that are only
* here. * displayed once even in splitscreen.
* \param dt Time step size. * \param dt Timestep sized.
*/ */
void RaceGUI::update(float dt) void RaceGUI::renderGlobal(float dt)
{ {
std::vector<Camera*>::iterator i;
for(i=m_cameras.begin(); i!=m_cameras.end(); i++)
(*i)->update(dt);
cleanupMessages(dt); cleanupMessages(dt);
} // update
assert(RaceManager::getWorld() != NULL);
if(RaceManager::getWorld()->getPhase() >= READY_PHASE &&
RaceManager::getWorld()->getPhase() <= GO_PHASE )
{
drawGlobalReadySetGo();
}
// 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
if(RaceManager::getWorld()->isStartPhase() ||
RaceManager::getWorld()->getTime()<1.0f)
{
displayPenaltyMessages();
}
// Timer etc. are not displayed unless the game is actually started.
if(!RaceManager::getWorld()->isRacePhase()) return;
drawGlobalTimer();
if(RaceManager::getWorld()->getPhase() == GO_PHASE ||
RaceManager::getWorld()->getPhase() == MUSIC_PHASE)
{
drawGlobalMusicDescription();
}
drawGlobalMiniMap();
RaceGUI::KartIconDisplayInfo* info = RaceManager::getWorld()->getKartsDisplayInfo();
drawGlobalPlayerIcons(info);
} // renderGlobal
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/** Render the race gui. Direct access to the screen is possible here, since /** Render the details for a single player, i.e. speed, energy,
* this is called during irrlicht rendering. * collectibles, ...
* \param player_id Player id.
* \param viewport Viewport to use (already set in the camera).
* \param scaling Scaling to use.
*/ */
void RaceGUI::render() void RaceGUI::renderPlayerView(unsigned int player_id,
const core::recti &viewport,
const core::vector2df &scaling)
{ {
drawStatusText(); if(!RaceManager::getWorld()->isRacePhase()) return;
} // render
RaceGUI::KartIconDisplayInfo* info = RaceManager::getWorld()->getKartsDisplayInfo();
Kart* player_kart = RaceManager::getWorld()->getLocalPlayerKart(player_id);
drawPowerupIcons (player_kart, viewport, scaling);
drawEnergyMeter (player_kart, viewport, scaling);
drawSpeed (player_kart, viewport, scaling);
drawLap (info, player_kart, viewport, scaling);
drawAllMessages (player_kart, viewport, scaling);
if(player_kart->hasViewBlockedByPlunger())
{
int offset_x = viewport.UpperLeftCorner.X;
int offset_y = viewport.UpperLeftCorner.Y;
float split_screen_ratio_x = scaling.X;
float split_screen_ratio_y = scaling.Y;
const int screen_width = viewport.LowerRightCorner.X-viewport.UpperLeftCorner.X;
const int plunger_size = viewport.UpperLeftCorner.Y-viewport.LowerRightCorner.Y;
int plunger_x = viewport.UpperLeftCorner.X + screen_width/2 - plunger_size/2;
video::ITexture *t=m_plunger_face->getTexture();
core::rect<s32> dest(plunger_x, offset_y,
plunger_x+plunger_size, offset_y+plunger_size);
const core::rect<s32> source(core::position2d<s32>(0,0), t->getOriginalSize());
static const video::SColor white = video::SColor(255, 255, 255, 255);
irr_driver->getVideoDriver()->draw2DImage(t, dest, source, 0,
&white, true);
}
} // renderPlayerView
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/** Displays the racing time on the screen.s /** Displays the racing time on the screen.s
*/ */
void RaceGUI::drawTimer () void RaceGUI::drawGlobalTimer()
{ {
assert(RaceManager::getWorld() != NULL); assert(RaceManager::getWorld() != NULL);
@ -204,12 +255,12 @@ void RaceGUI::drawTimer ()
UserConfigParams::m_width, 50); UserConfigParams::m_width, 50);
gui::IGUIFont* font = irr_driver->getRaceFont(); gui::IGUIFont* font = irr_driver->getRaceFont();
font->draw(sw.c_str(), pos, time_color); font->draw(sw.c_str(), pos, time_color);
} // drawTimer } // DRAWGLOBALTimer
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/** Draws the mini map and the position of all karts on it. /** Draws the mini map and the position of all karts on it.
*/ */
void RaceGUI::drawMiniMap() void RaceGUI::drawGlobalMiniMap()
{ {
// arenas currently don't have a map. // arenas currently don't have a map.
if(RaceManager::getTrack()->isArena()) return; if(RaceManager::getTrack()->isArena()) return;
@ -241,11 +292,11 @@ void RaceGUI::drawMiniMap()
lower_y -(int)(draw_at.getY()-marker_half_size)); lower_y -(int)(draw_at.getY()-marker_half_size));
irr_driver->getVideoDriver()->draw2DImage(m_marker, position, source, NULL, NULL, true); irr_driver->getVideoDriver()->draw2DImage(m_marker, position, source, NULL, NULL, true);
} // for i<getNumKarts } // for i<getNumKarts
} // drawMap } // drawGlobalMiniMap
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Draw players icons and their times (if defined in the current mode). // Draw players icons and their times (if defined in the current mode).
void RaceGUI::drawPlayerIcons (const KartIconDisplayInfo* info) void RaceGUI::drawGlobalPlayerIcons(const KartIconDisplayInfo* info)
{ {
assert(RaceManager::getWorld() != NULL); assert(RaceManager::getWorld() != NULL);
@ -301,12 +352,12 @@ void RaceGUI::drawPlayerIcons (const KartIconDisplayInfo* info)
} // next kart } // next kart
} // drawPlayerIcons } // drawGlobalPlayerIcons
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void RaceGUI::drawPowerupIcons(Kart* player_kart, int offset_x, void RaceGUI::drawPowerupIcons(Kart* player_kart,
int offset_y, float ratio_x, const core::recti &viewport,
float ratio_y ) const core::vector2df &scaling)
{ {
// If player doesn't have anything, do nothing. // If player doesn't have anything, do nothing.
Powerup* powerup=player_kart->getPowerup(); Powerup* powerup=player_kart->getPowerup();
@ -315,18 +366,18 @@ void RaceGUI::drawPowerupIcons(Kart* player_kart, int offset_x,
if(n<1) return; // shouldn't happen, but just in case if(n<1) return; // shouldn't happen, but just in case
if(n>5) n=5; // Display at most 5 items if(n>5) n=5; // Display at most 5 items
// Originally the hardcoded sizes were 320-32 and 400 int nSize=(int)(64.0f*std::min(scaling.X, scaling.Y));
int x1 = (int)((UserConfigParams::m_width/2-32) * ratio_x) + offset_x; int x1 = (int)((UserConfigParams::m_width/2-32) * scaling.X)
int y1 = (int)(20 * ratio_y) + offset_y; + viewport.UpperLeftCorner.X;
int y1 = UserConfigParams::m_height - viewport.LowerRightCorner.Y
int nSize=(int)(64.0f*std::min(ratio_x, ratio_y)); + (int)(20 * scaling.Y)+nSize;
video::ITexture *t=powerup->getIcon()->getTexture(); video::ITexture *t=powerup->getIcon()->getTexture();
core::rect<s32> rect(core::position2di(0, 0), t->getOriginalSize()); core::rect<s32> rect(core::position2di(0, 0), t->getOriginalSize());
for ( int i = 0 ; i < n ; i++ ) for ( int i = 0 ; i < n ; i++ )
{ {
core::rect<s32> pos(x1+i*30, y1, x1+i*30+nSize, y1+nSize); core::rect<s32> pos(x1+i*30, y1-nSize, x1+i*30+nSize, y1);
irr_driver->getVideoDriver()->draw2DImage(t, pos, rect, NULL, irr_driver->getVideoDriver()->draw2DImage(t, pos, rect, NULL,
NULL, true); NULL, true);
} // for i } // for i
@ -334,14 +385,16 @@ void RaceGUI::drawPowerupIcons(Kart* player_kart, int offset_x,
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/* Energy meter that gets filled with coins */ /* Energy meter that gets filled with coins */
void RaceGUI::drawEnergyMeter ( Kart *player_kart, int offset_x, int offset_y, void RaceGUI::drawEnergyMeter (Kart *player_kart,
float ratio_x, float ratio_y ) const core::recti &viewport,
const core::vector2df &scaling)
{ {
float state = (float)(player_kart->getEnergy()) / MAX_ITEMS_COLLECTED; float state = (float)(player_kart->getEnergy()) / MAX_ITEMS_COLLECTED;
int x = (int)((UserConfigParams::m_width-24) * ratio_x) + offset_x; int x = (int)((UserConfigParams::m_width-24) * scaling.X) + viewport.UpperLeftCorner.X;
int y = (int)(250 * ratio_y) + offset_y; //int y = (int)(250 * scaling.Y) + viewport.UpperLeftCorner.Y;
int w = (int)(16 * ratio_x); int y = UserConfigParams::m_height - (int)(250 * scaling.Y) - viewport.UpperLeftCorner.Y;
int h = (int)(UserConfigParams::m_height/4 * ratio_y); int w = (int)(16 * scaling.X);
int h = (int)(UserConfigParams::m_height/4 * scaling.Y);
float coin_target = (float)race_manager->getCoinTarget(); float coin_target = (float)race_manager->getCoinTarget();
int th = (int)(h*(coin_target/MAX_ITEMS_COLLECTED)); int th = (int)(h*(coin_target/MAX_ITEMS_COLLECTED));
@ -393,22 +446,25 @@ void RaceGUI::drawEnergyMeter ( Kart *player_kart, int offset_x, int offset_y,
} // drawEnergyMeter } // drawEnergyMeter
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void RaceGUI::drawSpeed(Kart* kart, int offset_x, int offset_y, void RaceGUI::drawSpeed(Kart* kart, const core::recti &viewport,
float ratio_x, float ratio_y ) const core::vector2df &scaling)
{ {
float minRatio = std::min(ratio_x, ratio_y); float minRatio = std::min(scaling.X, scaling.Y);
const int SPEEDWIDTH = 128; const int SPEEDWIDTH = 128;
int meter_width = (int)(SPEEDWIDTH*minRatio); int meter_width = (int)(SPEEDWIDTH*minRatio);
int meter_height = (int)(SPEEDWIDTH*minRatio); int meter_height = (int)(SPEEDWIDTH*minRatio);
offset_x += (int)((UserConfigParams::m_width-10)*ratio_x) - meter_width; core::vector2di offset = viewport.UpperLeftCorner;
offset_y += (int)(10*ratio_y); offset.X += (int)((UserConfigParams::m_width-10)*scaling.X) - meter_width;
offset.Y += (int)(10*scaling.Y);
// First draw the meter (i.e. the background which contains the numbers etc. // First draw the meter (i.e. the background which contains the numbers etc.
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
video::IVideoDriver *video = irr_driver->getVideoDriver(); video::IVideoDriver *video = irr_driver->getVideoDriver();
const core::rect<s32> meter_pos(offset_x, UserConfigParams::m_height-offset_y-meter_height, const core::rect<s32> meter_pos(offset.X,
offset_x+meter_width, UserConfigParams::m_height-offset_y); UserConfigParams::m_height-offset.Y-meter_height,
offset.X+meter_width,
UserConfigParams::m_height-offset.Y);
video::ITexture *meter_texture = m_speed_meter_icon->getTexture(); video::ITexture *meter_texture = m_speed_meter_icon->getTexture();
const core::rect<s32> meter_texture_coords(core::position2d<s32>(0,0), const core::rect<s32> meter_texture_coords(core::position2d<s32>(0,0),
meter_texture->getOriginalSize()); meter_texture->getOriginalSize());
@ -419,10 +475,10 @@ void RaceGUI::drawSpeed(Kart* kart, int offset_x, int offset_y,
if ( !kart->isOnGround() ) if ( !kart->isOnGround() )
{ {
static video::SColor color = video::SColor(255, 255, 255, 255); static video::SColor color = video::SColor(255, 255, 255, 255);
core::rect<s32> pos(offset_x-(int)(30*minRatio), core::rect<s32> pos(offset.X-(int)(30*minRatio),
UserConfigParams::m_height-(offset_y-(int)(10*minRatio)), UserConfigParams::m_height-(offset.Y-(int)(10*minRatio)),
offset_x-(int)(30*minRatio), offset.X-(int)(30*minRatio),
UserConfigParams::m_height-(offset_y-(int)(10*minRatio)) ); UserConfigParams::m_height-(offset.Y-(int)(10*minRatio)) );
irr_driver->getRaceFont()->draw(core::stringw("!").c_str(), pos, color); irr_driver->getRaceFont()->draw(core::stringw("!").c_str(), pos, color);
} }
@ -462,13 +518,13 @@ void RaceGUI::drawSpeed(Kart* kart, int offset_x, int offset_y,
{ {
count = 4; count = 4;
vertices[2].TCoords = core::vector2df(0,0); vertices[2].TCoords = core::vector2df(0,0);
vertices[2].Pos = core::vector3df((float)offset_x, vertices[2].Pos = core::vector3df((float)offset.X,
(float)(UserConfigParams::m_height-offset_y-meter_height), (float)(UserConfigParams::m_height-offset.Y-meter_height),
0); 0);
vertices[3].TCoords = core::vector2df(2*speed_ratio-1.0f, 0); vertices[3].TCoords = core::vector2df(2*speed_ratio-1.0f, 0);
vertices[3].Pos = core::vector3df(offset_x+2*(speed_ratio-0.5f)*meter_width, vertices[3].Pos = core::vector3df(offset.X+2*(speed_ratio-0.5f)*meter_width,
(float)(UserConfigParams::m_height-offset_y-meter_height), (float)(UserConfigParams::m_height-offset.Y-meter_height),
0); 0);
} }
short int index[4]; short int index[4];
for(unsigned int i=0; i<count; i++) for(unsigned int i=0; i<count; i++)
@ -479,6 +535,7 @@ void RaceGUI::drawSpeed(Kart* kart, int offset_x, int offset_y,
video::SMaterial m; video::SMaterial m;
m.setTexture(0, m_speed_bar_icon->getTexture()); m.setTexture(0, m_speed_bar_icon->getTexture());
irr_driver->getVideoDriver()->setMaterial(m); irr_driver->getVideoDriver()->setMaterial(m);
#define DOES_NOT_WORK_ATM
#ifdef DOES_NOT_WORK_ATM #ifdef DOES_NOT_WORK_ATM
irr_driver->getVideoDriver()->draw2DVertexPrimitiveList(vertices, count, irr_driver->getVideoDriver()->draw2DVertexPrimitiveList(vertices, count,
index, count-2, video::EVT_STANDARD, scene::EPT_TRIANGLE_FAN); index, count-2, video::EVT_STANDARD, scene::EPT_TRIANGLE_FAN);
@ -486,24 +543,28 @@ void RaceGUI::drawSpeed(Kart* kart, int offset_x, int offset_y,
} // drawSpeed } // drawSpeed
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void RaceGUI::drawLap(const KartIconDisplayInfo* info, Kart* kart, int offset_x, void RaceGUI::drawLap(const KartIconDisplayInfo* info, Kart* kart,
int offset_y, float ratio_x, float ratio_y ) const core::recti &viewport,
const core::vector2df &scaling)
{ {
// Don't display laps in follow the leader mode // Don't display laps in follow the leader mode
if(!RaceManager::getWorld()->raceHasLaps()) return; if(!RaceManager::getWorld()->raceHasLaps()) return;
const int lap = info[kart->getWorldKartId()].lap; const int lap = info[kart->getWorldKartId()].lap;
if(lap<0) return; // don't display 'lap 0/...', or do nothing if laps are disabled (-1) if(lap<0) return; // don't display 'lap 0/...'
float minRatio = std::min(ratio_x, ratio_y); float minRatio = std::min(scaling.X, scaling.Y);
offset_x += (int)(120*ratio_x); core::recti pos;
offset_y += (int)(UserConfigParams::m_height*5/6*minRatio); pos.UpperLeftCorner.X = viewport.UpperLeftCorner.X
+ (int)(0.15f*UserConfigParams::m_width*scaling.X);
gui::IGUIFont* font = irr_driver->getRaceFont(); pos.UpperLeftCorner.Y = UserConfigParams::m_height - viewport.LowerRightCorner.Y;
//pos.UpperLeftCorner.Y += (int)(UserConfigParams::m_height*5/6*minRatio);
pos.UpperLeftCorner.Y += (int)(40*minRatio);
pos.LowerRightCorner = pos.UpperLeftCorner;
gui::IGUIFont* font = irr_driver->getRaceFont();
if(kart->hasFinishedRace()) if(kart->hasFinishedRace())
{ {
static video::SColor color = video::SColor(255, 255, 255, 255); static video::SColor color = video::SColor(255, 255, 255, 255);
core::rect<s32> pos(offset_x, offset_y, offset_x, offset_y);
//I18N: Shown at the end of a race //I18N: Shown at the end of a race
core::stringw s=_("Finished"); core::stringw s=_("Finished");
font->draw(s.c_str(), pos, color); font->draw(s.c_str(), pos, color);
@ -511,14 +572,13 @@ void RaceGUI::drawLap(const KartIconDisplayInfo* info, Kart* kart, int offset_x,
else else
{ {
static video::SColor color = video::SColor(255, 255, 255, 255); static video::SColor color = video::SColor(255, 255, 255, 255);
core::rect<s32> pos(offset_x, offset_y, offset_x, offset_y);
core::stringw s = _("Lap"); core::stringw s = _("Lap");
font->draw(core::stringw(_("Lap")).c_str(), pos, color); font->draw(core::stringw(_("Lap")).c_str(), pos, color);
char str[256]; char str[256];
sprintf(str, "%d/%d", lap+1, race_manager->getNumLaps()); sprintf(str, "%d/%d", lap+1, race_manager->getNumLaps());
pos.UpperLeftCorner.Y += (int)(40*ratio_y); pos.UpperLeftCorner.Y += (int)(40*scaling.Y);
pos.LowerRightCorner.Y += (int)(40*ratio_y); pos.LowerRightCorner.Y += (int)(40*scaling.Y);
font->draw(core::stringw(str).c_str(), pos, color); font->draw(core::stringw(str).c_str(), pos, color);
} }
} // drawLap } // drawLap
@ -548,13 +608,14 @@ void RaceGUI::cleanupMessages(const float dt)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/** Displays all messages in the message queue /** Displays all messages in the message queue
**/ **/
void RaceGUI::drawAllMessages(Kart* player_kart, int offset_x, int offset_y, void RaceGUI::drawAllMessages(Kart* player_kart,
float ratio_x, float ratio_y ) const core::recti &viewport,
const core::vector2df &scaling)
{ {
int y; int y;
// First line of text somewhat under the top of the screen. For now // First line of text somewhat under the top of the screen. For now
// start just under the timer display // start just under the timer display
y = (int)(ratio_y*164+offset_y); y = (int)(scaling.Y*164+viewport.UpperLeftCorner.Y);
// The message are displayed in reverse order, so that a multi-line // The message are displayed in reverse order, so that a multi-line
// message (addMessage("1", ...); addMessage("2",...) is displayed // message (addMessage("1", ...); addMessage("2",...) is displayed
// in the right order: "1" on top of "2" // in the right order: "1" on top of "2"
@ -578,7 +639,7 @@ void RaceGUI::drawAllMessages(Kart* player_kart, int offset_x, int offset_y,
* certain amount of time (unless time<0, then the message is displayed * certain amount of time (unless time<0, then the message is displayed
* once). * once).
**/ **/
void RaceGUI::addMessage(const irr::core::stringw &msg, const Kart *kart, float time, void RaceGUI::addMessage(const core::stringw &msg, const Kart *kart, float time,
int font_size, const video::SColor &color) int font_size, const video::SColor &color)
{ {
m_messages.push_back(TimedMessage(msg, kart, time, font_size, color)); m_messages.push_back(TimedMessage(msg, kart, time, font_size, color));
@ -587,7 +648,7 @@ void RaceGUI::addMessage(const irr::core::stringw &msg, const Kart *kart, float
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Displays the description given for the music currently being played - // Displays the description given for the music currently being played -
// usually the title and composer. // usually the title and composer.
void RaceGUI::drawMusicDescription() void RaceGUI::drawGlobalMusicDescription()
{ {
if (!UserConfigParams::m_music) return; // show no music description when it's off if (!UserConfigParams::m_music) return; // show no music description when it's off
@ -659,10 +720,12 @@ void RaceGUI::drawMusicDescription()
irr_driver->getVideoDriver()->draw2DImage(t, dest, source, NULL, NULL, true); irr_driver->getVideoDriver()->draw2DImage(t, dest, source, NULL, NULL, true);
} // drawMusicDescription } // drawGlobalMusicDescription
//----------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void RaceGUI::drawStatusText() /** Draws the ready-set-go message on the screen.
*/
void RaceGUI::drawGlobalReadySetGo()
{ {
assert(RaceManager::getWorld() != NULL); assert(RaceManager::getWorld() != NULL);
switch (RaceManager::getWorld()->getPhase()) switch (RaceManager::getWorld()->getPhase())
@ -703,14 +766,11 @@ void RaceGUI::drawStatusText()
default: default:
break; break;
} // switch } // switch
} // drawGlobalReadySetGo
float split_screen_ratio_x, split_screen_ratio_y; // ----------------------------------------------------------------------------
split_screen_ratio_x = split_screen_ratio_y = 1.0; void RaceGUI::displayPenaltyMessages()
if(race_manager->getNumLocalPlayers() >= 2) {
split_screen_ratio_y = 0.5;
if(race_manager->getNumLocalPlayers() >= 3)
split_screen_ratio_x = 0.5;
// The penalty message needs to be displayed for up to one second // The penalty message needs to be displayed for up to one second
// after the start of the race, otherwise it disappears if // after the start of the race, otherwise it disappears if
// "Go" is displayed and the race starts // "Go" is displayed and the race starts
@ -731,88 +791,4 @@ void RaceGUI::drawStatusText()
} // if penalty } // if penalty
} // for i < getNum_players } // for i < getNum_players
} // if not RACE_PHASE } // if not RACE_PHASE
} // displayPenaltyMessage
if(!RaceManager::getWorld()->isRacePhase()) return;
RaceGUI::KartIconDisplayInfo* info = RaceManager::getWorld()->getKartsDisplayInfo();
for(unsigned int pla = 0; pla < num_players; pla++)
{
int offset_x = 0;
int offset_y = 0;
if(num_players == 2)
{
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
{
// Fixes width for player 3
split_screen_ratio_x = 1.0;
}
if (pla == 1)
offset_x = UserConfigParams::m_width/2;
}
else if(num_players == 4)
{
if(pla == 0 || pla == 1)
offset_y = UserConfigParams::m_height/2;
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 = (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;
video::ITexture *t=m_plunger_face->getTexture();
core::rect<s32> dest(plunger_x, offset_y,
plunger_x+plunger_size, offset_y+plunger_size);
const core::rect<s32> source(core::position2d<s32>(0,0), t->getOriginalSize());
static const video::SColor white = video::SColor(255, 255, 255, 255);
irr_driver->getVideoDriver()->draw2DImage(t, dest, source, 0,
&white,
true);
}
} // next player
drawTimer();
if(RaceManager::getWorld()->getPhase() == GO_PHASE ||
RaceManager::getWorld()->getPhase() == MUSIC_PHASE)
{
drawMusicDescription();
}
drawMiniMap();
drawPlayerIcons(info);
} // drawStatusText

View File

@ -30,7 +30,6 @@ using namespace irr;
#include "config/player.hpp" #include "config/player.hpp"
class Camera;
class InputMap; class InputMap;
class Kart; class Kart;
class Material; class Material;
@ -130,43 +129,43 @@ private:
/** Distance of map from bottom of screen. */ /** Distance of map from bottom of screen. */
int m_map_bottom; int m_map_bottom;
/** The list of all cameras. */
std::vector<Camera*> m_cameras;
void createMarkerTexture(); void createMarkerTexture();
void createRegularPolygon(unsigned int n, float radius, void createRegularPolygon(unsigned int n, float radius,
const core::vector2df &center, const core::vector2df &center,
const video::SColor &color, const video::SColor &color,
video::S3DVertex *v, unsigned short int *index); video::S3DVertex *v, unsigned short int *index);
/* Display informat on screen */ /* Display informat for one player on the screen. */
void drawStatusText ();
void drawEnergyMeter (Kart *player_kart, void drawEnergyMeter (Kart *player_kart,
int offset_x, int offset_y, const core::recti &viewport,
float ratio_x, float ratio_y ); const core::vector2df &scaling);
void drawPowerupIcons (Kart* player_kart, void drawPowerupIcons (Kart* player_kart,
int offset_x, int offset_y, const core::recti &viewport,
float ratio_x, float ratio_y ); const core::vector2df &scaling);
void drawAllMessages (Kart* player_kart, void drawAllMessages (Kart* player_kart,
int offset_x, int offset_y, const core::recti &viewport,
float ratio_x, float ratio_y ); const core::vector2df &scaling);
void drawPlayerIcons (const KartIconDisplayInfo* info); void drawSpeed (Kart* kart, const core::recti &viewport,
void oldDrawPlayerIcons (); const core::vector2df &scaling);
void drawMiniMap (); void drawLap (const KartIconDisplayInfo* info, Kart* kart,
void drawTimer (); const core::recti &viewport,
void drawMusicDescription (); const core::vector2df &scaling);
void drawGlobalPlayerIcons (const KartIconDisplayInfo* info);
/** Display items that are shown once only (for all karts). */
void drawGlobalMiniMap ();
void drawGlobalTimer ();
void drawGlobalMusicDescription();
void cleanupMessages (const float dt); void cleanupMessages (const float dt);
void drawSpeed (Kart* kart, int offset_x, int offset_y, void drawGlobalReadySetGo ();
float ratio_x, float ratio_y ); void displayPenaltyMessages();
void drawLap (const KartIconDisplayInfo* info, Kart* kart, int offset_x,
int offset_y, float ratio_x, float ratio_y );
public: public:
RaceGUI(); RaceGUI();
~RaceGUI(); ~RaceGUI();
void render(); void renderGlobal(float dt);
void update(float dt); void renderPlayerView(unsigned int player_id, const core::recti &viewport,
Camera *addCamera(unsigned int index, Kart *kart); const core::vector2df &scaling);
void addMessage(const irr::core::stringw &m, const Kart *kart, float time, void addMessage(const irr::core::stringw &m, const Kart *kart, float time,
int fonst_size, int fonst_size,
const video::SColor &color=video::SColor(255, 255, 0, 255)); const video::SColor &color=video::SColor(255, 255, 0, 255));

View File

@ -489,7 +489,7 @@ video::ITexture *QuadGraph::makeMiniMap(const core::dimension2di &dimension,
// Add the camera: // Add the camera:
// --------------- // ---------------
scene::ICameraSceneNode *camera = irr_driver->addCamera(); scene::ICameraSceneNode *camera = irr_driver->addCameraSceneNode();
Vec3 bb_min, bb_max; Vec3 bb_min, bb_max;
m_all_quads->getBoundingBox(&bb_min, &bb_max); m_all_quads->getBoundingBox(&bb_min, &bb_max);
Vec3 center = (bb_max+bb_min)*0.5f; Vec3 center = (bb_max+bb_min)*0.5f;
@ -505,7 +505,7 @@ video::ITexture *QuadGraph::makeMiniMap(const core::dimension2di &dimension,
video::ITexture *texture = rttProvider.renderToTexture(); video::ITexture *texture = rttProvider.renderToTexture();
cleanupDebugMesh(); cleanupDebugMesh();
irr_driver->removeCamera(camera); irr_driver->removeCameraSceneNode(camera);
m_min_coord = bb_min; m_min_coord = bb_min;
m_scaling.setX(dimension.Width/(bb_max.getX()-bb_min.getX())); m_scaling.setX(dimension.Width/(bb_max.getX()-bb_min.getX()));
m_scaling.setY(dimension.Width/(bb_max.getY()-bb_min.getY())); m_scaling.setY(dimension.Width/(bb_max.getY()-bb_min.getY()));

View File

@ -50,6 +50,7 @@ using namespace irr;
#include "tracks/check_manager.hpp" #include "tracks/check_manager.hpp"
#include "tracks/quad_graph.hpp" #include "tracks/quad_graph.hpp"
#include "tracks/quad_set.hpp" #include "tracks/quad_set.hpp"
#include "utils/constants.hpp"
#include "utils/string_utils.hpp" #include "utils/string_utils.hpp"
#include "utils/translation.hpp" #include "utils/translation.hpp"

View File

@ -37,16 +37,6 @@
#define KILOMETERS_PER_HOUR (KILOMETER/HOUR) #define KILOMETERS_PER_HOUR (KILOMETER/HOUR)
// Zipper related constants:
// =========================
#define ZIPPER_ANGLE 45.0
#define ZIPPER_TIME 1.0f /* Seconds */
#define ZIPPER_VELOCITY (100.0f * KILOMETERS_PER_HOUR )
// Traffic (not used at this time)
// ===============================
#define TRAFFIC_VELOCITY ( 20.0f * KILOMETERS_PER_HOUR )
/* M$ compilers don't define M_PI... */ /* M$ compilers don't define M_PI... */
#ifndef M_PI #ifndef M_PI

View File

@ -23,7 +23,6 @@
#include "LinearMath/btTransform.h" #include "LinearMath/btTransform.h"
#include "utils/constants.hpp"
#include "utils/vec3.hpp" #include "utils/vec3.hpp"
/** A class that stores a translation and rotation. It is used to convert /** A class that stores a translation and rotation. It is used to convert
@ -37,19 +36,6 @@ private:
/** Rotation as Eulerian HPR value. */ /** Rotation as Eulerian HPR value. */
Vec3 m_hpr; Vec3 m_hpr;
//sgCoord m_coord;
/** Sets the sgCoord data structures (and converts radians to degrees). */
/*
void setSgCoord()
{
sgSetCoord(&m_coord, m_xyz.toFloat(), m_hpr.toFloat());
// Convert hpr in radians to degrees, which sg needs.
for(int i=0; i<3; i++)
{
m_coord.hpr[i] = RAD_TO_DEGREE(m_coord.hpr[i]);
}
}*/
public: public:
/** Constructor. /** Constructor.