]> Chaos Git - vn/vndc.git/commitdiff
Mass Tab -> 4space this code
authorroot <chaos.kagami@gmail.com>
Fri, 6 May 2016 10:36:46 +0000 (06:36 -0400)
committerroot <chaos.kagami@gmail.com>
Fri, 6 May 2016 10:36:46 +0000 (06:36 -0400)
34 files changed:
external/zero/include/AudioManager.hpp
external/zero/include/ContextManager.hpp
external/zero/include/TextManager.hpp
external/zero/include/UDisplayable.hpp
external/zero/include/VertexController.hpp
external/zero/include/Zero.hpp
external/zero/src/AudioManager.cpp
external/zero/src/ContextManager.cpp
external/zero/src/TextManager.cpp
external/zero/src/UDisplayable.cpp
external/zero/src/VertexController.cpp
vndc/include/Data.hpp
vndc/include/Funcs.hpp
vndc/include/gitrev.hpp [new file with mode: 0644]
vndc/src/Data.cpp
vndc/src/Loop.cpp
vndc/src/Parse.cpp
vndc/src/VNDC.cpp
vndc/src/op_bgload.cpp
vndc/src/op_choice.cpp
vndc/src/op_cleartext.cpp
vndc/src/op_delay.cpp
vndc/src/op_fi.cpp
vndc/src/op_goto.cpp
vndc/src/op_gsetvar.cpp
vndc/src/op_if.cpp
vndc/src/op_jump.cpp
vndc/src/op_music.cpp
vndc/src/op_random.cpp
vndc/src/op_save.cpp
vndc/src/op_setimg.cpp
vndc/src/op_setvar.cpp
vndc/src/op_sound.cpp
vndc/src/op_text.cpp

index d736707169de3f8548464a2b5215a85e1bf2a4b8..0b2e14a857d5ed7eb60366fc8a8dc9c9f6f29c97 100644 (file)
@@ -2,35 +2,35 @@
 #define AUDIOMANAGER_HPP
 
 
-       class AudioManager {
-               public:
-                       // Ctors and dtors
-                       AudioManager();
-                       ~AudioManager();
-
-                       // Load index.
-                       int LoadSfx(char* fname);
-                       int LoadMusic(char* fname);
-
-                       // Playing functions.
-                       void PlaySfx(int index);
-                       void PlaySfx(int index, int count);
-                       void PlayMusic(int index);
-                       void PlayMusicLoop(int index);
-                       void PauseMusic();
-
-                       // Unload Functions
-                       void UnloadSfx(int index);
-                       void UnloadMusic(int index);
-
-                       // Complete unload functions
-                       void FlushSfx();
-                       void FlushMusic();
-               private:
-                       int SfxCount, MusicCount;
-                       Mix_Chunk** SfxStore;
-                       Mix_Music** MusicStore;
-       };
+    class AudioManager {
+        public:
+            // Ctors and dtors
+            AudioManager();
+            ~AudioManager();
+
+            // Load index.
+            int LoadSfx(char* fname);
+            int LoadMusic(char* fname);
+
+            // Playing functions.
+            void PlaySfx(int index);
+            void PlaySfx(int index, int count);
+            void PlayMusic(int index);
+            void PlayMusicLoop(int index);
+            void PauseMusic();
+
+            // Unload Functions
+            void UnloadSfx(int index);
+            void UnloadMusic(int index);
+
+            // Complete unload functions
+            void FlushSfx();
+            void FlushMusic();
+        private:
+            int SfxCount, MusicCount;
+            Mix_Chunk** SfxStore;
+            Mix_Music** MusicStore;
+    };
 
 
 #endif
index 1525ffd6ad5c79ad775b109c68a78d4960c7ec6f..1afac6381a11dfc03083df191b658d125a758b7f 100644 (file)
@@ -7,128 +7,128 @@ typedef void (*MouseCallback)(int, int, bool, bool, bool, bool); // X, Y, up/dow
 class VertexController;
 
 typedef enum {
-       Software = 0,
-       Accel2d  = 1,
-       OpenGL   = 2
+    Software = 0,
+    Accel2d  = 1,
+    OpenGL   = 2
 } DispMode_t;
 
 class TextManager; // Forward decl
 
-       // Input Mode enum. This is the max events allowed in one go.
-       typedef enum InMode_e {
-               Slow = 20,
-               Medium = 10,
-               Burst = 5
-       } InMode;
-
-       class ContextManager {
-               public:
-                       ContextManager();
-                       ContextManager(int scr_width, int scr_height, bool fulls, DispMode_t disp);
-
-                       // Initialization.
-                       void InitWindow(int width, int height, bool fulls, DispMode_t disp);
-                       void InitWindowLogical(int width, int height, int width_log, int height_log, bool fulls, DispMode_t disp);
-
-                       // Set window title
-                       void SetTitle(char* title);
-
-                       // Render related.
-                       void Clear();
-                       void Flush();
-                       void ClearOverlay();
-                       void Blit(void* inp, SDL_Rect* src, SDL_Rect* dst, SDL_Rect* glrect);
-                       void OverlayBlit(void* inp, SDL_Rect* src, SDL_Rect* dst, SDL_Rect* glrect);
-
-                       // Accessors.
-                       SDL_Surface* Surface();
-                       SDL_Renderer* Renderer();
-                       bool Accelerated();
-                       bool GLMode();
-                       int GetWidth();
-                       int GetHeight();
-
-                       // Run input callbacks and update states.
-                       bool Input();
-
-                       // Abstract remappable key functions.
-                       int RegisterInput(SDL_Keycode key, GameCallback func);
-                       void RegisterMouse(MouseCallback func);
-                       bool GetInput(int index);
-                       void RemapKey(int index, SDL_Keycode to);
-                       void InputMode(InMode mode);
-
-                       // Gets the AudioManager & TextManager for usage.
-                       AudioManager* Audio();
-                       TextManager* Text();
-                       VertexController* Vertex();
-
-                       // Exit methods.
-                       void SetQuit();
-                       bool GetQuit();
-
-                       // Logic sync limiter @ 60fps
-                       void StartSync();
-                       void EndSync();
-
-                       // Wrapper functions for tex load.
-                       void* LoadImage(char* fname);
-                       void* LoadImageMemory(void* mem, size_t len, char* type);
-                       void* AccelImage(void* in);
-                       void* GLTexImage(void* in);
-
-                       ~ContextManager();
-               private:
-                       // Lower init.
-                       void _InitWindowSW(int width, int height, bool fulls);
-                       void _InitWindowAC(int width, int height, bool fulls);
-                       void _InitWindowGL(int width, int height, bool fulls);
-
-                       // Lower init, logical.
-                       void _InitWindowLogicalSW(int width_win, int height_win, int width_log, int height_log, bool fulls);
-                       void _InitWindowLogicalAC(int width_win, int height_win, int width_log, int height_log, bool fulls);
-                       void _InitWindowLogicalGL(int width_win, int height_win, int width_log, int height_log, bool fulls);
-
-                       // Used to load default values in abscense of GNU exts
-                       void DefaultVariables();
-
-                       InMode inputmode;
-                       SDL_Window* window;
-                       SDL_Surface* surface, *surface_o;
-                       SDL_Texture* texture, *texture_o;
-                       SDL_Renderer* renderer;
-                       SDL_GLContext glctx;
-
-                       // use logical size
-                       bool logicalRender;
-                       bool accelerate;
-                       bool opengl_mode;
-
-                       GLuint fg, bg, fg_tex, bg_tex;
-
-                       bool StartQuit;
-
-                       AudioManager* audioMgr;
-                       TextManager* txtMgr;
-                       VertexController* vertCnt;
-
-                       SDL_Keycode* inputMappings; // This can actually be used instead of InputList now. Weird.
-                       bool* inputStates;
-                       GameCallback* inputCallbacks;
-                       MouseCallback mouseCallback;
-
-                       int inputRegistered;
-
-                       // Logic cap.
-                       int logicRate;
-                       int timeElapsed;
-                       int syncElapsed;
-
-                       // Width and height
-                       int WIN_width;
-                       int WIN_height;
-                       int LOG_width;
-                       int LOG_height;
-       };
+    // Input Mode enum. This is the max events allowed in one go.
+    typedef enum InMode_e {
+        Slow = 20,
+        Medium = 10,
+        Burst = 5
+    } InMode;
+
+    class ContextManager {
+        public:
+            ContextManager();
+            ContextManager(int scr_width, int scr_height, bool fulls, DispMode_t disp);
+
+            // Initialization.
+            void InitWindow(int width, int height, bool fulls, DispMode_t disp);
+            void InitWindowLogical(int width, int height, int width_log, int height_log, bool fulls, DispMode_t disp);
+
+            // Set window title
+            void SetTitle(char* title);
+
+            // Render related.
+            void Clear();
+            void Flush();
+            void ClearOverlay();
+            void Blit(void* inp, SDL_Rect* src, SDL_Rect* dst, SDL_Rect* glrect);
+            void OverlayBlit(void* inp, SDL_Rect* src, SDL_Rect* dst, SDL_Rect* glrect);
+
+            // Accessors.
+            SDL_Surface* Surface();
+            SDL_Renderer* Renderer();
+            bool Accelerated();
+            bool GLMode();
+            int GetWidth();
+            int GetHeight();
+
+            // Run input callbacks and update states.
+            bool Input();
+
+            // Abstract remappable key functions.
+            int RegisterInput(SDL_Keycode key, GameCallback func);
+            void RegisterMouse(MouseCallback func);
+            bool GetInput(int index);
+            void RemapKey(int index, SDL_Keycode to);
+            void InputMode(InMode mode);
+
+            // Gets the AudioManager & TextManager for usage.
+            AudioManager* Audio();
+            TextManager* Text();
+            VertexController* Vertex();
+
+            // Exit methods.
+            void SetQuit();
+            bool GetQuit();
+
+            // Logic sync limiter @ 60fps
+            void StartSync();
+            void EndSync();
+
+            // Wrapper functions for tex load.
+            void* LoadImage(char* fname);
+            void* LoadImageMemory(void* mem, size_t len, char* type);
+            void* AccelImage(void* in);
+            void* GLTexImage(void* in);
+
+            ~ContextManager();
+        private:
+            // Lower init.
+            void _InitWindowSW(int width, int height, bool fulls);
+            void _InitWindowAC(int width, int height, bool fulls);
+            void _InitWindowGL(int width, int height, bool fulls);
+
+            // Lower init, logical.
+            void _InitWindowLogicalSW(int width_win, int height_win, int width_log, int height_log, bool fulls);
+            void _InitWindowLogicalAC(int width_win, int height_win, int width_log, int height_log, bool fulls);
+            void _InitWindowLogicalGL(int width_win, int height_win, int width_log, int height_log, bool fulls);
+
+            // Used to load default values in abscense of GNU exts
+            void DefaultVariables();
+
+            InMode inputmode;
+            SDL_Window* window;
+            SDL_Surface* surface, *surface_o;
+            SDL_Texture* texture, *texture_o;
+            SDL_Renderer* renderer;
+            SDL_GLContext glctx;
+
+            // use logical size
+            bool logicalRender;
+            bool accelerate;
+            bool opengl_mode;
+
+            GLuint fg, bg, fg_tex, bg_tex;
+
+            bool StartQuit;
+
+            AudioManager* audioMgr;
+            TextManager* txtMgr;
+            VertexController* vertCnt;
+
+            SDL_Keycode* inputMappings; // This can actually be used instead of InputList now. Weird.
+            bool* inputStates;
+            GameCallback* inputCallbacks;
+            MouseCallback mouseCallback;
+
+            int inputRegistered;
+
+            // Logic cap.
+            int logicRate;
+            int timeElapsed;
+            int syncElapsed;
+
+            // Width and height
+            int WIN_width;
+            int WIN_height;
+            int LOG_width;
+            int LOG_height;
+    };
 
 #endif
index aba73f7edb04eff53f5fc5d3d3baf962f48e3cb1..1297a9559ca78b2e8bd1b83750803abbef0eddfd 100644 (file)
@@ -1,48 +1,48 @@
 
 class TextManager {
-       public:
-               // Ctors & Dtors
-               TextManager(ContextManager* ct);
-               ~TextManager();
-
-               // Base font functions.
-               int LoadFont(char* fname, int size);
-               void Render(char* text);
-               void Render(char* text, int x, int y);
-
-               int TestLen(char* text);
-               void Outline(int pixels);
-
-               // Property functions.
-               // void SetStyle(int style);
-               void SetFontUsed(int font);
-               void SetColor(int r, int g, int b, int a);
-
-               // Splits string based on font.
-               void SplitStringByWidth(char* string, int max_w, int* OUT_num, char*** OUT_ptrs);
-
-               // Complex functions.
-               // Like printf but with formatting codes. Also not varargs.
-               // Should support this subset of standards:
-               // %d %u %x %c %s %f %%
-               // It also should have the following:
-               // %t - Font Index. Switches to font index.
-               // %p - Style. Sets style to S.
-               // %m - Expects an SDL_Color. Sets the color.
-               // void fnoutf(char* text, void** data);
-
-               // Uses control codes, unline fnoutf. Mainly intended for scripts.
-               // These ops should be implemented:
-               // ^b (bold) ^i (italic) ^r (normal / reset) ^fI (font -> i)
-               // ^cNNN (color -> #NNN) ^n (next line) ^c (clear)
-               // void scoutf(char* text);
-
-       private:
-               TTF_Font** fonts;
-               int current_font;
-               int fonts_loaded;
-               SDL_Color color;
-               ContextManager* ctx;
-               bool outline;
-               int outline_px;
+    public:
+        // Ctors & Dtors
+        TextManager(ContextManager* ct);
+        ~TextManager();
+
+        // Base font functions.
+        int LoadFont(char* fname, int size);
+        void Render(char* text);
+        void Render(char* text, int x, int y);
+
+        int TestLen(char* text);
+        void Outline(int pixels);
+
+        // Property functions.
+        // void SetStyle(int style);
+        void SetFontUsed(int font);
+        void SetColor(int r, int g, int b, int a);
+
+        // Splits string based on font.
+        void SplitStringByWidth(char* string, int max_w, int* OUT_num, char*** OUT_ptrs);
+
+        // Complex functions.
+        // Like printf but with formatting codes. Also not varargs.
+        // Should support this subset of standards:
+        // %d %u %x %c %s %f %%
+        // It also should have the following:
+        // %t - Font Index. Switches to font index.
+        // %p - Style. Sets style to S.
+        // %m - Expects an SDL_Color. Sets the color.
+        // void fnoutf(char* text, void** data);
+
+        // Uses control codes, unline fnoutf. Mainly intended for scripts.
+        // These ops should be implemented:
+        // ^b (bold) ^i (italic) ^r (normal / reset) ^fI (font -> i)
+        // ^cNNN (color -> #NNN) ^n (next line) ^c (clear)
+        // void scoutf(char* text);
+
+    private:
+        TTF_Font** fonts;
+        int current_font;
+        int fonts_loaded;
+        SDL_Color color;
+        ContextManager* ctx;
+        bool outline;
+        int outline_px;
 };
index b733d64551ec31a5702d9a815db857b05b7c6aab..75a399d35cca7ae335dfaa97647affe197c418e2 100644 (file)
@@ -2,78 +2,78 @@
 #define UDISPLAYABLE_HPP
 
 typedef enum {
-       Normal=1,
-       Hitbox=2,
-       Docked=3,
-       HitboxDocked=4,
-       Anim=5, // nyi
-       AnimHitbox=6, // nyi
-       AnimDocked=7, // nyi
-       AnimHitboxDocked=8 // nyi
+    Normal=1,
+    Hitbox=2,
+    Docked=3,
+    HitboxDocked=4,
+    Anim=5, // nyi
+    AnimHitbox=6, // nyi
+    AnimDocked=7, // nyi
+    AnimHitboxDocked=8 // nyi
 } UDisplayableMode;
 
-       class UDisplayable {
-               public:
-                       UDisplayable(ContextManager* ctx, char* fname); // Sets up in normal mode.
-                       UDisplayable(ContextManager* ctx, UDisplayableMode mode, char* fname); // Sets up in specified mode; params not set
-                       UDisplayable(ContextManager* ctx, UDisplayableMode mode, void* memory, int mSize); // Sets up from memory block in mode
-                       UDisplayable(ContextManager* cx, UDisplayableMode mode, SDL_Surface* bitmap_tmp);  // Loads from SDL_surface
+    class UDisplayable {
+        public:
+            UDisplayable(ContextManager* ctx, char* fname); // Sets up in normal mode.
+            UDisplayable(ContextManager* ctx, UDisplayableMode mode, char* fname); // Sets up in specified mode; params not set
+            UDisplayable(ContextManager* ctx, UDisplayableMode mode, void* memory, int mSize); // Sets up from memory block in mode
+            UDisplayable(ContextManager* cx, UDisplayableMode mode, SDL_Surface* bitmap_tmp);  // Loads from SDL_surface
 
-                       // All modes can use the following.
-                       void SetXY(double x, double y);
-                       void ModXY(double xd, double yd);
+            // All modes can use the following.
+            void SetXY(double x, double y);
+            void ModXY(double xd, double yd);
 
-                       double GetX();
-                       double GetY();
+            double GetX();
+            double GetY();
 
-                       int GetXI();
-                       int GetYI();
+            int GetXI();
+            int GetYI();
 
-                       int GetW();
-                       int GetH();
+            int GetW();
+            int GetH();
 
-                       void Blit();
+            void Blit();
 
-                       int* GetHitbox();
+            int* GetHitbox();
 
-                       ~UDisplayable();
+            ~UDisplayable();
 
-                       // Only specific modes can use these. Otherwise, they nop.
-                       void SetHitbox(int x, int y, int w, int h);
-                       void SetDock(int x, int y, int w, int h);
-                       void SetOverlay(bool state);
+            // Only specific modes can use these. Otherwise, they nop.
+            void SetHitbox(int x, int y, int w, int h);
+            void SetDock(int x, int y, int w, int h);
+            void SetOverlay(bool state);
 
-                       // Only animated Displayables can use these.
-                       void SetFrameWidth(int frameW);
-                       void NextFrame();
-                       void NextFrame(int f);
-                       void ResetFrame();
-                       void SetFrame(int f);
+            // Only animated Displayables can use these.
+            void SetFrameWidth(int frameW);
+            void NextFrame();
+            void NextFrame(int f);
+            void ResetFrame();
+            void SetFrame(int f);
 
 
-               protected:
-                       void DefaultVars();
+        protected:
+            void DefaultVars();
 
-                       double x, y;
-                       void* bitmap; // Will contain either a SDL_Surface or SDL_Texture
-                       SDL_Rect loc, clip;
-                       ContextManager* ctx;
-                       bool over;
+            double x, y;
+            void* bitmap; // Will contain either a SDL_Surface or SDL_Texture
+            SDL_Rect loc, clip;
+            ContextManager* ctx;
+            bool over;
 
-                       int bmp_w, bmp_h;
+            int bmp_w, bmp_h;
 
-                       // Used in docked mode
-                       int* frame;
-                       // Used in hitbox mode
-                       int* hitbox;
+            // Used in docked mode
+            int* frame;
+            // Used in hitbox mode
+            int* hitbox;
 
-                       // The current mode.
-                       UDisplayableMode dispMode;
+            // The current mode.
+            UDisplayableMode dispMode;
 
-                       // Used by animated mode.
-                       int frameIndex;
-                       int frameWidth;
+            // Used by animated mode.
+            int frameIndex;
+            int frameWidth;
 
-                       bool Error;
-       };
+            bool Error;
+    };
 #endif
index d6a04bb4673ea668e45f39fb073ee22bf6eeba52..5b1bf947132d395eb820844809b179b7ff7ebbc1 100644 (file)
@@ -2,51 +2,51 @@
 #define VTEXCONTROL_HPP
 
 typedef struct {
-       GLfloat x, y, z;
-       GLfloat u, v;
+    GLfloat x, y, z;
+    GLfloat u, v;
 } VtexData;
 
 typedef struct {
-       VtexData pts[4];
+    VtexData pts[4];
 } PrimData;
 
 typedef struct {
-       PrimData* v; // Vertex data
-       int count;   // How many vertexes
-       int pts;     // 4 or 3
-       GLuint t;    // Texture ptr
+    PrimData* v; // Vertex data
+    int count;   // How many vertexes
+    int pts;     // 4 or 3
+    GLuint t;    // Texture ptr
 } ModelData;
 
 class VertexController {
-       public:
-               VertexController(ContextManager* cx);
+    public:
+        VertexController(ContextManager* cx);
 
-               // Storage initializers.
-               void LoadModel();
+        // Storage initializers.
+        void LoadModel();
 
-               // Programmatic Model Creation.
-               void PushModel(int mode);
+        // Programmatic Model Creation.
+        void PushModel(int mode);
 
-               void PushTexture(char* fname);
+        void PushTexture(char* fname);
 
-               void PushQuad(  GLfloat x1, GLfloat y1, GLfloat z1, GLfloat u1, GLfloat v1,
-                                               GLfloat x2, GLfloat y2, GLfloat z2, GLfloat u2, GLfloat v2,
-                                               GLfloat x3, GLfloat y3, GLfloat z3, GLfloat u3, GLfloat v3,
-                                               GLfloat x4, GLfloat y4, GLfloat z4, GLfloat u4, GLfloat v4  );
+        void PushQuad(    GLfloat x1, GLfloat y1, GLfloat z1, GLfloat u1, GLfloat v1,
+                        GLfloat x2, GLfloat y2, GLfloat z2, GLfloat u2, GLfloat v2,
+                        GLfloat x3, GLfloat y3, GLfloat z3, GLfloat u3, GLfloat v3,
+                        GLfloat x4, GLfloat y4, GLfloat z4, GLfloat u4, GLfloat v4  );
 
-               void PushTri(   GLfloat x1, GLfloat y1, GLfloat z1, GLfloat u1, GLfloat v1,
-                                               GLfloat x2, GLfloat y2, GLfloat z2, GLfloat u2, GLfloat v2,
-                                               GLfloat x3, GLfloat y3, GLfloat z3, GLfloat u3, GLfloat v3  );
+        void PushTri(   GLfloat x1, GLfloat y1, GLfloat z1, GLfloat u1, GLfloat v1,
+                        GLfloat x2, GLfloat y2, GLfloat z2, GLfloat u2, GLfloat v2,
+                        GLfloat x3, GLfloat y3, GLfloat z3, GLfloat u3, GLfloat v3  );
 
-               void PushDone();
+        void PushDone();
 
 
-       private:
-               ModelData* models;
-               ContextManager* ctx;
-               int modelscount;
+    private:
+        ModelData* models;
+        ContextManager* ctx;
+        int modelscount;
 
-               void _AllocateVertex();
+        void _AllocateVertex();
 };
 
 #endif
index c70d64b15441affdeb57b8730be24d13409eb89c..b0db32e825d90b3b53999e53b90dc148188bafd3 100644 (file)
 #include <SDL_opengl.h>
 
 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
-    #define RED_MASK   0xff000000
-    #define GREEN_MASK         0x00ff0000
-    #define BLUE_MASK  0x0000ff00
-    #define ALPHA_MASK         0x000000ff
+    #define RED_MASK     0xff000000
+    #define GREEN_MASK     0x00ff0000
+    #define BLUE_MASK     0x0000ff00
+    #define ALPHA_MASK     0x000000ff
 #else
-    #define RED_MASK   0x000000ff
-    #define GREEN_MASK         0x0000ff00
-    #define BLUE_MASK  0x00ff0000
-    #define ALPHA_MASK         0xff000000
+    #define RED_MASK     0x000000ff
+    #define GREEN_MASK     0x0000ff00
+    #define BLUE_MASK     0x00ff0000
+    #define ALPHA_MASK     0xff000000
 #endif
 
 #include "AudioManager.hpp"
index fa00a8d56cf19cd05d6b8084f5bcd127ef06fab2..5a7881e22091deacff9883c02edab32afddbf25e 100644 (file)
 #include "Zero.hpp"
 
-       // Sets up.
-       AudioManager::AudioManager() {
-               if((Mix_Init(MIX_INIT_OGG) & MIX_INIT_OGG) != MIX_INIT_OGG) {
-                       // Failed to load.
-                       fprintf(stderr, "[W] Failed on Mix_Init for OGG format.\n");
-                       fprintf(stderr, "[W] Internal message: %s\n", Mix_GetError());
-               }
+    // Sets up.
+    AudioManager::AudioManager() {
+        if((Mix_Init(MIX_INIT_OGG) & MIX_INIT_OGG) != MIX_INIT_OGG) {
+            // Failed to load.
+            fprintf(stderr, "[W] Failed on Mix_Init for OGG format.\n");
+            fprintf(stderr, "[W] Internal message: %s\n", Mix_GetError());
+        }
 
-               if((Mix_Init(MIX_INIT_FLAC) & MIX_INIT_FLAC) != MIX_INIT_FLAC) {
-                       // Failed to load.
-                       fprintf(stderr, "[W] Failed on Mix_Init for FLAC format.\n");
-                       fprintf(stderr, "[W] Internal message: %s\n", Mix_GetError());
-               }
+        if((Mix_Init(MIX_INIT_FLAC) & MIX_INIT_FLAC) != MIX_INIT_FLAC) {
+            // Failed to load.
+            fprintf(stderr, "[W] Failed on Mix_Init for FLAC format.\n");
+            fprintf(stderr, "[W] Internal message: %s\n", Mix_GetError());
+        }
 
-               if((Mix_Init(MIX_INIT_MP3) & MIX_INIT_MP3) != MIX_INIT_MP3) {
-                       // Failed to load.
-                       fprintf(stderr, "[W] Failed on Mix_Init for MP3 format.\n");
-                       fprintf(stderr, "[W] Internal message: %s\n", Mix_GetError());
-               }
+        if((Mix_Init(MIX_INIT_MP3) & MIX_INIT_MP3) != MIX_INIT_MP3) {
+            // Failed to load.
+            fprintf(stderr, "[W] Failed on Mix_Init for MP3 format.\n");
+            fprintf(stderr, "[W] Internal message: %s\n", Mix_GetError());
+        }
 
-               uint16_t fmt = 0;
-               int freq = 0, chan = 0;
-               Mix_QuerySpec(&freq, &fmt, &chan);
+        uint16_t fmt = 0;
+        int freq = 0, chan = 0;
+        Mix_QuerySpec(&freq, &fmt, &chan);
 
-               if (Mix_OpenAudio(freq, fmt, chan, 1024)) {
-                       printf("[Mix:err] %s\n", Mix_GetError());
-                       exit(-7);
-               }
+        if (Mix_OpenAudio(freq, fmt, chan, 1024)) {
+            printf("[Mix:err] %s\n", Mix_GetError());
+            exit(-7);
+        }
 
-               Mix_AllocateChannels(64); // 32 Sfx + 1 Music
+        Mix_AllocateChannels(64); // 32 Sfx + 1 Music
 
-               MusicStore = NULL;
-               MusicCount = 0;
-               SfxStore = NULL;
-               SfxCount = 0;
-       }
+        MusicStore = NULL;
+        MusicCount = 0;
+        SfxStore = NULL;
+        SfxCount = 0;
+    }
 
-       // Cleans up everything.
-       AudioManager::~AudioManager() {
-               Mix_HaltChannel(-1);
-               Mix_HaltMusic();
+    // Cleans up everything.
+    AudioManager::~AudioManager() {
+        Mix_HaltChannel(-1);
+        Mix_HaltMusic();
 
-               while (SfxCount > 0) {
-                       Mix_FreeChunk(SfxStore[SfxCount-1]);
-                       --SfxCount;
-               }
+        while (SfxCount > 0) {
+            Mix_FreeChunk(SfxStore[SfxCount-1]);
+            --SfxCount;
+        }
 
-               while (MusicCount > 0) {
-                       Mix_FreeMusic(MusicStore[MusicCount-1]);
-                       --MusicCount;
-               }
+        while (MusicCount > 0) {
+            Mix_FreeMusic(MusicStore[MusicCount-1]);
+            --MusicCount;
+        }
 
-               free(SfxStore);
-               free(MusicStore);
+        free(SfxStore);
+        free(MusicStore);
 
-               Mix_CloseAudio();
+        Mix_CloseAudio();
 
-               while(Mix_Init(0))
-                       Mix_Quit();
-       }
+        while(Mix_Init(0))
+            Mix_Quit();
+    }
 
-       int AudioManager::LoadSfx(char* fname) {
-               ++SfxCount;
-               SfxStore = (Mix_Chunk**)realloc(SfxStore, sizeof(Mix_Chunk*) * SfxCount);
+    int AudioManager::LoadSfx(char* fname) {
+        ++SfxCount;
+        SfxStore = (Mix_Chunk**)realloc(SfxStore, sizeof(Mix_Chunk*) * SfxCount);
 
-               memset(&SfxStore[SfxCount-1], 0, sizeof(Mix_Chunk*));
+        memset(&SfxStore[SfxCount-1], 0, sizeof(Mix_Chunk*));
 
-               SfxStore[SfxCount-1] = NULL;
+        SfxStore[SfxCount-1] = NULL;
 
-               SfxStore[SfxCount-1] = Mix_LoadWAV(fname);
+        SfxStore[SfxCount-1] = Mix_LoadWAV(fname);
 
-               if(!SfxStore[SfxCount-1]) {
-                       --SfxCount;
-                       SfxStore = (Mix_Chunk**)realloc(SfxStore, sizeof(Mix_Chunk*) * SfxCount);
-                       return -1;
-               }
+        if(!SfxStore[SfxCount-1]) {
+            --SfxCount;
+            SfxStore = (Mix_Chunk**)realloc(SfxStore, sizeof(Mix_Chunk*) * SfxCount);
+            return -1;
+        }
 
-               return SfxCount - 1;
-       }
+        return SfxCount - 1;
+    }
 
-       int AudioManager::LoadMusic(char* fname) {
-               ++MusicCount;
-               MusicStore = (Mix_Music**)realloc(MusicStore, sizeof(Mix_Music*) * MusicCount);
+    int AudioManager::LoadMusic(char* fname) {
+        ++MusicCount;
+        MusicStore = (Mix_Music**)realloc(MusicStore, sizeof(Mix_Music*) * MusicCount);
 
-               memset(&MusicStore[MusicCount-1], 0, sizeof(Mix_Music*));
+        memset(&MusicStore[MusicCount-1], 0, sizeof(Mix_Music*));
 
-               MusicStore[MusicCount-1] = NULL;
+        MusicStore[MusicCount-1] = NULL;
 
-               MusicStore[MusicCount-1] = Mix_LoadMUS(fname);
+        MusicStore[MusicCount-1] = Mix_LoadMUS(fname);
 
-               if(!MusicStore[MusicCount-1]) {
-                       --MusicCount;
-                       MusicStore = (Mix_Music**)realloc(MusicStore, sizeof(Mix_Music*) * MusicCount);
-                       return -1;
-               }
+        if(!MusicStore[MusicCount-1]) {
+            --MusicCount;
+            MusicStore = (Mix_Music**)realloc(MusicStore, sizeof(Mix_Music*) * MusicCount);
+            return -1;
+        }
 
-               return MusicCount - 1;
-       }
+        return MusicCount - 1;
+    }
 
-       void AudioManager::PlaySfx(int index) {
-               if(index == -1)
-                       return;
+    void AudioManager::PlaySfx(int index) {
+        if(index == -1)
+            return;
 
-               if (index > SfxCount-1)
-                       return; // Not a valid index. No-op.
+        if (index > SfxCount-1)
+            return; // Not a valid index. No-op.
 
-               Mix_PlayChannel(-1, SfxStore[index], 0);
-       }
+        Mix_PlayChannel(-1, SfxStore[index], 0);
+    }
 
-       void AudioManager::PlaySfx(int index, int count) {
-               if(index == -1)
-                       return;
+    void AudioManager::PlaySfx(int index, int count) {
+        if(index == -1)
+            return;
 
-               if (index > SfxCount-1)
-                       return; // Not a valid index. No-op.
+        if (index > SfxCount-1)
+            return; // Not a valid index. No-op.
 
-               Mix_PlayChannel(-1, SfxStore[index], count);
-       }
+        Mix_PlayChannel(-1, SfxStore[index], count);
+    }
 
-       void AudioManager::PlayMusic(int index) {
-               if(index == -1)
-                       return;
+    void AudioManager::PlayMusic(int index) {
+        if(index == -1)
+            return;
 
-               // FIXME - Implement this.
-               Mix_PlayMusic(MusicStore[index], 0);
-       }
+        // FIXME - Implement this.
+        Mix_PlayMusic(MusicStore[index], 0);
+    }
 
-       void AudioManager::PlayMusicLoop(int index) {
-               if(index == -1)
-                       return;
+    void AudioManager::PlayMusicLoop(int index) {
+        if(index == -1)
+            return;
 
-               // FIXME - Implement this.
-               Mix_PlayMusic(MusicStore[index], -1);
-       }
+        // FIXME - Implement this.
+        Mix_PlayMusic(MusicStore[index], -1);
+    }
 
-       void AudioManager::PauseMusic() {
-               // FIXME - Implement this.
-               Mix_PauseMusic();
-       }
+    void AudioManager::PauseMusic() {
+        // FIXME - Implement this.
+        Mix_PauseMusic();
+    }
 
-       void AudioManager::UnloadSfx(int index) {
-               if(index == -1)
-                       return;
+    void AudioManager::UnloadSfx(int index) {
+        if(index == -1)
+            return;
 
-               Mix_FreeChunk(SfxStore[index]);
-       }
+        Mix_FreeChunk(SfxStore[index]);
+    }
 
-       void AudioManager::UnloadMusic(int index) {
-               if(index == -1)
-                       return;
+    void AudioManager::UnloadMusic(int index) {
+        if(index == -1)
+            return;
 
-               Mix_FreeMusic(MusicStore[index]);
-       }
+        Mix_FreeMusic(MusicStore[index]);
+    }
 
-       // Unload all sfx
-       void AudioManager::FlushSfx() {
-               Mix_HaltChannel(-1);
+    // Unload all sfx
+    void AudioManager::FlushSfx() {
+        Mix_HaltChannel(-1);
 
-               while (SfxCount > 0) {
-                       Mix_FreeChunk(SfxStore[SfxCount-1]);
-                       --SfxCount;
-               }
+        while (SfxCount > 0) {
+            Mix_FreeChunk(SfxStore[SfxCount-1]);
+            --SfxCount;
+        }
 
-               free(SfxStore);
-               SfxStore = NULL;
-       }
+        free(SfxStore);
+        SfxStore = NULL;
+    }
 
-       // Unload all music.
-       void AudioManager::FlushMusic() {
-               Mix_HaltMusic();
+    // Unload all music.
+    void AudioManager::FlushMusic() {
+        Mix_HaltMusic();
 
-               while (MusicCount > 0) {
-                       Mix_FreeMusic(MusicStore[MusicCount-1]);
-                       --MusicCount;
-               }
+        while (MusicCount > 0) {
+            Mix_FreeMusic(MusicStore[MusicCount-1]);
+            --MusicCount;
+        }
 
-               free(MusicStore);
-               MusicStore = NULL;
-       }
+        free(MusicStore);
+        MusicStore = NULL;
+    }
index aec0511d0e6256d4e3cc842eb2e3273207049d54..667f29e66b67c0da4c340b554ad18c871c3a083f 100644 (file)
 #include "Zero.hpp"
 
 
-       void ContextManager::DefaultVariables() {
-               inputmode = Medium;
-               window = NULL;
-               surface = NULL; surface_o = NULL;
-               texture = NULL; texture_o = NULL;
-               renderer = NULL;
-               // use logical size
-               logicalRender = false;
-               accelerate = false;
-               opengl_mode = false;
-
-               StartQuit = false;
-
-               audioMgr = NULL;
-               txtMgr = NULL;
-
-               inputMappings = NULL; // This can actually be used instead of InputList now. Weird.
-               inputStates = NULL;
-               inputCallbacks = NULL;
-               mouseCallback = NULL;
-
-               inputRegistered = 0;
-
-               // Logic cap.
-               logicRate = 60;
-               timeElapsed = 0;
-               syncElapsed = 0;
-
-               // Width and height
-               WIN_width = 0;
-               WIN_height = 0;
-               LOG_width = 0;
-               LOG_height = 0;
-       }
-
-       // Initializes SDL and saves stuff into the context.
-
-       ContextManager::ContextManager(int scr_width, int scr_height, bool fulls, DispMode_t disp) {
-               DefaultVariables();
-
-               if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) < 0) {
-                       #ifdef DEBUG_OVERKILL
-                       printf("[ContextManager~Ctor] SDL Init error w/ VIDEO|AUDIO. Msg rep: %s\n", SDL_GetError());
-                       #else
-                       printf("Error initializing SDL. Info:%s\n", SDL_GetError());
-                       #endif
-               }
-               else {
-                       this->InitWindow(scr_width, scr_height, fulls, disp);
-               }
-
-               audioMgr = new AudioManager();
-       }
-
-       // Delays window creation; Use InitWindow before doing anything.
-
-       ContextManager::ContextManager() {
-               DefaultVariables();
-
-               if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) < 0) {
-                       #ifdef DEBUG_OVERKILL
-                       printf("[ContextManager~Ctor] SDL Init error w/ VIDEO|AUDIO. Msg rep: %s\n", SDL_GetError());
-                       #else
-                       printf("Error initializing SDL. Info:%s\n", SDL_GetError());
-                       #endif
-               }
-
-               audioMgr = new AudioManager();
-       }
-
-       // Creates a window.
-
-       void ContextManager::InitWindow(int width, int height, bool fulls, DispMode_t disp) {
-               this->WIN_width = width;
-               this->WIN_height = height;
-               this->LOG_width = width;
-               this->LOG_height = height;
-
-               #ifdef DEBUG_OVERKILL
-               printf("[ContextManager::InitWindow] Params: w:%d h:%d f:%d a:%d\n", width, height, fulls, disp);
-               #endif
-
-               if (disp == Accel2d) {
-                       _InitWindowAC(width, height, fulls);
-                       this->texture_o = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, width, height);
-                       SDL_SetTextureBlendMode(this->texture_o, SDL_BLENDMODE_BLEND);
-               }
-               else if (disp == Software) {
-                       _InitWindowSW(width, height, fulls);
-                       this->surface_o = SDL_CreateRGBSurface(0, width, height, 32, RED_MASK, GREEN_MASK, BLUE_MASK, ALPHA_MASK);
-                       SDL_SetSurfaceBlendMode(this->surface_o, SDL_BLENDMODE_BLEND);
-               }
-               else if (disp == OpenGL) {
-                       _InitWindowGL(width, height, fulls);
-               }
-
-               txtMgr = new TextManager(this);
-       }
-
-       void ContextManager::_InitWindowSW(int width, int height, bool fulls) {
-               // Add title setting function.
-               if(!fulls)
-                       this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_SHOWN);
-               else
-                       this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_FULLSCREEN);
-               if(this->window == NULL) {
-                       fprintf(stderr, "[E] Error creating window. Info:\n");
-                       fprintf(stderr, "[E] %s\n", SDL_GetError());
-                       fprintf(stderr, "[E] This is fatal. Dying.");
-                       exit(-1);
-               }
-               else {
-                       SDL_SetHintWithPriority(SDL_HINT_RENDER_VSYNC, "1", SDL_HINT_OVERRIDE);
-                       if(!SDL_CreateRenderer( this->window, -1, 0 )) {
-                               fprintf(stderr, "[E] Error creating renderer. Info:\n");
-                               fprintf(stderr, "[E] %s\n", SDL_GetError());
-                               fprintf(stderr, "[E] This is fatal. Dying.");
-                               exit(-1);
-                       }
-
-                       this->logicalRender = false;
-               }
-       }
-
-       void ContextManager::_InitWindowAC(int width, int height, bool fulls) {
-               this->accelerate = true;
-
-               if(!fulls)
-                       this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_SHOWN);
-               else
-                       this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_FULLSCREEN);
-               if(this->window == NULL) {
-                       fprintf(stderr, "[E] Error creating window. Info:\n");
-                       fprintf(stderr, "[E] %s\n", SDL_GetError());
-                       fprintf(stderr, "[E] This is fatal. Dying.");
-                       exit(-1);
-               }
-               else {
-                       this->renderer = SDL_CreateRenderer( this->window, -1, SDL_RENDERER_ACCELERATED );
-                       if(this->renderer == NULL) {
-                               fprintf(stderr, "[E] Error creating renderer. Info:\n");
-                               fprintf(stderr, "[E] %s\n", SDL_GetError());
-                               fprintf(stderr, "[E] This is fatal. Dying.");
-                               exit(-1);
-                       }
-                       else {
-                               this->logicalRender = true;
-
-                               this->texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, width, height);
-                       }
-               }
-       }
-
-       // OpenGL window. Note - a LOT functions different in this mode.
-       void ContextManager::_InitWindowGL(int width, int height, bool fulls) {
-               opengl_mode = true;
-
-               SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
-
-               // Request OpenGL 3.0 context. Yes, not 3.1, 3.2, 4.0. THREE POINT O'.
-               // Why? I use the fixed function pipeline which is gonzo in >3.1
-               // and I'm not about to learn a new api that consists of VBOs, FBOs,
-               // and shader code (which btw, is retarded.)
-               SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
-               SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
-
-               if(!fulls)
-                       this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_SHOWN|SDL_WINDOW_OPENGL);
-               else
-                       this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_FULLSCREEN|SDL_WINDOW_OPENGL);
-
-               glctx = SDL_GL_CreateContext(window);
-
-               glewExperimental = GL_TRUE;
-               glewInit();
-
-               if(glGenFramebuffers == NULL || glBindFramebuffer == NULL || glFramebufferTexture == NULL || glDrawBuffers == NULL) {
-                       fprintf(stderr, "[ERR] Glew didn't load some extensions needed.\n");
-                       fprintf(stderr, "[ERR] I assume your card doesn't support them.\n");
-                       exit(-11);
-               }
-
-
-               glEnable( GL_TEXTURE_2D );
-
-               glViewport( 0, 0, width, height );
-
-               glClear( GL_COLOR_BUFFER_BIT );
-
-               glMatrixMode( GL_PROJECTION );
-               glLoadIdentity();
-
-               glOrtho(0.0f, width, height, 0.0f, -1.0f, 1.0f);
-
-               glMatrixMode( GL_MODELVIEW );
-               glLoadIdentity();
-
-               vertCnt = new VertexController(this);
-
-               // Create Renderable Textures.
-               // Unfortunately, GL is an asshole and I have no clue.
-
-               glGenFramebuffers(1, &bg);
-               glBindFramebuffer(GL_FRAMEBUFFER, bg);
-
-               glGenTextures(1, &bg_tex);
-               glBindTexture(GL_TEXTURE_2D, bg_tex);
-
-               glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
-               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-
-               glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, bg_tex, 0);
-
-               GLenum colbuf_bg[1] = {GL_COLOR_ATTACHMENT0};
-               glDrawBuffers(1, colbuf_bg);
-
-               glGenFramebuffers(1, &fg);
-               glBindFramebuffer(GL_FRAMEBUFFER, fg);
-
-               glGenTextures(1, &fg_tex);
-               glBindTexture(GL_TEXTURE_2D, fg_tex);
-
-               glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
-               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-
-               glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, fg_tex, 0);
-
-               GLenum colbuf_fg[1] = {GL_COLOR_ATTACHMENT1};
-               glDrawBuffers(1, colbuf_fg);
-       }
-
-       // Init window with a logical size and a real one. Determines which backend to use.
-       void ContextManager::InitWindowLogical(int width_win, int height_win, int width_log, int height_log, bool fulls, DispMode_t disp) {
-               this->LOG_width = width_log;
-               this->LOG_height = height_log;
-               this->WIN_width = width_win;
-               this->WIN_height = height_win;
-
-               #ifdef DEBUG_OVERKILL
-               printf("[ContextManager::InitWindowLogical] phyw:%d phyh:%d logw:%d logh:%d f:%d a:%d\n", width_win, height_win, width_log, height_log, fulls, disp);
-               #endif
-
-               if (disp == Accel2d) {
-                       _InitWindowLogicalAC(width_win, height_win, width_log, height_log, fulls);
-                       this->texture_o = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, width_win, height_win);
-                       SDL_SetTextureBlendMode(this->texture_o, SDL_BLENDMODE_BLEND);
-               }
-               else if (disp == Software) {
-                       _InitWindowLogicalSW(width_win, height_win, width_log, height_log, fulls);
-                       this->surface_o = SDL_CreateRGBSurface(0, width_win, height_win, 32, RED_MASK, GREEN_MASK, BLUE_MASK, ALPHA_MASK);
-                       SDL_SetSurfaceBlendMode(this->surface_o, SDL_BLENDMODE_BLEND);
-               }
-               else if (disp == OpenGL) {
-                       _InitWindowLogicalGL(width_win, height_win, width_log, height_log, fulls);
-               }
-
-               txtMgr = new TextManager(this);
-       }
-
-       // Init window with a logical size and a real one.
-       void ContextManager::_InitWindowLogicalSW(int width_win, int height_win, int width_log, int height_log, bool fulls) {
-               if(!fulls)
-                       this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width_win, height_win, SDL_WINDOW_SHOWN);
-               else
-                       this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width_win, height_win, SDL_WINDOW_FULLSCREEN);
-               if(this->window == NULL) {
-                       fprintf(stderr, "[E] Error creating window. Info:\n");
-                       fprintf(stderr, "[E] %s\n", SDL_GetError());
-                       fprintf(stderr, "[E] This is fatal. Dying.");
-                       exit(-1);
-               }
-               else {
-                       this->renderer = SDL_CreateRenderer( this->window, -1, 0 );
-                       if(this->renderer == NULL) {
-                               fprintf(stderr, "[E] Error creating renderer. Info:\n");
-                               fprintf(stderr, "[E] %s\n", SDL_GetError());
-                               fprintf(stderr, "[E] This is fatal. Dying.");
-                               exit(-1);
-                       }
-                       else {
-                               this->logicalRender = true;
-
-                               this->surface = SDL_CreateRGBSurface(0, width_log, height_log, 32, RED_MASK, GREEN_MASK, BLUE_MASK, ALPHA_MASK);
-                       }
-               }
-       }
-
-               // Init window with a logical size and a real one.
-       void ContextManager::_InitWindowLogicalAC(int width_win, int height_win, int width_log, int height_log, bool fulls) {
-               this->accelerate = true;
-               if(!fulls)
-                       this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width_win, height_win, SDL_WINDOW_SHOWN);
-               else
-                       this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width_win, height_win, SDL_WINDOW_FULLSCREEN);
-               if(this->window == NULL) {
-                       fprintf(stderr, "[E] Error creating window. Info:\n");
-                       fprintf(stderr, "[E] %s\n", SDL_GetError());
-                       fprintf(stderr, "[E] This is fatal. Dying.");
-                       exit(-1);
-               }
-               else {
-                       this->renderer = SDL_CreateRenderer( this->window, -1, SDL_RENDERER_ACCELERATED );
-                       if(this->renderer == NULL) {
-                               fprintf(stderr, "[E] Error creating renderer. Info:\n");
-                               fprintf(stderr, "[E] %s\n", SDL_GetError());
-                               fprintf(stderr, "[E] This is fatal. Dying.");
-                               exit(-1);
-                       }
-                       else {
-                               this->logicalRender = true;
-
-                               this->texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, width_log, height_log);
-                       }
-               }
-       }
-
-       // OpenGL window. Note - a LOT functions different in this mode.
-       void ContextManager::_InitWindowLogicalGL(int width_win, int height_win, int width_log, int height_log, bool fulls) {
-
-               opengl_mode = true;
-
-               SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
-
-               // Request OpenGL 3.0 context. Yes, not 3.1, 3.2, 4.0. THREE POINT O'.
-               // Why? I use the fixed function pipeline which is gonzo in >3.1
-               // and I'm not about to learn a new api that consists of VBOs, FBOs,
-               // and shader code (which btw, is retarded.)
-               SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
-               SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
-
-               if(!fulls)
-                       this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width_win, height_win, SDL_WINDOW_SHOWN|SDL_WINDOW_OPENGL);
-               else
-                       this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width_win, height_win, SDL_WINDOW_FULLSCREEN|SDL_WINDOW_OPENGL);
-
-               glctx = SDL_GL_CreateContext(window);
-
-               glewExperimental = GL_TRUE;
-               glewInit();
-
-               if(glGenFramebuffers == NULL || glBindFramebuffer == NULL || glFramebufferTexture == NULL || glDrawBuffers == NULL) {
-                       fprintf(stderr, "[ERR] Glew didn't load some extensions needed.\n");
-                       fprintf(stderr, "[ERR] I assume your card doesn't support them.\n");
-                       exit(-11);
-               }
-
-               glEnable( GL_TEXTURE_2D );
-
-               glViewport( 0, 0, width_win, height_win );
-
-               glClear( GL_COLOR_BUFFER_BIT );
-
-               glMatrixMode( GL_PROJECTION );
-               glLoadIdentity();
-
-               glOrtho(0.0f, width_win, height_win, 0.0f, -1.0f, 1.0f);
-
-               glMatrixMode( GL_MODELVIEW );
-               glLoadIdentity();
-
-               vertCnt = new VertexController(this);
-
-               fprintf(stderr, "[info] Generating FBOs...(bg) ");
-
-               glGenFramebuffers(1, &bg);
-               glBindFramebuffer(GL_FRAMEBUFFER, bg);
-
-               glGenTextures(1, &bg_tex);
-               glBindTexture(GL_TEXTURE_2D, bg_tex);
-
-               glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width_log, height_log, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
-               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-
-               glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, bg_tex, 0);
-
-               GLenum colbuf_bg[1] = {GL_COLOR_ATTACHMENT0};
-               glDrawBuffers(1, colbuf_bg);
-
-               glGenFramebuffers(1, &fg);
-               glBindFramebuffer(GL_FRAMEBUFFER, fg);
-
-               glGenTextures(1, &fg_tex);
-               glBindTexture(GL_TEXTURE_2D, fg_tex);
-
-               glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width_win, height_win, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
-               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-
-               glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, fg_tex, 0);
-
-               GLenum colbuf_fg[1] = {GL_COLOR_ATTACHMENT1};
-               glDrawBuffers(1, colbuf_fg);
-
-               fprintf(stderr, "[info] OpenGL initialized.\n");
-       }
-
-       // Clears the display to black.
+    void ContextManager::DefaultVariables() {
+        inputmode = Medium;
+        window = NULL;
+        surface = NULL; surface_o = NULL;
+        texture = NULL; texture_o = NULL;
+        renderer = NULL;
+        // use logical size
+        logicalRender = false;
+        accelerate = false;
+        opengl_mode = false;
+
+        StartQuit = false;
+
+        audioMgr = NULL;
+        txtMgr = NULL;
+
+        inputMappings = NULL; // This can actually be used instead of InputList now. Weird.
+        inputStates = NULL;
+        inputCallbacks = NULL;
+        mouseCallback = NULL;
+
+        inputRegistered = 0;
+
+        // Logic cap.
+        logicRate = 60;
+        timeElapsed = 0;
+        syncElapsed = 0;
+
+        // Width and height
+        WIN_width = 0;
+        WIN_height = 0;
+        LOG_width = 0;
+        LOG_height = 0;
+    }
+
+    // Initializes SDL and saves stuff into the context.
+
+    ContextManager::ContextManager(int scr_width, int scr_height, bool fulls, DispMode_t disp) {
+        DefaultVariables();
+
+        if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) < 0) {
+            #ifdef DEBUG_OVERKILL
+            printf("[ContextManager~Ctor] SDL Init error w/ VIDEO|AUDIO. Msg rep: %s\n", SDL_GetError());
+            #else
+            printf("Error initializing SDL. Info:%s\n", SDL_GetError());
+            #endif
+        }
+        else {
+            this->InitWindow(scr_width, scr_height, fulls, disp);
+        }
+
+        audioMgr = new AudioManager();
+    }
+
+    // Delays window creation; Use InitWindow before doing anything.
+
+    ContextManager::ContextManager() {
+        DefaultVariables();
+
+        if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) < 0) {
+            #ifdef DEBUG_OVERKILL
+            printf("[ContextManager~Ctor] SDL Init error w/ VIDEO|AUDIO. Msg rep: %s\n", SDL_GetError());
+            #else
+            printf("Error initializing SDL. Info:%s\n", SDL_GetError());
+            #endif
+        }
+
+        audioMgr = new AudioManager();
+    }
+
+    // Creates a window.
+
+    void ContextManager::InitWindow(int width, int height, bool fulls, DispMode_t disp) {
+        this->WIN_width = width;
+        this->WIN_height = height;
+        this->LOG_width = width;
+        this->LOG_height = height;
+
+        #ifdef DEBUG_OVERKILL
+        printf("[ContextManager::InitWindow] Params: w:%d h:%d f:%d a:%d\n", width, height, fulls, disp);
+        #endif
+
+        if (disp == Accel2d) {
+            _InitWindowAC(width, height, fulls);
+            this->texture_o = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, width, height);
+            SDL_SetTextureBlendMode(this->texture_o, SDL_BLENDMODE_BLEND);
+        }
+        else if (disp == Software) {
+            _InitWindowSW(width, height, fulls);
+            this->surface_o = SDL_CreateRGBSurface(0, width, height, 32, RED_MASK, GREEN_MASK, BLUE_MASK, ALPHA_MASK);
+            SDL_SetSurfaceBlendMode(this->surface_o, SDL_BLENDMODE_BLEND);
+        }
+        else if (disp == OpenGL) {
+            _InitWindowGL(width, height, fulls);
+        }
+
+        txtMgr = new TextManager(this);
+    }
+
+    void ContextManager::_InitWindowSW(int width, int height, bool fulls) {
+        // Add title setting function.
+        if(!fulls)
+            this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_SHOWN);
+        else
+            this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_FULLSCREEN);
+        if(this->window == NULL) {
+            fprintf(stderr, "[E] Error creating window. Info:\n");
+            fprintf(stderr, "[E] %s\n", SDL_GetError());
+            fprintf(stderr, "[E] This is fatal. Dying.");
+            exit(-1);
+        }
+        else {
+            SDL_SetHintWithPriority(SDL_HINT_RENDER_VSYNC, "1", SDL_HINT_OVERRIDE);
+            if(!SDL_CreateRenderer( this->window, -1, 0 )) {
+                fprintf(stderr, "[E] Error creating renderer. Info:\n");
+                fprintf(stderr, "[E] %s\n", SDL_GetError());
+                fprintf(stderr, "[E] This is fatal. Dying.");
+                exit(-1);
+            }
+
+            this->logicalRender = false;
+        }
+    }
+
+    void ContextManager::_InitWindowAC(int width, int height, bool fulls) {
+        this->accelerate = true;
+
+        if(!fulls)
+            this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_SHOWN);
+        else
+            this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_FULLSCREEN);
+        if(this->window == NULL) {
+            fprintf(stderr, "[E] Error creating window. Info:\n");
+            fprintf(stderr, "[E] %s\n", SDL_GetError());
+            fprintf(stderr, "[E] This is fatal. Dying.");
+            exit(-1);
+        }
+        else {
+            this->renderer = SDL_CreateRenderer( this->window, -1, SDL_RENDERER_ACCELERATED );
+            if(this->renderer == NULL) {
+                fprintf(stderr, "[E] Error creating renderer. Info:\n");
+                fprintf(stderr, "[E] %s\n", SDL_GetError());
+                fprintf(stderr, "[E] This is fatal. Dying.");
+                exit(-1);
+            }
+            else {
+                this->logicalRender = true;
+
+                this->texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, width, height);
+            }
+        }
+    }
+
+    // OpenGL window. Note - a LOT functions different in this mode.
+    void ContextManager::_InitWindowGL(int width, int height, bool fulls) {
+        opengl_mode = true;
+
+        SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
+
+        // Request OpenGL 3.0 context. Yes, not 3.1, 3.2, 4.0. THREE POINT O'.
+        // Why? I use the fixed function pipeline which is gonzo in >3.1
+        // and I'm not about to learn a new api that consists of VBOs, FBOs,
+        // and shader code (which btw, is retarded.)
+        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
+        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
+
+        if(!fulls)
+            this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_SHOWN|SDL_WINDOW_OPENGL);
+        else
+            this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_FULLSCREEN|SDL_WINDOW_OPENGL);
+
+        glctx = SDL_GL_CreateContext(window);
+
+        glewExperimental = GL_TRUE;
+        glewInit();
+
+        if(glGenFramebuffers == NULL || glBindFramebuffer == NULL || glFramebufferTexture == NULL || glDrawBuffers == NULL) {
+            fprintf(stderr, "[ERR] Glew didn't load some extensions needed.\n");
+            fprintf(stderr, "[ERR] I assume your card doesn't support them.\n");
+            exit(-11);
+        }
+
+
+        glEnable( GL_TEXTURE_2D );
+
+        glViewport( 0, 0, width, height );
+
+        glClear( GL_COLOR_BUFFER_BIT );
+
+        glMatrixMode( GL_PROJECTION );
+        glLoadIdentity();
+
+        glOrtho(0.0f, width, height, 0.0f, -1.0f, 1.0f);
+
+        glMatrixMode( GL_MODELVIEW );
+        glLoadIdentity();
+
+        vertCnt = new VertexController(this);
+
+        // Create Renderable Textures.
+        // Unfortunately, GL is an asshole and I have no clue.
+
+        glGenFramebuffers(1, &bg);
+        glBindFramebuffer(GL_FRAMEBUFFER, bg);
+
+        glGenTextures(1, &bg_tex);
+        glBindTexture(GL_TEXTURE_2D, bg_tex);
+
+        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+
+        glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, bg_tex, 0);
+
+        GLenum colbuf_bg[1] = {GL_COLOR_ATTACHMENT0};
+        glDrawBuffers(1, colbuf_bg);
+
+        glGenFramebuffers(1, &fg);
+        glBindFramebuffer(GL_FRAMEBUFFER, fg);
+
+        glGenTextures(1, &fg_tex);
+        glBindTexture(GL_TEXTURE_2D, fg_tex);
+
+        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+
+        glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, fg_tex, 0);
+
+        GLenum colbuf_fg[1] = {GL_COLOR_ATTACHMENT1};
+        glDrawBuffers(1, colbuf_fg);
+    }
+
+    // Init window with a logical size and a real one. Determines which backend to use.
+    void ContextManager::InitWindowLogical(int width_win, int height_win, int width_log, int height_log, bool fulls, DispMode_t disp) {
+        this->LOG_width = width_log;
+        this->LOG_height = height_log;
+        this->WIN_width = width_win;
+        this->WIN_height = height_win;
+
+        #ifdef DEBUG_OVERKILL
+        printf("[ContextManager::InitWindowLogical] phyw:%d phyh:%d logw:%d logh:%d f:%d a:%d\n", width_win, height_win, width_log, height_log, fulls, disp);
+        #endif
+
+        if (disp == Accel2d) {
+            _InitWindowLogicalAC(width_win, height_win, width_log, height_log, fulls);
+            this->texture_o = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, width_win, height_win);
+            SDL_SetTextureBlendMode(this->texture_o, SDL_BLENDMODE_BLEND);
+        }
+        else if (disp == Software) {
+            _InitWindowLogicalSW(width_win, height_win, width_log, height_log, fulls);
+            this->surface_o = SDL_CreateRGBSurface(0, width_win, height_win, 32, RED_MASK, GREEN_MASK, BLUE_MASK, ALPHA_MASK);
+            SDL_SetSurfaceBlendMode(this->surface_o, SDL_BLENDMODE_BLEND);
+        }
+        else if (disp == OpenGL) {
+            _InitWindowLogicalGL(width_win, height_win, width_log, height_log, fulls);
+        }
+
+        txtMgr = new TextManager(this);
+    }
+
+    // Init window with a logical size and a real one.
+    void ContextManager::_InitWindowLogicalSW(int width_win, int height_win, int width_log, int height_log, bool fulls) {
+        if(!fulls)
+            this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width_win, height_win, SDL_WINDOW_SHOWN);
+        else
+            this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width_win, height_win, SDL_WINDOW_FULLSCREEN);
+        if(this->window == NULL) {
+            fprintf(stderr, "[E] Error creating window. Info:\n");
+            fprintf(stderr, "[E] %s\n", SDL_GetError());
+            fprintf(stderr, "[E] This is fatal. Dying.");
+            exit(-1);
+        }
+        else {
+            this->renderer = SDL_CreateRenderer( this->window, -1, 0 );
+            if(this->renderer == NULL) {
+                fprintf(stderr, "[E] Error creating renderer. Info:\n");
+                fprintf(stderr, "[E] %s\n", SDL_GetError());
+                fprintf(stderr, "[E] This is fatal. Dying.");
+                exit(-1);
+            }
+            else {
+                this->logicalRender = true;
+
+                this->surface = SDL_CreateRGBSurface(0, width_log, height_log, 32, RED_MASK, GREEN_MASK, BLUE_MASK, ALPHA_MASK);
+            }
+        }
+    }
+
+        // Init window with a logical size and a real one.
+    void ContextManager::_InitWindowLogicalAC(int width_win, int height_win, int width_log, int height_log, bool fulls) {
+        this->accelerate = true;
+        if(!fulls)
+            this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width_win, height_win, SDL_WINDOW_SHOWN);
+        else
+            this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width_win, height_win, SDL_WINDOW_FULLSCREEN);
+        if(this->window == NULL) {
+            fprintf(stderr, "[E] Error creating window. Info:\n");
+            fprintf(stderr, "[E] %s\n", SDL_GetError());
+            fprintf(stderr, "[E] This is fatal. Dying.");
+            exit(-1);
+        }
+        else {
+            this->renderer = SDL_CreateRenderer( this->window, -1, SDL_RENDERER_ACCELERATED );
+            if(this->renderer == NULL) {
+                fprintf(stderr, "[E] Error creating renderer. Info:\n");
+                fprintf(stderr, "[E] %s\n", SDL_GetError());
+                fprintf(stderr, "[E] This is fatal. Dying.");
+                exit(-1);
+            }
+            else {
+                this->logicalRender = true;
+
+                this->texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, width_log, height_log);
+            }
+        }
+    }
+
+    // OpenGL window. Note - a LOT functions different in this mode.
+    void ContextManager::_InitWindowLogicalGL(int width_win, int height_win, int width_log, int height_log, bool fulls) {
+
+        opengl_mode = true;
+
+        SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
+
+        // Request OpenGL 3.0 context. Yes, not 3.1, 3.2, 4.0. THREE POINT O'.
+        // Why? I use the fixed function pipeline which is gonzo in >3.1
+        // and I'm not about to learn a new api that consists of VBOs, FBOs,
+        // and shader code (which btw, is retarded.)
+        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
+        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
+
+        if(!fulls)
+            this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width_win, height_win, SDL_WINDOW_SHOWN|SDL_WINDOW_OPENGL);
+        else
+            this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width_win, height_win, SDL_WINDOW_FULLSCREEN|SDL_WINDOW_OPENGL);
+
+        glctx = SDL_GL_CreateContext(window);
+
+        glewExperimental = GL_TRUE;
+        glewInit();
+
+        if(glGenFramebuffers == NULL || glBindFramebuffer == NULL || glFramebufferTexture == NULL || glDrawBuffers == NULL) {
+            fprintf(stderr, "[ERR] Glew didn't load some extensions needed.\n");
+            fprintf(stderr, "[ERR] I assume your card doesn't support them.\n");
+            exit(-11);
+        }
+
+        glEnable( GL_TEXTURE_2D );
+
+        glViewport( 0, 0, width_win, height_win );
+
+        glClear( GL_COLOR_BUFFER_BIT );
+
+        glMatrixMode( GL_PROJECTION );
+        glLoadIdentity();
+
+        glOrtho(0.0f, width_win, height_win, 0.0f, -1.0f, 1.0f);
+
+        glMatrixMode( GL_MODELVIEW );
+        glLoadIdentity();
+
+        vertCnt = new VertexController(this);
+
+        fprintf(stderr, "[info] Generating FBOs...(bg) ");
+
+        glGenFramebuffers(1, &bg);
+        glBindFramebuffer(GL_FRAMEBUFFER, bg);
+
+        glGenTextures(1, &bg_tex);
+        glBindTexture(GL_TEXTURE_2D, bg_tex);
+
+        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width_log, height_log, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+
+        glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, bg_tex, 0);
+
+        GLenum colbuf_bg[1] = {GL_COLOR_ATTACHMENT0};
+        glDrawBuffers(1, colbuf_bg);
+
+        glGenFramebuffers(1, &fg);
+        glBindFramebuffer(GL_FRAMEBUFFER, fg);
+
+        glGenTextures(1, &fg_tex);
+        glBindTexture(GL_TEXTURE_2D, fg_tex);
+
+        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width_win, height_win, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+
+        glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, fg_tex, 0);
+
+        GLenum colbuf_fg[1] = {GL_COLOR_ATTACHMENT1};
+        glDrawBuffers(1, colbuf_fg);
+
+        fprintf(stderr, "[info] OpenGL initialized.\n");
+    }
+
+    // Clears the display to black.
 
-       void ContextManager::Clear() {
-               if(this->StartQuit) return;
+    void ContextManager::Clear() {
+        if(this->StartQuit) return;
 
-               if (accelerate) {
-                       if (logicalRender) {
-                               SDL_SetRenderTarget(renderer, texture);
-                               SDL_RenderClear(renderer);
-                               SDL_SetRenderTarget(renderer, NULL);
-                       }
+        if (accelerate) {
+            if (logicalRender) {
+                SDL_SetRenderTarget(renderer, texture);
+                SDL_RenderClear(renderer);
+                SDL_SetRenderTarget(renderer, NULL);
+            }
 
-                       SDL_SetRenderTarget(renderer, texture_o);
-                       SDL_RenderClear(renderer);
-                       SDL_SetRenderTarget(renderer, NULL);
+            SDL_SetRenderTarget(renderer, texture_o);
+            SDL_RenderClear(renderer);
+            SDL_SetRenderTarget(renderer, NULL);
 
-                       SDL_RenderClear(renderer);
-               }
-               else if (opengl_mode) {
-                       glBindFramebuffer(GL_FRAMEBUFFER, this->bg);
-                       glViewport(0,0,LOG_height,LOG_width);
-                       glClearColor(0,0,0,0);
-                       glClear(GL_COLOR_BUFFER_BIT);
-                       
-                       glBindFramebuffer(GL_FRAMEBUFFER, this->fg);
-                       glViewport(0,0,WIN_height,WIN_width);
-                       glClearColor(0,0,0,0);
-                       glClear(GL_COLOR_BUFFER_BIT);
+            SDL_RenderClear(renderer);
+        }
+        else if (opengl_mode) {
+            glBindFramebuffer(GL_FRAMEBUFFER, this->bg);
+            glViewport(0,0,LOG_height,LOG_width);
+            glClearColor(0,0,0,0);
+            glClear(GL_COLOR_BUFFER_BIT);
+            
+            glBindFramebuffer(GL_FRAMEBUFFER, this->fg);
+            glViewport(0,0,WIN_height,WIN_width);
+            glClearColor(0,0,0,0);
+            glClear(GL_COLOR_BUFFER_BIT);
 
-                       glBindFramebuffer(GL_FRAMEBUFFER, 0);
-                       glViewport(0,0,WIN_height,WIN_width);
-                       glClearColor(0,0,0,0);
-                       glClear(GL_COLOR_BUFFER_BIT);
-               }
-               else {
-                       if (logicalRender)
-                               SDL_FillRect(this->surface, NULL, SDL_MapRGB(this->surface->format, 0x0, 0x0, 0x0));
+            glBindFramebuffer(GL_FRAMEBUFFER, 0);
+            glViewport(0,0,WIN_height,WIN_width);
+            glClearColor(0,0,0,0);
+            glClear(GL_COLOR_BUFFER_BIT);
+        }
+        else {
+            if (logicalRender)
+                SDL_FillRect(this->surface, NULL, SDL_MapRGB(this->surface->format, 0x0, 0x0, 0x0));
 
-                       SDL_FillRect(this->surface_o, NULL, SDL_MapRGBA(this->surface_o->format, 0x0, 0x0, 0x0, 0x0));
+            SDL_FillRect(this->surface_o, NULL, SDL_MapRGBA(this->surface_o->format, 0x0, 0x0, 0x0, 0x0));
 
-                       SDL_FillRect(SDL_GetWindowSurface(this->window), NULL, SDL_MapRGB(SDL_GetWindowSurface(this->window)->format, 0x0, 0x0, 0x0));
-               }
-       }
+            SDL_FillRect(SDL_GetWindowSurface(this->window), NULL, SDL_MapRGB(SDL_GetWindowSurface(this->window)->format, 0x0, 0x0, 0x0));
+        }
+    }
 
-       // Clears the display to black.
+    // Clears the display to black.
 
-       void ContextManager::ClearOverlay() {
-               if(this->StartQuit) return;
+    void ContextManager::ClearOverlay() {
+        if(this->StartQuit) return;
 
-               if (accelerate) {
-                       SDL_SetRenderTarget(renderer, texture_o);
-                       SDL_RenderClear(renderer);
-                       SDL_SetRenderTarget(renderer, NULL);
-               }
-               else if (opengl_mode) {
-                       glBindFramebuffer(GL_FRAMEBUFFER, this->fg);
+        if (accelerate) {
+            SDL_SetRenderTarget(renderer, texture_o);
+            SDL_RenderClear(renderer);
+            SDL_SetRenderTarget(renderer, NULL);
+        }
+        else if (opengl_mode) {
+            glBindFramebuffer(GL_FRAMEBUFFER, this->fg);
 
-                       glViewport(0,0,WIN_height,WIN_width);
-                       glClearColor(0,0,0,0);
-                       glClear(GL_COLOR_BUFFER_BIT);
+            glViewport(0,0,WIN_height,WIN_width);
+            glClearColor(0,0,0,0);
+            glClear(GL_COLOR_BUFFER_BIT);
 
-                       glBindFramebuffer(GL_FRAMEBUFFER, 0);
-               }
-               else {
-                       SDL_FillRect(this->surface_o, NULL, SDL_MapRGBA(this->surface_o->format, 0, 0, 0, 0));
-               }
-       }
-
-       // Flush any changes in the surface to screen
+            glBindFramebuffer(GL_FRAMEBUFFER, 0);
+        }
+        else {
+            SDL_FillRect(this->surface_o, NULL, SDL_MapRGBA(this->surface_o->format, 0, 0, 0, 0));
+        }
+    }
+
+    // Flush any changes in the surface to screen
 
-       void ContextManager::Flush() {
-               if(this->StartQuit) return;
-               if (accelerate) {
-                       if(logicalRender) {
-                               SDL_Rect dst, src;
+    void ContextManager::Flush() {
+        if(this->StartQuit) return;
+        if (accelerate) {
+            if(logicalRender) {
+                SDL_Rect dst, src;
 
-                               src.x = 0;
-                               src.y = 0;
-                               src.w = LOG_width;
-                               src.h = LOG_height;
-
-                               dst.x = 0;
-                               dst.y = 0;
-                               dst.w = WIN_width;
-                               dst.h = WIN_height;
-
-                               SDL_RenderCopy(renderer, texture, &src, &dst);
-                       }
-
-                       SDL_RenderCopy(renderer, texture_o, NULL, NULL);
-
-                       SDL_RenderPresent(renderer);
-               }
-               else if (opengl_mode) {
-                       // Render prep.
-
-                       GLfloat x_tex, y_tex, x2_tex, y2_tex;
-                       x_tex  = 0.0f;
-                       y_tex  = 0.0f;
-                       x2_tex = 1.0f;
-                       y2_tex = 1.0f;
-
-
-                       GLfloat x_box, y_box, x2_box, y2_box;
-                       x_box = 0;
-                       y_box = WIN_height;
-                       x2_box = WIN_width;
-                       y2_box = 0;
-
-                       glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); //Don't use special coloring
-
-                       glBindTexture( GL_TEXTURE_2D, bg_tex );
-
-                       glBegin( GL_QUADS );
-                               //Bottom-left vertex (corner)
-                               glTexCoord2f( x_tex, y_tex );
-                               glVertex3f( x_box,  y2_box, 0.0f );
-
-                               //Bottom-right vertex (corner)
-                               glTexCoord2f( x2_tex, y_tex );
-                               glVertex3f( x2_box, y2_box, 0.0f );
-
-                               //Top-right vertex (corner)
-                               glTexCoord2f( x2_tex, y2_tex );
-                               glVertex3f( x2_box, y_box,  0.0f );
-
-                               //Top-left vertex (corner)
-                               glTexCoord2f( x_tex, y2_tex );
-                               glVertex3f( x_box,  y_box,  0.0f );
-                       glEnd();
-
-                       glBindTexture( GL_TEXTURE_2D, fg_tex );
-
-                       glBegin( GL_QUADS );
-                               //Bottom-left vertex (corner)
-                               glTexCoord2f( x_tex, y_tex );
-                               glVertex3f( x_box,  y2_box, 0.0f );
+                src.x = 0;
+                src.y = 0;
+                src.w = LOG_width;
+                src.h = LOG_height;
+
+                dst.x = 0;
+                dst.y = 0;
+                dst.w = WIN_width;
+                dst.h = WIN_height;
+
+                SDL_RenderCopy(renderer, texture, &src, &dst);
+            }
+
+            SDL_RenderCopy(renderer, texture_o, NULL, NULL);
+
+            SDL_RenderPresent(renderer);
+        }
+        else if (opengl_mode) {
+            // Render prep.
+
+            GLfloat x_tex, y_tex, x2_tex, y2_tex;
+            x_tex  = 0.0f;
+            y_tex  = 0.0f;
+            x2_tex = 1.0f;
+            y2_tex = 1.0f;
+
+
+            GLfloat x_box, y_box, x2_box, y2_box;
+            x_box = 0;
+            y_box = WIN_height;
+            x2_box = WIN_width;
+            y2_box = 0;
+
+            glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); //Don't use special coloring
+
+            glBindTexture( GL_TEXTURE_2D, bg_tex );
+
+            glBegin( GL_QUADS );
+                //Bottom-left vertex (corner)
+                glTexCoord2f( x_tex, y_tex );
+                glVertex3f( x_box,  y2_box, 0.0f );
+
+                //Bottom-right vertex (corner)
+                glTexCoord2f( x2_tex, y_tex );
+                glVertex3f( x2_box, y2_box, 0.0f );
+
+                //Top-right vertex (corner)
+                glTexCoord2f( x2_tex, y2_tex );
+                glVertex3f( x2_box, y_box,  0.0f );
+
+                //Top-left vertex (corner)
+                glTexCoord2f( x_tex, y2_tex );
+                glVertex3f( x_box,  y_box,  0.0f );
+            glEnd();
+
+            glBindTexture( GL_TEXTURE_2D, fg_tex );
+
+            glBegin( GL_QUADS );
+                //Bottom-left vertex (corner)
+                glTexCoord2f( x_tex, y_tex );
+                glVertex3f( x_box,  y2_box, 0.0f );
 
-                               //Bottom-right vertex (corner)
-                               glTexCoord2f( x2_tex, y_tex );
-                               glVertex3f( x2_box, y2_box, 0.0f );
+                //Bottom-right vertex (corner)
+                glTexCoord2f( x2_tex, y_tex );
+                glVertex3f( x2_box, y2_box, 0.0f );
 
-                               //Top-right vertex (corner)
-                               glTexCoord2f( x2_tex, y2_tex );
-                               glVertex3f( x2_box, y_box,  0.0f );
-
-                               //Top-left vertex (corner)
-                               glTexCoord2f( x_tex, y2_tex );
-                               glVertex3f( x_box,  y_box,  0.0f );
-                       glEnd();
-
-                       glBindTexture( GL_TEXTURE_2D, 0 );
-
-                       SDL_GL_SwapWindow(window);
-               }
-               else {
-                       if(logicalRender)
-                               SDL_BlitScaled(this->surface, NULL, SDL_GetWindowSurface(this->window), NULL);
-
-                       SDL_BlitScaled(this->surface_o, NULL, SDL_GetWindowSurface(this->window), NULL);
+                //Top-right vertex (corner)
+                glTexCoord2f( x2_tex, y2_tex );
+                glVertex3f( x2_box, y_box,  0.0f );
+
+                //Top-left vertex (corner)
+                glTexCoord2f( x_tex, y2_tex );
+                glVertex3f( x_box,  y_box,  0.0f );
+            glEnd();
+
+            glBindTexture( GL_TEXTURE_2D, 0 );
+
+            SDL_GL_SwapWindow(window);
+        }
+        else {
+            if(logicalRender)
+                SDL_BlitScaled(this->surface, NULL, SDL_GetWindowSurface(this->window), NULL);
+
+            SDL_BlitScaled(this->surface_o, NULL, SDL_GetWindowSurface(this->window), NULL);
 
-                       SDL_UpdateWindowSurface(this->window);
-               }
-       }
+            SDL_UpdateWindowSurface(this->window);
+        }
+    }
 
-       // Return the internal surface for external blits.
-       SDL_Surface* ContextManager::Surface() {
-               if(this->StartQuit) return NULL;
-               if(accelerate) return NULL;
+    // Return the internal surface for external blits.
+    SDL_Surface* ContextManager::Surface() {
+        if(this->StartQuit) return NULL;
+        if(accelerate) return NULL;
 
-               if( logicalRender )
-                       return this->surface;
+        if( logicalRender )
+            return this->surface;
 
-               return SDL_GetWindowSurface(this->window);
-       }
+        return SDL_GetWindowSurface(this->window);
+    }
 
-       // return the renderer.
-       SDL_Renderer* ContextManager::Renderer() {
-               return renderer;
-       }
+    // return the renderer.
+    SDL_Renderer* ContextManager::Renderer() {
+        return renderer;
+    }
 
-       // return the mode.
-       bool ContextManager::Accelerated() {
-               return accelerate;
-       }
+    // return the mode.
+    bool ContextManager::Accelerated() {
+        return accelerate;
+    }
 
-       // return the mode.
-       bool ContextManager::GLMode() {
-               return opengl_mode;
-       }
+    // return the mode.
+    bool ContextManager::GLMode() {
+        return opengl_mode;
+    }
 
-       // Blit data via cast. inp should be a SDL_Surface or SDL_Texture.
-       void ContextManager::Blit(void* inp, SDL_Rect* src, SDL_Rect* dst, SDL_Rect* glrect) {
-               if(accelerate) {
-                       if (logicalRender) SDL_SetRenderTarget(renderer, texture);
+    // Blit data via cast. inp should be a SDL_Surface or SDL_Texture.
+    void ContextManager::Blit(void* inp, SDL_Rect* src, SDL_Rect* dst, SDL_Rect* glrect) {
+        if(accelerate) {
+            if (logicalRender) SDL_SetRenderTarget(renderer, texture);
 
-                       SDL_RenderCopy(renderer, (SDL_Texture*)inp, src, dst);
+            SDL_RenderCopy(renderer, (SDL_Texture*)inp, src, dst);
 
-                       if (logicalRender) SDL_SetRenderTarget(renderer, NULL);
-               }
-               else if(opengl_mode) {
-                       GLuint in = ((GLuint*)inp)[0];
+            if (logicalRender) SDL_SetRenderTarget(renderer, NULL);
+        }
+        else if(opengl_mode) {
+            GLuint in = ((GLuint*)inp)[0];
 
-                       glBindFramebuffer(GL_FRAMEBUFFER, this->bg);
-                       glViewport(0,0,LOG_height,LOG_width);
+            glBindFramebuffer(GL_FRAMEBUFFER, this->bg);
+            glViewport(0,0,LOG_height,LOG_width);
 
-                       // printf("[GL] (blit) in: %d\n", in);
+            // printf("[GL] (blit) in: %d\n", in);
 
-                       GLfloat x_tex, y_tex, x2_tex, y2_tex;
-                       if(glrect == NULL) {
-                               x_tex  = 0.0f;
-                               y_tex  = 0.0f;
-                               x2_tex = 1.0f;
-                               y2_tex = 1.0f;
-                       }
-                       else {
-                               GLfloat tex_width, tex_height;
+            GLfloat x_tex, y_tex, x2_tex, y2_tex;
+            if(glrect == NULL) {
+                x_tex  = 0.0f;
+                y_tex  = 0.0f;
+                x2_tex = 1.0f;
+                y2_tex = 1.0f;
+            }
+            else {
+                GLfloat tex_width, tex_height;
 
-                               tex_width = 1.0f / ((float)glrect->w);
-                               tex_height = 1.0f / ((float)glrect->h);
-
-                               x_tex  = tex_width   * ((float)(src->x));
-                               y_tex = tex_height   * ((float)(src->y));
-                               x2_tex = tex_width   * ((float)(src->x + src->w));
-                               y2_tex  = tex_height * ((float)(src->y + src->h));
+                tex_width = 1.0f / ((float)glrect->w);
+                tex_height = 1.0f / ((float)glrect->h);
+
+                x_tex  = tex_width   * ((float)(src->x));
+                y_tex = tex_height   * ((float)(src->y));
+                x2_tex = tex_width   * ((float)(src->x + src->w));
+                y2_tex  = tex_height * ((float)(src->y + src->h));
 
-                               // printf("Detail Calculation] tex_w:%f tex_h:%f x_t:%f y_t:%f x2_t:%f y2_t:%f\n", tex_width, tex_height, x_tex, y_tex, x2_tex, y2_tex);
-                       }
+                // printf("Detail Calculation] tex_w:%f tex_h:%f x_t:%f y_t:%f x2_t:%f y2_t:%f\n", tex_width, tex_height, x_tex, y_tex, x2_tex, y2_tex);
+            }
 
-                       GLfloat x_box, y_box, x2_box, y2_box;
-                       x_box = dst->x;
-                       y_box = dst->y + dst->h;
-                       x2_box = dst->x + dst->w;
-                       y2_box = dst->y;
-
-                       //printf("[GL] Box: x.%f y.%f x2.%f y2.%f \n", x_box, y_box, x2_box, y2_box);
-
-                       glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); //Don't use special coloring
-
-                       // Bind the texture to which subsequent calls refer to
-                       glBindTexture( GL_TEXTURE_2D, in );
-
-                       glBegin( GL_QUADS );
-                               //Bottom-left vertex (corner)
-                               glTexCoord2f( x_tex, y_tex );
-                               glVertex3f( x_box,  y2_box, 0.0f );
-
-                               //Bottom-right vertex (corner)
-                               glTexCoord2f( x2_tex, y_tex );
-                               glVertex3f( x2_box, y2_box, 0.0f );
-
-                               //Top-right vertex (corner)
-                               glTexCoord2f( x2_tex, y2_tex );
-                               glVertex3f( x2_box, y_box,  0.0f );
-
-                               //Top-left vertex (corner)
-                               glTexCoord2f( x_tex, y2_tex );
-                               glVertex3f( x_box,  y_box,  0.0f );
-                       glEnd();
-
-                       glBindTexture( GL_TEXTURE_2D, 0 );
-
-                       glBindFramebuffer(GL_FRAMEBUFFER, 0);
-                       glViewport(0,0,WIN_height,WIN_width);
-
-               }
-               else {
-                       SDL_BlitSurface((SDL_Surface*)inp, src, surface, dst);
-               }
-       }
-
-       // Blit data to overlay via cast. inp should be a SDL_Surface or SDL_Texture.
-       void ContextManager::OverlayBlit(void* inp, SDL_Rect* src, SDL_Rect* dst, SDL_Rect* glrect) {
-               // Recalculate src and dst based on upscale.
-               double OUTW_Ratio, OUTH_Ratio;
-               OUTW_Ratio = (double)WIN_width  / (double)LOG_width;
-               OUTH_Ratio = (double)WIN_height / (double)LOG_height;
-
-               dst->x = (int)(((double)dst->x) * OUTW_Ratio);
-               dst->y = (int)(((double)dst->y) * OUTH_Ratio);
-               if(OUTW_Ratio < 1) dst->w = (int)(((double)dst->w) * OUTW_Ratio);
-               if(OUTH_Ratio < 1) dst->h = (int)(((double)dst->h) * OUTH_Ratio);
-
-               if(accelerate) {
-                       if (logicalRender) SDL_SetRenderTarget(renderer, texture_o);
-
-                       SDL_RenderCopy(renderer, (SDL_Texture*)inp, src, dst);
-
-                       if (logicalRender) SDL_SetRenderTarget(renderer, NULL);
-               }
-               else if(opengl_mode) {
-                       GLuint in = ((GLuint*)inp)[0];
-
-                       glBindFramebuffer(GL_FRAMEBUFFER, this->fg);
-                       glViewport(0,0,WIN_height,WIN_width);
-
-                       GLfloat x, y, x2, y2;
-                       x = 1.0f / glrect->x;
-                       y = 1.0f / glrect->y;
-                       x2 = 1.0f / (glrect->w + glrect->x);
-                       y2 = 1.0f / (glrect->h + glrect->y);
-
-                       // Bind the texture to which subsequent calls refer to
-                       glBindTexture( GL_TEXTURE_2D, in );
-
-                       glBegin( GL_QUADS );
-                               //Bottom-left vertex (corner)
-                               glTexCoord2f( x, y );
-                               glVertex3i( dst->x,          dst->y + dst->h, 0.0f );
-
-                               //Bottom-right vertex (corner)
-                               glTexCoord2f( x2, y );
-                               glVertex3i( dst->x + dst->w, dst->y + dst->h, 0.0f );
-
-                               //Top-right vertex (corner)
-                               glTexCoord2f( x2, y2 );
-                               glVertex3i( dst->x + dst->w, dst->y, 0.0f );
-
-                               //Top-left vertex (corner)
-                               glTexCoord2f( x, y2 );
-                               glVertex3i( dst->x,          dst->y, 0.0f );
-                       glEnd();
-
-                       glBindTexture( GL_TEXTURE_2D, 0 );
-
-                       glBindFramebuffer(GL_FRAMEBUFFER, 0);
-                       glViewport(0,0,WIN_height,WIN_width);
-
-               }
-               else {
-                       SDL_BlitSurface((SDL_Surface*)inp, src, surface_o, dst);
-               }
-       }
-
-       // Gets width of display
-       int ContextManager::GetWidth() {
-               return this->LOG_width;
-       }
-
-       // Gets height of display
-       int ContextManager::GetHeight() {
-               return this->LOG_height;
-       }
-
-       // Checks input events for matches and run callbacks.
-       bool ContextManager::Input() {
-               if(this->StartQuit) return this->StartQuit;
-
-               SDL_Event evt;
-               for(int i = 0; i < this->inputmode && SDL_PollEvent(&evt); i++) {
-                       for(int j = 0; j < inputRegistered; j++) {
-                               if(inputMappings[j] == evt.key.keysym.sym) {
-                                       bool down = false;
-                                       if(evt.type == SDL_KEYDOWN)
-                                               down = true;
-                                       inputStates[j] = down;
-                                       if((evt.type == SDL_KEYDOWN || evt.type == SDL_KEYUP) && inputCallbacks[j] != NULL) {
-                                               (inputCallbacks[j])(down);
-                                       }
-                               }
-                       }
-                       if((evt.type == SDL_MOUSEBUTTONDOWN || evt.type == SDL_MOUSEBUTTONUP) && mouseCallback != NULL) {
-                               if(evt.button.button == SDL_BUTTON_LEFT) {
-                                       (mouseCallback)(evt.button.x, evt.button.y, (evt.type == SDL_MOUSEBUTTONDOWN), true, false, false);
-                               }
-                               if(evt.button.button == SDL_BUTTON_MIDDLE) {
-                                       (mouseCallback)(evt.button.x, evt.button.y, (evt.type == SDL_MOUSEBUTTONDOWN), false, true, false);
-                               }
-                               if(evt.button.button == SDL_BUTTON_RIGHT) {
-                                       (mouseCallback)(evt.button.x, evt.button.y, (evt.type == SDL_MOUSEBUTTONDOWN), false, false, true);
-                               }
-                       }
-               }
-
-               return this->StartQuit;
-       }
-
-       // Changes the Input Mode used.
-       void ContextManager::InputMode(InMode in) {
-               inputmode = in;
-       }
-
-       // Register an abstract handler. Returns an int corresponding to the index for the mapping.
-       int ContextManager::RegisterInput(SDL_Keycode key, GameCallback func) {
-
-               // Apply input mappings.
-
-               ++inputRegistered;
-
-               // allocate space for current keys+1.
-               inputMappings = (SDL_Keycode*)realloc(inputMappings, sizeof(SDL_Keycode) * inputRegistered);
-               inputCallbacks = (GameCallback*)realloc(inputCallbacks, sizeof(GameCallback) * inputRegistered);
-               inputStates = (bool*)realloc(inputStates, sizeof(bool) * inputRegistered);
-
-               // Actually apply the new callback
-               inputMappings[inputRegistered-1] = key;
-               inputCallbacks[inputRegistered-1] = func;
-               inputStates[inputRegistered-1] = false;
-
-               // Return the index.
-               return inputRegistered-1;
-       }
-
-       void ContextManager::RegisterMouse(MouseCallback func) {
-               mouseCallback = func;
-       }
-
-       // Get input via abstract ID.
-       bool ContextManager::GetInput(int index) {
-               return inputStates[index];
-       }
-
-       // Remap abstract key.
-       void ContextManager::RemapKey(int index, SDL_Keycode to) {
-               // Check if something is already mapped to 'to'.
-               int reg = -1;
-               for(int i = 0; i < inputRegistered; i++) {
-                       if(inputMappings[i] == to) {
-                               reg = i;
-                       }
-               }
-               // Remap, swap if necessary.
-               if(reg > -1)
-                       inputMappings[reg] = inputMappings[index];
-               inputMappings[index] = to;
-       }
-
-       // Set Quit flag.
-       void ContextManager::SetQuit() {
-               this->StartQuit = true;
-       }
-
-       bool ContextManager::GetQuit() {
-               return this->StartQuit;
-       }
-
-       // Destroy context.
-
-       ContextManager::~ContextManager() {
-               delete audioMgr;
-               SDL_DestroyWindow(window);
-               SDL_Quit();
-       }
-
-       // Gets the audio manager.
-       AudioManager* ContextManager::Audio() {
-               return audioMgr;
-       }
-
-       // Gets the audio manager.
-       TextManager* ContextManager::Text() {
-               return txtMgr;
-       }
-
-       void ContextManager::StartSync() {
-               timeElapsed = SDL_GetTicks();
-       }
-
-       void ContextManager::EndSync() {
-               while (1) {
-                       double currentTime = SDL_GetTicks();
-                       if(currentTime - timeElapsed > 1000 / logicRate)
-                               return;
-                       SDL_Delay((1000 / logicRate) / 8);
-               }
-       }
-
-       void ContextManager::SetTitle(char* title) {
-               SDL_SetWindowTitle(window, title);
-       }
-
-       void* ContextManager::LoadImage(char* fname) {
-               return IMG_Load(fname);
-       }
-
-       void* ContextManager::LoadImageMemory(void* mem, size_t len, char* type) {
-               SDL_RWops* rwo = SDL_RWFromMem(mem, len);
-               SDL_Surface* bitmap_tmp = IMG_LoadTyped_RW(rwo, 0, type);
-
-               return bitmap_tmp;
-       }
-
-       void* ContextManager::AccelImage(void* in) {
-               if(accelerate) {
-                       SDL_Texture* tex = SDL_CreateTextureFromSurface(renderer, (SDL_Surface*)in);
-                       SDL_FreeSurface((SDL_Surface*)in);
-
-                       return tex;
-               }
-               return in;
-       }
-
-       void* ContextManager::GLTexImage(void* in) {
-
-               if(!opengl_mode) return in;
-
-               GLuint *tex = (GLuint*)calloc(sizeof(GLuint), 1);
-               GLenum texture_format;
-               GLint  nOfColors;
-               SDL_Surface* sfc = (SDL_Surface*)in;
-
-               if ( (sfc->w & (sfc->w - 1)) != 0 ) {
-                       printf("[WARN] Image width not ^2.\n");
-               }
-
-               // Also check if the height is a power of 2
-               if ( (sfc->h & (sfc->h - 1)) != 0 ) {
-                       printf("[WARN] Image height not ^2.\n");
-               }
-
-               // get the number of channels in the SDL surface
-               nOfColors = sfc->format->BytesPerPixel;
-               if (nOfColors == 4)     // contains an alpha channel
-               {
-                       if (sfc->format->Rmask == 0x000000ff)
-                               texture_format = GL_RGBA;
-                       else
-                               texture_format = GL_BGRA;
-               }
-               else if (nOfColors == 3)     // no alpha channel
-               {
-                       if (sfc->format->Rmask == 0x000000ff)
-                               texture_format = GL_RGB;
-                       else
-                               texture_format = GL_BGR;
-               }
-               else {
-                       printf("[WARN] Image not truecolor (32bpp). Expect explosions.\n");
-                       // this error should not go unhandled
-               }
-
-               // Have OpenGL generate a texture object handle for us
-               glGenTextures( 1, tex );
-
-               // Bind the texture object
-               glBindTexture( GL_TEXTURE_2D, tex[0] );
-
-               // Edit the texture object's image data using the information SDL_Surface gives us
-               glTexImage2D( GL_TEXTURE_2D, 0, nOfColors, sfc->w, sfc->h, 0, texture_format, GL_UNSIGNED_BYTE, sfc->pixels );
-
-               // Set the texture's stretching properties
-               glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
-               glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
-
-               // printf("[GL] tex: %d\n", tex[0]);
-
-               return tex;
-       }
+            GLfloat x_box, y_box, x2_box, y2_box;
+            x_box = dst->x;
+            y_box = dst->y + dst->h;
+            x2_box = dst->x + dst->w;
+            y2_box = dst->y;
+
+            //printf("[GL] Box: x.%f y.%f x2.%f y2.%f \n", x_box, y_box, x2_box, y2_box);
+
+            glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); //Don't use special coloring
+
+            // Bind the texture to which subsequent calls refer to
+            glBindTexture( GL_TEXTURE_2D, in );
+
+            glBegin( GL_QUADS );
+                //Bottom-left vertex (corner)
+                glTexCoord2f( x_tex, y_tex );
+                glVertex3f( x_box,  y2_box, 0.0f );
+
+                //Bottom-right vertex (corner)
+                glTexCoord2f( x2_tex, y_tex );
+                glVertex3f( x2_box, y2_box, 0.0f );
+
+                //Top-right vertex (corner)
+                glTexCoord2f( x2_tex, y2_tex );
+                glVertex3f( x2_box, y_box,  0.0f );
+
+                //Top-left vertex (corner)
+                glTexCoord2f( x_tex, y2_tex );
+                glVertex3f( x_box,  y_box,  0.0f );
+            glEnd();
+
+            glBindTexture( GL_TEXTURE_2D, 0 );
+
+            glBindFramebuffer(GL_FRAMEBUFFER, 0);
+            glViewport(0,0,WIN_height,WIN_width);
+
+        }
+        else {
+            SDL_BlitSurface((SDL_Surface*)inp, src, surface, dst);
+        }
+    }
+
+    // Blit data to overlay via cast. inp should be a SDL_Surface or SDL_Texture.
+    void ContextManager::OverlayBlit(void* inp, SDL_Rect* src, SDL_Rect* dst, SDL_Rect* glrect) {
+        // Recalculate src and dst based on upscale.
+        double OUTW_Ratio, OUTH_Ratio;
+        OUTW_Ratio = (double)WIN_width  / (double)LOG_width;
+        OUTH_Ratio = (double)WIN_height / (double)LOG_height;
+
+        dst->x = (int)(((double)dst->x) * OUTW_Ratio);
+        dst->y = (int)(((double)dst->y) * OUTH_Ratio);
+        if(OUTW_Ratio < 1) dst->w = (int)(((double)dst->w) * OUTW_Ratio);
+        if(OUTH_Ratio < 1) dst->h = (int)(((double)dst->h) * OUTH_Ratio);
+
+        if(accelerate) {
+            if (logicalRender) SDL_SetRenderTarget(renderer, texture_o);
+
+            SDL_RenderCopy(renderer, (SDL_Texture*)inp, src, dst);
+
+            if (logicalRender) SDL_SetRenderTarget(renderer, NULL);
+        }
+        else if(opengl_mode) {
+            GLuint in = ((GLuint*)inp)[0];
+
+            glBindFramebuffer(GL_FRAMEBUFFER, this->fg);
+            glViewport(0,0,WIN_height,WIN_width);
+
+            GLfloat x, y, x2, y2;
+            x = 1.0f / glrect->x;
+            y = 1.0f / glrect->y;
+            x2 = 1.0f / (glrect->w + glrect->x);
+            y2 = 1.0f / (glrect->h + glrect->y);
+
+            // Bind the texture to which subsequent calls refer to
+            glBindTexture( GL_TEXTURE_2D, in );
+
+            glBegin( GL_QUADS );
+                //Bottom-left vertex (corner)
+                glTexCoord2f( x, y );
+                glVertex3i( dst->x,          dst->y + dst->h, 0.0f );
+
+                //Bottom-right vertex (corner)
+                glTexCoord2f( x2, y );
+                glVertex3i( dst->x + dst->w, dst->y + dst->h, 0.0f );
+
+                //Top-right vertex (corner)
+                glTexCoord2f( x2, y2 );
+                glVertex3i( dst->x + dst->w, dst->y, 0.0f );
+
+                //Top-left vertex (corner)
+                glTexCoord2f( x, y2 );
+                glVertex3i( dst->x,          dst->y, 0.0f );
+            glEnd();
+
+            glBindTexture( GL_TEXTURE_2D, 0 );
+
+            glBindFramebuffer(GL_FRAMEBUFFER, 0);
+            glViewport(0,0,WIN_height,WIN_width);
+
+        }
+        else {
+            SDL_BlitSurface((SDL_Surface*)inp, src, surface_o, dst);
+        }
+    }
+
+    // Gets width of display
+    int ContextManager::GetWidth() {
+        return this->LOG_width;
+    }
+
+    // Gets height of display
+    int ContextManager::GetHeight() {
+        return this->LOG_height;
+    }
+
+    // Checks input events for matches and run callbacks.
+    bool ContextManager::Input() {
+        if(this->StartQuit) return this->StartQuit;
+
+        SDL_Event evt;
+        for(int i = 0; i < this->inputmode && SDL_PollEvent(&evt); i++) {
+            for(int j = 0; j < inputRegistered; j++) {
+                if(inputMappings[j] == evt.key.keysym.sym) {
+                    bool down = false;
+                    if(evt.type == SDL_KEYDOWN)
+                        down = true;
+                    inputStates[j] = down;
+                    if((evt.type == SDL_KEYDOWN || evt.type == SDL_KEYUP) && inputCallbacks[j] != NULL) {
+                        (inputCallbacks[j])(down);
+                    }
+                }
+            }
+            if((evt.type == SDL_MOUSEBUTTONDOWN || evt.type == SDL_MOUSEBUTTONUP) && mouseCallback != NULL) {
+                if(evt.button.button == SDL_BUTTON_LEFT) {
+                    (mouseCallback)(evt.button.x, evt.button.y, (evt.type == SDL_MOUSEBUTTONDOWN), true, false, false);
+                }
+                if(evt.button.button == SDL_BUTTON_MIDDLE) {
+                    (mouseCallback)(evt.button.x, evt.button.y, (evt.type == SDL_MOUSEBUTTONDOWN), false, true, false);
+                }
+                if(evt.button.button == SDL_BUTTON_RIGHT) {
+                    (mouseCallback)(evt.button.x, evt.button.y, (evt.type == SDL_MOUSEBUTTONDOWN), false, false, true);
+                }
+            }
+        }
+
+        return this->StartQuit;
+    }
+
+    // Changes the Input Mode used.
+    void ContextManager::InputMode(InMode in) {
+        inputmode = in;
+    }
+
+    // Register an abstract handler. Returns an int corresponding to the index for the mapping.
+    int ContextManager::RegisterInput(SDL_Keycode key, GameCallback func) {
+
+        // Apply input mappings.
+
+        ++inputRegistered;
+
+        // allocate space for current keys+1.
+        inputMappings = (SDL_Keycode*)realloc(inputMappings, sizeof(SDL_Keycode) * inputRegistered);
+        inputCallbacks = (GameCallback*)realloc(inputCallbacks, sizeof(GameCallback) * inputRegistered);
+        inputStates = (bool*)realloc(inputStates, sizeof(bool) * inputRegistered);
+
+        // Actually apply the new callback
+        inputMappings[inputRegistered-1] = key;
+        inputCallbacks[inputRegistered-1] = func;
+        inputStates[inputRegistered-1] = false;
+
+        // Return the index.
+        return inputRegistered-1;
+    }
+
+    void ContextManager::RegisterMouse(MouseCallback func) {
+        mouseCallback = func;
+    }
+
+    // Get input via abstract ID.
+    bool ContextManager::GetInput(int index) {
+        return inputStates[index];
+    }
+
+    // Remap abstract key.
+    void ContextManager::RemapKey(int index, SDL_Keycode to) {
+        // Check if something is already mapped to 'to'.
+        int reg = -1;
+        for(int i = 0; i < inputRegistered; i++) {
+            if(inputMappings[i] == to) {
+                reg = i;
+            }
+        }
+        // Remap, swap if necessary.
+        if(reg > -1)
+            inputMappings[reg] = inputMappings[index];
+        inputMappings[index] = to;
+    }
+
+    // Set Quit flag.
+    void ContextManager::SetQuit() {
+        this->StartQuit = true;
+    }
+
+    bool ContextManager::GetQuit() {
+        return this->StartQuit;
+    }
+
+    // Destroy context.
+
+    ContextManager::~ContextManager() {
+        delete audioMgr;
+        SDL_DestroyWindow(window);
+        SDL_Quit();
+    }
+
+    // Gets the audio manager.
+    AudioManager* ContextManager::Audio() {
+        return audioMgr;
+    }
+
+    // Gets the audio manager.
+    TextManager* ContextManager::Text() {
+        return txtMgr;
+    }
+
+    void ContextManager::StartSync() {
+        timeElapsed = SDL_GetTicks();
+    }
+
+    void ContextManager::EndSync() {
+        while (1) {
+            double currentTime = SDL_GetTicks();
+            if(currentTime - timeElapsed > 1000 / logicRate)
+                return;
+            SDL_Delay((1000 / logicRate) / 8);
+        }
+    }
+
+    void ContextManager::SetTitle(char* title) {
+        SDL_SetWindowTitle(window, title);
+    }
+
+    void* ContextManager::LoadImage(char* fname) {
+        return IMG_Load(fname);
+    }
+
+    void* ContextManager::LoadImageMemory(void* mem, size_t len, char* type) {
+        SDL_RWops* rwo = SDL_RWFromMem(mem, len);
+        SDL_Surface* bitmap_tmp = IMG_LoadTyped_RW(rwo, 0, type);
+
+        return bitmap_tmp;
+    }
+
+    void* ContextManager::AccelImage(void* in) {
+        if(accelerate) {
+            SDL_Texture* tex = SDL_CreateTextureFromSurface(renderer, (SDL_Surface*)in);
+            SDL_FreeSurface((SDL_Surface*)in);
+
+            return tex;
+        }
+        return in;
+    }
+
+    void* ContextManager::GLTexImage(void* in) {
+
+        if(!opengl_mode) return in;
+
+        GLuint *tex = (GLuint*)calloc(sizeof(GLuint), 1);
+        GLenum texture_format;
+        GLint  nOfColors;
+        SDL_Surface* sfc = (SDL_Surface*)in;
+
+        if ( (sfc->w & (sfc->w - 1)) != 0 ) {
+            printf("[WARN] Image width not ^2.\n");
+        }
+
+        // Also check if the height is a power of 2
+        if ( (sfc->h & (sfc->h - 1)) != 0 ) {
+            printf("[WARN] Image height not ^2.\n");
+        }
+
+        // get the number of channels in the SDL surface
+        nOfColors = sfc->format->BytesPerPixel;
+        if (nOfColors == 4)     // contains an alpha channel
+        {
+            if (sfc->format->Rmask == 0x000000ff)
+                texture_format = GL_RGBA;
+            else
+                texture_format = GL_BGRA;
+        }
+        else if (nOfColors == 3)     // no alpha channel
+        {
+            if (sfc->format->Rmask == 0x000000ff)
+                texture_format = GL_RGB;
+            else
+                texture_format = GL_BGR;
+        }
+        else {
+            printf("[WARN] Image not truecolor (32bpp). Expect explosions.\n");
+            // this error should not go unhandled
+        }
+
+        // Have OpenGL generate a texture object handle for us
+        glGenTextures( 1, tex );
+
+        // Bind the texture object
+        glBindTexture( GL_TEXTURE_2D, tex[0] );
+
+        // Edit the texture object's image data using the information SDL_Surface gives us
+        glTexImage2D( GL_TEXTURE_2D, 0, nOfColors, sfc->w, sfc->h, 0, texture_format, GL_UNSIGNED_BYTE, sfc->pixels );
+
+        // Set the texture's stretching properties
+        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
+        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
+
+        // printf("[GL] tex: %d\n", tex[0]);
+
+        return tex;
+    }
index b976180623bc6bdbb0613cf09d06a25d30e65bb0..834626d6f32fdf4c9fa927e6910cc339c919e57c 100644 (file)
 
 TextManager::TextManager(ContextManager* ct) {
 
-       fonts = NULL;
-       current_font = 0;
-       fonts_loaded = 0;
-       outline = false;
-       outline_px = 0;
+    fonts = NULL;
+    current_font = 0;
+    fonts_loaded = 0;
+    outline = false;
+    outline_px = 0;
 
-       this->ctx = ct;
+    this->ctx = ct;
 
-       if(TTF_Init() == -1) {
-               printf("TTF Init failed. %s\n", TTF_GetError());
-               exit(-8);
-       }
+    if(TTF_Init() == -1) {
+        printf("TTF Init failed. %s\n", TTF_GetError());
+        exit(-8);
+    }
 
-       LoadFont((char*)"default.ttf", 20);
+    LoadFont((char*)"default.ttf", 20);
 
-       color.r = 255;
-       color.g = 255;
-       color.b = 255;
-       color.a = 255;
+    color.r = 255;
+    color.g = 255;
+    color.b = 255;
+    color.a = 255;
 
 }
 
 TextManager::~TextManager() {
 
-       while(fonts_loaded > 0) {
-               TTF_CloseFont(fonts[fonts_loaded-1]);
-               --fonts_loaded;
-       }
+    while(fonts_loaded > 0) {
+        TTF_CloseFont(fonts[fonts_loaded-1]);
+        --fonts_loaded;
+    }
 
-       free(fonts);
+    free(fonts);
 
-       TTF_Quit();
+    TTF_Quit();
 }
 
 int TextManager::LoadFont(char* fname, int size) {
 
-       ++fonts_loaded;
+    ++fonts_loaded;
 
-       fonts = (TTF_Font**)realloc(fonts, sizeof(TTF_Font*) * fonts_loaded);
+    fonts = (TTF_Font**)realloc(fonts, sizeof(TTF_Font*) * fonts_loaded);
 
-       if ( !(fonts[fonts_loaded - 1] = TTF_OpenFont(fname, size) ) ) {
-               printf("Font Open Failed. Load attempt: %s. Msg: %s\n", fname, TTF_GetError());
-       }
+    if ( !(fonts[fonts_loaded - 1] = TTF_OpenFont(fname, size) ) ) {
+        printf("Font Open Failed. Load attempt: %s. Msg: %s\n", fname, TTF_GetError());
+    }
 
-       TTF_SetFontHinting(fonts[fonts_loaded - 1], TTF_HINTING_NONE);
+    TTF_SetFontHinting(fonts[fonts_loaded - 1], TTF_HINTING_NONE);
 
-       return fonts_loaded - 1;
+    return fonts_loaded - 1;
 }
 
 
 // Implement properly later with wrapped coordinates.
 void TextManager::Render(char* text) {
-       Render(text, 0, 0);
+    Render(text, 0, 0);
 }
 
 void TextManager::Render(char* text, int x, int y) {
-       if (text == NULL || fonts[current_font] == NULL) {
-               fprintf(stderr, "[WARN] Null text or font passed.\n");
-               return;
-       }
+    if (text == NULL || fonts[current_font] == NULL) {
+        fprintf(stderr, "[WARN] Null text or font passed.\n");
+        return;
+    }
 
 
-       SDL_Surface *sf1 = NULL, *sf2 = NULL;
+    SDL_Surface *sf1 = NULL, *sf2 = NULL;
 
-       sf1 = TTF_RenderUTF8_Blended(fonts[current_font], text, color);
+    sf1 = TTF_RenderUTF8_Blended(fonts[current_font], text, color);
 
-       if(outline) {
-               // Invert normal color.
-               SDL_Color n_color;
-               n_color.r = 255 - color.r;
-               n_color.g = 255 - color.g;
-               n_color.b = 255 - color.b;
-               n_color.a = color.a;
+    if(outline) {
+        // Invert normal color.
+        SDL_Color n_color;
+        n_color.r = 255 - color.r;
+        n_color.g = 255 - color.g;
+        n_color.b = 255 - color.b;
+        n_color.a = color.a;
 
-               // Outline, so increase size.
-               TTF_SetFontOutline(fonts[current_font], outline_px);
-               sf2 = TTF_RenderUTF8_Blended(fonts[current_font], text, n_color);
+        // Outline, so increase size.
+        TTF_SetFontOutline(fonts[current_font], outline_px);
+        sf2 = TTF_RenderUTF8_Blended(fonts[current_font], text, n_color);
 
-               // Disable Outline.
-               TTF_SetFontOutline(fonts[current_font], 0);
-       }
+        // Disable Outline.
+        TTF_SetFontOutline(fonts[current_font], 0);
+    }
 
-       if(outline) {
-               UDisplayable* r_sf2 = new UDisplayable(ctx, Normal, sf2);
-               r_sf2->SetOverlay(true);
-               r_sf2->SetXY(x-outline_px, y-outline_px);
+    if(outline) {
+        UDisplayable* r_sf2 = new UDisplayable(ctx, Normal, sf2);
+        r_sf2->SetOverlay(true);
+        r_sf2->SetXY(x-outline_px, y-outline_px);
 
-               r_sf2->Blit();
-               
-               delete r_sf2;
-       }
+        r_sf2->Blit();
+        
+        delete r_sf2;
+    }
 
-       UDisplayable* r_sf1 = new UDisplayable(ctx, Normal, sf1);
-       r_sf1->SetOverlay(true);
-       r_sf1->SetXY(x, y);
+    UDisplayable* r_sf1 = new UDisplayable(ctx, Normal, sf1);
+    r_sf1->SetOverlay(true);
+    r_sf1->SetXY(x, y);
 
-       r_sf1->Blit();
+    r_sf1->Blit();
 
-       delete r_sf1;
+    delete r_sf1;
 }
 
 int TextManager::TestLen(char* text) {
-       int w, h;
-       TTF_SizeText(fonts[current_font], text, &w, &h);
+    int w, h;
+    TTF_SizeText(fonts[current_font], text, &w, &h);
 
-       return w;
+    return w;
 }
 
 void TextManager::Outline(int pixels) {
-       if(pixels == 0) {
-               outline = false;
-       }
-       else {
-               outline = true;
-               outline_px = pixels;
-       }
+    if(pixels == 0) {
+        outline = false;
+    }
+    else {
+        outline = true;
+        outline_px = pixels;
+    }
 }
 
 void TextManager::SetColor(int r, int g, int b, int a)
 {
-       color.r = r;
-       color.g = g;
-       color.b = b;
-       color.a = a;
+    color.r = r;
+    color.g = g;
+    color.b = b;
+    color.a = a;
 }
 
 void TextManager::SetFontUsed(int index)
 {
-       current_font = index;
+    current_font = index;
 }
 
 // This splits a screen so that each line will fit to a width.
 // Note that this will modify the string in place by inserting \0
 // So your string will likely not be usable as before.
 void TextManager::SplitStringByWidth(char* string, int max_w, int* OUT_num, char*** OUT_ptrs) {
-       if(TestLen(string) > max_w) {
-               /* new algo */
-               char** ptrs = NULL;
-               int lines = 0;
-               int len = strlen(string);
+    if(TestLen(string) > max_w) {
+        /* new algo */
+        char** ptrs = NULL;
+        int lines = 0;
+        int len = strlen(string);
 
-               int counted = 0;
+        int counted = 0;
 
-               while(counted < len) {
-                       char* pt_start = &string[counted];
-                       char* pt_end = &pt_start[strlen(pt_start)];
+        while(counted < len) {
+            char* pt_start = &string[counted];
+            char* pt_end = &pt_start[strlen(pt_start)];
 
-                       while(pt_end > pt_start && TestLen(pt_start) > max_w) {
-                               *pt_end = ' ';
-                               --pt_end;
-                               while (*pt_end != ' ' && pt_end > pt_start) --pt_end;
+            while(pt_end > pt_start && TestLen(pt_start) > max_w) {
+                *pt_end = ' ';
+                --pt_end;
+                while (*pt_end != ' ' && pt_end > pt_start) --pt_end;
 
-                               *pt_end = '\0';
-                       }
+                *pt_end = '\0';
+            }
 
-                       #ifdef DEBUG_OVERKILL
-                       printf("Reduced line %d: %s\n", lines, pt_start);
-                       #endif
+            #ifdef DEBUG_OVERKILL
+            printf("Reduced line %d: %s\n", lines, pt_start);
+            #endif
 
-                       ptrs = (char**)realloc(ptrs, sizeof(char*)*(lines+1));
+            ptrs = (char**)realloc(ptrs, sizeof(char*)*(lines+1));
 
-                       ptrs[lines] = pt_start;
+            ptrs[lines] = pt_start;
 
-                       counted += strlen(pt_start) + 1;
+            counted += strlen(pt_start) + 1;
 
-                       ++lines;
-               }
+            ++lines;
+        }
 
-               *OUT_num = lines;
+        *OUT_num = lines;
 
-               *OUT_ptrs = ptrs;
-       }
-       else {
-               char** ptrs = (char**)calloc(sizeof(char*), 1);
-               ptrs[0] = string;
+        *OUT_ptrs = ptrs;
+    }
+    else {
+        char** ptrs = (char**)calloc(sizeof(char*), 1);
+        ptrs[0] = string;
 
-               // We pass thru values anyways, regardless of there being one line.
-               *OUT_num = 1;
-               *OUT_ptrs = ptrs;
-       }
+        // We pass thru values anyways, regardless of there being one line.
+        *OUT_num = 1;
+        *OUT_ptrs = ptrs;
+    }
 }
index 6c2618c2bee459ae290d83883a6c901d5597bf57..3dc5a88c59c78234073d3a72708534c54cc2ca13 100644 (file)
 #include "Zero.hpp"
 
