Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
416 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 a0e5851d..d9d3c9ff 100644
--- a/include/r-tech1/argument.h
+++ b/include/r-tech1/argument.h
@@ -1,34 +1,34 @@
-#ifndef _paintown_util_argument_h
-#define _paintown_util_argument_h
+#ifndef _rtech_util_argument_h
+#define _rtech_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 1fe9ffde..62a6f3c5 100644
--- a/include/r-tech1/compress.h
+++ b/include/r-tech1/compress.h
@@ -1,8 +1,8 @@
-#ifndef _paintown_compress_h
-#define _paintown_compress_h
+#ifndef _rtech_compress_h
+#define _rtech_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 912a9358..31efe11e 100644
--- a/include/r-tech1/configuration.h
+++ b/include/r-tech1/configuration.h
@@ -1,186 +1,186 @@
-#ifndef _paintown_configuration_h
-#define _paintown_configuration_h
+#ifndef _rtech_configuration_h
+#define _rtech_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 c105f1f4..87fbcf38 100644
--- a/include/r-tech1/console.h
+++ b/include/r-tech1/console.h
@@ -1,143 +1,143 @@
-#ifndef _paintown_console_h
-#define _paintown_console_h
+#ifndef _rtech_console_h
+#define _rtech_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 14ebe527..f01cc6ec 100644
--- a/include/r-tech1/debug.h
+++ b/include/r-tech1/debug.h
@@ -1,113 +1,113 @@
-#ifndef _paintown_debug_h
-#define _paintown_debug_h
+#ifndef _rtech_debug_h
+#define _rtech_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();
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 705825ed..30c7da07 100644
--- a/include/r-tech1/events.h
+++ b/include/r-tech1/events.h
@@ -1,133 +1,133 @@
-#ifndef _paintown_events_h
-#define _paintown_events_h
+#ifndef _rtech_events_h
+#define _rtech_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 7fe12e22..b49858f3 100644
--- a/include/r-tech1/exceptions/exception.h
+++ b/include/r-tech1/exceptions/exception.h
@@ -1,80 +1,80 @@
-#ifndef _paintown_exception_12345_h
-#define _paintown_exception_12345_h
+#ifndef _rtech_exception_12345_h
+#define _rtech_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 a5ecad80..b8c16556 100644
--- a/include/r-tech1/exceptions/shutdown_exception.h
+++ b/include/r-tech1/exceptions/shutdown_exception.h
@@ -1,17 +1,17 @@
-#ifndef _paintown_shutdown_exception_h
-#define _paintown_shutdown_exception_h
+#ifndef _rtech_shutdown_exception_h
+#define _rtech_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 c2242bd4..b31f50d9 100644
--- a/include/r-tech1/file-system.h
+++ b/include/r-tech1/file-system.h
@@ -1,606 +1,606 @@
-#ifndef _paintown_file_system_h
-#define _paintown_file_system_h
+#ifndef _rtech_file_system_h
+#define _rtech_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 paintown system.
+ * 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 0c521a70..41f48de2 100644
--- a/include/r-tech1/font.h
+++ b/include/r-tech1/font.h
@@ -1,125 +1,125 @@
-#ifndef _paintown_font_h
-#define _paintown_font_h
+#ifndef _rtech_font_h
+#define _rtech_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 5f3dda07..510c7c35 100644
--- a/include/r-tech1/font_factory.h
+++ b/include/r-tech1/font_factory.h
@@ -1,46 +1,46 @@
-#ifndef _paintown_font_factory_h
-#define _paintown_font_factory_h
+#ifndef _rtech_font_factory_h
+#define _rtech_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 33c6f822..47c28f77 100644
--- a/include/r-tech1/funcs.h
+++ b/include/r-tech1/funcs.h
@@ -1,118 +1,118 @@
-#ifndef _paintown_funcs_h
-#define _paintown_funcs_h
+#ifndef _rtech_funcs_h
+#define _rtech_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 dac58eb0..77d107f8 100644
--- a/include/r-tech1/graphics/bitmap.h
+++ b/include/r-tech1/graphics/bitmap.h
@@ -1,790 +1,790 @@
-#ifndef _paintown_bitmap_h_
-#define _paintown_bitmap_h_
+#ifndef _rtech_bitmap_h_
+#define _rtech_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 ed77ccb3..cfa65e8b 100644
--- a/include/r-tech1/graphics/color.h
+++ b/include/r-tech1/graphics/color.h
@@ -1,6 +1,6 @@
-#ifndef _paintown_graphics_color_h_
-#define _paintown_graphics_color_h_
+#ifndef _rtech_graphics_color_h_
+#define _rtech_graphics_color_h_
#include "bitmap.h"
#endif
diff --git a/include/r-tech1/graphics/fire.h b/include/r-tech1/graphics/fire.h
index 34f85fc0..f45713c4 100644
--- a/include/r-tech1/graphics/fire.h
+++ b/include/r-tech1/graphics/fire.h
@@ -1,45 +1,45 @@
-#ifndef _paintown_fire_93c6678306f3542737be4288dc09cfa9
-#define _paintown_fire_93c6678306f3542737be4288dc09cfa9
+#ifndef _rtech_fire_93c6678306f3542737be4288dc09cfa9
+#define _rtech_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 e1aff7d5..53116db7 100644
--- a/include/r-tech1/graphics/gradient.h
+++ b/include/r-tech1/graphics/gradient.h
@@ -1,43 +1,43 @@
-#ifndef _paintown_gradient_h
-#define _paintown_gradient_h
+#ifndef _rtech_gradient_h
+#define _rtech_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 3b6c044a..2aeabb2e 100644
--- a/include/r-tech1/gui/animation.h
+++ b/include/r-tech1/gui/animation.h
@@ -1,393 +1,393 @@
-#ifndef _paintown_gui_animation_h
-#define _paintown_gui_animation_h
+#ifndef _rtech_gui_animation_h
+#define _rtech_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 df0da48d..c414aa04 100644
--- a/include/r-tech1/gui/box.h
+++ b/include/r-tech1/gui/box.h
@@ -1,34 +1,34 @@
-#ifndef _paintown_gui_box_h
-#define _paintown_gui_box_h
+#ifndef _rtech_gui_box_h
+#define _rtech_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 e122a389..1c2c28b2 100644
--- a/include/r-tech1/gui/container.h
+++ b/include/r-tech1/gui/container.h
@@ -1,42 +1,42 @@
-#ifndef _paintown_gui_container_h
-#define _paintown_gui_container_h
+#ifndef _rtech_gui_container_h
+#define _rtech_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 3d6d7d27..75625114 100644
--- a/include/r-tech1/gui/context-box.h
+++ b/include/r-tech1/gui/context-box.h
@@ -1,262 +1,262 @@
-#ifndef _paintown_gui_context_box_h
-#define _paintown_gui_context_box_h
+#ifndef _rtech_gui_context_box_h
+#define _rtech_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 034e6ff2..bab89e62 100644
--- a/include/r-tech1/gui/coordinate.h
+++ b/include/r-tech1/gui/coordinate.h
@@ -1,236 +1,236 @@
-#ifndef _paintown_gui_coordinate_h
-#define _paintown_gui_coordinate_h
+#ifndef _rtech_gui_coordinate_h
+#define _rtech_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 bf0c9d7c..f3bc022a 100644
--- a/include/r-tech1/gui/lineedit.h
+++ b/include/r-tech1/gui/lineedit.h
@@ -1,78 +1,78 @@
-#ifndef paintown_gui_lineedit_h
-#define paintown_gui_lineedit_h
+#ifndef _rtech_gui_lineedit_h
+#define _rtech_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 50d069d3..1ce15a65 100644
--- a/include/r-tech1/gui/popup-box.h
+++ b/include/r-tech1/gui/popup-box.h
@@ -1,76 +1,76 @@
-#ifndef _paintown_gui_popup_box_h
-#define _paintown_gui_popup_box_h
+#ifndef _rtech_gui_popup_box_h
+#define _rtech_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 e37fc18a..4459a7fd 100644
--- a/include/r-tech1/gui/rectarea.h
+++ b/include/r-tech1/gui/rectarea.h
@@ -1,31 +1,31 @@
-#ifndef _paintown_gui_rectarea_h
-#define _paintown_gui_rectarea_h
+#ifndef _rtech_gui_rectarea_h
+#define _rtech_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 4f840f8c..e016f6c3 100644
--- a/include/r-tech1/gui/tabbed-box.h
+++ b/include/r-tech1/gui/tabbed-box.h
@@ -1,161 +1,161 @@
-#ifndef _paintown_gui_tabbed_box_h
-#define _paintown_gui_tabbed_box_h
+#ifndef _rtech_gui_tabbed_box_h
+#define _rtech_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 8e9c6d85..74c718e3 100644
--- a/include/r-tech1/gui/widget.h
+++ b/include/r-tech1/gui/widget.h
@@ -1,86 +1,86 @@
-#ifndef _paintown_gui_widget_h
-#define _paintown_gui_widget_h
+#ifndef _rtech_gui_widget_h
+#define _rtech_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 5bae4125..f92a05b3 100644
--- a/include/r-tech1/init.h
+++ b/include/r-tech1/init.h
@@ -1,61 +1,61 @@
-#ifndef _paintown_init_h
-#define _paintown_init_h
+#ifndef _rtech_init_h
+#define _rtech_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 9e1a95d3..4b3f1af2 100644
--- a/include/r-tech1/input/allegro5/joystick.h
+++ b/include/r-tech1/input/allegro5/joystick.h
@@ -1,36 +1,36 @@
-#ifndef _paintown_allegro5_joystick_h
-#define _paintown_allegro5_joystick_h
+#ifndef _rtech_allegro5_joystick_h
+#define _rtech_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 a68c3f6c..2ec407b7 100644
--- a/include/r-tech1/input/input-manager.h
+++ b/include/r-tech1/input/input-manager.h
@@ -1,316 +1,316 @@
-#ifndef _paintown_input_manager
-#define _paintown_input_manager
+#ifndef _rtech_input_manager
+#define _rtech_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 paintown_main(int, char**);
+ 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 7218ecfb..27baec0a 100644
--- a/include/r-tech1/input/input-map.h
+++ b/include/r-tech1/input/input-map.h
@@ -1,318 +1,318 @@
-#ifndef _paintown_input_map_h
-#define _paintown_input_map_h
+#ifndef _rtech_input_map_h
+#define _rtech_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 a5cf3d02..2c5aaaf3 100644
--- a/include/r-tech1/input/input-source.h
+++ b/include/r-tech1/input/input-source.h
@@ -1,38 +1,38 @@
-#ifndef paintown_input_source_h
-#define paintown_input_source_h
+#ifndef _rtech_input_source_h
+#define _rtech_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 eb454cb2..42b0fad3 100644
--- a/include/r-tech1/input/input.h
+++ b/include/r-tech1/input/input.h
@@ -1,32 +1,32 @@
-#ifndef _paintown_input_h
-#define _paintown_input_h
+#ifndef _rtech_input_h
+#define _rtech_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 0b91efa2..5bdb3016 100644
--- a/include/r-tech1/input/joystick.h
+++ b/include/r-tech1/input/joystick.h
@@ -1,167 +1,167 @@
-#ifndef _paintown_joystick_h
-#define _paintown_joystick_h
+#ifndef _rtech_joystick_h
+#define _rtech_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 c60a0f4b..ba99d229 100644
--- a/include/r-tech1/input/keyboard.h
+++ b/include/r-tech1/input/keyboard.h
@@ -1,297 +1,297 @@
-#ifndef _paintown_keyboard_h
-#define _paintown_keyboard_h
+#ifndef _rtech_keyboard_h
+#define _rtech_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 d04a1a54..4ba83df8 100644
--- a/include/r-tech1/input/text-input.h
+++ b/include/r-tech1/input/text-input.h
@@ -1,83 +1,83 @@
-#ifndef _paintown_text_input_h
-#define _paintown_text_input_h
+#ifndef _rtech_text_input_h
+#define _rtech_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 aa28b1ec..fc30fd03 100644
--- a/include/r-tech1/language-string.h
+++ b/include/r-tech1/language-string.h
@@ -1,38 +1,38 @@
-#ifndef _paintown_language_string_h
-#define _paintown_language_string_h
+#ifndef _rtech_language_string_h
+#define _rtech_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 adb3cc39..22c70f01 100644
--- a/include/r-tech1/loading.h
+++ b/include/r-tech1/loading.h
@@ -1,73 +1,73 @@
-#ifndef _paintown_loading_h
-#define _paintown_loading_h
+#ifndef _rtech_loading_h
+#define _rtech_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 setPosition(int x, int y);
virtual const Graphics::Bitmap * getBackground() const;
virtual const std::string & loadingMessage() const;
virtual const Filesystem::AbsolutePath & loadingBackground() const;
virtual int getPositionX() const;
virtual int getPositionY() const;
protected:
int x, y;
std::string _loadingMessage;
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 70a911e8..20796e8b 100644
--- a/include/r-tech1/main.h
+++ b/include/r-tech1/main.h
@@ -1,6 +1,6 @@
-#ifndef _paintown_main_h
-#define _paintown_main_h
+#ifndef _rtech_main_h
+#define _rtech_main_h
-int paintown_main( int argc, char ** argv );
+int rtech_main( int argc, char ** argv );
#endif
diff --git a/include/r-tech1/memory.h b/include/r-tech1/memory.h
index f4a96987..7a9ee95c 100644
--- a/include/r-tech1/memory.h
+++ b/include/r-tech1/memory.h
@@ -1,132 +1,132 @@
-#ifndef _paintown_3ac0ba2587944345f2241085269c24f8
-#define _paintown_3ac0ba2587944345f2241085269c24f8
+#ifndef _rtech_3ac0ba2587944345f2241085269c24f8
+#define _rtech_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 bbbfb723..108c2c5e 100644
--- a/include/r-tech1/menu/action_speed.h
+++ b/include/r-tech1/menu/action_speed.h
@@ -1,18 +1,18 @@
-#ifndef _paintown_action_speed_h
-#define _paintown_action_speed_h
+#ifndef _rtech_action_speed_h
+#define _rtech_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 57ddb9c8..ff5dcae2 100644
--- a/include/r-tech1/menu/actionfactory.h
+++ b/include/r-tech1/menu/actionfactory.h
@@ -1,9 +1,9 @@
-#ifndef _paintown_actionfactory_h
-#define _paintown_actionfactory_h
+#ifndef _rtech_actionfactory_h
+#define _rtech_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 6727a61c..c16274df 100644
--- a/include/r-tech1/menu/font-info.h
+++ b/include/r-tech1/menu/font-info.h
@@ -1,170 +1,170 @@
-#ifndef _paintown_font_info_h
-#define _paintown_font_info_h
+#ifndef _rtech_font_info_h
+#define _rtech_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 6271e5c1..cd79ea05 100644
--- a/include/r-tech1/menu/menu-exception.h
+++ b/include/r-tech1/menu/menu-exception.h
@@ -1,14 +1,14 @@
-#ifndef _paintown_menu_reload_exception_h
-#define _paintown_menu_reload_exception_h
+#ifndef _rtech_menu_reload_exception_h
+#define _rtech_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 f15e583a..870a3e74 100644
--- a/include/r-tech1/menu/menu.h
+++ b/include/r-tech1/menu/menu.h
@@ -1,575 +1,575 @@
-#ifndef _paintown_Menu_h
-#define _paintown_Menu_h
+#ifndef _rtech_Menu_h
+#define _rtech_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 c3af993e..f112bda3 100644
--- a/include/r-tech1/menu/menu_action.h
+++ b/include/r-tech1/menu/menu_action.h
@@ -1,18 +1,18 @@
-#ifndef _paintown_menu_action_h
-#define _paintown_menu_action_h
+#ifndef _rtech_menu_action_h
+#define _rtech_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 91fcaa2f..4b69e0ca 100644
--- a/include/r-tech1/menu/menu_option.h
+++ b/include/r-tech1/menu/menu_option.h
@@ -1,98 +1,98 @@
-#ifndef _paintown_menu_option_h
-#define _paintown_menu_option_h
+#ifndef _rtech_menu_option_h
+#define _rtech_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 c4389f82..aec7f8a1 100644
--- a/include/r-tech1/menu/optionfactory.h
+++ b/include/r-tech1/menu/optionfactory.h
@@ -1,22 +1,22 @@
-#ifndef _paintown_optionfactory_h
-#define _paintown_optionfactory_h
+#ifndef _rtech_optionfactory_h
+#define _rtech_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 52c67081..f397d03e 100644
--- a/include/r-tech1/menu/options.h
+++ b/include/r-tech1/menu/options.h
@@ -1,557 +1,557 @@
-#ifndef _paintown_options_h
-#define _paintown_options_h
+#ifndef _rtech_options_h
+#define _rtech_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 80e175d7..44fbcc65 100644
--- a/include/r-tech1/message-queue.h
+++ b/include/r-tech1/message-queue.h
@@ -1,36 +1,36 @@
-#ifndef _paintown_message_queue_h
-#define _paintown_message_queue_h
+#ifndef _rtech_message_queue_h
+#define _rtech_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 81284595..b4070ce7 100644
--- a/include/r-tech1/messages.h
+++ b/include/r-tech1/messages.h
@@ -1,39 +1,39 @@
-#ifndef _paintown_messages_h
-#define _paintown_messages_h
+#ifndef _rtech_messages_h
+#define _rtech_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 daa6bc12..b876f907 100644
--- a/include/r-tech1/nacl/network-system.h
+++ b/include/r-tech1/nacl/network-system.h
@@ -1,89 +1,89 @@
-#ifndef _paintown_network_system_h
-#define _paintown_network_system_h
+#ifndef _rtech_network_system_h
+#define _rtech_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/irc.h b/include/r-tech1/network/irc.h
index 1f675100..a9a349d3 100644
--- a/include/r-tech1/network/irc.h
+++ b/include/r-tech1/network/irc.h
@@ -1,397 +1,397 @@
#ifndef _util_network_irc_h
#define _util_network_irc_h
#include "network.h"
#include "chat.h"
#include "r-tech1/pointer.h"
#include "r-tech1/thread.h"
#include "r-tech1/gui/tab-container.h"
#include "r-tech1/gui/lineedit.h"
#include "r-tech1/gui/list.h"
#include <string>
#include <vector>
#include <queue>
#include <map>
namespace Network{
namespace IRC{
class Command{
public:
enum Type{
Unknown,
Pass,
Nick,
User,
Userhost,
Server,
Oper,
Quit,
Squit,
Join,
Part,
Mode,
Topic,
Names,
List,
Invite,
Kick,
Version,
Stats,
Links,
Time,
Connect,
Trace,
Admin,
Info,
PrivateMessage,
Notice,
Who,
Whois,
Whowas,
Kill,
Ping,
Pong,
Error,
ErrorNickInUse,
ErrorNoSuchNick,
ErrorNoSuchChannel,
ErrorNeedMoreParams,
ErrorBannedFromChannel,
ErrorInviteOnlyChannel,
ErrorBadChannelKey,
ErrorChannelIsFull,
ReplyNames,
ReplyNamesEndOf,
ReplyNoTopic,
ReplyTopic,
ReplyTopicAuthor,
ReplyMOTD,
ReplyMOTDStart,
ReplyMOTDEndOf,
ReplyUserhost,
};
// Initializes it from an incoming message off of socket
Command(const std::string &);
// Create a message with owner and type
Command(const std::string &, const Type &);
Command(const Command &);
virtual ~Command();
virtual const Command & operator=(const Command &);
virtual std::string getSendable() const;
virtual std::string getCTCPSendable() const;
virtual inline const std::string & getOwner() const {
return this->owner;
}
virtual inline const Type & getType() const {
return this->type;
}
virtual inline void setParameters(const std::string & param1){
this->parameters.clear();
this->parameters.push_back(param1);
}
virtual inline void setParameters(const std::string & param1, const std::string & param2){
this->parameters.clear();
this->parameters.push_back(param1);
this->parameters.push_back(param2);
}
virtual inline void setParameters(const std::string & param1, const std::string & param2, const std::string & param3){
this->parameters.clear();
this->parameters.push_back(param1);
this->parameters.push_back(param2);
this->parameters.push_back(param3);
}
virtual inline void setParameters(const std::string & param1, const std::string & param2, const std::string & param3, const std::string & param4){
this->parameters.clear();
this->parameters.push_back(param1);
this->parameters.push_back(param2);
this->parameters.push_back(param3);
this->parameters.push_back(param4);
}
virtual inline void setParameters(const std::vector< std::string > & params){
this->parameters = params;
}
virtual inline const std::vector< std::string > & getParameters() const {
return this->parameters;
}
virtual inline bool hasCtcp() const {
return !this->ctcp.empty();
}
virtual inline const std::vector< std::string > & getCtcp() const {
return this->ctcp;
}
protected:
std::string owner;
Type type;
std::vector< std::string > parameters;
std::vector< std::string > ctcp;
};
class Channel{
public:
Channel();
Channel(const std::string &);
Channel(const Channel &);
~Channel();
const Channel & operator=(const Channel &);
void addUser(const std::string &);
void removeUser(const std::string &);
void replaceUser(const std::string &, const std::string &);
void addUsers(const std::vector<std::string> &);
inline const std::vector<std::string> & getUsers() const{
return this->users;
}
inline const std::string & getName() const {
return this->name;
}
inline void setTopic(const std::string & topic){
this->topic = topic;
}
inline void setTopicAuthor(const std::string & topicAuthor, uint64_t topicDate){
this->topicAuthor = topicAuthor;
this->topicDate = topicDate;
}
protected:
std::string name;
std::string topic;
std::string topicAuthor;
uint64_t topicDate;
std::vector<std::string> users;
};
// Channel ReferenceCount
typedef Util::ReferenceCount<Channel> ChannelPointer;
class Client : public Chat::Threadable{
public:
Client(const std::string &, int port);
virtual ~Client();
- virtual void connect(const std::string & name = "paintown-test");
+ virtual void connect(const std::string & name = "rtech-test");
virtual void run();
virtual bool hasCommands() const;
virtual Command nextCommand() const;
virtual void sendCommand(const Command &);
virtual void sendCommand(const Command::Type &);
virtual void sendCommand(const Command::Type &, const std::string &);
virtual void sendCommand(const Command::Type &, const std::string &, const std::string &);
virtual void sendCommand(const Command::Type &, const std::string &, const std::string &, const std::string &);
virtual void sendCommand(const Command::Type &, const std::string &, const std::string &, const std::string &, const std::string &);
virtual void setName(const std::string &);
virtual inline const std::string & getName() const {
return this->username;
}
virtual void joinChannel(const std::string &);
virtual void partChannel(const std::string &);
virtual inline ChannelPointer getChannel() const {
if (this->activeChannels.empty()){
return ChannelPointer(NULL);
}
return this->activeChannels[this->currentChannel];
}
virtual inline std::vector< ChannelPointer > & channelList(){
return this->activeChannels;
}
virtual std::string channelListAsString();
virtual unsigned int getChannelIndex(const std::string &);
virtual bool isCurrentChannel(const std::string &);
virtual void setChannel(unsigned int channel);
virtual void nextChannel();
virtual void previousChannel();
virtual void sendMessage(const std::string &);
virtual void sendPong(const Command &);
virtual inline void setMessagesDisabled(bool disabled){
this->disableMessages = disabled;
}
protected:
void removeChannel(const std::string &);
ChannelPointer findChannel(const std::string &);
std::string readMessage();
//! Doesn't do anything to the command just handle some internal changes like username and channel stuff
void checkResponseAndHandle(const Command &);
Network::Socket socket;
std::string previousUsername;
std::string username;
unsigned int previousActiveChannel;
unsigned int currentChannel;
std::vector< ChannelPointer > activeChannels;
std::string hostname;
int port;
bool end;
mutable std::queue< Command > commands;
bool disableMessages;
};
namespace Message{
class EventInterface{
public:
EventInterface();
virtual ~EventInterface();
// Notify by message from local user
virtual void localNotify(const std::string &);
// Notify by command from local user
virtual void localCommand(const std::vector<std::string> &);
// Notify by message from remote
virtual void remoteNotify(const std::string &);
// Notify by command from remote
virtual void remoteCommand(const Command &);
};
class HandlerInterface{
public:
HandlerInterface();
virtual ~HandlerInterface();
typedef void *(*NotifyCallback)(const std::string &);
virtual inline void subscribe(NotifyCallback subscriber){
this->callbacks.push_back(subscriber);
}
virtual inline void subscribe(EventInterface * subscriber){
this->subscribers.push_back(subscriber);
}
protected:
// Callbacks for events and messages
std::vector<NotifyCallback> callbacks;
std::vector<EventInterface *> subscribers;
};
class QueueInterface{
public:
QueueInterface();
virtual ~QueueInterface();
virtual void addMessage(const std::string &) = 0;
class FontWrapper{
public:
FontWrapper();
virtual ~FontWrapper();
virtual int getWidth(const std::string &)=0;
virtual int getHeight()=0;
};
virtual void processMessages(FontWrapper &, int width, int height);
protected:
std::queue<std::string> messages;
std::deque<std::string> buffer;
};
}
// Create a tabbed chatter to implement in games
class ChatInterface: public Message::HandlerInterface{
public:
ChatInterface(const std::string &, int port, const std::string &);
virtual ~ChatInterface();
void act();
void draw(const Graphics::Bitmap &);
void nextChannel();
void previousChannel();
void gotoChannel(const std::string &);
Util::ReferenceCount<Client> getClient();
Util::ReferenceCount<Gui::TabItem> getCurrentTab();
Util::ReferenceCount<Gui::TabItem> getTabByName(const std::string &);
void addMessageToTab(const std::string &);
void addMessageToTab(const std::string &, const std::string &);
inline void setWidthRatio(double ratio){
this->widthRatio = ratio;
}
inline void setHeightRatio(double ratio){
this->heightRatio = ratio;
}
inline Gui::LineEdit & getInputBox() {
return this->inputBox;
}
protected:
void updateDimensions();
void remoteNotify(const std::string &);
void processRemoteCommands();
static void submit(void *);
// Notifications and commands for submit
void localNotify(const std::string &);
void localCommand(const std::vector<std::string> &);
// Update user list
void updateUserList();
void removeUser(const std::string &);
void changeUserName(const std::string &, const std::string &);
Util::ReferenceCount<Client> client;
const std::string & host;
Gui::TabContainer chatBox;
Gui::LineEdit inputBox;
Gui::SimpleList listBox;
double widthRatio;
double heightRatio;
int width;
int height;
int checkWidth;
int checkHeight;
Util::ReferenceCount<Gui::TabItem> serverTab;
// check ctcp reply
std::map<std::string, uint64_t> pingReply;
std::map< std::string, std::vector<std::string> > namesRequest;
};
}// end irc
}
#endif
diff --git a/include/r-tech1/network/network.h b/include/r-tech1/network/network.h
index a958343e..201863de 100644
--- a/include/r-tech1/network/network.h
+++ b/include/r-tech1/network/network.h
@@ -1,137 +1,137 @@
-#ifndef _paintown_network_h
-#define _paintown_network_h
+#ifndef _rtech_network_h
+#define _rtech_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 54da76e5..2fc7feda 100644
--- a/include/r-tech1/parameter.h
+++ b/include/r-tech1/parameter.h
@@ -1,76 +1,76 @@
-#ifndef _paintown_parameter_h
-#define _paintown_parameter_h
+#ifndef _rtech_parameter_h
+#define _rtech_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 f38a5687..8149dcb0 100644
--- a/include/r-tech1/pointer.h
+++ b/include/r-tech1/pointer.h
@@ -1,200 +1,200 @@
-#ifndef _paintown_util_pointer_h
-#define _paintown_util_pointer_h
+#ifndef _rtech_util_pointer_h
+#define _rtech_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 8f523b77..5629e70e 100644
--- a/include/r-tech1/reader.h
+++ b/include/r-tech1/reader.h
@@ -1,26 +1,26 @@
-#ifndef _paintown_reader_h
-#define _paintown_reader_h
+#ifndef _rtech_reader_h
+#define _rtech_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 9116b812..c45b74a5 100644
--- a/include/r-tech1/regex.h
+++ b/include/r-tech1/regex.h
@@ -1,22 +1,22 @@
-#ifndef _paintown_regex_h
-#define _paintown_regex_h
+#ifndef _rtech_regex_h
+#define _rtech_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 007ccc80..430ae620 100644
--- a/include/r-tech1/resource.h
+++ b/include/r-tech1/resource.h
@@ -1,42 +1,42 @@
-#ifndef _paintown_resource_manager_h
-#define _paintown_resource_manager_h
+#ifndef _rtech_resource_manager_h
+#define _rtech_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 0d42ac4a..de43e601 100644
--- a/include/r-tech1/sound/audio.h
+++ b/include/r-tech1/sound/audio.h
@@ -1,58 +1,58 @@
-#ifndef _paintown_audio_h
-#define _paintown_audio_h
+#ifndef _rtech_audio_h
+#define _rtech_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 eae6f5ad..7d80adfc 100644
--- a/include/r-tech1/sound/music-exception.h
+++ b/include/r-tech1/sound/music-exception.h
@@ -1,37 +1,37 @@
-#ifndef _paintown_music_exception_h
-#define _paintown_music_exception_h
+#ifndef _rtech_music_exception_h
+#define _rtech_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 3cc09f99..a60c6d9e 100644
--- a/include/r-tech1/sound/music-player.h
+++ b/include/r-tech1/sound/music-player.h
@@ -1,242 +1,242 @@
-#ifndef _paintown_music_player_h
-#define _paintown_music_player_h
+#ifndef _rtech_music_player_h
+#define _rtech_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 add31c9a..1e13aede 100644
--- a/include/r-tech1/sound/music-renderer.h
+++ b/include/r-tech1/sound/music-renderer.h
@@ -1,58 +1,58 @@
-#ifndef _paintown_music_renderer_h
-#define _paintown_music_renderer_h
+#ifndef _rtech_music_renderer_h
+#define _rtech_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 b2a1379e..bd030c24 100644
--- a/include/r-tech1/sound/music.h
+++ b/include/r-tech1/sound/music.h
@@ -1,65 +1,65 @@
-#ifndef _paintown_music_class_h
-#define _paintown_music_class_h
+#ifndef _rtech_music_class_h
+#define _rtech_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 e7cc098e..7c35519d 100644
--- a/include/r-tech1/sound/sound.h
+++ b/include/r-tech1/sound/sound.h
@@ -1,78 +1,78 @@
-#ifndef _paintown_sound_h
-#define _paintown_sound_h
+#ifndef _rtech_sound_h
+#define _rtech_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 dbf73430..060f6f84 100644
--- a/include/r-tech1/system.h
+++ b/include/r-tech1/system.h
@@ -1,25 +1,25 @@
-#ifndef _paintown_system_h
-#define _paintown_system_h
+#ifndef _rtech_system_h
+#define _rtech_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 e8a7ab42..3dee6307 100644
--- a/include/r-tech1/system/init.h
+++ b/include/r-tech1/system/init.h
@@ -1,11 +1,11 @@
-#ifndef _paintown_system_init_h
-#define _paintown_system_init_h
+#ifndef _rtech_system_init_h
+#define _rtech_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 085eeb79..0fd9ffe2 100644
--- a/include/r-tech1/system/timer.h
+++ b/include/r-tech1/system/timer.h
@@ -1,19 +1,19 @@
-#ifndef _paintown_system_timer_h
-#define _paintown_system_timer_h
+#ifndef _rtech_system_timer_h
+#define _rtech_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 9873421e..8f1688c7 100644
--- a/include/r-tech1/thread.h
+++ b/include/r-tech1/thread.h
@@ -1,298 +1,298 @@
-#ifndef _paintown_thread_h
-#define _paintown_thread_h
+#ifndef _rtech_thread_h
+#define _rtech_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 3eb83ba2..4243c0ed 100644
--- a/include/r-tech1/timer.h
+++ b/include/r-tech1/timer.h
@@ -1,29 +1,29 @@
-#ifndef _paintown_util_timer_h
-#define _paintown_util_timer_h
+#ifndef _rtech_util_timer_h
+#define _rtech_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 7dc80610..88dda804 100644
--- a/include/r-tech1/token.h
+++ b/include/r-tech1/token.h
@@ -1,321 +1,321 @@
-#ifndef _paintown_token_h
-#define _paintown_token_h
+#ifndef _rtech_token_h
+#define _rtech_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 e37f02a5..e4920f3c 100644
--- a/include/r-tech1/token_exception.h
+++ b/include/r-tech1/token_exception.h
@@ -1,29 +1,29 @@
-#ifndef _paintown_token_exception_h
-#define _paintown_token_exception_h
+#ifndef _rtech_token_exception_h
+#define _rtech_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 7bc66cd5..dd925fa4 100644
--- a/include/r-tech1/tokenreader.h
+++ b/include/r-tech1/tokenreader.h
@@ -1,40 +1,40 @@
-#ifndef _paintown_tokenreader_h
-#define _paintown_tokenreader_h
+#ifndef _rtech_tokenreader_h
+#define _rtech_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 1aa5e795..cacae3a9 100644
--- a/include/r-tech1/version.h
+++ b/include/r-tech1/version.h
@@ -1,21 +1,21 @@
-#ifndef _paintown_version_h
-#define _paintown_version_h
+#ifndef _rtech_version_h
+#define _rtech_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/CMakeLists.txt b/src/CMakeLists.txt
index 074d0b3a..964ff2aa 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,104 +1,102 @@
# -------------------------------------------------------
-# util cmake build script for paintown.
+# util cmake build script for r-tech1.
# Written by: juvinious
# Modified by: kazzmir
# -------------------------------------------------------
# -------------------------------------------------------
# Source directories containing all the necessary .cpp files
# -------------------------------------------------------
set(UTIL_SRC
argument.cpp
configuration.cpp
network/network.cpp
network/chat.cpp
network/irc.cpp
token.cpp
resource.cpp
tokenreader.cpp
timedifference.cpp
debug.cpp
timer.cpp
init.cpp
utf.cpp
console.cpp
input/keyboard.cpp
loading.cpp
messages.cpp
graphics/bitmap.cpp
graphics/image.cpp
events.cpp
font.cpp
font_factory.cpp
graphics/fire.cpp
ftalleg.cpp
funcs.cpp
directory.cpp
file-system.cpp
graphics/gradient.cpp
ebox.cpp
regex.cpp
language-string.cpp
thread.cpp
-input/input.cpp
input/text-input.cpp
input/input-manager.cpp
input/input-source.cpp
input/joystick.cpp
input/allegro5/joystick.cpp
xenon/xenon.cpp
libs/lz4/lz4.c
system.cpp
version.cpp
compress.cpp
message-queue.cpp
input/linux_joystick.cpp
exceptions/load_exception.cpp
-windows/funcs.cpp
windows/system.cpp
nacl/module.cpp
nacl/network-system.cpp
exceptions/exception.cpp
menu/actionfactory.cpp
menu/action_speed.cpp
menu/menu.cpp
menu/font-info.cpp
menu/menu_action.cpp
menu/menu_option.cpp
menu/options.cpp
menu/optionfactory.cpp
gui/animation.cpp
gui/box.cpp
gui/container.cpp
gui/context-box.cpp
gui/coordinate.cpp
gui/cutscene.cpp
gui/fadetool.cpp
gui/lineedit.cpp
gui/list.cpp
gui/rectarea.cpp
gui/popup-box.cpp
gui/scroll-list.cpp
gui/select-list.cpp
gui/tab-container.cpp
gui/tabbed-box.cpp
gui/timer.cpp
gui/widget.cpp
sound/sound.cpp
sound/audio.cpp
sound/music-player.cpp
sound/music-renderer.cpp
sound/music.cpp
system/timer.cpp
system/allegro5/timer.cpp
system/allegro5/init.cpp)
# -------------------------------------------------------
# Include directory
# -------------------------------------------------------
#include_directories(include include/internal)
# -------------------------------------------------------
# module
# -------------------------------------------------------
add_library (util_module ${UTIL_SRC})
diff --git a/src/debug.cpp b/src/debug.cpp
index 17dc26ef..fadf790a 100644
--- a/src/debug.cpp
+++ b/src/debug.cpp
@@ -1,431 +1,431 @@
#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, "paintown", __VA_ARGS__)
+#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;
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");
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;
}
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/funcs.cpp b/src/funcs.cpp
index 5887efda..7118a42f 100644
--- a/src/funcs.cpp
+++ b/src/funcs.cpp
@@ -1,387 +1,375 @@
#ifdef USE_ALLEGRO
#include <allegro.h>
#endif
#ifdef USE_SDL
#include <SDL.h>
#endif
#ifdef USE_ALLEGRO5
#include <allegro5/allegro.h>
#endif
#include "r-tech1/funcs.h"
#include "r-tech1/debug.h"
#include <vector>
#include <string>
#include <string.h>
#include <algorithm>
#include "r-tech1/file-system.h"
#include "r-tech1/graphics/bitmap.h"
#include "r-tech1/font.h"
#include "r-tech1/init.h"
#include <sstream>
#include "r-tech1/file-system.h"
#include <math.h>
#ifndef USE_ALLEGRO
/* FIXME: move this to the filesystem module */
#include "libs/sfl/sfl.h"
#include "libs/sfl/sflfile.h"
#endif
#ifndef WINDOWS
#include <unistd.h>
#endif
#ifdef max
#undef max
#endif
#ifdef min
#undef min
#endif
using namespace std;
/* remove this once cmake and scons properly set DATA_PATH */
#ifndef DATA_PATH
#define DATA_PATH "data"
#endif
/* the build system should define DATA_PATH */
static string dataPath = DATA_PATH;
const double Util::pi = 3.14159265358979323846;
double Util::radians(double degree){
return degree * pi / 180.0;
}
double Util::degrees(double radians){
return radians * 180.0 / pi;
}
/*
inline int rnd( int q ){
if ( q <= 0 ) return 0;
return (int)( rand() % q );
}
*/
int Util::max(int a, int b){
if (a>b){
return a;
}
return b;
}
double Util::min(double a, double b){
if (a < b){
return a;
}
return b;
}
double Util::max(double a, double b){
if (a > b){
return a;
}
return b;
}
/*
int Util::min(int a, int b){
if (a<b){
return a;
}
return b;
}
*/
int Util::clamp(int value, int min, int max){
return Util::min(Util::max(value, min), max);
}
double Util::clamp(double value, double min, double max){
return Util::min(Util::max(value, min), max);
}
int Util::rnd( int q, int min, int range ){
return q - min + rnd( range );
}
int Util::rnd( int min, int max ){
return rnd( max - min ) + min;
}
/* sleep for `x' milliseconds */
void Util::rest( int x ){
#ifdef USE_ALLEGRO
::rest(x);
#endif
#ifdef USE_SDL
SDL_Delay(x);
#endif
#ifdef USE_ALLEGRO5
al_rest((double) x / 1000.0);
#endif
}
void Util::restSeconds(double x){
Util::rest((int)(x * 1000));
}
#if 0
bool Util::checkVersion(int version){
if (version == Global::getVersion()){
return true;
}
/* when an incompatible version is made, add a check here, like
* version < getVersion(3, 5)
* would mean any client below version 3.5 is incompatible.
*
* assume versions of client's greater than ourself is compatible, but
* this may not be true. There is no way to check this.
*/
if (version < 0){
return false;
}
return true;
}
#endif
void Util::setDataPath( const string & str ){
dataPath = str;
}
Filesystem::AbsolutePath Util::getDataPath2(){
return Filesystem::AbsolutePath(dataPath + "/");
}
/* FIXME: remove this method */
bool Util::exists( const string & file ){
return Storage::instance().exists(Filesystem::AbsolutePath(file));
/*
#ifdef USE_ALLEGRO
return ::exists(file.c_str()) != 0;
#else
return file_exists(file.c_str());
#endif
*/
}
/*
vector<Filesystem::AbsolutePath> Util::getFiles(const Filesystem::AbsolutePath & dataPath, const string & find){
return Filesystem::getFiles(dataPath, find);
}
*/
string Util::trim(const std::string & str){
string s;
size_t startpos = str.find_first_not_of(" \t");
size_t endpos = str.find_last_not_of(" \t");
// if all spaces or empty return an empty string
if ((string::npos == startpos) ||
(string::npos == endpos)){
return "";
} else {
return str.substr(startpos, endpos-startpos+1);
}
return str;
}
/* makes the first letter of a string upper case */
string Util::upcase(std::string str){
if ( str.length() > 0 && (str[0] >= 'a' && str[0] <= 'z') ){
str[0] = str[0] - 'a' + 'A';
}
return str;
}
static int lowerCase(int c){
return tolower(c);
}
static int upperCase(int c){
return toupper(c);
}
string Util::upperCaseAll(std::string str){
std::transform(str.begin(), str.end(), str.begin(), upperCase);
return str;
}
string Util::lowerCaseAll(std::string str){
std::transform(str.begin(), str.end(), str.begin(), lowerCase);
/*
for (unsigned int i = 0; i < str.length(); i++){
if (str[0] >= 'A' && str[0] <= 'Z'){
str[0] = str[0] - 'A' + 'a';
}
}
*/
return str;
}
// Split string
std::vector<std::string> Util::splitString(std::string str, char splitter){
std::vector<std::string> strings;
size_t next = str.find(splitter);
while (next != std::string::npos){
strings.push_back(str.substr(0, next));
str = str.substr(next+1);
next = str.find(splitter);
}
if (str != ""){
strings.push_back(str);
}
return strings;
}
// Join strings
std::string Util::joinStrings(const std::vector< std::string > & message, unsigned int start){
std::string all;
for (unsigned int i = start; i < message.size(); ++i){
all+=message.at(i) + (i < message.size()-1 ? " " : "");
}
return all;
}
/*Gets the minimum of three values*/
static int minimum(int a,int b,int c){
int min=a;
if(b<min)
min=b;
if(c<min)
min=c;
return min;
}
/* Compute levenshtein distance between s and t
* from: http://www.merriampark.com/ldc.htm
*/
static int levenshtein_distance(const char *s, const char *t){
//Step 1
int k,i,j,n,m,cost,distance;
int * d;
n=strlen(s);
m=strlen(t);
if(n!=0&&m!=0){
d = (int*) malloc((sizeof(int))*(m+1)*(n+1));
m++;
n++;
//Step 2
for(k=0;k<n;k++)
d[k]=k;
for(k=0;k<m;k++)
d[k*n]=k;
//Step 3 and 4
for(i=1;i<n;i++)
for(j=1;j<m;j++)
{
//Step 5
if(s[i-1]==t[j-1])
cost=0;
else
cost=1;
//Step 6
d[j*n+i]=minimum(d[(j-1)*n+i]+1,d[j*n+i-1]+1,d[(j-1)*n+i-1]+cost);
}
distance=d[n*m-1];
free(d);
return distance;
} else {
return -1; //a negative return value means that one or both strings are empty.
}
}
int Util::levenshtein(const std::string & str1, const std::string & str2){
return levenshtein_distance(str1.c_str(), str2.c_str());
}
void Util::limitPrintf(char * buffer, int size, const char * format, va_list args){
#ifdef USE_ALLEGRO
uvszprintf(buffer, size, format, args);
#else
vsnprintf(buffer, size, format, args);
#endif
}
-/*
-#ifndef WINDOWS
-int Util::getPipe(int files[2]){
-#ifdef PS3
- return 0;
-#else
- return pipe(files);
-#endif
-}
-#endif
-*/
-
void Util::showError(const Graphics::Bitmap & screen, const Exception::Base & exception, const string & info){
// screen.BlitFromScreen(0, 0);
Graphics::Bitmap error(screen.getWidth() - 100, screen.getHeight() - 100);
error.fill(Graphics::darken(Graphics::makeColor(160, 0, 0), 3));
error.border(1, 2, Graphics::makeColor(240, 0, 0));
const Font & font = Font::getDefaultFont(17, 17);
int y = 10;
std::ostringstream out;
out << info;
out << " " << exception.getTrace();
Global::debug(0) << out.str() << std::endl;
font.printfWrap(10, 10, Graphics::makeColor(240, 240, 240), error, error.getWidth() - 20, out.str(), 0);
Graphics::Bitmap::transBlender(0, 0, 0, 220);
error.translucent().draw(50, 50, screen);
screen.BlitToScreen();
}
void Util::showError(const Exception::Base & exception, const std::string & info){
Graphics::Bitmap screen(*Graphics::screenParameter.current());
showError(screen, exception, info);
}
static double twoDigits(double x){
return (int) (x * 100) / 100.0;
}
string Util::niceSize(unsigned long size){
const char sizes[] = {'b', 'k', 'm', 'g', 't'};
double real = size;
for (unsigned int i = 0; i < sizeof(sizes) / sizeof(const char); i++){
if (real > 1024){
real /= 1024.0;
} else {
ostringstream in;
in << twoDigits(real) << sizes[i];
return in.str();
}
}
ostringstream in;
in << twoDigits(real) << "t";
return in.str();
}
std::string Util::join(const std::vector<std::string> & list, const std::string & middle){
ostringstream out;
bool first = true;
for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); it++){
if (!first){
out << middle;
}
out << *it;
first = false;
}
return out.str();
}
double Util::distance(double x1, double y1, double x2, double y2){
double xs = x1 - x2;
double ys = y1 - y2;
return sqrt(xs * xs + ys * ys);
}
diff --git a/src/input/input.cpp b/src/input/input.cpp
deleted file mode 100644
index ef4af1ca..00000000
--- a/src/input/input.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
-#include "input.h"
-#include "util/configuration.h"
-#include "paintown-engine/object/object.h"
-#include <vector>
-
-using namespace std;
-
-static Input::PaintownInput convertKey(const Configuration & configuration, const int facing, const int key){
- if (key == configuration.getRight()){
- switch (facing){
- case Paintown::Object::FACING_LEFT : return Input::Back;
- case Paintown::Object::FACING_RIGHT : return Input::Forward;
- }
- } else if (key == configuration.getLeft()){
- switch (facing){
- case Paintown::Object::FACING_LEFT : return Input::Forward;
- case Paintown::Object::FACING_RIGHT : return Input::Back;
- }
- } else if (key == configuration.getJump()){
- return Input::Jump;
- } else if (key == configuration.getUp()){
- return Input::Up;
- } else if (key == configuration.getDown()){
- return Input::Down;
- } else if (key == configuration.getAttack1()){
- return Input::Attack1;
- } else if (key == configuration.getAttack2()){
- return Input::Attack2;
- } else if (key == configuration.getAttack3()){
- return Input::Attack3;
- }
-
- return Input::Unknown;
-}
-
-vector<Input::PaintownInput> Input::convertKeyboard(const Configuration & configuration, int facing, const vector<int> & keys){
- vector<Input::PaintownInput> all;
-
- for (vector<int>::const_iterator it = keys.begin(); it != keys.end(); it++){
- Input::PaintownInput in = convertKey(configuration, facing, *it);
- if (in != Unknown){
- all.push_back(in);
- }
-
- }
-
- return all;
-}
-*/
diff --git a/src/libs/7z/CMakeLists.txt b/src/libs/7z/CMakeLists.txt
index 5b43992d..5e3a7981 100644
--- a/src/libs/7z/CMakeLists.txt
+++ b/src/libs/7z/CMakeLists.txt
@@ -1,35 +1,35 @@
# -------------------------------------------------------
-# util cmake build script for paintown.
+# util cmake build script for r-tech1.
# Written by: juvinious
# Modified by: kazzmir
# -------------------------------------------------------
# -------------------------------------------------------
# Source directories containing all the necessary .cpp files
# -------------------------------------------------------
set(x7Z_SRC
7zAlloc.c
7zBuf.c
7zBuf2.c
7zCrc.c
7zCrcOpt.c
7zDec.c
7zIn.c
CpuArch.c
LzmaDec.c
Lzma2Dec.c
Bra.c
Bra86.c
Bcj2.c
7zFile.c
7zStream.c)
# -------------------------------------------------------
# Include directory
# -------------------------------------------------------
#include_directories(include include/internal)
# -------------------------------------------------------
# module
# -------------------------------------------------------
add_library (x7z_module ${x7Z_SRC})
diff --git a/src/libs/dumb/CMakeLists.txt b/src/libs/dumb/CMakeLists.txt
index 431e3ee5..abf1b825 100644
--- a/src/libs/dumb/CMakeLists.txt
+++ b/src/libs/dumb/CMakeLists.txt
@@ -1,92 +1,92 @@
# -------------------------------------------------------
-# dumb cmake build script for paintown.
+# dumb cmake build script for r-tech1.
# Written by: juvinious
# -------------------------------------------------------
# -------------------------------------------------------
# Set some specific stuff for dumb
# -------------------------------------------------------
if(NOT MSVC)
set(CFLAGS "-W -O2 -Wwrite-strings -Wstrict-prototypes -Wall -funroll-loops -Wmissing-declarations -fomit-frame-pointer -Wno-missing-declarations")
else(NOT MSVC)
set(CFLAGS "-O2")
endif(NOT MSVC)
remove_definitions(${CXXFLAGS})
add_definitions(${CFLAGS})
if(MSVC)
add_definitions("/DDUMB_DECLARE_DEPRECATED")
else(MSVC)
add_definitions(-DDUMB_DECLARE_DEPRECATED)
endif(MSVC)
# -------------------------------------------------------
# Source directories containing all the necessary .cpp files
# -------------------------------------------------------
set(DUMB_SRC
src/it/itorder.c
src/it/xmeffect.c
src/it/itrender.c
src/it/itread2.c
src/it/itunload.c
src/it/loadmod.c
src/it/loads3m.c
src/it/loadxm2.c
src/it/itload2.c
src/it/readmod2.c
src/it/reads3m2.c
src/it/loadmod2.c
src/it/loadxm.c
src/it/loads3m2.c
src/it/itload.c
src/it/itmisc.c
src/it/itread.c
src/it/readxm.c
src/it/readmod.c
src/it/reads3m.c
src/it/readxm2.c
src/core/makeduh.c
src/core/unload.c
src/core/loadduh.c
src/core/rawsig.c
src/core/rendduh.c
src/core/rendsig.c
src/core/duhlen.c
src/core/duhtag.c
src/core/atexit.c
src/core/readduh.c
src/core/register.c
src/core/dumbfile.c
src/helpers/sampbuf.c
src/helpers/stdfile.c
src/helpers/resample.inc
src/helpers/clickrem.c
src/helpers/silence.c
src/helpers/resamp2.inc
src/helpers/resamp3.inc
src/helpers/memfile.c
src/helpers/resample.c
src/allegro/datit.c
src/allegro/datxm.c
src/allegro/datduh.c
src/allegro/datitq.c
src/allegro/datmod.c
src/allegro/dats3m.c
src/allegro/datxmq.c
src/allegro/datmodq.c
src/allegro/dats3mq.c
src/allegro/datunld.c
src/allegro/alplay.c
src/allegro/packfile.c)
# -------------------------------------------------------
# Include directory
# -------------------------------------------------------
include_directories(include include/internal)
# -------------------------------------------------------
# module
# -------------------------------------------------------
add_library (dumb_module ${DUMB_SRC})
diff --git a/src/libs/hawknl/CMakeLists.txt b/src/libs/hawknl/CMakeLists.txt
index 7928162e..086918a1 100644
--- a/src/libs/hawknl/CMakeLists.txt
+++ b/src/libs/hawknl/CMakeLists.txt
@@ -1,45 +1,45 @@
# -------------------------------------------------------
-# hawknl cmake build script for paintown.
+# hawknl cmake build script for r-tech1.
# Written by: juvinious
# -------------------------------------------------------
# -------------------------------------------------------
# Set some specific stuff for hawknl
# -------------------------------------------------------
if(NOT MSVC)
set(CFLAGS "-W -O2 -Wwrite-strings -Wstrict-prototypes -Wall -funroll-loops -Wmissing-declarations -fomit-frame-pointer -Wno-missing-declarations")
else(NOT MSVC)
set(CFLAGS "-O2")
endif(NOT MSVC)
remove_definitions(${CXXFLAGS})
add_definitions(${CFLAGS})
# -------------------------------------------------------
# Source directories containing all the necessary .cpp files
# -------------------------------------------------------
set(SRC
src/crc.cpp
src/err.cpp
src/errorstr.cpp
src/group.cpp
src/ipx.cpp
src/loopback.cpp
src/nl.cpp
src/nltime.cpp
src/sock.cpp)
#src/htcondition.cpp
#src/hthread.cpp
#src/htmutex.cpp
# -------------------------------------------------------
# Include directory
# -------------------------------------------------------
#include_directories(include hawknl)
# -------------------------------------------------------
# module
# -------------------------------------------------------
add_library (hawknl_module ${SRC})
diff --git a/src/libs/sfl/CMakeLists.txt b/src/libs/sfl/CMakeLists.txt
index a7d0b51d..d0d0796c 100644
--- a/src/libs/sfl/CMakeLists.txt
+++ b/src/libs/sfl/CMakeLists.txt
@@ -1,74 +1,74 @@
# -------------------------------------------------------
-# SFL cmake build script for paintown.
+# SFL cmake build script for r-tech1.
# Written by: juvinious
# -------------------------------------------------------
# -------------------------------------------------------
# Set some specific stuff for hawknl
# -------------------------------------------------------
if(NOT MSVC)
set(CFLAGS "-W -O2 -Wwrite-strings -Wstrict-prototypes -Wall -funroll-loops -Wmissing-declarations -fomit-frame-pointer -Wno-missing-declarations")
else(NOT MSVC)
set(CFLAGS "-O2")
endif(NOT MSVC)
remove_definitions(${CXXFLAGS})
add_definitions(${CFLAGS})
# -------------------------------------------------------
# Source directories containing all the necessary .cpp files
# -------------------------------------------------------
set(SRC
sflbits.c
sflcomp.c
sflcons.c
sflconv.c
sflcryp.c
sflcvbs.c
sflcvdp.c
sflcvds.c
sflcvns.c
sflcvsb.c
sflcvsd.c
sflcvsn.c
sflcvtp.c
sflcvts.c
sfldbio.c
sfldir.c
sflenv.c
sflexdr.c
sflfile.c
sflfind.c
sflfort.c
sflhttp.c
sflini.c
sfllang.c
sfllbuf.c
sfllist.c
sflmath.c
sflmem.c
sflmesg.c
sflmime.c
sflnode.c
sflprint.c
sflslot.c
sflstr.c
sflsymb.c
sflsyst.c
sfltok.c
sfltree.c
sfltron.c
sfluid.c
sflxml.c
sfldate.c)
# -------------------------------------------------------
# Include directory
# -------------------------------------------------------
include_directories(include ./)
# -------------------------------------------------------
# module
# -------------------------------------------------------
add_library (sfl_module ${SRC})
diff --git a/src/menu/options.cpp b/src/menu/options.cpp
index 530ceb95..56879cce 100644
--- a/src/menu/options.cpp
+++ b/src/menu/options.cpp
@@ -1,3128 +1,3128 @@
#include "r-tech1/graphics/bitmap.h"
#include "r-tech1/menu/options.h"
#include "r-tech1/token.h"
#include "r-tech1/input/input-source.h"
#include "r-tech1/parameter.h"
#include "r-tech1/tokenreader.h"
#include "r-tech1/menu/menu.h"
#include "r-tech1/configuration.h"
#include "r-tech1/exceptions/load_exception.h"
#include "r-tech1/menu/menu-exception.h"
#include "r-tech1/init.h"
#include "r-tech1/events.h"
#include "r-tech1/version.h"
#include "r-tech1/menu/optionfactory.h"
#include "r-tech1/sound/music.h"
#include "r-tech1/input/keyboard.h"
#include "r-tech1/funcs.h"
#include "r-tech1/file-system.h"
#include "r-tech1/system.h"
#include "r-tech1/font_factory.h"
#include "r-tech1/exceptions/shutdown_exception.h"
#include "r-tech1/exceptions/exception.h"
#include "r-tech1/font.h"
#include "r-tech1/gui/box.h"
#include "r-tech1/thread.h"
#include "r-tech1/loading.h"
#include "r-tech1/input/input-map.h"
#include "r-tech1/input/input-manager.h"
#include <sstream>
#include <algorithm>
#include <time.h>
#include <math.h>
using namespace std;
using namespace Gui;
/* true if the arguments passed in match todays date.
* pass 0 for any argument that you don't care about (it will match any date)
*/
static bool todaysDate(int month, int day, int year){
time_t result = time(NULL);
struct tm * local = localtime(&result);
return (month == 0 || month == (local->tm_mon + 1)) &&
(day == 0 || day == local->tm_mday) &&
(year == 0 || year == local->tm_year + 1900);
}
static bool jonBirthday(){
return todaysDate(3, 25, 0);
}
static bool miguelBirthday(){
return todaysDate(8, 11, 0);
}
OptionCredits::Block::Block(const std::string & title):
title(title),
titleColorOverride(false),
titleColor(Graphics::makeColor(0,255,255)),
colorOverride(false),
color(Graphics::makeColor(255,255,255)),
spacing(0){
}
OptionCredits::Block::Block(const Token * token):
titleColorOverride(false),
titleColor(Graphics::makeColor(0,255,255)),
colorOverride(false),
color(Graphics::makeColor(255,255,255)),
topWidth(0),
topHeight(0),
bottomWidth(0),
bottomHeight(0),
spacing(0){
if ( *token != "block" ){
throw LoadException(__FILE__, __LINE__, "Not a credit block");
}
TokenView view = token->view();
while (view.hasMore()){
std::string match;
try{
const Token * tok;
view >> tok;
if ( *tok == "title" ) {
tok->view() >> title;
} else if (*tok == "credit"){
std::string credit;
tok->view() >> credit;
credits.push_back(credit);
} else if ( *tok == "titlecolor" ) {
try{
int r,b,g;
tok->view() >> r >> g >> b;
titleColor = Graphics::makeColor( r, g, b );
titleColorOverride = true;
} catch (const TokenException & ex){
}
} else if ( *tok == "color" ) {
try{
int r,b,g;
tok->view() >> r >> g >> b;
color = Graphics::makeColor( r, g, b );
colorOverride = true;
} catch (const TokenException & ex){
}
} else if ( *tok == "animation" ) {
TokenView animView = tok->view();
while (animView.hasMore()){
const Token * animTok;
animView >> animTok;
if (*animTok == "top"){
tok->match("_/width", topWidth);
tok->match("_/height", topHeight);
topAnimation = Util::ReferenceCount<Gui::Animation>(new Animation(tok));
} else if (*animTok == "bottom"){
tok->match("_/width", bottomWidth);
tok->match("_/height", bottomHeight);
bottomAnimation = Util::ReferenceCount<Gui::Animation>(new Animation(tok));
}
}
} else if (*tok == "spacing"){
tok->view() >> spacing;
} else {
Global::debug( 3 ) <<"Unhandled Credit Block attribute: "<<endl;
if (Global::getDebug() >= 3){
tok->print(" ");
}
}
} catch ( const TokenException & ex ) {
throw LoadException(__FILE__, __LINE__, ex, "Credit Block parse error");
} catch ( const LoadException & ex ) {
throw ex;
}
}
}
OptionCredits::Block::Block(const OptionCredits::Block & copy):
title(copy.title),
credits(copy.credits),
titleColorOverride(copy.titleColorOverride),
titleColor(copy.titleColor),
colorOverride(copy.colorOverride),
color(copy.color),
topAnimation(copy.topAnimation),
topWidth(copy.topWidth),
topHeight(copy.topHeight),
bottomAnimation(copy.bottomAnimation),
bottomWidth(copy.bottomWidth),
bottomHeight(copy.bottomHeight),
spacing(copy.spacing){
}
OptionCredits::Block::~Block(){
}
const OptionCredits::Block & OptionCredits::Block::operator=(const OptionCredits::Block & copy){
title = copy.title;
credits = copy.credits;
titleColor = copy.titleColor;
titleColorOverride = copy.titleColorOverride;
color = copy.color;
colorOverride = copy.colorOverride;
topAnimation = copy.topAnimation;
topWidth =copy.topWidth;
topHeight = copy.topHeight;
bottomAnimation = copy.bottomAnimation;
bottomWidth = copy.bottomWidth;
bottomHeight = copy.bottomHeight;
spacing = copy.spacing;
return *this;
}
void OptionCredits::Block::addCredit(const std::string & credit){
credits.push_back(credit);
}
void OptionCredits::Block::act(){
// Top animation
if (topAnimation != NULL){
topAnimation->act();
}
// Bottom animation
if (bottomAnimation != NULL){
bottomAnimation->act();
}
}
int OptionCredits::Block::print(int x, int y, Graphics::Color defaultTitleColor, Graphics::Color defaultColor, const Font & font, const Graphics::Bitmap & work, const Justification & justification) const {
int currentY = y;
// Top animation
if (topAnimation != NULL){
int xmod = 0;
switch (justification){
default:
case Left:
xmod = 0;
break;
case Center:
xmod = topWidth/2;
break;
case Right:
xmod = topWidth;
break;
}
// FIXME temporary solution
const Graphics::Bitmap temp(topWidth, topHeight);
//topAnimation->draw(x - xmod, y, topWidth, topHeight, work);
topAnimation->draw(0, 0, topWidth, topHeight, temp);
temp.translucent().draw(x-xmod, y, work);
currentY += topHeight;
}
if (!title.empty()){
int xmod = 0;
switch (justification){
default:
case Left:
xmod = 0;
break;
case Center:
xmod = font.textLength(title.c_str())/2;
break;
case Right:
xmod = font.textLength(title.c_str());
break;
}
font.printf(x - xmod, currentY, (titleColorOverride ? titleColor : defaultTitleColor), work, title, 0);
currentY += font.getHeight();
}
for (std::vector<std::string>::const_iterator i = credits.begin(); i != credits.end(); ++i){
const std::string & credit = *i;
int xmod = 0;
switch (justification){
default:
case Left:
xmod = 0;
break;
case Center:
xmod = font.textLength(credit.c_str())/2;
break;
case Right:
xmod = font.textLength(credit.c_str());
break;
}
font.printf(x - xmod, currentY, (colorOverride ? color : defaultColor), work, credit, 0);
currentY += font.getHeight();
}
// Bottom animation
if (bottomAnimation != NULL){
int xmod = 0;
switch (justification){
default:
case Left:
xmod = 0;
break;
case Center:
xmod = bottomWidth/2;
break;
case Right:
xmod = bottomWidth;
break;
}
// FIXME temporary solution
const Graphics::Bitmap temp(topWidth, topHeight);
//bottomAnimation->draw(x - xmod, y, bottomWidth, bottomHeight, work);
bottomAnimation->draw(0, 0, bottomWidth, bottomHeight, temp);
temp.translucent().draw(x-xmod, y, work);
currentY += bottomHeight;
}
currentY += font.getHeight() + spacing;
return currentY;
}
const int OptionCredits::Block::size(const Font & font) const{
// Counts title and space in between
int total = 0;
if (topAnimation != NULL){
total += topHeight;
}
if (!title.empty()){
total+= font.getHeight();
}
total += credits.size() * font.getHeight();
if (bottomAnimation != NULL){
total += bottomHeight;
}
total += font.getHeight();
total += spacing;
return total;
}
OptionCredits::Sequence::Sequence(const Token * token):
type(Primary),
x(0),
y(0),
startx(0),
endx(0),
starty(0),
endy(0),
ticks(0),
duration(250),
speed(0),
alpha(0),
alphaMultiplier(0),
justification(Block::Center),
current(0),
done(false),
creditLength(0){
if ( *token != "sequence" ){
throw LoadException(__FILE__, __LINE__, "Not a credit sequence");
}
TokenView view = token->view();
while (view.hasMore()){
std::string match;
try{
const Token * tok;
view >> tok;
if (*tok == "type"){
std::string sequenceType;
tok->view() >> sequenceType;
if (sequenceType == "roll"){
type = Roll;
} else if (sequenceType == "primary"){
type = Primary;
}
} else if (*tok == "start-x"){
tok->view() >> startx;
} else if (*tok == "end-x"){
tok->view() >> endx;
} else if (*tok == "start-y"){
tok->view() >> starty;
} else if (*tok == "end-y"){
tok->view() >> endy;
} else if (*tok == "duration"){
tok->view() >> duration;
} else if (*tok == "speed"){
tok->view() >> speed;
} else if (*tok == "alpha-multiplier"){
tok->view() >> alphaMultiplier;
} else if ( *tok == "justification" ) {
std::string justify;
tok->view() >> justify;
if (justify == "left"){
justification = Block::Left;
} else if (justify == "center"){
justification = Block::Center;
} else if (justify == "right"){
justification = Block::Right;
}
} else if (*tok == "block"){
credits.push_back(Block(tok));
} else {
Global::debug( 3 ) <<"Unhandled Credit Sequence attribute: "<<endl;
if (Global::getDebug() >= 3){
tok->print(" ");
}
}
} catch ( const TokenException & ex ) {
throw LoadException(__FILE__, __LINE__, ex, "Credit Sequence parse error");
} catch ( const LoadException & ex ) {
throw ex;
}
}
// Initial
reset();
for (std::vector<OptionCredits::Block>::const_iterator i = credits.begin(); i != credits.end(); ++i){
const OptionCredits::Block & block = *i;
creditLength += block.size(Menu::menuFontParameter.current()->get());
}
}
OptionCredits::Sequence::Sequence(const Sequence & copy):
type(copy.type),
x(copy.x),
y(copy.y),
startx(copy.startx),
endx(copy.endx),
starty(copy.starty),
endy(copy.endy),
ticks(copy.ticks),
duration(copy.duration),
speed(copy.speed),
alpha(copy.alpha),
alphaMultiplier(copy.alphaMultiplier),
justification(copy.justification),
credits(copy.credits),
current(copy.current),
done(false),
creditLength(copy.creditLength){
}
OptionCredits::Sequence::~Sequence(){
}
const OptionCredits::Sequence & OptionCredits::Sequence::operator=(const OptionCredits::Sequence & copy){
type = copy.type;
x = copy.x;
y = copy.y;
startx = copy.startx;
endx = copy.endx;
starty = copy.starty;
endy = copy.endy;
ticks = copy.ticks;
duration = copy.duration;
speed = copy.speed;
alpha = copy.alpha;
alphaMultiplier = copy.alphaMultiplier;
justification = copy.justification;
credits = copy.credits;
current = copy.current;
done = false;
creditLength = copy.creditLength;
return *this;
}
static int alphaClamp(int x, double multiplier){
int clamp = x * multiplier;
if (clamp < 0){
clamp = 0;
} else if (clamp > 255){
clamp = 255;
}
return clamp;
}
void OptionCredits::Sequence::act(){
if (!done && !credits.empty()){
if (type == Roll){
y += speed;
if (starty > endy){
if ((y + (creditLength * 1.1)) < endy){
done = true;
}
} else if (starty < endy){
if ((y * 1.1) > endy){
done = true;
}
}
} else if (type == Primary){
credits[current].act();
if (startx != endx){
x += speed;
if (startx > endx){
const double midpoint = (startx+endx)/2;
const int mid = x > midpoint ? startx -x : x - endx;
alpha = alphaClamp(mid, alphaMultiplier);
if (x < endx){
next();
}
} else if (startx < endx){
const double midpoint = (startx+endx)/2;
const int mid = x < midpoint ? x - startx : endx - x;
alpha = alphaClamp(mid, alphaMultiplier);
//Global::debug(0) << "alpha: " << alpha << " midpoint: " << midpoint << " mid: " << mid << std::endl;
if (x > endx){
next();
}
}
} else {
const double midpoint = duration/2;
const int mid = ticks < midpoint ? ticks : duration - ticks;
alpha = alphaClamp(mid, alphaMultiplier);
ticks++;
if (ticks >= duration){
ticks = 0;
next();
}
}
}
}
}
void OptionCredits::Sequence::draw(Graphics::Color title, Graphics::Color color, const Graphics::Bitmap & work){
if (!done && !credits.empty()){
if (type == Roll){
int rollY = (int) y;
for (std::vector<OptionCredits::Block>::const_iterator i = credits.begin(); i != credits.end(); ++i){
const OptionCredits::Block & block = *i;
rollY = block.print(x, rollY, title, color, Menu::menuFontParameter.current()->get(), work, justification);
}
} else if (type == Primary){
Graphics::Bitmap::transBlender(0, 0, 0, alpha);
credits[current].print(x, y, title, color, Menu::menuFontParameter.current()->get(), work.translucent(), justification);
}
}
}
void OptionCredits::Sequence::reset(){
done = false;
current = 0;
ticks = 0;
if (!credits.empty()){
if (type == Roll){
x = startx;
y = starty;
} else if (type == Primary){
x = startx;
y = starty - (credits[current].size(Menu::menuFontParameter.current()->get())/2);
}
}
}
void OptionCredits::Sequence::next(){
if (type == Primary){
if (current < credits.size()){
current++;
if (current == credits.size()){
done = true;
} else {
x = startx;
y = starty - (credits[current].size(Menu::menuFontParameter.current()->get())/2);
}
}
}
}
static std::string defaultPositions(){
const int width = Configuration::getScreenWidth();
const int height = Configuration::getScreenHeight();
std::ostringstream out;
out << "(start-x " << width/2.3 << ") (end-x " << width/1.8 << ") (start-y " << height/2 << ") ";
//out << "(start-x " << width/2 << ") (end-x " << width/2 << ") (start-y " << height/2 << ") (duration 250) ";
return out.str();
}
OptionCredits::OptionCredits(const Gui::ContextBox & parent, const Token * token):
MenuOption(parent, token),
creditsContext(new Menu::Context()),
music(""),
color(Graphics::makeColor(255,255,255)),
title(Graphics::makeColor(0,255,255)),
clearColor(Graphics::makeColor(0,0,0)){
std::string defaultSequence = "(sequence (type primary) (speed 0.3) (alpha-multiplier 20) (justification center) " + defaultPositions();
/* Always */
if (jonBirthday()){
defaultSequence += "(block (title \"Happy birthday, Jon!\"))";
}
if (miguelBirthday()){
defaultSequence += "(block (title \"Happy birthday, Miguel!\"))";
}
if (Storage::instance().exists(Filesystem::RelativePath("sprites/paintown.png"))){
defaultSequence += "(block (animation (top) (width 350) (height 65) (image 0 \"sprites/paintown.png\") (frame (image 0) (time -1))) (credit \"Version " + Version::getVersionString() + "\"))";
} else {
- defaultSequence += "(block (title \"PAINTOWN\") (credit \"Version " + Version::getVersionString() + "\"))";
+ defaultSequence += "(block (title \"R-Tech1\") (credit \"Version " + Version::getVersionString() + "\"))";
}
defaultSequence += "(block (title \"Programming\") (credit \"Jon Rafkind\") (credit \"Miguel Gavidia\"))";
defaultSequence += "(block (title \"Level design\") (credit \"Jon Rafkind\") (credit \"Miguel Gavidia\"))";
defaultSequence += "(block (title \"Contact\") (credit \"Website: http://paintown.org\") (credit \"Email: jon@rafkind.com\")))";
TokenReader reader;
Sequence sequence(reader.readTokenFromString(defaultSequence));
sequences.push_back(sequence);
//Global::debug(0) << defaultSequence << std::endl;
if ( *token != "credits" ){
throw LoadException(__FILE__, __LINE__, "Not a credit menu");
}
readName(token);
TokenView view = token->view();
// NOTE Use this to handle legacy additional blocks for the time being
Block legacyAdditional("");
bool additionalTitle = true;
while (view.hasMore()){
try{
const Token * tok;
view >> tok;
if ( *tok == "music" ) {
/* Set music for credits */
tok->view() >> music;
} else if ( *tok == "background" ) {
/* Create an image and push it back on to vector */
std::string temp;
tok->view() >> temp;
creditsContext->addBackground(temp);
} else if ( *tok == "anim" || *tok == "animation" ){
creditsContext->addBackground(tok);
} else if ( *tok == "additional" ) {
std::string str;
TokenView additionalView = tok->view();
while (additionalView.hasMore()){
additionalView >> str;
if (additionalTitle){
legacyAdditional = Block(str);
additionalTitle = false;
} else {
legacyAdditional.addCredit(str);
}
}
} else if (*tok == "sequence"){
sequences.push_back(OptionCredits::Sequence(tok));
} else if ( *tok == "titlecolor" ) {
int r,b,g;
tok->view() >> r >> g >> b;
title = Graphics::makeColor( r, g, b );
} else if ( *tok == "color" ) {
int r,b,g;
tok->view() >> r >> g >> b;
color = Graphics::makeColor( r, g, b );
} else if ( *tok == "clear-color" ) {
int r,b,g;
tok->view() >> r >> g >> b;
clearColor = Graphics::makeColor( r, g, b );
} else {
Global::debug( 3 ) <<"Unhandled menu attribute: "<<endl;
if (Global::getDebug() >= 3){
tok->print(" ");
}
}
} catch ( const TokenException & ex ) {
throw LoadException(__FILE__, __LINE__, ex, "Menu parse error");
} catch ( const LoadException & ex ) {
throw ex;
}
}
if (!legacyAdditional.empty()){
//creditsRoll.push_back(legacyAdditional);
}
input.set(Keyboard::Key_ESC, 0, true, Exit);
input.set(Joystick::Button2, 0, true, Exit);
}
OptionCredits::~OptionCredits(){
}
void OptionCredits::logic(){
}
class CreditsLogicDraw : public Util::Logic, public Util::Draw {
public:
CreditsLogicDraw(std::vector<OptionCredits::Sequence> & sequences, Graphics::Color clearColor, Graphics::Color title, Graphics::Color color, const Font & font, InputMap<OptionCredits::CreditKey> & input, Menu::Context & context):
sequences(sequences),
clearColor(clearColor),
title(title),
color(color),
font(font),
input(input),
quit(false),
context(context),
current(0){
}
std::vector<OptionCredits::Sequence> & sequences;
Graphics::Color clearColor, title, color;
const Font & font;
InputMap<OptionCredits::CreditKey> & input;
bool quit;
Menu::Context & context;
unsigned int current;
void run(){
vector<InputMap<OptionCredits::CreditKey>::InputEvent> out = InputManager::getEvents(input, InputSource(true));
for (vector<InputMap<OptionCredits::CreditKey>::InputEvent>::iterator it = out.begin(); it != out.end(); it++){
const InputMap<OptionCredits::CreditKey>::InputEvent & event = *it;
if (event.enabled){
if (event.out == OptionCredits::Exit){
quit = true;
context.finish();
}
}
}
sequences[current].act();
if (sequences[current].isDone()){
sequences[current].reset();
current++;
if (current >= sequences.size()){
current = 0;
}
}
context.act();
}
bool done(){
return quit;
}
double ticks(double system){
return system * Global::ticksPerSecond(90);
}
void draw(const Graphics::Bitmap & buffer){
/* FIXME: hard coded resolution */
Graphics::StretchedBitmap work(640, 480, buffer, Graphics::StretchedBitmap::NoClear, Graphics::qualityFilterName(Configuration::getQualityFilter()));
work.fill(clearColor);
work.start();
//background.Blit(work);
context.render(Util::ReferenceCount<Menu::Renderer>(NULL), work);
sequences[current].draw(title, color, work);
work.finish();
// buffer.BlitToScreen();
}
};
void OptionCredits::run(const Menu::Context & context){
Menu::Context localContext(context, *creditsContext);
localContext.initialize();
if (!music.empty()){
if (Music::loadSong(Storage::instance().find(Filesystem::RelativePath(music)).path())){
Music::pause();
Music::play();
}
}
const Font & vFont = Menu::menuFontParameter.current()->get();
CreditsLogicDraw loop(sequences, clearColor, title, color, vFont, input, localContext);
Util::standardLoop(loop, loop);
InputManager::waitForRelease(input, InputSource(true), Exit);
throw Menu::Reload(__FILE__, __LINE__);
}
OptionDummy::OptionDummy(const Gui::ContextBox & parent, const Token *token):
MenuOption(parent, token){
if ( *token != "dummy" ){
throw LoadException(__FILE__, __LINE__, "Not dummy option");
}
readName(token);
if (getText().empty()){
this->setText("Dummy");
}
setRunnable(false);
}
OptionDummy::OptionDummy(const Gui::ContextBox & parent, const std::string &name):
MenuOption(parent, 0){
if (name.empty()){
throw LoadException(__FILE__, __LINE__, "No name given to dummy");
}
this->setText(name);
setRunnable(false);
}
OptionDummy::~OptionDummy(){
}
void OptionDummy::logic(){
}
void OptionDummy::run(const Menu::Context & context){
}
OptionFullscreen::OptionFullscreen(const Gui::ContextBox & parent, const Token *token):
MenuOption(parent, token),
lblue(255),
lgreen(255),
rblue(255),
rgreen(255){
setRunnable(false);
if ( *token != "fullscreen" )
throw LoadException(__FILE__, __LINE__, "Not fullscreen option");
readName(token);
}
OptionFullscreen::~OptionFullscreen()
{
// Nothing
}
std::string OptionFullscreen::getText() const {
ostringstream out;
out << MenuOption::getText() << ": " << (Configuration::getFullscreen() ? "Yes" : "No");
return out.str();
}
void OptionFullscreen::logic(){;
}
static void changeScreenMode(){
Configuration::setFullscreen(!Configuration::getFullscreen());
int gfx = (Configuration::getFullscreen() ? Global::FULLSCREEN : Global::WINDOWED);
Graphics::changeGraphicsMode(gfx, Graphics::Bitmap::getScreenWidth(), Graphics::Bitmap::getScreenHeight());
}
void OptionFullscreen::run(const Menu::Context & context){
changeScreenMode();
}
bool OptionFullscreen::leftKey(){
changeScreenMode();
return true;
}
bool OptionFullscreen::rightKey(){
changeScreenMode();
return true;
}
OptionFps::OptionFps(const Gui::ContextBox & parent, const Token * token):
MenuOption(parent, token){
readName(token);
setRunnable(false);
}
void OptionFps::logic(){
}
void OptionFps::run(const Menu::Context & context){
}
std::string OptionFps::getText() const {
ostringstream out;
out << "Frames per second: " << Global::TICS_PER_SECOND;
return out.str();
}
bool OptionFps::leftKey(){
Global::setTicksPerSecond(Global::TICS_PER_SECOND - 1);
Configuration::setFps(Global::TICS_PER_SECOND);
return true;
}
bool OptionFps::rightKey(){
Global::setTicksPerSecond(Global::TICS_PER_SECOND + 1);
Configuration::setFps(Global::TICS_PER_SECOND);
return true;
}
OptionFps::~OptionFps(){
}
OptionQualityFilter::OptionQualityFilter(const Gui::ContextBox & parent, const Token * token):
MenuOption(parent, token){
readName(token);
setRunnable(false);
}
std::string OptionQualityFilter::getText() const {
ostringstream out;
out << MenuOption::getText() << ": " << Configuration::getQualityFilter();
return out.str();
}
void OptionQualityFilter::logic(){
}
bool OptionQualityFilter::leftKey(){
string quality = Configuration::getQualityFilter();
if (quality == "none"){
quality = "hqx";
} else if (quality == "hqx"){
quality = "xbr";
} else if (quality == "xbr"){
quality = "none";
}
Configuration::setQualityFilter(quality);
return true;
}
bool OptionQualityFilter::rightKey(){
string quality = Configuration::getQualityFilter();
if (quality == "none"){
quality = "xbr";
} else if (quality == "hqx"){
quality = "none";
} else if (quality == "xbr"){
quality = "hqx";
}
Configuration::setQualityFilter(quality);
return true;
}
void OptionQualityFilter::run(const Menu::Context & context){
}
OptionQualityFilter::~OptionQualityFilter(){
}
#if 0
static OptionJoystick::JoystickType convertToKey(const std::string &k){
std::string temp = k;
for(unsigned int i=0;i<temp.length();i++){
temp[i] = tolower(temp[i]);
}
if (temp == "up") return OptionJoystick::Up;
if (temp == "down") return OptionJoystick::Down;
if (temp == "left") return OptionJoystick::Left;
/*
if (temp == "right") return OptionJoystick::Right;
if (temp == "jump") return OptionJoystick::Jump;
if (temp == "attack1") return OptionJoystick::Attack1;
if (temp == "attack2") return OptionJoystick::Attack2;
if (temp == "attack3") return OptionJoystick::Attack3;
if (temp == "attack4") return OptionJoystick::Attack4;
if (temp == "attack5") return OptionJoystick::Attack5;
if (temp == "attack6") return OptionJoystick::Attack6;
return OptionJoystick::Invalidkey;
}
static Configuration::JoystickInput getKey(int player, OptionJoystick::JoystickType k){
switch(k){
case OptionJoystick::Up:
return Joystick::Up;
case OptionJoystick::Down:
return Joystick::Down;
case OptionJoystick::Left:
return Joystick::Left;
case OptionJoystick::Right:
return Joystick::Right;
case OptionJoystick::Jump:
return Joystick::Button4;
case OptionJoystick::Attack1:
return Joystick::Button1;
case OptionJoystick::Attack2:
return Joystick::Button2;
case OptionJoystick::Attack3:
return Joystick::Button3;
case OptionJoystick::Attack4:
return Joystick::Button4;
case OptionJoystick::Attack5:
return Joystick::Button5;
case OptionJoystick::Attack6:
return Joystick::Button6;
default:
break;
}
return Joystick::Up;
}
static void setKey(int player, OptionJoystick::JoystickType k, Configuration::JoystickInput key){
/ *
switch(k){
case OptionJoystick::Up:
Configuration::setJoystickUp(player, key);
break;
case OptionJoystick::Down:
Configuration::setJoystickDown(player, key);
break;
case OptionJoystick::Left:
Configuration::setJoystickLeft(player, key);
break;
case OptionJoystick::Right:
Configuration::setJoystickRight(player, key);
break;
case OptionJoystick::Jump:
Configuration::setJoystickJump(player, key);
break;
case OptionJoystick::Attack1:
Configuration::setJoystickAttack1(player, key);
break;
case OptionJoystick::Attack2:
Configuration::setJoystickAttack2(player, key);
break;
case OptionJoystick::Attack3:
Configuration::setJoystickAttack3(player, key);
break;
case OptionJoystick::Attack4:
Configuration::setJoystickAttack4(player, key);
break;
case OptionJoystick::Attack5:
Configuration::setJoystickAttack5(player, key);
break;
case OptionJoystick::Attack6:
Configuration::setJoystickAttack6(player, key);
break;
default:
break;
}
*/
}
static Configuration::JoystickInput readJoystick(){
vector<Joystick::Key> keys;
keys.push_back(Joystick::Up);
keys.push_back(Joystick::Down);
keys.push_back(Joystick::Left);
keys.push_back(Joystick::Right);
keys.push_back(Joystick::Button1);
keys.push_back(Joystick::Button2);
keys.push_back(Joystick::Button3);
keys.push_back(Joystick::Button4);
keys.push_back(Joystick::Button5);
keys.push_back(Joystick::Button6);
InputMap<Joystick::Key> input;
for (vector<Joystick::Key>::iterator it = keys.begin(); it != keys.end(); it++){
input.set(*it, 0, true, *it);
}
input.set(Keyboard::Key_ESC, 0, true, Joystick::Invalid);
while (true){
InputManager::poll();
vector<InputMap<Joystick::Key>::InputEvent> out = InputManager::getEvents(input, InputSource());
for (vector<InputMap<Joystick::Key>::InputEvent>::iterator it = out.begin(); it != out.end(); it++){
const InputMap<Joystick::Key>::InputEvent & event = *it;
if (event.enabled){
Global::debug(1) << "Press: " << event.out << std::endl;
if (event.out == Joystick::Invalid){
InputManager::waitForRelease(input, InputSource(), Joystick::Invalid);
throw Exception::Return(__FILE__, __LINE__);
}
return event.out;
}
}
Util::rest(1);
}
/* control probably shouldn't get here.. */
return Joystick::Up;
}
OptionJoystick::OptionJoystick(const Gui::ContextBox & parent, const Token *token):
MenuOption(parent, token),
name(""),
player(-1),
type(Invalidkey),
keyCode(0){
if (*token != "joystick"){
throw LoadException(__FILE__, __LINE__, "Not joystick option");
}
TokenView view = token->view();
while (view.hasMore()){
try{
const Token * tok;
view >> tok;
if ( *tok == "name" ){
tok->view() >> name;
} else if ( *tok == "player" ) {
tok->view() >> player;
} else if ( *tok == "type" ) {
std::string temp;
tok->view() >> temp;
type = convertToKey(temp);
} else {
Global::debug( 3 ) <<"Unhandled menu attribute: "<<endl;
tok->print(" ");
}
} catch ( const TokenException & ex ) {
throw LoadException(__FILE__, __LINE__, ex, "Menu parse error");
} catch ( const LoadException & ex ) {
// delete current;
throw ex;
}
}
if (name.empty()){
throw LoadException(__FILE__, __LINE__, "No name set, this option should have a name!");
}
if (type == Invalidkey){
throw LoadException(__FILE__, __LINE__, "Invalid joystick button, should be up, down, left, right, up, down, jump, attack1-6!");
}
if (player == -1){
throw LoadException(__FILE__, __LINE__, "Player not specified in joystick configuration");
}
ostringstream out;
out << name << ": " << Joystick::keyToName(getKey(player, type));
setText(out.str());
}
OptionJoystick::~OptionJoystick(){
// Nothing
}
void OptionJoystick::logic(){
/*
char temp[255];
sprintf( temp, "%s: %s", name.c_str(), Joystick::keyToName(getKey(player,type)));
setText(std::string(temp));
*/
}
void OptionJoystick::run(const Menu::Context & context){
/*
//int x, y, width, height;
const Font & vFont = Menu::menuFontParameter.current()->get();
const char * message = "Press a joystick button!";
const int width = vFont.textLength(message) + 10;
const int height = vFont.getHeight() + 10;
// const int x = (getParent()->getWork()->getWidth()/2) - (width/2);
// const int y = (getParent()->getWork()->getHeight()/2) - (height/2);
const int x = Menu::Menu::Width / 2 - width/2;
const int y = Menu::Menu::Height / 2 - height/2;
Box dialog;
dialog.location.setPosition(Gui::AbsolutePoint(0,0));
dialog.location.setDimensions(vFont.textLength(message) + 10, vFont.getHeight() + 10);
dialog.transforms.setRadius(0);
dialog.colors.body = Graphics::makeColor(0,0,0);
dialog.colors.bodyAlpha = 200;
dialog.colors.border = Graphics::makeColor(255,255,255);
dialog.colors.borderAlpha = 255;
Graphics::Bitmap temp = Graphics::Bitmap::temporaryBitmap(width,height);
dialog.render(temp, vFont);
vFont.printf( 5, 5, Graphics::makeColor(255,255,255), temp, message, -1);
temp.BlitToScreen(x,y);
setKey(player, type, readJoystick());
ostringstream out;
out << name << ": " << Joystick::keyToName(getKey(player, type));
setText(out.str());
*/
Graphics::Bitmap temp(Menu::Menu::Width, Menu::Menu::Height);
// Menu::Context tempContext = context;
Menu::Context tempContext(context);
tempContext.initialize();
Menu::InfoBox keyDialog;
// keyDialog.setFont(tempContext.getFont());
//keyDialog.location.set(-1,-1,1,1);
const int width = temp.getWidth();
const int height = temp.getHeight();
const Font & font = Menu::menuFontParameter.current()->get();
const int radius = 15;
keyDialog.setText("Press a joystick button!");
keyDialog.initialize(font);
keyDialog.location.setDimensions(font.textLength("Press a joystick button!") + radius, font.getHeight() + radius);
keyDialog.location.setCenterPosition(Gui::RelativePoint(0, 0));
// keyDialog.location.setPosition(Gui::AbsolutePoint((width/2)-(keyDialog.location.getWidth()/2), (height/2)-(keyDialog.location.getHeight()/2)));
// keyDialog.location.setPosition2(Gui::AbsolutePoint((
keyDialog.transforms.setRadius(radius);
keyDialog.colors.body = Graphics::makeColor(0,0,0);
keyDialog.colors.bodyAlpha = 180;
keyDialog.colors.border = Graphics::makeColor(255,255,255);
keyDialog.colors.borderAlpha = 255;
keyDialog.open();
InputManager::waitForClear();
while (!InputManager::anyInput() && keyDialog.isActive()){
InputManager::poll();
keyDialog.act(font);
/*
if (keyDialog.isActive()){
InputManager::poll();
}
*/
tempContext.act();
tempContext.render(0, temp);
keyDialog.render(temp, font);
temp.BlitToScreen();
}
tempContext.finish();
setKey(player, type, readJoystick());
InputManager::waitForClear();
ostringstream out;
out << name << ": " << Joystick::keyToName(getKey(player, type));
setText(out.str());
/*
Keyboard key;
keyCode = readKey(key);
setKey(player,type, keyCode);
*/
}
#endif
static OptionKey::keyType convertToKeyboardKey(const std::string &k){
std::string temp = k;
for(unsigned int i=0;i<temp.length();i++){
temp[i] = tolower(temp[i]);
}
if (temp == "up") return OptionKey::up;
if (temp == "down") return OptionKey::down;
if (temp == "left") return OptionKey::left;
if (temp == "right") return OptionKey::right;
if (temp == "jump") return OptionKey::jump;
if (temp == "attack1") return OptionKey::attack1;
if (temp == "attack2") return OptionKey::attack2;
if (temp == "attack3") return OptionKey::attack3;
if (temp == "attack4") return OptionKey::attack4;
if (temp == "attack5") return OptionKey::attack5;
if (temp == "attack6") return OptionKey::attack6;
return OptionKey::invalidkey;
}
static int getKey(int player, OptionKey::keyType k){
switch(k){
case OptionKey::up:
return Configuration::getUp(player);
break;
case OptionKey::down:
return Configuration::getDown(player);
break;
case OptionKey::left:
return Configuration::getLeft(player);
break;
case OptionKey::right:
return Configuration::getRight(player);
break;
case OptionKey::jump:
return Configuration::getJump(player);
break;
case OptionKey::attack1:
return Configuration::getAttack1(player);
break;
case OptionKey::attack2:
return Configuration::getAttack2(player);
break;
case OptionKey::attack3:
return Configuration::getAttack3(player);
break;
case OptionKey::attack4:
return Configuration::getAttack4(player);
case OptionKey::attack5:
return Configuration::getAttack5(player);
case OptionKey::attack6:
return Configuration::getAttack6(player);
default:
break;
}
return 0;
}
static void setKey(int player, OptionKey::keyType k, int key){
switch(k){
case OptionKey::up:
Configuration::setUp(player, key);
break;
case OptionKey::down:
Configuration::setDown(player, key);
break;
case OptionKey::left:
Configuration::setLeft(player, key);
break;
case OptionKey::right:
Configuration::setRight(player, key);
break;
case OptionKey::jump:
Configuration::setJump(player, key);
break;
case OptionKey::attack1:
Configuration::setAttack1(player, key);
break;
case OptionKey::attack2:
Configuration::setAttack2(player, key);
break;
case OptionKey::attack3:
Configuration::setAttack3(player, key);
break;
case OptionKey::attack4:
Configuration::setAttack4(player, key);
break;
case OptionKey::attack5:
Configuration::setAttack5(player, key);
break;
case OptionKey::attack6:
Configuration::setAttack6(player, key);
break;
default:
break;
}
}
/*
static int readKey( Keyboard & key ){
int k = key.readKey();
key.wait();
return k;
}
*/
OptionKey::OptionKey(const Gui::ContextBox & parent, const Token *token):
MenuOption(parent, token),
name(""),
player(-1),
type(invalidkey),
keyCode(0){
if ( *token != "key" )
throw LoadException(__FILE__, __LINE__, "Not key option");
TokenView view = token->view();
while (view.hasMore()) {
try {
const Token * tok;
view >> tok;
if ( *tok == "name" ) {
tok->view() >> name;
} else if ( *tok == "player" ) {
tok->view() >> player;
} else if ( *tok == "type" ) {
std::string temp;
tok->view() >> temp;
type = convertToKeyboardKey(temp);
} else {
Global::debug( 3 ) <<"Unhandled menu attribute: "<<endl;
tok->print(" ");
}
} catch ( const TokenException & ex ){
throw LoadException(__FILE__, __LINE__, ex, "Menu parse error");
} catch ( const LoadException & ex ) {
// delete current;
throw ex;
}
}
if(name.empty())throw LoadException(__FILE__, __LINE__, "No name set, this option should have a name!");
if(type == invalidkey)throw LoadException(__FILE__, __LINE__, "Invalid key, should be up, down, left, right, up, down, jump, attack1-6!");
if(player == -1)throw LoadException(__FILE__, __LINE__, "Player not specified in key configuration");
char temp[255];
sprintf( temp, "%s: %s", name.c_str(), Keyboard::keyToName(getKey(player,type)));
setText(std::string(temp));
}
OptionKey::~OptionKey(){
// Nothing
}
void OptionKey::logic(){
char temp[255];
sprintf( temp, "%s: %s", name.c_str(), Keyboard::keyToName(getKey(player,type)));
setText(std::string(temp));
}
void OptionKey::run(const Menu::Context & context){
// Do dialog
//Box::messageDialog(Menu::Menu::Width, Menu::Menu::Height, "Press a Key!",2);
class WaitForKey: public Util::Logic, public Util::Draw {
public:
WaitForKey(const Menu::Context & context):
font(Menu::menuFontParameter.current()->get()),
tempContext(context),
speed(30),
listener(*this),
quit(false),
out(Keyboard::Key_ESC),
startingTime(System::currentMilliseconds()),
maxTime(5000){
tempContext.initialize();
// keyDialog.setFont(tempContext.getFont());
//keyDialog.location.set(-1,-1,1,1);
const int width = 320;
const int height = 240;
const int radius = 15;
keyDialog.setText("Press a Key!");
keyDialog.initialize(font);
keyDialog.location.setDimensions(font.textLength("Press a Key!") + radius, font.getHeight() + radius);
keyDialog.location.setCenterPosition(Gui::RelativePoint(0, 0));
// keyDialog.location.setPosition(Gui::AbsolutePoint((width/2)-(keyDialog.location.getWidth()/2), (height/2)-(keyDialog.location.getHeight()/2)));
// keyDialog.location.setPosition2(Gui::AbsolutePoint((
keyDialog.transforms.setRadius(radius);
keyDialog.colors.body = Graphics::makeColor(0,0,0);
keyDialog.colors.bodyAlpha = 180;
keyDialog.colors.border = Graphics::makeColor(255,255,255);
keyDialog.colors.borderAlpha = 255;
keyDialog.open();
Keyboard::pushRepeatState(false);
Keyboard::addListener(&listener);
vector<Graphics::BlendPoint> points;
points.push_back(Graphics::BlendPoint(Graphics::makeColor(255, 0, 0), 30));
points.push_back(Graphics::BlendPoint(Graphics::makeColor(0, 255, 0), 25));
points.push_back(Graphics::BlendPoint(Graphics::makeColor(255, 255, 255), 0));
colors = Graphics::blend_palette(points);
}
virtual ~WaitForKey(){
Keyboard::removeListener(&listener);
Keyboard::popRepeatState();
}
class Listener: public KeyboardListener {
public:
Listener(WaitForKey & parent):
parent(parent){
}
WaitForKey & parent;
virtual void press(Keyboard * keyboard, Keyboard::KeyType key, Keyboard::unicode_t code){
parent.press(key);
}
virtual void release(Keyboard * keyboard, Keyboard::KeyType key){
parent.release(key);
}
};
const Font & font;
Menu::Context tempContext;
Menu::InfoBox keyDialog;
const int speed;
Listener listener;
bool quit;
Keyboard::KeyType out;
/* keep track of how much time we are in this loop */
uint64_t startingTime;
/* maximum number of milliseconds to wait */
const uint64_t maxTime;
vector<Graphics::Color> colors;
virtual void press(Keyboard::KeyType key){
quit = true;
if (key != Keyboard::Key_ESC){
this->out = key;
}
}
virtual void release(Keyboard::KeyType key){
}
virtual void run(){
for (int i = 0; i < 90 / speed; i++){
tempContext.act();
keyDialog.act(font);
}
/* exit after 5 seconds */
quit = quit || (System::currentMilliseconds() - startingTime > maxTime);
}
virtual bool done(){
return quit;
}
virtual double ticks(double system){
return system * Global::ticksPerSecond(speed);
}
virtual void showTimeLeft(const Graphics::Bitmap & screen){
int x1 = 1;
int y1 = 1;
int x2 = screen.getWidth() * (1 - (double) (System::currentMilliseconds() - startingTime) / (double) maxTime);
if (x2 < x1){
x2 = x1;
}
int y2 = 10;
int color = (1.0 - (double) (System::currentMilliseconds() - startingTime) / maxTime) * colors.size();
if (color < 0){
color = 0;
}
if (color >= colors.size()){
color = colors.size() - 1;
}
screen.rectangleFill(x1, y1, x2, y2, colors[color]);
}
virtual void draw(const Graphics::Bitmap & screen){
Graphics::StretchedBitmap work(640, 480, screen);
work.start();
tempContext.render(Util::ReferenceCount<Menu::Renderer>(NULL), work);
keyDialog.render(work, font);
showTimeLeft(work);
work.finish();
}
};
WaitForKey run(context);
Util::standardLoop(run, run);
Keyboard::KeyType key = run.out;
if (key != Keyboard::Key_ESC){
setKey(player, type, key);
}
/*
Keyboard key;
key.wait();
*/
/*
Graphics::Bitmap temp(Menu::Menu::Width, Menu::Menu::Height);
// Menu::Context tempContext = context;
Menu::Context tempContext(context);
tempContext.initialize();
Menu::InfoBox keyDialog;
// keyDialog.setFont(tempContext.getFont());
//keyDialog.location.set(-1,-1,1,1);
const int width = temp.getWidth();
const int height = temp.getHeight();
const Font & font = Menu::menuFontParameter.current()->get();
const int radius = 15;
keyDialog.setText("Press a Key!");
keyDialog.initialize(font);
keyDialog.location.setDimensions(font.textLength("Press a Key!") + radius, font.getHeight() + radius);
keyDialog.location.setCenterPosition(Gui::RelativePoint(0, 0));
// keyDialog.location.setPosition(Gui::AbsolutePoint((width/2)-(keyDialog.location.getWidth()/2), (height/2)-(keyDialog.location.getHeight()/2)));
// keyDialog.location.setPosition2(Gui::AbsolutePoint((
keyDialog.transforms.setRadius(radius);
keyDialog.colors.body = Graphics::makeColor(0,0,0);
keyDialog.colors.bodyAlpha = 180;
keyDialog.colors.border = Graphics::makeColor(255,255,255);
keyDialog.colors.borderAlpha = 255;
keyDialog.open();
InputManager::waitForClear();
while (!InputManager::anyInput() && keyDialog.isActive()){
InputManager::poll();
keyDialog.act(font);
/ *
if (keyDialog.isActive()){
InputManager::poll();
}
* /
tempContext.act();
tempContext.render(Util::ReferenceCount<Menu::Renderer>(NULL), temp);
keyDialog.render(temp, font);
temp.BlitToScreen();
}
tempContext.finish();
keyCode = InputManager::readKey();
setKey(player,type, keyCode);
InputManager::waitForClear();
*/
}
OptionLevel::OptionLevel(const Gui::ContextBox & parent, const Token *token, int * set, int value):
MenuOption(parent, token),
set(set),
value(value){
// Nothing
}
OptionLevel::~OptionLevel(){
}
void OptionLevel::logic(){
}
void OptionLevel::run(const Menu::Context & context){
*set = value;
throw Menu::MenuException(__FILE__, __LINE__);
}
OptionMenu::OptionMenu(const Gui::ContextBox & parent, const Token *token, const Menu::OptionFactory & factory):
MenuOption(parent, token),
menu(0){
if (*token != "menu"){
throw LoadException(__FILE__, __LINE__, "Not a menu");
}
if (token->numTokens() == 1){
std::string temp;
token->view() >> temp;
menu = new Menu::Menu(Storage::instance().find(Filesystem::RelativePath(temp)), factory);
} else {
menu = new Menu::Menu(token, factory);
}
this->setText(menu->getName());
this->setInfoText(menu->getInfo());
// Lets check if this menu is going bye bye
//if ( menu->checkRemoval() ) setForRemoval(true);
}
OptionMenu::~OptionMenu(){
// Delete our menu
if (menu){
delete menu;
}
}
void OptionMenu::logic(){
// Nothing
}
void OptionMenu::run(const Menu::Context & context){
// Do our new menu
try{
menu->run(context);
} catch (const Exception::Return ignore){
throw Menu::Reload(__FILE__, __LINE__);
}
}
OptionReturn::OptionReturn(const Gui::ContextBox & parent, const Token * token):
MenuOption(parent, token){
if (*token != "return"){
throw LoadException(__FILE__, __LINE__, "Not a return option");
}
readName(token);
}
void OptionReturn::logic(){
}
/* maybe this option is misnamed, but its supposed to quit the current game
* and go back to the main menu
*/
void OptionReturn::run(const Menu::Context & context){
throw Exception::Quit(__FILE__, __LINE__);
}
OptionReturn::~OptionReturn(){
}
OptionContinue::OptionContinue(const Gui::ContextBox & parent, const Token * token):
MenuOption(parent, token){
if (*token != "continue"){
throw LoadException(__FILE__, __LINE__, "Not a continue option");
}
readName(token);
}
void OptionContinue::logic(){
}
void OptionContinue::run(const Menu::Context & context){
throw Exception::Return(__FILE__, __LINE__);
}
OptionContinue::~OptionContinue(){
}
OptionQuit::OptionQuit(const Gui::ContextBox & parent, const Token *token):
MenuOption(parent, token){
if ( *token != "quit" ){
throw LoadException(__FILE__, __LINE__, "Not quit option");
}
readName(token);
}
OptionQuit::OptionQuit(const Gui::ContextBox & parent, const std::string &name):
MenuOption(parent, 0){
if (name.empty()){
throw LoadException(__FILE__, __LINE__, "No name given to quit");
}
this->setText(name);
}
OptionQuit::~OptionQuit(){
}
void OptionQuit::logic(){
}
void OptionQuit::run(const Menu::Context & context){
throw ShutdownException();
}
#if defined(WINDOWS) && defined(doesnt_work_yet)
#include <windows.h>
#include <stdio.h>
/* contributed by Roy Underthump from allegro.cc */
static vector<ScreenSize> getScreenResolutions(){
HWND hwnd;
HDC hdc;
// int iPixelFormat;
int descerr;
int retval;
DEVMODE d;
PIXELFORMATDESCRIPTOR pfd;
hwnd = GetDesktopWindow();
hdc = GetDC(hwnd);
vector<ScreenSize> modes;
for (int i = 0;; i++){
retval = EnumDisplaySettings(0,i,&d);
if (!retval){
break;
}
descerr = DescribePixelFormat(hdc, i+1, sizeof(pfd), &pfd);
if(!descerr){
continue;
}
/*
printf("\n#%d bpp %d width %d height %d colorbits %d fps %d",i,d.dmBitsPerPel,
d.dmPelsWidth, d.dmPelsHeight,pfd.cColorBits,d.dmDisplayFrequency);
if(pfd.dwFlags & PFD_SUPPORT_OPENGL)printf(" OGL OK");
*/
modes.push_back(ScreenSize(d.dmPelsWidth, d.dmPelsHeight));
}
if (modes.empty()){
modes.push_back(ScreenSize(640,480));
}
return modes;
}
#else
static vector<ScreenSize> getScreenResolutions(){
vector<ScreenSize> modes;
modes.push_back(ScreenSize(320, 240));
modes.push_back(ScreenSize(640, 480));
modes.push_back(ScreenSize(800, 600));
modes.push_back(ScreenSize(960, 720));
modes.push_back(ScreenSize(1024, 768));
modes.push_back(ScreenSize(1280, 960));
modes.push_back(ScreenSize(1600, 1200));
return modes;
}
#endif
static bool doSort(const ScreenSize & a, const ScreenSize & b){
return (a.w * a.h) < (b.w * b.h);
}
static vector<ScreenSize> sortResolutions(const vector<ScreenSize> & modes){
vector<ScreenSize> copy(modes);
std::sort(copy.begin(), copy.end(), doSort);
return copy;
}
OptionScreenSize::OptionScreenSize(const Gui::ContextBox & parent, const Token *token):
MenuOption(parent, token),
name(""),
lblue(255),
lgreen(255),
rblue(255),
rgreen(255){
setRunnable(false);
Global::debug(1) << "Get screen resolution" << endl;
modes = sortResolutions(getScreenResolutions());
if (Global::getDebug() >= 1){
for (vector<ScreenSize>::iterator it = modes.begin(); it != modes.end(); it++){
Global::debug(1) << "Screen size: " << it->w << " x " << it->h << endl;
}
}
if ( *token != "screen-size" ){
throw LoadException(__FILE__, __LINE__, "Not a screen-size");
}
readName(token);
}
OptionScreenSize::~OptionScreenSize(){
// Nothing
}
void OptionScreenSize::logic(){
ostringstream temp;
temp << "Screen size: " << Configuration::getScreenWidth() << " x " << Configuration::getScreenHeight();
setText(temp.str());
}
void OptionScreenSize::run(const Menu::Context & context){
}
void OptionScreenSize::setMode(int width, int height){
if (width != Configuration::getScreenWidth() ||
height != Configuration::getScreenHeight()){
Global::debug(1) << "Changing mode to " << width << " x " << height << endl;
int gfx = Configuration::getFullscreen() ? Global::FULLSCREEN : Global::WINDOWED;
int ok = Graphics::changeGraphicsMode(gfx, width, height);
if (ok == 0){
Global::debug(1) << "Success" << endl;
Configuration::setScreenWidth(width);
Configuration::setScreenHeight(height);
} else {
Global::debug(1) << "Fail" << endl;
int ok = Graphics::changeGraphicsMode(gfx, Configuration::getScreenWidth(), Configuration::getScreenHeight());
Global::debug(1) << "Set mode back " << ok << endl;
}
}
}
/*
static int modes[][2] = {{640,480}, {800,600}, {1024,768}, {1280,1024}, {1600,1200}};
// static int max_modes = sizeof(modes) / sizeof(int[]);
static int max_modes = 5;
*/
int OptionScreenSize::findMode(int width, int height){
for (int mode = 0; mode < (int) modes.size(); mode++){
if (modes[mode].w == width && modes[mode].h == height){
return mode;
}
}
return -1;
}
bool OptionScreenSize::leftKey(){
int mode = findMode(Configuration::getScreenWidth(), Configuration::getScreenHeight());
if (mode >= 1 && mode < (int)modes.size()){
mode -= 1;
} else {
mode = 0;
}
setMode(modes[mode].w, modes[mode].h);
lblue = lgreen = 0;
return true;
}
bool OptionScreenSize::rightKey(){
int mode = findMode(Configuration::getScreenWidth(), Configuration::getScreenHeight());
if (mode >= 0 && mode < (int)modes.size() - 1){
mode += 1;
} else {
mode = 0;
}
setMode(modes[mode].w, modes[mode].h);
rblue = rgreen = 0;
return true;
}
static string joinPaths(const vector<Filesystem::AbsolutePath> & strings, const string & middle){
ostringstream out;
for (vector<Filesystem::AbsolutePath>::const_iterator it = strings.begin(); it != strings.end(); it++){
out << (*it).path() << middle;
}
return out.str();
}
static bool sortInfo(const Util::ReferenceCount<Menu::FontInfo> & info1,
const Util::ReferenceCount<Menu::FontInfo> & info2){
string name1 = Util::lowerCaseAll(info1->getName());
string name2 = Util::lowerCaseAll(info2->getName());
return name1 < name2;
}
static bool isWindows(){
#ifdef WINDOWS
return true;
#else
return false;
#endif
}
static bool isOSX(){
#ifdef MACOSX
return true;
#else
return false;
#endif
}
template <class X>
static vector<X> operator+(const vector<X> & v1, const vector<X> & v2){
vector<X> out;
for (typename vector<X>::const_iterator it = v1.begin(); it != v1.end(); it++){
out.push_back(*it);
}
for (typename vector<X>::const_iterator it = v2.begin(); it != v2.end(); it++){
out.push_back(*it);
}
return out;
}
static vector<Filesystem::AbsolutePath> findSystemFonts(){
if (isWindows()){
const char * windows = getenv("windir");
if (windows != NULL){
return Storage::instance().getFilesRecursive(Filesystem::AbsolutePath(string(windows) + "/fonts"), "*.ttf");
}
return vector<Filesystem::AbsolutePath>();
} else if (isOSX()){
return Storage::instance().getFilesRecursive(Filesystem::AbsolutePath("/Library/Fonts"), "*.ttf");
} else {
/* assume unix/linux conventions */
return Storage::instance().getFilesRecursive(Filesystem::AbsolutePath("/usr/share/fonts/truetype"), "*.ttf") +
Storage::instance().getFilesRecursive(Filesystem::AbsolutePath("/usr/local/share/fonts/truetype"), "*.ttf");
}
}
static vector<Util::ReferenceCount<Menu::FontInfo> > findFonts(){
vector<Util::ReferenceCount<Menu::FontInfo> > fonts;
try{
Filesystem::AbsolutePath fontsDirectory = Storage::instance().find(Filesystem::RelativePath("fonts"));
Global::debug(1, "fonts") << "Font directory " << fontsDirectory.path() << endl;
vector<Filesystem::AbsolutePath> ttfFonts = Storage::instance().getFiles(fontsDirectory, "*.ttf");
Global::debug(1, "fonts") << "Found ttf fonts " << joinPaths(ttfFonts, ", ") << endl;
vector<Filesystem::AbsolutePath> otfFonts = Storage::instance().getFiles(fontsDirectory, "*.otf");
Global::debug(1, "fonts") << "Found otf fonts " << joinPaths(otfFonts, ", ") << endl;
for (vector<Filesystem::AbsolutePath>::iterator it = ttfFonts.begin(); it != ttfFonts.end(); it++){
fonts.push_back(Util::ReferenceCount<Menu::FontInfo>(new Menu::RelativeFontInfo(Storage::instance().cleanse(*it), Configuration::getMenuFontWidth(), Configuration::getMenuFontHeight())));
}
for (vector<Filesystem::AbsolutePath>::iterator it = otfFonts.begin(); it != otfFonts.end(); it++){
fonts.push_back(Util::ReferenceCount<Menu::FontInfo>(new Menu::RelativeFontInfo(Storage::instance().cleanse(*it), Configuration::getMenuFontWidth(), Configuration::getMenuFontHeight())));
}
/* linux specific fonts */
vector<Filesystem::AbsolutePath> systemFonts = findSystemFonts();
for (vector<Filesystem::AbsolutePath>::iterator it = systemFonts.begin(); it != systemFonts.end(); it++){
Global::debug(1) << "Adding system font `" << (*it).path() << "'" << endl;
fonts.push_back(Util::ReferenceCount<Menu::FontInfo>(new Menu::AbsoluteFontInfo(*it, Configuration::getMenuFontWidth(), Configuration::getMenuFontHeight())));
}
sort(fonts.begin(), fonts.end(), sortInfo);
// DEFAULT (blank)
// fonts.insert(fonts.begin(), new Menu::DefaultFontInfo());
fonts.insert(fonts.begin(), Util::ReferenceCount<Menu::FontInfo>(NULL));
} catch (const Filesystem::NotFound & e){
throw LoadException(__FILE__, __LINE__, e, "Could not load font");
}
return fonts;
}
OptionSelectFont::OptionSelectFont(const Gui::ContextBox & parent, const Token *token):
MenuOption(parent, token),
typeAdjust(fontName),
lblue(255),
lgreen(255),
rblue(255),
rgreen(255){
setRunnable(false);
if ( *token != "font-select" ){
throw LoadException(__FILE__, __LINE__, "Not a font selector");
}
TokenView view = token->view();
while (view.hasMore()){
try{
const Token * tok;
view >> tok;
if ( *tok == "adjust" ){
std::string temp;
tok->view() >> temp;
if ( temp == "name" ) typeAdjust = fontName;
else if ( temp == "width" ) typeAdjust = fontWidth;
else if ( temp == "height" ) typeAdjust = fontHeight;
else throw LoadException(__FILE__, __LINE__, "Incorrect value \"" + temp + "\" in font-select");
} else {
Global::debug(3) << "Unhandled menu attribute: " << endl;
if (Global::getDebug() >= 3){
tok->print(" ");
}
}
} catch ( const TokenException & ex ) {
throw LoadException(__FILE__, __LINE__, ex, "Menu parse error");
} catch ( const LoadException & ex ) {
// delete current;
throw ex;
}
}
}
void OptionSelectFont::open(){
// Find and set fonts now
if (typeAdjust == fontName){
fonts = findFonts();
}
}
void OptionSelectFont::close(){
if (typeAdjust == fontName){
/* the user probably loaded a bunch of different fonts that will
* never be used again, so clear the font cache
* TODO: dont clear the currently selected font
*/
FontFactory::clear();
}
}
OptionSelectFont::~OptionSelectFont(){
// Nothing
}
void OptionSelectFont::logic(){
/* FIXME Get current font and display info */
switch (typeAdjust){
case fontName:{
std::string name;
if (Configuration::hasMenuFont()){
name = Configuration::getMenuFont()->getName();
} else {
name = "Default";
}
setText("Current Font: " + name);
break;
}
case fontWidth:{
ostringstream temp;
temp << "Font Width: " << Configuration::getMenuFontWidth();
setText(temp.str());
break;
}
case fontHeight:{
ostringstream temp;
temp << "Font Height: " << Configuration::getMenuFontHeight();
setText(temp.str());
break;
}
default: break;
}
if (lblue < 255){
lblue += 5;
}
if (rblue < 255){
rblue += 5;
}
if (lgreen < 255){
lgreen += 5;
}
if (rgreen < 255){
rgreen += 5;
}
}
void OptionSelectFont::run(const Menu::Context & context){
// throw Menu::MenuException(__FILE__, __LINE__);
/* throw something to quit back to the previous menu */
}
bool OptionSelectFont::leftKey(){
switch (typeAdjust){
case fontName:
nextIndex(false);
break;
case fontWidth:
Configuration::setMenuFontWidth(Configuration::getMenuFontWidth() - 1);
break;
case fontHeight:
Configuration::setMenuFontHeight(Configuration::getMenuFontHeight() - 1);
break;
default:
break;
}
lblue = lgreen = 0;
return true;
}
bool OptionSelectFont::rightKey(){
switch (typeAdjust){
case fontName:
nextIndex(true);
break;
case fontWidth:
Configuration::setMenuFontWidth(Configuration::getMenuFontWidth() + 1);
break;
case fontHeight:
Configuration::setMenuFontHeight(Configuration::getMenuFontHeight() + 1);
break;
default:
break;
}
rblue = rgreen = 0;
return true;
}
static bool saneFont(const Util::ReferenceCount<Menu::FontInfo> & info){
class Context: public Loader::LoadingContext {
public:
Context(const Util::ReferenceCount<Menu::FontInfo> & info):
info(info),
isok(false){
}
bool ok(){
try{
const Font & font = info->get();
return font.textLength("A") != 0 &&
font.getHeight() != 0;
} catch (const Exception::Base & ignore){
return true;
}
}
virtual void load(){
isok = ok();
}
const Util::ReferenceCount<Menu::FontInfo> & info;
bool isok;
};
if (info == NULL){
return true;
}
Context context(info);
/* an empty Info object, we don't really care about it */
Loader::Info level("Loading Font", Filesystem::AbsolutePath());
Loader::loadScreen(context, level, Loader::SimpleCircle);
return context.isok;
}
void OptionSelectFont::nextIndex(bool forward){
if (fonts.size() == 0){
return;
}
int index = 0;
for (unsigned int i = 0 ; i < fonts.size() ; ++i){
if ((Configuration::getMenuFont() == NULL && fonts[i] == NULL) ||
((Configuration::getMenuFont() != NULL && fonts[i] != NULL) &&
(*Configuration::getMenuFont() == *fonts[i]))){
index = i;
}
}
if (forward){
index++;
if (index >= (int) fonts.size()){
index = 0;
}
} else {
index--;
if (index < 0){
index = (int)fonts.size()-1;
}
}
while (!saneFont(fonts[index])){
Global::debug(0) << "Warning: erasing font `" << fonts[index]->getName() << "'" << endl;
int where = 0;
vector<Util::ReferenceCount<Menu::FontInfo> >::iterator it;
for (it = fonts.begin(); it != fonts.end() && where != index; it++, where++){
}
fonts.erase(it);
if (index >= (int) fonts.size()){
index = fonts.size() - 1;
}
}
Configuration::setMenuFont(fonts[index]);
/* FIXME */
/*
if (fonts[index] == "Default"){
Configuration::setMenuFont("");
} else {
Configuration::setMenuFont(fonts[index]);
}
*/
}
OptionSpeed::OptionSpeed(const Gui::ContextBox & parent, const Token *token):
MenuOption(parent, token),
name(""),
lblue(255),
lgreen(255),
rblue(255),
rgreen(255){
setRunnable(false);
if ( *token != "speed" )
throw LoadException(__FILE__, __LINE__, "Not speed option");
readName(token);
}
OptionSpeed::~OptionSpeed(){
// Nothing
}
std::string OptionSpeed::getText() const {
ostringstream out;
out << MenuOption::getText() << ": " << Configuration::getGameSpeed();
return out.str();
}
void OptionSpeed::logic(){
/*
//ostringstream temp;
char temp[255];
sprintf( temp, "%s: %0.2f", name.c_str(), MenuGlobals::getGameSpeed() );
setText(std::string(temp));
*/
}
void OptionSpeed::run(const Menu::Context & context){
}
bool OptionSpeed::leftKey(){
Configuration::setGameSpeed(Configuration::getGameSpeed() - 0.05);
if (Configuration::getGameSpeed() < 0.1){
Configuration::setGameSpeed(0.1);
}
return false;
}
bool OptionSpeed::rightKey(){
Configuration::setGameSpeed(Configuration::getGameSpeed() + 0.05);
rblue = rgreen = 0;
return false;
}
OptionTabMenu::OptionTabMenu(const Gui::ContextBox & parent, const Token *token, const Menu::OptionFactory & factory):
MenuOption(parent, token),
menu(0){
if (token->numTokens() == 1){
std::string temp;
token->view() >> temp;
menu = new Menu::Menu(Storage::instance().find(Filesystem::RelativePath(temp)), factory, Menu::Renderer::Tabbed);
} else {
menu = new Menu::Menu(token, factory, Menu::Renderer::Tabbed);
}
// this->setText(menu->getName());
// token->print("Menu: ");
const Token * tok = token->findToken("_/name");
if (tok != NULL){
std::string name;
tok->view() >> name;
// Global::debug(0, "menu") << "Menu name: " << name << endl;
this->setText(name);
} else {
// No name?
throw LoadException(__FILE__, __LINE__, "Menu has no name");
}
}
OptionTabMenu::~OptionTabMenu(){
// Delete our menu
if (menu){
delete menu;
}
}
void OptionTabMenu::logic(){
// Nothing
}
void OptionTabMenu::run(const Menu::Context & context){
// Do our new menu
// menu->run(context);
try{
menu->run(context);
} catch (const Exception::Return ignore){
throw Menu::Reload(__FILE__, __LINE__);
}
}
OptionSound::OptionSound(const Gui::ContextBox & parent, const Token *token):
MenuOption(parent, token),
lblue(255),
lgreen(255),
rblue(255),
rgreen(255){
setRunnable(false);
if (*token != "sound" ){
throw LoadException(__FILE__, __LINE__, "Not a sound option");
}
readName(token);
originalName = getName();
}
OptionSound::~OptionSound(){
}
void OptionSound::logic(){
ostringstream temp;
temp << originalName << ": " << Configuration::getSoundVolume();
setText(temp.str());
}
void OptionSound::run(const Menu::Context & context){
}
void OptionSound::changeSound(int much){
int volume = Configuration::getSoundVolume();
volume += much;
if (volume < 0){
volume = 0;
}
if (volume > 100){
volume = 100;
}
Configuration::setSoundVolume(volume);
}
bool OptionSound::leftKey(){
changeSound(-1);
lblue = lgreen = 0;
return true;
}
bool OptionSound::rightKey(){
changeSound(+1);
rblue = rgreen = 0;
return true;
}
OptionMusic::OptionMusic(const Gui::ContextBox & parent, const Token *token):
MenuOption(parent, token),
lblue(255),
lgreen(255),
rblue(255),
rgreen(255){
setRunnable(false);
if (*token != "music" ){
throw LoadException(__FILE__, __LINE__, "Not a music option");
}
readName(token);
originalName = getName();
}
void OptionMusic::logic(){
ostringstream temp;
temp << originalName << ": " << Configuration::getMusicVolume();
setText(temp.str());
}
void OptionMusic::run(const Menu::Context & context){
}
void OptionMusic::changeMusic(int much){
int volume = Configuration::getMusicVolume();
volume += much;
if (volume < 0){
volume = 0;
}
if (volume > 100){
volume = 100;
}
Configuration::setMusicVolume(volume);
Music::setVolume((double) volume / 100.0);
}
bool OptionMusic::leftKey(){
changeMusic(-1);
lblue = lgreen = 0;
return true;
}
bool OptionMusic::rightKey(){
changeMusic(+1);
lblue = lgreen = 0;
return true;
}
OptionMusic::~OptionMusic(){
}
OptionLanguage::OptionLanguage(const Gui::ContextBox & parent, const Token * token):
MenuOption(parent, token){
readName(token);
#if 0
const Token * start = token->getRootParent();
vector<const Token*> tokens = start->findTokens("*/language");
vector<string> all;
for (vector<const Token*>::iterator it = tokens.begin(); it != tokens.end(); it++){
string language;
const Token * token = *it;
if (token->match("language", language)){
all.push_back(language);
}
}
sort(all.begin(), all.end());
unique_copy(all.begin(), all.end(), back_insert_iterator<vector<string> >(languages));
// Global::debug(0) << "Found " << languages.size() << " languages" << endl;
#endif
}
void OptionLanguage::run(const Menu::Context & context){
class LanguageOption: public MenuOption {
public:
LanguageOption(const Gui::ContextBox & parent, const string & language):
MenuOption(parent, NULL){
setText(language);
setInfoText(language);
}
virtual void logic(){
}
virtual void run(const ::Menu::Context & context){
Configuration::setLanguage(getText());
Configuration::saveConfiguration();
throw ::Menu::MenuException(__FILE__, __LINE__);
}
};
Util::NewReferenceCount<Menu::DefaultRenderer> renderer;
Menu::Menu temp(renderer);
Util::ReferenceCount<Menu::FontInfo> info(new Menu::RelativeFontInfo(Font::getDefaultFontPath(), 24, 24));
temp.setFont(info);
const Gui::ContextBox & box = renderer->getBox();
vector<string> languages = context.getLanguages();
for (vector<string>::iterator it = languages.begin(); it != languages.end(); it++){
temp.addOption(new LanguageOption(box, *it));
}
try {
temp.run(context);
} catch (const Exception::Return & ignore){
} catch (const Menu::MenuException & ex){
}
throw Menu::Reload(__FILE__, __LINE__);
// throw Exception::Return(__FILE__, __LINE__);
}
void OptionLanguage::logic(){
}
OptionJoystick::OptionJoystick(const Gui::ContextBox & parent, const Token *token):
MenuOption(parent, token){
setRunnable(true);
if (*token != "joystick" ){
throw LoadException(__FILE__, __LINE__, "Not a joystick option");
}
readName(token);
}
void OptionJoystick::logic(){
}
class JoystickLogicDraw: public Util::Logic, public Util::Draw {
public:
enum Inputs{
Exit
};
static const int marginX = 20;
JoystickLogicDraw(int id, const Util::ReferenceCount<Joystick> & joystick, const ::Menu::Context & context):
id(id),
joystick(joystick),
quit(false),
context(context, Menu::Context()){
input.set(Keyboard::Key_ESC, Exit);
}
const int id;
Util::ReferenceCount<Joystick> joystick;
bool quit;
Menu::Context context;
InputMap<Inputs> input;
void doInput(){
vector<InputMap<Inputs>::InputEvent> out = InputManager::getEvents(input, InputSource(true));
for (vector<InputMap<Inputs>::InputEvent>::iterator it = out.begin(); it != out.end(); it++){
const InputMap<Inputs>::InputEvent & event = *it;
if (event.enabled){
if (event.out == Exit){
quit = true;
// context.finish();
}
}
}
}
virtual void run(){
doInput();
context.act();
}
bool done(){
return quit;
}
double ticks(double system){
return system * Global::ticksPerSecond(60);
}
void drawButtons(const Font & font, const Graphics::Bitmap & buffer, int y){
Graphics::Color color = Graphics::makeColor(255, 255, 255);
font.printf(marginX, y, color, buffer, "Up: ", 0); y += font.getHeight() + 5;
font.printf(marginX, y, color, buffer, "Down: ", 0); y += font.getHeight() + 5;
font.printf(marginX, y, color, buffer, "Left: ", 0); y += font.getHeight() + 5;
font.printf(marginX, y, color, buffer, "Right: ", 0); y += font.getHeight() + 5;
font.printf(marginX, y, color, buffer, "Button1: ", 0); y += font.getHeight() + 5;
font.printf(marginX, y, color, buffer, "Button2: ", 0); y += font.getHeight() + 5;
font.printf(marginX, y, color, buffer, "Button3: ", 0); y += font.getHeight() + 5;
font.printf(marginX, y, color, buffer, "Button4: ", 0); y += font.getHeight() + 5;
font.printf(marginX, y, color, buffer, "Button5: ", 0); y += font.getHeight() + 5;
font.printf(marginX, y, color, buffer, "Button6: ", 0); y += font.getHeight() + 5;
font.printf(marginX, y, color, buffer, "Select: ", 0); y += font.getHeight() + 5;
font.printf(marginX, y, color, buffer, "Quit: ", 0); y += font.getHeight() + 5;
}
void draw(const Graphics::Bitmap & buffer){
const Font & font = Menu::menuFontParameter.current()->get();
Graphics::StretchedBitmap work(640, 480, buffer, Graphics::StretchedBitmap::NoClear, Graphics::qualityFilterName(Configuration::getQualityFilter()));
work.start();
context.renderBackground(work);
/* FIXME: scale the joystck name down to fit */
font.printf(marginX, 1, Graphics::makeColor(255, 255, 255), work, "Joystick %d: %s", 0, id, joystick->getName().c_str());
drawButtons(font, work, 1 + font.getHeight() + 5);
context.renderForeground(work);
work.finish();
}
};
namespace{
struct Axis{
Axis():
stick(0),
axis(0),
first(0),
set(false),
last(0),
lastMotion(0){
}
int stick;
int axis;
/* first value from this axis. we assume that
* the first value is sufficiently close to 'zero' which
* can be any value, but most likely will either be
* -1, 0, or 1
*/
double first;
/* true if first has been set */
bool set;
/* keep track of last value for this axis */
double last;
/* last time an event was produced (or at least last
* time we read it). it might be better to get the actual
* time from the event itself.
*/
uint64_t lastMotion;
};
}
static void runJoystickMenu(int joystickId, const Util::ReferenceCount<Joystick> & joystick, const ::Menu::Context & context){
Util::NewReferenceCount<Menu::DefaultRenderer> renderer;
Menu::Menu menu(renderer);
Gui::ContextBox & box = renderer->getBox();
box.setListType(ContextBox::Normal);
Gui::ListValues attributes(box.getListValues());
attributes.setDistanceFade(false);
box.setListValues(attributes);
menu.setPosition(Gui::Coordinate(Gui::RelativePoint(-0.8, -0.3),
Gui::RelativePoint(0, 0.8)));
#define WAIT_TIME_MS (0.7 * 1000)
#define WAIT_TIME_AXIS_MS (1 * 1000)
#define AXIS_THRESHOLD 0.7
class JoystickButton: public MenuOption {
public:
JoystickButton(const Menu::Menu & menu, const Gui::ContextBox & parent, const Util::ReferenceCount<Joystick> & joystick, const string & name, Joystick::Key key):
MenuOption(parent, NULL),
menu(menu),
name(name),
joystick(joystick),
key(key){
setText(name);
setInfoText(name);
}
const Menu::Menu & menu;
string name;
Util::ReferenceCount<Joystick> joystick;
Joystick::Key key;
class ButtonListener: public JoystickListener {
public:
ButtonListener(const Util::ReferenceCount<Joystick> & joystick):
touched(false),
done(false),
chosen(-1),
chosenAxis(NULL){
map<int, map<int, double> > axisValues = joystick->getCurrentAxisValues();
for (map<int, map<int, double> >::iterator it = axisValues.begin(); it != axisValues.end(); it++){
int stick = it->first;
const map<int, double> & subMap = it->second;
for (map<int, double>::const_iterator it = subMap.begin(); it != subMap.end(); it++){
int axis = it->first;
double value = it->second;
Axis use;
use.stick = stick;
use.axis = axis;
use.first = value;
use.set = true;
use.last = value;
use.lastMotion = 0;
this->axis.push_back(use);
}
}
}
map<int, uint64_t> presses;
map<int, bool> pressed;
/* true if a button/axis is moved. flips to false when queried */
bool touched;
vector<Axis> axis;
bool done;
int chosen;
Axis * chosenAxis;
bool wasTouched(){
bool out = touched;
touched = false;
return out;
}
Axis & getAxis(int stick, int axis){
for (vector<Axis>::iterator it = this->axis.begin(); it != this->axis.end(); it++){
Axis & use = *it;
if (use.stick == stick && use.axis == axis){
return use;
}
}
Axis out;
out.stick = stick;
out.axis = axis;
this->axis.push_back(out);
return getAxis(stick, axis);
}
const vector<Axis> & getAllAxis() const {
return axis;
}
const map<int, uint64_t> & getPresses() const {
return presses;
}
int getButton() const {
return chosen;
}
Axis * getChosenAxis() const {
return chosenAxis;
}
virtual ~ButtonListener(){
}
bool isDone() const {
return (getButton() != -1 && !anyPressed()) ||
(getChosenAxis() != NULL);
}
void choose(){
uint64_t now = System::currentMilliseconds();
for (map<int, uint64_t>::const_iterator it = presses.begin(); it != presses.end(); it++){
uint64_t what = it->second;
if (what != 0 && now - what > WAIT_TIME_MS){
chosen = it->first;
}
}
for (vector<Axis>::iterator it = axis.begin(); it != axis.end(); it++){
Axis & use = *it;
if (fabs(use.last - use.first) > AXIS_THRESHOLD &&
now - use.lastMotion > WAIT_TIME_AXIS_MS){
chosenAxis = &use;
}
}
}
bool anyPressed() const {
for (map<int, bool>::const_iterator it = pressed.begin(); it != pressed.end(); it++){
if (it->second){
return true;
}
}
return false;
}
virtual void pressButton(Joystick * from, int button){
touched = true;
pressed[button] = true;
presses[button] = System::currentMilliseconds();
}
virtual void releaseButton(Joystick * from, int button){
presses[button] = 0;
pressed[button] = false;
}
/* either all increasing or all decreasing */
bool monotonic(const vector<double> & what){
if (what.size() == 0){
return true;
}
double first = what[0];
int direction = -1;
vector<double>::const_iterator it = what.begin();
it++;
for (/**/; it != what.end(); it++){
switch (direction){
case -1: {
if (*it < first){
direction = 1;
} else if (*it > first){
direction = 2;
}
first = *it;
break;
}
case 1: {
if (*it > first){
return false;
}
break;
}
case 2: {
if (*it < first){
return false;
}
break;
}
}
}
return true;
}
virtual void axisMotion(Joystick * from, int stick, int axis, double motion){
touched = true;
Axis & use = getAxis(stick, axis);
if (!use.set){
use.first = motion;
use.set = true;
}
use.last = motion;
use.lastMotion = System::currentMilliseconds();
/*
const double AXIS_THRESHOLD = 0.5;
Global::debug(0) << "stick " << stick << " axis " << axis << " first " << use.first << " last " << use.last << " diff " << fabs(use.last - use.first) << std::endl;
if (fabs(use.last - use.first) > AXIS_THRESHOLD){
Global::debug(0) << "stick " << stick << " axis " << axis << " motion " << motion << std::endl;
}
*/
}
virtual void hatMotion(Joystick * from, int motion){
}
};
void logic(){
ostringstream out;
int stick, axis;
double low, high;
if (joystick->getAxis(key, stick, axis, low, high)){
out << name << ": " << stick << "/" << axis << "/";
if (low < 0){
out << "-";
} else {
out << "+";
}
} else {
int button = joystick->getButton(key);
out << name << ": ";
if (button != -1){
out << joystick->getButton(key);
} else {
out << "unset";
}
}
setText(out.str());
}
void run(const Menu::Context & context){
class SetButton: public Util::Logic, public Util::Draw {
public:
SetButton(const Menu::Context & context, const Menu::Menu & menu, const string & name, const Util::ReferenceCount<Joystick> & joystick):
context(context),
menu(menu),
name(name),
listener(joystick),
joystick(joystick),
startingTime(System::currentMilliseconds()),
maxTime(5000){
input.set(Keyboard::Key_ESC, 0);
joystick->addListener(&listener);
vector<Graphics::BlendPoint> points;
points.push_back(Graphics::BlendPoint(Graphics::makeColor(255, 0, 0), 30));
points.push_back(Graphics::BlendPoint(Graphics::makeColor(0, 255, 0), 25));
points.push_back(Graphics::BlendPoint(Graphics::makeColor(255, 255, 255), 0));
colors = Graphics::blend_palette(points);
}
const Menu::Context & context;
const Menu::Menu & menu;
string name;
ButtonListener listener;
InputMap<int> input;
Util::ReferenceCount<Joystick> joystick;
vector<Graphics::Color> colors;
uint64_t startingTime;
const uint64_t maxTime;
virtual ~SetButton(){
joystick->removeListener(&listener);
}
virtual void showTimeLeft(const Graphics::Bitmap & screen){
int x1 = 1;
int y1 = 1;
int x2 = screen.getWidth() * (1 - (double) (System::currentMilliseconds() - startingTime) / (double) maxTime);
if (x2 < x1){
x2 = x1;
}
int y2 = 10;
int color = (1.0 - (double) (System::currentMilliseconds() - startingTime) / maxTime) * colors.size();
if (color < 0){
color = 0;
}
if (color >= colors.size()){
color = colors.size() - 1;
}
screen.rectangleFill(x1, y1, x2, y2, colors[color]);
}
void setButton(Joystick::Key key){
int button = listener.getButton();
if (button != -1){
Global::debug(1) << "Chosen button " << listener.getButton() << std::endl;
joystick->setCustomButton(listener.getButton(), key);
} else {
Axis * axis = listener.getChosenAxis();
double rangeLow = 0;
double rangeHigh = 0;
/* stick went negative and went to -1 */
if (axis->first <= 0 && axis->last < axis->first){
rangeLow = -1;
rangeHigh = -AXIS_THRESHOLD;
/* stick started at negative and went positive, possibly
* not above 0.
*/
} else if (axis->first < 0 && axis->last > axis->first){
rangeLow = 0;
rangeHigh = 1;
/* stick started positive and went to 1 */
} else if (axis->first >= 0 && axis->last > axis->first){
rangeLow = AXIS_THRESHOLD;
rangeHigh = 1;
/* stick started positive and went towards -1 */
} else if (axis->first > 0 && axis->last < axis->first){
rangeLow = -1;
rangeHigh = 0;
}
Global::debug(0) << "Set stick " << axis->stick << " axis " << axis->axis << " [" << rangeLow << ", " << rangeHigh << "]" << std::endl;
joystick->setCustomAxis(key, axis->stick, axis->axis, rangeLow, rangeHigh);
}
}
double ticks(double system){
return system * Global::ticksPerSecond(60);
}
bool done(){
return listener.isDone();
}
void run(){
vector<InputMap<int>::InputEvent> out = InputManager::getEvents(input, InputSource(true));
for (vector<InputMap<int>::InputEvent>::iterator it = out.begin(); it != out.end(); it++){
const InputMap<int>::InputEvent & event = *it;
if (event.enabled){
if (event.out == 0){
throw Exception::Return(__FILE__, __LINE__);
}
}
}
listener.choose();
if (listener.wasTouched()){
startingTime = System::currentMilliseconds();
}
if (System::currentMilliseconds() - startingTime >= maxTime){
throw Exception::Return(__FILE__, __LINE__);
}
}
void draw(const Graphics::Bitmap & buffer){
Graphics::StretchedBitmap work(640, 480, buffer, Graphics::StretchedBitmap::NoClear, Graphics::qualityFilterName(Configuration::getQualityFilter()));
work.start();
menu.render(context, work);
const Font & font = Menu::menuFontParameter.current()->get();
Gui::RelativePoint start(0.2, -0.3);
Gui::RelativePoint end(0.85, 0.8);
int x = start.getX();
int y = start.getY();
// font.printfWrap(x, y - font.getHeight() * 2 - 5, Graphics::makeColor(255, 255, 255), work, end.getX() - start.getX(), "Press and hold a button", 0);
font.printf(x, y - 18 - 5, 18, 18, Graphics::makeColor(255, 255, 255), work, "Press and hold a button", 0);
work.translucent(0, 0, 0, 128).rectangleFill(x, y, end.getX(), end.getY(), Graphics::makeColor(0, 0, 0));
uint64_t now = System::currentMilliseconds();
const map<int, uint64_t> & presses = listener.getPresses();
for (map<int, uint64_t>::const_iterator it = presses.begin(); it != presses.end(); it++){
int button = it->first;
uint64_t time = it->second;
if (time > 0){
int delta = now - time;
if (delta > WAIT_TIME_MS){
delta = WAIT_TIME_MS;
}
/* this shouldn't happen... */
if (delta < 0){
delta = 0;
}
Graphics::Color color;
color = Graphics::makeColor((int)(255.0 * (double) delta / (WAIT_TIME_MS)),
0, 255);
if (button == listener.getButton()){
color = Graphics::makeColor(255, 255, 255);
}
ostringstream text;
text << name << ": " << button;
font.printf(x, y, color, work, text.str(), 0);
y += font.getHeight() + 5;
}
}
const vector<Axis> & axis = listener.getAllAxis();
for (vector<Axis>::const_iterator it = axis.begin(); it != axis.end(); it++){
const Axis & use = *it;
if (fabs(use.last - use.first) > AXIS_THRESHOLD){
int delta = now - use.lastMotion;
if (delta > WAIT_TIME_AXIS_MS){
delta = WAIT_TIME_AXIS_MS;
}
/* this shouldn't happen... */
if (delta < 0){
delta = 0;
}
Graphics::Color color;
color = Graphics::makeColor((int)(255.0 * (double) delta / (WAIT_TIME_AXIS_MS)),
0, 255);
if (&use == listener.getChosenAxis()){
color = Graphics::makeColor(255, 255, 255);
}
ostringstream text;
text << name << ": stick " << use.stick << " axis " << use.axis;
if (use.last > use.first){
text << " +";
} else {
text << " -";
}
font.printf(x, y, 18, 18, color, work, text.str(), 0);
y += font.getHeight() + 5;
}
}
showTimeLeft(work);
work.finish();
}
void wait(){
while (listener.anyPressed()){
InputManager::poll();
Util::rest(1);
}
}
};
Global::debug(1) << "Set button " << getName() << std::endl;
SetButton set(context, menu, name, joystick);
try{
Util::standardLoop(set, set);
set.setButton(key);
} catch (const Exception::Return & quit){
}
set.wait();
}
};
menu.addOption(new JoystickButton(menu, box, joystick, "Up", Joystick::Up));
menu.addOption(new JoystickButton(menu, box, joystick, "Down", Joystick::Down));
menu.addOption(new JoystickButton(menu, box, joystick, "Left", Joystick::Left));
menu.addOption(new JoystickButton(menu, box, joystick, "Right", Joystick::Right));
menu.addOption(new JoystickButton(menu, box, joystick, "Button1", Joystick::Button1));
menu.addOption(new JoystickButton(menu, box, joystick, "Button2", Joystick::Button2));
menu.addOption(new JoystickButton(menu, box, joystick, "Button3", Joystick::Button3));
menu.addOption(new JoystickButton(menu, box, joystick, "Button4", Joystick::Button4));
menu.addOption(new JoystickButton(menu, box, joystick, "Button5", Joystick::Button5));
menu.addOption(new JoystickButton(menu, box, joystick, "Button6", Joystick::Button6));
menu.addOption(new JoystickButton(menu, box, joystick, "Start", Joystick::Start));
menu.addOption(new JoystickButton(menu, box, joystick, "Quit", Joystick::Quit));
try {
menu.run(context);
} catch (const Exception::Return & ignore){
} catch (const Menu::MenuException & ex){
}
}
void OptionJoystick::run(const Menu::Context & context){
class JoystickOption: public MenuOption {
public:
JoystickOption(const Gui::ContextBox & parent, int id, const Util::ReferenceCount<Joystick> & joystick):
MenuOption(parent, NULL),
joystick(joystick),
id(id){
ostringstream out;
out << "Joystick " << (id + 1);
setText(out.str());
setInfoText(joystick->getName());
}
const Util::ReferenceCount<Joystick> joystick;
const int id;
virtual void logic(){
}
virtual void run(const ::Menu::Context & context){
runJoystickMenu(id, joystick, context);
/*
JoystickLogicDraw mainLoop(id, joystick, context);
Util::standardLoop(mainLoop, mainLoop);
*/
throw ::Menu::MenuException(__FILE__, __LINE__);
}
};
Util::NewReferenceCount<Menu::DefaultRenderer> renderer;
Menu::Menu menu(renderer);
/*
Util::ReferenceCount<Menu::FontInfo> info(new Menu::RelativeFontInfo(Global::DEFAULT_FONT, 24, 24));
temp.setFont(info);
*/
Gui::ContextBox & box = renderer->getBox();
box.setListType(ContextBox::Normal);
map<int, Util::ReferenceCount<Joystick> > joysticks = InputManager::getJoysticks();
for (map<int, Util::ReferenceCount<Joystick> >::iterator it = joysticks.begin(); it != joysticks.end(); it++){
menu.addOption(new JoystickOption(box, it->first, it->second));
}
if (joysticks.size() == 0){
menu.addOption(new OptionDummy(box, "No joysticks found!"));
}
try {
menu.run(context);
} catch (const Exception::Return & ignore){
} catch (const Menu::MenuException & ex){
}
}
OptionJoystick::~OptionJoystick(){
}
diff --git a/src/windows/funcs.cpp b/src/windows/funcs.cpp
deleted file mode 100644
index 73502e8c..00000000
--- a/src/windows/funcs.cpp
+++ /dev/null
@@ -1,23 +0,0 @@
-#ifdef WINDOWS
-
-#include <windows.h>
-#include "util/funcs.h"
-#include <io.h>
-#include <fcntl.h>
-
-/*
-int Util::getPipe(int files[2]){
- HANDLE read_in, write_in;
- int ok = CreatePipe(&read_in, &write_in, NULL, 0);
- if (ok == 0){
- return -1;
- }
- // files[0] = _open_osfhandle(read_in, O_RDONLY | O_BINARY);
- // files[1] = _open_osfhandle(write_in, O_WRONLY | O_BINARY);
- files[0] = _open_osfhandle((intptr_t) read_in, _O_RDONLY);
- files[1] = _open_osfhandle((intptr_t) write_in, _O_WRONLY);
- return 0;
-}
-*/
-
-#endif
diff --git a/src/windows/game.res b/src/windows/game.res
deleted file mode 100644
index 3fa61ee5..00000000
Binary files a/src/windows/game.res and /dev/null differ
diff --git a/src/xmain.cpp b/src/xmain.cpp
index 0b41c456..6fd1aaef 100644
--- a/src/xmain.cpp
+++ b/src/xmain.cpp
@@ -1,41 +1,41 @@
#include "main.h"
#ifdef USE_ALLEGRO
#include <allegro.h>
int main(int argc, char ** argv){
- return paintown_main(argc, argv);
+ return rtech_main(argc, argv);
}
END_OF_MAIN()
#endif
#ifdef USE_ALLEGRO5
#include <allegro5/allegro.h>
int main(int argc, char ** argv){
- return paintown_main(argc, argv);
+ return rtech_main(argc, argv);
}
#endif
#ifdef MINPSPW
#include <pspkernel.h>
// Define only on windows because main is redefined as SDL_main (from SDL_psp_main.c comments)
#ifdef INCLUDE_SCE_MODULE_INFO
PSP_MODULE_INFO("Paintown", 0, 1, 1);
#endif
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);
PSP_HEAP_SIZE_MAX();
#endif
#ifndef NACL
#ifdef USE_SDL
#ifdef USE_SDL_MAIN
extern "C" int SDL_main(int argc, char ** argv){
- return paintown_main(argc, argv);
+ return rtech_main(argc, argv);
}
#else
int main( int argc, char ** argv ){
- return paintown_main(argc, argv);
+ return rtech_main(argc, argv);
}
#endif
#endif
#endif

File Metadata

Mime Type
text/x-diff
Expires
Wed, Jun 17, 9:29 PM (1 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
69861
Default Alt Text
(416 KB)

Event Timeline