Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
299 KB
Referenced Files
None
Subscribers
None
This file is larger than 256 KB, so syntax highlighting was skipped.
diff --git a/include/r-tech1/argument.h b/include/r-tech1/argument.h
index d9d3c9ff..981b0d1d 100644
--- a/include/r-tech1/argument.h
+++ b/include/r-tech1/argument.h
@@ -1,34 +1,34 @@
-#ifndef _rtech_util_argument_h
-#define _rtech_util_argument_h
+#ifndef _rtech1_util_argument_h
+#define _rtech1_util_argument_h
#include <vector>
#include <string>
#include "pointer.h"
class ArgumentAction{
public:
virtual void act() = 0;
virtual ~ArgumentAction();
};
typedef std::vector<Util::ReferenceCount<ArgumentAction> > ActionRefs;
class Argument{
public:
/* Keywords on the command line that should invoke this argument */
virtual std::vector<std::string> keywords() const = 0;
/* Parse more strings from the command line. Any actions that should take place
* after the command line has been parsed should be put into 'actions'
*/
virtual std::vector<std::string>::iterator parse(std::vector<std::string>::iterator current, std::vector<std::string>::iterator end, ActionRefs & actions) = 0;
/* Description of what this argument does */
virtual std::string description() const = 0;
bool isArg(const std::string & what) const;
virtual ~Argument();
};
#endif
diff --git a/include/r-tech1/compress.h b/include/r-tech1/compress.h
index 62a6f3c5..d8cf8c72 100644
--- a/include/r-tech1/compress.h
+++ b/include/r-tech1/compress.h
@@ -1,8 +1,8 @@
-#ifndef _rtech_compress_h
-#define _rtech_compress_h
+#ifndef _rtech1_compress_h
+#define _rtech1_compress_h
namespace Compress{
void testCompression(unsigned char * data, int length);
}
#endif
diff --git a/include/r-tech1/configuration.h b/include/r-tech1/configuration.h
index 31efe11e..bbd42d4b 100644
--- a/include/r-tech1/configuration.h
+++ b/include/r-tech1/configuration.h
@@ -1,186 +1,186 @@
-#ifndef _rtech_configuration_h
-#define _rtech_configuration_h
+#ifndef _rtech1_configuration_h
+#define _rtech1_configuration_h
#include <string>
#include <map>
#include "input/input.h"
#include "pointer.h"
#include "menu/font-info.h"
namespace Menu{
class FontInfo;
}
class Token;
class Configuration{
public:
virtual ~Configuration();
static void setDefaultKeys(int x);
static void loadConfigurations();
static void saveConfiguration();
enum PlayMode{
Cooperative = 1,
FreeForAll = 2,
};
static void setRight(int config, int i);
static void setLeft(int config, int i);
static void setUp(int config, int i);
static void setDown(int config, int i);
static void setAttack1(int config, int i);
static void setAttack2(int config, int i);
static void setAttack3(int config, int i);
static void setAttack4(int config, int i);
static void setAttack5(int config, int i);
static void setAttack6(int config, int i);
static void setJump(int config, int i);
/* Config is the associated player */
static int getRight(int config);
static int getLeft(int config);
static int getUp(int config);
static int getDown(int config);
static int getAttack1(int config);
static int getAttack2(int config);
static int getAttack3(int config);
static int getAttack4(int config);
static int getAttack5(int config);
static int getAttack6(int config);
static int getJump(int config);
/* Returns true if there was a custom axis set, and modifies the output parameters */
static bool getCustomAxis(Joystick::Key key, int config, const std::string & name, int & stick, int & axis, double & low, double & high);
static void setCustomAxis(Joystick::Key key, int config, const std::string & name, int stick, int axis, double low, double high);
/* Returns true if there was a custom button set, and modifies the output parameters */
static bool getCustomButton(Joystick::Key key, int config, const std::string & name, int & button);
static void setCustomButton(Joystick::Key key, int config, const std::string & name, int button);
/*
static void setJoystickRight(int config, JoystickInput i);
static void setJoystickLeft(int config, JoystickInput i);
static void setJoystickUp(int config, JoystickInput i);
static void setJoystickDown(int config, JoystickInput i);
static void setJoystickAttack1(int config, JoystickInput i);
static void setJoystickAttack2(int config, JoystickInput i);
static void setJoystickAttack3(int config, JoystickInput i);
static void setJoystickAttack4(int config, JoystickInput i);
static void setJoystickAttack5(int config, JoystickInput i);
static void setJoystickAttack6(int config, JoystickInput i);
static void setJoystickJump(int config, JoystickInput i);
static void setJoystickStart(int config, JoystickInput i);
static void setJoystickQuit(int config, JoystickInput i);
static JoystickInput getJoystickRight(int config);
static JoystickInput getJoystickLeft(int config);
static JoystickInput getJoystickUp(int config);
static JoystickInput getJoystickDown(int config);
static JoystickInput getJoystickAttack1(int config);
static JoystickInput getJoystickAttack2(int config);
static JoystickInput getJoystickAttack3(int config);
static JoystickInput getJoystickAttack4(int config);
static JoystickInput getJoystickAttack5(int config);
static JoystickInput getJoystickAttack6(int config);
static JoystickInput getJoystickJump(int config);
static JoystickInput getJoystickStart(int config);
static JoystickInput getJoystickQuit(int config);
*/
public:
static double getGameSpeed();
static void setGameSpeed(double s);
static bool getInvincible();
static void setInvincible(bool i);
static bool getFullscreen();
static void setFullscreen(bool f);
static int getLives();
static void setLives(int l);
static int getSoundVolume();
static void setSoundVolume(int volume);
static int getMusicVolume();
static void setMusicVolume(int volume);
static int getNpcBuddies();
static void setNpcBuddies(int i);
static PlayMode getPlayMode();
static void setPlayMode(PlayMode mode);
static void setScreenWidth(int i);
static int getScreenWidth();
static void setScreenHeight(int i);
static int getScreenHeight();
static std::string getQualityFilter();
static void setQualityFilter(const std::string & filter);
static int getFps();
static void setFps(int fps);
static Util::ReferenceCount<Menu::FontInfo> getMenuFont();
static void setMenuFont(const Util::ReferenceCount<Menu::FontInfo> & str);
static bool hasMenuFont();
static int getMenuFontWidth();
static int getMenuFontHeight();
static void setMenuFontWidth(int x);
static void setMenuFontHeight(int x);
/* directory of current game/mod */
/*
static std::string getCurrentGame();
static void setCurrentGame(const std::string & str);
*/
static std::string getLanguage();
static void setLanguage(const std::string & str);
static bool isJoystickEnabled();
static void setJoystickEnabled(bool enabled);
static void setProperty(const std::string & path, const std::string & value);
static std::string getProperty(const std::string & path, const std::string & defaultValue);
static void setProperty(const std::string & path, int value);
static int getProperty(const std::string & path, int value);
static void setProperty(const std::string & path, double value);
static double getProperty(const std::string & path, double value);
static void setProperty(const std::string & path, bool value);
static bool getProperty(const std::string & path, bool value);
static void setProperty(const std::string & path, Token * value);
/* Might return NULL */
static Token * getProperty(const std::string & path);
static void disableSave();
static void setSave(bool what);
static bool getSave();
protected:
Configuration();
Configuration(const Configuration & config);
Configuration & operator=(const Configuration & config);
static Token * getRawData();
static int getKey(int config, const std::string & name, int defaultValue);
static Joystick::Key getJoystickKey(int config, const std::string & name, Joystick::Key defaultValue);
static void setKey(int config, const std::string & name, int value);
static void setJoystickKey(int config, const std::string & name, const Joystick::Key & what);
private:
/* whether to save the configuration or not */
static bool save;
static Util::ReferenceCount<Menu::FontInfo> menuFont;
static bool joystickEnabled;
static Util::ReferenceCount<Token> data;
};
#endif
diff --git a/include/r-tech1/console.h b/include/r-tech1/console.h
index 87fbcf38..25a339da 100644
--- a/include/r-tech1/console.h
+++ b/include/r-tech1/console.h
@@ -1,143 +1,143 @@
-#ifndef _rtech_console_h
-#define _rtech_console_h
+#ifndef _rtech1_console_h
+#define _rtech1_console_h
#include <string>
#include <vector>
#include <deque>
#include <sstream>
#include <map>
#include "input/input-map.h"
#include "input/text-input.h"
#include "file-system.h"
#include "font.h"
#include "pointer.h"
namespace Graphics{
class Bitmap;
}
namespace Console{
/* equivalent of std::endl */
class ConsoleEnd{
private:
friend class Console;
ConsoleEnd(){
}
};
class Command{
public:
Command(){
}
virtual std::string act(const std::string & line) = 0;
virtual std::string getDescription() const = 0;
virtual ~Command(){
}
};
/* starts disabled */
class Console{
public:
Console(const int maxHeight, const Filesystem::RelativePath & font = Font::getDefaultFontPath());
virtual ~Console();
/* handle input and whatnot */
virtual void act();
virtual void draw(const Graphics::Bitmap & work);
/* enable / disable */
virtual void toggle();
/* removes all output from the console */
virtual void clear();
virtual bool doInput();
/* scroll up and down */
virtual void pageUp();
virtual void pageDown();
virtual bool isActive() const;
/* add a line of text */
virtual void addLine(const std::string & line);
inline int getTextHeight(){ return textHeight; };
inline int getTextWidth(){ return textWidth; };
inline void setTextHeight(int h){ textHeight = h; };
inline void setTextWidth(int w){ textWidth = w; };
void fontIncrease();
void fontDecrease();
inline const Filesystem::RelativePath & getFont() const {
return font;
}
/* for arbitrary data */
template<typename T> Console & operator<<(const T & x){
// textInput << x;
return *this;
}
std::vector<Util::ReferenceCount<Command> > getCommands() const;
void addCommand(const std::string & name, const Util::ReferenceCount<Command> & command);
/* make 'alias' do the same thing as command 'name' */
void addAlias(const std::string & alias, const std::string & name);
/* for end of line, always pass Console::endl */
Console & operator<<(const ConsoleEnd & e);
static ConsoleEnd endl;
void activate();
void previousHistory();
void nextHistory();
void tabComplete();
protected:
void process(const std::string & command);
enum State{
Closed,
Open,
Opening,
Closing,
} state;
const int maxHeight;
int height;
Filesystem::RelativePath font;
// Text height
int textHeight;
// Text width
int textWidth;
std::vector<std::string> lines;
// Our text inputer
// std::stringstream textInput;
// std::stringstream currentCommand;
unsigned int offset;
// InputMap<char> input;
TextInput textInput;
std::map<std::string, Util::ReferenceCount<Command> > commands;
/* history of typed commands */
std::deque<std::string> history;
/* index into history. 0 is latest */
unsigned int historyIndex;
int pagePosition;
};
}
#endif
diff --git a/include/r-tech1/debug.h b/include/r-tech1/debug.h
index f01cc6ec..9aae072c 100644
--- a/include/r-tech1/debug.h
+++ b/include/r-tech1/debug.h
@@ -1,113 +1,115 @@
-#ifndef _rtech_debug_h
-#define _rtech_debug_h
+#ifndef _rtech1_debug_h
+#define _rtech1_debug_h
#include <ostream>
#include <sstream>
#include <stdint.h>
#define PAINTOWN_DEBUG_CONTEXT Global::debug_context(__FILE__, __LINE__)
/* Enable this if you can't get regular debug output but have networking
*/
// #define NETWORK_DEBUG
namespace Global{
#ifdef ANDROID
class android_ostream: public std::ostream {
public:
android_ostream(bool enabled = true);
static android_ostream stream;
/* make these private at some point */
public:
bool enabled;
std::ostringstream buffer;
};
typedef android_ostream stream_type;
android_ostream & operator<<(android_ostream & stream, const std::string & input);
android_ostream & operator<<(android_ostream & stream, const char * input);
android_ostream & operator<<(android_ostream & stream, const char);
android_ostream & operator<<(android_ostream & stream, const double);
android_ostream & operator<<(android_ostream & stream, const int);
android_ostream & operator<<(android_ostream & stream, const short int);
android_ostream & operator<<(android_ostream & stream, const short unsigned int);
android_ostream & operator<<(android_ostream & stream, const unsigned int);
android_ostream & operator<<(android_ostream & stream, const bool);
android_ostream & operator<<(android_ostream & stream, const long int);
android_ostream & operator<<(android_ostream & stream, const unsigned long int);
android_ostream & operator<<(android_ostream & stream, const void *);
android_ostream & operator<<(android_ostream & stream, std::ostream & (*f)(std::ostream &));
#elif defined(WII) && defined(DEBUG)
class wii_ostream: public std::ostream {
public:
wii_ostream(bool enabled = true);
static wii_ostream stream;
/* make these private at some point */
public:
bool enabled;
std::ostringstream buffer;
};
typedef wii_ostream stream_type;
wii_ostream & operator<<(wii_ostream & stream, const std::string & input);
wii_ostream & operator<<(wii_ostream & stream, const char * input);
wii_ostream & operator<<(wii_ostream & stream, const char);
wii_ostream & operator<<(wii_ostream & stream, const double);
wii_ostream & operator<<(wii_ostream & stream, const int);
wii_ostream & operator<<(wii_ostream & stream, const short int);
wii_ostream & operator<<(wii_ostream & stream, const short unsigned int);
wii_ostream & operator<<(wii_ostream & stream, const unsigned int);
wii_ostream & operator<<(wii_ostream & stream, const bool);
wii_ostream & operator<<(wii_ostream & stream, const long int);
wii_ostream & operator<<(wii_ostream & stream, const unsigned long int);
wii_ostream & operator<<(wii_ostream & stream, const void *);
wii_ostream & operator<<(wii_ostream & stream, uint64_t);
wii_ostream & operator<<(wii_ostream & stream, std::ostream & (*f)(std::ostream &));
#elif defined(NETWORK_DEBUG)
class network_ostream: public std::ostream {
public:
network_ostream(const std::string & host, int port, bool enabled = true);
static network_ostream stream;
/* make these private at some point */
public:
std::string host;
int port;
bool enabled;
std::ostringstream buffer;
};
typedef network_ostream stream_type;
stream_type & operator<<(stream_type & stream, const std::string & input);
stream_type & operator<<(stream_type & stream, const char * input);
stream_type & operator<<(stream_type & stream, const char);
stream_type & operator<<(stream_type & stream, const double);
stream_type & operator<<(stream_type & stream, const int);
stream_type & operator<<(stream_type & stream, const short int);
stream_type & operator<<(stream_type & stream, const short unsigned int);
stream_type & operator<<(stream_type & stream, const unsigned int);
stream_type & operator<<(stream_type & stream, const bool);
stream_type & operator<<(stream_type & stream, const long int);
#ifndef PS3
stream_type & operator<<(stream_type & stream, const unsigned long int);
#endif
stream_type & operator<<(stream_type & stream, const void *);
stream_type & operator<<(stream_type & stream, uint64_t);
stream_type & operator<<(stream_type & stream, std::ostream & (*f)(std::ostream &));
#else
typedef std::ostream stream_type;
#endif
void logToFile();
void closeLog();
void setDebug(int i);
int getDebug();
+void setLogFile(const std::string &);
+const std::string & getLogFile();
extern std::string defaultDebugContext;
void setDefaultDebugContext(const std::string & context);
stream_type & debug(int i, const std::string & context = defaultDebugContext);
std::string debug_context(const char * file, int line);
}
#endif
diff --git a/include/r-tech1/events.h b/include/r-tech1/events.h
index 30c7da07..1fd31588 100644
--- a/include/r-tech1/events.h
+++ b/include/r-tech1/events.h
@@ -1,133 +1,133 @@
-#ifndef _rtech_events_h
-#define _rtech_events_h
+#ifndef _rtech1_events_h
+#define _rtech1_events_h
/* handles global events from the system such as
* window manager events (press X button)
* keyboard/mouse/joystick input (for some backends like SDL)
*/
#include <vector>
#include <map>
#include "pointer.h"
#ifdef USE_ALLEGRO5
struct ALLEGRO_EVENT_SOURCE;
struct ALLEGRO_EVENT_QUEUE;
#endif
#ifdef USE_SDL
#include <SDL.h>
#endif
class Keyboard;
class Joystick;
namespace Graphics{
class Bitmap;
}
namespace Util{
class WaitThread;
class EventManager{
public:
EventManager();
virtual void run(Keyboard & keyboard, std::map<int, ReferenceCount<Joystick> > joysticks);
virtual void waitForThread(WaitThread & thread);
virtual ~EventManager();
#ifdef USE_SDL
typedef SDLKey KeyType;
#else
typedef int KeyType;
#endif
inline const std::vector<KeyType> & getBufferedKeys() const {
return keys;
}
void deferResizeEvents(bool defer);
void enableKeyBuffer();
void disableKeyBuffer();
private:
enum Event{
CloseWindow,
ResizeScreen,
Key
};
struct ResizeEvent{
Event type;
int width;
int height;
bool enable;
};
virtual void dispatch(Event type, int arg1, int arg2);
virtual void dispatch(Event type, int arg1);
virtual void dispatch(Event type);
#ifdef USE_SDL
virtual void runSDL(Keyboard &, std::map<int, ReferenceCount<Joystick> >);
#endif
#ifdef USE_ALLEGRO
virtual void runAllegro(Keyboard & keyboard, std::map<int, ReferenceCount<Joystick> >);
#endif
#ifdef USE_ALLEGRO5
virtual void runAllegro5(Keyboard & keyboard, const std::map<int, ReferenceCount<Joystick> > &);
ALLEGRO_EVENT_QUEUE * queue;
#endif
std::vector<KeyType> keys;
bool bufferKeys;
bool deferResize;
/* Only need the last event */
ResizeEvent resize;
};
/* implement these classes to get the standard run loop */
class Logic{
public:
/* run a cycle of logic */
virtual void run() = 0;
/* the run loop should finish */
virtual bool done() = 0;
/* return a number of logic ticks for a given number of ticks on
* a real system.
*/
virtual double ticks(double systemTicks) = 0;
virtual ~Logic();
};
class Draw{
public:
Draw();
/* give the drawer a chance to draw stuff to the screen before any logic occurs.
* default implementation is to do nothing.
*/
virtual void drawFirst(const Graphics::Bitmap & screen);
/* standard draw method after logic has run */
virtual void draw(const Graphics::Bitmap & screen) = 0;
virtual ~Draw();
/* called by the standardLoop */
virtual void updateFrames();
virtual double getFps() const;
protected:
int frames;
unsigned int second_counter;
double fps;
};
void standardLoop(Logic & logic, Draw & draw);
/* true if the game should shutdown immediately */
bool shutdown();
extern int do_shutdown;
}
#endif
diff --git a/include/r-tech1/exceptions/exception.h b/include/r-tech1/exceptions/exception.h
index b49858f3..3759249b 100644
--- a/include/r-tech1/exceptions/exception.h
+++ b/include/r-tech1/exceptions/exception.h
@@ -1,80 +1,80 @@
-#ifndef _rtech_exception_12345_h
-#define _rtech_exception_12345_h
+#ifndef _rtech1_exception_12345_h
+#define _rtech1_exception_12345_h
#include <string>
#include <exception>
namespace Exception{
/* Base class for all exceptions */
class Base: public std::exception {
public:
Base(const std::string & file, int line);
Base(const std::string & file, int line, const Base & nested);
Base(const Base & copy);
/* if we use operator= then we get a bunch of warnings from gcc */
virtual void set(const Base & nested);
virtual void throwSelf() const {
throw *this;
}
virtual Base * copy() const;
const std::string getTrace() const;
virtual ~Base() throw ();
protected:
virtual const std::string getReason() const;
std::string file;
int line;
Base * nested;
};
/* This exception is thrown when the user wants to return to the previous menu or
* whatever from some menu or the game by through some abnormal means (like
* pressing ESC). If there is an "exit" button in the menu then usually you shouldn't
* throw this exception, just return as normal.
*/
class Return: public Base {
public:
Return(const std::string & file, int line);
Return(const std::string & file, int line, const Base & nested);
virtual ~Return() throw();
virtual void throwSelf() const;
protected:
virtual Base * copy() const;
};
/* try to quit out of a menu or something. Maybe this should derive from
* MenuException?
*/
class Quit: public Base {
public:
Quit(const std::string & file, int line);
Quit(const std::string & file, int line, const Base & nested);
virtual ~Quit() throw();
virtual void throwSelf() const;
protected:
virtual Base * copy() const;
};
class FontException: public Base {
public:
FontException(const std::string & file, int line, const std::string & reason);
FontException(const std::string & file, int line, const Base & nested, const std::string & reason);
virtual ~FontException() throw();
virtual void throwSelf() const;
protected:
virtual const std::string getReason() const;
virtual Base * copy() const;
std::string reason;
};
}
#endif
diff --git a/include/r-tech1/exceptions/shutdown_exception.h b/include/r-tech1/exceptions/shutdown_exception.h
index b8c16556..9c1af90b 100644
--- a/include/r-tech1/exceptions/shutdown_exception.h
+++ b/include/r-tech1/exceptions/shutdown_exception.h
@@ -1,17 +1,17 @@
-#ifndef _rtech_shutdown_exception_h
-#define _rtech_shutdown_exception_h
+#ifndef _rtech1_shutdown_exception_h
+#define _rtech1_shutdown_exception_h
#include <exception>
/* This exception is thrown when the user clicks the X button on window
* or otherwise wants to immediately shutdown the program.
* If you catch this exception to do something then you must throw it again.
*/
class ShutdownException: public std::exception {
public:
ShutdownException():exception(){}
virtual ~ShutdownException() throw(){}
};
#endif
diff --git a/include/r-tech1/file-system.h b/include/r-tech1/file-system.h
index b31f50d9..b14d1f58 100644
--- a/include/r-tech1/file-system.h
+++ b/include/r-tech1/file-system.h
@@ -1,606 +1,606 @@
-#ifndef _rtech_file_system_h
-#define _rtech_file_system_h
+#ifndef _rtech1_file_system_h
+#define _rtech1_file_system_h
#include "exceptions/exception.h"
#include "pointer.h"
#include "thread.h"
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <fstream>
#include <stdint.h>
class Token;
struct stat;
/* path utilities */
namespace Path{
class Path{
public:
const std::string & path() const;
const std::string getExtension() const;
bool isEmpty() const;
virtual ~Path();
protected:
Path();
Path(const std::string & path);
Path(const Path & path);
virtual inline void setPath(const std::string & s){
mypath = s;
}
std::string mypath;
};
class InsensitivePath: public Path {
public:
InsensitivePath(const Path & what);
bool operator==(const Path & path) const;
};
/* relative path should not have the leading data directory on it, just
* the path within the r-tech system.
*/
class RelativePath: public Path {
public:
explicit RelativePath();
explicit RelativePath(const std::string & path);
RelativePath(const RelativePath & path);
bool operator<(const RelativePath & path) const;
virtual RelativePath getDirectory() const;
virtual RelativePath getFilename() const;
RelativePath removeFirstDirectory() const;
RelativePath firstDirectory() const;
/* true if there are no directory parts to this path
* foo is a file
* bar/foo is not a file
*/
bool isFile() const;
/* a/ + b/ = a/b/ */
RelativePath join(const RelativePath & path) const;
RelativePath & operator=(const RelativePath & copy);
bool operator==(const RelativePath & path) const;
bool operator!=(const RelativePath & path) const;
};
/* absolute paths should have the entire filesystem path on it */
class AbsolutePath: public Path {
public:
explicit AbsolutePath();
explicit AbsolutePath(const std::string & path);
AbsolutePath(const AbsolutePath & path);
AbsolutePath & operator=(const AbsolutePath & copy);
bool operator<(const AbsolutePath & path) const;
bool operator==(const AbsolutePath & path) const;
bool operator!=(const AbsolutePath & path) const;
/* Remove a given path from the start of this path */
virtual RelativePath remove(const AbsolutePath & path) const;
virtual AbsolutePath getDirectory() const;
virtual AbsolutePath getFilename() const;
AbsolutePath removeFirstDirectory() const;
std::string firstDirectory() const;
bool isFile() const;
/* If the filename is empty then get the name of the directory.
* a/b -> b
* a/b/ -> b
*
* Otherwise (a/b/).getFilename() will be ""
*/
virtual std::string getLastComponent() const;
AbsolutePath join(const RelativePath & path) const;
};
std::string invertSlashes(std::string str);
std::string sanitize(std::string path);
/* remove extension. foo.txt -> foo */
std::string removeExtension(const std::string & str);
/* Replace the extension on `input' with `extension'. Don't put the . on the extension,
* so call it as replaceExtension(path, "foo")
* instead of replaceExtension(path, ".foo")
*/
AbsolutePath replaceExtension(const AbsolutePath & input, const std::string & extension);
/* basename, just get the filename and remove the directory part */
std::string stripDir(const std::string & str);
/* dirname, just get the directory and remove the filename part */
std::string stripFilename(const std::string & str);
}
namespace Storage{
/* sorry for the crappy abbreviation, but can't collide with the
* Exception class here
*/
namespace Exc = ::Exception;
class Exception: public Exc::Base {
public:
Exception(const std::string & where, int line, const std::string & file);
Exception(const std::string & where, int line, const Exc::Base & nested, const std::string & file);
Exception(const Exception & copy);
virtual ~Exception() throw ();
virtual void throwSelf() const {
throw *this;
}
protected:
virtual const std::string getReason() const;
virtual Exc::Base * copy() const {
return new Exception(*this);
}
private:
std::string reason;
};
class NotFound: public Exception {
public:
NotFound(const std::string & where, int line, const std::string & file);
NotFound(const std::string & where, int line, const Exc::Base & nested, const std::string & file);
virtual ~NotFound() throw();
NotFound(const NotFound & copy);
virtual void throwSelf() const {
throw *this;
}
protected:
virtual Exc::Base * copy() const {
return new NotFound(*this);
}
};
class IllegalPath: public Exception {
public:
IllegalPath(const std::string & where, int line, const std::string & file);
IllegalPath(const std::string & where, int line, const Exc::Base & nested, const std::string & file);
virtual ~IllegalPath() throw();
IllegalPath(const IllegalPath & copy);
virtual void throwSelf() const {
throw *this;
}
protected:
virtual Exc::Base * copy() const {
return new IllegalPath(*this);
}
};
class Eof: public std::exception {
public:
Eof(){
}
virtual ~Eof() throw (){
}
};
/* Abstraction for files. Should be used instead of FILE, ifstream, SDL_RWOps, anything else */
class File{
public:
enum Access{
Read,
Write,
ReadWrite
};
File();
virtual ~File();
/* Returns the number of bytes read */
virtual int readLine(char * output, int size) = 0;
/* Mostly for normal files, reset their error flags so
* we can seek after eof
*/
virtual void reset() = 0;
/* true if the underlying object can be streamed. generally
* this should be true if the object can be kept around while other files
* of the same type can be opened.
* zip files aren't streamable because only one zip entry can be
* open at a time so it must be closed as soon as possible.
*/
virtual bool canStream() = 0;
virtual long getModificationTime() = 0;
/* seek to an absolute position */
virtual off_t seek(off_t position, int whence) = 0;
virtual int getSize() = 0;
virtual long tell() = 0;
/* Returns a token that represents the path. For normal files it will just be
* a single string containing the path -- "data/x/y/z.txt"
* For zip files it will be (container "x/y/z.zip" "mount/point" "a.txt")
*/
virtual Token * location() = 0;
/* if the file is at eof and can't read anymore */
virtual bool eof() = 0;
/* if the file can still be read */
virtual bool good() = 0;
/* read one unsigned byte */
virtual File & operator>>(unsigned char &) = 0;
};
class EndianReader{
public:
EndianReader(const Util::ReferenceCount<Storage::File> & file){
internal = new FileInternal(file);
}
EndianReader(std::ifstream & stream){
internal = new StreamInternal(stream);
}
class Internal{
public:
Internal();
virtual bool eof() = 0;
virtual int read(char * data, int length) = 0;
virtual void seekEnd(std::streamoff where) = 0;
virtual void seek(std::streamoff where) = 0;
virtual int tell() = 0;
virtual ~Internal();
};
class StreamInternal: public Internal {
public:
StreamInternal(std::ifstream & stream):
stream(stream){
}
virtual bool eof();
virtual int read(char * data, int length);
virtual void seekEnd(std::streamoff where);
virtual void seek(std::streamoff where);
virtual int tell();
virtual ~StreamInternal();
/* Yes, use a reference here */
std::ifstream & stream;
};
class FileInternal: public Internal {
public:
FileInternal(const Util::ReferenceCount<Storage::File> & file):
file(file){
}
virtual bool eof();
virtual void seekEnd(std::streamoff where);
virtual void seek(std::streamoff where);
virtual int read(char * data, int length);
virtual int tell();
virtual ~FileInternal();
Util::ReferenceCount<Storage::File> file;
};
virtual ~EndianReader(){
}
virtual int8_t readByte1(){
return convert(readBytes(sizeof(int8_t)));
}
virtual int16_t readByte2(){
return convert(readBytes(sizeof(int16_t)));
}
virtual int32_t readByte4(){
return convert(readBytes(sizeof(int32_t)));
}
virtual std::string readStringX(int length);
virtual std::string readString2(int length);
virtual void readBytes(uint8_t * out, int length);
virtual void seekEnd(std::streamoff where);
virtual void seek(std::streampos where);
virtual int position();
protected:
virtual int32_t convert(const std::vector<uint8_t> & bytes) = 0;
std::vector<uint8_t> readBytes(int length);
Util::ReferenceCount<Internal> internal;
};
/* combines bytes b0 b1 b2 b3 as b0 + b1*2^8 + b2*2^16 + b3*2^24 */
class LittleEndianReader: public EndianReader {
public:
LittleEndianReader(const Util::ReferenceCount<Storage::File> & file):
EndianReader(file){
}
LittleEndianReader(std::ifstream & stream):
EndianReader(stream){
}
protected:
virtual int32_t convert(const std::vector<uint8_t> & bytes){
uint32_t out = 0;
for (std::vector<uint8_t>::const_reverse_iterator it = bytes.rbegin(); it != bytes.rend(); it++){
out = (out << 8) + *it;
}
return out;
}
};
/* combines bytes b0 b1 b2 b3 as b0*2^24 + b1*2^16 + b2*2^8 + b3 */
class BigEndianReader: public EndianReader {
public:
BigEndianReader(const Util::ReferenceCount<Storage::File> & file):
EndianReader(file){
}
BigEndianReader(std::ifstream & stream):
EndianReader(stream){
}
protected:
virtual int32_t convert(const std::vector<uint8_t> & bytes){
uint32_t out = 0;
for (std::vector<uint8_t>::const_iterator it = bytes.begin(); it != bytes.end(); it++){
out = (out << 8) + *it;
}
return out;
}
};
class LzmaContainer;
class ZipContainer;
class StringFile: public File {
public:
StringFile(const std::string & start);
virtual int readLine(char * output, int size);
virtual bool eof();
virtual bool good();
virtual int getSize();
virtual long getModificationTime();
virtual bool canStream();
virtual void reset();
virtual long tell();
virtual Token * location();
virtual off_t seek(off_t position, int whence);
virtual File & operator>>(unsigned char &);
virtual ~StringFile();
protected:
std::string data;
std::istringstream stream;
};
/* Contains information about an abstract File. */
class Descriptor{
public:
Descriptor();
virtual Util::ReferenceCount<File> open(File::Access mode) = 0;
virtual ~Descriptor();
};
class Traverser;
class Directory{
public:
Directory();
virtual ~Directory();
/* Finds any path in the given directory that matches find, files and directories */
std::vector<Path::AbsolutePath> findFiles(const Path::AbsolutePath & dataPath, const std::string & find, bool caseInsensitive);
/* Only finds directories */
std::vector<Path::AbsolutePath> findDirectories(const Path::AbsolutePath & dataPath, const std::string & find, bool caseInsensitive);
void addFile(const Path::AbsolutePath & path, const Util::ReferenceCount<Descriptor> & file);
void removeFile(const Path::AbsolutePath & path);
/* FIXME: maybe filenames() should just return files? */
/* Files + directories */
std::vector<std::string> filenames() const;
/* Just directories */
std::vector<std::string> directoryNames() const;
/* Finds a file with the given path. Will not find directories.
* Might return NULL if the path can't be found
*/
Util::ReferenceCount<Descriptor> lookup(const Path::AbsolutePath & path);
/* true if the path (either file or directory) exists */
bool exists(const Path::AbsolutePath & path);
/* true if path is a directory */
bool isDirectory(const Path::AbsolutePath & path);
protected:
void doTraverse(const Path::AbsolutePath & path, Traverser & traverser);
void traverse(const Path::AbsolutePath & path, Traverser & traverser);
// Util::ReferenceCount<File> doLookup(const Path::AbsolutePath & path);
std::map<std::string, Util::ReferenceCount<Directory> > directories;
std::map<std::string, Util::ReferenceCount<Descriptor> > files;
Util::Thread::LockObject lock;
};
class System{
public:
System();
virtual ~System();
typedef Path::AbsolutePath AbsolutePath;
typedef Path::RelativePath RelativePath;
virtual AbsolutePath find(const RelativePath & path) = 0;
virtual RelativePath cleanse(const AbsolutePath & path) = 0;
virtual bool exists(const RelativePath & path) = 0;
virtual bool exists(const AbsolutePath & path);
virtual bool isDirectory(const AbsolutePath & path);
virtual std::vector<AbsolutePath> getFilesRecursive(const AbsolutePath & dataPath, const std::string & find, bool caseInsensitive = false) = 0;
/* Finds all supported container files. Currently
* .zip
*/
virtual std::vector<AbsolutePath> getContainerFilesRecursive(const AbsolutePath & dataPath);
/* Gets container files only in the specified directory */
virtual std::vector<AbsolutePath> getContainerFiles(const AbsolutePath & dataPath);
/* Gets container files in <user>/path ./path and <data>/path */
virtual std::vector<AbsolutePath> getContainerFiles(const RelativePath & path);
/* Given a path with no extension, find a container file that is <name>.zip or
* <name>.7z or whatever exists.
* So if dataPath is "mugen/foo" this function will look for
* mugen/foo.zip
* mugen/foo.7z
* mugen/foo.rar
* ...
*
* and return the first one it finds
*/
virtual AbsolutePath findContainer(const RelativePath & dataPath);
/* search for a pattern of a single file within a directory */
virtual std::vector<AbsolutePath> getFiles(const AbsolutePath & dataPath, const std::string & find, bool caseInsensitive = false) = 0;
/* Container should be a path to a zip file */
virtual void addOverlay(const AbsolutePath & container, const AbsolutePath & where);
virtual void removeOverlay(const AbsolutePath & container, const AbsolutePath & where);
virtual std::vector<std::string> containerFileList(const AbsolutePath & container);
/* search for some path which may contain wildcards in a directory */
virtual std::vector<AbsolutePath> getFiles(const AbsolutePath & dataPath, const RelativePath & find, bool caseInsensitive);
/* Gets all the files in all directories matched by the relative path */
virtual std::vector<AbsolutePath> getFiles(const RelativePath & dataPath, const RelativePath & find, bool caseInsensitive) = 0;
virtual AbsolutePath configFile() = 0;
virtual AbsolutePath userDirectory() = 0;
virtual std::vector<AbsolutePath> findDirectories(const RelativePath & path) = 0;
virtual AbsolutePath findInsensitive(const RelativePath & path) = 0;
virtual AbsolutePath lookupInsensitive(const AbsolutePath & directory, const RelativePath & path) = 0;
virtual Util::ReferenceCount<File> open(const AbsolutePath & path, File::Access mode = File::Read);
/* Should be protected but needs to be public so we can use it in template methods
* in the implementation file.
*/
public:
virtual void overlayFile(const AbsolutePath & where, Util::ReferenceCount<ZipContainer> zip);
virtual void overlayFile(const AbsolutePath & where, Util::ReferenceCount<LzmaContainer> container);
/* package: */
virtual bool systemExists(const AbsolutePath & path) = 0;
virtual bool systemIsDirectory(const AbsolutePath & path) = 0;
virtual void unoverlayFile(const AbsolutePath & where);
// std::map<AbsolutePath, Util::ReferenceCount<ZipContainer> > overlays;
Storage::Directory virtualDirectory;
};
System & instance();
bool hasInstance();
System & setInstance(const Util::ReferenceCount<System> & what);
bool isContainer(const Path::AbsolutePath & path);
std::string readFile(const Path::AbsolutePath & path);
std::vector<std::string> containerTypes();
}
/*
* class Filesystem
* class NetworkStorage
* class ZipStorage
*/
class Filesystem: public Storage::System {
public:
Filesystem(const Path::AbsolutePath & dataPath);
typedef Path::AbsolutePath AbsolutePath;
typedef Path::RelativePath RelativePath;
typedef Path::InsensitivePath InsensitivePath;
typedef Storage::Exception Exception;
typedef Storage::NotFound NotFound;
/* given a relative path like sounds/arrow.png, prepend the proper
* data path to it to give data/sounds/arrow.png
*/
AbsolutePath find(const RelativePath & path);
/* like `find' but ignores case */
AbsolutePath findInsensitive(const RelativePath & path);
/* findInsensitive but starts in the given absolute directory path */
AbsolutePath lookupInsensitive(const AbsolutePath & directory, const RelativePath & path);
// void initialize();
/* whether the file exists at all */
using System::exists;
bool exists(const RelativePath & path);
/* remove the data path from a string
* data/sounds/arrow.png -> sounds/arrow.png
*/
RelativePath cleanse(const AbsolutePath & path);
/* returns all the directories starting with the given path.
* will look in the main data directory, the user directory, and
* the current working directory.
*/
std::vector<AbsolutePath> findDirectories(const RelativePath & path);
/* user specific directory to hold persistent data */
AbsolutePath userDirectory();
/* user specific path to store the configuration file */
AbsolutePath configFile();
using Storage::System::getFiles;
/* search a directory for some files matching pattern `find' */
virtual std::vector<AbsolutePath> getFiles(const AbsolutePath & dataPath, const std::string & find, bool caseInsensitive = false);
virtual std::vector<AbsolutePath> getFiles(const RelativePath & dataPath, const RelativePath & find, bool caseInsensitive);
/* same as getFiles but search directories recursively */
std::vector<AbsolutePath> getFilesRecursive(const AbsolutePath & dataPath, const std::string & find, bool caseInsensitive = false);
protected:
virtual bool systemExists(const AbsolutePath & path);
virtual bool systemIsDirectory(const AbsolutePath & path);
AbsolutePath lookup(const RelativePath path);
std::vector<AbsolutePath> findDirectoriesIn(const AbsolutePath & path);
std::vector<AbsolutePath> getAllDirectories(const AbsolutePath & path);
protected:
Util::Thread::LockObject lock;
AbsolutePath dataPath;
};
#endif
diff --git a/include/r-tech1/font.h b/include/r-tech1/font.h
index 41f48de2..35fb15aa 100644
--- a/include/r-tech1/font.h
+++ b/include/r-tech1/font.h
@@ -1,125 +1,125 @@
-#ifndef _rtech_font_h
-#define _rtech_font_h
+#ifndef _rtech1_font_h
+#define _rtech1_font_h
#include <string>
#include <vector>
#include "graphics/bitmap.h"
// #include "file-system.h"
#include "parameter.h"
// #include "ftalleg.h"
struct FONT;
namespace ftalleg{
class freetype;
}
namespace Path{
class RelativePath;
class AbsolutePath;
}
/* handle allegro fonts and true type fonts */
class Font{
public:
static Util::Parameter<Util::ReferenceCount<Path::RelativePath> > defaultFont;
Font();
virtual ~Font();
virtual void setSize( const int x, const int y ) = 0;
virtual int getSizeX() const = 0;
virtual int getSizeY() const = 0;
virtual int textLength( const char * text ) const = 0;
virtual int getHeight( const std::string & str ) const = 0;
virtual int getHeight() const = 0;
virtual void printf( int x, int y, int xSize, int ySize, Graphics::Color color, const Graphics::Bitmap & work, const std::string & str, int marker, ... ) const = 0;
virtual void printf( int x, int y, Graphics::Color color, const Graphics::Bitmap & work, const std::string & str, int marker, ... ) const = 0;
virtual void printfWrap( int x, int y, Graphics::Color color, const Graphics::Bitmap & work, int maxWidth, const std::string & str, int marker, ... ) const;
static const Path::RelativePath & getDefaultFontPath();
static const Font & getDefaultFont();
static const Font & getDefaultFont(int width, int height);
static const Font & getFont( const Path::RelativePath & name, const int x = 32, const int y = 32 );
static const Font & getFont( const Path::AbsolutePath & name, const int x = 32, const int y = 32 );
/* store all the freetype fonts forever */
// static std::vector< ftalleg::freetype * > cacheFreeType;
protected:
void printfWrapLine(int x, int & y, Graphics::Color color, const Graphics::Bitmap & work, int maxWidth, const char * line) const;
};
class NullFont: public Font {
public:
NullFont();
virtual ~NullFont();
virtual void setSize( const int x, const int y );
virtual int getSizeX() const;
virtual int getSizeY() const;
virtual int textLength( const char * text ) const;
virtual int getHeight( const std::string & str ) const;
virtual int getHeight() const;
virtual void printf( int x, int y, int xSize, int ySize, Graphics::Color color, const Graphics::Bitmap & work, const std::string & str, int marker, ... ) const;
virtual void printf( int x, int y, Graphics::Color color, const Graphics::Bitmap & work, const std::string & str, int marker, ... ) const;
};
#ifdef USE_ALLEGRO
class AllegroFont: public Font {
public:
AllegroFont( const FONT * const font );
AllegroFont( const AllegroFont & copy );
virtual ~AllegroFont();
virtual int getHeight() const;
virtual int getHeight( const std::string & str ) const;
virtual int textLength( const char * text ) const;
virtual void printf( int x, int y, Graphics::Color color, const Graphics::Bitmap & work, const std::string & str, int marker, ... ) const;
virtual void printf( int x, int y, int xSize, int ySize, Graphics::Color color, const Graphics::Bitmap & work, const std::string & str, int marker, ... ) const;
virtual void setSize( const int x, const int y );
virtual int getSizeX() const;
virtual int getSizeY() const;
private:
inline const FONT * getInternalFont() const {
return font;
}
const FONT * const font;
};
#endif
class FreeTypeFont: public Font {
public:
FreeTypeFont(const Path::AbsolutePath & filename);
FreeTypeFont(const FreeTypeFont & copy);
virtual ~FreeTypeFont();
virtual int getHeight() const;
virtual int getHeight( const std::string & str ) const;
virtual int textLength( const char * text ) const;
virtual void printf( int x, int y, Graphics::Color color, const Graphics::Bitmap & work, const std::string & str, int marker, ... ) const;
virtual void printf( int x, int y, int xSize, int ySize, Graphics::Color color, const Graphics::Bitmap & work, const std::string & str, int marker, ... ) const;
virtual void setSize( const int x, const int y );
virtual int getSizeX() const;
virtual int getSizeY() const;
private:
ftalleg::freetype * font;
int sizeX;
int sizeY;
bool own;
};
#endif
diff --git a/include/r-tech1/font_factory.h b/include/r-tech1/font_factory.h
index 510c7c35..72bfb641 100644
--- a/include/r-tech1/font_factory.h
+++ b/include/r-tech1/font_factory.h
@@ -1,46 +1,46 @@
-#ifndef _rtech_font_factory_h
-#define _rtech_font_factory_h
+#ifndef _rtech1_font_factory_h
+#define _rtech1_font_factory_h
#include <string>
#include <map>
#include "file-system.h"
#include "font.h"
#include "thread.h"
struct DATAFILE;
class Font;
class Collector;
class FontFactory{
public:
/* clear the cache. if anyone has a reference to an existing Font object a crash
* is likely to occur!
*/
static void clear();
private:
friend class Collector;
friend class Font;
static Font * getFont(const Filesystem::RelativePath & path, const int x, const int y );
static Font * getFont(const Filesystem::AbsolutePath & path, const int x, const int y );
private:
FontFactory();
virtual ~FontFactory();
static void destroy();
Font * getRealFont(const Filesystem::RelativePath & str, const int x, const int y );
Font * getRealFont(const Filesystem::AbsolutePath & str, int x, int y );
void _clear();
private:
static FontFactory * my_factory;
// DATAFILE * my_data;
std::map<std::string, Font *> font_mapper;
NullFont nullFont;
Util::Thread::LockObject lock;
};
#endif
diff --git a/include/r-tech1/funcs.h b/include/r-tech1/funcs.h
index 47c28f77..3a47a992 100644
--- a/include/r-tech1/funcs.h
+++ b/include/r-tech1/funcs.h
@@ -1,118 +1,118 @@
-#ifndef _rtech_funcs_h
-#define _rtech_funcs_h
+#ifndef _rtech1_funcs_h
+#define _rtech1_funcs_h
#include <stdlib.h>
#include <vector>
#include <string>
#include <stdarg.h>
#include "regex.h"
#include "file-system.h"
namespace Exception{
class Base;
}
namespace Graphics{
class Bitmap;
}
namespace Util{
extern const double pi;
/* returns a number between 0 and q-1. you will never get `q'. if
* you wanted to get `q' then pass in q+1
*/
inline int rnd( int q ){
if (q <= 0){
return 0;
}
return (int)(rand() % q);
}
// std::vector< std::string > getFiles(const Filesystem::AbsolutePath & dataPath, const std::string & find );
double radians(double degree);
double degrees(double radians);
Filesystem::AbsolutePath getDataPath2();
void setDataPath( const std::string & str );
bool exists( const std::string & file );
/* check that `version' is compatible with this program, mostly used
* for network clients.
*/
// bool checkVersion(int version);
/* return a random number + some range between min/max */
int rnd( int q, int min, int max );
int max(int a, int b);
inline int min(int a, int b){
if (a<b){
return a;
}
return b;
}
double min(double a, double b);
double max(double a, double b);
double distance(double x1, double y1, double x2, double y2);
int clamp(int value, int min, int max);
double clamp(double value, double min, double max);
/* return a number between min/max */
int rnd( int min, int max );
/* rest in milliseconds */
void rest( int x );
/* rest in seconds */
void restSeconds(double x);
std::string trim(const std::string & str);
/* only upper cases the first letter of a string */
std::string upcase(std::string str);
/* lower cases the entire string */
std::string lowerCaseAll(std::string str);
/* upper cases the entire string */
std::string upperCaseAll(std::string str);
// Split string
std::vector<std::string> splitString(std::string str, char splitter);
// Join strings
std::string joinStrings(const std::vector< std::string > & message, unsigned int start = 0);
/* convert a size in bytes into human readable form.
* 234823592 = 223.94m
*/
std::string niceSize(unsigned long size);
int levenshtein(const std::string & str1, const std::string & str2);
// int getPipe(int files[2]);
void limitPrintf(char * buffer, int size, const char * format, va_list args);
void showError(const Graphics::Bitmap & screen, const Exception::Base & exception, const std::string & info);
/* will create a screen of size GFX_X, GFX_Y */
void showError(const Exception::Base & exception, const std::string & info);
std::string join(const std::vector<std::string> & list, const std::string & middle);
template <class T, size_t N> size_t array_size(T (&)[N]){ return N; }
}
#endif
diff --git a/include/r-tech1/graphics/bitmap.h b/include/r-tech1/graphics/bitmap.h
index 77d107f8..f5e0c80d 100644
--- a/include/r-tech1/graphics/bitmap.h
+++ b/include/r-tech1/graphics/bitmap.h
@@ -1,790 +1,790 @@
-#ifndef _rtech_bitmap_h_
-#define _rtech_bitmap_h_
+#ifndef _rtech1_bitmap_h_
+#define _rtech1_bitmap_h_
#include "../exceptions/exception.h"
#include "../pointer.h"
#include "../parameter.h"
#include <string>
#include <vector>
#include <map>
#include <iostream>
#ifdef USE_ALLEGRO
#include "allegro/bitmap.h"
#endif
#ifdef USE_SDL
#include "sdl/bitmap.h"
#endif
#ifdef USE_ALLEGRO5
#include "allegro5/bitmap.h"
struct ALLEGRO_SHADER;
#endif
#include "color.h"
#if !defined(USE_ALLEGRO) && !defined(USE_SDL) && !defined(USE_ALLEGRO5)
#error No backend specified. Define one of USE_ALLEGRO, USE_SDL, or USE_ALLEGRO5
#endif
namespace Storage{
class File;
}
namespace Graphics{
class Bitmap;
class Color{
public:
explicit Color(const INTERNAL_COLOR & color):
color(color){
}
static INTERNAL_COLOR defaultColor();
Color():
color(defaultColor()){
}
Color & operator=(const Color & him){
this->color = him.color;
return *this;
}
bool operator==(const Color & him) const {
return color == him.color;
}
bool operator!=(const Color & him) const {
return !(*this == him);
}
bool operator<(const Color & him) const {
return this->color < him.color;
}
INTERNAL_COLOR color;
};
enum ImageFormat{
FormatPNG,
FormatBMP,
FormatJPG,
FormatPCX,
FormatTGA,
FormatTIF,
FormatXPM,
FormatGIF,
FormatUnknown
};
ImageFormat identifyImage(const unsigned char * data, int length);
class TranslucentBitmap;
class LitBitmap;
class Bitmap;
extern Util::Parameter<Bitmap*> screenParameter;
extern const int SPRITE_NORMAL;
extern const int SPRITE_LIT;
extern const int SPRITE_TRANS;
extern const int SPRITE_NO_FLIP;
extern const int SPRITE_V_FLIP;
extern const int SPRITE_H_FLIP;
/*
extern int SCALE_X;
extern int SCALE_Y;
*/
class BitmapException: public Exception::Base {
public:
BitmapException(const std::string & file, int line, const std::string & reason):
Base(file, line),
reason(reason){
}
BitmapException(const BitmapException & copy):
Base(copy),
reason(copy.reason){
}
virtual void throwSelf() const {
throw *this;
}
virtual ~BitmapException() throw () {
}
protected:
virtual const std::string getReason() const {
return reason;
}
std::string reason;
};
/* create a color from components */
Color makeColor(int r, int g, int b);
Color darken(Color color, double factor);
void hsvToRGB( float h, float s, float v, int * r, int * g, int * b );
int setGfxModeText();
int setGfxModeFullscreen( int x, int y );
int setGfxModeWindowed( int x, int y );
/* Only call this method once, from init. After that call changeGraphicsMode */
int setGraphicsMode(int mode, int width, int height);
int changeGraphicsMode(int mode, int width, int height);
/* get color components */
int getRed(Color x);
int getBlue(Color x);
int getGreen(Color x);
int getAlpha(Color x);
Color MaskColor();
enum QualityFilter{
NoFilter,
HqxFilter,
XbrFilter
};
QualityFilter qualityFilterName(const std::string & type);
/* FIXME: try to move the shader stuff to shader.h */
class Shader{
public:
Shader();
virtual ~Shader();
#ifdef USE_ALLEGRO5
Shader(ALLEGRO_SHADER * shader);
ALLEGRO_SHADER * getShader();
ALLEGRO_SHADER * shader;
#endif
};
class ShaderManager{
public:
ShaderManager();
Util::ReferenceCount<Shader> getShader(const std::string & name, Util::ReferenceCount<Shader> (*create)());
virtual ~ShaderManager();
protected:
std::map<std::string, Util::ReferenceCount<Shader> > shaders;
};
extern Util::Parameter<Util::ReferenceCount<ShaderManager> > shaderManager;
#ifdef USE_ALLEGRO5
ALLEGRO_SHADER * create_shader(const std::string & vertex, const std::string & pixel);
void setShaderSampler(ALLEGRO_SHADER * shader, const std::string & name, const Bitmap & texture, int unit);
void setShaderBool(ALLEGRO_SHADER * shader, const std::string & name, bool value);
void setShaderInt(ALLEGRO_SHADER * shader, const std::string & name, int value);
void setShaderFloat(ALLEGRO_SHADER * shader, const std::string & name, float value);
void setShaderVec4(ALLEGRO_SHADER * shader, const std::string & name, float v1, float v2, float v3, float v4);
std::string defaultVertexShader();
std::string defaultPixelShader();
#endif
class Bitmap{
private:
/* these constructors don't really matter, get rid of them at some point */
Bitmap( const Bitmap & copy, int sx, int sy, double accuracy );
Bitmap( const char * load_file, int sx, int sy, double accuracy );
public:
/* equivalent to a GPU shader */
class Filter{
public:
virtual Color filter(Color pixel) const = 0;
/* getShader should only return the Shader object and not set any uniforms/attributes */
virtual Util::ReferenceCount<Shader> getShader() = 0;
/* set the uniforms/attributes */
virtual void setupShader(const Util::ReferenceCount<Shader> &) = 0;
virtual ~Filter(){
}
};
/* default constructor makes 10x10 bitmap */
Bitmap();
Bitmap( int x, int y );
Bitmap( const char * load_file );
Bitmap(const char * data, int length);
Bitmap( const std::string & load_file );
Bitmap( const char * load_file, int sx, int sy );
/* Load a bitmap from an abstract file */
Bitmap(Storage::File & file);
/* 4/24/2010: remove this at some point */
#ifdef USE_ALLEGRO
explicit Bitmap( BITMAP * who, bool deep_copy = false );
#endif
#ifdef USE_SDL
explicit Bitmap(SDL_Surface * who, bool deep_copy = false );
#endif
#ifdef USE_ALLEGRO5
explicit Bitmap(ALLEGRO_BITMAP * who, bool deep_copy = false );
#endif
Bitmap( const Bitmap & copy, bool deep_copy = false );
Bitmap( const Bitmap & copy, int sx, int sy );
Bitmap( const Bitmap & copy, int x, int y, int width, int height );
virtual ~Bitmap();
/* For opengl backends, creates a memory bitmap. For software renderers
* just creates a regular bitmap.
*/
static Bitmap createMemoryBitmap(int width, int height);
virtual TranslucentBitmap translucent() const;
/* will call transBlender() with the supplied values for you */
virtual TranslucentBitmap translucent(int red, int green, int blue, int alpha) const;
virtual LitBitmap lit() const;
virtual void save( const std::string & str ) const;
virtual Bitmap & operator=( const Bitmap & );
virtual void load( const std::string & str );
virtual int getWidth() const;
virtual int getHeight() const;
/* true if this bitmap doesn't contain an image of any sort. if so, don't
* try to use this object!!
*/
virtual bool isEmpty() const;
/*
inline const int getWidth() const{
return getBitmap()->w;
}
inline const int getHeight() const{
return getBitmap()->h;
}
*/
/*
inline const int getWidth() const{
return my_bitmap->w;
}
inline const int getHeight() const{
return my_bitmap->h;
}
*/
void detach();
/* replace all pixels that have value `original' with `replaced' */
void replaceColor(const Color & original, const Color & replaced);
void set8BitMaskColor(const Color & color);
Color get8BitMaskColor();
/* Blend between source pixel and destination pixel.
* Source and dest should be 0-255.
* source = 64, dest = 128
* pixel = source_pixel * source / 255 + dest_pixel * dest / 255
*/
static void alphaBlender(int source, int dest);
static void transBlender( int r, int g, int b, int a );
static void multiplyBlender( int r, int g, int b, int a );
static void dissolveBlender( int r, int g, int b, int a );
static void addBlender( int r, int g, int b, int a );
static void burnBlender( int r, int g, int b, int a );
static void colorBlender( int r, int g, int b, int a );
static void differenceBlender( int r, int g, int b, int a );
static void dodgeBlender( int r, int g, int b, int a );
static void hueBlender( int r, int g, int b, int a );
static void luminanceBlender( int r, int g, int b, int a );
static void invertBlender( int r, int g, int b, int a );
static void screenBlender( int r, int g, int b, int a );
/* for testing */
static void setFakeGraphicsMode(int width, int height);
/* clean up any remaining state */
static void shutdown();
// static void drawingMode( int type );
virtual Color blendColor(const Color & input) const;
/* sets the blend state. try not to use these function unless
* absolutely necessary.
*/
virtual void startDrawing() const;
virtual void endDrawing() const;
void acquire();
void release();
void updateOnResize();
/* Resizes the bitmap and stretches the old pixels to the new bitmap */
void resize(const int width, const int height);
/* Just resizes the bitmap without copying pixels */
void updateSize(const int width, const int height);
/* Makes this bitmap the same as the parameter.
* Width/height is copied and then a Blit is called.
*/
void copy(const Bitmap & him);
void debugSelf() const;
/* convert to a grey scale version */
virtual Bitmap greyScale();
virtual void triangle( int x1, int y1, int x2, int y2, int x3, int y3, Color color ) const;
/* draws an equilateral triangle centered at (x,y) pointing at `angle'
* where each side has `size' pixels using the color.
*/
virtual void equilateralTriangle(int x, int y, int angle, int size, Color color) const;
virtual void ellipse( int x, int y, int rx, int ry, Color color ) const;
virtual void ellipseFill( int x, int y, int rx, int ry, Color color ) const;
virtual void light(int x, int y, int width, int height, int start_y, int focus_alpha, int edge_alpha, Color focus_color, Color edge_color) const;
virtual void applyTrans(const Color color) const;
virtual void border( int min, int max, Color color ) const;
virtual void rectangle( int x1, int y1, int x2, int y2, Color color ) const;
virtual void rectangleFill( int x1, int y1, int x2, int y2, Color color ) const;
virtual void circleFill( int x, int y, int radius, Color color ) const;
virtual void circle( int x, int y, int radius, Color color ) const;
virtual void circle(int x, int y, int radius, int thickness, Color color) const;
virtual void line( const int x1, const int y1, const int x2, const int y2, const Color color ) const;
virtual void floodfill( const int x, const int y, const Color color ) const;
virtual void horizontalLine( const int x1, const int y, const int x2, const Color color ) const;
virtual void hLine( const int x1, const int y, const int x2, const Color color ) const;
virtual void vLine( const int y1, const int x, const int y2, const Color color ) const;
virtual void polygon( const int * verts, const int nverts, const Color color ) const;
virtual void arc(const int x, const int y, const double ang1, const double ang2, const int radius, const Color color ) const;
virtual void arcFilled(const int x, const int y, const double ang1, const double ang2, const int radius, const Color color ) const;
/* x/y is in the center of the bitmap */
virtual void drawCenter(const int x, const int y, const Bitmap & where) const;
virtual void draw(const int x, const int y, const Bitmap & where) const;
virtual void draw(const int x, const int y, Filter * filter, const Bitmap & where) const;
virtual void draw(const int x, const int y, const int startWidth, const int startHeight, const int width, const int height, const Bitmap & where) const;
virtual void draw(const int x, const int y, const int startWidth, const int startHeight, const int width, const int height, Filter * filter, const Bitmap & where) const;
virtual void drawCharacter( const int x, const int y, const Color color, const int background, const Bitmap & where ) const;
/* flip horizontally */
virtual void drawHFlip(const int x, const int y, const Bitmap & where) const;
virtual void drawHFlip(const int x, const int y, Filter * filter, const Bitmap & where) const;
virtual void drawHFlip(const int x, const int y, const int startWidth, const int startHeight, const int width, const int height, const Bitmap & where) const;
virtual void drawHFlip(const int x, const int y, const int startWidth, const int startHeight, const int width, const int height, Filter * filter, const Bitmap & where) const;
/* flip vertically */
virtual void drawVFlip( const int x, const int y, const Bitmap & where ) const;
virtual void drawVFlip( const int x, const int y, Filter * filter, const Bitmap & where ) const;
/* flip horizontal and vertical */
virtual void drawHVFlip( const int x, const int y, const Bitmap & where ) const;
virtual void drawHVFlip( const int x, const int y, Filter * filter, const Bitmap & where ) const;
// virtual void drawTrans( const int x, const int y, const Bitmap & where ) const;
// virtual void drawTrans( const int x, const int y, Filter * filter, const Bitmap & where ) const;
// virtual void drawTransHFlip( const int x, const int y, const Bitmap & where ) const;
// virtual void drawTransHFlip( const int x, const int y, Filter * filter, const Bitmap & where ) const;
// virtual void drawTransVFlip( const int x, const int y, const Bitmap & where ) const;
// virtual void drawTransVFlip( const int x, const int y, Filter * filter, const Bitmap & where ) const;
// virtual void drawTransHVFlip( const int x, const int y, const Bitmap & where ) const;
// virtual void drawTransHVFlip( const int x, const int y, Filter * filter, const Bitmap & where ) const;
virtual void drawMask( const int x, const int y, const Bitmap & where );
virtual void drawStretched( const int x, const int y, const int new_width, const int new_height, const Bitmap & who ) const;
virtual void drawStretched(const Bitmap & who) const;
/* middle of the bitmap is at x, y */
virtual void drawRotateCenter(const int x, const int y, const int angle, const Bitmap & where);
/* upper left hand corner is at x, y*/
virtual void drawRotate(const int x, const int y, const int angle, const Bitmap & where);
virtual void drawPivot( const int centerX, const int centerY, const int x, const int y, const int angle, const Bitmap & where );
virtual void drawPivot( const int centerX, const int centerY, const int x, const int y, const int angle, const double scale, const Bitmap & where );
/* Stretch using the hqx algorithm */
virtual void StretchHqx(const Bitmap & where) const;
virtual void StretchHqx(const Bitmap & where, const int sourceX, const int sourceY, const int sourceWidth, const int sourceHeight, const int destX, const int destY, const int destWidth, const int destHeight) const;
/* Xbr is defined here:
* http://board.byuu.org/viewtopic.php?f=10&t=2248
*/
virtual void StretchXbr(const Bitmap & where) const;
virtual void StretchXbr(const Bitmap & where, const int sourceX, const int sourceY, const int sourceWidth, const int sourceHeight, const int destX, const int destY, const int destWidth, const int destHeight) const;
/* Just copies pixels (fast) */
virtual void Stretch(const Bitmap & where) const;
virtual void Stretch(const Bitmap & where, const int sourceX, const int sourceY, const int sourceWidth, const int sourceHeight, const int destX, const int destY, const int destWidth, const int destHeight ) const;
virtual void StretchBy2( const Bitmap & where );
virtual void StretchBy4( const Bitmap & where );
virtual void Blit( const std::string & xpath ) const;
virtual void Blit( const Bitmap & where ) const;
virtual void Blit( const int x, const int y, const Bitmap & where ) const;
virtual void Blit( const int mx, const int my, const int wx, const int wy, const Bitmap & where ) const;
virtual void Blit( const int mx, const int my, const int width, const int height, const int wx, const int wy, const Bitmap & where ) const;
virtual void BlitMasked( const int mx, const int my, const int width, const int height, const int wx, const int wy, const Bitmap & where ) const;
virtual void BlitToScreen() const;
virtual void BlitAreaToScreen(const int upper_left_x, const int upper_left_y) const;
virtual void BlitToScreen(const int upper_left_x, const int upper_left_y) const;
virtual void BlitFromScreen(const int x, const int y) const;
virtual void roundRect(int radius, int x1, int y1, int x2, int y2, Color color) const;
virtual void roundRectFill(int radius, int x1, int y1, int x2, int y2, Graphics::Color color) const;
virtual void drawShadow(Bitmap & where, int x, int y, int intensity, Color color, double scale, bool facingRight) const;
/* Return a bitmap that has an aspect ratio the same as the given numbers */
virtual Bitmap aspectRatio(int aspectWidth, int aspectHeight) const;
/* returned a scaled version of this bitmap of the given dimensions */
virtual Bitmap scaleTo(const int width, const int height) const;
/* scale the image by the given ratios, i.e: a ratio of 1 means do nothing.
* less than 1 will make it smaller and larger than 1 will make it larger.
*/
virtual Bitmap scaleBy(const double widthRatio, const double heightRatio) const;
/* try to call Global::getScreenWidth/Height() instead of these directly */
static int getScreenWidth();
static int getScreenHeight();
virtual void fill(Color color) const;
virtual void clear() const;
inline void clearToMask() const{
this->fill(MaskColor());
}
bool getError();
inline const Util::ReferenceCount<BitmapData> & getData() const {
return data;
}
inline Util::ReferenceCount<BitmapData> getData(){
return data;
}
void setData(Util::ReferenceCount<BitmapData> data){
this->data = data;
}
virtual void readLine( std::vector<Color> & vec, int y );
Color getPixel( const int x, const int y ) const;
/* lock video bitmap to memory */
void lock() const;
void lock(int x, int y, int width, int height) const;
void unlock() const;
/* true if the point is within the bounds of the bitmap */
bool inRange(int x, int y) const;
/* uses _putpixel16 underneath which ignores translucent behavior */
void putPixel( int x, int y, Color col ) const;
/* respects the current trans mode */
virtual void putPixelNormal(int x, int y, Color col) const;
/*
inline int getPixel( int x, int y ) const{
if ( x >= 0 && x < my_bitmap->w && y >= 0 && y <= my_bitmap->h )
return _getpixel16( my_bitmap, x, y );
return -1;
}
inline void putPixel( int x, int y, int col ) const{
if ( x >= 0 && x < my_bitmap->w && y >= 0 && y <= my_bitmap->h )
_putpixel16( my_bitmap, x, y, col );
}
*/
void setClipRect( int x1, int y1, int x2, int y2 ) const;
void getClipRect( int & x1, int & y1, int & x2, int & y2 ) const;
inline const std::string & getPath() const{
return path;
}
/* produce a temporary bitmap that is not guaranteed to be preserved
* after your function returns. do *not* hold references to this bitmap
* and if you make a temporary bitmap, do *not* call functions that
* might also make temporary bitmaps.
*/
/*
static Bitmap temporaryBitmap(int w, int h);
static Bitmap temporaryBitmap2(int w, int h);
*/
/* call this method to delete all temporary bitmaps.
* don't call this unless you know what you are doing
*/
static void cleanupTemporaryBitmaps();
static double getScale();
/*
* Convert color values between the HSV and RGB color spaces. The RGB values
* range from 0 to 255, hue is from 0 to 360, and saturation and value are
* from 0 to 1.
*/
static void rgbToHSV(int r, int g, int b, float * h, float * s, float * v);
/* convert cymk to rgb. values should be in the range 0-255 */
static void cymkToRGB(int c, int y, int m, int k, int * r, int * g, int * b);
/* Add two RGB16 colors together
* r = c1.r + c2.r
* g = c1.g + c2.g
* b = c1.b + c2.b
*/
static Color addColor( Color color1, Color color2 );
/*
inline static int makeColor( int r, int g, int b ){
return makecol16( r, g, b );
}
*/
// static const int MaskColor = MASK_COLOR_16;
/*
static const int MODE_TRANS;
static const int MODE_SOLID;
*/
#ifdef USE_ALLEGRO5
void convertToVideo();
#endif
protected:
#ifdef USE_ALLEGRO5
virtual void draw(const int x, const int y, Filter * filter, const Bitmap & where, int flags) const;
#endif
/* release a reference count, and possibly destroy data */
// void releaseInternalBitmap();
/* really destroy private data */
// void destroyPrivateData();
/*
inline void setBitmap( BITMAP * bitmap ){
if ( bitmap == NULL ){
std::cout << "*FATAL* Setting null bitmap" << std::endl;
}
_my_bitmap = bitmap;
}
*/
void loadFromMemory(const char * data, int length);
void internalLoadFile( const char * load_file );
/* implementation specific data */
Util::ReferenceCount<BitmapData> data;
// int * own;
bool mustResize;
// bool own;
bool error;
std::string path;
static Bitmap * temporary_bitmap;
static Bitmap * temporary_bitmap2;
Color bit8MaskColor;
/* only used by allegro5 for now */
int width, height;
};
/* 8-bit bitmap that supports a palette */
class PaletteBitmap: public Bitmap {
public:
PaletteBitmap();
virtual ~PaletteBitmap();
using Bitmap::operator=;
protected:
Color palette[256];
};
Bitmap memoryPCX(unsigned char * const data, const int length, const bool mask = true);
/* creates a bitmap that can be used as a buffer for the screen.
* on opengl/allegro5 systems this will return the current backbuffer
*/
Bitmap * getScreenBuffer();
struct BlendPoint{
BlendPoint(const Color & color, int length);
Color color;
int length;
};
void blend_palette(Color * pal, int mp, const Color & sc, const Color & ec);
std::vector<Color> blend_palette(const std::vector<BlendPoint> & in);
// bool sameColors(Color color1, Color color2);
class LitBitmap: public Bitmap {
public:
LitBitmap( const Bitmap & b );
LitBitmap();
virtual ~LitBitmap();
using Bitmap::draw;
virtual void draw(const int x, const int y, const Bitmap & where) const;
virtual void draw(const int x, const int y, Filter * filter, const Bitmap & where ) const;
using Bitmap::drawHFlip;
virtual void drawHFlip( const int x, const int y, const Bitmap & where ) const;
virtual void drawHFlip( const int x, const int y, Filter * filter, const Bitmap & where ) const;
using Bitmap::drawVFlip;
virtual void drawVFlip( const int x, const int y, const Bitmap & where ) const;
virtual void drawVFlip( const int x, const int y, Filter * filter, const Bitmap & where ) const;
using Bitmap::drawHVFlip;
virtual void drawHVFlip( const int x, const int y, const Bitmap & where ) const;
virtual void drawHVFlip( const int x, const int y, Filter * filter, const Bitmap & where ) const;
using Bitmap::operator=;
protected:
#ifdef USE_ALLEGRO5
virtual void draw(const int x, const int y, Filter * filter, const Bitmap & where, int flags) const;
#endif
};
class StretchedBitmap: public Bitmap {
public:
/* How to initialize the bitmap */
enum Clear{
/* Don't do anything */
NoClear,
/* Clear (to black) */
FullClear,
/* Fill with the masking color for software rendering and
* do nothing for opengl
*/
Mask
};
StretchedBitmap(int width, int height, const Bitmap & where, Clear = NoClear, QualityFilter filter = NoFilter);
void finish();
void start();
virtual int getWidth() const;
virtual int getHeight() const;
using Bitmap::operator=;
virtual double getScaleWidth() const;
virtual double getScaleHeight() const;
protected:
double width;
double height;
double scale_x, scale_y;
const Bitmap & where;
const QualityFilter filter;
const Clear clearKind;
Bitmap scaleToFilter;
};
class TranslatedBitmap: public Bitmap {
public:
TranslatedBitmap(int x, int y, const Bitmap & where);
using Bitmap::operator=;
using Bitmap::BlitToScreen;
virtual void BlitToScreen() const;
virtual ~TranslatedBitmap();
public:
int x, y;
};
class TranslucentBitmap: public Bitmap {
public:
TranslucentBitmap(const Bitmap & b);
TranslucentBitmap();
virtual ~TranslucentBitmap();
using Bitmap::operator=;
virtual Color blendColor(const Color & color) const;
virtual void startDrawing() const;
virtual void endDrawing() const;
virtual void putPixelNormal(int x, int y, Color col) const;
virtual void rectangleFill(int x1, int y1, int x2, int y2, Color color) const;
virtual void rectangle(int x1, int y1, int x2, int y2, Color color) const;
virtual void fill(Color color) const;
virtual void line( const int x1, const int y1, const int x2, const int y2, const Color color ) const;
virtual void hLine( const int x1, const int y, const int x2, const Color color ) const;
virtual void arc(const int x, const int y, const double ang1, const double ang2, const int radius, const Color color) const;
virtual void arcFilled(const int x, const int y, const double ang1, const double ang2, const int radius, const Color color ) const;
virtual void roundRect(int radius, int x1, int y1, int x2, int y2, Color color) const;
virtual void roundRectFill(int radius, int x1, int y1, int x2, int y2, Graphics::Color color) const;
virtual void circleFill( int x, int y, int radius, Color color ) const;
virtual void ellipse( int x, int y, int rx, int ry, Color color ) const;
virtual void ellipseFill( int x, int y, int rx, int ry, Color color ) const;
using Bitmap::draw;
virtual void draw(const int x, const int y, const Bitmap & where) const;
virtual void draw(const int x, const int y, Filter * filter, const Bitmap & where) const;
// virtual void draw(const int x, const int y, const int startWidth, const int startHeight, const int width, const int height, const Bitmap & where) const;
// virtual void draw(const int x, const int y, const int startWidth, const int startHeight, const int width, const int height, Filter * filter, const Bitmap & where) const;
using Bitmap::drawHFlip;
virtual void drawHFlip(const int x, const int y, const Bitmap & where) const;
virtual void drawHFlip(const int x, const int y, Filter * filter, const Bitmap & where) const;
// virtual void drawHFlip(const int x, const int y, const int startWidth, const int startHeight, const int width, const int height, const Bitmap & where) const;
// virtual void drawHFlip(const int x, const int y, const int startWidth, const int startHeight, const int width, const int height, Filter * filter, const Bitmap & where) const;
virtual void drawVFlip( const int x, const int y, const Bitmap & where ) const;
virtual void drawVFlip( const int x, const int y, Filter * filter, const Bitmap & where ) const;
virtual void drawHVFlip( const int x, const int y, const Bitmap & where ) const;
virtual void drawHVFlip( const int x, const int y, Filter * filter, const Bitmap & where ) const;
protected:
#ifdef USE_ALLEGRO5
virtual void draw(const int x, const int y, Filter * filter, const Bitmap & where, int flags) const;
#endif
};
/* Normal drawing operations but ultimately is drawn translucently onto the parent */
class SubTranslucentBitmap: public Bitmap {
public:
/* How to initialize the bitmap */
enum Clear{
/* Don't do anything */
NoClear,
/* Clear (to black) */
FullClear,
/* Fill with the masking color for software rendering and
* do nothing for opengl
*/
Mask
};
SubTranslucentBitmap(const Bitmap & where, int x, int y, int width, int height, Clear = NoClear);
using Bitmap::operator=;
virtual void roundRect(int radius, int x1, int y1, int x2, int y2, Color color) const;
virtual void roundRectFill(int radius, int x1, int y1, int x2, int y2, Color color) const;
virtual void finish();
virtual void start();
protected:
#ifdef USE_ALLEGRO5
TranslucentBitmap translucent;
#else
Bitmap translucent;
#endif
const Clear clearKind;
};
}
#endif
diff --git a/include/r-tech1/graphics/color.h b/include/r-tech1/graphics/color.h
index cfa65e8b..df7c0ac5 100644
--- a/include/r-tech1/graphics/color.h
+++ b/include/r-tech1/graphics/color.h
@@ -1,6 +1,6 @@
-#ifndef _rtech_graphics_color_h_
-#define _rtech_graphics_color_h_
+#ifndef _rtech1_graphics_color_h_
+#define _rtech1_graphics_color_h_
#include "bitmap.h"
#endif
diff --git a/include/r-tech1/graphics/fire.h b/include/r-tech1/graphics/fire.h
index f45713c4..3232d30b 100644
--- a/include/r-tech1/graphics/fire.h
+++ b/include/r-tech1/graphics/fire.h
@@ -1,45 +1,45 @@
-#ifndef _rtech_fire_93c6678306f3542737be4288dc09cfa9
-#define _rtech_fire_93c6678306f3542737be4288dc09cfa9
+#ifndef _rtech1_fire_93c6678306f3542737be4288dc09cfa9
+#define _rtech1_fire_93c6678306f3542737be4288dc09cfa9
#include "color.h"
namespace Graphics{
class Bitmap;
}
namespace Paintown{
struct Wisp{
double x, y;
int life;
int angle;
};
class Fire{
public:
Fire();
void update();
void draw(const Graphics::Bitmap & work);
virtual ~Fire();
protected:
void updateHotspots();
void updateWisps();
protected:
unsigned char ** data;
/* enough to fill an unsigned char */
static const int MAX_COLORS = 256;
Graphics::Color colors[MAX_COLORS];
static const int MAX_HOTSPOTS = 10;
double hotspots[MAX_HOTSPOTS];
double directions[MAX_HOTSPOTS];
static const int MAX_WISPS = 30;
Wisp wisps[MAX_WISPS];
};
}
#endif
diff --git a/include/r-tech1/graphics/gradient.h b/include/r-tech1/graphics/gradient.h
index 53116db7..8b5df2ea 100644
--- a/include/r-tech1/graphics/gradient.h
+++ b/include/r-tech1/graphics/gradient.h
@@ -1,43 +1,43 @@
-#ifndef _rtech_gradient_h
-#define _rtech_gradient_h
+#ifndef _rtech1_gradient_h
+#define _rtech1_gradient_h
#include "bitmap.h"
#include <stdint.h>
class Token;
namespace Effects{
class Gradient{
public:
Gradient();
Gradient(Graphics::Color singleColor);
Gradient(int size, Graphics::Color startColor, Graphics::Color endColor);
Gradient(const Gradient & copy);
Gradient(const Token * token);
Gradient & operator=(const Gradient & copy);
/* move to next color. update is an alias for `forward' */
void update();
void forward();
void backward();
/* start at startColor */
void reset();
/* get current color */
Graphics::Color current() const;
Graphics::Color current(int offset) const;
virtual ~Gradient();
protected:
Graphics::Color * colors;
uint32_t size;
uint32_t index;
};
}
#endif
diff --git a/include/r-tech1/gui/animation.h b/include/r-tech1/gui/animation.h
index 2aeabb2e..96ad4a03 100644
--- a/include/r-tech1/gui/animation.h
+++ b/include/r-tech1/gui/animation.h
@@ -1,393 +1,393 @@
-#ifndef _rtech_gui_animation_h
-#define _rtech_gui_animation_h
+#ifndef _rtech1_gui_animation_h
+#define _rtech1_gui_animation_h
#include <vector>
#include <map>
#include <string>
#include "coordinate.h"
#include "r-tech1/pointer.h"
#include "r-tech1/graphics/gradient.h"
class Filesystem;
namespace Path{
class AbsolutePath;
}
typedef Path::AbsolutePath AbsolutePath;
namespace Graphics{
class Bitmap;
}
namespace Util{
class Draw;
}
class Token;
namespace Gui{
// To hold images by number easier to access and reuse
typedef std::map<int, Util::ReferenceCount<Graphics::Bitmap> > ImageMap;
/*! Base Element class for frame types */
class Element{
public:
virtual ~Element();
virtual void act(double xvel, double yvel);
virtual void draw(int xaxis, int yaxis, const Graphics::Bitmap &) = 0;
virtual void draw(const Graphics::Bitmap &) = 0;
virtual void reset() = 0;
virtual void setToEnd(const RelativePoint &) = 0;
virtual const std::string getInfo() = 0;
virtual inline const RelativePoint getOffset() const {
return this->offset;
}
virtual inline const RelativePoint getScrollOffset() const {
return this->offset;
}
virtual inline int getTime() const {
return this->time;
}
virtual inline int getAlpha() const {
return this->alpha;
}
protected:
Element(const Token *);
RelativePoint offset;
RelativePoint scrollOffset;
int time;
int alpha;
private:
void parseToken(const Token *);
};
/*! Image Frame */
class ImageFrame : public Element{
public:
ImageFrame(const Token *, ImageMap &, const std::string &);
ImageFrame(Util::ReferenceCount<Graphics::Bitmap> bmp);
virtual ~ImageFrame();
virtual void act(double xvel, double yvel);
virtual void draw(int xaxis, int yaxis, const Graphics::Bitmap &);
virtual void draw(const Graphics::Bitmap &);
virtual void reset();
virtual void setToEnd(const RelativePoint &);
virtual const std::string getInfo();
virtual inline const Util::ReferenceCount<Graphics::Bitmap> & getBitmap() const {
return this->bmp;
}
protected:
virtual void parseToken(const Token *, const std::string &, ImageMap &);
protected:
Util::ReferenceCount<Graphics::Bitmap> bmp;
bool horizontalFlip;
bool verticalFlip;
};
/*! Text Frame */
class TextFrame: public Element {
public:
TextFrame(const Token *);
virtual ~TextFrame();
virtual void act(double xvel, double yvel);
virtual void draw(int xaxis, int yaxis, const Graphics::Bitmap &);
virtual void draw(const Graphics::Bitmap &);
virtual void reset();
virtual void setToEnd(const RelativePoint &);
virtual const std::string getInfo();
protected:
virtual void parseToken(const Token *);
/* FIXME: default this to Globals::DEFAULT_FONT */
std::string font;
std::string message;
int fontWidth, fontHeight;
Effects::Gradient gradient;
};
/* Iterates over a series of items */
class Sequence{
public:
Sequence();
virtual Util::ReferenceCount<Element> getCurrentFrame() const = 0;
virtual int totalTicks() const = 0;
virtual void setToEnd() = 0;
/* Move the sequence along by the number of ticks and at the specified speed
* Returns true if the sequence can't move any farther.
*/
virtual bool forward(int tickCount, double velocityX, double velocityY) = 0;
virtual bool reverse(int tickCount, double velocityX, double velocityY) = 0;
virtual void draw(int xaxis, int yaxis, const Graphics::Bitmap &) const = 0;
virtual void reset() = 0;
virtual void resetTicks() = 0;
/* Forcifully move to the next/previous frame */
virtual void forwardFrame() = 0;
virtual void backFrame() = 0;
virtual ~Sequence();
};
class SequenceFrame: public Sequence {
public:
SequenceFrame(const Util::ReferenceCount<Element> & frame);
virtual Util::ReferenceCount<Element> getCurrentFrame() const;
virtual int totalTicks() const;
virtual void reset();
virtual void resetTicks();
virtual void setToEnd();
virtual void draw(int xaxis, int yaxis, const Graphics::Bitmap &) const;
/* Move the sequence along by the number of ticks and at the specified speed */
virtual bool forward(int tickCount, double velocityX, double velocityY);
virtual bool reverse(int tickCount, double velocityX, double velocityY);
/* Forcifully move to the next/previous frame */
virtual void forwardFrame();
virtual void backFrame();
protected:
Util::ReferenceCount<Element> frame;
int ticks;
};
/* Shows sequences in a loop */
class SequenceLoop: public Sequence {
public:
SequenceLoop(int loops);
virtual Util::ReferenceCount<Element> getCurrentFrame() const;
virtual void reset();
virtual void resetTicks();
virtual void setToEnd();
virtual void addSequence(const Util::ReferenceCount<Sequence> & sequence);
virtual void parse(const Token * token, ImageMap & map, const std::string & baseDir);
virtual void draw(int xaxis, int yaxis, const Graphics::Bitmap &) const;
virtual int totalTicks() const;
/* Move the sequence along by the number of ticks and at the specified speed */
virtual bool forward(int tickCount, double velocityX, double velocityY);
virtual bool reverse(int tickCount, double velocityX, double velocityY);
/* Forcifully move to the next/previous frame */
virtual void forwardFrame();
virtual void backFrame();
protected:
void resetChildrenTicks();
virtual Util::ReferenceCount<Sequence> getCurrentSequence() const;
/* The current frame to display */
unsigned int currentFrame;
/* The number of times left to loop */
unsigned int currentLoop;
/* The total number of times to loop */
const unsigned int loopTimes;
std::vector<Util::ReferenceCount<Sequence> > frames;
};
/* Shows all sequences simaltaneously */
class SequenceAll: public Sequence {
public:
SequenceAll(const Token * token, ImageMap & images, const std::string & baseDir);
virtual Util::ReferenceCount<Element> getCurrentFrame() const;
virtual void reset();
virtual void resetTicks();
virtual void setToEnd();
virtual void addSequence(const Util::ReferenceCount<Sequence> & sequence);
virtual void draw(int xaxis, int yaxis, const Graphics::Bitmap &) const;
virtual int totalTicks() const;
/* Move the sequence along by the number of ticks and at the specified speed */
virtual bool forward(int tickCount, double velocityX, double velocityY);
virtual bool reverse(int tickCount, double velocityX, double velocityY);
/* Forcifully move to the next/previous frame */
virtual void forwardFrame();
virtual void backFrame();
protected:
std::vector<Util::ReferenceCount<Sequence> > sequences;
typedef std::vector<Util::ReferenceCount<Sequence> >::iterator SequenceIterator;
typedef std::vector<Util::ReferenceCount<Sequence> >::const_iterator SequenceConstIterator;
};
/* Displays a random child node for its duration */
class SequenceRandom: public Sequence {
public:
SequenceRandom(const Token * token, ImageMap & images, const std::string & baseDir);
virtual Util::ReferenceCount<Element> getCurrentFrame() const;
virtual void reset();
virtual void resetTicks();
virtual void setToEnd();
virtual void addSequence(const Util::ReferenceCount<Sequence> & sequence);
virtual void draw(int xaxis, int yaxis, const Graphics::Bitmap &) const;
virtual int totalTicks() const;
/* Move the sequence along by the number of ticks and at the specified speed */
virtual bool forward(int tickCount, double velocityX, double velocityY);
virtual bool reverse(int tickCount, double velocityX, double velocityY);
/* Forcifully move to the next/previous frame */
virtual void forwardFrame();
virtual void backFrame();
protected:
unsigned int current;
std::vector<Util::ReferenceCount<Sequence> > sequences;
typedef std::vector<Util::ReferenceCount<Sequence> >::iterator SequenceIterator;
typedef std::vector<Util::ReferenceCount<Sequence> >::const_iterator SequenceConstIterator;
};
/* Handles a series of bitmaps */
class Animation{
protected:
Animation();
public:
Animation(const Token *token);
/*! Load only a single bitmap (for backwards compatibility of backgrounds in menu) */
Animation(const std::string &);
Animation(const AbsolutePath &);
/*! use an existing bitmap */
Animation(Util::ReferenceCount<Graphics::Bitmap> image);
virtual ~Animation();
/*! Reverse with ticks */
virtual void reverse(int tickCount = 1);
/*! Forward with ticks */
virtual void forward(int tickCount = 1);
/*! Logic ticking per iteration and moving to subsequent frames */
virtual void act();
/*! Draw */
virtual void draw(const Graphics::Bitmap &) const;
virtual void draw(int x, int y, int width, int height, const Graphics::Bitmap &) const;
/*! Forward to next frame with no regard to ticks */
virtual void forwardFrame();
/*! Back a frame with no regard to ticks */
virtual void backFrame();
/*! Reset everything to the beginning of the start of the animation */
virtual void resetAll();
/*! Set everything to the end of the animation */
virtual void setToEnd();
/*! Get printable information regarding current frame */
virtual const std::string getInfo();
/*! Reset only frame ticks and other things are ignored */
virtual void reset();
/* Total number of ticks used by this animation. If any frames have a time
* of -1 then the total time will also be -1, meaning infinity.
*/
virtual int totalTicks() const;
/*! Return ID */
virtual inline int getID() const {
return id;
}
/*! Depth of animation
TODO make depth unlimited and just use integers for weight of depth
*/
enum Depth {
BackgroundBottom,
BackgroundMiddle,
BackgroundTop,
ForegroundBottom,
ForegroundMiddle,
ForegroundTop,
};
/*! Get depth */
inline const Depth & getDepth() const {
return this->depth;
}
protected:
int id;
Depth depth;
unsigned int currentSequence;
bool allowReset;
RelativePoint axis;
// This allows the frames to scroll in place
RelativePoint velocity;
Coordinate window;
// std::vector<Util::ReferenceCount<Frame> > frames;
SequenceLoop sequence;
ImageMap images;
};
/* Handles a Util::Draw, which really can't be controlled in any way. This just wraps the drawer.draw() method */
class DrawableAnimation: public Animation {
public:
DrawableAnimation(const Util::ReferenceCount<Util::Draw> & drawer, Depth depth);
DrawableAnimation(const Util::ReferenceCount<Util::Draw> & drawer);
virtual void draw(const Graphics::Bitmap &) const;
virtual void draw(int x, int y, int width, int height, const Graphics::Bitmap &) const;
protected:
const Util::ReferenceCount<Util::Draw> drawer;
};
/*! Generalized to for re-use in other contexts (menu, cutscene, characterselect, etc) */
class AnimationManager{
public:
AnimationManager();
AnimationManager(const AnimationManager &);
virtual ~AnimationManager();
const AnimationManager & operator=(const AnimationManager &);
void forward(int tickCount = 1);
void reverse(int tickCount = 1);
void act();
void render(const Gui::Animation::Depth &, const Graphics::Bitmap &) const;
void add(const Util::ReferenceCount<Gui::Animation > & animation);
void reset();
void setToEnd();
int totalTicks() const;
const std::string getInfo(int id, bool all = false);
const std::vector<int> getIdList();
virtual inline const bool empty() const{
return this->animations.empty();
}
protected:
int countTicks(const std::vector<Util::ReferenceCount<Gui::Animation> > & toCount) const;
private:
std::map< Gui::Animation::Depth, std::vector< Util::ReferenceCount<Gui::Animation> > > animations;
};
}
#endif
diff --git a/include/r-tech1/gui/box.h b/include/r-tech1/gui/box.h
index c414aa04..726caae0 100644
--- a/include/r-tech1/gui/box.h
+++ b/include/r-tech1/gui/box.h
@@ -1,34 +1,34 @@
-#ifndef _rtech_gui_box_h
-#define _rtech_gui_box_h
+#ifndef _rtech1_gui_box_h
+#define _rtech1_gui_box_h
#include <string>
#include "widget.h"
namespace Gui{
class Box : public Widget {
public:
Box();
Box( const Box & b );
virtual ~Box();
// copy
Box &operator=( const Box &);
// Logic
virtual void act(const Font &);
// Render
using Widget::render;
virtual void render(const Graphics::Bitmap &);
// Do a message Dialog centered with respect to the given width/height
static void messageDialog(int width, int height, const std::string & message, int radius = 0);
protected:
};
}
#endif
diff --git a/include/r-tech1/gui/container.h b/include/r-tech1/gui/container.h
index 1c2c28b2..cb33d4da 100644
--- a/include/r-tech1/gui/container.h
+++ b/include/r-tech1/gui/container.h
@@ -1,42 +1,42 @@
-#ifndef _rtech_gui_container_h
-#define _rtech_gui_container_h
+#ifndef _rtech1_gui_container_h
+#define _rtech1_gui_container_h
#include <list>
#include "rectarea.h"
namespace Graphics{
class Bitmap;
}
class Font;
namespace Gui{
class Widget;
class Container{
public:
Container();
virtual ~Container();
// position info
RectArea position;
// Logic
void act(const Font & font);
// Render
void render(const Graphics::Bitmap &);
// Add widget
void add(Widget *widget);
// Remove widget
void remove(Widget *widget);
private:
std::list<Widget *>widgets;
};
}
#endif
diff --git a/include/r-tech1/gui/context-box.h b/include/r-tech1/gui/context-box.h
index 75625114..83c33fb6 100644
--- a/include/r-tech1/gui/context-box.h
+++ b/include/r-tech1/gui/context-box.h
@@ -1,262 +1,262 @@
-#ifndef _rtech_gui_context_box_h
-#define _rtech_gui_context_box_h
+#ifndef _rtech1_gui_context_box_h
+#define _rtech1_gui_context_box_h
#include <string>
#include <vector>
#include "widget.h"
#include "popup-box.h"
#include "scroll-list.h"
#include "r-tech1/language-string.h"
#include "r-tech1/graphics/gradient.h"
#include "r-tech1/file-system.h"
#include "r-tech1/pointer.h"
class Token;
namespace Gui{
Effects::Gradient standardGradient(int max);
Effects::Gradient modifiedGradient(Graphics::Color low, Graphics::Color high, int max);
class ListValues{
public:
ListValues();
ListValues(const ListValues &);
virtual ~ListValues();
const ListValues & operator=(const ListValues &);
void getValues(const Token *);
virtual inline bool getInterpolate() const {
return this->interpolate;
}
virtual inline void setInterpolate(bool interpolate){
this->interpolate = interpolate;
}
virtual inline Graphics::Color getLowColor() const {
return this->lowColor;
}
virtual inline void setLowColor(Graphics::Color color){
this->lowColor = color;
}
virtual inline Graphics::Color getHighColor() const {
return this->highColor;
}
virtual inline void setHighColor(Graphics::Color color){
this->highColor = color;
}
virtual inline int getMaxGradient() const {
return this->maxGradient;
}
virtual inline void setMaxGradient(int max){
this->maxGradient = max;
}
virtual inline Graphics::Color getSelectedColor() const {
return this->selectedColor;
}
virtual inline void setSelectedColor(Graphics::Color color){
this->selectedColor = color;
}
virtual inline int getSelectedAlpha() const {
return this->selectedAlpha;
}
virtual inline void setSelectedAlpha(int alpha){
this->selectedAlpha = alpha;
}
virtual inline Graphics::Color getOtherColor() const {
return this->otherColor;
}
virtual inline void setOtherColor(Graphics::Color color){
this->otherColor = color;
}
virtual inline int getOtherAlpha() const {
return this->otherAlpha;
}
virtual inline void setOtherAlpha(int alpha){
this->otherAlpha = alpha;
}
virtual inline double getDistanceFadeMultiplier() const{
return this->distanceFadeMultiplier;
}
virtual inline void setDistanceFadeMultiplier(double multiplier){
this->distanceFadeMultiplier = multiplier;
}
virtual inline bool getDistanceFade() const {
return this->fade;
}
/* Whether or not non-selected items are faded proportional to their distance from the
* selected item.
*/
virtual inline void setDistanceFade(bool fade){
this->fade = fade;
}
protected:
bool interpolate;
Graphics::Color lowColor, highColor;
int maxGradient;
Graphics::Color selectedColor;
int selectedAlpha;
Graphics::Color otherColor;
int otherAlpha;
double distanceFadeMultiplier;
bool fade;
};
class ContextBox;
class ScrollListInterface;
class ContextItem: public ScrollItem {
public:
ContextItem(const std::string &, const ContextBox &);
virtual ~ContextItem();
virtual void draw(int x, int y, const Graphics::Bitmap & where, const Font & font, int distance) const;
virtual int size(const Font & font) const;
virtual void setText(const LanguageString & t);
inline const LanguageString & getLanguageText() const {
return text;
}
virtual inline std::string getText() const { return text.get(); }
protected:
LanguageString text;
const ContextBox & parent;
};
class ContextBox: public Widget {
public:
ContextBox();
ContextBox(const ContextBox &);
virtual ~ContextBox();
//! copy
ContextBox &operator=(const ContextBox &);
//! Logic
virtual void act(const Font &);
//! Render
using Widget::render;
virtual void render(const Graphics::Bitmap &);
virtual void render(const Graphics::Bitmap &, const Font & font);
//! Next
virtual bool next(const Font &);
//! Previous
virtual bool previous(const Font &);
//! Adjust left
virtual void adjustLeft();
//! Adjust right
virtual void adjustRight();
//! open context box
virtual void open();
//! Close context box
virtual void close();
//! Set context list
virtual void setList(const std::vector<Util::ReferenceCount<ContextItem> > & list);
virtual void addItem(const Util::ReferenceCount<ContextItem> & item);
/*! Scroll or Normal */
enum ListType{
Normal,
Scroll,
};
virtual void setListType(const ListType &);
virtual void setListWrap(bool wrap);
virtual Graphics::Color getSelectedColor() const;
//! Get current index
virtual inline unsigned int getCurrentIndex(){
return this->list->getCurrentIndex();
}
//! Is active?
virtual inline bool isActive(){
return (this->fadeState != NotActive);
}
//!set fadespeed
virtual inline void setFadeSpeed(int speed){
this->fadeSpeed = speed;
this->board.setFadeSpeed(speed);
}
//!set fade alpha
virtual inline void setFadeAlpha(int alpha){
this->fadeAlpha = alpha;
}
virtual inline int getFadeAlpha() const {
return this->fadeAlpha;
}
//! Set to use only text on background
virtual inline void setRenderOnlyText(bool render){
this->renderOnlyText = render;
}
virtual inline PopupBox & getBoard(){
return board;
}
virtual inline const Gui::ListValues & getListValues() const {
return this->values;
}
virtual inline Gui::ListValues & getListValues(){
return this->values;
}
virtual void setListValues(const Gui::ListValues & values);
private:
void doFade();
void drawText(const Graphics::Bitmap &, const Font & font);
enum FadeState{
NotActive,
FadeIn,
Active,
FadeOut,
};
//! Current fade state
FadeState fadeState;
//! Context list
Util::ReferenceCount<ScrollListInterface> list;
//! Fade speed
int fadeSpeed;
//! Fade Aplha
int fadeAlpha;
//! Board
PopupBox board;
//! The centered position
int cursorCenter;
//! Current y coordinate to render text from
int cursorLocation;
//! scroll wait
int scrollWait;
//! Gradient for selected cursor
Effects::Gradient selectedGradient;
//! Render Text only
bool renderOnlyText;
/*! List Values */
Gui::ListValues values;
};
}
#endif
diff --git a/include/r-tech1/gui/coordinate.h b/include/r-tech1/gui/coordinate.h
index bab89e62..1fcd36f3 100644
--- a/include/r-tech1/gui/coordinate.h
+++ b/include/r-tech1/gui/coordinate.h
@@ -1,236 +1,236 @@
-#ifndef _rtech_gui_coordinate_h
-#define _rtech_gui_coordinate_h
+#ifndef _rtech1_gui_coordinate_h
+#define _rtech1_gui_coordinate_h
namespace Graphics{
class Bitmap;
}
namespace Gui {
namespace Space{
class Space;
/* a 2-d point */
class Point{
public:
Point(double x, double y, const Space & space);
Point(const Point & point, const Space & space);
Point(const Point & point);
Point operator+(const Point &);
Point & operator+=(const Point &);
Point & operator=(const Point &);
bool operator==(const Point &) const;
bool operator!=(const Point &) const;
/* convert to physical space */
double physicalX() const;
double physicalY() const;
double x;
double y;
const Space & space;
private:
/* true if points use the same space system */
bool sameSpace(const Point & point) const;
};
/* mapping from coordinate space to physical space */
class Space{
public:
Space(double minX, double minY, double maxX, double maxY);
Point fromPhysical(int x, int y);
Point fromLocal(double x, double y);
bool operator==(const Space & space) const;
/* clamp the values to the size of the space */
double boundX(double x) const;
double boundY(double y) const;
double getMinimumX() const;
double getMinimumY() const;
double sizeX() const;
double sizeY() const;
double centerX() const;
double centerY() const;
double getLocalX(double physicalX) const;
double getLocalY(double physicalY) const;
private:
double minX, minY, maxX, maxY;
};
}
/* Coordinate system for handling scalable graphics */
class AbsolutePoint {
public:
AbsolutePoint();
explicit AbsolutePoint(int x, int y);
AbsolutePoint(const AbsolutePoint &);
virtual ~AbsolutePoint();
const AbsolutePoint & operator=(const AbsolutePoint &);
virtual inline void setX(int x){
this->x = x;
}
virtual int getX() const;
virtual inline void setY(int y){
this->y = y;
}
virtual int getY() const;
private:
int x;
int y;
};
class RelativePoint {
public:
RelativePoint();
explicit RelativePoint(double x, double y);
RelativePoint(const RelativePoint &);
RelativePoint(const AbsolutePoint &);
virtual ~RelativePoint();
const RelativePoint & operator=(const RelativePoint &);
const RelativePoint & operator=(const AbsolutePoint &);
bool operator==(const RelativePoint &);
bool operator!=(const RelativePoint &);
virtual inline void setX(double x){
this->x = x;
}
virtual int getX() const;
virtual inline void setY(double y){
this->y = y;
}
virtual int getY() const;
virtual inline void set(double x, double y){
this->x = x;
this->y = y;
}
virtual int getDistanceFromCenterX() const;
virtual int getDistanceFromCenterY() const;
virtual void moveX(double percent);
virtual void moveY(double percent);
virtual void moveBy(double x, double y);
virtual AbsolutePoint getAbsolute();
virtual double getRelativeX() const;
virtual double getRelativeY() const;
private:
double x;
double y;
};
class Coordinate {
public:
Coordinate();
Coordinate(AbsolutePoint &, AbsolutePoint &);
Coordinate(const RelativePoint &, const RelativePoint &);
Coordinate(const Coordinate &);
virtual ~Coordinate();
const Coordinate & operator=(const Coordinate &);
virtual inline void setZ(double z){
this->z = z;
}
virtual inline double getZ() const{
return this->z;
}
virtual int getX() const;
virtual int getY() const;
virtual int getWidth() const;
virtual int getHeight() const;
virtual int getX2() const;
virtual int getY2() const;
/* give a relative quantity */
virtual void growHorizontal(double by);
/* give an absolute quantity */
virtual void growHorizontalAbsolute(int by);
/* give a relative quantity */
virtual void growVertical(double by);
/* give an absolute quantity */
virtual void growVerticalAbsolute(int by);
virtual void growTo(const Coordinate &, double percent = 0.005);
virtual void center(const Coordinate &);
virtual void moveBy(double x, double y);
virtual inline double getRelativeX1() const{
return this->position.getRelativeX();
}
virtual inline double getRelativeX2() const{
return this->position2.getRelativeX();
}
virtual inline double getRelativeY1() const{
return this->position.getRelativeY();
}
virtual inline double getRelativeY2() const{
return this->position2.getRelativeY();
}
virtual inline void set(double x1, double y1, double x2, double y2){
this->position.setX(x1);
this->position.setY(y1);
this->position2.setX(x2);
this->position2.setY(y2);
}
virtual inline void setX1(double x){
this->position.setX(x);
}
virtual inline void setX2(double x){
this->position2.setX(x);
}
virtual inline void setY1(double y){
this->position.setY(y);
}
virtual inline void setY2(double y){
this->position2.setY(y);
}
bool operator==( const Coordinate &);
bool operator!=( const Coordinate &);
bool operator==( const Graphics::Bitmap &);
bool operator!=( const Graphics::Bitmap &);
/* moves the positions so that `center' is in the middle but the
* width/height is maintained
*/
virtual void setCenterPosition(const RelativePoint & center);
virtual void setPosition(const RelativePoint &);
virtual void setPosition(const AbsolutePoint &);
virtual void setPosition2(const RelativePoint &);
virtual void setPosition2(const AbsolutePoint &);
virtual void moveTo(const AbsolutePoint &);
virtual void setDimensions(int width, int height);
virtual inline const RelativePoint & getPosition() const {
return this->position;
}
virtual inline const RelativePoint & getPosition2() const {
return this->position2;
}
virtual inline bool empty(){
return (getWidth() == 0 && getHeight() == 0);
}
private:
void checkDimensions();
RelativePoint position;
RelativePoint position2;
double z;
};
}
#endif
diff --git a/include/r-tech1/gui/lineedit.h b/include/r-tech1/gui/lineedit.h
index f3bc022a..6832bee5 100644
--- a/include/r-tech1/gui/lineedit.h
+++ b/include/r-tech1/gui/lineedit.h
@@ -1,78 +1,78 @@
-#ifndef _rtech_gui_lineedit_h
-#define _rtech_gui_lineedit_h
+#ifndef _rtech1_gui_lineedit_h
+#define _rtech1_gui_lineedit_h
#include <iostream>
#include <vector>
#include "widget.h"
#include "timer.h"
#include "r-tech1/input/text-input.h"
class Font;
class keys;
namespace Gui{
class LineEdit: public Widget{
public:
//! Constructor
LineEdit();
//! Destructor
virtual ~LineEdit();
//! Set textColor
void setTextColor(const Graphics::Color color);
//! Set textColor
void setCursorColor(const Graphics::Color color);
//! Update
void act(const Font &);
//! Draw
void draw(const Font &, const Graphics::Bitmap &);
//! Render
using Gui::Widget::render;
void render(const Graphics::Bitmap &);
virtual void toggleEnabled();
virtual void setFocused(bool enabled);
virtual void addHook(int key, void (*callback)(void *), void * arg);
virtual bool didChanged(unsigned long long &);
virtual inline const std::string getText() const {
return this->input.getText();
}
virtual inline void setText(const std::string & text){
this->input.setText(text);
}
virtual inline void clear(){
this->input.clearInput();
}
virtual inline void setBlinkRate(int rate){
this->blinkRate = rate;
}
protected:
void renderCursor(int x, int y, const Font &, const Graphics::Bitmap &);
Graphics::Color textColor;
Graphics::Color cursorColor;
TextInput input;
int blinkRate;
int cursorTime;
bool changed;
};
}
#endif
diff --git a/include/r-tech1/gui/popup-box.h b/include/r-tech1/gui/popup-box.h
index 1ce15a65..110f13e3 100644
--- a/include/r-tech1/gui/popup-box.h
+++ b/include/r-tech1/gui/popup-box.h
@@ -1,76 +1,76 @@
-#ifndef _rtech_gui_popup_box_h
-#define _rtech_gui_popup_box_h
+#ifndef _rtech1_gui_popup_box_h
+#define _rtech1_gui_popup_box_h
#include <string>
#include <vector>
#include "widget.h"
#include "box.h"
#include "r-tech1/graphics/gradient.h"
namespace Gui{
class PopupBox : public Widget {
public:
PopupBox();
PopupBox(const PopupBox &);
virtual ~PopupBox();
//! copy
PopupBox &operator=(const PopupBox &);
//! Logic
virtual void act(const Font &);
//! Render
using Widget::render;
virtual void render(const Graphics::Bitmap &);
//! Open box
virtual void open();
//! Close box
virtual void close();
//! Is active?
virtual inline bool isActive(){
return (this->fadeState != Closed);
}
virtual inline bool isOpen(){
return this->fadeState == Open ||
this->fadeState == FadeIn;
}
//!set fadespeed
virtual inline void setFadeSpeed(int speed){
this->fadeSpeed = speed;
}
//! Get current box coordinates
virtual inline const Coordinate & getArea(){
return this->board.location;
}
//! Get current box transformations
virtual inline const Gui::Transformations & getTransforms(){
return this->board.transforms;
}
private:
void doFade();
enum FadeState{
Closed,
FadeIn,
Open,
FadeOut,
};
//! Current fade state
FadeState fadeState;
//! Fade speed
int fadeSpeed;
//! Board
Box board;
};
}
#endif
diff --git a/include/r-tech1/gui/rectarea.h b/include/r-tech1/gui/rectarea.h
index 4459a7fd..f6472de5 100644
--- a/include/r-tech1/gui/rectarea.h
+++ b/include/r-tech1/gui/rectarea.h
@@ -1,31 +1,31 @@
-#ifndef _rtech_gui_rectarea_h
-#define _rtech_gui_rectarea_h
+#ifndef _rtech1_gui_rectarea_h
+#define _rtech1_gui_rectarea_h
namespace Graphics{
class Bitmap;
}
namespace Gui{
struct RectArea{
RectArea();
RectArea(int x, int y, int w, int h);
inline int getX1() const { return x; }
inline int getY1() const { return y; }
inline int getX2() const { return x + width; }
inline int getY2() const { return y + height; }
bool operator==( const RectArea &);
bool operator!=( const RectArea &);
bool operator==( const Graphics::Bitmap &);
bool operator!=( const Graphics::Bitmap &);
bool empty();
int x;
int y;
int width;
int height;
int radius;
};
}
#endif
diff --git a/include/r-tech1/gui/tabbed-box.h b/include/r-tech1/gui/tabbed-box.h
index e016f6c3..3665db5b 100644
--- a/include/r-tech1/gui/tabbed-box.h
+++ b/include/r-tech1/gui/tabbed-box.h
@@ -1,161 +1,161 @@
-#ifndef _rtech_gui_tabbed_box_h
-#define _rtech_gui_tabbed_box_h
+#ifndef _rtech1_gui_tabbed_box_h
+#define _rtech1_gui_tabbed_box_h
#include <string>
#include <vector>
#include "widget.h"
#include "../file-system.h"
#include "../pointer.h"
#include "../graphics/gradient.h"
#include "context-box.h"
class Token;
namespace Gui{
class ContextBox;
class Tab{
public:
Tab();
virtual ~Tab();
void addOption(const Util::ReferenceCount<ContextItem> & item);
virtual void render(const Graphics::Bitmap & work, const Font & font);
virtual void act(const Font & font);
virtual void setList(const std::vector<Util::ReferenceCount<ContextItem> > & list);
virtual const Gui::ContextBox & getContext() const {
return context;
}
virtual Gui::ContextBox & getContext(){
return context;
}
virtual void close();
virtual void open();
virtual void previous(const Font & font);
virtual void next(const Font & font);
virtual void adjustLeft();
virtual void adjustRight();
virtual int getCurrentIndex();
virtual void setName(const std::string & name);
std::string name;
bool active;
protected:
Gui::ContextBox context;
};
class TabbedBox: public Widget {
public:
TabbedBox();
TabbedBox( const TabbedBox & );
virtual ~TabbedBox();
//! copy
TabbedBox &operator=( const TabbedBox &);
//! Logic
virtual void act(const Font &);
//! Render
using Widget::render;
virtual void render(const Graphics::Bitmap &);
virtual void render(const Graphics::Bitmap &, const Font &);
//! Add tab
virtual void addTab(const std::string &, const std::vector<Util::ReferenceCount<ContextItem> > & list);
virtual void addTab(Tab * tab);
//! Up
virtual void up(const Font &);
//! Down
virtual void down(const Font &);
//! Left
virtual void left(const Font &);
//! Right
virtual void right(const Font &);
//! Virtual
virtual void toggleTabSelect();
//! Set current font
virtual inline void setFont(const Filesystem::RelativePath & font, int width, int height){
this->font = font;
this->fontWidth = width;
this->fontHeight = height;
}
//! Get current tab
virtual inline unsigned int getCurrentTab() const {
return this->current;
}
//! Get current index on selected tab
virtual unsigned int getCurrentIndex() const;
//! Set tab font colors
virtual void setTabFontColor(Graphics::Color color);
//! Set selected tab font color
virtual void setSelectedTabFontColor(Graphics::Color color);
//! Empty
virtual inline bool empty() const {
return this->tabs.empty();
}
virtual inline bool isInTab() const {
return this->inTab;
}
/*! Tab Colors */
ColorInfo tabColors;
/*! Selected Tab Colors */
ColorInfo selectedTabColors;
/*! Selected Tab Colors */
ColorInfo runningTabColors;
protected:
void moveTab(int direction);
std::vector<Gui::Tab *> tabs;
unsigned int current;
Filesystem::RelativePath font;
int fontWidth;
int fontHeight;
/*! Is in tab */
bool inTab;
/*! Max Width of tabs */
int tabWidthMax;
/*! Render tab */
void renderTabs(const Graphics::Bitmap &, const Font &);
/*! Font Color */
Graphics::Color tabFontColor;
/*! Current Tab Font Color */
Graphics::Color currentTabFontColor;
/*! Gradient for selected Font */
Effects::Gradient * activeTabFontColor;
};
}
#endif
diff --git a/include/r-tech1/gui/widget.h b/include/r-tech1/gui/widget.h
index 74c718e3..a2f3f83f 100644
--- a/include/r-tech1/gui/widget.h
+++ b/include/r-tech1/gui/widget.h
@@ -1,86 +1,86 @@
-#ifndef _rtech_gui_widget_h
-#define _rtech_gui_widget_h
+#ifndef _rtech1_gui_widget_h
+#define _rtech1_gui_widget_h
#include "rectarea.h"
#include "coordinate.h"
#include "r-tech1/graphics/bitmap.h"
#include "r-tech1/pointer.h"
namespace Graphics{
class Bitmap;
}
class Token;
class Font;
namespace Gui{
struct ColorInfo{
ColorInfo();
Graphics::Color body;
int bodyAlpha;
Graphics::Color border;
int borderAlpha;
};
/*! Trasformations for widgets
* Eventually this could be expanded and used as something to perform changes on widgets but for now it remains to be just a place holder
* ************************
* radius - rounded corners
*/
class Transformations{
public:
Transformations();
Transformations(const Transformations &);
virtual ~Transformations();
Transformations & operator=(const Transformations &);
virtual inline void setRadius(double radius){
this->radius = radius;
}
virtual inline double getRadius() const{
return this->radius;
}
private:
double radius;
};
class Widget{
public:
Widget();
Widget( const Widget &);
virtual ~Widget();
// copy
Widget &operator=( const Widget &);
void setCoordinates(const Token * token);
void setColors(const Token * token);
void setTransforms(const Token * token);
//! New position data
Coordinate location;
//! Colors
ColorInfo colors;
//! Transformations
Transformations transforms;
// Logic
virtual void act(const Font &)=0;
// Render
virtual void render(const Graphics::Bitmap &) = 0;
/* default behavior is just to call render() */
virtual void render(const Graphics::Bitmap &, const Font &);
// draw box
static void drawBox(int radius, int x1, int y1, int x2, int y2, const Gui::ColorInfo &, const Graphics::Bitmap &);
protected:
Util::ReferenceCount<Graphics::Bitmap> checkWorkArea(const Graphics::Bitmap & parent);
};
}
#endif
diff --git a/include/r-tech1/init.h b/include/r-tech1/init.h
index f92a05b3..239eb4c9 100644
--- a/include/r-tech1/init.h
+++ b/include/r-tech1/init.h
@@ -1,61 +1,61 @@
-#ifndef _rtech_init_h
-#define _rtech_init_h
+#ifndef _rtech1_init_h
+#define _rtech1_init_h
/* global vars */
/*
#define GFX_X 640
#define GFX_Y 480
*/
namespace Global{
extern volatile int speed_counter4;
extern volatile unsigned int second_counter;
// extern const double LOGIC_MULTIPLIER;
extern int TICS_PER_SECOND;
extern const int WINDOWED;
extern const int FULLSCREEN;
extern bool rateLimit;
class InitConditions{
public:
InitConditions();
enum WindowMode{
Disabled,
Default,
Window,
Fullscreen
};
WindowMode graphics;
bool sound;
bool fullscreen;
bool networking;
};
bool init(const InitConditions & conditions);
void close();
// bool initNoGraphics();
/* Check for the data path */
bool dataCheck();
/* Returns a consistent number of ticks per second regardless of what
* TICS_PER_SECOND is.
*/
double ticksPerSecond(int ticks);
/* Updates TICS_PER_SECOND */
void setTicksPerSecond(int ticks);
}
/*
#define GFX_X 320
#define GFX_Y 240
*/
#endif
diff --git a/include/r-tech1/input/allegro5/joystick.h b/include/r-tech1/input/allegro5/joystick.h
index 4b3f1af2..68adb3cd 100644
--- a/include/r-tech1/input/allegro5/joystick.h
+++ b/include/r-tech1/input/allegro5/joystick.h
@@ -1,36 +1,36 @@
-#ifndef _rtech_allegro5_joystick_h
-#define _rtech_allegro5_joystick_h
+#ifndef _rtech1_allegro5_joystick_h
+#define _rtech1_allegro5_joystick_h
#include "r-tech1/input/joystick.h"
#include "r-tech1/pointer.h"
#include <string>
struct ALLEGRO_EVENT_QUEUE;
class ButtonMapping;
class Allegro5Joystick: public Joystick {
public:
virtual void poll();
virtual int getDeviceId() const;
virtual std::string getName() const;
virtual Key getKey(int button);
virtual int getButton(Key key);
virtual std::map<int, std::map<int, double> > getCurrentAxisValues() const;
virtual ~Allegro5Joystick();
friend class Joystick;
protected:
void axis(int stick, int axis, float position);
void buttonDown(int button);
void buttonUp(int button);
Allegro5Joystick(int id);
int id;
ALLEGRO_EVENT_QUEUE * queue;
Util::ReferenceCount<ButtonMapping> buttons;
};
#endif
diff --git a/include/r-tech1/input/input-manager.h b/include/r-tech1/input/input-manager.h
index 2ec407b7..0c206260 100644
--- a/include/r-tech1/input/input-manager.h
+++ b/include/r-tech1/input/input-manager.h
@@ -1,316 +1,316 @@
-#ifndef _rtech_input_manager
-#define _rtech_input_manager
+#ifndef _rtech1_input_manager
+#define _rtech1_input_manager
#include <vector>
#include <algorithm>
#include "input.h"
#include "input-map.h"
#include "input-source.h"
#include "r-tech1/funcs.h"
#include "r-tech1/pointer.h"
#include "r-tech1/events.h"
#include "keyboard.h"
#include "joystick.h"
#include "r-tech1/exceptions/exception.h"
class Configuration;
class InputSource;
template <class Output>
class InputHandler{
public:
InputHandler(){
}
virtual ~InputHandler(){
}
virtual void press(const Output & out, Keyboard::unicode_t unicode) = 0;
virtual void release(const Output & out, Keyboard::unicode_t unicode) = 0;
};
/* handles keyboard/joystick/whatever input during the game */
class InputManager{
public:
/* main has one instance of this and thats it.
* should the janitor have the reference instead?
*/
friend int rtech_main(int, char**);
friend int main(int, char **);
/* returns true if any input device is activated (keys pressed, joystick button */
static bool anyInput();
// static std::vector<Input::PaintownInput> getInput(const Configuration & configuration, const int facing);
static void poll();
/*
static void enableBufferInput();
static void disableBufferInput();
*/
static void waitForKeys(int key1, int key2, const InputSource & source);
static void waitForKeys(int key1, const InputSource & source);
static int readKey();
static void waitForClear();
static void deferResizeEvents(bool defer);
static const std::map<int, Util::ReferenceCount<Joystick> > & getJoysticks();
/*
template <class X>
static void observeKeyboard(InputMap<X> & input){
manager->keyboard.addObserver(InputMap<X>::observeKey, &input);
}
template <class X>
static void unObserveKeyboard(InputMap<X> & input){
manager->keyboard.removeObserver(InputMap<X>::observeKey, &input);
}
*/
static std::vector<Keyboard::unicode_t> readText(){
return manager->keyboard.readText();
}
template <typename X>
static std::vector<Keyboard::unicode_t> readText(InputMap<X> & input, typename InputMap<X>::Output & output){
return manager->_readText(input, output);
}
#if 0
template <typename X>
static typename InputMap<X>::Output getMap(InputMap<X> & input){
if (manager){
return manager->_getMap(input);
}
/* just crash hard.. who cares */
throw Exception::Base(__FILE__, __LINE__);
/* make the compiler happy about returning something */
return *(typename InputMap<X>::Output*)1;
}
#endif
template <typename X>
static typename std::vector<typename InputMap<X>::InputEvent> getEvents(InputMap<X> & input, const InputSource & source){
return manager->_getEvents(input, source);
}
template <typename X>
static void handleEvents(InputMap<X> & input, const InputSource & source, InputHandler<X> & handler){
typename std::vector<typename InputMap<X>::InputEvent> events = getEvents(input, source);
for (typename std::vector<typename InputMap<X>::InputEvent>::iterator it = events.begin(); it != events.end(); it++){
const typename InputMap<X>::InputEvent & event = *it;
if (event.enabled){
handler.press(event.out, event.unicode);
} else {
handler.release(event.out, event.unicode);
}
}
}
template <typename X>
static bool pressed(InputMap<X> & input, const InputSource & source, X out){
if (manager){
return manager->_pressed(input, source, out);
}
return false;
}
/* wait for a key to be released
* really this waits for all inputs that would result in `out'
* being generated to stop.
*/
template <typename X>
static void waitForRelease(InputMap<X> & input, const InputSource & source, X out){
while (InputManager::pressed(input, source, out)){
Util::rest(1);
InputManager::poll();
}
}
template <typename X>
static void waitForPress(InputMap<X> & input, const InputSource & source, X out){
while (!InputManager::pressed(input, source, out)){
Util::rest(1);
InputManager::poll();
}
}
template <typename X>
static void captureInput(InputMap<X> & input){
manager->_captureInput(input);
}
template <typename X>
static void releaseInput(InputMap<X> & input){
manager->_releaseInput(input);
}
protected:
InputManager();
virtual ~InputManager();
virtual bool _anyInput();
virtual int _readKey();
// virtual std::vector<Input::PaintownInput> _getInput(const Configuration & configuration, const int facing);
template <typename X>
void _captureInput(InputMap<X> & input){
capture = (void*) &input;
}
template <typename X>
void _releaseInput(InputMap<X> & input){
if (capture == (void*) &input){
capture = 0;
}
}
template <typename X>
std::vector<Keyboard::unicode_t> _readText(InputMap<X> & input, typename InputMap<X>::Output & output){
std::vector<Keyboard::unicode_t> text;
std::vector<Keyboard::KeyData> all = keyboard.readData();
for (std::vector<Keyboard::KeyData>::iterator it = all.begin(); it != all.end(); it++){
const Keyboard::KeyData & data = *it;
KeyState<X> * state = input.getState(data.key);
if (state != NULL && output[state->out]){
text.push_back(data.unicode);
}
}
return text;
}
void removeDuplicates(std::vector<int> & storage){
std::vector<int> output;
int last = -1;
for (std::vector<int>::iterator it = storage.begin(); it != storage.end(); it++){
if (*it != last){
output.push_back(*it);
last = *it;
}
}
storage = output;
}
template <typename X>
typename std::vector<typename InputMap<X>::InputEvent> _getEvents(InputMap<X> & input, const InputSource & source){
/* FIXME: get events from the source */
std::vector<typename InputMap<X>::InputEvent> events;
if (capture != NULL && capture != &input){
return events;
}
if (source.useKeyboard()){
const std::vector<typename Keyboard::KeyData> & buffer = keyboard.getBufferedKeys();
for (std::vector<Keyboard::KeyData>::const_iterator it = buffer.begin(); it != buffer.end(); it++){
const Keyboard::KeyData & data = *it;
Util::ReferenceCount<KeyState<X> > state = input.getState(data.key);
if (state != NULL){
events.push_back(typename InputMap<X>::InputEvent(state->out, data.unicode, data.enabled));
}
}
}
for (std::vector<int>::const_iterator it = source.getJoystick().begin(); it != source.getJoystick().end(); it++){
int config = *it;
if (config >= 0 && config < (int) joysticks.size()){
Util::ReferenceCount<Joystick> joystick = joysticks[config];
if (joystick != NULL){
const std::vector<typename Joystick::Event> & joystickEvents = joystick->getEvents();
for (std::vector<Joystick::Event>::const_iterator it = joystickEvents.begin(); it != joystickEvents.end(); it++){
Joystick::Event event = *it;
Util::ReferenceCount<JoystickState<X> > state = input.getJoystickState(event.key);
if (state != NULL){
events.push_back(typename InputMap<X>::InputEvent(state->out, -1, event.enabled));
}
}
}
}
}
return events;
}
#if 0
template <typename X>
typename InputMap<X>::Output _getMap(InputMap<X> & input){
typename InputMap<X>::Output output;
if (capture != 0 && capture != &input){
return output;
}
std::vector<int> all_keys;
keyboard.readKeys(all_keys);
keyboard.readBufferedKeys(all_keys);
// all_keys.insert(all_keys.end(), bufferedKeys.begin(), bufferedKeys.end());
// all_keys.insert(all_keys.end(), keyboard.currentKeys().begin(), keyboard.currentKeys.end());
std::sort(all_keys.begin(), all_keys.end());
removeDuplicates(all_keys);
// std::unique(all_keys.begin(), all_keys.end());
// bufferedKeys.clear();
input.read(all_keys, &output);
/*
if (joystick != NULL){
JoystickInput all_joystick = joystick->readAll();
input.read(all_joystick, &output);
}
*/
/* just bumps an internal counter */
input.update();
return output;
}
#endif
template <typename X>
bool _pressed(InputMap<X> & input, const InputSource & source, X result){
/* FIXME: use the input source, luke */
if (capture != 0 && capture != &input){
return false;
}
std::vector<int> all_keys;
keyboard.readKeys(all_keys);
// all_keys.insert(all_keys.end(), bufferedKeys.begin(), bufferedKeys.end());
std::sort(all_keys.begin(), all_keys.end());
removeDuplicates(all_keys);
// bufferedKeys.clear();
bool out = false;
out = input.pressed(all_keys, result);
/*
if (joystick != NULL){
JoystickInput all_joystick = joystick->readAll();
out |= input.pressed(all_joystick, result);
}
*/
return out;
}
virtual void _poll();
protected:
void installJoysticks();
void checkJoysticks();
private:
static InputManager * manager;
void * capture;
std::map<int, Util::ReferenceCount<Joystick> > joysticks;
Keyboard keyboard;
Util::EventManager eventManager;
// std::vector<int> bufferedKeys;
// bool bufferKeys;
};
#endif
diff --git a/include/r-tech1/input/input-map.h b/include/r-tech1/input/input-map.h
index 27baec0a..0fca0adc 100644
--- a/include/r-tech1/input/input-map.h
+++ b/include/r-tech1/input/input-map.h
@@ -1,318 +1,318 @@
-#ifndef _rtech_input_map_h
-#define _rtech_input_map_h
+#ifndef _rtech1_input_map_h
+#define _rtech1_input_map_h
#include <map>
#include <vector>
#include "joystick.h"
#include "keyboard.h"
#include "r-tech1/pointer.h"
#include <iostream>
template <typename X>
struct KeyState{
KeyState(unsigned int delay, bool block, X out, unsigned int last_read):
delay(delay),
block(block),
out(out),
pressed(false),
last_read(0),
seen(0){
}
unsigned int delay;
bool block;
X out;
bool pressed;
unsigned int last_read;
unsigned int seen;
};
/* cant typedef a template'd struct so we have to copy/paste the definition
*/
template <typename X>
struct JoystickState{
JoystickState(unsigned int delay, bool block, X out, unsigned int last_read):
delay(delay),
block(block),
out(out),
pressed(false),
last_read(0),
seen(0){
}
unsigned int delay;
bool block;
X out;
bool pressed;
unsigned int last_read;
unsigned int seen;
};
/* maps a raw input device (keyboard, joystick, etc.) to some user-defined type
* the template parameter, X, is that user-defined type
*/
template <typename X>
class InputMap{
public:
typedef std::map<X, bool> Output;
struct InputEvent{
InputEvent(const X & out, Keyboard::unicode_t unicode, bool enabled):
out(out),
unicode(unicode),
enabled(enabled){
}
InputEvent(const InputEvent & input):
out(input.out),
unicode(input.unicode),
enabled(input.enabled){
}
InputEvent(){
}
bool operator[](const X & is) const {
return this->out == is;
}
X out;
Keyboard::unicode_t unicode;
bool enabled;
};
InputMap():
last_read(0){
}
InputMap(const InputMap & copy){
copyMap(copy);
}
InputMap & operator=(const InputMap & copy){
copyMap(copy);
return *this;
}
void copyMap(const InputMap & copy){
key_states.clear();
for (typename std::map<Keyboard::KeyType, Util::ReferenceCount<KeyState<X> > >::const_iterator it = copy.key_states.begin(); it != copy.key_states.end(); it++){
if (it->second != NULL){
key_states[(*it).first] = Util::ReferenceCount<KeyState<X> >(new KeyState<X>(*(*it).second));
}
}
joy_states.clear();
for (typename std::map<typename Joystick::Key, Util::ReferenceCount<JoystickState<X> > >::const_iterator it = copy.joy_states.begin(); it != copy.joy_states.end(); it++){
if (it->second != NULL){
joy_states[(*it).first] = Util::ReferenceCount<JoystickState<X> >(new JoystickState<X>(*(*it).second));
}
}
last_read = copy.last_read;
}
virtual ~InputMap(){
/* map will clear itself, reference count will delete all objects */
}
/* key: the keyboard key to recognize, something like KEY_A
* delay: time before successive keys are recognized (if held down)
* block: if true then the key must be released before it will
* be recognized again. false allows repetition.
* out: user defined value to set if this key is pressed
*/
void set(Keyboard::KeyType key, int delay, bool block, X out){
key_states[key] = Util::ReferenceCount<KeyState<X> >(new KeyState<X>(delay, block, out, last_read));
}
void set(Keyboard::KeyType key, X out){
set(key, 0, false, out);
}
/* change an existing key */
void update(Keyboard::KeyType key, int delay, bool block, X out){
if (key_states[key] != 0){
key_states[key]->delay = delay;
key_states[key]->block = block;
key_states[key]->out = out;
}
}
/* mostly the same stuff but for joysticks.
*/
void set(typename Joystick::Key key, int delay, bool block, X out){
joy_states[key] = Util::ReferenceCount<JoystickState<X> >(new JoystickState<X>(delay, block, out, last_read));
}
void set(typename Joystick::Key key, X out){
set(key, 0, false, out);
}
static std::vector<X> getAllPressed(const Output & output){
std::vector<X> out;
for (typename Output::const_iterator it = output.begin(); it != output.end(); it++){
if ((*it).second){
out.push_back((*it).first);
}
}
return out;
}
/*
static void observeKey(const Keyboard::KeyData & data, void * self){
InputMap<X> * me = (InputMap<X>*) self;
KeyState<X> * state = state = getState(data.key);
if (state != NULL){
events.push_back(InputEvent(state->out, data.unicode, data.enabled));
}
}
*/
bool pressed(const std::vector<int> & keys, X out){
for (std::vector<int>::const_iterator it = keys.begin(); it != keys.end(); it++){
Keyboard::KeyType key = *it;
Util::ReferenceCount<KeyState<X> > state = key_states[key];
if (state != NULL){
if (state->out == out){
return true;
}
}
}
return false;
}
virtual Util::ReferenceCount<KeyState<X> > getState(int key){
return key_states[key];
}
virtual Util::ReferenceCount<JoystickState<X> > getJoystickState(Joystick::Key key){
return joy_states[key];
}
void read(const std::vector<int> & keys, Output * output){
for (std::vector<int>::const_iterator it = keys.begin(); it != keys.end(); it++){
Keyboard::KeyType key = *it;
Util::ReferenceCount<KeyState<X> > state = getState(key);
if (state != NULL){
bool use = false;
// Global::debug(0) << "read " << key << " last read is " << state->last_read << " my last read is " << last_read << std::endl;
if (state->block){
if (last_read - state->last_read > 1){
use = true;
}
} else if (last_read - state->last_read > 1 || state->seen >= state->delay){
use = true;
state->seen = 0;
} else {
state->seen += 1;
}
state->last_read = last_read;
// state->last_read = last_read;
(*output)[state->out] = use;
}
}
}
const std::map<Keyboard::KeyType, Util::ReferenceCount<KeyState<X> > > & getKeyStates() const {
return key_states;
}
/* called by the input manager when the map is read */
void update(){
last_read += 1;
}
void read(const JoystickInput & joystick, Output * output){
#define do_joy(field, key) if (joystick.field){\
Util::ReferenceCount<JoystickState<X> > state = joy_states[Joystick::key];\
doJoyState(state, output);\
}
do_joy(down, Down);
do_joy(up, Up);
do_joy(left, Left);
do_joy(right, Right);
do_joy(button1, Button1);
do_joy(button2, Button2);
do_joy(button3, Button3);
do_joy(button4, Button4);
do_joy(button5, Button5);
do_joy(button6, Button6);
do_joy(quit, Quit);
do_joy(start, Start);
/*
if (joystick.up){
JoystickState<X> * state = joy_states[Joystick::Up];
doJoyState(state);
}
if (joystick.down){
JoystickState<X> * state = joy_states[Joystick::Down];
doJoyState(state);
}
*/
#undef do_joy
}
bool pressed(const JoystickInput & joystick, X out){
#define do_joy(field, key) if (joystick.field){\
Util::ReferenceCount<JoystickState<X> > state = joy_states[Joystick::key];\
if (state != 0 && state->out == out){\
return true;\
}\
}
do_joy(down, Down);
do_joy(up, Up);
do_joy(left, Left);
do_joy(right, Right);
do_joy(button1, Button1);
do_joy(button2, Button2);
do_joy(button3, Button3);
do_joy(button4, Button4);
do_joy(button5, Button5);
do_joy(button6, Button6);
do_joy(quit, Quit);
do_joy(start, Start);
#undef do_joy
return false;
}
protected:
void doJoyState(JoystickState<X> * state, Output * output){
if (state != NULL){
bool use = false;
if (state->block){
if (last_read - state->last_read > 1){
use = true;
}
} else if (last_read - state->last_read > 1 || state->seen >= state->delay){
use = true;
state->seen = 0;
} else {
state->seen += 1;
}
state->last_read = last_read;
// state->last_read = last_read;
(*output)[state->out] = use;
}
}
private:
std::map<Keyboard::KeyType, Util::ReferenceCount<KeyState<X> > > key_states;
std::map<typename Joystick::Key, Util::ReferenceCount<JoystickState<X> > > joy_states;
unsigned int last_read;
};
#endif
diff --git a/include/r-tech1/input/input-source.h b/include/r-tech1/input/input-source.h
index 2c5aaaf3..9c00e217 100644
--- a/include/r-tech1/input/input-source.h
+++ b/include/r-tech1/input/input-source.h
@@ -1,38 +1,38 @@
-#ifndef _rtech_input_source_h
-#define _rtech_input_source_h
+#ifndef _rtech1_input_source_h
+#define _rtech1_input_source_h
#include <vector>
/* this class should abstract over actual devices (keyboard, joystick)
* and return a list of events on request.
*/
class InputSource{
public:
InputSource(bool default_);
/* keyboard specifies the configuration to use.
* joystick specifies the configuration and which physical joystick to use.
*/
InputSource(const std::vector<int> & keyboard, const std::vector<int> & joystick);
InputSource(const InputSource & copy);
virtual ~InputSource();
/* Creates a copy of this input source with the keyboard/joystick added
* to the current list
*/
InputSource addKeyboard(int keyboard);
InputSource addJoystick(int joystick);
InputSource & operator=(const InputSource &);
virtual bool useKeyboard() const;
virtual const std::vector<int> & getKeyboard() const;
virtual bool useJoystick() const;
virtual const std::vector<int> & getJoystick() const;
private:
std::vector<int> keyboard;
std::vector<int> joystick;
};
#endif
diff --git a/include/r-tech1/input/input.h b/include/r-tech1/input/input.h
index 42b0fad3..51461937 100644
--- a/include/r-tech1/input/input.h
+++ b/include/r-tech1/input/input.h
@@ -1,32 +1,32 @@
-#ifndef _rtech_input_h
-#define _rtech_input_h
+#ifndef _rtech1_input_h
+#define _rtech1_input_h
#include <vector>
#include "joystick.h"
class Configuration;
class Input{
public:
/* don't change these numbers, but you can add to them */
enum PaintownInput{
Unknown = -1,
Forward = 0,
Back = 1,
Up = 2,
Down = 3,
Attack1 = 4,
Attack2 = 5,
Attack3 = 6,
Jump = 7,
Grab = 8,
Attack4 = 9,
Attack5 = 10,
Attack6 = 11,
};
/* TODO: remove this method.. useless now. */
// static std::vector<PaintownInput> convertKeyboard(const Configuration & configuration,int facing, const std::vector<int> & keys);
};
#endif
diff --git a/include/r-tech1/input/joystick.h b/include/r-tech1/input/joystick.h
index 5bdb3016..ac88ebdf 100644
--- a/include/r-tech1/input/joystick.h
+++ b/include/r-tech1/input/joystick.h
@@ -1,167 +1,167 @@
-#ifndef _rtech_joystick_h
-#define _rtech_joystick_h
+#ifndef _rtech1_joystick_h
+#define _rtech1_joystick_h
#include <vector>
#include <set>
#include <string>
#include <map>
struct JoystickInput{
JoystickInput():
left(false),
right(false),
up(false),
down(false),
button1(false),
button2(false),
button3(false),
button4(false),
button5(false),
button6(false),
quit(false),
start(false){
}
JoystickInput(const JoystickInput & copy):
left(copy.left),
right(copy.right),
up(copy.up),
down(copy.down),
button1(copy.button1),
button2(copy.button2),
button3(copy.button3),
button4(copy.button4),
button5(copy.button5),
button6(copy.button6),
quit(copy.quit),
start(copy.start){
}
/* true if something is pressed */
bool pressed(){
return left || right || up || down ||
button1 || button2 || button3 || button4 ||
button5 || button6 ||
quit || start;
}
bool left;
bool right;
bool up;
bool down;
bool button1;
bool button2;
bool button3;
bool button4;
bool button5;
bool button6;
bool quit;
bool start;
};
/* Callback for joystick actions like button presses, axis motions, etc.
*/
class Joystick;
class JoystickListener{
public:
JoystickListener();
virtual ~JoystickListener();
virtual void pressButton(Joystick * from, int button) = 0;
virtual void releaseButton(Joystick * from, int button) = 0;
virtual void axisMotion(Joystick * from, int stick, int axis, double motion) = 0;
virtual void hatMotion(Joystick * from, int motion) = 0;
};
class Joystick{
public:
virtual void poll() = 0;
// virtual JoystickInput readAll() = 0;
virtual bool pressed() const;
virtual ~Joystick();
virtual int getDeviceId() const = 0;
virtual void pressButton(int button);
virtual void releaseButton(int button);
virtual void axisMotion(int axis, int motion);
virtual void hatMotion(int motion);
virtual std::string getName() const = 0;
/* create the ith joystick */
static Joystick * create(int i);
static int numberOfJoysticks();
enum Key{
Invalid = -1,
Up = 0,
Down,
Left,
Right,
Button1,
Button2,
Button3,
Button4,
Button5,
Button6,
Quit,
Start
};
struct Event{
Event(Key key, bool enabled):
key(key), enabled(enabled){
}
Key key;
bool enabled;
};
virtual inline const std::vector<Event> & getEvents() const {
return events;
}
virtual void setCustomButton(int button, Key key);
virtual void setCustomAxis(Key key, int stick, int axis, double low, double high);
virtual Key getKey(int button) = 0;
virtual int getButton(Key key) = 0;
/* returns true if there is an axis motion for the requested key */
virtual bool getAxis(Key key, int & stick, int & axis, double & low, double & high) const;
virtual std::map<int, std::map<int, double> > getCurrentAxisValues() const = 0;
static const char * keyToName(Key key);
static void addListener(JoystickListener * listener);
static void removeListener(JoystickListener * listener);
protected:
void readCustomButtons();
void readCustomButton(Key key);
void readCustomAxis(Key key);
void readCustomAxes();
void eraseCustomButton(Key key);
static const std::set<JoystickListener*> & getListeners();
static std::set<JoystickListener*> listeners;
std::vector<Event> events;
std::map<int, Key> customButton;
struct Axis{
int stick;
int axis;
double low;
double high;
/* true if this axis was in range and should not output an event */
bool on;
};
std::map<Key, Axis> customAxis;
Joystick();
};
#endif
diff --git a/include/r-tech1/input/keyboard.h b/include/r-tech1/input/keyboard.h
index ba99d229..d582741b 100644
--- a/include/r-tech1/input/keyboard.h
+++ b/include/r-tech1/input/keyboard.h
@@ -1,297 +1,297 @@
-#ifndef _rtech_keyboard_h
-#define _rtech_keyboard_h
+#ifndef _rtech1_keyboard_h
+#define _rtech1_keyboard_h
#include <map>
#include <vector>
#include <set>
#include <stdint.h>
/* FIXME: use a namespace here. Input maybe? */
class KeyboardListener;
/* handles allegro key[] array better than keypressed()
* and readkey()
*/
class Keyboard{
private:
Keyboard();
public:
friend class InputManager;
typedef int KeyType;
typedef uint32_t unicode_t;
struct KeyData{
KeyData():
key(-1),
unicode(-1),
enabled(false){
}
KeyData(int key, unicode_t unicode, bool enabled):
key(key),
unicode(unicode),
enabled(enabled){
}
int key;
/* Converted to a unicode character in UTF-32 */
unicode_t unicode;
/* whether the key is being pressed */
bool enabled;
};
/*
typedef void (*ObserverCallback)(const KeyData & data, void * extra);
struct Observer{
Observer():
callback(NULL),
extra(NULL){
}
Observer(ObserverCallback callback, void * extra):
callback(callback),
extra(extra){
}
ObserverCallback callback;
void * extra;
};
*/
/* poll:
* Put the keys in Allegro's key[] array into our map of int -> bool
*/
void poll();
/* wait for all keys to be released */
void wait();
/* []:
* Extract a boolean value given a key number
*/
#if 0
inline bool operator[] ( const int i ){
/* if the key has been pressed for the first time return true */
if ( my_keys[ i ] < 0 ){
my_keys[ i ] = 1;
return true;
}
bool b = my_keys[ i ] > key_delay[ i ];
if ( b ){
my_keys[ i ] = 1;
}
return b;
}
#endif
/* keypressed:
* Returns true if a key is pressed
*/
bool keypressed();
/* readKeys:
* Store all pressed keys in a user supplied vector
*/
void readKeys(std::vector< int > & all_keys);
void readBufferedKeys(std::vector<int> & keys);
std::vector<KeyData> readData();
std::vector<unicode_t> readText();
// int readKey();
void clear();
/* sets the latest repeat state. popping the state restores the previous state */
static void pushRepeatState(bool enabled);
static void popRepeatState();
static bool getRepeatState();
/* true on systems that probably have a keyboard, like pc.
* false on ps3, wii, etc.
*/
static bool haveKeyboard();
void setDelay( const int key, const int delay );
void setAllDelay( const int delay );
inline const std::vector<KeyData> & getBufferedKeys() const {
return buffer;
}
static const char * keyToName( int key );
static bool isNumber( int key );
static bool isChar( int key );
static bool isAlpha( int key );
static const KeyType Key_A;
static const KeyType Key_B;
static const KeyType Key_C;
static const KeyType Key_D;
static const KeyType Key_E;
static const KeyType Key_F;
static const KeyType Key_G;
static const KeyType Key_H;
static const KeyType Key_I;
static const KeyType Key_J;
static const KeyType Key_K;
static const KeyType Key_L;
static const KeyType Key_M;
static const KeyType Key_N;
static const KeyType Key_O;
static const KeyType Key_P;
static const KeyType Key_Q;
static const KeyType Key_R;
static const KeyType Key_S;
static const KeyType Key_T;
static const KeyType Key_U;
static const KeyType Key_V;
static const KeyType Key_W;
static const KeyType Key_X;
static const KeyType Key_Y;
static const KeyType Key_Z;
static const KeyType Key_0;
static const KeyType Key_1;
static const KeyType Key_2;
static const KeyType Key_3;
static const KeyType Key_4;
static const KeyType Key_5;
static const KeyType Key_6;
static const KeyType Key_7;
static const KeyType Key_8;
static const KeyType Key_9;
static const KeyType Key_0_PAD;
static const KeyType Key_1_PAD;
static const KeyType Key_2_PAD;
static const KeyType Key_3_PAD;
static const KeyType Key_4_PAD;
static const KeyType Key_5_PAD;
static const KeyType Key_6_PAD;
static const KeyType Key_7_PAD;
static const KeyType Key_8_PAD;
static const KeyType Key_9_PAD;
static const KeyType Key_F1;
static const KeyType Key_F2;
static const KeyType Key_F3;
static const KeyType Key_F4;
static const KeyType Key_F5;
static const KeyType Key_F6;
static const KeyType Key_F7;
static const KeyType Key_F8;
static const KeyType Key_F9;
static const KeyType Key_F10;
static const KeyType Key_F11;
static const KeyType Key_F12;
static const KeyType Key_ESC;
static const KeyType Key_TILDE;
static const KeyType Key_MINUS;
static const KeyType Key_EQUALS;
static const KeyType Key_BACKSPACE;
static const KeyType Key_TAB;
static const KeyType Key_OPENBRACE;
static const KeyType Key_CLOSEBRACE;
static const KeyType Key_ENTER;
static const KeyType Key_COLON;
static const KeyType Key_QUOTE;
static const KeyType Key_BACKSLASH;
static const KeyType Key_BACKSLASH2;
static const KeyType Key_COMMA;
static const KeyType Key_STOP;
static const KeyType Key_SLASH;
static const KeyType Key_SPACE;
static const KeyType Key_INSERT;
static const KeyType Key_DEL;
static const KeyType Key_HOME;
static const KeyType Key_END;
static const KeyType Key_PGUP;
static const KeyType Key_PGDN;
static const KeyType Key_LEFT;
static const KeyType Key_RIGHT;
static const KeyType Key_UP;
static const KeyType Key_DOWN;
static const KeyType Key_SLASH_PAD;
static const KeyType Key_ASTERISK;
static const KeyType Key_MINUS_PAD;
static const KeyType Key_PLUS_PAD;
static const KeyType Key_DEL_PAD;
static const KeyType Key_ENTER_PAD;
static const KeyType Key_PRTSCR;
static const KeyType Key_PAUSE;
static const KeyType Key_ABNT_C1;
static const KeyType Key_YEN;
static const KeyType Key_KANA;
static const KeyType Key_CONVERT;
static const KeyType Key_NOCONVERT;
static const KeyType Key_AT;
static const KeyType Key_CIRCUMFLEX;
static const KeyType Key_COLON2;
static const KeyType Key_KANJI;
static const KeyType Key_EQUALS_PAD;
static const KeyType Key_BACKQUOTE;
static const KeyType Key_SEMICOLON;
static const KeyType Key_COMMAND;
/*
static KeyType Key_UNKNOWN1;
static KeyType Key_UNKNOWN2;
static KeyType Key_UNKNOWN3;
static KeyType Key_UNKNOWN4;
static KeyType Key_UNKNOWN5;
static KeyType Key_UNKNOWN6;
static KeyType Key_UNKNOWN7;
static KeyType Key_UNKNOWN8;
*/
static const KeyType Key_MODIFIERS;
static const KeyType Key_LSHIFT;
static const KeyType Key_RSHIFT;
static const KeyType Key_LCONTROL;
static const KeyType Key_RCONTROL;
static const KeyType Key_ALT;
static const KeyType Key_ALTGR;
static const KeyType Key_LWIN;
static const KeyType Key_RWIN;
static const KeyType Key_MENU;
static const KeyType Key_SCRLOCK;
static const KeyType Key_NUMLOCK;
static const KeyType Key_CAPSLOCK;
void press(KeyType key, unicode_t unicode);
void release(KeyType key);
/*
virtual void addObserver(ObserverCallback observer, void * extra);
virtual void removeObserver(ObserverCallback observer, void * extra);
*/
static void addListener(KeyboardListener * listener);
static void removeListener(KeyboardListener * listener);
const std::set<KeyboardListener*> & getListeners();
protected:
static void disableKeyRepeat();
static void enableKeyRepeat();
static std::set<KeyboardListener*> listeners;
// std::map<int,int> my_keys;
std::map<int,int> key_delay;
// std::vector<Observer> observers;
std::map<KeyType, KeyData> keyState;
std::vector<KeyData> buffer;
bool enableBuffer;
static std::vector<bool> repeatState;
};
class KeyboardListener{
public:
KeyboardListener();
virtual ~KeyboardListener();
virtual void press(Keyboard * from, Keyboard::KeyType key, Keyboard::unicode_t unicode) = 0;
virtual void release(Keyboard * from, Keyboard::KeyType key) = 0;
};
#endif
diff --git a/include/r-tech1/input/text-input.h b/include/r-tech1/input/text-input.h
index 4ba83df8..e633a71c 100644
--- a/include/r-tech1/input/text-input.h
+++ b/include/r-tech1/input/text-input.h
@@ -1,83 +1,83 @@
-#ifndef _rtech_text_input_h
-#define _rtech_text_input_h
+#ifndef _rtech1_text_input_h
+#define _rtech1_text_input_h
#include "input-map.h"
#include "joystick.h"
#include <sstream>
#include <string>
#include <map>
typedef void (*callback)(void * arg);
struct Callback{
Callback():
function(0),
data(0){
}
Callback(callback function, void * data):
function(function),
data(data){
}
callback function;
void * data;
};
class TextInput: public InputMap<unsigned char> {
public:
TextInput(const std::string & start = "");
/* returns true if the text was modified */
bool doInput();
void enable();
void disable();
void addHandle(int key, int delay, callback function, void * data);
void addBlockingHandle(int key, callback function, void * data);
void addBlockingJoystickHandle(Joystick::Key key, callback function, void * data);
inline void setBlockingKeys(){
blockingKeys = true;
}
std::string getText() const;
void setText(const std::string & text);
void clearInput();
// void clear();
bool isEnabled() const {
return enabled;
}
void backspace();
void deleteLastWord();
virtual Util::ReferenceCount<KeyState<unsigned char> > getState(int key){
Util::ReferenceCount<KeyState<unsigned char> > state = InputMap<unsigned char>::getState(key);
if (state == NULL){
if (blockingKeys){
set(key, 0, true, key);
} else {
set(key, 10, false, key);
}
state = InputMap<unsigned char>::getState(key);
}
return state;
}
virtual ~TextInput();
protected:
int nextHandle();
std::ostringstream text;
/* whether key repeat is on or off */
bool blockingKeys;
bool enabled;
std::map<int, Callback> callbacks;
int handle;
};
#endif
diff --git a/include/r-tech1/language-string.h b/include/r-tech1/language-string.h
index fc30fd03..e1b9d778 100644
--- a/include/r-tech1/language-string.h
+++ b/include/r-tech1/language-string.h
@@ -1,38 +1,38 @@
-#ifndef _rtech_language_string_h
-#define _rtech_language_string_h
+#ifndef _rtech1_language_string_h
+#define _rtech1_language_string_h
#include <string>
#include <map>
class LanguageString: public std::string {
public:
LanguageString();
LanguageString(const char * stuff);
LanguageString(const std::string & stuff);
LanguageString(const std::string & stuff, const std::string & language);
LanguageString(const LanguageString & language);
LanguageString & operator=(const LanguageString & obj);
static const std::string defaultLanguage(){
return "English";
}
const std::string currentLanguage() const;
/* add a new language translation */
void add(const std::string & stuff, const std::string & language);
/* adds with the default language */
void add(const std::string & stuff);
std::string get() const;
inline const std::map<std::string, std::string> & getLanguages() const {
return languages;
}
protected:
std::map<std::string, std::string> languages;
};
#endif
diff --git a/include/r-tech1/loading.h b/include/r-tech1/loading.h
index 22c70f01..c2aaee27 100644
--- a/include/r-tech1/loading.h
+++ b/include/r-tech1/loading.h
@@ -1,73 +1,76 @@
-#ifndef _rtech_loading_h
-#define _rtech_loading_h
+#ifndef _rtech1_loading_h
+#define _rtech1_loading_h
#include <string>
#include "thread.h"
#include "file-system.h"
namespace Graphics{
class Bitmap;
}
namespace Loader{
class Info{
public:
Info(const std::string & message, const Filesystem::AbsolutePath & background);
Info(const Info & info);
virtual ~Info();
virtual void setBackground(const Graphics::Bitmap * background);
virtual void setLoadingMessage(const std::string & str);
+ virtual void addAuthorInfo(const std::vector<std::string> &);
virtual void setPosition(int x, int y);
virtual const Graphics::Bitmap * getBackground() const;
virtual const std::string & loadingMessage() const;
+ virtual const std::vector<std::string> & authorInfo() const;
virtual const Filesystem::AbsolutePath & loadingBackground() const;
virtual int getPositionX() const;
virtual int getPositionY() const;
protected:
int x, y;
std::string _loadingMessage;
+ std::vector<std::string> _authorInfo;
const Graphics::Bitmap * background;
Filesystem::AbsolutePath _loadingBackground;
};
/* Kind of loader to show */
enum Kind{
Default,
SimpleCircle
};
class LoadingContext{
public:
LoadingContext();
virtual ~LoadingContext();
virtual void doLoad();
virtual void load() = 0;
virtual bool done();
static void * load_it(void * arg);
protected:
Util::Thread::Lock lock;
bool finished;
};
extern volatile bool done_loading;
// extern Util::Thread::Lock loading_screen_mutex;
/* deprecated, remove */
void startLoadingX(Util::Thread::Id * thread, void * arg = 0, Kind kind = Default);
void stopLoadingX(Util::Thread::Id thread);
void loadScreen(LoadingContext & context, const Info & info, Kind kind = Default);
void * loadingScreen(void *);
}
#endif
diff --git a/include/r-tech1/main.h b/include/r-tech1/main.h
index 20796e8b..e1826109 100644
--- a/include/r-tech1/main.h
+++ b/include/r-tech1/main.h
@@ -1,6 +1,6 @@
-#ifndef _rtech_main_h
-#define _rtech_main_h
+#ifndef _rtech1_main_h
+#define _rtech1_main_h
int rtech_main( int argc, char ** argv );
#endif
diff --git a/include/r-tech1/memory.h b/include/r-tech1/memory.h
index 7a9ee95c..6821ad1e 100644
--- a/include/r-tech1/memory.h
+++ b/include/r-tech1/memory.h
@@ -1,132 +1,132 @@
-#ifndef _rtech_3ac0ba2587944345f2241085269c24f8
-#define _rtech_3ac0ba2587944345f2241085269c24f8
+#ifndef _rtech1_3ac0ba2587944345f2241085269c24f8
+#define _rtech1_3ac0ba2587944345f2241085269c24f8
#ifdef USE_ALLEGRO
#include <allegro.h>
namespace Memory{
struct memory{
memory(unsigned char * stream, int length):
stream(stream),
position(stream),
length(length){
}
int getSize() const {
return position - stream;
}
/* points to the head */
unsigned char * stream;
/* points to the current position */
unsigned char * position;
int length;
};
static int pf_fclose(void *userdata){
return 0;
/* nothing */
}
static int pf_getc(void *userdata){
memory * m = (memory*) userdata;
if (m->position < m->stream + m->length){
unsigned char x = *m->position;
m->position += 1;
return x;
}
return EOF;
}
static int pf_ungetc(int c, void *userdata){
memory * m = (memory*) userdata;
if (m->position > m->stream){
m->position -= 1;
return c;
} else {
return EOF;
}
}
static long pf_fread(void *p, long n, void *userdata){
memory *m = (memory*) userdata;
unsigned char *cp = (unsigned char *)p;
long i;
int c;
for (i=0; i<n; i++) {
if ((c = pf_getc(m)) == EOF)
break;
*(cp++) = c;
}
return i;
}
static int pf_putc(int c, void *userdata){
memory * m = (memory*) userdata;
if (m->position < m->stream + m->length){
*m->position = c;
m->position += 1;
return c;
}
return EOF;
}
static long pf_fwrite(const void *p, long n, void *userdata){
memory *m = (memory*) userdata;
const unsigned char * cp = (const unsigned char *) p;
long i;
int c;
/* probably should replace this with memcpy */
for (i=0; i<n; i++) {
if ((c = pf_putc(cp[i], userdata)) == EOF)
break;
}
return i;
}
static int pf_fseek(void *userdata, int offset){
memory * m = (memory*) userdata;
if (offset >= 0 && m->position + offset < m->stream + m->length){
m->position += offset;
return 0;
} else {
return -1;
}
}
static int pf_feof(void *userdata){
memory * m = (memory*) userdata;
return m->position >= m->stream + m->length;
}
static int pf_ferror(void *userdata){
memory * m = (memory*) userdata;
return m->position < m->stream || m->position >= m->stream + m->length;
}
static PACKFILE_VTABLE makeTable(){
PACKFILE_VTABLE table;
table.pf_fclose = Memory::pf_fclose;
table.pf_getc = Memory::pf_getc;
table.pf_ungetc = Memory::pf_ungetc;
table.pf_fread = Memory::pf_fread;
table.pf_putc = Memory::pf_putc;
table.pf_fwrite = Memory::pf_fwrite;
table.pf_fseek = Memory::pf_fseek;
table.pf_feof = Memory::pf_feof;
table.pf_ferror = Memory::pf_ferror;
return table;
}
}
#endif
#endif
diff --git a/include/r-tech1/menu/action_speed.h b/include/r-tech1/menu/action_speed.h
index 108c2c5e..d7df6d65 100644
--- a/include/r-tech1/menu/action_speed.h
+++ b/include/r-tech1/menu/action_speed.h
@@ -1,18 +1,18 @@
-#ifndef _rtech_action_speed_h
-#define _rtech_action_speed_h
+#ifndef _rtech1_action_speed_h
+#define _rtech1_action_speed_h
class Token;
class ActionSpeed{
public:
// Do whatever is needed for the requested item
virtual void act();
ActionSpeed(const Token *token);
virtual ~ActionSpeed();
private:
// speed
double speed;
};
#endif
diff --git a/include/r-tech1/menu/actionfactory.h b/include/r-tech1/menu/actionfactory.h
index ff5dcae2..f16b6bea 100644
--- a/include/r-tech1/menu/actionfactory.h
+++ b/include/r-tech1/menu/actionfactory.h
@@ -1,9 +1,9 @@
-#ifndef _rtech_actionfactory_h
-#define _rtech_actionfactory_h
+#ifndef _rtech1_actionfactory_h
+#define _rtech1_actionfactory_h
class Token;
void ActionAct(Token *token);
#endif
diff --git a/include/r-tech1/menu/font-info.h b/include/r-tech1/menu/font-info.h
index c16274df..3fdb97d7 100644
--- a/include/r-tech1/menu/font-info.h
+++ b/include/r-tech1/menu/font-info.h
@@ -1,170 +1,170 @@
-#ifndef _rtech_font_info_h
-#define _rtech_font_info_h
+#ifndef _rtech1_font_info_h
+#define _rtech1_font_info_h
#include <string>
#include "r-tech1/file-system.h"
#include "r-tech1/font.h"
class Font;
namespace Menu{
/*
* class FontInfo
* class RelativeFontInfo
* class AbsoluteFontInfo
*/
class AbsoluteFontInfo;
class RelativeFontInfo;
class FontInfo {
public:
FontInfo();
virtual ~FontInfo();
/*
inline void set(const Filesystem::RelativePath & font, int width, int height){
this->font = font;
this->width = width;
this->height = height;
}
*/
virtual const Font & get() const = 0;
virtual const Font & get(const Font & next) const = 0;
virtual const FontInfo & get(const FontInfo & next) const = 0;
virtual bool operator==(const FontInfo & who) const = 0;
virtual bool operator==(const AbsoluteFontInfo & who) const = 0;
virtual bool operator==(const RelativeFontInfo & who) const = 0;
/*
inline void setFont(const Filesystem::RelativePath & font){
this->font = font;
}
*/
virtual std::string getName() const = 0;
// virtual const Filesystem::RelativePath getFont(const FontInfo & next) const;
/*
inline void setWidth(int width){
this->width = width;
}
*/
virtual const int getWidth(const FontInfo & next) const = 0;
/*
inline void setHeight(int height){
this->height = height;
}
*/
virtual const int getHeight(const FontInfo & next) const = 0;
virtual const bool empty() const = 0;
};
template <class Type>
class PathFontInfo: public FontInfo {
public:
PathFontInfo(const Type & path, int width, int height):
path(path),
width(width),
height(height){
}
virtual const Font & get() const {
return Font::getFont(path, width, height);
}
virtual const Font & get(const Font & next) const {
return get();
}
virtual const FontInfo & get(const FontInfo & next) const {
return *this;
}
virtual std::string getName() const {
return path.getFilename().path();
}
virtual const int getWidth(const FontInfo & next) const {
return width;
}
virtual const int getHeight(const FontInfo & next) const {
return height;
}
virtual const bool empty() const {
return path.path().empty();
}
protected:
Type path;
int width;
int height;
};
class RelativeFontInfo: public PathFontInfo<Filesystem::RelativePath> {
public:
RelativeFontInfo(const Filesystem::RelativePath & path, int width, int height):
PathFontInfo<Filesystem::RelativePath>(path, width, height){
}
using FontInfo::operator==;
virtual bool operator==(const FontInfo & who) const;
virtual bool operator==(const AbsoluteFontInfo & who) const;
virtual bool operator==(const RelativeFontInfo & who) const;
};
class AbsoluteFontInfo: public PathFontInfo<Filesystem::AbsolutePath> {
public:
AbsoluteFontInfo(const Filesystem::AbsolutePath & path, int width, int height):
PathFontInfo<Filesystem::AbsolutePath>(path, width, height){
}
using FontInfo::operator==;
virtual bool operator==(const FontInfo & who) const;
virtual bool operator==(const AbsoluteFontInfo & who) const;
virtual bool operator==(const RelativeFontInfo & who) const;
};
/*
class RelativeFontInfo: public FontInfo {
public:
RelativeFontInfo();
RelativeFontInfo(const Filesystem::RelativePath & font, int width, int height);
virtual const bool empty() const;
private:
Filesystem::RelativePath font;
int width;
int height;
};
class AbsoluteFontInfo: public FontInfo {
public:
AbsoluteFontInfo(const Filesystem::AbsolutePath & font, int width, int height);
using FontInfo::get;
virtual const Font & get() const;
virtual const Font & get(const Font & next) const;
virtual std::string getName() const;
protected:
Filesystem::AbsolutePath font;
int width;
int height;
};
*/
}
#endif
diff --git a/include/r-tech1/menu/menu-exception.h b/include/r-tech1/menu/menu-exception.h
index cd79ea05..b2eb54ba 100644
--- a/include/r-tech1/menu/menu-exception.h
+++ b/include/r-tech1/menu/menu-exception.h
@@ -1,14 +1,14 @@
-#ifndef _rtech_menu_reload_exception_h
-#define _rtech_menu_reload_exception_h
+#ifndef _rtech1_menu_reload_exception_h
+#define _rtech1_menu_reload_exception_h
#include <exception>
/* This exception is thrown when a Mod is picked or changed */
class ReloadMenuException: public std::exception {
public:
ReloadMenuException():exception(){}
virtual ~ReloadMenuException() throw(){}
};
#endif
diff --git a/include/r-tech1/menu/menu.h b/include/r-tech1/menu/menu.h
index 870a3e74..80b43810 100644
--- a/include/r-tech1/menu/menu.h
+++ b/include/r-tech1/menu/menu.h
@@ -1,575 +1,575 @@
-#ifndef _rtech_Menu_h
-#define _rtech_Menu_h
+#ifndef _rtech1_Menu_h
+#define _rtech1_Menu_h
#include <vector>
#include <string>
#include <map>
#include "r-tech1/file-system.h"
#include "r-tech1/pointer.h"
#include "r-tech1/parameter.h"
#include "r-tech1/input/input-map.h"
#include "r-tech1/graphics/gradient.h"
#include "r-tech1/menu/font-info.h"
#include "r-tech1/gui/animation.h"
#include "r-tech1/gui/box.h"
#include "r-tech1/gui/context-box.h"
#include "r-tech1/gui/fadetool.h"
#include "r-tech1/gui/popup-box.h"
#include "r-tech1/gui/tabbed-box.h"
#include "r-tech1/gui/widget.h"
#include "r-tech1/gui/coordinate.h"
#ifdef _MSC_VER
#ifndef uint32_t
typedef unsigned __int32 uint32_t;
#endif
#endif
class Font;
namespace Graphics{
class Bitmap;
}
class MenuOption;
class Token;
class TokenView;
namespace Menu{
extern Util::Parameter<Util::ReferenceCount<FontInfo> > menuFontParameter;
Effects::Gradient standardGradient();
class OptionFactory;
class Point{
public:
int x;
int y;
Point();
Point(int x, int y);
~Point();
};
class InfoBox: public Gui::Widget {
public:
InfoBox();
~InfoBox();
void act(const Font &);
virtual void render(const Graphics::Bitmap &);
void render(const Graphics::Bitmap &, const Font & font);
void open();
void close();
void setText(const std::string &);
inline bool isActive(){
return (this->state != NotActive);
}
/*
inline void setFont(const Util::ReferenceCount<FontInfo> & font){
this->font = font;
}
*/
virtual void initialize(const Font & font);
private:
enum State{
NotActive,
Opening,
Active,
Closing,
};
State state;
Gui::PopupBox popup;
// Util::ReferenceCount<FontInfo> font;
int fadeAlpha;
std::vector<std::string> text;
std::vector<int> padding;
};
class MenuException : public Exception::Base{
public:
MenuException(const std::string & file, int line, const std::string reason = "");
MenuException(const MenuException & copy);
MenuException(const Exception::Base & copy);
virtual ~MenuException() throw();
protected:
std::string reason;
virtual inline const std::string getReason() const {
return reason;
}
virtual Exception::Base * copy() const;
};
/* reload the current menu, usually thrown by some option */
class Reload: public MenuException {
public:
Reload(const std::string & file, int line, const std::string reason = "");
virtual ~Reload() throw();
protected:
virtual Exception::Base * copy() const;
};
class ValueHolder{
public:
ValueHolder(const std::string &);
ValueHolder(const ValueHolder &);
virtual ~ValueHolder();
virtual ValueHolder & operator=(const ValueHolder &);
virtual ValueHolder & operator<<(const std::string &);
virtual ValueHolder & operator<<(bool val);
virtual ValueHolder & operator<<(int val);
virtual ValueHolder & operator<<(double val);
virtual ValueHolder & operator<<(TokenView &);
virtual ValueHolder & operator>>(std::string &);
virtual ValueHolder & operator>>(bool &);
virtual ValueHolder & operator>>(int &);
virtual ValueHolder & operator>>(double &);
virtual inline const std::string & getName() const {
return this->name;
}
virtual const std::string getValues();
private:
std::string name;
std::vector<std::string> values;
unsigned int location;
void next();
};
/*! Menu actions */
enum Actions{
Up,
Down,
Left,
Right,
Select,
Back,
Cancel,
Modify,
Pause,
PlayAsteroids /* Hack for now, remove later */
};
class Context;
/*! Menu Renderer
* Allows menu to modify the way it displays it's contents
* ie regular menus, tab menus, specialized menu etc
*/
class Renderer{
public:
Renderer();
virtual ~Renderer();
enum Type{
Default,
Tabbed
};
//! Reader
virtual bool readToken(const Token *, const OptionFactory &)=0;
virtual Type getType() const = 0;
virtual void initialize(Context &)=0;
virtual void finish()=0;
virtual bool active()=0;
virtual void act(const Context &)=0;
virtual void render(const Graphics::Bitmap &, const Font & font)=0;
// Set font if applicable
// virtual void setFont(const Util::ReferenceCount<FontInfo> &);
//! Compatibility for now, remove later
virtual void addOption(MenuOption *)=0;
virtual std::vector<Util::ReferenceCount<MenuOption> > getOptions() const = 0;
/*! Handle action, with access to context
*/
virtual void doAction(const Actions &, Context &)=0;
/*! Invoke override */
virtual void invokeOverride(const Context &)=0;
virtual void setPosition(const Gui::Coordinate & coordinate) = 0;
protected:
/*! Info boxes */
std::vector <InfoBox *> info;
/*! Menu info box */
InfoBox menuInfo;
/*! Add info box */
virtual void addInfo(const std::string &, const Gui::Widget &, Context &, const Font &);
/*! act info box */
virtual void actInfo(const Font &);
/*! render info box */
virtual void renderInfo(const Graphics::Bitmap &, const Font & font);
};
/*! Regular Menu */
class DefaultRenderer: public Renderer {
public:
DefaultRenderer();
virtual ~DefaultRenderer();
// virtual void setFont(const Util::ReferenceCount<FontInfo> &);
virtual bool readToken(const Token *, const OptionFactory &);
virtual void initialize(Context &);
virtual void finish();
virtual bool active();
virtual void act(const Context &);
virtual void render(const Graphics::Bitmap &, const Font &);
virtual void addOption(MenuOption *);
virtual void doAction(const Actions &, Context &);
virtual std::vector<Util::ReferenceCount<MenuOption> > getOptions() const;
virtual void invokeOverride(const Context &);
virtual void setPosition(const Gui::Coordinate & coordinate);
virtual Type getType() const;
virtual const Gui::ContextBox & getBox() const {
return menu;
}
virtual Gui::ContextBox & getBox(){
return menu;
}
private:
/*! Options */
std::vector<Util::ReferenceCount<MenuOption> > options;
/*! Context Box */
Gui::ContextBox menu;
/*! Override */
bool hasOverride;
/*! Override index */
unsigned int overrideIndex;
};
/*! Tabbed Menu */
class TabInfo {
public:
TabInfo();
~TabInfo();
std::string name;
std::string info;
std::string menuInfo;
void act();
/*! Options */
std::vector<Util::ReferenceCount<MenuOption> > options;
};
class TabRenderer: public Renderer {
public:
TabRenderer();
virtual ~TabRenderer();
// virtual void setFont(const Util::ReferenceCount<FontInfo> &);
virtual bool readToken(const Token *, const OptionFactory &);
virtual void initialize(Context &);
virtual void finish();
virtual bool active();
virtual void act(const Context &);
virtual void render(const Graphics::Bitmap &, const Font &);
virtual void addOption(MenuOption *);
virtual void doAction(const Actions &, Context &);
virtual std::vector<Util::ReferenceCount<MenuOption> > getOptions() const;
virtual void invokeOverride(const Context &);
virtual void setPosition(const Gui::Coordinate & coordinate);
virtual Type getType() const;
virtual Gui::TabbedBox & getBox(){
return menu;
}
private:
/*! Tabs */
std::vector<TabInfo *> tabs;
/*! Tabbed Box */
Gui::TabbedBox menu;
/*! Override */
bool hasOverride;
/*! Override index */
unsigned int overrideIndex;
};
/*! Menu contexts
- Each menu has a context which it defaults to
- Sub menus will be passed the parents context when run
- Fader
- Backgrounds (No background will fall back onto a fill screen)
- Menu (options, ContextBox, etc)
- Contexts are settable to omit drawing certain items (usefull for things like in-game menus)
*/
class Context{
public:
Context();
Context(const Context &, const Context &);
virtual ~Context();
virtual void act();
/*! Pass the widget (Menu ContextBox in this case) to be drawn
* Allows for custom widget menus to be draw in place (ie for tabs or something)
*/
virtual void render(const Util::ReferenceCount<Renderer> &, const Graphics::Bitmap &) const;
virtual void renderBackground(const Graphics::Bitmap & bmp) const;
virtual void renderForeground(const Graphics::Bitmap & bmp) const;
/*! Parse data */
virtual void parseToken(const Token *);
//! Compatibility stuff
virtual void addBackground(const Token *);
virtual void addBackground(const std::string &);
virtual void addBackground(const Graphics::Bitmap & image);
virtual void addBackground(const Util::ReferenceCount<Gui::Animation> & animation);
/*! Initializes things like faders */
virtual void initialize();
/*! Closes things out like faders */
virtual void finish();
/*! Play sound */
virtual void playSound(const Actions &) const;
/*! Add sound */
virtual void addSound(const Actions &, const Filesystem::RelativePath &);
/*! Play music */
virtual void playMusic();
/*! set music */
virtual inline void setMusic(const Filesystem::RelativePath & music){
this->music = music;
}
/*! Current state */
enum State{
NotStarted,
Initializing,
Running,
Finishing,
Completed,
};
inline const State & getState() const {
return this->state;
}
virtual void setFadeTool(Gui::FadeTool *);
virtual inline Gui::FadeTool * getFadeTool(){
return this->fades;
}
/*
virtual void setBackground(Util::ReferenceCount<Gui::AnimationManager> background);
virtual inline Util::ReferenceCount<Gui::AnimationManager> getBackground(){
return this->background;
}
*/
virtual inline void setFont(const Util::ReferenceCount<FontInfo> & font){
this->font = font;
}
virtual bool hasFont() const;
virtual inline const Util::ReferenceCount<FontInfo> & getFont() const {
return this->font;
}
virtual inline const Util::ReferenceCount<FontInfo> & getFontInfo() const {
return this->font;
}
virtual inline void setInfoLocation(double x, double y){
this->infoLocation.set(x,y);
}
virtual inline const Gui::RelativePoint & getInfoLocation() const {
return this->infoLocation;
}
virtual inline void setMenuInfoLocation(double x, double y){
this->menuInfoLocation.set(x,y);
}
virtual inline const Gui::RelativePoint & getMenuInfoLocation() const {
return this->menuInfoLocation;
}
virtual inline void setMenuInfoText(const std::string & text){
this->menuInfo = text;
}
virtual inline const std::string & getMenuInfoText() const {
return this->menuInfo;
}
virtual std::vector<std::string> getLanguages() const;
virtual void setLanguages(const std::vector<std::string> & languages);
private:
/*! Require cleanup *default constructor only* */
bool cleanup;
/*! Current state */
State state;
/*! Fade Tool */
Gui::FadeTool * fades;
/*! Backgrounds */
Gui::AnimationManager background;
/*! Sounds */
std::map<Actions, Filesystem::RelativePath> sounds;
/*! Music */
Filesystem::RelativePath music;
/*! Font */
Util::ReferenceCount<FontInfo> font;
/*! Info Placement */
Gui::RelativePoint infoLocation;
/*! Menu Info Placement */
Gui::RelativePoint menuInfoLocation;
/*! Menu Info Text */
std::string menuInfo;
std::vector<std::string> languages;
};
/*! New Menu class */
class Menu{
public:
/* These two are basically the same but the Type version will create the renderer for you */
Menu(const Renderer::Type & type = Renderer::Default);
Menu(const Util::ReferenceCount<Renderer> & renderer);
Menu(const Filesystem::AbsolutePath &, const Renderer::Type & type = Renderer::Default);
Menu(const Filesystem::AbsolutePath &, const OptionFactory & factory, const Renderer::Type & type = Renderer::Default);
Menu(const Token *, const Renderer::Type & type = Renderer::Default);
Menu(const Token * token, const OptionFactory & factory, const Renderer::Type & type = Renderer::Default);
virtual ~Menu();
/*! Run Menu pass parent context */
virtual void run(const Context &);
/* Set position of the menu */
virtual void setPosition(const Gui::Coordinate & coordinate);
/*! Logic pass local context */
virtual void act(Context &);
/*! render pass local context and work */
virtual void render(const Context &, const Graphics::Bitmap &) const;
virtual void setRenderer(const Renderer::Type &);
virtual void setRenderer(const Util::ReferenceCount<Renderer> & renderer);
/* a list of languages (translations) supported by this menu */
virtual std::vector<std::string> getLanguages() const;
/*! Get Name */
virtual std::string getName();
virtual std::string getInfo();
virtual void setFont(const Util::ReferenceCount<FontInfo> &);
/*! Add option */
virtual void addOption(MenuOption * opt);
virtual inline Util::ReferenceCount<Renderer> getRenderer() const {
return renderer;
}
static const int Width = 640;
static const int Height = 480;
protected:
void setupDefaultLanguage(const Context & context, const Menu & parent);
virtual void openOptions();
virtual void closeOptions();
/*! Context */
Context context;
/*! Data holder */
std::map<std::string, ValueHolder *> data;
/*! Renderer */
Util::ReferenceCount<Renderer> renderer;
/*! load token */
void load(const Token * token, const OptionFactory & factory);
#if 0
/*! Handle Override
* There can only be one decleration of an override per file/token
* The first one found will be the one executed.
* If found it will return true so that the menu can handle it and avoid going to everything else
*/
virtual bool handleOverride(const Token *);
#endif
/*! Do current version */
virtual void handleCurrentVersion(const Token *);
/*! Prior token compatibility based on version Global::getVersion() */
virtual void handleCompatibility(const Token *, int version, const OptionFactory & factory);
/*! Add Data */
void addData(ValueHolder *);
/*! Keys */
InputMap<Actions> input;
/*! Type */
Renderer::Type type;
/*! Check type */
virtual Util::ReferenceCount<Renderer> rendererType(const Renderer::Type &);
std::vector<std::string> languages;
};
}
#endif
diff --git a/include/r-tech1/menu/menu_action.h b/include/r-tech1/menu/menu_action.h
index f112bda3..6cac750c 100644
--- a/include/r-tech1/menu/menu_action.h
+++ b/include/r-tech1/menu/menu_action.h
@@ -1,18 +1,18 @@
-#ifndef _rtech_menu_action_h
-#define _rtech_menu_action_h
+#ifndef _rtech1_menu_action_h
+#define _rtech1_menu_action_h
class MenuAction
{
public:
// Do whatever is needed for the requested item
virtual void act()=0;
MenuAction();
virtual ~MenuAction();
private:
// Nothing
};
#endif
diff --git a/include/r-tech1/menu/menu_option.h b/include/r-tech1/menu/menu_option.h
index 4b69e0ca..a98850db 100644
--- a/include/r-tech1/menu/menu_option.h
+++ b/include/r-tech1/menu/menu_option.h
@@ -1,98 +1,98 @@
-#ifndef _rtech_menu_option_h
-#define _rtech_menu_option_h
+#ifndef _rtech1_menu_option_h
+#define _rtech1_menu_option_h
#include <string>
#include <vector>
#include "r-tech1/gui/box.h"
#include "r-tech1/language-string.h"
#include "r-tech1/gui/context-box.h"
#include "r-tech1/gui/scroll-list.h"
class Bitmap;
class Token;
namespace Menu {
class Context;
}
class MenuOption: public Gui::ContextItem {
public:
/* called when the menu containing this option is displayed to the user.
* default behavior is to do nothing.
*/
virtual void open();
/* called when the menu containing this option returns.
* default behavior is to do nothing.
*/
virtual void close();
/* Logic is executed every tick by the menu so you can do cool effects.
*/
virtual void logic() = 0;
/* Run is executed when the user selects this option */
// Finally it has been selected, this is what shall run
// endGame will be set true if it is a terminating option
virtual void run(const Menu::Context &) = 0;
// This is to pass paramaters to an option ie a bar or something
// return true to pause key input
virtual bool leftKey();
virtual bool rightKey();
enum state{
Selected = 0,
Deselected,
Run
};
enum OptionType{
Event = 0,
Option,
AdjustableOption
};
MenuOption(const Gui::ContextBox & parent, const Token *token);
/*
template <typename T>
Util::ReferenceCount<Gui::ScrollItem> getAsScrollItem(const Gui::ContextBox & parent){
Util::ReferenceCount<T> item = new T(this->getName(), parent);
return item.template convert<Gui::ScrollItem>();
}
*/
virtual ~MenuOption();
protected:
private:
state currentState;
OptionType mType;
LanguageString text;
LanguageString infoText;
bool runnable;
public:
inline void setState(const state s) { currentState = s; }
inline state getState() const { return currentState; }
inline void setType(const OptionType t) { mType = t; }
inline OptionType getType() const { return mType; }
inline void setInfoText(const LanguageString &t) { infoText = t; }
inline std::string getInfoText(){ return infoText.get(); }
inline void setRunnable(const bool r) { runnable = r; }
inline bool isRunnable() const { return runnable; }
public:
const std::string getName() const;
void addInfo(const Token *);
void addName(const Token *);
protected:
void readName(const Token * token, const std::string & matchType = "_/name");
void readInfo(const Token * token);
};
#endif
diff --git a/include/r-tech1/menu/optionfactory.h b/include/r-tech1/menu/optionfactory.h
index aec7f8a1..8304ea39 100644
--- a/include/r-tech1/menu/optionfactory.h
+++ b/include/r-tech1/menu/optionfactory.h
@@ -1,22 +1,22 @@
-#ifndef _rtech_optionfactory_h
-#define _rtech_optionfactory_h
+#ifndef _rtech1_optionfactory_h
+#define _rtech1_optionfactory_h
class MenuOption;
class Token;
namespace Gui{
class ContextBox;
}
namespace Menu{
class OptionFactory{
public:
OptionFactory();
virtual MenuOption * getOption(const Gui::ContextBox & parent, const Token *token) const;
virtual ~OptionFactory();
};
}
#endif
diff --git a/include/r-tech1/menu/options.h b/include/r-tech1/menu/options.h
index f397d03e..df74fc1b 100644
--- a/include/r-tech1/menu/options.h
+++ b/include/r-tech1/menu/options.h
@@ -1,557 +1,557 @@
-#ifndef _rtech_options_h
-#define _rtech_options_h
+#ifndef _rtech1_options_h
+#define _rtech1_options_h
#include "r-tech1/menu/menu_option.h"
#include "r-tech1/gui/animation.h"
#include "r-tech1/input/input-map.h"
#include "r-tech1/file-system.h"
#include "r-tech1/pointer.h"
#include "r-tech1/menu/font-info.h"
class Token;
namespace Menu{
class OptionFactory;
}
/*! Handles key reconfiguration */
class OptionCredits: public MenuOption {
public:
enum CreditKey{
Exit
};
class Block{
public:
Block(const std::string &);
Block(const Token *);
Block(const Block &);
~Block();
const Block & operator=(const Block &);
void addCredit(const std::string &);
void act();
enum Justification{
Left,
Center,
Right,
};
int print(int x, int y, Graphics::Color defaultTitleColor, Graphics::Color defaultColor, const Font &, const Graphics::Bitmap &, const Justification &) const;
const int size(const Font &) const;
inline const bool empty() const {
return title.empty() && credits.empty();
}
protected:
std::string title;
std::vector<std::string> credits;
bool titleColorOverride;
Graphics::Color titleColor;
bool colorOverride;
Graphics::Color color;
// Before title
Util::ReferenceCount<Gui::Animation> topAnimation;
int topWidth, topHeight;
// After last credit
Util::ReferenceCount<Gui::Animation> bottomAnimation;
int bottomWidth, bottomHeight;
// Spacing at bottom
int spacing;
};
class Sequence {
public:
Sequence(const Token *);
Sequence(const Sequence &);
~Sequence();
const Sequence & operator=(const Sequence &);
void act();
void draw(Graphics::Color title, Graphics::Color color, const Graphics::Bitmap &);
void reset();
enum Type{
Primary,
Roll,
};
inline const bool isDone() const {
return this->done;
}
protected:
// Next for primary
void next();
Type type;
double x;
double y;
int startx;
int endx;
int starty;
int endy;
// Only used if both x's or y's are == to each other
int ticks;
int duration;
double speed;
int alpha;
double alphaMultiplier;
Block::Justification justification;
std::vector<Block> credits;
unsigned int current;
bool done;
int creditLength;
};
// Do logic before run part
virtual void logic();
// Finally it has been selected, this is what shall run
// endGame will be set true if it is a terminating option
virtual void run(const Menu::Context &);
OptionCredits(const Gui::ContextBox & parent, const Token *token);
virtual ~OptionCredits();
private:
Util::ReferenceCount<Menu::Context> creditsContext;
std::vector<Sequence> sequences;
std::string music;
Graphics::Color color, title;
InputMap<CreditKey> input;
// Clear background (default black)
Graphics::Color clearColor;
};
/*! Dummy option, to allow place fillers in menus */
class OptionDummy: public MenuOption{
public:
OptionDummy(const Gui::ContextBox & parent, const Token *token);
OptionDummy(const Gui::ContextBox & parent, const std::string &name);
// Do logic before run part
virtual void logic();
// Finally it has been selected, this is what shall run
// endGame will be set true if it is a terminating option
virtual void run(const Menu::Context &);
virtual ~OptionDummy();
};
/*! Handles key reconfiguration */
class OptionFullscreen: public MenuOption{
public:
// Do logic before run part
virtual void logic();
// Finally it has been selected, this is what shall run
// endGame will be set true if it is a terminating option
virtual void run(const Menu::Context &);
virtual std::string getText() const;
// This is to pass paramaters to an option ie a bar or something
virtual bool leftKey();
virtual bool rightKey();
OptionFullscreen(const Gui::ContextBox & parent, const Token *token);
virtual ~OptionFullscreen();
private:
int lblue, lgreen;
int rblue, rgreen;
};
/*! Handles joystick reconfiguration */
/*
class OptionJoystick: public MenuOption {
public:
// Do logic before run part
virtual void logic();
// Finally it has been selected, this is what shall run
// endGame will be set true if it is a terminating option
virtual void run(const Menu::Context &);
OptionJoystick(const Gui::ContextBox & parent, const Token *token);
virtual ~OptionJoystick();
//! keys
enum JoystickType{
Up = 0,
Down,
Left,
Right,
Jump,
Attack1,
Attack2,
Attack3,
Attack4,
Attack5,
Attack6,
Invalidkey
};
private:
//! name
std::string name;
int player;
JoystickType type;
int keyCode;
};
*/
/*! Handles key reconfiguration */
class OptionKey: public MenuOption{
public:
// Do logic before run part
virtual void logic();
// Finally it has been selected, this is what shall run
// endGame will be set true if it is a terminating option
virtual void run(const Menu::Context &);
OptionKey(const Gui::ContextBox & parent, const Token *token);
virtual ~OptionKey();
//! keys
enum keyType
{
up=0,
down,
left,
right,
jump,
attack1,
attack2,
attack3,
attack4,
attack5,
attack6,
invalidkey
};
private:
//! name
std::string name;
int player;
keyType type;
int keyCode;
};
/*! Handles key reconfiguration */
class OptionLevel: public MenuOption {
public:
OptionLevel(const Gui::ContextBox & parent, const Token *token, int * set, int value);
// Do logic before run part
virtual void logic();
// Finally it has been selected, this is what shall run
// endGame will be set true if it is a terminating option
virtual void run(const Menu::Context &);
virtual ~OptionLevel();
protected:
/* integer to set if this option is chosen */
int * set;
int value;
};
namespace Menu {
class Menu;
class Context;
}
/*! Handles sub menus */
class OptionMenu: public MenuOption {
public:
// Do logic before run part
virtual void logic();
// Finally it has been selected, this is what shall run
// endGame will be set true if it is a terminating option
virtual void run(const Menu::Context &);
OptionMenu(const Gui::ContextBox & parent, const Token *token, const Menu::OptionFactory & factory);
virtual ~OptionMenu();
private:
//Menu *menu;
Menu::Menu *menu;
};
class OptionQuit : public MenuOption {
public:
OptionQuit(const Gui::ContextBox & parent, const Token *token);
OptionQuit(const Gui::ContextBox & parent, const std::string &name);
// Do logic before run part
virtual void logic();
// Finally it has been selected, this is what shall run
// endGame will be set true if it is a terminating option
virtual void run(const Menu::Context &);
virtual ~OptionQuit();
};
/* return to previous menu */
class OptionReturn: public MenuOption {
public:
OptionReturn(const Gui::ContextBox & parent, const Token * token);
virtual void logic();
virtual void run(const Menu::Context &);
virtual ~OptionReturn();
};
/* Sets the quality filter used to stretch the screen (xbr/hqx) */
class OptionQualityFilter: public MenuOption {
public:
OptionQualityFilter(const Gui::ContextBox & parent, const Token * token);
virtual void logic();
virtual void run(const Menu::Context &);
std::string getText() const;
virtual bool leftKey();
virtual bool rightKey();
virtual ~OptionQualityFilter();
protected:
std::string filter;
};
/* Change the fps */
class OptionFps: public MenuOption {
public:
OptionFps(const Gui::ContextBox & parent, const Token * token);
virtual void logic();
virtual void run(const Menu::Context &);
std::string getText() const;
virtual bool leftKey();
virtual bool rightKey();
virtual ~OptionFps();
};
/* continue the game */
class OptionContinue: public MenuOption {
public:
OptionContinue(const Gui::ContextBox & parent, const Token * token);
virtual void logic();
virtual void run(const Menu::Context &);
virtual ~OptionContinue();
};
struct ScreenSize{
ScreenSize(int w, int h):w(w), h(h){}
int w, h;
};
/*! Handles key reconfiguration */
class OptionScreenSize : public MenuOption {
public:
OptionScreenSize(const Gui::ContextBox & parent, const Token *token);
// Do logic before run part
virtual void logic();
// Finally it has been selected, this is what shall run
// endGame will be set true if it is a terminating option
virtual void run(const Menu::Context &);
// This is to pass paramaters to an option ie a bar or something
virtual bool leftKey();
virtual bool rightKey();
virtual ~OptionScreenSize();
protected:
void setMode(int width, int height);
int findMode(int width, int height);
private:
// name
std::string name;
std::vector<ScreenSize> modes;
int lblue, lgreen;
int rblue, rgreen;
};
/*! Handles font selection */
class OptionSelectFont: public MenuOption {
public:
OptionSelectFont(const Gui::ContextBox & parent, const Token *token);
virtual void open();
virtual void close();
// Do logic before run part
virtual void logic();
// Finally it has been selected, this is what shall run
// endGame will be set true if it is a terminating option
virtual void run(const Menu::Context &);
// This is to pass paramaters to an option ie a bar or something
virtual bool leftKey();
virtual bool rightKey();
virtual ~OptionSelectFont();
protected:
private:
// Type of selector
enum Adjust{
fontName=0,
fontHeight,
fontWidth
};
// Current type of menu to adjust
Adjust typeAdjust;
int lblue, lgreen;
int rblue, rgreen;
std::vector<Util::ReferenceCount<Menu::FontInfo> > fonts;
void nextIndex(bool forward);
};
/*! Handles key reconfiguration */
class OptionSpeed: public MenuOption {
public:
// Do logic before run part
virtual void logic();
// Finally it has been selected, this is what shall run
// endGame will be set true if it is a terminating option
virtual void run(const Menu::Context &);
// This is to pass paramaters to an option ie a bar or something
virtual bool leftKey();
virtual bool rightKey();
virtual std::string getText() const;
OptionSpeed(const Gui::ContextBox & parent, const Token *token);
virtual ~OptionSpeed();
private:
// name
std::string name;
int lblue, lgreen;
int rblue, rgreen;
};
/*! Handles sub menus */
class OptionTabMenu: public MenuOption {
public:
// Do logic before run part
virtual void logic();
// Finally it has been selected, this is what shall run
// endGame will be set true if it is a terminating option
virtual void run(const Menu::Context &);
OptionTabMenu(const Gui::ContextBox & parent, const Token *token, const Menu::OptionFactory & factory);
virtual ~OptionTabMenu();
private:
Menu::Menu *menu;
};
class OptionSound: public MenuOption {
public:
OptionSound(const Gui::ContextBox & parent, const Token *token);
// Do logic before run part
virtual void logic();
// Finally it has been selected, this is what shall run
// endGame will be set true if it is a terminating option
virtual void run(const Menu::Context &);
// This is to pass parameters to an option ie a bar or something
virtual bool leftKey();
virtual bool rightKey();
virtual ~OptionSound();
protected:
void changeSound(int much);
private:
int lblue, lgreen;
int rblue, rgreen;
std::string originalName;
};
class OptionMusic: public MenuOption {
public:
OptionMusic(const Gui::ContextBox & parent, const Token *token);
// Do logic before run part
virtual void logic();
// Finally it has been selected, this is what shall run
// endGame will be set true if it is a terminating option
virtual void run(const Menu::Context &);
// This is to pass parameters to an option ie a bar or something
virtual bool leftKey();
virtual bool rightKey();
virtual ~OptionMusic();
protected:
void changeMusic(int much);
private:
int lblue, lgreen;
int rblue, rgreen;
std::string originalName;
};
class OptionLanguage: public MenuOption {
public:
OptionLanguage(const Gui::ContextBox & parent, const Token * token);
virtual void logic();
virtual void run(const Menu::Context &);
};
class OptionJoystick: public MenuOption {
public:
OptionJoystick(const Gui::ContextBox & parent, const Token *token);
// Do logic before run part
virtual void logic();
// Finally it has been selected, this is what shall run
// endGame will be set true if it is a terminating option
virtual void run(const Menu::Context &);
virtual ~OptionJoystick();
};
#endif
diff --git a/include/r-tech1/message-queue.h b/include/r-tech1/message-queue.h
index 44fbcc65..888d681b 100644
--- a/include/r-tech1/message-queue.h
+++ b/include/r-tech1/message-queue.h
@@ -1,36 +1,36 @@
-#ifndef _rtech_message_queue_h
-#define _rtech_message_queue_h
+#ifndef _rtech1_message_queue_h
+#define _rtech1_message_queue_h
#include <queue>
#include <string>
#include "thread.h"
/* multithreaded message queue.
* someone puts messages in, someone takes them out.
* FIFO order
*/
class MessageQueue{
public:
MessageQueue();
/* push on */
void add(const std::string & str);
/* true if any messages are left */
bool hasAny();
/* get the first message */
std::string get();
virtual ~MessageQueue();
static void registerInfo(MessageQueue *);
static void unregisterInfo(MessageQueue *);
static void info(const std::string & str);
static void clearInfo();
static Util::Thread::Lock messageLock;
private:
std::queue<std::string> messages;
Util::Thread::Lock lock;
};
#endif
diff --git a/include/r-tech1/messages.h b/include/r-tech1/messages.h
index b4070ce7..b98d7087 100644
--- a/include/r-tech1/messages.h
+++ b/include/r-tech1/messages.h
@@ -1,39 +1,39 @@
-#ifndef _rtech_messages_h
-#define _rtech_messages_h
+#ifndef _rtech1_messages_h
+#define _rtech1_messages_h
#include <string>
#include <vector>
#include "graphics/color.h"
namespace Graphics{
class Bitmap;
}
class Font;
class Messages{
public:
Messages(int width, int height, int opaque = 128);
virtual inline int getHeight() const {
return height;
}
virtual inline int getWidth() const {
return width;
}
virtual void addMessage( const std::string & s );
virtual void draw( int x, int y, const Graphics::Bitmap & work, const Font & font );
virtual ~Messages();
protected:
int width;
int height;
int opaque;
Graphics::Color borderColor;
std::vector< std::string > messages;
};
#endif
diff --git a/include/r-tech1/nacl/network-system.h b/include/r-tech1/nacl/network-system.h
index b876f907..9f221363 100644
--- a/include/r-tech1/nacl/network-system.h
+++ b/include/r-tech1/nacl/network-system.h
@@ -1,89 +1,89 @@
-#ifndef _rtech_network_system_h
-#define _rtech_network_system_h
+#ifndef _rtech1_network_system_h
+#define _rtech1_network_system_h
#ifdef NACL
#include <map>
#include <string>
#include <vector>
#include "../file-system.h"
#include "../thread.h"
#include "../pointer.h"
namespace pp{
class Instance;
class Core;
}
namespace Nacl{
typedef Path::AbsolutePath AbsolutePath;
typedef Path::RelativePath RelativePath;
typedef Path::InsensitivePath InsensitivePath;
class Manager;
class OpenHandle;
class FileHandle;
class File;
class NetworkSystem: public Storage::System {
public:
NetworkSystem(pp::Instance * instance, pp::Core * core);
virtual ~NetworkSystem();
virtual AbsolutePath find(const RelativePath & path);
virtual RelativePath cleanse(const AbsolutePath & path);
using System::exists;
virtual bool exists(const RelativePath & path);
virtual std::vector<AbsolutePath> getFilesRecursive(const AbsolutePath & dataPath, const std::string & find, bool caseInsensitive = false);
using Storage::System::getFiles;
virtual std::vector<AbsolutePath> getFiles(const AbsolutePath & dataPath, const std::string & find, bool caseInsensitive = false);
virtual std::vector<AbsolutePath> getFiles(const RelativePath & path, const RelativePath & find, bool caseInsensitive);
virtual AbsolutePath configFile();
virtual AbsolutePath userDirectory();
virtual std::vector<AbsolutePath> findDirectories(const RelativePath & path);
virtual AbsolutePath findInsensitive(const RelativePath & path);
virtual AbsolutePath lookupInsensitive(const AbsolutePath & directory, const RelativePath & path);
public:
virtual int libcOpen(const char * path, int mode, int params);
virtual ssize_t libcRead(int fd, void * buf, size_t count);
virtual int libcClose(int fd);
virtual off_t libcLseek(int fd, off_t offset, int whence);
virtual int libcLstat(const char * path, struct stat * buf);
virtual int libcAccess(const char *filename, int mode);
protected:
virtual bool systemExists(const AbsolutePath & path);
/*
string readFileAsString(const AbsolutePath & path);
Directory parseDirectory(const AbsolutePath & path);
*/
unsigned int fileSize(Manager & manager, const Filesystem::AbsolutePath & path);
using System::open;
Util::ReferenceCount<FileHandle> open(const Util::ReferenceCount<OpenHandle> & handle);
protected:
pp::Instance * instance;
pp::Core * core;
/* only one thread at a time to access the network system */
Util::Thread::LockObject fileLock;
Util::Thread::LockObject existsLock;
// Util::ReferenceCount<Manager> manager;
std::map<AbsolutePath, bool> existsCache;
/* map a filesystem path to an object that holds the data for the file */
std::map<std::string, Util::ReferenceCount<OpenHandle> > files;
/* map a file descriptor number to an object that stores information for
* reading from the file
*/
std::map<int, Util::ReferenceCount<File> > fileTable;
};
}
#endif
#endif
diff --git a/include/r-tech1/network/network.h b/include/r-tech1/network/network.h
index 201863de..9e2a60d8 100644
--- a/include/r-tech1/network/network.h
+++ b/include/r-tech1/network/network.h
@@ -1,137 +1,137 @@
-#ifndef _rtech_network_h
-#define _rtech_network_h
+#ifndef _rtech1_network_h
+#define _rtech1_network_h
#include <stdint.h>
#ifdef HAVE_NETWORKING
#include "hawknl/nl.h"
#endif
#include <string>
#include <vector>
#include <exception>
namespace Network{
#ifdef HAVE_NETWORKING
typedef NLsocket Socket;
#else
typedef int Socket;
#endif
const int NO_CONNECTIONS_PENDING = 1;
const int NETWORK_ERROR = 2;
const int DATA_SIZE = 16;
class NetworkException: public std::exception{
public:
NetworkException( const std::string message = "" ):std::exception(),message(message){}
inline const std::string getMessage() const {
return message;
}
~NetworkException() throw();
protected:
inline void setMessage( const std::string & m ){
this->message = m;
}
private:
std::string message;
};
class NoConnectionsPendingException: public NetworkException{
public:
NoConnectionsPendingException(const std::string message = ""):
NetworkException(message){
}
};
class MessageEnd: public NetworkException {
public:
MessageEnd();
};
class InvalidPortException: public NetworkException{
public:
InvalidPortException( int port, const std::string message = "" );
};
class CannotListenException: public NetworkException{
public:
CannotListenException( const std::string message = "" ):
NetworkException( message ){
}
};
/*
template <class M>
int totalSize(const std::vector<M> & messages);
template <class M>
void dump(const std::vector<M> & messages, uint8_t * buffer );
*/
int8_t read8(Socket socket);
int16_t read16(Socket socket);
int32_t read32(Socket socket);
char * dump16(char * where, int16_t length);
char * dump32(char * where, uint32_t length);
void send16(Socket socket, int16_t length);
/* Reads a string by expecting the string to be terminated with a null byte */
std::string readStr(Socket socket, const uint16_t length);
/* This will send a string plus its null byte. If you just wanted to send the string
* without a null byte then use sendBytes(socket, str.c_str(), str.size())
*/
void sendStr(Socket socket, const std::string & str );
void sendBytes(Socket socket, const uint8_t * data, int length);
void sendAllBytes(Socket socket, const uint8_t * data, int length);
void readBytes(Socket socket, uint8_t * data, int length);
/* reads as many bytes as possible in one go. useful for udp where partial packets
* are discarded.
*/
int readUptoBytes(Socket socket, uint8_t * data, int length);
/* Copies the string plus its null byte to the `where' buffer.
* Returns a pointer that is where + str.size() + 1
*/
char * dumpStr(char * where, const std::string & str);
char * parse16(char * where, uint16_t * out);
char * parse32(char * where, uint32_t * out);
/* Reads a string into 'out' from 'where' that is expected to be 'length' bytes.
* Right now the function lies, it just does *out = string(where) so if the actual
* string is longer than 'length' the returned pointer will be into the middle
* of the 'where' buffer.
*/
char * parseString(char * where, std::string * out, uint16_t length);
void init();
void shutdown();
/* Whether or not blocking is enabled by default for new sockets */
void blocking(bool b);
/* Enable/disable blocking for a specific socket */
bool blocking(Socket s, bool b);
/* Enable/disable NODELAY -- the Nagle algorithm for TCP */
bool noDelay(Socket s, bool b);
/* Whether or not new sockets re-use ports */
void reuseSockets(bool what);
void listen(Socket s) throw (NetworkException);
Socket accept(Socket s) throw (NetworkException);
Socket openReliable(int port);
Socket openUnreliable(int port);
Socket connectReliable(std::string server, int port);
Socket connectUnreliable(std::string server, int port);
void close(Socket);
void closeAll();
static std::vector<Socket> open_sockets;
}
#endif
diff --git a/include/r-tech1/parameter.h b/include/r-tech1/parameter.h
index 2fc7feda..7197c5ea 100644
--- a/include/r-tech1/parameter.h
+++ b/include/r-tech1/parameter.h
@@ -1,76 +1,76 @@
-#ifndef _rtech_parameter_h
-#define _rtech_parameter_h
+#ifndef _rtech1_parameter_h
+#define _rtech1_parameter_h
/* parameters are to be used to control the dynamic extent of values. values
* can be pushed onto the current extent and are automatically popped off
* upon function return.
* this is similar to 'parameters' in Racket.
*
* This class is not thread safe.
*/
#include <vector>
#include "pointer.h"
namespace Util{
/* the static variable `stack' has to be defined somewhere. use this syntax to define it
* template <class Value> typename Util::Parameter<Value>::container Util::Parameter<Value>::stacks;
*/
template <class Value>
class Parameter{
public:
/* push a new value on the stack */
Parameter(Parameter & parent, const Value & what):
stack(parent.stack),
items(0){
push(what);
}
Parameter(Parameter & parent):
stack(parent.stack),
items(0){
}
Parameter():
items(0){
stack = new std::vector<Value>();
}
/* pop last value */
virtual ~Parameter(){
for (int i = 0; i < items; i++){
if (stack->size() > 0){
stack->pop_back();
}
}
}
void push(const Value & what){
items += 1;
stack->push_back(what);
}
/* get the current value */
Value current(){
if (stack->size() > 0){
return stack->back();
}
return Value();
}
ReferenceCount<std::vector<Value> > stack;
protected:
/* number of things pushed onto the stack by this object. note this is
* not the number of items on the stack because if there are multiple
* parameter objects then each one could have pushed 1 object on. thus
* the stack will have 2 things in it but each parameter will have an
* 'items' count of 1.
*/
int items;
};
}
#endif
diff --git a/include/r-tech1/pointer.h b/include/r-tech1/pointer.h
index 8149dcb0..b4c1df5f 100644
--- a/include/r-tech1/pointer.h
+++ b/include/r-tech1/pointer.h
@@ -1,200 +1,200 @@
-#ifndef _rtech_util_pointer_h
-#define _rtech_util_pointer_h
+#ifndef _rtech1_util_pointer_h
+#define _rtech1_util_pointer_h
#include <stdlib.h>
namespace Util{
/* Some helpful pointer classes, probably equivalent to stuff in boost
*/
template <class Data>
class ReferenceCount{
public:
explicit ReferenceCount(Data * what = NULL):
count(NULL),
data(what){
count = new int;
*count = 1;
}
ReferenceCount(const ReferenceCount<Data> & him){
data = him.data;
count = him.count;
*count += 1;
}
ReferenceCount & operator=(const ReferenceCount<Data> & him){
/* this object might have a link to `him' so if we release first
* then `him' will get deleted before we can capture his data.
* we need to increase his count first and then release our data
* to insure that `him' will still be alive.
*/
int * temp_count = him.count;
*temp_count += 1;
Data * temp_data = him.data;
release();
data = temp_data;
count = temp_count;
return *this;
}
ReferenceCount & operator=(Data * what){
release();
count = new int;
*count = 1;
data = what;
return *this;
}
/* use this if you need to convert between classes in a heirarchy.
* Base
* Child: public Base
* ReferenceCount<Base> base;
* ReferenceCount<Child> child;
* base = child; is illegal but
* base = child.convert<Base>(); is ok
*/
/*
template <class Convert>
ReferenceCount<Convert> convert() const {
ReferenceCount<Convert> what;
what.release();
what.count = count;
*what.count += 1;
what.data = (Convert*) data;
return what;
}
*/
template <class Convert>
operator ReferenceCount<Convert>() const {
ReferenceCount<Convert> out;
out.release();
out.data = (Convert*) this->data;
out.count = this->count;
*out.count += 1;
return out;
}
bool operator!() const {
return !this->data;
}
Data * operator->() const {
return data;
}
Data & operator*() const {
return *data;
}
/* get the raw pointer -- be ultra careful! */
Data * raw() const {
return data;
}
bool operator<(const ReferenceCount<Data> & him) const {
return data < him.data;
}
bool operator==(const ReferenceCount<Data> & him) const {
return data == him.data;
}
bool operator!=(const ReferenceCount<Data> & him) const {
return !(*this == him);
}
bool operator==(const void * what) const {
return data == what;
}
bool operator!=(const void * what) const {
return !(*this == what);
}
virtual ~ReferenceCount(){
release();
}
/* this has to be public to make the convert() function work but pretend
* its private!
*/
public:
void release(){
*count -= 1;
if (*count == 0){
delete data;
delete count;
data = NULL;
count = NULL;
}
}
int * count;
Data * data;
};
/* Same as ReferenceCount but by default passes a new instance of Data to the constructor
* of ReferenceCount
*/
template <class Data>
class NewReferenceCount: public ReferenceCount<Data> {
public:
NewReferenceCount():
ReferenceCount<Data>(new Data()){
}
};
/* Initializes its pointer to NULL and deletes the data in the destructor.
* how is this different from the ReferenceCount class above? its basically
* the same thing but only allows one owner at a time.
*/
template <class Data>
class ClassPointer{
public:
ClassPointer():
data(NULL){
}
ClassPointer(Data * him):
data(him){
}
ClassPointer & operator=(Data * him){
if (data != NULL){
delete data;
}
data = him;
return *this;
}
Data & operator*() const {
return *data;
}
bool operator==(const void * what) const {
return data == what;
}
bool operator!=(const void * what) const {
return !(*this == what);
}
Data* operator->() const {
return data;
}
virtual ~ClassPointer(){
delete data;
}
private:
Data* data;
};
}
#endif
diff --git a/include/r-tech1/reader.h b/include/r-tech1/reader.h
index 5629e70e..93c00dbd 100644
--- a/include/r-tech1/reader.h
+++ b/include/r-tech1/reader.h
@@ -1,26 +1,26 @@
-#ifndef _rtech_reader_h
-#define _rtech_reader_h
+#ifndef _rtech1_reader_h
+#define _rtech1_reader_h
namespace Util{
/* reads data from some place: files from the filesystem, files with a zipfile,
* files over the network maybe.
*/
class Reader{
public:
Reader();
};
class FileReader: public Reader {
public:
FileReader();
};
class ZipReader: public Reader {
public:
ZipReader();
}
}
#endif
diff --git a/include/r-tech1/regex.h b/include/r-tech1/regex.h
index c45b74a5..fcd7afe2 100644
--- a/include/r-tech1/regex.h
+++ b/include/r-tech1/regex.h
@@ -1,22 +1,22 @@
-#ifndef _rtech_regex_h
-#define _rtech_regex_h
+#ifndef _rtech1_regex_h
+#define _rtech1_regex_h
#include <string>
namespace Util{
/* Use a new type so raw strings are not confused for regexes */
class Regex{
public:
explicit Regex(const std::string & input);
const std::string & get() const;
public:
std::string data;
};
bool matchRegex(const std::string & str, const Regex & regex);
std::string captureRegex(const std::string & str, const Regex & regex, int capture);
}
#endif
diff --git a/include/r-tech1/resource.h b/include/r-tech1/resource.h
index 430ae620..2a0811c6 100644
--- a/include/r-tech1/resource.h
+++ b/include/r-tech1/resource.h
@@ -1,42 +1,42 @@
-#ifndef _rtech_resource_manager_h
-#define _rtech_resource_manager_h
+#ifndef _rtech1_resource_manager_h
+#define _rtech1_resource_manager_h
#include "file-system.h"
#include "thread.h"
#include "pointer.h"
#include <map>
#include <string>
#include <vector>
class Sound;
namespace Graphics{
class Bitmap;
}
/* thread-safe */
class Resource{
public:
/* do not prepend Util::getDataPath() to paths. Resource will do it for you.
*/
static Util::ReferenceCount<Sound> getSound(const Filesystem::RelativePath & path);
static Util::ReferenceCount<Graphics::Bitmap> getBitmap(const Filesystem::RelativePath & path);
static void destroy();
static void initialize();
private:
static Resource * getResource();
Resource();
virtual ~Resource();
Util::ReferenceCount<Sound> _getSound(const Filesystem::AbsolutePath & path);
Util::ReferenceCount<Graphics::Bitmap> _getBitmap(const Filesystem::AbsolutePath & path);
private:
static Resource * resource;
std::map<std::string, Util::ReferenceCount<Sound> > sounds;
std::map<std::string, Util::ReferenceCount<Graphics::Bitmap> > bitmaps;
Util::Thread::LockObject lock;
};
#endif
diff --git a/include/r-tech1/sound/audio.h b/include/r-tech1/sound/audio.h
index de43e601..faedf9bd 100644
--- a/include/r-tech1/sound/audio.h
+++ b/include/r-tech1/sound/audio.h
@@ -1,58 +1,58 @@
-#ifndef _rtech_audio_h
-#define _rtech_audio_h
+#ifndef _rtech1_audio_h
+#define _rtech1_audio_h
/* Deals with audio conversion between any source format and any destination format.
* A format consists of
* byte encoding (8/16/32 bit, signed/unsigned, floating point/integer)
* number of channels (mono/stereo)
* frequency (22050hz, 44100hz, arbitrary hz)
*/
namespace Util{
/* endianness is always native */
enum Encoding{
Unsigned8,
Signed16,
Unsigned16,
Float32
};
class AudioConverter{
public:
AudioConverter(Encoding inputEncoding, int inputChannels, int inputFrequency,
Encoding outputEncoding, int outputChannels, int outputFrequency);
/* given some input length, return how long the converted output will be */
unsigned int convertedLength(int length);
/* convert the audio, put the output in the same buffer passed in -- 'input'
* and returns the number of converted samples.
* 'length' is the number of input samples in *bytes*
* 'input' should be large enough to hold convertedLength(length) samples
*/
int convert(void * input, int length);
virtual ~AudioConverter();
protected:
struct Format{
Encoding bytes;
int channels;
int frequency;
bool operator==(const Format & him) const;
};
int byteSize(const Format & what);
int encodingBytes(Encoding what);
Format input, output;
double sizeRatio;
char * buffer;
int bufferSize;
};
}
#endif
diff --git a/include/r-tech1/sound/music-exception.h b/include/r-tech1/sound/music-exception.h
index 7d80adfc..4bc3812a 100644
--- a/include/r-tech1/sound/music-exception.h
+++ b/include/r-tech1/sound/music-exception.h
@@ -1,37 +1,37 @@
-#ifndef _rtech_music_exception_h
-#define _rtech_music_exception_h
+#ifndef _rtech1_music_exception_h
+#define _rtech1_music_exception_h
#include "../exceptions/exception.h"
namespace Util{
class MusicException: public Exception::Base {
public:
MusicException(const std::string & file, int line, const std::string & reason):
Exception::Base(file, line),
reason(reason){
}
MusicException(const MusicException & copy):
Exception::Base(copy),
reason(copy.reason){
}
virtual ~MusicException() throw(){
}
protected:
virtual const std::string getReason() const {
return reason;
}
virtual Exception::Base * copy() const {
return new MusicException(*this);
}
std::string reason;
};
}
#endif
diff --git a/include/r-tech1/sound/music-player.h b/include/r-tech1/sound/music-player.h
index a60c6d9e..33653549 100644
--- a/include/r-tech1/sound/music-player.h
+++ b/include/r-tech1/sound/music-player.h
@@ -1,242 +1,242 @@
-#ifndef _rtech_music_player_h
-#define _rtech_music_player_h
+#ifndef _rtech1_music_player_h
+#define _rtech1_music_player_h
#include <string>
#include <vector>
#include <stdio.h>
#ifdef HAVE_MP3_MPG123
#include <mpg123.h>
#endif
#ifdef HAVE_OGG
#include <vorbis/vorbisfile.h>
#endif
#ifdef HAVE_MP3_MAD
#include <mad.h>
#endif
#include "../pointer.h"
#include "../file-system.h"
struct DUH;
struct DUH_SIGRENDERER;
struct DUMBFILE;
struct LOGG_Stream;
class Music_Emu;
namespace Util{
class MusicRenderer;
class MusicPlayer{
public:
MusicPlayer();
virtual void play();
virtual void poll();
virtual void pause();
virtual void setVolume(double volume) = 0;
virtual ~MusicPlayer();
/* length is in samples not bytes.
* this function must produce samples that are
* signed
* 16-bit
* use the native endian of the machine
* dual-channel
*
* Which means each sample should be 4 bytes
* 2 bytes * 2 channels
*/
virtual void render(void * stream, int length) = 0;
virtual inline double getVolume() const {
return volume;
}
virtual const ReferenceCount<MusicRenderer> & getRenderer() const {
return out;
}
virtual void setRenderer(const ReferenceCount<MusicRenderer> & what);
protected:
double volume;
ReferenceCount<MusicRenderer> out;
};
/* uses the GME library, plays nintendo music files and others */
class GMEPlayer: public MusicPlayer {
public:
GMEPlayer(std::string path);
virtual void setVolume(double volume);
virtual ~GMEPlayer();
virtual void render(void * stream, int length);
protected:
Music_Emu * emulator;
};
#ifdef HAVE_OGG
struct OggPage{
struct Page{
Page():
position(0),
max(0),
buffer(NULL){
}
int position;
int max;
char * buffer;
~Page(){
delete[] buffer;
}
};
Page buffer1;
// Page buffer2;
// int use;
};
/* Maybe have some common sdl mixer class that this can inherit? */
class OggPlayer: public MusicPlayer {
public:
OggPlayer(const Filesystem::AbsolutePath & path);
virtual void setVolume(double volume);
virtual void render(void * stream, int length);
virtual ~OggPlayer();
class Stream{
public:
Stream();
virtual void reset() = 0;
virtual size_t doRead(void *ptr, size_t size, size_t nmemb) = 0;
virtual int doSeek(ogg_int64_t offset, int whence) = 0;
virtual int doClose() = 0;
virtual long doTell() = 0;
virtual ov_callbacks oggCallbacks() = 0;
static size_t read(void *ptr, size_t size, size_t nmemb, void *datasource);
static int seek(void *datasource, ogg_int64_t offset, int whence);
static int close(void *datasource);
static long tell(void *datasource);
virtual ~Stream();
};
protected:
Stream * createStream(const ReferenceCount<Storage::File> & path);
void openOgg();
void fillPage(OggPage::Page * page);
void doRender(char * data, int bytes);
// FILE* file;
Filesystem::AbsolutePath path;
OggVorbis_File ogg;
ReferenceCount<OggPage> buffer;
ReferenceCount<Stream> stream;
int frequency;
int channels;
int bits;
ogg_int64_t length;
};
#endif
#if defined (HAVE_MP3_MPG123) || defined (HAVE_MP3_MAD)
#ifdef HAVE_MP3_MPG123
class Mpg123Handler{
public:
Mpg123Handler();
virtual ~Mpg123Handler();
virtual void read(void * data, int samples);
virtual void setVolume(double volume);
virtual std::string name() const = 0;
protected:
virtual void reopen() = 0;
mpg123_handle * mp3;
double base_volume;
};
#endif
/* Interface for mp3s */
class Mp3Player: public MusicPlayer {
public:
Mp3Player(const Path::AbsolutePath & path);
virtual void setVolume(double volume);
virtual void render(void * data, int length);
virtual ~Mp3Player();
protected:
#ifdef HAVE_MP3_MPG123
ReferenceCount<Mpg123Handler> handler;
#elif HAVE_MP3_MAD
void output(mad_header const * header, mad_pcm * pcm);
static mad_flow error(void * data, mad_stream * stream, mad_frame * frame);
static mad_flow input(void * data, mad_stream * stream);
void discoverInfo(unsigned char * raw, int length, int * rate, int * channels);
void fill(int frames);
mad_stream stream;
mad_frame frame;
mad_synth synth;
char * available;
int bytesLeft;
int position;
bool readMore;
struct Data{
Data():
data(NULL),
length(0){
}
Data(char * data, int length):
data(data), length(length){
}
~Data(){
}
char * data;
int length;
};
std::vector<Data> pages;
unsigned char * raw;
int rawLength;
#endif
};
#endif
/* interface to DUMB, plays mod/s3m/xm/it */
class DumbPlayer: public MusicPlayer {
public:
DumbPlayer(const Filesystem::AbsolutePath & path);
virtual void setVolume(double volume);
virtual void render(void * data, int samples);
virtual ~DumbPlayer();
class DumbSystem{
public:
DumbSystem();
virtual DUH * loadDumbFile() = 0;
virtual ~DumbSystem();
};
// DUH * loadDumbFile(std::string path);
protected:
DUH * music_file;
DUH_SIGRENDERER * renderer;
ReferenceCount<DumbSystem> system;
};
}
#endif
diff --git a/include/r-tech1/sound/music-renderer.h b/include/r-tech1/sound/music-renderer.h
index 1e13aede..3ab97240 100644
--- a/include/r-tech1/sound/music-renderer.h
+++ b/include/r-tech1/sound/music-renderer.h
@@ -1,58 +1,58 @@
-#ifndef _rtech_music_renderer_h
-#define _rtech_music_renderer_h
+#ifndef _rtech1_music_renderer_h
+#define _rtech1_music_renderer_h
#ifdef USE_SDL
/* for Uint8 */
#include <SDL.h>
#include "sdl/mixer/SDL_mixer.h"
#include "audio.h"
#endif
#ifdef USE_ALLEGRO
struct AUDIOSTREAM;
#endif
#ifdef USE_ALLEGRO5
struct ALLEGRO_AUDIO_STREAM;
struct ALLEGRO_EVENT_QUEUE;
#endif
namespace Util{
class MusicPlayer;
/* implemented by some backend: allegro4/sdl/allergo5 */
class MusicRenderer{
public:
MusicRenderer();
MusicRenderer(int frequency, int channels);
virtual ~MusicRenderer();
void poll(MusicPlayer & player);
void play(MusicPlayer & player);
void pause();
protected:
void create(int frequency, int channels);
#ifdef USE_SDL
static void mixer(void * arg, Uint8 * stream, int length);
void fill(MusicPlayer * player);
void read(MusicPlayer * player, Uint8 * stream, int bytes);
AudioConverter convert;
// SDL_AudioCVT convert;
Uint8 * data;
int position;
int converted;
#endif
#ifdef USE_ALLEGRO
AUDIOSTREAM * stream;
#endif
#ifdef USE_ALLEGRO5
ALLEGRO_AUDIO_STREAM * stream;
ALLEGRO_EVENT_QUEUE * queue;
#endif
};
}
#endif
diff --git a/include/r-tech1/sound/music.h b/include/r-tech1/sound/music.h
index bd030c24..e0d803ef 100644
--- a/include/r-tech1/sound/music.h
+++ b/include/r-tech1/sound/music.h
@@ -1,65 +1,65 @@
-#ifndef _rtech_music_class_h
-#define _rtech_music_class_h
+#ifndef _rtech1_music_class_h
+#define _rtech1_music_class_h
#include <string>
#include <vector>
#include "../file-system.h"
#include "../pointer.h"
namespace Util{
class MusicPlayer;
}
/* The music class. Dont be late or youll get an F!
*/
class Music{
public:
Music( bool on );
virtual ~Music();
static bool loadSong(const std::string & song);
static void changeSong();
/* randomnly select a song from 'songs' and load it */
static void loadSong(std::vector<Filesystem::AbsolutePath> songs);
static void pause();
static void play();
static void soften();
static void louden();
static void fadeIn( double vol );
static void fadeOut( double vol );
static void setVolume( double v );
static double getVolume();
static void mute();
static void unmute();
void doPlay();
protected:
static bool doLoadSong(std::string song);
std::string supportedExtensions();
void _setVolume( double vol );
void _play();
void _pause();
void _soften();
void _louden();
void _fadeIn();
void _fadeOut();
bool playing;
bool enabled;
int fading;
bool internal_loadSong(std::string path);
Util::ReferenceCount<Util::MusicPlayer> musicPlayer;
std::string currentSong;
};
#endif
diff --git a/include/r-tech1/sound/sound.h b/include/r-tech1/sound/sound.h
index 7c35519d..ae07ea7e 100644
--- a/include/r-tech1/sound/sound.h
+++ b/include/r-tech1/sound/sound.h
@@ -1,78 +1,78 @@
-#ifndef _rtech_sound_h
-#define _rtech_sound_h
+#ifndef _rtech1_sound_h
+#define _rtech1_sound_h
#include <string>
#include "r-tech1/exceptions/load_exception.h"
#ifdef USE_ALLEGRO5
#include "allegro5/sound.h"
#endif
struct SAMPLE;
namespace Storage{
class File;
}
/* a sound! */
class Sound{
public:
Sound();
/* create from wav file (riff header + pcm) */
Sound(const char * data, int length);
/* load from abstract file */
Sound(Storage::File & file);
/* load from path */
Sound(const std::string & path);
Sound(const Sound & copy);
/* do any global initialization necessary */
static void initialize();
/* cleanup */
static void uninitialize();
Sound & operator=( const Sound & rhs );
void play();
void play(double volume, int pan);
void playLoop();
void stop();
void setVolume(double volume);
virtual ~Sound();
/* global frequency to use */
// static const int FREQUENCY = 22050;
struct SoundInfo{
SoundInfo():
frequency(44100),
channels(2),
format(0){
}
int frequency;
int channels;
/* format is mostly for SDL */
int format;
};
static SoundInfo Info;
protected:
void loadFromMemory(const char * data, int length);
/* scale to the configuration sound level */
static double scale(double in);
void destroy();
// SAMPLE * my_sound;
SoundData data;
/* reference counting */
int * own;
};
#endif
diff --git a/include/r-tech1/system.h b/include/r-tech1/system.h
index 060f6f84..e13b2b0c 100644
--- a/include/r-tech1/system.h
+++ b/include/r-tech1/system.h
@@ -1,25 +1,25 @@
-#ifndef _rtech_system_h
-#define _rtech_system_h
+#ifndef _rtech1_system_h
+#define _rtech1_system_h
/* system utilities */
#include <string>
#include <stdint.h>
namespace System{
bool isDirectory(const std::string & path);
void makeDirectory(const std::string & path);
void makeAllDirectory(const std::string & path);
bool readableFile(const std::string & path);
bool readable(const std::string & path);
uint64_t getModificationTime(const std::string & path);
// uint64_t currentMicroseconds();
uint64_t currentMilliseconds();
uint64_t currentSeconds();
unsigned long memoryUsage();
/* call startMemoryUsage once at the very beginning of the program */
void startMemoryUsage();
}
#endif
diff --git a/include/r-tech1/system/init.h b/include/r-tech1/system/init.h
index 3dee6307..2f1c318c 100644
--- a/include/r-tech1/system/init.h
+++ b/include/r-tech1/system/init.h
@@ -1,11 +1,11 @@
-#ifndef _rtech_system_init_h
-#define _rtech_system_init_h
+#ifndef _rtech1_system_init_h
+#define _rtech1_system_init_h
#include "r-tech1/debug.h"
#include "r-tech1/init.h"
namespace System{
void initSystem(const Global::InitConditions & conditions, Global::stream_type & out);
}
#endif
diff --git a/include/r-tech1/system/timer.h b/include/r-tech1/system/timer.h
index 0fd9ffe2..783c7292 100644
--- a/include/r-tech1/system/timer.h
+++ b/include/r-tech1/system/timer.h
@@ -1,19 +1,19 @@
-#ifndef _rtech_system_timer_h
-#define _rtech_system_timer_h
+#ifndef _rtech1_system_timer_h
+#define _rtech1_system_timer_h
#include "r-tech1/thread.h"
#include <vector>
namespace System{
extern volatile bool run_timer;
extern Util::Thread::Lock run_timer_lock;
extern Util::ThreadBoolean run_timer_guard;
extern std::vector<Util::Thread::Id> running_timers;
void closeTimers();
void startTimers();
}
#endif
diff --git a/include/r-tech1/thread.h b/include/r-tech1/thread.h
index 8f1688c7..af48db02 100644
--- a/include/r-tech1/thread.h
+++ b/include/r-tech1/thread.h
@@ -1,298 +1,298 @@
-#ifndef _rtech_thread_h
-#define _rtech_thread_h
+#ifndef _rtech1_thread_h
+#define _rtech1_thread_h
/* FIXME: NACL should be able to use SDL threads but they are broken
* for some reason. SDL is implemented in terms of pthreads anyway
* so for now just use the native pthreads implementation.
*/
#if defined(USE_SDL) && !defined(USE_NACL)
#include <SDL.h>
#include <SDL_thread.h>
#include <SDL_mutex.h>
#elif USE_ALLEGRO5
#include <allegro5/allegro5.h>
#else
#include <pthread.h>
// #include <semaphore.h>
#endif
#include "exceptions/exception.h"
/*
#include "exceptions/load_exception.h"
#include "token_exception.h"
#include "mugen/exception.h"
*/
// #include "funcs.h"
#include "debug.h"
/* 9/10/2012: Condition variables have been removed. There are no use-cases in the code
* where multiple threads are waiting for producer thread to signal them so a simpler
* solution is just to use a mutex and poll. The main motivation to remove condition
* variables was in getting the xbox 360 port to work with libxenon which does not
* yet have support for condition variables, but supposedly mutexes work ok.
*/
namespace Util{
void rest(int x);
/* Either uses pthreads or SDL_thread */
namespace Thread{
#ifdef USE_SDL
typedef SDL_mutex* Lock;
typedef SDL_Thread* Id;
typedef int (*ThreadFunction)(void*);
typedef SDL_cond* Condition;
// typedef SDL_semaphore* Semaphore;
#elif USE_ALLEGRO5
typedef ALLEGRO_MUTEX* Lock;
typedef ALLEGRO_THREAD* Id;
typedef void * (*ThreadFunction)(void*);
typedef ALLEGRO_COND* Condition;
// typedef SDL_semaphore* Semaphore;
#else
typedef pthread_mutex_t Lock;
typedef pthread_t Id;
typedef pthread_cond_t Condition;
// typedef sem_t Semaphore;
typedef void * (*ThreadFunction)(void*);
#endif
extern Id uninitializedValue;
bool isUninitialized(Id thread);
bool initializeLock(Lock * lock);
/*
void initializeCondition(Condition * condition);
void destroyCondition(Condition * condition);
int conditionWait(Condition * condition, Lock * lock);
int conditionSignal(Condition * condition);
*/
/*
void initializeSemaphore(Semaphore * semaphore, unsigned int value);
void destroySemaphore(Semaphore * semaphore);
void semaphoreDecrease(Semaphore * semaphore);
void semaphoreIncrease(Semaphore * semaphore);
*/
int acquireLock(Lock * lock);
int releaseLock(Lock * lock);
void destroyLock(Lock * lock);
bool createThread(Id * thread, void * attributes, ThreadFunction function, void * arg);
void joinThread(Id thread);
void cancelThread(Id thread);
/* wraps a Lock in a c++ class */
class LockObject{
public:
LockObject();
int acquire() const;
int release() const;
Lock & getLock(){
return lock;
}
/* wait until check is true.
* you MUST acquire the lock before calling this function */
// void wait(volatile bool & check) const;
/* just until we are signaled
* you MUST acquire the lock before calling this function */
// void wait() const;
/* you MUST acquire the lock before calling this function */
// void signal() const;
/* gets the lock, sets the boolean, and signals the condition
* you MUST NOT acquire the lock before calling this function
*/
// void lockAndSignal(volatile bool & check, bool what) const;
virtual ~LockObject();
Lock lock;
// Condition condition;
};
/* acquires/releases the lock in RAII fashion */
class ScopedLock{
public:
ScopedLock(const LockObject & lock);
~ScopedLock();
private:
const LockObject & lock;
};
class ThreadObject{
public:
ThreadObject(void * data, void * (function)(void * arg));
/* true if the thread was started, false otherwise */
virtual bool start();
virtual ~ThreadObject();
protected:
void * data;
void * (*function)(void * arg);
Id thread;
};
}
class WaitThread{
public:
/* does not start a new thread yet */
WaitThread();
/* starts a thread */
WaitThread(Thread::ThreadFunction thread, void * arg);
/* starts a thread */
void start(Thread::ThreadFunction thread, void * arg);
bool isRunning();
void kill();
virtual ~WaitThread();
public:
/* actually runs the thread */
void doRun();
protected:
Thread::Lock doneLock;
Thread::Id thread;
volatile bool done;
void * arg;
Thread::ThreadFunction function;
};
/* wraps a boolean with lock/unlock while checking/setting it */
class ThreadBoolean{
public:
ThreadBoolean(volatile bool & what, Thread::Lock & lock);
bool get();
void set(bool value);
protected:
volatile bool & what;
Thread::Lock & lock;
};
/* Computes stuff in a separate thread and gives it back when you ask for it.
* Call start() on the future to begin executing it. You can then call `get' on
* the future object to get the result. If the thread is still executing then
* `get' will block until the future completes. If the future has already
* completed then `get' will return immediately with the computed value. The
* use case is computing something that has to be used later: Future future;
* future.start(); // might take a while to compute
* do_stuff_that_takes_a_while(); // future might finish sometime in here
* Object o = future.get(); // future is already done
*
*/
template<class X> class Future{
public:
Future():
thing(0),
thread(Thread::uninitializedValue),
done(false),
exception(NULL),
ran(false){ }
virtual ~Future(){
Thread::joinThread(thread);
delete exception;
}
virtual X get(){
/* make sure the future has been started */
if (Thread::isUninitialized(thread)){
start();
}
Exception::Base * failed = NULL;
bool ok = false;
while (!ok){
future.acquire();
if (!done){
future.release();
Util::rest(1);
} else {
ok = true;
}
}
if (exception != NULL){
failed = exception;
}
X out = thing;
future.release();
if (failed){
failed->throwSelf();
}
return out;
}
virtual void start(){
if (ran){
return;
}
if (!Thread::createThread(&thread, NULL, (Thread::ThreadFunction) runit, this)){
Global::debug(0) << "Could not create future thread. Blocking until its done" << std::endl;
runit(this);
}
ran = true;
}
protected:
bool isDone(){
Thread::ScopedLock scoped(future);
return done;
}
static void * runit(void * arg){
Future<X> * me = (Future<X>*) arg;
try{
me->compute();
/*
} catch (const LoadException & load){
me->exception = new LoadException(load);
} catch (const TokenException & t){
me->exception = new TokenException(t);
} catch (const MugenException & m){
me->exception = new MugenException(m);
*/
} catch (const Exception::Base & base){
me->exception = base.copy();
} catch (...){
me->exception = new Exception::Base(__FILE__, __LINE__);
}
me->future.acquire();
me->done = true;
me->future.release();
// me->future.lockAndSignal(me->done, true);
return NULL;
}
virtual void set(X x){
this->thing = x;
}
virtual void compute() = 0;
X thing;
Thread::Id thread;
Thread::LockObject future;
volatile bool done;
/* if any exceptions occur, throw them from `get' */
Exception::Base * exception;
/* if the future was already started this is true so it can't be
* accidentally started twice
*/
bool ran;
};
}
#endif
diff --git a/include/r-tech1/timer.h b/include/r-tech1/timer.h
index 4243c0ed..eb01c9f7 100644
--- a/include/r-tech1/timer.h
+++ b/include/r-tech1/timer.h
@@ -1,29 +1,29 @@
-#ifndef _rtech_util_timer_h
-#define _rtech_util_timer_h
+#ifndef _rtech1_util_timer_h
+#define _rtech1_util_timer_h
#include "thread.h"
namespace Util{
/* calls a function after X seconds unless stop() is called first */
class Timer{
public:
typedef void (*timeout)(void * arg);
Timer(unsigned int seconds_to_wait, timeout func, void * arg);
void stop();
friend void * do_wait(void * timer_);
protected:
unsigned int wait;
timeout func;
void * arg;
bool stopped;
Thread::Lock lock;
Thread::Id timer;
};
}
#endif
diff --git a/include/r-tech1/token.h b/include/r-tech1/token.h
index 88dda804..7c4eb2ef 100644
--- a/include/r-tech1/token.h
+++ b/include/r-tech1/token.h
@@ -1,321 +1,321 @@
-#ifndef _rtech_token_h
-#define _rtech_token_h
+#ifndef _rtech1_token_h
+#define _rtech1_token_h
#include <string>
#include <vector>
#include <ostream>
#include <stdint.h>
#include "token_exception.h"
class TokenReader;
class Configuration;
class Token;
class TokenView{
public:
TokenView(std::vector<const Token *> tokens);
TokenView(const TokenView & view);
bool hasMore() const;
TokenView & operator=(const TokenView & view);
TokenView & operator>>(const Token* & item);
TokenView & operator>>(std::string & item);
TokenView & operator>>(int & item);
TokenView & operator>>(unsigned char & item);
TokenView & operator>>(uint32_t & item);
TokenView & operator>>(uint64_t & item);
TokenView & operator>>(double & item);
TokenView & operator>>(bool & item);
const Token * next();
protected:
std::vector<const Token*> tokens;
std::vector<const Token*>::iterator current;
};
class TokenMatcher{
public:
template <typename X1>
bool match(X1 & obj1);
template <typename X1, typename X2>
bool match(X1 & obj1, X2 & obj2);
template <typename X1, typename X2, typename X3>
bool match(X1 & obj1, X2 & obj2, X3 & obj3);
template <typename X1, typename X2, typename X3, typename X4>
bool match(X1 & obj1, X2 & obj2, X3 & obj3, X4 & obj4);
TokenMatcher & operator=(const TokenMatcher & matcher);
protected:
TokenMatcher(std::vector<const Token*> tokens);
explicit TokenMatcher();
friend class Token;
std::vector<const Token*> tokens;
std::vector<const Token*>::iterator current;
};
/* Token:
* Basically a tree where each node stores a value in a string
* and can have 0 or more children
*/
class Token{
public:
typedef TokenMatcher Matcher;
Token();
Token(Token const & copy);
Token(std::string tok, bool parse = false);
virtual ~Token();
/* add an existing token to the tree */
void addToken(Token * t);
/* creates a new empty token and returns it */
Token * newToken();
/*
inline const string & getName(){
return name;
}
*/
const std::string & getName() const;
const Token * getParent() const;
Token * getParent();
/* get the original parent, the parent with no parents */
const Token * getRootParent() const;
void setFile( const std::string & s );
const std::string getFileName() const;
/* gets the parents of the token.
*
*
* The lineage of (baz) is 'foo -> bar -> baz'
*/
const std::string getLineage() const;
void print( const std::string space ) const;
std::string toString() const;
/* a pretty printed s-expression */
void toString(std::ostream & stream, const std::string & space) const;
/* no extra whitespace */
void toStringCompact(std::ostream & stream) const;
std::string toStringCompact() const;
/*
bool match(const std::string & subject) const {
TokenMatcher matcher = getMatcher(subject);
return false;
}
*/
template <typename X>
bool match(const std::string & subject, X & obj) const {
TokenMatcher matcher = getMatcher(subject);
return matcher.match(obj);
}
template <typename X1, typename X2>
bool match(const std::string & subject, X1 & obj1, X2 & obj2) const {
TokenMatcher matcher = getMatcher(subject);
return matcher.match(obj1, obj2);
/*
return matcher.match(obj1) &&
matcher.match(obj2);
*/
}
template <typename X1, typename X2, typename X3>
bool match(const std::string & subject, X1 & obj1, X2 & obj2, X3 & obj3) const {
TokenMatcher matcher = getMatcher(subject);
return matcher.match(obj1, obj2, obj3);
}
template <typename X1, typename X2, typename X3, typename X4>
bool match(const std::string & subject, X1 & obj1, X2 & obj2, X3 & obj3, X4 & obj4) const {
TokenMatcher matcher = getMatcher(subject);
return matcher.match(obj1, obj2, obj3, obj4);
}
/*
template <typename X1, typename X2, typename X3, typename X4, typename X5>
bool match(const std::string & subject, X1 & obj1, X2 & obj2, X3 & obj3, X4 & obj4, X5 & obj5) const {
TokenMatcher matcher = getMatcher(subject);
return matcher.match(obj1) &&
matcher.match(obj2) &&
matcher.match(obj3) &&
matcher.match(obj4) &&
matcher.match(obj5);
}
*/
TokenView view() const;
TokenMatcher getMatcher(const std::string & subject) const;
Token * getToken(unsigned int n) const;
/* xpath-esque searching for tokens
* '/' delimits tokens
* <literal> matches a token
*/
const Token * findToken(const std::string & path) const;
Token * findToken(const std::string & path);
/* find all tokens. special characters _ and * */
std::vector<const Token *> findTokens(const std::string & path) const;
/* Removes the given token if the current one contains it */
void removeToken(Token * token);
inline signed int numTokens() const {
return tokens.size() - 1;
}
inline bool isData() const {
return numTokens() == -1;
}
inline const std::vector< Token * > * getTokens() const {
return &tokens;
}
inline void resetToken(){
num_token = 1;
}
/* returns a deep copy of this token. the parent field is set to null */
Token * copy() const;
Token * readToken();
bool hasTokens() const;
bool operator== ( const std::string & rhs ) const;
bool operator!= ( const std::string & rhs ) const;
/*
Token & operator>>( std::string & rhs ) throw( TokenException );
Token & operator>>( int & rhs ) throw( TokenException );
Token & operator>>( double & rhs ) throw( TokenException );
Token & operator>>( Token * & rhs ) throw( TokenException );
Token & operator>>( bool & rhs ) throw( TokenException );
*/
Token & operator<<(const std::string & rhs);
#ifdef XENON
Token & operator<<(const int rhs);
#else
Token & operator<<(const int32_t rhs);
#endif
Token & operator<<(const int64_t rhs);
Token & operator<<(const uint32_t rhs);
Token & operator<<(const uint64_t rhs);
Token & operator<<(Token * token);
Token & operator<<(const double rhs);
protected:
friend class TokenReader;
virtual inline const std::string & _getName(){
return name;
}
virtual inline void setParent(Token * parent){
this->parent = parent;
}
std::string lowerCase(const std::string & s) const;
unsigned int num_token;
std::vector< Token * > tokens;
std::string filename;
Token * parent;
std::string name;
bool own;
};
template <typename X1>
bool TokenMatcher::match(X1 & obj1){
if (current == tokens.end()){
return false;
}
const Token * token = *current;
current++;
try{
token->view() >> obj1;
return true;
} catch (const TokenException & t){
}
return false;
}
template <typename X1, typename X2>
bool TokenMatcher::match(X1 & obj1, X2 & obj2){
if (current == tokens.end()){
return false;
}
const Token * token = *current;
current++;
try{
token->view() >> obj1 >> obj2;
return true;
} catch (const TokenException & t){
}
return false;
}
template <typename X1, typename X2, typename X3>
bool TokenMatcher::match(X1 & obj1, X2 & obj2, X3 & obj3){
if (current == tokens.end()){
return false;
}
const Token * token = *current;
current++;
try{
token->view() >> obj1 >> obj2 >> obj3;
return true;
} catch (const TokenException & t){
}
return false;
}
template <typename X1, typename X2, typename X3, typename X4>
bool TokenMatcher::match(X1 & obj1, X2 & obj2, X3 & obj3, X4 & obj4){
if (current == tokens.end()){
return false;
}
const Token * token = *current;
current++;
try{
token->view() >> obj1 >> obj2 >> obj3 >> obj4;
return true;
} catch (const TokenException & t){
}
return false;
}
#endif
diff --git a/include/r-tech1/token_exception.h b/include/r-tech1/token_exception.h
index e4920f3c..3720cb2e 100644
--- a/include/r-tech1/token_exception.h
+++ b/include/r-tech1/token_exception.h
@@ -1,29 +1,29 @@
-#ifndef _rtech_token_exception_h
-#define _rtech_token_exception_h
+#ifndef _rtech1_token_exception_h
+#define _rtech1_token_exception_h
#include "exceptions/exception.h"
#include <string>
class TokenException: public Exception::Base {
public:
TokenException(const std::string & file, int line, const std::string reason = "");
TokenException(const TokenException & copy);
TokenException(const Exception::Base & base);
virtual ~TokenException() throw();
virtual void throwSelf() const {
throw *this;
}
virtual Exception::Base * copy() const;
protected:
virtual inline const std::string getReason() const {
return reason;
}
std::string reason;
};
#endif
diff --git a/include/r-tech1/tokenreader.h b/include/r-tech1/tokenreader.h
index dd925fa4..bdd2f487 100644
--- a/include/r-tech1/tokenreader.h
+++ b/include/r-tech1/tokenreader.h
@@ -1,40 +1,40 @@
-#ifndef _rtech_tokenreader_h
-#define _rtech_tokenreader_h
+#ifndef _rtech1_tokenreader_h
+#define _rtech1_tokenreader_h
#include <string>
#include <vector>
#include "token_exception.h"
class Token;
namespace Storage{
class File;
}
class TokenReader{
public:
TokenReader();
virtual Token * readToken(const std::string & path);
virtual Token * readToken(const char * path);
virtual Token * readTokenFromString(const std::string & stuff);
virtual Token * readTokenFromFile(const std::string & path);
virtual Token * readTokenFromFile(Storage::File & file);
virtual ~TokenReader();
protected:
/* deprecated */
TokenReader( const std::string & s );
TokenReader( const char * filename );
virtual Token * readToken();
virtual void readTokens(Storage::File & stream);
/*
std::ifstream ifile;
std::string myfile;
*/
std::vector<Token *> my_tokens;
};
#endif
diff --git a/include/r-tech1/version.h b/include/r-tech1/version.h
index cacae3a9..e13bd676 100644
--- a/include/r-tech1/version.h
+++ b/include/r-tech1/version.h
@@ -1,21 +1,21 @@
-#ifndef _rtech_version_h
-#define _rtech_version_h
+#ifndef _rtech1_version_h
+#define _rtech1_version_h
#include <string>
namespace Version{
void setVersion(int major, int minor, int micro);
/* The current version */
int getVersion();
/* The current version as a string */
std::string getVersionString();
/* Turn some major.minor.micro into a single version number for comparisons */
int getVersion(int major, int minor, int micro);
}
#endif
diff --git a/src/debug.cpp b/src/debug.cpp
index fadf790a..1ad426e3 100644
--- a/src/debug.cpp
+++ b/src/debug.cpp
@@ -1,431 +1,440 @@
#include "r-tech1/debug.h"
#include "r-tech1/system.h"
#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#ifdef ANDROID
#include <android/log.h>
#define ANDROID_LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, "r-tech1", __VA_ARGS__)
#endif
#ifdef NETWORK_DEBUG
#include <sys/socket.h>
#include <sys/types.h>
#include <string.h>
#include <arpa/inet.h>
#endif
using namespace std;
static int global_debug_level = 0;
+static std::string global_log_file = "r-tech1.log";
namespace Global{
#ifdef ANDROID
android_ostream::android_ostream(bool enabled):
enabled(enabled){
}
android_ostream & operator<<(android_ostream & stream, const std::string & input){
stream.buffer << input;
return stream;
}
android_ostream & operator<<(android_ostream & stream, const char * input){
stream.buffer << input;
return stream;
}
android_ostream & operator<<(android_ostream & stream, const char input){
stream.buffer << input;
return stream;
}
android_ostream & operator<<(android_ostream & stream, const double input){
stream.buffer << input;
return stream;
}
android_ostream & operator<<(android_ostream & stream, const int input){
stream.buffer << input;
return stream;
}
android_ostream & operator<<(android_ostream & stream, const short int input){
stream.buffer << input;
return stream;
}
android_ostream & operator<<(android_ostream & stream, const short unsigned int input){
stream.buffer << input;
return stream;
}
android_ostream & operator<<(android_ostream & stream, const unsigned int input){
stream.buffer << input;
return stream;
}
android_ostream & operator<<(android_ostream & stream, const bool input){
stream.buffer << input;
return stream;
}
android_ostream & operator<<(android_ostream & stream, const long int input){
stream.buffer << input;
return stream;
}
android_ostream & operator<<(android_ostream & stream, const unsigned long int input){
stream.buffer << input;
return stream;
}
android_ostream & operator<<(android_ostream & stream, const void * input){
stream.buffer << input;
return stream;
}
android_ostream & operator<<(android_ostream & stream, std::ostream & (*f)(std::ostream &)){
if (stream.enabled){
ANDROID_LOGV("%s\n", stream.buffer.str().c_str());
}
stream.buffer.str("");
stream.buffer.rdbuf()->pubseekoff(0, ios_base::end, ios_base::out);
stream.buffer.clear();
return stream;
}
android_ostream android_ostream::stream;
static android_ostream nullcout(false);
#elif defined(WII) && defined(DEBUG)
wii_ostream::wii_ostream(bool enabled):
enabled(enabled){
}
wii_ostream & operator<<(wii_ostream & stream, const std::string & input){
stream.buffer << input;
return stream;
}
wii_ostream & operator<<(wii_ostream & stream, const char * input){
stream.buffer << input;
return stream;
}
wii_ostream & operator<<(wii_ostream & stream, const char input){
stream.buffer << input;
return stream;
}
wii_ostream & operator<<(wii_ostream & stream, const double input){
stream.buffer << input;
return stream;
}
wii_ostream & operator<<(wii_ostream & stream, const int input){
stream.buffer << input;
return stream;
}
wii_ostream & operator<<(wii_ostream & stream, uint64_t input){
stream.buffer << input;
return stream;
}
wii_ostream & operator<<(wii_ostream & stream, const short int input){
stream.buffer << input;
return stream;
}
wii_ostream & operator<<(wii_ostream & stream, const short unsigned int input){
stream.buffer << input;
return stream;
}
wii_ostream & operator<<(wii_ostream & stream, const unsigned int input){
stream.buffer << input;
return stream;
}
wii_ostream & operator<<(wii_ostream & stream, const bool input){
stream.buffer << input;
return stream;
}
wii_ostream & operator<<(wii_ostream & stream, const long int input){
stream.buffer << input;
return stream;
}
wii_ostream & operator<<(wii_ostream & stream, const unsigned long int input){
stream.buffer << input;
return stream;
}
wii_ostream & operator<<(wii_ostream & stream, const void * input){
stream.buffer << input;
return stream;
}
wii_ostream & operator<<(wii_ostream & stream, std::ostream & (*f)(std::ostream &)){
if (stream.enabled){
printf("%s\n", stream.buffer.str().c_str());
}
stream.buffer.str("");
stream.buffer.rdbuf()->pubseekoff(0, ios_base::end, ios_base::out);
stream.buffer.clear();
return stream;
}
wii_ostream wii_ostream::stream;
static wii_ostream nullcout(false);
#elif defined(NETWORK_DEBUG)
network_ostream::network_ostream(const std::string & host, int port, bool enabled):
host(host),
port(port),
enabled(enabled){
}
network_ostream & operator<<(network_ostream & stream, const std::string & input){
stream.buffer << input;
return stream;
}
network_ostream & operator<<(network_ostream & stream, const char * input){
stream.buffer << input;
return stream;
}
network_ostream & operator<<(network_ostream & stream, const char input){
stream.buffer << input;
return stream;
}
network_ostream & operator<<(network_ostream & stream, const double input){
stream.buffer << input;
return stream;
}
network_ostream & operator<<(network_ostream & stream, const int input){
stream.buffer << input;
return stream;
}
network_ostream & operator<<(network_ostream & stream, uint64_t input){
stream.buffer << input;
return stream;
}
network_ostream & operator<<(network_ostream & stream, const short int input){
stream.buffer << input;
return stream;
}
network_ostream & operator<<(network_ostream & stream, const short unsigned int input){
stream.buffer << input;
return stream;
}
network_ostream & operator<<(network_ostream & stream, const unsigned int input){
stream.buffer << input;
return stream;
}
network_ostream & operator<<(network_ostream & stream, const bool input){
stream.buffer << input;
return stream;
}
network_ostream & operator<<(network_ostream & stream, const long int input){
stream.buffer << input;
return stream;
}
#ifndef PS3
network_ostream & operator<<(network_ostream & stream, const unsigned long int input){
stream.buffer << input;
return stream;
}
#endif
network_ostream & operator<<(network_ostream & stream, const void * input){
stream.buffer << input;
return stream;
}
static void sendString(const std::string & host, int port, const std::string & data){
int gateway = socket(PF_INET, SOCK_STREAM, 0);
struct sockaddr_in address;
address.sin_family = AF_INET;
address.sin_port = htons(port);
address.sin_addr.s_addr = inet_addr(host.c_str());
memset(address.sin_zero, '\0', sizeof(address.sin_zero));
connect(gateway, (struct sockaddr*) &address, sizeof(address));
send(gateway, data.c_str(), data.size(), 0);
send(gateway, "\n", 1, 0);
close(gateway);
}
network_ostream & operator<<(network_ostream & stream, std::ostream & (*f)(std::ostream &)){
if (stream.enabled){
sendString(stream.host, stream.port, stream.buffer.str());
// printf("%s\n", stream.buffer.str().c_str());
}
stream.buffer.str("");
stream.buffer.rdbuf()->pubseekoff(0, ios_base::end, ios_base::out);
stream.buffer.clear();
return stream;
}
/* IP address and port are arbitrary */
network_ostream network_ostream::stream("192.168.1.100", 5670);
static network_ostream nullcout("", 0, false);
#else
class nullstreambuf_t: public std::streambuf {
public:
nullstreambuf_t():std::streambuf(){
}
};
static nullstreambuf_t nullstreambuf;
class nullcout_t: public std::ostream {
public:
nullcout_t():std::ostream(&nullstreambuf){
}
};
static nullcout_t nullcout;
#endif
#ifdef ANDROID
static stream_type & defaultStream(){
return android_ostream::stream;
}
static stream_type & getStream(){
return defaultStream();
}
void logToFile(){
}
void closeLog(){
}
#elif defined(WII) && defined(DEBUG)
static stream_type & defaultStream(){
return wii_ostream::stream;
}
static stream_type & getStream(){
return defaultStream();
}
void logToFile(){
}
void closeLog(){
}
#elif defined(NETWORK_DEBUG)
static stream_type & defaultStream(){
return network_ostream::stream;
}
static stream_type & getStream(){
return defaultStream();
}
void logToFile(){
}
void closeLog(){
}
#else
static stream_type & defaultStream(){
return std::cout;
}
static std::ofstream log;
static bool useFile = false;
static stream_type & fileStream(){
static bool init = false;
if (!init){
- log.open("paintown.log");
+ log.open(Global::getLogFile().c_str());
init = true;
}
return log;
}
static void closeFileStream(){
log.close();
}
static stream_type & getStream(){
if (useFile){
return fileStream();
} else {
return defaultStream();
}
}
void logToFile(){
useFile = true;
}
void closeLog(){
closeFileStream();
}
#endif
}
Global::stream_type & Global::debug(int i, const string & context){
if (global_debug_level >= i){
Global::stream_type & out = getStream();
out << "[" << i << ":" << context << "] ";
return out;
}
return nullcout;
}
void Global::setDebug(int i){
global_debug_level = i;
}
int Global::getDebug(){
return global_debug_level;
}
+void Global::setLogFile(const std::string & file){
+ global_log_file = file;
+}
+
+const std::string & Global::getLogFile(){
+ return global_log_file;
+}
+
std::string Global::defaultDebugContext = "default";
void Global::setDefaultDebugContext(const std::string & context){
defaultDebugContext = context;
}
static std::string now(){
time_t t = time(NULL);
tm * timeData;
timeData = localtime(&t);
uint64_t millis = System::currentMilliseconds() % 1000;
if (timeData != NULL){
char buffer[200];
strftime(buffer, sizeof(buffer), "%F %I:%M:%S", timeData);
std::ostringstream out;
out << buffer << "." << millis;
strftime(buffer, sizeof(buffer), " %p", timeData);
out << buffer;
return out.str();
// return std::string(buffer);
}
return std::string();
}
std::string Global::debug_context(const char * file, int line){
std::ostringstream out;
out << file << ":" << line << " " << now();
return out.str();
}
diff --git a/src/loading.cpp b/src/loading.cpp
index 3ff3ae8e..8d58dfc7 100644
--- a/src/loading.cpp
+++ b/src/loading.cpp
@@ -1,553 +1,524 @@
#include "r-tech1/graphics/bitmap.h"
#include <math.h>
#include <iostream>
#include "r-tech1/messages.h"
#include "r-tech1/loading.h"
#include "r-tech1/file-system.h"
#include "r-tech1/font.h"
#include "r-tech1/funcs.h"
#include "r-tech1/version.h"
#include "r-tech1/graphics/gradient.h"
#include "r-tech1/parameter.h"
#include "r-tech1/thread.h"
#include <vector>
#include "r-tech1/thread.h"
#include "r-tech1/message-queue.h"
#include "r-tech1/init.h"
#include "r-tech1/events.h"
#include "r-tech1/input/input-map.h"
#include "r-tech1/input/input-manager.h"
using namespace std;
namespace Loader{
volatile bool done_loading = true;
typedef struct pair{
int x, y;
} ppair;
class MessageInfo{
public:
MessageInfo(){
MessageQueue::registerInfo(&messages);
}
bool transferMessages(Messages & box){
bool did = false;
while (messages.hasAny()){
const string & str = messages.get();
box.addMessage(str);
did = true;
}
return did;
}
~MessageInfo(){
MessageQueue::unregisterInfo(&messages);
}
private:
MessageQueue messages;
};
Info::Info(const string & message, const Filesystem::AbsolutePath & background):
x(-1),
y(-1),
_loadingMessage(message),
background(NULL),
_loadingBackground(background){
}
Info::Info(const Info & info){
this->x = info.x;
this->y = info.y;
this->_loadingMessage = info._loadingMessage;
this->background = info.background;
this->_loadingBackground = info._loadingBackground;
}
Info::~Info(){
}
void Info::setBackground(const Graphics::Bitmap * background){
this->background = background;
}
void Info::setLoadingMessage(const std::string & str){
this->_loadingMessage = str;
}
+void Info::addAuthorInfo(const std::vector<std::string> & info){
+ this->_authorInfo = info;
+}
+
void Info::setPosition(int x, int y){
this->x = x;
this->y = y;
}
const Graphics::Bitmap * Info::getBackground() const {
return background;
}
const string & Info::loadingMessage() const {
return _loadingMessage;
}
+const std::vector<std::string> & Info::authorInfo() const {
+ return _authorInfo;
+}
+
const Filesystem::AbsolutePath & Info::loadingBackground() const {
return _loadingBackground;
}
int Info::getPositionX() const {
return x;
}
int Info::getPositionY() const {
return y;
}
void * loadingScreenSimple1(void * arg);
-static void setupBackground(const Graphics::Bitmap & background, int load_x, int load_y, int load_width, int load_height, int infobox_x, int infobox_y, int infoWidth, int infoHeight, const Graphics::Bitmap & infoBackground, const Graphics::Bitmap & screen){
- int startX = background.getWidth() - Font::getDefaultFont().textLength("Paintown version 9.9.9.9");
- int startY = background.getHeight() - Font::getDefaultFont().getHeight() * 4;
- int height = Font::getDefaultFont().getHeight();
-
- Font::getDefaultFont().printf(startX, startY + height * 0, Graphics::makeColor(192, 192, 192), background, "Paintown version %s", 0, Version::getVersionString().c_str());
- Font::getDefaultFont().printf(startX, startY + height * 1, Graphics::makeColor(192, 192, 192), background, "Made by Jon Rafkind", 0);
- Font::getDefaultFont().printf(startX, startY + height * 2, Graphics::makeColor(192, 192, 192), background, "http://paintown.org", 0);
-
- /* we have to blit to the screen object passed in because that is the bitmap
- * that will be operated on in the draw() method of loadingScreen1.
- * we also have to blit to the real screen because the screen object
- * is not drawn in its entirety to the real screen, only the part
- * that shows the 'Loading ...' message and the info box.
- * drawing twice in Allegro5 is redundant because the screen object is the real
- * screen but for Allegro4 and SDL we need to do this because the screen object
- * is a buffer.
- */
- background.Blit(screen);
- background.BlitToScreen();
- background.Blit(infobox_x, infobox_y, infoWidth, infoHeight, 0, 0, infoBackground);
-}
-
/* converts a bitmap with some text on it into a sequence of points */
static vector<ppair> generateFontPixels(const Font & myFont, const string & message, int width, int height){
Graphics::Bitmap letters(Graphics::Bitmap::createMemoryBitmap(width, height));
letters.fill(Graphics::MaskColor());
myFont.printf(0, 0, Graphics::makeColor(255, 255, 255), letters, message.c_str(), 0);
vector<ppair> pairs;
for (int x = 0; x < letters.getWidth(); x++){
for (int y = 0; y < letters.getHeight(); y++){
Graphics::Color pixel = letters.getPixel(x, y);
if (pixel != Graphics::MaskColor()){
ppair p;
p.x = x;
p.y = y;
pairs.push_back(p);
}
}
}
// Graphics::resetDisplay();
return pairs;
}
/* shows time elapsed */
class TimeCounter{
public:
TimeCounter():
work(200, 40){
start = Global::second_counter;
last = 0;
}
void draw(int x, int y){
const Font & font = Font::getDefaultFont(24, 24);
if (Global::second_counter != last){
work.clear();
last = Global::second_counter;
font.printf(0, 0, Graphics::makeColor(192, 192, 192), work, "Waiting.. %d", 0, last - start);
work.BlitAreaToScreen(x, y);
}
}
Graphics::Bitmap work;
unsigned int start;
unsigned int last;
};
enum LoadingKeys{
Activate
};
static void loadingScreen1(LoadingContext & context, const Info & levelInfo){
int load_x = 80;
int load_y = 220;
const int infobox_width = 300;
const int infobox_height = 150;
const Font & myFont = Font::getDefaultFont(24, 24);
if (levelInfo.getPositionX() != -1){
load_x = levelInfo.getPositionX();
}
if (levelInfo.getPositionY() != -1){
load_y = levelInfo.getPositionY();
}
// const char * the_string = (arg != NULL) ? (const char *) arg : "Loading...";
int load_width = myFont.textLength(levelInfo.loadingMessage().c_str());
int load_height = myFont.getHeight(levelInfo.loadingMessage().c_str());
Global::debug(2) << "loading screen" << endl;
Messages infobox(infobox_width, infobox_height);
const int MAX_COLOR = 200;
/* blend from dark grey to light red */
Effects::Gradient gradient(MAX_COLOR, Graphics::makeColor(16, 16, 16), Graphics::makeColor(192, 8, 8));
// TimeCounter counter;
struct State{
bool drawInfo;
};
class Logic: public Util::Logic {
public:
Logic(LoadingContext & context, State & state, Effects::Gradient & gradient, Messages & infoBox):
context(context),
state(state),
gradient(gradient),
infobox(infoBox),
active(false){
input.set(Keyboard::Key_SPACE, 0, true, Activate);
input.set(Keyboard::Key_ENTER, 0, true, Activate);
input.set(Joystick::Button1, 0, true, Activate);
}
LoadingContext & context;
State & state;
Effects::Gradient & gradient;
MessageInfo info;
Messages & infobox;
bool active;
InputMap<LoadingKeys> input;
void doInput(){
class Handler: public InputHandler<LoadingKeys> {
public:
Handler(bool & active):
active(active){
}
bool & active;
void press(const LoadingKeys & out, Keyboard::unicode_t unicode){
if (out == Activate){
/* the info box can't really be turned off because once
* its drawn it will remain there. the background would
* have to be drawn on top of it to remove the old
* info box. maybe do this in the future, if so use
* active = ! active
* to toggle it.
*/
active = ! active;
}
}
void release(const LoadingKeys & out, Keyboard::unicode_t unicode){
}
};
Handler handler(active);
InputManager::handleEvents(input, InputSource(true), handler);
}
void run(){
for (int i = 0; i < 3; i++){
gradient.backward();
}
doInput();
info.transferMessages(infobox);
// state.drawInfo = active && (info.transferMessages(infobox) || state.drawInfo);
state.drawInfo = active;
}
double ticks(double system){
return system * Global::ticksPerSecond(8);
}
bool done(){
return context.done();
}
};
class Draw: public Util::Draw {
public:
Draw(const Info & levelInfo, State & state, Messages & infobox, Effects::Gradient & gradient, int load_width, int load_height, int infobox_width, int infobox_height, int load_x, int load_y):
levelInfo(levelInfo),
gradient(gradient),
state(state),
infobox(infobox),
infobox_x(load_x),
infobox_y(load_y + load_height * 2),
infobox_width(infobox_width),
infobox_height(infobox_height),
load_x(load_x),
load_y(load_y),
load_width(load_width),
load_height(load_height){
if (levelInfo.loadingBackground() != Filesystem::AbsolutePath("")){
background = Graphics::Bitmap(levelInfo.loadingBackground().path());
}
const Font & myFont = Font::getDefaultFont(24, 24);
pairs = generateFontPixels(myFont, levelInfo.loadingMessage(), load_width, load_height);
}
const Info & levelInfo;
Effects::Gradient & gradient;
State & state;
Messages & infobox;
Graphics::Bitmap background;
// Graphics::Bitmap infoWork;
// Graphics::Bitmap infoBackground;
vector<ppair> pairs;
const int infobox_x;
const int infobox_y;
const int infobox_width;
const int infobox_height;
const int load_x;
const int load_y;
const int load_width;
const int load_height;
- /*
- void drawFirst(const Graphics::Bitmap & screen){
- if (levelInfo.getBackground() != NULL){
- setupBackground(*levelInfo.getBackground(), load_x, load_y, load_width, load_height, infobox_x, infobox_y, infoBackground.getWidth(), infoBackground.getHeight(), infoBackground, screen);
- } else {
- Graphics::Bitmap background;
- if (levelInfo.loadingBackground() != Filesystem::AbsolutePath("")){
- background = Graphics::Bitmap(levelInfo.loadingBackground().path());
- } else {
- background = Graphics::Bitmap(*Graphics::screenParameter.current(), true);
- }
- setupBackground(background, load_x, load_y, load_width, load_height, infobox_x, infobox_y, infoBackground.getWidth(), infoBackground.getHeight(), infoBackground, screen);
- }
- }
- */
-
void drawAuthorInfo(const Graphics::Bitmap & screen){
- int startX = screen.getWidth() - Font::getDefaultFont().textLength("Paintown version 9.9.9.9");
- int startY = screen.getHeight() - Font::getDefaultFont().getHeight() * 4;
+ int startX = screen.getWidth() - Font::getDefaultFont().textLength("R-tech1 version 9.9.9.9");
+ int startY = screen.getHeight() - Font::getDefaultFont().getHeight() * (levelInfo.authorInfo().size() + 1);
int height = Font::getDefaultFont().getHeight();
- Font::getDefaultFont().printf(startX, startY + height * 0, Graphics::makeColor(192, 192, 192), screen, "Paintown version %s", 0, Version::getVersionString().c_str());
- Font::getDefaultFont().printf(startX, startY + height * 1, Graphics::makeColor(192, 192, 192), screen, "Made by Jon Rafkind", 0);
- Font::getDefaultFont().printf(startX, startY + height * 2, Graphics::makeColor(192, 192, 192), screen, "http://paintown.org", 0);
+ Font::getDefaultFont().printf(startX, startY + height * 0, Graphics::makeColor(192, 192, 192), screen, "R-tech1 version %s", 0, Version::getVersionString().c_str());
+ int mod = 1;
+ for (std::vector<std::string>::const_iterator i = levelInfo.authorInfo().begin(); i != levelInfo.authorInfo().end(); ++i, mod++){
+ Font::getDefaultFont().printf(startX, startY + height * mod, Graphics::makeColor(192, 192, 192), screen, (*i), 0);
+ }
}
void draw(const Graphics::Bitmap & screen){
if (!background.isEmpty()){
background.drawStretched(screen);
}
Graphics::Bitmap work(screen, load_x, load_y, load_width, load_height);
// work.lock();
for (vector< ppair >::iterator it = pairs.begin(); it != pairs.end(); it++){
Graphics::Color color = gradient.current(it->x);
work.putPixel(it->x, it->y, color);
}
// work.unlock();
if (state.drawInfo){
// infoBackground.Blit(infoWork);
const Font & infoFont = Font::getDefaultFont(24, 24);
/* cheesy hack to change the font size. the font
* should store the size and change it on its own
*/
Graphics::Bitmap infoWork(screen, infobox_x, infobox_y, infobox_width, infobox_height);
Font::getDefaultFont(13, 13);
infobox.draw(0, 0, infoWork, infoFont);
Font::getDefaultFont(24, 24);
infoWork.BlitAreaToScreen(infobox_x, infobox_y);
// infoWork.BlitToScreen();
// state.drawInfo = false;
}
drawAuthorInfo(screen);
/* work already contains the correct background */
// work.Blit( load_x, load_y, *Bitmap::Screen );
// work.BlitToScreen();
// work.BlitAreaToScreen(load_x, load_y);
}
};
State state;
state.drawInfo = false;
Logic logic(context, state, gradient, infobox);
Draw draw(levelInfo, state, infobox, gradient, load_width, load_height, infobox_width, infobox_height, load_x, load_y);
Util::standardLoop(logic, draw);
}
static void loadingScreenSimpleX1(LoadingContext & context, const Info & levelInfo){
class Logic: public Util::Logic {
public:
Logic(LoadingContext & context, int & angle, int speed):
context(context),
speed(speed),
angle(angle){
}
LoadingContext & context;
/* speed of rotation */
const int speed;
int & angle;
double ticks(double system){
return system * Global::ticksPerSecond(10);
}
bool done(){
return context.done();
}
void run(){
angle += speed * 2;
angle = angle % 360;
}
};
class Draw: public Util::Draw {
public:
Draw(int & angle, const int speed):
angle(angle),
speed(speed){
/*
if (levelInfo.loadingBackground() != Filesystem::AbsolutePath("")){
background = Graphics::Bitmap(levelInfo.loadingBackground().path());
}
*/
colors[0] = Graphics::makeColor(0x18, 0x52, 0xa0);
colors[1] = Graphics::makeColor(0x00, 0x99, 0xff);
colors[2] = Graphics::makeColor(0xff, 0x22, 0x33);
colors[3] = Graphics::makeColor(0x44, 0x77, 0x33);
Graphics::Bitmap::transBlender(0, 0, 0, 64);
}
Graphics::Bitmap background;
int & angle;
const int speed;
/* the length of this array is the number of circles to show */
Graphics::Color colors[4];
virtual ~Draw(){
}
void draw(const Graphics::Bitmap & screen){
if (!background.isEmpty()){
background.drawStretched(screen);
}
Graphics::Bitmap work(screen, 0, 0, 40, 40);
int max = Util::array_size(colors);
double middleX = work.getWidth() / 2;
double middleY = work.getHeight() / 2;
int size = 15;
int radius = 3;
for (int i = 0; i < max; i++){
double new_angle = angle + 360.0 / (double) max * i;
int lag = 17;
double x = cos(Util::radians(new_angle - lag)) * size;
double y = sin(Util::radians(new_angle - lag)) * size;
/* ghost circle */
work.translucent(0, 0, 0, 128).circleFill(middleX + x, middleY + y, radius, colors[i]);
x = cos(Util::radians(new_angle)) * size;
y = sin(Util::radians(new_angle)) * size;
/* real circle */
work.circleFill(middleX + x, middleY + y, radius, colors[i]);
}
// work.BlitAreaToScreen(0, 0);
}
};
int angle = 0;
int speed = 10;
Logic logic(context, angle, speed);
Draw draw(angle, speed);
Util::standardLoop(logic, draw);
}
LoadingContext::LoadingContext():
finished(false){
Util::Thread::initializeLock(&lock);
}
LoadingContext::~LoadingContext(){
}
void LoadingContext::doLoad(){
this->load();
Util::Thread::acquireLock(&lock);
finished = true;
Util::Thread::releaseLock(&lock);
}
bool LoadingContext::done(){
bool ok = false;
Util::Thread::acquireLock(&lock);
ok = this->finished;
Util::Thread::releaseLock(&lock);
return ok;
}
void * LoadingContext::load_it(void * arg){
LoadingContext * context = (LoadingContext*) arg;
context->doLoad();
return NULL;
}
static void showLoadMessage(){
int screenX = 80;
int screenY = 50;
Graphics::Bitmap work(110, 50);
work.BlitFromScreen(screenX, screenY);
Graphics::Bitmap top(110, 50);
top.fill(Graphics::makeColor(0, 0, 0));
Font::getDefaultFont(25, 25).printf(10, 5, Graphics::makeColor(192, 192, 192), top, "Loading", 0);
Graphics::Bitmap::transBlender(0, 0, 0, 200);
top.translucent().draw(0, 0, work);
work.BlitAreaToScreen(screenX, screenY);
}
void loadScreen(LoadingContext & context, const Info & info, Kind kind){
Util::Thread::Id loadingThread;
bool created = Util::Thread::createThread(&loadingThread, NULL, (Util::Thread::ThreadFunction) LoadingContext::load_it, &context);
if (!created){
Global::debug(0) << "Could not create loading thread. Loading will occur in the main thread" << endl;
showLoadMessage();
LoadingContext::load_it(&context);
// throw LoadException(__FILE__, __LINE__, "Could not create loader thread");
} else {
InputManager::deferResizeEvents(true);
switch (kind){
case Default: loadingScreen1(context, info); break;
case SimpleCircle: loadingScreenSimpleX1(context, info); break;
default: loadingScreen1(context, info); break;
}
Util::Thread::joinThread(loadingThread);
InputManager::deferResizeEvents(false);
}
}
}

File Metadata

Mime Type
text/x-diff
Expires
Mon, Jun 15, 11:25 PM (2 w, 3 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
69747
Default Alt Text
(299 KB)

Event Timeline