Commit c09ec283 authored by gerstrong@gmail.com's avatar gerstrong@gmail.com

VirtualPad Macro fixes and more general cleanups

parent 4108ac3e
......@@ -7,13 +7,16 @@ Project(CommanderGenius)
set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake")
option(USE_VIRTUALPAD "Enable Onscreen Virtual Gamepad support " yes)
if(USE_VIRTUALPAD)
ADD_DEFINITIONS(-DVIRTUALPAD)
endif(USE_VIRTUALPAD)
# Use COmpile TIme REducer
include(cotire)
if(USE_SDL2S)
include(FindSDL2_mixer)
endif()
option(USE_PYTHON3 "Use Python3 scripts" yes)
set (CMAKE_CXX_STANDARD 14)
......
......@@ -7,18 +7,11 @@ Project(GsKit)
OPTION(USE_SDL2 "SDL2 support" Yes)
option(USE_PYTHON3 "Use Python3 scripts" yes)
option(USE_VIRTUALPAD "Enable Onscreen Virtual Gamepad support " yes)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(USE_VIRTUALPAD)
ADD_DEFINITIONS(-DVIRTUALPAD)
endif(USE_VIRTUALPAD)
IF(WIN32)
ADD_DEFINITIONS(-DWIN32)
ENDIF(WIN32)
......
......@@ -258,7 +258,7 @@ void CInput::loadControlconfig(void)
else
{
for(size_t c=1 ; c<= NUM_INPUTS ; c++)
resetControls(c);
resetControls(int(c));
}
}
......@@ -274,26 +274,30 @@ void CInput::saveControlconfig()
std::string section;
for(size_t i=0 ; i<NUM_INPUTS ; i++)
{
section = "input" + itoa(i);
Configuration.WriteString(section, "Left", getEventName(IC_LEFT, i));
Configuration.WriteString(section, "Up", getEventName(IC_UP, i));
Configuration.WriteString(section, "Right", getEventName(IC_RIGHT, i));
Configuration.WriteString(section, "Down", getEventName(IC_DOWN, i));
Configuration.WriteString(section, "Upper-Left", getEventName(IC_UPPERLEFT, i));
Configuration.WriteString(section, "Upper-Right", getEventName(IC_UPPERRIGHT, i));
Configuration.WriteString(section, "Lower-Left", getEventName(IC_LOWERLEFT, i));
Configuration.WriteString(section, "Lower-Right", getEventName(IC_LOWERRIGHT, i));
Configuration.WriteString(section, "Jump", getEventName(IC_JUMP, i));
Configuration.WriteString(section, "Pogo", getEventName(IC_POGO, i));
Configuration.WriteString(section, "Fire", getEventName(IC_FIRE, i));
Configuration.WriteString(section, "Run", getEventName(IC_RUN, i));
Configuration.WriteString(section, "Status", getEventName(IC_STATUS, i));
Configuration.WriteString(section, "Camlead", getEventName(IC_CAMLEAD, i));
Configuration.WriteString(section, "Help", getEventName(IC_HELP, i));
Configuration.WriteString(section, "Back", getEventName(IC_BACK, i));
Configuration.SetKeyword(section, "TwoButtonFiring", TwoButtonFiring[i]);
Configuration.SetKeyword(section, "Analog", mAnalogAxesMovement[i]);
section = "input" + itoa(i);
const auto inputVal = static_cast<unsigned char>(i);
Configuration.WriteString(section, "Left", getEventName(IC_LEFT, inputVal));
Configuration.WriteString(section, "Up", getEventName(IC_UP, inputVal));
Configuration.WriteString(section, "Right", getEventName(IC_RIGHT, inputVal));
Configuration.WriteString(section, "Down", getEventName(IC_DOWN, inputVal));
Configuration.WriteString(section, "Upper-Left", getEventName(IC_UPPERLEFT, inputVal));
Configuration.WriteString(section, "Upper-Right", getEventName(IC_UPPERRIGHT, inputVal));
Configuration.WriteString(section, "Lower-Left", getEventName(IC_LOWERLEFT, inputVal));
Configuration.WriteString(section, "Lower-Right", getEventName(IC_LOWERRIGHT, inputVal));
Configuration.WriteString(section, "Jump", getEventName(IC_JUMP, inputVal));
Configuration.WriteString(section, "Pogo", getEventName(IC_POGO, inputVal));
Configuration.WriteString(section, "Fire", getEventName(IC_FIRE, inputVal));
Configuration.WriteString(section, "Run", getEventName(IC_RUN, inputVal));
Configuration.WriteString(section, "Status", getEventName(IC_STATUS, inputVal));
Configuration.WriteString(section, "Camlead", getEventName(IC_CAMLEAD, inputVal));
Configuration.WriteString(section, "Help", getEventName(IC_HELP, inputVal));
Configuration.WriteString(section, "Back", getEventName(IC_BACK, inputVal));
Configuration.SetKeyword(section, "TwoButtonFiring", TwoButtonFiring[i]);
Configuration.SetKeyword(section, "Analog", mAnalogAxesMovement[i]);
}
Configuration.saveCfgFile();
}
......
......@@ -160,7 +160,7 @@ class CInput : public GsSingleton<CInput>
public:
CInput();
~CInput();
virtual ~CInput();
/**
* @brief transMouseRelCoord transforms a mouse click from the screen coordinates to the relative coordinates
......
......@@ -251,15 +251,14 @@ void GsApp::runMainCycle()
curr = timerTicks();
if(gTimer.resetLogicSignal())
start = curr;
start = curr;
if(vsyncEnabled)
{
start = timerTicks();
// Game cycle
{
{
// Poll Inputs
gInput.pollEvents();
......
......@@ -5,8 +5,8 @@
* Author: gerstrong
*/
#ifndef __GSAPP_H_
#define GSAPP_H
#ifndef GSAPP_H_
#define GSAPP_H_
#include <base/GsEvent.h>
#include <base/GsEngine.h>
......
......@@ -56,9 +56,9 @@ public:
stInputCommand* cmd = nullptr;
//stInputCommand* cmd = nullptr;
int immediateIndex = 0;
//int x = 0, y = 0, w = 0, h = 0;
float x = 0.0f, y = 0.0f, w = 0.0f, h = 0.0f;
bool invisible = true;
......@@ -77,8 +77,6 @@ public:
return !mFingerSet.empty();
}
//private:
std::set<SDL_FingerID> mFingerSet;
#endif
......@@ -98,7 +96,7 @@ public:
/**
* @brief GsVirtualInput basic constructor, just setup some variables.
*/
GsVirtualInput() {}
//GsVirtualInput() {}
virtual ~GsVirtualInput() {}
......@@ -186,8 +184,6 @@ protected:
bool mEnabled = true;
//GsSurface mOverlay;
float mTranslucency = 0.5f;
};
......
......@@ -18,47 +18,56 @@
///////////////////
// If you want to use the adress of some Uint32 directly with memcpy or similar, use this
inline Uint32 SDLColourToNativeColour(Uint32 pixel, short bpp) {
/*
inline Uint32 SDLColourToNativeColour(Uint32 pixel, short bpp)
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
return (pixel << (32 - 8 * bpp));
#else
return pixel;
#endif
}
*/
/////////////////
// If you copied some data directly with memcpy into an Uint32, use this
inline Uint32 NativeColourToSDLColour(Uint32 pixel, short bpp) {
/*
inline Uint32 NativeColourToSDLColour(Uint32 pixel, short bpp)
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
return (pixel >> (32 - 8 * bpp));
#else
return pixel;
#endif
}
*/
///////////////
// Get the specified component from the pixel (grabbed from SDL)
inline Uint8 GetR(Uint32 pixel, SDL_PixelFormat *fmt) {
/*
inline Uint8 GetR(Uint32 pixel, SDL_PixelFormat *fmt)
{
return (Uint8)((((pixel & fmt->Rmask) >> fmt->Rshift) << fmt->Rloss) +
(((pixel & fmt->Rmask) >> fmt->Rshift) >> (8 - (fmt->Rloss << 1))));
}
inline Uint8 GetG(Uint32 pixel, SDL_PixelFormat *fmt) {
inline Uint8 GetG(Uint32 pixel, SDL_PixelFormat *fmt)
{
return (Uint8)((((pixel & fmt->Gmask) >> fmt->Gshift) << fmt->Gloss) +
(((pixel & fmt->Gmask) >> fmt->Gshift) >> (8 - (fmt->Gloss << 1))));
}
inline Uint8 GetB(Uint32 pixel, SDL_PixelFormat *fmt) {
inline Uint8 GetB(Uint32 pixel, SDL_PixelFormat *fmt)
{
return (Uint8)((((pixel & fmt->Bmask) >> fmt->Bshift) << fmt->Bloss) +
(((pixel & fmt->Bmask) >> fmt->Bshift) >> (8 - (fmt->Bloss << 1))));
}
inline Uint8 GetA(Uint32 pixel, SDL_PixelFormat *fmt) {
inline Uint8 GetA(Uint32 pixel, SDL_PixelFormat *fmt)
{
return (Uint8)((((pixel & fmt->Amask) >> fmt->Ashift) << fmt->Aloss) +
(((pixel & fmt->Amask) >> fmt->Ashift) >> (8 - (fmt->Aloss << 1))));
}
*/
//extern SDL_PixelFormat* mainPixelFormat;
/*inline SDL_PixelFormat* getMainPixelFormat()
......@@ -136,14 +145,16 @@ struct GsColor
*/
void converge(GsColor &&c)
{
r = (Uint16(r) + Uint16(c.r))/2;
g = (Uint16(g) + Uint16(c.g))/2;
b = (Uint16(b) + Uint16(c.b))/2;
a = (Uint16(a) + Uint16(c.a))/2;
r = Uint8((Uint16(r) + Uint16(c.r))/2);
g = Uint8((Uint16(g) + Uint16(c.g))/2);
b = Uint8((Uint16(b) + Uint16(c.b))/2);
a = Uint8((Uint16(a) + Uint16(c.a))/2);
}
Uint8& operator[](int i) { switch(i) { case 0: return r; case 1: return g; case 2: return b; case 3: return a; default: assert(false); } return *((Uint8*)NULL); }
Uint8 operator[](int i) const { switch(i) { case 0: return r; case 1: return g; case 2: return b; case 3: return a; default: assert(false); } return 0; }
/*
Uint8& operator[](int i) { switch(i) { case 0: return r; case 1: return g; case 2: return b; case 3: return a; default: assert(false); } return *(reinterpret_cast<Uint8*>(0)); }
Uint8 operator[](int i) const { switch(i) { case 0: return r; case 1: return g; case 2: return b; case 3: return a; default: assert(false); } return 0; }
*/
};
#endif // COLOR_H
......@@ -111,6 +111,7 @@ static inline void scale2x_8_def_whole(scale2x_uint8* restrict dst0, scale2x_uin
}
}
#ifndef USE_SCALE_RANDOMWRITE
static inline void scale2x_8_def_border(scale2x_uint8* restrict dst, const scale2x_uint8* restrict src0, const scale2x_uint8* restrict src1, const scale2x_uint8* restrict src2, unsigned count)
{
assert(count >= 2);
......@@ -155,6 +156,7 @@ static inline void scale2x_8_def_border(scale2x_uint8* restrict dst, const scale
dst[1] = src1[0];
}
}
#endif
static inline void scale2x_8_def_center(scale2x_uint8* restrict dst, const scale2x_uint8* restrict src0, const scale2x_uint8* restrict src1, const scale2x_uint8* restrict src2, unsigned count)
{
......@@ -409,6 +411,8 @@ static inline void scale2x_32_def_whole(scale2x_uint32* restrict dst0, scale2x_u
}
}
#ifndef USE_SCALE_RANDOMWRITE
static inline void scale2x_32_def_border(scale2x_uint32* restrict dst, const scale2x_uint32* restrict src0, const scale2x_uint32* restrict src1, const scale2x_uint32* restrict src2, unsigned count)
{
assert(count >= 2);
......@@ -453,6 +457,7 @@ static inline void scale2x_32_def_border(scale2x_uint32* restrict dst, const sca
dst[1] = src1[0];
}
}
#endif
static inline void scale2x_32_def_center(scale2x_uint32* restrict dst, const scale2x_uint32* restrict src0, const scale2x_uint32* restrict src1, const scale2x_uint32* restrict src2, unsigned count)
{
......
......@@ -15,7 +15,7 @@
#include <graphics/GsGraphics.h>
#include <base/GsLogging.h>
const unsigned int MAX_ELEMENTS_PER_PAGE = 7;
//const unsigned int MAX_ELEMENTS_PER_PAGE = 7;
const unsigned int MAX_STEPS = 20;
......
......@@ -10,7 +10,7 @@
you feel merit inclusion in the source tree email them
to me at gerstrong@gmail.com.
Thanks to ID Software for the "Commander Keen" series.
Thanks to ID Software for the "Commander Keen" series.
"Commander Keen" and it's associated
graphics, level, and sound files are the property of ID
Software. Commander Genius requires the original version of a
......@@ -35,7 +35,7 @@
#ifdef ANDROID
#include <SDL_main.h>
#include <SDL_main.h>
#endif
#include <base/utils/FindFile.h>
......@@ -64,54 +64,54 @@ int main(int argc, char *argv[])
{
#if SDL_VERSION_ATLEAST(2, 0, 0)
#ifdef ANDROID
SDL_SetMainReady( );
#endif
#ifdef ANDROID
SDL_SetMainReady( );
#endif
#endif
// Check if CG should look into a given directory
std::string binary_dir;
if(argc >= 1)
{
binary_dir = argv[0];
size_t slashpos = findLastPathSep(binary_dir);
if(slashpos != std::string::npos)
{
binary_dir.erase(slashpos);
// Check if CG should look into a given directory
std::string binary_dir;
if(argc >= 1)
{
binary_dir = argv[0];
size_t slashpos = findLastPathSep(binary_dir);
if(slashpos != std::string::npos)
{
binary_dir.erase(slashpos);
binary_dir = SystemNativeToUtf8(binary_dir);
}
else
{
binary_dir = ".";
}
}
else
{
warnings << "Binary-argument not given, assuming current dir" << endl;
binary_dir = ".";
}
SetBinaryDir( GetAbsolutePath(binary_dir) );
InitThreadPool();
}
else
{
binary_dir = ".";
}
}
else
{
warnings << "Binary-argument not given, assuming current dir" << endl;
binary_dir = ".";
}
SetBinaryDir( GetAbsolutePath(binary_dir) );
InitThreadPool();
InitSearchPaths(gSettings.getConfigFileName());
if( !gLogging.CreateLogfile("CGLog.html", APP_NAME, CGVERSION) )
{
errors << "Not even able to create \"CGLog.html\"." << endl;
return 1;
return 1;
}
// Init Video Driver with SDL all together
if( !gVideoDriver.init() )
// Init Video Driver with SDL all together
if( !gVideoDriver.init() )
{
return 1;
return 1;
}
// Check if there are settings on the PC, otherwise use defaults.
if( !gSettings.loadDrvCfg() )
// Check if there are settings on the PC, otherwise use defaults.
if( !gSettings.loadDrvCfg() )
{
//m_firsttime = true;
gLogging.textOut(FONTCOLORS::RED,"First time message: CG didn't find the driver config file. ");
......@@ -133,7 +133,7 @@ int main(int argc, char *argv[])
// Initialize CG and run the main cycle if worthy //
////////////////////////////////////////////////////
if( gApp.init( argc, argv ) )
{
{
////////////////////////////////
// Set GameLauncher as Engine //
////////////////////////////////
......@@ -143,10 +143,10 @@ int main(int argc, char *argv[])
// Run the Commander Genius //
//////////////////////////////
gApp.runMainCycle();
}
}
gSettings.saveDispCfg();
UnInitThreadPool();
return 0;
UnInitThreadPool();
return 0;
}
......@@ -661,19 +661,19 @@ void CGameLauncher::pumpEvent(const CEvent *evPtr)
if( const MouseWheelEvent *mwe = dynamic_cast<const MouseWheelEvent*>(evPtr) )
{
// Wrapper for the simple mouse scroll event
if(mwe->amount.y > 0.0)
if(mwe->amount.y > 0.0f)
{
mLauncherDialog.sendEvent(new CommandEvent( IC_UP ));
}
else if(mwe->amount.y < 0.0)
else if(mwe->amount.y < 0.0f)
{
mLauncherDialog.sendEvent(new CommandEvent( IC_DOWN ));
}
if(mwe->amount.x < 0.0)
if(mwe->amount.x < 0.0f)
{
mLauncherDialog.sendEvent(new CommandEvent( IC_RIGHT ));
}
else if(mwe->amount.x > 0.0)
else if(mwe->amount.x > 0.0f)
{
mLauncherDialog.sendEvent(new CommandEvent( IC_LEFT ));
}
......
......@@ -20,8 +20,8 @@ size_t bulletActionMap[] =
namespace galaxy
{
const Uint32 speed = 10;
const Uint32 hittime = 100;
//const Uint32 speed = 10;
//const Uint32 hittime = 100;
CBullet::CBullet(CMap *pmap, const Uint16 foeID, const Uint32 x, const Uint32 y,
const int xDir, const int yDir, const int sprVar) :
......
......@@ -29,43 +29,43 @@
#include <array>
struct EventEnterLevel : CEvent {
uint16_t data;
int mSprVar = 0;
EventEnterLevel(const int sprVar,
const uint16_t d) : data(d),
mSprVar(sprVar) {}
uint16_t data;
int mSprVar = 0;
EventEnterLevel(const int sprVar,
const uint16_t d) : data(d),
mSprVar(sprVar) {}
};
struct EventExitLevel : CEvent {
const uint16_t levelObject;
const bool sucess;
const bool teleport;
const int who;
bool playSound = false;
EventExitLevel(const uint16_t l, const bool s, const bool t, const bool lWho) :
levelObject(l), sucess(s), teleport(t), who(lWho) {}
const uint16_t levelObject;
const bool sucess;
const bool teleport;
const int who;
bool playSound = false;
EventExitLevel(const uint16_t l, const bool s, const bool t, const bool lWho) :
levelObject(l), sucess(s), teleport(t), who(lWho) {}
};
struct EventExitLevelWithFoot : CEvent {
const uint16_t levelObject;
const int who;
EventExitLevelWithFoot(const uint16_t l, const int lWho) : levelObject(l), who(lWho) {}
const uint16_t levelObject;
const int who;
EventExitLevelWithFoot(const uint16_t l, const int lWho) : levelObject(l), who(lWho) {}
};
struct EventDieKeenPlayer : CEvent
{
const int playerID;
const bool gameOver;
const int levelObj;
const std::string levelName;
EventDieKeenPlayer(const int id, const bool go, const int lo, const std::string &ln) :
playerID(id), gameOver(go),
levelObj(lo), levelName(ln){}
const int playerID;
const bool gameOver;
const int levelObj;
const std::string levelName;
EventDieKeenPlayer(const int id, const bool go, const int lo, const std::string &ln) :
playerID(id), gameOver(go),
levelObj(lo), levelName(ln){}
};
......@@ -73,59 +73,59 @@ namespace galaxy
{
enum PLAYER_ACTIONS
{
A_KEEN_STAND = 0,
A_KEEN_ON_PLAT,
A_KEEN_BORED,
A_KEEN_QUESTION,
A_KEEN_MOON,
A_KEEN_BOOK_OPEN,
A_KEEN_BOOK_READ,
A_KEEN_BOOK_CLOSE,
A_KEEN_LOOKUP,
A_KEEN_LOOKDOWN,
A_KEEN_ACTION_1,
A_KEEN_ACTION_2,
A_KEEN_ACTION_3,
A_KEEN_DIE,
A_KEEN_DIE_ALT,
A_KEEN_SHOOT,
A_KEEN_SHOOT_UP,
A_KEEN_ACTION_4,
A_KEEN_SLIDE,
A_KEEN_ENTER_DOOR,
A_KEEN_POLE,
A_KEEN_POLE_CLIMB,
A_KEEN_POLE_SLIDE,
A_KEEN_POLE_SHOOT,
A_KEEN_POLE_SHOOTUP,
A_KEEN_POLE_SHOOTDOWN,
A_KEEN_RUN,
A_KEEN_POGO_START,
A_KEEN_POGO_UP,
A_KEEN_POGO_HIGH,
A_KEEN_JUMP,
A_KEEN_JUMP_DOWN,
A_KEEN_FALL,
A_KEEN_JUMP_SHOOT,
A_KEEN_JUMP_SHOOTUP,
A_KEEN_JUMP_SHOOTDOWN,
A_KEEN_HANG,
A_KEEN_CLIMB,
A_KEEN_RIDING_ON_FOOT,
A_KEEN_STUNNED,
NUM_KEEN_ACTIONS
};
class CPlayerBase : public CGalaxySpriteObject
{
public:
/**
* \description Basic Constructor. An Object always need the pointer to the Map of the level,
* Coordinates as also the type of the Object
*/
enum PLAYER_ACTIONS
{
A_KEEN_STAND = 0,
A_KEEN_ON_PLAT,
A_KEEN_BORED,
A_KEEN_QUESTION,
A_KEEN_MOON,
A_KEEN_BOOK_OPEN,
A_KEEN_BOOK_READ,
A_KEEN_BOOK_CLOSE,
A_KEEN_LOOKUP,
A_KEEN_LOOKDOWN,
A_KEEN_ACTION_1,
A_KEEN_ACTION_2,
A_KEEN_ACTION_3,
A_KEEN_DIE,
A_KEEN_DIE_ALT,
A_KEEN_SHOOT,
A_KEEN_SHOOT_UP,
A_KEEN_ACTION_4,
A_KEEN_SLIDE,
A_KEEN_ENTER_DOOR,
A_KEEN_POLE,
A_KEEN_POLE_CLIMB,
A_KEEN_POLE_SLIDE,
A_KEEN_POLE_SHOOT,
A_KEEN_POLE_SHOOTUP,
A_KEEN_POLE_SHOOTDOWN,
A_KEEN_RUN,
A_KEEN_POGO_START,
A_KEEN_POGO_UP,
A_KEEN_POGO_HIGH,
A_KEEN_JUMP,
A_KEEN_JUMP_DOWN,
A_KEEN_FALL,
A_KEEN_JUMP_SHOOT,
A_KEEN_JUMP_SHOOTUP,
A_KEEN_JUMP_SHOOTDOWN,
A_KEEN_HANG,
A_KEEN_CLIMB,
A_KEEN_RIDING_ON_FOOT,
A_KEEN_STUNNED,
NUM_KEEN_ACTIONS
};
class CPlayerBase : public CGalaxySpriteObject
{
public:
/**
* \description Basic Constructor. An Object always need the pointer to the Map of the level,
* Coordinates as also the type of the Object
*/
CPlayerBase(CMap *pmap,
const Uint16 foeID,
Uint32 x,
......@@ -177,35 +177,35 @@ public:
/**
* \description Read the Input of the Player and sets the variables accordingly
*/
virtual void processInput();
virtual void processInput();
void processLevelMiscFlagsCheck();
void processLevelMiscFlagsCheck();
/**
* Produces the walking sound. To produce that sound correctly, it uses a special timer.
* That's the reason we need that aiding function
*/
void playWalkSound();
/**
* Produces the walking sound. To produce that sound correctly, it uses a special timer.
* That's the reason we need that aiding function
*/
void playWalkSound();
/**
* Make keen move with x/y speed move towards a target which is held in the variable "mTarget"
* it only moves towards, this routines is exec'd several times in order achieve a smooth transition.
*/
/**
* Make keen move with x/y speed move towards a target which is held in the variable "mTarget"
* it only moves towards, this routines is exec'd several times in order achieve a smooth transition.
*/
void guideToTarget(const Vector2D<int> &speed);
/**
/**
* Same here but with swimming. If moving set to true player is moving keen actually
*/
*/
void playSwimSound(const bool moving);
void respawnImportantItem(const int itemId);
bool touchedBottomOfMap();
void processDead();
void processDead();
virtual void processDying();
void processExiting();
......@@ -219,43 +219,43 @@ public:
virtual void kill(const bool force = false,
const bool noDieProcess = false) override;
/**
* Happens when usually the Dopefish eats Keen
*/
void getEaten();
/**
* Happens when usually the Dopefish eats Keen
*/
void getEaten();
/**
* Process the cycle when keen is getting eaten
*/
void processGetEaten();
/**
* Process the cycle when keen is getting eaten
*/
void processGetEaten();