-       void UDisplayable::DefaultVars() {
-                       bitmap = NULL; // Will contain either a SDL_Surface or SDL_Texture
-
-                       bmp_w = 0; bmp_h = 0;
-
-                       // Used in docked mode
-                       frame = NULL;
-                       // Used in hitbox mode
-                       hitbox = NULL;
-
-                       // The current mode.
-                       dispMode = Normal;
-
-                       // Used by animated mode.
-                       frameIndex = -1;
-
-                       Error = false;
-
-                       over = false;
-       }
-
-       // Creates a new Displayable.
-       // The mode is already Normal if we do nothing, so this constructor doesn't have to change.
-       UDisplayable::UDisplayable(ContextManager* cx, char* fname) {
-
-               DefaultVars();
-
-               SDL_Surface* bitmap_tmp = (SDL_Surface*)cx->LoadImage(fname);
-
-               if(!bitmap_tmp) {
-                       printf("[UDisplayable::Ctor] File could not be loaded, this->Error set.\n");
-                       Error = true;
-               }
-               else {
-                       this->x = 0;
-                       this->y = 0;
-                       this->loc.x = 0;
-                       this->loc.y = 0;
-                       this->ctx = cx;
-                       this->frameWidth = bitmap_tmp->w;
-                       this->bmp_w = bitmap_tmp->w;
-                       this->bmp_h = bitmap_tmp->h;
-
-                       // We still allocate the two arrays, regardless.
-
-                       // These values are unused, but we'll default them so it will operate normally.
-                       hitbox = (int*)calloc(sizeof(int), 4);
-
-                       // By default, it will fill this with 0, 0, W, H.
-                       // This will behave identically to a displayable.
-                       hitbox[0] = 0;
-                       hitbox[1] = 0;
-                       hitbox[2] = bitmap_tmp->w;
-                       hitbox[3] = bitmap_tmp->h;
-
-                       this->loc.w = bitmap_tmp->w;
-                       this->loc.h = bitmap_tmp->w;
-
-                       frame = (int*)calloc(sizeof(int), 4);
-
-                       frame[0] = 0;
-                       frame[1] = 0;
-                       frame[2] = cx->GetWidth();
-                       frame[3] = cx->GetHeight();
-
-                       // Determine if we're on an accelerated context. If so, we create a texture out of the bitmap.
-                       // Then we store what we'll use to the void* bitmap, either Tex or Surf.
-                       if(cx->Accelerated()) {
-                               this->bitmap = cx->AccelImage(bitmap_tmp);
-                       }
-                       else {
-                               this->bitmap = cx->GLTexImage(bitmap_tmp);
-                       }
-               }
-               #ifdef DEBUG_OVERKILL
-               printf("[UDisplayable~Ctor] accel:%d\n", cx->Accelerated());
-               #endif
-       }
-
-       // Sets the Displayable's mode.
-       UDisplayable::UDisplayable(ContextManager* cx, UDisplayableMode mode, char* fname) {
-               // UDisplayable(cx, fname);
-
-
-               DefaultVars();
-
-               SDL_Surface* bitmap_tmp = (SDL_Surface*)cx->LoadImage(fname);
-
-               if(!bitmap_tmp) {
-                       printf("[UDisplayable::Ctor] File could not be loaded, this->Error set.\n");
-                       Error = true;
-               }
-               else {
-                       this->x = 0;
-                       this->y = 0;
-                       this->loc.x = 0;
-                       this->loc.y = 0;
-                       this->ctx = cx;
-                       this->frameWidth = bitmap_tmp->w;
-                       this->bmp_w = bitmap_tmp->w;
-                       this->bmp_h = bitmap_tmp->h;
-
-                       // We still allocate the two arrays, regardless.
-
-                       // These values are unused, but we'll default them so it will operate normally.
-                       hitbox = (int*)calloc(sizeof(int), 4);
-
-                       // By default, it will fill this with 0, 0, W, H.
-                       // This will behave identically to a displayable.
-                       hitbox[0] = 0;
-                       hitbox[1] = 0;
-                       hitbox[2] = bitmap_tmp->w;
-                       hitbox[3] = bitmap_tmp->h;
-
-                       this->loc.w = bitmap_tmp->w;
-                       this->loc.h = bitmap_tmp->w;
-
-                       frame = (int*)calloc(sizeof(int), 4);
-
-                       frame[0] = 0;
-                       frame[1] = 0;
-                       frame[2] = cx->GetWidth();
-                       frame[3] = cx->GetHeight();
-
-                       // Determine if we're on an accelerated context. If so, we create a texture out of the bitmap.
-                       // Then we store what we'll use to the void* bitmap, either Tex or Surf.
-
-                       if(cx->Accelerated()) {
-                               this->bitmap = cx->AccelImage(bitmap_tmp);
-                       }
-                       else {
-                               this->bitmap = cx->GLTexImage(bitmap_tmp);
-                       }
-               }
-               #ifdef DEBUG_OVERKILL
-               printf("[UDisplayable~Ctor] accel:%d\n", cx->Accelerated());
-               #endif
-
-               this->dispMode = mode;
-       }
-
-       // Load from memory.
-       UDisplayable::UDisplayable(ContextManager* cx, UDisplayableMode mode, void* memory, int mSize) {
-
-               DefaultVars();
-
-               SDL_Surface* bitmap_tmp = (SDL_Surface*)cx->LoadImageMemory(memory, mSize, (char*)"PNG");
-
-               this->x = 0;
-               this->y = 0;
-               this->loc.x = 0;
-               this->loc.y = 0;
-               this->ctx = cx;
-               this->frameWidth = bitmap_tmp->w;
-               this->bmp_w = bitmap_tmp->w;
-               this->bmp_h = bitmap_tmp->h;
-
-               // We still allocate the two arrays, regardless.
-
-               // These values are unused, but we'll default them so it will operate normally.
-               hitbox = (int*)calloc(sizeof(int), 4);
-
-               // By default, it will fill this with 0, 0, W, H.
-               // This will behave identically to a displayable.
-               hitbox[0] = 0;
-               hitbox[1] = 0;
-               hitbox[2] = bitmap_tmp->w;
-               hitbox[3] = bitmap_tmp->h;
-
-               this->loc.w = bitmap_tmp->w;
-               this->loc.h = bitmap_tmp->w;
-
-               frame = (int*)calloc(sizeof(int), 4);
-
-               frame[0] = 0;
-               frame[1] = 0;
-               frame[2] = cx->GetWidth();
-               frame[3] = cx->GetHeight();
-
-               // Determine if we're on an accelerated context. If so, we create a texture out of the bitmap.
-               // Then we store what we'll use to the void* bitmap, either Tex or Surf.
-
-               if(cx->Accelerated()) {
-                       this->bitmap = cx->AccelImage(bitmap_tmp);
-               }
-               else {
-                       this->bitmap = cx->GLTexImage(bitmap_tmp);
-               }
-
-               this->dispMode = mode;
-       }
-
-       // From SDL_Surface.
-       UDisplayable::UDisplayable(ContextManager* cx, UDisplayableMode mode, SDL_Surface* bitmap_tmp) {
-
-               DefaultVars();
-
-               this->x = 0;
-               this->y = 0;
-               this->loc.x = 0;
-               this->loc.y = 0;
-               this->ctx = cx;
-               this->frameWidth = bitmap_tmp->w;
-               this->bmp_w = bitmap_tmp->w;
-               this->bmp_h = bitmap_tmp->h;
-
-               // We still allocate the two arrays, regardless.
-
-               // These values are unused, but we'll default them so it will operate normally.
-               hitbox = (int*)calloc(sizeof(int), 4);
-
-               // By default, it will fill this with 0, 0, W, H.
-               // This will behave identically to a displayable.
-               hitbox[0] = 0;
-               hitbox[1] = 0;
-               hitbox[2] = bitmap_tmp->w;
-               hitbox[3] = bitmap_tmp->h;
-
-               this->loc.w = bitmap_tmp->w;
-               this->loc.h = bitmap_tmp->w;
-
-               frame = (int*)calloc(sizeof(int), 4);
-
-               frame[0] = 0;
-               frame[1] = 0;
-               frame[2] = cx->GetWidth();
-               frame[3] = cx->GetHeight();
-
-               // Determine if we're on an accelerated context. If so, we create a texture out of the bitmap.
-               // Then we store what we'll use to the void* bitmap, either Tex or Surf.
-
-               if(cx->Accelerated()) {
-                       this->bitmap = cx->AccelImage(bitmap_tmp);
-               }
-               else {
-                       this->bitmap = cx->GLTexImage(bitmap_tmp);
-               }
-
-               this->dispMode = mode;
-       }
-
-       // Sets the position on screen.
-
-       void UDisplayable::SetXY(double x, double y) {
-               if (Error) {
-                       fprintf(stderr, "[WARN] Error flag set.\n");
-                       return;
-               }
-               this->x = x;
-               this->y = y;
-
-               // Expand that logic above.
-
-               if(this->x < 0)
-                       this->x = 0;
-               if(this->y < 0)
-                       this->y = 0;
-
-               if(frameIndex == -1) {
-                       if(over) {
-                               if(this->x > ctx->GetWidth() - this->bmp_w)
-                                       this->x = (double)(ctx->GetWidth() - this->bmp_w);
-                       }
-                       else {
-                               if(this->x > frame[2] - this->bmp_w)
-                                       this->x = (double)(frame[2] - this->bmp_w);
-                       }
-               }
-               else {
-                       if(over) {
-                               if(this->x > ctx->GetWidth() - this->bmp_w)
-                                       this->x = (double)(ctx->GetWidth() - this->frameWidth);
-                       }
-                       else {
-                               if(this->x > frame[2] - this->frameWidth)
-                                       this->x = (double)(frame[2] - this->frameWidth);
-                       }
-               }
-
-               if(over) {
-                       if(this->y > ctx->GetHeight() - this->bmp_h)
-                               this->y = (double)(ctx->GetHeight() - this->bmp_h);
-               }
-               else {
-                       if(this->y > frame[3] - this->bmp_h)
-                               this->y = (double)(frame[3] - this->bmp_h);
-               }
-
-               this->loc.x = (int)this->x;
-               this->loc.y = (int)this->y;
-
-               #ifdef DEBUG_OVERKILL
-               printf("[UDisplayable::SetXY] x:%d y:%d\n", this->loc.x, this->loc.y);
-               #endif
-       }
-
-       // Modifies the position on screen. Meant to avoid embedded retrievals.
-
-       void UDisplayable::ModXY(double x, double y) {
-               if (Error)
-                       return;
-
-               this->x += x;
-               this->y += y;
-
-               // Expand that logic above.
-
-               if(this->x < 0)
-                       this->x = 0;
-               if(this->y < 0)
-                       this->y = 0;
-
-               if(frameIndex == -1) {
-                       if(over) {
-                               if(this->x > ctx->GetWidth() - this->bmp_w)
-                                       this->x = (double)(ctx->GetWidth() - this->bmp_w);
-                       }
-                       else {
-                               if(this->x > frame[2] - this->bmp_w)
-                                       this->x = (double)(frame[2] - this->bmp_w);
-                       }
-               }
-               else {
-                       if(over) {
-                               if(this->x > ctx->GetWidth() - this->bmp_w)
-                                       this->x = (double)(ctx->GetWidth() - this->frameWidth);
-                       }
-                       else {
-                               if(this->x > frame[2] - this->frameWidth)
-                                       this->x = (double)(frame[2] - this->frameWidth);
-                       }
-               }
-
-               if(over) {
-                       if(this->y > ctx->GetHeight() - this->bmp_h)
-                               this->y = (double)(ctx->GetHeight() - this->bmp_h);
-               }
-               else {
-                       if(this->y > frame[3] - this->bmp_h)
-                               this->y = (double)(frame[3] - this->bmp_h);
-               }
-
-               this->loc.x = (int)this->x;
-               this->loc.y = (int)this->y;
-
-               #ifdef DEBUG_OVERKILL
-               printf("[UDisplayable::SetXY] x:%d y:%d w:%d h:%d\n", frame[0], frame[1], frame[2], frame[3]);
-               #endif
-       }
-
-       // Get X coord.
-
-       double UDisplayable::GetX() {
-               if (Error)
-                       return 0;
-
-               return this->x;
-       }
-
-       // Get Y coord.
-
-       double UDisplayable::GetY() {
-               if (Error)
-                       return 0;
-               return this->y;
-       }
-
-       // Get aligned X coord.
-
-       int UDisplayable::GetXI() {
-               if (Error)
-                       return 0;
-               return this->loc.x;
-       }
-
-       // Get aligned Y coord.
-
-       int UDisplayable::GetYI() {
-               if (Error)
-                       return 0;
-               return this->loc.y;
-       }
-
-       // Get Width
-
-       int UDisplayable::GetW() {
-               if (Error)
-                       return 0;
-               return this->bmp_w;
-       }
-
-       // Get Height
-
-       int UDisplayable::GetH() {
-               if (Error)
-                       return 0;
-               return this->bmp_h;
-       }
-
-       // Blit to an associated context.
-
-       void UDisplayable::Blit() {
-               if (Error)
-                       return;
-
-               // Copy loc and alter position.
-               SDL_Rect loc_adj;
-               loc_adj.x = loc.x + frame[0];
-               loc_adj.y = loc.y + frame[1];
-               loc_adj.w = frameWidth;
-               loc_adj.h = bmp_h;
-
-               #ifdef DEBUG_OVERKILL
-               printf("[UDisplayable::Blit]\n");
-               #endif
-
-               SDL_Rect src;
-               src.x = 0;
-               src.y = 0;
-               src.w = bmp_w;
-               src.h = bmp_h;
-
-               if (frameIndex == -1) {
-                       if(over)
-                               ctx->OverlayBlit(bitmap, &src, &loc_adj, &src);
-                       else
-                               ctx->Blit(bitmap, &src, &loc_adj, &src);
-                       return;
-               }
-
-               SDL_Rect frameClip;
-
-               frameClip.x = frameWidth * frameIndex;
-               frameClip.y = 0;
-               frameClip.w = frameWidth;
-               frameClip.h = bmp_h;
-
-               if(over)
-                       ctx->OverlayBlit(bitmap, &frameClip, &loc_adj, &src);
-               else
-                       ctx->Blit(bitmap, &frameClip, &loc_adj, &src);
-       }
-
-       // Get SDL_Rect for collision calculation. In a base Displayable, it returns the image width.
-       // In a derived class, it may return only a hitbox.
-
-       int* UDisplayable::GetHitbox() {
-               if (Error)
-                       return NULL;
-               int* rect = (int*)calloc(sizeof(int), 4);
-
-               rect[0] = hitbox[0] + (int)this->x;
-               rect[1] = hitbox[1] + (int)this->y;
-               rect[2] = hitbox[2];
-               rect[3] = hitbox[3];
-
-               return rect;
-       }
-
-       // Surface is on overlay, not background.
-       void UDisplayable::SetOverlay(bool state) {
-               over = state;
-       }
-
-       // Destroy bitmap.
-
-       UDisplayable::~UDisplayable() {
-               if (Error)
-                       return;
-               if(ctx->Accelerated())
-                       SDL_DestroyTexture((SDL_Texture*)bitmap);
-               else
-                       SDL_FreeSurface((SDL_Surface*)bitmap);
-               free(hitbox);
-               free(frame);
-       }
-
-       void UDisplayable::SetHitbox(int x, int y, int w, int h) {
-               if (Error)
-                       return;
-               if(dispMode == Normal || dispMode == Docked || dispMode == Anim || dispMode == AnimDocked)
-                       return;
-
-               hitbox[0] = x;
-               hitbox[1] = y;
-               hitbox[2] = w;
-               hitbox[3] = h;
-       }
-
-       void UDisplayable::SetDock(int x, int y, int w, int h) {
-               if (Error)
-                       return;
-               if(dispMode == Normal || dispMode == Hitbox || dispMode == Anim || dispMode == AnimHitbox)
-                       return;
-               frame[0] = x;
-               frame[1] = y;
-               frame[2] = w;
-               frame[3] = h;
-       }
-
-       void UDisplayable::NextFrame() {
-               if (Error)
-                       return;
-               if (dispMode == Normal || dispMode == Hitbox || dispMode == Docked || dispMode == HitboxDocked)
-                       return;
-
-               ++frameIndex;
-
-               if(frameWidth * frameIndex >= bmp_w)
-                       frameIndex = 0;
-       }
-
-       void UDisplayable::NextFrame(int f) {
-               if (Error)
-                       return;
-               if (dispMode == Normal || dispMode == Hitbox || dispMode == Docked || dispMode == HitboxDocked)
-                       return;
-               frameIndex += f;
-
-               if(frameWidth * frameIndex >= bmp_w)
-                       frameIndex = 0;
-       }
-
-       void UDisplayable::ResetFrame() {
-               if (Error)
-                       return;
-               if (dispMode == Normal || dispMode == Hitbox || dispMode == Docked || dispMode == HitboxDocked)
-                       return;
-               frameIndex = 0;
-       }
-
-       void UDisplayable::SetFrame(int f) {
-               if (Error)
-                       return;
-               if (dispMode == Normal || dispMode == Hitbox || dispMode == Docked || dispMode == HitboxDocked)
-                       return;
-
-               frameIndex = f;
-       }
-
-       void UDisplayable::SetFrameWidth(int frameW) {
-               if (Error)
-                       return;
-               if (dispMode == Normal || dispMode == Hitbox || dispMode == Docked || dispMode == HitboxDocked)
-                       return;
-               this->frameWidth = frameW;
-
-               #ifdef DEBUG_OVERKILL
-               printf("[UDisplayable::SetFrameWidth] fW:%d\n", frameW);
-               #endif
-       }
+    void UDisplayable::DefaultVars() {
+            bitmap = NULL; // Will contain either a SDL_Surface or SDL_Texture
+
+            bmp_w = 0; bmp_h = 0;
+
+            // Used in docked mode
+            frame = NULL;
+            // Used in hitbox mode
+            hitbox = NULL;
+
+            // The current mode.
+            dispMode = Normal;
+
+            // Used by animated mode.
+            frameIndex = -1;
+
+            Error = false;
+
+            over = false;
+    }
+
+    // Creates a new Displayable.
+    // The mode is already Normal if we do nothing, so this constructor doesn't have to change.
+    UDisplayable::UDisplayable(ContextManager* cx, char* fname) {
+
+        DefaultVars();
+
+        SDL_Surface* bitmap_tmp = (SDL_Surface*)cx->LoadImage(fname);
+
+        if(!bitmap_tmp) {
+            printf("[UDisplayable::Ctor] File could not be loaded, this->Error set.\n");
+            Error = true;
+        }
+        else {
+            this->x = 0;
+            this->y = 0;
+            this->loc.x = 0;
+            this->loc.y = 0;
+            this->ctx = cx;
+            this->frameWidth = bitmap_tmp->w;
+            this->bmp_w = bitmap_tmp->w;
+            this->bmp_h = bitmap_tmp->h;
+
+            // We still allocate the two arrays, regardless.
+
+            // These values are unused, but we'll default them so it will operate normally.
+            hitbox = (int*)calloc(sizeof(int), 4);
+
+            // By default, it will fill this with 0, 0, W, H.
+            // This will behave identically to a displayable.
+            hitbox[0] = 0;
+            hitbox[1] = 0;
+            hitbox[2] = bitmap_tmp->w;
+            hitbox[3] = bitmap_tmp->h;
+
+            this->loc.w = bitmap_tmp->w;
+            this->loc.h = bitmap_tmp->w;
+
+            frame = (int*)calloc(sizeof(int), 4);
+
+            frame[0] = 0;
+            frame[1] = 0;
+            frame[2] = cx->GetWidth();
+            frame[3] = cx->GetHeight();
+
+            // Determine if we're on an accelerated context. If so, we create a texture out of the bitmap.
+            // Then we store what we'll use to the void* bitmap, either Tex or Surf.
+            if(cx->Accelerated()) {
+                this->bitmap = cx->AccelImage(bitmap_tmp);
+            }
+            else {
+                this->bitmap = cx->GLTexImage(bitmap_tmp);
+            }
+        }
+        #ifdef DEBUG_OVERKILL
+        printf("[UDisplayable~Ctor] accel:%d\n", cx->Accelerated());
+        #endif
+    }
+
+    // Sets the Displayable's mode.
+    UDisplayable::UDisplayable(ContextManager* cx, UDisplayableMode mode, char* fname) {
+        // UDisplayable(cx, fname);
+
+
+        DefaultVars();
+
+        SDL_Surface* bitmap_tmp = (SDL_Surface*)cx->LoadImage(fname);
+
+        if(!bitmap_tmp) {
+            printf("[UDisplayable::Ctor] File could not be loaded, this->Error set.\n");
+            Error = true;
+        }
+        else {
+            this->x = 0;
+            this->y = 0;
+            this->loc.x = 0;
+            this->loc.y = 0;
+            this->ctx = cx;
+            this->frameWidth = bitmap_tmp->w;
+            this->bmp_w = bitmap_tmp->w;
+            this->bmp_h = bitmap_tmp->h;
+
+            // We still allocate the two arrays, regardless.
+
+            // These values are unused, but we'll default them so it will operate normally.
+            hitbox = (int*)calloc(sizeof(int), 4);
+
+            // By default, it will fill this with 0, 0, W, H.
+            // This will behave identically to a displayable.
+            hitbox[0] = 0;
+            hitbox[1] = 0;
+            hitbox[2] = bitmap_tmp->w;
+            hitbox[3] = bitmap_tmp->h;
+
+            this->loc.w = bitmap_tmp->w;
+            this->loc.h = bitmap_tmp->w;
+
+            frame = (int*)calloc(sizeof(int), 4);
+
+            frame[0] = 0;
+            frame[1] = 0;
+            frame[2] = cx->GetWidth();
+            frame[3] = cx->GetHeight();
+
+            // Determine if we're on an accelerated context. If so, we create a texture out of the bitmap.
+            // Then we store what we'll use to the void* bitmap, either Tex or Surf.
+
+            if(cx->Accelerated()) {
+                this->bitmap = cx->AccelImage(bitmap_tmp);
+            }
+            else {
+                this->bitmap = cx->GLTexImage(bitmap_tmp);
+            }
+        }
+        #ifdef DEBUG_OVERKILL
+        printf("[UDisplayable~Ctor] accel:%d\n", cx->Accelerated());
+        #endif
+
+        this->dispMode = mode;
+    }
+
+    // Load from memory.
+    UDisplayable::UDisplayable(ContextManager* cx, UDisplayableMode mode, void* memory, int mSize) {
+
+        DefaultVars();
+
+        SDL_Surface* bitmap_tmp = (SDL_Surface*)cx->LoadImageMemory(memory, mSize, (char*)"PNG");
+
+        this->x = 0;
+        this->y = 0;
+        this->loc.x = 0;
+        this->loc.y = 0;
+        this->ctx = cx;
+        this->frameWidth = bitmap_tmp->w;
+        this->bmp_w = bitmap_tmp->w;
+        this->bmp_h = bitmap_tmp->h;
+
+        // We still allocate the two arrays, regardless.
+
+        // These values are unused, but we'll default them so it will operate normally.
+        hitbox = (int*)calloc(sizeof(int), 4);
+
+        // By default, it will fill this with 0, 0, W, H.
+        // This will behave identically to a displayable.
+        hitbox[0] = 0;
+        hitbox[1] = 0;
+        hitbox[2] = bitmap_tmp->w;
+        hitbox[3] = bitmap_tmp->h;
+
+        this->loc.w = bitmap_tmp->w;
+        this->loc.h = bitmap_tmp->w;
+
+        frame = (int*)calloc(sizeof(int), 4);
+
+        frame[0] = 0;
+        frame[1] = 0;
+        frame[2] = cx->GetWidth();
+        frame[3] = cx->GetHeight();
+
+        // Determine if we're on an accelerated context. If so, we create a texture out of the bitmap.
+        // Then we store what we'll use to the void* bitmap, either Tex or Surf.
+
+        if(cx->Accelerated()) {
+            this->bitmap = cx->AccelImage(bitmap_tmp);
+        }
+        else {
+            this->bitmap = cx->GLTexImage(bitmap_tmp);
+        }
+
+        this->dispMode = mode;
+    }
+
+    // From SDL_Surface.
+    UDisplayable::UDisplayable(ContextManager* cx, UDisplayableMode mode, SDL_Surface* bitmap_tmp) {
+
+        DefaultVars();
+
+        this->x = 0;
+        this->y = 0;
+        this->loc.x = 0;
+        this->loc.y = 0;
+        this->ctx = cx;
+        this->frameWidth = bitmap_tmp->w;
+        this->bmp_w = bitmap_tmp->w;
+        this->bmp_h = bitmap_tmp->h;
+
+        // We still allocate the two arrays, regardless.
+
+        // These values are unused, but we'll default them so it will operate normally.
+        hitbox = (int*)calloc(sizeof(int), 4);
+
+        // By default, it will fill this with 0, 0, W, H.
+        // This will behave identically to a displayable.
+        hitbox[0] = 0;
+        hitbox[1] = 0;
+        hitbox[2] = bitmap_tmp->w;
+        hitbox[3] = bitmap_tmp->h;
+
+        this->loc.w = bitmap_tmp->w;
+        this->loc.h = bitmap_tmp->w;
+
+        frame = (int*)calloc(sizeof(int), 4);
+
+        frame[0] = 0;
+        frame[1] = 0;
+        frame[2] = cx->GetWidth();
+        frame[3] = cx->GetHeight();
+
+        // Determine if we're on an accelerated context. If so, we create a texture out of the bitmap.
+        // Then we store what we'll use to the void* bitmap, either Tex or Surf.
+
+        if(cx->Accelerated()) {
+            this->bitmap = cx->AccelImage(bitmap_tmp);
+        }
+        else {
+            this->bitmap = cx->GLTexImage(bitmap_tmp);
+        }
+
+        this->dispMode = mode;
+    }
+
+    // Sets the position on screen.
+
+    void UDisplayable::SetXY(double x, double y) {
+        if (Error) {
+            fprintf(stderr, "[WARN] Error flag set.\n");
+            return;
+        }
+        this->x = x;
+        this->y = y;
+
+        // Expand that logic above.
+
+        if(this->x < 0)
+            this->x = 0;
+        if(this->y < 0)
+            this->y = 0;
+
+        if(frameIndex == -1) {
+            if(over) {
+                if(this->x > ctx->GetWidth() - this->bmp_w)
+                    this->x = (double)(ctx->GetWidth() - this->bmp_w);
+            }
+            else {
+                if(this->x > frame[2] - this->bmp_w)
+                    this->x = (double)(frame[2] - this->bmp_w);
+            }
+        }
+        else {
+            if(over) {
+                if(this->x > ctx->GetWidth() - this->bmp_w)
+                    this->x = (double)(ctx->GetWidth() - this->frameWidth);
+            }
+            else {
+                if(this->x > frame[2] - this->frameWidth)
+                    this->x = (double)(frame[2] - this->frameWidth);
+            }
+        }
+
+        if(over) {
+            if(this->y > ctx->GetHeight() - this->bmp_h)
+                this->y = (double)(ctx->GetHeight() - this->bmp_h);
+        }
+        else {
+            if(this->y > frame[3] - this->bmp_h)
+                this->y = (double)(frame[3] - this->bmp_h);
+        }
+
+        this->loc.x = (int)this->x;
+        this->loc.y = (int)this->y;
+
+        #ifdef DEBUG_OVERKILL
+        printf("[UDisplayable::SetXY] x:%d y:%d\n", this->loc.x, this->loc.y);
+        #endif
+    }
+
+    // Modifies the position on screen. Meant to avoid embedded retrievals.
+
+    void UDisplayable::ModXY(double x, double y) {
+        if (Error)
+            return;
+
+        this->x += x;
+        this->y += y;
+
+        // Expand that logic above.
+
+        if(this->x < 0)
+            this->x = 0;
+        if(this->y < 0)
+            this->y = 0;
+
+        if(frameIndex == -1) {
+            if(over) {
+                if(this->x > ctx->GetWidth() - this->bmp_w)
+                    this->x = (double)(ctx->GetWidth() - this->bmp_w);
+            }
+            else {
+                if(this->x > frame[2] - this->bmp_w)
+                    this->x = (double)(frame[2] - this->bmp_w);
+            }
+        }
+        else {
+            if(over) {
+                if(this->x > ctx->GetWidth() - this->bmp_w)
+                    this->x = (double)(ctx->GetWidth() - this->frameWidth);
+            }
+            else {
+                if(this->x > frame[2] - this->frameWidth)
+                    this->x = (double)(frame[2] - this->frameWidth);
+            }
+        }
+
+        if(over) {
+            if(this->y > ctx->GetHeight() - this->bmp_h)
+                this->y = (double)(ctx->GetHeight() - this->bmp_h);
+        }
+        else {
+            if(this->y > frame[3] - this->bmp_h)
+                this->y = (double)(frame[3] - this->bmp_h);
+        }
+
+        this->loc.x = (int)this->x;
+        this->loc.y = (int)this->y;
+
+        #ifdef DEBUG_OVERKILL
+        printf("[UDisplayable::SetXY] x:%d y:%d w:%d h:%d\n", frame[0], frame[1], frame[2], frame[3]);
+        #endif
+    }
+
+    // Get X coord.
+
+    double UDisplayable::GetX() {
+        if (Error)
+            return 0;
+
+        return this->x;
+    }
+
+    // Get Y coord.
+
+    double UDisplayable::GetY() {
+        if (Error)
+            return 0;
+        return this->y;
+    }
+
+    // Get aligned X coord.
+
+    int UDisplayable::GetXI() {
+        if (Error)
+            return 0;
+        return this->loc.x;
+    }
+
+    // Get aligned Y coord.
+
+    int UDisplayable::GetYI() {
+        if (Error)
+            return 0;
+        return this->loc.y;
+    }
+
+    // Get Width
+
+    int UDisplayable::GetW() {
+        if (Error)
+            return 0;
+        return this->bmp_w;
+    }
+
+    // Get Height
+
+    int UDisplayable::GetH() {
+        if (Error)
+            return 0;
+        return this->bmp_h;
+    }
+
+    // Blit to an associated context.
+
+    void UDisplayable::Blit() {
+        if (Error)
+            return;
+
+        // Copy loc and alter position.
+        SDL_Rect loc_adj;
+        loc_adj.x = loc.x + frame[0];
+        loc_adj.y = loc.y + frame[1];
+        loc_adj.w = frameWidth;
+        loc_adj.h = bmp_h;
+
+        #ifdef DEBUG_OVERKILL
+        printf("[UDisplayable::Blit]\n");
+        #endif
+
+        SDL_Rect src;
+        src.x = 0;
+        src.y = 0;
+        src.w = bmp_w;
+        src.h = bmp_h;
+
+        if (frameIndex == -1) {
+            if(over)
+                ctx->OverlayBlit(bitmap, &src, &loc_adj, &src);
+            else
+                ctx->Blit(bitmap, &src, &loc_adj, &src);
+            return;
+        }
+
+        SDL_Rect frameClip;
+
+        frameClip.x = frameWidth * frameIndex;
+        frameClip.y = 0;
+        frameClip.w = frameWidth;
+        frameClip.h = bmp_h;
+
+        if(over)
+            ctx->OverlayBlit(bitmap, &frameClip, &loc_adj, &src);
+        else
+            ctx->Blit(bitmap, &frameClip, &loc_adj, &src);
+    }
+
+    // Get SDL_Rect for collision calculation. In a base Displayable, it returns the image width.
+    // In a derived class, it may return only a hitbox.
+
+    int* UDisplayable::GetHitbox() {
+        if (Error)
+            return NULL;
+        int* rect = (int*)calloc(sizeof(int), 4);
+
+        rect[0] = hitbox[0] + (int)this->x;
+        rect[1] = hitbox[1] + (int)this->y;
+        rect[2] = hitbox[2];
+        rect[3] = hitbox[3];
+
+        return rect;
+    }
+
+    // Surface is on overlay, not background.
+    void UDisplayable::SetOverlay(bool state) {
+        over = state;
+    }
+
+    // Destroy bitmap.
+
+    UDisplayable::~UDisplayable() {
+        if (Error)
+            return;
+        if(ctx->Accelerated())
+            SDL_DestroyTexture((SDL_Texture*)bitmap);
+        else
+            SDL_FreeSurface((SDL_Surface*)bitmap);
+        free(hitbox);
+        free(frame);
+    }
+
+    void UDisplayable::SetHitbox(int x, int y, int w, int h) {
+        if (Error)
+            return;
+        if(dispMode == Normal || dispMode == Docked || dispMode == Anim || dispMode == AnimDocked)
+            return;
+
+        hitbox[0] = x;
+        hitbox[1] = y;
+        hitbox[2] = w;
+        hitbox[3] = h;
+    }
+
+    void UDisplayable::SetDock(int x, int y, int w, int h) {
+        if (Error)
+            return;
+        if(dispMode == Normal || dispMode == Hitbox || dispMode == Anim || dispMode == AnimHitbox)
+            return;
+        frame[0] = x;
+        frame[1] = y;
+        frame[2] = w;
+        frame[3] = h;
+    }
+
+    void UDisplayable::NextFrame() {
+        if (Error)
+            return;
+        if (dispMode == Normal || dispMode == Hitbox || dispMode == Docked || dispMode == HitboxDocked)
+            return;
+
+        ++frameIndex;
+
+        if(frameWidth * frameIndex >= bmp_w)
+            frameIndex = 0;
+    }
+
+    void UDisplayable::NextFrame(int f) {
+        if (Error)
+            return;
+        if (dispMode == Normal || dispMode == Hitbox || dispMode == Docked || dispMode == HitboxDocked)
+            return;
+        frameIndex += f;
+
+        if(frameWidth * frameIndex >= bmp_w)
+            frameIndex = 0;
+    }
+
+    void UDisplayable::ResetFrame() {
+        if (Error)
+            return;
+        if (dispMode == Normal || dispMode == Hitbox || dispMode == Docked || dispMode == HitboxDocked)
+            return;
+        frameIndex = 0;
+    }
+
+    void UDisplayable::SetFrame(int f) {
+        if (Error)
+            return;
+        if (dispMode == Normal || dispMode == Hitbox || dispMode == Docked || dispMode == HitboxDocked)
+            return;
+
+        frameIndex = f;
+    }
+
+    void UDisplayable::SetFrameWidth(int frameW) {
+        if (Error)
+            return;
+        if (dispMode == Normal || dispMode == Hitbox || dispMode == Docked || dispMode == HitboxDocked)
+            return;
+        this->frameWidth = frameW;
+
+        #ifdef DEBUG_OVERKILL
+        printf("[UDisplayable::SetFrameWidth] fW:%d\n", frameW);
+        #endif
+    }
index b1593399202892b22a975b054dec8d6752467955..64e2cd94e65de281ce0e27dca1cd95b18465bfdc 100644 (file)
@@ -1,92 +1,92 @@
 #include <Zero.hpp>
