Skip to content

Commit

Permalink
Merge branch 'apollo' of github.com:adam000/xsera
Browse files Browse the repository at this point in the history
  • Loading branch information
adam000 committed Dec 31, 2010
2 parents 1f5a5a4 + 191fed5 commit 3e5d64c
Show file tree
Hide file tree
Showing 11 changed files with 227 additions and 44 deletions.
11 changes: 10 additions & 1 deletion Engine/Apollo.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#ifdef WIN32
#define assert(x) { if (! ( x ) ) { printf("Assertion failure: %s\n\tFile: %s\n\tLine: %d\n", # x , __FILE__, __LINE__ ); abort(); } }
#undef SendMessage
#undef GetMessage //apparently, these are windows directives
#undef GetMessage //apparently, these are Windows directives
#endif
#include <SDL/SDL.h>

Expand Down Expand Up @@ -36,3 +36,12 @@ extern void Shutdown ();
}

#endif

/**
* @mainpage
* Contained within is the documentation for Apollo, the engine for Xsera.\n\n
* We will try to keep this documentation as up-to-date as possible, but this is
* no easy task. If you can make an improvement to the documentation, please
* contact us through the official Xsera repository at
* http://github.com/xsera/xsera
*/
31 changes: 30 additions & 1 deletion Engine/Graphics/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <cmath>
#else
#include <OpenGL/gl.h>
#include <SDL_ttf/SDL_ttf.h>
#endif
#include <SDL/SDL.h>
#include "RNG.h"
Expand Down Expand Up @@ -478,7 +479,24 @@ void DrawSpriteTile ( const std::string& sheetname, int sheet_x, int sheet_y, ve
}
}*/

void DrawTextSDL ( const std::string& text, const std::string& font, const char* justify, vec2 position, float height, colour col, float rotation )
const int MAX_TEXTURE_SIZE = 4096;

// splits regardless of words
int imperfectSplit ( vec2 dims, std::string* bob, int maxSize )
{
// bob needs to be a std::vector of std::strings, so that I can add however many strings to it
// yet to be figured out
return 1;
}

// splits along spaces, dropping the spaces
int idealSplit ( vec2 dims, std::string* bob, int maxSize )
{
// has yet to be figured out either
return 1;
}

