Commit b89b26a3 authored by Gerhard Stein's avatar Gerhard Stein

Changes to the camera system. Now global camera settings are part of...

Changes to the camera system. Now global camera settings are part of CVideoDriver and the camera class is prepared to be a local object
parent dd14ae5d
......@@ -175,11 +175,12 @@ bool CPlayer::scrollTriggers()
px = (getXPosition()>>STC)-scroll_x;
py = (getYPosition()>>STC)-scroll_y;
left = g_pCamera->getScrollLeft();
up = g_pCamera->getScrollUp();
right = g_pCamera->getScrollRight();
down = g_pCamera->getScrollDown();
speed = g_pCamera->getScrollSpeed();
st_camera_bounds CameraBounds = g_pVideoDriver->getCameraBounds();
left = CameraBounds.left;
up = CameraBounds.up;
right = CameraBounds.right;
down = CameraBounds.down;
speed = CameraBounds.speed;
// left-right scrolling
if(px > right && scroll_x < mp_Map->m_maxscrollx)
......
......@@ -6,39 +6,32 @@
*/
#include "CCameraSettings.h"
#include "../../engine/vorticon/CCamera.h"
#include "../../StringUtils.h"
CCameraSettings::CCameraSettings(Uint8 dlg_theme):
CBaseMenu(dlg_theme)
CBaseMenu(dlg_theme),
m_CameraBounds(g_pVideoDriver->getCameraBounds())
{
m_left = g_pCamera->getScrollLeft();
m_up = g_pCamera->getScrollUp();
m_right = g_pCamera->getScrollRight();
m_down = g_pCamera->getScrollDown();
m_speed = g_pCamera->getScrollSpeed();
std::string buf;
mp_Dialog = new CDialog(18, 13, INPUT_MODE_UP_DOWN, m_dlg_theme);
mp_Dialog->addObject(DLG_OBJ_TEXT, 1, 1, " Adjust Bounds: ");
mp_Dialog->addObject(DLG_OBJ_TEXT, 1, 2, " Left (50-270): ");
mp_Dialog->addObject(DLG_OBJ_OPTION_TEXT, 1, 3, " "+itoa(m_left));
mp_Dialog->addObject(DLG_OBJ_OPTION_TEXT, 1, 3, " "+itoa(m_CameraBounds.left));
mp_Dialog->addObject(DLG_OBJ_TEXT, 1, 4, " Right (50-270):");
mp_Dialog->addObject(DLG_OBJ_OPTION_TEXT, 1, 5, " "+itoa(m_right));
mp_Dialog->addObject(DLG_OBJ_OPTION_TEXT, 1, 5, " "+itoa(m_CameraBounds.right));
mp_Dialog->addObject(DLG_OBJ_TEXT, 1, 6, " Up (50-150): ");
mp_Dialog->addObject(DLG_OBJ_OPTION_TEXT, 1, 7, " "+itoa(m_up));
mp_Dialog->addObject(DLG_OBJ_OPTION_TEXT, 1, 7, " "+itoa(m_CameraBounds.up));
mp_Dialog->addObject(DLG_OBJ_TEXT, 1, 8, " Down (50-150): ");
mp_Dialog->addObject(DLG_OBJ_OPTION_TEXT, 1, 9, " "+itoa(m_down));
mp_Dialog->addObject(DLG_OBJ_OPTION_TEXT, 1, 9, " "+itoa(m_CameraBounds.down));
mp_Dialog->addObject(DLG_OBJ_TEXT, 1, 10, " Speed (1-50): ");
mp_Dialog->addObject(DLG_OBJ_OPTION_TEXT, 1, 11, " "+itoa(m_speed));
mp_Dialog->addObject(DLG_OBJ_OPTION_TEXT, 1, 11, " "+itoa(m_CameraBounds.speed));
mp_Dialog->setInputMode(INPUT_MODE_COUNTER);
}
void CCameraSettings::processSpecific()
{
if(mp_Dialog->getSelection() == 2)
{
mp_Dialog->m_min = 50;
......@@ -70,11 +63,11 @@ void CCameraSettings::processSpecific()
mp_Dialog->m_length = 2;
}
m_left = atoi(mp_Dialog->m_dlgobject.at(2)->m_Option->m_text);
m_right = atoi(mp_Dialog->m_dlgobject.at(4)->m_Option->m_text);
m_up = atoi(mp_Dialog->m_dlgobject.at(6)->m_Option->m_text);
m_down = atoi(mp_Dialog->m_dlgobject.at(8)->m_Option->m_text);
m_speed = atoi(mp_Dialog->m_dlgobject.at(10)->m_Option->m_text);
m_CameraBounds.left = atoi(mp_Dialog->m_dlgobject.at(2)->m_Option->m_text);
m_CameraBounds.right = atoi(mp_Dialog->m_dlgobject.at(4)->m_Option->m_text);
m_CameraBounds.up = atoi(mp_Dialog->m_dlgobject.at(6)->m_Option->m_text);
m_CameraBounds.down = atoi(mp_Dialog->m_dlgobject.at(8)->m_Option->m_text);
m_CameraBounds.speed = atoi(mp_Dialog->m_dlgobject.at(10)->m_Option->m_text);
if( m_selection != NO_SELECTION)
{
......@@ -108,5 +101,5 @@ void CCameraSettings::processSpecific()
CCameraSettings::~CCameraSettings()
{
g_pCamera->setScrollTriggers(m_left, m_up, m_right, m_down, m_speed);
g_pVideoDriver->saveCameraBounds(m_CameraBounds);
}
......@@ -9,6 +9,7 @@
#define CCAMERASETTINGS_H_
#include "CBaseMenu.h"
#include "../../sdl/CVideoDriver.h"
class CCameraSettings : public CBaseMenu
{
......@@ -18,7 +19,8 @@ public:
virtual ~CCameraSettings();
private:
int m_left, m_right, m_up, m_down, m_speed, m_changeint;
st_camera_bounds m_CameraBounds;
int m_changeint;
};
#endif /* CCAMERASETTINGS_H_ */
/*
* CCamera.h
*
* Created on: 09.03.2010
* Author: pizza2004 and gerstrong
*
* This camera class is used for the scrolling during the "gameplay".
* The old values of that used that class are now a structure part of CVideoDriver
* This class will be another object that will following the player
* It has the feature to attach to any object in the game scenario and follow it.
* It also can detached and moved manually. That might be used for
* the active Level viewer feature.
*/
#include "CCamera.h"
#include "../../CLogFile.h"
CCamera::CCamera()
{
g_pLogFile->ftextOut("Starting the camera system...<br>");
}
CCamera::~CCamera()
{
// TODO Auto-generated destructor stub
}
/*
* CCamera.h
*
* Created on: 09.03.2010
* Author: pizza2004 and gerstrong
*
* This camera class is used for the scrolling during the "gameplay".
* The old values of that used that class are now a structure part of CVideoDriver
* This class will be another object that will following the player
* It has the feature to attach to any object in the game scenario and follow it.
* It also can detached and moved manually. That might be used for
* the active Level viewer feature.
*/
#include ""
#ifndef CCAMERA_H_
#define CCAMERA_H_
class CCamera
{
public:
CCamera();
virtual ~CCamera();
private:
};
#endif /* CCAMERA_H_ */
......@@ -55,15 +55,26 @@ void CPlayGameGalaxy::process()
processInput();
// process WM. If a level is open process it also in this class
// process World Map if active. At the start it's enabled
//if(m_WorldMap.isActive())
//m_WorldMap.process();
// process Finale
// process World Map if active. At the start it's enabled
//if(m_LevelPlay.isActive())
//m_LevelPlay.process();
// process Page if one is open. Could be one of the finale
//if(m_Page.isActive())
//m_Page.process();
processRendering();
}
void CPlayGameGalaxy::processInput()
{
// TODO: wrap this into the camera class they way it can be used in the vorticons engine
// Also make it more efficient.
if(g_pInput->getPressedCommand(IC_QUIT))
m_endgame = true;
......
/*
* CCamera.cpp
*
* Created on: 09.03.2010
* Author: pizza2004
*/
#include "CCamera.h"
#include "../../CLogFile.h"
CCamera::CCamera()
{
g_pLogFile->ftextOut("Starting the camera system...<br>");
setDefaults();
}
void CCamera::setDefaults()
{
m_scrolltriggerright = 168;
m_scrolltriggerleft = 152;
m_scrolltriggerup = 92;
m_scrolltriggerdown = 108;
m_scrollspeed = 20;
}
void CCamera::setScrollTriggers(int left, int up, int right, int down, int speed)
{
int i;
if(left>right)
{
i = left-right;
i = i/2;
left = left-i;
right = right+i;
if(left>right)
left = left-1;
}
if(up>down)
{
i = up-down;
i = i/2;
up = up-i;
down = down+i;
if(up>down)
up = up-1;
}
bool invalid_value = (left<50) || (up<50) || (right<50) || (down<50) || (speed<1) || (left>270) || (up>150) || (right>270) || (down>150) || (speed>50);
if(invalid_value)
setDefaults();
else
{
m_scrolltriggerleft = left;
m_scrolltriggerup = up;
m_scrolltriggerright = right;
m_scrolltriggerdown = down;
m_scrollspeed = speed;
}
}
CCamera::~CCamera()
{
// TODO Auto-generated destructor stub
}
/*
* CCamera.h
*
* Created on: 09.03.2010
* Author: pizza2004
*/
#ifndef CCAMERA_H_
#define CCAMERA_H_
#include "../../CSingleton.h"
#define g_pCamera CCamera::Get()
class CCamera : public CSingleton<CCamera>
{
public:
CCamera();
void setDefaults();
void setScrollTriggers(int left, int up, int right, int down, int speed);
int getScrollLeft() { return m_scrolltriggerleft ; }
int getScrollUp() { return m_scrolltriggerup ; }
int getScrollRight() { return m_scrolltriggerright ; }
int getScrollDown() { return m_scrolltriggerdown ; }
int getScrollSpeed() { return m_scrollspeed ; }
virtual ~CCamera();
private:
// scroll triggers
int m_scrolltriggerright;
int m_scrolltriggerleft;
int m_scrolltriggerup;
int m_scrolltriggerdown;
int m_scrollspeed;
};
#endif /* CCAMERA_H_ */
......@@ -52,14 +52,15 @@ bool CSettings::saveDrvCfg()
Configuration.WriteInt("Video", "scale", g_pVideoDriver->getZoomValue());
Configuration.WriteInt("Video", "OGLfilter", g_pVideoDriver->getOGLFilter());
Configuration.WriteInt("Video", "filter", g_pVideoDriver->getFiltermode());
Configuration.WriteInt("Video", "specialfx",g_pVideoDriver->getSpecialFXConfig());
Configuration.WriteInt("Video", "specialfx", g_pVideoDriver->getSpecialFXConfig());
Configuration.WriteInt("Video", "autoframeskip", g_pTimer->getFrameRate());
Configuration.WriteInt("Bound", "left", g_pCamera->getScrollLeft());
Configuration.WriteInt("Bound", "right", g_pCamera->getScrollRight());
Configuration.WriteInt("Bound", "up", g_pCamera->getScrollUp());
Configuration.WriteInt("Bound", "down", g_pCamera->getScrollDown());
Configuration.WriteInt("Bound", "speed", g_pCamera->getScrollSpeed());
st_camera_bounds &CameraBounds = g_pVideoDriver->getCameraBounds();
Configuration.WriteInt("Bound", "left", CameraBounds.left);
Configuration.WriteInt("Bound", "right", CameraBounds.right);
Configuration.WriteInt("Bound", "up", CameraBounds.up);
Configuration.WriteInt("Bound", "down", CameraBounds.down);
Configuration.WriteInt("Bound", "speed", CameraBounds.speed);
Configuration.WriteInt("Audio", "channels", (g_pSound->getAudioSpec()).channels);
Configuration.WriteInt("Audio", "format", (g_pSound->getAudioSpec()).format);
......@@ -117,14 +118,14 @@ bool CSettings::loadDrvCfg()
Configuration.ReadInteger("Video", "autoframeskip", &framerate, 60);
g_pTimer->setFrameRate(DEFAULT_LPS, framerate, DEFAULT_SYNC);
int boundl, boundr, boundu, boundd, sspeed;
Configuration.ReadInteger("Bound", "left", &boundl, 152);
Configuration.ReadInteger("Bound", "right", &boundr, 168);
Configuration.ReadInteger("Bound", "up", &boundu, 92);
Configuration.ReadInteger("Bound", "down", &boundd, 108);
Configuration.ReadInteger("Bound", "speed", &sspeed, 20);
st_camera_bounds CameraBounds;
Configuration.ReadInteger("Bound", "left", &CameraBounds.left, 152);
Configuration.ReadInteger("Bound", "right", &CameraBounds.right, 168);
Configuration.ReadInteger("Bound", "up", &CameraBounds.up, 92);
Configuration.ReadInteger("Bound", "down", &CameraBounds.down, 108);
Configuration.ReadInteger("Bound", "speed", &CameraBounds.speed, 20);
g_pCamera->setScrollTriggers(boundl,boundu,boundr,boundd,sspeed);
g_pVideoDriver->saveCameraBounds(CameraBounds);
int filter;
Configuration.ReadInteger("Video", "filter", &filter, 2);
......
......@@ -75,6 +75,13 @@ m_blitsurface_alloc(false)
screenrect.h=0;
screenrect.w=0;
// Default camera settings
m_CameraBounds.left = 152;
m_CameraBounds.up = 92;
m_CameraBounds.right = 168;
m_CameraBounds.down = 108;
m_CameraBounds.speed = 20;
ScrollSurface=NULL; // 512x512 scroll buffer
FGLayerSurface=NULL; // Scroll buffer for Messages
BlitSurface=NULL;
......@@ -598,22 +605,6 @@ void CVideoDriver::setScrollBuffer(Sint16 *pbufx, Sint16 *pbufy)
mp_sbuffery = pbufy;
}
/*static void sb_lowblit(SDL_Surface* src, SDL_Rect* srcrect, SDL_Surface* dst, SDL_Rect* dstrect) {
#if !defined(USE_OPENGL) && (defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR))
// SDL_BlitSurface doesn't work for some reason
int _xend = srcrect->x + dstrect->w;
int _yend = srcrect->y + dstrect->h;
int _dst_xdiff = dstrect->x - srcrect->x;
int _dst_ydiff = dstrect->y - srcrect->y;
for(int x = srcrect->x; x < _xend; ++x)
for(int y = srcrect->y; y < _yend; ++y)
SDL_DrawPoint(dst, x + _dst_xdiff, y + _dst_ydiff, convert4to32BPPcolor( ((Uint8*)src->pixels)[y * 512 + x], dst ));
#else
SDL_BlitSurface(src, srcrect, dst, dstrect);
#endif
}
*/
void CVideoDriver::blitScrollSurface() // This is only for tiles
// The name should be changed
{
......@@ -986,6 +977,51 @@ void CVideoDriver::AddConsoleMsg(const char *the_msg)
ConsoleExpireTimer = CONSOLE_EXPIRE_RATE;
}
void CVideoDriver::saveCameraBounds(const st_camera_bounds &CameraBounds)
{
int i;
int left = CameraBounds.left;
int up = CameraBounds.up;
int right = CameraBounds.right;
int down = CameraBounds.down;
int speed = CameraBounds.speed;
if(left>right)
{
i = left-right;
i = i/2;
left = left-i;
right = right+i;
if(left>right)
left = left-1;
}
if(up>down)
{
i = up-down;
i = i/2;
up = up-i;
down = down+i;
if(up>down)
up = up-1;
}
bool invalid_value = (left<50) || (up<50) || (right<50) || (down<50) || (speed<1) || (left>270) || (up>150) || (right>270) || (down>150) || (speed>50);
if(invalid_value)
{
m_CameraBounds.left = 152;
m_CameraBounds.up = 92;
m_CameraBounds.right = 168;
m_CameraBounds.down = 108;
m_CameraBounds.speed = 20;
}
else
{
m_CameraBounds.left = left;
m_CameraBounds.up = up;
m_CameraBounds.right = right;
m_CameraBounds.down = down;
m_CameraBounds.speed = speed;
}
}
short CVideoDriver::getZoomValue(void){ return Zoom; }
void CVideoDriver::showFPS(bool value){ showfps = value; }
......@@ -1012,6 +1048,9 @@ unsigned short CVideoDriver::getDepth(void)
SDL_Surface *CVideoDriver::getScrollSurface(void)
{ return ScrollSurface; }
st_camera_bounds &CVideoDriver::getCameraBounds()
{ return m_CameraBounds; }
CVideoDriver::~CVideoDriver() {
stop();
}
......@@ -14,6 +14,9 @@
struct st_resolution
{ int width,height,depth; };
struct st_camera_bounds
{ int left, right, down, up, speed; };
#ifdef USE_OPENGL
#include "COpenGL.h"
#endif
......@@ -41,8 +44,6 @@ public:
bool applyMode();
SDL_Rect adaptGameResolution();
SDL_Surface* createSurface( std::string name, bool alpha, int width, int height, int bpp, int mode, SDL_PixelFormat* format );
//void resetSettings();
//bool createSurfaces(void);
void stop(void);
bool start(void);
......@@ -64,6 +65,8 @@ public:
void DeleteConsoleMsgs(void);
void AddConsoleMsg(const char *the_msg);
void saveCameraBounds(const st_camera_bounds &CameraBounds);
short getZoomValue(void);
bool getShowFPS(void);
short getFiltermode(void);
......@@ -108,6 +111,8 @@ public:
bool getAspectCorrection(void) { return m_aspect_correction; }
bool getSpecialFXConfig(void) { return m_special_fx; }
st_camera_bounds &getCameraBounds();
virtual ~CVideoDriver();
SDL_Surface *BlitSurface;
......@@ -146,6 +151,8 @@ private:
SDL_Rect blitrect;
SDL_Rect game_resolution_rect; // Also called Screenspace. Yet very limited.
st_camera_bounds m_CameraBounds;
Sint16 *mp_sbufferx, *mp_sbuffery;
SDL_Surface *screen; // the actual video memory/window
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment