From: Daniel Karbach Date: Fri, 20 Dec 2013 16:16:44 +0000 (+0100) Subject: some cleanup X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=11306935dbf7213d583222ce239985e1b3f180bf;p=space.git some cleanup --- diff --git a/src/app/Application.cpp b/src/app/Application.cpp index d18c757..34edd25 100644 --- a/src/app/Application.cpp +++ b/src/app/Application.cpp @@ -9,7 +9,7 @@ namespace space { Application::Application(InitScreen &s) : screen(s) -, univ(Vector(10, 10), Vector(10, 10), Vector(10, 10), 10) +, univ(Vector(10, 10), Vector(10, 10), Vector(10, 10)) , focus(Vector(500, 500), 500) , cam(800, 800, focus.Pos()) , last(SDL_GetTicks()) diff --git a/src/graphics/Camera.cpp b/src/graphics/Camera.cpp index 553b74f..ad2587f 100644 --- a/src/graphics/Camera.cpp +++ b/src/graphics/Camera.cpp @@ -6,7 +6,8 @@ namespace space { Camera::Camera(int w, int h, const Vector &t) : target(&t) , offset(w/2, h/2) -, zoom(1) { +, zoom(1) +, zoomAcc(0) { } diff --git a/src/graphics/Camera.h b/src/graphics/Camera.h index ad1a997..911f236 100644 --- a/src/graphics/Camera.h +++ b/src/graphics/Camera.h @@ -24,10 +24,10 @@ public: void StopShrink(); Vector ToScreen(Vector v) const { - return Vector(OffsetOf(v)); + return Vector(OffsetOf(v)) + offset; } Vector OffsetOf(Vector v) const { - return ToScale(v - *target) + offset; + return ToScale(v - *target); } Vector ToScale(Vector v) const { return v * zoom; @@ -35,7 +35,7 @@ public: private: const Vector *target; - Vector offset; + Vector offset; float zoom; int zoomAcc; diff --git a/src/space.cpp b/src/space.cpp index 606cc61..5cd6bd7 100644 --- a/src/space.cpp +++ b/src/space.cpp @@ -1,9 +1,6 @@ #include "app/Application.h" #include "sdl/InitSDL.h" #include "sdl/InitScreen.h" -#include "world/Resource.h" -#include "world/Sector.h" -#include "world/Universe.h" using namespace space; diff --git a/src/world/Sector.cpp b/src/world/Sector.cpp deleted file mode 100644 index 781f23d..0000000 --- a/src/world/Sector.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "Sector.h" - -#include - - -namespace space { - -Sector::Sector(Vector size, int numres) -: size(size) -, numres(numres) -, total(size.x * size.y * numres) -, res_begin(new int[total]) -, res_end(res_begin + total) { - std::memset(res_begin, 0, total * sizeof(int)); -} - -Sector::~Sector() { - delete[] res_begin; -} - -} diff --git a/src/world/Sector.h b/src/world/Sector.h deleted file mode 100644 index d5c101c..0000000 --- a/src/world/Sector.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef SPACE_SECTOR_H_ -#define SPACE_SECTOR_H_ - -#include "../math/Vector.h" - - -namespace space { - -class Sector { - -public: - Sector(Vector size, int numres); - ~Sector(); - - Sector(const Sector &) = delete; - Sector &operator =(const Sector &) = delete; - -private: - Vector size; - int numres; - int total; - int *res_begin; - int *res_end; - -}; - -} - -#endif diff --git a/src/world/Universe.cpp b/src/world/Universe.cpp index ec71fd1..9f9efe6 100644 --- a/src/world/Universe.cpp +++ b/src/world/Universe.cpp @@ -1,28 +1,20 @@ #include "Universe.h" -#include "Sector.h" - #include #include namespace space { -Universe::Universe(Vector size, Vector secSize, Vector areaSize, int numres) +Universe::Universe(Vector size, Vector secSize, Vector areaSize) : size(size) , secSize(secSize) -, areaSize(areaSize) -, numres(numres) -, total(size.x * size.y) -, sec_begin(reinterpret_cast(new char[total * sizeof(Sector)])) -, sec_end(sec_begin + total) { - for (Sector *i = sec_begin; i < sec_end; ++i) { - new (i) Sector(secSize, numres); - } +, areaSize(areaSize) { + } Universe::~Universe() { - delete[] reinterpret_cast(sec_begin); + } diff --git a/src/world/Universe.h b/src/world/Universe.h index 563bfd9..7405926 100644 --- a/src/world/Universe.h +++ b/src/world/Universe.h @@ -9,12 +9,10 @@ namespace space { -class Sector; - class Universe { public: - Universe(Vector size, Vector secSize, Vector areaSize, int numres); + Universe(Vector size, Vector secSize, Vector areaSize); ~Universe(); Universe(const Universe &) = delete; @@ -25,6 +23,49 @@ public: const Vector secSize; const Vector areaSize; +public: + class Area; + + class Sector { + + public: + Sector(const Universe &univ, Vector coords) + : univ(univ), coords(coords) { } + + public: + Vector SectorCoords() const { return coords; } + Vector AreaCoords() const { return univ.areaSize * coords; } + + Area AreaAt(Vector ac) const { return univ.AreaAt(AreaCoords() + ac); } + + private: + const Universe &univ; + Vector coords; + + }; + + class Area { + + public: + Area(const Universe &univ, Vector coords) + : univ(univ), coords(coords) { } + + public: + Vector SectorCoords() const { return coords / univ.areaSize; } + Vector AreaCoords() const { return coords; } + + Sector ParentSector() const { return univ.SectorAt(SectorCoords()); } + + private: + const Universe &univ; + Vector coords; + + }; + +public: + Sector SectorAt(Vector coords) const { return Sector(*this, coords); } + Area AreaAt(Vector coords) const { return Area(*this, coords); } + public: Entity *AddEntity(const Entity &); const std::list &Entities() const { return entities; } @@ -33,13 +74,6 @@ public: void Update(float deltaT); private: - - int numres; - int total; - - Sector *sec_begin; - Sector *sec_end; - std::list entities; };