void DrawTextSDL ( const std::string& text, const std::string& font, const char* justify, vec2 position, int height, colour col, float rotation )
{
SetShader("Text");
EnableTexturing();
Expand All @@ -489,6 +507,17 @@ void DrawTextSDL ( const std::string& text, const std::string& font, const char*
Matrices::SetModelMatrix(matrix2x3::Rotation(rotation));
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texID);
vec2 dims = TextRenderer::TextDimensions(font, text, height);

// TEMP
int xcoord = 0;
int ycoord = 0;
TTF_Font* fontObject = TextRenderer::GetFont(font, height);
if (TTF_SizeUTF8(fontObject, text.c_str(), &xcoord, &ycoord) == 0 && text == "This is as long as a message can be at font 20: not long..")
{
printf("The text '%s' has dimensions of %d by %d, and a height of %d\n", text.c_str(), xcoord, ycoord, height);
}
// END TEMP

GLfloat textureArray[] = { 0.0f, 0.0f, dims.X(), 0.0f, dims.X(), dims.Y(), 0.0f, dims.Y() };
vec2 halfSize;
if (strcmp(justify, "left") == 0)
Expand Down
18 changes: 11 additions & 7 deletions Engine/Graphics/Graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ vec2 SpriteDimensions ( const std::string& sheetname );
/**
* Draws a sprite.
* @note For rotational sprites, pass 0 for sheet_x and sheet_y
* @note This may be used to draw images, using a '+' before the name of the sprite sheet
* @note This may be used to draw images, using a '+' before the name of the
* sprite sheet
* @param sheetname The sprite sheet to use
* @param sheet_x The x position on the sprite sheet
* @param sheet_y The y position on the sprite sheet
Expand Down Expand Up @@ -64,13 +65,14 @@ inline void DrawImage ( const std::string& imageName, vec2 position, vec2 size )
* Draws a string of text
* @param text The text to draw
* @param font The font to use
* @param justify The justification of the text (should be "left", "right", or "center")
* @param justify The justification of the text (should be "left", "right", or
* "center")
* @param position The position of the centre of the text on-screen
* @param height The height of the text
* @param col The colour of the text
* @param rotation The rotation of the text
*/
void DrawTextSDL ( const std::string& text, const std::string& font, const char* justify, vec2 position, float height, colour col, float rotation );
void DrawTextSDL ( const std::string& text, const std::string& font, const char* justify, vec2 position, int height, colour col, float rotation );
/**
* Draws a line
* @param coordinate1 Beginning coordinates of the line
Expand All @@ -86,8 +88,8 @@ void DrawLine ( vec2 coordinate1, vec2 coordinate2, float width, colour col );
* @param width The width of the lightning, in pixels
* @param chaos The chaos of the lightning
* @param col The colour of the lightning
* @param tailed If tailed is true, the lightning tapers down to the endpoint. If
* tailed is false, the lightning does not taper down to the endpoint but
* @param tailed If tailed is true, the lightning tapers down to the endpoint.
* If tailed is false, the lightning does not taper down to the endpoint but
* instead ends somewhere around the endpoint.
*/
void DrawLightning ( vec2 coordinate1, vec2 coordinate2, float width, float chaos, colour col, bool tailed );
Expand Down Expand Up @@ -147,7 +149,8 @@ void ClearParticles ();
* @param velocity The average of the particle system
* @param velocityVariance The variation in the velocity of the particles
* @param acceleration The acceleration of the particles
* @param sizeFactor The factor of the original size that particles will grow to over their lifetime
* @param sizeFactor The factor of the original size that particles will grow to
* over their lifetime
* @param lifetime The lifetime of the particles
*/
void AddParticles ( const std::string& name, unsigned long particleCount, vec2 centre, vec2 velocity, vec2 velocityVariance, vec2 acceleration, float sizeFactor, float lifetime );
Expand Down Expand Up @@ -198,7 +201,8 @@ void DrawObject3DGlow ( std::string name, vec2 centre, float glow, float scale,
*/
float AspectRatio ();
/**
* Maps a point in window coordinates to a corresponding point in the current camera
* Maps a point in window coordinates to a corresponding point in the current
* camera
* @param windowCoords The point to be mapped
* @return The point in the camera
*/
Expand Down
39 changes: 36 additions & 3 deletions Engine/Graphics/TextRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ TextEntry* GetEntry ( const std::string& font, const std::string& text, float si
newEntry->texID = 0;
newEntry->surface = NULL;
newEntry->lastUse = 0.0f;
TTF_Font* fontObject = GetFont(font, size);
TTF_Font* fontObject = Graphics::TextRenderer::GetFont(font, size);
const SDL_Color fg = { 0xFF, 0xFF, 0xFF, 0xFF };
newEntry->surface = TTF_RenderUTF8_Blended(fontObject, text.c_str(), fg);
assert(newEntry->surface);
Expand All @@ -135,7 +135,40 @@ namespace Graphics
namespace TextRenderer
{

vec2 TextDimensions ( const std::string& font, const std::string& text, float size )
TTF_Font* GetFont ( const std::string& name, int size )
{
if (!ttf_initted)
{
TTF_Init();
ttf_initted = true;
}
std::map<std::string, TTF_Font*>::iterator iter = fonts.find(name);
if (iter != fonts.end())
{
return iter->second;
}
SDL_RWops* rwops = ResourceManager::OpenFile("Fonts/" + name + ".ttf");
TTF_Font* loadedFont;
if (rwops)
{
if (loadedFont = TTF_OpenFontRW(rwops, 1, size))
{
fonts[name] = loadedFont;
return loadedFont;
}
}
if (name == DEFAULT_FONT)
{
LOG("Graphics::TextRenderer", LOG_ERROR, "Unable to load default font: %s", DEFAULT_FONT);
exit(1);
}
loadedFont = GetFont(DEFAULT_FONT, size);
fonts[name] = loadedFont;
LOG("Graphics::TextRenderer", LOG_WARNING, "Unable to load font '%s', defaulted to '%s'", name.c_str(), DEFAULT_FONT);
return loadedFont;
}

vec2 TextDimensions ( const std::string& font, const std::string& text, int size )
{
int xcoord = 0;
int ycoord = 0;
Expand All @@ -147,7 +180,7 @@ vec2 TextDimensions ( const std::string& font, const std::string& text, float si
return vec2(xcoord, ycoord);
}

GLuint TextObject ( const std::string& font, const std::string& text, float size )
GLuint TextObject ( const std::string& font, const std::string& text, int size )
{
TextEntry* entry = GetEntry(font, text, size);
assert(entry);
Expand Down
7 changes: 5 additions & 2 deletions Engine/Graphics/TextRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
#include <string>
#ifdef WIN32
#include <gl/gl.h>
#include <SDL/SDL_ttf.h>
#else
#include <OpenGL/gl.h>
#include <SDL_ttf/SDL_ttf.h>
#endif
#include "Utilities/Vec2.h"

Expand All @@ -15,8 +17,9 @@ namespace Graphics
namespace TextRenderer
{

vec2 TextDimensions ( const std::string& font, const std::string& text, float size );
GLuint TextObject ( const std::string& font, const std::string& text, float size );
TTF_Font* GetFont ( const std::string& name, int size );
vec2 TextDimensions ( const std::string& font, const std::string& text, int size );
GLuint TextObject ( const std::string& font, const std::string& text, int size );
void Prune ();
void Flush ();

Expand Down
1 change: 0 additions & 1 deletion Engine/Modes/ModeManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ class LuaMode : public AppMode
script->InvokeSubroutine("mouse_up", event.object, mouseMapped.X(), mouseMapped.Y());
break;
case Input::Event::QUIT:
// TODO: interpret this better: maybe just handle it like an ESC?
QuitEngine();
break;
default: break;
Expand Down
4 changes: 2 additions & 2 deletions Engine/Net/Net.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ struct Message
{
Message ( std::string _message, const void* _data, size_t _len ) : message(_message), dataLength(_len), clientID(0), data(NULL) { if (_data) { data = malloc(_len); memcpy(data, _data, _len); } }
~Message () { if (data) free(data); }
unsigned int clientID; // only for server use
std::string message;
void* data;
size_t dataLength;
unsigned int clientID; // only for server use
void* data;
};

class Client
Expand Down
Loading

0 comments on commit 3e5d64c

Please sign in to comment.