]> git.localhorst.tv Git - space.git/commitdiff
some cleanup
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 20 Dec 2013 16:16:44 +0000 (17:16 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 20 Dec 2013 16:16:44 +0000 (17:16 +0100)
src/app/Application.cpp
src/graphics/Camera.cpp
src/graphics/Camera.h
src/space.cpp
src/world/Sector.cpp [deleted file]
src/world/Sector.h [deleted file]
src/world/Universe.cpp
src/world/Universe.h

index d18c757eca9141e62b18ea112844bc49eb049cc4..34edd257174ec97494a0317b53307684659dd409 100644 (file)
@@ -9,7 +9,7 @@ namespace space {
 
 Application::Application(InitScreen &s)
 : screen(s)
-, univ(Vector<int>(10, 10), Vector<int>(10, 10), Vector<int>(10, 10), 10)
+, univ(Vector<int>(10, 10), Vector<int>(10, 10), Vector<int>(10, 10))
 , focus(Vector<float>(500, 500), 500)
 , cam(800, 800, focus.Pos())
 , last(SDL_GetTicks())
index 553b74f77f0f9afbd36e1f6373d1b7b41bda50b5..ad2587f3e755e5a06b5fc47300da564ee4a426fe 100644 (file)
@@ -6,7 +6,8 @@ namespace space {
 Camera::Camera(int w, int h, const Vector<float> &t)
 : target(&t)
 , offset(w/2, h/2)
-, zoom(1) {
+, zoom(1)
+, zoomAcc(0) {
 
 }
 
index ad1a997ef6383cad9283ff884321b46133822e33..911f23601feacc59b287cf2734924470b20640c8 100644 (file)
@@ -24,10 +24,10 @@ public:
        void StopShrink();
 
        Vector<int> ToScreen(Vector<float> v) const {
-               return Vector<int>(OffsetOf(v));
+               return Vector<int>(OffsetOf(v)) + offset;
        }
        Vector<float> OffsetOf(Vector<float> v) const {
-               return ToScale(v - *target) + offset;
+               return ToScale(v - *target);
        }
        Vector<float> ToScale(Vector<float> v) const {
                return v * zoom;
@@ -35,7 +35,7 @@ public:
 
 private:
        const Vector<float> *target;
-       Vector<float> offset;
+       Vector<int> offset;
 
        float zoom;
        int zoomAcc;
index 606cc6113a3e21647f66b93dc78ad9a61215e0b4..5cd6bd7f363681680296e24f1c392550fa112f42 100644 (file)
@@ -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 (file)
index 781f23d..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-#include "Sector.h"
-
-#include <cstring>
-
-
-namespace space {
-
-Sector::Sector(Vector<int> 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 (file)
index d5c101c..0000000
+++ /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<int> size, int numres);
-       ~Sector();
-
-       Sector(const Sector &) = delete;
-       Sector &operator =(const Sector &) = delete;
-
-private:
-       Vector<int> size;
-       int numres;
-       int total;
-       int *res_begin;
-       int *res_end;
-
-};
-
-}
-
-#endif
index ec71fd1acc665a83e42ff80023b3195e0b78f8af..9f9efe627839eb4be29d33ed2751dc225fe0250a 100644 (file)
@@ -1,28 +1,20 @@
 #include "Universe.h"
 
-#include "Sector.h"
-
 #include <cstring>
 #include <memory>
 
 
 namespace space {
 
-Universe::Universe(Vector<int> size, Vector<int> secSize, Vector<int> areaSize, int numres)
+Universe::Universe(Vector<int> size, Vector<int> secSize, Vector<int> areaSize)
 : size(size)
 , secSize(secSize)
-, areaSize(areaSize)
-, numres(numres)
-, total(size.x * size.y)
-, sec_begin(reinterpret_cast<Sector *>(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<char *>(sec_begin);
+
 }
 
 
index 563bfd90000b545d56bf754778b5f39d1827ab4a..740592690fb86935f68fccb92eaadd9527fcda1d 100644 (file)
@@ -9,12 +9,10 @@
 
 namespace space {
 
-class Sector;
-
 class Universe {
 
 public:
-       Universe(Vector<int> size, Vector<int> secSize, Vector<int> areaSize, int numres);
+       Universe(Vector<int> size, Vector<int> secSize, Vector<int> areaSize);
        ~Universe();
 
        Universe(const Universe &) = delete;
@@ -25,6 +23,49 @@ public:
        const Vector<int> secSize;
        const Vector<int> areaSize;
 
+public:
+       class Area;
+
+       class Sector {
+
+       public:
+               Sector(const Universe &univ, Vector<int> coords)
+               : univ(univ), coords(coords) { }
+
+       public:
+               Vector<int> SectorCoords() const { return coords; }
+               Vector<int> AreaCoords() const { return univ.areaSize * coords; }
+
+               Area AreaAt(Vector<int> ac) const { return univ.AreaAt(AreaCoords() + ac); }
+
+       private:
+               const Universe &univ;
+               Vector<int> coords;
+
+       };
+
+       class Area {
+
+       public:
+               Area(const Universe &univ, Vector<int> coords)
+               : univ(univ), coords(coords) { }
+
+       public:
+               Vector<int> SectorCoords() const { return coords / univ.areaSize; }
+               Vector<int> AreaCoords() const { return coords; }
+
+               Sector ParentSector() const { return univ.SectorAt(SectorCoords()); }
+
+       private:
+               const Universe &univ;
+               Vector<int> coords;
+
+       };
+
+public:
+       Sector SectorAt(Vector<int> coords) const { return Sector(*this, coords); }
+       Area AreaAt(Vector<int> coords) const { return Area(*this, coords); }
+
 public:
        Entity *AddEntity(const Entity &);
        const std::list<Entity> &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<Entity> entities;
 
 };