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

Compilation optimizations and speedups

parent 0956e6d2
......@@ -11,8 +11,9 @@
#include <SDL.h>
#include <string>
#include <list>
#include <vector>
#include <base/utils/Geometry.h>
#include <base/GsEvent.h>
#include <base/GsEventContainer.h>
#include <base/InputEvents.h>
#include <base/Singleton.h>
......
......@@ -6,7 +6,7 @@
*/
#ifndef __GSAPP_H_
#define __GSAPP_H_
#define GSAPP_H
#include <base/GsEvent.h>
#include <base/GsEngine.h>
......@@ -69,4 +69,4 @@ private:
// It's a simple quit event which will force CG to close the App
struct GMQuit : CEvent {};
#endif /* __GSAPP_H_ */
#endif /* GSAPP_H */
......@@ -2,11 +2,6 @@
#define GSEVENT_H
#include "base/Singleton.h"
#include <vector>
#include <deque>
#include <list>
#include <memory>
#include <ctime>
struct CEvent { virtual ~CEvent(); };
......@@ -29,138 +24,6 @@ public:
};
#define gEventManager CEventContainer::get()
class CEventContainer : public GsSingleton<CEventContainer>
{
public:
size_t size() { return m_EventList.size(); }
bool empty() { return m_EventList.empty(); }
void clear() { m_EventList.clear(); }
/**
* @brief regSink will register the sink in the Container
* when you are destroying the object, you must call unregSink() first!
* Otherwise app might crash.
* @param pSink pointer to the sink to be registered
*/
void regSink(GsEventSink *pSink)
{
mSinkPtrList.push_back(pSink);
}
void unregSink(GsEventSink *pSink)
{
mSinkPtrList.remove(pSink);
}
void processSinks()
{
// First check if there are pendingEvents to be processed
if(m_EventList.empty())
return;
// Make a copy of that list, because the original
// could change, while pumping happens
for(auto &ev : m_EventList)
{
mPumpEventPtrs.push_back(ev);
}
// We don't need anything from this list anymore
m_EventList.clear();
for( GsEventSink* sink : mSinkPtrList )
{
for( auto &event : mPumpEventPtrs )
{
sink->pumpEvent( event.get() );
if(mFlush)
break;
}
if(mFlush)
break;
}
mPumpEventPtrs.clear();
mFlush = false;
}
void flush()
{
m_EventList.clear();
mFlush = true;
}
void add(std::shared_ptr<CEvent>& ev)
{
m_EventList.push_back(ev);
}
// template version
template <class _T>
void add()
{
_T *ev = new _T;
m_EventList.push_back(std::shared_ptr<CEvent>(ev));
}
void add(CEvent *ev)
{
m_EventList.push_back(std::shared_ptr<CEvent>(ev));
}
void wait(const float time)
{
timepoint = clock();
pausetime = static_cast<clock_t>(time*static_cast<float>(CLOCKS_PER_SEC));
}
void update()
{
if(pausetime<=0.0f)
return;
const clock_t newTime = clock();
const clock_t passed = newTime-timepoint;
timepoint = newTime;
pausetime -= passed;
return;
}
std::deque< std::shared_ptr<CEvent> >::iterator erase(std::deque< std::shared_ptr<CEvent> >::iterator &it)
{ return m_EventList.erase(it); }
std::deque< std::shared_ptr<CEvent> >::iterator begin() { return m_EventList.begin(); }
std::deque< std::shared_ptr<CEvent> >::iterator end() { return m_EventList.end(); }
template<typename T> T* occurredEvent();
void pop_Event() { m_EventList.pop_front(); }
private:
std::list< GsEventSink* > mSinkPtrList;
std::deque< std::shared_ptr<CEvent> > m_EventList;
std::vector< std::shared_ptr<CEvent> > mPumpEventPtrs;
clock_t pausetime = 0;
clock_t timepoint = 0;
bool mFlush = false;
};
template<typename T>
T* CEventContainer::occurredEvent()
{
if(m_EventList.empty() || pausetime > 0 )
return nullptr;
return dynamic_cast<T*> (m_EventList.front().get());
}
#endif /* GSEVENT_H */
#include "GsEventContainer.h"
void CEventContainer::processSinks()
{
// First check if there are pendingEvents to be processed
if(m_EventList.empty())
return;
// Make a copy of that list, because the original
// could change, while pumping happens
for(auto &ev : m_EventList)
{
mPumpEventPtrs.push_back(ev);
}
// We don't need anything from this list anymore
m_EventList.clear();
for( GsEventSink* sink : mSinkPtrList )
{
for( auto &event : mPumpEventPtrs )
{
sink->pumpEvent( event.get() );
if(mFlush)
break;
}
if(mFlush)
break;
}
mPumpEventPtrs.clear();
mFlush = false;
}
void CEventContainer::update()
{
if(pausetime<=0.0f)
return;
const clock_t newTime = clock();
const clock_t passed = newTime-timepoint;
timepoint = newTime;
pausetime -= passed;
return;
}
#ifndef GSEVENTCONTAINER_H
#define GSEVENTCONTAINER_H
#include "GsEvent.h"
#include <vector>
#include <deque>
#include <list>
#include <memory>
#include <ctime>
#define gEventManager CEventContainer::get()
class CEventContainer : public GsSingleton<CEventContainer>
{
public:
size_t size() { return m_EventList.size(); }
bool empty() { return m_EventList.empty(); }
void clear() { m_EventList.clear(); }
/**
* @brief regSink will register the sink in the Container
* when you are destroying the object, you must call unregSink() first!
* Otherwise app might crash.
* @param pSink pointer to the sink to be registered
*/
void regSink(GsEventSink *pSink)
{
mSinkPtrList.push_back(pSink);
}
void unregSink(GsEventSink *pSink)
{
mSinkPtrList.remove(pSink);
}
/**
* @brief processSinks processor of the added event within the applications
*/
void processSinks();
void flush()
{
m_EventList.clear();
mFlush = true;
}
void add(std::shared_ptr<CEvent>& ev)
{
m_EventList.push_back(ev);
}
// template version
template <class _T>
void add()
{
_T *ev = new _T;
m_EventList.push_back(std::shared_ptr<CEvent>(ev));
}
void add(CEvent *ev)
{
m_EventList.push_back(std::shared_ptr<CEvent>(ev));
}
void wait(const float time)
{
timepoint = clock();
pausetime = static_cast<clock_t>(time*static_cast<float>(CLOCKS_PER_SEC));
}
void update();
std::deque< std::shared_ptr<CEvent> >::iterator erase(std::deque< std::shared_ptr<CEvent> >::iterator &it)
{ return m_EventList.erase(it); }
std::deque< std::shared_ptr<CEvent> >::iterator begin() { return m_EventList.begin(); }
std::deque< std::shared_ptr<CEvent> >::iterator end() { return m_EventList.end(); }
template<typename T> T* occurredEvent();
void pop_Event() { m_EventList.pop_front(); }
private:
std::list< GsEventSink* > mSinkPtrList;
std::deque< std::shared_ptr<CEvent> > m_EventList;
std::vector< std::shared_ptr<CEvent> > mPumpEventPtrs;
clock_t pausetime = 0;
clock_t timepoint = 0;
bool mFlush = false;
};
template<typename T>
T* CEventContainer::occurredEvent()
{
if(m_EventList.empty() || pausetime > 0 )
return nullptr;
return dynamic_cast<T*> (m_EventList.front().get());
}
#endif /* GSEVENTCONTAINER_H */
......@@ -22,8 +22,8 @@ GsBitmap::GsBitmap(const GsWeakSurface &sfc)
}
GsBitmap::GsBitmap(const GsBitmap &bitmap) :
mName(bitmap.getName())
GsBitmap::GsBitmap(const GsBitmap &bitmap)/* :
mName(bitmap.getName())*/
{
if(bitmap.empty())
{
......@@ -33,8 +33,8 @@ mName(bitmap.getName())
mBitmapSurface.createCopy(bitmap.mBitmapSurface);
}
GsBitmap::GsBitmap(GsBitmap &bitmap) :
mName(bitmap.getName())
GsBitmap::GsBitmap(GsBitmap &bitmap)/* :
mName(bitmap.getName())*/
{
if(bitmap.empty())
{
......@@ -51,7 +51,7 @@ mName(bitmap.getName())
*/
GsBitmap & GsBitmap::operator=(const GsBitmap &bmp)
{
mName = bmp.getName();
//mName = bmp.getName();
if(!bmp.empty())
{
......
......@@ -83,8 +83,8 @@ public:
void setColorKey(const Uint8 r, const Uint8 g, const Uint8 b);
bool scaleTo(const GsRect<Uint16> &destRes);
std::string getName() const { return mName; }
void setName(const std::string &name) { mName = name; }
// std::string getName() const { return mName; }
// void setName(const std::string &name) { mName = name; }
/**
......@@ -101,7 +101,7 @@ public:
void _draw(const int x, const int y, SDL_Surface *dst) const;
private:
std::string mName;
//std::string mName;
GsSurface mBitmapSurface;
};
......
......@@ -263,6 +263,12 @@ GsTilemap &GsGraphics::getTileMap(size_t tilemap)
std::vector<GsTilemap> &GsGraphics::getTileMaps()
{ return Tilemap; }
void GsGraphics::setBitmapNameForIdx(const std::string name,
const int idx)
{
mBitmapNameToIdx[name] = idx;
}
GsBitmap &GsGraphics::getBitmapFromId(const int var,
const int slot)
//{ return mBitmap[var][slot]; }
......@@ -290,22 +296,17 @@ GsFont &GsGraphics::getFont(Uint8 index)
GsBitmap *GsGraphics::getBitmapFromStr(const int sprVar,
const std::string &name) const
{
std::string s_name;
//const auto bmpVecIdx = sprVar;
const auto bmpVecIdx = 0;
for(unsigned int i=0 ; i<mBitmap[bmpVecIdx].size() ; i++)
{
auto &bitmap = mBitmap[bmpVecIdx][i];
s_name = bitmap.getName();
auto it = mBitmapNameToIdx.find(name);
if(s_name == name)
{
return const_cast<GsBitmap*>(&bitmap);
}
}
if(it != mBitmapNameToIdx.end())
{
const int idx = it->second;
auto &bitmap = mBitmap[bmpVecIdx][size_t(idx)];
return const_cast<GsBitmap*>(&bitmap);
}
std::string error = "Ooops! Wrong TextID ";
error += "name";
......
......@@ -23,6 +23,7 @@
#include <vector>
#include <memory>
#include <unordered_map>
#include <string>
#include <base/Singleton.h>
#define gGraphics GsGraphics::get()
......@@ -62,6 +63,11 @@ public:
GsTilemap &getTileMap(size_t tilemap);
std::vector<GsTilemap> &getTileMaps();
void setBitmapNameForIdx(const std::string name,
const int idx);
GsBitmap &getBitmapFromId(const int var,
const int slot);
GsBitmap &getMaskedBitmap(Uint16 slot);
......@@ -93,11 +99,16 @@ private:
std::vector<GsFont> Font;
std::vector<GsTilemap> Tilemap;
std::vector< std::vector<GsBitmap> > mBitmap;
std::unordered_map<std::string, int> mBitmapNameToIdx;
std::vector<GsBitmap> maskedBitmap;
std::vector<GsBitmap> miscGsBitmap;
std::vector< std::vector<GsSprite> > mSprite;
std::unordered_map<std::string, GsSprite> mSpecialSpriteMap;
};
......
......@@ -10,6 +10,7 @@
#include <string>
#include <memory>
#include <list>
#include <graphics/GsSurface.h>
#include "GsButton.h"
......
......@@ -10,8 +10,7 @@
#include "GsControl.h"
#include <string>
//#include "engine/CEvent.h"
#include <memory>
class CGUIInputText : public GsControl
{
......
......@@ -11,6 +11,8 @@
#define CGUITEXT_H_
#include <string>
#include <list>
#include <memory>
#include "GsControl.h"
......
......@@ -67,35 +67,8 @@ ENDIF()
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/GsKit)
#set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/CMake)
# Try to use Ogg if enabled
#IF (OGG)
# IF(BUILD_TARGET STREQUAL WIN32)
#set(VORBIS_INCLUDE_DIR ${CMAKE_INCLUDE_PATH})
#ELSE(BUILD_TARGET STREQUAL WIN32)
# FIND_PATH(VORBIS_INCLUDE_DIR vorbis/vorbisfile.h DOC "Include for Ogg Vorbis")
# ENDIF()
# SET(VORBIS_INCLUDE_PATH "${VORBIS_INCLUDE_DIR}/vorbis")
# ADD_DEFINITIONS(-DOGG)
# INCLUDE_DIRECTORIES(${VORBIS_INCLUDE_PATH})
# INCLUDE_DIRECTORIES(${VORBIS_INCLUDE_DIR})
#ENDIF (OGG)
#IF (TREMOR)
#FIND_PATH(TREMOR_INCLUDE_DIR
#ivorbisfile.h
#PATHS /usr/include /usr/include/tremor
# DOC "Include for Tremor")
#INCLUDE_DIRECTORIES(${TREMOR_INCLUDE_DIR})
#ADD_DEFINITIONS(-DTREMOR)
#ENDIF (TREMOR)
# If we want to debug set the proper flags or have release etc.
IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
ADD_DEFINITIONS(-DDEBUG)
......@@ -220,11 +193,6 @@ target_link_libraries(CGeniusExe sdl_extensions_audio sdl_extensions_sys)
if(USE_SDL2)
message(STATUS "SDL2_LIBRARY = ${SDL2_LIBRARY}")
message(STATUS "SDL2IMAGE_LIBRARY = ${SDL2IMAGE_LIBRARY}")
else(USE_SDL2)
# SDL stuff to link
# target_link_libraries(CGeniusExe ${SDL_NET_LIBRARIES})
# target_link_libraries(CGeniusExe ${SDL_LIBRARY})
# target_link_libraries(CGeniusExe ${SDL_IMAGE_LIBRARY})
endif(USE_SDL2)
......@@ -232,11 +200,8 @@ endif(USE_SDL2)
# The Windows Version has an icon in the executable
IF(WIN32)
SET_TARGET_PROPERTIES(CGeniusExe PROPERTIES OUTPUT_NAME "CGenius")
# ADD_CUSTOM_COMMAND(TARGET CGeniusExe PRE_LINK COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/src/CGLogo.rc ${CMAKE_CURRENT_SOURCE_DIR}/CGLogo.rc )
# ADD_CUSTOM_COMMAND(TARGET CGeniusExe PRE_LINK COMMAND ${mingw64dir}bin/icotool -c -o ${CMAKE_CURRENT_SOURCE_DIR}/CGLogo.ico ${CMAKE_CURRENT_SOURCE_DIR}/vfsroot/cglogo512.png )
ADD_CUSTOM_COMMAND(TARGET CGeniusExe PRE_LINK COMMAND windres ${CMAKE_CURRENT_SOURCE_DIR}/CGLogo.rc ${CMAKE_CURRENT_SOURCE_DIR}/CGLogo.o)
SET_TARGET_PROPERTIES(CGeniusExe PROPERTIES LINK_FLAGS "-mwindows ${CMAKE_CURRENT_SOURCE_DIR}/CGLogo.o")
# LINK_DIRECTORIES(/opt/mingw32/lib)
MESSAGE(STATUS "Will build with the CG-Icon for Windows." )
ENDIF(WIN32)
......@@ -247,9 +212,7 @@ if(WIN32)
target_link_libraries(CGeniusExe mingw32)
target_link_libraries(CGeniusExe user32)
target_link_libraries(CGeniusExe gdi32)
#target_link_libraries(CGeniusExe SDL2Main SDL2)
target_link_libraries(CGeniusExe SDL2Main)
#target_link_libraries(CGeniusExe SDL2_image)
target_link_libraries(CGeniusExe winmm)
target_link_libraries(CGeniusExe Imm32)
target_link_libraries(CGeniusExe Version)
......
......@@ -98,8 +98,8 @@ public:
std::vector<stTeleporterTable>& getTeleporterTable()
{ return m_TeleporterTable; }
CEventContainer &EventList()
{ return gEventManager; }
//CEventContainer &EventList()
//{ return gEventManager; }
void setEpisode(const size_t Episode)
{ mEpisode = Episode; }
......
......@@ -8,6 +8,7 @@
#include "engine/core/spritedefines.h"
#include "CSpriteObject.h"
#include <base/GsLogging.h>
#include <base/GsEventContainer.h>
#include <base/video/CVideoDriver.h>
#include <base/utils/FindFile.h>
......
......@@ -9,8 +9,8 @@
*/
#ifndef __CSpriteObject_H_
#define __CSpriteObject_H_
#ifndef CSpriteObject_H
#define CSpriteObject_H
#include <base/GsEvent.h>
......@@ -439,4 +439,4 @@ struct EventSpawnObject : CEvent {
pObject( pObject ) {}
};
#endif // __CSpriteObject_H_
#endif // CSpriteObject_H_
......@@ -11,6 +11,7 @@
#include <widgets/GsMenuController.h>
#include "LoadMenu.h"
#include <base/GsEventContainer.h>
#include "fileio/CSaveGameController.h"
#include "engine/core/CBehaviorEngine.h"
......
......@@ -11,6 +11,7 @@
#include <graphics/GsGraphics.h>
#include <base/video/CVideoDriver.h>
#include <base/GsApp.h>
#include <base/GsEventContainer.h>
#include <memory>
CGamePlayMode::CGamePlayMode(const int Episode,
......
......@@ -2,6 +2,7 @@
#include <widgets/GsProgressbar.h>
#include <widgets/GsButton.h>
#include <base/GsApp.h>
#include <base/GsEventContainer.h>
#include <base/utils/FindFile.h>
#include <base/utils/ThreadPool.h>
......
......@@ -7,6 +7,7 @@
#include "CMessageBoxBitmapGalaxy.h"
#include <base/video/CVideoDriver.h>
#include <base/GsEventContainer.h>
#include "dialog/CMessageBox.h"
......
......@@ -44,6 +44,8 @@ mSprVar(sprVar)
mMBRect.y = (gameRes.h-mMBRect.h)/2;
}
CMessageBoxGalaxy::~CMessageBoxGalaxy() {}
void CMessageBoxGalaxy::init()
{
mMBSurface.createRGBSurface(mMBRect);
......
......@@ -8,10 +8,10 @@
#ifndef CMESSAGEBOXGALAXY_H_
#define CMESSAGEBOXGALAXY_H_
//#include <base/utils/CVec.h>
#include <string>
#include <SDL.h>
#include <memory>
#include <vector>
#include <base/GsEvent.h>
#include <graphics/GsSurface.h>
......@@ -24,6 +24,8 @@ class CMessageBoxGalaxy
{
public:
virtual ~CMessageBoxGalaxy();
/**
* \brief This constructor creates a typical Keen Galaxy Message Box
* \param Text Message to be shown
......
......@@ -10,6 +10,7 @@
#include "CMessageBoxGalaxy.h"
#include <base/GsEvent.h>
#include <list>
/**
* \description small structure which bind a string to an event.
......@@ -31,7 +32,8 @@ public:
* Options that can be selected
* \param Text Message to be shown
*/
CMessageBoxSelection( const std::string& Text, const std::list<TextEventMatchOption> &Options );
CMessageBoxSelection( const std::string& Text,
const std::list<TextEventMatchOption> &Options );
void init();
......
......@@ -1146,7 +1146,7 @@ bool CEGAGraphicsGalaxy::readBitmaps()
auto &bmpName = bitmapNamesThisEp[i];
bitmap.setName(bmpName);
gGraphics.setBitmapNameForIdx(bmpName, i);
for(const auto &bmpFile : bmpFileList)
{
......
......@@ -20,7 +20,7 @@
#include <stdio.h>
#include <string.h>
CEGALatch::CEGALatch( int planesize,
CEGALatch::CEGALatch(int planesize,
long bitmaptablelocation,
short fonttiles,
long fontlocation,
......@@ -29,8 +29,7 @@ CEGALatch::CEGALatch( int planesize,
short num16tiles,
long tiles16location,
short bitmaps,
long bitmaplocation) :
RawData(NULL)
long bitmaplocation)
{
m_latchplanesize = planesize;
m_bitmaptablelocation = bitmaptablelocation;
......@@ -65,7 +64,7 @@ bool CEGALatch::loadHead( char *data, short m_episode )
name = name.substr(0,8); // Cut the rest of data down, if junk detected in the exe file
TrimSpaces(name);
if( name != "" ) Bitmap.setName( name );
if( name != "" ) gGraphics.setBitmapNameForIdx(name, i);
else
{
if (m_episode == 1)
......@@ -73,20 +72,20 @@ bool CEGALatch::loadHead( char *data, short m_episode )
const std::string default_names[] = { "TITLE", "IDLOGO", "F1HELP", "HIGHSCOR",
"NAME", "SCORE", "PARTS", "GAMEOVER", "AN", "PRESENT", "APOGEE", "KEENSHIP", "WINDON",
"WINDOFF", "ONEMOMEN", "OFAN", "PRODUCT", "IDSOFT" }; // in case the names are empty
Bitmap.setName( default_names[i] );
gGraphics.setBitmapNameForIdx(default_names[i], i);
}
else if (m_episode == 2)
{
const std::string default_names[] = { "TITLE", "IDLOGO", "F1HELP", "HIGHSCOR",
"NAME", "SCORE", "SAVED", "GAMEOVER", "AN", "PRESENT", "APOGEE", "KEENSHIP", "WINDON",
"WINDOFF", "ONEMOMEN", "OFAN", "PRODUCT", "IDSOFT" }; // in case the names are empty
Bitmap.setName( default_names[i] );
gGraphics.setBitmapNameForIdx(default_names[i], i);