-               VertexController::VertexController(ContextManager* cx) {
-                       ctx = cx;
-               }
-
-               // Storage initializers.
-               void VertexController::LoadModel() {
-
-               }
-
-               // Programmatic Model Creation.
-               void VertexController::PushModel(int mode) {
-                       ++modelscount;
-                       models = NULL;
-
-                       models = (ModelData*)realloc(models, sizeof(ModelData) * modelscount);
-
-                       models[modelscount-1].pts = mode;
-                       models[modelscount-1].count = 0;
-                       models[modelscount-1].v = NULL;
-               }
-
-               void VertexController::PushTexture(char* fname) {
-                       void* ptr = ctx->LoadImage(fname);
-                       models[modelscount-1].t = ((GLuint*)ctx->GLTexImage(ptr))[0];
-               }
-
-               void VertexController::PushQuad(        GLfloat x1, GLfloat y1, GLfloat z1, GLfloat u1, GLfloat v1,
-                                                                                       GLfloat x2, GLfloat y2, GLfloat z2, GLfloat u2, GLfloat v2,
-                                                                                       GLfloat x3, GLfloat y3, GLfloat z3, GLfloat u3, GLfloat v3,
-                                                                                       GLfloat x4, GLfloat y4, GLfloat z4, GLfloat u4, GLfloat v4  ) {
-                       _AllocateVertex();
-
-                       models[modelscount-1].v[models[modelscount-1].count-1].pts[0].x = x1;
-                       models[modelscount-1].v[models[modelscount-1].count-1].pts[0].y = y1;
-                       models[modelscount-1].v[models[modelscount-1].count-1].pts[0].z = z1;
-                       models[modelscount-1].v[models[modelscount-1].count-1].pts[0].u = u1;
-                       models[modelscount-1].v[models[modelscount-1].count-1].pts[0].v = v1;
-
-                       models[modelscount-1].v[models[modelscount-1].count-1].pts[1].x = x2;
-                       models[modelscount-1].v[models[modelscount-1].count-1].pts[1].y = y2;
-                       models[modelscount-1].v[models[modelscount-1].count-1].pts[1].z = z2;
-                       models[modelscount-1].v[models[modelscount-1].count-1].pts[1].u = u2;
-                       models[modelscount-1].v[models[modelscount-1].count-1].pts[1].v = v2;
-
-                       models[modelscount-1].v[models[modelscount-1].count-1].pts[2].x = x3;
-                       models[modelscount-1].v[models[modelscount-1].count-1].pts[2].y = y3;
-                       models[modelscount-1].v[models[modelscount-1].count-1].pts[2].z = z3;
-                       models[modelscount-1].v[models[modelscount-1].count-1].pts[2].u = u3;
-                       models[modelscount-1].v[models[modelscount-1].count-1].pts[2].v = v3;
-
-                       models[modelscount-1].v[models[modelscount-1].count-1].pts[3].x = x4;
-                       models[modelscount-1].v[models[modelscount-1].count-1].pts[3].y = y4;
-                       models[modelscount-1].v[models[modelscount-1].count-1].pts[3].z = z4;
-                       models[modelscount-1].v[models[modelscount-1].count-1].pts[3].u = u4;
-                       models[modelscount-1].v[models[modelscount-1].count-1].pts[3].v = v4;
-
-
-               }
-
-               void VertexController::PushTri(         GLfloat x1, GLfloat y1, GLfloat z1, GLfloat u1, GLfloat v1,
-                                                                                       GLfloat x2, GLfloat y2, GLfloat z2, GLfloat u2, GLfloat v2,
-                                                                                       GLfloat x3, GLfloat y3, GLfloat z3, GLfloat u3, GLfloat v3  ) {
-                       _AllocateVertex();
-
-                       models[modelscount-1].v[models[modelscount-1].count-1].pts[0].x = x1;
-                       models[modelscount-1].v[models[modelscount-1].count-1].pts[0].y = y1;
-                       models[modelscount-1].v[models[modelscount-1].count-1].pts[0].z = z1;
-                       models[modelscount-1].v[models[modelscount-1].count-1].pts[0].u = u1;
-                       models[modelscount-1].v[models[modelscount-1].count-1].pts[0].v = v1;
-
-                       models[modelscount-1].v[models[modelscount-1].count-1].pts[1].x = x2;
-                       models[modelscount-1].v[models[modelscount-1].count-1].pts[1].y = y2;
-                       models[modelscount-1].v[models[modelscount-1].count-1].pts[1].z = z2;
-                       models[modelscount-1].v[models[modelscount-1].count-1].pts[1].u = u2;
-                       models[modelscount-1].v[models[modelscount-1].count-1].pts[1].v = v2;
-
-                       models[modelscount-1].v[models[modelscount-1].count-1].pts[2].x = x3;
-                       models[modelscount-1].v[models[modelscount-1].count-1].pts[2].y = y3;
-                       models[modelscount-1].v[models[modelscount-1].count-1].pts[2].z = z3;
-                       models[modelscount-1].v[models[modelscount-1].count-1].pts[2].u = u3;
-                       models[modelscount-1].v[models[modelscount-1].count-1].pts[2].v = v3;
-               }
-
-               void VertexController::_AllocateVertex() {
-                       models[modelscount-1].count += 1;
-                       models[modelscount-1].v = (PrimData*)realloc(models[modelscount-1].v, sizeof(PrimData) * models[modelscount-1].count);
-               }
-
-               void VertexController::PushDone() {
-
-               }
+        VertexController::VertexController(ContextManager* cx) {
+            ctx = cx;
+        }
+
+        // Storage initializers.
+        void VertexController::LoadModel() {
+
+        }
+
+        // Programmatic Model Creation.
+        void VertexController::PushModel(int mode) {
+            ++modelscount;
+            models = NULL;
+
+            models = (ModelData*)realloc(models, sizeof(ModelData) * modelscount);
+
+            models[modelscount-1].pts = mode;
+            models[modelscount-1].count = 0;
+            models[modelscount-1].v = NULL;
+        }
+
+        void VertexController::PushTexture(char* fname) {
+            void* ptr = ctx->LoadImage(fname);
+            models[modelscount-1].t = ((GLuint*)ctx->GLTexImage(ptr))[0];
+        }
+
+        void VertexController::PushQuad(    GLfloat x1, GLfloat y1, GLfloat z1, GLfloat u1, GLfloat v1,
+                                            GLfloat x2, GLfloat y2, GLfloat z2, GLfloat u2, GLfloat v2,
+                                            GLfloat x3, GLfloat y3, GLfloat z3, GLfloat u3, GLfloat v3,
+                                            GLfloat x4, GLfloat y4, GLfloat z4, GLfloat u4, GLfloat v4  ) {
+            _AllocateVertex();
+
+            models[modelscount-1].v[models[modelscount-1].count-1].pts[0].x = x1;
+            models[modelscount-1].v[models[modelscount-1].count-1].pts[0].y = y1;
+            models[modelscount-1].v[models[modelscount-1].count-1].pts[0].z = z1;
+            models[modelscount-1].v[models[modelscount-1].count-1].pts[0].u = u1;
+            models[modelscount-1].v[models[modelscount-1].count-1].pts[0].v = v1;
+
+            models[modelscount-1].v[models[modelscount-1].count-1].pts[1].x = x2;
+            models[modelscount-1].v[models[modelscount-1].count-1].pts[1].y = y2;
+            models[modelscount-1].v[models[modelscount-1].count-1].pts[1].z = z2;
+            models[modelscount-1].v[models[modelscount-1].count-1].pts[1].u = u2;
+            models[modelscount-1].v[models[modelscount-1].count-1].pts[1].v = v2;
+
+            models[modelscount-1].v[models[modelscount-1].count-1].pts[2].x = x3;
+            models[modelscount-1].v[models[modelscount-1].count-1].pts[2].y = y3;
+            models[modelscount-1].v[models[modelscount-1].count-1].pts[2].z = z3;
+            models[modelscount-1].v[models[modelscount-1].count-1].pts[2].u = u3;
+            models[modelscount-1].v[models[modelscount-1].count-1].pts[2].v = v3;
+
+            models[modelscount-1].v[models[modelscount-1].count-1].pts[3].x = x4;
+            models[modelscount-1].v[models[modelscount-1].count-1].pts[3].y = y4;
+            models[modelscount-1].v[models[modelscount-1].count-1].pts[3].z = z4;
+            models[modelscount-1].v[models[modelscount-1].count-1].pts[3].u = u4;
+            models[modelscount-1].v[models[modelscount-1].count-1].pts[3].v = v4;
+
+
+        }
+
+        void VertexController::PushTri(       GLfloat x1, GLfloat y1, GLfloat z1, GLfloat u1, GLfloat v1,
+                                            GLfloat x2, GLfloat y2, GLfloat z2, GLfloat u2, GLfloat v2,
+                                            GLfloat x3, GLfloat y3, GLfloat z3, GLfloat u3, GLfloat v3  ) {
+            _AllocateVertex();
+
+            models[modelscount-1].v[models[modelscount-1].count-1].pts[0].x = x1;
+            models[modelscount-1].v[models[modelscount-1].count-1].pts[0].y = y1;
+            models[modelscount-1].v[models[modelscount-1].count-1].pts[0].z = z1;
+            models[modelscount-1].v[models[modelscount-1].count-1].pts[0].u = u1;
+            models[modelscount-1].v[models[modelscount-1].count-1].pts[0].v = v1;
+
+            models[modelscount-1].v[models[modelscount-1].count-1].pts[1].x = x2;
+            models[modelscount-1].v[models[modelscount-1].count-1].pts[1].y = y2;
+            models[modelscount-1].v[models[modelscount-1].count-1].pts[1].z = z2;
+            models[modelscount-1].v[models[modelscount-1].count-1].pts[1].u = u2;
+            models[modelscount-1].v[models[modelscount-1].count-1].pts[1].v = v2;
+
+            models[modelscount-1].v[models[modelscount-1].count-1].pts[2].x = x3;
+            models[modelscount-1].v[models[modelscount-1].count-1].pts[2].y = y3;
+            models[modelscount-1].v[models[modelscount-1].count-1].pts[2].z = z3;
+            models[modelscount-1].v[models[modelscount-1].count-1].pts[2].u = u3;
+            models[modelscount-1].v[models[modelscount-1].count-1].pts[2].v = v3;
+        }
+
+        void VertexController::_AllocateVertex() {
+            models[modelscount-1].count += 1;
+            models[modelscount-1].v = (PrimData*)realloc(models[modelscount-1].v, sizeof(PrimData) * models[modelscount-1].count);
+        }
+
+        void VertexController::PushDone() {
+
+        }
index e1dfd859f392d270b5f88118a5afae58510529fd..7dece62939d9523e670c592d814e51b50d6b20b4 100644 (file)
@@ -5,45 +5,45 @@
 #include <string>
 
 class DataContainer {
-       public:
-               DataContainer();
+    public:
+        DataContainer();
 
-               ContextManager* ctx;
-               int if_fail;
-               bool wait_input;
-               char current_scr[400], current_music[400], current_bg[400];
-               int screen_w;
-               int screen_h;
-               int physical_w;
-               int physical_h;
-               int render_x1;
-               int render_y1;
-               int render_x2;
-               int render_y2;
-               int text_gap;
-               int text_size;
-               int text_x;
-               int text_y;
-               std::map<std::string, int> *s_flags;
-               bool jumped;
-               int* choice_coords;
-               int choices;
-               FILE* accessScriptHandle;
-               char** main_scr; // Default value.
-               bool vndc_enabled;
-               bool quote_incomplete;
-               bool debug_mode;
-               bool debug_to_shell;
-               bool verbose;
-               int currentLine;
-               bool skip_key_on;
-               int rendering_mode;
-               bool fullscreen;
-               bool eof;
-               char* window_name;
-               char* next_line; // Used for voice-detect.
-                                       // It's impossible to parse without lookahead.
-               UDisplayable* text_box_base;
+        ContextManager* ctx;
+        int if_fail;
+        bool wait_input;
+        char current_scr[400], current_music[400], current_bg[400];
+        int screen_w;
+        int screen_h;
+        int physical_w;
+        int physical_h;
+        int render_x1;
+        int render_y1;
+        int render_x2;
+        int render_y2;
+        int text_gap;
+        int text_size;
+        int text_x;
+        int text_y;
+        std::map<std::string, int> *s_flags;
+        bool jumped;
+        int* choice_coords;
+        int choices;
+        FILE* accessScriptHandle;
+        char** main_scr; // Default value.
+        bool vndc_enabled;
+        bool quote_incomplete;
+        bool debug_mode;
+        bool debug_to_shell;
+        bool verbose;
+        int currentLine;
+        bool skip_key_on;
+        int rendering_mode;
+        bool fullscreen;
+        bool eof;
+        char* window_name;
+        char* next_line; // Used for voice-detect.
+                    // It's impossible to parse without lookahead.
+        UDisplayable* text_box_base;
 };
 
 DataContainer* GetData();
index 3ae17bafee85eb38c1184472cc2a6882cd901a64..adeeb109d173b0d6b3a71ed4ddf343bc01906b75 100644 (file)
@@ -10,9 +10,9 @@
 
 #include "Data.hpp"
 
-void Parse();                          // This reads commands from files.
-void ParseShell();                     // This reads commands from the shell.
-void ParseCmd(char* line);     // This does the heavy lifting.
+void Parse();                // This reads commands from files.
+void ParseShell();            // This reads commands from the shell.
+void ParseCmd(char* line);     // This does the heavy lifting.
 void Loop();
 void Wait();
 void Setup();
diff --git a/vndc/include/gitrev.hpp b/vndc/include/gitrev.hpp
new file mode 100644 (file)
index 0000000..5bec3a8
--- /dev/null
@@ -0,0 +1,5 @@
+#ifndef GIT_REV_HDR
+#define GIT_REV_HDR
+#define GIT_REV "6be35badb2e320ca50d0f6df6f9ca998210dbdd8"
+
+#endif
index 17b3def2fe02c140bf66e364ec11e642ca56b78d..8ce62129e6f6fd4a4a4e79be7ec46c9787dee46c 100644 (file)
@@ -7,100 +7,100 @@ DataContainer* data = NULL;
 const char* loadup = "script/main.scr";
 
 DataContainer::DataContainer() {
-       if_fail = 0;
-       wait_input = false;
-       screen_w = 800;
-       screen_h = 600;
-       physical_w = 800;
-       physical_h = 600;
-       render_x1 = screen_w / 15;
-       render_y1 = screen_h / 15;
-       render_x2 = screen_w / 15 * 14;
-       render_y2 = screen_h / 15 * 13;
-       text_x = render_x1;
-       text_y = render_y1;
-       text_gap = 35;
-       text_size = 24;
-       jumped = false;
-       choice_coords = NULL;
-       choices = 0;
-       accessScriptHandle = NULL;
-       vndc_enabled = true;
-       quote_incomplete = false;
-       debug_mode = false;
-       debug_to_shell = false;
-       verbose = false;
-       currentLine = 0;
-       skip_key_on = false;
+    if_fail = 0;
+    wait_input = false;
+    screen_w = 800;
+    screen_h = 600;
+    physical_w = 800;
+    physical_h = 600;
+    render_x1 = screen_w / 15;
+    render_y1 = screen_h / 15;
+    render_x2 = screen_w / 15 * 14;
+    render_y2 = screen_h / 15 * 13;
+    text_x = render_x1;
+    text_y = render_y1;
+    text_gap = 35;
+    text_size = 24;
+    jumped = false;
+    choice_coords = NULL;
+    choices = 0;
+    accessScriptHandle = NULL;
+    vndc_enabled = true;
+    quote_incomplete = false;
+    debug_mode = false;
+    debug_to_shell = false;
+    verbose = false;
+    currentLine = 0;
+    skip_key_on = false;
 #ifdef USE_ANDROID
-       rendering_mode = 0;
-       fullscreen = true;
+    rendering_mode = 0;
+    fullscreen = true;
 #else
-       rendering_mode = 1;
-       fullscreen = false;
+    rendering_mode = 1;
+    fullscreen = false;
 #endif
-       eof = false;
-       next_line = NULL; // Used for voice-detect.
-                                       // It's impossible to parse without lookahead.
+    eof = false;
+    next_line = NULL; // Used for voice-detect.
+                    // It's impossible to parse without lookahead.
 }
 
 void Data_PreInit() {
-       data = new DataContainer();
+    data = new DataContainer();
 
-       /* Storage of values for saves */
-       GetData()->main_scr = (char**)calloc(sizeof(char*), 1);
-       GetData()->main_scr[0] = (char*)calloc(sizeof(char), 400);
-       strncpy(GetData()->main_scr[0], loadup, 400);
+    /* Storage of values for saves */
+    GetData()->main_scr = (char**)calloc(sizeof(char*), 1);
+    GetData()->main_scr[0] = (char*)calloc(sizeof(char), 400);
+    strncpy(GetData()->main_scr[0], loadup, 400);
 }
 
 void Data_PostInit() {
-       /* Generate the surface for use with cleartext. */
-       int width_dr = (GetData()->render_x2 - GetData()->render_x1 + 20);
-       int height_dr = (GetData()->render_y2 - GetData()->render_y1 + 20 + 30);
+    /* Generate the surface for use with cleartext. */
+    int width_dr = (GetData()->render_x2 - GetData()->render_x1 + 20);
+    int height_dr = (GetData()->render_y2 - GetData()->render_y1 + 20 + 30);
 
-       SDL_Surface* pass_sfc = SDL_CreateRGBSurface(0, width_dr, height_dr, 32, RED_MASK, GREEN_MASK, BLUE_MASK, ALPHA_MASK);
-       SDL_FillRect(pass_sfc, NULL, SDL_MapRGBA(pass_sfc->format, 0, 0, 0, 100));
+    SDL_Surface* pass_sfc = SDL_CreateRGBSurface(0, width_dr, height_dr, 32, RED_MASK, GREEN_MASK, BLUE_MASK, ALPHA_MASK);
+    SDL_FillRect(pass_sfc, NULL, SDL_MapRGBA(pass_sfc->format, 0, 0, 0, 100));
 
-       GetData()->text_box_base = new UDisplayable(GetData()->ctx, Normal, pass_sfc);
-       GetData()->text_box_base->SetOverlay(true);
-       GetData()->text_box_base->SetXY(GetData()->render_x1 - 10, GetData()->render_y1 - 10);
+    GetData()->text_box_base = new UDisplayable(GetData()->ctx, Normal, pass_sfc);
+    GetData()->text_box_base->SetOverlay(true);
+    GetData()->text_box_base->SetXY(GetData()->render_x1 - 10, GetData()->render_y1 - 10);
 }
 
 DataContainer* GetData() {
-       return &data[0];
+    return &data[0];
 }
 
 void DumpSave(char* fname) {
-       // Dump variables.
-       // Dump script file.
-
-       // A save actually ends up as a mini-script.
-       // So, to load a save you load something like this as the
-       // main script:
-
-       // setvar data1 = 6
-       // setvar data2 = 9
-       // music mus
-       // bgload bg
-       // jump script.scr 60
-
-       FILE* save_to = fopen(fname, "w");
-
-       std::map<std::string, int> data_vals = GetData()->s_flags[0];
-
-       if(!data_vals.empty()) {
-               std::map<std::string, int>::iterator item = data_vals.begin();
-               while(item != data_vals.end()) {
-                       if(strcmp(item->first.c_str(), "selected"))
-                               fprintf(save_to, "setvar %s = %d\n", item->first.c_str(), item->second);
-
-                       ++item;
-               }
-       }
-
-       fprintf(save_to, "music %s\n", &(GetData()->current_music[6]));
-       fprintf(save_to, "bgload %s\n", &(GetData()->current_bg[11]));
-       fprintf(save_to, "jump %s %d\n", &(GetData()->current_scr[7]), GetData()->currentLine - 1); // The text ack'd with leftclick
-                                                                                                   // So restore back one to replay
-       fclose(save_to);
+    // Dump variables.
+    // Dump script file.
+
+    // A save actually ends up as a mini-script.
+    // So, to load a save you load something like this as the
+    // main script:
+
+    // setvar data1 = 6
+    // setvar data2 = 9
+    // music mus
+    // bgload bg
+    // jump script.scr 60
+
+    FILE* save_to = fopen(fname, "w");
+
+    std::map<std::string, int> data_vals = GetData()->s_flags[0];
+
+    if(!data_vals.empty()) {
+        std::map<std::string, int>::iterator item = data_vals.begin();
+        while(item != data_vals.end()) {
+            if(strcmp(item->first.c_str(), "selected"))
+                fprintf(save_to, "setvar %s = %d\n", item->first.c_str(), item->second);
+
+            ++item;
+        }
+    }
+
+    fprintf(save_to, "music %s\n", &(GetData()->current_music[6]));
+    fprintf(save_to, "bgload %s\n", &(GetData()->current_bg[11]));
+    fprintf(save_to, "jump %s %d\n", &(GetData()->current_scr[7]), GetData()->currentLine - 1); // The text ack'd with leftclick
+                                                    // So restore back one to replay
+    fclose(save_to);
 }
index 788d07ee6d14d446b15ef2354d7d6fed4e462e0a..3af975d0e7d25cad370ee43c3e09daec1241dd48 100644 (file)
@@ -3,71 +3,71 @@
 #include "Funcs.hpp"
 
 void Wait() {
-       // If wait wasn't specified, don't halt.
-       // Don't even bother with extensions off.
-       // If we're currently in a quote, leave it alone.
-       // If the line is spoken, then halt previous spoken lines.
-       // If the skip key is held, just gogogo
+    // If wait wasn't specified, don't halt.
+    // Don't even bother with extensions off.
+    // If we're currently in a quote, leave it alone.
+    // If the line is spoken, then halt previous spoken lines.
+    // If the skip key is held, just gogogo
 
-       // bool stop_voice = GetData()->wait_input && GetData()->vndc_enabled && GetData()->is_spoken_line;
+    // bool stop_voice = GetData()->wait_input && GetData()->vndc_enabled && GetData()->is_spoken_line;
 
-       while((GetData()->wait_input && !GetData()->ctx->GetQuit())) {
-               GetData()->ctx->Input();
+    while((GetData()->wait_input && !GetData()->ctx->GetQuit())) {
+        GetData()->ctx->Input();
 
-               GetData()->ctx->Flush();
+        GetData()->ctx->Flush();
 
-               if(GetData()->debug_to_shell)
-                       ParseShell();
+        if(GetData()->debug_to_shell)
+            ParseShell();
 
-               if(GetData()->ctx->GetInput(1)) break;
-       }
+        if(GetData()->ctx->GetInput(1)) break;
+    }
 }
 
 void Loop() {
-       if(GetData()->ctx->GetQuit()) return;
-               Parse();
+    if(GetData()->ctx->GetQuit()) return;
+        Parse();
 
-       // We don't clear. This system uses dirty blits. ;P
-       GetData()->ctx->Flush();
+    // We don't clear. This system uses dirty blits. ;P
+    GetData()->ctx->Flush();
 
-       GetData()->ctx->StartSync();
+    GetData()->ctx->StartSync();
 
-               Wait();
+        Wait();
 
-       GetData()->ctx->EndSync();
+    GetData()->ctx->EndSync();
 }
 
 void Setup() {
-       // Init window
-       if (GetData()->rendering_mode == 0)
-               GetData()->ctx->InitWindowLogical(GetData()->physical_w, GetData()->physical_h, GetData()->screen_w, GetData()->screen_h, GetData()->fullscreen, Software);
-       else if (GetData()->rendering_mode == 1)
-               GetData()->ctx->InitWindowLogical(GetData()->physical_w, GetData()->physical_h, GetData()->screen_w, GetData()->screen_h, GetData()->fullscreen, Accel2d);
-       else if (GetData()->rendering_mode == 2)
-               GetData()->ctx->InitWindowLogical(GetData()->physical_w, GetData()->physical_h, GetData()->screen_w, GetData()->screen_h, GetData()->fullscreen, OpenGL);
+    // Init window
+    if (GetData()->rendering_mode == 0)
+        GetData()->ctx->InitWindowLogical(GetData()->physical_w, GetData()->physical_h, GetData()->screen_w, GetData()->screen_h, GetData()->fullscreen, Software);
+    else if (GetData()->rendering_mode == 1)
+        GetData()->ctx->InitWindowLogical(GetData()->physical_w, GetData()->physical_h, GetData()->screen_w, GetData()->screen_h, GetData()->fullscreen, Accel2d);
+    else if (GetData()->rendering_mode == 2)
+        GetData()->ctx->InitWindowLogical(GetData()->physical_w, GetData()->physical_h, GetData()->screen_w, GetData()->screen_h, GetData()->fullscreen, OpenGL);
 
-       GetData()->window_name = (char*)calloc(sizeof(char), 400);
-       sprintf(GetData()->window_name, "%s", "VNDC Interpreter ");
-       GetData()->ctx->SetTitle(GetData()->window_name);
+    GetData()->window_name = (char*)calloc(sizeof(char), 400);
+    sprintf(GetData()->window_name, "%s", "VNDC Interpreter ");
+    GetData()->ctx->SetTitle(GetData()->window_name);
 
-       GetData()->ctx->InputMode(Burst);
+    GetData()->ctx->InputMode(Burst);
 
-       // Input
-       GetData()->ctx->RegisterMouse(&InputAdvance);
-       GetData()->ctx->RegisterInput(SDLK_ESCAPE, &QuitKey);
-       GetData()->ctx->RegisterInput(SDLK_LCTRL, &NopKey);
+    // Input
+    GetData()->ctx->RegisterMouse(&InputAdvance);
+    GetData()->ctx->RegisterInput(SDLK_ESCAPE, &QuitKey);
+    GetData()->ctx->RegisterInput(SDLK_LCTRL, &NopKey);
 
-       GetData()->s_flags = new std::map<std::string, int>();
+    GetData()->s_flags = new std::map<std::string, int>();
 
-       // Font
-       // FIXME - Not loading default.ttf is a segv. Print an error instead
-       GetData()->ctx->Text()->LoadFont((char*)"default.ttf", GetData()->text_size);
-       GetData()->ctx->Text()->SetFontUsed(1);
+    // Font
+    // FIXME - Not loading default.ttf is a segv. Print an error instead
+    GetData()->ctx->Text()->LoadFont((char*)"default.ttf", GetData()->text_size);
+    GetData()->ctx->Text()->SetFontUsed(1);
 
-       GetData()->ctx->Text()->Outline(1);
-       GetData()->ctx->Text()->SetColor(255,255,255,255);
+    GetData()->ctx->Text()->Outline(1);
+    GetData()->ctx->Text()->SetColor(255,255,255,255);
 
-       Data_PostInit();
+    Data_PostInit();
 
-       op_cleartext();
+    op_cleartext();
 }
