@@ -31,7 +31,7 @@ class FontData | |||
friend class Font; | |||
private: | |||
char *name; | |||
String m_name; | |||
TileSet *tileset; | |||
ivec2 size; | |||
}; | |||
@@ -43,8 +43,7 @@ private: | |||
Font::Font(char const *path) | |||
: data(new FontData()) | |||
{ | |||
data->name = (char *)malloc(7 + strlen(path) + 1); | |||
sprintf(data->name, "<font> %s", path); | |||
data->m_name = String("<font> ") + path; | |||
data->tileset = Tiler::Register(path, ivec2(0), ivec2(16)); | |||
data->size = data->tileset->GetSize(0); | |||
@@ -55,7 +54,6 @@ Font::Font(char const *path) | |||
Font::~Font() | |||
{ | |||
Tiler::Deregister(data->tileset); | |||
free(data->name); | |||
delete data; | |||
} | |||
@@ -66,7 +64,7 @@ void Font::TickDraw(float seconds) | |||
char const *Font::GetName() | |||
{ | |||
return data->name; | |||
return data->m_name.C(); | |||
} | |||
void Font::Print(vec3 pos, char const *str, vec2 scale) | |||
@@ -344,14 +344,13 @@ ShaderUniform Shader::GetUniformLocation(char const *uni) const | |||
ShaderUniform ret; | |||
#if defined USE_D3D9 || defined _XBOX | |||
/* Global variables are prefixed with "$" */ | |||
char tmpname[128]; | |||
sprintf(tmpname, "$%s", uni); | |||
String tmpname = String("$") + uni; | |||
D3DXCONSTANT_DESC cdesc; | |||
D3DXHANDLE hr; | |||
UINT count; | |||
count = 0; | |||
hr = data->frag_table->GetConstantByName(nullptr, tmpname); | |||
hr = data->frag_table->GetConstantByName(nullptr, tmpname.C()); | |||
if (hr) | |||
data->frag_table->GetConstantDesc(hr, &cdesc, &count); | |||
if (count) | |||
@@ -361,7 +360,7 @@ ShaderUniform Shader::GetUniformLocation(char const *uni) const | |||
} | |||
count = 0; | |||
hr = data->vert_table->GetConstantByName(nullptr, tmpname); | |||
hr = data->vert_table->GetConstantByName(nullptr, tmpname.C()); | |||
if (hr) | |||
data->vert_table->GetConstantDesc(hr, &cdesc, &count); | |||
if (count) | |||
@@ -45,7 +45,7 @@ class SampleData | |||
friend class Sample; | |||
private: | |||
char *name, *path; | |||
String m_name; | |||
#if defined USE_SDL_MIXER | |||
Mix_Chunk *m_chunk; | |||
int m_channel; | |||
@@ -59,9 +59,7 @@ private: | |||
Sample::Sample(char const *path) | |||
: data(new SampleData()) | |||
{ | |||
data->name = (char *)malloc(9 + strlen(path) + 1); | |||
data->path = data->name + 9; | |||
sprintf(data->name, "<sample> %s", path); | |||
data->m_name = String("<sample> ") + path; | |||
#if defined USE_SDL_MIXER | |||
Array<String> pathlist = System::GetPathList(path); | |||
@@ -88,7 +86,6 @@ Sample::~Sample() | |||
#if defined USE_SDL_MIXER | |||
Mix_FreeChunk(data->m_chunk); | |||
#endif | |||
free(data->name); | |||
delete data; | |||
} | |||
@@ -99,7 +96,7 @@ void Sample::TickGame(float seconds) | |||
char const *Sample::GetName() | |||
{ | |||
return data->name; | |||
return data->m_name.C(); | |||
} | |||
void Sample::Play() | |||
@@ -32,8 +32,8 @@ class TextData | |||
friend class Text; | |||
private: | |||
int font, align, length; | |||
char *text; | |||
int font, align; | |||
String m_text; | |||
vec3 pos; | |||
}; | |||
@@ -45,8 +45,8 @@ Text::Text(char const *text, char const *font) | |||
: data(new TextData()) | |||
{ | |||
data->font = Forge::Register(font); | |||
data->text = text ? strdup(text) : nullptr; | |||
data->length = text ? strlen(text) : 0; | |||
if (text) | |||
data->m_text = text; | |||
data->pos = vec3(0, 0, 0); | |||
m_drawgroup = DRAWGROUP_HUD; | |||
@@ -54,20 +54,12 @@ Text::Text(char const *text, char const *font) | |||
void Text::SetText(char const *text) | |||
{ | |||
if (data->text) | |||
free(data->text); | |||
data->text = text ? strdup(text) : nullptr; | |||
data->length = text ? strlen(text) : 0; | |||
data->m_text = text; | |||
} | |||
void Text::SetInt(int val) | |||
{ | |||
if (data->text) | |||
free(data->text); | |||
char text[128]; | |||
sprintf(text, "%i", val); | |||
data->text = strdup(text); | |||
data->length = strlen(text); | |||
data->m_text = String::Printf("%i", val); | |||
} | |||
void Text::SetPos(vec3 pos) | |||
@@ -90,22 +82,21 @@ void Text::TickDraw(float seconds) | |||
{ | |||
Entity::TickDraw(seconds); | |||
if (data->text) | |||
int length = data->m_text.Count(); | |||
if (length) | |||
{ | |||
Font *font = Forge::GetFont(data->font); | |||
vec3 delta(0.0f); | |||
if (data->align == ALIGN_RIGHT) | |||
delta.x -= data->length * font->GetSize().x; | |||
delta.x -= length * font->GetSize().x; | |||
else if (data->align == ALIGN_CENTER) | |||
delta.x -= data->length * font->GetSize().x / 2; | |||
font->Print(data->pos + delta, data->text); | |||
delta.x -= length * font->GetSize().x / 2; | |||
font->Print(data->pos + delta, data->m_text.C()); | |||
} | |||
} | |||
Text::~Text() | |||
{ | |||
if (data->text) | |||
free(data->text); | |||
Forge::Deregister(data->font); | |||
delete data; | |||
} | |||
@@ -49,7 +49,7 @@ class TileSetData | |||
friend class TileSet; | |||
private: | |||
char *name, *path; | |||
String m_name; | |||
int *tiles, ntiles; | |||
ivec2 size, isize, count; | |||
vec2 scale; | |||
@@ -66,9 +66,7 @@ private: | |||
TileSet::TileSet(char const *path, ivec2 size, ivec2 count) | |||
: data(new TileSetData()) | |||
{ | |||
data->name = (char *)malloc(10 + strlen(path) + 1); | |||
data->path = data->name + 10; | |||
sprintf(data->name, "<tileset> %s", path); | |||
data->m_name = String("<tileset> ") + path; | |||
data->tiles = nullptr; | |||
data->m_texture = 0; | |||
@@ -100,7 +98,6 @@ TileSet::TileSet(char const *path, ivec2 size, ivec2 count) | |||
TileSet::~TileSet() | |||
{ | |||
free(data->tiles); | |||
free(data->name); | |||
delete data; | |||
} | |||
@@ -159,7 +156,7 @@ void TileSet::TickDraw(float seconds) | |||
char const *TileSet::GetName() | |||
{ | |||
return data->name; | |||
return data->m_name.C(); | |||
} | |||
ivec2 TileSet::GetCount() const | |||