Commit 92099ad4 authored by gerstrong's avatar gerstrong

copying backup back to the original source directory. This should resolve all tree conflicts

git-svn-id: https://clonekeenplus.svn.sourceforge.net/svnroot/clonekeenplus/cgenius/trunk@965 4df4b0f3-56ce-47cb-b001-ed939b7d65a6
parent 7e1a561e
#Sat Jan 10 20:53:00 CET 2009
eclipse.preferences.version=1
org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false
1 ICON "CGLogo.ico"
/*
* CGame.cpp
*
* Created on: 01.05.2009
* Author: gerstrong
* This Game-engine stripes down the main function
* and provides more dynamic control over the game
*/
#include <stdlib.h>
#include "CGame.h"
#include "common/CMenu.h"
#include "CLogFile.h"
#include "engine/vorticon/CCamera.h"
#include "sdl/CVideoDriver.h"
#include "sdl/CInput.h"
#include "sdl/CTimer.h"
#include "sdl/sound/CSound.h"
CGame::CGame() {
}
//////////////////////////////////
// Initialize Game Engine here! //
//////////////////////////////////
bool CGame::init(int argc, char *argv[])
{
CSettings Settings(m_option);
m_Engine.mp_option = m_option;
// Check if there are settings on the PC, otherwise use defaults.
if(!Settings.loadDrvCfg())
{
g_pLogFile->textOut(PURPLE,"First time message: CKP didn't find the driver config file. However, it generated some default values and will save them now.<br>");
if(g_pCamera->getScrollLeft() == -1)
g_pCamera->init();
Settings.saveDrvCfg();
}
if(g_pCamera->getScrollLeft() == -1)
g_pCamera->init();
if(!Settings.loadGameCfg()) Settings.loadDefaultGameCfg();
// Setup the Hardware using the settings we have loaded
g_pLogFile->textOut(GREEN,"Loading hardware settings...<br>");
if(!loadCKPDrivers())
{
g_pLogFile->textOut(RED,"The game cannot start, because you do not meet the hardware requirements.<br>");
return false;
}
// Initialize the way the launcher is started
if(!m_Engine.init(argc, argv)) return false;
return true;
}
// Load the driver needed to start the game
bool CGame::loadCKPDrivers()
{
// initialize/activate all drivers
g_pLogFile->ftextOut("Starting graphics driver...<br>");
// The graphics are very important, if the other subsystems fail, warn but continue
if (!g_pVideoDriver->start()) return false;
g_pLogFile->ftextOut("Starting sound driver...<br>");
g_pSound->init();
// g_pInput is started automatically when needed!
return true;
}
/////////////////////////////
// Process Game Engine here! //
/////////////////////////////
void CGame::run()
{
do
{
// Perform game logic
if (g_pTimer->TimeToLogic()) {
// Poll Inputs
g_pInput->pollEvents();
// Process Game Control
m_Engine.process();
}
// Render the Screen
if (g_pTimer->TimeToRender()) {
// Pass all the surfaces to one
g_pVideoDriver->collectSurfaces();
// Apply graphical effects if any
g_pGfxEngine->process();
// Now you really render the screen
// When enabled, it also will apply Filters
g_pVideoDriver->updateScreen();
}
// delay time remaining in current loop
g_pTimer->TimeToDelay();
} while(!m_Engine.mustShutdown() && !g_pInput->getExitEvent());
}
///////////////////////////////
// Cleanup Game Engine here! //
///////////////////////////////
void CGame::cleanup()
{
m_Engine.cleanupAll();
g_pInput->Del();
g_pSound->Del();
g_pVideoDriver->Del();
g_pTimer->Del();
}
CGame::~CGame() {
}
/*
* CGame.h
*
* Created on: 01.05.2009
* Author: gerstrong
*/
#ifndef CGAME_H_
#define CGAME_H_
#include "CGameControl.h"
#include "common/options.h"
// references to cinematics/CommonEnding
//int endsequence(stCloneKeenPlus *pCKP);
// Reference from game.cpp
//void initgame(stLevelControl *p_levelcontrol);
class CGame {
public:
CGame();
virtual ~CGame();
bool init(int argc, char *argv[]);
bool loadCKPDrivers();
void run();
void cleanup();
stOption m_option[NUM_OPTIONS];
private:
CGameControl m_Engine;
};
#endif /* CGAME_H_ */
This diff is collapsed.
/*
* CGameControl.h
*
* Created on: 22.09.2009
* Author: gerstrong
*
* Auxiliary Class for CGame. It only tell the Game-Engine what to do.
*/
#ifndef CGAMECONTROL_H_
#define CGAMECONTROL_H_
#include "common/CGameLauncher.h"
#include "common/CTeleporter.h"
#include "common/options.h"
#include "fileio/CSavedGame.h"
#include "engine/CEGAGraphics.h"
#include "engine/CMessages.h"
#include "engine/CPassive.h"
#include "engine/playgame/CPlayGame.h"
#include <string>
enum load_states{
LOADGFX=0x01,
LOADSTR=0x02,
LOADSND=0x04,
LOADALL=0xFF
};
class CGameControl {
public:
enum GameMode{
GAMELAUNCHER, PASSIVE, PLAYGAME, SHUTDOWN
};
CGameControl();
bool init(int argc, char *argv[]);
bool init(char mode=GAMELAUNCHER);
bool loadResources(unsigned short Episode, const std::string& DataDirectory, Uint8 flags=LOADALL);
bool loadMenuResources();
void process();
void cleanup(char mode);
void cleanupAll();
// getters and setters
bool mustShutdown(){ return (m_mode==SHUTDOWN); }
char m_mode;
stOption *mp_option;
virtual ~CGameControl();
private:
CGameLauncher *mp_GameLauncher;
CPassive *mp_PassiveMode;
CPlayGame *mp_PlayGame;
CSavedGame m_SavedGame;
bool m_endgame;
bool m_show_finale;
Uint8 m_Episode;
Uint8 m_Numplayers;
Uint8 m_ChosenGame;
Uint8 m_Difficulty;
std::string m_DataDirectory;
int current_demo;
Uint8 m_startLevel;
std::vector<stTeleporterTable> m_TeleporterTable; // Teleporter table used for the destinations
CEGAGraphics *m_EGAGraphics;
};
#endif /* CGAMECONTROL_H_ */
/*
* CLogFile.cpp
*
* Created on: 20.04.2009
* Author: gerstrong
*/
#include <stdarg.h>
#include <iostream>
#include <string.h>
#include "CLogFile.h"
#include <fstream>
#include "FindFile.h"
#include "Debug.h"
CLogFile::CLogFile() {}
CLogFile::~CLogFile() {
// Logfile End
textOut ("<br><br>End of logfile</font></body></html>");
fclose (m_Logfile);
}
void CLogFile::CreateLogfile(const char *LogName)
{
// Open and empty the log file
m_Logfile = OpenGameFile(LogName, "wt");
// Write the head
textOut("<html><head><title>LogFile</title></head>");
textOut("<body><font face='courier new'>");
WriteTopic("Logfile", 3);
textOut(BLUE,REVISION);
// Mark the Build and Platform
#ifdef DEBUG
textOut("BUILD: DEBUG<br>");
#else
textOut("BUILD: RELEASE<br>");
#endif
#ifdef TARGET_LNX
textOut("PLATFORM: LINUX<br>");
#elif TARGET_WIN32
textOut("PLATFORM: WINDOWS<br>");
#elif __APPLE__
textOut("PLATFORM: MAC OS X<br>");
#else
textOut("PLATFORM: UNKNOWN<br>");
#endif
// Show my e-mail adress
textOut("<a href='mailto:gerstrong@gmail.com?subject=CG Logfile'>");
textOut("Send E-Mail to me</a><br><br>");
fclose(m_Logfile);
m_Logfile = OpenGameFile(LogName, "at");
}
// Function for writing the topic
void CLogFile::WriteTopic(const char *Topic, int Size)
{
textOut("<table cellspacing='0' cellpadding='0' width='100%%' bgcolor='#DFDFE5'>\n");
textOut("<tr>\n<tr>\n<td>\n");
ftextOut("<font face='arial' size='+%i'>\n", Size);
textOut(Topic);
textOut("</font>\n</td>\n</tr>\n</table>\n<br>");
fflush(m_Logfile);
}
// The main textOut function
// Standard textOut (Black color)
// Now with colors
void CLogFile::textOut(FONTCOLORS Color, const std::string& Text)
{
textOut(Color, false, Text);
}
// Now the entire definition (with list and color)
void CLogFile::textOut(FONTCOLORS Color, bool List, const std::string& Text)
{
if(List == true)
textOut("<li>");
// write color tag
switch(Color)
{
case BLACK:
textOut("<font color=black>"); break;
case RED:
textOut("<font color=red>"); break;
case GREEN:
textOut("<font color=green>"); break;
case BLUE:
textOut("<font color=blue>"); break;
case PURPLE:
textOut("<font color=purple>"); break;
};
// Write the text
textOut(Text);
textOut("</font>");
if (List == false)
textOut("<br>");
else
textOut("</li>");
}
std::string CLogFile::removeHTML(const std::string& input)
{
std::string::size_type left, right;
std::string output;
output = input;
do {
left = output.find_first_of('<', 0);
right = output.find_first_of('>', 0);
if( left == std::string::npos || right == std::string::npos )
break;
output = output.erase( left, right-left+1 );
} while( 1 );
return output;
}
void CLogFile::textOut(const std::string& Text)
{
std::string output;
output = removeHTML(Text);
if( output.length() > 0 ) {
notes << output << endl;
}
fprintf(m_Logfile,"%s",Text.c_str());
fflush(m_Logfile);
}
void CLogFile::ftextOut(const char *Text, ...)
{
char buffer[MAX_BUFFER];
va_list pArgList;
va_start(pArgList, Text);
vsprintf(buffer, Text, pArgList);
va_end(pArgList);
textOut(buffer);
}
void CLogFile::fltextOut(FONTCOLORS Color, bool List, const char *Text, ...)
{
char buffer[MAX_BUFFER];
va_list pArgList;
va_start(pArgList, Text);
vsprintf(buffer, Text, pArgList);
va_end(pArgList);
textOut(Color, List, buffer);
}
void CLogFile::ftextOut(FONTCOLORS Color, const char *Text, ...)
{
char buffer[MAX_BUFFER];
va_list pArgList;
va_start(pArgList, Text);
vsprintf(buffer, Text, pArgList);
va_end(pArgList);
textOut(Color, buffer);
}
void CLogFile::FunctionResult (const char *Name,bool Result)
{
if (Result == true)
{
textOut("<table width='100%%' cellSpacing='1' cellPadding='5'>");
textOut(" border='0' bgcolor='C0C0C0'><tr><td bgcolor=");
ftextOut("'#FFFFFF' width='35%%'>%s</TD>", Name);
textOut("<td bgcolor='#FFFFFF' width='30%%'><font color =");
textOut("'green'>OK</FONT></TD><td bgcolor='#FFFFFF' ");
textOut("width='35%%'>-/-</TD></tr></table>");
}
else
{
textOut("<table width='100%%' cellSpacing='1' cellPadding='5'>");
textOut(" border='0' bgcolor='C0C0C0'><tr><td bgcolor=");
ftextOut("'#FFFFFF' width='35%%'>%s</TD>", Name);
textOut("<td bgcolor='#FFFFFF' width='30%%'><font color =");
textOut("'red'>ERROR</FONT></TD><td bgcolor='#FFFFFF' ");
textOut("width='35%%'>-/-</TD></tr></table>");
}
}
/*
* CLogFile.h
*
* Created on: 20.04.2009
* Author: gerstrong
*/
#ifndef CLOGFILE_H_
#define CLOGFILE_H_
#define REVISION "Commander Genius Release v0.3.1.0"
#include "CSingleton.h"
#include <string>
#define g_pLogFile CLogFile::Get()
#define MAX_BUFFER 1024
enum FONTCOLORS
{
BLACK,
RED,
GREEN,
BLUE,
PURPLE
};
class CLogFile : public CSingleton <CLogFile>
{
public:
CLogFile();
virtual ~CLogFile();
void CreateLogfile (const char *LogName);
void WriteTopic (const char *Topic, int Size);
void textOut (const std::string& Text);
void textOut (FONTCOLORS Color, const std::string& Text);
void textOut (FONTCOLORS Color, bool List, const std::string& Text);
void ftextOut (const char *Text, ...);
void ftextOut (FONTCOLORS Color, const char *Text, ...);
void fltextOut (FONTCOLORS Color, bool List, const char *Text, ...);
void FunctionResult (const char *Name, bool Result);
private:
FILE *m_Logfile;
std::string removeHTML(const std::string& input);
};
#endif /* CLOGFILE_H_ */
/*
* CSingleton.h
*
* Created on: 19.04.2009
* Author: gerstrong
*/
#ifndef CSINGLETON_H_
#define CSINGLETON_H_
#include <stdio.h>
template <class T>
class CSingleton {
protected:
static T *m_pSingleton; // Static Object
public:
//CSingleton();
inline static T* Get()
{
if(!m_pSingleton)
m_pSingleton = new T;
return (m_pSingleton);
}
static void Del()
{
if(m_pSingleton)
{
delete (m_pSingleton);
m_pSingleton = NULL;
}
}
virtual ~CSingleton() // Unused, because this class is never constructed!!
{}
};
template <class T>
T* CSingleton<T>::m_pSingleton = NULL;
#endif /* CSINGLETON_H_ */
/////////////////////////////////////////
//
// OpenLieroX
//
// Auxiliary Software class library
//
// based on the work of JasonB
// enhanced by Dark Charlie and Albert Zeyer
//
// code under LGPL
//
/////////////////////////////////////////
// 2D Vector / Matrix class
// Created 20/11/01
// By Jason Boettcher
// enhanced by Albert Zeyer
#ifndef __CVEC_H__
#define __CVEC_H__
#include <cmath>
template<typename _T>
struct VectorD2 {
// Constructor
VectorD2() : x(0), y(0) {}
VectorD2(_T _x, _T _y) : x(_x), y(_y) {}
// Attributes
_T x, y;
// Methods
template<typename _T2>
VectorD2(const _T2& cp) {
x = (_T)cp.x; y = (_T)cp.y;
}
float GetLength() const { return sqrtf((float)x*x + (float)y*y); }
_T GetLength2() const { return x*x + y*y; };
float GetAngle() const { return (float)atan2((float)y,(float)x); }
VectorD2 Normalize() { return *this/GetLength(); }
_T Scalar(const VectorD2& vec) const { return x*vec.x + y*vec.y; }
VectorD2 orthogonal() const { return VectorD2(y, -x); }
_T Cross(const VectorD2& oth) const { return x * oth.y - y * oth.x; }
// Overloads
VectorD2 operator*(const float scalar) const {
return VectorD2(x*scalar,y*scalar);
}
VectorD2 operator*(const int scalar) const {
return VectorD2(x*scalar,y*scalar);
}
/*
VectorD2 operator*(const VectorD2& vec) const {
// WARNING: this doesn't make any sense (in most 'mathematical' cases)
// TODO: why is it here? I would expect dot product or cross product...
return VectorD2(x*vec.x,y*vec.y);
}