Skip to content

Commit

Permalink
Added basic camera, not completely finished yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
wqking committed Feb 15, 2017
1 parent 7c47866 commit 87dbf88
Show file tree
Hide file tree
Showing 14 changed files with 420 additions and 148 deletions.
1 change: 1 addition & 0 deletions include/gincu/gcomponentcamera.h
Expand Up @@ -36,6 +36,7 @@ class GComponentCamera : public GComponent
uint32_t getMask() const { return this->camera.getMask(); }

bool belongs(const unsigned int cameraId) const { return this->camera.belongs(cameraId); }
const GCamera & getCamera() const { return this->camera; }

private:
void onEntityEvent(GComponent * component, const GEntityEventType eventType);
Expand Down
33 changes: 32 additions & 1 deletion include/gincu/gcomponentmanager.h
Expand Up @@ -5,6 +5,7 @@

#include <vector>
#include <map>
#include <memory>

namespace gincu {

Expand All @@ -18,6 +19,35 @@ class GComponentManager
{
private:
typedef std::vector<GComponent *> ComponentListType;

struct CameraInfo
{
CameraInfo();
explicit CameraInfo(GComponentCamera * camera);

void loadRootTransformList(const std::vector<GComponentTransform *> & componentList);
void loadTouchHandlerList(const std::vector<GComponent *> & componentList);

void zOrderChanged(GComponentTransform * transform);
void cameraIdChanged(GComponentTransform * transform, const unsigned int oldCameraId);

void addTransform(GComponentTransform * component);
void removeTransform(GComponentTransform * component);
void addTouchHandler(GComponent * component);
void removeTouchHandler(GComponent * component);

bool belongs(const GComponent * component);

void render();
void findTouchHandlers(const GPoint & position, std::vector<GComponentTouchHandler *> * outputResult);

GComponentCamera * camera;
std::vector<GComponentTransform *> rootTransformList;
bool needSortRootTransformList;
std::vector<GComponent *> touchHandlerList;
};

typedef std::shared_ptr<CameraInfo> CameraInfoPointer;

public:
GComponentManager();
Expand All @@ -28,7 +58,7 @@ class GComponentManager

void parentChanged(GComponentLocalTransform * localTransform);
void zOrderChanged(GComponentTransform * transform); // this can be either a global or local transform
void cameraIdChanged(GComponentTransform * transform);
void cameraIdChanged(GComponentTransform * transform, const unsigned int oldCameraId);
void cameraMaskChanged(GComponentCamera * camera);

void updateAnimation();
Expand All @@ -51,6 +81,7 @@ class GComponentManager
std::map<unsigned int, ComponentListType> componentListColdMap;
mutable std::vector<GComponentTransform *> rootTransformList;
mutable bool needSortRootTransformList;
mutable std::vector<CameraInfoPointer> cameraInfoList;
mutable bool needSortCameraList;
};

Expand Down
2 changes: 1 addition & 1 deletion include/gincu/gcomponentrender.h
Expand Up @@ -102,7 +102,7 @@ class GComponentRenderCommon : public GComponentRender
virtual void doDraw() override {
GComponentTransform * transform = this->getEntity()->template getComponentByType<GComponentTransform>();
if(transform->isVisible()) {
this->render.draw(computeRenderableTransform(transform, this), this->getRenderInfo());
this->render.draw(computeRenderableMatrix(transform, this), this->getRenderInfo());
}
}

Expand Down
1 change: 0 additions & 1 deletion include/gincu/gcomponenttransform.h
Expand Up @@ -45,7 +45,6 @@ class GComponentTransform : public GComponent
GComponentTransform * setZOrder(const int zOrder);

const GTransform & getTransform() const { return this->transform; }
GTransform & getTransform() { return this->transform; }
GComponentTransform * setTransform(const GTransform & transform) { this->transform = transform; return this; }

private:
Expand Down
6 changes: 3 additions & 3 deletions include/gincu/gentityutil.h
Expand Up @@ -19,7 +19,7 @@ void enumerateEntityChildren(GComponentLocalTransform * localTransform, const Ca
}

template <typename T>
T * getComponentByTypeFromComponent(GComponent * component)
T * getComponentByTypeFromComponent(const GComponent * component)
{
if(component != nullptr) {
GEntity * entity = component->getEntity();
Expand All @@ -35,8 +35,8 @@ class GComponentRender;
class GEntity;
class GComponentManager;

GMatrix44 computeRenderableTransform(GComponentTransform * componentTransform, const GSize & size);
GMatrix44 computeRenderableTransform(GComponentTransform * componentTransform, GComponentRender * render = nullptr);
GMatrix44 computeRenderableMatrix(GComponentTransform * componentTransform, const GSize & size);
GMatrix44 computeRenderableMatrix(GComponentTransform * componentTransform, GComponentRender * render = nullptr);

GComponentManager * getComponentManagerFromEntity(const GEntity * entity);
GComponentLocalTransform * getParentLocalTransform(const GEntity * entity);
Expand Down
8 changes: 6 additions & 2 deletions include/gincu/gscene.h
Expand Up @@ -2,7 +2,6 @@
#define GSCENE_H

#include "gincu/ggeometry.h"
#include "gincu/gcomponentmanager.h"

#include "cpgf/tween/gtweenlist.h"

Expand All @@ -11,6 +10,7 @@

namespace gincu {

class GComponentManager;
class GEntity;
struct GEvent;

Expand Down Expand Up @@ -39,13 +39,17 @@ class GScene

cpgf::GTweenList * getTweenList() { return &this->tweenList; }

private:
void initializePrimaryCamera();

private:
virtual void doOnEnter();
virtual void doOnExit();

private:
GComponentManager componentManager;
std::unique_ptr<GComponentManager> componentManager;
std::vector<EntityPointer> entityList;
GEntity * primaryCamera;
GEntity * touchCapture;
cpgf::GTweenList tweenList;
};
Expand Down
6 changes: 6 additions & 0 deletions include/gincu/gutil.h
Expand Up @@ -34,6 +34,12 @@ void removeValueFromContainer(C & container, const V & value)
container.erase(std::remove(container.begin(), container.end(), value), container.end());
}

template <typename C, typename V>
void removeIfValueFromContainer(C & container, const V & predication)
{
container.erase(std::remove_if(container.begin(), container.end(), predication), container.end());
}


inline bool isEqual(const int a, const int b)
{
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Expand Up @@ -17,7 +17,7 @@ Now there is a match-three game in the project. In the future we may add more ga

## Version

1.0.1
0.0.1

## Supported platform

Expand Down

0 comments on commit 87dbf88

Please sign in to comment.