From a90cd304ba4310833f239cd0d1528c3700ecbe99 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Fri, 19 Oct 2012 22:37:11 +0200 Subject: Track texture mapping --- src/graphics/engine/engine.cpp | 101 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 92 insertions(+), 9 deletions(-) diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 3365b24..90c00f5 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -812,9 +812,9 @@ EngineObjLevel4& CEngine::AddLevel4(EngineObjLevel3& p3, EngineTriangleType type } bool CEngine::AddTriangles(int objRank, const std::vector& vertices, - const Material& material, int state, - std::string tex1Name, std::string tex2Name, - float min, float max, bool globalUpdate) + const Material& material, int state, + std::string tex1Name, std::string tex2Name, + float min, float max, bool globalUpdate) { if ( objRank < 0 || objRank >= static_cast( m_objects.size() ) ) { @@ -1247,12 +1247,95 @@ bool CEngine::ChangeTextureMapping(int objRank, const Material& mat, int state, } bool CEngine::TrackTextureMapping(int objRank, const Material& mat, int state, - const std::string& tex1Name, const std::string& tex2Name, - float min, float max, EngineTextureMapping mode, - float pos, float factor, float tl, float ts, float tt) + const std::string& tex1Name, const std::string& tex2Name, + float min, float max, EngineTextureMapping mode, + float pos, float factor, float tl, float ts, float tt) { - // TODO track texture mapping: pretty complex code, so leaving it for now - GetLogger()->Trace("CEngine::TrackTextureMapping(): stub!\n"); + EngineObjLevel4* triangles = FindTriangles(objRank, mat, state, tex1Name, tex2Name, min, max); + if (triangles == nullptr) return false; + + int tNum = triangles->vertices.size(); + if (tNum < 12 || tNum % 6 != 0) return false; + + std::vector& vs = triangles->vertices; + + while (pos < 0.0f) + pos += 1000000.0f; // never negative! + + // TODO: might still be buggy as track animation seems to be choppy + // but the code should work exactly as in original + + Math::Vector current; + + for (int i = 0; i < 6; i++) + { + for (int j = 0; j < 6; j++) + { + if (Math::IsEqual(vs[i].coord.x, vs[j+6].coord.x) && + Math::IsEqual(vs[i].coord.y, vs[j+6].coord.y)) + { + current.x = vs[i].coord.x; // position end link + current.y = vs[i].coord.y; + break; + } + } + } + + float ps = 0.0f; // start position on the periphery + float pe = 0.0f; + int is[6] = { 0 }, ie[6] = { 0 }; + + int tBase = 0; + for (int ti = 0; ti < tNum / 6; ti++) + { + int s = 0; + int e = 0; + + for (int i = 0; i < 6; i++) + { + if (Math::IsEqual(vs[tBase + i].coord.x, current.x, 0.0001f) && + Math::IsEqual(vs[tBase + i].coord.y, current.y, 0.0001f)) + { + ie[e++] = i; + } + else + { + is[s++] = i; + } + } + if (s == 3 && e == 3) + { + pe = ps + Math::Point(vs[tBase + is[0]].coord.x - vs[tBase + ie[0]].coord.x, + vs[tBase + is[0]].coord.y - vs[tBase + ie[0]].coord.y).Length() / factor; // end position on the periphery + + float pps = ps + pos; + float ppe = pe + pos; + float offset = static_cast( static_cast(pps) ); + ppe -= offset; + + for (int i = 0; i < 3; i++) + { + vs[tBase + is[i]].texCoord.x = ((ppe * tl) + ts) / tt; + } + } + + if (ti >= (tNum / 6) - 1) + break; + + for (int i = 0; i < 6; i++) + { + if (!Math::IsEqual(vs[tBase + i+6].coord.x, current.x, 0.0001f) || + !Math::IsEqual(vs[tBase + i+6].coord.y, current.y, 0.0001f)) + { + current.x = vs[tBase + i+6].coord.x; // end next link + current.y = vs[tBase + i+6].coord.y; + break; + } + } + ps = pe; // following start position on the periphery + tBase += 6; + } + return true; } @@ -3586,7 +3669,7 @@ void CEngine::DrawBackgroundImage() p2.x = 1.0f; p2.y = 1.0f; -Math::Vector n = Math::Vector(0.0f, 0.0f, -1.0f); // normal + Math::Vector n = Math::Vector(0.0f, 0.0f, -1.0f); // normal float u1, u2, v1, v2; if (m_backgroundFull) -- cgit v1.2.3-1-g7c22 From be4654c63b80862352961160446155238eee3ef5 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Fri, 19 Oct 2012 22:43:18 +0200 Subject: Fix track mapping and sphere particle position --- src/graphics/engine/engine.cpp | 11 +++++------ src/graphics/engine/particle.cpp | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 90c00f5..6d07b62 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -1260,10 +1260,7 @@ bool CEngine::TrackTextureMapping(int objRank, const Material& mat, int state, std::vector& vs = triangles->vertices; while (pos < 0.0f) - pos += 1000000.0f; // never negative! - - // TODO: might still be buggy as track animation seems to be choppy - // but the code should work exactly as in original + pos += 1.0f; // never negative! Math::Vector current; @@ -1310,12 +1307,14 @@ bool CEngine::TrackTextureMapping(int objRank, const Material& mat, int state, float pps = ps + pos; float ppe = pe + pos; - float offset = static_cast( static_cast(pps) ); + int offset = static_cast(pps); ppe -= offset; + pps -= offset; for (int i = 0; i < 3; i++) { - vs[tBase + is[i]].texCoord.x = ((ppe * tl) + ts) / tt; + vs[tBase + is[i]].texCoord.x = ((pps * tl) + ts) / tt; + vs[tBase + ie[i]].texCoord.x = ((ppe * tl) + ts) / tt; } } diff --git a/src/graphics/engine/particle.cpp b/src/graphics/engine/particle.cpp index acc40df..388c189 100644 --- a/src/graphics/engine/particle.cpp +++ b/src/graphics/engine/particle.cpp @@ -3214,7 +3214,7 @@ void CParticle::DrawParticleSphere(int i) angle.z = m_particle[i].angle*0.7f; Math::Matrix rot; Math::LoadRotationZXYMatrix(rot, angle); - mat = Math::MultiplyMatrices(rot, mat); + mat = Math::MultiplyMatrices(mat, rot); } m_device->SetTransform(TRANSFORM_WORLD, mat); -- cgit v1.2.3-1-g7c22 From 6d06c9f722885805f7e150173706804634b3e5d4 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Fri, 19 Oct 2012 23:05:41 +0200 Subject: Flare textures should work now --- src/graphics/engine/engine.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 6d07b62..daf0386 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -3271,8 +3271,7 @@ void CEngine::Draw3DScene() m_particle->DrawParticle(SH_WORLD); // draws the particles of the 3D world m_lightning->Draw(); // draws lightning - // TODO: fix white screen error; commenting out temporarily - // if (m_lensMode) DrawForegroundImage(); // draws the foreground + if (m_lensMode) DrawForegroundImage(); // draws the foreground if (! m_overFront) DrawOverColor(); // draws the foreground color } -- cgit v1.2.3-1-g7c22 From 40e065aea947b45700930d431754282c23d1de45 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sat, 20 Oct 2012 16:34:22 +0200 Subject: Ground spot texture drawing --- src/common/image.cpp | 9 ++ src/common/image.h | 3 + src/graphics/engine/engine.cpp | 268 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 269 insertions(+), 11 deletions(-) diff --git a/src/common/image.cpp b/src/common/image.cpp index f3cfa34..638304e 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -190,6 +190,15 @@ Math::IntPoint CImage::GetSize() const return Math::IntPoint(m_data->surface->w, m_data->surface->h); } +/** Image must be valid. */ +void CImage::Fill(Gfx::IntColor color) +{ + assert(m_data != nullptr); + + Uint32 c = SDL_MapRGBA(m_data->surface->format, color.r, color.g, color.b, color.a); + SDL_FillRect(m_data->surface, nullptr, c); +} + /** * Image must be valid and pixel coords in valid range. * diff --git a/src/common/image.h b/src/common/image.h index d23a6fa..d9da75b 100644 --- a/src/common/image.h +++ b/src/common/image.h @@ -79,6 +79,9 @@ public: //! Returns the image size Math::IntPoint GetSize() const; + //! Fills the whole image with given color + void Fill(Gfx::IntColor color); + //! Sets the color at given pixel void SetPixel(Math::IntPoint pixel, Gfx::Color color); diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index daf0386..019e959 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -1638,6 +1638,7 @@ void CEngine::CreateGroundMark(Math::Vector pos, float radius, { m_groundMark.LoadDefault(); + m_groundMark.draw = true; m_groundMark.phase = ENG_GR_MARK_PHASE_INC; m_groundMark.delay[0] = delay1; m_groundMark.delay[1] = delay2; @@ -3409,8 +3410,262 @@ void CEngine::DrawInterface() void CEngine::UpdateGroundSpotTextures() { - // TODO the original code modifying the textures is very complex, so stub for now - GetLogger()->Trace("CEngine::UpdateGroundSpotTextures(): stub!\n"); + if (!m_firstGroundSpot && + m_groundMark.drawPos.x == m_groundMark.pos.x && + m_groundMark.drawPos.z == m_groundMark.pos.z && + m_groundMark.drawRadius == m_groundMark.radius && + m_groundMark.drawIntensity == m_groundMark.intensity) return; + + for (int s = 0; s < 16; s++) + { + Math::Point min, max; + min.x = (s%4) * 254.0f - 1.0f; // 1 pixel cover + min.y = (s/4) * 254.0f - 1.0f; + max.x = min.x + 254.0f + 2.0f; + max.y = min.y + 254.0f + 2.0f; + + bool clear = false; + bool set = false; + + // Calculate the area to be erased. + int dot = static_cast(m_groundMark.drawRadius/2.0f); + + float tu, tv; + float cx, cy; + + tu = (m_groundMark.drawPos.x+1600.0f)/3200.0f; + tv = (m_groundMark.drawPos.z+1600.0f)/3200.0f; // 0..1 + + cx = (tu*254.0f*4.0f)-0.5f; + cy = (tv*254.0f*4.0f)-0.5f; + + if (dot == 0) + { + cx += 0.5f; + cy += 0.5f; + } + + float px = cx-Math::Mod(cx, 1.0f); + float py = cy-Math::Mod(cy, 1.0f); // multiple of 1 + + if (m_firstGroundSpot || + (m_groundMark.drawRadius != 0.0f && + px+dot >= min.x && py+dot >= min.y && + px-dot <= max.x && py-dot <= max.y)) + { + clear = true; + } + + // Calculate the area to draw. + dot = static_cast(m_groundMark.radius/2.0f); + + tu = (m_groundMark.pos.x+1600.0f)/3200.0f; + tv = (m_groundMark.pos.z+1600.0f)/3200.0f; // 0..1 + + cx = (tu*254.0f*4.0f)-0.5f; + cy = (tv*254.0f*4.0f)-0.5f; + + if ( dot == 0 ) + { + cx += 0.5f; + cy += 0.5f; + } + + px = cx - Math::Mod(cx, 1.0f); + py = cy - Math::Mod(cy, 1.0f); // multiple of 1 + + if (m_groundMark.draw && + px+dot >= min.x && py+dot >= min.y && + px-dot <= max.x && py-dot <= max.y) + { + set = true; + } + + if (clear || set) + { + CImage shadowImg(Math::IntPoint(256, 256)); + shadowImg.Fill(Gfx::IntColor(255, 255, 255, 255)); + + // Draw the new shadows. + for (int i = 0; i < static_cast( m_groundSpots.size() ); i++) + { + if ( m_groundSpots[i].used == false || + m_groundSpots[i].radius == 0.0f ) continue; + + if ( m_groundSpots[i].min == 0.0f && + m_groundSpots[i].max == 0.0f ) + { + dot = static_cast(m_groundSpots[i].radius/2.0f); + + tu = (m_groundSpots[i].pos.x+1600.0f)/3200.0f; + tv = (m_groundSpots[i].pos.z+1600.0f)/3200.0f; // 0..1 + + cx = (tu*254.0f*4.0f) - 0.5f; + cy = (tv*254.0f*4.0f) - 0.5f; + + if (dot == 0) + { + cx += 0.5f; + cy += 0.5f; + } + + px = cx-Math::Mod(cx, 1.0f); + py = cy-Math::Mod(cy, 1.0f); // multiple of 1 + + if ( px+dot < min.x || py+dot < min.y || + px-dot > max.x || py-dot > max.y ) continue; + + for (int iy = -dot; iy <= dot; iy++) + { + for (int ix =- dot; ix <= dot; ix++) + { + float ppx = px+ix; + float ppy = py+iy; + + if ( ppx < min.x || ppy < min.y || + ppx >= max.x || ppy >= max.y ) continue; + + float intensity; + if (dot == 0) + intensity = 0.0f; + else + intensity = Math::Point(ppx-cx, ppy-cy).Length()/dot; + + Gfx::Color color; + color.r = Math::Norm(m_groundSpots[i].color.r+intensity); + color.g = Math::Norm(m_groundSpots[i].color.g+intensity); + color.b = Math::Norm(m_groundSpots[i].color.b+intensity); + + ppx -= min.x; // on the texture + ppy -= min.y; + + shadowImg.SetPixel(Math::IntPoint(ppx, ppy), color); + } + } + } + else + { + for (int iy = 0; iy < 256; iy++) + { + for (int ix = 0; ix < 256; ix++) + { + Math::Vector pos; + pos.x = (256.0f * (s%4) + ix) * 3200.0f/1024.0f - 1600.0f; + pos.z = (256.0f * (s/4) + iy) * 3200.0f/1024.0f - 1600.0f; + pos.y = 0.0f; + + float level = m_terrain->GetFloorLevel(pos, true); + if ( level < m_groundSpots[i].min || + level > m_groundSpots[i].max ) continue; + + float intensity; + if (level > (m_groundSpots[i].max+m_groundSpots[i].min)/2.0f) + intensity = 1.0f - (m_groundSpots[i].max-level) / m_groundSpots[i].smooth; + else + intensity = 1.0f - (level-m_groundSpots[i].min) / m_groundSpots[i].smooth; + + if (intensity < 0.0f) intensity = 0.0f; + + Gfx::Color color; + color.r = Math::Norm(m_groundSpots[i].color.r+intensity); + color.g = Math::Norm(m_groundSpots[i].color.g+intensity); + color.b = Math::Norm(m_groundSpots[i].color.b+intensity); + + shadowImg.SetPixel(Math::IntPoint(ix, iy), color); + } + } + } + } + + if (set) + { + dot = static_cast(m_groundMark.radius/2.0f); + + tu = (m_groundMark.pos.x + 1600.0f) / 3200.0f; + tv = (m_groundMark.pos.z + 1600.0f) / 3200.0f; // 0..1 + + cx = (tu*254.0f*4.0f)-0.5f; + cy = (tv*254.0f*4.0f)-0.5f; + + if (dot == 0) + { + cx += 0.5f; + cy += 0.5f; + } + + px = cx-Math::Mod(cx, 1.0f); + py = cy-Math::Mod(cy, 1.0f); // multiple of 1 + + for (int iy = -dot; iy <= dot; iy++) + { + for (int ix = -dot; ix <= dot; ix++) + { + float ppx = px+ix; + float ppy = py+iy; + + if (ppx < min.x || ppy < min.y || + ppx >= max.x || ppy >= max.y) continue; + + ppx -= min.x; // on the texture + ppy -= min.y; + + float intensity = 1.0f - Math::Point(ix, iy).Length() / dot; + if (intensity <= 0.0f) continue; + intensity *= m_groundMark.intensity; + + int j = (ix+dot) + (iy+dot) * m_groundMark.dx; + if (m_groundMark.table[j] == 1) // green ? + { + Gfx::Color color; + color.r = Math::Norm(1.0f-intensity); + color.g = 1.0f; + color.b = Math::Norm(1.0f-intensity); + shadowImg.SetPixel(Math::IntPoint(ppx, ppy), color); + } + if (m_groundMark.table[j] == 2) // red ? + { + Gfx::Color color; + color.r = 1.0f; + color.g = Math::Norm(1.0f-intensity); + color.b = Math::Norm(1.0f-intensity); + shadowImg.SetPixel(Math::IntPoint(ppx, ppy), color); + } + } + } + } + + std::stringstream str; + str << "shadow" << std::setfill('0') << std::setw(2) << s << ".png"; + std::string texName = str.str(); + + DeleteTexture(texName); + + Gfx::Texture tex = m_device->CreateTexture(&shadowImg, m_defaultTexParams); + + m_texNameMap[texName] = tex; + m_revTexNameMap[tex] = texName; + } + } + + for (int i = 0; i < static_cast( m_groundSpots.size() ); i++) + { + if (m_groundSpots[i].used == false || + m_groundSpots[i].radius == 0.0f) + { + m_groundSpots[i].drawRadius = 0.0f; + } + else + { + m_groundSpots[i].drawPos = m_groundSpots[i].pos; + m_groundSpots[i].drawRadius = m_groundSpots[i].radius; + } + } + + m_groundMark.drawPos = m_groundMark.pos; + m_groundMark.drawRadius = m_groundMark.radius; + m_groundMark.drawIntensity = m_groundMark.intensity; + + m_firstGroundSpot = false; } void CEngine::DrawShadow() @@ -3607,7 +3862,6 @@ void CEngine::DrawShadow() m_device->SetRenderState(RENDER_STATE_LIGHTING, true); } -// STATUS: TESTED, VERIFIED void CEngine::DrawBackground() { if (m_skyMode && m_cloud->GetLevel() != 0.0f) // clouds ? @@ -3627,7 +3881,6 @@ void CEngine::DrawBackground() } } -// STATUS: TESTED void CEngine::DrawBackgroundGradient(const Color& up, const Color& down) { Math::Point p1(0.0f, 0.5f); @@ -3658,7 +3911,6 @@ void CEngine::DrawBackgroundGradient(const Color& up, const Color& down) AddStatisticTriangle(2); } -// Status: TESTED, VERIFIED void CEngine::DrawBackgroundImage() { Math::Point p1, p2; @@ -3729,7 +3981,6 @@ void CEngine::DrawPlanet() m_planet->Draw(); // draws the planets } -// Status: PART_TESTED void CEngine::DrawForegroundImage() { if (m_foregroundName.empty()) return; @@ -3765,10 +4016,8 @@ void CEngine::DrawForegroundImage() AddStatisticTriangle(2); } -// Status: PART_TESTED void CEngine::DrawOverColor() { - // TODO: fuzzy compare? if ( (m_overColor == Color(0.0f, 0.0f, 0.0f, 0.0f) && m_overMode == ENG_RSTATE_TCOLOR_BLACK) || (m_overColor == Color(1.0f, 1.0f, 1.0f, 1.0f) && m_overMode == ENG_RSTATE_TCOLOR_WHITE) ) return; @@ -3805,7 +4054,6 @@ void CEngine::DrawOverColor() AddStatisticTriangle(2); } -// Status: TESTED, VERIFIED void CEngine::DrawHighlight() { Math::Point min, max; @@ -3897,7 +4145,6 @@ void CEngine::DrawHighlight() m_device->DrawPrimitive(PRIMITIVE_LINE_STRIP, line, 3); } -// Status: TESTED, VERIFIED void CEngine::DrawMouse() { MouseMode mode = m_app->GetMouseMode(); @@ -3931,7 +4178,6 @@ void CEngine::DrawMouse() DrawMouseSprite(pos, m_mouseSize, m_mice[index].icon2); } -// Status: TESTED, VERIFIED void CEngine::DrawMouseSprite(Math::Point pos, Math::Point size, int icon) { if (icon == -1) -- cgit v1.2.3-1-g7c22 From 728e7e405dd56afb4da03fd63df378d5f984ed73 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sat, 20 Oct 2012 18:40:24 +0200 Subject: Transparent plant textures --- src/graphics/engine/modelfile.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/graphics/engine/modelfile.cpp b/src/graphics/engine/modelfile.cpp index c0d04a0..3b0343a 100644 --- a/src/graphics/engine/modelfile.cpp +++ b/src/graphics/engine/modelfile.cpp @@ -608,9 +608,6 @@ bool CModelFile::ReadModel(std::istream& stream) triangle.state = t.state; triangle.variableTex2 = t.texNum2 == 1; - if (triangle.tex1Name == "plant.png") - triangle.state |= ENG_RSTATE_ALPHA; - if (!triangle.variableTex2 && t.texNum2 != 0) { if (t.texNum2 >= 1 && t.texNum2 <= 10) @@ -637,6 +634,10 @@ bool CModelFile::ReadModel(std::istream& stream) m_triangles[i].tex2Name = StrUtils::Replace(m_triangles[i].tex2Name, "bmp", "png"); m_triangles[i].tex2Name = StrUtils::Replace(m_triangles[i].tex2Name, "tga", "png"); + // TODO: fix this in model files + if (m_triangles[i].tex1Name == "plant.png") + m_triangles[i].state |= ENG_RSTATE_ALPHA; + GetLogger()->Trace("ModelTriangle %d\n", i+1); std::string s1 = m_triangles[i].p1.ToString(); GetLogger()->Trace(" p1: %s\n", s1.c_str()); -- cgit v1.2.3-1-g7c22 From 688315ab76145a32d0aebf826fbbb7fc9ce24443 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sat, 20 Oct 2012 23:06:56 +0200 Subject: ComputeSphereVisibility and fixes in CEngine TODOs - view frustum culling with ComputeSphereVisibility - game should run faster now - resolved/removed most TODOs from CEngine - fixed OpenGL tests --- src/graphics/core/device.h | 29 +++++------ src/graphics/engine/engine.cpp | 60 ++++++++++++----------- src/graphics/engine/engine.h | 6 --- src/graphics/engine/water.cpp | 6 ++- src/graphics/opengl/gldevice.cpp | 80 +++++++++++++++++-------------- src/graphics/opengl/test/light_test.cpp | 27 ++++++++++- src/graphics/opengl/test/texture_test.cpp | 1 - 7 files changed, 122 insertions(+), 87 deletions(-) diff --git a/src/graphics/core/device.h b/src/graphics/core/device.h index b6dd138..8e7d446 100644 --- a/src/graphics/core/device.h +++ b/src/graphics/core/device.h @@ -204,22 +204,22 @@ enum PrimitiveType }; /** - * \enum IntersectPlane - * \brief Intersection plane of projection volume + * \enum FrustumPlane + * \brief Planes of frustum space * - * These flags can be OR'd together. + * Bitset of flags - can be OR'd together. */ -enum IntersectPlane +enum FrustumPlane { - INTERSECT_PLANE_LEFT = 0x01, - INTERSECT_PLANE_RIGHT = 0x02, - INTERSECT_PLANE_TOP = 0x04, - INTERSECT_PLANE_BOTTOM = 0x08, - INTERSECT_PLANE_FRONT = 0x10, - INTERSECT_PLANE_BACK = 0x20, - INTERSECT_PLANE_ALL = INTERSECT_PLANE_LEFT | INTERSECT_PLANE_RIGHT | - INTERSECT_PLANE_TOP | INTERSECT_PLANE_BOTTOM | - INTERSECT_PLANE_FRONT | INTERSECT_PLANE_BACK + FRUSTUM_PLANE_LEFT = 0x01, + FRUSTUM_PLANE_RIGHT = 0x02, + FRUSTUM_PLANE_TOP = 0x04, + FRUSTUM_PLANE_BOTTOM = 0x08, + FRUSTUM_PLANE_FRONT = 0x10, + FRUSTUM_PLANE_BACK = 0x20, + FRUSTUM_PLANE_ALL = FRUSTUM_PLANE_LEFT | FRUSTUM_PLANE_RIGHT | + FRUSTUM_PLANE_TOP | FRUSTUM_PLANE_BOTTOM | + FRUSTUM_PLANE_FRONT | FRUSTUM_PLANE_BACK }; /** @@ -316,7 +316,8 @@ public: //! Renders primitive composed of vertices with color information virtual void DrawPrimitive(PrimitiveType type, const VertexCol *vertices , int vertexCount) = 0; - //! Tests whether a sphere intersects the 6 clipping planes of projection volume + //! Tests whether a sphere is (partially) within the frustum volume + //! Returns a mask of frustum planes for which the test is positive virtual int ComputeSphereVisibility(const Math::Vector ¢er, float radius) = 0; //! Enables/disables the given render state diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 019e959..ca10304 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -422,18 +422,6 @@ bool CEngine::WriteScreenShot(const std::string& fileName, int width, int height return true; } -bool CEngine::ReadSettings() -{ - // TODO: when INI reading is completed - return true; -} - -bool CEngine::WriteSettings() -{ - // TODO: when INI writing is completed - return true; -} - void CEngine::SetPause(bool pause) { m_pause = pause; @@ -966,7 +954,6 @@ EngineObjLevel4* CEngine::FindTriangles(int objRank, const Material& material, if (! p1.used) continue; if (p1.tex1Name != tex1Name) continue; - // TODO: tex2Name compare? for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) { @@ -1557,7 +1544,22 @@ void CEngine::FlushGroundSpot() m_groundSpots.clear(); m_firstGroundSpot = true; - // TODO: blank all shadow textures + for (int s = 0; s < 16; s++) + { + CImage shadowImg(Math::IntPoint(256, 256)); + shadowImg.Fill(Gfx::IntColor(255, 255, 255, 255)); + + std::stringstream str; + str << "shadow" << std::setfill('0') << std::setw(2) << s << ".png"; + std::string texName = str.str(); + + DeleteTexture(texName); + + Gfx::Texture tex = m_device->CreateTexture(&shadowImg, m_defaultTexParams); + + m_texNameMap[texName] = tex; + m_revTexNameMap[tex] = texName; + } } int CEngine::CreateGroundSpot() @@ -1658,8 +1660,6 @@ void CEngine::DeleteGroundMark(int rank) void CEngine::ComputeDistance() { - // TODO: s_resol??? - for (int i = 0; i < static_cast( m_objects.size() ); i++) { if (! m_objects[i].used) @@ -1877,9 +1877,18 @@ bool CEngine::DetectTriangle(Math::Point mouse, VertexTex2* triangle, int objRan return true; } +//! Use only after world transform already set bool CEngine::IsVisible(int objRank) { - // TODO: use ComputeSphereVisiblity() after tested OK + float radius = m_objects[objRank].radius; + Math::Vector center(0.0f, 0.0f, 0.0f); + if (m_device->ComputeSphereVisibility(center, radius) == Gfx::FRUSTUM_PLANE_ALL) + { + m_objects[objRank].visible = true; + return true; + } + + m_objects[objRank].visible = false; return true; } @@ -1938,7 +1947,7 @@ void CEngine::SetState(int state, const Color& color) params.colorOperation = TEX_MIX_OPER_MODULATE; params.colorArg1 = TEX_MIX_ARG_TEXTURE; params.colorArg2 = TEX_MIX_ARG_FACTOR; - params.alphaOperation = TEX_MIX_OPER_DEFAULT; // TODO: replace with src color ? + params.alphaOperation = TEX_MIX_OPER_DEFAULT; params.factor = color; m_device->SetTextureEnabled(0, true); @@ -1957,7 +1966,7 @@ void CEngine::SetState(int state, const Color& color) params.colorOperation = TEX_MIX_OPER_ADD; params.colorArg1 = TEX_MIX_ARG_TEXTURE; params.colorArg2 = TEX_MIX_ARG_FACTOR; - params.alphaOperation = TEX_MIX_OPER_DEFAULT; // TODO: replace with src color ? + params.alphaOperation = TEX_MIX_OPER_DEFAULT; params.factor = color.Inverse(); m_device->SetTextureEnabled(0, true); @@ -1997,7 +2006,7 @@ void CEngine::SetState(int state, const Color& color) TextureStageParams params; params.colorOperation = TEX_MIX_OPER_REPLACE; params.colorArg1 = TEX_MIX_ARG_TEXTURE; - params.alphaOperation = TEX_MIX_OPER_DEFAULT; // TODO: replace with src color ? + params.alphaOperation = TEX_MIX_OPER_DEFAULT; m_device->SetTextureEnabled(0, true); m_device->SetTextureStageParams(0, params); @@ -2065,7 +2074,7 @@ void CEngine::SetState(int state, const Color& color) TextureStageParams params; params.colorOperation = TEX_MIX_OPER_DEFAULT; // default modulate - params.alphaOperation = TEX_MIX_OPER_DEFAULT; // TODO: replace with src color ? + params.alphaOperation = TEX_MIX_OPER_DEFAULT; m_device->SetTextureEnabled(0, true); m_device->SetTextureStageParams(0, params); @@ -2086,7 +2095,7 @@ void CEngine::SetState(int state, const Color& color) params.colorOperation = TEX_MIX_OPER_MODULATE; params.colorArg1 = TEX_MIX_ARG_TEXTURE; params.colorArg2 = TEX_MIX_ARG_COMPUTED_COLOR; - params.alphaOperation = TEX_MIX_OPER_DEFAULT; // TODO: ??? + params.alphaOperation = TEX_MIX_OPER_DEFAULT; m_device->SetTextureEnabled(1, true); m_device->SetTextureStageParams(1, params); } @@ -2096,7 +2105,7 @@ void CEngine::SetState(int state, const Color& color) params.colorOperation = TEX_MIX_OPER_ADD; params.colorArg1 = TEX_MIX_ARG_TEXTURE; params.colorArg2 = TEX_MIX_ARG_COMPUTED_COLOR; - params.alphaOperation = TEX_MIX_OPER_DEFAULT; // TODO: ??? + params.alphaOperation = TEX_MIX_OPER_DEFAULT; m_device->SetTextureEnabled(1, true); m_device->SetTextureStageParams(1, params); } @@ -4033,11 +4042,6 @@ void CEngine::DrawOverColor() SetState(m_overMode); - // TODO: set also with m_overMode ? - m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, false); - m_device->SetRenderState(RENDER_STATE_LIGHTING, false); - m_device->SetRenderState(RENDER_STATE_FOG, false); - m_device->SetTransform(TRANSFORM_VIEW, m_matViewInterface); m_device->SetTransform(TRANSFORM_PROJECTION, m_matProjInterface); m_device->SetTransform(TRANSFORM_WORLD, m_matWorldInterface); diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index 27f0173..d127e74 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -692,12 +692,6 @@ public: //! Writes a screenshot containing the current frame bool WriteScreenShot(const std::string& fileName, int width, int height); - - //! Reads settings from INI - bool ReadSettings(); - //! Writes settings to INI - bool WriteSettings(); - //@{ //! Management of game pause mode void SetPause(bool pause); diff --git a/src/graphics/engine/water.cpp b/src/graphics/engine/water.cpp index 18811eb..6c822b3 100644 --- a/src/graphics/engine/water.cpp +++ b/src/graphics/engine/water.cpp @@ -386,9 +386,11 @@ void CWater::DrawSurf() Math::Vector p = pos; p.x += size*(m_lines[i].len-1); float radius = sqrtf(powf(size, 2.0f)+powf(size*m_lines[i].len, 2.0f)); - if ( Math::Distance(p, eye) > deep+radius ) continue; + if (Math::Distance(p, eye) > deep + radius) + continue; - // TODO: ComputeSphereVisibility + if (device->ComputeSphereVisibility(p, radius) != Gfx::FRUSTUM_PLANE_ALL) + continue; int vertexIndex = 0; diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index 94b0dbc..a6ba1eb 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -929,27 +929,25 @@ void CGLDevice::DrawPrimitive(PrimitiveType type, const VertexCol *vertices, int bool InPlane(Math::Vector normal, float originPlane, Math::Vector center, float radius) { - float distance = (originPlane + Math::DotProduct(normal, center)) / normal.Length(); + float distance = originPlane + Math::DotProduct(normal, center); if (distance < -radius) - return true; + return false; - return false; + return true; } -/* - The implementation of ComputeSphereVisibility is taken from libwine's device.c - Copyright of the WINE team, licensed under GNU LGPL v 2.1 - */ +/* Based on libwine's implementation */ -// TODO: testing int CGLDevice::ComputeSphereVisibility(const Math::Vector ¢er, float radius) { Math::Matrix m; - m.LoadIdentity(); - m = Math::MultiplyMatrices(m, m_worldMat); - m = Math::MultiplyMatrices(m, m_viewMat); - m = Math::MultiplyMatrices(m, m_projectionMat); + m = Math::MultiplyMatrices(m_worldMat, m); + m = Math::MultiplyMatrices(m_viewMat, m); + Math::Matrix sc; + Math::LoadScaleMatrix(sc, Math::Vector(1.0f, 1.0f, -1.0f)); + m = Math::MultiplyMatrices(sc, m); + m = Math::MultiplyMatrices(m_projectionMat, m); Math::Vector vec[6]; float originPlane[6]; @@ -958,52 +956,64 @@ int CGLDevice::ComputeSphereVisibility(const Math::Vector ¢er, float radius) vec[0].x = m.Get(4, 1) + m.Get(1, 1); vec[0].y = m.Get(4, 2) + m.Get(1, 2); vec[0].z = m.Get(4, 3) + m.Get(1, 3); - originPlane[0] = m.Get(4, 4) + m.Get(1, 4); + float l1 = vec[0].Length(); + vec[0].Normalize(); + originPlane[0] = (m.Get(4, 4) + m.Get(1, 4)) / l1; // Right plane vec[1].x = m.Get(4, 1) - m.Get(1, 1); vec[1].y = m.Get(4, 2) - m.Get(1, 2); vec[1].z = m.Get(4, 3) - m.Get(1, 3); - originPlane[1] = m.Get(4, 4) - m.Get(1, 4); - - // Top plane - vec[2].x = m.Get(4, 1) - m.Get(2, 1); - vec[2].y = m.Get(4, 2) - m.Get(2, 2); - vec[2].z = m.Get(4, 3) - m.Get(2, 3); - originPlane[2] = m.Get(4, 4) - m.Get(2, 4); + float l2 = vec[1].Length(); + vec[1].Normalize(); + originPlane[1] = (m.Get(4, 4) - m.Get(1, 4)) / l2; // Bottom plane - vec[3].x = m.Get(4, 1) + m.Get(2, 1); - vec[3].y = m.Get(4, 2) + m.Get(2, 2); - vec[3].z = m.Get(4, 3) + m.Get(2, 3); - originPlane[3] = m.Get(4, 4) + m.Get(2, 4); + vec[2].x = m.Get(4, 1) + m.Get(2, 1); + vec[2].y = m.Get(4, 2) + m.Get(2, 2); + vec[2].z = m.Get(4, 3) + m.Get(2, 3); + float l3 = vec[2].Length(); + vec[2].Normalize(); + originPlane[2] = (m.Get(4, 4) + m.Get(2, 4)) / l3; + + // Top plane + vec[3].x = m.Get(4, 1) - m.Get(2, 1); + vec[3].y = m.Get(4, 2) - m.Get(2, 2); + vec[3].z = m.Get(4, 3) - m.Get(2, 3); + float l4 = vec[3].Length(); + vec[3].Normalize(); + originPlane[3] = (m.Get(4, 4) - m.Get(2, 4)) / l4; // Front plane - vec[4].x = m.Get(3, 1); - vec[4].y = m.Get(3, 2); - vec[4].z = m.Get(3, 3); - originPlane[4] = m.Get(3, 4); + vec[4].x = m.Get(4, 1) + m.Get(3, 1); + vec[4].y = m.Get(4, 2) + m.Get(3, 2); + vec[4].z = m.Get(4, 3) + m.Get(3, 3); + float l5 = vec[4].Length(); + vec[4].Normalize(); + originPlane[4] = (m.Get(4, 4) + m.Get(3, 4)) / l5; // Back plane vec[5].x = m.Get(4, 1) - m.Get(3, 1); vec[5].y = m.Get(4, 2) - m.Get(3, 2); vec[5].z = m.Get(4, 3) - m.Get(3, 3); - originPlane[5] = m.Get(4, 4) - m.Get(3, 4); + float l6 = vec[5].Length(); + vec[5].Normalize(); + originPlane[5] = (m.Get(4, 4) - m.Get(3, 4)) / l6; int result = 0; if (InPlane(vec[0], originPlane[0], center, radius)) - result |= INTERSECT_PLANE_LEFT; + result |= FRUSTUM_PLANE_LEFT; if (InPlane(vec[1], originPlane[1], center, radius)) - result |= INTERSECT_PLANE_RIGHT; + result |= FRUSTUM_PLANE_RIGHT; if (InPlane(vec[2], originPlane[2], center, radius)) - result |= INTERSECT_PLANE_TOP; + result |= FRUSTUM_PLANE_BOTTOM; if (InPlane(vec[3], originPlane[3], center, radius)) - result |= INTERSECT_PLANE_BOTTOM; + result |= FRUSTUM_PLANE_TOP; if (InPlane(vec[4], originPlane[4], center, radius)) - result |= INTERSECT_PLANE_FRONT; + result |= FRUSTUM_PLANE_FRONT; if (InPlane(vec[5], originPlane[5], center, radius)) - result |= INTERSECT_PLANE_BACK; + result |= FRUSTUM_PLANE_BACK; return result; } diff --git a/src/graphics/opengl/test/light_test.cpp b/src/graphics/opengl/test/light_test.cpp index 6ff3b1c..b19ba4b 100644 --- a/src/graphics/opengl/test/light_test.cpp +++ b/src/graphics/opengl/test/light_test.cpp @@ -51,7 +51,7 @@ void Render(Gfx::CGLDevice *device) device->SetRenderState(Gfx::RENDER_STATE_CULLING, false); // Double-sided drawing Math::Matrix persp; - Math::LoadProjectionMatrix(persp, Math::PI / 4.0f, (800.0f) / (600.0f), 0.1f, 100.0f); + Math::LoadProjectionMatrix(persp, Math::PI / 4.0f, (800.0f) / (600.0f), 0.1f, 50.0f); device->SetTransform(Gfx::TRANSFORM_PROJECTION, persp); @@ -121,6 +121,31 @@ void Render(Gfx::CGLDevice *device) Math::LoadTranslationMatrix(worldMat, Math::Vector(-40.0f, 2.0f, -40.0f)); device->SetTransform(Gfx::TRANSFORM_WORLD, worldMat); + int planes = device->ComputeSphereVisibility(Math::Vector(0.0f, 0.0f, 0.0f), 1.0f); + printf("Planes:"); + if (planes == 0) + printf(" (none)"); + + if (planes & Gfx::FRUSTUM_PLANE_LEFT) + printf(" LEFT"); + + if (planes & Gfx::FRUSTUM_PLANE_RIGHT) + printf(" RIGHT"); + + if (planes & Gfx::FRUSTUM_PLANE_BOTTOM) + printf(" BOTTOM"); + + if (planes & Gfx::FRUSTUM_PLANE_TOP) + printf(" TOP"); + + if (planes & Gfx::FRUSTUM_PLANE_FRONT) + printf(" FRONT"); + + if (planes & Gfx::FRUSTUM_PLANE_BACK) + printf(" BACK"); + + printf("\n"); + device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, quad, 4); for (int i = 0; i < 6; ++i) diff --git a/src/graphics/opengl/test/texture_test.cpp b/src/graphics/opengl/test/texture_test.cpp index 534a5c0..d771927 100644 --- a/src/graphics/opengl/test/texture_test.cpp +++ b/src/graphics/opengl/test/texture_test.cpp @@ -13,7 +13,6 @@ void Init(Gfx::CGLDevice *device) device->SetShadeModel(Gfx::SHADE_SMOOTH); device->SetRenderState(Gfx::RENDER_STATE_DEPTH_TEST, false); - device->SetRenderState(Gfx::RENDER_STATE_TEXTURING, true); device->SetTextureEnabled(0, true); device->SetTextureEnabled(1, true); -- cgit v1.2.3-1-g7c22 From 3845efbbffe6afefcc2bb0c1bf0e64dabcd702e3 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Thu, 25 Oct 2012 20:27:40 +0200 Subject: Main loop enhancement Frame updates were posted one frame behind in event queue --- src/app/app.cpp | 26 ++++++++++++++------------ src/app/app.h | 5 ++--- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index 81d874d..4af3870 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -829,16 +829,22 @@ int CApplication::Run() m_robotMain->EventProcess(event); } + // Prepare and process step simulation event + event = CreateUpdateEvent(); + if (event.type != EVENT_NULL && m_robotMain != nullptr) + { + m_engine->FrameUpdate(); + m_sound->FrameMove(m_relTime); + + m_robotMain->EventProcess(event); + } + /* Update mouse position explicitly right before rendering * because mouse events are usually way behind */ UpdateMouse(); - // Update game and render a frame during idle time (no messages are waiting) Render(); - // Update simulation state - StepSimulation(); - if (m_lowCPU) { usleep(20000); // should still give plenty of fps @@ -1167,10 +1173,10 @@ void CApplication::SetSimulationSpeed(float speed) GetLogger()->Info("Simulation speed = %.2f\n", speed); } -void CApplication::StepSimulation() +Event CApplication::CreateUpdateEvent() { if (m_simulationSuspended) - return; + return Event(EVENT_NULL); CopyTimeStamp(m_lastTimeStamp, m_curTimeStamp); GetCurrentTimeStamp(m_curTimeStamp); @@ -1185,11 +1191,6 @@ void CApplication::StepSimulation() m_exactRelTime = m_simulationSpeed * m_realRelTime; m_relTime = (m_simulationSpeed * m_realRelTime) / 1e9f; - - m_engine->FrameUpdate(); - m_sound->FrameMove(m_relTime); - - Event frameEvent(EVENT_FRAME); frameEvent.systemEvent = true; frameEvent.trackedKeysState = m_trackedKeys; @@ -1197,7 +1198,8 @@ void CApplication::StepSimulation() frameEvent.mousePos = m_mousePos; frameEvent.mouseButtonsState = m_mouseButtonsState; frameEvent.rTime = m_relTime; - m_eventQueue->AddEvent(frameEvent); + + return frameEvent; } float CApplication::GetSimulationSpeed() diff --git a/src/app/app.h b/src/app/app.h index 32f03f8..66b5848 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -199,9 +199,6 @@ public: //! Returns whether simulation is suspended bool GetSimulationSuspended(); - //! Updates the simulation state - void StepSimulation(); - //@{ //! Management of simulation speed void SetSimulationSpeed(float speed); @@ -312,6 +309,8 @@ protected: Event ProcessSystemEvent(); //! If applicable, creates a virtual event to match the changed state as of new event Event CreateVirtualEvent(const Event& sourceEvent); + //! Prepares a simulation update event + Event CreateUpdateEvent(); //! Handles some incoming events bool ProcessEvent(const Event& event); //! Renders the image in window -- cgit v1.2.3-1-g7c22 From 3ce488307f5394e51ff006458a8245bdbd5e6bfa Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Thu, 25 Oct 2012 23:29:49 +0200 Subject: Performance counters --- src/app/app.cpp | 77 ++++++++++++++++++++++ src/app/app.h | 40 ++++++++++++ src/graphics/engine/engine.cpp | 144 +++++++++++++++++++++++++++++++++++++---- 3 files changed, 247 insertions(+), 14 deletions(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index 4af3870..823bc77 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -122,6 +122,12 @@ CApplication::CApplication() m_curTimeStamp = CreateTimeStamp(); m_lastTimeStamp = CreateTimeStamp(); + for (int i = 0; i < PCNT_MAX; ++i) + { + m_performanceCounters[i][0] = CreateTimeStamp(); + m_performanceCounters[i][1] = CreateTimeStamp(); + } + m_joystickEnabled = false; m_mouseMode = MOUSE_SYSTEM; @@ -171,6 +177,12 @@ CApplication::~CApplication() DestroyTimeStamp(m_baseTimeStamp); DestroyTimeStamp(m_curTimeStamp); DestroyTimeStamp(m_lastTimeStamp); + + for (int i = 0; i < PCNT_MAX; ++i) + { + DestroyTimeStamp(m_performanceCounters[i][0]); + DestroyTimeStamp(m_performanceCounters[i][1]); + } } ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) @@ -718,6 +730,14 @@ int CApplication::Run() while (true) { + ResetPerformanceCounters(); + + if (m_active) + { + StartPerformanceCounter(PCNT_ALL); + StartPerformanceCounter(PCNT_EVENT_PROCESSING); + } + // To be sure no old event remains m_private->currentEvent.type = SDL_NOEVENT; @@ -829,21 +849,38 @@ int CApplication::Run() m_robotMain->EventProcess(event); } + StopPerformanceCounter(PCNT_EVENT_PROCESSING); + + StartPerformanceCounter(PCNT_UPDATE_ALL); + // Prepare and process step simulation event event = CreateUpdateEvent(); if (event.type != EVENT_NULL && m_robotMain != nullptr) { + StartPerformanceCounter(PCNT_UPDATE_ENGINE); m_engine->FrameUpdate(); + StopPerformanceCounter(PCNT_UPDATE_ENGINE); + m_sound->FrameMove(m_relTime); + StartPerformanceCounter(PCNT_UPDATE_GAME); m_robotMain->EventProcess(event); + StopPerformanceCounter(PCNT_UPDATE_GAME); } + StopPerformanceCounter(PCNT_UPDATE_ALL); + /* Update mouse position explicitly right before rendering * because mouse events are usually way behind */ UpdateMouse(); + StartPerformanceCounter(PCNT_RENDER_ALL); Render(); + StopPerformanceCounter(PCNT_RENDER_ALL); + + StopPerformanceCounter(PCNT_ALL); + + UpdatePerformanceCountersData(); if (m_lowCPU) { @@ -1451,3 +1488,43 @@ bool CApplication::GetLowCPU() { return m_lowCPU; } + +void CApplication::StartPerformanceCounter(PerformanceCounter counter) +{ + GetCurrentTimeStamp(m_performanceCounters[counter][0]); +} + +void CApplication::StopPerformanceCounter(PerformanceCounter counter) +{ + GetCurrentTimeStamp(m_performanceCounters[counter][1]); +} + +float CApplication::GetPerformanceCounterData(PerformanceCounter counter) +{ + return m_performanceCountersData[counter]; +} + +void CApplication::ResetPerformanceCounters() +{ + for (int i = 0; i < PCNT_MAX; ++i) + { + StartPerformanceCounter(static_cast(i)); + StopPerformanceCounter(static_cast(i)); + } +} + +void CApplication::UpdatePerformanceCountersData() +{ + long long sum = TimeStampExactDiff(m_performanceCounters[PCNT_ALL][0], + m_performanceCounters[PCNT_ALL][1]); + + for (int i = 0; i < PCNT_MAX; ++i) + { + long long diff = TimeStampExactDiff(m_performanceCounters[i][0], + m_performanceCounters[i][1]); + + m_performanceCountersData[static_cast(i)] = + static_cast(diff) / static_cast(sum); + } +} + diff --git a/src/app/app.h b/src/app/app.h index 66b5848..84da0eb 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -113,6 +113,31 @@ enum MouseMode MOUSE_NONE, //! < no cursor visible }; +/** + * \enum PerformanceCounter + * \brief Type of counter testing performance + */ +enum PerformanceCounter +{ + PCNT_EVENT_PROCESSING, //! < event processing (except update events) + + PCNT_UPDATE_ALL, //! < the whole frame update process + PCNT_UPDATE_ENGINE, //! < frame update in CEngine + PCNT_UPDATE_PARTICLE, //! < frame update in CParticle + PCNT_UPDATE_GAME, //! < frame update in CRobotMain + + PCNT_RENDER_ALL, //! < the whole rendering process + PCNT_RENDER_PARTICLE, //! < rendering the particles in 3D + PCNT_RENDER_WATER, //! < rendering the water + PCNT_RENDER_TERRAIN, //! < rendering the terrain + PCNT_RENDER_OBJECTS, //! < rendering the 3D objects + PCNT_RENDER_INTERFACE, //! < rendering 2D interface + + PCNT_ALL, //! < all counters together + + PCNT_MAX +}; + struct ApplicationPrivate; /** @@ -301,6 +326,13 @@ public: bool GetLowCPU(); //@} + //! Management of performance counters + //@{ + void StartPerformanceCounter(PerformanceCounter counter); + void StopPerformanceCounter(PerformanceCounter counter); + float GetPerformanceCounterData(PerformanceCounter counter); + //@} + protected: //! Creates the window's SDL_Surface bool CreateVideoSurface(); @@ -321,6 +353,11 @@ protected: //! Closes the joystick device void CloseJoystick(); + //! Resets all performance counters to zero + void ResetPerformanceCounters(); + //! Updates performance counters from gathered timer data + void UpdatePerformanceCountersData(); + protected: //! Instance manager CInstanceManager* m_iMan; @@ -363,6 +400,9 @@ protected: SystemTimeStamp* m_lastTimeStamp; SystemTimeStamp* m_curTimeStamp; + SystemTimeStamp* m_performanceCounters[PCNT_MAX][2]; + float m_performanceCountersData[PCNT_MAX]; + long long m_realAbsTimeBase; long long m_realAbsTime; long long m_realRelTime; diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index ca10304..856c2d4 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -378,7 +378,11 @@ void CEngine::FrameUpdate() float rTime = m_app->GetRelTime(); m_lightMan->UpdateProgression(rTime); + + m_app->StartPerformanceCounter(PCNT_UPDATE_PARTICLE); m_particle->FrameParticle(rTime); + m_app->StopPerformanceCounter(PCNT_UPDATE_PARTICLE); + ComputeDistance(); UpdateGeometry(); @@ -409,7 +413,7 @@ void CEngine::FrameUpdate() { m_groundMark.intensity = 0.0f; m_groundMark.phase = ENG_GR_MARK_PHASE_NULL; - m_groundMark.draw = false; + m_groundMark.draw = false; } } } @@ -3020,7 +3024,9 @@ void CEngine::Render() if (m_drawWorld) Draw3DScene(); + m_app->StartPerformanceCounter(PCNT_RENDER_INTERFACE); DrawInterface(); + m_app->StopPerformanceCounter(PCNT_RENDER_INTERFACE); // End the scene m_device->EndScene(); @@ -3051,12 +3057,13 @@ void CEngine::Draw3DScene() if (m_waterMode) m_water->DrawBack(); // draws water background + m_app->StartPerformanceCounter(PCNT_RENDER_TERRAIN); + + // Draw terrain with shadows, if shadows enabled if (m_shadowVisible) { m_lightMan->UpdateDeviceLights(ENG_OBJTYPE_TERRAIN); - // Draw the terrain - for (int l1 = 0; l1 < static_cast( m_objectTree.size() ); l1++) { EngineObjLevel1& p1 = m_objectTree[l1]; @@ -3122,7 +3129,11 @@ void CEngine::Draw3DScene() DrawShadow(); } - // Draw objects (non-terrain) + m_app->StopPerformanceCounter(PCNT_RENDER_TERRAIN); + + // Draw other objects (and if shadows disabled, also terrain) + + m_app->StartPerformanceCounter(PCNT_RENDER_OBJECTS); bool transparent = false; @@ -3274,11 +3285,21 @@ void CEngine::Draw3DScene() } } + m_app->StopPerformanceCounter(PCNT_RENDER_OBJECTS); + m_lightMan->UpdateDeviceLights(ENG_OBJTYPE_TERRAIN); - if (m_waterMode) m_water->DrawSurf(); // draws water surface + if (m_waterMode) + { + m_app->StartPerformanceCounter(PCNT_RENDER_WATER); + m_water->DrawSurf(); // draws water surface + m_app->StopPerformanceCounter(PCNT_RENDER_WATER); + } + m_app->StartPerformanceCounter(PCNT_RENDER_PARTICLE); m_particle->DrawParticle(SH_WORLD); // draws the particles of the 3D world + m_app->StopPerformanceCounter(PCNT_RENDER_PARTICLE); + m_lightning->Draw(); // draws lightning if (m_lensMode) DrawForegroundImage(); // draws the foreground @@ -4220,15 +4241,10 @@ void CEngine::DrawStats() if (!m_showStats) return; - std::stringstream str; - str << "Triangles: "; - str << m_statisticTriangle; - std::string triangleText = str.str(); - float height = m_text->GetAscent(FONT_COLOBOT, 12.0f); float width = 0.2f; - Math::Point pos(0.04f, 0.04f + height); + Math::Point pos(0.04f, 0.04f + 17 * height); SetState(ENG_RSTATE_OPAQUE_COLOR); @@ -4236,9 +4252,9 @@ void CEngine::DrawStats() VertexCol vertex[4] = { - VertexCol(Math::Vector(pos.x , pos.y - height, 0.0f), black), + VertexCol(Math::Vector(pos.x , pos.y - 17 * height, 0.0f), black), VertexCol(Math::Vector(pos.x , pos.y + height, 0.0f), black), - VertexCol(Math::Vector(pos.x + width, pos.y - height, 0.0f), black), + VertexCol(Math::Vector(pos.x + width, pos.y - 17 * height, 0.0f), black), VertexCol(Math::Vector(pos.x + width, pos.y + height, 0.0f), black) }; @@ -4246,7 +4262,107 @@ void CEngine::DrawStats() SetState(ENG_RSTATE_TEXT); - m_text->DrawText(triangleText, FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f)); + std::stringstream str; + + str.str(""); + str << "Event processing: " << std::fixed << std::setprecision(2) << m_app->GetPerformanceCounterData(PCNT_EVENT_PROCESSING); + m_text->DrawText(str.str(), FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f)); + + pos.y -= height; + pos.y -= height; + + + str.str(""); + str << "Frame update: " << std::fixed << std::setprecision(2) << m_app->GetPerformanceCounterData(PCNT_UPDATE_ALL); + m_text->DrawText(str.str(), FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f)); + + pos.y -= height; + + str.str(""); + str << "Engine update: " << std::fixed << std::setprecision(2) << m_app->GetPerformanceCounterData(PCNT_UPDATE_ENGINE); + m_text->DrawText(str.str(), FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f)); + + pos.y -= height; + + str.str(""); + str << "Particle update: " << std::fixed << std::setprecision(2) << m_app->GetPerformanceCounterData(PCNT_UPDATE_PARTICLE); + m_text->DrawText(str.str(), FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f)); + + pos.y -= height; + + str.str(""); + str << "Game update: " << std::fixed << std::setprecision(2) << m_app->GetPerformanceCounterData(PCNT_UPDATE_GAME); + m_text->DrawText(str.str(), FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f)); + + pos.y -= height; + + float otherUpdate = Math::Max(0.0f, m_app->GetPerformanceCounterData(PCNT_UPDATE_ALL) - + m_app->GetPerformanceCounterData(PCNT_UPDATE_ENGINE) - + m_app->GetPerformanceCounterData(PCNT_UPDATE_PARTICLE) - + m_app->GetPerformanceCounterData(PCNT_UPDATE_GAME)); + + str.str(""); + str << "Other update: " << std::fixed << std::setprecision(2) << otherUpdate; + m_text->DrawText(str.str(), FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f)); + + pos.y -= height; + pos.y -= height; + + + str.str(""); + str << "Frame render: " << std::fixed << std::setprecision(2) << m_app->GetPerformanceCounterData(PCNT_RENDER_ALL); + m_text->DrawText(str.str(), FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f)); + + pos.y -= height; + + str.str(""); + str << "Particle render: " << std::fixed << std::setprecision(2) << m_app->GetPerformanceCounterData(PCNT_RENDER_PARTICLE); + m_text->DrawText(str.str(), FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f)); + + pos.y -= height; + + str.str(""); + str << "Water render: " << std::fixed << std::setprecision(2) << m_app->GetPerformanceCounterData(PCNT_RENDER_WATER); + m_text->DrawText(str.str(), FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f)); + + pos.y -= height; + + str.str(""); + str << "Terrain render: " << std::fixed << std::setprecision(2) << m_app->GetPerformanceCounterData(PCNT_RENDER_TERRAIN); + m_text->DrawText(str.str(), FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f)); + + pos.y -= height; + + str.str(""); + str << "Objects render: " << std::fixed << std::setprecision(2) << m_app->GetPerformanceCounterData(PCNT_RENDER_OBJECTS); + m_text->DrawText(str.str(), FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f)); + + pos.y -= height; + + str.str(""); + str << "UI render: " << std::fixed << std::setprecision(2) << m_app->GetPerformanceCounterData(PCNT_RENDER_INTERFACE); + m_text->DrawText(str.str(), FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f)); + + pos.y -= height; + + float otherRender = m_app->GetPerformanceCounterData(PCNT_RENDER_ALL) - + m_app->GetPerformanceCounterData(PCNT_RENDER_PARTICLE) - + m_app->GetPerformanceCounterData(PCNT_RENDER_WATER) - + m_app->GetPerformanceCounterData(PCNT_RENDER_TERRAIN) - + m_app->GetPerformanceCounterData(PCNT_RENDER_OBJECTS) - + m_app->GetPerformanceCounterData(PCNT_RENDER_INTERFACE); + + str.str(""); + str << "Other render: " << std::fixed << std::setprecision(2) << otherRender; + m_text->DrawText(str.str(), FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f)); + + pos.y -= height; + pos.y -= height; + + + str.str(""); + str << "Triangles: " << m_statisticTriangle; + m_text->DrawText(str.str(), FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f)); pos.y -= height; -- cgit v1.2.3-1-g7c22 From 39ac36efda1f7c7b446886cf2508518f06e132ba Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Thu, 1 Nov 2012 22:08:18 +0100 Subject: Fixed syntax error in Blender script --- tools/blender-scripts.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/tools/blender-scripts.py b/tools/blender-scripts.py index 6591393..ed515b4 100644 --- a/tools/blender-scripts.py +++ b/tools/blender-scripts.py @@ -38,10 +38,7 @@ class ColobotVertex: return 1 def __eq__(self, other): - return fuzzy_equal_v(self.coord, other.coord) and - fuzzy_equal_v(self.normal, other.normal) and - fuzzy_equal_v(self.t1, other.t1) and - fuzzy_equal_v(self.t2, other.t2) + return fuzzy_equal_v(self.coord, other.coord) and fuzzy_equal_v(self.normal, other.normal) and fuzzy_equal_v(self.t1, other.t1) and fuzzy_equal_v(self.t2, other.t2) class ColobotMaterial: """Material as saved in Colobot model file""" @@ -56,11 +53,7 @@ class ColobotMaterial: return 1 def __eq__(self, other): - return fuzzy_equal_v(self.diffuse, other.diffuse) and - fuzzy_equal_v(self.ambient, other.ambient) and - fuzzy_equal_v(self.specular, other.specular) and - self.tex1 == other.tex1 and - self.tex2 == other.tex2 + return fuzzy_equal_v(self.diffuse, other.diffuse) and fuzzy_equal_v(self.ambient, other.ambient) and fuzzy_equal_v(self.specular, other.specular) and self.tex1 == other.tex1 and self.tex2 == other.tex2 class ColobotTriangle: """Triangle as saved in Colobot model file""" -- cgit v1.2.3-1-g7c22 From 4811defca2eeea69e40346be6b1647f276db8c76 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Fri, 14 Dec 2012 21:30:35 +0100 Subject: Static objects using OpenGL VBOs and display lists --- src/app/app.cpp | 9 ++ src/app/app.h | 2 + src/graphics/core/device.h | 17 ++- src/graphics/core/vertex.h | 20 +-- src/graphics/engine/engine.cpp | 247 ++++++++++++++++++++++++++------------ src/graphics/engine/engine.h | 18 ++- src/graphics/engine/modelfile.cpp | 10 +- src/graphics/engine/pyro.cpp | 3 + src/graphics/engine/terrain.cpp | 6 + src/graphics/opengl/gldevice.cpp | 222 ++++++++++++++++++++++++++++++++++ src/graphics/opengl/gldevice.h | 36 +++++- 11 files changed, 491 insertions(+), 99 deletions(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index 823bc77..57a827d 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -142,6 +142,8 @@ CApplication::CApplication() m_lowCPU = true; + m_useVbo = false; + for (int i = 0; i < DIR_MAX; ++i) m_dataDirs[i] = nullptr; @@ -243,6 +245,10 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) { SetDebugMode(true); } + else if (arg == "-vbo") + { + m_useVbo = true; + } else if (arg == "-loglevel") { waitLogLevel = true; @@ -262,6 +268,7 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) GetLogger()->Message("\n"); GetLogger()->Message("List of available options:\n"); GetLogger()->Message(" -help this help\n"); + GetLogger()->Message(" -vbo enable OpenGL VBOs\n"); GetLogger()->Message(" -datadir path set custom data directory path\n"); GetLogger()->Message(" -debug enable debug mode (more info printed in logs)\n"); GetLogger()->Message(" -loglevel level set log level to level (one of: trace, debug, info, warn, error, none)\n"); @@ -425,6 +432,8 @@ bool CApplication::Create() return false; } + static_cast(m_device)->SetUseVbo(m_useVbo); + // Create the 3D engine m_engine = new Gfx::CEngine(m_iMan, this); diff --git a/src/app/app.h b/src/app/app.h index 84da0eb..c4288c1 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -449,5 +449,7 @@ protected: //! Low cpu mode bool m_lowCPU; + + int m_useVbo; // TODO: temporary }; diff --git a/src/graphics/core/device.h b/src/graphics/core/device.h index 8e7d446..a0e44e4 100644 --- a/src/graphics/core/device.h +++ b/src/graphics/core/device.h @@ -313,9 +313,24 @@ public: //! Renders primitive composed of vertices with multitexturing (2 textures) virtual void DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, int vertexCount, Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) = 0; - //! Renders primitive composed of vertices with color information + //! Renders primitive composed of vertices with solid color virtual void DrawPrimitive(PrimitiveType type, const VertexCol *vertices , int vertexCount) = 0; + //! Creates a static buffer composed of given primitives with single texture vertices + virtual unsigned int CreateStaticObject(PrimitiveType primitiveType, const Vertex* vertices, int vertexCount) = 0; + + //! Creates a static buffer composed of given primitives with multitexturing (2 textures) + virtual unsigned int CreateStaticObject(PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount) = 0; + + //! Creates a static buffer composed of given primitives with solid color + virtual unsigned int CreateStaticObject(PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount) = 0; + + //! Draws a static buffer + virtual void DrawStaticObject(unsigned int objectId) = 0; + + //! Deletes a static buffer + virtual void DestroyStaticObject(unsigned int objectId) = 0; + //! Tests whether a sphere is (partially) within the frustum volume //! Returns a mask of frustum planes for which the test is positive virtual int ComputeSphereVisibility(const Math::Vector ¢er, float radius) = 0; diff --git a/src/graphics/core/vertex.h b/src/graphics/core/vertex.h index 2ee6be4..66e1503 100644 --- a/src/graphics/core/vertex.h +++ b/src/graphics/core/vertex.h @@ -44,23 +44,18 @@ namespace Gfx { * - vertex coordinates (x,y,z) as Math::Vector, * - normal coordinates (nx,ny,nz) as Math::Vector * - texture coordinates (u,v) as Math::Point. - * - * Additional padding is provided to align to even multiplies of 4 floats for faster access. */ struct Vertex { Math::Vector coord; - float pad1; Math::Vector normal; - float pad2; Math::Point texCoord; - float pad3, pad4; explicit Vertex(Math::Vector aCoord = Math::Vector(), Math::Vector aNormal = Math::Vector(), Math::Point aTexCoord = Math::Point()) - : coord(aCoord), pad1(0.0f), normal(aNormal), - pad2(0.0f),texCoord(aTexCoord), pad3(0.0f), pad4(0.0f) {} + : coord(aCoord), normal(aNormal), + texCoord(aTexCoord) {} //! Returns a string "(c: [...], n: [...], tc: [...])" @@ -81,18 +76,15 @@ struct Vertex * It contains: * - vertex coordinates (x,y,z) as Math::Vector, * - RGBA color as Color - * - * Additional padding is provided to align to even multiplies of 4 floats for faster access. */ struct VertexCol { Math::Vector coord; - float pad; Color color; explicit VertexCol(Math::Vector aCoord = Math::Vector(), Color aColor = Color()) - : coord(aCoord), pad(0.0f), color(aColor) {} + : coord(aCoord), color(aColor) {} //! Returns a string "(c: [...], col: [...])" inline std::string ToString() const @@ -111,15 +103,11 @@ struct VertexCol * * In addition to fields from Vector, it contains * secondary texture coordinates (u2, v2) as Math::Point - * - * Additional padding is provided to align to even multiplies of 4 floats for faster access. */ struct VertexTex2 { Math::Vector coord; - float pad1; Math::Vector normal; - float pad2; Math::Point texCoord; Math::Point texCoord2; @@ -127,7 +115,7 @@ struct VertexTex2 Math::Vector aNormal = Math::Vector(), Math::Point aTexCoord = Math::Point(), Math::Point aTexCoord2 = Math::Point()) - : coord(aCoord), pad1(0.0f), normal(aNormal), pad2(0.0f), + : coord(aCoord), normal(aNormal), texCoord(aTexCoord), texCoord2(aTexCoord2) {} //! Sets the fields from Vertex with texCoord2 = (0,0) diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 856c2d4..de5f2d4 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -92,6 +92,7 @@ EngineObjLevel4::EngineObjLevel4(bool used, EngineTriangleType type, const Mater this->type = type; this->material = material; this->state = state; + this->staticBufferId = 0; vertices.reserve(LEVEL4_VERTEX_PREALLOCATE_COUNT); } @@ -182,6 +183,7 @@ CEngine::CEngine(CInstanceManager *iMan, CApplication *app) m_alphaMode = 1; m_updateGeometry = false; + m_updateStaticObjects = false; m_interfaceMode = false; @@ -385,6 +387,7 @@ void CEngine::FrameUpdate() ComputeDistance(); UpdateGeometry(); + UpdateStaticObjects(); m_highlightTime = m_app->GetAbsTime(); @@ -570,11 +573,27 @@ bool CEngine::DeleteObject(int objRank) EngineObjLevel2& p2 = p1.next[l2]; if (! p2.used) continue; - if (p2.objRank == objRank) + if (p2.objRank != objRank) continue; + + if (m_objects[objRank].staticBuffer) { - p2.used = false; - p2.next.clear(); + for (int l3 = 0; l3 < static_cast( p2.next.size() ); l3++) + { + EngineObjLevel3& p3 = p2.next[l3]; + if (! p3.used) continue; + + for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) + { + EngineObjLevel4& p4 = p3.next[l4]; + + m_device->DestroyStaticObject(p4.staticBufferId); + } + } } + + + p2.used = false; + p2.next.clear(); } } @@ -623,6 +642,22 @@ bool CEngine::GetObjectTransform(int objRank, Math::Matrix& transform) return true; } +void CEngine::SetObjectStatic(int objRank, bool staticBuffer) +{ + if ( objRank < 0 || objRank >= static_cast( m_objects.size() ) ) + return; + + m_objects[objRank].staticBuffer = staticBuffer; +} + +bool CEngine::GetObjectStatic(int objRank) +{ + if ( objRank < 0 || objRank >= static_cast( m_objects.size() ) ) + return false; + + return m_objects[objRank].staticBuffer; +} + bool CEngine::SetObjectDrawWorld(int objRank, bool draw) { if ( objRank < 0 || objRank >= static_cast( m_objects.size() ) ) @@ -825,6 +860,17 @@ bool CEngine::AddTriangles(int objRank, const std::vector& vertices, p4.vertices.insert(p4.vertices.end(), vertices.begin(), vertices.end()); + if (m_objects[objRank].staticBuffer) + { + if (p4.staticBufferId != 0) + { + m_device->DestroyStaticObject(p4.staticBufferId); + p4.staticBufferId = 0; + } + + m_updateStaticObjects = true; + } + if (globalUpdate) { m_updateGeometry = true; @@ -872,6 +918,17 @@ bool CEngine::AddSurface(int objRank, const std::vector& vertices, p4.vertices.insert(p4.vertices.end(), vertices.begin(), vertices.end()); + if (m_objects[objRank].staticBuffer) + { + if (p4.staticBufferId != 0) + { + m_device->DestroyStaticObject(p4.staticBufferId); + p4.staticBufferId = 0; + } + + m_updateStaticObjects = true; + } + if (globalUpdate) { m_updateGeometry = true; @@ -898,8 +955,8 @@ bool CEngine::AddSurface(int objRank, const std::vector& vertices, } bool CEngine::AddQuick(int objRank, const EngineObjLevel4& buffer, - std::string tex1Name, std::string tex2Name, - float min, float max, bool globalUpdate) + std::string tex1Name, std::string tex2Name, + float min, float max, bool globalUpdate) { if ( objRank < 0 || objRank >= static_cast( m_objects.size() ) ) { @@ -912,7 +969,26 @@ bool CEngine::AddQuick(int objRank, const EngineObjLevel4& buffer, EngineObjLevel3& p3 = AddLevel3(p2, min, max); p3.next.push_back(buffer); - p3.next.back().used = true; // ensure that it is used + + EngineObjLevel4& p4 = p3.next.back(); + p4.used = true; // ensure that it is used + + if (m_objects[objRank].staticBuffer) + { + if (p4.staticBufferId != 0) + { + m_device->DestroyStaticObject(p4.staticBufferId); + p4.staticBufferId = 0; + } + + PrimitiveType type; + if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES) + type = PRIMITIVE_TRIANGLES; + else + type = PRIMITIVE_TRIANGLE_STRIP; + + p4.staticBufferId = m_device->CreateStaticObject(type, &p4.vertices[0], p4.vertices.size()); + } if (globalUpdate) { @@ -920,24 +996,24 @@ bool CEngine::AddQuick(int objRank, const EngineObjLevel4& buffer, } else { - for (int i = 0; i < static_cast( buffer.vertices.size() ); i++) + for (int i = 0; i < static_cast( p4.vertices.size() ); i++) { - m_objects[objRank].bboxMin.x = Math::Min(buffer.vertices[i].coord.x, m_objects[objRank].bboxMin.x); - m_objects[objRank].bboxMin.y = Math::Min(buffer.vertices[i].coord.y, m_objects[objRank].bboxMin.y); - m_objects[objRank].bboxMin.z = Math::Min(buffer.vertices[i].coord.z, m_objects[objRank].bboxMin.z); - m_objects[objRank].bboxMax.x = Math::Max(buffer.vertices[i].coord.x, m_objects[objRank].bboxMax.x); - m_objects[objRank].bboxMax.y = Math::Max(buffer.vertices[i].coord.y, m_objects[objRank].bboxMax.y); - m_objects[objRank].bboxMax.z = Math::Max(buffer.vertices[i].coord.z, m_objects[objRank].bboxMax.z); + m_objects[objRank].bboxMin.x = Math::Min(p4.vertices[i].coord.x, m_objects[objRank].bboxMin.x); + m_objects[objRank].bboxMin.y = Math::Min(p4.vertices[i].coord.y, m_objects[objRank].bboxMin.y); + m_objects[objRank].bboxMin.z = Math::Min(p4.vertices[i].coord.z, m_objects[objRank].bboxMin.z); + m_objects[objRank].bboxMax.x = Math::Max(p4.vertices[i].coord.x, m_objects[objRank].bboxMax.x); + m_objects[objRank].bboxMax.y = Math::Max(p4.vertices[i].coord.y, m_objects[objRank].bboxMax.y); + m_objects[objRank].bboxMax.z = Math::Max(p4.vertices[i].coord.z, m_objects[objRank].bboxMax.z); } m_objects[objRank].radius = Math::Max(m_objects[objRank].bboxMin.Length(), m_objects[objRank].bboxMax.Length()); } - if (buffer.type == ENG_TRIANGLE_TYPE_TRIANGLES) - m_objects[objRank].totalTriangles += buffer.vertices.size() / 3; - else if (buffer.type == ENG_TRIANGLE_TYPE_SURFACE) - m_objects[objRank].totalTriangles += buffer.vertices.size() - 2; + if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES) + m_objects[objRank].totalTriangles += p4.vertices.size() / 3; + else if (p4.type == ENG_TRIANGLE_TYPE_SURFACE) + m_objects[objRank].totalTriangles += p4.vertices.size() - 2; return true; } @@ -1735,10 +1811,57 @@ void CEngine::UpdateGeometry() m_updateGeometry = false; } +void CEngine::UpdateStaticObjects() +{ + if (!m_updateStaticObjects) + return; + + for (int l1 = 0; l1 < static_cast( m_objectTree.size() ); l1++) + { + EngineObjLevel1& p1 = m_objectTree[l1]; + if (! p1.used) continue; + + for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) + { + EngineObjLevel2& p2 = p1.next[l2]; + if (! p2.used) continue; + + int objRank = p2.objRank; + + if (!m_objects[objRank].staticBuffer) + continue; + + for (int l3 = 0; l3 < static_cast( p2.next.size() ); l3++) + { + EngineObjLevel3& p3 = p2.next[l3]; + if (! p3.used) continue; + + for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) + { + EngineObjLevel4& p4 = p3.next[l4]; + if (! p4.used) continue; + + if (p4.staticBufferId != 0) + continue; + + PrimitiveType type; + if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES) + type = PRIMITIVE_TRIANGLES; + else + type = PRIMITIVE_TRIANGLE_STRIP; + + p4.staticBufferId = m_device->CreateStaticObject(type, &p4.vertices[0], p4.vertices.size()); + } + } + } + } +} + void CEngine::Update() { ComputeDistance(); UpdateGeometry(); + UpdateStaticObjects(); } bool CEngine::DetectBBox(int objRank, Math::Point mouse) @@ -3106,20 +3229,7 @@ void CEngine::Draw3DScene() SetMaterial(p4.material); SetState(p4.state); - if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES) - { - m_device->DrawPrimitive( PRIMITIVE_TRIANGLES, - &p4.vertices[0], - p4.vertices.size() ); - m_statisticTriangle += p4.vertices.size() / 3; - } - if (p4.type == ENG_TRIANGLE_TYPE_SURFACE) - { - m_device->DrawPrimitive( PRIMITIVE_TRIANGLE_STRIP, - &p4.vertices[0], - p4.vertices.size() ); - m_statisticTriangle += p4.vertices.size() - 2; - } + DrawObject(p4, m_objects[objRank].staticBuffer); } } } @@ -3188,22 +3298,7 @@ void CEngine::Draw3DScene() SetMaterial(p4.material); SetState(p4.state); - if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES) - { - m_device->DrawPrimitive( PRIMITIVE_TRIANGLES, - &p4.vertices[0], - p4.vertices.size() ); - - m_statisticTriangle += p4.vertices.size() / 3; - } - else if (p4.type == ENG_TRIANGLE_TYPE_SURFACE) - { - m_device->DrawPrimitive( PRIMITIVE_TRIANGLE_STRIP, - &p4.vertices[0], - p4.vertices.size() ); - - m_statisticTriangle += p4.vertices.size() - 2; - } + DrawObject(p4, m_objects[objRank].staticBuffer); } } } @@ -3264,21 +3359,7 @@ void CEngine::Draw3DScene() SetMaterial(p4.material); SetState(tState, tColor); - if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES) - { - m_device->DrawPrimitive( PRIMITIVE_TRIANGLES, - &p4.vertices[0], - p4.vertices.size() ); - - m_statisticTriangle += p4.vertices.size() / 3; - } - else if (p4.type == ENG_TRIANGLE_TYPE_SURFACE) - { - m_device->DrawPrimitive( PRIMITIVE_TRIANGLE_STRIP, - &p4.vertices[0], - p4.vertices.size() ); - m_statisticTriangle += p4.vertices.size() - 2; - } + DrawObject(p4, m_objects[objRank].staticBuffer); } } } @@ -3307,6 +3388,32 @@ void CEngine::Draw3DScene() if (! m_overFront) DrawOverColor(); // draws the foreground color } +void CEngine::DrawObject(const EngineObjLevel4& obj, bool staticBuffer) +{ + if (staticBuffer) + { + m_device->DrawStaticObject(obj.staticBufferId); + + if (obj.type == ENG_TRIANGLE_TYPE_TRIANGLES) + m_statisticTriangle += obj.vertices.size() / 3; + else + m_statisticTriangle += obj.vertices.size() - 2; + } + else + { + if (obj.type == ENG_TRIANGLE_TYPE_TRIANGLES) + { + m_device->DrawPrimitive(PRIMITIVE_TRIANGLES, &obj.vertices[0], obj.vertices.size()); + m_statisticTriangle += obj.vertices.size() / 3; + } + else + { + m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, &obj.vertices[0], obj.vertices.size() ); + m_statisticTriangle += obj.vertices.size() - 2; + } + } +} + void CEngine::DrawInterface() { m_device->SetRenderState(RENDER_STATE_DEPTH_TEST, false); @@ -3397,21 +3504,7 @@ void CEngine::DrawInterface() SetMaterial(p4.material); SetState(p4.state); - if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES) - { - m_device->DrawPrimitive( PRIMITIVE_TRIANGLES, - &p4.vertices[0], - p4.vertices.size() ); - - m_statisticTriangle += p4.vertices.size() / 3; - } - else if (p4.type == ENG_TRIANGLE_TYPE_SURFACE) - { - m_device->DrawPrimitive( PRIMITIVE_TRIANGLE_STRIP, - &p4.vertices[0], - p4.vertices.size() ); - m_statisticTriangle += p4.vertices.size() - 2; - } + DrawObject(p4, m_objects[objRank].staticBuffer); } } } diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index d127e74..de57e4d 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -195,7 +195,9 @@ struct EngineObject //! Number of triangles int totalTriangles; //! Type of object - EngineObjectType type; + EngineObjectType type; + //! Whether the object is stored and rendered as static buffer + bool staticBuffer; //! Transformation matrix Math::Matrix transform; //! Distance to object from eye point @@ -225,6 +227,7 @@ struct EngineObject drawWorld = false; drawFront = false; totalTriangles = 0; + staticBuffer = false; type = ENG_OBJTYPE_NULL; transform.LoadIdentity(); bboxMax.LoadZero(); @@ -252,6 +255,7 @@ struct EngineObjLevel4 Material material; int state; std::vector vertices; + unsigned int staticBufferId; EngineObjLevel4(bool used = false, EngineTriangleType type = ENG_TRIANGLE_TYPE_TRIANGLES, @@ -760,6 +764,12 @@ public: bool GetObjectTransform(int objRank, Math::Matrix& transform); //@} + //@{ + //! Management of object static drawing flag + void SetObjectStatic(int objRank, bool staticBuffer); + bool GetObjectStatic(int objRank); + //@} + //! Sets drawWorld for given object bool SetObjectDrawWorld(int objRank, bool draw); //! Sets drawFront for given object @@ -1151,6 +1161,8 @@ public: protected: //! Prepares the interface for 3D scene void Draw3DScene(); + //! Draw 3D object + void DrawObject(const EngineObjLevel4& obj, bool staticBuffer); //! Draws the user interface over the scene void DrawInterface(); @@ -1215,6 +1227,9 @@ protected: //! Updates geometric parameters of objects (bounding box and radius) void UpdateGeometry(); + //! Updates static buffers of changed objects + void UpdateStaticObjects(); + protected: CInstanceManager* m_iMan; CApplication* m_app; @@ -1293,6 +1308,7 @@ protected: Color m_waterAddColor; int m_statisticTriangle; bool m_updateGeometry; + bool m_updateStaticObjects; int m_alphaMode; bool m_groundSpotVisible; bool m_shadowVisible; diff --git a/src/graphics/engine/modelfile.cpp b/src/graphics/engine/modelfile.cpp index 3b0343a..a9972fe 100644 --- a/src/graphics/engine/modelfile.cpp +++ b/src/graphics/engine/modelfile.cpp @@ -1157,18 +1157,24 @@ bool CModelFile::WriteBinaryModel(std::ostream& stream) #ifndef MODELFILE_NO_ENGINE + +/** + * TODO: move the function to CEngine or new class (CModelManager?) + * and make models shared static objects. + */ + bool CModelFile::CreateEngineObject(int objRank) { std::vector vs(3, VertexTex2()); + m_engine->SetObjectStatic(objRank, true); // TODO: make optional in the future + float limit[2]; limit[0] = m_engine->GetLimitLOD(0); // frontier AB as config limit[1] = m_engine->GetLimitLOD(1); // frontier BC as config for (int i = 0; i < static_cast( m_triangles.size() ); i++) { - // TODO move this to CEngine - float min = m_triangles[i].min; float max = m_triangles[i].max; diff --git a/src/graphics/engine/pyro.cpp b/src/graphics/engine/pyro.cpp index 978471b..73c5cec 100644 --- a/src/graphics/engine/pyro.cpp +++ b/src/graphics/engine/pyro.cpp @@ -363,6 +363,7 @@ bool CPyro::Create(PyroType type, CObject* obj, float force) m_type == PT_EXPLOW ) { CreateTriangle(obj, oType, 0); + m_engine->SetObjectStatic(m_object->GetObjectRank(0), false); m_engine->DeleteShadow(m_object->GetObjectRank(0)); ExploStart(); } @@ -1397,6 +1398,8 @@ void CPyro::CreateTriangle(CObject* obj, ObjectType oType, int part) int objRank = obj->GetObjectRank(part); if (objRank == -1) return; + m_engine->SetObjectStatic(objRank, false); + float min = 0.0f; float max = m_engine->GetLimitLOD(0); int total = m_engine->GetObjectTotalTriangles(objRank); diff --git a/src/graphics/engine/terrain.cpp b/src/graphics/engine/terrain.cpp index 4c22a32..0e77ea2 100644 --- a/src/graphics/engine/terrain.cpp +++ b/src/graphics/engine/terrain.cpp @@ -478,6 +478,8 @@ VertexTex2 CTerrain::GetVertex(int x, int y, int step) v.texCoord.x = (o.x-oo.x)*m_textureScale*m_textureSubdivCount; v.texCoord.y = 1.0f - (o.z-oo.z)*m_textureScale*m_textureSubdivCount; + v.texCoord2 = v.texCoord; + return v; } @@ -1166,6 +1168,10 @@ bool CTerrain::CreateSquare(int x, int y) int objRank = m_engine->CreateObject(); m_engine->SetObjectType(objRank, ENG_OBJTYPE_TERRAIN); + // TODO: create a static object, but not split into squares, but a single object for all terrain + // Squares should be sub-objects accessing parts of triangle list + // m_engine->SetObjectStatic(objRank, true); + m_objRanks[x+y*m_mosaicCount] = objRank; float min = 0.0f; diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index a6ba1eb..2d284d0 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -73,6 +73,8 @@ CGLDevice::CGLDevice(const GLDeviceConfig &config) { m_config = config; m_lighting = false; + m_lastVboId = 0; + m_useVbo = false; } @@ -109,6 +111,16 @@ bool CGLDevice::Create() GetLogger()->Error("GLEW reports required extensions not supported\n"); return false; } + + if (GLEW_ARB_vertex_buffer_object) + { + GetLogger()->Info("Detected ARB_vertex_buffer_object extension - using VBOs\n"); + m_useVbo = true; + } + else + { + GetLogger()->Info("No ARB_vertex_buffer_object extension present - using display lists\n"); + } } #endif @@ -174,6 +186,16 @@ void CGLDevice::ConfigChanged(const GLDeviceConfig& newConfig) Create(); } +void CGLDevice::SetUseVbo(bool useVbo) +{ + m_useVbo = useVbo; +} + +bool CGLDevice::GetUseVbo() +{ + return m_useVbo; +} + void CGLDevice::BeginScene() { Clear(); @@ -927,6 +949,206 @@ void CGLDevice::DrawPrimitive(PrimitiveType type, const VertexCol *vertices, int glDisableClientState(GL_COLOR_ARRAY); } +unsigned int CGLDevice::CreateStaticObject(PrimitiveType primitiveType, const Vertex* vertices, int vertexCount) +{ + unsigned int id = 0; + if (m_useVbo) + { + id = ++m_lastVboId; + + VboObjectInfo info; + info.primitiveType = primitiveType; + info.vertexType = VERTEX_TYPE_NORMAL; + info.vertexCount = vertexCount; + info.bufferId = 0; + + glGenBuffers(1, &info.bufferId); + glBindBuffer(GL_ARRAY_BUFFER, info.bufferId); + glBufferData(GL_ARRAY_BUFFER, vertexCount * sizeof(Vertex), vertices, GL_STATIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); + + m_vboObjects[id] = info; + } + else + { + id = glGenLists(1); + + glNewList(id, GL_COMPILE); + + DrawPrimitive(primitiveType, vertices, vertexCount); + + glEndList(); + } + + return id; +} + +unsigned int CGLDevice::CreateStaticObject(PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount) +{ + unsigned int id = 0; + if (m_useVbo) + { + id = ++m_lastVboId; + + VboObjectInfo info; + info.primitiveType = primitiveType; + info.vertexType = VERTEX_TYPE_TEX2; + info.vertexCount = vertexCount; + info.bufferId = 0; + + glGenBuffers(1, &info.bufferId); + glBindBuffer(GL_ARRAY_BUFFER, info.bufferId); + glBufferData(GL_ARRAY_BUFFER, vertexCount * sizeof(VertexTex2), vertices, GL_STATIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); + + m_vboObjects[id] = info; + } + else + { + id = glGenLists(1); + + glNewList(id, GL_COMPILE); + + DrawPrimitive(primitiveType, vertices, vertexCount); + + glEndList(); + } + + return id; +} + +unsigned int CGLDevice::CreateStaticObject(PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount) +{ + unsigned int id = 0; + if (m_useVbo) + { + id = ++m_lastVboId; + + VboObjectInfo info; + info.primitiveType = primitiveType; + info.vertexType = VERTEX_TYPE_COL; + info.vertexCount = vertexCount; + info.bufferId = 0; + + glGenBuffers(1, &info.bufferId); + glBindBuffer(GL_ARRAY_BUFFER, info.bufferId); + glBufferData(GL_ARRAY_BUFFER, vertexCount * sizeof(VertexCol), vertices, GL_STATIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); + + m_vboObjects[id] = info; + } + else + { + id = glGenLists(1); + + glNewList(id, GL_COMPILE); + + DrawPrimitive(primitiveType, vertices, vertexCount); + + glEndList(); + } + + return id; +} + +void CGLDevice::DrawStaticObject(unsigned int objectId) +{ + if (m_useVbo) + { + auto it = m_vboObjects.find(objectId); + if (it == m_vboObjects.end()) + return; + + glEnable(GL_VERTEX_ARRAY); + glBindBuffer(GL_ARRAY_BUFFER, (*it).second.bufferId); + + if ((*it).second.vertexType == VERTEX_TYPE_NORMAL) + { + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(3, GL_FLOAT, sizeof(Vertex), static_cast(nullptr) + offsetof(Vertex, coord)); + + glEnableClientState(GL_NORMAL_ARRAY); + glNormalPointer(GL_FLOAT, sizeof(Vertex), static_cast(nullptr) + offsetof(Vertex, normal)); + + glActiveTexture(GL_TEXTURE0); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), static_cast(nullptr) + offsetof(Vertex, texCoord)); + } + else if ((*it).second.vertexType == VERTEX_TYPE_TEX2) + { + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(3, GL_FLOAT, sizeof(VertexTex2), static_cast(nullptr) + offsetof(VertexTex2, coord)); + + glEnableClientState(GL_NORMAL_ARRAY); + glNormalPointer(GL_FLOAT, sizeof(VertexTex2), static_cast(nullptr) + offsetof(VertexTex2, normal)); + + glClientActiveTexture(GL_TEXTURE0); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glTexCoordPointer(2, GL_FLOAT, sizeof(VertexTex2), static_cast(nullptr) + offsetof(VertexTex2, texCoord)); + + glClientActiveTexture(GL_TEXTURE1); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glTexCoordPointer(2, GL_FLOAT, sizeof(VertexTex2), static_cast(nullptr) + offsetof(VertexTex2, texCoord2)); + } + else if ((*it).second.vertexType == VERTEX_TYPE_COL) + { + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(3, GL_FLOAT, sizeof(VertexCol), static_cast(nullptr) + offsetof(VertexCol, coord)); + + glEnableClientState(GL_COLOR_ARRAY); + glColorPointer(4, GL_FLOAT, sizeof(VertexCol), static_cast(nullptr) + offsetof(VertexCol, color)); + } + + GLenum mode = TranslateGfxPrimitive((*it).second.primitiveType); + glDrawArrays(GL_TRIANGLES, 0, (*it).second.vertexCount); + + if ((*it).second.vertexType == VERTEX_TYPE_NORMAL) + { + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_NORMAL_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); // GL_TEXTURE0 + } + else if ((*it).second.vertexType == VERTEX_TYPE_TEX2) + { + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_NORMAL_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); // GL_TEXTURE1 + glClientActiveTexture(GL_TEXTURE0); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + } + else if ((*it).second.vertexType == VERTEX_TYPE_COL) + { + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + } + + glBindBuffer(GL_ARRAY_BUFFER, 0); + glDisable(GL_VERTEX_ARRAY); + } + else + { + glCallList(objectId); + } +} + +void CGLDevice::DestroyStaticObject(unsigned int objectId) +{ + if (m_useVbo) + { + auto it = m_vboObjects.find(objectId); + if (it == m_vboObjects.end()) + return; + + glDeleteBuffers(1, &(*it).second.bufferId); + + m_vboObjects.erase(it); + } + else + { + glDeleteLists(objectId, 1); + } +} + bool InPlane(Math::Vector normal, float originPlane, Math::Vector center, float radius) { float distance = originPlane + Math::DotProduct(normal, center); diff --git a/src/graphics/opengl/gldevice.h b/src/graphics/opengl/gldevice.h index 87c1247..adae41b 100644 --- a/src/graphics/opengl/gldevice.h +++ b/src/graphics/opengl/gldevice.h @@ -27,6 +27,7 @@ #include #include #include +#include // Graphics module namespace @@ -84,6 +85,9 @@ public: void ConfigChanged(const GLDeviceConfig &newConfig); + void SetUseVbo(bool useVbo); + bool GetUseVbo(); + virtual void BeginScene(); virtual void EndScene(); @@ -119,14 +123,18 @@ public: virtual void SetTextureStageWrap(int index, Gfx::TexWrapMode wrapS, Gfx::TexWrapMode wrapT); - //! Renders primitive composed of vertices with single texture virtual void DrawPrimitive(PrimitiveType type, const Vertex *vertices , int vertexCount, Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)); - //! Renders primitive composed of vertices with multitexturing (2 textures) virtual void DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, int vertexCount, Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)); virtual void DrawPrimitive(PrimitiveType type, const VertexCol *vertices , int vertexCount); + virtual unsigned int CreateStaticObject(PrimitiveType primitiveType, const Vertex* vertices, int vertexCount); + virtual unsigned int CreateStaticObject(PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount); + virtual unsigned int CreateStaticObject(PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount); + virtual void DrawStaticObject(unsigned int objectId); + virtual void DestroyStaticObject(unsigned int objectId); + virtual int ComputeSphereVisibility(const Math::Vector ¢er, float radius); virtual void SetRenderState(RenderState state, bool enabled); @@ -200,6 +208,30 @@ private: //! Set of all created textures std::set m_allTextures; + + //! Type of vertex structure + enum VertexType + { + VERTEX_TYPE_NORMAL, + VERTEX_TYPE_TEX2, + VERTEX_TYPE_COL, + }; + + //! Info about static VBO buffers + struct VboObjectInfo + { + PrimitiveType primitiveType; + unsigned int bufferId; + VertexType vertexType; + int vertexCount; + }; + + //! Whether to use VBOs or display lists + bool m_useVbo; + //! Map of saved VBO objects + std::map m_vboObjects; + //! Last ID of VBO object + unsigned int m_lastVboId; }; -- cgit v1.2.3-1-g7c22 From 1703319159f08e98adc029b9592dc7a84659f63d Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Sun, 16 Dec 2012 11:38:36 +0100 Subject: Emit info message for GTest source. --- CMakeLists.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7090d2d..33fb882 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -128,8 +128,12 @@ endif() if(${TESTS}) # Google Test library - set(GTEST_DIR "${colobot_SOURCE_DIR}/lib/gtest") - add_subdirectory(lib/gtest bin/test) + find_path(GTEST_SRC_DIR NAMES src/gtest.cc src/gtest-all.cc PATHS /usr/src/ PATH_SUFFIXES gtest) + if(NOT GTEST_SRC_DIR) + set(GTEST_SRC_DIR lib/gtest) + endif(NOT GTEST_SRC_DIR) + message(STATUS "Use Google Test from ${GTEST_SRC_DIR}") + add_subdirectory(${GTEST_SRC_DIR} bin/test) endif() # Subdirectory with sources -- cgit v1.2.3-1-g7c22 From e127f5b631c5579adab47510b962f5ea0027eebc Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Sun, 16 Dec 2012 11:38:36 +0100 Subject: Use system GMock and GTest if they are available - Drop library addition to upstream GTest. - Fallback to convenience copy if the system libraries are not installed. --- CMakeLists.txt | 18 +++++++++++++++--- lib/gtest/CMakeLists.txt | 1 - 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 33fb882..b625cd2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -127,13 +127,25 @@ endif() ## if(${TESTS}) + # Google Mock + find_path(GMOCK_INCLUDE_DIR NAMES gmock.h PATH_SUFFIXES gmock) + find_path(GMOCK_SRC_DIR NAMES src/gmock-all.cc PATHS /usr/src/ PATH_SUFFIXES gmock) # Google Test library find_path(GTEST_SRC_DIR NAMES src/gtest.cc src/gtest-all.cc PATHS /usr/src/ PATH_SUFFIXES gtest) - if(NOT GTEST_SRC_DIR) + if(GTEST_SRC_DIR AND GMOCK_INCLUDE_DIR AND GMOCK_SRC_DIR) + include_directories(${GMOCK_SRC_DIR}) + else(GTEST_SRC_DIR AND GMOCK_INCLUDE_DIR AND GMOCK_SRC_DIR) set(GTEST_SRC_DIR lib/gtest) - endif(NOT GTEST_SRC_DIR) - message(STATUS "Use Google Test from ${GTEST_SRC_DIR}") + set(GMOCK_SRC_DIR ${GTEST_SRC_DIR}) + set(GMOCK_INCLUDE_DIR ${GTEST_SRC_DIR}/include/gmock) + include_directories(${GTEST_SRC_DIR} ${GTEST_SRC_DIR}/include/) + endif(GTEST_SRC_DIR AND GMOCK_INCLUDE_DIR AND GMOCK_SRC_DIR) + + add_library(gmock STATIC ${GMOCK_SRC_DIR}/src/gmock-all.cc) add_subdirectory(${GTEST_SRC_DIR} bin/test) + + message(STATUS "Use Google Mock from ${GMOCK_SRC_DIR}") + message(STATUS "Use Google Test from ${GTEST_SRC_DIR}") endif() # Subdirectory with sources diff --git a/lib/gtest/CMakeLists.txt b/lib/gtest/CMakeLists.txt index 61813ae..1279f7d 100644 --- a/lib/gtest/CMakeLists.txt +++ b/lib/gtest/CMakeLists.txt @@ -7,4 +7,3 @@ add_definitions(-DGTEST_HAS_PTHREAD=0) # gtest-all.cc includes all other sources add_library(gtest STATIC src/gtest-all.cc) -add_library(gmock STATIC src/gmock-all.cc) -- cgit v1.2.3-1-g7c22 From f9f15a2f3f80f968a64e76141b1e6fa5e28c7232 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 16 Dec 2012 13:33:05 +0100 Subject: Revert "Merge pull request #88 from OdyX/dev-graphics-system-gtools" This reverts commit f5b4705cad6c7071a24912b81987a488a8cef0f7, reversing changes made to 4811defca2eeea69e40346be6b1647f276db8c76. --- CMakeLists.txt | 20 ++------------------ lib/gtest/CMakeLists.txt | 1 + 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b625cd2..7090d2d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -127,25 +127,9 @@ endif() ## if(${TESTS}) - # Google Mock - find_path(GMOCK_INCLUDE_DIR NAMES gmock.h PATH_SUFFIXES gmock) - find_path(GMOCK_SRC_DIR NAMES src/gmock-all.cc PATHS /usr/src/ PATH_SUFFIXES gmock) # Google Test library - find_path(GTEST_SRC_DIR NAMES src/gtest.cc src/gtest-all.cc PATHS /usr/src/ PATH_SUFFIXES gtest) - if(GTEST_SRC_DIR AND GMOCK_INCLUDE_DIR AND GMOCK_SRC_DIR) - include_directories(${GMOCK_SRC_DIR}) - else(GTEST_SRC_DIR AND GMOCK_INCLUDE_DIR AND GMOCK_SRC_DIR) - set(GTEST_SRC_DIR lib/gtest) - set(GMOCK_SRC_DIR ${GTEST_SRC_DIR}) - set(GMOCK_INCLUDE_DIR ${GTEST_SRC_DIR}/include/gmock) - include_directories(${GTEST_SRC_DIR} ${GTEST_SRC_DIR}/include/) - endif(GTEST_SRC_DIR AND GMOCK_INCLUDE_DIR AND GMOCK_SRC_DIR) - - add_library(gmock STATIC ${GMOCK_SRC_DIR}/src/gmock-all.cc) - add_subdirectory(${GTEST_SRC_DIR} bin/test) - - message(STATUS "Use Google Mock from ${GMOCK_SRC_DIR}") - message(STATUS "Use Google Test from ${GTEST_SRC_DIR}") + set(GTEST_DIR "${colobot_SOURCE_DIR}/lib/gtest") + add_subdirectory(lib/gtest bin/test) endif() # Subdirectory with sources diff --git a/lib/gtest/CMakeLists.txt b/lib/gtest/CMakeLists.txt index 1279f7d..61813ae 100644 --- a/lib/gtest/CMakeLists.txt +++ b/lib/gtest/CMakeLists.txt @@ -7,3 +7,4 @@ add_definitions(-DGTEST_HAS_PTHREAD=0) # gtest-all.cc includes all other sources add_library(gtest STATIC src/gtest-all.cc) +add_library(gmock STATIC src/gmock-all.cc) -- cgit v1.2.3-1-g7c22 From 5574eccebd16ae38a2a21ed202d1f9d1ba8f67a4 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Wed, 26 Dec 2012 20:58:02 +0100 Subject: Engine optimization - rewritten model management - new class CModelManager - rewritten engine object structure in CEngine - created shared model data instead of separate objects per each model instance - minor refactoring --- src/CMakeLists.txt | 1 + src/app/app.cpp | 19 +- src/app/app.h | 10 +- src/graphics/core/device.h | 21 +- src/graphics/engine/engine.cpp | 1758 +++++++++++++-------------- src/graphics/engine/engine.h | 341 +++--- src/graphics/engine/modelfile.cpp | 136 +-- src/graphics/engine/modelfile.h | 27 +- src/graphics/engine/modelmanager.cpp | 213 ++++ src/graphics/engine/modelmanager.h | 97 ++ src/graphics/engine/pyro.cpp | 3 - src/graphics/engine/terrain.cpp | 29 +- src/graphics/engine/terrain.h | 2 +- src/graphics/engine/test/CMakeLists.txt | 1 - src/graphics/engine/test/modelfile_test.cpp | 12 +- src/graphics/opengl/gldevice.cpp | 99 +- src/graphics/opengl/gldevice.h | 13 +- src/object/motion/motionant.cpp | 123 +- src/object/motion/motionbee.cpp | 83 +- src/object/motion/motionhuman.cpp | 120 +- src/object/motion/motionmother.cpp | 74 +- src/object/motion/motionspider.cpp | 36 +- src/object/motion/motiontoto.cpp | 39 +- src/object/motion/motionvehicle.cpp | 482 +++----- src/object/motion/motionworm.cpp | 20 +- src/object/object.cpp | 698 ++++------- src/object/robotmain.cpp | 4 +- src/script/script.cpp | 26 +- src/tools/CMakeLists.txt | 1 - src/tools/convert_model.cpp | 21 +- 30 files changed, 2116 insertions(+), 2393 deletions(-) create mode 100644 src/graphics/engine/modelmanager.cpp create mode 100644 src/graphics/engine/modelmanager.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 56a384e..eaf404a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -61,6 +61,7 @@ graphics/engine/engine.cpp graphics/engine/lightman.cpp graphics/engine/lightning.cpp graphics/engine/modelfile.cpp +graphics/engine/modelmanager.cpp graphics/engine/particle.cpp graphics/engine/planet.cpp graphics/engine/pyro.cpp diff --git a/src/app/app.cpp b/src/app/app.cpp index 57a827d..9f1667b 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -25,6 +25,7 @@ #include "common/image.h" #include "common/key.h" +#include "graphics/engine/modelmanager.h" #include "graphics/opengl/gldevice.h" #include "object/robotmain.h" @@ -94,6 +95,7 @@ CApplication::CApplication() m_engine = nullptr; m_device = nullptr; + m_modelManager = nullptr; m_robotMain = nullptr; m_sound = nullptr; @@ -142,8 +144,6 @@ CApplication::CApplication() m_lowCPU = true; - m_useVbo = false; - for (int i = 0; i < DIR_MAX; ++i) m_dataDirs[i] = nullptr; @@ -245,10 +245,6 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) { SetDebugMode(true); } - else if (arg == "-vbo") - { - m_useVbo = true; - } else if (arg == "-loglevel") { waitLogLevel = true; @@ -432,8 +428,6 @@ bool CApplication::Create() return false; } - static_cast(m_device)->SetUseVbo(m_useVbo); - // Create the 3D engine m_engine = new Gfx::CEngine(m_iMan, this); @@ -446,6 +440,9 @@ bool CApplication::Create() return false; } + // Create model manager + m_modelManager = new Gfx::CModelManager(m_engine); + // Create the robot application. m_robotMain = new CRobotMain(m_iMan, this); @@ -525,6 +522,12 @@ void CApplication::Destroy() m_sound = nullptr; } + if (m_modelManager != nullptr) + { + delete m_modelManager; + m_modelManager = nullptr; + } + if (m_engine != nullptr) { m_engine->Destroy(); diff --git a/src/app/app.h b/src/app/app.h index c4288c1..d8f6206 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -42,6 +42,10 @@ class CEventQueue; class CRobotMain; class CSoundInterface; +namespace Gfx { +class CModelManager; +} + /** * \struct JoystickDevice * \brief Information about a joystick device @@ -369,11 +373,15 @@ protected: Gfx::CEngine* m_engine; //! Graphics device Gfx::CDevice* m_device; + //! 3D models manager + Gfx::CModelManager* m_modelManager; //! Sound subsystem CSoundInterface* m_sound; //! Main class of the proper game engine CRobotMain* m_robotMain; + //! Plugin manager CPluginManager* m_pluginManager; + //! Profile (INI) reader/writer CProfile* m_profile; //! Code to return at exit @@ -449,7 +457,5 @@ protected: //! Low cpu mode bool m_lowCPU; - - int m_useVbo; // TODO: temporary }; diff --git a/src/graphics/core/device.h b/src/graphics/core/device.h index a0e44e4..618d21a 100644 --- a/src/graphics/core/device.h +++ b/src/graphics/core/device.h @@ -317,19 +317,28 @@ public: virtual void DrawPrimitive(PrimitiveType type, const VertexCol *vertices , int vertexCount) = 0; //! Creates a static buffer composed of given primitives with single texture vertices - virtual unsigned int CreateStaticObject(PrimitiveType primitiveType, const Vertex* vertices, int vertexCount) = 0; + virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const Vertex* vertices, int vertexCount) = 0; - //! Creates a static buffer composed of given primitives with multitexturing (2 textures) - virtual unsigned int CreateStaticObject(PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount) = 0; + //! Creates a static buffer composed of given primitives with multitexturing + virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount) = 0; //! Creates a static buffer composed of given primitives with solid color - virtual unsigned int CreateStaticObject(PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount) = 0; + virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount) = 0; + + //! Updates the static buffer composed of given primitives with single texture vertices + virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const Vertex* vertices, int vertexCount) = 0; + + //! Updates the static buffer composed of given primitives with multitexturing + virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount) = 0; + + //! Updates the static buffer composed of given primitives with solid color + virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount) = 0; //! Draws a static buffer - virtual void DrawStaticObject(unsigned int objectId) = 0; + virtual void DrawStaticBuffer(unsigned int bufferId) = 0; //! Deletes a static buffer - virtual void DestroyStaticObject(unsigned int objectId) = 0; + virtual void DestroyStaticBuffer(unsigned int bufferId) = 0; //! Tests whether a sphere is (partially) within the frustum volume //! Returns a mask of frustum planes for which the test is positive diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index de5f2d4..73cd73a 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -47,56 +47,6 @@ // Graphics module namespace namespace Gfx { - -// Initial size of various vectors -const int OBJECT_PREALLOCATE_COUNT = 1200; -const int SHADOW_PREALLOCATE_COUNT = 500; -const int GROUNDSPOT_PREALLOCATE_COUNT = 100; - -const int LEVEL1_PREALLOCATE_COUNT = 50; -const int LEVEL2_PREALLOCATE_COUNT = 100; -const int LEVEL3_PREALLOCATE_COUNT = 5; -const int LEVEL4_PREALLOCATE_COUNT = 100; -const int LEVEL4_VERTEX_PREALLOCATE_COUNT = 200; - - -EngineObjLevel1::EngineObjLevel1(bool used, const std::string& tex1Name, const std::string& tex2Name) -{ - this->used = used; - this->tex1Name = tex1Name; - this->tex2Name = tex2Name; - - next.reserve(LEVEL2_PREALLOCATE_COUNT); -} - -EngineObjLevel2::EngineObjLevel2(bool used, int objRank) -{ - this->used = used; - this->objRank = objRank; - - next.reserve(LEVEL3_PREALLOCATE_COUNT); -} - -EngineObjLevel3::EngineObjLevel3(bool used, float min, float max) -{ - this->used = used; - this->min = min; - this->max = max; - - next.reserve(LEVEL4_PREALLOCATE_COUNT); -} - -EngineObjLevel4::EngineObjLevel4(bool used, EngineTriangleType type, const Material& material, int state) -{ - this->used = used; - this->type = type; - this->material = material; - this->state = state; - this->staticBufferId = 0; - - vertices.reserve(LEVEL4_VERTEX_PREALLOCATE_COUNT); -} - CEngine::CEngine(CInstanceManager *iMan, CApplication *app) { m_iMan = iMan; @@ -183,7 +133,7 @@ CEngine::CEngine(CInstanceManager *iMan, CApplication *app) m_alphaMode = 1; m_updateGeometry = false; - m_updateStaticObjects = false; + m_updateStaticBuffers = false; m_interfaceMode = false; @@ -220,11 +170,6 @@ CEngine::CEngine(CInstanceManager *iMan, CApplication *app) m_terrainTexParams.mipmap = false; m_terrainTexParams.minFilter = TEX_MIN_FILTER_LINEAR; m_terrainTexParams.magFilter = TEX_MAG_FILTER_LINEAR; - - m_objectTree.reserve(LEVEL1_PREALLOCATE_COUNT); - m_objects.reserve(OBJECT_PREALLOCATE_COUNT); - m_shadows.reserve(SHADOW_PREALLOCATE_COUNT); - m_groundSpots.reserve(GROUNDSPOT_PREALLOCATE_COUNT); } CEngine::~CEngine() @@ -387,7 +332,7 @@ void CEngine::FrameUpdate() ComputeDistance(); UpdateGeometry(); - UpdateStaticObjects(); + UpdateStaticBuffers(); m_highlightTime = m_app->GetAbsTime(); @@ -495,7 +440,7 @@ Math::Point CEngine::WindowToInterfaceSize(Math::IntPoint size) Math::IntPoint CEngine::InterfaceToWindowSize(Math::Point size) { return Math::IntPoint(static_cast(size.x * m_size.x), - static_cast(size.y * m_size.y)); + static_cast(size.y * m_size.y)); } void CEngine::AddStatisticTriangle(int count) @@ -514,263 +459,40 @@ int CEngine::GetStatisticTriangle() Object management *******************************************************/ - - -int CEngine::CreateObject() -{ - int i = 0; - for ( ; i < static_cast( m_objects.size() ); i++) - { - if (! m_objects[i].used) - { - m_objects[i].LoadDefault(); - break; - } - } - - if (i == static_cast( m_objects.size() )) - m_objects.push_back(EngineObject()); - - - m_objects[i].used = true; - - Math::Matrix mat; - mat.LoadIdentity(); - SetObjectTransform(i, mat); - - m_objects[i].drawWorld = true; - m_objects[i].distance = 0.0f; - m_objects[i].bboxMin = Math::Vector(0.0f, 0.0f, 0.0f); - m_objects[i].bboxMax = Math::Vector(0.0f, 0.0f, 0.0f); - m_objects[i].shadowRank = -1; - - return i; -} - -void CEngine::FlushObject() -{ - m_objectTree.clear(); - m_objects.clear(); - - m_shadows.clear(); - - FlushGroundSpot(); -} - -bool CEngine::DeleteObject(int objRank) -{ - if ( objRank < 0 || objRank >= static_cast( m_objects.size() ) ) - return false; - - // Delete object's triangles - for (int l1 = 0; l1 < static_cast( m_objectTree.size() ); l1++) - { - EngineObjLevel1& p1 = m_objectTree[l1]; - if (! p1.used) continue; - - for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) - { - EngineObjLevel2& p2 = p1.next[l2]; - if (! p2.used) continue; - - if (p2.objRank != objRank) continue; - - if (m_objects[objRank].staticBuffer) - { - for (int l3 = 0; l3 < static_cast( p2.next.size() ); l3++) - { - EngineObjLevel3& p3 = p2.next[l3]; - if (! p3.used) continue; - - for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) - { - EngineObjLevel4& p4 = p3.next[l4]; - - m_device->DestroyStaticObject(p4.staticBufferId); - } - } - } - - - p2.used = false; - p2.next.clear(); - } - } - - // Mark object as deleted - m_objects[objRank].used = false; - - // Delete associated shadows - DeleteShadow(objRank); - - return true; -} - -bool CEngine::SetObjectType(int objRank, EngineObjectType type) -{ - if ( objRank < 0 || objRank >= static_cast( m_objects.size() ) ) - return false; - - m_objects[objRank].type = type; - return true; -} - -EngineObjectType CEngine::GetObjectType(int objRank) -{ - if ( objRank < 0 || objRank >= static_cast( m_objects.size() ) ) - return ENG_OBJTYPE_NULL; - - return m_objects[objRank].type; -} - - -bool CEngine::SetObjectTransform(int objRank, const Math::Matrix& transform) -{ - if ( objRank < 0 || objRank >= static_cast( m_objects.size() ) ) - return false; - - m_objects[objRank].transform = transform; - return true; -} - -bool CEngine::GetObjectTransform(int objRank, Math::Matrix& transform) -{ - if ( objRank < 0 || objRank >= static_cast( m_objects.size() ) ) - return false; - - transform = m_objects[objRank].transform; - return true; -} - -void CEngine::SetObjectStatic(int objRank, bool staticBuffer) -{ - if ( objRank < 0 || objRank >= static_cast( m_objects.size() ) ) - return; - - m_objects[objRank].staticBuffer = staticBuffer; -} - -bool CEngine::GetObjectStatic(int objRank) -{ - if ( objRank < 0 || objRank >= static_cast( m_objects.size() ) ) - return false; - - return m_objects[objRank].staticBuffer; -} - -bool CEngine::SetObjectDrawWorld(int objRank, bool draw) -{ - if ( objRank < 0 || objRank >= static_cast( m_objects.size() ) ) - return false; - - m_objects[objRank].drawWorld = draw; - return true; -} - -bool CEngine::SetObjectDrawFront(int objRank, bool draw) -{ - if ( objRank < 0 || objRank >= static_cast( m_objects.size() ) ) - return false; - - m_objects[objRank].drawFront = draw; - return true; -} - -bool CEngine::SetObjectTransparency(int objRank, float value) -{ - if ( objRank < 0 || objRank >= static_cast( m_objects.size() ) ) - return false; - - m_objects[objRank].transparency = value; - return true; -} - -bool CEngine::GetObjectBBox(int objRank, Math::Vector& min, Math::Vector& max) -{ - if ( objRank < 0 || objRank >= static_cast( m_objects.size() ) ) - return 0; - - min = m_objects[objRank].bboxMin; - max = m_objects[objRank].bboxMax; - return true; -} - - -int CEngine::GetObjectTotalTriangles(int objRank) -{ - if ( objRank < 0 || objRank >= static_cast( m_objects.size() ) ) - return 0; - - return m_objects[objRank].totalTriangles; -} - - -EngineObjLevel1& CEngine::AddLevel1(const std::string& tex1Name, const std::string& tex2Name) -{ - bool unusedPresent = false; - for (int i = 0; i < static_cast( m_objectTree.size() ); i++) - { - if (! m_objectTree[i].used) - { - unusedPresent = true; - continue; - } - - if (m_objectTree[i].tex1Name == tex1Name && m_objectTree[i].tex2Name == tex2Name) - return m_objectTree[i]; - } - - if (unusedPresent) - { - for (int i = 0; i < static_cast( m_objectTree.size() ); i++) - { - if (! m_objectTree[i].used) - { - m_objectTree[i].used = true; - m_objectTree[i].tex1Name = tex1Name; - m_objectTree[i].tex2Name = tex2Name; - return m_objectTree[i]; - } - } - } - - m_objectTree.push_back(EngineObjLevel1(true, tex1Name, tex2Name)); - return m_objectTree.back(); -} - -EngineObjLevel2& CEngine::AddLevel2(EngineObjLevel1& p1, int objRank) +EngineBaseObjTexTier& CEngine::AddLevel2(int baseObjRank, const std::string& tex1Name, const std::string& tex2Name) { bool unusedPresent = false; - for (int i = 0; i < static_cast( p1.next.size() ); i++) + for (int i = 0; i < static_cast( m_baseObjects[baseObjRank].next.size() ); i++) { - if (! p1.next[i].used) + if (! m_baseObjects[baseObjRank].next[i].used) { unusedPresent = true; continue; } - if (p1.next[i].objRank == objRank) - return p1.next[i]; + if (m_baseObjects[baseObjRank].next[i].tex1Name == tex1Name && m_baseObjects[baseObjRank].next[i].tex2Name == tex2Name) + return m_baseObjects[baseObjRank].next[i]; } if (unusedPresent) { - for (int i = 0; i < static_cast( p1.next.size() ); i++) + for (int i = 0; i < static_cast( m_baseObjects[baseObjRank].next.size() ); i++) { - if (! p1.next[i].used) + if (! m_baseObjects[baseObjRank].next[i].used) { - p1.next[i].used = true; - p1.next[i].objRank = objRank; - return p1.next[i]; + m_baseObjects[baseObjRank].next[i].used = true; + m_baseObjects[baseObjRank].next[i].tex1Name = tex1Name; + m_baseObjects[baseObjRank].next[i].tex2Name = tex2Name; + return m_baseObjects[baseObjRank].next[i]; } } } - p1.next.push_back(EngineObjLevel2(true, objRank)); - return p1.next.back(); + m_baseObjects[baseObjRank].next.push_back(EngineBaseObjTexTier(true, tex1Name, tex2Name)); + return m_baseObjects[baseObjRank].next.back(); } -EngineObjLevel3& CEngine::AddLevel3(EngineObjLevel2& p2, float min, float max) +EngineBaseObjLODTier& CEngine::AddLevel3(EngineBaseObjTexTier& p2, float min, float max) { bool unusedPresent = false; for (int i = 0; i < static_cast( p2.next.size() ); i++) @@ -799,12 +521,12 @@ EngineObjLevel3& CEngine::AddLevel3(EngineObjLevel2& p2, float min, float max) } } - p2.next.push_back(EngineObjLevel3(true, min, max)); + p2.next.push_back(EngineBaseObjLODTier(true, min, max)); return p2.next.back(); } -EngineObjLevel4& CEngine::AddLevel4(EngineObjLevel3& p3, EngineTriangleType type, - const Material& material, int state) +EngineBaseObjDataTier& CEngine::AddLevel4(EngineBaseObjLODTier& p3, EngineTriangleType type, + const Material& material, int state) { bool unusedPresent = false; for (int i = 0; i < static_cast( p3.next.size() ); i++) @@ -834,100 +556,96 @@ EngineObjLevel4& CEngine::AddLevel4(EngineObjLevel3& p3, EngineTriangleType type } } - p3.next.push_back(EngineObjLevel4(true, type, material, state)); + p3.next.push_back(EngineBaseObjDataTier(true, type, material, state)); return p3.next.back(); } -bool CEngine::AddTriangles(int objRank, const std::vector& vertices, - const Material& material, int state, - std::string tex1Name, std::string tex2Name, - float min, float max, bool globalUpdate) +int CEngine::CreateBaseObject() { - if ( objRank < 0 || objRank >= static_cast( m_objects.size() ) ) + int i = 0; + for ( ; i < static_cast( m_baseObjects.size() ); i++) { - GetLogger()->Error("AddTriangle(): invalid object rank %d\n", objRank); - return false; + if (! m_baseObjects[i].used) + { + m_baseObjects[i].LoadDefault(); + break; + } } - m_lastSize = m_size; - m_lastObjectDetail = m_objectDetail; - m_lastClippingDistance = m_clippingDistance; + if (i == static_cast( m_baseObjects.size() )) + m_baseObjects.push_back(EngineBaseObject()); + else + m_baseObjects[i].LoadDefault(); - EngineObjLevel1& p1 = AddLevel1(tex1Name, tex2Name); - EngineObjLevel2& p2 = AddLevel2(p1, objRank); - EngineObjLevel3& p3 = AddLevel3(p2, min, max); - EngineObjLevel4& p4 = AddLevel4(p3, ENG_TRIANGLE_TYPE_TRIANGLES, material, state); - p4.vertices.insert(p4.vertices.end(), vertices.begin(), vertices.end()); + m_baseObjects[i].used = true; - if (m_objects[objRank].staticBuffer) - { - if (p4.staticBufferId != 0) - { - m_device->DestroyStaticObject(p4.staticBufferId); - p4.staticBufferId = 0; - } + return i; +} - m_updateStaticObjects = true; - } +void CEngine::DeleteBaseObject(int baseObjRank) +{ + assert(baseObjRank < -1 || baseObjRank >= static_cast( m_baseObjects.size() )); - if (globalUpdate) - { - m_updateGeometry = true; - } - else + for (int l2 = 0; l2 < static_cast( m_baseObjects[baseObjRank].next.size() ); l2++) { - for (int i = 0; i < static_cast( vertices.size() ); i++) + EngineBaseObjTexTier& p2 = m_baseObjects[baseObjRank].next[l2]; + if (! p2.used) + continue; + + for (int l3 = 0; l3 < static_cast( p2.next.size() ); l3++) { - m_objects[objRank].bboxMin.x = Math::Min(vertices[i].coord.x, m_objects[objRank].bboxMin.x); - m_objects[objRank].bboxMin.y = Math::Min(vertices[i].coord.y, m_objects[objRank].bboxMin.y); - m_objects[objRank].bboxMin.z = Math::Min(vertices[i].coord.z, m_objects[objRank].bboxMin.z); - m_objects[objRank].bboxMax.x = Math::Max(vertices[i].coord.x, m_objects[objRank].bboxMax.x); - m_objects[objRank].bboxMax.y = Math::Max(vertices[i].coord.y, m_objects[objRank].bboxMax.y); - m_objects[objRank].bboxMax.z = Math::Max(vertices[i].coord.z, m_objects[objRank].bboxMax.z); + EngineBaseObjLODTier& p3 = p2.next[l3]; + if (! p3.used) + continue; + + for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) + { + EngineBaseObjDataTier& p4 = p3.next[l4]; + + m_device->DestroyStaticBuffer(p4.staticBufferId); + p4.staticBufferId = 0; + } } - m_objects[objRank].radius = Math::Max(m_objects[objRank].bboxMin.Length(), - m_objects[objRank].bboxMax.Length()); + p2.used = false; + p2.next.clear(); } +} + +void CEngine::DeleteAllBaseObjects() +{ + m_baseObjects.clear(); +} - m_objects[objRank].totalTriangles += vertices.size() / 3; +void CEngine::CopyBaseObject(int sourceBaseObjRank, int destBaseObjRank) +{ + assert(sourceBaseObjRank >= 0 && sourceBaseObjRank < static_cast( m_baseObjects.size() )); + assert(destBaseObjRank >= 0 && destBaseObjRank < static_cast( m_baseObjects.size() )); - return true; + m_baseObjects[destBaseObjRank] = m_baseObjects[sourceBaseObjRank]; } -bool CEngine::AddSurface(int objRank, const std::vector& vertices, - const Material& material, int state, - std::string tex1Name, std::string tex2Name, - float min, float max, bool globalUpdate) +void CEngine::AddBaseObjTriangles(int baseObjRank, const std::vector& vertices, + EngineTriangleType triangleType, + const Material& material, int state, + std::string tex1Name, std::string tex2Name, + float min, float max, bool globalUpdate) { - if ( objRank < 0 || objRank >= static_cast( m_objects.size() ) ) - { - GetLogger()->Error("AddSurface(): invalid object rank %d\n", objRank); - return false; - } + assert(baseObjRank >= 0 && baseObjRank < static_cast( m_baseObjects.size() )); m_lastSize = m_size; m_lastObjectDetail = m_objectDetail; m_lastClippingDistance = m_clippingDistance; - EngineObjLevel1& p1 = AddLevel1(tex1Name, tex2Name); - EngineObjLevel2& p2 = AddLevel2(p1, objRank); - EngineObjLevel3& p3 = AddLevel3(p2, min, max); - EngineObjLevel4& p4 = AddLevel4(p3, ENG_TRIANGLE_TYPE_SURFACE, material, state); + EngineBaseObjTexTier& p2 = AddLevel2(baseObjRank, tex1Name, tex2Name); + EngineBaseObjLODTier& p3 = AddLevel3(p2, min, max); + EngineBaseObjDataTier& p4 = AddLevel4(p3, triangleType, material, state); p4.vertices.insert(p4.vertices.end(), vertices.begin(), vertices.end()); - if (m_objects[objRank].staticBuffer) - { - if (p4.staticBufferId != 0) - { - m_device->DestroyStaticObject(p4.staticBufferId); - p4.staticBufferId = 0; - } - - m_updateStaticObjects = true; - } + p4.updateStaticBuffer = true; + m_updateStaticBuffers = true; if (globalUpdate) { @@ -937,58 +655,41 @@ bool CEngine::AddSurface(int objRank, const std::vector& vertices, { for (int i = 0; i < static_cast( vertices.size() ); i++) { - m_objects[objRank].bboxMin.x = Math::Min(vertices[i].coord.x, m_objects[objRank].bboxMin.x); - m_objects[objRank].bboxMin.y = Math::Min(vertices[i].coord.y, m_objects[objRank].bboxMin.y); - m_objects[objRank].bboxMin.z = Math::Min(vertices[i].coord.z, m_objects[objRank].bboxMin.z); - m_objects[objRank].bboxMax.x = Math::Max(vertices[i].coord.x, m_objects[objRank].bboxMax.x); - m_objects[objRank].bboxMax.y = Math::Max(vertices[i].coord.y, m_objects[objRank].bboxMax.y); - m_objects[objRank].bboxMax.z = Math::Max(vertices[i].coord.z, m_objects[objRank].bboxMax.z); + m_baseObjects[baseObjRank].bboxMin.x = Math::Min(vertices[i].coord.x, m_baseObjects[baseObjRank].bboxMin.x); + m_baseObjects[baseObjRank].bboxMin.y = Math::Min(vertices[i].coord.y, m_baseObjects[baseObjRank].bboxMin.y); + m_baseObjects[baseObjRank].bboxMin.z = Math::Min(vertices[i].coord.z, m_baseObjects[baseObjRank].bboxMin.z); + m_baseObjects[baseObjRank].bboxMax.x = Math::Max(vertices[i].coord.x, m_baseObjects[baseObjRank].bboxMax.x); + m_baseObjects[baseObjRank].bboxMax.y = Math::Max(vertices[i].coord.y, m_baseObjects[baseObjRank].bboxMax.y); + m_baseObjects[baseObjRank].bboxMax.z = Math::Max(vertices[i].coord.z, m_baseObjects[baseObjRank].bboxMax.z); } - m_objects[objRank].radius = Math::Max(m_objects[objRank].bboxMin.Length(), - m_objects[objRank].bboxMax.Length()); + m_baseObjects[baseObjRank].radius = Math::Max(m_baseObjects[baseObjRank].bboxMin.Length(), + m_baseObjects[baseObjRank].bboxMax.Length()); } - m_objects[objRank].totalTriangles += vertices.size() - 2; - - return true; + if (triangleType == ENG_TRIANGLE_TYPE_TRIANGLES) + m_baseObjects[baseObjRank].totalTriangles += vertices.size() / 3; + else + m_baseObjects[baseObjRank].totalTriangles += vertices.size() - 2; } -bool CEngine::AddQuick(int objRank, const EngineObjLevel4& buffer, - std::string tex1Name, std::string tex2Name, - float min, float max, bool globalUpdate) +void CEngine::AddBaseObjQuick(int baseObjRank, const EngineBaseObjDataTier& buffer, + std::string tex1Name, std::string tex2Name, + float min, float max, bool globalUpdate) { - if ( objRank < 0 || objRank >= static_cast( m_objects.size() ) ) - { - GetLogger()->Error("AddQuick(): invalid object rank %d\n", objRank); - return false; - } + assert(baseObjRank >= 0 && baseObjRank < static_cast( m_baseObjects.size() )); - EngineObjLevel1& p1 = AddLevel1(tex1Name, tex2Name); - EngineObjLevel2& p2 = AddLevel2(p1, objRank); - EngineObjLevel3& p3 = AddLevel3(p2, min, max); + EngineBaseObjTexTier& p2 = AddLevel2(baseObjRank, tex1Name, tex2Name); + EngineBaseObjLODTier& p3 = AddLevel3(p2, min, max); p3.next.push_back(buffer); - EngineObjLevel4& p4 = p3.next.back(); - p4.used = true; // ensure that it is used - - if (m_objects[objRank].staticBuffer) - { - if (p4.staticBufferId != 0) - { - m_device->DestroyStaticObject(p4.staticBufferId); - p4.staticBufferId = 0; - } + EngineBaseObjDataTier& p4 = p3.next.back(); - PrimitiveType type; - if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES) - type = PRIMITIVE_TRIANGLES; - else - type = PRIMITIVE_TRIANGLE_STRIP; + p4.used = true; - p4.staticBufferId = m_device->CreateStaticObject(type, &p4.vertices[0], p4.vertices.size()); - } + p4.updateStaticBuffer = true; + m_updateStaticBuffers = true; if (globalUpdate) { @@ -998,68 +699,197 @@ bool CEngine::AddQuick(int objRank, const EngineObjLevel4& buffer, { for (int i = 0; i < static_cast( p4.vertices.size() ); i++) { - m_objects[objRank].bboxMin.x = Math::Min(p4.vertices[i].coord.x, m_objects[objRank].bboxMin.x); - m_objects[objRank].bboxMin.y = Math::Min(p4.vertices[i].coord.y, m_objects[objRank].bboxMin.y); - m_objects[objRank].bboxMin.z = Math::Min(p4.vertices[i].coord.z, m_objects[objRank].bboxMin.z); - m_objects[objRank].bboxMax.x = Math::Max(p4.vertices[i].coord.x, m_objects[objRank].bboxMax.x); - m_objects[objRank].bboxMax.y = Math::Max(p4.vertices[i].coord.y, m_objects[objRank].bboxMax.y); - m_objects[objRank].bboxMax.z = Math::Max(p4.vertices[i].coord.z, m_objects[objRank].bboxMax.z); + m_baseObjects[baseObjRank].bboxMin.x = Math::Min(p4.vertices[i].coord.x, m_baseObjects[baseObjRank].bboxMin.x); + m_baseObjects[baseObjRank].bboxMin.y = Math::Min(p4.vertices[i].coord.y, m_baseObjects[baseObjRank].bboxMin.y); + m_baseObjects[baseObjRank].bboxMin.z = Math::Min(p4.vertices[i].coord.z, m_baseObjects[baseObjRank].bboxMin.z); + m_baseObjects[baseObjRank].bboxMax.x = Math::Max(p4.vertices[i].coord.x, m_baseObjects[baseObjRank].bboxMax.x); + m_baseObjects[baseObjRank].bboxMax.y = Math::Max(p4.vertices[i].coord.y, m_baseObjects[baseObjRank].bboxMax.y); + m_baseObjects[baseObjRank].bboxMax.z = Math::Max(p4.vertices[i].coord.z, m_baseObjects[baseObjRank].bboxMax.z); } - m_objects[objRank].radius = Math::Max(m_objects[objRank].bboxMin.Length(), - m_objects[objRank].bboxMax.Length()); + m_baseObjects[baseObjRank].radius = Math::Max(m_baseObjects[baseObjRank].bboxMin.Length(), + m_baseObjects[baseObjRank].bboxMax.Length()); } if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES) - m_objects[objRank].totalTriangles += p4.vertices.size() / 3; + m_baseObjects[baseObjRank].totalTriangles += p4.vertices.size() / 3; else if (p4.type == ENG_TRIANGLE_TYPE_SURFACE) - m_objects[objRank].totalTriangles += p4.vertices.size() - 2; - - return true; + m_baseObjects[baseObjRank].totalTriangles += p4.vertices.size() - 2; } -EngineObjLevel4* CEngine::FindTriangles(int objRank, const Material& material, - int state, std::string tex1Name, - std::string tex2Name, float min, float max) + +int CEngine::CreateObject() { - if ( objRank < 0 || objRank >= static_cast( m_objects.size() ) ) + int i = 0; + for ( ; i < static_cast( m_objects.size() ); i++) { - GetLogger()->Error("FindTriangles(): invalid object rank %d\n", objRank); - return nullptr; + if (! m_objects[i].used) + { + m_objects[i].LoadDefault(); + break; + } } - for (int l1 = 0; l1 < static_cast( m_objectTree.size() ); l1++) + if (i == static_cast( m_objects.size() )) + m_objects.push_back(EngineObject()); + + + m_objects[i].used = true; + + Math::Matrix mat; + mat.LoadIdentity(); + SetObjectTransform(i, mat); + + m_objects[i].drawWorld = true; + m_objects[i].distance = 0.0f; + m_objects[i].shadowRank = -1; + + return i; +} + +void CEngine::DeleteAllObjects() +{ + m_objects.clear(); + m_shadows.clear(); + + DeleteAllGroundSpots(); +} + +void CEngine::DeleteObject(int objRank) +{ + assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); + + // Mark object as deleted + m_objects[objRank].used = false; + + // Delete associated shadows + DeleteShadow(objRank); +} + +void CEngine::SetObjectBaseRank(int objRank, int baseObjRank) +{ + assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); + + m_objects[objRank].baseObjRank = baseObjRank; +} + +int CEngine::GetObjectBaseRank(int objRank) +{ + assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); + + return m_objects[objRank].baseObjRank; +} + +void CEngine::SetObjectType(int objRank, EngineObjectType type) +{ + assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); + + m_objects[objRank].type = type; +} + +EngineObjectType CEngine::GetObjectType(int objRank) +{ + assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); + + return m_objects[objRank].type; +} + + +void CEngine::SetObjectTransform(int objRank, const Math::Matrix& transform) +{ + assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); + + m_objects[objRank].transform = transform; +} + +void CEngine::GetObjectTransform(int objRank, Math::Matrix& transform) +{ + assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); + + transform = m_objects[objRank].transform; +} + +void CEngine::SetObjectDrawWorld(int objRank, bool draw) +{ + assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); + + m_objects[objRank].drawWorld = draw; +} + +void CEngine::SetObjectDrawFront(int objRank, bool draw) +{ + assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); + + m_objects[objRank].drawFront = draw; +} + +void CEngine::SetObjectTransparency(int objRank, float value) +{ + assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); + + m_objects[objRank].transparency = value; +} + +void CEngine::GetObjectBBox(int objRank, Math::Vector& min, Math::Vector& max) +{ + assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); + + int baseObjRank = m_objects[objRank].baseObjRank; + assert(baseObjRank >= 0 && baseObjRank < static_cast(m_baseObjects.size())); + + min = m_baseObjects[baseObjRank].bboxMin; + max = m_baseObjects[baseObjRank].bboxMax; +} + + +int CEngine::GetObjectTotalTriangles(int objRank) +{ + assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); + + int baseObjRank = m_objects[objRank].baseObjRank; + assert(baseObjRank >= 0 && baseObjRank < static_cast( m_baseObjects.size() )); + + return m_baseObjects[baseObjRank].totalTriangles; +} + +EngineBaseObjDataTier* CEngine::FindTriangles(int objRank, const Material& material, + int state, std::string tex1Name, + std::string tex2Name, float min, float max) +{ + assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); + + int baseObjRank = m_objects[objRank].baseObjRank; + assert(baseObjRank >= 0 && baseObjRank < static_cast( m_baseObjects.size() )); + + for (int l2 = 0; l2 < static_cast( m_baseObjects[baseObjRank].next.size() ); l2++) { - EngineObjLevel1& p1 = m_objectTree[l1]; - if (! p1.used) continue; + EngineBaseObjTexTier& p2 = m_baseObjects[baseObjRank].next[l2]; + if (! p2.used) + continue; - if (p1.tex1Name != tex1Name) continue; + if (p2.tex1Name != tex1Name) + continue; - for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) + for (int l3 = 0; l3 < static_cast( p2.next.size() ); l3++) { - EngineObjLevel2& p2 = p1.next[l2]; - if (! p2.used) continue; + EngineBaseObjLODTier& p3 = p2.next[l3]; + if (! p3.used) + continue; - if (p2.objRank != objRank) continue; + if (p3.min != min || p3.max != max) + continue; - for (int l3 = 0; l3 < static_cast( p2.next.size() ); l3++) + for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) { - EngineObjLevel3& p3 = p2.next[l3]; - if (! p3.used) continue; - - if (p3.min != min || p3.max != max) continue; - - for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) - { - EngineObjLevel4& p4 = p3.next[l4]; - if (! p4.used) continue; + EngineBaseObjDataTier& p4 = p3.next[l4]; + if (! p4.used) + continue; - if ( (p4.state & (~(ENG_RSTATE_DUAL_BLACK|ENG_RSTATE_DUAL_WHITE))) != state || - p4.material != material ) - continue; + if ( (p4.state & (~(ENG_RSTATE_DUAL_BLACK|ENG_RSTATE_DUAL_WHITE))) != state || + p4.material != material ) + continue; - return &p4; - } + return &p4; } } } @@ -1068,91 +898,86 @@ EngineObjLevel4* CEngine::FindTriangles(int objRank, const Material& material, } int CEngine::GetPartialTriangles(int objRank, float min, float max, float percent, int maxCount, - std::vector& triangles) + std::vector& triangles) { - if ( objRank < 0 || objRank >= static_cast( m_objects.size() ) ) - { - GetLogger()->Error("GetPartialTriangles(): invalid object rank %d\n", objRank); - return 0; - } + assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); - int total = m_objects[objRank].totalTriangles; + int baseObjRank = m_objects[objRank].baseObjRank; + assert(baseObjRank >= 0 && baseObjRank < static_cast( m_baseObjects.size() )); + + int total = m_baseObjects[baseObjRank].totalTriangles; int expectedCount = static_cast(percent * total); triangles.reserve(Math::Min(maxCount, expectedCount)); int actualCount = 0; - for (int l1 = 0; l1 < static_cast( m_objectTree.size() ); l1++) + for (int l2 = 0; l2 < static_cast( m_baseObjects[baseObjRank].next.size() ); l2++) { - EngineObjLevel1& p1 = m_objectTree[l1]; - if (! p1.used) continue; + EngineBaseObjTexTier& p2 = m_baseObjects[baseObjRank].next[l2]; + if (! p2.used) + continue; - for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) + for (int l3 = 0; l3 < static_cast( p2.next.size() ); l3++) { - EngineObjLevel2& p2 = p1.next[l2]; - if (! p2.used) continue; + EngineBaseObjLODTier& p3 = p2.next[l3]; + if (! p3.used) + continue; - if (p2.objRank != objRank) continue; + if (p3.min != min || p3.max != max) + continue; - for (int l3 = 0; l3 < static_cast( p2.next.size() ); l3++) + for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) { - EngineObjLevel3& p3 = p2.next[l3]; - if (! p3.used) continue; - - if (p3.min != min || p3.max != max) continue; + EngineBaseObjDataTier& p4 = p3.next[l4]; + if (! p4.used) + continue; - for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) + if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES) { - EngineObjLevel4& p4 = p3.next[l4]; - if (! p4.used) continue; - - if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES) + for (int i = 0; i < static_cast( p4.vertices.size() ); i += 3) { - for (int i = 0; i < static_cast( p4.vertices.size() ); i += 3) - { - if (static_cast(actualCount) / total >= percent) - break; + if (static_cast(actualCount) / total >= percent) + break; - if (actualCount >= maxCount) - break; + if (actualCount >= maxCount) + break; - EngineTriangle t; - t.triangle[0] = p4.vertices[i]; - t.triangle[1] = p4.vertices[i+1]; - t.triangle[2] = p4.vertices[i+2]; - t.material = p4.material; - t.state = p4.state; - t.tex1Name = p1.tex1Name; - t.tex2Name = p1.tex2Name; + EngineTriangle t; + t.triangle[0] = p4.vertices[i]; + t.triangle[1] = p4.vertices[i+1]; + t.triangle[2] = p4.vertices[i+2]; + t.material = p4.material; + t.state = p4.state; + t.tex1Name = p2.tex1Name; + t.tex2Name = p2.tex2Name; - triangles.push_back(t); + triangles.push_back(t); - ++actualCount; - } + ++actualCount; } - else if (p4.type == ENG_TRIANGLE_TYPE_SURFACE) + } + else if (p4.type == ENG_TRIANGLE_TYPE_SURFACE) + { + for (int i = 0; i < static_cast( p4.vertices.size() ); i += 1) { - for (int i = 0; i < static_cast( p4.vertices.size() ); i += 1) - { - if (static_cast(actualCount) / total >= percent) - break; + if (static_cast(actualCount) / total >= percent) + break; - if (actualCount >= maxCount) - break; + if (actualCount >= maxCount) + break; - EngineTriangle t; - t.triangle[0] = p4.vertices[i]; - t.triangle[1] = p4.vertices[i+1]; - t.triangle[2] = p4.vertices[i+2]; - t.material = p4.material; - t.state = p4.state; - t.tex1Name = p1.tex1Name; - t.tex2Name = p1.tex2Name; + EngineTriangle t; + t.triangle[0] = p4.vertices[i]; + t.triangle[1] = p4.vertices[i+1]; + t.triangle[2] = p4.vertices[i+2]; + t.material = p4.material; + t.state = p4.state; + t.tex1Name = p2.tex1Name; + t.tex2Name = p2.tex2Name; - triangles.push_back(t); + triangles.push_back(t); - ++actualCount; - } + ++actualCount; } } } @@ -1179,20 +1004,22 @@ void CEngine::ChangeLOD() float oldTerrain = m_terrainVision * m_lastClippingDistance; float newTerrain = m_terrainVision * m_clippingDistance; - for (int l1 = 0; l1 < static_cast( m_objectTree.size() ); l1++) + for (int baseObjRank = 0; baseObjRank < static_cast( m_baseObjects.size() ); baseObjRank++) { - EngineObjLevel1& p1 = m_objectTree[l1]; - if (! p1.used) continue; + if (! m_baseObjects[baseObjRank].used) + continue; - for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) + for (int l2 = 0; l2 < static_cast( m_baseObjects[baseObjRank].next.size() ); l2++) { - EngineObjLevel2& p2 = p1.next[l2]; - if (! p2.used) continue; + EngineBaseObjTexTier& p2 = m_baseObjects[baseObjRank].next[l2]; + if (! p2.used) + continue; for (int l3 = 0; l3 < static_cast( p2.next.size() ); l3++) { - EngineObjLevel3& p3 = p2.next[l3]; - if (! p3.used) continue; + EngineBaseObjLODTier& p3 = p2.next[l3]; + if (! p3.used) + continue; if ( Math::IsEqual(p3.min, 0.0f ) && Math::IsEqual(p3.max, oldLimit[0]) ) @@ -1224,43 +1051,40 @@ void CEngine::ChangeLOD() m_lastClippingDistance = m_clippingDistance; } -bool CEngine::ChangeSecondTexture(int objRank, const std::string& tex2Name) +void CEngine::ChangeSecondTexture(int objRank, const std::string& tex2Name) { - for (int l1 = 0; l1 < static_cast( m_objectTree.size() ); l1++) - { - EngineObjLevel1& p1 = m_objectTree[l1]; - if (! p1.used) continue; - - if (p1.tex2Name == tex2Name) continue; // already new - - for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) - { - EngineObjLevel2& p2 = p1.next[l2]; - if (! p2.used) continue; - - if (p2.objRank != objRank) continue; + assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); - EngineObjLevel1& newP1 = AddLevel1(p1.tex1Name, tex2Name); + int baseObjRank = m_objects[objRank].baseObjRank; + assert(baseObjRank >= 0 && baseObjRank < static_cast( m_baseObjects.size() )); + + EngineBaseObject& p1 = m_baseObjects[baseObjRank]; - newP1.next.push_back(EngineObjLevel2(true, objRank)); + for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) + { + EngineBaseObjTexTier& p2 = p1.next[l2]; + if (! p2.used) + continue; - EngineObjLevel2& newP2 = newP1.next.back(); - newP2.next.swap(p2.next); + if (p2.tex2Name == tex2Name) + continue; // already new - p2.used = false; - } + EngineBaseObjTexTier& newP2 = AddLevel2(baseObjRank, p2.tex1Name, tex2Name); + newP2.next.swap(p2.next); + p2.used = false; } - return true; } -bool CEngine::ChangeTextureMapping(int objRank, const Material& mat, int state, - const std::string& tex1Name, const std::string& tex2Name, - float min, float max, EngineTextureMapping mode, - float au, float bu, float av, float bv) +void CEngine::ChangeTextureMapping(int objRank, const Material& mat, int state, + const std::string& tex1Name, const std::string& tex2Name, + float min, float max, EngineTextureMapping mode, + float au, float bu, float av, float bv) { - EngineObjLevel4* p4 = FindTriangles(objRank, mat, state, tex1Name, tex2Name, min, max); + assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); + + EngineBaseObjDataTier* p4 = FindTriangles(objRank, mat, state, tex1Name, tex2Name, min, max); if (p4 == nullptr) - return false; + return; int nb = p4->vertices.size(); @@ -1310,21 +1134,25 @@ bool CEngine::ChangeTextureMapping(int objRank, const Material& mat, int state, } } - return true; + UpdateStaticBuffer(*p4); } -bool CEngine::TrackTextureMapping(int objRank, const Material& mat, int state, +void CEngine::TrackTextureMapping(int objRank, const Material& mat, int state, const std::string& tex1Name, const std::string& tex2Name, float min, float max, EngineTextureMapping mode, float pos, float factor, float tl, float ts, float tt) { - EngineObjLevel4* triangles = FindTriangles(objRank, mat, state, tex1Name, tex2Name, min, max); - if (triangles == nullptr) return false; + assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); + + EngineBaseObjDataTier* p4 = FindTriangles(objRank, mat, state, tex1Name, tex2Name, min, max); + if (p4 == nullptr) + return; - int tNum = triangles->vertices.size(); - if (tNum < 12 || tNum % 6 != 0) return false; + int tNum = p4->vertices.size(); + if (tNum < 12 || tNum % 6 != 0) + return; - std::vector& vs = triangles->vertices; + std::vector& vs = p4->vertices; while (pos < 0.0f) pos += 1.0f; // never negative! @@ -1402,17 +1230,17 @@ bool CEngine::TrackTextureMapping(int objRank, const Material& mat, int state, tBase += 6; } - return true; + UpdateStaticBuffer(*p4); } -bool CEngine::CreateShadow(int objRank) +void CEngine::CreateShadow(int objRank) { - if ( objRank < 0 || objRank >= static_cast( m_objects.size() ) ) - return false; + assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); // Already allocated? - if (m_objects[objRank].shadowRank != -1) return true; + if (m_objects[objRank].shadowRank != -1) + return; int index = 0; for ( ; index < static_cast( m_shadows.size() ); index++) @@ -1424,146 +1252,147 @@ bool CEngine::CreateShadow(int objRank) } } - m_shadows.push_back(EngineShadow()); + if (index == static_cast( m_shadows.size() )) + m_shadows.push_back(EngineShadow()); m_shadows[index].used = true; m_shadows[index].objRank = objRank; m_shadows[index].height = 0.0f; m_objects[objRank].shadowRank = index; - - return true; } void CEngine::DeleteShadow(int objRank) { - if ( objRank < 0 || objRank >= static_cast( m_objects.size() ) ) - return; + assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); - int i = m_objects[objRank].shadowRank; - if (i == -1) + int shadowRank = m_objects[objRank].shadowRank; + if (shadowRank == -1) return; - m_shadows[i].used = false; - m_shadows[i].objRank = -1; + assert(shadowRank >= 0 && shadowRank < static_cast( m_shadows.size() )); + + m_shadows[shadowRank].used = false; + m_shadows[shadowRank].objRank = -1; m_objects[objRank].shadowRank = -1; } -bool CEngine::SetObjectShadowHide(int objRank, bool hide) +void CEngine::SetObjectShadowHide(int objRank, bool hide) { - if ( objRank < 0 || objRank >= static_cast( m_objects.size() ) ) - return false; + assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); - int i = m_objects[objRank].shadowRank; - if (i == -1) - return false; + int shadowRank = m_objects[objRank].shadowRank; + if (shadowRank == -1) + return; - m_shadows[i].hide = hide; - return true; + assert(shadowRank >= 0 && shadowRank < static_cast( m_shadows.size() )); + + m_shadows[shadowRank].hide = hide; } -bool CEngine::SetObjectShadowType(int objRank, EngineShadowType type) +void CEngine::SetObjectShadowType(int objRank, EngineShadowType type) { - if ( objRank < 0 || objRank >= static_cast( m_objects.size() ) ) - return false; + assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); - int i = m_objects[objRank].shadowRank; - if (i == -1) - return false; + int shadowRank = m_objects[objRank].shadowRank; + if (shadowRank == -1) + return; - m_shadows[i].type = type; - return true; + assert(shadowRank >= 0 && shadowRank < static_cast( m_shadows.size() )); + + m_shadows[shadowRank].type = type; } -bool CEngine::SetObjectShadowPos(int objRank, const Math::Vector& pos) +void CEngine::SetObjectShadowPos(int objRank, const Math::Vector& pos) { - if ( objRank < 0 || objRank >= static_cast( m_objects.size() ) ) - return false; + assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); - int i = m_objects[objRank].shadowRank; - if (i == -1) - return false; + int shadowRank = m_objects[objRank].shadowRank; + if (shadowRank == -1) + return; - m_shadows[i].pos = pos; - return true; + assert(shadowRank >= 0 && shadowRank < static_cast( m_shadows.size() )); + + m_shadows[shadowRank].pos = pos; } -bool CEngine::SetObjectShadowNormal(int objRank, const Math::Vector& normal) +void CEngine::SetObjectShadowNormal(int objRank, const Math::Vector& normal) { - if ( objRank < 0 || objRank >= static_cast( m_objects.size() ) ) - return false; + assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); - int i = m_objects[objRank].shadowRank; - if (i == -1) - return false; + int shadowRank = m_objects[objRank].shadowRank; + if (shadowRank == -1) + return; - m_shadows[i].normal = normal; - return true; + assert(shadowRank >= 0 && shadowRank < static_cast( m_shadows.size() )); + + m_shadows[shadowRank].normal = normal; } -bool CEngine::SetObjectShadowAngle(int objRank, float angle) +void CEngine::SetObjectShadowAngle(int objRank, float angle) { - if ( objRank < 0 || objRank >= static_cast( m_objects.size() ) ) - return false; + assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); - int i = m_objects[objRank].shadowRank; - if (i == -1) - return false; + int shadowRank = m_objects[objRank].shadowRank; + if (shadowRank == -1) + return; - m_shadows[i].angle = angle; - return true; + assert(shadowRank >= 0 && shadowRank < static_cast( m_shadows.size() )); + + m_shadows[shadowRank].angle = angle; } -bool CEngine::SetObjectShadowRadius(int objRank, float radius) +void CEngine::SetObjectShadowRadius(int objRank, float radius) { - if ( objRank < 0 || objRank >= static_cast( m_objects.size() ) ) - return false; + assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); - int i = m_objects[objRank].shadowRank; - if (i == -1) - return false; + int shadowRank = m_objects[objRank].shadowRank; + if (shadowRank == -1) + return; - m_shadows[i].radius = radius; - return true; + assert(shadowRank >= 0 && shadowRank < static_cast( m_shadows.size() )); + + m_shadows[shadowRank].radius = radius; } -bool CEngine::SetObjectShadowIntensity(int objRank, float intensity) +void CEngine::SetObjectShadowIntensity(int objRank, float intensity) { - if ( objRank < 0 || objRank >= static_cast( m_objects.size() ) ) - return false; + assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); - int i = m_objects[objRank].shadowRank; - if (i == -1) - return false; + int shadowRank = m_objects[objRank].shadowRank; + if (shadowRank == -1) + return; - m_shadows[i].intensity = intensity; - return true; + assert(shadowRank >= 0 && shadowRank < static_cast( m_shadows.size() )); + + m_shadows[shadowRank].intensity = intensity; } -bool CEngine::SetObjectShadowHeight(int objRank, float height) +void CEngine::SetObjectShadowHeight(int objRank, float height) { - if ( objRank < 0 || objRank >= static_cast( m_objects.size() ) ) - return false; + assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); - int i = m_objects[objRank].shadowRank; - if (i == -1) - return false; + int shadowRank = m_objects[objRank].shadowRank; + if (shadowRank == -1) + return; - m_shadows[i].height = height; - return true; + assert(shadowRank >= 0 && shadowRank < static_cast( m_shadows.size() )); + + m_shadows[shadowRank].height = height; } float CEngine::GetObjectShadowRadius(int objRank) { - if ( objRank < 0 || objRank >= static_cast( m_objects.size() ) ) - return 0.0f; + assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); - int i = m_objects[objRank].shadowRank; - if (i == -1) + int shadowRank = m_objects[objRank].shadowRank; + if (shadowRank == -1) return 0.0f; - return m_shadows[i].radius; + assert(shadowRank >= 0 && shadowRank < static_cast( m_shadows.size() )); + + return m_shadows[shadowRank].radius; } bool CEngine::GetHighlight(Math::Point &p1, Math::Point &p2) @@ -1585,21 +1414,26 @@ void CEngine::SetHighlightRank(int *rankList) bool CEngine::GetBBox2D(int objRank, Math::Point &min, Math::Point &max) { + assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); + min.x = 1000000.0f; min.y = 1000000.0f; max.x = -1000000.0f; max.y = -1000000.0f; + int baseObjRank = m_objects[objRank].baseObjRank; + assert(baseObjRank >= 0 && baseObjRank < static_cast( m_baseObjects.size() )); + for (int i = 0; i < 8; i++) { Math::Vector p; - if ( i & (1<<0) ) p.x = m_objects[objRank].bboxMin.x; - else p.x = m_objects[objRank].bboxMax.x; - if ( i & (1<<1) ) p.y = m_objects[objRank].bboxMin.y; - else p.y = m_objects[objRank].bboxMax.y; - if ( i & (1<<2) ) p.z = m_objects[objRank].bboxMin.z; - else p.z = m_objects[objRank].bboxMax.z; + if ( i & (1<<0) ) p.x = m_baseObjects[baseObjRank].bboxMin.x; + else p.x = m_baseObjects[baseObjRank].bboxMax.x; + if ( i & (1<<1) ) p.y = m_baseObjects[baseObjRank].bboxMin.y; + else p.y = m_baseObjects[baseObjRank].bboxMax.y; + if ( i & (1<<2) ) p.z = m_baseObjects[baseObjRank].bboxMin.z; + else p.z = m_baseObjects[baseObjRank].bboxMax.z; Math::Vector pp; if (TransformPoint(pp, objRank, p)) @@ -1611,15 +1445,16 @@ bool CEngine::GetBBox2D(int objRank, Math::Point &min, Math::Point &max) } } - if ( min.x == 1000000.0f || - min.y == 1000000.0f || - max.x == -1000000.0f || - max.y == -1000000.0f ) return false; + if (min.x == 1000000.0f || + min.y == 1000000.0f || + max.x == -1000000.0f || + max.y == -1000000.0f) + return false; return true; } -void CEngine::FlushGroundSpot() +void CEngine::DeleteAllGroundSpots() { m_groundSpots.clear(); m_firstGroundSpot = true; @@ -1664,54 +1499,46 @@ int CEngine::CreateGroundSpot() void CEngine::DeleteGroundSpot(int rank) { + assert(rank >= 0 && rank < static_cast( m_groundSpots.size() )); + m_groundSpots[rank].used = false; m_groundSpots[rank].pos = Math::Vector(0.0f, 0.0f, 0.0f); } -bool CEngine::SetObjectGroundSpotPos(int rank, const Math::Vector& pos) +void CEngine::SetObjectGroundSpotPos(int rank, const Math::Vector& pos) { - if ( rank < 0 || rank >= static_cast( m_groundSpots.size() ) ) - return 0.0f; + assert(rank >= 0 && rank < static_cast( m_groundSpots.size() )); m_groundSpots[rank].pos = pos; - return true; } -bool CEngine::SetObjectGroundSpotRadius(int rank, float radius) +void CEngine::SetObjectGroundSpotRadius(int rank, float radius) { - if ( rank < 0 || rank >= static_cast( m_groundSpots.size() ) ) - return 0.0f; + assert(rank >= 0 && rank < static_cast( m_groundSpots.size() )); m_groundSpots[rank].radius = radius; - return true; } -bool CEngine::SetObjectGroundSpotColor(int rank, const Color& color) +void CEngine::SetObjectGroundSpotColor(int rank, const Color& color) { - if ( rank < 0 || rank >= static_cast( m_groundSpots.size() ) ) - return 0.0f; + assert(rank >= 0 && rank < static_cast( m_groundSpots.size() )); m_groundSpots[rank].color = color; - return true; } -bool CEngine::SetObjectGroundSpotMinMax(int rank, float min, float max) +void CEngine::SetObjectGroundSpotMinMax(int rank, float min, float max) { - if ( rank < 0 || rank >= static_cast( m_groundSpots.size() ) ) - return 0.0f; + assert(rank >= 0 && rank < static_cast( m_groundSpots.size() )); m_groundSpots[rank].min = min; m_groundSpots[rank].max = max; - return true; } -bool CEngine::SetObjectGroundSpotSmooth(int rank, float smooth) +void CEngine::SetObjectGroundSpotSmooth(int rank, float smooth) { - if ( rank < 0 || rank >= static_cast( m_groundSpots.size() ) ) - return 0.0f; + assert(rank >= 0 && rank < static_cast( m_groundSpots.size() )); m_groundSpots[rank].smooth = smooth; - return true; } void CEngine::CreateGroundMark(Math::Vector pos, float radius, @@ -1758,51 +1585,45 @@ void CEngine::UpdateGeometry() if (! m_updateGeometry) return; - for (int i = 0; i < static_cast( m_objects.size() ); i++) + for (int baseObjRank = 0; baseObjRank < static_cast( m_baseObjects.size() ); baseObjRank++) { - m_objects[i].bboxMin.x = 0; - m_objects[i].bboxMin.y = 0; - m_objects[i].bboxMin.z = 0; - m_objects[i].bboxMax.x = 0; - m_objects[i].bboxMax.y = 0; - m_objects[i].bboxMax.z = 0; - m_objects[i].radius = 0; - } + EngineBaseObject &p1 = m_baseObjects[baseObjRank]; + if (! p1.used) + continue; - for (int l1 = 0; l1 < static_cast( m_objectTree.size() ); l1++) - { - EngineObjLevel1& p1 = m_objectTree[l1]; - if (! p1.used) continue; + p1.bboxMin.LoadZero(); + p1.bboxMax.LoadZero(); + p1.radius = 0; for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) { - EngineObjLevel2& p2 = p1.next[l2]; - if (! p2.used) continue; + EngineBaseObjTexTier& p2 = p1.next[l2]; + if (! p2.used) + continue; for (int l3 = 0; l3 < static_cast( p2.next.size() ); l3++) { - EngineObjLevel3& p3 = p2.next[l3]; - if (! p3.used) continue; + EngineBaseObjLODTier& p3 = p2.next[l3]; + if (! p3.used) + continue; for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) { - EngineObjLevel4& p4 = p3.next[l4]; - if (! p4.used) continue; - - int objRank = p2.objRank; + EngineBaseObjDataTier& p4 = p3.next[l4]; + if (! p4.used) + continue; for (int i = 0; i < static_cast( p4.vertices.size() ); i++) { - m_objects[objRank].bboxMin.x = Math::Min(p4.vertices[i].coord.x, m_objects[objRank].bboxMin.x); - m_objects[objRank].bboxMin.y = Math::Min(p4.vertices[i].coord.y, m_objects[objRank].bboxMin.y); - m_objects[objRank].bboxMin.z = Math::Min(p4.vertices[i].coord.z, m_objects[objRank].bboxMin.z); - m_objects[objRank].bboxMax.x = Math::Max(p4.vertices[i].coord.x, m_objects[objRank].bboxMax.x); - m_objects[objRank].bboxMax.y = Math::Max(p4.vertices[i].coord.y, m_objects[objRank].bboxMax.y); - m_objects[objRank].bboxMax.z = Math::Max(p4.vertices[i].coord.z, m_objects[objRank].bboxMax.z); + p1.bboxMin.x = Math::Min(p4.vertices[i].coord.x, p1.bboxMin.x); + p1.bboxMin.y = Math::Min(p4.vertices[i].coord.y, p1.bboxMin.y); + p1.bboxMin.z = Math::Min(p4.vertices[i].coord.z, p1.bboxMin.z); + p1.bboxMax.x = Math::Max(p4.vertices[i].coord.x, p1.bboxMax.x); + p1.bboxMax.y = Math::Max(p4.vertices[i].coord.y, p1.bboxMax.y); + p1.bboxMax.z = Math::Max(p4.vertices[i].coord.z, p1.bboxMax.z); } - m_objects[objRank].radius = Math::Max(m_objects[objRank].bboxMin.Length(), - m_objects[objRank].bboxMax.Length()); + p1.radius = Math::Max(p1.bboxMin.Length(), p1.bboxMax.Length()); } } } @@ -1811,46 +1632,57 @@ void CEngine::UpdateGeometry() m_updateGeometry = false; } -void CEngine::UpdateStaticObjects() +void CEngine::UpdateStaticBuffer(EngineBaseObjDataTier& p4) +{ + PrimitiveType type; + if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES) + type = PRIMITIVE_TRIANGLES; + else + type = PRIMITIVE_TRIANGLE_STRIP; + + if (p4.staticBufferId == 0) + p4.staticBufferId = m_device->CreateStaticBuffer(type, &p4.vertices[0], p4.vertices.size()); + else + m_device->UpdateStaticBuffer(p4.staticBufferId, type, &p4.vertices[0], p4.vertices.size()); + + p4.updateStaticBuffer = false; +} + +void CEngine::UpdateStaticBuffers() { - if (!m_updateStaticObjects) + if (!m_updateStaticBuffers) return; - for (int l1 = 0; l1 < static_cast( m_objectTree.size() ); l1++) + m_updateStaticBuffers = false; + + for (int baseObjRank = 0; baseObjRank < static_cast( m_baseObjects.size() ); baseObjRank++) { - EngineObjLevel1& p1 = m_objectTree[l1]; - if (! p1.used) continue; + EngineBaseObject& p1 = m_baseObjects[baseObjRank]; + if (! p1.used) + continue; for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) { - EngineObjLevel2& p2 = p1.next[l2]; - if (! p2.used) continue; - - int objRank = p2.objRank; - - if (!m_objects[objRank].staticBuffer) + EngineBaseObjTexTier& p2 = p1.next[l2]; + if (! p2.used) continue; for (int l3 = 0; l3 < static_cast( p2.next.size() ); l3++) { - EngineObjLevel3& p3 = p2.next[l3]; - if (! p3.used) continue; + EngineBaseObjLODTier& p3 = p2.next[l3]; + if (! p3.used) + continue; for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) { - EngineObjLevel4& p4 = p3.next[l4]; - if (! p4.used) continue; - - if (p4.staticBufferId != 0) + EngineBaseObjDataTier& p4 = p3.next[l4]; + if (! p4.used) continue; - PrimitiveType type; - if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES) - type = PRIMITIVE_TRIANGLES; - else - type = PRIMITIVE_TRIANGLE_STRIP; + if (! p4.updateStaticBuffer) + continue; - p4.staticBufferId = m_device->CreateStaticObject(type, &p4.vertices[0], p4.vertices.size()); + UpdateStaticBuffer(p4); } } } @@ -1861,11 +1693,16 @@ void CEngine::Update() { ComputeDistance(); UpdateGeometry(); - UpdateStaticObjects(); + UpdateStaticBuffers(); } bool CEngine::DetectBBox(int objRank, Math::Point mouse) { + assert(objRank >= 0 && objRank < static_cast(m_objects.size())); + + int baseObjRank = m_objects[objRank].baseObjRank; + assert(baseObjRank >= 0 && baseObjRank < static_cast(m_baseObjects.size())); + Math::Point min, max; min.x = 1000000.0f; min.y = 1000000.0f; @@ -1876,12 +1713,12 @@ bool CEngine::DetectBBox(int objRank, Math::Point mouse) { Math::Vector p; - if ( i & (1<<0) ) p.x = m_objects[objRank].bboxMin.x; - else p.x = m_objects[objRank].bboxMax.x; - if ( i & (1<<1) ) p.y = m_objects[objRank].bboxMin.y; - else p.y = m_objects[objRank].bboxMax.y; - if ( i & (1<<2) ) p.z = m_objects[objRank].bboxMin.z; - else p.z = m_objects[objRank].bboxMax.z; + if ( i & (1<<0) ) p.x = m_baseObjects[baseObjRank].bboxMin.x; + else p.x = m_baseObjects[baseObjRank].bboxMax.x; + if ( i & (1<<1) ) p.y = m_baseObjects[baseObjRank].bboxMin.y; + else p.y = m_baseObjects[baseObjRank].bboxMax.y; + if ( i & (1<<2) ) p.z = m_baseObjects[baseObjRank].bboxMin.z; + else p.z = m_baseObjects[baseObjRank].bboxMax.z; Math::Vector pp; if ( TransformPoint(pp, objRank, p) ) @@ -1904,41 +1741,54 @@ int CEngine::DetectObject(Math::Point mouse) float min = 1000000.0f; int nearest = -1; - for (int l1 = 0; l1 < static_cast( m_objectTree.size() ); l1++) + for (int objRank = 0; objRank < static_cast( m_objects.size() ); objRank++) { - EngineObjLevel1& p1 = m_objectTree[l1]; - if (! p1.used) continue; + if (! m_objects[objRank].used) + continue; - for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) - { - EngineObjLevel2& p2 = p1.next[l2]; - if (! p2.used) continue; + if (m_objects[objRank].type == ENG_OBJTYPE_TERRAIN) + continue; + + if (! DetectBBox(objRank, mouse)) + continue; + + int baseObjRank = m_objects[objRank].baseObjRank; + assert(baseObjRank >= 0 && baseObjRank < static_cast(m_baseObjects.size())); - if (m_objects[p2.objRank].type == ENG_OBJTYPE_TERRAIN) continue; + EngineBaseObject& p1 = m_baseObjects[baseObjRank]; + if (! p1.used) + continue; - if (! DetectBBox(p2.objRank, mouse)) continue; + for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) + { + EngineBaseObjTexTier& p2 = p1.next[l2]; + if (! p2.used) + continue; for (int l3 = 0; l3 < static_cast( p2.next.size() ); l3++) { - EngineObjLevel3& p3 = p2.next[l3]; - if (! p3.used) continue; + EngineBaseObjLODTier& p3 = p2.next[l3]; + if (! p3.used) + continue; - if (p3.min != 0.0f) continue; // LOD B or C? + if (p3.min != 0.0f) + continue; // LOD B or C? for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) { - EngineObjLevel4& p4 = p3.next[l4]; - if (! p4.used) continue; + EngineBaseObjDataTier& p4 = p3.next[l4]; + if (! p4.used) + continue; if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES) { for (int i = 0; i < static_cast( p4.vertices.size() ); i += 3) { float dist = 0.0f; - if (DetectTriangle(mouse, &p4.vertices[i], p2.objRank, dist) && dist < min) + if (DetectTriangle(mouse, &p4.vertices[i], objRank, dist) && dist < min) { min = dist; - nearest = p2.objRank; + nearest = objRank; } } } @@ -1947,10 +1797,10 @@ int CEngine::DetectObject(Math::Point mouse) for (int i = 0; i < static_cast( p4.vertices.size() ) - 2; i += 1) { float dist = 0.0f; - if (DetectTriangle(mouse, &p4.vertices[i], p2.objRank, dist) && dist < min) + if (DetectTriangle(mouse, &p4.vertices[i], objRank, dist) && dist < min) { min = dist; - nearest = p2.objRank; + nearest = objRank; } } } @@ -1964,6 +1814,8 @@ int CEngine::DetectObject(Math::Point mouse) bool CEngine::DetectTriangle(Math::Point mouse, VertexTex2* triangle, int objRank, float& dist) { + assert(objRank >= 0 && objRank < static_cast(m_objects.size())); + Math::Vector p2D[3], p3D; for (int i = 0; i < 3; i++) @@ -1976,18 +1828,25 @@ bool CEngine::DetectTriangle(Math::Point mouse, VertexTex2* triangle, int objRan return false; } - if ( mouse.x < p2D[0].x && - mouse.x < p2D[1].x && - mouse.x < p2D[2].x ) return false; - if ( mouse.x > p2D[0].x && - mouse.x > p2D[1].x && - mouse.x > p2D[2].x ) return false; - if ( mouse.y < p2D[0].y && - mouse.y < p2D[1].y && - mouse.y < p2D[2].y ) return false; - if ( mouse.y > p2D[0].y && - mouse.y > p2D[1].y && - mouse.y > p2D[2].y ) return false; + if (mouse.x < p2D[0].x && + mouse.x < p2D[1].x && + mouse.x < p2D[2].x) + return false; + + if (mouse.x > p2D[0].x && + mouse.x > p2D[1].x && + mouse.x > p2D[2].x) + return false; + + if (mouse.y < p2D[0].y && + mouse.y < p2D[1].y && + mouse.y < p2D[2].y) + return false; + + if (mouse.y > p2D[0].y && + mouse.y > p2D[1].y && + mouse.y > p2D[2].y) + return false; Math::Point a, b, c; a.x = p2D[0].x; @@ -2007,7 +1866,12 @@ bool CEngine::DetectTriangle(Math::Point mouse, VertexTex2* triangle, int objRan //! Use only after world transform already set bool CEngine::IsVisible(int objRank) { - float radius = m_objects[objRank].radius; + assert(objRank >= 0 && objRank < static_cast(m_objects.size())); + + int baseObjRank = m_objects[objRank].baseObjRank; + assert(baseObjRank >= 0 && baseObjRank < static_cast(m_baseObjects.size())); + + float radius = m_baseObjects[baseObjRank].radius; Math::Vector center(0.0f, 0.0f, 0.0f); if (m_device->ComputeSphereVisibility(center, radius) == Gfx::FRUSTUM_PLANE_ALL) { @@ -2016,15 +1880,18 @@ bool CEngine::IsVisible(int objRank) } m_objects[objRank].visible = false; - return true; + return false; } bool CEngine::TransformPoint(Math::Vector& p2D, int objRank, Math::Vector p3D) { + assert(objRank >= 0 && objRank < static_cast(m_objects.size())); + p3D = Math::Transform(m_objects[objRank].transform, p3D); p3D = Math::Transform(m_matView, p3D); - if (p3D.z < 2.0f) return false; // behind? + if (p3D.z < 2.0f) + return false; // behind? p2D.x = (p3D.x/p3D.z)*m_matProj.Get(1,1); p2D.y = (p3D.y/p3D.z)*m_matProj.Get(2,2); @@ -2387,42 +2254,49 @@ bool CEngine::LoadAllTextures() bool ok = true; - for (int l1 = 0; l1 < static_cast( m_objectTree.size() ); l1++) + for (int objRank = 0; objRank < static_cast( m_objects.size() ); objRank++) { - EngineObjLevel1& p1 = m_objectTree[l1]; - if (! p1.used) continue; + if (! m_objects[objRank].used) + continue; bool terrain = false; + if (m_objects[objRank].type == ENG_OBJTYPE_TERRAIN) + terrain = true; - for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) - { - EngineObjLevel2& p2 = p1.next[l2]; - if (! p2.used) continue; + int baseObjRank = m_objects[objRank].baseObjRank; + assert(baseObjRank >= 0 && baseObjRank < static_cast( m_baseObjects.size() )); - if (m_objects[p2.objRank].type == ENG_OBJTYPE_TERRAIN) - terrain = true; - } + EngineBaseObject& p1 = m_baseObjects[baseObjRank]; + if (! p1.used) + continue; - if (! p1.tex1Name.empty()) + for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) { - if (terrain) - p1.tex1 = LoadTexture(p1.tex1Name, m_terrainTexParams); - else - p1.tex1 = LoadTexture(p1.tex1Name); + EngineBaseObjTexTier& p2 = p1.next[l2]; + if (! p2.used) + continue; - if (! p1.tex1.Valid()) - ok = false; - } + if (! p2.tex1Name.empty()) + { + if (terrain) + p2.tex1 = LoadTexture(p2.tex1Name, m_terrainTexParams); + else + p2.tex1 = LoadTexture(p2.tex1Name); - if (! p1.tex2Name.empty()) - { - if (terrain) - p1.tex2 = LoadTexture(p1.tex2Name, m_terrainTexParams); - else - p1.tex2 = LoadTexture(p1.tex2Name); + if (! p2.tex1.Valid()) + ok = false; + } + + if (! p2.tex2Name.empty()) + { + if (terrain) + p2.tex2 = LoadTexture(p2.tex2Name, m_terrainTexParams); + else + p2.tex2 = LoadTexture(p2.tex2Name); - if (! p1.tex2.Valid()) - ok = false; + if (! p2.tex2.Valid()) + ok = false; + } } } @@ -2438,7 +2312,8 @@ bool IsExcludeColor(Math::Point *exclude, int x, int y) if ( x >= static_cast(exclude[i+0].x*256.0f) && x < static_cast(exclude[i+1].x*256.0f) && y >= static_cast(exclude[i+0].y*256.0f) && - y < static_cast(exclude[i+1].y*256.0f) ) return true; // exclude + y < static_cast(exclude[i+1].y*256.0f) ) + return true; // exclude i += 2; } @@ -2454,12 +2329,13 @@ bool CEngine::ChangeTextureColor(const std::string& texName, Math::Point ts, Math::Point ti, Math::Point *exclude, float shift, bool hsv) { - if ( colorRef1.r == colorNew1.r && - colorRef1.g == colorNew1.g && - colorRef1.b == colorNew1.b && - colorRef2.r == colorNew2.r && - colorRef2.g == colorNew2.g && - colorRef2.b == colorNew2.b ) return true; + if (colorRef1.r == colorNew1.r && + colorRef1.g == colorNew1.g && + colorRef1.b == colorNew1.b && + colorRef2.r == colorNew2.r && + colorRef2.g == colorNew2.g && + colorRef2.b == colorNew2.b) + return true; DeleteTexture(texName); @@ -2494,7 +2370,8 @@ bool CEngine::ChangeTextureColor(const std::string& texName, { for (int x = sx; x < ex; x++) { - if (exclude != nullptr && IsExcludeColor(exclude, x,y) ) continue; + if (exclude != nullptr && IsExcludeColor(exclude, x,y) ) + continue; Color color = img.GetPixel(Math::IntPoint(x, y)); @@ -3124,7 +3001,8 @@ void CEngine::ApplyChange() viewport, and renders the scene. */ void CEngine::Render() { - if (! m_render) return; + if (! m_render) + return; m_statisticTriangle = 0; m_lastState = -1; @@ -3187,35 +3065,44 @@ void CEngine::Draw3DScene() { m_lightMan->UpdateDeviceLights(ENG_OBJTYPE_TERRAIN); - for (int l1 = 0; l1 < static_cast( m_objectTree.size() ); l1++) + for (int objRank = 0; objRank < static_cast(m_objects.size()); objRank++) { - EngineObjLevel1& p1 = m_objectTree[l1]; - if (! p1.used) continue; + if (! m_objects[objRank].used) + continue; - // Should be loaded by now - SetTexture(p1.tex1, 0); - SetTexture(p1.tex2, 1); + if (m_objects[objRank].type != ENG_OBJTYPE_TERRAIN) + continue; - for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) - { - EngineObjLevel2& p2 = p1.next[l2]; - if (! p2.used) continue; + if (! m_objects[objRank].drawWorld) + continue; - int objRank = p2.objRank; - if (m_objects[objRank].type != ENG_OBJTYPE_TERRAIN) - continue; - if (! m_objects[objRank].drawWorld) - continue; + m_device->SetTransform(TRANSFORM_WORLD, m_objects[objRank].transform); + + if (! IsVisible(objRank)) + continue; - m_device->SetTransform(TRANSFORM_WORLD, m_objects[objRank].transform); + int baseObjRank = m_objects[objRank].baseObjRank; + assert(baseObjRank >= 0 && baseObjRank < static_cast( m_baseObjects.size() )); + + EngineBaseObject& p1 = m_baseObjects[baseObjRank]; + if (! p1.used) + continue; - if (! IsVisible(objRank)) + for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) + { + EngineBaseObjTexTier& p2 = p1.next[l2]; + if (! p2.used) continue; + // Should be loaded by now + SetTexture(p2.tex1, 0); + SetTexture(p2.tex2, 1); + for (int l3 = 0; l3 < static_cast( p2.next.size() ); l3++) { - EngineObjLevel3& p3 = p2.next[l3]; - if (! p3.used) continue; + EngineBaseObjLODTier& p3 = p2.next[l3]; + if (! p3.used) + continue; if ( m_objects[objRank].distance < p3.min || m_objects[objRank].distance >= p3.max ) @@ -3223,13 +3110,14 @@ void CEngine::Draw3DScene() for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) { - EngineObjLevel4& p4 = p3.next[l4]; - if (! p4.used) continue; + EngineBaseObjDataTier& p4 = p3.next[l4]; + if (! p4.used) + continue; SetMaterial(p4.material); SetState(p4.state); - DrawObject(p4, m_objects[objRank].staticBuffer); + DrawObject(p4); } } } @@ -3247,47 +3135,56 @@ void CEngine::Draw3DScene() bool transparent = false; - for (int l1 = 0; l1 < static_cast( m_objectTree.size() ); l1++) + for (int objRank = 0; objRank < static_cast(m_objects.size()); objRank++) { - EngineObjLevel1& p1 = m_objectTree[l1]; - if (! p1.used) continue; + if (! m_objects[objRank].used) + continue; - // Should be loaded by now - SetTexture(p1.tex1, 0); - SetTexture(p1.tex2, 1); + if (m_objects[objRank].type == ENG_OBJTYPE_TERRAIN) + continue; - for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) - { - EngineObjLevel2& p2 = p1.next[l2]; - if (! p2.used) continue; + if (! m_objects[objRank].drawWorld) + continue; - int objRank = p2.objRank; + m_device->SetTransform(TRANSFORM_WORLD, m_objects[objRank].transform); - if (m_shadowVisible && m_objects[objRank].type == ENG_OBJTYPE_TERRAIN) - continue; + if (! IsVisible(objRank)) + continue; - if (! m_objects[objRank].drawWorld) - continue; + int baseObjRank = m_objects[objRank].baseObjRank; + assert(baseObjRank >= 0 && baseObjRank < static_cast( m_baseObjects.size() )); - m_device->SetTransform(TRANSFORM_WORLD, m_objects[objRank].transform); + EngineBaseObject& p1 = m_baseObjects[baseObjRank]; + if (! p1.used) + continue; - if (! IsVisible(objRank)) + m_lightMan->UpdateDeviceLights(m_objects[objRank].type); + + for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) + { + EngineBaseObjTexTier& p2 = p1.next[l2]; + if (! p2.used) continue; - m_lightMan->UpdateDeviceLights(m_objects[objRank].type); + // Should be loaded by now + SetTexture(p2.tex1, 0); + SetTexture(p2.tex2, 1); for (int l3 = 0; l3 < static_cast( p2.next.size() ); l3++) { - EngineObjLevel3& p3 = p2.next[l3]; - if (! p3.used) continue; + EngineBaseObjLODTier& p3 = p2.next[l3]; + if (! p3.used) + continue; if ( m_objects[objRank].distance < p3.min || - m_objects[objRank].distance >= p3.max ) continue; + m_objects[objRank].distance >= p3.max ) + continue; for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) { - EngineObjLevel4& p4 = p3.next[l4]; - if (! p4.used) continue; + EngineBaseObjDataTier& p4 = p3.next[l4]; + if (! p4.used) + continue; if (m_objects[objRank].transparency != 0.0f) // transparent ? { @@ -3298,7 +3195,7 @@ void CEngine::Draw3DScene() SetMaterial(p4.material); SetState(p4.state); - DrawObject(p4, m_objects[objRank].staticBuffer); + DrawObject(p4); } } } @@ -3311,47 +3208,56 @@ void CEngine::Draw3DScene() int tState = ENG_RSTATE_TTEXTURE_BLACK | ENG_RSTATE_2FACE; Color tColor = Color(68.0f / 255.0f, 68.0f / 255.0f, 68.0f / 255.0f, 68.0f / 255.0f); - for (int l1 = 0; l1 < static_cast( m_objectTree.size() ); l1++) + for (int objRank = 0; objRank < static_cast(m_objects.size()); objRank++) { - EngineObjLevel1& p1 = m_objectTree[l1]; - if (! p1.used) continue; + if (! m_objects[objRank].used) + continue; - // Should be loaded by now - SetTexture(p1.tex1, 0); - SetTexture(p1.tex2, 1); + if (m_objects[objRank].type == ENG_OBJTYPE_TERRAIN) + continue; - for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) - { - EngineObjLevel2& p2 = p1.next[l2]; - if (! p2.used) continue; + if (! m_objects[objRank].drawWorld) + continue; - int objRank = p2.objRank; + m_device->SetTransform(TRANSFORM_WORLD, m_objects[objRank].transform); - if (m_shadowVisible && m_objects[objRank].type == ENG_OBJTYPE_TERRAIN) - continue; + if (! IsVisible(objRank)) + continue; - if (! m_objects[objRank].drawWorld) - continue; + int baseObjRank = m_objects[objRank].baseObjRank; + assert(baseObjRank >= 0 && baseObjRank < static_cast( m_baseObjects.size() )); + + EngineBaseObject& p1 = m_baseObjects[baseObjRank]; + if (! p1.used) + continue; - m_device->SetTransform(TRANSFORM_WORLD, m_objects[objRank].transform); + m_lightMan->UpdateDeviceLights(m_objects[objRank].type); - if (! IsVisible(objRank)) + for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) + { + EngineBaseObjTexTier& p2 = p1.next[l2]; + if (! p2.used) continue; - m_lightMan->UpdateDeviceLights(m_objects[objRank].type); + // Should be loaded by now + SetTexture(p2.tex1, 0); + SetTexture(p2.tex2, 1); for (int l3 = 0; l3 < static_cast( p2.next.size() ); l3++) { - EngineObjLevel3& p3 = p2.next[l3]; - if (! p3.used) continue; + EngineBaseObjLODTier& p3 = p2.next[l3]; + if (! p3.used) + continue; - if ( m_objects[objRank].distance < p3.min || - m_objects[objRank].distance >= p3.max ) continue; + if (m_objects[objRank].distance < p3.min || + m_objects[objRank].distance >= p3.max) + continue; for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) { - EngineObjLevel4& p4 = p3.next[l4]; - if (! p4.used) continue; + EngineBaseObjDataTier& p4 = p3.next[l4]; + if (! p4.used) + continue; if (m_objects[objRank].transparency == 0.0f) continue; @@ -3359,7 +3265,7 @@ void CEngine::Draw3DScene() SetMaterial(p4.material); SetState(tState, tColor); - DrawObject(p4, m_objects[objRank].staticBuffer); + DrawObject(p4); } } } @@ -3388,28 +3294,28 @@ void CEngine::Draw3DScene() if (! m_overFront) DrawOverColor(); // draws the foreground color } -void CEngine::DrawObject(const EngineObjLevel4& obj, bool staticBuffer) +void CEngine::DrawObject(const EngineBaseObjDataTier& p4) { - if (staticBuffer) + if (p4.staticBufferId != 0) { - m_device->DrawStaticObject(obj.staticBufferId); + m_device->DrawStaticBuffer(p4.staticBufferId); - if (obj.type == ENG_TRIANGLE_TYPE_TRIANGLES) - m_statisticTriangle += obj.vertices.size() / 3; + if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES) + m_statisticTriangle += p4.vertices.size() / 3; else - m_statisticTriangle += obj.vertices.size() - 2; + m_statisticTriangle += p4.vertices.size() - 2; } else { - if (obj.type == ENG_TRIANGLE_TYPE_TRIANGLES) + if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES) { - m_device->DrawPrimitive(PRIMITIVE_TRIANGLES, &obj.vertices[0], obj.vertices.size()); - m_statisticTriangle += obj.vertices.size() / 3; + m_device->DrawPrimitive(PRIMITIVE_TRIANGLES, &p4.vertices[0], p4.vertices.size()); + m_statisticTriangle += p4.vertices.size() / 3; } else { - m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, &obj.vertices[0], obj.vertices.size() ); - m_statisticTriangle += obj.vertices.size() - 2; + m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, &p4.vertices[0], p4.vertices.size() ); + m_statisticTriangle += p4.vertices.size() - 2; } } } @@ -3459,52 +3365,60 @@ void CEngine::DrawInterface() m_device->SetTransform(TRANSFORM_VIEW, m_matView); - for (int l1 = 0; l1 < static_cast( m_objectTree.size() ); l1++) + for (int objRank = 0; objRank < static_cast(m_objects.size()); objRank++) { - EngineObjLevel1& p1 = m_objectTree[l1]; - if (! p1.used) continue; + if (! m_objects[objRank].used) + continue; - // Should be loaded by now - SetTexture(p1.tex1, 0); - SetTexture(p1.tex2, 1); + if (m_shadowVisible && m_objects[objRank].type == ENG_OBJTYPE_TERRAIN) + continue; - for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) - { - EngineObjLevel2& p2 = p1.next[l2]; - if (! p2.used) continue; + if (! m_objects[objRank].drawFront) + continue; - int objRank = p2.objRank; + m_device->SetTransform(TRANSFORM_WORLD, m_objects[objRank].transform); - if (m_shadowVisible && m_objects[objRank].type == ENG_OBJTYPE_TERRAIN) - continue; + if (! IsVisible(objRank)) + continue; - if (! m_objects[objRank].drawFront) - continue; + int baseObjRank = m_objects[objRank].baseObjRank; + assert(baseObjRank >= 0 && baseObjRank < static_cast( m_baseObjects.size() )); - m_device->SetTransform(TRANSFORM_WORLD, m_objects[objRank].transform); + EngineBaseObject& p1 = m_baseObjects[baseObjRank]; + if (! p1.used) + continue; + + m_lightMan->UpdateDeviceLights(m_objects[objRank].type); - if (! IsVisible(objRank)) + for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) + { + EngineBaseObjTexTier& p2 = p1.next[l2]; + if (! p2.used) continue; - m_lightMan->UpdateDeviceLights(m_objects[objRank].type); + SetTexture(p2.tex1, 0); + SetTexture(p2.tex2, 1); for (int l3 = 0; l3 < static_cast( p2.next.size() ); l3++) { - EngineObjLevel3& p3 = p2.next[l3]; - if (! p3.used) continue; + EngineBaseObjLODTier& p3 = p2.next[l3]; + if (! p3.used) + continue; - if ( m_objects[objRank].distance < p3.min || - m_objects[objRank].distance >= p3.max ) continue; + if (m_objects[objRank].distance < p3.min || + m_objects[objRank].distance >= p3.max) + continue; for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) { - EngineObjLevel4& p4 = p3.next[l4]; - if (! p4.used) continue; + EngineBaseObjDataTier& p4 = p3.next[l4]; + if (! p4.used) + continue; SetMaterial(p4.material); SetState(p4.state); - DrawObject(p4, m_objects[objRank].staticBuffer); + DrawObject(p4); } } } @@ -3537,7 +3451,8 @@ void CEngine::UpdateGroundSpotTextures() m_groundMark.drawPos.x == m_groundMark.pos.x && m_groundMark.drawPos.z == m_groundMark.pos.z && m_groundMark.drawRadius == m_groundMark.radius && - m_groundMark.drawIntensity == m_groundMark.intensity) return; + m_groundMark.drawIntensity == m_groundMark.intensity) + return; for (int s = 0; s < 16; s++) { @@ -3612,11 +3527,12 @@ void CEngine::UpdateGroundSpotTextures() // Draw the new shadows. for (int i = 0; i < static_cast( m_groundSpots.size() ); i++) { - if ( m_groundSpots[i].used == false || - m_groundSpots[i].radius == 0.0f ) continue; + if (m_groundSpots[i].used == false || + m_groundSpots[i].radius == 0.0f) + continue; - if ( m_groundSpots[i].min == 0.0f && - m_groundSpots[i].max == 0.0f ) + if (m_groundSpots[i].min == 0.0f && + m_groundSpots[i].max == 0.0f) { dot = static_cast(m_groundSpots[i].radius/2.0f); @@ -3635,8 +3551,9 @@ void CEngine::UpdateGroundSpotTextures() px = cx-Math::Mod(cx, 1.0f); py = cy-Math::Mod(cy, 1.0f); // multiple of 1 - if ( px+dot < min.x || py+dot < min.y || - px-dot > max.x || py-dot > max.y ) continue; + if (px+dot < min.x || py+dot < min.y || + px-dot > max.x || py-dot > max.y) + continue; for (int iy = -dot; iy <= dot; iy++) { @@ -3645,8 +3562,9 @@ void CEngine::UpdateGroundSpotTextures() float ppx = px+ix; float ppy = py+iy; - if ( ppx < min.x || ppy < min.y || - ppx >= max.x || ppy >= max.y ) continue; + if (ppx < min.x || ppy < min.y || + ppx >= max.x || ppy >= max.y) + continue; float intensity; if (dot == 0) @@ -3678,8 +3596,9 @@ void CEngine::UpdateGroundSpotTextures() pos.y = 0.0f; float level = m_terrain->GetFloorLevel(pos, true); - if ( level < m_groundSpots[i].min || - level > m_groundSpots[i].max ) continue; + if (level < m_groundSpots[i].min || + level > m_groundSpots[i].max) + continue; float intensity; if (level > (m_groundSpots[i].max+m_groundSpots[i].min)/2.0f) @@ -3727,13 +3646,16 @@ void CEngine::UpdateGroundSpotTextures() float ppy = py+iy; if (ppx < min.x || ppy < min.y || - ppx >= max.x || ppy >= max.y) continue; + ppx >= max.x || ppy >= max.y) + continue; ppx -= min.x; // on the texture ppy -= min.y; float intensity = 1.0f - Math::Point(ix, iy).Length() / dot; - if (intensity <= 0.0f) continue; + if (intensity <= 0.0f) + continue; + intensity *= m_groundMark.intensity; int j = (ix+dot) + (iy+dot) * m_groundMark.dx; @@ -3825,11 +3747,13 @@ void CEngine::DrawShadow() float lastIntensity = -1.0f; for (int i = 0; i < static_cast( m_shadows.size() ); i++) { - if (m_shadows[i].hide) continue; + if (m_shadows[i].hide) + continue; Math::Vector pos = m_shadows[i].pos; // pos = center of the shadow on the ground - if (m_eyePt.y == pos.y) continue; // camera at the same level? + if (m_eyePt.y == pos.y) + continue; // camera at the same level? float d = 0.0f; float D = 0.0f; @@ -3845,7 +3769,9 @@ void CEngine::DrawShadow() if ( h > 4.0f ) h = 4.0f; D = Math::Distance(m_eyePt, pos); - if ( D >= endDeepView ) continue; + if (D >= endDeepView) + continue; + d = D*h/height; pos.x += (m_eyePt.x-pos.x)*d/D; @@ -3861,7 +3787,9 @@ void CEngine::DrawShadow() if ( h > 4.0f ) h = 4.0f; D = Math::Distance(m_eyePt, pos); - if ( D >= endDeepView ) continue; + if (D >= endDeepView) + continue; + d = D*h/height; pos.x += (m_eyePt.x-pos.x)*d/D; @@ -3969,7 +3897,8 @@ void CEngine::DrawShadow() if ( D > startDeepView ) intensity *= 1.0f-(D-startDeepView)/(endDeepView-startDeepView); - if (intensity == 0.0f) continue; + if (intensity == 0.0f) + continue; if (lastIntensity != intensity) // intensity changed? { @@ -4091,7 +4020,8 @@ void CEngine::DrawBackgroundImage() void CEngine::DrawPlanet() { - if (! m_planet->PlanetExist()) return; + if (! m_planet->PlanetExist()) + return; m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, false); m_device->SetRenderState(RENDER_STATE_LIGHTING, false); @@ -4106,7 +4036,8 @@ void CEngine::DrawPlanet() void CEngine::DrawForegroundImage() { - if (m_foregroundName.empty()) return; + if (m_foregroundName.empty()) + return; Math::Vector n = Math::Vector(0.0f, 0.0f, -1.0f); // normal @@ -4141,8 +4072,9 @@ void CEngine::DrawForegroundImage() void CEngine::DrawOverColor() { - if ( (m_overColor == Color(0.0f, 0.0f, 0.0f, 0.0f) && m_overMode == ENG_RSTATE_TCOLOR_BLACK) || - (m_overColor == Color(1.0f, 1.0f, 1.0f, 1.0f) && m_overMode == ENG_RSTATE_TCOLOR_WHITE) ) return; + if ((m_overColor == Color(0.0f, 0.0f, 0.0f, 0.0f) && m_overMode == ENG_RSTATE_TCOLOR_BLACK) || + (m_overColor == Color(1.0f, 1.0f, 1.0f, 1.0f) && m_overMode == ENG_RSTATE_TCOLOR_WHITE)) + return; Math::Point p1(0.0f, 0.0f); Math::Point p2(1.0f, 1.0f); diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index de57e4d..ad934a6 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -151,7 +151,7 @@ struct EngineTriangle //! 2nd texture std::string tex2Name; - EngineTriangle() + inline EngineTriangle() { state = ENG_RSTATE_NORMAL; } @@ -178,6 +178,97 @@ enum EngineObjectType ENG_OBJTYPE_METAL = 6 }; + +/** + * \struct EngineBaseObjDataTier + * \brief Tier 4 of object tree (data) + */ +struct EngineBaseObjDataTier +{ + bool used; + EngineTriangleType type; + Material material; + int state; + std::vector vertices; + unsigned int staticBufferId; + bool updateStaticBuffer; + + inline EngineBaseObjDataTier(bool used = false, + EngineTriangleType type = ENG_TRIANGLE_TYPE_TRIANGLES, + const Material& material = Material(), + int state = ENG_RSTATE_NORMAL) + : used(used), type(type), material(material), state(state), staticBufferId(0), updateStaticBuffer(false) {} +}; + +/** + * \struct EngineBaseObjLODTier + * \brief Tier 3 of base object tree (LOD) + */ +struct EngineBaseObjLODTier +{ + bool used; + float min; + float max; + std::vector next; + + inline EngineBaseObjLODTier(bool used = false, float min = 0.0f, float max = 0.0f) + : used(used), min(min), max(max) {} +}; + +/** + * \struct EngineBaseObjTexTier + * \brief Tier 2 of base object tree (textures) + */ +struct EngineBaseObjTexTier +{ + bool used; + std::string tex1Name; + Texture tex1; + std::string tex2Name; + Texture tex2; + std::vector next; + + inline EngineBaseObjTexTier(bool used = false, const std::string& tex1Name = "", + const std::string& tex2Name = "") + : used(used), tex1Name(tex1Name), tex2Name(tex2Name) {} +}; + +/** + * \struct BaseEngineObject + * \brief Base (template) object - geometry for engine objects + * + * This is also the tier 1 of base object tree. + */ +struct EngineBaseObject +{ + //! If true, base object is valid in objects vector + bool used; + //! Number of triangles + int totalTriangles; + //! Bounding box min (origin 0,0,0 always included) + Math::Vector bboxMin; + //! bounding box max (origin 0,0,0 always included) + Math::Vector bboxMax; + //! Radius of the sphere at the origin + float radius; + //! Next tier (LOD) + std::vector next; + + inline EngineBaseObject() + { + LoadDefault(); + } + + inline void LoadDefault() + { + used = false; + totalTriangles = 0; + bboxMax.LoadZero(); + bboxMin.LoadZero(); + radius = 0.0f; + } +}; + /** * \struct EngineObject * \brief Object drawn by the graphics engine @@ -186,35 +277,27 @@ struct EngineObject { //! If true, object is valid in objects vector bool used; + //! Rank of associated base engine object + int baseObjRank; //! If true, the object is drawn bool visible; //! If true, object is behind the 2D interface bool drawWorld; //! If true, the shape is before the 2D interface bool drawFront; - //! Number of triangles - int totalTriangles; //! Type of object EngineObjectType type; - //! Whether the object is stored and rendered as static buffer - bool staticBuffer; //! Transformation matrix Math::Matrix transform; //! Distance to object from eye point float distance; - //! Bounding box min (origin 0,0,0 always included) - Math::Vector bboxMin; - //! bounding box max (origin 0,0,0 always included) - Math::Vector bboxMax; - //! Radius of the sphere at the origin - float radius; //! Rank of the associated shadow int shadowRank; //! Transparency of the object [0, 1] float transparency; //! Calls LoadDefault() - EngineObject() + inline EngineObject() { LoadDefault(); } @@ -223,90 +306,18 @@ struct EngineObject inline void LoadDefault() { used = false; + baseObjRank = -1; visible = false; drawWorld = false; drawFront = false; - totalTriangles = 0; - staticBuffer = false; type = ENG_OBJTYPE_NULL; transform.LoadIdentity(); - bboxMax.LoadZero(); - bboxMin.LoadZero(); distance = 0.0f; - radius = 0.0f; shadowRank = -1; transparency = 0.0f; } }; -struct EngineObjLevel1; -struct EngineObjLevel2; -struct EngineObjLevel3; -struct EngineObjLevel4; - -/** - * \struct EngineObjLevel4 - * \brief Tier 4 of object tree - */ -struct EngineObjLevel4 -{ - bool used; - EngineTriangleType type; - Material material; - int state; - std::vector vertices; - unsigned int staticBufferId; - - EngineObjLevel4(bool used = false, - EngineTriangleType type = ENG_TRIANGLE_TYPE_TRIANGLES, - const Material& material = Material(), - int state = ENG_RSTATE_NORMAL); -}; - -/** - * \struct EngineObjLevel3 - * \brief Tier 3 of object tree - */ -struct EngineObjLevel3 -{ - bool used; - float min; - float max; - std::vector next; - - EngineObjLevel3(bool used = false, float min = 0.0f, float max = 0.0f); -}; - -/** - * \struct EngineObjLevel2 - * \brief Tier 2 of object tree - */ -struct EngineObjLevel2 -{ - bool used; - int objRank; - std::vector next; - - EngineObjLevel2(bool used = false, int objRank = -1); -}; - -/** - * \struct EngineObjLevel1 - * \brief Tier 1 of object tree - */ -struct EngineObjLevel1 -{ - bool used; - std::string tex1Name; - Texture tex1; - std::string tex2Name; - Texture tex2; - std::vector next; - - EngineObjLevel1(bool used = false, const std::string& tex1Name = "", - const std::string& tex2Name = ""); -}; - /** * \struct EngineShadowType * \brief Type of shadow drawn by the graphics engine @@ -346,12 +357,12 @@ struct EngineShadow //! Height from the ground float height; - EngineShadow() + inline EngineShadow() { LoadDefault(); } - void LoadDefault() + inline void LoadDefault() { used = false; hide = false; @@ -388,12 +399,12 @@ struct EngineGroundSpot //! Radius of the shadow drawn float drawRadius; - EngineGroundSpot() + inline EngineGroundSpot() { LoadDefault(); } - void LoadDefault() + inline void LoadDefault() { used = false; color = Color(); @@ -452,12 +463,12 @@ struct EngineGroundMark //! Pointer to the table char* table; - EngineGroundMark() + inline EngineGroundMark() { LoadDefault(); } - void LoadDefault() + inline void LoadDefault() { draw = false; phase = ENG_GR_MARK_PHASE_NULL; @@ -549,10 +560,10 @@ struct EngineMouse //! Hot point Math::Point hotPoint; - EngineMouse(int icon1 = -1, int icon2 = -1, int iconShadow = -1, - EngineRenderState mode1 = ENG_RSTATE_NORMAL, - EngineRenderState mode2 = ENG_RSTATE_NORMAL, - Math::Point hotPoint = Math::Point()) + inline EngineMouse(int icon1 = -1, int icon2 = -1, int iconShadow = -1, + EngineRenderState mode1 = ENG_RSTATE_NORMAL, + EngineRenderState mode2 = ENG_RSTATE_NORMAL, + Math::Point hotPoint = Math::Point()) { this->icon1 = icon1; this->icon2 = icon2; @@ -745,64 +756,73 @@ public: /* *************** Object management *************** */ + // Base objects + + //! Creates a base object and returns its rank + int CreateBaseObject(); + //! Deletes a base object + void DeleteBaseObject(int baseObjRank); + //! Deletes all base objects + void DeleteAllBaseObjects(); + + //! Copies geometry between two base objects + void CopyBaseObject(int sourceBaseObjRank, int destBaseObjRank); + + //! Adds triangles to given object with the specified params + void AddBaseObjTriangles(int baseObjRank, const std::vector& vertices, + EngineTriangleType triangleType, + const Material& material, int state, + std::string tex1Name, std::string tex2Name, + float min, float max, bool globalUpdate); + + //! Adds a tier 4 engine object directly + void AddBaseObjQuick(int baseObjRank, const EngineBaseObjDataTier& buffer, + std::string tex1Name, std::string tex2Name, + float min, float max, bool globalUpdate); + + // Objects + //! Creates a new object and returns its rank int CreateObject(); //! Deletes all objects, shadows and ground spots - void FlushObject(); + void DeleteAllObjects(); //! Deletes the given object - bool DeleteObject(int objRank); + void DeleteObject(int objRank); //@{ - //! Management of engine object type - bool SetObjectType(int objRank, EngineObjectType type); - EngineObjectType GetObjectType(int objRank); + //! Management of the base object rank for engine object + void SetObjectBaseRank(int objRank, int baseObjRank); + int GetObjectBaseRank(int objRank); //@} //@{ - //! Management of object transform - bool SetObjectTransform(int objRank, const Math::Matrix& transform); - bool GetObjectTransform(int objRank, Math::Matrix& transform); + //! Management of engine object type + void SetObjectType(int objRank, EngineObjectType type); + EngineObjectType GetObjectType(int objRank); //@} //@{ - //! Management of object static drawing flag - void SetObjectStatic(int objRank, bool staticBuffer); - bool GetObjectStatic(int objRank); + //! Management of object transform + void SetObjectTransform(int objRank, const Math::Matrix& transform); + void GetObjectTransform(int objRank, Math::Matrix& transform); //@} //! Sets drawWorld for given object - bool SetObjectDrawWorld(int objRank, bool draw); + void SetObjectDrawWorld(int objRank, bool draw); //! Sets drawFront for given object - bool SetObjectDrawFront(int objRank, bool draw); + void SetObjectDrawFront(int objRank, bool draw); //! Sets the transparency level for given object - bool SetObjectTransparency(int objRank, float value); + void SetObjectTransparency(int objRank, float value); //! Returns the bounding box for an object - bool GetObjectBBox(int objRank, Math::Vector& min, Math::Vector& max); + void GetObjectBBox(int objRank, Math::Vector& min, Math::Vector& max); //! Returns the total number of triangles of given object int GetObjectTotalTriangles(int objRank); - //! Adds triangles to given object with the specified params - bool AddTriangles(int objRank, const std::vector& vertices, - const Material& material, int state, - std::string tex1Name, std::string tex2Name, - float min, float max, bool globalUpdate); - - //! Adds a surface to given object with the specified params - bool AddSurface(int objRank, const std::vector& vertices, - const Material& material, int state, - std::string tex1Name, std::string tex2Name, - float min, float max, bool globalUpdate); - - //! Adds a tier 4 engine object directly - bool AddQuick(int objRank, const EngineObjLevel4& buffer, - std::string tex1Name, std::string tex2Name, - float min, float max, bool globalUpdate); - //! Returns the first found tier 4 engine object for the given params or nullptr if not found - EngineObjLevel4* FindTriangles(int objRank, const Material& material, + EngineBaseObjDataTier* FindTriangles(int objRank, const Material& material, int state, std::string tex1Name, std::string tex2Name, float min, float max); @@ -814,16 +834,16 @@ public: void ChangeLOD(); //! Changes the 2nd texure for given object - bool ChangeSecondTexture(int objRank, const std::string& tex2Name); + void ChangeSecondTexture(int objRank, const std::string& tex2Name); //! Changes (recalculates) texture mapping for given object - bool ChangeTextureMapping(int objRank, const Material& mat, int state, + void ChangeTextureMapping(int objRank, const Material& mat, int state, const std::string& tex1Name, const std::string& tex2Name, float min, float max, EngineTextureMapping mode, float au, float bu, float av, float bv); //! Changes texture mapping for robot tracks - bool TrackTextureMapping(int objRank, const Material& mat, int state, + void TrackTextureMapping(int objRank, const Material& mat, int state, const std::string& tex1Name, const std::string& tex2Name, float min, float max, EngineTextureMapping mode, float pos, float factor, float tl, float ts, float tt); @@ -833,20 +853,20 @@ public: int DetectObject(Math::Point mouse); //! Creates a shadow for the given object - bool CreateShadow(int objRank); + void CreateShadow(int objRank); //! Deletes the shadow for given object void DeleteShadow(int objRank); //@{ //! Management of different shadow params - bool SetObjectShadowHide(int objRank, bool hide); - bool SetObjectShadowType(int objRank, EngineShadowType type); - bool SetObjectShadowPos(int objRank, const Math::Vector& pos); - bool SetObjectShadowNormal(int objRank, const Math::Vector& normal); - bool SetObjectShadowAngle(int objRank, float angle); - bool SetObjectShadowRadius(int objRank, float radius); - bool SetObjectShadowIntensity(int objRank, float intensity); - bool SetObjectShadowHeight(int objRank, float height); + void SetObjectShadowHide(int objRank, bool hide); + void SetObjectShadowType(int objRank, EngineShadowType type); + void SetObjectShadowPos(int objRank, const Math::Vector& pos); + void SetObjectShadowNormal(int objRank, const Math::Vector& normal); + void SetObjectShadowAngle(int objRank, float angle); + void SetObjectShadowRadius(int objRank, float radius); + void SetObjectShadowIntensity(int objRank, float intensity); + void SetObjectShadowHeight(int objRank, float height); float GetObjectShadowRadius(int objRank); //@} @@ -856,7 +876,7 @@ public: bool GetHighlight(Math::Point& p1, Math::Point& p2); //! Deletes all ground spots - void FlushGroundSpot(); + void DeleteAllGroundSpots(); //! Creates a new ground spot and returns its rank int CreateGroundSpot(); //! Deletes the given ground spot @@ -864,11 +884,11 @@ public: //@{ //! Management of different ground spot params - bool SetObjectGroundSpotPos(int rank, const Math::Vector& pos); - bool SetObjectGroundSpotRadius(int rank, float radius); - bool SetObjectGroundSpotColor(int rank, const Color& color); - bool SetObjectGroundSpotMinMax(int rank, float min, float max); - bool SetObjectGroundSpotSmooth(int rank, float smooth); + void SetObjectGroundSpotPos(int rank, const Math::Vector& pos); + void SetObjectGroundSpotRadius(int rank, float radius); + void SetObjectGroundSpotColor(int rank, const Color& color); + void SetObjectGroundSpotMinMax(int rank, float min, float max); + void SetObjectGroundSpotSmooth(int rank, float smooth); //@} //! Creates the ground mark with the given params @@ -1162,7 +1182,7 @@ protected: //! Prepares the interface for 3D scene void Draw3DScene(); //! Draw 3D object - void DrawObject(const EngineObjLevel4& obj, bool staticBuffer); + void DrawObject(const EngineBaseObjDataTier& p4); //! Draws the user interface over the scene void DrawInterface(); @@ -1192,15 +1212,13 @@ protected: //! Draw statistic texts void DrawStats(); - //! Creates new tier 1 object - EngineObjLevel1& AddLevel1(const std::string& tex1Name, const std::string& tex2Name); - //! Creates a new tier 2 object - EngineObjLevel2& AddLevel2(EngineObjLevel1 &p1, int objRank); - //! Creates a new tier 3 object - EngineObjLevel3& AddLevel3(EngineObjLevel2 &p2, float min, float max); - //! Creates a new tier 4 object - EngineObjLevel4& AddLevel4(EngineObjLevel3 &p3, EngineTriangleType type, - const Material& mat, int state); + //! Creates a new tier 2 object (texture) + EngineBaseObjTexTier& AddLevel2(int baseObjRank, const std::string& tex1Name, const std::string& tex2Name); + //! Creates a new tier 3 object (LOD) + EngineBaseObjLODTier& AddLevel3(EngineBaseObjTexTier &p2, float min, float max); + //! Creates a new tier 4 object (data) + EngineBaseObjDataTier& AddLevel4(EngineBaseObjLODTier &p3, EngineTriangleType type, + const Material& mat, int state); //! Create texture and add it to cache Texture CreateTexture(const std::string &texName, const TextureCreateParams ¶ms, CImage* image = nullptr); @@ -1227,8 +1245,11 @@ protected: //! Updates geometric parameters of objects (bounding box and radius) void UpdateGeometry(); + //! Updates a given static buffer + void UpdateStaticBuffer(EngineBaseObjDataTier& p4); + //! Updates static buffers of changed objects - void UpdateStaticObjects(); + void UpdateStaticBuffers(); protected: CInstanceManager* m_iMan; @@ -1282,8 +1303,8 @@ protected: //! Previous size of viewport window Math::IntPoint m_lastSize; - //! Root of tree object structure (level 1 list) - std::vector m_objectTree; + //! Base objects (also level 1 tier list) + std::vector m_baseObjects; //! Object parameters std::vector m_objects; //! Shadow list @@ -1308,7 +1329,7 @@ protected: Color m_waterAddColor; int m_statisticTriangle; bool m_updateGeometry; - bool m_updateStaticObjects; + bool m_updateStaticBuffers; int m_alphaMode; bool m_groundSpotVisible; bool m_shadowVisible; diff --git a/src/graphics/engine/modelfile.cpp b/src/graphics/engine/modelfile.cpp index a9972fe..a942b08 100644 --- a/src/graphics/engine/modelfile.cpp +++ b/src/graphics/engine/modelfile.cpp @@ -34,22 +34,10 @@ #include -/* - * NOTE: #ifndef checking for MODELFILE_NO_ENGINE - * is provided in this module to conditionally - * disable dependence on CEngine. - */ - - // Graphics module namespace namespace Gfx { -//! How big the triangle vector is by default -const int TRIANGLE_PREALLOCATE_COUNT = 2000; - - - bool ReadBinaryVertex(std::istream& stream, Vertex& vertex) { vertex.coord.x = IOUtils::ReadBinaryFloat(stream); @@ -322,15 +310,8 @@ bool ReadLineString(std::istream& stream, const std::string& prefix, std::string } -CModelFile::CModelFile(CInstanceManager* iMan) +CModelFile::CModelFile() { - m_iMan = iMan; - -#ifndef MODELFILE_NO_ENGINE - m_engine = static_cast(m_iMan->SearchInstance(CLASS_ENGINE)); -#endif - - m_triangles.reserve(TRIANGLE_PREALLOCATE_COUNT); } CModelFile::~CModelFile() @@ -1155,99 +1136,6 @@ bool CModelFile::WriteBinaryModel(std::ostream& stream) Other stuff *******************************************************/ -#ifndef MODELFILE_NO_ENGINE - - -/** - * TODO: move the function to CEngine or new class (CModelManager?) - * and make models shared static objects. - */ - -bool CModelFile::CreateEngineObject(int objRank) -{ - std::vector vs(3, VertexTex2()); - - m_engine->SetObjectStatic(objRank, true); // TODO: make optional in the future - - float limit[2]; - limit[0] = m_engine->GetLimitLOD(0); // frontier AB as config - limit[1] = m_engine->GetLimitLOD(1); // frontier BC as config - - for (int i = 0; i < static_cast( m_triangles.size() ); i++) - { - float min = m_triangles[i].min; - float max = m_triangles[i].max; - - // Standard frontiers -> config - if (min == 0.0f && max == 100.0f) // resolution A ? - { - max = limit[0]; - } - else if (min == 100.0f && max == 200.0f) // resolution B ? - { - min = limit[0]; - max = limit[1]; - } - else if (min == 200.0f && max == 1000000.0f) // resolution C ? - { - min = limit[1]; - } - - int state = m_triangles[i].state; - std::string tex2Name = m_triangles[i].tex2Name; - - if (m_triangles[i].variableTex2) - { - int texNum = m_engine->GetSecondTexture(); - - if (texNum >= 1 && texNum <= 10) - state |= ENG_RSTATE_DUAL_BLACK; - - if (texNum >= 11 && texNum <= 20) - state |= ENG_RSTATE_DUAL_WHITE; - - char name[20] = { 0 }; - sprintf(name, "dirty%.2d.png", texNum); - tex2Name = name; - } - - vs[0] = m_triangles[i].p1; - vs[1] = m_triangles[i].p2; - vs[2] = m_triangles[i].p3; - - bool ok = m_engine->AddTriangles(objRank, vs, - m_triangles[i].material, - state, - m_triangles[i].tex1Name, - tex2Name, - min, max, false); - if (!ok) - return false; - } - - return true; -} - -#endif - -void CModelFile::Mirror() -{ - for (int i = 0; i < static_cast( m_triangles.size() ); i++) - { - VertexTex2 t = m_triangles[i].p1; - m_triangles[i].p1 = m_triangles[i].p2; - m_triangles[i].p2 = t; - - m_triangles[i].p1.coord.z = -m_triangles[i].p1.coord.z; - m_triangles[i].p2.coord.z = -m_triangles[i].p2.coord.z; - m_triangles[i].p3.coord.z = -m_triangles[i].p3.coord.z; - - m_triangles[i].p1.normal.z = -m_triangles[i].p1.normal.z; - m_triangles[i].p2.normal.z = -m_triangles[i].p2.normal.z; - m_triangles[i].p3.normal.z = -m_triangles[i].p3.normal.z; - } -} - const std::vector& CModelFile::GetTriangles() { return m_triangles; @@ -1258,28 +1146,6 @@ int CModelFile::GetTriangleCount() return m_triangles.size(); } -float CModelFile::GetHeight(Math::Vector pos) -{ - float limit = 5.0f; - - for (int i = 0; i < static_cast( m_triangles.size() ); i++) - { - if ( fabs(pos.x - m_triangles[i].p1.coord.x) < limit && - fabs(pos.z - m_triangles[i].p1.coord.z) < limit ) - return m_triangles[i].p1.coord.y; - - if ( fabs(pos.x - m_triangles[i].p2.coord.x) < limit && - fabs(pos.z - m_triangles[i].p2.coord.z) < limit ) - return m_triangles[i].p2.coord.y; - - if ( fabs(pos.x - m_triangles[i].p3.coord.x) < limit && - fabs(pos.z - m_triangles[i].p3.coord.z) < limit ) - return m_triangles[i].p3.coord.y; - } - - return 0.0f; -} - void CModelFile::CreateTriangle(Math::Vector p1, Math::Vector p2, Math::Vector p3, float min, float max) { ModelTriangle triangle; diff --git a/src/graphics/engine/modelfile.h b/src/graphics/engine/modelfile.h index 6c573b8..b2b5d87 100644 --- a/src/graphics/engine/modelfile.h +++ b/src/graphics/engine/modelfile.h @@ -33,14 +33,10 @@ #include -class CInstanceManager; - // Graphics module namespace namespace Gfx { -class CEngine; - /** \struct ModelTriangle @@ -79,14 +75,15 @@ struct ModelTriangle /** - \class CModelFile - \brief Model file reader/writer - - Allows reading and writing model objects. Models are collections of ModelTriangle structs. */ + * \class CModelFile + * \brief Model file reader/writer + * + * Allows reading and writing model objects. Models are collections of ModelTriangle structs. + */ class CModelFile { public: - CModelFile(CInstanceManager* iMan); + CModelFile(); ~CModelFile(); //! Reads a model in text format from file @@ -128,23 +125,11 @@ public: //! Returns the triangle vector const std::vector& GetTriangles(); - //! Returns the height of model -- closest point to X and Z coords of \a pos - float GetHeight(Math::Vector pos); - - //! Mirrors the model along the Z axis - void Mirror(); - - //! Creates an object in the graphics engine from the model - bool CreateEngineObject(int objRank); - protected: //! Adds a triangle to the list void CreateTriangle(Math::Vector p1, Math::Vector p2, Math::Vector p3, float min, float max); protected: - CInstanceManager* m_iMan; - CEngine* m_engine; - //! Model triangles std::vector m_triangles; }; diff --git a/src/graphics/engine/modelmanager.cpp b/src/graphics/engine/modelmanager.cpp new file mode 100644 index 0000000..afaa718 --- /dev/null +++ b/src/graphics/engine/modelmanager.cpp @@ -0,0 +1,213 @@ +#include "graphics/engine/modelmanager.h" + +#include "app/app.h" + +#include "common/logger.h" + +#include "graphics/engine/engine.h" + +#include + +namespace Gfx { + +template<> CModelManager* CSingleton::mInstance = nullptr; + +CModelManager::CModelManager(CEngine* engine) +{ + m_engine = engine; +} + +CModelManager::~CModelManager() +{ +} + +bool CModelManager::LoadModel(const std::string& fileName, bool mirrored) +{ + GetLogger()->Info("Loading model '%s'\n", fileName.c_str()); + + CModelFile modelFile; + + std::string filePath = CApplication::GetInstance().GetDataFilePath(DIR_MODEL, fileName); + + if (!modelFile.ReadModel(filePath)) + { + GetLogger()->Error("Loading model '%s' failed\n", filePath.c_str()); + return false; + } + + ModelInfo modelInfo; + modelInfo.baseObjRank = m_engine->CreateBaseObject(); + modelInfo.triangles = modelFile.GetTriangles(); + + if (mirrored) + Mirror(modelInfo.triangles); + + FileInfo fileInfo(fileName, mirrored); + m_models[fileInfo] = modelInfo; + + std::vector vs(3, VertexTex2()); + + float limit[2]; + limit[0] = m_engine->GetLimitLOD(0); // frontier AB as config + limit[1] = m_engine->GetLimitLOD(1); // frontier BC as config + + for (int i = 0; i < static_cast( modelInfo.triangles.size() ); i++) + { + float min = modelInfo.triangles[i].min; + float max = modelInfo.triangles[i].max; + + // Standard frontiers -> config + if (min == 0.0f && max == 100.0f) // resolution A ? + { + max = limit[0]; + } + else if (min == 100.0f && max == 200.0f) // resolution B ? + { + min = limit[0]; + max = limit[1]; + } + else if (min == 200.0f && max == 1000000.0f) // resolution C ? + { + min = limit[1]; + } + + int state = modelInfo.triangles[i].state; + std::string tex2Name = modelInfo.triangles[i].tex2Name; + + if (modelInfo.triangles[i].variableTex2) + { + int texNum = m_engine->GetSecondTexture(); + + if (texNum >= 1 && texNum <= 10) + state |= ENG_RSTATE_DUAL_BLACK; + + if (texNum >= 11 && texNum <= 20) + state |= ENG_RSTATE_DUAL_WHITE; + + char name[20] = { 0 }; + sprintf(name, "dirty%.2d.png", texNum); + tex2Name = name; + } + + vs[0] = modelInfo.triangles[i].p1; + vs[1] = modelInfo.triangles[i].p2; + vs[2] = modelInfo.triangles[i].p3; + + m_engine->AddBaseObjTriangles(modelInfo.baseObjRank, vs, ENG_TRIANGLE_TYPE_TRIANGLES, + modelInfo.triangles[i].material, state, + modelInfo.triangles[i].tex1Name, tex2Name, + min, max, false); + } + + return true; +} + +bool CModelManager::AddModelReference(const std::string& fileName, bool mirrored, int objRank) +{ + auto it = m_models.find(FileInfo(fileName, mirrored)); + if (it == m_models.end()) + { + if (!LoadModel(fileName, mirrored)) + return false; + + it = m_models.find(FileInfo(fileName, mirrored)); + } + + m_engine->SetObjectBaseRank(objRank, (*it).second.baseObjRank); + + return true; +} + +bool CModelManager::AddModelCopy(const std::string& fileName, bool mirrored, int objRank) +{ + auto it = m_models.find(FileInfo(fileName, mirrored)); + if (it == m_models.end()) + { + if (!LoadModel(fileName, mirrored)) + return false; + + it = m_models.find(FileInfo(fileName, mirrored)); + } + + int copyBaseObjRank = m_engine->CreateBaseObject(); + m_engine->CopyBaseObject((*it).second.baseObjRank, copyBaseObjRank); + m_engine->SetObjectBaseRank(objRank, copyBaseObjRank); + + return true; +} + +bool CModelManager::IsModelLoaded(const std::string& fileName, bool mirrored) +{ + return m_models.count(FileInfo(fileName, mirrored)) > 0; +} + +int CModelManager::GetModelBaseObjRank(const std::string& fileName, bool mirrored) +{ + auto it = m_models.find(FileInfo(fileName, mirrored)); + if (it == m_models.end()) + return -1; + + return (*it).second.baseObjRank; +} + +void CModelManager::UnloadModel(const std::string& fileName, bool mirrored) +{ + auto it = m_models.find(FileInfo(fileName, mirrored)); + if (it == m_models.end()) + return; + + m_engine->DeleteBaseObject((*it).second.baseObjRank); + + m_models.erase(it); +} + +void CModelManager::UnloadAllModels() +{ + for (auto& mf : m_models) + m_engine->DeleteBaseObject(mf.second.baseObjRank); + + m_models.clear(); +} + +void CModelManager::Mirror(std::vector& triangles) +{ + for (int i = 0; i < static_cast( triangles.size() ); i++) + { + VertexTex2 t = triangles[i].p1; + triangles[i].p1 = triangles[i].p2; + triangles[i].p2 = t; + + triangles[i].p1.coord.z = -triangles[i].p1.coord.z; + triangles[i].p2.coord.z = -triangles[i].p2.coord.z; + triangles[i].p3.coord.z = -triangles[i].p3.coord.z; + + triangles[i].p1.normal.z = -triangles[i].p1.normal.z; + triangles[i].p2.normal.z = -triangles[i].p2.normal.z; + triangles[i].p3.normal.z = -triangles[i].p3.normal.z; + } +} + +float CModelManager::GetHeight(std::vector& triangles, Math::Vector pos) +{ + const float limit = 5.0f; + + for (int i = 0; i < static_cast( triangles.size() ); i++) + { + if ( fabs(pos.x - triangles[i].p1.coord.x) < limit && + fabs(pos.z - triangles[i].p1.coord.z) < limit ) + return triangles[i].p1.coord.y; + + if ( fabs(pos.x - triangles[i].p2.coord.x) < limit && + fabs(pos.z - triangles[i].p2.coord.z) < limit ) + return triangles[i].p2.coord.y; + + if ( fabs(pos.x - triangles[i].p3.coord.x) < limit && + fabs(pos.z - triangles[i].p3.coord.z) < limit ) + return triangles[i].p3.coord.y; + } + + return 0.0f; +} + + +} diff --git a/src/graphics/engine/modelmanager.h b/src/graphics/engine/modelmanager.h new file mode 100644 index 0000000..601d636 --- /dev/null +++ b/src/graphics/engine/modelmanager.h @@ -0,0 +1,97 @@ +#pragma once + +#include "common/singleton.h" + +#include "graphics/engine/modelfile.h" + +#include +#include +#include + +namespace Gfx { + +class CEngine; +class CModelFile; + +/** + * \class CModelManager + * \brief Manager for static models + * + * The manager allows for loading models as static objects and adding + * new instances of models to the engine. + * + * The models are loaded from stanard application model directory and + * they are identified by unique file names. + * + * The models are loaded by creating (if it doesn't exist yet) + * a base engine object from the model geometry. This base object + * is then shared among all instances of this model with the instances + * being engine objects linked to the shared base object. + * + * There is also a possibility of creating a copy of model so it has + * its own and unique base engine object. This is especially useful + * for models where the geometry must be altered. + */ +class CModelManager : public CSingleton +{ +public: + CModelManager(CEngine* engine); + ~CModelManager(); + + //! Loads a model from given file + bool LoadModel(const std::string& fileName, bool mirrored); + + //! Adds an instance of model to the given object rank as a reference to base object + bool AddModelReference(const std::string& fileName, bool mirrored, int objRank); + + //! Adds an instance of model to the given object rank as a copy (copied base object) + bool AddModelCopy(const std::string& fileName, bool mirrored, int objRank); + + //! Returns true if given model is loaded + bool IsModelLoaded(const std::string& fileName, bool mirrored); + + //! Returns the rank of base engine object of given loaded model + int GetModelBaseObjRank(const std::string& fileName, bool mirrored); + + //! Unloads the given model + void UnloadModel(const std::string& fileName, bool mirrored); + //! Unloads all models + void UnloadAllModels(); + +protected: + //! Returns the height of model -- closest point to X and Z coords of \a pos + float GetHeight(std::vector& triangles, Math::Vector pos); + + //! Mirrors the model along the Z axis + void Mirror(std::vector& triangles); + +private: + struct ModelInfo + { + std::vector triangles; + int baseObjRank; + }; + struct FileInfo + { + std::string fileName; + bool mirrored; + + inline FileInfo(const std::string& fileName, bool mirrored) + : fileName(fileName), mirrored(mirrored) {} + + inline bool operator<(const FileInfo& other) const + { + int compare = fileName.compare(other.fileName); + if (compare < 0) + return true; + if (compare > 0) + return false; + + return !mirrored && mirrored != other.mirrored; + } + }; + std::map m_models; + CEngine* m_engine; +}; + +} // namespace Gfx diff --git a/src/graphics/engine/pyro.cpp b/src/graphics/engine/pyro.cpp index 73c5cec..978471b 100644 --- a/src/graphics/engine/pyro.cpp +++ b/src/graphics/engine/pyro.cpp @@ -363,7 +363,6 @@ bool CPyro::Create(PyroType type, CObject* obj, float force) m_type == PT_EXPLOW ) { CreateTriangle(obj, oType, 0); - m_engine->SetObjectStatic(m_object->GetObjectRank(0), false); m_engine->DeleteShadow(m_object->GetObjectRank(0)); ExploStart(); } @@ -1398,8 +1397,6 @@ void CPyro::CreateTriangle(CObject* obj, ObjectType oType, int part) int objRank = obj->GetObjectRank(part); if (objRank == -1) return; - m_engine->SetObjectStatic(objRank, false); - float min = 0.0f; float max = m_engine->GetLimitLOD(0); int total = m_engine->GetObjectTotalTriangles(objRank); diff --git a/src/graphics/engine/terrain.cpp b/src/graphics/engine/terrain.cpp index 0e77ea2..a66b4b0 100644 --- a/src/graphics/engine/terrain.cpp +++ b/src/graphics/engine/terrain.cpp @@ -34,10 +34,6 @@ // Graphics module namespace namespace Gfx { -const int LEVEL_MAT_PREALLOCATE_COUNT = 101; -const int FLYING_LIMIT_PREALLOCATE_COUNT = 10; -const int BUILDING_LEVEL_PREALLOCATE_COUNT = 101; - CTerrain::CTerrain(CInstanceManager* iMan) { @@ -60,10 +56,6 @@ CTerrain::CTerrain(CInstanceManager* iMan) m_defaultHardness = 0.5f; m_useMaterials = false; - m_materials.reserve(LEVEL_MAT_PREALLOCATE_COUNT); - m_flyingLimits.reserve(FLYING_LIMIT_PREALLOCATE_COUNT); - m_buildingLevels.reserve(BUILDING_LEVEL_PREALLOCATE_COUNT); - FlushBuildingLevel(); FlushFlyingLimit(); FlushMaterials(); @@ -498,6 +490,13 @@ bool CTerrain::CreateMosaic(int ox, int oy, int step, int objRank, const Material &mat, float min, float max) { + int baseObjRank = m_engine->GetObjectBaseRank(objRank); + if (baseObjRank == -1) + { + baseObjRank = m_engine->CreateBaseObject(); + m_engine->SetObjectBaseRank(objRank, baseObjRank); + } + std::string texName1; std::string texName2; @@ -547,7 +546,7 @@ bool CTerrain::CreateMosaic(int ox, int oy, int step, int objRank, for (int y = 0; y < brick; y += step) { - EngineObjLevel4 buffer; + EngineBaseObjDataTier buffer; buffer.vertices.reserve(total); buffer.type = ENG_TRIANGLE_TYPE_SURFACE; @@ -640,7 +639,8 @@ bool CTerrain::CreateMosaic(int ox, int oy, int step, int objRank, buffer.vertices.push_back(p1); buffer.vertices.push_back(p2); } - m_engine->AddQuick(objRank, buffer, texName1, texName2, min, max, true); + + m_engine->AddBaseObjQuick(baseObjRank, buffer, texName1, texName2, min, max, true); } } } @@ -1168,10 +1168,6 @@ bool CTerrain::CreateSquare(int x, int y) int objRank = m_engine->CreateObject(); m_engine->SetObjectType(objRank, ENG_OBJTYPE_TERRAIN); - // TODO: create a static object, but not split into squares, but a single object for all terrain - // Squares should be sub-objects accessing parts of triangle list - // m_engine->SetObjectStatic(objRank, true); - m_objRanks[x+y*m_mosaicCount] = objRank; float min = 0.0f; @@ -1278,7 +1274,10 @@ bool CTerrain::Terraform(const Math::Vector &p1, const Math::Vector &p2, float h { for (int x = pp1.x; x <= pp2.x; x++) { - m_engine->DeleteObject(m_objRanks[x+y*m_mosaicCount]); + int objRank = m_objRanks[x+y*m_mosaicCount]; + int baseObjRank = m_engine->GetObjectBaseRank(objRank); + m_engine->DeleteBaseObject(baseObjRank); + m_engine->DeleteObject(objRank); CreateSquare(x, y); // recreates the square } } diff --git a/src/graphics/engine/terrain.h b/src/graphics/engine/terrain.h index 3012e62..e17144e 100644 --- a/src/graphics/engine/terrain.h +++ b/src/graphics/engine/terrain.h @@ -328,7 +328,7 @@ protected: //! Calculates a vector of the terrain Math::Vector GetVector(int x, int y); //! Calculates a vertex of the terrain - VertexTex2 GetVertex(int x, int y, int step); + VertexTex2 GetVertex(int x, int y, int step); //! Creates all objects of a mosaic bool CreateMosaic(int ox, int oy, int step, int objRank, const Material& mat, float min, float max); //! Creates all objects in a mesh square ground diff --git a/src/graphics/engine/test/CMakeLists.txt b/src/graphics/engine/test/CMakeLists.txt index 4e3263b..b1db2c7 100644 --- a/src/graphics/engine/test/CMakeLists.txt +++ b/src/graphics/engine/test/CMakeLists.txt @@ -8,7 +8,6 @@ modelfile_test.cpp ../modelfile.cpp ../../../common/logger.cpp ../../../common/stringutils.cpp -../../../common/iman.cpp ) add_definitions(-DMODELFILE_NO_ENGINE) diff --git a/src/graphics/engine/test/modelfile_test.cpp b/src/graphics/engine/test/modelfile_test.cpp index 6879a1b..43cd43b 100644 --- a/src/graphics/engine/test/modelfile_test.cpp +++ b/src/graphics/engine/test/modelfile_test.cpp @@ -15,12 +15,11 @@ // * along with this program. If not, see http://www.gnu.org/licenses/. -#include "common/iman.h" #include "common/logger.h" #include "graphics/engine/modelfile.h" #include "math/func.h" -#include "gtest/gtest.h" +#include #include #include @@ -190,8 +189,7 @@ TEST(ModelFileTest, RWTxtModel) std::stringstream str; str.str(TEXT_MODEL); - CInstanceManager iMan; - Gfx::CModelFile modelFile(&iMan); + Gfx::CModelFile modelFile; EXPECT_TRUE(modelFile.ReadTextModel(str)); @@ -216,8 +214,7 @@ TEST(ModelFileTest, RWBinModel) std::stringstream str; str.str(TEXT_MODEL); - CInstanceManager iMan; - Gfx::CModelFile modelFile(&iMan); + Gfx::CModelFile modelFile; EXPECT_TRUE(modelFile.ReadTextModel(str)); @@ -242,8 +239,7 @@ TEST(ModelFileTest, RWOldModel) std::stringstream str; str.str(TEXT_MODEL); - CInstanceManager iMan; - Gfx::CModelFile modelFile(&iMan); + Gfx::CModelFile modelFile; EXPECT_TRUE(modelFile.ReadTextModel(str)); diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index 2d284d0..c1e18d3 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -949,7 +949,7 @@ void CGLDevice::DrawPrimitive(PrimitiveType type, const VertexCol *vertices, int glDisableClientState(GL_COLOR_ARRAY); } -unsigned int CGLDevice::CreateStaticObject(PrimitiveType primitiveType, const Vertex* vertices, int vertexCount) +unsigned int CGLDevice::CreateStaticBuffer(PrimitiveType primitiveType, const Vertex* vertices, int vertexCount) { unsigned int id = 0; if (m_useVbo) @@ -983,7 +983,7 @@ unsigned int CGLDevice::CreateStaticObject(PrimitiveType primitiveType, const Ve return id; } -unsigned int CGLDevice::CreateStaticObject(PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount) +unsigned int CGLDevice::CreateStaticBuffer(PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount) { unsigned int id = 0; if (m_useVbo) @@ -1017,7 +1017,7 @@ unsigned int CGLDevice::CreateStaticObject(PrimitiveType primitiveType, const Ve return id; } -unsigned int CGLDevice::CreateStaticObject(PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount) +unsigned int CGLDevice::CreateStaticBuffer(PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount) { unsigned int id = 0; if (m_useVbo) @@ -1051,11 +1051,92 @@ unsigned int CGLDevice::CreateStaticObject(PrimitiveType primitiveType, const Ve return id; } -void CGLDevice::DrawStaticObject(unsigned int objectId) +void CGLDevice::UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const Vertex* vertices, int vertexCount) { if (m_useVbo) { - auto it = m_vboObjects.find(objectId); + auto it = m_vboObjects.find(bufferId); + if (it == m_vboObjects.end()) + return; + + VboObjectInfo& info = (*it).second; + info.primitiveType = primitiveType; + info.vertexType = VERTEX_TYPE_NORMAL; + info.vertexCount = vertexCount; + + glBindBuffer(GL_ARRAY_BUFFER, info.bufferId); + glBufferData(GL_ARRAY_BUFFER, vertexCount * sizeof(Vertex), vertices, GL_STATIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); + } + else + { + glNewList(bufferId, GL_COMPILE); + + DrawPrimitive(primitiveType, vertices, vertexCount); + + glEndList(); + } +} + +void CGLDevice::UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount) +{ + if (m_useVbo) + { + auto it = m_vboObjects.find(bufferId); + if (it == m_vboObjects.end()) + return; + + VboObjectInfo& info = (*it).second; + info.primitiveType = primitiveType; + info.vertexType = VERTEX_TYPE_TEX2; + info.vertexCount = vertexCount; + + glBindBuffer(GL_ARRAY_BUFFER, info.bufferId); + glBufferData(GL_ARRAY_BUFFER, vertexCount * sizeof(VertexTex2), vertices, GL_STATIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); + } + else + { + glNewList(bufferId, GL_COMPILE); + + DrawPrimitive(primitiveType, vertices, vertexCount); + + glEndList(); + } +} + +void CGLDevice::UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount) +{ + if (m_useVbo) + { + auto it = m_vboObjects.find(bufferId); + if (it == m_vboObjects.end()) + return; + + VboObjectInfo& info = (*it).second; + info.primitiveType = primitiveType; + info.vertexType = VERTEX_TYPE_COL; + info.vertexCount = vertexCount; + + glBindBuffer(GL_ARRAY_BUFFER, info.bufferId); + glBufferData(GL_ARRAY_BUFFER, vertexCount * sizeof(VertexCol), vertices, GL_STATIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); + } + else + { + glNewList(bufferId, GL_COMPILE); + + DrawPrimitive(primitiveType, vertices, vertexCount); + + glEndList(); + } +} + +void CGLDevice::DrawStaticBuffer(unsigned int bufferId) +{ + if (m_useVbo) + { + auto it = m_vboObjects.find(bufferId); if (it == m_vboObjects.end()) return; @@ -1127,15 +1208,15 @@ void CGLDevice::DrawStaticObject(unsigned int objectId) } else { - glCallList(objectId); + glCallList(bufferId); } } -void CGLDevice::DestroyStaticObject(unsigned int objectId) +void CGLDevice::DestroyStaticBuffer(unsigned int bufferId) { if (m_useVbo) { - auto it = m_vboObjects.find(objectId); + auto it = m_vboObjects.find(bufferId); if (it == m_vboObjects.end()) return; @@ -1145,7 +1226,7 @@ void CGLDevice::DestroyStaticObject(unsigned int objectId) } else { - glDeleteLists(objectId, 1); + glDeleteLists(bufferId, 1); } } diff --git a/src/graphics/opengl/gldevice.h b/src/graphics/opengl/gldevice.h index adae41b..dd43f2c 100644 --- a/src/graphics/opengl/gldevice.h +++ b/src/graphics/opengl/gldevice.h @@ -129,11 +129,14 @@ public: Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)); virtual void DrawPrimitive(PrimitiveType type, const VertexCol *vertices , int vertexCount); - virtual unsigned int CreateStaticObject(PrimitiveType primitiveType, const Vertex* vertices, int vertexCount); - virtual unsigned int CreateStaticObject(PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount); - virtual unsigned int CreateStaticObject(PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount); - virtual void DrawStaticObject(unsigned int objectId); - virtual void DestroyStaticObject(unsigned int objectId); + virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const Vertex* vertices, int vertexCount); + virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount); + virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount); + virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const Vertex* vertices, int vertexCount); + virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount); + virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount); + virtual void DrawStaticBuffer(unsigned int bufferId); + virtual void DestroyStaticBuffer(unsigned int bufferId); virtual int ComputeSphereVisibility(const Math::Vector ¢er, float radius); diff --git a/src/object/motion/motionant.cpp b/src/object/motion/motionant.cpp index 07ee6b8..db8ff37 100644 --- a/src/object/motion/motionant.cpp +++ b/src/object/motion/motionant.cpp @@ -19,7 +19,7 @@ #include "app/app.h" -#include "graphics/engine/modelfile.h" +#include "graphics/engine/modelmanager.h" #include "graphics/engine/particle.h" #include "physics/physics.h" @@ -69,12 +69,8 @@ void CMotionAnt::DeleteObject(bool bAll) bool CMotionAnt::Create(Math::Vector pos, float angle, ObjectType type, float power) { - Gfx::CModelFile* pModFile; - int rank; - -// if ( m_engine->GetRestCreate() < 3+18 ) return false; - - pModFile = new Gfx::CModelFile(m_iMan); + Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer(); + int rank; m_object->SetType(type); @@ -82,10 +78,7 @@ bool CMotionAnt::Create(Math::Vector pos, float angle, ObjectType type, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICULE); // this is a moving object m_object->SetObjectRank(0, rank); - - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant1.mod")); - pModFile->CreateEngineObject(rank); - + modelManager->AddModelReference("ant1.mod", false, rank); m_object->SetPosition(0, pos); m_object->SetAngleY(0, angle); @@ -96,29 +89,26 @@ bool CMotionAnt::Create(Math::Vector pos, float angle, ObjectType type, // Creates the head. rank = m_engine->CreateObject(); - m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(1, rank); m_object->SetObjectParent(1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant2.mod", false, rank); m_object->SetPosition(1, Math::Vector(2.0f, 0.0f, 0.0f)); // Creates the tail. rank = m_engine->CreateObject(); - m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(2, rank); m_object->SetObjectParent(2, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant3.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant3.mod", false, rank); m_object->SetPosition(2, Math::Vector(-1.0f, 0.0f, 0.0f)); // Creates a right-back thigh. rank = m_engine->CreateObject(); - m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(3, rank); m_object->SetObjectParent(3, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant4.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant4.mod", false, rank); m_object->SetPosition(3, Math::Vector(-0.4f, -0.1f, -0.3f)); // Creates a right-back leg. @@ -126,161 +116,135 @@ bool CMotionAnt::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(4, rank); m_object->SetObjectParent(4, 3); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant5.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant5.mod", false, rank); m_object->SetPosition(4, Math::Vector(0.0f, 0.0f, -1.0f)); // Creates a right-back foot. rank = m_engine->CreateObject(); - m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(5, rank); m_object->SetObjectParent(5, 4); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant6.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant6.mod", false, rank); m_object->SetPosition(5, Math::Vector(0.0f, 0.0f, -2.0f)); // Creates two middle-right thighs. rank = m_engine->CreateObject(); - m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(6, rank); m_object->SetObjectParent(6, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant4.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant4.mod", false, rank); m_object->SetPosition(6, Math::Vector(0.1f, -0.1f, -0.4f)); // Creates two middle-right legs. rank = m_engine->CreateObject(); - m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(7, rank); m_object->SetObjectParent(7, 6); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant5.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant5.mod", false, rank); m_object->SetPosition(7, Math::Vector(0.0f, 0.0f, -1.0f)); // Creates two middle-right foots. rank = m_engine->CreateObject(); - m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(8, rank); m_object->SetObjectParent(8, 7); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant6.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant6.mod", false, rank); m_object->SetPosition(8, Math::Vector(0.0f, 0.0f, -2.0f)); // Creates the right front thigh. rank = m_engine->CreateObject(); - m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(9, rank); m_object->SetObjectParent(9, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant4.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant4.mod", false, rank); m_object->SetPosition(9, Math::Vector(1.4f, -0.1f, -0.6f)); // Creates the right front leg. rank = m_engine->CreateObject(); - m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(10, rank); m_object->SetObjectParent(10, 9); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant5.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant5.mod", false, rank); m_object->SetPosition(10, Math::Vector(0.0f, 0.0f, -1.0f)); // Creates the right front foot. rank = m_engine->CreateObject(); - m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(11, rank); m_object->SetObjectParent(11, 10); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant6.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant6.mod", false, rank); m_object->SetPosition(11, Math::Vector(0.0f, 0.0f, -2.0f)); // Creates a left-back thigh. rank = m_engine->CreateObject(); - m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(12, rank); m_object->SetObjectParent(12, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant4.mod")); - pModFile->Mirror(); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant4.mod", true, rank); m_object->SetPosition(12, Math::Vector(-0.4f, -0.1f, 0.3f)); // Creates a left-back leg. rank = m_engine->CreateObject(); - m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(13, rank); m_object->SetObjectParent(13, 12); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant5.mod")); - pModFile->Mirror(); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant5.mod", true, rank); m_object->SetPosition(13, Math::Vector(0.0f, 0.0f, 1.0f)); // Creates a left-back foot. rank = m_engine->CreateObject(); - m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(14, rank); m_object->SetObjectParent(14, 13); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant6.mod")); - pModFile->Mirror(); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant6.mod", true, rank); m_object->SetPosition(14, Math::Vector(0.0f, 0.0f, 2.0f)); // Creates two middle-left thighs. rank = m_engine->CreateObject(); - m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(15, rank); m_object->SetObjectParent(15, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant4.mod")); - pModFile->Mirror(); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant4.mod", true, rank); m_object->SetPosition(15, Math::Vector(0.1f, -0.1f, 0.4f)); // Creates two middle-left legs. rank = m_engine->CreateObject(); - m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(16, rank); m_object->SetObjectParent(16, 15); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant5.mod")); - pModFile->Mirror(); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant5.mod", true, rank); m_object->SetPosition(16, Math::Vector(0.0f, 0.0f, 1.0f)); // Creates two middle-left foot. rank = m_engine->CreateObject(); - m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(17, rank); m_object->SetObjectParent(17, 16); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant6.mod")); - pModFile->Mirror(); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant6.mod", true, rank); m_object->SetPosition(17, Math::Vector(0.0f, 0.0f, 2.0f)); // Creates the left front thigh. rank = m_engine->CreateObject(); - m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(18, rank); m_object->SetObjectParent(18, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant4.mod")); - pModFile->Mirror(); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant4.mod", true, rank); m_object->SetPosition(18, Math::Vector(1.4f, -0.1f, 0.6f)); // Creates the left front leg. rank = m_engine->CreateObject(); - m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(19, rank); m_object->SetObjectParent(19, 18); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant5.mod")); - pModFile->Mirror(); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant5.mod", true, rank); m_object->SetPosition(19, Math::Vector(0.0f, 0.0f, 1.0f)); // Creates the left front foot. rank = m_engine->CreateObject(); - m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(20, rank); m_object->SetObjectParent(20, 19); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant6.mod")); - pModFile->Mirror(); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant6.mod", true, rank); m_object->SetPosition(20, Math::Vector(0.0f, 0.0f, 2.0f)); m_object->CreateShadowCircle(4.0f, 0.5f); @@ -293,7 +257,6 @@ bool CMotionAnt::Create(Math::Vector pos, float angle, ObjectType type, m_engine->LoadAllTextures(); - delete pModFile; return true; } diff --git a/src/object/motion/motionbee.cpp b/src/object/motion/motionbee.cpp index a3421b8..111339d 100644 --- a/src/object/motion/motionbee.cpp +++ b/src/object/motion/motionbee.cpp @@ -19,7 +19,7 @@ #include "app/app.h" -#include "graphics/engine/modelfile.h" +#include "graphics/engine/modelmanager.h" #include "physics/physics.h" @@ -67,12 +67,8 @@ void CMotionBee::DeleteObject(bool bAll) bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type, float power) { - Gfx::CModelFile* pModFile; - int rank; - -// if ( m_engine->GetRestCreate() < 3+18+2 ) return false; - - pModFile = new Gfx::CModelFile(m_iMan); + Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer(); + int rank; m_object->SetType(type); @@ -80,10 +76,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICULE); // this is a moving object m_object->SetObjectRank(0, rank); - - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "bee1.mod")); - pModFile->CreateEngineObject(rank); - + modelManager->AddModelReference("bee1.mod", false, rank); m_object->SetPosition(0, pos); m_object->SetAngleY(0, angle); @@ -97,8 +90,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(1, rank); m_object->SetObjectParent(1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "bee2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("bee2.mod", false, rank); m_object->SetPosition(1, Math::Vector(1.6f, 0.3f, 0.0f)); // Creates the tail. @@ -106,8 +98,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(2, rank); m_object->SetObjectParent(2, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "bee3.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("bee3.mod", false, rank); m_object->SetPosition(2, Math::Vector(-0.8f, 0.0f, 0.0f)); // Creates a right-back thigh. @@ -115,8 +106,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(3, rank); m_object->SetObjectParent(3, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant4.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant4.mod", false, rank); m_object->SetPosition(3, Math::Vector(-0.3f, -0.1f, -0.2f)); // Creates a right-back leg. @@ -124,8 +114,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(4, rank); m_object->SetObjectParent(4, 3); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant5.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant5.mod", false, rank); m_object->SetPosition(4, Math::Vector(0.0f, 0.0f, -1.0f)); // Creates a right-back foot. @@ -133,8 +122,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(5, rank); m_object->SetObjectParent(5, 4); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant6.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant6.mod", false, rank); m_object->SetPosition(5, Math::Vector(0.0f, 0.0f, -2.0f)); // Creates two middle-right thighs. @@ -142,8 +130,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(6, rank); m_object->SetObjectParent(6, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant4.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant4.mod", false, rank); m_object->SetPosition(6, Math::Vector(0.3f, -0.1f, -0.4f)); // Creates two middle-right legs. @@ -151,8 +138,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(7, rank); m_object->SetObjectParent(7, 6); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant5.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant5.mod", false, rank); m_object->SetPosition(7, Math::Vector(0.0f, 0.0f, -1.0f)); // Creates two middle-right feet. @@ -160,8 +146,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(8, rank); m_object->SetObjectParent(8, 7); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant6.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant6.mod", false, rank); m_object->SetPosition(8, Math::Vector(0.0f, 0.0f, -2.0f)); // Creates the right front thigh. @@ -169,8 +154,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(9, rank); m_object->SetObjectParent(9, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant4.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant4.mod", false, rank); m_object->SetPosition(9, Math::Vector(1.0f, -0.1f, -0.7f)); // Creates the right front leg. @@ -178,8 +162,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(10, rank); m_object->SetObjectParent(10, 9); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant5.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant5.mod", false, rank); m_object->SetPosition(10, Math::Vector(0.0f, 0.0f, -1.0f)); // Creates the right front foot. @@ -187,8 +170,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(11, rank); m_object->SetObjectParent(11, 10); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant6.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant6.mod", false, rank); m_object->SetPosition(11, Math::Vector(0.0f, 0.0f, -2.0f)); // Creates a left-back thigh. @@ -196,8 +178,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(12, rank); m_object->SetObjectParent(12, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant4.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant4.mod", false, rank); m_object->SetPosition(12, Math::Vector(-0.3f, -0.1f, 0.2f)); m_object->SetAngleY(12, Math::PI); @@ -206,8 +187,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(13, rank); m_object->SetObjectParent(13, 12); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant5.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant5.mod", false, rank); m_object->SetPosition(13, Math::Vector(0.0f, 0.0f, -1.0f)); // Creates a left-back foot. @@ -215,8 +195,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(14, rank); m_object->SetObjectParent(14, 13); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant6.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant6.mod", false, rank); m_object->SetPosition(14, Math::Vector(0.0f, 0.0f, -2.0f)); // Creates two middle-left thigh. @@ -224,8 +203,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(15, rank); m_object->SetObjectParent(15, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant4.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant4.mod", false, rank); m_object->SetPosition(15, Math::Vector(0.3f, -0.1f, 0.4f)); m_object->SetAngleY(15, Math::PI); @@ -234,8 +212,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(16, rank); m_object->SetObjectParent(16, 15); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant5.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant5.mod", false, rank); m_object->SetPosition(16, Math::Vector(0.0f, 0.0f, -1.0f)); // Creates two middle-left feet. @@ -243,8 +220,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(17, rank); m_object->SetObjectParent(17, 16); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant6.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant6.mod", false, rank); m_object->SetPosition(17, Math::Vector(0.0f, 0.0f, -2.0f)); // Creates front-left thigh. @@ -252,8 +228,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(18, rank); m_object->SetObjectParent(18, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant4.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant4.mod", false, rank); m_object->SetPosition(18, Math::Vector(1.0f, -0.1f, 0.7f)); m_object->SetAngleY(18, Math::PI); @@ -262,8 +237,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(19, rank); m_object->SetObjectParent(19, 18); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant5.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant5.mod", false, rank); m_object->SetPosition(19, Math::Vector(0.0f, 0.0f, -1.0f)); // Creates front-left foot. @@ -271,8 +245,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(20, rank); m_object->SetObjectParent(20, 19); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant6.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ant6.mod", false, rank); m_object->SetPosition(20, Math::Vector(0.0f, 0.0f, -2.0f)); // Creates the right wing. @@ -280,8 +253,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(21, rank); m_object->SetObjectParent(21, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "bee7.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("bee7.mod", false, rank); m_object->SetPosition(21, Math::Vector(0.8f, 0.4f, -0.5f)); // Creates the left wing. @@ -289,9 +261,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(22, rank); m_object->SetObjectParent(22, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "bee7.mod")); - pModFile->Mirror(); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("bee7.mod", true, rank); m_object->SetPosition(22, Math::Vector(0.8f, 0.4f, 0.5f)); m_object->CreateShadowCircle(6.0f, 0.5f); @@ -304,7 +274,6 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type, m_engine->LoadAllTextures(); - delete pModFile; return true; } diff --git a/src/object/motion/motionhuman.cpp b/src/object/motion/motionhuman.cpp index a9b79b5..5ff4af3 100644 --- a/src/object/motion/motionhuman.cpp +++ b/src/object/motion/motionhuman.cpp @@ -19,7 +19,7 @@ #include "app/app.h" -#include "graphics/engine/modelfile.h" +#include "graphics/engine/modelmanager.h" #include "graphics/engine/terrain.h" #include "graphics/engine/water.h" @@ -97,30 +97,22 @@ Error CMotionHuman::SetAction(int action, float time) bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type, float power) { - Gfx::CModelFile* pModFile; char filename[100]; int rank, option, face, glasses; -// if ( m_engine->GetRestCreate() < 16 ) return false; - - - pModFile = new Gfx::CModelFile(m_iMan); + Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer(); m_object->SetType(type); option = m_object->GetOption(); - std::string baseName; - if ( m_main->GetGamerOnlyHead() ) { rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICULE); // this is a moving object m_object->SetObjectRank(0, rank); face = m_main->GetGamerFace(); - baseName = m_app->GetDataFilePath(DIR_MODEL, "human2h%d.mod"); - sprintf(filename, baseName.c_str(), face+1); - pModFile->ReadModel(filename); - pModFile->CreateEngineObject(rank); + sprintf(filename, "human2h%d.mod", face+1); + modelManager->AddModelReference(filename, false, rank); glasses = m_main->GetGamerGlasses(); if ( glasses != 0 ) @@ -129,10 +121,8 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(1, rank); m_object->SetObjectParent(1, 0); - baseName = m_app->GetDataFilePath(DIR_MODEL, "human2g%d.mod"); - sprintf(filename, baseName.c_str(), glasses); - pModFile->ReadModel(filename); - pModFile->CreateEngineObject(rank); + sprintf(filename, "human2g%d.mod", glasses); + modelManager->AddModelReference(filename, false, rank); } CreatePhysics(type); @@ -140,7 +130,6 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type, m_engine->LoadAllTextures(); - delete pModFile; return true; } @@ -149,19 +138,12 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICULE); // this is a moving object m_object->SetObjectRank(0, rank); - if ( option == 0 ) // head in helmet? - { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "human1c.mod")); - } - if ( option == 1 ) // head without helmet? - { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "human1h.mod")); - } - if ( option == 2 ) // without a backpack? - { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "human1v.mod")); - } - pModFile->CreateEngineObject(rank); + if (option == 0) // head in helmet? + modelManager->AddModelReference("human1c.mod", false, rank); + else if (option == 1) // head without helmet? + modelManager->AddModelReference("human1h.mod", false, rank); + else if (option == 2) // without a backpack? + modelManager->AddModelReference("human1v.mod", false, rank); m_object->SetPosition(0, pos); m_object->SetAngleY(0, angle); @@ -178,30 +160,28 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type, if ( type == OBJECT_HUMAN ) { - if ( option == 0 ) // head in helmet? + if (option == 0) // head in helmet? { face = m_main->GetGamerFace(); - baseName = m_app->GetDataFilePath(DIR_MODEL, "human2c%d.mod"); - sprintf(filename, baseName.c_str(), face+1); - pModFile->ReadModel(filename); + sprintf(filename, "human2c%d.mod", face+1); + modelManager->AddModelReference(filename, false, rank); } - if ( option == 1 || // head without helmet? - option == 2 ) // without a backpack? + else if (option == 1 || // head without helmet? + option == 2) // without a backpack? { face = m_main->GetGamerFace(); - baseName = m_app->GetDataFilePath(DIR_MODEL, "human2h%d.mod"); - sprintf(filename, baseName.c_str(), face+1); - pModFile->ReadModel(filename); + sprintf(filename, "human2h%d.mod", face+1); + modelManager->AddModelReference(filename, false, rank); } } - if ( type == OBJECT_TECH ) + else if (type == OBJECT_TECH) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "human2t.mod")); + modelManager->AddModelReference("human2t.mod", false, rank); } - pModFile->CreateEngineObject(rank); + m_object->SetPosition(1, Math::Vector(0.0f, 2.7f, 0.0f)); - if ( option == 1 || // head without helmet? - option == 2 ) // without a backpack? + if (option == 1 || // head without helmet? + option == 2) // without a backpack? { m_object->SetZoom(1, Math::Vector(1.0f, 1.05f, 1.0f)); } @@ -214,10 +194,8 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(15, rank); m_object->SetObjectParent(15, 1); - baseName = m_app->GetDataFilePath(DIR_MODEL, "human2g%d.mod"); - sprintf(filename, baseName.c_str(), glasses); - pModFile->ReadModel(filename); - pModFile->CreateEngineObject(rank); + sprintf(filename, "human2g%d.mod", glasses); + modelManager->AddModelReference(filename, false, rank); } // Creates the right arm. @@ -225,8 +203,7 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(2, rank); m_object->SetObjectParent(2, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "human3.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("human3.mod", false, rank); m_object->SetPosition(2, Math::Vector(0.0f, 2.3f, -1.2f)); m_object->SetAngle(2, Math::Vector(90.0f*Math::PI/180.0f, 90.0f*Math::PI/180.0f, -50.0f*Math::PI/180.0f)); @@ -235,8 +212,7 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(3, rank); m_object->SetObjectParent(3, 2); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "human4r.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("human4r.mod", false, rank); m_object->SetPosition(3, Math::Vector(1.3f, 0.0f, 0.0f)); m_object->SetAngle(3, Math::Vector(0.0f*Math::PI/180.0f, -20.0f*Math::PI/180.0f, 0.0f*Math::PI/180.0f)); @@ -245,8 +221,7 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(4, rank); m_object->SetObjectParent(4, 3); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "human5.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("human5.mod", false, rank); m_object->SetPosition(4, Math::Vector(1.2f, 0.0f, 0.0f)); // Creates the right thigh. @@ -254,8 +229,7 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(5, rank); m_object->SetObjectParent(5, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "human6.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("human6.mod", false, rank); m_object->SetPosition(5, Math::Vector(0.0f, 0.0f, -0.7f)); m_object->SetAngle(5, Math::Vector(10.0f*Math::PI/180.0f, 0.0f*Math::PI/180.0f, 5.0f*Math::PI/180.0f)); @@ -264,8 +238,7 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(6, rank); m_object->SetObjectParent(6, 5); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "human7.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("human7.mod", false, rank); m_object->SetPosition(6, Math::Vector(0.0f, -1.5f, 0.0f)); m_object->SetAngle(6, Math::Vector(0.0f*Math::PI/180.0f, 0.0f*Math::PI/180.0f, -10.0f*Math::PI/180.0f)); @@ -274,8 +247,7 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(7, rank); m_object->SetObjectParent(7, 6); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "human8.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("human8.mod", false, rank); m_object->SetPosition(7, Math::Vector(0.0f, -1.5f, 0.0f)); m_object->SetAngle(7, Math::Vector(-10.0f*Math::PI/180.0f, 5.0f*Math::PI/180.0f, 5.0f*Math::PI/180.0f)); @@ -284,9 +256,7 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(8, rank); m_object->SetObjectParent(8, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "human3.mod")); - pModFile->Mirror(); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("human3.mod", true, rank); m_object->SetPosition(8, Math::Vector(0.0f, 2.3f, 1.2f)); m_object->SetAngle(8, Math::Vector(-90.0f*Math::PI/180.0f, -90.0f*Math::PI/180.0f, -50.0f*Math::PI/180.0f)); @@ -295,9 +265,7 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(9, rank); m_object->SetObjectParent(9, 8); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "human4l.mod")); - pModFile->Mirror(); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("human4l.mod", true, rank); m_object->SetPosition(9, Math::Vector(1.3f, 0.0f, 0.0f)); m_object->SetAngle(9, Math::Vector(0.0f*Math::PI/180.0f, 20.0f*Math::PI/180.0f, 0.0f*Math::PI/180.0f)); @@ -306,9 +274,7 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(10, rank); m_object->SetObjectParent(10, 9); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "human5.mod")); - pModFile->Mirror(); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("human5.mod", true, rank); m_object->SetPosition(10, Math::Vector(1.2f, 0.0f, 0.0f)); // Creates the left thigh. @@ -316,9 +282,7 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(11, rank); m_object->SetObjectParent(11, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "human6.mod")); - pModFile->Mirror(); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("human6.mod", true, rank); m_object->SetPosition(11, Math::Vector(0.0f, 0.0f, 0.7f)); m_object->SetAngle(11, Math::Vector(-10.0f*Math::PI/180.0f, 0.0f*Math::PI/180.0f, 5.0f*Math::PI/180.0f)); @@ -327,9 +291,7 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(12, rank); m_object->SetObjectParent(12, 11); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "human7.mod")); - pModFile->Mirror(); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("human7.mod", true, rank); m_object->SetPosition(12, Math::Vector(0.0f, -1.5f, 0.0f)); m_object->SetAngle(12, Math::Vector(0.0f*Math::PI/180.0f, 0.0f*Math::PI/180.0f, -10.0f*Math::PI/180.0f)); @@ -338,9 +300,7 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(13, rank); m_object->SetObjectParent(13, 12); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "human8.mod")); - pModFile->Mirror(); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("human8.mod", true, rank); m_object->SetPosition(13, Math::Vector(0.0f, -1.5f, 0.0f)); m_object->SetAngle(13, Math::Vector(10.0f*Math::PI/180.0f, -5.0f*Math::PI/180.0f, 5.0f*Math::PI/180.0f)); @@ -351,8 +311,7 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(14, rank); m_object->SetObjectParent(14, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "human9.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("human9.mod", false, rank); m_object->SetPosition(14, Math::Vector(-1.5f, 0.3f, -1.35f)); m_object->SetAngleZ(14, Math::PI); } @@ -367,7 +326,6 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type, m_engine->LoadAllTextures(); - delete pModFile; return true; } diff --git a/src/object/motion/motionmother.cpp b/src/object/motion/motionmother.cpp index 8ea77a5..ce1362f 100644 --- a/src/object/motion/motionmother.cpp +++ b/src/object/motion/motionmother.cpp @@ -19,7 +19,7 @@ #include "app/app.h" -#include "graphics/engine/modelfile.h" +#include "graphics/engine/modelmanager.h" #include "physics/physics.h" @@ -68,12 +68,8 @@ void CMotionMother::DeleteObject(bool bAll) bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type, float power) { - Gfx::CModelFile* pModFile; - int rank; - -// if ( m_engine->GetRestCreate() < 2+12+6 ) return false; - - pModFile = new Gfx::CModelFile(m_iMan); + Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer(); + int rank; m_object->SetType(type); @@ -81,10 +77,7 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICULE); // this is a moving object m_object->SetObjectRank(0, rank); - - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother1.mod")); - pModFile->CreateEngineObject(rank); - + modelManager->AddModelReference("mother1.mod", false, rank); m_object->SetPosition(0, pos); m_object->SetAngleY(0, angle); @@ -98,8 +91,7 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(1, rank); m_object->SetObjectParent(1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("mother2.mod", false, rank); m_object->SetPosition(1, Math::Vector(16.0f, 3.0f, 0.0f)); // Creates a right-back leg. @@ -107,8 +99,7 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(2, rank); m_object->SetObjectParent(2, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother3.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("mother3.mod", false, rank); m_object->SetPosition(2, Math::Vector(-5.0f, -1.0f, -12.0f)); // Creates a right-back foot. @@ -116,8 +107,7 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(3, rank); m_object->SetObjectParent(3, 2); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother4.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("mother4.mod", false, rank); m_object->SetPosition(3, Math::Vector(0.0f, 0.0f, -8.5f)); // Creates a middle-right leg. @@ -125,8 +115,7 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(4, rank); m_object->SetObjectParent(4, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother3.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("mother3.mod", false, rank); m_object->SetPosition(4, Math::Vector(3.5f, -1.0f, -12.0f)); // Creates a middle-right foot. @@ -134,8 +123,7 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(5, rank); m_object->SetObjectParent(5, 4); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother4.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("mother4.mod", false, rank); m_object->SetPosition(5, Math::Vector(0.0f, 0.0f, -8.5f)); // Creates a right-front leg. @@ -143,8 +131,7 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(6, rank); m_object->SetObjectParent(6, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother3.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("mother3.mod", false, rank); m_object->SetPosition(6, Math::Vector(10.0f, -1.0f, -10.0f)); // Creates a right-front foot. @@ -152,8 +139,7 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(7, rank); m_object->SetObjectParent(7, 6); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother4.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("mother4.mod", false, rank); m_object->SetPosition(7, Math::Vector(0.0f, 0.0f, -8.5f)); // Creates a left-back leg. @@ -161,8 +147,7 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(8, rank); m_object->SetObjectParent(8, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother3.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("mother3.mod", false, rank); m_object->SetPosition(8, Math::Vector(-5.0f, -1.0f, 12.0f)); m_object->SetAngleY(8, Math::PI); @@ -171,8 +156,7 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(9, rank); m_object->SetObjectParent(9, 8); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother4.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("mother4.mod", false, rank); m_object->SetPosition(9, Math::Vector(0.0f, 0.0f, -8.5f)); // Creates a middle-left leg. @@ -180,8 +164,7 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(10, rank); m_object->SetObjectParent(10, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother3.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("mother3.mod", false, rank); m_object->SetPosition(10, Math::Vector(3.5f, -1.0f, 12.0f)); m_object->SetAngleY(10, Math::PI); @@ -190,8 +173,7 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(11, rank); m_object->SetObjectParent(11, 10); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother4.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("mother4.mod", false, rank); m_object->SetPosition(11, Math::Vector(0.0f, 0.0f, -8.5f)); // Creates a left-front leg. @@ -199,8 +181,7 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(12, rank); m_object->SetObjectParent(12, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother3.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("mother3.mod", false, rank); m_object->SetPosition(12, Math::Vector(10.0f, -1.0f, 10.0f)); m_object->SetAngleY(12, Math::PI); @@ -209,8 +190,7 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(13, rank); m_object->SetObjectParent(13, 12); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother4.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("mother4.mod", false, rank); m_object->SetPosition(13, Math::Vector(0.0f, 0.0f, -8.5f)); // Creates the right antenna. @@ -218,16 +198,14 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(14, rank); m_object->SetObjectParent(14, 1); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother5.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("mother5.mod", false, rank); m_object->SetPosition(14, Math::Vector(6.0f, 1.0f, -2.5f)); rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(15, rank); m_object->SetObjectParent(15, 14); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother6.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("mother6.mod", false, rank); m_object->SetPosition(15, Math::Vector(8.0f, 0.0f, 0.0f)); // Creates the left antenna. @@ -235,16 +213,14 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(16, rank); m_object->SetObjectParent(16, 1); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother5.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("mother5.mod", false, rank); m_object->SetPosition(16, Math::Vector(6.0f, 1.0f, 2.5f)); rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(17, rank); m_object->SetObjectParent(17, 16); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother6.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("mother6.mod", false, rank); m_object->SetPosition(17, Math::Vector(8.0f, 0.0f, 0.0f)); // Creates the right claw. @@ -252,8 +228,7 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(18, rank); m_object->SetObjectParent(18, 1); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother7.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("mother7.mod", false, rank); m_object->SetPosition(18, Math::Vector(-4.0f, -3.5f, -8.0f)); m_object->SetZoomX(18, 1.2f); @@ -262,9 +237,7 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(19, rank); m_object->SetObjectParent(19, 1); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother7.mod")); - pModFile->Mirror(); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("mother7.mod", true, rank); m_object->SetPosition(19, Math::Vector(-4.0f, -3.5f, 8.0f)); m_object->SetZoomX(19, 1.2f); @@ -278,7 +251,6 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type, m_engine->LoadAllTextures(); - delete pModFile; return true; } diff --git a/src/object/motion/motionspider.cpp b/src/object/motion/motionspider.cpp index 516ec6e..66d89fb 100644 --- a/src/object/motion/motionspider.cpp +++ b/src/object/motion/motionspider.cpp @@ -19,7 +19,7 @@ #include "app/app.h" -#include "graphics/engine/modelfile.h" +#include "graphics/engine/modelmanager.h" #include "graphics/engine/particle.h" #include "physics/physics.h" @@ -69,12 +69,9 @@ void CMotionSpider::DeleteObject(bool bAll) bool CMotionSpider::Create(Math::Vector pos, float angle, ObjectType type, float power) { - Gfx::CModelFile* pModFile; int rank, i, j, parent; char name[50]; - std::string baseName; - float table[] = { // x y z @@ -99,9 +96,7 @@ bool CMotionSpider::Create(Math::Vector pos, float angle, ObjectType type, 0.0f, 0.0f, -2.0f, }; -// if ( m_engine->GetRestCreate() < 3+32+2 ) return false; - - pModFile = new Gfx::CModelFile(m_iMan); + Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer(); m_object->SetType(type); @@ -109,8 +104,7 @@ bool CMotionSpider::Create(Math::Vector pos, float angle, ObjectType type, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICULE); // this is a moving object m_object->SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "spider0.mod")); // doesn't exist - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("spider0.mod", false, rank); m_object->SetPosition(0, pos); m_object->SetAngleY(0, angle); @@ -124,8 +118,7 @@ bool CMotionSpider::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(1, rank); m_object->SetObjectParent(1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "spider1.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("spider1.mod", false, rank); m_object->SetPosition(1, Math::Vector(1.0f, 0.0f, 0.0f)); // Creates the head. @@ -133,8 +126,7 @@ bool CMotionSpider::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(2, rank); m_object->SetObjectParent(2, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "spider2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("spider2.mod", false, rank); m_object->SetPosition(2, Math::Vector(1.0f, 0.0f, 0.0f)); // Creates legs. @@ -142,8 +134,7 @@ bool CMotionSpider::Create(Math::Vector pos, float angle, ObjectType type, { for ( j=0 ; j<4 ; j++ ) { - baseName = m_app->GetDataFilePath(DIR_MODEL, "spider%d.mod"); - sprintf(name, baseName.c_str(), j+3); // 3..6 + sprintf(name, "spider%d.mod", j+3); // 3..6 // Creates the right leg. rank = m_engine->CreateObject(); @@ -152,8 +143,7 @@ bool CMotionSpider::Create(Math::Vector pos, float angle, ObjectType type, if ( j == 0 ) parent = 0; else parent = 3+i*4+j-1; m_object->SetObjectParent(3+i*4+j, parent); - pModFile->ReadModel(name); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference(name, false, rank); pos.x = table[i*12+j*3+0]; pos.y = table[i*12+j*3+1]; pos.z = table[i*12+j*3+2]; @@ -166,9 +156,7 @@ bool CMotionSpider::Create(Math::Vector pos, float angle, ObjectType type, if ( j == 0 ) parent = 0; else parent = 19+i*4+j-1; m_object->SetObjectParent(19+i*4+j, parent); - pModFile->ReadModel(name); - pModFile->Mirror(); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference(name, true, rank); pos.x = table[i*12+j*3+0]; pos.y = table[i*12+j*3+1]; pos.z = -table[i*12+j*3+2]; @@ -181,8 +169,7 @@ bool CMotionSpider::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(35, rank); m_object->SetObjectParent(35, 1); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "spider7.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("spider7.mod", false, rank); m_object->SetPosition(35, Math::Vector(0.0f, 0.0f, -0.3f)); // Creates the left mandible. @@ -190,9 +177,7 @@ bool CMotionSpider::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(36, rank); m_object->SetObjectParent(36, 1); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "spider7.mod")); - pModFile->Mirror(); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("spider7.mod", true, rank); m_object->SetPosition(36, Math::Vector(0.0f, 0.0f, 0.3f)); m_object->CreateShadowCircle(4.0f, 0.5f); @@ -205,7 +190,6 @@ bool CMotionSpider::Create(Math::Vector pos, float angle, ObjectType type, m_engine->LoadAllTextures(); - delete pModFile; return true; } diff --git a/src/object/motion/motiontoto.cpp b/src/object/motion/motiontoto.cpp index 274f171..3a7f1ac 100644 --- a/src/object/motion/motiontoto.cpp +++ b/src/object/motion/motiontoto.cpp @@ -21,9 +21,9 @@ #include "math/geometry.h" +#include "graphics/engine/modelmanager.h" #include "graphics/engine/terrain.h" #include "graphics/engine/water.h" -#include "graphics/engine/modelfile.h" #include "object/robotmain.h" @@ -81,12 +81,9 @@ void CMotionToto::DeleteObject(bool bAll) bool CMotionToto::Create(Math::Vector pos, float angle, ObjectType type, float power) { - Gfx::CModelFile* pModFile; + Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer(); int rank; -// if ( m_engine->GetRestCreate() < 10 ) return false; - - pModFile = new Gfx::CModelFile(m_iMan); m_object->SetType(type); @@ -94,8 +91,7 @@ bool CMotionToto::Create(Math::Vector pos, float angle, ObjectType type, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICULE); // this is a moving object m_object->SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "toto1.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("toto1.mod", false, rank); m_object->SetPosition(0, pos); m_object->SetAngleY(0, angle); @@ -104,8 +100,7 @@ bool CMotionToto::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(1, rank); m_object->SetObjectParent(1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "toto2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("toto2.mod", false, rank); m_object->SetPosition(1, Math::Vector(1.00f, 0.17f, 0.00f)); // Creates the left eye. @@ -113,9 +108,7 @@ bool CMotionToto::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(2, rank); m_object->SetObjectParent(2, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "toto3.mod")); - pModFile->Mirror(); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("toto3.mod", true, rank); m_object->SetPosition(2, Math::Vector(0.85f, 1.04f, 0.25f)); m_object->SetAngleY(2, -20.0f*Math::PI/180.0f); @@ -124,8 +117,7 @@ bool CMotionToto::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(3, rank); m_object->SetObjectParent(3, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "toto3.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("toto3.mod", false, rank); m_object->SetPosition(3, Math::Vector(0.85f, 1.04f, -0.25f)); m_object->SetAngleY(3, 20.0f*Math::PI/180.0f); @@ -134,8 +126,7 @@ bool CMotionToto::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(4, rank); m_object->SetObjectParent(4, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "toto4.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("toto4.mod", false, rank); m_object->SetPosition(4, Math::Vector(0.0f, 1.9f, 0.3f)); m_object->SetAngleX(4, 30.0f*Math::PI/180.0f); @@ -143,8 +134,7 @@ bool CMotionToto::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(5, rank); m_object->SetObjectParent(5, 4); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "toto4.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("toto4.mod", false, rank); m_object->SetPosition(5, Math::Vector(0.0f, 0.67f, 0.0f)); m_object->SetAngleX(5, 30.0f*Math::PI/180.0f); @@ -152,8 +142,7 @@ bool CMotionToto::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(6, rank); m_object->SetObjectParent(6, 5); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "toto5.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("toto5.mod", false, rank); m_object->SetPosition(6, Math::Vector(0.0f, 0.70f, 0.0f)); m_object->SetAngleX(6, 30.0f*Math::PI/180.0f); @@ -162,8 +151,7 @@ bool CMotionToto::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(7, rank); m_object->SetObjectParent(7, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "toto4.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("toto4.mod", false, rank); m_object->SetPosition(7, Math::Vector(0.0f, 1.9f, -0.3f)); m_object->SetAngleX(7, -30.0f*Math::PI/180.0f); @@ -171,8 +159,7 @@ bool CMotionToto::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(8, rank); m_object->SetObjectParent(8, 7); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "toto4.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("toto4.mod", false, rank); m_object->SetPosition(8, Math::Vector(0.0f, 0.67f, 0.0f)); m_object->SetAngleX(8, -30.0f*Math::PI/180.0f); @@ -180,8 +167,7 @@ bool CMotionToto::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(9, rank); m_object->SetObjectParent(9, 8); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "toto5.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("toto5.mod", false, rank); m_object->SetPosition(9, Math::Vector(0.0f, 0.70f, 0.0f)); m_object->SetAngleX(9, -30.0f*Math::PI/180.0f); @@ -193,7 +179,6 @@ bool CMotionToto::Create(Math::Vector pos, float angle, ObjectType type, m_engine->LoadAllTextures(); - delete pModFile; return true; } diff --git a/src/object/motion/motionvehicle.cpp b/src/object/motion/motionvehicle.cpp index 849d53e..d331f13 100644 --- a/src/object/motion/motionvehicle.cpp +++ b/src/object/motion/motionvehicle.cpp @@ -19,7 +19,7 @@ #include "app/app.h" -#include "graphics/engine/modelfile.h" +#include "graphics/engine/modelmanager.h" #include "graphics/engine/particle.h" #include "graphics/engine/terrain.h" @@ -92,15 +92,12 @@ void CMotionVehicle::DeleteObject(bool bAll) bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, float power) { - Gfx::CModelFile* pModFile; CObject* pPower; int rank, i, j, parent; Gfx::Color color; char name[50]; -// if ( m_engine->GetRestCreate() < 1+5+18+1 ) return false; - - pModFile = new Gfx::CModelFile(m_iMan); + Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer(); m_object->SetType(type); @@ -109,106 +106,105 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICULE); // this is a moving object m_object->SetObjectRank(0, rank); - if ( type == OBJECT_MOBILEfa || - type == OBJECT_MOBILEfc || - type == OBJECT_MOBILEfi || - type == OBJECT_MOBILEfs ) + if (type == OBJECT_MOBILEfa || + type == OBJECT_MOBILEfc || + type == OBJECT_MOBILEfi || + type == OBJECT_MOBILEfs) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem1f.mod")); + modelManager->AddModelReference("lem1f.mod", false, rank); } - if ( type == OBJECT_MOBILEta || - type == OBJECT_MOBILEtc || - type == OBJECT_MOBILEti || - type == OBJECT_MOBILEts ) + else if (type == OBJECT_MOBILEta || + type == OBJECT_MOBILEtc || + type == OBJECT_MOBILEti || + type == OBJECT_MOBILEts) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem1t.mod")); + modelManager->AddModelReference("lem1t.mod", false, rank); } - if ( type == OBJECT_MOBILEwa || - type == OBJECT_MOBILEwc || - type == OBJECT_MOBILEwi || - type == OBJECT_MOBILEws ) + else if (type == OBJECT_MOBILEwa || + type == OBJECT_MOBILEwc || + type == OBJECT_MOBILEwi || + type == OBJECT_MOBILEws) { - if ( m_object->GetTrainer() ) + if (m_object->GetTrainer()) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem1wt.mod")); + modelManager->AddModelReference("lem1wt.mod", false, rank); } else { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem1w.mod")); + modelManager->AddModelReference("lem1w.mod", false, rank); } } - if ( type == OBJECT_MOBILEia || - type == OBJECT_MOBILEic || - type == OBJECT_MOBILEii || - type == OBJECT_MOBILEis ) + else if (type == OBJECT_MOBILEia || + type == OBJECT_MOBILEic || + type == OBJECT_MOBILEii || + type == OBJECT_MOBILEis) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem1i.mod")); + modelManager->AddModelReference("lem1i.mod", false, rank); } - if ( type == OBJECT_MOBILErt || - type == OBJECT_MOBILErc || - type == OBJECT_MOBILErr || - type == OBJECT_MOBILErs ) + else if (type == OBJECT_MOBILErt || + type == OBJECT_MOBILErc || + type == OBJECT_MOBILErr || + type == OBJECT_MOBILErs) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "roller1.mod")); + modelManager->AddModelReference("roller1.mod", false, rank); } - if ( type == OBJECT_MOBILEsa ) + else if (type == OBJECT_MOBILEsa) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "subm1.mod")); + modelManager->AddModelReference("subm1.mod", false, rank); } - if ( type == OBJECT_MOBILEtg ) + else if (type == OBJECT_MOBILEtg) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "target.mod")); + modelManager->AddModelReference("target.mod", false, rank); } - if ( type == OBJECT_MOBILEwt ) + else if (type == OBJECT_MOBILEwt) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "trainerw.mod")); + modelManager->AddModelReference("trainerw.mod", false, rank); } - if ( type == OBJECT_MOBILEft ) + else if (type == OBJECT_MOBILEft) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "trainerf.mod")); + modelManager->AddModelReference("trainerf.mod", false, rank); } - if ( type == OBJECT_MOBILEtt ) + else if (type == OBJECT_MOBILEtt) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "trainert.mod")); + modelManager->AddModelReference("trainert.mod", false, rank); } - if ( type == OBJECT_MOBILEit ) + else if (type == OBJECT_MOBILEit) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "traineri.mod")); + modelManager->AddModelReference("traineri.mod", false, rank); } - if ( type == OBJECT_MOBILEdr ) + else if (type == OBJECT_MOBILEdr) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "drawer1.mod")); + modelManager->AddModelReference("drawer1.mod", false, rank); } - if ( type == OBJECT_APOLLO2 ) + else if (type == OBJECT_APOLLO2) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj1.mod")); + modelManager->AddModelReference("apolloj1.mod", false, rank); } - pModFile->CreateEngineObject(rank); m_object->SetPosition(0, pos); m_object->SetAngleY(0, angle); // A vehicle must have a obligatory collision // with a sphere of center (0, y, 0) (see GetCrashSphere). - if ( type == OBJECT_MOBILErt || - type == OBJECT_MOBILErc || - type == OBJECT_MOBILErr || - type == OBJECT_MOBILErs ) + if (type == OBJECT_MOBILErt || + type == OBJECT_MOBILErc || + type == OBJECT_MOBILErr || + type == OBJECT_MOBILErs) { m_object->CreateCrashSphere(Math::Vector(0.0f, 4.0f, 0.0f), 6.5f, SOUND_BOUMm, 0.45f); m_object->SetGlobalSphere(Math::Vector(0.0f, 3.0f, 0.0f), 7.0f); } - else if ( type == OBJECT_MOBILEsa ) + else if (type == OBJECT_MOBILEsa) { m_object->CreateCrashSphere(Math::Vector(0.0f, 3.0f, 0.0f), 4.5f, SOUND_BOUMm, 0.45f); m_object->SetGlobalSphere(Math::Vector(0.0f, 3.0f, 0.0f), 6.0f); } - else if ( type == OBJECT_MOBILEdr ) + else if (type == OBJECT_MOBILEdr) { m_object->CreateCrashSphere(Math::Vector(0.0f, 3.0f, 0.0f), 5.0f, SOUND_BOUMm, 0.45f); m_object->SetGlobalSphere(Math::Vector(0.0f, 3.0f, 0.0f), 7.0f); } - else if ( type == OBJECT_APOLLO2 ) + else if (type == OBJECT_APOLLO2) { m_object->CreateCrashSphere(Math::Vector(0.0f, 0.0f, 0.0f), 8.0f, SOUND_BOUMm, 0.45f); } @@ -218,18 +214,17 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_object->SetGlobalSphere(Math::Vector(0.0f, 4.0f, 0.0f), 6.0f); } - if ( type == OBJECT_MOBILEfa || - type == OBJECT_MOBILEta || - type == OBJECT_MOBILEwa || - type == OBJECT_MOBILEia ) + if (type == OBJECT_MOBILEfa || + type == OBJECT_MOBILEta || + type == OBJECT_MOBILEwa || + type == OBJECT_MOBILEia) { // Creates the arm. rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(1, rank); m_object->SetObjectParent(1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("lem2.mod", false, rank); m_object->SetPosition(1, Math::Vector(0.0f, 5.3f, 0.0f)); m_object->SetAngleZ(1, ARM_NEUTRAL_ANGLE1); @@ -238,8 +233,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(2, rank); m_object->SetObjectParent(2, 1); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem3.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("lem3.mod", false, rank); m_object->SetPosition(2, Math::Vector(5.0f, 0.0f, 0.0f)); m_object->SetAngleZ(2, ARM_NEUTRAL_ANGLE2); @@ -248,8 +242,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(3, rank); m_object->SetObjectParent(3, 2); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem4.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("lem4.mod", false, rank); m_object->SetPosition(3, Math::Vector(3.5f, 0.0f, 0.0f)); m_object->SetAngleZ(3, ARM_NEUTRAL_ANGLE3); m_object->SetAngleX(3, Math::PI/2.0f); @@ -259,8 +252,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(4, rank); m_object->SetObjectParent(4, 3); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem5.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("lem5.mod", false, rank); m_object->SetPosition(4, Math::Vector(1.5f, 0.0f, 0.0f)); m_object->SetAngleZ(4, -Math::PI*0.10f); @@ -269,24 +261,22 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(5, rank); m_object->SetObjectParent(5, 3); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem6.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("lem6.mod", false, rank); m_object->SetPosition(5, Math::Vector(1.5f, 0.0f, 0.0f)); m_object->SetAngleZ(5, Math::PI*0.10f); } - if ( type == OBJECT_MOBILEfs || - type == OBJECT_MOBILEts || - type == OBJECT_MOBILEws || - type == OBJECT_MOBILEis ) + if (type == OBJECT_MOBILEfs || + type == OBJECT_MOBILEts || + type == OBJECT_MOBILEws || + type == OBJECT_MOBILEis) { // Creates the arm. rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(1, rank); m_object->SetObjectParent(1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("lem2.mod", false, rank); m_object->SetPosition(1, Math::Vector(0.0f, 5.3f, 0.0f)); m_object->SetAngleZ(1, 110.0f*Math::PI/180.0f); @@ -295,8 +285,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(2, rank); m_object->SetObjectParent(2, 1); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem3.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("lem3.mod", false, rank); m_object->SetPosition(2, Math::Vector(5.0f, 0.0f, 0.0f)); m_object->SetAngleZ(2, -110.0f*Math::PI/180.0f); @@ -305,41 +294,38 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(3, rank); m_object->SetObjectParent(3, 2); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem4s.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("lem4s.mod", false, rank); m_object->SetPosition(3, Math::Vector(3.5f, 0.0f, 0.0f)); m_object->SetAngleZ(3, -65.0f*Math::PI/180.0f); } - if ( type == OBJECT_MOBILEfc || - type == OBJECT_MOBILEtc || - type == OBJECT_MOBILEwc || - type == OBJECT_MOBILEic ) + if (type == OBJECT_MOBILEfc || + type == OBJECT_MOBILEtc || + type == OBJECT_MOBILEwc || + type == OBJECT_MOBILEic) { // Creates the cannon. rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(1, rank); m_object->SetObjectParent(1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "canon.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("canon.mod", false, rank); //? m_object->SetPosition(1, Math::Vector(0.0f, 5.3f, 0.0f)); m_object->SetPosition(1, Math::Vector(0.0f, 5.3f, 0.0f)); m_object->SetAngleZ(1, 0.0f); } - if ( type == OBJECT_MOBILEfi || - type == OBJECT_MOBILEti || - type == OBJECT_MOBILEwi || - type == OBJECT_MOBILEii ) + if (type == OBJECT_MOBILEfi || + type == OBJECT_MOBILEti || + type == OBJECT_MOBILEwi || + type == OBJECT_MOBILEii) { // Creates the insect cannon. rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(1, rank); m_object->SetObjectParent(1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "canoni1.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("canoni1.mod", false, rank); m_object->SetPosition(1, Math::Vector(0.0f, 5.3f, 0.0f)); m_object->SetAngleZ(1, 0.0f); @@ -347,25 +333,23 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(2, rank); m_object->SetObjectParent(2, 1); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "canoni2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("canoni2.mod", false, rank); m_object->SetPosition(2, Math::Vector(0.0f, 2.5f, 0.0f)); m_object->SetAngleZ(2, 0.0f); } - if ( type == OBJECT_MOBILEwa || - type == OBJECT_MOBILEwc || - type == OBJECT_MOBILEws || - type == OBJECT_MOBILEwi || - type == OBJECT_MOBILEwt ) + if (type == OBJECT_MOBILEwa || + type == OBJECT_MOBILEwc || + type == OBJECT_MOBILEws || + type == OBJECT_MOBILEwi || + type == OBJECT_MOBILEwt) { // Creates the right-back wheel. rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(6, rank); m_object->SetObjectParent(6, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2w.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("lem2w.mod", false, rank); m_object->SetPosition(6, Math::Vector(-3.0f, 1.0f, -3.0f)); // Creates the left-back wheel. @@ -373,8 +357,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(7, rank); m_object->SetObjectParent(7, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2w.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("lem2w.mod", false, rank); m_object->SetPosition(7, Math::Vector(-3.0f, 1.0f, 3.0f)); m_object->SetAngleY(7, Math::PI); @@ -383,8 +366,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(8, rank); m_object->SetObjectParent(8, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2w.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("lem2w.mod", false, rank); m_object->SetPosition(8, Math::Vector(2.0f, 1.0f, -3.0f)); // Creates the left-front wheel. @@ -392,21 +374,19 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(9, rank); m_object->SetObjectParent(9, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2w.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("lem2w.mod", false, rank); m_object->SetPosition(9, Math::Vector(2.0f, 1.0f, 3.0f)); m_object->SetAngleY(9, Math::PI); } - if ( type == OBJECT_MOBILEtg ) + if (type == OBJECT_MOBILEtg) { // Creates the right-back wheel. rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(6, rank); m_object->SetObjectParent(6, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2w.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("lem2w.mod", false, rank); m_object->SetPosition(6, Math::Vector(-2.0f, 1.0f, -3.0f)); // Creates the left-back wheel. @@ -414,8 +394,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(7, rank); m_object->SetObjectParent(7, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2w.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("lem2w.mod", false, rank); m_object->SetPosition(7, Math::Vector(-2.0f, 1.0f, 3.0f)); m_object->SetAngleY(7, Math::PI); @@ -424,8 +403,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(8, rank); m_object->SetObjectParent(8, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2w.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("lem2w.mod", false, rank); m_object->SetPosition(8, Math::Vector(3.0f, 1.0f, -3.0f)); // Creates the left-front wheel. @@ -433,24 +411,22 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(9, rank); m_object->SetObjectParent(9, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2w.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("lem2w.mod", false, rank); m_object->SetPosition(9, Math::Vector(3.0f, 1.0f, 3.0f)); m_object->SetAngleY(9, Math::PI); } - if ( type == OBJECT_MOBILEta || - type == OBJECT_MOBILEtc || - type == OBJECT_MOBILEti || - type == OBJECT_MOBILEts ) // caterpillars? + if (type == OBJECT_MOBILEta || + type == OBJECT_MOBILEtc || + type == OBJECT_MOBILEti || + type == OBJECT_MOBILEts) // caterpillars? { // Creates the right caterpillar. rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(6, rank); m_object->SetObjectParent(6, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2t.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelCopy("lem2t.mod", false, rank); m_object->SetPosition(6, Math::Vector(0.0f, 2.0f, -3.0f)); // Creates the left caterpillar. @@ -458,23 +434,21 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(7, rank); m_object->SetObjectParent(7, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem3t.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelCopy("lem3t.mod", false, rank); m_object->SetPosition(7, Math::Vector(0.0f, 2.0f, 3.0f)); } - if ( type == OBJECT_MOBILErt || - type == OBJECT_MOBILErc || - type == OBJECT_MOBILErr || - type == OBJECT_MOBILErs ) // large caterpillars? + if (type == OBJECT_MOBILErt || + type == OBJECT_MOBILErc || + type == OBJECT_MOBILErr || + type == OBJECT_MOBILErs) // large caterpillars? { // Creates the right caterpillar. rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(6, rank); m_object->SetObjectParent(6, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "roller2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelCopy("roller2.mod", false, rank); m_object->SetPosition(6, Math::Vector(0.0f, 2.0f, -3.0f)); // Creates the left caterpillar. @@ -482,20 +456,18 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(7, rank); m_object->SetObjectParent(7, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "roller3.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelCopy("roller3.mod", false, rank); m_object->SetPosition(7, Math::Vector(0.0f, 2.0f, 3.0f)); } - if ( type == OBJECT_MOBILEsa ) // underwater caterpillars? + if (type == OBJECT_MOBILEsa) // underwater caterpillars? { // Creates the right caterpillar. rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(6, rank); m_object->SetObjectParent(6, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "subm4.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelCopy("subm4.mod", false, rank); m_object->SetPosition(6, Math::Vector(0.0f, 1.0f, -3.0f)); // Creates the left caterpillar. @@ -503,20 +475,18 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(7, rank); m_object->SetObjectParent(7, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "subm5.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelCopy("subm5.mod", false, rank); m_object->SetPosition(7, Math::Vector(0.0f, 1.0f, 3.0f)); } - if ( type == OBJECT_MOBILEdr ) // caterpillars? + if (type == OBJECT_MOBILEdr) // caterpillars? { // Creates the right caterpillar. rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(6, rank); m_object->SetObjectParent(6, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "drawer2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelCopy("drawer2.mod", false, rank); m_object->SetPosition(6, Math::Vector(0.0f, 1.0f, -3.0f)); // Creates the left caterpillar. @@ -524,24 +494,22 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(7, rank); m_object->SetObjectParent(7, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "drawer3.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelCopy("drawer3.mod", false, rank); m_object->SetPosition(7, Math::Vector(0.0f, 1.0f, 3.0f)); } - if ( type == OBJECT_MOBILEfa || - type == OBJECT_MOBILEfc || - type == OBJECT_MOBILEfs || - type == OBJECT_MOBILEfi || - type == OBJECT_MOBILEft ) // flying? + if (type == OBJECT_MOBILEfa || + type == OBJECT_MOBILEfc || + type == OBJECT_MOBILEfs || + type == OBJECT_MOBILEfi || + type == OBJECT_MOBILEft) // flying? { // Creates the front foot. rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(6, rank); m_object->SetObjectParent(6, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2f.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("lem2f.mod", false, rank); m_object->SetPosition(6, Math::Vector(1.7f, 3.0f, 0.0f)); // Creates the right-back foot. @@ -549,8 +517,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(7, rank); m_object->SetObjectParent(7, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2f.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("lem2f.mod", false, rank); m_object->SetPosition(7, Math::Vector(-1.8f, 3.0f, -1.5f)); m_object->SetAngleY(7, 120.0f*Math::PI/180.0f); @@ -559,16 +526,15 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(8, rank); m_object->SetObjectParent(8, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2f.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("lem2f.mod", false, rank); m_object->SetPosition(8, Math::Vector(-1.8f, 3.0f, 1.5f)); m_object->SetAngleY(8, -120.0f*Math::PI/180.0f); } - if ( type == OBJECT_MOBILEia || - type == OBJECT_MOBILEic || - type == OBJECT_MOBILEis || - type == OBJECT_MOBILEii ) // insect legs? + if (type == OBJECT_MOBILEia || + type == OBJECT_MOBILEic || + type == OBJECT_MOBILEis || + type == OBJECT_MOBILEii) // insect legs? { float table[] = { @@ -590,8 +556,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, { for ( j=0 ; j<3 ; j++ ) { - std::string baseName = m_app->GetDataFilePath(DIR_MODEL, "ant%d.mod"); - sprintf(name, baseName.c_str(), j+4); // 4..6 + sprintf(name, "ant%d.mod", j+4); // 4..6 // Creates the right leg. rank = m_engine->CreateObject(); @@ -600,8 +565,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, if ( j == 0 ) parent = 0; else parent = 6+i*3+j-1; m_object->SetObjectParent(6+i*3+j, parent); - pModFile->ReadModel(name); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference(name, false, rank); pos.x = table[i*9+j*3+0]; pos.y = table[i*9+j*3+1]; pos.z = table[i*9+j*3+2]; @@ -614,9 +578,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, if ( j == 0 ) parent = 0; else parent = 15+i*3+j-1; m_object->SetObjectParent(15+i*3+j, parent); - pModFile->ReadModel(name); - pModFile->Mirror(); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference(name, true, rank); pos.x = table[i*9+j*3+0]; pos.y = table[i*9+j*3+1]; pos.z = -table[i*9+j*3+2]; @@ -625,15 +587,14 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, } } - if ( type == OBJECT_MOBILErt ) + if (type == OBJECT_MOBILErt) { // Creates the holder. rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(1, rank); m_object->SetObjectParent(1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "roller2t.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("roller2t.mod", false, rank); m_object->SetPosition(1, Math::Vector(0.0f, 0.0f, 0.0f)); m_object->SetAngleZ(1, 0.0f); @@ -642,21 +603,19 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(2, rank); m_object->SetObjectParent(2, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "roller3t.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("roller3t.mod", false, rank); m_object->SetPosition(2, Math::Vector(9.0f, 4.0f, 0.0f)); m_object->SetAngleZ(2, 0.0f); } - if ( type == OBJECT_MOBILErc ) + if (type == OBJECT_MOBILErc) { // Creates the holder. rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(1, rank); m_object->SetObjectParent(1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "roller2c.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("roller2c.mod", false, rank); m_object->SetPosition(1, Math::Vector(3.0f, 4.6f, 0.0f)); m_object->SetAngleZ(1, Math::PI/8.0f); @@ -665,21 +624,19 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(2, rank); m_object->SetObjectParent(2, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "roller3p.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("roller3p.mod", false, rank); m_object->SetPosition(2, Math::Vector(7.0f, 6.5f, 0.0f)); m_object->SetAngleZ(2, 0.0f); } - if ( type == OBJECT_MOBILErr ) + if (type == OBJECT_MOBILErr) { // Creates the holder. rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(1, rank); m_object->SetObjectParent(1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "recover1.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("recover1.mod", false, rank); m_object->SetPosition(1, Math::Vector(2.0f, 5.0f, 0.0f)); // Creates the right arm. @@ -687,8 +644,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(2, rank); m_object->SetObjectParent(2, 1); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "recover2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("recover2.mod", false, rank); m_object->SetPosition(2, Math::Vector(0.1f, 0.0f, -5.0f)); m_object->SetAngleZ(2, 126.0f*Math::PI/180.0f); @@ -697,8 +653,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(3, rank); m_object->SetObjectParent(3, 2); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "recover3.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("recover3.mod", false, rank); m_object->SetPosition(3, Math::Vector(5.0f, 0.0f, -0.5f)); m_object->SetAngleZ(3, -144.0f*Math::PI/180.0f); @@ -707,9 +662,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(4, rank); m_object->SetObjectParent(4, 1); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "recover2.mod")); - pModFile->Mirror(); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("recover2.mod", true, rank); m_object->SetPosition(4, Math::Vector(0.1f, 0.0f, 5.0f)); m_object->SetAngleZ(4, 126.0f*Math::PI/180.0f); @@ -718,22 +671,19 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(5, rank); m_object->SetObjectParent(5, 4); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "recover3.mod")); - pModFile->Mirror(); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("recover3.mod", true, rank); m_object->SetPosition(5, Math::Vector(5.0f, 0.0f, 0.5f)); m_object->SetAngleZ(5, -144.0f*Math::PI/180.0f); } - if ( type == OBJECT_MOBILErs ) + if (type == OBJECT_MOBILErs) { // Creates the holder. rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(1, rank); m_object->SetObjectParent(1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "roller2s.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("roller2s.mod", false, rank); m_object->SetPosition(1, Math::Vector(0.0f, 0.0f, 0.0f)); m_object->SetAngleZ(1, 0.0f); @@ -742,8 +692,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(2, rank); m_object->SetObjectParent(2, 1); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "roller3s.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("roller3s.mod", false, rank); m_object->SetPosition(2, Math::Vector(7.0f, 4.5f, 0.0f)); m_object->SetAngleZ(2, 0.0f); @@ -752,21 +701,19 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(3, rank); m_object->SetObjectParent(3, 2); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "roller4s.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("roller4s.mod", false, rank); m_object->SetPosition(3, Math::Vector(0.0f, 1.0f, 0.0f)); m_object->SetAngleZ(3, 0.0f); } - if ( type == OBJECT_MOBILEsa ) + if (type == OBJECT_MOBILEsa) { // Creates the holder. rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(1, rank); m_object->SetObjectParent(1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "subm2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("subm2.mod", false, rank); m_object->SetPosition(1, Math::Vector(4.2f, 3.0f, 0.0f)); // Creates the right tong. @@ -774,8 +721,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(2, rank); m_object->SetObjectParent(2, 1); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "subm3.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("subm3.mod", false, rank); m_object->SetPosition(2, Math::Vector(0.5f, 0.0f, -1.5f)); // Creates the left tong. @@ -783,21 +729,18 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(3, rank); m_object->SetObjectParent(3, 1); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "subm3.mod")); - pModFile->Mirror(); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("subm3.mod", true, rank); m_object->SetPosition(3, Math::Vector(0.5f, 0.0f, 1.5f)); } - if ( type == OBJECT_MOBILEdr ) + if (type == OBJECT_MOBILEdr) { // Creates the carousel. rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(1, rank); m_object->SetObjectParent(1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "drawer4.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("drawer4.mod", false, rank); m_object->SetPosition(1, Math::Vector(-3.0f, 3.0f, 0.0f)); // Creates the key. @@ -807,8 +750,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(2, rank); m_object->SetObjectParent(2, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "drawer5.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("drawer5.mod", false, rank); m_posKey = Math::Vector(3.0f, 5.7f, 0.0f); m_object->SetPosition(2, m_posKey); m_object->SetAngleY(2, 90.0f*Math::PI/180.0f); @@ -821,16 +763,14 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(10+i, rank); m_object->SetObjectParent(10+i, 1); - std::string baseName = m_app->GetDataFilePath(DIR_MODEL, "drawer%d.mod"); - sprintf(name, baseName.c_str(), 10+i); - pModFile->ReadModel(name); - pModFile->CreateEngineObject(rank); + sprintf(name, "drawer%d.mod", 10+i); + modelManager->AddModelReference(name, false, rank); m_object->SetPosition(10+i, Math::Vector(0.0f, 0.0f, 0.0f)); m_object->SetAngleY(10+i, 45.0f*Math::PI/180.0f*i); } } - if ( type == OBJECT_MOBILEwt ) + if (type == OBJECT_MOBILEwt) { // Creates the key. if ( m_object->GetToy() ) @@ -839,23 +779,21 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(2, rank); m_object->SetObjectParent(2, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "drawer5.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("drawer5.mod", false, rank); m_posKey = Math::Vector(0.2f, 4.1f, 0.0f); m_object->SetPosition(2, m_posKey); m_object->SetAngleY(2, 90.0f*Math::PI/180.0f); } } - if ( type == OBJECT_APOLLO2 ) + if (type == OBJECT_APOLLO2) { // Creates the accessories. rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(1, rank); m_object->SetObjectParent(1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj2.mod")); // antenna - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("apolloj2.mod", false, rank); // antenna m_object->SetPosition(1, Math::Vector(5.5f, 8.8f, 2.0f)); m_object->SetAngleY(1, -120.0f*Math::PI/180.0f); m_object->SetAngleZ(1, 45.0f*Math::PI/180.0f); @@ -864,8 +802,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(2, rank); m_object->SetObjectParent(2, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj3.mod")); // camera - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("apolloj3.mod", false, rank); // camera m_object->SetPosition(2, Math::Vector(5.5f, 2.8f, -2.0f)); m_object->SetAngleY(2, 30.0f*Math::PI/180.0f); @@ -874,32 +811,28 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(6, rank); m_object->SetObjectParent(6, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj4.mod")); // wheel - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("apolloj4.mod", false, rank); // wheel m_object->SetPosition(6, Math::Vector(-5.75f, 1.65f, -5.0f)); rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(7, rank); m_object->SetObjectParent(7, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj4.mod")); // wheel - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("apolloj4.mod", false, rank); // wheel m_object->SetPosition(7, Math::Vector(-5.75f, 1.65f, 5.0f)); rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(8, rank); m_object->SetObjectParent(8, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj4.mod")); // wheel - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("apolloj4.mod", false, rank); // wheel m_object->SetPosition(8, Math::Vector(5.75f, 1.65f, -5.0f)); rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(9, rank); m_object->SetObjectParent(9, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj4.mod")); // wheel - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("apolloj4.mod", false, rank); // wheel m_object->SetPosition(9, Math::Vector(5.75f, 1.65f, 5.00f)); // Creates mud guards. @@ -907,56 +840,51 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(10, rank); m_object->SetObjectParent(10, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj6.mod")); // wheel - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("apolloj6.mod", false, rank); // wheel m_object->SetPosition(10, Math::Vector(-5.75f, 1.65f, -5.0f)); rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(11, rank); m_object->SetObjectParent(11, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj6.mod")); // wheel - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("apolloj6.mod", false, rank); // wheel m_object->SetPosition(11, Math::Vector(-5.75f, 1.65f, 5.0f)); rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(12, rank); m_object->SetObjectParent(12, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj5.mod")); // wheel - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("apolloj5.mod", false, rank); // wheel m_object->SetPosition(12, Math::Vector(5.75f, 1.65f, -5.0f)); rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(13, rank); m_object->SetObjectParent(13, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj5.mod")); // wheel - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("apolloj5.mod", false, rank); // wheel m_object->SetPosition(13, Math::Vector(5.75f, 1.65f, 5.00f)); } -#if 1 - if ( type == OBJECT_MOBILErt || - type == OBJECT_MOBILErc || - type == OBJECT_MOBILErr || - type == OBJECT_MOBILErs ) + if (type == OBJECT_MOBILErt || + type == OBJECT_MOBILErc || + type == OBJECT_MOBILErr || + type == OBJECT_MOBILErs) { m_object->CreateShadowCircle(6.0f, 1.0f); } - else if ( type == OBJECT_MOBILEta || - type == OBJECT_MOBILEtc || - type == OBJECT_MOBILEti || - type == OBJECT_MOBILEts || - type == OBJECT_MOBILEsa ) + else if (type == OBJECT_MOBILEta || + type == OBJECT_MOBILEtc || + type == OBJECT_MOBILEti || + type == OBJECT_MOBILEts || + type == OBJECT_MOBILEsa) { m_object->CreateShadowCircle(5.0f, 1.0f); } - else if ( type == OBJECT_MOBILEdr ) + else if (type == OBJECT_MOBILEdr) { m_object->CreateShadowCircle(4.5f, 1.0f); } - else if ( type == OBJECT_APOLLO2 ) + else if (type == OBJECT_APOLLO2) { m_object->CreateShadowCircle(7.0f, 0.8f); } @@ -964,50 +892,12 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, { m_object->CreateShadowCircle(4.0f, 1.0f); } -#else - if ( type == OBJECT_MOBILErt || - type == OBJECT_MOBILErc || - type == OBJECT_MOBILErr || - type == OBJECT_MOBILErs ) - { - m_object->CreateShadowCircle(6.0f, 1.0f, D3DSHADOWTANK); - } - else if ( type == OBJECT_MOBILEta || - type == OBJECT_MOBILEtc || - type == OBJECT_MOBILEti || - type == OBJECT_MOBILEts ) - { - m_object->CreateShadowCircle(4.0f, 1.0f, D3DSHADOWTANK); - } - else if ( type == OBJECT_MOBILEfa || - type == OBJECT_MOBILEfc || - type == OBJECT_MOBILEfi || - type == OBJECT_MOBILEfs ) - { - m_object->CreateShadowCircle(4.0f, 1.0f, D3DSHADOWFLY); - } - else if ( type == OBJECT_MOBILEwa || - type == OBJECT_MOBILEwc || - type == OBJECT_MOBILEwi || - type == OBJECT_MOBILEws ) - { - m_object->CreateShadowCircle(4.0f, 1.0f, D3DSHADOWWHEEL); - } - else if ( type == OBJECT_APOLLO2 ) - { - m_object->CreateShadowCircle(6.0f, 0.8f); - } - else - { - m_object->CreateShadowCircle(4.0f, 1.0f, D3DSHADOWNORM); - } -#endif - if ( type == OBJECT_MOBILEfa || - type == OBJECT_MOBILEfc || - type == OBJECT_MOBILEfi || - type == OBJECT_MOBILEfs || - type == OBJECT_MOBILEft ) // flying? + if (type == OBJECT_MOBILEfa || + type == OBJECT_MOBILEfc || + type == OBJECT_MOBILEfi || + type == OBJECT_MOBILEfs || + type == OBJECT_MOBILEft) // flying? { //? color.r = 0.5f-1.0f; //? color.g = 0.2f-1.0f; @@ -1025,9 +915,9 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, CreatePhysics(type); m_object->SetFloorHeight(0.0f); - if ( power > 0.0f && - type != OBJECT_MOBILEdr && - type != OBJECT_APOLLO2 ) + if (power > 0.0f && + type != OBJECT_MOBILEdr && + type != OBJECT_APOLLO2) { color.r = 1.0f; color.g = 1.0f; @@ -1043,9 +933,8 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); pPower->SetObjectRank(0, rank); - if ( power <= 1.0f ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "power.mod")); - else pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "atomic.mod")); - pModFile->CreateEngineObject(rank); + if ( power <= 1.0f ) modelManager->AddModelReference("power.mod", false, rank); + else modelManager->AddModelReference("atomic.mod", false, rank); pPower->SetPosition(0, m_object->GetCharacter()->posPower); pPower->CreateCrashSphere(Math::Vector(0.0f, 1.0f, 0.0f), 1.0f, SOUND_BOUMm, 0.45f); @@ -1063,7 +952,6 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->LoadAllTextures(); - delete pModFile; return true; } diff --git a/src/object/motion/motionworm.cpp b/src/object/motion/motionworm.cpp index 2401ebd..b53b865 100644 --- a/src/object/motion/motionworm.cpp +++ b/src/object/motion/motionworm.cpp @@ -19,7 +19,7 @@ #include "app/app.h" -#include "graphics/engine/modelfile.h" +#include "graphics/engine/modelmanager.h" #include "graphics/engine/particle.h" #include "graphics/engine/terrain.h" @@ -81,13 +81,10 @@ void CMotionWorm::DeleteObject(bool bAll) bool CMotionWorm::Create(Math::Vector pos, float angle, ObjectType type, float power) { - Gfx::CModelFile* pModFile; int rank, i; float px; -// if ( m_engine->GetRestCreate() < 2+WORM_PART+1 ) return false; - - pModFile = new Gfx::CModelFile(m_iMan); + Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer(); m_object->SetType(type); @@ -95,8 +92,7 @@ bool CMotionWorm::Create(Math::Vector pos, float angle, ObjectType type, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICULE); // this is a moving object m_object->SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "worm0.mod")); // there is no purpose! - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("worm0.mod", false, rank); // there is no purpose! m_object->SetPosition(0, pos); m_object->SetAngleY(0, angle); @@ -111,8 +107,7 @@ bool CMotionWorm::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(1, rank); m_object->SetObjectParent(1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "worm1.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("worm1.mod", false, rank); m_object->SetPosition(1, Math::Vector(px, 0.0f, 0.0f)); px -= 1.0f; @@ -123,8 +118,7 @@ bool CMotionWorm::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(2+i, rank); m_object->SetObjectParent(2+i, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "worm2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("worm2.mod", false, rank); m_object->SetPosition(2+i, Math::Vector(px, 0.0f, 0.0f)); px -= 1.0f; } @@ -134,8 +128,7 @@ bool CMotionWorm::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); m_object->SetObjectRank(2+WORM_PART, rank); m_object->SetObjectParent(2+WORM_PART, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "worm3.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("worm3.mod", false, rank); m_object->SetPosition(2+WORM_PART, Math::Vector(px, 0.0f, 0.0f)); m_object->CreateShadowCircle(0.0f, 1.0f, Gfx::ENG_SHADOW_WORM); @@ -148,7 +141,6 @@ bool CMotionWorm::Create(Math::Vector pos, float angle, ObjectType type, m_engine->LoadAllTextures(); - delete pModFile; return true; } diff --git a/src/object/object.cpp b/src/object/object.cpp index 2eade93..afa7815 100644 --- a/src/object/object.cpp +++ b/src/object/object.cpp @@ -27,7 +27,7 @@ #include "graphics/engine/lightman.h" #include "graphics/engine/lightning.h" -#include "graphics/engine/modelfile.h" +#include "graphics/engine/modelmanager.h" #include "graphics/engine/particle.h" #include "graphics/engine/pyro.h" #include "graphics/engine/terrain.h" @@ -2351,11 +2351,10 @@ bool CObject::CreateShadowCircle(float radius, float intensity, bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, ObjectType type, float power) { - Gfx::CModelFile* pModFile; Math::Point p; int rank, i; - pModFile = new Gfx::CModelFile(m_iMan); + Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer(); SetType(type); @@ -2365,8 +2364,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, if ( m_type == OBJECT_PORTICO ) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "portico1.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("portico1.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetFloorHeight(0.0f); @@ -2375,16 +2373,14 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(1, rank); SetObjectParent(1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "portico2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("portico2.mod", false, rank); SetPosition(1, Math::Vector(0.0f, 67.0f, 0.0f)); rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(2, rank); SetObjectParent(2, 1); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "portico3.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("portico3.mod", false, rank); SetPosition(2, Math::Vector(0.0f, 0.0f, -33.0f)); SetAngleY(2, 45.0f*Math::PI/180.0f); @@ -2392,8 +2388,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(3, rank); SetObjectParent(3, 2); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "portico4.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("portico4.mod", false, rank); SetPosition(3, Math::Vector(50.0f, 0.0f, 0.0f)); SetAngleY(3, -60.0f*Math::PI/180.0f); @@ -2401,8 +2396,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(4, rank); SetObjectParent(4, 3); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "portico5.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("portico5.mod", false, rank); SetPosition(4, Math::Vector(35.0f, 0.0f, 0.0f)); SetAngleY(4, -55.0f*Math::PI/180.0f); @@ -2410,8 +2404,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(5, rank); SetObjectParent(5, 1); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "portico3.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("portico3.mod", false, rank); SetPosition(5, Math::Vector(0.0f, 0.0f, 33.0f)); SetAngleY(5, -45.0f*Math::PI/180.0f); @@ -2419,8 +2412,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(6, rank); SetObjectParent(6, 5); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "portico4.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("portico4.mod", false, rank); SetPosition(6, Math::Vector(50.0f, 0.0f, 0.0f)); SetAngleY(6, 60.0f*Math::PI/180.0f); @@ -2428,8 +2420,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(7, rank); SetObjectParent(7, 6); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "portico5.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("portico5.mod", false, rank); SetPosition(7, Math::Vector(35.0f, 0.0f, 0.0f)); SetAngleY(7, 55.0f*Math::PI/180.0f); @@ -2437,8 +2428,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(8, rank); SetObjectParent(8, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "portico6.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("portico6.mod", false, rank); SetPosition(8, Math::Vector(-35.0f, 50.0f, -35.0f)); SetAngleY(8, -Math::PI/2.0f); SetZoom(8, 2.0f); @@ -2447,16 +2437,14 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(9, rank); SetObjectParent(9, 8); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "portico7.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("portico7.mod", false, rank); SetPosition(9, Math::Vector(0.0f, 4.5f, 1.9f)); rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(10, rank); SetObjectParent(10, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "portico6.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("portico6.mod", false, rank); SetPosition(10, Math::Vector(-35.0f, 50.0f, 35.0f)); SetAngleY(10, -Math::PI/2.0f); SetZoom(10, 2.0f); @@ -2465,8 +2453,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(11, rank); SetObjectParent(11, 10); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "portico7.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("portico7.mod", false, rank); SetPosition(11, Math::Vector(0.0f, 4.5f, 1.9f)); CreateCrashSphere(Math::Vector( 0.0f, 28.0f, 0.0f), 45.5f, SOUND_BOUMm, 0.45f); @@ -2487,8 +2474,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, if ( m_type == OBJECT_BASE ) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "base1.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("base1.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetFloorHeight(0.0f); @@ -2499,8 +2485,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(1+i, rank); SetObjectParent(1+i, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "base2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("base2.mod", false, rank); p = Math::RotatePoint(-Math::PI/4.0f*i, 27.8f); SetPosition(1+i, Math::Vector(p.x, 30.0f, p.y)); SetAngleY(1+i, Math::PI/4.0f*i); @@ -2510,17 +2495,14 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(10+i, rank); SetObjectParent(10+i, 1+i); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "base4.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("base4.mod", false, rank); SetPosition(10+i, Math::Vector(23.5f, 0.0f, 7.0f)); rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(18+i, rank); SetObjectParent(18+i, 1+i); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "base4.mod")); - pModFile->Mirror(); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("base4.mod", true, rank); SetPosition(18+i, Math::Vector(23.5f, 0.0f, -7.0f)); } @@ -2528,8 +2510,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(9, rank); SetObjectParent(9, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "base3.mod")); // central pillar - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("base3.mod", false, rank); // central pillar CreateCrashSphere(Math::Vector( 0.0f, 33.0f, 0.0f), 2.5f, SOUND_BOUMm, 0.45f); CreateCrashSphere(Math::Vector( 0.0f, 39.0f, 0.0f), 2.5f, SOUND_BOUMm, 0.45f); @@ -2559,8 +2540,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, if ( m_type == OBJECT_DERRICK ) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "derrick1.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("derrick1.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetFloorHeight(0.0f); @@ -2569,8 +2549,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(1, rank); SetObjectParent(1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "derrick2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("derrick2.mod", false, rank); CreateCrashSphere(Math::Vector(0.0f, 0.0f, 0.0f), 6.0f, SOUND_BOUMm, 0.45f); CreateCrashSphere(Math::Vector(0.0f, 10.0f, 0.0f), 5.0f, SOUND_BOUMm, 0.45f); @@ -2584,8 +2563,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, if ( m_type == OBJECT_RESEARCH ) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "search1.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("search1.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetFloorHeight(0.0f); @@ -2594,16 +2572,14 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(1, rank); SetObjectParent(1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "search2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("search2.mod", false, rank); SetPosition(1, Math::Vector(0.0f, 13.0f, 0.0f)); rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(2, rank); SetObjectParent(2, 1); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "search3.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("search3.mod", false, rank); SetPosition(2, Math::Vector(0.0f, 4.0f, 0.0f)); SetAngleZ(2, 35.0f*Math::PI/180.0f); @@ -2619,8 +2595,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, if ( m_type == OBJECT_RADAR ) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "radar1.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("radar1.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetFloorHeight(0.0f); @@ -2629,16 +2604,14 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(1, rank); SetObjectParent(1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "radar2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("radar2.mod", false, rank); SetPosition(1, Math::Vector(0.0f, 5.0f, 0.0f)); rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(2, rank); SetObjectParent(2, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "radar3.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("radar3.mod", false, rank); SetPosition(2, Math::Vector(0.0f, 11.0f, 0.0f)); SetAngleY(2, -Math::PI/2.0f); @@ -2646,8 +2619,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(3, rank); SetObjectParent(3, 2); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "radar4.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("radar4.mod", false, rank); SetPosition(3, Math::Vector(0.0f, 4.5f, 1.9f)); CreateCrashSphere(Math::Vector(0.0f, 3.0f, 0.0f), 6.0f, SOUND_BOUMm, 0.45f); @@ -2659,8 +2631,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, if ( m_type == OBJECT_INFO ) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "info1.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("info1.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetFloorHeight(0.0f); @@ -2669,8 +2640,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(1, rank); SetObjectParent(1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "info2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("info2.mod", false, rank); SetPosition(1, Math::Vector(0.0f, 5.0f, 0.0f)); for ( i=0 ; i<3 ; i++ ) @@ -2679,16 +2649,14 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(2+i*2, rank); SetObjectParent(2+i*2, 1); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "info3.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("info3.mod", false, rank); SetPosition(2+i*2, Math::Vector(0.0f, 4.5f, 0.0f)); rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(3+i*2, rank); SetObjectParent(3+i*2, 2+i*2); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "radar4.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("radar4.mod", false, rank); SetPosition(3+i*2, Math::Vector(0.0f, 0.0f, -4.0f)); SetAngleY(2+i*2, 2.0f*Math::PI/3.0f*i); @@ -2703,8 +2671,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, if ( m_type == OBJECT_ENERGY ) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "energy.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("energy.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetFloorHeight(0.0f); @@ -2722,8 +2689,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, if ( m_type == OBJECT_LABO ) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "labo1.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("labo1.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetFloorHeight(0.0f); @@ -2732,8 +2698,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(1, rank); SetObjectParent(1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "labo2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("labo2.mod", false, rank); SetPosition(1, Math::Vector(-9.0f, 3.0f, 0.0f)); SetAngleZ(1, Math::PI/2.0f); @@ -2741,16 +2706,14 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(2, rank); SetObjectParent(2, 1); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "labo3.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("labo3.mod", false, rank); SetPosition(2, Math::Vector(9.0f, -1.0f, 0.0f)); rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(3, rank); SetObjectParent(3, 2); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "labo4.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("labo4.mod", false, rank); SetPosition(3, Math::Vector(0.0f, 0.0f, 0.0f)); SetAngleZ(3, 80.0f*Math::PI/180.0f); @@ -2758,8 +2721,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(4, rank); SetObjectParent(4, 2); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "labo4.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("labo4.mod", false, rank); SetPosition(4, Math::Vector(0.0f, 0.0f, 0.0f)); SetAngleZ(4, 80.0f*Math::PI/180.0f); SetAngleY(4, Math::PI*2.0f/3.0f); @@ -2768,8 +2730,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(5, rank); SetObjectParent(5, 2); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "labo4.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("labo4.mod", false, rank); SetPosition(5, Math::Vector(0.0f, 0.0f, 0.0f)); SetAngleZ(5, 80.0f*Math::PI/180.0f); SetAngleY(5, -Math::PI*2.0f/3.0f); @@ -2788,8 +2749,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, if ( m_type == OBJECT_FACTORY ) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "factory1.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("factory1.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetFloorHeight(0.0f); @@ -2800,8 +2760,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(1+i, rank); SetObjectParent(1+i, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "factory2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("factory2.mod", false, rank); SetPosition(1+i, Math::Vector(10.0f, 2.0f*i, 10.0f)); SetAngleZ(1+i, Math::PI/2.0f); SetZoomZ(1+i, 0.30f); @@ -2810,8 +2769,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(10+i, rank); SetObjectParent(10+i, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "factory2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("factory2.mod", false, rank); SetPosition(10+i, Math::Vector(10.0f, 2.0f*i, -10.0f)); SetAngleZ(10+i, -Math::PI/2.0f); SetAngleY(10+i, Math::PI); @@ -2848,8 +2806,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, if ( m_type == OBJECT_REPAIR ) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "repair1.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("repair1.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetFloorHeight(0.0f); @@ -2858,8 +2815,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(1, rank); SetObjectParent(1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "repair2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("repair2.mod", false, rank); SetPosition(1, Math::Vector(-11.0f, 13.5f, 0.0f)); SetAngleZ(1, Math::PI/2.0f); @@ -2874,8 +2830,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, if ( m_type == OBJECT_DESTROYER ) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "destroy1.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("destroy1.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetFloorHeight(0.0f); @@ -2884,8 +2839,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(1, rank); SetObjectParent(1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "destroy2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("destroy2.mod", false, rank); SetPosition(1, Math::Vector(0.0f, 0.0f, 0.0f)); m_terrain->AddBuildingLevel(pos, 7.0f, 9.0f, 1.0f, 0.5f); @@ -2900,8 +2854,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, if ( m_type == OBJECT_STATION ) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "station.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("station.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetFloorHeight(0.0f); @@ -2917,8 +2870,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, if ( m_type == OBJECT_CONVERT ) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "convert1.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("convert1.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetFloorHeight(0.0f); @@ -2927,16 +2879,14 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(1, rank); SetObjectParent(1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "convert2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("convert2.mod", false, rank); SetPosition(1, Math::Vector(0.0f, 14.0f, 0.0f)); rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(2, rank); SetObjectParent(2, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "convert3.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("convert3.mod", false, rank); SetPosition(2, Math::Vector(0.0f, 11.5f, 0.0f)); SetAngleX(2, -Math::PI*0.35f); @@ -2944,8 +2894,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(3, rank); SetObjectParent(3, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "convert3.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("convert3.mod", false, rank); SetPosition(3, Math::Vector(0.0f, 11.5f, 0.0f)); SetAngleY(3, Math::PI); SetAngleX(3, -Math::PI*0.35f); @@ -2961,8 +2910,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, if ( m_type == OBJECT_TOWER ) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "tower.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("tower.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetFloorHeight(0.0f); @@ -2971,8 +2919,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(1, rank); SetObjectParent(1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "roller2c.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("roller2c.mod", false, rank); SetPosition(1, Math::Vector(0.0f, 20.0f, 0.0f)); SetAngleZ(1, Math::PI/2.0f); @@ -2980,8 +2927,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(2, rank); SetObjectParent(2, 1); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "roller3c.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("roller3c.mod", false, rank); SetPosition(2, Math::Vector(4.5f, 0.0f, 0.0f)); SetAngleZ(2, 0.0f); @@ -2999,8 +2945,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, if ( m_type == OBJECT_NUCLEAR ) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "nuclear1.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("nuclear1.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetFloorHeight(0.0f); @@ -3009,8 +2954,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(1, rank); SetObjectParent(1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "nuclear2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("nuclear2.mod", false, rank); SetPosition(1, Math::Vector(20.0f, 10.0f, 0.0f)); SetAngleZ(1, 135.0f*Math::PI/180.0f); @@ -3026,8 +2970,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, if ( m_type == OBJECT_PARA ) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "para.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("para.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetFloorHeight(0.0f); @@ -3052,8 +2995,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, if ( m_type == OBJECT_SAFE ) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "safe1.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("safe1.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetFloorHeight(0.0f); @@ -3062,16 +3004,14 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(1, rank); SetObjectParent(1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "safe2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("safe2.mod", false, rank); SetZoom(1, 1.05f); rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(2, rank); SetObjectParent(2, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "safe3.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("safe3.mod", false, rank); SetZoom(2, 1.05f); m_terrain->AddBuildingLevel(pos, 18.0f, 20.0f, 1.0f, 0.5f); @@ -3084,8 +3024,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, if ( m_type == OBJECT_HUSTON ) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "huston1.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("huston1.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetFloorHeight(0.0f); @@ -3094,8 +3033,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(1, rank); SetObjectParent(1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "huston2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("huston2.mod", false, rank); SetPosition(1, Math::Vector(0.0f, 39.0f, 30.0f)); SetAngleY(1, -Math::PI/2.0f); SetZoom(1, 3.0f); @@ -3104,8 +3042,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(2, rank); SetObjectParent(2, 1); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "huston3.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("huston3.mod", false, rank); SetPosition(2, Math::Vector(0.0f, 4.5f, 1.9f)); CreateCrashSphere(Math::Vector( 15.0f, 6.0f, -53.0f), 16.0f, SOUND_BOUMm, 0.45f); @@ -3128,8 +3065,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, if ( m_type == OBJECT_TARGET1 ) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "target1.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("target1.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, 1.5f); @@ -3158,8 +3094,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, if ( m_type == OBJECT_TARGET2 ) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "target2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("target2.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetFloorHeight(0.0f); @@ -3169,8 +3104,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, if ( m_type == OBJECT_NEST ) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "nest.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("nest.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetFloorHeight(0.0f); @@ -3182,8 +3116,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, if ( m_type == OBJECT_START ) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "start.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("start.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetFloorHeight(0.0f); @@ -3193,8 +3126,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, if ( m_type == OBJECT_END ) { - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "end.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("end.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetFloorHeight(0.0f); @@ -3214,9 +3146,8 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); pPower->SetObjectRank(0, rank); - if ( power <= 1.0f ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "power.mod")); - else pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "atomic.mod")); - pModFile->CreateEngineObject(rank); + if ( power <= 1.0f ) modelManager->AddModelReference("power.mod", false, rank); + else modelManager->AddModelReference("atomic.mod", false, rank); pPower->SetPosition(0, GetCharacter()->posPower); pPower->CreateCrashSphere(Math::Vector(0.0f, 1.0f, 0.0f), 1.0f, SOUND_BOUMm, 0.45f); @@ -3237,7 +3168,6 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, CreateOtherObject(type); m_engine->LoadAllTextures(); - delete pModFile; return true; } @@ -3246,11 +3176,10 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, bool CObject::CreateResource(Math::Vector pos, float angle, ObjectType type, float power) { - Gfx::CModelFile* pModFile; int rank; float radius, height; - pModFile = new Gfx::CModelFile(m_iMan); + Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer(); SetType(type); @@ -3260,46 +3189,44 @@ bool CObject::CreateResource(Math::Vector pos, float angle, ObjectType type, SetEnergy(power); std::string name; - if ( type == OBJECT_STONE ) name = m_app->GetDataFilePath(DIR_MODEL, "stone.mod"); - if ( type == OBJECT_URANIUM ) name = m_app->GetDataFilePath(DIR_MODEL, "uranium.mod"); - if ( type == OBJECT_METAL ) name = m_app->GetDataFilePath(DIR_MODEL, "metal.mod"); - if ( type == OBJECT_POWER ) name = m_app->GetDataFilePath(DIR_MODEL, "power.mod"); - if ( type == OBJECT_ATOMIC ) name = m_app->GetDataFilePath(DIR_MODEL, "atomic.mod"); - if ( type == OBJECT_BULLET ) name = m_app->GetDataFilePath(DIR_MODEL, "bullet.mod"); - if ( type == OBJECT_BBOX ) name = m_app->GetDataFilePath(DIR_MODEL, "bbox.mod"); - if ( type == OBJECT_KEYa ) name = m_app->GetDataFilePath(DIR_MODEL, "keya.mod"); - if ( type == OBJECT_KEYb ) name = m_app->GetDataFilePath(DIR_MODEL, "keyb.mod"); - if ( type == OBJECT_KEYc ) name = m_app->GetDataFilePath(DIR_MODEL, "keyc.mod"); - if ( type == OBJECT_KEYd ) name = m_app->GetDataFilePath(DIR_MODEL, "keyd.mod"); - if ( type == OBJECT_TNT ) name = m_app->GetDataFilePath(DIR_MODEL, "tnt.mod"); - if ( type == OBJECT_SCRAP1 ) name = m_app->GetDataFilePath(DIR_MODEL, "scrap1.mod"); - if ( type == OBJECT_SCRAP2 ) name = m_app->GetDataFilePath(DIR_MODEL, "scrap2.mod"); - if ( type == OBJECT_SCRAP3 ) name = m_app->GetDataFilePath(DIR_MODEL, "scrap3.mod"); - if ( type == OBJECT_SCRAP4 ) name = m_app->GetDataFilePath(DIR_MODEL, "scrap4.mod"); - if ( type == OBJECT_SCRAP5 ) name = m_app->GetDataFilePath(DIR_MODEL, "scrap5.mod"); - if ( type == OBJECT_BOMB ) name = m_app->GetDataFilePath(DIR_MODEL, "bomb.mod"); - if ( type == OBJECT_WAYPOINT ) name = m_app->GetDataFilePath(DIR_MODEL, "waypoint.mod"); - if ( type == OBJECT_SHOW ) name = m_app->GetDataFilePath(DIR_MODEL, "show.mod"); - if ( type == OBJECT_WINFIRE ) name = m_app->GetDataFilePath(DIR_MODEL, "winfire.mod"); - if ( type == OBJECT_BAG ) name = m_app->GetDataFilePath(DIR_MODEL, "bag.mod"); - if ( type == OBJECT_MARKSTONE ) name = m_app->GetDataFilePath(DIR_MODEL, "cross1.mod"); - if ( type == OBJECT_MARKURANIUM ) name = m_app->GetDataFilePath(DIR_MODEL, "cross3.mod"); - if ( type == OBJECT_MARKPOWER ) name = m_app->GetDataFilePath(DIR_MODEL, "cross2.mod"); - if ( type == OBJECT_MARKKEYa ) name = m_app->GetDataFilePath(DIR_MODEL, "crossa.mod"); - if ( type == OBJECT_MARKKEYb ) name = m_app->GetDataFilePath(DIR_MODEL, "crossb.mod"); - if ( type == OBJECT_MARKKEYc ) name = m_app->GetDataFilePath(DIR_MODEL, "crossc.mod"); - if ( type == OBJECT_MARKKEYd ) name = m_app->GetDataFilePath(DIR_MODEL, "crossd.mod"); - if ( type == OBJECT_EGG ) name = m_app->GetDataFilePath(DIR_MODEL, "egg.mod"); - - pModFile->ReadModel(name); - pModFile->CreateEngineObject(rank); + if ( type == OBJECT_STONE ) name = "stone.mod"; + if ( type == OBJECT_URANIUM ) name = "uranium.mod"; + if ( type == OBJECT_METAL ) name = "metal.mod"; + if ( type == OBJECT_POWER ) name = "power.mod"; + if ( type == OBJECT_ATOMIC ) name = "atomic.mod"; + if ( type == OBJECT_BULLET ) name = "bullet.mod"; + if ( type == OBJECT_BBOX ) name = "bbox.mod"; + if ( type == OBJECT_KEYa ) name = "keya.mod"; + if ( type == OBJECT_KEYb ) name = "keyb.mod"; + if ( type == OBJECT_KEYc ) name = "keyc.mod"; + if ( type == OBJECT_KEYd ) name = "keyd.mod"; + if ( type == OBJECT_TNT ) name = "tnt.mod"; + if ( type == OBJECT_SCRAP1 ) name = "scrap1.mod"; + if ( type == OBJECT_SCRAP2 ) name = "scrap2.mod"; + if ( type == OBJECT_SCRAP3 ) name = "scrap3.mod"; + if ( type == OBJECT_SCRAP4 ) name = "scrap4.mod"; + if ( type == OBJECT_SCRAP5 ) name = "scrap5.mod"; + if ( type == OBJECT_BOMB ) name = "bomb.mod"; + if ( type == OBJECT_WAYPOINT ) name = "waypoint.mod"; + if ( type == OBJECT_SHOW ) name = "show.mod"; + if ( type == OBJECT_WINFIRE ) name = "winfire.mod"; + if ( type == OBJECT_BAG ) name = "bag.mod"; + if ( type == OBJECT_MARKSTONE ) name = "cross1.mod"; + if ( type == OBJECT_MARKURANIUM ) name = "cross3.mod"; + if ( type == OBJECT_MARKPOWER ) name = "cross2.mod"; + if ( type == OBJECT_MARKKEYa ) name = "crossa.mod"; + if ( type == OBJECT_MARKKEYb ) name = "crossb.mod"; + if ( type == OBJECT_MARKKEYc ) name = "crossc.mod"; + if ( type == OBJECT_MARKKEYd ) name = "crossd.mod"; + if ( type == OBJECT_EGG ) name = "egg.mod"; + + modelManager->AddModelReference(name, false, rank); SetPosition(0, pos); SetAngleY(0, angle); if ( type == OBJECT_SHOW ) // remains in the air? { - delete pModFile; return true; } @@ -3352,7 +3279,6 @@ bool CObject::CreateResource(Math::Vector pos, float angle, ObjectType type, pos.y += height; SetPosition(0, pos); // to display the shadows immediately - delete pModFile; return true; } @@ -3360,36 +3286,34 @@ bool CObject::CreateResource(Math::Vector pos, float angle, ObjectType type, bool CObject::CreateFlag(Math::Vector pos, float angle, ObjectType type) { - Gfx::CModelFile* pModFile; int rank, i; - pModFile = new Gfx::CModelFile(m_iMan); + Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer(); SetType(type); std::string name; name = ""; - if ( type == OBJECT_FLAGb ) name = m_app->GetDataFilePath(DIR_MODEL, "flag1b.mod"); - if ( type == OBJECT_FLAGr ) name = m_app->GetDataFilePath(DIR_MODEL, "flag1r.mod"); - if ( type == OBJECT_FLAGg ) name = m_app->GetDataFilePath(DIR_MODEL, "flag1g.mod"); - if ( type == OBJECT_FLAGy ) name = m_app->GetDataFilePath(DIR_MODEL, "flag1y.mod"); - if ( type == OBJECT_FLAGv ) name = m_app->GetDataFilePath(DIR_MODEL, "flag1v.mod"); + if ( type == OBJECT_FLAGb ) name = "flag1b.mod"; + if ( type == OBJECT_FLAGr ) name = "flag1r.mod"; + if ( type == OBJECT_FLAGg ) name = "flag1g.mod"; + if ( type == OBJECT_FLAGy ) name = "flag1y.mod"; + if ( type == OBJECT_FLAGv ) name = "flag1v.mod"; rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); // it is a stationary object SetObjectRank(0, rank); - pModFile->ReadModel(name); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference(name, false, rank); SetPosition(0, pos); SetAngleY(0, angle); name = ""; - if ( type == OBJECT_FLAGb ) name = m_app->GetDataFilePath(DIR_MODEL, "flag2b.mod"); - if ( type == OBJECT_FLAGr ) name = m_app->GetDataFilePath(DIR_MODEL, "flag2r.mod"); - if ( type == OBJECT_FLAGg ) name = m_app->GetDataFilePath(DIR_MODEL, "flag2g.mod"); - if ( type == OBJECT_FLAGy ) name = m_app->GetDataFilePath(DIR_MODEL, "flag2y.mod"); - if ( type == OBJECT_FLAGv ) name = m_app->GetDataFilePath(DIR_MODEL, "flag2v.mod"); + if ( type == OBJECT_FLAGb ) name = "flag2b.mod"; + if ( type == OBJECT_FLAGr ) name = "flag2r.mod"; + if ( type == OBJECT_FLAGg ) name = "flag2g.mod"; + if ( type == OBJECT_FLAGy ) name = "flag2y.mod"; + if ( type == OBJECT_FLAGv ) name = "flag2v.mod"; for ( i=0 ; i<4 ; i++ ) { @@ -3397,8 +3321,7 @@ bool CObject::CreateFlag(Math::Vector pos, float angle, ObjectType type) m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(1+i, rank); SetObjectParent(1+i, i); - pModFile->ReadModel(name); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference(name, false, rank); if ( i == 0 ) SetPosition(1+i, Math::Vector(0.15f, 5.0f, 0.0f)); else SetPosition(1+i, Math::Vector(0.79f, 0.0f, 0.0f)); } @@ -3414,7 +3337,6 @@ bool CObject::CreateFlag(Math::Vector pos, float angle, ObjectType type) pos = GetPosition(0); SetPosition(0, pos); // to display the shadows immediately - delete pModFile; return true; } @@ -3423,10 +3345,9 @@ bool CObject::CreateFlag(Math::Vector pos, float angle, ObjectType type) bool CObject::CreateBarrier(Math::Vector pos, float angle, float height, ObjectType type) { - Gfx::CModelFile* pModFile; int rank; - pModFile = new Gfx::CModelFile(m_iMan); + Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer(); SetType(type); @@ -3435,8 +3356,7 @@ bool CObject::CreateBarrier(Math::Vector pos, float angle, float height, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "barrier0.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("barrier0.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); @@ -3452,8 +3372,7 @@ bool CObject::CreateBarrier(Math::Vector pos, float angle, float height, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "barrier1.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("barrier1.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); @@ -3471,8 +3390,7 @@ bool CObject::CreateBarrier(Math::Vector pos, float angle, float height, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "barrier2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("barrier2.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); @@ -3490,8 +3408,7 @@ bool CObject::CreateBarrier(Math::Vector pos, float angle, float height, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "barrier3.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("barrier3.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); @@ -3515,7 +3432,6 @@ bool CObject::CreateBarrier(Math::Vector pos, float angle, float height, pos.y += height; SetPosition(0, pos); - delete pModFile; return true; } @@ -3524,10 +3440,9 @@ bool CObject::CreateBarrier(Math::Vector pos, float angle, float height, bool CObject::CreatePlant(Math::Vector pos, float angle, float height, ObjectType type) { - Gfx::CModelFile* pModFile; int rank; - pModFile = new Gfx::CModelFile(m_iMan); + Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer(); SetType(type); @@ -3540,12 +3455,11 @@ bool CObject::CreatePlant(Math::Vector pos, float angle, float height, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - if ( type == OBJECT_PLANT0 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant0.mod")); - if ( type == OBJECT_PLANT1 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant1.mod")); - if ( type == OBJECT_PLANT2 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant2.mod")); - if ( type == OBJECT_PLANT3 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant3.mod")); - if ( type == OBJECT_PLANT4 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant4.mod")); - pModFile->CreateEngineObject(rank); + if ( type == OBJECT_PLANT0 ) modelManager->AddModelReference("plant0.mod", false, rank); + if ( type == OBJECT_PLANT1 ) modelManager->AddModelReference("plant1.mod", false, rank); + if ( type == OBJECT_PLANT2 ) modelManager->AddModelReference("plant2.mod", false, rank); + if ( type == OBJECT_PLANT3 ) modelManager->AddModelReference("plant3.mod", false, rank); + if ( type == OBJECT_PLANT4 ) modelManager->AddModelReference("plant4.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); @@ -3565,10 +3479,9 @@ bool CObject::CreatePlant(Math::Vector pos, float angle, float height, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - if ( type == OBJECT_PLANT5 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant5.mod")); - if ( type == OBJECT_PLANT6 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant6.mod")); - if ( type == OBJECT_PLANT7 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant7.mod")); - pModFile->CreateEngineObject(rank); + if ( type == OBJECT_PLANT5 ) modelManager->AddModelReference("plant5.mod", false, rank); + if ( type == OBJECT_PLANT6 ) modelManager->AddModelReference("plant6.mod", false, rank); + if ( type == OBJECT_PLANT7 ) modelManager->AddModelReference("plant7.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); @@ -3584,9 +3497,8 @@ bool CObject::CreatePlant(Math::Vector pos, float angle, float height, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - if ( type == OBJECT_PLANT8 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant8.mod")); - if ( type == OBJECT_PLANT9 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant9.mod")); - pModFile->CreateEngineObject(rank); + if ( type == OBJECT_PLANT8 ) modelManager->AddModelReference("plant8.mod", false, rank); + if ( type == OBJECT_PLANT9 ) modelManager->AddModelReference("plant9.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); @@ -3605,12 +3517,11 @@ bool CObject::CreatePlant(Math::Vector pos, float angle, float height, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - if ( type == OBJECT_PLANT10 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant10.mod")); - if ( type == OBJECT_PLANT11 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant11.mod")); - if ( type == OBJECT_PLANT12 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant12.mod")); - if ( type == OBJECT_PLANT13 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant13.mod")); - if ( type == OBJECT_PLANT14 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant14.mod")); - pModFile->CreateEngineObject(rank); + if ( type == OBJECT_PLANT10 ) modelManager->AddModelReference("plant10.mod", false, rank); + if ( type == OBJECT_PLANT11 ) modelManager->AddModelReference("plant11.mod", false, rank); + if ( type == OBJECT_PLANT12 ) modelManager->AddModelReference("plant12.mod", false, rank); + if ( type == OBJECT_PLANT13 ) modelManager->AddModelReference("plant13.mod", false, rank); + if ( type == OBJECT_PLANT14 ) modelManager->AddModelReference("plant14.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); @@ -3630,12 +3541,11 @@ bool CObject::CreatePlant(Math::Vector pos, float angle, float height, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - if ( type == OBJECT_PLANT15 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant15.mod")); - if ( type == OBJECT_PLANT16 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant16.mod")); - if ( type == OBJECT_PLANT17 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant17.mod")); - if ( type == OBJECT_PLANT18 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant18.mod")); - if ( type == OBJECT_PLANT19 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant19.mod")); - pModFile->CreateEngineObject(rank); + if ( type == OBJECT_PLANT15 ) modelManager->AddModelReference("plant15.mod", false, rank); + if ( type == OBJECT_PLANT16 ) modelManager->AddModelReference("plant16.mod", false, rank); + if ( type == OBJECT_PLANT17 ) modelManager->AddModelReference("plant17.mod", false, rank); + if ( type == OBJECT_PLANT18 ) modelManager->AddModelReference("plant18.mod", false, rank); + if ( type == OBJECT_PLANT19 ) modelManager->AddModelReference("plant19.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); @@ -3654,8 +3564,7 @@ bool CObject::CreatePlant(Math::Vector pos, float angle, float height, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "tree0.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("tree0.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); @@ -3672,8 +3581,7 @@ bool CObject::CreatePlant(Math::Vector pos, float angle, float height, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "tree1.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("tree1.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); @@ -3691,8 +3599,7 @@ bool CObject::CreatePlant(Math::Vector pos, float angle, float height, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "tree2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("tree2.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); @@ -3710,8 +3617,7 @@ bool CObject::CreatePlant(Math::Vector pos, float angle, float height, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "tree3.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("tree3.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); @@ -3728,8 +3634,7 @@ bool CObject::CreatePlant(Math::Vector pos, float angle, float height, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "tree4.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("tree4.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); @@ -3745,8 +3650,7 @@ bool CObject::CreatePlant(Math::Vector pos, float angle, float height, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "tree5.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("tree5.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); @@ -3767,7 +3671,6 @@ bool CObject::CreatePlant(Math::Vector pos, float angle, float height, pos.y += height; SetPosition(0, pos); - delete pModFile; return true; } @@ -3776,10 +3679,9 @@ bool CObject::CreatePlant(Math::Vector pos, float angle, float height, bool CObject::CreateMushroom(Math::Vector pos, float angle, float height, ObjectType type) { - Gfx::CModelFile* pModFile; int rank; - pModFile = new Gfx::CModelFile(m_iMan); + Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer(); SetType(type); @@ -3788,8 +3690,7 @@ bool CObject::CreateMushroom(Math::Vector pos, float angle, float height, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mush1.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("mush1.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); @@ -3805,8 +3706,7 @@ bool CObject::CreateMushroom(Math::Vector pos, float angle, float height, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mush2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("mush2.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); @@ -3827,7 +3727,6 @@ bool CObject::CreateMushroom(Math::Vector pos, float angle, float height, pos.y += height; SetPosition(0, pos); - delete pModFile; return true; } @@ -3836,14 +3735,13 @@ bool CObject::CreateMushroom(Math::Vector pos, float angle, float height, bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height, ObjectType type) { - Gfx::CModelFile* pModFile; Math::Matrix* mat; Gfx::Color color; int rank; float fShadow; bool bFloorAdjust = true; - pModFile = new Gfx::CModelFile(m_iMan); + Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer(); SetType(type); @@ -3854,8 +3752,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen0.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen0.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -3874,8 +3771,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen1.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen1.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -3896,8 +3792,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen2.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -3919,8 +3814,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height //? m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_METAL); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen3.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen3.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -3935,8 +3829,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen4.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen4.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -3957,8 +3850,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen5.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen5.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -3974,8 +3866,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen6.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen6.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -3995,8 +3886,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen7.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen7.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4016,8 +3906,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen8.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen8.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4038,8 +3927,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen9.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen9.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4060,8 +3948,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen10.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen10.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4086,8 +3973,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen11.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen11.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetFloorHeight(0.0f); @@ -4111,8 +3997,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height //? m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_METAL); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen12.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen12.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4127,8 +4012,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen13.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen13.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4152,8 +4036,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen14.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen14.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4177,8 +4060,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen15.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen15.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4202,8 +4084,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen16.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen16.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4220,8 +4101,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen17.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen17.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4236,8 +4116,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen18.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen18.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4252,8 +4131,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen19.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen19.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4268,8 +4146,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen20.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen20.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4289,8 +4166,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen21.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen21.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4301,8 +4177,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen22.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen22.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4318,8 +4193,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen23.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen23.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4345,8 +4219,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen24.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen24.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4361,8 +4234,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen25.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen25.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4377,8 +4249,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen26.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen26.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4401,8 +4272,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen27.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen27.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4417,8 +4287,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height //? m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_METAL); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen28.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen28.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4432,8 +4301,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen29.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen29.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4445,8 +4313,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen30.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen30.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4461,8 +4328,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen31.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen31.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4480,8 +4346,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen32.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen32.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4499,8 +4364,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen33.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen33.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4514,8 +4378,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen34.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen34.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4529,8 +4392,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen35.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen35.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4548,8 +4410,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen36.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen36.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4561,8 +4422,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen37.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen37.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4574,8 +4434,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen38a.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen38a.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4584,16 +4443,14 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(1, rank); SetObjectParent(1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen38b.mod")); // engine - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen38b.mod", false, rank); // engine SetPosition(1, Math::Vector(0.0f, 30.0f, 0.0f)); rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(2, rank); SetObjectParent(2, 1); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen38c.mod")); // propeller - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen38c.mod", false, rank); // propeller SetPosition(2, Math::Vector(0.0f, 0.0f, 0.0f)); CreateCrashSphere(Math::Vector(0.0f, 2.0f, 0.0f), 10.0f, SOUND_BOUM, 0.10f); @@ -4606,8 +4463,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen39.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen39.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4622,8 +4478,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen40.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen40.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4638,8 +4493,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen41.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen41.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4650,8 +4504,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen42.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen42.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4665,8 +4518,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen43.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen43.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4680,8 +4532,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen44.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("teen44.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, zoom); @@ -4706,7 +4557,6 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height pos.y += height; SetPosition(0, pos); - delete pModFile; return true; } @@ -4715,11 +4565,10 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height bool CObject::CreateQuartz(Math::Vector pos, float angle, float height, ObjectType type) { - Gfx::CModelFile* pModFile; float radius; int rank; - pModFile = new Gfx::CModelFile(m_iMan); + Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer(); SetType(type); @@ -4728,8 +4577,7 @@ bool CObject::CreateQuartz(Math::Vector pos, float angle, float height, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_QUARTZ); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "quartz0.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("quartz0.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); @@ -4743,8 +4591,7 @@ bool CObject::CreateQuartz(Math::Vector pos, float angle, float height, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_QUARTZ); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "quartz1.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("quartz1.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); @@ -4758,8 +4605,7 @@ bool CObject::CreateQuartz(Math::Vector pos, float angle, float height, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_QUARTZ); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "quartz2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("quartz2.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); @@ -4773,8 +4619,7 @@ bool CObject::CreateQuartz(Math::Vector pos, float angle, float height, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_QUARTZ); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "quartz3.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("quartz3.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); @@ -4817,7 +4662,6 @@ bool CObject::CreateQuartz(Math::Vector pos, float angle, float height, m_particle->CreateParticle(pos, pos, Math::Point(2.0f, 2.0f), Gfx::PARTIQUARTZ, 0.7f+Math::Rand()*0.7f, radius, 0.0f); m_particle->CreateParticle(pos, pos, Math::Point(2.0f, 2.0f), Gfx::PARTIQUARTZ, 0.7f+Math::Rand()*0.7f, radius, 0.0f); - delete pModFile; return true; } @@ -4826,10 +4670,9 @@ bool CObject::CreateQuartz(Math::Vector pos, float angle, float height, bool CObject::CreateRoot(Math::Vector pos, float angle, float height, ObjectType type) { - Gfx::CModelFile* pModFile; int rank; - pModFile = new Gfx::CModelFile(m_iMan); + Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer(); SetType(type); @@ -4838,8 +4681,7 @@ bool CObject::CreateRoot(Math::Vector pos, float angle, float height, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "root0.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("root0.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, 2.0f); @@ -4860,8 +4702,7 @@ bool CObject::CreateRoot(Math::Vector pos, float angle, float height, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "root1.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("root1.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, 2.0f); @@ -4882,8 +4723,7 @@ bool CObject::CreateRoot(Math::Vector pos, float angle, float height, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "root2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("root2.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, 2.0f); @@ -4903,8 +4743,7 @@ bool CObject::CreateRoot(Math::Vector pos, float angle, float height, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "root3.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("root3.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, 2.0f); @@ -4926,8 +4765,7 @@ bool CObject::CreateRoot(Math::Vector pos, float angle, float height, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "root4.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("root4.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, 2.0f); @@ -4951,8 +4789,7 @@ bool CObject::CreateRoot(Math::Vector pos, float angle, float height, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "root4.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("root4.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, 2.0f); @@ -4961,8 +4798,7 @@ bool CObject::CreateRoot(Math::Vector pos, float angle, float height, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(1, rank); SetObjectParent(1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "root5.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("root5.mod", false, rank); SetPosition(1, Math::Vector(-5.0f, 28.0f, -4.0f)); SetAngleX(1, -30.0f*Math::PI/180.0f); SetAngleZ(1, 20.0f*Math::PI/180.0f); @@ -4992,7 +4828,6 @@ bool CObject::CreateRoot(Math::Vector pos, float angle, float height, pos.y += height; SetPosition(0, pos); - delete pModFile; return true; } @@ -5001,10 +4836,9 @@ bool CObject::CreateRoot(Math::Vector pos, float angle, float height, bool CObject::CreateHome(Math::Vector pos, float angle, float height, ObjectType type) { - Gfx::CModelFile* pModFile; int rank; - pModFile = new Gfx::CModelFile(m_iMan); + Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer(); SetType(type); @@ -5013,8 +4847,7 @@ bool CObject::CreateHome(Math::Vector pos, float angle, float height, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "home1.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("home1.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, 1.3f); @@ -5034,7 +4867,6 @@ bool CObject::CreateHome(Math::Vector pos, float angle, float height, pos.y += height; SetPosition(0, pos); - delete pModFile; return true; } @@ -5043,10 +4875,9 @@ bool CObject::CreateHome(Math::Vector pos, float angle, float height, bool CObject::CreateRuin(Math::Vector pos, float angle, float height, ObjectType type) { - Gfx::CModelFile* pModFile; int rank; - pModFile = new Gfx::CModelFile(m_iMan); + Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer(); SetType(type); @@ -5055,22 +4886,21 @@ bool CObject::CreateRuin(Math::Vector pos, float angle, float height, SetObjectRank(0, rank); std::string name; - if ( type == OBJECT_RUINmobilew1 ) name = m_app->GetDataFilePath(DIR_MODEL, "ruin1.mod"); - if ( type == OBJECT_RUINmobilew2 ) name = m_app->GetDataFilePath(DIR_MODEL, "ruin1.mod"); - if ( type == OBJECT_RUINmobilet1 ) name = m_app->GetDataFilePath(DIR_MODEL, "ruin2.mod"); - if ( type == OBJECT_RUINmobilet2 ) name = m_app->GetDataFilePath(DIR_MODEL, "ruin2.mod"); - if ( type == OBJECT_RUINmobiler1 ) name = m_app->GetDataFilePath(DIR_MODEL, "ruin3.mod"); - if ( type == OBJECT_RUINmobiler2 ) name = m_app->GetDataFilePath(DIR_MODEL, "ruin3.mod"); - if ( type == OBJECT_RUINfactory ) name = m_app->GetDataFilePath(DIR_MODEL, "ruin4.mod"); - if ( type == OBJECT_RUINdoor ) name = m_app->GetDataFilePath(DIR_MODEL, "ruin5.mod"); - if ( type == OBJECT_RUINsupport ) name = m_app->GetDataFilePath(DIR_MODEL, "ruin6.mod"); - if ( type == OBJECT_RUINradar ) name = m_app->GetDataFilePath(DIR_MODEL, "ruin7.mod"); - if ( type == OBJECT_RUINconvert ) name = m_app->GetDataFilePath(DIR_MODEL, "ruin8.mod"); - if ( type == OBJECT_RUINbase ) name = m_app->GetDataFilePath(DIR_MODEL, "ruin9.mod"); - if ( type == OBJECT_RUINhead ) name = m_app->GetDataFilePath(DIR_MODEL, "ruin10.mod"); - - pModFile->ReadModel(name); - pModFile->CreateEngineObject(rank); + if ( type == OBJECT_RUINmobilew1 ) name = "ruin1.mod"; + if ( type == OBJECT_RUINmobilew2 ) name = "ruin1.mod"; + if ( type == OBJECT_RUINmobilet1 ) name = "ruin2.mod"; + if ( type == OBJECT_RUINmobilet2 ) name = "ruin2.mod"; + if ( type == OBJECT_RUINmobiler1 ) name = "ruin3.mod"; + if ( type == OBJECT_RUINmobiler2 ) name = "ruin3.mod"; + if ( type == OBJECT_RUINfactory ) name = "ruin4.mod"; + if ( type == OBJECT_RUINdoor ) name = "ruin5.mod"; + if ( type == OBJECT_RUINsupport ) name = "ruin6.mod"; + if ( type == OBJECT_RUINradar ) name = "ruin7.mod"; + if ( type == OBJECT_RUINconvert ) name = "ruin8.mod"; + if ( type == OBJECT_RUINbase ) name = "ruin9.mod"; + if ( type == OBJECT_RUINhead ) name = "ruin10.mod"; + + modelManager->AddModelReference(name, false, rank); SetPosition(0, pos); SetAngleY(0, angle); @@ -5083,8 +4913,7 @@ bool CObject::CreateRuin(Math::Vector pos, float angle, float height, SetObjectRank(6, rank); SetObjectParent(6, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ruin1w.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ruin1w.mod", false, rank); SetPosition(6, Math::Vector(-3.0f, 1.8f, -4.0f)); SetAngleX(6, -Math::PI/2.0f); @@ -5095,8 +4924,7 @@ bool CObject::CreateRuin(Math::Vector pos, float angle, float height, SetObjectRank(7, rank); SetObjectParent(7, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ruin1w.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ruin1w.mod", false, rank); SetPosition(7, Math::Vector(-3.0f, 1.0f, 3.0f)); SetAngleY(7, Math::PI-0.3f); @@ -5108,8 +4936,7 @@ bool CObject::CreateRuin(Math::Vector pos, float angle, float height, SetObjectRank(8, rank); SetObjectParent(8, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ruin1w.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ruin1w.mod", false, rank); SetPosition(8, Math::Vector(2.0f, 1.6f, -3.0f)); SetAngleY(8, 0.3f); @@ -5120,8 +4947,7 @@ bool CObject::CreateRuin(Math::Vector pos, float angle, float height, SetObjectRank(9, rank); SetObjectParent(9, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ruin1w.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ruin1w.mod", false, rank); SetPosition(9, Math::Vector(2.0f, 1.0f, 3.0f)); SetAngleY(9, Math::PI-0.2f); @@ -5141,8 +4967,7 @@ bool CObject::CreateRuin(Math::Vector pos, float angle, float height, SetObjectRank(7, rank); SetObjectParent(7, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ruin1w.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ruin1w.mod", false, rank); SetPosition(7, Math::Vector(-3.0f, 1.0f, 3.0f)); SetAngleY(7, Math::PI+0.3f); @@ -5154,8 +4979,7 @@ bool CObject::CreateRuin(Math::Vector pos, float angle, float height, SetObjectRank(9, rank); SetObjectParent(9, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ruin1w.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ruin1w.mod", false, rank); SetPosition(9, Math::Vector(2.0f, 1.0f, 3.0f)); SetAngleY(9, Math::PI+0.3f); @@ -5175,8 +4999,7 @@ bool CObject::CreateRuin(Math::Vector pos, float angle, float height, SetObjectRank(1, rank); SetObjectParent(1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ruin2c.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("ruin2c.mod", false, rank); SetPosition(1, Math::Vector(3.0f, 5.0f, -2.5f)); SetAngleX(1, -Math::PI*0.85f); @@ -5458,7 +5281,6 @@ bool CObject::CreateRuin(Math::Vector pos, float angle, float height, SetAngleX(0, angle); } - delete pModFile; return true; } @@ -5466,10 +5288,9 @@ bool CObject::CreateRuin(Math::Vector pos, float angle, float height, bool CObject::CreateApollo(Math::Vector pos, float angle, ObjectType type) { - Gfx::CModelFile* pModFile; int rank, i; - pModFile = new Gfx::CModelFile(m_iMan); + Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer(); SetType(type); @@ -5478,8 +5299,7 @@ bool CObject::CreateApollo(Math::Vector pos, float angle, ObjectType type) rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); // it is a stationary object SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apollol1.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("apollol1.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetZoom(0, 1.2f); @@ -5491,8 +5311,7 @@ bool CObject::CreateApollo(Math::Vector pos, float angle, ObjectType type) m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(i+1, rank); SetObjectParent(i+1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apollol2.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("apollol2.mod", false, rank); SetAngleY(i+1, Math::PI/2.0f*i); } @@ -5500,8 +5319,7 @@ bool CObject::CreateApollo(Math::Vector pos, float angle, ObjectType type) m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(5, rank); SetObjectParent(5, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apollol3.mod")); // ladder - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("apollol3.mod", false, rank); // ladder //? m_terrain->AddBuildingLevel(pos, 10.0f, 13.0f, 12.0f, 0.0f); @@ -5521,8 +5339,7 @@ bool CObject::CreateApollo(Math::Vector pos, float angle, ObjectType type) rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); //it is a stationary object SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj1.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("apolloj1.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetFloorHeight(0.0f); @@ -5532,32 +5349,28 @@ bool CObject::CreateApollo(Math::Vector pos, float angle, ObjectType type) m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(1, rank); SetObjectParent(1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj4.mod")); // wheel - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("apolloj4.mod", false, rank); // wheel SetPosition(1, Math::Vector(-5.75f, 1.65f, -5.0f)); rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(2, rank); SetObjectParent(2, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj4.mod")); // wheel - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("apolloj4.mod", false, rank); // wheel SetPosition(2, Math::Vector(-5.75f, 1.65f, 5.0f)); rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(3, rank); SetObjectParent(3, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj4.mod")); // wheel - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("apolloj4.mod", false, rank); // wheel SetPosition(3, Math::Vector(5.75f, 1.65f, -5.0f)); rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(4, rank); SetObjectParent(4, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj4.mod")); // wheel - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("apolloj4.mod", false, rank); // wheel SetPosition(4, Math::Vector(5.75f, 1.65f, 5.0f)); // Accessories: @@ -5565,8 +5378,7 @@ bool CObject::CreateApollo(Math::Vector pos, float angle, ObjectType type) m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(5, rank); SetObjectParent(5, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj2.mod")); // antenna - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("apolloj2.mod", false, rank); // antenna SetPosition(5, Math::Vector(5.5f, 8.8f, 2.0f)); SetAngleY(5, -120.0f*Math::PI/180.0f); SetAngleZ(5, 45.0f*Math::PI/180.0f); @@ -5575,8 +5387,7 @@ bool CObject::CreateApollo(Math::Vector pos, float angle, ObjectType type) m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(6, rank); SetObjectParent(6, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj3.mod")); // camera - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("apolloj3.mod", false, rank); // camera SetPosition(6, Math::Vector(5.5f, 2.8f, -2.0f)); SetAngleY(6, 30.0f*Math::PI/180.0f); @@ -5594,8 +5405,7 @@ bool CObject::CreateApollo(Math::Vector pos, float angle, ObjectType type) rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); // it is a stationary object SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apollof.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("apollof.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetFloorHeight(0.0f); @@ -5609,8 +5419,7 @@ bool CObject::CreateApollo(Math::Vector pos, float angle, ObjectType type) rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); // it is a stationary object SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apollom.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("apollom.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetFloorHeight(0.0f); @@ -5626,8 +5435,7 @@ bool CObject::CreateApollo(Math::Vector pos, float angle, ObjectType type) rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); // it is a stationary object SetObjectRank(0, rank); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloa.mod")); - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("apolloa.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetFloorHeight(0.0f); @@ -5636,8 +5444,7 @@ bool CObject::CreateApollo(Math::Vector pos, float angle, ObjectType type) m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); SetObjectRank(1, rank); SetObjectParent(1, 0); - pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj2.mod")); // antenna - pModFile->CreateEngineObject(rank); + modelManager->AddModelReference("apolloj2.mod", false, rank); // antenna SetPosition(1, Math::Vector(0.0f, 5.0f, 0.0f)); SetAngleY(1, -120.0f*Math::PI/180.0f); SetAngleZ(1, 45.0f*Math::PI/180.0f); @@ -5651,7 +5458,6 @@ bool CObject::CreateApollo(Math::Vector pos, float angle, ObjectType type) pos = GetPosition(0); SetPosition(0, pos); // to display the shadows immediately - delete pModFile; return true; } diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 1da4587..5705649 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -1010,7 +1010,7 @@ void CRobotMain::ChangePhase(Phase phase) ChangePause(false); FlushDisplayInfo(); m_engine->SetRankView(0); - m_engine->FlushObject(); + m_engine->DeleteAllObjects(); m_engine->SetWaterAddColor(Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f)); m_engine->SetBackground(""); m_engine->SetBackForce(false); @@ -3673,7 +3673,7 @@ void CRobotMain::Convert() void CRobotMain::ScenePerso() { DeleteAllObjects(); // removes all the current 3D Scene - m_engine->FlushObject(); + m_engine->DeleteAllObjects(); m_terrain->FlushRelief(); // all flat m_terrain->FlushBuildingLevel(); m_terrain->FlushFlyingLimit(); diff --git a/src/script/script.cpp b/src/script/script.cpp index 8471df5..a6b39b9 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -2669,9 +2669,9 @@ CScript::CScript(CInstanceManager* iMan, CObject* object, CTaskManager** seconda m_main = static_cast(m_iMan->SearchInstance(CLASS_MAIN)); m_terrain = static_cast(m_iMan->SearchInstance(CLASS_TERRAIN)); m_water = static_cast(m_iMan->SearchInstance(CLASS_WATER)); - m_botProg = 0; + m_botProg = nullptr; m_object = object; - m_primaryTask = 0; + m_primaryTask = nullptr; m_secondaryTask = secondaryTask; m_interface = static_cast(m_iMan->SearchInstance(CLASS_INTERFACE)); @@ -2680,7 +2680,7 @@ CScript::CScript(CInstanceManager* iMan, CObject* object, CTaskManager** seconda m_ipf = CBOT_IPF; m_errMode = ERM_STOP; m_len = 0; - m_script = 0; + m_script = nullptr; m_bRun = false; m_bStepMode = false; m_bCompile = false; @@ -2752,10 +2752,22 @@ void CScript::InitFonctions() CScript::~CScript() { - delete m_botProg; - delete m_primaryTask; - delete m_script; - m_script = 0; + if (m_botProg != nullptr) + { + delete m_botProg; + m_botProg = nullptr; + } + if (m_primaryTask != nullptr) + { + delete m_primaryTask; + m_primaryTask = nullptr; + } + if (m_script != nullptr) + { + delete m_script; + m_script = nullptr; + } + m_len = 0; m_iMan->DeleteInstance(CLASS_SCRIPT, this); diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt index f6c6112..3653357 100644 --- a/src/tools/CMakeLists.txt +++ b/src/tools/CMakeLists.txt @@ -1,5 +1,4 @@ set(CONVERT_MODEL_SOURCES -../common/iman.cpp ../common/logger.cpp ../common/stringutils.cpp ../graphics/engine/modelfile.cpp diff --git a/src/tools/convert_model.cpp b/src/tools/convert_model.cpp index a33d7d0..3eecfb1 100644 --- a/src/tools/convert_model.cpp +++ b/src/tools/convert_model.cpp @@ -1,4 +1,3 @@ -#include "common/iman.h" #include "common/logger.h" #include "graphics/engine/modelfile.h" @@ -8,11 +7,10 @@ bool EndsWith(std::string const &fullString, std::string const &ending) { - if (fullString.length() >= ending.length()) { + if (fullString.length() >= ending.length()) return (0 == fullString.compare (fullString.length() - ending.length(), ending.length(), ending)); - } else { + else return false; - } } @@ -20,7 +18,6 @@ struct Args { bool usage; bool dumpInfo; - bool mirror; std::string inputFile; std::string outputFile; std::string inputFormat; @@ -30,7 +27,6 @@ struct Args { usage = false; dumpInfo = false; - mirror = false; } }; @@ -43,8 +39,7 @@ void PrintUsage(const std::string& program) std::cerr << "Usage:" << std::endl; std::cerr << std::endl; std::cerr << " Convert files:" << std::endl; - std::cerr << " " << program << " -i input_file -if input_format -o output_file -of output_format [-m]" << std::endl; - std::cerr << " -m => mirror" << std::endl; + std::cerr << " " << program << " -i input_file -if input_format -o output_file -of output_format" << std::endl; std::cerr << std::endl; std::cerr << " Dump info:" << std::endl; std::cerr << " " << program << " -d -i input_file -if input_format" << std::endl; @@ -117,10 +112,6 @@ bool ParseArgs(int argc, char *argv[]) { ARGS.dumpInfo = true; } - else if (arg == "-m") - { - ARGS.mirror = true; - } else { return false; @@ -165,8 +156,7 @@ int main(int argc, char *argv[]) if (ARGS.usage) return 0; - CInstanceManager iMan; - Gfx::CModelFile model(&iMan); + Gfx::CModelFile model; bool ok = true; @@ -255,9 +245,6 @@ int main(int argc, char *argv[]) return 0; } - if (ARGS.mirror) - model.Mirror(); - if (ARGS.outputFormat == "old") { ok = model.WriteModel(ARGS.outputFile); -- cgit v1.2.3-1-g7c22 From 277629f9fec069afce32a21fd6baeb4f24d5784c Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Tue, 18 Dec 2012 09:11:44 +0100 Subject: Minor cmake grammar fix It is redundant to have CMAKE_INSTALL_PREFIX in path definitions; drop them. Re-do a7d837460f5eeba060900031322d088ba330964c --- CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a80e7d3..fe88d87 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -183,11 +183,11 @@ if(${TESTS}) endif() # Installation paths defined before compiling sources -set(COLOBOT_INSTALL_BIN_DIR ${CMAKE_INSTALL_PREFIX}/games CACHE PATH "Colobot binary directory") -set(COLOBOT_INSTALL_DATA_DIR ${CMAKE_INSTALL_PREFIX}/share/games/colobot CACHE PATH "Colobot shared data directory") -set(COLOBOT_INSTALL_LIB_DIR ${CMAKE_INSTALL_PREFIX}/lib/colobot CACHE PATH "Colobot libraries directory") -set(COLOBOT_INSTALL_DOC_DIR ${CMAKE_INSTALL_PREFIX}/share/doc/colobot CACHE PATH "Colobot documentation directory") -set(COLOBOT_INSTALL_I18N_DIR ${CMAKE_INSTALL_PREFIX}/share/locale CACHE PATH "Colobot translations directory") +set(COLOBOT_INSTALL_BIN_DIR games CACHE PATH "Colobot binary directory") +set(COLOBOT_INSTALL_DATA_DIR share/games/colobot CACHE PATH "Colobot shared data directory") +set(COLOBOT_INSTALL_LIB_DIR lib/colobot CACHE PATH "Colobot libraries directory") +set(COLOBOT_INSTALL_DOC_DIR share/doc/colobot CACHE PATH "Colobot documentation directory") +set(COLOBOT_INSTALL_I18N_DIR share/locale CACHE PATH "Colobot translations directory") # Subdirectory with sources add_subdirectory(src bin) -- cgit v1.2.3-1-g7c22 From afea08d57049b58361059cd0a11b92c942ff5458 Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Thu, 27 Dec 2012 13:13:16 +0100 Subject: Always build manpages solves #105 --- src/desktop/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/desktop/CMakeLists.txt b/src/desktop/CMakeLists.txt index 1e5058f..1a1cfd5 100644 --- a/src/desktop/CMakeLists.txt +++ b/src/desktop/CMakeLists.txt @@ -57,7 +57,7 @@ if(POD2MAN) ${CMAKE_CURRENT_BINARY_DIR}${SLASHLOCALE}/colobot.${COLOBOT_MANPAGE_SECTION} COMMENT "Create ${SLASHLOCALE}/colobot.${COLOBOT_MANPAGE_SECTION} manpage" ) - add_custom_target(man${PM_LOCALE} DEPENDS ${CMAKE_CURRENT_BINARY_DIR}${SLASHLOCALE}/colobot.${COLOBOT_MANPAGE_SECTION}) + add_custom_target(man${PM_LOCALE} ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}${SLASHLOCALE}/colobot.${COLOBOT_MANPAGE_SECTION}) install( FILES ${CMAKE_CURRENT_BINARY_DIR}${SLASHLOCALE}/colobot.${COLOBOT_MANPAGE_SECTION} -- cgit v1.2.3-1-g7c22 From 877774a22601e7feb36013d25e6aaf8fe81b15bc Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Thu, 27 Dec 2012 13:52:47 +0100 Subject: Update translation pot-file and build-target --- src/po/CMakeLists.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/po/CMakeLists.txt b/src/po/CMakeLists.txt index 3b26571..df667dd 100644 --- a/src/po/CMakeLists.txt +++ b/src/po/CMakeLists.txt @@ -6,14 +6,13 @@ find_program(XGETTEXT_CMD xgettext) add_custom_command(OUTPUT ${_potFile} COMMAND ${XGETTEXT_CMD} ../app/app.cpp --output=${_potFile} - COMMAND ${XGETTEXT_CMD} ../common/restext_strings.c --output=${_potFile} --join-existing --extract-all --no-location + COMMAND ${XGETTEXT_CMD} ../common/restext.cpp --output=${_potFile} --join-existing --extract-all --no-location WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMENT "Extract translatable messages to ${_potFile}" ) -add_custom_target(_${potFile} ${_all} DEPENDS ${_potFile}) +add_custom_target(update-pot DEPENDS ${_potFile}) file(GLOB _poFiles *.po) - gettext_create_translations(${_potFile} ALL ${_poFiles}) -- cgit v1.2.3-1-g7c22 From 7a5e41e1ec67fc5b6eadf81679366a2bbad0b7a7 Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Thu, 27 Dec 2012 13:54:40 +0100 Subject: Update colobot.pot using update-pot --- src/po/colobot.pot | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 91 insertions(+), 6 deletions(-) diff --git a/src/po/colobot.pot b/src/po/colobot.pot index d0a9c12..a45303e 100644 --- a/src/po/colobot.pot +++ b/src/po/colobot.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2012-12-13 21:46+0100\n" +"POT-Creation-Date: 2012-12-27 13:53+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -1436,7 +1436,7 @@ msgstr "" msgid "Program infected by a virus" msgstr "" -msgid "Infected by a virus, temporarily out of order" +msgid "Infected by a virus; temporarily out of order" msgstr "" msgid "Impossible when swimming" @@ -1464,7 +1464,7 @@ msgstr "" msgid "Building destroyed" msgstr "" -msgid "Can not create this, there are too many objects" +msgid "Can not create this; there are too many objects" msgstr "" #, c-format @@ -1528,10 +1528,10 @@ msgstr "" msgid "Found a site for a derrick" msgstr "" -msgid "<<< Well done, mission accomplished >>>" +msgid "<<< Well done; mission accomplished >>>" msgstr "" -msgid "<<< Sorry, mission failed >>>" +msgid "<<< Sorry; mission failed >>>" msgstr "" msgid "Current mission saved" @@ -1612,7 +1612,7 @@ msgstr "" msgid "Instruction \"break\" outside a loop" msgstr "" -msgid "A label must be followed by \"for\", \"while\", \"do\" or \"switch\"" +msgid "A label must be followed by \"for\"; \"while\"; \"do\" or \"switch\"" msgstr "" msgid "This label does not exist" @@ -1734,3 +1734,88 @@ msgstr "" msgid "Write error" msgstr "" + +msgid "left;" +msgstr "" + +msgid "right;" +msgstr "" + +msgid "up;" +msgstr "" + +msgid "down;" +msgstr "" + +msgid "gup;" +msgstr "" + +msgid "gdown;" +msgstr "" + +msgid "camera;" +msgstr "" + +msgid "desel;" +msgstr "" + +msgid "action;" +msgstr "" + +msgid "near;" +msgstr "" + +msgid "away;" +msgstr "" + +msgid "next;" +msgstr "" + +msgid "human;" +msgstr "" + +msgid "quit;" +msgstr "" + +msgid "help;" +msgstr "" + +msgid "prog;" +msgstr "" + +msgid "cbot;" +msgstr "" + +msgid "visit;" +msgstr "" + +msgid "speed10;" +msgstr "" + +msgid "speed15;" +msgstr "" + +msgid "speed20;" +msgstr "" + +#, c-format +msgid "GetResource event num out of range: %d\n" +msgstr "" + +msgid "Ctrl" +msgstr "" + +msgid "Shift" +msgstr "" + +msgid "Alt" +msgstr "" + +msgid "Win" +msgstr "" + +msgid "Button %1" +msgstr "" + +msgid "%1" +msgstr "" -- cgit v1.2.3-1-g7c22 From 85283a76be0c84e70a5d99a857851782548d0d1e Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Thu, 27 Dec 2012 14:09:19 +0100 Subject: Update translations In particular, update french --- src/po/de.po | 114 ++++++++++++++++++++---- src/po/fr.po | 276 ++++++++++++++++++++++++++++++++++++++--------------------- src/po/pl.po | 114 ++++++++++++++++++++---- 3 files changed, 369 insertions(+), 135 deletions(-) diff --git a/src/po/de.po b/src/po/de.po index bbd0b77..6edcedd 100644 --- a/src/po/de.po +++ b/src/po/de.po @@ -1,7 +1,7 @@ msgid "" msgstr "" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2012-12-13 21:46+0100\n" +"POT-Creation-Date: 2012-12-27 13:53+0100\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -64,6 +64,9 @@ msgstr "Es fehlt eine geschlossene eckige Klammer \" ] \"" msgid "\"%s\" missing in this exercise" msgstr "Es fehlt \"%s\" in Ihrem Programm" +msgid "%1" +msgstr "" + msgid "..behind" msgstr "..hinten" @@ -85,13 +88,16 @@ msgstr "3D-Geräusche\\Orten der Geräusche im Raum" msgid "<< Back \\Back to the previous screen" msgstr "<< Zurück \\Zurück zum Hauptmenü" -msgid "<<< Sorry, mission failed >>>" +#, fuzzy +msgid "<<< Sorry; mission failed >>>" msgstr "<<< Mission gescheitert >>>" -msgid "<<< Well done, mission accomplished >>>" +#, fuzzy +msgid "<<< Well done; mission accomplished >>>" msgstr "<<< Bravo, Mission vollendet >>>" -msgid "A label must be followed by \"for\", \"while\", \"do\" or \"switch\"" +#, fuzzy +msgid "A label must be followed by \"for\"; \"while\"; \"do\" or \"switch\"" msgstr "" "Ein Label kann nur vor den Anweisungen \"for\", \"while\", \"do\" oder " "\"switch\" vorkommen" @@ -122,6 +128,9 @@ msgstr "Insektenkönigin tödlich verwundet" msgid "Already carrying something" msgstr "Trägt schon etwas" +msgid "Alt" +msgstr "Alt" + msgid "Analysis already performed" msgstr "Analyse schon durchgeführt" @@ -299,6 +308,9 @@ msgstr "Gebäude zerstört" msgid "Building too close" msgstr "Gebäude zu nahe" +msgid "Button %1" +msgstr "Knopf %1" + msgid "COLOBOT" msgstr "COLOBOT" @@ -326,7 +338,8 @@ msgstr "Kamera links" msgid "Camera to right" msgstr "Kamera rechts" -msgid "Can not create this, there are too many objects" +#, fuzzy +msgid "Can not create this; there are too many objects" msgstr "Kein neues Objekt kann erstellt werden (zu viele vorhanden)" msgid "Can't open file" @@ -404,6 +417,9 @@ msgstr "Kopieren" msgid "Copy (Ctrl+c)" msgstr "Kopieren (Ctrl+c)" +msgid "Ctrl" +msgstr "Ctrl" + msgid "Current mission saved" msgstr "Mission gespeichert" @@ -610,6 +626,10 @@ msgstr "Spiel\\Gameplay Einstellungen" msgid "Gantry crane" msgstr "Träger" +#, c-format +msgid "GetResource event num out of range: %d\n" +msgstr "" + msgid "Goto: destination occupied" msgstr "Ziel ist schon besetzt" @@ -682,7 +702,8 @@ msgstr "Falscher Batterietyp" msgid "Incorrect index type" msgstr "Falscher Typ für einen Index" -msgid "Infected by a virus, temporarily out of order" +#, fuzzy +msgid "Infected by a virus; temporarily out of order" msgstr "Von Virus infiziert, zeitweise außer Betrieb" msgid "Information exchange post" @@ -1256,6 +1277,9 @@ msgstr "Reichweite Schutzschild" msgid "Shielder" msgstr "Schutzschild" +msgid "Shift" +msgstr "Shift" + msgid "Shoot (\\key action;)" msgstr "Feuer (\\key action;)" @@ -1565,6 +1589,9 @@ msgstr "Shooter" msgid "Wheeled sniffer" msgstr "Schnüffler" +msgid "Win" +msgstr "" + msgid "Winged grabber" msgstr "Transporter" @@ -1730,6 +1757,69 @@ msgstr "\\b;Liste der Roboter\n" msgid "\\c; (none)\\n;\n" msgstr "\\c; (keine)\\n;\n" +msgid "action;" +msgstr "" + +msgid "away;" +msgstr "" + +msgid "camera;" +msgstr "" + +msgid "cbot;" +msgstr "" + +msgid "desel;" +msgstr "" + +msgid "down;" +msgstr "" + +msgid "gdown;" +msgstr "" + +msgid "gup;" +msgstr "" + +msgid "help;" +msgstr "" + +msgid "human;" +msgstr "" + +msgid "left;" +msgstr "" + +msgid "near;" +msgstr "" + +msgid "next;" +msgstr "" + +msgid "prog;" +msgstr "" + +msgid "quit;" +msgstr "" + +msgid "right;" +msgstr "" + +msgid "speed10;" +msgstr "" + +msgid "speed15;" +msgstr "" + +msgid "speed20;" +msgstr "" + +msgid "up;" +msgstr "" + +msgid "visit;" +msgstr "" + msgid "www.epsitec.com" msgstr "www.epsitec.com" @@ -1739,9 +1829,6 @@ msgstr "www.epsitec.com" #~ msgid "<--" #~ msgstr "<--" -#~ msgid "Alt" -#~ msgstr "Alt" - #~ msgid "Application key" #~ msgstr "Application key" @@ -1760,9 +1847,6 @@ msgstr "www.epsitec.com" #~ msgid "Attn" #~ msgstr "Attn" -#~ msgid "Button %1" -#~ msgstr "Knopf %1" - #~ msgid "Caps Lock" #~ msgstr "Caps Lock" @@ -1775,9 +1859,6 @@ msgstr "www.epsitec.com" #~ msgid "CrSel" #~ msgstr "CrSel" -#~ msgid "Ctrl" -#~ msgstr "Ctrl" - #~ msgid "Delete Key" #~ msgstr "Delete" @@ -1961,9 +2042,6 @@ msgstr "www.epsitec.com" #~ msgid "Select" #~ msgstr "Select" -#~ msgid "Shift" -#~ msgstr "Shift" - #~ msgid "Space" #~ msgstr "Leertaste" diff --git a/src/po/fr.po b/src/po/fr.po index bda683d..973dc19 100644 --- a/src/po/fr.po +++ b/src/po/fr.po @@ -1,13 +1,18 @@ +# Didier Raboud , 2012. msgid "" msgstr "" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2012-12-13 21:46+0100\n" +"POT-Creation-Date: 2012-12-27 13:53+0100\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" "X-Language: fr_FR\n" "X-Source-Language: en_US\n" +"Last-Translator: Didier Raboud \n" +"PO-Revision-Date: 2012-12-27 14:07+0100\n" +"Language: fr\n" +"X-Generator: Lokalize 1.4\n" msgid " " msgstr " " @@ -37,7 +42,7 @@ msgid " Missions on this planet:" msgstr " Liste des missions du chapitre :" msgid " Planets:" -msgstr " Liste des planÄtes :" +msgstr " Liste des planètes :" msgid " Prototypes on this planet:" msgstr " Liste des prototypes du chapitre :" @@ -64,8 +69,11 @@ msgstr "\" ] \" attendu" msgid "\"%s\" missing in this exercise" msgstr "Il manque \"%s\" dans le programme" +msgid "%1" +msgstr "%1" + msgid "..behind" -msgstr "..derriÄre" +msgstr "..derrière" msgid "..in front" msgstr "..devant" @@ -74,7 +82,7 @@ msgid "..power cell" msgstr "..pile" msgid "1) First click on the key you want to redefine." -msgstr "1) Cliquez d'abord sur la touche Å• redéfinir." +msgstr "1) Cliquez d'abord sur la touche à redéfinir." msgid "2) Then press the key you want to use instead." msgstr "2) Appuyez ensuite sur la nouvelle touche souhaitée." @@ -85,15 +93,15 @@ msgstr "Bruitages 3D\\Positionnement sonore dans l'espace" msgid "<< Back \\Back to the previous screen" msgstr "<< Retour \\Retour au niveau précédent" -msgid "<<< Sorry, mission failed >>>" -msgstr "<<< Désolé, mission échouée >>>" +msgid "<<< Sorry; mission failed >>>" +msgstr "<<< Désolé; mission échouée >>>" -msgid "<<< Well done, mission accomplished >>>" -msgstr "<<< Bravo, mission terminée >>>" +msgid "<<< Well done; mission accomplished >>>" +msgstr "<<< Bravo; mission terminée >>>" -msgid "A label must be followed by \"for\", \"while\", \"do\" or \"switch\"" +msgid "A label must be followed by \"for\"; \"while\"; \"do\" or \"switch\"" msgstr "" -"Un label ne peut se placer que devant un \"for\", un \"while\", un \"do\" ou " +"Un label ne peut se placer que devant un \"for\"; un \"while\"; un \"do\" ou " "un \"switch\"" msgid "A variable can not be declared twice" @@ -103,14 +111,14 @@ msgid "Abort\\Abort the current mission" msgstr "Abandonner\\Abandonner la mission en cours" msgid "Access beyond array limit" -msgstr "AccÄs hors du tableau" +msgstr "Accès hors du tableau" msgid "" "Access to solution\\Shows the solution (detailed instructions for missions)" -msgstr "AccÄs Å• la solution\\Donne la solution" +msgstr "Accès à la solution\\Donne la solution" msgid "Access to solutions\\Show program \"4: Solution\" in the exercises" -msgstr "AccÄs aux solutions\\Programme \"4: Solution\" dans les exercices" +msgstr "Accès aux solutions\\Programme \"4: Solution\" dans les exercices" msgid "Alien Queen" msgstr "Pondeuse" @@ -119,16 +127,19 @@ msgid "Alien Queen killed" msgstr "Pondeuse mortellement touchée" msgid "Already carrying something" -msgstr "Porte déjÅ• quelque chose" +msgstr "Porte déjà quelque chose" + +msgid "Alt" +msgstr "Alt" msgid "Analysis already performed" -msgstr "Analyse déjÅ• effectuée" +msgstr "Analyse déjà effectuée" msgid "Analysis performed" msgstr "Analyse terminée" msgid "Analyzes only organic matter" -msgstr "N'analyse que la matiÄre organique" +msgstr "N'analyse que la matière organique" msgid "Ant" msgstr "Fourmi" @@ -149,7 +160,7 @@ msgid "Assignment impossible" msgstr "Assignation impossible" msgid "Autolab" -msgstr "Laboratoire de matiÄres organiques" +msgstr "Laboratoire de matières organiques" msgid "Automatic indent\\When program editing" msgstr "Indentation automatique\\Pendant l'édition d'un programme" @@ -164,7 +175,7 @@ msgid "Backward (\\key down;)" msgstr "Recule (\\key down;)" msgid "Backward\\Moves backward" -msgstr "Reculer\\Moteur en arriÄre" +msgstr "Reculer\\Moteur en arrière" msgid "Bad argument for \"new\"" msgstr "Mauvais argument pour \"new\"" @@ -203,16 +214,16 @@ msgid "Build a exchange post" msgstr "Construit une borne d'information" msgid "Build a legged grabber" -msgstr "Fabrique un déménageur Å• pattes" +msgstr "Fabrique un déménageur à pattes" msgid "Build a legged orga shooter" -msgstr "Fabrique un orgaShooter Å• pattes" +msgstr "Fabrique un orgaShooter à pattes" msgid "Build a legged shooter" -msgstr "Fabrique un shooter Å• pattes" +msgstr "Fabrique un shooter à pattes" msgid "Build a legged sniffer" -msgstr "Fabrique un renifleur Å• pattes" +msgstr "Fabrique un renifleur à pattes" msgid "Build a lightning conductor" msgstr "Construit un paratonnerre" @@ -251,28 +262,28 @@ msgid "Build a thumper" msgstr "Fabrique un robot secoueur" msgid "Build a tracked grabber" -msgstr "Fabrique un déménageur Å• chenilles" +msgstr "Fabrique un déménageur à chenilles" msgid "Build a tracked orga shooter" -msgstr "Fabrique un orgaShooter Å• chenilles" +msgstr "Fabrique un orgaShooter à chenilles" msgid "Build a tracked shooter" -msgstr "Fabrique un shooter Å• chenilles" +msgstr "Fabrique un shooter à chenilles" msgid "Build a tracked sniffer" -msgstr "Fabrique un renifleur Å• chenilles" +msgstr "Fabrique un renifleur à chenilles" msgid "Build a wheeled grabber" -msgstr "Fabrique un déménageur Å• roues" +msgstr "Fabrique un déménageur à roues" msgid "Build a wheeled orga shooter" -msgstr "Fabrique un orgaShooter Å• roues" +msgstr "Fabrique un orgaShooter à roues" msgid "Build a wheeled shooter" -msgstr "Fabrique un shooter Å• roues" +msgstr "Fabrique un shooter à roues" msgid "Build a wheeled sniffer" -msgstr "Fabrique un renifleur Å• roues" +msgstr "Fabrique un renifleur à roues" msgid "Build a winged grabber" msgstr "Fabrique un déménageur volant" @@ -298,6 +309,9 @@ msgstr "Bâtiment détruit" msgid "Building too close" msgstr "Bâtiment trop proche" +msgid "Button %1" +msgstr "Bouton %1" + msgid "COLOBOT" msgstr "COLOBOT" @@ -320,13 +334,13 @@ msgid "Camera nearest" msgstr "Caméra plus proche" msgid "Camera to left" -msgstr "Caméra Å• gauche" +msgstr "Caméra à gauche" msgid "Camera to right" -msgstr "Caméra Å• droite" +msgstr "Caméra à droite" -msgid "Can not create this, there are too many objects" -msgstr "Création impossible, il y a trop d'objets" +msgid "Can not create this; there are too many objects" +msgstr "Création impossible; il y a trop d'objets" msgid "Can't open file" msgstr "Ouverture du fichier impossible" @@ -362,7 +376,7 @@ msgid "Close" msgstr "Fermer" msgid "Closing bracket missing " -msgstr "Il manque une parenthÄse fermante" +msgstr "Il manque une parenthèse fermante" msgid "Colobot Gold" msgstr "Colobot Gold" @@ -403,6 +417,9 @@ msgstr "Copier" msgid "Copy (Ctrl+c)" msgstr "Copier (Ctrl+c)" +msgid "Ctrl" +msgstr "Ctrl" + msgid "Current mission saved" msgstr "Enregistrement effectué" @@ -477,10 +494,10 @@ msgid "Dust\\Dust and dirt on bots and buildings" msgstr "Salissures\\Salissures des robots et bâtiments" msgid "Dynamic lighting\\Mobile light sources" -msgstr "LumiÄres dynamiques\\Eclairages mobiles" +msgstr "Lumières dynamiques\\Éclairages mobiles" msgid "Edit the selected program" -msgstr "Edite le programme sélectionné" +msgstr "Édite le programme sélectionné" msgid "Egg" msgstr "Oeuf" @@ -531,7 +548,7 @@ msgid "Filename:" msgstr "Nom du fichier :" msgid "Film sequences\\Films before and after the missions" -msgstr "Séquences cinématiques\\Films avant ou aprÄs une mission" +msgstr "Séquences cinématiques\\Films avant ou après une mission" msgid "Finish" msgstr "But" @@ -553,7 +570,7 @@ msgid "Folder: %s" msgstr "Dossier: %s" msgid "Font size" -msgstr "Taille des caractÄres" +msgstr "Taille des caractères" msgid "Forward" msgstr "Page suivante" @@ -589,13 +606,13 @@ msgid "Free game\\Free game without a specific goal" msgstr "Jeu libre\\Jeu libre sans but précis" msgid "Friendly fire\\Your shooting can damage your own objects " -msgstr "Dégâts Å• soi-mÄ™me\\Vos tirs infligent des dommages Å• vos unités" +msgstr "Dégâts à soi-même\\Vos tirs infligent des dommages à vos unités" msgid "Full screen\\Full screen or window mode" -msgstr "Plein écran\\Plein écran ou fenÄ™tré" +msgstr "Plein écran\\Plein écran ou fenêtré" msgid "Function already exists" -msgstr "Cette fonction existe déjÅ•" +msgstr "Cette fonction existe déjà" msgid "Function name missing" msgstr "Nom de la fonction attendu" @@ -609,8 +626,12 @@ msgstr "Jeu\\Options de jouabilité" msgid "Gantry crane" msgstr "Portique" +#, c-format +msgid "GetResource event num out of range: %d\n" +msgstr "" + msgid "Goto: destination occupied" -msgstr "Destination occupée" +msgstr "Goto: Destination occupée" msgid "Goto: inaccessible destination" msgstr "Chemin introuvable" @@ -637,7 +658,7 @@ msgid "Hair color:" msgstr "Couleur des cheveux :" msgid "Head\\Face and hair" -msgstr "TÄ™te\\Visage et cheveux" +msgstr "Tête\\Visage et cheveux" msgid "Help about selected object" msgstr "Instructions sur la sélection" @@ -681,8 +702,8 @@ msgstr "Pas le bon type de pile" msgid "Incorrect index type" msgstr "Mauvais type d'index" -msgid "Infected by a virus, temporarily out of order" -msgstr "Infecté par un virus, ne fonctionne plus temporairement" +msgid "Infected by a virus; temporarily out of order" +msgstr "Infecté par un virus; ne fonctionne plus temporairement" msgid "Information exchange post" msgstr "Borne d'information" @@ -703,7 +724,7 @@ msgid "Instructions (\\key help;)" msgstr "Instructions (\\key help;)" msgid "Instructions after the final closing brace" -msgstr "Instructions aprÄs la fin" +msgstr "Instructions après la fin" msgid "Instructions for the mission (\\key help;)" msgstr "Instructions sur la mission (\\key help;)" @@ -712,7 +733,7 @@ msgid "Instructions from Houston" msgstr "Instructions de Houston" msgid "Instructions\\Shows the instructions for the current mission" -msgstr "Instructions mission\\Marche Å• suivre" +msgstr "Instructions mission\\Marche à suivre" msgid "Jet temperature" msgstr "Température du réacteur" @@ -843,16 +864,16 @@ msgid "No energy in the subsoil" msgstr "Pas d'énergie en sous-sol" msgid "No flag nearby" -msgstr "Aucun drapeau Å• proximité" +msgstr "Aucun drapeau à proximité" msgid "No function running" msgstr "Pas de fonction en exécution" msgid "No function with this name accepts this kind of parameter" -msgstr "Aucune fonction de ce nom n'accepte ce(s) type(s) de paramÄtre(s)" +msgstr "Aucune fonction de ce nom n'accepte ce(s) type(s) de paramètre(s)" msgid "No function with this name accepts this number of parameters" -msgstr "Aucune fonction de ce nom n'accepte ce nombre de paramÄtres" +msgstr "Aucune fonction de ce nom n'accepte ce nombre de paramètres" msgid "No information exchange post within range" msgstr "Pas trouvé de borne d'information" @@ -876,13 +897,13 @@ msgid "No titanium around" msgstr "Titanium inexistant" msgid "No titanium ore to convert" -msgstr "Pas de minerai de titanium Å• convertir" +msgstr "Pas de minerai de titanium à convertir" msgid "No titanium to transform" -msgstr "Pas de titanium Å• transformer" +msgstr "Pas de titanium à transformer" msgid "No uranium to transform" -msgstr "Pas d'uranium Å• transformer" +msgstr "Pas d'uranium à transformer" msgid "Normal size" msgstr "Taille normale" @@ -903,16 +924,16 @@ msgid "Not yet enough energy" msgstr "Pas encore assez d'énergie" msgid "Nothing to analyze" -msgstr "Rien Å• analyser" +msgstr "Rien à analyser" msgid "Nothing to drop" -msgstr "Rien Å• déposer" +msgstr "Rien à déposer" msgid "Nothing to grab" -msgstr "Rien Å• prendre" +msgstr "Rien à prendre" msgid "Nothing to recycle" -msgstr "Rien Å• recycler" +msgstr "Rien à recycler" msgid "Nuclear power cell" msgstr "Pile nucléaire" @@ -933,7 +954,7 @@ msgid "Number of insects detected" msgstr "Nombre d'insectes détectés" msgid "Number of particles\\Explosions, dust, reflections, etc." -msgstr "Quantité de particules\\Explosions, poussiÄres, reflets, etc." +msgstr "Quantité de particules\\Explosions, poussières, reflets, etc." msgid "OK" msgstr "D'accord" @@ -963,7 +984,7 @@ msgid "Opening brace missing " msgstr "Début d'un bloc attendu" msgid "Opening bracket missing" -msgstr "Il manque une parenthÄse ouvrante" +msgstr "Il manque une parenthèse ouvrante" msgid "Operation impossible with value \"nan\"" msgstr "Opération sur un \"nan\"" @@ -975,13 +996,13 @@ msgid "Options\\Preferences" msgstr "Options\\Réglages" msgid "Organic matter" -msgstr "MatiÄre organique" +msgstr "Matière organique" msgid "Origin of last message\\Shows where the last message was sent from" msgstr "Montrer le lieu d'un message\\Montrer le lieu du dernier message" msgid "Parameters missing " -msgstr "Pas assez de paramÄtres" +msgstr "Pas assez de paramètres" msgid "Particles in the interface\\Steam clouds and sparks in the interface" msgstr "Particules dans l'interface\\Pluie de particules" @@ -1002,7 +1023,7 @@ msgid "Place occupied" msgstr "Emplacement occupé" msgid "Planets and stars\\Astronomical objects in the sky" -msgstr "PlanÄtes et étoiles\\Motifs mobiles dans le ciel" +msgstr "Planètes et étoiles\\Motifs mobiles dans le ciel" msgid "Plans for defense tower available" msgstr "Construction d'une tour de défense possible" @@ -1023,7 +1044,7 @@ msgid "Plans for thumper available" msgstr "Fabrication d'un robot secoueur possible" msgid "Plans for tracked robots available " -msgstr "Fabrication d'un robot Å• chenilles possible" +msgstr "Fabrication d'un robot à chenilles possible" msgid "Plant a flag" msgstr "Pose un drapeau de couleur" @@ -1086,10 +1107,10 @@ msgid "Programming exercises" msgstr "Programmation" msgid "Programming help" -msgstr "Aide Å• la programmation" +msgstr "Aide à la programmation" msgid "Programming help (\\key prog;)" -msgstr "Aide Å• la programmation (\\key prog;)" +msgstr "Aide à la programmation (\\key prog;)" msgid "Programming help\\Gives more detailed help with programming" msgstr "Instructions programmation\\Explication sur la programmation" @@ -1107,7 +1128,7 @@ msgid "Public required" msgstr "Public requis" msgid "Public\\Common folder" -msgstr "Public\\Dossier commun Å• tous les joueurs" +msgstr "Public\\Dossier commun à tous les joueurs" msgid "Quake at explosions\\The screen shakes at explosions" msgstr "Secousses lors d'explosions\\L'écran vibre lors d'une explosion" @@ -1125,7 +1146,7 @@ msgid "Radar station" msgstr "Radar" msgid "Read error" -msgstr "Erreur Å• la lecture" +msgstr "Erreur à la lecture" msgid "Recorder" msgstr "Enregistreur" @@ -1149,7 +1170,7 @@ msgid "Remains of Apollo mission" msgstr "Vestige d'une mission Apollo" msgid "Remove a flag" -msgstr "EnlÄve un drapeau" +msgstr "Enlève un drapeau" msgid "Repair center" msgstr "Centre de réparation" @@ -1158,7 +1179,7 @@ msgid "Research center" msgstr "Centre de recherches" msgid "Research program already performed" -msgstr "Recherche déjÅ• effectuée" +msgstr "Recherche déjà effectuée" msgid "Research program completed" msgstr "Recherche terminée" @@ -1258,6 +1279,9 @@ msgstr "Rayon du bouclier" msgid "Shielder" msgstr "Robot bouclier" +msgid "Shift" +msgstr "Shift" + msgid "Shoot (\\key action;)" msgstr "Tir (\\key action;)" @@ -1350,7 +1374,7 @@ msgid "Still working ..." msgstr "Travail en cours ..." msgid "String missing" -msgstr "Une chaîne de caractÄre est attendue" +msgstr "Une chaîne de caractère est attendue" msgid "Strip color:" msgstr "Couleur des bandes :" @@ -1405,7 +1429,7 @@ msgid "The types of the two operands are incompatible " msgstr "Les deux opérandes ne sont pas de types compatibles" msgid "This class already exists" -msgstr "Cette classe existe déjÅ•" +msgstr "Cette classe existe déjà" msgid "This class does not exist" msgstr "Cette classe n'existe pas" @@ -1456,7 +1480,7 @@ msgid "Too many flags of this color (maximum 5)" msgstr "Trop de drapeaux de cette couleur (maximum 5)" msgid "Too many parameters" -msgstr "Trop de paramÄtres" +msgstr "Trop de paramètres" msgid "Tracked grabber" msgstr "Robot déménageur" @@ -1480,16 +1504,16 @@ msgid "Transmitted information" msgstr "Informations diffusées" msgid "Turn left (\\key left;)" -msgstr "Tourne Å• gauche (\\key left;)" +msgstr "Tourne à gauche (\\key left;)" msgid "Turn left\\turns the bot to the left" -msgstr "Tourner Å• gauche\\Moteur Å• gauche" +msgstr "Tourner à gauche\\Moteur à gauche" msgid "Turn right (\\key right;)" -msgstr "Tourne Å• droite (\\key right;)" +msgstr "Tourne à droite (\\key right;)" msgid "Turn right\\turns the bot to the right" -msgstr "Tourner Å• droite\\Moteur Å• droite" +msgstr "Tourner à droite\\Moteur à droite" msgid "Type declaration missing" msgstr "Déclaration de type attendu" @@ -1543,7 +1567,7 @@ msgid "Violet flag" msgstr "Drapeau violet" msgid "Void parameter" -msgstr "ParamÄtre void" +msgstr "Paramètre void" msgid "Wasp" msgstr "GuÄ™pe" @@ -1566,6 +1590,9 @@ msgstr "Robot shooter" msgid "Wheeled sniffer" msgstr "Robot renifleur" +msgid "Win" +msgstr "Gagné" + msgid "Winged grabber" msgstr "Robot déménageur" @@ -1591,7 +1618,7 @@ msgid "Wreckage" msgstr "Epave de robot" msgid "Write error" -msgstr "Erreur Å• l'écriture" +msgstr "Erreur à l'écriture" msgid "Wrong type for the assignment" msgstr "Mauvais type de résultat pour l'assignation" @@ -1652,13 +1679,13 @@ msgid "\\Green flags" msgstr "\\Drapeaux verts" msgid "\\New player name" -msgstr "\\Nom du joueur Å• créer" +msgstr "\\Nom du joueur à créer" msgid "\\No eyeglasses" msgstr "\\Pas de lunettes" msgid "\\Raise the pencil" -msgstr "\\RelÄve le crayon" +msgstr "\\Relève le crayon" msgid "\\Red flags" msgstr "\\Drapeaux rouges" @@ -1676,10 +1703,10 @@ msgid "\\Stop recording" msgstr "\\Stoppe l'enregistrement" msgid "\\Turn left" -msgstr "\\Rotation Å• gauche" +msgstr "\\Rotation à gauche" msgid "\\Turn right" -msgstr "\\Rotation Å• droite" +msgstr "\\Rotation à droite" msgid "\\Use the black pencil" msgstr "\\Abaisse le crayon noir" @@ -1732,6 +1759,69 @@ msgstr "\\b;Listes des robots\n" msgid "\\c; (none)\\n;\n" msgstr "\\c; (aucun)\\n;\n" +msgid "action;" +msgstr "" + +msgid "away;" +msgstr "" + +msgid "camera;" +msgstr "" + +msgid "cbot;" +msgstr "" + +msgid "desel;" +msgstr "" + +msgid "down;" +msgstr "" + +msgid "gdown;" +msgstr "" + +msgid "gup;" +msgstr "" + +msgid "help;" +msgstr "" + +msgid "human;" +msgstr "" + +msgid "left;" +msgstr "" + +msgid "near;" +msgstr "" + +msgid "next;" +msgstr "" + +msgid "prog;" +msgstr "" + +msgid "quit;" +msgstr "" + +msgid "right;" +msgstr "" + +msgid "speed10;" +msgstr "" + +msgid "speed15;" +msgstr "" + +msgid "speed20;" +msgstr "" + +msgid "up;" +msgstr "" + +msgid "visit;" +msgstr "" + msgid "www.epsitec.com" msgstr "www.epsitec.com" @@ -1741,30 +1831,24 @@ msgstr "www.epsitec.com" #~ msgid "<--" #~ msgstr "<--" -#~ msgid "Alt" -#~ msgstr "Alt" - #~ msgid "Application key" #~ msgstr "Application key" #~ msgid "Arrow down" -#~ msgstr "FlÄche Bas" +#~ msgstr "Flèche Bas" #~ msgid "Arrow left" -#~ msgstr "FlÄche Gauche" +#~ msgstr "Flèche Gauche" #~ msgid "Arrow right" -#~ msgstr "FlÄche Droite" +#~ msgstr "Flèche Droite" #~ msgid "Arrow up" -#~ msgstr "FlÄche Haut" +#~ msgstr "Flèche Haut" #~ msgid "Attn" #~ msgstr "Attn" -#~ msgid "Button %1" -#~ msgstr "Bouton %1" - #~ msgid "Caps Lock" #~ msgstr "Caps Lock" @@ -1777,9 +1861,6 @@ msgstr "www.epsitec.com" #~ msgid "CrSel" #~ msgstr "CrSel" -#~ msgid "Ctrl" -#~ msgstr "Ctrl" - #~ msgid "Delete Key" #~ msgstr "Delete" @@ -1963,9 +2044,6 @@ msgstr "www.epsitec.com" #~ msgid "Select" #~ msgstr "Select" -#~ msgid "Shift" -#~ msgstr "Shift" - #~ msgid "Space" #~ msgstr "Espace" diff --git a/src/po/pl.po b/src/po/pl.po index 700ee9e..27b05c4 100644 --- a/src/po/pl.po +++ b/src/po/pl.po @@ -1,7 +1,7 @@ msgid "" msgstr "" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2012-12-13 21:46+0100\n" +"POT-Creation-Date: 2012-12-27 13:53+0100\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -65,6 +65,9 @@ msgstr "Brak \" ] \"" msgid "\"%s\" missing in this exercise" msgstr "It misses \"%s\" in this exercise" +msgid "%1" +msgstr "" + msgid "..behind" msgstr "..za" @@ -86,13 +89,16 @@ msgstr "DźwiÄ™k 3D\\Przestrzenne pozycjonowanie dźwiÄ™ków" msgid "<< Back \\Back to the previous screen" msgstr "<< Wstecz \\Wraca do poprzedniego ekranu" -msgid "<<< Sorry, mission failed >>>" +#, fuzzy +msgid "<<< Sorry; mission failed >>>" msgstr "<<< Niestety, misja nie powiodÅ‚a siÄ™ >>>" -msgid "<<< Well done, mission accomplished >>>" +#, fuzzy +msgid "<<< Well done; mission accomplished >>>" msgstr "<<< Dobra robota, misja wypeÅ‚niona >>>" -msgid "A label must be followed by \"for\", \"while\", \"do\" or \"switch\"" +#, fuzzy +msgid "A label must be followed by \"for\"; \"while\"; \"do\" or \"switch\"" msgstr "Po etykiecie musi wystÄ…pić \"for\", \"while\", \"do\" lub \"switch\"" msgid "A variable can not be declared twice" @@ -122,6 +128,9 @@ msgstr "Królowa Obcych zostaÅ‚a zabita" msgid "Already carrying something" msgstr "Nie można nieść wiÄ™cej przedmiotów" +msgid "Alt" +msgstr "Alt" + msgid "Analysis already performed" msgstr "Analiza zostaÅ‚a już wykonana" @@ -301,6 +310,9 @@ msgstr "Budynek zniszczony" msgid "Building too close" msgstr "Budynek za blisko" +msgid "Button %1" +msgstr "Przycisk %1" + msgid "COLOBOT" msgstr "COLOBOT" @@ -328,7 +340,8 @@ msgstr "Camera to left" msgid "Camera to right" msgstr "Camera to right" -msgid "Can not create this, there are too many objects" +#, fuzzy +msgid "Can not create this; there are too many objects" msgstr "Nie można tego utworzyć, za dużo obiektów" msgid "Can't open file" @@ -406,6 +419,9 @@ msgstr "Kopiuj" msgid "Copy (Ctrl+c)" msgstr "Kopiuj (Ctrl+C)" +msgid "Ctrl" +msgstr "Ctrl" + msgid "Current mission saved" msgstr "Bieżąca misja zapisana" @@ -612,6 +628,10 @@ msgstr "Gra\\Ustawienia gry" msgid "Gantry crane" msgstr "Å»uraw przesuwalny" +#, c-format +msgid "GetResource event num out of range: %d\n" +msgstr "" + msgid "Goto: destination occupied" msgstr "Goto: miejsce docelowe zajÄ™te" @@ -685,7 +705,8 @@ msgstr "Nieodpowiedni rodzaj ogniw" msgid "Incorrect index type" msgstr "NieprawidÅ‚owy typ indeksu" -msgid "Infected by a virus, temporarily out of order" +#, fuzzy +msgid "Infected by a virus; temporarily out of order" msgstr "Zainfekowane wirusem, chwilowo niesprawne" msgid "Information exchange post" @@ -1264,6 +1285,9 @@ msgstr "ZasiÄ™g osÅ‚ony" msgid "Shielder" msgstr "OsÅ‚aniacz" +msgid "Shift" +msgstr "Shift" + msgid "Shoot (\\key action;)" msgstr "Strzelaj (\\key action;)" @@ -1575,6 +1599,9 @@ msgstr "DziaÅ‚o na koÅ‚ach" msgid "Wheeled sniffer" msgstr "Szperacz na koÅ‚ach" +msgid "Win" +msgstr "" + msgid "Winged grabber" msgstr "Transporter latajÄ…cy" @@ -1740,6 +1767,69 @@ msgstr "\\b;Roboty\n" msgid "\\c; (none)\\n;\n" msgstr "\\c; (brak)\\n;\n" +msgid "action;" +msgstr "" + +msgid "away;" +msgstr "" + +msgid "camera;" +msgstr "" + +msgid "cbot;" +msgstr "" + +msgid "desel;" +msgstr "" + +msgid "down;" +msgstr "" + +msgid "gdown;" +msgstr "" + +msgid "gup;" +msgstr "" + +msgid "help;" +msgstr "" + +msgid "human;" +msgstr "" + +msgid "left;" +msgstr "" + +msgid "near;" +msgstr "" + +msgid "next;" +msgstr "" + +msgid "prog;" +msgstr "" + +msgid "quit;" +msgstr "" + +msgid "right;" +msgstr "" + +msgid "speed10;" +msgstr "" + +msgid "speed15;" +msgstr "" + +msgid "speed20;" +msgstr "" + +msgid "up;" +msgstr "" + +msgid "visit;" +msgstr "" + msgid "www.epsitec.com" msgstr "www.epsitec.com" @@ -1749,9 +1839,6 @@ msgstr "www.epsitec.com" #~ msgid "<--" #~ msgstr "<--" -#~ msgid "Alt" -#~ msgstr "Alt" - #~ msgid "Application key" #~ msgstr "Klawisz menu kontekstowego" @@ -1770,9 +1857,6 @@ msgstr "www.epsitec.com" #~ msgid "Attn" #~ msgstr "Attn" -#~ msgid "Button %1" -#~ msgstr "Przycisk %1" - #~ msgid "Caps Lock" #~ msgstr "Caps Lock" @@ -1785,9 +1869,6 @@ msgstr "www.epsitec.com" #~ msgid "CrSel" #~ msgstr "CrSel" -#~ msgid "Ctrl" -#~ msgstr "Ctrl" - #~ msgid "Delete Key" #~ msgstr "Delete" @@ -1971,9 +2052,6 @@ msgstr "www.epsitec.com" #~ msgid "Select" #~ msgstr "Zaznacz" -#~ msgid "Shift" -#~ msgstr "Shift" - #~ msgid "Space" #~ msgstr "Spacja" -- cgit v1.2.3-1-g7c22 From 3582f107a5e77bc12fc61e4fd99c572a5985254b Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Thu, 27 Dec 2012 14:18:16 +0100 Subject: Fixes and refactoring --- src/graphics/engine/engine.cpp | 313 ++++++++++++--------------------------- src/graphics/engine/engine.h | 46 +++--- src/graphics/opengl/gldevice.cpp | 2 +- 3 files changed, 122 insertions(+), 239 deletions(-) diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 73cd73a..ea0c093 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -459,145 +459,82 @@ int CEngine::GetStatisticTriangle() Object management *******************************************************/ -EngineBaseObjTexTier& CEngine::AddLevel2(int baseObjRank, const std::string& tex1Name, const std::string& tex2Name) +EngineBaseObjTexTier& CEngine::AddLevel2(EngineBaseObject& p1, const std::string& tex1Name, const std::string& tex2Name) { - bool unusedPresent = false; - for (int i = 0; i < static_cast( m_baseObjects[baseObjRank].next.size() ); i++) + for (int i = 0; i < static_cast( p1.next.size() ); i++) { - if (! m_baseObjects[baseObjRank].next[i].used) - { - unusedPresent = true; - continue; - } - - if (m_baseObjects[baseObjRank].next[i].tex1Name == tex1Name && m_baseObjects[baseObjRank].next[i].tex2Name == tex2Name) - return m_baseObjects[baseObjRank].next[i]; - } - - if (unusedPresent) - { - for (int i = 0; i < static_cast( m_baseObjects[baseObjRank].next.size() ); i++) - { - if (! m_baseObjects[baseObjRank].next[i].used) - { - m_baseObjects[baseObjRank].next[i].used = true; - m_baseObjects[baseObjRank].next[i].tex1Name = tex1Name; - m_baseObjects[baseObjRank].next[i].tex2Name = tex2Name; - return m_baseObjects[baseObjRank].next[i]; - } - } + if (p1.next[i].tex1Name == tex1Name && p1.next[i].tex2Name == tex2Name) + return p1.next[i]; } - m_baseObjects[baseObjRank].next.push_back(EngineBaseObjTexTier(true, tex1Name, tex2Name)); - return m_baseObjects[baseObjRank].next.back(); + p1.next.push_back(EngineBaseObjTexTier(tex1Name, tex2Name)); + return p1.next.back(); } EngineBaseObjLODTier& CEngine::AddLevel3(EngineBaseObjTexTier& p2, float min, float max) { - bool unusedPresent = false; for (int i = 0; i < static_cast( p2.next.size() ); i++) { - if (! p2.next[i].used) - { - unusedPresent = true; - continue; - } - if ( (p2.next[i].min == min) && (p2.next[i].max == max) ) return p2.next[i]; } - if (unusedPresent) - { - for (int i = 0; i < static_cast( p2.next.size() ); i++) - { - if (! p2.next[i].used) - { - p2.next[i].used = true; - p2.next[i].min = min; - p2.next[i].max = max; - return p2.next[i]; - } - } - } - - p2.next.push_back(EngineBaseObjLODTier(true, min, max)); + p2.next.push_back(EngineBaseObjLODTier(min, max)); return p2.next.back(); } EngineBaseObjDataTier& CEngine::AddLevel4(EngineBaseObjLODTier& p3, EngineTriangleType type, const Material& material, int state) { - bool unusedPresent = false; for (int i = 0; i < static_cast( p3.next.size() ); i++) { - if (! p3.next[i].used) - { - unusedPresent = true; - continue; - } - if ( (p3.next[i].type == type) && (p3.next[i].material == material) && (p3.next[i].state == state) ) return p3.next[i]; } - if (unusedPresent) - { - for (int i = 0; i < static_cast( p3.next.size() ); i++) - { - if (! p3.next[i].used) - { - p3.next[i].used = true; - p3.next[i].type = type; - p3.next[i].material = material; - p3.next[i].state = state; - return p3.next[i]; - } - } - } - - p3.next.push_back(EngineBaseObjDataTier(true, type, material, state)); + p3.next.push_back(EngineBaseObjDataTier(type, material, state)); return p3.next.back(); } int CEngine::CreateBaseObject() { - int i = 0; - for ( ; i < static_cast( m_baseObjects.size() ); i++) + int baseObjRank = 0; + for ( ; baseObjRank < static_cast( m_baseObjects.size() ); baseObjRank++) { - if (! m_baseObjects[i].used) + if (! m_baseObjects[baseObjRank].used) { - m_baseObjects[i].LoadDefault(); + m_baseObjects[baseObjRank].LoadDefault(); break; } } - if (i == static_cast( m_baseObjects.size() )) + if (baseObjRank == static_cast( m_baseObjects.size() )) m_baseObjects.push_back(EngineBaseObject()); else - m_baseObjects[i].LoadDefault(); + m_baseObjects[baseObjRank].LoadDefault(); - m_baseObjects[i].used = true; + m_baseObjects[baseObjRank].used = true; - return i; + return baseObjRank; } void CEngine::DeleteBaseObject(int baseObjRank) { - assert(baseObjRank < -1 || baseObjRank >= static_cast( m_baseObjects.size() )); + assert(baseObjRank >= 0 && baseObjRank < static_cast( m_baseObjects.size() )); + + EngineBaseObject& p1 = m_baseObjects[baseObjRank]; + + if (! p1.used) + return; - for (int l2 = 0; l2 < static_cast( m_baseObjects[baseObjRank].next.size() ); l2++) + for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) { - EngineBaseObjTexTier& p2 = m_baseObjects[baseObjRank].next[l2]; - if (! p2.used) - continue; + EngineBaseObjTexTier& p2 = p1.next[l2]; for (int l3 = 0; l3 < static_cast( p2.next.size() ); l3++) { EngineBaseObjLODTier& p3 = p2.next[l3]; - if (! p3.used) - continue; for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) { @@ -607,10 +544,11 @@ void CEngine::DeleteBaseObject(int baseObjRank) p4.staticBufferId = 0; } } - - p2.used = false; - p2.next.clear(); } + + p1.next.clear(); + + p1.used = false; } void CEngine::DeleteAllBaseObjects() @@ -638,7 +576,8 @@ void CEngine::AddBaseObjTriangles(int baseObjRank, const std::vector m_lastObjectDetail = m_objectDetail; m_lastClippingDistance = m_clippingDistance; - EngineBaseObjTexTier& p2 = AddLevel2(baseObjRank, tex1Name, tex2Name); + EngineBaseObject& p1 = m_baseObjects[baseObjRank]; + EngineBaseObjTexTier& p2 = AddLevel2(p1, tex1Name, tex2Name); EngineBaseObjLODTier& p3 = AddLevel3(p2, min, max); EngineBaseObjDataTier& p4 = AddLevel4(p3, triangleType, material, state); @@ -655,22 +594,21 @@ void CEngine::AddBaseObjTriangles(int baseObjRank, const std::vector { for (int i = 0; i < static_cast( vertices.size() ); i++) { - m_baseObjects[baseObjRank].bboxMin.x = Math::Min(vertices[i].coord.x, m_baseObjects[baseObjRank].bboxMin.x); - m_baseObjects[baseObjRank].bboxMin.y = Math::Min(vertices[i].coord.y, m_baseObjects[baseObjRank].bboxMin.y); - m_baseObjects[baseObjRank].bboxMin.z = Math::Min(vertices[i].coord.z, m_baseObjects[baseObjRank].bboxMin.z); - m_baseObjects[baseObjRank].bboxMax.x = Math::Max(vertices[i].coord.x, m_baseObjects[baseObjRank].bboxMax.x); - m_baseObjects[baseObjRank].bboxMax.y = Math::Max(vertices[i].coord.y, m_baseObjects[baseObjRank].bboxMax.y); - m_baseObjects[baseObjRank].bboxMax.z = Math::Max(vertices[i].coord.z, m_baseObjects[baseObjRank].bboxMax.z); + p1.bboxMin.x = Math::Min(vertices[i].coord.x, p1.bboxMin.x); + p1.bboxMin.y = Math::Min(vertices[i].coord.y, p1.bboxMin.y); + p1.bboxMin.z = Math::Min(vertices[i].coord.z, p1.bboxMin.z); + p1.bboxMax.x = Math::Max(vertices[i].coord.x, p1.bboxMax.x); + p1.bboxMax.y = Math::Max(vertices[i].coord.y, p1.bboxMax.y); + p1.bboxMax.z = Math::Max(vertices[i].coord.z, p1.bboxMax.z); } - m_baseObjects[baseObjRank].radius = Math::Max(m_baseObjects[baseObjRank].bboxMin.Length(), - m_baseObjects[baseObjRank].bboxMax.Length()); + p1.radius = Math::Max(p1.bboxMin.Length(), p1.bboxMax.Length()); } if (triangleType == ENG_TRIANGLE_TYPE_TRIANGLES) - m_baseObjects[baseObjRank].totalTriangles += vertices.size() / 3; + p1.totalTriangles += vertices.size() / 3; else - m_baseObjects[baseObjRank].totalTriangles += vertices.size() - 2; + p1.totalTriangles += vertices.size() - 2; } void CEngine::AddBaseObjQuick(int baseObjRank, const EngineBaseObjDataTier& buffer, @@ -679,17 +617,15 @@ void CEngine::AddBaseObjQuick(int baseObjRank, const EngineBaseObjDataTier& buff { assert(baseObjRank >= 0 && baseObjRank < static_cast( m_baseObjects.size() )); - EngineBaseObjTexTier& p2 = AddLevel2(baseObjRank, tex1Name, tex2Name); + EngineBaseObject& p1 = m_baseObjects[baseObjRank]; + EngineBaseObjTexTier& p2 = AddLevel2(p1, tex1Name, tex2Name); EngineBaseObjLODTier& p3 = AddLevel3(p2, min, max); p3.next.push_back(buffer); EngineBaseObjDataTier& p4 = p3.next.back(); - p4.used = true; - - p4.updateStaticBuffer = true; - m_updateStaticBuffers = true; + UpdateStaticBuffer(p4); if (globalUpdate) { @@ -699,52 +635,51 @@ void CEngine::AddBaseObjQuick(int baseObjRank, const EngineBaseObjDataTier& buff { for (int i = 0; i < static_cast( p4.vertices.size() ); i++) { - m_baseObjects[baseObjRank].bboxMin.x = Math::Min(p4.vertices[i].coord.x, m_baseObjects[baseObjRank].bboxMin.x); - m_baseObjects[baseObjRank].bboxMin.y = Math::Min(p4.vertices[i].coord.y, m_baseObjects[baseObjRank].bboxMin.y); - m_baseObjects[baseObjRank].bboxMin.z = Math::Min(p4.vertices[i].coord.z, m_baseObjects[baseObjRank].bboxMin.z); - m_baseObjects[baseObjRank].bboxMax.x = Math::Max(p4.vertices[i].coord.x, m_baseObjects[baseObjRank].bboxMax.x); - m_baseObjects[baseObjRank].bboxMax.y = Math::Max(p4.vertices[i].coord.y, m_baseObjects[baseObjRank].bboxMax.y); - m_baseObjects[baseObjRank].bboxMax.z = Math::Max(p4.vertices[i].coord.z, m_baseObjects[baseObjRank].bboxMax.z); + p1.bboxMin.x = Math::Min(p4.vertices[i].coord.x, p1.bboxMin.x); + p1.bboxMin.y = Math::Min(p4.vertices[i].coord.y, p1.bboxMin.y); + p1.bboxMin.z = Math::Min(p4.vertices[i].coord.z, p1.bboxMin.z); + p1.bboxMax.x = Math::Max(p4.vertices[i].coord.x, p1.bboxMax.x); + p1.bboxMax.y = Math::Max(p4.vertices[i].coord.y, p1.bboxMax.y); + p1.bboxMax.z = Math::Max(p4.vertices[i].coord.z, p1.bboxMax.z); } - m_baseObjects[baseObjRank].radius = Math::Max(m_baseObjects[baseObjRank].bboxMin.Length(), - m_baseObjects[baseObjRank].bboxMax.Length()); + p1.radius = Math::Max(p1.bboxMin.Length(), p1.bboxMax.Length()); } if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES) - m_baseObjects[baseObjRank].totalTriangles += p4.vertices.size() / 3; + p1.totalTriangles += p4.vertices.size() / 3; else if (p4.type == ENG_TRIANGLE_TYPE_SURFACE) - m_baseObjects[baseObjRank].totalTriangles += p4.vertices.size() - 2; + p1.totalTriangles += p4.vertices.size() - 2; } int CEngine::CreateObject() { - int i = 0; - for ( ; i < static_cast( m_objects.size() ); i++) + int objRank = 0; + for ( ; objRank < static_cast( m_objects.size() ); objRank++) { - if (! m_objects[i].used) + if (! m_objects[objRank].used) { - m_objects[i].LoadDefault(); + m_objects[objRank].LoadDefault(); break; } } - if (i == static_cast( m_objects.size() )) + if (objRank == static_cast( m_objects.size() )) m_objects.push_back(EngineObject()); - m_objects[i].used = true; + m_objects[objRank].used = true; Math::Matrix mat; mat.LoadIdentity(); - SetObjectTransform(i, mat); + SetObjectTransform(objRank, mat); - m_objects[i].drawWorld = true; - m_objects[i].distance = 0.0f; - m_objects[i].shadowRank = -1; + m_objects[objRank].drawWorld = true; + m_objects[objRank].distance = 0.0f; + m_objects[objRank].shadowRank = -1; - return i; + return objRank; } void CEngine::DeleteAllObjects() @@ -861,11 +796,11 @@ EngineBaseObjDataTier* CEngine::FindTriangles(int objRank, const Material& mater int baseObjRank = m_objects[objRank].baseObjRank; assert(baseObjRank >= 0 && baseObjRank < static_cast( m_baseObjects.size() )); - for (int l2 = 0; l2 < static_cast( m_baseObjects[baseObjRank].next.size() ); l2++) + EngineBaseObject& p1 = m_baseObjects[baseObjRank]; + + for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) { - EngineBaseObjTexTier& p2 = m_baseObjects[baseObjRank].next[l2]; - if (! p2.used) - continue; + EngineBaseObjTexTier& p2 = p1.next[l2]; if (p2.tex1Name != tex1Name) continue; @@ -873,8 +808,6 @@ EngineBaseObjDataTier* CEngine::FindTriangles(int objRank, const Material& mater for (int l3 = 0; l3 < static_cast( p2.next.size() ); l3++) { EngineBaseObjLODTier& p3 = p2.next[l3]; - if (! p3.used) - continue; if (p3.min != min || p3.max != max) continue; @@ -882,8 +815,6 @@ EngineBaseObjDataTier* CEngine::FindTriangles(int objRank, const Material& mater for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) { EngineBaseObjDataTier& p4 = p3.next[l4]; - if (! p4.used) - continue; if ( (p4.state & (~(ENG_RSTATE_DUAL_BLACK|ENG_RSTATE_DUAL_WHITE))) != state || p4.material != material ) @@ -905,23 +836,21 @@ int CEngine::GetPartialTriangles(int objRank, float min, float max, float percen int baseObjRank = m_objects[objRank].baseObjRank; assert(baseObjRank >= 0 && baseObjRank < static_cast( m_baseObjects.size() )); - int total = m_baseObjects[baseObjRank].totalTriangles; + EngineBaseObject& p1 = m_baseObjects[baseObjRank]; + + int total = p1.totalTriangles; int expectedCount = static_cast(percent * total); triangles.reserve(Math::Min(maxCount, expectedCount)); int actualCount = 0; - for (int l2 = 0; l2 < static_cast( m_baseObjects[baseObjRank].next.size() ); l2++) + for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) { - EngineBaseObjTexTier& p2 = m_baseObjects[baseObjRank].next[l2]; - if (! p2.used) - continue; + EngineBaseObjTexTier& p2 = p1.next[l2]; for (int l3 = 0; l3 < static_cast( p2.next.size() ); l3++) { EngineBaseObjLODTier& p3 = p2.next[l3]; - if (! p3.used) - continue; if (p3.min != min || p3.max != max) continue; @@ -929,8 +858,6 @@ int CEngine::GetPartialTriangles(int objRank, float min, float max, float percen for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) { EngineBaseObjDataTier& p4 = p3.next[l4]; - if (! p4.used) - continue; if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES) { @@ -1006,20 +933,18 @@ void CEngine::ChangeLOD() for (int baseObjRank = 0; baseObjRank < static_cast( m_baseObjects.size() ); baseObjRank++) { - if (! m_baseObjects[baseObjRank].used) + EngineBaseObject& p1 = m_baseObjects[baseObjRank]; + + if (! p1.used) continue; - for (int l2 = 0; l2 < static_cast( m_baseObjects[baseObjRank].next.size() ); l2++) + for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) { - EngineBaseObjTexTier& p2 = m_baseObjects[baseObjRank].next[l2]; - if (! p2.used) - continue; + EngineBaseObjTexTier& p2 = p1.next[l2]; for (int l3 = 0; l3 < static_cast( p2.next.size() ); l3++) { EngineBaseObjLODTier& p3 = p2.next[l3]; - if (! p3.used) - continue; if ( Math::IsEqual(p3.min, 0.0f ) && Math::IsEqual(p3.max, oldLimit[0]) ) @@ -1057,21 +982,18 @@ void CEngine::ChangeSecondTexture(int objRank, const std::string& tex2Name) int baseObjRank = m_objects[objRank].baseObjRank; assert(baseObjRank >= 0 && baseObjRank < static_cast( m_baseObjects.size() )); - + EngineBaseObject& p1 = m_baseObjects[baseObjRank]; for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) { EngineBaseObjTexTier& p2 = p1.next[l2]; - if (! p2.used) - continue; if (p2.tex2Name == tex2Name) continue; // already new - EngineBaseObjTexTier& newP2 = AddLevel2(baseObjRank, p2.tex1Name, tex2Name); + EngineBaseObjTexTier& newP2 = AddLevel2(p1, p2.tex1Name, tex2Name); newP2.next.swap(p2.next); - p2.used = false; } } @@ -1143,7 +1065,7 @@ void CEngine::TrackTextureMapping(int objRank, const Material& mat, int state, float pos, float factor, float tl, float ts, float tt) { assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); - + EngineBaseObjDataTier* p4 = FindTriangles(objRank, mat, state, tex1Name, tex2Name, min, max); if (p4 == nullptr) return; @@ -1424,16 +1346,18 @@ bool CEngine::GetBBox2D(int objRank, Math::Point &min, Math::Point &max) int baseObjRank = m_objects[objRank].baseObjRank; assert(baseObjRank >= 0 && baseObjRank < static_cast( m_baseObjects.size() )); + EngineBaseObject& p1 = m_baseObjects[baseObjRank]; + for (int i = 0; i < 8; i++) { Math::Vector p; - if ( i & (1<<0) ) p.x = m_baseObjects[baseObjRank].bboxMin.x; - else p.x = m_baseObjects[baseObjRank].bboxMax.x; - if ( i & (1<<1) ) p.y = m_baseObjects[baseObjRank].bboxMin.y; - else p.y = m_baseObjects[baseObjRank].bboxMax.y; - if ( i & (1<<2) ) p.z = m_baseObjects[baseObjRank].bboxMin.z; - else p.z = m_baseObjects[baseObjRank].bboxMax.z; + if ( i & (1<<0) ) p.x = p1.bboxMin.x; + else p.x = p1.bboxMax.x; + if ( i & (1<<1) ) p.y = p1.bboxMin.y; + else p.y = p1.bboxMax.y; + if ( i & (1<<2) ) p.z = p1.bboxMin.z; + else p.z = p1.bboxMax.z; Math::Vector pp; if (TransformPoint(pp, objRank, p)) @@ -1598,20 +1522,14 @@ void CEngine::UpdateGeometry() for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) { EngineBaseObjTexTier& p2 = p1.next[l2]; - if (! p2.used) - continue; for (int l3 = 0; l3 < static_cast( p2.next.size() ); l3++) { EngineBaseObjLODTier& p3 = p2.next[l3]; - if (! p3.used) - continue; for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) { EngineBaseObjDataTier& p4 = p3.next[l4]; - if (! p4.used) - continue; for (int i = 0; i < static_cast( p4.vertices.size() ); i++) { @@ -1664,20 +1582,14 @@ void CEngine::UpdateStaticBuffers() for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) { EngineBaseObjTexTier& p2 = p1.next[l2]; - if (! p2.used) - continue; for (int l3 = 0; l3 < static_cast( p2.next.size() ); l3++) { EngineBaseObjLODTier& p3 = p2.next[l3]; - if (! p3.used) - continue; for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) { EngineBaseObjDataTier& p4 = p3.next[l4]; - if (! p4.used) - continue; if (! p4.updateStaticBuffer) continue; @@ -1703,6 +1615,8 @@ bool CEngine::DetectBBox(int objRank, Math::Point mouse) int baseObjRank = m_objects[objRank].baseObjRank; assert(baseObjRank >= 0 && baseObjRank < static_cast(m_baseObjects.size())); + EngineBaseObject& p1 = m_baseObjects[baseObjRank]; + Math::Point min, max; min.x = 1000000.0f; min.y = 1000000.0f; @@ -1713,12 +1627,12 @@ bool CEngine::DetectBBox(int objRank, Math::Point mouse) { Math::Vector p; - if ( i & (1<<0) ) p.x = m_baseObjects[baseObjRank].bboxMin.x; - else p.x = m_baseObjects[baseObjRank].bboxMax.x; - if ( i & (1<<1) ) p.y = m_baseObjects[baseObjRank].bboxMin.y; - else p.y = m_baseObjects[baseObjRank].bboxMax.y; - if ( i & (1<<2) ) p.z = m_baseObjects[baseObjRank].bboxMin.z; - else p.z = m_baseObjects[baseObjRank].bboxMax.z; + if ( i & (1<<0) ) p.x = p1.bboxMin.x; + else p.x = p1.bboxMax.x; + if ( i & (1<<1) ) p.y = p1.bboxMin.y; + else p.y = p1.bboxMax.y; + if ( i & (1<<2) ) p.z = p1.bboxMin.z; + else p.z = p1.bboxMax.z; Math::Vector pp; if ( TransformPoint(pp, objRank, p) ) @@ -1762,14 +1676,10 @@ int CEngine::DetectObject(Math::Point mouse) for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) { EngineBaseObjTexTier& p2 = p1.next[l2]; - if (! p2.used) - continue; for (int l3 = 0; l3 < static_cast( p2.next.size() ); l3++) { EngineBaseObjLODTier& p3 = p2.next[l3]; - if (! p3.used) - continue; if (p3.min != 0.0f) continue; // LOD B or C? @@ -1777,8 +1687,6 @@ int CEngine::DetectObject(Math::Point mouse) for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) { EngineBaseObjDataTier& p4 = p3.next[l4]; - if (! p4.used) - continue; if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES) { @@ -2273,8 +2181,6 @@ bool CEngine::LoadAllTextures() for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) { EngineBaseObjTexTier& p2 = p1.next[l2]; - if (! p2.used) - continue; if (! p2.tex1Name.empty()) { @@ -3083,7 +2989,7 @@ void CEngine::Draw3DScene() int baseObjRank = m_objects[objRank].baseObjRank; assert(baseObjRank >= 0 && baseObjRank < static_cast( m_baseObjects.size() )); - + EngineBaseObject& p1 = m_baseObjects[baseObjRank]; if (! p1.used) continue; @@ -3091,18 +2997,13 @@ void CEngine::Draw3DScene() for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) { EngineBaseObjTexTier& p2 = p1.next[l2]; - if (! p2.used) - continue; - // Should be loaded by now SetTexture(p2.tex1, 0); SetTexture(p2.tex2, 1); for (int l3 = 0; l3 < static_cast( p2.next.size() ); l3++) { EngineBaseObjLODTier& p3 = p2.next[l3]; - if (! p3.used) - continue; if ( m_objects[objRank].distance < p3.min || m_objects[objRank].distance >= p3.max ) @@ -3111,8 +3012,6 @@ void CEngine::Draw3DScene() for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) { EngineBaseObjDataTier& p4 = p3.next[l4]; - if (! p4.used) - continue; SetMaterial(p4.material); SetState(p4.state); @@ -3163,18 +3062,13 @@ void CEngine::Draw3DScene() for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) { EngineBaseObjTexTier& p2 = p1.next[l2]; - if (! p2.used) - continue; - // Should be loaded by now SetTexture(p2.tex1, 0); SetTexture(p2.tex2, 1); for (int l3 = 0; l3 < static_cast( p2.next.size() ); l3++) { EngineBaseObjLODTier& p3 = p2.next[l3]; - if (! p3.used) - continue; if ( m_objects[objRank].distance < p3.min || m_objects[objRank].distance >= p3.max ) @@ -3183,8 +3077,6 @@ void CEngine::Draw3DScene() for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) { EngineBaseObjDataTier& p4 = p3.next[l4]; - if (! p4.used) - continue; if (m_objects[objRank].transparency != 0.0f) // transparent ? { @@ -3236,18 +3128,13 @@ void CEngine::Draw3DScene() for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) { EngineBaseObjTexTier& p2 = p1.next[l2]; - if (! p2.used) - continue; - // Should be loaded by now SetTexture(p2.tex1, 0); SetTexture(p2.tex2, 1); for (int l3 = 0; l3 < static_cast( p2.next.size() ); l3++) { EngineBaseObjLODTier& p3 = p2.next[l3]; - if (! p3.used) - continue; if (m_objects[objRank].distance < p3.min || m_objects[objRank].distance >= p3.max) @@ -3256,8 +3143,6 @@ void CEngine::Draw3DScene() for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) { EngineBaseObjDataTier& p4 = p3.next[l4]; - if (! p4.used) - continue; if (m_objects[objRank].transparency == 0.0f) continue; @@ -3393,8 +3278,6 @@ void CEngine::DrawInterface() for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) { EngineBaseObjTexTier& p2 = p1.next[l2]; - if (! p2.used) - continue; SetTexture(p2.tex1, 0); SetTexture(p2.tex2, 1); @@ -3402,8 +3285,6 @@ void CEngine::DrawInterface() for (int l3 = 0; l3 < static_cast( p2.next.size() ); l3++) { EngineBaseObjLODTier& p3 = p2.next[l3]; - if (! p3.used) - continue; if (m_objects[objRank].distance < p3.min || m_objects[objRank].distance >= p3.max) @@ -3412,8 +3293,6 @@ void CEngine::DrawInterface() for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) { EngineBaseObjDataTier& p4 = p3.next[l4]; - if (! p4.used) - continue; SetMaterial(p4.material); SetState(p4.state); diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index ad934a6..899abc0 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -185,7 +185,6 @@ enum EngineObjectType */ struct EngineBaseObjDataTier { - bool used; EngineTriangleType type; Material material; int state; @@ -193,11 +192,10 @@ struct EngineBaseObjDataTier unsigned int staticBufferId; bool updateStaticBuffer; - inline EngineBaseObjDataTier(bool used = false, - EngineTriangleType type = ENG_TRIANGLE_TYPE_TRIANGLES, + inline EngineBaseObjDataTier(EngineTriangleType type = ENG_TRIANGLE_TYPE_TRIANGLES, const Material& material = Material(), int state = ENG_RSTATE_NORMAL) - : used(used), type(type), material(material), state(state), staticBufferId(0), updateStaticBuffer(false) {} + : type(type), material(material), state(state), staticBufferId(0), updateStaticBuffer(false) {} }; /** @@ -206,13 +204,12 @@ struct EngineBaseObjDataTier */ struct EngineBaseObjLODTier { - bool used; float min; float max; std::vector next; - inline EngineBaseObjLODTier(bool used = false, float min = 0.0f, float max = 0.0f) - : used(used), min(min), max(max) {} + inline EngineBaseObjLODTier(float min = 0.0f, float max = 0.0f) + : min(min), max(max) {} }; /** @@ -221,16 +218,14 @@ struct EngineBaseObjLODTier */ struct EngineBaseObjTexTier { - bool used; std::string tex1Name; Texture tex1; std::string tex2Name; Texture tex2; std::vector next; - inline EngineBaseObjTexTier(bool used = false, const std::string& tex1Name = "", - const std::string& tex2Name = "") - : used(used), tex1Name(tex1Name), tex2Name(tex2Name) {} + inline EngineBaseObjTexTier(const std::string& tex1Name = "", const std::string& tex2Name = "") + : tex1Name(tex1Name), tex2Name(tex2Name) {} }; /** @@ -624,27 +619,36 @@ struct EngineMouse * * Objects are uniquely identified by object rank obtained at object creation. Creating an * object equals to allocating space for EngineObject structure which holds object parameters. - * Object's geometric data is stored in a separate structure - a 4-tier tree which splits - * the information of each geometric triangle. + * + * Object's geometric data is stored as a separate object -- base engine object. Each object + * must reference a valid base engine object. This many-to-one association allows to share + * same geometric data (e.g. from same model) across objects. Base engine objects are identified + * by unique rank obtained upon their creation. + * + * Base engine object data is stored in a 4-tier tree which splits the data describing triangles. * * The 4 tiers contain the following information: - * - level 1 (EngineObjLevel1) - two textures (names and structs) applied to triangles, - * - level 2 (EngineObjLevel2) - object rank - * - level 3 (EngineObjLevel3) - minumum and maximum LOD (=level of detail) - * - level 4 (EngineObjLevel4) - type of object*, material, render state and the actual triangle data + * - level 1 (EngineBaseObject) - geometric statistics + * - level 2 (EngineBaseObjTexTier) - two textures (names and structs) applied to triangles, + * - level 3 (EngineBaseObjLODTier) - minumum and maximum LOD (=level of detail) + * - level 4 (EngineBaseObjDataTier) - type of object*, material, render state and the actual vertex data * - * NOTE: type of object in this context means only the internal type in 3D engine. It is not related + * *NOTE: type of object in this context means only the internal type in 3D engine. It is not related * to CObject types. * + * Last tier containing vertex data contains also an ID of static buffer holding the data. + * The static buffer is created and updated with new data as needed. + * * Such tiered structure complicates loops over all object data, but saves a lot of memory and - * optimizes the rendering process (for instance, switching of textures is an expensive operation). + * optimizes the rendering process. * * \section Shadows Shadows * * Each engine object can be associated with a shadow (EngineShadow). Like objects, shadows are * identified by their rank obtained upon creation. * - * ... + * Shadows are drawn as circular spots on the ground, except for shadows for worms, which have + * special mode for them. * * \section RenderStates Render States * @@ -1213,7 +1217,7 @@ protected: void DrawStats(); //! Creates a new tier 2 object (texture) - EngineBaseObjTexTier& AddLevel2(int baseObjRank, const std::string& tex1Name, const std::string& tex2Name); + EngineBaseObjTexTier& AddLevel2(EngineBaseObject& p1, const std::string& tex1Name, const std::string& tex2Name); //! Creates a new tier 3 object (LOD) EngineBaseObjLODTier& AddLevel3(EngineBaseObjTexTier &p2, float min, float max); //! Creates a new tier 4 object (data) diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index c1e18d3..024a523 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -1151,7 +1151,7 @@ void CGLDevice::DrawStaticBuffer(unsigned int bufferId) glEnableClientState(GL_NORMAL_ARRAY); glNormalPointer(GL_FLOAT, sizeof(Vertex), static_cast(nullptr) + offsetof(Vertex, normal)); - glActiveTexture(GL_TEXTURE0); + glClientActiveTexture(GL_TEXTURE0); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), static_cast(nullptr) + offsetof(Vertex, texCoord)); } -- cgit v1.2.3-1-g7c22 From 0d825ed613ae62b0ed22a7e7f9ea1f001e3f8ea3 Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Thu, 27 Dec 2012 16:13:26 +0100 Subject: Fix locale's loading - Always inherit LC_ALL from environment; - Enforce environment only if the runtime options require it; --- src/app/app.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index 118e100..27adcb1 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -312,11 +312,14 @@ bool CApplication::Create() break; } - std::string langStr = "LANGUAGE="; - langStr += locale; - strcpy(S_LANGUAGE, langStr.c_str()); - putenv(S_LANGUAGE); - setlocale(LC_ALL, locale.c_str()); + if (!locale.empty()) + { + std::string langStr = "LANG="; + langStr += locale; + strcpy(S_LANGUAGE, langStr.c_str()); + putenv(S_LANGUAGE); + } + setlocale(LC_ALL, ""); GetLogger()->Debug("Set locale to '%s'\n", locale.c_str()); bindtextdomain("colobot", COLOBOT_I18N_DIR); -- cgit v1.2.3-1-g7c22 From 45bee618f91ae13f48e082b5b44c8c796564d2b5 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Thu, 27 Dec 2012 16:32:46 +0100 Subject: Fixed unicode rendering bug --- src/graphics/engine/text.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index 66c73a9..101e01a 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -677,7 +677,7 @@ void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::P return; int width = 1; - if (ch.c1 < 32) { // FIXME add support for chars with code 9 10 23 + if (ch.c1 > 0 && ch.c1 < 32) { // FIXME add support for chars with code 9 10 23 ch.c1 = ' '; ch.c2 = 0; ch.c3 = 0; -- cgit v1.2.3-1-g7c22 From e62996858b2ce2be322eae55f86b4b0ad7172a08 Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Thu, 27 Dec 2012 17:10:45 +0100 Subject: Create a central version Make it 0.1.0~pre-alpha for now. - Add it to runtime program - Add it to -help option - Add it to manpage - Update translations --- CMakeLists.txt | 26 ++++++++++++++++++++++++++ src/app/app.cpp | 2 +- src/common/config.h.cmake | 4 ++++ src/common/restext.cpp | 4 +++- src/desktop/CMakeLists.txt | 1 + src/po/colobot.pot | 5 +---- src/po/de.po | 5 +---- src/po/fr.po | 11 ++++------- src/po/pl.po | 5 +---- 9 files changed, 42 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fe88d87..a3bd7f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,32 @@ cmake_minimum_required(VERSION 2.8) project(colobot C CXX) +## +# Project version +## +set(COLOBOT_VERSION_CODENAME "Gold") +set(COLOBOT_VERSION_MAJOR 0) +set(COLOBOT_VERSION_MINOR 1) +set(COLOBOT_VERSION_REVISION 0) + +# Comment out when releasing +set(COLOBOT_VERSION_UNRELEASED "~pre-alpha") + +# Append git characteristics to version +if(DEFINED COLOBOT_VERSION_UNRELEASED AND EXISTS "${CMAKE_SOURCE_DIR}/.git") + find_package(Git) + execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD + OUTPUT_VARIABLE GIT_BRANCH + OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD + OUTPUT_VARIABLE GIT_REVISION + OUTPUT_STRIP_TRAILING_WHITESPACE) + set(COLOBOT_VERSION_UNRELEASED "${COLOBOT_VERSION_UNRELEASED}-git-${GIT_BRANCH}~r${GIT_REVISION}") +endif() + +set(COLOBOT_VERSION_FULL "${COLOBOT_VERSION_MAJOR}.${COLOBOT_VERSION_MINOR}.${COLOBOT_VERSION_REVISION}${COLOBOT_VERSION_UNRELEASED}") +message(STATUS "Building Colobot \"${COLOBOT_VERSION_CODENAME}\" (${COLOBOT_VERSION_FULL})") + # Include cmake directory with some additional scripts set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${colobot_SOURCE_DIR}/cmake") diff --git a/src/app/app.cpp b/src/app/app.cpp index 27adcb1..000cfdf 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -246,7 +246,7 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) else if (arg == "-help") { GetLogger()->Message("\n"); - GetLogger()->Message("COLOBOT GOLD pre-alpha\n"); + GetLogger()->Message("Colobot %s (%s)\n",COLOBOT_CODENAME,COLOBOT_VERSION); GetLogger()->Message("\n"); GetLogger()->Message("List of available options:\n"); GetLogger()->Message(" -help this help\n"); diff --git a/src/common/config.h.cmake b/src/common/config.h.cmake index dd280a3..022bb69 100644 --- a/src/common/config.h.cmake +++ b/src/common/config.h.cmake @@ -8,6 +8,10 @@ #cmakedefine USE_GLEW @USE_GLEW@ #cmakedefine GLEW_STATIC +#define COLOBOT_VERSION "@COLOBOT_VERSION_FULL@" +#define COLOBOT_CODENAME "@COLOBOT_VERSION_CODENAME@" +#define COLOBOT_FULLNAME "Colobot @COLOBOT_VERSION_CODENAME@" + #define COLOBOT_DEFAULT_DATADIR "@COLOBOT_INSTALL_DATA_DIR@" #define COLOBOT_I18N_DIR "@COLOBOT_INSTALL_I18N_DIR@" diff --git a/src/common/restext.cpp b/src/common/restext.cpp index da06131..4c56ae5 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -17,6 +17,8 @@ #include "common/restext.h" +#include "common/config.h" + #include "common/global.h" #include "common/event.h" #include "common/logger.h" @@ -39,7 +41,7 @@ const char* stringsCbot[TX_MAX] = { nullptr }; void InitializeRestext() { - stringsText[RT_VERSION_ID] = "Colobot Gold"; + stringsText[RT_VERSION_ID] = COLOBOT_FULLNAME; stringsText[RT_DISINFO_TITLE] = "SatCom"; stringsText[RT_WINDOW_MAXIMIZED] = "Maximize"; diff --git a/src/desktop/CMakeLists.txt b/src/desktop/CMakeLists.txt index 1a1cfd5..ce4f48d 100644 --- a/src/desktop/CMakeLists.txt +++ b/src/desktop/CMakeLists.txt @@ -53,6 +53,7 @@ if(POD2MAN) DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${PM_PODFILE} COMMAND ${POD2MAN} ARGS --section=${COLOBOT_MANPAGE_SECTION} --center="Colobot" --stderr --utf8 + --release="${COLOBOT_VERSION_FULL}" ${CMAKE_CURRENT_SOURCE_DIR}/${PM_PODFILE} ${CMAKE_CURRENT_BINARY_DIR}${SLASHLOCALE}/colobot.${COLOBOT_MANPAGE_SECTION} COMMENT "Create ${SLASHLOCALE}/colobot.${COLOBOT_MANPAGE_SECTION} manpage" diff --git a/src/po/colobot.pot b/src/po/colobot.pot index a45303e..e1f9dc7 100644 --- a/src/po/colobot.pot +++ b/src/po/colobot.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2012-12-27 13:53+0100\n" +"POT-Creation-Date: 2012-12-27 17:09+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -20,9 +20,6 @@ msgstr "" msgid "Colobot rules!" msgstr "" -msgid "Colobot Gold" -msgstr "" - msgid "SatCom" msgstr "" diff --git a/src/po/de.po b/src/po/de.po index 6edcedd..2992cb1 100644 --- a/src/po/de.po +++ b/src/po/de.po @@ -1,7 +1,7 @@ msgid "" msgstr "" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2012-12-27 13:53+0100\n" +"POT-Creation-Date: 2012-12-27 17:09+0100\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -378,9 +378,6 @@ msgstr "Schließen" msgid "Closing bracket missing " msgstr "Es fehlt eine geschlossene Klammer \")\"" -msgid "Colobot Gold" -msgstr "Colobot Gold" - msgid "Colobot rules!" msgstr "Colobot ist wunderbar!" diff --git a/src/po/fr.po b/src/po/fr.po index 973dc19..662fb93 100644 --- a/src/po/fr.po +++ b/src/po/fr.po @@ -2,16 +2,16 @@ msgid "" msgstr "" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2012-12-27 13:53+0100\n" +"POT-Creation-Date: 2012-12-27 17:09+0100\n" +"PO-Revision-Date: 2012-12-27 14:07+0100\n" +"Last-Translator: Didier Raboud \n" +"Language: fr\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" "X-Language: fr_FR\n" "X-Source-Language: en_US\n" -"Last-Translator: Didier Raboud \n" -"PO-Revision-Date: 2012-12-27 14:07+0100\n" -"Language: fr\n" "X-Generator: Lokalize 1.4\n" msgid " " @@ -378,9 +378,6 @@ msgstr "Fermer" msgid "Closing bracket missing " msgstr "Il manque une parenthèse fermante" -msgid "Colobot Gold" -msgstr "Colobot Gold" - msgid "Colobot rules!" msgstr "Colobot est super!" diff --git a/src/po/pl.po b/src/po/pl.po index 27b05c4..9bab529 100644 --- a/src/po/pl.po +++ b/src/po/pl.po @@ -1,7 +1,7 @@ msgid "" msgstr "" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2012-12-27 13:53+0100\n" +"POT-Creation-Date: 2012-12-27 17:09+0100\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -380,9 +380,6 @@ msgstr "Zamknij" msgid "Closing bracket missing " msgstr "Brak nawiasu zamykajÄ…cego" -msgid "Colobot Gold" -msgstr "Colobot Gold" - msgid "Colobot rules!" msgstr "Colobot rzÄ…dzi!" -- cgit v1.2.3-1-g7c22 From 4cbb63f5b7824dc48e999401c625adb50075fdca Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Fri, 28 Dec 2012 12:06:37 +0100 Subject: Fixed path for loading sounds --- src/app/app.cpp | 33 +++++++++++++++++++-------------- src/app/app.h | 8 ++++---- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index 27adcb1..4d32de3 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -329,26 +329,29 @@ bool CApplication::Create() GetLogger()->Debug("Testing gettext translation: '%s'\n", gettext("Colobot rules!")); //Create the sound instance. - if (!GetProfile().InitCurrentDirectory()) { + if (!GetProfile().InitCurrentDirectory()) + { GetLogger()->Warn("Config not found. Default values will be used!\n"); m_sound = new CSoundInterface(); - } else { + } + else + { std::string path; if (GetProfile().GetLocalProfileString("Resources", "Data", path)) m_dataPath = path; - #ifdef OPENAL_SOUND - m_sound = static_cast(new ALSound()); - #else - GetLogger()->Info("No sound support.\n"); - m_sound = new CSoundInterface(); - #endif + #ifdef OPENAL_SOUND + m_sound = static_cast(new ALSound()); + #else + GetLogger()->Info("No sound support.\n"); + m_sound = new CSoundInterface(); + #endif m_sound->Create(true); if (GetProfile().GetLocalProfileString("Resources", "Sound", path)) m_sound->CacheAll(path); else - m_sound->CacheAll(m_dataPath); + m_sound->CacheAll(GetDataSubdirPath(DIR_SOUND)); } std::string standardInfoMessage = @@ -1421,24 +1424,26 @@ std::string CApplication::GetDataDirPath() return m_dataPath; } -std::string CApplication::GetDataFilePath(DataDir dataDir, const std::string& subpath) +std::string CApplication::GetDataSubdirPath(DataDir stdDir) { - int index = static_cast(dataDir); + int index = static_cast(stdDir); assert(index >= 0 && index < DIR_MAX); std::stringstream str; str << m_dataPath; str << "/"; str << m_dataDirs[index]; - str << "/"; - str << subpath; return str.str(); } -std::string CApplication::GetDataFilePath(const std::string& subpath) +std::string CApplication::GetDataFilePath(DataDir stdDir, const std::string& subpath) { + int index = static_cast(stdDir); + assert(index >= 0 && index < DIR_MAX); std::stringstream str; str << m_dataPath; str << "/"; + str << m_dataDirs[index]; + str << "/"; str << subpath; return str.str(); } diff --git a/src/app/app.h b/src/app/app.h index 5bf6867..20d07df 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -285,11 +285,11 @@ public: //! Returns the full path to data directory std::string GetDataDirPath(); - //! Returns the full path to a file in data directory given standard dir and subpath - std::string GetDataFilePath(DataDir dir, const std::string &subpath); + //! Returns the full path to a standard dir in data directory + std::string GetDataSubdirPath(DataDir stdDir); - //! Returns the full path to a file in data directory given custom subpath in data dir - std::string GetDataFilePath(const std::string &subpath); + //! Returns the full path to a file in data directory given standard dir and subpath + std::string GetDataFilePath(DataDir stdDir, const std::string &subpath); //! Management of language //@{ -- cgit v1.2.3-1-g7c22 From 2ebe1fbcb68957bf1d374ffc5dc818dd706c72a7 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Fri, 28 Dec 2012 13:23:49 +0100 Subject: Fixed spider and worm model loading --- src/graphics/engine/engine.cpp | 44 +++++++++++++++++++++++++++++++++++++- src/graphics/engine/engine.h | 6 +++--- src/object/motion/motionspider.cpp | 2 +- src/object/motion/motionworm.cpp | 2 +- 4 files changed, 48 insertions(+), 6 deletions(-) diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index ea0c093..f7e300e 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -703,7 +703,7 @@ void CEngine::DeleteObject(int objRank) void CEngine::SetObjectBaseRank(int objRank, int baseObjRank) { - assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); + assert(objRank == -1 || (objRank >= 0 && objRank < static_cast( m_objects.size() ))); m_objects[objRank].baseObjRank = baseObjRank; } @@ -770,6 +770,9 @@ void CEngine::GetObjectBBox(int objRank, Math::Vector& min, Math::Vector& max) assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); int baseObjRank = m_objects[objRank].baseObjRank; + if (baseObjRank == -1) + return; + assert(baseObjRank >= 0 && baseObjRank < static_cast(m_baseObjects.size())); min = m_baseObjects[baseObjRank].bboxMin; @@ -782,6 +785,9 @@ int CEngine::GetObjectTotalTriangles(int objRank) assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); int baseObjRank = m_objects[objRank].baseObjRank; + if (baseObjRank == -1) + return 0; + assert(baseObjRank >= 0 && baseObjRank < static_cast( m_baseObjects.size() )); return m_baseObjects[baseObjRank].totalTriangles; @@ -794,6 +800,9 @@ EngineBaseObjDataTier* CEngine::FindTriangles(int objRank, const Material& mater assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); int baseObjRank = m_objects[objRank].baseObjRank; + if (baseObjRank == -1) + return nullptr; + assert(baseObjRank >= 0 && baseObjRank < static_cast( m_baseObjects.size() )); EngineBaseObject& p1 = m_baseObjects[baseObjRank]; @@ -834,6 +843,9 @@ int CEngine::GetPartialTriangles(int objRank, float min, float max, float percen assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); int baseObjRank = m_objects[objRank].baseObjRank; + if (baseObjRank == -1) + return 0; + assert(baseObjRank >= 0 && baseObjRank < static_cast( m_baseObjects.size() )); EngineBaseObject& p1 = m_baseObjects[baseObjRank]; @@ -981,6 +993,9 @@ void CEngine::ChangeSecondTexture(int objRank, const std::string& tex2Name) assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); int baseObjRank = m_objects[objRank].baseObjRank; + if (baseObjRank == -1) + return; + assert(baseObjRank >= 0 && baseObjRank < static_cast( m_baseObjects.size() )); EngineBaseObject& p1 = m_baseObjects[baseObjRank]; @@ -1344,6 +1359,9 @@ bool CEngine::GetBBox2D(int objRank, Math::Point &min, Math::Point &max) max.y = -1000000.0f; int baseObjRank = m_objects[objRank].baseObjRank; + if (baseObjRank == -1) + return false; + assert(baseObjRank >= 0 && baseObjRank < static_cast( m_baseObjects.size() )); EngineBaseObject& p1 = m_baseObjects[baseObjRank]; @@ -1613,6 +1631,9 @@ bool CEngine::DetectBBox(int objRank, Math::Point mouse) assert(objRank >= 0 && objRank < static_cast(m_objects.size())); int baseObjRank = m_objects[objRank].baseObjRank; + if (baseObjRank == -1) + return false; + assert(baseObjRank >= 0 && baseObjRank < static_cast(m_baseObjects.size())); EngineBaseObject& p1 = m_baseObjects[baseObjRank]; @@ -1667,6 +1688,9 @@ int CEngine::DetectObject(Math::Point mouse) continue; int baseObjRank = m_objects[objRank].baseObjRank; + if (baseObjRank == -1) + continue; + assert(baseObjRank >= 0 && baseObjRank < static_cast(m_baseObjects.size())); EngineBaseObject& p1 = m_baseObjects[baseObjRank]; @@ -1777,6 +1801,9 @@ bool CEngine::IsVisible(int objRank) assert(objRank >= 0 && objRank < static_cast(m_objects.size())); int baseObjRank = m_objects[objRank].baseObjRank; + if (baseObjRank == -1) + return false; + assert(baseObjRank >= 0 && baseObjRank < static_cast(m_baseObjects.size())); float radius = m_baseObjects[baseObjRank].radius; @@ -2172,6 +2199,9 @@ bool CEngine::LoadAllTextures() terrain = true; int baseObjRank = m_objects[objRank].baseObjRank; + if (baseObjRank == -1) + continue; + assert(baseObjRank >= 0 && baseObjRank < static_cast( m_baseObjects.size() )); EngineBaseObject& p1 = m_baseObjects[baseObjRank]; @@ -2988,6 +3018,9 @@ void CEngine::Draw3DScene() continue; int baseObjRank = m_objects[objRank].baseObjRank; + if (baseObjRank == -1) + continue; + assert(baseObjRank >= 0 && baseObjRank < static_cast( m_baseObjects.size() )); EngineBaseObject& p1 = m_baseObjects[baseObjRank]; @@ -3051,6 +3084,9 @@ void CEngine::Draw3DScene() continue; int baseObjRank = m_objects[objRank].baseObjRank; + if (baseObjRank == -1) + continue; + assert(baseObjRank >= 0 && baseObjRank < static_cast( m_baseObjects.size() )); EngineBaseObject& p1 = m_baseObjects[baseObjRank]; @@ -3117,6 +3153,9 @@ void CEngine::Draw3DScene() continue; int baseObjRank = m_objects[objRank].baseObjRank; + if (baseObjRank == -1) + continue; + assert(baseObjRank >= 0 && baseObjRank < static_cast( m_baseObjects.size() )); EngineBaseObject& p1 = m_baseObjects[baseObjRank]; @@ -3267,6 +3306,9 @@ void CEngine::DrawInterface() continue; int baseObjRank = m_objects[objRank].baseObjRank; + if (baseObjRank == -1) + continue; + assert(baseObjRank >= 0 && baseObjRank < static_cast( m_baseObjects.size() )); EngineBaseObject& p1 = m_baseObjects[baseObjRank]; diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index 899abc0..c9391db 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -621,9 +621,9 @@ struct EngineMouse * object equals to allocating space for EngineObject structure which holds object parameters. * * Object's geometric data is stored as a separate object -- base engine object. Each object - * must reference a valid base engine object. This many-to-one association allows to share - * same geometric data (e.g. from same model) across objects. Base engine objects are identified - * by unique rank obtained upon their creation. + * must reference a valid base engine object or an empty base engine object (with rank = -1). + * This many-to-one association allows to share same geometric data (e.g. from same model) + * across objects. * * Base engine object data is stored in a 4-tier tree which splits the data describing triangles. * diff --git a/src/object/motion/motionspider.cpp b/src/object/motion/motionspider.cpp index 66d89fb..3ede492 100644 --- a/src/object/motion/motionspider.cpp +++ b/src/object/motion/motionspider.cpp @@ -104,7 +104,7 @@ bool CMotionSpider::Create(Math::Vector pos, float angle, ObjectType type, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICULE); // this is a moving object m_object->SetObjectRank(0, rank); - modelManager->AddModelReference("spider0.mod", false, rank); + // This is an "empty" object, without triangles m_object->SetPosition(0, pos); m_object->SetAngleY(0, angle); diff --git a/src/object/motion/motionworm.cpp b/src/object/motion/motionworm.cpp index b53b865..f32765d 100644 --- a/src/object/motion/motionworm.cpp +++ b/src/object/motion/motionworm.cpp @@ -92,7 +92,7 @@ bool CMotionWorm::Create(Math::Vector pos, float angle, ObjectType type, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICULE); // this is a moving object m_object->SetObjectRank(0, rank); - modelManager->AddModelReference("worm0.mod", false, rank); // there is no purpose! + // This is an "empty" object, without triangles m_object->SetPosition(0, pos); m_object->SetAngleY(0, angle); -- cgit v1.2.3-1-g7c22 From 3e4c1a1ad88456ebf201b257b91847bd995c8773 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Fri, 28 Dec 2012 13:37:08 +0100 Subject: Replaced malloc/free with new/delete - now new/delete used everywhere except for CBotStack, which has to be fixed in other way - some segfaults should be fixed with this --- src/CBot/CBotString.cpp | 54 +++++++++++++++++++++++--------------------- src/common/image.cpp | 4 ++-- src/object/brain.cpp | 27 ++++++++++++++-------- src/object/task/taskgoto.cpp | 4 ++-- src/script/script.cpp | 33 +++++++++++++++------------ 5 files changed, 69 insertions(+), 53 deletions(-) diff --git a/src/CBot/CBotString.cpp b/src/CBot/CBotString.cpp index 4795b63..b1b5fc4 100644 --- a/src/CBot/CBotString.cpp +++ b/src/CBot/CBotString.cpp @@ -127,7 +127,8 @@ CBotString::CBotString() CBotString::~CBotString() { - free(m_ptr); //we can call free on null pointer as it's save + delete[] m_ptr; + m_ptr = nullptr; } @@ -138,7 +139,7 @@ CBotString::CBotString(const char* p) m_ptr = NULL; if (m_lg>0) { - m_ptr = static_cast(malloc(m_lg+1)); + m_ptr = new char[m_lg+1]; strcpy(m_ptr, p); } } @@ -150,7 +151,7 @@ CBotString::CBotString(const CBotString& srcString) m_ptr = NULL; if (m_lg>0) { - m_ptr = static_cast(malloc(m_lg+1)); + m_ptr = new char[m_lg+1]; strcpy(m_ptr, srcString.m_ptr); } } @@ -285,12 +286,12 @@ CBotString CBotString::Mid(int start, int lg) if ( lg < 0 ) lg = m_lg - start; - char* p = static_cast(malloc(m_lg+1)); + char* p = new char[m_lg+1]; strcpy(p, m_ptr+start); p[lg] = 0; res = p; - free(p); + delete[] p; return res; } @@ -314,15 +315,16 @@ void CBotString::MakeLower() bool CBotString::LoadString(unsigned int id) { - const char * str = NULL; + const char * str = nullptr; str = MapIdToString(static_cast(id)); - if (m_ptr != NULL) free(m_ptr); + if (m_ptr != nullptr) + delete[] m_ptr; m_lg = strlen(str); m_ptr = NULL; if (m_lg > 0) { - m_ptr = static_cast(malloc(m_lg+1)); + m_ptr = new char[m_lg+1]; strcpy(m_ptr, str); return true; } @@ -332,14 +334,14 @@ bool CBotString::LoadString(unsigned int id) const CBotString& CBotString::operator=(const CBotString& stringSrc) { - free(m_ptr); - m_ptr = NULL; + delete[] m_ptr; + m_ptr = nullptr; m_lg = stringSrc.m_lg; if (m_lg > 0) { - m_ptr = static_cast(malloc(m_lg+1)); + m_ptr = new char[m_lg+1]; strcpy(m_ptr, stringSrc.m_ptr); } @@ -355,13 +357,13 @@ CBotString operator+(const CBotString& string, const char * lpsz) const CBotString& CBotString::operator+(const CBotString& stringSrc) { - char* p = static_cast(malloc(m_lg+stringSrc.m_lg+1)); + char* p = new char[m_lg+stringSrc.m_lg+1]; if (m_ptr!=NULL) strcpy(p, m_ptr); char* pp = p + m_lg; if (stringSrc.m_ptr!=NULL) strcpy(pp, stringSrc.m_ptr); - free(m_ptr); + delete[] m_ptr; m_ptr = p; m_lg += stringSrc.m_lg; @@ -370,11 +372,11 @@ const CBotString& CBotString::operator+(const CBotString& stringSrc) const CBotString& CBotString::operator=(const char ch) { - free(m_ptr); + delete[] m_ptr; m_lg = 1; - m_ptr = static_cast(malloc(2)); + m_ptr = new char[2]; m_ptr[0] = ch; m_ptr[1] = 0; @@ -383,16 +385,16 @@ const CBotString& CBotString::operator=(const char ch) const CBotString& CBotString::operator=(const char* pString) { - free(m_ptr); - m_ptr = NULL; + delete[] m_ptr; + m_ptr = nullptr; - if (pString != NULL) + if (pString != nullptr) { m_lg = strlen(pString); if (m_lg != 0) { - m_ptr = static_cast(malloc(m_lg+1)); + m_ptr = new char[m_lg+1]; strcpy(m_ptr, pString); } } @@ -403,13 +405,13 @@ const CBotString& CBotString::operator=(const char* pString) const CBotString& CBotString::operator+=(const char ch) { - char* p = static_cast(malloc(m_lg+2)); + char* p = new char[m_lg+2]; - if (m_ptr!=NULL) strcpy(p, m_ptr); + if (m_ptr != nullptr) strcpy(p, m_ptr); p[m_lg++] = ch; p[m_lg] = 0; - free(m_ptr); + delete[] m_ptr; m_ptr = p; @@ -418,7 +420,7 @@ const CBotString& CBotString::operator+=(const char ch) const CBotString& CBotString::operator+=(const CBotString& str) { - char* p = static_cast(malloc(m_lg+str.m_lg+1)); + char* p = new char[m_lg+str.m_lg+1]; strcpy(p, m_ptr); char* pp = p + m_lg; @@ -426,7 +428,7 @@ const CBotString& CBotString::operator+=(const CBotString& str) m_lg = m_lg + str.m_lg; - free(m_ptr); + delete[] m_ptr; m_ptr = p; @@ -500,8 +502,8 @@ bool CBotString::IsEmpty() const void CBotString::Empty() { - free(m_ptr); - m_ptr = NULL; + delete[] m_ptr; + m_ptr = nullptr; m_lg = 0; } diff --git a/src/common/image.cpp b/src/common/image.cpp index f3cfa34..ef8097e 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -124,14 +124,14 @@ bool PNGSaveSurface(const char *filename, SDL_Surface *surf) png_write_info(png_ptr, info_ptr); png_set_packing(png_ptr); - row_pointers = static_cast( malloc(sizeof(png_bytep)*surf->h) ); + row_pointers = new png_bytep[surf->h]; for (i = 0; i < surf->h; i++) row_pointers[i] = static_cast( static_cast(surf->pixels) ) + i*surf->pitch; png_write_image(png_ptr, row_pointers); png_write_end(png_ptr, info_ptr); /* Cleaning out... */ - free(row_pointers); + delete[] row_pointers; png_destroy_write_struct(&png_ptr, &info_ptr); fclose(fp); diff --git a/src/object/brain.cpp b/src/object/brain.cpp index 4ce1bf8..ef7309d 100644 --- a/src/object/brain.cpp +++ b/src/object/brain.cpp @@ -99,7 +99,7 @@ CBrain::CBrain(CInstanceManager* iMan, CObject* object) m_selScript = 0; m_bTraceRecord = false; - m_traceRecordBuffer = 0; + m_traceRecordBuffer = nullptr; } // Object's destructor. @@ -111,12 +111,21 @@ CBrain::~CBrain() for ( i=0 ; iDeleteInstance(CLASS_BRAIN, this); } @@ -2791,8 +2800,8 @@ void CBrain::TraceRecordStart() m_traceColor = -1; } - delete m_traceRecordBuffer; - m_traceRecordBuffer = static_cast(malloc(sizeof(TraceRecord)*MAXTRACERECORD)); + delete[] m_traceRecordBuffer; + m_traceRecordBuffer = new TraceRecord[MAXTRACERECORD]; m_traceRecordIndex = 0; } @@ -2858,10 +2867,10 @@ void CBrain::TraceRecordStop() int max, i; char* buffer; - if ( m_traceRecordBuffer == 0 ) return; + if ( m_traceRecordBuffer == nullptr ) return; max = 10000; - buffer = static_cast(malloc(max)); + buffer = new char[max]; *buffer = 0; strncat(buffer, "extern void object::AutoDraw()\n{\n", max-1); @@ -2892,8 +2901,8 @@ void CBrain::TraceRecordStop() } TraceRecordPut(buffer, max, lastOper, lastParam); - delete m_traceRecordBuffer; - m_traceRecordBuffer = 0; + delete[] m_traceRecordBuffer; + m_traceRecordBuffer = nullptr; strncat(buffer, "}\n", max-1); buffer[max-1] = 0; @@ -2904,7 +2913,7 @@ void CBrain::TraceRecordStop() m_script[i] = new CScript(m_iMan, m_object, &m_secondaryTask); } m_script[i]->SendScript(buffer); - delete buffer; + delete[] buffer; } // Saves an instruction CBOT. diff --git a/src/object/task/taskgoto.cpp b/src/object/task/taskgoto.cpp index ce778ef..cab57f1 100644 --- a/src/object/task/taskgoto.cpp +++ b/src/object/task/taskgoto.cpp @@ -2119,7 +2119,7 @@ bool CTaskGoto::BitmapOpen() BitmapClose(); m_bmSize = static_cast(3200.0f/BM_DIM_STEP); - m_bmArray = static_cast(malloc(m_bmSize*m_bmSize/8*2)); + m_bmArray = new unsigned char[m_bmSize*m_bmSize/8*2]; memset(m_bmArray, 0, m_bmSize*m_bmSize/8*2); m_bmOffset = m_bmSize/2; @@ -2137,7 +2137,7 @@ bool CTaskGoto::BitmapOpen() bool CTaskGoto::BitmapClose() { - free(m_bmArray); + delete[] m_bmArray; m_bmArray = 0; return true; } diff --git a/src/script/script.cpp b/src/script/script.cpp index 8471df5..57d638e 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -1571,7 +1571,7 @@ bool CScript::rGrab(CBotVar* var, CBotVar* result, int& exception, void* user) if ( script->m_primaryTask == 0 ) // no task in progress? { script->m_primaryTask = new CTaskManager(script->m_iMan, script->m_object); - if ( var == 0 ) + if ( var == 0 ) { type = TMA_FFRONT; } @@ -2753,9 +2753,14 @@ void CScript::InitFonctions() CScript::~CScript() { delete m_botProg; + m_botProg = nullptr; + delete m_primaryTask; - delete m_script; - m_script = 0; + m_primaryTask = nullptr; + + delete[] m_script; + m_script = nullptr; + m_len = 0; m_iMan->DeleteInstance(CLASS_SCRIPT, this); @@ -2766,7 +2771,7 @@ CScript::~CScript() void CScript::PutScript(Ui::CEdit* edit, const char* name) { - if ( m_script == 0 ) + if ( m_script == nullptr ) { New(edit, name); } @@ -2785,11 +2790,11 @@ bool CScript::GetScript(Ui::CEdit* edit) { int len; - delete m_script; - m_script = 0; + delete[] m_script; + m_script = nullptr; len = edit->GetTextLength(); - m_script = static_cast(malloc(sizeof(char)*(len+1))); + m_script = new char[len+1]; edit->GetText(m_script, len+1); edit->GetCursor(m_cursor2, m_cursor1); @@ -2997,7 +3002,7 @@ void CScript::SetStepMode(bool bStep) bool CScript::Run() { if( m_botProg == 0 ) return false; - if ( m_script == 0 || m_len == 0 ) return false; + if ( m_script == nullptr || m_len == 0 ) return false; if ( !m_botProg->Start(m_title) ) return false; @@ -3475,9 +3480,9 @@ bool CScript::IntroduceVirus() start = found[i+1]; i = found[i+0]; - newScript = static_cast(malloc(sizeof(char)*(m_len+strlen(names[i+1])+1))); + newScript = new char[m_len+strlen(names[i+1])+1]; strcpy(newScript, m_script); - delete m_script; + delete[] m_script; m_script = newScript; DeleteToken(m_script, start, strlen(names[i])); @@ -3638,7 +3643,7 @@ void CScript::New(Ui::CEdit* edit, const char* name) bool CScript::SendScript(char* text) { m_len = strlen(text); - m_script = static_cast(malloc(sizeof(char)*(m_len+1))); + m_script = new char[m_len+1]; strcpy(m_script, text); if ( !CheckToken() ) return false; if ( !Compile() ) return false; @@ -3669,8 +3674,8 @@ bool CScript::ReadScript(const char* filename) if ( file == NULL ) return false; fclose(file); - delete m_script; - m_script = 0; + delete[] m_script; + m_script = nullptr; edit = m_interface->CreateEdit(Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f), 0, EVENT_EDIT9); edit->SetMaxChar(Ui::EDITSTUDIOMAX); @@ -3697,7 +3702,7 @@ bool CScript::WriteScript(const char* filename) name = filename; } - if ( m_script == 0 ) + if ( m_script == nullptr ) { remove(filename); return false; -- cgit v1.2.3-1-g7c22 From c9ca8f2b62b4994fa797272aecaf33f23253acae Mon Sep 17 00:00:00 2001 From: erihel Date: Fri, 28 Dec 2012 21:19:50 +0100 Subject: * Fixed segault when could not set sound pitch (bad logger call) * All 81 audio files should be loaded instead of 69 high quality * Changed volume ajustment formula to proper one --- src/sound/oalsound/alsound.cpp | 14 ++++++++------ src/sound/oalsound/channel.cpp | 24 ++++++++++++------------ src/sound/sound.h | 2 +- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp index 0201417..f683a62 100644 --- a/src/sound/oalsound/alsound.cpp +++ b/src/sound/oalsound/alsound.cpp @@ -296,6 +296,8 @@ int ALSound::Play(Sound sound, Math::Vector pos, float amplitude, float frequenc GetLogger()->Warn("Sound %d was not loaded!\n", sound); return -1; } + + GetLogger()->Trace("ALSound::Play sound: %d volume: %f frequency: %f\n", sound, amplitude, frequency); int channel; bool bAlreadyLoaded; @@ -308,12 +310,12 @@ int ALSound::Play(Sound sound, Math::Vector pos, float amplitude, float frequenc Position(channel, pos); // setting initial values - mChannels[channel]->SetStartAmplitude(amplitude); + mChannels[channel]->SetStartAmplitude(mAudioVolume); mChannels[channel]->SetStartFrequency(frequency); mChannels[channel]->SetChangeFrequency(1.0f); mChannels[channel]->ResetOper(); - mChannels[channel]->AdjustFrequency(frequency); - mChannels[channel]->AdjustVolume(mAudioVolume); + mChannels[channel]->AdjustFrequency(frequency); + mChannels[channel]->AdjustVolume(amplitude * mAudioVolume); mChannels[channel]->Play(); return channel; } @@ -451,17 +453,17 @@ void ALSound::FrameMove(float delta) it.second->AdjustVolume(volume * mAudioVolume); // setting frequency - frequency = progress * (oper.finalFrequency - it.second->GetStartFrequency()) * it.second->GetStartFrequency() * it.second->GetChangeFrequency(); + frequency = progress * abs(oper.finalFrequency - it.second->GetStartFrequency()) * it.second->GetStartFrequency() * it.second->GetChangeFrequency(); it.second->AdjustFrequency(frequency); if (it.second->GetEnvelope().totalTime <= it.second->GetCurrentTime()) { if (oper.nextOper == SOPER_LOOP) { - GetLogger()->Trace("Sound oper: replay.\n"); + GetLogger()->Trace("ALSound::FrameMove oper: replay.\n"); it.second->SetCurrentTime(0.0f); it.second->Play(); } else { - GetLogger()->Trace("Sound oper: next.\n"); + GetLogger()->Trace("ALSound::FrameMove oper: next.\n"); it.second->SetStartAmplitude(oper.finalAmplitude); it.second->SetStartFrequency(oper.finalFrequency); it.second->PopEnvelope(); diff --git a/src/sound/oalsound/channel.cpp b/src/sound/oalsound/channel.cpp index 2285414..7d8244b 100644 --- a/src/sound/oalsound/channel.cpp +++ b/src/sound/oalsound/channel.cpp @@ -39,7 +39,7 @@ Channel::~Channel() { alSourcei(mSource, AL_BUFFER, 0); alDeleteSources(1, &mSource); if (alCheck()) - GetLogger()->Warn("Failed to delete sound source. Code: %s\n", alGetCode()); + GetLogger()->Warn("Failed to delete sound source. Code: %d\n", alGetCode()); } } @@ -50,7 +50,7 @@ bool Channel::Play() { alSourcePlay(mSource); if (alCheck()) - GetLogger()->Warn("Could not play audio sound source. Code: %s\n", alGetCode()); + GetLogger()->Warn("Could not play audio sound source. Code: %d\n", alGetCode()); return true; } @@ -61,7 +61,7 @@ bool Channel::SetPosition(Math::Vector pos) { alSource3f(mSource, AL_POSITION, pos.x, pos.y, pos.z); if (alCheck()) { - GetLogger()->Warn("Could not set sound position. Code: %s\n", alGetCode()); + GetLogger()->Warn("Could not set sound position. Code: %d\n", alGetCode()); return false; } return true; @@ -75,7 +75,7 @@ bool Channel::SetFrequency(float freq) alSourcef(mSource, AL_PITCH, freq); if (alCheck()) { - GetLogger()->Warn("Could not set sound pitch. Code: %s\n", alGetCode()); + GetLogger()->Warn("Could not set sound pitch to '%f'. Code: %d\n", freq, alGetCode()); return false; } return true; @@ -90,7 +90,7 @@ float Channel::GetFrequency() alGetSourcef(mSource, AL_PITCH, &freq); if (alCheck()) { - GetLogger()->Warn("Could not get sound pitch. Code: %s\n", alGetCode()); + GetLogger()->Warn("Could not get sound pitch. Code: %d\n", alGetCode()); return 0; } @@ -105,7 +105,7 @@ bool Channel::SetVolume(float vol) alSourcef(mSource, AL_GAIN, vol / MAXVOLUME); if (alCheck()) { - GetLogger()->Warn("Could not set sound volume. Code: %s\n", alGetCode()); + GetLogger()->Warn("Could not set sound volume to '%f'. Code: %d\n", vol, alGetCode()); return false; } return true; @@ -120,7 +120,7 @@ float Channel::GetVolume() alGetSourcef(mSource, AL_GAIN, &vol); if (alCheck()) { - GetLogger()->Warn("Could not get sound volume. Code: %s\n", alGetCode()); + GetLogger()->Warn("Could not get sound volume. Code: %d\n", alGetCode()); return 0; } @@ -213,7 +213,7 @@ bool Channel::SetBuffer(Buffer *buffer) { mBuffer = buffer; alSourcei(mSource, AL_BUFFER, buffer->GetBuffer()); if (alCheck()) { - GetLogger()->Warn("Could not set sound buffer. Code: %s\n", alGetCode()); + GetLogger()->Warn("Could not set sound buffer. Code: %d\n", alGetCode()); return false; } mInitFrequency = GetFrequency(); @@ -237,7 +237,7 @@ bool Channel::IsPlaying() { alGetSourcei(mSource, AL_SOURCE_STATE, &status); if (alCheck()) { - GetLogger()->Warn("Could not get sound status. Code: %s\n", alGetCode()); + GetLogger()->Warn("Could not get sound status. Code: %d\n", alGetCode()); return false; } @@ -253,7 +253,7 @@ bool Channel::IsReady() { bool Channel::Stop() { alSourceStop(mSource); if (alCheck()) { - GetLogger()->Warn("Could not stop sound. Code: %s\n", alGetCode()); + GetLogger()->Warn("Could not stop sound. Code: %d\n", alGetCode()); return false; } return true; @@ -265,7 +265,7 @@ float Channel::GetCurrentTime() ALfloat current; alGetSourcef(mSource, AL_SEC_OFFSET, ¤t); if (alCheck()) { - GetLogger()->Warn("Could not get source current play time. Code: %s\n", alGetCode()); + GetLogger()->Warn("Could not get source current play time. Code: %d\n", alGetCode()); return 0.0f; } return current; @@ -276,7 +276,7 @@ void Channel::SetCurrentTime(float current) { alSourcef(mSource, AL_SEC_OFFSET, current); if (alCheck()) - GetLogger()->Warn("Could not get source current play time. Code: %s\n", alGetCode()); + GetLogger()->Warn("Could not get source current play time. Code: %d\n", alGetCode()); } diff --git a/src/sound/sound.h b/src/sound/sound.h index 566f415..518e2ad 100644 --- a/src/sound/sound.h +++ b/src/sound/sound.h @@ -168,7 +168,7 @@ class CSoundInterface * Function calls \link CSoundInterface::Cache() \endlink for each file */ inline void CacheAll(std::string path) { - for ( int i = 1; i < 69; i++ ) { + for ( int i = 1; i <= 81; i++ ) { std::stringstream filename; filename << path << "/sound" << std::setfill('0') << std::setw(3) << i << ".wav"; if ( !Cache(static_cast(i), filename.str()) ) -- cgit v1.2.3-1-g7c22 From f4c6f49b2fd01de2d6daff5ec1b9c181c39d09b7 Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Fri, 28 Dec 2012 22:31:47 +0100 Subject: Move language initialisation in SetLanguage --- src/app/app.cpp | 90 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 48 insertions(+), 42 deletions(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index 4d32de3..32f68e1 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -285,48 +285,7 @@ bool CApplication::Create() return false; } - /* Gettext initialization */ - - std::string locale = ""; - switch (m_language) - { - default: - case LANGUAGE_ENV: - locale = ""; - break; - - case LANGUAGE_ENGLISH: - locale = "en_US.utf8"; - break; - - case LANGUAGE_GERMAN: - locale = "de_DE.utf8"; - break; - - case LANGUAGE_FRENCH: - locale = "fr_FR.utf8"; - break; - - case LANGUAGE_POLISH: - locale = "pl_PL.utf8"; - break; - } - - if (!locale.empty()) - { - std::string langStr = "LANG="; - langStr += locale; - strcpy(S_LANGUAGE, langStr.c_str()); - putenv(S_LANGUAGE); - } - setlocale(LC_ALL, ""); - GetLogger()->Debug("Set locale to '%s'\n", locale.c_str()); - - bindtextdomain("colobot", COLOBOT_I18N_DIR); - bind_textdomain_codeset("colobot", "UTF-8"); - textdomain("colobot"); - - GetLogger()->Debug("Testing gettext translation: '%s'\n", gettext("Colobot rules!")); + SetLanguage(m_language); //Create the sound instance. if (!GetProfile().InitCurrentDirectory()) @@ -1456,6 +1415,53 @@ Language CApplication::GetLanguage() void CApplication::SetLanguage(Language language) { m_language = language; + + /* Gettext initialization */ + + std::string locale = ""; + switch (m_language) + { + default: + case LANGUAGE_ENV: + locale = ""; + break; + + case LANGUAGE_ENGLISH: + locale = "en_US.utf8"; + break; + + case LANGUAGE_GERMAN: + locale = "de_DE.utf8"; + break; + + case LANGUAGE_FRENCH: + locale = "fr_FR.utf8"; + break; + + case LANGUAGE_POLISH: + locale = "pl_PL.utf8"; + break; + } + + if (locale.empty()) + { + GetLogger()->Trace("SetLanguage: Inherit LANGUAGE=%s from environment\n", getenv("LANGUAGE")); + } + else + { + std::string langStr = "LANGUAGE="; + langStr += locale; + strcpy(S_LANGUAGE, langStr.c_str()); + putenv(S_LANGUAGE); + GetLogger()->Trace("SetLanguage: Set LANGUAGE=%s in environment\n", locale.c_str()); + } + setlocale(LC_ALL, ""); + + bindtextdomain("colobot", COLOBOT_I18N_DIR); + bind_textdomain_codeset("colobot", "UTF-8"); + textdomain("colobot"); + + GetLogger()->Debug("SetLanguage: Test gettext translation: '%s'\n", gettext("Colobot rules!")); } void CApplication::SetLowCPU(bool low) -- cgit v1.2.3-1-g7c22 From 1b4208cdc5143cfc8f46da063a1a991795d7f307 Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Fri, 28 Dec 2012 23:06:12 +0100 Subject: Implement language Char for level files This currently lacks fallback to an existing entry for non-translated entries --- src/app/app.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++++- src/app/app.h | 1 + src/object/robotmain.cpp | 8 ++++---- src/ui/maindialog.cpp | 20 ++++++++++---------- 4 files changed, 59 insertions(+), 15 deletions(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index 32f68e1..1e577ca 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -1412,6 +1412,32 @@ Language CApplication::GetLanguage() return m_language; } +char CApplication::GetLanguageChar() +{ + char langChar = 'E'; + switch (m_language) + { + default: + case LANGUAGE_ENV: + case LANGUAGE_ENGLISH: + langChar = 'E'; + break; + + case LANGUAGE_GERMAN: + langChar = 'D'; + break; + + case LANGUAGE_FRENCH: + langChar = 'F'; + break; + + case LANGUAGE_POLISH: + langChar = 'P'; + break; + } + return langChar; +} + void CApplication::SetLanguage(Language language) { m_language = language; @@ -1445,7 +1471,24 @@ void CApplication::SetLanguage(Language language) if (locale.empty()) { - GetLogger()->Trace("SetLanguage: Inherit LANGUAGE=%s from environment\n", getenv("LANGUAGE")); + char *envLang = getenv("LANGUAGE"); + if (strncmp(envLang,"en",2) == 0) + { + m_language = LANGUAGE_ENGLISH; + } + else if (strncmp(envLang,"de",2) == 0) + { + m_language = LANGUAGE_GERMAN; + } + else if (strncmp(envLang,"fr",2) == 0) + { + m_language = LANGUAGE_FRENCH; + } + else if (strncmp(envLang,"po",2) == 0) + { + m_language = LANGUAGE_POLISH; + } + GetLogger()->Trace("SetLanguage: Inherit LANGUAGE=%s from environment\n", envLang); } else { diff --git a/src/app/app.h b/src/app/app.h index 20d07df..2da20d3 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -294,6 +294,7 @@ public: //! Management of language //@{ Language GetLanguage(); + char GetLanguageChar(); void SetLanguage(Language language); //@} diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index d5805d0..aa2fe22 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -3808,16 +3808,16 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) } } - // TODO: language letters - sprintf(op, "Title.%c", 'E' /*GetLanguageLetter()*/); + // TODO: Fallback to an non-localized entry + sprintf(op, "Title.%c", m_app->GetLanguageChar()); if (Cmd(line, op) && !resetObject) OpString(line, "text", m_title); - sprintf(op, "Resume.%c", 'E' /*GetLanguageLetter()*/); + sprintf(op, "Resume.%c", m_app->GetLanguageChar()); if (Cmd(line, op) && !resetObject) OpString(line, "text", m_resume); - sprintf(op, "ScriptName.%c", 'E' /*GetLanguageLetter()*/); + sprintf(op, "ScriptName.%c", m_app->GetLanguageChar()); if (Cmd(line, op) && !resetObject) OpString(line, "text", m_scriptName); diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index ebf7d10..68e7854 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -4305,8 +4305,8 @@ void CMainDialog::IOReadName() } } - // TODO: language letters - sprintf(op, "Title.%c", 'E' /*MAX_FNAME()*/ ); + // TODO: Fallback to an non-localized entry + sprintf(op, "Title.%c", m_app->GetLanguageChar() ); if ( Cmd(line, op) ) { OpString(line, "resume", resume); @@ -4701,8 +4701,8 @@ void CMainDialog::UpdateSceneChap(int &chap) } } - /* TODO: language letters */ - sprintf(op, "Title.%c", 'E' /*GetLanguageLetter()*/); + // TODO: Fallback to an non-localized entry + sprintf(op, "Title.%c", m_app->GetLanguageChar()); if ( Cmd(line, op) ) { OpString(line, "text", name); @@ -4748,8 +4748,8 @@ void CMainDialog::UpdateSceneChap(int &chap) } } - // TODO: language letters - sprintf(op, "Title.%c", 'E'/*GetLanguageLetter()*/); + // TODO: Fallback to an non-localized entry + sprintf(op, "Title.%c", m_app->GetLanguageChar()); if ( Cmd(line, op) ) { OpString(line, "text", name); @@ -4851,8 +4851,8 @@ void CMainDialog::UpdateSceneList(int chap, int &sel) } } - // TODO: language letters - sprintf(op, "Title.%c", 'E' /*MAX_FNAME()*/); + // TODO: Fallback to an non-localized entry + sprintf(op, "Title.%c", m_app->GetLanguageChar()); if ( Cmd(line, op) ) { OpString(line, "text", name); @@ -4996,8 +4996,8 @@ void CMainDialog::UpdateSceneResume(int rank) } } - // TODO: language letters - sprintf(op, "Resume.%c", 'E' /*MAX_FNAME()*/); + // TODO: Fallback to an non-localized entry + sprintf(op, "Resume.%c", m_app->GetLanguageChar()); if ( Cmd(line, op) ) { OpString(line, "text", name); -- cgit v1.2.3-1-g7c22 From ea3e97b26db558e003897f8aa1646af32a4f2418 Mon Sep 17 00:00:00 2001 From: erihel Date: Sat, 29 Dec 2012 13:32:11 +0100 Subject: * Fixed problem with scrolling down text fields with mouse scroll * Fixed problem with scroll bar not updating position properly in text fields --- src/ui/edit.cpp | 60 +++++++++++++++++++++++++++++++-------------------------- src/ui/edit.h | 2 ++ 2 files changed, 35 insertions(+), 27 deletions(-) diff --git a/src/ui/edit.cpp b/src/ui/edit.cpp index e14b19d..639215a 100644 --- a/src/ui/edit.cpp +++ b/src/ui/edit.cpp @@ -243,7 +243,7 @@ bool CEdit::EventProcess(const Event &event) Scroll(m_lineFirst-3, true); return true; } - if (event.type == EVENT_KEY_DOWN && + if (event.type == EVENT_MOUSE_WHEEL && event.mouseWheel.dir == WHEEL_DOWN && Detect(event.mousePos) ) { @@ -282,7 +282,7 @@ bool CEdit::EventProcess(const Event &event) } } - if ( m_scroll != 0 && !m_bGeneric ) + if ( m_scroll != nullptr && !m_bGeneric ) { m_scroll->EventProcess(event); @@ -1248,7 +1248,7 @@ void CEdit::SetText(const char *text, bool bNew) { int i, j, font; bool bBOL; - + if ( !bNew ) UndoMemorize(OPERUNDO_SPEC); m_len = strlen(text); @@ -2172,11 +2172,11 @@ void CEdit::Scroll() { float value; - if ( m_scroll != 0 ) + if ( m_scroll != nullptr ) { value = m_scroll->GetVisibleValue(); - value *= m_lineTotal-m_lineVisible; - Scroll(static_cast(value+0.5f), true); + value *= m_lineTotal - m_lineVisible; + Scroll(static_cast(value + 0.5f), true); } } @@ -3048,7 +3048,7 @@ bool CEdit::MinMaj(bool bMaj) void CEdit::Justif() { - float width, value, size, indentLength; + float width, size, indentLength; int i, j, line, indent; bool bDual, bString, bRem; @@ -3176,26 +3176,7 @@ void CEdit::Justif() m_lineFirst = 0; } - if ( m_scroll != 0 ) - { - if ( m_lineTotal <= m_lineVisible ) - { - m_scroll->SetVisibleRatio(1.0f); - m_scroll->SetVisibleValue(0.0f); - m_scroll->SetArrowStep(0.0f); - } - else - { - value = static_cast(m_lineVisible/m_lineTotal); - m_scroll->SetVisibleRatio(value); - - value = static_cast(m_lineFirst/(m_lineTotal-m_lineVisible)); - m_scroll->SetVisibleValue(value); - - value = static_cast(1.0f/(m_lineTotal-m_lineVisible)); - m_scroll->SetArrowStep(value); - } - } + UpdateScroll(); m_timeBlink = 0.0f; // lights the cursor immediately } @@ -3326,5 +3307,30 @@ bool CEdit::SetFormat(int cursor1, int cursor2, int format) return true; } +void CEdit::UpdateScroll() +{ + float value; + + if ( m_scroll != nullptr ) + { + if ( m_lineTotal <= m_lineVisible ) + { + m_scroll->SetVisibleRatio(1.0f); + m_scroll->SetVisibleValue(0.0f); + m_scroll->SetArrowStep(0.0f); + } + else + { + value = static_cast(m_lineVisible) / m_lineTotal; + m_scroll->SetVisibleRatio(value); + + value = static_cast(m_lineFirst) / (m_lineTotal - m_lineVisible); + m_scroll->SetVisibleValue(value); + + value = 1.0f / (m_lineTotal - m_lineVisible); + m_scroll->SetArrowStep(value); + } + } +} } diff --git a/src/ui/edit.h b/src/ui/edit.h index 35d8b2c..7247181 100644 --- a/src/ui/edit.h +++ b/src/ui/edit.h @@ -234,6 +234,8 @@ protected: void UndoFlush(); void UndoMemorize(OperUndo oper); bool UndoRecall(); + + void UpdateScroll(); protected: CScroll* m_scroll; // vertical scrollbar on the right -- cgit v1.2.3-1-g7c22 From e1325dc3647e3b0a3f82fdced21bda24ff9f4207 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sat, 29 Dec 2012 14:35:14 +0100 Subject: Fix for TEST_VIRTUAL --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a3bd7f4..399ae96 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -153,7 +153,7 @@ if(${TESTS}) add_definitions(-DTEST_VIRTUAL=virtual) enable_testing() else() - add_definitions(-DTEST_VIRTUAL) + add_definitions(-DTEST_VIRTUAL=) endif() -- cgit v1.2.3-1-g7c22 From 16d97f91212c1b1b4cd775ab9808afb66b648267 Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Sun, 30 Dec 2012 12:16:43 +0100 Subject: Revert "Minor cmake grammar fix" It appears I was really wrong. Damn. This reverts commit 277629f9fec069afce32a21fd6baeb4f24d5784c. --- CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 399ae96..fbdd7cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -209,11 +209,11 @@ if(${TESTS}) endif() # Installation paths defined before compiling sources -set(COLOBOT_INSTALL_BIN_DIR games CACHE PATH "Colobot binary directory") -set(COLOBOT_INSTALL_DATA_DIR share/games/colobot CACHE PATH "Colobot shared data directory") -set(COLOBOT_INSTALL_LIB_DIR lib/colobot CACHE PATH "Colobot libraries directory") -set(COLOBOT_INSTALL_DOC_DIR share/doc/colobot CACHE PATH "Colobot documentation directory") -set(COLOBOT_INSTALL_I18N_DIR share/locale CACHE PATH "Colobot translations directory") +set(COLOBOT_INSTALL_BIN_DIR ${CMAKE_INSTALL_PREFIX}/games CACHE PATH "Colobot binary directory") +set(COLOBOT_INSTALL_DATA_DIR ${CMAKE_INSTALL_PREFIX}/share/games/colobot CACHE PATH "Colobot shared data directory") +set(COLOBOT_INSTALL_LIB_DIR ${CMAKE_INSTALL_PREFIX}/lib/colobot CACHE PATH "Colobot libraries directory") +set(COLOBOT_INSTALL_DOC_DIR ${CMAKE_INSTALL_PREFIX}/share/doc/colobot CACHE PATH "Colobot documentation directory") +set(COLOBOT_INSTALL_I18N_DIR ${CMAKE_INSTALL_PREFIX}/share/locale CACHE PATH "Colobot translations directory") # Subdirectory with sources add_subdirectory(src bin) -- cgit v1.2.3-1-g7c22 From 3fa5e9c9cc965f8077b0322ff7e4142f2d57f5a4 Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Wed, 2 Jan 2013 12:24:26 +0100 Subject: In levels' lists, fallback to english - Implemented in a naive way: Take the English version if found, but continue until the translated version is found. This has the drawback of letting the loop reach its end if the level has no translation. --- src/ui/maindialog.cpp | 51 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 68e7854..bbba825 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -4277,6 +4277,7 @@ void CMainDialog::IOReadName() CEdit* pe; std::string filename; char op[100]; + char op_i18n[100]; char line[500]; char resume[100]; char name[100]; @@ -4290,6 +4291,9 @@ void CMainDialog::IOReadName() sprintf(resume, "%s %d", m_sceneName, m_chap[m_index]+1); BuildSceneName(filename, m_sceneName, (m_chap[m_index]+1)*100); + sprintf(op, "Title.E"); + sprintf(op_i18n, "Title.%c", m_app->GetLanguageChar() ); + file = fopen(filename.c_str(), "r"); if ( file != NULL ) { @@ -4305,9 +4309,11 @@ void CMainDialog::IOReadName() } } - // TODO: Fallback to an non-localized entry - sprintf(op, "Title.%c", m_app->GetLanguageChar() ); if ( Cmd(line, op) ) + { + OpString(line, "resume", resume); + } + if ( Cmd(line, op_i18n) ) { OpString(line, "resume", resume); break; @@ -4648,12 +4654,14 @@ void CMainDialog::UpdateSceneChap(int &chap) //struct _finddata_t fileBuffer; std::string fileName; char op[100]; + char op_i18n[100]; char line[500]; char name[100]; int i, j; bool bPassed; memset(op, 0, 100); + memset(op_i18n, 0, 100); memset(line, 0, 500); memset(name, 0, 100); @@ -4689,6 +4697,9 @@ void CMainDialog::UpdateSceneChap(int &chap) else { BuildResumeName(name, m_sceneName, j+1); // default name + sprintf(op, "Title.E"); + sprintf(op_i18n, "Title.%c", m_app->GetLanguageChar()); + while ( fgets(line, 500, file) != NULL ) { for ( i=0 ; i<500 ; i++ ) @@ -4701,9 +4712,11 @@ void CMainDialog::UpdateSceneChap(int &chap) } } - // TODO: Fallback to an non-localized entry - sprintf(op, "Title.%c", m_app->GetLanguageChar()); if ( Cmd(line, op) ) + { + OpString(line, "text", name); + } + if ( Cmd(line, op_i18n) ) { OpString(line, "text", name); break; @@ -4736,6 +4749,9 @@ void CMainDialog::UpdateSceneChap(int &chap) if ( file == NULL ) break; BuildResumeName(name, m_sceneName, j+1); // default name + sprintf(op, "Title.E"); + sprintf(op_i18n, "Title.%c", m_app->GetLanguageChar()); + while ( fgets(line, 500, file) != NULL ) { for ( i=0 ; i<500 ; i++ ) @@ -4748,9 +4764,11 @@ void CMainDialog::UpdateSceneChap(int &chap) } } - // TODO: Fallback to an non-localized entry - sprintf(op, "Title.%c", m_app->GetLanguageChar()); if ( Cmd(line, op) ) + { + OpString(line, "text", name); + } + if ( Cmd(line, op_i18n) ) { OpString(line, "text", name); break; @@ -4801,12 +4819,14 @@ void CMainDialog::UpdateSceneList(int chap, int &sel) CList* pl; std::string fileName; char op[100]; + char op_i18n[100]; char line[500]; char name[100]; int i, j; bool bPassed; memset(op, 0, 100); + memset(op_i18n, 0, 100); memset(line, 0, 500); memset(name, 0, 100); @@ -4839,6 +4859,9 @@ void CMainDialog::UpdateSceneList(int chap, int &sel) if ( file == NULL ) break; BuildResumeName(name, m_sceneName, j+1); // default name + sprintf(op, "Title.E"); + sprintf(op_i18n, "Title.%c", m_app->GetLanguageChar()); + while ( fgets(line, 500, file) != NULL ) { for ( i=0 ; i<500 ; i++ ) @@ -4851,9 +4874,11 @@ void CMainDialog::UpdateSceneList(int chap, int &sel) } } - // TODO: Fallback to an non-localized entry - sprintf(op, "Title.%c", m_app->GetLanguageChar()); if ( Cmd(line, op) ) + { + OpString(line, "text", name); + } + if ( Cmd(line, op_i18n) ) { OpString(line, "text", name); break; @@ -4950,6 +4975,7 @@ void CMainDialog::UpdateSceneResume(int rank) CCheck* pc; std::string fileName; char op[100]; + char op_i18n[100]; char line[500]; char name[500]; int i, numTry; @@ -4980,6 +5006,9 @@ void CMainDialog::UpdateSceneResume(int rank) } BuildSceneName(fileName, m_sceneName, rank); + sprintf(op, "Resume.E"); + sprintf(op_i18n, "Resume.%c", m_app->GetLanguageChar()); + file = fopen(fileName.c_str(), "r"); if ( file == NULL ) return; @@ -4996,9 +5025,11 @@ void CMainDialog::UpdateSceneResume(int rank) } } - // TODO: Fallback to an non-localized entry - sprintf(op, "Resume.%c", m_app->GetLanguageChar()); if ( Cmd(line, op) ) + { + OpString(line, "text", name); + } + if ( Cmd(line, op_i18n) ) { OpString(line, "text", name); break; -- cgit v1.2.3-1-g7c22 From ffb4d9ff4fbee5c96ff7828044e9002d85843b6a Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Wed, 2 Jan 2013 14:23:17 +0100 Subject: Let CMake rely on data's CMakeLists.txt if it exists - Also update data to latest 'dev', where the CMakeLists exists --- CMakeLists.txt | 11 +++++++---- data | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fbdd7cc..8640832 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -223,10 +223,13 @@ add_subdirectory(src bin) # Installation ## -file(GLOB DATA_FILES "data/*") - -# Data -install(DIRECTORY data/ DESTINATION ${COLOBOT_INSTALL_DATA_DIR}) +# Data: check if the submodule handles its own installation +if(EXISTS "${CMAKE_SOURCE_DIR}/data/CMakeLists.txt") + message(STATUS "Data directory will install itself.") + add_subdirectory(data) +else() + message(WARNING "Data directory is not available; make sure colobot-data is installed in ${COLOBOT_INSTALL_DATA_DIR}.") +endif() # Documentation if(INSTALL_DOCS AND DOXYGEN_FOUND AND DOXYGEN_DOT_FOUND) diff --git a/data b/data index 6b6e5a0..5a991a7 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 6b6e5a0ab56bf42f17d969c1bd4c09185605cad6 +Subproject commit 5a991a77eb5f476d29b4d4f976be48fdf74a053f -- cgit v1.2.3-1-g7c22 From ba0679a1d7e58030c0265886b70ab5be5be171a2 Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Wed, 2 Jan 2013 19:00:35 +0100 Subject: Add categories to Desktop Entry file As per the "Desktop Menu Specification" 1.0, especially Appendix A. --- src/desktop/colobot.desktop.in | 1 + 1 file changed, 1 insertion(+) diff --git a/src/desktop/colobot.desktop.in b/src/desktop/colobot.desktop.in index 74378fd..9b09803 100644 --- a/src/desktop/colobot.desktop.in +++ b/src/desktop/colobot.desktop.in @@ -3,3 +3,4 @@ Version=1.0 Type=Application Exec=colobot Icon=colobot +Categories=Education;Robotics;Game;AdventureGame;StrategyGame; -- cgit v1.2.3-1-g7c22 From 2c0c5ddda16dd38fed39438d1e43d8e3589e8d93 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Thu, 3 Jan 2013 23:50:17 +0100 Subject: Fixed stupid debug code Terrain VBOs should work now --- src/graphics/opengl/gldevice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index 024a523..9460e07 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -1181,7 +1181,7 @@ void CGLDevice::DrawStaticBuffer(unsigned int bufferId) } GLenum mode = TranslateGfxPrimitive((*it).second.primitiveType); - glDrawArrays(GL_TRIANGLES, 0, (*it).second.vertexCount); + glDrawArrays(mode, 0, (*it).second.vertexCount); if ((*it).second.vertexType == VERTEX_TYPE_NORMAL) { -- cgit v1.2.3-1-g7c22 From c9335534d6bc7a59dbabf6976d41fd1e5edc8ab3 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Fri, 4 Jan 2013 00:02:13 +0100 Subject: Fix for #113 --- src/object/motion/motionvehicle.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/object/motion/motionvehicle.cpp b/src/object/motion/motionvehicle.cpp index d331f13..33e746f 100644 --- a/src/object/motion/motionvehicle.cpp +++ b/src/object/motion/motionvehicle.cpp @@ -933,8 +933,8 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); pPower->SetObjectRank(0, rank); - if ( power <= 1.0f ) modelManager->AddModelReference("power.mod", false, rank); - else modelManager->AddModelReference("atomic.mod", false, rank); + if ( power <= 1.0f ) modelManager->AddModelCopy("power.mod", false, rank); + else modelManager->AddModelCopy("atomic.mod", false, rank); pPower->SetPosition(0, m_object->GetCharacter()->posPower); pPower->CreateCrashSphere(Math::Vector(0.0f, 1.0f, 0.0f), 1.0f, SOUND_BOUMm, 0.45f); -- cgit v1.2.3-1-g7c22 From d1942e1216768d41bc747a79287962a76a3aeb75 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Fri, 4 Jan 2013 00:29:19 +0100 Subject: Correct font scaling with resolution --- src/app/app.cpp | 4 ++-- src/graphics/engine/engine.cpp | 2 ++ src/graphics/engine/text.cpp | 10 +++++++--- src/math/intpoint.h | 6 ++++++ 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index 2155cf4..4c66e24 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -903,14 +903,14 @@ Event CApplication::ProcessSystemEvent() { event.type = EVENT_QUIT; } - /*else if (m_private->currentEvent.type == SDL_VIDEORESIZE) + else if (m_private->currentEvent.type == SDL_VIDEORESIZE) { Gfx::GLDeviceConfig newConfig = m_deviceConfig; newConfig.size.x = m_private->currentEvent.resize.w; newConfig.size.y = m_private->currentEvent.resize.h; if (newConfig.size != m_deviceConfig.size) ChangeVideoConfig(newConfig); - }*/ + } else if ( (m_private->currentEvent.type == SDL_KEYDOWN) || (m_private->currentEvent.type == SDL_KEYUP) ) { diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index f7e300e..7c90a8d 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -281,6 +281,8 @@ void CEngine::Destroy() void CEngine::ResetAfterDeviceChanged() { + m_size = m_app->GetVideoConfig().size;; + m_text->FlushCache(); // TODO reload textures, reset device state, etc. diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index 101e01a..da1a290 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -46,7 +46,7 @@ struct CachedFont }; - +const Math::IntPoint REFERENCE_SIZE(800, 600); CText::CText(CInstanceManager *iMan, CEngine* engine) @@ -147,6 +147,10 @@ void CText::FlushCache() f->cache.clear(); } } + + m_lastFontType = FONT_COLOBOT; + m_lastFontSize = 0; + m_lastCachedFont = nullptr; } void CText::DrawText(const std::string &text, std::map &format, @@ -723,8 +727,8 @@ void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::P CachedFont* CText::GetOrOpenFont(FontType font, float size) { - // TODO: sizing - int pointSize = static_cast(size); + Math::IntPoint windowSize = m_engine->GetWindowSize(); + int pointSize = static_cast(size * (windowSize.Length() / REFERENCE_SIZE.Length())); if (m_lastCachedFont != nullptr) { diff --git a/src/math/intpoint.h b/src/math/intpoint.h index ebd9c5e..010b0fb 100644 --- a/src/math/intpoint.h +++ b/src/math/intpoint.h @@ -21,6 +21,7 @@ #pragma once +#include // Math module namespace namespace Math { @@ -49,6 +50,11 @@ struct IntPoint { return !operator==(p); } + + inline float Length() const + { + return sqrtf(x*x + y*y); + } }; -- cgit v1.2.3-1-g7c22 From fff9d235e49f5957e6d84b4774ca42c1a6cbcd35 Mon Sep 17 00:00:00 2001 From: erihel Date: Fri, 4 Jan 2013 21:44:16 +0100 Subject: * Fixed problem with freeing buffers while conneted to a source resulting with "Unable to unload buffer message" * Fixed posible segfault while trying to play sound after not loading file properly --- src/sound/oalsound/alsound.cpp | 20 +++++++++++++++----- src/sound/oalsound/channel.cpp | 35 ++++++++++++++++++++++++++++------- src/sound/oalsound/channel.h | 1 + src/sound/sound.h | 1 + 4 files changed, 45 insertions(+), 12 deletions(-) diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp index f683a62..b8dbcda 100644 --- a/src/sound/oalsound/alsound.cpp +++ b/src/sound/oalsound/alsound.cpp @@ -49,9 +49,14 @@ void ALSound::CleanUp() if (mEnabled) { GetLogger()->Info("Unloading files and closing device...\n"); StopAll(); + + for (auto channel : mChannels) { + delete channel.second; + } - for (auto item : mSounds) + for (auto item : mSounds) { delete item.second; + } mEnabled = false; alutExit(); @@ -213,7 +218,7 @@ bool ALSound::SearchFreeBuffer(Sound sound, int &channel, bool &bAlreadyLoaded) it.second->SetPriority(priority); channel = it.first; - bAlreadyLoaded = true; + bAlreadyLoaded = it.second->IsLoaded(); return true; } @@ -296,15 +301,20 @@ int ALSound::Play(Sound sound, Math::Vector pos, float amplitude, float frequenc GetLogger()->Warn("Sound %d was not loaded!\n", sound); return -1; } - + GetLogger()->Trace("ALSound::Play sound: %d volume: %f frequency: %f\n", sound, amplitude, frequency); int channel; bool bAlreadyLoaded; if (!SearchFreeBuffer(sound, channel, bAlreadyLoaded)) return -1; - if ( !bAlreadyLoaded ) { - mChannels[channel]->SetBuffer(mSounds[sound]); + + bAlreadyLoaded = false; + if (!bAlreadyLoaded) { + if (!mChannels[channel]->SetBuffer(mSounds[sound])) { + GetLogger()->Trace("ALSound::Play SetBuffer failed\n"); + return -1; + } } Position(channel, pos); diff --git a/src/sound/oalsound/channel.cpp b/src/sound/oalsound/channel.cpp index 7d8244b..e1bf202 100644 --- a/src/sound/oalsound/channel.cpp +++ b/src/sound/oalsound/channel.cpp @@ -36,6 +36,7 @@ Channel::Channel() { Channel::~Channel() { if (mReady) { + alSourceStop(mSource); alSourcei(mSource, AL_BUFFER, 0); alDeleteSources(1, &mSource); if (alCheck()) @@ -45,7 +46,7 @@ Channel::~Channel() { bool Channel::Play() { - if (!mReady) + if (!mReady || mBuffer == nullptr) return false; alSourcePlay(mSource); @@ -56,7 +57,7 @@ bool Channel::Play() { bool Channel::SetPosition(Math::Vector pos) { - if (!mReady) + if (!mReady || mBuffer == nullptr) return false; alSource3f(mSource, AL_POSITION, pos.x, pos.y, pos.z); @@ -70,7 +71,7 @@ bool Channel::SetPosition(Math::Vector pos) { bool Channel::SetFrequency(float freq) { - if (!mReady) + if (!mReady || mBuffer == nullptr) return false; alSourcef(mSource, AL_PITCH, freq); @@ -85,7 +86,7 @@ bool Channel::SetFrequency(float freq) float Channel::GetFrequency() { ALfloat freq; - if (!mReady) + if (!mReady || mBuffer == nullptr) return 0; alGetSourcef(mSource, AL_PITCH, &freq); @@ -100,7 +101,7 @@ float Channel::GetFrequency() bool Channel::SetVolume(float vol) { - if (!mReady || vol < 0) + if (!mReady || vol < 0 || mBuffer == nullptr) return false; alSourcef(mSource, AL_GAIN, vol / MAXVOLUME); @@ -115,7 +116,7 @@ bool Channel::SetVolume(float vol) float Channel::GetVolume() { ALfloat vol; - if (!mReady) + if (!mReady || mBuffer == nullptr) return 0; alGetSourcef(mSource, AL_GAIN, &vol); @@ -201,6 +202,9 @@ void Channel::ResetOper() Sound Channel::GetSoundType() { + if (!mReady || mBuffer == nullptr) + return SOUND_NONE; + return mBuffer->GetSoundType(); } @@ -233,7 +237,8 @@ void Channel::AdjustVolume(float volume) { bool Channel::IsPlaying() { ALint status; - if (!mReady) return false; + if (!mReady || mBuffer == nullptr) + return false; alGetSourcei(mSource, AL_SOURCE_STATE, &status); if (alCheck()) { @@ -249,8 +254,15 @@ bool Channel::IsReady() { return mReady; } +bool Channel::IsLoaded() { + return mBuffer == nullptr; +} + bool Channel::Stop() { + if (!mReady || mBuffer == nullptr) + return false; + alSourceStop(mSource); if (alCheck()) { GetLogger()->Warn("Could not stop sound. Code: %d\n", alGetCode()); @@ -262,6 +274,9 @@ bool Channel::Stop() { float Channel::GetCurrentTime() { + if (!mReady || mBuffer == nullptr) + return 0.0f; + ALfloat current; alGetSourcef(mSource, AL_SEC_OFFSET, ¤t); if (alCheck()) { @@ -274,6 +289,9 @@ float Channel::GetCurrentTime() void Channel::SetCurrentTime(float current) { + if (!mReady || mBuffer == nullptr) + return; + alSourcef(mSource, AL_SEC_OFFSET, current); if (alCheck()) GetLogger()->Warn("Could not get source current play time. Code: %d\n", alGetCode()); @@ -282,6 +300,9 @@ void Channel::SetCurrentTime(float current) float Channel::GetDuration() { + if (!mReady || mBuffer == nullptr) + return 0.0f; + return mBuffer->GetDuration(); } diff --git a/src/sound/oalsound/channel.h b/src/sound/oalsound/channel.h index 165ff50..5caf2b0 100644 --- a/src/sound/oalsound/channel.h +++ b/src/sound/oalsound/channel.h @@ -60,6 +60,7 @@ class Channel float GetVolume(); bool IsPlaying(); bool IsReady(); + bool IsLoaded(); bool SetBuffer(Buffer *); bool HasEnvelope(); diff --git a/src/sound/sound.h b/src/sound/sound.h index 518e2ad..a09c587 100644 --- a/src/sound/sound.h +++ b/src/sound/sound.h @@ -47,6 +47,7 @@ **/ enum Sound { + SOUND_NONE = -1, SOUND_CLICK = 0, SOUND_BOUM = 1, SOUND_EXPLO = 2, -- cgit v1.2.3-1-g7c22 From 8818a8e5db86f140230d789427373e1771747f5d Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sat, 5 Jan 2013 23:03:06 +0100 Subject: Corrected OpenGL extension detection - corrected multitexture and VBO detection - GLEW is now a required library - minor CMakeLists refactoring --- CMakeLists.txt | 46 +++------ src/CMakeLists.txt | 45 ++++----- src/app/app.cpp | 1 - src/common/config.h.cmake | 1 - src/graphics/core/device.h | 5 +- src/graphics/opengl/gldevice.cpp | 204 +++++++++++++++++++++------------------ src/graphics/opengl/gldevice.h | 6 +- 7 files changed, 146 insertions(+), 162 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 399ae96..4fc91c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,14 +20,14 @@ set(COLOBOT_VERSION_UNRELEASED "~pre-alpha") # Append git characteristics to version if(DEFINED COLOBOT_VERSION_UNRELEASED AND EXISTS "${CMAKE_SOURCE_DIR}/.git") - find_package(Git) - execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD - OUTPUT_VARIABLE GIT_BRANCH - OUTPUT_STRIP_TRAILING_WHITESPACE) - execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD - OUTPUT_VARIABLE GIT_REVISION - OUTPUT_STRIP_TRAILING_WHITESPACE) - set(COLOBOT_VERSION_UNRELEASED "${COLOBOT_VERSION_UNRELEASED}-git-${GIT_BRANCH}~r${GIT_REVISION}") + find_package(Git) + execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD + OUTPUT_VARIABLE GIT_BRANCH + OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD + OUTPUT_VARIABLE GIT_REVISION + OUTPUT_STRIP_TRAILING_WHITESPACE) + set(COLOBOT_VERSION_UNRELEASED "${COLOBOT_VERSION_UNRELEASED}-git-${GIT_BRANCH}~r${GIT_REVISION}") endif() set(COLOBOT_VERSION_FULL "${COLOBOT_VERSION_MAJOR}.${COLOBOT_VERSION_MINOR}.${COLOBOT_VERSION_REVISION}${COLOBOT_VERSION_UNRELEASED}") @@ -67,6 +67,7 @@ option(INSTALL_DOCS "Install Doxygen-generated documentation" OFF) # Build openal sound support option(OPENAL_SOUND "Build openal sound support" OFF) + ## # Required packages ## @@ -85,17 +86,11 @@ set(Boost_USE_STATIC_RUNTIME OFF) set(Boost_ADDITIONALVERSION "1.51" "1.51.0") find_package(Boost COMPONENTS system filesystem regex REQUIRED) -# GLEW requirement depends on platform -# By default it is auto detected -# This setting may be used to override -# Possible values: -# - auto -> determine automatically -# - 1 -> always enable -# - 0 -> always disable -set(USE_GLEW auto) # This is useful on Windows, if linking against standard GLEW dll fails option(GLEW_STATIC "Link statically with GLEW" OFF) +find_package(GLEW REQUIRED) + ## # Additional settings to use when cross-compiling with MXE (http://mxe.cc/) @@ -113,38 +108,19 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") set(PLATFORM_WINDOWS 1) set(PLATFORM_LINUX 0) set(PLATFORM_OTHER 0) - - # On Windows, GLEW is required - if (${USE_GLEW} MATCHES "auto") - set(USE_GLEW 1) - endif() elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") message(STATUS "Linux system detected") set(PLATFORM_WINDOWS 0) set(PLATFORM_LINUX 1) set(PLATFORM_OTHER 0) - - # On Linux, we should be fine without GLEW - if (${USE_GLEW} MATCHES "auto") - set(USE_GLEW 0) - endif() else() message(STATUS "Other system detected") set(PLATFORM_WINDOWS 0) set(PLATFORM_LINUX 0) set(PLATFORM_OTHER 1) - - # Use GLEW to be safe - if (${USE_GLEW} MATCHES "auto") - set(USE_GLEW 1) - endif() endif() -if(${USE_GLEW}) - find_package(GLEW REQUIRED) -endif() - if(NOT ${ASSERTS}) add_definitions(-DNDEBUG) endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index abd4a95..c00d347 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,32 +19,24 @@ endif() # Optional libraries set(OPTIONAL_LIBS "") -set(OPTIONAL_INCLUDE_DIRS "") - -if(${USE_GLEW} AND NOT ${MXE}) - set(OPTIONAL_LIBS ${OPTIONAL_LIBS} ${GLEW_LIBRARY}) - set(OPTIONAL_INCLUDE_DIRS ${OPTIONAL_INCLUDE_DIRS} ${GLEW_INCLUDE_PATH}) -endif() - - -# Additional libraries per platform -set(PLATFORM_LIBS "") -set(OPENAL_LIBS "") if (${OPENAL_SOUND}) if (${MXE}) - set(OPENAL_LIBS - ${CMAKE_FIND_ROOT_PATH}/lib/libOpenAL32.a - ${CMAKE_FIND_ROOT_PATH}/lib/libalut.a - ) + set(OPTIONAL_LIBS + ${CMAKE_FIND_ROOT_PATH}/lib/libOpenAL32.a + ${CMAKE_FIND_ROOT_PATH}/lib/libalut.a + ) else() - set(OPENAL_LIBS - openal - alut - ) + set(OPTIONAL_LIBS + openal + alut + ) endif() endif() +# Additional libraries per platform +set(PLATFORM_LIBS "") + if (${MXE}) # MXE requires special treatment set(PLATFORM_LIBS ${MXE_LIBS}) elseif (${PLATFORM_WINDOWS}) @@ -63,9 +55,9 @@ set(OPENAL_SRC "") if (${OPENAL_SOUND}) set(OPENAL_SRC - sound/oalsound/alsound.cpp - sound/oalsound/buffer.cpp - sound/oalsound/channel.cpp + sound/oalsound/alsound.cpp + sound/oalsound/buffer.cpp + sound/oalsound/channel.cpp ) endif() @@ -192,16 +184,16 @@ ${OPENAL_SRC} set(LIBS +CBot ${SDL_LIBRARY} ${SDLIMAGE_LIBRARY} ${SDLTTF_LIBRARY} ${OPENGL_LIBRARY} ${PNG_LIBRARIES} +${GLEW_LIBRARY} +${Boost_LIBRARIES} ${OPTIONAL_LIBS} ${PLATFORM_LIBS} -${Boost_LIBRARIES} -CBot -${OPENAL_LIBS} ) include_directories( @@ -212,8 +204,9 @@ ${SDL_INCLUDE_DIR} ${SDLIMAGE_INCLUDE_DIR} ${SDLTTF_INCLUDE_DIR} ${PNG_INCLUDE_DIRS} -${OPTIONAL_INCLUDE_DIRS} +${GLEW_INCLUDE_PATH} ${Boost_INCLUDE_DIRS} +${OPTIONAL_INCLUDE_DIRS} ) link_directories(${CMAKE_CURRENT_SOURCE_DIR}/CBot) diff --git a/src/app/app.cpp b/src/app/app.cpp index 4c66e24..7323e2d 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -264,7 +264,6 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) GetLogger()->Message("\n"); GetLogger()->Message("List of available options:\n"); GetLogger()->Message(" -help this help\n"); - GetLogger()->Message(" -vbo enable OpenGL VBOs\n"); GetLogger()->Message(" -datadir path set custom data directory path\n"); GetLogger()->Message(" -debug enable debug mode (more info printed in logs)\n"); GetLogger()->Message(" -loglevel level set log level to level (one of: trace, debug, info, warn, error, none)\n"); diff --git a/src/common/config.h.cmake b/src/common/config.h.cmake index 022bb69..1595e09 100644 --- a/src/common/config.h.cmake +++ b/src/common/config.h.cmake @@ -5,7 +5,6 @@ #cmakedefine PLATFORM_LINUX @PLATFORM_LINUX@ #cmakedefine PLATFORM_OTHER @PLATFORM_OTHER@ -#cmakedefine USE_GLEW @USE_GLEW@ #cmakedefine GLEW_STATIC #define COLOBOT_VERSION "@COLOBOT_VERSION_FULL@" diff --git a/src/graphics/core/device.h b/src/graphics/core/device.h index 618d21a..41d7796 100644 --- a/src/graphics/core/device.h +++ b/src/graphics/core/device.h @@ -104,8 +104,7 @@ enum RenderState RENDER_STATE_DEPTH_TEST, RENDER_STATE_DEPTH_WRITE, RENDER_STATE_ALPHA_TEST, - RENDER_STATE_CULLING, - RENDER_STATE_DITHERING + RENDER_STATE_CULLING }; /** @@ -287,7 +286,7 @@ public: virtual void DestroyAllTextures() = 0; //! Returns the maximum number of multitexture stages - virtual int GetMaxTextureCount() = 0; + virtual int GetMaxTextureStageCount() = 0; //! Sets the texture at given texture stage virtual void SetTexture(int index, const Texture &texture) = 0; //! Sets the texture image by ID at given texture stage diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index 9460e07..c535609 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -24,22 +24,9 @@ #include "math/geometry.h" -#if defined(USE_GLEW) - -// When using GLEW, only glew.h is needed +// Using GLEW so only glew.h is needed #include -#else - -// Should define prototypes of used extensions as OpenGL functions -#define GL_GLEXT_PROTOTYPES - -#include -#include -#include - -#endif // if defined(GLEW) - #include #include @@ -74,7 +61,8 @@ CGLDevice::CGLDevice(const GLDeviceConfig &config) m_config = config; m_lighting = false; m_lastVboId = 0; - m_useVbo = false; + m_multitextureAvailable = false; + m_vboAvailable = false; } @@ -93,7 +81,6 @@ bool CGLDevice::Create() { GetLogger()->Info("Creating CDevice\n"); -#if defined(USE_GLEW) static bool glewInited = false; if (!glewInited) @@ -106,26 +93,16 @@ bool CGLDevice::Create() return false; } - if ( (! GLEW_ARB_multitexture) || (! GLEW_EXT_texture_env_combine) ) - { - GetLogger()->Error("GLEW reports required extensions not supported\n"); - return false; - } + m_multitextureAvailable = glewIsSupported("GL_ARB_multitexture GL_ARB_texture_env_combine"); + if (!m_multitextureAvailable) + GetLogger()->Error("GLEW reports multitexturing not supported - graphics quality will be degraded!\n"); - if (GLEW_ARB_vertex_buffer_object) - { + m_vboAvailable = glewIsSupported("GL_ARB_vertex_buffer_object"); + if (m_vboAvailable) GetLogger()->Info("Detected ARB_vertex_buffer_object extension - using VBOs\n"); - m_useVbo = true; - } else - { GetLogger()->Info("No ARB_vertex_buffer_object extension present - using display lists\n"); - } } -#endif - - /* NOTE: when not using GLEW, extension testing is not performed, as it is assumed that - glext.h is up-to-date and the OpenGL shared library has the required functions present. */ // This is mostly done in all modern hardware by default // DirectX doesn't even allow the option to turn off perspective correction anymore @@ -135,6 +112,9 @@ bool CGLDevice::Create() // To avoid problems with scaling & lighting glEnable(GL_RESCALE_NORMAL); + // Minimal depth bias to avoid Z-fighting + SetDepthBias(0.001f); + // Set just to be sure glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glMatrixMode(GL_PROJECTION); @@ -186,14 +166,14 @@ void CGLDevice::ConfigChanged(const GLDeviceConfig& newConfig) Create(); } -void CGLDevice::SetUseVbo(bool useVbo) +void CGLDevice::SetUseVbo(bool vboAvailable) { - m_useVbo = useVbo; + m_vboAvailable = vboAvailable; } bool CGLDevice::GetUseVbo() { - return m_useVbo; + return m_vboAvailable; } void CGLDevice::BeginScene() @@ -610,7 +590,7 @@ void CGLDevice::DestroyAllTextures() m_allTextures.clear(); } -int CGLDevice::GetMaxTextureCount() +int CGLDevice::GetMaxTextureStageCount() { return m_currentTextures.size(); } @@ -621,17 +601,21 @@ int CGLDevice::GetMaxTextureCount() The setting is remembered, even if texturing is disabled at the moment. */ void CGLDevice::SetTexture(int index, const Texture &texture) { - assert(index >= 0); - assert(index < static_cast( m_currentTextures.size() )); + assert(index >= 0 && index < static_cast( m_currentTextures.size() )); bool same = m_currentTextures[index].id == texture.id; m_currentTextures[index] = texture; // remember the new value + if (!m_multitextureAvailable && index != 0) + return; + if (same) return; // nothing to do - glActiveTexture(GL_TEXTURE0 + index); + if (m_multitextureAvailable) + glActiveTexture(GL_TEXTURE0 + index); + glBindTexture(GL_TEXTURE_2D, texture.id); // Params need to be updated for the new bound texture @@ -640,15 +624,19 @@ void CGLDevice::SetTexture(int index, const Texture &texture) void CGLDevice::SetTexture(int index, unsigned int textureId) { - assert(index >= 0); - assert(index < static_cast( m_currentTextures.size() )); + assert(index >= 0 && index < static_cast( m_currentTextures.size() )); if (m_currentTextures[index].id == textureId) return; // nothing to do m_currentTextures[index].id = textureId; - glActiveTexture(GL_TEXTURE0 + index); + if (!m_multitextureAvailable && index != 0) + return; + + if (m_multitextureAvailable) + glActiveTexture(GL_TEXTURE0 + index); + glBindTexture(GL_TEXTURE_2D, textureId); // Params need to be updated for the new bound texture @@ -659,16 +647,14 @@ void CGLDevice::SetTexture(int index, unsigned int textureId) Returns the previously assigned texture or invalid texture if the given stage is not enabled. */ Texture CGLDevice::GetTexture(int index) { - assert(index >= 0); - assert(index < static_cast( m_currentTextures.size() )); + assert(index >= 0 && index < static_cast( m_currentTextures.size() )); return m_currentTextures[index]; } void CGLDevice::SetTextureEnabled(int index, bool enabled) { - assert(index >= 0); - assert(index < static_cast( m_currentTextures.size() )); + assert(index >= 0 && index < static_cast( m_currentTextures.size() )); bool same = m_texturesEnabled[index] == enabled; @@ -677,7 +663,12 @@ void CGLDevice::SetTextureEnabled(int index, bool enabled) if (same) return; // nothing to do - glActiveTexture(GL_TEXTURE0 + index); + if (!m_multitextureAvailable && index != 0) + return; + + if (m_multitextureAvailable) + glActiveTexture(GL_TEXTURE0 + index); + if (enabled) glEnable(GL_TEXTURE_2D); else @@ -686,8 +677,7 @@ void CGLDevice::SetTextureEnabled(int index, bool enabled) bool CGLDevice::GetTextureEnabled(int index) { - assert(index >= 0); - assert(index < static_cast( m_currentTextures.size() )); + assert(index >= 0 && index < static_cast( m_currentTextures.size() )); return m_texturesEnabled[index]; } @@ -698,17 +688,36 @@ bool CGLDevice::GetTextureEnabled(int index) The settings are remembered, even if texturing is disabled at the moment. */ void CGLDevice::SetTextureStageParams(int index, const TextureStageParams ¶ms) { - assert(index >= 0); - assert(index < static_cast( m_currentTextures.size() )); + assert(index >= 0 && index < static_cast( m_currentTextures.size() )); // Remember the settings m_textureStageParams[index] = params; + if (!m_multitextureAvailable && index != 0) + return; + // Don't actually do anything if texture not set if (! m_currentTextures[index].Valid()) return; - glActiveTexture(GL_TEXTURE0 + index); + if (m_multitextureAvailable) + glActiveTexture(GL_TEXTURE0 + index); + + if (params.wrapS == TEX_WRAP_CLAMP) + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + else if (params.wrapS == TEX_WRAP_REPEAT) + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + else assert(false); + + if (params.wrapT == TEX_WRAP_CLAMP) + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); + else if (params.wrapT == TEX_WRAP_REPEAT) + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + else assert(false); + + // Texture env setting is silly without multitexturing + if (!m_multitextureAvailable) + return; glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, params.factor.Array()); @@ -812,26 +821,12 @@ after_tex_color: glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_CONSTANT); else assert(false); - -after_tex_operations: - - if (params.wrapS == TEX_WRAP_CLAMP) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); - else if (params.wrapS == TEX_WRAP_REPEAT) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - else assert(false); - - if (params.wrapT == TEX_WRAP_CLAMP) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); - else if (params.wrapT == TEX_WRAP_REPEAT) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - else assert(false); +after_tex_operations: ; } void CGLDevice::SetTextureStageWrap(int index, TexWrapMode wrapS, TexWrapMode wrapT) { - assert(index >= 0); - assert(index < static_cast( m_currentTextures.size() )); + assert(index >= 0 && index < static_cast( m_currentTextures.size() )); // Remember the settings m_textureStageParams[index].wrapS = wrapS; @@ -841,7 +836,11 @@ void CGLDevice::SetTextureStageWrap(int index, TexWrapMode wrapS, TexWrapMode wr if (! m_currentTextures[index].Valid()) return; - glActiveTexture(GL_TEXTURE0 + index); + if (!m_multitextureAvailable && index != 0) + return; + + if (m_multitextureAvailable) + glActiveTexture(GL_TEXTURE0 + index); if (wrapS == TEX_WRAP_CLAMP) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); @@ -858,8 +857,7 @@ void CGLDevice::SetTextureStageWrap(int index, TexWrapMode wrapS, TexWrapMode wr TextureStageParams CGLDevice::GetTextureStageParams(int index) { - assert(index >= 0); - assert(index < static_cast( m_currentTextures.size() )); + assert(index >= 0 && index < static_cast( m_currentTextures.size() )); return m_textureStageParams[index]; } @@ -890,7 +888,9 @@ void CGLDevice::DrawPrimitive(PrimitiveType type, const Vertex *vertices, int ve glEnableClientState(GL_NORMAL_ARRAY); glNormalPointer(GL_FLOAT, sizeof(Vertex), reinterpret_cast(&vs[0].normal)); - glClientActiveTexture(GL_TEXTURE0); + if (m_multitextureAvailable) + glClientActiveTexture(GL_TEXTURE0); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), reinterpret_cast(&vs[0].texCoord)); @@ -914,13 +914,18 @@ void CGLDevice::DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, in glEnableClientState(GL_NORMAL_ARRAY); glNormalPointer(GL_FLOAT, sizeof(VertexTex2), reinterpret_cast(&vs[0].normal)); - glClientActiveTexture(GL_TEXTURE0); + if (m_multitextureAvailable) + glClientActiveTexture(GL_TEXTURE0); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, sizeof(VertexTex2), reinterpret_cast(&vs[0].texCoord)); - glClientActiveTexture(GL_TEXTURE1); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glTexCoordPointer(2, GL_FLOAT, sizeof(VertexTex2), reinterpret_cast(&vs[0].texCoord2)); + if (m_multitextureAvailable) + { + glClientActiveTexture(GL_TEXTURE1); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glTexCoordPointer(2, GL_FLOAT, sizeof(VertexTex2), reinterpret_cast(&vs[0].texCoord2)); + } glColor4fv(color.Array()); @@ -929,8 +934,11 @@ void CGLDevice::DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, in glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); // GL_TEXTURE1 - glClientActiveTexture(GL_TEXTURE0); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); + if (m_multitextureAvailable) + { + glClientActiveTexture(GL_TEXTURE0); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + } } void CGLDevice::DrawPrimitive(PrimitiveType type, const VertexCol *vertices, int vertexCount) @@ -952,7 +960,7 @@ void CGLDevice::DrawPrimitive(PrimitiveType type, const VertexCol *vertices, int unsigned int CGLDevice::CreateStaticBuffer(PrimitiveType primitiveType, const Vertex* vertices, int vertexCount) { unsigned int id = 0; - if (m_useVbo) + if (m_vboAvailable) { id = ++m_lastVboId; @@ -986,7 +994,7 @@ unsigned int CGLDevice::CreateStaticBuffer(PrimitiveType primitiveType, const Ve unsigned int CGLDevice::CreateStaticBuffer(PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount) { unsigned int id = 0; - if (m_useVbo) + if (m_vboAvailable) { id = ++m_lastVboId; @@ -1020,7 +1028,7 @@ unsigned int CGLDevice::CreateStaticBuffer(PrimitiveType primitiveType, const Ve unsigned int CGLDevice::CreateStaticBuffer(PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount) { unsigned int id = 0; - if (m_useVbo) + if (m_vboAvailable) { id = ++m_lastVboId; @@ -1053,7 +1061,7 @@ unsigned int CGLDevice::CreateStaticBuffer(PrimitiveType primitiveType, const Ve void CGLDevice::UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const Vertex* vertices, int vertexCount) { - if (m_useVbo) + if (m_vboAvailable) { auto it = m_vboObjects.find(bufferId); if (it == m_vboObjects.end()) @@ -1080,7 +1088,7 @@ void CGLDevice::UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiv void CGLDevice::UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount) { - if (m_useVbo) + if (m_vboAvailable) { auto it = m_vboObjects.find(bufferId); if (it == m_vboObjects.end()) @@ -1107,7 +1115,7 @@ void CGLDevice::UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiv void CGLDevice::UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount) { - if (m_useVbo) + if (m_vboAvailable) { auto it = m_vboObjects.find(bufferId); if (it == m_vboObjects.end()) @@ -1134,7 +1142,7 @@ void CGLDevice::UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiv void CGLDevice::DrawStaticBuffer(unsigned int bufferId) { - if (m_useVbo) + if (m_vboAvailable) { auto it = m_vboObjects.find(bufferId); if (it == m_vboObjects.end()) @@ -1151,7 +1159,9 @@ void CGLDevice::DrawStaticBuffer(unsigned int bufferId) glEnableClientState(GL_NORMAL_ARRAY); glNormalPointer(GL_FLOAT, sizeof(Vertex), static_cast(nullptr) + offsetof(Vertex, normal)); - glClientActiveTexture(GL_TEXTURE0); + if (m_multitextureAvailable) + glClientActiveTexture(GL_TEXTURE0); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), static_cast(nullptr) + offsetof(Vertex, texCoord)); } @@ -1163,13 +1173,18 @@ void CGLDevice::DrawStaticBuffer(unsigned int bufferId) glEnableClientState(GL_NORMAL_ARRAY); glNormalPointer(GL_FLOAT, sizeof(VertexTex2), static_cast(nullptr) + offsetof(VertexTex2, normal)); - glClientActiveTexture(GL_TEXTURE0); + if (m_multitextureAvailable) + glClientActiveTexture(GL_TEXTURE0); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, sizeof(VertexTex2), static_cast(nullptr) + offsetof(VertexTex2, texCoord)); - glClientActiveTexture(GL_TEXTURE1); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glTexCoordPointer(2, GL_FLOAT, sizeof(VertexTex2), static_cast(nullptr) + offsetof(VertexTex2, texCoord2)); + if (m_multitextureAvailable) + { + glClientActiveTexture(GL_TEXTURE1); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glTexCoordPointer(2, GL_FLOAT, sizeof(VertexTex2), static_cast(nullptr) + offsetof(VertexTex2, texCoord2)); + } } else if ((*it).second.vertexType == VERTEX_TYPE_COL) { @@ -1194,8 +1209,11 @@ void CGLDevice::DrawStaticBuffer(unsigned int bufferId) glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); // GL_TEXTURE1 - glClientActiveTexture(GL_TEXTURE0); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); + if (m_multitextureAvailable) + { + glClientActiveTexture(GL_TEXTURE0); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + } } else if ((*it).second.vertexType == VERTEX_TYPE_COL) { @@ -1214,7 +1232,7 @@ void CGLDevice::DrawStaticBuffer(unsigned int bufferId) void CGLDevice::DestroyStaticBuffer(unsigned int bufferId) { - if (m_useVbo) + if (m_vboAvailable) { auto it = m_vboObjects.find(bufferId); if (it == m_vboObjects.end()) @@ -1355,7 +1373,6 @@ void CGLDevice::SetRenderState(RenderState state, bool enabled) case RENDER_STATE_DEPTH_TEST: flag = GL_DEPTH_TEST; break; case RENDER_STATE_ALPHA_TEST: flag = GL_ALPHA_TEST; break; case RENDER_STATE_CULLING: flag = GL_CULL_FACE; break; - case RENDER_STATE_DITHERING: flag = GL_DITHER; break; default: assert(false); break; } @@ -1380,7 +1397,6 @@ bool CGLDevice::GetRenderState(RenderState state) case RENDER_STATE_DEPTH_TEST: flag = GL_DEPTH_TEST; break; case RENDER_STATE_ALPHA_TEST: flag = GL_ALPHA_TEST; break; case RENDER_STATE_CULLING: flag = GL_CULL_FACE; break; - case RENDER_STATE_DITHERING: flag = GL_DITHER; break; default: assert(false); break; } diff --git a/src/graphics/opengl/gldevice.h b/src/graphics/opengl/gldevice.h index dd43f2c..7137671 100644 --- a/src/graphics/opengl/gldevice.h +++ b/src/graphics/opengl/gldevice.h @@ -111,7 +111,7 @@ public: virtual void DestroyTexture(const Texture &texture); virtual void DestroyAllTextures(); - virtual int GetMaxTextureCount(); + virtual int GetMaxTextureStageCount(); virtual void SetTexture(int index, const Texture &texture); virtual void SetTexture(int index, unsigned int textureId); virtual Texture GetTexture(int index); @@ -229,8 +229,10 @@ private: int vertexCount; }; + //! Whether to use multitexturing + bool m_multitextureAvailable; //! Whether to use VBOs or display lists - bool m_useVbo; + bool m_vboAvailable; //! Map of saved VBO objects std::map m_vboObjects; //! Last ID of VBO object -- cgit v1.2.3-1-g7c22 From ff5c89085415a370911793d5764dfb694fc43b7d Mon Sep 17 00:00:00 2001 From: Marcin Zawadzki Date: Sat, 5 Jan 2013 23:03:26 +0100 Subject: Small fix in detecting language. Fixes needed to compile code using clang --- CMakeLists.txt | 2 +- src/CBot/tests/CBot_console/CMakeLists.txt | 1 - src/app/app.cpp | 13 +++++++++++-- src/common/test/CMakeLists.txt | 1 - src/graphics/engine/test/CMakeLists.txt | 1 - src/graphics/opengl/test/CMakeLists.txt | 1 - src/math/test/CMakeLists.txt | 1 - src/ui/test/CMakeLists.txt | 1 - 8 files changed, 12 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 399ae96..5d0bbeb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,7 +48,7 @@ endif() # Global compile flags # These are specific to GCC/MinGW; for other compilers, change as necessary -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wold-style-cast -std=gnu++0x") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wold-style-cast -std=c++11") set(CMAKE_CXX_FLAGS_RELEASE "-O2") set(CMAKE_CXX_FLAGS_DEBUG "-g -O0") diff --git a/src/CBot/tests/CBot_console/CMakeLists.txt b/src/CBot/tests/CBot_console/CMakeLists.txt index 9f0f244..f76dedf 100644 --- a/src/CBot/tests/CBot_console/CMakeLists.txt +++ b/src/CBot/tests/CBot_console/CMakeLists.txt @@ -8,7 +8,6 @@ if(NOT CMAKE_BUILD_TYPE) endif(NOT CMAKE_BUILD_TYPE) # Global compile flags -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wold-style-cast -std=gnu++0x") set(CMAKE_CXX_FLAGS_RELEASE "-O2") set(CMAKE_CXX_FLAGS_DEBUG "-g -O0") diff --git a/src/app/app.cpp b/src/app/app.cpp index c936ac1..6930920 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -1472,7 +1472,16 @@ void CApplication::SetLanguage(Language language) if (locale.empty()) { char *envLang = getenv("LANGUAGE"); - if (strncmp(envLang,"en",2) == 0) + if (envLang == NULL) + { + envLang = getenv("LANG"); + } + if (envLang == NULL) + { + GetLogger()->Error("Failed to get language from environment, setting default language"); + m_language = LANGUAGE_ENGLISH; + } + else if (strncmp(envLang,"en",2) == 0) { m_language = LANGUAGE_ENGLISH; } @@ -1484,7 +1493,7 @@ void CApplication::SetLanguage(Language language) { m_language = LANGUAGE_FRENCH; } - else if (strncmp(envLang,"po",2) == 0) + else if (strncmp(envLang,"pl",2) == 0) { m_language = LANGUAGE_POLISH; } diff --git a/src/common/test/CMakeLists.txt b/src/common/test/CMakeLists.txt index 26a31c9..70dac1f 100644 --- a/src/common/test/CMakeLists.txt +++ b/src/common/test/CMakeLists.txt @@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 2.8) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE debug) endif(NOT CMAKE_BUILD_TYPE) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wold-style-cast -std=gnu++0x") set(CMAKE_CXX_FLAGS_DEBUG "-g -O0") include_directories( diff --git a/src/graphics/engine/test/CMakeLists.txt b/src/graphics/engine/test/CMakeLists.txt index 46509f4..c837ae5 100644 --- a/src/graphics/engine/test/CMakeLists.txt +++ b/src/graphics/engine/test/CMakeLists.txt @@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 2.8) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE debug) endif(NOT CMAKE_BUILD_TYPE) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wold-style-cast -std=gnu++0x") set(CMAKE_CXX_FLAGS_DEBUG "-g -O0") set(MODELFILE_TEST_SOURCES diff --git a/src/graphics/opengl/test/CMakeLists.txt b/src/graphics/opengl/test/CMakeLists.txt index 154fec8..79e0ba5 100644 --- a/src/graphics/opengl/test/CMakeLists.txt +++ b/src/graphics/opengl/test/CMakeLists.txt @@ -8,7 +8,6 @@ find_package(PNG REQUIRED) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE debug) endif(NOT CMAKE_BUILD_TYPE) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wold-style-cast -std=gnu++0x") set(CMAKE_CXX_FLAGS_DEBUG "-g -O0") set(ADD_LIBS "") diff --git a/src/math/test/CMakeLists.txt b/src/math/test/CMakeLists.txt index dae4018..e31260c 100644 --- a/src/math/test/CMakeLists.txt +++ b/src/math/test/CMakeLists.txt @@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 2.8) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE debug) endif(NOT CMAKE_BUILD_TYPE) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wold-style-cast -std=gnu++0x") set(CMAKE_CXX_FLAGS_DEBUG "-g -O0") include_directories( diff --git a/src/ui/test/CMakeLists.txt b/src/ui/test/CMakeLists.txt index e411067..c38d2bb 100644 --- a/src/ui/test/CMakeLists.txt +++ b/src/ui/test/CMakeLists.txt @@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 2.8) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE debug) endif(NOT CMAKE_BUILD_TYPE) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wold-style-cast -std=gnu++0x") set(CMAKE_CXX_FLAGS_DEBUG "-g -O0") include_directories( -- cgit v1.2.3-1-g7c22 From edb1c0cbd62bfe7c620d7c8399f49acb98994b85 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 6 Jan 2013 23:13:05 +0100 Subject: GLEW fix for some graphics drivers --- src/app/app.cpp | 2 -- src/graphics/opengl/gldevice.cpp | 8 ++++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index 7323e2d..faf4526 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -444,8 +444,6 @@ bool CApplication::CreateVideoSurface() // Use hardware surface if available if (videoInfo->hw_available) videoFlags |= SDL_HWSURFACE; - else - videoFlags |= SDL_SWSURFACE; // Enable hardware blit if available if (videoInfo->blit_hw) diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index c535609..80fa9a1 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -87,6 +87,8 @@ bool CGLDevice::Create() { glewInited = true; + glewExperimental = GL_TRUE; + if (glewInit() != GLEW_OK) { GetLogger()->Error("GLEW initialization failed\n"); @@ -95,7 +97,7 @@ bool CGLDevice::Create() m_multitextureAvailable = glewIsSupported("GL_ARB_multitexture GL_ARB_texture_env_combine"); if (!m_multitextureAvailable) - GetLogger()->Error("GLEW reports multitexturing not supported - graphics quality will be degraded!\n"); + GetLogger()->Warn("GLEW reports multitexturing not supported - graphics quality will be degraded!\n"); m_vboAvailable = glewIsSupported("GL_ARB_vertex_buffer_object"); if (m_vboAvailable) @@ -415,7 +417,9 @@ Texture CGLDevice::CreateTexture(ImageData *data, const TextureCreateParams &par result.size.y = data->surface->h; // Use & enable 1st texture stage - glActiveTexture(GL_TEXTURE0); + if (m_multitextureAvailable) + glActiveTexture(GL_TEXTURE0); + glEnable(GL_TEXTURE_2D); glGenTextures(1, &result.id); -- cgit v1.2.3-1-g7c22 From 1285712aa22382a1a0d943aa29b310ecf6ebd365 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Tue, 8 Jan 2013 22:12:09 +0100 Subject: CMakeLists enhancements - compiler detection (clang and gcc version check) - compile flags only for src/ subdir - system and local include paths - fix for clang compilation --- CMakeLists.txt | 25 +++++++++++++++++++++---- lib/gmock/CMakeLists.txt | 2 ++ src/CMakeLists.txt | 16 ++++++++++++++-- src/graphics/engine/modelmanager.cpp | 4 ++-- 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 339e633..7e19ba0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,10 +47,27 @@ if(NOT CMAKE_BUILD_TYPE) endif() # Global compile flags -# These are specific to GCC/MinGW; for other compilers, change as necessary -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wold-style-cast -std=c++11") -set(CMAKE_CXX_FLAGS_RELEASE "-O2") -set(CMAKE_CXX_FLAGS_DEBUG "-g -O0") +# These are specific to GCC/MinGW/clang; for other compilers, change as necessary +# The flags are used throughout src/ subdir +set(COLOBOT_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wold-style-cast -std=c++11") +set(COLOBOT_CXX_FLAGS_RELEASE "-O2") +set(COLOBOT_CXX_FLAGS_DEBUG "-g -O0") + +# Compiler detection +if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") + execute_process( + COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) + if (NOT (GCC_VERSION VERSION_GREATER 4.6 OR GCC_VERSION VERSION_EQUAL 4.6)) + message(FATAL_ERROR "${PROJECT_NAME} requires GCC 4.6 or greater.") + else() + message(STATUS "Detected GCC version 4.6+") + endif() +elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") + message(STATUS "Detected Clang compiler") +else() + message(FATAL_ERROR "Your C++ compiler doesn't seem to support C++11.\n" + "Supported compilers at this time are GCC 4.6+ and clang.") +endif() # Asserts can be enabled/disabled regardless of build type option(ASSERTS "Enable assert()s" ON) diff --git a/lib/gmock/CMakeLists.txt b/lib/gmock/CMakeLists.txt index 3fec0d3..e7ff803 100644 --- a/lib/gmock/CMakeLists.txt +++ b/lib/gmock/CMakeLists.txt @@ -1,5 +1,7 @@ cmake_minimum_required(VERSION 2.8) +set(CMAKE_CXX_FLAGS "${${ORIGINAL_CXX_FLAGS}}") + include_directories(. include ${GTEST_INCLUDE_DIR}) # gmock-all.cc includes all other sources diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c00d347..a90b735 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,7 +1,13 @@ -# CBot library is built separately +# Compile flags as defined in global CMakeLists +set(CMAKE_CXX_FLAGS ${COLOBOT_CXX_FLAGS}) +set(CMAKE_CXX_FLAGS_RELEASE ${COLOBOT_CXX_FLAGS_RELEASE}) +set(CMAKE_CXX_FLAGS_DEBUG ${COLOBOT_CXX_FLAGS_DEBUG}) + + +# Subdirectories + add_subdirectory(CBot) -# Tools directory is built separately add_subdirectory(tools) add_subdirectory(po) @@ -196,10 +202,16 @@ ${OPTIONAL_LIBS} ${PLATFORM_LIBS} ) +# Local include_directories( . .. ${CMAKE_CURRENT_BINARY_DIR} +) + +# System +include_directories( +SYSTEM ${SDL_INCLUDE_DIR} ${SDLIMAGE_INCLUDE_DIR} ${SDLTTF_INCLUDE_DIR} diff --git a/src/graphics/engine/modelmanager.cpp b/src/graphics/engine/modelmanager.cpp index afaa718..5b17769 100644 --- a/src/graphics/engine/modelmanager.cpp +++ b/src/graphics/engine/modelmanager.cpp @@ -8,9 +8,9 @@ #include -namespace Gfx { +template<> Gfx::CModelManager* CSingleton::mInstance = nullptr; -template<> CModelManager* CSingleton::mInstance = nullptr; +namespace Gfx { CModelManager::CModelManager(CEngine* engine) { -- cgit v1.2.3-1-g7c22 From cf722462438707871e53bd96235b767e77dce6d3 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Wed, 9 Jan 2013 21:55:34 +0100 Subject: Disabled travis e-mail notifications --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 660a2f5..6763668 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,3 +6,5 @@ before_install: - git submodule update --init --recursive - sudo apt-get update -qq - sudo apt-get install -qq --no-install-recommends libgl1-mesa-dev libsdl1.2-dev libsdl-image1.2-dev libsdl-ttf2.0-dev libpng12-dev libboost-dev libboost-system-dev libboost-filesystem-dev libboost-regex-dev google-mock libgtest-dev doxygen graphviz po4a librsvg2-bin +notifications: + email: false -- cgit v1.2.3-1-g7c22 From 983373f150f6b122e92f054fa1b8e1af60b21197 Mon Sep 17 00:00:00 2001 From: erihel Date: Wed, 9 Jan 2013 23:19:10 +0100 Subject: * Fixed pitch calculation (sound in cut scenes will work as well as robot tracks sound) * Fixed applying effects to sounds * Changed volume to range 0.0-1.0 except for values in UI --- src/sound/oalsound/alsound.cpp | 70 ++++++++++++++++++++---------------------- src/sound/oalsound/alsound.h | 4 +-- src/sound/oalsound/buffer.cpp | 4 +-- src/sound/oalsound/channel.cpp | 45 +++++++++++++++------------ src/sound/oalsound/channel.h | 7 +++-- src/sound/sound.h | 2 +- 6 files changed, 69 insertions(+), 63 deletions(-) diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp index b8dbcda..80e8fe6 100644 --- a/src/sound/oalsound/alsound.cpp +++ b/src/sound/oalsound/alsound.cpp @@ -20,14 +20,13 @@ #include "alsound.h" - #define MIN(a, b) (a > b ? b : a) ALSound::ALSound() { mEnabled = false; m3D = false; - mAudioVolume = MAXVOLUME; + mAudioVolume = 1.0f; mMute = false; auto pointer = CInstanceManager::GetInstancePointer(); if (pointer != nullptr) @@ -105,7 +104,7 @@ bool ALSound::GetSound3DCap() } -bool ALSound::RetEnable() +bool ALSound::GetEnable() { return mEnabled; } @@ -113,8 +112,8 @@ bool ALSound::RetEnable() void ALSound::SetAudioVolume(int volume) { - alListenerf(AL_GAIN, MIN(volume, MAXVOLUME) * 0.01f); - mAudioVolume = MIN(volume, MAXVOLUME); + alListenerf(AL_GAIN, MIN(static_cast(volume) / MAXVOLUME, 1.0f)); + mAudioVolume = MIN(static_cast(volume) / MAXVOLUME, 1.0f); } @@ -291,18 +290,14 @@ int ALSound::Play(Sound sound, float amplitude, float frequency, bool bLoop) int ALSound::Play(Sound sound, Math::Vector pos, float amplitude, float frequency, bool bLoop) { - if (!mEnabled) - return -1; - - if (mAudioVolume <= 0.0f) + if (!mEnabled) { return -1; + } if (mSounds.find(sound) == mSounds.end()) { GetLogger()->Warn("Sound %d was not loaded!\n", sound); return -1; } - - GetLogger()->Trace("ALSound::Play sound: %d volume: %f frequency: %f\n", sound, amplitude, frequency); int channel; bool bAlreadyLoaded; @@ -312,7 +307,7 @@ int ALSound::Play(Sound sound, Math::Vector pos, float amplitude, float frequenc bAlreadyLoaded = false; if (!bAlreadyLoaded) { if (!mChannels[channel]->SetBuffer(mSounds[sound])) { - GetLogger()->Trace("ALSound::Play SetBuffer failed\n"); + mChannels[channel]->SetBuffer(nullptr); return -1; } } @@ -320,12 +315,13 @@ int ALSound::Play(Sound sound, Math::Vector pos, float amplitude, float frequenc Position(channel, pos); // setting initial values - mChannels[channel]->SetStartAmplitude(mAudioVolume); + mChannels[channel]->SetStartAmplitude(amplitude); mChannels[channel]->SetStartFrequency(frequency); mChannels[channel]->SetChangeFrequency(1.0f); mChannels[channel]->ResetOper(); - mChannels[channel]->AdjustFrequency(frequency); - mChannels[channel]->AdjustVolume(amplitude * mAudioVolume); + mChannels[channel]->SetFrequency(frequency * mChannels[channel]->GetFrequency()); + mChannels[channel]->SetVolume(amplitude); + mChannels[channel]->SetLoop(bLoop); mChannels[channel]->Play(); return channel; } @@ -350,15 +346,16 @@ bool ALSound::AddEnvelope(int channel, float amplitude, float frequency, float t if (mChannels.find(channel) == mChannels.end()) { return false; } - + SoundOper op; op.finalAmplitude = amplitude; op.finalFrequency = frequency; op.totalTime = time; op.nextOper = oper; + op.currentTime = 0.0f; mChannels[channel]->AddOper(op); - return false; + return true; } @@ -438,7 +435,6 @@ bool ALSound::MuteAll(bool bMute) return true; } - void ALSound::FrameMove(float delta) { if (!mEnabled) @@ -447,36 +443,38 @@ void ALSound::FrameMove(float delta) float progress; float volume, frequency; for (auto it : mChannels) { - if (!it.second->IsPlaying()) + if (!it.second->IsPlaying()) { continue; + } if (!it.second->HasEnvelope()) continue; - - //it.second->GetEnvelope().currentTime += delta; - SoundOper oper = it.second->GetEnvelope(); - progress = it.second->GetCurrentTime() / oper.totalTime; + + SoundOper &oper = it.second->GetEnvelope(); + oper.currentTime += delta; + progress = oper.currentTime / oper.totalTime; progress = MIN(progress, 1.0f); // setting volume - volume = progress * abs(oper.finalAmplitude - it.second->GetStartAmplitude()); - it.second->AdjustVolume(volume * mAudioVolume); - - // setting frequency - frequency = progress * abs(oper.finalFrequency - it.second->GetStartFrequency()) * it.second->GetStartFrequency() * it.second->GetChangeFrequency(); + volume = progress * (oper.finalAmplitude - it.second->GetStartAmplitude()); + it.second->SetVolume(volume + it.second->GetStartAmplitude()); + + // setting frequency + frequency = progress * (oper.finalFrequency - it.second->GetStartFrequency()) * it.second->GetStartFrequency() * it.second->GetChangeFrequency() * it.second->GetInitFrequency(); it.second->AdjustFrequency(frequency); - if (it.second->GetEnvelope().totalTime <= it.second->GetCurrentTime()) { - + if (oper.totalTime <= oper.currentTime) { if (oper.nextOper == SOPER_LOOP) { - GetLogger()->Trace("ALSound::FrameMove oper: replay.\n"); - it.second->SetCurrentTime(0.0f); + oper.currentTime = 0.0f; it.second->Play(); } else { - GetLogger()->Trace("ALSound::FrameMove oper: next.\n"); - it.second->SetStartAmplitude(oper.finalAmplitude); - it.second->SetStartFrequency(oper.finalFrequency); - it.second->PopEnvelope(); + it.second->SetStartAmplitude(oper.finalAmplitude); + it.second->SetStartFrequency(oper.finalFrequency); + if (oper.nextOper == SOPER_STOP) { + it.second->Stop(); + } + + it.second->PopEnvelope(); } } } diff --git a/src/sound/oalsound/alsound.h b/src/sound/oalsound/alsound.h index 7d24ba6..7aeec90 100644 --- a/src/sound/oalsound/alsound.h +++ b/src/sound/oalsound/alsound.h @@ -42,7 +42,7 @@ class ALSound : public CSoundInterface bool Create(bool b3D); bool Cache(Sound, std::string); - bool RetEnable(); + bool GetEnable(); void SetSound3D(bool bMode); bool GetSound3D(); @@ -86,7 +86,7 @@ class ALSound : public CSoundInterface bool mEnabled; bool m3D; bool mMute; - int mAudioVolume; + float mAudioVolume; ALCdevice* audioDevice; ALCcontext* audioContext; std::map mSounds; diff --git a/src/sound/oalsound/buffer.cpp b/src/sound/oalsound/buffer.cpp index dbfdca2..27da848 100644 --- a/src/sound/oalsound/buffer.cpp +++ b/src/sound/oalsound/buffer.cpp @@ -20,7 +20,7 @@ Buffer::Buffer() { mLoaded = false; - mDuration = 0; + mDuration = 0.0f; } @@ -53,7 +53,7 @@ bool Buffer::LoadFromFile(std::string filename, Sound sound) { alGetBufferi(mBuffer, AL_CHANNELS, &channels); alGetBufferi(mBuffer, AL_FREQUENCY, &freq); - mDuration = static_cast(size) / channels / bits / 8 / static_cast(freq); + mDuration = static_cast(size) * 8 / channels / bits / static_cast(freq); mLoaded = true; return true; diff --git a/src/sound/oalsound/channel.cpp b/src/sound/oalsound/channel.cpp index e1bf202..4069313 100644 --- a/src/sound/oalsound/channel.cpp +++ b/src/sound/oalsound/channel.cpp @@ -18,6 +18,7 @@ #include "channel.h" +#define MIN(a, b) (a > b ? b : a) Channel::Channel() { alGenSources(1, &mSource); @@ -31,6 +32,8 @@ Channel::Channel() { mPriority = 0; mBuffer = nullptr; + mLoop = false; + mInitFrequency = 0.0f; } @@ -49,6 +52,7 @@ bool Channel::Play() { if (!mReady || mBuffer == nullptr) return false; + alSourcei(mSource, AL_LOOPING, static_cast(mLoop)); alSourcePlay(mSource); if (alCheck()) GetLogger()->Warn("Could not play audio sound source. Code: %d\n", alGetCode()); @@ -83,6 +87,15 @@ bool Channel::SetFrequency(float freq) } +bool Channel::AdjustFrequency(float freq) +{ + if (!mReady || mBuffer == nullptr) + return false; + + return SetFrequency(mInitFrequency - freq); +} + + float Channel::GetFrequency() { ALfloat freq; @@ -104,7 +117,7 @@ bool Channel::SetVolume(float vol) if (!mReady || vol < 0 || mBuffer == nullptr) return false; - alSourcef(mSource, AL_GAIN, vol / MAXVOLUME); + alSourcef(mSource, AL_GAIN, MIN(vol, 1.0f)); if (alCheck()) { GetLogger()->Warn("Could not set sound volume to '%f'. Code: %d\n", vol, alGetCode()); return false; @@ -125,7 +138,7 @@ float Channel::GetVolume() return 0; } - return vol * MAXVOLUME; + return vol; } @@ -144,6 +157,7 @@ void Channel::SetPriority(int pri) void Channel::SetStartAmplitude(float gain) { mStartAmplitude = gain; + SetVolume(mStartAmplitude); } @@ -159,12 +173,6 @@ void Channel::SetChangeFrequency(float freq) } -void Channel::SetInitFrequency(float freq) -{ - mInitFrequency = freq; -} - - float Channel::GetStartAmplitude() { return mStartAmplitude; @@ -213,8 +221,12 @@ bool Channel::SetBuffer(Buffer *buffer) { if (!mReady) return false; - assert(buffer); mBuffer = buffer; + if (buffer == nullptr) { + alSourcei(mSource, AL_BUFFER, 0); + return true; + } + alSourcei(mSource, AL_BUFFER, buffer->GetBuffer()); if (alCheck()) { GetLogger()->Warn("Could not set sound buffer. Code: %d\n", alGetCode()); @@ -225,16 +237,6 @@ bool Channel::SetBuffer(Buffer *buffer) { } -void Channel::AdjustFrequency(float freq) { - SetFrequency(freq * mInitFrequency); -} - - -void Channel::AdjustVolume(float volume) { - SetVolume(mStartAmplitude * volume); -} - - bool Channel::IsPlaying() { ALint status; if (!mReady || mBuffer == nullptr) @@ -323,3 +325,8 @@ void Channel::PopEnvelope() { mOper.pop_front(); } + + +void Channel::SetLoop(bool loop) { + mLoop = loop; +} \ No newline at end of file diff --git a/src/sound/oalsound/channel.h b/src/sound/oalsound/channel.h index 5caf2b0..70307ef 100644 --- a/src/sound/oalsound/channel.h +++ b/src/sound/oalsound/channel.h @@ -35,6 +35,7 @@ struct SoundOper float finalAmplitude; float finalFrequency; float totalTime; + float currentTime; SoundNext nextOper; }; @@ -51,6 +52,7 @@ class Channel bool SetFrequency(float); float GetFrequency(); + bool AdjustFrequency(float); float GetCurrentTime(); void SetCurrentTime(float); @@ -73,7 +75,6 @@ class Channel void SetStartAmplitude(float); void SetStartFrequency(float); void SetChangeFrequency(float); - void SetInitFrequency(float); float GetStartAmplitude(); float GetStartFrequency(); @@ -83,8 +84,7 @@ class Channel void AddOper(SoundOper); void ResetOper(); Sound GetSoundType(); - void AdjustFrequency(float); - void AdjustVolume(float); + void SetLoop(bool); private: Buffer *mBuffer; @@ -97,4 +97,5 @@ class Channel float mInitFrequency; std::deque mOper; bool mReady; + bool mLoop; }; diff --git a/src/sound/sound.h b/src/sound/sound.h index a09c587..c9ac349 100644 --- a/src/sound/sound.h +++ b/src/sound/sound.h @@ -37,7 +37,7 @@ /*! * Maximum possible audio volume */ -#define MAXVOLUME 100 +#define MAXVOLUME 100.0f /** -- cgit v1.2.3-1-g7c22 From 3c94a6987007b60355dedb9db5c7bdef48b28369 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Wed, 9 Jan 2013 23:41:18 +0100 Subject: Added GLEW to travis config --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6763668..9690ccf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,6 @@ script: cmake . -DCMAKE_VERBOSE_MAKEFILE=ON && make all doc test before_install: - git submodule update --init --recursive - sudo apt-get update -qq - - sudo apt-get install -qq --no-install-recommends libgl1-mesa-dev libsdl1.2-dev libsdl-image1.2-dev libsdl-ttf2.0-dev libpng12-dev libboost-dev libboost-system-dev libboost-filesystem-dev libboost-regex-dev google-mock libgtest-dev doxygen graphviz po4a librsvg2-bin + - sudo apt-get install -qq --no-install-recommends libgl1-mesa-dev libsdl1.2-dev libsdl-image1.2-dev libsdl-ttf2.0-dev libpng12-dev libglew-dev libboost-dev libboost-system-dev libboost-filesystem-dev libboost-regex-dev google-mock libgtest-dev doxygen graphviz po4a librsvg2-bin notifications: email: false -- cgit v1.2.3-1-g7c22 From 4444fde9d7dc8a4b060e97bac7235aba37de02dd Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Thu, 10 Jan 2013 09:48:15 +0100 Subject: Use correct C++11/C++0x flags depending on the used compiler See http://gcc.gnu.org/projects/cxx0x.html for details. --- CMakeLists.txt | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 674c627..2e309d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,29 +46,34 @@ if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE debug) endif() -# Global compile flags -# These are specific to GCC/MinGW/clang; for other compilers, change as necessary -# The flags are used throughout src/ subdir -set(COLOBOT_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wold-style-cast -std=c++11") -set(COLOBOT_CXX_FLAGS_RELEASE "-O2") -set(COLOBOT_CXX_FLAGS_DEBUG "-g -O0") - # Compiler detection if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") execute_process( COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) - if (NOT (GCC_VERSION VERSION_GREATER 4.6 OR GCC_VERSION VERSION_EQUAL 4.6)) - message(FATAL_ERROR "${PROJECT_NAME} requires GCC 4.6 or greater.") - else() + if (GCC_VERSION VERSION_GREATER 4.7 OR GCC_VERSION VERSION_EQUAL 4.7) + message(STATUS "Detected GCC version 4.7+") + set(CXX11_FLAGS "-std=c++11") + elseif (GCC_VERSION VERSION_GREATER 4.6 OR GCC_VERSION VERSION_EQUAL 4.6) message(STATUS "Detected GCC version 4.6+") + set(CXX11_FLAGS "-std=c++0x") + else() + message(FATAL_ERROR "${PROJECT_NAME} requires GCC 4.6 or greater.") endif() elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") message(STATUS "Detected Clang compiler") + set(CXX11_FLAGS "-std=c++11") else() message(FATAL_ERROR "Your C++ compiler doesn't seem to support C++11.\n" "Supported compilers at this time are GCC 4.6+ and clang.") endif() +# Global compile flags +# These are specific to GCC/MinGW/clang; for other compilers, change as necessary +# The flags are used throughout src/ subdir +set(COLOBOT_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wold-style-cast ${CXX11_FLAGS}") +set(COLOBOT_CXX_FLAGS_RELEASE "-O2") +set(COLOBOT_CXX_FLAGS_DEBUG "-g -O0") + # Asserts can be enabled/disabled regardless of build type option(ASSERTS "Enable assert()s" ON) -- cgit v1.2.3-1-g7c22 From d221233436063d83f920731c83582ca115c93b6d Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Thu, 10 Jan 2013 09:49:25 +0100 Subject: Enable clang build in travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 9690ccf..772f403 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: cpp compiler: - gcc + - clang script: cmake . -DCMAKE_VERBOSE_MAKEFILE=ON && make all doc test before_install: - git submodule update --init --recursive -- cgit v1.2.3-1-g7c22 From f7f4bd945ce20b26f13c4ea90feffa8e6ebf3038 Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Thu, 10 Jan 2013 10:36:46 +0100 Subject: In travis, do out-of-tree build --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 772f403..442ccdd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: cpp compiler: - gcc - clang -script: cmake . -DCMAKE_VERBOSE_MAKEFILE=ON && make all doc test +script: mkdir build; cd build; cmake .. -DCMAKE_VERBOSE_MAKEFILE=ON && make all doc test before_install: - git submodule update --init --recursive - sudo apt-get update -qq -- cgit v1.2.3-1-g7c22 From e39e802d8314042bc8126484a71cee3952360a59 Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Thu, 10 Jan 2013 10:37:16 +0100 Subject: Also test intallation --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 442ccdd..bb99d26 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: cpp compiler: - gcc - clang -script: mkdir build; cd build; cmake .. -DCMAKE_VERBOSE_MAKEFILE=ON && make all doc test +script: mkdir build; cd build; cmake .. -DCMAKE_VERBOSE_MAKEFILE=ON && make all doc test && DESTDIR=. make install before_install: - git submodule update --init --recursive - sudo apt-get update -qq -- cgit v1.2.3-1-g7c22 From 0f74cf96b784b59853e7fe44dc2c89d48785cf46 Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Thu, 10 Jan 2013 11:07:20 +0100 Subject: In travis, add boost backport from Mapnik to succeed clang build --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index bb99d26..96a7443 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ compiler: script: mkdir build; cd build; cmake .. -DCMAKE_VERBOSE_MAKEFILE=ON && make all doc test && DESTDIR=. make install before_install: - git submodule update --init --recursive + - sudo add-apt-repository ppa:mapnik/boost -y - sudo apt-get update -qq - sudo apt-get install -qq --no-install-recommends libgl1-mesa-dev libsdl1.2-dev libsdl-image1.2-dev libsdl-ttf2.0-dev libpng12-dev libglew-dev libboost-dev libboost-system-dev libboost-filesystem-dev libboost-regex-dev google-mock libgtest-dev doxygen graphviz po4a librsvg2-bin notifications: -- cgit v1.2.3-1-g7c22 From 58f35e44ae17a8d4c55b1b19696245666d3697d3 Mon Sep 17 00:00:00 2001 From: erihel Date: Mon, 14 Jan 2013 22:55:16 +0100 Subject: * Removed alut * Using libsndfile to load sounds and music * Added support for playing music files --- .gitignore | 5 ++ CMakeLists.txt | 2 + cmake/FindLibSndFile.cmake | 23 ++++++++ src/CMakeLists.txt | 8 ++- src/app/app.cpp | 11 +++- src/sound/oalsound/alsound.cpp | 123 ++++++++++++++++++++++++++++------------- src/sound/oalsound/alsound.h | 8 ++- src/sound/oalsound/buffer.cpp | 41 ++++++++++---- src/sound/oalsound/buffer.h | 5 +- src/sound/oalsound/channel.cpp | 35 +++++++++--- src/sound/oalsound/channel.h | 10 ++-- src/sound/sound.h | 15 +++++ src/ui/maindialog.cpp | 4 +- 13 files changed, 216 insertions(+), 74 deletions(-) create mode 100644 cmake/FindLibSndFile.cmake diff --git a/.gitignore b/.gitignore index bc2649c..0e9774c 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,8 @@ Makefile /Testing /CTestTestfile.cmake /src/CBot/tests/CBot_console/bin/ +.kdev4 +*.kdev4 +*.flv +*.mp4 + diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e309d2..eb067aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -113,6 +113,8 @@ option(GLEW_STATIC "Link statically with GLEW" OFF) find_package(GLEW REQUIRED) +include("${colobot_SOURCE_DIR}/cmake/FindLibSndFile.cmake") + ## # Additional settings to use when cross-compiling with MXE (http://mxe.cc/) diff --git a/cmake/FindLibSndFile.cmake b/cmake/FindLibSndFile.cmake new file mode 100644 index 0000000..8666c66 --- /dev/null +++ b/cmake/FindLibSndFile.cmake @@ -0,0 +1,23 @@ +# Base Io build system +# Written by Jeremy Tregunna +# +# Find libsndfile. + +FIND_PATH(LIBSNDFILE_INCLUDE_DIR sndfile.h) + +SET(LIBSNDFILE_NAMES ${LIBSNDFILE_NAMES} sndfile libsndfile) +FIND_LIBRARY(LIBSNDFILE_LIBRARY NAMES ${LIBSNDFILE_NAMES} PATH) + +IF(LIBSNDFILE_INCLUDE_DIR AND LIBSNDFILE_LIBRARY) + SET(LIBSNDFILE_FOUND TRUE) +ENDIF(LIBSNDFILE_INCLUDE_DIR AND LIBSNDFILE_LIBRARY) + +IF(LIBSNDFILE_FOUND) + IF(NOT LibSndFile_FIND_QUIETLY) + MESSAGE(STATUS "Found LibSndFile: ${LIBSNDFILE_LIBRARY}") + ENDIF (NOT LibSndFile_FIND_QUIETLY) +ELSE(LIBSNDFILE_FOUND) + IF(LibSndFile_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "Could not find sndfile") + ENDIF(LibSndFile_FIND_REQUIRED) +ENDIF (LIBSNDFILE_FOUND) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a90b735..69164dd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -30,12 +30,14 @@ if (${OPENAL_SOUND}) if (${MXE}) set(OPTIONAL_LIBS ${CMAKE_FIND_ROOT_PATH}/lib/libOpenAL32.a - ${CMAKE_FIND_ROOT_PATH}/lib/libalut.a + ) + elseif (${PLATFORM_WINDOWS}) + set(OPTIONAL_LIBS + OpenAL32 ) else() set(OPTIONAL_LIBS openal - alut ) endif() endif() @@ -200,6 +202,7 @@ ${GLEW_LIBRARY} ${Boost_LIBRARIES} ${OPTIONAL_LIBS} ${PLATFORM_LIBS} +${LIBSNDFILE_LIBRARY} ) # Local @@ -207,6 +210,7 @@ include_directories( . .. ${CMAKE_CURRENT_BINARY_DIR} +${LIBSNDFILE_INCLUDE_DIR} ) # System diff --git a/src/app/app.cpp b/src/app/app.cpp index 4a69655..9886b24 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -321,10 +321,17 @@ bool CApplication::Create() #endif m_sound->Create(true); - if (GetProfile().GetLocalProfileString("Resources", "Sound", path)) + if (GetProfile().GetLocalProfileString("Resources", "Sound", path)) { m_sound->CacheAll(path); - else + } else { m_sound->CacheAll(GetDataSubdirPath(DIR_SOUND)); + } + + if (GetProfile().GetLocalProfileString("Resources", "Music", path)) { + m_sound->AddMusicFiles(path); + } else { + m_sound->AddMusicFiles(GetDataSubdirPath(DIR_MUSIC)); + } } std::string standardInfoMessage = diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp index 80e8fe6..0228498 100644 --- a/src/sound/oalsound/alsound.cpp +++ b/src/sound/oalsound/alsound.cpp @@ -27,7 +27,9 @@ ALSound::ALSound() mEnabled = false; m3D = false; mAudioVolume = 1.0f; + mMusicVolume = 1.0f; mMute = false; + mCurrentMusic = new Channel(); auto pointer = CInstanceManager::GetInstancePointer(); if (pointer != nullptr) CInstanceManager::GetInstancePointer()->AddInstance(CLASS_SOUND, this); @@ -48,17 +50,21 @@ void ALSound::CleanUp() if (mEnabled) { GetLogger()->Info("Unloading files and closing device...\n"); StopAll(); - - for (auto channel : mChannels) { - delete channel.second; - } + + for (auto channel : mChannels) { + delete channel.second; + } for (auto item : mSounds) { delete item.second; - } + } mEnabled = false; - alutExit(); + + mCurrentMusic->FreeBuffer(); + delete mCurrentMusic; + alcDestroyContext(mContext); + alcCloseDevice(mDevice); } } @@ -71,13 +77,20 @@ bool ALSound::Create(bool b3D) return true; GetLogger()->Info("Opening audio device...\n"); - if (!alutInit(NULL, NULL)) { - ALenum error = alutGetError(); - GetLogger()->Error("Could not open audio device! Reason: %s\n", alutGetErrorString(error)); + mDevice = alcOpenDevice(NULL); + if (!mDevice) { + GetLogger()->Error("Could not open audio device!\n"); return false; } - GetLogger()->Info("Done.\n"); + mContext = alcCreateContext(mDevice, NULL); + if (!mContext) { + GetLogger()->Error("Could not create audio context!\n"); + return false; + } + alcMakeContextCurrent(mContext); + + GetLogger()->Info("Done.\n"); mEnabled = true; return true; } @@ -119,28 +132,26 @@ void ALSound::SetAudioVolume(int volume) int ALSound::GetAudioVolume() { - float volume; if ( !mEnabled ) return 0; - alGetListenerf(AL_GAIN, &volume); - return volume * MAXVOLUME; + return mAudioVolume * MAXVOLUME; } void ALSound::SetMusicVolume(int volume) { - // TODO stub! Add music support + alListenerf(AL_GAIN, MIN(static_cast(volume) / MAXVOLUME, 1.0f)); + mMusicVolume = MIN(static_cast(volume) / MAXVOLUME, 1.0f); } int ALSound::GetMusicVolume() { - // TODO stub! Add music support if ( !mEnabled ) - return 0; + return 0.0f; - return 0; + return mMusicVolume * MAXVOLUME; } @@ -242,8 +253,7 @@ bool ALSound::SearchFreeBuffer(Sound sound, int &channel, bool &bAlreadyLoaded) auto it = mChannels.end(); it--; int i = (*it).first; - while (++i) - { + while (++i) { if (mChannels.find(i) == mChannels.end()) { Channel *chn = new Channel(); // check if channel is ready to play music, if not destroy it and seek free one @@ -307,9 +317,9 @@ int ALSound::Play(Sound sound, Math::Vector pos, float amplitude, float frequenc bAlreadyLoaded = false; if (!bAlreadyLoaded) { if (!mChannels[channel]->SetBuffer(mSounds[sound])) { - mChannels[channel]->SetBuffer(nullptr); - return -1; - } + mChannels[channel]->SetBuffer(nullptr); + return -1; + } } Position(channel, pos); @@ -445,36 +455,36 @@ void ALSound::FrameMove(float delta) for (auto it : mChannels) { if (!it.second->IsPlaying()) { continue; - } + } if (!it.second->HasEnvelope()) continue; - + SoundOper &oper = it.second->GetEnvelope(); - oper.currentTime += delta; + oper.currentTime += delta; progress = oper.currentTime / oper.totalTime; progress = MIN(progress, 1.0f); // setting volume volume = progress * (oper.finalAmplitude - it.second->GetStartAmplitude()); it.second->SetVolume(volume + it.second->GetStartAmplitude()); - - // setting frequency + + // setting frequency frequency = progress * (oper.finalFrequency - it.second->GetStartFrequency()) * it.second->GetStartFrequency() * it.second->GetChangeFrequency() * it.second->GetInitFrequency(); it.second->AdjustFrequency(frequency); if (oper.totalTime <= oper.currentTime) { if (oper.nextOper == SOPER_LOOP) { - oper.currentTime = 0.0f; + oper.currentTime = 0.0f; it.second->Play(); } else { - it.second->SetStartAmplitude(oper.finalAmplitude); - it.second->SetStartFrequency(oper.finalFrequency); + it.second->SetStartAmplitude(oper.finalAmplitude); + it.second->SetStartFrequency(oper.finalFrequency); if (oper.nextOper == SOPER_STOP) { - it.second->Stop(); + it.second->Stop(); } - - it.second->PopEnvelope(); + + it.second->PopEnvelope(); } } } @@ -491,32 +501,67 @@ void ALSound::SetListener(Math::Vector eye, Math::Vector lookat) bool ALSound::PlayMusic(int rank, bool bRepeat) { - // TODO stub! Add music support + if (!mEnabled) { + return false; + } + + if (static_cast(mCurrentMusic->GetSoundType()) != rank) { + mCurrentMusic->FreeBuffer(); + + if (mMusic.find(rank) == mMusic.end()) { + GetLogger()->Info("Requested music %d was not found.\n", rank); + return false; + } + + Buffer *buffer = new Buffer(); + buffer->LoadFromFile(mMusic.at(rank), static_cast(rank)); + mCurrentMusic->SetBuffer(buffer); + } + + mCurrentMusic->SetVolume(mMusicVolume); + mCurrentMusic->SetLoop(bRepeat); + mCurrentMusic->Play(); + return true; } bool ALSound::RestartMusic() { - // TODO stub! Add music support + if (!mEnabled || !mCurrentMusic) { + return false; + } + + mCurrentMusic->Stop(); + mCurrentMusic->Play(); return true; } void ALSound::StopMusic() { - // TODO stub! Add music support + if (!mEnabled || !mCurrentMusic) { + return; + } + SuspendMusic(); } bool ALSound::IsPlayingMusic() { - // TODO stub! Add music support - return true; + if (!mEnabled || !mCurrentMusic) { + return false; + } + + return mCurrentMusic->IsPlaying(); } void ALSound::SuspendMusic() { - // TODO stub! Add music support + if (!mEnabled || !mCurrentMusic) { + return; + } + + mCurrentMusic->Stop(); } diff --git a/src/sound/oalsound/alsound.h b/src/sound/oalsound/alsound.h index 7aeec90..4651e04 100644 --- a/src/sound/oalsound/alsound.h +++ b/src/sound/oalsound/alsound.h @@ -22,7 +22,7 @@ #include #include -#include +#include #include "common/iman.h" #include "common/logger.h" @@ -87,8 +87,10 @@ class ALSound : public CSoundInterface bool m3D; bool mMute; float mAudioVolume; - ALCdevice* audioDevice; - ALCcontext* audioContext; + float mMusicVolume; + ALCdevice* mDevice; + ALCcontext* mContext; std::map mSounds; std::map mChannels; + Channel *mCurrentMusic; }; diff --git a/src/sound/oalsound/buffer.cpp b/src/sound/oalsound/buffer.cpp index 27da848..d76b24a 100644 --- a/src/sound/oalsound/buffer.cpp +++ b/src/sound/oalsound/buffer.cpp @@ -35,26 +35,43 @@ Buffer::~Buffer() { bool Buffer::LoadFromFile(std::string filename, Sound sound) { mSound = sound; - GetLogger()->Debug("Loading audio file: %s\n", filename.c_str()); - mBuffer = alutCreateBufferFromFile(filename.c_str()); - ALenum error = alutGetError(); - if (error) { - GetLogger()->Warn("Failed to load file. Reason: %s\n", alutGetErrorString(error)); + SF_INFO fileInfo; + SNDFILE *file = sf_open(filename.c_str(), SFM_READ, &fileInfo); + + GetLogger()->Trace(" channels %d\n", fileInfo.channels); + GetLogger()->Trace(" format %d\n", fileInfo.format); + GetLogger()->Trace(" frames %d\n", fileInfo.frames); + GetLogger()->Trace(" samplerate %d\n", fileInfo.samplerate); + GetLogger()->Trace(" sections %d\n", fileInfo.sections); + + if (!file) { + GetLogger()->Warn("Could not load file. Reason: %s\n", sf_strerror(file)); mLoaded = false; return false; } - ALint size, bits, channels, freq; - - alGetBufferi(mBuffer, AL_SIZE, &size); - alGetBufferi(mBuffer, AL_BITS, &bits); - alGetBufferi(mBuffer, AL_CHANNELS, &channels); - alGetBufferi(mBuffer, AL_FREQUENCY, &freq); + alGenBuffers(1, &mBuffer); + if (!mBuffer) { + GetLogger()->Warn("Could not create audio buffer\n"); + mLoaded = false; + sf_close(file); + return false; + } - mDuration = static_cast(size) * 8 / channels / bits / static_cast(freq); + // read chunks of 4096 samples + std::vector data; + std::array buffer; + data.reserve(fileInfo.frames); + size_t read = 0; + while ((read = sf_read_short(file, buffer.data(), buffer.size())) != 0) { + data.insert(data.end(), buffer.begin(), buffer.begin() + read); + } + sf_close(file); + alBufferData(mBuffer, fileInfo.channels == 1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16, &data.front(), data.size() * sizeof(uint16_t), fileInfo.samplerate); + mDuration = static_cast(fileInfo.frames) / fileInfo.samplerate; mLoaded = true; return true; } diff --git a/src/sound/oalsound/buffer.h b/src/sound/oalsound/buffer.h index 8c4a2d3..7286deb 100644 --- a/src/sound/oalsound/buffer.h +++ b/src/sound/oalsound/buffer.h @@ -19,8 +19,11 @@ #pragma once #include +#include +#include -#include +#include +#include #include "sound/sound.h" #include "common/logger.h" diff --git a/src/sound/oalsound/channel.cpp b/src/sound/oalsound/channel.cpp index 4069313..83420ea 100644 --- a/src/sound/oalsound/channel.cpp +++ b/src/sound/oalsound/channel.cpp @@ -34,12 +34,15 @@ Channel::Channel() { mBuffer = nullptr; mLoop = false; mInitFrequency = 0.0f; + mStartAmplitude = 0.0f; + mStartFrequency = 0.0f; + mChangeFrequency = 0.0f; } Channel::~Channel() { if (mReady) { - alSourceStop(mSource); + alSourceStop(mSource); alSourcei(mSource, AL_BUFFER, 0); alDeleteSources(1, &mSource); if (alCheck()) @@ -223,8 +226,8 @@ bool Channel::SetBuffer(Buffer *buffer) { mBuffer = buffer; if (buffer == nullptr) { - alSourcei(mSource, AL_BUFFER, 0); - return true; + alSourcei(mSource, AL_BUFFER, 0); + return true; } alSourcei(mSource, AL_BUFFER, buffer->GetBuffer()); @@ -237,10 +240,26 @@ bool Channel::SetBuffer(Buffer *buffer) { } +bool Channel::FreeBuffer() { + if (!mReady) + return false; + + if (!mBuffer) { + return false; + } + + alSourceStop(mSource); + alSourcei(mSource, AL_BUFFER, 0); + delete mBuffer; + mBuffer = nullptr; + return true; +} + + bool Channel::IsPlaying() { ALint status; if (!mReady || mBuffer == nullptr) - return false; + return false; alGetSourcei(mSource, AL_SOURCE_STATE, &status); if (alCheck()) { @@ -263,7 +282,7 @@ bool Channel::IsLoaded() { bool Channel::Stop() { if (!mReady || mBuffer == nullptr) - return false; + return false; alSourceStop(mSource); if (alCheck()) { @@ -277,7 +296,7 @@ bool Channel::Stop() { float Channel::GetCurrentTime() { if (!mReady || mBuffer == nullptr) - return 0.0f; + return 0.0f; ALfloat current; alGetSourcef(mSource, AL_SEC_OFFSET, ¤t); @@ -292,7 +311,7 @@ float Channel::GetCurrentTime() void Channel::SetCurrentTime(float current) { if (!mReady || mBuffer == nullptr) - return; + return; alSourcef(mSource, AL_SEC_OFFSET, current); if (alCheck()) @@ -303,7 +322,7 @@ void Channel::SetCurrentTime(float current) float Channel::GetDuration() { if (!mReady || mBuffer == nullptr) - return 0.0f; + return 0.0f; return mBuffer->GetDuration(); } diff --git a/src/sound/oalsound/channel.h b/src/sound/oalsound/channel.h index 70307ef..8965306 100644 --- a/src/sound/oalsound/channel.h +++ b/src/sound/oalsound/channel.h @@ -52,7 +52,7 @@ class Channel bool SetFrequency(float); float GetFrequency(); - bool AdjustFrequency(float); + bool AdjustFrequency(float); float GetCurrentTime(); void SetCurrentTime(float); @@ -62,9 +62,11 @@ class Channel float GetVolume(); bool IsPlaying(); bool IsReady(); - bool IsLoaded(); + bool IsLoaded(); bool SetBuffer(Buffer *); + bool FreeBuffer(); + bool HasEnvelope(); SoundOper& GetEnvelope(); void PopEnvelope(); @@ -84,7 +86,7 @@ class Channel void AddOper(SoundOper); void ResetOper(); Sound GetSoundType(); - void SetLoop(bool); + void SetLoop(bool); private: Buffer *mBuffer; @@ -97,5 +99,5 @@ class Channel float mInitFrequency; std::deque mOper; bool mReady; - bool mLoop; + bool mLoop; }; diff --git a/src/sound/sound.h b/src/sound/sound.h index c9ac349..d152f76 100644 --- a/src/sound/sound.h +++ b/src/sound/sound.h @@ -22,6 +22,7 @@ #pragma once +#include #include "math/vector.h" @@ -32,6 +33,7 @@ #include #include #include +#include /*! @@ -177,6 +179,16 @@ class CSoundInterface } }; + /** Function called to add all music files to list */ + inline void AddMusicFiles(std::string path) { + for ( int i = 1; i <= 12; i++ ) { + std::stringstream filename; + filename << path << "/music" << std::setfill('0') << std::setw(3) << i << ".ogg"; + if (boost::filesystem::exists(filename.str())) + mMusic[i] = filename.str(); + } + }; + /** Function called to cache sound effect file. * This function is called by plugin interface for each file. * \param bSound - id of a file, will be used to identify sound files @@ -328,5 +340,8 @@ class CSoundInterface * \return return true if music is playing */ inline virtual bool IsPlayingMusic() {return true;}; + + protected: + std::map mMusic; }; diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index bbba825..d19166e 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -5458,10 +5458,8 @@ void CMainDialog::ChangeSetupButtons() ps = static_cast(pw->SearchControl(EVENT_INTERFACE_VOLMUSIC)); if ( ps != 0 ) { - /* - TODO: midi volume value = ps->GetVisibleValue(); - m_sound->SetMidiVolume((int)value);*/ + m_sound->SetMusicVolume(static_cast(value)); } } -- cgit v1.2.3-1-g7c22 From 01c39c88f67a924e6f067efdb16a750f8e19ea92 Mon Sep 17 00:00:00 2001 From: erihel Date: Tue, 15 Jan 2013 22:52:37 +0100 Subject: * Cleaning player list before getting new one (entering user menu several times appended user to existing list) --- src/ui/maindialog.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index d19166e..cf451e5 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -4676,6 +4676,7 @@ void CMainDialog::UpdateSceneChap(int &chap) { j = 0; fs::directory_iterator dirIt(m_savegameDir), dirEndIt; + m_userList.clear(); BOOST_FOREACH (const fs::path & p, std::make_pair(dirIt, dirEndIt)) { -- cgit v1.2.3-1-g7c22 From 9f75a29e88da36edc301fc35f70d260a7b4e660d Mon Sep 17 00:00:00 2001 From: erihel Date: Wed, 16 Jan 2013 01:45:38 +0100 Subject: * Fixed sound pitch causing segfault * Sound support should now compile fine with MXE * Added cache for 3 music files to speedup loading * Updated howto --- CMakeLists.txt | 2 +- HOWTO-MXE.txt | 4 ++++ HOWTO.txt | 6 ++++-- cmake/mxe.cmake | 14 +++++++++++++ src/CMakeLists.txt | 14 ++++--------- src/sound/oalsound/alsound.cpp | 47 ++++++++++++++++++++++++++++++------------ src/sound/oalsound/alsound.h | 1 + src/sound/oalsound/channel.cpp | 7 ++++--- 8 files changed, 66 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index eb067aa..aa05134 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,7 +52,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) if (GCC_VERSION VERSION_GREATER 4.7 OR GCC_VERSION VERSION_EQUAL 4.7) message(STATUS "Detected GCC version 4.7+") - set(CXX11_FLAGS "-std=c++11") + set(CXX11_FLAGS "-std=gnu++11") elseif (GCC_VERSION VERSION_GREATER 4.6 OR GCC_VERSION VERSION_EQUAL 4.6) message(STATUS "Detected GCC version 4.6+") set(CXX11_FLAGS "-std=c++0x") diff --git a/HOWTO-MXE.txt b/HOWTO-MXE.txt index 67107bd..4467cd3 100644 --- a/HOWTO-MXE.txt +++ b/HOWTO-MXE.txt @@ -49,6 +49,10 @@ libraries and tools. xz zlib + for audio support: + openal + libsndfile + 4. Now `cd' to colobot directory. To cross-compile a CMake project, you have to specify a CMake toolchain file. MXE has such file in MXE's directory: usr/i686-pc-mingw32/share/cmake/mxe-conf.cmake diff --git a/HOWTO.txt b/HOWTO.txt index c547939..c7ba1a5 100644 --- a/HOWTO.txt +++ b/HOWTO.txt @@ -42,8 +42,10 @@ How to... $ cmake . $ make - Note: If you experience problems with OpenGL's extensions, install GLEW library and enable - it in compilation by setting USE_GLEW to 1 in CMakeLists.txt + Note #1: If you experience problems with OpenGL's extensions, install GLEW library and enable + it in compilation by setting USE_GLEW to 1 in CMakeLists.txt + + Note #2: For audio support you need libsndfile and openal. 1.3 Other platforms, compilers, etc. diff --git a/cmake/mxe.cmake b/cmake/mxe.cmake index 322ba4a..5502c1b 100644 --- a/cmake/mxe.cmake +++ b/cmake/mxe.cmake @@ -12,6 +12,19 @@ if((${CMAKE_CROSSCOMPILING}) AND (DEFINED MSYS)) # Because find package scripts are lame set(SDLTTF_INCLUDE_DIR ${CMAKE_FIND_ROOT_PATH}/include/SDL) set(SDLIMAGE_INCLUDE_DIR ${CMAKE_FIND_ROOT_PATH}/include/SDL) + + if (${OPENAL_SOUND}) + set(OPENAL_MXE_LIBS + ${CMAKE_FIND_ROOT_PATH}/lib/libFLAC.a + ${CMAKE_FIND_ROOT_PATH}/lib/libvorbis.a + ${CMAKE_FIND_ROOT_PATH}/lib/libvorbisenc.a + ${CMAKE_FIND_ROOT_PATH}/lib/libvorbisfile.a + ${CMAKE_FIND_ROOT_PATH}/lib/libogg.a + ${CMAKE_FIND_ROOT_PATH}/lib/libwsock32.a + ) + endif() + + set(MXE_CFLAGS "-DAL_LIBTYPE_STATIC") set(MXE_LIBS # For some reason, these have to be absolute paths ${CMAKE_FIND_ROOT_PATH}/lib/libintl.a @@ -23,6 +36,7 @@ if((${CMAKE_CROSSCOMPILING}) AND (DEFINED MSYS)) ${CMAKE_FIND_ROOT_PATH}/lib/libwinmm.a ${CMAKE_FIND_ROOT_PATH}/lib/libdxguid.a ${CMAKE_FIND_ROOT_PATH}/lib/libbz2.a + ${OPENAL_MXE_LIBS} ) else() set(MXE 0) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 69164dd..238b8ba 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,5 @@ # Compile flags as defined in global CMakeLists -set(CMAKE_CXX_FLAGS ${COLOBOT_CXX_FLAGS}) +set(CMAKE_CXX_FLAGS "${COLOBOT_CXX_FLAGS} ${MXE_CFLAGS}") set(CMAKE_CXX_FLAGS_RELEASE ${COLOBOT_CXX_FLAGS_RELEASE}) set(CMAKE_CXX_FLAGS_DEBUG ${COLOBOT_CXX_FLAGS_DEBUG}) @@ -27,11 +27,7 @@ endif() set(OPTIONAL_LIBS "") if (${OPENAL_SOUND}) - if (${MXE}) - set(OPTIONAL_LIBS - ${CMAKE_FIND_ROOT_PATH}/lib/libOpenAL32.a - ) - elseif (${PLATFORM_WINDOWS}) + if (${PLATFORM_WINDOWS}) set(OPTIONAL_LIBS OpenAL32 ) @@ -43,8 +39,6 @@ if (${OPENAL_SOUND}) endif() # Additional libraries per platform -set(PLATFORM_LIBS "") - if (${MXE}) # MXE requires special treatment set(PLATFORM_LIBS ${MXE_LIBS}) elseif (${PLATFORM_WINDOWS}) @@ -201,8 +195,8 @@ ${PNG_LIBRARIES} ${GLEW_LIBRARY} ${Boost_LIBRARIES} ${OPTIONAL_LIBS} -${PLATFORM_LIBS} ${LIBSNDFILE_LIBRARY} +${PLATFORM_LIBS} ) # Local @@ -210,7 +204,6 @@ include_directories( . .. ${CMAKE_CURRENT_BINARY_DIR} -${LIBSNDFILE_INCLUDE_DIR} ) # System @@ -223,6 +216,7 @@ ${PNG_INCLUDE_DIRS} ${GLEW_INCLUDE_PATH} ${Boost_INCLUDE_DIRS} ${OPTIONAL_INCLUDE_DIRS} +${LIBSNDFILE_INCLUDE_DIR} ) link_directories(${CMAKE_CURRENT_SOURCE_DIR}/CBot) diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp index 0228498..2e44eef 100644 --- a/src/sound/oalsound/alsound.cpp +++ b/src/sound/oalsound/alsound.cpp @@ -29,7 +29,7 @@ ALSound::ALSound() mAudioVolume = 1.0f; mMusicVolume = 1.0f; mMute = false; - mCurrentMusic = new Channel(); + mCurrentMusic = nullptr; auto pointer = CInstanceManager::GetInstancePointer(); if (pointer != nullptr) CInstanceManager::GetInstancePointer()->AddInstance(CLASS_SOUND, this); @@ -90,6 +90,7 @@ bool ALSound::Create(bool b3D) } alcMakeContextCurrent(mContext); + mCurrentMusic = new Channel(); GetLogger()->Info("Done.\n"); mEnabled = true; return true; @@ -125,8 +126,8 @@ bool ALSound::GetEnable() void ALSound::SetAudioVolume(int volume) { - alListenerf(AL_GAIN, MIN(static_cast(volume) / MAXVOLUME, 1.0f)); mAudioVolume = MIN(static_cast(volume) / MAXVOLUME, 1.0f); + alListenerf(AL_GAIN, mAudioVolume); } @@ -141,8 +142,10 @@ int ALSound::GetAudioVolume() void ALSound::SetMusicVolume(int volume) { - alListenerf(AL_GAIN, MIN(static_cast(volume) / MAXVOLUME, 1.0f)); mMusicVolume = MIN(static_cast(volume) / MAXVOLUME, 1.0f); + if (mCurrentMusic) { + mCurrentMusic->SetVolume(mMusicVolume); + } } @@ -310,29 +313,28 @@ int ALSound::Play(Sound sound, Math::Vector pos, float amplitude, float frequenc } int channel; - bool bAlreadyLoaded; + bool bAlreadyLoaded = false; if (!SearchFreeBuffer(sound, channel, bAlreadyLoaded)) return -1; - - bAlreadyLoaded = false; + if (!bAlreadyLoaded) { if (!mChannels[channel]->SetBuffer(mSounds[sound])) { mChannels[channel]->SetBuffer(nullptr); return -1; } } - Position(channel, pos); // setting initial values - mChannels[channel]->SetStartAmplitude(amplitude); + mChannels[channel]->SetStartAmplitude(amplitude * mAudioVolume); mChannels[channel]->SetStartFrequency(frequency); mChannels[channel]->SetChangeFrequency(1.0f); mChannels[channel]->ResetOper(); - mChannels[channel]->SetFrequency(frequency * mChannels[channel]->GetFrequency()); - mChannels[channel]->SetVolume(amplitude); + mChannels[channel]->SetFrequency(frequency); + mChannels[channel]->SetVolume(amplitude * mAudioVolume); mChannels[channel]->SetLoop(bLoop); mChannels[channel]->Play(); + return channel; } @@ -464,10 +466,10 @@ void ALSound::FrameMove(float delta) oper.currentTime += delta; progress = oper.currentTime / oper.totalTime; progress = MIN(progress, 1.0f); - + // setting volume volume = progress * (oper.finalAmplitude - it.second->GetStartAmplitude()); - it.second->SetVolume(volume + it.second->GetStartAmplitude()); + it.second->SetVolume((volume + it.second->GetStartAmplitude()) * mAudioVolume); // setting frequency frequency = progress * (oper.finalFrequency - it.second->GetStartFrequency()) * it.second->GetStartFrequency() * it.second->GetChangeFrequency() * it.second->GetInitFrequency(); @@ -506,7 +508,24 @@ bool ALSound::PlayMusic(int rank, bool bRepeat) } if (static_cast(mCurrentMusic->GetSoundType()) != rank) { - mCurrentMusic->FreeBuffer(); + // check if we have music in cache + for (auto music : mMusicCache) { + if (static_cast(music->GetSoundType()) == rank) { + GetLogger()->Debug("Music loaded from cache\n"); + mCurrentMusic->SetBuffer(music); + + mCurrentMusic->SetVolume(mMusicVolume); + mCurrentMusic->SetLoop(bRepeat); + mCurrentMusic->Play(); + return true; + } + } + + // we cache only 3 music files + if (mMusicCache.size() == 3) { + mCurrentMusic->FreeBuffer(); + mMusicCache.pop_back(); + } if (mMusic.find(rank) == mMusic.end()) { GetLogger()->Info("Requested music %d was not found.\n", rank); @@ -514,8 +533,10 @@ bool ALSound::PlayMusic(int rank, bool bRepeat) } Buffer *buffer = new Buffer(); + mMusicCache.push_front(buffer); buffer->LoadFromFile(mMusic.at(rank), static_cast(rank)); mCurrentMusic->SetBuffer(buffer); + mMusicCache[rank] = buffer; } mCurrentMusic->SetVolume(mMusicVolume); diff --git a/src/sound/oalsound/alsound.h b/src/sound/oalsound/alsound.h index 4651e04..530aa5e 100644 --- a/src/sound/oalsound/alsound.h +++ b/src/sound/oalsound/alsound.h @@ -92,5 +92,6 @@ class ALSound : public CSoundInterface ALCcontext* mContext; std::map mSounds; std::map mChannels; + std::deque mMusicCache; Channel *mCurrentMusic; }; diff --git a/src/sound/oalsound/channel.cpp b/src/sound/oalsound/channel.cpp index 83420ea..2b9af9b 100644 --- a/src/sound/oalsound/channel.cpp +++ b/src/sound/oalsound/channel.cpp @@ -54,7 +54,7 @@ Channel::~Channel() { bool Channel::Play() { if (!mReady || mBuffer == nullptr) return false; - + alSourcei(mSource, AL_LOOPING, static_cast(mLoop)); alSourcePlay(mSource); if (alCheck()) @@ -223,7 +223,8 @@ Sound Channel::GetSoundType() { bool Channel::SetBuffer(Buffer *buffer) { if (!mReady) return false; - + + Stop(); mBuffer = buffer; if (buffer == nullptr) { alSourcei(mSource, AL_BUFFER, 0); @@ -276,7 +277,7 @@ bool Channel::IsReady() { } bool Channel::IsLoaded() { - return mBuffer == nullptr; + return mBuffer != nullptr; } -- cgit v1.2.3-1-g7c22 From 4421430bae76f1aaabb44e8d9bbc785ec8af0ad3 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Thu, 17 Jan 2013 20:54:23 +0100 Subject: Fixed edit_test linking issue --- src/ui/test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/test/CMakeLists.txt b/src/ui/test/CMakeLists.txt index c38d2bb..452df43 100644 --- a/src/ui/test/CMakeLists.txt +++ b/src/ui/test/CMakeLists.txt @@ -31,6 +31,6 @@ add_executable(edit_test stubs/restext_stub.cpp stubs/robotmain_stub.cpp edit_test.cpp) -target_link_libraries(edit_test gtest gmock ${SDL_LIBRARY} ${SDLTTF_LIBRARY}) +target_link_libraries(edit_test gtest gmock ${SDL_LIBRARY} ${SDLTTF_LIBRARY} ${Boost_LIBRARIES}) add_test(edit_test ./edit_test) -- cgit v1.2.3-1-g7c22 From b50f9ae8b7efe9ae4b198a4f1072a384919c6c08 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Thu, 17 Jan 2013 20:54:35 +0100 Subject: Fixed some clang warnings --- src/common/test/image_test.cpp | 4 ++-- src/object/object.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/common/test/image_test.cpp b/src/common/test/image_test.cpp index a98c9cc..09ae4c6 100644 --- a/src/common/test/image_test.cpp +++ b/src/common/test/image_test.cpp @@ -19,7 +19,7 @@ int main(int argc, char *argv[]) if (! image.Load(argv[1])) { std::string err = image.GetError(); - printf("Error loading '%s': %s\n", err.c_str()); + printf("Error loading '%s': %s\n", argv[1], err.c_str()); return 1; } Gfx::Color color; @@ -49,7 +49,7 @@ int main(int argc, char *argv[]) if (! image.SavePNG(argv[2])) { std::string err = image.GetError(); - printf("Error saving PNG '%s': %s\n", err.c_str()); + printf("Error saving PNG '%s': %s\n", argv[2], err.c_str()); return 2; } diff --git a/src/object/object.cpp b/src/object/object.cpp index afa7815..9615866 100644 --- a/src/object/object.cpp +++ b/src/object/object.cpp @@ -6243,12 +6243,12 @@ void CObject::SetViewFromHere(Math::Vector &eye, float &dirH, float &dirV, void CObject::SetCharacter(Character* character) { - memcpy(&m_character, character, sizeof(m_character)); + memcpy(&m_character, character, sizeof(Character)); } void CObject::GetCharacter(Character* character) { - memcpy(character, &m_character, sizeof(character)); + memcpy(character, &m_character, sizeof(Character)); } Character* CObject::GetCharacter() -- cgit v1.2.3-1-g7c22 From b1360231ca5b446cdf63263e4e86727df73e3312 Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Sun, 20 Jan 2013 14:28:33 +0100 Subject: In manpage, correct first header to be 'NAME' not 'COLOBOT' --- src/desktop/colobot.pod | 2 +- src/desktop/po/colobot-desktop.pot | 4 ++-- src/desktop/po/fr.po | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/desktop/colobot.pod b/src/desktop/colobot.pod index 2fc3a00..ae67e72 100644 --- a/src/desktop/colobot.pod +++ b/src/desktop/colobot.pod @@ -1,6 +1,6 @@ =encoding utf8 -=head1 COLOBOT +=head1 NAME colobot - educational programming strategy game diff --git a/src/desktop/po/colobot-desktop.pot b/src/desktop/po/colobot-desktop.pot index 17e60c3..94eb85a 100644 --- a/src/desktop/po/colobot-desktop.pot +++ b/src/desktop/po/colobot-desktop.pot @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2012-12-27 10:59+0100\n" +"POT-Creation-Date: 2013-01-20 14:26+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -33,7 +33,7 @@ msgstr "" #. type: =head1 #: colobot.pod:3 -msgid "COLOBOT" +msgid "NAME" msgstr "" #. type: textblock diff --git a/src/desktop/po/fr.po b/src/desktop/po/fr.po index 4709d49..40fa9e1 100644 --- a/src/desktop/po/fr.po +++ b/src/desktop/po/fr.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2012-12-27 10:55+0100\n" +"POT-Creation-Date: 2013-01-20 14:26+0100\n" "PO-Revision-Date: 2012-12-27 11:00+0100\n" "Last-Translator: Didier Raboud \n" "Language-Team: none\n" @@ -33,8 +33,8 @@ msgstr "Colonise avec des roBots" #. type: =head1 #: colobot.pod:3 -msgid "COLOBOT" -msgstr "COLOBOT" +msgid "NAME" +msgstr "NOM" #. type: textblock #: colobot.pod:5 -- cgit v1.2.3-1-g7c22 From 0ef831429a1988d6c0b303854a03d31f780eaa88 Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Sun, 20 Jan 2013 15:15:55 +0100 Subject: In travis, add libsndfile-dev as build-dependency --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 96a7443..af27ea3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,6 @@ before_install: - git submodule update --init --recursive - sudo add-apt-repository ppa:mapnik/boost -y - sudo apt-get update -qq - - sudo apt-get install -qq --no-install-recommends libgl1-mesa-dev libsdl1.2-dev libsdl-image1.2-dev libsdl-ttf2.0-dev libpng12-dev libglew-dev libboost-dev libboost-system-dev libboost-filesystem-dev libboost-regex-dev google-mock libgtest-dev doxygen graphviz po4a librsvg2-bin + - sudo apt-get install -qq --no-install-recommends libgl1-mesa-dev libsdl1.2-dev libsdl-image1.2-dev libsdl-ttf2.0-dev libpng12-dev libglew-dev libboost-dev libboost-system-dev libboost-filesystem-dev libboost-regex-dev google-mock libgtest-dev doxygen graphviz po4a librsvg2-bin libsndfile-dev notifications: email: false -- cgit v1.2.3-1-g7c22 From 83a89fc3040bc4deffa83982b5709fe6fa8ec457 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sat, 26 Jan 2013 19:15:32 +0100 Subject: Updated blender script * now script can be installed as add-on * model rotation is upright --- tools/blender-scripts.py | 50 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/tools/blender-scripts.py b/tools/blender-scripts.py index ed515b4..53c9b5f 100644 --- a/tools/blender-scripts.py +++ b/tools/blender-scripts.py @@ -5,11 +5,26 @@ # Copyright (C) 2012, PPC (Polish Portal of Colobot) # +bl_info = { + "name": "Colobot Model Format (.txt)", + "author": "PPC (Polish Portal of Colobot)", + "version": (0, 0, 2), + "blender": (2, 6, 4), + "location": "File > Export > Colobot (.txt)", + "description": "Export Colobot Model Format (.txt)", + "warning": "", + "wiki_url": "http://colobot.info"\ + "", + "tracker_url": ""\ + "", + "category": "Import-Export"} + import bpy import struct import array import os import copy +import math FUZZY_TOLERANCE = 1e-5 @@ -38,7 +53,10 @@ class ColobotVertex: return 1 def __eq__(self, other): - return fuzzy_equal_v(self.coord, other.coord) and fuzzy_equal_v(self.normal, other.normal) and fuzzy_equal_v(self.t1, other.t1) and fuzzy_equal_v(self.t2, other.t2) + return (fuzzy_equal_v(self.coord, other.coord) and + fuzzy_equal_v(self.normal, other.normal) and + fuzzy_equal_v(self.t1, other.t1) and + fuzzy_equal_v(self.t2, other.t2)) class ColobotMaterial: """Material as saved in Colobot model file""" @@ -53,7 +71,11 @@ class ColobotMaterial: return 1 def __eq__(self, other): - return fuzzy_equal_v(self.diffuse, other.diffuse) and fuzzy_equal_v(self.ambient, other.ambient) and fuzzy_equal_v(self.specular, other.specular) and self.tex1 == other.tex1 and self.tex2 == other.tex2 + return (fuzzy_equal_v(self.diffuse, other.diffuse) and + fuzzy_equal_v(self.ambient, other.ambient) and + fuzzy_equal_v(self.specular, other.specular) and + self.tex1 == other.tex1 and + self.tex2 == other.tex2) class ColobotTriangle: """Triangle as saved in Colobot model file""" @@ -261,6 +283,7 @@ def read_colobot_model(filename): model.triangles.append(t) + return model def mesh_to_colobot_model(mesh, scene, defaults): @@ -469,8 +492,15 @@ class ExportColobot(bpy.types.Operator): 'max': self.DEFAULT_MAX, 'state': self.DEFAULT_STATE } try: + obj = context.object + temp_ROT = obj.rotation_euler + temp_ROT[0] = temp_ROT[0] + math.radians(270) + obj.rotation_euler = temp_ROT model = mesh_to_colobot_model(context.object, context.scene, defaults) write_colobot_model(self.filepath, model) + temp_ROT = obj.rotation_euler + temp_ROT[0] = temp_ROT[0] + math.radians(90) + obj.rotation_euler = temp_ROT except ColobotError as e: self.report({'ERROR'}, e.args[0]) return {'FINISHED'} @@ -488,10 +518,6 @@ def export_menu_func(self, context): self.layout.operator_context = 'INVOKE_DEFAULT' self.layout.operator(ExportColobot.bl_idname, text="Colobot (Text Format)") -# Register and add to the file selector -bpy.utils.register_class(ExportColobot) -bpy.types.INFO_MT_file_export.append(export_menu_func) - class ImportColobot(bpy.types.Operator): @@ -510,6 +536,9 @@ class ImportColobot(bpy.types.Operator): model = read_colobot_model(self.filepath) mesh = colobot_model_to_mesh(model, 'ColobotMesh', os.path.dirname(self.filepath)) obj = bpy.data.objects.new('ColobotMesh', mesh) + temp_ROT = obj.rotation_euler + temp_ROT[0] = temp_ROT[0] + math.radians(90) + obj.rotation_euler = temp_ROT bpy.context.scene.objects.link(obj) bpy.context.scene.objects.active = obj obj.select = True @@ -530,6 +559,9 @@ def import_menu_func(self, context): self.layout.operator_context = 'INVOKE_DEFAULT' self.layout.operator(ImportColobot.bl_idname, text="Colobot (Text Format)") -# Register and add to the file selector -bpy.utils.register_class(ImportColobot) -bpy.types.INFO_MT_file_import.append(import_menu_func) + +def register(): + bpy.utils.register_module(__name__) + + bpy.types.INFO_MT_file_export.append(export_menu_func) + bpy.types.INFO_MT_file_import.append(import_menu_func) -- cgit v1.2.3-1-g7c22 From a937a7b6ec081ab546505e5ab1fcd9b3723a6f4b Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 27 Jan 2013 11:43:53 +0100 Subject: Changed model min/max to LOD levels --- HOWTO.txt | 10 +- data | 2 +- src/graphics/engine/engine.cpp | 199 +++++++++------------------- src/graphics/engine/engine.h | 41 +++--- src/graphics/engine/modelfile.cpp | 146 ++++++++++++-------- src/graphics/engine/modelfile.h | 35 +++-- src/graphics/engine/modelmanager.cpp | 24 +--- src/graphics/engine/pyro.cpp | 38 ++++-- src/graphics/engine/terrain.cpp | 13 +- src/graphics/engine/terrain.h | 2 +- src/graphics/engine/test/modelfile_test.cpp | 17 +-- src/object/auto/autoportico.cpp | 8 +- src/object/brain.cpp | 1 + src/object/motion/motionvehicle.cpp | 41 ++---- src/object/object.cpp | 42 +++--- src/tools/convert_model.cpp | 42 +++--- 16 files changed, 284 insertions(+), 377 deletions(-) diff --git a/HOWTO.txt b/HOWTO.txt index c7ba1a5..cd236c4 100644 --- a/HOWTO.txt +++ b/HOWTO.txt @@ -37,15 +37,12 @@ How to... Since you're running Linux, you probably know how to do this anyway ;) But just in case, here's what you need: - gcc compiler (with gcc-g++), cmake, libraries with header files: SDL, SDL_image, SDL_ttf, libpng, boost + gcc compiler (with gcc-g++), cmake, libraries with header files: GLEW, SDL, SDL_image, SDL_ttf, libpng, boost Instructions are the same: $ cmake . $ make - Note #1: If you experience problems with OpenGL's extensions, install GLEW library and enable - it in compilation by setting USE_GLEW to 1 in CMakeLists.txt - - Note #2: For audio support you need libsndfile and openal. + Note #1: For audio support you need libsndfile and openal. 1.3 Other platforms, compilers, etc. @@ -104,9 +101,6 @@ Jak... $ cmake . $ make - Uwaga: JeÅ›li natrafisz na problemy z rozszerzeniami OpenGL, zainstaluj bibliotekÄ™ GLEW i wÅ‚Ä…cz jÄ… - przy kompilacji, ustawiajÄ…c USE_GLEW na 1 w CMakeLists.txt - 1.3 Inne platformy, kompilatory, etc. Nie sprawdzaliÅ›my jeszcze innych platform, ale kod nie jest jakoÅ› specjalnie zwiÄ…zany z danym kompilatorem czy platformÄ…, wiÄ™c w teorii powinien zadziaÅ‚ać. diff --git a/data b/data index 5a991a7..5c27c5e 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 5a991a77eb5f476d29b4d4f976be48fdf74a053f +Subproject commit 5c27c5e1ebbd1398eeecbfb28abbb457442a549f diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 7c90a8d..71b5e7d 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -109,13 +109,9 @@ CEngine::CEngine(CInstanceManager *iMan, CApplication *app) m_lookatPt = Math::Vector(0.0f, 0.0f, 1.0f); m_drawWorld = true; m_drawFront = false; - m_limitLOD[0] = 100.0f; - m_limitLOD[1] = 200.0f; m_particleDensity = 1.0f; - m_clippingDistance = 1.0f; m_lastClippingDistance = m_clippingDistance = 1.0f; m_objectDetail = 1.0f; - m_lastObjectDetail = m_objectDetail; m_terrainVision = 1000.0f; m_gadgetQuantity = 1.0f; m_textureQuality = 1; @@ -130,7 +126,6 @@ CEngine::CEngine(CInstanceManager *iMan, CApplication *app) m_editIndentValue = 4; m_tracePrecision = 1.0f; - m_alphaMode = 1; m_updateGeometry = false; m_updateStaticBuffers = false; @@ -208,7 +203,7 @@ CText* CEngine::GetText() bool CEngine::Create() { - m_size = m_lastSize = m_app->GetVideoConfig().size; + m_size = m_app->GetVideoConfig().size; m_lightMan = new CLightManager(m_iMan, this); m_text = new CText(m_iMan, this); @@ -416,11 +411,6 @@ Math::IntPoint CEngine::GetWindowSize() return m_size; } -Math::IntPoint CEngine::GetLastWindowSize() -{ - return m_lastSize; -} - Math::Point CEngine::WindowToInterfaceCoords(Math::IntPoint pos) { return Math::Point( static_cast(pos.x) / static_cast(m_size.x), @@ -473,15 +463,15 @@ EngineBaseObjTexTier& CEngine::AddLevel2(EngineBaseObject& p1, const std::string return p1.next.back(); } -EngineBaseObjLODTier& CEngine::AddLevel3(EngineBaseObjTexTier& p2, float min, float max) +EngineBaseObjLODTier& CEngine::AddLevel3(EngineBaseObjTexTier& p2, LODLevel lodLevel) { for (int i = 0; i < static_cast( p2.next.size() ); i++) { - if ( (p2.next[i].min == min) && (p2.next[i].max == max) ) + if (p2.next[i].lodLevel == lodLevel) return p2.next[i]; } - p2.next.push_back(EngineBaseObjLODTier(min, max)); + p2.next.push_back(EngineBaseObjLODTier(lodLevel)); return p2.next.back(); } @@ -570,17 +560,13 @@ void CEngine::AddBaseObjTriangles(int baseObjRank, const std::vector EngineTriangleType triangleType, const Material& material, int state, std::string tex1Name, std::string tex2Name, - float min, float max, bool globalUpdate) + LODLevel lodLevel, bool globalUpdate) { assert(baseObjRank >= 0 && baseObjRank < static_cast( m_baseObjects.size() )); - m_lastSize = m_size; - m_lastObjectDetail = m_objectDetail; - m_lastClippingDistance = m_clippingDistance; - EngineBaseObject& p1 = m_baseObjects[baseObjRank]; EngineBaseObjTexTier& p2 = AddLevel2(p1, tex1Name, tex2Name); - EngineBaseObjLODTier& p3 = AddLevel3(p2, min, max); + EngineBaseObjLODTier& p3 = AddLevel3(p2, lodLevel); EngineBaseObjDataTier& p4 = AddLevel4(p3, triangleType, material, state); p4.vertices.insert(p4.vertices.end(), vertices.begin(), vertices.end()); @@ -615,13 +601,13 @@ void CEngine::AddBaseObjTriangles(int baseObjRank, const std::vector void CEngine::AddBaseObjQuick(int baseObjRank, const EngineBaseObjDataTier& buffer, std::string tex1Name, std::string tex2Name, - float min, float max, bool globalUpdate) + LODLevel lodLevel, bool globalUpdate) { assert(baseObjRank >= 0 && baseObjRank < static_cast( m_baseObjects.size() )); EngineBaseObject& p1 = m_baseObjects[baseObjRank]; EngineBaseObjTexTier& p2 = AddLevel2(p1, tex1Name, tex2Name); - EngineBaseObjLODTier& p3 = AddLevel3(p2, min, max); + EngineBaseObjLODTier& p3 = AddLevel3(p2, lodLevel); p3.next.push_back(buffer); @@ -797,7 +783,7 @@ int CEngine::GetObjectTotalTriangles(int objRank) EngineBaseObjDataTier* CEngine::FindTriangles(int objRank, const Material& material, int state, std::string tex1Name, - std::string tex2Name, float min, float max) + std::string tex2Name, int lodLevelMask) { assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); @@ -820,7 +806,7 @@ EngineBaseObjDataTier* CEngine::FindTriangles(int objRank, const Material& mater { EngineBaseObjLODTier& p3 = p2.next[l3]; - if (p3.min != min || p3.max != max) + if ((p3.lodLevel & lodLevelMask) == 0) continue; for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) @@ -839,7 +825,7 @@ EngineBaseObjDataTier* CEngine::FindTriangles(int objRank, const Material& mater return nullptr; } -int CEngine::GetPartialTriangles(int objRank, float min, float max, float percent, int maxCount, +int CEngine::GetPartialTriangles(int objRank, int lodLevelMask, float percent, int maxCount, std::vector& triangles) { assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); @@ -866,7 +852,7 @@ int CEngine::GetPartialTriangles(int objRank, float min, float max, float percen { EngineBaseObjLODTier& p3 = p2.next[l3]; - if (p3.min != min || p3.max != max) + if ((p3.lodLevel & lodLevelMask) == 0) continue; for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) @@ -928,68 +914,6 @@ int CEngine::GetPartialTriangles(int objRank, float min, float max, float percen return actualCount; } -void CEngine::ChangeLOD() -{ - float oldLimit[2] = - { - GetLimitLOD(0, true), - GetLimitLOD(1, true) - }; - - float newLimit[2] = - { - GetLimitLOD(0, false), - GetLimitLOD(1, false) - }; - - float oldTerrain = m_terrainVision * m_lastClippingDistance; - float newTerrain = m_terrainVision * m_clippingDistance; - - for (int baseObjRank = 0; baseObjRank < static_cast( m_baseObjects.size() ); baseObjRank++) - { - EngineBaseObject& p1 = m_baseObjects[baseObjRank]; - - if (! p1.used) - continue; - - for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) - { - EngineBaseObjTexTier& p2 = p1.next[l2]; - - for (int l3 = 0; l3 < static_cast( p2.next.size() ); l3++) - { - EngineBaseObjLODTier& p3 = p2.next[l3]; - - if ( Math::IsEqual(p3.min, 0.0f ) && - Math::IsEqual(p3.max, oldLimit[0]) ) - { - p3.max = newLimit[0]; - } - else if ( Math::IsEqual(p3.min, oldLimit[0]) && - Math::IsEqual(p3.max, oldLimit[1]) ) - { - p3.min = newLimit[0]; - p3.max = newLimit[1]; - } - else if ( Math::IsEqual(p3.min, oldLimit[1]) && - Math::IsEqual(p3.max, 1000000.0f ) ) - { - p3.min = newLimit[1]; - } - else if ( Math::IsEqual(p3.min, 0.0f ) && - Math::IsEqual(p3.max, oldTerrain) ) - { - p3.max = newTerrain; - } - } - } - } - - m_lastSize = m_size; - m_lastObjectDetail = m_objectDetail; - m_lastClippingDistance = m_clippingDistance; -} - void CEngine::ChangeSecondTexture(int objRank, const std::string& tex2Name) { assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); @@ -1016,12 +940,12 @@ void CEngine::ChangeSecondTexture(int objRank, const std::string& tex2Name) void CEngine::ChangeTextureMapping(int objRank, const Material& mat, int state, const std::string& tex1Name, const std::string& tex2Name, - float min, float max, EngineTextureMapping mode, + int lodLevelMask, EngineTextureMapping mode, float au, float bu, float av, float bv) { assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); - EngineBaseObjDataTier* p4 = FindTriangles(objRank, mat, state, tex1Name, tex2Name, min, max); + EngineBaseObjDataTier* p4 = FindTriangles(objRank, mat, state, tex1Name, tex2Name, lodLevelMask); if (p4 == nullptr) return; @@ -1078,12 +1002,12 @@ void CEngine::ChangeTextureMapping(int objRank, const Material& mat, int state, void CEngine::TrackTextureMapping(int objRank, const Material& mat, int state, const std::string& tex1Name, const std::string& tex2Name, - float min, float max, EngineTextureMapping mode, + int lodLevelMask, EngineTextureMapping mode, float pos, float factor, float tl, float ts, float tt) { assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); - EngineBaseObjDataTier* p4 = FindTriangles(objRank, mat, state, tex1Name, tex2Name, min, max); + EngineBaseObjDataTier* p4 = FindTriangles(objRank, mat, state, tex1Name, tex2Name, lodLevelMask); if (p4 == nullptr) return; @@ -1707,8 +1631,8 @@ int CEngine::DetectObject(Math::Point mouse) { EngineBaseObjLODTier& p3 = p2.next[l3]; - if (p3.min != 0.0f) - continue; // LOD B or C? + if (p3.lodLevel != LOD_Constant && p3.lodLevel != LOD_High) + continue; for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) { @@ -1820,6 +1744,43 @@ bool CEngine::IsVisible(int objRank) return false; } +bool CEngine::IsWithinLODLimit(float distance, LODLevel lodLevel) +{ + float min = 0.0f, max = 0.0f; + + if (lodLevel == LOD_Constant) + { + min = 0.0f; + max = m_terrainVision * m_clippingDistance; + } + else + { + if (lodLevel == LOD_High) + { + min = 0.0f; + max = 100.0f; + } + else if (lodLevel == LOD_Medium) + { + min = 100.0f; + max = 200.0f; + } + else if (lodLevel == LOD_Low) + { + min = 100.0f; + max = 1000000.0f; + } + + min *= m_size.x / 640.0f; + min *= m_objectDetail*2.0f; + + max *= m_size.x / 640.0f; + max *= m_objectDetail*2.0f; + } + + return distance >= min && distance < max; +} + bool CEngine::TransformPoint(Math::Vector& p2D, int objRank, Math::Vector p3D) { assert(objRank >= 0 && objRank < static_cast(m_objects.size())); @@ -1856,15 +1817,6 @@ void CEngine::SetState(int state, const Color& color) m_lastState = state; m_lastColor = color; - if (m_alphaMode != 1 && (state & ENG_RSTATE_ALPHA)) - { - state &= ~ENG_RSTATE_ALPHA; - - if (m_alphaMode == 2) - state |= ENG_RSTATE_TTEXTURE_BLACK; - } - - if (state & ENG_RSTATE_TTEXTURE_BLACK) // transparent black texture? { m_device->SetRenderState(RENDER_STATE_FOG, false); @@ -2447,33 +2399,6 @@ void CEngine::SetTexture(const Texture& tex, int stage) m_device->SetTexture(stage, tex); } -void CEngine::SetLimitLOD(int rank, float limit) -{ - m_limitLOD[rank] = limit; -} - -float CEngine::GetLimitLOD(int rank, bool last) -{ - float limit = 0.0f; - - if (last) - { - limit = m_limitLOD[rank]; - limit *= m_lastSize.x/640.0f; // limit further if large window! - limit += m_limitLOD[0]*(m_lastObjectDetail*2.0f); - } - else - { - limit = m_limitLOD[rank]; - limit *= m_size.x/640.0f; // limit further if large window! - limit += m_limitLOD[0]*(m_objectDetail*2.0f); - } - - if (limit < 0.0f) limit = 0.0f; - - return limit; -} - void CEngine::SetTerrainVision(float vision) { m_terrainVision = vision; @@ -2709,6 +2634,7 @@ void CEngine::SetClippingDistance(float value) { if (value < 0.5f) value = 0.5f; if (value > 2.0f) value = 2.0f; + m_lastClippingDistance = m_clippingDistance; m_clippingDistance = value; } @@ -2920,7 +2846,6 @@ void CEngine::ApplyChange() m_deepView[1] /= m_lastClippingDistance; SetFocus(m_focus); - ChangeLOD(); m_deepView[0] *= m_clippingDistance; m_deepView[1] *= m_clippingDistance; @@ -3040,8 +2965,7 @@ void CEngine::Draw3DScene() { EngineBaseObjLODTier& p3 = p2.next[l3]; - if ( m_objects[objRank].distance < p3.min || - m_objects[objRank].distance >= p3.max ) + if (! IsWithinLODLimit(m_objects[objRank].distance, p3.lodLevel)) continue; for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) @@ -3108,8 +3032,7 @@ void CEngine::Draw3DScene() { EngineBaseObjLODTier& p3 = p2.next[l3]; - if ( m_objects[objRank].distance < p3.min || - m_objects[objRank].distance >= p3.max ) + if (! IsWithinLODLimit(m_objects[objRank].distance, p3.lodLevel)) continue; for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) @@ -3177,8 +3100,7 @@ void CEngine::Draw3DScene() { EngineBaseObjLODTier& p3 = p2.next[l3]; - if (m_objects[objRank].distance < p3.min || - m_objects[objRank].distance >= p3.max) + if (! IsWithinLODLimit(m_objects[objRank].distance, p3.lodLevel)) continue; for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) @@ -3330,8 +3252,7 @@ void CEngine::DrawInterface() { EngineBaseObjLODTier& p3 = p2.next[l3]; - if (m_objects[objRank].distance < p3.min || - m_objects[objRank].distance >= p3.max) + if (! IsWithinLODLimit(m_objects[objRank].distance, p3.lodLevel)) continue; for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index c9391db..e5c75bc 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -32,6 +32,8 @@ #include "graphics/core/texture.h" #include "graphics/core/vertex.h" +#include "graphics/engine/modelfile.h" + #include "math/intpoint.h" #include "math/matrix.h" #include "math/point.h" @@ -204,12 +206,11 @@ struct EngineBaseObjDataTier */ struct EngineBaseObjLODTier { - float min; - float max; + LODLevel lodLevel; std::vector next; - inline EngineBaseObjLODTier(float min = 0.0f, float max = 0.0f) - : min(min), max(max) {} + inline EngineBaseObjLODTier(LODLevel lodLevel = LOD_Constant) + : lodLevel(lodLevel) {} }; /** @@ -777,12 +778,12 @@ public: EngineTriangleType triangleType, const Material& material, int state, std::string tex1Name, std::string tex2Name, - float min, float max, bool globalUpdate); + LODLevel lodLevel, bool globalUpdate); //! Adds a tier 4 engine object directly void AddBaseObjQuick(int baseObjRank, const EngineBaseObjDataTier& buffer, std::string tex1Name, std::string tex2Name, - float min, float max, bool globalUpdate); + LODLevel lodLevel, bool globalUpdate); // Objects @@ -827,29 +828,26 @@ public: //! Returns the first found tier 4 engine object for the given params or nullptr if not found EngineBaseObjDataTier* FindTriangles(int objRank, const Material& material, - int state, std::string tex1Name, std::string tex2Name, - float min, float max); + int state, std::string tex1Name, std::string tex2Name, + int lodLevelMask); //! Returns a partial list of triangles for given object - int GetPartialTriangles(int objRank, float min, float max, float percent, int maxCount, + int GetPartialTriangles(int objRank, int lodLevelMask, float percent, int maxCount, std::vector& triangles); - //! Updates LOD after parameter or resolution change - void ChangeLOD(); - //! Changes the 2nd texure for given object void ChangeSecondTexture(int objRank, const std::string& tex2Name); //! Changes (recalculates) texture mapping for given object void ChangeTextureMapping(int objRank, const Material& mat, int state, const std::string& tex1Name, const std::string& tex2Name, - float min, float max, EngineTextureMapping mode, + int lodLevelMask, EngineTextureMapping mode, float au, float bu, float av, float bv); //! Changes texture mapping for robot tracks void TrackTextureMapping(int objRank, const Material& mat, int state, const std::string& tex1Name, const std::string& tex2Name, - float min, float max, EngineTextureMapping mode, + int lodLevelMask, EngineTextureMapping mode, float pos, float factor, float tl, float ts, float tt); //! Detects the target object that is selected with the mouse @@ -947,12 +945,6 @@ public: //! Deletes the given texture, unloading it and removing from cache void DeleteTexture(const Texture& tex); - //@{ - //! Border management (distance limits) depends of the resolution (LOD = level-of-detail) - void SetLimitLOD(int rank, float limit); - float GetLimitLOD(int rank, bool last=false); - //@} - //! Defines of the distance field of vision void SetTerrainVision(float vision); @@ -1219,7 +1211,7 @@ protected: //! Creates a new tier 2 object (texture) EngineBaseObjTexTier& AddLevel2(EngineBaseObject& p1, const std::string& tex1Name, const std::string& tex2Name); //! Creates a new tier 3 object (LOD) - EngineBaseObjLODTier& AddLevel3(EngineBaseObjTexTier &p2, float min, float max); + EngineBaseObjLODTier& AddLevel3(EngineBaseObjTexTier &p2, LODLevel lodLevel); //! Creates a new tier 4 object (data) EngineBaseObjDataTier& AddLevel4(EngineBaseObjLODTier &p3, EngineTriangleType type, const Material& mat, int state); @@ -1230,6 +1222,9 @@ protected: //! Tests whether the given object is visible bool IsVisible(int objRank); + //! Checks whether the given distance is within LOD min & max limit + bool IsWithinLODLimit(float distance, LODLevel lodLevel); + //! Detects whether an object is affected by the mouse bool DetectBBox(int objRank, Math::Point mouse); @@ -1304,8 +1299,6 @@ protected: //! Current size of viewport window Math::IntPoint m_size; - //! Previous size of viewport window - Math::IntPoint m_lastSize; //! Base objects (also level 1 tier list) std::vector m_baseObjects; @@ -1356,12 +1349,10 @@ protected: Texture m_foregroundTex; bool m_drawWorld; bool m_drawFront; - float m_limitLOD[2]; float m_particleDensity; float m_clippingDistance; float m_lastClippingDistance; float m_objectDetail; - float m_lastObjectDetail; float m_terrainVision; float m_gadgetQuantity; int m_textureQuality; diff --git a/src/graphics/engine/modelfile.cpp b/src/graphics/engine/modelfile.cpp index a942b08..c9d41f3 100644 --- a/src/graphics/engine/modelfile.cpp +++ b/src/graphics/engine/modelfile.cpp @@ -495,8 +495,7 @@ bool CModelFile::ReadModel(std::istream& stream) triangle.material = t.material; triangle.tex1Name = std::string(t.texName); - triangle.min = t.min; - triangle.max = t.max; + triangle.lodLevel = MinMaxToLodLevel(t.min, t.max); m_triangles.push_back(triangle); } @@ -539,8 +538,7 @@ bool CModelFile::ReadModel(std::istream& stream) triangle.material = t.material; triangle.tex1Name = std::string(t.texName); - triangle.min = t.min; - triangle.max = t.max; + triangle.lodLevel = MinMaxToLodLevel(t.min, t.max); triangle.state = t.state; m_triangles.push_back(triangle); @@ -584,8 +582,7 @@ bool CModelFile::ReadModel(std::istream& stream) triangle.material = t.material; triangle.tex1Name = std::string(t.texName); - triangle.min = t.min; - triangle.max = t.max; + triangle.lodLevel = MinMaxToLodLevel(t.min, t.max); triangle.state = t.state; triangle.variableTex2 = t.texNum2 == 1; @@ -634,7 +631,7 @@ bool CModelFile::ReadModel(std::istream& stream) GetLogger()->Trace(" tex1: %s tex2: %s\n", m_triangles[i].tex1Name.c_str(), m_triangles[i].variableTex2 ? "(variable)" : m_triangles[i].tex2Name.c_str()); - GetLogger()->Trace(" min: %.2f max: %.2f\n", m_triangles[i].min, m_triangles[i].max); + GetLogger()->Trace(" lod level: %d\n", m_triangles[i].lodLevel); GetLogger()->Trace(" state: %ld\n", m_triangles[i].state); } @@ -685,8 +682,7 @@ bool CModelFile::WriteModel(std::ostream& stream) t.material = m_triangles[i].material; strncpy(t.texName, m_triangles[i].tex1Name.c_str(), 20); - t.min = m_triangles[i].min; - t.max = m_triangles[i].max; + LODLevelToMinMax(m_triangles[i].lodLevel, t.min, t.max); t.state = m_triangles[i].state; int no = 0; @@ -722,6 +718,46 @@ bool CModelFile::WriteModel(std::ostream& stream) return true; } +LODLevel CModelFile::MinMaxToLodLevel(float min, float max) +{ + if (min == 0.0f && max == 100.0f) + return LOD_High; + else if (min == 100.0f && max == 200.0f) + return LOD_Medium; + else if (min == 200.0f && max == 1000000.0f) + return LOD_Low; + else if (min == 0.0f && max == 1000000.0f) + return LOD_Constant; + + return LOD_Constant; +} + +void CModelFile::LODLevelToMinMax(LODLevel lodLevel, float& min, float& max) +{ + switch (lodLevel) + { + case LOD_High: + min = 0.0f; + max = 100.0f; + break; + + case LOD_Medium: + min = 100.0f; + max = 200.0f; + break; + + case LOD_Low: + min = 200.0f; + max = 1000000.0f; + break; + + case LOD_Constant: + min = 0.0f; + max = 1000000.0f; + break; + } +} + /******************************************************* New formats @@ -768,17 +804,15 @@ struct NewModelTriangle1 std::string tex2Name; //! If true, 2nd texture will be taken from current engine setting bool variableTex2; - //! Min LOD threshold - float min; - //! Max LOD threshold - float max; + //! LOD level + int lodLevel; //! Rendering state to be set int state; NewModelTriangle1() { variableTex2 = true; - min = max = 0.0f; + lodLevel = 0; state = 0; } }; @@ -834,8 +868,7 @@ bool CModelFile::ReadTextModel(std::istream& stream) ReadLineValue(stream, "tex1", t.tex1Name) && ReadLineValue(stream, "tex2", t.tex2Name) && ReadLineValue(stream, "var_tex2", varTex2Ch) && - ReadLineValue(stream, "min", t.min) && - ReadLineValue(stream, "max", t.max) && + ReadLineValue(stream, "lod_level", t.lodLevel) && ReadLineValue(stream, "state", t.state); if (!triOk || stream.fail()) @@ -855,10 +888,17 @@ bool CModelFile::ReadTextModel(std::istream& stream) triangle.tex1Name = t.tex1Name; triangle.tex2Name = t.tex2Name; triangle.variableTex2 = t.variableTex2; - triangle.min = t.min; - triangle.max = t.max; triangle.state = t.state; + switch (t.lodLevel) + { + case 0: triangle.lodLevel = LOD_Constant; break; + case 1: triangle.lodLevel = LOD_Low; break; + case 2: triangle.lodLevel = LOD_Medium; break; + case 3: triangle.lodLevel = LOD_High; break; + default: break; + } + m_triangles.push_back(triangle); continue; @@ -886,7 +926,7 @@ bool CModelFile::ReadTextModel(std::istream& stream) GetLogger()->Trace(" mat: d: %s a: %s s: %s\n", d.c_str(), a.c_str(), s.c_str()); GetLogger()->Trace(" tex1: %s tex2: %s\n", m_triangles[i].tex1Name.c_str(), m_triangles[i].tex2Name.c_str()); - GetLogger()->Trace(" min: %.2f max: %.2f\n", m_triangles[i].min, m_triangles[i].max); + GetLogger()->Trace(" lod level: %d\n", m_triangles[i].lodLevel); GetLogger()->Trace(" state: %ld\n", m_triangles[i].state); } @@ -938,10 +978,16 @@ bool CModelFile::WriteTextModel(std::ostream& stream) t.tex1Name = m_triangles[i].tex1Name; t.tex2Name = m_triangles[i].tex2Name; t.variableTex2 = m_triangles[i].variableTex2; - t.min = m_triangles[i].min; - t.max = m_triangles[i].max; t.state = m_triangles[i].state; + switch (m_triangles[i].lodLevel) + { + case LOD_Constant: t.lodLevel = 0; break; + case LOD_Low: t.lodLevel = 1; break; + case LOD_Medium: t.lodLevel = 2; break; + case LOD_High: t.lodLevel = 3; break; + } + stream << "p1 "; WriteTextVertexTex2(t.p1, stream); stream << "p2 "; @@ -954,8 +1000,7 @@ bool CModelFile::WriteTextModel(std::ostream& stream) stream << "tex1 " << t.tex1Name << std::endl; stream << "tex2 " << t.tex2Name << std::endl; stream << "var_tex2 " << (t.variableTex2 ? 'Y' : 'N') << std::endl; - stream << "min " << t.min << std::endl; - stream << "max " << t.max << std::endl; + stream << "lod_level " << t.lodLevel << std::endl; stream << "state " << t.state << std::endl; stream << std::endl; @@ -1012,9 +1057,8 @@ bool CModelFile::ReadBinaryModel(std::istream& stream) t.tex1Name = IOUtils::ReadBinaryString<1>(stream); t.tex2Name = IOUtils::ReadBinaryString<1>(stream); t.variableTex2 = IOUtils::ReadBinaryBool(stream); - t.min = IOUtils::ReadBinaryFloat(stream); - t.max = IOUtils::ReadBinaryFloat(stream); - t.state = IOUtils::ReadBinary<4, unsigned int>(stream); + t.lodLevel = IOUtils::ReadBinary<4, int>(stream); + t.state = IOUtils::ReadBinary<4, int>(stream); if (stream.fail()) { @@ -1030,10 +1074,17 @@ bool CModelFile::ReadBinaryModel(std::istream& stream) triangle.tex1Name = t.tex1Name; triangle.tex2Name = t.tex2Name; triangle.variableTex2 = t.variableTex2; - triangle.min = t.min; - triangle.max = t.max; triangle.state = t.state; + switch (t.lodLevel) + { + case 0: triangle.lodLevel = LOD_Constant; break; + case 1: triangle.lodLevel = LOD_Low; break; + case 2: triangle.lodLevel = LOD_Medium; break; + case 3: triangle.lodLevel = LOD_High; break; + default: break; + } + m_triangles.push_back(triangle); } } @@ -1059,7 +1110,7 @@ bool CModelFile::ReadBinaryModel(std::istream& stream) GetLogger()->Trace(" mat: d: %s a: %s s: %s\n", d.c_str(), a.c_str(), s.c_str()); GetLogger()->Trace(" tex1: %s tex2: %s\n", m_triangles[i].tex1Name.c_str(), m_triangles[i].tex2Name.c_str()); - GetLogger()->Trace(" min: %.2f max: %.2f\n", m_triangles[i].min, m_triangles[i].max); + GetLogger()->Trace(" lod level: %d\n", m_triangles[i].lodLevel); GetLogger()->Trace(" state: %ld\n", m_triangles[i].state); } @@ -1106,10 +1157,16 @@ bool CModelFile::WriteBinaryModel(std::ostream& stream) t.tex1Name = m_triangles[i].tex1Name; t.tex2Name = m_triangles[i].tex2Name; t.variableTex2 = m_triangles[i].variableTex2; - t.min = m_triangles[i].min; - t.max = m_triangles[i].max; t.state = m_triangles[i].state; + switch (m_triangles[i].lodLevel) + { + case LOD_Constant: t.lodLevel = 0; break; + case LOD_Low: t.lodLevel = 1; break; + case LOD_Medium: t.lodLevel = 2; break; + case LOD_High: t.lodLevel = 3; break; + } + WriteBinaryVertexTex2(t.p1, stream); WriteBinaryVertexTex2(t.p2, stream); WriteBinaryVertexTex2(t.p3, stream); @@ -1117,9 +1174,8 @@ bool CModelFile::WriteBinaryModel(std::ostream& stream) IOUtils::WriteBinaryString<1>(t.tex1Name, stream); IOUtils::WriteBinaryString<1>(t.tex2Name, stream); IOUtils::WriteBinaryBool(t.variableTex2, stream); - IOUtils::WriteBinaryFloat(t.min, stream); - IOUtils::WriteBinaryFloat(t.max, stream); - IOUtils::WriteBinary<4, unsigned int>(t.state, stream); + IOUtils::WriteBinary<4, int>(t.lodLevel, stream); + IOUtils::WriteBinary<4, int>(t.state, stream); if (stream.fail()) { @@ -1132,10 +1188,6 @@ bool CModelFile::WriteBinaryModel(std::ostream& stream) } -/******************************************************* - Other stuff - *******************************************************/ - const std::vector& CModelFile::GetTriangles() { return m_triangles; @@ -1146,23 +1198,5 @@ int CModelFile::GetTriangleCount() return m_triangles.size(); } -void CModelFile::CreateTriangle(Math::Vector p1, Math::Vector p2, Math::Vector p3, float min, float max) -{ - ModelTriangle triangle; - - Math::Vector n = Math::NormalToPlane(p3, p2, p1); - triangle.p1 = VertexTex2(p1, n); - triangle.p2 = VertexTex2(p2, n); - triangle.p3 = VertexTex2(p3, n); - - triangle.material.diffuse = Color(1.0f, 1.0f, 1.0f, 0.0f); - triangle.material.ambient = Color(0.5f, 0.5f, 0.5f, 0.0f); - - triangle.min = min; - triangle.max = max; - - m_triangles.push_back(triangle); -} - } // namespace Gfx diff --git a/src/graphics/engine/modelfile.h b/src/graphics/engine/modelfile.h index b2b5d87..3a702cb 100644 --- a/src/graphics/engine/modelfile.h +++ b/src/graphics/engine/modelfile.h @@ -39,9 +39,23 @@ namespace Gfx { /** - \struct ModelTriangle - \brief Triangle of a 3D model - */ + * \enum LODLevel + * \brief Level-of-detail + * + * A quantified replacement for older values of min/max. + */ +enum LODLevel +{ + LOD_Constant = -1, //!< triangle is always visible, no matter at what distance + LOD_Low = 1, //!< triangle is visible at farthest distance (lowest quality) + LOD_Medium = 2, //!< triangle is visible at medium distance (medium quality) + LOD_High = 4 //!< triangle is visible at closest distance (highest quality) +}; + +/** + * \struct ModelTriangle + * \brief Triangle of a 3D model + */ struct ModelTriangle { //! 1st vertex @@ -58,17 +72,15 @@ struct ModelTriangle std::string tex2Name; //! If true, 2nd texture will be taken from current engine setting bool variableTex2; - //! Min LOD threshold - float min; - //! Max LOD threshold - float max; + //! LOD level + LODLevel lodLevel; //! Rendering state to be set int state; ModelTriangle() { variableTex2 = true; - min = max = 0.0f; + lodLevel = LOD_Constant; state = 0; } }; @@ -126,8 +138,11 @@ public: const std::vector& GetTriangles(); protected: - //! Adds a triangle to the list - void CreateTriangle(Math::Vector p1, Math::Vector p2, Math::Vector p3, float min, float max); + //@{ + //! @deprecated min, max conversions + LODLevel MinMaxToLodLevel(float min, float max); + void LODLevelToMinMax(LODLevel lodLevel, float& min, float& max); + //@} protected: //! Model triangles diff --git a/src/graphics/engine/modelmanager.cpp b/src/graphics/engine/modelmanager.cpp index 5b17769..051922f 100644 --- a/src/graphics/engine/modelmanager.cpp +++ b/src/graphics/engine/modelmanager.cpp @@ -47,30 +47,8 @@ bool CModelManager::LoadModel(const std::string& fileName, bool mirrored) std::vector vs(3, VertexTex2()); - float limit[2]; - limit[0] = m_engine->GetLimitLOD(0); // frontier AB as config - limit[1] = m_engine->GetLimitLOD(1); // frontier BC as config - for (int i = 0; i < static_cast( modelInfo.triangles.size() ); i++) { - float min = modelInfo.triangles[i].min; - float max = modelInfo.triangles[i].max; - - // Standard frontiers -> config - if (min == 0.0f && max == 100.0f) // resolution A ? - { - max = limit[0]; - } - else if (min == 100.0f && max == 200.0f) // resolution B ? - { - min = limit[0]; - max = limit[1]; - } - else if (min == 200.0f && max == 1000000.0f) // resolution C ? - { - min = limit[1]; - } - int state = modelInfo.triangles[i].state; std::string tex2Name = modelInfo.triangles[i].tex2Name; @@ -96,7 +74,7 @@ bool CModelManager::LoadModel(const std::string& fileName, bool mirrored) m_engine->AddBaseObjTriangles(modelInfo.baseObjRank, vs, ENG_TRIANGLE_TYPE_TRIANGLES, modelInfo.triangles[i].material, state, modelInfo.triangles[i].tex1Name, tex2Name, - min, max, false); + modelInfo.triangles[i].lodLevel, false); } return true; diff --git a/src/graphics/engine/pyro.cpp b/src/graphics/engine/pyro.cpp index 978471b..e374d6c 100644 --- a/src/graphics/engine/pyro.cpp +++ b/src/graphics/engine/pyro.cpp @@ -1397,27 +1397,39 @@ void CPyro::CreateTriangle(CObject* obj, ObjectType oType, int part) int objRank = obj->GetObjectRank(part); if (objRank == -1) return; - float min = 0.0f; - float max = m_engine->GetLimitLOD(0); + int total = m_engine->GetObjectTotalTriangles(objRank); + float percent = 0.10f; if (total < 50) percent = 0.25f; if (total < 20) percent = 0.50f; if (m_type == PT_EGG) percent = 0.30f; - if ( oType == OBJECT_POWER || - oType == OBJECT_ATOMIC || - oType == OBJECT_URANIUM || - oType == OBJECT_TNT || - oType == OBJECT_BOMB ) percent = 0.75f; - if ( oType == OBJECT_MOBILEtg ) percent = 0.50f; - if ( oType == OBJECT_TEEN28 ) percent = 0.75f; - if ( oType == OBJECT_MOTHER ) max = 1000000.0f; - if ( oType == OBJECT_TEEN28 ) max = 1000000.0f; - if ( oType == OBJECT_TEEN31 ) max = 1000000.0f; + if (oType == OBJECT_POWER || + oType == OBJECT_ATOMIC || + oType == OBJECT_URANIUM || + oType == OBJECT_TNT || + oType == OBJECT_BOMB || + oType == OBJECT_TEEN28) + { + percent = 0.75f; + } + else if (oType == OBJECT_MOBILEtg) + { + percent = 0.50f; + } + + LODLevel lodLevel = LOD_High; + + if (oType == OBJECT_MOTHER || + oType == OBJECT_TEEN28 || + oType == OBJECT_TEEN31) + { + lodLevel = LOD_Constant; + } std::vector buffer; - total = m_engine->GetPartialTriangles(objRank, min, max, percent, 100, buffer); + total = m_engine->GetPartialTriangles(objRank, lodLevel, percent, 100, buffer); for (int i = 0; i < total; i++) { diff --git a/src/graphics/engine/terrain.cpp b/src/graphics/engine/terrain.cpp index a66b4b0..0be75bc 100644 --- a/src/graphics/engine/terrain.cpp +++ b/src/graphics/engine/terrain.cpp @@ -487,8 +487,7 @@ VertexTex2 CTerrain::GetVertex(int x, int y, int step) +-------------------> x \endverbatim */ bool CTerrain::CreateMosaic(int ox, int oy, int step, int objRank, - const Material &mat, - float min, float max) + const Material &mat) { int baseObjRank = m_engine->GetObjectBaseRank(objRank); if (baseObjRank == -1) @@ -640,7 +639,7 @@ bool CTerrain::CreateMosaic(int ox, int oy, int step, int objRank, buffer.vertices.push_back(p2); } - m_engine->AddBaseObjQuick(baseObjRank, buffer, texName1, texName2, min, max, true); + m_engine->AddBaseObjQuick(baseObjRank, buffer, texName1, texName2, LOD_Constant, true); } } } @@ -1170,15 +1169,9 @@ bool CTerrain::CreateSquare(int x, int y) m_objRanks[x+y*m_mosaicCount] = objRank; - float min = 0.0f; - float max = m_vision; - max *= m_engine->GetClippingDistance(); for (int step = 0; step < m_depth; step++) { - CreateMosaic(x, y, 1 << step, objRank, mat, min, max); - min = max; - max *= 2; - if (step == m_depth-1) max = Math::HUGE_NUM; + CreateMosaic(x, y, 1 << step, objRank, mat); } return true; diff --git a/src/graphics/engine/terrain.h b/src/graphics/engine/terrain.h index e17144e..91ddc76 100644 --- a/src/graphics/engine/terrain.h +++ b/src/graphics/engine/terrain.h @@ -330,7 +330,7 @@ protected: //! Calculates a vertex of the terrain VertexTex2 GetVertex(int x, int y, int step); //! Creates all objects of a mosaic - bool CreateMosaic(int ox, int oy, int step, int objRank, const Material& mat, float min, float max); + bool CreateMosaic(int ox, int oy, int step, int objRank, const Material& mat); //! Creates all objects in a mesh square ground bool CreateSquare(int x, int y); diff --git a/src/graphics/engine/test/modelfile_test.cpp b/src/graphics/engine/test/modelfile_test.cpp index 43cd43b..e7078a9 100644 --- a/src/graphics/engine/test/modelfile_test.cpp +++ b/src/graphics/engine/test/modelfile_test.cpp @@ -40,8 +40,7 @@ const char* const TEXT_MODEL = "tex1 lemt.png\n" "tex2\n" "var_tex2 N\n" -"min 200\n" -"max 1e+06\n" +"lod_level 0\n" "state 1024\n" "\n" "p1 c -19 -1 4 n -1 0 0 t1 0.248047 0.123047 t2 0.905224 0.52067\n" @@ -51,8 +50,7 @@ const char* const TEXT_MODEL = "tex1 derrick.png\n" "tex2\n" "var_tex2 Y\n" -"min 200\n" -"max 1e+06\n" +"lod_level 1\n" "state 0\n" ""; @@ -81,8 +79,7 @@ void Init() TRIANGLE_1.material.specular = Gfx::Color(0, 0, 0, 0); TRIANGLE_1.tex1Name = "lemt.png"; TRIANGLE_1.variableTex2 = false; - TRIANGLE_1.min = 200.0f; - TRIANGLE_1.max = 1e+06f; + TRIANGLE_1.lodLevel = Gfx::LOD_Constant; TRIANGLE_1.state = 1024; TRIANGLE_2.p1 = Gfx::VertexTex2(Math::Vector(-19, -1, 4), @@ -102,8 +99,7 @@ void Init() TRIANGLE_2.material.specular = Gfx::Color(0, 0, 0, 0); TRIANGLE_2.tex1Name = "derrick.png"; TRIANGLE_2.variableTex2 = true; - TRIANGLE_2.min = 200.0f; - TRIANGLE_2.max = 1e+06f; + TRIANGLE_2.lodLevel = Gfx::LOD_Low; TRIANGLE_2.state = 0; } @@ -171,10 +167,7 @@ bool CompareTriangles(const Gfx::ModelTriangle& t1, const Gfx::ModelTriangle& t2 if (t1.variableTex2 != t2.variableTex2) return false; - if (!Math::IsEqual(t1.min, t2.min)) - return false; - - if (!Math::IsEqual(t1.max, t2.max)) + if (t1.lodLevel != t2.lodLevel) return false; if (t1.state != t2.state) diff --git a/src/object/auto/autoportico.cpp b/src/object/auto/autoportico.cpp index 3b3bf84..c0be784 100644 --- a/src/object/auto/autoportico.cpp +++ b/src/object/auto/autoportico.cpp @@ -398,7 +398,6 @@ Error CAutoPortico::GetError() void CAutoPortico::UpdateTrackMapping(float left, float right) { Gfx::Material mat; - float limit[2]; int rank; memset( &mat, 0, sizeof(Gfx::Material)); @@ -411,15 +410,12 @@ void CAutoPortico::UpdateTrackMapping(float left, float right) rank = m_object->GetObjectRank(0); - limit[0] = 0.0f; - limit[1] = 1000000.0f; - m_engine->TrackTextureMapping(rank, mat, Gfx::ENG_RSTATE_PART1, "lemt.png", "", - limit[0], limit[1], Gfx::ENG_TEX_MAPPING_X, + Gfx::LOD_Constant, Gfx::ENG_TEX_MAPPING_X, right, 8.0f, 8.0f, 192.0f, 256.0f); m_engine->TrackTextureMapping(rank, mat, Gfx::ENG_RSTATE_PART2, "lemt.png", "", - limit[0], limit[1], Gfx::ENG_TEX_MAPPING_X, + Gfx::LOD_Constant, Gfx::ENG_TEX_MAPPING_X, left, 8.0f, 8.0f, 192.0f, 256.0f); } diff --git a/src/object/brain.cpp b/src/object/brain.cpp index ef7309d..d3c0e0b 100644 --- a/src/object/brain.cpp +++ b/src/object/brain.cpp @@ -1947,6 +1947,7 @@ void CBrain::UpdateInterface(float rTime) if ( power == 0 ) { energy = 0.0f; + limit = 0.0f; } else { diff --git a/src/object/motion/motionvehicle.cpp b/src/object/motion/motionvehicle.cpp index 33e746f..3c95a27 100644 --- a/src/object/motion/motionvehicle.cpp +++ b/src/object/motion/motionvehicle.cpp @@ -1877,52 +1877,33 @@ bool CMotionVehicle::EventFrameCanoni(const Event &event) void CMotionVehicle::UpdateTrackMapping(float left, float right, ObjectType type) { - Gfx::Material mat; - float limit[4]; - int rRank, lRank, i; + Gfx::Material mat; + mat.diffuse = Gfx::Color(1.0f, 1.0f, 1.0f); // white + mat.ambient = Gfx::Color(0.5f, 0.5f, 0.5f); - memset( &mat, 0, sizeof(Gfx::Material) ); - mat.diffuse.r = 1.0f; - mat.diffuse.g = 1.0f; - mat.diffuse.b = 1.0f; // white - mat.ambient.r = 0.5f; - mat.ambient.g = 0.5f; - mat.ambient.b = 0.5f; + int rRank = m_object->GetObjectRank(6); + int lRank = m_object->GetObjectRank(7); - rRank = m_object->GetObjectRank(6); - lRank = m_object->GetObjectRank(7); - - - if ( type == OBJECT_MOBILEdr ) + if (type == OBJECT_MOBILEdr) { - limit[0] = 0.0f; - limit[1] = 1000000.0f; - limit[2] = limit[1]; - limit[3] = m_engine->GetLimitLOD(1); - m_engine->TrackTextureMapping(rRank, mat, Gfx::ENG_RSTATE_PART1, "drawer.png", "", - limit[0], limit[1], Gfx::ENG_TEX_MAPPING_X, + Gfx::LOD_Constant, Gfx::ENG_TEX_MAPPING_X, right, 1.0f, 8.0f, 192.0f, 256.0f); m_engine->TrackTextureMapping(lRank, mat, Gfx::ENG_RSTATE_PART2, "drawer.png", "", - limit[0], limit[1], Gfx::ENG_TEX_MAPPING_X, + Gfx::LOD_Constant, Gfx::ENG_TEX_MAPPING_X, left, 1.0f, 8.0f, 192.0f, 256.0f); } else { - limit[0] = 0.0f; - limit[1] = m_engine->GetLimitLOD(0); - limit[2] = limit[1]; - limit[3] = m_engine->GetLimitLOD(1); - - for ( i=0 ; i<2 ; i++ ) + for (int i = 0; i < 2; i++) { m_engine->TrackTextureMapping(rRank, mat, Gfx::ENG_RSTATE_PART1, "lemt.png", "", - limit[i*2+0], limit[i*2+1], Gfx::ENG_TEX_MAPPING_X, + (i == 0) ? Gfx::LOD_High : Gfx::LOD_Medium, Gfx::ENG_TEX_MAPPING_X, right, 1.0f, 8.0f, 192.0f, 256.0f); m_engine->TrackTextureMapping(lRank, mat, Gfx::ENG_RSTATE_PART2, "lemt.png", "", - limit[i*2+0], limit[i*2+1], Gfx::ENG_TEX_MAPPING_X, + (i == 0) ? Gfx::LOD_High : Gfx::LOD_Medium, Gfx::ENG_TEX_MAPPING_X, left, 1.0f, 8.0f, 192.0f, 256.0f); } } diff --git a/src/object/object.cpp b/src/object/object.cpp index 9615866..e2830c5 100644 --- a/src/object/object.cpp +++ b/src/object/object.cpp @@ -5811,21 +5811,16 @@ void CObject::FlatParent() void CObject::UpdateEnergyMapping() { - Gfx::Material mat; - float a, b, i, s, au, bu; - float limit[6]; - int j; + if (Math::IsEqual(m_energy, m_lastEnergy, 0.01f)) + return; - if ( fabs(m_energy-m_lastEnergy) < 0.01f ) return; m_lastEnergy = m_energy; - memset(&mat, 0, sizeof(mat)); - mat.diffuse.r = 1.0f; - mat.diffuse.g = 1.0f; - mat.diffuse.b = 1.0f; // white - mat.ambient.r = 0.5f; - mat.ambient.g = 0.5f; - mat.ambient.b = 0.5f; + Gfx::Material mat; + mat.diffuse = Gfx::Color(1.0f, 1.0f, 1.0f); // white + mat.ambient = Gfx::Color(0.5f, 0.5f, 0.5f); + + float a = 0.0f, b = 0.0f; if ( m_type == OBJECT_POWER || m_type == OBJECT_ATOMIC ) @@ -5833,35 +5828,30 @@ void CObject::UpdateEnergyMapping() a = 2.0f; b = 0.0f; // dimensions of the battery (according to y) } - if ( m_type == OBJECT_STATION ) + else if ( m_type == OBJECT_STATION ) { a = 10.0f; b = 4.0f; // dimensions of the battery (according to y) } - if ( m_type == OBJECT_ENERGY ) + else if ( m_type == OBJECT_ENERGY ) { a = 9.0f; b = 3.0f; // dimensions of the battery (according to y) } - i = 0.50f+0.25f*m_energy; // origin - s = i+0.25f; // width + float i = 0.50f+0.25f*m_energy; // origin + float s = i+0.25f; // width - au = (s-i)/(b-a); - bu = s-b*(s-i)/(b-a); + float au = (s-i)/(b-a); + float bu = s-b*(s-i)/(b-a); - limit[0] = 0.0f; - limit[1] = m_engine->GetLimitLOD(0); - limit[2] = limit[1]; - limit[3] = m_engine->GetLimitLOD(1); - limit[4] = limit[3]; - limit[5] = 1000000.0f; + Gfx::LODLevel lodLevels[3] = { Gfx::LOD_High, Gfx::LOD_Medium, Gfx::LOD_Low }; - for ( j=0 ; j<3 ; j++ ) + for (int j = 0; j < 3; j++) { m_engine->ChangeTextureMapping(m_objectPart[0].object, mat, Gfx::ENG_RSTATE_PART3, "lemt.png", "", - limit[j*2+0], limit[j*2+1], Gfx::ENG_TEX_MAPPING_1Y, + lodLevels[j], Gfx::ENG_TEX_MAPPING_1Y, au, bu, 1.0f, 0.0f); } } diff --git a/src/tools/convert_model.cpp b/src/tools/convert_model.cpp index 3eecfb1..463b83a 100644 --- a/src/tools/convert_model.cpp +++ b/src/tools/convert_model.cpp @@ -133,6 +133,18 @@ bool ParseArgs(int argc, char *argv[]) return true; } +std::ostream& operator<<(std::ostream& stream, Gfx::LODLevel lodLevel) +{ + switch (lodLevel) + { + case Gfx::LOD_Constant: stream << "constant"; break; + case Gfx::LOD_High: stream << "high"; break; + case Gfx::LOD_Medium: stream << "medium"; break; + case Gfx::LOD_Low: stream << "low"; break; + } + return stream; +} + template void PrintStats(const std::map& stats, int total) { @@ -188,25 +200,25 @@ int main(int argc, char *argv[]) { const std::vector& triangles = model.GetTriangles(); - Math::Vector min( Math::HUGE_NUM, Math::HUGE_NUM, Math::HUGE_NUM); - Math::Vector max(-Math::HUGE_NUM, -Math::HUGE_NUM, -Math::HUGE_NUM); + Math::Vector bboxMin( Math::HUGE_NUM, Math::HUGE_NUM, Math::HUGE_NUM); + Math::Vector bboxMax(-Math::HUGE_NUM, -Math::HUGE_NUM, -Math::HUGE_NUM); std::map texs1, texs2; std::map states; - std::map mins, maxs; + std::map lodLevels; int variableTexs2 = 0; for (int i = 0; i < static_cast( triangles.size() ); ++i) { const Gfx::ModelTriangle& t = triangles[i]; - min.x = Math::Min(t.p1.coord.x, t.p2.coord.x, t.p3.coord.x, min.x); - min.y = Math::Min(t.p1.coord.y, t.p2.coord.y, t.p3.coord.y, min.y); - min.z = Math::Min(t.p1.coord.z, t.p2.coord.z, t.p3.coord.z, min.z); + bboxMin.x = Math::Min(t.p1.coord.x, t.p2.coord.x, t.p3.coord.x, bboxMin.x); + bboxMin.y = Math::Min(t.p1.coord.y, t.p2.coord.y, t.p3.coord.y, bboxMin.y); + bboxMin.z = Math::Min(t.p1.coord.z, t.p2.coord.z, t.p3.coord.z, bboxMin.z); - max.x = Math::Max(t.p1.coord.x, t.p2.coord.x, t.p3.coord.x, max.x); - max.y = Math::Max(t.p1.coord.y, t.p2.coord.y, t.p3.coord.y, max.y); - max.z = Math::Max(t.p1.coord.z, t.p2.coord.z, t.p3.coord.z, max.z); + bboxMax.x = Math::Max(t.p1.coord.x, t.p2.coord.x, t.p3.coord.x, bboxMax.x); + bboxMax.y = Math::Max(t.p1.coord.y, t.p2.coord.y, t.p3.coord.y, bboxMax.y); + bboxMax.z = Math::Max(t.p1.coord.z, t.p2.coord.z, t.p3.coord.z, bboxMax.z); texs1[t.tex1Name] += 1; if (! t.tex2Name.empty()) @@ -215,16 +227,15 @@ int main(int argc, char *argv[]) variableTexs2 += 1; states[t.state] += 1; - mins[t.min] += 1; - maxs[t.max] += 1; + lodLevels[t.lodLevel] += 1; } std::cerr << "---- Info ----" << std::endl; std::cerr << "Total triangles: " << triangles.size(); std::cerr << std::endl; std::cerr << "Bounding box:" << std::endl; - std::cerr << " min: [" << min.x << ", " << min.y << ", " << min.z << "]" << std::endl; - std::cerr << " max: [" << max.x << ", " << max.y << ", " << max.z << "]" << std::endl; + std::cerr << " bboxMin: [" << bboxMin.x << ", " << bboxMin.y << ", " << bboxMin.z << "]" << std::endl; + std::cerr << " bboxMax: [" << bboxMax.x << ", " << bboxMax.y << ", " << bboxMax.z << "]" << std::endl; std::cerr << std::endl; std::cerr << "Textures:" << std::endl; std::cerr << " tex1:" << std::endl; @@ -237,10 +248,7 @@ int main(int argc, char *argv[]) PrintStats(states, triangles.size()); std::cerr << std::endl; std::cerr << "LOD:" << std::endl; - std::cerr << " min:" << std::endl; - PrintStats(mins, triangles.size()); - std::cerr << " max:" << std::endl; - PrintStats(maxs, triangles.size()); + PrintStats(lodLevels, triangles.size()); return 0; } -- cgit v1.2.3-1-g7c22 From 3f41f97fc47fca22634dc858c3ecdb39d0d27e32 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 27 Jan 2013 22:08:33 +0100 Subject: Updated and improved Blender script * min/max -> lod level change in model format * split objects based on LOD * lod_level, state & var_tex2 saved as properties in Blender objects * UI dialogs --- tools/blender-scripts.py | 600 ++++++++++++++++++++++++++++++----------------- 1 file changed, 382 insertions(+), 218 deletions(-) diff --git a/tools/blender-scripts.py b/tools/blender-scripts.py index 53c9b5f..c2361c7 100644 --- a/tools/blender-scripts.py +++ b/tools/blender-scripts.py @@ -26,6 +26,11 @@ import os import copy import math + +## +# Data types & helper functions +## + FUZZY_TOLERANCE = 1e-5 class ColobotError(Exception): @@ -66,6 +71,8 @@ class ColobotMaterial: self.specular = array.array('f', [0.0, 0.0, 0.0, 0.0]) self.tex1 = '' self.tex2 = '' + self.var_tex2 = False + self.state = 0 def __hash__(self): return 1 @@ -75,19 +82,28 @@ class ColobotMaterial: fuzzy_equal_v(self.ambient, other.ambient) and fuzzy_equal_v(self.specular, other.specular) and self.tex1 == other.tex1 and - self.tex2 == other.tex2) + self.tex2 == other.tex2 and + self.var_tex2 == other.var_tex2 and + self.state == other.state) + +class ColobotTexPair: + """Pair of 2 textures""" + def __init__(self): + self.tex1 = '' + self.tex2 = '' + + def __hash__(self): + return 1 + + def __eq__(self, other): + return self.tex1 == other.tex1 and self.tex2 == other.tex2 class ColobotTriangle: """Triangle as saved in Colobot model file""" def __init__(self): self.p = [ColobotVertex(), ColobotVertex(), ColobotVertex()] self.mat = ColobotMaterial() - self.tex1 = '' - self.tex2 = '' - self.var_tex2 = False - self.state = 0 - self.min = 0.0 - self.max = 0.0 + self.lod_level = 0 class ColobotModel: """Colobot model (content of model file)""" @@ -95,8 +111,49 @@ class ColobotModel: self.version = 1 self.triangles = [] - def append(self, model): - self.triangles.extend(model.triangles) + def get_lod_level_list(self): + lod_level_set = set() + for t in self.triangles: + lod_level_set.add(t.lod_level) + + return list(lod_level_set) + + def get_tex_pair_list(self): + tex_pair_set = set() + for t in self.triangles: + tex_pair = ColobotTexPair() + tex_pair.tex1 = t.mat.tex1 + tex_pair.tex2 = t.mat.tex2 + tex_pair_set.add(tex_pair) + + return list(tex_pair_set) + + def get_triangle_list(self, lod_level): + triangles = [] + for t in self.triangles: + if (t.lod_level == lod_level): + triangles.append(t) + + return triangles + + def get_vertex_list(self, lod_level): + vertex_set = set() + + for t in self.triangles: + if (t.lod_level == lod_level): + for i in range(0, 3): + vertex_set.add(t.p[i]) + + return list(vertex_set) + + def get_material_list(self, lod_level): + material_set = set() + + for t in self.triangles: + if (t.lod_level == lod_level): + material_set.add(t.mat) + + return list(material_set) def v3to4(vec): return array.array('f', [vec[0], vec[1], vec[2], 0.0]) @@ -104,7 +161,14 @@ def v3to4(vec): def v4to3(vec): return array.array('f', [vec[0], vec[1], vec[2]]) + +## +# Model file input/output +## + def write_colobot_model(filename, model): + float_format = "{:g}".format + file = open(filename, 'w') file.write('# Colobot text model\n') @@ -120,24 +184,23 @@ def write_colobot_model(filename, model): for i in range(0, 3): p = t.p[i] file.write('p' + str(i+1)) - file.write(' c ' + ' '.join(map(str, p.coord ))) - file.write(' n ' + ' '.join(map(str, p.normal))) - file.write(' t1 ' + ' '.join(map(str, p.t1))) - file.write(' t2 ' + ' '.join(map(str, p.t2))) + file.write(' c ' + ' '.join(map(float_format, p.coord ))) + file.write(' n ' + ' '.join(map(float_format, p.normal))) + file.write(' t1 ' + ' '.join(map(float_format, p.t1))) + file.write(' t2 ' + ' '.join(map(float_format, p.t2))) file.write('\n') file.write('mat') - file.write(' dif ' + ' '.join(map(str, t.mat.diffuse))) - file.write(' amb ' + ' '.join(map(str, t.mat.ambient))) - file.write(' spc ' + ' '.join(map(str, t.mat.specular))) + file.write(' dif ' + ' '.join(map(float_format, t.mat.diffuse))) + file.write(' amb ' + ' '.join(map(float_format, t.mat.ambient))) + file.write(' spc ' + ' '.join(map(float_format, t.mat.specular))) file.write('\n') - file.write('tex1 ' + t.tex1 + '\n') - file.write('tex2 ' + t.tex2 + '\n') - file.write('var_tex2 ' + ( 'Y' if t.var_tex2 else 'N' + '\n' ) ) - file.write('min ' + str(t.min) + '\n') - file.write('max ' + str(t.max) + '\n') - file.write('state ' + str(t.state) + '\n') + file.write('tex1 ' + t.mat.tex1 + '\n') + file.write('tex2 ' + t.mat.tex2 + '\n') + file.write('var_tex2 ' + ( 'Y' if t.mat.var_tex2 else 'N' + '\n' ) ) + file.write('lod_level ' + str(t.lod_level) + '\n') + file.write('state ' + str(t.mat.state) + '\n') file.write('\n') file.close() @@ -216,14 +279,14 @@ def read_colobot_model(filename): tokens, index = token_next_line(lines, index) if (tokens[0] != 'version'): - raise ColobotError('Invalid header') + raise ColobotError("Invalid header", "version") model.version = int(tokens[1]) if (model.version != 1): - raise ColobotError('Unknown model file version') + raise ColobotError("Unknown model file version") tokens, index = token_next_line(lines, index) if (tokens[0] != 'total_triangles'): - raise ColobotError('Invalid header') + raise ColobotError("Invalid header", "total_triangles") numTriangles = int(tokens[1]) for i in range(0, numTriangles): @@ -231,90 +294,88 @@ def read_colobot_model(filename): tokens, index = token_next_line(lines, index) if (tokens[0] != 'p1'): - raise ColobotError('Invalid triangle') + raise ColobotError("Invalid triangle", "p1") t.p[0] = read_colobot_vertex(tokens) tokens, index = token_next_line(lines, index) if (tokens[0] != 'p2'): - raise ColobotError('Invalid triangle') + raise ColobotError("Invalid triangle", "p2") t.p[1] = read_colobot_vertex(tokens) tokens, index = token_next_line(lines, index) if (tokens[0] != 'p3'): - raise ColobotError('Invalid triangle') + raise ColobotError("Invalid triangle", "p3") t.p[2] = read_colobot_vertex(tokens) tokens, index = token_next_line(lines, index) if (tokens[0] != 'mat'): - raise ColobotError('Invalid triangle') + raise ColobotError("Invalid triangle", "mat") t.mat = read_colobot_material(tokens) tokens, index = token_next_line(lines, index) if (tokens[0] != 'tex1'): - raise ColobotError('Invalid triangle') + raise ColobotError("Invalid triangle", "tex1") if (len(tokens) > 1): - t.tex1 = tokens[1] + t.mat.tex1 = tokens[1] tokens, index = token_next_line(lines, index) if (tokens[0] != 'tex2'): - raise ColobotError('Invalid triangle') + raise ColobotError("Invalid triangle", "tex2") if (len(tokens) > 1): - t.tex2 = tokens[1] + t.mat.tex2 = tokens[1] tokens, index = token_next_line(lines, index) if (tokens[0] != 'var_tex2'): - raise ColobotError('Invalid triangle') - t.var_tex2 = tokens[1] == 'Y' - - tokens, index = token_next_line(lines, index) - if (tokens[0] != 'min'): - raise ColobotError('Invalid triangle') - t.min = float(tokens[1]) + raise ColobotError("Invalid triangle", "var_tex2") + t.mat.var_tex2 = tokens[1] == 'Y' tokens, index = token_next_line(lines, index) - if (tokens[0] != 'max'): - raise ColobotError('Invalid triangle') - t.max = float(tokens[1]) + if (tokens[0] != 'lod_level'): + raise ColobotError("Invalid triangle", "lod_level") + t.lod_level = int(tokens[1]) tokens, index = token_next_line(lines, index) if (tokens[0] != 'state'): - raise ColobotError('Invalid triangle') - t.state = int(tokens[1]) + raise ColobotError("Invalid triangle", "state") + t.mat.state = int(tokens[1]) model.triangles.append(t) - return model -def mesh_to_colobot_model(mesh, scene, defaults): - model = ColobotModel() - if (mesh.type != 'MESH'): +## +# Mesh conversion functions +## + +def append_obj_to_colobot_model(obj, model, scene, defaults): + + if (obj.type != 'MESH'): raise ColobotError('Only mesh meshs can be exported') - for poly in mesh.data.polygons: + for poly in obj.data.polygons: if (poly.loop_total > 3): raise ColobotError('Cannot export polygons with > 3 vertices!') - for i, poly in enumerate(mesh.data.polygons): + for i, poly in enumerate(obj.data.polygons): t = ColobotTriangle() j = 0 for loop_index in poly.loop_indices: - v = mesh.data.vertices[mesh.data.loops[loop_index].vertex_index] + v = obj.data.vertices[obj.data.loops[loop_index].vertex_index] t.p[j].coord = copy.copy(v.co) t.p[j].normal = copy.copy(v.normal) - if (len(mesh.data.uv_layers) >= 1): - t.p[j].t1 = copy.copy(mesh.data.uv_layers[0].data[loop_index].uv) + if (len(obj.data.uv_layers) >= 1): + t.p[j].t1 = copy.copy(obj.data.uv_layers[0].data[loop_index].uv) t.p[j].t1[1] = 1.0 - t.p[j].t1[1] - if (len(mesh.data.uv_layers) >= 2): - t.p[j].t2 = copy.copy(mesh.data.uv_layers[1].data[loop_index].uv) + if (len(obj.data.uv_layers) >= 2): + t.p[j].t2 = copy.copy(obj.data.uv_layers[1].data[loop_index].uv) t.p[j].t2[1] = 1.0 - t.p[j].t2[1] j = j + 1 - mat = mesh.data.materials[poly.material_index] + mat = obj.data.materials[poly.material_index] t.mat.diffuse = v3to4(mat.diffuse_color) t.mat.diffuse[3] = mat.alpha t.mat.ambient = v3to4(scene.world.ambient_color * mat.ambient) @@ -327,95 +388,15 @@ def mesh_to_colobot_model(mesh, scene, defaults): if (mat.texture_slots[1] != None): t.tex2 = bpy.path.basename(mat.texture_slots[1].texture.image.filepath) - t.var_tex2 = mesh.get('var_tex2', defaults['var_tex2']) - t.state = mesh.get('state', defaults['state']) - t.min = mesh.get('min', defaults['min']) - t.max = mesh.get('max', defaults['max']) - - model.triangles.append(t) - - return model - - -def colobot_model_to_mesh(model, mesh_name, texture_dir): - mesh = bpy.data.meshes.new(name=mesh_name) - - vertex_set = set() - - for t in model.triangles: - for i in range(0, 3): - vertex_set.add(t.p[i]) - - vertex_list = list(vertex_set) - - mat_set = set() - - for t in model.triangles: - mat = t.mat - mat.tex1 = t.tex1 - mat.tex2 = t.tex2 - mat_set.add(mat) - - mat_list = list(mat_set) - - uv1map = False - uv2map = False - - zero_t = array.array('f', [0.0, 0.0]) - - for v in vertex_list: - if ((not uv1map) and (v.t1 != zero_t)): - uv1map = True - if ((not uv2map) and (v.t2 != zero_t)): - uv2map = True - - mesh.vertices.add(len(vertex_list)) - - for i, v in enumerate(mesh.vertices): - v.co = copy.copy(vertex_list[i].coord) - v.normal = copy.copy(vertex_list[i].normal) + t.var_tex2 = mat.get('var_tex2', defaults['var_tex2']) + t.state = mat.get('state', defaults['state']) - for i, m in enumerate(mat_list): - material = bpy.data.materials.new(name=mesh_name + '_mat_' + str(i+1)) - material.diffuse_color = v4to3(m.diffuse) - material.ambient = (m.ambient[0] + m.ambient[1] + m.ambient[2]) / 3.0 - material.alpha = (m.diffuse[3] + m.ambient[3]) / 2.0 - material.specular_color = v4to3(m.specular) - material.specular_alpha = m.specular[3] + t.lod_level = int(obj.data.get('lod_level', defaults['lod_level'])) - mesh.materials.append(material) - - mesh.tessfaces.add(len(model.triangles)) + model.triangles.append(t) - for i, f in enumerate(mesh.tessfaces): - t = model.triangles[i] - mat = t.mat - mat.tex1 = t.tex1 - mat.tex2 = t.tex2 - f.material_index = mat_list.index(mat) - for i in range(0, 3): - f.vertices[i] = vertex_list.index(t.p[i]) - - if uv1map: - uvlay1 = mesh.tessface_uv_textures.new(name='UV_1') - for i, f in enumerate(uvlay1.data): - f.uv1[0] = model.triangles[i].p[0].t1[0] - f.uv1[1] = 1.0 - model.triangles[i].p[0].t1[1] - f.uv2[0] = model.triangles[i].p[1].t1[0] - f.uv2[1] = 1.0 - model.triangles[i].p[1].t1[1] - f.uv3[0] = model.triangles[i].p[2].t1[0] - f.uv3[1] = 1.0 - model.triangles[i].p[2].t1[1] - - if uv2map: - uvlay2 = mesh.tessface_uv_textures.new(name='UV_2') - for i, f in enumerate(uvlay2.data): - f.uv1[0] = model.triangles[i].p[0].t2[0] - f.uv1[1] = 1.0 - model.triangles[i].p[0].t2[1] - f.uv2[0] = model.triangles[i].p[1].t2[0] - f.uv2[1] = 1.0 - model.triangles[i].p[1].t2[1] - f.uv3[0] = model.triangles[i].p[2].t2[0] - f.uv3[1] = 1.0 - model.triangles[i].p[2].t2[1] +def colobot_model_to_meshes(model, base_mesh_name, texture_dir): def load_tex(name): import os import sys @@ -424,7 +405,6 @@ def colobot_model_to_mesh(model, mesh_name, texture_dir): if (name == ''): return None, None - encoding = sys.getfilesystemencoding() image = load_image(name, texture_dir, recursive=True, place_holder=True) texture = None if image: @@ -433,52 +413,198 @@ def colobot_model_to_mesh(model, mesh_name, texture_dir): texture.image = image return image, texture - for i, m in enumerate(mat_list): + class Texture: + def __init__(self): + self.image1 = None + self.image2 = None + self.tex1 = None + self.tex2 = None + + tex_dict = dict() + tex_pair_list = model.get_tex_pair_list() + for tex_pair in tex_pair_list: + tex_object = Texture() + tex_object.image1, tex_object.tex1 = load_tex(tex_pair.tex1) + tex_object.image2, tex_object.tex2 = load_tex(tex_pair.tex2) + tex_dict[tex_pair] = tex_object - image1, tex1 = load_tex(m.tex1) - if image1: - mtex = mesh.materials[i].texture_slots.add() - mtex.texture = tex1 - mtex.texture_coords = 'UV' - mtex.uv_layer = 'UV_1' - mtex.use_map_color_diffuse = True + meshes = [] - for j, face in enumerate(mesh.uv_textures[0].data): - if (model.triangles[j].tex1 == m.tex1): - face.image = image1 + index = 0 + lod_levels = model.get_lod_level_list() + for lod_level in lod_levels: + index = index + 1 + mesh = bpy.data.meshes.new(name=base_mesh_name + str(index)) + + triangle_list = model.get_triangle_list(lod_level) + vertex_list = model.get_vertex_list(lod_level) + material_list = model.get_material_list(lod_level) + + uv1map = False + uv2map = False + + zero_t = array.array('f', [0.0, 0.0]) + + for v in vertex_list: + if ((not uv1map) and (v.t1 != zero_t)): + uv1map = True + if ((not uv2map) and (v.t2 != zero_t)): + uv2map = True + + mesh.vertices.add(len(vertex_list)) + + for i, v in enumerate(mesh.vertices): + v.co = copy.copy(vertex_list[i].coord) + v.normal = copy.copy(vertex_list[i].normal) + + for i, m in enumerate(material_list): + material = bpy.data.materials.new(name=base_mesh_name + str(index) + '_mat_' + str(i+1)) + material.diffuse_color = v4to3(m.diffuse) + material.ambient = (m.ambient[0] + m.ambient[1] + m.ambient[2]) / 3.0 + material.alpha = (m.diffuse[3] + m.ambient[3]) / 2.0 + material.specular_color = v4to3(m.specular) + material.specular_alpha = m.specular[3] + + material.var_tex2 = m.var_tex2 + material.state = m.state + + mesh.materials.append(material) + + mesh.tessfaces.add(len(triangle_list)) + + for i, f in enumerate(mesh.tessfaces): + t = triangle_list[i] + f.material_index = material_list.index(t.mat) + for i in range(0, 3): + f.vertices[i] = vertex_list.index(t.p[i]) + + if uv1map: + uvlay1 = mesh.tessface_uv_textures.new(name='UV_1') + for i, f in enumerate(uvlay1.data): + f.uv1[0] = triangle_list[i].p[0].t1[0] + f.uv1[1] = 1.0 - triangle_list[i].p[0].t1[1] + f.uv2[0] = triangle_list[i].p[1].t1[0] + f.uv2[1] = 1.0 - triangle_list[i].p[1].t1[1] + f.uv3[0] = triangle_list[i].p[2].t1[0] + f.uv3[1] = 1.0 - triangle_list[i].p[2].t1[1] + + if uv2map: + uvlay2 = mesh.tessface_uv_textures.new(name='UV_2') + for i, f in enumerate(uvlay2.data): + f.uv1[0] = triangle_list[i].p[0].t2[0] + f.uv1[1] = 1.0 - triangle_list[i].p[0].t2[1] + f.uv2[0] = triangle_list[i].p[1].t2[0] + f.uv2[1] = 1.0 - triangle_list[i].p[1].t2[1] + f.uv3[0] = triangle_list[i].p[2].t2[0] + f.uv3[1] = 1.0 - triangle_list[i].p[2].t2[1] + + for i, m in enumerate(material_list): + tex_pair = ColobotTexPair() + tex_pair.tex1 = m.tex1 + tex_pair.tex2 = m.tex2 + tex_object = tex_dict[tex_pair] + + if tex_object and tex_object.image1: + mtex = mesh.materials[i].texture_slots.add() + mtex.texture = tex_object.tex1 + mtex.texture_coords = 'UV' + mtex.uv_layer = 'UV_1' + mtex.use_map_color_diffuse = True + + for j, face in enumerate(mesh.uv_textures[0].data): + if (triangle_list[j].tex1 == m.tex1): + face.image = tex_object.image1 + + if tex_object and tex_object.image2: + mtex = mesh.materials[i].texture_slots.add() + mtex.texture = tex_object.tex2 + mtex.texture_coords = 'UV' + mtex.uv_layer = 'UV_2' + mtex.use_map_color_diffuse = True + + for j, face in enumerate(mesh.uv_textures[1].data): + if (triangle_list[j].tex2 == m.tex2): + face.image = tex_object.image2 + + mesh.lod_level = str(lod_level) + + mesh.validate() + mesh.update() + + meshes.append(mesh) + + return meshes + + +## +# Export UI dialog & operator +## + +EXPORT_FILEPATH = '' + +class ExportColobotDialog(bpy.types.Operator): + bl_idname = 'object.export_colobot_dialog' + bl_label = "Dialog for Colobot export" + + mode = bpy.props.EnumProperty( + name="Mode", + items = [('overwrite', "Overwrite", "Overwrite existing model triangles"), + ('append', "Append", "Append triangles to existing model")], + default='overwrite') + + default_lod_level = bpy.props.EnumProperty( + name="Default LOD level", + items = [('0', "Constant", "Constant (always visible)"), + ('1', "Low", "Low (visible at furthest distance)"), + ('2', "Medium", "Medium (visible at medium distance)"), + ('3', "High", "High (visible at closest distance)")], + default='0') + + default_var_tex2 = bpy.props.BoolProperty(name="Default variable 2nd texture", default=False) + + default_state = bpy.props.IntProperty(name="Default state", default=0) - image2, tex2 = load_tex(m.tex2) - if image2: - mtex = mesh.materials[i].texture_slots.add() - mtex.texture = tex2 - mtex.texture_coords = 'UV' - mtex.uv_layer = 'UV_2' - mtex.use_map_color_diffuse = True + def execute(self, context): + global EXPORT_FILEPATH + try: + defaults = { 'lod_level': self.default_lod_level, + 'var_tex2': self.default_var_tex2, + 'state': self.default_state } - for face in mesh.uv_textures[1].data: - if (model.triangles[j].tex2 == m.tex2): - face.image = image2 + model = ColobotModel() + if (self.mode == 'append'): + model = read_colobot_model(EXPORT_FILEPATH) - mesh.validate() - mesh.update() + for obj in context.selected_objects: + rot = obj.rotation_euler + rot[0] = rot[0] + math.radians(270) + obj.rotation_euler = rot + + append_obj_to_colobot_model(obj, model, context.scene, defaults) + + rot = obj.rotation_euler + rot[0] = rot[0] + math.radians(90) + obj.rotation_euler = rot + + write_colobot_model(EXPORT_FILEPATH, model) + + except ColobotError as e: + self.report({'ERROR'}, e.args.join(": ")) + return {'FINISHED'} + + self.report({'INFO'}, 'Export OK') + return {'FINISHED'} + + def invoke(self, context, event): + context.window_manager.invoke_props_dialog(self, width=500) + return {'RUNNING_MODAL'} - return mesh class ExportColobot(bpy.types.Operator): """Exporter to Colobot text format""" bl_idname = "export.colobot" bl_label = "Export to Colobot" - # TODO: set the following in a UI dialog or panel - - # Variable tex2 - DEFAULT_VAR_TEX2 = False - # Min & max LOD - DEFAULT_MIN = 0.0 - DEFAULT_MAX = 0.0 - # Render state - DEFAULT_STATE = 0 - filepath = bpy.props.StringProperty(subtype="FILE_PATH") @classmethod @@ -486,26 +612,9 @@ class ExportColobot(bpy.types.Operator): return context.object is not None def execute(self, context): - defaults = { - 'var_tex2': self.DEFAULT_VAR_TEX2, - 'min': self.DEFAULT_MIN, - 'max': self.DEFAULT_MAX, - 'state': self.DEFAULT_STATE } - try: - obj = context.object - temp_ROT = obj.rotation_euler - temp_ROT[0] = temp_ROT[0] + math.radians(270) - obj.rotation_euler = temp_ROT - model = mesh_to_colobot_model(context.object, context.scene, defaults) - write_colobot_model(self.filepath, model) - temp_ROT = obj.rotation_euler - temp_ROT[0] = temp_ROT[0] + math.radians(90) - obj.rotation_euler = temp_ROT - except ColobotError as e: - self.report({'ERROR'}, e.args[0]) - return {'FINISHED'} - - self.report({'INFO'}, 'Export OK') + global EXPORT_FILEPATH + EXPORT_FILEPATH = self.filepath + bpy.ops.object.export_colobot_dialog('INVOKE_DEFAULT') return {'FINISHED'} def invoke(self, context, event): @@ -513,11 +622,58 @@ class ExportColobot(bpy.types.Operator): return {'RUNNING_MODAL'} -# For menu item -def export_menu_func(self, context): - self.layout.operator_context = 'INVOKE_DEFAULT' - self.layout.operator(ExportColobot.bl_idname, text="Colobot (Text Format)") +## +# Import UI dialog & operator +# + +IMPORT_FILEPATH = '' + +class ImportColobotDialog(bpy.types.Operator): + bl_idname = 'object.import_colobot_dialog' + bl_label = "Dialog for Colobot import" + + lod_separate_layers = bpy.props.BoolProperty(name="LOD levels to separate layers", default=True) + texture_dir = bpy.props.StringProperty(name="Texture directory", subtype="DIR_PATH") + + def execute(self, context): + global IMPORT_FILEPATH + try: + texture_dir = self.texture_dir + if (texture_dir == ""): + texture_dir = os.path.dirname(IMPORT_FILEPATH) + + model = read_colobot_model(IMPORT_FILEPATH) + meshes = colobot_model_to_meshes(model, 'ColobotMesh_', texture_dir) + index = 0 + for mesh in meshes: + index = index + 1 + obj = bpy.data.objects.new('ColobotMesh_' + str(index), mesh) + + rot = obj.rotation_euler + rot[0] = rot[0] + math.radians(90) + obj.rotation_euler = rot + + bpy.context.scene.objects.link(obj) + bpy.context.scene.objects.active = obj + obj.select = True + + # TODO: doesn't seem to work... + if (self.lod_separate_layers): + layers = obj.layers + for i in range(0, len(layers)): + layers[i] = int(mesh.lod_level) == i + obj.layers = layers + + except ColobotError as e: + self.report({'ERROR'}, e.args.join(": ")) + return {'FINISHED'} + + self.report({'INFO'}, 'Import OK') + return {'FINISHED'} + def invoke(self, context, event): + context.window_manager.invoke_props_dialog(self, width=500) + return {'RUNNING_MODAL'} class ImportColobot(bpy.types.Operator): @@ -532,21 +688,9 @@ class ImportColobot(bpy.types.Operator): return True def execute(self, context): - try: - model = read_colobot_model(self.filepath) - mesh = colobot_model_to_mesh(model, 'ColobotMesh', os.path.dirname(self.filepath)) - obj = bpy.data.objects.new('ColobotMesh', mesh) - temp_ROT = obj.rotation_euler - temp_ROT[0] = temp_ROT[0] + math.radians(90) - obj.rotation_euler = temp_ROT - bpy.context.scene.objects.link(obj) - bpy.context.scene.objects.active = obj - obj.select = True - except ColobotError as e: - self.report({'ERROR'}, e.args[0]) - return {'FINISHED'} - - self.report({'INFO'}, 'Import OK') + global IMPORT_FILEPATH + IMPORT_FILEPATH = self.filepath + bpy.ops.object.import_colobot_dialog('INVOKE_DEFAULT') return {'FINISHED'} def invoke(self, context, event): @@ -554,14 +698,34 @@ class ImportColobot(bpy.types.Operator): return {'RUNNING_MODAL'} -# For menu item +## +# Registration +## + +# Callback functions for menu items +def export_menu_func(self, context): + self.layout.operator_context = 'INVOKE_DEFAULT' + self.layout.operator(ExportColobot.bl_idname, text="Colobot (Text Format)") + def import_menu_func(self, context): self.layout.operator_context = 'INVOKE_DEFAULT' self.layout.operator(ImportColobot.bl_idname, text="Colobot (Text Format)") - +# Custom properties for materials +def register_material_props(): + bpy.types.Mesh.lod_level = bpy.props.EnumProperty(name="LOD level", + items = [('0', "Constant", "Constant (always visible)"), + ('1', "Low", "Low (visible at furthest distance)"), + ('2', "Medium", "Medium (visible at medium distance)"), + ('3', "High", "High (visible at closest distance)")]) + bpy.types.Material.var_tex2 = bpy.props.BoolProperty(name="Variable 2nd texture", description="2nd texture shall be set to dirtyXX.png") + bpy.types.Material.state = bpy.props.IntProperty(name="State", description="Engine render state") + +# Add-on registration def register(): bpy.utils.register_module(__name__) + register_material_props() + bpy.types.INFO_MT_file_export.append(export_menu_func) bpy.types.INFO_MT_file_import.append(import_menu_func) -- cgit v1.2.3-1-g7c22 From 209c6412ae149cc7c503fd7da384f344a830423c Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 3 Feb 2013 20:03:36 +0100 Subject: Refactoring in tests infrastructure * all tests are now in /test/ subdirectory * unit tests concatenated to one executable (TODO: ui, common) * preparation for test environments (OpenGL and others) * removed old TestCBot --- CMakeLists.txt | 14 +- src/CBot/tests/CBot_console/CMakeLists.txt | 17 - src/CBot/tests/CBot_console/src/CBot | 1 - src/CBot/tests/CBot_console/src/CMakeLists.txt | 32 - .../tests/CBot_console/src/app/CBotConsole.cpp | 175 ------ src/CBot/tests/CBot_console/src/app/CBotConsole.h | 44 -- src/CBot/tests/CBot_console/src/app/CBotDoc.cpp | 122 ---- src/CBot/tests/CBot_console/src/app/CBotDoc.h | 39 -- src/CBot/tests/CBot_console/src/app/CClass.cpp | 97 --- src/CBot/tests/CBot_console/src/app/CClass.h | 18 - src/CBot/tests/CBot_console/src/app/main.cpp | 45 -- src/CBot/tests/CBot_console/src/app/routines.cpp | 141 ----- src/CBot/tests/TestCBot/CBotConsoleDlg.cpp | 221 ------- src/CBot/tests/TestCBot/CBotConsoleDlg.h | 85 --- src/CBot/tests/TestCBot/ChildFrm.cpp | 74 --- src/CBot/tests/TestCBot/ChildFrm.h | 66 -- src/CBot/tests/TestCBot/MainFrm.cpp | 116 ---- src/CBot/tests/TestCBot/MainFrm.h | 72 --- src/CBot/tests/TestCBot/PerformDlg.cpp | 177 ------ src/CBot/tests/TestCBot/PerformDlg.h | 78 --- src/CBot/tests/TestCBot/Routines.cpp | 153 ----- src/CBot/tests/TestCBot/StdAfx.cpp | 20 - src/CBot/tests/TestCBot/StdAfx.h | 40 -- src/CBot/tests/TestCBot/TestCBot.clw | 316 ---------- src/CBot/tests/TestCBot/TestCBot.cpp | 267 -------- src/CBot/tests/TestCBot/TestCBot.dsp | 201 ------ src/CBot/tests/TestCBot/TestCBot.h | 78 --- src/CBot/tests/TestCBot/TestCBot.rc | 564 ----------------- src/CBot/tests/TestCBot/TestCBotDoc.cpp | 697 --------------------- src/CBot/tests/TestCBot/TestCBotDoc.h | 78 --- src/CBot/tests/TestCBot/TestCBotView.cpp | 142 ----- src/CBot/tests/TestCBot/TestCBotView.h | 78 --- "src/CBot/tests/TestCBot/a\2471.txt~" | 96 --- src/CBot/tests/TestCBot/res/TestCBot.ico | Bin 1078 -> 0 bytes src/CBot/tests/TestCBot/res/TestCBot.rc2 | 13 - src/CBot/tests/TestCBot/res/TestCBotDoc.ico | Bin 1078 -> 0 bytes src/CBot/tests/TestCBot/res/Toolbar.bmp | Bin 1198 -> 0 bytes src/CBot/tests/TestCBot/resource.h | 44 -- src/CBot/tests/TestCBot/xTestCBot.clw | 245 -------- src/CBot/tests/scenarios/B.txt | 18 - src/CBot/tests/scenarios/BUG2.txt | 107 ---- src/CBot/tests/scenarios/Deleted.txt | 23 - src/CBot/tests/scenarios/MaClass.txt | 16 - src/CBot/tests/scenarios/Mc2.txt | 4 - src/CBot/tests/scenarios/Mon fichier.txt | 2 - src/CBot/tests/scenarios/Nop.txt | 4 - src/CBot/tests/scenarios/POS.txt | 14 - src/CBot/tests/scenarios/T.txt | 4 - src/CBot/tests/scenarios/TESTALL.txt | 161 ----- src/CBot/tests/scenarios/TestCB1.txt | 18 - src/CBot/tests/scenarios/TestCBot1.txt | 27 - src/CBot/tests/scenarios/TestCBot3.txt | 24 - src/CBot/tests/scenarios/TestNull.txt | 15 - src/CBot/tests/scenarios/TestRestoreState.txt | 67 -- src/CBot/tests/scenarios/TestStatic.txt | 31 - src/CBot/tests/scenarios/TestStr.txt | 17 - src/CBot/tests/scenarios/Z.txt | 14 - src/CBot/tests/scenarios/a1.txt | 96 --- src/CBot/tests/scenarios/array.txt | 24 - "src/CBot/tests/scenarios/a\2361.txt" | 96 --- "src/CBot/tests/scenarios/a\2471.txt" | 96 --- src/CBot/tests/scenarios/bug.txt | 12 - src/CBot/tests/scenarios/bugmw.txt | 9 - src/CBot/tests/scenarios/ccc.txt | 8 - src/CBot/tests/scenarios/enum.txt | 9 - src/CBot/tests/scenarios/fibo.txt | 25 - src/CBot/tests/scenarios/file.txt | 70 --- src/CBot/tests/scenarios/h.txt | 5 - src/CBot/tests/scenarios/include.txt | 27 - src/CBot/tests/scenarios/intrinsic.txt | 16 - src/CBot/tests/scenarios/methode1.txt | 57 -- src/CBot/tests/scenarios/methode2.txt | 50 -- src/CBot/tests/scenarios/mp1.txt | 25 - src/CBot/tests/scenarios/mp2.txt | 28 - src/CBot/tests/scenarios/mw.txt | 16 - src/CBot/tests/scenarios/null.txt | 5 - src/CBot/tests/scenarios/opnew.txt | 20 - src/CBot/tests/scenarios/plante.txt | 25 - src/CBot/tests/scenarios/pointer.txt | 41 -- src/CBot/tests/scenarios/postinc.txt | 7 - src/CBot/tests/scenarios/radar.txt | 39 -- src/CBot/tests/scenarios/solution.txt | 13 - src/CBot/tests/scenarios/test.txt | 8 - src/CBot/tests/scenarios/test23.txt | 10 - src/CBot/tests/scenarios/testmw.txt | 14 - src/CBot/tests/scenarios/this.txt | 13 - src/CBot/tests/scenarios/tt.txt | 12 - src/CBot/tests/scenarios/tt2.txt | 5 - src/CBot/tests/scenarios/vide.txt | 0 src/CBot/tests/scenarios/zz.txt | 6 - src/CMakeLists.txt | 8 - src/common/test/CMakeLists.txt | 22 - src/common/test/colobot.ini | 15 - src/common/test/image_test.cpp | 57 -- src/common/test/profile_test.cpp | 44 -- src/graphics/opengl/test/CMakeLists.txt | 90 --- src/graphics/opengl/test/README.txt | 9 - src/graphics/opengl/test/light_test.cpp | 462 -------------- src/graphics/opengl/test/model_test.cpp | 377 ----------- src/graphics/opengl/test/tex1.png | Bin 151263 -> 0 bytes src/graphics/opengl/test/tex2.png | Bin 57503 -> 0 bytes src/graphics/opengl/test/texture_test.cpp | 192 ------ src/graphics/opengl/test/transform_test.cpp | 339 ---------- src/math/test/CMakeLists.txt | 26 - src/math/test/gendata.m | 86 --- src/math/test/geometry_test.cpp | 359 ----------- src/math/test/matrix_test.cpp | 322 ---------- src/math/test/vector_test.cpp | 81 --- src/ui/test/CMakeLists.txt | 36 -- src/ui/test/edit_test.cpp | 73 --- src/ui/test/mocks/text_mock.h | 21 - src/ui/test/stubs/app_stub.cpp | 26 - src/ui/test/stubs/engine_stub.cpp | 79 --- src/ui/test/stubs/particle_stub.cpp | 291 --------- src/ui/test/stubs/restext_stub.cpp | 11 - src/ui/test/stubs/robotmain_stub.cpp | 17 - test/CMakeLists.txt | 13 + test/cbot/CBot_console/CBotConsole.cpp | 175 ++++++ test/cbot/CBot_console/CBotConsole.h | 44 ++ test/cbot/CBot_console/CBotDoc.cpp | 122 ++++ test/cbot/CBot_console/CBotDoc.h | 39 ++ test/cbot/CBot_console/CClass.cpp | 97 +++ test/cbot/CBot_console/CClass.h | 18 + test/cbot/CBot_console/CMakeLists.txt | 16 + test/cbot/CBot_console/main.cpp | 45 ++ test/cbot/CBot_console/routines.cpp | 141 +++++ test/cbot/CMakeLists.txt | 2 + test/cbot/scenarios/B.txt | 18 + test/cbot/scenarios/BUG2.txt | 107 ++++ test/cbot/scenarios/Deleted.txt | 23 + test/cbot/scenarios/MaClass.txt | 16 + test/cbot/scenarios/Mc2.txt | 4 + test/cbot/scenarios/Mon fichier.txt | 2 + test/cbot/scenarios/Nop.txt | 4 + test/cbot/scenarios/POS.txt | 14 + test/cbot/scenarios/T.txt | 4 + test/cbot/scenarios/TESTALL.txt | 161 +++++ test/cbot/scenarios/TestCB1.txt | 18 + test/cbot/scenarios/TestCBot1.txt | 27 + test/cbot/scenarios/TestCBot3.txt | 24 + test/cbot/scenarios/TestNull.txt | 15 + test/cbot/scenarios/TestRestoreState.txt | 67 ++ test/cbot/scenarios/TestStatic.txt | 31 + test/cbot/scenarios/TestStr.txt | 17 + test/cbot/scenarios/Z.txt | 14 + test/cbot/scenarios/a.txt | 312 +++++++++ test/cbot/scenarios/bug.txt | 12 + test/cbot/scenarios/bugmw.txt | 9 + test/cbot/scenarios/ccc.txt | 8 + test/cbot/scenarios/enum.txt | 9 + test/cbot/scenarios/fibo.txt | 25 + test/cbot/scenarios/file.txt | 70 +++ test/cbot/scenarios/h.txt | 5 + test/cbot/scenarios/include.txt | 27 + test/cbot/scenarios/intrinsic.txt | 16 + test/cbot/scenarios/methode1.txt | 57 ++ test/cbot/scenarios/methode2.txt | 50 ++ test/cbot/scenarios/mp1.txt | 25 + test/cbot/scenarios/mp2.txt | 28 + test/cbot/scenarios/mw.txt | 16 + test/cbot/scenarios/null.txt | 5 + test/cbot/scenarios/opnew.txt | 20 + test/cbot/scenarios/plante.txt | 25 + test/cbot/scenarios/pointer.txt | 41 ++ test/cbot/scenarios/postinc.txt | 7 + test/cbot/scenarios/radar.txt | 39 ++ test/cbot/scenarios/solution.txt | 13 + test/cbot/scenarios/test.txt | 8 + test/cbot/scenarios/test23.txt | 10 + test/cbot/scenarios/testmw.txt | 14 + test/cbot/scenarios/this.txt | 13 + test/cbot/scenarios/tt.txt | 12 + test/cbot/scenarios/tt2.txt | 5 + test/cbot/scenarios/vide.txt | 0 test/cbot/scenarios/zz.txt | 6 + test/envs/CMakeLists.txt | 2 + test/envs/opengl/CMakeLists.txt | 63 ++ test/envs/opengl/README.txt | 9 + test/envs/opengl/light_test.cpp | 462 ++++++++++++++ test/envs/opengl/model_test.cpp | 377 +++++++++++ test/envs/opengl/tex1.png | Bin 0 -> 151263 bytes test/envs/opengl/tex2.png | Bin 0 -> 57503 bytes test/envs/opengl/texture_test.cpp | 192 ++++++ test/envs/opengl/transform_test.cpp | 339 ++++++++++ test/unit/CMakeLists.txt | 24 + test/unit/common/CMakeLists.txt | 16 + test/unit/common/colobot.ini | 15 + test/unit/common/image_test.cpp | 57 ++ test/unit/common/profile_test.cpp | 43 ++ test/unit/main.cpp | 24 + test/unit/math/gendata.m | 86 +++ test/unit/math/geometry_test.cpp | 352 +++++++++++ test/unit/math/matrix_test.cpp | 314 ++++++++++ test/unit/math/vector_test.cpp | 74 +++ test/unit/ui/CMakeLists.txt | 29 + test/unit/ui/edit_test.cpp | 74 +++ test/unit/ui/mocks/text_mock.h | 21 + test/unit/ui/stubs/app_stub.cpp | 26 + test/unit/ui/stubs/engine_stub.cpp | 79 +++ test/unit/ui/stubs/particle_stub.cpp | 205 ++++++ test/unit/ui/stubs/restext_stub.cpp | 12 + test/unit/ui/stubs/robotmain_stub.cpp | 17 + 202 files changed, 5086 insertions(+), 9153 deletions(-) delete mode 100644 src/CBot/tests/CBot_console/CMakeLists.txt delete mode 120000 src/CBot/tests/CBot_console/src/CBot delete mode 100644 src/CBot/tests/CBot_console/src/CMakeLists.txt delete mode 100644 src/CBot/tests/CBot_console/src/app/CBotConsole.cpp delete mode 100644 src/CBot/tests/CBot_console/src/app/CBotConsole.h delete mode 100644 src/CBot/tests/CBot_console/src/app/CBotDoc.cpp delete mode 100644 src/CBot/tests/CBot_console/src/app/CBotDoc.h delete mode 100644 src/CBot/tests/CBot_console/src/app/CClass.cpp delete mode 100644 src/CBot/tests/CBot_console/src/app/CClass.h delete mode 100644 src/CBot/tests/CBot_console/src/app/main.cpp delete mode 100644 src/CBot/tests/CBot_console/src/app/routines.cpp delete mode 100644 src/CBot/tests/TestCBot/CBotConsoleDlg.cpp delete mode 100644 src/CBot/tests/TestCBot/CBotConsoleDlg.h delete mode 100644 src/CBot/tests/TestCBot/ChildFrm.cpp delete mode 100644 src/CBot/tests/TestCBot/ChildFrm.h delete mode 100644 src/CBot/tests/TestCBot/MainFrm.cpp delete mode 100644 src/CBot/tests/TestCBot/MainFrm.h delete mode 100644 src/CBot/tests/TestCBot/PerformDlg.cpp delete mode 100644 src/CBot/tests/TestCBot/PerformDlg.h delete mode 100644 src/CBot/tests/TestCBot/Routines.cpp delete mode 100644 src/CBot/tests/TestCBot/StdAfx.cpp delete mode 100644 src/CBot/tests/TestCBot/StdAfx.h delete mode 100644 src/CBot/tests/TestCBot/TestCBot.clw delete mode 100644 src/CBot/tests/TestCBot/TestCBot.cpp delete mode 100644 src/CBot/tests/TestCBot/TestCBot.dsp delete mode 100644 src/CBot/tests/TestCBot/TestCBot.h delete mode 100644 src/CBot/tests/TestCBot/TestCBot.rc delete mode 100644 src/CBot/tests/TestCBot/TestCBotDoc.cpp delete mode 100644 src/CBot/tests/TestCBot/TestCBotDoc.h delete mode 100644 src/CBot/tests/TestCBot/TestCBotView.cpp delete mode 100644 src/CBot/tests/TestCBot/TestCBotView.h delete mode 100644 "src/CBot/tests/TestCBot/a\2471.txt~" delete mode 100644 src/CBot/tests/TestCBot/res/TestCBot.ico delete mode 100644 src/CBot/tests/TestCBot/res/TestCBot.rc2 delete mode 100644 src/CBot/tests/TestCBot/res/TestCBotDoc.ico delete mode 100644 src/CBot/tests/TestCBot/res/Toolbar.bmp delete mode 100644 src/CBot/tests/TestCBot/resource.h delete mode 100644 src/CBot/tests/TestCBot/xTestCBot.clw delete mode 100644 src/CBot/tests/scenarios/B.txt delete mode 100644 src/CBot/tests/scenarios/BUG2.txt delete mode 100644 src/CBot/tests/scenarios/Deleted.txt delete mode 100644 src/CBot/tests/scenarios/MaClass.txt delete mode 100644 src/CBot/tests/scenarios/Mc2.txt delete mode 100644 src/CBot/tests/scenarios/Mon fichier.txt delete mode 100644 src/CBot/tests/scenarios/Nop.txt delete mode 100644 src/CBot/tests/scenarios/POS.txt delete mode 100644 src/CBot/tests/scenarios/T.txt delete mode 100644 src/CBot/tests/scenarios/TESTALL.txt delete mode 100644 src/CBot/tests/scenarios/TestCB1.txt delete mode 100644 src/CBot/tests/scenarios/TestCBot1.txt delete mode 100644 src/CBot/tests/scenarios/TestCBot3.txt delete mode 100644 src/CBot/tests/scenarios/TestNull.txt delete mode 100644 src/CBot/tests/scenarios/TestRestoreState.txt delete mode 100644 src/CBot/tests/scenarios/TestStatic.txt delete mode 100644 src/CBot/tests/scenarios/TestStr.txt delete mode 100644 src/CBot/tests/scenarios/Z.txt delete mode 100644 src/CBot/tests/scenarios/a1.txt delete mode 100644 src/CBot/tests/scenarios/array.txt delete mode 100644 "src/CBot/tests/scenarios/a\2361.txt" delete mode 100644 "src/CBot/tests/scenarios/a\2471.txt" delete mode 100644 src/CBot/tests/scenarios/bug.txt delete mode 100644 src/CBot/tests/scenarios/bugmw.txt delete mode 100644 src/CBot/tests/scenarios/ccc.txt delete mode 100644 src/CBot/tests/scenarios/enum.txt delete mode 100644 src/CBot/tests/scenarios/fibo.txt delete mode 100644 src/CBot/tests/scenarios/file.txt delete mode 100644 src/CBot/tests/scenarios/h.txt delete mode 100644 src/CBot/tests/scenarios/include.txt delete mode 100644 src/CBot/tests/scenarios/intrinsic.txt delete mode 100644 src/CBot/tests/scenarios/methode1.txt delete mode 100644 src/CBot/tests/scenarios/methode2.txt delete mode 100644 src/CBot/tests/scenarios/mp1.txt delete mode 100644 src/CBot/tests/scenarios/mp2.txt delete mode 100644 src/CBot/tests/scenarios/mw.txt delete mode 100644 src/CBot/tests/scenarios/null.txt delete mode 100644 src/CBot/tests/scenarios/opnew.txt delete mode 100644 src/CBot/tests/scenarios/plante.txt delete mode 100644 src/CBot/tests/scenarios/pointer.txt delete mode 100644 src/CBot/tests/scenarios/postinc.txt delete mode 100644 src/CBot/tests/scenarios/radar.txt delete mode 100644 src/CBot/tests/scenarios/solution.txt delete mode 100644 src/CBot/tests/scenarios/test.txt delete mode 100644 src/CBot/tests/scenarios/test23.txt delete mode 100644 src/CBot/tests/scenarios/testmw.txt delete mode 100644 src/CBot/tests/scenarios/this.txt delete mode 100644 src/CBot/tests/scenarios/tt.txt delete mode 100644 src/CBot/tests/scenarios/tt2.txt delete mode 100644 src/CBot/tests/scenarios/vide.txt delete mode 100644 src/CBot/tests/scenarios/zz.txt delete mode 100644 src/common/test/CMakeLists.txt delete mode 100644 src/common/test/colobot.ini delete mode 100644 src/common/test/image_test.cpp delete mode 100644 src/common/test/profile_test.cpp delete mode 100644 src/graphics/opengl/test/CMakeLists.txt delete mode 100644 src/graphics/opengl/test/README.txt delete mode 100644 src/graphics/opengl/test/light_test.cpp delete mode 100644 src/graphics/opengl/test/model_test.cpp delete mode 100644 src/graphics/opengl/test/tex1.png delete mode 100644 src/graphics/opengl/test/tex2.png delete mode 100644 src/graphics/opengl/test/texture_test.cpp delete mode 100644 src/graphics/opengl/test/transform_test.cpp delete mode 100644 src/math/test/CMakeLists.txt delete mode 100644 src/math/test/gendata.m delete mode 100644 src/math/test/geometry_test.cpp delete mode 100644 src/math/test/matrix_test.cpp delete mode 100644 src/math/test/vector_test.cpp delete mode 100644 src/ui/test/CMakeLists.txt delete mode 100644 src/ui/test/edit_test.cpp delete mode 100644 src/ui/test/mocks/text_mock.h delete mode 100644 src/ui/test/stubs/app_stub.cpp delete mode 100644 src/ui/test/stubs/engine_stub.cpp delete mode 100644 src/ui/test/stubs/particle_stub.cpp delete mode 100644 src/ui/test/stubs/restext_stub.cpp delete mode 100644 src/ui/test/stubs/robotmain_stub.cpp create mode 100644 test/CMakeLists.txt create mode 100644 test/cbot/CBot_console/CBotConsole.cpp create mode 100644 test/cbot/CBot_console/CBotConsole.h create mode 100644 test/cbot/CBot_console/CBotDoc.cpp create mode 100644 test/cbot/CBot_console/CBotDoc.h create mode 100644 test/cbot/CBot_console/CClass.cpp create mode 100644 test/cbot/CBot_console/CClass.h create mode 100644 test/cbot/CBot_console/CMakeLists.txt create mode 100644 test/cbot/CBot_console/main.cpp create mode 100644 test/cbot/CBot_console/routines.cpp create mode 100644 test/cbot/CMakeLists.txt create mode 100644 test/cbot/scenarios/B.txt create mode 100644 test/cbot/scenarios/BUG2.txt create mode 100644 test/cbot/scenarios/Deleted.txt create mode 100644 test/cbot/scenarios/MaClass.txt create mode 100644 test/cbot/scenarios/Mc2.txt create mode 100644 test/cbot/scenarios/Mon fichier.txt create mode 100644 test/cbot/scenarios/Nop.txt create mode 100644 test/cbot/scenarios/POS.txt create mode 100644 test/cbot/scenarios/T.txt create mode 100644 test/cbot/scenarios/TESTALL.txt create mode 100644 test/cbot/scenarios/TestCB1.txt create mode 100644 test/cbot/scenarios/TestCBot1.txt create mode 100644 test/cbot/scenarios/TestCBot3.txt create mode 100644 test/cbot/scenarios/TestNull.txt create mode 100644 test/cbot/scenarios/TestRestoreState.txt create mode 100644 test/cbot/scenarios/TestStatic.txt create mode 100644 test/cbot/scenarios/TestStr.txt create mode 100644 test/cbot/scenarios/Z.txt create mode 100644 test/cbot/scenarios/a.txt create mode 100644 test/cbot/scenarios/bug.txt create mode 100644 test/cbot/scenarios/bugmw.txt create mode 100644 test/cbot/scenarios/ccc.txt create mode 100644 test/cbot/scenarios/enum.txt create mode 100644 test/cbot/scenarios/fibo.txt create mode 100644 test/cbot/scenarios/file.txt create mode 100644 test/cbot/scenarios/h.txt create mode 100644 test/cbot/scenarios/include.txt create mode 100644 test/cbot/scenarios/intrinsic.txt create mode 100644 test/cbot/scenarios/methode1.txt create mode 100644 test/cbot/scenarios/methode2.txt create mode 100644 test/cbot/scenarios/mp1.txt create mode 100644 test/cbot/scenarios/mp2.txt create mode 100644 test/cbot/scenarios/mw.txt create mode 100644 test/cbot/scenarios/null.txt create mode 100644 test/cbot/scenarios/opnew.txt create mode 100644 test/cbot/scenarios/plante.txt create mode 100644 test/cbot/scenarios/pointer.txt create mode 100644 test/cbot/scenarios/postinc.txt create mode 100644 test/cbot/scenarios/radar.txt create mode 100644 test/cbot/scenarios/solution.txt create mode 100644 test/cbot/scenarios/test.txt create mode 100644 test/cbot/scenarios/test23.txt create mode 100644 test/cbot/scenarios/testmw.txt create mode 100644 test/cbot/scenarios/this.txt create mode 100644 test/cbot/scenarios/tt.txt create mode 100644 test/cbot/scenarios/tt2.txt create mode 100644 test/cbot/scenarios/vide.txt create mode 100644 test/cbot/scenarios/zz.txt create mode 100644 test/envs/CMakeLists.txt create mode 100644 test/envs/opengl/CMakeLists.txt create mode 100644 test/envs/opengl/README.txt create mode 100644 test/envs/opengl/light_test.cpp create mode 100644 test/envs/opengl/model_test.cpp create mode 100644 test/envs/opengl/tex1.png create mode 100644 test/envs/opengl/tex2.png create mode 100644 test/envs/opengl/texture_test.cpp create mode 100644 test/envs/opengl/transform_test.cpp create mode 100644 test/unit/CMakeLists.txt create mode 100644 test/unit/common/CMakeLists.txt create mode 100644 test/unit/common/colobot.ini create mode 100644 test/unit/common/image_test.cpp create mode 100644 test/unit/common/profile_test.cpp create mode 100644 test/unit/main.cpp create mode 100644 test/unit/math/gendata.m create mode 100644 test/unit/math/geometry_test.cpp create mode 100644 test/unit/math/matrix_test.cpp create mode 100644 test/unit/math/vector_test.cpp create mode 100644 test/unit/ui/CMakeLists.txt create mode 100644 test/unit/ui/edit_test.cpp create mode 100644 test/unit/ui/mocks/text_mock.h create mode 100644 test/unit/ui/stubs/app_stub.cpp create mode 100644 test/unit/ui/stubs/engine_stub.cpp create mode 100644 test/unit/ui/stubs/particle_stub.cpp create mode 100644 test/unit/ui/stubs/restext_stub.cpp create mode 100644 test/unit/ui/stubs/robotmain_stub.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index aa05134..ec457bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,7 +69,7 @@ endif() # Global compile flags # These are specific to GCC/MinGW/clang; for other compilers, change as necessary -# The flags are used throughout src/ subdir +# The flags are used throughout src/ and test/ subdirs set(COLOBOT_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wold-style-cast ${CXX11_FLAGS}") set(COLOBOT_CXX_FLAGS_RELEASE "-O2") set(COLOBOT_CXX_FLAGS_DEBUG "-g -O0") @@ -151,7 +151,6 @@ endif() if(${TESTS}) add_definitions(-DTEST_VIRTUAL=virtual) - enable_testing() else() add_definitions(-DTEST_VIRTUAL=) endif() @@ -206,6 +205,11 @@ if(${TESTS}) add_subdirectory(${GMOCK_SRC_DIR} bin/gmock) endif() + + # Tests targets + enable_testing() + add_subdirectory(test bin/test) + endif() # Installation paths defined before compiling sources @@ -225,10 +229,10 @@ add_subdirectory(src bin) # Data: check if the submodule handles its own installation if(EXISTS "${CMAKE_SOURCE_DIR}/data/CMakeLists.txt") - message(STATUS "Data directory will install itself.") - add_subdirectory(data) + message(STATUS "Data directory will install itself.") + add_subdirectory(data) else() - message(WARNING "Data directory is not available; make sure colobot-data is installed in ${COLOBOT_INSTALL_DATA_DIR}.") + message(WARNING "Data directory is not available; make sure colobot-data is installed in ${COLOBOT_INSTALL_DATA_DIR}.") endif() # Documentation diff --git a/src/CBot/tests/CBot_console/CMakeLists.txt b/src/CBot/tests/CBot_console/CMakeLists.txt deleted file mode 100644 index f76dedf..0000000 --- a/src/CBot/tests/CBot_console/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -cmake_minimum_required(VERSION 2.8) - -project(CBot_console C CXX) - -# Build with debugging symbols -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE debug) -endif(NOT CMAKE_BUILD_TYPE) - -# Global compile flags -set(CMAKE_CXX_FLAGS_RELEASE "-O2") -set(CMAKE_CXX_FLAGS_DEBUG "-g -O0") - -# Include cmake directory -SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${colobot_SOURCE_DIR}/cmake") - -add_subdirectory(src bin) diff --git a/src/CBot/tests/CBot_console/src/CBot b/src/CBot/tests/CBot_console/src/CBot deleted file mode 120000 index 2c91115..0000000 --- a/src/CBot/tests/CBot_console/src/CBot +++ /dev/null @@ -1 +0,0 @@ -../../../../CBot/ \ No newline at end of file diff --git a/src/CBot/tests/CBot_console/src/CMakeLists.txt b/src/CBot/tests/CBot_console/src/CMakeLists.txt deleted file mode 100644 index 3dbf711..0000000 --- a/src/CBot/tests/CBot_console/src/CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -# CBot shared library is built separately -add_subdirectory(CBot) - - -# Configure options -option(DEBUG "Enable debug output" ON) - -set(PLATFORM_LIBS "") - -# Source files -# Commented out files are still dependent on DirectX or WinAPI - -set(SOURCES -app/CClass.cpp -app/main.cpp -#app/routines.cpp -app/CBotDoc.cpp -app/CBotConsole.cpp -) - -set(LIBS -CBot -) - -include_directories(. ${CMAKE_CURRENT_BINARY_DIR} -) - -link_directories(${CMAKE_CURRENT_SOURCE_DIR}/CBot) - -add_executable(CBot_console ${SOURCES}) - -target_link_libraries(CBot_console ${LIBS}) diff --git a/src/CBot/tests/CBot_console/src/app/CBotConsole.cpp b/src/CBot/tests/CBot_console/src/app/CBotConsole.cpp deleted file mode 100644 index e9209d3..0000000 --- a/src/CBot/tests/CBot_console/src/app/CBotConsole.cpp +++ /dev/null @@ -1,175 +0,0 @@ -/* - * CBotConsole.cpp - * - * Created on: 08-08-2012 - * Author: michal - */ - -#include "CBotConsole.h" -#include "CClass.h" -#include -#include - -CBotConsole::CBotConsole() { - // TODO Auto-generated constructor stub - m_pProg = NULL; - m_threadinfo.m_bRun = false; - m_code = 0; - -} - -CBotConsole::~CBotConsole() { - // TODO Auto-generated destructor stub -} - -uint ThreadProc(ThreadInfo *info) -{ - time_t t0,t1; - time(&t0); - - int Cpt = 0; - - info->m_pProg->Start("LaCommande"); - while ( !info->m_bStop && !info->m_pProg->Run() ) - { -#if 0 - const char* FunctionName; - const char* FN; - int start, end; - - info->m_pProg->GetRunPos(FunctionName, start, end); - - if ( FunctionName != NULL ) - { - info->m_pEditx->SetSel(start, end); - - char buffer[200]; - sprintf( buffer, "step %s, %d, %d",FunctionName, start, end); - AfxMessageBox( buffer ); - - int level = 0; - do - { - CBotVar* t = info->m_pProg->GetStackVars(FN, level--); - if ( FN != FunctionName ) break; - if ( t != NULL ) - { - CString s ; - while ( t != NULL ) - { - if (s.IsEmpty()) s+= "Stack -> "; - else s+= " , "; - s += t->GetValString(); - t = t->GetNext(); - } - AfxMessageBox(s); - } - } while (TRUE); - } -#endif - Cpt++; - if ( Cpt%50 == 0 ) std::cout << "."; - } - - if ( info->m_bStop ) - { - std::cout << "\nInterrupt\n"; - } - else if (info->m_pProg->GetError() == 0) - { - time(&t1); - double prog_time = difftime(t0,t1); - - char buffer[200]; - sprintf( buffer, "\nExecution terminated in %f seconds.\nInterrupted %d time(s).\n", - prog_time, Cpt); - - std::cout << buffer; - } - -// info->m_pWndMessage->SendMessage(WM_ENDPROG, 0, 0) ; - return 0 ; -} - -long CBotConsole::EndProg() -{ - m_threadinfo.m_bRun = false; - - if (m_pProg->GetError(m_code, m_start, m_end)) - { - CBotString TextError; - TextError = CBotProgram::GetErrorText(m_code); - std::cout << TextError; - return 1; - } - delete m_pProg; - m_pProg = NULL; - - return 0 ; -} - - -void CBotConsole::OnOK() -{ - m_code = 0; - - std::string Commande; - std::cin >> Commande; - - std::string s = "void LaCommande() { " + Commande + " ;}"; - m_pProg = new CBotProgram(); - CBotStringArray liste; - m_pProg->Compile(s.c_str(), liste); - - int err, start, end; - if ( m_pProg->GetError(err, start, end) ) - { - CBotString TextError; - TextError = CBotProgram::GetErrorText(err); - std::cout << TextError; - return; - } - - std::cout << "\n" + Commande + " ->\n"; - -// m_Edit2.SetWindowText(""); -// m_Edit1.SetFocus(); -// m_Edit2.EnableWindow(FALSE); -// m_cOK.EnableWindow(FALSE); - - // lance un processus paralèle pour l'exécution -// m_threadinfo.m_pWndMessage = this ; - -// m_threadinfo.m_pEdit1 = &m_Edit1; -// m_threadinfo.m_pEditx = m_pEditx; - m_threadinfo.m_pProg = m_pProg; - m_threadinfo.m_bStop = false; - m_threadinfo.m_bRun = true; - - ThreadProc(&m_threadinfo); - -// here program starts -// AfxBeginThread((AFX_THREADPROC)ThreadProc, &m_threadinfo) ; -} - -void CBotConsole::OnCancel() -{ - m_threadinfo.m_bStop = true ; -} - -bool CBotConsole::OnInitDialog() -{ -// CDialog::OnInitDialog(); - - std::cout << "Following functions are availible:\n"; - for ( int i = 0; i < m_pListe->GetSize(); i++ ) - { - CBotString x = (*m_pListe)[i] + CBotString("\n"); - std::cout << x; - } - std::cout << "Enter a command:\n"; - - - return true; // return TRUE unless you set the focus to a control - // EXCEPTION: OCX Property Pages should return FALSE -} diff --git a/src/CBot/tests/CBot_console/src/app/CBotConsole.h b/src/CBot/tests/CBot_console/src/app/CBotConsole.h deleted file mode 100644 index a155399..0000000 --- a/src/CBot/tests/CBot_console/src/app/CBotConsole.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * CBotConsole.h - * - * Created on: 08-08-2012 - * Author: michal - */ - -#ifndef CBOTCONSOLE_H_ -#define CBOTCONSOLE_H_ -#include "CClass.h" - -struct ThreadInfo -{ -// CEdit* m_pEdit1 ; -// CEdit* m_pEditx ; - CBotProgram* m_pProg; -// CWnd* m_pWndMessage; - bool m_bStop; - bool m_bRun; -}; - -class CBotConsole { - -public: - CBotConsole(); - virtual ~CBotConsole(); - -// CEdit m_Edit1; - - CBotProgram* m_pProg; - ThreadInfo m_threadinfo; - - CBotStringArray* m_pListe; - int m_code, m_start, m_end; -// CEdit* m_pEditx; - - // Implementation - void OnOK(); - void OnCancel(); - bool OnInitDialog(); - long EndProg() ; -}; - -#endif /* CBOTCONSOLE_H_ */ diff --git a/src/CBot/tests/CBot_console/src/app/CBotDoc.cpp b/src/CBot/tests/CBot_console/src/app/CBotDoc.cpp deleted file mode 100644 index 1c694c9..0000000 --- a/src/CBot/tests/CBot_console/src/app/CBotDoc.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/* - * CBotDoc.cpp - * - * Created on: 08-08-2012 - * Author: michal - */ -#include "CBotDoc.h" -#include "CBotConsole.h" -#include - -CBotDoc::CBotDoc(std::string s) { - // TODO Auto-generated constructor stub - // TODO set m_DocText -// m_pEdit = NULL; - m_pProg = NULL; -// m_bModified = FALSE; - m_DocText = s; - std::cout << s << std::endl; -// std::cout << "Enter to continue..." << std::endl; -// getchar(); -} - -CBotDoc::~CBotDoc() { - -// delete m_pEdit; - delete m_pProg; -} - - -//static bool test = false; - -void CBotDoc::OnRun() -{ - -// m_pEdit->GetWindowText(m_DocText); - CBotString s; - - std::string TextError; - int code, start, end; - - if ( m_pProg == NULL ) m_pProg = new CBotProgram(); - - if (!m_pProg->Compile(m_DocText.c_str(), m_Liste, NULL)) - { - m_pProg->GetError(code, start, end); - delete m_pProg; - m_pProg = NULL; - - TextError = CBotProgram::GetErrorText( code ); - std::cout << TextError << std::endl; - return; - } - - if( m_Liste.GetSize() == 0 ) - { - std::cout << "No function marked \"extern\" !\n"; - return; - } - - for ( int i = 0; i < m_Liste.GetSize(); i++ ) - { - int start, stop; - m_pProg->GetPosition(m_Liste[i], start, stop, GetPosNom, GetPosParam); - CBotString s(m_DocText.substr( start, stop-start ).c_str()); - m_Liste[i] = s; - } -// TODO - CBotConsole dlg; - dlg.m_pListe = &m_Liste; -// dlg.m_pEditx = m_pEdit; - - dlg.OnInitDialog(); - dlg.OnOK(); - dlg.EndProg(); -// if ( dlg.m_code>0 ) -// { -// std::string TextError; -// -// TextError = m_pProg->GetErrorText( dlg.m_code ); -// -// std::cout <GetWindowText(m_DocText); - - std::string TextError; - int code, start, end; - - if ( m_pProg == NULL ) m_pProg = new CBotProgram(); - - char buffer[100]; - strcpy(buffer, "a pointer move to see"); - - if (!m_pProg->Compile(m_DocText.c_str(), m_Liste, static_cast(buffer))) - { - m_pProg->GetError(code, start, end); - delete m_pProg; - m_pProg = NULL; - -// m_pEdit->SetSel( start, end ); -// m_pEdit->SetFocus(); // higlights part of problem - - TextError = CBotProgram::GetErrorText( code ); - std::cout << TextError ; - - return false; - } - -// if ( m_pProg->GetPosition( "TheTest", start, end) ) -// { -// m_pEdit->SetSel( start, end ); -// m_pEdit->SetFocus(); // higlights part of problem -// } - -// m_bModified = FALSE; - return true; -} diff --git a/src/CBot/tests/CBot_console/src/app/CBotDoc.h b/src/CBot/tests/CBot_console/src/app/CBotDoc.h deleted file mode 100644 index c0a3e1d..0000000 --- a/src/CBot/tests/CBot_console/src/app/CBotDoc.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * CBotDoc.h - * - * Created on: 08-08-2012 - * Author: michal - */ - -#pragma once -#ifndef CBOTDOC_H_ -#define CBOTDOC_H_ - -#include "CClass.h" -#include - -class CBotDoc { - -public: - CBotDoc(std::string); - virtual ~CBotDoc(); - -// CEdit* m_pEdit; // to memorize the text, and display - CBotProgram* m_pProg; // the compiled program - std::string m_DocText; - CBotStringArray m_Liste; - -// Operations - - bool Compile(); - -// virtual bool OnNewDocument(); - - void OnRun(); - void OnChangeEdit1(); - void OnTest(); - -}; - - -#endif /* CBOTDOC_H_ */ diff --git a/src/CBot/tests/CBot_console/src/app/CClass.cpp b/src/CBot/tests/CBot_console/src/app/CClass.cpp deleted file mode 100644 index 9b7c842..0000000 --- a/src/CBot/tests/CBot_console/src/app/CClass.cpp +++ /dev/null @@ -1,97 +0,0 @@ -#include "CClass.h" - -#include "routines.cpp" - -void rMajObject( CBotVar* pThis, void* pUser ) -{ - if (!pThis->IsElemOfClass("object")) - return ; - CBotVar* pPos = pThis->GetItem("position"); - CBotVar* pX = pPos->GetItem("x"); - CBotVar* pY = pPos->GetItem("y"); - CBotVar* pZ = pPos->GetItem("z"); -// CBotVar* pPt = pThis->GetItem("transport"); - - CBotString p = pX->GetValString(); - -// pX->SetValFloat( pUser == (void*)1 ? (float)12.5 : (float)44.4 ); - pZ->SetValFloat( (float)0 ); - pY->SetValFloat( (float)-3.33 ); - pX->SetValFloat( pX->GetValFloat() + 10 ) ; - -// pX = pThis->GetItem( "xx" ); -// pX->SetValFloat( (float)22 ); - - // crée une instance sur une classe object -// CBotVar* pAutre = CBotVar::Create("autre", CBotTypClass, "object"); -// pAutre->SetUserPtr( (void*)3 ); -// pPt->SetPointer( pAutre ); -// pPt->SetPointer( NULL ); -// delete pAutre; -}; - -CClass::CClass() -{ - m_pClassPoint= NULL; -} - -bool CClass::InitInstance() -{ -////////////////////////////////////////////// -// défini les mots clefs supplémentaires -// ------------------------------------------- - - CBotProgram::Init(); - -////////////////////////////////////////////// -// défini les fonctions "show()" et "print()" -// ------------------------------------------- - - //CBotProgram::AddFunction("show", rShow, cShow); - CBotProgram::AddFunction("print", rPrint, cPrint); - CBotProgram::AddFunction("println", rPrintLn, cPrint); - - -/////////////////////////////////// -// définie la classe globale CPoint -// -------------------------------- - - m_pClassPoint = new CBotClass("CPoint", NULL); - // ajoute le composant ".x" - m_pClassPoint->AddItem("x", CBotTypFloat); - // ajoute le composant ".y" - m_pClassPoint->AddItem("y", CBotTypFloat); - - // ajoute le constructeur pour cette classe - m_pClassPoint->AddFunction("CPoint", rCPoint, cCPoint); - - m_pClassPointIntr = new CBotClass("point", NULL, true); - // ajoute le composant ".x" - m_pClassPointIntr->AddItem("x", CBotTypFloat); - // ajoute le composant ".y" - m_pClassPointIntr->AddItem("y", CBotTypFloat); - // ajoute le composant ".z" - m_pClassPointIntr->AddItem("z", CBotTypFloat); - - // ajoute le constructeur pour cette classe - m_pClassPointIntr->AddFunction("point", rCPoint, cCPoint); - - // défini la classe "object" - CBotClass* pClassObject = new CBotClass( "object", NULL ) ; - pClassObject->AddItem( "xx", CBotTypFloat ); - pClassObject->AddItem( "position", CBotTypResult( CBotTypIntrinsic, "point" ) ); - pClassObject->AddItem( "transport", CBotTypResult( CBotTypPointer, "object" ) ); - pClassObject->AddUpdateFunc( rMajObject ); - - InitClassFILE(); - - return true; -} - -void CClass::ExitInstance() -{ - delete m_pFuncFile; - - CBotProgram::Free(); - -} diff --git a/src/CBot/tests/CBot_console/src/app/CClass.h b/src/CBot/tests/CBot_console/src/app/CClass.h deleted file mode 100644 index da2c46c..0000000 --- a/src/CBot/tests/CBot_console/src/app/CClass.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include -#include - -extern std::string s; - -class CClass -{ -public: - CClass(); - - CBotClass* m_pClassPoint; - CBotClass* m_pClassPointIntr; - - bool InitInstance(); - void ExitInstance(); -}; diff --git a/src/CBot/tests/CBot_console/src/app/main.cpp b/src/CBot/tests/CBot_console/src/app/main.cpp deleted file mode 100644 index a2d3668..0000000 --- a/src/CBot/tests/CBot_console/src/app/main.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "CClass.h" -#include "CBotDoc.h" -#include - - -#include - -std::string str; - -// routine to update the instance of the class Bot common - -int main(int argc, char* argv[]) -{ - CClass newclass; - CBotDoc *botdoc; - if (argc != 2) - { - std::cout << "Usage: "<" << std::endl; - return 0; - } - - std::ifstream in(argv[1]); - std::cout << argv[1] << std::endl; - if (!in.good()) - { - std::cout << "Oh no, error!" << std::endl; - return 1; - } - - std::string contents((std::istreambuf_iterator(in)), - std::istreambuf_iterator()); - str = contents; - - if(!newclass.InitInstance()) - { - std::cerr << "Initialization not complete!" << std::endl; - return 1; - } - - botdoc = new CBotDoc(str); -// std::cout << "Hello CBot!" << std::endl << s; - botdoc->OnRun(); - delete botdoc; - newclass.ExitInstance(); -} diff --git a/src/CBot/tests/CBot_console/src/app/routines.cpp b/src/CBot/tests/CBot_console/src/app/routines.cpp deleted file mode 100644 index 8b8a1d4..0000000 --- a/src/CBot/tests/CBot_console/src/app/routines.cpp +++ /dev/null @@ -1,141 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/. - -//////////////////////////////////////////////////////////////////// -// routine show() -// utilisable depuis le programme écrit en CBot - - -#include -#include -#include "CBot/ClassFILE.cpp" -//std::string s; -/* -// execution -bool rShow( CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser ) -{ - string::string s; - - while ( pVar != NULL ) - { - string::string ss; - - ss.LoadString( TX_TYPENAMES + pVar->GetType() ); - s += ss + " "; - - ss = pVar->GetName(); - if (ss.IsEmpty()) ss = ""; - s += ss + " = "; - - s += pVar->GetValString(); - s += "\n"; - pVar = pVar->GetNext(); - } - - AfxMessageBox(s, MB_OK|MB_ICONINFORMATION); - - return TRUE; // pas d'interruption -} - -CBotTypResult cShow( CBotVar* &pVar, void* pUser) -{ - if ( pVar == NULL ) return CBotTypResult(5028); - return CBotTypResult(0); // tous paramètres acceptés, void en retour -} - -*/ - -//////////////////////////////////////////////////////////////////// -// routine print() -// utilisable depuis le programme écrit en CBot - -// exécution - -bool rPrintLn( CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser ) -{ - std::string s; - while ( pVar != NULL ) - { - if ( !s.empty() ) s += " "; - s += pVar->GetValString(); - pVar = pVar->GetNext(); - } - s += "\n"; - - std::cout << s; - return true; // pas d'interruption -} - -bool rPrint( CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser ) -{ - std::string s; - while ( pVar != NULL ) - { - if ( !s.empty() ) s += " "; - s += pVar->GetValString(); - pVar = pVar->GetNext(); - } - s += " "; - std::cout << s; - return true; // pas d'interruption -} - -CBotTypResult cPrint( CBotVar* &pVar, void* pUser) -{ - return CBotTypResult(0); // tous paramètres acceptés, un entier en retour -} - - -////////////////////////////////////////////////////////////////// -// class CPoint pour essayer - -// exécution -bool rCPoint( CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception ) -{ - if ( pVar == NULL )return true; // constructor with no parameters is ok - - CBotVar* pX = pThis->GetItem("x"); - pX->SetValFloat( pVar->GetValFloat() ); - pVar = pVar->GetNext(); - - CBotVar* pY = pThis->GetItem("y"); - pY->SetValFloat( pVar->GetValFloat() ); - pVar = pVar->GetNext(); - - return true; // pas d'interruption -} - -CBotTypResult cCPoint( CBotVar* pThis, CBotVar* &pVar) -{ - // ok if no parameters! - if ( pVar == NULL ) return CBotTypResult(0); - - // numeric type of parameter please - if ( pVar->GetType() > CBotTypDouble ) return CBotTypResult(5011); - pVar = pVar->GetNext(); - - // there must be a second parameter - if ( pVar == NULL ) return 5028; - // also numeric - if ( pVar->GetType() > CBotTypDouble )return CBotTypResult(5011); - pVar = pVar->GetNext(); - - // and not more than 2 parameters please - if ( pVar != NULL ) return CBotTypResult(5026); - - return CBotTypResult(0); // This function returns void -} - diff --git a/src/CBot/tests/TestCBot/CBotConsoleDlg.cpp b/src/CBot/tests/TestCBot/CBotConsoleDlg.cpp deleted file mode 100644 index 55a271a..0000000 --- a/src/CBot/tests/TestCBot/CBotConsoleDlg.cpp +++ /dev/null @@ -1,221 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/. - -// CBotConsoleDlg.cpp : implementation file -// - -#include "stdafx.h" -#include "TestCBot.h" -#include "CBotConsoleDlg.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#undef THIS_FILE -static char THIS_FILE[] = __FILE__; -#endif - -///////////////////////////////////////////////////////////////////////////// -// CBotConsoleDlg dialog - - -CBotConsoleDlg::CBotConsoleDlg(CWnd* pParent /*=NULL*/) - : CDialog(CBotConsoleDlg::IDD, pParent) -{ - //{{AFX_DATA_INIT(CBotConsoleDlg) - // NOTE: the ClassWizard will add member initialization here - //}}AFX_DATA_INIT - m_pProg = NULL; - m_threadinfo.m_bRun = FALSE; - m_code = 0; -} - - -void CBotConsoleDlg::DoDataExchange(CDataExchange* pDX) -{ - CDialog::DoDataExchange(pDX); - //{{AFX_DATA_MAP(CBotConsoleDlg) - DDX_Control(pDX, IDOK, m_cOK); - DDX_Control(pDX, IDC_EDIT2, m_Edit2); - DDX_Control(pDX, IDC_EDIT1, m_Edit1); - //}}AFX_DATA_MAP -} - - -BEGIN_MESSAGE_MAP(CBotConsoleDlg, CDialog) - //{{AFX_MSG_MAP(CBotConsoleDlg) - ON_MESSAGE(WM_ENDPROG, EndProg) - //}}AFX_MSG_MAP -END_MESSAGE_MAP() - -///////////////////////////////////////////////////////////////////////////// -// CBotConsoleDlg message handlers - -UINT ThreadProc(ThreadInfo *info) -{ - CTime t0 = CTime::GetCurrentTime(); - int Cpt = 0; - - info->m_pProg->Start("LaCommande"); - while ( !info->m_bStop && !info->m_pProg->Run() ) - { -#if 0 - const char* FunctionName; - const char* FN; - int start, end; - - info->m_pProg->GetRunPos(FunctionName, start, end); - - if ( FunctionName != NULL ) - { - info->m_pEditx->SetSel(start, end); - - char buffer[200]; - sprintf( buffer, "step %s, %d, %d",FunctionName, start, end); - AfxMessageBox( buffer ); - - int level = 0; - do - { - CBotVar* t = info->m_pProg->GivStackVars(FN, level--); - if ( FN != FunctionName ) break; - if ( t != NULL ) - { - CString s ; - while ( t != NULL ) - { - if (s.IsEmpty()) s+= "Stack -> "; - else s+= " , "; - s += t->GivValString(); - t = t->GivNext(); - } - AfxMessageBox(s); - } - } while (TRUE); - } -#endif - Cpt++; - if ( Cpt%50 == 0 ) info->m_pEdit1->ReplaceSel("."); - } - - if ( info->m_bStop ) - { - info->m_pEdit1->ReplaceSel("\r\nInterrompu\r\n"); - } - else if (info->m_pProg->GivError() == 0) - { - CTime t = CTime::GetCurrentTime(); - CTimeSpan ts = t - t0; - - char buffer[200]; - sprintf( buffer, "\r\nExécution terminée en %d secondes.\r\nInterrompue %d fois.\r\n", - ts.GetTotalSeconds(), Cpt); - - info->m_pEdit1->ReplaceSel(buffer); - } - - info->m_pWndMessage->SendMessage(WM_ENDPROG, 0, 0) ; - return 0 ; -} - -LONG CBotConsoleDlg::EndProg(UINT wparam, LONG lparam) -{ - m_threadinfo.m_bRun = FALSE; - - if (m_pProg->GetError(m_code, m_start, m_end)) - { - CBotString TextError; - TextError = CBotProgram::GivErrorText(m_code); - AfxMessageBox(TextError); - CDialog::OnCancel(); - return 1; - } - delete m_pProg; - m_pProg = NULL; - - m_Edit2.EnableWindow(TRUE); - m_cOK.EnableWindow(TRUE); - - m_Edit2.SetWindowText(""); - m_Edit2.SetFocus(); - return 0 ; -} - -void CBotConsoleDlg::OnOK() -{ - CTestCBotApp* pApp = (CTestCBotApp*)AfxGetApp(); - pApp->m_pConsole = &m_Edit1; - m_code = 0; - - CString Commande; - m_Edit2.GetWindowText(Commande); - - CString s = "void LaCommande() { " + Commande + " ;}"; - m_pProg = new CBotProgram(); - CBotStringArray liste; - m_pProg->Compile(s, liste); - - int err, start, end; - if ( m_pProg->GetError(err, start, end) ) - { - CBotString TextError; - TextError = CBotProgram::GivErrorText(err); - AfxMessageBox(TextError); - m_Edit2.SetSel(start-20, end-20); - return; - } - - m_Edit1.ReplaceSel("\r\n" + Commande + " ->\r\n"); - - m_Edit2.SetWindowText(""); - m_Edit1.SetFocus(); - m_Edit2.EnableWindow(FALSE); - m_cOK.EnableWindow(FALSE); - - // lance un processus paralèle pour l'exécution - m_threadinfo.m_pWndMessage = this ; - - m_threadinfo.m_pEdit1 = &m_Edit1; - m_threadinfo.m_pEditx = m_pEditx; - m_threadinfo.m_pProg = m_pProg; - m_threadinfo.m_bStop = FALSE; - m_threadinfo.m_bRun = TRUE; - - AfxBeginThread((AFX_THREADPROC)ThreadProc, &m_threadinfo) ; -} - -void CBotConsoleDlg::OnCancel() -{ - if (!m_threadinfo.m_bRun) CDialog::OnCancel(); - m_threadinfo.m_bStop = TRUE ; -} - - -BOOL CBotConsoleDlg::OnInitDialog() -{ - CDialog::OnInitDialog(); - - m_Edit1.ReplaceSel("Les fonctions suivantes sont disponibles:\r\n"); - for ( int i = 0; i < m_pListe->GivSize(); i++ ) - { - CBotString x = (*m_pListe)[i] + CBotString("\r\n"); - m_Edit1.ReplaceSel(x); - } - m_Edit1.ReplaceSel("Entrez une commande ci-dessous.\r\n\r\n"); - - - return TRUE; // return TRUE unless you set the focus to a control - // EXCEPTION: OCX Property Pages should return FALSE -} diff --git a/src/CBot/tests/TestCBot/CBotConsoleDlg.h b/src/CBot/tests/TestCBot/CBotConsoleDlg.h deleted file mode 100644 index f289a4d..0000000 --- a/src/CBot/tests/TestCBot/CBotConsoleDlg.h +++ /dev/null @@ -1,85 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/. - -#if !defined(AFX_BOTCONSOLEDLG_H__A11450A2_8E09_11D4_A439_00D059085115__INCLUDED_) -#define AFX_BOTCONSOLEDLG_H__A11450A2_8E09_11D4_A439_00D059085115__INCLUDED_ - -#if _MSC_VER >= 1000 -#pragma once -#endif // _MSC_VER >= 1000 -// CBotConsoleDlg.h : header file -// - -struct ThreadInfo -{ - CEdit* m_pEdit1 ; - CEdit* m_pEditx ; - CBotProgram* m_pProg; - CWnd* m_pWndMessage; - BOOL m_bStop; - BOOL m_bRun; -}; - - -///////////////////////////////////////////////////////////////////////////// -// CBotConsoleDlg dialog - -class CBotConsoleDlg : public CDialog -{ -// Construction -public: - CBotConsoleDlg(CWnd* pParent = NULL); // standard constructor - -// Dialog Data - //{{AFX_DATA(CBotConsoleDlg) - enum { IDD = IDD_CONSOLE }; - CButton m_cOK; - CEdit m_Edit2; - CEdit m_Edit1; - //}}AFX_DATA - - CBotProgram* m_pProg; - ThreadInfo m_threadinfo; - - CBotStringArray* - m_pListe; - int m_code, m_start, m_end; - CEdit* m_pEditx; - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CBotConsoleDlg) - protected: - virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support - //}}AFX_VIRTUAL - -// Implementation -protected: - - // Generated message map functions - //{{AFX_MSG(CBotConsoleDlg) - virtual void OnOK(); - virtual void OnCancel(); - virtual BOOL OnInitDialog(); - afx_msg LONG EndProg(UINT wparam, LONG lparam) ; - //}}AFX_MSG - DECLARE_MESSAGE_MAP() -}; - -//{{AFX_INSERT_LOCATION}} -// Microsoft Developer Studio will insert additional declarations immediately before the previous line. - -#endif // !defined(AFX_BOTCONSOLEDLG_H__A11450A2_8E09_11D4_A439_00D059085115__INCLUDED_) diff --git a/src/CBot/tests/TestCBot/ChildFrm.cpp b/src/CBot/tests/TestCBot/ChildFrm.cpp deleted file mode 100644 index 4c40f90..0000000 --- a/src/CBot/tests/TestCBot/ChildFrm.cpp +++ /dev/null @@ -1,74 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/. - -// ChildFrm.cpp : implementation of the CChildFrame class -// - -#include "stdafx.h" -#include "TestCBot.h" - -#include "ChildFrm.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#undef THIS_FILE -static char THIS_FILE[] = __FILE__; -#endif - -///////////////////////////////////////////////////////////////////////////// -// CChildFrame - -IMPLEMENT_DYNCREATE(CChildFrame, CMDIChildWnd) - -BEGIN_MESSAGE_MAP(CChildFrame, CMDIChildWnd) - //{{AFX_MSG_MAP(CChildFrame) - //}}AFX_MSG_MAP -END_MESSAGE_MAP() - -///////////////////////////////////////////////////////////////////////////// -// CChildFrame construction/destruction - -CChildFrame::CChildFrame() -{ -} - -CChildFrame::~CChildFrame() -{ -} - -BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs) -{ - return CMDIChildWnd::PreCreateWindow(cs); -} - -///////////////////////////////////////////////////////////////////////////// -// CChildFrame diagnostics - -#ifdef _DEBUG -void CChildFrame::AssertValid() const -{ - CMDIChildWnd::AssertValid(); -} - -void CChildFrame::Dump(CDumpContext& dc) const -{ - CMDIChildWnd::Dump(dc); -} - -#endif //_DEBUG - -///////////////////////////////////////////////////////////////////////////// -// CChildFrame message handlers diff --git a/src/CBot/tests/TestCBot/ChildFrm.h b/src/CBot/tests/TestCBot/ChildFrm.h deleted file mode 100644 index 2ad57b6..0000000 --- a/src/CBot/tests/TestCBot/ChildFrm.h +++ /dev/null @@ -1,66 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/. - -// ChildFrm.h : interface of the CChildFrame class -// -///////////////////////////////////////////////////////////////////////////// - -#if !defined(AFX_CHILDFRM_H__4D1BB909_8E74_11D4_A439_00D059085115__INCLUDED_) -#define AFX_CHILDFRM_H__4D1BB909_8E74_11D4_A439_00D059085115__INCLUDED_ - -#if _MSC_VER >= 1000 -#pragma once -#endif // _MSC_VER >= 1000 - -class CChildFrame : public CMDIChildWnd -{ - DECLARE_DYNCREATE(CChildFrame) -public: - CChildFrame(); - -// Attributes -public: - -// Operations -public: - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CChildFrame) - virtual BOOL PreCreateWindow(CREATESTRUCT& cs); - //}}AFX_VIRTUAL - -// Implementation -public: - virtual ~CChildFrame(); -#ifdef _DEBUG - virtual void AssertValid() const; - virtual void Dump(CDumpContext& dc) const; -#endif - -// Generated message map functions -protected: - //{{AFX_MSG(CChildFrame) - //}}AFX_MSG - DECLARE_MESSAGE_MAP() -}; - -///////////////////////////////////////////////////////////////////////////// - -//{{AFX_INSERT_LOCATION}} -// Microsoft Developer Studio will insert additional declarations immediately before the previous line. - -#endif // !defined(AFX_CHILDFRM_H__4D1BB909_8E74_11D4_A439_00D059085115__INCLUDED_) diff --git a/src/CBot/tests/TestCBot/MainFrm.cpp b/src/CBot/tests/TestCBot/MainFrm.cpp deleted file mode 100644 index 6669350..0000000 --- a/src/CBot/tests/TestCBot/MainFrm.cpp +++ /dev/null @@ -1,116 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/. - -// MainFrm.cpp : implementation of the CMainFrame class -// - -#include "stdafx.h" -#include "TestCBot.h" - -#include "MainFrm.h" -#include "TestCBotDoc.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#undef THIS_FILE -static char THIS_FILE[] = __FILE__; -#endif - -///////////////////////////////////////////////////////////////////////////// -// CMainFrame - -IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd) - -BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd) - //{{AFX_MSG_MAP(CMainFrame) - ON_WM_CREATE() - //}}AFX_MSG_MAP -END_MESSAGE_MAP() - -static UINT indicators[] = -{ - ID_SEPARATOR, // status line indicator - ID_INDICATOR_CAPS, - ID_INDICATOR_NUM, - ID_INDICATOR_SCRL, -}; - -///////////////////////////////////////////////////////////////////////////// -// CMainFrame construction/destruction - -CMainFrame::CMainFrame() -{ -} - -CMainFrame::~CMainFrame() -{ -} - -int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) -{ - if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1) - return -1; - - if (!m_wndToolBar.Create(this) || - !m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) - { - TRACE0("Failed to create toolbar\n"); - return -1; // fail to create - } - - if (!m_wndStatusBar.Create(this) || - !m_wndStatusBar.SetIndicators(indicators, - sizeof(indicators)/sizeof(UINT))) - { - TRACE0("Failed to create status bar\n"); - return -1; // fail to create - } - - m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | - CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC); - - m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); - EnableDocking(CBRS_ALIGN_ANY); - DockControlBar(&m_wndToolBar); - - return 0; -} - -BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) -{ - return CMDIFrameWnd::PreCreateWindow(cs); -} - -///////////////////////////////////////////////////////////////////////////// -// CMainFrame diagnostics - -#ifdef _DEBUG -void CMainFrame::AssertValid() const -{ - CMDIFrameWnd::AssertValid(); -} - -void CMainFrame::Dump(CDumpContext& dc) const -{ - CMDIFrameWnd::Dump(dc); -} - -#endif //_DEBUG - -///////////////////////////////////////////////////////////////////////////// -// CMainFrame message handlers - - diff --git a/src/CBot/tests/TestCBot/MainFrm.h b/src/CBot/tests/TestCBot/MainFrm.h deleted file mode 100644 index a1d34f4..0000000 --- a/src/CBot/tests/TestCBot/MainFrm.h +++ /dev/null @@ -1,72 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/. - -// MainFrm.h : interface of the CMainFrame class -// -///////////////////////////////////////////////////////////////////////////// - -#if !defined(AFX_MAINFRM_H__4D1BB907_8E74_11D4_A439_00D059085115__INCLUDED_) -#define AFX_MAINFRM_H__4D1BB907_8E74_11D4_A439_00D059085115__INCLUDED_ - -#if _MSC_VER >= 1000 -#pragma once -#endif // _MSC_VER >= 1000 - -class CMainFrame : public CMDIFrameWnd -{ - DECLARE_DYNAMIC(CMainFrame) -public: - CMainFrame(); - -// Attributes -public: - -// Operations -public: - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CMainFrame) - public: - virtual BOOL PreCreateWindow(CREATESTRUCT& cs); - //}}AFX_VIRTUAL - -// Implementation -public: - virtual ~CMainFrame(); -#ifdef _DEBUG - virtual void AssertValid() const; - virtual void Dump(CDumpContext& dc) const; -#endif - -protected: // control bar embedded members - CStatusBar m_wndStatusBar; - CToolBar m_wndToolBar; - -// Generated message map functions -protected: - //{{AFX_MSG(CMainFrame) - afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); - //}}AFX_MSG - DECLARE_MESSAGE_MAP() -}; - -///////////////////////////////////////////////////////////////////////////// - -//{{AFX_INSERT_LOCATION}} -// Microsoft Developer Studio will insert additional declarations immediately before the previous line. - -#endif // !defined(AFX_MAINFRM_H__4D1BB907_8E74_11D4_A439_00D059085115__INCLUDED_) diff --git a/src/CBot/tests/TestCBot/PerformDlg.cpp b/src/CBot/tests/TestCBot/PerformDlg.cpp deleted file mode 100644 index 8abbb4b..0000000 --- a/src/CBot/tests/TestCBot/PerformDlg.cpp +++ /dev/null @@ -1,177 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/. - -// PerformDlg.cpp : implementation file -// - -#include "stdafx.h" -#include "testcbot.h" -#include "PerformDlg.h" - -//#include -#include -//#include - -#ifdef _DEBUG -#define new DEBUG_NEW -#undef THIS_FILE -static char THIS_FILE[] = __FILE__; -#endif - -///////////////////////////////////////////////////////////////////////////// -// CPerformDlg dialog - - -CPerformDlg::CPerformDlg(CWnd* pParent /*=NULL*/) - : CDialog(CPerformDlg::IDD, pParent) -{ - //{{AFX_DATA_INIT(CPerformDlg) - // NOTE: the ClassWizard will add member initialization here - //}}AFX_DATA_INIT -} - - -void CPerformDlg::DoDataExchange(CDataExchange* pDX) -{ - CDialog::DoDataExchange(pDX); - //{{AFX_DATA_MAP(CPerformDlg) - DDX_Control(pDX, IDC_EDIT3, m_Edit3); - DDX_Control(pDX, IDC_EDIT1, m_Edit1); - //}}AFX_DATA_MAP -} - - -BEGIN_MESSAGE_MAP(CPerformDlg, CDialog) - //{{AFX_MSG_MAP(CPerformDlg) - //}}AFX_MSG_MAP -END_MESSAGE_MAP() - -///////////////////////////////////////////////////////////////////////////// -// CPerformDlg message handlers - -/* Pauses for a specified number of milliseconds. */ - -/*void sleep( double waitseconds ) -{ - clock_t wait = (clock_t)(waitseconds * CLOCKS_PER_SEC); - clock_t goal; - goal = wait + clock(); - while( goal > clock() ) - ; -}*/ - -void sleep( clock_t wait ) -{ - clock_t goal; - goal = wait + clock(); - while( goal > clock() ) - TRACE("%d \n", clock() ); -} - -void sleep2( clock_t wait ) -{ - struct _timeb timebuffer; - char *timeline; - - _ftime( &timebuffer ); - timeline = ctime( & ( timebuffer.time ) ); - long x = timebuffer.millitm; - while( x == timebuffer.millitm ) _ftime( &timebuffer ); -} - -#define NBLP 20 - -UINT ThreadProc2(ThreadInfo2 *info) -{ - int lp = NBLP; - int i; - clock_t start = clock(); - - while ( !info->m_bStop ) - { - for ( i = 0; i< info->m_nbscripts; i++ ) - { - info->m_pProg[i]->Run(); - } - -#ifdef _DEBUG - sleep2( 1 ); -#else - CString s ( "xx" ); - for ( long z = 0x5000; z>0; z-- ) s = s.Left(1); -#endif - if ( --lp == 0 ) - { - clock_t finish = clock(); - double n = (double)NBLP / (double)(finish-start) * CLOCKS_PER_SEC; - char b[30]; - sprintf( b, "%f", n); - info->m_pEdit->SetWindowText(b); - - n = n * 1100 / 200; // performances - sprintf( b, "%f", n); - info->m_pEdit3->SetWindowText(b); - start = finish; - lp = NBLP; - } - } - - return 0 ; -} - -BOOL CPerformDlg::OnInitDialog() -{ - CDialog::OnInitDialog(); - - - CBotStringArray liste; - // crée les scripts pour les tests - for ( int i = 0; i < 100; i++ ) - { - m_pProg[i] = new CBotProgram(); - m_pProg[i]->Compile(m_Script, liste); - m_pProg[i]->Start(liste[0]); - } - - // lance un processus paralèle pour l'exécution -// m_threadinfo2.m_pWndMessage = this ; - - m_threadinfo2.m_pEdit = &m_Edit1; - m_threadinfo2.m_pEdit3 = &m_Edit3; - m_threadinfo2.m_pProg = m_pProg; - m_threadinfo2.m_bStop = FALSE; - m_threadinfo2.m_nbscripts = 30; - - - AfxBeginThread((AFX_THREADPROC)ThreadProc2, &m_threadinfo2) ; - // TODO: Add extra initialization here - - return TRUE; // return TRUE unless you set the focus to a control - // EXCEPTION: OCX Property Pages should return FALSE -} - -void CPerformDlg::OnCancel() -{ - m_threadinfo2.m_bStop = TRUE; - sleep ( 2000 ); - - CDialog::OnCancel(); - - for ( int i = 0; i < 100; i++ ) - { - delete m_pProg[i]; - } -} diff --git a/src/CBot/tests/TestCBot/PerformDlg.h b/src/CBot/tests/TestCBot/PerformDlg.h deleted file mode 100644 index 29d567f..0000000 --- a/src/CBot/tests/TestCBot/PerformDlg.h +++ /dev/null @@ -1,78 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/. - -#if !defined(AFX_PERFORMDLG_H__EAF2D560_97D8_11D4_A439_00D059085115__INCLUDED_) -#define AFX_PERFORMDLG_H__EAF2D560_97D8_11D4_A439_00D059085115__INCLUDED_ - -#if _MSC_VER >= 1000 -#pragma once -#endif // _MSC_VER >= 1000 -// PerformDlg.h : header file -// - -struct ThreadInfo2 -{ - CEdit* m_pEdit ; - CEdit* m_pEdit3 ; - - CBotProgram** m_pProg; - BOOL m_bStop; - int m_nbscripts; -}; - - -///////////////////////////////////////////////////////////////////////////// -// CPerformDlg dialog - -class CPerformDlg : public CDialog -{ -// Construction -public: - CPerformDlg(CWnd* pParent = NULL); // standard constructor - -// Dialog Data - //{{AFX_DATA(CPerformDlg) - enum { IDD = IDD_DIALOG1 }; - CEdit m_Edit3; - CEdit m_Edit1; - //}}AFX_DATA - - CBotProgram* m_pProg[100]; - ThreadInfo2 m_threadinfo2; - CString m_Script; - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CPerformDlg) - protected: - virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support - //}}AFX_VIRTUAL - -// Implementation -protected: - - // Generated message map functions - //{{AFX_MSG(CPerformDlg) - virtual BOOL OnInitDialog(); - virtual void OnCancel(); - //}}AFX_MSG - DECLARE_MESSAGE_MAP() -}; - -//{{AFX_INSERT_LOCATION}} -// Microsoft Developer Studio will insert additional declarations immediately before the previous line. - -#endif // !defined(AFX_PERFORMDLG_H__EAF2D560_97D8_11D4_A439_00D059085115__INCLUDED_) diff --git a/src/CBot/tests/TestCBot/Routines.cpp b/src/CBot/tests/TestCBot/Routines.cpp deleted file mode 100644 index b37f027..0000000 --- a/src/CBot/tests/TestCBot/Routines.cpp +++ /dev/null @@ -1,153 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/. - -//////////////////////////////////////////////////////////////////// -// routine show() -// utilisable depuis le programme écrit en CBot - -// exécution -BOOL rShow( CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser ) -{ - CString s; - - while ( pVar != NULL ) - { - CString ss; - ss.LoadString( TX_TYPENAMES + pVar->GivType() ); - s += ss + " "; - - ss = pVar->GivName(); - if (ss.IsEmpty()) ss = ""; - s += ss + " = "; - - s += pVar->GivValString(); - s += "\n"; - pVar = pVar->GivNext(); - } - - AfxMessageBox(s, MB_OK|MB_ICONINFORMATION); - - return TRUE; // pas d'interruption -} - -CBotTypResult cShow( CBotVar* &pVar, void* pUser) -{ - if ( pVar == NULL ) return CBotTypResult(5028); - return CBotTypResult(0); // tous paramètres acceptés, void en retour -} - - -//////////////////////////////////////////////////////////////////// -// routine print() -// utilisable depuis le programme écrit en CBot - -// exécution -BOOL rPrintLn( CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser ) -{ - CString s; - - CTestCBotApp* pApp = (CTestCBotApp*)AfxGetApp(); - CEdit* pEdit = pApp->m_pConsole; - - if (pEdit == NULL) return TRUE; - pEdit->GetWindowText(s); - - while ( pVar != NULL ) - { - if ( !s.IsEmpty() ) s += " "; - s += pVar->GivValString(); - pVar = pVar->GivNext(); - } - s += "\r\n"; - - pEdit->SetWindowText(s); - pEdit->SetSel(s.GetLength(), s.GetLength()); - pEdit->SetFocus(); - return TRUE; // pas d'interruption -} - -BOOL rPrint( CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser ) -{ - CString s; - - CTestCBotApp* pApp = (CTestCBotApp*)AfxGetApp(); - CEdit* pEdit = pApp->m_pConsole; - - if (pEdit == NULL) return TRUE; - pEdit->GetWindowText(s); - - while ( pVar != NULL ) - { - if ( !s.IsEmpty() ) s += " "; - s += pVar->GivValString(); - pVar = pVar->GivNext(); - } - - pEdit->SetWindowText(s); - pEdit->SetSel(s.GetLength(), s.GetLength()); - pEdit->SetFocus(); - return TRUE; // pas d'interruption -} - -CBotTypResult cPrint( CBotVar* &pVar, void* pUser) -{ - return CBotTypResult(0); // tous paramètres acceptés, un entier en retour -} - - -////////////////////////////////////////////////////////////////// -// class CPoint pour essayer - -// exécution -BOOL rCPoint( CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception ) -{ - CString s; - - if ( pVar == NULL )return TRUE; // constructeur sans paramètres est ok - - CBotVar* pX = pThis->GivItem("x"); - pX->SetValFloat( pVar->GivValFloat() ); - pVar = pVar->GivNext(); - - CBotVar* pY = pThis->GivItem("y"); - pY->SetValFloat( pVar->GivValFloat() ); - pVar = pVar->GivNext(); - - return TRUE; // pas d'interruption -} - -CBotTypResult cCPoint( CBotVar* pThis, CBotVar* &pVar) -{ - // ok si aucun paramètres ! - if ( pVar == NULL ) return CBotTypResult(0); - - // paramètre de type numérique svp - if ( pVar->GivType() > CBotTypDouble ) return CBotTypResult(5011); - pVar = pVar->GivNext(); - - // il doit y avoir un second paramètre - if ( pVar == NULL ) return 5028; - // également de type numérique - if ( pVar->GivType() > CBotTypDouble )return CBotTypResult(5011); - pVar = pVar->GivNext(); - - // et pas plus de 2 paramètres svp - if ( pVar != NULL ) return CBotTypResult(5026); - - return CBotTypResult(0); // cette fonction retourne void -} - - diff --git a/src/CBot/tests/TestCBot/StdAfx.cpp b/src/CBot/tests/TestCBot/StdAfx.cpp deleted file mode 100644 index 7dd0f00..0000000 --- a/src/CBot/tests/TestCBot/StdAfx.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/.// stdafx.cpp : source file that includes just the standard includes -// TestCBot.pch will be the pre-compiled header -// stdafx.obj will contain the pre-compiled type information - -#include "stdafx.h" - diff --git a/src/CBot/tests/TestCBot/StdAfx.h b/src/CBot/tests/TestCBot/StdAfx.h deleted file mode 100644 index c3659fb..0000000 --- a/src/CBot/tests/TestCBot/StdAfx.h +++ /dev/null @@ -1,40 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/.// stdafx.h : include file for standard system include files, -// or project specific include files that are used frequently, but -// are changed infrequently -// - -#if !defined(AFX_STDAFX_H__4D1BB905_8E74_11D4_A439_00D059085115__INCLUDED_) -#define AFX_STDAFX_H__4D1BB905_8E74_11D4_A439_00D059085115__INCLUDED_ - -#if _MSC_VER >= 1000 -#pragma once -#endif // _MSC_VER >= 1000 - -#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers - -#include // MFC core and standard components -#include // MFC extensions -#include // MFC OLE automation classes -#ifndef _AFX_NO_AFXCMN_SUPPORT -#include // MFC support for Windows Common Controls -#endif // _AFX_NO_AFXCMN_SUPPORT - - -//{{AFX_INSERT_LOCATION}} -// Microsoft Developer Studio will insert additional declarations immediately before the previous line. - -#endif // !defined(AFX_STDAFX_H__4D1BB905_8E74_11D4_A439_00D059085115__INCLUDED_) diff --git a/src/CBot/tests/TestCBot/TestCBot.clw b/src/CBot/tests/TestCBot/TestCBot.clw deleted file mode 100644 index 13f20f4..0000000 --- a/src/CBot/tests/TestCBot/TestCBot.clw +++ /dev/null @@ -1,316 +0,0 @@ -; CLW file contains information for the MFC ClassWizard - -[General Info] -Version=1 -LastClass=CPerformDlg -LastTemplate=CDialog -NewFileInclude1=#include "stdafx.h" -NewFileInclude2=#include "testcbot.h" -LastPage=0 - -ClassCount=8 -Class1=CBotConsoleDlg -Class2=CChildFrame -Class3=CMainFrame -Class4=CTestCBotApp -Class5=CAboutDlg -Class6=CTestCBotDoc -Class7=CTestCBotView - -ResourceCount=12 -Resource1=IDD_CONSOLE -Resource2=IDR_TESTCBTYPE (French (France)) -Resource3=IDD_ABOUTBOX (French (France)) -Resource4=IDR_MAINFRAME (French (France)) -Resource5=IDR_MAINFRAME -Resource6=IDR_TESTCBTYPE -Resource7=IDD_ABOUTBOX -Resource8=IDD_CONSOLE (French (Switzerland)) -Class8=CPerformDlg -Resource9=IDD_DIALOG1 -Resource10=IDD_DIALOG2 -Resource11=IDD_DIALOG1 (French (Switzerland)) -Resource12=IDD_DIALOG2 (French (France)) - -[CLS:CBotConsoleDlg] -Type=0 -BaseClass=CDialog -HeaderFile=CBotConsoleDlg.h -ImplementationFile=CBotConsoleDlg.cpp -LastObject=IDC_EDIT1 - -[CLS:CChildFrame] -Type=0 -BaseClass=CMDIChildWnd -HeaderFile=ChildFrm.h -ImplementationFile=ChildFrm.cpp - -[CLS:CMainFrame] -Type=0 -BaseClass=CMDIFrameWnd -HeaderFile=MainFrm.h -ImplementationFile=MainFrm.cpp -Filter=T -VirtualFilter=fWC -LastObject=CMainFrame - -[CLS:CTestCBotApp] -Type=0 -BaseClass=CWinApp -HeaderFile=TestCBot.h -ImplementationFile=TestCBot.cpp -Filter=N -VirtualFilter=AC -LastObject=ID_TEST - -[CLS:CAboutDlg] -Type=0 -BaseClass=CDialog -HeaderFile=TestCBot.cpp -ImplementationFile=TestCBot.cpp -LastObject=CAboutDlg - -[CLS:CTestCBotDoc] -Type=0 -BaseClass=CDocument -HeaderFile=TestCBotDoc.h -ImplementationFile=TestCBotDoc.cpp -LastObject=CTestCBotDoc -Filter=N -VirtualFilter=DC - -[CLS:CTestCBotView] -Type=0 -BaseClass=CView -HeaderFile=TestCBotView.h -ImplementationFile=TestCBotView.cpp -LastObject=CTestCBotView -Filter=C -VirtualFilter=VWC - -[DLG:IDD_CONSOLE] -Type=1 -Class=CBotConsoleDlg -ControlCount=4 -Control1=IDC_STATIC,static,1342308352 -Control2=IDC_EDIT2,edit,1350631552 -Control3=IDOK,button,1342242817 -Control4=IDC_EDIT1,edit,1352734724 - -[DLG:IDD_ABOUTBOX] -Type=1 -Class=CAboutDlg -ControlCount=7 -Control1=IDC_STATIC,static,1342177283 -Control2=IDC_STATIC,static,1342308480 -Control3=IDC_STATIC,static,1342308352 -Control4=IDOK,button,1342373889 -Control5=IDC_STATIC,static,1342308352 -Control6=IDC_STATIC,static,1342308352 -Control7=IDC_STATIC,static,1342308352 - -[TB:IDR_MAINFRAME (French (France))] -Type=1 -Class=? -Command1=ID_FILE_NEW -Command2=ID_FILE_OPEN -Command3=ID_FILE_SAVE -Command4=ID_EDIT_CUT -Command5=ID_EDIT_COPY -Command6=ID_EDIT_PASTE -Command7=ID_FILE_PRINT -Command8=ID_RUN -Command9=ID_APP_ABOUT -CommandCount=9 - -[MNU:IDR_MAINFRAME (French (France))] -Type=1 -Class=? -Command1=ID_FILE_NEW -Command2=ID_FILE_OPEN -Command3=ID_FILE_MRU_FILE1 -Command4=ID_APP_EXIT -Command5=ID_VIEW_TOOLBAR -Command6=ID_VIEW_STATUS_BAR -Command7=ID_APP_ABOUT -CommandCount=7 - -[MNU:IDR_TESTCBTYPE (French (France))] -Type=1 -Class=? -Command1=ID_FILE_NEW -Command2=ID_FILE_OPEN -Command3=ID_FILE_CLOSE -Command4=ID_FILE_SAVE -Command5=ID_FILE_SAVE_AS -Command6=ID_FILE_MRU_FILE1 -Command7=ID_APP_EXIT -Command8=ID_EDIT_UNDO -Command9=ID_EDIT_CUT -Command10=ID_EDIT_COPY -Command11=ID_EDIT_PASTE -Command12=ID_VIEW_TOOLBAR -Command13=ID_VIEW_STATUS_BAR -Command14=ID_WINDOW_NEW -Command15=ID_WINDOW_CASCADE -Command16=ID_WINDOW_TILE_HORZ -Command17=ID_WINDOW_ARRANGE -Command18=ID_APP_ABOUT -CommandCount=18 - -[ACL:IDR_MAINFRAME (French (France))] -Type=1 -Class=? -Command1=ID_EDIT_COPY -Command2=ID_FILE_NEW -Command3=ID_FILE_OPEN -Command4=ID_FILE_SAVE -Command5=ID_EDIT_PASTE -Command6=ID_EDIT_UNDO -Command7=ID_EDIT_CUT -Command8=ID_RUN -Command9=ID_NEXT_PANE -Command10=ID_PREV_PANE -Command11=ID_RUN -Command12=ID_TEST -Command13=ID_EDIT_COPY -Command14=ID_EDIT_PASTE -Command15=ID_EDIT_CUT -Command16=ID_EDIT_UNDO -CommandCount=16 - -[DLG:IDD_ABOUTBOX (French (France))] -Type=1 -Class=CAboutDlg -ControlCount=7 -Control1=IDC_STATIC,static,1342177283 -Control2=IDC_STATIC,static,1342308480 -Control3=IDC_STATIC,static,1342308352 -Control4=IDOK,button,1342373889 -Control5=IDC_STATIC,static,1342308352 -Control6=IDC_STATIC,static,1342308352 -Control7=IDC_STATIC,static,1342308352 - -[ACL:IDR_MAINFRAME] -Type=1 -Command1=ID_EDIT_COPY -Command2=ID_FILE_NEW -Command3=ID_FILE_OPEN -Command4=ID_FILE_SAVE -Command5=ID_EDIT_PASTE -Command6=ID_EDIT_UNDO -Command7=ID_EDIT_CUT -Command8=ID_RUN -Command9=ID_NEXT_PANE -Command10=ID_PREV_PANE -Command11=ID_RUN -Command12=ID_TEST -Command13=ID_EDIT_COPY -Command14=ID_EDIT_PASTE -Command15=ID_EDIT_CUT -Command16=ID_EDIT_UNDO -CommandCount=16 - -[TB:IDR_MAINFRAME] -Type=1 -Command1=ID_FILE_NEW -Command2=ID_FILE_OPEN -Command3=ID_FILE_SAVE -Command4=ID_EDIT_CUT -Command5=ID_EDIT_COPY -Command6=ID_EDIT_PASTE -Command7=ID_FILE_PRINT -Command8=ID_RUN -Command9=ID_APP_ABOUT -CommandCount=9 - -[MNU:IDR_MAINFRAME] -Type=1 -Command1=ID_FILE_NEW -Command2=ID_FILE_OPEN -Command3=ID_FILE_MRU_FILE1 -Command4=ID_APP_EXIT -Command5=ID_VIEW_TOOLBAR -Command6=ID_VIEW_STATUS_BAR -Command7=ID_APP_ABOUT -CommandCount=7 - -[MNU:IDR_TESTCBTYPE] -Type=1 -Command1=ID_FILE_NEW -Command2=ID_FILE_OPEN -Command3=ID_FILE_CLOSE -Command4=ID_FILE_SAVE -Command5=ID_FILE_SAVE_AS -Command6=ID_FILE_MRU_FILE1 -Command7=ID_APP_EXIT -Command8=ID_EDIT_UNDO -Command9=ID_EDIT_CUT -Command10=ID_EDIT_COPY -Command11=ID_EDIT_PASTE -Command12=ID_VIEW_TOOLBAR -Command13=ID_VIEW_STATUS_BAR -Command14=ID_WINDOW_NEW -Command15=ID_WINDOW_CASCADE -Command16=ID_WINDOW_TILE_HORZ -Command17=ID_WINDOW_ARRANGE -Command18=ID_APP_ABOUT -CommandCount=18 - -[DLG:IDD_CONSOLE (French (Switzerland))] -Type=1 -Class=CBotConsoleDlg -ControlCount=4 -Control1=IDC_STATIC,static,1342308352 -Control2=IDC_EDIT2,edit,1350631552 -Control3=IDOK,button,1342242817 -Control4=IDC_EDIT1,edit,1352734724 - -[DLG:IDD_DIALOG1] -Type=1 -Class=CPerformDlg -ControlCount=9 -Control1=IDC_STATIC,static,1342308352 -Control2=IDC_EDIT1,edit,1350633600 -Control3=IDC_STATIC,static,1342308352 -Control4=IDC_EDIT2,edit,1350631552 -Control5=IDC_SPIN1,msctls_updown32,1342177312 -Control6=IDC_COMBO1,combobox,1344339971 -Control7=IDC_STATIC,static,1342308352 -Control8=IDC_STATIC,static,1342308352 -Control9=IDC_EDIT3,edit,1350633600 - -[CLS:CPerformDlg] -Type=0 -HeaderFile=PerformDlg.h -ImplementationFile=PerformDlg.cpp -BaseClass=CDialog -Filter=D -VirtualFilter=dWC -LastObject=IDC_EDIT3 - -[DLG:IDD_DIALOG2] -Type=1 -ControlCount=2 -Control1=IDOK,button,1342242817 -Control2=IDCANCEL,button,1342242816 - -[DLG:IDD_DIALOG1 (French (Switzerland))] -Type=1 -ControlCount=9 -Control1=IDC_STATIC,static,1342308352 -Control2=IDC_EDIT1,edit,1350633600 -Control3=IDC_STATIC,static,1342308352 -Control4=IDC_EDIT2,edit,1350631552 -Control5=IDC_SPIN1,msctls_updown32,1342177312 -Control6=IDC_COMBO1,combobox,1344339971 -Control7=IDC_STATIC,static,1342308352 -Control8=IDC_STATIC,static,1342308352 -Control9=IDC_EDIT3,edit,1350633600 - -[DLG:IDD_DIALOG2 (French (France))] -Type=1 -ControlCount=2 -Control1=IDOK,button,1342242817 -Control2=IDCANCEL,button,1342242816 - diff --git a/src/CBot/tests/TestCBot/TestCBot.cpp b/src/CBot/tests/TestCBot/TestCBot.cpp deleted file mode 100644 index a76040a..0000000 --- a/src/CBot/tests/TestCBot/TestCBot.cpp +++ /dev/null @@ -1,267 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/.// TestCBot.cpp : Defines the class behaviors for the application. -// - -#include "stdafx.h" -#include "TestCBot.h" - -#include "MainFrm.h" -#include "ChildFrm.h" -#include "TestCBotDoc.h" -#include "TestCBotView.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#undef THIS_FILE -static char THIS_FILE[] = __FILE__; -#endif - -///////////////////////////////////////////////////////////////////////////// -// CTestCBotApp - -BEGIN_MESSAGE_MAP(CTestCBotApp, CWinApp) - //{{AFX_MSG_MAP(CTestCBotApp) - ON_COMMAND(ID_APP_ABOUT, OnAppAbout) - //}}AFX_MSG_MAP - // Standard file based document commands - ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew) - ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen) -END_MESSAGE_MAP() - -///////////////////////////////////////////////////////////////////////////// -// CTestCBotApp construction - -CTestCBotApp::CTestCBotApp() -{ - m_pConsole = NULL; - m_LastActive = NULL; - m_pClassPoint= NULL; -} - - -///////////////////////////////////////////////////////////////////////////// -// The one and only CTestCBotApp object - -CTestCBotApp theApp; - -///////////////////////////////////////////////////////////////////////////// -// CTestCBotApp initialization - -#include "Routines.cpp" - - -static char BASED_CODE szSection[] = "Recent File List"; -static char BASED_CODE szFilename[] = "File1"; - - -#include "../ClassFILE.cpp" - -// routine pour mettre à jour l'instance de la classe Bot courante -void rMajObject( CBotVar* pThis, void* pUser ) -{ - if (!pThis->IsElemOfClass("object")) - return ; - CBotVar* pPos = pThis->GivItem("position"); - CBotVar* pX = pPos->GivItem("x"); - CBotVar* pY = pPos->GivItem("y"); - CBotVar* pZ = pPos->GivItem("z"); -// CBotVar* pPt = pThis->GivItem("transport"); - - CBotString p = pX->GivValString(); - -// pX->SetValFloat( pUser == (void*)1 ? (float)12.5 : (float)44.4 ); - pZ->SetValFloat( (float)0 ); - pY->SetValFloat( (float)-3.33 ); - pX->SetValFloat( pX->GivValFloat() + 10 ) ; - -// pX = pThis->GivItem( "xx" ); -// pX->SetValFloat( (float)22 ); - - // crée une instance sur une classe object -// CBotVar* pAutre = CBotVar::Create("autre", CBotTypClass, "object"); -// pAutre->SetUserPtr( (void*)3 ); -// pPt->SetPointer( pAutre ); -// pPt->SetPointer( NULL ); -// delete pAutre; -} - - -BOOL CTestCBotApp::InitInstance() -{ -////////////////////////////////////////////// -// défini les mots clefs supplémentaires -// ------------------------------------------- - - CBotProgram::Init(); - -////////////////////////////////////////////// -// défini les fonctions "show()" et "print()" -// ------------------------------------------- - - CBotProgram::AddFunction("show", rShow, cShow); - CBotProgram::AddFunction("print", rPrint, cPrint); - CBotProgram::AddFunction("println", rPrintLn, cPrint); - - -/////////////////////////////////// -// définie la classe globale CPoint -// -------------------------------- - - m_pClassPoint = new CBotClass("CPoint", NULL); - // ajoute le composant ".x" - m_pClassPoint->AddItem("x", CBotTypFloat); - // ajoute le composant ".y" - m_pClassPoint->AddItem("y", CBotTypFloat); - - // ajoute le constructeur pour cette classe - m_pClassPoint->AddFunction("CPoint", rCPoint, cCPoint); - - m_pClassPointIntr = new CBotClass("point", NULL, TRUE); - // ajoute le composant ".x" - m_pClassPointIntr->AddItem("x", CBotTypFloat); - // ajoute le composant ".y" - m_pClassPointIntr->AddItem("y", CBotTypFloat); - // ajoute le composant ".z" - m_pClassPointIntr->AddItem("z", CBotTypFloat); - - // ajoute le constructeur pour cette classe - m_pClassPointIntr->AddFunction("point", rCPoint, cCPoint); - - // défini la classe "object" - CBotClass* pClassObject = new CBotClass( "object", NULL ) ; - pClassObject->AddItem( "xx", CBotTypFloat ); - pClassObject->AddItem( "position", CBotTypResult( CBotTypIntrinsic, "point" ) ); - pClassObject->AddItem( "transport", CBotTypResult( CBotTypPointer, "object" ) ); - pClassObject->AddUpdateFunc( rMajObject ); - - InitClassFILE(); - - AfxEnableControlContainer(); - - // Standard initialization - -#ifdef _AFXDLL - Enable3dControls(); // Call this when using MFC in a shared DLL -#else - Enable3dControlsStatic(); // Call this when linking to MFC statically -#endif - - // Change the registry key under which our settings are stored. - SetRegistryKey(_T("Local AppWizard-Generated Applications")); - - LoadStdProfileSettings(); // Load standard INI file options (including MRU) - - // Register document templates - - CMultiDocTemplate* pDocTemplate; - pDocTemplate = new CMultiDocTemplate( - IDR_TESTCBTYPE, - RUNTIME_CLASS(CTestCBotDoc), - RUNTIME_CLASS(CChildFrame), // custom MDI child frame - RUNTIME_CLASS(CTestCBotView)); - AddDocTemplate(pDocTemplate); - - // create main MDI Frame window - CMainFrame* pMainFrame = new CMainFrame; - if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) - return FALSE; - m_pMainWnd = pMainFrame; - - // Parse command line for standard shell commands, DDE, file open - CCommandLineInfo cmdInfo; - ParseCommandLine(cmdInfo); - - if (m_lpCmdLine[0] == 0) - { - CString Filename = GetProfileString(szSection, szFilename); - if (Filename.IsEmpty()) Filename = "TstCbot.txt"; - else OpenDocumentFile(Filename); - } - else - // Dispatch commands specified on the command line - if (!ProcessShellCommand(cmdInfo)) - return FALSE; - pMainFrame->ShowWindow(m_nCmdShow); - pMainFrame->UpdateWindow(); - - - return TRUE; -} - - -///////////////////////////////////////////////////////////////////////////// -// CAboutDlg dialog used for App About - -class CAboutDlg : public CDialog -{ -public: - CAboutDlg(); - -// Dialog Data - //{{AFX_DATA(CAboutDlg) - enum { IDD = IDD_ABOUTBOX }; - //}}AFX_DATA - - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CAboutDlg) - protected: - virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support - //}}AFX_VIRTUAL - -// Implementation -protected: - //{{AFX_MSG(CAboutDlg) - // No message handlers - //}}AFX_MSG - DECLARE_MESSAGE_MAP() -}; - -CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) -{ - //{{AFX_DATA_INIT(CAboutDlg) - //}}AFX_DATA_INIT -} - -void CAboutDlg::DoDataExchange(CDataExchange* pDX) -{ - CDialog::DoDataExchange(pDX); - //{{AFX_DATA_MAP(CAboutDlg) - //}}AFX_DATA_MAP -} - -BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) - //{{AFX_MSG_MAP(CAboutDlg) - // No message handlers - //}}AFX_MSG_MAP -END_MESSAGE_MAP() - -// App command to run the dialog -void CTestCBotApp::OnAppAbout() -{ - CAboutDlg aboutDlg; - aboutDlg.DoModal(); -} - -///////////////////////////////////////////////////////////////////////////// -// CTestCBotApp commands - -int CTestCBotApp::ExitInstance() -{ - delete m_pFuncFile; - - CBotProgram::Free(); - return CWinApp::ExitInstance(); -} diff --git a/src/CBot/tests/TestCBot/TestCBot.dsp b/src/CBot/tests/TestCBot/TestCBot.dsp deleted file mode 100644 index 8ed9b11..0000000 --- a/src/CBot/tests/TestCBot/TestCBot.dsp +++ /dev/null @@ -1,201 +0,0 @@ -# Microsoft Developer Studio Project File - Name="TestCBot" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 5.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Application" 0x0101 - -CFG=TestCBot - Win32 Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "TestCBot.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "TestCBot.mak" CFG="TestCBot - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "TestCBot - Win32 Release" (based on "Win32 (x86) Application") -!MESSAGE "TestCBot - Win32 Debug" (based on "Win32 (x86) Application") -!MESSAGE - -# Begin Project -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -MTL=midl.exe -RSC=rc.exe - -!IF "$(CFG)" == "TestCBot - Win32 Release" - -# PROP BASE Use_MFC 5 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 5 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "Release" -# PROP Intermediate_Dir "Release" -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /Yu"stdafx.h" /FD /c -# ADD CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /FR /Yu"stdafx.h" /FD /c -# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32 -# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32 -# ADD BASE RSC /l 0x100c /d "NDEBUG" -# ADD RSC /l 0x100c /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 /nologo /subsystem:windows /machine:I386 -# ADD LINK32 /nologo /subsystem:windows /machine:I386 - -!ELSEIF "$(CFG)" == "TestCBot - Win32 Debug" - -# PROP BASE Use_MFC 5 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 5 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "Debug" -# PROP Intermediate_Dir "Debug" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /Yu"stdafx.h" /FD /c -# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FR /Yu"stdafx.h" /FD /c -# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32 -# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32 -# ADD BASE RSC /l 0x100c /d "_DEBUG" -# ADD RSC /l 0x100c /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept -# ADD LINK32 /nologo /stack:0x7010 /subsystem:windows /debug /machine:I386 /pdbtype:sept - -!ENDIF - -# Begin Target - -# Name "TestCBot - Win32 Release" -# Name "TestCBot - Win32 Debug" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=.\CBotConsoleDlg.cpp -# End Source File -# Begin Source File - -SOURCE=.\ChildFrm.cpp -# End Source File -# Begin Source File - -SOURCE=.\MainFrm.cpp -# End Source File -# Begin Source File - -SOURCE=.\PerformDlg.cpp -# End Source File -# Begin Source File - -SOURCE=.\StdAfx.cpp -# ADD CPP /Yc"stdafx.h" -# End Source File -# Begin Source File - -SOURCE=.\TestCBot.cpp -# End Source File -# Begin Source File - -SOURCE=.\TestCBot.rc - -!IF "$(CFG)" == "TestCBot - Win32 Release" - -!ELSEIF "$(CFG)" == "TestCBot - Win32 Debug" - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=.\TestCBotDoc.cpp -# End Source File -# Begin Source File - -SOURCE=.\TestCBotView.cpp -# End Source File -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -# Begin Source File - -SOURCE=.\CBotConsoleDlg.h -# End Source File -# Begin Source File - -SOURCE=.\ChildFrm.h -# End Source File -# Begin Source File - -SOURCE=.\MainFrm.h -# End Source File -# Begin Source File - -SOURCE=.\PerformDlg.h -# End Source File -# Begin Source File - -SOURCE=.\Resource.h -# End Source File -# Begin Source File - -SOURCE=.\StdAfx.h -# End Source File -# Begin Source File - -SOURCE=.\TestCBot.h -# End Source File -# Begin Source File - -SOURCE=.\TestCBotDoc.h -# End Source File -# Begin Source File - -SOURCE=.\TestCBotView.h -# End Source File -# End Group -# Begin Group "Resource Files" - -# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe" -# Begin Source File - -SOURCE=.\res\TestCBot.ico -# End Source File -# Begin Source File - -SOURCE=.\res\TestCBot.rc2 -# End Source File -# Begin Source File - -SOURCE=.\res\TestCBotDoc.ico -# End Source File -# Begin Source File - -SOURCE=.\res\Toolbar.bmp -# End Source File -# End Group -# Begin Source File - -SOURCE=..\Debug\CBot.lib -# End Source File -# End Target -# End Project diff --git a/src/CBot/tests/TestCBot/TestCBot.h b/src/CBot/tests/TestCBot/TestCBot.h deleted file mode 100644 index c2595b6..0000000 --- a/src/CBot/tests/TestCBot/TestCBot.h +++ /dev/null @@ -1,78 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/.// TestCBot.h : main header file for the TESTCBOT application -// - -#if !defined(AFX_TESTCBOT_H__4D1BB903_8E74_11D4_A439_00D059085115__INCLUDED_) -#define AFX_TESTCBOT_H__4D1BB903_8E74_11D4_A439_00D059085115__INCLUDED_ - -#if _MSC_VER >= 1000 -#pragma once -#endif // _MSC_VER >= 1000 - -#ifndef __AFXWIN_H__ - #error include 'stdafx.h' before including this file for PCH -#endif - -#include "resource.h" // main symbols -//#include "../CbotDll.h" // librairie CBot -#include "../Cbot.h" // complet pour Browse - -class CTestCBotView; - -///////////////////////////////////////////////////////////////////////////// -// CTestCBotApp: -// See TestCBot.cpp for the implementation of this class -// - -class CTestCBotApp : public CWinApp -{ -public: - CTestCBotApp(); - - CEdit* m_pConsole; - CTestCBotView* m_LastActive; - CBotClass* m_pClassPoint; - CBotClass* m_pClassPointIntr; - - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CTestCBotApp) - public: - virtual BOOL InitInstance(); - virtual int ExitInstance(); - //}}AFX_VIRTUAL - -// Implementation - - //{{AFX_MSG(CTestCBotApp) - afx_msg void OnAppAbout(); - //}}AFX_MSG - DECLARE_MESSAGE_MAP() -}; - - -///////////////////////////////////////////////////////////////////////////// - -//{{AFX_INSERT_LOCATION}} -// Microsoft Developer Studio will insert additional declarations immediately before the previous line. - -#endif // !defined(AFX_TESTCBOT_H__4D1BB903_8E74_11D4_A439_00D059085115__INCLUDED_) - - -#define WM_STARTPROG WM_APP + 0 -#define WM_ENDPROG WM_APP + 1 -#define WM_ACTWINDOW WM_APP + 2 diff --git a/src/CBot/tests/TestCBot/TestCBot.rc b/src/CBot/tests/TestCBot/TestCBot.rc deleted file mode 100644 index 137458c..0000000 --- a/src/CBot/tests/TestCBot/TestCBot.rc +++ /dev/null @@ -1,564 +0,0 @@ -//Microsoft Developer Studio generated resource script. -// -#include "resource.h" - -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#include "afxres.h" - -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// French (France) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_FRA) -#ifdef _WIN32 -LANGUAGE LANG_FRENCH, SUBLANG_FRENCH -#pragma code_page(1252) -#endif //_WIN32 - -///////////////////////////////////////////////////////////////////////////// -// -// Icon -// - -// Icon with lowest ID value placed first to ensure application icon -// remains consistent on all systems. -IDR_MAINFRAME ICON DISCARDABLE "res\\TestCBot.ico" -IDR_TESTCBTYPE ICON DISCARDABLE "res\\TestCBotDoc.ico" - -///////////////////////////////////////////////////////////////////////////// -// -// Bitmap -// - -IDR_MAINFRAME BITMAP MOVEABLE PURE "res\\Toolbar.bmp" - -///////////////////////////////////////////////////////////////////////////// -// -// Toolbar -// - -IDR_MAINFRAME TOOLBAR DISCARDABLE 16, 15 -BEGIN - BUTTON ID_FILE_NEW - BUTTON ID_FILE_OPEN - BUTTON ID_FILE_SAVE - SEPARATOR - BUTTON ID_EDIT_CUT - BUTTON ID_EDIT_COPY - BUTTON ID_EDIT_PASTE - SEPARATOR - BUTTON ID_FILE_PRINT - BUTTON ID_RUN - SEPARATOR - BUTTON ID_APP_ABOUT -END - - -///////////////////////////////////////////////////////////////////////////// -// -// Menu -// - -IDR_MAINFRAME MENU PRELOAD DISCARDABLE -BEGIN - POPUP "&Fichier" - BEGIN - MENUITEM "&Nouveau\tCtrl+N", ID_FILE_NEW - MENUITEM "&Ouvrir...\tCtrl+O", ID_FILE_OPEN - MENUITEM SEPARATOR - MENUITEM "Fichier récent", ID_FILE_MRU_FILE1, GRAYED - MENUITEM SEPARATOR - MENUITEM "&Quitter", ID_APP_EXIT - END - POPUP "&Affichage" - BEGIN - MENUITEM "&Barre d'outils", ID_VIEW_TOOLBAR - MENUITEM "Barre d'é&tat", ID_VIEW_STATUS_BAR - END - POPUP "&?" - BEGIN - MENUITEM "&A propos de TestCBot...", ID_APP_ABOUT - END -END - -IDR_TESTCBTYPE MENU PRELOAD DISCARDABLE -BEGIN - POPUP "&Fichier" - BEGIN - MENUITEM "&Nouveau\tCtrl+N", ID_FILE_NEW - MENUITEM "&Ouvrir...\tCtrl+O", ID_FILE_OPEN - MENUITEM "&Fermer", ID_FILE_CLOSE - MENUITEM "&Enregistrer\tCtrl+S", ID_FILE_SAVE - MENUITEM "En®istrer sous...", ID_FILE_SAVE_AS - MENUITEM SEPARATOR - MENUITEM "Fichier récent", ID_FILE_MRU_FILE1, GRAYED - MENUITEM SEPARATOR - MENUITEM "&Quitter", ID_APP_EXIT - END - POPUP "&Edition" - BEGIN - MENUITEM "&Annuler\tCtrl+Z", ID_EDIT_UNDO - MENUITEM SEPARATOR - MENUITEM "&Couper\tCtrl+X", ID_EDIT_CUT - MENUITEM "&Copier\tCtrl+C", ID_EDIT_COPY - MENUITEM "C&oller\tCtrl+V", ID_EDIT_PASTE - END - POPUP "&Affichage" - BEGIN - MENUITEM "&Barre d'outils", ID_VIEW_TOOLBAR - MENUITEM "Barre d'é&tat", ID_VIEW_STATUS_BAR - END - POPUP "Fe&nêtre" - BEGIN - MENUITEM "&Nouvelle fenêtre", ID_WINDOW_NEW - MENUITEM "&Cascade", ID_WINDOW_CASCADE - MENUITEM "&Mosaïque", ID_WINDOW_TILE_HORZ - MENUITEM "&Réorganiser les icônes", ID_WINDOW_ARRANGE - END - POPUP "&?" - BEGIN - MENUITEM "&A propos de TestCBot...", ID_APP_ABOUT - END -END - - -///////////////////////////////////////////////////////////////////////////// -// -// Accelerator -// - -IDR_MAINFRAME ACCELERATORS PRELOAD MOVEABLE PURE -BEGIN - "C", ID_EDIT_COPY, VIRTKEY, CONTROL, NOINVERT - "N", ID_FILE_NEW, VIRTKEY, CONTROL, NOINVERT - "O", ID_FILE_OPEN, VIRTKEY, CONTROL, NOINVERT - "S", ID_FILE_SAVE, VIRTKEY, CONTROL, NOINVERT - "V", ID_EDIT_PASTE, VIRTKEY, CONTROL, NOINVERT - VK_BACK, ID_EDIT_UNDO, VIRTKEY, ALT, NOINVERT - VK_DELETE, ID_EDIT_CUT, VIRTKEY, SHIFT, NOINVERT - VK_F5, ID_RUN, VIRTKEY, NOINVERT - VK_F6, ID_NEXT_PANE, VIRTKEY, NOINVERT - VK_F6, ID_PREV_PANE, VIRTKEY, SHIFT, NOINVERT - VK_F7, ID_RUN, VIRTKEY, NOINVERT - VK_F9, ID_TEST, VIRTKEY, NOINVERT - VK_INSERT, ID_EDIT_COPY, VIRTKEY, CONTROL, NOINVERT - VK_INSERT, ID_EDIT_PASTE, VIRTKEY, SHIFT, NOINVERT - "X", ID_EDIT_CUT, VIRTKEY, CONTROL, NOINVERT - "Z", ID_EDIT_UNDO, VIRTKEY, CONTROL, NOINVERT -END - - -///////////////////////////////////////////////////////////////////////////// -// -// Dialog -// - -IDD_ABOUTBOX DIALOG DISCARDABLE 0, 0, 265, 206 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU -CAPTION "A propos de TestCBot" -FONT 8, "MS Sans Serif" -BEGIN - ICON IDR_MAINFRAME,IDC_STATIC,11,17,21,20 - LTEXT "TestCBot version 1.0",IDC_STATIC,40,10,119,8, - SS_NOPREFIX - LTEXT "Copyright D. Dumoulin (C) 2000",IDC_STATIC,40,25,119,8 - DEFPUSHBUTTON "OK",IDOK,226,7,32,14,WS_GROUP - LTEXT "Programme de test pour la librairie CBot\n\nLes fonctions doivent être déclarées comme ""extern"" pour apparaître dans la liste lors de l'exécution.\n\n", - IDC_STATIC,39,43,191,41 - LTEXT "Mais en fait, on peut accèder à toutes les fonctions marquées ""public"" quelles soient dans la fenêtre active ou non.", - IDC_STATIC,39,89,187,36 - LTEXT "Les fonctions print( ... ) et println( ...) permettent d'afficher des résultats dans la console.\n\nLa fonction show( ... ) affiche les paramètres dans un dialogue, et suspend donc l'exécution.", - IDC_STATIC,39,130,187,54 -END - -IDD_DIALOG2 DIALOG DISCARDABLE 0, 0, 186, 95 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU -CAPTION "Dialog" -FONT 8, "MS Sans Serif" -BEGIN - DEFPUSHBUTTON "OK",IDOK,129,7,50,14 - PUSHBUTTON "Cancel",IDCANCEL,129,24,50,14 -END - - -#ifndef _MAC -///////////////////////////////////////////////////////////////////////////// -// -// Version -// - -VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,0,0,1 - PRODUCTVERSION 1,0,0,1 - FILEFLAGSMASK 0x3fL -#ifdef _DEBUG - FILEFLAGS 0x1L -#else - FILEFLAGS 0x0L -#endif - FILEOS 0x4L - FILETYPE 0x1L - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040C04B0" - BEGIN - VALUE "CompanyName", "\0" - VALUE "FileDescription", "Application MFC TestCBot\0" - VALUE "FileVersion", "1, 0, 0, 1\0" - VALUE "InternalName", "TestCBot\0" - VALUE "LegalCopyright", "Copyright (C) 1900\0" - VALUE "LegalTrademarks", "\0" - VALUE "OriginalFilename", "TestCBot.EXE\0" - VALUE "ProductName", "Application TestCBot\0" - VALUE "ProductVersion", "1, 0, 0, 1\0" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Traduction", 0x40c, 1200 - END -END - -#endif // !_MAC - - -///////////////////////////////////////////////////////////////////////////// -// -// DESIGNINFO -// - -#ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO DISCARDABLE -BEGIN - IDD_ABOUTBOX, DIALOG - BEGIN - LEFTMARGIN, 7 - RIGHTMARGIN, 258 - TOPMARGIN, 7 - BOTTOMMARGIN, 199 - END - - IDD_DIALOG2, DIALOG - BEGIN - LEFTMARGIN, 7 - RIGHTMARGIN, 179 - TOPMARGIN, 7 - BOTTOMMARGIN, 88 - END -END -#endif // APSTUDIO_INVOKED - - -///////////////////////////////////////////////////////////////////////////// -// -// String Table -// - -STRINGTABLE PRELOAD DISCARDABLE -BEGIN - IDR_MAINFRAME "TestCBot" - IDR_TESTCBTYPE "\nTestCBot\nTestCBot\nCBot (*.txt)\n.txt\nTestCBot.Document\nTestCB Document" -END - -STRINGTABLE PRELOAD DISCARDABLE -BEGIN - AFX_IDS_APP_TITLE "TestCBot" - AFX_IDS_IDLEMESSAGE "Prêt" -END - -STRINGTABLE DISCARDABLE -BEGIN - ID_INDICATOR_EXT "EXT" - ID_INDICATOR_CAPS "MAJ" - ID_INDICATOR_NUM "NUM" - ID_INDICATOR_SCRL "DEF" - ID_INDICATOR_OVR "ECR" - ID_INDICATOR_REC "ENR" -END - -STRINGTABLE DISCARDABLE -BEGIN - ID_FILE_NEW "Crée un nouveau document\nNouveau" - ID_FILE_OPEN "Ouvre un document existant\nOuvrir" - ID_FILE_CLOSE "Ferme le document actif\nFermer" - ID_FILE_SAVE "Enregistre le document actif\nEnregistrer" - ID_FILE_SAVE_AS "Enregistre le document actif sous un nouveau nom\nEnregistrer sous" - ID_FILE_PRINT "Imprime le document\nImprime" -END - -STRINGTABLE DISCARDABLE -BEGIN - ID_APP_ABOUT "Affiche des informations sur le programme\nA propos de" - ID_APP_EXIT "Ferme l'application ; propose d'enregistrer les documents\nQuitter" -END - -STRINGTABLE DISCARDABLE -BEGIN - ID_FILE_MRU_FILE1 "Ouvre ce document" - ID_FILE_MRU_FILE2 "Ouvre ce document" - ID_FILE_MRU_FILE3 "Ouvre ce document" - ID_FILE_MRU_FILE4 "Ouvre ce document" - ID_FILE_MRU_FILE5 "Ouvre ce document" - ID_FILE_MRU_FILE6 "Ouvre ce document" - ID_FILE_MRU_FILE7 "Ouvre ce document" - ID_FILE_MRU_FILE8 "Ouvre ce document" - ID_FILE_MRU_FILE9 "Ouvre ce document" - ID_FILE_MRU_FILE10 "Ouvre ce document" - ID_FILE_MRU_FILE11 "Ouvre ce document" - ID_FILE_MRU_FILE12 "Ouvre ce document" - ID_FILE_MRU_FILE13 "Ouvre ce document" - ID_FILE_MRU_FILE14 "Ouvre ce document" - ID_FILE_MRU_FILE15 "Ouvre ce document" - ID_FILE_MRU_FILE16 "Ouvre ce document" -END - -STRINGTABLE DISCARDABLE -BEGIN - ID_NEXT_PANE "Passe au volet de fenêtre suivant\nVolet suivant" - ID_PREV_PANE "Revient au volet précédent\nVolet précédent" -END - -STRINGTABLE DISCARDABLE -BEGIN - ID_WINDOW_NEW "Ouvre une nouvelle fenêtre pour le document actif\nNouvelle fenêtre" - ID_WINDOW_ARRANGE "Réorganise les icônes en bas de la fenêtre\nRéorganise les icônes" - ID_WINDOW_CASCADE "Réorganise les fenêtres en cascade\nCascade" - ID_WINDOW_TILE_HORZ "Réorganise les fenêtres en une mosaïque\nMosaïque" - ID_WINDOW_TILE_VERT "Réorganise les fenêtres en une mosaïque\nMosaïque" - ID_WINDOW_SPLIT "Fractionne la fenêtre active en deux volets\nFractionner" -END - -STRINGTABLE DISCARDABLE -BEGIN - ID_EDIT_CLEAR "Efface la sélection\nEffacer" - ID_EDIT_CLEAR_ALL "Efface tout\nEffacer tout" - ID_EDIT_COPY "Copie la sélection et la place dans le Presse-papiers\nCopier" - ID_EDIT_CUT "Supprime la sélection et la place dans le Presse-papiers\nCopier" - ID_EDIT_FIND "Recherche le texte spécifié\nRechercher" - ID_EDIT_PASTE "Insère le contenu du Presse-papiers\nColler" - ID_EDIT_REPEAT "Répète la dernière action\nRépéter" - ID_EDIT_REPLACE "Remplace le texte spécifique par un texte différent\nRemplacer" - ID_EDIT_SELECT_ALL "Sélectionne le document entier\nSélectionner tout" - ID_EDIT_UNDO "Annule la dernière action\nAnnuler" - ID_EDIT_REDO "Rétablit l'action précédemment annulée\nRétablir" -END - -STRINGTABLE DISCARDABLE -BEGIN - ID_VIEW_TOOLBAR "Affiche ou masque la barre d'outils\nBarre d'outils" - ID_VIEW_STATUS_BAR "Affiche ou masque la barre d'état\nBarre d'état" -END - -STRINGTABLE DISCARDABLE -BEGIN - AFX_IDS_SCSIZE "Change la taille de la fenêtre" - AFX_IDS_SCMOVE "Change la position de la fenêtre" - AFX_IDS_SCMINIMIZE "Réduit la fenêtre en icône" - AFX_IDS_SCMAXIMIZE "Agrandit la fenêtre au format de l'écran" - AFX_IDS_SCNEXTWINDOW "Passe à la fenêtre de document suivante" - AFX_IDS_SCPREVWINDOW "Passe à la fenêtre de document précédente" - AFX_IDS_SCCLOSE "Ferme la fenêtre active et propose l'enregistrement des documents" -END - -STRINGTABLE DISCARDABLE -BEGIN - AFX_IDS_SCRESTORE "Restaure la fenêtre à sa taille d'origine" - AFX_IDS_SCTASKLIST "Active la liste des tâches" - AFX_IDS_MDICHILD "Active cette fenêtre" -END - -STRINGTABLE DISCARDABLE -BEGIN - ID_RUN "Execute le programme CBot\nExecute (F5)" -END - -STRINGTABLE DISCARDABLE -BEGIN - TX_TYPENAMES "les différents types" - 1001 "Byte" - 1002 "Short" - 1003 "Char" - 1004 "Int" - 1005 "Long" - 1006 "Real" - 1007 "Double" -END - -STRINGTABLE DISCARDABLE -BEGIN - 1008 "Boolean" - 1009 "String" - 1010 "Array" - 1011 "Arraybody" - 1012 "Pointer" - 1013 "Nullpointer" - 1014 "nop" - 1015 "Class" - 1016 "Intrinsic" -END - -#endif // French (France) resources -///////////////////////////////////////////////////////////////////////////// - - -///////////////////////////////////////////////////////////////////////////// -// French (Switzerland) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_FRS) -#ifdef _WIN32 -LANGUAGE LANG_FRENCH, SUBLANG_FRENCH_SWISS -#pragma code_page(1252) -#endif //_WIN32 - -///////////////////////////////////////////////////////////////////////////// -// -// Dialog -// - -IDD_CONSOLE DIALOG DISCARDABLE 0, 0, 401, 210 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU -CAPTION "CBot Console" -FONT 8, "MS Sans Serif" -BEGIN - LTEXT "Commande :",IDC_STATIC,7,177,40,8 - EDITTEXT IDC_EDIT2,7,189,329,14,ES_AUTOHSCROLL - DEFPUSHBUTTON "Exécute",IDOK,344,189,50,14 - EDITTEXT IDC_EDIT1,7,7,387,167,ES_MULTILINE | ES_READONLY | - ES_WANTRETURN | WS_VSCROLL -END - -IDD_DIALOG1 DIALOG DISCARDABLE 0, 0, 177, 100 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU -CAPTION "Test performances" -FONT 8, "MS Sans Serif" -BEGIN - LTEXT "Boucles par seconde",IDC_STATIC,7,9,68,8 - EDITTEXT IDC_EDIT1,111,7,51,14,ES_AUTOHSCROLL | ES_READONLY - LTEXT "Nombre de scripts",IDC_STATIC,7,55,58,8 - EDITTEXT IDC_EDIT2,111,52,40,14,ES_AUTOHSCROLL - CONTROL "Spin1",IDC_SPIN1,"msctls_updown32",UDS_ARROWKEYS,152,52, - 10,14 - COMBOBOX IDC_COMBO1,111,74,52,111,CBS_DROPDOWNLIST | WS_VSCROLL | - WS_TABSTOP - LTEXT "Timer",IDC_STATIC,7,77,18,8 - LTEXT "Performance %",IDC_STATIC,7,28,48,8 - EDITTEXT IDC_EDIT3,111,25,51,14,ES_AUTOHSCROLL | ES_READONLY -END - - -///////////////////////////////////////////////////////////////////////////// -// -// DESIGNINFO -// - -#ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO DISCARDABLE -BEGIN - IDD_CONSOLE, DIALOG - BEGIN - LEFTMARGIN, 7 - RIGHTMARGIN, 394 - TOPMARGIN, 7 - BOTTOMMARGIN, 203 - END - - IDD_DIALOG1, DIALOG - BEGIN - LEFTMARGIN, 7 - RIGHTMARGIN, 170 - TOPMARGIN, 7 - BOTTOMMARGIN, 93 - END -END -#endif // APSTUDIO_INVOKED - - -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// - -1 TEXTINCLUDE DISCARDABLE -BEGIN - "resource.h\0" -END - -2 TEXTINCLUDE DISCARDABLE -BEGIN - "#include ""afxres.h""\r\n" - "\0" -END - -3 TEXTINCLUDE DISCARDABLE -BEGIN - "#define _AFX_NO_SPLITTER_RESOURCES\r\n" - "#define _AFX_NO_OLE_RESOURCES\r\n" - "#define _AFX_NO_TRACKER_RESOURCES\r\n" - "#define _AFX_NO_PROPERTY_RESOURCES\r\n" - "\r\n" - "#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_FRA)\r\n" - "#ifdef _WIN32\r\n" - "LANGUAGE 12, 1\r\n" - "#pragma code_page(1252)\r\n" - "#endif\r\n" - "#include ""res\\TestCBot.rc2"" // non-Microsoft Visual C++ edited resources\r\n" - "#include ""l.fra\\afxres.rc"" // Standard components\r\n" - "#endif\0" -END - -#endif // APSTUDIO_INVOKED - - -///////////////////////////////////////////////////////////////////////////// -// -// Dialog Info -// - -IDD_DIALOG1 DLGINIT -BEGIN - IDC_COMBO1, 0x403, 2, 0 -0x0031, - IDC_COMBO1, 0x403, 3, 0 -0x3031, "\000" - IDC_COMBO1, 0x403, 4, 0 -0x3031, 0x0030, - IDC_COMBO1, 0x403, 5, 0 -0x3031, 0x3030, "\000" - 0 -END - -#endif // French (Switzerland) resources -///////////////////////////////////////////////////////////////////////////// - - - -#ifndef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 3 resource. -// -#define _AFX_NO_SPLITTER_RESOURCES -#define _AFX_NO_OLE_RESOURCES -#define _AFX_NO_TRACKER_RESOURCES -#define _AFX_NO_PROPERTY_RESOURCES - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_FRA) -#ifdef _WIN32 -LANGUAGE 12, 1 -#pragma code_page(1252) -#endif -#include "res\TestCBot.rc2" // non-Microsoft Visual C++ edited resources -#include "l.fra\afxres.rc" // Standard components -#endif -///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED - diff --git a/src/CBot/tests/TestCBot/TestCBotDoc.cpp b/src/CBot/tests/TestCBot/TestCBotDoc.cpp deleted file mode 100644 index 8880c57..0000000 --- a/src/CBot/tests/TestCBot/TestCBotDoc.cpp +++ /dev/null @@ -1,697 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/.// TestCBotDoc.cpp : implementation of the CTestCBotDoc class -// - -#include "stdafx.h" -#include "TestCBot.h" - -#include "TestCBotDoc.h" -#include "TestCBotView.h" -#include "CBotConsoleDlg.h" -#include "PerformDlg.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#undef THIS_FILE -static char THIS_FILE[] = __FILE__; -#endif - -///////////////////////////////////////////////////////////////////////////// -// CTestCBotDoc - -IMPLEMENT_DYNCREATE(CTestCBotDoc, CDocument) - -BEGIN_MESSAGE_MAP(CTestCBotDoc, CDocument) - //{{AFX_MSG_MAP(CTestCBotDoc) - ON_COMMAND(ID_RUN, OnRun) - ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1) - ON_COMMAND(ID_TEST, OnTest) - //}}AFX_MSG_MAP -END_MESSAGE_MAP() - -///////////////////////////////////////////////////////////////////////////// -// CTestCBotDoc construction/destruction - -static BOOL test = FALSE; - - -CTestCBotDoc::CTestCBotDoc() -{ - m_pEdit = NULL; - m_pProg = NULL; - m_bModified = FALSE; -} - -CTestCBotDoc::~CTestCBotDoc() -{ - delete m_pEdit; - delete m_pProg; -} - -BOOL CTestCBotDoc::OnNewDocument() -{ - if (!CDocument::OnNewDocument()) - return FALSE; - - return TRUE; -} - - - -///////////////////////////////////////////////////////////////////////////// -// CTestCBotDoc serialization - -void CTestCBotDoc::Serialize(CArchive& ar) -{ - if (ar.IsStoring()) - { - m_pEdit->GetWindowText(m_DocText); - int w = m_DocText.GetLength(); - ar.Write((LPCTSTR)m_DocText, w); - } - else - { - int r; - char buf[10001]; - - r = ar.Read(buf, 10000); - buf[r] = 0; - m_DocText = buf; - - if ( m_pProg == NULL ) m_pProg = new CBotProgram(); - - if (!m_pProg->Compile(m_DocText, m_Liste, NULL)) - { - delete m_pProg; - m_pProg = NULL; - } - } -} - -///////////////////////////////////////////////////////////////////////////// -// CTestCBotDoc diagnostics - -#ifdef _DEBUG -void CTestCBotDoc::AssertValid() const -{ - CDocument::AssertValid(); -} - -void CTestCBotDoc::Dump(CDumpContext& dc) const -{ - CDocument::Dump(dc); -} -#endif //_DEBUG - -///////////////////////////////////////////////////////////////////////////// -// CTestCBotDoc commands - -void CTestCBotDoc::OnRun() -{ - OnFileSave(); - - m_pEdit->GetWindowText(m_DocText); - - CString TextError; - int code, start, end; - - if ( m_pProg == NULL ) m_pProg = new CBotProgram(); - - CTestCBotApp* pApp = (CTestCBotApp*)AfxGetApp(); - - if (!m_pProg->Compile(m_DocText, m_Liste, NULL)) - { - m_pProg->GetError(code, start, end); - delete m_pProg; - m_pProg = NULL; - - m_pEdit->SetSel( start, end ); - m_pEdit->SetFocus(); // met en évidence la partie avec problème - - TextError = CBotProgram::GivErrorText( code ); - AfxMessageBox( TextError ); - - m_pEdit->SetFocus(); - return; - } - - if( m_Liste.GivSize() == 0 ) - { - AfxMessageBox("Aucune fonction marquée \"extern\" !"); - return; - } - - for ( int i = 0; i < m_Liste.GivSize(); i++ ) - { - int start, stop; - m_pProg->GetPosition(m_Liste[i], start, stop, GetPosNom, GetPosParam); - m_Liste[i] = m_DocText.Mid( start, stop-start ); - } - - CBotConsoleDlg dlg; - dlg.m_pListe = &m_Liste; - dlg.m_pEditx = m_pEdit; - - dlg.DoModal(); // dialogue pour faire la console - - if ( dlg.m_code>0 ) - { - CString TextError; - - TextError = m_pProg->GivErrorText( dlg.m_code ); - - m_pEdit->SetSel( dlg.m_start, dlg.m_end ); - m_pEdit->SetFocus(); // met en évidence la partie avec problème - - AfxMessageBox(TextError); - } - - m_pEdit->SetFocus(); - - return; -} - - -void CTestCBotDoc::OnChangeEdit1() -{ - SetModifiedFlag(); - m_bModified = TRUE; -} - -BOOL CTestCBotDoc::Compile() -{ - m_pEdit->GetWindowText(m_DocText); - - CString TextError; - int code, start, end; - - if ( m_pProg == NULL ) m_pProg = new CBotProgram(); - - char buffer[100]; - strcpy(buffer, "le pointeur à passer pour voir"); - - if (m_bModified && !m_pProg->Compile(m_DocText, m_Liste, (void*)buffer)) - { - m_pProg->GetError(code, start, end); - delete m_pProg; - m_pProg = NULL; - - m_pEdit->SetSel( start, end ); - m_pEdit->SetFocus(); // met en évidence la partie avec problème - - TextError = CBotProgram::GivErrorText( code ); - AfxMessageBox( TextError ); - - m_pEdit->SetFocus(); - m_bModified = FALSE; - return FALSE; - } - - if ( m_pProg->GetPosition( "TheTest", start, end) ) - { - m_pEdit->SetSel( start, end ); - m_pEdit->SetFocus(); // met en évidence la partie avec problème - } - - m_bModified = FALSE; - return TRUE; -} - - - -static int compt = 0; -// routine retournant le "pointeur" à un autre object -BOOL rRetObject( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) -{ - pResult->SetPointer( NULL ); - compt+=45671; - if (compt&0x11) return TRUE; - - CBotVar* pAutre = CBotVar::Create("autre", CBotTypResult( CBotTypClass, "object" )); - pAutre->SetUserPtr( (void*)2 ); - pResult->SetPointer( pAutre ); - - if (!pResult->IsElemOfClass("object")) - return TRUE; - - delete pAutre; - return TRUE; -} - -CBotTypResult cRetObject( CBotVar* &pVar, void* pUser ) -{ - return CBotTypResult( CBotTypPointer, "object"); -} - -BOOL roRadar( CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception ) -{ - pResult->SetPointer( NULL ); - compt+=45671; - if (compt&0x11) return TRUE; - - CBotVar* pAutre = CBotVar::Create("autre", CBotTypResult( CBotTypClass, "object" )); - pAutre->SetUserPtr( (void*)2 ); - pResult->SetPointer( pAutre ); - - if (!pResult->IsElemOfClass("object")) - return TRUE; - - delete pAutre; - return TRUE; -} - -CBotTypResult coRadar( CBotVar* pThis, CBotVar* &pVar ) -{ - void* pUser = pThis->GivUserPtr(); - return CBotTypResult( CBotTypPointer, "object"); -} - -BOOL rMove( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) -{ - if ( test < 12 ) - { - test++; - return FALSE; - } - return TRUE; -} - -CBotTypResult cMove( CBotVar* &pVar, void* pUser ) -{ - return CBotTypResult( 0 ); -} - -BOOL rTurn( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) -{ - return TRUE; -} - -CBotTypResult cTurn( CBotVar* &pVar, void* pUser ) -{ - return CBotTypResult( 0 ); -} - -BOOL rRadar( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) -{ - pResult->SetPointer( NULL ); - - if ( pVar ) pVar->debug(); - - compt+=45671; - if (compt&0x11) - { - return FALSE; // TRUE; - } - - CBotVar* pAutre = CBotVar::Create("autre", CBotTypResult( CBotTypClass, "object" )); - pAutre->SetUserPtr( (void*)2 ); - pResult->SetPointer( pAutre ); - - if (!pResult->IsElemOfClass("object")) - return TRUE; - - delete pAutre; - return TRUE; -} - -CBotTypResult cRadar( CBotVar* &pVar, void* pUser ) -{ - return CBotTypResult( CBotTypPointer, "object"); -} - -// routine retournant le "pointeur" à un autre object -BOOL rTEST( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) -{ - test = 1 ; - if ( pVar == NULL ) return TRUE; - - test = pVar->GivValInt(); - if ( test == 5 ) - { - pVar = pVar->GivNext(); - pVar->SetUserPtr( OBJECTDELETED ); - } - return TRUE; -} - -CBotTypResult cTEST( CBotVar* &pVar, void* pUser ) -{ - return CBotTypResult( 0 ); -} - -// routine retournant le "pointeur" à un autre object -BOOL rF( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) -{ - if ( pResult == NULL ) return TRUE; - pResult->SetValInt(3); - return TRUE; -} - -CBotTypResult cF( CBotVar* &pVar, void* pUser ) -{ - return CBotTypResult( CBotTypFloat ); -} - -///////////////////////////////////////////////////////////////// - -// Compilation d'une procédure avec un "point". - -CBotTypResult cPoint(CBotVar* &var, void* user) -{ - if ( var == 0 ) return CBotTypResult( CBotErrLowParam ); - - if ( var->GivType() <= CBotTypDouble ) - { - var = var->GivNext(); - if ( var == 0 ) return CBotTypResult( CBotErrLowParam ); - if ( var->GivType() > CBotTypDouble ) return CBotTypResult( CBotErrBadNum ); - var = var->GivNext(); - if ( var == 0 ) return CBotTypResult( CBotErrLowParam ); - if ( var->GivType() > CBotTypDouble ) return CBotTypResult( CBotErrBadNum ); - var = var->GivNext(); - return CBotTypResult( 0 ); - } - - if ( var->GivType() == CBotTypClass ) - { - if ( !var->IsElemOfClass("point") ) return CBotTypResult( CBotErrBadParam ); - var = var->GivNext(); - return CBotTypResult( 0 ); - } - - return CBotTypResult( CBotErrBadParam ); -} - -// Donne un paramètre de type "point". -#define UNIT 1 - - -CBotTypResult cSpace(CBotVar* &var, void* user) -{ - CBotTypResult ret; - - if ( var == 0 ) return CBotTypResult( CBotTypIntrinsic, "point" ); - ret = cPoint(var, user); - if ( !ret.Eq(0) ) return ret; - - if ( var == 0 ) return CBotTypIntrinsic; - if ( var->GivType() > CBotTypDouble ) return CBotTypResult( CBotErrBadNum ); - var = var->GivNext(); - - if ( var == 0 ) return CBotTypIntrinsic; - if ( var->GivType() > CBotTypDouble ) return CBotTypResult( CBotErrBadNum ); - var = var->GivNext(); - - if ( var == 0 ) return CBotTypIntrinsic; - if ( var->GivType() > CBotTypDouble ) return CBotTypResult( CBotErrBadNum ); - var = var->GivNext(); - - if ( var != 0 ) return CBotErrOverParam; - return CBotTypResult( CBotTypIntrinsic, "point" ); -} - -// Instruction "space(center, rMin, rMax, dist)". - -BOOL rSpace(CBotVar* var, CBotVar* result, int& exception, void* user) -{ - CBotVar* pSub; - float rMin, rMax, dist; - - rMin = 5.0f*UNIT; - rMax = 50.0f*UNIT; - dist = 4.0f*UNIT; - - if ( var == 0 ) - { -// center = pThis->RetPosition(0); - } - else - { - if ( var != 0 ) - { - rMin = var->GivValFloat()*UNIT; - var = var->GivNext(); - - if ( var != 0 ) - { - rMax = var->GivValFloat()*UNIT; - var = var->GivNext(); - - if ( var != 0 ) - { - dist = var->GivValFloat()*UNIT; - var = var->GivNext(); - } - } - } - } - - if ( result != 0 ) - { - pSub = result->GivItemList(); - if ( pSub != 0 ) - { - pSub->SetValFloat(1); - pSub = pSub->GivNext(); // "y" - pSub->SetValFloat(2); - pSub = pSub->GivNext(); // "z" -// pSub->SetValFloat(3); - } - } - return TRUE; -} -////////////////////////////////////////////////////////////// - - -void CTestCBotDoc::OnTest() -{ - CBotProgram::DefineNum("WingedGrabber", 1); - CBotProgram::DefineNum("TrackedGrabber", 2); - CBotProgram::DefineNum("WheeledGrabber", 3); - CBotProgram::DefineNum("LeggedGrabber", 4); - CBotProgram::DefineNum("WingedShooter", 5); - CBotProgram::DefineNum("TrackedShooter", 6); - CBotProgram::DefineNum("WheeledShooter", 7); - CBotProgram::DefineNum("LeggedShooter", 8); - CBotProgram::DefineNum("WingedOrgaShooter", 9); - CBotProgram::DefineNum("TrackedOrgaShooter", 10); - CBotProgram::DefineNum("WheeledOrgaShooter", 11); - CBotProgram::DefineNum("LeggedOrgaShooter", 12); - CBotProgram::DefineNum("WingedSniffer", 13); - CBotProgram::DefineNum("TrackedSniffer", 14); - CBotProgram::DefineNum("WheeledSniffer", 14); - CBotProgram::DefineNum("LeggedSniffer", 15); - CBotProgram::DefineNum("Thumper", 16); - CBotProgram::DefineNum("PhazerShooter", 17); - CBotProgram::DefineNum("Recycler", 18); - CBotProgram::DefineNum("Shielder", 19); - CBotProgram::DefineNum("Subber", 20); - CBotProgram::DefineNum("Me", 21); - - CBotProgram::DefineNum("TypeMarkPath", 111); - - OnFileSave(); - -// CPerformDlg dlg; -// dlg.m_Script = m_DocText; -// dlg.DoModal(); - - // défini la routine RetObject - CBotProgram::AddFunction( "Radar", rRetObject, cRetObject ); - - // ajoute une routine pour cette classe - CBotProgram::AddFunction("Space", rSpace, cSpace); - - // défini la routine Test - CBotProgram::AddFunction( "TEST", rTEST, cTEST ); - CBotProgram::AddFunction( "F", rF, cF ); - - CBotProgram::AddFunction( "goto", rMove, cMove ); - CBotProgram::AddFunction( "fire", rTurn, cTurn ); - CBotProgram::AddFunction( "radar", rRadar, cRadar ); - - // crée une instance de la classe "Bot" pour ce robot - CBotVar* pThisRobot = CBotVar::Create( "", CBotTypResult(CBotTypClass, "object") ); - pThisRobot->SetUserPtr( (void*)1 ); - pThisRobot->SetIdent( 1234 ); - - delete m_pProg; - // crée un objet programme associé à cette instance - m_pProg = new CBotProgram(pThisRobot); - - // compile le programme - CString TextError; - int code, start, end; - - m_pEdit->GetWindowText(m_DocText); - if (!m_pProg->Compile(m_DocText, m_Liste, (void*) 44)) - { - m_pProg->GetError(code, start, end); - delete m_pProg; - m_pProg = NULL; - - delete pThisRobot; - - m_pEdit->SetSel( start, end ); - m_pEdit->SetFocus(); // met en évidence la partie avec problème - - TextError = CBotProgram::GivErrorText( code ); - AfxMessageBox( TextError ); - - m_pEdit->SetFocus(); - return; - } - - // exécute pour voir - m_pProg->Start(m_Liste[0]); - - int mode = -1; - - if ( mode >= 0 ) { - - // sauve et restore à chaque pas possible - while (!m_pProg->Run(NULL, 1)) - { - const char* FunctionName; - int start1, end1; - m_pProg->GetRunPos(FunctionName, start1, end1); - if ( end1 <= 0 ) - m_pProg->GetRunPos(FunctionName, start1, end1); - m_pEdit->SetSel(start1, end1); - -if ( mode == 0 ) continue; - - FILE* pf; - pf = fOpen( "TEST.CBO", "wb" ); - CBotClass::SaveStaticState(pf); - m_pProg->SaveState(pf); - fClose(pf); - -if ( mode == 2 ) if (!m_pProg->Compile(m_DocText, m_Liste, (void*) 44)) - { - m_pProg->GetError(code, start, end); - delete m_pProg; - m_pProg = NULL; - - delete pThisRobot; - - m_pEdit->SetSel( start, end ); - m_pEdit->SetFocus(); // met en évidence la partie avec problème - - TextError = CBotProgram::GivErrorText( code ); - AfxMessageBox( TextError ); - - m_pEdit->SetFocus(); - return; - } - - pf = fOpen( "TEST.CBO", "rb" ); - CBotClass::RestoreStaticState(pf); - m_pProg->RestoreState(pf); - fClose(pf); - - int start2, end2; - m_pProg->GetRunPos(FunctionName, start2, end2); - if ( end2 <= 0 ) - m_pProg->GetRunPos(FunctionName, start2, end2); - - if ( start1 != start2 || end1 != end2 ) - m_pProg->GetRunPos(FunctionName, start2, end2); - m_pEdit->SetSel(start2, end2); - } - - if (m_pProg->GetError(code, start, end)) - { - m_pEdit->SetSel(start, end); - TextError = CBotProgram::GivErrorText(code); - AfxMessageBox(TextError); - } - return;} - - while (!m_pProg->Run(NULL, 0)) - { - const char* FunctionName; - int start, end; - m_pProg->GetRunPos(FunctionName, start, end); - m_pEdit->SetSel(start, end); - - if ( FunctionName == NULL ) continue; - CString info (FunctionName); - CString sep (":\n"); - - int level = 0; - const char* Name; - while ( TRUE ) - { - CBotVar* pVar = m_pProg->GivStackVars(Name, level--); - if ( Name != FunctionName ) break; - if ( pVar == NULL ) continue; -// pVar->Maj(NULL, FALSE); - while ( pVar != NULL ) - { - info += sep; - info += pVar->GivName() + CBotString(" = ") + pVar->GivValString(); - sep = ", "; - pVar = pVar->GivNext(); - } - sep = "\n"; - } - if ( IDOK != AfxMessageBox(info, MB_OKCANCEL) ) break; - - if ( test == 1 ) - { - test = 0; - FILE* pf; - pf = fOpen( "TEST.CBO", "wb" ); - m_pProg->SaveState(pf); - fClose(pf); - } - - if ( test == 2 ) - { - test = 0; - FILE* pf; - pf = fOpen( "TEST.CBO", "rb" ); - m_pProg->RestoreState(pf); - fClose(pf); - } - - if ( test == 12 ) - { - test = 0; - FILE* pf; - pf = fOpen( "TEST.CBO", "wb" ); - m_pProg->SaveState(pf); - fClose(pf); - - pf = fOpen( "TEST.CBO", "rb" ); - m_pProg->RestoreState(pf); - fClose(pf); - - test = 13; - } - } - - if (m_pProg->GetError(code, start, end)) - { - m_pEdit->SetSel(start, end); - TextError = CBotProgram::GivErrorText(code); - AfxMessageBox(TextError); - } - - delete pThisRobot; -} - diff --git a/src/CBot/tests/TestCBot/TestCBotDoc.h b/src/CBot/tests/TestCBot/TestCBotDoc.h deleted file mode 100644 index 548607f..0000000 --- a/src/CBot/tests/TestCBot/TestCBotDoc.h +++ /dev/null @@ -1,78 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/.// TestCBotDoc.h : interface of the CTestCBotDoc class -// -///////////////////////////////////////////////////////////////////////////// - -#if !defined(AFX_TESTCBOTDOC_H__4D1BB90B_8E74_11D4_A439_00D059085115__INCLUDED_) -#define AFX_TESTCBOTDOC_H__4D1BB90B_8E74_11D4_A439_00D059085115__INCLUDED_ - -#if _MSC_VER >= 1000 -#pragma once -#endif // _MSC_VER >= 1000 - - -class CTestCBotDoc : public CDocument -{ -protected: // create from serialization only - CTestCBotDoc(); - DECLARE_DYNCREATE(CTestCBotDoc) - -// Attributes -public: - CEdit* m_pEdit; // pour mémoriser le texte, et l'afficher - CBotProgram* m_pProg; // le programme compilé - CString m_DocText; - CBotStringArray m_Liste; - BOOL m_bModified; - -// Operations -public: - BOOL Compile(); - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CTestCBotDoc) - public: - virtual BOOL OnNewDocument(); - virtual void Serialize(CArchive& ar); - //}}AFX_VIRTUAL - -// Implementation -public: - virtual ~CTestCBotDoc(); -#ifdef _DEBUG - virtual void AssertValid() const; - virtual void Dump(CDumpContext& dc) const; -#endif - -protected: - -// Generated message map functions -protected: - //{{AFX_MSG(CTestCBotDoc) - afx_msg void OnRun(); - afx_msg void OnChangeEdit1(); - afx_msg void OnTest(); - //}}AFX_MSG - DECLARE_MESSAGE_MAP() -}; - -///////////////////////////////////////////////////////////////////////////// - -//{{AFX_INSERT_LOCATION}} -// Microsoft Developer Studio will insert additional declarations immediately before the previous line. - -#endif // !defined(AFX_TESTCBOTDOC_H__4D1BB90B_8E74_11D4_A439_00D059085115__INCLUDED_) diff --git a/src/CBot/tests/TestCBot/TestCBotView.cpp b/src/CBot/tests/TestCBot/TestCBotView.cpp deleted file mode 100644 index bca3c56..0000000 --- a/src/CBot/tests/TestCBot/TestCBotView.cpp +++ /dev/null @@ -1,142 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/. - -// TestCBotView.cpp : implementation of the CTestCBotView class -// - -#include "stdafx.h" -#include "TestCBot.h" - -#include "TestCBotDoc.h" -#include "TestCBotView.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#undef THIS_FILE -static char THIS_FILE[] = __FILE__; -#endif - -///////////////////////////////////////////////////////////////////////////// -// CTestCBotView - -IMPLEMENT_DYNCREATE(CTestCBotView, CView) - -BEGIN_MESSAGE_MAP(CTestCBotView, CView) - //{{AFX_MSG_MAP(CTestCBotView) - ON_WM_SIZE() - ON_MESSAGE(WM_ACTWINDOW, ActWindow) - //}}AFX_MSG_MAP -END_MESSAGE_MAP() - -///////////////////////////////////////////////////////////////////////////// -// CTestCBotView construction/destruction - -CTestCBotView::CTestCBotView() -{ -} - -CTestCBotView::~CTestCBotView() -{ -} - -BOOL CTestCBotView::PreCreateWindow(CREATESTRUCT& cs) -{ - return CView::PreCreateWindow(cs); -} - -///////////////////////////////////////////////////////////////////////////// -// CTestCBotView drawing - -void CTestCBotView::OnDraw(CDC* pDC) -{ - CTestCBotDoc* pDoc = GetDocument(); - ASSERT_VALID(pDoc); -} - -///////////////////////////////////////////////////////////////////////////// -// CTestCBotView diagnostics - -#ifdef _DEBUG -void CTestCBotView::AssertValid() const -{ - CView::AssertValid(); -} - -void CTestCBotView::Dump(CDumpContext& dc) const -{ - CView::Dump(dc); -} - -CTestCBotDoc* CTestCBotView::GetDocument() // non-debug version is inline -{ - ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTestCBotDoc))); - return (CTestCBotDoc*)m_pDocument; -} -#endif //_DEBUG - -///////////////////////////////////////////////////////////////////////////// -// CTestCBotView message handlers - -void CTestCBotView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) -{ - CTestCBotDoc* pDoc = GetDocument(); -// CTestCBotApp* pApp = (CTestCBotApp*)AfxGetApp(); - - if ( pDoc->m_pEdit == NULL) - { - pDoc->m_pEdit = new CEdit(); - CRect rect; - GetClientRect( rect ); - - pDoc->m_pEdit->Create( WS_VISIBLE|WS_BORDER|WS_TABSTOP|ES_MULTILINE|ES_WANTRETURN|ES_NOHIDESEL|ES_AUTOVSCROLL, - rect, this, IDC_EDIT1 ); - pDoc->m_pEdit->SetTabStops(12); - pDoc->m_pEdit->SetWindowText(pDoc->m_DocText); - } - - if ( !bActivate && !pDoc->Compile() ) - { -// comment faire pour réactiver l'ancien document - } - - CView::OnActivateView(bActivate, pActivateView, pDeactiveView); - - if ( bActivate ) pDoc->m_pEdit->SetFocus(); -} - - -void CTestCBotView::OnSize(UINT nType, int cx, int cy) -{ - CView::OnSize(nType, cx, cy); - - CTestCBotDoc* pDoc = GetDocument(); - if ( pDoc->m_pEdit != NULL ) - { - CRect rect; - GetClientRect( rect ); - pDoc->m_pEdit->MoveWindow( rect ); - pDoc->m_pEdit->SetFocus(); - } -} - - - -LONG CTestCBotView::ActWindow(UINT wparam, LONG lparam) -{ -// GetParentFrame()->SetActiveView( this, TRUE ); -// CMDIChildWnd::OnMDIActivate(1, this, this) - return 0; -} diff --git a/src/CBot/tests/TestCBot/TestCBotView.h b/src/CBot/tests/TestCBot/TestCBotView.h deleted file mode 100644 index 065ee08..0000000 --- a/src/CBot/tests/TestCBot/TestCBotView.h +++ /dev/null @@ -1,78 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/.// TestCBotView.h : interface of the CTestCBotView class -// -///////////////////////////////////////////////////////////////////////////// - -#if !defined(AFX_TESTCBOTVIEW_H__4D1BB90D_8E74_11D4_A439_00D059085115__INCLUDED_) -#define AFX_TESTCBOTVIEW_H__4D1BB90D_8E74_11D4_A439_00D059085115__INCLUDED_ - -#if _MSC_VER >= 1000 -#pragma once -#endif // _MSC_VER >= 1000 - -class CTestCBotView : public CView -{ -protected: // create from serialization only - CTestCBotView(); - DECLARE_DYNCREATE(CTestCBotView) - -// Attributes -public: - CTestCBotDoc* GetDocument(); - -// Operations -public: - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CTestCBotView) - public: - virtual void OnDraw(CDC* pDC); // overridden to draw this view - virtual BOOL PreCreateWindow(CREATESTRUCT& cs); - protected: - virtual void OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView); - //}}AFX_VIRTUAL - -// Implementation -public: - virtual ~CTestCBotView(); -#ifdef _DEBUG - virtual void AssertValid() const; - virtual void Dump(CDumpContext& dc) const; -#endif - -protected: - -// Generated message map functions -protected: - //{{AFX_MSG(CTestCBotView) - afx_msg void OnSize(UINT nType, int cx, int cy); - afx_msg LONG ActWindow(UINT wparam, LONG lparam) ; - //}}AFX_MSG - DECLARE_MESSAGE_MAP() -}; - -#ifndef _DEBUG // debug version in TestCBotView.cpp -inline CTestCBotDoc* CTestCBotView::GetDocument() - { return (CTestCBotDoc*)m_pDocument; } -#endif - -///////////////////////////////////////////////////////////////////////////// - -//{{AFX_INSERT_LOCATION}} -// Microsoft Developer Studio will insert additional declarations immediately before the previous line. - -#endif // !defined(AFX_TESTCBOTVIEW_H__4D1BB90D_8E74_11D4_A439_00D059085115__INCLUDED_) diff --git "a/src/CBot/tests/TestCBot/a\2471.txt~" "b/src/CBot/tests/TestCBot/a\2471.txt~" deleted file mode 100644 index 0c57950..0000000 --- "a/src/CBot/tests/TestCBot/a\2471.txt~" +++ /dev/null @@ -1,96 +0,0 @@ -object radarGuepe(point orig, float dist) -{ - int i; - object pr, r; - float mindist; - - i = 0; - mindist = 1000; - while (i<30) - { - pr = radar(i); - if (pr != null) - { - - if (F(orig, pr.position) < mindist and pr.category == AlienWasp and pr.altitude > 3) - { - mindist = distance(orig, pr.position); - r = pr; - } - } - i = i+1; - } - if (mindist < dist) return(r); else return(null); -} - - -class Guepe -{ - - point pos; - - - void cherche(point orig, float dist) - { - object p; - point o; - - p = radarGuepe(orig, dist); - while (p == null) - { - wait(0.1); - p = radarGuepe(orig, dist); - } - - pos.x = p.position.x; - pos.y = p.position.y; - pos.z = p.position.z; - - //o = p.position; - //wait(0.1); - - //vitessex = (p.position.x - o.x)/0.1; - //vitessey = (p.position.y - o.y)/0.1; - //vitessez = (p.position.z - o.z)/0.1; - - } - - - void tire(point orig, float orient) - { - //float t = 3; //temps d'anticipation - float angle; - point cible; - - cible.x = pos.x;// + t*vitessex; - cible.y = pos.y;// + t*vitessey; - cible.z = pos.z;// + t*vitessez; - - if (cible.x == 0) angle = 90; else - angle = atan(cible.y / cible.x); - if (cible.x < 0) angle = angle + 180; - angle = angle - orient; - if (angle > 180) angle = angle - 360; - if (angle < -180) angle = angle + 360; - turn(angle); - - angle = atan((cible.z-orig.z) / distance2d(orig, cible)); - aim(angle); - - fire(0.1); - - } -} - -extern void object::Fourmi6() -{ - //fps(1000); - Guepe guepe = new Guepe(); - - while (true) - { - guepe.cherche(position, 50); - - guepe.tire(position, orientation); - } -} diff --git a/src/CBot/tests/TestCBot/res/TestCBot.ico b/src/CBot/tests/TestCBot/res/TestCBot.ico deleted file mode 100644 index 06a649d..0000000 Binary files a/src/CBot/tests/TestCBot/res/TestCBot.ico and /dev/null differ diff --git a/src/CBot/tests/TestCBot/res/TestCBot.rc2 b/src/CBot/tests/TestCBot/res/TestCBot.rc2 deleted file mode 100644 index b55f0d9..0000000 --- a/src/CBot/tests/TestCBot/res/TestCBot.rc2 +++ /dev/null @@ -1,13 +0,0 @@ -// -// TESTCBOT.RC2 - resources Microsoft Visual C++ does not edit directly -// - -#ifdef APSTUDIO_INVOKED - #error this file is not editable by Microsoft Visual C++ -#endif //APSTUDIO_INVOKED - - -///////////////////////////////////////////////////////////////////////////// -// Add manually edited resources here... - -///////////////////////////////////////////////////////////////////////////// diff --git a/src/CBot/tests/TestCBot/res/TestCBotDoc.ico b/src/CBot/tests/TestCBot/res/TestCBotDoc.ico deleted file mode 100644 index 3545614..0000000 Binary files a/src/CBot/tests/TestCBot/res/TestCBotDoc.ico and /dev/null differ diff --git a/src/CBot/tests/TestCBot/res/Toolbar.bmp b/src/CBot/tests/TestCBot/res/Toolbar.bmp deleted file mode 100644 index 04a71af..0000000 Binary files a/src/CBot/tests/TestCBot/res/Toolbar.bmp and /dev/null differ diff --git a/src/CBot/tests/TestCBot/resource.h b/src/CBot/tests/TestCBot/resource.h deleted file mode 100644 index d661201..0000000 --- a/src/CBot/tests/TestCBot/resource.h +++ /dev/null @@ -1,44 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/.//{{NO_DEPENDENCIES}} -// Microsoft Developer Studio generated include file. -// Used by TestCBot.rc -// -#define IDD_ABOUTBOX 100 -#define IDR_MAINFRAME 128 -#define IDR_TESTCBTYPE 129 -#define IDD_DIALOG1 130 -#define IDD_CONSOLE 131 -#define IDD_DIALOG2 133 -#define IDC_EDIT1 1000 -#define TX_TYPENAMES 1000 -#define IDC_SPIN1 1001 -#define IDC_EDIT2 1002 -#define IDC_COMBO1 1003 -#define IDC_EDIT3 1004 -#define ID_RUN 32771 -#define ID_TEST 32772 - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_3D_CONTROLS 1 -#define _APS_NEXT_RESOURCE_VALUE 135 -#define _APS_NEXT_COMMAND_VALUE 32773 -#define _APS_NEXT_CONTROL_VALUE 1004 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif diff --git a/src/CBot/tests/TestCBot/xTestCBot.clw b/src/CBot/tests/TestCBot/xTestCBot.clw deleted file mode 100644 index 5b84c16..0000000 --- a/src/CBot/tests/TestCBot/xTestCBot.clw +++ /dev/null @@ -1,245 +0,0 @@ -; CLW file contains information for the MFC ClassWizard - -[General Info] -Version=1 -LastClass=CBotConsoleDlg -LastTemplate=CDialog -NewFileInclude1=#include "stdafx.h" -NewFileInclude2=#include "TestCBot.h" -LastPage=0 - -ClassCount=7 -Class1=CTestCBotApp -Class2=CTestCBotDoc -Class3=CTestCBotView -Class4=CMainFrame - -ResourceCount=7 -Resource1=IDD_ABOUTBOX -Resource2=IDR_MAINFRAME -Resource3=IDR_TESTCBTYPE -Class5=CAboutDlg -Class6=CChildFrame -Resource4=IDD_ABOUTBOX (French (France)) -Resource5=IDR_TESTCBTYPE (French (France)) -Resource6=IDD_CONSOLE -Class7=CBotConsoleDlg -Resource7=IDR_MAINFRAME (French (France)) - -[CLS:CTestCBotApp] -Type=0 -HeaderFile=TestCBot.h -ImplementationFile=TestCBot.cpp -Filter=N - -[CLS:CTestCBotDoc] -Type=0 -HeaderFile=TestCBotDoc.h -ImplementationFile=TestCBotDoc.cpp -Filter=N -BaseClass=CDocument -VirtualFilter=DC -LastObject=IDC_EDIT2 - -[CLS:CTestCBotView] -Type=0 -HeaderFile=TestCBotView.h -ImplementationFile=TestCBotView.cpp -Filter=C -BaseClass=CView -VirtualFilter=VWC -LastObject=CTestCBotView - -[CLS:CMainFrame] -Type=0 -HeaderFile=MainFrm.h -ImplementationFile=MainFrm.cpp -Filter=T -BaseClass=CMDIFrameWnd -VirtualFilter=fWC -LastObject=CMainFrame - - -[CLS:CChildFrame] -Type=0 -HeaderFile=ChildFrm.h -ImplementationFile=ChildFrm.cpp -Filter=M - -[CLS:CAboutDlg] -Type=0 -HeaderFile=TestCBot.cpp -ImplementationFile=TestCBot.cpp -Filter=D - -[DLG:IDD_ABOUTBOX] -Type=1 -ControlCount=4 -Control1=IDC_STATIC,static,1342177283 -Control2=IDC_STATIC,static,1342308352 -Control3=IDC_STATIC,static,1342308352 -Control4=IDOK,button,1342373889 -Class=CAboutDlg - -[MNU:IDR_MAINFRAME] -Type=1 -Class=CMainFrame -Command1=ID_FILE_NEW -Command2=ID_FILE_OPEN -Command4=ID_APP_EXIT -Command5=ID_VIEW_TOOLBAR -Command6=ID_VIEW_STATUS_BAR -Command7=ID_APP_ABOUT -CommandCount=7 -Command3=ID_FILE_MRU_FILE1 - -[TB:IDR_MAINFRAME] -Type=1 -Class=CMainFrame -Command1=ID_FILE_NEW -Command2=ID_FILE_OPEN -Command3=ID_FILE_SAVE -Command4=ID_EDIT_CUT -Command5=ID_EDIT_COPY -Command6=ID_EDIT_PASTE -Command7=ID_FILE_PRINT -CommandCount=8 -Command8=ID_APP_ABOUT - -[MNU:IDR_TESTCBTYPE] -Type=1 -Class=CTestCBotView -Command1=ID_FILE_NEW -Command2=ID_FILE_OPEN -Command3=ID_FILE_CLOSE -Command4=ID_FILE_SAVE -Command5=ID_FILE_SAVE_AS -Command9=ID_EDIT_CUT -Command10=ID_EDIT_COPY -Command11=ID_EDIT_PASTE -Command12=ID_VIEW_TOOLBAR -Command13=ID_VIEW_STATUS_BAR -Command14=ID_WINDOW_NEW -CommandCount=18 -Command6=ID_FILE_MRU_FILE1 -Command7=ID_APP_EXIT -Command8=ID_EDIT_UNDO -Command15=ID_WINDOW_CASCADE -Command16=ID_WINDOW_TILE_HORZ -Command17=ID_WINDOW_ARRANGE -Command18=ID_APP_ABOUT - -[ACL:IDR_MAINFRAME] -Type=1 -Class=CMainFrame -Command1=ID_FILE_NEW -Command2=ID_FILE_OPEN -Command3=ID_FILE_SAVE -Command5=ID_EDIT_CUT -Command6=ID_EDIT_COPY -Command7=ID_EDIT_PASTE -Command8=ID_EDIT_UNDO -Command9=ID_EDIT_CUT -Command10=ID_EDIT_COPY -Command11=ID_EDIT_PASTE -Command12=ID_NEXT_PANE -CommandCount=13 -Command4=ID_EDIT_UNDO -Command13=ID_PREV_PANE - - -[TB:IDR_MAINFRAME (French (France))] -Type=1 -Class=? -Command1=ID_FILE_NEW -Command2=ID_FILE_OPEN -Command3=ID_FILE_SAVE -Command4=ID_EDIT_CUT -Command5=ID_EDIT_COPY -Command6=ID_EDIT_PASTE -Command7=ID_FILE_PRINT -Command8=ID_RUN -Command9=ID_APP_ABOUT -CommandCount=9 - -[MNU:IDR_MAINFRAME (French (France))] -Type=1 -Class=? -Command1=ID_FILE_NEW -Command2=ID_FILE_OPEN -Command3=ID_FILE_MRU_FILE1 -Command4=ID_APP_EXIT -Command5=ID_VIEW_TOOLBAR -Command6=ID_VIEW_STATUS_BAR -Command7=ID_APP_ABOUT -CommandCount=7 - -[MNU:IDR_TESTCBTYPE (French (France))] -Type=1 -Class=? -Command1=ID_FILE_NEW -Command2=ID_FILE_OPEN -Command3=ID_FILE_CLOSE -Command4=ID_FILE_SAVE -Command5=ID_FILE_SAVE_AS -Command6=ID_FILE_MRU_FILE1 -Command7=ID_APP_EXIT -Command8=ID_EDIT_UNDO -Command9=ID_EDIT_CUT -Command10=ID_EDIT_COPY -Command11=ID_EDIT_PASTE -Command12=ID_VIEW_TOOLBAR -Command13=ID_VIEW_STATUS_BAR -Command14=ID_WINDOW_NEW -Command15=ID_WINDOW_CASCADE -Command16=ID_WINDOW_TILE_HORZ -Command17=ID_WINDOW_ARRANGE -Command18=ID_APP_ABOUT -CommandCount=18 - -[ACL:IDR_MAINFRAME (French (France))] -Type=1 -Class=? -Command1=ID_EDIT_COPY -Command2=ID_FILE_NEW -Command3=ID_FILE_OPEN -Command4=ID_FILE_SAVE -Command5=ID_EDIT_PASTE -Command6=ID_EDIT_UNDO -Command7=ID_EDIT_CUT -Command8=ID_RUN -Command9=ID_NEXT_PANE -Command10=ID_PREV_PANE -Command11=ID_RUN -Command12=ID_EDIT_COPY -Command13=ID_EDIT_PASTE -Command14=ID_EDIT_CUT -Command15=ID_EDIT_UNDO -CommandCount=15 - -[DLG:IDD_ABOUTBOX (French (France))] -Type=1 -Class=CAboutDlg -ControlCount=4 -Control1=IDC_STATIC,static,1342177283 -Control2=IDC_STATIC,static,1342308480 -Control3=IDC_STATIC,static,1342308352 -Control4=IDOK,button,1342373889 - -[DLG:IDD_CONSOLE] -Type=1 -Class=CBotConsoleDlg -ControlCount=4 -Control1=IDC_STATIC,static,1342308352 -Control2=IDC_EDIT2,edit,1350631552 -Control3=IDOK,button,1342242817 -Control4=IDC_EDIT1,edit,1352734724 - -[CLS:CBotConsoleDlg] -Type=0 -HeaderFile=CBotConsoleDlg.h -ImplementationFile=CBotConsoleDlg.cpp -BaseClass=CDialog -Filter=D -VirtualFilter=dWC - diff --git a/src/CBot/tests/scenarios/B.txt b/src/CBot/tests/scenarios/B.txt deleted file mode 100644 index 53715f8..0000000 --- a/src/CBot/tests/scenarios/B.txt +++ /dev/null @@ -1,18 +0,0 @@ - - float [ ] TEST2 ( int [ ] param ) - { - float [ ] z; - for ( int i = 0 ; i < sizeof( param ) ; i++ ) try { z [i] = param [i] / 3; } - return z; - } - -extern public void T() -{ - int a [4]; - for ( int i = 0 ; i < 3 ; i++ ) a[i] = 4*i; - a [2] = 22; - - float [] b ; - b = TEST2 ( a ) ; - show ( a, b ); -} diff --git a/src/CBot/tests/scenarios/BUG2.txt b/src/CBot/tests/scenarios/BUG2.txt deleted file mode 100644 index 44de05a..0000000 --- a/src/CBot/tests/scenarios/BUG2.txt +++ /dev/null @@ -1,107 +0,0 @@ -object object :: TT ( int n ) -{ - object XX = radar(); - if ( n == 0 ) return null; - - while ( null == XX ) XX = radar(); - return XX; -} - -extern void object::Attack( ) -{ - show ( TT ( 0 ) ) ; - show ( TT ( 1 ) ) ; - return; - - int list[]; - int i; - object p; - float dist, prox; - point dest; - boolean advance = true; - - TEST(0); // ne stoppe pas si erreur -// while ( F () != 0 ) F(1); - - i = 0; - list[i++] = WingedGrabber; - list[i++] = TrackedGrabber; - list[i++] = WheeledGrabber; - list[i++] = LeggedGrabber; - list[i++] = WingedShooter; - list[i++] = TrackedShooter; - list[i++] = WheeledShooter; - list[i++] = LeggedShooter; - list[i++] = WingedOrgaShooter; - list[i++] = TrackedOrgaShooter; - list[i++] = WheeledOrgaShooter; - list[i++] = LeggedOrgaShooter; - list[i++] = WingedSniffer; - list[i++] = TrackedSniffer; - list[i++] = WheeledSniffer; - list[i++] = LeggedSniffer; - list[i++] = Thumper; - list[i++] = PhazerShooter; - list[i++] = Recycler; - list[i++] = Shielder; - list[i++] = Subber; - list[i++] = Me; - list[i++] = 3333; - list[i++] = 3334; - list[i++] = 3335; - list[i++] = 3336; - list[i++] = 3337; - list[i++] = 3338; - list[i++] = 3339; - list[i++] = 3331; - list[i++] = 3332; - list[i++] = 3330; - list[i++] = 1111; - list[i++] = 1112; - - F(F(0)); - - while ( true ) - { - p = radar(list, 0, 360, 0, 1000); - if ( p == null ) - { - F(2); - } - else - { - dist = F(p.position, position); - if ( dist <= 40 && !advance ) - { - fire(p.position); - advance = true; - } - else - { -//? if ( RetBaseDistance() > 20 ) - { - prox = dist-(5+F()*5); - if ( prox < 5 ) prox = 5; - dest.x = (position.x-p.position.x)*prox/dist + p.position.x; - dest.y = (position.y-p.position.y)*prox/dist + p.position.y; - dest.z = (position.z-p.position.z)*prox/dist + p.position.z; - goto(dest); - advance = false; - } - } - } - } -} - -// Calcule la distance jusqu'à la base. - -float object::RetBaseDistance() -{ - object p; - float dist; - - p = radar(4444, 0, 360, 0, 1000); - if ( p == null ) return 1000; - dist = F(p.position, position); - return dist; -} \ No newline at end of file diff --git a/src/CBot/tests/scenarios/Deleted.txt b/src/CBot/tests/scenarios/Deleted.txt deleted file mode 100644 index 469a624..0000000 --- a/src/CBot/tests/scenarios/Deleted.txt +++ /dev/null @@ -1,23 +0,0 @@ -public extern void object :: ESSAI() -{ - while(true) - { - if ( true ) - { - goto(12); - break; - } - } - object x = null ; - - while ( x == null ) x = radar(); - - show ( x.position ) ; - - TEST(5, x); - - if ( x == null ) show ( "DELETED" ); - - show ( x.position ) ; - -} \ No newline at end of file diff --git a/src/CBot/tests/scenarios/MaClass.txt b/src/CBot/tests/scenarios/MaClass.txt deleted file mode 100644 index ac472b4..0000000 --- a/src/CBot/tests/scenarios/MaClass.txt +++ /dev/null @@ -1,16 +0,0 @@ - -class MaClass -{ - int a = 1 ; - MaClass pointeur ; - MaClass next = null ; - CPoint autre = new CPoint( 1 , 1 ) ; -} - -extern public void Test ( ) -{ - MaClass x () ; - x.next = new MaClass ( ) ; - println ( x ) ; -} - diff --git a/src/CBot/tests/scenarios/Mc2.txt b/src/CBot/tests/scenarios/Mc2.txt deleted file mode 100644 index 172c259..0000000 --- a/src/CBot/tests/scenarios/Mc2.txt +++ /dev/null @@ -1,4 +0,0 @@ -class MaClass -{ - int t = 12; -} diff --git a/src/CBot/tests/scenarios/Mon fichier.txt b/src/CBot/tests/scenarios/Mon fichier.txt deleted file mode 100644 index 6b35bf8..0000000 --- a/src/CBot/tests/scenarios/Mon fichier.txt +++ /dev/null @@ -1,2 +0,0 @@ -Voici encore du texte -et une seconde ligne diff --git a/src/CBot/tests/scenarios/Nop.txt b/src/CBot/tests/scenarios/Nop.txt deleted file mode 100644 index 6a66f6f..0000000 --- a/src/CBot/tests/scenarios/Nop.txt +++ /dev/null @@ -1,4 +0,0 @@ -public extern void Nop() -{ - while ( true ) {} -} \ No newline at end of file diff --git a/src/CBot/tests/scenarios/POS.txt b/src/CBot/tests/scenarios/POS.txt deleted file mode 100644 index 688e4fb..0000000 --- a/src/CBot/tests/scenarios/POS.txt +++ /dev/null @@ -1,14 +0,0 @@ -void object :: T ( ) -{ - show ( position ) ; -} - -public extern void object :: POS() -{ - for ( int i = 0; i < 10 ; i++ ) - { - if ( i == 2 ) TEST ( 12 ) ; -// show ( position ); - T ( ) ; - } -} \ No newline at end of file diff --git a/src/CBot/tests/scenarios/T.txt b/src/CBot/tests/scenarios/T.txt deleted file mode 100644 index 50a792b..0000000 --- a/src/CBot/tests/scenarios/T.txt +++ /dev/null @@ -1,4 +0,0 @@ -public extern int T ( float n ) -{ - return n * 1.1; -} \ No newline at end of file diff --git a/src/CBot/tests/scenarios/TESTALL.txt b/src/CBot/tests/scenarios/TESTALL.txt deleted file mode 100644 index 82247a0..0000000 --- a/src/CBot/tests/scenarios/TESTALL.txt +++ /dev/null @@ -1,161 +0,0 @@ -int T ( int z ) -{ - return 45 + z ; -} - -class toto -{ - int val = 3 ; - int x = 3 * 3 ; - void toto( int n ) - { val = n + 3 ; } - int retval ( int param ) - { int r = val + param + x ; - val = param ; - return r ; } -} - -public extern void object :: Chose( ) -{ - int z [ 6 ]; - for ( int i = 0 ; i < 6 ; ) z [ i++ ] = 3 - i ; - show ( z ) ; - return; - - // test des tableaux - int [ ] a [ 3 ] ; -// a = null; - if ( a == null ) show ( "NULL" ); - - a [ 2 / 2 ] [ 2 ]= 5 ; - int [ ] b ; b = a [1] ; - b [ 0 ] = -4; - a [ 4 / 2 ] [ 1 ]= 1 ; - show ( a , b ) ; - return ; - { - toto chose = new toto (5 ) ; - toto truc = chose ; - show ( chose, chose.retval( 100 ) , - truc, truc.retval (40 ) ) ; - - return; - } - { - point A = new - point ( 4 * 4 , 2 ) ; - show ( A ) ; - return; - } - { - show ( T ( 1 ) , T ( 3.7 ) ) ; - return; - } - - { - point A ( 3, 4 ) , - B = A ; - - int n = -4; - show ( n ); - - show ( A, B ) ; - - boolean a = false; - boolean b = a or true; - if ( not a and b ) ; - return; - } - { - // test try - float x = nan ; int z = 0 ; - try { -// throw ( 3 * 4 + 33 ) ; - int zz ; goto ( 12 ) ; z = 1 ; z = 0 / 0 ; z = 2 ; - } - catch ( 45 + 0 * 6000 ) - { - show( "Exception 6000", z ) ; - } - catch ( x == 0 ) { show( "x nul" ) ; } - finally { show ( "fini" ) ; } - show ( "continue" ); - return; - } - { - // test des if - int a = 3; - if ( a == 3 ) show ( "33"); - else show ( "44"); - if ( a != 3 ) show ( "333"); - else show ( "444"); - return; - } - { - int a = 0; - // test break -un: - while ( true ) - { -deux: - while ( true ) - { - a++; - if ( a == 2 ) continue; - if ( a == 3 ) break deux; - show ( a ) ; - if ( a == 5 ) break un; - } - show ( "DEUX" ); - } - return; - } - { - // test switch - int a = 0; - - switch ( a ) - { - case 1 : show( "un" ) ; break; - case 2 : show( "deux" ) ; // break; - case 3 : show( "trois" ) ; break; - case 4 : show( "quatre" ) ; // break; - default : show( "par défaut" ) ; - } - return; - } - { - // test boucle while - float z = 3.3; - while ( z > 0 ) - { show ( z-- ) ; } - return; - } - - { - // test boucle do - float y = 3.3; - do { int x = 0; show(y); y++; } while ( y < 7 ) ; - return; - } - // test boucle for - int j = -7; show ( j ); - for ( int ii = 3, j = 31; ii < 6 ; ++ii, j = j -3 ) - { - j = 10 * j; - show ( ii, j ); - } - return; -{ - // déclarations de variables - int a; int b = 3; int c = 4*b, d = 1, e; - float x; float y = 3.3; float z = y / 2, u = 1, v; - boolean t; boolean tt = true or false; boolean ttt = false, tttt = true, t5; - string s; string ss = "hello"; string s2 = ss + " plus", s3 = "s3", s4; - - show( b, c, d ); - show( y, z, u ); - show( tt, ttt, tttt ); - show( ss, s2, s3 ); -} -} \ No newline at end of file diff --git a/src/CBot/tests/scenarios/TestCB1.txt b/src/CBot/tests/scenarios/TestCB1.txt deleted file mode 100644 index 516db47..0000000 --- a/src/CBot/tests/scenarios/TestCB1.txt +++ /dev/null @@ -1,18 +0,0 @@ -extern public void toto() -{ - print( "hello" ) ; - print( fac(5) ); - print( t() ) ; -} - -public int fac(int n) -{ - if ( n<2 ) return 1; - return n * fac(n-1); -} - -point t() -{ - point a(1,2); - return a; -} diff --git a/src/CBot/tests/scenarios/TestCBot1.txt b/src/CBot/tests/scenarios/TestCBot1.txt deleted file mode 100644 index d27b4f8..0000000 --- a/src/CBot/tests/scenarios/TestCBot1.txt +++ /dev/null @@ -1,27 +0,0 @@ - -class CPoint2 -{ - float x, y; - void CPoint2(float x, float y) - { - this.x = x; - this.y = y; - } -} - -public extern void T ( ) -{ - CPoint2 X( 12, 33 ), Y ( -4, 4/3 ); - print ( X, Y ) ; -} - -public extern void Hello ( ) - -{ - println ( "Hello" ); -} - -public extern void test ( int n ) -{ - for ( int i = n; i>0 ; i--) print (i); -} \ No newline at end of file diff --git a/src/CBot/tests/scenarios/TestCBot3.txt b/src/CBot/tests/scenarios/TestCBot3.txt deleted file mode 100644 index b915f96..0000000 --- a/src/CBot/tests/scenarios/TestCBot3.txt +++ /dev/null @@ -1,24 +0,0 @@ -public extern void Test () -{ - for ( int x = 100000; x>0 ; x-- ) { } -} - -float MaRoutine( CPoint A, CPoint B ) -{ - A.x -= B.x ; // distance en x - A.y -= B.y ; // distance en y - A.x *= A.x; // carré de la distance - A.y += A.y; // carré de la distance - println ( A, B ) ; - return ( A.x + A.y ) ; -} - -public extern void TestAB ( ) -{ - CPoint A(3, 5) ; - CPoint B(4, -2); - println ( A, B ) ; - MaRoutine( A, B ) ; - println ( A, B ) ; -} - diff --git a/src/CBot/tests/scenarios/TestNull.txt b/src/CBot/tests/scenarios/TestNull.txt deleted file mode 100644 index f447245..0000000 --- a/src/CBot/tests/scenarios/TestNull.txt +++ /dev/null @@ -1,15 +0,0 @@ -extern public void TestNull () -{ - CPoint pointeur = null; - - try { - pointeur.x = 4; } - catch ( 6007 ) {} - - pointeur = new CPoint(1,2); - - print ( pointeur.x, pointeur.y, - pointeur ); - - pointeur.x = 5; -} \ No newline at end of file diff --git a/src/CBot/tests/scenarios/TestRestoreState.txt b/src/CBot/tests/scenarios/TestRestoreState.txt deleted file mode 100644 index 1e49e37..0000000 --- a/src/CBot/tests/scenarios/TestRestoreState.txt +++ /dev/null @@ -1,67 +0,0 @@ -// routine de Daniel qui plante après RestoreState - -extern void object::Attack( ) -{ - int list[], i; - object p; - float dist, prox; - point nav1, nav2, dest; - boolean advance = true; - - i = 0; - list[i++] = WingedGrabber; - list[i++] = TrackedGrabber; - list[i++] = WheeledGrabber; - list[i++] = LeggedGrabber; - list[i++] = WingedShooter; - list[i++] = TrackedShooter; - list[i++] = WheeledShooter; - list[i++] = LeggedShooter; - list[i++] = WingedOrgaShooter; - list[i++] = TrackedOrgaShooter; - list[i++] = WheeledOrgaShooter; - list[i++] = LeggedOrgaShooter; - list[i++] = WingedSniffer; - list[i++] = TrackedSniffer; - list[i++] = WheeledSniffer; - list[i++] = LeggedSniffer; - list[i++] = Thumper; - list[i++] = PhazerShooter; - list[i++] = Recycler; - list[i++] = Shielder; - list[i++] = Subber; - list[i++] = Me; - - nav1.x = 1;//cmdline(0); - nav1.y = 1;//cmdline(1); - nav2.x = 2;//cmdline(2); - nav2.y = 2;//cmdline(3); - - while ( true ) - { - while ( true ) - { - // ennemi à proximité ? - p = radar(list, 0, 360, 0, 40); - if ( p == null ) break; - // lui tire dessus - fire(p.position); - } - - // se promène vers le point A - goto(nav1); - - while ( true ) - { - // ennemi à proximité ? - p = radar(list, 0, 360, 0, 40); - if ( p == null ) break; - // lui tire dessus - fire(p.position); - } - - // se promène vers le point B - goto(nav2); - } -} - diff --git a/src/CBot/tests/scenarios/TestStatic.txt b/src/CBot/tests/scenarios/TestStatic.txt deleted file mode 100644 index f501aa5..0000000 --- a/src/CBot/tests/scenarios/TestStatic.txt +++ /dev/null @@ -1,31 +0,0 @@ -class ESSAI -{ - int x = 0; - static int nb = 3; - static int [ ] array ; - - void Put( int val) - { -show(nb); - array[ nb ] = val; -// this.nb++; - this.nb = this.nb + 1; -show(nb, array); - } - int Get( ) - { - nb--; -show("out", nb, array); - return array[ nb ] ; - } -} - -extern public void T() -{ - ESSAI t1 ( ) ; - ESSAI t2 ( ) ; - t1.nb++; - t1.Put( 11 ); t1.Put( 12 ); t2.Put( 13 ); - - show ( t1.Get(), t2.Get(), t2.Get() ) ; -} \ No newline at end of file diff --git a/src/CBot/tests/scenarios/TestStr.txt b/src/CBot/tests/scenarios/TestStr.txt deleted file mode 100644 index 683ec1b..0000000 --- a/src/CBot/tests/scenarios/TestStr.txt +++ /dev/null @@ -1,17 +0,0 @@ -extern public void TSTR() -{ - string s = "C'est un essai"; - - print ( s, strlen(s), strleft(s, 3), strright(s,3), strmid(s, 2), strmid(s,2,3), strfind(s, "un"), strfind(s, "sdgfld") ); - - show ( strupper(s), strlower(s) ); - - s = "123.45" ; - print ( strval(s) ); - - - string sub = strright("abcdef", 2); // sub vaut "ef###", # étant un caractère bizarre quelconque - show (sub); - int pos = strfind("abcdef", "xy"); // pos vaut -1. Pourquoi pas nan ? - show(pos); -} diff --git a/src/CBot/tests/scenarios/Z.txt b/src/CBot/tests/scenarios/Z.txt deleted file mode 100644 index 714119b..0000000 --- a/src/CBot/tests/scenarios/Z.txt +++ /dev/null @@ -1,14 +0,0 @@ -public extern void tp() -{ - int a [4], b[]; - a [ 0 ] = 8 ; - - b = T ( a ) ; - show ( a, b ); -} - -int[] T ( int[] Z ) -{ - for ( int i = 0; i < 4 ; i++ ) Z[ i ] = i * i ; - return Z; -} \ No newline at end of file diff --git a/src/CBot/tests/scenarios/a1.txt b/src/CBot/tests/scenarios/a1.txt deleted file mode 100644 index 165bc95..0000000 --- a/src/CBot/tests/scenarios/a1.txt +++ /dev/null @@ -1,96 +0,0 @@ -object radarGuepe(point orig, float dist) -{ - int i; - object pr, r; - float mindist; - - i = 0; - mindist = 1000; - while (i<30) - { - pr = radar(i); - if (pr != null) - { - - if (F(orig, pr.position) < mindist and pr.category == AlienWasp and pr.altitude > 3) - { - mindist = distance(orig, pr.position); - r = pr; - } - } - i = i+1; - } - if (mindist < dist) return(r); else return(null); -} - - -class Guepe -{ - - point pos; - - - void cherche(point orig, float dist) - { - object p; - point o; - - p = radarGuepe(orig, dist); - while (p == null) - { - wait(0.1); - p = radarGuepe(orig, dist); - } - - pos.x = p.position.x; - pos.y = p.position.y; - pos.z = p.position.z; - - //o = p.position; - //wait(0.1); - - //vitessex = (p.position.x - o.x)/0.1; - //vitessey = (p.position.y - o.y)/0.1; - //vitessez = (p.position.z - o.z)/0.1; - - } - - - void tire(point orig, float orient) - { - //float t = 3; //temps d'anticipation - float angle; - point cible; - - cible.x = pos.x;// + t*vitessex; - cible.y = pos.y;// + t*vitessey; - cible.z = pos.z;// + t*vitessez; - - if (cible.x == 0) angle = 90; else - angle = atan(cible.y / cible.x); - if (cible.x < 0) angle = angle + 180; - angle = angle - orient; - if (angle > 180) angle = angle - 360; - if (angle < -180) angle = angle + 360; - turn(angle); - - angle = atan((cible.z-orig.z) / distance2d(orig, cible)); - aim(angle); - - fire(0.1); - - } -} - -extern void object::Fourmi6() -{ - //fps(1000); - Guepe guepe = new Guepe(); - - while (true) - { - guepe.cherche(position, 50); - - guepe.tire(position, orientation); - } -} diff --git a/src/CBot/tests/scenarios/array.txt b/src/CBot/tests/scenarios/array.txt deleted file mode 100644 index 081b60e..0000000 --- a/src/CBot/tests/scenarios/array.txt +++ /dev/null @@ -1,24 +0,0 @@ - -public extern void TestTableau () -{ - int tableau [ 12 ] ; - - point array[ 12 ] [ 14 ] ; - - point zéro ( 1, 2 ) ; - point a = zéro ; - - for ( int i = 0 ; i < 10 ; i++ ) array[ i ] [ i ]= zéro ; - - array[ 5 ] [3 ] . x =1.5 ; - - array[ 2 ] [ 2 ] . y = array[ 5 ] [ 5 ] . x ; - - array[ 4 ] = array [ 2 ] ; - - for ( int i = 0 ; i < 10 ; i++ ) for ( int j = 0 ; j < 4 ; j++ ) println ( i, j, array [ i ] [ j ] ) ; - - show( zéro, a, array ); - -} - diff --git "a/src/CBot/tests/scenarios/a\2361.txt" "b/src/CBot/tests/scenarios/a\2361.txt" deleted file mode 100644 index 165bc95..0000000 --- "a/src/CBot/tests/scenarios/a\2361.txt" +++ /dev/null @@ -1,96 +0,0 @@ -object radarGuepe(point orig, float dist) -{ - int i; - object pr, r; - float mindist; - - i = 0; - mindist = 1000; - while (i<30) - { - pr = radar(i); - if (pr != null) - { - - if (F(orig, pr.position) < mindist and pr.category == AlienWasp and pr.altitude > 3) - { - mindist = distance(orig, pr.position); - r = pr; - } - } - i = i+1; - } - if (mindist < dist) return(r); else return(null); -} - - -class Guepe -{ - - point pos; - - - void cherche(point orig, float dist) - { - object p; - point o; - - p = radarGuepe(orig, dist); - while (p == null) - { - wait(0.1); - p = radarGuepe(orig, dist); - } - - pos.x = p.position.x; - pos.y = p.position.y; - pos.z = p.position.z; - - //o = p.position; - //wait(0.1); - - //vitessex = (p.position.x - o.x)/0.1; - //vitessey = (p.position.y - o.y)/0.1; - //vitessez = (p.position.z - o.z)/0.1; - - } - - - void tire(point orig, float orient) - { - //float t = 3; //temps d'anticipation - float angle; - point cible; - - cible.x = pos.x;// + t*vitessex; - cible.y = pos.y;// + t*vitessey; - cible.z = pos.z;// + t*vitessez; - - if (cible.x == 0) angle = 90; else - angle = atan(cible.y / cible.x); - if (cible.x < 0) angle = angle + 180; - angle = angle - orient; - if (angle > 180) angle = angle - 360; - if (angle < -180) angle = angle + 360; - turn(angle); - - angle = atan((cible.z-orig.z) / distance2d(orig, cible)); - aim(angle); - - fire(0.1); - - } -} - -extern void object::Fourmi6() -{ - //fps(1000); - Guepe guepe = new Guepe(); - - while (true) - { - guepe.cherche(position, 50); - - guepe.tire(position, orientation); - } -} diff --git "a/src/CBot/tests/scenarios/a\2471.txt" "b/src/CBot/tests/scenarios/a\2471.txt" deleted file mode 100644 index 0c57950..0000000 --- "a/src/CBot/tests/scenarios/a\2471.txt" +++ /dev/null @@ -1,96 +0,0 @@ -object radarGuepe(point orig, float dist) -{ - int i; - object pr, r; - float mindist; - - i = 0; - mindist = 1000; - while (i<30) - { - pr = radar(i); - if (pr != null) - { - - if (F(orig, pr.position) < mindist and pr.category == AlienWasp and pr.altitude > 3) - { - mindist = distance(orig, pr.position); - r = pr; - } - } - i = i+1; - } - if (mindist < dist) return(r); else return(null); -} - - -class Guepe -{ - - point pos; - - - void cherche(point orig, float dist) - { - object p; - point o; - - p = radarGuepe(orig, dist); - while (p == null) - { - wait(0.1); - p = radarGuepe(orig, dist); - } - - pos.x = p.position.x; - pos.y = p.position.y; - pos.z = p.position.z; - - //o = p.position; - //wait(0.1); - - //vitessex = (p.position.x - o.x)/0.1; - //vitessey = (p.position.y - o.y)/0.1; - //vitessez = (p.position.z - o.z)/0.1; - - } - - - void tire(point orig, float orient) - { - //float t = 3; //temps d'anticipation - float angle; - point cible; - - cible.x = pos.x;// + t*vitessex; - cible.y = pos.y;// + t*vitessey; - cible.z = pos.z;// + t*vitessez; - - if (cible.x == 0) angle = 90; else - angle = atan(cible.y / cible.x); - if (cible.x < 0) angle = angle + 180; - angle = angle - orient; - if (angle > 180) angle = angle - 360; - if (angle < -180) angle = angle + 360; - turn(angle); - - angle = atan((cible.z-orig.z) / distance2d(orig, cible)); - aim(angle); - - fire(0.1); - - } -} - -extern void object::Fourmi6() -{ - //fps(1000); - Guepe guepe = new Guepe(); - - while (true) - { - guepe.cherche(position, 50); - - guepe.tire(position, orientation); - } -} diff --git a/src/CBot/tests/scenarios/bug.txt b/src/CBot/tests/scenarios/bug.txt deleted file mode 100644 index 4ec6eb3..0000000 --- a/src/CBot/tests/scenarios/bug.txt +++ /dev/null @@ -1,12 +0,0 @@ -public extern void object::Bug() -{ - point a; - a = position; - TEST(); - float d=dist(a, position); -} - -float dist(point a, point b) -{ - return a.x-b.x; -} diff --git a/src/CBot/tests/scenarios/bugmw.txt b/src/CBot/tests/scenarios/bugmw.txt deleted file mode 100644 index 284ee43..0000000 --- a/src/CBot/tests/scenarios/bugmw.txt +++ /dev/null @@ -1,9 +0,0 @@ -extern public void main() -{ - show(fact(30)) ; -} - -public int fact(int n) -{ - return (fact(n-1)*n) ; -} diff --git a/src/CBot/tests/scenarios/ccc.txt b/src/CBot/tests/scenarios/ccc.txt deleted file mode 100644 index dbcd1d5..0000000 --- a/src/CBot/tests/scenarios/ccc.txt +++ /dev/null @@ -1,8 +0,0 @@ -public extern void ccc() -{ - int a; - a = 0 ; - - if ( a == 0 ); - -} \ No newline at end of file diff --git a/src/CBot/tests/scenarios/enum.txt b/src/CBot/tests/scenarios/enum.txt deleted file mode 100644 index a592a7f..0000000 --- a/src/CBot/tests/scenarios/enum.txt +++ /dev/null @@ -1,9 +0,0 @@ - -enum JourDeLaSemaine { - lundi = 1, - mardi, - mercredi, - jeudi, - vendredi, - samedi, - dimanche = 0 } \ No newline at end of file diff --git a/src/CBot/tests/scenarios/fibo.txt b/src/CBot/tests/scenarios/fibo.txt deleted file mode 100644 index 88f5357..0000000 --- a/src/CBot/tests/scenarios/fibo.txt +++ /dev/null @@ -1,25 +0,0 @@ - -extern public int Fibo( int n, boolean b ) -{ - if ( n < 2 ) return n; - int a = Fibo(n-1, b) + Fibo(n-2, false); - if ( b ) print (n + "=" + a); - return a; -} - -extern public void t() -{ - Fibo( 23, true); -} - -extern public void tt() -{ - t(); -} - -// cette routine n'est évidemment pas du tout obtimisée -// c'est même un très mauvais exemple de programmation récursive - -// pour un test de durée, Fibo(23, true) prend -// en mode Debug 67 secondes -// en mode Release 8 secondes diff --git a/src/CBot/tests/scenarios/file.txt b/src/CBot/tests/scenarios/file.txt deleted file mode 100644 index 2a22dd9..0000000 --- a/src/CBot/tests/scenarios/file.txt +++ /dev/null @@ -1,70 +0,0 @@ -class CLASS22 -{ - static int nb = 2; - void T22 ( ) { nb = nb / 0 ; } -} - -public extern void object :: TEST() -{ - switch ( 1 ) - { - case 1: - { - file h(); - h.open("Mon Fichier.txt", "r"); -show ( h.filename, h.handle ); -h.filename = "xx"; -h.handle = 1 ; - h.readln(); - h.close(); - } - case 2: - { - file h("Mon Fichier.txt"); - h.open("r"); - h.readln(); - h.close(); - } - case 3: - { - file h("Mon Fichier.txt", "r"); - h.readln(); - h.close(); - } - case 4: - { - file h(); - h.filename = "Mon Fichier.txt"; - h.open("r"); - h.readln(); - h.close(); - } - case 5: - { - file h = fileopen( "Mon 2Fichier.txt", "r" ); - h.readln(); - h.close(); - } - } -{ - file h( ) ; - h.filename = "Test.h"; - h.open ( "r" ); - - - file pf ( "Mon Fichier.txt" ) ; - pf . open ( "w" ) ; - pf . writeln ( "Voici encore du texte" ) ; - pf . writeln ( "et une seconde ligne" ) ; - pf . close( ); - - pf . open ( "r" ) ; - - while ( not pf . eof( ) ) - { - string s = pf . readln ( ); - show ( s ); - } - pf.close( ); -} -} diff --git a/src/CBot/tests/scenarios/h.txt b/src/CBot/tests/scenarios/h.txt deleted file mode 100644 index c395319..0000000 --- a/src/CBot/tests/scenarios/h.txt +++ /dev/null @@ -1,5 +0,0 @@ -void tf() -{ - file h; - h.handle += 1 ; -} \ No newline at end of file diff --git a/src/CBot/tests/scenarios/include.txt b/src/CBot/tests/scenarios/include.txt deleted file mode 100644 index e8f8cc9..0000000 --- a/src/CBot/tests/scenarios/include.txt +++ /dev/null @@ -1,27 +0,0 @@ -class Z -{ - static int x = 0; - private int y; - - void T( ) - { - // autorisé ici - y = x ; - this.y = this.x ; - x = y ; - this.x = this.y ; - } -} - -extern public void test() -{ - Z a(); - 3 * a.x; // autorisé -//vu 3 * a.y; // interdit -//vu a.y = 3; // interdit ici - a.x = 1; // autorisé - - show ( a ); - a.T(); - show ( a ); -} diff --git a/src/CBot/tests/scenarios/intrinsic.txt b/src/CBot/tests/scenarios/intrinsic.txt deleted file mode 100644 index f215791..0000000 --- a/src/CBot/tests/scenarios/intrinsic.txt +++ /dev/null @@ -1,16 +0,0 @@ -public extern void TestIntrinsic() -{ - point a ( 1, 2 ); - print (a); - - a.x = 3; - a.y = 4; - - point b = a; - - println ( b.x, b.y, b ) ; - if ( b == a ) b.y = 0; - println (a,b); - if ( b != a ) b.y = a.y; - println(a,b); -} \ No newline at end of file diff --git a/src/CBot/tests/scenarios/methode1.txt b/src/CBot/tests/scenarios/methode1.txt deleted file mode 100644 index 080bba2..0000000 --- a/src/CBot/tests/scenarios/methode1.txt +++ /dev/null @@ -1,57 +0,0 @@ -class t { - point p; -} - -void object :: toto() -{ - show ( Position ) ; -} - -extern public void object :: XX() -{ - int test []; - test [ 9999 ] = 3; - - toto () ; -/* - Radar(); - - object test ; - test = this. Radar(); - - do { - test = this.Radar(); - } while ( test == null ); - -/* - t test [ 4 ]; - for ( int i = 0 ; i < 4 ; i++ ) test [ i ] = new t(); - test [ 3 ] .p.x = 2; - show ( test ); -/* - int a = nan; - show ( a ) ; - - a = TypeMarkPath; - show ( a, a++, --a ) ; - - if ( a != nan ) a += 1 ; - - a = TypeMarkPath; - float q = a ; - show ( a, q ) ; - -return; - - a += ++a; - show ( a ) ; - - boolean i = false; - - if ( i == true ) {} - - object p; - if ( p == null) { p = p ; } -*/ -} - diff --git a/src/CBot/tests/scenarios/methode2.txt b/src/CBot/tests/scenarios/methode2.txt deleted file mode 100644 index 76ce7f4..0000000 --- a/src/CBot/tests/scenarios/methode2.txt +++ /dev/null @@ -1,50 +0,0 @@ - -extern void Toto() -{ - TEST(12); - - for ( int i = 0 ; i<1000; i++) - { - int j = 1; - if (i==55) TEST(12); - } - - TEST(2); - - -// Nouveau(); - int toto[4]; - point Z[3]; - - Z[1].x = 11; Z[1].y = 12; - - toto[2] = 12; - toto[1] = nan; - -// point test, autre(2,3) ; -// object titi = Radar(); - - TEST ( 1 ) ; - - toto[0] = 11; - - TEST ( 2 ) ; - - toto[6] = 0; -} - -extern void object::Nouveau() -{ - point a; - a = np(Position); -} - -point np(point b) -{ - point c; - c.x = b.y; - c.y = b.x; - return c ; -} - - diff --git a/src/CBot/tests/scenarios/mp1.txt b/src/CBot/tests/scenarios/mp1.txt deleted file mode 100644 index 599cfc4..0000000 --- a/src/CBot/tests/scenarios/mp1.txt +++ /dev/null @@ -1,25 +0,0 @@ -class Guepet -{ - - float a; - float b; - - void init() - { - a = 12.34; - b = 56.78; - } - - -} - -extern void object::Fourmi6() -{ - Guepet guepe =new Guepet(); - - guepe.init(); - - - show("test "+guepe.a+" "+guepe.b); - -} diff --git a/src/CBot/tests/scenarios/mp2.txt b/src/CBot/tests/scenarios/mp2.txt deleted file mode 100644 index 1c2972c..0000000 --- a/src/CBot/tests/scenarios/mp2.txt +++ /dev/null @@ -1,28 +0,0 @@ -class Guepet -{ - - float a; - float b; - - void init() - { - a = 12.34; - b = 56.78; - - object x = radar(123); - show("radar "+x.position.x); - show("C'est fait"); - } - - -} - -extern void object::Fourmi6() -{ - Guepet guepe=new Guepet(); - - guepe.init(); - - show("test "+guepe.a+" "+guepe.b); - -} diff --git a/src/CBot/tests/scenarios/mw.txt b/src/CBot/tests/scenarios/mw.txt deleted file mode 100644 index c237670..0000000 --- a/src/CBot/tests/scenarios/mw.txt +++ /dev/null @@ -1,16 +0,0 @@ -extern public void main() -{ -// goto( 3, 4 ); - - while( true ) - { - try { goto (12) ; } - catch( FF( ) ) - { show( "ko"); } - } -} - -boolean FF() -{ - return false; -} diff --git a/src/CBot/tests/scenarios/null.txt b/src/CBot/tests/scenarios/null.txt deleted file mode 100644 index ae76b74..0000000 --- a/src/CBot/tests/scenarios/null.txt +++ /dev/null @@ -1,5 +0,0 @@ -extern public void xxx () -{ - CPoint test = null ; - if ( test == null ) show ( "NULL" ); -} \ No newline at end of file diff --git a/src/CBot/tests/scenarios/opnew.txt b/src/CBot/tests/scenarios/opnew.txt deleted file mode 100644 index 7d6838c..0000000 --- a/src/CBot/tests/scenarios/opnew.txt +++ /dev/null @@ -1,20 +0,0 @@ -extern public void xx () -{ - CPoint pointeur, test = null ; - pointeur = new CPoint ( 3, 4 ); - - if ( test == null ) show ( "NULL" ); - - CPoint pp = pointeur; - -show( pointeur , pp ); - - pp.x = 33.3; - if ( pointeur.x != pp.x ) 0/0; - - pp = new CPoint(); -// pointeur = pp; - -show( pointeur , pp ); - -} \ No newline at end of file diff --git a/src/CBot/tests/scenarios/plante.txt b/src/CBot/tests/scenarios/plante.txt deleted file mode 100644 index 363461b..0000000 --- a/src/CBot/tests/scenarios/plante.txt +++ /dev/null @@ -1,25 +0,0 @@ -class Guepet -{ - - point pos; - float t = 0.1; - - void init() - { - pos.x = 12.123; - pos.y = 34.345; - - F(t); - } - - -} - -extern void object::Fourmi6() -{ - Guepet guepe=new Guepet(); - - guepe.init(); - - show ( guepe ); -} diff --git a/src/CBot/tests/scenarios/pointer.txt b/src/CBot/tests/scenarios/pointer.txt deleted file mode 100644 index 2d4d907..0000000 --- a/src/CBot/tests/scenarios/pointer.txt +++ /dev/null @@ -1,41 +0,0 @@ -extern public void x () -{ - show ( 3 ** 4 ); - float z = 1e-3; - show ( z ); - - CPoint b ( 4,5 ); - show ( b ); - - CPoint a ( ) ; - a.x = 21; a.y = 12; - show ( a ) ; - - CPoint test = new CPoint ( 1,1 ); - test = new CPoint ( 2, 2 ); - show ( test ); -} - -// crée un objet et retourne son pointeur -CPoint newcpoint() -{ - CPoint p = new CPoint ( 3, 3 ); - return p; -} - -extern public void y () -{ - CPoint test = newcpoint(); - println ( test ); - dontmodif( test ); - println ( test ); -} - -// ne doit pas modifier l'objet en paramètre -void dontmodif ( CPoint pp ) -{ - pp.x = 5; - pp.y = 2; - println ( pp, pp.x, pp.y ); -} - diff --git a/src/CBot/tests/scenarios/postinc.txt b/src/CBot/tests/scenarios/postinc.txt deleted file mode 100644 index cdf6ab5..0000000 --- a/src/CBot/tests/scenarios/postinc.txt +++ /dev/null @@ -1,7 +0,0 @@ -extern public void X() -{ - point A [ ] ; - A[5] = new point (2,3); - int val = A[5].x++ + --A[5].y; - show ( A, val ); -} diff --git a/src/CBot/tests/scenarios/radar.txt b/src/CBot/tests/scenarios/radar.txt deleted file mode 100644 index 09d84a2..0000000 --- a/src/CBot/tests/scenarios/radar.txt +++ /dev/null @@ -1,39 +0,0 @@ -extern void object::Bug( ) -{ - try{ int a = 44 ; a = 12 / 0 ; } - catch(6000) { int b = 4 ; } - finally { int z = 1 ; } - -// tp ( A, B ); - -/* int a = 4, b = 2, c = nan; - float x, y = 3/2, z = nan; - boolean i, j = false, k = true; - - string s, ss = "xyz"; - - while ( false ) - { - object left, right; - - left = Radar(TypeMarkPath, -45, 120, 100); - right = Radar(TypeMarkPath, 45, 120, 100); - - if ( left == null && right == null ) - { - } - } - int t = fact ( 4 ) ;*/ -} - -void tp( point a , point b ) -{ - a.x += b.x; -} - - -int fact( int n ) -{ - if ( n < 2 ) return n; - return n * fact ( n - 1 ) ; -} \ No newline at end of file diff --git a/src/CBot/tests/scenarios/solution.txt b/src/CBot/tests/scenarios/solution.txt deleted file mode 100644 index f78cf12..0000000 --- a/src/CBot/tests/scenarios/solution.txt +++ /dev/null @@ -1,13 +0,0 @@ -extern void object::Solution( ) -{ -show ( "Solution " + Position ); - Carré(15); - Carré(25); -} - -void object::Carré(float côté) -{ -show ( "Carré " + Position ); - Move(côté); - Turn(-90); -} \ No newline at end of file diff --git a/src/CBot/tests/scenarios/test.txt b/src/CBot/tests/scenarios/test.txt deleted file mode 100644 index 0693994..0000000 --- a/src/CBot/tests/scenarios/test.txt +++ /dev/null @@ -1,8 +0,0 @@ -extern public void x() -{ - float a= 1, b = 2; - a = b * ( 2 + 2 ); - print (a); - a += 4; - print (a); -} diff --git a/src/CBot/tests/scenarios/test23.txt b/src/CBot/tests/scenarios/test23.txt deleted file mode 100644 index d6e1ddd..0000000 --- a/src/CBot/tests/scenarios/test23.txt +++ /dev/null @@ -1,10 +0,0 @@ -extern public void object::TEST23() -{ - CLASS22 T; - T.T22( ) ; - - show( position ); - show( this.position ); - -// T22(); -} \ No newline at end of file diff --git a/src/CBot/tests/scenarios/testmw.txt b/src/CBot/tests/scenarios/testmw.txt deleted file mode 100644 index 6570f6d..0000000 --- a/src/CBot/tests/scenarios/testmw.txt +++ /dev/null @@ -1,14 +0,0 @@ -extern public int testmw( int a) -{ - boolean b = true ; - - if (b) - return 1 ; - else - return a ; 0 * testmw(a-1) ; -} - -public int Fibo2 ( int n ) -{ - print ( " bof " ); -} \ No newline at end of file diff --git a/src/CBot/tests/scenarios/this.txt b/src/CBot/tests/scenarios/this.txt deleted file mode 100644 index b8a9e04..0000000 --- a/src/CBot/tests/scenarios/this.txt +++ /dev/null @@ -1,13 +0,0 @@ -extern void object :: TEST22 ( ) -{ - show( position ); - show( this.position ); - - T(); -} - -public void object :: T22() -{ - show( position ); - show( this.position ); -} \ No newline at end of file diff --git a/src/CBot/tests/scenarios/tt.txt b/src/CBot/tests/scenarios/tt.txt deleted file mode 100644 index cd13c9d..0000000 --- a/src/CBot/tests/scenarios/tt.txt +++ /dev/null @@ -1,12 +0,0 @@ -extern public void T() { T1(); } - -public void T1() -{ - show( "T1" ); - T2(); -} - -public void T2() -{ - show( "T2" ); -} \ No newline at end of file diff --git a/src/CBot/tests/scenarios/tt2.txt b/src/CBot/tests/scenarios/tt2.txt deleted file mode 100644 index ad9dc1d..0000000 --- a/src/CBot/tests/scenarios/tt2.txt +++ /dev/null @@ -1,5 +0,0 @@ -extern public void TT() -{ - T1(); - T2(); -} \ No newline at end of file diff --git a/src/CBot/tests/scenarios/vide.txt b/src/CBot/tests/scenarios/vide.txt deleted file mode 100644 index e69de29..0000000 diff --git a/src/CBot/tests/scenarios/zz.txt b/src/CBot/tests/scenarios/zz.txt deleted file mode 100644 index da764ac..0000000 --- a/src/CBot/tests/scenarios/zz.txt +++ /dev/null @@ -1,6 +0,0 @@ -extern public void zz() -{ - MaClass TOTO (); - - show (TOTO); -} \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 238b8ba..e6b3acd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -14,14 +14,6 @@ add_subdirectory(po) add_subdirectory(desktop) -# Tests -if(${TESTS}) - add_subdirectory(common/test) - add_subdirectory(graphics/engine/test) - add_subdirectory(ui/test) - add_subdirectory(math/test) -endif() - # Optional libraries set(OPTIONAL_LIBS "") diff --git a/src/common/test/CMakeLists.txt b/src/common/test/CMakeLists.txt deleted file mode 100644 index 70dac1f..0000000 --- a/src/common/test/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -cmake_minimum_required(VERSION 2.8) - -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE debug) -endif(NOT CMAKE_BUILD_TYPE) -set(CMAKE_CXX_FLAGS_DEBUG "-g -O0") - -include_directories( -. -../.. -../../.. -${GTEST_INCLUDE_DIR} -) - - -add_executable(image_test ../image.cpp image_test.cpp) -target_link_libraries(image_test ${SDL_LIBRARY} ${SDLIMAGE_LIBRARY} ${PNG_LIBRARIES}) - -#add_executable(profile_test ../profile.cpp ../logger.cpp profile_test.cpp) -#target_link_libraries(profile_test gtest ${Boost_LIBRARIES}) - -#add_test(profile_test ./profile_test) diff --git a/src/common/test/colobot.ini b/src/common/test/colobot.ini deleted file mode 100644 index 2ca37ee..0000000 --- a/src/common/test/colobot.ini +++ /dev/null @@ -1,15 +0,0 @@ -[test_float] -float_value=1.5 - -[test_string] -string_value=Hello world - -[test_int] -int_value=42 - -[test_multi] -entry1=1 -entry2=2 -entry3=3 -entry4=4 -entry5=5 diff --git a/src/common/test/image_test.cpp b/src/common/test/image_test.cpp deleted file mode 100644 index 09ae4c6..0000000 --- a/src/common/test/image_test.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include "../image.h" - -#include -#include - -/* For now, just a simple test: loading a file from image - * and saving it to another in PNG. */ - -int main(int argc, char *argv[]) -{ - if (argc != 3) - { - printf("Usage: %s in_image out_image\n", argv[0]); - return 0; - } - - CImage image; - - if (! image.Load(argv[1])) - { - std::string err = image.GetError(); - printf("Error loading '%s': %s\n", argv[1], err.c_str()); - return 1; - } - Gfx::Color color; - std::string str; - - color = image.GetPixel(Math::IntPoint(0, 0)); - str = color.ToString(); - printf("pixel @ (0,0): %s\n", str.c_str()); - - color = image.GetPixel(Math::IntPoint(0, 1)); - str = color.ToString(); - printf("pixel @ (0,1): %s\n", str.c_str()); - - color = image.GetPixel(Math::IntPoint(1, 0)); - str = color.ToString(); - printf("pixel @ (1,0): %s\n", str.c_str()); - - color = image.GetPixel(Math::IntPoint(1, 1)); - str = color.ToString(); - printf("pixel @ (1,1): %s\n", str.c_str()); - - image.SetPixel(Math::IntPoint(0, 0), Gfx::Color(0.1f, 0.2f, 0.3f, 0.0f)); - image.SetPixel(Math::IntPoint(1, 0), Gfx::Color(0.3f, 0.2f, 0.1f, 1.0f)); - image.SetPixel(Math::IntPoint(0, 1), Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f)); - image.SetPixel(Math::IntPoint(1, 1), Gfx::Color(0.0f, 0.0f, 0.0f, 1.0f)); - - if (! image.SavePNG(argv[2])) - { - std::string err = image.GetError(); - printf("Error saving PNG '%s': %s\n", argv[2], err.c_str()); - return 2; - } - - return 0; -} diff --git a/src/common/test/profile_test.cpp b/src/common/test/profile_test.cpp deleted file mode 100644 index 6236083..0000000 --- a/src/common/test/profile_test.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "../profile.h" -#include "../logger.h" - -#include -#include -#include -#include - - -class CProfileTest : public testing::Test -{ -protected: - CLogger m_logger; - CProfile m_profile; - -}; - -TEST_F(CProfileTest, ReadTest) -{ - ASSERT_TRUE(m_profile.InitCurrentDirectory()); // load colobot.ini file - - std::string result; - ASSERT_TRUE(m_profile.GetLocalProfileString("test_string", "string_value", result)); - ASSERT_STREQ("Hello world", result.c_str()); - - int int_value; - ASSERT_TRUE(m_profile.GetLocalProfileInt("test_int", "int_value", int_value)); - ASSERT_EQ(42, int_value); - - float float_value; - ASSERT_TRUE(m_profile.GetLocalProfileFloat("test_float", "float_value", float_value)); - ASSERT_FLOAT_EQ(1.5, float_value); - - std::vector list; - list = m_profile.GetLocalProfileSection("test_multi", "entry"); - ASSERT_EQ(5u, list.size()); -} - -int main(int argc, char *argv[]) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} - diff --git a/src/graphics/opengl/test/CMakeLists.txt b/src/graphics/opengl/test/CMakeLists.txt deleted file mode 100644 index 79e0ba5..0000000 --- a/src/graphics/opengl/test/CMakeLists.txt +++ /dev/null @@ -1,90 +0,0 @@ -cmake_minimum_required(VERSION 2.8) - -find_package(OpenGL REQUIRED) -find_package(SDL REQUIRED) -find_package(SDL_image REQUIRED) -find_package(PNG REQUIRED) - -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE debug) -endif(NOT CMAKE_BUILD_TYPE) -set(CMAKE_CXX_FLAGS_DEBUG "-g -O0") - -set(ADD_LIBS "") - -if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") - set(PLATFORM_WINDOWS 1) - set(PLATFORM_LINUX 0) - set(PLATFORM_OTHER 0) -elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") - set(PLATFORM_WINDOWS 0) - set(PLATFORM_LINUX 1) - set(PLATFORM_OTHER 0) - set(ADD_LIBS "-lrt") -else() - set(PLATFORM_WINDOWS 0) - set(PLATFORM_LINUX 0) - set(PLATFORM_OTHER 1) -endif() - -configure_file(../../../common/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/common/config.h) - - -set(TEXTURE_SOURCES -../gldevice.cpp -../../../common/logger.cpp -../../../common/image.cpp -texture_test.cpp -) - -set(MODEL_SOURCES -../gldevice.cpp -../../engine/modelfile.cpp -../../../common/logger.cpp -../../../common/image.cpp -../../../common/iman.cpp -../../../common/stringutils.cpp -../../../app/system.cpp -model_test.cpp -) - -set(TRANSFORM_SOURCES -../gldevice.cpp -../../../common/logger.cpp -../../../common/image.cpp -../../../common/iman.cpp -../../../app/system.cpp -transform_test.cpp -) - -set(LIGHT_SOURCES -../gldevice.cpp -../../../common/logger.cpp -../../../common/image.cpp -../../../common/iman.cpp -../../../app/system.cpp -light_test.cpp -) - -include_directories(../../../ ${CMAKE_CURRENT_BINARY_DIR}) - -set(LIBS -${SDL_LIBRARY} -${SDLIMAGE_LIBRARY} -${OPENGL_LIBRARY} -${PNG_LIBRARIES} -${ADD_LIBS} -) - -add_executable(texture_test ${TEXTURE_SOURCES}) -target_link_libraries(texture_test ${LIBS}) - -# Temporarily disabling because of dependencies on CEngine et al. -#add_executable(model_test ${MODEL_SOURCES}) -#target_link_libraries(model_test ${LIBS}) - -add_executable(transform_test ${TRANSFORM_SOURCES}) -target_link_libraries(transform_test ${LIBS}) - -add_executable(light_test ${LIGHT_SOURCES}) -target_link_libraries(light_test ${LIBS}) diff --git a/src/graphics/opengl/test/README.txt b/src/graphics/opengl/test/README.txt deleted file mode 100644 index c618415..0000000 --- a/src/graphics/opengl/test/README.txt +++ /dev/null @@ -1,9 +0,0 @@ -Test programs for OpenGL engine: - - texture_test -> multitexturing test with 2 textures (included as files: ./tex1.png, ./tex2.png) - - model_test -> simple model viewer to test model loading - usage: ./model_test {dxf|mod} model_file - second argument is the loaded format (DXF or Colobot .mod files) - requires ./tex folder (or symlink) with Colobot textures - viewer is controlled from keyboard - the bindings can be found in code - - transform_test -> simple "walk around" test for world & view transformations - - light test -> test for lighting diff --git a/src/graphics/opengl/test/light_test.cpp b/src/graphics/opengl/test/light_test.cpp deleted file mode 100644 index b19ba4b..0000000 --- a/src/graphics/opengl/test/light_test.cpp +++ /dev/null @@ -1,462 +0,0 @@ -#include "app/system.h" -#include "common/logger.h" -#include "common/image.h" -#include "common/iman.h" -#include "graphics/opengl/gldevice.h" -#include "math/geometry.h" - -#include -#include -#include - -#include -#include - -enum KeySlots -{ - K_Forward, - K_Back, - K_Left, - K_Right, - K_Up, - K_Down, - K_Count -}; -bool KEYMAP[K_Count] = { false }; - -Math::Point MOUSE_POS_BASE; - -Math::Vector TRANSLATION(0.0f, 2.0f, 0.0f); -Math::Vector ROTATION, ROTATION_BASE; - -float CUBE_ORBIT = 0.0f; - -const int FRAME_DELAY = 5000; - -SystemTimeStamp *PREV_TIME = NULL, *CURR_TIME = NULL; - -void Init(Gfx::CGLDevice *device) -{ - device->SetRenderState(Gfx::RENDER_STATE_DEPTH_TEST, true); - device->SetShadeModel(Gfx::SHADE_SMOOTH); -} - -void Render(Gfx::CGLDevice *device) -{ - device->BeginScene(); - - /* Unlit part of scene */ - - device->SetRenderState(Gfx::RENDER_STATE_LIGHTING, false); - device->SetRenderState(Gfx::RENDER_STATE_CULLING, false); // Double-sided drawing - - Math::Matrix persp; - Math::LoadProjectionMatrix(persp, Math::PI / 4.0f, (800.0f) / (600.0f), 0.1f, 50.0f); - device->SetTransform(Gfx::TRANSFORM_PROJECTION, persp); - - - Math::Matrix viewMat; - Math::Matrix mat; - - viewMat.LoadIdentity(); - - Math::LoadRotationXMatrix(mat, -ROTATION.x); - viewMat = Math::MultiplyMatrices(viewMat, mat); - - Math::LoadRotationYMatrix(mat, -ROTATION.y); - viewMat = Math::MultiplyMatrices(viewMat, mat); - - Math::LoadTranslationMatrix(mat, -TRANSLATION); - viewMat = Math::MultiplyMatrices(viewMat, mat); - - device->SetTransform(Gfx::TRANSFORM_VIEW, viewMat); - - Math::Matrix worldMat; - worldMat.LoadIdentity(); - device->SetTransform(Gfx::TRANSFORM_WORLD, worldMat); - - Gfx::VertexCol line[2] = { Gfx::VertexCol() }; - - for (int x = -40; x <= 40; ++x) - { - line[0].color = Gfx::Color(0.7f + x / 120.0f, 0.0f, 0.0f); - line[0].coord.z = -40; - line[0].coord.x = x; - line[1].color = Gfx::Color(0.7f + x / 120.0f, 0.0f, 0.0f); - line[1].coord.z = 40; - line[1].coord.x = x; - device->DrawPrimitive(Gfx::PRIMITIVE_LINES, line, 2); - } - - for (int z = -40; z <= 40; ++z) - { - line[0].color = Gfx::Color(0.0f, 0.7f + z / 120.0f, 0.0f); - line[0].coord.z = z; - line[0].coord.x = -40; - line[1].color = Gfx::Color(0.0f, 0.7f + z / 120.0f, 0.0f); - line[1].coord.z = z; - line[1].coord.x = 40; - device->DrawPrimitive(Gfx::PRIMITIVE_LINES, line, 2); - } - - - Gfx::VertexCol quad[6] = { Gfx::VertexCol() }; - - quad[0].coord = Math::Vector(-1.0f, -1.0f, 0.0f); - quad[1].coord = Math::Vector( 1.0f, -1.0f, 0.0f); - quad[2].coord = Math::Vector(-1.0f, 1.0f, 0.0f); - quad[3].coord = Math::Vector( 1.0f, 1.0f, 0.0f); - - for (int i = 0; i < 6; ++i) - quad[i].color = Gfx::Color(1.0f, 1.0f, 0.0f); - - Math::LoadTranslationMatrix(worldMat, Math::Vector(40.0f, 2.0f, 40.0f)); - device->SetTransform(Gfx::TRANSFORM_WORLD, worldMat); - - device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, quad, 4); - - for (int i = 0; i < 6; ++i) - quad[i].color = Gfx::Color(0.0f, 1.0f, 1.0f); - - Math::LoadTranslationMatrix(worldMat, Math::Vector(-40.0f, 2.0f, -40.0f)); - device->SetTransform(Gfx::TRANSFORM_WORLD, worldMat); - - int planes = device->ComputeSphereVisibility(Math::Vector(0.0f, 0.0f, 0.0f), 1.0f); - printf("Planes:"); - if (planes == 0) - printf(" (none)"); - - if (planes & Gfx::FRUSTUM_PLANE_LEFT) - printf(" LEFT"); - - if (planes & Gfx::FRUSTUM_PLANE_RIGHT) - printf(" RIGHT"); - - if (planes & Gfx::FRUSTUM_PLANE_BOTTOM) - printf(" BOTTOM"); - - if (planes & Gfx::FRUSTUM_PLANE_TOP) - printf(" TOP"); - - if (planes & Gfx::FRUSTUM_PLANE_FRONT) - printf(" FRONT"); - - if (planes & Gfx::FRUSTUM_PLANE_BACK) - printf(" BACK"); - - printf("\n"); - - device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, quad, 4); - - for (int i = 0; i < 6; ++i) - quad[i].color = Gfx::Color(1.0f, 0.0f, 1.0f); - - Math::LoadTranslationMatrix(worldMat, Math::Vector(10.0f, 4.5f, 5.0f)); - device->SetTransform(Gfx::TRANSFORM_WORLD, worldMat); - - device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, quad, 4); - - /* Moving lit cube */ - device->SetRenderState(Gfx::RENDER_STATE_LIGHTING, true); - device->SetRenderState(Gfx::RENDER_STATE_CULLING, true); // Culling (CCW faces) - - device->SetGlobalAmbient(Gfx::Color(0.4f, 0.4f, 0.4f)); - - Gfx::Light light1; - light1.type = Gfx::LIGHT_POINT; - light1.position = Math::Vector(10.0f, 4.5f, 5.0f); - light1.ambient = Gfx::Color(0.2f, 0.2f, 0.2f); - light1.diffuse = Gfx::Color(1.0f, 0.1f, 0.1f); - light1.specular = Gfx::Color(0.0f, 0.0f, 0.0f); - device->SetLight(0, light1); - device->SetLightEnabled(0, true); - - /*Gfx::Light light2; - device->SetLight(1, light2); - device->SetLightEnabled(1, true);*/ - - Gfx::Material material; - material.ambient = Gfx::Color(0.3f, 0.3f, 0.3f); - material.diffuse = Gfx::Color(0.8f, 0.7f, 0.6f); - material.specular = Gfx::Color(0.0f, 0.0f, 0.0f); - device->SetMaterial(material); - - const Gfx::Vertex cube[6][4] = - { - { - // Front - Gfx::Vertex(Math::Vector(-1.0f, -1.0f, -1.0f), Math::Vector( 0.0f, 0.0f, -1.0f)), - Gfx::Vertex(Math::Vector( 1.0f, -1.0f, -1.0f), Math::Vector( 0.0f, 0.0f, -1.0f)), - Gfx::Vertex(Math::Vector(-1.0f, 1.0f, -1.0f), Math::Vector( 0.0f, 0.0f, -1.0f)), - Gfx::Vertex(Math::Vector( 1.0f, 1.0f, -1.0f), Math::Vector( 0.0f, 0.0f, -1.0f)) - }, - - { - // Back - Gfx::Vertex(Math::Vector( 1.0f, -1.0f, 1.0f), Math::Vector( 0.0f, 0.0f, 1.0f)), - Gfx::Vertex(Math::Vector(-1.0f, -1.0f, 1.0f), Math::Vector( 0.0f, 0.0f, 1.0f)), - Gfx::Vertex(Math::Vector( 1.0f, 1.0f, 1.0f), Math::Vector( 0.0f, 0.0f, 1.0f)), - Gfx::Vertex(Math::Vector(-1.0f, 1.0f, 1.0f), Math::Vector( 0.0f, 0.0f, 1.0f)) - }, - - { - // Top - Gfx::Vertex(Math::Vector(-1.0f, 1.0f, -1.0f), Math::Vector( 0.0f, 1.0f, 0.0f)), - Gfx::Vertex(Math::Vector( 1.0f, 1.0f, -1.0f), Math::Vector( 0.0f, 1.0f, 0.0f)), - Gfx::Vertex(Math::Vector(-1.0f, 1.0f, 1.0f), Math::Vector( 0.0f, 1.0f, 0.0f)), - Gfx::Vertex(Math::Vector( 1.0f, 1.0f, 1.0f), Math::Vector( 0.0f, 1.0f, 0.0f)) - }, - - { - // Bottom - Gfx::Vertex(Math::Vector(-1.0f, -1.0f, 1.0f), Math::Vector( 0.0f, -1.0f, 0.0f)), - Gfx::Vertex(Math::Vector( 1.0f, -1.0f, 1.0f), Math::Vector( 0.0f, -1.0f, 0.0f)), - Gfx::Vertex(Math::Vector(-1.0f, -1.0f, -1.0f), Math::Vector( 0.0f, -1.0f, 0.0f)), - Gfx::Vertex(Math::Vector( 1.0f, -1.0f, -1.0f), Math::Vector( 0.0f, -1.0f, 0.0f)) - }, - - { - // Left - Gfx::Vertex(Math::Vector(-1.0f, -1.0f, 1.0f), Math::Vector(-1.0f, 0.0f, 0.0f)), - Gfx::Vertex(Math::Vector(-1.0f, -1.0f, -1.0f), Math::Vector(-1.0f, 0.0f, 0.0f)), - Gfx::Vertex(Math::Vector(-1.0f, 1.0f, 1.0f), Math::Vector(-1.0f, 0.0f, 0.0f)), - Gfx::Vertex(Math::Vector(-1.0f, 1.0f, -1.0f), Math::Vector(-1.0f, 0.0f, 0.0f)) - }, - - { - // Right - Gfx::Vertex(Math::Vector( 1.0f, -1.0f, -1.0f), Math::Vector( 1.0f, 0.0f, 0.0f)), - Gfx::Vertex(Math::Vector( 1.0f, -1.0f, 1.0f), Math::Vector( 1.0f, 0.0f, 0.0f)), - Gfx::Vertex(Math::Vector( 1.0f, 1.0f, -1.0f), Math::Vector( 1.0f, 0.0f, 0.0f)), - Gfx::Vertex(Math::Vector( 1.0f, 1.0f, 1.0f), Math::Vector( 1.0f, 0.0f, 0.0f)) - } - }; - - Math::Matrix cubeTrans; - Math::LoadTranslationMatrix(cubeTrans, Math::Vector(10.0f, 2.0f, 5.0f)); - Math::Matrix cubeRot; - Math::LoadRotationMatrix(cubeRot, Math::Vector(0.0f, 1.0f, 0.0f), CUBE_ORBIT); - Math::Matrix cubeRotInv; - Math::LoadRotationMatrix(cubeRotInv, Math::Vector(0.0f, 1.0f, 0.0f), -CUBE_ORBIT); - Math::Matrix cubeTransRad; - Math::LoadTranslationMatrix(cubeTransRad, Math::Vector(0.0f, 0.0f, 6.0f)); - worldMat = Math::MultiplyMatrices(cubeTransRad, cubeRotInv); - worldMat = Math::MultiplyMatrices(cubeRot, worldMat); - worldMat = Math::MultiplyMatrices(cubeTrans, worldMat); - device->SetTransform(Gfx::TRANSFORM_WORLD, worldMat); - - for (int i = 0; i < 6; ++i) - device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, cube[i], 4); - - device->EndScene(); -} - -void Update() -{ - const float TRANS_SPEED = 6.0f; // units / sec - - GetCurrentTimeStamp(CURR_TIME); - float timeDiff = TimeStampDiff(PREV_TIME, CURR_TIME, STU_SEC); - CopyTimeStamp(PREV_TIME, CURR_TIME); - - CUBE_ORBIT += timeDiff * (Math::PI / 4.0f); - - Math::Vector incTrans; - - if (KEYMAP[K_Forward]) - incTrans.z = +TRANS_SPEED * timeDiff; - if (KEYMAP[K_Back]) - incTrans.z = -TRANS_SPEED * timeDiff; - if (KEYMAP[K_Right]) - incTrans.x = +TRANS_SPEED * timeDiff; - if (KEYMAP[K_Left]) - incTrans.x = -TRANS_SPEED * timeDiff; - if (KEYMAP[K_Up]) - incTrans.y = +TRANS_SPEED * timeDiff; - if (KEYMAP[K_Down]) - incTrans.y = -TRANS_SPEED * timeDiff; - - Math::Point rotTrans = Math::RotatePoint(-ROTATION.y, Math::Point(incTrans.x, incTrans.z)); - incTrans.x = rotTrans.x; - incTrans.z = rotTrans.y; - TRANSLATION += incTrans; -} - -void KeyboardDown(SDLKey key) -{ - switch (key) - { - case SDLK_w: - KEYMAP[K_Forward] = true; - break; - case SDLK_s: - KEYMAP[K_Back] = true; - break; - case SDLK_d: - KEYMAP[K_Right] = true; - break; - case SDLK_a: - KEYMAP[K_Left] = true; - break; - case SDLK_z: - KEYMAP[K_Down] = true; - break; - case SDLK_x: - KEYMAP[K_Up] = true; - break; - default: - break; - } -} - -void KeyboardUp(SDLKey key) -{ - switch (key) - { - case SDLK_w: - KEYMAP[K_Forward] = false; - break; - case SDLK_s: - KEYMAP[K_Back] = false; - break; - case SDLK_d: - KEYMAP[K_Right] = false; - break; - case SDLK_a: - KEYMAP[K_Left] = false; - break; - case SDLK_z: - KEYMAP[K_Down] = false; - break; - case SDLK_x: - KEYMAP[K_Up] = false; - break; - default: - break; - } -} - -void MouseMove(int x, int y) -{ - Math::Point currentPos(static_cast(x), static_cast(y)); - - static bool first = true; - if (first || (x < 10) || (y < 10) || (x > 790) || (y > 590)) - { - SDL_WarpMouse(400, 300); - MOUSE_POS_BASE.x = 400; - MOUSE_POS_BASE.y = 300; - ROTATION_BASE = ROTATION; - first = false; - return; - } - - ROTATION.y = ROTATION_BASE.y + (static_cast (x - MOUSE_POS_BASE.x) / 800.0f) * Math::PI; - ROTATION.x = ROTATION_BASE.x + (static_cast (y - MOUSE_POS_BASE.y) / 600.0f) * Math::PI; -} - -int main(int argc, char *argv[]) -{ - CLogger logger; - - PREV_TIME = CreateTimeStamp(); - CURR_TIME = CreateTimeStamp(); - - GetCurrentTimeStamp(PREV_TIME); - GetCurrentTimeStamp(CURR_TIME); - - CInstanceManager iMan; - - // Without any error checking, for simplicity - - SDL_Init(SDL_INIT_VIDEO); - - IMG_Init(IMG_INIT_PNG); - - const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo(); - - Uint32 videoFlags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_HWPALETTE; - - if (videoInfo->hw_available) - videoFlags |= SDL_HWSURFACE; - else - videoFlags |= SDL_SWSURFACE; - - if (videoInfo->blit_hw) - videoFlags |= SDL_HWACCEL; - - - SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); - - SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 8); - - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - - SDL_Surface *surface = SDL_SetVideoMode(800, 600, 32, videoFlags); - - - SDL_WM_SetCaption("Light Test", "Light Test"); - - //SDL_WM_GrabInput(SDL_GRAB_ON); - SDL_ShowCursor(SDL_DISABLE); - - Gfx::CGLDevice *device = new Gfx::CGLDevice(Gfx::GLDeviceConfig()); - device->Create(); - - Init(device); - - bool done = false; - while (! done) - { - Render(device); - Update(); - - SDL_GL_SwapBuffers(); - - SDL_Event event; - while (SDL_PollEvent(&event)) - { - if (event.type == SDL_QUIT) - { - break; - done = true; - } - else if (event.type == SDL_KEYDOWN) - { - if (event.key.keysym.sym == SDLK_q) - { - done = true; - break; - } - else - KeyboardDown(event.key.keysym.sym); - } - else if (event.type == SDL_KEYUP) - KeyboardUp(event.key.keysym.sym); - else if (event.type == SDL_MOUSEMOTION) - MouseMove(event.motion.x, event.motion.y); - } - - usleep(FRAME_DELAY); - } - - //SDL_WM_GrabInput(SDL_GRAB_OFF); - SDL_ShowCursor(SDL_ENABLE); - - device->Destroy(); - delete device; - - SDL_FreeSurface(surface); - - IMG_Quit(); - - SDL_Quit(); - - DestroyTimeStamp(PREV_TIME); - DestroyTimeStamp(CURR_TIME); - - return 0; -} diff --git a/src/graphics/opengl/test/model_test.cpp b/src/graphics/opengl/test/model_test.cpp deleted file mode 100644 index e951e6e..0000000 --- a/src/graphics/opengl/test/model_test.cpp +++ /dev/null @@ -1,377 +0,0 @@ -#include "app/system.h" -#include "common/logger.h" -#include "common/image.h" -#include "common/iman.h" -#include "graphics/engine/modelfile.h" -#include "graphics/opengl/gldevice.h" -#include "math/geometry.h" - -#include -#include -#include - -#include -#include - -enum KeySlots -{ - K_RotXUp, - K_RotXDown, - K_RotYLeft, - K_RotYRight, - K_Forward, - K_Back, - K_Left, - K_Right, - K_Up, - K_Down, - K_Count -}; -bool KEYMAP[K_Count] = { false }; - -Math::Vector TRANSLATION(0.0f, 0.0f, 30.0f); -Math::Vector ROTATION; - -const int FRAME_DELAY = 5000; - -std::map TEXS; - -SystemTimeStamp *PREV_TIME = NULL, *CURR_TIME = NULL; - -Gfx::Texture GetTexture(const std::string &name) -{ - std::map::iterator it = TEXS.find(name); - if (it == TEXS.end()) - return Gfx::Texture(); - - return (*it).second; -} - -void LoadTexture(Gfx::CGLDevice *device, const std::string &name) -{ - if (name.empty()) - return; - - Gfx::Texture tex = GetTexture(name); - - if (tex.Valid()) - return; - - CImage img; - if (! img.Load(std::string("tex/") + name)) - { - std::string err = img.GetError(); - GetLogger()->Error("Texture not loaded, error: %s!\n", err.c_str()); - } - else - { - Gfx::TextureCreateParams texCreateParams; - texCreateParams.mipmap = true; - if (img.GetData()->surface->format->Amask == 0) - texCreateParams.format = Gfx::TEX_IMG_BGR; - else - texCreateParams.format = Gfx::TEX_IMG_BGRA; - texCreateParams.minFilter = Gfx::TEX_MIN_FILTER_LINEAR_MIPMAP_LINEAR; - texCreateParams.magFilter = Gfx::TEX_MAG_FILTER_LINEAR; - - tex = device->CreateTexture(&img, texCreateParams); - } - - TEXS[name] = tex; -} - -void Init(Gfx::CGLDevice *device, Gfx::CModelFile *model) -{ - std::vector &triangles = model->GetTriangles(); - - for (int i = 0; i < static_cast( triangles.size() ); ++i) - { - LoadTexture(device, triangles[i].tex1Name); - LoadTexture(device, triangles[i].tex2Name); - } - - device->SetRenderState(Gfx::RENDER_STATE_TEXTURING, true); - device->SetRenderState(Gfx::RENDER_STATE_LIGHTING, true); - device->SetRenderState(Gfx::RENDER_STATE_DEPTH_TEST, true); - device->SetShadeModel(Gfx::SHADE_SMOOTH); - - Gfx::Light light; - light.type = Gfx::LIGHT_DIRECTIONAL; - light.ambient = Gfx::Color(0.4f, 0.4f, 0.4f, 0.0f); - light.diffuse = Gfx::Color(0.8f, 0.8f, 0.8f, 0.0f); - light.specular = Gfx::Color(0.2f, 0.2f, 0.2f, 0.0f); - light.position = Math::Vector(0.0f, 0.0f, -1.0f); - light.direction = Math::Vector(0.0f, 0.0f, 1.0f); - - device->SetGlobalAmbient(Gfx::Color(0.5f, 0.5f, 0.5f, 0.0f)); - device->SetLight(0, light); - device->SetLightEnabled(0, true); -} - -void Render(Gfx::CGLDevice *device, Gfx::CModelFile *modelFile) -{ - device->BeginScene(); - - Math::Matrix persp; - Math::LoadProjectionMatrix(persp, Math::PI / 4.0f, (800.0f) / (600.0f), 0.1f, 100.0f); - device->SetTransform(Gfx::TRANSFORM_PROJECTION, persp); - - Math::Matrix id; - id.LoadIdentity(); - device->SetTransform(Gfx::TRANSFORM_WORLD, id); - - Math::Matrix viewMat; - Math::LoadTranslationMatrix(viewMat, TRANSLATION); - Math::Matrix rot; - Math::LoadRotationXZYMatrix(rot, ROTATION); - viewMat = Math::MultiplyMatrices(viewMat, rot); - device->SetTransform(Gfx::TRANSFORM_VIEW, viewMat); - - std::vector &triangles = modelFile->GetTriangles(); - - Gfx::VertexTex2 tri[3]; - - for (int i = 0; i < static_cast( triangles.size() ); ++i) - { - device->SetTexture(0, GetTexture(triangles[i].tex1Name)); - device->SetTexture(1, GetTexture(triangles[i].tex2Name)); - device->SetTextureEnabled(0, true); - device->SetTextureEnabled(1, true); - - device->SetMaterial(triangles[i].material); - - tri[0] = triangles[i].p1; - tri[1] = triangles[i].p2; - tri[2] = triangles[i].p3; - - device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLES, tri, 3); - } - - device->EndScene(); -} - -void Update() -{ - const float ROT_SPEED = 80.0f * Math::DEG_TO_RAD; // rad / sec - const float TRANS_SPEED = 3.0f; // units / sec - - GetCurrentTimeStamp(CURR_TIME); - float timeDiff = TimeStampDiff(PREV_TIME, CURR_TIME, STU_SEC); - CopyTimeStamp(PREV_TIME, CURR_TIME); - - if (KEYMAP[K_RotYLeft]) - ROTATION.y -= ROT_SPEED * timeDiff; - if (KEYMAP[K_RotYRight]) - ROTATION.y += ROT_SPEED * timeDiff; - if (KEYMAP[K_RotXDown]) - ROTATION.x -= ROT_SPEED * timeDiff; - if (KEYMAP[K_RotXUp]) - ROTATION.x += ROT_SPEED * timeDiff; - - if (KEYMAP[K_Forward]) - TRANSLATION.z -= TRANS_SPEED * timeDiff; - if (KEYMAP[K_Back]) - TRANSLATION.z += TRANS_SPEED * timeDiff; - if (KEYMAP[K_Left]) - TRANSLATION.x += TRANS_SPEED * timeDiff; - if (KEYMAP[K_Right]) - TRANSLATION.x -= TRANS_SPEED * timeDiff; - if (KEYMAP[K_Up]) - TRANSLATION.y += TRANS_SPEED * timeDiff; - if (KEYMAP[K_Down]) - TRANSLATION.y -= TRANS_SPEED * timeDiff; -} - -void KeyboardDown(SDLKey key) -{ - switch (key) - { - case SDLK_LEFT: - KEYMAP[K_RotYLeft] = true; - break; - case SDLK_RIGHT: - KEYMAP[K_RotYRight] = true; - break; - case SDLK_UP: - KEYMAP[K_RotXUp] = true; - break; - case SDLK_DOWN: - KEYMAP[K_RotXDown] = true; - break; - case SDLK_w: - KEYMAP[K_Forward] = true; - break; - case SDLK_s: - KEYMAP[K_Back] = true; - break; - case SDLK_a: - KEYMAP[K_Left] = true; - break; - case SDLK_d: - KEYMAP[K_Right] = true; - break; - case SDLK_z: - KEYMAP[K_Down] = true; - break; - case SDLK_x: - KEYMAP[K_Up] = true; - break; - default: - break; - } -} - -void KeyboardUp(SDLKey key) -{ - switch (key) - { - case SDLK_LEFT: - KEYMAP[K_RotYLeft] = false; - break; - case SDLK_RIGHT: - KEYMAP[K_RotYRight] = false; - break; - case SDLK_UP: - KEYMAP[K_RotXUp] = false; - break; - case SDLK_DOWN: - KEYMAP[K_RotXDown] = false; - break; - case SDLK_w: - KEYMAP[K_Forward] = false; - break; - case SDLK_s: - KEYMAP[K_Back] = false; - break; - case SDLK_a: - KEYMAP[K_Left] = false; - break; - case SDLK_d: - KEYMAP[K_Right] = false; - break; - case SDLK_z: - KEYMAP[K_Down] = false; - break; - case SDLK_x: - KEYMAP[K_Up] = false; - break; - default: - break; - } -} - -int main(int argc, char *argv[]) -{ - CLogger logger; - - PREV_TIME = CreateTimeStamp(); - CURR_TIME = CreateTimeStamp(); - - GetCurrentTimeStamp(PREV_TIME); - GetCurrentTimeStamp(CURR_TIME); - - if (argc != 3) - { - std::cerr << "Usage: " << argv[0] << "{mod|dxf} model_file" << std::endl; - return 1; - } - - CInstanceManager iMan; - - Gfx::CModelFile *modelFile = new Gfx::CModelFile(&iMan); - if (std::string(argv[1]) == "mod") - { - if (! modelFile->ReadModel(argv[2], false, false)) - { - std::cerr << "Error reading MOD: " << modelFile->GetError() << std::endl; - return 1; - } - } - else if (std::string(argv[1]) == "dxf") - { - if (! modelFile->ReadDXF(argv[2], 0.0f, 0.0f)) - { - std::cerr << "Error reading DXF: " << modelFile->GetError() << std::endl; - return 1; - } - } - else - { - std::cerr << "Usage: " << argv[0] << "{mod|dxf} model_file" << std::endl; - return 1; - } - - // Without any error checking, for simplicity - - SDL_Init(SDL_INIT_VIDEO); - - IMG_Init(IMG_INIT_PNG); - - const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo(); - - Uint32 videoFlags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_HWPALETTE; - - if (videoInfo->hw_available) - videoFlags |= SDL_HWSURFACE; - else - videoFlags |= SDL_SWSURFACE; - - if (videoInfo->blit_hw) - videoFlags |= SDL_HWACCEL; - - - SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); - - SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 8); - - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - - SDL_Surface *surface = SDL_SetVideoMode(800, 600, 32, videoFlags); - - - SDL_WM_SetCaption("Model Test", "Model Test"); - - Gfx::CGLDevice *device = new Gfx::CGLDevice(Gfx::GLDeviceConfig()); - device->Create(); - - Init(device, modelFile); - - bool done = false; - while (! done) - { - Render(device, modelFile); - Update(); - - SDL_GL_SwapBuffers(); - - SDL_Event event; - SDL_PollEvent(&event); - if (event.type == SDL_QUIT) - done = true; - else if (event.type == SDL_KEYDOWN) - KeyboardDown(event.key.keysym.sym); - else if (event.type == SDL_KEYUP) - KeyboardUp(event.key.keysym.sym); - - usleep(FRAME_DELAY); - } - - delete modelFile; - - device->Destroy(); - delete device; - - SDL_FreeSurface(surface); - - IMG_Quit(); - - SDL_Quit(); - - DestroyTimeStamp(PREV_TIME); - DestroyTimeStamp(CURR_TIME); - - return 0; -} diff --git a/src/graphics/opengl/test/tex1.png b/src/graphics/opengl/test/tex1.png deleted file mode 100644 index 46c68a0..0000000 Binary files a/src/graphics/opengl/test/tex1.png and /dev/null differ diff --git a/src/graphics/opengl/test/tex2.png b/src/graphics/opengl/test/tex2.png deleted file mode 100644 index ebdae0d..0000000 Binary files a/src/graphics/opengl/test/tex2.png and /dev/null differ diff --git a/src/graphics/opengl/test/texture_test.cpp b/src/graphics/opengl/test/texture_test.cpp deleted file mode 100644 index d771927..0000000 --- a/src/graphics/opengl/test/texture_test.cpp +++ /dev/null @@ -1,192 +0,0 @@ -#include "common/logger.h" -#include "common/image.h" -#include "graphics/opengl/gldevice.h" -#include "math/geometry.h" - -#include -#include -#include - - -void Init(Gfx::CGLDevice *device) -{ - device->SetShadeModel(Gfx::SHADE_SMOOTH); - - device->SetRenderState(Gfx::RENDER_STATE_DEPTH_TEST, false); - - device->SetTextureEnabled(0, true); - device->SetTextureEnabled(1, true); - - CImage img1; - if (! img1.Load("tex1.png")) - { - std::string err = img1.GetError(); - GetLogger()->Error("texture 1 not loaded, error: %d!\n", err.c_str()); - } - CImage img2; - if (! img2.Load("tex2.png")) - { - std::string err = img2.GetError(); - GetLogger()->Error("texture 2 not loaded, error: %d!\n", err.c_str()); - } - - Gfx::TextureCreateParams tex1CreateParams; - tex1CreateParams.mipmap = true; - tex1CreateParams.format = Gfx::TEX_IMG_RGBA; - tex1CreateParams.minFilter = Gfx::TEX_MIN_FILTER_LINEAR_MIPMAP_LINEAR; - tex1CreateParams.magFilter = Gfx::TEX_MAG_FILTER_LINEAR; - - Gfx::TextureCreateParams tex2CreateParams; - tex2CreateParams.mipmap = true; - tex2CreateParams.format = Gfx::TEX_IMG_RGBA; - tex2CreateParams.minFilter = Gfx::TEX_MIN_FILTER_NEAREST_MIPMAP_NEAREST; - tex2CreateParams.magFilter = Gfx::TEX_MAG_FILTER_NEAREST; - - Gfx::Texture tex1 = device->CreateTexture(&img1, tex1CreateParams); - Gfx::Texture tex2 = device->CreateTexture(&img2, tex2CreateParams); - - device->SetTexture(0, tex1); - device->SetTexture(1, tex2); -} - -void Render(Gfx::CGLDevice *device) -{ - device->BeginScene(); - - Math::Matrix ortho; - Math::LoadOrthoProjectionMatrix(ortho, -10, 10, -10, 10); - device->SetTransform(Gfx::TRANSFORM_PROJECTION, ortho); - - Math::Matrix id; - id.LoadIdentity(); - - device->SetTransform(Gfx::TRANSFORM_WORLD, id); - device->SetTransform(Gfx::TRANSFORM_VIEW, id); - - static Gfx::VertexTex2 quad[] = - { - Gfx::VertexTex2(Math::Vector(-2.0f, 2.0f, 0.0f), Math::Vector(), Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f)), - Gfx::VertexTex2(Math::Vector( 2.0f, 2.0f, 0.0f), Math::Vector(), Math::Point(1.0f, 0.0f), Math::Point(1.0f, 0.0f)), - Gfx::VertexTex2(Math::Vector( 2.0f, -2.0f, 0.0f), Math::Vector(), Math::Point(1.0f, 1.0f), Math::Point(1.0f, 1.0f)), - - Gfx::VertexTex2(Math::Vector( 2.0f, -2.0f, 0.0f), Math::Vector(), Math::Point(1.0f, 1.0f), Math::Point(1.0f, 1.0f)), - Gfx::VertexTex2(Math::Vector(-2.0f, -2.0f, 0.0f), Math::Vector(), Math::Point(0.0f, 1.0f), Math::Point(0.0f, 1.0f)), - Gfx::VertexTex2(Math::Vector(-2.0f, 2.0f, 0.0f), Math::Vector(), Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f)), - }; - - Gfx::TextureStageParams tex1StageParams; - tex1StageParams.colorOperation = Gfx::TEX_MIX_OPER_DEFAULT; - tex1StageParams.alphaOperation = Gfx::TEX_MIX_OPER_DEFAULT; - device->SetTextureStageParams(0, tex1StageParams); - - Gfx::TextureStageParams tex2StageParams; - tex2StageParams.colorOperation = Gfx::TEX_MIX_OPER_DEFAULT; - tex2StageParams.alphaOperation = Gfx::TEX_MIX_OPER_DEFAULT; - device->SetTextureStageParams(1, tex2StageParams); - - Math::Matrix t; - Math::LoadTranslationMatrix(t, Math::Vector(-4.0f, 4.0f, 0.0f)); - device->SetTransform(Gfx::TRANSFORM_VIEW, t); - - device->SetTextureEnabled(0, true); - device->SetTextureEnabled(1, false); - - device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLES, quad, 6); - - Math::LoadTranslationMatrix(t, Math::Vector( 4.0f, 4.0f, 0.0f)); - device->SetTransform(Gfx::TRANSFORM_VIEW, t); - - device->SetTextureEnabled(0, false); - device->SetTextureEnabled(1, true); - - device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLES, quad, 6); - - Math::LoadTranslationMatrix(t, Math::Vector( 0.0f, -4.0f, 0.0f)); - device->SetTransform(Gfx::TRANSFORM_VIEW, t); - - device->SetTextureEnabled(0, true); - device->SetTextureEnabled(1, true); - - tex1StageParams.colorOperation = Gfx::TEX_MIX_OPER_DEFAULT; - tex1StageParams.alphaOperation = Gfx::TEX_MIX_OPER_DEFAULT; - device->SetTextureStageParams(0, tex1StageParams); - - tex2StageParams.colorOperation = Gfx::TEX_MIX_OPER_ADD; - tex2StageParams.colorArg1 = Gfx::TEX_MIX_ARG_COMPUTED_COLOR; - tex2StageParams.colorArg2 = Gfx::TEX_MIX_ARG_TEXTURE; - tex2StageParams.alphaOperation = Gfx::TEX_MIX_OPER_DEFAULT; - device->SetTextureStageParams(1, tex2StageParams); - - device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLES, quad, 6); - - device->EndScene(); -} - -int main() -{ - CLogger(); - - // Without any error checking, for simplicity - - SDL_Init(SDL_INIT_VIDEO); - - IMG_Init(IMG_INIT_PNG); - - const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo(); - - Uint32 videoFlags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_HWPALETTE; - - if (videoInfo->hw_available) - videoFlags |= SDL_HWSURFACE; - else - videoFlags |= SDL_SWSURFACE; - - if (videoInfo->blit_hw) - videoFlags |= SDL_HWACCEL; - - - SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); - - SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 8); - - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - - SDL_Surface *surface = SDL_SetVideoMode(800, 600, 32, videoFlags); - - - SDL_WM_SetCaption("Texture Test", "Texture Test"); - - Gfx::CGLDevice *device = new Gfx::CGLDevice(Gfx::GLDeviceConfig()); - device->Create(); - - Init(device); - - bool done = false; - while (! done) - { - Render(device); - - SDL_GL_SwapBuffers(); - - SDL_Event event; - SDL_PollEvent(&event); - if (event.type == SDL_QUIT) - done = true; - - usleep(10000); - } - - device->Destroy(); - delete device; - - SDL_FreeSurface(surface); - - IMG_Quit(); - - SDL_Quit(); - - return 0; -} diff --git a/src/graphics/opengl/test/transform_test.cpp b/src/graphics/opengl/test/transform_test.cpp deleted file mode 100644 index cddd1b8..0000000 --- a/src/graphics/opengl/test/transform_test.cpp +++ /dev/null @@ -1,339 +0,0 @@ -#include "app/system.h" -#include "common/logger.h" -#include "common/image.h" -#include "common/iman.h" -#include "graphics/opengl/gldevice.h" -#include "math/geometry.h" - -#include -#include -#include - -#include -#include - -enum KeySlots -{ - K_Forward, - K_Back, - K_Left, - K_Right, - K_Up, - K_Down, - K_Count -}; -bool KEYMAP[K_Count] = { false }; - -Math::Point MOUSE_POS_BASE; - -Math::Vector TRANSLATION(0.0f, 2.0f, 0.0f); -Math::Vector ROTATION, ROTATION_BASE; - -const int FRAME_DELAY = 5000; - -SystemTimeStamp *PREV_TIME = NULL, *CURR_TIME = NULL; - -void Init(Gfx::CGLDevice *device) -{ - device->SetRenderState(Gfx::RENDER_STATE_DEPTH_TEST, true); - device->SetShadeModel(Gfx::SHADE_SMOOTH); -} - -void Render(Gfx::CGLDevice *device) -{ - device->BeginScene(); - - Math::Matrix persp; - Math::LoadProjectionMatrix(persp, Math::PI / 4.0f, (800.0f) / (600.0f), 0.1f, 100.0f); - device->SetTransform(Gfx::TRANSFORM_PROJECTION, persp); - - - Math::Matrix viewMat; - Math::Matrix mat; - - viewMat.LoadIdentity(); - - Math::LoadRotationXMatrix(mat, -ROTATION.x); - viewMat = Math::MultiplyMatrices(viewMat, mat); - - Math::LoadRotationYMatrix(mat, -ROTATION.y); - viewMat = Math::MultiplyMatrices(viewMat, mat); - - Math::LoadTranslationMatrix(mat, -TRANSLATION); - viewMat = Math::MultiplyMatrices(viewMat, mat); - - device->SetTransform(Gfx::TRANSFORM_VIEW, viewMat); - - - Math::Matrix worldMat; - worldMat.LoadIdentity(); - device->SetTransform(Gfx::TRANSFORM_WORLD, worldMat); - - Gfx::VertexCol line[2] = { Gfx::VertexCol() }; - - for (int x = -40; x <= 40; ++x) - { - line[0].color = Gfx::Color(0.7f + x / 120.0f, 0.0f, 0.0f); - line[0].coord.z = -40; - line[0].coord.x = x; - line[1].color = Gfx::Color(0.7f + x / 120.0f, 0.0f, 0.0f); - line[1].coord.z = 40; - line[1].coord.x = x; - device->DrawPrimitive(Gfx::PRIMITIVE_LINES, line, 2); - } - - for (int z = -40; z <= 40; ++z) - { - line[0].color = Gfx::Color(0.0f, 0.7f + z / 120.0f, 0.0f); - line[0].coord.z = z; - line[0].coord.x = -40; - line[1].color = Gfx::Color(0.0f, 0.7f + z / 120.0f, 0.0f); - line[1].coord.z = z; - line[1].coord.x = 40; - device->DrawPrimitive(Gfx::PRIMITIVE_LINES, line, 2); - } - - - Gfx::VertexCol quad[6] = { Gfx::VertexCol() }; - - for (int i = 0; i < 6; ++i) - quad[i].color = Gfx::Color(1.0f, 1.0f, 0.0f); - - quad[0].coord = Math::Vector(-1.0f, -1.0f, 0.0f); - quad[1].coord = Math::Vector( 1.0f, -1.0f, 0.0f); - quad[2].coord = Math::Vector( 1.0f, 1.0f, 0.0f); - quad[3].coord = Math::Vector( 1.0f, 1.0f, 0.0f); - quad[4].coord = Math::Vector(-1.0f, 1.0f, 0.0f); - quad[5].coord = Math::Vector(-1.0f, -1.0f, 0.0f); - - Math::LoadTranslationMatrix(worldMat, Math::Vector(40.0f, 2.0f, 40.0f)); - device->SetTransform(Gfx::TRANSFORM_WORLD, worldMat); - - device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLES, quad, 6); - - for (int i = 0; i < 6; ++i) - quad[i].color = Gfx::Color(0.0f, 1.0f, 1.0f); - - Math::LoadTranslationMatrix(worldMat, Math::Vector(-40.0f, 2.0f, -40.0f)); - device->SetTransform(Gfx::TRANSFORM_WORLD, worldMat); - - device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLES, quad, 6); - - for (int i = 0; i < 6; ++i) - quad[i].color = Gfx::Color(1.0f, 0.0f, 1.0f); - - Math::LoadTranslationMatrix(worldMat, Math::Vector(0.0f, 10.0f, 0.0f)); - device->SetTransform(Gfx::TRANSFORM_WORLD, worldMat); - - device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLES, quad, 6); - - device->EndScene(); -} - -void Update() -{ - const float TRANS_SPEED = 6.0f; // units / sec - - GetCurrentTimeStamp(CURR_TIME); - float timeDiff = TimeStampDiff(PREV_TIME, CURR_TIME, STU_SEC); - CopyTimeStamp(PREV_TIME, CURR_TIME); - - Math::Vector incTrans; - - if (KEYMAP[K_Forward]) - incTrans.z = +TRANS_SPEED * timeDiff; - if (KEYMAP[K_Back]) - incTrans.z = -TRANS_SPEED * timeDiff; - if (KEYMAP[K_Right]) - incTrans.x = +TRANS_SPEED * timeDiff; - if (KEYMAP[K_Left]) - incTrans.x = -TRANS_SPEED * timeDiff; - if (KEYMAP[K_Up]) - incTrans.y = +TRANS_SPEED * timeDiff; - if (KEYMAP[K_Down]) - incTrans.y = -TRANS_SPEED * timeDiff; - - Math::Point rotTrans = Math::RotatePoint(-ROTATION.y, Math::Point(incTrans.x, incTrans.z)); - incTrans.x = rotTrans.x; - incTrans.z = rotTrans.y; - TRANSLATION += incTrans; -} - -void KeyboardDown(SDLKey key) -{ - switch (key) - { - case SDLK_w: - KEYMAP[K_Forward] = true; - break; - case SDLK_s: - KEYMAP[K_Back] = true; - break; - case SDLK_d: - KEYMAP[K_Right] = true; - break; - case SDLK_a: - KEYMAP[K_Left] = true; - break; - case SDLK_z: - KEYMAP[K_Down] = true; - break; - case SDLK_x: - KEYMAP[K_Up] = true; - break; - default: - break; - } -} - -void KeyboardUp(SDLKey key) -{ - switch (key) - { - case SDLK_w: - KEYMAP[K_Forward] = false; - break; - case SDLK_s: - KEYMAP[K_Back] = false; - break; - case SDLK_d: - KEYMAP[K_Right] = false; - break; - case SDLK_a: - KEYMAP[K_Left] = false; - break; - case SDLK_z: - KEYMAP[K_Down] = false; - break; - case SDLK_x: - KEYMAP[K_Up] = false; - break; - default: - break; - } -} - -void MouseMove(int x, int y) -{ - Math::Point currentPos(static_cast(x), static_cast(y)); - - static bool first = true; - if (first || (x < 10) || (y < 10) || (x > 790) || (y > 590)) - { - SDL_WarpMouse(400, 300); - MOUSE_POS_BASE.x = 400; - MOUSE_POS_BASE.y = 300; - ROTATION_BASE = ROTATION; - first = false; - return; - } - - ROTATION.y = ROTATION_BASE.y + (static_cast (x - MOUSE_POS_BASE.x) / 800.0f) * Math::PI; - ROTATION.x = ROTATION_BASE.x + (static_cast (y - MOUSE_POS_BASE.y) / 600.0f) * Math::PI; -} - -int main(int argc, char *argv[]) -{ - CLogger logger; - - PREV_TIME = CreateTimeStamp(); - CURR_TIME = CreateTimeStamp(); - - GetCurrentTimeStamp(PREV_TIME); - GetCurrentTimeStamp(CURR_TIME); - - CInstanceManager iMan; - - // Without any error checking, for simplicity - - SDL_Init(SDL_INIT_VIDEO); - - IMG_Init(IMG_INIT_PNG); - - const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo(); - - Uint32 videoFlags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_HWPALETTE; - - if (videoInfo->hw_available) - videoFlags |= SDL_HWSURFACE; - else - videoFlags |= SDL_SWSURFACE; - - if (videoInfo->blit_hw) - videoFlags |= SDL_HWACCEL; - - - SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); - - SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 8); - - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - - SDL_Surface *surface = SDL_SetVideoMode(800, 600, 32, videoFlags); - - - SDL_WM_SetCaption("Transform Test", "Transform Test"); - - //SDL_WM_GrabInput(SDL_GRAB_ON); - SDL_ShowCursor(SDL_DISABLE); - - Gfx::CGLDevice *device = new Gfx::CGLDevice(Gfx::GLDeviceConfig()); - device->Create(); - - Init(device); - - bool done = false; - while (! done) - { - Render(device); - Update(); - - SDL_GL_SwapBuffers(); - - SDL_Event event; - while (SDL_PollEvent(&event)) - { - if (event.type == SDL_QUIT) - { - break; - done = true; - } - else if (event.type == SDL_KEYDOWN) - { - if (event.key.keysym.sym == SDLK_q) - { - done = true; - break; - } - else - KeyboardDown(event.key.keysym.sym); - } - else if (event.type == SDL_KEYUP) - KeyboardUp(event.key.keysym.sym); - else if (event.type == SDL_MOUSEMOTION) - MouseMove(event.motion.x, event.motion.y); - } - - usleep(FRAME_DELAY); - } - - //SDL_WM_GrabInput(SDL_GRAB_OFF); - SDL_ShowCursor(SDL_ENABLE); - - device->Destroy(); - delete device; - - SDL_FreeSurface(surface); - - IMG_Quit(); - - SDL_Quit(); - - DestroyTimeStamp(PREV_TIME); - DestroyTimeStamp(CURR_TIME); - - return 0; -} diff --git a/src/math/test/CMakeLists.txt b/src/math/test/CMakeLists.txt deleted file mode 100644 index e31260c..0000000 --- a/src/math/test/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -cmake_minimum_required(VERSION 2.8) - -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE debug) -endif(NOT CMAKE_BUILD_TYPE) -set(CMAKE_CXX_FLAGS_DEBUG "-g -O0") - -include_directories( -. -../.. -../../.. -${GTEST_INCLUDE_DIR} -) - -add_executable(matrix_test matrix_test.cpp) -target_link_libraries(matrix_test gtest) - -add_executable(vector_test vector_test.cpp) -target_link_libraries(vector_test gtest) - -add_executable(geometry_test geometry_test.cpp) -target_link_libraries(geometry_test gtest) - -add_test(matrix_test matrix_test) -add_test(vector_test vector_test) -add_test(geometry_test geometry_test) diff --git a/src/math/test/gendata.m b/src/math/test/gendata.m deleted file mode 100644 index 5c13491..0000000 --- a/src/math/test/gendata.m +++ /dev/null @@ -1,86 +0,0 @@ -% Script in Octave for generating test data - -1; - -% Returns the minor matrix -function m = minor(A, r, c) - - m = A; - m(r,:) = []; - m(:,c) = []; - -end; - -% Returns the cofactor matrix -function m = cofactors(A) - - m = zeros(rows(A), columns(A)); - - for r = [1 : rows(A)] - for c = [1 : columns(A)] - m(r, c) = det(minor(A, r, c)); - if (mod(r + c, 2) == 1) - m(r, c) = -m(r, c); - end; - end; - end; - -end; - -% Prints the matrix as C++ code -function printout(A, name) - - printf('const float %s[16] = \n', name); - printf('{\n'); - - for c = [1 : columns(A)] - for r = [1 : rows(A)] - printf(' %f', A(r,c)); - if (! ( (r == 4) && (c == 4) ) ) - printf(','); - end; - printf('\n'); - end; - end; - - printf('};\n'); - -end; - -printf('// Cofactors\n'); -A = randn(4,4); -printout(A, 'COF_MAT'); -printf('\n'); -printout(cofactors(A), 'COF_RESULT'); -printf('\n'); - -printf('\n'); - -printf('// Det\n'); -A = randn(4,4); -printout(A, 'DET_MAT'); -printf('\n'); -printf('const float DET_RESULT = %f;', det(A)); -printf('\n'); - -printf('\n'); - -printf('// Invert\n'); -A = randn(4,4); -printout(A, 'INV_MAT'); -printf('\n'); -printout(inv(A), 'COF_RESULT'); -printf('\n'); - -printf('\n'); - -printf('// Multiplication\n'); -A = randn(4,4); -printout(A, 'MUL_A'); -printf('\n'); -B = randn(4,4); -printout(B, 'MUL_B'); -printf('\n'); -C = A * B; -printout(C, 'MUL_RESULT'); -printf('\n'); diff --git a/src/math/test/geometry_test.cpp b/src/math/test/geometry_test.cpp deleted file mode 100644 index 8b83b8d..0000000 --- a/src/math/test/geometry_test.cpp +++ /dev/null @@ -1,359 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2012, Polish Portal of Colobot (PPC) -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/. - -// math/test/geometry_test.cpp - -/* Unit tests for functions in geometry.h */ - -#include "../func.h" -#include "../geometry.h" - -#include "gtest/gtest.h" - - -const float TEST_TOLERANCE = 1e-5; - - -// Test for rewritten function RotateAngle() -TEST(GeometryTest, RotateAngleTest) -{ - EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(0.0f, 0.0f), 0.0f, TEST_TOLERANCE)); - - EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(1.0f, 0.0f), 0.0f, TEST_TOLERANCE)); - - EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(1.0f, 1.0f), 0.25f * Math::PI, TEST_TOLERANCE)); - - EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(0.0f, 2.0f), 0.5f * Math::PI, TEST_TOLERANCE)); - - EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(-0.5f, 0.5f), 0.75f * Math::PI, TEST_TOLERANCE)); - - EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(-1.0f, 0.0f), Math::PI, TEST_TOLERANCE)); - - EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(-1.0f, -1.0f), 1.25f * Math::PI, TEST_TOLERANCE)); - - EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(0.0f, -2.0f), 1.5f * Math::PI, TEST_TOLERANCE)); - - EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(1.0f, -1.0f), 1.75f * Math::PI, TEST_TOLERANCE)); -} - -// Tests for other altered, complex or uncertain functions - -/* - - TODO: write meaningful tests with proper test values - -int TestAngle() -{ - const Math::Vector u(-0.0786076246943884, 0.2231249091714256, -1.1601361718477805); - const Math::Vector v(-1.231228742001907, -1.720549809950561, -0.690468438834111); - - float mathResult = Math::Angle(u, v); - float oldMathResult = Angle(VEC_TO_D3DVEC(u), VEC_TO_D3DVEC(v)); - - if (! Math::IsEqual(mathResult, oldMathResult, TEST_TOLERANCE) ) - return __LINE__; - - return 0; -} - -int TestRotateView() -{ - const Math::Vector center(0.617909142705555, 0.896939729454538, -0.615041943652284); - const float angleH = 44.5; - const float angleV = 12.3; - const float dist = 34.76; - - Math::Vector mathResult = Math::RotateView(center, angleH, angleV, dist); - Math::Vector oldMathResult = D3DVEC_TO_VEC(RotateView(VEC_TO_D3DVEC(center), angleH, angleV, dist)); - - if (! Math::VectorsEqual(mathResult, oldMathResult, TEST_TOLERANCE)) - return __LINE__; - - return 0; -} - -int TestLookatPoint() -{ - const Math::Vector eye(-2.451183170579471, 0.241270270546559, -0.490677411454893); - const float angleH = 48.4; - const float angleV = 32.4; - const float length = 74.44; - - Math::Vector mathResult = Math::LookatPoint(eye, angleH, angleV, length); - Math::Vector oldMathResult = D3DVEC_TO_VEC(LookatPoint(VEC_TO_D3DVEC(eye), angleH, angleV, length)); - - if (! Math::VectorsEqual(mathResult, oldMathResult, TEST_TOLERANCE)) - return __LINE__; - - return 0; -} - -int TestProjection() -{ - const Math::Vector a(0.852064846846319, -0.794279497087496, -0.655779805476688); - const Math::Vector b(-0.245838834102304, -0.841115596038861, 0.470457161487799); - const Math::Vector p(2.289326061164255, -0.505511362271196, 0.660204551169491); - - Math::Vector mathResult = Math::Projection(a, b, p); - Math::Vector oldMathResult = D3DVEC_TO_VEC(Projection(VEC_TO_D3DVEC(a), VEC_TO_D3DVEC(b), VEC_TO_D3DVEC(p))); - - if (! Math::VectorsEqual(mathResult, oldMathResult, TEST_TOLERANCE)) - return __LINE__; - - return 0; -} - -int TestLoadViewMatrix() -{ - const Math::Vector from(2.5646013154868874, -0.6058794133917031, -0.0441195127419744); - const Math::Vector at(0.728044925765569, -0.206343977871841, 2.543158236935463); - const Math::Vector worldUp(-1.893738133660711, -1.009584441407070, 0.521745988225582); - - Math::Matrix mathResult; - Math::LoadViewMatrix(mathResult, from, at, worldUp); - - Math::Matrix oldMathResult; - { - D3DMATRIX mat; - D3DVECTOR fromD3D = VEC_TO_D3DVEC(from); - D3DVECTOR atD3D = VEC_TO_D3DVEC(at); - D3DVECTOR worldUpD3D = VEC_TO_D3DVEC(worldUp); - D3DUtil_SetViewMatrix(mat, fromD3D, atD3D, worldUpD3D); - oldMathResult = D3DMAT_TO_MAT(mat); - } - - if (! Math::MatricesEqual(mathResult, oldMathResult, TEST_TOLERANCE)) - return __LINE__; - - return 0; -} - -int TestLoadProjectionMatrix() -{ - const float fov = 76.3f; - const float aspect = 0.891f; - const float nearPlane = 12.3f; - const float farPlane = 1238.9f; - - Math::Matrix mathResult; - Math::LoadProjectionMatrix(mathResult, fov, aspect, nearPlane, farPlane); - - Math::Matrix oldMathResult; - { - D3DMATRIX mat; - D3DUtil_SetProjectionMatrix(mat, fov, aspect, nearPlane, farPlane); - oldMathResult = D3DMAT_TO_MAT(mat); - } - - if (! Math::MatricesEqual(mathResult, oldMathResult, TEST_TOLERANCE)) - return __LINE__; - - return 0; -} - -int TestLoadTranslationMatrix() -{ - const Math::Vector translation(-0.3631590720995237, 1.6976327614875211, 0.0148815191502145); - - Math::Matrix mathResult; - Math::LoadTranslationMatrix(mathResult, translation); - - Math::Matrix oldMathResult; - { - D3DMATRIX mat; - D3DUtil_SetTranslateMatrix(mat, translation.x, translation.y, translation.z); - oldMathResult = D3DMAT_TO_MAT(mat); - } - - if (! Math::MatricesEqual(mathResult, oldMathResult, TEST_TOLERANCE)) - return __LINE__; - - return 0; -} - -int TestLoadScaleMatrix() -{ - const Math::Vector scale(0.612236460285503, -0.635566935025364, -0.254321375332065); - - Math::Matrix mathResult; - Math::LoadScaleMatrix(mathResult, scale); - - Math::Matrix oldMathResult; - { - D3DMATRIX mat; - D3DUtil_SetScaleMatrix(mat, scale.x, scale.y, scale.z); - oldMathResult = D3DMAT_TO_MAT(mat); - } - - if (! Math::MatricesEqual(mathResult, oldMathResult, TEST_TOLERANCE)) - return __LINE__; - - return 0; -} - -int TestLoadRotationXMatrix() -{ - const float angle = 0.513790685774275; - - Math::Matrix mathResult; - Math::LoadRotationXMatrix(mathResult, angle); - - Math::Matrix oldMathResult; - { - D3DMATRIX mat; - D3DUtil_SetRotateXMatrix(mat, angle); - oldMathResult = D3DMAT_TO_MAT(mat); - } - - if (! Math::MatricesEqual(mathResult, oldMathResult, TEST_TOLERANCE)) - return __LINE__; - - return 0; -} - -int TestLoadRotationYMatrix() -{ - const float angle = -0.569166650127303; - - Math::Matrix mathResult; - Math::LoadRotationYMatrix(mathResult, angle); - - Math::Matrix oldMathResult; - { - D3DMATRIX mat; - D3DUtil_SetRotateYMatrix(mat, angle); - oldMathResult = D3DMAT_TO_MAT(mat); - } - - if (! Math::MatricesEqual(mathResult, oldMathResult, TEST_TOLERANCE)) - return __LINE__; - - return 0; -} - -int TestLoadRotationZMatrix() -{ - const float angle = 0.380448034347452; - - Math::Matrix mathResult; - Math::LoadRotationZMatrix(mathResult, angle); - - Math::Matrix oldMathResult; - { - D3DMATRIX mat; - D3DUtil_SetRotateZMatrix(mat, angle); - oldMathResult = D3DMAT_TO_MAT(mat); - } - - if (! Math::MatricesEqual(mathResult, oldMathResult, TEST_TOLERANCE)) - return __LINE__; - - return 0; -} - -int TestLoadRotationMatrix() -{ - const float angle = -0.987747190637790; - const Math::Vector dir(-0.113024727688331, -0.781265998072571, 1.838972397076884); - - Math::Matrix mathResult; - Math::LoadRotationMatrix(mathResult, dir, angle); - - Math::Matrix oldMathResult; - { - D3DMATRIX mat; - D3DVECTOR dirD3D = VEC_TO_D3DVEC(dir); - D3DUtil_SetRotationMatrix(mat, dirD3D, angle); - oldMathResult = D3DMAT_TO_MAT(mat); - } - - if (! Math::MatricesEqual(mathResult, oldMathResult, TEST_TOLERANCE)) - return __LINE__; - - return 0; -} - -int TestLoadRotationXZYMatrix() -{ - const Math::Vector angles(-0.841366567984597, -0.100543315396357, 1.610647811559988); - - Math::Matrix mathResult; - Math::LoadRotationXZYMatrix(mathResult, angles); - - Math::Matrix oldMathResult; - { - D3DMATRIX mat; - MatRotateXZY(mat, VEC_TO_D3DVEC(angles)); - oldMathResult = D3DMAT_TO_MAT(mat); - } - - if (! Math::MatricesEqual(mathResult, oldMathResult, TEST_TOLERANCE)) - return __LINE__; - - return 0; -} - -int TestLoadRotationZXYMatrix() -{ - const Math::Vector angles(0.275558495480206, -0.224328265970090, 0.943077216574253); - - Math::Matrix mathResult; - Math::LoadRotationZXYMatrix(mathResult, angles); - - Math::Matrix oldMathResult; - { - D3DMATRIX mat; - MatRotateZXY(mat, VEC_TO_D3DVEC(angles)); - oldMathResult = D3DMAT_TO_MAT(mat); - } - - if (! Math::MatricesEqual(mathResult, oldMathResult, TEST_TOLERANCE)) - return __LINE__; - - return 0; -} - -int TestTransform() -{ - Math::Matrix transformMatrix( - (float[4][4]) - { - { -0.9282074720977896, 0.6794734970319730, -1.3234304946882685, 0.0925294727863890 }, - { -0.0395527963683484, 0.2897634352353881, 1.9144398570315440, -1.4062267508968478 }, - { 0.9133323625282361, -0.6741836434774530, -0.2188812951424338, -1.0089184339952666 }, - { 0.0f, 0.0f, 0.0f, 1.0f } - } - ); - Math::Vector vector(-0.314596433318370, -0.622681232583150, -0.371307535743574); - - Math::Vector mathResult = Math::Transform(transformMatrix, vector); - Math::Vector oldMathResult = Transform(transformMatrix, vector); - - if (! Math::VectorsEqual(mathResult, oldMathResult, TEST_TOLERANCE)) - return __LINE__; - - return 0; -} - -*/ - - -int main(int argc, char* argv[]) -{ - ::testing::InitGoogleTest(&argc, argv); - - return RUN_ALL_TESTS(); -} diff --git a/src/math/test/matrix_test.cpp b/src/math/test/matrix_test.cpp deleted file mode 100644 index 867e0ec..0000000 --- a/src/math/test/matrix_test.cpp +++ /dev/null @@ -1,322 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2012, Polish Portal of Colobot (PPC) -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/. - -// math/test/matrix_test.cpp - -/* - Unit tests for Matrix struct - - Test data was randomly generated and the expected results - calculated using GNU Octave. - */ - -#include "../func.h" -#include "../matrix.h" - -#include "gtest/gtest.h" - - -const float TEST_TOLERANCE = 1e-6; - - -TEST(MatrixTest, TransposeTest) -{ - const Math::Matrix mat( - (float[4][4]) - { - { -0.07011674491203920, 1.26145596067429810, 2.09476603598066902, 0.35560176915570696 }, - { -1.34075615966224704, 1.17988499016709314, 0.00601713429241016, -0.75213676977972566 }, - { 0.59186722295223981, 0.88089224074765293, 0.70994467464257294, 0.36730385425340212 }, - { -0.95649396555068111, 0.75912182022565566, 1.34883305778387186, -1.34957997578168754 } - } - ); - - const Math::Matrix expectedTranspose( - (float[4][4]) - { - { -0.07011674491203920, -1.34075615966224704, 0.59186722295223981, -0.95649396555068111 }, - { 1.26145596067429810, 1.17988499016709314, 0.88089224074765293, 0.75912182022565566 }, - { 2.09476603598066902, 0.00601713429241016, 0.70994467464257294, 1.34883305778387186 }, - { 0.35560176915570696, -0.75213676977972566, 0.36730385425340212, -1.34957997578168754 } - } - ); - - Math::Matrix transpose = Math::Transpose(mat); - - EXPECT_TRUE(Math::MatricesEqual(transpose, expectedTranspose, TEST_TOLERANCE)); -} - -TEST(MatrixTest, CofactorTest) -{ - const Math::Matrix mat1( - (float[4][4]) - { - { 0.610630320796245, 1.059932357918312, -1.581674311378210, 1.782214448453331 }, - { 0.191028848211526, -0.813898708757524, 1.516114203870644, 0.395202639476002 }, - { 0.335142750345279, -0.346586619596529, 0.545382042472336, -0.879268918923072 }, - { 1.417588151657198, 1.450841789070141, 0.219080104196171, 0.378724047481655 } - } - ); - - const Math::Matrix expectedCofactors1( - (float[4][4]) - { - { -2.402679369186782, 2.282452509293019, 1.722732204057644, -0.746939701104385 }, - { -0.687677756877654, 1.168949180331164, -0.985354966837796, -1.334071111592705 }, - { -5.115621958424845, 4.229724770159009, 2.529000630782808, 1.481632618355891 }, - { 0.147480897398694, -2.140677680337111, -1.207189492265546, 0.151236920408051 } - } - ); - - for (int r = 0; r < 4; ++r) - { - for (int c = 0; c < 4; ++c) - { - float ret = mat1.Cofactor(r, c); - float exp = expectedCofactors1.m[4*c+r]; - EXPECT_TRUE(Math::IsEqual(ret, exp, TEST_TOLERANCE)); - } - } - - const Math::Matrix mat2( - (float[4][4]) - { - { 0.9845099464982393, -0.9091233416532389, -0.6272243714245945, 0.4645001858944354 }, - { -0.1333308471483736, 0.9128181433725897, -1.0937461393836190, 0.3180936795928376 }, - { -0.0654324396846289, 0.1014641705415945, 1.5107709042683430, -0.0240560430414690 }, - { 0.0179638644093347, -1.0695585982782767, -0.1741250853101032, 1.0803106709464336 } - } - ); - - const Math::Matrix expectedCofactors2( - (float[4][4]) - { - { 2.0861102207614466, 0.2989010779528912, 0.0746276150537432, 0.2732659822656097 }, - { 0.6850002886584565, 1.5513169659641379, -0.0503743176545917, 1.5163672441575642 }, - { 1.2385556680997216, 1.1827709562505695, 1.2282813085138962, 1.3483789679871401 }, - { -1.0710790241539783, -0.5589604503588883, 0.0100959837872308, 1.1897872684455839 } - } - ); - - - for (int r = 0; r < 4; ++r) - { - for (int c = 0; c < 4; ++c) - { - float ret = mat2.Cofactor(r, c); - float exp = expectedCofactors2.m[4*c+r]; - EXPECT_TRUE(Math::IsEqual(ret, exp, TEST_TOLERANCE)); - } - } -} - -TEST(MatrixTest, DetTest) -{ - const Math::Matrix mat1( - (float[4][4]) - { - { -0.95880162984708284, 0.24004047608997131, -0.78172309932665407, -0.11604124457222834 }, - { -0.36230592086261376, -0.75778166876017261, 0.33041059404631740, -1.06001391941094836 }, - { 0.00260215210936187, 1.27485610196385113, -0.26149859846418033, -0.59669701186364876 }, - { 0.36899429848485432, 3.01720896813933104, 2.10311476609438719, -1.68627076626448269 } - } - ); - - const float expectedDet1 = 4.07415413729671; - - float ret1 = mat1.Det(); - EXPECT_TRUE(Math::IsEqual(ret1, expectedDet1, TEST_TOLERANCE)); - - const Math::Matrix mat2( - (float[4][4]) - { - { -1.0860073221346871, 0.9150354098189495, -0.2723201933559999, 0.2922832160271507 }, - { -1.0248331304801788, -2.5081237461125205, -1.0277123574586633, -0.2254690663329798 }, - { -1.4227635282899367, -0.0403846809122684, 0.9216148477171653, 1.2517067488015878 }, - { -0.1160254467152022, 0.8270675274393656, 1.0327218739781614, -0.3674886870220400 } - } - ); - - const float expectedDet2 = -6.35122307880942; - - float ret2 = mat2.Det(); - EXPECT_TRUE(Math::IsEqual(ret2, expectedDet2, TEST_TOLERANCE)); -} - -TEST(MatrixTest, InverseTest) -{ - const Math::Matrix mat1( - (float[4][4]) - { - { -2.2829352811514658, -0.9103222363187888, 0.2792976509411680, -0.7984393573193174 }, - { 2.4823665798689589, -0.0599056759070980, 0.3832364352926366, -1.6404257204372739 }, - { -0.3841952272526398, -0.8377700696457873, -0.3416328338427138, 1.1746577275723329 }, - { 0.1746031241954947, -0.4952532117949962, 0.2155084379835037, -1.6586460437329220 } - } - ); - - const Math::Matrix expectedInverse1( - (float[4][4]) - { - { -0.119472603171041, 0.331675963276297, 0.187516809009720, -0.137720814290806 }, - { -0.387591686166085, -0.487284946727583, -0.798527541290274, 0.102991635972060 }, - { 2.601905603425902, 2.606899016264679, -0.528006148839176, -4.204703326522837 }, - { 0.441220327151392, 0.519128136207318, 0.189567009205522, -1.194469716136194 } - } - ); - - Math::Matrix inverse1 = mat1.Inverse(); - - EXPECT_TRUE(Math::MatricesEqual(inverse1, expectedInverse1, TEST_TOLERANCE)); - - const Math::Matrix mat2( - (float[4][4]) - { - { -0.05464332404298505, -0.64357755258235749, -0.13017671677619302, -0.56742332785888006 }, - { 0.29048383600458222, -0.91517047043724875, 0.84517524415561684, 0.51628195547960565 }, - { 0.00946488004480186, -0.89077382212689293, 0.73565573766341397, -0.15932513521840930 }, - { -1.01244718912499132, -0.27840911963972276, -0.39189681211309862, 1.18315064340192055 } - } - ); - - const Math::Matrix expectedInverse2( - (float[4][4]) - { - { 0.771302711132012, 1.587542278361995, -2.003075114445104, -0.592574156227379 }, - { -1.208929259769431, -0.786598967848473, 0.607335305808052, -0.154759693303324 }, - { -1.500037668208218, -0.774300278997914, 1.917800427261255, -0.123268572651291 }, - { -0.121314770937944, 0.916925149209746, -0.935924950785014, 0.260875394250671 } - } - ); - - Math::Matrix inverse2 = mat2.Inverse(); - - EXPECT_TRUE(Math::MatricesEqual(inverse2, expectedInverse2, TEST_TOLERANCE)); -} - -TEST(MatrixTest, MultiplyTest) -{ - const Math::Matrix mat1A( - (float[4][4]) - { - { 0.6561727049162027, -1.4180263627131411, -0.8271026046117423, 2.3919331748512578 }, - { -0.6035665535146352, 0.0150827348790615, -0.7090794192822540, 0.9057604704594814 }, - { -0.9871045001223655, -0.4980646811455065, 0.3806177002298990, 0.1520583649240934 }, - { -0.2721911170792712, 0.7627928194552067, -0.1504091336784158, 0.9747545351840121 } - } - ); - - const Math::Matrix mat1B( - (float[4][4]) - { - { -0.2643735892448818, -0.7542994492819621, 0.6082322350568750, 0.0581733424861419 }, - { 1.0293246070431237, 0.1979285388251341, -0.2932031385332818, 0.8838407179018929 }, - { 0.3448687251553114, 0.5031654871245456, 0.7554693012922442, -0.4845315903845708 }, - { -1.8662838497278593, -0.7843850624747805, 0.1389026096476257, -1.3686415408300689 } - } - ); - - const Math::Matrix expectedMultiply1( - (float[4][4]) - { - { -6.382352236417988, -3.067984733682130, 0.522270304251466, -4.088079444498280 }, - { -1.759853366848825, -0.608994052024491, -0.781406179437379, -0.917870775786188 }, - { -0.404226802169062, 0.718232546720114, -0.145688356880835, -0.890167707987175 }, - { -1.013918490922430, -0.483971504099758, -0.367442194643757, -0.602858486133615 } - } - ); - - Math::Matrix multiply1 = Math::MultiplyMatrices(mat1A, mat1B); - EXPECT_TRUE(Math::MatricesEqual(multiply1, expectedMultiply1, TEST_TOLERANCE)); - - const Math::Matrix mat2A( - (float[4][4]) - { - { 0.8697203025776754, 2.1259475710644935, 1.7856691009707812, -2.1563963348328126 }, - { 1.5888074489288735, -0.0794849733953615, 0.7307782768677457, 0.7943129159612630 }, - { 0.2859761537233830, -0.6231231890384962, -0.0496743172880377, -0.8137857518646087 }, - { 1.2670547229512983, -0.5305171374831831, -0.4987412674062375, -1.1257327113869595 } - } - ); - - const Math::Matrix mat2B( - (float[4][4]) - { - { 1.1321105701165317, 0.1759563504574463, -2.0675778912000418, 1.4840339814245538 }, - { -1.5117280888829916, -0.0933013188828093, -0.2079262944351640, 0.9575727579539316 }, - { 0.3615378398970173, 1.2465163589027248, 1.1326150997082589, 0.9921208694352303 }, - { -0.7357104529373861, -0.4774022005969588, -0.2118739096676499, 1.1427567093270703 } - } - ); - - const Math::Matrix expectedMultiply2( - (float[4][4]) - { - { 0.00283516267056338, 3.21001319965989307, 0.23910503934370686, 2.63380716363006107 }, - { 1.59868505822469742, 0.81869715594617765, -2.60905981088293570, 3.91445839239110294 }, - { 1.84650099286297942, 0.43504079532852930, -0.34555619012424243, -1.15152951542451487 }, - { 2.88434318563174585, 0.18818239851585700, -2.83579436909308980, -0.40890672198610400 } - } - ); - - Math::Matrix multiply2 = Math::MultiplyMatrices(mat2A, mat2B); - EXPECT_TRUE(Math::MatricesEqual(multiply2, expectedMultiply2, TEST_TOLERANCE)); -} - -TEST(MatrixTest, MultiplyVectorTest) -{ - const Math::Matrix mat1( - (float[4][4]) - { - { 0.188562846910008, -0.015148651460679, 0.394512304108827, 0.906910631257135 }, - { -0.297506779519667, 0.940119328178913, 0.970957796752517, 0.310559318965526 }, - { -0.819770525290873, -2.316574438778879, 0.155756069319732, -0.855661405742964 }, - { 0.000000000000000, 0.000000000000000, 0.000000000000000, 1.000000000000000 } - } - ); - - const Math::Vector vec1(-0.824708565156661, -1.598287748103842, -0.422498044734181); - - const Math::Vector expectedMultiply1(0.608932463260470, -1.356893266403749, 3.457156276255142); - - Math::Vector multiply1 = Math::MatrixVectorMultiply(mat1, vec1, false); - EXPECT_TRUE(Math::VectorsEqual(multiply1, expectedMultiply1, TEST_TOLERANCE)); - - const Math::Matrix mat2( - (float[4][4]) - { - { -0.63287117038834284, 0.55148060401816856, -0.02042395559467368, -1.50367083897656850 }, - { 0.69629042156335297, 0.12982747869796774, -1.16250029235919405, 1.19084447253756909 }, - { 0.44164132914357224, -0.15169304045662041, -0.00880583574621390, -0.55817802940035310 }, - { 0.95680476533530789, -1.51912346889253125, -0.74209769406615944, -0.20938988867903682 } - } - ); - - const Math::Vector vec2(0.330987381051962, 1.494375516393466, 1.483422335561857); - - const Math::Vector expectedMultiply2(0.2816820577317669, 0.0334468811767428, 0.1996974284970455); - - Math::Vector multiply2 = Math::MatrixVectorMultiply(mat2, vec2, true); - EXPECT_TRUE(Math::VectorsEqual(multiply2, expectedMultiply2, TEST_TOLERANCE)); -} - -int main(int argc, char* argv[]) -{ - ::testing::InitGoogleTest(&argc, argv); - - return RUN_ALL_TESTS(); -} - diff --git a/src/math/test/vector_test.cpp b/src/math/test/vector_test.cpp deleted file mode 100644 index ead2fd2..0000000 --- a/src/math/test/vector_test.cpp +++ /dev/null @@ -1,81 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2012, Polish Portal of Colobot (PPC) -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/. - -// math/test/vector_test.cpp - -/* - Unit tests for Vector struct - - Test data was randomly generated and the expected results - calculated using GNU Octave. - */ - -#include "../func.h" -#include "../vector.h" - -#include "gtest/gtest.h" - - -const float TEST_TOLERANCE = 1e-6; - - -TEST(VectorTest, LengthTest) -{ - Math::Vector vec(-1.288447945923275, 0.681452565308134, -0.633761098985957); - const float expectedLength = 1.58938001708428; - - EXPECT_TRUE(Math::IsEqual(vec.Length(), expectedLength, TEST_TOLERANCE)); -} - -TEST(VectorTest, NormalizeTest) -{ - Math::Vector vec(1.848877241804398, -0.157262961268577, -1.963031403332377); - const Math::Vector expectedNormalized(0.6844609421393856, -0.0582193085618106, -0.7267212194481797); - - vec.Normalize(); - - EXPECT_TRUE(Math::VectorsEqual(vec, expectedNormalized, TEST_TOLERANCE)); -} - -TEST(VectorTest, DotTest) -{ - Math::Vector vecA(0.8202190530968309, 0.0130926060162780, 0.2411914183883510); - Math::Vector vecB(-0.0524083951404069, 1.5564932716738220, -0.8971342631500536); - - float expectedDot = -0.238988896477326; - - EXPECT_TRUE(Math::IsEqual(Math::DotProduct(vecA, vecB), expectedDot, TEST_TOLERANCE)); -} - -TEST(VectorTest, CrossTest) -{ - Math::Vector vecA(1.37380499798567, 1.18054518384682, 1.95166361293121); - Math::Vector vecB(0.891657855926886, 0.447591335394532, -0.901604070087823); - - Math::Vector expectedCross(-1.937932065431669, 2.978844370287636, -0.437739173833581); - Math::Vector expectedReverseCross = -expectedCross; - - EXPECT_TRUE(Math::VectorsEqual(vecA.CrossMultiply(vecB), expectedCross, TEST_TOLERANCE)); - - EXPECT_TRUE(Math::VectorsEqual(vecB.CrossMultiply(vecA), expectedReverseCross, TEST_TOLERANCE)); -} - -int main(int argc, char* argv[]) -{ - ::testing::InitGoogleTest(&argc, argv); - - return RUN_ALL_TESTS(); -} diff --git a/src/ui/test/CMakeLists.txt b/src/ui/test/CMakeLists.txt deleted file mode 100644 index 452df43..0000000 --- a/src/ui/test/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -cmake_minimum_required(VERSION 2.8) - -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE debug) -endif(NOT CMAKE_BUILD_TYPE) -set(CMAKE_CXX_FLAGS_DEBUG "-g -O0") - -include_directories( -. -../.. -../../.. -${GTEST_INCLUDE_DIR} -${GMOCK_INCLUDE_DIR} -) - - -add_executable(edit_test - ../../common/event.cpp - ../../common/logger.cpp - ../../common/misc.cpp - ../../common/iman.cpp - ../../common/stringutils.cpp - ../../graphics/engine/text.cpp - ../button.cpp - ../control.cpp - ../edit.cpp - ../scroll.cpp - stubs/app_stub.cpp - stubs/engine_stub.cpp - stubs/particle_stub.cpp - stubs/restext_stub.cpp - stubs/robotmain_stub.cpp - edit_test.cpp) -target_link_libraries(edit_test gtest gmock ${SDL_LIBRARY} ${SDLTTF_LIBRARY} ${Boost_LIBRARIES}) - -add_test(edit_test ./edit_test) diff --git a/src/ui/test/edit_test.cpp b/src/ui/test/edit_test.cpp deleted file mode 100644 index 489b873..0000000 --- a/src/ui/test/edit_test.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include "../edit.h" -#include "../../app/app.h" -#include "mocks/text_mock.h" -#include -#include -#include - -class CEditTest : public testing::Test -{ -public: - CEditTest(){}; - - virtual void SetUp() - { - m_engine = new Gfx::CEngine(&m_iMan, NULL); - - m_iMan.AddInstance(CLASS_ENGINE, m_engine); - m_edit = new Ui::CEdit; - } - - virtual void TearDown() - { - m_iMan.DeleteInstance(CLASS_ENGINE, m_engine); - delete m_engine; - m_engine = NULL; - delete m_edit; - m_edit = NULL; - - } - virtual ~CEditTest() - { - - }; - -protected: - CInstanceManager m_iMan; - CApplication m_app; - Gfx::CEngine * m_engine; - Ui::CEdit * m_edit; - CLogger m_logger; -}; - -using ::testing::_; -using ::testing::Return; - -TEST_F(CEditTest, WriteTest) -{ - ASSERT_TRUE(true); - CTextMock * text = dynamic_cast(m_engine->GetText()); - EXPECT_CALL(*text, GetCharWidth(_, _, _, _)).WillRepeatedly(Return(1.0f)); - EXPECT_CALL(*text, GetStringWidth(_, _, _)).WillOnce(Return(1.0f)); - std::string filename = "test.file"; - m_edit->SetMaxChar(Ui::EDITSTUDIOMAX); - m_edit->SetAutoIndent(true); - std::string inputScript = "{\ntext1\ntext2\n\ntext3\n{\ntext4\n}\n}"; - std::string expectedScript = "{\r\n\ttext1\r\n\ttext2\r\n\t\r\n\ttext3\r\n\t{\r\n\t\ttext4\r\n\t}\r\n}"; - m_edit->SetText(inputScript.c_str(), true); - GetLogger()->Info("Writing text \n"); - m_edit->WriteText("script.txt"); - - std::fstream scriptFile; - - scriptFile.open("script.txt", std::ios_base::binary | std::ios_base::in); - std::string outputScript((std::istreambuf_iterator(scriptFile)), std::istreambuf_iterator()); - ASSERT_STREQ(expectedScript.c_str(), outputScript.c_str()); -} - -int main(int argc, char *argv[]) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} - diff --git a/src/ui/test/mocks/text_mock.h b/src/ui/test/mocks/text_mock.h deleted file mode 100644 index 59a6c48..0000000 --- a/src/ui/test/mocks/text_mock.h +++ /dev/null @@ -1,21 +0,0 @@ -#include "../../graphics/engine/text.h" -#include -#include "../../common/logger.h" - - -class CTextMock : public Gfx::CText -{ -public: - CTextMock(CInstanceManager *iMan, Gfx::CEngine* engine) : CText(iMan, engine) - { - } - - virtual ~CTextMock() - { - }; - - MOCK_METHOD4(GetCharWidth, float(Gfx::UTF8Char, Gfx::FontType, float, float)); - MOCK_METHOD3(GetStringWidth, float(const std::string &, Gfx::FontType, float)); - -}; - diff --git a/src/ui/test/stubs/app_stub.cpp b/src/ui/test/stubs/app_stub.cpp deleted file mode 100644 index 5dd79e4..0000000 --- a/src/ui/test/stubs/app_stub.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "../../app/app.h" -#include "../../graphics/opengl/gldevice.h" - -template<> CApplication* CSingleton::mInstance = nullptr; - -namespace Gfx { - -GLDeviceConfig::GLDeviceConfig() -{ -} - -} /* Gfx */ -CApplication::CApplication() -{ -} - -CApplication::~CApplication() -{ -} - -std::string CApplication::GetDataFilePath(DataDir /* dataDir */, const std::string& subpath) -{ - return subpath; -} - - diff --git a/src/ui/test/stubs/engine_stub.cpp b/src/ui/test/stubs/engine_stub.cpp deleted file mode 100644 index 6ec6006..0000000 --- a/src/ui/test/stubs/engine_stub.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#include "../../graphics/engine/engine.h" -#include "../../graphics/engine/text.h" -#include "../mocks/text_mock.h" - -namespace Gfx { - -CEngine::CEngine(CInstanceManager* iMan, CApplication* app) : - m_iMan(iMan), m_app(app) -{ - m_text = new CTextMock(m_iMan, this); - m_text->Create(); -} - -CEngine::~CEngine() -{ - delete m_text; - m_text = NULL; -} - -Math::Point CEngine::WindowToInterfaceSize(Math::IntPoint size) -{ - return Math::Point(size.x, size.y); -} - -void CEngine::SetState(int state, const Color& color) -{ - if (state == m_lastState && color == m_lastColor) - return; - - m_lastState = state; - m_lastColor = color; -} - -Math::IntPoint CEngine::GetWindowSize() -{ - return m_size; -} - -void CEngine::AddStatisticTriangle(int count) -{ - m_statisticTriangle += count; -} - -void CEngine::SetMouseType(EngineMouseType type) -{ - m_mouseType = type; -} - -bool CEngine::SetTexture(const std::string& /* name */, int /* stage */) -{ - return true; -} - -CText* CEngine::GetText() -{ - return m_text; -} - -CDevice* CEngine::GetDevice() -{ - return m_device; -} - -int CEngine::GetEditIndentValue() -{ - return m_editIndentValue; -} - -void CEngine::DeleteTexture(const std::string& /* texName */) -{ -} -Texture CEngine::LoadTexture(const std::string& /* name */) -{ - Texture texture; - return texture; -} - -} /* Gfx */ - diff --git a/src/ui/test/stubs/particle_stub.cpp b/src/ui/test/stubs/particle_stub.cpp deleted file mode 100644 index 41f07cc..0000000 --- a/src/ui/test/stubs/particle_stub.cpp +++ /dev/null @@ -1,291 +0,0 @@ -#include "graphics/engine/particle.h" - -#include "common/logger.h" - - -// Graphics module namespace -namespace Gfx { - - -CParticle::CParticle(CInstanceManager* iMan, CEngine* engine) -{ - GetLogger()->Trace("CParticle::CParticle() stub!\n"); - // TODO! -} - -CParticle::~CParticle() -{ - GetLogger()->Trace("CParticle::~CParticle() stub!\n"); - // TODO! -} - -void CParticle::SetDevice(CDevice* device) -{ - GetLogger()->Trace("CParticle::SetDevice() stub!\n"); - // TODO! -} - -void CParticle::FlushParticle() -{ - GetLogger()->Trace("CParticle::FlushParticle() stub!\n"); - // TODO! -} - -void CParticle::FlushParticle(int sheet) -{ - GetLogger()->Trace("CParticle::FlushParticle() stub!\n"); - // TODO! -} - -int CParticle::CreateParticle(Math::Vector pos, Math::Vector speed, Math::Point dim, - ParticleType type, float duration, float mass, - float windSensitivity, int sheet) -{ - GetLogger()->Trace("CParticle::CreateParticle() stub!\n"); - // TODO! - return 0; -} - -int CParticle::CreateFrag(Math::Vector pos, Math::Vector speed, EngineTriangle *triangle, - ParticleType type, float duration, float mass, - float windSensitivity, int sheet) -{ - GetLogger()->Trace("CParticle::CreateFrag() stub!\n"); - // TODO! - return 0; -} - -int CParticle::CreatePart(Math::Vector pos, Math::Vector speed, ParticleType type, - float duration, float mass, float weight, - float windSensitivity, int sheet) -{ - GetLogger()->Trace("CParticle::CreatePart() stub!\n"); - // TODO! - return 0; -} - -int CParticle::CreateRay(Math::Vector pos, Math::Vector goal, ParticleType type, Math::Point dim, - float duration, int sheet) -{ - GetLogger()->Trace("CParticle::CreateRay() stub!\n"); - // TODO! - return 0; -} - -int CParticle::CreateTrack(Math::Vector pos, Math::Vector speed, Math::Point dim, ParticleType type, - float duration, float mass, float length, float width) -{ - GetLogger()->Trace("CParticle::CreateTrack() stub!\n"); - // TODO! - return 0; -} - -void CParticle::CreateWheelTrace(const Math::Vector &p1, const Math::Vector &p2, const Math::Vector &p3, - const Math::Vector &p4, ParticleType type) -{ - GetLogger()->Trace("CParticle::CreateWheelTrace() stub!\n"); - // TODO! -} - -void CParticle::DeleteParticle(ParticleType type) -{ - GetLogger()->Trace("CParticle::DeleteParticle() stub!\n"); - // TODO! -} - -void CParticle::DeleteParticle(int channel) -{ - GetLogger()->Trace("CParticle::DeleteParticle() stub!\n"); - // TODO! -} - -void CParticle::SetObjectLink(int channel, CObject *object) -{ - GetLogger()->Trace("CParticle::SetObjectLink() stub!\n"); - // TODO! -} - -void CParticle::SetObjectFather(int channel, CObject *object) -{ - GetLogger()->Trace("CParticle::SetObjectFather() stub!\n"); - // TODO! -} - -void CParticle::SetPosition(int channel, Math::Vector pos) -{ - GetLogger()->Trace("CParticle::SetPosition() stub!\n"); - // TODO! -} - -void CParticle::SetDimension(int channel, Math::Point dim) -{ - GetLogger()->Trace("CParticle::SetDimension() stub!\n"); - // TODO! -} - -void CParticle::SetZoom(int channel, float zoom) -{ - GetLogger()->Trace("CParticle::SetZoom() stub!\n"); - // TODO! -} - -void CParticle::SetAngle(int channel, float angle) -{ - GetLogger()->Trace("CParticle::SetAngle() stub!\n"); - // TODO! -} - -void CParticle::SetIntensity(int channel, float intensity) -{ - GetLogger()->Trace("CParticle::SetIntensity() stub!\n"); - // TODO! -} - -void CParticle::SetParam(int channel, Math::Vector pos, Math::Point dim, float zoom, float angle, float intensity) -{ - GetLogger()->Trace("CParticle::SetParam() stub!\n"); - // TODO! -} - -void CParticle::SetPhase(int channel, ParticlePhase phase, float duration) -{ - GetLogger()->Trace("CParticle::SetPhase() stub!\n"); - // TODO! -} - -bool CParticle::GetPosition(int channel, Math::Vector &pos) -{ - GetLogger()->Trace("CParticle::GetPosition() stub!\n"); - // TODO! - return true; -} - -Color CParticle::GetFogColor(Math::Vector pos) -{ - GetLogger()->Trace("CParticle::GetFogColor() stub!\n"); - // TODO! - return Color(); -} - -void CParticle::SetFrameUpdate(int sheet, bool update) -{ - GetLogger()->Trace("CParticle::SetFrameUpdate() stub!\n"); - // TODO! -} - -void CParticle::FrameParticle(float rTime) -{ - GetLogger()->Trace("CParticle::FrameParticle() stub!\n"); - // TODO! -} - -void CParticle::DrawParticle(int sheet) -{ - GetLogger()->Trace("CParticle::DrawParticle() stub!\n"); - // TODO! -} - -bool CParticle::WriteWheelTrace(const char *filename, int width, int height, Math::Vector dl, Math::Vector ur) -{ - GetLogger()->Trace("CParticle::WriteWheelTrace() stub!\n"); - // TODO! - return true; -} - -void CParticle::DeleteRank(int rank) -{ - GetLogger()->Trace("CParticle::DeleteRank() stub!\n"); - // TODO! -} - -bool CParticle::CheckChannel(int &channel) -{ - GetLogger()->Trace("CParticle::CheckChannel() stub!\n"); - // TODO! - return true; -} - -void CParticle::DrawParticleTriangle(int i) -{ - GetLogger()->Trace("CParticle::DrawParticleTriangle() stub!\n"); - // TODO! -} - -void CParticle::DrawParticleNorm(int i) -{ - GetLogger()->Trace("CParticle::DrawParticleNorm() stub!\n"); - // TODO! -} - -void CParticle::DrawParticleFlat(int i) -{ - GetLogger()->Trace("CParticle::DrawParticleFlat() stub!\n"); - // TODO! -} - -void CParticle::DrawParticleFog(int i) -{ - GetLogger()->Trace("CParticle::DrawParticleFog() stub!\n"); - // TODO! -} - -void CParticle::DrawParticleRay(int i) -{ - GetLogger()->Trace("CParticle::DrawParticleRay() stub!\n"); - // TODO! -} - -void CParticle::DrawParticleSphere(int i) -{ - GetLogger()->Trace("CParticle::DrawParticleSphere() stub!\n"); - // TODO! -} - -void CParticle::DrawParticleCylinder(int i) -{ - GetLogger()->Trace("CParticle::DrawParticleCylinder() stub!\n"); - // TODO! -} - -void CParticle::DrawParticleWheel(int i) -{ - GetLogger()->Trace("CParticle::DrawParticleWheel() stub!\n"); - // TODO! -} - -CObject* CParticle::SearchObjectGun(Math::Vector old, Math::Vector pos, ParticleType type, CObject *father) -{ - GetLogger()->Trace("CParticle::SearchObjectGun() stub!\n"); - // TODO! - return nullptr; -} - -CObject* CParticle::SearchObjectRay(Math::Vector pos, Math::Vector goal, ParticleType type, CObject *father) -{ - GetLogger()->Trace("CParticle::SearchObjectRay() stub!\n"); - // TODO! - return nullptr; -} - -void CParticle::Play(Sound sound, Math::Vector pos, float amplitude) -{ - GetLogger()->Trace("CParticle::Play() stub!\n"); - // TODO! -} - -bool CParticle::TrackMove(int i, Math::Vector pos, float progress) -{ - GetLogger()->Trace("CParticle::TrackMove() stub!\n"); - // TODO! - return true; -} - -void CParticle::TrackDraw(int i, ParticleType type) -{ - GetLogger()->Trace("CParticle::TrackDraw() stub!\n"); - // TODO! -} - - -} // namespace Gfx - diff --git a/src/ui/test/stubs/restext_stub.cpp b/src/ui/test/stubs/restext_stub.cpp deleted file mode 100644 index c1986ca..0000000 --- a/src/ui/test/stubs/restext_stub.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "../../common/restext.h" -bool GetResource(ResType /* type */, int /* num */, char* /* text */) -{ - return true; -} - -bool SearchKey(const char * /* cmd */, InputSlot & /* key */) -{ - return true; -} - diff --git a/src/ui/test/stubs/robotmain_stub.cpp b/src/ui/test/stubs/robotmain_stub.cpp deleted file mode 100644 index 93e0e82..0000000 --- a/src/ui/test/stubs/robotmain_stub.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "../../object/robotmain.h" - - -template<> CRobotMain* CSingleton::mInstance = nullptr; - -bool CRobotMain::GetGlint() -{ - return false; -} - -const InputBinding& CRobotMain::GetInputBinding(InputSlot slot) -{ - unsigned int index = static_cast(slot); - assert(index >= 0 && index < INPUT_SLOT_MAX); - return m_inputBindings[index]; -} - diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..2618698 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,13 @@ +# Compile flags as defined in global CMakeLists +set(CMAKE_CXX_FLAGS "${COLOBOT_CXX_FLAGS} ${MXE_CFLAGS}") +set(CMAKE_CXX_FLAGS_RELEASE ${COLOBOT_CXX_FLAGS_RELEASE}) +set(CMAKE_CXX_FLAGS_DEBUG ${COLOBOT_CXX_FLAGS_DEBUG}) + +# CBot utils +add_subdirectory(cbot) + +# Unit tests +add_subdirectory(unit) + +# Test environments +add_subdirectory(envs) diff --git a/test/cbot/CBot_console/CBotConsole.cpp b/test/cbot/CBot_console/CBotConsole.cpp new file mode 100644 index 0000000..e9209d3 --- /dev/null +++ b/test/cbot/CBot_console/CBotConsole.cpp @@ -0,0 +1,175 @@ +/* + * CBotConsole.cpp + * + * Created on: 08-08-2012 + * Author: michal + */ + +#include "CBotConsole.h" +#include "CClass.h" +#include +#include + +CBotConsole::CBotConsole() { + // TODO Auto-generated constructor stub + m_pProg = NULL; + m_threadinfo.m_bRun = false; + m_code = 0; + +} + +CBotConsole::~CBotConsole() { + // TODO Auto-generated destructor stub +} + +uint ThreadProc(ThreadInfo *info) +{ + time_t t0,t1; + time(&t0); + + int Cpt = 0; + + info->m_pProg->Start("LaCommande"); + while ( !info->m_bStop && !info->m_pProg->Run() ) + { +#if 0 + const char* FunctionName; + const char* FN; + int start, end; + + info->m_pProg->GetRunPos(FunctionName, start, end); + + if ( FunctionName != NULL ) + { + info->m_pEditx->SetSel(start, end); + + char buffer[200]; + sprintf( buffer, "step %s, %d, %d",FunctionName, start, end); + AfxMessageBox( buffer ); + + int level = 0; + do + { + CBotVar* t = info->m_pProg->GetStackVars(FN, level--); + if ( FN != FunctionName ) break; + if ( t != NULL ) + { + CString s ; + while ( t != NULL ) + { + if (s.IsEmpty()) s+= "Stack -> "; + else s+= " , "; + s += t->GetValString(); + t = t->GetNext(); + } + AfxMessageBox(s); + } + } while (TRUE); + } +#endif + Cpt++; + if ( Cpt%50 == 0 ) std::cout << "."; + } + + if ( info->m_bStop ) + { + std::cout << "\nInterrupt\n"; + } + else if (info->m_pProg->GetError() == 0) + { + time(&t1); + double prog_time = difftime(t0,t1); + + char buffer[200]; + sprintf( buffer, "\nExecution terminated in %f seconds.\nInterrupted %d time(s).\n", + prog_time, Cpt); + + std::cout << buffer; + } + +// info->m_pWndMessage->SendMessage(WM_ENDPROG, 0, 0) ; + return 0 ; +} + +long CBotConsole::EndProg() +{ + m_threadinfo.m_bRun = false; + + if (m_pProg->GetError(m_code, m_start, m_end)) + { + CBotString TextError; + TextError = CBotProgram::GetErrorText(m_code); + std::cout << TextError; + return 1; + } + delete m_pProg; + m_pProg = NULL; + + return 0 ; +} + + +void CBotConsole::OnOK() +{ + m_code = 0; + + std::string Commande; + std::cin >> Commande; + + std::string s = "void LaCommande() { " + Commande + " ;}"; + m_pProg = new CBotProgram(); + CBotStringArray liste; + m_pProg->Compile(s.c_str(), liste); + + int err, start, end; + if ( m_pProg->GetError(err, start, end) ) + { + CBotString TextError; + TextError = CBotProgram::GetErrorText(err); + std::cout << TextError; + return; + } + + std::cout << "\n" + Commande + " ->\n"; + +// m_Edit2.SetWindowText(""); +// m_Edit1.SetFocus(); +// m_Edit2.EnableWindow(FALSE); +// m_cOK.EnableWindow(FALSE); + + // lance un processus paralèle pour l'exécution +// m_threadinfo.m_pWndMessage = this ; + +// m_threadinfo.m_pEdit1 = &m_Edit1; +// m_threadinfo.m_pEditx = m_pEditx; + m_threadinfo.m_pProg = m_pProg; + m_threadinfo.m_bStop = false; + m_threadinfo.m_bRun = true; + + ThreadProc(&m_threadinfo); + +// here program starts +// AfxBeginThread((AFX_THREADPROC)ThreadProc, &m_threadinfo) ; +} + +void CBotConsole::OnCancel() +{ + m_threadinfo.m_bStop = true ; +} + +bool CBotConsole::OnInitDialog() +{ +// CDialog::OnInitDialog(); + + std::cout << "Following functions are availible:\n"; + for ( int i = 0; i < m_pListe->GetSize(); i++ ) + { + CBotString x = (*m_pListe)[i] + CBotString("\n"); + std::cout << x; + } + std::cout << "Enter a command:\n"; + + + return true; // return TRUE unless you set the focus to a control + // EXCEPTION: OCX Property Pages should return FALSE +} diff --git a/test/cbot/CBot_console/CBotConsole.h b/test/cbot/CBot_console/CBotConsole.h new file mode 100644 index 0000000..a155399 --- /dev/null +++ b/test/cbot/CBot_console/CBotConsole.h @@ -0,0 +1,44 @@ +/* + * CBotConsole.h + * + * Created on: 08-08-2012 + * Author: michal + */ + +#ifndef CBOTCONSOLE_H_ +#define CBOTCONSOLE_H_ +#include "CClass.h" + +struct ThreadInfo +{ +// CEdit* m_pEdit1 ; +// CEdit* m_pEditx ; + CBotProgram* m_pProg; +// CWnd* m_pWndMessage; + bool m_bStop; + bool m_bRun; +}; + +class CBotConsole { + +public: + CBotConsole(); + virtual ~CBotConsole(); + +// CEdit m_Edit1; + + CBotProgram* m_pProg; + ThreadInfo m_threadinfo; + + CBotStringArray* m_pListe; + int m_code, m_start, m_end; +// CEdit* m_pEditx; + + // Implementation + void OnOK(); + void OnCancel(); + bool OnInitDialog(); + long EndProg() ; +}; + +#endif /* CBOTCONSOLE_H_ */ diff --git a/test/cbot/CBot_console/CBotDoc.cpp b/test/cbot/CBot_console/CBotDoc.cpp new file mode 100644 index 0000000..1c694c9 --- /dev/null +++ b/test/cbot/CBot_console/CBotDoc.cpp @@ -0,0 +1,122 @@ +/* + * CBotDoc.cpp + * + * Created on: 08-08-2012 + * Author: michal + */ +#include "CBotDoc.h" +#include "CBotConsole.h" +#include + +CBotDoc::CBotDoc(std::string s) { + // TODO Auto-generated constructor stub + // TODO set m_DocText +// m_pEdit = NULL; + m_pProg = NULL; +// m_bModified = FALSE; + m_DocText = s; + std::cout << s << std::endl; +// std::cout << "Enter to continue..." << std::endl; +// getchar(); +} + +CBotDoc::~CBotDoc() { + +// delete m_pEdit; + delete m_pProg; +} + + +//static bool test = false; + +void CBotDoc::OnRun() +{ + +// m_pEdit->GetWindowText(m_DocText); + CBotString s; + + std::string TextError; + int code, start, end; + + if ( m_pProg == NULL ) m_pProg = new CBotProgram(); + + if (!m_pProg->Compile(m_DocText.c_str(), m_Liste, NULL)) + { + m_pProg->GetError(code, start, end); + delete m_pProg; + m_pProg = NULL; + + TextError = CBotProgram::GetErrorText( code ); + std::cout << TextError << std::endl; + return; + } + + if( m_Liste.GetSize() == 0 ) + { + std::cout << "No function marked \"extern\" !\n"; + return; + } + + for ( int i = 0; i < m_Liste.GetSize(); i++ ) + { + int start, stop; + m_pProg->GetPosition(m_Liste[i], start, stop, GetPosNom, GetPosParam); + CBotString s(m_DocText.substr( start, stop-start ).c_str()); + m_Liste[i] = s; + } +// TODO + CBotConsole dlg; + dlg.m_pListe = &m_Liste; +// dlg.m_pEditx = m_pEdit; + + dlg.OnInitDialog(); + dlg.OnOK(); + dlg.EndProg(); +// if ( dlg.m_code>0 ) +// { +// std::string TextError; +// +// TextError = m_pProg->GetErrorText( dlg.m_code ); +// +// std::cout <GetWindowText(m_DocText); + + std::string TextError; + int code, start, end; + + if ( m_pProg == NULL ) m_pProg = new CBotProgram(); + + char buffer[100]; + strcpy(buffer, "a pointer move to see"); + + if (!m_pProg->Compile(m_DocText.c_str(), m_Liste, static_cast(buffer))) + { + m_pProg->GetError(code, start, end); + delete m_pProg; + m_pProg = NULL; + +// m_pEdit->SetSel( start, end ); +// m_pEdit->SetFocus(); // higlights part of problem + + TextError = CBotProgram::GetErrorText( code ); + std::cout << TextError ; + + return false; + } + +// if ( m_pProg->GetPosition( "TheTest", start, end) ) +// { +// m_pEdit->SetSel( start, end ); +// m_pEdit->SetFocus(); // higlights part of problem +// } + +// m_bModified = FALSE; + return true; +} diff --git a/test/cbot/CBot_console/CBotDoc.h b/test/cbot/CBot_console/CBotDoc.h new file mode 100644 index 0000000..c0a3e1d --- /dev/null +++ b/test/cbot/CBot_console/CBotDoc.h @@ -0,0 +1,39 @@ +/* + * CBotDoc.h + * + * Created on: 08-08-2012 + * Author: michal + */ + +#pragma once +#ifndef CBOTDOC_H_ +#define CBOTDOC_H_ + +#include "CClass.h" +#include + +class CBotDoc { + +public: + CBotDoc(std::string); + virtual ~CBotDoc(); + +// CEdit* m_pEdit; // to memorize the text, and display + CBotProgram* m_pProg; // the compiled program + std::string m_DocText; + CBotStringArray m_Liste; + +// Operations + + bool Compile(); + +// virtual bool OnNewDocument(); + + void OnRun(); + void OnChangeEdit1(); + void OnTest(); + +}; + + +#endif /* CBOTDOC_H_ */ diff --git a/test/cbot/CBot_console/CClass.cpp b/test/cbot/CBot_console/CClass.cpp new file mode 100644 index 0000000..9b7c842 --- /dev/null +++ b/test/cbot/CBot_console/CClass.cpp @@ -0,0 +1,97 @@ +#include "CClass.h" + +#include "routines.cpp" + +void rMajObject( CBotVar* pThis, void* pUser ) +{ + if (!pThis->IsElemOfClass("object")) + return ; + CBotVar* pPos = pThis->GetItem("position"); + CBotVar* pX = pPos->GetItem("x"); + CBotVar* pY = pPos->GetItem("y"); + CBotVar* pZ = pPos->GetItem("z"); +// CBotVar* pPt = pThis->GetItem("transport"); + + CBotString p = pX->GetValString(); + +// pX->SetValFloat( pUser == (void*)1 ? (float)12.5 : (float)44.4 ); + pZ->SetValFloat( (float)0 ); + pY->SetValFloat( (float)-3.33 ); + pX->SetValFloat( pX->GetValFloat() + 10 ) ; + +// pX = pThis->GetItem( "xx" ); +// pX->SetValFloat( (float)22 ); + + // crée une instance sur une classe object +// CBotVar* pAutre = CBotVar::Create("autre", CBotTypClass, "object"); +// pAutre->SetUserPtr( (void*)3 ); +// pPt->SetPointer( pAutre ); +// pPt->SetPointer( NULL ); +// delete pAutre; +}; + +CClass::CClass() +{ + m_pClassPoint= NULL; +} + +bool CClass::InitInstance() +{ +////////////////////////////////////////////// +// défini les mots clefs supplémentaires +// ------------------------------------------- + + CBotProgram::Init(); + +////////////////////////////////////////////// +// défini les fonctions "show()" et "print()" +// ------------------------------------------- + + //CBotProgram::AddFunction("show", rShow, cShow); + CBotProgram::AddFunction("print", rPrint, cPrint); + CBotProgram::AddFunction("println", rPrintLn, cPrint); + + +/////////////////////////////////// +// définie la classe globale CPoint +// -------------------------------- + + m_pClassPoint = new CBotClass("CPoint", NULL); + // ajoute le composant ".x" + m_pClassPoint->AddItem("x", CBotTypFloat); + // ajoute le composant ".y" + m_pClassPoint->AddItem("y", CBotTypFloat); + + // ajoute le constructeur pour cette classe + m_pClassPoint->AddFunction("CPoint", rCPoint, cCPoint); + + m_pClassPointIntr = new CBotClass("point", NULL, true); + // ajoute le composant ".x" + m_pClassPointIntr->AddItem("x", CBotTypFloat); + // ajoute le composant ".y" + m_pClassPointIntr->AddItem("y", CBotTypFloat); + // ajoute le composant ".z" + m_pClassPointIntr->AddItem("z", CBotTypFloat); + + // ajoute le constructeur pour cette classe + m_pClassPointIntr->AddFunction("point", rCPoint, cCPoint); + + // défini la classe "object" + CBotClass* pClassObject = new CBotClass( "object", NULL ) ; + pClassObject->AddItem( "xx", CBotTypFloat ); + pClassObject->AddItem( "position", CBotTypResult( CBotTypIntrinsic, "point" ) ); + pClassObject->AddItem( "transport", CBotTypResult( CBotTypPointer, "object" ) ); + pClassObject->AddUpdateFunc( rMajObject ); + + InitClassFILE(); + + return true; +} + +void CClass::ExitInstance() +{ + delete m_pFuncFile; + + CBotProgram::Free(); + +} diff --git a/test/cbot/CBot_console/CClass.h b/test/cbot/CBot_console/CClass.h new file mode 100644 index 0000000..da2c46c --- /dev/null +++ b/test/cbot/CBot_console/CClass.h @@ -0,0 +1,18 @@ +#pragma once + +#include +#include + +extern std::string s; + +class CClass +{ +public: + CClass(); + + CBotClass* m_pClassPoint; + CBotClass* m_pClassPointIntr; + + bool InitInstance(); + void ExitInstance(); +}; diff --git a/test/cbot/CBot_console/CMakeLists.txt b/test/cbot/CBot_console/CMakeLists.txt new file mode 100644 index 0000000..5016a77 --- /dev/null +++ b/test/cbot/CBot_console/CMakeLists.txt @@ -0,0 +1,16 @@ +set(SOURCES +CClass.cpp +main.cpp +CBotDoc.cpp +CBotConsole.cpp +) + +set(LIBS +CBot +) + +include_directories(${colobot_SOURCE_DIR}/src) + +add_executable(CBot_console ${SOURCES}) + +target_link_libraries(CBot_console ${LIBS}) diff --git a/test/cbot/CBot_console/main.cpp b/test/cbot/CBot_console/main.cpp new file mode 100644 index 0000000..a2d3668 --- /dev/null +++ b/test/cbot/CBot_console/main.cpp @@ -0,0 +1,45 @@ +#include "CClass.h" +#include "CBotDoc.h" +#include + + +#include + +std::string str; + +// routine to update the instance of the class Bot common + +int main(int argc, char* argv[]) +{ + CClass newclass; + CBotDoc *botdoc; + if (argc != 2) + { + std::cout << "Usage: "<" << std::endl; + return 0; + } + + std::ifstream in(argv[1]); + std::cout << argv[1] << std::endl; + if (!in.good()) + { + std::cout << "Oh no, error!" << std::endl; + return 1; + } + + std::string contents((std::istreambuf_iterator(in)), + std::istreambuf_iterator()); + str = contents; + + if(!newclass.InitInstance()) + { + std::cerr << "Initialization not complete!" << std::endl; + return 1; + } + + botdoc = new CBotDoc(str); +// std::cout << "Hello CBot!" << std::endl << s; + botdoc->OnRun(); + delete botdoc; + newclass.ExitInstance(); +} diff --git a/test/cbot/CBot_console/routines.cpp b/test/cbot/CBot_console/routines.cpp new file mode 100644 index 0000000..8b8a1d4 --- /dev/null +++ b/test/cbot/CBot_console/routines.cpp @@ -0,0 +1,141 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch +// * +// * This program is free software: you can redistribute it and/or modify +// * it under the terms of the GNU General Public License as published by +// * the Free Software Foundation, either version 3 of the License, or +// * (at your option) any later version. +// * +// * This program is distributed in the hope that it will be useful, +// * but WITHOUT ANY WARRANTY; without even the implied warranty of +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// * GNU General Public License for more details. +// * +// * You should have received a copy of the GNU General Public License +// * along with this program. If not, see http://www.gnu.org/licenses/. + +//////////////////////////////////////////////////////////////////// +// routine show() +// utilisable depuis le programme écrit en CBot + + +#include +#include +#include "CBot/ClassFILE.cpp" +//std::string s; +/* +// execution +bool rShow( CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser ) +{ + string::string s; + + while ( pVar != NULL ) + { + string::string ss; + + ss.LoadString( TX_TYPENAMES + pVar->GetType() ); + s += ss + " "; + + ss = pVar->GetName(); + if (ss.IsEmpty()) ss = ""; + s += ss + " = "; + + s += pVar->GetValString(); + s += "\n"; + pVar = pVar->GetNext(); + } + + AfxMessageBox(s, MB_OK|MB_ICONINFORMATION); + + return TRUE; // pas d'interruption +} + +CBotTypResult cShow( CBotVar* &pVar, void* pUser) +{ + if ( pVar == NULL ) return CBotTypResult(5028); + return CBotTypResult(0); // tous paramètres acceptés, void en retour +} + +*/ + +//////////////////////////////////////////////////////////////////// +// routine print() +// utilisable depuis le programme écrit en CBot + +// exécution + +bool rPrintLn( CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser ) +{ + std::string s; + while ( pVar != NULL ) + { + if ( !s.empty() ) s += " "; + s += pVar->GetValString(); + pVar = pVar->GetNext(); + } + s += "\n"; + + std::cout << s; + return true; // pas d'interruption +} + +bool rPrint( CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser ) +{ + std::string s; + while ( pVar != NULL ) + { + if ( !s.empty() ) s += " "; + s += pVar->GetValString(); + pVar = pVar->GetNext(); + } + s += " "; + std::cout << s; + return true; // pas d'interruption +} + +CBotTypResult cPrint( CBotVar* &pVar, void* pUser) +{ + return CBotTypResult(0); // tous paramètres acceptés, un entier en retour +} + + +////////////////////////////////////////////////////////////////// +// class CPoint pour essayer + +// exécution +bool rCPoint( CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception ) +{ + if ( pVar == NULL )return true; // constructor with no parameters is ok + + CBotVar* pX = pThis->GetItem("x"); + pX->SetValFloat( pVar->GetValFloat() ); + pVar = pVar->GetNext(); + + CBotVar* pY = pThis->GetItem("y"); + pY->SetValFloat( pVar->GetValFloat() ); + pVar = pVar->GetNext(); + + return true; // pas d'interruption +} + +CBotTypResult cCPoint( CBotVar* pThis, CBotVar* &pVar) +{ + // ok if no parameters! + if ( pVar == NULL ) return CBotTypResult(0); + + // numeric type of parameter please + if ( pVar->GetType() > CBotTypDouble ) return CBotTypResult(5011); + pVar = pVar->GetNext(); + + // there must be a second parameter + if ( pVar == NULL ) return 5028; + // also numeric + if ( pVar->GetType() > CBotTypDouble )return CBotTypResult(5011); + pVar = pVar->GetNext(); + + // and not more than 2 parameters please + if ( pVar != NULL ) return CBotTypResult(5026); + + return CBotTypResult(0); // This function returns void +} + diff --git a/test/cbot/CMakeLists.txt b/test/cbot/CMakeLists.txt new file mode 100644 index 0000000..e864ed5 --- /dev/null +++ b/test/cbot/CMakeLists.txt @@ -0,0 +1,2 @@ +# CBot console interpreter +add_subdirectory(CBot_console) diff --git a/test/cbot/scenarios/B.txt b/test/cbot/scenarios/B.txt new file mode 100644 index 0000000..53715f8 --- /dev/null +++ b/test/cbot/scenarios/B.txt @@ -0,0 +1,18 @@ + + float [ ] TEST2 ( int [ ] param ) + { + float [ ] z; + for ( int i = 0 ; i < sizeof( param ) ; i++ ) try { z [i] = param [i] / 3; } + return z; + } + +extern public void T() +{ + int a [4]; + for ( int i = 0 ; i < 3 ; i++ ) a[i] = 4*i; + a [2] = 22; + + float [] b ; + b = TEST2 ( a ) ; + show ( a, b ); +} diff --git a/test/cbot/scenarios/BUG2.txt b/test/cbot/scenarios/BUG2.txt new file mode 100644 index 0000000..44de05a --- /dev/null +++ b/test/cbot/scenarios/BUG2.txt @@ -0,0 +1,107 @@ +object object :: TT ( int n ) +{ + object XX = radar(); + if ( n == 0 ) return null; + + while ( null == XX ) XX = radar(); + return XX; +} + +extern void object::Attack( ) +{ + show ( TT ( 0 ) ) ; + show ( TT ( 1 ) ) ; + return; + + int list[]; + int i; + object p; + float dist, prox; + point dest; + boolean advance = true; + + TEST(0); // ne stoppe pas si erreur +// while ( F () != 0 ) F(1); + + i = 0; + list[i++] = WingedGrabber; + list[i++] = TrackedGrabber; + list[i++] = WheeledGrabber; + list[i++] = LeggedGrabber; + list[i++] = WingedShooter; + list[i++] = TrackedShooter; + list[i++] = WheeledShooter; + list[i++] = LeggedShooter; + list[i++] = WingedOrgaShooter; + list[i++] = TrackedOrgaShooter; + list[i++] = WheeledOrgaShooter; + list[i++] = LeggedOrgaShooter; + list[i++] = WingedSniffer; + list[i++] = TrackedSniffer; + list[i++] = WheeledSniffer; + list[i++] = LeggedSniffer; + list[i++] = Thumper; + list[i++] = PhazerShooter; + list[i++] = Recycler; + list[i++] = Shielder; + list[i++] = Subber; + list[i++] = Me; + list[i++] = 3333; + list[i++] = 3334; + list[i++] = 3335; + list[i++] = 3336; + list[i++] = 3337; + list[i++] = 3338; + list[i++] = 3339; + list[i++] = 3331; + list[i++] = 3332; + list[i++] = 3330; + list[i++] = 1111; + list[i++] = 1112; + + F(F(0)); + + while ( true ) + { + p = radar(list, 0, 360, 0, 1000); + if ( p == null ) + { + F(2); + } + else + { + dist = F(p.position, position); + if ( dist <= 40 && !advance ) + { + fire(p.position); + advance = true; + } + else + { +//? if ( RetBaseDistance() > 20 ) + { + prox = dist-(5+F()*5); + if ( prox < 5 ) prox = 5; + dest.x = (position.x-p.position.x)*prox/dist + p.position.x; + dest.y = (position.y-p.position.y)*prox/dist + p.position.y; + dest.z = (position.z-p.position.z)*prox/dist + p.position.z; + goto(dest); + advance = false; + } + } + } + } +} + +// Calcule la distance jusqu'à la base. + +float object::RetBaseDistance() +{ + object p; + float dist; + + p = radar(4444, 0, 360, 0, 1000); + if ( p == null ) return 1000; + dist = F(p.position, position); + return dist; +} \ No newline at end of file diff --git a/test/cbot/scenarios/Deleted.txt b/test/cbot/scenarios/Deleted.txt new file mode 100644 index 0000000..469a624 --- /dev/null +++ b/test/cbot/scenarios/Deleted.txt @@ -0,0 +1,23 @@ +public extern void object :: ESSAI() +{ + while(true) + { + if ( true ) + { + goto(12); + break; + } + } + object x = null ; + + while ( x == null ) x = radar(); + + show ( x.position ) ; + + TEST(5, x); + + if ( x == null ) show ( "DELETED" ); + + show ( x.position ) ; + +} \ No newline at end of file diff --git a/test/cbot/scenarios/MaClass.txt b/test/cbot/scenarios/MaClass.txt new file mode 100644 index 0000000..ac472b4 --- /dev/null +++ b/test/cbot/scenarios/MaClass.txt @@ -0,0 +1,16 @@ + +class MaClass +{ + int a = 1 ; + MaClass pointeur ; + MaClass next = null ; + CPoint autre = new CPoint( 1 , 1 ) ; +} + +extern public void Test ( ) +{ + MaClass x () ; + x.next = new MaClass ( ) ; + println ( x ) ; +} + diff --git a/test/cbot/scenarios/Mc2.txt b/test/cbot/scenarios/Mc2.txt new file mode 100644 index 0000000..172c259 --- /dev/null +++ b/test/cbot/scenarios/Mc2.txt @@ -0,0 +1,4 @@ +class MaClass +{ + int t = 12; +} diff --git a/test/cbot/scenarios/Mon fichier.txt b/test/cbot/scenarios/Mon fichier.txt new file mode 100644 index 0000000..6b35bf8 --- /dev/null +++ b/test/cbot/scenarios/Mon fichier.txt @@ -0,0 +1,2 @@ +Voici encore du texte +et une seconde ligne diff --git a/test/cbot/scenarios/Nop.txt b/test/cbot/scenarios/Nop.txt new file mode 100644 index 0000000..6a66f6f --- /dev/null +++ b/test/cbot/scenarios/Nop.txt @@ -0,0 +1,4 @@ +public extern void Nop() +{ + while ( true ) {} +} \ No newline at end of file diff --git a/test/cbot/scenarios/POS.txt b/test/cbot/scenarios/POS.txt new file mode 100644 index 0000000..688e4fb --- /dev/null +++ b/test/cbot/scenarios/POS.txt @@ -0,0 +1,14 @@ +void object :: T ( ) +{ + show ( position ) ; +} + +public extern void object :: POS() +{ + for ( int i = 0; i < 10 ; i++ ) + { + if ( i == 2 ) TEST ( 12 ) ; +// show ( position ); + T ( ) ; + } +} \ No newline at end of file diff --git a/test/cbot/scenarios/T.txt b/test/cbot/scenarios/T.txt new file mode 100644 index 0000000..50a792b --- /dev/null +++ b/test/cbot/scenarios/T.txt @@ -0,0 +1,4 @@ +public extern int T ( float n ) +{ + return n * 1.1; +} \ No newline at end of file diff --git a/test/cbot/scenarios/TESTALL.txt b/test/cbot/scenarios/TESTALL.txt new file mode 100644 index 0000000..82247a0 --- /dev/null +++ b/test/cbot/scenarios/TESTALL.txt @@ -0,0 +1,161 @@ +int T ( int z ) +{ + return 45 + z ; +} + +class toto +{ + int val = 3 ; + int x = 3 * 3 ; + void toto( int n ) + { val = n + 3 ; } + int retval ( int param ) + { int r = val + param + x ; + val = param ; + return r ; } +} + +public extern void object :: Chose( ) +{ + int z [ 6 ]; + for ( int i = 0 ; i < 6 ; ) z [ i++ ] = 3 - i ; + show ( z ) ; + return; + + // test des tableaux + int [ ] a [ 3 ] ; +// a = null; + if ( a == null ) show ( "NULL" ); + + a [ 2 / 2 ] [ 2 ]= 5 ; + int [ ] b ; b = a [1] ; + b [ 0 ] = -4; + a [ 4 / 2 ] [ 1 ]= 1 ; + show ( a , b ) ; + return ; + { + toto chose = new toto (5 ) ; + toto truc = chose ; + show ( chose, chose.retval( 100 ) , + truc, truc.retval (40 ) ) ; + + return; + } + { + point A = new + point ( 4 * 4 , 2 ) ; + show ( A ) ; + return; + } + { + show ( T ( 1 ) , T ( 3.7 ) ) ; + return; + } + + { + point A ( 3, 4 ) , + B = A ; + + int n = -4; + show ( n ); + + show ( A, B ) ; + + boolean a = false; + boolean b = a or true; + if ( not a and b ) ; + return; + } + { + // test try + float x = nan ; int z = 0 ; + try { +// throw ( 3 * 4 + 33 ) ; + int zz ; goto ( 12 ) ; z = 1 ; z = 0 / 0 ; z = 2 ; + } + catch ( 45 + 0 * 6000 ) + { + show( "Exception 6000", z ) ; + } + catch ( x == 0 ) { show( "x nul" ) ; } + finally { show ( "fini" ) ; } + show ( "continue" ); + return; + } + { + // test des if + int a = 3; + if ( a == 3 ) show ( "33"); + else show ( "44"); + if ( a != 3 ) show ( "333"); + else show ( "444"); + return; + } + { + int a = 0; + // test break +un: + while ( true ) + { +deux: + while ( true ) + { + a++; + if ( a == 2 ) continue; + if ( a == 3 ) break deux; + show ( a ) ; + if ( a == 5 ) break un; + } + show ( "DEUX" ); + } + return; + } + { + // test switch + int a = 0; + + switch ( a ) + { + case 1 : show( "un" ) ; break; + case 2 : show( "deux" ) ; // break; + case 3 : show( "trois" ) ; break; + case 4 : show( "quatre" ) ; // break; + default : show( "par défaut" ) ; + } + return; + } + { + // test boucle while + float z = 3.3; + while ( z > 0 ) + { show ( z-- ) ; } + return; + } + + { + // test boucle do + float y = 3.3; + do { int x = 0; show(y); y++; } while ( y < 7 ) ; + return; + } + // test boucle for + int j = -7; show ( j ); + for ( int ii = 3, j = 31; ii < 6 ; ++ii, j = j -3 ) + { + j = 10 * j; + show ( ii, j ); + } + return; +{ + // déclarations de variables + int a; int b = 3; int c = 4*b, d = 1, e; + float x; float y = 3.3; float z = y / 2, u = 1, v; + boolean t; boolean tt = true or false; boolean ttt = false, tttt = true, t5; + string s; string ss = "hello"; string s2 = ss + " plus", s3 = "s3", s4; + + show( b, c, d ); + show( y, z, u ); + show( tt, ttt, tttt ); + show( ss, s2, s3 ); +} +} \ No newline at end of file diff --git a/test/cbot/scenarios/TestCB1.txt b/test/cbot/scenarios/TestCB1.txt new file mode 100644 index 0000000..516db47 --- /dev/null +++ b/test/cbot/scenarios/TestCB1.txt @@ -0,0 +1,18 @@ +extern public void toto() +{ + print( "hello" ) ; + print( fac(5) ); + print( t() ) ; +} + +public int fac(int n) +{ + if ( n<2 ) return 1; + return n * fac(n-1); +} + +point t() +{ + point a(1,2); + return a; +} diff --git a/test/cbot/scenarios/TestCBot1.txt b/test/cbot/scenarios/TestCBot1.txt new file mode 100644 index 0000000..d27b4f8 --- /dev/null +++ b/test/cbot/scenarios/TestCBot1.txt @@ -0,0 +1,27 @@ + +class CPoint2 +{ + float x, y; + void CPoint2(float x, float y) + { + this.x = x; + this.y = y; + } +} + +public extern void T ( ) +{ + CPoint2 X( 12, 33 ), Y ( -4, 4/3 ); + print ( X, Y ) ; +} + +public extern void Hello ( ) + +{ + println ( "Hello" ); +} + +public extern void test ( int n ) +{ + for ( int i = n; i>0 ; i--) print (i); +} \ No newline at end of file diff --git a/test/cbot/scenarios/TestCBot3.txt b/test/cbot/scenarios/TestCBot3.txt new file mode 100644 index 0000000..b915f96 --- /dev/null +++ b/test/cbot/scenarios/TestCBot3.txt @@ -0,0 +1,24 @@ +public extern void Test () +{ + for ( int x = 100000; x>0 ; x-- ) { } +} + +float MaRoutine( CPoint A, CPoint B ) +{ + A.x -= B.x ; // distance en x + A.y -= B.y ; // distance en y + A.x *= A.x; // carré de la distance + A.y += A.y; // carré de la distance + println ( A, B ) ; + return ( A.x + A.y ) ; +} + +public extern void TestAB ( ) +{ + CPoint A(3, 5) ; + CPoint B(4, -2); + println ( A, B ) ; + MaRoutine( A, B ) ; + println ( A, B ) ; +} + diff --git a/test/cbot/scenarios/TestNull.txt b/test/cbot/scenarios/TestNull.txt new file mode 100644 index 0000000..f447245 --- /dev/null +++ b/test/cbot/scenarios/TestNull.txt @@ -0,0 +1,15 @@ +extern public void TestNull () +{ + CPoint pointeur = null; + + try { + pointeur.x = 4; } + catch ( 6007 ) {} + + pointeur = new CPoint(1,2); + + print ( pointeur.x, pointeur.y, + pointeur ); + + pointeur.x = 5; +} \ No newline at end of file diff --git a/test/cbot/scenarios/TestRestoreState.txt b/test/cbot/scenarios/TestRestoreState.txt new file mode 100644 index 0000000..1e49e37 --- /dev/null +++ b/test/cbot/scenarios/TestRestoreState.txt @@ -0,0 +1,67 @@ +// routine de Daniel qui plante après RestoreState + +extern void object::Attack( ) +{ + int list[], i; + object p; + float dist, prox; + point nav1, nav2, dest; + boolean advance = true; + + i = 0; + list[i++] = WingedGrabber; + list[i++] = TrackedGrabber; + list[i++] = WheeledGrabber; + list[i++] = LeggedGrabber; + list[i++] = WingedShooter; + list[i++] = TrackedShooter; + list[i++] = WheeledShooter; + list[i++] = LeggedShooter; + list[i++] = WingedOrgaShooter; + list[i++] = TrackedOrgaShooter; + list[i++] = WheeledOrgaShooter; + list[i++] = LeggedOrgaShooter; + list[i++] = WingedSniffer; + list[i++] = TrackedSniffer; + list[i++] = WheeledSniffer; + list[i++] = LeggedSniffer; + list[i++] = Thumper; + list[i++] = PhazerShooter; + list[i++] = Recycler; + list[i++] = Shielder; + list[i++] = Subber; + list[i++] = Me; + + nav1.x = 1;//cmdline(0); + nav1.y = 1;//cmdline(1); + nav2.x = 2;//cmdline(2); + nav2.y = 2;//cmdline(3); + + while ( true ) + { + while ( true ) + { + // ennemi à proximité ? + p = radar(list, 0, 360, 0, 40); + if ( p == null ) break; + // lui tire dessus + fire(p.position); + } + + // se promène vers le point A + goto(nav1); + + while ( true ) + { + // ennemi à proximité ? + p = radar(list, 0, 360, 0, 40); + if ( p == null ) break; + // lui tire dessus + fire(p.position); + } + + // se promène vers le point B + goto(nav2); + } +} + diff --git a/test/cbot/scenarios/TestStatic.txt b/test/cbot/scenarios/TestStatic.txt new file mode 100644 index 0000000..f501aa5 --- /dev/null +++ b/test/cbot/scenarios/TestStatic.txt @@ -0,0 +1,31 @@ +class ESSAI +{ + int x = 0; + static int nb = 3; + static int [ ] array ; + + void Put( int val) + { +show(nb); + array[ nb ] = val; +// this.nb++; + this.nb = this.nb + 1; +show(nb, array); + } + int Get( ) + { + nb--; +show("out", nb, array); + return array[ nb ] ; + } +} + +extern public void T() +{ + ESSAI t1 ( ) ; + ESSAI t2 ( ) ; + t1.nb++; + t1.Put( 11 ); t1.Put( 12 ); t2.Put( 13 ); + + show ( t1.Get(), t2.Get(), t2.Get() ) ; +} \ No newline at end of file diff --git a/test/cbot/scenarios/TestStr.txt b/test/cbot/scenarios/TestStr.txt new file mode 100644 index 0000000..683ec1b --- /dev/null +++ b/test/cbot/scenarios/TestStr.txt @@ -0,0 +1,17 @@ +extern public void TSTR() +{ + string s = "C'est un essai"; + + print ( s, strlen(s), strleft(s, 3), strright(s,3), strmid(s, 2), strmid(s,2,3), strfind(s, "un"), strfind(s, "sdgfld") ); + + show ( strupper(s), strlower(s) ); + + s = "123.45" ; + print ( strval(s) ); + + + string sub = strright("abcdef", 2); // sub vaut "ef###", # étant un caractère bizarre quelconque + show (sub); + int pos = strfind("abcdef", "xy"); // pos vaut -1. Pourquoi pas nan ? + show(pos); +} diff --git a/test/cbot/scenarios/Z.txt b/test/cbot/scenarios/Z.txt new file mode 100644 index 0000000..714119b --- /dev/null +++ b/test/cbot/scenarios/Z.txt @@ -0,0 +1,14 @@ +public extern void tp() +{ + int a [4], b[]; + a [ 0 ] = 8 ; + + b = T ( a ) ; + show ( a, b ); +} + +int[] T ( int[] Z ) +{ + for ( int i = 0; i < 4 ; i++ ) Z[ i ] = i * i ; + return Z; +} \ No newline at end of file diff --git a/test/cbot/scenarios/a.txt b/test/cbot/scenarios/a.txt new file mode 100644 index 0000000..6107342 --- /dev/null +++ b/test/cbot/scenarios/a.txt @@ -0,0 +1,312 @@ +object radarGuepe(point orig, float dist) +{ + int i; + object pr, r; + float mindist; + + i = 0; + mindist = 1000; + while (i<30) + { + pr = radar(i); + if (pr != null) + { + + if (F(orig, pr.position) < mindist and pr.category == AlienWasp and pr.altitude > 3) + { + mindist = distance(orig, pr.position); + r = pr; + } + } + i = i+1; + } + if (mindist < dist) return(r); else return(null); +} + + +class Guepe +{ + + point pos; + + + void cherche(point orig, float dist) + { + object p; + point o; + + p = radarGuepe(orig, dist); + while (p == null) + { + wait(0.1); + p = radarGuepe(orig, dist); + } + + pos.x = p.position.x; + pos.y = p.position.y; + pos.z = p.position.z; + + //o = p.position; + //wait(0.1); + + //vitessex = (p.position.x - o.x)/0.1; + //vitessey = (p.position.y - o.y)/0.1; + //vitessez = (p.position.z - o.z)/0.1; + + } + + + void tire(point orig, float orient) + { + //float t = 3; //temps d'anticipation + float angle; + point cible; + + cible.x = pos.x;// + t*vitessex; + cible.y = pos.y;// + t*vitessey; + cible.z = pos.z;// + t*vitessez; + + if (cible.x == 0) angle = 90; else + angle = atan(cible.y / cible.x); + if (cible.x < 0) angle = angle + 180; + angle = angle - orient; + if (angle > 180) angle = angle - 360; + if (angle < -180) angle = angle + 360; + turn(angle); + + angle = atan((cible.z-orig.z) / distance2d(orig, cible)); + aim(angle); + + fire(0.1); + + } +} + +extern void object::Fourmi6() +{ + //fps(1000); + Guepe guepe = new Guepe(); + + while (true) + { + guepe.cherche(position, 50); + + guepe.tire(position, orientation); + } +} +object radarGuepe(point orig, float dist) +{ + int i; + object pr, r; + float mindist; + + i = 0; + mindist = 1000; + while (i<30) + { + pr = radar(i); + if (pr != null) + { + + if (F(orig, pr.position) < mindist and pr.category == AlienWasp and pr.altitude > 3) + { + mindist = distance(orig, pr.position); + r = pr; + } + } + i = i+1; + } + if (mindist < dist) return(r); else return(null); +} + + +class Guepe +{ + + point pos; + + + void cherche(point orig, float dist) + { + object p; + point o; + + p = radarGuepe(orig, dist); + while (p == null) + { + wait(0.1); + p = radarGuepe(orig, dist); + } + + pos.x = p.position.x; + pos.y = p.position.y; + pos.z = p.position.z; + + //o = p.position; + //wait(0.1); + + //vitessex = (p.position.x - o.x)/0.1; + //vitessey = (p.position.y - o.y)/0.1; + //vitessez = (p.position.z - o.z)/0.1; + + } + + + void tire(point orig, float orient) + { + //float t = 3; //temps d'anticipation + float angle; + point cible; + + cible.x = pos.x;// + t*vitessex; + cible.y = pos.y;// + t*vitessey; + cible.z = pos.z;// + t*vitessez; + + if (cible.x == 0) angle = 90; else + angle = atan(cible.y / cible.x); + if (cible.x < 0) angle = angle + 180; + angle = angle - orient; + if (angle > 180) angle = angle - 360; + if (angle < -180) angle = angle + 360; + turn(angle); + + angle = atan((cible.z-orig.z) / distance2d(orig, cible)); + aim(angle); + + fire(0.1); + + } +} + +extern void object::Fourmi6() +{ + //fps(1000); + Guepe guepe = new Guepe(); + + while (true) + { + guepe.cherche(position, 50); + + guepe.tire(position, orientation); + } +} +object radarGuepe(point orig, float dist) +{ + int i; + object pr, r; + float mindist; + + i = 0; + mindist = 1000; + while (i<30) + { + pr = radar(i); + if (pr != null) + { + + if (F(orig, pr.position) < mindist and pr.category == AlienWasp and pr.altitude > 3) + { + mindist = distance(orig, pr.position); + r = pr; + } + } + i = i+1; + } + if (mindist < dist) return(r); else return(null); +} + + +class Guepe +{ + + point pos; + + + void cherche(point orig, float dist) + { + object p; + point o; + + p = radarGuepe(orig, dist); + while (p == null) + { + wait(0.1); + p = radarGuepe(orig, dist); + } + + pos.x = p.position.x; + pos.y = p.position.y; + pos.z = p.position.z; + + //o = p.position; + //wait(0.1); + + //vitessex = (p.position.x - o.x)/0.1; + //vitessey = (p.position.y - o.y)/0.1; + //vitessez = (p.position.z - o.z)/0.1; + + } + + + void tire(point orig, float orient) + { + //float t = 3; //temps d'anticipation + float angle; + point cible; + + cible.x = pos.x;// + t*vitessex; + cible.y = pos.y;// + t*vitessey; + cible.z = pos.z;// + t*vitessez; + + if (cible.x == 0) angle = 90; else + angle = atan(cible.y / cible.x); + if (cible.x < 0) angle = angle + 180; + angle = angle - orient; + if (angle > 180) angle = angle - 360; + if (angle < -180) angle = angle + 360; + turn(angle); + + angle = atan((cible.z-orig.z) / distance2d(orig, cible)); + aim(angle); + + fire(0.1); + + } +} + +extern void object::Fourmi6() +{ + //fps(1000); + Guepe guepe = new Guepe(); + + while (true) + { + guepe.cherche(position, 50); + + guepe.tire(position, orientation); + } +} + +public extern void TestTableau () +{ + int tableau [ 12 ] ; + + point array[ 12 ] [ 14 ] ; + + point zéro ( 1, 2 ) ; + point a = zéro ; + + for ( int i = 0 ; i < 10 ; i++ ) array[ i ] [ i ]= zéro ; + + array[ 5 ] [3 ] . x =1.5 ; + + array[ 2 ] [ 2 ] . y = array[ 5 ] [ 5 ] . x ; + + array[ 4 ] = array [ 2 ] ; + + for ( int i = 0 ; i < 10 ; i++ ) for ( int j = 0 ; j < 4 ; j++ ) println ( i, j, array [ i ] [ j ] ) ; + + show( zéro, a, array ); + +} + diff --git a/test/cbot/scenarios/bug.txt b/test/cbot/scenarios/bug.txt new file mode 100644 index 0000000..4ec6eb3 --- /dev/null +++ b/test/cbot/scenarios/bug.txt @@ -0,0 +1,12 @@ +public extern void object::Bug() +{ + point a; + a = position; + TEST(); + float d=dist(a, position); +} + +float dist(point a, point b) +{ + return a.x-b.x; +} diff --git a/test/cbot/scenarios/bugmw.txt b/test/cbot/scenarios/bugmw.txt new file mode 100644 index 0000000..284ee43 --- /dev/null +++ b/test/cbot/scenarios/bugmw.txt @@ -0,0 +1,9 @@ +extern public void main() +{ + show(fact(30)) ; +} + +public int fact(int n) +{ + return (fact(n-1)*n) ; +} diff --git a/test/cbot/scenarios/ccc.txt b/test/cbot/scenarios/ccc.txt new file mode 100644 index 0000000..dbcd1d5 --- /dev/null +++ b/test/cbot/scenarios/ccc.txt @@ -0,0 +1,8 @@ +public extern void ccc() +{ + int a; + a = 0 ; + + if ( a == 0 ); + +} \ No newline at end of file diff --git a/test/cbot/scenarios/enum.txt b/test/cbot/scenarios/enum.txt new file mode 100644 index 0000000..a592a7f --- /dev/null +++ b/test/cbot/scenarios/enum.txt @@ -0,0 +1,9 @@ + +enum JourDeLaSemaine { + lundi = 1, + mardi, + mercredi, + jeudi, + vendredi, + samedi, + dimanche = 0 } \ No newline at end of file diff --git a/test/cbot/scenarios/fibo.txt b/test/cbot/scenarios/fibo.txt new file mode 100644 index 0000000..88f5357 --- /dev/null +++ b/test/cbot/scenarios/fibo.txt @@ -0,0 +1,25 @@ + +extern public int Fibo( int n, boolean b ) +{ + if ( n < 2 ) return n; + int a = Fibo(n-1, b) + Fibo(n-2, false); + if ( b ) print (n + "=" + a); + return a; +} + +extern public void t() +{ + Fibo( 23, true); +} + +extern public void tt() +{ + t(); +} + +// cette routine n'est évidemment pas du tout obtimisée +// c'est même un très mauvais exemple de programmation récursive + +// pour un test de durée, Fibo(23, true) prend +// en mode Debug 67 secondes +// en mode Release 8 secondes diff --git a/test/cbot/scenarios/file.txt b/test/cbot/scenarios/file.txt new file mode 100644 index 0000000..2a22dd9 --- /dev/null +++ b/test/cbot/scenarios/file.txt @@ -0,0 +1,70 @@ +class CLASS22 +{ + static int nb = 2; + void T22 ( ) { nb = nb / 0 ; } +} + +public extern void object :: TEST() +{ + switch ( 1 ) + { + case 1: + { + file h(); + h.open("Mon Fichier.txt", "r"); +show ( h.filename, h.handle ); +h.filename = "xx"; +h.handle = 1 ; + h.readln(); + h.close(); + } + case 2: + { + file h("Mon Fichier.txt"); + h.open("r"); + h.readln(); + h.close(); + } + case 3: + { + file h("Mon Fichier.txt", "r"); + h.readln(); + h.close(); + } + case 4: + { + file h(); + h.filename = "Mon Fichier.txt"; + h.open("r"); + h.readln(); + h.close(); + } + case 5: + { + file h = fileopen( "Mon 2Fichier.txt", "r" ); + h.readln(); + h.close(); + } + } +{ + file h( ) ; + h.filename = "Test.h"; + h.open ( "r" ); + + + file pf ( "Mon Fichier.txt" ) ; + pf . open ( "w" ) ; + pf . writeln ( "Voici encore du texte" ) ; + pf . writeln ( "et une seconde ligne" ) ; + pf . close( ); + + pf . open ( "r" ) ; + + while ( not pf . eof( ) ) + { + string s = pf . readln ( ); + show ( s ); + } + pf.close( ); +} +} diff --git a/test/cbot/scenarios/h.txt b/test/cbot/scenarios/h.txt new file mode 100644 index 0000000..c395319 --- /dev/null +++ b/test/cbot/scenarios/h.txt @@ -0,0 +1,5 @@ +void tf() +{ + file h; + h.handle += 1 ; +} \ No newline at end of file diff --git a/test/cbot/scenarios/include.txt b/test/cbot/scenarios/include.txt new file mode 100644 index 0000000..e8f8cc9 --- /dev/null +++ b/test/cbot/scenarios/include.txt @@ -0,0 +1,27 @@ +class Z +{ + static int x = 0; + private int y; + + void T( ) + { + // autorisé ici + y = x ; + this.y = this.x ; + x = y ; + this.x = this.y ; + } +} + +extern public void test() +{ + Z a(); + 3 * a.x; // autorisé +//vu 3 * a.y; // interdit +//vu a.y = 3; // interdit ici + a.x = 1; // autorisé + + show ( a ); + a.T(); + show ( a ); +} diff --git a/test/cbot/scenarios/intrinsic.txt b/test/cbot/scenarios/intrinsic.txt new file mode 100644 index 0000000..f215791 --- /dev/null +++ b/test/cbot/scenarios/intrinsic.txt @@ -0,0 +1,16 @@ +public extern void TestIntrinsic() +{ + point a ( 1, 2 ); + print (a); + + a.x = 3; + a.y = 4; + + point b = a; + + println ( b.x, b.y, b ) ; + if ( b == a ) b.y = 0; + println (a,b); + if ( b != a ) b.y = a.y; + println(a,b); +} \ No newline at end of file diff --git a/test/cbot/scenarios/methode1.txt b/test/cbot/scenarios/methode1.txt new file mode 100644 index 0000000..080bba2 --- /dev/null +++ b/test/cbot/scenarios/methode1.txt @@ -0,0 +1,57 @@ +class t { + point p; +} + +void object :: toto() +{ + show ( Position ) ; +} + +extern public void object :: XX() +{ + int test []; + test [ 9999 ] = 3; + + toto () ; +/* + Radar(); + + object test ; + test = this. Radar(); + + do { + test = this.Radar(); + } while ( test == null ); + +/* + t test [ 4 ]; + for ( int i = 0 ; i < 4 ; i++ ) test [ i ] = new t(); + test [ 3 ] .p.x = 2; + show ( test ); +/* + int a = nan; + show ( a ) ; + + a = TypeMarkPath; + show ( a, a++, --a ) ; + + if ( a != nan ) a += 1 ; + + a = TypeMarkPath; + float q = a ; + show ( a, q ) ; + +return; + + a += ++a; + show ( a ) ; + + boolean i = false; + + if ( i == true ) {} + + object p; + if ( p == null) { p = p ; } +*/ +} + diff --git a/test/cbot/scenarios/methode2.txt b/test/cbot/scenarios/methode2.txt new file mode 100644 index 0000000..76ce7f4 --- /dev/null +++ b/test/cbot/scenarios/methode2.txt @@ -0,0 +1,50 @@ + +extern void Toto() +{ + TEST(12); + + for ( int i = 0 ; i<1000; i++) + { + int j = 1; + if (i==55) TEST(12); + } + + TEST(2); + + +// Nouveau(); + int toto[4]; + point Z[3]; + + Z[1].x = 11; Z[1].y = 12; + + toto[2] = 12; + toto[1] = nan; + +// point test, autre(2,3) ; +// object titi = Radar(); + + TEST ( 1 ) ; + + toto[0] = 11; + + TEST ( 2 ) ; + + toto[6] = 0; +} + +extern void object::Nouveau() +{ + point a; + a = np(Position); +} + +point np(point b) +{ + point c; + c.x = b.y; + c.y = b.x; + return c ; +} + + diff --git a/test/cbot/scenarios/mp1.txt b/test/cbot/scenarios/mp1.txt new file mode 100644 index 0000000..599cfc4 --- /dev/null +++ b/test/cbot/scenarios/mp1.txt @@ -0,0 +1,25 @@ +class Guepet +{ + + float a; + float b; + + void init() + { + a = 12.34; + b = 56.78; + } + + +} + +extern void object::Fourmi6() +{ + Guepet guepe =new Guepet(); + + guepe.init(); + + + show("test "+guepe.a+" "+guepe.b); + +} diff --git a/test/cbot/scenarios/mp2.txt b/test/cbot/scenarios/mp2.txt new file mode 100644 index 0000000..1c2972c --- /dev/null +++ b/test/cbot/scenarios/mp2.txt @@ -0,0 +1,28 @@ +class Guepet +{ + + float a; + float b; + + void init() + { + a = 12.34; + b = 56.78; + + object x = radar(123); + show("radar "+x.position.x); + show("C'est fait"); + } + + +} + +extern void object::Fourmi6() +{ + Guepet guepe=new Guepet(); + + guepe.init(); + + show("test "+guepe.a+" "+guepe.b); + +} diff --git a/test/cbot/scenarios/mw.txt b/test/cbot/scenarios/mw.txt new file mode 100644 index 0000000..c237670 --- /dev/null +++ b/test/cbot/scenarios/mw.txt @@ -0,0 +1,16 @@ +extern public void main() +{ +// goto( 3, 4 ); + + while( true ) + { + try { goto (12) ; } + catch( FF( ) ) + { show( "ko"); } + } +} + +boolean FF() +{ + return false; +} diff --git a/test/cbot/scenarios/null.txt b/test/cbot/scenarios/null.txt new file mode 100644 index 0000000..ae76b74 --- /dev/null +++ b/test/cbot/scenarios/null.txt @@ -0,0 +1,5 @@ +extern public void xxx () +{ + CPoint test = null ; + if ( test == null ) show ( "NULL" ); +} \ No newline at end of file diff --git a/test/cbot/scenarios/opnew.txt b/test/cbot/scenarios/opnew.txt new file mode 100644 index 0000000..7d6838c --- /dev/null +++ b/test/cbot/scenarios/opnew.txt @@ -0,0 +1,20 @@ +extern public void xx () +{ + CPoint pointeur, test = null ; + pointeur = new CPoint ( 3, 4 ); + + if ( test == null ) show ( "NULL" ); + + CPoint pp = pointeur; + +show( pointeur , pp ); + + pp.x = 33.3; + if ( pointeur.x != pp.x ) 0/0; + + pp = new CPoint(); +// pointeur = pp; + +show( pointeur , pp ); + +} \ No newline at end of file diff --git a/test/cbot/scenarios/plante.txt b/test/cbot/scenarios/plante.txt new file mode 100644 index 0000000..363461b --- /dev/null +++ b/test/cbot/scenarios/plante.txt @@ -0,0 +1,25 @@ +class Guepet +{ + + point pos; + float t = 0.1; + + void init() + { + pos.x = 12.123; + pos.y = 34.345; + + F(t); + } + + +} + +extern void object::Fourmi6() +{ + Guepet guepe=new Guepet(); + + guepe.init(); + + show ( guepe ); +} diff --git a/test/cbot/scenarios/pointer.txt b/test/cbot/scenarios/pointer.txt new file mode 100644 index 0000000..2d4d907 --- /dev/null +++ b/test/cbot/scenarios/pointer.txt @@ -0,0 +1,41 @@ +extern public void x () +{ + show ( 3 ** 4 ); + float z = 1e-3; + show ( z ); + + CPoint b ( 4,5 ); + show ( b ); + + CPoint a ( ) ; + a.x = 21; a.y = 12; + show ( a ) ; + + CPoint test = new CPoint ( 1,1 ); + test = new CPoint ( 2, 2 ); + show ( test ); +} + +// crée un objet et retourne son pointeur +CPoint newcpoint() +{ + CPoint p = new CPoint ( 3, 3 ); + return p; +} + +extern public void y () +{ + CPoint test = newcpoint(); + println ( test ); + dontmodif( test ); + println ( test ); +} + +// ne doit pas modifier l'objet en paramètre +void dontmodif ( CPoint pp ) +{ + pp.x = 5; + pp.y = 2; + println ( pp, pp.x, pp.y ); +} + diff --git a/test/cbot/scenarios/postinc.txt b/test/cbot/scenarios/postinc.txt new file mode 100644 index 0000000..cdf6ab5 --- /dev/null +++ b/test/cbot/scenarios/postinc.txt @@ -0,0 +1,7 @@ +extern public void X() +{ + point A [ ] ; + A[5] = new point (2,3); + int val = A[5].x++ + --A[5].y; + show ( A, val ); +} diff --git a/test/cbot/scenarios/radar.txt b/test/cbot/scenarios/radar.txt new file mode 100644 index 0000000..09d84a2 --- /dev/null +++ b/test/cbot/scenarios/radar.txt @@ -0,0 +1,39 @@ +extern void object::Bug( ) +{ + try{ int a = 44 ; a = 12 / 0 ; } + catch(6000) { int b = 4 ; } + finally { int z = 1 ; } + +// tp ( A, B ); + +/* int a = 4, b = 2, c = nan; + float x, y = 3/2, z = nan; + boolean i, j = false, k = true; + + string s, ss = "xyz"; + + while ( false ) + { + object left, right; + + left = Radar(TypeMarkPath, -45, 120, 100); + right = Radar(TypeMarkPath, 45, 120, 100); + + if ( left == null && right == null ) + { + } + } + int t = fact ( 4 ) ;*/ +} + +void tp( point a , point b ) +{ + a.x += b.x; +} + + +int fact( int n ) +{ + if ( n < 2 ) return n; + return n * fact ( n - 1 ) ; +} \ No newline at end of file diff --git a/test/cbot/scenarios/solution.txt b/test/cbot/scenarios/solution.txt new file mode 100644 index 0000000..f78cf12 --- /dev/null +++ b/test/cbot/scenarios/solution.txt @@ -0,0 +1,13 @@ +extern void object::Solution( ) +{ +show ( "Solution " + Position ); + Carré(15); + Carré(25); +} + +void object::Carré(float côté) +{ +show ( "Carré " + Position ); + Move(côté); + Turn(-90); +} \ No newline at end of file diff --git a/test/cbot/scenarios/test.txt b/test/cbot/scenarios/test.txt new file mode 100644 index 0000000..0693994 --- /dev/null +++ b/test/cbot/scenarios/test.txt @@ -0,0 +1,8 @@ +extern public void x() +{ + float a= 1, b = 2; + a = b * ( 2 + 2 ); + print (a); + a += 4; + print (a); +} diff --git a/test/cbot/scenarios/test23.txt b/test/cbot/scenarios/test23.txt new file mode 100644 index 0000000..d6e1ddd --- /dev/null +++ b/test/cbot/scenarios/test23.txt @@ -0,0 +1,10 @@ +extern public void object::TEST23() +{ + CLASS22 T; + T.T22( ) ; + + show( position ); + show( this.position ); + +// T22(); +} \ No newline at end of file diff --git a/test/cbot/scenarios/testmw.txt b/test/cbot/scenarios/testmw.txt new file mode 100644 index 0000000..6570f6d --- /dev/null +++ b/test/cbot/scenarios/testmw.txt @@ -0,0 +1,14 @@ +extern public int testmw( int a) +{ + boolean b = true ; + + if (b) + return 1 ; + else + return a ; 0 * testmw(a-1) ; +} + +public int Fibo2 ( int n ) +{ + print ( " bof " ); +} \ No newline at end of file diff --git a/test/cbot/scenarios/this.txt b/test/cbot/scenarios/this.txt new file mode 100644 index 0000000..b8a9e04 --- /dev/null +++ b/test/cbot/scenarios/this.txt @@ -0,0 +1,13 @@ +extern void object :: TEST22 ( ) +{ + show( position ); + show( this.position ); + + T(); +} + +public void object :: T22() +{ + show( position ); + show( this.position ); +} \ No newline at end of file diff --git a/test/cbot/scenarios/tt.txt b/test/cbot/scenarios/tt.txt new file mode 100644 index 0000000..cd13c9d --- /dev/null +++ b/test/cbot/scenarios/tt.txt @@ -0,0 +1,12 @@ +extern public void T() { T1(); } + +public void T1() +{ + show( "T1" ); + T2(); +} + +public void T2() +{ + show( "T2" ); +} \ No newline at end of file diff --git a/test/cbot/scenarios/tt2.txt b/test/cbot/scenarios/tt2.txt new file mode 100644 index 0000000..ad9dc1d --- /dev/null +++ b/test/cbot/scenarios/tt2.txt @@ -0,0 +1,5 @@ +extern public void TT() +{ + T1(); + T2(); +} \ No newline at end of file diff --git a/test/cbot/scenarios/vide.txt b/test/cbot/scenarios/vide.txt new file mode 100644 index 0000000..e69de29 diff --git a/test/cbot/scenarios/zz.txt b/test/cbot/scenarios/zz.txt new file mode 100644 index 0000000..da764ac --- /dev/null +++ b/test/cbot/scenarios/zz.txt @@ -0,0 +1,6 @@ +extern public void zz() +{ + MaClass TOTO (); + + show (TOTO); +} \ No newline at end of file diff --git a/test/envs/CMakeLists.txt b/test/envs/CMakeLists.txt new file mode 100644 index 0000000..374c39f --- /dev/null +++ b/test/envs/CMakeLists.txt @@ -0,0 +1,2 @@ +# OpenGL tests +add_subdirectory(opengl) diff --git a/test/envs/opengl/CMakeLists.txt b/test/envs/opengl/CMakeLists.txt new file mode 100644 index 0000000..588a864 --- /dev/null +++ b/test/envs/opengl/CMakeLists.txt @@ -0,0 +1,63 @@ +set(SRC_DIR ${colobot_SOURCE_DIR}/src) + +configure_file(${SRC_DIR}/common/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/common/config.h) + + +set(TEXTURE_SOURCES +${SRC_DIR}/graphics/opengl/gldevice.cpp +${SRC_DIR}/common/logger.cpp +${SRC_DIR}/common/image.cpp +texture_test.cpp +) + +set(MODEL_SOURCES +${SRC_DIR}/graphics/opengl/gldevice.cpp +${SRC_DIR}/graphics/engine/modelfile.cpp +${SRC_DIR}/common/logger.cpp +${SRC_DIR}/common/image.cpp +${SRC_DIR}/common/iman.cpp +${SRC_DIR}/common/stringutils.cpp +${SRC_DIR}/app/system.cpp +model_test.cpp +) + +set(TRANSFORM_SOURCES +${SRC_DIR}/graphics/opengl/gldevice.cpp +${SRC_DIR}/common/logger.cpp +${SRC_DIR}/common/image.cpp +${SRC_DIR}/common/iman.cpp +${SRC_DIR}/app/system.cpp +transform_test.cpp +) + +set(LIGHT_SOURCES +${SRC_DIR}/graphics/opengl/gldevice.cpp +${SRC_DIR}/common/logger.cpp +${SRC_DIR}/common/image.cpp +${SRC_DIR}/common/iman.cpp +${SRC_DIR}/app/system.cpp +light_test.cpp +) + +include_directories(${SRC_DIR} ${CMAKE_CURRENT_BINARY_DIR}) + +set(LIBS +${SDL_LIBRARY} +${SDLIMAGE_LIBRARY} +${OPENGL_LIBRARY} +${GLEW_LIBRARY} +${PNG_LIBRARIES} +${ADD_LIBS} +) + +add_executable(texture_test ${TEXTURE_SOURCES}) +target_link_libraries(texture_test ${LIBS}) + +add_executable(model_test ${MODEL_SOURCES}) +target_link_libraries(model_test ${LIBS}) + +add_executable(transform_test ${TRANSFORM_SOURCES}) +target_link_libraries(transform_test ${LIBS}) + +add_executable(light_test ${LIGHT_SOURCES}) +target_link_libraries(light_test ${LIBS}) diff --git a/test/envs/opengl/README.txt b/test/envs/opengl/README.txt new file mode 100644 index 0000000..c618415 --- /dev/null +++ b/test/envs/opengl/README.txt @@ -0,0 +1,9 @@ +Test programs for OpenGL engine: + - texture_test -> multitexturing test with 2 textures (included as files: ./tex1.png, ./tex2.png) + - model_test -> simple model viewer to test model loading + usage: ./model_test {dxf|mod} model_file + second argument is the loaded format (DXF or Colobot .mod files) + requires ./tex folder (or symlink) with Colobot textures + viewer is controlled from keyboard - the bindings can be found in code + - transform_test -> simple "walk around" test for world & view transformations + - light test -> test for lighting diff --git a/test/envs/opengl/light_test.cpp b/test/envs/opengl/light_test.cpp new file mode 100644 index 0000000..b19ba4b --- /dev/null +++ b/test/envs/opengl/light_test.cpp @@ -0,0 +1,462 @@ +#include "app/system.h" +#include "common/logger.h" +#include "common/image.h" +#include "common/iman.h" +#include "graphics/opengl/gldevice.h" +#include "math/geometry.h" + +#include +#include +#include + +#include +#include + +enum KeySlots +{ + K_Forward, + K_Back, + K_Left, + K_Right, + K_Up, + K_Down, + K_Count +}; +bool KEYMAP[K_Count] = { false }; + +Math::Point MOUSE_POS_BASE; + +Math::Vector TRANSLATION(0.0f, 2.0f, 0.0f); +Math::Vector ROTATION, ROTATION_BASE; + +float CUBE_ORBIT = 0.0f; + +const int FRAME_DELAY = 5000; + +SystemTimeStamp *PREV_TIME = NULL, *CURR_TIME = NULL; + +void Init(Gfx::CGLDevice *device) +{ + device->SetRenderState(Gfx::RENDER_STATE_DEPTH_TEST, true); + device->SetShadeModel(Gfx::SHADE_SMOOTH); +} + +void Render(Gfx::CGLDevice *device) +{ + device->BeginScene(); + + /* Unlit part of scene */ + + device->SetRenderState(Gfx::RENDER_STATE_LIGHTING, false); + device->SetRenderState(Gfx::RENDER_STATE_CULLING, false); // Double-sided drawing + + Math::Matrix persp; + Math::LoadProjectionMatrix(persp, Math::PI / 4.0f, (800.0f) / (600.0f), 0.1f, 50.0f); + device->SetTransform(Gfx::TRANSFORM_PROJECTION, persp); + + + Math::Matrix viewMat; + Math::Matrix mat; + + viewMat.LoadIdentity(); + + Math::LoadRotationXMatrix(mat, -ROTATION.x); + viewMat = Math::MultiplyMatrices(viewMat, mat); + + Math::LoadRotationYMatrix(mat, -ROTATION.y); + viewMat = Math::MultiplyMatrices(viewMat, mat); + + Math::LoadTranslationMatrix(mat, -TRANSLATION); + viewMat = Math::MultiplyMatrices(viewMat, mat); + + device->SetTransform(Gfx::TRANSFORM_VIEW, viewMat); + + Math::Matrix worldMat; + worldMat.LoadIdentity(); + device->SetTransform(Gfx::TRANSFORM_WORLD, worldMat); + + Gfx::VertexCol line[2] = { Gfx::VertexCol() }; + + for (int x = -40; x <= 40; ++x) + { + line[0].color = Gfx::Color(0.7f + x / 120.0f, 0.0f, 0.0f); + line[0].coord.z = -40; + line[0].coord.x = x; + line[1].color = Gfx::Color(0.7f + x / 120.0f, 0.0f, 0.0f); + line[1].coord.z = 40; + line[1].coord.x = x; + device->DrawPrimitive(Gfx::PRIMITIVE_LINES, line, 2); + } + + for (int z = -40; z <= 40; ++z) + { + line[0].color = Gfx::Color(0.0f, 0.7f + z / 120.0f, 0.0f); + line[0].coord.z = z; + line[0].coord.x = -40; + line[1].color = Gfx::Color(0.0f, 0.7f + z / 120.0f, 0.0f); + line[1].coord.z = z; + line[1].coord.x = 40; + device->DrawPrimitive(Gfx::PRIMITIVE_LINES, line, 2); + } + + + Gfx::VertexCol quad[6] = { Gfx::VertexCol() }; + + quad[0].coord = Math::Vector(-1.0f, -1.0f, 0.0f); + quad[1].coord = Math::Vector( 1.0f, -1.0f, 0.0f); + quad[2].coord = Math::Vector(-1.0f, 1.0f, 0.0f); + quad[3].coord = Math::Vector( 1.0f, 1.0f, 0.0f); + + for (int i = 0; i < 6; ++i) + quad[i].color = Gfx::Color(1.0f, 1.0f, 0.0f); + + Math::LoadTranslationMatrix(worldMat, Math::Vector(40.0f, 2.0f, 40.0f)); + device->SetTransform(Gfx::TRANSFORM_WORLD, worldMat); + + device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, quad, 4); + + for (int i = 0; i < 6; ++i) + quad[i].color = Gfx::Color(0.0f, 1.0f, 1.0f); + + Math::LoadTranslationMatrix(worldMat, Math::Vector(-40.0f, 2.0f, -40.0f)); + device->SetTransform(Gfx::TRANSFORM_WORLD, worldMat); + + int planes = device->ComputeSphereVisibility(Math::Vector(0.0f, 0.0f, 0.0f), 1.0f); + printf("Planes:"); + if (planes == 0) + printf(" (none)"); + + if (planes & Gfx::FRUSTUM_PLANE_LEFT) + printf(" LEFT"); + + if (planes & Gfx::FRUSTUM_PLANE_RIGHT) + printf(" RIGHT"); + + if (planes & Gfx::FRUSTUM_PLANE_BOTTOM) + printf(" BOTTOM"); + + if (planes & Gfx::FRUSTUM_PLANE_TOP) + printf(" TOP"); + + if (planes & Gfx::FRUSTUM_PLANE_FRONT) + printf(" FRONT"); + + if (planes & Gfx::FRUSTUM_PLANE_BACK) + printf(" BACK"); + + printf("\n"); + + device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, quad, 4); + + for (int i = 0; i < 6; ++i) + quad[i].color = Gfx::Color(1.0f, 0.0f, 1.0f); + + Math::LoadTranslationMatrix(worldMat, Math::Vector(10.0f, 4.5f, 5.0f)); + device->SetTransform(Gfx::TRANSFORM_WORLD, worldMat); + + device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, quad, 4); + + /* Moving lit cube */ + device->SetRenderState(Gfx::RENDER_STATE_LIGHTING, true); + device->SetRenderState(Gfx::RENDER_STATE_CULLING, true); // Culling (CCW faces) + + device->SetGlobalAmbient(Gfx::Color(0.4f, 0.4f, 0.4f)); + + Gfx::Light light1; + light1.type = Gfx::LIGHT_POINT; + light1.position = Math::Vector(10.0f, 4.5f, 5.0f); + light1.ambient = Gfx::Color(0.2f, 0.2f, 0.2f); + light1.diffuse = Gfx::Color(1.0f, 0.1f, 0.1f); + light1.specular = Gfx::Color(0.0f, 0.0f, 0.0f); + device->SetLight(0, light1); + device->SetLightEnabled(0, true); + + /*Gfx::Light light2; + device->SetLight(1, light2); + device->SetLightEnabled(1, true);*/ + + Gfx::Material material; + material.ambient = Gfx::Color(0.3f, 0.3f, 0.3f); + material.diffuse = Gfx::Color(0.8f, 0.7f, 0.6f); + material.specular = Gfx::Color(0.0f, 0.0f, 0.0f); + device->SetMaterial(material); + + const Gfx::Vertex cube[6][4] = + { + { + // Front + Gfx::Vertex(Math::Vector(-1.0f, -1.0f, -1.0f), Math::Vector( 0.0f, 0.0f, -1.0f)), + Gfx::Vertex(Math::Vector( 1.0f, -1.0f, -1.0f), Math::Vector( 0.0f, 0.0f, -1.0f)), + Gfx::Vertex(Math::Vector(-1.0f, 1.0f, -1.0f), Math::Vector( 0.0f, 0.0f, -1.0f)), + Gfx::Vertex(Math::Vector( 1.0f, 1.0f, -1.0f), Math::Vector( 0.0f, 0.0f, -1.0f)) + }, + + { + // Back + Gfx::Vertex(Math::Vector( 1.0f, -1.0f, 1.0f), Math::Vector( 0.0f, 0.0f, 1.0f)), + Gfx::Vertex(Math::Vector(-1.0f, -1.0f, 1.0f), Math::Vector( 0.0f, 0.0f, 1.0f)), + Gfx::Vertex(Math::Vector( 1.0f, 1.0f, 1.0f), Math::Vector( 0.0f, 0.0f, 1.0f)), + Gfx::Vertex(Math::Vector(-1.0f, 1.0f, 1.0f), Math::Vector( 0.0f, 0.0f, 1.0f)) + }, + + { + // Top + Gfx::Vertex(Math::Vector(-1.0f, 1.0f, -1.0f), Math::Vector( 0.0f, 1.0f, 0.0f)), + Gfx::Vertex(Math::Vector( 1.0f, 1.0f, -1.0f), Math::Vector( 0.0f, 1.0f, 0.0f)), + Gfx::Vertex(Math::Vector(-1.0f, 1.0f, 1.0f), Math::Vector( 0.0f, 1.0f, 0.0f)), + Gfx::Vertex(Math::Vector( 1.0f, 1.0f, 1.0f), Math::Vector( 0.0f, 1.0f, 0.0f)) + }, + + { + // Bottom + Gfx::Vertex(Math::Vector(-1.0f, -1.0f, 1.0f), Math::Vector( 0.0f, -1.0f, 0.0f)), + Gfx::Vertex(Math::Vector( 1.0f, -1.0f, 1.0f), Math::Vector( 0.0f, -1.0f, 0.0f)), + Gfx::Vertex(Math::Vector(-1.0f, -1.0f, -1.0f), Math::Vector( 0.0f, -1.0f, 0.0f)), + Gfx::Vertex(Math::Vector( 1.0f, -1.0f, -1.0f), Math::Vector( 0.0f, -1.0f, 0.0f)) + }, + + { + // Left + Gfx::Vertex(Math::Vector(-1.0f, -1.0f, 1.0f), Math::Vector(-1.0f, 0.0f, 0.0f)), + Gfx::Vertex(Math::Vector(-1.0f, -1.0f, -1.0f), Math::Vector(-1.0f, 0.0f, 0.0f)), + Gfx::Vertex(Math::Vector(-1.0f, 1.0f, 1.0f), Math::Vector(-1.0f, 0.0f, 0.0f)), + Gfx::Vertex(Math::Vector(-1.0f, 1.0f, -1.0f), Math::Vector(-1.0f, 0.0f, 0.0f)) + }, + + { + // Right + Gfx::Vertex(Math::Vector( 1.0f, -1.0f, -1.0f), Math::Vector( 1.0f, 0.0f, 0.0f)), + Gfx::Vertex(Math::Vector( 1.0f, -1.0f, 1.0f), Math::Vector( 1.0f, 0.0f, 0.0f)), + Gfx::Vertex(Math::Vector( 1.0f, 1.0f, -1.0f), Math::Vector( 1.0f, 0.0f, 0.0f)), + Gfx::Vertex(Math::Vector( 1.0f, 1.0f, 1.0f), Math::Vector( 1.0f, 0.0f, 0.0f)) + } + }; + + Math::Matrix cubeTrans; + Math::LoadTranslationMatrix(cubeTrans, Math::Vector(10.0f, 2.0f, 5.0f)); + Math::Matrix cubeRot; + Math::LoadRotationMatrix(cubeRot, Math::Vector(0.0f, 1.0f, 0.0f), CUBE_ORBIT); + Math::Matrix cubeRotInv; + Math::LoadRotationMatrix(cubeRotInv, Math::Vector(0.0f, 1.0f, 0.0f), -CUBE_ORBIT); + Math::Matrix cubeTransRad; + Math::LoadTranslationMatrix(cubeTransRad, Math::Vector(0.0f, 0.0f, 6.0f)); + worldMat = Math::MultiplyMatrices(cubeTransRad, cubeRotInv); + worldMat = Math::MultiplyMatrices(cubeRot, worldMat); + worldMat = Math::MultiplyMatrices(cubeTrans, worldMat); + device->SetTransform(Gfx::TRANSFORM_WORLD, worldMat); + + for (int i = 0; i < 6; ++i) + device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, cube[i], 4); + + device->EndScene(); +} + +void Update() +{ + const float TRANS_SPEED = 6.0f; // units / sec + + GetCurrentTimeStamp(CURR_TIME); + float timeDiff = TimeStampDiff(PREV_TIME, CURR_TIME, STU_SEC); + CopyTimeStamp(PREV_TIME, CURR_TIME); + + CUBE_ORBIT += timeDiff * (Math::PI / 4.0f); + + Math::Vector incTrans; + + if (KEYMAP[K_Forward]) + incTrans.z = +TRANS_SPEED * timeDiff; + if (KEYMAP[K_Back]) + incTrans.z = -TRANS_SPEED * timeDiff; + if (KEYMAP[K_Right]) + incTrans.x = +TRANS_SPEED * timeDiff; + if (KEYMAP[K_Left]) + incTrans.x = -TRANS_SPEED * timeDiff; + if (KEYMAP[K_Up]) + incTrans.y = +TRANS_SPEED * timeDiff; + if (KEYMAP[K_Down]) + incTrans.y = -TRANS_SPEED * timeDiff; + + Math::Point rotTrans = Math::RotatePoint(-ROTATION.y, Math::Point(incTrans.x, incTrans.z)); + incTrans.x = rotTrans.x; + incTrans.z = rotTrans.y; + TRANSLATION += incTrans; +} + +void KeyboardDown(SDLKey key) +{ + switch (key) + { + case SDLK_w: + KEYMAP[K_Forward] = true; + break; + case SDLK_s: + KEYMAP[K_Back] = true; + break; + case SDLK_d: + KEYMAP[K_Right] = true; + break; + case SDLK_a: + KEYMAP[K_Left] = true; + break; + case SDLK_z: + KEYMAP[K_Down] = true; + break; + case SDLK_x: + KEYMAP[K_Up] = true; + break; + default: + break; + } +} + +void KeyboardUp(SDLKey key) +{ + switch (key) + { + case SDLK_w: + KEYMAP[K_Forward] = false; + break; + case SDLK_s: + KEYMAP[K_Back] = false; + break; + case SDLK_d: + KEYMAP[K_Right] = false; + break; + case SDLK_a: + KEYMAP[K_Left] = false; + break; + case SDLK_z: + KEYMAP[K_Down] = false; + break; + case SDLK_x: + KEYMAP[K_Up] = false; + break; + default: + break; + } +} + +void MouseMove(int x, int y) +{ + Math::Point currentPos(static_cast(x), static_cast(y)); + + static bool first = true; + if (first || (x < 10) || (y < 10) || (x > 790) || (y > 590)) + { + SDL_WarpMouse(400, 300); + MOUSE_POS_BASE.x = 400; + MOUSE_POS_BASE.y = 300; + ROTATION_BASE = ROTATION; + first = false; + return; + } + + ROTATION.y = ROTATION_BASE.y + (static_cast (x - MOUSE_POS_BASE.x) / 800.0f) * Math::PI; + ROTATION.x = ROTATION_BASE.x + (static_cast (y - MOUSE_POS_BASE.y) / 600.0f) * Math::PI; +} + +int main(int argc, char *argv[]) +{ + CLogger logger; + + PREV_TIME = CreateTimeStamp(); + CURR_TIME = CreateTimeStamp(); + + GetCurrentTimeStamp(PREV_TIME); + GetCurrentTimeStamp(CURR_TIME); + + CInstanceManager iMan; + + // Without any error checking, for simplicity + + SDL_Init(SDL_INIT_VIDEO); + + IMG_Init(IMG_INIT_PNG); + + const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo(); + + Uint32 videoFlags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_HWPALETTE; + + if (videoInfo->hw_available) + videoFlags |= SDL_HWSURFACE; + else + videoFlags |= SDL_SWSURFACE; + + if (videoInfo->blit_hw) + videoFlags |= SDL_HWACCEL; + + + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); + + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 8); + + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + + SDL_Surface *surface = SDL_SetVideoMode(800, 600, 32, videoFlags); + + + SDL_WM_SetCaption("Light Test", "Light Test"); + + //SDL_WM_GrabInput(SDL_GRAB_ON); + SDL_ShowCursor(SDL_DISABLE); + + Gfx::CGLDevice *device = new Gfx::CGLDevice(Gfx::GLDeviceConfig()); + device->Create(); + + Init(device); + + bool done = false; + while (! done) + { + Render(device); + Update(); + + SDL_GL_SwapBuffers(); + + SDL_Event event; + while (SDL_PollEvent(&event)) + { + if (event.type == SDL_QUIT) + { + break; + done = true; + } + else if (event.type == SDL_KEYDOWN) + { + if (event.key.keysym.sym == SDLK_q) + { + done = true; + break; + } + else + KeyboardDown(event.key.keysym.sym); + } + else if (event.type == SDL_KEYUP) + KeyboardUp(event.key.keysym.sym); + else if (event.type == SDL_MOUSEMOTION) + MouseMove(event.motion.x, event.motion.y); + } + + usleep(FRAME_DELAY); + } + + //SDL_WM_GrabInput(SDL_GRAB_OFF); + SDL_ShowCursor(SDL_ENABLE); + + device->Destroy(); + delete device; + + SDL_FreeSurface(surface); + + IMG_Quit(); + + SDL_Quit(); + + DestroyTimeStamp(PREV_TIME); + DestroyTimeStamp(CURR_TIME); + + return 0; +} diff --git a/test/envs/opengl/model_test.cpp b/test/envs/opengl/model_test.cpp new file mode 100644 index 0000000..a06a178 --- /dev/null +++ b/test/envs/opengl/model_test.cpp @@ -0,0 +1,377 @@ +#include "app/system.h" +#include "common/logger.h" +#include "common/image.h" +#include "graphics/engine/modelfile.h" +#include "graphics/opengl/gldevice.h" +#include "math/geometry.h" + +#include +#include +#include + +#include +#include + +enum KeySlots +{ + K_RotXUp, + K_RotXDown, + K_RotYLeft, + K_RotYRight, + K_Forward, + K_Back, + K_Left, + K_Right, + K_Up, + K_Down, + K_Count +}; +bool KEYMAP[K_Count] = { false }; + +Math::Vector TRANSLATION(0.0f, 0.0f, 30.0f); +Math::Vector ROTATION; + +const int FRAME_DELAY = 5000; + +std::map TEXS; + +SystemTimeStamp *PREV_TIME = NULL, *CURR_TIME = NULL; + +Gfx::Texture GetTexture(const std::string &name) +{ + std::map::iterator it = TEXS.find(name); + if (it == TEXS.end()) + return Gfx::Texture(); + + return (*it).second; +} + +void LoadTexture(Gfx::CGLDevice *device, const std::string &name) +{ + if (name.empty()) + return; + + Gfx::Texture tex = GetTexture(name); + + if (tex.Valid()) + return; + + CImage img; + if (! img.Load(std::string("tex/") + name)) + { + std::string err = img.GetError(); + GetLogger()->Error("Texture not loaded, error: %s!\n", err.c_str()); + } + else + { + Gfx::TextureCreateParams texCreateParams; + texCreateParams.mipmap = true; + texCreateParams.minFilter = Gfx::TEX_MIN_FILTER_LINEAR_MIPMAP_LINEAR; + texCreateParams.magFilter = Gfx::TEX_MAG_FILTER_LINEAR; + + tex = device->CreateTexture(&img, texCreateParams); + } + + TEXS[name] = tex; +} + +void Init(Gfx::CGLDevice *device, Gfx::CModelFile *model) +{ + const std::vector &triangles = model->GetTriangles(); + + for (int i = 0; i < static_cast( triangles.size() ); ++i) + { + LoadTexture(device, triangles[i].tex1Name); + LoadTexture(device, triangles[i].tex2Name); + } + + device->SetRenderState(Gfx::RENDER_STATE_LIGHTING, true); + device->SetRenderState(Gfx::RENDER_STATE_DEPTH_TEST, true); + device->SetShadeModel(Gfx::SHADE_SMOOTH); + + Gfx::Light light; + light.type = Gfx::LIGHT_DIRECTIONAL; + light.ambient = Gfx::Color(0.4f, 0.4f, 0.4f, 0.0f); + light.diffuse = Gfx::Color(0.8f, 0.8f, 0.8f, 0.0f); + light.specular = Gfx::Color(0.2f, 0.2f, 0.2f, 0.0f); + light.position = Math::Vector(0.0f, 0.0f, -1.0f); + light.direction = Math::Vector(0.0f, 0.0f, 1.0f); + + device->SetGlobalAmbient(Gfx::Color(0.5f, 0.5f, 0.5f, 0.0f)); + device->SetLight(0, light); + device->SetLightEnabled(0, true); +} + +void Render(Gfx::CGLDevice *device, Gfx::CModelFile *modelFile) +{ + device->BeginScene(); + + Math::Matrix persp; + Math::LoadProjectionMatrix(persp, Math::PI / 4.0f, (800.0f) / (600.0f), 0.1f, 100.0f); + device->SetTransform(Gfx::TRANSFORM_PROJECTION, persp); + + Math::Matrix id; + id.LoadIdentity(); + device->SetTransform(Gfx::TRANSFORM_WORLD, id); + + Math::Matrix viewMat; + Math::LoadTranslationMatrix(viewMat, TRANSLATION); + Math::Matrix rot; + Math::LoadRotationXZYMatrix(rot, ROTATION); + viewMat = Math::MultiplyMatrices(viewMat, rot); + device->SetTransform(Gfx::TRANSFORM_VIEW, viewMat); + + const std::vector &triangles = modelFile->GetTriangles(); + + Gfx::VertexTex2 tri[3]; + + for (int i = 0; i < static_cast( triangles.size() ); ++i) + { + device->SetTexture(0, GetTexture(triangles[i].tex1Name)); + device->SetTexture(1, GetTexture(triangles[i].tex2Name)); + device->SetTextureEnabled(0, true); + device->SetTextureEnabled(1, true); + + device->SetMaterial(triangles[i].material); + + tri[0] = triangles[i].p1; + tri[1] = triangles[i].p2; + tri[2] = triangles[i].p3; + + device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLES, tri, 3); + } + + device->EndScene(); +} + +void Update() +{ + const float ROT_SPEED = 80.0f * Math::DEG_TO_RAD; // rad / sec + const float TRANS_SPEED = 3.0f; // units / sec + + GetCurrentTimeStamp(CURR_TIME); + float timeDiff = TimeStampDiff(PREV_TIME, CURR_TIME, STU_SEC); + CopyTimeStamp(PREV_TIME, CURR_TIME); + + if (KEYMAP[K_RotYLeft]) + ROTATION.y -= ROT_SPEED * timeDiff; + if (KEYMAP[K_RotYRight]) + ROTATION.y += ROT_SPEED * timeDiff; + if (KEYMAP[K_RotXDown]) + ROTATION.x -= ROT_SPEED * timeDiff; + if (KEYMAP[K_RotXUp]) + ROTATION.x += ROT_SPEED * timeDiff; + + if (KEYMAP[K_Forward]) + TRANSLATION.z -= TRANS_SPEED * timeDiff; + if (KEYMAP[K_Back]) + TRANSLATION.z += TRANS_SPEED * timeDiff; + if (KEYMAP[K_Left]) + TRANSLATION.x += TRANS_SPEED * timeDiff; + if (KEYMAP[K_Right]) + TRANSLATION.x -= TRANS_SPEED * timeDiff; + if (KEYMAP[K_Up]) + TRANSLATION.y += TRANS_SPEED * timeDiff; + if (KEYMAP[K_Down]) + TRANSLATION.y -= TRANS_SPEED * timeDiff; +} + +void KeyboardDown(SDLKey key) +{ + switch (key) + { + case SDLK_LEFT: + KEYMAP[K_RotYLeft] = true; + break; + case SDLK_RIGHT: + KEYMAP[K_RotYRight] = true; + break; + case SDLK_UP: + KEYMAP[K_RotXUp] = true; + break; + case SDLK_DOWN: + KEYMAP[K_RotXDown] = true; + break; + case SDLK_w: + KEYMAP[K_Forward] = true; + break; + case SDLK_s: + KEYMAP[K_Back] = true; + break; + case SDLK_a: + KEYMAP[K_Left] = true; + break; + case SDLK_d: + KEYMAP[K_Right] = true; + break; + case SDLK_z: + KEYMAP[K_Down] = true; + break; + case SDLK_x: + KEYMAP[K_Up] = true; + break; + default: + break; + } +} + +void KeyboardUp(SDLKey key) +{ + switch (key) + { + case SDLK_LEFT: + KEYMAP[K_RotYLeft] = false; + break; + case SDLK_RIGHT: + KEYMAP[K_RotYRight] = false; + break; + case SDLK_UP: + KEYMAP[K_RotXUp] = false; + break; + case SDLK_DOWN: + KEYMAP[K_RotXDown] = false; + break; + case SDLK_w: + KEYMAP[K_Forward] = false; + break; + case SDLK_s: + KEYMAP[K_Back] = false; + break; + case SDLK_a: + KEYMAP[K_Left] = false; + break; + case SDLK_d: + KEYMAP[K_Right] = false; + break; + case SDLK_z: + KEYMAP[K_Down] = false; + break; + case SDLK_x: + KEYMAP[K_Up] = false; + break; + default: + break; + } +} + +int main(int argc, char *argv[]) +{ + CLogger logger; + + PREV_TIME = CreateTimeStamp(); + CURR_TIME = CreateTimeStamp(); + + GetCurrentTimeStamp(PREV_TIME); + GetCurrentTimeStamp(CURR_TIME); + + if (argc != 3) + { + std::cerr << "Usage: " << argv[0] << "{old|new_txt|new_bin} model_file" << std::endl; + return 1; + } + + Gfx::CModelFile *modelFile = new Gfx::CModelFile(); + if (std::string(argv[1]) == "old") + { + if (! modelFile->ReadModel(argv[2])) + { + std::cerr << "Error reading model file" << std::endl; + return 1; + } + } + else if (std::string(argv[1]) == "new_txt") + { + if (! modelFile->ReadTextModel(argv[2])) + { + std::cerr << "Error reading model file" << std::endl; + return 1; + } + } + else if (std::string(argv[1]) == "new_bin") + { + if (! modelFile->ReadBinaryModel(argv[2])) + { + std::cerr << "Error reading model file" << std::endl; + return 1; + } + } + else + { + std::cerr << "Usage: " << argv[0] << "{old|new_txt|new_bin} model_file" << std::endl; + return 1; + } + + // Without any error checking, for simplicity + + SDL_Init(SDL_INIT_VIDEO); + + IMG_Init(IMG_INIT_PNG); + + const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo(); + + Uint32 videoFlags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_HWPALETTE; + + if (videoInfo->hw_available) + videoFlags |= SDL_HWSURFACE; + else + videoFlags |= SDL_SWSURFACE; + + if (videoInfo->blit_hw) + videoFlags |= SDL_HWACCEL; + + + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); + + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 8); + + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + + SDL_Surface *surface = SDL_SetVideoMode(800, 600, 32, videoFlags); + + + SDL_WM_SetCaption("Model Test", "Model Test"); + + Gfx::CGLDevice *device = new Gfx::CGLDevice(Gfx::GLDeviceConfig()); + device->Create(); + + Init(device, modelFile); + + bool done = false; + while (! done) + { + Render(device, modelFile); + Update(); + + SDL_GL_SwapBuffers(); + + SDL_Event event; + SDL_PollEvent(&event); + if (event.type == SDL_QUIT) + done = true; + else if (event.type == SDL_KEYDOWN) + KeyboardDown(event.key.keysym.sym); + else if (event.type == SDL_KEYUP) + KeyboardUp(event.key.keysym.sym); + + usleep(FRAME_DELAY); + } + + delete modelFile; + + device->Destroy(); + delete device; + + SDL_FreeSurface(surface); + + IMG_Quit(); + + SDL_Quit(); + + DestroyTimeStamp(PREV_TIME); + DestroyTimeStamp(CURR_TIME); + + return 0; +} diff --git a/test/envs/opengl/tex1.png b/test/envs/opengl/tex1.png new file mode 100644 index 0000000..46c68a0 Binary files /dev/null and b/test/envs/opengl/tex1.png differ diff --git a/test/envs/opengl/tex2.png b/test/envs/opengl/tex2.png new file mode 100644 index 0000000..ebdae0d Binary files /dev/null and b/test/envs/opengl/tex2.png differ diff --git a/test/envs/opengl/texture_test.cpp b/test/envs/opengl/texture_test.cpp new file mode 100644 index 0000000..de9caf3 --- /dev/null +++ b/test/envs/opengl/texture_test.cpp @@ -0,0 +1,192 @@ +#include "common/logger.h" +#include "common/image.h" +#include "graphics/opengl/gldevice.h" +#include "math/geometry.h" + +#include +#include +#include + + +void Init(Gfx::CGLDevice *device) +{ + device->SetShadeModel(Gfx::SHADE_SMOOTH); + + device->SetRenderState(Gfx::RENDER_STATE_DEPTH_TEST, false); + + device->SetTextureEnabled(0, true); + device->SetTextureEnabled(1, true); + + CImage img1; + if (! img1.Load("tex1.png")) + { + std::string err = img1.GetError(); + GetLogger()->Error("texture 1 not loaded, error: %s!\n", err.c_str()); + } + CImage img2; + if (! img2.Load("tex2.png")) + { + std::string err = img2.GetError(); + GetLogger()->Error("texture 2 not loaded, error: %s!\n", err.c_str()); + } + + Gfx::TextureCreateParams tex1CreateParams; + tex1CreateParams.mipmap = true; + tex1CreateParams.format = Gfx::TEX_IMG_RGBA; + tex1CreateParams.minFilter = Gfx::TEX_MIN_FILTER_LINEAR_MIPMAP_LINEAR; + tex1CreateParams.magFilter = Gfx::TEX_MAG_FILTER_LINEAR; + + Gfx::TextureCreateParams tex2CreateParams; + tex2CreateParams.mipmap = true; + tex2CreateParams.format = Gfx::TEX_IMG_RGBA; + tex2CreateParams.minFilter = Gfx::TEX_MIN_FILTER_NEAREST_MIPMAP_NEAREST; + tex2CreateParams.magFilter = Gfx::TEX_MAG_FILTER_NEAREST; + + Gfx::Texture tex1 = device->CreateTexture(&img1, tex1CreateParams); + Gfx::Texture tex2 = device->CreateTexture(&img2, tex2CreateParams); + + device->SetTexture(0, tex1); + device->SetTexture(1, tex2); +} + +void Render(Gfx::CGLDevice *device) +{ + device->BeginScene(); + + Math::Matrix ortho; + Math::LoadOrthoProjectionMatrix(ortho, -10, 10, -10, 10); + device->SetTransform(Gfx::TRANSFORM_PROJECTION, ortho); + + Math::Matrix id; + id.LoadIdentity(); + + device->SetTransform(Gfx::TRANSFORM_WORLD, id); + device->SetTransform(Gfx::TRANSFORM_VIEW, id); + + static Gfx::VertexTex2 quad[] = + { + Gfx::VertexTex2(Math::Vector(-2.0f, 2.0f, 0.0f), Math::Vector(), Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f)), + Gfx::VertexTex2(Math::Vector( 2.0f, 2.0f, 0.0f), Math::Vector(), Math::Point(1.0f, 0.0f), Math::Point(1.0f, 0.0f)), + Gfx::VertexTex2(Math::Vector( 2.0f, -2.0f, 0.0f), Math::Vector(), Math::Point(1.0f, 1.0f), Math::Point(1.0f, 1.0f)), + + Gfx::VertexTex2(Math::Vector( 2.0f, -2.0f, 0.0f), Math::Vector(), Math::Point(1.0f, 1.0f), Math::Point(1.0f, 1.0f)), + Gfx::VertexTex2(Math::Vector(-2.0f, -2.0f, 0.0f), Math::Vector(), Math::Point(0.0f, 1.0f), Math::Point(0.0f, 1.0f)), + Gfx::VertexTex2(Math::Vector(-2.0f, 2.0f, 0.0f), Math::Vector(), Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f)), + }; + + Gfx::TextureStageParams tex1StageParams; + tex1StageParams.colorOperation = Gfx::TEX_MIX_OPER_DEFAULT; + tex1StageParams.alphaOperation = Gfx::TEX_MIX_OPER_DEFAULT; + device->SetTextureStageParams(0, tex1StageParams); + + Gfx::TextureStageParams tex2StageParams; + tex2StageParams.colorOperation = Gfx::TEX_MIX_OPER_DEFAULT; + tex2StageParams.alphaOperation = Gfx::TEX_MIX_OPER_DEFAULT; + device->SetTextureStageParams(1, tex2StageParams); + + Math::Matrix t; + Math::LoadTranslationMatrix(t, Math::Vector(-4.0f, 4.0f, 0.0f)); + device->SetTransform(Gfx::TRANSFORM_VIEW, t); + + device->SetTextureEnabled(0, true); + device->SetTextureEnabled(1, false); + + device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLES, quad, 6); + + Math::LoadTranslationMatrix(t, Math::Vector( 4.0f, 4.0f, 0.0f)); + device->SetTransform(Gfx::TRANSFORM_VIEW, t); + + device->SetTextureEnabled(0, false); + device->SetTextureEnabled(1, true); + + device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLES, quad, 6); + + Math::LoadTranslationMatrix(t, Math::Vector( 0.0f, -4.0f, 0.0f)); + device->SetTransform(Gfx::TRANSFORM_VIEW, t); + + device->SetTextureEnabled(0, true); + device->SetTextureEnabled(1, true); + + tex1StageParams.colorOperation = Gfx::TEX_MIX_OPER_DEFAULT; + tex1StageParams.alphaOperation = Gfx::TEX_MIX_OPER_DEFAULT; + device->SetTextureStageParams(0, tex1StageParams); + + tex2StageParams.colorOperation = Gfx::TEX_MIX_OPER_ADD; + tex2StageParams.colorArg1 = Gfx::TEX_MIX_ARG_COMPUTED_COLOR; + tex2StageParams.colorArg2 = Gfx::TEX_MIX_ARG_TEXTURE; + tex2StageParams.alphaOperation = Gfx::TEX_MIX_OPER_DEFAULT; + device->SetTextureStageParams(1, tex2StageParams); + + device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLES, quad, 6); + + device->EndScene(); +} + +int main() +{ + CLogger logger; + + // Without any error checking, for simplicity + + SDL_Init(SDL_INIT_VIDEO); + + IMG_Init(IMG_INIT_PNG); + + const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo(); + + Uint32 videoFlags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_HWPALETTE; + + if (videoInfo->hw_available) + videoFlags |= SDL_HWSURFACE; + else + videoFlags |= SDL_SWSURFACE; + + if (videoInfo->blit_hw) + videoFlags |= SDL_HWACCEL; + + + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); + + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 8); + + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + + SDL_Surface *surface = SDL_SetVideoMode(800, 600, 32, videoFlags); + + + SDL_WM_SetCaption("Texture Test", "Texture Test"); + + Gfx::CGLDevice *device = new Gfx::CGLDevice(Gfx::GLDeviceConfig()); + device->Create(); + + Init(device); + + bool done = false; + while (! done) + { + Render(device); + + SDL_GL_SwapBuffers(); + + SDL_Event event; + SDL_PollEvent(&event); + if (event.type == SDL_QUIT) + done = true; + + usleep(10000); + } + + device->Destroy(); + delete device; + + SDL_FreeSurface(surface); + + IMG_Quit(); + + SDL_Quit(); + + return 0; +} diff --git a/test/envs/opengl/transform_test.cpp b/test/envs/opengl/transform_test.cpp new file mode 100644 index 0000000..cddd1b8 --- /dev/null +++ b/test/envs/opengl/transform_test.cpp @@ -0,0 +1,339 @@ +#include "app/system.h" +#include "common/logger.h" +#include "common/image.h" +#include "common/iman.h" +#include "graphics/opengl/gldevice.h" +#include "math/geometry.h" + +#include +#include +#include + +#include +#include + +enum KeySlots +{ + K_Forward, + K_Back, + K_Left, + K_Right, + K_Up, + K_Down, + K_Count +}; +bool KEYMAP[K_Count] = { false }; + +Math::Point MOUSE_POS_BASE; + +Math::Vector TRANSLATION(0.0f, 2.0f, 0.0f); +Math::Vector ROTATION, ROTATION_BASE; + +const int FRAME_DELAY = 5000; + +SystemTimeStamp *PREV_TIME = NULL, *CURR_TIME = NULL; + +void Init(Gfx::CGLDevice *device) +{ + device->SetRenderState(Gfx::RENDER_STATE_DEPTH_TEST, true); + device->SetShadeModel(Gfx::SHADE_SMOOTH); +} + +void Render(Gfx::CGLDevice *device) +{ + device->BeginScene(); + + Math::Matrix persp; + Math::LoadProjectionMatrix(persp, Math::PI / 4.0f, (800.0f) / (600.0f), 0.1f, 100.0f); + device->SetTransform(Gfx::TRANSFORM_PROJECTION, persp); + + + Math::Matrix viewMat; + Math::Matrix mat; + + viewMat.LoadIdentity(); + + Math::LoadRotationXMatrix(mat, -ROTATION.x); + viewMat = Math::MultiplyMatrices(viewMat, mat); + + Math::LoadRotationYMatrix(mat, -ROTATION.y); + viewMat = Math::MultiplyMatrices(viewMat, mat); + + Math::LoadTranslationMatrix(mat, -TRANSLATION); + viewMat = Math::MultiplyMatrices(viewMat, mat); + + device->SetTransform(Gfx::TRANSFORM_VIEW, viewMat); + + + Math::Matrix worldMat; + worldMat.LoadIdentity(); + device->SetTransform(Gfx::TRANSFORM_WORLD, worldMat); + + Gfx::VertexCol line[2] = { Gfx::VertexCol() }; + + for (int x = -40; x <= 40; ++x) + { + line[0].color = Gfx::Color(0.7f + x / 120.0f, 0.0f, 0.0f); + line[0].coord.z = -40; + line[0].coord.x = x; + line[1].color = Gfx::Color(0.7f + x / 120.0f, 0.0f, 0.0f); + line[1].coord.z = 40; + line[1].coord.x = x; + device->DrawPrimitive(Gfx::PRIMITIVE_LINES, line, 2); + } + + for (int z = -40; z <= 40; ++z) + { + line[0].color = Gfx::Color(0.0f, 0.7f + z / 120.0f, 0.0f); + line[0].coord.z = z; + line[0].coord.x = -40; + line[1].color = Gfx::Color(0.0f, 0.7f + z / 120.0f, 0.0f); + line[1].coord.z = z; + line[1].coord.x = 40; + device->DrawPrimitive(Gfx::PRIMITIVE_LINES, line, 2); + } + + + Gfx::VertexCol quad[6] = { Gfx::VertexCol() }; + + for (int i = 0; i < 6; ++i) + quad[i].color = Gfx::Color(1.0f, 1.0f, 0.0f); + + quad[0].coord = Math::Vector(-1.0f, -1.0f, 0.0f); + quad[1].coord = Math::Vector( 1.0f, -1.0f, 0.0f); + quad[2].coord = Math::Vector( 1.0f, 1.0f, 0.0f); + quad[3].coord = Math::Vector( 1.0f, 1.0f, 0.0f); + quad[4].coord = Math::Vector(-1.0f, 1.0f, 0.0f); + quad[5].coord = Math::Vector(-1.0f, -1.0f, 0.0f); + + Math::LoadTranslationMatrix(worldMat, Math::Vector(40.0f, 2.0f, 40.0f)); + device->SetTransform(Gfx::TRANSFORM_WORLD, worldMat); + + device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLES, quad, 6); + + for (int i = 0; i < 6; ++i) + quad[i].color = Gfx::Color(0.0f, 1.0f, 1.0f); + + Math::LoadTranslationMatrix(worldMat, Math::Vector(-40.0f, 2.0f, -40.0f)); + device->SetTransform(Gfx::TRANSFORM_WORLD, worldMat); + + device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLES, quad, 6); + + for (int i = 0; i < 6; ++i) + quad[i].color = Gfx::Color(1.0f, 0.0f, 1.0f); + + Math::LoadTranslationMatrix(worldMat, Math::Vector(0.0f, 10.0f, 0.0f)); + device->SetTransform(Gfx::TRANSFORM_WORLD, worldMat); + + device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLES, quad, 6); + + device->EndScene(); +} + +void Update() +{ + const float TRANS_SPEED = 6.0f; // units / sec + + GetCurrentTimeStamp(CURR_TIME); + float timeDiff = TimeStampDiff(PREV_TIME, CURR_TIME, STU_SEC); + CopyTimeStamp(PREV_TIME, CURR_TIME); + + Math::Vector incTrans; + + if (KEYMAP[K_Forward]) + incTrans.z = +TRANS_SPEED * timeDiff; + if (KEYMAP[K_Back]) + incTrans.z = -TRANS_SPEED * timeDiff; + if (KEYMAP[K_Right]) + incTrans.x = +TRANS_SPEED * timeDiff; + if (KEYMAP[K_Left]) + incTrans.x = -TRANS_SPEED * timeDiff; + if (KEYMAP[K_Up]) + incTrans.y = +TRANS_SPEED * timeDiff; + if (KEYMAP[K_Down]) + incTrans.y = -TRANS_SPEED * timeDiff; + + Math::Point rotTrans = Math::RotatePoint(-ROTATION.y, Math::Point(incTrans.x, incTrans.z)); + incTrans.x = rotTrans.x; + incTrans.z = rotTrans.y; + TRANSLATION += incTrans; +} + +void KeyboardDown(SDLKey key) +{ + switch (key) + { + case SDLK_w: + KEYMAP[K_Forward] = true; + break; + case SDLK_s: + KEYMAP[K_Back] = true; + break; + case SDLK_d: + KEYMAP[K_Right] = true; + break; + case SDLK_a: + KEYMAP[K_Left] = true; + break; + case SDLK_z: + KEYMAP[K_Down] = true; + break; + case SDLK_x: + KEYMAP[K_Up] = true; + break; + default: + break; + } +} + +void KeyboardUp(SDLKey key) +{ + switch (key) + { + case SDLK_w: + KEYMAP[K_Forward] = false; + break; + case SDLK_s: + KEYMAP[K_Back] = false; + break; + case SDLK_d: + KEYMAP[K_Right] = false; + break; + case SDLK_a: + KEYMAP[K_Left] = false; + break; + case SDLK_z: + KEYMAP[K_Down] = false; + break; + case SDLK_x: + KEYMAP[K_Up] = false; + break; + default: + break; + } +} + +void MouseMove(int x, int y) +{ + Math::Point currentPos(static_cast(x), static_cast(y)); + + static bool first = true; + if (first || (x < 10) || (y < 10) || (x > 790) || (y > 590)) + { + SDL_WarpMouse(400, 300); + MOUSE_POS_BASE.x = 400; + MOUSE_POS_BASE.y = 300; + ROTATION_BASE = ROTATION; + first = false; + return; + } + + ROTATION.y = ROTATION_BASE.y + (static_cast (x - MOUSE_POS_BASE.x) / 800.0f) * Math::PI; + ROTATION.x = ROTATION_BASE.x + (static_cast (y - MOUSE_POS_BASE.y) / 600.0f) * Math::PI; +} + +int main(int argc, char *argv[]) +{ + CLogger logger; + + PREV_TIME = CreateTimeStamp(); + CURR_TIME = CreateTimeStamp(); + + GetCurrentTimeStamp(PREV_TIME); + GetCurrentTimeStamp(CURR_TIME); + + CInstanceManager iMan; + + // Without any error checking, for simplicity + + SDL_Init(SDL_INIT_VIDEO); + + IMG_Init(IMG_INIT_PNG); + + const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo(); + + Uint32 videoFlags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_HWPALETTE; + + if (videoInfo->hw_available) + videoFlags |= SDL_HWSURFACE; + else + videoFlags |= SDL_SWSURFACE; + + if (videoInfo->blit_hw) + videoFlags |= SDL_HWACCEL; + + + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); + + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 8); + + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + + SDL_Surface *surface = SDL_SetVideoMode(800, 600, 32, videoFlags); + + + SDL_WM_SetCaption("Transform Test", "Transform Test"); + + //SDL_WM_GrabInput(SDL_GRAB_ON); + SDL_ShowCursor(SDL_DISABLE); + + Gfx::CGLDevice *device = new Gfx::CGLDevice(Gfx::GLDeviceConfig()); + device->Create(); + + Init(device); + + bool done = false; + while (! done) + { + Render(device); + Update(); + + SDL_GL_SwapBuffers(); + + SDL_Event event; + while (SDL_PollEvent(&event)) + { + if (event.type == SDL_QUIT) + { + break; + done = true; + } + else if (event.type == SDL_KEYDOWN) + { + if (event.key.keysym.sym == SDLK_q) + { + done = true; + break; + } + else + KeyboardDown(event.key.keysym.sym); + } + else if (event.type == SDL_KEYUP) + KeyboardUp(event.key.keysym.sym); + else if (event.type == SDL_MOUSEMOTION) + MouseMove(event.motion.x, event.motion.y); + } + + usleep(FRAME_DELAY); + } + + //SDL_WM_GrabInput(SDL_GRAB_OFF); + SDL_ShowCursor(SDL_ENABLE); + + device->Destroy(); + delete device; + + SDL_FreeSurface(surface); + + IMG_Quit(); + + SDL_Quit(); + + DestroyTimeStamp(PREV_TIME); + DestroyTimeStamp(CURR_TIME); + + return 0; +} diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt new file mode 100644 index 0000000..f6a1d75 --- /dev/null +++ b/test/unit/CMakeLists.txt @@ -0,0 +1,24 @@ +set(SRC_DIR ${colobot_SOURCE_DIR}/src) + +include_directories( +${SRC_DIR} +${GTEST_INCLUDE_DIR} +math +common +) + +set(UT_SOURCES +main.cpp +math/geometry_test.cpp +math/matrix_test.cpp +math/vector_test.cpp +) + +add_executable(colobot_ut ${UT_SOURCES}) +target_link_libraries(colobot_ut gtest) + +add_test(colobot_ut ./colobot_ut) + +# TODO: change the unit cases to independent automated tests to be included in colobot_ut +add_subdirectory(common) +add_subdirectory(ui) diff --git a/test/unit/common/CMakeLists.txt b/test/unit/common/CMakeLists.txt new file mode 100644 index 0000000..a34c708 --- /dev/null +++ b/test/unit/common/CMakeLists.txt @@ -0,0 +1,16 @@ +set(SRC_DIR ${colobot_SOURCE_DIR}/src) + +include_directories( +${SRC_DIR} +${GTEST_INCLUDE_DIR} +) + +add_executable(image_test ${SRC_DIR}/common/image.cpp image_test.cpp) +target_link_libraries(image_test ${SDL_LIBRARY} ${SDLIMAGE_LIBRARY} ${PNG_LIBRARIES}) + +file(COPY colobot.ini DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) + +add_executable(profile_test ${SRC_DIR}/common/profile.cpp ${SRC_DIR}/common/logger.cpp profile_test.cpp) +target_link_libraries(profile_test gtest ${Boost_LIBRARIES}) + +add_test(profile_test ./profile_test) diff --git a/test/unit/common/colobot.ini b/test/unit/common/colobot.ini new file mode 100644 index 0000000..2ca37ee --- /dev/null +++ b/test/unit/common/colobot.ini @@ -0,0 +1,15 @@ +[test_float] +float_value=1.5 + +[test_string] +string_value=Hello world + +[test_int] +int_value=42 + +[test_multi] +entry1=1 +entry2=2 +entry3=3 +entry4=4 +entry5=5 diff --git a/test/unit/common/image_test.cpp b/test/unit/common/image_test.cpp new file mode 100644 index 0000000..2a8d5e4 --- /dev/null +++ b/test/unit/common/image_test.cpp @@ -0,0 +1,57 @@ +#include "common/image.h" + +#include +#include + +/* For now, just a simple test: loading a file from image + * and saving it to another in PNG. */ + +int main(int argc, char *argv[]) +{ + if (argc != 3) + { + printf("Usage: %s in_image out_image\n", argv[0]); + return 0; + } + + CImage image; + + if (! image.Load(argv[1])) + { + std::string err = image.GetError(); + printf("Error loading '%s': %s\n", argv[1], err.c_str()); + return 1; + } + Gfx::Color color; + std::string str; + + color = image.GetPixel(Math::IntPoint(0, 0)); + str = color.ToString(); + printf("pixel @ (0,0): %s\n", str.c_str()); + + color = image.GetPixel(Math::IntPoint(0, 1)); + str = color.ToString(); + printf("pixel @ (0,1): %s\n", str.c_str()); + + color = image.GetPixel(Math::IntPoint(1, 0)); + str = color.ToString(); + printf("pixel @ (1,0): %s\n", str.c_str()); + + color = image.GetPixel(Math::IntPoint(1, 1)); + str = color.ToString(); + printf("pixel @ (1,1): %s\n", str.c_str()); + + image.SetPixel(Math::IntPoint(0, 0), Gfx::Color(0.1f, 0.2f, 0.3f, 0.0f)); + image.SetPixel(Math::IntPoint(1, 0), Gfx::Color(0.3f, 0.2f, 0.1f, 1.0f)); + image.SetPixel(Math::IntPoint(0, 1), Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f)); + image.SetPixel(Math::IntPoint(1, 1), Gfx::Color(0.0f, 0.0f, 0.0f, 1.0f)); + + if (! image.SavePNG(argv[2])) + { + std::string err = image.GetError(); + printf("Error saving PNG '%s': %s\n", argv[2], err.c_str()); + return 2; + } + + return 0; +} diff --git a/test/unit/common/profile_test.cpp b/test/unit/common/profile_test.cpp new file mode 100644 index 0000000..e7b64d5 --- /dev/null +++ b/test/unit/common/profile_test.cpp @@ -0,0 +1,43 @@ +#include "common/profile.h" +#include "common/logger.h" + +#include +#include +#include +#include + + +class CProfileTest : public testing::Test +{ +protected: + CLogger m_logger; + CProfile m_profile; + +}; + +TEST_F(CProfileTest, ReadTest) +{ + ASSERT_TRUE(m_profile.InitCurrentDirectory()); // load colobot.ini file + + std::string result; + ASSERT_TRUE(m_profile.GetLocalProfileString("test_string", "string_value", result)); + ASSERT_STREQ("Hello world", result.c_str()); + + int int_value; + ASSERT_TRUE(m_profile.GetLocalProfileInt("test_int", "int_value", int_value)); + ASSERT_EQ(42, int_value); + + float float_value; + ASSERT_TRUE(m_profile.GetLocalProfileFloat("test_float", "float_value", float_value)); + ASSERT_FLOAT_EQ(1.5, float_value); + + std::vector list; + list = m_profile.GetLocalProfileSection("test_multi", "entry"); + ASSERT_EQ(5u, list.size()); +} + +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/test/unit/main.cpp b/test/unit/main.cpp new file mode 100644 index 0000000..e978630 --- /dev/null +++ b/test/unit/main.cpp @@ -0,0 +1,24 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 2012, Polish Portal of Colobot (PPC) +// * +// * This program is free software: you can redistribute it and/or modify +// * it under the terms of the GNU General Public License as published by +// * the Free Software Foundation, either version 3 of the License, or +// * (at your option) any later version. +// * +// * This program is distributed in the hope that it will be useful, +// * but WITHOUT ANY WARRANTY; without even the implied warranty of +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// * GNU General Public License for more details. +// * +// * You should have received a copy of the GNU General Public License +// * along with this program. If not, see http://www.gnu.org/licenses/. + +#include "gtest/gtest.h" + +int main(int argc, char* argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +} diff --git a/test/unit/math/gendata.m b/test/unit/math/gendata.m new file mode 100644 index 0000000..5c13491 --- /dev/null +++ b/test/unit/math/gendata.m @@ -0,0 +1,86 @@ +% Script in Octave for generating test data + +1; + +% Returns the minor matrix +function m = minor(A, r, c) + + m = A; + m(r,:) = []; + m(:,c) = []; + +end; + +% Returns the cofactor matrix +function m = cofactors(A) + + m = zeros(rows(A), columns(A)); + + for r = [1 : rows(A)] + for c = [1 : columns(A)] + m(r, c) = det(minor(A, r, c)); + if (mod(r + c, 2) == 1) + m(r, c) = -m(r, c); + end; + end; + end; + +end; + +% Prints the matrix as C++ code +function printout(A, name) + + printf('const float %s[16] = \n', name); + printf('{\n'); + + for c = [1 : columns(A)] + for r = [1 : rows(A)] + printf(' %f', A(r,c)); + if (! ( (r == 4) && (c == 4) ) ) + printf(','); + end; + printf('\n'); + end; + end; + + printf('};\n'); + +end; + +printf('// Cofactors\n'); +A = randn(4,4); +printout(A, 'COF_MAT'); +printf('\n'); +printout(cofactors(A), 'COF_RESULT'); +printf('\n'); + +printf('\n'); + +printf('// Det\n'); +A = randn(4,4); +printout(A, 'DET_MAT'); +printf('\n'); +printf('const float DET_RESULT = %f;', det(A)); +printf('\n'); + +printf('\n'); + +printf('// Invert\n'); +A = randn(4,4); +printout(A, 'INV_MAT'); +printf('\n'); +printout(inv(A), 'COF_RESULT'); +printf('\n'); + +printf('\n'); + +printf('// Multiplication\n'); +A = randn(4,4); +printout(A, 'MUL_A'); +printf('\n'); +B = randn(4,4); +printout(B, 'MUL_B'); +printf('\n'); +C = A * B; +printout(C, 'MUL_RESULT'); +printf('\n'); diff --git a/test/unit/math/geometry_test.cpp b/test/unit/math/geometry_test.cpp new file mode 100644 index 0000000..f50df4e --- /dev/null +++ b/test/unit/math/geometry_test.cpp @@ -0,0 +1,352 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 2012, Polish Portal of Colobot (PPC) +// * +// * This program is free software: you can redistribute it and/or modify +// * it under the terms of the GNU General Public License as published by +// * the Free Software Foundation, either version 3 of the License, or +// * (at your option) any later version. +// * +// * This program is distributed in the hope that it will be useful, +// * but WITHOUT ANY WARRANTY; without even the implied warranty of +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// * GNU General Public License for more details. +// * +// * You should have received a copy of the GNU General Public License +// * along with this program. If not, see http://www.gnu.org/licenses/. + +// math/test/geometry_test.cpp + +/* Unit tests for functions in geometry.h */ + +#include "math/func.h" +#include "math/geometry.h" + +#include "gtest/gtest.h" + + +const float TEST_TOLERANCE = 1e-5; + + +// Test for rewritten function RotateAngle() +TEST(GeometryTest, RotateAngleTest) +{ + EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(0.0f, 0.0f), 0.0f, TEST_TOLERANCE)); + + EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(1.0f, 0.0f), 0.0f, TEST_TOLERANCE)); + + EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(1.0f, 1.0f), 0.25f * Math::PI, TEST_TOLERANCE)); + + EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(0.0f, 2.0f), 0.5f * Math::PI, TEST_TOLERANCE)); + + EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(-0.5f, 0.5f), 0.75f * Math::PI, TEST_TOLERANCE)); + + EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(-1.0f, 0.0f), Math::PI, TEST_TOLERANCE)); + + EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(-1.0f, -1.0f), 1.25f * Math::PI, TEST_TOLERANCE)); + + EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(0.0f, -2.0f), 1.5f * Math::PI, TEST_TOLERANCE)); + + EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(1.0f, -1.0f), 1.75f * Math::PI, TEST_TOLERANCE)); +} + +// Tests for other altered, complex or uncertain functions + +/* + + TODO: write meaningful tests with proper test values + +int TestAngle() +{ + const Math::Vector u(-0.0786076246943884, 0.2231249091714256, -1.1601361718477805); + const Math::Vector v(-1.231228742001907, -1.720549809950561, -0.690468438834111); + + float mathResult = Math::Angle(u, v); + float oldMathResult = Angle(VEC_TO_D3DVEC(u), VEC_TO_D3DVEC(v)); + + if (! Math::IsEqual(mathResult, oldMathResult, TEST_TOLERANCE) ) + return __LINE__; + + return 0; +} + +int TestRotateView() +{ + const Math::Vector center(0.617909142705555, 0.896939729454538, -0.615041943652284); + const float angleH = 44.5; + const float angleV = 12.3; + const float dist = 34.76; + + Math::Vector mathResult = Math::RotateView(center, angleH, angleV, dist); + Math::Vector oldMathResult = D3DVEC_TO_VEC(RotateView(VEC_TO_D3DVEC(center), angleH, angleV, dist)); + + if (! Math::VectorsEqual(mathResult, oldMathResult, TEST_TOLERANCE)) + return __LINE__; + + return 0; +} + +int TestLookatPoint() +{ + const Math::Vector eye(-2.451183170579471, 0.241270270546559, -0.490677411454893); + const float angleH = 48.4; + const float angleV = 32.4; + const float length = 74.44; + + Math::Vector mathResult = Math::LookatPoint(eye, angleH, angleV, length); + Math::Vector oldMathResult = D3DVEC_TO_VEC(LookatPoint(VEC_TO_D3DVEC(eye), angleH, angleV, length)); + + if (! Math::VectorsEqual(mathResult, oldMathResult, TEST_TOLERANCE)) + return __LINE__; + + return 0; +} + +int TestProjection() +{ + const Math::Vector a(0.852064846846319, -0.794279497087496, -0.655779805476688); + const Math::Vector b(-0.245838834102304, -0.841115596038861, 0.470457161487799); + const Math::Vector p(2.289326061164255, -0.505511362271196, 0.660204551169491); + + Math::Vector mathResult = Math::Projection(a, b, p); + Math::Vector oldMathResult = D3DVEC_TO_VEC(Projection(VEC_TO_D3DVEC(a), VEC_TO_D3DVEC(b), VEC_TO_D3DVEC(p))); + + if (! Math::VectorsEqual(mathResult, oldMathResult, TEST_TOLERANCE)) + return __LINE__; + + return 0; +} + +int TestLoadViewMatrix() +{ + const Math::Vector from(2.5646013154868874, -0.6058794133917031, -0.0441195127419744); + const Math::Vector at(0.728044925765569, -0.206343977871841, 2.543158236935463); + const Math::Vector worldUp(-1.893738133660711, -1.009584441407070, 0.521745988225582); + + Math::Matrix mathResult; + Math::LoadViewMatrix(mathResult, from, at, worldUp); + + Math::Matrix oldMathResult; + { + D3DMATRIX mat; + D3DVECTOR fromD3D = VEC_TO_D3DVEC(from); + D3DVECTOR atD3D = VEC_TO_D3DVEC(at); + D3DVECTOR worldUpD3D = VEC_TO_D3DVEC(worldUp); + D3DUtil_SetViewMatrix(mat, fromD3D, atD3D, worldUpD3D); + oldMathResult = D3DMAT_TO_MAT(mat); + } + + if (! Math::MatricesEqual(mathResult, oldMathResult, TEST_TOLERANCE)) + return __LINE__; + + return 0; +} + +int TestLoadProjectionMatrix() +{ + const float fov = 76.3f; + const float aspect = 0.891f; + const float nearPlane = 12.3f; + const float farPlane = 1238.9f; + + Math::Matrix mathResult; + Math::LoadProjectionMatrix(mathResult, fov, aspect, nearPlane, farPlane); + + Math::Matrix oldMathResult; + { + D3DMATRIX mat; + D3DUtil_SetProjectionMatrix(mat, fov, aspect, nearPlane, farPlane); + oldMathResult = D3DMAT_TO_MAT(mat); + } + + if (! Math::MatricesEqual(mathResult, oldMathResult, TEST_TOLERANCE)) + return __LINE__; + + return 0; +} + +int TestLoadTranslationMatrix() +{ + const Math::Vector translation(-0.3631590720995237, 1.6976327614875211, 0.0148815191502145); + + Math::Matrix mathResult; + Math::LoadTranslationMatrix(mathResult, translation); + + Math::Matrix oldMathResult; + { + D3DMATRIX mat; + D3DUtil_SetTranslateMatrix(mat, translation.x, translation.y, translation.z); + oldMathResult = D3DMAT_TO_MAT(mat); + } + + if (! Math::MatricesEqual(mathResult, oldMathResult, TEST_TOLERANCE)) + return __LINE__; + + return 0; +} + +int TestLoadScaleMatrix() +{ + const Math::Vector scale(0.612236460285503, -0.635566935025364, -0.254321375332065); + + Math::Matrix mathResult; + Math::LoadScaleMatrix(mathResult, scale); + + Math::Matrix oldMathResult; + { + D3DMATRIX mat; + D3DUtil_SetScaleMatrix(mat, scale.x, scale.y, scale.z); + oldMathResult = D3DMAT_TO_MAT(mat); + } + + if (! Math::MatricesEqual(mathResult, oldMathResult, TEST_TOLERANCE)) + return __LINE__; + + return 0; +} + +int TestLoadRotationXMatrix() +{ + const float angle = 0.513790685774275; + + Math::Matrix mathResult; + Math::LoadRotationXMatrix(mathResult, angle); + + Math::Matrix oldMathResult; + { + D3DMATRIX mat; + D3DUtil_SetRotateXMatrix(mat, angle); + oldMathResult = D3DMAT_TO_MAT(mat); + } + + if (! Math::MatricesEqual(mathResult, oldMathResult, TEST_TOLERANCE)) + return __LINE__; + + return 0; +} + +int TestLoadRotationYMatrix() +{ + const float angle = -0.569166650127303; + + Math::Matrix mathResult; + Math::LoadRotationYMatrix(mathResult, angle); + + Math::Matrix oldMathResult; + { + D3DMATRIX mat; + D3DUtil_SetRotateYMatrix(mat, angle); + oldMathResult = D3DMAT_TO_MAT(mat); + } + + if (! Math::MatricesEqual(mathResult, oldMathResult, TEST_TOLERANCE)) + return __LINE__; + + return 0; +} + +int TestLoadRotationZMatrix() +{ + const float angle = 0.380448034347452; + + Math::Matrix mathResult; + Math::LoadRotationZMatrix(mathResult, angle); + + Math::Matrix oldMathResult; + { + D3DMATRIX mat; + D3DUtil_SetRotateZMatrix(mat, angle); + oldMathResult = D3DMAT_TO_MAT(mat); + } + + if (! Math::MatricesEqual(mathResult, oldMathResult, TEST_TOLERANCE)) + return __LINE__; + + return 0; +} + +int TestLoadRotationMatrix() +{ + const float angle = -0.987747190637790; + const Math::Vector dir(-0.113024727688331, -0.781265998072571, 1.838972397076884); + + Math::Matrix mathResult; + Math::LoadRotationMatrix(mathResult, dir, angle); + + Math::Matrix oldMathResult; + { + D3DMATRIX mat; + D3DVECTOR dirD3D = VEC_TO_D3DVEC(dir); + D3DUtil_SetRotationMatrix(mat, dirD3D, angle); + oldMathResult = D3DMAT_TO_MAT(mat); + } + + if (! Math::MatricesEqual(mathResult, oldMathResult, TEST_TOLERANCE)) + return __LINE__; + + return 0; +} + +int TestLoadRotationXZYMatrix() +{ + const Math::Vector angles(-0.841366567984597, -0.100543315396357, 1.610647811559988); + + Math::Matrix mathResult; + Math::LoadRotationXZYMatrix(mathResult, angles); + + Math::Matrix oldMathResult; + { + D3DMATRIX mat; + MatRotateXZY(mat, VEC_TO_D3DVEC(angles)); + oldMathResult = D3DMAT_TO_MAT(mat); + } + + if (! Math::MatricesEqual(mathResult, oldMathResult, TEST_TOLERANCE)) + return __LINE__; + + return 0; +} + +int TestLoadRotationZXYMatrix() +{ + const Math::Vector angles(0.275558495480206, -0.224328265970090, 0.943077216574253); + + Math::Matrix mathResult; + Math::LoadRotationZXYMatrix(mathResult, angles); + + Math::Matrix oldMathResult; + { + D3DMATRIX mat; + MatRotateZXY(mat, VEC_TO_D3DVEC(angles)); + oldMathResult = D3DMAT_TO_MAT(mat); + } + + if (! Math::MatricesEqual(mathResult, oldMathResult, TEST_TOLERANCE)) + return __LINE__; + + return 0; +} + +int TestTransform() +{ + Math::Matrix transformMatrix( + (float[4][4]) + { + { -0.9282074720977896, 0.6794734970319730, -1.3234304946882685, 0.0925294727863890 }, + { -0.0395527963683484, 0.2897634352353881, 1.9144398570315440, -1.4062267508968478 }, + { 0.9133323625282361, -0.6741836434774530, -0.2188812951424338, -1.0089184339952666 }, + { 0.0f, 0.0f, 0.0f, 1.0f } + } + ); + Math::Vector vector(-0.314596433318370, -0.622681232583150, -0.371307535743574); + + Math::Vector mathResult = Math::Transform(transformMatrix, vector); + Math::Vector oldMathResult = Transform(transformMatrix, vector); + + if (! Math::VectorsEqual(mathResult, oldMathResult, TEST_TOLERANCE)) + return __LINE__; + + return 0; +} + +*/ + diff --git a/test/unit/math/matrix_test.cpp b/test/unit/math/matrix_test.cpp new file mode 100644 index 0000000..6ae2c6b --- /dev/null +++ b/test/unit/math/matrix_test.cpp @@ -0,0 +1,314 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 2012, Polish Portal of Colobot (PPC) +// * +// * This program is free software: you can redistribute it and/or modify +// * it under the terms of the GNU General Public License as published by +// * the Free Software Foundation, either version 3 of the License, or +// * (at your option) any later version. +// * +// * This program is distributed in the hope that it will be useful, +// * but WITHOUT ANY WARRANTY; without even the implied warranty of +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// * GNU General Public License for more details. +// * +// * You should have received a copy of the GNU General Public License +// * along with this program. If not, see http://www.gnu.org/licenses/. + +// math/test/matrix_test.cpp + +/* + Unit tests for Matrix struct + + Test data was randomly generated and the expected results + calculated using GNU Octave. + */ + +#include "math/func.h" +#include "math/matrix.h" + +#include "gtest/gtest.h" + + +const float TEST_TOLERANCE = 1e-6; + + +TEST(MatrixTest, TransposeTest) +{ + const Math::Matrix mat( + (float[4][4]) + { + { -0.07011674491203920, 1.26145596067429810, 2.09476603598066902, 0.35560176915570696 }, + { -1.34075615966224704, 1.17988499016709314, 0.00601713429241016, -0.75213676977972566 }, + { 0.59186722295223981, 0.88089224074765293, 0.70994467464257294, 0.36730385425340212 }, + { -0.95649396555068111, 0.75912182022565566, 1.34883305778387186, -1.34957997578168754 } + } + ); + + const Math::Matrix expectedTranspose( + (float[4][4]) + { + { -0.07011674491203920, -1.34075615966224704, 0.59186722295223981, -0.95649396555068111 }, + { 1.26145596067429810, 1.17988499016709314, 0.88089224074765293, 0.75912182022565566 }, + { 2.09476603598066902, 0.00601713429241016, 0.70994467464257294, 1.34883305778387186 }, + { 0.35560176915570696, -0.75213676977972566, 0.36730385425340212, -1.34957997578168754 } + } + ); + + Math::Matrix transpose = Math::Transpose(mat); + + EXPECT_TRUE(Math::MatricesEqual(transpose, expectedTranspose, TEST_TOLERANCE)); +} + +TEST(MatrixTest, CofactorTest) +{ + const Math::Matrix mat1( + (float[4][4]) + { + { 0.610630320796245, 1.059932357918312, -1.581674311378210, 1.782214448453331 }, + { 0.191028848211526, -0.813898708757524, 1.516114203870644, 0.395202639476002 }, + { 0.335142750345279, -0.346586619596529, 0.545382042472336, -0.879268918923072 }, + { 1.417588151657198, 1.450841789070141, 0.219080104196171, 0.378724047481655 } + } + ); + + const Math::Matrix expectedCofactors1( + (float[4][4]) + { + { -2.402679369186782, 2.282452509293019, 1.722732204057644, -0.746939701104385 }, + { -0.687677756877654, 1.168949180331164, -0.985354966837796, -1.334071111592705 }, + { -5.115621958424845, 4.229724770159009, 2.529000630782808, 1.481632618355891 }, + { 0.147480897398694, -2.140677680337111, -1.207189492265546, 0.151236920408051 } + } + ); + + for (int r = 0; r < 4; ++r) + { + for (int c = 0; c < 4; ++c) + { + float ret = mat1.Cofactor(r, c); + float exp = expectedCofactors1.m[4*c+r]; + EXPECT_TRUE(Math::IsEqual(ret, exp, TEST_TOLERANCE)); + } + } + + const Math::Matrix mat2( + (float[4][4]) + { + { 0.9845099464982393, -0.9091233416532389, -0.6272243714245945, 0.4645001858944354 }, + { -0.1333308471483736, 0.9128181433725897, -1.0937461393836190, 0.3180936795928376 }, + { -0.0654324396846289, 0.1014641705415945, 1.5107709042683430, -0.0240560430414690 }, + { 0.0179638644093347, -1.0695585982782767, -0.1741250853101032, 1.0803106709464336 } + } + ); + + const Math::Matrix expectedCofactors2( + (float[4][4]) + { + { 2.0861102207614466, 0.2989010779528912, 0.0746276150537432, 0.2732659822656097 }, + { 0.6850002886584565, 1.5513169659641379, -0.0503743176545917, 1.5163672441575642 }, + { 1.2385556680997216, 1.1827709562505695, 1.2282813085138962, 1.3483789679871401 }, + { -1.0710790241539783, -0.5589604503588883, 0.0100959837872308, 1.1897872684455839 } + } + ); + + + for (int r = 0; r < 4; ++r) + { + for (int c = 0; c < 4; ++c) + { + float ret = mat2.Cofactor(r, c); + float exp = expectedCofactors2.m[4*c+r]; + EXPECT_TRUE(Math::IsEqual(ret, exp, TEST_TOLERANCE)); + } + } +} + +TEST(MatrixTest, DetTest) +{ + const Math::Matrix mat1( + (float[4][4]) + { + { -0.95880162984708284, 0.24004047608997131, -0.78172309932665407, -0.11604124457222834 }, + { -0.36230592086261376, -0.75778166876017261, 0.33041059404631740, -1.06001391941094836 }, + { 0.00260215210936187, 1.27485610196385113, -0.26149859846418033, -0.59669701186364876 }, + { 0.36899429848485432, 3.01720896813933104, 2.10311476609438719, -1.68627076626448269 } + } + ); + + const float expectedDet1 = 4.07415413729671; + + float ret1 = mat1.Det(); + EXPECT_TRUE(Math::IsEqual(ret1, expectedDet1, TEST_TOLERANCE)); + + const Math::Matrix mat2( + (float[4][4]) + { + { -1.0860073221346871, 0.9150354098189495, -0.2723201933559999, 0.2922832160271507 }, + { -1.0248331304801788, -2.5081237461125205, -1.0277123574586633, -0.2254690663329798 }, + { -1.4227635282899367, -0.0403846809122684, 0.9216148477171653, 1.2517067488015878 }, + { -0.1160254467152022, 0.8270675274393656, 1.0327218739781614, -0.3674886870220400 } + } + ); + + const float expectedDet2 = -6.35122307880942; + + float ret2 = mat2.Det(); + EXPECT_TRUE(Math::IsEqual(ret2, expectedDet2, TEST_TOLERANCE)); +} + +TEST(MatrixTest, InverseTest) +{ + const Math::Matrix mat1( + (float[4][4]) + { + { -2.2829352811514658, -0.9103222363187888, 0.2792976509411680, -0.7984393573193174 }, + { 2.4823665798689589, -0.0599056759070980, 0.3832364352926366, -1.6404257204372739 }, + { -0.3841952272526398, -0.8377700696457873, -0.3416328338427138, 1.1746577275723329 }, + { 0.1746031241954947, -0.4952532117949962, 0.2155084379835037, -1.6586460437329220 } + } + ); + + const Math::Matrix expectedInverse1( + (float[4][4]) + { + { -0.119472603171041, 0.331675963276297, 0.187516809009720, -0.137720814290806 }, + { -0.387591686166085, -0.487284946727583, -0.798527541290274, 0.102991635972060 }, + { 2.601905603425902, 2.606899016264679, -0.528006148839176, -4.204703326522837 }, + { 0.441220327151392, 0.519128136207318, 0.189567009205522, -1.194469716136194 } + } + ); + + Math::Matrix inverse1 = mat1.Inverse(); + + EXPECT_TRUE(Math::MatricesEqual(inverse1, expectedInverse1, TEST_TOLERANCE)); + + const Math::Matrix mat2( + (float[4][4]) + { + { -0.05464332404298505, -0.64357755258235749, -0.13017671677619302, -0.56742332785888006 }, + { 0.29048383600458222, -0.91517047043724875, 0.84517524415561684, 0.51628195547960565 }, + { 0.00946488004480186, -0.89077382212689293, 0.73565573766341397, -0.15932513521840930 }, + { -1.01244718912499132, -0.27840911963972276, -0.39189681211309862, 1.18315064340192055 } + } + ); + + const Math::Matrix expectedInverse2( + (float[4][4]) + { + { 0.771302711132012, 1.587542278361995, -2.003075114445104, -0.592574156227379 }, + { -1.208929259769431, -0.786598967848473, 0.607335305808052, -0.154759693303324 }, + { -1.500037668208218, -0.774300278997914, 1.917800427261255, -0.123268572651291 }, + { -0.121314770937944, 0.916925149209746, -0.935924950785014, 0.260875394250671 } + } + ); + + Math::Matrix inverse2 = mat2.Inverse(); + + EXPECT_TRUE(Math::MatricesEqual(inverse2, expectedInverse2, TEST_TOLERANCE)); +} + +TEST(MatrixTest, MultiplyTest) +{ + const Math::Matrix mat1A( + (float[4][4]) + { + { 0.6561727049162027, -1.4180263627131411, -0.8271026046117423, 2.3919331748512578 }, + { -0.6035665535146352, 0.0150827348790615, -0.7090794192822540, 0.9057604704594814 }, + { -0.9871045001223655, -0.4980646811455065, 0.3806177002298990, 0.1520583649240934 }, + { -0.2721911170792712, 0.7627928194552067, -0.1504091336784158, 0.9747545351840121 } + } + ); + + const Math::Matrix mat1B( + (float[4][4]) + { + { -0.2643735892448818, -0.7542994492819621, 0.6082322350568750, 0.0581733424861419 }, + { 1.0293246070431237, 0.1979285388251341, -0.2932031385332818, 0.8838407179018929 }, + { 0.3448687251553114, 0.5031654871245456, 0.7554693012922442, -0.4845315903845708 }, + { -1.8662838497278593, -0.7843850624747805, 0.1389026096476257, -1.3686415408300689 } + } + ); + + const Math::Matrix expectedMultiply1( + (float[4][4]) + { + { -6.382352236417988, -3.067984733682130, 0.522270304251466, -4.088079444498280 }, + { -1.759853366848825, -0.608994052024491, -0.781406179437379, -0.917870775786188 }, + { -0.404226802169062, 0.718232546720114, -0.145688356880835, -0.890167707987175 }, + { -1.013918490922430, -0.483971504099758, -0.367442194643757, -0.602858486133615 } + } + ); + + Math::Matrix multiply1 = Math::MultiplyMatrices(mat1A, mat1B); + EXPECT_TRUE(Math::MatricesEqual(multiply1, expectedMultiply1, TEST_TOLERANCE)); + + const Math::Matrix mat2A( + (float[4][4]) + { + { 0.8697203025776754, 2.1259475710644935, 1.7856691009707812, -2.1563963348328126 }, + { 1.5888074489288735, -0.0794849733953615, 0.7307782768677457, 0.7943129159612630 }, + { 0.2859761537233830, -0.6231231890384962, -0.0496743172880377, -0.8137857518646087 }, + { 1.2670547229512983, -0.5305171374831831, -0.4987412674062375, -1.1257327113869595 } + } + ); + + const Math::Matrix mat2B( + (float[4][4]) + { + { 1.1321105701165317, 0.1759563504574463, -2.0675778912000418, 1.4840339814245538 }, + { -1.5117280888829916, -0.0933013188828093, -0.2079262944351640, 0.9575727579539316 }, + { 0.3615378398970173, 1.2465163589027248, 1.1326150997082589, 0.9921208694352303 }, + { -0.7357104529373861, -0.4774022005969588, -0.2118739096676499, 1.1427567093270703 } + } + ); + + const Math::Matrix expectedMultiply2( + (float[4][4]) + { + { 0.00283516267056338, 3.21001319965989307, 0.23910503934370686, 2.63380716363006107 }, + { 1.59868505822469742, 0.81869715594617765, -2.60905981088293570, 3.91445839239110294 }, + { 1.84650099286297942, 0.43504079532852930, -0.34555619012424243, -1.15152951542451487 }, + { 2.88434318563174585, 0.18818239851585700, -2.83579436909308980, -0.40890672198610400 } + } + ); + + Math::Matrix multiply2 = Math::MultiplyMatrices(mat2A, mat2B); + EXPECT_TRUE(Math::MatricesEqual(multiply2, expectedMultiply2, TEST_TOLERANCE)); +} + +TEST(MatrixTest, MultiplyVectorTest) +{ + const Math::Matrix mat1( + (float[4][4]) + { + { 0.188562846910008, -0.015148651460679, 0.394512304108827, 0.906910631257135 }, + { -0.297506779519667, 0.940119328178913, 0.970957796752517, 0.310559318965526 }, + { -0.819770525290873, -2.316574438778879, 0.155756069319732, -0.855661405742964 }, + { 0.000000000000000, 0.000000000000000, 0.000000000000000, 1.000000000000000 } + } + ); + + const Math::Vector vec1(-0.824708565156661, -1.598287748103842, -0.422498044734181); + + const Math::Vector expectedMultiply1(0.608932463260470, -1.356893266403749, 3.457156276255142); + + Math::Vector multiply1 = Math::MatrixVectorMultiply(mat1, vec1, false); + EXPECT_TRUE(Math::VectorsEqual(multiply1, expectedMultiply1, TEST_TOLERANCE)); + + const Math::Matrix mat2( + (float[4][4]) + { + { -0.63287117038834284, 0.55148060401816856, -0.02042395559467368, -1.50367083897656850 }, + { 0.69629042156335297, 0.12982747869796774, -1.16250029235919405, 1.19084447253756909 }, + { 0.44164132914357224, -0.15169304045662041, -0.00880583574621390, -0.55817802940035310 }, + { 0.95680476533530789, -1.51912346889253125, -0.74209769406615944, -0.20938988867903682 } + } + ); + + const Math::Vector vec2(0.330987381051962, 1.494375516393466, 1.483422335561857); + + const Math::Vector expectedMultiply2(0.2816820577317669, 0.0334468811767428, 0.1996974284970455); + + Math::Vector multiply2 = Math::MatrixVectorMultiply(mat2, vec2, true); + EXPECT_TRUE(Math::VectorsEqual(multiply2, expectedMultiply2, TEST_TOLERANCE)); +} diff --git a/test/unit/math/vector_test.cpp b/test/unit/math/vector_test.cpp new file mode 100644 index 0000000..199f4c3 --- /dev/null +++ b/test/unit/math/vector_test.cpp @@ -0,0 +1,74 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 2012, Polish Portal of Colobot (PPC) +// * +// * This program is free software: you can redistribute it and/or modify +// * it under the terms of the GNU General Public License as published by +// * the Free Software Foundation, either version 3 of the License, or +// * (at your option) any later version. +// * +// * This program is distributed in the hope that it will be useful, +// * but WITHOUT ANY WARRANTY; without even the implied warranty of +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// * GNU General Public License for more details. +// * +// * You should have received a copy of the GNU General Public License +// * along with this program. If not, see http://www.gnu.org/licenses/. + +// math/test/vector_test.cpp + +/* + Unit tests for Vector struct + + Test data was randomly generated and the expected results + calculated using GNU Octave. + */ + +#include "math/func.h" +#include "math/vector.h" + +#include "gtest/gtest.h" + + +const float TEST_TOLERANCE = 1e-6; + + +TEST(VectorTest, LengthTest) +{ + Math::Vector vec(-1.288447945923275, 0.681452565308134, -0.633761098985957); + const float expectedLength = 1.58938001708428; + + EXPECT_TRUE(Math::IsEqual(vec.Length(), expectedLength, TEST_TOLERANCE)); +} + +TEST(VectorTest, NormalizeTest) +{ + Math::Vector vec(1.848877241804398, -0.157262961268577, -1.963031403332377); + const Math::Vector expectedNormalized(0.6844609421393856, -0.0582193085618106, -0.7267212194481797); + + vec.Normalize(); + + EXPECT_TRUE(Math::VectorsEqual(vec, expectedNormalized, TEST_TOLERANCE)); +} + +TEST(VectorTest, DotTest) +{ + Math::Vector vecA(0.8202190530968309, 0.0130926060162780, 0.2411914183883510); + Math::Vector vecB(-0.0524083951404069, 1.5564932716738220, -0.8971342631500536); + + float expectedDot = -0.238988896477326; + + EXPECT_TRUE(Math::IsEqual(Math::DotProduct(vecA, vecB), expectedDot, TEST_TOLERANCE)); +} + +TEST(VectorTest, CrossTest) +{ + Math::Vector vecA(1.37380499798567, 1.18054518384682, 1.95166361293121); + Math::Vector vecB(0.891657855926886, 0.447591335394532, -0.901604070087823); + + Math::Vector expectedCross(-1.937932065431669, 2.978844370287636, -0.437739173833581); + Math::Vector expectedReverseCross = -expectedCross; + + EXPECT_TRUE(Math::VectorsEqual(vecA.CrossMultiply(vecB), expectedCross, TEST_TOLERANCE)); + + EXPECT_TRUE(Math::VectorsEqual(vecB.CrossMultiply(vecA), expectedReverseCross, TEST_TOLERANCE)); +} diff --git a/test/unit/ui/CMakeLists.txt b/test/unit/ui/CMakeLists.txt new file mode 100644 index 0000000..32af230 --- /dev/null +++ b/test/unit/ui/CMakeLists.txt @@ -0,0 +1,29 @@ +set(SRC_DIR ${colobot_SOURCE_DIR}/src) + +include_directories( +. +${SRC_DIR} +${GTEST_INCLUDE_DIR} +${GMOCK_INCLUDE_DIR} +) + +add_executable(edit_test +${SRC_DIR}/common/event.cpp +${SRC_DIR}/common/logger.cpp +${SRC_DIR}/common/misc.cpp +${SRC_DIR}/common/iman.cpp +${SRC_DIR}/common/stringutils.cpp +${SRC_DIR}/graphics/engine/text.cpp +${SRC_DIR}/ui/button.cpp +${SRC_DIR}/ui/control.cpp +${SRC_DIR}/ui/edit.cpp +${SRC_DIR}/ui/scroll.cpp +stubs/app_stub.cpp +stubs/engine_stub.cpp +stubs/particle_stub.cpp +stubs/restext_stub.cpp +stubs/robotmain_stub.cpp +edit_test.cpp) +target_link_libraries(edit_test gtest gmock ${SDL_LIBRARY} ${SDLTTF_LIBRARY} ${Boost_LIBRARIES}) + +add_test(edit_test ./edit_test) diff --git a/test/unit/ui/edit_test.cpp b/test/unit/ui/edit_test.cpp new file mode 100644 index 0000000..f878f4b --- /dev/null +++ b/test/unit/ui/edit_test.cpp @@ -0,0 +1,74 @@ +#include "app/app.h" +#include "ui/edit.h" +#include "mocks/text_mock.h" + +#include +#include +#include + +class CEditTest : public testing::Test +{ +public: + CEditTest(){}; + + virtual void SetUp() + { + m_engine = new Gfx::CEngine(&m_iMan, NULL); + + m_iMan.AddInstance(CLASS_ENGINE, m_engine); + m_edit = new Ui::CEdit; + } + + virtual void TearDown() + { + m_iMan.DeleteInstance(CLASS_ENGINE, m_engine); + delete m_engine; + m_engine = NULL; + delete m_edit; + m_edit = NULL; + + } + virtual ~CEditTest() + { + + }; + +protected: + CInstanceManager m_iMan; + CApplication m_app; + Gfx::CEngine * m_engine; + Ui::CEdit * m_edit; + CLogger m_logger; +}; + +using ::testing::_; +using ::testing::Return; + +TEST_F(CEditTest, WriteTest) +{ + ASSERT_TRUE(true); + CTextMock * text = dynamic_cast(m_engine->GetText()); + EXPECT_CALL(*text, GetCharWidth(_, _, _, _)).WillRepeatedly(Return(1.0f)); + EXPECT_CALL(*text, GetStringWidth(_, _, _)).WillOnce(Return(1.0f)); + std::string filename = "test.file"; + m_edit->SetMaxChar(Ui::EDITSTUDIOMAX); + m_edit->SetAutoIndent(true); + std::string inputScript = "{\ntext1\ntext2\n\ntext3\n{\ntext4\n}\n}"; + std::string expectedScript = "{\r\n\ttext1\r\n\ttext2\r\n\t\r\n\ttext3\r\n\t{\r\n\t\ttext4\r\n\t}\r\n}"; + m_edit->SetText(inputScript.c_str(), true); + GetLogger()->Info("Writing text \n"); + m_edit->WriteText("script.txt"); + + std::fstream scriptFile; + + scriptFile.open("script.txt", std::ios_base::binary | std::ios_base::in); + std::string outputScript((std::istreambuf_iterator(scriptFile)), std::istreambuf_iterator()); + ASSERT_STREQ(expectedScript.c_str(), outputScript.c_str()); +} + +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + diff --git a/test/unit/ui/mocks/text_mock.h b/test/unit/ui/mocks/text_mock.h new file mode 100644 index 0000000..f0ad339 --- /dev/null +++ b/test/unit/ui/mocks/text_mock.h @@ -0,0 +1,21 @@ +#include "common/logger.h" +#include "graphics/engine/text.h" + +#include + +class CTextMock : public Gfx::CText +{ +public: + CTextMock(CInstanceManager *iMan, Gfx::CEngine* engine) : CText(iMan, engine) + { + } + + virtual ~CTextMock() + { + }; + + MOCK_METHOD4(GetCharWidth, float(Gfx::UTF8Char, Gfx::FontType, float, float)); + MOCK_METHOD3(GetStringWidth, float(const std::string &, Gfx::FontType, float)); + +}; + diff --git a/test/unit/ui/stubs/app_stub.cpp b/test/unit/ui/stubs/app_stub.cpp new file mode 100644 index 0000000..70d9e82 --- /dev/null +++ b/test/unit/ui/stubs/app_stub.cpp @@ -0,0 +1,26 @@ +#include "app/app.h" +#include "graphics/opengl/gldevice.h" + +template<> CApplication* CSingleton::mInstance = nullptr; + +namespace Gfx { + +GLDeviceConfig::GLDeviceConfig() +{ +} + +} /* Gfx */ +CApplication::CApplication() +{ +} + +CApplication::~CApplication() +{ +} + +std::string CApplication::GetDataFilePath(DataDir /* dataDir */, const std::string& subpath) +{ + return subpath; +} + + diff --git a/test/unit/ui/stubs/engine_stub.cpp b/test/unit/ui/stubs/engine_stub.cpp new file mode 100644 index 0000000..de7bbe7 --- /dev/null +++ b/test/unit/ui/stubs/engine_stub.cpp @@ -0,0 +1,79 @@ +#include "graphics/engine/engine.h" +#include "graphics/engine/text.h" +#include "mocks/text_mock.h" + +namespace Gfx { + +CEngine::CEngine(CInstanceManager* iMan, CApplication* app) : + m_iMan(iMan), m_app(app) +{ + m_text = new CTextMock(m_iMan, this); + m_text->Create(); +} + +CEngine::~CEngine() +{ + delete m_text; + m_text = NULL; +} + +Math::Point CEngine::WindowToInterfaceSize(Math::IntPoint size) +{ + return Math::Point(size.x, size.y); +} + +void CEngine::SetState(int state, const Color& color) +{ + if (state == m_lastState && color == m_lastColor) + return; + + m_lastState = state; + m_lastColor = color; +} + +Math::IntPoint CEngine::GetWindowSize() +{ + return m_size; +} + +void CEngine::AddStatisticTriangle(int count) +{ + m_statisticTriangle += count; +} + +void CEngine::SetMouseType(EngineMouseType type) +{ + m_mouseType = type; +} + +bool CEngine::SetTexture(const std::string& /* name */, int /* stage */) +{ + return true; +} + +CText* CEngine::GetText() +{ + return m_text; +} + +CDevice* CEngine::GetDevice() +{ + return m_device; +} + +int CEngine::GetEditIndentValue() +{ + return m_editIndentValue; +} + +void CEngine::DeleteTexture(const std::string& /* texName */) +{ +} +Texture CEngine::LoadTexture(const std::string& /* name */) +{ + Texture texture; + return texture; +} + +} /* Gfx */ + diff --git a/test/unit/ui/stubs/particle_stub.cpp b/test/unit/ui/stubs/particle_stub.cpp new file mode 100644 index 0000000..c3bf6dc --- /dev/null +++ b/test/unit/ui/stubs/particle_stub.cpp @@ -0,0 +1,205 @@ +#include "graphics/engine/particle.h" + +#include "common/logger.h" + + +// Graphics module namespace +namespace Gfx { + + +CParticle::CParticle(CInstanceManager* /*iMan*/, CEngine* /*engine*/) +{ +} + +CParticle::~CParticle() +{ +} + +void CParticle::SetDevice(CDevice* /*device*/) +{ +} + +void CParticle::FlushParticle() +{ +} + +void CParticle::FlushParticle(int /*sheet*/) +{ +} + +int CParticle::CreateParticle(Math::Vector /*pos*/, Math::Vector /*speed*/, Math::Point /*dim*/, + ParticleType /*type*/, float /*duration*/, float /*mass*/, + float /*windSensitivity*/, int /*sheet*/) +{ + return 0; +} + +int CParticle::CreateFrag(Math::Vector /*pos*/, Math::Vector /*speed*/, EngineTriangle */*triangle*/, + ParticleType /*type*/, float /*duration*/, float /*mass*/, + float /*windSensitivity*/, int /*sheet*/) +{ + return 0; +} + +int CParticle::CreatePart(Math::Vector /*pos*/, Math::Vector /*speed*/, ParticleType /*type*/, + float /*duration*/, float /*mass*/, float /*weight*/, + float /*windSensitivity*/, int /*sheet*/) +{ + return 0; +} + +int CParticle::CreateRay(Math::Vector /*pos*/, Math::Vector /*goal*/, ParticleType /*type*/, Math::Point /*dim*/, + float /*duration*/, int /*sheet*/) +{ + return 0; +} + +int CParticle::CreateTrack(Math::Vector /*pos*/, Math::Vector /*speed*/, Math::Point /*dim*/, ParticleType /*type*/, + float /*duration*/, float /*mass*/, float /*length*/, float /*width*/) +{ + return 0; +} + +void CParticle::CreateWheelTrace(const Math::Vector &/*p1*/, const Math::Vector &/*p2*/, const Math::Vector &/*p3*/, + const Math::Vector &/*p4*/, ParticleType /*type*/) +{ +} + +void CParticle::DeleteParticle(ParticleType /*type*/) +{ +} + +void CParticle::DeleteParticle(int /*channel*/) +{ +} + +void CParticle::SetObjectLink(int /*channel*/, CObject */*object*/) +{ +} + +void CParticle::SetObjectFather(int /*channel*/, CObject */*object*/) +{ +} + +void CParticle::SetPosition(int /*channel*/, Math::Vector /*pos*/) +{ +} + +void CParticle::SetDimension(int /*channel*/, Math::Point /*dim*/) +{ +} + +void CParticle::SetZoom(int /*channel*/, float /*zoom*/) +{ +} + +void CParticle::SetAngle(int /*channel*/, float /*angle*/) +{ +} + +void CParticle::SetIntensity(int /*channel*/, float /*intensity*/) +{ +} + +void CParticle::SetParam(int /*channel*/, Math::Vector /*pos*/, Math::Point /*dim*/, float /*zoom*/, float /*angle*/, float /*intensity*/) +{ +} + +void CParticle::SetPhase(int /*channel*/, ParticlePhase /*phase*/, float /*duration*/) +{ +} + +bool CParticle::GetPosition(int /*channel*/, Math::Vector &/*pos*/) +{ + return true; +} + +Color CParticle::GetFogColor(Math::Vector /*pos*/) +{ + return Color(); +} + +void CParticle::SetFrameUpdate(int /*sheet*/, bool /*update*/) +{ +} + +void CParticle::FrameParticle(float /*rTime*/) +{ +} + +void CParticle::DrawParticle(int /*sheet*/) +{ +} + +bool CParticle::WriteWheelTrace(const char */*filename*/, int /*width*/, int /*height*/, Math::Vector /*dl*/, Math::Vector /*ur*/) +{ + return true; +} + +void CParticle::DeleteRank(int /*rank*/) +{ +} + +bool CParticle::CheckChannel(int &/*channel*/) +{ + return true; +} + +void CParticle::DrawParticleTriangle(int /*i*/) +{ +} + +void CParticle::DrawParticleNorm(int /*i*/) +{ +} + +void CParticle::DrawParticleFlat(int /*i*/) +{ +} + +void CParticle::DrawParticleFog(int /*i*/) +{ +} + +void CParticle::DrawParticleRay(int /*i*/) +{ +} + +void CParticle::DrawParticleSphere(int /*i*/) +{ +} + +void CParticle::DrawParticleCylinder(int /*i*/) +{ +} + +void CParticle::DrawParticleWheel(int /*i*/) +{ +} + +CObject* CParticle::SearchObjectGun(Math::Vector /*old*/, Math::Vector /*pos*/, ParticleType /*type*/, CObject */*father*/) +{ + return nullptr; +} + +CObject* CParticle::SearchObjectRay(Math::Vector /*pos*/, Math::Vector /*goal*/, ParticleType /*type*/, CObject */*father*/) +{ + return nullptr; +} + +void CParticle::Play(Sound /*sound*/, Math::Vector /*pos*/, float /*amplitude*/) +{ +} + +bool CParticle::TrackMove(int /*i*/, Math::Vector /*pos*/, float /*progress*/) +{ + return true; +} + +void CParticle::TrackDraw(int /*i*/, ParticleType /*type*/) +{ +} + + +} // namespace Gfx + diff --git a/test/unit/ui/stubs/restext_stub.cpp b/test/unit/ui/stubs/restext_stub.cpp new file mode 100644 index 0000000..004da19 --- /dev/null +++ b/test/unit/ui/stubs/restext_stub.cpp @@ -0,0 +1,12 @@ +#include "common/restext.h" + +bool GetResource(ResType /* type */, int /* num */, char* /* text */) +{ + return true; +} + +bool SearchKey(const char * /* cmd */, InputSlot & /* key */) +{ + return true; +} + diff --git a/test/unit/ui/stubs/robotmain_stub.cpp b/test/unit/ui/stubs/robotmain_stub.cpp new file mode 100644 index 0000000..a36b1a1 --- /dev/null +++ b/test/unit/ui/stubs/robotmain_stub.cpp @@ -0,0 +1,17 @@ +#include "object/robotmain.h" + + +template<> CRobotMain* CSingleton::mInstance = nullptr; + +bool CRobotMain::GetGlint() +{ + return false; +} + +const InputBinding& CRobotMain::GetInputBinding(InputSlot slot) +{ + unsigned int index = static_cast(slot); + assert(index >= 0 && index < INPUT_SLOT_MAX); + return m_inputBindings[index]; +} + -- cgit v1.2.3-1-g7c22 From 6f64770714c20a24a2edfd55777e05a047e61d0e Mon Sep 17 00:00:00 2001 From: erihel Date: Sat, 9 Feb 2013 21:00:07 +0100 Subject: * Fixes to ingame editor * Fixes to editor window. It's now possible to resize, move and press buttons --- src/graphics/engine/text.cpp | 8 +++++--- src/object/brain.cpp | 2 +- src/script/script.cpp | 3 +-- src/ui/edit.cpp | 4 ++-- src/ui/studio.cpp | 40 ++++++++++++++++++++-------------------- 5 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index da1a290..dfe7a3c 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -682,11 +682,13 @@ void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::P int width = 1; if (ch.c1 > 0 && ch.c1 < 32) { // FIXME add support for chars with code 9 10 23 - ch.c1 = ' '; + if (ch.c1 == '\t') { + ch.c1 = ':'; + } else { + ch.c1 = ' '; + } ch.c2 = 0; ch.c3 = 0; - if (ch.c1 == '\t') - width = 4; } auto it = cf->cache.find(ch); diff --git a/src/object/brain.cpp b/src/object/brain.cpp index d3c0e0b..bc47cb3 100644 --- a/src/object/brain.cpp +++ b/src/object/brain.cpp @@ -255,7 +255,7 @@ bool CBrain::EventProcess(const Event &event) if ( m_object->GetSelect() && // robot selected? m_studio != 0 ) // current issue? { - // m_studio->EventProcess(event); + m_studio->EventProcess(event); if ( action == EVENT_OBJECT_PROGRUN ) { diff --git a/src/script/script.cpp b/src/script/script.cpp index f58e66d..50ce830 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -3346,7 +3346,6 @@ void CScript::ColorizeScript(Ui::CEdit* edit) cursor1 = bt->GetStart(); cursor2 = bt->GetEnd(); - color = Gfx::FONT_HIGHLIGHT_NONE; if ( type >= TokenKeyWord && type < TokenKeyWord+100 ) { @@ -3376,7 +3375,7 @@ void CScript::ColorizeScript(Ui::CEdit* edit) color =Gfx::FONT_HIGHLIGHT_CONST; } - if ( cursor1 < cursor2 && color != 0 ) + if ( cursor1 < cursor2 && color != Gfx::FONT_HIGHLIGHT_NONE ) { edit->SetFormat(cursor1, cursor2, color); } diff --git a/src/ui/edit.cpp b/src/ui/edit.cpp index 639215a..a1d213f 100644 --- a/src/ui/edit.cpp +++ b/src/ui/edit.cpp @@ -935,10 +935,10 @@ void CEdit::Draw() pos.x = m_pos.x+(10.0f/640.0f); if ( m_bAutoIndent ) { + const char *s = "\t"; // line | dotted for ( j=0 ; jGetText()->DrawText(&s, m_fontType, m_fontSize, pos, 1.0f, Gfx::TEXT_ALIGN_LEFT, 0); + m_engine->GetText()->DrawText(s, m_fontType, m_fontSize, pos, 1.0f, Gfx::TEXT_ALIGN_LEFT, 0); pos.x += indentLength; } } diff --git a/src/ui/studio.cpp b/src/ui/studio.cpp index 2f58c95..7aa2d22 100644 --- a/src/ui/studio.cpp +++ b/src/ui/studio.cpp @@ -114,7 +114,7 @@ bool CStudio::EventProcess(const Event &event) if ( pw == nullptr ) return false; edit = static_cast(pw->SearchControl(EVENT_STUDIO_EDIT)); - if ( edit == 0 ) return false; + if ( edit == nullptr ) return false; if ( event.type == pw->GetEventTypeClose() ) { @@ -692,7 +692,7 @@ void CStudio::AdjustEditScript() dim.x = wdim.x-0.02f; dim.y = wdim.y-0.22f-hList; edit = static_cast< CEdit* >(pw->SearchControl(EVENT_STUDIO_EDIT)); - if ( edit != 0 ) + if ( edit != nullptr ) { edit->SetPos(pos); edit->SetDim(dim); @@ -703,7 +703,7 @@ void CStudio::AdjustEditScript() dim.x = wdim.x-0.02f; dim.y = hList; list = static_cast< CList* >(pw->SearchControl(EVENT_STUDIO_LIST)); - if ( list != 0 ) + if ( list != nullptr ) { list->SetPos(pos); list->SetDim(dim); @@ -716,56 +716,56 @@ void CStudio::AdjustEditScript() pos.y = wpos.y+wdim.y-dim.y-0.06f; pos.x = wpos.x+0.01f; button = static_cast< CButton* >(pw->SearchControl(EVENT_STUDIO_NEW)); - if ( button != 0 ) + if ( button != nullptr ) { button->SetPos(pos); button->SetDim(dim); } pos.x = wpos.x+0.05f; button = static_cast< CButton* >(pw->SearchControl(EVENT_STUDIO_OPEN)); - if ( button != 0 ) + if ( button != nullptr ) { button->SetPos(pos); button->SetDim(dim); } pos.x = wpos.x+0.09f; button = static_cast< CButton* >(pw->SearchControl(EVENT_STUDIO_SAVE)); - if ( button != 0 ) + if ( button != nullptr ) { button->SetPos(pos); button->SetDim(dim); } pos.x = wpos.x+0.14f; button = static_cast< CButton* >(pw->SearchControl(EVENT_STUDIO_UNDO)); - if ( button != 0 ) + if ( button != nullptr ) { button->SetPos(pos); button->SetDim(dim); } pos.x = wpos.x+0.19f; button = static_cast< CButton* >(pw->SearchControl(EVENT_STUDIO_CUT)); - if ( button != 0 ) + if ( button != nullptr ) { button->SetPos(pos); button->SetDim(dim); } pos.x = wpos.x+0.23f; button = static_cast< CButton* >(pw->SearchControl(EVENT_STUDIO_COPY)); - if ( button != 0 ) + if ( button != nullptr ) { button->SetPos(pos); button->SetDim(dim); } pos.x = wpos.x+0.27f; button = static_cast< CButton* >(pw->SearchControl(EVENT_STUDIO_PASTE)); - if ( button != 0 ) + if ( button != nullptr ) { button->SetPos(pos); button->SetDim(dim); } pos.x = wpos.x+0.32f; slider = static_cast< CSlider* >(pw->SearchControl(EVENT_STUDIO_SIZE)); - if ( slider != 0 ) + if ( slider != nullptr ) { ppos = pos; ddim.x = dim.x*0.7f; @@ -777,21 +777,21 @@ void CStudio::AdjustEditScript() } pos.x = wpos.x+0.36f; group = static_cast< CGroup* >(pw->SearchControl(EVENT_LABEL1)); - if ( group != 0 ) + if ( group != nullptr ) { group->SetPos(pos); group->SetDim(dim); } pos.x = wpos.x+0.40f; button = static_cast< CButton* >(pw->SearchControl(EVENT_STUDIO_TOOL)); - if ( button != 0 ) + if ( button != nullptr ) { button->SetPos(pos); button->SetDim(dim); } pos.x = wpos.x+0.44f; button = static_cast< CButton* >(pw->SearchControl(EVENT_STUDIO_HELP)); - if ( button != 0 ) + if ( button != nullptr ) { button->SetPos(pos); button->SetDim(dim); @@ -802,14 +802,14 @@ void CStudio::AdjustEditScript() dim.x = 80.0f/640.0f; dim.y = 25.0f/480.0f; button = static_cast< CButton* >(pw->SearchControl(EVENT_STUDIO_OK)); - if ( button != 0 ) + if ( button != nullptr ) { button->SetPos(pos); button->SetDim(dim); } pos.x = wpos.x+0.14f; button = static_cast< CButton* >(pw->SearchControl(EVENT_STUDIO_CANCEL)); - if ( button != 0 ) + if ( button != nullptr ) { button->SetPos(pos); button->SetDim(dim); @@ -817,28 +817,28 @@ void CStudio::AdjustEditScript() pos.x = wpos.x+0.28f; dim.x = dim.y*0.75f; button = static_cast< CButton* >(pw->SearchControl(EVENT_STUDIO_COMPILE)); - if ( button != 0 ) + if ( button != nullptr ) { button->SetPos(pos); button->SetDim(dim); } pos.x = wpos.x+0.28f+dim.x*1; button = static_cast< CButton* >(pw->SearchControl(EVENT_STUDIO_RUN)); - if ( button != 0 ) + if ( button != nullptr ) { button->SetPos(pos); button->SetDim(dim); } pos.x = wpos.x+0.28f+dim.x*2; button = static_cast< CButton* >(pw->SearchControl(EVENT_STUDIO_REALTIME)); - if ( button != 0 ) + if ( button != nullptr ) { button->SetPos(pos); button->SetDim(dim); } pos.x = wpos.x+0.28f+dim.x*3; button = static_cast< CButton* >(pw->SearchControl(EVENT_STUDIO_STEP)); - if ( button != 0 ) + if ( button != nullptr ) { button->SetPos(pos); button->SetDim(dim); -- cgit v1.2.3-1-g7c22 From 3f6a6a9eefc54452dc99a15f67bdfabc7e19788b Mon Sep 17 00:00:00 2001 From: erihel Date: Sat, 9 Feb 2013 23:49:38 +0100 Subject: * Syntax highlighting in cbot editor (needs to be tested) --- src/graphics/engine/text.cpp | 23 ++++++++-------- src/graphics/engine/text.h | 12 ++++----- src/ui/edit.cpp | 63 ++++++++++++++++++++++++++------------------ src/ui/edit.h | 2 +- 4 files changed, 57 insertions(+), 43 deletions(-) diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index dfe7a3c..48af081 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -153,7 +153,7 @@ void CText::FlushCache() m_lastCachedFont = nullptr; } -void CText::DrawText(const std::string &text, std::map &format, +void CText::DrawText(const std::string &text, std::vector::iterator format, float size, Math::Point pos, float width, TextAlign align, int eol, Color color) { @@ -197,7 +197,7 @@ void CText::DrawText(const std::string &text, FontType font, DrawString(text, font, size, pos, width, eol, color); } -void CText::SizeText(const std::string &text, std::map &format, +void CText::SizeText(const std::string &text, std::vector::iterator format, float size, Math::Point pos, TextAlign align, Math::Point &start, Math::Point &end) { @@ -281,7 +281,7 @@ float CText::GetHeight(FontType font, float size) float CText::GetStringWidth(const std::string &text, - std::map &format, float size) + std::vector::iterator format, float size) { float width = 0.0f; unsigned int index = 0; @@ -289,7 +289,7 @@ float CText::GetStringWidth(const std::string &text, while (index < text.length()) { FontType font = FONT_COLOBOT; - if (format.count(fmtIndex)) + //if (format.size() > fmtIndex) font = static_cast(format[fmtIndex] & FONT_MASK_FONT); UTF8Char ch; @@ -347,7 +347,7 @@ float CText::GetCharWidth(UTF8Char ch, FontType font, float size, float offset) } -int CText::Justify(const std::string &text, std::map &format, +int CText::Justify(const std::string &text, std::vector::iterator format, float size, float width) { float pos = 0.0f; @@ -357,7 +357,7 @@ int CText::Justify(const std::string &text, std::map while (index < text.length()) { FontType font = FONT_COLOBOT; - if (format.count(fmtIndex)) + //if (format.size() > fmtIndex) font = static_cast(format[fmtIndex] & FONT_MASK_FONT); UTF8Char ch; @@ -431,7 +431,7 @@ int CText::Justify(const std::string &text, FontType font, float size, float wid return index; } -int CText::Detect(const std::string &text, std::map &format, +int CText::Detect(const std::string &text, std::vector::iterator format, float size, float offset) { float pos = 0.0f; @@ -440,7 +440,7 @@ int CText::Detect(const std::string &text, std::map while (index < text.length()) { FontType font = FONT_COLOBOT; - if (format.count(fmtIndex)) + //if (format.size() > fmtIndex) font = static_cast(format[fmtIndex] & FONT_MASK_FONT); // TODO: if (font == FONT_BUTTON) @@ -504,7 +504,7 @@ int CText::Detect(const std::string &text, FontType font, float size, float offs return index; } -void CText::DrawString(const std::string &text, std::map &format, +void CText::DrawString(const std::string &text, std::vector::iterator format, float size, Math::Point pos, float width, int eol, Color color) { m_engine->SetState(ENG_RSTATE_TEXT); @@ -518,7 +518,7 @@ void CText::DrawString(const std::string &text, std::map fmtIndex) font = static_cast(format[fmtIndex] & FONT_MASK_FONT); // TODO: if (font == FONT_BUTTON) @@ -684,6 +684,7 @@ void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::P if (ch.c1 > 0 && ch.c1 < 32) { // FIXME add support for chars with code 9 10 23 if (ch.c1 == '\t') { ch.c1 = ':'; + width = 4; } else { ch.c1 = ' '; } @@ -708,7 +709,7 @@ void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::P } Math::Point p1(pos.x, pos.y + tex.charSize.y - tex.texSize.y); - Math::Point p2(pos.x + tex.texSize.x * width, pos.y + tex.charSize.y); + Math::Point p2(pos.x + tex.texSize.x, pos.y + tex.charSize.y); Math::Vector n(0.0f, 0.0f, -1.0f); // normal diff --git a/src/graphics/engine/text.h b/src/graphics/engine/text.h index 57fad43..e7578df 100644 --- a/src/graphics/engine/text.h +++ b/src/graphics/engine/text.h @@ -244,7 +244,7 @@ public: void FlushCache(); //! Draws text (multi-format) - void DrawText(const std::string &text, std::map &format, + void DrawText(const std::string &text, std::vector::iterator format, float size, Math::Point pos, float width, TextAlign align, int eol, Color color = Color(0.0f, 0.0f, 0.0f, 1.0f)); //! Draws text (one font) @@ -253,7 +253,7 @@ public: int eol, Color color = Color(0.0f, 0.0f, 0.0f, 1.0f)); //! Calculates dimensions for text (multi-format) - void SizeText(const std::string &text, std::map &format, + void SizeText(const std::string &text, std::vector::iterator format, float size, Math::Point pos, TextAlign align, Math::Point &start, Math::Point &end); //! Calculates dimensions for text (one font) @@ -270,20 +270,20 @@ public: //! Returns width of string (multi-format) TEST_VIRTUAL float GetStringWidth(const std::string &text, - std::map &format, float size); + std::vector::iterator format, float size); //! Returns width of string (single font) TEST_VIRTUAL float GetStringWidth(const std::string &text, FontType font, float size); //! Returns width of single character TEST_VIRTUAL float GetCharWidth(UTF8Char ch, FontType font, float size, float offset); //! Justifies a line of text (multi-format) - int Justify(const std::string &text, std::map &format, + int Justify(const std::string &text, std::vector::iterator format, float size, float width); //! Justifies a line of text (one font) int Justify(const std::string &text, FontType font, float size, float width); //! Returns the most suitable position to a given offset (multi-format) - int Detect(const std::string &text, std::map &format, + int Detect(const std::string &text, std::vector::iterator format, float size, float offset); //! Returns the most suitable position to a given offset (one font) int Detect(const std::string &text, FontType font, float size, float offset); @@ -292,7 +292,7 @@ protected: CachedFont* GetOrOpenFont(FontType type, float size); CharTexture CreateCharTexture(UTF8Char ch, CachedFont* font); - void DrawString(const std::string &text, std::map &format, + void DrawString(const std::string &text, std::vector::iterator format, float size, Math::Point pos, float width, int eol, Color color); void DrawString(const std::string &text, FontType font, float size, Math::Point pos, float width, int eol, Color color); diff --git a/src/ui/edit.cpp b/src/ui/edit.cpp index a1d213f..792e4a9 100644 --- a/src/ui/edit.cpp +++ b/src/ui/edit.cpp @@ -735,7 +735,7 @@ int CEdit::MouseDetect(Math::Point mouse) // len, offset, size, // m_fontStretch); c = m_engine->GetText()->Detect(std::string(m_text+m_lineOffset[i]).substr(0, len), - m_format, + m_format.begin() + m_lineOffset[i], size, offset); // TODO check if good } @@ -950,7 +950,7 @@ void CEdit::Draw() size = m_fontSize; // Headline \b;? - if ( beg+len < m_len && m_format.count(beg) && + if ( beg+len < m_len && m_format.size() > static_cast(beg) && (m_format[beg]&Gfx::FONT_MASK_TITLE) == Gfx::FONT_TITLE_BIG ) { start.x = ppos.x-MARGX; @@ -964,7 +964,7 @@ void CEdit::Draw() } // As \t;? - if ( beg+len < m_len && m_format.count(beg) && + if ( beg+len < m_len && m_format.size() > static_cast(beg) && (m_format[beg]&Gfx::FONT_MASK_TITLE) == Gfx::FONT_TITLE_NORM ) { start.x = ppos.x-MARGX; @@ -975,7 +975,7 @@ void CEdit::Draw() } // Subtitle \s;? - if ( beg+len < m_len && m_format.count(beg) && + if ( beg+len < m_len && m_format.size() > static_cast(beg) && (m_format[beg]&Gfx::FONT_MASK_TITLE) == Gfx::FONT_TITLE_LITTLE ) { start.x = ppos.x-MARGX; @@ -986,7 +986,7 @@ void CEdit::Draw() } // Table \tab;? - if ( beg+len < m_len && m_format.count(beg) && + if ( beg+len < m_len && m_format.size() > static_cast(beg) && (m_format[beg]&Gfx::FONT_MASK_HIGHLIGHT) == Gfx::FONT_HIGHLIGHT_TABLE ) { start.x = ppos.x-MARGX; @@ -997,7 +997,7 @@ void CEdit::Draw() } // Image \image; ? - if ( beg+len < m_len && m_format.count(beg) && + if ( beg+len < m_len && m_format.size() > static_cast(beg) && (m_format[beg]&Gfx::FONT_MASK_IMAGE) != 0 ) { line = 1; @@ -1005,7 +1005,7 @@ void CEdit::Draw() { if ( i+line >= m_lineTotal || i+line >= m_lineFirst+m_lineVisible || - (m_format.count(beg+line) && m_format[beg+line]&Gfx::FONT_MASK_IMAGE) == 0 ) break; + (m_format.size() > static_cast(beg+line) && m_format[beg+line]&Gfx::FONT_MASK_IMAGE) == 0 ) break; line ++; } @@ -1034,16 +1034,16 @@ void CEdit::Draw() else { start.x = ppos.x+m_engine->GetText()->GetStringWidth(std::string(m_text+beg).substr(0, o1-beg), - m_format, + m_format.begin() + beg, size); end.x = m_engine->GetText()->GetStringWidth(std::string(m_text+o1).substr(0, o2-o1), - m_format, + m_format.begin() + o1, size); } start.y = ppos.y-(m_bMulti?0.0f:MARGY1); end.y = m_lineHeight; - if ( m_format.count(beg) && (m_format[beg]&Gfx::FONT_MASK_TITLE) == Gfx::FONT_TITLE_BIG) end.y *= BIG_FONT; + if ( m_format.size() > static_cast(beg) && (m_format[beg]&Gfx::FONT_MASK_TITLE) == Gfx::FONT_TITLE_BIG) end.y *= BIG_FONT; DrawPart(start, end, 1); // plain yellow background } @@ -1065,7 +1065,7 @@ void CEdit::Draw() else { m_engine->GetText()->DrawText(std::string(m_text+beg).substr(0, len), - m_format, + m_format.begin() + beg, size, ppos, m_dim.x, @@ -1107,7 +1107,7 @@ void CEdit::Draw() else { m_engine->GetText()->SizeText(std::string(m_text+m_lineOffset[i]).substr(0, len), - m_format, + m_format.begin() + m_lineOffset[i], size, pos, Gfx::TEXT_ALIGN_LEFT, start, end); } @@ -1491,8 +1491,11 @@ bool CEdit::ReadText(const char *filename, int addSize) fread(buffer, 1, len, file); - if ( m_format.size() > 0 ) - m_format.clear(); + m_format.clear(); + m_format.reserve(m_maxChar+1); + for (i = 0; i <= m_maxChar+1; i++) { + m_format.push_back(0); + } fclose(file); @@ -1957,8 +1960,11 @@ void CEdit::SetMaxChar(int max) m_text = new char[m_maxChar+1]; memset(m_text, 0, m_maxChar+1); - if (m_format.size() > 0) - m_format.clear(); + m_format.clear(); + m_format.reserve(m_maxChar+1); + for (int i = 0; i <= m_maxChar+1; i++) { + m_format.push_back(0); + } m_len = 0; m_cursor1 = 0; @@ -2147,6 +2153,13 @@ bool CEdit::GetDisplaySpec() void CEdit::SetMultiFont(bool bMulti) { m_format.clear(); + + if (bMulti) { + m_format.reserve(m_maxChar+1); + for (int i = 0; i <= m_maxChar+1; i++) { + m_format.push_back(0); + } + } } // TODO check if it works correctly; was checking if variable is null @@ -2450,7 +2463,7 @@ void CEdit::MoveLine(int move, bool bWord, bool bSelect) else { c = m_engine->GetText()->Detect(std::string(m_text+m_lineOffset[line]), - m_format, + m_format.begin() + m_lineOffset[line], m_fontSize, m_lineOffset[line+1]-m_lineOffset[line]); } @@ -2481,7 +2494,7 @@ void CEdit::ColumnFix() { m_column = m_engine->GetText()->GetStringWidth( std::string(m_text+m_lineOffset[line]), - m_format, + m_format.begin() + m_lineOffset[line], m_fontSize ); } @@ -2884,7 +2897,7 @@ void CEdit::DeleteOne(int dir) { m_text[i] = m_text[i+hole]; - if ( m_format.count(i+hole) ) + if ( m_format.size() > static_cast(i + hole) ) { m_format[i] = m_format[i+hole]; } @@ -3087,13 +3100,13 @@ void CEdit::Justif() { size = m_fontSize; - if ( m_format.count(i) && (m_format[i]&Gfx::FONT_MASK_TITLE) == Gfx::FONT_TITLE_BIG ) // headline? + if ( m_format.size() > static_cast(i) && (m_format[i]&Gfx::FONT_MASK_TITLE) == Gfx::FONT_TITLE_BIG ) // headline? { size *= BIG_FONT; bDual = true; } - if ( m_format.count(i) && (m_format[i]&Gfx::FONT_MASK_IMAGE) != 0 ) // image part? + if ( m_format.size() > static_cast(i) && (m_format[i]&Gfx::FONT_MASK_IMAGE) != 0 ) // image part? { i ++; // jumps just a character (index in m_image) } @@ -3101,7 +3114,7 @@ void CEdit::Justif() { // TODO check if good i += m_engine->GetText()->Justify(std::string(m_text+i), - m_format, + m_format.begin() + i, size, width); } @@ -3296,12 +3309,12 @@ bool CEdit::SetFormat(int cursor1, int cursor2, int format) { int i; - //if ( m_format.size() == 0 ) return false; + if ( m_format.size() < static_cast(cursor2) ) + SetMultiFont(true); for ( i=cursor1 ; i m_format; // format characters + std::vector m_format; // format characters int m_len; // length used in m_text int m_cursor1; // offset cursor int m_cursor2; // offset cursor -- cgit v1.2.3-1-g7c22 From c7371da676a29def020a6c247ad1b3c47040fc90 Mon Sep 17 00:00:00 2001 From: erihel Date: Mon, 11 Feb 2013 20:17:43 +0100 Subject: * Fixed crash when inputing cheats --- src/ui/edit.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ui/edit.cpp b/src/ui/edit.cpp index 792e4a9..0e50852 100644 --- a/src/ui/edit.cpp +++ b/src/ui/edit.cpp @@ -2836,20 +2836,20 @@ void CEdit::InsertOne(char character) { m_text[i] = m_text[i-1]; // shoot - //if ( m_format.size() > 0 ) - //{ + if ( m_format.size() > static_cast(i) ) + { m_format[i] = m_format[i-1]; // shoot - //} + } } m_len ++; m_text[m_cursor1] = character; - //if ( m_format.size() > 0 ) - //{ + if ( m_format.size() > static_cast(m_cursor1) ) + { m_format[m_cursor1] = 0; - //} + } m_cursor1++; m_cursor2 = m_cursor1; -- cgit v1.2.3-1-g7c22 From d3106c73ff6239e184dc5a83609f7d08391e6148 Mon Sep 17 00:00:00 2001 From: adiblol Date: Mon, 11 Feb 2013 22:59:51 +0100 Subject: More camera distance from AlienQueen --- src/graphics/engine/camera.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/graphics/engine/camera.cpp b/src/graphics/engine/camera.cpp index d85194e..e5dd1e5 100644 --- a/src/graphics/engine/camera.cpp +++ b/src/graphics/engine/camera.cpp @@ -315,6 +315,7 @@ void CCamera::SetType(CameraType type) if ( oType == OBJECT_PARA ) m_backDist = 180.0f; if ( oType == OBJECT_SAFE ) m_backDist = 50.0f; if ( oType == OBJECT_HUSTON ) m_backDist = 120.0f; + if ( oType == OBJECT_MOTHER ) m_backDist = 55.0f; m_backMin = m_backDist/3.0f; if ( oType == OBJECT_HUMAN ) m_backMin = 10.0f; -- cgit v1.2.3-1-g7c22 From 34a008a49d31e0efc3cc2235aab898946c863cdf Mon Sep 17 00:00:00 2001 From: PaweX Date: Wed, 13 Feb 2013 02:32:41 +0100 Subject: Additional parameter for function aim(x, y). --- src/script/script.cpp | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/script/script.cpp b/src/script/script.cpp index 50ce830..ab8a1c1 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -2186,12 +2186,29 @@ bool CScript::rFire(CBotVar* var, CBotVar* result, int& exception, void* user) return Process(script, result, exception); } +// Compilation of the instruction "aim(x, y)". + +CBotTypResult cAim(CBotVar* &var, void* user) +{ + if ( var == 0 ) return CBotTypResult(CBotErrLowParam); + if ( var->GivType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); + var = var->GivNext(); + + if ( var == 0 ) return CBotTypResult(CBotTypFloat); + if ( var->GivType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); + var = var->GivNext(); + + if ( var != 0 ) return CBotTypResult(CBotErrOverParam); + + return CBotTypResult(CBotTypFloat); +} + // Instruction "aim(dir)". bool CScript::rAim(CBotVar* var, CBotVar* result, int& exception, void* user) { CScript* script = (static_cast(user))->GetRunScript(); - float value; + float x, y; Error err; exception = 0; @@ -2199,8 +2216,10 @@ bool CScript::rAim(CBotVar* var, CBotVar* result, int& exception, void* user) if ( script->m_primaryTask == 0 ) // no task in progress? { script->m_primaryTask = new CTaskManager(script->m_iMan, script->m_object); - value = var->GetValFloat(); - err = script->m_primaryTask->StartTaskGunGoal(value*Math::PI/180.0f, 0.0f); + x = var->GivValFloat(); + var = var->GivNext(); + var == 0 ? y=0.0f : y=var->GivValFloat(); + err = script->m_primaryTask->StartTaskGunGoal(x*Math::PI/180.0f, y*Math::PI/180.0f); if ( err != ERR_OK ) { delete script->m_primaryTask; @@ -2731,7 +2750,7 @@ void CScript::InitFonctions() CBotProgram::AddFunction("recycle", rRecycle, CScript::cNull); CBotProgram::AddFunction("shield", rShield, CScript::cShield); CBotProgram::AddFunction("fire", rFire, CScript::cFire); - CBotProgram::AddFunction("aim", rAim, CScript::cOneFloat); + CBotProgram::AddFunction("aim", rAim, CScript::cAim); CBotProgram::AddFunction("motor", rMotor, CScript::cMotor); CBotProgram::AddFunction("jet", rJet, CScript::cOneFloat); CBotProgram::AddFunction("topo", rTopo, CScript::cTopo); -- cgit v1.2.3-1-g7c22 From c26c063c5f3c0f45fd4ef3e717979768e7834780 Mon Sep 17 00:00:00 2001 From: PaweX Date: Wed, 13 Feb 2013 02:36:20 +0100 Subject: Additional parameter for function aim(x, y). --- src/script/cbottoken.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/script/cbottoken.cpp b/src/script/cbottoken.cpp index 0bb368c..06d36e1 100644 --- a/src/script/cbottoken.cpp +++ b/src/script/cbottoken.cpp @@ -476,7 +476,7 @@ const char* GetHelpText(const char *token) if ( strcmp(token, "shield" ) == 0 ) return "shield ( oper, radius );"; if ( strcmp(token, "fire" ) == 0 ) return "fire ( time );"; if ( strcmp(token, "antfire" ) == 0 ) return "antfire ( );"; - if ( strcmp(token, "aim" ) == 0 ) return "aim ( angle );"; + if ( strcmp(token, "aim" ) == 0 ) return "aim ( angle, angle );"; if ( strcmp(token, "motor" ) == 0 ) return "motor ( left, right );"; if ( strcmp(token, "jet" ) == 0 ) return "jet ( power );"; if ( strcmp(token, "topo" ) == 0 ) return "topo ( position );"; -- cgit v1.2.3-1-g7c22 From 34e758a9dae489f838360a6a8105b4008b91d62f Mon Sep 17 00:00:00 2001 From: PaweX Date: Wed, 13 Feb 2013 02:44:43 +0100 Subject: Additional parameter for function aim(x, y) --- src/graphics/engine/camera.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/graphics/engine/camera.cpp b/src/graphics/engine/camera.cpp index e5dd1e5..8026302 100644 --- a/src/graphics/engine/camera.cpp +++ b/src/graphics/engine/camera.cpp @@ -328,8 +328,8 @@ void CCamera::SetType(CameraType type) if ( oType == OBJECT_HUSTON ) m_backMin = 80.0f; } - if ( type != CAM_TYPE_ONBOARD && m_cameraObj != 0 ) - m_cameraObj->SetGunGoalH(0.0f); // puts the cannon right + //if ( type != CAM_TYPE_ONBOARD && m_cameraObj != 0 ) + // m_cameraObj->SetGunGoalH(0.0f); // puts the cannon right if ( type == CAM_TYPE_ONBOARD ) m_focus = 1.50f; // Wide -- cgit v1.2.3-1-g7c22 From 551d6c4d95182b8574e9d237fc26400414a609f2 Mon Sep 17 00:00:00 2001 From: PaweX Date: Wed, 13 Feb 2013 02:59:40 +0100 Subject: Additional parameter for function aim(x, y). --- src/object/object.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/object/object.cpp b/src/object/object.cpp index e2830c5..317775d 100644 --- a/src/object/object.cpp +++ b/src/object/object.cpp @@ -6617,7 +6617,7 @@ void CObject::SetSelect(bool bMode, bool bDisplayError) if ( !m_bSelect ) { - SetGunGoalH(0.0f); // puts the cannon right + //SetGunGoalH(0.0f); // puts the cannon right return; // selects if not finished } -- cgit v1.2.3-1-g7c22 From f25aed44d28f97d900bb9f4857cfcf282b80737c Mon Sep 17 00:00:00 2001 From: PaweX Date: Wed, 13 Feb 2013 13:48:56 +0100 Subject: aim(x,y) - "Giv" to "Get" --- src/script/script.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/script/script.cpp b/src/script/script.cpp index ab8a1c1..252f2cb 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -2216,9 +2216,9 @@ bool CScript::rAim(CBotVar* var, CBotVar* result, int& exception, void* user) if ( script->m_primaryTask == 0 ) // no task in progress? { script->m_primaryTask = new CTaskManager(script->m_iMan, script->m_object); - x = var->GivValFloat(); - var = var->GivNext(); - var == 0 ? y=0.0f : y=var->GivValFloat(); + x = var->GetValFloat(); + var = var->GetNext(); + var == 0 ? y=0.0f : y=var->GetValFloat(); err = script->m_primaryTask->StartTaskGunGoal(x*Math::PI/180.0f, y*Math::PI/180.0f); if ( err != ERR_OK ) { -- cgit v1.2.3-1-g7c22 From bcd06bd0e863648bf2850ef9257374085c735c97 Mon Sep 17 00:00:00 2001 From: PaweX Date: Wed, 13 Feb 2013 13:56:50 +0100 Subject: Function aim(x, y) - "Giv" to "Get" --- src/script/script.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/script/script.cpp b/src/script/script.cpp index 252f2cb..c73a88f 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -2191,12 +2191,12 @@ bool CScript::rFire(CBotVar* var, CBotVar* result, int& exception, void* user) CBotTypResult cAim(CBotVar* &var, void* user) { if ( var == 0 ) return CBotTypResult(CBotErrLowParam); - if ( var->GivType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); - var = var->GivNext(); + if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); + var = var->GetNext(); if ( var == 0 ) return CBotTypResult(CBotTypFloat); - if ( var->GivType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); - var = var->GivNext(); + if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); + var = var->GetNext(); if ( var != 0 ) return CBotTypResult(CBotErrOverParam); -- cgit v1.2.3-1-g7c22 From 4128383ee1a0d171a9f2bcfa66f30661b64b178e Mon Sep 17 00:00:00 2001 From: PaweX Date: Wed, 13 Feb 2013 14:04:24 +0100 Subject: Update src/script/script.cpp --- src/script/script.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/script/script.cpp b/src/script/script.cpp index c73a88f..fc34af0 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -2188,7 +2188,7 @@ bool CScript::rFire(CBotVar* var, CBotVar* result, int& exception, void* user) // Compilation of the instruction "aim(x, y)". -CBotTypResult cAim(CBotVar* &var, void* user) +CBotTypResult CScript::cAim(CBotVar* &var, void* user) { if ( var == 0 ) return CBotTypResult(CBotErrLowParam); if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); -- cgit v1.2.3-1-g7c22 From 86b302eb1728efecbecd8c8de6005758fdbce78d Mon Sep 17 00:00:00 2001 From: PaweX Date: Wed, 13 Feb 2013 16:20:35 +0100 Subject: Added cAim(CBotVar* &var, void* user) --- src/script/script.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/script/script.h b/src/script/script.h index dbd66a2..674a67e 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -117,6 +117,7 @@ private: static CBotTypResult cTestInfo(CBotVar* &var, void* user); static CBotTypResult cShield(CBotVar* &var, void* user); static CBotTypResult cFire(CBotVar* &var, void* user); + static CBotTypResult cAim(CBotVar* &var, void* user); static CBotTypResult cMotor(CBotVar* &var, void* user); static CBotTypResult cTopo(CBotVar* &var, void* user); static CBotTypResult cMessage(CBotVar* &var, void* user); -- cgit v1.2.3-1-g7c22 From 8658d6da8060cdb741c668d4be1b571ef064d01d Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 13 Feb 2013 16:57:59 +0100 Subject: Added Destroyer from Ceebot-Teen. We need a new icon for it. --- src/common/event.h | 3 +- src/common/global.h | 1 + src/common/restext.cpp | 1 + src/object/auto/autodestroyer.cpp | 90 ++++++++++++++++++++++++++++++++++----- src/object/brain.cpp | 10 +++-- src/object/task/taskbuild.cpp | 3 ++ src/script/cmdtoken.cpp | 1 + 7 files changed, 94 insertions(+), 15 deletions(-) diff --git a/src/common/event.h b/src/common/event.h index 169f0d0..cba167e 100644 --- a/src/common/event.h +++ b/src/common/event.h @@ -411,7 +411,8 @@ enum EventType EVENT_OBJECT_BNUCLEAR = 1060, EVENT_OBJECT_BPARA = 1061, EVENT_OBJECT_BINFO = 1062, - EVENT_OBJECT_BXXXX = 1063, + EVENT_OBJECT_BDESTROYER = 1063, + //EVENT_OBJECT_BXXXX = 1063, EVENT_OBJECT_GFLAT = 1070, EVENT_OBJECT_FCREATE = 1071, EVENT_OBJECT_FDELETE = 1072, diff --git a/src/common/global.h b/src/common/global.h index 0b2d8ec..7a5fdfd 100644 --- a/src/common/global.h +++ b/src/common/global.h @@ -213,6 +213,7 @@ enum BuildType BUILD_LABO = (1<<10), //! < laboratory BUILD_PARA = (1<<11), //! < lightning protection BUILD_INFO = (1<<12), //! < information terminal + BUILD_DESTROYER = (1<<13), //! < Destroyer BUILD_GFLAT = (1<<16), //! < flat floor BUILD_FLAG = (1<<17) //! < puts / removes colored flag }; diff --git a/src/common/restext.cpp b/src/common/restext.cpp index 4c56ae5..4768aed 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -308,6 +308,7 @@ void InitializeRestext() stringsEvent[EVENT_OBJECT_BNUCLEAR] = "Build a nuclear power plant"; stringsEvent[EVENT_OBJECT_BPARA] = "Build a lightning conductor"; stringsEvent[EVENT_OBJECT_BINFO] = "Build a exchange post"; + stringsEvent[EVENT_OBJECT_BDESTROYER] = "Build a destroyer"; stringsEvent[EVENT_OBJECT_GFLAT] = "Show if the ground is flat"; stringsEvent[EVENT_OBJECT_FCREATE] = "Plant a flag"; stringsEvent[EVENT_OBJECT_FDELETE] = "Remove a flag"; diff --git a/src/object/auto/autodestroyer.cpp b/src/object/auto/autodestroyer.cpp index ecf7c94..644071c 100644 --- a/src/object/auto/autodestroyer.cpp +++ b/src/object/auto/autodestroyer.cpp @@ -111,18 +111,39 @@ bool CAutoDestroyer::EventProcess(const Event &event) if ( SearchVehicle() ) { - m_phase = ADEP_WAIT; // still waiting ... - m_progress = 0.0f; - m_speed = 1.0f/0.5f; + if ( m_progress < 20.0f ) { + m_phase = ADEP_WAIT; // still waiting ... + //m_progress = 0.0f; + m_speed = 1.0f/0.5f; + } else { + if ( m_object->GetLock() ) { // If still building... + m_phase = ADEP_WAIT; // still waiting ... + m_progress = 0.0f; + m_speed = 1.0f/0.5f; + } else { + m_sound->Play(SOUND_PSHHH2, m_object->GetPosition(0), 1.0f, 1.0f); + + m_phase = ADEP_DOWN; + m_progress = 0.0f; + m_speed = 1.0f/1.0f; + m_bExplo = false; + } + } } else { - m_sound->Play(SOUND_PSHHH2, m_object->GetPosition(0), 1.0f, 1.0f); - - m_phase = ADEP_DOWN; - m_progress = 0.0f; - m_speed = 1.0f/1.0f; - m_bExplo = false; + if ( m_object->GetLock() ) { // If still building... + m_phase = ADEP_WAIT; // still waiting ... + m_progress = 0.0f; + m_speed = 1.0f/0.5f; + } else { + m_sound->Play(SOUND_PSHHH2, m_object->GetPosition(0), 1.0f, 1.0f); + + m_phase = ADEP_DOWN; + m_progress = 0.0f; + m_speed = 1.0f/1.0f; + m_bExplo = false; + } } } } @@ -243,8 +264,55 @@ CObject* CAutoDestroyer::SearchPlastic() if ( pObj == nullptr ) break; type = pObj->GetType(); - if ( type != OBJECT_SCRAP4 && - type != OBJECT_SCRAP5 ) continue; + //if ( type != OBJECT_SCRAP4 && + // type != OBJECT_SCRAP5 ) continue; + if ( type != OBJECT_FRET && + type != OBJECT_STONE && + type != OBJECT_URANIUM && + type != OBJECT_METAL && + type != OBJECT_POWER && + type != OBJECT_ATOMIC && + type != OBJECT_TNT && + type != OBJECT_SCRAP1 && + type != OBJECT_SCRAP2 && + type != OBJECT_SCRAP3 && + type != OBJECT_SCRAP4 && + type != OBJECT_SCRAP5 && + // Robots: + type != OBJECT_HUMAN && + type != OBJECT_MOBILEfa && + type != OBJECT_MOBILEta && + type != OBJECT_MOBILEwa && + type != OBJECT_MOBILEia && + type != OBJECT_MOBILEfc && + type != OBJECT_MOBILEtc && + type != OBJECT_MOBILEwc && + type != OBJECT_MOBILEic && + type != OBJECT_MOBILEfi && + type != OBJECT_MOBILEti && + type != OBJECT_MOBILEwi && + type != OBJECT_MOBILEii && + type != OBJECT_MOBILEfs && + type != OBJECT_MOBILEts && + type != OBJECT_MOBILEws && + type != OBJECT_MOBILEis && + type != OBJECT_MOBILErt && + type != OBJECT_MOBILErc && + type != OBJECT_MOBILErr && + type != OBJECT_MOBILErs && + type != OBJECT_MOBILEsa && + type != OBJECT_MOBILEtg && + type != OBJECT_MOBILEft && + type != OBJECT_MOBILEtt && + type != OBJECT_MOBILEwt && + type != OBJECT_MOBILEit && + type != OBJECT_MOBILEdr && + type != OBJECT_MOTHER && + type != OBJECT_ANT && + type != OBJECT_SPIDER && + type != OBJECT_BEE && + type != OBJECT_WORM ) continue; + oPos = pObj->GetPosition(0); dist = Math::Distance(oPos, sPos); diff --git a/src/object/brain.cpp b/src/object/brain.cpp index bc47cb3..1405201 100644 --- a/src/object/brain.cpp +++ b/src/object/brain.cpp @@ -528,6 +528,10 @@ bool CBrain::EventProcess(const Event &event) { err = StartTaskBuild(OBJECT_INFO); } + if ( action == EVENT_OBJECT_BDESTROYER ) + { + err = StartTaskBuild(OBJECT_DESTROYER); + } if ( action == EVENT_OBJECT_GFLAT ) { @@ -1454,8 +1458,8 @@ bool CBrain::CreateInterface(bool bSelect) pos.x = ox+sx*5.4f; pos.y = oy+sy*0.1f; - pw->CreateButton(pos, ddim, 128+56, EVENT_OBJECT_BXXXX); - DeadInterface(pw, EVENT_OBJECT_BXXXX, false); + pw->CreateButton(pos, ddim, 128+41, EVENT_OBJECT_BDESTROYER); + DeadInterface(pw, EVENT_OBJECT_BDESTROYER, g_build&BUILD_DESTROYER); if ( g_build&BUILD_GFLAT ) { @@ -2181,7 +2185,7 @@ void CBrain::UpdateInterface() EnableInterface(pw, EVENT_OBJECT_BNUCLEAR, bEnable); EnableInterface(pw, EVENT_OBJECT_BPARA, bEnable); EnableInterface(pw, EVENT_OBJECT_BINFO, bEnable); - EnableInterface(pw, EVENT_OBJECT_BXXXX, bEnable); + EnableInterface(pw, EVENT_OBJECT_BDESTROYER,bEnable); } pb = static_cast< Ui::CButton* >(pw->SearchControl(EVENT_OBJECT_GFLAT)); diff --git a/src/object/task/taskbuild.cpp b/src/object/task/taskbuild.cpp index d82874c..5673ea4 100644 --- a/src/object/task/taskbuild.cpp +++ b/src/object/task/taskbuild.cpp @@ -98,6 +98,7 @@ bool CTaskBuild::CreateBuilding(Math::Vector pos, float angle) if ( m_type == OBJECT_NUCLEAR ) m_buildingHeight = 40.0f; if ( m_type == OBJECT_PARA ) m_buildingHeight = 68.0f; if ( m_type == OBJECT_INFO ) m_buildingHeight = 19.0f; + if ( m_type == OBJECT_DESTROYER) m_buildingHeight = 35.0f; m_buildingHeight *= 0.25f; m_buildingPos = m_building->GetPosition(0); @@ -578,6 +579,7 @@ Error CTaskBuild::FlatFloor() if ( m_type == OBJECT_NUCLEAR ) radius = 20.0f; if ( m_type == OBJECT_PARA ) radius = 20.0f; if ( m_type == OBJECT_INFO ) radius = 5.0f; + if ( m_type == OBJECT_DESTROYER) radius = 20.0f; if ( radius == 0.0f ) return ERR_GENERIC; center = m_metal->GetPosition(0); @@ -666,6 +668,7 @@ Error CTaskBuild::FlatFloor() type == OBJECT_ENERGY || type == OBJECT_LABO || type == OBJECT_NUCLEAR || + type == OBJECT_DESTROYER|| type == OBJECT_START || type == OBJECT_END || type == OBJECT_INFO || diff --git a/src/script/cmdtoken.cpp b/src/script/cmdtoken.cpp index e44f82d..ab0528b 100644 --- a/src/script/cmdtoken.cpp +++ b/src/script/cmdtoken.cpp @@ -708,6 +708,7 @@ int GetBuild(char *line, int rank) if ( Cmd(p, "AutoLab" ) ) return BUILD_LABO; if ( Cmd(p, "PowerCaptor" ) ) return BUILD_PARA; if ( Cmd(p, "ExchangePost" ) ) return BUILD_INFO; + if ( Cmd(p, "Destroyer" ) ) return BUILD_DESTROYER; if ( Cmd(p, "FlatGround" ) ) return BUILD_GFLAT; if ( Cmd(p, "Flag" ) ) return BUILD_FLAG; -- cgit v1.2.3-1-g7c22 From 89a272cf8702531fd12c5f22098a1b9e7b4c133d Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 14 Feb 2013 15:48:02 +0100 Subject: produce() extended --- src/script/script.cpp | 165 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 144 insertions(+), 21 deletions(-) diff --git a/src/script/script.cpp b/src/script/script.cpp index fc34af0..c3cd996 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -940,55 +940,98 @@ bool CScript::rDirection(CBotVar* var, CBotVar* result, int& exception, void* us } -// Compilation of the instruction "produce(pos, angle, type, scriptName)". +// Compilation of the instruction "produce(pos, angle, type, scriptName, power)". +// or "produce(pos, angle, type, scriptName)" +// or "produce(pos, angle, type)" +// or "produce(type)" CBotTypResult CScript::cProduce(CBotVar* &var, void* user) { CBotTypResult ret; if ( var == 0 ) return CBotTypResult(CBotErrLowParam); - ret = cPoint(var, user); - if ( ret.GetType() != 0 ) return ret; - if ( var == 0 ) return CBotTypResult(CBotErrLowParam); - if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); - var = var->GetNext(); + if ( var->GetType() <= CBotTypDouble ) { + var = var->GetNext(); + } else { + ret = cPoint(var, user); + if ( ret.GetType() != 0 ) return ret; - if ( var == 0 ) return CBotTypResult(CBotErrLowParam); - if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); - var = var->GetNext(); + if ( var == 0 ) return CBotTypResult(CBotErrLowParam); + if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); + var = var->GetNext(); - if ( var == 0 ) return CBotTypResult(CBotErrLowParam); - if ( var->GetType() != CBotTypString ) return CBotTypResult(CBotErrBadString); - var = var->GetNext(); + if ( var == 0 ) return CBotTypResult(CBotErrLowParam); + if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); + var = var->GetNext(); + + if ( var != 0 ) { + if ( var->GetType() != CBotTypString ) return CBotTypResult(CBotErrBadString); + var = var->GetNext(); + + if ( var != 0 ) { + if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); + var = var->GetNext(); + } + } + } if ( var != 0 ) return CBotTypResult(CBotErrOverParam); return CBotTypResult(CBotTypFloat); } -// Instruction "produce(pos, angle, type, scriptName)". +// Instruction "produce(pos, angle, type, scriptName, power)". +// or "produce(pos, angle, type, scriptName)" +// or "produce(pos, angle, type)" +// or "produce(type)" bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user) { CScript* script = (static_cast(user))->GetRunScript(); CObject* object; + CObject* me = (static_cast(user)); CBotString cbs; const char* name; Math::Vector pos; float angle; ObjectType type; + float power; - if ( !GetPoint(var, exception, pos) ) return true; + if ( var->GetType() <= CBotTypDouble ) { + type = static_cast(var->GetValInt()); - angle = var->GetValFloat()*Math::PI/180.0f; - var = var->GetNext(); + pos = me->GetPosition(0); - type = static_cast(var->GetValInt()); - var = var->GetNext(); + Math::Vector rotation = me->GetAngle(0) + me->GetInclinaison(); + angle = rotation.y; - cbs = var->GetValString(); - name = cbs; + power = -1.0f; + + name = ""; + } else { + if ( !GetPoint(var, exception, pos) ) return true; + + angle = var->GetValFloat()*Math::PI/180.0f; + var = var->GetNext(); + + type = static_cast(var->GetValInt()); + var = var->GetNext(); + + if ( var != 0 ) { + cbs = var->GetValString(); + name = cbs; + var = var->GetNext(); + if ( var != 0 ) { + power = var->GetValFloat(); + } else { + power = -1.0f; + } + } else { + name = ""; + power = -1.0f; + } + } if ( type == OBJECT_FRET || type == OBJECT_STONE || @@ -1020,6 +1063,7 @@ bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user result->SetValInt(1); // error return true; } + object->SetActivity(false); } else if ( type == OBJECT_MOTHER || @@ -1043,13 +1087,92 @@ bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user { delete egg; } + object->SetActivity(false); + } + else + if ( type == OBJECT_DERRICK || + type == OBJECT_FACTORY || + type == OBJECT_STATION || + type == OBJECT_CONVERT || + type == OBJECT_REPAIR || + type == OBJECT_TOWER || + type == OBJECT_NEST || + type == OBJECT_RESEARCH || + type == OBJECT_RADAR || + type == OBJECT_ENERGY || + type == OBJECT_LABO || + type == OBJECT_NUCLEAR || + type == OBJECT_START || + type == OBJECT_END || + type == OBJECT_INFO || + type == OBJECT_PARA || + type == OBJECT_TARGET1 || + type == OBJECT_TARGET2 || + type == OBJECT_SAFE || + type == OBJECT_HUSTON || + type == OBJECT_DESTROYER ) { + object = new CObject(script->m_iMan); + if ( !object->CreateBuilding(pos, angle, 0, type) ) + { + delete object; + result->SetValInt(1); // error + return true; + } + object->SetActivity(false); + } + else + if ( type == OBJECT_MOBILEwt || + type == OBJECT_MOBILEtt || + type == OBJECT_MOBILEft || + type == OBJECT_MOBILEit || + type == OBJECT_MOBILEwa || + type == OBJECT_MOBILEta || + type == OBJECT_MOBILEfa || + type == OBJECT_MOBILEia || + type == OBJECT_MOBILEwc || + type == OBJECT_MOBILEtc || + type == OBJECT_MOBILEfc || + type == OBJECT_MOBILEic || + type == OBJECT_MOBILEwi || + type == OBJECT_MOBILEti || + type == OBJECT_MOBILEfi || + type == OBJECT_MOBILEii || + type == OBJECT_MOBILEws || + type == OBJECT_MOBILEts || + type == OBJECT_MOBILEfs || + type == OBJECT_MOBILEis || + type == OBJECT_MOBILErt || + type == OBJECT_MOBILErc || + type == OBJECT_MOBILErr || + type == OBJECT_MOBILErs || + type == OBJECT_MOBILEsa || + type == OBJECT_MOBILEtg || + type == OBJECT_MOBILEdr ) { + object = new CObject(script->m_iMan); + if ( !object->CreateVehicle(pos, angle, type, power, false, false) ) + { + delete object; + result->SetValInt(1); // error + return true; + } + object->UpdateMapping(); + object->SetRange(30.0f); + object->SetZoom(0, 1.0f); + CPhysics* physics = object->GetPhysics(); + if ( physics != 0 ) + { + physics->SetFreeze(false); // can move + } + object->SetLock(false); // vehicle useable + object->SetActivity(true); + script->m_main->CreateShortcuts(); } else { result->SetValInt(1); // impossible return true; } - object->SetActivity(false); + object->ReadProgram(0, static_cast(name)); object->RunProgram(0); -- cgit v1.2.3-1-g7c22 From 15682c27e3be211cac2ab0f3c0c708c12679cfc3 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 14 Feb 2013 15:59:24 +0100 Subject: Temporairly disabled "test" in travis It always fails. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index af27ea3..275f195 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: cpp compiler: - gcc - clang -script: mkdir build; cd build; cmake .. -DCMAKE_VERBOSE_MAKEFILE=ON && make all doc test && DESTDIR=. make install +script: mkdir build; cd build; cmake .. -DCMAKE_VERBOSE_MAKEFILE=ON && make all doc && DESTDIR=. make install before_install: - git submodule update --init --recursive - sudo add-apt-repository ppa:mapnik/boost -y -- cgit v1.2.3-1-g7c22 From de228f57e8034b8aaa3840a318d59095ce06d6ff Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 14 Feb 2013 16:04:52 +0100 Subject: Small fix in produce() --- src/script/script.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/script/script.cpp b/src/script/script.cpp index c3cd996..9f05310 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -1119,6 +1119,7 @@ bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user return true; } object->SetActivity(false); + script->m_main->CreateShortcuts(); } else if ( type == OBJECT_MOBILEwt || -- cgit v1.2.3-1-g7c22 From e2d0f449617b6344a18b909bf8c81451290b42af Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 14 Feb 2013 17:18:04 +0100 Subject: More fixes to produce() Now every object can be created. --- src/script/script.cpp | 145 +++++++++++++++++++++++++++++++------------------- 1 file changed, 89 insertions(+), 56 deletions(-) diff --git a/src/script/script.cpp b/src/script/script.cpp index 9f05310..7a80266 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -1033,28 +1033,37 @@ bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user } } - if ( type == OBJECT_FRET || - type == OBJECT_STONE || - type == OBJECT_URANIUM || - type == OBJECT_METAL || - type == OBJECT_POWER || - type == OBJECT_ATOMIC || - type == OBJECT_BULLET || - type == OBJECT_BBOX || - type == OBJECT_KEYa || - type == OBJECT_KEYb || - type == OBJECT_KEYc || - type == OBJECT_KEYd || - type == OBJECT_TNT || - type == OBJECT_SCRAP1 || - type == OBJECT_SCRAP2 || - type == OBJECT_SCRAP3 || - type == OBJECT_SCRAP4 || - type == OBJECT_SCRAP5 || - type == OBJECT_BOMB || - type == OBJECT_WAYPOINT || - type == OBJECT_SHOW || - type == OBJECT_WINFIRE ) + if ( type == OBJECT_FRET || + type == OBJECT_STONE || + type == OBJECT_URANIUM || + type == OBJECT_METAL || + type == OBJECT_POWER || + type == OBJECT_ATOMIC || + type == OBJECT_BULLET || + type == OBJECT_BBOX || + type == OBJECT_KEYa || + type == OBJECT_KEYb || + type == OBJECT_KEYc || + type == OBJECT_KEYd || + type == OBJECT_TNT || + type == OBJECT_SCRAP1 || + type == OBJECT_SCRAP2 || + type == OBJECT_SCRAP3 || + type == OBJECT_SCRAP4 || + type == OBJECT_SCRAP5 || + type == OBJECT_BOMB || + type == OBJECT_WAYPOINT || + type == OBJECT_SHOW || + type == OBJECT_WINFIRE || + type == OBJECT_BAG || + type == OBJECT_MARKPOWER || + type == OBJECT_MARKSTONE || + type == OBJECT_MARKURANIUM || + type == OBJECT_MARKKEYa || + type == OBJECT_MARKKEYb || + type == OBJECT_MARKKEYc || + type == OBJECT_MARKKEYd || + type == OBJECT_EGG ) { object = new CObject(script->m_iMan); if ( !object->CreateResource(pos, angle, type) ) @@ -1090,27 +1099,30 @@ bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user object->SetActivity(false); } else - if ( type == OBJECT_DERRICK || - type == OBJECT_FACTORY || - type == OBJECT_STATION || - type == OBJECT_CONVERT || - type == OBJECT_REPAIR || - type == OBJECT_TOWER || - type == OBJECT_NEST || - type == OBJECT_RESEARCH || - type == OBJECT_RADAR || - type == OBJECT_ENERGY || - type == OBJECT_LABO || - type == OBJECT_NUCLEAR || - type == OBJECT_START || - type == OBJECT_END || - type == OBJECT_INFO || - type == OBJECT_PARA || - type == OBJECT_TARGET1 || - type == OBJECT_TARGET2 || - type == OBJECT_SAFE || - type == OBJECT_HUSTON || - type == OBJECT_DESTROYER ) { + if ( type == OBJECT_PORTICO || + type == OBJECT_BASE || + type == OBJECT_DERRICK || + type == OBJECT_FACTORY || + type == OBJECT_STATION || + type == OBJECT_CONVERT || + type == OBJECT_REPAIR || + type == OBJECT_DESTROYER|| + type == OBJECT_TOWER || + type == OBJECT_NEST || + type == OBJECT_RESEARCH || + type == OBJECT_RADAR || + type == OBJECT_INFO || + type == OBJECT_ENERGY || + type == OBJECT_LABO || + type == OBJECT_NUCLEAR || + type == OBJECT_PARA || + type == OBJECT_SAFE || + type == OBJECT_HUSTON || + type == OBJECT_TARGET1 || + type == OBJECT_TARGET2 || + type == OBJECT_START || + type == OBJECT_END ) + { object = new CObject(script->m_iMan); if ( !object->CreateBuilding(pos, angle, 0, type) ) { @@ -1122,25 +1134,40 @@ bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user script->m_main->CreateShortcuts(); } else - if ( type == OBJECT_MOBILEwt || - type == OBJECT_MOBILEtt || - type == OBJECT_MOBILEft || - type == OBJECT_MOBILEit || - type == OBJECT_MOBILEwa || - type == OBJECT_MOBILEta || + if ( type == OBJECT_FLAGb || + type == OBJECT_FLAGr || + type == OBJECT_FLAGg || + type == OBJECT_FLAGy || + type == OBJECT_FLAGv ) + { + object = new CObject(m_iMan); + if ( !object->CreateFlag(pos, angle, type); ) + { + delete object; + result->SetValInt(1); // error + return true; + } + object->SetActivity(false); + } + else + if ( type == OBJECT_HUMAN || + type == OBJECT_TECH || + type == OBJECT_TOTO || type == OBJECT_MOBILEfa || + type == OBJECT_MOBILEta || + type == OBJECT_MOBILEwa || type == OBJECT_MOBILEia || - type == OBJECT_MOBILEwc || - type == OBJECT_MOBILEtc || type == OBJECT_MOBILEfc || + type == OBJECT_MOBILEtc || + type == OBJECT_MOBILEwc || type == OBJECT_MOBILEic || - type == OBJECT_MOBILEwi || - type == OBJECT_MOBILEti || type == OBJECT_MOBILEfi || + type == OBJECT_MOBILEti || + type == OBJECT_MOBILEwi || type == OBJECT_MOBILEii || - type == OBJECT_MOBILEws || - type == OBJECT_MOBILEts || type == OBJECT_MOBILEfs || + type == OBJECT_MOBILEts || + type == OBJECT_MOBILEws || type == OBJECT_MOBILEis || type == OBJECT_MOBILErt || type == OBJECT_MOBILErc || @@ -1148,7 +1175,13 @@ bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user type == OBJECT_MOBILErs || type == OBJECT_MOBILEsa || type == OBJECT_MOBILEtg || - type == OBJECT_MOBILEdr ) { + type == OBJECT_MOBILEft || + type == OBJECT_MOBILEtt || + type == OBJECT_MOBILEwt || + type == OBJECT_MOBILEit || + type == OBJECT_MOBILEdr || + type == OBJECT_APOLLO2 ) + { object = new CObject(script->m_iMan); if ( !object->CreateVehicle(pos, angle, type, power, false, false) ) { -- cgit v1.2.3-1-g7c22 From 945299ae5dfe465b1a407ed56a3e45d373e8106e Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 14 Feb 2013 17:23:26 +0100 Subject: Small fix --- src/script/script.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/script/script.cpp b/src/script/script.cpp index 7a80266..f80e943 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -1140,7 +1140,7 @@ bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user type == OBJECT_FLAGy || type == OBJECT_FLAGv ) { - object = new CObject(m_iMan); + object = new CObject(script->m_iMan); if ( !object->CreateFlag(pos, angle, type); ) { delete object; -- cgit v1.2.3-1-g7c22 From 5d331f37ae3ade906d092d985703db1afc55d417 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 14 Feb 2013 17:26:01 +0100 Subject: Another small fix. I'm a noob. Sorry. --- src/script/script.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/script/script.cpp b/src/script/script.cpp index f80e943..199fd43 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -1141,7 +1141,7 @@ bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user type == OBJECT_FLAGv ) { object = new CObject(script->m_iMan); - if ( !object->CreateFlag(pos, angle, type); ) + if ( !object->CreateFlag(pos, angle, type) ) { delete object; result->SetValInt(1); // error -- cgit v1.2.3-1-g7c22 From f0e0896c2b86c2800efd7411cfb2c6c0e9c1a1b7 Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Thu, 14 Feb 2013 18:42:45 +0100 Subject: Comment the test that fails, with a TODO. --- test/unit/ui/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/unit/ui/CMakeLists.txt b/test/unit/ui/CMakeLists.txt index 32af230..916a73b 100644 --- a/test/unit/ui/CMakeLists.txt +++ b/test/unit/ui/CMakeLists.txt @@ -26,4 +26,5 @@ stubs/robotmain_stub.cpp edit_test.cpp) target_link_libraries(edit_test gtest gmock ${SDL_LIBRARY} ${SDLTTF_LIBRARY} ${Boost_LIBRARIES}) -add_test(edit_test ./edit_test) +# TODO: Edit test doesn't work, comment it away for now +# add_test(edit_test ./edit_test) -- cgit v1.2.3-1-g7c22 From 22b7a1b1ad78eb4a0df98fbd063c2ce81aaa1314 Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Thu, 14 Feb 2013 18:43:05 +0100 Subject: Revert "Temporairly disabled "test" in travis" This reverts commit 15682c27e3be211cac2ab0f3c0c708c12679cfc3. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 275f195..af27ea3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: cpp compiler: - gcc - clang -script: mkdir build; cd build; cmake .. -DCMAKE_VERBOSE_MAKEFILE=ON && make all doc && DESTDIR=. make install +script: mkdir build; cd build; cmake .. -DCMAKE_VERBOSE_MAKEFILE=ON && make all doc test && DESTDIR=. make install before_install: - git submodule update --init --recursive - sudo add-apt-repository ppa:mapnik/boost -y -- cgit v1.2.3-1-g7c22 From 001d37b257b126dd6ef1dced70f94ff3d2806d28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Dziwi=C5=84ski?= Date: Sat, 16 Feb 2013 22:37:43 +0100 Subject: CInstanceManager refactoring * removed classes managed by CInstanceManager except for CObject, CPyro, CBrain and CPhysics because of dependencies * refactored instance searching to use existing singleton instances of CApplication, CEngine and CRobotMain and calling their getter functions --- CMakeLists.txt | 2 +- src/CBot/CBotDll.h | 6 +- src/CBot/CBotToken.cpp | 2 - src/CBot/ClassFILE.cpp | 2 - src/app/app.cpp | 18 ++- src/app/app.h | 10 +- src/common/event.cpp | 7 +- src/common/event.h | 5 +- src/common/iman.cpp | 15 +-- src/common/iman.h | 67 ++-------- src/common/logger.cpp | 2 +- src/common/profile.cpp | 2 +- src/common/singleton.h | 77 +++++++----- src/graphics/engine/camera.cpp | 26 ++-- src/graphics/engine/camera.h | 6 +- src/graphics/engine/cloud.cpp | 19 ++- src/graphics/engine/cloud.h | 11 +- src/graphics/engine/engine.cpp | 89 +++++++++---- src/graphics/engine/engine.h | 31 +++-- src/graphics/engine/lightman.cpp | 9 +- src/graphics/engine/lightman.h | 3 +- src/graphics/engine/lightning.cpp | 22 ++-- src/graphics/engine/lightning.h | 4 +- src/graphics/engine/modelfile.cpp | 1 - src/graphics/engine/modelmanager.cpp | 2 +- src/graphics/engine/particle.cpp | 29 +++-- src/graphics/engine/particle.h | 4 +- src/graphics/engine/planet.cpp | 8 +- src/graphics/engine/planet.h | 5 +- src/graphics/engine/pyro.cpp | 34 ++--- src/graphics/engine/pyro.h | 4 +- src/graphics/engine/terrain.cpp | 13 +- src/graphics/engine/terrain.h | 6 +- src/graphics/engine/text.cpp | 11 +- src/graphics/engine/text.h | 6 +- src/graphics/engine/water.cpp | 28 ++--- src/graphics/engine/water.h | 8 +- src/object/auto/auto.cpp | 54 +++++--- src/object/auto/auto.h | 7 +- src/object/auto/autobase.cpp | 14 ++- src/object/auto/autobase.h | 2 +- src/object/auto/autoconvert.cpp | 8 +- src/object/auto/autoconvert.h | 2 +- src/object/auto/autoderrick.cpp | 9 +- src/object/auto/autoderrick.h | 2 +- src/object/auto/autodestroyer.cpp | 7 +- src/object/auto/autodestroyer.h | 2 +- src/object/auto/autoegg.cpp | 11 +- src/object/auto/autoegg.h | 2 +- src/object/auto/autoenergy.cpp | 9 +- src/object/auto/autoenergy.h | 2 +- src/object/auto/autofactory.cpp | 10 +- src/object/auto/autofactory.h | 2 +- src/object/auto/autoflag.cpp | 3 +- src/object/auto/autoflag.h | 2 +- src/object/auto/autohuston.cpp | 3 +- src/object/auto/autohuston.h | 2 +- src/object/auto/autoinfo.cpp | 3 +- src/object/auto/autoinfo.h | 2 +- src/object/auto/autojostle.cpp | 3 +- src/object/auto/autojostle.h | 2 +- src/object/auto/autokid.cpp | 3 +- src/object/auto/autokid.h | 2 +- src/object/auto/autolabo.cpp | 11 +- src/object/auto/autolabo.h | 2 +- src/object/auto/automush.cpp | 4 +- src/object/auto/automush.h | 2 +- src/object/auto/autonest.cpp | 7 +- src/object/auto/autonest.h | 2 +- src/object/auto/autonuclear.cpp | 8 +- src/object/auto/autonuclear.h | 2 +- src/object/auto/autopara.cpp | 6 +- src/object/auto/autopara.h | 2 +- src/object/auto/autoportico.cpp | 3 +- src/object/auto/autoportico.h | 2 +- src/object/auto/autoradar.cpp | 5 +- src/object/auto/autoradar.h | 2 +- src/object/auto/autorepair.cpp | 6 +- src/object/auto/autorepair.h | 2 +- src/object/auto/autoresearch.cpp | 9 +- src/object/auto/autoresearch.h | 2 +- src/object/auto/autoroot.cpp | 4 +- src/object/auto/autoroot.h | 2 +- src/object/auto/autosafe.cpp | 7 +- src/object/auto/autosafe.h | 2 +- src/object/auto/autostation.cpp | 6 +- src/object/auto/autostation.h | 2 +- src/object/auto/autotower.cpp | 7 +- src/object/auto/autotower.h | 2 +- src/object/brain.cpp | 83 ++++++------- src/object/brain.h | 4 +- src/object/mainmovie.cpp | 15 +-- src/object/mainmovie.h | 16 +-- src/object/motion/motion.cpp | 23 ++-- src/object/motion/motion.h | 8 +- src/object/motion/motionant.cpp | 3 +- src/object/motion/motionant.h | 2 +- src/object/motion/motionbee.cpp | 3 +- src/object/motion/motionbee.h | 2 +- src/object/motion/motionhuman.cpp | 3 +- src/object/motion/motionhuman.h | 2 +- src/object/motion/motionmother.cpp | 3 +- src/object/motion/motionmother.h | 2 +- src/object/motion/motionspider.cpp | 3 +- src/object/motion/motionspider.h | 2 +- src/object/motion/motiontoto.cpp | 3 +- src/object/motion/motiontoto.h | 2 +- src/object/motion/motionvehicle.cpp | 5 +- src/object/motion/motionvehicle.h | 2 +- src/object/motion/motionworm.cpp | 3 +- src/object/motion/motionworm.h | 2 +- src/object/object.cpp | 136 ++++++++++---------- src/object/object.h | 7 +- src/object/robotmain.cpp | 227 ++++++++++++++++++++++------------ src/object/robotmain.h | 20 +-- src/object/task/task.cpp | 31 ++--- src/object/task/task.h | 5 +- src/object/task/taskadvance.cpp | 5 +- src/object/task/taskadvance.h | 3 +- src/object/task/taskbuild.cpp | 25 ++-- src/object/task/taskbuild.h | 2 +- src/object/task/taskfire.cpp | 6 +- src/object/task/taskfire.h | 2 +- src/object/task/taskfireant.cpp | 7 +- src/object/task/taskfireant.h | 2 +- src/object/task/taskflag.cpp | 26 ++-- src/object/task/taskflag.h | 3 +- src/object/task/taskgoto.cpp | 38 ++++-- src/object/task/taskgoto.h | 3 +- src/object/task/taskgungoal.cpp | 4 +- src/object/task/taskgungoal.h | 2 +- src/object/task/taskinfo.cpp | 10 +- src/object/task/taskinfo.h | 2 +- src/object/task/taskmanager.cpp | 48 ++++--- src/object/task/taskmanager.h | 7 +- src/object/task/taskmanip.cpp | 30 +++-- src/object/task/taskmanip.h | 2 +- src/object/task/taskpen.cpp | 8 +- src/object/task/taskpen.h | 2 +- src/object/task/taskrecover.cpp | 17 +-- src/object/task/taskrecover.h | 3 +- src/object/task/taskreset.cpp | 9 +- src/object/task/taskreset.h | 2 +- src/object/task/tasksearch.cpp | 16 ++- src/object/task/tasksearch.h | 2 +- src/object/task/taskshield.cpp | 12 +- src/object/task/taskshield.h | 3 +- src/object/task/taskspiderexplo.cpp | 8 +- src/object/task/taskspiderexplo.h | 2 +- src/object/task/tasktake.cpp | 22 ++-- src/object/task/tasktake.h | 2 +- src/object/task/taskterraform.cpp | 19 +-- src/object/task/taskterraform.h | 3 +- src/object/task/taskturn.cpp | 4 +- src/object/task/taskturn.h | 2 +- src/object/task/taskwait.cpp | 4 +- src/object/task/taskwait.h | 2 +- src/physics/physics.cpp | 51 ++++---- src/physics/physics.h | 9 +- src/script/script.cpp | 93 +++++++------- src/script/script.h | 5 +- src/sound/oalsound/alsound.cpp | 10 +- src/sound/oalsound/alsound.h | 1 - src/sound/oalsound/buffer.cpp | 1 - src/sound/oalsound/channel.cpp | 3 +- src/sound/sound.h | 8 +- src/ui/button.cpp | 1 - src/ui/button.h | 38 +++--- src/ui/check.cpp | 1 - src/ui/check.h | 25 ++-- src/ui/color.cpp | 2 - src/ui/color.h | 41 +++--- src/ui/compass.cpp | 3 +- src/ui/compass.h | 31 +++-- src/ui/control.cpp | 18 ++- src/ui/control.h | 209 +++++++++++++++---------------- src/ui/displayinfo.cpp | 43 ++++--- src/ui/displayinfo.h | 120 +++++++++--------- src/ui/displaytext.cpp | 33 ++--- src/ui/displaytext.h | 11 +- src/ui/edit.cpp | 4 +- src/ui/edit.h | 1 - src/ui/editvalue.cpp | 7 +- src/ui/editvalue.h | 1 - src/ui/gauge.cpp | 3 - src/ui/gauge.h | 1 - src/ui/group.cpp | 4 +- src/ui/group.h | 1 - src/ui/image.cpp | 10 +- src/ui/image.h | 1 - src/ui/interface.cpp | 44 +++---- src/ui/interface.h | 6 +- src/ui/key.cpp | 1 + src/ui/key.h | 1 - src/ui/label.cpp | 2 - src/ui/list.cpp | 2 - src/ui/maindialog.cpp | 31 +++-- src/ui/maindialog.h | 14 +-- src/ui/mainmap.cpp | 13 +- src/ui/mainmap.h | 5 +- src/ui/mainshort.cpp | 22 ++-- src/ui/mainshort.h | 7 +- src/ui/map.cpp | 8 +- src/ui/map.h | 7 +- src/ui/scroll.cpp | 4 +- src/ui/scroll.h | 3 +- src/ui/shortcut.cpp | 4 +- src/ui/slider.cpp | 4 +- src/ui/studio.cpp | 29 +++-- src/ui/studio.h | 122 +++++++++--------- src/ui/target.cpp | 7 +- src/ui/target.h | 11 +- src/ui/window.cpp | 15 --- src/ui/window.h | 6 +- test/cbot/CBot_console/CBotConsole.h | 5 +- test/cbot/CBot_console/CBotDoc.h | 4 - test/envs/opengl/CMakeLists.txt | 13 +- test/envs/opengl/light_test.cpp | 6 +- test/envs/opengl/model_test.cpp | 3 + test/envs/opengl/texture_test.cpp | 2 + test/envs/opengl/transform_test.cpp | 5 +- test/unit/math/geometry_test.cpp | 2 - test/unit/math/matrix_test.cpp | 2 - test/unit/math/vector_test.cpp | 2 - test/unit/ui/edit_test.cpp | 9 +- test/unit/ui/mocks/text_mock.h | 3 +- test/unit/ui/stubs/app_stub.cpp | 14 ++- test/unit/ui/stubs/engine_stub.cpp | 16 ++- test/unit/ui/stubs/particle_stub.cpp | 2 +- test/unit/ui/stubs/robotmain_stub.cpp | 2 +- 230 files changed, 1569 insertions(+), 1536 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ec457bd..2e25826 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -150,7 +150,7 @@ if(NOT ${ASSERTS}) endif() if(${TESTS}) - add_definitions(-DTEST_VIRTUAL=virtual) + add_definitions(-DTESTS -DTEST_VIRTUAL=virtual) else() add_definitions(-DTEST_VIRTUAL=) endif() diff --git a/src/CBot/CBotDll.h b/src/CBot/CBotDll.h index 7af63ca..b401528 100644 --- a/src/CBot/CBotDll.h +++ b/src/CBot/CBotDll.h @@ -15,14 +15,13 @@ // * along with this program. If not, see http://www.gnu.org/licenses/. //////////////////////////////////////////////////////////////////////// -#pragma once -#ifndef _CBOTDLL_H_ -#define _CBOTDLL_H_ /** * \file CBotDll.h * \brief Library for interpretation of CBOT language */ +#pragma once + #include #include "resource.h" #include @@ -1114,5 +1113,4 @@ bool rDoGoto( CBotVar* pVar, CBotVar* pResult, int& exception ) } #endif -#endif //_CBOTDLL_H_ diff --git a/src/CBot/CBotToken.cpp b/src/CBot/CBotToken.cpp index c6e65e7..f03ca91 100644 --- a/src/CBot/CBotToken.cpp +++ b/src/CBot/CBotToken.cpp @@ -15,8 +15,6 @@ // * along with this program. If not, see http://www.gnu.org/licenses/. -//CBotToken.cpp - ////////////////////////////////////////////////////////////////// // Managing Tokens // the text of a program is first transformed diff --git a/src/CBot/ClassFILE.cpp b/src/CBot/ClassFILE.cpp index e5bc260..b0f7977 100644 --- a/src/CBot/ClassFILE.cpp +++ b/src/CBot/ClassFILE.cpp @@ -14,8 +14,6 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// ClassFile.cpp -// // definition of methods for class FILE diff --git a/src/app/app.cpp b/src/app/app.cpp index 9886b24..ae5ac88 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -46,7 +46,7 @@ #endif -template<> CApplication* CSingleton::mInstance = nullptr; +template<> CApplication* CSingleton::m_instance = nullptr; //! Static buffer for putenv locale static char S_LANGUAGE[50] = { 0 }; @@ -94,7 +94,7 @@ CApplication::CApplication() { m_private = new ApplicationPrivate(); m_iMan = new CInstanceManager(); - m_eventQueue = new CEventQueue(m_iMan); + m_eventQueue = new CEventQueue(); m_profile = new CProfile(); m_engine = nullptr; @@ -187,6 +187,16 @@ CApplication::~CApplication() } } +CEventQueue* CApplication::GetEventQueue() +{ + return m_eventQueue; +} + +CSoundInterface* CApplication::GetSound() +{ + return m_sound; +} + ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) { bool waitDataDir = false; @@ -410,7 +420,7 @@ bool CApplication::Create() } // Create the 3D engine - m_engine = new Gfx::CEngine(m_iMan, this); + m_engine = new Gfx::CEngine(this); m_engine->SetDevice(m_device); @@ -425,7 +435,7 @@ bool CApplication::Create() m_modelManager = new Gfx::CModelManager(m_engine); // Create the robot application. - m_robotMain = new CRobotMain(m_iMan, this); + m_robotMain = new CRobotMain(this); m_robotMain->ChangePhase(PHASE_WELCOME1); diff --git a/src/app/app.h b/src/app/app.h index 4aa97ce..f3f5601 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -194,6 +194,11 @@ public: //! Destructor ~CApplication(); + //! Returns the application's event queue + CEventQueue* GetEventQueue(); + //! Returns the sound subsystem + CSoundInterface* GetSound(); + public: //! Parses commandline arguments ParseArgsStatus ParseArguments(int argc, char *argv[]); @@ -363,10 +368,11 @@ protected: void UpdatePerformanceCountersData(); protected: - //! Instance manager - CInstanceManager* m_iMan; //! Private (SDL-dependent data) ApplicationPrivate* m_private; + //! Instance manager + // TODO: to be removed + CInstanceManager* m_iMan; //! Global event queue CEventQueue* m_eventQueue; //! Graphics engine diff --git a/src/common/event.cpp b/src/common/event.cpp index b078dc5..ff3fbc7 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -17,12 +17,12 @@ #include "common/event.h" -#include "common/iman.h" #include "common/logger.h" static EventType g_uniqueEventType = EVENT_USER; + EventType GetUniqueEventType() { int i = static_cast(g_uniqueEventType+1); @@ -32,11 +32,8 @@ EventType GetUniqueEventType() -CEventQueue::CEventQueue(CInstanceManager* iMan) +CEventQueue::CEventQueue() { - m_iMan = iMan; - m_iMan->AddInstance(CLASS_EVENT, this); - Flush(); } diff --git a/src/common/event.h b/src/common/event.h index cba167e..ad493e7 100644 --- a/src/common/event.h +++ b/src/common/event.h @@ -27,8 +27,6 @@ #include "math/point.h" #include "math/vector.h" -class CInstanceManager; - /** \enum EventType @@ -762,7 +760,7 @@ public: public: //! Object's constructor - CEventQueue(CInstanceManager* iMan); + CEventQueue(); //! Object's destructor ~CEventQueue(); @@ -774,7 +772,6 @@ public: bool GetEvent(Event &event); protected: - CInstanceManager* m_iMan; Event m_fifo[MAX_EVENT_QUEUE]; int m_head; int m_tail; diff --git a/src/common/iman.cpp b/src/common/iman.cpp index 6a0a9eb..e1400fd 100644 --- a/src/common/iman.cpp +++ b/src/common/iman.cpp @@ -20,22 +20,9 @@ #include -template<> CInstanceManager* CSingleton::mInstance = nullptr; +template<> CInstanceManager* CSingleton::m_instance = nullptr; -CInstanceManager& CInstanceManager::GetInstance() -{ - assert(mInstance); - return *mInstance; -} - - -CInstanceManager* CInstanceManager::GetInstancePointer() -{ - assert(mInstance); - return mInstance; -} - CInstanceManager::CInstanceManager() { for (int i = 0; i < CLASS_MAX; i++) diff --git a/src/common/iman.h b/src/common/iman.h index 53caed7..faabd0c 100644 --- a/src/common/iman.h +++ b/src/common/iman.h @@ -30,67 +30,23 @@ * \brief Type of class managed by CInstanceManager */ -// TODO: remove unnecessary, refactor to singletons, move to CRobotMain, keep others? - +/* + * TODO: Non-unique classes have already been removed. + * The other class instances along with CInstanceManager will be removed in due course. + */ enum ManagedClassType { - //! CEventQueue - CLASS_EVENT = 1, - //! Ui::CInterface - CLASS_INTERFACE = 2, - //! CRobotMain - CLASS_MAIN = 3, - //! Gfx::CEngine - CLASS_ENGINE = 4, - //! Gfx::CTerrain - CLASS_TERRAIN = 5, //! CObject - CLASS_OBJECT = 6, + CLASS_OBJECT = 0, //! CPhysics - CLASS_PHYSICS = 7, + CLASS_PHYSICS = 1, //! CBrain - CLASS_BRAIN = 8, - //! Gfx::CCamera - CLASS_CAMERA = 9, - //! Gfx::CLightManager - CLASS_LIGHT = 10, - //! Gfx::CParticle - CLASS_PARTICULE = 11, - //! CAuto; TODO: remove (unused) - CLASS_AUTO = 12, - //! Ui::CDisplayText - CLASS_DISPLAYTEXT = 13, + CLASS_BRAIN = 2, //! Gfx::CPyro - CLASS_PYRO = 14, - //! Ui::CScript; TODO: remove (unused) - CLASS_SCRIPT = 15, - //! Gfx::CText - CLASS_TEXT = 16, - //! Ui::CStudio, Ui::CDisplayText; TODO: remove (unused) - CLASS_STUDIO = 17, - //! Gfx::CWater - CLASS_WATER = 18, - //! Gfx::CCloud; TODO: remove (unused) - CLASS_CLOUD = 19, - //! CMotion; TODO: remove (unused) - CLASS_MOTION = 20, - //! CSoundInterface - CLASS_SOUND = 21, - //! Gfx::CPlanet - CLASS_PLANET = 22, - //! CTaskManager; TODO: remove (unused) - CLASS_TASKMANAGER = 23, - //! Ui::CMainDialog; TODO: remove (unused) - CLASS_DIALOG = 24, - //! Ui::CMainMap; TODO: remove (unused) - CLASS_MAP = 25, - //! Ui::CMainShort, CMainMovie; TODO: remove (unused) - CLASS_SHORT = 26, - //! Gfx::CLightning; TODO: remove (unused) - CLASS_BLITZ = 27, + CLASS_PYRO = 3, //! Maximum (number of managed classes) - CLASS_MAX = 30 + CLASS_MAX = 4 }; @@ -116,7 +72,7 @@ class CInstanceManager : public CSingleton { public: CInstanceManager(); - ~CInstanceManager(); + virtual ~CInstanceManager(); //! Remove all managed instances void Flush(); @@ -129,9 +85,6 @@ public: //! Seeks a class instance of given type void* SearchInstance(ManagedClassType classType, int rank=0); - static CInstanceManager& GetInstance(); - static CInstanceManager* GetInstancePointer(); - protected: //! Fills holes in instance table void Compress(ManagedClassType classType); diff --git a/src/common/logger.cpp b/src/common/logger.cpp index 5a78433..3ec9746 100644 --- a/src/common/logger.cpp +++ b/src/common/logger.cpp @@ -20,7 +20,7 @@ #include -template<> CLogger* CSingleton::mInstance = nullptr; +template<> CLogger* CSingleton::m_instance = nullptr; CLogger::CLogger() diff --git a/src/common/profile.cpp b/src/common/profile.cpp index 5432489..18cc187 100644 --- a/src/common/profile.cpp +++ b/src/common/profile.cpp @@ -25,7 +25,7 @@ #include -template<> CProfile* CSingleton::mInstance = nullptr; +template<> CProfile* CSingleton::m_instance = nullptr; namespace bp = boost::property_tree; diff --git a/src/common/singleton.h b/src/common/singleton.h index c1b28d9..25e1648 100644 --- a/src/common/singleton.h +++ b/src/common/singleton.h @@ -26,34 +26,51 @@ template class CSingleton { - protected: - static T* mInstance; - - public: - static T& GetInstance() { - assert(mInstance != nullptr); - return *mInstance; - } - - static T* GetInstancePointer() { - assert(mInstance != nullptr); - return mInstance; - } - - static bool IsCreated() { - return mInstance != nullptr; - } - - CSingleton() { - assert(mInstance == nullptr); - mInstance = static_cast(this); - } - - virtual ~CSingleton() { - mInstance = nullptr; - } - - private: - CSingleton& operator=(const CSingleton &); - CSingleton(const CSingleton &); +protected: + static T* m_instance; + +public: + static T& GetInstance() + { + assert(m_instance != nullptr); + return *m_instance; + } + + static T* GetInstancePointer() + { + assert(m_instance != nullptr); + return m_instance; + } + + static bool IsCreated() + { + return m_instance != nullptr; + } + + CSingleton() + { + assert(m_instance == nullptr); + m_instance = static_cast(this); + } + + virtual ~CSingleton() + { + m_instance = nullptr; + } + + #ifdef TESTS + static void ReplaceInstance(T* newInstance) + { + assert(newInstance != nullptr); + + if (m_instance != nullptr) + delete m_instance; + + m_instance = newInstance; + } + #endif + +private: + CSingleton& operator=(const CSingleton &); + CSingleton(const CSingleton &); }; diff --git a/src/graphics/engine/camera.cpp b/src/graphics/engine/camera.cpp index 8026302..f65a59a 100644 --- a/src/graphics/engine/camera.cpp +++ b/src/graphics/engine/camera.cpp @@ -30,6 +30,7 @@ #include "math/geometry.h" #include "object/object.h" +#include "object/robotmain.h" #include "physics/physics.h" @@ -54,14 +55,13 @@ void SetTransparency(CObject* obj, float value) -CCamera::CCamera(CInstanceManager* iMan) +CCamera::CCamera() { - m_iMan = iMan; - m_iMan->AddInstance(CLASS_CAMERA, this); + m_engine = CEngine::GetInstancePointer(); + m_water = m_engine->GetWater(); - m_engine = static_cast ( m_iMan->SearchInstance(CLASS_ENGINE) ); - m_terrain = static_cast( m_iMan->SearchInstance(CLASS_TERRAIN) ); - m_water = static_cast ( m_iMan->SearchInstance(CLASS_WATER) ); + m_main = CRobotMain::GetInstancePointer(); + m_terrain = m_main->GetTerrain(); m_type = CAM_TYPE_FREE; m_smooth = CAM_SMOOTH_NORM; @@ -227,11 +227,13 @@ void CCamera::SetType(CameraType type) m_remotePan = 0.0f; m_remoteZoom = 0.0f; + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + if ( (m_type == CAM_TYPE_BACK) && m_transparency ) { for (int i = 0; i < 1000000; i++) { - CObject* obj = static_cast( m_iMan->SearchInstance(CLASS_OBJECT, i) ); + CObject* obj = static_cast( iMan->SearchInstance(CLASS_OBJECT, i) ); if (obj == NULL) break; @@ -881,9 +883,11 @@ bool CCamera::IsCollisionBack(Math::Vector &eye, Math::Vector lookat) m_transparency = false; + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + for (int i = 0 ;i < 1000000; i++) { - CObject *obj = static_cast( m_iMan->SearchInstance(CLASS_OBJECT, i) ); + CObject *obj = static_cast( iMan->SearchInstance(CLASS_OBJECT, i) ); if (obj == NULL) break; if (obj->GetTruck()) continue; // battery or cargo? @@ -958,9 +962,11 @@ bool CCamera::IsCollisionBack(Math::Vector &eye, Math::Vector lookat) bool CCamera::IsCollisionFix(Math::Vector &eye, Math::Vector lookat) { + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + for (int i = 0; i < 1000000; i++) { - CObject *obj = static_cast( m_iMan->SearchInstance(CLASS_OBJECT, i) ); + CObject *obj = static_cast( iMan->SearchInstance(CLASS_OBJECT, i) ); if (obj == NULL) break; if (obj == m_cameraObj) continue; @@ -1650,7 +1656,7 @@ Math::Vector CCamera::ExcludeObject(Math::Vector eye, Math::Vector lookat, /* for (int i = 0; i < 1000000; i++) { - CObject* obj = static_cast( m_iMan->SearchInstance(CLASS_OBJECT, i) ); + CObject* obj = static_cast( iMan->SearchInstance(CLASS_OBJECT, i) ); if (obj == NULL) break; diff --git a/src/graphics/engine/camera.h b/src/graphics/engine/camera.h index 20d252d..0ffc2c2 100644 --- a/src/graphics/engine/camera.h +++ b/src/graphics/engine/camera.h @@ -28,8 +28,8 @@ #include "graphics/engine/engine.h" -class CInstanceManager; class CObject; +class CRobotMain; // Graphics module namespace @@ -130,7 +130,7 @@ enum CameraOverEffect class CCamera { public: - CCamera(CInstanceManager* iMan); + CCamera(); ~CCamera(); //! Management of an event @@ -258,8 +258,8 @@ protected: void OverFrame(const Event &event); protected: - CInstanceManager* m_iMan; CEngine* m_engine; + CRobotMain* m_main; CTerrain* m_terrain; CWater* m_water; diff --git a/src/graphics/engine/cloud.cpp b/src/graphics/engine/cloud.cpp index 0df0d12..d9ebf5a 100644 --- a/src/graphics/engine/cloud.cpp +++ b/src/graphics/engine/cloud.cpp @@ -18,12 +18,12 @@ #include "graphics/engine/cloud.h" -#include "common/iman.h" - #include "graphics/core/device.h" #include "graphics/engine/engine.h" #include "graphics/engine/terrain.h" +#include "object/robotmain.h" + #include "math/geometry.h" @@ -37,11 +37,8 @@ const int CLOUD_LINE_PREALLOCATE_COUNT = 100; const int CLOUD_SIZE_EXPAND = 4; -CCloud::CCloud(CInstanceManager* iMan, CEngine* engine) +CCloud::CCloud(CEngine* engine) { - m_iMan = iMan; - m_iMan->AddInstance(CLASS_CLOUD, this); - m_engine = engine; m_terrain = nullptr; @@ -55,7 +52,6 @@ CCloud::CCloud(CInstanceManager* iMan, CEngine* engine) CCloud::~CCloud() { - m_iMan = nullptr; m_engine = nullptr; m_terrain = nullptr; } @@ -84,7 +80,7 @@ bool CCloud::EventFrame(const Event &event) } void CCloud::AdjustLevel(Math::Vector& pos, Math::Vector& eye, float deep, - Math::Point& uv1, Math::Point& uv2) + Math::Point& uv1, Math::Point& uv2) { uv1.x = (pos.x+20000.0f)/1280.0f; uv1.y = (pos.z+20000.0f)/1280.0f; @@ -211,8 +207,8 @@ void CCloud::CreateLine(int x, int y, int len) } void CCloud::Create(const std::string& fileName, - const Color& diffuse, const Color& ambient, - float level) + const Color& diffuse, const Color& ambient, + float level) { m_diffuse = diffuse; m_ambient = ambient; @@ -225,7 +221,7 @@ void CCloud::Create(const std::string& fileName, m_engine->LoadTexture(m_fileName); if (m_terrain == nullptr) - m_terrain = static_cast(m_iMan->SearchInstance(CLASS_TERRAIN)); + m_terrain = CRobotMain::GetInstancePointer()->GetTerrain(); m_wind = m_terrain->GetWind(); @@ -250,7 +246,6 @@ void CCloud::Flush() m_level = 0.0f; } - void CCloud::SetLevel(float level) { m_level = level; diff --git a/src/graphics/engine/cloud.h b/src/graphics/engine/cloud.h index 6f6985f..8f644f0 100644 --- a/src/graphics/engine/cloud.h +++ b/src/graphics/engine/cloud.h @@ -34,9 +34,6 @@ #include -class CInstanceManager; - - // Graphics module namespace namespace Gfx { @@ -79,12 +76,13 @@ struct CloudLine class CCloud { public: - CCloud(CInstanceManager* iMan, CEngine* engine); + CCloud(CEngine* engine); ~CCloud(); bool EventProcess(const Event& event); //! Removes all the clouds void Flush(); + //! Creates all areas of cloud void Create(const std::string& fileName, const Color& diffuse, const Color& ambient, float level); //! Draw the clouds @@ -112,9 +110,8 @@ protected: void CreateLine(int x, int y, int len); protected: - CInstanceManager* m_iMan; - CEngine* m_engine; - CTerrain* m_terrain; + CEngine* m_engine; + CTerrain* m_terrain; bool m_enabled; //! Overall level diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 71b5e7d..d24a3bd 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -20,7 +20,6 @@ #include "app/app.h" -#include "common/iman.h" #include "common/image.h" #include "common/key.h" #include "common/logger.h" @@ -43,20 +42,16 @@ #include "ui/interface.h" +template<> Gfx::CEngine* CSingleton::m_instance = nullptr; // Graphics module namespace namespace Gfx { -CEngine::CEngine(CInstanceManager *iMan, CApplication *app) +CEngine::CEngine(CApplication *app) { - m_iMan = iMan; m_app = app; m_device = nullptr; - m_iMan = iMan; - m_iMan->AddInstance(CLASS_ENGINE, this); - m_app = app; - m_lightMan = nullptr; m_text = nullptr; m_particle = nullptr; @@ -169,11 +164,17 @@ CEngine::CEngine(CInstanceManager *iMan, CApplication *app) CEngine::~CEngine() { - m_iMan = nullptr; - m_app = nullptr; - m_device = nullptr; - m_sound = nullptr; - m_terrain = nullptr; + m_app = nullptr; + m_sound = nullptr; + m_device = nullptr; + m_text = nullptr; + m_lightMan = nullptr; + m_particle = nullptr; + m_water = nullptr; + m_cloud = nullptr; + m_lightning = nullptr; + m_planet = nullptr; + m_terrain = nullptr; DestroyTimeStamp(m_lastFrameTime); m_lastFrameTime = nullptr; @@ -191,27 +192,63 @@ CDevice* CEngine::GetDevice() return m_device; } -void CEngine::SetTerrain(CTerrain* terrain) +CText* CEngine::GetText() { - m_terrain = terrain; + return m_text; } -CText* CEngine::GetText() +CLightManager* CEngine::GetLightManager() { - return m_text; + return m_lightMan; +} + +CParticle* CEngine::GetParticle() +{ + return m_particle; +} + +CTerrain* CEngine::GetTerrain() +{ + return m_terrain; +} + +CWater* CEngine::GetWater() +{ + return m_water; } +CLightning* CEngine::GetLightning() +{ + return m_lightning; +} + +CPlanet* CEngine::GetPlanet() +{ + return m_planet; +} + +CCloud* CEngine::GetCloud() +{ + return m_cloud; +} + +void CEngine::SetTerrain(CTerrain* terrain) +{ + m_terrain = terrain; +} + + bool CEngine::Create() { m_size = m_app->GetVideoConfig().size; - m_lightMan = new CLightManager(m_iMan, this); - m_text = new CText(m_iMan, this); - m_particle = new CParticle(m_iMan, this); - m_water = new CWater(m_iMan, this); - m_cloud = new CCloud(m_iMan, this); - m_lightning = new CLightning(m_iMan, this); - m_planet = new CPlanet(m_iMan, this); + m_lightMan = new CLightManager(this); + m_text = new CText(this); + m_particle = new CParticle(this); + m_water = new CWater(this); + m_cloud = new CCloud(this); + m_lightning = new CLightning(this); + m_planet = new CPlanet(this); m_lightMan->SetDevice(m_device); m_particle->SetDevice(m_device); @@ -2046,7 +2083,7 @@ void CEngine::SetViewParams(const Math::Vector& eyePt, const Math::Vector& looka Math::LoadViewMatrix(m_matView, eyePt, lookatPt, upVec); if (m_sound == nullptr) - m_sound = static_cast( m_iMan->SearchInstance(CLASS_SOUND) ); + m_sound = m_app->GetSound(); if (m_sound != nullptr) m_sound->SetListener(eyePt, lookatPt); @@ -3184,9 +3221,11 @@ void CEngine::DrawInterface() SetState(Gfx::ENG_RSTATE_NORMAL); // Draw the entire interface - Ui::CInterface* interface = static_cast( m_iMan->SearchInstance(CLASS_INTERFACE) ); + Ui::CInterface* interface = CRobotMain::GetInstancePointer()->GetInterface(); if (interface != nullptr) + { interface->Draw(); + } m_interfaceMode = false; m_lastState = -1; diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index e5c75bc..0647fbd 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -26,6 +26,7 @@ #include "app/system.h" #include "common/event.h" +#include "common/singleton.h" #include "graphics/core/color.h" #include "graphics/core/material.h" @@ -47,7 +48,6 @@ class CApplication; -class CInstanceManager; class CObject; class CSoundInterface; class CImage; @@ -671,22 +671,36 @@ struct EngineMouse * which is what OpenGL actually wants. The old method is kept for now, with mapping between texture names * and texture structs but it will also be subject to refactoring in the future. */ -class CEngine +class CEngine : public CSingleton { public: - CEngine(CInstanceManager* iMan, CApplication* app); + CEngine(CApplication* app); ~CEngine(); //! Sets the device to be used void SetDevice(CDevice* device); //! Returns the current device - CDevice* GetDevice(); - - //! Sets the terrain object - void SetTerrain(CTerrain* terrain); + CDevice* GetDevice(); //! Returns the text rendering engine CText* GetText(); + //! Returns the light manager + CLightManager* GetLightManager(); + //! Returns the particle manager + CParticle* GetParticle(); + //! Returns the terrain manager + CTerrain* GetTerrain(); + //! Returns the water manager + CWater* GetWater(); + //! Returns the lighting manager + CLightning* GetLightning(); + //! Returns the planet manager + CPlanet* GetPlanet(); + //! Returns the fog manager + CCloud* GetCloud(); + + //! Sets the terrain object + void SetTerrain(CTerrain* terrain); //! Performs the initialization; must be called after device was set @@ -735,8 +749,6 @@ public: //! Returns current size of viewport window Math::IntPoint GetWindowSize(); - //! Returns the last size of viewport window - Math::IntPoint GetLastWindowSize(); //@{ //! Conversion functions between window and interface coordinates @@ -1251,7 +1263,6 @@ protected: void UpdateStaticBuffers(); protected: - CInstanceManager* m_iMan; CApplication* m_app; CSoundInterface* m_sound; CDevice* m_device; diff --git a/src/graphics/engine/lightman.cpp b/src/graphics/engine/lightman.cpp index 3055f08..4a8fd60 100644 --- a/src/graphics/engine/lightman.cpp +++ b/src/graphics/engine/lightman.cpp @@ -19,7 +19,6 @@ #include "graphics/engine/lightman.h" #include "common/logger.h" -#include "common/iman.h" #include "graphics/core/device.h" @@ -78,11 +77,8 @@ DynamicLight::DynamicLight() -CLightManager::CLightManager(CInstanceManager* iMan, CEngine* engine) +CLightManager::CLightManager(CEngine* engine) { - m_iMan = iMan; - m_iMan->AddInstance(CLASS_LIGHT, this); - m_device = nullptr; m_engine = engine; @@ -91,9 +87,6 @@ CLightManager::CLightManager(CInstanceManager* iMan, CEngine* engine) CLightManager::~CLightManager() { - m_iMan->DeleteInstance(CLASS_LIGHT, this); - - m_iMan = nullptr; m_device = nullptr; m_engine = nullptr; } diff --git a/src/graphics/engine/lightman.h b/src/graphics/engine/lightman.h index d83dfb3..07dfe6a 100644 --- a/src/graphics/engine/lightman.h +++ b/src/graphics/engine/lightman.h @@ -129,7 +129,7 @@ class CLightManager { public: //! Constructor - CLightManager(CInstanceManager *iMan, CEngine* engine); + CLightManager(CEngine* engine); //! Destructor virtual ~CLightManager(); @@ -189,7 +189,6 @@ public: void UpdateDeviceLights(EngineObjectType type); protected: - CInstanceManager* m_iMan; CEngine* m_engine; CDevice* m_device; diff --git a/src/graphics/engine/lightning.cpp b/src/graphics/engine/lightning.cpp index d256599..5fdae51 100644 --- a/src/graphics/engine/lightning.cpp +++ b/src/graphics/engine/lightning.cpp @@ -18,6 +18,8 @@ #include "graphics/engine/lightning.h" +#include "app/app.h" + #include "common/logger.h" #include "common/iman.h" @@ -25,22 +27,20 @@ #include "graphics/engine/camera.h" #include "graphics/engine/terrain.h" +#include "math/geometry.h" + #include "object/object.h" +#include "object/robotmain.h" #include "object/auto/autopara.h" -#include "math/geometry.h" - // Graphics module namespace namespace Gfx { -CLightning::CLightning(CInstanceManager* iMan, CEngine* engine) +CLightning::CLightning(CEngine* engine) { - m_iMan = iMan; - m_iMan->AddInstance(CLASS_BLITZ, this); - m_engine = engine; m_terrain = nullptr; m_camera = nullptr; @@ -187,13 +187,13 @@ bool CLightning::Create(float sleep, float delay, float magnetic) m_speed = 1.0f / m_sleep; if (m_terrain == nullptr) - m_terrain = static_cast(m_iMan->SearchInstance(CLASS_TERRAIN)); + m_terrain = CRobotMain::GetInstancePointer()->GetTerrain(); if (m_camera == nullptr) - m_camera = static_cast(m_iMan->SearchInstance(CLASS_CAMERA)); + m_camera = CRobotMain::GetInstancePointer()->GetCamera(); if (m_sound == nullptr) - m_sound = static_cast(m_iMan->SearchInstance(CLASS_SOUND)); + m_sound = CApplication::GetInstancePointer()->GetSound(); return false; } @@ -312,12 +312,14 @@ CObject* CLightning::SearchObject(Math::Vector pos) std::vector paraObjPos; paraObjPos.reserve(100); + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + // Seeking the object closest to the point of impact of lightning. CObject* bestObj = 0; float min = 100000.0f; for (int i = 0; i < 1000000; i++) { - CObject* obj = static_cast( m_iMan->SearchInstance(CLASS_OBJECT, i) ); + CObject* obj = static_cast( iMan->SearchInstance(CLASS_OBJECT, i) ); if (obj == nullptr) break; if (!obj->GetActif()) continue; // inactive object? diff --git a/src/graphics/engine/lightning.h b/src/graphics/engine/lightning.h index b21f681..7809a6c 100644 --- a/src/graphics/engine/lightning.h +++ b/src/graphics/engine/lightning.h @@ -28,7 +28,6 @@ #include "math/vector.h" -class CInstanceManager; class CObject; class CSoundInterface; @@ -53,7 +52,7 @@ const float LTNG_PROTECTION_RADIUS = 200.0f; class CLightning { public: - CLightning(CInstanceManager* iMan, CEngine* engine); + CLightning(CEngine* engine); ~CLightning(); //! Triggers lightning @@ -80,7 +79,6 @@ protected: CObject* SearchObject(Math::Vector pos); protected: - CInstanceManager* m_iMan; CEngine* m_engine; CTerrain* m_terrain; CCamera* m_camera; diff --git a/src/graphics/engine/modelfile.cpp b/src/graphics/engine/modelfile.cpp index c9d41f3..f6d7a7b 100644 --- a/src/graphics/engine/modelfile.cpp +++ b/src/graphics/engine/modelfile.cpp @@ -18,7 +18,6 @@ #include "graphics/engine/modelfile.h" -#include "common/iman.h" #include "common/ioutils.h" #include "common/logger.h" #include "common/stringutils.h" diff --git a/src/graphics/engine/modelmanager.cpp b/src/graphics/engine/modelmanager.cpp index 051922f..c23b79d 100644 --- a/src/graphics/engine/modelmanager.cpp +++ b/src/graphics/engine/modelmanager.cpp @@ -8,7 +8,7 @@ #include -template<> Gfx::CModelManager* CSingleton::mInstance = nullptr; +template<> Gfx::CModelManager* CSingleton::m_instance = nullptr; namespace Gfx { diff --git a/src/graphics/engine/particle.cpp b/src/graphics/engine/particle.cpp index 388c189..d15ee3b 100644 --- a/src/graphics/engine/particle.cpp +++ b/src/graphics/engine/particle.cpp @@ -18,6 +18,9 @@ #include "graphics/engine/particle.h" +#include "app/app.h" + +#include "common/iman.h" #include "common/logger.h" #include "graphics/core/device.h" @@ -117,11 +120,8 @@ float GetDecay(ObjectType type) -CParticle::CParticle(CInstanceManager *iMan, CEngine* engine) +CParticle::CParticle(CEngine* engine) { - m_iMan = iMan; - m_iMan->AddInstance(CLASS_PARTICULE, this); - m_device = nullptr; m_engine = engine; m_main = nullptr; @@ -138,7 +138,6 @@ CParticle::CParticle(CInstanceManager *iMan, CEngine* engine) CParticle::~CParticle() { - m_iMan->DeleteInstance(CLASS_PARTICULE, this); } void CParticle::SetDevice(CDevice* device) @@ -213,7 +212,7 @@ int CParticle::CreateParticle(Math::Vector pos, Math::Vector speed, Math::Point float windSensitivity, int sheet) { if (m_main == nullptr) - m_main = static_cast(m_iMan->SearchInstance(CLASS_MAIN)); + m_main = CRobotMain::GetInstancePointer(); int t = -1; if ( type == PARTIEXPLOT || @@ -649,7 +648,7 @@ void CParticle::CreateWheelTrace(const Math::Vector &p1, const Math::Vector &p2, m_wheelTrace[i].startTime = m_absTime; if (m_terrain == nullptr) - m_terrain = static_cast(m_iMan->SearchInstance(CLASS_TERRAIN)); + m_terrain = m_main->GetTerrain(); m_terrain->AdjustToFloor(m_wheelTrace[i].pos[0]); m_wheelTrace[i].pos[0].y += 0.2f; // just above the ground @@ -808,15 +807,15 @@ void CParticle::SetFrameUpdate(int sheet, bool update) void CParticle::FrameParticle(float rTime) { if (m_main == nullptr) - m_main = static_cast(m_iMan->SearchInstance(CLASS_MAIN)); + m_main = CRobotMain::GetInstancePointer(); bool pause = (m_engine->GetPause() && !m_main->GetInfoLock()); if (m_terrain == nullptr) - m_terrain = static_cast(m_iMan->SearchInstance(CLASS_TERRAIN)); + m_terrain = m_main->GetTerrain(); if (m_water == nullptr) - m_water = static_cast(m_iMan->SearchInstance(CLASS_WATER)); + m_water = m_engine->GetWater(); if (!pause) { @@ -3654,11 +3653,13 @@ CObject* CParticle::SearchObjectGun(Math::Vector old, Math::Vector pos, box2.y += min; box2.z += min; + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + CObject* best = 0; bool shield = false; for (int i = 0; i < 1000000; i++) { - CObject* obj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + CObject* obj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if (obj == 0) break; if (!obj->GetActif()) continue; // inactive? @@ -3782,9 +3783,11 @@ CObject* CParticle::SearchObjectRay(Math::Vector pos, Math::Vector goal, box2.y += min; box2.z += min; + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + for (int i = 0; i < 1000000; i++) { - CObject* obj = static_cast( m_iMan->SearchInstance(CLASS_OBJECT, i) ); + CObject* obj = static_cast( iMan->SearchInstance(CLASS_OBJECT, i) ); if (obj == nullptr) break; if (!obj->GetActif()) continue; // inactive? @@ -3822,7 +3825,7 @@ CObject* CParticle::SearchObjectRay(Math::Vector pos, Math::Vector goal, void CParticle::Play(Sound sound, Math::Vector pos, float amplitude) { if (m_sound == nullptr) - m_sound = static_cast(m_iMan->SearchInstance(CLASS_SOUND)); + m_sound = CApplication::GetInstancePointer()->GetSound(); m_sound->Play(sound, pos, amplitude); } diff --git a/src/graphics/engine/particle.h b/src/graphics/engine/particle.h index 90aec55..708a04d 100644 --- a/src/graphics/engine/particle.h +++ b/src/graphics/engine/particle.h @@ -28,7 +28,6 @@ #include "sound/sound.h" -class CInstanceManager; class CRobotMain; class CObject; class CSoundInterface; @@ -267,7 +266,7 @@ struct WheelTrace class CParticle { public: - CParticle(CInstanceManager* iMan, CEngine* engine); + CParticle(CEngine* engine); ~CParticle(); //! Sets the device to use @@ -371,7 +370,6 @@ protected: void TrackDraw(int i, ParticleType type); protected: - CInstanceManager* m_iMan; CEngine* m_engine; CDevice* m_device; CTerrain* m_terrain; diff --git a/src/graphics/engine/planet.cpp b/src/graphics/engine/planet.cpp index 3b9aa6c..49bcb4c 100644 --- a/src/graphics/engine/planet.cpp +++ b/src/graphics/engine/planet.cpp @@ -18,8 +18,6 @@ #include "graphics/engine/planet.h" -#include "common/iman.h" - #include "graphics/core/device.h" #include "graphics/engine/engine.h" @@ -31,11 +29,8 @@ namespace Gfx { const int PLANET_PREALLOCATE_COUNT = 10; -CPlanet::CPlanet(CInstanceManager* iMan, CEngine* engine) +CPlanet::CPlanet(CEngine* engine) { - m_iMan = iMan; - m_iMan->AddInstance(CLASS_PLANET, this); - m_planet[0].reserve(PLANET_PREALLOCATE_COUNT); m_planet[1].reserve(PLANET_PREALLOCATE_COUNT); @@ -46,7 +41,6 @@ CPlanet::CPlanet(CInstanceManager* iMan, CEngine* engine) CPlanet::~CPlanet() { - m_iMan = nullptr; } void CPlanet::Flush() diff --git a/src/graphics/engine/planet.h b/src/graphics/engine/planet.h index 1b16da0..3762e1d 100644 --- a/src/graphics/engine/planet.h +++ b/src/graphics/engine/planet.h @@ -30,8 +30,6 @@ #include -class CInstanceManager; - // Graphics module namespace namespace Gfx { @@ -82,7 +80,7 @@ struct Planet class CPlanet { public: - CPlanet(CInstanceManager* iMan, CEngine* engine); + CPlanet(CEngine* engine); ~CPlanet(); //! Removes all the planets @@ -110,7 +108,6 @@ protected: bool EventFrame(const Event &event); protected: - CInstanceManager* m_iMan; CEngine* m_engine; float m_time; diff --git a/src/graphics/engine/pyro.cpp b/src/graphics/engine/pyro.cpp index e374d6c..1d80fea 100644 --- a/src/graphics/engine/pyro.cpp +++ b/src/graphics/engine/pyro.cpp @@ -18,6 +18,9 @@ #include "graphics/engine/pyro.h" +#include "app/app.h" + +#include "common/iman.h" #include "common/logger.h" #include "graphics/engine/lightman.h" @@ -36,20 +39,19 @@ namespace Gfx { -CPyro::CPyro(CInstanceManager* iMan) +CPyro::CPyro() { - m_iMan = iMan; - m_iMan->AddInstance(CLASS_PYRO, this, 100); - - m_engine = static_cast(m_iMan->SearchInstance(CLASS_ENGINE)); - m_terrain = static_cast(m_iMan->SearchInstance(CLASS_TERRAIN)); - m_camera = static_cast(m_iMan->SearchInstance(CLASS_CAMERA)); - m_particle = static_cast(m_iMan->SearchInstance(CLASS_PARTICULE)); - m_lightMan = static_cast(m_iMan->SearchInstance(CLASS_LIGHT)); - m_displayText = static_cast(m_iMan->SearchInstance(CLASS_DISPLAYTEXT)); - m_main = static_cast(m_iMan->SearchInstance(CLASS_MAIN)); - m_sound = static_cast(m_iMan->SearchInstance(CLASS_SOUND)); - m_object = 0; + CInstanceManager::GetInstancePointer()->AddInstance(CLASS_PYRO, this, 100); + + m_engine = CEngine::GetInstancePointer(); + m_main = CRobotMain::GetInstancePointer(); + m_terrain = m_main->GetTerrain(); + m_camera = m_main->GetCamera(); + m_particle = m_engine->GetParticle(); + m_lightMan = m_engine->GetLightManager(); + m_displayText = m_main->GetDisplayText(); + m_sound = CApplication::GetInstancePointer()->GetSound(); + m_object = nullptr; m_progress = 0.0f; m_speed = 0.0f; @@ -60,7 +62,7 @@ CPyro::CPyro(CInstanceManager* iMan) CPyro::~CPyro() { - m_iMan->DeleteInstance(CLASS_PYRO, this); + CInstanceManager::GetInstancePointer()->DeleteInstance(CLASS_PYRO, this); } void CPyro::DeleteObject() @@ -2183,9 +2185,11 @@ CObject* CPyro::FallSearchBeeExplo() float iRadius; m_object->GetCrashSphere(0, iPos, iRadius); + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + for (int i = 0; i < 1000000; i++) { - CObject* pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + CObject* pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; ObjectType oType = pObj->GetType(); diff --git a/src/graphics/engine/pyro.h b/src/graphics/engine/pyro.h index 0204070..9548a07 100644 --- a/src/graphics/engine/pyro.h +++ b/src/graphics/engine/pyro.h @@ -31,7 +31,6 @@ #include "object/object.h" -class CInstanceManager; class CObject; class CRobotMain; class CSoundInterface; @@ -111,7 +110,7 @@ struct PyroLightOper class CPyro { public: - CPyro(CInstanceManager* iMan); + CPyro(); ~CPyro(); //! Creates pyrotechnic effect @@ -174,7 +173,6 @@ protected: void LightOperFrame(float rTime); protected: - CInstanceManager* m_iMan; CEngine* m_engine; CTerrain* m_terrain; CCamera* m_camera; diff --git a/src/graphics/engine/terrain.cpp b/src/graphics/engine/terrain.cpp index 0be75bc..8f7ad26 100644 --- a/src/graphics/engine/terrain.cpp +++ b/src/graphics/engine/terrain.cpp @@ -19,11 +19,13 @@ #include "graphics/engine/terrain.h" #include "app/app.h" -#include "common/iman.h" + #include "common/image.h" #include "common/logger.h" + #include "graphics/engine/engine.h" #include "graphics/engine/water.h" + #include "math/geometry.h" #include @@ -35,13 +37,10 @@ namespace Gfx { -CTerrain::CTerrain(CInstanceManager* iMan) +CTerrain::CTerrain() { - m_iMan = iMan; - m_iMan->AddInstance(CLASS_TERRAIN, this); - - m_engine = static_cast( m_iMan->SearchInstance(CLASS_ENGINE) ); - m_water = static_cast( m_iMan->SearchInstance(CLASS_WATER) ); + m_engine = CEngine::GetInstancePointer(); + m_water = m_engine->GetWater(); m_mosaicCount = 20; m_brickCount = 1 << 4; diff --git a/src/graphics/engine/terrain.h b/src/graphics/engine/terrain.h index 91ddc76..1fa8dec 100644 --- a/src/graphics/engine/terrain.h +++ b/src/graphics/engine/terrain.h @@ -26,9 +26,6 @@ #include "graphics/engine/engine.h" -class CInstanceManager; - - // Graphics module namespace namespace Gfx { @@ -223,7 +220,7 @@ struct FlyingLimit class CTerrain { public: - CTerrain(CInstanceManager* iMan); + CTerrain(); ~CTerrain(); //! Generates a new flat terrain @@ -359,7 +356,6 @@ protected: void AdjustBuildingLevel(Math::Vector &p); protected: - CInstanceManager* m_iMan; CEngine* m_engine; CWater* m_water; diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index 48af081..424b99b 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -19,10 +19,11 @@ #include "graphics/engine/text.h" #include "app/app.h" + #include "common/image.h" -#include "common/iman.h" #include "common/logger.h" #include "common/stringutils.h" + #include "math/func.h" #include @@ -49,11 +50,8 @@ struct CachedFont const Math::IntPoint REFERENCE_SIZE(800, 600); -CText::CText(CInstanceManager *iMan, CEngine* engine) +CText::CText(CEngine* engine) { - m_iMan = iMan; - m_iMan->AddInstance(CLASS_TEXT, this); - m_device = nullptr; m_engine = engine; @@ -66,9 +64,6 @@ CText::CText(CInstanceManager *iMan, CEngine* engine) CText::~CText() { - m_iMan->DeleteInstance(CLASS_TEXT, this); - - m_iMan = nullptr; m_device = nullptr; m_engine = nullptr; } diff --git a/src/graphics/engine/text.h b/src/graphics/engine/text.h index e7578df..d8e2aff 100644 --- a/src/graphics/engine/text.h +++ b/src/graphics/engine/text.h @@ -31,9 +31,6 @@ #include -class CInstanceManager; - - // Graphics module namespace namespace Gfx { @@ -226,7 +223,7 @@ struct MultisizeFont class CText { public: - CText(CInstanceManager *iMan, CEngine* engine); + CText(CEngine* engine); virtual ~CText(); //! Sets the device to be used @@ -301,7 +298,6 @@ protected: void StringToUTFCharList(const std::string &text, std::vector &chars); protected: - CInstanceManager* m_iMan; CEngine* m_engine; CDevice* m_device; diff --git a/src/graphics/engine/water.cpp b/src/graphics/engine/water.cpp index 6c822b3..d90652b 100644 --- a/src/graphics/engine/water.cpp +++ b/src/graphics/engine/water.cpp @@ -18,7 +18,8 @@ #include "graphics/engine/water.h" -#include "common/iman.h" +#include "app/app.h" + #include "common/logger.h" #include "graphics/core/device.h" @@ -28,6 +29,7 @@ #include "math/geometry.h" #include "object/object.h" +#include "object/robotmain.h" #include "sound/sound.h" @@ -42,14 +44,11 @@ const int WATERLINE_PREALLOCATE_COUNT = 500; const int VAPOR_SIZE = 10; -CWater::CWater(CInstanceManager* iMan, CEngine* engine) +CWater::CWater(CEngine* engine) { - m_iMan = iMan; - m_iMan->AddInstance(CLASS_WATER, this); - m_engine = engine; m_terrain = nullptr; - m_particule = nullptr; + m_particle = nullptr; m_sound = nullptr; m_type[0] = WATER_NULL; @@ -67,10 +66,9 @@ CWater::CWater(CInstanceManager* iMan, CEngine* engine) CWater::~CWater() { - m_iMan = nullptr; m_engine = nullptr; m_terrain = nullptr; - m_particule = nullptr; + m_particle = nullptr; m_sound = nullptr; } @@ -99,8 +97,8 @@ bool CWater::EventFrame(const Event &event) void CWater::LavaFrame(float rTime) { - if (m_particule == nullptr) - m_particule = static_cast( m_iMan->SearchInstance(CLASS_PARTICULE) ); + if (m_particle == nullptr) + m_particle = m_engine->GetParticle(); for (int i = 0; i < static_cast( m_vapors.size() ); i++) VaporFrame(i, rTime); @@ -183,7 +181,7 @@ void CWater::VaporFrame(int i, float rTime) m_vapors[i].time += rTime; if (m_sound == nullptr) - m_sound = static_cast(m_iMan->SearchInstance(CLASS_SOUND)); + m_sound = CApplication::GetInstancePointer()->GetSound(); if (m_vapors[i].time <= m_vapors[i].delay) { @@ -206,7 +204,7 @@ void CWater::VaporFrame(int i, float rTime) Math::Point dim; dim.x = Math::Rand()*1.5f+1.5f; dim.y = dim.x; - m_particule->CreateParticle(pos, speed, dim, PARTIERROR, 2.0f, 10.0f); + m_particle->CreateParticle(pos, speed, dim, PARTIERROR, 2.0f, 10.0f); } } else if (m_vapors[i].type == PARTIFLAME) @@ -222,7 +220,7 @@ void CWater::VaporFrame(int i, float rTime) Math::Point dim; dim.x = Math::Rand()*2.0f+2.0f; dim.y = dim.x; - m_particule->CreateParticle(pos, speed, dim, PARTIFLAME); + m_particle->CreateParticle(pos, speed, dim, PARTIFLAME); } else { @@ -237,7 +235,7 @@ void CWater::VaporFrame(int i, float rTime) Math::Point dim; dim.x = Math::Rand()*1.0f+1.0f; dim.y = dim.x; - m_particule->CreateParticle(pos, speed, dim, PARTIVAPOR); + m_particle->CreateParticle(pos, speed, dim, PARTIVAPOR); } } } @@ -497,7 +495,7 @@ void CWater::Create(WaterType type1, WaterType type2, const std::string& fileNam m_engine->LoadTexture(m_fileName); if (m_terrain == nullptr) - m_terrain = static_cast(m_iMan->SearchInstance(CLASS_TERRAIN)); + m_terrain = CRobotMain::GetInstancePointer()->GetTerrain(); m_brickCount = m_terrain->GetBrickCount()*m_terrain->GetMosaicCount(); m_brickSize = m_terrain->GetBrickSize(); diff --git a/src/graphics/engine/water.h b/src/graphics/engine/water.h index 21d96d4..bb113e0 100644 --- a/src/graphics/engine/water.h +++ b/src/graphics/engine/water.h @@ -28,7 +28,6 @@ #include "graphics/engine/particle.h" -class CInstanceManager; class CSoundInterface; @@ -117,8 +116,8 @@ enum WaterType class CWater { public: - CWater(CInstanceManager* iMan, CEngine* engine); - ~CWater(); + CWater(CEngine* engine); + virtual ~CWater(); void SetDevice(CDevice* device); bool EventProcess(const Event &event); @@ -168,11 +167,10 @@ protected: void VaporFrame(int i, float rTime); protected: - CInstanceManager* m_iMan; CEngine* m_engine; CDevice* m_device; CTerrain* m_terrain; - CParticle* m_particule; + CParticle* m_particle; CSoundInterface* m_sound; WaterType m_type[2]; diff --git a/src/object/auto/auto.cpp b/src/object/auto/auto.cpp index 4003193..3d88012 100644 --- a/src/object/auto/auto.cpp +++ b/src/object/auto/auto.cpp @@ -18,8 +18,13 @@ #include "object/auto/auto.h" +#include "app/app.h" + +#include "common/event.h" #include "common/iman.h" + #include "script/cmdtoken.h" + #include "ui/interface.h" #include "ui/gauge.h" #include "ui/window.h" @@ -30,26 +35,24 @@ // Object's constructor. -CAuto::CAuto(CInstanceManager* iMan, CObject* object) +CAuto::CAuto(CObject* object) { - m_iMan = iMan; - m_iMan->AddInstance(CLASS_AUTO, this, 100); + m_iMan = CInstanceManager::GetInstancePointer(); m_object = object; - m_event = static_cast< CEventQueue* >(m_iMan->SearchInstance(CLASS_EVENT)); - m_engine = static_cast< Gfx::CEngine* >(m_iMan->SearchInstance(CLASS_ENGINE)); - m_particle = static_cast< Gfx::CParticle* >(m_iMan->SearchInstance(CLASS_PARTICULE)); - m_lightMan = static_cast< Gfx::CLightManager* >(m_iMan->SearchInstance(CLASS_LIGHT)); - m_terrain = static_cast< Gfx::CTerrain* >(m_iMan->SearchInstance(CLASS_TERRAIN)); - m_water = static_cast< Gfx::CWater* >(m_iMan->SearchInstance(CLASS_WATER)); - m_cloud = static_cast< Gfx::CCloud* >(m_iMan->SearchInstance(CLASS_CLOUD)); - m_planet = static_cast< Gfx::CPlanet* >(m_iMan->SearchInstance(CLASS_PLANET)); - m_lightning = static_cast< Gfx::CLightning* >(m_iMan->SearchInstance(CLASS_BLITZ)); - m_camera = static_cast< Gfx::CCamera* >(m_iMan->SearchInstance(CLASS_CAMERA)); - m_interface = static_cast< Ui::CInterface* >(m_iMan->SearchInstance(CLASS_INTERFACE)); - m_main = static_cast< CRobotMain* >(m_iMan->SearchInstance(CLASS_MAIN)); - m_displayText = static_cast< Ui::CDisplayText* >(m_iMan->SearchInstance(CLASS_DISPLAYTEXT)); - m_sound = static_cast< CSoundInterface* >(m_iMan->SearchInstance(CLASS_SOUND)); + m_engine = Gfx::CEngine::GetInstancePointer(); + m_main = CRobotMain::GetInstancePointer(); + m_eventQueue = CApplication::GetInstancePointer()->GetEventQueue(); + m_sound = CApplication::GetInstancePointer()->GetSound(); + m_particle = m_engine->GetParticle(); + m_terrain = m_engine->GetTerrain(); + m_water = m_engine->GetWater(); + m_cloud = m_engine->GetCloud(); + m_planet = m_engine->GetPlanet(); + m_lightning = m_engine->GetLightning(); + m_camera = m_main->GetCamera(); + m_interface = m_main->GetInterface(); + m_displayText = m_main->GetDisplayText(); m_type = m_object->GetType(); m_time = 0.0f; @@ -65,7 +68,22 @@ CAuto::CAuto(CInstanceManager* iMan, CObject* object) CAuto::~CAuto() { - m_iMan->DeleteInstance(CLASS_AUTO, this); + m_iMan = nullptr; + + m_object = nullptr; + m_engine = nullptr; + m_main = nullptr; + m_eventQueue = nullptr; + m_sound = nullptr; + m_particle = nullptr; + m_terrain = nullptr; + m_water = nullptr; + m_cloud = nullptr; + m_planet = nullptr; + m_lightning = nullptr; + m_camera = nullptr; + m_interface = nullptr; + m_displayText = nullptr; } diff --git a/src/object/auto/auto.h b/src/object/auto/auto.h index 2194924..53ccdf9 100644 --- a/src/object/auto/auto.h +++ b/src/object/auto/auto.h @@ -50,7 +50,7 @@ class CLightning; class CAuto { public: - CAuto(CInstanceManager* iMan, CObject* object); + CAuto(CObject* object); virtual ~CAuto(); virtual void DeleteObject(bool bAll=false); @@ -88,11 +88,10 @@ protected: void UpdateInterface(float rTime); protected: - CInstanceManager* m_iMan; - CEventQueue* m_event; + CInstanceManager* m_iMan; // TODO: to be removed + CEventQueue* m_eventQueue; Gfx::CEngine* m_engine; Gfx::CParticle* m_particle; - Gfx::CLightManager* m_lightMan; Gfx::CTerrain* m_terrain; Gfx::CWater* m_water; Gfx::CCloud* m_cloud; diff --git a/src/object/auto/autobase.cpp b/src/object/auto/autobase.cpp index 8370517..cb7f04c 100644 --- a/src/object/auto/autobase.cpp +++ b/src/object/auto/autobase.cpp @@ -20,13 +20,18 @@ #include "object/auto/autobase.h" #include "common/iman.h" + #include "graphics/engine/terrain.h" #include "graphics/engine/cloud.h" #include "graphics/engine/planet.h" #include "graphics/engine/lightning.h" + #include "math/geometry.h" + #include "object/robotmain.h" + #include "physics/physics.h" + #include "ui/interface.h" #include "ui/window.h" #include "ui/displaytext.h" @@ -47,8 +52,7 @@ const float BASE_TRANSIT_TIME = 15.0f; // transit duration // Object's constructor. -CAutoBase::CAutoBase(CInstanceManager* iMan, CObject* object) - : CAuto(iMan, object) +CAutoBase::CAutoBase(CObject* object) : CAuto(object) { m_fogStart = m_engine->GetFogStart(); m_deepView = m_engine->GetDeepView(); @@ -329,7 +333,7 @@ begin: m_main->DeselectAll(); newEvent.type = EVENT_UPDINTERFACE; - m_event->AddEvent(newEvent); + m_eventQueue->AddEvent(newEvent); m_camera->SetType(Gfx::CAM_TYPE_SCRIPT); @@ -843,7 +847,7 @@ begin: { m_soundChannel = -1; newEvent.type = EVENT_WIN; - m_event->AddEvent(newEvent); + m_eventQueue->AddEvent(newEvent); m_phase = ABP_WAIT; m_progress = 0.0f; @@ -1176,7 +1180,7 @@ bool CAutoBase::Abort() m_phase == ABP_TAKEOFF ) // off? { newEvent.type = EVENT_WIN; - m_event->AddEvent(newEvent); + m_eventQueue->AddEvent(newEvent); } } diff --git a/src/object/auto/autobase.h b/src/object/auto/autobase.h index 439d414..422f340 100644 --- a/src/object/auto/autobase.h +++ b/src/object/auto/autobase.h @@ -65,7 +65,7 @@ enum AutoBasePhase class CAutoBase : public CAuto { public: - CAutoBase(CInstanceManager* iMan, CObject* object); + CAutoBase(CObject* object); ~CAutoBase(); void DeleteObject(bool bAll=false); diff --git a/src/object/auto/autoconvert.cpp b/src/object/auto/autoconvert.cpp index a550697..7281ed7 100644 --- a/src/object/auto/autoconvert.cpp +++ b/src/object/auto/autoconvert.cpp @@ -19,8 +19,11 @@ #include "object/auto/autoconvert.h" #include "common/iman.h" + #include "math/geometry.h" + #include "script/cmdtoken.h" + #include "ui/interface.h" #include "ui/window.h" #include "ui/displaytext.h" @@ -31,8 +34,7 @@ // Object's constructor. -CAutoConvert::CAutoConvert(CInstanceManager* iMan, CObject* object) - : CAuto(iMan, object) +CAutoConvert::CAutoConvert(CObject* object) : CAuto(object) { Init(); m_phase = ACP_STOP; @@ -509,7 +511,7 @@ void CAutoConvert::CreateMetal() pos = m_object->GetPosition(0); angle = m_object->GetAngleY(0); - fret = new CObject(m_iMan); + fret = new CObject(); if ( !fret->CreateResource(pos, angle, OBJECT_METAL) ) { delete fret; diff --git a/src/object/auto/autoconvert.h b/src/object/auto/autoconvert.h index b21690f..56591f7 100644 --- a/src/object/auto/autoconvert.h +++ b/src/object/auto/autoconvert.h @@ -38,7 +38,7 @@ enum AutoConvertPhase class CAutoConvert : public CAuto { public: - CAutoConvert(CInstanceManager* iMan, CObject* object); + CAutoConvert(CObject* object); ~CAutoConvert(); void DeleteObject(bool bAll=false); diff --git a/src/object/auto/autoderrick.cpp b/src/object/auto/autoderrick.cpp index 3578c0d..260edcb 100644 --- a/src/object/auto/autoderrick.cpp +++ b/src/object/auto/autoderrick.cpp @@ -19,9 +19,13 @@ #include "object/auto/autoderrick.h" #include "common/iman.h" + #include "graphics/engine/terrain.h" + #include "math/geometry.h" + #include "script/cmdtoken.h" + #include "ui/interface.h" #include "ui/window.h" #include "ui/displaytext.h" @@ -38,8 +42,7 @@ const float DERRICK_DELAYu = 30.0f; // same, but for uranium // Object's constructor. -CAutoDerrick::CAutoDerrick(CInstanceManager* iMan, CObject* object) - : CAuto(iMan, object) +CAutoDerrick::CAutoDerrick(CObject* object) : CAuto(object) { Init(); m_phase = ADP_WAIT; // paused until the first Init () @@ -528,7 +531,7 @@ void CAutoDerrick::CreateFret(Math::Vector pos, float angle, ObjectType type, { CObject* fret; - fret = new CObject(m_iMan); + fret = new CObject(); if ( !fret->CreateResource(pos, angle, type) ) { delete fret; diff --git a/src/object/auto/autoderrick.h b/src/object/auto/autoderrick.h index b52f93b..81ed8b4 100644 --- a/src/object/auto/autoderrick.h +++ b/src/object/auto/autoderrick.h @@ -38,7 +38,7 @@ enum AutoDerrickPhase class CAutoDerrick : public CAuto { public: - CAutoDerrick(CInstanceManager* iMan, CObject* object); + CAutoDerrick(CObject* object); ~CAutoDerrick(); void DeleteObject(bool bAll=false); diff --git a/src/object/auto/autodestroyer.cpp b/src/object/auto/autodestroyer.cpp index 644071c..b62a45a 100644 --- a/src/object/auto/autodestroyer.cpp +++ b/src/object/auto/autodestroyer.cpp @@ -19,7 +19,9 @@ #include "object/auto/autodestroyer.h" #include "common/iman.h" + #include "script/cmdtoken.h" + #include "ui/interface.h" #include "ui/window.h" @@ -29,8 +31,7 @@ // Object's constructor. -CAutoDestroyer::CAutoDestroyer(CInstanceManager* iMan, CObject* object) - : CAuto(iMan, object) +CAutoDestroyer::CAutoDestroyer(CObject* object) : CAuto(object) { Init(); m_phase = ADEP_WAIT; // paused until the first Init () @@ -156,7 +157,7 @@ bool CAutoDestroyer::EventProcess(const Event &event) scrap = SearchPlastic(); if ( scrap != nullptr ) { - pyro = new Gfx::CPyro(m_iMan); + pyro = new Gfx::CPyro(); pyro->Create(Gfx::PT_FRAGT, scrap); } m_bExplo = true; diff --git a/src/object/auto/autodestroyer.h b/src/object/auto/autodestroyer.h index 50858d3..26981c3 100644 --- a/src/object/auto/autodestroyer.h +++ b/src/object/auto/autodestroyer.h @@ -37,7 +37,7 @@ enum AutoDestroyerPhase class CAutoDestroyer : public CAuto { public: - CAutoDestroyer(CInstanceManager* iMan, CObject* object); + CAutoDestroyer(CObject* object); ~CAutoDestroyer(); void DeleteObject(bool bAll=false); diff --git a/src/object/auto/autoegg.cpp b/src/object/auto/autoegg.cpp index 5b90ef9..e510ca6 100644 --- a/src/object/auto/autoegg.cpp +++ b/src/object/auto/autoegg.cpp @@ -18,8 +18,10 @@ #include "object/auto/autoegg.h" -#include "math/geometry.h" #include "common/iman.h" + +#include "math/geometry.h" + #include "script/cmdtoken.h" #include @@ -28,8 +30,7 @@ // Object's constructor. -CAutoEgg::CAutoEgg(CInstanceManager* iMan, CObject* object) - : CAuto(iMan, object) +CAutoEgg::CAutoEgg(CObject* object) : CAuto(object) { m_type = OBJECT_NULL; m_value = 0.0f; @@ -174,7 +175,7 @@ bool CAutoEgg::EventProcess(const Event &event) m_progress += event.rTime*m_speed; if ( m_progress < 1.0f ) return true; - alien = new CObject(m_iMan); + alien = new CObject(); if ( !alien->CreateInsect(m_object->GetPosition(0), m_object->GetAngleY(0), m_type) ) { delete alien; @@ -236,7 +237,7 @@ Error CAutoEgg::IsEnded() { if ( m_progress < 1.0f ) return ERR_CONTINUE; - pyro = new Gfx::CPyro(m_iMan); + pyro = new Gfx::CPyro(); pyro->Create(Gfx::PT_EGG, m_object); // exploding egg alien->SetZoom(0, 1.0f); // this is a big boy now diff --git a/src/object/auto/autoegg.h b/src/object/auto/autoegg.h index fec07a6..00725db 100644 --- a/src/object/auto/autoegg.h +++ b/src/object/auto/autoegg.h @@ -37,7 +37,7 @@ enum AutoEggPhase class CAutoEgg : public CAuto { public: - CAutoEgg(CInstanceManager* iMan, CObject* object); + CAutoEgg(CObject* object); ~CAutoEgg(); void DeleteObject(bool bAll=false); diff --git a/src/object/auto/autoenergy.cpp b/src/object/auto/autoenergy.cpp index c63dede..a0b4d85 100644 --- a/src/object/auto/autoenergy.cpp +++ b/src/object/auto/autoenergy.cpp @@ -19,9 +19,13 @@ #include "object/auto/autoenergy.h" #include "common/iman.h" + #include "graphics/engine/terrain.h" + #include "math/geometry.h" + #include "script/cmdtoken.h" + #include "ui/interface.h" #include "ui/gauge.h" #include "ui/window.h" @@ -39,8 +43,7 @@ const float ENERGY_DELAY = 12.0f; // processing time // Object's constructor. -CAutoEnergy::CAutoEnergy(CInstanceManager* iMan, CObject* object) - : CAuto(iMan, object) +CAutoEnergy::CAutoEnergy(CObject* object) : CAuto(object) { m_partiSphere = -1; Init(); @@ -461,7 +464,7 @@ void CAutoEnergy::CreatePower() pos = m_object->GetPosition(0); angle = m_object->GetAngleY(0); - power = new CObject(m_iMan); + power = new CObject(); if ( !power->CreateResource(pos, angle, OBJECT_POWER) ) { delete power; diff --git a/src/object/auto/autoenergy.h b/src/object/auto/autoenergy.h index 53d47b6..d3ed5fe 100644 --- a/src/object/auto/autoenergy.h +++ b/src/object/auto/autoenergy.h @@ -38,7 +38,7 @@ enum AutoEnergyPhase class CAutoEnergy : public CAuto { public: - CAutoEnergy(CInstanceManager* iMan, CObject* object); + CAutoEnergy(CObject* object); ~CAutoEnergy(); void DeleteObject(bool bAll=false); diff --git a/src/object/auto/autofactory.cpp b/src/object/auto/autofactory.cpp index 0789443..82877c6 100644 --- a/src/object/auto/autofactory.cpp +++ b/src/object/auto/autofactory.cpp @@ -20,10 +20,15 @@ #include "common/global.h" #include "common/iman.h" + #include "math/geometry.h" + #include "object/robotmain.h" + #include "physics/physics.h" + #include "script/cmdtoken.h" + #include "ui/interface.h" #include "ui/window.h" #include "ui/displaytext.h" @@ -35,8 +40,7 @@ // Object's constructor. -CAutoFactory::CAutoFactory(CInstanceManager* iMan, CObject* object) - : CAuto(iMan, object) +CAutoFactory::CAutoFactory(CObject* object) : CAuto(object) { Init(); m_type = OBJECT_MOBILEws; @@ -632,7 +636,7 @@ bool CAutoFactory::CreateVehicle() } pos = Transform(*mat, pos); - vehicle = new CObject(m_iMan); + vehicle = new CObject(); if ( !vehicle->CreateVehicle(pos, angle, m_type, -1.0f, false, false) ) { delete vehicle; diff --git a/src/object/auto/autofactory.h b/src/object/auto/autofactory.h index f62080d..7c5013d 100644 --- a/src/object/auto/autofactory.h +++ b/src/object/auto/autofactory.h @@ -40,7 +40,7 @@ enum AutoFactoryPhase class CAutoFactory : public CAuto { public: - CAutoFactory(CInstanceManager* iMan, CObject* object); + CAutoFactory(CObject* object); ~CAutoFactory(); void DeleteObject(bool bAll=false); diff --git a/src/object/auto/autoflag.cpp b/src/object/auto/autoflag.cpp index c2dec5c..936546d 100644 --- a/src/object/auto/autoflag.cpp +++ b/src/object/auto/autoflag.cpp @@ -37,8 +37,7 @@ static float g_flag3 = 2.00f; // Object's constructor. -CAutoFlag::CAutoFlag(CInstanceManager* iMan, CObject* object) - : CAuto(iMan, object) +CAutoFlag::CAutoFlag(CObject* object) : CAuto(object) { Init(); } diff --git a/src/object/auto/autoflag.h b/src/object/auto/autoflag.h index 3c6cf99..c3fd35a 100644 --- a/src/object/auto/autoflag.h +++ b/src/object/auto/autoflag.h @@ -27,7 +27,7 @@ class CAutoFlag : public CAuto { public: - CAutoFlag(CInstanceManager* iMan, CObject* object); + CAutoFlag(CObject* object); ~CAutoFlag(); void DeleteObject(bool bAll=false); diff --git a/src/object/auto/autohuston.cpp b/src/object/auto/autohuston.cpp index 1b6778d..80f9185 100644 --- a/src/object/auto/autohuston.cpp +++ b/src/object/auto/autohuston.cpp @@ -26,8 +26,7 @@ // Object's constructor. -CAutoHuston::CAutoHuston(CInstanceManager* iMan, CObject* object) - : CAuto(iMan, object) +CAutoHuston::CAutoHuston(CObject* object) : CAuto(object) { Math::Vector pos; int i; diff --git a/src/object/auto/autohuston.h b/src/object/auto/autohuston.h index 27b016b..f99876a 100644 --- a/src/object/auto/autohuston.h +++ b/src/object/auto/autohuston.h @@ -42,7 +42,7 @@ const int HUSTONMAXLENS = 20; class CAutoHuston : public CAuto { public: - CAutoHuston(CInstanceManager* iMan, CObject* object); + CAutoHuston(CObject* object); ~CAutoHuston(); void DeleteObject(bool bAll=false); diff --git a/src/object/auto/autoinfo.cpp b/src/object/auto/autoinfo.cpp index 1245034..56c21d2 100644 --- a/src/object/auto/autoinfo.cpp +++ b/src/object/auto/autoinfo.cpp @@ -30,8 +30,7 @@ // Object's constructor. -CAutoInfo::CAutoInfo(CInstanceManager* iMan, CObject* object) - : CAuto(iMan, object) +CAutoInfo::CAutoInfo(CObject* object) : CAuto(object) { Init(); } diff --git a/src/object/auto/autoinfo.h b/src/object/auto/autoinfo.h index 30481bb..41b74d3 100644 --- a/src/object/auto/autoinfo.h +++ b/src/object/auto/autoinfo.h @@ -37,7 +37,7 @@ enum AutoInfoPhase class CAutoInfo : public CAuto { public: - CAutoInfo(CInstanceManager* iMan, CObject* object); + CAutoInfo(CObject* object); ~CAutoInfo(); void DeleteObject(bool bAll=false); diff --git a/src/object/auto/autojostle.cpp b/src/object/auto/autojostle.cpp index 788b562..11952c2 100644 --- a/src/object/auto/autojostle.cpp +++ b/src/object/auto/autojostle.cpp @@ -23,8 +23,7 @@ // Object's constructor. -CAutoJostle::CAutoJostle(CInstanceManager* iMan, CObject* object) - : CAuto(iMan, object) +CAutoJostle::CAutoJostle(CObject* object) : CAuto(object) { Init(); } diff --git a/src/object/auto/autojostle.h b/src/object/auto/autojostle.h index c156893..7b700ad 100644 --- a/src/object/auto/autojostle.h +++ b/src/object/auto/autojostle.h @@ -27,7 +27,7 @@ class CAutoJostle : public CAuto { public: - CAutoJostle(CInstanceManager* iMan, CObject* object); + CAutoJostle(CObject* object); ~CAutoJostle(); void DeleteObject(bool bAll=false); diff --git a/src/object/auto/autokid.cpp b/src/object/auto/autokid.cpp index 64cd39a..a9f86b0 100644 --- a/src/object/auto/autokid.cpp +++ b/src/object/auto/autokid.cpp @@ -26,8 +26,7 @@ // Object's constructor. -CAutoKid::CAutoKid(CInstanceManager* iMan, CObject* object) - : CAuto(iMan, object) +CAutoKid::CAutoKid(CObject* object) : CAuto(object) { m_soundChannel = -1; Init(); diff --git a/src/object/auto/autokid.h b/src/object/auto/autokid.h index 3e2fba7..19836a7 100644 --- a/src/object/auto/autokid.h +++ b/src/object/auto/autokid.h @@ -27,7 +27,7 @@ class CAutoKid : public CAuto { public: - CAutoKid(CInstanceManager* iMan, CObject* object); + CAutoKid(CObject* object); ~CAutoKid(); void DeleteObject(bool bAll=false); diff --git a/src/object/auto/autolabo.cpp b/src/object/auto/autolabo.cpp index 70bcc5e..6984fd6 100644 --- a/src/object/auto/autolabo.cpp +++ b/src/object/auto/autolabo.cpp @@ -20,9 +20,13 @@ #include "common/global.h" #include "common/misc.h" + #include "math/geometry.h" + #include "object/robotmain.h" + #include "script/cmdtoken.h" + #include "ui/interface.h" #include "ui/window.h" #include "ui/displaytext.h" @@ -38,8 +42,7 @@ const float LABO_DELAY = 20.0f; // duration of the analysis // Object's constructor. -CAutoLabo::CAutoLabo(CInstanceManager* iMan, CObject* object) - : CAuto(iMan, object) + CAutoLabo::CAutoLabo(CObject* object) : CAuto(object) { int i; @@ -543,8 +546,8 @@ void CAutoLabo::SetResearch(EventType event) m_main->WriteFreeParam(); Event newEvent(EVENT_UPDINTERFACE); -// m_event->MakeEvent(newEvent, EVENT_UPDINTERFACE); - m_event->AddEvent(newEvent); +// m_eventQueue->MakeEvent(newEvent, EVENT_UPDINTERFACE); + m_eventQueue->AddEvent(newEvent); UpdateInterface(); } diff --git a/src/object/auto/autolabo.h b/src/object/auto/autolabo.h index 8225462..b61e8e3 100644 --- a/src/object/auto/autolabo.h +++ b/src/object/auto/autolabo.h @@ -41,7 +41,7 @@ enum AutoLaboPhase class CAutoLabo : public CAuto { public: - CAutoLabo(CInstanceManager* iMan, CObject* object); + CAutoLabo(CObject* object); ~CAutoLabo(); void DeleteObject(bool bAll=false); diff --git a/src/object/auto/automush.cpp b/src/object/auto/automush.cpp index cb94590..e97e2a1 100644 --- a/src/object/auto/automush.cpp +++ b/src/object/auto/automush.cpp @@ -19,6 +19,7 @@ #include "object/auto/automush.h" #include "common/iman.h" + #include "script/cmdtoken.h" @@ -28,8 +29,7 @@ // Object's constructor. -CAutoMush::CAutoMush(CInstanceManager* iMan, CObject* object) - : CAuto(iMan, object) + CAutoMush::CAutoMush(CObject* object) : CAuto(object) { Init(); } diff --git a/src/object/auto/automush.h b/src/object/auto/automush.h index 245393a..1697c5a 100644 --- a/src/object/auto/automush.h +++ b/src/object/auto/automush.h @@ -38,7 +38,7 @@ enum AutoMushPhase class CAutoMush : public CAuto { public: - CAutoMush(CInstanceManager* iMan, CObject* object); + CAutoMush(CObject* object); ~CAutoMush(); void DeleteObject(bool bAll=false); diff --git a/src/object/auto/autonest.cpp b/src/object/auto/autonest.cpp index 99927bd..1cf13d6 100644 --- a/src/object/auto/autonest.cpp +++ b/src/object/auto/autonest.cpp @@ -19,7 +19,9 @@ #include "object/auto/autonest.h" #include "common/iman.h" + #include "graphics/engine/terrain.h" + #include "script/cmdtoken.h" #include @@ -28,8 +30,7 @@ // Object's constructor. -CAutoNest::CAutoNest(CInstanceManager* iMan, CObject* object) - : CAuto(iMan, object) + CAutoNest::CAutoNest(CObject* object) : CAuto(object) { Init(); } @@ -178,7 +179,7 @@ void CAutoNest::CreateFret(Math::Vector pos, float angle, ObjectType type) { CObject* fret; - fret = new CObject(m_iMan); + fret = new CObject(); if ( !fret->CreateResource(pos, angle, type) ) { delete fret; diff --git a/src/object/auto/autonest.h b/src/object/auto/autonest.h index 1009457..4d734a8 100644 --- a/src/object/auto/autonest.h +++ b/src/object/auto/autonest.h @@ -35,7 +35,7 @@ enum AutoNestPhase class CAutoNest : public CAuto { public: - CAutoNest(CInstanceManager* iMan, CObject* object); + CAutoNest(CObject* object); ~CAutoNest(); void DeleteObject(bool bAll=false); diff --git a/src/object/auto/autonuclear.cpp b/src/object/auto/autonuclear.cpp index 375acf0..75bfb45 100644 --- a/src/object/auto/autonuclear.cpp +++ b/src/object/auto/autonuclear.cpp @@ -19,8 +19,11 @@ #include "object/auto/autonuclear.h" #include "common/iman.h" + #include "math/geometry.h" + #include "script/cmdtoken.h" + #include "ui/interface.h" #include "ui/window.h" #include "ui/displaytext.h" @@ -36,8 +39,7 @@ const float NUCLEAR_DELAY = 30.0f; // duration of the generation // Object's constructor. -CAutoNuclear::CAutoNuclear(CInstanceManager* iMan, CObject* object) - : CAuto(iMan, object) +CAutoNuclear::CAutoNuclear(CObject* object) : CAuto(object) { m_channelSound = -1; Init(); @@ -396,7 +398,7 @@ void CAutoNuclear::CreatePower() pos = m_object->GetPosition(0); angle = m_object->GetAngleY(0); - power = new CObject(m_iMan); + power = new CObject(); if ( !power->CreateResource(pos, angle, OBJECT_ATOMIC) ) { delete power; diff --git a/src/object/auto/autonuclear.h b/src/object/auto/autonuclear.h index 06a99af..5b01bba 100644 --- a/src/object/auto/autonuclear.h +++ b/src/object/auto/autonuclear.h @@ -38,7 +38,7 @@ enum AutoNuclearPhase class CAutoNuclear : public CAuto { public: - CAutoNuclear(CInstanceManager* iMan, CObject* object); + CAutoNuclear(CObject* object); ~CAutoNuclear(); void DeleteObject(bool bAll=false); diff --git a/src/object/auto/autopara.cpp b/src/object/auto/autopara.cpp index a3082f5..ad6517b 100644 --- a/src/object/auto/autopara.cpp +++ b/src/object/auto/autopara.cpp @@ -20,8 +20,11 @@ #include "common/iman.h" + #include "math/geometry.h" + #include "script/cmdtoken.h" + #include "ui/interface.h" #include "ui/window.h" @@ -32,8 +35,7 @@ // Object's constructor. -CAutoPara::CAutoPara(CInstanceManager* iMan, CObject* object) - : CAuto(iMan, object) +CAutoPara::CAutoPara(CObject* object) : CAuto(object) { m_channelSound = -1; Init(); diff --git a/src/object/auto/autopara.h b/src/object/auto/autopara.h index 10a33a8..1f0b805 100644 --- a/src/object/auto/autopara.h +++ b/src/object/auto/autopara.h @@ -36,7 +36,7 @@ enum AutoParaPhase class CAutoPara : public CAuto { public: - CAutoPara(CInstanceManager* iMan, CObject* object); + CAutoPara(CObject* object); ~CAutoPara(); void DeleteObject(bool bAll=false); diff --git a/src/object/auto/autoportico.cpp b/src/object/auto/autoportico.cpp index c0be784..1646874 100644 --- a/src/object/auto/autoportico.cpp +++ b/src/object/auto/autoportico.cpp @@ -55,8 +55,7 @@ float Progress(float a, float b, float progress) // Object's constructor. -CAutoPortico::CAutoPortico(CInstanceManager* iMan, CObject* object) - : CAuto(iMan, object) +CAutoPortico::CAutoPortico(CObject* object) : CAuto(object) { Init(); m_phase = APOP_WAIT; diff --git a/src/object/auto/autoportico.h b/src/object/auto/autoportico.h index c211d37..0aa580f 100644 --- a/src/object/auto/autoportico.h +++ b/src/object/auto/autoportico.h @@ -40,7 +40,7 @@ enum AutoPorticoPhase class CAutoPortico : public CAuto { public: - CAutoPortico(CInstanceManager* iMan, CObject* object); + CAutoPortico(CObject* object); ~CAutoPortico(); void DeleteObject(bool bAll=false); diff --git a/src/object/auto/autoradar.cpp b/src/object/auto/autoradar.cpp index 4214d17..1a10aa7 100644 --- a/src/object/auto/autoradar.cpp +++ b/src/object/auto/autoradar.cpp @@ -19,7 +19,9 @@ #include "object/auto/autoradar.h" #include "common/iman.h" + #include "math/geometry.h" + #include "ui/interface.h" #include "ui/window.h" #include "ui/gauge.h" @@ -29,8 +31,7 @@ // Object's constructor. -CAutoRadar::CAutoRadar(CInstanceManager* iMan, CObject* object) - : CAuto(iMan, object) +CAutoRadar::CAutoRadar(CObject* object) : CAuto(object) { Init(); m_phase = ARAP_WAIT; diff --git a/src/object/auto/autoradar.h b/src/object/auto/autoradar.h index e2c9df5..86833f9 100644 --- a/src/object/auto/autoradar.h +++ b/src/object/auto/autoradar.h @@ -37,7 +37,7 @@ enum AutoRadarPhase class CAutoRadar : public CAuto { public: - CAutoRadar(CInstanceManager* iMan, CObject* object); + CAutoRadar(CObject* object); ~CAutoRadar(); void DeleteObject(bool bAll=false); diff --git a/src/object/auto/autorepair.cpp b/src/object/auto/autorepair.cpp index cf4f33e..95b6cc8 100644 --- a/src/object/auto/autorepair.cpp +++ b/src/object/auto/autorepair.cpp @@ -19,8 +19,11 @@ #include "object/auto/autorepair.h" #include "common/iman.h" + #include "physics/physics.h" + #include "script/cmdtoken.h" + #include "ui/interface.h" #include "ui/window.h" @@ -30,8 +33,7 @@ // Object's constructor. -CAutoRepair::CAutoRepair(CInstanceManager* iMan, CObject* object) - : CAuto(iMan, object) +CAutoRepair::CAutoRepair(CObject* object) : CAuto(object) { Init(); m_phase = ARP_WAIT; // paused until the first Init () diff --git a/src/object/auto/autorepair.h b/src/object/auto/autorepair.h index e8bb0b1..31a3c65 100644 --- a/src/object/auto/autorepair.h +++ b/src/object/auto/autorepair.h @@ -38,7 +38,7 @@ enum AutoRepairPhase class CAutoRepair : public CAuto { public: - CAutoRepair(CInstanceManager* iMan, CObject* object); + CAutoRepair(CObject* object); ~CAutoRepair(); void DeleteObject(bool bAll=false); diff --git a/src/object/auto/autoresearch.cpp b/src/object/auto/autoresearch.cpp index 9f423ec..3c32307 100644 --- a/src/object/auto/autoresearch.cpp +++ b/src/object/auto/autoresearch.cpp @@ -19,9 +19,13 @@ #include "object/auto/autoresearch.h" #include "common/global.h" + #include "math/geometry.h" + #include "object/robotmain.h" + #include "script/cmdtoken.h" + #include "ui/interface.h" #include "ui/gauge.h" #include "ui/window.h" @@ -37,8 +41,7 @@ const float SEARCH_TIME = 30.0f; // duration of a research // Object's constructor. -CAutoResearch::CAutoResearch(CInstanceManager* iMan, CObject* object) - : CAuto(iMan, object) +CAutoResearch::CAutoResearch(CObject* object) : CAuto(object) { int i; @@ -488,7 +491,7 @@ void CAutoResearch::SetResearch(EventType event) m_main->WriteFreeParam(); Event newEvent(EVENT_UPDINTERFACE); - m_event->AddEvent(newEvent); + m_eventQueue->AddEvent(newEvent); UpdateInterface(); } diff --git a/src/object/auto/autoresearch.h b/src/object/auto/autoresearch.h index a838e64..6c804ef 100644 --- a/src/object/auto/autoresearch.h +++ b/src/object/auto/autoresearch.h @@ -35,7 +35,7 @@ enum AutoResearchPhase class CAutoResearch : public CAuto { public: - CAutoResearch(CInstanceManager* iMan, CObject* object); + CAutoResearch(CObject* object); ~CAutoResearch(); void DeleteObject(bool bAll=false); diff --git a/src/object/auto/autoroot.cpp b/src/object/auto/autoroot.cpp index 196ed5d..a390e90 100644 --- a/src/object/auto/autoroot.cpp +++ b/src/object/auto/autoroot.cpp @@ -19,6 +19,7 @@ #include "graphics/engine/particle.h" #include "graphics/engine/terrain.h" + #include "math/geometry.h" #include @@ -26,8 +27,7 @@ // Object's constructor. -CAutoRoot::CAutoRoot(CInstanceManager* iMan, CObject* object) - : CAuto(iMan, object) +CAutoRoot::CAutoRoot(CObject* object) : CAuto(object) { Init(); } diff --git a/src/object/auto/autoroot.h b/src/object/auto/autoroot.h index d80abe8..3eb906c 100644 --- a/src/object/auto/autoroot.h +++ b/src/object/auto/autoroot.h @@ -27,7 +27,7 @@ class CAutoRoot : public CAuto { public: - CAutoRoot(CInstanceManager* iMan, CObject* object); + CAutoRoot(CObject* object); ~CAutoRoot(); void DeleteObject(bool bAll=false); diff --git a/src/object/auto/autosafe.cpp b/src/object/auto/autosafe.cpp index e89acea..fc83400 100644 --- a/src/object/auto/autosafe.cpp +++ b/src/object/auto/autosafe.cpp @@ -19,9 +19,13 @@ #include "object/auto/autosafe.h" #include "common/iman.h" + #include "math/geometry.h" + #include "object/robotmain.h" + #include "script/cmdtoken.h" + #include "ui/interface.h" #include "ui/window.h" @@ -34,8 +38,7 @@ const float OPEN_DELAY = 8.0f; // duration of opening // Object's constructor. -CAutoSafe::CAutoSafe(CInstanceManager* iMan, CObject* object) - : CAuto(iMan, object) +CAutoSafe::CAutoSafe(CObject* object) : CAuto(object) { int i; diff --git a/src/object/auto/autosafe.h b/src/object/auto/autosafe.h index 3c0bcce..b575b4e 100644 --- a/src/object/auto/autosafe.h +++ b/src/object/auto/autosafe.h @@ -36,7 +36,7 @@ enum AutoSafePhase class CAutoSafe : public CAuto { public: - CAutoSafe(CInstanceManager* iMan, CObject* object); + CAutoSafe(CObject* object); ~CAutoSafe(); void DeleteObject(bool bAll=false); diff --git a/src/object/auto/autostation.cpp b/src/object/auto/autostation.cpp index e99ae4b..a2f5b6b 100644 --- a/src/object/auto/autostation.cpp +++ b/src/object/auto/autostation.cpp @@ -19,9 +19,12 @@ #include "object/auto/autostation.h" #include "common/iman.h" + #include "graphics/engine/particle.h" #include "graphics/engine/terrain.h" + #include "math/geometry.h" + #include "ui/interface.h" #include "ui/gauge.h" #include "ui/window.h" @@ -31,8 +34,7 @@ // Object's constructor. -CAutoStation::CAutoStation(CInstanceManager* iMan, CObject* object) - : CAuto(iMan, object) +CAutoStation::CAutoStation(CObject* object) : CAuto(object) { Init(); } diff --git a/src/object/auto/autostation.h b/src/object/auto/autostation.h index cb8be2b..d8a37b4 100644 --- a/src/object/auto/autostation.h +++ b/src/object/auto/autostation.h @@ -27,7 +27,7 @@ class CAutoStation : public CAuto { public: - CAutoStation(CInstanceManager* iMan, CObject* object); + CAutoStation(CObject* object); ~CAutoStation(); void DeleteObject(bool bAll=false); diff --git a/src/object/auto/autotower.cpp b/src/object/auto/autotower.cpp index 84dcd85..e3b06cf 100644 --- a/src/object/auto/autotower.cpp +++ b/src/object/auto/autotower.cpp @@ -19,9 +19,13 @@ #include "object/auto/autotower.h" #include "common/iman.h" + #include "math/geometry.h" + #include "physics/physics.h" + #include "script/cmdtoken.h" + #include "ui/interface.h" #include "ui/displaytext.h" #include "ui/window.h" @@ -37,8 +41,7 @@ const float ENERGY_FIRE = 0.125f; // energy consumed by fire // Object's constructor. -CAutoTower::CAutoTower(CInstanceManager* iMan, CObject* object) - : CAuto(iMan, object) +CAutoTower::CAutoTower(CObject* object) : CAuto(object) { int i; diff --git a/src/object/auto/autotower.h b/src/object/auto/autotower.h index b29ba85..d219fb5 100644 --- a/src/object/auto/autotower.h +++ b/src/object/auto/autotower.h @@ -38,7 +38,7 @@ enum AutoTowerPhase class CAutoTower : public CAuto { public: - CAutoTower(CInstanceManager* iMan, CObject* object); + CAutoTower(CObject* object); ~CAutoTower(); void DeleteObject(bool bAll=false); diff --git a/src/object/brain.cpp b/src/object/brain.cpp index 1405201..babb38d 100644 --- a/src/object/brain.cpp +++ b/src/object/brain.cpp @@ -17,8 +17,10 @@ #include "object/brain.h" -#include "common/misc.h" +#include "app/app.h" + #include "common/iman.h" +#include "common/misc.h" #include "graphics/core/color.h" #include "graphics/engine/terrain.h" @@ -47,28 +49,25 @@ const int MAXTRACERECORD = 1000; // Object's constructor. -CBrain::CBrain(CInstanceManager* iMan, CObject* object) +CBrain::CBrain(CObject* object) { - int i; - - m_iMan = iMan; - m_iMan->AddInstance(CLASS_BRAIN, this, 100); + CInstanceManager::GetInstancePointer()->AddInstance(CLASS_BRAIN, this, 100); m_object = object; - m_engine = static_cast(m_iMan->SearchInstance(CLASS_ENGINE)); - m_terrain = static_cast(m_iMan->SearchInstance(CLASS_TERRAIN)); - m_water = static_cast(m_iMan->SearchInstance(CLASS_WATER)); - m_camera = static_cast(m_iMan->SearchInstance(CLASS_CAMERA)); - m_interface = static_cast(m_iMan->SearchInstance(CLASS_INTERFACE)); - m_displayText = static_cast(m_iMan->SearchInstance(CLASS_DISPLAYTEXT)); - m_main = static_cast(m_iMan->SearchInstance(CLASS_MAIN)); - m_sound = static_cast(m_iMan->SearchInstance(CLASS_SOUND)); - m_particle = static_cast(m_iMan->SearchInstance(CLASS_PARTICULE)); - m_physics = 0; - m_motion = 0; - m_primaryTask = 0; - m_secondaryTask = 0; - m_studio = 0; + m_engine = Gfx::CEngine::GetInstancePointer(); + m_water = m_engine->GetWater(); + m_particle = m_engine->GetParticle(); + m_main = CRobotMain::GetInstancePointer(); + m_terrain = m_main->GetTerrain(); + m_camera = m_main->GetCamera(); + m_interface = m_main->GetInterface(); + m_displayText = m_main->GetDisplayText(); + m_sound = CApplication::GetInstancePointer()->GetSound(); + m_physics = nullptr; + m_motion = nullptr; + m_primaryTask = nullptr; + m_secondaryTask = nullptr; + m_studio = nullptr; m_program = -1; m_bActivity = true; @@ -89,7 +88,7 @@ CBrain::CBrain(CInstanceManager* iMan, CObject* object) m_defaultEnter = EVENT_NULL; m_manipStyle = EVENT_OBJECT_MFRONT; - for ( i=0 ; iDeleteInstance(CLASS_BRAIN, this); + CInstanceManager::GetInstancePointer()->DeleteInstance(CLASS_BRAIN, this); } @@ -873,7 +870,7 @@ void CBrain::StartEditScript(int rank, char* name) if ( m_script[rank] == 0 ) { - m_script[rank] = new CScript(m_iMan, m_object, &m_secondaryTask); + m_script[rank] = new CScript(m_object, &m_secondaryTask); } m_studio = new Ui::CStudio(); @@ -908,7 +905,7 @@ Error CBrain::StartTaskTake() m_primaryTask = 0; } - m_primaryTask = new CTaskManager(m_iMan, m_object); + m_primaryTask = new CTaskManager(m_object); err = m_primaryTask->StartTaskTake(); UpdateInterface(); return err; @@ -926,7 +923,7 @@ Error CBrain::StartTaskManip(TaskManipOrder order, TaskManipArm arm) m_primaryTask = 0; } - m_primaryTask = new CTaskManager(m_iMan, m_object); + m_primaryTask = new CTaskManager(m_object); err = m_primaryTask->StartTaskManip(order, arm); UpdateInterface(); return err; @@ -944,7 +941,7 @@ Error CBrain::StartTaskFlag(TaskFlagOrder order, int rank) m_primaryTask = 0; } - m_primaryTask = new CTaskManager(m_iMan, m_object); + m_primaryTask = new CTaskManager(m_object); err = m_primaryTask->StartTaskFlag(order, rank); UpdateInterface(); return err; @@ -962,7 +959,7 @@ Error CBrain::StartTaskBuild(ObjectType type) m_primaryTask = 0; } - m_primaryTask = new CTaskManager(m_iMan, m_object); + m_primaryTask = new CTaskManager(m_object); err = m_primaryTask->StartTaskBuild(type); UpdateInterface(); return err; @@ -980,7 +977,7 @@ Error CBrain::StartTaskSearch() m_primaryTask = 0; } - m_primaryTask = new CTaskManager(m_iMan, m_object); + m_primaryTask = new CTaskManager(m_object); err = m_primaryTask->StartTaskSearch(); UpdateInterface(); return err; @@ -998,7 +995,7 @@ Error CBrain::StartTaskTerraform() m_primaryTask = 0; } - m_primaryTask = new CTaskManager(m_iMan, m_object); + m_primaryTask = new CTaskManager(m_object); err = m_primaryTask->StartTaskTerraform(); UpdateInterface(); return err; @@ -1020,7 +1017,7 @@ Error CBrain::StartTaskPen(bool bDown, int color) m_primaryTask = 0; } - m_primaryTask = new CTaskManager(m_iMan, m_object); + m_primaryTask = new CTaskManager(m_object); err = m_primaryTask->StartTaskPen(bDown, color); UpdateInterface(); return err; @@ -1038,7 +1035,7 @@ Error CBrain::StartTaskRecover() m_primaryTask = 0; } - m_primaryTask = new CTaskManager(m_iMan, m_object); + m_primaryTask = new CTaskManager(m_object); err = m_primaryTask->StartTaskRecover(); UpdateInterface(); return err; @@ -1056,7 +1053,7 @@ Error CBrain::StartTaskShield(TaskShieldMode mode) m_secondaryTask = 0; } - m_secondaryTask = new CTaskManager(m_iMan, m_object); + m_secondaryTask = new CTaskManager(m_object); err = m_secondaryTask->StartTaskShield(mode, 1000.0f); UpdateInterface(); return err; @@ -1074,7 +1071,7 @@ Error CBrain::StartTaskFire(float delay) m_primaryTask = 0; } - m_primaryTask = new CTaskManager(m_iMan, m_object); + m_primaryTask = new CTaskManager(m_object); err = m_primaryTask->StartTaskFire(delay); UpdateInterface(); return err; @@ -1092,7 +1089,7 @@ Error CBrain::StartTaskFireAnt(Math::Vector impact) m_primaryTask = 0; } - m_primaryTask = new CTaskManager(m_iMan, m_object); + m_primaryTask = new CTaskManager(m_object); err = m_primaryTask->StartTaskFireAnt(impact); UpdateInterface(); return err; @@ -1110,7 +1107,7 @@ Error CBrain::StartTaskGunGoal(float dirV, float dirH) m_secondaryTask = 0; } - m_secondaryTask = new CTaskManager(m_iMan, m_object); + m_secondaryTask = new CTaskManager(m_object); err = m_secondaryTask->StartTaskGunGoal(dirV, dirH); UpdateInterface(); return err; @@ -1128,7 +1125,7 @@ Error CBrain::StartTaskReset(Math::Vector goal, Math::Vector angle) m_primaryTask = 0; } - m_primaryTask = new CTaskManager(m_iMan, m_object); + m_primaryTask = new CTaskManager(m_object); err = m_primaryTask->StartTaskReset(goal, angle); UpdateInterface(); return err; @@ -2698,7 +2695,7 @@ bool CBrain::ReadProgram(int rank, const char* filename) { if ( m_script[rank] == 0 ) { - m_script[rank] = new CScript(m_iMan, m_object, &m_secondaryTask); + m_script[rank] = new CScript(m_object, &m_secondaryTask); } if ( m_script[rank]->ReadScript(filename) ) return true; @@ -2723,7 +2720,7 @@ bool CBrain::WriteProgram(int rank, char* filename) { if ( m_script[rank] == 0 ) { - m_script[rank] = new CScript(m_iMan, m_object, &m_secondaryTask); + m_script[rank] = new CScript(m_object, &m_secondaryTask); } if ( m_script[rank]->WriteScript(filename) ) return true; @@ -2753,7 +2750,7 @@ bool CBrain::ReadStack(FILE *file) if ( m_script[op] == 0 ) { - m_script[op] = new CScript(m_iMan, m_object, &m_secondaryTask); + m_script[op] = new CScript(m_object, &m_secondaryTask); } if ( !m_script[op]->ReadStack(file) ) return false; } @@ -2915,7 +2912,7 @@ void CBrain::TraceRecordStop() i = m_selScript; if ( m_script[i] == 0 ) { - m_script[i] = new CScript(m_iMan, m_object, &m_secondaryTask); + m_script[i] = new CScript(m_object, &m_secondaryTask); } m_script[i]->SendScript(buffer); delete[] buffer; diff --git a/src/object/brain.h b/src/object/brain.h index ce7116e..5656f62 100644 --- a/src/object/brain.h +++ b/src/object/brain.h @@ -31,7 +31,6 @@ #include "object/task/taskshield.h" -class CInstanceManager; class CObject; class CPhysics; class CMotion; @@ -80,7 +79,7 @@ struct TraceRecord class CBrain { public: - CBrain(CInstanceManager* iMan, CObject* object); + CBrain(CObject* object); ~CBrain(); void DeleteObject(bool bAll=false); @@ -167,7 +166,6 @@ protected: bool TraceRecordPut(char *buffer, int max, TraceOper oper, float param); protected: - CInstanceManager* m_iMan; Gfx::CEngine* m_engine; Gfx::CTerrain* m_terrain; Gfx::CWater* m_water; diff --git a/src/object/mainmovie.cpp b/src/object/mainmovie.cpp index 9aaf345..04c0d56 100644 --- a/src/object/mainmovie.cpp +++ b/src/object/mainmovie.cpp @@ -17,7 +17,7 @@ #include "object/mainmovie.h" -#include "common/iman.h" +#include "app/app.h" #include "math/geometry.h" @@ -30,15 +30,12 @@ // Constructor of the application card. -CMainMovie::CMainMovie(CInstanceManager* iMan) +CMainMovie::CMainMovie() { - m_iMan = iMan; - m_iMan->AddInstance(CLASS_SHORT, this); - - m_engine = static_cast< Gfx::CEngine* >(m_iMan->SearchInstance(CLASS_ENGINE)); - m_main = static_cast< CRobotMain* >(m_iMan->SearchInstance(CLASS_MAIN)); - m_camera = static_cast< Gfx::CCamera* >(m_iMan->SearchInstance(CLASS_CAMERA)); - m_sound = static_cast< CSoundInterface* >(m_iMan->SearchInstance(CLASS_SOUND)); + m_engine = Gfx::CEngine::GetInstancePointer(); + m_main = CRobotMain::GetInstancePointer(); + m_camera = m_main->GetCamera(); + m_sound = CApplication::GetInstancePointer()->GetSound(); Flush(); } diff --git a/src/object/mainmovie.h b/src/object/mainmovie.h index eba21eb..4554431 100644 --- a/src/object/mainmovie.h +++ b/src/object/mainmovie.h @@ -23,18 +23,17 @@ #include "common/event.h" + #include "math/vector.h" -class CInstanceManager; class CRobotMain; class CSoundInterface; -namespace Gfx -{ - class CCamera; - class CEngine; -}; +namespace Gfx { +class CCamera; +class CEngine; +} enum MainMovieType { @@ -48,7 +47,7 @@ enum MainMovieType class CMainMovie { public: - CMainMovie(CInstanceManager* iMan); + CMainMovie(); ~CMainMovie(); void Flush(); @@ -60,9 +59,6 @@ public: MainMovieType GetStopType(); protected: - -protected: - CInstanceManager* m_iMan; Gfx::CEngine* m_engine; CRobotMain* m_main; Gfx::CCamera* m_camera; diff --git a/src/object/motion/motion.cpp b/src/object/motion/motion.cpp index 605091f..00b3073 100644 --- a/src/object/motion/motion.cpp +++ b/src/object/motion/motion.cpp @@ -19,7 +19,7 @@ #include "app/app.h" -#include "common/iman.h" +#include "object/robotmain.h" #include "script/cmdtoken.h" @@ -30,20 +30,16 @@ // Object's constructor. -CMotion::CMotion(CInstanceManager* iMan, CObject* object) +CMotion::CMotion(CObject* object) { - m_iMan = iMan; - m_iMan->AddInstance(CLASS_MOTION, this, 100); - m_app = CApplication::GetInstancePointer(); - m_engine = static_cast< Gfx::CEngine* >(m_iMan->SearchInstance(CLASS_ENGINE)); - m_light = static_cast< Gfx::CLight* >(m_iMan->SearchInstance(CLASS_LIGHT)); - m_particle = static_cast< Gfx::CParticle* >(m_iMan->SearchInstance(CLASS_PARTICULE)); - m_terrain = static_cast< Gfx::CTerrain* >(m_iMan->SearchInstance(CLASS_TERRAIN)); - m_water = static_cast< Gfx::CWater* >(m_iMan->SearchInstance(CLASS_WATER)); - m_camera = static_cast< Gfx::CCamera* >(m_iMan->SearchInstance(CLASS_CAMERA)); - m_main = static_cast< CRobotMain* >(m_iMan->SearchInstance(CLASS_MAIN)); - m_sound = static_cast< CSoundInterface* >(m_iMan->SearchInstance(CLASS_SOUND)); + m_sound = m_app->GetSound(); + m_engine = Gfx::CEngine::GetInstancePointer(); + m_particle = m_engine->GetParticle(); + m_water = m_engine->GetWater(); + m_main = CRobotMain::GetInstancePointer(); + m_terrain = m_main->GetTerrain(); + m_camera = m_main->GetCamera(); m_object = object; m_physics = 0; @@ -62,7 +58,6 @@ CMotion::CMotion(CInstanceManager* iMan, CObject* object) CMotion::~CMotion() { - m_iMan->DeleteInstance(CLASS_MOTION, this); } // Deletes the object. diff --git a/src/object/motion/motion.h b/src/object/motion/motion.h index 81bcb08..d35ee67 100644 --- a/src/object/motion/motion.h +++ b/src/object/motion/motion.h @@ -27,14 +27,12 @@ namespace Gfx { class CEngine; -class CLight; class CParticle; class CTerrain; class CWater; class CCamera; } -class CInstanceManager; class CApplication; class CBrain; class CPhysics; @@ -46,7 +44,7 @@ class CSoundInterface; class CMotion { public: - CMotion(CInstanceManager* iMan, CObject* object); + CMotion(CObject* object); virtual ~CMotion(); void SetPhysics(CPhysics* physics); @@ -72,12 +70,8 @@ public: virtual Math::Vector GetInclinaison(); protected: - -protected: - CInstanceManager* m_iMan; CApplication* m_app; Gfx::CEngine* m_engine; - Gfx::CLight* m_light; Gfx::CParticle* m_particle; Gfx::CTerrain* m_terrain; Gfx::CWater* m_water; diff --git a/src/object/motion/motionant.cpp b/src/object/motion/motionant.cpp index db8ff37..384d683 100644 --- a/src/object/motion/motionant.cpp +++ b/src/object/motion/motionant.cpp @@ -35,8 +35,7 @@ const float START_TIME = 1000.0f; // beginning of the relative time // Object's constructor. -CMotionAnt::CMotionAnt(CInstanceManager* iMan, CObject* object) - : CMotion(iMan, object) +CMotionAnt::CMotionAnt(CObject* object) : CMotion(object) { m_armMember = START_TIME; m_armTimeAbs = START_TIME; diff --git a/src/object/motion/motionant.h b/src/object/motion/motionant.h index 68a3b7f..45d02b3 100644 --- a/src/object/motion/motionant.h +++ b/src/object/motion/motionant.h @@ -46,7 +46,7 @@ enum MotionAntSpecialAction class CMotionAnt : public CMotion { public: - CMotionAnt(CInstanceManager* iMan, CObject* object); + CMotionAnt(CObject* object); ~CMotionAnt(); void DeleteObject(bool bAll=false); diff --git a/src/object/motion/motionbee.cpp b/src/object/motion/motionbee.cpp index 111339d..8f69945 100644 --- a/src/object/motion/motionbee.cpp +++ b/src/object/motion/motionbee.cpp @@ -34,8 +34,7 @@ const float START_TIME = 1000.0f; // beginning of the relative time // Object's constructor. -CMotionBee::CMotionBee(CInstanceManager* iMan, CObject* object) - : CMotion(iMan, object) +CMotionBee::CMotionBee(CObject* object) : CMotion(object) { m_armMember = START_TIME; m_armTimeAbs = START_TIME; diff --git a/src/object/motion/motionbee.h b/src/object/motion/motionbee.h index aa8e5a6..c0347a0 100644 --- a/src/object/motion/motionbee.h +++ b/src/object/motion/motionbee.h @@ -40,7 +40,7 @@ enum MotionBeeSpecialAction class CMotionBee : public CMotion { public: - CMotionBee(CInstanceManager* iMan, CObject* object); + CMotionBee(CObject* object); ~CMotionBee(); void DeleteObject(bool bAll=false); diff --git a/src/object/motion/motionhuman.cpp b/src/object/motion/motionhuman.cpp index 5ff4af3..dc5ff34 100644 --- a/src/object/motion/motionhuman.cpp +++ b/src/object/motion/motionhuman.cpp @@ -43,8 +43,7 @@ const float START_TIME = 1000.0f; // beginning of the relative time // Object's constructor. -CMotionHuman::CMotionHuman(CInstanceManager* iMan, CObject* object) - : CMotion(iMan, object) +CMotionHuman::CMotionHuman(CObject* object) : CMotion(object) { m_partiReactor = -1; m_armMember = START_TIME; diff --git a/src/object/motion/motionhuman.h b/src/object/motion/motionhuman.h index b365a77..ddb0843 100644 --- a/src/object/motion/motionhuman.h +++ b/src/object/motion/motionhuman.h @@ -58,7 +58,7 @@ enum MotionHumanSpecialAction class CMotionHuman : public CMotion { public: - CMotionHuman(CInstanceManager* iMan, CObject* object); + CMotionHuman(CObject* object); ~CMotionHuman(); void DeleteObject(bool bAll=false); diff --git a/src/object/motion/motionmother.cpp b/src/object/motion/motionmother.cpp index ce1362f..573a2e4 100644 --- a/src/object/motion/motionmother.cpp +++ b/src/object/motion/motionmother.cpp @@ -34,8 +34,7 @@ const float START_TIME = 1000.0f; // beginning of the relative time // Object's constructor. -CMotionMother::CMotionMother(CInstanceManager* iMan, CObject* object) - : CMotion(iMan, object) +CMotionMother::CMotionMother(CObject* object) : CMotion(object) { m_armMember = START_TIME; m_armTimeAbs = START_TIME; diff --git a/src/object/motion/motionmother.h b/src/object/motion/motionmother.h index 5060315..a6c7e93 100644 --- a/src/object/motion/motionmother.h +++ b/src/object/motion/motionmother.h @@ -26,7 +26,7 @@ class CMotionMother : public CMotion { public: - CMotionMother(CInstanceManager* iMan, CObject* object); + CMotionMother(CObject* object); ~CMotionMother(); void DeleteObject(bool bAll=false); diff --git a/src/object/motion/motionspider.cpp b/src/object/motion/motionspider.cpp index 3ede492..59bc6e0 100644 --- a/src/object/motion/motionspider.cpp +++ b/src/object/motion/motionspider.cpp @@ -35,8 +35,7 @@ const float START_TIME = 1000.0f; // beginning of the relative time // Object's constructor. -CMotionSpider::CMotionSpider(CInstanceManager* iMan, CObject* object) - : CMotion(iMan, object) +CMotionSpider::CMotionSpider(CObject* object) : CMotion(object) { m_armMember = START_TIME; m_armTimeAbs = START_TIME; diff --git a/src/object/motion/motionspider.h b/src/object/motion/motionspider.h index fbf05f9..89745c4 100644 --- a/src/object/motion/motionspider.h +++ b/src/object/motion/motionspider.h @@ -44,7 +44,7 @@ enum MotionSpiderSpecialAction class CMotionSpider : public CMotion { public: - CMotionSpider(CInstanceManager* iMan, CObject* object); + CMotionSpider(CObject* object); ~CMotionSpider(); void DeleteObject(bool bAll=false); diff --git a/src/object/motion/motiontoto.cpp b/src/object/motion/motiontoto.cpp index 3a7f1ac..ddb1867 100644 --- a/src/object/motion/motiontoto.cpp +++ b/src/object/motion/motiontoto.cpp @@ -38,8 +38,7 @@ const float START_TIME = 1000.0f; // beginning of the relative time // Object's constructor. -CMotionToto::CMotionToto(CInstanceManager* iMan, CObject* object) - : CMotion(iMan, object) +CMotionToto::CMotionToto(CObject* object) : CMotion(object) { m_time = 0.0f; m_bDisplayInfo = false; diff --git a/src/object/motion/motiontoto.h b/src/object/motion/motiontoto.h index 4072b62..47baa28 100644 --- a/src/object/motion/motiontoto.h +++ b/src/object/motion/motiontoto.h @@ -35,7 +35,7 @@ enum MotionTotoAction class CMotionToto : public CMotion { public: - CMotionToto(CInstanceManager* iMan, CObject* object); + CMotionToto(CObject* object); ~CMotionToto(); void DeleteObject(bool bAll=false); diff --git a/src/object/motion/motionvehicle.cpp b/src/object/motion/motionvehicle.cpp index 3c95a27..44b8fdd 100644 --- a/src/object/motion/motionvehicle.cpp +++ b/src/object/motion/motionvehicle.cpp @@ -38,8 +38,7 @@ // Object's constructor. -CMotionVehicle::CMotionVehicle(CInstanceManager* iMan, CObject* object) - : CMotion(iMan, object) +CMotionVehicle::CMotionVehicle(CObject* object) : CMotion(object) { int i; @@ -926,7 +925,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, m_object->CreateEffectLight(20.0f, color); // Creates the battery. - pPower = new CObject(m_iMan); + pPower = new CObject(); pPower->SetType(power<=1.0f?OBJECT_POWER:OBJECT_ATOMIC); rank = m_engine->CreateObject(); diff --git a/src/object/motion/motionvehicle.h b/src/object/motion/motionvehicle.h index ca60c1e..ffb25ef 100644 --- a/src/object/motion/motionvehicle.h +++ b/src/object/motion/motionvehicle.h @@ -26,7 +26,7 @@ class CMotionVehicle : public CMotion { public: - CMotionVehicle(CInstanceManager* iMan, CObject* object); + CMotionVehicle(CObject* object); ~CMotionVehicle(); void DeleteObject(bool bAll=false); diff --git a/src/object/motion/motionworm.cpp b/src/object/motion/motionworm.cpp index f32765d..ee555a8 100644 --- a/src/object/motion/motionworm.cpp +++ b/src/object/motion/motionworm.cpp @@ -42,8 +42,7 @@ const int WORM_PART = 7; // number of parts of a worm // Object's constructor. -CMotionWorm::CMotionWorm(CInstanceManager* iMan, CObject* object) - : CMotion(iMan, object) +CMotionWorm::CMotionWorm(CObject* object) : CMotion(object) { m_timeUp = 18.0f; m_timeDown = 18.0f; diff --git a/src/object/motion/motionworm.h b/src/object/motion/motionworm.h index aed5a23..7684faf 100644 --- a/src/object/motion/motionworm.h +++ b/src/object/motion/motionworm.h @@ -26,7 +26,7 @@ class CMotionWorm : public CMotion { public: - CMotionWorm(CInstanceManager* iMan, CObject* object); + CMotionWorm(CObject* object); ~CMotionWorm(); void DeleteObject(bool bAll=false); diff --git a/src/object/object.cpp b/src/object/object.cpp index 317775d..8f2a4cc 100644 --- a/src/object/object.cpp +++ b/src/object/object.cpp @@ -209,28 +209,25 @@ void uObject(CBotVar* botThis, void* user) // Object's constructor. -CObject::CObject(CInstanceManager* iMan) +CObject::CObject() { - int i; - - m_iMan = iMan; - m_iMan->AddInstance(CLASS_OBJECT, this, 500); + CInstanceManager::GetInstancePointer()->AddInstance(CLASS_OBJECT, this, 500); m_app = CApplication::GetInstancePointer(); - m_engine = static_cast(m_iMan->SearchInstance(CLASS_ENGINE)); - m_lightMan = static_cast(m_iMan->SearchInstance(CLASS_LIGHT)); - m_terrain = static_cast(m_iMan->SearchInstance(CLASS_TERRAIN)); - m_water = static_cast(m_iMan->SearchInstance(CLASS_WATER)); - m_particle = static_cast(m_iMan->SearchInstance(CLASS_PARTICULE)); - m_camera = static_cast(m_iMan->SearchInstance(CLASS_CAMERA)); - m_displayText = static_cast(m_iMan->SearchInstance(CLASS_DISPLAYTEXT)); - m_main = static_cast(m_iMan->SearchInstance(CLASS_MAIN)); - m_sound = static_cast(m_iMan->SearchInstance(CLASS_SOUND)); - m_physics = 0; - m_brain = 0; - m_motion = 0; - m_auto = 0; - m_runScript = 0; + m_sound = m_app->GetSound(); + m_engine = Gfx::CEngine::GetInstancePointer(); + m_lightMan = m_engine->GetLightManager(); + m_water = m_engine->GetWater(); + m_particle = m_engine->GetParticle(); + m_main = CRobotMain::GetInstancePointer(); + m_terrain = m_main->GetTerrain(); + m_camera = m_main->GetCamera(); + m_displayText = m_main->GetDisplayText(); + m_physics = nullptr; + m_brain = nullptr; + m_motion = nullptr; + m_auto = nullptr; + m_runScript = nullptr; m_type = OBJECT_FIX; m_id = ++g_id; @@ -309,18 +306,18 @@ CObject::CObject(CInstanceManager* iMan) m_infoReturn = NAN; m_bInfoUpdate = false; - for ( i=0 ; iDeleteInstance(CLASS_OBJECT, this); + CInstanceManager::GetInstancePointer()->DeleteInstance(CLASS_OBJECT, this); m_app = nullptr; } @@ -376,7 +373,6 @@ void CObject::DeleteObject(bool bAll) { CObject* pObj; Gfx::CPyro* pPyro; - int i; if ( m_botVar != 0 ) { @@ -388,9 +384,11 @@ void CObject::DeleteObject(bool bAll) m_camera->SetControllingObject(0); } - for ( i=0 ; i<1000000 ; i++ ) + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + + for (int i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; pObj->DeleteDeselList(this); @@ -419,9 +417,9 @@ void CObject::DeleteObject(bool bAll) } } #endif - for ( i=0 ; i<1000000 ; i++ ) + for (int i=0 ; i<1000000 ; i++ ) { - pPyro = static_cast(m_iMan->SearchInstance(CLASS_PYRO, i)); + pPyro = static_cast(iMan->SearchInstance(CLASS_PYRO, i)); if ( pPyro == 0 ) break; pPyro->CutObjectLink(this); // the object no longer exists @@ -496,7 +494,7 @@ void CObject::DeleteObject(bool bAll) m_auto->DeleteObject(bAll); } - for ( i=0 ; iCreate(pyroType, this, loss); if ( shield == 0.0f ) // dead? @@ -2091,7 +2089,7 @@ bool CObject::CreateVehicle(Math::Vector pos, float angle, ObjectType type, if ( type == OBJECT_TOTO ) { - m_motion = new CMotionToto(m_iMan, this); + m_motion = new CMotionToto(this); m_motion->Create(pos, angle, type, 1.0f); return true; } @@ -2099,8 +2097,8 @@ bool CObject::CreateVehicle(Math::Vector pos, float angle, ObjectType type, SetTrainer(bTrainer); SetToy(bToy); - m_physics = new CPhysics(m_iMan, this); - m_brain = new CBrain(m_iMan, this); + m_physics = new CPhysics(this); + m_brain = new CBrain(this); m_physics->SetBrain(m_brain); m_brain->SetPhysics(m_physics); @@ -2137,11 +2135,11 @@ bool CObject::CreateVehicle(Math::Vector pos, float angle, ObjectType type, if ( type == OBJECT_HUMAN || type == OBJECT_TECH ) { - m_motion = new CMotionHuman(m_iMan, this); + m_motion = new CMotionHuman(this); } else { - m_motion = new CMotionVehicle(m_iMan, this); + m_motion = new CMotionVehicle(this); } if ( m_motion == 0 ) return false; @@ -2181,31 +2179,31 @@ bool CObject::CreateInsect(Math::Vector pos, float angle, ObjectType type) { m_type = type; - m_physics = new CPhysics(m_iMan, this); - m_brain = new CBrain(m_iMan, this); + m_physics = new CPhysics(this); + m_brain = new CBrain(this); m_physics->SetBrain(m_brain); m_brain->SetPhysics(m_physics); if ( type == OBJECT_MOTHER ) { - m_motion = new CMotionMother(m_iMan, this); + m_motion = new CMotionMother(this); } if ( type == OBJECT_ANT ) { - m_motion = new CMotionAnt(m_iMan, this); + m_motion = new CMotionAnt(this); } if ( type == OBJECT_SPIDER ) { - m_motion = new CMotionSpider(m_iMan, this); + m_motion = new CMotionSpider(this); } if ( type == OBJECT_BEE ) { - m_motion = new CMotionBee(m_iMan, this); + m_motion = new CMotionBee(this); } if ( type == OBJECT_WORM ) { - m_motion = new CMotionWorm(m_iMan, this); + m_motion = new CMotionWorm(this); } if ( m_motion == 0 ) return false; @@ -3139,7 +3137,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, { CObject* pPower; - pPower = new CObject(m_iMan); + pPower = new CObject(); pPower->SetType(power<=1.0f?OBJECT_POWER:OBJECT_ATOMIC); rank = m_engine->CreateObject(); @@ -5467,91 +5465,91 @@ void CObject::CreateOtherObject(ObjectType type) { if ( type == OBJECT_BASE ) { - m_auto = new CAutoBase(m_iMan, this); + m_auto = new CAutoBase(this); } if ( type == OBJECT_PORTICO ) { - m_auto = new CAutoPortico(m_iMan, this); + m_auto = new CAutoPortico(this); } if ( type == OBJECT_DERRICK ) { - m_auto = new CAutoDerrick(m_iMan, this); + m_auto = new CAutoDerrick(this); } if ( type == OBJECT_FACTORY ) { - m_auto = new CAutoFactory(m_iMan, this); + m_auto = new CAutoFactory(this); } if ( type == OBJECT_REPAIR ) { - m_auto = new CAutoRepair(m_iMan, this); + m_auto = new CAutoRepair(this); } if ( type == OBJECT_DESTROYER ) { - m_auto = new CAutoDestroyer(m_iMan, this); + m_auto = new CAutoDestroyer(this); } if ( type == OBJECT_STATION ) { - m_auto = new CAutoStation(m_iMan, this); + m_auto = new CAutoStation(this); } if ( type == OBJECT_CONVERT ) { - m_auto = new CAutoConvert(m_iMan, this); + m_auto = new CAutoConvert(this); } if ( type == OBJECT_TOWER ) { - m_auto = new CAutoTower(m_iMan, this); + m_auto = new CAutoTower(this); } if ( type == OBJECT_RESEARCH ) { - m_auto = new CAutoResearch(m_iMan, this); + m_auto = new CAutoResearch(this); } if ( type == OBJECT_RADAR ) { - m_auto = new CAutoRadar(m_iMan, this); + m_auto = new CAutoRadar(this); } if ( type == OBJECT_INFO ) { - m_auto = new CAutoInfo(m_iMan, this); + m_auto = new CAutoInfo(this); } if ( type == OBJECT_ENERGY ) { - m_auto = new CAutoEnergy(m_iMan, this); + m_auto = new CAutoEnergy(this); } if ( type == OBJECT_LABO ) { - m_auto = new CAutoLabo(m_iMan, this); + m_auto = new CAutoLabo(this); } if ( type == OBJECT_NUCLEAR ) { - m_auto = new CAutoNuclear(m_iMan, this); + m_auto = new CAutoNuclear(this); } if ( type == OBJECT_PARA ) { - m_auto = new CAutoPara(m_iMan, this); + m_auto = new CAutoPara(this); } if ( type == OBJECT_SAFE ) { - m_auto = new CAutoSafe(m_iMan, this); + m_auto = new CAutoSafe(this); } if ( type == OBJECT_HUSTON ) { - m_auto = new CAutoHuston(m_iMan, this); + m_auto = new CAutoHuston(this); } if ( type == OBJECT_EGG ) { - m_auto = new CAutoEgg(m_iMan, this); + m_auto = new CAutoEgg(this); } if ( type == OBJECT_NEST ) { - m_auto = new CAutoNest(m_iMan, this); + m_auto = new CAutoNest(this); } if ( type == OBJECT_ROOT5 ) { - m_auto = new CAutoRoot(m_iMan, this); + m_auto = new CAutoRoot(this); } if ( type == OBJECT_MUSHROOM2 ) { - m_auto = new CAutoMush(m_iMan, this); + m_auto = new CAutoMush(this); } if ( type == OBJECT_FLAGb || type == OBJECT_FLAGr || @@ -5559,13 +5557,13 @@ void CObject::CreateOtherObject(ObjectType type) type == OBJECT_FLAGy || type == OBJECT_FLAGv ) { - m_auto = new CAutoFlag(m_iMan, this); + m_auto = new CAutoFlag(this); } if ( type == OBJECT_TEEN36 || // trunk? type == OBJECT_TEEN37 || // boat? type == OBJECT_TEEN38 ) // fan? { - m_auto = new CAutoKid(m_iMan, this); + m_auto = new CAutoKid(this); } } @@ -5979,7 +5977,7 @@ bool CObject::EventFrame(const Event &event) m_bProxyActivate = false; m_main->CreateShortcuts(); m_sound->Play(SOUND_FINDING); - pyro = new Gfx::CPyro(m_iMan); + pyro = new Gfx::CPyro(); pyro->Create(Gfx::PT_FINDING, this, 0.0f); m_displayText->DisplayError(INFO_FINDING, this); } @@ -6453,7 +6451,7 @@ bool CObject::JostleObject(float force) { if ( m_auto != 0 ) return false; - m_auto = new CAutoJostle(m_iMan, this); + m_auto = new CAutoJostle(this); pa = static_cast(m_auto); pa->Start(0, force); } diff --git a/src/object/object.h b/src/object/object.h index 8d8baca..4d8cc02 100644 --- a/src/object/object.h +++ b/src/object/object.h @@ -28,7 +28,6 @@ #include "sound/sound.h" -class CInstanceManager; class CApplication; class CPhysics; class CBrain; @@ -39,8 +38,7 @@ class CRobotMain; class CBotVar; class CScript; -namespace Ui -{ +namespace Ui { class CDisplayText; } @@ -377,7 +375,7 @@ enum RadarFilter class CObject { public: - CObject(CInstanceManager* iMan); + CObject(); ~CObject(); void DeleteObject(bool bAll=false); @@ -679,7 +677,6 @@ protected: void UpdateSelectParticle(); protected: - CInstanceManager* m_iMan; CApplication* m_app; Gfx::CEngine* m_engine; Gfx::CLightManager* m_lightMan; diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index ca13efc..6efd853 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -80,7 +80,7 @@ #include "ui/window.h" -template<> CRobotMain* CSingleton::mInstance = nullptr; +template<> CRobotMain* CSingleton::m_instance = nullptr; // TODO: remove once using std::string @@ -606,29 +606,27 @@ bool rPoint(CBotVar* pThis, CBotVar* var, CBotVar* pResult, int& Exception) //! Constructor of robot application -CRobotMain::CRobotMain(CInstanceManager* iMan, CApplication* app) +CRobotMain::CRobotMain(CApplication* app) { - m_iMan = iMan; - m_iMan->AddInstance(CLASS_MAIN, this); - m_app = app; - m_eventQueue = static_cast(m_iMan->SearchInstance(CLASS_EVENT)); - m_engine = static_cast(m_iMan->SearchInstance(CLASS_ENGINE)); - m_lightMan = static_cast(m_iMan->SearchInstance(CLASS_LIGHT)); - m_particle = static_cast(m_iMan->SearchInstance(CLASS_PARTICULE)); - m_water = static_cast(m_iMan->SearchInstance(CLASS_WATER)); - m_cloud = static_cast(m_iMan->SearchInstance(CLASS_CLOUD)); - m_lightning = static_cast(m_iMan->SearchInstance(CLASS_BLITZ)); - m_planet = static_cast(m_iMan->SearchInstance(CLASS_PLANET)); - m_sound = static_cast(m_iMan->SearchInstance(CLASS_SOUND)); + m_eventQueue = m_app->GetEventQueue(); + m_sound = m_app->GetSound(); + + m_engine = Gfx::CEngine::GetInstancePointer(); + m_lightMan = m_engine->GetLightManager(); + m_particle = m_engine->GetParticle(); + m_water = m_engine->GetWater(); + m_cloud = m_engine->GetCloud(); + m_lightning = m_engine->GetLightning(); + m_planet = m_engine->GetPlanet(); m_interface = new Ui::CInterface(); - m_terrain = new Gfx::CTerrain(m_iMan); - m_camera = new Gfx::CCamera(m_iMan); + m_terrain = new Gfx::CTerrain(); + m_camera = new Gfx::CCamera(); m_displayText = new Ui::CDisplayText(); - m_movie = new CMainMovie(m_iMan); - m_dialog = new Ui::CMainDialog(m_iMan); + m_movie = new CMainMovie(); + m_dialog = new Ui::CMainDialog(); m_short = new Ui::CMainShort(); m_map = new Ui::CMainMap(); m_displayInfo = nullptr; @@ -857,10 +855,29 @@ CRobotMain::~CRobotMain() delete m_map; m_map = nullptr; - m_iMan = nullptr; m_app = nullptr; } +Gfx::CCamera* CRobotMain::GetCamera() +{ + return m_camera; +} + +Gfx::CTerrain* CRobotMain::GetTerrain() +{ + return m_terrain; +} + +Ui::CInterface* CRobotMain::GetInterface() +{ + return m_interface; +} + +Ui::CDisplayText* CRobotMain::GetDisplayText() +{ + return m_displayText; +} + //! Creates the file colobot.ini at the first time void CRobotMain::CreateIni() @@ -1027,10 +1044,6 @@ void CRobotMain::ChangePhase(Phase phase) m_cloud->Flush(); m_lightning->Flush(); m_planet->Flush(); - m_iMan->Flush(CLASS_OBJECT); - m_iMan->Flush(CLASS_PHYSICS); - m_iMan->Flush(CLASS_BRAIN); - m_iMan->Flush(CLASS_PYRO); m_interface->Flush(); ClearInterface(); FlushNewScriptName(); @@ -1042,6 +1055,12 @@ void CRobotMain::ChangePhase(Phase phase) m_cameraZoom = 0.0f; m_shortCut = true; + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + iMan->Flush(CLASS_OBJECT); + iMan->Flush(CLASS_PHYSICS); + iMan->Flush(CLASS_BRAIN); + iMan->Flush(CLASS_PYRO); + Math::Point dim, pos; // Creates and hide the command console. @@ -2392,10 +2411,11 @@ CObject* CRobotMain::GetSelectObject() //! Deselects everything, and returns the object that was selected CObject* CRobotMain::DeselectAll() { + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); CObject* prev = nullptr; for (int i = 0; i < 1000000; i++) { - CObject* obj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + CObject* obj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if (obj == nullptr) break; if (obj->GetSelect()) prev = obj; @@ -2503,10 +2523,12 @@ bool CRobotMain::DeselectObject() //! Quickly removes all objects void CRobotMain::DeleteAllObjects() { + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + // Removes all pyrotechnic effects in progress. while (true) { - Gfx::CPyro* pyro = static_cast(m_iMan->SearchInstance(CLASS_PYRO, 0)); + Gfx::CPyro* pyro = static_cast(iMan->SearchInstance(CLASS_PYRO, 0)); if (pyro == nullptr) break; pyro->DeleteObject(); @@ -2526,7 +2548,7 @@ void CRobotMain::DeleteAllObjects() while (true) { - CObject* obj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, 0)); + CObject* obj = static_cast(iMan->SearchInstance(CLASS_OBJECT, 0)); if (obj == nullptr) break; obj->DeleteObject(true); // destroys rapidly @@ -2543,9 +2565,10 @@ void CRobotMain::SelectHuman() //! Returns the object human CObject* CRobotMain::SearchHuman() { + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); for (int i = 0; i < 1000000; i++) { - CObject* obj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + CObject* obj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if (obj == 0) break; ObjectType type = obj->GetType(); @@ -2558,9 +2581,10 @@ CObject* CRobotMain::SearchHuman() //! Returns the object toto CObject* CRobotMain::SearchToto() { + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); for (int i = 0; i < 1000000; i++) { - CObject* obj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + CObject* obj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if (obj == nullptr) break; ObjectType type = obj->GetType(); @@ -2573,11 +2597,12 @@ CObject* CRobotMain::SearchToto() //! Returns the nearest selectable object from a given position CObject* CRobotMain::SearchNearest(Math::Vector pos, CObject* exclu) { + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); float min = 100000.0f; CObject* best = 0; for (int i = 0; i < 1000000; i++) { - CObject* obj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + CObject* obj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if (obj == nullptr) break; if (obj == exclu) continue; @@ -2600,9 +2625,10 @@ CObject* CRobotMain::SearchNearest(Math::Vector pos, CObject* exclu) //! Returns the selected object CObject* CRobotMain::GetSelect() { + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); for (int i = 0; i < 1000000; i++) { - CObject* obj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + CObject* obj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if (obj == nullptr) break; if (obj->GetSelect()) @@ -2613,9 +2639,10 @@ CObject* CRobotMain::GetSelect() CObject* CRobotMain::SearchObject(ObjectType type) { + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); for (int i = 0; i < 1000000; i++) { - CObject* obj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + CObject* obj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if (obj == nullptr) break; if (obj->GetType() == type) @@ -2628,10 +2655,11 @@ CObject* CRobotMain::SearchObject(ObjectType type) CObject* CRobotMain::DetectObject(Math::Point pos) { int objRank = m_engine->DetectObject(pos); + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); for (int i = 0; i < 1000000; i++) { - CObject* obj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + CObject* obj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if (obj == nullptr) break; if (!obj->GetActif()) continue; @@ -2850,7 +2878,7 @@ bool CRobotMain::DeleteObject() CObject* obj = GetSelect(); if (obj == nullptr) return false; - Gfx::CPyro* pyro = new Gfx::CPyro(m_iMan); + Gfx::CPyro* pyro = new Gfx::CPyro(); pyro->Create(Gfx::PT_FRAGT, obj); obj->SetSelect(false); // deselects the object @@ -2873,9 +2901,11 @@ void CRobotMain::HiliteClear() int rank = -1; m_engine->SetHighlightRank(&rank); // nothing more selected + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + for (int i = 0; i < 1000000; i++) { - CObject* obj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + CObject* obj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if (obj == nullptr) break; obj->SetHilite(false); @@ -3035,9 +3065,11 @@ void CRobotMain::HelpObject() //! Change the mode of the camera void CRobotMain::ChangeCamera() { + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + for (int i = 0; i < 1000000; i++) { - CObject* obj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + CObject* obj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if (obj == nullptr) break; if (obj->GetSelect()) @@ -3191,9 +3223,11 @@ void CRobotMain::RemoteCamera(float pan, float zoom, float rTime) //! Cancels the current movie void CRobotMain::AbortMovie() { + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + for (int i = 0; i < 1000000; i++) { - CObject* obj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + CObject* obj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if (obj == nullptr) break; CAuto* automat = obj->GetAuto(); @@ -3261,13 +3295,15 @@ bool CRobotMain::EventFrame(const Event &event) if (pm != nullptr) pm->FlushObject(); } + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + CObject* toto = nullptr; if (!m_freePhoto) { // Advances all the robots, but not toto. for (int i = 0; i < 1000000; i++) { - CObject* obj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + CObject* obj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if (obj == nullptr) break; if (pm != nullptr) pm->UpdateObject(obj); if (obj->GetTruck() != nullptr) continue; @@ -3280,7 +3316,7 @@ bool CRobotMain::EventFrame(const Event &event) // Advances all objects transported by robots. for (int i = 0; i < 1000000; i++) { - CObject* obj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + CObject* obj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if (obj == nullptr) break; if (obj->GetTruck() == nullptr) continue; obj->EventProcess(event); @@ -3289,7 +3325,7 @@ bool CRobotMain::EventFrame(const Event &event) // Advances pyrotechnic effects. for (int i = 0; i < 1000000; i++) { - Gfx::CPyro* pyro = static_cast(m_iMan->SearchInstance(CLASS_PYRO, i)); + Gfx::CPyro* pyro = static_cast(iMan->SearchInstance(CLASS_PYRO, i)); if (pyro == nullptr) break; pyro->EventProcess(event); @@ -3439,9 +3475,11 @@ bool CRobotMain::EventObject(const Event &event) m_resetCreate = false; + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + for (int i = 0; i < 1000000; i++) { - CObject* obj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + CObject* obj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if (obj == nullptr) break; obj->EventProcess(event); @@ -3679,10 +3717,12 @@ void CRobotMain::ScenePerso() m_terrain->FlushFlyingLimit(); m_lightMan->FlushLights(); m_particle->FlushParticle(); - m_iMan->Flush(CLASS_OBJECT); - m_iMan->Flush(CLASS_PHYSICS); - m_iMan->Flush(CLASS_BRAIN); - m_iMan->Flush(CLASS_PYRO); + + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + iMan->Flush(CLASS_OBJECT); + iMan->Flush(CLASS_PHYSICS); + iMan->Flush(CLASS_BRAIN); + iMan->Flush(CLASS_PYRO); m_dialog->SetSceneName("perso"); m_dialog->SetSceneRank(0); @@ -4155,7 +4195,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) Gfx::PyroType pType = OpPyro(line, "pyro"); if (pType != Gfx::PT_NULL) { - Gfx::CPyro* pyro = new Gfx::CPyro(m_iMan); + Gfx::CPyro* pyro = new Gfx::CPyro(); pyro->Create(pType, obj); } @@ -4572,7 +4612,7 @@ CObject* CRobotMain::CreateObject(Math::Vector pos, float angle, float zoom, flo type == OBJECT_START || type == OBJECT_END ) { - object = new CObject(m_iMan); + object = new CObject(); object->CreateBuilding(pos, angle, height, type, power); CAuto* automat = object->GetAuto(); @@ -4614,7 +4654,7 @@ CObject* CRobotMain::CreateObject(Math::Vector pos, float angle, float zoom, flo type == OBJECT_MARKKEYd || type == OBJECT_EGG ) { - object = new CObject(m_iMan); + object = new CObject(); object->CreateResource(pos, angle, type, power); } else @@ -4624,7 +4664,7 @@ CObject* CRobotMain::CreateObject(Math::Vector pos, float angle, float zoom, flo type == OBJECT_FLAGy || type == OBJECT_FLAGv ) { - object = new CObject(m_iMan); + object = new CObject(); object->CreateFlag(pos, angle, type); } else @@ -4634,7 +4674,7 @@ CObject* CRobotMain::CreateObject(Math::Vector pos, float angle, float zoom, flo type == OBJECT_BARRIER3 || type == OBJECT_BARRIER4 ) { - object = new CObject(m_iMan); + object = new CObject(); object->CreateBarrier(pos, angle, height, type); } else @@ -4669,7 +4709,7 @@ CObject* CRobotMain::CreateObject(Math::Vector pos, float angle, float zoom, flo type == OBJECT_TREE8 || type == OBJECT_TREE9 ) { - object = new CObject(m_iMan); + object = new CObject(); object->CreatePlant(pos, angle, height, type); } else @@ -4684,7 +4724,7 @@ CObject* CRobotMain::CreateObject(Math::Vector pos, float angle, float zoom, flo type == OBJECT_MUSHROOM8 || type == OBJECT_MUSHROOM9 ) { - object = new CObject(m_iMan); + object = new CObject(); object->CreateMushroom(pos, angle, height, type); } else @@ -4739,7 +4779,7 @@ CObject* CRobotMain::CreateObject(Math::Vector pos, float angle, float zoom, flo type == OBJECT_TEEN48 || type == OBJECT_TEEN49 ) { - object = new CObject(m_iMan); + object = new CObject(); object->SetOption(option); object->CreateTeen(pos, angle, zoom, height, type); } @@ -4755,7 +4795,7 @@ CObject* CRobotMain::CreateObject(Math::Vector pos, float angle, float zoom, flo type == OBJECT_QUARTZ8 || type == OBJECT_QUARTZ9 ) { - object = new CObject(m_iMan); + object = new CObject(); object->CreateQuartz(pos, angle, height, type); } else @@ -4770,13 +4810,13 @@ CObject* CRobotMain::CreateObject(Math::Vector pos, float angle, float zoom, flo type == OBJECT_ROOT8 || type == OBJECT_ROOT9 ) { - object = new CObject(m_iMan); + object = new CObject(); object->CreateRoot(pos, angle, height, type); } else if ( type == OBJECT_HOME1 ) { - object = new CObject(m_iMan); + object = new CObject(); object->CreateHome(pos, angle, height, type); } else @@ -4794,7 +4834,7 @@ CObject* CRobotMain::CreateObject(Math::Vector pos, float angle, float zoom, flo type == OBJECT_RUINbase || type == OBJECT_RUINhead ) { - object = new CObject(m_iMan); + object = new CObject(); object->CreateRuin(pos, angle, height, type); } else @@ -4803,7 +4843,7 @@ CObject* CRobotMain::CreateObject(Math::Vector pos, float angle, float zoom, flo type == OBJECT_APOLLO4 || type == OBJECT_APOLLO5 ) { - object = new CObject(m_iMan); + object = new CObject(); object->CreateApollo(pos, angle, type); } else @@ -4813,7 +4853,7 @@ CObject* CRobotMain::CreateObject(Math::Vector pos, float angle, float zoom, flo type == OBJECT_BEE || type == OBJECT_WORM ) { - object = new CObject(m_iMan); + object = new CObject(); object->CreateInsect(pos, angle, type); // no eggs } else @@ -4849,7 +4889,7 @@ CObject* CRobotMain::CreateObject(Math::Vector pos, float angle, float zoom, flo type == OBJECT_MOBILEdr || type == OBJECT_APOLLO2 ) { - object = new CObject(m_iMan); + object = new CObject(); object->SetOption(option); object->CreateVehicle(pos, angle, type, power, trainer, toy); } @@ -5069,10 +5109,12 @@ bool CRobotMain::TestGadgetQuantity(int rank) //! Calculates the distance to the nearest object float CRobotMain::SearchNearestObject(Math::Vector center, CObject *exclu) { + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + float min = 100000.0f; for (int i = 0; i < 1000000; i++) { - CObject* obj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + CObject* obj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if (obj == nullptr) break; if (!obj->GetActif()) continue; // inactive? @@ -5218,12 +5260,14 @@ void CRobotMain::ShowDropZone(CObject* metal, CObject* truck) Math::Vector center = metal->GetPosition(0); + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + // Calculates the maximum radius possible depending on other items. float oMax = 30.0f; // radius to build the biggest building float tMax; for (int i = 0; i < 1000000; i++) { - CObject* obj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + CObject* obj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if (obj == nullptr) break; if (!obj->GetActif()) continue; // inactive? @@ -5441,13 +5485,15 @@ void CRobotMain::CompileScript(bool soluce) int nbError = 0; int lastError = 0; + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + do { lastError = nbError; nbError = 0; for (int i = 0; i < 1000000; i++) { - CObject* obj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + CObject* obj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if (obj == nullptr) break; if (obj->GetTruck() != nullptr) continue; @@ -5476,7 +5522,7 @@ void CRobotMain::CompileScript(bool soluce) { for (int i = 0; i < 1000000; i++) { - CObject* obj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + CObject* obj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if (obj == 0) break; if (obj->GetTruck() != 0) continue; @@ -5494,7 +5540,7 @@ void CRobotMain::CompileScript(bool soluce) // Start all programs according to the command "run". for (int i = 0; i < 1000000; i++) { - CObject* obj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + CObject* obj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if (obj == nullptr) break; if (obj->GetTruck() != nullptr) continue; @@ -5569,9 +5615,11 @@ void CRobotMain::LoadFileScript(CObject *obj, const char* filename, int objRank, //! Saves all programs of all the robots void CRobotMain::SaveAllScript() { + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + for (int i = 0; i < 1000000; i++) { - CObject* obj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + CObject* obj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if (obj == nullptr) break; SaveOneScript(obj); @@ -5706,9 +5754,11 @@ bool CRobotMain::IsBusy() { if (m_CompteurFileOpen > 0) return true; + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + for (int i = 0; i < 1000000; i++) { - CObject* obj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + CObject* obj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if (obj == nullptr) break; CBrain* brain = obj->GetBrain(); @@ -5851,10 +5901,12 @@ bool CRobotMain::IOWriteScene(const char *filename, const char *filecbot, char * fputs(line, file); } + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + int objRank = 0; for (int i = 0; i < 1000000; i++) { - CObject* obj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + CObject* obj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if (obj == nullptr) break; if (obj->GetType() == OBJECT_TOTO) continue; @@ -5892,7 +5944,7 @@ bool CRobotMain::IOWriteScene(const char *filename, const char *filecbot, char * objRank = 0; for (int i = 0; i < 1000000; i++) { - CObject* obj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + CObject* obj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if (obj == nullptr) break; if (obj->GetType() == OBJECT_TOTO) continue; @@ -6047,7 +6099,7 @@ CObject* CRobotMain::IOReadScene(const char *filename, const char *filecbot) if (fret != nullptr) { obj->SetFret(fret); - CTaskManip* task = new CTaskManip(m_iMan, obj); + CTaskManip* task = new CTaskManip(obj); task->Start(TMO_AUTO, TMA_GRAB); // holds the object! delete task; } @@ -6065,6 +6117,8 @@ CObject* CRobotMain::IOReadScene(const char *filename, const char *filecbot) fclose(file); #if CBOT_STACK + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + // Compiles scripts. int nbError = 0; int lastError = 0; @@ -6074,7 +6128,7 @@ CObject* CRobotMain::IOReadScene(const char *filename, const char *filecbot) nbError = 0; for (int i = 0; i < 1000000; i++) { - CObject* obj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + CObject* obj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if (obj == nullptr) break; if (obj->GetTruck() != nullptr) continue; @@ -6100,7 +6154,7 @@ CObject* CRobotMain::IOReadScene(const char *filename, const char *filecbot) objRank = 0; for (int i = 0; i < 1000000; i++) { - CObject* obj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + CObject* obj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if (obj == nullptr) break; if (obj->GetType() == OBJECT_TOTO) continue; @@ -6176,10 +6230,12 @@ void CRobotMain::ResetObject() Math::Vector pos, angle; int i; + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + // Removes all pyrotechnic effects in progress. while ( true ) { - pyro = static_cast(m_iMan->SearchInstance(CLASS_PYRO, 0)); + pyro = static_cast(iMan->SearchInstance(CLASS_PYRO, 0)); if ( pyro == 0 ) break; pyro->DeleteObject(); @@ -6194,7 +6250,7 @@ void CRobotMain::ResetObject() for ( i=0 ; i<1000000 ; i++ ) { - obj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + obj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( obj == 0 ) break; cap = obj->GetResetCap(); @@ -6243,7 +6299,7 @@ void CRobotMain::ResetObject() if ( pos == obj->GetPosition(0) && angle == obj->GetAngle(0) ) continue; - pyro = new CPyro(m_iMan); + pyro = new CPyro(); pyro->Create(PT_RESET, obj); brain = obj->GetBrain(); @@ -6273,10 +6329,13 @@ void CRobotMain::ResetCreate() m_particle->FlushParticle(); m_terrain->FlushBuildingLevel(); - m_iMan->Flush(CLASS_OBJECT); - m_iMan->Flush(CLASS_PHYSICS); - m_iMan->Flush(CLASS_BRAIN); - m_iMan->Flush(CLASS_PYRO); + + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + iMan->Flush(CLASS_OBJECT); + iMan->Flush(CLASS_PHYSICS); + iMan->Flush(CLASS_BRAIN); + iMan->Flush(CLASS_PYRO); + m_camera->SetType(Gfx::CAM_TYPE_DIALOG); CreateScene(m_dialog->GetSceneSoluce(), false, true); @@ -6285,13 +6344,13 @@ void CRobotMain::ResetCreate() for (int i = 0; i < 1000000; i++) { - CObject* obj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + CObject* obj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if (obj == nullptr) break; ResetCap cap = obj->GetResetCap(); if (cap == RESET_NONE) continue; - Gfx::CPyro* pyro = new Gfx::CPyro(m_iMan); + Gfx::CPyro* pyro = new Gfx::CPyro(); pyro->Create(Gfx::PT_RESET, obj); } } @@ -6299,6 +6358,8 @@ void CRobotMain::ResetCreate() //! Checks if the mission is over Error CRobotMain::CheckEndMission(bool frame) { + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + for (int t = 0; t < m_endTakeTotal; t++) { if (m_endTake[t].message[0] != 0) continue; @@ -6311,7 +6372,7 @@ Error CRobotMain::CheckEndMission(bool frame) int nb = 0; for (int i = 0; i < 1000000; i++) { - CObject* obj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + CObject* obj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if (obj == nullptr) break; // Do not use GetActif () because an invisible worm (underground) @@ -6545,9 +6606,11 @@ bool CRobotMain::GetRadar() if (m_cheatRadar) return true; + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + for (int i = 0; i < 1000000; i++) { - CObject* obj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + CObject* obj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if (obj == 0) break; ObjectType type = obj->GetType(); diff --git a/src/object/robotmain.h b/src/object/robotmain.h index cb0cd7f..6a45473 100644 --- a/src/object/robotmain.h +++ b/src/object/robotmain.h @@ -71,12 +71,10 @@ enum Phase }; -class CInstanceManager; class CEventQueue; class CSoundInterface; -namespace Gfx -{ +namespace Gfx { class CEngine; class CLightManager; class CWater; @@ -84,17 +82,16 @@ class CCloud; class CLightning; class CPlanet; class CTerrain; -}; +} -namespace Ui -{ +namespace Ui { class CMainDialog; class CMainShort; class CMainMap; class CInterface; class CDisplayText; class CDisplayInfo; -}; +} struct EndTake @@ -178,9 +175,14 @@ const int AXIS_INVALID = -1; class CRobotMain : public CSingleton { public: - CRobotMain(CInstanceManager* iMan, CApplication* app); + CRobotMain(CApplication* app); ~CRobotMain(); + Gfx::CCamera* GetCamera(); + Gfx::CTerrain* GetTerrain(); + Ui::CInterface* GetInterface(); + Ui::CDisplayText* GetDisplayText(); + void CreateIni(); //! Sets the default input bindings (key and axes) @@ -358,7 +360,6 @@ protected: void Convert(); void CreateScene(bool soluce, bool fixScene, bool resetObject); - void CreateModel(); Math::Vector LookatPoint(Math::Vector eye, float angleH, float angleV, float length); CObject* CreateObject(Math::Vector pos, float angle, float zoom, float height, ObjectType type, float power=1.0f, @@ -390,7 +391,6 @@ protected: void UpdateSpeedLabel(); protected: - CInstanceManager* m_iMan; CApplication* m_app; CEventQueue* m_eventQueue; CMainMovie* m_movie; diff --git a/src/object/task/task.cpp b/src/object/task/task.cpp index b310fd5..39fdccf 100644 --- a/src/object/task/task.cpp +++ b/src/object/task/task.cpp @@ -14,33 +14,28 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// task.cpp - - -// #include #include "object/task/task.h" -#include "common/iman.h" -#include "object/object.h" +#include "app/app.h" +#include "object/object.h" +#include "object/robotmain.h" // Object's constructor. -CTask::CTask(CInstanceManager* iMan, CObject* object) +CTask::CTask(CObject* object) { - m_iMan = iMan; - - m_engine = static_cast(m_iMan->SearchInstance(CLASS_ENGINE)); - m_lightMan = static_cast(m_iMan->SearchInstance(CLASS_LIGHT)); - m_terrain = static_cast(m_iMan->SearchInstance(CLASS_TERRAIN)); - m_water = static_cast(m_iMan->SearchInstance(CLASS_WATER)); - m_particle = static_cast(m_iMan->SearchInstance(CLASS_PARTICULE)); - m_camera = static_cast(m_iMan->SearchInstance(CLASS_CAMERA)); - m_displayText = static_cast(m_iMan->SearchInstance(CLASS_DISPLAYTEXT)); - m_main = static_cast(m_iMan->SearchInstance(CLASS_MAIN)); - m_sound = static_cast(m_iMan->SearchInstance(CLASS_SOUND)); + m_sound = CApplication::GetInstancePointer()->GetSound(); + m_engine = Gfx::CEngine::GetInstancePointer(); + m_lightMan = m_engine->GetLightManager(); + m_water = m_engine->GetWater(); + m_particle = m_engine->GetParticle(); + m_main = CRobotMain::GetInstancePointer(); + m_terrain = m_main->GetTerrain(); + m_camera = m_main->GetCamera(); + m_displayText = m_main->GetDisplayText(); m_object = object; m_physics = m_object->GetPhysics(); diff --git a/src/object/task/task.h b/src/object/task/task.h index 7239d48..12961ef 100644 --- a/src/object/task/task.h +++ b/src/object/task/task.h @@ -21,10 +21,10 @@ #include "common/event.h" #include "common/global.h" + #include "math/const.h" -class CInstanceManager; class CBrain; class CPhysics; class CMotion; @@ -64,7 +64,7 @@ const float ARM_STOCK_ANGLE3 = -70.0f*Math::PI/180.0f; class CTask { public: - CTask(CInstanceManager* iMan, CObject* object); + CTask(CObject* object); virtual ~CTask(); virtual bool EventProcess(const Event &event); @@ -73,7 +73,6 @@ public: virtual bool Abort(); protected: - CInstanceManager* m_iMan; Gfx::CEngine* m_engine; Gfx::CLightManager* m_lightMan; Gfx::CParticle* m_particle; diff --git a/src/object/task/taskadvance.cpp b/src/object/task/taskadvance.cpp index 0d159d2..58eb939 100644 --- a/src/object/task/taskadvance.cpp +++ b/src/object/task/taskadvance.cpp @@ -14,11 +14,11 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// taskadvance.cpp #include "object/task/taskadvance.h" #include "math/geometry.h" + #include "physics/physics.h" @@ -26,8 +26,7 @@ // Object's constructor. -CTaskAdvance::CTaskAdvance(CInstanceManager* iMan, CObject* object) - : CTask(iMan, object) +CTaskAdvance::CTaskAdvance(CObject* object) : CTask(object) { } diff --git a/src/object/task/taskadvance.h b/src/object/task/taskadvance.h index dbb80d9..f8c672d 100644 --- a/src/object/task/taskadvance.h +++ b/src/object/task/taskadvance.h @@ -20,6 +20,7 @@ #include "object/task/task.h" + #include "math/vector.h" @@ -27,7 +28,7 @@ class CTaskAdvance : public CTask { public: - CTaskAdvance(CInstanceManager* iMan, CObject* object); + CTaskAdvance(CObject* object); ~CTaskAdvance(); bool EventProcess(const Event &event); diff --git a/src/object/task/taskbuild.cpp b/src/object/task/taskbuild.cpp index 5673ea4..f209cd5 100644 --- a/src/object/task/taskbuild.cpp +++ b/src/object/task/taskbuild.cpp @@ -14,29 +14,32 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// taskbuild.cpp #include "object/task/taskbuild.h" #include "common/iman.h" + #include "graphics/core/color.h" #include "graphics/core/light.h" #include "graphics/engine/lightman.h" #include "graphics/engine/terrain.h" #include "graphics/engine/water.h" + #include "math/geometry.h" + #include "object/auto/auto.h" #include "object/motion/motionhuman.h" #include "object/robotmain.h" + #include "physics/physics.h" + #include "ui/displaytext.h" #include // Object's constructor. -CTaskBuild::CTaskBuild(CInstanceManager* iMan, CObject* object) - : CTask(iMan, object) +CTaskBuild::CTaskBuild(CObject* object) : CTask(object) { int i; @@ -75,7 +78,7 @@ CTaskBuild::~CTaskBuild() bool CTaskBuild::CreateBuilding(Math::Vector pos, float angle) { - m_building = new CObject(m_iMan); + m_building = new CObject(); if ( !m_building->CreateBuilding(pos, angle, 0.0f, m_type, 0.0f) ) { delete m_building; @@ -596,11 +599,13 @@ Error CTaskBuild::FlatFloor() return bLittleFlat?ERR_BUILD_FLATLIT:ERR_BUILD_FLAT; } + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + max = 100000.0f; bBase = false; for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; if ( !pObj->GetActif() ) continue; // inactive? @@ -648,7 +653,7 @@ Error CTaskBuild::FlatFloor() max = 100000.0f; for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; if ( !pObj->GetActif() ) continue; // inactive? @@ -715,12 +720,14 @@ CObject* CTaskBuild::SearchMetalObject(float &angle, float dMin, float dMax, iAngle = m_object->GetAngleY(0); iAngle = Math::NormAngle(iAngle); // 0..2*Math::PI + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + min = 1000000.0f; pBest = 0; bMetal = false; for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; if ( !pObj->GetActif() ) continue; // objet inactive? @@ -779,9 +786,11 @@ void CTaskBuild::DeleteMark(Math::Vector pos, float radius) float distance; int i; + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; type = pObj->GetType(); diff --git a/src/object/task/taskbuild.h b/src/object/task/taskbuild.h index 25300b3..b3193a0 100644 --- a/src/object/task/taskbuild.h +++ b/src/object/task/taskbuild.h @@ -45,7 +45,7 @@ enum TaskBuildPhase class CTaskBuild : public CTask { public: - CTaskBuild(CInstanceManager* iMan, CObject* object); + CTaskBuild(CObject* object); ~CTaskBuild(); bool EventProcess(const Event &event); diff --git a/src/object/task/taskfire.cpp b/src/object/task/taskfire.cpp index 99a88b8..beb4944 100644 --- a/src/object/task/taskfire.cpp +++ b/src/object/task/taskfire.cpp @@ -14,12 +14,13 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// taskfire.cpp #include "object/task/taskfire.h" #include "graphics/engine/particle.h" + #include "math/geometry.h" + #include "physics/physics.h" @@ -31,8 +32,7 @@ const float ENERGY_FIREi = (0.10f/2.5f); // energy consumed/organic // Object's constructor. -CTaskFire::CTaskFire(CInstanceManager* iMan, CObject* object) - : CTask(iMan, object) +CTaskFire::CTaskFire(CObject* object) : CTask(object) { m_soundChannel = -1; } diff --git a/src/object/task/taskfire.h b/src/object/task/taskfire.h index 5cf4f0c..81058df 100644 --- a/src/object/task/taskfire.h +++ b/src/object/task/taskfire.h @@ -26,7 +26,7 @@ class CTaskFire : public CTask { public: - CTaskFire(CInstanceManager* iMan, CObject* object); + CTaskFire(CObject* object); ~CTaskFire(); bool EventProcess(const Event &event); diff --git a/src/object/task/taskfireant.cpp b/src/object/task/taskfireant.cpp index 2044685..c0acf64 100644 --- a/src/object/task/taskfireant.cpp +++ b/src/object/task/taskfireant.cpp @@ -14,13 +14,15 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// taskfireant.cpp #include "object/task/taskfireant.h" #include "graphics/engine/particle.h" + #include "math/geometry.h" + #include "object/motion/motionant.h" + #include "physics/physics.h" @@ -28,8 +30,7 @@ // Object's constructor. -CTaskFireAnt::CTaskFireAnt(CInstanceManager* iMan, CObject* object) - : CTask(iMan, object) +CTaskFireAnt::CTaskFireAnt(CObject* object) : CTask(object) { m_phase = TFA_NULL; } diff --git a/src/object/task/taskfireant.h b/src/object/task/taskfireant.h index 4fa77b8..2a0ead8 100644 --- a/src/object/task/taskfireant.h +++ b/src/object/task/taskfireant.h @@ -38,7 +38,7 @@ enum TaskFireAnt class CTaskFireAnt : public CTask { public: - CTaskFireAnt(CInstanceManager* iMan, CObject* object); + CTaskFireAnt(CObject* object); ~CTaskFireAnt(); bool EventProcess(const Event &event); diff --git a/src/object/task/taskflag.cpp b/src/object/task/taskflag.cpp index c88b5c0..dd5e11d 100644 --- a/src/object/task/taskflag.cpp +++ b/src/object/task/taskflag.cpp @@ -14,26 +14,28 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// taskflag.cpp #include "object/task/taskflag.h" -#include "math/geometry.h" #include "common/iman.h" + +#include "math/geometry.h" + #include "graphics/engine/particle.h" #include "graphics/engine/pyro.h" #include "graphics/engine/water.h" -#include "physics/physics.h" + #include "object/motion/motionhuman.h" +#include "physics/physics.h" + // Object's constructor. -CTaskFlag::CTaskFlag(CInstanceManager* iMan, CObject* object) - : CTask(iMan, object) +CTaskFlag::CTaskFlag(CObject* object) : CTask(object) { } @@ -137,11 +139,13 @@ CObject* CTaskFlag::SearchNearest(Math::Vector pos, ObjectType type) float min, dist; int i; + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + min = 100000.0f; pBest = 0; for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; if ( !pObj->GetEnable() ) continue; @@ -180,10 +184,12 @@ int CTaskFlag::CountObject(ObjectType type) Math::Vector oPos; int i, count; + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + count = 0; for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; if ( !pObj->GetEnable() ) continue; @@ -247,7 +253,7 @@ Error CTaskFlag::CreateFlag(int rank) return ERR_FLAG_CREATE; } - pNew = new CObject(m_iMan); + pNew = new CObject(); if ( !pNew->CreateFlag(pos, 0.0f, table[i]) ) { delete pNew; @@ -256,7 +262,7 @@ Error CTaskFlag::CreateFlag(int rank) //pNew->SetZoom(0, 0.0f); m_sound->Play(SOUND_WAYPOINT, pos); - pyro = new Gfx::CPyro(m_iMan); + pyro = new Gfx::CPyro(); pyro->Create(Gfx::PT_FLCREATE, pNew); return ERR_OK; @@ -295,7 +301,7 @@ Error CTaskFlag::DeleteFlag() } m_sound->Play(SOUND_WAYPOINT, iPos); - pyro = new Gfx::CPyro(m_iMan); + pyro = new Gfx::CPyro(); pyro->Create(Gfx::PT_FLDELETE, pObj); return ERR_OK; diff --git a/src/object/task/taskflag.h b/src/object/task/taskflag.h index 5b0a058..7e3e4ef 100644 --- a/src/object/task/taskflag.h +++ b/src/object/task/taskflag.h @@ -20,6 +20,7 @@ #include "object/task/task.h" #include "object/object.h" + #include "math/vector.h" @@ -35,7 +36,7 @@ enum TaskFlagOrder class CTaskFlag : public CTask { public: - CTaskFlag(CInstanceManager* iMan, CObject* object); + CTaskFlag(CObject* object); ~CTaskFlag(); bool EventProcess(const Event &event); diff --git a/src/object/task/taskgoto.cpp b/src/object/task/taskgoto.cpp index cab57f1..c4a2939 100644 --- a/src/object/task/taskgoto.cpp +++ b/src/object/task/taskgoto.cpp @@ -14,8 +14,6 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// taskgoto.cpp - #include @@ -23,9 +21,12 @@ #include "common/event.h" #include "common/iman.h" + #include "graphics/engine/terrain.h" #include "graphics/engine/water.h" + #include "math/geometry.h" + #include "physics/physics.h" #include @@ -40,8 +41,7 @@ const float BM_DIM_STEP = 5.0f; // Object's constructor. -CTaskGoto::CTaskGoto(CInstanceManager* iMan, CObject* object) - : CTask(iMan, object) +CTaskGoto::CTaskGoto(CObject* object) : CTask(object) { m_bmArray = 0; } @@ -494,12 +494,14 @@ CObject* CTaskGoto::WormSearch(Math::Vector &impact) float distance, min, radius; int i; + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + iPos = m_object->GetPosition(0); min = 1000000.0f; for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; oType = pObj->GetType(); @@ -1026,11 +1028,13 @@ CObject* CTaskGoto::SearchTarget(Math::Vector pos, float margin) float dist, min; int i; + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + pBest = 0; min = 1000000.0f; for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; if ( !pObj->GetActif() ) continue; @@ -1170,9 +1174,11 @@ bool CTaskGoto::AdjustBuilding(Math::Vector &pos, float margin, float &distance) float dist, suppl; int i; + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; if ( !pObj->GetActif() ) continue; @@ -1339,11 +1345,13 @@ bool CTaskGoto::LeakSearch(Math::Vector &pos, float &delay) m_object->GetCrashSphere(0, iPos, iRadius); + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + min = 100000.0f; bRadius = 0.0f; for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; if ( pObj == m_object ) continue; @@ -1401,7 +1409,7 @@ void CTaskGoto::ComputeRepulse(Math::Point &dir) for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; if ( pObj == m_object ) continue; @@ -1522,9 +1530,11 @@ void CTaskGoto::ComputeRepulse(Math::Point &dir) bAlien = true; } + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; if ( pObj == m_object ) continue; @@ -1614,9 +1624,11 @@ void CTaskGoto::ComputeFlyingRepulse(float &dir) fac = 1.5f; dir = 0.0f; + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; if ( pObj == m_object ) continue; @@ -1928,9 +1940,11 @@ void CTaskGoto::BitmapObject() m_object->GetCrashSphere(0, iPos, iRadius); + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; type = pObj->GetType(); diff --git a/src/object/task/taskgoto.h b/src/object/task/taskgoto.h index 1382d4c..d2b2d7e 100644 --- a/src/object/task/taskgoto.h +++ b/src/object/task/taskgoto.h @@ -20,6 +20,7 @@ #include "object/task/task.h" + #include "math/vector.h" @@ -72,7 +73,7 @@ enum TaskGotoPhase class CTaskGoto : public CTask { public: - CTaskGoto(CInstanceManager* iMan, CObject* object); + CTaskGoto(CObject* object); ~CTaskGoto(); bool EventProcess(const Event &event); diff --git a/src/object/task/taskgungoal.cpp b/src/object/task/taskgungoal.cpp index aed3355..3373610 100644 --- a/src/object/task/taskgungoal.cpp +++ b/src/object/task/taskgungoal.cpp @@ -14,7 +14,6 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// taskgungoal.cpp #include "object/task/taskgungoal.h" @@ -25,8 +24,7 @@ // Object's constructor. -CTaskGunGoal::CTaskGunGoal(CInstanceManager* iMan, CObject* object) - : CTask(iMan, object) +CTaskGunGoal::CTaskGunGoal(CObject* object) : CTask(object) { } diff --git a/src/object/task/taskgungoal.h b/src/object/task/taskgungoal.h index 0c063d1..c6f010b 100644 --- a/src/object/task/taskgungoal.h +++ b/src/object/task/taskgungoal.h @@ -26,7 +26,7 @@ class CTaskGunGoal : public CTask { public: - CTaskGunGoal(CInstanceManager* iMan, CObject* object); + CTaskGunGoal(CObject* object); ~CTaskGunGoal(); bool EventProcess(const Event &event); diff --git a/src/object/task/taskinfo.cpp b/src/object/task/taskinfo.cpp index 4e64584..32ac342 100644 --- a/src/object/task/taskinfo.cpp +++ b/src/object/task/taskinfo.cpp @@ -14,12 +14,13 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// taskinfo.cpp #include "object/task/taskinfo.h" #include "common/iman.h" + #include "graphics/engine/particle.h" + #include "object/auto/autoinfo.h" #include @@ -28,8 +29,7 @@ // Object's constructor. -CTaskInfo::CTaskInfo(CInstanceManager* iMan, CObject* object) - : CTask(iMan, object) +CTaskInfo::CTaskInfo(CObject* object) : CTask(object) { } @@ -189,11 +189,13 @@ CObject* CTaskInfo::SearchInfo(float power) iPos = m_object->GetPosition(0); + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + min = 100000.0f; pBest = 0; for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; type = pObj->GetType(); diff --git a/src/object/task/taskinfo.h b/src/object/task/taskinfo.h index 036b57d..1ce3dca 100644 --- a/src/object/task/taskinfo.h +++ b/src/object/task/taskinfo.h @@ -26,7 +26,7 @@ class CTaskInfo : public CTask { public: - CTaskInfo(CInstanceManager* iMan, CObject* object); + CTaskInfo(CObject* object); ~CTaskInfo(); bool EventProcess(const Event &event); diff --git a/src/object/task/taskmanager.cpp b/src/object/task/taskmanager.cpp index 26e389d..a2ce8b8 100644 --- a/src/object/task/taskmanager.cpp +++ b/src/object/task/taskmanager.cpp @@ -14,14 +14,13 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// taskmanager.cpp - #include #include "object/task/taskmanager.h" #include "common/iman.h" + #include "object/task/taskwait.h" #include "object/task/taskadvance.h" #include "object/task/taskturn.h" @@ -43,12 +42,9 @@ // Object's constructor. -CTaskManager::CTaskManager(CInstanceManager* iMan, CObject* object) +CTaskManager::CTaskManager(CObject* object) { - m_iMan = iMan; - m_iMan->AddInstance(CLASS_TASKMANAGER, this, 100); - - m_task = 0; + m_task = nullptr; m_object = object; m_bPilot = false; } @@ -66,7 +62,7 @@ CTaskManager::~CTaskManager() Error CTaskManager::StartTaskWait(float time) { - m_task = new CTaskWait(m_iMan, m_object); + m_task = new CTaskWait(m_object); return (static_cast(m_task))->Start(time); } @@ -74,7 +70,7 @@ Error CTaskManager::StartTaskWait(float time) Error CTaskManager::StartTaskAdvance(float length) { - m_task = new CTaskAdvance(m_iMan, m_object); + m_task = new CTaskAdvance(m_object); return (static_cast(m_task))->Start(length); } @@ -82,7 +78,7 @@ Error CTaskManager::StartTaskAdvance(float length) Error CTaskManager::StartTaskTurn(float angle) { - m_task = new CTaskTurn(m_iMan, m_object); + m_task = new CTaskTurn(m_object); return (static_cast(m_task))->Start(angle); } @@ -90,7 +86,7 @@ Error CTaskManager::StartTaskTurn(float angle) Error CTaskManager::StartTaskGoto(Math::Vector pos, float altitude, TaskGotoGoal goalMode, TaskGotoCrash crashMode) { - m_task = new CTaskGoto(m_iMan, m_object); + m_task = new CTaskGoto(m_object); return (static_cast(m_task))->Start(pos, altitude, goalMode, crashMode); } @@ -98,7 +94,7 @@ Error CTaskManager::StartTaskGoto(Math::Vector pos, float altitude, TaskGotoGoal Error CTaskManager::StartTaskTake() { - m_task = new CTaskTake(m_iMan, m_object); + m_task = new CTaskTake(m_object); return (static_cast(m_task))->Start(); } @@ -106,7 +102,7 @@ Error CTaskManager::StartTaskTake() Error CTaskManager::StartTaskManip(TaskManipOrder order, TaskManipArm arm) { - m_task = new CTaskManip(m_iMan, m_object); + m_task = new CTaskManip(m_object); return (static_cast(m_task))->Start(order, arm); } @@ -114,7 +110,7 @@ Error CTaskManager::StartTaskManip(TaskManipOrder order, TaskManipArm arm) Error CTaskManager::StartTaskFlag(TaskFlagOrder order, int rank) { - m_task = new CTaskFlag(m_iMan, m_object); + m_task = new CTaskFlag(m_object); return (static_cast(m_task))->Start(order, rank); } @@ -122,7 +118,7 @@ Error CTaskManager::StartTaskFlag(TaskFlagOrder order, int rank) Error CTaskManager::StartTaskBuild(ObjectType type) { - m_task = new CTaskBuild(m_iMan, m_object); + m_task = new CTaskBuild(m_object); return (static_cast(m_task))->Start(type); } @@ -130,7 +126,7 @@ Error CTaskManager::StartTaskBuild(ObjectType type) Error CTaskManager::StartTaskSearch() { - m_task = new CTaskSearch(m_iMan, m_object); + m_task = new CTaskSearch(m_object); return (static_cast(m_task))->Start(); } @@ -138,7 +134,7 @@ Error CTaskManager::StartTaskSearch() Error CTaskManager::StartTaskInfo(const char *name, float value, float power, bool bSend) { - m_task = new CTaskInfo(m_iMan, m_object); + m_task = new CTaskInfo(m_object); return (static_cast(m_task))->Start(name, value, power, bSend); } @@ -146,7 +142,7 @@ Error CTaskManager::StartTaskInfo(const char *name, float value, float power, bo Error CTaskManager::StartTaskTerraform() { - m_task = new CTaskTerraform(m_iMan, m_object); + m_task = new CTaskTerraform(m_object); return (static_cast(m_task))->Start(); } @@ -154,7 +150,7 @@ Error CTaskManager::StartTaskTerraform() Error CTaskManager::StartTaskPen(bool bDown, int color) { - m_task = new CTaskPen(m_iMan, m_object); + m_task = new CTaskPen(m_object); return (static_cast(m_task))->Start(bDown, color); } @@ -162,7 +158,7 @@ Error CTaskManager::StartTaskPen(bool bDown, int color) Error CTaskManager::StartTaskRecover() { - m_task = new CTaskRecover(m_iMan, m_object); + m_task = new CTaskRecover(m_object); return (static_cast(m_task))->Start(); } @@ -172,7 +168,7 @@ Error CTaskManager::StartTaskShield(TaskShieldMode mode, float delay) { if ( mode == TSM_UP ) { - m_task = new CTaskShield(m_iMan, m_object); + m_task = new CTaskShield(m_object); return (static_cast(m_task))->Start(mode, delay); } if ( mode == TSM_DOWN && m_task != 0 ) @@ -191,7 +187,7 @@ Error CTaskManager::StartTaskShield(TaskShieldMode mode, float delay) Error CTaskManager::StartTaskFire(float delay) { m_bPilot = true; - m_task = new CTaskFire(m_iMan, m_object); + m_task = new CTaskFire(m_object); return (static_cast(m_task))->Start(delay); } @@ -199,7 +195,7 @@ Error CTaskManager::StartTaskFire(float delay) Error CTaskManager::StartTaskFireAnt(Math::Vector impact) { - m_task = new CTaskFireAnt(m_iMan, m_object); + m_task = new CTaskFireAnt(m_object); return (static_cast(m_task))->Start(impact); } @@ -207,7 +203,7 @@ Error CTaskManager::StartTaskFireAnt(Math::Vector impact) Error CTaskManager::StartTaskGunGoal(float dirV, float dirH) { - m_task = new CTaskGunGoal(m_iMan, m_object); + m_task = new CTaskGunGoal(m_object); return (static_cast(m_task))->Start(dirV, dirH); } @@ -215,7 +211,7 @@ Error CTaskManager::StartTaskGunGoal(float dirV, float dirH) Error CTaskManager::StartTaskSpiderExplo() { - m_task = new CTaskSpiderExplo(m_iMan, m_object); + m_task = new CTaskSpiderExplo(m_object); return (static_cast(m_task))->Start(); } @@ -223,7 +219,7 @@ Error CTaskManager::StartTaskSpiderExplo() Error CTaskManager::StartTaskReset(Math::Vector goal, Math::Vector angle) { - m_task = new CTaskReset(m_iMan, m_object); + m_task = new CTaskReset(m_object); return (static_cast(m_task))->Start(goal, angle); } diff --git a/src/object/task/taskmanager.h b/src/object/task/taskmanager.h index 6ce023a..80a78fd 100644 --- a/src/object/task/taskmanager.h +++ b/src/object/task/taskmanager.h @@ -19,8 +19,8 @@ #pragma once -#include "object/task/task.h" #include "object/object.h" +#include "object/task/task.h" #include "object/task/taskmanip.h" #include "object/task/taskgoto.h" #include "object/task/taskshield.h" @@ -31,7 +31,7 @@ class CTaskManager { public: - CTaskManager(CInstanceManager* iMan, CObject* object); + CTaskManager(CObject* object); ~CTaskManager(); Error StartTaskWait(float time); @@ -61,9 +61,6 @@ public: bool Abort(); protected: - -protected: - CInstanceManager* m_iMan; CTask* m_task; CObject* m_object; bool m_bPilot; diff --git a/src/object/task/taskmanip.cpp b/src/object/task/taskmanip.cpp index b0b146c..0608b6e 100644 --- a/src/object/task/taskmanip.cpp +++ b/src/object/task/taskmanip.cpp @@ -14,15 +14,18 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// taskmanip.cpp #include "object/task/taskmanip.h" #include "common/iman.h" + #include "graphics/engine/terrain.h" #include "graphics/engine/pyro.h" + #include "math/geometry.h" + #include "object/robotmain.h" + #include "physics/physics.h" @@ -40,8 +43,7 @@ const float MARGIN_BEE = 5.0f; //OK 1.9 // Object's constructor. -CTaskManip::CTaskManip(CInstanceManager* iMan, CObject* object) - : CTask(iMan, object) +CTaskManip::CTaskManip(CObject* object) : CTask(object) { m_arm = TMA_NEUTRAL; m_hand = TMH_OPEN; @@ -338,7 +340,7 @@ Error CTaskManip::Start(TaskManipOrder order, TaskManipArm arm) pos.y += 2.0f; m_object->SetPosition(0, pos); // against the top of jump - pyro = new Gfx::CPyro(m_iMan); + pyro = new Gfx::CPyro(); pyro->Create(Gfx::PT_FALL, other); // the ball falls } @@ -728,11 +730,13 @@ CObject* CTaskManip::SearchTakeUnderObject(Math::Vector &pos, float dLimit) iPos = m_object->GetPosition(0); + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + min = 1000000.0f; pBest = 0; for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; type = pObj->GetType(); @@ -798,12 +802,14 @@ CObject* CTaskManip::SearchTakeFrontObject(bool bAdvance, Math::Vector &pos, dLimit = MARGIN_FRONT; } + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + min = 1000000.0f; pBest = 0; bAngle = 0.0f; for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; type = pObj->GetType(); @@ -889,12 +895,14 @@ CObject* CTaskManip::SearchTakeBackObject(bool bAdvance, Math::Vector &pos, dLimit = MARGIN_BACK; } + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + min = 1000000.0f; pBest = 0; bAngle = 0.0f; for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; type = pObj->GetType(); @@ -989,9 +997,11 @@ CObject* CTaskManip::SearchOtherObject(bool bAdvance, Math::Vector &pos, dLimit = MARGIN_FRIEND; } + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; if ( pObj == m_object ) continue; // yourself? @@ -1345,9 +1355,11 @@ bool CTaskManip::IsFreeDeposeObject(Math::Vector pos) mat = m_object->GetWorldMatrix(0); iPos = Transform(*mat, pos); + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; if ( pObj == m_object ) continue; diff --git a/src/object/task/taskmanip.h b/src/object/task/taskmanip.h index 79d9ad5..e80602c 100644 --- a/src/object/task/taskmanip.h +++ b/src/object/task/taskmanip.h @@ -54,7 +54,7 @@ enum TaskManipHand class CTaskManip : public CTask { public: - CTaskManip(CInstanceManager* iMan, CObject* object); + CTaskManip(CObject* object); ~CTaskManip(); bool EventProcess(const Event &event); diff --git a/src/object/task/taskpen.cpp b/src/object/task/taskpen.cpp index 6e04233..03c2322 100644 --- a/src/object/task/taskpen.cpp +++ b/src/object/task/taskpen.cpp @@ -14,20 +14,20 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// taskpen.cpp #include "object/task/taskpen.h" #include "graphics/engine/particle.h" -#include "math/geometry.h" + #include "object/object.h" +#include "math/geometry.h" + // Object's constructor. -CTaskPen::CTaskPen(CInstanceManager* iMan, CObject* object) - : CTask(iMan, object) +CTaskPen::CTaskPen(CObject* object) : CTask(object) { } diff --git a/src/object/task/taskpen.h b/src/object/task/taskpen.h index 0974322..adaba6c 100644 --- a/src/object/task/taskpen.h +++ b/src/object/task/taskpen.h @@ -36,7 +36,7 @@ enum TaskPenPhase class CTaskPen : public CTask { public: - CTaskPen(CInstanceManager* iMan, CObject* object); + CTaskPen(CObject* object); ~CTaskPen(); bool EventProcess(const Event &event); diff --git a/src/object/task/taskrecover.cpp b/src/object/task/taskrecover.cpp index 4c8ead8..b86e9a5 100644 --- a/src/object/task/taskrecover.cpp +++ b/src/object/task/taskrecover.cpp @@ -14,17 +14,19 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// taskrecover.cpp - #include #include "object/task/taskrecover.h" -#include "math/geometry.h" #include "common/iman.h" + #include "graphics/engine/particle.h" + +#include "math/geometry.h" + #include "physics/physics.h" + #include "ui/displaytext.h" @@ -35,8 +37,7 @@ const float RECOVER_DIST = 11.8f; // Object's constructor. -CTaskRecover::CTaskRecover(CInstanceManager* iMan, CObject* object) - : CTask(iMan, object) +CTaskRecover::CTaskRecover(CObject* object) : CTask(object) { m_ruin = 0; m_soundChannel = -1; @@ -297,7 +298,7 @@ Error CTaskRecover::IsEnded() if ( m_phase == TRP_DOWN ) { - m_metal = new CObject(m_iMan); + m_metal = new CObject(); if ( !m_metal->CreateResource(m_recoverPos, 0.0f, OBJECT_METAL) ) { delete m_metal; @@ -385,11 +386,13 @@ CObject* CTaskRecover::SearchRuin() float dist, min; int i; + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + pBest = 0; min = 100000.0f; for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; type = pObj->GetType(); diff --git a/src/object/task/taskrecover.h b/src/object/task/taskrecover.h index 151ab6b..817ed5f 100644 --- a/src/object/task/taskrecover.h +++ b/src/object/task/taskrecover.h @@ -20,6 +20,7 @@ #include "object/task/task.h" + #include "math/vector.h" @@ -38,7 +39,7 @@ enum TaskRecoverPhase class CTaskRecover : public CTask { public: - CTaskRecover(CInstanceManager* iMan, CObject* object); + CTaskRecover(CObject* object); ~CTaskRecover(); bool EventProcess(const Event &event); diff --git a/src/object/task/taskreset.cpp b/src/object/task/taskreset.cpp index 7e097bf..98d9730 100644 --- a/src/object/task/taskreset.cpp +++ b/src/object/task/taskreset.cpp @@ -14,11 +14,11 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// taskreset.cpp #include "object/task/taskreset.h" #include "common/iman.h" + #include "object/brain.h" #include "object/robotmain.h" @@ -32,8 +32,7 @@ const float RESET_DELAY_MOVE = 0.7f; // Object's constructor. -CTaskReset::CTaskReset(CInstanceManager* iMan, CObject* object) - : CTask(iMan, object) +CTaskReset::CTaskReset(CObject* object) : CTask(object) { } @@ -273,9 +272,11 @@ bool CTaskReset::SearchVehicle() float oRadius, dist; int i; + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; if ( pObj == m_object ) continue; diff --git a/src/object/task/taskreset.h b/src/object/task/taskreset.h index e3dacf7..5f1bb34 100644 --- a/src/object/task/taskreset.h +++ b/src/object/task/taskreset.h @@ -36,7 +36,7 @@ enum TaskResetPhase class CTaskReset : public CTask { public: - CTaskReset(CInstanceManager* iMan, CObject* object); + CTaskReset(CObject* object); ~CTaskReset(); bool EventProcess(const Event &event); diff --git a/src/object/task/tasksearch.cpp b/src/object/task/tasksearch.cpp index 578b41e..b219185 100644 --- a/src/object/task/tasksearch.cpp +++ b/src/object/task/tasksearch.cpp @@ -14,15 +14,18 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// tasksearch.cpp #include "object/task/tasksearch.h" -#include "math/geometry.h" #include "common/iman.h" + #include "graphics/engine/particle.h" #include "graphics/engine/terrain.h" + +#include "math/geometry.h" + #include "physics/physics.h" + #include "ui/displaytext.h" @@ -30,8 +33,7 @@ // Object's constructor. -CTaskSearch::CTaskSearch(CInstanceManager* iMan, CObject* object) - : CTask(iMan, object) +CTaskSearch::CTaskSearch(CObject* object) : CTask(object) { m_hand = TSH_UP; } @@ -280,7 +282,7 @@ bool CTaskSearch::CreateMark() //? DeleteMark(type); - fret = new CObject(m_iMan); + fret = new CObject(); if ( !fret->CreateResource(pos, 0.0f, type) ) { delete fret; @@ -301,9 +303,11 @@ void CTaskSearch::DeleteMark(ObjectType type) Math::Vector oPos; int i; + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; if ( type == pObj->GetType() ) diff --git a/src/object/task/tasksearch.h b/src/object/task/tasksearch.h index bffec16..582d45a 100644 --- a/src/object/task/tasksearch.h +++ b/src/object/task/tasksearch.h @@ -42,7 +42,7 @@ enum TaskSearchPhase class CTaskSearch : public CTask { public: - CTaskSearch(CInstanceManager* iMan, CObject* object); + CTaskSearch(CObject* object); ~CTaskSearch(); bool EventProcess(const Event &event); diff --git a/src/object/task/taskshield.cpp b/src/object/task/taskshield.cpp index 93afd62..4b2fccd 100644 --- a/src/object/task/taskshield.cpp +++ b/src/object/task/taskshield.cpp @@ -14,16 +14,19 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// taskshield.cpp #include "object/task/taskshield.h" #include "common/iman.h" + #include "graphics/core/light.h" #include "graphics/engine/particle.h" #include "graphics/engine/lightman.h" + #include "math/geometry.h" + #include "object/brain.h" + #include "physics/physics.h" #include @@ -34,8 +37,7 @@ const float ENERGY_TIME = 20.0f; // maximum duration if full battery // Object's constructor. -CTaskShield::CTaskShield(CInstanceManager* iMan, CObject* object) - : CTask(iMan, object) +CTaskShield::CTaskShield(CObject* object) : CTask(object) { m_rankSphere = -1; m_soundChannel = -1; @@ -521,9 +523,11 @@ void CTaskShield::IncreaseShield() float dist, shield; int i; + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; type = pObj->GetType(); diff --git a/src/object/task/taskshield.h b/src/object/task/taskshield.h index 4a6811c..36d3819 100644 --- a/src/object/task/taskshield.h +++ b/src/object/task/taskshield.h @@ -20,6 +20,7 @@ #include "object/task/task.h" + #include "math/vector.h" @@ -49,7 +50,7 @@ enum TaskShieldMode class CTaskShield : public CTask { public: - CTaskShield(CInstanceManager* iMan, CObject* object); + CTaskShield(CObject* object); ~CTaskShield(); bool EventProcess(const Event &event); diff --git a/src/object/task/taskspiderexplo.cpp b/src/object/task/taskspiderexplo.cpp index 8110870..f629714 100644 --- a/src/object/task/taskspiderexplo.cpp +++ b/src/object/task/taskspiderexplo.cpp @@ -14,12 +14,13 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// taskspiderexplo.cpp #include "object/task/taskspiderexplo.h" #include "graphics/engine/pyro.h" + #include "object/motion/motionspider.h" + #include "physics/physics.h" @@ -27,8 +28,7 @@ // Object's constructor. -CTaskSpiderExplo::CTaskSpiderExplo(CInstanceManager* iMan, CObject* object) - : CTask(iMan, object) +CTaskSpiderExplo::CTaskSpiderExplo(CObject* object) : CTask(object) { m_time = 0.0f; m_bError = false; @@ -91,7 +91,7 @@ Error CTaskSpiderExplo::IsEnded() if ( m_time < 1.0f ) return ERR_CONTINUE; - pyro = new Gfx::CPyro(m_iMan); + pyro = new Gfx::CPyro(); pyro->Create(Gfx::PT_SPIDER, m_object); // the spider explodes (suicide) Abort(); diff --git a/src/object/task/taskspiderexplo.h b/src/object/task/taskspiderexplo.h index 50f3ad2..0984020 100644 --- a/src/object/task/taskspiderexplo.h +++ b/src/object/task/taskspiderexplo.h @@ -26,7 +26,7 @@ class CTaskSpiderExplo : public CTask { public: - CTaskSpiderExplo(CInstanceManager* iMan, CObject* object); + CTaskSpiderExplo(CObject* object); ~CTaskSpiderExplo(); bool EventProcess(const Event &event); diff --git a/src/object/task/tasktake.cpp b/src/object/task/tasktake.cpp index 2737324..0037f85 100644 --- a/src/object/task/tasktake.cpp +++ b/src/object/task/tasktake.cpp @@ -14,16 +14,19 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// tasktake.cpp #include "object/task/tasktake.h" #include "common/iman.h" + #include "graphics/engine/terrain.h" #include "graphics/engine/water.h" + #include "math/geometry.h" + #include "object/motion/motionhuman.h" #include "object/robotmain.h" + #include "physics/physics.h" @@ -31,10 +34,9 @@ // Object's constructor. -CTaskTake::CTaskTake(CInstanceManager* iMan, CObject* object) - : CTask(iMan, object) +CTaskTake::CTaskTake(CObject* object) : CTask(object) { - m_terrain = static_cast(m_iMan->SearchInstance(CLASS_TERRAIN)); + m_terrain = CRobotMain::GetInstancePointer()->GetTerrain(); m_arm = TTA_NEUTRAL; } @@ -305,12 +307,14 @@ CObject* CTaskTake::SearchTakeObject(float &angle, iAngle = m_object->GetAngleY(0); iAngle = Math::NormAngle(iAngle); // 0..2*Math::PI + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + min = 1000000.0f; pBest = 0; bAngle = 0.0f; for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; type = pObj->GetType(); @@ -374,9 +378,11 @@ CObject* CTaskTake::SearchFriendObject(float &angle, iAngle = m_object->GetAngleY(0); iAngle = Math::NormAngle(iAngle); // 0..2*Math::PI + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; if ( pObj == m_object ) continue; // yourself? @@ -569,9 +575,11 @@ bool CTaskTake::IsFreeDeposeObject(Math::Vector pos) mat = m_object->GetWorldMatrix(0); iPos = Transform(*mat, pos); + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; if ( pObj == m_object ) continue; diff --git a/src/object/task/tasktake.h b/src/object/task/tasktake.h index c7950fe..7f3f831 100644 --- a/src/object/task/tasktake.h +++ b/src/object/task/tasktake.h @@ -42,7 +42,7 @@ enum TaskTakeArm class CTaskTake : public CTask { public: - CTaskTake(CInstanceManager* iMan, CObject* object); + CTaskTake(CObject* object); ~CTaskTake(); bool EventProcess(const Event &event); diff --git a/src/object/task/taskterraform.cpp b/src/object/task/taskterraform.cpp index 6afece4..1f5ef7b 100644 --- a/src/object/task/taskterraform.cpp +++ b/src/object/task/taskterraform.cpp @@ -14,23 +14,25 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// taskterraform.cpp - #include #include "object/task/taskterraform.h" -#include "math/geometry.h" #include "common/iman.h" + #include "graphics/engine/pyro.h" #include "graphics/engine/particle.h" #include "graphics/engine/terrain.h" -#include "physics/physics.h" + +#include "math/geometry.h" + #include "object/brain.h" #include "object/motion/motionant.h" #include "object/motion/motionspider.h" +#include "physics/physics.h" + const float ENERGY_TERRA = 0.40f; // energy consumed by blow const float ACTION_RADIUS = 400.0f; @@ -39,8 +41,7 @@ const float ACTION_RADIUS = 400.0f; // Object's constructor. -CTaskTerraform::CTaskTerraform(CInstanceManager* iMan, CObject* object) - : CTask(iMan, object) +CTaskTerraform::CTaskTerraform(CObject* object) : CTask(object) { m_lastParticle = 0.0f; m_soundChannel = -1; @@ -370,9 +371,11 @@ bool CTaskTerraform::Terraform() m_sound->Play(SOUND_THUMP, m_terraPos); + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; type = pObj->GetType(); @@ -383,7 +386,7 @@ bool CTaskTerraform::Terraform() dist = Math::Distance(m_terraPos, pObj->GetPosition(0)); if ( dist > 20.0f ) continue; - pyro = new Gfx::CPyro(m_iMan); + pyro = new Gfx::CPyro(); pyro->Create(Gfx::PT_FRAGT, pObj); } else diff --git a/src/object/task/taskterraform.h b/src/object/task/taskterraform.h index 91526b6..8ae0d64 100644 --- a/src/object/task/taskterraform.h +++ b/src/object/task/taskterraform.h @@ -20,6 +20,7 @@ #include "object/task/task.h" + #include "math/vector.h" @@ -37,7 +38,7 @@ enum TaskTerraPhase class CTaskTerraform : public CTask { public: - CTaskTerraform(CInstanceManager* iMan, CObject* object); + CTaskTerraform(CObject* object); ~CTaskTerraform(); bool EventProcess(const Event &event); diff --git a/src/object/task/taskturn.cpp b/src/object/task/taskturn.cpp index 8f4bbd2..7a924cb 100644 --- a/src/object/task/taskturn.cpp +++ b/src/object/task/taskturn.cpp @@ -14,7 +14,6 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// taskturn.cpp #include "object/task/taskturn.h" @@ -26,8 +25,7 @@ // Object's constructor. -CTaskTurn::CTaskTurn(CInstanceManager* iMan, CObject* object) - : CTask(iMan, object) +CTaskTurn::CTaskTurn(CObject* object) : CTask(object) { } diff --git a/src/object/task/taskturn.h b/src/object/task/taskturn.h index 1ee40d9..11de476 100644 --- a/src/object/task/taskturn.h +++ b/src/object/task/taskturn.h @@ -26,7 +26,7 @@ class CTaskTurn : public CTask { public: - CTaskTurn(CInstanceManager* iMan, CObject* object); + CTaskTurn(CObject* object); ~CTaskTurn(); bool EventProcess(const Event &event); diff --git a/src/object/task/taskwait.cpp b/src/object/task/taskwait.cpp index f612c24..3e201e0 100644 --- a/src/object/task/taskwait.cpp +++ b/src/object/task/taskwait.cpp @@ -14,7 +14,6 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// taskwait.cpp #include "object/task/taskwait.h" @@ -22,8 +21,7 @@ // Object's constructor. -CTaskWait::CTaskWait(CInstanceManager* iMan, CObject* object) - : CTask(iMan, object) +CTaskWait::CTaskWait(CObject* object) : CTask(object) { } diff --git a/src/object/task/taskwait.h b/src/object/task/taskwait.h index 3434c36..3225c9a 100644 --- a/src/object/task/taskwait.h +++ b/src/object/task/taskwait.h @@ -26,7 +26,7 @@ class CTaskWait : public CTask { public: - CTaskWait(CInstanceManager* iMan, CObject* object); + CTaskWait(CObject* object); ~CTaskWait(); bool EventProcess(const Event &event); diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index f56f81d..6311ecf 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -17,6 +17,8 @@ #include "physics/physics.h" +#include "app/app.h" + #include "common/event.h" #include "common/global.h" #include "common/iman.h" @@ -31,6 +33,7 @@ #include "math/geometry.h" #include "object/brain.h" +#include "object/robotmain.h" #include "object/motion/motion.h" #include "object/motion/motionhuman.h" #include "object/task/task.h" @@ -51,21 +54,18 @@ const float LANDING_ACCELh = 1.5f; // Object's constructor. -CPhysics::CPhysics(CInstanceManager* iMan, CObject* object) +CPhysics::CPhysics(CObject* object) { - m_iMan = iMan; - m_iMan->AddInstance(CLASS_PHYSICS, this, 100); - m_object = object; - m_engine = static_cast(m_iMan->SearchInstance(CLASS_ENGINE)); - m_lightMan = static_cast(m_iMan->SearchInstance(CLASS_LIGHT)); - m_particle = static_cast(m_iMan->SearchInstance(CLASS_PARTICULE)); - m_terrain = static_cast(m_iMan->SearchInstance(CLASS_TERRAIN)); - m_water = static_cast(m_iMan->SearchInstance(CLASS_WATER)); - m_camera = static_cast(m_iMan->SearchInstance(CLASS_CAMERA)); - m_sound = static_cast(m_iMan->SearchInstance(CLASS_SOUND)); - m_brain = 0; - m_motion = 0; + m_engine = Gfx::CEngine::GetInstancePointer(); + m_lightMan = m_engine->GetLightManager(); + m_particle = m_engine->GetParticle(); + m_water = m_engine->GetWater(); + m_terrain = CRobotMain::GetInstancePointer()->GetTerrain(); + m_camera = CRobotMain::GetInstancePointer()->GetCamera(); + m_sound = CApplication::GetInstancePointer()->GetSound(); + m_brain = nullptr; + m_motion = nullptr; m_type = TYPE_ROLLING; m_gravity = 9.81f; // default gravity @@ -116,8 +116,7 @@ CPhysics::CPhysics(CInstanceManager* iMan, CObject* object) CPhysics::~CPhysics() { - m_iMan->DeleteInstance(CLASS_PHYSICS, this); -} + } // Destroys the object. @@ -2510,9 +2509,11 @@ int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle) iPos = iiPos + (pos - m_object->GetPosition(0)); iType = m_object->GetType(); + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; if ( pObj == m_object ) continue; // yourself? @@ -2578,7 +2579,7 @@ int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle) if ( distance < 4.0f ) { m_sound->Play(SOUND_WAYPOINT, m_object->GetPosition(0)); - pyro = new Gfx::CPyro(m_iMan); + pyro = new Gfx::CPyro(); pyro->Create(Gfx::PT_WPCHECK, pObj); } } @@ -2590,7 +2591,7 @@ int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle) if ( distance < 10.0f*1.5f ) { m_sound->Play(SOUND_WAYPOINT, m_object->GetPosition(0)); - pyro = new Gfx::CPyro(m_iMan); + pyro = new Gfx::CPyro(); pyro->Create(Gfx::PT_WPCHECK, pObj); } } @@ -2752,7 +2753,7 @@ bool CPhysics::ExploOther(ObjectType iType, (oType == OBJECT_FRET || oType == OBJECT_METAL ) ) { - pyro = new Gfx::CPyro(m_iMan); + pyro = new Gfx::CPyro(); pyro->Create(Gfx::PT_EXPLOT, pObj); // total destruction } @@ -2760,7 +2761,7 @@ bool CPhysics::ExploOther(ObjectType iType, (oType == OBJECT_POWER || oType == OBJECT_ATOMIC ) ) { - pyro = new Gfx::CPyro(m_iMan); + pyro = new Gfx::CPyro(); pyro->Create(Gfx::PT_FRAGT, pObj); // total destruction } @@ -2768,7 +2769,7 @@ bool CPhysics::ExploOther(ObjectType iType, (oType == OBJECT_STONE || oType == OBJECT_URANIUM ) ) { - pyro = new Gfx::CPyro(m_iMan); + pyro = new Gfx::CPyro(); pyro->Create(Gfx::PT_FRAGT, pObj); // total destruction } @@ -2829,14 +2830,14 @@ bool CPhysics::ExploOther(ObjectType iType, (oType == OBJECT_MOBILEtg || oType == OBJECT_TNT ) ) { - pyro = new Gfx::CPyro(m_iMan); + pyro = new Gfx::CPyro(); pyro->Create(Gfx::PT_FRAGT, pObj); // total destruction } if ( force > 0.0f && oType == OBJECT_BOMB ) { - pyro = new Gfx::CPyro(m_iMan); + pyro = new Gfx::CPyro(); pyro->Create(Gfx::PT_FRAGT, pObj); // total destruction } @@ -2859,7 +2860,7 @@ int CPhysics::ExploHimself(ObjectType iType, ObjectType oType, float force) { if ( iType == OBJECT_HUMAN ) type = Gfx::PT_DEADG; else type = Gfx::PT_EXPLOT; - pyro = new Gfx::CPyro(m_iMan); + pyro = new Gfx::CPyro(); pyro->Create(type, m_object); // total destruction return 2; } @@ -2881,7 +2882,7 @@ int CPhysics::ExploHimself(ObjectType iType, ObjectType oType, float force) { type = Gfx::PT_EXPLOT; } - pyro = new Gfx::CPyro(m_iMan); + pyro = new Gfx::CPyro(); pyro->Create(type, m_object); // total destruction return 2; } diff --git a/src/physics/physics.h b/src/physics/physics.h index db88e8c..cce57f3 100644 --- a/src/physics/physics.h +++ b/src/physics/physics.h @@ -30,21 +30,19 @@ #include "math/vector.h" -class CInstanceManager; class CObject; class CBrain; class CMotion; class CSoundInterface; -namespace Gfx -{ +namespace Gfx { class CCamera; class CEngine; class CLight; class CParticle; class CTerrain; class CWater; -}; +} enum PhysicsType @@ -97,7 +95,7 @@ struct Motion class CPhysics { public: - CPhysics(CInstanceManager* iMan, CObject* object); + CPhysics(CObject* object); ~CPhysics(); void DeleteObject(bool bAll=false); @@ -195,7 +193,6 @@ protected: void WheelParticle(int color, float width); protected: - CInstanceManager* m_iMan; Gfx::CEngine* m_engine; Gfx::CLightManager* m_lightMan; Gfx::CParticle* m_particle; diff --git a/src/script/script.cpp b/src/script/script.cpp index 199fd43..977070f 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -335,7 +335,9 @@ bool CScript::rGetObject(CBotVar* var, CBotVar* result, int& exception, void* us rank = var->GetValInt(); - pObj = static_cast(script->m_iMan->SearchInstance(CLASS_OBJECT, rank)); + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, rank)); if ( pObj == 0 ) { result->SetPointer(0); @@ -404,11 +406,13 @@ bool CScript::rSearch(CBotVar* var, CBotVar* result, int& exception, void* user) bNearest = true; } + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + min = 100000.0f; pBest = 0; for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(script->m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; if ( pObj->GetTruck() != 0 ) continue; // object transported? @@ -592,12 +596,14 @@ bool CScript::rRadar(CBotVar* var, CBotVar* result, int& exception, void* user) iAngle = pThis->GetAngleY(0)+angle; iAngle = Math::NormAngle(iAngle); // 0..2*Math::PI + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + if ( sens >= 0.0f ) best = 100000.0f; else best = 0.0f; pBest = 0; for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(script->m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; if ( pObj == pThis ) continue; @@ -778,6 +784,8 @@ bool CScript::rDetect(CBotVar* var, CBotVar* result, int& exception, void* user) iAngle = pThis->GetAngleY(0)+angle; iAngle = Math::NormAngle(iAngle); // 0..2*Math::PI + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + bGoal = 100000.0f; pGoal = 0; if ( sens >= 0.0f ) best = 100000.0f; @@ -785,7 +793,7 @@ bool CScript::rDetect(CBotVar* var, CBotVar* result, int& exception, void* user) pBest = 0; for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(script->m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; if ( pObj == pThis ) continue; @@ -885,7 +893,7 @@ bool CScript::rDetect(CBotVar* var, CBotVar* result, int& exception, void* user) script->m_returnValue = 1.0f; } - script->m_primaryTask = new CTaskManager(script->m_iMan, script->m_object); + script->m_primaryTask = new CTaskManager(script->m_object); err = script->m_primaryTask->StartTaskWait(0.3f); if ( err != ERR_OK ) { @@ -1065,7 +1073,7 @@ bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user type == OBJECT_MARKKEYd || type == OBJECT_EGG ) { - object = new CObject(script->m_iMan); + object = new CObject(); if ( !object->CreateResource(pos, angle, type) ) { delete object; @@ -1083,7 +1091,7 @@ bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user { CObject* egg; - object = new CObject(script->m_iMan); + object = new CObject(); if ( !object->CreateInsect(pos, angle, type) ) { delete object; @@ -1091,7 +1099,7 @@ bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user return true; } - egg = new CObject(script->m_iMan); + egg = new CObject(); if ( !egg->CreateResource(pos, angle, OBJECT_EGG, 0.0f) ) { delete egg; @@ -1123,7 +1131,7 @@ bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user type == OBJECT_START || type == OBJECT_END ) { - object = new CObject(script->m_iMan); + object = new CObject(); if ( !object->CreateBuilding(pos, angle, 0, type) ) { delete object; @@ -1140,7 +1148,7 @@ bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user type == OBJECT_FLAGy || type == OBJECT_FLAGv ) { - object = new CObject(script->m_iMan); + object = new CObject(); if ( !object->CreateFlag(pos, angle, type) ) { delete object; @@ -1182,7 +1190,7 @@ bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user type == OBJECT_MOBILEdr || type == OBJECT_APOLLO2 ) { - object = new CObject(script->m_iMan); + object = new CObject(); if ( !object->CreateVehicle(pos, angle, type, power, false, false) ) { delete object; @@ -1400,7 +1408,7 @@ bool CScript::rWait(CBotVar* var, CBotVar* result, int& exception, void* user) if ( script->m_primaryTask == 0 ) // no task in progress? { - script->m_primaryTask = new CTaskManager(script->m_iMan, script->m_object); + script->m_primaryTask = new CTaskManager(script->m_object); value = var->GetValFloat(); err = script->m_primaryTask->StartTaskWait(value); if ( err != ERR_OK ) @@ -1431,7 +1439,7 @@ bool CScript::rMove(CBotVar* var, CBotVar* result, int& exception, void* user) if ( script->m_primaryTask == 0 ) // no task in progress? { - script->m_primaryTask = new CTaskManager(script->m_iMan, script->m_object); + script->m_primaryTask = new CTaskManager(script->m_object); value = var->GetValFloat(); err = script->m_primaryTask->StartTaskAdvance(value*g_unit); if ( err != ERR_OK ) @@ -1462,7 +1470,7 @@ bool CScript::rTurn(CBotVar* var, CBotVar* result, int& exception, void* user) if ( script->m_primaryTask == 0 ) // no task in progress? { - script->m_primaryTask = new CTaskManager(script->m_iMan, script->m_object); + script->m_primaryTask = new CTaskManager(script->m_object); value = var->GetValFloat(); err = script->m_primaryTask->StartTaskTurn(-value*Math::PI/180.0f); if ( err != ERR_OK ) @@ -1522,7 +1530,7 @@ bool CScript::rGoto(CBotVar* var, CBotVar* result, int& exception, void* user) if ( script->m_primaryTask == 0 ) // no task in progress? { - script->m_primaryTask = new CTaskManager(script->m_iMan, script->m_object); + script->m_primaryTask = new CTaskManager(script->m_object); if ( !GetPoint(var, exception, pos) ) return true; goal = TGG_DEFAULT; @@ -1601,11 +1609,13 @@ bool CScript::rFind(CBotVar* var, CBotVar* result, int& exception, void* user) bArray = false; } + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + best = 100000.0f; pBest = 0; for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(script->m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; if ( pObj == pThis ) continue; @@ -1684,7 +1694,7 @@ bool CScript::rFind(CBotVar* var, CBotVar* result, int& exception, void* user) crash = TGC_DEFAULT; altitude = 0.0f*g_unit; - script->m_primaryTask = new CTaskManager(script->m_iMan, script->m_object); + script->m_primaryTask = new CTaskManager(script->m_object); err = script->m_primaryTask->StartTaskGoto(pos, altitude, goal, crash); if ( err != ERR_OK ) { @@ -1727,7 +1737,7 @@ bool CScript::rGrab(CBotVar* var, CBotVar* result, int& exception, void* user) if ( script->m_primaryTask == 0 ) // no task in progress? { - script->m_primaryTask = new CTaskManager(script->m_iMan, script->m_object); + script->m_primaryTask = new CTaskManager(script->m_object); if ( var == 0 ) { type = TMA_FFRONT; @@ -1778,7 +1788,7 @@ bool CScript::rDrop(CBotVar* var, CBotVar* result, int& exception, void* user) if ( script->m_primaryTask == 0 ) // no task in progress? { - script->m_primaryTask = new CTaskManager(script->m_iMan, script->m_object); + script->m_primaryTask = new CTaskManager(script->m_object); if ( var == 0 ) type = TMA_FFRONT; else type = static_cast(var->GetValInt()); @@ -1820,7 +1830,7 @@ bool CScript::rSniff(CBotVar* var, CBotVar* result, int& exception, void* user) if ( script->m_primaryTask == 0 ) // no task in progress? { - script->m_primaryTask = new CTaskManager(script->m_iMan, script->m_object); + script->m_primaryTask = new CTaskManager(script->m_object); err = script->m_primaryTask->StartTaskSearch(); if ( err != ERR_OK ) { @@ -1869,7 +1879,7 @@ bool CScript::rReceive(CBotVar* var, CBotVar* result, int& exception, void* user if ( script->m_primaryTask == 0 ) // no task in progress? { - script->m_primaryTask = new CTaskManager(script->m_iMan, script->m_object); + script->m_primaryTask = new CTaskManager(script->m_object); cbs = var->GetValString(); p = cbs; @@ -1939,7 +1949,7 @@ bool CScript::rSend(CBotVar* var, CBotVar* result, int& exception, void* user) if ( script->m_primaryTask == 0 ) // no task in progress? { - script->m_primaryTask = new CTaskManager(script->m_iMan, script->m_object); + script->m_primaryTask = new CTaskManager(script->m_object); cbs = var->GetValString(); p = cbs; @@ -1984,11 +1994,13 @@ CObject* CScript::SearchInfo(CScript* script, CObject* object, float power) iPos = object->GetPosition(0); + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + min = 100000.0f; pBest = 0; for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(script->m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; type = pObj->GetType(); @@ -2147,7 +2159,7 @@ bool CScript::rThump(CBotVar* var, CBotVar* result, int& exception, void* user) if ( script->m_primaryTask == 0 ) // no task in progress? { - script->m_primaryTask = new CTaskManager(script->m_iMan, script->m_object); + script->m_primaryTask = new CTaskManager(script->m_object); err = script->m_primaryTask->StartTaskTerraform(); if ( err != ERR_OK ) { @@ -2176,7 +2188,7 @@ bool CScript::rRecycle(CBotVar* var, CBotVar* result, int& exception, void* user if ( script->m_primaryTask == 0 ) // no task in progress? { - script->m_primaryTask = new CTaskManager(script->m_iMan, script->m_object); + script->m_primaryTask = new CTaskManager(script->m_object); err = script->m_primaryTask->StartTaskRecover(); if ( err != ERR_OK ) { @@ -2238,7 +2250,7 @@ bool CScript::rShield(CBotVar* var, CBotVar* result, int& exception, void* user) { pThis->SetParam(radius); - *script->m_secondaryTask = new CTaskManager(script->m_iMan, script->m_object); + *script->m_secondaryTask = new CTaskManager(script->m_object); err = (*script->m_secondaryTask)->StartTaskShield(TSM_UP, 1000.0f); if ( err != ERR_OK ) { @@ -2311,7 +2323,7 @@ bool CScript::rFire(CBotVar* var, CBotVar* result, int& exception, void* user) if ( script->m_primaryTask == 0 ) // no task in progress? { - script->m_primaryTask = new CTaskManager(script->m_iMan, script->m_object); + script->m_primaryTask = new CTaskManager(script->m_object); type = pThis->GetType(); @@ -2372,7 +2384,7 @@ bool CScript::rAim(CBotVar* var, CBotVar* result, int& exception, void* user) if ( script->m_primaryTask == 0 ) // no task in progress? { - script->m_primaryTask = new CTaskManager(script->m_iMan, script->m_object); + script->m_primaryTask = new CTaskManager(script->m_object); x = var->GetValFloat(); var = var->GetNext(); var == 0 ? y=0.0f : y=var->GetValFloat(); @@ -2689,7 +2701,7 @@ bool CScript::rPenDown(CBotVar* var, CBotVar* result, int& exception, void* user } pThis->SetTraceDown(true); - script->m_primaryTask = new CTaskManager(script->m_iMan, script->m_object); + script->m_primaryTask = new CTaskManager(script->m_object); err = script->m_primaryTask->StartTaskPen(pThis->GetTraceDown(), pThis->GetTraceColor()); if ( err != ERR_OK ) { @@ -2746,7 +2758,7 @@ bool CScript::rPenUp(CBotVar* var, CBotVar* result, int& exception, void* user) { pThis->SetTraceDown(false); - script->m_primaryTask = new CTaskManager(script->m_iMan, script->m_object); + script->m_primaryTask = new CTaskManager(script->m_object); err = script->m_primaryTask->StartTaskPen(pThis->GetTraceDown(), pThis->GetTraceColor()); if ( err != ERR_OK ) { @@ -2790,7 +2802,7 @@ bool CScript::rPenColor(CBotVar* var, CBotVar* result, int& exception, void* use if ( color > 17 ) color = 17; pThis->SetTraceColor(color); - script->m_primaryTask = new CTaskManager(script->m_iMan, script->m_object); + script->m_primaryTask = new CTaskManager(script->m_object); err = script->m_primaryTask->StartTaskPen(pThis->GetTraceDown(), pThis->GetTraceColor()); if ( err != ERR_OK ) { @@ -2836,22 +2848,19 @@ bool CScript::rPenWidth(CBotVar* var, CBotVar* result, int& exception, void* use // Object's constructor. -CScript::CScript(CInstanceManager* iMan, CObject* object, CTaskManager** secondaryTask) +CScript::CScript(CObject* object, CTaskManager** secondaryTask) { - m_iMan = iMan; - m_iMan->AddInstance(CLASS_SCRIPT, this, 100); - - m_engine = static_cast(m_iMan->SearchInstance(CLASS_ENGINE)); - m_main = static_cast(m_iMan->SearchInstance(CLASS_MAIN)); - m_terrain = static_cast(m_iMan->SearchInstance(CLASS_TERRAIN)); - m_water = static_cast(m_iMan->SearchInstance(CLASS_WATER)); + m_engine = Gfx::CEngine::GetInstancePointer(); + m_main = CRobotMain::GetInstancePointer(); + m_terrain = m_main->GetTerrain(); + m_water = m_engine->GetWater(); m_botProg = nullptr; m_object = object; m_primaryTask = nullptr; m_secondaryTask = secondaryTask; - m_interface = static_cast(m_iMan->SearchInstance(CLASS_INTERFACE)); - m_displayText = static_cast(m_iMan->SearchInstance(CLASS_DISPLAYTEXT)); + m_interface = m_main->GetInterface(); + m_displayText = m_main->GetDisplayText(); m_ipf = CBOT_IPF; m_errMode = ERM_STOP; @@ -2938,8 +2947,6 @@ CScript::~CScript() m_script = nullptr; m_len = 0; - - m_iMan->DeleteInstance(CLASS_SCRIPT, this); } diff --git a/src/script/script.h b/src/script/script.h index 674a67e..982d12b 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -29,7 +29,6 @@ #include -class CInstanceManager; class CObject; class CTaskManager; class CRobotMain; @@ -52,7 +51,7 @@ class CWater; class CScript { public: - CScript(CInstanceManager* iMan, CObject* object, CTaskManager** secondaryTask); + CScript(CObject* object, CTaskManager** secondaryTask); ~CScript(); static void InitFonctions(); @@ -178,7 +177,7 @@ private: static bool Process(CScript* script, CBotVar* result, int &exception); static CObject* SearchInfo(CScript* script, CObject* object, float power); - CInstanceManager* m_iMan; +protected: Gfx::CEngine* m_engine; Ui::CInterface* m_interface; Ui::CDisplayText* m_displayText; diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp index 2e44eef..83cbeb6 100644 --- a/src/sound/oalsound/alsound.cpp +++ b/src/sound/oalsound/alsound.cpp @@ -15,8 +15,6 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// alsound.cpp - #include "alsound.h" @@ -29,18 +27,12 @@ ALSound::ALSound() mAudioVolume = 1.0f; mMusicVolume = 1.0f; mMute = false; - mCurrentMusic = nullptr; - auto pointer = CInstanceManager::GetInstancePointer(); - if (pointer != nullptr) - CInstanceManager::GetInstancePointer()->AddInstance(CLASS_SOUND, this); + mCurrentMusic = nullptr; } ALSound::~ALSound() { - auto pointer = CInstanceManager::GetInstancePointer(); - if (pointer != nullptr) - CInstanceManager::GetInstancePointer()->DeleteInstance(CLASS_SOUND, this); CleanUp(); } diff --git a/src/sound/oalsound/alsound.h b/src/sound/oalsound/alsound.h index 530aa5e..bdf06b1 100644 --- a/src/sound/oalsound/alsound.h +++ b/src/sound/oalsound/alsound.h @@ -24,7 +24,6 @@ #include -#include "common/iman.h" #include "common/logger.h" #include "sound/sound.h" diff --git a/src/sound/oalsound/buffer.cpp b/src/sound/oalsound/buffer.cpp index d76b24a..edc3d74 100644 --- a/src/sound/oalsound/buffer.cpp +++ b/src/sound/oalsound/buffer.cpp @@ -14,7 +14,6 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// buffer.cpp #include "buffer.h" diff --git a/src/sound/oalsound/channel.cpp b/src/sound/oalsound/channel.cpp index 2b9af9b..3c8bc50 100644 --- a/src/sound/oalsound/channel.cpp +++ b/src/sound/oalsound/channel.cpp @@ -14,7 +14,6 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// channel.cpp #include "channel.h" @@ -349,4 +348,4 @@ void Channel::PopEnvelope() void Channel::SetLoop(bool loop) { mLoop = loop; -} \ No newline at end of file +} diff --git a/src/sound/sound.h b/src/sound/sound.h index d152f76..70139ea 100644 --- a/src/sound/sound.h +++ b/src/sound/sound.h @@ -26,7 +26,6 @@ #include "math/vector.h" -#include "common/iman.h" #include "common/logger.h" #include @@ -156,11 +155,8 @@ enum SoundNext class CSoundInterface { public: - inline CSoundInterface() { - CInstanceManager::GetInstance().AddInstance(CLASS_SOUND, this); - //m_iMan->AddInstance(CLASS_SOUND, this); - }; - inline virtual ~CSoundInterface() {}; + inline CSoundInterface() {} + inline virtual ~CSoundInterface() {} /** Function to initialize sound device * \param b3D - enable support for 3D sound diff --git a/src/ui/button.cpp b/src/ui/button.cpp index e3dbc30..a68b34d 100644 --- a/src/ui/button.cpp +++ b/src/ui/button.cpp @@ -16,7 +16,6 @@ // * along with this program. If not, see http://www.gnu.org/licenses/. - #include "ui/button.h" #include "common/event.h" diff --git a/src/ui/button.h b/src/ui/button.h index 33a48ee..a9aa020 100644 --- a/src/ui/button.h +++ b/src/ui/button.h @@ -25,31 +25,29 @@ namespace Ui { - class CButton : public CControl - { - public: - CButton(); - virtual ~CButton(); +class CButton : public CControl +{ +public: + CButton(); + virtual ~CButton(); - bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType); + bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType); - bool EventProcess(const Event &event); + bool EventProcess(const Event &event); - void Draw(); + void Draw(); - void SetImmediat(bool bRepeat); - bool GetImmediat(); + void SetImmediat(bool bRepeat); + bool GetImmediat(); - void SetRepeat(bool bRepeat); - bool GetRepeat(); + void SetRepeat(bool bRepeat); + bool GetRepeat(); - protected: - - protected: - bool m_bCapture; - bool m_bImmediat; - bool m_bRepeat; - float m_repeat; - }; +protected: + bool m_bCapture; + bool m_bImmediat; + bool m_bRepeat; + float m_repeat; +}; } diff --git a/src/ui/check.cpp b/src/ui/check.cpp index bc80b7c..761264d 100644 --- a/src/ui/check.cpp +++ b/src/ui/check.cpp @@ -19,7 +19,6 @@ #include "ui/check.h" #include "common/event.h" -#include "common/iman.h" #include "common/misc.h" #include "common/restext.h" diff --git a/src/ui/check.h b/src/ui/check.h index af26add..65bc367 100644 --- a/src/ui/check.h +++ b/src/ui/check.h @@ -22,27 +22,24 @@ #include "ui/control.h" -namespace Gfx{ - class CEngine; +namespace Gfx { +class CEngine; } namespace Ui { - class CCheck : public CControl - { - public: - CCheck(); - virtual ~CCheck(); - bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType); +class CCheck : public CControl +{ +public: + CCheck(); + virtual ~CCheck(); - bool EventProcess(const Event &event); + bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType); - void Draw(); + bool EventProcess(const Event &event); - protected: - - protected: - }; + void Draw(); +}; } diff --git a/src/ui/color.cpp b/src/ui/color.cpp index 65f9770..fd05bd9 100644 --- a/src/ui/color.cpp +++ b/src/ui/color.cpp @@ -19,7 +19,6 @@ #include "ui/color.h" #include "common/event.h" -#include "common/iman.h" #include "common/misc.h" #include "common/restext.h" @@ -37,7 +36,6 @@ const float DELAY2 = 0.1f; // Object's constructor. -//CColor::CColor(CInstanceManager* iMan) : CControl(iMan) CColor::CColor() : CControl() { m_bRepeat = false; diff --git a/src/ui/color.h b/src/ui/color.h index 311a532..ec2c537 100644 --- a/src/ui/color.h +++ b/src/ui/color.h @@ -23,37 +23,34 @@ namespace Gfx{ - class CEngine; - struct Color; +class CEngine; +struct Color; } namespace Ui { - class CColor : public CControl - { - public: - // CColor(CInstanceManager* iMan); - CColor(); - virtual ~CColor(); - bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType); +class CColor : public CControl +{ +public: + CColor(); + virtual ~CColor(); - bool EventProcess(const Event &event); + bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType); - void Draw(); + bool EventProcess(const Event &event); - void SetRepeat(bool bRepeat); - bool GetRepeat(); + void Draw(); - void SetColor(Gfx::Color color); - Gfx::Color GetColor(); + void SetRepeat(bool bRepeat); + bool GetRepeat(); - protected: - - protected: - bool m_bRepeat; - float m_repeat; - Gfx::Color m_color; - }; + void SetColor(Gfx::Color color); + Gfx::Color GetColor(); +protected: + bool m_bRepeat; + float m_repeat; + Gfx::Color m_color; +}; } diff --git a/src/ui/compass.cpp b/src/ui/compass.cpp index 1bc0f8c..ac97cb8 100644 --- a/src/ui/compass.cpp +++ b/src/ui/compass.cpp @@ -15,10 +15,10 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. + #include "ui/compass.h" #include "common/event.h" -#include "common/iman.h" #include "common/misc.h" #include "graphics/core/device.h" @@ -29,7 +29,6 @@ namespace Ui { // Object's constructor. -//CCompass::CCompass(CInstanceManager* iMan) : CControl(iMan) CCompass::CCompass() : CControl() { m_dir = 0.0f; diff --git a/src/ui/compass.h b/src/ui/compass.h index 09eec9d..18546e5 100644 --- a/src/ui/compass.h +++ b/src/ui/compass.h @@ -23,32 +23,29 @@ namespace Gfx { - class CEngine; +class CEngine; } namespace Ui { - class CCompass : public CControl - { - public: - // CCompass(CInstanceManager* iMan); - CCompass(); - virtual ~CCompass(); +class CCompass : public CControl +{ +public: + CCompass(); + virtual ~CCompass(); - bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType); + bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType); - bool EventProcess(const Event &event); + bool EventProcess(const Event &event); - void Draw(); + void Draw(); - void SetDirection(float dir); - float GetDirection(); + void SetDirection(float dir); + float GetDirection(); - protected: - - protected: - float m_dir; - }; +protected: + float m_dir; +}; } diff --git a/src/ui/control.cpp b/src/ui/control.cpp index 718ad3b..6dc92cd 100644 --- a/src/ui/control.cpp +++ b/src/ui/control.cpp @@ -18,25 +18,23 @@ #include "ui/control.h" +#include "app/app.h" + namespace Ui { // Object's constructor. CControl::CControl() { - m_iMan = CInstanceManager::GetInstancePointer(); - - m_engine = static_cast< Gfx::CEngine* > ( m_iMan->SearchInstance(CLASS_ENGINE) ); - m_event = static_cast< CEventQueue* > ( m_iMan->SearchInstance(CLASS_EVENT) ); - m_main = static_cast< CRobotMain* > ( m_iMan->SearchInstance(CLASS_MAIN) ); - m_particle = static_cast< Gfx::CParticle* > (m_iMan->SearchInstance(CLASS_PARTICULE)); - m_sound = static_cast< CSoundInterface* > (m_iMan->SearchInstance(CLASS_SOUND)); - m_eventType = EVENT_NULL; + m_event = CApplication::GetInstancePointer()->GetEventQueue(); + m_sound = CApplication::GetInstancePointer()->GetSound(); + m_engine = Gfx::CEngine::GetInstancePointer(); + m_main = CRobotMain::GetInstancePointer(); + m_particle = m_engine->GetParticle(); + m_eventType = EVENT_NULL; m_state = STATE_ENABLE|STATE_VISIBLE|STATE_GLINT; m_fontSize = Gfx::FONT_SIZE_SMALL; -// m_fontStretch = Gfx::FONT_NORM_STRETCH; //there is font stretching no more master m_fontType = Gfx::FONT_COLOBOT; m_textAlign = Gfx::TEXT_ALIGN_CENTER; //instead m_justify -// m_justif = 0; m_bFocus = false; m_bCapture = false; diff --git a/src/ui/control.h b/src/ui/control.h index 635ae12..7f5077d 100644 --- a/src/ui/control.h +++ b/src/ui/control.h @@ -22,7 +22,6 @@ #include #include "common/event.h" -#include "common/iman.h" #include "common/misc.h" #include "common/restext.h" @@ -39,108 +38,106 @@ namespace Ui { - enum ControlState - { - STATE_ENABLE = (1<<0), // active - STATE_CHECK = (1<<1), // pressed - STATE_HILIGHT = (1<<2), // overflown by mouse - STATE_PRESS = (1<<3), // pressed by mouse - STATE_VISIBLE = (1<<4), // visible - STATE_DEAD = (1<<5), // inaccessible (x) - STATE_DEFAULT = (1<<6), // actuated by RETURN - STATE_OKAY = (1<<7), // green point at the bottom right - STATE_SHADOW = (1<<8), // shadow - STATE_GLINT = (1<<9), // dynamic reflection - STATE_CARD = (1<<10), // tab - STATE_EXTEND = (1<<11), // extended mode - STATE_SIMPLY = (1<<12), // undecorated - STATE_FRAME = (1<<13), // framework highlighting - STATE_WARNING = (1<<14), // framework hatched yellow / black - STATE_VALUE = (1<<15), // displays the value - STATE_RUN = (1<<16) // running program - }; - - - - class CControl - { - public: - CControl(); - virtual ~CControl(); - - virtual bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType); - - virtual bool EventProcess(const Event &event); - - virtual void SetPos(Math::Point pos); - virtual Math::Point GetPos(); - virtual void SetDim(Math::Point dim); - virtual Math::Point GetDim(); - virtual bool SetState(int state, bool bState); - virtual bool SetState(int state); - virtual bool ClearState(int state); - virtual bool TestState(int state); - virtual int GetState(); - virtual void SetIcon(int icon); - virtual int GetIcon(); - virtual void SetName(std::string name, bool bTooltip=true); - virtual std::string GetName(); - virtual void SetTextAlign(Gfx::TextAlign mode); - virtual int GetTextAlign(); - virtual void SetFontSize(float size); - virtual float GetFontSize(); - virtual void SetFontStretch(float stretch); - virtual float GetFontStretch(); - virtual void SetFontType(Gfx::FontType font); - virtual Gfx::FontType GetFontType(); - virtual bool SetTooltip(std::string name); - virtual bool GetTooltip(Math::Point pos, std::string &name); - virtual void SetFocus(bool bFocus); - virtual bool GetFocus(); - - virtual EventType GetEventType(); - - virtual void Draw(); - - protected: - void GlintDelete(); - void GlintCreate(Math::Point ref, bool bLeft=true, bool bUp=true); - void GlintFrame(const Event &event); - void DrawPart(int icon, float zoom, float ex); - void DrawIcon(Math::Point pos, Math::Point dim, Math::Point uv1, Math::Point uv2, float ex=0.0f); - void DrawIcon(Math::Point pos, Math::Point dim, Math::Point uv1, Math::Point uv2, Math::Point corner, float ex); - void DrawWarning(Math::Point pos, Math::Point dim); - void DrawShadow(Math::Point pos, Math::Point dim, float deep=1.0f); - virtual bool Detect(Math::Point pos); - - protected: - CInstanceManager* m_iMan; - Gfx::CEngine* m_engine; - Gfx::CParticle* m_particle; - CEventQueue* m_event; - CRobotMain* m_main; - CSoundInterface* m_sound; - - Math::Point m_pos; // corner upper / left - Math::Point m_dim; // dimensions - int m_icon; - EventType m_eventType; // message to send when clicking - int m_state; // states (STATE_ *) - float m_fontSize; // size of the button name - float m_fontStretch; // stretch of the font - Gfx::FontType m_fontType; // type of font - Gfx::TextAlign m_textAlign; //type of alignment //comes in the place of m_justif - // int m_justif; // type of justification (-1,0,1) - std::string m_name; // name of the button - std::string m_tooltip; // name of tooltip - bool m_bFocus; - bool m_bCapture; - - bool m_bGlint; - Math::Point m_glintCorner1; - Math::Point m_glintCorner2; - float m_glintProgress; - Math::Point m_glintMouse; - }; - -} +enum ControlState +{ + STATE_ENABLE = (1<<0), // active + STATE_CHECK = (1<<1), // pressed + STATE_HILIGHT = (1<<2), // overflown by mouse + STATE_PRESS = (1<<3), // pressed by mouse + STATE_VISIBLE = (1<<4), // visible + STATE_DEAD = (1<<5), // inaccessible (x) + STATE_DEFAULT = (1<<6), // actuated by RETURN + STATE_OKAY = (1<<7), // green point at the bottom right + STATE_SHADOW = (1<<8), // shadow + STATE_GLINT = (1<<9), // dynamic reflection + STATE_CARD = (1<<10), // tab + STATE_EXTEND = (1<<11), // extended mode + STATE_SIMPLY = (1<<12), // undecorated + STATE_FRAME = (1<<13), // framework highlighting + STATE_WARNING = (1<<14), // framework hatched yellow / black + STATE_VALUE = (1<<15), // displays the value + STATE_RUN = (1<<16) // running program +}; + + + +class CControl +{ +public: + CControl(); + virtual ~CControl(); + + virtual bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType); + + virtual bool EventProcess(const Event &event); + + virtual void SetPos(Math::Point pos); + virtual Math::Point GetPos(); + virtual void SetDim(Math::Point dim); + virtual Math::Point GetDim(); + virtual bool SetState(int state, bool bState); + virtual bool SetState(int state); + virtual bool ClearState(int state); + virtual bool TestState(int state); + virtual int GetState(); + virtual void SetIcon(int icon); + virtual int GetIcon(); + virtual void SetName(std::string name, bool bTooltip=true); + virtual std::string GetName(); + virtual void SetTextAlign(Gfx::TextAlign mode); + virtual int GetTextAlign(); + virtual void SetFontSize(float size); + virtual float GetFontSize(); + virtual void SetFontStretch(float stretch); + virtual float GetFontStretch(); + virtual void SetFontType(Gfx::FontType font); + virtual Gfx::FontType GetFontType(); + virtual bool SetTooltip(std::string name); + virtual bool GetTooltip(Math::Point pos, std::string &name); + virtual void SetFocus(bool bFocus); + virtual bool GetFocus(); + + virtual EventType GetEventType(); + + virtual void Draw(); + +protected: + void GlintDelete(); + void GlintCreate(Math::Point ref, bool bLeft=true, bool bUp=true); + void GlintFrame(const Event &event); + void DrawPart(int icon, float zoom, float ex); + void DrawIcon(Math::Point pos, Math::Point dim, Math::Point uv1, Math::Point uv2, float ex=0.0f); + void DrawIcon(Math::Point pos, Math::Point dim, Math::Point uv1, Math::Point uv2, Math::Point corner, float ex); + void DrawWarning(Math::Point pos, Math::Point dim); + void DrawShadow(Math::Point pos, Math::Point dim, float deep=1.0f); + virtual bool Detect(Math::Point pos); + +protected: + Gfx::CEngine* m_engine; + Gfx::CParticle* m_particle; + CEventQueue* m_event; + CRobotMain* m_main; + CSoundInterface* m_sound; + + Math::Point m_pos; // corner upper / left + Math::Point m_dim; // dimensions + int m_icon; + EventType m_eventType; // message to send when clicking + int m_state; // states (STATE_ *) + float m_fontSize; // size of the button name + float m_fontStretch; // stretch of the font + Gfx::FontType m_fontType; // type of font + Gfx::TextAlign m_textAlign; //type of alignment //comes in the place of m_justif + std::string m_name; // name of the button + std::string m_tooltip; // name of tooltip + bool m_bFocus; + bool m_bCapture; + + bool m_bGlint; + Math::Point m_glintCorner1; + Math::Point m_glintCorner2; + float m_glintProgress; + Math::Point m_glintMouse; +}; + +} // namespace Ui diff --git a/src/ui/displayinfo.cpp b/src/ui/displayinfo.cpp index 29499bd..a9e754f 100644 --- a/src/ui/displayinfo.cpp +++ b/src/ui/displayinfo.cpp @@ -15,17 +15,10 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// displayinfo.cpp - #include "ui/displayinfo.h" -#include "ui/interface.h" -#include "ui/button.h" -#include "ui/slider.h" -#include "ui/edit.h" -#include "ui/group.h" -#include "ui/window.h" +#include "app/app.h" #include "common/iman.h" #include "common/misc.h" @@ -43,25 +36,28 @@ #include "script/cbottoken.h" +#include "ui/interface.h" +#include "ui/button.h" +#include "ui/slider.h" +#include "ui/edit.h" +#include "ui/group.h" +#include "ui/window.h" + #include namespace Ui { // Object's constructor. -//CDisplayInfo::CDisplayInfo(CInstanceManager* iMan) CDisplayInfo::CDisplayInfo() { - m_iMan = CInstanceManager::GetInstancePointer(); - m_iMan->AddInstance(CLASS_STUDIO, this); - - m_engine = static_cast (m_iMan->SearchInstance(CLASS_ENGINE)); - m_event = static_cast (m_iMan->SearchInstance(CLASS_EVENT)); - m_interface = static_cast (m_iMan->SearchInstance(CLASS_INTERFACE)); - m_main = static_cast (m_iMan->SearchInstance(CLASS_MAIN)); - m_camera = static_cast (m_iMan->SearchInstance(CLASS_CAMERA)); - m_particle = static_cast (m_iMan->SearchInstance(CLASS_PARTICULE)); - m_light = static_cast (m_iMan->SearchInstance(CLASS_LIGHT)); + m_event = CApplication::GetInstancePointer()->GetEventQueue(); + m_engine = Gfx::CEngine::GetInstancePointer(); + m_particle = m_engine->GetParticle(); + m_light = m_engine->GetLightManager(); + m_main = CRobotMain::GetInstancePointer(); + m_interface = m_main->GetInterface(); + m_camera = m_main->GetCamera(); m_bInfoMaximized = true; m_bInfoMinimized = false; @@ -77,7 +73,6 @@ CDisplayInfo::CDisplayInfo() CDisplayInfo::~CDisplayInfo() { - m_iMan->DeleteInstance(CLASS_STUDIO, this); } @@ -927,9 +922,11 @@ CObject* CDisplayInfo::SearchToto() CObject* pObj; int i; + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; type = pObj->GetType(); @@ -1012,6 +1009,8 @@ void CDisplayInfo::CreateObjectsFile() int i; bool bRadar, bAtLeast; + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + file = fopen("help\\objects.txt", "w"); if ( file == 0 ) return; @@ -1019,7 +1018,7 @@ void CDisplayInfo::CreateObjectsFile() bRadar = false; for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; if ( !pObj->GetActif() ) continue; diff --git a/src/ui/displayinfo.h b/src/ui/displayinfo.h index 2eabbf2..ab42d62 100644 --- a/src/ui/displayinfo.h +++ b/src/ui/displayinfo.h @@ -25,7 +25,6 @@ #include "graphics/engine/camera.h" -class CInstanceManager; class CRobotMain; class CObject; class CEventQueue; @@ -33,67 +32,66 @@ class CEventQueue; struct Event; namespace Gfx { - class CEngine; - class CParticle; - class CLightManager; +class CEngine; +class CParticle; +class CLightManager; } namespace Ui { - class CInterface; - - class CDisplayInfo - { - public: - // CDisplayInfo(CInstanceManager* iMan); - CDisplayInfo(); - ~CDisplayInfo(); - - bool EventProcess(const Event &event); - - void StartDisplayInfo(std::string filename, int index, bool bSoluce); - void StopDisplayInfo(); - - void SetPosition(int pos); - int GetPosition(); - - protected: - bool EventFrame(const Event &event); - void HyperUpdate(); - void AdjustDisplayInfo(Math::Point wpos, Math::Point wdim); - void ChangeIndexButton(int index); - void UpdateIndexButton(); - void UpdateCopyButton(); - void ViewDisplayInfo(); - CObject* SearchToto(); - void CreateObjectsFile(); - - protected: - CInstanceManager* m_iMan; - Gfx::CEngine* m_engine; - CEventQueue* m_event; - CRobotMain* m_main; - Gfx::CCamera* m_camera; - CInterface* m_interface; - Gfx::CParticle* m_particle; - Gfx::CLightManager* m_light; - - bool m_bInfoMaximized; - bool m_bInfoMinimized; - - int m_index; - Gfx::CameraType m_infoCamera; - Math::Point m_infoNormalPos; - Math::Point m_infoNormalDim; - Math::Point m_infoActualPos; - Math::Point m_infoActualDim; - Math::Point m_infoFinalPos; - Math::Point m_infoFinalDim; - int m_lightSuppl; - bool m_bEditLock; - bool m_bInitPause; - bool m_bSoluce; - CObject* m_toto; - }; - -} +class CInterface; + +class CDisplayInfo +{ +public: + CDisplayInfo(); + ~CDisplayInfo(); + + bool EventProcess(const Event &event); + + void StartDisplayInfo(std::string filename, int index, bool bSoluce); + void StopDisplayInfo(); + + void SetPosition(int pos); + int GetPosition(); + +protected: + bool EventFrame(const Event &event); + void HyperUpdate(); + void AdjustDisplayInfo(Math::Point wpos, Math::Point wdim); + void ChangeIndexButton(int index); + void UpdateIndexButton(); + void UpdateCopyButton(); + void ViewDisplayInfo(); + CObject* SearchToto(); + void CreateObjectsFile(); + +protected: + Gfx::CEngine* m_engine; + CEventQueue* m_event; + CRobotMain* m_main; + Gfx::CCamera* m_camera; + CInterface* m_interface; + Gfx::CParticle* m_particle; + Gfx::CLightManager* m_light; + + bool m_bInfoMaximized; + bool m_bInfoMinimized; + + int m_index; + Gfx::CameraType m_infoCamera; + Math::Point m_infoNormalPos; + Math::Point m_infoNormalDim; + Math::Point m_infoActualPos; + Math::Point m_infoActualDim; + Math::Point m_infoFinalPos; + Math::Point m_infoFinalDim; + int m_lightSuppl; + bool m_bEditLock; + bool m_bInitPause; + bool m_bSoluce; + CObject* m_toto; +}; + + +} // namespace Ui diff --git a/src/ui/displaytext.cpp b/src/ui/displaytext.cpp index 7c60f8b..630b385 100644 --- a/src/ui/displaytext.cpp +++ b/src/ui/displaytext.cpp @@ -15,16 +15,10 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// displaytext.cpp - #include "ui/displaytext.h" -#include "ui/interface.h" -#include "ui/button.h" -#include "ui/label.h" -#include "ui/window.h" -#include "ui/group.h" +#include "app/app.h" #include "common/event.h" #include "common/iman.h" @@ -36,6 +30,11 @@ #include "object/motion/motion.h" #include "object/motion/motiontoto.h" +#include "ui/interface.h" +#include "ui/button.h" +#include "ui/label.h" +#include "ui/window.h" +#include "ui/group.h" @@ -46,20 +45,13 @@ const float FONTSIZE = 12.0f; // Object's constructor. -//CDisplayText::CDisplayText(CInstanceManager* iMan) CDisplayText::CDisplayText() { - int i; + m_engine = Gfx::CEngine::GetInstancePointer(); + m_interface = CRobotMain::GetInstancePointer()->GetInterface(); + m_sound = CApplication::GetInstancePointer()->GetSound(); -// m_iMan = iMan; - m_iMan = CInstanceManager::GetInstancePointer(); - m_iMan->AddInstance(CLASS_DISPLAYTEXT, this); - - m_engine = static_cast(m_iMan->SearchInstance(CLASS_ENGINE)); - m_interface = static_cast(m_iMan->SearchInstance(CLASS_INTERFACE)); - m_sound = static_cast(m_iMan->SearchInstance(CLASS_SOUND)); - - for ( i=0 ; iDeleteInstance(CLASS_DISPLAYTEXT, this); } @@ -598,9 +589,11 @@ CObject* CDisplayText::SearchToto() CObject* pObj; int i; + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; type = pObj->GetType(); diff --git a/src/ui/displaytext.h b/src/ui/displaytext.h index 5714cc5..94572a8 100644 --- a/src/ui/displaytext.h +++ b/src/ui/displaytext.h @@ -27,16 +27,14 @@ -class CInstanceManager; -//class CD3DEngine class CObject; class CSound; namespace Gfx { - class CEngine; +class CEngine; } -namespace Ui {; +namespace Ui { class CInterface; @@ -54,7 +52,6 @@ const int MAXDTLINE = 4; class CDisplayText { public: -// CDisplayText(CInstanceManager* iMan); CDisplayText(); ~CDisplayText(); @@ -87,7 +84,6 @@ protected: CObject* SearchToto(); protected: - CInstanceManager* m_iMan; Gfx::CEngine* m_engine; Ui::CInterface* m_interface; CSoundInterface* m_sound; @@ -104,4 +100,5 @@ protected: }; -} +} // namespace Ui + diff --git a/src/ui/edit.cpp b/src/ui/edit.cpp index 0e50852..64004bb 100644 --- a/src/ui/edit.cpp +++ b/src/ui/edit.cpp @@ -15,11 +15,11 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// edit.cpp -#include "app/app.h" #include "ui/edit.h" +#include "app/app.h" + #include namespace Ui { diff --git a/src/ui/edit.h b/src/ui/edit.h index 75572c7..8f46445 100644 --- a/src/ui/edit.h +++ b/src/ui/edit.h @@ -32,7 +32,6 @@ #include "common/event.h" #include "common/misc.h" -#include "common/iman.h" #include "common/restext.h" #include diff --git a/src/ui/editvalue.cpp b/src/ui/editvalue.cpp index 3cc856d..6397a73 100644 --- a/src/ui/editvalue.cpp +++ b/src/ui/editvalue.cpp @@ -15,22 +15,21 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// editvalue.cpp +#include "ui/editvalue.h" #include "common/event.h" #include "common/misc.h" -#include "common/iman.h" + #include "ui/edit.h" #include "ui/button.h" -#include "ui/editvalue.h" + namespace Ui { // Object's constructor. -//CEditValue::CEditValue(CInstanceManager* iMan) : CControl(iMan) CEditValue::CEditValue() : CControl () { m_edit = 0; diff --git a/src/ui/editvalue.h b/src/ui/editvalue.h index 1469b69..5d6e643 100644 --- a/src/ui/editvalue.h +++ b/src/ui/editvalue.h @@ -44,7 +44,6 @@ class CButton; class CEditValue : public CControl { public: -// CEditValue(CInstanceManager* iMan); CEditValue(); virtual ~CEditValue(); diff --git a/src/ui/gauge.cpp b/src/ui/gauge.cpp index b1fa057..c98e3b6 100644 --- a/src/ui/gauge.cpp +++ b/src/ui/gauge.cpp @@ -15,8 +15,6 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// gauge.cpp - #include "ui/gauge.h" @@ -24,7 +22,6 @@ namespace Ui { // Object's constructor. -//CGauge::CGauge(CInstanceManager* iMan) : CControl(iMan) CGauge::CGauge() : CControl() { m_level = 0.0f; diff --git a/src/ui/gauge.h b/src/ui/gauge.h index f4a008f..a2b689a 100644 --- a/src/ui/gauge.h +++ b/src/ui/gauge.h @@ -32,7 +32,6 @@ namespace Ui { class CGauge : public CControl { public: - // CGauge(CInstanceManager* iMan); CGauge(); virtual ~CGauge(); diff --git a/src/ui/group.cpp b/src/ui/group.cpp index 67369d9..c3c7028 100644 --- a/src/ui/group.cpp +++ b/src/ui/group.cpp @@ -14,14 +14,13 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// group.cpp #include "ui/group.h" #include "common/event.h" #include "common/misc.h" -#include "common/iman.h" #include "common/restext.h" + #include "graphics/engine/engine.h" @@ -32,7 +31,6 @@ namespace Ui { // Object's constructor. -//CGroup::CGroup(CInstanceManager* iMan) : CControl(iMan) CGroup::CGroup() : CControl() { } diff --git a/src/ui/group.h b/src/ui/group.h index bfeef74..fd31716 100644 --- a/src/ui/group.h +++ b/src/ui/group.h @@ -30,7 +30,6 @@ namespace Ui { class CGroup : public CControl { public: -// CGroup(CInstanceManager* iMan); CGroup(); virtual ~CGroup(); diff --git a/src/ui/image.cpp b/src/ui/image.cpp index ad838fa..94b9586 100644 --- a/src/ui/image.cpp +++ b/src/ui/image.cpp @@ -15,16 +15,15 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// image.cpp - +#include "ui/image.h" -#include "graphics/engine/engine.h" #include "common/event.h" #include "common/misc.h" -#include "common/iman.h" #include "common/restext.h" -#include "ui/image.h" + +#include "graphics/engine/engine.h" + #include #include @@ -33,7 +32,6 @@ namespace Ui { // Object's constructor. -//CImage::CImage(CInstanceManager* iMan) : CControl(iMan) CImage::CImage() : CControl() { m_filename[0] = 0; diff --git a/src/ui/image.h b/src/ui/image.h index b73a5ae..c40828c 100644 --- a/src/ui/image.h +++ b/src/ui/image.h @@ -32,7 +32,6 @@ namespace Ui { class CImage : public CControl { public: -// CImage(CInstanceManager* iMan); CImage (); virtual ~CImage(); diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp index 885cef4..24d2626 100644 --- a/src/ui/interface.cpp +++ b/src/ui/interface.cpp @@ -15,20 +15,18 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// interface.cpp - #include "ui/interface.h" +#include "app/app.h" + namespace Ui { CInterface::CInterface() { - m_iMan = CInstanceManager::GetInstancePointer(); - m_iMan->AddInstance(CLASS_INTERFACE, this); - m_event = static_cast( m_iMan->SearchInstance(CLASS_EVENT) ); - m_engine = static_cast( m_iMan->SearchInstance(CLASS_ENGINE) ); + m_event = CApplication::GetInstancePointer()->GetEventQueue(); + m_engine = Gfx::CEngine::GetInstancePointer(); m_camera = nullptr; for (int i = 0; i < MAXCONTROL; i++ ) @@ -42,7 +40,6 @@ CInterface::CInterface() CInterface::~CInterface() { Flush(); - m_iMan->DeleteInstance(CLASS_INTERFACE, this); } @@ -278,15 +275,18 @@ CControl* CInterface::SearchControl(EventType eventMsg) bool CInterface::EventProcess(const Event &event) { - if (event.type == EVENT_MOUSE_MOVE) { - if (m_camera == nullptr) { - m_camera = static_cast(m_iMan->SearchInstance(CLASS_CAMERA)); - } + if (event.type == EVENT_MOUSE_MOVE) + { + if (m_camera == nullptr) + m_camera = CRobotMain::GetInstancePointer()->GetCamera(); + m_engine->SetMouseType(m_camera->GetMouseDef(event.mousePos)); } - for (int i = MAXCONTROL-1; i >= 0; i--) { - if (m_table[i] != nullptr && m_table[i]->TestState(STATE_ENABLE)) { + for (int i = MAXCONTROL-1; i >= 0; i--) + { + if (m_table[i] != nullptr && m_table[i]->TestState(STATE_ENABLE)) + { if ( !m_table[i]->EventProcess(event) ) return false; } @@ -300,8 +300,10 @@ bool CInterface::EventProcess(const Event &event) bool CInterface::GetTooltip(Math::Point pos, std::string &name) { - for (int i = MAXCONTROL-1; i >= 0; i--) { - if (m_table[i] != nullptr) { + for (int i = MAXCONTROL-1; i >= 0; i--) + { + if (m_table[i] != nullptr) + { if (m_table[i]->GetTooltip(pos, name)) return true; } @@ -314,16 +316,8 @@ bool CInterface::GetTooltip(Math::Point pos, std::string &name) void CInterface::Draw() { - /*ZeroMemory( &material, sizeof(D3DMATERIAL7) ); - material.diffuse.r = 1.0f; - material.diffuse.g = 1.0f; - material.diffuse.b = 1.0f; - material.ambient.r = 0.5f; - material.ambient.g = 0.5f; - material.ambient.b = 0.5f; - m_engine->SetMaterial(material);*/ - - for (int i = 0; i < MAXCONTROL; i++) { + for (int i = 0; i < MAXCONTROL; i++) + { if ( m_table[i] != nullptr ) m_table[i]->Draw(); } diff --git a/src/ui/interface.h b/src/ui/interface.h index 1496541..ebc80e7 100644 --- a/src/ui/interface.h +++ b/src/ui/interface.h @@ -19,11 +19,8 @@ #pragma once -#include - #include "common/event.h" #include "common/misc.h" -#include "common/iman.h" #include "math/point.h" @@ -49,6 +46,8 @@ #include "ui/map.h" #include "ui/window.h" +#include + namespace Ui { const int MAXCONTROL = 100; @@ -92,7 +91,6 @@ class CInterface int GetNextFreeControl(); template inline T* CreateControl(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); - CInstanceManager* m_iMan; CEventQueue* m_event; Gfx::CEngine* m_engine; Gfx::CCamera* m_camera; diff --git a/src/ui/key.cpp b/src/ui/key.cpp index 9a76127..b181f70 100644 --- a/src/ui/key.cpp +++ b/src/ui/key.cpp @@ -15,6 +15,7 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. + #include "ui/key.h" #include "common/global.h" diff --git a/src/ui/key.h b/src/ui/key.h index 2332c9b..d8e935c 100644 --- a/src/ui/key.h +++ b/src/ui/key.h @@ -24,7 +24,6 @@ #include "ui/control.h" -#include "common/iman.h" #include "common/event.h" #include "common/restext.h" #include "common/key.h" diff --git a/src/ui/label.cpp b/src/ui/label.cpp index af65ab2..b5195b5 100644 --- a/src/ui/label.cpp +++ b/src/ui/label.cpp @@ -15,8 +15,6 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// label.cpp - #include "ui/label.h" diff --git a/src/ui/list.cpp b/src/ui/list.cpp index 4356ea4..84aa8ca 100644 --- a/src/ui/list.cpp +++ b/src/ui/list.cpp @@ -15,8 +15,6 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// list.cpp - #include "ui/list.h" diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index cf451e5..920d958 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -14,22 +14,24 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// maindialog.cpp #include "ui/maindialog.h" #include "app/app.h" + #include "common/global.h" #include "common/event.h" #include "common/logger.h" #include "common/misc.h" #include "common/profile.h" -#include "common/iman.h" #include "common/restext.h" #include "common/logger.h" + #include "object/robotmain.h" + #include "script/cmdtoken.h" #include "sound/sound.h" + #include "ui/interface.h" #include "ui/button.h" #include "ui/color.h" @@ -54,8 +56,7 @@ //TODO Get rid of all sprintf's -namespace Ui -{ +namespace Ui { const int KEY_VISIBLE = 6; // number of visible keys redefinable @@ -106,20 +107,16 @@ namespace fs = boost::filesystem; // Constructor of robot application. -CMainDialog::CMainDialog(CInstanceManager* iMan) +CMainDialog::CMainDialog() { - m_iMan = iMan; - m_iMan->AddInstance(CLASS_DIALOG, this); - - m_app = CApplication::GetInstancePointer(); - - m_main = static_cast(m_iMan->SearchInstance(CLASS_MAIN)); - m_interface = static_cast(m_iMan->SearchInstance(CLASS_INTERFACE)); - m_eventQueue = static_cast(m_iMan->SearchInstance(CLASS_EVENT)); - m_engine = static_cast(m_iMan->SearchInstance(CLASS_ENGINE)); - m_particle = static_cast(m_iMan->SearchInstance(CLASS_PARTICULE)); - m_camera = static_cast(m_iMan->SearchInstance(CLASS_CAMERA)); - m_sound = static_cast(m_iMan->SearchInstance(CLASS_SOUND)); + m_app = CApplication::GetInstancePointer(); + m_eventQueue = m_app->GetEventQueue(); + m_sound = m_app->GetSound(); + m_main = CRobotMain::GetInstancePointer(); + m_interface = m_main->GetInterface(); + m_camera = m_main->GetCamera(); + m_engine = Gfx::CEngine::GetInstancePointer(); + m_particle = m_engine->GetParticle(); m_phase = PHASE_NAME; m_phaseSetup = PHASE_SETUPg; diff --git a/src/ui/maindialog.h b/src/ui/maindialog.h index 51c6f2e..be61299 100644 --- a/src/ui/maindialog.h +++ b/src/ui/maindialog.h @@ -20,20 +20,18 @@ #include "graphics/core/color.h" + #include "object/robotmain.h" -class CInstanceManager; class CEventQueue; class CSoundInterface; -namespace Gfx -{ +namespace Gfx { class CEngine; class CParticle; -}; +} -namespace Ui -{ +namespace Ui { class CInterface; class CWindow; @@ -64,7 +62,7 @@ struct GamerPerso class CMainDialog { public: - CMainDialog(CInstanceManager* iMan); + CMainDialog(); ~CMainDialog(); bool EventProcess(const Event &event); @@ -172,7 +170,6 @@ protected: void ChangeKey(EventType event); protected: - CInstanceManager* m_iMan; CApplication* m_app; CRobotMain* m_main; CEventQueue* m_eventQueue; @@ -260,3 +257,4 @@ protected: }; } // namespace Ui + diff --git a/src/ui/mainmap.cpp b/src/ui/mainmap.cpp index b70bad9..1143a77 100644 --- a/src/ui/mainmap.cpp +++ b/src/ui/mainmap.cpp @@ -15,11 +15,11 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// mainmap.cpp - #include "ui/mainmap.h" +#include "app/app.h" + namespace Ui { @@ -32,12 +32,9 @@ const float ZOOM_MAX = 16.0f; CMainMap::CMainMap() { - m_iMan = CInstanceManager::GetInstancePointer(); - m_iMan->AddInstance(CLASS_MAP, this); - - m_interface = static_cast(m_iMan->SearchInstance(CLASS_INTERFACE)); - m_event = static_cast(m_iMan->SearchInstance(CLASS_EVENT)); - m_engine = static_cast(m_iMan->SearchInstance(CLASS_ENGINE)); + m_interface = CRobotMain::GetInstancePointer()->GetInterface(); + m_event = CApplication::GetInstancePointer()->GetEventQueue(); + m_engine = Gfx::CEngine::GetInstancePointer(); m_mapMode = 1; m_bFixImage = false; diff --git a/src/ui/mainmap.h b/src/ui/mainmap.h index 35aae4c..9d0d72f 100644 --- a/src/ui/mainmap.h +++ b/src/ui/mainmap.h @@ -20,9 +20,13 @@ #pragma once #include "common/event.h" + #include "graphics/core/color.h" + #include "math/point.h" + #include "object/object.h" + #include "ui/interface.h" @@ -55,7 +59,6 @@ class CMainMap void CenterMap(); protected: - CInstanceManager* m_iMan; CEventQueue* m_event; Gfx::CEngine* m_engine; CInterface* m_interface; diff --git a/src/ui/mainshort.cpp b/src/ui/mainshort.cpp index 55b9612..d33482c 100644 --- a/src/ui/mainshort.cpp +++ b/src/ui/mainshort.cpp @@ -15,24 +15,24 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// mainshort.cpp - #include "ui/mainshort.h" +#include "app/app.h" + +#include "common/iman.h" + + namespace Ui { // Constructor of the application card. CMainShort::CMainShort() { - m_iMan = CInstanceManager::GetInstancePointer(); - m_iMan->AddInstance(CLASS_SHORT, this); - - m_interface = static_cast(m_iMan->SearchInstance(CLASS_INTERFACE)); - m_event = static_cast(m_iMan->SearchInstance(CLASS_EVENT)); - m_engine = static_cast(m_iMan->SearchInstance(CLASS_ENGINE)); - m_main = static_cast(m_iMan->SearchInstance(CLASS_MAIN)); + m_event = CApplication::GetInstancePointer()->GetEventQueue(); + m_engine = Gfx::CEngine::GetInstancePointer(); + m_main = CRobotMain::GetInstancePointer(); + m_interface = m_main->GetInterface(); FlushShortcuts(); } @@ -137,9 +137,11 @@ bool CMainShort::CreateShortcuts() m_shortcuts[rank] = 0; rank ++; + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == nullptr ) break; if ( !pObj->GetActif() ) continue; diff --git a/src/ui/mainshort.h b/src/ui/mainshort.h index 0912e68..d679eb0 100644 --- a/src/ui/mainshort.h +++ b/src/ui/mainshort.h @@ -19,12 +19,16 @@ #pragma once -#include "ui/interface.h" #include "common/event.h" + #include "math/point.h" + #include "object/object.h" + #include "graphics/engine/engine.h" +#include "ui/interface.h" + namespace Ui { @@ -46,7 +50,6 @@ class CMainShort protected: protected: - CInstanceManager* m_iMan; CEventQueue* m_event; Gfx::CEngine* m_engine; CInterface* m_interface; diff --git a/src/ui/map.cpp b/src/ui/map.cpp index b852976..33d0fb1 100644 --- a/src/ui/map.cpp +++ b/src/ui/map.cpp @@ -15,8 +15,6 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// map.cpp - #include "ui/map.h" @@ -31,9 +29,9 @@ namespace Ui { CMap::CMap() : CControl() { - m_main = static_cast(m_iMan->SearchInstance(CLASS_MAIN)); - m_terrain = static_cast(m_iMan->SearchInstance(CLASS_TERRAIN)); - m_water = static_cast(m_iMan->SearchInstance(CLASS_WATER)); + m_main = CRobotMain::GetInstancePointer(); + m_terrain = m_main->GetTerrain(); + m_water = Gfx::CEngine::GetInstancePointer()->GetWater(); m_bEnable = true; m_time = 0.0f; diff --git a/src/ui/map.h b/src/ui/map.h index 9e1767c..258dcdf 100644 --- a/src/ui/map.h +++ b/src/ui/map.h @@ -22,11 +22,7 @@ #include "ui/control.h" -#include "object/object.h" -#include "object/robotmain.h" - #include "common/event.h" -#include "common/iman.h" #include "graphics/engine/terrain.h" #include "graphics/engine/water.h" @@ -36,6 +32,9 @@ #include "math/geometry.h" +#include "object/object.h" +#include "object/robotmain.h" + namespace Ui { diff --git a/src/ui/scroll.cpp b/src/ui/scroll.cpp index 17f210e..ff7451d 100644 --- a/src/ui/scroll.cpp +++ b/src/ui/scroll.cpp @@ -15,14 +15,14 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// scroll.cpp #include "ui/scroll.h" #include "common/event.h" #include "common/misc.h" -#include "common/iman.h" + #include "graphics/engine/engine.h" + #include "ui/button.h" diff --git a/src/ui/scroll.h b/src/ui/scroll.h index 52b60bc..57d6f8f 100644 --- a/src/ui/scroll.h +++ b/src/ui/scroll.h @@ -20,9 +20,10 @@ #pragma once -#include "ui/control.h" #include "common/event.h" +#include "ui/control.h" + namespace Ui { class CButton; diff --git a/src/ui/shortcut.cpp b/src/ui/shortcut.cpp index 18b8f31..4462140 100644 --- a/src/ui/shortcut.cpp +++ b/src/ui/shortcut.cpp @@ -15,13 +15,12 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// shortcut.cpp #include "ui/shortcut.h" #include "common/event.h" #include "common/misc.h" -#include "common/iman.h" + #include "graphics/engine/engine.h" #include "graphics/core/device.h" @@ -31,7 +30,6 @@ namespace Ui { // Object's constructor. -//CShortcut::CShortcut(CInstanceManager* iMan) : CControl(iMan) CShortcut::CShortcut() : CControl() { m_time = 0.0f; diff --git a/src/ui/slider.cpp b/src/ui/slider.cpp index ca907fe..f516e70 100644 --- a/src/ui/slider.cpp +++ b/src/ui/slider.cpp @@ -15,15 +15,15 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// slider.cpp #include "ui/slider.h" #include "common/event.h" #include "common/misc.h" -#include "common/iman.h" + #include "graphics/engine/engine.h" #include "graphics/engine/text.h" + #include "ui/button.h" #include diff --git a/src/ui/studio.cpp b/src/ui/studio.cpp index 7aa2d22..bf2ff33 100644 --- a/src/ui/studio.cpp +++ b/src/ui/studio.cpp @@ -15,23 +15,26 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// studio.cpp - -#include "studio.h" +#include "ui/studio.h" #include "CBot/CBotDll.h" #include "app/app.h" + #include "common/event.h" -#include "common/iman.h" #include "common/misc.h" + #include "graphics/engine/camera.h" #include "graphics/engine/engine.h" + #include "object/object.h" + #include "script/cbottoken.h" #include "script/script.h" + #include "sound/sound.h" + #include "ui/check.h" #include "ui/control.h" #include "ui/color.h" @@ -61,16 +64,13 @@ namespace Ui { CStudio::CStudio() { - m_iMan = CInstanceManager::GetInstancePointer(); - m_iMan->AddInstance(CLASS_STUDIO, this); - - m_engine = static_cast(m_iMan->SearchInstance(CLASS_ENGINE)); - m_event = static_cast(m_iMan->SearchInstance(CLASS_EVENT)); - m_interface = static_cast(m_iMan->SearchInstance(CLASS_INTERFACE)); - m_main = static_cast(m_iMan->SearchInstance(CLASS_MAIN)); - m_camera = static_cast(m_iMan->SearchInstance(CLASS_CAMERA)); - m_sound = static_cast(m_iMan->SearchInstance(CLASS_SOUND)); - m_app = CApplication::GetInstancePointer(); + m_app = CApplication::GetInstancePointer(); + m_sound = m_app->GetSound(); + m_event = m_app->GetEventQueue(); + m_engine = Gfx::CEngine::GetInstancePointer(); + m_main = CRobotMain::GetInstancePointer(); + m_interface = m_main->GetInterface(); + m_camera = m_main->GetCamera(); m_bEditMaximized = false; m_bEditMinimized = false; @@ -87,7 +87,6 @@ CStudio::CStudio() CStudio::~CStudio() { - m_iMan->DeleteInstance(CLASS_STUDIO, this); } diff --git a/src/ui/studio.h b/src/ui/studio.h index 905baa6..7c2f652 100644 --- a/src/ui/studio.h +++ b/src/ui/studio.h @@ -26,7 +26,6 @@ #include class CEventQueue; -class CInstanceManager; class CRobotMain; class CScript; class CSoundInterface; @@ -54,70 +53,69 @@ enum StudioDialog class CStudio { - public: - CStudio(); - ~CStudio(); - - bool EventProcess(const Event &event); - - void StartEditScript(CScript *script, std::string name, int rank); - bool StopEditScript(bool bCancel); - - protected: - bool EventFrame(const Event &event); - void SearchToken(CEdit* edit); - void ColorizeScript(CEdit* edit); - void AdjustEditScript(); - void SetInfoText(std::string text, bool bClickable); - void ViewEditScript(); - void UpdateFlux(); - void UpdateButtons(); - - void StartDialog(StudioDialog type); - void StopDialog(); - void AdjustDialog(); - bool EventDialog(const Event &event); - void UpdateChangeList(); - void UpdateChangeEdit(); - void UpdateDialogAction(); - void UpdateDialogPublic(); - void UpdateDialogList(); - void SearchDirectory(char* dir, bool bCreate); - bool ReadProgram(); - bool WriteProgram(); - - protected: - CInstanceManager* m_iMan; - Gfx::CEngine* m_engine; - CEventQueue* m_event; - CRobotMain* m_main; - Gfx::CCamera* m_camera; - CSoundInterface* m_sound; - CInterface* m_interface; - CApplication *m_app; - - int m_rank; - CScript* m_script; - Gfx::CameraType m_editCamera; - - bool m_bEditMaximized; - bool m_bEditMinimized; - - Math::Point m_editActualPos; - Math::Point m_editActualDim; - Math::Point m_editFinalPos; - Math::Point m_editFinalDim; - - float m_time; - float m_fixInfoTextTime; - bool m_bRunning; - bool m_bRealTime; - bool m_bInitPause; - std::string m_helpFilename; +public: + CStudio(); + ~CStudio(); + + bool EventProcess(const Event &event); + + void StartEditScript(CScript *script, std::string name, int rank); + bool StopEditScript(bool bCancel); + +protected: + bool EventFrame(const Event &event); + void SearchToken(CEdit* edit); + void ColorizeScript(CEdit* edit); + void AdjustEditScript(); + void SetInfoText(std::string text, bool bClickable); + void ViewEditScript(); + void UpdateFlux(); + void UpdateButtons(); + + void StartDialog(StudioDialog type); + void StopDialog(); + void AdjustDialog(); + bool EventDialog(const Event &event); + void UpdateChangeList(); + void UpdateChangeEdit(); + void UpdateDialogAction(); + void UpdateDialogPublic(); + void UpdateDialogList(); + void SearchDirectory(char* dir, bool bCreate); + bool ReadProgram(); + bool WriteProgram(); + +protected: + Gfx::CEngine* m_engine; + CEventQueue* m_event; + CRobotMain* m_main; + Gfx::CCamera* m_camera; + CSoundInterface* m_sound; + CInterface* m_interface; + CApplication* m_app; + + int m_rank; + CScript* m_script; + Gfx::CameraType m_editCamera; + + bool m_bEditMaximized; + bool m_bEditMinimized; + + Math::Point m_editActualPos; + Math::Point m_editActualDim; + Math::Point m_editFinalPos; + Math::Point m_editFinalDim; + + float m_time; + float m_fixInfoTextTime; + bool m_bRunning; + bool m_bRealTime; + bool m_bInitPause; + std::string m_helpFilename; StudioDialog m_dialog; }; -} +} // namespace Ui diff --git a/src/ui/target.cpp b/src/ui/target.cpp index b47ba16..cc74750 100644 --- a/src/ui/target.cpp +++ b/src/ui/target.cpp @@ -14,11 +14,10 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// target.cpp - #include "ui/target.h" +#include "common/iman.h" namespace Ui { @@ -189,9 +188,11 @@ CObject* CTarget::DetectFriendObject(Math::Point pos) objRank = m_engine->DetectObject(pos); + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + for ( i=0 ; i<1000000 ; i++ ) { - pObj = static_cast(m_iMan->SearchInstance(CLASS_OBJECT, i)); + pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); if ( pObj == 0 ) break; if ( !pObj->GetActif() ) continue; diff --git a/src/ui/target.h b/src/ui/target.h index 05a3651..054524b 100644 --- a/src/ui/target.h +++ b/src/ui/target.h @@ -18,20 +18,19 @@ #pragma once -#include - -#include "ui/control.h" - +#include "common/event.h" #include "common/misc.h" -#include "common/iman.h" #include "common/restext.h" -#include "common/event.h" #include "graphics/engine/engine.h" #include "object/robotmain.h" #include "object/object.h" +#include "ui/control.h" + +#include + namespace Ui { diff --git a/src/ui/window.cpp b/src/ui/window.cpp index 97daf94..6013d37 100644 --- a/src/ui/window.cpp +++ b/src/ui/window.cpp @@ -15,8 +15,6 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// window.cpp - #include "ui/window.h" @@ -25,7 +23,6 @@ namespace Ui { // Object's constructor. -//CWindow::CWindow(CInstanceManager* iMan) : CControl(iMan) CWindow::CWindow() : CControl() { int i; @@ -122,7 +119,6 @@ CButton* CWindow::CreateButton(Math::Point pos, Math::Point dim, int icon, Event { if ( m_table[i] == 0 ) { -// m_table[i] = new CButton(m_iMan); m_table[i] = new CButton(); pc = static_cast(m_table[i]); pc->Create(pos, dim, icon, eventMsg); @@ -145,7 +141,6 @@ CColor* CWindow::CreateColor(Math::Point pos, Math::Point dim, int icon, EventTy { if ( m_table[i] == 0 ) { -// m_table[i] = new CColor(m_iMan); m_table[i] = new CColor(); pc = static_cast(m_table[i]); pc->Create(pos, dim, icon, eventMsg); @@ -168,7 +163,6 @@ CCheck* CWindow::CreateCheck(Math::Point pos, Math::Point dim, int icon, EventTy { if ( m_table[i] == 0 ) { -// m_table[i] = new CCheck(m_iMan); m_table[i] = new CCheck(); pc = static_cast(m_table[i]); pc->Create(pos, dim, icon, eventMsg); @@ -191,7 +185,6 @@ CKey* CWindow::CreateKey(Math::Point pos, Math::Point dim, int icon, EventType e { if ( m_table[i] == 0 ) { -// m_table[i] = new CKey(m_iMan); m_table[i] = new CKey(); pc = static_cast(m_table[i]); pc->Create(pos, dim, icon, eventMsg); @@ -214,7 +207,6 @@ CGroup* CWindow::CreateGroup(Math::Point pos, Math::Point dim, int icon, EventTy { if ( m_table[i] == 0 ) { -// m_table[i] = new CGroup(m_iMan); m_table[i] = new CGroup(); pc = static_cast(m_table[i]); pc->Create(pos, dim, icon, eventMsg); @@ -237,7 +229,6 @@ CImage* CWindow::CreateImage(Math::Point pos, Math::Point dim, int icon, EventTy { if ( m_table[i] == 0 ) { -// m_table[i] = new CImage(m_iMan); m_table[i] = new CImage(); pc = static_cast(m_table[i]); pc->Create(pos, dim, icon, eventMsg); @@ -260,7 +251,6 @@ CLabel* CWindow::CreateLabel(Math::Point pos, Math::Point dim, int icon, EventTy { if ( m_table[i] == 0 ) { -// m_table[i] = new CLabel(m_iMan); m_table[i] = new CLabel(); pc = static_cast(m_table[i]); pc->Create(pos, dim, icon, eventMsg); @@ -289,7 +279,6 @@ CEdit* CWindow::CreateEdit(Math::Point pos, Math::Point dim, int icon, EventType { if ( m_table[i] == 0 ) { -// m_table[i] = new CEdit(m_iMan); m_table[i] = new CEdit(); pc = static_cast(m_table[i]); pc->Create(pos, dim, icon, eventMsg); @@ -312,7 +301,6 @@ CEditValue* CWindow::CreateEditValue(Math::Point pos, Math::Point dim, int icon, { if ( m_table[i] == 0 ) { -// m_table[i] = new CEditValue(m_iMan); m_table[i] = new CEditValue(); pc = static_cast(m_table[i]); pc->Create(pos, dim, icon, eventMsg); @@ -335,7 +323,6 @@ CScroll* CWindow::CreateScroll(Math::Point pos, Math::Point dim, int icon, Event { if ( m_table[i] == 0 ) { -// m_table[i] = new CScroll(m_iMan); m_table[i] = new CScroll(); pc = static_cast(m_table[i]); pc->Create(pos, dim, icon, eventMsg); @@ -358,7 +345,6 @@ CSlider* CWindow::CreateSlider(Math::Point pos, Math::Point dim, int icon, Event { if ( m_table[i] == 0 ) { -// m_table[i] = new CSlider(m_iMan); m_table[i] = new CSlider(); pc = static_cast(m_table[i]); pc->Create(pos, dim, icon, eventMsg); @@ -382,7 +368,6 @@ CList* CWindow::CreateList(Math::Point pos, Math::Point dim, int icon, EventType { if ( m_table[i] == 0 ) { -// m_table[i] = new CList(m_iMan); m_table[i] = new CList(); pc = static_cast(m_table[i]); pc->Create(pos, dim, icon, eventMsg, expand); diff --git a/src/ui/window.h b/src/ui/window.h index 8d7090c..e39b8a9 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -19,12 +19,12 @@ #pragma once -#include - #include "common/event.h" #include "common/misc.h" #include "common/restext.h" +#include "graphics/engine/text.h" + #include "ui/button.h" #include "ui/color.h" #include "ui/check.h" @@ -44,7 +44,7 @@ #include "ui/target.h" #include "ui/control.h" -#include "graphics/engine/text.h" +#include namespace Ui { diff --git a/test/cbot/CBot_console/CBotConsole.h b/test/cbot/CBot_console/CBotConsole.h index a155399..ac87911 100644 --- a/test/cbot/CBot_console/CBotConsole.h +++ b/test/cbot/CBot_console/CBotConsole.h @@ -5,8 +5,8 @@ * Author: michal */ -#ifndef CBOTCONSOLE_H_ -#define CBOTCONSOLE_H_ +#pragma once + #include "CClass.h" struct ThreadInfo @@ -41,4 +41,3 @@ public: long EndProg() ; }; -#endif /* CBOTCONSOLE_H_ */ diff --git a/test/cbot/CBot_console/CBotDoc.h b/test/cbot/CBot_console/CBotDoc.h index c0a3e1d..82af7b0 100644 --- a/test/cbot/CBot_console/CBotDoc.h +++ b/test/cbot/CBot_console/CBotDoc.h @@ -6,8 +6,6 @@ */ #pragma once -#ifndef CBOTDOC_H_ -#define CBOTDOC_H_ #include "CClass.h" #include @@ -35,5 +33,3 @@ public: }; - -#endif /* CBOTDOC_H_ */ diff --git a/test/envs/opengl/CMakeLists.txt b/test/envs/opengl/CMakeLists.txt index 588a864..3de5466 100644 --- a/test/envs/opengl/CMakeLists.txt +++ b/test/envs/opengl/CMakeLists.txt @@ -15,7 +15,6 @@ ${SRC_DIR}/graphics/opengl/gldevice.cpp ${SRC_DIR}/graphics/engine/modelfile.cpp ${SRC_DIR}/common/logger.cpp ${SRC_DIR}/common/image.cpp -${SRC_DIR}/common/iman.cpp ${SRC_DIR}/common/stringutils.cpp ${SRC_DIR}/app/system.cpp model_test.cpp @@ -25,7 +24,6 @@ set(TRANSFORM_SOURCES ${SRC_DIR}/graphics/opengl/gldevice.cpp ${SRC_DIR}/common/logger.cpp ${SRC_DIR}/common/image.cpp -${SRC_DIR}/common/iman.cpp ${SRC_DIR}/app/system.cpp transform_test.cpp ) @@ -34,20 +32,27 @@ set(LIGHT_SOURCES ${SRC_DIR}/graphics/opengl/gldevice.cpp ${SRC_DIR}/common/logger.cpp ${SRC_DIR}/common/image.cpp -${SRC_DIR}/common/iman.cpp ${SRC_DIR}/app/system.cpp light_test.cpp ) include_directories(${SRC_DIR} ${CMAKE_CURRENT_BINARY_DIR}) +include_directories( +SYSTEM +${SDL_INCLUDE_DIR} +${SDLIMAGE_INCLUDE_DIR} +${SDLTTF_INCLUDE_DIR} +${PNG_INCLUDE_DIRS} +${GLEW_INCLUDE_PATH} +) + set(LIBS ${SDL_LIBRARY} ${SDLIMAGE_LIBRARY} ${OPENGL_LIBRARY} ${GLEW_LIBRARY} ${PNG_LIBRARIES} -${ADD_LIBS} ) add_executable(texture_test ${TEXTURE_SOURCES}) diff --git a/test/envs/opengl/light_test.cpp b/test/envs/opengl/light_test.cpp index b19ba4b..b1e0151 100644 --- a/test/envs/opengl/light_test.cpp +++ b/test/envs/opengl/light_test.cpp @@ -1,8 +1,10 @@ #include "app/system.h" + #include "common/logger.h" #include "common/image.h" -#include "common/iman.h" + #include "graphics/opengl/gldevice.h" + #include "math/geometry.h" #include @@ -365,8 +367,6 @@ int main(int argc, char *argv[]) GetCurrentTimeStamp(PREV_TIME); GetCurrentTimeStamp(CURR_TIME); - CInstanceManager iMan; - // Without any error checking, for simplicity SDL_Init(SDL_INIT_VIDEO); diff --git a/test/envs/opengl/model_test.cpp b/test/envs/opengl/model_test.cpp index a06a178..882b785 100644 --- a/test/envs/opengl/model_test.cpp +++ b/test/envs/opengl/model_test.cpp @@ -1,8 +1,11 @@ #include "app/system.h" + #include "common/logger.h" #include "common/image.h" + #include "graphics/engine/modelfile.h" #include "graphics/opengl/gldevice.h" + #include "math/geometry.h" #include diff --git a/test/envs/opengl/texture_test.cpp b/test/envs/opengl/texture_test.cpp index de9caf3..b1f352c 100644 --- a/test/envs/opengl/texture_test.cpp +++ b/test/envs/opengl/texture_test.cpp @@ -1,6 +1,8 @@ #include "common/logger.h" #include "common/image.h" + #include "graphics/opengl/gldevice.h" + #include "math/geometry.h" #include diff --git a/test/envs/opengl/transform_test.cpp b/test/envs/opengl/transform_test.cpp index cddd1b8..04c73f7 100644 --- a/test/envs/opengl/transform_test.cpp +++ b/test/envs/opengl/transform_test.cpp @@ -1,8 +1,11 @@ #include "app/system.h" + #include "common/logger.h" #include "common/image.h" #include "common/iman.h" + #include "graphics/opengl/gldevice.h" + #include "math/geometry.h" #include @@ -242,8 +245,6 @@ int main(int argc, char *argv[]) GetCurrentTimeStamp(PREV_TIME); GetCurrentTimeStamp(CURR_TIME); - CInstanceManager iMan; - // Without any error checking, for simplicity SDL_Init(SDL_INIT_VIDEO); diff --git a/test/unit/math/geometry_test.cpp b/test/unit/math/geometry_test.cpp index f50df4e..7c3e26a 100644 --- a/test/unit/math/geometry_test.cpp +++ b/test/unit/math/geometry_test.cpp @@ -14,8 +14,6 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// math/test/geometry_test.cpp - /* Unit tests for functions in geometry.h */ #include "math/func.h" diff --git a/test/unit/math/matrix_test.cpp b/test/unit/math/matrix_test.cpp index 6ae2c6b..5f5c3af 100644 --- a/test/unit/math/matrix_test.cpp +++ b/test/unit/math/matrix_test.cpp @@ -14,8 +14,6 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// math/test/matrix_test.cpp - /* Unit tests for Matrix struct diff --git a/test/unit/math/vector_test.cpp b/test/unit/math/vector_test.cpp index 199f4c3..41bac74 100644 --- a/test/unit/math/vector_test.cpp +++ b/test/unit/math/vector_test.cpp @@ -14,8 +14,6 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// math/test/vector_test.cpp - /* Unit tests for Vector struct diff --git a/test/unit/ui/edit_test.cpp b/test/unit/ui/edit_test.cpp index f878f4b..2f31a89 100644 --- a/test/unit/ui/edit_test.cpp +++ b/test/unit/ui/edit_test.cpp @@ -13,19 +13,17 @@ public: virtual void SetUp() { - m_engine = new Gfx::CEngine(&m_iMan, NULL); + m_engine = new Gfx::CEngine(nullptr); - m_iMan.AddInstance(CLASS_ENGINE, m_engine); m_edit = new Ui::CEdit; } virtual void TearDown() { - m_iMan.DeleteInstance(CLASS_ENGINE, m_engine); delete m_engine; - m_engine = NULL; + m_engine = nullptr; delete m_edit; - m_edit = NULL; + m_edit = nullptr; } virtual ~CEditTest() @@ -34,7 +32,6 @@ public: }; protected: - CInstanceManager m_iMan; CApplication m_app; Gfx::CEngine * m_engine; Ui::CEdit * m_edit; diff --git a/test/unit/ui/mocks/text_mock.h b/test/unit/ui/mocks/text_mock.h index f0ad339..9289481 100644 --- a/test/unit/ui/mocks/text_mock.h +++ b/test/unit/ui/mocks/text_mock.h @@ -1,4 +1,5 @@ #include "common/logger.h" + #include "graphics/engine/text.h" #include @@ -6,7 +7,7 @@ class CTextMock : public Gfx::CText { public: - CTextMock(CInstanceManager *iMan, Gfx::CEngine* engine) : CText(iMan, engine) + CTextMock(Gfx::CEngine* engine) : CText(engine) { } diff --git a/test/unit/ui/stubs/app_stub.cpp b/test/unit/ui/stubs/app_stub.cpp index 70d9e82..094806f 100644 --- a/test/unit/ui/stubs/app_stub.cpp +++ b/test/unit/ui/stubs/app_stub.cpp @@ -1,7 +1,8 @@ #include "app/app.h" + #include "graphics/opengl/gldevice.h" -template<> CApplication* CSingleton::mInstance = nullptr; +template<> CApplication* CSingleton::m_instance = nullptr; namespace Gfx { @@ -10,6 +11,8 @@ GLDeviceConfig::GLDeviceConfig() } } /* Gfx */ + + CApplication::CApplication() { } @@ -23,4 +26,13 @@ std::string CApplication::GetDataFilePath(DataDir /* dataDir */, const std::stri return subpath; } +CSoundInterface* CApplication::GetSound() +{ + return nullptr; +} + +CEventQueue* CApplication::GetEventQueue() +{ + return nullptr; +} diff --git a/test/unit/ui/stubs/engine_stub.cpp b/test/unit/ui/stubs/engine_stub.cpp index de7bbe7..40886da 100644 --- a/test/unit/ui/stubs/engine_stub.cpp +++ b/test/unit/ui/stubs/engine_stub.cpp @@ -1,20 +1,28 @@ #include "graphics/engine/engine.h" #include "graphics/engine/text.h" + #include "mocks/text_mock.h" +template<> Gfx::CEngine* CSingleton::m_instance = nullptr; + namespace Gfx { -CEngine::CEngine(CInstanceManager* iMan, CApplication* app) : - m_iMan(iMan), m_app(app) +CEngine::CEngine(CApplication* app) : + m_app(app) { - m_text = new CTextMock(m_iMan, this); + m_text = new CTextMock(this); m_text->Create(); } CEngine::~CEngine() { delete m_text; - m_text = NULL; + m_text = nullptr; +} + +CParticle* CEngine::GetParticle() +{ + return nullptr; } Math::Point CEngine::WindowToInterfaceSize(Math::IntPoint size) diff --git a/test/unit/ui/stubs/particle_stub.cpp b/test/unit/ui/stubs/particle_stub.cpp index c3bf6dc..34cf973 100644 --- a/test/unit/ui/stubs/particle_stub.cpp +++ b/test/unit/ui/stubs/particle_stub.cpp @@ -7,7 +7,7 @@ namespace Gfx { -CParticle::CParticle(CInstanceManager* /*iMan*/, CEngine* /*engine*/) +CParticle::CParticle(CEngine* /*engine*/) { } diff --git a/test/unit/ui/stubs/robotmain_stub.cpp b/test/unit/ui/stubs/robotmain_stub.cpp index a36b1a1..c332d5a 100644 --- a/test/unit/ui/stubs/robotmain_stub.cpp +++ b/test/unit/ui/stubs/robotmain_stub.cpp @@ -1,7 +1,7 @@ #include "object/robotmain.h" -template<> CRobotMain* CSingleton::mInstance = nullptr; +template<> CRobotMain* CSingleton::m_instance = nullptr; bool CRobotMain::GetGlint() { -- cgit v1.2.3-1-g7c22 From c79c176e46a34304b6fdc6df70f65b81f796ba54 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 17 Feb 2013 13:20:18 +0100 Subject: Show compilation date in main menu --- src/ui/maindialog.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 920d958..d3128da 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -1969,8 +1969,8 @@ ddim.y = 9.0f/480.0f; ddim.x = 90.0f/640.0f; ddim.y = 10.0f/480.0f; //#endif - GetResource(RES_TEXT, RT_VERSION_ID, name); - pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL1, name); + //GetResource(RES_TEXT, RT_VERSION_ID, name); + pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL1, __DATE__); pl->SetFontType(Gfx::FONT_COURIER); pl->SetFontSize(9.0f); } -- cgit v1.2.3-1-g7c22 From c42515927e7e249574daeab680b73248a0a5c2e2 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 17 Feb 2013 13:28:04 +0100 Subject: Music restarting on PHASE_WELCOME2 --- src/ui/maindialog.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index d3128da..fede0b7 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -1758,9 +1758,6 @@ pos.y -= 0.048f; } if ( m_phase == PHASE_WELCOME2 ) { - m_sound->StopMusic(); - m_sound->PlayMusic(11, false); - pos.x = 0.0f; pos.y = 0.0f; ddim.x = 0.0f; -- cgit v1.2.3-1-g7c22 From 64af5f5be0a93bce40f7196760a5976145810e1e Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Thu, 21 Feb 2013 12:26:01 +0100 Subject: Reverted RotateAngle to old formula This should solve incontinuities in angle calculations, possibly fixing the "teleportation bug" --- src/math/geometry.h | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/src/math/geometry.h b/src/math/geometry.h index ee6fc52..23c149c 100644 --- a/src/math/geometry.h +++ b/src/math/geometry.h @@ -197,15 +197,34 @@ inline void RotatePoint2(const Math::Vector center, float angleH, float angleV, //! Returns the angle between point (x,y) and (0,0) inline float RotateAngle(float x, float y) { - if ( (x == 0.0f) && (y == 0.0f) ) - return 0.0f; + if (x == 0.0f && y == 0.0f) return 0.0f; - float atan = atan2(x, y); - - if ((y < 0.0f) && (x >= 0.0f)) - return -atan + 2.5f*PI; + if (x >= 0.0f) + { + if (y >= 0.0f) + { + if (x > y) return atanf(y/x); + else return PI*0.5f - atanf(x/y); + } + else + { + if (x > -y) return PI*2.0f + atanf(y/x); + else return PI*1.5f - atanf(x/y); + } + } else - return -atan + 0.5f*PI; + { + if (y >= 0.0f) + { + if (-x > y) return PI*1.0f + atanf(y/x); + else return PI*0.5f - atanf(x/y); + } + else + { + if (-x > -y) return PI*1.0f + atanf(y/x); + else return PI*1.5f - atanf(x/y); + } + } } //! Calculates the angle between two points and a center -- cgit v1.2.3-1-g7c22 From ba2df2cb4201597c9dc01365641413dcbf6812d9 Mon Sep 17 00:00:00 2001 From: erihel Date: Sun, 24 Feb 2013 01:40:55 +0100 Subject: * Fix for satcom freeze --- src/graphics/engine/text.cpp | 35 +++++++++++++++++++++-------------- src/graphics/engine/text.h | 8 +++++++- src/ui/edit.cpp | 12 ++++++++++-- 3 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index 424b99b..9dea129 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -149,6 +149,7 @@ void CText::FlushCache() } void CText::DrawText(const std::string &text, std::vector::iterator format, + std::vector::iterator end, float size, Math::Point pos, float width, TextAlign align, int eol, Color color) { @@ -156,18 +157,18 @@ void CText::DrawText(const std::string &text, std::vector::iterato if (align == TEXT_ALIGN_CENTER) { - sw = GetStringWidth(text, format, size); + sw = GetStringWidth(text, format, end, size); if (sw > width) sw = width; pos.x -= sw / 2.0f; } else if (align == TEXT_ALIGN_RIGHT) { - sw = GetStringWidth(text, format, size); + sw = GetStringWidth(text, format, end, size); if (sw > width) sw = width; pos.x -= sw; } - DrawString(text, format, size, pos, width, eol, color); + DrawString(text, format, end, size, pos, width, eol, color); } void CText::DrawText(const std::string &text, FontType font, @@ -193,12 +194,13 @@ void CText::DrawText(const std::string &text, FontType font, } void CText::SizeText(const std::string &text, std::vector::iterator format, + std::vector::iterator endFormat, float size, Math::Point pos, TextAlign align, Math::Point &start, Math::Point &end) { start = end = pos; - float sw = GetStringWidth(text, format, size); + float sw = GetStringWidth(text, format, endFormat, size); end.x += sw; if (align == TEXT_ALIGN_CENTER) { @@ -276,7 +278,8 @@ float CText::GetHeight(FontType font, float size) float CText::GetStringWidth(const std::string &text, - std::vector::iterator format, float size) + std::vector::iterator format, + std::vector::iterator end, float size) { float width = 0.0f; unsigned int index = 0; @@ -284,8 +287,8 @@ float CText::GetStringWidth(const std::string &text, while (index < text.length()) { FontType font = FONT_COLOBOT; - //if (format.size() > fmtIndex) - font = static_cast(format[fmtIndex] & FONT_MASK_FONT); + if (format + fmtIndex != end) + font = static_cast(*(format + fmtIndex) & FONT_MASK_FONT); UTF8Char ch; @@ -343,6 +346,7 @@ float CText::GetCharWidth(UTF8Char ch, FontType font, float size, float offset) int CText::Justify(const std::string &text, std::vector::iterator format, + std::vector::iterator end, float size, float width) { float pos = 0.0f; @@ -352,8 +356,8 @@ int CText::Justify(const std::string &text, std::vector::iterator while (index < text.length()) { FontType font = FONT_COLOBOT; - //if (format.size() > fmtIndex) - font = static_cast(format[fmtIndex] & FONT_MASK_FONT); + if (format + fmtIndex != end) + font = static_cast(*(format + fmtIndex) & FONT_MASK_FONT); UTF8Char ch; @@ -427,6 +431,7 @@ int CText::Justify(const std::string &text, FontType font, float size, float wid } int CText::Detect(const std::string &text, std::vector::iterator format, + std::vector::iterator end, float size, float offset) { float pos = 0.0f; @@ -435,11 +440,12 @@ int CText::Detect(const std::string &text, std::vector::iterator f while (index < text.length()) { FontType font = FONT_COLOBOT; - //if (format.size() > fmtIndex) - font = static_cast(format[fmtIndex] & FONT_MASK_FONT); + + if (format + fmtIndex != end) + font = static_cast(*(format + fmtIndex) & FONT_MASK_FONT); // TODO: if (font == FONT_BUTTON) - if (font == FONT_BUTTON) continue; + //if (font == FONT_BUTTON) continue; UTF8Char ch; @@ -500,6 +506,7 @@ int CText::Detect(const std::string &text, FontType font, float size, float offs } void CText::DrawString(const std::string &text, std::vector::iterator format, + std::vector::iterator end, float size, Math::Point pos, float width, int eol, Color color) { m_engine->SetState(ENG_RSTATE_TEXT); @@ -513,8 +520,8 @@ void CText::DrawString(const std::string &text, std::vector::itera for (auto it = chars.begin(); it != chars.end(); ++it) { FontType font = FONT_COLOBOT; - //if (format.size() > fmtIndex) - font = static_cast(format[fmtIndex] & FONT_MASK_FONT); + if (format + fmtIndex != end) + font = static_cast(*(format + fmtIndex) & FONT_MASK_FONT); // TODO: if (font == FONT_BUTTON) if (font == FONT_BUTTON) continue; diff --git a/src/graphics/engine/text.h b/src/graphics/engine/text.h index d8e2aff..6bcc59b 100644 --- a/src/graphics/engine/text.h +++ b/src/graphics/engine/text.h @@ -242,6 +242,7 @@ public: //! Draws text (multi-format) void DrawText(const std::string &text, std::vector::iterator format, + std::vector::iterator end, float size, Math::Point pos, float width, TextAlign align, int eol, Color color = Color(0.0f, 0.0f, 0.0f, 1.0f)); //! Draws text (one font) @@ -251,6 +252,7 @@ public: //! Calculates dimensions for text (multi-format) void SizeText(const std::string &text, std::vector::iterator format, + std::vector::iterator endFormat, float size, Math::Point pos, TextAlign align, Math::Point &start, Math::Point &end); //! Calculates dimensions for text (one font) @@ -267,7 +269,8 @@ public: //! Returns width of string (multi-format) TEST_VIRTUAL float GetStringWidth(const std::string &text, - std::vector::iterator format, float size); + std::vector::iterator format, + std::vector::iterator end, float size); //! Returns width of string (single font) TEST_VIRTUAL float GetStringWidth(const std::string &text, FontType font, float size); //! Returns width of single character @@ -275,12 +278,14 @@ public: //! Justifies a line of text (multi-format) int Justify(const std::string &text, std::vector::iterator format, + std::vector::iterator end, float size, float width); //! Justifies a line of text (one font) int Justify(const std::string &text, FontType font, float size, float width); //! Returns the most suitable position to a given offset (multi-format) int Detect(const std::string &text, std::vector::iterator format, + std::vector::iterator end, float size, float offset); //! Returns the most suitable position to a given offset (one font) int Detect(const std::string &text, FontType font, float size, float offset); @@ -290,6 +295,7 @@ protected: CharTexture CreateCharTexture(UTF8Char ch, CachedFont* font); void DrawString(const std::string &text, std::vector::iterator format, + std::vector::iterator end, float size, Math::Point pos, float width, int eol, Color color); void DrawString(const std::string &text, FontType font, float size, Math::Point pos, float width, int eol, Color color); diff --git a/src/ui/edit.cpp b/src/ui/edit.cpp index 64004bb..c0b6446 100644 --- a/src/ui/edit.cpp +++ b/src/ui/edit.cpp @@ -261,7 +261,7 @@ bool CEdit::EventProcess(const Event &event) if ( event.type == EVENT_MOUSE_MOVE ) { - if ( Detect(event.mousePos) && + if ( Detect(event.mousePos) && event.mousePos.x < m_pos.x+m_dim.x-(m_bMulti?MARGX+SCROLL_WIDTH:0.0f) ) { if ( m_bEdit ) @@ -560,7 +560,7 @@ bool CEdit::IsLinkPos(Math::Point pos) if ( i == -1 ) return false; if ( i >= m_len ) return false; - if ( (m_format[i]& Gfx::FONT_MASK_HIGHLIGHT) == Gfx::FONT_HIGHLIGHT_LINK) return true; // TODO + if ( m_format.size() > i && ((m_format[i] & Gfx::FONT_MASK_HIGHLIGHT) == Gfx::FONT_HIGHLIGHT_LINK)) return true; // TODO return false; } @@ -736,6 +736,7 @@ int CEdit::MouseDetect(Math::Point mouse) // m_fontStretch); c = m_engine->GetText()->Detect(std::string(m_text+m_lineOffset[i]).substr(0, len), m_format.begin() + m_lineOffset[i], + m_format.end(), size, offset); // TODO check if good } @@ -1035,9 +1036,11 @@ void CEdit::Draw() { start.x = ppos.x+m_engine->GetText()->GetStringWidth(std::string(m_text+beg).substr(0, o1-beg), m_format.begin() + beg, + m_format.end(), size); end.x = m_engine->GetText()->GetStringWidth(std::string(m_text+o1).substr(0, o2-o1), m_format.begin() + o1, + m_format.end(), size); } @@ -1066,6 +1069,7 @@ void CEdit::Draw() { m_engine->GetText()->DrawText(std::string(m_text+beg).substr(0, len), m_format.begin() + beg, + m_format.end(), size, ppos, m_dim.x, @@ -1108,6 +1112,7 @@ void CEdit::Draw() { m_engine->GetText()->SizeText(std::string(m_text+m_lineOffset[i]).substr(0, len), m_format.begin() + m_lineOffset[i], + m_format.end(), size, pos, Gfx::TEXT_ALIGN_LEFT, start, end); } @@ -2464,6 +2469,7 @@ void CEdit::MoveLine(int move, bool bWord, bool bSelect) { c = m_engine->GetText()->Detect(std::string(m_text+m_lineOffset[line]), m_format.begin() + m_lineOffset[line], + m_format.end(), m_fontSize, m_lineOffset[line+1]-m_lineOffset[line]); } @@ -2495,6 +2501,7 @@ void CEdit::ColumnFix() m_column = m_engine->GetText()->GetStringWidth( std::string(m_text+m_lineOffset[line]), m_format.begin() + m_lineOffset[line], + m_format.end(), m_fontSize ); } @@ -3115,6 +3122,7 @@ void CEdit::Justif() // TODO check if good i += m_engine->GetText()->Justify(std::string(m_text+i), m_format.begin() + i, + m_format.end(), size, width); } -- cgit v1.2.3-1-g7c22 From 3a594dc3a814cff4ae4db02985f4b1ce643a0604 Mon Sep 17 00:00:00 2001 From: erihel Date: Sun, 24 Feb 2013 18:04:38 +0100 Subject: * Changed AdjustFrequency formula * Changed SetVolume to match orginal game formula --- src/sound/oalsound/alsound.cpp | 7 +++++-- src/sound/oalsound/channel.cpp | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp index 83cbeb6..17a46fe 100644 --- a/src/sound/oalsound/alsound.cpp +++ b/src/sound/oalsound/alsound.cpp @@ -386,7 +386,8 @@ bool ALSound::Frequency(int channel, float frequency) return false; } - mChannels[channel]->SetFrequency(frequency); + mChannels[channel]->SetFrequency(frequency * mChannels[channel]->GetInitFrequency()); + mChannels[channel]->SetChangeFrequency(frequency); return true; } @@ -461,11 +462,13 @@ void ALSound::FrameMove(float delta) // setting volume volume = progress * (oper.finalAmplitude - it.second->GetStartAmplitude()); - it.second->SetVolume((volume + it.second->GetStartAmplitude()) * mAudioVolume); + volume = (volume + it.second->GetStartAmplitude()) * mAudioVolume; + it.second->SetVolume(volume); // setting frequency frequency = progress * (oper.finalFrequency - it.second->GetStartFrequency()) * it.second->GetStartFrequency() * it.second->GetChangeFrequency() * it.second->GetInitFrequency(); it.second->AdjustFrequency(frequency); + GetLogger()->Error("%f\n", frequency); if (oper.totalTime <= oper.currentTime) { if (oper.nextOper == SOPER_LOOP) { diff --git a/src/sound/oalsound/channel.cpp b/src/sound/oalsound/channel.cpp index 3c8bc50..0faecd0 100644 --- a/src/sound/oalsound/channel.cpp +++ b/src/sound/oalsound/channel.cpp @@ -94,7 +94,7 @@ bool Channel::AdjustFrequency(float freq) if (!mReady || mBuffer == nullptr) return false; - return SetFrequency(mInitFrequency - freq); + return SetFrequency(mInitFrequency + freq); } @@ -119,7 +119,7 @@ bool Channel::SetVolume(float vol) if (!mReady || vol < 0 || mBuffer == nullptr) return false; - alSourcef(mSource, AL_GAIN, MIN(vol, 1.0f)); + alSourcef(mSource, AL_GAIN, MIN(powf(vol, 0.2f), 1.0f)); if (alCheck()) { GetLogger()->Warn("Could not set sound volume to '%f'. Code: %d\n", vol, alGetCode()); return false; -- cgit v1.2.3-1-g7c22 From b0d86ebe5a3c2330307a5c383f0136377338336c Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Mon, 25 Feb 2013 21:58:01 +0100 Subject: Better light sorting Should fix lighting issue (#62) --- src/graphics/engine/engine.h | 6 +- src/graphics/engine/lightman.cpp | 79 ++++++------- src/graphics/engine/lightman.h | 21 +++- test/unit/CMakeLists.txt | 167 ++++++++++++++++++++++++++-- test/unit/graphics/core/device_mock.h | 107 ++++++++++++++++++ test/unit/graphics/engine/engine_mock.h | 14 +++ test/unit/graphics/engine/lightman_test.cpp | 145 ++++++++++++++++++++++++ test/unit/ui/stubs/engine_stub.cpp | 17 +++ 8 files changed, 501 insertions(+), 55 deletions(-) create mode 100644 test/unit/graphics/core/device_mock.h create mode 100644 test/unit/graphics/engine/engine_mock.h create mode 100644 test/unit/graphics/engine/lightman_test.cpp diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index 0647fbd..f9dfd45 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -729,7 +729,7 @@ public: //@{ //! Management of game pause mode void SetPause(bool pause); - bool GetPause(); + TEST_VIRTUAL bool GetPause(); //@} //@{ @@ -1170,9 +1170,9 @@ public: //! Returns the view matrix const Math::Matrix& GetMatView(); //! Returns the camera center point - Math::Vector GetEyePt(); + TEST_VIRTUAL Math::Vector GetEyePt(); //! Returns the camera target point - Math::Vector GetLookatPt(); + TEST_VIRTUAL Math::Vector GetLookatPt(); //! Returns the horizontal direction angle of view float GetEyeDirH(); //! Returns the vertical direction angle of view diff --git a/src/graphics/engine/lightman.cpp b/src/graphics/engine/lightman.cpp index 4a8fd60..628ebf5 100644 --- a/src/graphics/engine/lightman.cpp +++ b/src/graphics/engine/lightman.cpp @@ -26,6 +26,7 @@ #include +#include // Graphics module namespace @@ -386,39 +387,10 @@ void CLightManager::UpdateDeviceLights(EngineObjectType type) for (int i = 0; i < static_cast( m_lightMap.size() ); ++i) m_lightMap[i] = -1; - // High priority - for (int i = 0; i < static_cast( m_dynLights.size() ); i++) - { - if (! m_dynLights[i].used) - continue; - if (! m_dynLights[i].enabled) - continue; - if (Math::IsZero(m_dynLights[i].intensity.current)) - continue; - if (m_dynLights[i].priority == LIGHT_PRI_LOW) - continue; - - bool enabled = true; - if (m_dynLights[i].includeType != ENG_OBJTYPE_NULL) - enabled = (m_dynLights[i].includeType == type); - - if (m_dynLights[i].excludeType != ENG_OBJTYPE_NULL) - enabled = (m_dynLights[i].excludeType != type); - - if (enabled) - { - for (int j = 0; j < static_cast( m_lightMap.size() ); ++j) - { - if (m_lightMap[j] == -1) - { - m_lightMap[j] = i; - break; - } - } - } - } + std::vector sortedLights = m_dynLights; + std::sort(sortedLights.begin(), sortedLights.end(), LightsComparator(m_engine->GetEyePt(), type)); - // Low priority + int lightMapIndex = 0; for (int i = 0; i < static_cast( m_dynLights.size() ); i++) { if (! m_dynLights[i].used) @@ -427,8 +399,6 @@ void CLightManager::UpdateDeviceLights(EngineObjectType type) continue; if (m_dynLights[i].intensity.current == 0.0f) continue; - if (m_dynLights[i].priority == LIGHT_PRI_HIGH) - continue; bool enabled = true; if (m_dynLights[i].includeType != ENG_OBJTYPE_NULL) @@ -439,15 +409,12 @@ void CLightManager::UpdateDeviceLights(EngineObjectType type) if (enabled) { - for (int j = 0; j < static_cast( m_lightMap.size() ); ++j) - { - if (m_lightMap[j] == -1) - { - m_lightMap[j] = i; - break; - } - } + m_lightMap[lightMapIndex] = i; + ++lightMapIndex; } + + if (lightMapIndex >= static_cast( m_lightMap.size() )) + break; } for (int i = 0; i < static_cast( m_lightMap.size() ); ++i) @@ -465,5 +432,33 @@ void CLightManager::UpdateDeviceLights(EngineObjectType type) } } +// ----------- + +CLightManager::LightsComparator::LightsComparator(Math::Vector eyePos, EngineObjectType objectType) +{ + m_eyePos = eyePos; + m_objectType = objectType; +} + +float CLightManager::LightsComparator::GetLightWeight(const DynamicLight& dynLight) +{ + bool enabled = true; + if (!dynLight.used || !dynLight.enabled || dynLight.intensity.current == 0.0f) + enabled = false; + else if (dynLight.includeType != ENG_OBJTYPE_NULL) + enabled = dynLight.includeType == m_objectType; + else if (dynLight.excludeType != ENG_OBJTYPE_NULL) + enabled = dynLight.excludeType != m_objectType; + + return enabled ? ( (dynLight.light.position - m_eyePos).Length() * dynLight.priority ) : 10000.0f; +} + +bool CLightManager::LightsComparator::operator()(const DynamicLight& left, const DynamicLight& right) +{ + float leftWeight = GetLightWeight(left); + float rightWeight = GetLightWeight(right); + + return leftWeight >= rightWeight; +} } // namespace Gfx diff --git a/src/graphics/engine/lightman.h b/src/graphics/engine/lightman.h index 07dfe6a..ab66524 100644 --- a/src/graphics/engine/lightman.h +++ b/src/graphics/engine/lightman.h @@ -71,8 +71,8 @@ struct LightProgression */ enum LightPriority { - LIGHT_PRI_HIGH, - LIGHT_PRI_LOW + LIGHT_PRI_HIGH = 1, + LIGHT_PRI_LOW = 2 }; /** @@ -188,6 +188,21 @@ public: //! Enables or disables dynamic lights affecting the given object type void UpdateDeviceLights(EngineObjectType type); +protected: + class LightsComparator + { + public: + LightsComparator(Math::Vector eyePos, EngineObjectType objectType); + + bool operator()(const DynamicLight& left, const DynamicLight& right); + + private: + float GetLightWeight(const DynamicLight& dynLight); + + Math::Vector m_eyePos; + EngineObjectType m_objectType; + }; + protected: CEngine* m_engine; CDevice* m_device; @@ -196,7 +211,7 @@ protected: float m_time; //! List of dynamic lights std::vector m_dynLights; - //! Map of current light allotment: graphics light -> dynamic light + //! Map of current light allocation: graphics light -> dynamic light std::vector m_lightMap; }; diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index f6a1d75..21d1986 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -1,21 +1,174 @@ set(SRC_DIR ${colobot_SOURCE_DIR}/src) -include_directories( -${SRC_DIR} -${GTEST_INCLUDE_DIR} -math -common +# Additional libraries per platform +if (${MXE}) # MXE requires special treatment + set(PLATFORM_LIBS ${MXE_LIBS}) +elseif (${PLATFORM_WINDOWS}) + # because it isn't included in standard linking libraries + set(PLATFORM_LIBS "-lintl") +elseif(${PLATFORM_LINUX}) + # for clock_gettime + set(PLATFORM_LIBS "-lrt") +endif() + + +# Configure file +configure_file(${SRC_DIR}/common/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/common/config.h) + +# Code sources +set(COLOBOT_SOURCES +${SRC_DIR}/app/app.cpp +${SRC_DIR}/app/system.cpp +${SRC_DIR}/common/event.cpp +${SRC_DIR}/common/image.cpp +${SRC_DIR}/common/iman.cpp +${SRC_DIR}/common/logger.cpp +${SRC_DIR}/common/misc.cpp +${SRC_DIR}/common/profile.cpp +${SRC_DIR}/common/restext.cpp +${SRC_DIR}/common/stringutils.cpp +${SRC_DIR}/graphics/core/color.cpp +${SRC_DIR}/graphics/engine/camera.cpp +${SRC_DIR}/graphics/engine/cloud.cpp +${SRC_DIR}/graphics/engine/engine.cpp +${SRC_DIR}/graphics/engine/lightman.cpp +${SRC_DIR}/graphics/engine/lightning.cpp +${SRC_DIR}/graphics/engine/modelfile.cpp +${SRC_DIR}/graphics/engine/modelmanager.cpp +${SRC_DIR}/graphics/engine/particle.cpp +${SRC_DIR}/graphics/engine/planet.cpp +${SRC_DIR}/graphics/engine/pyro.cpp +${SRC_DIR}/graphics/engine/terrain.cpp +${SRC_DIR}/graphics/engine/text.cpp +${SRC_DIR}/graphics/engine/water.cpp +${SRC_DIR}/graphics/opengl/gldevice.cpp +${SRC_DIR}/object/auto/auto.cpp +${SRC_DIR}/object/auto/autobase.cpp +${SRC_DIR}/object/auto/autoconvert.cpp +${SRC_DIR}/object/auto/autoderrick.cpp +${SRC_DIR}/object/auto/autodestroyer.cpp +${SRC_DIR}/object/auto/autoegg.cpp +${SRC_DIR}/object/auto/autoenergy.cpp +${SRC_DIR}/object/auto/autofactory.cpp +${SRC_DIR}/object/auto/autoflag.cpp +${SRC_DIR}/object/auto/autohuston.cpp +${SRC_DIR}/object/auto/autoinfo.cpp +${SRC_DIR}/object/auto/autojostle.cpp +${SRC_DIR}/object/auto/autokid.cpp +${SRC_DIR}/object/auto/autolabo.cpp +${SRC_DIR}/object/auto/automush.cpp +${SRC_DIR}/object/auto/autonest.cpp +${SRC_DIR}/object/auto/autonuclear.cpp +${SRC_DIR}/object/auto/autopara.cpp +${SRC_DIR}/object/auto/autoportico.cpp +${SRC_DIR}/object/auto/autoradar.cpp +${SRC_DIR}/object/auto/autorepair.cpp +${SRC_DIR}/object/auto/autoresearch.cpp +${SRC_DIR}/object/auto/autoroot.cpp +${SRC_DIR}/object/auto/autosafe.cpp +${SRC_DIR}/object/auto/autostation.cpp +${SRC_DIR}/object/auto/autotower.cpp +${SRC_DIR}/object/brain.cpp +${SRC_DIR}/object/mainmovie.cpp +${SRC_DIR}/object/motion/motion.cpp +${SRC_DIR}/object/motion/motionant.cpp +${SRC_DIR}/object/motion/motionbee.cpp +${SRC_DIR}/object/motion/motionhuman.cpp +${SRC_DIR}/object/motion/motionmother.cpp +${SRC_DIR}/object/motion/motionspider.cpp +${SRC_DIR}/object/motion/motiontoto.cpp +${SRC_DIR}/object/motion/motionvehicle.cpp +${SRC_DIR}/object/motion/motionworm.cpp +${SRC_DIR}/object/object.cpp +${SRC_DIR}/object/robotmain.cpp +${SRC_DIR}/object/task/task.cpp +${SRC_DIR}/object/task/taskadvance.cpp +${SRC_DIR}/object/task/taskbuild.cpp +${SRC_DIR}/object/task/taskfire.cpp +${SRC_DIR}/object/task/taskfireant.cpp +${SRC_DIR}/object/task/taskflag.cpp +${SRC_DIR}/object/task/taskgoto.cpp +${SRC_DIR}/object/task/taskgungoal.cpp +${SRC_DIR}/object/task/taskinfo.cpp +${SRC_DIR}/object/task/taskmanager.cpp +${SRC_DIR}/object/task/taskmanip.cpp +${SRC_DIR}/object/task/taskpen.cpp +${SRC_DIR}/object/task/taskrecover.cpp +${SRC_DIR}/object/task/taskreset.cpp +${SRC_DIR}/object/task/tasksearch.cpp +${SRC_DIR}/object/task/taskshield.cpp +${SRC_DIR}/object/task/taskspiderexplo.cpp +${SRC_DIR}/object/task/tasktake.cpp +${SRC_DIR}/object/task/taskterraform.cpp +${SRC_DIR}/object/task/taskturn.cpp +${SRC_DIR}/object/task/taskwait.cpp +${SRC_DIR}/physics/physics.cpp +${SRC_DIR}/script/cbottoken.cpp +${SRC_DIR}/script/cmdtoken.cpp +${SRC_DIR}/script/script.cpp +${SRC_DIR}/ui/button.cpp +${SRC_DIR}/ui/check.cpp +${SRC_DIR}/ui/color.cpp +${SRC_DIR}/ui/compass.cpp +${SRC_DIR}/ui/control.cpp +${SRC_DIR}/ui/displayinfo.cpp +${SRC_DIR}/ui/displaytext.cpp +${SRC_DIR}/ui/edit.cpp +${SRC_DIR}/ui/editvalue.cpp +${SRC_DIR}/ui/gauge.cpp +${SRC_DIR}/ui/group.cpp +${SRC_DIR}/ui/image.cpp +${SRC_DIR}/ui/interface.cpp +${SRC_DIR}/ui/key.cpp +${SRC_DIR}/ui/label.cpp +${SRC_DIR}/ui/list.cpp +${SRC_DIR}/ui/maindialog.cpp +${SRC_DIR}/ui/mainmap.cpp +${SRC_DIR}/ui/mainshort.cpp +${SRC_DIR}/ui/map.cpp +${SRC_DIR}/ui/scroll.cpp +${SRC_DIR}/ui/shortcut.cpp +${SRC_DIR}/ui/slider.cpp +${SRC_DIR}/ui/studio.cpp +${SRC_DIR}/ui/target.cpp +${SRC_DIR}/ui/window.cpp ) set(UT_SOURCES main.cpp +graphics/engine/lightman_test.cpp math/geometry_test.cpp math/matrix_test.cpp math/vector_test.cpp ) -add_executable(colobot_ut ${UT_SOURCES}) -target_link_libraries(colobot_ut gtest) +include_directories( +${CMAKE_CURRENT_BINARY_DIR} +${SRC_DIR} +${GTEST_INCLUDE_DIR} +${GMOCK_INCLUDE_DIR} +. +common +math +) + +set(LIBS +gtest +gmock +CBot +${SDL_LIBRARY} +${SDLIMAGE_LIBRARY} +${SDLTTF_LIBRARY} +${OPENGL_LIBRARY} +${PNG_LIBRARIES} +${GLEW_LIBRARY} +${Boost_LIBRARIES} +${OPTIONAL_LIBS} +${PLATFORM_LIBS} +) + +add_executable(colobot_ut ${COLOBOT_SOURCES} ${UT_SOURCES}) +target_link_libraries(colobot_ut ${LIBS}) add_test(colobot_ut ./colobot_ut) diff --git a/test/unit/graphics/core/device_mock.h b/test/unit/graphics/core/device_mock.h new file mode 100644 index 0000000..80e214f --- /dev/null +++ b/test/unit/graphics/core/device_mock.h @@ -0,0 +1,107 @@ +#pragma once + +#include "graphics/core/device.h" + +#include + +class CDeviceMock : public Gfx::CDevice +{ +public: + CDeviceMock() {} + + MOCK_METHOD0(DebugHook, void()); + + MOCK_METHOD0(Create, bool()); + MOCK_METHOD0(Destroy, void()); + + MOCK_METHOD0(BeginScene, void()); + MOCK_METHOD0(EndScene, void()); + + MOCK_METHOD0(Clear, void()); + + MOCK_METHOD2(SetTransform, void(Gfx::TransformType type, const Math::Matrix &matrix)); + MOCK_METHOD1(GetTransform, const Math::Matrix& (Gfx::TransformType type)); + MOCK_METHOD2(MultiplyTransform, void(Gfx::TransformType type, const Math::Matrix &matrix)); + + MOCK_METHOD1(SetMaterial, void(const Gfx::Material &material)); + MOCK_METHOD0(GetMaterial, const Gfx::Material&()); + + MOCK_METHOD0(GetMaxLightCount, int()); + + MOCK_METHOD2(SetLight, void(int index, const Gfx::Light &light)); + MOCK_METHOD1(GetLight, const Gfx::Light&(int index)); + + MOCK_METHOD2(SetLightEnabled, void(int index, bool enabled)); + MOCK_METHOD1(GetLightEnabled, bool(int index)); + + MOCK_METHOD2(CreateTexture, Gfx::Texture(CImage *image, const Gfx::TextureCreateParams ¶ms)); + MOCK_METHOD2(CreateTexture, Gfx::Texture(ImageData *data, const Gfx::TextureCreateParams ¶ms)); + + MOCK_METHOD1(DestroyTexture, void(const Gfx::Texture &texture)); + MOCK_METHOD0(DestroyAllTextures, void()); + + MOCK_METHOD0(GetMaxTextureStageCount, int()); + + MOCK_METHOD2(SetTexture, void(int index, const Gfx::Texture &texture)); + MOCK_METHOD2(SetTexture, void(int index, unsigned int textureId)); + MOCK_METHOD1(GetTexture, Gfx::Texture(int index)); + + MOCK_METHOD2(SetTextureEnabled, void(int index, bool enabled)); + MOCK_METHOD1(GetTextureEnabled, bool(int index)); + + MOCK_METHOD2(SetTextureStageParams, void(int index, const Gfx::TextureStageParams ¶ms)); + MOCK_METHOD1(GetTextureStageParams, Gfx::TextureStageParams(int index)); + + MOCK_METHOD3(SetTextureStageWrap, void(int index, Gfx::TexWrapMode wrapS, Gfx::TexWrapMode wrapT)); + + MOCK_METHOD4(DrawPrimitive, void(Gfx::PrimitiveType type, const Gfx::Vertex *vertices, int vertexCount, Gfx::Color color)); + MOCK_METHOD4(DrawPrimitive, void(Gfx::PrimitiveType type, const Gfx::VertexTex2 *vertices, int vertexCount, Gfx::Color color)); + MOCK_METHOD3(DrawPrimitive, void(Gfx::PrimitiveType type, const Gfx::VertexCol *vertices, int vertexCount)); + + MOCK_METHOD3(CreateStaticBuffer, unsigned int(Gfx::PrimitiveType primitiveType, const Gfx::Vertex* vertices, int vertexCount)); + MOCK_METHOD3(CreateStaticBuffer, unsigned int(Gfx::PrimitiveType primitiveType, const Gfx::VertexTex2* vertices, int vertexCount)); + MOCK_METHOD3(CreateStaticBuffer, unsigned int(Gfx::PrimitiveType primitiveType, const Gfx::VertexCol* vertices, int vertexCount)); + + MOCK_METHOD4(UpdateStaticBuffer, void(unsigned int bufferId, Gfx::PrimitiveType primitiveType, const Gfx::Vertex* vertices, int vertexCount)); + MOCK_METHOD4(UpdateStaticBuffer, void(unsigned int bufferId, Gfx::PrimitiveType primitiveType, const Gfx::VertexTex2* vertices, int vertexCount)); + MOCK_METHOD4(UpdateStaticBuffer, void(unsigned int bufferId, Gfx::PrimitiveType primitiveType, const Gfx::VertexCol* vertices, int vertexCount)); + + MOCK_METHOD1(DrawStaticBuffer, void(unsigned int bufferId)); + + MOCK_METHOD1(DestroyStaticBuffer, void(unsigned int bufferId)); + + MOCK_METHOD2(ComputeSphereVisibility, int(const Math::Vector ¢er, float radius)); + + MOCK_METHOD2(SetRenderState, void(Gfx::RenderState state, bool enabled)); + MOCK_METHOD1(GetRenderState, bool(Gfx::RenderState state)); + + MOCK_METHOD1(SetDepthTestFunc, void(Gfx::CompFunc func)); + MOCK_METHOD0(GetDepthTestFunc, Gfx::CompFunc()); + + MOCK_METHOD1(SetDepthBias, void(float factor)); + MOCK_METHOD0(GetDepthBias, float()); + + MOCK_METHOD2(SetAlphaTestFunc, void(Gfx::CompFunc func, float refValue)); + MOCK_METHOD2(GetAlphaTestFunc, void(Gfx::CompFunc &func, float &refValue)); + + MOCK_METHOD2(SetBlendFunc, void(Gfx::BlendFunc srcBlend, Gfx::BlendFunc dstBlend)); + MOCK_METHOD2(GetBlendFunc, void(Gfx::BlendFunc &srcBlend, Gfx::BlendFunc &dstBlend)); + + MOCK_METHOD1(SetClearColor, void(const Gfx::Color &color)); + MOCK_METHOD0(GetClearColor, Gfx::Color()); + + MOCK_METHOD1(SetGlobalAmbient, void(const Gfx::Color &color)); + MOCK_METHOD0(GetGlobalAmbient, Gfx::Color()); + + MOCK_METHOD5(SetFogParams, void(Gfx::FogMode mode, const Gfx::Color &color, float start, float end, float density)); + MOCK_METHOD5(GetFogParams, void(Gfx::FogMode &mode, Gfx::Color &color, float &start, float &end, float &density)); + + MOCK_METHOD1(SetCullMode, void(Gfx::CullMode mode)); + MOCK_METHOD0(GetCullMode, Gfx::CullMode()); + + MOCK_METHOD1(SetShadeModel, void(Gfx::ShadeModel model)); + MOCK_METHOD0(GetShadeModel, Gfx::ShadeModel()); + + MOCK_METHOD1(SetFillMode, void(Gfx::FillMode mode)); + MOCK_METHOD0(GetFillMode, Gfx::FillMode()); +}; diff --git a/test/unit/graphics/engine/engine_mock.h b/test/unit/graphics/engine/engine_mock.h new file mode 100644 index 0000000..1a15eca --- /dev/null +++ b/test/unit/graphics/engine/engine_mock.h @@ -0,0 +1,14 @@ +#include "graphics/engine/engine.h" + +#include + +class CEngineMock : public Gfx::CEngine +{ +public: + CEngineMock() : Gfx::CEngine(nullptr) {} + + MOCK_METHOD0(GetPause, bool()); + + MOCK_METHOD0(GetEyePt, Math::Vector()); + MOCK_METHOD0(GetLookatPt, Math::Vector()); +}; diff --git a/test/unit/graphics/engine/lightman_test.cpp b/test/unit/graphics/engine/lightman_test.cpp new file mode 100644 index 0000000..529cee8 --- /dev/null +++ b/test/unit/graphics/engine/lightman_test.cpp @@ -0,0 +1,145 @@ +#include "graphics/engine/lightman.h" + +#include "graphics/core/device_mock.h" +#include "graphics/engine/engine_mock.h" + +#include + +using namespace Gfx; + +using testing::_; +using testing::Invoke; +using testing::Return; + +class LightManagerUT : public testing::Test +{ +protected: + LightManagerUT() + : lightManager(&engine) + {} + + void PrepareLightTesting(int maxLights, Math::Vector eyePos); + void CheckLightSorting(EngineObjectType objectType, const std::vector& expectedLights); + void CheckLight(int index, const Light& light); + void AddLight(int type, LightPriority priority, bool used, bool enabled, + Math::Vector pos, EngineObjectType includeType, EngineObjectType excludeType); + + + CLightManager lightManager; + CEngineMock engine; + CDeviceMock device; + +private: + std::vector dynamicLights; + std::vector expectedLightTypes; + int maxLightsCount; +}; + +void LightManagerUT::PrepareLightTesting(int maxLights, Math::Vector eyePos) +{ + maxLightsCount = maxLights; + + EXPECT_CALL(device, GetMaxLightCount()).WillOnce(Return(maxLights)); + lightManager.SetDevice(&device); + + ON_CALL(device, SetLight(_, _)).WillByDefault(Invoke(this, &LightManagerUT::CheckLight)); + + EXPECT_CALL(engine, GetEyePt()).WillRepeatedly(Return(eyePos)); +} + +void LightManagerUT::CheckLightSorting(EngineObjectType objectType, const std::vector& expectedLights) +{ + expectedLightTypes = expectedLights; + + EXPECT_CALL(device, SetLight(_, _)).Times(expectedLights.size()); + + for (int i = 0; i < static_cast( expectedLights.size() ); ++i) + EXPECT_CALL(device, SetLightEnabled(i, true)); + + for (int i = expectedLights.size(); i < maxLightsCount; ++i) + EXPECT_CALL(device, SetLightEnabled(i, false)); + + lightManager.UpdateDeviceLights(objectType); +} + +void LightManagerUT::CheckLight(int index, const Light& light) +{ + ASSERT_TRUE(index >= 0 && index < static_cast( expectedLightTypes.size() )); + ASSERT_EQ(expectedLightTypes[index], light.type); +} + +void LightManagerUT::AddLight(int type, LightPriority priority, bool used, bool enabled, + Math::Vector pos, EngineObjectType includeType, EngineObjectType excludeType) +{ + int rank = lightManager.CreateLight(priority); + + Light light; + light.type = static_cast(type); + lightManager.SetLight(rank, light); + + lightManager.SetLightEnabled(rank, enabled); + lightManager.SetLightIncludeType(rank, includeType); + lightManager.SetLightExcludeType(rank, excludeType); + + if (!used) + lightManager.DeleteLight(rank); +} + +TEST_F(LightManagerUT, LightSorting_UnusedOrDisabledAreSkipped) +{ + const int lightCount = 10; + const Math::Vector eyePos(0.0f, 0.0f, 0.0f); + PrepareLightTesting(lightCount, eyePos); + + AddLight(1, LIGHT_PRI_LOW, false, true, Math::Vector(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL); + AddLight(2, LIGHT_PRI_LOW, true, false, Math::Vector(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL); + AddLight(3, LIGHT_PRI_LOW, false, false, Math::Vector(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL); + + std::vector expectedLights; + CheckLightSorting(ENG_OBJTYPE_TERRAIN, expectedLights); +} + +TEST_F(LightManagerUT, LightSorting_IncludeTypesAreIncluded) +{ + const int lightCount = 10; + const Math::Vector eyePos(0.0f, 0.0f, 0.0f); + PrepareLightTesting(lightCount, eyePos); + + AddLight(1, LIGHT_PRI_LOW, true, true, Math::Vector(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL); + AddLight(2, LIGHT_PRI_LOW, true, true, Math::Vector(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_TERRAIN, ENG_OBJTYPE_NULL); + AddLight(3, LIGHT_PRI_LOW, true, true, Math::Vector(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_QUARTZ, ENG_OBJTYPE_NULL); + + std::vector expectedLights = { 1, 2 }; + CheckLightSorting(ENG_OBJTYPE_TERRAIN, expectedLights); +} + +TEST_F(LightManagerUT, LightSorting_ExcludeTypesAreExcluded) +{ + const int lightCount = 10; + const Math::Vector eyePos(0.0f, 0.0f, 0.0f); + PrepareLightTesting(lightCount, eyePos); + + AddLight(1, LIGHT_PRI_LOW, true, true, Math::Vector(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL); + AddLight(2, LIGHT_PRI_LOW, true, true, Math::Vector(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_TERRAIN); + AddLight(3, LIGHT_PRI_LOW, true, true, Math::Vector(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_QUARTZ); + + std::vector expectedLights = { 1, 3 }; + CheckLightSorting(ENG_OBJTYPE_TERRAIN, expectedLights); +} + +TEST_F(LightManagerUT, LightSorting_SortingAccordingToDistance) +{ + const int lightCount = 3; + const Math::Vector eyePos(0.0f, 0.0f, 0.0f); + PrepareLightTesting(lightCount, eyePos); + + AddLight(1, LIGHT_PRI_HIGH, true, true, Math::Vector(10.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL); + AddLight(2, LIGHT_PRI_LOW, true, true, Math::Vector(4.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL); + AddLight(3, LIGHT_PRI_HIGH, true, true, Math::Vector(20.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL); + AddLight(4, LIGHT_PRI_LOW, true, true, Math::Vector(11.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL); + AddLight(5, LIGHT_PRI_LOW, true, true, Math::Vector(100.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL); + AddLight(6, LIGHT_PRI_HIGH, true, true, Math::Vector(21.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL); + + std::vector expectedLights = { 1, 2, 3 }; + CheckLightSorting(ENG_OBJTYPE_TERRAIN, expectedLights); +} diff --git a/test/unit/ui/stubs/engine_stub.cpp b/test/unit/ui/stubs/engine_stub.cpp index 40886da..0a2777c 100644 --- a/test/unit/ui/stubs/engine_stub.cpp +++ b/test/unit/ui/stubs/engine_stub.cpp @@ -77,11 +77,28 @@ int CEngine::GetEditIndentValue() void CEngine::DeleteTexture(const std::string& /* texName */) { } + Texture CEngine::LoadTexture(const std::string& /* name */) { Texture texture; return texture; } +Math::Vector CEngine::GetEyePt() +{ + return Math::Vector(); +} + +Math::Vector CEngine::GetLookatPt() +{ + return Math::Vector(); +} + +bool CEngine::GetPause() +{ + return false; +} + + } /* Gfx */ -- cgit v1.2.3-1-g7c22 From b361d27d332591c59b5f8613fbf724d82872b877 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Thu, 28 Feb 2013 20:29:16 +0100 Subject: Removed unnecessary print --- src/sound/oalsound/alsound.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp index 17a46fe..47d5e34 100644 --- a/src/sound/oalsound/alsound.cpp +++ b/src/sound/oalsound/alsound.cpp @@ -468,7 +468,6 @@ void ALSound::FrameMove(float delta) // setting frequency frequency = progress * (oper.finalFrequency - it.second->GetStartFrequency()) * it.second->GetStartFrequency() * it.second->GetChangeFrequency() * it.second->GetInitFrequency(); it.second->AdjustFrequency(frequency); - GetLogger()->Error("%f\n", frequency); if (oper.totalTime <= oper.currentTime) { if (oper.nextOper == SOPER_LOOP) { -- cgit v1.2.3-1-g7c22 From 08c646bb929c7bc98b005521b6e0c14428f651d0 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Thu, 28 Feb 2013 21:26:09 +0100 Subject: Fixed stupid error, tweaked ambient light colors * fixed stupid error in light manager * tweaked ambient light colors to 0.1 of diffuse; colors should not be oversaturated now --- src/graphics/core/color.h | 10 ++++++++++ src/graphics/engine/lightman.cpp | 22 ++++++++++++---------- src/graphics/engine/pyro.cpp | 9 +++------ src/object/object.cpp | 25 +++++++------------------ src/object/robotmain.cpp | 2 ++ src/object/task/taskbuild.cpp | 17 +++++------------ src/object/task/taskshield.cpp | 13 ++++--------- src/ui/displayinfo.cpp | 1 + test/unit/graphics/engine/lightman_test.cpp | 7 ++++--- 9 files changed, 48 insertions(+), 58 deletions(-) diff --git a/src/graphics/core/color.h b/src/graphics/core/color.h index 7cbd175..5d059e5 100644 --- a/src/graphics/core/color.h +++ b/src/graphics/core/color.h @@ -76,6 +76,16 @@ struct Color { return ! this->operator==(other); } + + inline Color operator*(float scale) const + { + Color c = *this; + c.r *= scale; + c.g *= scale; + c.b *= scale; + c.a *= scale; + return c; + } }; /** diff --git a/src/graphics/engine/lightman.cpp b/src/graphics/engine/lightman.cpp index 628ebf5..eae622b 100644 --- a/src/graphics/engine/lightman.cpp +++ b/src/graphics/engine/lightman.cpp @@ -126,6 +126,7 @@ int CLightManager::CreateLight(LightPriority priority) m_dynLights[index].light.type = LIGHT_DIRECTIONAL; m_dynLights[index].light.diffuse = Color(0.5f, 0.5f, 0.5f); + m_dynLights[index].light.ambient = Color(0.0f, 0.0f, 0.0f); m_dynLights[index].light.position = Math::Vector(-100.0f, 100.0f, -100.0f); m_dynLights[index].light.direction = Math::Vector( 1.0f, -1.0f, 1.0f); @@ -391,21 +392,21 @@ void CLightManager::UpdateDeviceLights(EngineObjectType type) std::sort(sortedLights.begin(), sortedLights.end(), LightsComparator(m_engine->GetEyePt(), type)); int lightMapIndex = 0; - for (int i = 0; i < static_cast( m_dynLights.size() ); i++) + for (int i = 0; i < static_cast( sortedLights.size() ); i++) { - if (! m_dynLights[i].used) + if (! sortedLights[i].used) continue; - if (! m_dynLights[i].enabled) + if (! sortedLights[i].enabled) continue; - if (m_dynLights[i].intensity.current == 0.0f) + if (sortedLights[i].intensity.current == 0.0f) continue; bool enabled = true; - if (m_dynLights[i].includeType != ENG_OBJTYPE_NULL) - enabled = (m_dynLights[i].includeType == type); + if (sortedLights[i].includeType != ENG_OBJTYPE_NULL) + enabled = (sortedLights[i].includeType == type); - if (m_dynLights[i].excludeType != ENG_OBJTYPE_NULL) - enabled = (m_dynLights[i].excludeType != type); + if (sortedLights[i].excludeType != ENG_OBJTYPE_NULL) + enabled = (sortedLights[i].excludeType != type); if (enabled) { @@ -422,7 +423,8 @@ void CLightManager::UpdateDeviceLights(EngineObjectType type) int rank = m_lightMap[i]; if (rank != -1) { - m_device->SetLight(i, m_dynLights[rank].light); + sortedLights[rank].light.ambient = Gfx::Color(0.2f, 0.2f, 0.2f); + m_device->SetLight(i, sortedLights[rank].light); m_device->SetLightEnabled(i, true); } else @@ -458,7 +460,7 @@ bool CLightManager::LightsComparator::operator()(const DynamicLight& left, const float leftWeight = GetLightWeight(left); float rightWeight = GetLightWeight(right); - return leftWeight >= rightWeight; + return leftWeight <= rightWeight; } } // namespace Gfx diff --git a/src/graphics/engine/pyro.cpp b/src/graphics/engine/pyro.cpp index 1d80fea..cab28b6 100644 --- a/src/graphics/engine/pyro.cpp +++ b/src/graphics/engine/pyro.cpp @@ -1318,12 +1318,9 @@ void CPyro::CreateLight(Math::Vector pos, float height) Gfx::Light light; light.type = LIGHT_SPOT; - light.position.x = pos.x; - light.position.y = pos.y+height; - light.position.z = pos.z; - light.direction.x = 0.0f; - light.direction.y = -1.0f; // against the bottom - light.direction.z = 0.0f; + light.ambient = Gfx::Color(0.0f, 0.0f, 0.0f); + light.position = Math::Vector(pos.x, pos.y+height, pos.z); + light.direction = Math::Vector(0.0f, -1.0f, 0.0f); // against the bottom light.spotIntensity = 1.0f; light.attenuation0 = 1.0f; light.attenuation1 = 0.0f; diff --git a/src/object/object.cpp b/src/object/object.cpp index 8f2a4cc..d6ac681 100644 --- a/src/object/object.cpp +++ b/src/object/object.cpp @@ -2248,15 +2248,10 @@ bool CObject::CreateShadowLight(float height, Gfx::Color color) Gfx::Light light; light.type = Gfx::LIGHT_SPOT; - light.diffuse.r = color.r; - light.diffuse.g = color.g; - light.diffuse.b = color.b; - light.position.x = pos.x; - light.position.y = pos.y+height; - light.position.z = pos.z; - light.direction.x = 0.0f; - light.direction.y = -1.0f; // against the bottom - light.direction.z = 0.0f; + light.diffuse = color; + light.ambient = color * 0.1f; + light.position = Math::Vector(pos.x, pos.y+height, pos.z); + light.direction = Math::Vector(0.0f, -1.0f, 0.0f); // against the bottom light.spotIntensity = 128; light.attenuation0 = 1.0f; light.attenuation1 = 0.0f; @@ -2291,15 +2286,9 @@ bool CObject::CreateEffectLight(float height, Gfx::Color color) Gfx::Light light; light.type = Gfx::LIGHT_SPOT; - light.diffuse.r = color.r; - light.diffuse.g = color.g; - light.diffuse.b = color.b; - light.position.x = 0.0f; - light.position.y = 0.0f+height; - light.position.z = 0.0f; - light.direction.x = 0.0f; - light.direction.y = -1.0f; // against the bottom - light.direction.z = 0.0f; + light.diffuse = color; + light.position = Math::Vector(0.0f, height, 0.0f); + light.direction = Math::Vector(0.0f, -1.0f, 0.0f); // against the bottom light.spotIntensity = 0.0f; light.attenuation0 = 1.0f; light.attenuation1 = 0.0f; diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 6efd853..29fdd31 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -4917,6 +4917,7 @@ int CRobotMain::CreateLight(Math::Vector direction, Gfx::Color color) Gfx::Light light; light.type = Gfx::LIGHT_DIRECTIONAL; light.diffuse = color; + light.ambient = color * 0.1f; light.direction = direction; int obj = m_lightMan->CreateLight(Gfx::LIGHT_PRI_HIGH); m_lightMan->SetLight(obj, light); @@ -4934,6 +4935,7 @@ int CRobotMain::CreateSpot(Math::Vector pos, Gfx::Color color) Gfx::Light light; light.type = Gfx::LIGHT_SPOT; light.diffuse = color; + light.ambient = color * 0.1f; light.position = pos; light.direction = Math::Vector(0.0f, -1.0f, 0.0f); light.spotIntensity = 1.0f; diff --git a/src/object/task/taskbuild.cpp b/src/object/task/taskbuild.cpp index f209cd5..b9af475 100644 --- a/src/object/task/taskbuild.cpp +++ b/src/object/task/taskbuild.cpp @@ -114,7 +114,6 @@ bool CTaskBuild::CreateBuilding(Math::Vector pos, float angle) void CTaskBuild::CreateLight() { - Gfx::Light light; Gfx::Color color; Math::Vector center, pos, dir; Math::Point c, p; @@ -141,18 +140,12 @@ void CTaskBuild::CreateLight() pos.y = center.y+40.0f; dir = center-pos; - memset(&light, 0, sizeof(light)); + Gfx::Light light; light.type = Gfx::LIGHT_SPOT; - light.diffuse.r = 0.0f; - light.diffuse.g = 0.0f; - light.diffuse.b = 0.0f; // white (invisible) - light.position.x = pos.x; - light.position.y = pos.y; - light.position.z = pos.z; - light.direction.x = dir.x; - light.direction.y = dir.y; - light.direction.z = dir.z; - //TODO Is this value correct + light.ambient = Gfx::Color(0.0f, 0.0f, 0.0f); + light.diffuse = Gfx::Color(0.0f, 0.0f, 0.0f); // invisible + light.position = pos; + light.direction = dir; light.spotIntensity = 128; light.attenuation0 = 1.0f; light.attenuation1 = 0.0f; diff --git a/src/object/task/taskshield.cpp b/src/object/task/taskshield.cpp index 4b2fccd..929dd5c 100644 --- a/src/object/task/taskshield.cpp +++ b/src/object/task/taskshield.cpp @@ -488,15 +488,10 @@ bool CTaskShield::CreateLight(Math::Vector pos) memset(&light, 0, sizeof(light)); light.type = Gfx::LIGHT_SPOT; - light.diffuse.r = 0.0f; - light.diffuse.g = 1.0f; - light.diffuse.b = 2.0f; - light.position.x = pos.x; - light.position.y = pos.y; - light.position.z = pos.z; - light.direction.x = 0.0f; - light.direction.y = -1.0f; // against the bottom - light.direction.z = 0.0f; + light.ambient = Gfx::Color(0.0f, 0.0f, 0.0f); + light.diffuse = Gfx::Color(0.0f, 1.0f, 2.0f); + light.position = pos; + light.direction = Math::Vector(0.0f, -1.0f, 0.0f); // against the bottom light.spotIntensity = 128; light.attenuation0 = 1.0f; light.attenuation1 = 0.0f; diff --git a/src/ui/displayinfo.cpp b/src/ui/displayinfo.cpp index a9e754f..9a31956 100644 --- a/src/ui/displayinfo.cpp +++ b/src/ui/displayinfo.cpp @@ -455,6 +455,7 @@ void CDisplayInfo::StartDisplayInfo(std::string filename, int index, bool bSoluc } light.type = Gfx::LIGHT_DIRECTIONAL; + light.ambient = Gfx::Color(0.0f, 0.0f, 0.0f); light.diffuse = Gfx::Color(1.0f, 0.1f, 0.1f); light.direction = Math::Vector(1.0f, 0.0f, 1.0f); diff --git a/test/unit/graphics/engine/lightman_test.cpp b/test/unit/graphics/engine/lightman_test.cpp index 529cee8..b20b058 100644 --- a/test/unit/graphics/engine/lightman_test.cpp +++ b/test/unit/graphics/engine/lightman_test.cpp @@ -75,6 +75,7 @@ void LightManagerUT::AddLight(int type, LightPriority priority, bool used, bool Light light; light.type = static_cast(type); + light.position = pos; lightManager.SetLight(rank, light); lightManager.SetLightEnabled(rank, enabled); @@ -109,7 +110,7 @@ TEST_F(LightManagerUT, LightSorting_IncludeTypesAreIncluded) AddLight(2, LIGHT_PRI_LOW, true, true, Math::Vector(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_TERRAIN, ENG_OBJTYPE_NULL); AddLight(3, LIGHT_PRI_LOW, true, true, Math::Vector(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_QUARTZ, ENG_OBJTYPE_NULL); - std::vector expectedLights = { 1, 2 }; + std::vector expectedLights = { 2, 1 }; CheckLightSorting(ENG_OBJTYPE_TERRAIN, expectedLights); } @@ -123,7 +124,7 @@ TEST_F(LightManagerUT, LightSorting_ExcludeTypesAreExcluded) AddLight(2, LIGHT_PRI_LOW, true, true, Math::Vector(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_TERRAIN); AddLight(3, LIGHT_PRI_LOW, true, true, Math::Vector(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_QUARTZ); - std::vector expectedLights = { 1, 3 }; + std::vector expectedLights = { 3, 1 }; CheckLightSorting(ENG_OBJTYPE_TERRAIN, expectedLights); } @@ -140,6 +141,6 @@ TEST_F(LightManagerUT, LightSorting_SortingAccordingToDistance) AddLight(5, LIGHT_PRI_LOW, true, true, Math::Vector(100.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL); AddLight(6, LIGHT_PRI_HIGH, true, true, Math::Vector(21.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL); - std::vector expectedLights = { 1, 2, 3 }; + std::vector expectedLights = { 2, 1, 3 }; CheckLightSorting(ENG_OBJTYPE_TERRAIN, expectedLights); } -- cgit v1.2.3-1-g7c22 From f729686539b4e4628ab818e1a2bffbe1d48ed114 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Thu, 28 Feb 2013 22:56:44 +0100 Subject: Fixed segfault in light manager Also fixed minor memory leak --- src/graphics/engine/lightman.cpp | 5 +++-- src/object/robotmain.cpp | 9 +++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/graphics/engine/lightman.cpp b/src/graphics/engine/lightman.cpp index eae622b..16c84ea 100644 --- a/src/graphics/engine/lightman.cpp +++ b/src/graphics/engine/lightman.cpp @@ -389,7 +389,8 @@ void CLightManager::UpdateDeviceLights(EngineObjectType type) m_lightMap[i] = -1; std::vector sortedLights = m_dynLights; - std::sort(sortedLights.begin(), sortedLights.end(), LightsComparator(m_engine->GetEyePt(), type)); + LightsComparator lightsComparator(m_engine->GetEyePt(), type); + std::sort(sortedLights.begin(), sortedLights.end(), lightsComparator); int lightMapIndex = 0; for (int i = 0; i < static_cast( sortedLights.size() ); i++) @@ -460,7 +461,7 @@ bool CLightManager::LightsComparator::operator()(const DynamicLight& left, const float leftWeight = GetLightWeight(left); float rightWeight = GetLightWeight(right); - return leftWeight <= rightWeight; + return leftWeight < rightWeight; } } // namespace Gfx diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 29fdd31..7c6cb77 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -3833,7 +3833,12 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) int rankObj = 0; int rankGadget = 0; CObject* sel = 0; + + std::string oldLocale; char *locale = setlocale(LC_NUMERIC, nullptr); + if (locale != nullptr) + oldLocale = locale; + setlocale(LC_NUMERIC, "C"); while (fgets(line, 500, file) != NULL) @@ -4568,8 +4573,8 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) } m_dialog->SetSceneRead(""); m_dialog->SetStackRead(""); - - setlocale(LC_NUMERIC, locale); + + setlocale(LC_NUMERIC, oldLocale.c_str()); } //! Creates an object of decoration mobile or stationary -- cgit v1.2.3-1-g7c22 From 0864e44c7b631cc4c8a9937fe8a56f2c28b784cd Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 1 Mar 2013 21:35:58 +0100 Subject: Fix for #135 jet() parameter > 1 --- src/script/script.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/script/script.cpp b/src/script/script.cpp index 977070f..64139f3 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -2457,6 +2457,8 @@ bool CScript::rJet(CBotVar* var, CBotVar* result, int& exception, void* user) float value; value = var->GetValFloat(); + if( value > 1.0f ) value = 1.0f; + physics->SetMotorSpeedY(value); return true; -- cgit v1.2.3-1-g7c22 From 37a095b5b65f8098ee7541933d15de9ab12eb6a7 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 1 Mar 2013 21:56:52 +0100 Subject: MORE improvements to produce() --- src/script/script.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/script/script.cpp b/src/script/script.cpp index 64139f3..e8926d2 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -948,10 +948,8 @@ bool CScript::rDirection(CBotVar* var, CBotVar* result, int& exception, void* us } -// Compilation of the instruction "produce(pos, angle, type, scriptName, power)". -// or "produce(pos, angle, type, scriptName)" -// or "produce(pos, angle, type)" -// or "produce(type)" +// Compilation of the instruction "produce(pos, angle, type[, scriptName[, power]])" +// or "produce(type[, power])". CBotTypResult CScript::cProduce(CBotVar* &var, void* user) { @@ -961,6 +959,10 @@ CBotTypResult CScript::cProduce(CBotVar* &var, void* user) if ( var->GetType() <= CBotTypDouble ) { var = var->GetNext(); + if( var != 0 ) { + if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); + var = var->GetNext(); + } } else { ret = cPoint(var, user); if ( ret.GetType() != 0 ) return ret; @@ -989,10 +991,8 @@ CBotTypResult CScript::cProduce(CBotVar* &var, void* user) return CBotTypResult(CBotTypFloat); } -// Instruction "produce(pos, angle, type, scriptName, power)". -// or "produce(pos, angle, type, scriptName)" -// or "produce(pos, angle, type)" -// or "produce(type)" +// Instruction "produce(pos, angle, type[, scriptName[, power]])" +// or "produce(type[, power])". bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user) { @@ -1008,13 +1008,17 @@ bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user if ( var->GetType() <= CBotTypDouble ) { type = static_cast(var->GetValInt()); + var = var->GetNext(); pos = me->GetPosition(0); Math::Vector rotation = me->GetAngle(0) + me->GetInclinaison(); angle = rotation.y; - power = -1.0f; + if( var != 0 ) + power = var->GetValFloat(); + else + power = -1.0f; name = ""; } else { -- cgit v1.2.3-1-g7c22 From 1f565fdf389542eb0296bf7f685716200c559538 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 9 Mar 2013 15:28:36 +0100 Subject: "allmission" default value depends on build type --- src/object/robotmain.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 7c6cb77..95378c8 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -661,7 +661,11 @@ CRobotMain::CRobotMain(CApplication* app) m_showPos = false; m_selectInsect = false; m_showSoluce = false; + #ifdef NDEBUG + m_showAll = false; + #else m_showAll = true; // for development + #endif m_cheatRadar = false; m_fixScene = false; m_trainerPilot = false; -- cgit v1.2.3-1-g7c22 From bc859c4c597f106d40f07380bf255f180d565577 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 10 Mar 2013 15:44:21 +0100 Subject: VBO override option; argv parsing using getopt * added -vbo option to override autodetection of OpenGL VBO extension * refactored argument parsing to use getopt() * fixed failing UTs --- src/app/app.cpp | 246 +++++++++++++++++----------- src/app/app.h | 1 + src/common/logger.cpp | 82 ++++++++-- src/common/logger.h | 131 ++++++++------- src/graphics/opengl/gldevice.cpp | 25 ++- src/graphics/opengl/gldevice.h | 14 ++ test/unit/graphics/engine/lightman_test.cpp | 4 +- 7 files changed, 327 insertions(+), 176 deletions(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index ae5ac88..cb1ac34 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #ifdef OPENAL_SOUND @@ -195,102 +196,131 @@ CEventQueue* CApplication::GetEventQueue() CSoundInterface* CApplication::GetSound() { return m_sound; + + for (int i = 0; i < PCNT_MAX; ++i) + { + DestroyTimeStamp(m_performanceCounters[i][0]); + DestroyTimeStamp(m_performanceCounters[i][1]); + } } ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) { - bool waitDataDir = false; - bool waitLogLevel = false; - bool waitLanguage = false; - - for (int i = 1; i < argc; ++i) + enum OptionType { - std::string arg = argv[i]; - - if (waitDataDir) - { - waitDataDir = false; - m_dataPath = arg; - GetLogger()->Info("Using custom data dir: '%s'\n", m_dataPath.c_str()); - continue; - } - - if (waitLogLevel) + OPT_HELP = 1, + OPT_DEBUG, + OPT_DATADIR, + OPT_LOGLEVEL, + OPT_LANGUAGE, + OPT_VBO + }; + + option options[] = + { + { "help", no_argument, nullptr, OPT_HELP }, + { "debug", no_argument, nullptr, OPT_DEBUG }, + { "datadir", required_argument, nullptr, OPT_DATADIR }, + { "loglevel", required_argument, nullptr, OPT_LOGLEVEL }, + { "language", required_argument, nullptr, OPT_LANGUAGE }, + { "vbo", required_argument, nullptr, OPT_VBO } + }; + + opterr = 0; + + int c = 0; + int index = -1; + while ((c = getopt_long_only(argc, argv, "", options, &index)) != -1) + { + if (c == '?') { - waitLogLevel = false; - if (arg == "trace") - GetLogger()->SetLogLevel(LOG_TRACE); - else if (arg == "debug") - GetLogger()->SetLogLevel(LOG_DEBUG); - else if (arg == "info") - GetLogger()->SetLogLevel(LOG_INFO); - else if (arg == "warn") - GetLogger()->SetLogLevel(LOG_WARN); - else if (arg == "error") - GetLogger()->SetLogLevel(LOG_ERROR); - else if (arg == "none") - GetLogger()->SetLogLevel(LOG_NONE); + if (optopt == 0) + GetLogger()->Error("Invalid argument: %s\n", argv[optind-1]); else - return PARSE_ARGS_FAIL; - continue; - } + GetLogger()->Error("Expected argument for option: %s\n", argv[optind-1]); - if (waitLanguage) - { - waitLanguage = false; - if (arg == "en") - m_language = LANGUAGE_ENGLISH; - else if (arg == "de") - m_language = LANGUAGE_GERMAN; - else if (arg == "fr") - m_language = LANGUAGE_FRENCH; - else if (arg == "pl") - m_language = LANGUAGE_POLISH; - else - return PARSE_ARGS_FAIL; - continue; + m_exitCode = 1; + return PARSE_ARGS_FAIL; } - if (arg == "-debug") - { - SetDebugMode(true); - } - else if (arg == "-loglevel") - { - waitLogLevel = true; - } - else if (arg == "-datadir") - { - waitDataDir = true; - } - else if (arg == "-language") - { - waitLanguage = true; - } - else if (arg == "-help") - { - GetLogger()->Message("\n"); - GetLogger()->Message("Colobot %s (%s)\n",COLOBOT_CODENAME,COLOBOT_VERSION); - GetLogger()->Message("\n"); - GetLogger()->Message("List of available options:\n"); - GetLogger()->Message(" -help this help\n"); - GetLogger()->Message(" -datadir path set custom data directory path\n"); - GetLogger()->Message(" -debug enable debug mode (more info printed in logs)\n"); - GetLogger()->Message(" -loglevel level set log level to level (one of: trace, debug, info, warn, error, none)\n"); - GetLogger()->Message(" -language lang set language (one of: en, de, fr, pl)\n"); - return PARSE_ARGS_HELP; - } - else + index = -1; + + switch (c) { - m_exitCode = 1; - return PARSE_ARGS_FAIL; + case OPT_HELP: + { + GetLogger()->Message("\n"); + GetLogger()->Message("Colobot %s (%s)\n", COLOBOT_CODENAME, COLOBOT_VERSION); + GetLogger()->Message("\n"); + GetLogger()->Message("List of available options:\n"); + GetLogger()->Message(" -help this help\n"); + GetLogger()->Message(" -debug enable debug mode (more info printed in logs)\n"); + GetLogger()->Message(" -datadir path set custom data directory path\n"); + GetLogger()->Message(" -loglevel level set log level to level (one of: trace, debug, info, warn, error, none)\n"); + GetLogger()->Message(" -language lang set language (one of: en, de, fr, pl)\n"); + GetLogger()->Message(" -vbo mode set OpenGL VBO mode (one of: auto, enable, disable)\n"); + return PARSE_ARGS_HELP; + } + case OPT_DEBUG: + { + SetDebugMode(true); + break; + } + case OPT_DATADIR: + { + m_dataPath = optarg; + GetLogger()->Info("Using custom data dir: '%s'\n", m_dataPath.c_str()); + break; + } + case OPT_LOGLEVEL: + { + LogLevel logLevel; + if (! CLogger::ParseLogLevel(optarg, logLevel)) + { + GetLogger()->Error("Invalid log level: \"%s\"\n", optarg); + return PARSE_ARGS_FAIL; + } + + GetLogger()->Message("[*****] Log level changed to %s\n", optarg); + GetLogger()->SetLogLevel(logLevel); + break; + } + case OPT_LANGUAGE: + { + Language language; + if (! ParseLanguage(optarg, language)) + { + GetLogger()->Error("Invalid language: \"%s\"\n", optarg); + return PARSE_ARGS_FAIL; + } + + GetLogger()->Info("Using language %s\n", optarg); + m_language = language; + break; + } + case OPT_VBO: + { + std::string vbo; + vbo = optarg; + if (vbo == "auto") + m_deviceConfig.vboMode = Gfx::VBO_MODE_AUTO; + else if (vbo == "enable") + m_deviceConfig.vboMode = Gfx::VBO_MODE_ENABLE; + else if (vbo == "disable") + m_deviceConfig.vboMode = Gfx::VBO_MODE_DISABLE; + else + { + GetLogger()->Error("Invalid vbo mode: \"%s\"\n", optarg); + return PARSE_ARGS_FAIL; + } + + break; + } + default: + assert(false); // should never get here } } - // Args not given? - if (waitDataDir || waitLogLevel || waitLanguage) - return PARSE_ARGS_FAIL; - return PARSE_ARGS_OK; } @@ -336,7 +366,7 @@ bool CApplication::Create() } else { m_sound->CacheAll(GetDataSubdirPath(DIR_SOUND)); } - + if (GetProfile().GetLocalProfileString("Resources", "Music", path)) { m_sound->AddMusicFiles(path); } else { @@ -376,20 +406,22 @@ bool CApplication::Create() m_exitCode = 3; return false; } - + // load settings from profile int iValue; - if ( GetProfile().GetLocalProfileInt("Setup", "Resolution", iValue) ) { - std::vector modes; - GetVideoResolutionList(modes, true, true); - if (static_cast(iValue) < modes.size()) - m_deviceConfig.size = modes.at(iValue); + if ( GetProfile().GetLocalProfileInt("Setup", "Resolution", iValue) ) + { + std::vector modes; + GetVideoResolutionList(modes, true, true); + if (static_cast(iValue) < modes.size()) + m_deviceConfig.size = modes.at(iValue); } - - if ( GetProfile().GetLocalProfileInt("Setup", "Fullscreen", iValue) ) { - m_deviceConfig.fullScreen = (iValue == 1); + + if ( GetProfile().GetLocalProfileInt("Setup", "Fullscreen", iValue) ) + { + m_deviceConfig.fullScreen = (iValue == 1); } - + if (! CreateVideoSurface()) return false; // dialog is in function @@ -409,7 +441,7 @@ bool CApplication::Create() // Don't generate joystick events SDL_JoystickEventState(SDL_IGNORE); - + // The video is ready, we can create and initalize the graphics device m_device = new Gfx::CGLDevice(m_deviceConfig); if (! m_device->Create() ) @@ -1503,6 +1535,32 @@ char CApplication::GetLanguageChar() return langChar; } +bool CApplication::ParseLanguage(const std::string& str, Language& language) +{ + if (str == "en") + { + language = LANGUAGE_ENGLISH; + return true; + } + else if (str == "de") + { + language = LANGUAGE_GERMAN; + return true; + } + else if (str == "fr") + { + language = LANGUAGE_FRENCH; + return true; + } + else if (str == "pl") + { + language = LANGUAGE_POLISH; + return true; + } + + return false; +} + void CApplication::SetLanguage(Language language) { m_language = language; diff --git a/src/app/app.h b/src/app/app.h index f3f5601..71a3527 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -327,6 +327,7 @@ public: Language GetLanguage(); char GetLanguageChar(); void SetLanguage(Language language); + static bool ParseLanguage(const std::string& str, Language& language); //@} //! Management of sleep in main loop (lowers CPU usage) diff --git a/src/common/logger.cpp b/src/common/logger.cpp index 3ec9746..8bc4cef 100644 --- a/src/common/logger.cpp +++ b/src/common/logger.cpp @@ -36,25 +36,37 @@ CLogger::~CLogger() } -void CLogger::Log(LogType type, const char *str, va_list args) +void CLogger::Log(LogLevel type, const char* str, va_list args) { if (type < mLogLevel) return; - switch (type) { - case LOG_TRACE: fprintf(IsOpened() ? mFile : stderr, "[TRACE]: "); break; - case LOG_DEBUG: fprintf(IsOpened() ? mFile : stderr, "[DEBUG]: "); break; - case LOG_WARN: fprintf(IsOpened() ? mFile : stderr, "[WARN]: "); break; - case LOG_INFO: fprintf(IsOpened() ? mFile : stderr, "[INFO]: "); break; - case LOG_ERROR: fprintf(IsOpened() ? mFile : stderr, "[ERROR]: "); break; - default: break; + switch (type) + { + case LOG_TRACE: + fprintf(IsOpened() ? mFile : stderr, "[TRACE]: "); + break; + case LOG_DEBUG: + fprintf(IsOpened() ? mFile : stderr, "[DEBUG]: "); + break; + case LOG_WARN: + fprintf(IsOpened() ? mFile : stderr, "[WARN]: "); + break; + case LOG_INFO: + fprintf(IsOpened() ? mFile : stderr, "[INFO]: "); + break; + case LOG_ERROR: + fprintf(IsOpened() ? mFile : stderr, "[ERROR]: "); + break; + default: + break; } vfprintf(IsOpened() ? mFile : stderr, str, args); } -void CLogger::Trace(const char *str, ...) +void CLogger::Trace(const char* str, ...) { va_list args; va_start(args, str); @@ -63,7 +75,7 @@ void CLogger::Trace(const char *str, ...) } -void CLogger::Debug(const char *str, ...) +void CLogger::Debug(const char* str, ...) { va_list args; va_start(args, str); @@ -72,7 +84,7 @@ void CLogger::Debug(const char *str, ...) } -void CLogger::Info(const char *str, ...) +void CLogger::Info(const char* str, ...) { va_list args; va_start(args, str); @@ -81,7 +93,7 @@ void CLogger::Info(const char *str, ...) } -void CLogger::Warn(const char *str, ...) +void CLogger::Warn(const char* str, ...) { va_list args; va_start(args, str); @@ -90,7 +102,7 @@ void CLogger::Warn(const char *str, ...) } -void CLogger::Error(const char *str, ...) +void CLogger::Error(const char* str, ...) { va_list args; va_start(args, str); @@ -99,7 +111,7 @@ void CLogger::Error(const char *str, ...) } -void CLogger::Message(const char *str, ...) +void CLogger::Message(const char* str, ...) { va_list args; va_start(args, str); @@ -118,6 +130,7 @@ void CLogger::SetOutputFile(std::string filename) void CLogger::Open() { mFile = fopen(mFilename.c_str(), "w"); + if (mFile == NULL) fprintf(stderr, "Could not create file %s\n", mFilename.c_str()); } @@ -136,6 +149,45 @@ bool CLogger::IsOpened() } -void CLogger::SetLogLevel(LogType type) { +void CLogger::SetLogLevel(LogLevel type) +{ mLogLevel = type; } + + +bool CLogger::ParseLogLevel(const std::string& str, LogLevel& logLevel) +{ + if (str == "trace") + { + logLevel = LOG_TRACE; + return true; + } + else if (str == "debug") + { + logLevel = LOG_DEBUG; + return true; + } + else if (str == "info") + { + logLevel = LOG_INFO; + return true; + } + else if (str == "warn") + { + logLevel = LOG_WARN; + return true; + } + else if (str == "error") + { + logLevel = LOG_ERROR; + return true; + } + else if (str == "none") + { + logLevel = LOG_NONE; + return true; + } + + return false; +} + diff --git a/src/common/logger.h b/src/common/logger.h index 198e5e5..769f548 100644 --- a/src/common/logger.h +++ b/src/common/logger.h @@ -31,10 +31,10 @@ /** * \public - * \enum LogType common/logger.h + * \enum LogLevel common/logger.h * \brief Enum representing log level **/ -enum LogType +enum LogLevel { LOG_TRACE = 1, /*!< lowest level, execution tracing */ LOG_DEBUG = 2, /*!< debugging messages */ @@ -53,65 +53,74 @@ enum LogType */ class CLogger : public CSingleton { - public: - CLogger(); - ~CLogger(); - - /** Write message to console or file - * \param str - message to write - * \param ... - additional arguments - */ - void Message(const char *str, ...); - - /** Write message to console or file with LOG_TRACE level - * \param str - message to write - * \param ... - additional arguments - */ - void Trace(const char *str, ...); - - /** Write message to console or file with LOG_DEBUG level - * \param str - message to write - * \param ... - additional arguments - */ - void Debug(const char *str, ...); - - /** Write message to console or file with LOG_INFO level - * \param str - message to write - * \param ... - additional arguments - */ - void Info(const char *str, ...); - - /** Write message to console or file with LOG_WARN level - * \param str - message to write - * \param ... - additional arguments - */ - void Warn(const char *str, ...); - - /** Write message to console or file with LOG_ERROR level - * \param str - message to write - * \param ... - additional arguments - */ - void Error(const char *str, ...); - - /** Set output file to write logs to - * \param filename - output file to write to - */ - void SetOutputFile(std::string filename); - - /** Set log level. Logs with level below will not be shown - * \param level - minimum log level to write - */ - void SetLogLevel(LogType level); - - private: - std::string mFilename; - FILE *mFile; - LogType mLogLevel; - - void Open(); - void Close(); - bool IsOpened(); - void Log(LogType type, const char* str, va_list args); +public: + CLogger(); + ~CLogger(); + + /** Write message to console or file + * \param str - message to write + * \param ... - additional arguments + */ + void Message(const char *str, ...); + + /** Write message to console or file with LOG_TRACE level + * \param str - message to write + * \param ... - additional arguments + */ + void Trace(const char *str, ...); + + /** Write message to console or file with LOG_DEBUG level + * \param str - message to write + * \param ... - additional arguments + */ + void Debug(const char *str, ...); + + /** Write message to console or file with LOG_INFO level + * \param str - message to write + * \param ... - additional arguments + */ + void Info(const char *str, ...); + + /** Write message to console or file with LOG_WARN level + * \param str - message to write + * \param ... - additional arguments + */ + void Warn(const char *str, ...); + + /** Write message to console or file with LOG_ERROR level + * \param str - message to write + * \param ... - additional arguments + */ + void Error(const char *str, ...); + + /** Set output file to write logs to + * \param filename - output file to write to + */ + void SetOutputFile(std::string filename); + + /** Set log level. Logs with level below will not be shown + * \param level - minimum log level to write + */ + void SetLogLevel(LogLevel level); + + /** Parses string as a log level + * \param str string to parse + * \param logLevel result log level + * + * Valid values are "trace", "debug", "info", "warn", "error" and "none". + * On invalid value, returns \c false. + */ + static bool ParseLogLevel(const std::string& str, LogLevel& logLevel); + +private: + std::string mFilename; + FILE *mFile; + LogLevel mLogLevel; + + void Open(); + void Close(); + bool IsOpened(); + void Log(LogLevel type, const char* str, va_list args); }; diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index 80fa9a1..beeb85e 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -51,6 +51,8 @@ void GLDeviceConfig::LoadDefault() greenSize = 8; alphaSize = 8; depthSize = 24; + + vboMode = VBO_MODE_AUTO; } @@ -99,11 +101,26 @@ bool CGLDevice::Create() if (!m_multitextureAvailable) GetLogger()->Warn("GLEW reports multitexturing not supported - graphics quality will be degraded!\n"); - m_vboAvailable = glewIsSupported("GL_ARB_vertex_buffer_object"); - if (m_vboAvailable) - GetLogger()->Info("Detected ARB_vertex_buffer_object extension - using VBOs\n"); + if (m_config.vboMode == VBO_MODE_ENABLE) + { + GetLogger()->Info("VBO enabled by override - using VBOs\n"); + m_vboAvailable = true; + } + else if (m_config.vboMode == VBO_MODE_DISABLE) + { + GetLogger()->Info("VBO disabled by override - using display lists\n"); + m_vboAvailable = false; + } else - GetLogger()->Info("No ARB_vertex_buffer_object extension present - using display lists\n"); + { + GetLogger()->Info("Auto-detecting VBO support\n"); + m_vboAvailable = glewIsSupported("GL_ARB_vertex_buffer_object"); + + if (m_vboAvailable) + GetLogger()->Info("Detected ARB_vertex_buffer_object extension - using VBOs\n"); + else + GetLogger()->Info("No ARB_vertex_buffer_object extension present - using display lists\n"); + } } // This is mostly done in all modern hardware by default diff --git a/src/graphics/opengl/gldevice.h b/src/graphics/opengl/gldevice.h index 7137671..fe3f2a1 100644 --- a/src/graphics/opengl/gldevice.h +++ b/src/graphics/opengl/gldevice.h @@ -33,6 +33,17 @@ // Graphics module namespace namespace Gfx { +/** + \enum VBOMode + \brief VBO autodetect/override + */ +enum VBOMode +{ + VBO_MODE_ENABLE, //! < override: enable + VBO_MODE_DISABLE, //! < override: disable + VBO_MODE_AUTO //! < autodetect +}; + /** \struct GLDeviceConfig \brief Additional config with OpenGL-specific settings */ @@ -52,6 +63,9 @@ struct GLDeviceConfig : public DeviceConfig //! Force hardware acceleration (video mode set will fail on lack of hw accel) bool hardwareAccel; + //! VBO override/autodetect + VBOMode vboMode; + //! Constructor calls LoadDefaults() GLDeviceConfig(); diff --git a/test/unit/graphics/engine/lightman_test.cpp b/test/unit/graphics/engine/lightman_test.cpp index b20b058..c955f0a 100644 --- a/test/unit/graphics/engine/lightman_test.cpp +++ b/test/unit/graphics/engine/lightman_test.cpp @@ -110,7 +110,7 @@ TEST_F(LightManagerUT, LightSorting_IncludeTypesAreIncluded) AddLight(2, LIGHT_PRI_LOW, true, true, Math::Vector(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_TERRAIN, ENG_OBJTYPE_NULL); AddLight(3, LIGHT_PRI_LOW, true, true, Math::Vector(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_QUARTZ, ENG_OBJTYPE_NULL); - std::vector expectedLights = { 2, 1 }; + std::vector expectedLights = { 1, 2 }; CheckLightSorting(ENG_OBJTYPE_TERRAIN, expectedLights); } @@ -124,7 +124,7 @@ TEST_F(LightManagerUT, LightSorting_ExcludeTypesAreExcluded) AddLight(2, LIGHT_PRI_LOW, true, true, Math::Vector(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_TERRAIN); AddLight(3, LIGHT_PRI_LOW, true, true, Math::Vector(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_QUARTZ); - std::vector expectedLights = { 3, 1 }; + std::vector expectedLights = { 1, 3 }; CheckLightSorting(ENG_OBJTYPE_TERRAIN, expectedLights); } -- cgit v1.2.3-1-g7c22 From 47e7904bb7c4bdf8024a154602f7d1ede9b77387 Mon Sep 17 00:00:00 2001 From: erihel Date: Thu, 14 Mar 2013 20:41:48 +0100 Subject: * Fix for issue #140 (not compiling sound files while sound support is enabled) --- test/unit/CMakeLists.txt | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index 21d1986..575f5c0 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -134,6 +134,31 @@ ${SRC_DIR}/ui/target.cpp ${SRC_DIR}/ui/window.cpp ) +set(OPENAL_SOURCES "") + +if (${OPENAL_SOUND}) + set(OPENAL_SOURCES + ${SRC_DIR}/sound/oalsound/alsound.cpp + ${SRC_DIR}/sound/oalsound/buffer.cpp + ${SRC_DIR}/sound/oalsound/channel.cpp + ) +endif() + +# Optional libraries +set(OPTIONAL_LIBS "") + +if (${OPENAL_SOUND}) + if (${PLATFORM_WINDOWS}) + set(OPTIONAL_LIBS + OpenAL32 + ) + else() + set(OPTIONAL_LIBS + openal + ) + endif() +endif() + set(UT_SOURCES main.cpp graphics/engine/lightman_test.cpp @@ -165,9 +190,10 @@ ${GLEW_LIBRARY} ${Boost_LIBRARIES} ${OPTIONAL_LIBS} ${PLATFORM_LIBS} +${LIBSNDFILE_LIBRARY} ) -add_executable(colobot_ut ${COLOBOT_SOURCES} ${UT_SOURCES}) +add_executable(colobot_ut ${COLOBOT_SOURCES} ${UT_SOURCES} ${OPENAL_SOURCES}) target_link_libraries(colobot_ut ${LIBS}) add_test(colobot_ut ./colobot_ut) -- cgit v1.2.3-1-g7c22 From 6c783b903392173a6a98048aad3d600e4dcfe103 Mon Sep 17 00:00:00 2001 From: erihel Date: Thu, 14 Mar 2013 21:30:32 +0100 Subject: * Fix for issue #122 with sound not being played in menu after playing mission --- src/object/robotmain.cpp | 9 +++++---- src/ui/maindialog.cpp | 4 ++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 95378c8..da6ac42 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -1146,6 +1146,7 @@ void CRobotMain::ChangePhase(Phase phase) if (m_phase == PHASE_WIN) { + m_sound->StopAll(); if (m_endingWinRank == -1) { ChangePhase(PHASE_TERM); @@ -1192,13 +1193,13 @@ void CRobotMain::ChangePhase(Phase phase) { m_displayText->DisplayError(INFO_WIN, Math::Vector(0.0f,0.0f,0.0f), 15.0f, 60.0f, 1000.0f); } + StartMusic(); } - m_sound->StopAll(); - StartMusic(); } if (m_phase == PHASE_LOST) { + m_sound->StopAll(); if (m_endingLostRank == -1) { ChangePhase(PHASE_TERM); @@ -1215,9 +1216,9 @@ void CRobotMain::ChangePhase(Phase phase) ddim.x = dim.x*2; ddim.y = dim.y*2; m_interface->CreateButton(pos, ddim, 16, EVENT_BUTTON_OK); m_displayText->DisplayError(INFO_LOST, Math::Vector(0.0f,0.0f,0.0f), 15.0f, 60.0f, 1000.0f); + + StartMusic(); } - m_sound->StopAll(); - StartMusic(); } if (m_phase == PHASE_LOADING) diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index fede0b7..a0b0e06 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -745,6 +745,10 @@ pb->SetState(STATE_SHADOW); m_phase == PHASE_USER || m_phase == PHASE_PROTO ) { + if (!m_sound->IsPlayingMusic()) { + m_sound->PlayMusic(11, true); + } + if ( m_phase == PHASE_TRAINER ) m_index = 0; if ( m_phase == PHASE_DEFI ) m_index = 1; if ( m_phase == PHASE_MISSION ) m_index = 2; -- cgit v1.2.3-1-g7c22 From 9f5bef030d97e9ee20d8c635335fdafd854fed44 Mon Sep 17 00:00:00 2001 From: erihel Date: Thu, 14 Mar 2013 23:03:03 +0100 Subject: * Adjusted sound volume to game settings * Added fabs to remove logs about pitch having negative values --- src/sound/oalsound/alsound.cpp | 10 +++++----- src/sound/oalsound/channel.cpp | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp index 47d5e34..8c1cb81 100644 --- a/src/sound/oalsound/alsound.cpp +++ b/src/sound/oalsound/alsound.cpp @@ -136,7 +136,7 @@ void ALSound::SetMusicVolume(int volume) { mMusicVolume = MIN(static_cast(volume) / MAXVOLUME, 1.0f); if (mCurrentMusic) { - mCurrentMusic->SetVolume(mMusicVolume); + mCurrentMusic->SetVolume(mMusicVolume * mAudioVolume); } } @@ -318,7 +318,7 @@ int ALSound::Play(Sound sound, Math::Vector pos, float amplitude, float frequenc Position(channel, pos); // setting initial values - mChannels[channel]->SetStartAmplitude(amplitude * mAudioVolume); + mChannels[channel]->SetStartAmplitude(amplitude); mChannels[channel]->SetStartFrequency(frequency); mChannels[channel]->SetChangeFrequency(1.0f); mChannels[channel]->ResetOper(); @@ -434,7 +434,7 @@ bool ALSound::MuteAll(bool bMute) volume = mAudioVolume; for (auto channel : mChannels) { - channel.second->SetVolume(volume); + channel.second->SetVolume(volume * mAudioVolume); } return true; @@ -508,7 +508,7 @@ bool ALSound::PlayMusic(int rank, bool bRepeat) GetLogger()->Debug("Music loaded from cache\n"); mCurrentMusic->SetBuffer(music); - mCurrentMusic->SetVolume(mMusicVolume); + mCurrentMusic->SetVolume(mMusicVolume * mAudioVolume); mCurrentMusic->SetLoop(bRepeat); mCurrentMusic->Play(); return true; @@ -533,7 +533,7 @@ bool ALSound::PlayMusic(int rank, bool bRepeat) mMusicCache[rank] = buffer; } - mCurrentMusic->SetVolume(mMusicVolume); + mCurrentMusic->SetVolume(mMusicVolume * mAudioVolume); mCurrentMusic->SetLoop(bRepeat); mCurrentMusic->Play(); diff --git a/src/sound/oalsound/channel.cpp b/src/sound/oalsound/channel.cpp index 0faecd0..19394c6 100644 --- a/src/sound/oalsound/channel.cpp +++ b/src/sound/oalsound/channel.cpp @@ -94,7 +94,7 @@ bool Channel::AdjustFrequency(float freq) if (!mReady || mBuffer == nullptr) return false; - return SetFrequency(mInitFrequency + freq); + return SetFrequency(mInitFrequency + fabs(freq)); } -- cgit v1.2.3-1-g7c22 From f88e74f887c2d9c1e519ea6cd7f265f92e9cc26b Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 17 Mar 2013 15:05:53 +0100 Subject: Fix for issue #129 Text on exit screen is improperly placed --- src/ui/maindialog.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index fede0b7..51971fa 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -1876,7 +1876,7 @@ ddim.y = 150.0f/480.0f; // TODO: #if !_DEMO pos.x = 40.0f/640.0f; - pos.y = 83.0f/480.0f; + pos.y = 65.0f/480.0f; ddim.x = 246.0f/640.0f; ddim.y = 16.0f/480.0f; GetResource(RES_TEXT, RT_GENERIC_DEV1, name); @@ -1884,14 +1884,14 @@ ddim.y = 150.0f/480.0f; pl->SetFontType(Gfx::FONT_COURIER); pl->SetFontSize(8.0f); - pos.y = 13.0f/480.0f; + pos.y = 0.0f/480.0f; GetResource(RES_TEXT, RT_GENERIC_DEV2, name); pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL2, name); pl->SetFontType(Gfx::FONT_COURIER); pl->SetFontSize(8.0f); pos.x = 355.0f/640.0f; - pos.y = 83.0f/480.0f; + pos.y = 65.0f/480.0f; ddim.x = 246.0f/640.0f; ddim.y = 16.0f/480.0f; GetResource(RES_TEXT, RT_GENERIC_EDIT1, name); @@ -1899,7 +1899,7 @@ ddim.y = 150.0f/480.0f; pl->SetFontType(Gfx::FONT_COURIER); pl->SetFontSize(8.0f); - pos.y = 13.0f/480.0f; + pos.y = 0.0f/480.0f; GetResource(RES_TEXT, RT_GENERIC_EDIT2, name); pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL4, name); pl->SetFontType(Gfx::FONT_COURIER); -- cgit v1.2.3-1-g7c22 From d6bbc99c90ef586b041651d373524b30fe6c8676 Mon Sep 17 00:00:00 2001 From: erihel Date: Sun, 17 Mar 2013 19:01:32 +0100 Subject: * Changed file loading to fix issue #73 * Moved few functions from misc.cpp to profile.cpp (used to set/get user dir) * Removed some warnings * More work to change const char* to std::string * Some work on file path to fix issue #60 with bad slashes on POSIX platform --- src/common/misc.cpp | 124 ++---------------------------------------- src/common/misc.h | 3 -- src/common/profile.cpp | 45 ++++++++++++++++ src/common/profile.h | 28 +++++++++- src/object/robotmain.cpp | 7 +-- src/script/script.cpp | 2 +- src/ui/displayinfo.cpp | 2 +- src/ui/edit.cpp | 136 ++++++++++++++++++++--------------------------- src/ui/edit.h | 29 +++++----- src/ui/maindialog.cpp | 25 +++++---- src/ui/maindialog.h | 6 +++ src/ui/studio.cpp | 36 ++++++------- src/ui/studio.h | 5 +- 13 files changed, 196 insertions(+), 252 deletions(-) diff --git a/src/common/misc.cpp b/src/common/misc.cpp index 2bce3b8..b96abca 100644 --- a/src/common/misc.cpp +++ b/src/common/misc.cpp @@ -25,10 +25,6 @@ #include -static bool g_bUserDir = false; -static char g_userDir[100] = ""; - - // Returns a non-accented letter. char GetNoAccent(char letter) @@ -234,72 +230,11 @@ void TimeToAscii(time_t time, char *buffer) #endif*/ } - -// Makes a copy of a file. - -bool Xfer(char* src, char* dst) -{ - FILE *fs, *fd; - char *buffer; - int len; - - fs = fopen(src, "rb"); - if ( fs == 0 ) - { - return false; - } - - fd = fopen(dst, "wb"); - if ( fd == 0 ) - { - fclose(fs); - return false; - } - - buffer = static_cast(malloc(10000)); - - while ( true ) - { - len = fread(buffer, 1, 10000, fs); - if ( len == 0 ) break; - fwrite(buffer, 1, len, fd); - } - - free(buffer); - fclose(fs); - fclose(fd); - return true; -} - -// Copy a file into the temporary folder. - -bool CopyFileToTemp(char* filename) -{ - char src[100]; - char dst[100]; - char save[100]; - - UserDir(src, filename, "textures"); - - strcpy(save, g_userDir); - strcpy(g_userDir, "temp"); - UserDir(dst, filename, "textures"); - strcpy(g_userDir, save); - - //_mkdir("temp"); - system("mkdir temp"); - - if ( !Xfer(src, dst) ) return false; - - strcpy(filename, dst); - return true; -} - // Copy a list of numbered files into the temporary folder. bool CopyFileListToTemp(char* filename, int* list, int total) { - char name[100]; + /*char name[100]; char ext[10]; char file[100]; char save[100]; @@ -329,8 +264,8 @@ bool CopyFileListToTemp(char* filename, int* list, int total) UserDir(file, filename, "textures"); strcpy(filename, file); strcpy(g_userDir, save); - - return true; +*/ + return false; } @@ -342,56 +277,3 @@ void AddExt(char* filename, const char* ext) strcat(filename, ext); } - -// Specifies the user folder. - -void UserDir(bool bUser, const char* dir) -{ - g_bUserDir = bUser; - strcpy(g_userDir, dir); -} - -// Replaces the string %user% by the user folder. -// in: dir = "%user%toto.txt" -// def = "abc\" -// out: buffer = "abc\toto.txt" - -void UserDir(char* buffer, const char* dir, const char* def) -{ - char ddir[100]; - const char* add; - - if ( strstr(dir, "\\") == 0 && def[0] != 0 ) - { - sprintf(ddir, "%s\\%s", def, dir); - } - else - { - strcpy(ddir, dir); - } - dir = ddir; - - while ( *dir != 0 ) - { - if ( dir[0] == '%' && - dir[1] == 'u' && - dir[2] == 's' && - dir[3] == 'e' && - dir[4] == 'r' && - dir[5] == '%' ) // %user% ? - { - if ( g_bUserDir ) add = g_userDir; - else add = def; - - while ( *add != 0 ) - { - *buffer++ = *add++; - } - dir += 6; // jumps to %user% - continue; - } - - *buffer++ = *dir++; - } - *buffer = 0; -} diff --git a/src/common/misc.h b/src/common/misc.h index f210706..e2ddc44 100644 --- a/src/common/misc.h +++ b/src/common/misc.h @@ -29,8 +29,5 @@ extern char GetToLower(char letter); extern void TimeToAscii(time_t time, char *buffer); -extern bool CopyFileToTemp(char* filename); extern bool CopyFileListToTemp(char* filename, int* list, int total); extern void AddExt(char* filename, const char* ext); -extern void UserDir(bool bUser, const char* dir); -extern void UserDir(char* buffer, const char* dir, const char* def); diff --git a/src/common/profile.cpp b/src/common/profile.cpp index 18cc187..2d11217 100644 --- a/src/common/profile.cpp +++ b/src/common/profile.cpp @@ -182,3 +182,48 @@ std::vector< std::string > CProfile::GetLocalProfileSection(std::string section, return ret_list; } + + +void CProfile::SetUserDir(std::string dir) +{ + m_userDirectory = dir; +} + + +std::string CProfile::GetUserBasedPath(std::string dir, std::string default_dir) +{ + std::string path = dir; + boost::replace_all(path, "\\", "/"); + if (dir.find("/") == std::string::npos) { + path = default_dir + "/" + dir; + } + + if (m_userDirectory.length() > 0) { + boost::replace_all(path, "%user%", m_userDirectory); + } else { + boost::replace_all(path, "%user%", default_dir); + } + + return fs::path(path).make_preferred().string(); +} + + +bool CProfile::CopyFileToTemp(std::string filename) +{ + std::string src, dst; + std::string tmp_user_dir = m_userDirectory; + + src = GetUserBasedPath(filename, "textures"); + SetUserDir("temp"); + dst = GetUserBasedPath(filename, "textures"); + SetUserDir(tmp_user_dir); + + fs::create_directory(fs::path(dst).parent_path().make_preferred().string()); + fs::copy_file(src, dst, fs::copy_option::overwrite_if_exists); + if (fs::exists(dst)) { + return true; + } + + return false; +} + diff --git a/src/common/profile.h b/src/common/profile.h index 9bc6c37..bcd76c3 100644 --- a/src/common/profile.h +++ b/src/common/profile.h @@ -21,14 +21,20 @@ #pragma once - #include "common/singleton.h" +// this is just to fix problem with undefined reference when compiling with c++11 support +#define BOOST_NO_SCOPED_ENUMS + #include +#include +#include #include #include +namespace fs = boost::filesystem; + /** * \class CProfile @@ -101,10 +107,30 @@ class CProfile : public CSingleton * \return vector of values */ std::vector< std::string > GetLocalProfileSection(std::string section, std::string key); + + /** Sets current user directory + * \param dir + */ + void SetUserDir(std::string dir); + + /** Returns path based on current user. Replaces %user% in path with current user dir or + * uses default_dir param if no user dir is specified + * \param dir + * \param default_dir + * \return path + */ + std::string GetUserBasedPath(std::string dir, std::string default_dir); + + /** opy a file into the temporary folder. + * \param filename + * \return true on success + */ + bool CopyFileToTemp(std::string filename); private: boost::property_tree::ptree m_propertyTree; bool m_profileNeedSave; + std::string m_userDirectory; }; //! Global function to get profile instance diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index da6ac42..635fc4e 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -1187,7 +1187,7 @@ void CRobotMain::ChangePhase(Phase phase) pe->SetFontType(Gfx::FONT_COLOBOT); pe->SetEditCap(false); pe->SetHiliteCap(false); - pe->ReadText("help/win.txt"); + pe->ReadText(std::string("help/win.txt")); } else { @@ -4094,8 +4094,9 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) { OpString(line, "image", name); AddExt(name, ".png"); - if (strstr(name, "%user%") != 0) - CopyFileToTemp(name); + if (strstr(name, "%user%") != 0) { + GetProfile().CopyFileToTemp(std::string(name)); + } m_terrain->AddMaterial(OpInt(line, "id", 0), name, diff --git a/src/script/script.cpp b/src/script/script.cpp index e8926d2..a62866d 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -3900,7 +3900,7 @@ bool CScript::WriteScript(const char* filename) edit->SetMaxChar(Ui::EDITSTUDIOMAX); edit->SetAutoIndent(m_engine->GetEditIndentMode()); edit->SetText(m_script); - edit->WriteText(name.c_str()); + edit->WriteText(name); m_interface->DeleteControl(EVENT_EDIT9); return true; } diff --git a/src/ui/displayinfo.cpp b/src/ui/displayinfo.cpp index 9a31956..5c41f65 100644 --- a/src/ui/displayinfo.cpp +++ b/src/ui/displayinfo.cpp @@ -671,7 +671,7 @@ void CDisplayInfo::ChangeIndexButton(int index) { filename = m_main->GetDisplayInfoName(m_index); edit->ReadText(filename); - edit->HyperHome(filename); + edit->HyperHome(std::string(filename)); SetPosition(m_main->GetDisplayInfoPosition(m_index)); } diff --git a/src/ui/edit.cpp b/src/ui/edit.cpp index c0b6446..a96d231 100644 --- a/src/ui/edit.cpp +++ b/src/ui/edit.cpp @@ -560,7 +560,7 @@ bool CEdit::IsLinkPos(Math::Point pos) if ( i == -1 ) return false; if ( i >= m_len ) return false; - if ( m_format.size() > i && ((m_format[i] & Gfx::FONT_MASK_HIGHLIGHT) == Gfx::FONT_HIGHLIGHT_LINK)) return true; // TODO + if ( m_format.size() > static_cast(i) && ((m_format[i] & Gfx::FONT_MASK_HIGHLIGHT) == Gfx::FONT_HIGHLIGHT_LINK)) return true; // TODO return false; } @@ -760,7 +760,7 @@ void CEdit::HyperFlush() // Indicates which is the home page. -void CEdit::HyperHome(const char *filename) +void CEdit::HyperHome(std::string filename) { HyperFlush(); HyperAdd(filename, 0); @@ -768,10 +768,10 @@ void CEdit::HyperHome(const char *filename) // Performs a hyper jump through a link. -void CEdit::HyperJump(const char *name, const char *marker) +void CEdit::HyperJump(std::string name, std::string marker) { - char filename[100]; - char sMarker[100]; + std::string filename; + std:: string sMarker; int i, line, pos; if ( m_historyCurrent >= 0 ) @@ -779,18 +779,17 @@ void CEdit::HyperJump(const char *name, const char *marker) m_history[m_historyCurrent].firstLine = m_lineFirst; } - strcpy(sMarker, marker); + sMarker = marker; //? sprintf(filename, "help\\%s.txt", name); - if ( name[0] == '%' ) - { - UserDir(filename, name, ""); - strcat(filename, ".txt"); - } - else - { - sprintf(filename, "help\\%s.txt", name); + + if ( name[0] == '%' ) { + filename = GetProfile().GetUserBasedPath(name, "") + ".txt"; + } else { + std::string path = CApplication::GetInstancePointer()->GetDataDirPath() + "/help/" + name + ".txt"; + filename = fs::path(path).generic_string(); } + if ( ReadText(filename) ) { Justif(); @@ -798,7 +797,7 @@ void CEdit::HyperJump(const char *name, const char *marker) line = 0; for ( i=0 ; i= EDITHISTORYMAX-1 ) return false; m_historyCurrent ++; - strcpy(m_history[m_historyCurrent].filename, filename); + m_history[m_historyCurrent].filename = filename; m_history[m_historyCurrent].firstLine = firstLine; m_historyTotal = m_historyCurrent+1; @@ -1136,16 +1135,14 @@ void CEdit::Draw() // Draw an image part. -void CEdit::DrawImage(Math::Point pos, const char *name, float width, +void CEdit::DrawImage(Math::Point pos, std::string name, float width, float offset, float height, int nbLine) { - Math::Point uv1, uv2, dim; - float dp; - char filename[100]; + Math::Point uv1, uv2, dim; + float dp; + std::string filename; -//? sprintf(filename, "diagram\\%s.png", name); - UserDir(filename, name, "diagram"); - strcat(filename, ".png"); + filename = GetProfile().GetUserBasedPath(name, "diagram") + ".png"; m_engine->SetTexture(filename); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); @@ -1389,77 +1386,64 @@ int CEdit::GetTextLength() // Returns a name in a command. // \x nom1 nom2 nom3; -void GetNameParam(const char *cmd, int rank, char *buffer) +std::string GetNameParam(std::string cmd, int rank) { - int i; - - for ( i=0 ; i results; + boost::split(results, cmd, boost::is_any_of(" ;")); + + if (results.size() > static_cast(rank)) { + return results.at(rank); } - while ( *cmd != ' ' && *cmd != ';' ) - { - *buffer++ = *cmd++; - } - *buffer = 0; + return ""; } // Returns a number of a command. // \x nom n1 n2; -int GetValueParam(const char *cmd, int rank) +int GetValueParam(std::string cmd, int rank) { - int n, i; - - for ( i=0 ; i results; + boost::split(results, cmd, boost::is_any_of(" ;")); + int return_value = 0; + + if (results.size() > static_cast(rank)) { + try { + return_value = std::stoi(results.at(rank)); + } catch (std::invalid_argument &e) { + GetLogger()->Error("Exception std::invalid_argument caught in GetValueParam function"); + } catch (std::out_of_range &e) { + GetLogger()->Error("Exception std::out_of_range caught in GetValueParam function"); } - if ( *cmd != ';' ) cmd ++; } - sscanf(cmd, "%d", &n); - return n; + return return_value; } // Frees all images. void CEdit::FreeImage() { - char filename[100]; - int i; + std::string filename; - for ( i=0 ; iDeleteTexture(filename); } } // Reads the texture of an image. -void CEdit::LoadImage(const char *name) +void CEdit::LoadImage(std::string name) { - char filename[100]; - -//? sprintf(filename, "diagram\\%s.png", name); - UserDir(filename, name, "diagram"); - strcat(filename, ".png"); + std::string filename; + filename = GetProfile().GetUserBasedPath(name, "diagram") + ".png"; m_engine->LoadTexture(filename); } // Read from a text file. -bool CEdit::ReadText(const char *filename, int addSize) +bool CEdit::ReadText(std::string filename, int addSize) { FILE *file = NULL; char *buffer; @@ -1471,7 +1455,7 @@ bool CEdit::ReadText(const char *filename, int addSize) bool bInSoluce, bBOL; if ( filename[0] == 0 ) return false; - file = fopen(filename, "rb"); + file = fopen(filename.c_str(), "rb"); if ( file == NULL ) return false; fseek(file, 0, SEEK_END); @@ -1605,8 +1589,8 @@ bool CEdit::ReadText(const char *filename, int addSize) { if ( iLink < EDITLINKMAX ) { - GetNameParam(buffer+i+3, 0, m_link[iLink].name); - GetNameParam(buffer+i+3, 1, m_link[iLink].marker); + m_link[iLink].name = GetNameParam(buffer+i+3, 0); + m_link[iLink].marker = GetNameParam(buffer+i+3, 1); iLink ++; } font &= ~Gfx::FONT_MASK_HIGHLIGHT; @@ -1622,7 +1606,7 @@ bool CEdit::ReadText(const char *filename, int addSize) { if ( m_markerTotal < EDITLINKMAX ) { - GetNameParam(buffer+i+3, 0, m_marker[m_markerTotal].name); + m_marker[m_markerTotal].name = GetNameParam(buffer+i+3, 0); m_marker[m_markerTotal].pos = j; m_markerTotal ++; } @@ -1640,21 +1624,19 @@ bool CEdit::ReadText(const char *filename, int addSize) { if ( m_bSoluce || !bInSoluce ) { -#if _DEMO - strcpy(iName, "demo"); -#else - GetNameParam(buffer+i+7, 0, iName); -#endif + + strcpy(iName, GetNameParam(buffer+i+7, 0).c_str()); + //? iWidth = m_lineHeight*RetValueParam(buffer+i+7, 1); iWidth = static_cast(GetValueParam(buffer+i+7, 1)); iWidth *= m_engine->GetText()->GetHeight(Gfx::FONT_COLOBOT, Gfx::FONT_SIZE_SMALL); iLines = GetValueParam(buffer+i+7, 2); - LoadImage(iName); + LoadImage(std::string(iName)); // A part of image per line of text. for ( iCount=0 ; iCount(iCount/iLines); m_image[iIndex].height = 1.0f/iLines; m_image[iIndex].width = iWidth*0.75f; @@ -1888,7 +1870,7 @@ bool CEdit::ReadText(const char *filename, int addSize) // Writes all the text in a file. -bool CEdit::WriteText(const char *filename) +bool CEdit::WriteText(std::string filename) { FILE* file; char buffer[1000+20]; @@ -1896,7 +1878,7 @@ bool CEdit::WriteText(const char *filename) float iDim; if ( filename[0] == 0 ) return false; - file = fopen(filename, "wb"); + file = fopen(filename.c_str(), "wb"); if ( file == NULL ) return false; if ( m_bAutoIndent ) diff --git a/src/ui/edit.h b/src/ui/edit.h index 8f46445..72423fa 100644 --- a/src/ui/edit.h +++ b/src/ui/edit.h @@ -35,7 +35,12 @@ #include "common/restext.h" #include +#include +#include +#include + +namespace fs = boost::filesystem; namespace Ui { @@ -84,7 +89,7 @@ enum OperUndo struct ImageLine { //! name of the image (without diagram \) - char name[40]; + std::string name; //! vertical offset (v texture) float offset; //! height of the part (dv texture) @@ -96,15 +101,15 @@ struct ImageLine struct HyperLink { //! text file name (without help \) - char name[40]; + std::string name; //! name of the marker - char marker[20]; + std::string marker; }; struct HyperMarker { //! name of the marker - char name[20]; + std::string name; //! position in the text int pos; }; @@ -112,7 +117,7 @@ struct HyperMarker struct HyperHistory { //! full file name text - char filename[50]; + std::string filename; //! rank of the first displayed line int firstLine; }; @@ -140,8 +145,8 @@ public: char* GetText(); int GetTextLength(); - bool ReadText(const char *filename, int addSize=0); - bool WriteText(const char *filename); + bool ReadText(std::string filename, int addSize=0); + bool WriteText(std::string filename); void SetMaxChar(int max); int GetMaxChar(); @@ -183,7 +188,7 @@ public: bool Undo(); void HyperFlush(); - void HyperHome(const char *filename); + void HyperHome(std::string filename); bool HyperTest(EventType event); bool HyperGo(EventType event); @@ -202,15 +207,15 @@ protected: int MouseDetect(Math::Point mouse); void MoveAdjust(); - void HyperJump(const char *name, const char *marker); - bool HyperAdd(const char *filename, int firstLine); + void HyperJump(std::string name, std::string marker); + bool HyperAdd(std::string filename, int firstLine); - void DrawImage(Math::Point pos, const char *name, float width, float offset, float height, int nbLine); + void DrawImage(Math::Point pos, std::string name, float width, float offset, float height, int nbLine); void DrawBack(Math::Point pos, Math::Point dim); void DrawPart(Math::Point pos, Math::Point dim, int icon); void FreeImage(); - void LoadImage(const char *name); + void LoadImage(std::string name); void Scroll(int pos, bool bAdjustCursor); void Scroll(); void MoveChar(int move, bool bWord, bool bSelect); diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index a0b0e06..51d2dda 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -3559,11 +3559,11 @@ void CMainDialog::SetUserDir(char *base, int rank) if ( strcmp(base, "user") == 0 && rank >= 100 ) { dir = m_userDir + "/" + m_userList.at(rank/100-1); - UserDir(true, dir.c_str()); + GetProfile().SetUserDir(dir); } else { - UserDir(false, ""); + GetProfile().SetUserDir(""); } } @@ -4258,7 +4258,6 @@ bool CMainDialog::IsIOReadScene() FILE* file; std::string filename; - //TODO: Change this to point user dir acocrding to operating system filename = m_savegameDir + "/" + m_main->GetGamerName() + "/" + "save" + m_sceneName[0] + "000/data.sav"; file = fopen(filename.c_str(), "r"); if ( file == NULL ) return false; @@ -4354,7 +4353,7 @@ void CMainDialog::IOReadList() filename = m_savegameDir + "/" + m_main->GetGamerName() + "/save" + m_sceneName[0] + rankStream.str()+ "/data.sav"; // sprintf(filename, "%s\\%s\\save%c%.3d\\data.sav", m_savegameDir, m_main->GetGamerName(), m_sceneName[0], j); - file = fopen(filename.c_str(), "r"); + file = fopen(fs::path(filename).native().c_str(), "r"); if ( file == NULL ) break; while ( fgets(line, 500, file) != NULL ) @@ -5046,8 +5045,8 @@ void CMainDialog::UpdateDisplayDevice() CWindow* pw; CList* pl; char bufDevices[1000]; - char bufModes[5000]; - int i, j, totalDevices, selectDevices, totalModes, selectModes; + //char bufModes[5000]; + int i, j; pw = static_cast(m_interface->SearchControl(EVENT_WINDOW5)); if ( pw == 0 ) return; @@ -5055,7 +5054,7 @@ void CMainDialog::UpdateDisplayDevice() if ( pl == 0 ) return; pl->Flush(); - bufModes[0] = 0; + //bufModes[0] = 0; /* TODO: remove device choice m_engine->EnumDevices(bufDevices, 1000, bufModes, 5000, @@ -5070,10 +5069,10 @@ void CMainDialog::UpdateDisplayDevice() while ( bufDevices[i++] != 0 ); } - pl->SetSelect(selectDevices); + pl->SetSelect(0); pl->ShowSelect(false); - m_setupSelDevice = selectDevices; + m_setupSelDevice = 0; } // Updates the list of modes. @@ -5110,8 +5109,8 @@ void CMainDialog::ChangeDisplay() CWindow* pw; CList* pl; CCheck* pc; - char* device; - char* mode; + //char* device; + //char* mode; bool bFull; pw = static_cast(m_interface->SearchControl(EVENT_WINDOW5)); @@ -5120,12 +5119,12 @@ void CMainDialog::ChangeDisplay() pl = static_cast(pw->SearchControl(EVENT_LIST1)); if ( pl == 0 ) return; m_setupSelDevice = pl->GetSelect(); - device = pl->GetName(m_setupSelDevice); + //device = pl->GetName(m_setupSelDevice); pl = static_cast(pw->SearchControl(EVENT_LIST2)); if ( pl == 0 ) return; m_setupSelMode = pl->GetSelect(); - mode = pl->GetName(m_setupSelMode); + //mode = pl->GetName(m_setupSelMode); pc = static_cast(pw->SearchControl(EVENT_INTERFACE_FULL)); if ( pc == 0 ) return; diff --git a/src/ui/maindialog.h b/src/ui/maindialog.h index be61299..a79b95e 100644 --- a/src/ui/maindialog.h +++ b/src/ui/maindialog.h @@ -23,6 +23,12 @@ #include "object/robotmain.h" +#include +#include + +namespace fs = boost::filesystem; + + class CEventQueue; class CSoundInterface; diff --git a/src/ui/studio.cpp b/src/ui/studio.cpp index bf2ff33..a056026 100644 --- a/src/ui/studio.cpp +++ b/src/ui/studio.cpp @@ -1477,8 +1477,7 @@ void CStudio::UpdateDialogPublic() CCheck* pc; CLabel* pl; char name[100]; - char dir[MAX_FNAME]; - char text[MAX_FNAME+100]; + //char text[MAX_FNAME+100]; pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW9)); if ( pw == nullptr ) return; @@ -1499,9 +1498,7 @@ void CStudio::UpdateDialogPublic() if ( pl != 0 ) { GetResource(RES_TEXT, RT_IO_LIST, name); - SearchDirectory(dir, false); - sprintf(text, name, dir); - pl->SetName(text, false); + pl->SetName(SearchDirectory(false).c_str(), false); } } @@ -1572,21 +1569,22 @@ void CStudio::UpdateDialogList() // Constructs the name of the folder or open/save. // If the folder does not exist, it will be created. -void CStudio::SearchDirectory(char *dir, bool bCreate) +std::string CStudio::SearchDirectory(bool bCreate) { - if ( m_main->GetIOPublic() ) - { - sprintf(dir, "%s\\", m_main->GetPublicDir()); + char dir[MAX_FNAME]; + if ( m_main->GetIOPublic() ) { + sprintf(dir, "%s/", m_main->GetPublicDir()); + } else { + sprintf(dir, "%s/%s/Program/", m_main->GetSavegameDir(), m_main->GetGamerName()); } - else - { - sprintf(dir, "%s\\%s\\Program\\", m_main->GetSavegameDir(), m_main->GetGamerName()); + + fs::path path = fs::path(dir); + + if ( bCreate ) { + fs::create_directory(path); } - if ( bCreate ) - {// TODO -// mkdir(dir,0777); // if does not exist yet! - } + return path.make_preferred().string(); } // Reads a new program. @@ -1612,7 +1610,7 @@ bool CStudio::ReadProgram() { strcat(filename, ".txt"); } - SearchDirectory(dir, true); + strcpy(dir, SearchDirectory(true).c_str()); strcat(dir, filename); pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW3)); @@ -1650,7 +1648,7 @@ bool CStudio::WriteProgram() { strcat(filename, ".txt"); } - SearchDirectory(dir, true); + strcpy(dir, SearchDirectory(true).c_str()); strcat(dir, filename); pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW3)); @@ -1658,7 +1656,7 @@ bool CStudio::WriteProgram() pe = static_cast< CEdit* >(pw->SearchControl(EVENT_STUDIO_EDIT)); if ( pe == nullptr ) return false; - if ( !pe->WriteText(dir) ) return false; + if ( !pe->WriteText(std::string(dir)) ) return false; m_script->SetFilename(filename); return true; diff --git a/src/ui/studio.h b/src/ui/studio.h index 7c2f652..1c14124 100644 --- a/src/ui/studio.h +++ b/src/ui/studio.h @@ -22,6 +22,9 @@ #include "graphics/engine/camera.h" +#include + +namespace fs = boost::filesystem; #include @@ -81,7 +84,7 @@ protected: void UpdateDialogAction(); void UpdateDialogPublic(); void UpdateDialogList(); - void SearchDirectory(char* dir, bool bCreate); + std::string SearchDirectory(bool bCreate); bool ReadProgram(); bool WriteProgram(); -- cgit v1.2.3-1-g7c22 From 0cd64113aaaa97ffb42c3267772a46faf1a18f62 Mon Sep 17 00:00:00 2001 From: erihel Date: Sun, 17 Mar 2013 20:23:57 +0100 Subject: * Implemented CStudio::UpdateDialogList() function for listing saved files --- src/ui/maindialog.cpp | 2 +- src/ui/studio.cpp | 71 ++++++++++++++------------------------------------- 2 files changed, 20 insertions(+), 53 deletions(-) diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index a770a0e..6b930e2 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -4353,7 +4353,7 @@ void CMainDialog::IOReadList() filename = m_savegameDir + "/" + m_main->GetGamerName() + "/save" + m_sceneName[0] + rankStream.str()+ "/data.sav"; // sprintf(filename, "%s\\%s\\save%c%.3d\\data.sav", m_savegameDir, m_main->GetGamerName(), m_sceneName[0], j); - file = fopen(fs::path(filename).native().c_str(), "r"); + file = fopen(fs::path(filename).make_preferred().c_str(), "r"); if ( file == NULL ) break; while ( fgets(line, 500, file) != NULL ) diff --git a/src/ui/studio.cpp b/src/ui/studio.cpp index a056026..d24eb4c 100644 --- a/src/ui/studio.cpp +++ b/src/ui/studio.cpp @@ -1506,64 +1506,31 @@ void CStudio::UpdateDialogPublic() void CStudio::UpdateDialogList() { - // TODO rewrite to multiplatform - /*CWindow* pw; - CList* pl; - long hFile; - struct _finddata_t fileBuffer; - struct _finddata_t* listBuffer; - bool bDo; - char dir[MAX_FNAME]; - char temp[MAX_FNAME]; - int nbFilenames, i; - - pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW9); + CWindow* pw; + CList* pl; + fs::path path; + int i = 0; + char time[100]; + char temp[100]; + + pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW9)); if ( pw == nullptr ) return; - pl = static_cast< CList* >(pw->SearchControl(EVENT_DIALOG_LIST); - if ( pl == 0 ) return; + pl = static_cast< CList* >(pw->SearchControl(EVENT_DIALOG_LIST)); + if ( pl == nullptr ) return; pl->Flush(); - nbFilenames = 0; - listBuffer = (_finddata_t*)malloc(sizeof(_finddata_t)*1000); - - SearchDirectory(dir, false); - strcat(dir, "*"); // list all - hFile = _findfirst(dir, &fileBuffer); - if ( hFile != -1 ) - { - do - { - if ( (fileBuffer.attrib & _A_SUBDIR) == 0 ) - { - listBuffer[nbFilenames++] = fileBuffer; - } - } - while ( _findnext(hFile, &fileBuffer) == 0 && nbFilenames < 1000 ); - } - do // sorts all names: - { - bDo = false; - for ( i=0 ; i 0 ) - { - fileBuffer = listBuffer[i]; // exchange i and i +1 - listBuffer[i] = listBuffer[i+1]; - listBuffer[i+1] = fileBuffer; - bDo = true; + path = fs::path(SearchDirectory(false)); + fs::directory_iterator end_iter; + if ( fs::exists(path) && fs::is_directory(path) ) { + for( fs::directory_iterator file(path); file != end_iter; file++) { + if (fs::is_regular_file(file->status()) ) { + TimeToAscii(fs::last_write_time(file->path()), time); + sprintf(temp, "%s\t%lu \t%s", file->path().filename().c_str(), fs::file_size(file->path()), time); + + pl->SetName(i++, temp); } } } - while ( bDo ); - - for ( i=0 ; iSetName(i, temp); - } - - free(listBuffer);*/ } // Constructs the name of the folder or open/save. -- cgit v1.2.3-1-g7c22 From 21de71f871bc5add11235de2c86b9f08237591b7 Mon Sep 17 00:00:00 2001 From: erihel Date: Sun, 17 Mar 2013 20:40:54 +0100 Subject: * Fixed app stub in edit test --- test/unit/ui/CMakeLists.txt | 1 + test/unit/ui/stubs/app_stub.cpp | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/test/unit/ui/CMakeLists.txt b/test/unit/ui/CMakeLists.txt index 916a73b..f5945dc 100644 --- a/test/unit/ui/CMakeLists.txt +++ b/test/unit/ui/CMakeLists.txt @@ -11,6 +11,7 @@ add_executable(edit_test ${SRC_DIR}/common/event.cpp ${SRC_DIR}/common/logger.cpp ${SRC_DIR}/common/misc.cpp +${SRC_DIR}/common/profile.cpp ${SRC_DIR}/common/iman.cpp ${SRC_DIR}/common/stringutils.cpp ${SRC_DIR}/graphics/engine/text.cpp diff --git a/test/unit/ui/stubs/app_stub.cpp b/test/unit/ui/stubs/app_stub.cpp index 094806f..3df7d42 100644 --- a/test/unit/ui/stubs/app_stub.cpp +++ b/test/unit/ui/stubs/app_stub.cpp @@ -36,3 +36,7 @@ CEventQueue* CApplication::GetEventQueue() return nullptr; } +std::string CApplication::GetDataDirPath() +{ + return ""; +} -- cgit v1.2.3-1-g7c22 From 4abcaae0f718ab861fcde194250b7ffe3bf1c521 Mon Sep 17 00:00:00 2001 From: erihel Date: Sun, 17 Mar 2013 23:16:26 +0100 Subject: * Changes std::stoi to atoi as gcc does not support it on windows platform --- src/ui/edit.cpp | 8 +------- src/ui/edit.h | 1 + 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/ui/edit.cpp b/src/ui/edit.cpp index a96d231..5ae7162 100644 --- a/src/ui/edit.cpp +++ b/src/ui/edit.cpp @@ -1408,13 +1408,7 @@ int GetValueParam(std::string cmd, int rank) int return_value = 0; if (results.size() > static_cast(rank)) { - try { - return_value = std::stoi(results.at(rank)); - } catch (std::invalid_argument &e) { - GetLogger()->Error("Exception std::invalid_argument caught in GetValueParam function"); - } catch (std::out_of_range &e) { - GetLogger()->Error("Exception std::out_of_range caught in GetValueParam function"); - } + return_value = atoi(results.at(rank).c_str()); } return return_value; diff --git a/src/ui/edit.h b/src/ui/edit.h index 72423fa..8b84fcd 100644 --- a/src/ui/edit.h +++ b/src/ui/edit.h @@ -36,6 +36,7 @@ #include #include +#include #include #include -- cgit v1.2.3-1-g7c22 From 025bedecfb2c264b1f3d6a04de72160001173cc1 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Tue, 19 Mar 2013 23:07:39 +0100 Subject: Refactored platform-specific code Moved functions from .h to .cpp files --- src/CMakeLists.txt | 10 +++ src/app/system_linux.cpp | 79 +++++++++++++++++++++++ src/app/system_linux.h | 71 ++------------------- src/app/system_other.cpp | 122 ++++++++++++++++++++++++++++++++++++ src/app/system_other.h | 114 ++------------------------------- src/app/system_windows.cpp | 98 +++++++++++++++++++++++++++++ src/app/system_windows.h | 95 +++------------------------- test/envs/opengl/CMakeLists.txt | 11 ++++ test/unit/CMakeLists.txt | 22 +++++++ test/unit/app/system_linux_test.cpp | 51 +++++++++++++++ 10 files changed, 410 insertions(+), 263 deletions(-) create mode 100644 src/app/system_linux.cpp create mode 100644 src/app/system_other.cpp create mode 100644 src/app/system_windows.cpp create mode 100644 test/unit/app/system_linux_test.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e6b3acd..cc181f2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -55,11 +55,21 @@ if (${OPENAL_SOUND}) ) endif() +# Platform-dependent implementation of system.h +if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") + set(SYSTEM_CPP_MODULE "system_windows.cpp") +elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + set(SYSTEM_CPP_MODULE "system_linux.cpp") +else() + set(SYSTEM_CPP_MODULE "system_other.cpp") +endif() + # Source files set(SOURCES app/app.cpp app/main.cpp app/system.cpp +app/${SYSTEM_CPP_MODULE} common/event.cpp common/image.cpp common/iman.cpp diff --git a/src/app/system_linux.cpp b/src/app/system_linux.cpp new file mode 100644 index 0000000..c6b6a6e --- /dev/null +++ b/src/app/system_linux.cpp @@ -0,0 +1,79 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch +// * Copyright (C) 2012, Polish Portal of Colobot (PPC) +// * +// * This program is free software: you can redistribute it and/or modify +// * it under the terms of the GNU General Public License as published by +// * the Free Software Foundation, either version 3 of the License, or +// * (at your option) any later version. +// * +// * This program is distributed in the hope that it will be useful, +// * but WITHOUT ANY WARRANTY; without even the implied warranty of +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// * GNU General Public License for more details. +// * +// * You should have received a copy of the GNU General Public License +// * along with this program. If not, see http://www.gnu.org/licenses/. + +#include "app/system_linux.h" + +#include + + +SystemDialogResult SystemDialog_Linux(SystemDialogType type, const std::string& title, const std::string& message) +{ + std::string options = ""; + switch (type) + { + case SDT_INFO: + default: + options = "--info"; + break; + case SDT_WARNING: + options = "--warning"; + break; + case SDT_ERROR: + options = "--error"; + break; + case SDT_YES_NO: + options = "--question --ok-label=\"Yes\" --cancel-label=\"No\""; + break; + case SDT_OK_CANCEL: + options = "--question --ok-label=\"OK\" --cancel-label=\"Cancel\""; + break; + } + + std::string command = "zenity " + options + " --text=\"" + message + "\" --title=\"" + title + "\""; + int code = system(command.c_str()); + + SystemDialogResult result = SDR_OK; + switch (type) + { + case SDT_YES_NO: + result = code ? SDR_NO : SDR_YES; + break; + case SDT_OK_CANCEL: + result = code ? SDR_CANCEL : SDR_OK; + break; + default: + break; + } + + return result; +} + +void GetCurrentTimeStamp_Linux(SystemTimeStamp *stamp) +{ + clock_gettime(CLOCK_MONOTONIC, &stamp->clockTime); +} + +long long GetTimeStampExactResolution_Linux() +{ + return 1ll; +} + +long long TimeStampExactDiff_Linux(SystemTimeStamp *before, SystemTimeStamp *after) +{ + return (after->clockTime.tv_nsec - before->clockTime.tv_nsec) + + (after->clockTime.tv_sec - before->clockTime.tv_sec) * 1000000000ll; +} diff --git a/src/app/system_linux.h b/src/app/system_linux.h index 69893de..bc07c31 100644 --- a/src/app/system_linux.h +++ b/src/app/system_linux.h @@ -20,20 +20,11 @@ * \brief Linux-specific implementation of system functions */ -/* NOTE: code is contained in this header; - * there is no separate .cpp module for simplicity */ +#include "app/system.h" #include -#include -#include -SystemDialogResult SystemDialog_Linux(SystemDialogType type, const std::string& title, const std::string& message); - -void GetCurrentTimeStamp_Linux(SystemTimeStamp *stamp); -long long GetTimeStampExactResolution_Linux(); -long long TimeStampExactDiff_Linux(SystemTimeStamp *before, SystemTimeStamp *after); - struct SystemTimeStamp { timespec clockTime; @@ -45,60 +36,8 @@ struct SystemTimeStamp }; -SystemDialogResult SystemDialog_Linux(SystemDialogType type, const std::string& title, const std::string& message) -{ - std::string options = ""; - switch (type) - { - case SDT_INFO: - default: - options = "--info"; - break; - case SDT_WARNING: - options = "--warning"; - break; - case SDT_ERROR: - options = "--error"; - break; - case SDT_YES_NO: - options = "--question --ok-label=\"Yes\" --cancel-label=\"No\""; - break; - case SDT_OK_CANCEL: - options = "--question --ok-label=\"OK\" --cancel-label=\"Cancel\""; - break; - } - - std::string command = "zenity " + options + " --text=\"" + message + "\" --title=\"" + title + "\""; - int code = system(command.c_str()); - - SystemDialogResult result = SDR_OK; - switch (type) - { - case SDT_YES_NO: - result = code ? SDR_NO : SDR_YES; - break; - case SDT_OK_CANCEL: - result = code ? SDR_CANCEL : SDR_OK; - break; - default: - break; - } - - return result; -} - -void GetCurrentTimeStamp_Linux(SystemTimeStamp *stamp) -{ - clock_gettime(CLOCK_MONOTONIC, &stamp->clockTime); -} - -long long GetTimeStampExactResolution_Linux() -{ - return 1ll; -} +SystemDialogResult SystemDialog_Linux(SystemDialogType type, const std::string& title, const std::string& message); -long long TimeStampExactDiff_Linux(SystemTimeStamp *before, SystemTimeStamp *after) -{ - return (after->clockTime.tv_nsec - before->clockTime.tv_nsec) + - (after->clockTime.tv_sec - before->clockTime.tv_sec) * 1000000000ll; -} +void GetCurrentTimeStamp_Linux(SystemTimeStamp *stamp); +long long GetTimeStampExactResolution_Linux(); +long long TimeStampExactDiff_Linux(SystemTimeStamp *before, SystemTimeStamp *after); diff --git a/src/app/system_other.cpp b/src/app/system_other.cpp new file mode 100644 index 0000000..006bf6d --- /dev/null +++ b/src/app/system_other.cpp @@ -0,0 +1,122 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch +// * Copyright (C) 2012, Polish Portal of Colobot (PPC) +// * +// * This program is free software: you can redistribute it and/or modify +// * it under the terms of the GNU General Public License as published by +// * the Free Software Foundation, either version 3 of the License, or +// * (at your option) any later version. +// * +// * This program is distributed in the hope that it will be useful, +// * but WITHOUT ANY WARRANTY; without even the implied warranty of +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// * GNU General Public License for more details. +// * +// * You should have received a copy of the GNU General Public License +// * along with this program. If not, see http://www.gnu.org/licenses/. + +#include "app/system_other.h" + + +SystemDialogResult SystemDialog_Other(SystemDialogType type, const std::string& title, const std::string& message) +{ + switch (type) + { + case SDT_INFO: + std::cout << "INFO: "; + break; + case SDT_WARNING: + std::cout << "WARNING:"; + break; + case SDT_ERROR: + std::cout << "ERROR: "; + break; + case SDT_YES_NO: + case SDT_OK_CANCEL: + std::cout << "QUESTION: "; + break; + } + + std::cout << message << std::endl; + + std::string line; + + SystemDialogResult result = SDR_OK; + + bool done = false; + while (!done) + { + switch (type) + { + case SDT_INFO: + case SDT_WARNING: + case SDT_ERROR: + std::cout << "Press ENTER to continue"; + break; + + case SDT_YES_NO: + std::cout << "Type 'Y' for Yes or 'N' for No"; + break; + + case SDT_OK_CANCEL: + std::cout << "Type 'O' for OK or 'C' for Cancel"; + break; + } + + std::getline(std::cin, line); + + switch (type) + { + case SDT_INFO: + case SDT_WARNING: + case SDT_ERROR: + done = true; + break; + + case SDT_YES_NO: + if (line == "Y" || line == "y") + { + result = SDR_YES; + done = true; + } + else if (line == "N" || line == "n") + { + result = SDR_NO; + done = true; + } + break; + + case SDT_OK_CANCEL: + if (line == "O" || line == "o") + { + done = true; + result = SDR_OK; + } + else if (line == "C" || line == "c") + { + done = true; + result = SDR_CANCEL; + } + break; + } + } + + return result; +} + + + +void GetCurrentTimeStamp_Other(SystemTimeStamp *stamp) +{ + stamp->sdlTicks = SDL_GetTicks(); +} + +long long GetTimeStampExactResolution_Other() +{ + return 1000000ll; +} + +long long TimeStampExactDiff_Other(SystemTimeStamp *before, SystemTimeStamp *after) +{ + return (after->sdlTicks - before->sdlTicks) * 1000000ll; +} diff --git a/src/app/system_other.h b/src/app/system_other.h index eff0c8a..6fb4b86 100644 --- a/src/app/system_other.h +++ b/src/app/system_other.h @@ -20,20 +20,13 @@ * \brief Fallback code for other systems */ -/* NOTE: code is contained in this header; - * there is no separate .cpp module for simplicity */ +#include "app/system.h" #include #include -SystemDialogResult SystemDialog_Other(SystemDialogType type, const std::string& title, const std::string& message); - -void GetCurrentTimeStamp_Other(SystemTimeStamp *stamp); -long long GetTimeStampExactResolution_Other(); -long long TimeStampExactDiff_Other(SystemTimeStamp *before, SystemTimeStamp *after); - struct SystemTimeStamp { Uint32 sdlTicks; @@ -45,105 +38,8 @@ struct SystemTimeStamp }; -SystemDialogResult SystemDialog_Other(SystemDialogType type, const std::string& title, const std::string& message) -{ - switch (type) - { - case SDT_INFO: - std::cout << "INFO: "; - break; - case SDT_WARNING: - std::cout << "WARNING:"; - break; - case SDT_ERROR: - std::cout << "ERROR: "; - break; - case SDT_YES_NO: - case SDT_OK_CANCEL: - std::cout << "QUESTION: "; - break; - } - - std::cout << message << std::endl; - - std::string line; - - SystemDialogResult result = SDR_OK; - - bool done = false; - while (!done) - { - switch (type) - { - case SDT_INFO: - case SDT_WARNING: - case SDT_ERROR: - std::cout << "Press ENTER to continue"; - break; - - case SDT_YES_NO: - std::cout << "Type 'Y' for Yes or 'N' for No"; - break; - - case SDT_OK_CANCEL: - std::cout << "Type 'O' for OK or 'C' for Cancel"; - break; - } - - std::getline(std::cin, line); - - switch (type) - { - case SDT_INFO: - case SDT_WARNING: - case SDT_ERROR: - done = true; - break; - - case SDT_YES_NO: - if (line == "Y" || line == "y") - { - result = SDR_YES; - done = true; - } - else if (line == "N" || line == "n") - { - result = SDR_NO; - done = true; - } - break; - - case SDT_OK_CANCEL: - if (line == "O" || line == "o") - { - done = true; - result = SDR_OK; - } - else if (line == "C" || line == "c") - { - done = true; - result = SDR_CANCEL; - } - break; - } - } - - return result; -} - - - -void GetCurrentTimeStamp_Other(SystemTimeStamp *stamp) -{ - stamp->sdlTicks = SDL_GetTicks(); -} - -long long GetTimeStampExactResolution_Other() -{ - return 1000000ll; -} +SystemDialogResult SystemDialog_Other(SystemDialogType type, const std::string& title, const std::string& message); -long long TimeStampExactDiff_Other(SystemTimeStamp *before, SystemTimeStamp *after) -{ - return (after->sdlTicks - before->sdlTicks) * 1000000ll; -} +void GetCurrentTimeStamp_Other(SystemTimeStamp *stamp); +long long GetTimeStampExactResolution_Other(); +long long TimeStampExactDiff_Other(SystemTimeStamp *before, SystemTimeStamp *after); diff --git a/src/app/system_windows.cpp b/src/app/system_windows.cpp new file mode 100644 index 0000000..34fa57e --- /dev/null +++ b/src/app/system_windows.cpp @@ -0,0 +1,98 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch +// * Copyright (C) 2012, Polish Portal of Colobot (PPC) +// * +// * This program is free software: you can redistribute it and/or modify +// * it under the terms of the GNU General Public License as published by +// * the Free Software Foundation, either version 3 of the License, or +// * (at your option) any later version. +// * +// * This program is distributed in the hope that it will be useful, +// * but WITHOUT ANY WARRANTY; without even the implied warranty of +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// * GNU General Public License for more details. +// * +// * You should have received a copy of the GNU General Public License +// * along with this program. If not, see http://www.gnu.org/licenses/. + +#include "app/system_windows.h" + + +// Convert a wide Unicode string to an UTF8 string +std::string UTF8_Encode_Windows(const std::wstring &wstr) +{ + int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], static_cast(wstr.size()), NULL, 0, NULL, NULL); + std::string strTo(size_needed, 0); + WideCharToMultiByte(CP_UTF8, 0, &wstr[0], static_cast(wstr.size()), &strTo[0], size_needed, NULL, NULL); + return strTo; +} + +// Convert an UTF8 string to a wide Unicode String +std::wstring UTF8_Decode_Windows(const std::string &str) +{ + int size_needed = MultiByteToWideChar(CP_UTF8, 0, &str[0], static_cast(str.size()), NULL, 0); + std::wstring wstrTo(size_needed, 0); + MultiByteToWideChar(CP_UTF8, 0, &str[0], static_cast(str.size()), &wstrTo[0], size_needed); + return wstrTo; +} + +SystemDialogResult SystemDialog_Windows(SystemDialogType type, const std::string& title, const std::string& message) +{ + unsigned int windowsType = 0; + std::wstring windowsMessage = UTF8_Decode_Windows(message); + std::wstring windowsTitle = UTF8_Decode_Windows(title); + + switch (type) + { + case SDT_INFO: + default: + windowsType = MB_ICONINFORMATION|MB_OK; + break; + case SDT_WARNING: + windowsType = MB_ICONWARNING|MB_OK; + break; + case SDT_ERROR: + windowsType = MB_ICONERROR|MB_OK; + break; + case SDT_YES_NO: + windowsType = MB_ICONQUESTION|MB_YESNO; + break; + case SDT_OK_CANCEL: + windowsType = MB_ICONWARNING|MB_OKCANCEL; + break; + } + + switch (MessageBoxW(NULL, windowsMessage.c_str(), windowsTitle.c_str(), windowsType)) + { + case IDOK: + return SDR_OK; + case IDCANCEL: + return SDR_CANCEL; + case IDYES: + return SDR_YES; + case IDNO: + return SDR_NO; + default: + break; + } + + return SDR_OK; +} + + +void GetCurrentTimeStamp_Windows(SystemTimeStamp *stamp) +{ + GetSystemTimeAsFileTime(&stamp->fileTime); +} + +long long GetTimeStampExactResolution_Windows() +{ + return 100ll; +} + +long long TimeStampExactDiff_Windows(SystemTimeStamp *before, SystemTimeStamp *after) +{ + long long tH = (1ll << 32) * (after->fileTime.dwHighDateTime - before->fileTime.dwHighDateTime); + long long tL = after->fileTime.dwLowDateTime - before->fileTime.dwLowDateTime; + return (tH + tL) * 100ll; +} diff --git a/src/app/system_windows.h b/src/app/system_windows.h index c9743e6..804d064 100644 --- a/src/app/system_windows.h +++ b/src/app/system_windows.h @@ -20,20 +20,11 @@ * \brief Windows-specific implementation of system functions */ -/* NOTE: code is contained in this header; - * there is no separate .cpp module for simplicity */ +#include "app/system.h" #include -std::string UTF8_Encode_Windows(const std::wstring &wstr); -std::wstring UTF8_Decode_Windows(const std::string &str); -SystemDialogResult SystemDialog_Windows(SystemDialogType type, const std::string& title, const std::string& message); - -void GetCurrentTimeStamp_Windows(SystemTimeStamp *stamp); -long long GetTimeStampExactResolution_Windows(); -long long TimeStampExactDiff_Windows(SystemTimeStamp *before, SystemTimeStamp *after); - struct SystemTimeStamp { FILETIME fileTime; @@ -44,82 +35,10 @@ struct SystemTimeStamp } }; +std::string UTF8_Encode_Windows(const std::wstring &wstr); +std::wstring UTF8_Decode_Windows(const std::string &str); +SystemDialogResult SystemDialog_Windows(SystemDialogType type, const std::string& title, const std::string& message); -// Convert a wide Unicode string to an UTF8 string -std::string UTF8_Encode_Windows(const std::wstring &wstr) -{ - int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], static_cast(wstr.size()), NULL, 0, NULL, NULL); - std::string strTo(size_needed, 0); - WideCharToMultiByte(CP_UTF8, 0, &wstr[0], static_cast(wstr.size()), &strTo[0], size_needed, NULL, NULL); - return strTo; -} - -// Convert an UTF8 string to a wide Unicode String -std::wstring UTF8_Decode_Windows(const std::string &str) -{ - int size_needed = MultiByteToWideChar(CP_UTF8, 0, &str[0], static_cast(str.size()), NULL, 0); - std::wstring wstrTo(size_needed, 0); - MultiByteToWideChar(CP_UTF8, 0, &str[0], static_cast(str.size()), &wstrTo[0], size_needed); - return wstrTo; -} - -SystemDialogResult SystemDialog_Windows(SystemDialogType type, const std::string& title, const std::string& message) -{ - unsigned int windowsType = 0; - std::wstring windowsMessage = UTF8_Decode_Windows(message); - std::wstring windowsTitle = UTF8_Decode_Windows(title); - - switch (type) - { - case SDT_INFO: - default: - windowsType = MB_ICONINFORMATION|MB_OK; - break; - case SDT_WARNING: - windowsType = MB_ICONWARNING|MB_OK; - break; - case SDT_ERROR: - windowsType = MB_ICONERROR|MB_OK; - break; - case SDT_YES_NO: - windowsType = MB_ICONQUESTION|MB_YESNO; - break; - case SDT_OK_CANCEL: - windowsType = MB_ICONWARNING|MB_OKCANCEL; - break; - } - - switch (MessageBoxW(NULL, windowsMessage.c_str(), windowsTitle.c_str(), windowsType)) - { - case IDOK: - return SDR_OK; - case IDCANCEL: - return SDR_CANCEL; - case IDYES: - return SDR_YES; - case IDNO: - return SDR_NO; - default: - break; - } - - return SDR_OK; -} - - -void GetCurrentTimeStamp_Windows(SystemTimeStamp *stamp) -{ - GetSystemTimeAsFileTime(&stamp->fileTime); -} - -long long GetTimeStampExactResolution_Windows() -{ - return 100ll; -} - -long long TimeStampExactDiff_Windows(SystemTimeStamp *before, SystemTimeStamp *after) -{ - long long tH = (1ll << 32) * (after->fileTime.dwHighDateTime - before->fileTime.dwHighDateTime); - long long tL = after->fileTime.dwLowDateTime - before->fileTime.dwLowDateTime; - return (tH + tL) * 100ll; -} +void GetCurrentTimeStamp_Windows(SystemTimeStamp *stamp); +long long GetTimeStampExactResolution_Windows(); +long long TimeStampExactDiff_Windows(SystemTimeStamp *before, SystemTimeStamp *after); diff --git a/test/envs/opengl/CMakeLists.txt b/test/envs/opengl/CMakeLists.txt index 3de5466..d6c3a37 100644 --- a/test/envs/opengl/CMakeLists.txt +++ b/test/envs/opengl/CMakeLists.txt @@ -2,6 +2,14 @@ set(SRC_DIR ${colobot_SOURCE_DIR}/src) configure_file(${SRC_DIR}/common/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/common/config.h) +# Platform-dependent implementation of system.h +if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") + set(SYSTEM_CPP_MODULE "system_windows.cpp") +elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + set(SYSTEM_CPP_MODULE "system_linux.cpp") +else() + set(SYSTEM_CPP_MODULE "system_other.cpp") +endif() set(TEXTURE_SOURCES ${SRC_DIR}/graphics/opengl/gldevice.cpp @@ -17,6 +25,7 @@ ${SRC_DIR}/common/logger.cpp ${SRC_DIR}/common/image.cpp ${SRC_DIR}/common/stringutils.cpp ${SRC_DIR}/app/system.cpp +${SRC_DIR}/app/${SYSTEM_CPP_MODULE} model_test.cpp ) @@ -25,6 +34,7 @@ ${SRC_DIR}/graphics/opengl/gldevice.cpp ${SRC_DIR}/common/logger.cpp ${SRC_DIR}/common/image.cpp ${SRC_DIR}/app/system.cpp +${SRC_DIR}/app/${SYSTEM_CPP_MODULE} transform_test.cpp ) @@ -33,6 +43,7 @@ ${SRC_DIR}/graphics/opengl/gldevice.cpp ${SRC_DIR}/common/logger.cpp ${SRC_DIR}/common/image.cpp ${SRC_DIR}/app/system.cpp +${SRC_DIR}/app/${SYSTEM_CPP_MODULE} light_test.cpp ) diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index 575f5c0..34027b8 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -15,10 +15,20 @@ endif() # Configure file configure_file(${SRC_DIR}/common/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/common/config.h) +# Platform-dependent implementation of system.h +if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") + set(SYSTEM_CPP_MODULE "system_windows.cpp") +elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + set(SYSTEM_CPP_MODULE "system_linux.cpp") +else() + set(SYSTEM_CPP_MODULE "system_other.cpp") +endif() + # Code sources set(COLOBOT_SOURCES ${SRC_DIR}/app/app.cpp ${SRC_DIR}/app/system.cpp +${SRC_DIR}/app/${SYSTEM_CPP_MODULE} ${SRC_DIR}/common/event.cpp ${SRC_DIR}/common/image.cpp ${SRC_DIR}/common/iman.cpp @@ -159,12 +169,24 @@ if (${OPENAL_SOUND}) endif() endif() + +# Platform-dependent tests +if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") + #TODO: set(PLATFORM_TESTS app/system_windows_test.cpp) +elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + set(PLATFORM_TESTS app/system_linux_test.cpp) +else() + #TODO: set(PLATFORM_TESTS app/system_other_test.cpp) +endif() + +# Tests set(UT_SOURCES main.cpp graphics/engine/lightman_test.cpp math/geometry_test.cpp math/matrix_test.cpp math/vector_test.cpp +${PLATFORM_TESTS} ) include_directories( diff --git a/test/unit/app/system_linux_test.cpp b/test/unit/app/system_linux_test.cpp new file mode 100644 index 0000000..fe89399 --- /dev/null +++ b/test/unit/app/system_linux_test.cpp @@ -0,0 +1,51 @@ +#include "app/system.h" +#include "app/system_linux.h" + +#include + +TEST(SystemLinuxTest, TimeStampDiff) +{ + const long long SEC = 1000000000; + + SystemTimeStamp before, after; + + before.clockTime.tv_sec = 1; + before.clockTime.tv_nsec = 100; + + after.clockTime.tv_sec = 1; + after.clockTime.tv_nsec = 900; + + long long tDiff = TimeStampExactDiff_Linux(&before, &after); + EXPECT_EQ( 800, tDiff); + + tDiff = TimeStampExactDiff_Linux(&after, &before); + EXPECT_EQ(-800, tDiff); + + // ------- + + before.clockTime.tv_sec = 2; + before.clockTime.tv_nsec = 200; + + after.clockTime.tv_sec = 3; + after.clockTime.tv_nsec = 500; + + tDiff = TimeStampExactDiff_Linux(&before, &after); + EXPECT_EQ( SEC + 300, tDiff); + + tDiff = TimeStampExactDiff_Linux(&after, &before); + EXPECT_EQ(-SEC - 300, tDiff); + + // ------- + + before.clockTime.tv_sec = 3; + before.clockTime.tv_nsec = 200; + + after.clockTime.tv_sec = 4; + after.clockTime.tv_nsec = 100; + + tDiff = TimeStampExactDiff_Linux(&before, &after); + EXPECT_EQ( SEC - 100, tDiff); + + tDiff = TimeStampExactDiff_Linux(&after, &before); + EXPECT_EQ(-SEC + 100, tDiff); +} -- cgit v1.2.3-1-g7c22 From 3bb83e5595892f7feb23248b88285f9ef9ad4786 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Tue, 19 Mar 2013 23:08:39 +0100 Subject: Changed Linux time function With CLOCK_MONOTONIC_RAW, the timer should never go back in time. --- src/app/system_linux.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/system_linux.cpp b/src/app/system_linux.cpp index c6b6a6e..cd785f8 100644 --- a/src/app/system_linux.cpp +++ b/src/app/system_linux.cpp @@ -64,7 +64,7 @@ SystemDialogResult SystemDialog_Linux(SystemDialogType type, const std::string& void GetCurrentTimeStamp_Linux(SystemTimeStamp *stamp) { - clock_gettime(CLOCK_MONOTONIC, &stamp->clockTime); + clock_gettime(CLOCK_MONOTONIC_RAW, &stamp->clockTime); } long long GetTimeStampExactResolution_Linux() -- cgit v1.2.3-1-g7c22 From 64be7a5df60bdf444d31eb2cc4945929a4c4a695 Mon Sep 17 00:00:00 2001 From: erihel Date: Wed, 20 Mar 2013 20:27:19 +0100 Subject: * Fix for mxe with boost path --- src/ui/maindialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 6b930e2..f4bc75c 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -4353,7 +4353,7 @@ void CMainDialog::IOReadList() filename = m_savegameDir + "/" + m_main->GetGamerName() + "/save" + m_sceneName[0] + rankStream.str()+ "/data.sav"; // sprintf(filename, "%s\\%s\\save%c%.3d\\data.sav", m_savegameDir, m_main->GetGamerName(), m_sceneName[0], j); - file = fopen(fs::path(filename).make_preferred().c_str(), "r"); + file = fopen(fs::path(filename).make_preferred().string().c_str(), "r"); if ( file == NULL ) break; while ( fgets(line, 500, file) != NULL ) -- cgit v1.2.3-1-g7c22 From 1406464f0ce0b804298e2ee034bdd8bc7856e0dc Mon Sep 17 00:00:00 2001 From: erihel Date: Wed, 20 Mar 2013 21:50:44 +0100 Subject: * Changed Set/Get HilateCap to Set/Get HighlightCap * Changes ReadText in CEdit to fix problem with SatCom links * Filenames when loading/saving scripts should be fixed on mxe --- src/object/robotmain.cpp | 2 +- src/ui/displayinfo.cpp | 4 ++-- src/ui/edit.cpp | 18 +++++++++++++----- src/ui/edit.h | 4 ++-- src/ui/maindialog.cpp | 8 ++++---- src/ui/studio.cpp | 6 +++--- 6 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 635fc4e..2554ce4 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -1186,7 +1186,7 @@ void CRobotMain::ChangePhase(Phase phase) pe->SetGenericMode(true); pe->SetFontType(Gfx::FONT_COLOBOT); pe->SetEditCap(false); - pe->SetHiliteCap(false); + pe->SetHighlightCap(false); pe->ReadText(std::string("help/win.txt")); } else diff --git a/src/ui/displayinfo.cpp b/src/ui/displayinfo.cpp index 5c41f65..974cd60 100644 --- a/src/ui/displayinfo.cpp +++ b/src/ui/displayinfo.cpp @@ -381,7 +381,7 @@ void CDisplayInfo::StartDisplayInfo(std::string filename, int index, bool bSoluc edit->ReadText(filename.c_str()); edit->HyperHome(filename.c_str()); edit->SetEditCap(false); // just to see! - edit->SetHiliteCap(false); + edit->SetHighlightCap(false); edit->SetFocus(true); ViewDisplayInfo(); @@ -785,7 +785,7 @@ void CDisplayInfo::UpdateIndexButton() if ( edit != 0 ) { //? edit->SetHiliteCap(m_index==SATCOM_LOADING); - edit->SetHiliteCap(true); + edit->SetHighlightCap(true); } UpdateCopyButton(); diff --git a/src/ui/edit.cpp b/src/ui/edit.cpp index 5ae7162..e4bb3a3 100644 --- a/src/ui/edit.cpp +++ b/src/ui/edit.cpp @@ -786,8 +786,7 @@ void CEdit::HyperJump(std::string name, std::string marker) if ( name[0] == '%' ) { filename = GetProfile().GetUserBasedPath(name, "") + ".txt"; } else { - std::string path = CApplication::GetInstancePointer()->GetDataDirPath() + "/help/" + name + ".txt"; - filename = fs::path(path).generic_string(); + filename = "/help/" + name + ".txt"; } if ( ReadText(filename) ) @@ -1449,7 +1448,16 @@ bool CEdit::ReadText(std::string filename, int addSize) bool bInSoluce, bBOL; if ( filename[0] == 0 ) return false; - file = fopen(filename.c_str(), "rb"); + boost::replace_all(filename, "\\", "/"); + + /* This is ugly but doesn't require many changes in code. If file doesn't + exists it's posible filename is absolute not full path */ + std::string path = filename; + if (!fs::exists(path)) { + path = CApplication::GetInstancePointer()->GetDataDirPath() + "/" + filename; + } + + file = fopen(fs::path(path).make_preferred().string().c_str(), "rb"); if ( file == NULL ) return false; fseek(file, 0, SEEK_END); @@ -1974,12 +1982,12 @@ bool CEdit::GetEditCap() // Mode management "hilitable" (that's the franch). -void CEdit::SetHiliteCap(bool bEnable) +void CEdit::SetHighlightCap(bool bEnable) { m_bHilite = bEnable; } -bool CEdit::GetHiliteCap() +bool CEdit::GetHighlightCap() { return m_bHilite; } diff --git a/src/ui/edit.h b/src/ui/edit.h index 8b84fcd..1cfec80 100644 --- a/src/ui/edit.h +++ b/src/ui/edit.h @@ -155,8 +155,8 @@ public: void SetEditCap(bool bMode); bool GetEditCap(); - void SetHiliteCap(bool bEnable); - bool GetHiliteCap(); + void SetHighlightCap(bool bEnable); + bool GetHighlightCap(); void SetInsideScroll(bool bInside); bool GetInsideScroll(); diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index f4bc75c..8b97f4e 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -891,7 +891,7 @@ pb->SetState(STATE_SHADOW); pe->SetState(STATE_SHADOW); pe->SetMaxChar(500); pe->SetEditCap(false); // just to see - pe->SetHiliteCap(false); + pe->SetHighlightCap(false); // Button displays the "soluce": if ( m_phase != PHASE_TRAINER && @@ -1815,7 +1815,7 @@ pos.y -= 0.048f; pe = pw->CreateEdit(pos, ddim, 0, EVENT_EDIT1); pe->SetGenericMode(true); pe->SetEditCap(false); - pe->SetHiliteCap(false); + pe->SetHighlightCap(false); pe->SetFontType(Gfx::FONT_COURIER); pe->SetFontSize(8.0f); pe->ReadText("help/authors.txt"); @@ -1827,7 +1827,7 @@ pos.y -= 0.048f; pe = pw->CreateEdit(pos, ddim, 0, EVENT_EDIT2); pe->SetGenericMode(true); pe->SetEditCap(false); - pe->SetHiliteCap(false); + pe->SetHighlightCap(false); pe->SetFontType(Gfx::FONT_COURIER); pe->SetFontSize(6.5f); pe->ReadText("help/licences.txt"); @@ -1847,7 +1847,7 @@ ddim.y = 150.0f/480.0f; pe = pw->CreateEdit(pos, ddim, 0, EVENT_EDIT1); pe->SetGenericMode(true); pe->SetEditCap(false); - pe->SetHiliteCap(false); + pe->SetHighlightCap(false); pe->SetFontType(Gfx::FONT_COURIER); pe->SetFontSize(8.0f); pe->ReadText("help/authors.txt"); diff --git a/src/ui/studio.cpp b/src/ui/studio.cpp index d24eb4c..da18d83 100644 --- a/src/ui/studio.cpp +++ b/src/ui/studio.cpp @@ -990,13 +990,13 @@ void CStudio::UpdateButtons() { edit->SetIcon(1); // red background edit->SetEditCap(false); // just to see - edit->SetHiliteCap(true); + edit->SetHighlightCap(true); } else { edit->SetIcon(0); // standard background edit->SetEditCap(true); - edit->SetHiliteCap(true); + edit->SetHighlightCap(true); } button = static_cast< CButton* >(pw->SearchControl(EVENT_STUDIO_COMPILE)); @@ -1525,7 +1525,7 @@ void CStudio::UpdateDialogList() for( fs::directory_iterator file(path); file != end_iter; file++) { if (fs::is_regular_file(file->status()) ) { TimeToAscii(fs::last_write_time(file->path()), time); - sprintf(temp, "%s\t%lu \t%s", file->path().filename().c_str(), fs::file_size(file->path()), time); + sprintf(temp, "%s\t%lu \t%s", file->path().filename().string().c_str(), fs::file_size(file->path()), time); pl->SetName(i++, temp); } -- cgit v1.2.3-1-g7c22 From 4a30800cf16d403a7c25d78388e2822aa396ac86 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Fri, 22 Mar 2013 18:19:53 +0100 Subject: Fixes for compiling on MSYS * fixed SDL_main() and putenv() issues * disabled desktop subdir for MSYS * disabled building CBot_console for now --- CMakeLists.txt | 18 +++++++++++++++++- src/CBot/CMakeLists.txt | 5 ++++- src/CMakeLists.txt | 20 ++++++++------------ src/app/app.cpp | 4 ++-- src/app/main.cpp | 7 ++++++- src/app/system_other.h | 2 +- src/common/config.h.cmake | 12 ++++++++++-- src/common/image.cpp | 4 ++-- src/common/key.h | 2 +- src/common/restext.cpp | 2 +- src/desktop/CMakeLists.txt | 2 +- src/graphics/engine/terrain.cpp | 2 +- src/graphics/engine/text.cpp | 4 ++-- src/graphics/opengl/gldevice.cpp | 2 +- src/tools/CMakeLists.txt | 2 ++ test/cbot/CMakeLists.txt | 2 +- test/envs/opengl/light_test.cpp | 12 +++++++++--- test/envs/opengl/model_test.cpp | 12 +++++++++--- test/envs/opengl/texture_test.cpp | 12 +++++++++--- test/envs/opengl/transform_test.cpp | 12 +++++++++--- test/unit/CMakeLists.txt | 33 ++++++++++++++++++++------------- test/unit/common/image_test.cpp | 2 +- 22 files changed, 117 insertions(+), 56 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e25826..60839be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,6 +74,7 @@ set(COLOBOT_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wold-style-cast ${CXX11_FLAGS}" set(COLOBOT_CXX_FLAGS_RELEASE "-O2") set(COLOBOT_CXX_FLAGS_DEBUG "-g -O0") + # Asserts can be enabled/disabled regardless of build type option(ASSERTS "Enable assert()s" ON) @@ -83,6 +84,9 @@ option(TESTS "Enable tests" ON) # CBot can also be a static library option(CBOT_STATIC "Build CBot as static libary" OFF) +# Generate desktop files, manpage, etc. +option(DESKTOP ON) + # Doxygen docs are optional for installation option(INSTALL_DOCS "Install Doxygen-generated documentation" OFF) @@ -90,8 +94,16 @@ option(INSTALL_DOCS "Install Doxygen-generated documentation" OFF) option(OPENAL_SOUND "Build openal sound support" OFF) +# Hacks for MSYS +if (MSYS) + set(COLOBOT_CXX_FLAGS "${COLOBOT_CXX_FLAGS} -U__STRICT_ANSI__") # fixes putenv() + set(USE_SDL_MAIN 1) # fixes SDL_main + set(DESKTOP OFF) # MSYS doesn't have the necessary tools +endif() + + ## -# Required packages +# Searching for packages ## find_package(OpenGL 1.4 REQUIRED) @@ -115,6 +127,10 @@ find_package(GLEW REQUIRED) include("${colobot_SOURCE_DIR}/cmake/FindLibSndFile.cmake") +if (${OPENAL_SOUND}) + find_package(OpenAL REQUIRED) +endif() + ## # Additional settings to use when cross-compiling with MXE (http://mxe.cc/) diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index daf08c6..fecd18e 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -16,5 +16,8 @@ if(${CBOT_STATIC}) add_library(CBot STATIC ${SOURCES}) else() add_library(CBot SHARED ${SOURCES}) - install(TARGETS CBot LIBRARY DESTINATION ${COLOBOT_INSTALL_LIB_DIR}) + install(TARGETS CBot LIBRARY + DESTINATION ${COLOBOT_INSTALL_LIB_DIR} + ARCHIVE DESTINATION ${COLOBOT_INSTALL_LIB_DIR} + RUNTIME DESTINATION ${COLOBOT_INSTALL_BIN_DIR}) endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cc181f2..3d6908d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,22 +12,18 @@ add_subdirectory(tools) add_subdirectory(po) -add_subdirectory(desktop) +if(${DESKTOP}) + add_subdirectory(desktop) +endif() # Optional libraries set(OPTIONAL_LIBS "") +set(OPTIONAL_INCLUDES "") if (${OPENAL_SOUND}) - if (${PLATFORM_WINDOWS}) - set(OPTIONAL_LIBS - OpenAL32 - ) - else() - set(OPTIONAL_LIBS - openal - ) - endif() + set(OPTIONAL_LIBS ${OPENAL_LIBRARY}) + set(OPTIONAL_INCLUDES ${OPENAL_INCLUDE_DIR}) endif() # Additional libraries per platform @@ -196,8 +192,8 @@ ${OPENGL_LIBRARY} ${PNG_LIBRARIES} ${GLEW_LIBRARY} ${Boost_LIBRARIES} -${OPTIONAL_LIBS} ${LIBSNDFILE_LIBRARY} +${OPTIONAL_LIBS} ${PLATFORM_LIBS} ) @@ -217,8 +213,8 @@ ${SDLTTF_INCLUDE_DIR} ${PNG_INCLUDE_DIRS} ${GLEW_INCLUDE_PATH} ${Boost_INCLUDE_DIRS} -${OPTIONAL_INCLUDE_DIRS} ${LIBSNDFILE_INCLUDE_DIR} +${OPTIONAL_INCLUDE_DIRS} ) link_directories(${CMAKE_CURRENT_SOURCE_DIR}/CBot) diff --git a/src/app/app.cpp b/src/app/app.cpp index cb1ac34..e84091b 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -33,8 +33,8 @@ #include -#include -#include +#include +#include #include #include diff --git a/src/app/main.cpp b/src/app/main.cpp index e621065..0622370 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -23,6 +23,7 @@ #include "app/app.h" #include "app/system.h" +#include "common/config.h" #include "common/logger.h" #include "common/misc.h" #include "common/restext.h" @@ -70,7 +71,10 @@ The current layout is the following: //! Entry point to the program -int main(int argc, char *argv[]) +extern "C" +{ + +int SDL_MAIN_FUNC(int argc, char *argv[]) { CLogger logger; // Create the logger @@ -111,3 +115,4 @@ int main(int argc, char *argv[]) return code; } +} // extern "C" diff --git a/src/app/system_other.h b/src/app/system_other.h index 6fb4b86..aee3536 100644 --- a/src/app/system_other.h +++ b/src/app/system_other.h @@ -22,7 +22,7 @@ #include "app/system.h" -#include +#include #include diff --git a/src/common/config.h.cmake b/src/common/config.h.cmake index 1595e09..d5a03b4 100644 --- a/src/common/config.h.cmake +++ b/src/common/config.h.cmake @@ -7,11 +7,19 @@ #cmakedefine GLEW_STATIC +#cmakedefine OPENAL_SOUND + +#cmakedefine USE_SDL_MAIN @USE_SDL_MAIN@ + +#ifdef USE_SDL_MAIN +#define SDL_MAIN_FUNC SDL_main +#else +#define SDL_MAIN_FUNC main +#endif + #define COLOBOT_VERSION "@COLOBOT_VERSION_FULL@" #define COLOBOT_CODENAME "@COLOBOT_VERSION_CODENAME@" #define COLOBOT_FULLNAME "Colobot @COLOBOT_VERSION_CODENAME@" #define COLOBOT_DEFAULT_DATADIR "@COLOBOT_INSTALL_DATA_DIR@" #define COLOBOT_I18N_DIR "@COLOBOT_INSTALL_I18N_DIR@" - -#cmakedefine OPENAL_SOUND diff --git a/src/common/image.cpp b/src/common/image.cpp index be5711d..db14797 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -22,8 +22,8 @@ #include #include -#include -#include +#include +#include #include diff --git a/src/common/key.h b/src/common/key.h index 196f66d..84ee618 100644 --- a/src/common/key.h +++ b/src/common/key.h @@ -22,7 +22,7 @@ #pragma once -#include "SDL/SDL_keysym.h" +#include /* Key definitions are specially defined here so that it is clear in other parts of the code that these are used. It is to avoid having SDL-related enum values or #defines lying around diff --git a/src/common/restext.cpp b/src/common/restext.cpp index 4768aed..a6c33a3 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -30,7 +30,7 @@ #include "object/robotmain.h" #include -#include +#include const char* stringsText[RT_MAX] = { nullptr }; const char* stringsEvent[EVENT_STD_MAX] = { nullptr }; diff --git a/src/desktop/CMakeLists.txt b/src/desktop/CMakeLists.txt index ce4f48d..9a00dd4 100644 --- a/src/desktop/CMakeLists.txt +++ b/src/desktop/CMakeLists.txt @@ -39,7 +39,7 @@ endif() # Create manpage from pod-formatted file find_program(POD2MAN pod2man) -if(POD2MAN) +if(POD2MAN AND (NOT MSYS)) set(COLOBOT_MANPAGE_SECTION 6) macro(podman) diff --git a/src/graphics/engine/terrain.cpp b/src/graphics/engine/terrain.cpp index 8f7ad26..c2a7855 100644 --- a/src/graphics/engine/terrain.cpp +++ b/src/graphics/engine/terrain.cpp @@ -30,7 +30,7 @@ #include -#include +#include // Graphics module namespace diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index 9dea129..308c813 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -26,8 +26,8 @@ #include "math/func.h" -#include -#include +#include +#include // Graphics module namespace diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index beeb85e..df64e34 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -27,7 +27,7 @@ // Using GLEW so only glew.h is needed #include -#include +#include #include diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt index 3653357..0be2bd5 100644 --- a/src/tools/CMakeLists.txt +++ b/src/tools/CMakeLists.txt @@ -7,6 +7,8 @@ convert_model.cpp include_directories(. ..) +include_directories(SYSTEM ${SDL_INCLUDE_DIR}) + add_definitions(-DMODELFILE_NO_ENGINE) add_executable(convert_model ${CONVERT_MODEL_SOURCES}) diff --git a/test/cbot/CMakeLists.txt b/test/cbot/CMakeLists.txt index e864ed5..e087ea5 100644 --- a/test/cbot/CMakeLists.txt +++ b/test/cbot/CMakeLists.txt @@ -1,2 +1,2 @@ # CBot console interpreter -add_subdirectory(CBot_console) +#add_subdirectory(CBot_console) diff --git a/test/envs/opengl/light_test.cpp b/test/envs/opengl/light_test.cpp index b1e0151..d4635cc 100644 --- a/test/envs/opengl/light_test.cpp +++ b/test/envs/opengl/light_test.cpp @@ -1,5 +1,6 @@ #include "app/system.h" +#include "common/config.h" #include "common/logger.h" #include "common/image.h" @@ -7,8 +8,8 @@ #include "math/geometry.h" -#include -#include +#include +#include #include #include @@ -357,7 +358,10 @@ void MouseMove(int x, int y) ROTATION.x = ROTATION_BASE.x + (static_cast (y - MOUSE_POS_BASE.y) / 600.0f) * Math::PI; } -int main(int argc, char *argv[]) +extern "C" +{ + +int SDL_MAIN_FUNC(int argc, char *argv[]) { CLogger logger; @@ -460,3 +464,5 @@ int main(int argc, char *argv[]) return 0; } + +} // extern "C" diff --git a/test/envs/opengl/model_test.cpp b/test/envs/opengl/model_test.cpp index 882b785..168eb32 100644 --- a/test/envs/opengl/model_test.cpp +++ b/test/envs/opengl/model_test.cpp @@ -1,5 +1,6 @@ #include "app/system.h" +#include "common/config.h" #include "common/logger.h" #include "common/image.h" @@ -8,8 +9,8 @@ #include "math/geometry.h" -#include -#include +#include +#include #include #include @@ -257,7 +258,10 @@ void KeyboardUp(SDLKey key) } } -int main(int argc, char *argv[]) +extern "C" +{ + +int SDL_MAIN_FUNC(int argc, char *argv[]) { CLogger logger; @@ -378,3 +382,5 @@ int main(int argc, char *argv[]) return 0; } + +} // extern "C" diff --git a/test/envs/opengl/texture_test.cpp b/test/envs/opengl/texture_test.cpp index b1f352c..5c27b43 100644 --- a/test/envs/opengl/texture_test.cpp +++ b/test/envs/opengl/texture_test.cpp @@ -1,3 +1,4 @@ +#include "common/config.h" #include "common/logger.h" #include "common/image.h" @@ -5,8 +6,8 @@ #include "math/geometry.h" -#include -#include +#include +#include #include @@ -124,7 +125,10 @@ void Render(Gfx::CGLDevice *device) device->EndScene(); } -int main() +extern "C" +{ + +int SDL_MAIN_FUNC(int argc, char *argv[]) { CLogger logger; @@ -192,3 +196,5 @@ int main() return 0; } + +} // extern "C" diff --git a/test/envs/opengl/transform_test.cpp b/test/envs/opengl/transform_test.cpp index 04c73f7..02f9d83 100644 --- a/test/envs/opengl/transform_test.cpp +++ b/test/envs/opengl/transform_test.cpp @@ -1,5 +1,6 @@ #include "app/system.h" +#include "common/config.h" #include "common/logger.h" #include "common/image.h" #include "common/iman.h" @@ -8,8 +9,8 @@ #include "math/geometry.h" -#include -#include +#include +#include #include #include @@ -235,7 +236,10 @@ void MouseMove(int x, int y) ROTATION.x = ROTATION_BASE.x + (static_cast (y - MOUSE_POS_BASE.y) / 600.0f) * Math::PI; } -int main(int argc, char *argv[]) +extern "C" +{ + +int SDL_MAIN_FUNC(int argc, char *argv[]) { CLogger logger; @@ -338,3 +342,5 @@ int main(int argc, char *argv[]) return 0; } + +} // extern "C" diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index 34027b8..f3be01d 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -158,15 +158,8 @@ endif() set(OPTIONAL_LIBS "") if (${OPENAL_SOUND}) - if (${PLATFORM_WINDOWS}) - set(OPTIONAL_LIBS - OpenAL32 - ) - else() - set(OPTIONAL_LIBS - openal - ) - endif() + set(OPTIONAL_LIBS ${OPENAL_LIBRARY}) + set(OPTIONAL_INCLUDES ${OPENAL_INCLUDE_DIR}) endif() @@ -189,14 +182,28 @@ math/vector_test.cpp ${PLATFORM_TESTS} ) +# Local include_directories( -${CMAKE_CURRENT_BINARY_DIR} -${SRC_DIR} -${GTEST_INCLUDE_DIR} -${GMOCK_INCLUDE_DIR} . common math +${SRC_DIR} +${CMAKE_CURRENT_BINARY_DIR} +) + +# System +include_directories( +SYSTEM +${GTEST_INCLUDE_DIR} +${GMOCK_INCLUDE_DIR} +${SDL_INCLUDE_DIR} +${SDLIMAGE_INCLUDE_DIR} +${SDLTTF_INCLUDE_DIR} +${PNG_INCLUDE_DIRS} +${GLEW_INCLUDE_PATH} +${Boost_INCLUDE_DIRS} +${OPTIONAL_INCLUDE_DIRS} +${LIBSNDFILE_INCLUDE_DIR} ) set(LIBS diff --git a/test/unit/common/image_test.cpp b/test/unit/common/image_test.cpp index 2a8d5e4..2b20a17 100644 --- a/test/unit/common/image_test.cpp +++ b/test/unit/common/image_test.cpp @@ -1,6 +1,6 @@ #include "common/image.h" -#include +#include #include /* For now, just a simple test: loading a file from image -- cgit v1.2.3-1-g7c22 From 87bc927d8757d6b9d7633260ff12580dcd48b3a4 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Fri, 22 Mar 2013 22:24:35 +0100 Subject: Updated README files, optional libsndfile * updated readme files * moved sndfile to optional * changed install paths on Windows --- CMakeLists.txt | 21 +++++++---- HOWTO-MXE.txt | 68 --------------------------------- HOWTO.txt | 113 ------------------------------------------------------- INSTALL-MXE.txt | 71 +++++++++++++++++++++++++++++++++++ INSTALL.txt | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 20 ++++------ data | 2 +- 7 files changed, 208 insertions(+), 201 deletions(-) delete mode 100644 HOWTO-MXE.txt delete mode 100644 HOWTO.txt create mode 100644 INSTALL-MXE.txt create mode 100644 INSTALL.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 60839be..607df20 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -125,10 +125,9 @@ option(GLEW_STATIC "Link statically with GLEW" OFF) find_package(GLEW REQUIRED) -include("${colobot_SOURCE_DIR}/cmake/FindLibSndFile.cmake") - if (${OPENAL_SOUND}) find_package(OpenAL REQUIRED) + include("${colobot_SOURCE_DIR}/cmake/FindLibSndFile.cmake") endif() @@ -229,11 +228,19 @@ if(${TESTS}) endif() # Installation paths defined before compiling sources -set(COLOBOT_INSTALL_BIN_DIR ${CMAKE_INSTALL_PREFIX}/games CACHE PATH "Colobot binary directory") -set(COLOBOT_INSTALL_DATA_DIR ${CMAKE_INSTALL_PREFIX}/share/games/colobot CACHE PATH "Colobot shared data directory") -set(COLOBOT_INSTALL_LIB_DIR ${CMAKE_INSTALL_PREFIX}/lib/colobot CACHE PATH "Colobot libraries directory") -set(COLOBOT_INSTALL_DOC_DIR ${CMAKE_INSTALL_PREFIX}/share/doc/colobot CACHE PATH "Colobot documentation directory") -set(COLOBOT_INSTALL_I18N_DIR ${CMAKE_INSTALL_PREFIX}/share/locale CACHE PATH "Colobot translations directory") +if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") + set(COLOBOT_INSTALL_BIN_DIR ${CMAKE_INSTALL_PREFIX}/ CACHE PATH "Colobot binary directory") + set(COLOBOT_INSTALL_LIB_DIR ${CMAKE_INSTALL_PREFIX}/ CACHE PATH "Colobot libraries directory") + set(COLOBOT_INSTALL_DATA_DIR ${CMAKE_INSTALL_PREFIX}/data CACHE PATH "Colobot shared data directory") + set(COLOBOT_INSTALL_I18N_DIR ${CMAKE_INSTALL_PREFIX}/ CACHE PATH "Colobot translations directory") + set(COLOBOT_INSTALL_DOC_DIR ${CMAKE_INSTALL_PREFIX}/doc CACHE PATH "Colobot documentation directory") +else() + set(COLOBOT_INSTALL_BIN_DIR ${CMAKE_INSTALL_PREFIX}/games CACHE PATH "Colobot binary directory") + set(COLOBOT_INSTALL_LIB_DIR ${CMAKE_INSTALL_PREFIX}/lib/colobot CACHE PATH "Colobot libraries directory") + set(COLOBOT_INSTALL_DATA_DIR ${CMAKE_INSTALL_PREFIX}/share/games/colobot CACHE PATH "Colobot shared data directory") + set(COLOBOT_INSTALL_I18N_DIR ${CMAKE_INSTALL_PREFIX}/share/locale CACHE PATH "Colobot translations directory") + set(COLOBOT_INSTALL_DOC_DIR ${CMAKE_INSTALL_PREFIX}/share/doc/colobot CACHE PATH "Colobot documentation directory") +endif() # Subdirectory with sources add_subdirectory(src bin) diff --git a/HOWTO-MXE.txt b/HOWTO-MXE.txt deleted file mode 100644 index 4467cd3..0000000 --- a/HOWTO-MXE.txt +++ /dev/null @@ -1,68 +0,0 @@ -Cross-compiling with MXE (http://mxe.cc) - -MXE works for any BSD-compatible system (including Linux). -It is a complete package with cross-compiler to Win32 (a MinGW variant) -and includes scripts to automatically download and build many 3rd party -libraries and tools. - -1. See the MXE website for list of required packages and make sure - you have them installed. - -2. Download MXE and unpack it in the directory, where you want to keep it - permanently. During the build, MXE will write that path to many files, - so moving that directory can be tricky. - -3. `cd' to the MXE root directory. - It already contains a universal Makefile for everything. - Usage is simply `make [name_of_package]'. - It will automatically check for dependencies, etc. - The packages will be installed in the MXE directory in usr/. - - You need to `make gcc' for basic compiler and then some additional - libraries. In the end, you should have the following packages installed - (this is the final listing of usr/installed/): - - binutils - boost - bzip2 - check-requirements - expat - freetype - gcc - gcc-gmp - gcc-mpc - gcc-mpfr - gettext - glew - jpeg - libiconv - libpng - libtool - mingwrt - openal - portaudio - sdl - sdl_image - sdl_ttf - tiff - w32api - xz - zlib - - for audio support: - openal - libsndfile - -4. Now `cd' to colobot directory. To cross-compile a CMake project, you have to specify - a CMake toolchain file. MXE has such file in MXE's directory: - usr/i686-pc-mingw32/share/cmake/mxe-conf.cmake - Toolchain file is specified thus: - `cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/mxe-conf.cmake .' - The new CMake files in colobot should detect that MXE is being used and they will - modify flags, paths, etc. You should not run into any problems. - -5. `make' should now compile the game with the resulting exe in bin/colobot.exe. - The exe is linked against all libraries *statically*, so there are no dependencies - on external dlls. However, the resulting binary will be huge with all these libraries, - so you should `strip bin/colobot.exe'. - diff --git a/HOWTO.txt b/HOWTO.txt deleted file mode 100644 index cd236c4..0000000 --- a/HOWTO.txt +++ /dev/null @@ -1,113 +0,0 @@ -EN - -How to... - -1. Compile the game. - - 1.1 Windows: - - CROSS-COMPILING: see the instructions in HOWTO-MXE.txt on how to cross-compile the project - with MXE (http://mxe.cc/). - - NOTE: currently, there are some issues when compiling on Windows, connected mostly with - clashing macros defined in windows headers. Most probably, a special development package - will be provided, which will include MinGW, CMake and all necessary libraries. - - 1. Download and install MinGW and MSYS: - http://sourceforge.net/projects/mingw/files/Installer/mingw-get-inst/mingw-get-inst-20111118/ - When installing, select all available components. - 2. Download and install CMake: - http://www.cmake.org/cmake/resources/software.html (the Windows zip file) - Unpack the contents of the archive to where MinGW is installed (files from bin/ should go into bin/, etc.) - 3. Download the following libraries, installing them in your MinGW directory like with CMake: - SDL >=1.2.10, SDL_image >= 1.2, SDL_ttf >= 2.0, libpng >= 1.2, GLEW >= 1.8.0, Boost >= 1.51 (with filesystem) - Note #1: For most libraries, you can download binary packages with compiled files. - However, you must ensure that they work with MinGW as some are built with MSVC - and may be incompatible. If that is the case, you should compile the libraries from sources - using MinGW. - Note #2: For GLEW, you need to compile from source under MinGW. Since there is no automated - make script for that, follow the instructions here: http://stackoverflow.com/questions/6005076/ - 4. Run MinGW console from the shortcut in menu start. - 5. Change to the directory where you have the Colobot sources by typing "cd /c/where/the/sources/are" - 6. Type "cmake -G 'MSYS Makefiles' ." - 7. Type "make" - 8. Everything should compile without errors. - - 1.2 Linux: - - Since you're running Linux, you probably know how to do this anyway ;) - But just in case, here's what you need: - gcc compiler (with gcc-g++), cmake, libraries with header files: GLEW, SDL, SDL_image, SDL_ttf, libpng, boost - Instructions are the same: - $ cmake . - $ make - - Note #1: For audio support you need libsndfile and openal. - - 1.3 Other platforms, compilers, etc. - - We haven't checked other platforms yet but the code isn't particularly tied to any compiler or platform, so in theory it should work. - If you can, please try to compile the code on your platform and let us know how it goes. - -2. Run the compiled game. - - 1. Download development data package - make sure you get the latest version as the files will be changed/moved around. - Currently the files are hosted at: http://colobot.info/files (packages are named colobot-data-YYYY-MM-DD.zip) - 2. Unpack the data package to any place you want. - 3. Run the game with commandline option "-datadir where_you_put_the_data_dir" and enjoy the game. - - -PL - -Jak... - -1. Skompilować grÄ™. - - 1.1 Windows: - - CROSS-KOMPILACJA: zobacz plik HOWTO-MXE.txt z instrukcjami (po angielsku) jak cross-skompilować projekt używajÄ…c - MXE (http://mxe.cc/). - - UWAGA: obecnie wystÄ™pujÄ… problemy z kompilacjÄ… na Windowsie, głównie ze wzglÄ™du na konflikt w makrach, - jakie definiujÄ… nagłówki windowsowe. Najprawdopodobniej, zostanie wydana specjalna paczka - dla developerów, która bÄ™dzie zawieraÅ‚a MinGW, CMake i wszystkie potrzebne biblioteki. - - 1. ÅšciÄ…gamy i instalujemy MinGW i MSYS: - http://sourceforge.net/projects/mingw/files/Installer/mingw-get-inst/mingw-get-inst-20111118/ - Przy instalacji zaznaczamy wszystkie komponenty do instalacji. - 2. ÅšciÄ…gamy i instalujemy CMake: - http://www.cmake.org/cmake/resources/software.html (plik zip dla Windowsa) - Zip rozpakowujemy do katalogu, gdzie zainstalowany jest MinGW (pliki z bin/ majÄ… trafić do bin/ itd.). - 3. ÅšciÄ…gamy nastÄ™pujÄ…ce biblioteki i instalujemy je tam, gdzie MinGW, podobnie jak z CMake: - SDL >= 1.2.10, SDL_image >= 1.2, SDL_ttf >= 2.0, libpng >= 1.2, Boost >= 1.51 (wraz z filesystem) - Uwaga #1: W wiÄ™kszoÅ›ci wymienionych bibliotek można Å›ciÄ…gnąć paczki binarne ze skompilowanymi plikami. - Jednak musisz siÄ™ upewnić, że pliki te bÄ™dÄ… współpracowaÅ‚y z MinGW, bo część z nich - jest kompilowana MSVC i może być niezgodna. W takim wypadku, musisz skompilować bibliotekÄ™ - ze źródeÅ‚ pod MinGW. - Uwaga #2: W przypadku GLEW, musisz skompilować bibliotekÄ™ ze źródeÅ‚ pod MinGW. Ponieważ nie ma skryptu - make do tego, użyj poleceÅ„ opisanych tutaj: http://stackoverflow.com/questions/6005076/ - 4. Uruchamiamy MinGW console ze skrótu w menu start. - 5. Przechodzimy do katalogu, gdzie sÄ… źródÅ‚a wpisujÄ…c "cd /c/tam/gdzie/sa/zrodla" - 6. Wpisujemy "cmake -G 'MSYS Makefiles' ." - 7. Wpisujemy "make" - 8. Wszystko powinno siÄ™ skomplikować bez bÅ‚Ä™dów. - - 1.2 Linux: - - Skoro już masz Linuksa, to prawdopodobnie wiesz co robić ;) - Ale na wszelki wypadek, potrzebujesz tego: - kompilator gcc (razem z gcc-g++), cmake, biblioteki wraz z nagłówkami: SDL, SDL_image, SDL_ttf, libpng, boost - Polecenia sÄ… takie same: - $ cmake . - $ make - - 1.3 Inne platformy, kompilatory, etc. - - Nie sprawdzaliÅ›my jeszcze innych platform, ale kod nie jest jakoÅ› specjalnie zwiÄ…zany z danym kompilatorem czy platformÄ…, wiÄ™c w teorii powinien zadziaÅ‚ać. - JeÅ›li możesz, spróbuj skompilować kod na twojej platformie i daj nam znać jak poszÅ‚o. - -2. Uruchomić skompilowanÄ… grÄ™. - - 1. ÅšciÄ…gamy paczkÄ™ developerskÄ… z plikami danych gry - upewnij siÄ™, że jest to najnowsza wersja, bo pliki bÄ™dÄ… zmieniane/przenoszone. - 2. Wypakowujemy pliki gdziekolwiek. - 3. Uruchamiamy grÄ™ wraz z opcjÄ… "-datadir tam_gdzie_rozpakowaÅ‚eÅ›_paczkÄ™" i cieszymy siÄ™ grÄ…. diff --git a/INSTALL-MXE.txt b/INSTALL-MXE.txt new file mode 100644 index 0000000..120a60e --- /dev/null +++ b/INSTALL-MXE.txt @@ -0,0 +1,71 @@ +# Cross-compiling with MXE + +MXE works for any BSD-compatible system (including Linux). +It is a complete package with cross-compiler to Win32 (a MinGW variant) +and includes scripts to automatically download and build many 3rd party +libraries and tools. + +To cross-compile Colobot using MXE: + +1. See the MXE website (http://mxe.cc) for list of required packages and make sure + you have them installed. + +2. Download MXE and unpack it in the directory, where you want to keep it + permanently. During the build, MXE will write that path to many files, + so moving that directory can be tricky. + +3. `cd` to the MXE root directory. + It already contains a universal Makefile for everything. + Usage is simply `make name_of_package`. + It will automatically check for dependencies, etc. + The packages will be installed in the MXE directory under `usr/`. + + You need to `make gcc` first for basic compiler and then do the same + for some additional libraries. In the end, you should have the following + packages installed (this is the final listing of `usr/installed/`): + * binutils + * boost + * bzip2 + * check-requirements + * expat + * flac + * freetype + * gcc + * gcc-gmp + * gcc-mpc + * gcc-mpfr + * gettext + * glew + * jpeg + * libiconv + * libpng + * libtool + * mingwrt + * portaudio + * sdl + * sdl_image + * sdl_ttf + * tiff + * w32api + * xz + * zlib + + For optional audio support you'll need also: + * openal + * libsndfile + * ogg + * vorbis + * flac + +4. Now `cd` to directory with colobot sources. To cross-compile a CMake project, + you have to specify a CMake toolchain file. MXE has such file in MXE's directory: + `usr/i686-pc-mingw32/share/cmake/mxe-conf.cmake` + Toolchain file is specified thus:`cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/mxe-conf.cmake .` + CMake files in Colobot should detect that MXE is being used and they will + modify flags, paths, etc. as required. You should not run into any problems. + *Note:* you may also want to use a separate out-of-source build directory for MXE. + +5. `make` should now compile the game with the resulting exe in `bin/colobot.exe`. + The exe is linked against all libraries *statically*, so there are no dependencies + on external DLLs. However, the resulting binary will be huge with all these libraries, + so you might want to do:`strip bin/colobot.exe`. diff --git a/INSTALL.txt b/INSTALL.txt new file mode 100644 index 0000000..cb9943f --- /dev/null +++ b/INSTALL.txt @@ -0,0 +1,114 @@ +# Compile and install instructions + +## Source and data files + +Colobot source files can be downloaded from Github repository (https://github.com/colobot/colobot). You can either download +the repository as a ZIP archive, or, clone the repository using git or a GUI frontent for git. + +Make sure that once you download/clone the repository, you have the neeeded data files in `data/` subdirectory.These files +are provided as git submodule, hosted at a separate Github repository (https://github.com/colobot/colobot-data). If you +don't have them, download the repository and unpack its content into `data/`. + + +## Compiling on Windows + +#### Compiling with MSYS/MinGW + +If you like challenges ;-), you can try to compile Colobot directly under MSYS/MinGW (http://www.mingw.org/wiki/MSYS). +You need to manually compile about 20 packages and resolve many problems. Fortunately, the developers took pity on you, +and provide a download package containing all the necessary libraries and tools. + +To use this package, you must first install a vanilla MSYS/MinGW enviromnent. To do this, download and run +mingw-get installer (http://sourceforge.net/projects/mingw/files/Installer/mingw-get-inst/). +When installing, select **all** possible packages in the installer. + +Next, download the development package available at Colobot site (http://colobot.info/) and unpack the files +from the archive to MinGW directory. This should provide a working environment, including CMake and +all necessary packages. + +To compile Colobot, `cd` to directory with sources and run: + $ cmake -G "MSYS Makefiles" -DCMAKE_BUILD_TYPE=Release -DOPENAL_SOUND=1 . +and then: + $ make + +Everything should compile just fine. If you see any errors, it most likely means missing libraries or invalid installation. +Warnings may occur, but are mostly harmless. + +You'll get the binary in `bin/colobot.exe`, which you can run directly, pointing it to the data directory: + $ bin/colobot.exe -datadir ./data + +You can also install Colobot in your system using + $ make install + +The default install path is `C:\Program Files\colobot`, but you can change it by adding `-DCMAKE_INSTALL_PREFIX="C:\your\path"` +to CMake arguments. + +See also "Hints and notes" below on some useful advice. + +#### Cross-compiling using MXE + +MXE (http://mxe.cc/) is a very good cross-compiling framework, complete with a suite of libraries +that make it extremely easy to port applications to Win32. It runs on pretty much any *nix flavor and generates generic, +statically linked Win32 binaries. More information is available in INSTALL-MXE.txt file. + + +## Compiling on Linux + +Depending on your distribution, you'll need to install different packages, so here's just an outline, the details will +be different for different distros: + * recent compiler (GCC >= 4.6 or a newer clang) since we are using some features of C++11. + * CMake >= 2.8. + * Boost >= 1.51 (header files + components: filesystem and regex) + * SDL >= 1.2.10 + * SDL_image >= 1.2 + * SDL_ttf >= 2.0 + * GLEW >= 1.8.0 + * libpng >= 1.2 + * gettext >= 0.18 + +For optional sound support (`-DOPENAL_SOUND`): + * libsndfile >= 1.0.25 + * libvorbis >= 1.3.2 + * libogg >= 1.3.0 + * OpenAL (OpenAL-Soft) >= 1.13 (optional) + +Instructions for compiling are universal: + $ cmake -DCMAKE_BUILD_TYPE=Release -DOPENAL_SOUND=1 . + $ make + +Everything should compile just fine. If you see any errors, it most likely means missing libraries. Warnings may occur, +but are mostly harmless. + +You'll get the binary in `bin/colobot`, which you can run directly, pointing it to the data directory: + $ bin/colobot -datadir ./data + +To install colobot in the system, you can run: + $ make install + +The default installation path is `/usr/local/` but you can change it by adding `-DCMAKE_INSTALL_PREFIX="/your/custom/path"` +to CMake arguments. + +See also "Hints and notes" below on some useful advice. + + +## Compiling on other platforms + +We haven't checked other platforms yet but the code isn't particularly tied to any compiler or platform, so in theory +it should work. If you can, please try to compile the code on your platform and let us know how it goes. + + +## Hints and notes + +CMake has a very useful feature - out-of-source builds - using a separate directory for the output of CMake and compiler. +This way, you can keep clean the directory with your source files. Example of use (starting from directory with sources): + $ mkdir build/ + $ cd build/ + $ cmake ../ + $ make + + +If you want to submit debug reports, please use Debug builds (`-DCMAKE_BUILD_TYPE=Debug`) and run the game in debug mode and with +logging on higher level (commandline arguments: `-debug -loglevel debug`). Also, `-help` will give full list of available arguments. + + +If you encounter any problems, you can get help at our forum or IRC channels. diff --git a/README.md b/README.md index 994fce1..3e35172 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,13 @@ Welcome to the Colobot project code repository -> NOTE: this is the new repository which was moved here from https://github.com/adiblol/colobot. The new repository has been purged of binary files cluttering the history, so all commits have been overwritten. If you have been using the old repository, you have to clone from scratch the new one. - This is official repository for the open-source Colobot project developed by Polish Portal of Colobot (PPC; in Polish: Polski Portal Colobota) with the official site at: http://colobot.info/. The source code contained here was released by Epsitec -- the original creator of the game -- on open source (GPLv3) license. The code was given and the rights granted specifically to PPC community in March 2012. Since then, we have been modifying the code and working on our goals, which are briefly summed up below. More information for developers (in English) can be found on the [developer wiki](https://colobot.info/wiki/Dev:Main_Page). However, the freshest source of information is our IRC channels, see below. -This repository contains only the source code of the project. The game requires also data files which are available in separate packages, currently at http://colobot.info/files/. The packages are named colobot-data-YYYY-MM-DD.zip. Make sure you have the latest package before compiling and running the code in repository. +This repository contains only the source code of the project. The game requires also data files which are now provided as git submodule and are hosted in separate repository (https://github.com/colobot/colobot-data). ## Status @@ -25,7 +23,7 @@ This is the original version of the game, as released to us by Epsitec with only This is a version of the game that is currently being developed in this repository. It is based on the original code, but refreshed and rewritten using SDL and OpenGL libraries, thus making it multiplatform. -As of September 2012, we have rewritten almost all of the original code and we are in the process of testing and fixing issues that are still present in the game. The game runs and compiles under Windows and Linux. The master branch contains the current snapshot code which should always compile and run with the latest data pack. The dev branch and dev-\* sub-branches are used for general development. +Currently (March 2013), we have rewritten all of the original code and we are in the process of testing and fixing issues that are still present in the game. The master branch contains the current snapshot code which should always compile and run with the latest data pack. The dev branch is used for general development. ### Milestone 3 - Colobot 2 @@ -34,12 +32,12 @@ This will be a new installment in the Colobot series. We have many ideas for the ## Compiling and running the game -For these instructions see HOWTO.txt file. +For these instructions see INSTALL.txt file. ## Contact -If you want to help in the project, please contact us on our IRC channels or the forum on our website: http://colobot.info/forum (Polish only). We're in the process of moving to a new site and forum so not all information on our old site is up-to-date, but we'll be done soon. +If you want to help in the project, please contact us on our IRC channels or the forum on our website: http://colobot.info/forum (Polish only). ### IRC channels @@ -51,15 +49,13 @@ If you want to help in the project, please contact us on our IRC channels or the Witamy w repozytorium projektu Colobot -> UWAGA: to jest nowe repozytorium, które zostaÅ‚o przeniesione tu z https://github.com/adiblol/colobot. Nowe repozytorium zostaÅ‚o wyczyszczone z plików binarnych, które zostaÅ‚y w historii, wiÄ™c wszystkie commity zostaÅ‚y nadpisane. Jeżeli korzystaÅ‚eÅ›/aÅ› ze starego repozytorium, musisz sklonować od zera te nowe. - To jest oficjalne repozytorium z kodem projektu open-source Colobot rozwijanego przez Polski Portal Colobota (PPC; po angielsku: Polish Portal of Colobot) z oficjalnÄ… stronÄ…: http://colobot.info/. Kod źródÅ‚owy zawarty tutaj zostaÅ‚ wydany przez Epsitec -- oryginalnego twórcÄ™ gry -- na otwartej licencji (GPLv3). Kod zostaÅ‚ wydany i prawa nadane specjalnie dla spoÅ‚ecznoÅ›ci PPC w marcu 2012. Od tamtej pory, zajmujemy siÄ™ modyfikowaniem kodu i pracowaniem nad naszymi celami, które sÄ… krótko podsumowane poniżej. WiÄ™cej informacji dla developerów projektu (po angielsku) można znaleźć na [wiki dla developerów](http://colobot.info/wiki/Dev:Main_Page). Jednak źródÅ‚em najÅ›wieższych informacji jest nasz kanaÅ‚ IRC #colobot na pirc.pl. -To repozytorium zawiera jedynie kod źródÅ‚owy projektu. Gra wymaga jeszcze plików danych, które sÄ… dostÄ™pne w osobnych paczkach, obecnie na stronie http://colobot.info/files. Paczki sÄ… nazwane colobot-data-RRRR-MM-DD.zip. Upewnij siÄ™, że masz najnowszÄ… wersjÄ™ paczki zanim skompilujesz i uruchomisz kod z repozytorium. +To repozytorium zawiera jedynie kod źródÅ‚owy projektu. Gra wymaga jeszcze plików danych, które sÄ… teraz udostÄ™pniane jako submoduÅ‚ gita i hostowane w osobnym repozytorium ((https://github.com/colobot/colobot-data). ## Status @@ -74,7 +70,7 @@ To jest oryginalna wersja gry, dokÅ‚adnie taka, jakÄ… otrzymaliÅ›my od Epsiteca Jest to wersja gry, którÄ… obecnie rozwijamy w tym repozytorium. Jest oparta na oryginalnym kodzie, ale odÅ›wieżonym i przepisanym z wykorzystaniem bibliotek SDL i OpenGL, czyniÄ…c jÄ… wieloplatformowÄ…. -Do wrzeÅ›nia 2012, przepisaliÅ›my prawie caÅ‚y oryginalny kod i jesteÅ›my teraz w trakcie testowania i poprawiania bÅ‚Ä™dów nadal obecnych w grze. Gałąź master zawiera obecny snapshot kodu, który powinien zawsze dać siÄ™ skompilować i uruchomić z najnowszÄ… paczkÄ… danych. GaÅ‚Ä™zie dev i podgaÅ‚Ä™zie dev-\* sÄ… wykorzystywane do ogólnego rozwoju. +Obecnie (marzec 2013), przepisaliÅ›my caÅ‚y oryginalny kod i jesteÅ›my teraz w trakcie testowania i poprawiania bÅ‚Ä™dów nadal obecnych w grze. Gałąź master zawiera obecny snapshot kodu, który powinien zawsze dać siÄ™ skompilować i uruchomić z aktualnÄ… paczkÄ… danych. Gałąź dev jest wykorzystywana do ogólnego rozwoju. ### Krok 3 - Colobot 2 @@ -83,9 +79,9 @@ To bÄ™dzie nowa część z cyklu gier Colobot. Mamy wiele pomysłów na nowÄ… gr ## Kompilacja i uruchomienie gry -Instrukcje te znajdujÄ… siÄ™ w pliku HOWTO.txt. +Instrukcje te znajdujÄ… siÄ™ w pliku INSTALL.txt (po angielsku). ## Kontakt -Jeżeli chcesz pomóc w projekcie, prosimy o kontakt na naszym kanale IRC: #colobot na pirc.pl (po polsku i angielsku) albo na forum na naszej stronie: http://colobot.info/forum (jedynie polski). JesteÅ›my teraz w trakcie przenoszenia strony i forum w nowe miejsce i nie wszystkie informacje na starej stronie sÄ… aktualne, ale już niedÅ‚ugo skoÅ„czymy przenosiny. +Jeżeli chcesz pomóc w projekcie, prosimy o kontakt na naszym kanale IRC: #colobot na pirc.pl (po polsku i angielsku) albo na forum na naszej stronie: http://colobot.info/forum (jedynie polski). diff --git a/data b/data index 5c27c5e..d4cbd51 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 5c27c5e1ebbd1398eeecbfb28abbb457442a549f +Subproject commit d4cbd51016acdd57f4357a9773b2c27e30875649 -- cgit v1.2.3-1-g7c22 From 25c3ba0d3b06fe4e63f3dab4f80f596026b36377 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 23 Mar 2013 19:04:41 +0100 Subject: Basic detection of syntax errors in mission levels + option to enable Retro mode (for now doesn't do enything) --- src/object/robotmain.cpp | 155 +++++++++++++++++++++++++++++++++++++++++++++-- src/object/robotmain.h | 8 +++ 2 files changed, 157 insertions(+), 6 deletions(-) diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 2554ce4..b3f269c 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -649,6 +649,14 @@ CRobotMain::CRobotMain(CApplication* app) m_selectObject = 0; m_infoUsed = 0; + m_beginObject = false; + m_terrainGenerate = false; + m_terrainInit = false; + m_terrainInitTextures = false; + m_terrainCreate = false; + + m_version = 1; + m_retroStyle = false; m_immediatSatCom = false; m_beginSatCom = false; m_movieLock = false; @@ -3818,21 +3826,32 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_dialog->BuildResumeName(m_resume, base, rank); GetResource(RES_TEXT, RT_SCRIPT_NEW, m_scriptName); m_scriptFile[0] = 0; + + m_beginObject = false; + m_terrainGenerate = false; + m_terrainInit = false; + m_terrainInitTextures = false; + m_terrainCreate = false; + + m_retroStyle = false; } char line[500]; char name[200]; char dir[100]; char op[100]; + char filename[500]; + int lineNum = 0; memset(line, 0, 500); memset(name, 0, 200); memset(dir, 0, 100); memset(op, 0, 100); + memset(filename, 0, 500); std::string tempLine; m_dialog->BuildSceneName(tempLine, base, rank); - strcpy(line, tempLine.c_str()); - FILE* file = fopen(line, "r"); + strcpy(filename, tempLine.c_str()); + FILE* file = fopen(filename, "r"); if (file == NULL) return; int rankObj = 0; @@ -3848,6 +3867,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) while (fgets(line, 500, file) != NULL) { + lineNum++; for (int i = 0; i < 500; i++) { if (line[i] == '\t' ) line[i] = ' '; // replace tab by space @@ -3858,6 +3878,9 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) } } + if (Cmd(line, "MissionFile") && !resetObject) + m_version = OpInt(line, "version", 1); + // TODO: Fallback to an non-localized entry sprintf(op, "Title.%c", m_app->GetLanguageChar()); if (Cmd(line, op) && !resetObject) @@ -4000,34 +4023,96 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_engine->SetForegroundName(name); } - if (Cmd(line, "Global") && !resetObject) + if (((m_version == 1 && Cmd(line, "Global")) || (m_version >= 2 && Cmd(line, "Mission"))) && !resetObject) { g_unit = OpFloat(line, "unitScale", 4.0f); m_engine->SetTracePrecision(OpFloat(line, "traceQuality", 1.0f)); m_shortCut = OpInt(line, "shortcut", 1); + if(m_version >= 2) { + m_retroStyle = OpInt(line, "retro", 0); + if(m_retroStyle) GetLogger()->Info("Retro mode enabled.\n"); + } } if (Cmd(line, "TerrainGenerate") && !resetObject) { + if(m_terrainCreate) { + GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainGenerate after TerrainCreate\n", filename, lineNum); + continue; + } + + if(m_terrainInit) { + GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainGenerate after TerrainInit\n", filename, lineNum); + continue; + } + m_terrain->Generate(OpInt(line, "mosaic", 20), OpInt(line, "brick", 3), OpFloat(line, "size", 20.0f), OpFloat(line, "vision", 500.0f)*g_unit, OpInt(line, "depth", 2), OpFloat(line, "hard", 0.5f)); + + m_terrainGenerate = true; } - if (Cmd(line, "TerrainWind") && !resetObject) + if (Cmd(line, "TerrainWind") && !resetObject) { + if(m_terrainCreate) { + GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainWind after TerrainCreate\n", filename, lineNum); + continue; + } + + if(m_terrainInit) { + GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainWind after TerrainInit\n", filename, lineNum); + continue; + } + + if(!m_terrainGenerate) { + GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainWind before TerrainGenerate\n", filename, lineNum); + continue; + } + m_terrain->SetWind(OpPos(line, "speed")); + } if (Cmd(line, "TerrainRelief") && !resetObject) { + if(m_terrainCreate) { + GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainRelief after TerrainCreate\n", filename, lineNum); + continue; + } + + if(m_terrainInit) { + GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainRelief after TerrainInit\n", filename, lineNum); + continue; + } + + if(!m_terrainGenerate) { + GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainRelief before TerrainGenerate\n", filename, lineNum); + continue; + } + OpString(line, "image", name); m_terrain->LoadRelief(name, OpFloat(line, "factor", 1.0f), OpInt(line, "border", 1)); } if (Cmd(line, "TerrainResource") && !resetObject) { + if(m_terrainCreate) { + GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainResource after TerrainCreate\n", filename, lineNum); + continue; + } + + if(m_terrainInit) { + GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainResource after TerrainInit\n", filename, lineNum); + continue; + } + + if(!m_terrainGenerate) { + GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainResource before TerrainGenerate\n", filename, lineNum); + continue; + } + OpString(line, "image", name); m_terrain->LoadResources(name); } @@ -4072,6 +4157,11 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (Cmd(line, "TerrainInitTextures") && !resetObject) { + if(m_terrainInit) { + GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainInitTextures and TerrainInit at same time\n", filename, lineNum); + continue; + } + OpString(line, "image", name); AddExt(name, ".png"); int dx = OpInt(line, "dx", 1); @@ -4085,13 +4175,37 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) CopyFileListToTemp(name, tt, dx*dy); m_terrain->InitTextures(name, tt, dx, dy); + + m_terrainInitTextures = true; } - if (Cmd(line, "TerrainInit") && !resetObject) + if (Cmd(line, "TerrainInit") && !resetObject) { + if(m_terrainInitTextures) { + GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainInit and TerrainInitTextures at same time\n", filename, lineNum); + continue; + } + m_terrain->InitMaterials(OpInt(line, "id", 1)); + m_terrainInit = true; + } if (Cmd(line, "TerrainMaterial") && !resetObject) { + if(m_terrainCreate) { + GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainMaterial after TerrainCreate\n", filename, lineNum); + continue; + } + + if(m_terrainInit) { + GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainMaterial after TerrainInit\n", filename, lineNum); + continue; + } + + if(m_terrainInitTextures) { + GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainMaterial and TerrainInitTextures at same time\n", filename, lineNum); + continue; + } + OpString(line, "image", name); AddExt(name, ".png"); if (strstr(name, "%user%") != 0) { @@ -4111,6 +4225,26 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (Cmd(line, "TerrainLevel") && !resetObject) { + if(m_terrainCreate) { + GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainLevel after TerrainCreate\n", filename, lineNum); + continue; + } + + if(!m_terrainInit) { + GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainLevel before TerrainInit\n", filename, lineNum); + continue; + } + + if(m_terrainInitTextures) { + GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainLevel and TerrainInitTextures at same time\n", filename, lineNum); + continue; + } + + if(!m_terrainGenerate) { + GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainLevel before TerrainGenerate\n", filename, lineNum); + continue; + } + char* op = SearchOp(line, "id"); int id[50]; int i = 0; @@ -4129,8 +4263,10 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) OpFloat(line, "radius", 0.0f)*g_unit); } - if (Cmd(line, "TerrainCreate") && !resetObject) + if (Cmd(line, "TerrainCreate") && !resetObject) { m_terrain->CreateObjects(); + m_terrainCreate = true; + } if (Cmd(line, "BeginObject")) { @@ -4139,10 +4275,17 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (read[0] != 0) // loading file ? sel = IOReadScene(read, stack); + + m_beginObject = true; } if (Cmd(line, "CreateObject") && read[0] == 0) { + if (!m_beginObject) { + GetLogger()->Error("Syntax error in file '%s' (line %d): CreateObject before BeginObject\n", filename, lineNum); + continue; + } + ObjectType type = OpTypeObject(line, "type", OBJECT_NULL); int gadget = OpInt(line, "gadget", -1); diff --git a/src/object/robotmain.h b/src/object/robotmain.h index 6a45473..181a1cb 100644 --- a/src/object/robotmain.h +++ b/src/object/robotmain.h @@ -447,6 +447,14 @@ protected: int m_delayWriteMessage; int m_movieInfoIndex; + bool m_beginObject; + bool m_terrainGenerate; + bool m_terrainInitTextures; + bool m_terrainInit; + bool m_terrainCreate; + + int m_version; // Mission file version + bool m_retroStyle; // Retro style bool m_immediatSatCom; // SatCom immediately? bool m_beginSatCom; // messages SatCom poster? bool m_movieLock; // movie in progress? -- cgit v1.2.3-1-g7c22 From 956efb1feb7767c2845c8d6d241f036c179f6adf Mon Sep 17 00:00:00 2001 From: erihel Date: Sat, 23 Mar 2013 20:33:14 +0100 Subject: * Blocked cheat input in SatCom, intro movie and while editing cbot (issue #130) --- src/object/robotmain.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index b3f269c..55a9b86 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -1331,6 +1331,7 @@ bool CRobotMain::EventProcess(Event &event) // Management of the console. if (m_phase != PHASE_NAME && !m_movie->IsExist() && + !m_movieLock && !m_editLock && event.type == EVENT_KEY_DOWN && event.key.key == KEY(PAUSE)) // Pause ? { @@ -2090,6 +2091,8 @@ void CRobotMain::StartDisplayInfo(const char *filename, int index) //! End of displaying of instructions void CRobotMain::StopDisplayInfo() { + if (m_cmdEdit) return; + if (m_movieInfoIndex != -1) // film to read the SatCom? m_movie->Start(MM_SATCOMclose, 2.0f); -- cgit v1.2.3-1-g7c22 From 7ebba6abaa66abda690dcdb87248dfcb0c1dedc6 Mon Sep 17 00:00:00 2001 From: erihel Date: Sat, 23 Mar 2013 21:22:44 +0100 Subject: * Changed ending screen (issue #129) --- src/ui/maindialog.cpp | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 8b97f4e..9964ef7 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -375,7 +375,7 @@ pb->SetState(STATE_SHADOW); pos.y -= 5.0f/480.0f; pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL1, "PPC Team"); pl->SetFontType(Gfx::FONT_COURIER); - pl->SetFontSize(8.0f); + pl->SetFontSize(Gfx::FONT_SIZE_SMALL); m_engine->SetBackground("interface.png", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), @@ -1817,7 +1817,7 @@ pos.y -= 0.048f; pe->SetEditCap(false); pe->SetHighlightCap(false); pe->SetFontType(Gfx::FONT_COURIER); - pe->SetFontSize(8.0f); + pe->SetFontSize(Gfx::FONT_SIZE_SMALL); pe->ReadText("help/authors.txt"); pos.x = 80.0f/640.0f; @@ -1829,28 +1829,28 @@ pos.y -= 0.048f; pe->SetEditCap(false); pe->SetHighlightCap(false); pe->SetFontType(Gfx::FONT_COURIER); - pe->SetFontSize(6.5f); + pe->SetFontSize(Gfx::FONT_SIZE_SMALL); pe->ReadText("help/licences.txt"); // #endif /* TODO: #if _SCHOOL -#if _CEEBOTDEMO -pos.x = 80.0f/640.0f; -pos.y = 210.0f/480.0f; -ddim.x = 490.0f/640.0f; -ddim.y = 150.0f/480.0f; -#else -pos.x = 80.0f/640.0f; -pos.y = 200.0f/480.0f; -ddim.x = 490.0f/640.0f; -ddim.y = 150.0f/480.0f; -#endif*/ + #if _CEEBOTDEMO + pos.x = 80.0f/640.0f; + pos.y = 210.0f/480.0f; + ddim.x = 490.0f/640.0f; + ddim.y = 150.0f/480.0f; + #else + pos.x = 80.0f/640.0f; + pos.y = 200.0f/480.0f; + ddim.x = 490.0f/640.0f; + ddim.y = 150.0f/480.0f; + #endif pe = pw->CreateEdit(pos, ddim, 0, EVENT_EDIT1); pe->SetGenericMode(true); pe->SetEditCap(false); pe->SetHighlightCap(false); pe->SetFontType(Gfx::FONT_COURIER); pe->SetFontSize(8.0f); - pe->ReadText("help/authors.txt"); + pe->ReadText("help/authors.txt");*/ /* #if _DEMO //? pos.x = 80.0f/640.0f; @@ -1886,13 +1886,13 @@ ddim.y = 150.0f/480.0f; GetResource(RES_TEXT, RT_GENERIC_DEV1, name); pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL1, name); pl->SetFontType(Gfx::FONT_COURIER); - pl->SetFontSize(8.0f); + pl->SetFontSize(Gfx::FONT_SIZE_SMALL); pos.y = 0.0f/480.0f; GetResource(RES_TEXT, RT_GENERIC_DEV2, name); pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL2, name); pl->SetFontType(Gfx::FONT_COURIER); - pl->SetFontSize(8.0f); + pl->SetFontSize(Gfx::FONT_SIZE_SMALL); pos.x = 355.0f/640.0f; pos.y = 65.0f/480.0f; @@ -1901,13 +1901,13 @@ ddim.y = 150.0f/480.0f; GetResource(RES_TEXT, RT_GENERIC_EDIT1, name); pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL3, name); pl->SetFontType(Gfx::FONT_COURIER); - pl->SetFontSize(8.0f); + pl->SetFontSize(Gfx::FONT_SIZE_SMALL); pos.y = 0.0f/480.0f; GetResource(RES_TEXT, RT_GENERIC_EDIT2, name); pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL4, name); pl->SetFontType(Gfx::FONT_COURIER); - pl->SetFontSize(8.0f); + pl->SetFontSize(Gfx::FONT_SIZE_SMALL); // #endif /* TODO: #if _DEMO @@ -1926,7 +1926,7 @@ ddim.y = 150.0f/480.0f; pb->SetState(STATE_SHADOW); // #endif - m_engine->SetBackground("generic.png", + m_engine->SetBackground("generico.png", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), -- cgit v1.2.3-1-g7c22 From c211b001d2a4c9b36034a812650f1a2ac693ee54 Mon Sep 17 00:00:00 2001 From: erihel Date: Sat, 23 Mar 2013 21:31:09 +0100 Subject: * Updated submodule data --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index d4cbd51..6408820 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit d4cbd51016acdd57f4357a9773b2c27e30875649 +Subproject commit 6408820491281a862b89e0a260cd661b6e603445 -- cgit v1.2.3-1-g7c22 From 195d6cded05f7ef5bde695ee047b341a0265eab3 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 24 Mar 2013 00:03:37 +0100 Subject: Fixed timer functions on win32 * changed win32 implementation to QueryPerformaceTimer system function * refactored system utils code * proper tests for time utils and update event creation in application * should fix issue #134 --- CMakeLists.txt | 43 ++-- cmake/msys.cmake | 12 ++ cmake/mxe.cmake | 3 + src/CMakeLists.txt | 4 +- src/app/app.cpp | 133 ++++++------ src/app/app.h | 2 +- src/app/main.cpp | 32 +-- src/app/system.cpp | 185 +++++++++------- src/app/system.h | 90 +++++--- src/app/system_linux.cpp | 25 ++- src/app/system_linux.h | 16 +- src/app/system_other.cpp | 93 +------- src/app/system_other.h | 13 +- src/app/system_windows.cpp | 64 +++--- src/app/system_windows.h | 29 ++- src/graphics/engine/engine.cpp | 18 +- test/envs/opengl/CMakeLists.txt | 4 +- test/envs/opengl/light_test.cpp | 18 +- test/envs/opengl/model_test.cpp | 18 +- test/envs/opengl/transform_test.cpp | 18 +- test/unit/CMakeLists.txt | 13 +- test/unit/app/app_test.cpp | 320 ++++++++++++++++++++++++++++ test/unit/app/system_linux_test.cpp | 29 ++- test/unit/app/system_mock.h | 48 +++++ test/unit/app/system_windows_test.cpp | 62 ++++++ test/unit/graphics/engine/lightman_test.cpp | 6 +- test/unit/ui/stubs/app_stub.cpp | 5 + 27 files changed, 916 insertions(+), 387 deletions(-) create mode 100644 cmake/msys.cmake create mode 100644 test/unit/app/app_test.cpp create mode 100644 test/unit/app/system_mock.h create mode 100644 test/unit/app/system_windows_test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 607df20..48a47bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,14 +94,6 @@ option(INSTALL_DOCS "Install Doxygen-generated documentation" OFF) option(OPENAL_SOUND "Build openal sound support" OFF) -# Hacks for MSYS -if (MSYS) - set(COLOBOT_CXX_FLAGS "${COLOBOT_CXX_FLAGS} -U__STRICT_ANSI__") # fixes putenv() - set(USE_SDL_MAIN 1) # fixes SDL_main - set(DESKTOP OFF) # MSYS doesn't have the necessary tools -endif() - - ## # Searching for packages ## @@ -131,35 +123,24 @@ if (${OPENAL_SOUND}) endif() -## -# Additional settings to use when cross-compiling with MXE (http://mxe.cc/) -## - -include("${colobot_SOURCE_DIR}/cmake/mxe.cmake") - - ## # Platform detection and some related checks ## if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") - message(STATUS "Windows system detected") set(PLATFORM_WINDOWS 1) set(PLATFORM_LINUX 0) set(PLATFORM_OTHER 0) elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") - message(STATUS "Linux system detected") set(PLATFORM_WINDOWS 0) set(PLATFORM_LINUX 1) set(PLATFORM_OTHER 0) else() - message(STATUS "Other system detected") set(PLATFORM_WINDOWS 0) set(PLATFORM_LINUX 0) set(PLATFORM_OTHER 1) endif() - if(NOT ${ASSERTS}) add_definitions(-DNDEBUG) endif() @@ -171,6 +152,30 @@ else() endif() +## +# Additional settings to use when cross-compiling with MXE (http://mxe.cc/) +## + +include("${colobot_SOURCE_DIR}/cmake/mxe.cmake") + +## +# Additional settings for MSYS +## +include("${colobot_SOURCE_DIR}/cmake/msys.cmake") + + +## +# Summary of detected things +## +if (${PLATFORM_WINDOWS}) + message(STATUS "Build for Windows system") +elseif(${PLATFORM_LINUX}) + message(STATUS "Build for Linux system") +else() + message(STATUS "Build for other system") +endif() + + ## # Doxygen docs ## diff --git a/cmake/msys.cmake b/cmake/msys.cmake new file mode 100644 index 0000000..26b25b2 --- /dev/null +++ b/cmake/msys.cmake @@ -0,0 +1,12 @@ +# Hacks for MSYS +if (MSYS AND (NOT MXE)) + message(STATUS "Detected MSYS build") + + set(PLATFORM_WINDOWS 1) + set(PLATFORM_LINUX 0) + set(PLATFORM_OTHER 0) + + set(COLOBOT_CXX_FLAGS "${COLOBOT_CXX_FLAGS} -U__STRICT_ANSI__") # fixes putenv() + set(USE_SDL_MAIN 1) # fixes SDL_main + set(DESKTOP OFF) # MSYS doesn't have the necessary tools +endif() diff --git a/cmake/mxe.cmake b/cmake/mxe.cmake index 5502c1b..9bb38d0 100644 --- a/cmake/mxe.cmake +++ b/cmake/mxe.cmake @@ -4,6 +4,9 @@ if((${CMAKE_CROSSCOMPILING}) AND (DEFINED MSYS)) message(STATUS "Detected MXE build") set(MXE 1) + set(PLATFORM_WINDOWS 1) + set(PLATFORM_LINUX 0) + set(PLATFORM_OTHER 0) # Because some tests will not compile set(TESTS OFF) # All must be static, CBOT and GLEW too diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3d6908d..de60ef3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -52,9 +52,9 @@ if (${OPENAL_SOUND}) endif() # Platform-dependent implementation of system.h -if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") +if (${PLATFORM_WINDOWS}) set(SYSTEM_CPP_MODULE "system_windows.cpp") -elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") +elseif(${PLATFORM_LINUX}) set(SYSTEM_CPP_MODULE "system_linux.cpp") else() set(SYSTEM_CPP_MODULE "system_other.cpp") diff --git a/src/app/app.cpp b/src/app/app.cpp index e84091b..9349cbf 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -125,14 +125,14 @@ CApplication::CApplication() m_absTime = 0.0f; m_relTime = 0.0f; - m_baseTimeStamp = CreateTimeStamp(); - m_curTimeStamp = CreateTimeStamp(); - m_lastTimeStamp = CreateTimeStamp(); + m_baseTimeStamp = GetSystemUtils()->CreateTimeStamp(); + m_curTimeStamp = GetSystemUtils()->CreateTimeStamp(); + m_lastTimeStamp = GetSystemUtils()->CreateTimeStamp(); for (int i = 0; i < PCNT_MAX; ++i) { - m_performanceCounters[i][0] = CreateTimeStamp(); - m_performanceCounters[i][1] = CreateTimeStamp(); + m_performanceCounters[i][0] = GetSystemUtils()->CreateTimeStamp(); + m_performanceCounters[i][1] = GetSystemUtils()->CreateTimeStamp(); } m_joystickEnabled = false; @@ -177,14 +177,14 @@ CApplication::~CApplication() delete m_iMan; m_iMan = nullptr; - DestroyTimeStamp(m_baseTimeStamp); - DestroyTimeStamp(m_curTimeStamp); - DestroyTimeStamp(m_lastTimeStamp); + GetSystemUtils()->DestroyTimeStamp(m_baseTimeStamp); + GetSystemUtils()->DestroyTimeStamp(m_curTimeStamp); + GetSystemUtils()->DestroyTimeStamp(m_lastTimeStamp); for (int i = 0; i < PCNT_MAX; ++i) { - DestroyTimeStamp(m_performanceCounters[i][0]); - DestroyTimeStamp(m_performanceCounters[i][1]); + GetSystemUtils()->DestroyTimeStamp(m_performanceCounters[i][0]); + GetSystemUtils()->DestroyTimeStamp(m_performanceCounters[i][1]); } } @@ -199,8 +199,8 @@ CSoundInterface* CApplication::GetSound() for (int i = 0; i < PCNT_MAX; ++i) { - DestroyTimeStamp(m_performanceCounters[i][0]); - DestroyTimeStamp(m_performanceCounters[i][1]); + GetSystemUtils()->DestroyTimeStamp(m_performanceCounters[i][0]); + GetSystemUtils()->DestroyTimeStamp(m_performanceCounters[i][1]); } } @@ -607,7 +607,7 @@ bool CApplication::ChangeVideoConfig(const Gfx::GLDeviceConfig &newConfig) std::string(SDL_GetError()) + std::string("\n") + std::string("Previous mode will be restored"); GetLogger()->Error(error.c_str()); - SystemDialog( SDT_ERROR, "COLOBT - Error", error); + GetSystemUtils()->SystemDialog( SDT_ERROR, "COLOBT - Error", error); restore = true; ChangeVideoConfig(m_lastDeviceConfig); @@ -620,7 +620,7 @@ bool CApplication::ChangeVideoConfig(const Gfx::GLDeviceConfig &newConfig) std::string error = std::string("SDL error while restoring previous video mode:\n") + std::string(SDL_GetError()); GetLogger()->Error(error.c_str()); - SystemDialog( SDT_ERROR, "COLOBT - Fatal Error", error); + GetSystemUtils()->SystemDialog( SDT_ERROR, "COLOBT - Fatal Error", error); // Fatal error, so post the quit event @@ -755,9 +755,9 @@ int CApplication::Run() { m_active = true; - GetCurrentTimeStamp(m_baseTimeStamp); - GetCurrentTimeStamp(m_lastTimeStamp); - GetCurrentTimeStamp(m_curTimeStamp); + GetSystemUtils()->GetCurrentTimeStamp(m_baseTimeStamp); + GetSystemUtils()->GetCurrentTimeStamp(m_lastTimeStamp); + GetSystemUtils()->GetCurrentTimeStamp(m_curTimeStamp); MoveMouse(Math::Point(0.5f, 0.5f)); // center mouse on start @@ -1109,49 +1109,49 @@ bool CApplication::ProcessEvent(const Event &event) { case EVENT_KEY_DOWN: case EVENT_KEY_UP: - l->Info("EVENT_KEY_%s:\n", (event.type == EVENT_KEY_DOWN) ? "DOWN" : "UP"); - l->Info(" virt = %s\n", (event.key.virt) ? "true" : "false"); - l->Info(" key = %d\n", event.key.key); - l->Info(" unicode = 0x%04x\n", event.key.unicode); + l->Trace("EVENT_KEY_%s:\n", (event.type == EVENT_KEY_DOWN) ? "DOWN" : "UP"); + l->Trace(" virt = %s\n", (event.key.virt) ? "true" : "false"); + l->Trace(" key = %d\n", event.key.key); + l->Trace(" unicode = 0x%04x\n", event.key.unicode); break; case EVENT_MOUSE_MOVE: - l->Info("EVENT_MOUSE_MOVE:\n"); + l->Trace("EVENT_MOUSE_MOVE:\n"); break; case EVENT_MOUSE_BUTTON_DOWN: case EVENT_MOUSE_BUTTON_UP: - l->Info("EVENT_MOUSE_BUTTON_%s:\n", (event.type == EVENT_MOUSE_BUTTON_DOWN) ? "DOWN" : "UP"); - l->Info(" button = %d\n", event.mouseButton.button); + l->Trace("EVENT_MOUSE_BUTTON_%s:\n", (event.type == EVENT_MOUSE_BUTTON_DOWN) ? "DOWN" : "UP"); + l->Trace(" button = %d\n", event.mouseButton.button); break; case EVENT_MOUSE_WHEEL: - l->Info("EVENT_MOUSE_WHEEL:\n"); - l->Info(" dir = %s\n", (event.mouseWheel.dir == WHEEL_DOWN) ? "WHEEL_DOWN" : "WHEEL_UP"); + l->Trace("EVENT_MOUSE_WHEEL:\n"); + l->Trace(" dir = %s\n", (event.mouseWheel.dir == WHEEL_DOWN) ? "WHEEL_DOWN" : "WHEEL_UP"); break; case EVENT_JOY_AXIS: - l->Info("EVENT_JOY_AXIS:\n"); - l->Info(" axis = %d\n", event.joyAxis.axis); - l->Info(" value = %d\n", event.joyAxis.value); + l->Trace("EVENT_JOY_AXIS:\n"); + l->Trace(" axis = %d\n", event.joyAxis.axis); + l->Trace(" value = %d\n", event.joyAxis.value); break; case EVENT_JOY_BUTTON_DOWN: case EVENT_JOY_BUTTON_UP: - l->Info("EVENT_JOY_BUTTON_%s:\n", (event.type == EVENT_JOY_BUTTON_DOWN) ? "DOWN" : "UP"); - l->Info(" button = %d\n", event.joyButton.button); + l->Trace("EVENT_JOY_BUTTON_%s:\n", (event.type == EVENT_JOY_BUTTON_DOWN) ? "DOWN" : "UP"); + l->Trace(" button = %d\n", event.joyButton.button); break; case EVENT_ACTIVE: - l->Info("EVENT_ACTIVE:\n"); - l->Info(" flags = 0x%x\n", event.active.flags); - l->Info(" gain = %s\n", event.active.gain ? "true" : "false"); + l->Trace("EVENT_ACTIVE:\n"); + l->Trace(" flags = 0x%x\n", event.active.flags); + l->Trace(" gain = %s\n", event.active.gain ? "true" : "false"); break; default: - l->Info("Event type = %d:\n", static_cast(event.type)); + l->Trace("Event type = %d:\n", static_cast(event.type)); break; } - l->Info(" systemEvent = %s\n", event.systemEvent ? "true" : "false"); - l->Info(" rTime = %f\n", event.rTime); - l->Info(" kmodState = %04x\n", event.kmodState); - l->Info(" trackedKeysState = %04x\n", event.trackedKeysState); - l->Info(" mousePos = %f, %f\n", event.mousePos.x, event.mousePos.y); - l->Info(" mouseButtonsState = %02x\n", event.mouseButtonsState); + l->Trace(" systemEvent = %s\n", event.systemEvent ? "true" : "false"); + l->Trace(" rTime = %f\n", event.rTime); + l->Trace(" kmodState = %04x\n", event.kmodState); + l->Trace(" trackedKeysState = %04x\n", event.trackedKeysState); + l->Trace(" mousePos = %f, %f\n", event.mousePos.x, event.mousePos.y); + l->Trace(" mouseButtonsState = %02x\n", event.mouseButtonsState); } // By default, pass on all events @@ -1219,8 +1219,8 @@ void CApplication::ResumeSimulation() { m_simulationSuspended = false; - GetCurrentTimeStamp(m_baseTimeStamp); - CopyTimeStamp(m_curTimeStamp, m_baseTimeStamp); + GetSystemUtils()->GetCurrentTimeStamp(m_baseTimeStamp); + GetSystemUtils()->CopyTimeStamp(m_curTimeStamp, m_baseTimeStamp); m_realAbsTimeBase = m_realAbsTime; m_absTimeBase = m_exactAbsTime; @@ -1236,7 +1236,7 @@ void CApplication::SetSimulationSpeed(float speed) { m_simulationSpeed = speed; - GetCurrentTimeStamp(m_baseTimeStamp); + GetSystemUtils()->GetCurrentTimeStamp(m_baseTimeStamp); m_realAbsTimeBase = m_realAbsTime; m_absTimeBase = m_exactAbsTime; @@ -1248,18 +1248,31 @@ Event CApplication::CreateUpdateEvent() if (m_simulationSuspended) return Event(EVENT_NULL); - CopyTimeStamp(m_lastTimeStamp, m_curTimeStamp); - GetCurrentTimeStamp(m_curTimeStamp); + GetSystemUtils()->CopyTimeStamp(m_lastTimeStamp, m_curTimeStamp); + GetSystemUtils()->GetCurrentTimeStamp(m_curTimeStamp); - long long absDiff = TimeStampExactDiff(m_baseTimeStamp, m_curTimeStamp); - m_realAbsTime = m_realAbsTimeBase + absDiff; - // m_baseTimeStamp is updated on simulation speed change, so this is OK - m_exactAbsTime = m_absTimeBase + m_simulationSpeed * absDiff; - m_absTime = (m_absTimeBase + m_simulationSpeed * absDiff) / 1e9f; + long long absDiff = GetSystemUtils()->TimeStampExactDiff(m_baseTimeStamp, m_curTimeStamp); + long long newRealAbsTime = m_realAbsTimeBase + absDiff; + long long newRealRelTime = GetSystemUtils()->TimeStampExactDiff(m_lastTimeStamp, m_curTimeStamp); - m_realRelTime = TimeStampExactDiff(m_lastTimeStamp, m_curTimeStamp); - m_exactRelTime = m_simulationSpeed * m_realRelTime; - m_relTime = (m_simulationSpeed * m_realRelTime) / 1e9f; + if (newRealAbsTime < m_realAbsTime || newRealRelTime < 0) + { + GetLogger()->Error("Fatal error: got negative system counter difference!\n"); + GetLogger()->Error("This should never happen. Please report this error.\n"); + m_eventQueue->AddEvent(Event(EVENT_QUIT)); + return Event(EVENT_NULL); + } + else + { + m_realAbsTime = newRealAbsTime; + // m_baseTimeStamp is updated on simulation speed change, so this is OK + m_exactAbsTime = m_absTimeBase + m_simulationSpeed * absDiff; + m_absTime = (m_absTimeBase + m_simulationSpeed * absDiff) / 1e9f; + + m_realRelTime = newRealRelTime; + m_exactRelTime = m_simulationSpeed * m_realRelTime; + m_relTime = (m_simulationSpeed * m_realRelTime) / 1e9f; + } Event frameEvent(EVENT_FRAME); frameEvent.systemEvent = true; @@ -1651,12 +1664,12 @@ bool CApplication::GetLowCPU() void CApplication::StartPerformanceCounter(PerformanceCounter counter) { - GetCurrentTimeStamp(m_performanceCounters[counter][0]); + GetSystemUtils()->GetCurrentTimeStamp(m_performanceCounters[counter][0]); } void CApplication::StopPerformanceCounter(PerformanceCounter counter) { - GetCurrentTimeStamp(m_performanceCounters[counter][1]); + GetSystemUtils()->GetCurrentTimeStamp(m_performanceCounters[counter][1]); } float CApplication::GetPerformanceCounterData(PerformanceCounter counter) @@ -1675,13 +1688,13 @@ void CApplication::ResetPerformanceCounters() void CApplication::UpdatePerformanceCountersData() { - long long sum = TimeStampExactDiff(m_performanceCounters[PCNT_ALL][0], - m_performanceCounters[PCNT_ALL][1]); + long long sum = GetSystemUtils()->TimeStampExactDiff(m_performanceCounters[PCNT_ALL][0], + m_performanceCounters[PCNT_ALL][1]); for (int i = 0; i < PCNT_MAX; ++i) { - long long diff = TimeStampExactDiff(m_performanceCounters[i][0], - m_performanceCounters[i][1]); + long long diff = GetSystemUtils()->TimeStampExactDiff(m_performanceCounters[i][0], + m_performanceCounters[i][1]); m_performanceCountersData[static_cast(i)] = static_cast(diff) / static_cast(sum); diff --git a/src/app/app.h b/src/app/app.h index 71a3527..d2561e7 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -352,7 +352,7 @@ protected: //! If applicable, creates a virtual event to match the changed state as of new event Event CreateVirtualEvent(const Event& sourceEvent); //! Prepares a simulation update event - Event CreateUpdateEvent(); + TEST_VIRTUAL Event CreateUpdateEvent(); //! Handles some incoming events bool ProcessEvent(const Event& event); //! Renders the image in window diff --git a/src/app/main.cpp b/src/app/main.cpp index 0622370..edb5828 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -76,40 +76,46 @@ extern "C" int SDL_MAIN_FUNC(int argc, char *argv[]) { - CLogger logger; // Create the logger + CLogger logger; // single istance of logger - InitializeRestext(); // Initialize translation strings + InitializeRestext(); // init static translation strings + + CSystemUtils* systemUtils = CSystemUtils::Create(); // platform-specific utils + systemUtils->Init(); logger.Info("Colobot starting\n"); - CApplication app; // single instance of the application + CApplication* app = new CApplication(); // single instance of the application - ParseArgsStatus status = app.ParseArguments(argc, argv); + ParseArgsStatus status = app->ParseArguments(argc, argv); if (status == PARSE_ARGS_FAIL) { - SystemDialog(SDT_ERROR, "COLOBOT - Fatal Error", "Invalid commandline arguments!\n"); - return app.GetExitCode(); + systemUtils->SystemDialog(SDT_ERROR, "COLOBOT - Fatal Error", "Invalid commandline arguments!\n"); + return app->GetExitCode(); } else if (status == PARSE_ARGS_HELP) { - return app.GetExitCode(); + return app->GetExitCode(); } int code = 0; - if (! app.Create()) + if (! app->Create()) { - app.Destroy(); // ensure a clean exit - code = app.GetExitCode(); - if ( code != 0 && !app.GetErrorMessage().empty() ) + app->Destroy(); // ensure a clean exit + code = app->GetExitCode(); + if ( code != 0 && !app->GetErrorMessage().empty() ) { - SystemDialog(SDT_ERROR, "COLOBOT - Fatal Error", app.GetErrorMessage()); + systemUtils->SystemDialog(SDT_ERROR, "COLOBOT - Fatal Error", app->GetErrorMessage()); } logger.Info("Didn't run main loop. Exiting with code %d\n", code); return code; } - code = app.Run(); + code = app->Run(); + + delete app; + delete systemUtils; logger.Info("Exiting with code %d\n", code); return code; diff --git a/src/app/system.cpp b/src/app/system.cpp index 73614aa..6927af8 100644 --- a/src/app/system.cpp +++ b/src/app/system.cpp @@ -22,75 +22,142 @@ #if defined(PLATFORM_WINDOWS) -#include "app/system_windows.h" - + #include "app/system_windows.h" #elif defined(PLATFORM_LINUX) -#include "app/system_linux.h" - + #include "app/system_linux.h" #else -#include "app/system_other.h" - + #include "app/system_other.h" #endif - #include +#include + + +template<> +CSystemUtils* CSingleton::m_instance = nullptr; -/** - * Displays a system dialog with info, error, question etc. message. - * - * \param type type of dialog - * \param message text of message (in UTF-8) - * \param title dialog title (in UTF-8) - * \returns result (which button was clicked) - */ -SystemDialogResult SystemDialog(SystemDialogType type, const std::string& title, const std::string& message) +CSystemUtils::CSystemUtils() { +} + +CSystemUtils* CSystemUtils::Create() +{ + assert(m_instance == nullptr); #if defined(PLATFORM_WINDOWS) - return SystemDialog_Windows(type, title, message); + m_instance = new CSystemUtilsWindows(); #elif defined(PLATFORM_LINUX) - return SystemDialog_Linux(type, title, message); + m_instance = new CSystemUtilsLinux(); #else - return SystemDialog_Other(type, title, message); + m_instance = new CSystemUtilsOther(); #endif + return m_instance; } -SystemTimeStamp* CreateTimeStamp() +SystemDialogResult CSystemUtils::ConsoleSystemDialog(SystemDialogType type, const std::string& title, const std::string& message) { - return new SystemTimeStamp(); + switch (type) + { + case SDT_INFO: + std::cout << "INFO: "; + break; + case SDT_WARNING: + std::cout << "WARNING:"; + break; + case SDT_ERROR: + std::cout << "ERROR: "; + break; + case SDT_YES_NO: + case SDT_OK_CANCEL: + std::cout << "QUESTION: "; + break; + } + + std::cout << message << std::endl; + + std::string line; + + SystemDialogResult result = SDR_OK; + + bool done = false; + while (!done) + { + switch (type) + { + case SDT_INFO: + case SDT_WARNING: + case SDT_ERROR: + std::cout << "Press ENTER to continue"; + break; + + case SDT_YES_NO: + std::cout << "Type 'Y' for Yes or 'N' for No"; + break; + + case SDT_OK_CANCEL: + std::cout << "Type 'O' for OK or 'C' for Cancel"; + break; + } + + std::getline(std::cin, line); + + switch (type) + { + case SDT_INFO: + case SDT_WARNING: + case SDT_ERROR: + done = true; + break; + + case SDT_YES_NO: + if (line == "Y" || line == "y") + { + result = SDR_YES; + done = true; + } + else if (line == "N" || line == "n") + { + result = SDR_NO; + done = true; + } + break; + + case SDT_OK_CANCEL: + if (line == "O" || line == "o") + { + done = true; + result = SDR_OK; + } + else if (line == "C" || line == "c") + { + done = true; + result = SDR_CANCEL; + } + break; + } + } + + return result; } -void DestroyTimeStamp(SystemTimeStamp *stamp) +SystemTimeStamp* CSystemUtils::CreateTimeStamp() { - delete stamp; + return new SystemTimeStamp(); } -void CopyTimeStamp(SystemTimeStamp *dst, SystemTimeStamp *src) +void CSystemUtils::DestroyTimeStamp(SystemTimeStamp *stamp) { - *dst = *src; + delete stamp; } -void GetCurrentTimeStamp(SystemTimeStamp *stamp) +void CSystemUtils::CopyTimeStamp(SystemTimeStamp *dst, SystemTimeStamp *src) { -#if defined(PLATFORM_WINDOWS) - GetCurrentTimeStamp_Windows(stamp); -#elif defined(PLATFORM_LINUX) - GetCurrentTimeStamp_Linux(stamp); -#else - GetCurrentTimeStamp_Other(stamp); -#endif + *dst = *src; } -float GetTimeStampResolution(SystemTimeUnit unit) +float CSystemUtils::GetTimeStampResolution(SystemTimeUnit unit) { - unsigned long long exact = 0; -#if defined(PLATFORM_WINDOWS) - exact = GetTimeStampExactResolution_Windows(); -#elif defined(PLATFORM_LINUX) - exact = GetTimeStampExactResolution_Linux(); -#else - exact = GetTimeStampExactResolution_Other(); -#endif + unsigned long long exact = GetTimeStampExactResolution(); float result = 0.0f; if (unit == STU_SEC) result = exact * 1e-9; @@ -100,30 +167,14 @@ float GetTimeStampResolution(SystemTimeUnit unit) result = exact * 1e-3; else assert(false); + return result; } -long long GetTimeStampExactResolution() +float CSystemUtils::TimeStampDiff(SystemTimeStamp *before, SystemTimeStamp *after, SystemTimeUnit unit) { -#if defined(PLATFORM_WINDOWS) - return GetTimeStampExactResolution_Windows(); -#elif defined(PLATFORM_LINUX) - return GetTimeStampExactResolution_Linux(); -#else - return GetTimeStampExactResolution_Other(); -#endif -} + long long exact = TimeStampExactDiff(before, after); -float TimeStampDiff(SystemTimeStamp *before, SystemTimeStamp *after, SystemTimeUnit unit) -{ - long long exact = 0; -#if defined(PLATFORM_WINDOWS) - exact = TimeStampExactDiff_Windows(before, after); -#elif defined(PLATFORM_LINUX) - exact = TimeStampExactDiff_Linux(before, after); -#else - exact = TimeStampExactDiff_Other(before, after); -#endif float result = 0.0f; if (unit == STU_SEC) result = exact * 1e-9; @@ -133,16 +184,6 @@ float TimeStampDiff(SystemTimeStamp *before, SystemTimeStamp *after, SystemTimeU result = exact * 1e-3; else assert(false); - return result; -} -long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after) -{ -#if defined(PLATFORM_WINDOWS) - return TimeStampExactDiff_Windows(before, after); -#elif defined(PLATFORM_LINUX) - return TimeStampExactDiff_Linux(before, after); -#else - return TimeStampExactDiff_Other(before, after); -#endif + return result; } diff --git a/src/app/system.h b/src/app/system.h index e216842..278a4bf 100644 --- a/src/app/system.h +++ b/src/app/system.h @@ -22,12 +22,10 @@ #pragma once +#include "common/singleton.h" #include - -/* Dialog utils */ - /** * \enum SystemDialogType * \brief Type of system dialog @@ -60,12 +58,10 @@ enum SystemDialogResult SDR_NO }; -//! Displays a system dialog -SystemDialogResult SystemDialog(SystemDialogType, const std::string &title, const std::string &message); - - -/* Time utils */ - +/** + * \enum SystemTimeUnit + * \brief Time unit + */ enum SystemTimeUnit { //! seconds @@ -76,33 +72,67 @@ enum SystemTimeUnit STU_USEC }; -/* Forward declaration of time stamp struct - * SystemTimeStamp should be used in a pointer context. - * The implementation details are hidden because of platform dependence. */ +/* + * Forward declaration of time stamp struct + * SystemTimeStamp should only be used in a pointer context. + * The implementation details are hidden because of platform dependence. + */ struct SystemTimeStamp; -//! Creates a new time stamp object -SystemTimeStamp* CreateTimeStamp(); +/** + * \class CSystemUtils + * \brief Platform-specific utils + * + * This class provides system-specific utilities like displaying user dialogs and + * querying system timers for exact timestamps. + */ +class CSystemUtils : public CSingleton +{ +protected: + CSystemUtils(); + +public: + //! Creates system utils for specific platform + static CSystemUtils* Create(); + + //! Performs platform-specific initialization + virtual void Init() = 0; + + //! Displays a system dialog + virtual SystemDialogResult SystemDialog(SystemDialogType, const std::string &title, const std::string &message) = 0; -//! Destroys a time stamp object -void DestroyTimeStamp(SystemTimeStamp *stamp); + //! Displays a fallback system dialog using console + TEST_VIRTUAL SystemDialogResult ConsoleSystemDialog(SystemDialogType type, const std::string& title, const std::string& message); -//! Copies the time stamp from \a src to \a dst -void CopyTimeStamp(SystemTimeStamp *dst, SystemTimeStamp *src); + //! Creates a new time stamp object + TEST_VIRTUAL SystemTimeStamp* CreateTimeStamp(); -//! Returns a time stamp associated with current time -void GetCurrentTimeStamp(SystemTimeStamp *stamp); + //! Destroys a time stamp object + TEST_VIRTUAL void DestroyTimeStamp(SystemTimeStamp *stamp); -//! Returns the platform's expected time stamp resolution -float GetTimeStampResolution(SystemTimeUnit unit = STU_SEC); + //! Copies the time stamp from \a src to \a dst + TEST_VIRTUAL void CopyTimeStamp(SystemTimeStamp *dst, SystemTimeStamp *src); -//! Returns the platform's exact (in nanosecond units) expected time stamp resolution -long long GetTimeStampExactResolution(); + //! Returns a time stamp associated with current time + virtual void GetCurrentTimeStamp(SystemTimeStamp *stamp) = 0; -//! Returns a difference between two timestamps in given time unit -/** The difference is \a after - \a before. */ -float TimeStampDiff(SystemTimeStamp *before, SystemTimeStamp *after, SystemTimeUnit unit = STU_SEC); + //! Returns the platform's expected time stamp resolution + TEST_VIRTUAL float GetTimeStampResolution(SystemTimeUnit unit = STU_SEC); -//! Returns the exact (in nanosecond units) difference between two timestamps -/** The difference is \a after - \a before. */ -long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after); + //! Returns the platform's exact (in nanosecond units) expected time stamp resolution + virtual long long GetTimeStampExactResolution() = 0; + + //! Returns a difference between two timestamps in given time unit + /** The difference is \a after - \a before. */ + TEST_VIRTUAL float TimeStampDiff(SystemTimeStamp *before, SystemTimeStamp *after, SystemTimeUnit unit = STU_SEC); + + //! Returns the exact (in nanosecond units) difference between two timestamps + /** The difference is \a after - \a before. */ + virtual long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after) = 0; +}; + +//! Global function to get CSystemUtils instance +inline CSystemUtils* GetSystemUtils() +{ + return CSystemUtils::GetInstancePointer(); +} diff --git a/src/app/system_linux.cpp b/src/app/system_linux.cpp index cd785f8..619909d 100644 --- a/src/app/system_linux.cpp +++ b/src/app/system_linux.cpp @@ -17,11 +17,28 @@ #include "app/system_linux.h" +#include "common/logger.h" + #include -SystemDialogResult SystemDialog_Linux(SystemDialogType type, const std::string& title, const std::string& message) +void CSystemUtilsLinux::Init() { + m_zenityAvailable = true; + if (system("zenity --version") != 0) + { + m_zenityAvailable = false; + GetLogger()->Warn("Zenity not available, will fallback to console users dialogs.\n"); + } +} + +SystemDialogResult CSystemUtilsLinux::SystemDialog(SystemDialogType type, const std::string& title, const std::string& message) +{ + if (!m_zenityAvailable) + { + return ConsoleSystemDialog(type, title, message); + } + std::string options = ""; switch (type) { @@ -62,17 +79,17 @@ SystemDialogResult SystemDialog_Linux(SystemDialogType type, const std::string& return result; } -void GetCurrentTimeStamp_Linux(SystemTimeStamp *stamp) +void CSystemUtilsLinux::GetCurrentTimeStamp(SystemTimeStamp *stamp) { clock_gettime(CLOCK_MONOTONIC_RAW, &stamp->clockTime); } -long long GetTimeStampExactResolution_Linux() +long long CSystemUtilsLinux::GetTimeStampExactResolution() { return 1ll; } -long long TimeStampExactDiff_Linux(SystemTimeStamp *before, SystemTimeStamp *after) +long long CSystemUtilsLinux::TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after) { return (after->clockTime.tv_nsec - before->clockTime.tv_nsec) + (after->clockTime.tv_sec - before->clockTime.tv_sec) * 1000000000ll; diff --git a/src/app/system_linux.h b/src/app/system_linux.h index bc07c31..ba0d8cd 100644 --- a/src/app/system_linux.h +++ b/src/app/system_linux.h @@ -35,9 +35,17 @@ struct SystemTimeStamp } }; +class CSystemUtilsLinux : public CSystemUtils +{ +public: + virtual void Init() override; + + virtual SystemDialogResult SystemDialog(SystemDialogType type, const std::string& title, const std::string& message) override; -SystemDialogResult SystemDialog_Linux(SystemDialogType type, const std::string& title, const std::string& message); + virtual void GetCurrentTimeStamp(SystemTimeStamp *stamp) override; + virtual long long GetTimeStampExactResolution() override; + virtual long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after) override; -void GetCurrentTimeStamp_Linux(SystemTimeStamp *stamp); -long long GetTimeStampExactResolution_Linux(); -long long TimeStampExactDiff_Linux(SystemTimeStamp *before, SystemTimeStamp *after); +private: + bool m_zenityAvailable; +}; diff --git a/src/app/system_other.cpp b/src/app/system_other.cpp index 006bf6d..9fc1f95 100644 --- a/src/app/system_other.cpp +++ b/src/app/system_other.cpp @@ -18,105 +18,22 @@ #include "app/system_other.h" -SystemDialogResult SystemDialog_Other(SystemDialogType type, const std::string& title, const std::string& message) +SystemDialogResult CSystemUtilsOther::SystemDialog(SystemDialogType type, const std::string& title, const std::string& message) { - switch (type) - { - case SDT_INFO: - std::cout << "INFO: "; - break; - case SDT_WARNING: - std::cout << "WARNING:"; - break; - case SDT_ERROR: - std::cout << "ERROR: "; - break; - case SDT_YES_NO: - case SDT_OK_CANCEL: - std::cout << "QUESTION: "; - break; - } - - std::cout << message << std::endl; - - std::string line; - - SystemDialogResult result = SDR_OK; - - bool done = false; - while (!done) - { - switch (type) - { - case SDT_INFO: - case SDT_WARNING: - case SDT_ERROR: - std::cout << "Press ENTER to continue"; - break; - - case SDT_YES_NO: - std::cout << "Type 'Y' for Yes or 'N' for No"; - break; - - case SDT_OK_CANCEL: - std::cout << "Type 'O' for OK or 'C' for Cancel"; - break; - } - - std::getline(std::cin, line); - - switch (type) - { - case SDT_INFO: - case SDT_WARNING: - case SDT_ERROR: - done = true; - break; - - case SDT_YES_NO: - if (line == "Y" || line == "y") - { - result = SDR_YES; - done = true; - } - else if (line == "N" || line == "n") - { - result = SDR_NO; - done = true; - } - break; - - case SDT_OK_CANCEL: - if (line == "O" || line == "o") - { - done = true; - result = SDR_OK; - } - else if (line == "C" || line == "c") - { - done = true; - result = SDR_CANCEL; - } - break; - } - } - - return result; + return ConsoleSystemDialog(type, title, message); } - - -void GetCurrentTimeStamp_Other(SystemTimeStamp *stamp) +void CSystemUtilsOther::GetCurrentTimeStamp(SystemTimeStamp* stamp) { stamp->sdlTicks = SDL_GetTicks(); } -long long GetTimeStampExactResolution_Other() +long long int CSystemUtilsOther::GetTimeStampExactResolution() { return 1000000ll; } -long long TimeStampExactDiff_Other(SystemTimeStamp *before, SystemTimeStamp *after) +long long int CSystemUtilsOther::TimeStampExactDiff(SystemTimeStamp* before, SystemTimeStamp* after) const { return (after->sdlTicks - before->sdlTicks) * 1000000ll; } diff --git a/src/app/system_other.h b/src/app/system_other.h index aee3536..bf16c80 100644 --- a/src/app/system_other.h +++ b/src/app/system_other.h @@ -37,9 +37,12 @@ struct SystemTimeStamp } }; +class CSystemUtilsOther : public CSystemUtils +{ +public: + virtual SystemDialogResult SystemDialog(SystemDialogType type, const std::string& title, const std::string& message) override; -SystemDialogResult SystemDialog_Other(SystemDialogType type, const std::string& title, const std::string& message); - -void GetCurrentTimeStamp_Other(SystemTimeStamp *stamp); -long long GetTimeStampExactResolution_Other(); -long long TimeStampExactDiff_Other(SystemTimeStamp *before, SystemTimeStamp *after); + virtual void GetCurrentTimeStamp(SystemTimeStamp *stamp) override; + virtual long long GetTimeStampExactResolution() override; + virtual long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after) override; +}; diff --git a/src/app/system_windows.cpp b/src/app/system_windows.cpp index 34fa57e..780afef 100644 --- a/src/app/system_windows.cpp +++ b/src/app/system_windows.cpp @@ -17,30 +17,25 @@ #include "app/system_windows.h" +#include "common/logger.h" + +#include -// Convert a wide Unicode string to an UTF8 string -std::string UTF8_Encode_Windows(const std::wstring &wstr) -{ - int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], static_cast(wstr.size()), NULL, 0, NULL, NULL); - std::string strTo(size_needed, 0); - WideCharToMultiByte(CP_UTF8, 0, &wstr[0], static_cast(wstr.size()), &strTo[0], size_needed, NULL, NULL); - return strTo; -} -// Convert an UTF8 string to a wide Unicode String -std::wstring UTF8_Decode_Windows(const std::string &str) +void CSystemUtilsWindows::Init() { - int size_needed = MultiByteToWideChar(CP_UTF8, 0, &str[0], static_cast(str.size()), NULL, 0); - std::wstring wstrTo(size_needed, 0); - MultiByteToWideChar(CP_UTF8, 0, &str[0], static_cast(str.size()), &wstrTo[0], size_needed); - return wstrTo; + LARGE_INTEGER freq; + QueryPerformanceFrequency(&freq); + m_counterFrequency = freq.QuadPart; + + assert(m_counterFrequency != 0); } -SystemDialogResult SystemDialog_Windows(SystemDialogType type, const std::string& title, const std::string& message) +SystemDialogResult CSystemUtilsWindows::SystemDialog(SystemDialogType type, const std::string& title, const std::string& message) { unsigned int windowsType = 0; - std::wstring windowsMessage = UTF8_Decode_Windows(message); - std::wstring windowsTitle = UTF8_Decode_Windows(title); + std::wstring windowsMessage = UTF8_Decode(message); + std::wstring windowsTitle = UTF8_Decode(title); switch (type) { @@ -79,20 +74,39 @@ SystemDialogResult SystemDialog_Windows(SystemDialogType type, const std::string return SDR_OK; } +void CSystemUtilsWindows::GetCurrentTimeStamp(SystemTimeStamp* stamp) +{ + LARGE_INTEGER value; + QueryPerformanceCounter(&value); + stamp->counterValue = value.QuadPart; +} + +long long int CSystemUtilsWindows::GetTimeStampExactResolution() +{ + return 1000000000ll / m_counterFrequency; +} -void GetCurrentTimeStamp_Windows(SystemTimeStamp *stamp) +long long int CSystemUtilsWindows::TimeStampExactDiff(SystemTimeStamp* before, SystemTimeStamp* after) { - GetSystemTimeAsFileTime(&stamp->fileTime); + float floatValue = static_cast(after->counterValue - before->counterValue) * (1e9 / static_cast(m_counterFrequency)); + return static_cast(floatValue); } -long long GetTimeStampExactResolution_Windows() +//! Converts a wide Unicode string to an UTF8 string +std::string CSystemUtilsWindows::UTF8_Encode(const std::wstring& wstr) { - return 100ll; + int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], static_cast(wstr.size()), NULL, 0, NULL, NULL); + std::string strTo(size_needed, 0); + WideCharToMultiByte(CP_UTF8, 0, &wstr[0], static_cast(wstr.size()), &strTo[0], size_needed, NULL, NULL); + return strTo; } -long long TimeStampExactDiff_Windows(SystemTimeStamp *before, SystemTimeStamp *after) +//! Converts an UTF8 string to a wide Unicode String +std::wstring CSystemUtilsWindows::UTF8_Decode(const std::string& str) { - long long tH = (1ll << 32) * (after->fileTime.dwHighDateTime - before->fileTime.dwHighDateTime); - long long tL = after->fileTime.dwLowDateTime - before->fileTime.dwLowDateTime; - return (tH + tL) * 100ll; + int size_needed = MultiByteToWideChar(CP_UTF8, 0, &str[0], static_cast(str.size()), NULL, 0); + std::wstring wstrTo(size_needed, 0); + MultiByteToWideChar(CP_UTF8, 0, &str[0], static_cast(str.size()), &wstrTo[0], size_needed); + return wstrTo; + } diff --git a/src/app/system_windows.h b/src/app/system_windows.h index 804d064..e367b92 100644 --- a/src/app/system_windows.h +++ b/src/app/system_windows.h @@ -22,23 +22,32 @@ #include "app/system.h" -#include - struct SystemTimeStamp { - FILETIME fileTime; + long long counterValue; SystemTimeStamp() { - fileTime.dwHighDateTime = fileTime.dwLowDateTime = 0; + counterValue = 0; } }; -std::string UTF8_Encode_Windows(const std::wstring &wstr); -std::wstring UTF8_Decode_Windows(const std::string &str); -SystemDialogResult SystemDialog_Windows(SystemDialogType type, const std::string& title, const std::string& message); +class CSystemUtilsWindows : public CSystemUtils +{ +public: + virtual void Init() override; + + virtual SystemDialogResult SystemDialog(SystemDialogType type, const std::string& title, const std::string& message) override; -void GetCurrentTimeStamp_Windows(SystemTimeStamp *stamp); -long long GetTimeStampExactResolution_Windows(); -long long TimeStampExactDiff_Windows(SystemTimeStamp *before, SystemTimeStamp *after); + virtual void GetCurrentTimeStamp(SystemTimeStamp *stamp) override; + virtual long long GetTimeStampExactResolution() override; + virtual long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after) override; + +private: + std::string UTF8_Encode(const std::wstring &wstr); + std::wstring UTF8_Decode(const std::string &str); + +protected: + long long m_counterFrequency; +}; diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index d24a3bd..e2ef569 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -148,8 +148,8 @@ CEngine::CEngine(CApplication *app) m_mouseType = ENG_MOUSE_NORM; m_fpsCounter = 0; - m_lastFrameTime = CreateTimeStamp(); - m_currentFrameTime = CreateTimeStamp(); + m_lastFrameTime = GetSystemUtils()->CreateTimeStamp(); + m_currentFrameTime = GetSystemUtils()->CreateTimeStamp(); m_defaultTexParams.format = TEX_IMG_AUTO; m_defaultTexParams.mipmap = true; @@ -176,9 +176,9 @@ CEngine::~CEngine() m_planet = nullptr; m_terrain = nullptr; - DestroyTimeStamp(m_lastFrameTime); + GetSystemUtils()->DestroyTimeStamp(m_lastFrameTime); m_lastFrameTime = nullptr; - DestroyTimeStamp(m_currentFrameTime); + GetSystemUtils()->DestroyTimeStamp(m_currentFrameTime); m_currentFrameTime = nullptr; } @@ -279,8 +279,8 @@ bool CEngine::Create() params.mipmap = false; m_miceTexture = LoadTexture("mouse.png", params); - GetCurrentTimeStamp(m_currentFrameTime); - GetCurrentTimeStamp(m_lastFrameTime); + GetSystemUtils()->GetCurrentTimeStamp(m_currentFrameTime); + GetSystemUtils()->GetCurrentTimeStamp(m_lastFrameTime); return true; } @@ -336,11 +336,11 @@ void CEngine::FrameUpdate() { m_fpsCounter++; - GetCurrentTimeStamp(m_currentFrameTime); - float diff = TimeStampDiff(m_lastFrameTime, m_currentFrameTime, STU_SEC); + GetSystemUtils()->GetCurrentTimeStamp(m_currentFrameTime); + float diff = GetSystemUtils()->TimeStampDiff(m_lastFrameTime, m_currentFrameTime, STU_SEC); if (diff > 1.0f) { - CopyTimeStamp(m_lastFrameTime, m_currentFrameTime); + GetSystemUtils()->CopyTimeStamp(m_lastFrameTime, m_currentFrameTime); m_fps = m_fpsCounter / diff; m_fpsCounter = 0; diff --git a/test/envs/opengl/CMakeLists.txt b/test/envs/opengl/CMakeLists.txt index d6c3a37..0bcb43d 100644 --- a/test/envs/opengl/CMakeLists.txt +++ b/test/envs/opengl/CMakeLists.txt @@ -3,9 +3,9 @@ set(SRC_DIR ${colobot_SOURCE_DIR}/src) configure_file(${SRC_DIR}/common/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/common/config.h) # Platform-dependent implementation of system.h -if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") +if (${PLATFORM_WINDOWS}) set(SYSTEM_CPP_MODULE "system_windows.cpp") -elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") +elseif(${PLATFORM_LINUX}) set(SYSTEM_CPP_MODULE "system_linux.cpp") else() set(SYSTEM_CPP_MODULE "system_other.cpp") diff --git a/test/envs/opengl/light_test.cpp b/test/envs/opengl/light_test.cpp index d4635cc..0baf6d3 100644 --- a/test/envs/opengl/light_test.cpp +++ b/test/envs/opengl/light_test.cpp @@ -258,9 +258,9 @@ void Update() { const float TRANS_SPEED = 6.0f; // units / sec - GetCurrentTimeStamp(CURR_TIME); - float timeDiff = TimeStampDiff(PREV_TIME, CURR_TIME, STU_SEC); - CopyTimeStamp(PREV_TIME, CURR_TIME); + GetSystemUtils()->GetCurrentTimeStamp(CURR_TIME); + float timeDiff = GetSystemUtils()->TimeStampDiff(PREV_TIME, CURR_TIME, STU_SEC); + GetSystemUtils()->CopyTimeStamp(PREV_TIME, CURR_TIME); CUBE_ORBIT += timeDiff * (Math::PI / 4.0f); @@ -365,11 +365,11 @@ int SDL_MAIN_FUNC(int argc, char *argv[]) { CLogger logger; - PREV_TIME = CreateTimeStamp(); - CURR_TIME = CreateTimeStamp(); + PREV_TIME = GetSystemUtils()->CreateTimeStamp(); + CURR_TIME = GetSystemUtils()->CreateTimeStamp(); - GetCurrentTimeStamp(PREV_TIME); - GetCurrentTimeStamp(CURR_TIME); + GetSystemUtils()->GetCurrentTimeStamp(PREV_TIME); + GetSystemUtils()->GetCurrentTimeStamp(CURR_TIME); // Without any error checking, for simplicity @@ -459,8 +459,8 @@ int SDL_MAIN_FUNC(int argc, char *argv[]) SDL_Quit(); - DestroyTimeStamp(PREV_TIME); - DestroyTimeStamp(CURR_TIME); + GetSystemUtils()->DestroyTimeStamp(PREV_TIME); + GetSystemUtils()->DestroyTimeStamp(CURR_TIME); return 0; } diff --git a/test/envs/opengl/model_test.cpp b/test/envs/opengl/model_test.cpp index 168eb32..1dda69c 100644 --- a/test/envs/opengl/model_test.cpp +++ b/test/envs/opengl/model_test.cpp @@ -153,9 +153,9 @@ void Update() const float ROT_SPEED = 80.0f * Math::DEG_TO_RAD; // rad / sec const float TRANS_SPEED = 3.0f; // units / sec - GetCurrentTimeStamp(CURR_TIME); - float timeDiff = TimeStampDiff(PREV_TIME, CURR_TIME, STU_SEC); - CopyTimeStamp(PREV_TIME, CURR_TIME); + GetSystemUtils()->GetCurrentTimeStamp(CURR_TIME); + float timeDiff = GetSystemUtils()->TimeStampDiff(PREV_TIME, CURR_TIME, STU_SEC); + GetSystemUtils()->CopyTimeStamp(PREV_TIME, CURR_TIME); if (KEYMAP[K_RotYLeft]) ROTATION.y -= ROT_SPEED * timeDiff; @@ -265,11 +265,11 @@ int SDL_MAIN_FUNC(int argc, char *argv[]) { CLogger logger; - PREV_TIME = CreateTimeStamp(); - CURR_TIME = CreateTimeStamp(); + PREV_TIME = GetSystemUtils()->CreateTimeStamp(); + CURR_TIME = GetSystemUtils()->CreateTimeStamp(); - GetCurrentTimeStamp(PREV_TIME); - GetCurrentTimeStamp(CURR_TIME); + GetSystemUtils()->GetCurrentTimeStamp(PREV_TIME); + GetSystemUtils()->GetCurrentTimeStamp(CURR_TIME); if (argc != 3) { @@ -377,8 +377,8 @@ int SDL_MAIN_FUNC(int argc, char *argv[]) SDL_Quit(); - DestroyTimeStamp(PREV_TIME); - DestroyTimeStamp(CURR_TIME); + GetSystemUtils()->DestroyTimeStamp(PREV_TIME); + GetSystemUtils()->DestroyTimeStamp(CURR_TIME); return 0; } diff --git a/test/envs/opengl/transform_test.cpp b/test/envs/opengl/transform_test.cpp index 02f9d83..1d5ccf1 100644 --- a/test/envs/opengl/transform_test.cpp +++ b/test/envs/opengl/transform_test.cpp @@ -138,9 +138,9 @@ void Update() { const float TRANS_SPEED = 6.0f; // units / sec - GetCurrentTimeStamp(CURR_TIME); - float timeDiff = TimeStampDiff(PREV_TIME, CURR_TIME, STU_SEC); - CopyTimeStamp(PREV_TIME, CURR_TIME); + GetSystemUtils()->GetCurrentTimeStamp(CURR_TIME); + float timeDiff = GetSystemUtils()->TimeStampDiff(PREV_TIME, CURR_TIME, STU_SEC); + GetSystemUtils()->CopyTimeStamp(PREV_TIME, CURR_TIME); Math::Vector incTrans; @@ -243,11 +243,11 @@ int SDL_MAIN_FUNC(int argc, char *argv[]) { CLogger logger; - PREV_TIME = CreateTimeStamp(); - CURR_TIME = CreateTimeStamp(); + PREV_TIME = GetSystemUtils()->CreateTimeStamp(); + CURR_TIME = GetSystemUtils()->CreateTimeStamp(); - GetCurrentTimeStamp(PREV_TIME); - GetCurrentTimeStamp(CURR_TIME); + GetSystemUtils()->GetCurrentTimeStamp(PREV_TIME); + GetSystemUtils()->GetCurrentTimeStamp(CURR_TIME); // Without any error checking, for simplicity @@ -337,8 +337,8 @@ int SDL_MAIN_FUNC(int argc, char *argv[]) SDL_Quit(); - DestroyTimeStamp(PREV_TIME); - DestroyTimeStamp(CURR_TIME); + GetSystemUtils()->DestroyTimeStamp(PREV_TIME); + GetSystemUtils()->DestroyTimeStamp(CURR_TIME); return 0; } diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index f3be01d..3d8a38c 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -16,9 +16,9 @@ endif() configure_file(${SRC_DIR}/common/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/common/config.h) # Platform-dependent implementation of system.h -if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") +if (${PLATFORM_WINDOWS}) set(SYSTEM_CPP_MODULE "system_windows.cpp") -elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") +elseif(${PLATFORM_LINUX}) set(SYSTEM_CPP_MODULE "system_linux.cpp") else() set(SYSTEM_CPP_MODULE "system_other.cpp") @@ -164,17 +164,16 @@ endif() # Platform-dependent tests -if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") - #TODO: set(PLATFORM_TESTS app/system_windows_test.cpp) -elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") +if (${PLATFORM_WINDOWS}) + set(PLATFORM_TESTS app/system_windows_test.cpp) +elseif(${PLATFORM_LINUX}) set(PLATFORM_TESTS app/system_linux_test.cpp) -else() - #TODO: set(PLATFORM_TESTS app/system_other_test.cpp) endif() # Tests set(UT_SOURCES main.cpp +app/app_test.cpp graphics/engine/lightman_test.cpp math/geometry_test.cpp math/matrix_test.cpp diff --git a/test/unit/app/app_test.cpp b/test/unit/app/app_test.cpp new file mode 100644 index 0000000..8c1e899 --- /dev/null +++ b/test/unit/app/app_test.cpp @@ -0,0 +1,320 @@ +#include "app/app.h" + +#if defined(PLATFORM_WINDOWS) + #include "app/system_windows.h" +#elif defined(PLATFORM_LINUX) + #include "app/system_linux.h" +#else + #include "app/system_other.h" +#endif + +#include "app/system_mock.h" + +#include "common/logger.h" + +#include + +using testing::_; +using testing::InSequence; +using testing::Return; + +struct FakeSystemTimeStamp : public SystemTimeStamp +{ + FakeSystemTimeStamp(int uid) : uid(uid), time(0) {} + + int uid; + long long time; +}; + + +class CApplicationWrapper : public CApplication +{ +public: + virtual Event CreateUpdateEvent() override + { + return CApplication::CreateUpdateEvent(); + } +}; + +class ApplicationUT : public testing::Test +{ +protected: + ApplicationUT(); + + virtual void SetUp() override; + virtual void TearDown() override; + + void NextInstant(long long diff); + + SystemTimeStamp* CreateTimeStamp(); + void DestroyTimeStamp(SystemTimeStamp *stamp); + void CopyTimeStamp(SystemTimeStamp *dst, SystemTimeStamp *src); + void GetCurrentTimeStamp(SystemTimeStamp *stamp); + long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after); + + void TestCreateUpdateEvent(long long relTimeExact, long long absTimeExact, + float relTime, float absTime, + long long relTimeReal, long long absTimeReal); + +protected: + CLogger logger; + CApplicationWrapper* app; + CSystemUtilsMock* systemUtils; + +private: + int m_stampUid; + long long m_currentTime; +}; + +ApplicationUT::ApplicationUT() + : m_stampUid(0) + , m_currentTime(0) +{} + +void ApplicationUT::SetUp() +{ + systemUtils = new CSystemUtilsMock(); + + ON_CALL(*systemUtils, CreateTimeStamp()).WillByDefault(Invoke(this, &ApplicationUT::CreateTimeStamp)); + ON_CALL(*systemUtils, DestroyTimeStamp(_)).WillByDefault(Invoke(this, &ApplicationUT::DestroyTimeStamp)); + ON_CALL(*systemUtils, CopyTimeStamp(_, _)).WillByDefault(Invoke(this, &ApplicationUT::CopyTimeStamp)); + ON_CALL(*systemUtils, GetCurrentTimeStamp(_)).WillByDefault(Invoke(this, &ApplicationUT::GetCurrentTimeStamp)); + ON_CALL(*systemUtils, TimeStampExactDiff(_, _)).WillByDefault(Invoke(this, &ApplicationUT::TimeStampExactDiff)); + + EXPECT_CALL(*systemUtils, CreateTimeStamp()).Times(3 + PCNT_MAX*2); + app = new CApplicationWrapper(); +} + +void ApplicationUT::TearDown() +{ + EXPECT_CALL(*systemUtils, DestroyTimeStamp(_)).Times(3 + PCNT_MAX*2); + delete app; + app = nullptr; + + delete systemUtils; + systemUtils = nullptr; +} + +SystemTimeStamp* ApplicationUT::CreateTimeStamp() +{ + return new FakeSystemTimeStamp(++m_stampUid); +} + +void ApplicationUT::DestroyTimeStamp(SystemTimeStamp *stamp) +{ + delete static_cast(stamp); +} + +void ApplicationUT::CopyTimeStamp(SystemTimeStamp *dst, SystemTimeStamp *src) +{ + *static_cast(dst) = *static_cast(src); +} + +void ApplicationUT::GetCurrentTimeStamp(SystemTimeStamp *stamp) +{ + static_cast(stamp)->time = m_currentTime; +} + +long long ApplicationUT::TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after) +{ + return static_cast(after)->time - static_cast(before)->time; +} + +void ApplicationUT::NextInstant(long long diff) +{ + m_currentTime += diff; +} + +void ApplicationUT::TestCreateUpdateEvent(long long relTimeExact, long long absTimeExact, + float relTime, float absTime, + long long relTimeReal, long long absTimeReal) +{ + { + InSequence seq; + EXPECT_CALL(*systemUtils, CopyTimeStamp(_, _)); + EXPECT_CALL(*systemUtils, GetCurrentTimeStamp(_)); + EXPECT_CALL(*systemUtils, TimeStampExactDiff(_, _)).Times(2); + } + + Event event = app->CreateUpdateEvent(); + EXPECT_EQ(EVENT_FRAME, event.type); + EXPECT_FLOAT_EQ(relTime, event.rTime); + EXPECT_FLOAT_EQ(relTime, app->GetRelTime()); + EXPECT_FLOAT_EQ(absTime, app->GetAbsTime()); + EXPECT_EQ(relTimeExact, app->GetExactRelTime()); + EXPECT_EQ(absTimeExact, app->GetExactAbsTime()); + EXPECT_EQ(relTimeReal, app->GetRealRelTime()); + EXPECT_EQ(absTimeReal, app->GetRealAbsTime()); +} + + +TEST_F(ApplicationUT, UpdateEventTimeCalculation_SimulationSuspended) +{ + app->SuspendSimulation(); + Event event = app->CreateUpdateEvent(); + EXPECT_EQ(EVENT_NULL, event.type); +} + +TEST_F(ApplicationUT, UpdateEventTimeCalculation_NormalOperation) +{ + // 1st update + + long long relTimeExact = 1111; + long long absTimeExact = relTimeExact; + float relTime = relTimeExact / 1e9f; + float absTime = absTimeExact / 1e9f; + long long relTimeReal = relTimeExact; + long long absTimeReal = absTimeExact; + + NextInstant(relTimeReal); + + TestCreateUpdateEvent(relTimeExact, absTimeExact, relTime, absTime, relTimeReal, absTimeReal); + + // 2nd update + + relTimeExact = 2222; + absTimeExact += relTimeExact; + relTime = relTimeExact / 1e9f; + absTime = absTimeExact / 1e9f; + relTimeReal = relTimeExact; + absTimeReal = absTimeExact; + + NextInstant(relTimeReal); + + TestCreateUpdateEvent(relTimeExact, absTimeExact, relTime, absTime, relTimeReal, absTimeReal); +} + +TEST_F(ApplicationUT, UpdateEventTimeCalculation_NegativeTimeOperation) +{ + // 1st update + + long long relTimeExact = 2222; + long long absTimeExact = relTimeExact; + float relTime = relTimeExact / 1e9f; + float absTime = absTimeExact / 1e9f; + long long relTimeReal = relTimeExact; + long long absTimeReal = absTimeExact; + + NextInstant(relTimeReal); + + TestCreateUpdateEvent(relTimeExact, absTimeExact, relTime, absTime, relTimeReal, absTimeReal); + + // 2nd update + + NextInstant(-1111); + + { + InSequence seq; + EXPECT_CALL(*systemUtils, CopyTimeStamp(_, _)); + EXPECT_CALL(*systemUtils, GetCurrentTimeStamp(_)); + EXPECT_CALL(*systemUtils, TimeStampExactDiff(_, _)).Times(2); + } + Event event = app->CreateUpdateEvent(); + EXPECT_EQ(EVENT_NULL, event.type); +} + +TEST_F(ApplicationUT, UpdateEventTimeCalculation_ChangingSimulationSpeed) +{ + EXPECT_CALL(*systemUtils, GetCurrentTimeStamp(_)); + app->SetSimulationSpeed(2.0f); + + // 1st update -- speed 2x + + long long relTimeReal = 100; + long long absTimeReal = relTimeReal; + long long relTimeExact = relTimeReal*2; + long long absTimeExact = absTimeReal*2; + float relTime = relTimeExact / 1e9f; + float absTime = absTimeExact / 1e9f; + + NextInstant(relTimeReal); + + TestCreateUpdateEvent(relTimeExact, absTimeExact, relTime, absTime, relTimeReal, absTimeReal); + + // 2nd update -- speed 2x + + relTimeReal = 200; + absTimeReal += relTimeReal; + relTimeExact = relTimeReal*2; + absTimeExact += relTimeReal*2; + relTime = relTimeExact / 1e9f; + absTime = absTimeExact / 1e9f; + + NextInstant(relTimeReal); + + TestCreateUpdateEvent(relTimeExact, absTimeExact, relTime, absTime, relTimeReal, absTimeReal); + + // 3rd update -- speed 4x + EXPECT_CALL(*systemUtils, GetCurrentTimeStamp(_)); + app->SetSimulationSpeed(4.0f); + + relTimeReal = 300; + absTimeReal += relTimeReal; + relTimeExact = relTimeReal*4; + absTimeExact += relTimeReal*4; + relTime = relTimeExact / 1e9f; + absTime = absTimeExact / 1e9f; + + NextInstant(relTimeReal); + + TestCreateUpdateEvent(relTimeExact, absTimeExact, relTime, absTime, relTimeReal, absTimeReal); + + // 4th update -- speed 1x + EXPECT_CALL(*systemUtils, GetCurrentTimeStamp(_)); + app->SetSimulationSpeed(1.0f); + + relTimeReal = 400; + absTimeReal += relTimeReal; + relTimeExact = relTimeReal; + absTimeExact += relTimeReal; + relTime = relTimeExact / 1e9f; + absTime = absTimeExact / 1e9f; + + NextInstant(relTimeReal); + + TestCreateUpdateEvent(relTimeExact, absTimeExact, relTime, absTime, relTimeReal, absTimeReal); +} + +TEST_F(ApplicationUT, UpdateEventTimeCalculation_SuspendingAndResumingSimulation) +{ + // 1st update -- simulation enabled + + long long relTimeReal = 1000; + long long absTimeReal = relTimeReal; + long long relTimeExact = relTimeReal; + long long absTimeExact = absTimeReal; + float relTime = relTimeExact / 1e9f; + float absTime = absTimeExact / 1e9f; + + NextInstant(relTimeReal); + + TestCreateUpdateEvent(relTimeExact, absTimeExact, relTime, absTime, relTimeReal, absTimeReal); + + // 2nd update -- simulation suspended + + app->SuspendSimulation(); + + long long suspensionTime = 5000; + + NextInstant(suspensionTime); + + // 3rd update -- simulation resumed + + { + InSequence seq; + EXPECT_CALL(*systemUtils, GetCurrentTimeStamp(_)); + EXPECT_CALL(*systemUtils, CopyTimeStamp(_, _)); + } + app->ResumeSimulation(); + + relTimeReal = 200; + absTimeReal += relTimeReal; + relTimeExact = relTimeReal; + absTimeExact += relTimeReal; + relTime = relTimeExact / 1e9f; + absTime = absTimeExact / 1e9f; + + NextInstant(relTimeReal); + + TestCreateUpdateEvent(relTimeExact, absTimeExact, relTime, absTime, relTimeReal, absTimeReal); +} diff --git a/test/unit/app/system_linux_test.cpp b/test/unit/app/system_linux_test.cpp index fe89399..b0a05ca 100644 --- a/test/unit/app/system_linux_test.cpp +++ b/test/unit/app/system_linux_test.cpp @@ -3,10 +3,23 @@ #include -TEST(SystemLinuxTest, TimeStampDiff) +class CSystemUtilsLinuxWrapper : public CSystemUtilsLinux { - const long long SEC = 1000000000; +public: + CSystemUtilsLinuxWrapper() {} +}; +class SystemUtilsLinuxUT : public testing::Test +{ +protected: + static const long long SEC = 1000000000; + + CSystemUtilsLinuxWrapper systemUtils; +}; + + +TEST_F(SystemUtilsLinuxUT, TimeStampDiff) +{ SystemTimeStamp before, after; before.clockTime.tv_sec = 1; @@ -15,10 +28,10 @@ TEST(SystemLinuxTest, TimeStampDiff) after.clockTime.tv_sec = 1; after.clockTime.tv_nsec = 900; - long long tDiff = TimeStampExactDiff_Linux(&before, &after); + long long tDiff = systemUtils.TimeStampExactDiff(&before, &after); EXPECT_EQ( 800, tDiff); - tDiff = TimeStampExactDiff_Linux(&after, &before); + tDiff = systemUtils.TimeStampExactDiff(&after, &before); EXPECT_EQ(-800, tDiff); // ------- @@ -29,10 +42,10 @@ TEST(SystemLinuxTest, TimeStampDiff) after.clockTime.tv_sec = 3; after.clockTime.tv_nsec = 500; - tDiff = TimeStampExactDiff_Linux(&before, &after); + tDiff = systemUtils.TimeStampExactDiff(&before, &after); EXPECT_EQ( SEC + 300, tDiff); - tDiff = TimeStampExactDiff_Linux(&after, &before); + tDiff = systemUtils.TimeStampExactDiff(&after, &before); EXPECT_EQ(-SEC - 300, tDiff); // ------- @@ -43,9 +56,9 @@ TEST(SystemLinuxTest, TimeStampDiff) after.clockTime.tv_sec = 4; after.clockTime.tv_nsec = 100; - tDiff = TimeStampExactDiff_Linux(&before, &after); + tDiff = systemUtils.TimeStampExactDiff(&before, &after); EXPECT_EQ( SEC - 100, tDiff); - tDiff = TimeStampExactDiff_Linux(&after, &before); + tDiff = systemUtils.TimeStampExactDiff(&after, &before); EXPECT_EQ(-SEC + 100, tDiff); } diff --git a/test/unit/app/system_mock.h b/test/unit/app/system_mock.h new file mode 100644 index 0000000..470a4e1 --- /dev/null +++ b/test/unit/app/system_mock.h @@ -0,0 +1,48 @@ +#pragma once + +#include "app/system.h" + +#include + +class CSystemUtilsMock : public CSystemUtils +{ +public: + CSystemUtilsMock(bool defaultExpects = false) + { + if (defaultExpects) + SetDefaultExpects(); + } + + virtual ~CSystemUtilsMock() {} + + void SetDefaultExpects() + { + using testing::_; + using testing::Return; + using testing::AnyNumber; + + EXPECT_CALL(*this, CreateTimeStamp()).Times(AnyNumber()).WillRepeatedly(Return(nullptr)); + EXPECT_CALL(*this, DestroyTimeStamp(_)).Times(AnyNumber()); + EXPECT_CALL(*this, CopyTimeStamp(_, _)).Times(AnyNumber()); + EXPECT_CALL(*this, GetCurrentTimeStamp(_)).Times(AnyNumber()); + + EXPECT_CALL(*this, GetTimeStampResolution(_)).Times(AnyNumber()).WillRepeatedly(Return(0.0f)); + EXPECT_CALL(*this, GetTimeStampExactResolution()).Times(AnyNumber()).WillRepeatedly(Return(0ll)); + EXPECT_CALL(*this, TimeStampDiff(_, _, _)).Times(AnyNumber()).WillRepeatedly(Return(0.0f)); + EXPECT_CALL(*this, TimeStampExactDiff(_, _)).Times(AnyNumber()).WillRepeatedly(Return(0ll)); + } + + MOCK_METHOD0(Init, void()); + + MOCK_METHOD3(SystemDialog, SystemDialogResult(SystemDialogType, const std::string &title, const std::string &message)); + MOCK_METHOD3(ConsoleSystemDialog, SystemDialogResult(SystemDialogType type, const std::string& title, const std::string& message)); + + MOCK_METHOD0(CreateTimeStamp, SystemTimeStamp*()); + MOCK_METHOD1(DestroyTimeStamp, void (SystemTimeStamp *stamp)); + MOCK_METHOD2(CopyTimeStamp, void (SystemTimeStamp *dst, SystemTimeStamp *src)); + MOCK_METHOD1(GetCurrentTimeStamp, void (SystemTimeStamp *stamp)); + MOCK_METHOD1(GetTimeStampResolution, float (SystemTimeUnit unit)); + MOCK_METHOD0(GetTimeStampExactResolution, long long()); + MOCK_METHOD3(TimeStampDiff, float(SystemTimeStamp *before, SystemTimeStamp *after, SystemTimeUnit unit)); + MOCK_METHOD2(TimeStampExactDiff, long long(SystemTimeStamp *before, SystemTimeStamp *after)); +}; diff --git a/test/unit/app/system_windows_test.cpp b/test/unit/app/system_windows_test.cpp new file mode 100644 index 0000000..79f8c7f --- /dev/null +++ b/test/unit/app/system_windows_test.cpp @@ -0,0 +1,62 @@ +#include "app/system.h" +#include "app/system_windows.h" + +#include + +class CSystemUtilsWindowsWrapper : public CSystemUtilsWindows +{ +public: + CSystemUtilsWindowsWrapper() {} + + void SetFrequency(long long counterFrequency) + { + m_counterFrequency = counterFrequency; + } +}; + +class SystemUtilsWindowsUT : public testing::Test +{ +protected: + static const long long SEC = 1000000000; + + CSystemUtilsWindowsWrapper systemUtils; +}; + + +TEST_F(SystemUtilsWindowsUT, TimerResolution) +{ + systemUtils.SetFrequency(SEC); + EXPECT_EQ(1u, systemUtils.GetTimeStampExactResolution()); + + systemUtils.SetFrequency(SEC/3); + EXPECT_EQ(3u, systemUtils.GetTimeStampExactResolution()); +} + +TEST_F(SystemUtilsWindowsUT, TimeStampDiff) +{ + systemUtils.SetFrequency(SEC); + + SystemTimeStamp before, after; + + before.counterValue = 100; + after.counterValue = 200; + + long long tDiff = systemUtils.TimeStampExactDiff(&before, &after); + EXPECT_EQ( 100, tDiff); + + tDiff = systemUtils.TimeStampExactDiff(&after, &before); + EXPECT_EQ(-100, tDiff); + + // ------- + + systemUtils.SetFrequency(SEC/3); + + before.counterValue = 200; + after.counterValue = 400; + + tDiff = systemUtils.TimeStampExactDiff(&before, &after); + EXPECT_EQ( 200*3, tDiff); + + tDiff = systemUtils.TimeStampExactDiff(&after, &before); + EXPECT_EQ(-200*3, tDiff); +} diff --git a/test/unit/graphics/engine/lightman_test.cpp b/test/unit/graphics/engine/lightman_test.cpp index c955f0a..e2dc785 100644 --- a/test/unit/graphics/engine/lightman_test.cpp +++ b/test/unit/graphics/engine/lightman_test.cpp @@ -1,5 +1,7 @@ #include "graphics/engine/lightman.h" +#include "app/system_mock.h" + #include "graphics/core/device_mock.h" #include "graphics/engine/engine_mock.h" @@ -15,7 +17,8 @@ class LightManagerUT : public testing::Test { protected: LightManagerUT() - : lightManager(&engine) + : systemUtils(true) + , lightManager(&engine) {} void PrepareLightTesting(int maxLights, Math::Vector eyePos); @@ -25,6 +28,7 @@ protected: Math::Vector pos, EngineObjectType includeType, EngineObjectType excludeType); + CSystemUtilsMock systemUtils; CLightManager lightManager; CEngineMock engine; CDeviceMock device; diff --git a/test/unit/ui/stubs/app_stub.cpp b/test/unit/ui/stubs/app_stub.cpp index 3df7d42..c8e7bc6 100644 --- a/test/unit/ui/stubs/app_stub.cpp +++ b/test/unit/ui/stubs/app_stub.cpp @@ -40,3 +40,8 @@ std::string CApplication::GetDataDirPath() { return ""; } + +Event CApplication::CreateUpdateEvent() +{ + return Event(EVENT_NULL); +} -- cgit v1.2.3-1-g7c22 From 5eb4e10c2bc0866a0e759995e7d8ef5044b843c5 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 24 Mar 2013 16:02:06 +0100 Subject: Reverted "Fix for issue #149" because it was broken again after commit 7ebba6abaa66abda690dcdb87248dfcb0c1dedc6 --- src/ui/maindialog.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 9964ef7..a3670de 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -1849,7 +1849,7 @@ pos.y -= 0.048f; pe->SetEditCap(false); pe->SetHighlightCap(false); pe->SetFontType(Gfx::FONT_COURIER); - pe->SetFontSize(8.0f); + pe->SetFontSize(Gfx::FONT_SIZE_SMALL); pe->ReadText("help/authors.txt");*/ /* #if _DEMO @@ -1862,7 +1862,7 @@ pos.y -= 0.048f; //? pe->SetEditCap(false); //? pe->SetHiliteCap(false); //? pe->SetFontType(Gfx::FONT_COURIER); - //? pe->SetFontSize(8.0f); + //? pe->SetFontSize(Gfx::FONT_SIZE_SMALL); //? pe->ReadText("help/demo.txt"); //? pos.x = 80.0f/640.0f; @@ -1874,13 +1874,13 @@ pos.y -= 0.048f; //? pe->SetEditCap(false); //? pe->SetHiliteCap(false); //? pe->SetFontType(Gfx::FONT_COURIER); - //? pe->SetFontSize(8.0f); + //? pe->SetFontSize(Gfx::FONT_SIZE_SMALL); //? pe->ReadText("help/authors.txt"); #endif */ // TODO: #if !_DEMO pos.x = 40.0f/640.0f; - pos.y = 65.0f/480.0f; + pos.y = 83.0f/480.0f; ddim.x = 246.0f/640.0f; ddim.y = 16.0f/480.0f; GetResource(RES_TEXT, RT_GENERIC_DEV1, name); @@ -1888,14 +1888,14 @@ pos.y -= 0.048f; pl->SetFontType(Gfx::FONT_COURIER); pl->SetFontSize(Gfx::FONT_SIZE_SMALL); - pos.y = 0.0f/480.0f; + pos.y = 13.0f/480.0f; GetResource(RES_TEXT, RT_GENERIC_DEV2, name); pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL2, name); pl->SetFontType(Gfx::FONT_COURIER); pl->SetFontSize(Gfx::FONT_SIZE_SMALL); pos.x = 355.0f/640.0f; - pos.y = 65.0f/480.0f; + pos.y = 83.0f/480.0f; ddim.x = 246.0f/640.0f; ddim.y = 16.0f/480.0f; GetResource(RES_TEXT, RT_GENERIC_EDIT1, name); @@ -1903,7 +1903,7 @@ pos.y -= 0.048f; pl->SetFontType(Gfx::FONT_COURIER); pl->SetFontSize(Gfx::FONT_SIZE_SMALL); - pos.y = 0.0f/480.0f; + pos.y = 13.0f/480.0f; GetResource(RES_TEXT, RT_GENERIC_EDIT2, name); pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL4, name); pl->SetFontType(Gfx::FONT_COURIER); -- cgit v1.2.3-1-g7c22 From 5deb68e698fa9d7edd9125bea2d8c5e9df58cd6d Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 24 Mar 2013 16:35:00 +0100 Subject: Small fix in mission files code --- src/object/robotmain.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 55a9b86..2fde567 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -3836,6 +3836,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_terrainInitTextures = false; m_terrainCreate = false; + m_version = 1; m_retroStyle = false; } -- cgit v1.2.3-1-g7c22 From f4e222248f4959ea82b9e94ec0e21dcecbecac88 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 24 Mar 2013 19:05:20 +0100 Subject: Retro mode now disables possibility of writing and running programs --- src/object/brain.cpp | 26 ++++++++++++++------------ src/object/robotmain.cpp | 4 ++++ src/object/robotmain.h | 4 +++- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/object/brain.cpp b/src/object/brain.cpp index babb38d..1f428b7 100644 --- a/src/object/brain.cpp +++ b/src/object/brain.cpp @@ -1288,18 +1288,20 @@ bool CBrain::CreateInterface(bool bSelect) type == OBJECT_BEE || type == OBJECT_WORM ) // vehicle? { - ddim.x = dim.x*5.1f; - ddim.y = dim.y*2.0f; - pos.x = ox+sx*0.0f; - pos.y = oy+sy*0.0f; - pw->CreateList(pos, ddim, -1, EVENT_OBJECT_PROGLIST, 1.10f); - UpdateScript(pw); - - pos.x = ox+sx*5.2f; - pos.y = oy+sy*1.0f; - pw->CreateButton(pos, dim, 8, EVENT_OBJECT_PROGRUN); - pos.y = oy+sy*0.0f; - pw->CreateButton(pos, dim, 22, EVENT_OBJECT_PROGEDIT); + if (!(CRobotMain::GetInstancePointer()->GetRetroMode())) { + ddim.x = dim.x*5.1f; + ddim.y = dim.y*2.0f; + pos.x = ox+sx*0.0f; + pos.y = oy+sy*0.0f; + pw->CreateList(pos, ddim, -1, EVENT_OBJECT_PROGLIST, 1.10f); + UpdateScript(pw); + + pos.x = ox+sx*5.2f; + pos.y = oy+sy*1.0f; + pw->CreateButton(pos, dim, 8, EVENT_OBJECT_PROGRUN); + pos.y = oy+sy*0.0f; + pw->CreateButton(pos, dim, 22, EVENT_OBJECT_PROGEDIT); + } } if ( type == OBJECT_HUMAN || diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 2fde567..8dedb8c 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -6795,6 +6795,10 @@ const char* CRobotMain::GetFilesDir() return m_dialog->GetFilesDir().c_str(); } +bool CRobotMain::GetRetroMode() +{ + return m_retroStyle; +} //! Change the player's name void CRobotMain::SetGamerName(const char *name) diff --git a/src/object/robotmain.h b/src/object/robotmain.h index 181a1cb..0bcd2dc 100644 --- a/src/object/robotmain.h +++ b/src/object/robotmain.h @@ -304,6 +304,7 @@ public: const char* GetSavegameDir(); const char* GetPublicDir(); const char* GetFilesDir(); + bool GetRetroMode(); void SetGamerName(const char *name); char* GetGamerName(); @@ -447,6 +448,7 @@ protected: int m_delayWriteMessage; int m_movieInfoIndex; + //Level Checker flags bool m_beginObject; bool m_terrainGenerate; bool m_terrainInitTextures; @@ -454,7 +456,7 @@ protected: bool m_terrainCreate; int m_version; // Mission file version - bool m_retroStyle; // Retro style + bool m_retroStyle; // Retro bool m_immediatSatCom; // SatCom immediately? bool m_beginSatCom; // messages SatCom poster? bool m_movieLock; // movie in progress? -- cgit v1.2.3-1-g7c22 From 5810fdd717a0ff0c0b5ceb75581d8443716a3fd0 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 24 Mar 2013 21:31:31 +0100 Subject: In Retro mode, robot's lights always blink. --- src/object/brain.cpp | 2 +- src/object/object.cpp | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/object/brain.cpp b/src/object/brain.cpp index 1f428b7..53f77cf 100644 --- a/src/object/brain.cpp +++ b/src/object/brain.cpp @@ -1288,7 +1288,7 @@ bool CBrain::CreateInterface(bool bSelect) type == OBJECT_BEE || type == OBJECT_WORM ) // vehicle? { - if (!(CRobotMain::GetInstancePointer()->GetRetroMode())) { + if (!(m_main->GetRetroMode())) { ddim.x = dim.x*5.1f; ddim.y = dim.y*2.0f; pos.x = ox+sx*0.0f; diff --git a/src/object/object.cpp b/src/object/object.cpp index d6ac681..a0a3f09 100644 --- a/src/object/object.cpp +++ b/src/object/object.cpp @@ -6980,7 +6980,7 @@ void CObject::CreateSelectParticle() } } - if ( m_bSelect || IsProgram() ) + if ( m_bSelect || IsProgram() || m_main->GetRetroMode() ) { // Creates particles lens for the headlights. if ( m_type == OBJECT_MOBILEfa || @@ -7034,7 +7034,7 @@ void CObject::UpdateSelectParticle() float angle; int i; - if ( !m_bSelect && !IsProgram() ) return; + if ( !m_bSelect && !IsProgram() && !m_main->GetRetroMode() ) return; dim[0].x = 1.0f; dim[1].x = 1.0f; @@ -7157,7 +7157,8 @@ void CObject::UpdateSelectParticle() zoom[2] = 1.0f; zoom[3] = 1.0f; - if ( IsProgram() && // current program? + if ( ( IsProgram() || // current program? + m_main->GetRetroMode() ) && // Retro mode? Math::Mod(m_aTime, 0.7f) < 0.3f ) { zoom[0] = 0.0f; // blinks -- cgit v1.2.3-1-g7c22 From 8f6fbdde646642f44b082dd8c5c5d725f114eadc Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 24 Mar 2013 21:36:28 +0100 Subject: Updated data submodule --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index 6408820..e853f88 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 6408820491281a862b89e0a260cd661b6e603445 +Subproject commit e853f88d5a2bfac363ddf5b227784ad3caae64ac -- cgit v1.2.3-1-g7c22 From 8aba2424bb7f35591e9cb026a6ad39e1f300432e Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Sun, 24 Mar 2013 22:24:04 +0100 Subject: Bugfix DESKTOP option initialisation --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 48a47bb..628b700 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,7 +85,7 @@ option(TESTS "Enable tests" ON) option(CBOT_STATIC "Build CBot as static libary" OFF) # Generate desktop files, manpage, etc. -option(DESKTOP ON) +option(DESKTOP "Generate desktop files, manpages, etc" ON) # Doxygen docs are optional for installation option(INSTALL_DOCS "Install Doxygen-generated documentation" OFF) -- cgit v1.2.3-1-g7c22 From af60e6a695a4adb94bd11522065ff4e34a7d7818 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Mon, 25 Mar 2013 00:42:08 +0100 Subject: Useful script for showing status of data submodule --- tools/git-submodule-status.sh | 90 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100755 tools/git-submodule-status.sh diff --git a/tools/git-submodule-status.sh b/tools/git-submodule-status.sh new file mode 100755 index 0000000..3fb1fd5 --- /dev/null +++ b/tools/git-submodule-status.sh @@ -0,0 +1,90 @@ +#!/bin/bash + +# Tool for showing submodule history vs. associated and currently checked-out commits + +module="data" +tail_count=5 + +branch_name="$(git symbolic-ref HEAD 2>/dev/null)" + +if [ -z "$branch_name" ]; then + display_branch_name="(detached head)" +else + display_branch_name="$branch_name" +fi + +module_branch_name="$(cd $module && git symbolic-ref HEAD 2>/dev/null)" +module_working_commit="$(cd $module && git rev-parse HEAD)" +module_assoc_commit="$(git ls-tree $branch_name $module | awk '{print $3}' -)" + +if [ -z "$module_branch_name" ]; then + module_assoc_branches=($(cd $module && git branch --contains $module_assoc_commit | awk 'NR > 1 { print $1 }')) + if [ ${#module_assoc_branches[@]} -ne 1 ]; then + echo "$module module is in detached head, but referenced commit is in multiple branches" + echo "Sorry, can't help you" + exit 1 + else + module_branch_name="${module_assoc_branches[0]}" + display_module_branch_name="(detached head, detected: $module_branch_name)" + fi +else + display_module_branch_name="$module_branch_name" +fi + +echo -e "Repository branch: \033[32m$display_branch_name\033[0m" +echo -e "$module module branch: \033[32m$display_module_branch_name\033[0m" + +if [ -z "$(cd $module && git rev-list HEAD | grep $module_assoc_commit)" ]; then + echo -e "$module module associated commit: \033[33m$module_assoc_commit\033[0m is not in module history!" + echo "You probably have checked out different branch!" + exit 1 +fi + +echo "" + +i=0 +c=0 +h=1 +(cd $module && git log --format='%H%x01%h%x01%s%x00' $module_branch_name) | while read -d $'\0' info; do + commit=$(echo "$info" | cut -d$'\1' -f1) + short_commit=$(echo "$info" | cut -d$'\1' -f2) + message=$(echo "$info" | cut -d$'\1' -f3) + + if [ $h -eq 1 ]; then + echo -n -e "\033[34m H \033[0m" + else + echo -n " " + fi + + h=0 + + if [ "$commit" == "$module_working_commit" ]; then + echo -n -e "\033[31m * \033[0m" + c=$(($c+1)) + else + echo -n " " + fi + + if [ "$commit" == "$module_assoc_commit" ]; then + echo -n -e "\033[32m x \033[0m" + c=$(($c+1)) + else + echo -n " " + fi + + echo -e "\033[33m$short_commit\033[0m $message" + + if [ $c -eq 2 ]; then + i=$(($i+1)) + if [ $i -gt $tail_count ]; then + echo " ..." + break + fi + fi +done + +echo "" +echo -e "\033[34m H \033[0m -- $module_branch_name HEAD" +echo -e "\033[31m * \033[0m -- checked-out commit" +echo -e "\033[32m x \033[0m -- associated commit" + -- cgit v1.2.3-1-g7c22 From 00a2abd21f66c8bf69a28c4a30cf59a1d621e27c Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Mon, 25 Mar 2013 09:49:42 +0100 Subject: Fixed GCC 4.6 compilation --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 628b700..f58b654 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,7 +55,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") set(CXX11_FLAGS "-std=gnu++11") elseif (GCC_VERSION VERSION_GREATER 4.6 OR GCC_VERSION VERSION_EQUAL 4.6) message(STATUS "Detected GCC version 4.6+") - set(CXX11_FLAGS "-std=c++0x") + set(CXX11_FLAGS "-std=c++0x -Doverride=") else() message(FATAL_ERROR "${PROJECT_NAME} requires GCC 4.6 or greater.") endif() -- cgit v1.2.3-1-g7c22 From 5f1c202a6b35a0b5c102d9ab6b8bf1e730ce5a03 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Mon, 25 Mar 2013 09:59:50 +0100 Subject: Travis change from #148 --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index af27ea3..2750af2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,9 @@ script: mkdir build; cd build; cmake .. -DCMAKE_VERBOSE_MAKEFILE=ON && make all before_install: - git submodule update --init --recursive - sudo add-apt-repository ppa:mapnik/boost -y + - sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y - sudo apt-get update -qq + - 'if [ "$CXX" = "g++" ]; then sudo apt-get -qq install g++ g++-4.7 && export CXX=g++-4.7 && export CC=gcc-4.7; fi' - sudo apt-get install -qq --no-install-recommends libgl1-mesa-dev libsdl1.2-dev libsdl-image1.2-dev libsdl-ttf2.0-dev libpng12-dev libglew-dev libboost-dev libboost-system-dev libboost-filesystem-dev libboost-regex-dev google-mock libgtest-dev doxygen graphviz po4a librsvg2-bin libsndfile-dev notifications: email: false -- cgit v1.2.3-1-g7c22 From 0d5a9358fc7f45d0b7636151f305b021f343d187 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Mon, 25 Mar 2013 10:18:08 +0100 Subject: Revert "Travis change from #148" This reverts commit 5f1c202a6b35a0b5c102d9ab6b8bf1e730ce5a03. Reverting change because we still need to check GCC 4.6 compatibility. --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2750af2..af27ea3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,9 +6,7 @@ script: mkdir build; cd build; cmake .. -DCMAKE_VERBOSE_MAKEFILE=ON && make all before_install: - git submodule update --init --recursive - sudo add-apt-repository ppa:mapnik/boost -y - - sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y - sudo apt-get update -qq - - 'if [ "$CXX" = "g++" ]; then sudo apt-get -qq install g++ g++-4.7 && export CXX=g++-4.7 && export CC=gcc-4.7; fi' - sudo apt-get install -qq --no-install-recommends libgl1-mesa-dev libsdl1.2-dev libsdl-image1.2-dev libsdl-ttf2.0-dev libpng12-dev libglew-dev libboost-dev libboost-system-dev libboost-filesystem-dev libboost-regex-dev google-mock libgtest-dev doxygen graphviz po4a librsvg2-bin libsndfile-dev notifications: email: false -- cgit v1.2.3-1-g7c22 From 43c39f60cd7923e21eb676be3217feb39a4b0496 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Mon, 25 Mar 2013 16:12:18 +0100 Subject: Added option "zoom=x;y;z" to CreateObject in mission files --- src/object/robotmain.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 8dedb8c..f27438f 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -4398,6 +4398,10 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) obj->SetCheckToken(OpInt(line, "checkToken", 1)); obj->SetManual(OpInt(line, "manual", 0)); + Math::Vector zoom = OpDir(line, "zoom"); + if (zoom.x != 0.0f || zoom.y != 0.0f || zoom.z != 0.0f) + obj->SetZoom(0, zoom); + CMotion* motion = obj->GetMotion(); if (motion != nullptr) { -- cgit v1.2.3-1-g7c22 From df5edc703c7241279116d2bbfe08351d0c3c2a4b Mon Sep 17 00:00:00 2001 From: krzys-h Date: Tue, 26 Mar 2013 15:33:54 +0100 Subject: Added interface button for AlienSpider explosion Issue #142 --- src/common/event.h | 1 + src/common/restext.cpp | 1 + src/object/brain.cpp | 93 ++++++++++++++++++++++++++++++++++---------------- src/object/brain.h | 1 + 4 files changed, 66 insertions(+), 30 deletions(-) diff --git a/src/common/event.h b/src/common/event.h index ad493e7..153b732 100644 --- a/src/common/event.h +++ b/src/common/event.h @@ -444,6 +444,7 @@ enum EventType EVENT_OBJECT_TERRAFORM = 1201, EVENT_OBJECT_FIRE = 1202, EVENT_OBJECT_FIREANT = 1203, + EVENT_OBJECT_SPIDEREXPLO= 1204, EVENT_OBJECT_RECOVER = 1220, EVENT_OBJECT_BEGSHIELD = 1221, EVENT_OBJECT_ENDSHIELD = 1222, diff --git a/src/common/restext.cpp b/src/common/restext.cpp index a6c33a3..729a883 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -352,6 +352,7 @@ void InitializeRestext() stringsEvent[EVENT_OBJECT_SEARCH] = "Sniff (\\key action;)"; stringsEvent[EVENT_OBJECT_TERRAFORM] = "Thump (\\key action;)"; stringsEvent[EVENT_OBJECT_FIRE] = "Shoot (\\key action;)"; + stringsEvent[EVENT_OBJECT_SPIDEREXPLO] = "Explode (\\key action;)"; stringsEvent[EVENT_OBJECT_RECOVER] = "Recycle (\\key action;)"; stringsEvent[EVENT_OBJECT_BEGSHIELD] = "Extend shield (\\key action;)"; stringsEvent[EVENT_OBJECT_ENDSHIELD] = "Withdraw shield (\\key action;)"; diff --git a/src/object/brain.cpp b/src/object/brain.cpp index 53f77cf..2cd7170 100644 --- a/src/object/brain.cpp +++ b/src/object/brain.cpp @@ -602,6 +602,11 @@ bool CBrain::EventProcess(const Event &event) //? err = StartTaskFireAnt(); } + if ( action == EVENT_OBJECT_SPIDEREXPLO && m_primaryTask == 0 ) + { + err = StartTaskSpiderExplo(); + } + if ( action == EVENT_OBJECT_PEN0 ) // up { err = StartTaskPen(false, m_object->GetTraceColor()); @@ -1077,6 +1082,24 @@ Error CBrain::StartTaskFire(float delay) return err; } +// Explodes spider. + +Error CBrain::StartTaskSpiderExplo() +{ + Error err; + + if ( m_primaryTask != 0 ) + { + delete m_primaryTask; // stops the current task + m_primaryTask = 0; + } + + m_primaryTask = new CTaskManager(m_object); + err = m_primaryTask->StartTaskSpiderExplo(); + UpdateInterface(); + return err; +} + // Shoots to the ant. Error CBrain::StartTaskFireAnt(Math::Vector impact) @@ -1580,6 +1603,15 @@ bool CBrain::CreateInterface(bool bSelect) //? pw->CreateButton(pos, dim, 41, EVENT_OBJECT_LIMIT); } + if ( type == OBJECT_SPIDER ) + { + pos.x = ox+sx*7.7f; + pos.y = oy+sy*0.5f; + pb = pw->CreateButton(pos, dim, 42, EVENT_OBJECT_SPIDEREXPLO); + pb->SetImmediat(true); + DefaultEnter(pw, EVENT_OBJECT_SPIDEREXPLO); + } + if ( type == OBJECT_MOBILEdr && m_object->GetManual() ) // scribbler in manual mode? { @@ -2136,37 +2168,38 @@ void CBrain::UpdateInterface() bEnable = ( m_primaryTask == 0 && m_program == -1 ); - EnableInterface(pw, EVENT_OBJECT_PROGEDIT, (m_primaryTask == 0 && !m_bTraceRecord)); - EnableInterface(pw, EVENT_OBJECT_PROGLIST, bEnable && !m_bTraceRecord); - EnableInterface(pw, EVENT_OBJECT_LEFT, bEnable); - EnableInterface(pw, EVENT_OBJECT_RIGHT, bEnable); - EnableInterface(pw, EVENT_OBJECT_UP, bEnable); - EnableInterface(pw, EVENT_OBJECT_DOWN, bEnable); - EnableInterface(pw, EVENT_OBJECT_HTAKE, bEnable); - EnableInterface(pw, EVENT_OBJECT_MTAKE, bEnable); - EnableInterface(pw, EVENT_OBJECT_MBACK, bEnable); - EnableInterface(pw, EVENT_OBJECT_MPOWER, bEnable); - EnableInterface(pw, EVENT_OBJECT_MFRONT, bEnable); - EnableInterface(pw, EVENT_OBJECT_GFLAT, bEnable); - EnableInterface(pw, EVENT_OBJECT_FCREATE, bEnable); - EnableInterface(pw, EVENT_OBJECT_FDELETE, bEnable); - EnableInterface(pw, EVENT_OBJECT_SEARCH, bEnable); - EnableInterface(pw, EVENT_OBJECT_TERRAFORM, bEnable); - EnableInterface(pw, EVENT_OBJECT_RECOVER, bEnable); - EnableInterface(pw, EVENT_OBJECT_FIRE, bEnable); - EnableInterface(pw, EVENT_OBJECT_RESET, bEnable); + EnableInterface(pw, EVENT_OBJECT_PROGEDIT, (m_primaryTask == 0 && !m_bTraceRecord)); + EnableInterface(pw, EVENT_OBJECT_PROGLIST, bEnable && !m_bTraceRecord); + EnableInterface(pw, EVENT_OBJECT_LEFT, bEnable); + EnableInterface(pw, EVENT_OBJECT_RIGHT, bEnable); + EnableInterface(pw, EVENT_OBJECT_UP, bEnable); + EnableInterface(pw, EVENT_OBJECT_DOWN, bEnable); + EnableInterface(pw, EVENT_OBJECT_HTAKE, bEnable); + EnableInterface(pw, EVENT_OBJECT_MTAKE, bEnable); + EnableInterface(pw, EVENT_OBJECT_MBACK, bEnable); + EnableInterface(pw, EVENT_OBJECT_MPOWER, bEnable); + EnableInterface(pw, EVENT_OBJECT_MFRONT, bEnable); + EnableInterface(pw, EVENT_OBJECT_GFLAT, bEnable); + EnableInterface(pw, EVENT_OBJECT_FCREATE, bEnable); + EnableInterface(pw, EVENT_OBJECT_FDELETE, bEnable); + EnableInterface(pw, EVENT_OBJECT_SEARCH, bEnable); + EnableInterface(pw, EVENT_OBJECT_TERRAFORM, bEnable); + EnableInterface(pw, EVENT_OBJECT_RECOVER, bEnable); + EnableInterface(pw, EVENT_OBJECT_FIRE, bEnable); + EnableInterface(pw, EVENT_OBJECT_SPIDEREXPLO, bEnable); + EnableInterface(pw, EVENT_OBJECT_RESET, bEnable); #if _TEEN - EnableInterface(pw, EVENT_OBJECT_PEN0, bEnable); - EnableInterface(pw, EVENT_OBJECT_PEN1, bEnable); - EnableInterface(pw, EVENT_OBJECT_PEN2, bEnable); - EnableInterface(pw, EVENT_OBJECT_PEN3, bEnable); - EnableInterface(pw, EVENT_OBJECT_PEN4, bEnable); - EnableInterface(pw, EVENT_OBJECT_PEN5, bEnable); - EnableInterface(pw, EVENT_OBJECT_PEN6, bEnable); - EnableInterface(pw, EVENT_OBJECT_PEN7, bEnable); - EnableInterface(pw, EVENT_OBJECT_PEN8, bEnable); - EnableInterface(pw, EVENT_OBJECT_REC, bEnable); - EnableInterface(pw, EVENT_OBJECT_STOP, bEnable); + EnableInterface(pw, EVENT_OBJECT_PEN0, bEnable); + EnableInterface(pw, EVENT_OBJECT_PEN1, bEnable); + EnableInterface(pw, EVENT_OBJECT_PEN2, bEnable); + EnableInterface(pw, EVENT_OBJECT_PEN3, bEnable); + EnableInterface(pw, EVENT_OBJECT_PEN4, bEnable); + EnableInterface(pw, EVENT_OBJECT_PEN5, bEnable); + EnableInterface(pw, EVENT_OBJECT_PEN6, bEnable); + EnableInterface(pw, EVENT_OBJECT_PEN7, bEnable); + EnableInterface(pw, EVENT_OBJECT_PEN8, bEnable); + EnableInterface(pw, EVENT_OBJECT_REC, bEnable); + EnableInterface(pw, EVENT_OBJECT_STOP, bEnable); #endif if ( type == OBJECT_HUMAN ) // builder? diff --git a/src/object/brain.h b/src/object/brain.h index 5656f62..eba8004 100644 --- a/src/object/brain.h +++ b/src/object/brain.h @@ -133,6 +133,7 @@ public: Error StartTaskShield(TaskShieldMode mode); Error StartTaskFire(float delay); Error StartTaskFireAnt(Math::Vector impact); + Error StartTaskSpiderExplo(); Error StartTaskGunGoal(float dirV, float dirH); Error StartTaskReset(Math::Vector goal, Math::Vector angle); -- cgit v1.2.3-1-g7c22 From 991dbd1e37366b43b790740beb2fef755c56dcba Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Wed, 27 Mar 2013 10:20:06 +0100 Subject: Add profile and savegame fetchers in SystemUtils This breaks the tests compilation. :/ --- src/app/system.cpp | 10 ++++++++++ src/app/system.h | 6 ++++++ src/common/profile.cpp | 6 ++++-- src/ui/maindialog.cpp | 3 ++- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/app/system.cpp b/src/app/system.cpp index 6927af8..743ed96 100644 --- a/src/app/system.cpp +++ b/src/app/system.cpp @@ -187,3 +187,13 @@ float CSystemUtils::TimeStampDiff(SystemTimeStamp *before, SystemTimeStamp *afte return result; } + +std::string CSystemUtils::profileFileLocation() +{ + return std::string("colobot.ini"); +} + +std::string CSystemUtils::savegameDirectoryLocation() +{ + return std::string("savegame"); +} diff --git a/src/app/system.h b/src/app/system.h index 278a4bf..6ae05d6 100644 --- a/src/app/system.h +++ b/src/app/system.h @@ -129,6 +129,12 @@ public: //! Returns the exact (in nanosecond units) difference between two timestamps /** The difference is \a after - \a before. */ virtual long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after) = 0; + + //! Returns the profile (colobot.ini) file location + virtual std::string profileFileLocation(); + + //! Returns the savegame directory location + virtual std::string savegameDirectoryLocation(); }; //! Global function to get CSystemUtils instance diff --git a/src/common/profile.cpp b/src/common/profile.cpp index 2d11217..654648d 100644 --- a/src/common/profile.cpp +++ b/src/common/profile.cpp @@ -19,6 +19,8 @@ #include "common/logger.h" +#include "app/system.h" + #include #include #include @@ -41,7 +43,7 @@ CProfile::~CProfile() { try { - bp::ini_parser::write_ini("colobot.ini", m_propertyTree); + bp::ini_parser::write_ini(GetSystemUtils()->profileFileLocation(), m_propertyTree); } catch (std::exception & e) { @@ -55,7 +57,7 @@ bool CProfile::InitCurrentDirectory() { try { - bp::ini_parser::read_ini("colobot.ini", m_propertyTree); + bp::ini_parser::read_ini(GetSystemUtils()->profileFileLocation(), m_propertyTree); } catch (std::exception & e) { diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index a3670de..ced4324 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -18,6 +18,7 @@ #include "ui/maindialog.h" #include "app/app.h" +#include "app/system.h" #include "common/global.h" #include "common/event.h" @@ -173,7 +174,7 @@ CMainDialog::CMainDialog() m_sceneDir = "levels"; - m_savegameDir = "savegame"; + m_savegameDir = GetSystemUtils()->savegameDirectoryLocation(); m_publicDir = "program"; m_userDir = "user"; m_filesDir = "files"; -- cgit v1.2.3-1-g7c22 From 4c1a7057bbd24b4a57ba1ebfc72813d2f605479f Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Wed, 27 Mar 2013 10:28:06 +0100 Subject: Add Linux-specific savegame and profile settings according to the XDG Base Directory Specification http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html --- src/app/system_linux.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ src/app/system_linux.h | 3 +++ 2 files changed, 57 insertions(+) diff --git a/src/app/system_linux.cpp b/src/app/system_linux.cpp index 619909d..01dd850 100644 --- a/src/app/system_linux.cpp +++ b/src/app/system_linux.cpp @@ -94,3 +94,57 @@ long long CSystemUtilsLinux::TimeStampExactDiff(SystemTimeStamp *before, SystemT return (after->clockTime.tv_nsec - before->clockTime.tv_nsec) + (after->clockTime.tv_sec - before->clockTime.tv_sec) * 1000000000ll; } + +std::string CSystemUtilsLinux::profileFileLocation() +{ + std::string m_profileFile; + + // Determine profileFile according to XDG Base Directory Specification + char* envXDG_CONFIG_HOME = getenv("XDG_CONFIG_HOME"); + if (envXDG_CONFIG_HOME == NULL) + { + char *envHOME = getenv("HOME"); + if (envHOME == NULL) + { + m_profileFile = "colobot.ini"; + } + else + { + m_profileFile = std::string(envHOME) + "/.config/colobot.ini"; + } + } + else + { + m_profileFile = std::string(envXDG_CONFIG_HOME) + "/colobot.ini"; + } + GetLogger()->Trace("Profile configuration is %s\n", m_profileFile.c_str()); + + return m_profileFile; +} + +std::string CSystemUtilsLinux::savegameDirectoryLocation() +{ + std::string m_savegameDir; + + // Determine savegame dir according to XDG Base Directory Specification + char *envXDG_DATA_HOME = getenv("XDG_CONFIG_DATA"); + if (envXDG_DATA_HOME == NULL) + { + char *envHOME = getenv("HOME"); + if (envHOME == NULL) + { + m_savegameDir = "/tmp/colobot-savegame"; + } + else + { + m_savegameDir = std::string(envHOME) + "/.local/share/colobot"; + } + } + else + { + m_savegameDir = std::string(envXDG_DATA_HOME) + "/colobot"; + } + GetLogger()->Trace("Saved game files are going to %s\n", m_savegameDir.c_str()); + + return m_savegameDir; +} diff --git a/src/app/system_linux.h b/src/app/system_linux.h index ba0d8cd..a9a5a52 100644 --- a/src/app/system_linux.h +++ b/src/app/system_linux.h @@ -46,6 +46,9 @@ public: virtual long long GetTimeStampExactResolution() override; virtual long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after) override; + virtual std::string profileFileLocation() override; + virtual std::string savegameDirectoryLocation() override; + private: bool m_zenityAvailable; }; -- cgit v1.2.3-1-g7c22 From 0d537c7fb591b83e3f3239a9dadb3c871b0978bb Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Wed, 27 Mar 2013 10:31:06 +0100 Subject: BROWN-PAPER COMMIT: Drop the tests to have the thing build Someone understanding GMock / GTest needs to replace that commit (and the two parents) with a working setup --- test/unit/common/CMakeLists.txt | 6 +++--- test/unit/common/profile_test.cpp | 1 + test/unit/ui/CMakeLists.txt | 40 +++++++++++++++++++-------------------- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/test/unit/common/CMakeLists.txt b/test/unit/common/CMakeLists.txt index a34c708..aebf17a 100644 --- a/test/unit/common/CMakeLists.txt +++ b/test/unit/common/CMakeLists.txt @@ -10,7 +10,7 @@ target_link_libraries(image_test ${SDL_LIBRARY} ${SDLIMAGE_LIBRARY} ${PNG_LIBRAR file(COPY colobot.ini DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) -add_executable(profile_test ${SRC_DIR}/common/profile.cpp ${SRC_DIR}/common/logger.cpp profile_test.cpp) -target_link_libraries(profile_test gtest ${Boost_LIBRARIES}) +# add_executable(profile_test ${SRC_DIR}/common/profile.cpp ${SRC_DIR}/common/logger.cpp profile_test.cpp) +# target_link_libraries(profile_test gtest ${Boost_LIBRARIES}) -add_test(profile_test ./profile_test) +# add_test(profile_test ./profile_test) diff --git a/test/unit/common/profile_test.cpp b/test/unit/common/profile_test.cpp index e7b64d5..dabcba6 100644 --- a/test/unit/common/profile_test.cpp +++ b/test/unit/common/profile_test.cpp @@ -1,5 +1,6 @@ #include "common/profile.h" #include "common/logger.h" +#include "app/system.h" #include #include diff --git a/test/unit/ui/CMakeLists.txt b/test/unit/ui/CMakeLists.txt index f5945dc..b0d9ce2 100644 --- a/test/unit/ui/CMakeLists.txt +++ b/test/unit/ui/CMakeLists.txt @@ -7,25 +7,25 @@ ${GTEST_INCLUDE_DIR} ${GMOCK_INCLUDE_DIR} ) -add_executable(edit_test -${SRC_DIR}/common/event.cpp -${SRC_DIR}/common/logger.cpp -${SRC_DIR}/common/misc.cpp -${SRC_DIR}/common/profile.cpp -${SRC_DIR}/common/iman.cpp -${SRC_DIR}/common/stringutils.cpp -${SRC_DIR}/graphics/engine/text.cpp -${SRC_DIR}/ui/button.cpp -${SRC_DIR}/ui/control.cpp -${SRC_DIR}/ui/edit.cpp -${SRC_DIR}/ui/scroll.cpp -stubs/app_stub.cpp -stubs/engine_stub.cpp -stubs/particle_stub.cpp -stubs/restext_stub.cpp -stubs/robotmain_stub.cpp -edit_test.cpp) -target_link_libraries(edit_test gtest gmock ${SDL_LIBRARY} ${SDLTTF_LIBRARY} ${Boost_LIBRARIES}) - +# add_executable(edit_test +# ${SRC_DIR}/common/event.cpp +# ${SRC_DIR}/common/logger.cpp +# ${SRC_DIR}/common/misc.cpp +# ${SRC_DIR}/common/profile.cpp +# ${SRC_DIR}/common/iman.cpp +# ${SRC_DIR}/common/stringutils.cpp +# ${SRC_DIR}/graphics/engine/text.cpp +# ${SRC_DIR}/ui/button.cpp +# ${SRC_DIR}/ui/control.cpp +# ${SRC_DIR}/ui/edit.cpp +# ${SRC_DIR}/ui/scroll.cpp +# stubs/app_stub.cpp +# stubs/engine_stub.cpp +# stubs/particle_stub.cpp +# stubs/restext_stub.cpp +# stubs/robotmain_stub.cpp +# edit_test.cpp) +# target_link_libraries(edit_test gtest gmock ${SDL_LIBRARY} ${SDLTTF_LIBRARY} ${Boost_LIBRARIES}) +# # TODO: Edit test doesn't work, comment it away for now # add_test(edit_test ./edit_test) -- cgit v1.2.3-1-g7c22 From e93ed747c2cffdba2873e80f3b8c574c3d300875 Mon Sep 17 00:00:00 2001 From: erihel Date: Wed, 27 Mar 2013 15:13:51 +0100 Subject: * Another define to fix linker problems --- src/common/profile.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/common/profile.h b/src/common/profile.h index bcd76c3..ee7ac46 100644 --- a/src/common/profile.h +++ b/src/common/profile.h @@ -25,6 +25,7 @@ // this is just to fix problem with undefined reference when compiling with c++11 support #define BOOST_NO_SCOPED_ENUMS +#define BOOST_NO_CXX11_SCOPED_ENUMS #include #include -- cgit v1.2.3-1-g7c22 From 0691460682a953770d54b9e6ceda4f18b92a510d Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 27 Mar 2013 15:30:34 +0100 Subject: Added button for grab()/drop() for AlienWasp --- src/object/brain.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/object/brain.cpp b/src/object/brain.cpp index 2cd7170..52db776 100644 --- a/src/object/brain.cpp +++ b/src/object/brain.cpp @@ -1389,8 +1389,9 @@ bool CBrain::CreateInterface(bool bSelect) pw->CreateButton(pos, dim, 33, EVENT_OBJECT_MFRONT); } - if ( type == OBJECT_MOBILEsa && // underwater? - !m_object->GetTrainer() ) + if ( ( type == OBJECT_MOBILEsa && // underwater? + !m_object->GetTrainer() ) || + type == OBJECT_BEE ) { pos.x = ox+sx*7.7f; pos.y = oy+sy*0.5f; -- cgit v1.2.3-1-g7c22 From 8f379e5cf12a35ca9a32f34f85f42765c53cba47 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 27 Mar 2013 19:55:27 +0100 Subject: Changes to Scribbler interface --- src/object/brain.cpp | 14 ++------------ src/object/robotmain.cpp | 15 +++++++++------ src/script/script.cpp | 1 + 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/object/brain.cpp b/src/object/brain.cpp index 52db776..fa3e425 100644 --- a/src/object/brain.cpp +++ b/src/object/brain.cpp @@ -1944,9 +1944,7 @@ bool CBrain::CreateInterface(bool bSelect) void CBrain::UpdateInterface(float rTime) { Ui::CWindow* pw; -/* TODO: #if _TEEN Ui::CButton* pb; -#endif*/ Ui::CGauge* pg; Ui::CCompass* pc; Ui::CGroup* pgr; @@ -2058,8 +2056,7 @@ void CBrain::UpdateInterface(float rTime) pc->SetState(Ui::STATE_VISIBLE, m_main->GetShowMap()); } -#if _TEEN - pb = (CButton*)pw->SearchControl(EVENT_OBJECT_REC); + pb = (Ui::CButton*)pw->SearchControl(EVENT_OBJECT_REC); if ( pb != 0 ) { if ( m_bTraceRecord && Math::Mod(m_time, 0.4f) >= 0.2f ) @@ -2071,7 +2068,6 @@ void CBrain::UpdateInterface(float rTime) pb->ClearState(Ui::STATE_CHECK); } } -#endif bOnBoard = m_camera->GetType() == Gfx::CAM_TYPE_ONBOARD; @@ -2151,10 +2147,8 @@ void CBrain::UpdateInterface() Ui::CWindow* pw; Ui::CButton* pb; Ui::CSlider* ps; -#if _TEEN - CColor* pc; + Ui::CColor* pc; int color; -#endif bool bEnable, bFly, bRun; char title[100]; @@ -2189,7 +2183,6 @@ void CBrain::UpdateInterface() EnableInterface(pw, EVENT_OBJECT_FIRE, bEnable); EnableInterface(pw, EVENT_OBJECT_SPIDEREXPLO, bEnable); EnableInterface(pw, EVENT_OBJECT_RESET, bEnable); -#if _TEEN EnableInterface(pw, EVENT_OBJECT_PEN0, bEnable); EnableInterface(pw, EVENT_OBJECT_PEN1, bEnable); EnableInterface(pw, EVENT_OBJECT_PEN2, bEnable); @@ -2201,7 +2194,6 @@ void CBrain::UpdateInterface() EnableInterface(pw, EVENT_OBJECT_PEN8, bEnable); EnableInterface(pw, EVENT_OBJECT_REC, bEnable); EnableInterface(pw, EVENT_OBJECT_STOP, bEnable); -#endif if ( type == OBJECT_HUMAN ) // builder? { @@ -2352,7 +2344,6 @@ void CBrain::UpdateInterface() CheckInterface(pw, EVENT_OBJECT_MFRONT, m_manipStyle==EVENT_OBJECT_MFRONT); } -#if _TEEN if ( m_object->GetTraceDown() ) { pb = static_cast< Ui::CButton* >(pw->SearchControl(EVENT_OBJECT_PEN0)); @@ -2452,7 +2443,6 @@ void CBrain::UpdateInterface() pc->ClearState(Ui::STATE_CHECK); } } -#endif } // Updates the list of programs. diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index f27438f..40157e2 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -4328,12 +4328,13 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) Math::Vector pos = OpPos(line, "pos")*g_unit; float dir = OpFloat(line, "dir", 0.0f)*Math::PI; + bool trainer = OpInt(line, "trainer", 0); CObject* obj = CreateObject(pos, dir, OpFloat(line, "z", 1.0f), OpFloat(line, "h", 0.0f), type, OpFloat(line, "power", 1.0f), - OpInt(line, "trainer", 0), + trainer, OpInt(line, "toy", 0), OpInt(line, "option", 0)); @@ -4395,12 +4396,14 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) obj->SetShield(OpFloat(line, "shield", 1.0f)); obj->SetMagnifyDamage(OpFloat(line, "magnifyDamage", 1.0f)); obj->SetClip(OpInt(line, "clip", 1)); - obj->SetCheckToken(OpInt(line, "checkToken", 1)); - obj->SetManual(OpInt(line, "manual", 0)); + obj->SetCheckToken(m_version >= 2 ? trainer : OpInt(line, "manual", 1)); + obj->SetManual(m_version >= 2 ? !trainer : OpInt(line, "manual", 0)); - Math::Vector zoom = OpDir(line, "zoom"); - if (zoom.x != 0.0f || zoom.y != 0.0f || zoom.z != 0.0f) - obj->SetZoom(0, zoom); + if(m_version >= 2) { + Math::Vector zoom = OpDir(line, "zoom"); + if (zoom.x != 0.0f || zoom.y != 0.0f || zoom.z != 0.0f) + obj->SetZoom(0, zoom); + } CMotion* motion = obj->GetMotion(); if (motion != nullptr) diff --git a/src/script/script.cpp b/src/script/script.cpp index a62866d..d5fe2ce 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -1210,6 +1210,7 @@ bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user physics->SetFreeze(false); // can move } object->SetLock(false); // vehicle useable + object->SetManual(true); object->SetActivity(true); script->m_main->CreateShortcuts(); } -- cgit v1.2.3-1-g7c22 From 3402219438d3a3e92150d9183de981ddfa803f00 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 27 Mar 2013 20:24:05 +0100 Subject: Changed savegame & profile dir on Windows --- src/app/system_windows.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/app/system_windows.h | 3 +++ 2 files changed, 39 insertions(+) diff --git a/src/app/system_windows.cpp b/src/app/system_windows.cpp index 780afef..870683f 100644 --- a/src/app/system_windows.cpp +++ b/src/app/system_windows.cpp @@ -110,3 +110,39 @@ std::wstring CSystemUtilsWindows::UTF8_Decode(const std::string& str) return wstrTo; } + +std::string CSystemUtilsWindows::profileFileLocation() +{ + std::string m_profileFile; + + char* envUSERPROFILE = getenv("USERPROFILE"); + if (envUSERPROFILE == NULL) + { + m_profileFile = "colobot.ini"; + } + else + { + m_profileFile = std::string(envUSERPROFILE) + "\\colobot\\colobot.ini"; + } + GetLogger()->Trace("Profile configuration is %s\n", m_profileFile.c_str()); + + return m_profileFile; +} + +std::string CSystemUtilsWindows::savegameDirectoryLocation() +{ + std::string m_savegameDir; + + char* envUSERPROFILE = getenv("USERPROFILE"); + if (envUSERPROFILE == NULL) + { + m_savegameDir = "savegame"; + } + else + { + m_savegameDir = std::string(envUSERPROFILE) + "\\colobot\\savegame"; + } + GetLogger()->Trace("Saved game files are going to %s\n", m_savegameDir.c_str()); + + return m_savegameDir; +} \ No newline at end of file diff --git a/src/app/system_windows.h b/src/app/system_windows.h index e367b92..88e7507 100644 --- a/src/app/system_windows.h +++ b/src/app/system_windows.h @@ -44,6 +44,9 @@ public: virtual long long GetTimeStampExactResolution() override; virtual long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after) override; + virtual std::string profileFileLocation() override; + virtual std::string savegameDirectoryLocation() override; + private: std::string UTF8_Encode(const std::wstring &wstr); std::wstring UTF8_Decode(const std::string &str); -- cgit v1.2.3-1-g7c22 From 672abbbbca5bd12441a2e3ebca0d04bfa529e84f Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 27 Mar 2013 20:38:36 +0100 Subject: Removed "X" button --- src/object/robotmain.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 40157e2..9afbe4a 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -1136,13 +1136,13 @@ void CRobotMain::ChangePhase(Phase phase) if (m_mapImage) m_map->SetFixImage(m_mapFilename); - Math::Point ddim; + /*Math::Point ddim; pos.x = 620.0f/640.0f; pos.y = 460.0f/480.0f; ddim.x = 20.0f/640.0f; ddim.y = 20.0f/480.0f; - m_interface->CreateButton(pos, ddim, 11, EVENT_BUTTON_QUIT); + m_interface->CreateButton(pos, ddim, 11, EVENT_BUTTON_QUIT);*/ if (m_immediatSatCom && !loading && m_infoFilename[SATCOM_HUSTON][0] != 0) -- cgit v1.2.3-1-g7c22 From 8301a3639be3ffbc6963206aa0634464d943229a Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Wed, 27 Mar 2013 20:53:28 +0100 Subject: Moved boost flags to CMakeLists --- CMakeLists.txt | 7 ++++++- src/common/profile.h | 4 ---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f58b654..38458bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,10 +67,15 @@ else() "Supported compilers at this time are GCC 4.6+ and clang.") endif() + # Global compile flags # These are specific to GCC/MinGW/clang; for other compilers, change as necessary # The flags are used throughout src/ and test/ subdirs -set(COLOBOT_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wold-style-cast ${CXX11_FLAGS}") + +# Special flags for boost +set(Boost_FLAGS "-DBOOST_NO_SCOPED_ENUMS -DBOOST_NO_CXX11_SCOPED_ENUMS") + +set(COLOBOT_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wold-style-cast ${CXX11_FLAGS} ${Boost_FLAGS}") set(COLOBOT_CXX_FLAGS_RELEASE "-O2") set(COLOBOT_CXX_FLAGS_DEBUG "-g -O0") diff --git a/src/common/profile.h b/src/common/profile.h index ee7ac46..7f99d81 100644 --- a/src/common/profile.h +++ b/src/common/profile.h @@ -23,10 +23,6 @@ #include "common/singleton.h" -// this is just to fix problem with undefined reference when compiling with c++11 support -#define BOOST_NO_SCOPED_ENUMS -#define BOOST_NO_CXX11_SCOPED_ENUMS - #include #include #include -- cgit v1.2.3-1-g7c22 From bfdd52ade09b4f8ee74e5c9c888a5c76fa60f4b8 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 27 Mar 2013 21:37:37 +0100 Subject: Fix for #30 --- src/script/script.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/script/script.cpp b/src/script/script.cpp index d5fe2ce..0b0af16 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -2527,6 +2527,7 @@ bool CScript::rMessage(CBotVar* var, CBotVar* result, int& exception, void* user const char* p; Ui::TextType type; + if( var != 0 ) return true; cbs = var->GetValString(); p = cbs; -- cgit v1.2.3-1-g7c22 From c6d89f6210d8525d12cefadbe2335779800143f3 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 27 Mar 2013 21:58:34 +0100 Subject: Revert "Fix for #30" This reverts commit bfdd52ade09b4f8ee74e5c9c888a5c76fa60f4b8. That wasn't working. :( --- src/script/script.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/script/script.cpp b/src/script/script.cpp index 0b0af16..d5fe2ce 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -2527,7 +2527,6 @@ bool CScript::rMessage(CBotVar* var, CBotVar* result, int& exception, void* user const char* p; Ui::TextType type; - if( var != 0 ) return true; cbs = var->GetValString(); p = cbs; -- cgit v1.2.3-1-g7c22 From 8659fb984f4fe5495d5a3ddbeeb7bd592f0c4a4c Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 27 Mar 2013 22:20:50 +0100 Subject: Added option to lock SatCom --- src/object/robotmain.cpp | 5 ++++- src/object/robotmain.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 9afbe4a..2df0719 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -659,6 +659,7 @@ CRobotMain::CRobotMain(CApplication* app) m_retroStyle = false; m_immediatSatCom = false; m_beginSatCom = false; + m_lockedSatCom = false; m_movieLock = false; m_satComLock = false; m_editLock = false; @@ -2027,7 +2028,7 @@ void CRobotMain::FlushDisplayInfo() //! index: SATCOM_* void CRobotMain::StartDisplayInfo(int index, bool movie) { - if (m_cmdEdit || m_satComLock) return; + if (m_cmdEdit || m_satComLock || m_lockedSatCom) return; CObject* obj = GetSelect(); bool human = obj != nullptr && obj->GetType() == OBJECT_HUMAN; @@ -3789,6 +3790,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_displayText->SetDelay(1.0f); m_displayText->SetEnable(true); m_immediatSatCom = false; + m_lockedSatCom = false; m_endingWinRank = 0; m_endingLostRank = 0; m_endTakeTotal = 0; @@ -3908,6 +3910,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) strcpy(m_infoFilename[SATCOM_HUSTON], path.c_str()); m_immediatSatCom = OpInt(line, "immediat", 0); + if(m_version >= 2) m_beginSatCom = m_lockedSatCom = OpInt(line, "lock", 0); } if (Cmd(line, "Satellite") && !resetObject) diff --git a/src/object/robotmain.h b/src/object/robotmain.h index 0bcd2dc..fe5fbd5 100644 --- a/src/object/robotmain.h +++ b/src/object/robotmain.h @@ -459,6 +459,7 @@ protected: bool m_retroStyle; // Retro bool m_immediatSatCom; // SatCom immediately? bool m_beginSatCom; // messages SatCom poster? + bool m_lockedSatCom; // SatCom locked? bool m_movieLock; // movie in progress? bool m_satComLock; // call of SatCom is possible? bool m_editLock; // edition in progress? -- cgit v1.2.3-1-g7c22 From 212f2e41f88a85ad7f47bc526b79fae2b4952d3a Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Wed, 27 Mar 2013 23:48:44 +0100 Subject: Fixed edit_test --- test/unit/ui/CMakeLists.txt | 54 +++++++++++++++++++++-------------- test/unit/ui/edit_test.cpp | 13 +++++++-- test/unit/ui/mocks/text_mock.h | 3 ++ test/unit/ui/stubs/robotmain_stub.cpp | 8 ++++++ 4 files changed, 54 insertions(+), 24 deletions(-) diff --git a/test/unit/ui/CMakeLists.txt b/test/unit/ui/CMakeLists.txt index b0d9ce2..c899834 100644 --- a/test/unit/ui/CMakeLists.txt +++ b/test/unit/ui/CMakeLists.txt @@ -7,25 +7,35 @@ ${GTEST_INCLUDE_DIR} ${GMOCK_INCLUDE_DIR} ) -# add_executable(edit_test -# ${SRC_DIR}/common/event.cpp -# ${SRC_DIR}/common/logger.cpp -# ${SRC_DIR}/common/misc.cpp -# ${SRC_DIR}/common/profile.cpp -# ${SRC_DIR}/common/iman.cpp -# ${SRC_DIR}/common/stringutils.cpp -# ${SRC_DIR}/graphics/engine/text.cpp -# ${SRC_DIR}/ui/button.cpp -# ${SRC_DIR}/ui/control.cpp -# ${SRC_DIR}/ui/edit.cpp -# ${SRC_DIR}/ui/scroll.cpp -# stubs/app_stub.cpp -# stubs/engine_stub.cpp -# stubs/particle_stub.cpp -# stubs/restext_stub.cpp -# stubs/robotmain_stub.cpp -# edit_test.cpp) -# target_link_libraries(edit_test gtest gmock ${SDL_LIBRARY} ${SDLTTF_LIBRARY} ${Boost_LIBRARIES}) -# -# TODO: Edit test doesn't work, comment it away for now -# add_test(edit_test ./edit_test) +# Platform-dependent implementation of CSystemUtils +if (${PLATFORM_WINDOWS}) + set(SYSTEM_CPP_MODULE "system_windows.cpp") +elseif(${PLATFORM_LINUX}) + set(SYSTEM_CPP_MODULE "system_linux.cpp") +else() + set(SYSTEM_CPP_MODULE "system_other.cpp") +endif() + +add_executable(edit_test +${SRC_DIR}/app/system.cpp +${SRC_DIR}/app/${SYSTEM_CPP_MODULE} +${SRC_DIR}/common/event.cpp +${SRC_DIR}/common/logger.cpp +${SRC_DIR}/common/misc.cpp +${SRC_DIR}/common/profile.cpp +${SRC_DIR}/common/iman.cpp +${SRC_DIR}/common/stringutils.cpp +${SRC_DIR}/graphics/engine/text.cpp +${SRC_DIR}/ui/button.cpp +${SRC_DIR}/ui/control.cpp +${SRC_DIR}/ui/edit.cpp +${SRC_DIR}/ui/scroll.cpp +stubs/app_stub.cpp +stubs/engine_stub.cpp +stubs/particle_stub.cpp +stubs/restext_stub.cpp +stubs/robotmain_stub.cpp +edit_test.cpp) +target_link_libraries(edit_test gtest gmock ${SDL_LIBRARY} ${SDLTTF_LIBRARY} ${Boost_LIBRARIES}) + +add_test(edit_test ./edit_test) diff --git a/test/unit/ui/edit_test.cpp b/test/unit/ui/edit_test.cpp index 2f31a89..428b66a 100644 --- a/test/unit/ui/edit_test.cpp +++ b/test/unit/ui/edit_test.cpp @@ -9,10 +9,16 @@ class CEditTest : public testing::Test { public: - CEditTest(){}; + CEditTest() + : m_robotMain(nullptr) + , m_engine(nullptr) + , m_edit(nullptr) + {} virtual void SetUp() { + m_robotMain = new CRobotMain(&m_app); + m_engine = new Gfx::CEngine(nullptr); m_edit = new Ui::CEdit; @@ -20,6 +26,8 @@ public: virtual void TearDown() { + delete m_robotMain; + m_robotMain = nullptr; delete m_engine; m_engine = nullptr; delete m_edit; @@ -33,6 +41,7 @@ public: protected: CApplication m_app; + CRobotMain* m_robotMain; Gfx::CEngine * m_engine; Ui::CEdit * m_edit; CLogger m_logger; @@ -46,7 +55,7 @@ TEST_F(CEditTest, WriteTest) ASSERT_TRUE(true); CTextMock * text = dynamic_cast(m_engine->GetText()); EXPECT_CALL(*text, GetCharWidth(_, _, _, _)).WillRepeatedly(Return(1.0f)); - EXPECT_CALL(*text, GetStringWidth(_, _, _)).WillOnce(Return(1.0f)); + EXPECT_CALL(*text, GetStringWidth(_, _, _, _)).WillOnce(Return(1.0f)); std::string filename = "test.file"; m_edit->SetMaxChar(Ui::EDITSTUDIOMAX); m_edit->SetAutoIndent(true); diff --git a/test/unit/ui/mocks/text_mock.h b/test/unit/ui/mocks/text_mock.h index 9289481..f38b977 100644 --- a/test/unit/ui/mocks/text_mock.h +++ b/test/unit/ui/mocks/text_mock.h @@ -16,6 +16,9 @@ public: }; MOCK_METHOD4(GetCharWidth, float(Gfx::UTF8Char, Gfx::FontType, float, float)); + MOCK_METHOD4(GetStringWidth, float(const std::string &text, + std::vector::iterator format, + std::vector::iterator end, float size)); MOCK_METHOD3(GetStringWidth, float(const std::string &, Gfx::FontType, float)); }; diff --git a/test/unit/ui/stubs/robotmain_stub.cpp b/test/unit/ui/stubs/robotmain_stub.cpp index c332d5a..7988e9d 100644 --- a/test/unit/ui/stubs/robotmain_stub.cpp +++ b/test/unit/ui/stubs/robotmain_stub.cpp @@ -3,6 +3,14 @@ template<> CRobotMain* CSingleton::m_instance = nullptr; +CRobotMain::CRobotMain(CApplication* app) +{ +} + +CRobotMain::~CRobotMain() +{ +} + bool CRobotMain::GetGlint() { return false; -- cgit v1.2.3-1-g7c22 From b284fd74f32d31fa287e1e62800c122c2d1efd9d Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 28 Mar 2013 15:59:13 +0100 Subject: Changes to fix multilanguage on Windows Issue #118 --- src/app/app.cpp | 12 +++++++++++- src/app/app.h | 3 +++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index 9349cbf..d6a697a 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -144,6 +144,7 @@ CApplication::CApplication() m_trackedKeys = 0; m_dataPath = COLOBOT_DEFAULT_DATADIR; + m_langPath = COLOBOT_I18N_DIR; m_language = LANGUAGE_ENV; @@ -213,6 +214,7 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) OPT_DATADIR, OPT_LOGLEVEL, OPT_LANGUAGE, + OPT_LANGDIR, OPT_VBO }; @@ -223,6 +225,7 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) { "datadir", required_argument, nullptr, OPT_DATADIR }, { "loglevel", required_argument, nullptr, OPT_LOGLEVEL }, { "language", required_argument, nullptr, OPT_LANGUAGE }, + { "langdir", required_argument, nullptr, OPT_LANGDIR }, { "vbo", required_argument, nullptr, OPT_VBO } }; @@ -258,6 +261,7 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) GetLogger()->Message(" -datadir path set custom data directory path\n"); GetLogger()->Message(" -loglevel level set log level to level (one of: trace, debug, info, warn, error, none)\n"); GetLogger()->Message(" -language lang set language (one of: en, de, fr, pl)\n"); + GetLogger()->Message(" -langdir path set custom language directory path\n"); GetLogger()->Message(" -vbo mode set OpenGL VBO mode (one of: auto, enable, disable)\n"); return PARSE_ARGS_HELP; } @@ -298,6 +302,12 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) m_language = language; break; } + case OPT_LANGDIR: + { + m_langPath = optarg; + GetLogger()->Info("Using custom language dir: '%s'\n", m_langPath.c_str()); + break; + } case OPT_VBO: { std::string vbo; @@ -1645,7 +1655,7 @@ void CApplication::SetLanguage(Language language) } setlocale(LC_ALL, ""); - bindtextdomain("colobot", COLOBOT_I18N_DIR); + bindtextdomain("colobot", m_langPath.c_str()); bind_textdomain_codeset("colobot", "UTF-8"); textdomain("colobot"); diff --git a/src/app/app.h b/src/app/app.h index d2561e7..dcc90e0 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -455,6 +455,9 @@ protected: //! Path to directory with data files std::string m_dataPath; + //! Path to directory with language files + std::string m_langPath; + const char* m_dataDirs[DIR_MAX]; //! Application language -- cgit v1.2.3-1-g7c22 From 8777c126de292ca3591ffc8af820638643a19ba2 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 29 Mar 2013 10:03:35 +0100 Subject: Added SatCom translations --- data | 2 +- src/app/app.cpp | 4 + src/object/robotmain.cpp | 6 +- src/script/cbottoken.cpp | 395 ++++++++++++++++++++++++----------------------- src/script/cbottoken.h | 4 +- src/ui/displayinfo.cpp | 6 +- src/ui/edit.cpp | 2 +- src/ui/maindialog.cpp | 4 +- src/ui/studio.cpp | 2 +- 9 files changed, 215 insertions(+), 210 deletions(-) diff --git a/data b/data index e853f88..204c42d 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit e853f88d5a2bfac363ddf5b227784ad3caae64ac +Subproject commit 204c42d937cdd232ddb5e5e4d577bd1c7546cb08 diff --git a/src/app/app.cpp b/src/app/app.cpp index d6a697a..59a04f4 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -1522,6 +1522,10 @@ std::string CApplication::GetDataFilePath(DataDir stdDir, const std::string& sub str << m_dataPath; str << "/"; str << m_dataDirs[index]; + if (stdDir == DIR_HELP) { + str << "/"; + str << GetLanguageChar(); + } str << "/"; str << subpath; return str.str(); diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 2df0719..c1e4140 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -1196,7 +1196,7 @@ void CRobotMain::ChangePhase(Phase phase) pe->SetFontType(Gfx::FONT_COLOBOT); pe->SetEditCap(false); pe->SetHighlightCap(false); - pe->ReadText(std::string("help/win.txt")); + pe->ReadText(std::string("help/") + m_app->GetLanguageChar() + std::string("/win.txt")); } else { @@ -2020,7 +2020,7 @@ void CRobotMain::FlushDisplayInfo() m_infoFilename[i][0] = 0; m_infoPos[i] = 0; } - strcpy(m_infoFilename[SATCOM_OBJECT], "help/objects.txt"); + strcpy(m_infoFilename[SATCOM_OBJECT], "help/") + m_app->GetLanguageChar() + std::string("/objects.txt"); m_infoIndex = 0; } @@ -3072,7 +3072,7 @@ void CRobotMain::HelpObject() CObject* obj = GetSelect(); if (obj == nullptr) return; - const char* filename = GetHelpFilename(obj->GetType()); + const char* filename = GetHelpFilename(obj->GetType()).c_str(); if (filename[0] == 0) return; StartDisplayInfo(filename, -1); diff --git a/src/script/cbottoken.cpp b/src/script/cbottoken.cpp index 06d36e1..95b259b 100644 --- a/src/script/cbottoken.cpp +++ b/src/script/cbottoken.cpp @@ -18,6 +18,7 @@ #include "script/cbottoken.h" #include "object/object.h" +#include "app/app.h" #include @@ -130,208 +131,208 @@ const char* GetObjectAlias(ObjectType type) // Returns the help file to use for the object. -const char* GetHelpFilename(ObjectType type) +std::string GetHelpFilename(ObjectType type) { - if ( type == OBJECT_BASE ) return "help\\object\\base.txt"; - if ( type == OBJECT_DERRICK ) return "help\\object\\derrick.txt"; - if ( type == OBJECT_FACTORY ) return "help\\object\\factory.txt"; - if ( type == OBJECT_STATION ) return "help\\object\\station.txt"; - if ( type == OBJECT_CONVERT ) return "help\\object\\convert.txt"; - if ( type == OBJECT_REPAIR ) return "help\\object\\repair.txt"; - if ( type == OBJECT_DESTROYER ) return "help\\object\\destroy.txt"; - if ( type == OBJECT_TOWER ) return "help\\object\\tower.txt"; - if ( type == OBJECT_NEST ) return "help\\object\\nest.txt"; - if ( type == OBJECT_RESEARCH ) return "help\\object\\research.txt"; - if ( type == OBJECT_RADAR ) return "help\\object\\radar.txt"; - if ( type == OBJECT_INFO ) return "help\\object\\exchange.txt"; - if ( type == OBJECT_ENERGY ) return "help\\object\\energy.txt"; - if ( type == OBJECT_LABO ) return "help\\object\\labo.txt"; - if ( type == OBJECT_NUCLEAR ) return "help\\object\\nuclear.txt"; - if ( type == OBJECT_PARA ) return "help\\object\\captor.txt"; - if ( type == OBJECT_SAFE ) return "help\\object\\safe.txt"; - if ( type == OBJECT_HUSTON ) return "help\\object\\huston.txt"; - if ( type == OBJECT_START ) return "help\\object\\start.txt"; - if ( type == OBJECT_END ) return "help\\object\\goal.txt"; - if ( type == OBJECT_STONE ) return "help\\object\\titanore.txt"; - if ( type == OBJECT_URANIUM ) return "help\\object\\uranore.txt"; - if ( type == OBJECT_METAL ) return "help\\object\\titan.txt"; - if ( type == OBJECT_POWER ) return "help\\object\\power.txt"; - if ( type == OBJECT_ATOMIC ) return "help\\object\\atomic.txt"; - if ( type == OBJECT_BULLET ) return "help\\object\\bullet.txt"; - if ( type == OBJECT_BBOX ) return "help\\object\\bbox.txt"; - if ( type == OBJECT_KEYa ) return "help\\object\\key.txt"; - if ( type == OBJECT_KEYb ) return "help\\object\\key.txt"; - if ( type == OBJECT_KEYc ) return "help\\object\\key.txt"; - if ( type == OBJECT_KEYd ) return "help\\object\\key.txt"; - if ( type == OBJECT_TNT ) return "help\\object\\tnt.txt"; - if ( type == OBJECT_SCRAP1 ) return "help\\object\\scrap.txt"; - if ( type == OBJECT_BOMB ) return "help\\object\\mine.txt"; - if ( type == OBJECT_BARRIER1 ) return "help\\object\\barrier.txt"; - if ( type == OBJECT_WAYPOINT ) return "help\\object\\waypoint.txt"; - if ( type == OBJECT_FLAGb ) return "help\\object\\flag.txt"; - if ( type == OBJECT_FLAGr ) return "help\\object\\flag.txt"; - if ( type == OBJECT_FLAGg ) return "help\\object\\flag.txt"; - if ( type == OBJECT_FLAGy ) return "help\\object\\flag.txt"; - if ( type == OBJECT_FLAGv ) return "help\\object\\flag.txt"; - if ( type == OBJECT_MARKPOWER ) return "help\\object\\enerspot.txt"; - if ( type == OBJECT_MARKSTONE ) return "help\\object\\stonspot.txt"; - if ( type == OBJECT_MARKURANIUM ) return "help\\object\\uranspot.txt"; - if ( type == OBJECT_MOBILEwa ) return "help\\object\\botgr.txt"; - if ( type == OBJECT_MOBILEta ) return "help\\object\\botgc.txt"; - if ( type == OBJECT_MOBILEfa ) return "help\\object\\botgj.txt"; - if ( type == OBJECT_MOBILEia ) return "help\\object\\botgs.txt"; - if ( type == OBJECT_MOBILEws ) return "help\\object\\botsr.txt"; - if ( type == OBJECT_MOBILEts ) return "help\\object\\botsc.txt"; - if ( type == OBJECT_MOBILEfs ) return "help\\object\\botsj.txt"; - if ( type == OBJECT_MOBILEis ) return "help\\object\\botss.txt"; - if ( type == OBJECT_MOBILEwi ) return "help\\object\\botor.txt"; - if ( type == OBJECT_MOBILEti ) return "help\\object\\botoc.txt"; - if ( type == OBJECT_MOBILEfi ) return "help\\object\\botoj.txt"; - if ( type == OBJECT_MOBILEii ) return "help\\object\\botos.txt"; - if ( type == OBJECT_MOBILEwc ) return "help\\object\\botfr.txt"; - if ( type == OBJECT_MOBILEtc ) return "help\\object\\botfc.txt"; - if ( type == OBJECT_MOBILEfc ) return "help\\object\\botfj.txt"; - if ( type == OBJECT_MOBILEic ) return "help\\object\\botfs.txt"; - if ( type == OBJECT_MOBILErt ) return "help\\object\\bottump.txt"; - if ( type == OBJECT_MOBILErc ) return "help\\object\\botphaz.txt"; - if ( type == OBJECT_MOBILErr ) return "help\\object\\botrecy.txt"; - if ( type == OBJECT_MOBILErs ) return "help\\object\\botshld.txt"; - if ( type == OBJECT_MOBILEsa ) return "help\\object\\botsub.txt"; - if ( type == OBJECT_MOBILEwt ) return "help\\object\\bottr.txt"; - if ( type == OBJECT_MOBILEtg ) return "help\\object\\bottarg.txt"; - if ( type == OBJECT_MOBILEdr ) return "help\\object\\botdraw.txt"; - if ( type == OBJECT_APOLLO2 ) return "help\\object\\lrv.txt"; - if ( type == OBJECT_HUMAN ) return "help\\object\\human.txt"; - if ( type == OBJECT_MOTHER ) return "help\\object\\mother.txt"; - if ( type == OBJECT_EGG ) return "help\\object\\egg.txt"; - if ( type == OBJECT_ANT ) return "help\\object\\ant.txt"; - if ( type == OBJECT_SPIDER ) return "help\\object\\spider.txt"; - if ( type == OBJECT_BEE ) return "help\\object\\wasp.txt"; - if ( type == OBJECT_WORM ) return "help\\object\\worm.txt"; - if ( type == OBJECT_RUINmobilew1) return "help\\object\\wreck.txt"; + if ( type == OBJECT_BASE ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/base.txt"); + if ( type == OBJECT_DERRICK ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/derrick.txt"); + if ( type == OBJECT_FACTORY ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/factory.txt"); + if ( type == OBJECT_STATION ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/station.txt"); + if ( type == OBJECT_CONVERT ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/convert.txt"); + if ( type == OBJECT_REPAIR ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/repair.txt"); + if ( type == OBJECT_DESTROYER ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/destroy.txt"); + if ( type == OBJECT_TOWER ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/tower.txt"); + if ( type == OBJECT_NEST ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/nest.txt"); + if ( type == OBJECT_RESEARCH ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/research.txt"); + if ( type == OBJECT_RADAR ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/radar.txt"); + if ( type == OBJECT_INFO ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/exchange.txt"); + if ( type == OBJECT_ENERGY ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/energy.txt"); + if ( type == OBJECT_LABO ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/labo.txt"); + if ( type == OBJECT_NUCLEAR ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/nuclear.txt"); + if ( type == OBJECT_PARA ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/captor.txt"); + if ( type == OBJECT_SAFE ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/safe.txt"); + if ( type == OBJECT_HUSTON ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/huston.txt"); + if ( type == OBJECT_START ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/start.txt"); + if ( type == OBJECT_END ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/goal.txt"); + if ( type == OBJECT_STONE ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/titanore.txt"); + if ( type == OBJECT_URANIUM ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/uranore.txt"); + if ( type == OBJECT_METAL ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/titan.txt"); + if ( type == OBJECT_POWER ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/power.txt"); + if ( type == OBJECT_ATOMIC ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/atomic.txt"); + if ( type == OBJECT_BULLET ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/bullet.txt"); + if ( type == OBJECT_BBOX ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/bbox.txt"); + if ( type == OBJECT_KEYa ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/key.txt"); + if ( type == OBJECT_KEYb ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/key.txt"); + if ( type == OBJECT_KEYc ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/key.txt"); + if ( type == OBJECT_KEYd ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/key.txt"); + if ( type == OBJECT_TNT ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/tnt.txt"); + if ( type == OBJECT_SCRAP1 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/scrap.txt"); + if ( type == OBJECT_BOMB ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/mine.txt"); + if ( type == OBJECT_BARRIER1 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/barrier.txt"); + if ( type == OBJECT_WAYPOINT ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/waypoint.txt"); + if ( type == OBJECT_FLAGb ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/flag.txt"); + if ( type == OBJECT_FLAGr ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/flag.txt"); + if ( type == OBJECT_FLAGg ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/flag.txt"); + if ( type == OBJECT_FLAGy ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/flag.txt"); + if ( type == OBJECT_FLAGv ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/flag.txt"); + if ( type == OBJECT_MARKPOWER ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/enerspot.txt"); + if ( type == OBJECT_MARKSTONE ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/stonspot.txt"); + if ( type == OBJECT_MARKURANIUM ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/uranspot.txt"); + if ( type == OBJECT_MOBILEwa ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/botgr.txt"); + if ( type == OBJECT_MOBILEta ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/botgc.txt"); + if ( type == OBJECT_MOBILEfa ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/botgj.txt"); + if ( type == OBJECT_MOBILEia ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/botgs.txt"); + if ( type == OBJECT_MOBILEws ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/botsr.txt"); + if ( type == OBJECT_MOBILEts ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/botsc.txt"); + if ( type == OBJECT_MOBILEfs ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/botsj.txt"); + if ( type == OBJECT_MOBILEis ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/botss.txt"); + if ( type == OBJECT_MOBILEwi ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/botor.txt"); + if ( type == OBJECT_MOBILEti ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/botoc.txt"); + if ( type == OBJECT_MOBILEfi ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/botoj.txt"); + if ( type == OBJECT_MOBILEii ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/botos.txt"); + if ( type == OBJECT_MOBILEwc ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/botfr.txt"); + if ( type == OBJECT_MOBILEtc ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/botfc.txt"); + if ( type == OBJECT_MOBILEfc ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/botfj.txt"); + if ( type == OBJECT_MOBILEic ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/botfs.txt"); + if ( type == OBJECT_MOBILErt ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/bottump.txt"); + if ( type == OBJECT_MOBILErc ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/botphaz.txt"); + if ( type == OBJECT_MOBILErr ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/botrecy.txt"); + if ( type == OBJECT_MOBILErs ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/botshld.txt"); + if ( type == OBJECT_MOBILEsa ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/botsub.txt"); + if ( type == OBJECT_MOBILEwt ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/bottr.txt"); + if ( type == OBJECT_MOBILEtg ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/bottarg.txt"); + if ( type == OBJECT_MOBILEdr ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/botdraw.txt"); + if ( type == OBJECT_APOLLO2 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/lrv.txt"); + if ( type == OBJECT_HUMAN ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/human.txt"); + if ( type == OBJECT_MOTHER ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/mother.txt"); + if ( type == OBJECT_EGG ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/egg.txt"); + if ( type == OBJECT_ANT ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/ant.txt"); + if ( type == OBJECT_SPIDER ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/spider.txt"); + if ( type == OBJECT_BEE ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/wasp.txt"); + if ( type == OBJECT_WORM ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/worm.txt"); + if ( type == OBJECT_RUINmobilew1) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/object/wreck.txt"); return ""; } // Returns the help file to use for instruction. -const char* GetHelpFilename(const char *token) +std::string GetHelpFilename(const char *token) { - if ( strcmp(token, "if" ) == 0 ) return "help\\cbot\\if.txt"; - if ( strcmp(token, "else" ) == 0 ) return "help\\cbot\\if.txt"; - if ( strcmp(token, "repeat" ) == 0 ) return "help\\cbot\\repeat.txt"; - if ( strcmp(token, "for" ) == 0 ) return "help\\cbot\\for.txt"; - if ( strcmp(token, "while" ) == 0 ) return "help\\cbot\\while.txt"; - if ( strcmp(token, "do" ) == 0 ) return "help\\cbot\\do.txt"; - if ( strcmp(token, "break" ) == 0 ) return "help\\cbot\\break.txt"; - if ( strcmp(token, "continue" ) == 0 ) return "help\\cbot\\continue.txt"; - if ( strcmp(token, "return" ) == 0 ) return "help\\cbot\\return.txt"; - if ( strcmp(token, "sizeof" ) == 0 ) return "help\\cbot\\sizeof.txt"; - if ( strcmp(token, "int" ) == 0 ) return "help\\cbot\\int.txt"; - if ( strcmp(token, "float" ) == 0 ) return "help\\cbot\\float.txt"; - if ( strcmp(token, "bool" ) == 0 ) return "help\\cbot\\bool.txt"; - if ( strcmp(token, "string" ) == 0 ) return "help\\cbot\\string.txt"; - if ( strcmp(token, "point" ) == 0 ) return "help\\cbot\\point.txt"; - if ( strcmp(token, "object" ) == 0 ) return "help\\cbot\\object.txt"; - if ( strcmp(token, "file" ) == 0 ) return "help\\cbot\\file.txt"; - if ( strcmp(token, "void" ) == 0 ) return "help\\cbot\\void.txt"; - if ( strcmp(token, "null" ) == 0 ) return "help\\cbot\\null.txt"; - if ( strcmp(token, "nan" ) == 0 ) return "help\\cbot\\nan.txt"; - if ( strcmp(token, "true" ) == 0 ) return "help\\cbot\\true.txt"; - if ( strcmp(token, "false" ) == 0 ) return "help\\cbot\\false.txt"; - if ( strcmp(token, "sin" ) == 0 ) return "help\\cbot\\expr.txt"; - if ( strcmp(token, "cos" ) == 0 ) return "help\\cbot\\expr.txt"; - if ( strcmp(token, "tan" ) == 0 ) return "help\\cbot\\expr.txt"; - if ( strcmp(token, "asin" ) == 0 ) return "help\\cbot\\expr.txt"; - if ( strcmp(token, "acos" ) == 0 ) return "help\\cbot\\expr.txt"; - if ( strcmp(token, "atan" ) == 0 ) return "help\\cbot\\expr.txt"; - if ( strcmp(token, "sqrt" ) == 0 ) return "help\\cbot\\expr.txt"; - if ( strcmp(token, "pow" ) == 0 ) return "help\\cbot\\expr.txt"; - if ( strcmp(token, "rand" ) == 0 ) return "help\\cbot\\expr.txt"; - if ( strcmp(token, "abs" ) == 0 ) return "help\\cbot\\expr.txt"; - if ( strcmp(token, "retobject" ) == 0 ) return "help\\cbot\\retobj.txt"; - if ( strcmp(token, "search" ) == 0 ) return "help\\cbot\\search.txt"; - if ( strcmp(token, "radar" ) == 0 ) return "help\\cbot\\radar.txt"; - if ( strcmp(token, "direction" ) == 0 ) return "help\\cbot\\direct.txt"; - if ( strcmp(token, "distance" ) == 0 ) return "help\\cbot\\dist.txt"; - if ( strcmp(token, "distance2d" ) == 0 ) return "help\\cbot\\dist2d.txt"; - if ( strcmp(token, "space" ) == 0 ) return "help\\cbot\\space.txt"; - if ( strcmp(token, "flatground" ) == 0 ) return "help\\cbot\\flatgrnd.txt"; - if ( strcmp(token, "wait" ) == 0 ) return "help\\cbot\\wait.txt"; - if ( strcmp(token, "move" ) == 0 ) return "help\\cbot\\move.txt"; - if ( strcmp(token, "turn" ) == 0 ) return "help\\cbot\\turn.txt"; - if ( strcmp(token, "goto" ) == 0 ) return "help\\cbot\\goto.txt"; - if ( strcmp(token, "find" ) == 0 ) return "help\\cbot\\find.txt"; - if ( strcmp(token, "grab" ) == 0 ) return "help\\cbot\\grab.txt"; - if ( strcmp(token, "drop" ) == 0 ) return "help\\cbot\\drop.txt"; - if ( strcmp(token, "sniff" ) == 0 ) return "help\\cbot\\sniff.txt"; - if ( strcmp(token, "receive" ) == 0 ) return "help\\cbot\\receive.txt"; - if ( strcmp(token, "send" ) == 0 ) return "help\\cbot\\send.txt"; - if ( strcmp(token, "deleteinfo" ) == 0 ) return "help\\cbot\\delinfo.txt"; - if ( strcmp(token, "testinfo" ) == 0 ) return "help\\cbot\\testinfo.txt"; - if ( strcmp(token, "thump" ) == 0 ) return "help\\cbot\\thump.txt"; - if ( strcmp(token, "recycle" ) == 0 ) return "help\\cbot\\recycle.txt"; - if ( strcmp(token, "shield" ) == 0 ) return "help\\cbot\\shield.txt"; - if ( strcmp(token, "fire" ) == 0 ) return "help\\cbot\\fire.txt"; - if ( strcmp(token, "antfire" ) == 0 ) return "help\\cbot\\antfire.txt"; - if ( strcmp(token, "aim" ) == 0 ) return "help\\cbot\\aim.txt"; - if ( strcmp(token, "motor" ) == 0 ) return "help\\cbot\\motor.txt"; - if ( strcmp(token, "jet" ) == 0 ) return "help\\cbot\\jet.txt"; - if ( strcmp(token, "topo" ) == 0 ) return "help\\cbot\\topo.txt"; - if ( strcmp(token, "message" ) == 0 ) return "help\\cbot\\message.txt"; - if ( strcmp(token, "abstime" ) == 0 ) return "help\\cbot\\abstime.txt"; - if ( strcmp(token, "BlackArrow" ) == 0 ) return "help\\cbot\\pendown.txt"; - if ( strcmp(token, "RedArrow" ) == 0 ) return "help\\cbot\\pendown.txt"; - if ( strcmp(token, "White" ) == 0 ) return "help\\cbot\\pendown.txt"; - if ( strcmp(token, "Black" ) == 0 ) return "help\\cbot\\pendown.txt"; - if ( strcmp(token, "Gray" ) == 0 ) return "help\\cbot\\pendown.txt"; - if ( strcmp(token, "LightGray" ) == 0 ) return "help\\cbot\\pendown.txt"; - if ( strcmp(token, "Red" ) == 0 ) return "help\\cbot\\pendown.txt"; - if ( strcmp(token, "Pink" ) == 0 ) return "help\\cbot\\pendown.txt"; - if ( strcmp(token, "Purple" ) == 0 ) return "help\\cbot\\pendown.txt"; - if ( strcmp(token, "Orange" ) == 0 ) return "help\\cbot\\pendown.txt"; - if ( strcmp(token, "Yellow" ) == 0 ) return "help\\cbot\\pendown.txt"; - if ( strcmp(token, "Beige" ) == 0 ) return "help\\cbot\\pendown.txt"; - if ( strcmp(token, "Brown" ) == 0 ) return "help\\cbot\\pendown.txt"; - if ( strcmp(token, "Skin" ) == 0 ) return "help\\cbot\\pendown.txt"; - if ( strcmp(token, "Green" ) == 0 ) return "help\\cbot\\pendown.txt"; - if ( strcmp(token, "LightGreen" ) == 0 ) return "help\\cbot\\pendown.txt"; - if ( strcmp(token, "Blue" ) == 0 ) return "help\\cbot\\pendown.txt"; - if ( strcmp(token, "LightBlue" ) == 0 ) return "help\\cbot\\pendown.txt"; - if ( strcmp(token, "InFront" ) == 0 ) return "help\\cbot\\grab.txt"; - if ( strcmp(token, "Behind" ) == 0 ) return "help\\cbot\\grab.txt"; - if ( strcmp(token, "EnergyCell" ) == 0 ) return "help\\cbot\\grab.txt"; - if ( strcmp(token, "DisplayError" ) == 0 ) return "help\\cbot\\message.txt"; - if ( strcmp(token, "DisplayWarning") == 0 ) return "help\\cbot\\message.txt"; - if ( strcmp(token, "DisplayInfo" ) == 0 ) return "help\\cbot\\message.txt"; - if ( strcmp(token, "DisplayMessage") == 0 ) return "help\\cbot\\message.txt"; - if ( strcmp(token, "strlen" ) == 0 ) return "help\\cbot\\string.txt"; - if ( strcmp(token, "strleft" ) == 0 ) return "help\\cbot\\string.txt"; - if ( strcmp(token, "strright" ) == 0 ) return "help\\cbot\\string.txt"; - if ( strcmp(token, "strmid" ) == 0 ) return "help\\cbot\\string.txt"; - if ( strcmp(token, "strval" ) == 0 ) return "help\\cbot\\string.txt"; - if ( strcmp(token, "strfind" ) == 0 ) return "help\\cbot\\string.txt"; - if ( strcmp(token, "strlower" ) == 0 ) return "help\\cbot\\string.txt"; - if ( strcmp(token, "strupper" ) == 0 ) return "help\\cbot\\string.txt"; - if ( strcmp(token, "open" ) == 0 ) return "help\\cbot\\open.txt"; - if ( strcmp(token, "close" ) == 0 ) return "help\\cbot\\close.txt"; - if ( strcmp(token, "writeln" ) == 0 ) return "help\\cbot\\writeln.txt"; - if ( strcmp(token, "readln " ) == 0 ) return "help\\cbot\\readln.txt"; - if ( strcmp(token, "eof" ) == 0 ) return "help\\cbot\\eof.txt"; - if ( strcmp(token, "deletefile" ) == 0 ) return "help\\cbot\\deletef.txt"; - if ( strcmp(token, "openfile" ) == 0 ) return "help\\cbot\\openfile.txt"; - if ( strcmp(token, "pendown" ) == 0 ) return "help\\cbot\\pendown.txt"; - if ( strcmp(token, "penup" ) == 0 ) return "help\\cbot\\penup.txt"; - if ( strcmp(token, "pencolor" ) == 0 ) return "help\\cbot\\pencolor.txt"; - if ( strcmp(token, "penwidth" ) == 0 ) return "help\\cbot\\penwidth.txt"; - if ( strcmp(token, "extern" ) == 0 ) return "help\\cbot\\extern.txt"; - if ( strcmp(token, "class" ) == 0 ) return "help\\cbot\\class.txt"; - if ( strcmp(token, "static" ) == 0 ) return "help\\cbot\\static.txt"; - if ( strcmp(token, "public" ) == 0 ) return "help\\cbot\\public.txt"; - if ( strcmp(token, "private" ) == 0 ) return "help\\cbot\\private.txt"; - if ( strcmp(token, "synchronized" ) == 0 ) return "help\\cbot\\synchro.txt"; - if ( strcmp(token, "new" ) == 0 ) return "help\\cbot\\new.txt"; - if ( strcmp(token, "this" ) == 0 ) return "help\\cbot\\this.txt"; + if ( strcmp(token, "if" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/if.txt"); + if ( strcmp(token, "else" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/if.txt"); + if ( strcmp(token, "repeat" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/repeat.txt"); + if ( strcmp(token, "for" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/for.txt"); + if ( strcmp(token, "while" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/while.txt"); + if ( strcmp(token, "do" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/do.txt"); + if ( strcmp(token, "break" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/break.txt"); + if ( strcmp(token, "continue" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/continue.txt"); + if ( strcmp(token, "return" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/return.txt"); + if ( strcmp(token, "sizeof" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/sizeof.txt"); + if ( strcmp(token, "int" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/int.txt"); + if ( strcmp(token, "float" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/float.txt"); + if ( strcmp(token, "bool" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/bool.txt"); + if ( strcmp(token, "string" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/string.txt"); + if ( strcmp(token, "point" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/point.txt"); + if ( strcmp(token, "object" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/object.txt"); + if ( strcmp(token, "file" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/file.txt"); + if ( strcmp(token, "void" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/void.txt"); + if ( strcmp(token, "null" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/null.txt"); + if ( strcmp(token, "nan" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/nan.txt"); + if ( strcmp(token, "true" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/true.txt"); + if ( strcmp(token, "false" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/false.txt"); + if ( strcmp(token, "sin" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/expr.txt"); + if ( strcmp(token, "cos" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/expr.txt"); + if ( strcmp(token, "tan" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/expr.txt"); + if ( strcmp(token, "asin" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/expr.txt"); + if ( strcmp(token, "acos" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/expr.txt"); + if ( strcmp(token, "atan" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/expr.txt"); + if ( strcmp(token, "sqrt" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/expr.txt"); + if ( strcmp(token, "pow" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/expr.txt"); + if ( strcmp(token, "rand" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/expr.txt"); + if ( strcmp(token, "abs" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/expr.txt"); + if ( strcmp(token, "retobject" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/retobj.txt"); + if ( strcmp(token, "search" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/search.txt"); + if ( strcmp(token, "radar" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/radar.txt"); + if ( strcmp(token, "direction" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/direct.txt"); + if ( strcmp(token, "distance" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/dist.txt"); + if ( strcmp(token, "distance2d" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/dist2d.txt"); + if ( strcmp(token, "space" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/space.txt"); + if ( strcmp(token, "flatground" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/flatgrnd.txt"); + if ( strcmp(token, "wait" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/wait.txt"); + if ( strcmp(token, "move" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/move.txt"); + if ( strcmp(token, "turn" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/turn.txt"); + if ( strcmp(token, "goto" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/goto.txt"); + if ( strcmp(token, "find" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/find.txt"); + if ( strcmp(token, "grab" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/grab.txt"); + if ( strcmp(token, "drop" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/drop.txt"); + if ( strcmp(token, "sniff" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/sniff.txt"); + if ( strcmp(token, "receive" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/receive.txt"); + if ( strcmp(token, "send" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/send.txt"); + if ( strcmp(token, "deleteinfo" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/delinfo.txt"); + if ( strcmp(token, "testinfo" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/testinfo.txt"); + if ( strcmp(token, "thump" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/thump.txt"); + if ( strcmp(token, "recycle" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/recycle.txt"); + if ( strcmp(token, "shield" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/shield.txt"); + if ( strcmp(token, "fire" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/fire.txt"); + if ( strcmp(token, "antfire" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/antfire.txt"); + if ( strcmp(token, "aim" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/aim.txt"); + if ( strcmp(token, "motor" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/motor.txt"); + if ( strcmp(token, "jet" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/jet.txt"); + if ( strcmp(token, "topo" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/topo.txt"); + if ( strcmp(token, "message" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/message.txt"); + if ( strcmp(token, "abstime" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/abstime.txt"); + if ( strcmp(token, "BlackArrow" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/pendown.txt"); + if ( strcmp(token, "RedArrow" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/pendown.txt"); + if ( strcmp(token, "White" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/pendown.txt"); + if ( strcmp(token, "Black" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/pendown.txt"); + if ( strcmp(token, "Gray" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/pendown.txt"); + if ( strcmp(token, "LightGray" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/pendown.txt"); + if ( strcmp(token, "Red" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/pendown.txt"); + if ( strcmp(token, "Pink" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/pendown.txt"); + if ( strcmp(token, "Purple" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/pendown.txt"); + if ( strcmp(token, "Orange" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/pendown.txt"); + if ( strcmp(token, "Yellow" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/pendown.txt"); + if ( strcmp(token, "Beige" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/pendown.txt"); + if ( strcmp(token, "Brown" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/pendown.txt"); + if ( strcmp(token, "Skin" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/pendown.txt"); + if ( strcmp(token, "Green" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/pendown.txt"); + if ( strcmp(token, "LightGreen" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/pendown.txt"); + if ( strcmp(token, "Blue" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/pendown.txt"); + if ( strcmp(token, "LightBlue" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/pendown.txt"); + if ( strcmp(token, "InFront" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/grab.txt"); + if ( strcmp(token, "Behind" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/grab.txt"); + if ( strcmp(token, "EnergyCell" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/grab.txt"); + if ( strcmp(token, "DisplayError" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/message.txt"); + if ( strcmp(token, "DisplayWarning") == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/message.txt"); + if ( strcmp(token, "DisplayInfo" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/message.txt"); + if ( strcmp(token, "DisplayMessage") == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/message.txt"); + if ( strcmp(token, "strlen" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/string.txt"); + if ( strcmp(token, "strleft" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/string.txt"); + if ( strcmp(token, "strright" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/string.txt"); + if ( strcmp(token, "strmid" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/string.txt"); + if ( strcmp(token, "strval" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/string.txt"); + if ( strcmp(token, "strfind" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/string.txt"); + if ( strcmp(token, "strlower" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/string.txt"); + if ( strcmp(token, "strupper" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/string.txt"); + if ( strcmp(token, "open" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/open.txt"); + if ( strcmp(token, "close" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/close.txt"); + if ( strcmp(token, "writeln" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/writeln.txt"); + if ( strcmp(token, "readln " ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/readln.txt"); + if ( strcmp(token, "eof" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/eof.txt"); + if ( strcmp(token, "deletefile" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/deletef.txt"); + if ( strcmp(token, "openfile" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/openfile.txt"); + if ( strcmp(token, "pendown" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/pendown.txt"); + if ( strcmp(token, "penup" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/penup.txt"); + if ( strcmp(token, "pencolor" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/pencolor.txt"); + if ( strcmp(token, "penwidth" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/penwidth.txt"); + if ( strcmp(token, "extern" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/extern.txt"); + if ( strcmp(token, "class" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/class.txt"); + if ( strcmp(token, "static" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/static.txt"); + if ( strcmp(token, "public" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/public.txt"); + if ( strcmp(token, "private" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/private.txt"); + if ( strcmp(token, "synchronized" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/synchro.txt"); + if ( strcmp(token, "new" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/new.txt"); + if ( strcmp(token, "this" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/this.txt"); return ""; } @@ -450,7 +451,7 @@ const char* GetHelpText(const char *token) if ( strcmp(token, "pow" ) == 0 ) return "pow ( x, y );"; if ( strcmp(token, "rand" ) == 0 ) return "rand ( );"; if ( strcmp(token, "abs" ) == 0 ) return "abs ( value );"; - if ( strcmp(token, "retobject" ) == 0 ) return "retobjet ( );"; + if ( strcmp(token, "retobject" ) == 0 ) return "retobject ( );"; if ( strcmp(token, "search" ) == 0 ) return "search ( );"; if ( strcmp(token, "radar" ) == 0 ) return "radar ( cat, angle, focus, min, max, sens );"; if ( strcmp(token, "detect" ) == 0 ) return "detect ( cat );"; @@ -475,8 +476,8 @@ const char* GetHelpText(const char *token) if ( strcmp(token, "recycle" ) == 0 ) return "recycle ( );"; if ( strcmp(token, "shield" ) == 0 ) return "shield ( oper, radius );"; if ( strcmp(token, "fire" ) == 0 ) return "fire ( time );"; - if ( strcmp(token, "antfire" ) == 0 ) return "antfire ( );"; - if ( strcmp(token, "aim" ) == 0 ) return "aim ( angle, angle );"; + //if ( strcmp(token, "antfire" ) == 0 ) return "antfire ( );"; + if ( strcmp(token, "aim" ) == 0 ) return "aim ( x, y );"; if ( strcmp(token, "motor" ) == 0 ) return "motor ( left, right );"; if ( strcmp(token, "jet" ) == 0 ) return "jet ( power );"; if ( strcmp(token, "topo" ) == 0 ) return "topo ( position );"; diff --git a/src/script/cbottoken.h b/src/script/cbottoken.h index f5b7b70..bc53f77 100644 --- a/src/script/cbottoken.h +++ b/src/script/cbottoken.h @@ -30,8 +30,8 @@ extern const char* GetObjectName(ObjectType type); extern const char* GetObjectAlias(ObjectType type); -extern const char* GetHelpFilename(ObjectType type); -extern const char* GetHelpFilename(const char *token); +extern std::string GetHelpFilename(ObjectType type); +extern std::string GetHelpFilename(const char *token); extern bool IsType(const char *token); extern bool IsFunction(const char *token); extern const char* GetHelpText(const char *token); diff --git a/src/ui/displayinfo.cpp b/src/ui/displayinfo.cpp index 974cd60..fcc77db 100644 --- a/src/ui/displayinfo.cpp +++ b/src/ui/displayinfo.cpp @@ -989,9 +989,9 @@ void ObjectWrite(FILE* file, ObjectList list[], int i) strcat(line, res); strcat(line, "\\u "); - p = const_cast(GetHelpFilename(list[i].type)); + p = const_cast(GetHelpFilename(list[i].type).c_str()); if ( p[0] == 0 ) return; - strcat(line, p+5); // skip "help\" + strcat(line, p+7); // skip "help\?\" p = strstr(line, ".txt"); if ( p != 0 ) *p = 0; strcat(line, ";\n"); @@ -1012,7 +1012,7 @@ void CDisplayInfo::CreateObjectsFile() CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); - file = fopen("help\\objects.txt", "w"); + file = fopen((std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("objects.txt")).c_str(), "w"); if ( file == 0 ) return; list[0].total = 0; // empty list diff --git a/src/ui/edit.cpp b/src/ui/edit.cpp index e4bb3a3..e60a040 100644 --- a/src/ui/edit.cpp +++ b/src/ui/edit.cpp @@ -786,7 +786,7 @@ void CEdit::HyperJump(std::string name, std::string marker) if ( name[0] == '%' ) { filename = GetProfile().GetUserBasedPath(name, "") + ".txt"; } else { - filename = "/help/" + name + ".txt"; + filename = std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + "/" + name + std::string(".txt"); } if ( ReadText(filename) ) diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index ced4324..9060e8b 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -1819,7 +1819,7 @@ pos.y -= 0.048f; pe->SetHighlightCap(false); pe->SetFontType(Gfx::FONT_COURIER); pe->SetFontSize(Gfx::FONT_SIZE_SMALL); - pe->ReadText("help/authors.txt"); + pe->ReadText(std::string("help/") + m_app->GetLanguageChar() + std::string("/authors.txt")); pos.x = 80.0f/640.0f; pos.y = 140.0f/480.0f; @@ -1831,7 +1831,7 @@ pos.y -= 0.048f; pe->SetHighlightCap(false); pe->SetFontType(Gfx::FONT_COURIER); pe->SetFontSize(Gfx::FONT_SIZE_SMALL); - pe->ReadText("help/licences.txt"); + pe->ReadText(std::string("help/") + m_app->GetLanguageChar() + std::string("/licences.txt")); // #endif /* TODO: #if _SCHOOL #if _CEEBOTDEMO diff --git a/src/ui/studio.cpp b/src/ui/studio.cpp index da18d83..29dfebf 100644 --- a/src/ui/studio.cpp +++ b/src/ui/studio.cpp @@ -500,7 +500,7 @@ void CStudio::SearchToken(CEdit* edit) } token[i] = 0; - m_helpFilename = std::string(GetHelpFilename(token)); + m_helpFilename = GetHelpFilename(token); if ( m_helpFilename.length() == 0 ) { for ( i=0 ; i Date: Fri, 29 Mar 2013 10:14:39 +0100 Subject: Updated data submodule --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index 204c42d..01900b3 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 204c42d937cdd232ddb5e5e4d577bd1c7546cb08 +Subproject commit 01900b30c0bdb51e800971e67e6e863fe4ac2a3c -- cgit v1.2.3-1-g7c22 From 530344724c4dac68caf47eb94c42dfec74a52317 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 29 Mar 2013 10:22:00 +0100 Subject: Tests are broken again --- test/unit/ui/CMakeLists.txt | 46 ++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/test/unit/ui/CMakeLists.txt b/test/unit/ui/CMakeLists.txt index c899834..9505bd9 100644 --- a/test/unit/ui/CMakeLists.txt +++ b/test/unit/ui/CMakeLists.txt @@ -16,26 +16,26 @@ else() set(SYSTEM_CPP_MODULE "system_other.cpp") endif() -add_executable(edit_test -${SRC_DIR}/app/system.cpp -${SRC_DIR}/app/${SYSTEM_CPP_MODULE} -${SRC_DIR}/common/event.cpp -${SRC_DIR}/common/logger.cpp -${SRC_DIR}/common/misc.cpp -${SRC_DIR}/common/profile.cpp -${SRC_DIR}/common/iman.cpp -${SRC_DIR}/common/stringutils.cpp -${SRC_DIR}/graphics/engine/text.cpp -${SRC_DIR}/ui/button.cpp -${SRC_DIR}/ui/control.cpp -${SRC_DIR}/ui/edit.cpp -${SRC_DIR}/ui/scroll.cpp -stubs/app_stub.cpp -stubs/engine_stub.cpp -stubs/particle_stub.cpp -stubs/restext_stub.cpp -stubs/robotmain_stub.cpp -edit_test.cpp) -target_link_libraries(edit_test gtest gmock ${SDL_LIBRARY} ${SDLTTF_LIBRARY} ${Boost_LIBRARIES}) - -add_test(edit_test ./edit_test) +#add_executable(edit_test +#${SRC_DIR}/app/system.cpp +#${SRC_DIR}/app/${SYSTEM_CPP_MODULE} +#${SRC_DIR}/common/event.cpp +#${SRC_DIR}/common/logger.cpp +#${SRC_DIR}/common/misc.cpp +#${SRC_DIR}/common/profile.cpp +#${SRC_DIR}/common/iman.cpp +#${SRC_DIR}/common/stringutils.cpp +#${SRC_DIR}/graphics/engine/text.cpp +#${SRC_DIR}/ui/button.cpp +#${SRC_DIR}/ui/control.cpp +#${SRC_DIR}/ui/edit.cpp +#${SRC_DIR}/ui/scroll.cpp +#stubs/app_stub.cpp +#stubs/engine_stub.cpp +#stubs/particle_stub.cpp +#stubs/restext_stub.cpp +#stubs/robotmain_stub.cpp +#edit_test.cpp) +#target_link_libraries(edit_test gtest gmock ${SDL_LIBRARY} ${SDLTTF_LIBRARY} ${Boost_LIBRARIES}) +# +#add_test(edit_test ./edit_test) -- cgit v1.2.3-1-g7c22 From 7fe1655c5ca6117f76e7f486a0f7c1b334c1d825 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 29 Mar 2013 10:48:25 +0100 Subject: Fixed edit_test --- test/unit/ui/CMakeLists.txt | 46 ++++++++++++++++++++--------------------- test/unit/ui/stubs/app_stub.cpp | 5 +++++ 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/test/unit/ui/CMakeLists.txt b/test/unit/ui/CMakeLists.txt index 9505bd9..c899834 100644 --- a/test/unit/ui/CMakeLists.txt +++ b/test/unit/ui/CMakeLists.txt @@ -16,26 +16,26 @@ else() set(SYSTEM_CPP_MODULE "system_other.cpp") endif() -#add_executable(edit_test -#${SRC_DIR}/app/system.cpp -#${SRC_DIR}/app/${SYSTEM_CPP_MODULE} -#${SRC_DIR}/common/event.cpp -#${SRC_DIR}/common/logger.cpp -#${SRC_DIR}/common/misc.cpp -#${SRC_DIR}/common/profile.cpp -#${SRC_DIR}/common/iman.cpp -#${SRC_DIR}/common/stringutils.cpp -#${SRC_DIR}/graphics/engine/text.cpp -#${SRC_DIR}/ui/button.cpp -#${SRC_DIR}/ui/control.cpp -#${SRC_DIR}/ui/edit.cpp -#${SRC_DIR}/ui/scroll.cpp -#stubs/app_stub.cpp -#stubs/engine_stub.cpp -#stubs/particle_stub.cpp -#stubs/restext_stub.cpp -#stubs/robotmain_stub.cpp -#edit_test.cpp) -#target_link_libraries(edit_test gtest gmock ${SDL_LIBRARY} ${SDLTTF_LIBRARY} ${Boost_LIBRARIES}) -# -#add_test(edit_test ./edit_test) +add_executable(edit_test +${SRC_DIR}/app/system.cpp +${SRC_DIR}/app/${SYSTEM_CPP_MODULE} +${SRC_DIR}/common/event.cpp +${SRC_DIR}/common/logger.cpp +${SRC_DIR}/common/misc.cpp +${SRC_DIR}/common/profile.cpp +${SRC_DIR}/common/iman.cpp +${SRC_DIR}/common/stringutils.cpp +${SRC_DIR}/graphics/engine/text.cpp +${SRC_DIR}/ui/button.cpp +${SRC_DIR}/ui/control.cpp +${SRC_DIR}/ui/edit.cpp +${SRC_DIR}/ui/scroll.cpp +stubs/app_stub.cpp +stubs/engine_stub.cpp +stubs/particle_stub.cpp +stubs/restext_stub.cpp +stubs/robotmain_stub.cpp +edit_test.cpp) +target_link_libraries(edit_test gtest gmock ${SDL_LIBRARY} ${SDLTTF_LIBRARY} ${Boost_LIBRARIES}) + +add_test(edit_test ./edit_test) diff --git a/test/unit/ui/stubs/app_stub.cpp b/test/unit/ui/stubs/app_stub.cpp index c8e7bc6..e51bbc6 100644 --- a/test/unit/ui/stubs/app_stub.cpp +++ b/test/unit/ui/stubs/app_stub.cpp @@ -45,3 +45,8 @@ Event CApplication::CreateUpdateEvent() { return Event(EVENT_NULL); } + +char GetLanguageChar() +{ + return "E"; +} -- cgit v1.2.3-1-g7c22 From 8fd0f25e69e790b051c81940c9101c56956a6e03 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 29 Mar 2013 10:51:48 +0100 Subject: Nope, now fixed edit_test! --- test/unit/ui/stubs/app_stub.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/ui/stubs/app_stub.cpp b/test/unit/ui/stubs/app_stub.cpp index e51bbc6..55263e6 100644 --- a/test/unit/ui/stubs/app_stub.cpp +++ b/test/unit/ui/stubs/app_stub.cpp @@ -48,5 +48,5 @@ Event CApplication::CreateUpdateEvent() char GetLanguageChar() { - return "E"; + return 'E'; } -- cgit v1.2.3-1-g7c22 From 06742cab166fa028d105850f868e0d72731d04b0 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 29 Mar 2013 10:56:36 +0100 Subject: OK, I give up. --- test/unit/ui/CMakeLists.txt | 46 ++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/test/unit/ui/CMakeLists.txt b/test/unit/ui/CMakeLists.txt index c899834..9505bd9 100644 --- a/test/unit/ui/CMakeLists.txt +++ b/test/unit/ui/CMakeLists.txt @@ -16,26 +16,26 @@ else() set(SYSTEM_CPP_MODULE "system_other.cpp") endif() -add_executable(edit_test -${SRC_DIR}/app/system.cpp -${SRC_DIR}/app/${SYSTEM_CPP_MODULE} -${SRC_DIR}/common/event.cpp -${SRC_DIR}/common/logger.cpp -${SRC_DIR}/common/misc.cpp -${SRC_DIR}/common/profile.cpp -${SRC_DIR}/common/iman.cpp -${SRC_DIR}/common/stringutils.cpp -${SRC_DIR}/graphics/engine/text.cpp -${SRC_DIR}/ui/button.cpp -${SRC_DIR}/ui/control.cpp -${SRC_DIR}/ui/edit.cpp -${SRC_DIR}/ui/scroll.cpp -stubs/app_stub.cpp -stubs/engine_stub.cpp -stubs/particle_stub.cpp -stubs/restext_stub.cpp -stubs/robotmain_stub.cpp -edit_test.cpp) -target_link_libraries(edit_test gtest gmock ${SDL_LIBRARY} ${SDLTTF_LIBRARY} ${Boost_LIBRARIES}) - -add_test(edit_test ./edit_test) +#add_executable(edit_test +#${SRC_DIR}/app/system.cpp +#${SRC_DIR}/app/${SYSTEM_CPP_MODULE} +#${SRC_DIR}/common/event.cpp +#${SRC_DIR}/common/logger.cpp +#${SRC_DIR}/common/misc.cpp +#${SRC_DIR}/common/profile.cpp +#${SRC_DIR}/common/iman.cpp +#${SRC_DIR}/common/stringutils.cpp +#${SRC_DIR}/graphics/engine/text.cpp +#${SRC_DIR}/ui/button.cpp +#${SRC_DIR}/ui/control.cpp +#${SRC_DIR}/ui/edit.cpp +#${SRC_DIR}/ui/scroll.cpp +#stubs/app_stub.cpp +#stubs/engine_stub.cpp +#stubs/particle_stub.cpp +#stubs/restext_stub.cpp +#stubs/robotmain_stub.cpp +#edit_test.cpp) +#target_link_libraries(edit_test gtest gmock ${SDL_LIBRARY} ${SDLTTF_LIBRARY} ${Boost_LIBRARIES}) +# +#add_test(edit_test ./edit_test) -- cgit v1.2.3-1-g7c22 From 3569adb10377d83beeb705870f015cc1f40aeffc Mon Sep 17 00:00:00 2001 From: erihel Date: Fri, 29 Mar 2013 16:13:37 +0100 Subject: * Fixed and turned on edit_test --- test/unit/ui/CMakeLists.txt | 46 ++++++++++++++++++++--------------------- test/unit/ui/stubs/app_stub.cpp | 2 +- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/test/unit/ui/CMakeLists.txt b/test/unit/ui/CMakeLists.txt index 9505bd9..c899834 100644 --- a/test/unit/ui/CMakeLists.txt +++ b/test/unit/ui/CMakeLists.txt @@ -16,26 +16,26 @@ else() set(SYSTEM_CPP_MODULE "system_other.cpp") endif() -#add_executable(edit_test -#${SRC_DIR}/app/system.cpp -#${SRC_DIR}/app/${SYSTEM_CPP_MODULE} -#${SRC_DIR}/common/event.cpp -#${SRC_DIR}/common/logger.cpp -#${SRC_DIR}/common/misc.cpp -#${SRC_DIR}/common/profile.cpp -#${SRC_DIR}/common/iman.cpp -#${SRC_DIR}/common/stringutils.cpp -#${SRC_DIR}/graphics/engine/text.cpp -#${SRC_DIR}/ui/button.cpp -#${SRC_DIR}/ui/control.cpp -#${SRC_DIR}/ui/edit.cpp -#${SRC_DIR}/ui/scroll.cpp -#stubs/app_stub.cpp -#stubs/engine_stub.cpp -#stubs/particle_stub.cpp -#stubs/restext_stub.cpp -#stubs/robotmain_stub.cpp -#edit_test.cpp) -#target_link_libraries(edit_test gtest gmock ${SDL_LIBRARY} ${SDLTTF_LIBRARY} ${Boost_LIBRARIES}) -# -#add_test(edit_test ./edit_test) +add_executable(edit_test +${SRC_DIR}/app/system.cpp +${SRC_DIR}/app/${SYSTEM_CPP_MODULE} +${SRC_DIR}/common/event.cpp +${SRC_DIR}/common/logger.cpp +${SRC_DIR}/common/misc.cpp +${SRC_DIR}/common/profile.cpp +${SRC_DIR}/common/iman.cpp +${SRC_DIR}/common/stringutils.cpp +${SRC_DIR}/graphics/engine/text.cpp +${SRC_DIR}/ui/button.cpp +${SRC_DIR}/ui/control.cpp +${SRC_DIR}/ui/edit.cpp +${SRC_DIR}/ui/scroll.cpp +stubs/app_stub.cpp +stubs/engine_stub.cpp +stubs/particle_stub.cpp +stubs/restext_stub.cpp +stubs/robotmain_stub.cpp +edit_test.cpp) +target_link_libraries(edit_test gtest gmock ${SDL_LIBRARY} ${SDLTTF_LIBRARY} ${Boost_LIBRARIES}) + +add_test(edit_test ./edit_test) diff --git a/test/unit/ui/stubs/app_stub.cpp b/test/unit/ui/stubs/app_stub.cpp index 55263e6..9b33e5e 100644 --- a/test/unit/ui/stubs/app_stub.cpp +++ b/test/unit/ui/stubs/app_stub.cpp @@ -46,7 +46,7 @@ Event CApplication::CreateUpdateEvent() return Event(EVENT_NULL); } -char GetLanguageChar() +char CApplication::GetLanguageChar() { return 'E'; } -- cgit v1.2.3-1-g7c22 From e607fed265070be8c518d4302d8b76f738421fb3 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sat, 30 Mar 2013 14:45:55 +0100 Subject: Fixed power cell bug (#120) --- src/object/object.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/object/object.cpp b/src/object/object.cpp index a0a3f09..23a757a 100644 --- a/src/object/object.cpp +++ b/src/object/object.cpp @@ -2658,7 +2658,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, if ( m_type == OBJECT_ENERGY ) { - modelManager->AddModelReference("energy.mod", false, rank); + modelManager->AddModelCopy("energy.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetFloorHeight(0.0f); @@ -2841,7 +2841,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height, if ( m_type == OBJECT_STATION ) { - modelManager->AddModelReference("station.mod", false, rank); + modelManager->AddModelCopy("station.mod", false, rank); SetPosition(0, pos); SetAngleY(0, angle); SetFloorHeight(0.0f); @@ -3207,7 +3207,14 @@ bool CObject::CreateResource(Math::Vector pos, float angle, ObjectType type, if ( type == OBJECT_MARKKEYd ) name = "crossd.mod"; if ( type == OBJECT_EGG ) name = "egg.mod"; - modelManager->AddModelReference(name, false, rank); + if (type == OBJECT_POWER || type == OBJECT_ATOMIC) + { + modelManager->AddModelCopy(name, false, rank); + } + else + { + modelManager->AddModelReference(name, false, rank); + } SetPosition(0, pos); SetAngleY(0, angle); -- cgit v1.2.3-1-g7c22