Commit d9d3ea33 authored by Chad Anderson's avatar Chad Anderson

Revert "Cleanup"

This reverts commit 4c0081d1.
parent 4c0081d1
......@@ -45,25 +45,25 @@ static BOOL gFinderLaunch;
/* Set the working directory to the .app's parent directory */
- (void) setupWorkingDirectory:(BOOL)shouldChdir
{
char parentdir[MAXPATHLEN];
char *c;
strncpy ( parentdir, gArgv[0], sizeof(parentdir) );
c = (char*) parentdir;
while (*c != '\0') // go to end
c++;
while (*c != '/') // back up to parent
c--;
*c++ = '\0'; // cut off last part (binary name)
if (shouldChdir)
{
assert ( chdir (parentdir) == 0 ); // chdir to the binary app's parent
assert ( chdir ("../../../") == 0 ); // chdir to the .app's parent
}
char parentdir[MAXPATHLEN];
char *c;
strncpy ( parentdir, gArgv[0], sizeof(parentdir) );
c = (char*) parentdir;
while (*c != '\0') // go to end
c++;
while (*c != '/') // back up to parent
c--;
*c++ = '\0'; // cut off last part (binary name)
if (shouldChdir)
{
assert ( chdir (parentdir) == 0 ); // chdir to the binary app's parent
assert ( chdir ("../../../") == 0 ); // chdir to the .app's parent
}
}
void setupAppleMenu(void)
......
......@@ -5,7 +5,7 @@
* Author: gerstrong
* This Game-engine stripes down the main function
* and provides more dynamic control over the game engine itself
*
*
* It also manages the load of drivers and main game cycle itself which we divide
* Logic Per Second and Frames Per second processing
*/
......@@ -68,12 +68,12 @@ bool CGame::init(int argc, char *argv[])
g_pLogFile->textOut(RED,"However, it generated some default values and will save them now.\n");
g_pSettings->saveDrvCfg();
}
if(!g_pSettings->loadGameOptions())
{
g_pSettings->loadDefaultGameCfg();
}
// Setup the Hardware using the settings we have loaded
g_pLogFile->textOut(GREEN,"Loading hardware settings...<br>");
if(!loadCKPDrivers())
......@@ -121,74 +121,74 @@ bool CGame::loadCKPDrivers()
*/
void CGame::run()
{
float acc = 0.0f;
float start = 0.0f;
float elapsed = 0.0f;
float total_elapsed = 0.0f;
float curr = 0.0f;
int counter = 0;
float acc = 0.0f;
float start = 0.0f;
float elapsed = 0.0f;
float total_elapsed = 0.0f;
float curr = 0.0f;
int counter = 0;
while(1)
{
const float logicLatency = g_pTimer->LogicLatency();
const float renderLatency = g_pTimer->RenderLatency();
curr = timerTicks();
if(g_pTimer->resetLogicSingal())
start = curr;
elapsed = curr - start;
acc += elapsed;
start = timerTicks();
// Perform the game cycle
while( acc > logicLatency )
{
// Poll Inputs
g_pInput->pollEvents();
// Process Game Control
m_Engine.process();
// Here we try to process all the drawing related Tasks not yet done
g_pVideoDriver->pollDrawingTasks();
// Apply graphical effects if any. It does not render, it only prepares for the rendering task.
g_pGfxEngine->process();
acc -= logicLatency;
}
// Pass all the surfaces to one
g_pVideoDriver->collectSurfaces();
// Now you really render the screen
// When enabled, it also will apply Filters
g_pVideoDriver->updateScreen();
elapsed = timerTicks() - start;
total_elapsed += elapsed;
const float logicLatency = g_pTimer->LogicLatency();
const float renderLatency = g_pTimer->RenderLatency();
curr = timerTicks();
if(g_pTimer->resetLogicSingal())
start = curr;
elapsed = curr - start;
acc += elapsed;
start = timerTicks();
// Perform the game cycle
while( acc > logicLatency )
{
// Poll Inputs
g_pInput->pollEvents();
// Process Game Control
m_Engine.process();
// Here we try to process all the drawing related Tasks not yet done
g_pVideoDriver->pollDrawingTasks();
// Apply graphical effects if any. It does not render, it only prepares for the rendering task.
g_pGfxEngine->process();
acc -= logicLatency;
}
// Pass all the surfaces to one
g_pVideoDriver->collectSurfaces();
// Now you really render the screen
// When enabled, it also will apply Filters
g_pVideoDriver->updateScreen();
elapsed = timerTicks() - start;
total_elapsed += elapsed;
if( m_Engine.mustShutdown() || g_pInput->getExitEvent() )
break;
int waitTime = renderLatency - elapsed;
// wait time remaining in current loop
if( waitTime > 0 )
timerDelay(waitTime);
total_elapsed += static_cast<float>(waitTime);
// This will refresh the fps display, so it stays readable and calculates an average value.
counter++;
if(counter >= 100)
{
counter = 0;
g_pTimer->setTimeforLastLoop(total_elapsed/100.0f);
total_elapsed = 0.0f;
}
break;
int waitTime = renderLatency - elapsed;
// wait time remaining in current loop
if( waitTime > 0 )
timerDelay(waitTime);
total_elapsed += static_cast<float>(waitTime);
// This will refresh the fps display, so it stays readable and calculates an average value.
counter++;
if(counter >= 100)
{
counter = 0;
g_pTimer->setTimeforLastLoop(total_elapsed/100.0f);
total_elapsed = 0.0f;
}
}
}
......@@ -20,7 +20,7 @@ public:
void run();
void cleanup();
private:
bool m_firsttime;
CGameControl m_Engine;
......
......@@ -29,7 +29,7 @@ void CLogFile::CreateLogfile(const char *LogName)
std::string versionstring = CGVERSION;
textOut(BLUE, APP_NAME + " v" + versionstring);
// Mark the Build and Platform
#ifdef DEBUG
textOut("BUILD: DEBUG<br>");
......@@ -46,7 +46,7 @@ void CLogFile::CreateLogfile(const char *LogName)
#else
textOut("PLATFORM: UNKNOWN<br>");
#endif
// Ads
textOut("<br>");
std::string datestring = __DATE__;
......
......@@ -57,15 +57,15 @@ int CResourceLoader::RunLoadAction(Action* act, const std::string &threadname, i
bool CResourceLoader::process(int* ret)
{
float acc = 0.0f;
float start = 0.0f;
float elapsed = 0.0f;
float total_elapsed = 0.0f;
float curr = 0.0f;
int counter = 0;
float acc = 0.0f;
float start = 0.0f;
float elapsed = 0.0f;
float total_elapsed = 0.0f;
float curr = 0.0f;
int counter = 0;
if(!mp_Thread)
return false;
return false;
// Draw the first Frame, so transition looks complete!
g_pVideoDriver->clearDrawingTasks();
......@@ -83,7 +83,7 @@ bool CResourceLoader::process(int* ret)
curr = timerTicks();
elapsed = curr - start;
elapsed = curr - start;
acc += elapsed;
start = timerTicks();
......@@ -95,23 +95,23 @@ bool CResourceLoader::process(int* ret)
if(m_permil >= m_permiltarget)
{
setPermilage(m_permil+1);
setPermilage(m_permil+1);
}
else
{
int delta_permil = (m_permiltarget-m_permil)/2;
if(delta_permil == 0)
setPermilageForce(m_permil+1);
else
setPermilageForce(m_permil+delta_permil);
int delta_permil = (m_permiltarget-m_permil)/2;
if(delta_permil == 0)
setPermilageForce(m_permil+1);
else
setPermilageForce(m_permil+delta_permil);
}
// Here we try to process all the drawing related Tasks not yet done
g_pVideoDriver->pollDrawingTasks();
acc -= logicLatency;
}
}
// Pass all the surfaces to one
g_pVideoDriver->collectSurfaces();
......@@ -127,12 +127,12 @@ bool CResourceLoader::process(int* ret)
// wait time remaining in current loop
if( waitTime > 0 )
timerDelay(waitTime);
timerDelay(waitTime);
total_elapsed += static_cast<float>(waitTime);
// This will refresh the fps display, so it stays readable and calculates an average value.
counter++;
counter++;
if(counter >= 100)
{
counter = 0;
......@@ -146,7 +146,7 @@ bool CResourceLoader::process(int* ret)
setPermilage(m_max_permil);
renderLoadingGraphic();
g_pVideoDriver->pollDrawingTasks();
g_pVideoDriver->updateScreen();
g_pVideoDriver->updateScreen();
m_permiltarget = m_permil = m_min_permil;
......@@ -212,25 +212,25 @@ void CResourceLoader::renderLoadingGraphic()
rect.x = (320-width)/2;
rect.y = (200+height)/2;
rect.w = (width*m_permil)/1000;
rect.w = (width*m_permil)/1000;
rect.h = 4;
// Fade from yellow to green with this formula
Uint32 color = SDL_MapRGB(sfc->format, 200-(200*m_permil)/1000, 200, 0 );
SDL_FillRect(sfc, &rect, color);
}
else if(m_style == PROGRESS_STYLE_BAR)
{
{
const int width = 160;
const int height = 0;
SDL_Rect rect;
SDL_Rect bgRect;
rect.x = (320-width)/2;
rect.y = (200+height)/2;
rect.w = (width*m_permil)/1000;
rect.w = (width*m_permil)/1000;
rect.h = 4;
bgRect = rect;
......@@ -238,7 +238,7 @@ void CResourceLoader::renderLoadingGraphic()
bgRect.y--;
bgRect.w = width+2;
bgRect.h = 6;
// Fade from yellow to green with this formula
Uint32 color = SDL_MapRGB(sfc->format, 200-(200*m_permil)/1000, 200, 0 );
......
......@@ -29,23 +29,23 @@ enum ProgressStyle
class CResourceLoader : public CSingleton<CResourceLoader> {
public:
CResourceLoader();
void setStyle(ProgressStyle style);
int RunLoadAction(Action* act, const std::string &threadname, int min_permil=0, int max_permil=1000);
bool process(int* ret);
void setPermilage(int permil);
private:
void setPermilageForce(int permil);
void renderLoadingGraphic();
int m_permil;
int m_permiltarget;
int m_min_permil;
int m_max_permil;
ProgressStyle m_style;
std::unique_ptr<ThreadPoolItem> mp_Thread;
std::shared_ptr<SDL_Surface> mpProgressSfc;
......
......@@ -31,18 +31,18 @@ template <typename T>
class RingBuffer {
public:
RingBuffer():
mp_start(NULL),
mp_cur(NULL),
mp_end(NULL),
m_size(0)
mp_start(NULL),
mp_cur(NULL),
mp_end(NULL),
m_size(0)
{}
~RingBuffer()
{
if(!empty())
clear();
}
/**
* Allocates memory for the Ring buffer
*/
......@@ -53,18 +53,18 @@ public:
// TODO: throw exception here! This must never happen!
return false;
}
m_size = size;
if(m_size == 0)
return false;
mp_cur = new T[m_size];
mp_start = mp_cur;
mp_end = mp_start + m_size;
return true;
}
/**
* Clears the buffer without checking if ever was reserved. Be careful!
*/
......@@ -74,8 +74,8 @@ public:
mp_start = NULL;
m_size = 0;
}
/**
* Just checks and tells if the ring buffer is actually empty or not reserved
*/
......@@ -83,34 +83,34 @@ public:
{
return (m_size == 0 || mp_start == NULL);
}
/**
* Just tell whether the buffer of the as at the initial pointer which must be the same as at the end, because
* until this call, the pointer was rewound.
*/
bool atStart()
{ return (mp_cur == mp_start); }
/**
* Although a ring doesn't have a start, this function will set the pointer to first data chunk that on what it
* was initialized
*/
void gotoStart()
{ mp_cur=mp_start; }
/**
* Just return the absolute start of the pointer.
*/
T *getStartPtr()
{ return mp_start; }
/**
* Just return the absolute end of the pointer.
*/
T *getLastElem()
{ return mp_end-1; }
/**