index 2effdac30741001f1986c868510e12f43685b76d..19f946bf12c05972559bd3bdc838d87d336f7785 100644 (file)
 
 void ParseCmd(char* line) {
 
-       char *passthru_line = (char*)calloc(sizeof(char), 400);
-
-       char** tokens = NULL;
-
-       strncpy(passthru_line, line, sizeof(char)*400);
-
-       if(GetData()->verbose) printf("[scr] %s\n", line);
-
-       int num = 1;
-       tokens = (char**)realloc(NULL, sizeof(char*) * (1));
-       tokens[num-1] = strtok(line, " ");
-
-       do {
-               #ifdef DEBUG_OVERKILL
-               printf("Loop: num = %d;\n", num);
-               #endif
-               ++num;
-               tokens = (char**)realloc(tokens, sizeof(char*) * (num));
-               tokens[num-1] = strtok(NULL, " ");
-       } while(tokens[num-1] != NULL);
-
-       --num;
-
-       //printf("Made it out of the loop.\n");
-       //for (int i = 0; i < num; i++) {
-               //printf("[param] %d = '%s'\n", i, tokens[i]);
-       //}
-
-       int value_1, value_2;
-
-       if(!strcmp(tokens[0], "bgload")) {
-               //printf("[OP::bgload] exec (params:%d)", num-1);
-               if (num > 2) {
-                       sscanf(tokens[2], "%d", &value_1);
-                       op_bgload(tokens[1], &value_1);
-               }
-               else
-                       op_bgload(tokens[1], NULL);
-       }
-       else if(!strcmp(tokens[0], "setimg")) {
-               sscanf(tokens[2], "%d", &value_1);
-               sscanf(tokens[3], "%d", &value_2);
-               op_setimg(tokens[1], &value_1, &value_2);
-       }
-       else if(!strcmp(tokens[0], "sound")) {
-               // Another ridiculous thing. Second parameter if not
-               // specified is implicity one
-               if(num > 2) {
-                       sscanf(tokens[2], "%d", &value_1);
-                       op_sound(tokens[1], &value_1);
-               }
-               else
-                       op_sound(tokens[1], NULL);
-       }
-       else if(!strcmp(tokens[0], "music"))
-               op_music(tokens[1]);
-       else if(!strcmp(tokens[0], "text")) {
-               // Because of *reasons* (lack of quotes) we use the copy of line,
-               // passthru_line and adjust the pointer to use that.
-               // strtok destroys the structure
-               // And there's the possibility of a zero-length string as well.
-               //printf("[op_text] Reconstructed string = '%s'\n", &passthru_line[5]);
-               op_text(&passthru_line[5]);
-       }
-       else if(!strcmp(tokens[0], "choice")) {
-               op_choice(&passthru_line[7]);
-       }
-       else if(!strcmp(tokens[0], "setvar")) {
-               if(num > 3) {
-                       if(!strcmp(tokens[2], "="))
-                               value_1 = 0;
-                       else if(!strcmp(tokens[2], "+"))
-                               value_1 = 1;
-                       else if(!strcmp(tokens[2], "-"))
-                               value_1 = -1;
-                       else if(!strcmp(tokens[2], "~")) // Apparently resets. UGH NOT DOC'D
-                               value_1 = -2;
-
-
-                       sscanf(tokens[3], "%d", &value_2);
-                       op_setvar(tokens[1], &value_1, tokens[3]);
-               }
-               else {
-                       value_1 = -2;
-                       op_setvar(tokens[1], &value_1, NULL);
-               }
-       }
-       else if(!strcmp(tokens[0], "gsetvar")) {
-               if(!strcmp(tokens[2], "="))
-                       value_1 = 0;
-               else if(!strcmp(tokens[2], "+"))
-                       value_1 = 1;
-               else if(!strcmp(tokens[2], "-"))
-                       value_1 = -1;
-
-               op_gsetvar(tokens[1], &value_1, tokens[3]);
-       }
-       else if(!strcmp(tokens[0], "if")) {
-               if(!strcmp(tokens[2], "<="))
-                       value_1 = 0;
-               else if(!strcmp(tokens[2], "<"))
-                       value_1 = 1;
-               else if(!strcmp(tokens[2], "=="))
-                       value_1 = 2;
-               else if(!strcmp(tokens[2], "!="))
-                       value_1 = 3;
-               else if(!strcmp(tokens[2], ">"))
-                       value_1 = 4;
-               else if(!strcmp(tokens[2], ">="))
-                       value_1 = 5;
-
-               op_if(tokens[1], &value_1, tokens[3]);
-       }
-       else if(!strcmp(tokens[0], "fi"))
-               op_fi();
-       else if(!strcmp(tokens[0], "jump")) {
-               if(num > 2) {
-                       sscanf(tokens[2], "%d", &value_1);
-                       op_jump(tokens[1], &value_1, false);
-               }
-               else
-                       op_jump(tokens[1], NULL, false);
-       }
-       else if(!strcmp(tokens[0], "delay")) {
-               sscanf(tokens[1], "%d", &value_1);
-               op_delay(&value_1);
-       }
-       else if(!strcmp(tokens[0], "random")) {
-               sscanf(tokens[2], "%d", &value_1);
-               sscanf(tokens[3], "%d", &value_2);
-               op_random(tokens[1], &value_1, &value_2);
-       }
-       else if(!strcmp(tokens[0], "goto"))
-               op_goto(tokens[1]);
-       else if(!strcmp(tokens[0], "cleartext"))
-               op_cleartext();
-       else if(!strcmp(tokens[0], "save") && num == 2)
-               op_save(tokens[1]);
-
-       free(tokens);
-       free(passthru_line);
+    char *passthru_line = (char*)calloc(sizeof(char), 400);
+
+    char** tokens = NULL;
+
+    strncpy(passthru_line, line, sizeof(char)*400);
+
+    if(GetData()->verbose) printf("[scr] %s\n", line);
+
+    int num = 1;
+    tokens = (char**)realloc(NULL, sizeof(char*) * (1));
+    tokens[num-1] = strtok(line, " ");
+
+    do {
+        #ifdef DEBUG_OVERKILL
+        printf("Loop: num = %d;\n", num);
+        #endif
+        ++num;
+        tokens = (char**)realloc(tokens, sizeof(char*) * (num));
+        tokens[num-1] = strtok(NULL, " ");
+    } while(tokens[num-1] != NULL);
+
+    --num;
+
+    //printf("Made it out of the loop.\n");
+    //for (int i = 0; i < num; i++) {
+        //printf("[param] %d = '%s'\n", i, tokens[i]);
+    //}
+
+    int value_1, value_2;
+
+    if(!strcmp(tokens[0], "bgload")) {
+        //printf("[OP::bgload] exec (params:%d)", num-1);
+        if (num > 2) {
+            sscanf(tokens[2], "%d", &value_1);
+            op_bgload(tokens[1], &value_1);
+        }
+        else
+            op_bgload(tokens[1], NULL);
+    }
+    else if(!strcmp(tokens[0], "setimg")) {
+        sscanf(tokens[2], "%d", &value_1);
+        sscanf(tokens[3], "%d", &value_2);
+        op_setimg(tokens[1], &value_1, &value_2);
+    }
+    else if(!strcmp(tokens[0], "sound")) {
+        // Another ridiculous thing. Second parameter if not
+        // specified is implicity one
+        if(num > 2) {
+            sscanf(tokens[2], "%d", &value_1);
+            op_sound(tokens[1], &value_1);
+        }
+        else
+            op_sound(tokens[1], NULL);
+    }
+    else if(!strcmp(tokens[0], "music"))
+        op_music(tokens[1]);
+    else if(!strcmp(tokens[0], "text")) {
+        // Because of *reasons* (lack of quotes) we use the copy of line,
+        // passthru_line and adjust the pointer to use that.
+        // strtok destroys the structure
+        // And there's the possibility of a zero-length string as well.
+        //printf("[op_text] Reconstructed string = '%s'\n", &passthru_line[5]);
+        op_text(&passthru_line[5]);
+    }
+    else if(!strcmp(tokens[0], "choice")) {
+        op_choice(&passthru_line[7]);
+    }
+    else if(!strcmp(tokens[0], "setvar")) {
+        if(num > 3) {
+            if(!strcmp(tokens[2], "="))
+                value_1 = 0;
+            else if(!strcmp(tokens[2], "+"))
+                value_1 = 1;
+            else if(!strcmp(tokens[2], "-"))
+                value_1 = -1;
+            else if(!strcmp(tokens[2], "~")) // Apparently resets. UGH NOT DOC'D
+                value_1 = -2;
+
+
+            sscanf(tokens[3], "%d", &value_2);
+            op_setvar(tokens[1], &value_1, tokens[3]);
+        }
+        else {
+            value_1 = -2;
+            op_setvar(tokens[1], &value_1, NULL);
+        }
+    }
+    else if(!strcmp(tokens[0], "gsetvar")) {
+        if(!strcmp(tokens[2], "="))
+            value_1 = 0;
+        else if(!strcmp(tokens[2], "+"))
+            value_1 = 1;
+        else if(!strcmp(tokens[2], "-"))
+            value_1 = -1;
+
+        op_gsetvar(tokens[1], &value_1, tokens[3]);
+    }
+    else if(!strcmp(tokens[0], "if")) {
+        if(!strcmp(tokens[2], "<="))
+            value_1 = 0;
+        else if(!strcmp(tokens[2], "<"))
+            value_1 = 1;
+        else if(!strcmp(tokens[2], "=="))
+            value_1 = 2;
+        else if(!strcmp(tokens[2], "!="))
+            value_1 = 3;
+        else if(!strcmp(tokens[2], ">"))
+            value_1 = 4;
+        else if(!strcmp(tokens[2], ">="))
+            value_1 = 5;
+
+        op_if(tokens[1], &value_1, tokens[3]);
+    }
+    else if(!strcmp(tokens[0], "fi"))
+        op_fi();
+    else if(!strcmp(tokens[0], "jump")) {
+        if(num > 2) {
+            sscanf(tokens[2], "%d", &value_1);
+            op_jump(tokens[1], &value_1, false);
+        }
+        else
+            op_jump(tokens[1], NULL, false);
+    }
+    else if(!strcmp(tokens[0], "delay")) {
+        sscanf(tokens[1], "%d", &value_1);
+        op_delay(&value_1);
+    }
+    else if(!strcmp(tokens[0], "random")) {
+        sscanf(tokens[2], "%d", &value_1);
+        sscanf(tokens[3], "%d", &value_2);
+        op_random(tokens[1], &value_1, &value_2);
+    }
+    else if(!strcmp(tokens[0], "goto"))
+        op_goto(tokens[1]);
+    else if(!strcmp(tokens[0], "cleartext"))
+        op_cleartext();
+    else if(!strcmp(tokens[0], "save") && num == 2)
+        op_save(tokens[1]);
+
+    free(tokens);
+    free(passthru_line);
 }
 
 void ParseShell() {
-       bool DebugContinue = true;
-       char buffer[400];
-       while(DebugContinue) {
-               memset(buffer, 0, sizeof(char)*400);
-
-               printf("[scr command] $ ");
-               fgets(buffer, 400, stdin);
-
-               // Remove all '\n' from this string
-               for(int i=0; i < 400; i++) {
-                       if (buffer[i] == '\n')
-                               buffer[i] = '\0';
-               }
-
-               if(!strcmp(buffer, "help") || strlen(buffer) < 1) {
-                       printf("%s\n", "Commands available:");
-                       printf("\t%s\t\t\t%s\n", "(debug) resume", "Stops debug mode");
-                       printf("\t%s\t\t\t%s\n", "(debug) quit", "Quits game");
-                       printf("\t%s\t\t%s\n", "(debug) save [file]", "Saves immediately to file");
-                       printf("\t%s\t%s\n", "setvar [var] [mod] [val]", "Set save flag");
-                       printf("\t%s\t%s\n", "gsetvar [var] [mod] [val]", "Set system flag");
-                       printf("\t%s\t\t\t%s\n", "text [text] ...", "Display text");
-                       printf("\t%s\t\t%s\n", "sound [file] (num)", "Play sound num times");
-                       printf("\t%s\t\t\t%s\n", "music [file]", "Play music");
-                       printf("\t%s\t\t%s\n", "setimg [file] [x] [y]", "Display image at x,y");
-                       printf("\t%s\t%s\n", "random [var] [low] [high]", "Store random number in var");
-                       printf("\t%s\t\t%s\n", "jump [file.scr] {N}", "Switch to file.src (goto line N)");
-                       printf("\t%s\t\t\t%s\n", "goto [label]", "Goto label in current file");
-                       printf("\t%s\t\t%s\n", "if [var] [op] [val]", "Test condition, and execute till\n\t\t\t\t\tfi if true");
-                       printf("\t%s\t\t\t\t%s\n", "fi", "Stop computing if");
-                       printf("\t%s\t\t\t%s\n", "delay [frames]", "Delay frames (at 60fps)");
-                       printf("\t%s\t\t\t%s\n", "cleartext", "Clear text from screen");
-                       printf("\t%s\t%s\n", "choice [ch|ch|...] {<var}", "Get input for choice. Store to selected\n\t\t\t\t\t(or var if extensions are on)");
-                       printf("\t%s\t%s\n", "bgload [file] [fadeframes]", "Load background");
-               }
-               else if (!strcmp(buffer, "quit")) {
-                       printf("[debug] Setting quit status & stopping debug.\n");
-                       GetData()->ctx->SetQuit();
-                       DebugContinue = false;
-               }
-               else if (!strcmp(buffer, "resume")) {
-                       printf("[debug] Exiting debug shell and resuming.\n");
-                       DebugContinue = false;
-                       GetData()->wait_input = true;
-               }
-               else if (!strncmp(buffer, "debugsave", 4)) {
-                       char* savefile = &buffer[5];
-                       printf("[debug] Saving to file '%s' NOW.\n", savefile);
-                       DumpSave(savefile);
-               }
-               else {
-                       ParseCmd(buffer);
-                       GetData()->ctx->Flush();
-                       GetData()->wait_input = false;
-               }
-       }
-       GetData()->debug_to_shell = false;
+    bool DebugContinue = true;
+    char buffer[400];
+    while(DebugContinue) {
+        memset(buffer, 0, sizeof(char)*400);
+
+        printf("[scr command] $ ");
+        fgets(buffer, 400, stdin);
+
+        // Remove all '\n' from this string
+        for(int i=0; i < 400; i++) {
+            if (buffer[i] == '\n')
+                buffer[i] = '\0';
+        }
+
+        if(!strcmp(buffer, "help") || strlen(buffer) < 1) {
+            printf("%s\n", "Commands available:");
+            printf("\t%s\t\t\t%s\n", "(debug) resume", "Stops debug mode");
+            printf("\t%s\t\t\t%s\n", "(debug) quit", "Quits game");
+            printf("\t%s\t\t%s\n", "(debug) save [file]", "Saves immediately to file");
+            printf("\t%s\t%s\n", "setvar [var] [mod] [val]", "Set save flag");
+            printf("\t%s\t%s\n", "gsetvar [var] [mod] [val]", "Set system flag");
+            printf("\t%s\t\t\t%s\n", "text [text] ...", "Display text");
+            printf("\t%s\t\t%s\n", "sound [file] (num)", "Play sound num times");
+            printf("\t%s\t\t\t%s\n", "music [file]", "Play music");
+            printf("\t%s\t\t%s\n", "setimg [file] [x] [y]", "Display image at x,y");
+            printf("\t%s\t%s\n", "random [var] [low] [high]", "Store random number in var");
+            printf("\t%s\t\t%s\n", "jump [file.scr] {N}", "Switch to file.src (goto line N)");
+            printf("\t%s\t\t\t%s\n", "goto [label]", "Goto label in current file");
+            printf("\t%s\t\t%s\n", "if [var] [op] [val]", "Test condition, and execute till\n\t\t\t\t\tfi if true");
+            printf("\t%s\t\t\t\t%s\n", "fi", "Stop computing if");
+            printf("\t%s\t\t\t%s\n", "delay [frames]", "Delay frames (at 60fps)");
+            printf("\t%s\t\t\t%s\n", "cleartext", "Clear text from screen");
+            printf("\t%s\t%s\n", "choice [ch|ch|...] {<var}", "Get input for choice. Store to selected\n\t\t\t\t\t(or var if extensions are on)");
+            printf("\t%s\t%s\n", "bgload [file] [fadeframes]", "Load background");
+        }
+        else if (!strcmp(buffer, "quit")) {
+            printf("[debug] Setting quit status & stopping debug.\n");
+            GetData()->ctx->SetQuit();
+            DebugContinue = false;
+        }
+        else if (!strcmp(buffer, "resume")) {
+            printf("[debug] Exiting debug shell and resuming.\n");
+            DebugContinue = false;
+            GetData()->wait_input = true;
+        }
+        else if (!strncmp(buffer, "debugsave", 4)) {
+            char* savefile = &buffer[5];
+            printf("[debug] Saving to file '%s' NOW.\n", savefile);
+            DumpSave(savefile);
+        }
+        else {
+            ParseCmd(buffer);
+            GetData()->ctx->Flush();
+            GetData()->wait_input = false;
+        }
+    }
+    GetData()->debug_to_shell = false;
 }
 
 void Parse() {
-       if(GetData()->ctx->GetQuit()) return;
+    if(GetData()->ctx->GetQuit()) return;
 
-       ++(GetData()->currentLine);
+    ++(GetData()->currentLine);
 
-       if (!GetData()->accessScriptHandle) {
-               fprintf(stderr, "Could not open script data\n");
-               exit(-8);
-       }
+    if (!GetData()->accessScriptHandle) {
+        fprintf(stderr, "Could not open script data\n");
+        exit(-8);
+    }
 
-       // Load the next line to this one.
-       char* line = GetData()->next_line;
+    // Load the next line to this one.
+    char* line = GetData()->next_line;
 
-       char* line_copy = line;
+    char* line_copy = line;
 
-       while(line_copy[0] == ' ' || line_copy[0] == '\t') {
-               line_copy[0] = '\0';
-               line_copy = &line_copy[1];
-       }
+    while(line_copy[0] == ' ' || line_copy[0] == '\t') {
+        line_copy[0] = '\0';
+        line_copy = &line_copy[1];
+    }
 
-       // Remove all '\n' from the buffer line
-       for(int i=0; i < (int)strlen(line_copy); i++) {
-               if (line_copy[i] == '\n')
-                       line_copy[i] = '\0';
-       }
+    // Remove all '\n' from the buffer line
+    for(int i=0; i < (int)strlen(line_copy); i++) {
+        if (line_copy[i] == '\n')
+            line_copy[i] = '\0';
+    }
 
-       // The next line is null, because the file is finished.
-       if(feof(GetData()->accessScriptHandle) && strlen(GetData()->next_line) == 0) {
-               // We've reached EOF. Jump back and return.
-               op_jump(GetData()->main_scr[0], NULL, true);
-       }
+    // The next line is null, because the file is finished.
+    if(feof(GetData()->accessScriptHandle) && strlen(GetData()->next_line) == 0) {
+        // We've reached EOF. Jump back and return.
+        op_jump(GetData()->main_scr[0], NULL, true);
+    }
 
-       GetData()->next_line = (char*)calloc(sizeof(char), 400);
-       fgets(GetData()->next_line, 400, GetData()->accessScriptHandle);
+    GetData()->next_line = (char*)calloc(sizeof(char), 400);
+    fgets(GetData()->next_line, 400, GetData()->accessScriptHandle);
 
-       // Execute the current line.
-       if(strlen(line_copy) != 0) {
-               ParseCmd(line_copy);
-       }
+    // Execute the current line.
+    if(strlen(line_copy) != 0) {
+        ParseCmd(line_copy);
+    }
 
-       free(line);
+    free(line);
 
-       // Load the next line.
+    // Load the next line.
 
-       return;
+    return;
 }
 
 void InputAdvance(int x, int y, bool down, bool left, bool middle, bool right) {
-       if(GetData()->choices > 0) {
-               // Choose an option.
-               for(int i=0; i<GetData()->choices; i++) {
-                       if(!down && y > GetData()->choice_coords[i*2] && y < GetData()->choice_coords[i*2+1])
-                       {
-                               GetData()->choices = -(i+1); // Negative indicates complete. This is just
-                                                            // for storage savings.
-                       }
-               }
-       }
-       else if(left && !down) {
-               GetData()->wait_input = false;
-       }
+    if(GetData()->choices > 0) {
+        // Choose an option.
+        for(int i=0; i<GetData()->choices; i++) {
+            if(!down && y > GetData()->choice_coords[i*2] && y < GetData()->choice_coords[i*2+1])
+            {
+                GetData()->choices = -(i+1); // Negative indicates complete. This is just
+                                             // for storage savings.
+            }
+        }
+    }
+    else if(left && !down) {
+        GetData()->wait_input = false;
+    }
 }
 
 void QuitKey(bool down) {
-       // Flush data to save.scr
-       DumpSave((char*)"save.scr");
+    // Flush data to save.scr
+    DumpSave((char*)"save.scr");
 
-       GetData()->ctx->SetQuit();
+    GetData()->ctx->SetQuit();
 }
 
 void NopKey(bool down) {}
index f885a9ced9a76139ef493a5d985e4e7528ba35bc..2224f180daac2dd24c75074d8dbf1e31c3167f6f 100644 (file)
 #include <signal.h>
 
 void DebugTrap(int sig) {
-       GetData()->debug_to_shell = true;
+    GetData()->debug_to_shell = true;
 }
 
 int main(int argc, char** argv) {
-       printf(" ___________________________________________________________ \n");
-       printf("| VNDC - VNDC is Not a Direct Clone (of VNDS ;P)            |\n");
-       printf("| Interprets VNDS scripts with a few goodies and extensions |\n");
-       printf("| (C) Jonathan Feldman 2014 - Under the MIT license         |\n");
-       printf("| git: %s             |\n", GIT_REV);
-       printf("|___________________________________________________________|\n\n");
-
-       char* chdir_to_dir = NULL;
-       char* main_script_override = NULL;
-       char* save_file = NULL;
-       bool vndc_extensions = true;
-       int width = 0, height = 0;
-       bool debug_enable = false;
-       bool enable_v = false;
-       bool newgame = false;
-       char c;
-       #ifdef USE_ANDROID
-       int mode = 0;
-       bool fulls = true;
-       #else
-       int mode = 1;
-       bool fulls = false;
-       #endif
-
-       while((c = getopt(argc, argv, "fr:nbvx:y:d:m:s:ch")) != -1) {
-               switch(c) {
-                       case 'f':
-                               printf("[info] Starting in fullscreen mode.\n");
-                               fulls = true;
-                               break;
-                       case 'r':
-                               if(!strcmp(optarg, "sdlsw")) {
-                                       printf("[info] Using SDL software backend.\n");
-                                       mode = 0;
-                               }
-                               if(!strcmp(optarg, "sdlhw")) {
-                                       printf("[info] Using SDL hardware backend.\n");
-                                       mode = 1;
-                               }
-                               if(!strcmp(optarg, "gl")) {
-                                       printf("[info] Using OpenGL backend. (note - experimental)\n");                                 
-                                       mode = 2;
-                               }
-                               break;
-                       case 'n':
-                               printf("[info] New game, not reloading save.\n");
-                               newgame = true;
-                               break;
-                       case 'v':
-                               printf("[info] Script commands will be echoed.\n");
-                               enable_v = true;
-                               break;
-                       case 'b':
-                               printf("[debug] Debug Mode enabled.\n");
-                               debug_enable = true;
-                               break;
-                       case 'd':
-                               printf("[info] Directory specified: %s\n", optarg);
-                               chdir_to_dir = optarg;
-                               break;
-                       case 'x':
-                               sscanf(optarg, "%d", &width);
-                               break;
-                       case 'y':
-                               sscanf(optarg, "%d", &height);
-                               chdir_to_dir = optarg;
-                               break;
-                       case 'm':
-                               printf("[debug] Main script overriden as: '%s'\n", optarg);
-                               main_script_override = optarg;
-                               break;
-                       case 's':
-                               printf("[info] Load save: '%s'\n", optarg);
-                               save_file = optarg;
-                               break;
-                       case 'c':
-                               printf("[debug] Compliant mode: all VNDC extensions off\n");
-                               vndc_extensions = false;
-                               break;
-                       case 'h':
-                               printf("-x size -y size\tStretch display window to WxH\n");
-                               printf("-r mode\t\tUse render mode (sdlsw, sdlhw, gl)\n");
-                               printf("-f\t\tFullscreen mode.\n");
-                               printf("-n\t\tNew Game. Do not reload default save.\n");
-                               printf("-d dir\t\tChange to directory/Run game in directory\n");
-                               printf("-b\t\tDebug Mode. Hit Ctrl+C on console for shell\n");
-                               printf("-v\t\tVerbose. Echo script commands back as they execute\n");
-                               printf("-m .scr\t\tLoad .scr as main script\n");
-                               printf("-s .scr\t\tLoad save .scr instead of default\n");
-                               printf("-c\t\tCompliant mode; don't use VNDC extensions\n");
-                               printf("-h\t\tPrint this help message\n\n");
-                               return 0;
-                               break;
-                       default:
-                               break;
-               }
-       }
-
-       Data_PreInit();
-
-       GetData()->ctx = new ContextManager();
-
-       if(chdir_to_dir)
-               chdir(chdir_to_dir);
-       #ifdef WITH_ANDROID
-       chdir((char*)"/mnt/sdcard/vndc/");
-       #endif
-
-       if(main_script_override != NULL) {
-               printf("[debug] Note that in this mode, l_flags is not set.\n[debug] Expect bugs/gameover, this is normal.\n");
-               memset(GetData()->main_scr[0], 0, 399);
-               strncpy(GetData()->main_scr[0], main_script_override, 399);
-       }
-
-       GetData()->vndc_enabled = vndc_extensions;
-       GetData()->verbose = enable_v;
-       GetData()->rendering_mode = mode;
-       GetData()->fullscreen = fulls;
-
-       if(debug_enable) {
-               signal(SIGINT, DebugTrap);
-               GetData()->debug_mode = true;
-       }
-
-       if(width > 0 && height > 0) {
-               GetData()->physical_w = width;
-               GetData()->physical_h = height;
-       }
-
-       Setup();
-
-       if(!save_file) {
-               // Check if a default save exists at save.scr.
-               if(newgame == false) {
-                       FILE* t = fopen((char*)"save.scr", "r");
-                       if(t != NULL) {
-                               // File exists. first, close the descriptor.
-                               fclose(t);
-                               // Op_jump to it
-                               op_jump((char*)"save.scr", NULL, true);
-                       }
-                       else // Jump to main, there is no save.
-                               op_jump(GetData()->main_scr[0], NULL, true);
-               }
-               else // Otherwise just jump to the main screen.
-                       op_jump(GetData()->main_scr[0], NULL, true);
-       }
-       else // Jump to save file specified.
-               op_jump(save_file, NULL, true);
-
-       while(!(GetData()->ctx->GetQuit())) {
-               Loop();
-       }
-
-       delete GetData()->ctx;
-       delete GetData();
-
-       return 0;
+    printf(" ___________________________________________________________ \n");
+    printf("| VNDC - VNDC is Not a Direct Clone (of VNDS ;P)            |\n");
+    printf("| Interprets VNDS scripts with a few goodies and extensions |\n");
+    printf("| (C) Jonathan Feldman 2014 - Under the MIT license         |\n");
+    printf("| git: %s             |\n", GIT_REV);
+    printf("|___________________________________________________________|\n\n");
+
+    char* chdir_to_dir = NULL;
+    char* main_script_override = NULL;
+    char* save_file = NULL;
+    bool vndc_extensions = true;
+    int width = 0, height = 0;
+    bool debug_enable = false;
+    bool enable_v = false;
+    bool newgame = false;
+    char c;
+    #ifdef USE_ANDROID
+    int mode = 0;
+    bool fulls = true;
+    #else
+    int mode = 1;
+    bool fulls = false;
+    #endif
+
+    while((c = getopt(argc, argv, "fr:nbvx:y:d:m:s:ch")) != -1) {
+        switch(c) {
+            case 'f':
+                printf("[info] Starting in fullscreen mode.\n");
+                fulls = true;
+                break;
+            case 'r':
+                if(!strcmp(optarg, "sdlsw")) {
+                    printf("[info] Using SDL software backend.\n");
+                    mode = 0;
+                }
+                if(!strcmp(optarg, "sdlhw")) {
+                    printf("[info] Using SDL hardware backend.\n");
+                    mode = 1;
+                }
+                if(!strcmp(optarg, "gl")) {
+                    printf("[info] Using OpenGL backend. (note - experimental)\n");                    
+                    mode = 2;
+                }
+                break;
+            case 'n':
+                printf("[info] New game, not reloading save.\n");
+                newgame = true;
+                break;
+            case 'v':
+                printf("[info] Script commands will be echoed.\n");
+                enable_v = true;
+                break;
+            case 'b':
+                printf("[debug] Debug Mode enabled.\n");
+                debug_enable = true;
+                break;
+            case 'd':
+                printf("[info] Directory specified: %s\n", optarg);
+                chdir_to_dir = optarg;
+                break;
+            case 'x':
+                sscanf(optarg, "%d", &width);
+                break;
+            case 'y':
+                sscanf(optarg, "%d", &height);
+                chdir_to_dir = optarg;
+                break;
+            case 'm':
+                printf("[debug] Main script overriden as: '%s'\n", optarg);
+                main_script_override = optarg;
+                break;
+            case 's':
+                printf("[info] Load save: '%s'\n", optarg);
+                save_file = optarg;
+                break;
+            case 'c':
+                printf("[debug] Compliant mode: all VNDC extensions off\n");
+                vndc_extensions = false;
+                break;
+            case 'h':
+                printf("-x size -y size\tStretch display window to WxH\n");
+                printf("-r mode\t\tUse render mode (sdlsw, sdlhw, gl)\n");
+                printf("-f\t\tFullscreen mode.\n");
+                printf("-n\t\tNew Game. Do not reload default save.\n");
+                printf("-d dir\t\tChange to directory/Run game in directory\n");
+                printf("-b\t\tDebug Mode. Hit Ctrl+C on console for shell\n");
+                printf("-v\t\tVerbose. Echo script commands back as they execute\n");
+                printf("-m .scr\t\tLoad .scr as main script\n");
+                printf("-s .scr\t\tLoad save .scr instead of default\n");
+                printf("-c\t\tCompliant mode; don't use VNDC extensions\n");
+                printf("-h\t\tPrint this help message\n\n");
+                return 0;
+                break;
+            default:
+                break;
+        }
+    }
+
+    Data_PreInit();
+
+    GetData()->ctx = new ContextManager();
+
+    if(chdir_to_dir)
+        chdir(chdir_to_dir);
+    #ifdef WITH_ANDROID
+    chdir((char*)"/mnt/sdcard/vndc/");
+    #endif
+
+    if(main_script_override != NULL) {
+        printf("[debug] Note that in this mode, l_flags is not set.\n[debug] Expect bugs/gameover, this is normal.\n");
+        memset(GetData()->main_scr[0], 0, 399);
+        strncpy(GetData()->main_scr[0], main_script_override, 399);
+    }
+
+    GetData()->vndc_enabled = vndc_extensions;
+    GetData()->verbose = enable_v;
+    GetData()->rendering_mode = mode;
+    GetData()->fullscreen = fulls;
+
+    if(debug_enable) {
+        signal(SIGINT, DebugTrap);
+        GetData()->debug_mode = true;
+    }
+
+    if(width > 0 && height > 0) {
+        GetData()->physical_w = width;
+        GetData()->physical_h = height;
+    }
+
+    Setup();
+
+    if(!save_file) {
+        // Check if a default save exists at save.scr.
+        if(newgame == false) {
+            FILE* t = fopen((char*)"save.scr", "r");
+            if(t != NULL) {
+                // File exists. first, close the descriptor.
+                fclose(t);
+                // Op_jump to it
+                op_jump((char*)"save.scr", NULL, true);
+            }
+            else // Jump to main, there is no save.
+                op_jump(GetData()->main_scr[0], NULL, true);
+        }
+        else // Otherwise just jump to the main screen.
+            op_jump(GetData()->main_scr[0], NULL, true);
+    }
+    else // Jump to save file specified.
+        op_jump(save_file, NULL, true);
+
+    while(!(GetData()->ctx->GetQuit())) {
+        Loop();
+    }
+
+    delete GetData()->ctx;
+    delete GetData();
+
+    return 0;
 }
index 3f2c2311dc00dcaae047af96805881f0360c8f6c..3b1d0023489a5f74f2190c0c731b7fe614b1e434 100644 (file)
@@ -8,28 +8,28 @@
  */
 
 void op_bgload(char* file, int* fadetime) {
-       if (GetData()->if_fail != 0 || GetData()->ctx->GetQuit())
-               return;
+    if (GetData()->if_fail != 0 || GetData()->ctx->GetQuit())
+        return;
 
-       memset(GetData()->current_bg, 0, 400);
+    memset(GetData()->current_bg, 0, 400);
 
-       snprintf(GetData()->current_bg, 400, "background/%s", file);
+    snprintf(GetData()->current_bg, 400, "background/%s", file);
 
-       // Load displayable.
+    // Load displayable.
 
-       UDisplayable* disp = new UDisplayable(GetData()->ctx, GetData()->current_bg);
+    UDisplayable* disp = new UDisplayable(GetData()->ctx, GetData()->current_bg);
 
-       // SDL_Surface* sfc = IMG_Load(GetData()->current_bg);
+    // SDL_Surface* sfc = IMG_Load(GetData()->current_bg);
 
-       uint8_t transp_incr = 16;
-       if(fadetime != NULL)
-               transp_incr = 255 / *fadetime;
+    uint8_t transp_incr = 16;
+    if(fadetime != NULL)
+        transp_incr = 255 / *fadetime;
 
-       // FIXME - Implement proper fading out functionality.
+    // FIXME - Implement proper fading out functionality.
 
-       int delay = 1;
-       for(int tr = 0; tr < 255; tr += transp_incr) {          
-               disp->Blit();
-               op_delay(&delay);
-       }
+    int delay = 1;
+    for(int tr = 0; tr < 255; tr += transp_incr) {        
+        disp->Blit();
+        op_delay(&delay);
+    }
 }
index 08000bb50fa10a77e33b162e414c1450c07a5bd7..6631a64a7f133468c029f1fe44e19f8b97888ce6 100644 (file)
  */
 
 void op_choice(char* line) {
-       if (GetData()->if_fail != 0)
-               return;
-       // Strtok by the pipe '|' character
-
-       //printf("%s\n", line);
-
-       int num = 1;
-       char** tokens = (char**)realloc(NULL, sizeof(char*) * (1));
-       tokens[num-1] = strtok(line, "|");
-
-       do {
-               //printf("Loop: num = %d;\n", num);
-               ++num;
-               tokens = (char**)realloc(tokens, sizeof(char*) * (num));
-               tokens[num-1] = strtok(NULL, "|");
-       } while(tokens[num-1] != NULL);
-
-       --num;
-
-       /*for(int i=0; i<num; i++) {
-               printf("%s\n", tokens[i]);
-       }*/
-
-       // Scan thru the last token to see if a '>' is there.
-
-       char varname[400];
-       memset(varname, 0, 400);
-       int defaultname = 0;
-
-       if(GetData()->vndc_enabled) { // This is an extension.
-               for( int i = strlen(tokens[num-1]); i >= 0; i-- ) {
-                       if(tokens[num-1][i] == '>') {
-                               // Yes there is.
-                               defaultname = i + 1;
-                               tokens[num-1][i] = '\0';
-                               break;
-                       }
-               }
-       }
-
-       if(defaultname > 0) {
-               strncpy(varname, &tokens[num-1][defaultname], 400);
-       }
-       else {
-               strncpy(varname, "selected", 400);
-       }
-
-       op_cleartext();
-
-       // For each choice, we need to print text and make a click area. This will use the text function.
-       int *choices = (int*)calloc(sizeof(int), num * 2);
-
-       for(int i=0; i < num*2; i+=2) {
-               choices[i] = GetData()->text_y;
-               char* outarr = (char*)calloc(sizeof(char*), strlen(tokens[i/2])+3);
-               outarr[0] = '0' + (i/2);
-               outarr[1] = '.';
-               outarr[2] = ' ';
-               strncpy(&outarr[3], tokens[i/2], strlen(tokens[i/2]));
-               op_text(outarr);
-               free(outarr);
-               choices[i+1] = GetData()->text_y;
-       }
-
-       GetData()->choice_coords = choices;
-       GetData()->choices = num;
-
-       while(GetData()->choices > 0) {
-               if(GetData()->ctx->GetQuit()) goto killed;
-
-               GetData()->ctx->Flush();
-
-               GetData()->ctx->StartSync();
-                       GetData()->ctx->Input();
-               GetData()->ctx->EndSync();
-       }
-
-       // Get the chosen option and load it to a variable (abs of course)
-
-       GetData()->s_flags[0][std::string(varname)] = -(GetData()->choices);
-
-       // Clear after choices. Period.
-       op_cleartext();
+    if (GetData()->if_fail != 0)
+        return;
+    // Strtok by the pipe '|' character
+
+    //printf("%s\n", line);
+
+    int num = 1;
+    char** tokens = (char**)realloc(NULL, sizeof(char*) * (1));
+    tokens[num-1] = strtok(line, "|");
+
+    do {
+        //printf("Loop: num = %d;\n", num);
+        ++num;
+        tokens = (char**)realloc(tokens, sizeof(char*) * (num));
+        tokens[num-1] = strtok(NULL, "|");
+    } while(tokens[num-1] != NULL);
+
+    --num;
+
+    /*for(int i=0; i<num; i++) {
+        printf("%s\n", tokens[i]);
+    }*/
+
+    // Scan thru the last token to see if a '>' is there.
+
+    char varname[400];
+    memset(varname, 0, 400);
+    int defaultname = 0;
+
+    if(GetData()->vndc_enabled) { // This is an extension.
+        for( int i = strlen(tokens[num-1]); i >= 0; i-- ) {
+            if(tokens[num-1][i] == '>') {
+                // Yes there is.
+                defaultname = i + 1;
+                tokens[num-1][i] = '\0';
+                break;
+            }
+        }
+    }
+
+    if(defaultname > 0) {
+        strncpy(varname, &tokens[num-1][defaultname], 400);
+    }
+    else {
+        strncpy(varname, "selected", 400);
+    }
+
+    op_cleartext();
+
+    // For each choice, we need to print text and make a click area. This will use the text function.
+    int *choices = (int*)calloc(sizeof(int), num * 2);
+
+    for(int i=0; i < num*2; i+=2) {
+        choices[i] = GetData()->text_y;
+        char* outarr = (char*)calloc(sizeof(char*), strlen(tokens[i/2])+3);
+        outarr[0] = '0' + (i/2);
+        outarr[1] = '.';
+        outarr[2] = ' ';
+        strncpy(&outarr[3], tokens[i/2], strlen(tokens[i/2]));
+        op_text(outarr);
+        free(outarr);
+        choices[i+1] = GetData()->text_y;
+    }
+
+    GetData()->choice_coords = choices;
+    GetData()->choices = num;
+
+    while(GetData()->choices > 0) {
+        if(GetData()->ctx->GetQuit()) goto killed;
+
+        GetData()->ctx->Flush();
+
+        GetData()->ctx->StartSync();
+            GetData()->ctx->Input();
+        GetData()->ctx->EndSync();
+    }
+
+    // Get the chosen option and load it to a variable (abs of course)
+
+    GetData()->s_flags[0][std::string(varname)] = -(GetData()->choices);
+
+    // Clear after choices. Period.
+    op_cleartext();
 
 killed:
 
-       // Also reset the 'need to click' since we just did.
-       GetData()->wait_input = false;
+    // Also reset the 'need to click' since we just did.
+    GetData()->wait_input = false;
 }
