diff --git a/color.h b/color.h index 9c96e8a6d09..d5a392c012a 100644 --- a/color.h +++ b/color.h @@ -40,6 +40,11 @@ public: vals_[0] = c.vals_[0]; vals_[1] = c.vals_[1]; vals_[2] = c.vals_[2]; return *this; } + + Color& operator =(Color *c) { + vals_[0] = c->vals_[0]; vals_[1] = c->vals_[1]; vals_[2] = c->vals_[2]; + return *this; + } }; #endif diff --git a/colormap.h b/colormap.h index 589b3ff2681..544ddb27287 100644 --- a/colormap.h +++ b/colormap.h @@ -22,10 +22,10 @@ #include "resource.h" #include -class Colormap : public Resource { +class CMap : public Resource { public: // Load a colormap from the given data. - Colormap(const char *filename, const char *data, int len) : + CMap(const char *filename, const char *data, int len) : Resource(filename) { if (len < 4 || std::memcmp(data, "CMP ", 4) != 0) diff --git a/costume.cpp b/costume.cpp index 40d59629b09..d5ebdfc4385 100644 --- a/costume.cpp +++ b/costume.cpp @@ -107,7 +107,7 @@ public: void setKey(int val); void update(); void reset(); - void setColormap(Colormap *c); + void setColormap(CMap *c); void setMatrix(Matrix4 matrix) { matrix_ = matrix; }; ~ModelComponent(); @@ -117,7 +117,7 @@ public: protected: std::string filename_; ResPtr obj_; - ResPtr cmap_; + ResPtr cmap_; Model::HierNode *hier_; Matrix4 matrix_; }; @@ -226,7 +226,7 @@ void ModelComponent::reset() { hier_->hierVisible_ = false; } -void ModelComponent::setColormap(Colormap *c) { +void ModelComponent::setColormap(CMap *c) { cmap_ = c; } @@ -287,7 +287,7 @@ public: ~ColormapComponent(); private: - ResPtr cmap_; + ResPtr cmap_; }; ColormapComponent::ColormapComponent(Costume::Component *parent, @@ -775,4 +775,4 @@ void Costume::setPosRotate( Vector3d pos_, float pitch_, float yaw_, float roll_ { matrix_.pos_ = pos_; matrix_.rot_.buildFromPitchYawRoll( pitch_, yaw_, roll_ ); -} \ No newline at end of file +} diff --git a/engine.h b/engine.h index c73b8dd398d..5ae35eb0d2a 100644 --- a/engine.h +++ b/engine.h @@ -80,6 +80,8 @@ enum { class Engine { public: + GLuint font; // FIXME: Temporary font drawing hack + static Engine *instance() { if (instance_ == NULL) instance_ = new Engine; @@ -120,6 +122,9 @@ public: return textObjects_.end(); } void registerTextObject(TextObject *a) { textObjects_.push_back(a); } + void killTextObject(TextObject *a) { + textObjects_.remove(a); + } void killTextObjects() { while (!textObjects_.empty()) { delete textObjects_.back(); @@ -127,6 +132,7 @@ public: } } + private: static Engine *instance_; diff --git a/lua.cpp b/lua.cpp index ac8eae51958..9c94d19d35d 100644 --- a/lua.cpp +++ b/lua.cpp @@ -882,63 +882,70 @@ static void MakeTextObject() { } textObject = new TextObject((const char *)line, x, y, *fgColor); + lua_pushstring(line); // FIXME: Register a LUA text object and pass that instead? } static void KillTextObject() { - char *line; + char *textID; if (lua_isnil(lua_getparam(1))) { // FIXME: check this.. nil is kill all lines? - Engine::instance()->killTextObjects(); + error("KillTextObject(NULL)"); + //Engine::instance()->killTextObjects(); return; } - line = lua_getstring(lua_getparam(1)); + textID = lua_getstring(lua_getparam(1)); - error("killTextObject(%s)", line); + warning("killTextObject(%s)", textID); for (Engine::text_list_type::const_iterator i = Engine::instance()->textsBegin(); i != Engine::instance()->textsEnd(); i++) { TextObject *textO = *i; - const char *name = textO->name(); - if (name==NULL) - error("Text object with null name!"); - warning("Comparing **%s** to **%s**", line, name); - if (strstr(name, line)) { - error("Wanting to destroy text object %s ", line); - break; + if (strstr(textO->name(), textID)) { + Engine::instance()->killTextObject(textO); + delete textO; + return; } } } static void ChangeTextObject() { - char *line = lua_getstring(lua_getparam(1)), *key_text = NULL, *val_text = NULL; - lua_Object table_obj = lua_getparam(2), key; + char *textID = lua_getstring(lua_getparam(1)), *keyText = NULL; + lua_Object tableObj = lua_getparam(2), tableKey; + TextObject *modifyObject = NULL; - // FIXME: Disable this for now, as it seems to go into an infinite loop - // when using Don's computer?!? - warning("STUB: ChangeTextObject(%s)", line); - return; + for (Engine::text_list_type::const_iterator i = Engine::instance()->textsBegin(); + i != Engine::instance()->textsEnd(); i++) { + TextObject *textO = *i; - printf("STUB: ChangeTextObject(%s, ", line); - - while(1) { - lua_pushobject(table_obj); - if (key_text) - lua_pushobject(key); - else - lua_pushnil(); - - lua_call("next"); - key=lua_getresult(1); - if (lua_isnil(key)) - break; - - key_text=lua_getstring(key); - val_text=lua_getstring(lua_getresult(2)); - printf(" %s=%s ", key_text, val_text); + if (strstr(textO->name(), textID)) { + modifyObject = textO; + break; + } } - printf(")\n"); + if (!modifyObject) + error("ChangeTextObject(%s): Cannot find active text object", textID); + + while(1) { + lua_pushobject(tableObj); + if (keyText) lua_pushobject(tableKey); else lua_pushnil(); + lua_call("next"); + tableKey=lua_getresult(1); + if (lua_isnil(tableKey)) + break; + + keyText=lua_getstring(tableKey); + + if (strstr(keyText, "fgcolor")) + modifyObject->setColor(check_color(2)); + else if (strstr(keyText, "x")) + ; // modifyObject->setX(atoi(lua_getstring(lua_getresult(2)))); + else if (strstr(keyText, "y")) + ; // modifyObject->setY(atoi(lua_getstring(lua_getresult(2)))); + else + printf("ChangeTextObject(%s) - Unknown key %s\n", textID, keyText); + } } static void GetTextObjectDimensions() { diff --git a/main.cpp b/main.cpp index 84eb07bd9d1..870f9acebdd 100644 --- a/main.cpp +++ b/main.cpp @@ -30,6 +30,14 @@ #include #endif +// Hacky includes for temporary font rendering +#ifndef WIN32 + #include + #include +#else + #include +#endif + // Hacky global toggles for experimental/debug code int ZBUFFER_GLOBAL, SCREENBLOCKS_GLOBAL; @@ -117,6 +125,19 @@ int main(int argc, char *argv[]) { lua_call("BOOT"); lua_endblock(); + // FIXME: Hacky temporary font renderer code + Engine::instance()->font = glGenLists(256); + #ifdef WIN32 + #warning FIXME: Do Win32 code + #else + { + Display *dpy = XOpenDisplay(NULL); + XFontStruct *XFont = XLoadQueryFont(dpy, "-misc-fixed-medium-r-*-*-20-*-*-*-*-*-*-*" ); + glXUseXFont(XFont->fid, 0, 256, Engine::instance()->font); + XFreeFont(dpy, XFont); + XCloseDisplay(dpy); + } + #endif Engine::instance()->mainLoop(); return 0; diff --git a/material.cpp b/material.cpp index 8daf5d181f4..2a5e88725b0 100644 --- a/material.cpp +++ b/material.cpp @@ -22,7 +22,7 @@ #include "debug.h" Material::Material(const char *filename, const char *data, int len, - const Colormap &cmap) : + const CMap &cmap) : Resource(filename) { if (len < 4 || memcmp(data, "MAT ", 4) != 0) diff --git a/material.h b/material.h index 0efa1dda1b1..0d961b8562e 100644 --- a/material.h +++ b/material.h @@ -23,13 +23,13 @@ #include #include -class Colormap; +class CMap; class Material : public Resource { public: // Load a texture from the given data. Material(const char *filename, const char *data, int len, - const Colormap &cmap); + const CMap &cmap); // Load this texture into the GL context void select() const; diff --git a/model.cpp b/model.cpp index 4f054a89048..e981397fdb2 100644 --- a/model.cpp +++ b/model.cpp @@ -28,7 +28,7 @@ #include "screen.h" Model::Model(const char *filename, const char *data, int len, - const Colormap &cmap) : Resource(filename) + const CMap &cmap) : Resource(filename) { if (len >= 4 && std::memcmp(data, "LDOM", 4) == 0) loadBinary(data, cmap); @@ -38,7 +38,7 @@ Model::Model(const char *filename, const char *data, int len, } } -void Model::loadBinary(const char *data, const Colormap &cmap) { +void Model::loadBinary(const char *data, const CMap &cmap) { numMaterials_ = get_LE_uint32(data + 4); data += 8; materials_ = new ResPtr[numMaterials_]; @@ -293,7 +293,7 @@ Model::HierNode *Model::copyHierarchy() { return result; } -void Model::loadText(TextSplitter &ts, const Colormap &cmap) { +void Model::loadText(TextSplitter &ts, const CMap &cmap) { ts.expectString("section: header"); int major, minor; ts.scanString("3do %d.%d", 2, &major, &minor); @@ -650,12 +650,11 @@ void Model::Mesh::draw() const { // Ender: HACK HACK HACK // Mannys head isn't computed correctly, so bail out to prevent memory corruption. // .. at least until it IS computed, or the DirtyScreen code has bounds checking :) - if (strstr(name_, "m_head_1")) - return; + //if (strstr(name_, "m_head_1")) + // return; // Yaz: debug // this compute the dirty rect for the mesh - glPushMatrix(); glLoadIdentity(); @@ -712,8 +711,8 @@ void Model::Mesh::draw() const { if (SCREENBLOCKS_GLOBAL == 1) screenBlocksAddRectangle( top, right, left, bottom, bestDepth ); } - - /* glDisable(GL_DEPTH_TEST); +/* + glDisable(GL_DEPTH_TEST); glPointSize( 3.f ); glColor4f( 1.f, 1.f, 0.f, 1.f ); glDisable(GL_TEXTURE_2D ); @@ -750,8 +749,9 @@ void Model::Mesh::draw() const { glEnd(); glEnable(GL_DEPTH_TEST); - glEnable(GL_TEXTURE_2D ); */ + glEnable(GL_TEXTURE_2D ); glPopMatrix(); +*/ } void Model::Face::draw(float *vertices, float *vertNormals, diff --git a/model.h b/model.h index 5ab059a8a9c..a7fefd8c319 100644 --- a/model.h +++ b/model.h @@ -23,16 +23,16 @@ #include "resource.h" #include -class Colormap; +class CMap; class Material; class TextSplitter; class Model : public Resource { public: // Construct a 3D model from the given data. - Model(const char *filename, const char *data, int len, const Colormap &cmap); - void loadBinary(const char *data, const Colormap &cmap); - void loadText(TextSplitter &ts, const Colormap &cmap); + Model(const char *filename, const char *data, int len, const CMap &cmap); + void loadBinary(const char *data, const CMap &cmap); + void loadText(TextSplitter &ts, const CMap &cmap); void draw() const; diff --git a/resource.cpp b/resource.cpp index 67578d62957..bb75482c34c 100644 --- a/resource.cpp +++ b/resource.cpp @@ -149,18 +149,18 @@ Bitmap *ResourceLoader::loadBitmap(const char *filename) { return result; } -Colormap *ResourceLoader::loadColormap(const char *filename) { +CMap *ResourceLoader::loadColormap(const char *filename) { std::string fname = filename; makeLower(fname); cache_type::iterator i = cache_.find(fname); if (i != cache_.end()) { - return dynamic_cast(i->second); + return dynamic_cast(i->second); } Block *b = getFileBlock(filename); if (b == NULL) error("Could not find colormap %s\n", filename); - Colormap *result = new Colormap(filename, b->data(), b->len()); + CMap *result = new CMap(filename, b->data(), b->len()); delete b; cache_[fname] = result; return result; @@ -195,7 +195,7 @@ KeyframeAnim *ResourceLoader::loadKeyframe(const char *filename) { } Material *ResourceLoader::loadMaterial(const char *filename, - const Colormap &c) { + const CMap &c) { std::string fname = filename; makeLower(fname); cache_type::iterator i = cache_.find(fname); @@ -212,7 +212,7 @@ Material *ResourceLoader::loadMaterial(const char *filename, return result; } -Model *ResourceLoader::loadModel(const char *filename, const Colormap &c) { +Model *ResourceLoader::loadModel(const char *filename, const CMap &c) { std::string fname = filename; makeLower(fname); cache_type::iterator i = cache_.find(fname); diff --git a/resource.h b/resource.h index 2d3299711bf..fa46069542a 100644 --- a/resource.h +++ b/resource.h @@ -24,7 +24,7 @@ #include class Bitmap; -class Colormap; +class CMap; class Costume; class KeyframeAnim; class Material; @@ -94,11 +94,11 @@ public: } Bitmap *loadBitmap(const char *fname); - Colormap *loadColormap(const char *fname); + CMap *loadColormap(const char *fname); Costume *loadCostume(const char *fname, Costume *prevCost); KeyframeAnim *loadKeyframe(const char *fname); - Material *loadMaterial(const char *fname, const Colormap &c); - Model *loadModel(const char *fname, const Colormap &c); + Material *loadMaterial(const char *fname, const CMap &c); + Model *loadModel(const char *fname, const CMap &c); Sound *loadSound(const char *fname); void uncache(const char *fname); diff --git a/scene.cpp b/scene.cpp index aabf6ff7ef8..7a4514d407f 100644 --- a/scene.cpp +++ b/scene.cpp @@ -35,7 +35,7 @@ Scene::Scene(const char *name, const char *buf, int len) : ts.expectString("section: colormaps"); ts.scanString(" numcolormaps %d", 1, &numCmaps_); - cmaps_ = new ResPtr[numCmaps_]; + cmaps_ = new ResPtr[numCmaps_]; char cmap_name[256]; for (int i = 0; i < numCmaps_; i++) { ts.scanString(" colormap %256s", 1, cmap_name); diff --git a/scene.h b/scene.h index 09e0341fc99..902fb159a38 100644 --- a/scene.h +++ b/scene.h @@ -27,7 +27,7 @@ #include #include -class Colormap; +class CMap; class TextSplitter; // The Lua code calls this a "set". @@ -86,7 +86,7 @@ private: std::string name_; int numCmaps_; - ResPtr *cmaps_; + ResPtr *cmaps_; int numSetups_, numLights_, numSectors_; Sector *sectors_; Light *lights_; diff --git a/textobject.cpp b/textobject.cpp index 8b315da75b5..6bc744ba1f8 100644 --- a/textobject.cpp +++ b/textobject.cpp @@ -28,10 +28,29 @@ TextObject::TextObject(const char *text, const int x, const int y, const Color& void TextObject::setX(int x) {x_ = x;} void TextObject::setY(int y) {y_ = y;} -void TextObject::setColor(const Color& newcolor) {fgColor_ = newcolor;} +void TextObject::setColor(Color *newcolor) {fgColor_ = newcolor;} void TextObject::draw() { - std::string result = Localizer::instance()->localize(textID_); - warning("Drawing text object %s at (%d,%d): %s", textID_, x_, y_, result.c_str()); + const char *localString = Localizer::instance()->localize(textID_).c_str(); + //warning("Drawing text object %s at (%d,%d): %s", textID_, x_, y_, localString); + + glMatrixMode( GL_PROJECTION ); + glPushMatrix(); + glLoadIdentity(); + glOrtho(0, 640, 480, 0, 0, 1); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + + glColor3f(fgColor_.red(), fgColor_.green(), fgColor_.blue()); + glRasterPos2i(x_, y_); + glListBase(Engine::instance()->font); + glCallLists( + strlen(rindex(localString, '/')) - 1, + GL_UNSIGNED_BYTE, + rindex(localString, '/') + 1 + ); + + glMatrixMode( GL_PROJECTION ); + glPopMatrix(); } diff --git a/textobject.h b/textobject.h index ba0a817e2d1..8fa36daa8e8 100644 --- a/textobject.h +++ b/textobject.h @@ -29,7 +29,7 @@ class TextObject { TextObject(const char *text, const int x, const int y, const Color& fgColor); void setX(int x); void setY(int y); - void setColor(const Color& newColor); + void setColor(Color *newColor); const char *name() const { return textID_; } void draw();