Commit b7f08820 authored by 魔大农's avatar 魔大农

Avoided passing Context and MasterControl pointers

parent 0edb6bbb
......@@ -2917,6 +2917,39 @@
fx="-172.85402"
fy="566.65106"
r="156.43126" />
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient4841"
id="radialGradient6101"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(7.6275385e-8,1.6329197,-1.9043716,8.8955188e-8,-358.45081,703.44583)"
cx="-172.85405"
cy="566.65106"
fx="-172.85405"
fy="566.65106"
r="109.35714" />
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient4841"
id="radialGradient6103"
gradientUnits="userSpaceOnUse"
cx="-172.85403"
cy="566.65106"
fx="-172.85402"
fy="566.65106"
r="156.43126"
gradientTransform="translate(-1264.711,-145.46197)" />
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient4841"
id="radialGradient5098"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(7.6275385e-8,1.6329197,-1.9043716,8.8955188e-8,401.1839,848.9078)"
cx="-172.85405"
cy="566.65106"
fx="-172.85405"
fy="566.65106"
r="109.35714" />
</defs>
<sodipodi:namedview
id="base"
......@@ -2925,17 +2958,17 @@
borderopacity="1.0"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:zoom="0.061871843"
inkscape:cx="5975.7572"
inkscape:cy="-5278.1825"
inkscape:zoom="0.24748737"
inkscape:cx="-785.49702"
inkscape:cy="-426.497"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
showborder="false"
inkscape:window-width="1920"
inkscape:window-height="1032"
inkscape:window-height="1056"
inkscape:window-x="0"
inkscape:window-y="24"
inkscape:window-y="0"
inkscape:window-maximized="1"
showguides="true"
inkscape:guide-bbox="true" />
......@@ -2947,7 +2980,7 @@
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
......@@ -9868,5 +9901,60 @@
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#47108b;stroke-width:23;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
id="circle8122" />
</g>
<g
id="g6105"
transform="translate(351.53309,177.78685)"
inkscape:export-filename="/home/frode/Sync/Creations/Games/Quatter/Resources/icon.png"
inkscape:export-xdpi="31.68"
inkscape:export-ydpi="31.68">
<path
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:url(#radialGradient6101);fill-opacity:1;fill-rule:evenodd;stroke:#47108b;stroke-width:23;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
id="path6095"
sodipodi:type="arc"
sodipodi:cx="-1437.5681"
sodipodi:cy="421.18597"
sodipodi:rx="195.71428"
sodipodi:ry="195.71428"
sodipodi:start="0"
sodipodi:end="1.5707963"
d="m -1241.8538,421.18597 a 195.71428,195.71428 0 0 1 -195.7143,195.71428 l 0,-195.71428 z" />
<path
id="path6097"
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:url(#radialGradient6103);fill-opacity:1;fill-rule:evenodd;stroke:#47108b;stroke-width:23;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
sodipodi:type="arc"
sodipodi:cx="-1437.5681"
sodipodi:cy="421.18597"
sodipodi:rx="144.93436"
sodipodi:ry="144.93436"
sodipodi:start="1.5707963"
sodipodi:end="0"
d="m -1437.5681,566.12033 a 144.93436,144.93436 0 0 1 -133.9019,-89.47038 144.93436,144.93436 0 0 1 31.4178,-157.94804 144.93436,144.93436 0 0 1 157.9481,-31.41782 144.93436,144.93436 0 0 1 89.4703,133.90188 l -144.9343,0 z" />
<path
d="m -1437.567,515.58221 a 94.395134,94.395134 0 0 1 -87.2097,-58.27168 94.395134,94.395134 0 0 1 20.4622,-102.8709 94.395134,94.395134 0 0 1 102.8709,-20.46229 94.395134,94.395134 0 0 1 58.2717,87.20973"
sodipodi:end="0"
sodipodi:start="1.5707963"
sodipodi:ry="94.395134"
sodipodi:rx="94.395134"
sodipodi:cy="421.18707"
sodipodi:cx="-1437.567"
sodipodi:type="arc"
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#47108b;stroke-width:23;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
id="path6099"
sodipodi:open="true" />
</g>
<path
d="m -482.21913,566.64795 a 195.71428,195.71428 0 0 1 -195.71428,195.71428 l 0,-195.71428 z"
sodipodi:end="1.5707963"
sodipodi:start="0"
sodipodi:ry="195.71428"
sodipodi:rx="195.71428"
sodipodi:cy="566.64795"
sodipodi:cx="-677.93341"
sodipodi:type="arc"
id="path5096"
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:url(#radialGradient5098);fill-opacity:1;fill-rule:evenodd;stroke:#47108b;stroke-width:23;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
inkscape:export-filename="/home/frode/Sync/Creations/Games/Quatter/Resources/Textures/Cursor.png"
inkscape:export-xdpi="105.34291"
inkscape:export-ydpi="105.34291" />
</g>
</svg>
#include "board.h"
Board::Board(Context* context, MasterControl *masterControl): Object(context),
masterControl_{masterControl}
Board::Board(): Object(MC->GetContext())
{
Node* rootNode = masterControl_->world.scene->CreateChild("Board");
Node* rootNode = MC->world.scene->CreateChild("Board");
model_ = rootNode->CreateComponent<StaticModel>();
model_->SetModel(masterControl_->cache_->GetResource<Model>("Resources/Models/Board.mdl"));
model_->SetMaterial(masterControl_->cache_->GetResource<Material>("Resources/Materials/Board.xml"));
model_->SetModel(MC->cache_->GetResource<Model>("Resources/Models/Board.mdl"));
model_->SetMaterial(MC->cache_->GetResource<Material>("Resources/Materials/Board.xml"));
model_->SetCastShadows(true);
}
......@@ -15,10 +15,9 @@ class Board : public Object
{
URHO3D_OBJECT(Board, Object);
public:
Board(Context *context, MasterControl* masterControl);
Board();
float GetHeight() const { return model_->GetBoundingBox().Size().y_; }
private:
MasterControl* masterControl_;
StaticModel* model_;
};
......
#include "inputmaster.h"
#include "quattercam.h"
InputMaster::InputMaster(Context* context, MasterControl* masterControl) : Master(context, masterControl),
InputMaster::InputMaster() : Master(),
input_{GetSubsystem<Input>()}
{
SubscribeToEvent(E_MOUSEBUTTONDOWN, URHO3D_HANDLER(InputMaster, HandleMouseButtonDown));
......@@ -22,7 +22,7 @@ void InputMaster::HandleKeyDown(StringHash eventType, VariantMap &eventData)
switch (key){
//Exit when ESC is pressed
case KEY_ESC:{
masterControl_->Exit();
MC->Exit();
} break;
//Take screenshot when 9 is pressed
case KEY_9:{
......@@ -81,6 +81,6 @@ void InputMaster::HandleUpdate(StringHash eventType, VariantMap &eventData)
if (input_->GetMouseButtonDown(2)){
IntVector2 mouseMove = input_->GetMouseMove();
Vector2 rotation = Vector2(mouseMove.x_, mouseMove.y_) * 0.23f;
masterControl_->world.camera->Rotate(rotation);
MC->world.camera->Rotate(rotation);
}
}
......@@ -9,7 +9,7 @@ class InputMaster : public Master
{
URHO3D_OBJECT(InputMaster, Master);
public:
InputMaster(Context* context, MasterControl* masterControl);
InputMaster();
WeakPtr<Node> firstHit_;
private:
Input* input_;
......
#include "master.h"
Master::Master(Context* context, MasterControl *masterControl): Object(context),
masterControl_{masterControl}
Master::Master(): Object(MC->GetContext())
{
}
......@@ -15,11 +15,11 @@ using namespace Urho3D;
class Master : public Object
{
friend class MasterControl;
URHO3D_OBJECT(Master, Object);
public:
Master(Context *context, MasterControl* masterControl);
Master();
protected:
MasterControl* masterControl_;
// virtual void HandleUpdate(StringHash eventType, VariantMap &eventData);
};
......
......@@ -5,23 +5,33 @@
URHO3D_DEFINE_APPLICATION_MAIN(MasterControl);
MasterControl* MasterControl::instance_ = NULL;
MasterControl* MasterControl::GetInstance()
{
return MasterControl::instance_;
}
MasterControl::MasterControl(Context *context):
Application(context),
gamePhase_{GamePhase::PLAYER1PICKS}
{
instance_ = this;
}
void MasterControl::Setup()
{
engineParameters_["WindowTitle"] = "Quatter";
engineParameters_["LogName"] = GetSubsystem<FileSystem>()->GetAppPreferencesDir("urho3d", "logs")+"Quatter.log";
engineParameters_["ResourcePaths"] = "Data;CoreData;Resources";
engineParameters_["WindowIcon"] = "icon.png";
// engineParameters_["FullScreen"] = false;
// engineParameters_["WindowWidth"] = 960;
// engineParameters_["WindowHeight"] = 540;
}
void MasterControl::Start()
{
new InputMaster(context_, this);
new InputMaster();
cache_ = GetSubsystem<ResourceCache>();
CreateScene();
......@@ -47,7 +57,7 @@ void MasterControl::CreateScene()
{
world.scene = new Scene(context_);
world.scene->CreateComponent<Octree>();
world.camera = new QuatterCam(context_, this);
world.camera = new QuatterCam();
CreateLights();
//Create table
......@@ -60,11 +70,11 @@ void MasterControl::CreateScene()
tableModel->GetMaterial()->SetShaderParameter("MatDiffColor", Vector4(0.32f, 0.40f, 0.42f, 1.0f));
//Create board and pieces
world.board_ = new Board(context_, this);
world.board_ = new Board();
tableNode->SetPosition(Vector3::DOWN * world.board_->GetHeight());
for (int p = 0; p < 16; ++p){
Piece* newPiece = new Piece(context_, this, std::bitset<4>(p));
Piece* newPiece = new Piece(std::bitset<4>(p));
world.pieces_.Push(SharedPtr<Piece>(newPiece));
newPiece->SetPosition(Quaternion(360.0f/16 * p, Vector3::UP) * Vector3::RIGHT * 6.66f +
Vector3::DOWN * world.board_->GetHeight());
......
......@@ -33,12 +33,16 @@ typedef struct GameWorld
} cursor;
} GameWorld;
#define MC MasterControl::GetInstance()
class MasterControl : public Application
{
URHO3D_OBJECT(MasterControl, Application);
friend class InputMaster;
public:
MasterControl(Context* context);
static MasterControl* GetInstance();
GameWorld world;
SharedPtr<ResourceCache> cache_;
SharedPtr<Graphics> graphics_;
......@@ -54,6 +58,8 @@ public:
void CreateLights();
inline GamePhase GetGamePhase() const noexcept { return gamePhase_; }
private:
static MasterControl* instance_;
GamePhase gamePhase_;
Node* movingLightNode_;
......
#include "piece.h"
Piece::Piece(Context* context, MasterControl *masterControl, std::bitset<4> attributes): Object(context),
masterControl_{masterControl}
Piece::Piece(std::bitset<4> attributes): Object(MC->GetContext()),
state_{PieceState::FREE}
{
rootNode_ = masterControl_->world.scene->CreateChild("Piece");
rootNode_ = MC->world.scene->CreateChild("Piece");
rootNode_->SetRotation(Quaternion(Random(360.0f), Vector3::UP));
attributes_ = attributes;
......@@ -12,27 +12,27 @@ Piece::Piece(Context* context, MasterControl *masterControl, std::bitset<4> attr
model->SetCastShadows(true);
switch (attributes.to_ulong()){
case 0: case 8: model->SetModel(masterControl_->cache_->GetResource<Model>("Resources/Models/Piece_SSS.mdl"));
case 0: case 8: model->SetModel(MC->cache_->GetResource<Model>("Resources/Models/Piece_SSS.mdl"));
break;
case 1: case 9: model->SetModel(masterControl_->cache_->GetResource<Model>("Resources/Models/Piece_SSH.mdl"));
case 1: case 9: model->SetModel(MC->cache_->GetResource<Model>("Resources/Models/Piece_SSH.mdl"));
break;
case 2: case 10: model->SetModel(masterControl_->cache_->GetResource<Model>("Resources/Models/Piece_SRS.mdl"));
case 2: case 10: model->SetModel(MC->cache_->GetResource<Model>("Resources/Models/Piece_SRS.mdl"));
break;
case 3: case 11: model->SetModel(masterControl_->cache_->GetResource<Model>("Resources/Models/Piece_SRH.mdl"));
case 3: case 11: model->SetModel(MC->cache_->GetResource<Model>("Resources/Models/Piece_SRH.mdl"));
break;
case 4: case 12: model->SetModel(masterControl_->cache_->GetResource<Model>("Resources/Models/Piece_TSS.mdl"));
case 4: case 12: model->SetModel(MC->cache_->GetResource<Model>("Resources/Models/Piece_TSS.mdl"));
break;
case 5: case 13: model->SetModel(masterControl_->cache_->GetResource<Model>("Resources/Models/Piece_TSH.mdl"));
case 5: case 13: model->SetModel(MC->cache_->GetResource<Model>("Resources/Models/Piece_TSH.mdl"));
break;
case 6: case 14: model->SetModel(masterControl_->cache_->GetResource<Model>("Resources/Models/Piece_TRS.mdl"));
case 6: case 14: model->SetModel(MC->cache_->GetResource<Model>("Resources/Models/Piece_TRS.mdl"));
break;
case 7: case 15: model->SetModel(masterControl_->cache_->GetResource<Model>("Resources/Models/Piece_TRH.mdl"));
case 7: case 15: model->SetModel(MC->cache_->GetResource<Model>("Resources/Models/Piece_TRH.mdl"));
break;
}
if (attributes[3]){
model->SetMaterial(masterControl_->cache_->GetResource<Material>("Resources/Materials/Wood_dark.xml"));
model->SetMaterial(MC->cache_->GetResource<Material>("Resources/Materials/Wood_dark.xml"));
}
else model->SetMaterial(masterControl_->cache_->GetResource<Material>("Resources/Materials/Wood_light.xml"));
else model->SetMaterial(MC->cache_->GetResource<Material>("Resources/Materials/Wood_light.xml"));
}
......@@ -17,12 +17,11 @@ class Piece : public Object
{
URHO3D_OBJECT(Piece, Object);
public:
Piece(Context *context, MasterControl* masterControl, std::bitset<4> attributes);
Piece(std::bitset<4> attributes);
void SetPosition(Vector3 pos) { rootNode_->SetPosition(pos); }
inline bool GetAttribute(int index) const noexcept { return attributes_[index]; }
private:
MasterControl* masterControl_;
Node* rootNode_;
std::bitset<4> attributes_;
PieceState state_;
......
#include "quattercam.h"
QuatterCam::QuatterCam(Context *context, MasterControl *masterControl):
Object(context),
QuatterCam::QuatterCam():
Object(MC->GetContext()),
distance_{23.0f},
dollyRotation_{Vector2::ZERO},
targetPosition_{Vector3::ZERO},
lastTargetPosition_{Vector3::ZERO}
{
masterControl_ = masterControl;
rootNode_ = masterControl_->world.scene->CreateChild("Camera");
rootNode_ = MC->world.scene->CreateChild("Camera");
camera_ = rootNode_->CreateComponent<Camera>();
camera_->SetFarClip(1024.0f);
rootNode_->SetPosition(Vector3(3.0f, 5.0f, -11.0f));
......@@ -26,14 +24,14 @@ QuatterCam::QuatterCam(Context *context, MasterControl *masterControl):
void QuatterCam::SetupViewport()
{
//Set up a viewport to the Renderer subsystem so that the 3D scene can be seen
SharedPtr<Viewport> viewport(new Viewport(context_, masterControl_->world.scene, camera_));
SharedPtr<Viewport> viewport(new Viewport(context_, MC->world.scene, camera_));
viewport_ = viewport;
//Add anti-asliasing and bloom
effectRenderPath_ = viewport_->GetRenderPath()->Clone();
effectRenderPath_->Append(masterControl_->cache_->GetResource<XMLFile>("PostProcess/FXAA3.xml"));
effectRenderPath_->Append(MC->cache_->GetResource<XMLFile>("PostProcess/FXAA3.xml"));
effectRenderPath_->SetEnabled("FXAA3", true);
effectRenderPath_->Append(masterControl_->cache_->GetResource<XMLFile>("PostProcess/Bloom.xml"));
effectRenderPath_->Append(MC->cache_->GetResource<XMLFile>("PostProcess/Bloom.xml"));
effectRenderPath_->SetShaderParameter("BloomThreshold", 0.23f);
effectRenderPath_->SetShaderParameter("BloomMix", Vector2(1.75f, 1.25f));
effectRenderPath_->SetEnabled("Bloom", true);
......
......@@ -22,7 +22,7 @@ class QuatterCam : public Object
friend class MasterControl;
friend class InputMaster;
public:
QuatterCam(Context *context, MasterControl* masterControl);
QuatterCam();
SharedPtr<Camera> camera_;
SharedPtr<Viewport> viewport_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment