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())
Camera::Camera(int w, int h, const Vector<float> &t)
: target(&t)
, offset(w/2, h/2)
-, zoom(1) {
+, zoom(1)
+, zoomAcc(0) {
}
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;
private:
const Vector<float> *target;
- Vector<float> offset;
+ Vector<int> offset;
float zoom;
int zoomAcc;
#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;
+++ /dev/null
-#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;
-}
-
-}
+++ /dev/null
-#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
#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);
+
}
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;
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; }
void Update(float deltaT);
private:
-
- int numres;
- int total;
-
- Sector *sec_begin;
- Sector *sec_end;
-
std::list<Entity> entities;
};