index 1763ceb15d32662bb3ea5791b254fb87bb75d3f9..ee100142c19217188d623567b27c0fe9cbf76f35 100644 (file)
@@ -9,13 +9,13 @@
  */
 
 void op_cleartext() {
-       if (GetData()->if_fail != 0 || GetData()->ctx->GetQuit())
-               return;
+    if (GetData()->if_fail != 0 || GetData()->ctx->GetQuit())
+        return;
 
-       GetData()->text_x = GetData()->render_x1;
-       GetData()->text_y = GetData()->render_y1;
-       GetData()->ctx->ClearOverlay();
+    GetData()->text_x = GetData()->render_x1;
+    GetData()->text_y = GetData()->render_y1;
+    GetData()->ctx->ClearOverlay();
 
-       // Dim transparent overlay
-       GetData()->text_box_base->Blit();
+    // Dim transparent overlay
+    GetData()->text_box_base->Blit();
 }
index c96b622459fc3db80b7835696742905b7f11a444..c36030d86f8d1ff1061063e15d4d7785fb67cc70 100644 (file)
@@ -8,11 +8,11 @@
  */
 
 void op_delay(int* frames) {
-       if (GetData()->if_fail != 0 || GetData()->ctx->GetQuit())
-               return;
-       for(int i = 0; i < *frames; i++) {
-               // This is one frame.
-               GetData()->ctx->StartSync();
-               GetData()->ctx->EndSync();
-       }
+    if (GetData()->if_fail != 0 || GetData()->ctx->GetQuit())
+        return;
+    for(int i = 0; i < *frames; i++) {
+        // This is one frame.
+        GetData()->ctx->StartSync();
+        GetData()->ctx->EndSync();
+    }
 }
index 181602581a4c087b9d73c903b6554e44b2838a4c..be7727d1344ba14393e1f8f2354be78e4f476aac 100644 (file)
@@ -8,6 +8,6 @@
  */
 
 void op_fi() {
-       if(GetData()->if_fail != 0)
-               GetData()->if_fail -= 1;
+    if(GetData()->if_fail != 0)
+        GetData()->if_fail -= 1;
 }
index f3b5e076247ececdadd884f0a6fdf7877a1daa47..a2a7ac459e729a2a1cb9872529ce16e1211058c8 100644 (file)
@@ -8,43 +8,43 @@
  */
 
 void op_goto(char* label) {
-       if (GetData()->if_fail != 0 || GetData()->ctx->GetQuit())
-               return;
-       FILE** infile = &(GetData()->accessScriptHandle);
+    if (GetData()->if_fail != 0 || GetData()->ctx->GetQuit())
+        return;
+    FILE** infile = &(GetData()->accessScriptHandle);
 
-       rewind(*infile);
+    rewind(*infile);
 
-       char *line = (char*)calloc(sizeof(char), 400);
+    char *line = (char*)calloc(sizeof(char), 400);
 
-       int line_to = 0;
+    int line_to = 0;
 
-       bool found = false;
-       while(!found) {
-               line_to++;
-               fgets(line, 400, *infile);
+    bool found = false;
+    while(!found) {
+        line_to++;
+        fgets(line, 400, *infile);
 
-               // Remove all '\n' from this string
-               for(int i=0; i < 400; i++) {
-                       if (line[i] == '\n')
-                               line[i] = '\0';
-               }
+        // Remove all '\n' from this string
+        for(int i=0; i < 400; i++) {
+            if (line[i] == '\n')
+                line[i] = '\0';
+        }
 
-               int num = 1;
-               char** tokens = (char**)realloc(NULL, sizeof(char*) * (1));
-               tokens[num-1] = strtok(line, " ");
+        int num = 1;
+        char** tokens = (char**)realloc(NULL, sizeof(char*) * (1));
+        tokens[num-1] = strtok(line, " ");
 
-               do {
-                       //printf("Loop: num = %d;\n", num);
-                       ++num;
-                       tokens = (char**)realloc(tokens, sizeof(char*) * (num));
-                       tokens[num-1] = strtok(NULL, " ");
-               } while(tokens[num-1] != NULL);
+        do {
+            //printf("Loop: num = %d;\n", num);
+            ++num;
+            tokens = (char**)realloc(tokens, sizeof(char*) * (num));
+            tokens[num-1] = strtok(NULL, " ");
+        } while(tokens[num-1] != NULL);
 
-               --num;
+        --num;
 
-               if(!strcmp(tokens[0], "label"))
-                       if(!strcmp(tokens[1], label))
-                               found = true;
-       }
-       GetData()->currentLine = line_to;
+        if(!strcmp(tokens[0], "label"))
+            if(!strcmp(tokens[1], label))
+                found = true;
+    }
+    GetData()->currentLine = line_to;
 }
index f128b021b171c1bf55aa0405d255462f25269f0f..98dbbb76c1d96d0efca8cb585cb07896a05d1d55 100644 (file)
@@ -21,8 +21,8 @@
  */
 
 void op_gsetvar(char* var, int *modifier, char *value) {
-       if (GetData()->if_fail != 0)
-               return;
+    if (GetData()->if_fail != 0)
+        return;
 
-       op_setvar(var, modifier, value);
+    op_setvar(var, modifier, value);
 }
index 1bca33f57da1092c9a49735c11a317def0b0381e..b78f0d040ce6101f280a9c387953822ea35a2a87 100644 (file)
  */
 
 void op_if(char* left, int* op, char* right) {
-       if (GetData()->if_fail != 0) {
-               GetData()->if_fail += 1;
-               return;
-       }
-
-       int r_val = 0, ret = 0;
-       
-       ret = sscanf(right, "%d", &r_val);
-
-       if(ret == 0 && GetData()->vndc_enabled) { // This is a var name. We couldn't scan a number.
-               r_val = GetData()->s_flags[0][std::string(right)];
-       }
-
-       int l_val = GetData()->s_flags[0][std::string(left)];
-
-       //printf("op_if(%s, %d, %d)\n", var, op[0], val[0]);
-       //printf("GetData()->s_flags[0][%s] = %d\n", var, GetData()->s_flags[0][std::string(var)]);
-
-       switch (op[0]) {
-               case 0:
-                       if ( !(l_val <= r_val) )
-                               GetData()->if_fail += 1;
-                       break;
-               case 1:
-                       if ( !(l_val < r_val) )
-                               GetData()->if_fail += 1;
-                       break;
-               case 2:
-                       if ( !(l_val == r_val) )
-                               GetData()->if_fail += 1;
-                       break;
-               case 3:
-                       if ( !(l_val != r_val) )
-                               GetData()->if_fail += 1;
-                       break;
-               case 4:
-                       if ( !(l_val > r_val) )
-                               GetData()->if_fail += 1;
-                       break;
-               case 5:
-                       if ( !(l_val >= r_val) )
-                               GetData()->if_fail += 1;
-                       break;
-       }
+    if (GetData()->if_fail != 0) {
+        GetData()->if_fail += 1;
+        return;
+    }
+
+    int r_val = 0, ret = 0;
+    
+    ret = sscanf(right, "%d", &r_val);
+
+    if(ret == 0 && GetData()->vndc_enabled) { // This is a var name. We couldn't scan a number.
+        r_val = GetData()->s_flags[0][std::string(right)];
+    }
+
+    int l_val = GetData()->s_flags[0][std::string(left)];
+
+    //printf("op_if(%s, %d, %d)\n", var, op[0], val[0]);
+    //printf("GetData()->s_flags[0][%s] = %d\n", var, GetData()->s_flags[0][std::string(var)]);
+
+    switch (op[0]) {
+        case 0:
+            if ( !(l_val <= r_val) )
+                GetData()->if_fail += 1;
+            break;
+        case 1:
+            if ( !(l_val < r_val) )
+                GetData()->if_fail += 1;
+            break;
+        case 2:
+            if ( !(l_val == r_val) )
+                GetData()->if_fail += 1;
+            break;
+        case 3:
+            if ( !(l_val != r_val) )
+                GetData()->if_fail += 1;
+            break;
+        case 4:
+            if ( !(l_val > r_val) )
+                GetData()->if_fail += 1;
+            break;
+        case 5:
+            if ( !(l_val >= r_val) )
+                GetData()->if_fail += 1;
+            break;
+    }
 }
index 7650ab80b98e21d8d9cc5c5e094d021455e3e285..566176ed6dd0ec3d26180274df3c3cb251b6e230 100644 (file)
@@ -8,46 +8,46 @@
  */
 
 void op_jump(char* file, int* lineTo, bool isSave) {
-       if (GetData()->if_fail != 0)
-               return;
-
-       memset(GetData()->current_scr, 0, 400);
-       if(!isSave)
-               snprintf(GetData()->current_scr, 400, "script/%s", file);
-       else
-               snprintf(GetData()->current_scr, 400, "%s", file);
-
-       if(GetData()->debug_mode) {
-               memset(&GetData()->window_name[16], 0, sizeof(char)*400);
-               snprintf(&GetData()->window_name[16], 400-16-3, " (%s)", file);
-               GetData()->ctx->SetTitle(GetData()->window_name);
-       }
-
-       if(GetData()->accessScriptHandle != NULL)
-               fclose(GetData()->accessScriptHandle);
-
-       GetData()->accessScriptHandle = fopen(GetData()->current_scr, "r");
-       if(GetData()->accessScriptHandle == NULL) {
-               printf("[error] Failed to open script file %s.\n", GetData()->current_scr);
-               exit(-1);
-       }
-
-
-       if(lineTo != NULL) {
-               GetData()->currentLine = lineTo[0];
-               char *line = (char*)calloc(sizeof(char), 400);
-
-               while(--lineTo[0] > 0) {
-                       fgets(line, 400, GetData()->accessScriptHandle);
-               }
-       }
-       else {
-               GetData()->currentLine = 0;
-       }
-
-       // Read the first line into next_line.
-       GetData()->next_line = (char*)calloc(sizeof(char), 400);
-       // Load the next line.
-       fgets(GetData()->next_line, 400, GetData()->accessScriptHandle);
+    if (GetData()->if_fail != 0)
+        return;
+
+    memset(GetData()->current_scr, 0, 400);
+    if(!isSave)
+        snprintf(GetData()->current_scr, 400, "script/%s", file);
+    else
+        snprintf(GetData()->current_scr, 400, "%s", file);
+
+    if(GetData()->debug_mode) {
+        memset(&GetData()->window_name[16], 0, sizeof(char)*400);
+        snprintf(&GetData()->window_name[16], 400-16-3, " (%s)", file);
+        GetData()->ctx->SetTitle(GetData()->window_name);
+    }
+
+    if(GetData()->accessScriptHandle != NULL)
+        fclose(GetData()->accessScriptHandle);
+
+    GetData()->accessScriptHandle = fopen(GetData()->current_scr, "r");
+    if(GetData()->accessScriptHandle == NULL) {
+        printf("[error] Failed to open script file %s.\n", GetData()->current_scr);
+        exit(-1);
+    }
+
+
+    if(lineTo != NULL) {
+        GetData()->currentLine = lineTo[0];
+        char *line = (char*)calloc(sizeof(char), 400);
+
+        while(--lineTo[0] > 0) {
+            fgets(line, 400, GetData()->accessScriptHandle);
+        }
+    }
+    else {
+        GetData()->currentLine = 0;
+    }
+
+    // Read the first line into next_line.
+    GetData()->next_line = (char*)calloc(sizeof(char), 400);
+    // Load the next line.
+    fgets(GetData()->next_line, 400, GetData()->accessScriptHandle);
 
 }
index 6be012e39c4015e5368d0d04d11ce4e6065aa22a..a94396fc9a1c415ed92ab0564c345200cf9de01e 100644 (file)
@@ -8,23 +8,23 @@
  */
 
 void op_music(char* file) {
-       if (GetData()->if_fail != 0 || GetData()->ctx->GetQuit())
-               return;
+    if (GetData()->if_fail != 0 || GetData()->ctx->GetQuit())
+        return;
 
-       memset(GetData()->current_music, 0, 400);
+    memset(GetData()->current_music, 0, 400);
 
-       snprintf(GetData()->current_music, 400, "sound/%s", file);
+    snprintf(GetData()->current_music, 400, "sound/%s", file);
 
-       // Halt command
-       if (!strcmp(file, "~")) {
-               GetData()->ctx->Audio()->FlushMusic();
-       }
-       // Play command
-       else {
-               GetData()->ctx->Audio()->FlushMusic();
+    // Halt command
+    if (!strcmp(file, "~")) {
+        GetData()->ctx->Audio()->FlushMusic();
+    }
+    // Play command
+    else {
+        GetData()->ctx->Audio()->FlushMusic();
 
-               int index = GetData()->ctx->Audio()->LoadMusic(GetData()->current_music);
+        int index = GetData()->ctx->Audio()->LoadMusic(GetData()->current_music);
 
-               GetData()->ctx->Audio()->PlayMusicLoop(index);
-       }
+        GetData()->ctx->Audio()->PlayMusicLoop(index);
+    }
 }
index 5895ba98e8dad2828f09ed326db87c7b1e7f1922..eb355e873438f54ddf78e98708017c53cbb9b601 100644 (file)
 bool seeded = false;
 
 void op_random(char* var, int* low, int* high) {
-       if (GetData()->if_fail != 0)
-               return;
-       if (seeded == false)
-               srand(time(NULL));
+    if (GetData()->if_fail != 0)
+        return;
+    if (seeded == false)
+        srand(time(NULL));
 
-       int num = *low + ( rand() % ( *high - *low ) );
+    int num = *low + ( rand() % ( *high - *low ) );
 
-       GetData()->s_flags[0][std::string(var)] = num;
+    GetData()->s_flags[0][std::string(var)] = num;
 }
index cda54e9ea7209781098ed33d009c60395aae203a..c7426002b85c975a2e011588b8865ef5dfe563f8 100644 (file)
@@ -6,7 +6,7 @@
 #include "Funcs.hpp"
 
 void op_save(char* name) {
-       DumpSave(name); // Just a wrapper. No harm done.
-                       // TODO - Replace all dumpsave calls with this and move function here
+    DumpSave(name); // Just a wrapper. No harm done.
+            // TODO - Replace all dumpsave calls with this and move function here
 }
 
index d1e66ebf5c65b2525e501bebfb257d45f9cbc2f2..8d9922800c303d8c99fe249f48687d0a38e16cc1 100644 (file)
@@ -8,29 +8,29 @@
  */
 
 void op_setimg(char* file, int* x, int* y) {
-       if (GetData()->if_fail != 0 || GetData()->ctx->GetQuit())
-               return;
+    if (GetData()->if_fail != 0 || GetData()->ctx->GetQuit())
+        return;
 
-       // Fadeout not implemented yet.
+    // Fadeout not implemented yet.
 
-       char path[400];
-       memset(path, 0, 400);
+    char path[400];
+    memset(path, 0, 400);
 
-       snprintf(path, 400, "foreground/%s", file);
+    snprintf(path, 400, "foreground/%s", file);
 
-       // Load displayable.
-       UDisplayable* fg_add = new UDisplayable(GetData()->ctx, Normal, path);
+    // Load displayable.
+    UDisplayable* fg_add = new UDisplayable(GetData()->ctx, Normal, path);
 
-       // Centered NDS adapted
-       double adp_x = ((double)x[0]) * (GetData()->screen_w / 256);
-       double adp_y = ((double)y[0]) * (GetData()->screen_h / 192);
-       fg_add->SetXY((int)adp_x, (int)adp_y);
+    // Centered NDS adapted
+    double adp_x = ((double)x[0]) * (GetData()->screen_w / 256);
+    double adp_y = ((double)y[0]) * (GetData()->screen_h / 192);
+    fg_add->SetXY((int)adp_x, (int)adp_y);
 
-       // Raw
-       // fg_add->SetXY(x[0], y[0]);
+    // Raw
+    // fg_add->SetXY(x[0], y[0]);
 
-       fg_add->Blit();
+    fg_add->Blit();
 
-       // Delete fg_new. We're done with it.
-       delete fg_add;
+    // Delete fg_new. We're done with it.
+    delete fg_add;
 }
index ab229bd07a0a6339f65339ec74ce1b7607e80092..bfd0d72caaf8b566cf62488348948514c86c8520 100644 (file)
  */
 
 void op_setvar(char* var, int* modifier, char* value) {
-       if (GetData()->if_fail != 0)
-               return;
+    if (GetData()->if_fail != 0)
+        return;
 
-       int value_r = 0, ret;
-       if(value == NULL)
-               ret = 0;
-       else
-               ret = sscanf(value, "%d", &value_r);
+    int value_r = 0, ret;
+    if(value == NULL)
+        ret = 0;
+    else
+        ret = sscanf(value, "%d", &value_r);
 
-       if(ret == 0 && GetData()->vndc_enabled) { // value is a variable not a number
-               if(*modifier == 0) {
-                       GetData()->s_flags[0][std::string(var)] = GetData()->s_flags[0][std::string(value)];
-               }
-               else if (*modifier == -1) {
-                       GetData()->s_flags[0][std::string(var)] -= GetData()->s_flags[0][std::string(value)];
-               }
-               else if (*modifier == 1) {
-                       GetData()->s_flags[0][std::string(var)] += GetData()->s_flags[0][std::string(value)];
-               }
-       }
-       else {
-               if(*modifier == 0) {
-                       GetData()->s_flags[0][std::string(var)] = value_r;
-               }
-               else if (*modifier == -1) {
-                       GetData()->s_flags[0][std::string(var)] -= value_r;
-               }
-               else if (*modifier == 1) {
-                       GetData()->s_flags[0][std::string(var)] += value_r;
-               }
-               else if (*modifier == -2) {
-                       // There's a rare case on program start where a resetall
-                       // happens.
+    if(ret == 0 && GetData()->vndc_enabled) { // value is a variable not a number
+        if(*modifier == 0) {
+            GetData()->s_flags[0][std::string(var)] = GetData()->s_flags[0][std::string(value)];
+        }
+        else if (*modifier == -1) {
+            GetData()->s_flags[0][std::string(var)] -= GetData()->s_flags[0][std::string(value)];
+        }
+        else if (*modifier == 1) {
+            GetData()->s_flags[0][std::string(var)] += GetData()->s_flags[0][std::string(value)];
+        }
+    }
+    else {
+        if(*modifier == 0) {
+            GetData()->s_flags[0][std::string(var)] = value_r;
+        }
+        else if (*modifier == -1) {
+            GetData()->s_flags[0][std::string(var)] -= value_r;
+        }
+        else if (*modifier == 1) {
+            GetData()->s_flags[0][std::string(var)] += value_r;
+        }
+        else if (*modifier == -2) {
+            // There's a rare case on program start where a resetall
+            // happens.
 
-                       if(!strcmp(var, "~")) {
-                               // We'll handle it by searching through and deleting all non-G values.
-                               // g values are global, so they by definition survive this.
-       
-                               if(!GetData()->s_flags[0].empty()) {
-                                       std::map<std::string, int>::iterator item = GetData()->s_flags[0].begin();
-                                       while(item != GetData()->s_flags[0].end()) {
-                                               if(item->first.c_str()[0] != 'g')
-                                                       GetData()->s_flags[0].erase(item++);
-                                               else
-                                                       item++;
-                                       }
-                               }
-                               return;
-                       }
+            if(!strcmp(var, "~")) {
+                // We'll handle it by searching through and deleting all non-G values.
+                // g values are global, so they by definition survive this.
+    
+                if(!GetData()->s_flags[0].empty()) {
+                    std::map<std::string, int>::iterator item = GetData()->s_flags[0].begin();
+                    while(item != GetData()->s_flags[0].end()) {
+                        if(item->first.c_str()[0] != 'g')
+                            GetData()->s_flags[0].erase(item++);
+                        else
+                            item++;
+                    }
+                }
+                return;
+            }
 
-                       GetData()->s_flags[0][std::string(var)] = 0;
-               }
-       }
+            GetData()->s_flags[0][std::string(var)] = 0;
+        }
+    }
 }
index 542ed4961281826600e3ff3c94819dffdd07b472..dcd09fc8c8859d9886788cdc8c6e326d2243faea 100644 (file)
@@ -8,57 +8,57 @@
  */
 
 void op_sound(char* file, int* times) {
-       if (GetData()->if_fail != 0 || GetData()->ctx->GetQuit())
-               return;
+    if (GetData()->if_fail != 0 || GetData()->ctx->GetQuit())
+        return;
 
-       // Fadeout not implemented yet.
+    // Fadeout not implemented yet.
 
-       // Halt command
-       if (!strcmp(file, "~")) {
-               GetData()->ctx->Audio()->FlushSfx();
-               return;
-       }
-       // Extension - Voiced auto-stop. If the next line contains quotes,
-       // it is voiced. We set a flag in response. If the flag is already
-       // set - e.g. the sound was a voice as well, we stop the previous
-       // sound before playing this one.
+    // Halt command
+    if (!strcmp(file, "~")) {
+        GetData()->ctx->Audio()->FlushSfx();
+        return;
+    }
+    // Extension - Voiced auto-stop. If the next line contains quotes,
+    // it is voiced. We set a flag in response. If the flag is already
+    // set - e.g. the sound was a voice as well, we stop the previous
+    // sound before playing this one.
 
-       if(GetData()->vndc_enabled &&         // 0 1 2 3 4 5
-          (GetData()->next_line[5] == '"' || // t e x t   "
-           GetData()->next_line[strlen(GetData()->next_line) - 1] == '"' ||
-               GetData()->quote_incomplete)) {
-               GetData()->ctx->Audio()->FlushSfx();
+    if(GetData()->vndc_enabled &&         // 0 1 2 3 4 5
+       (GetData()->next_line[5] == '"' || // t e x t   "
+        GetData()->next_line[strlen(GetData()->next_line) - 1] == '"' ||
+        GetData()->quote_incomplete)) {
+        GetData()->ctx->Audio()->FlushSfx();
 
-               if(GetData()->next_line[5] == '"' &&
-                  !(GetData()->next_line[strlen(GetData()->next_line) - 1] == '"')) {
-                       // Quote is incomplete.
-                       GetData()->quote_incomplete = true;
-               }
+        if(GetData()->next_line[5] == '"' &&
+           !(GetData()->next_line[strlen(GetData()->next_line) - 1] == '"')) {
+            // Quote is incomplete.
+            GetData()->quote_incomplete = true;
+        }
 
-               if(GetData()->next_line[strlen(GetData()->next_line) - 1] == '"' &&
-                  !(GetData()->next_line[5] == '"')) {
-                       GetData()->quote_incomplete = false;
-               }
+        if(GetData()->next_line[strlen(GetData()->next_line) - 1] == '"' &&
+           !(GetData()->next_line[5] == '"')) {
+            GetData()->quote_incomplete = false;
+        }
 
-       }
+    }
 
-       // Play command
-       int count = 1;
-       if (times != NULL)
-               count = *times;
+    // Play command
+    int count = 1;
+    if (times != NULL)
+        count = *times;
 
-       char path[400];
-       memset(path, 0, 400);
+    char path[400];
+    memset(path, 0, 400);
 
-       snprintf(path, 400, "sound/%s", file);
+    snprintf(path, 400, "sound/%s", file);
 
-       // Load sfx.
-       int sfxi = GetData()->ctx->Audio()->LoadSfx(path);
+    // Load sfx.
+    int sfxi = GetData()->ctx->Audio()->LoadSfx(path);
 
-       if (count == -1) {
-               GetData()->ctx->Audio()->PlaySfx(sfxi, count);
-       }
-       else {
-               GetData()->ctx->Audio()->PlaySfx(sfxi, count-1);
-       }
+    if (count == -1) {
+        GetData()->ctx->Audio()->PlaySfx(sfxi, count);
+    }
+    else {
+        GetData()->ctx->Audio()->PlaySfx(sfxi, count-1);
+    }
 }
index d8892711fe3510eae10ffd0f1a67650f47b1dcb0..1385ae501d77442b93ea2016ab7c7d286ffc1093 100644 (file)
@@ -8,80 +8,80 @@
  */
 
 void op_text(char* string) {
-       if (GetData()->if_fail != 0 || GetData()->ctx->GetQuit())
-               return;
-
-       // Linebreak on zero-length, and render size exceed.
-       if (GetData()->text_y > (GetData()->render_y2) || strlen(string) < 1)
-               op_cleartext();
-
-       if(strlen(string) < 1)
-               return;
-
-       // Improvised linebreak. Also, an extension.
-       if(GetData()->vndc_enabled && string[1] == '-' && string[2] == '-' && string[3] == '-') {
-               op_cleartext();
-       }
-       // Improvised Tag display. Extension.
-       if(GetData()->vndc_enabled && string[0] == '<' && string[strlen(string)-1] == '>') {
-               string[strlen(string)-1] = '\0';
-               string = &string[1];
-               
-               GetData()->ctx->ClearOverlay();
-
-               TextManager* txt = GetData()->ctx->Text();
-
-               int xloc = ( GetData()->screen_w - (txt->TestLen(string) + GetData()->render_x1) );
-               
-               txt->Render(string, xloc, GetData()->render_y1);
-
-               GetData()->wait_input = true;
-               Wait();
-
-               op_cleartext();
-
-               return;
-       }
-       // Wait for input, then blank
-       if(!strcmp(string, "!")) {
-               GetData()->wait_input = true;
-               Wait();
-               op_cleartext();
-       }
-       // Blank screen
-       else if(!strcmp(string, "~")) {
-               op_cleartext();
-       }
-       // Output
-       else {
-               bool noclick = false;
-               // No click required
-               if(string[0] == '@') {
-                       noclick = true;
-                       string = &string[1];
-               }
-
-
-               TextManager* txt = GetData()->ctx->Text();
-
-               int lines = 0;
-               char** ptrs = NULL;
-
-               txt->SplitStringByWidth(string, GetData()->render_x2 - GetData()->render_x1, &lines, &ptrs);
-
-               if( ( lines * GetData()->text_gap + GetData()->text_y ) > GetData()->render_y2 )
-                       op_cleartext();
-
-               for(int i=0; i < lines; i++) {
-                       //printf("[br] %s\n", ptrs[i]);
-                       txt->Render(ptrs[i], GetData()->text_x, GetData()->text_y);
-                       GetData()->text_y += GetData()->text_gap;
-               }
-
-               free(ptrs);
-
-               if(!noclick) {
-                       GetData()->wait_input = true;
-               }
-       }
+    if (GetData()->if_fail != 0 || GetData()->ctx->GetQuit())
+        return;
+
+    // Linebreak on zero-length, and render size exceed.
+    if (GetData()->text_y > (GetData()->render_y2) || strlen(string) < 1)
+        op_cleartext();
+
+    if(strlen(string) < 1)
+        return;
+
+    // Improvised linebreak. Also, an extension.
+    if(GetData()->vndc_enabled && string[1] == '-' && string[2] == '-' && string[3] == '-') {
+        op_cleartext();
+    }
+    // Improvised Tag display. Extension.
+    if(GetData()->vndc_enabled && string[0] == '<' && string[strlen(string)-1] == '>') {
+        string[strlen(string)-1] = '\0';
+        string = &string[1];
+        
+        GetData()->ctx->ClearOverlay();
+
+        TextManager* txt = GetData()->ctx->Text();
+
+        int xloc = ( GetData()->screen_w - (txt->TestLen(string) + GetData()->render_x1) );
+        
+        txt->Render(string, xloc, GetData()->render_y1);
+
+        GetData()->wait_input = true;
+        Wait();
+
+        op_cleartext();
+
+        return;
+    }
+    // Wait for input, then blank
+    if(!strcmp(string, "!")) {
+        GetData()->wait_input = true;
+        Wait();
+        op_cleartext();
+    }
+    // Blank screen
+    else if(!strcmp(string, "~")) {
+        op_cleartext();
+    }
+    // Output
+    else {
+        bool noclick = false;
+        // No click required
+        if(string[0] == '@') {
+            noclick = true;
+            string = &string[1];
+        }
+
+
+        TextManager* txt = GetData()->ctx->Text();
+
+        int lines = 0;
+        char** ptrs = NULL;
+
+        txt->SplitStringByWidth(string, GetData()->render_x2 - GetData()->render_x1, &lines, &ptrs);
+
+        if( ( lines * GetData()->text_gap + GetData()->text_y ) > GetData()->render_y2 )
+            op_cleartext();
+
+        for(int i=0; i < lines; i++) {
+            //printf("[br] %s\n", ptrs[i]);
+            txt->Render(ptrs[i], GetData()->text_x, GetData()->text_y);
+            GetData()->text_y += GetData()->text_gap;
+        }
+
+        free(ptrs);
+
+        if(!noclick) {
+            GetData()->wait_input = true;
+        }
+    }
 }