Commit 3f478e49 authored by Ilya Prokhorov's avatar Ilya Prokhorov

Fixed by aStyle

parent 1550a023
......@@ -12,229 +12,232 @@ using namespace FlameSteelCore::Utils;
void EditorController::step() {
if (isInitialized == false) {
sceneSerializer = make<SceneSerializer>(toNotNull(objectsContext), toNotNull(shared_from_this()));
cursorColors.push_back(
CursorColor{255,255,255}
);
cursorColors.push_back(
CursorColor{255,255,0}
);
cursorColors.push_back(
CursorColor{0,255,255}
);
cursorColors.push_back(
CursorColor{0,255,0}
);
cursorColors.push_back(
CursorColor{255,0,255}
);
cursorColors.push_back(
CursorColor{255,0,0}
);
cursorColors.push_back(
CursorColor{0,0,255}
);
cursorColors.push_back(
CursorColor{0,0,0}
);
currentCursorColor = cursorColors[0];
camera = Factory::makeObject(
make_shared<string>("camera"),
make_shared<string>("camera"),
0,0,0,
1,1,1,
0,0,0
);
objectsContext->addObject(camera.sharedPointer());
freeCameraControlsController = make<FreeCameraControlsController>(camera, toNotNull(ioSystem->inputController), shared_from_this());
inputController = toNotNull(ioSystem->inputController);
auto cubeBuilder = make<CubeBuilder>();
auto cursorRed = currentCursorColor.red;
auto cursorGreen = currentCursorColor.green;
auto cursorBlue = currentCursorColor.blue;
cursorCube = toNotNull(cubeBuilder->makeCube(0, 0, 0, cursorRed, cursorGreen, cursorBlue));
objectsContext->addObject(cursorCube.sharedPointer());
if (startedSerializedScene.get() != nullptr) {
sceneSerializer->deserialize(toNotNull(startedSerializedScene));
}
isInitialized = true;
}
if (testRunner.get() != nullptr) {
testRunner->step();
}
auto cubeCursorPosition = freeCameraControlsController->cubeCursorPositionVector();
auto cubePositionVector = FSEGTUtils::getObjectPosition(cursorCube.sharedPointer());
cubePositionVector->x = cubeCursorPosition->x;
cubePositionVector->y = cubeCursorPosition->y;
cubePositionVector->z = cubeCursorPosition->z;
if (inputController->wheelDiffY > 0) {
cout << "Change color forward" << endl;
auto surfaceMaterial = FSEGTUtils::getObjectSurfaceMaterial(cursorCube.sharedPointer());
auto surface = surfaceMaterial->material->surface;
currentCursorIndex += 1;
if (currentCursorIndex >= cursorColors.size()) {
currentCursorIndex = 0;
}
currentCursorColor = cursorColors[currentCursorIndex];
auto cursorRed = currentCursorColor.red;
auto cursorGreen = currentCursorColor.green;
auto cursorBlue = currentCursorColor.blue;
SDL_FillRect(surface, NULL, SDL_MapRGB(surface->format, cursorRed, cursorGreen, cursorBlue));
surfaceMaterial->material->needsUpdate = true;
}
else if (inputController->wheelDiffY < 0) {
cout << "Change color backward" << endl;
auto surfaceMaterial = FSEGTUtils::getObjectSurfaceMaterial(cursorCube.sharedPointer());
auto surface = surfaceMaterial->material->surface;
currentCursorIndex -= 1;
if (currentCursorIndex <= 0) {
currentCursorIndex = cursorColors.size() - 1;
}
currentCursorColor = cursorColors[currentCursorIndex];
auto cursorRed = currentCursorColor.red;
auto cursorGreen = currentCursorColor.green;
auto cursorBlue = currentCursorColor.blue;
SDL_FillRect(surface, NULL, SDL_MapRGB(surface->format, cursorRed, cursorGreen, cursorBlue));
surfaceMaterial->material->needsUpdate = true;
}
objectsContext->updateObject(cursorCube.sharedPointer());
if (isInitialized == false) {
sceneSerializer = make<SceneSerializer>(toNotNull(objectsContext), toNotNull(shared_from_this()));
cursorColors.push_back(
CursorColor{255,255,255}
);
cursorColors.push_back(
CursorColor{255,255,0}
);
cursorColors.push_back(
CursorColor{0,255,255}
);
cursorColors.push_back(
CursorColor{0,255,0}
);
cursorColors.push_back(
CursorColor{255,0,255}
);
cursorColors.push_back(
CursorColor{255,0,0}
);
cursorColors.push_back(
CursorColor{0,0,255}
);
cursorColors.push_back(
CursorColor{0,0,0}
);
currentCursorColor = cursorColors[0];
camera = Factory::makeObject(
make_shared<string>("camera"),
make_shared<string>("camera"),
0,0,0,
1,1,1,
0,0,0
);
objectsContext->addObject(camera.sharedPointer());
freeCameraControlsController = make<FreeCameraControlsController>(camera, toNotNull(ioSystem->inputController), shared_from_this());
inputController = toNotNull(ioSystem->inputController);
auto cubeBuilder = make<CubeBuilder>();
auto cursorRed = currentCursorColor.red;
auto cursorGreen = currentCursorColor.green;
auto cursorBlue = currentCursorColor.blue;
cursorCube = toNotNull(cubeBuilder->makeCube(0, 0, 0, cursorRed, cursorGreen, cursorBlue));
objectsContext->addObject(cursorCube.sharedPointer());
if (startedSerializedScene.get() != nullptr) {
sceneSerializer->deserialize(toNotNull(startedSerializedScene));
}
isInitialized = true;
}
if (testRunner.get() != nullptr) {
testRunner->step();
}
auto cubeCursorPosition = freeCameraControlsController->cubeCursorPositionVector();
auto cubePositionVector = FSEGTUtils::getObjectPosition(cursorCube.sharedPointer());
cubePositionVector->x = cubeCursorPosition->x;
cubePositionVector->y = cubeCursorPosition->y;
cubePositionVector->z = cubeCursorPosition->z;
if (inputController->wheelDiffY > 0) {
cout << "Change color forward" << endl;
auto surfaceMaterial = FSEGTUtils::getObjectSurfaceMaterial(cursorCube.sharedPointer());
auto surface = surfaceMaterial->material->surface;
currentCursorIndex += 1;
if (currentCursorIndex >= cursorColors.size()) {
currentCursorIndex = 0;
}
currentCursorColor = cursorColors[currentCursorIndex];
auto cursorRed = currentCursorColor.red;
auto cursorGreen = currentCursorColor.green;
auto cursorBlue = currentCursorColor.blue;
SDL_FillRect(surface, NULL, SDL_MapRGB(surface->format, cursorRed, cursorGreen, cursorBlue));
surfaceMaterial->material->needsUpdate = true;
}
else if (inputController->wheelDiffY < 0) {
cout << "Change color backward" << endl;
auto surfaceMaterial = FSEGTUtils::getObjectSurfaceMaterial(cursorCube.sharedPointer());
auto surface = surfaceMaterial->material->surface;
currentCursorIndex -= 1;
if (currentCursorIndex <= 0) {
currentCursorIndex = cursorColors.size() - 1;
}
currentCursorColor = cursorColors[currentCursorIndex];
auto cursorRed = currentCursorColor.red;
auto cursorGreen = currentCursorColor.green;
auto cursorBlue = currentCursorColor.blue;
SDL_FillRect(surface, NULL, SDL_MapRGB(surface->format, cursorRed, cursorGreen, cursorBlue));
surfaceMaterial->material->needsUpdate = true;
}
objectsContext->updateObject(cursorCube.sharedPointer());
//cout << "EditorController step" << endl;
inputController->pollKey();
if (ioSystem->inputController.get() == nullptr) {
throwRuntimeException(string("ioSystem->inputController.get() == nullptr"));
}
if (ioSystem->inputController->touches->size() > 0) {
auto rawTouch = ioSystem->inputController->touches->objectAtIndex(0);
auto nowTouch = static_pointer_cast<FSEGTTouch>(rawTouch);
cout << "nowTouch:" << endl;
cout << nowTouch->x << endl;
cout << nowTouch->y << endl;
if (touch.get() == nullptr && nowTouch->x >= 480 && nowTouch->y >= 160 && nowTouch->x <= 645 && nowTouch->y <= 309) {
touch = nowTouch;
removeOrAddCubeAt(
cubePositionVector->x,
cubePositionVector->y,
cubePositionVector->z,
currentCursorColor.red,
currentCursorColor.green,
currentCursorColor.blue
);
cout << "Change color forward" << endl;
auto surfaceMaterial = FSEGTUtils::getObjectSurfaceMaterial(cursorCube.sharedPointer());
auto surface = surfaceMaterial->material->surface;
currentCursorIndex += 1;
if (currentCursorIndex >= cursorColors.size()) {
currentCursorIndex = 0;
}
currentCursorColor = cursorColors[currentCursorIndex];
auto cursorRed = currentCursorColor.red;
auto cursorGreen = currentCursorColor.green;
auto cursorBlue = currentCursorColor.blue;
SDL_FillRect(surface, NULL, SDL_MapRGB(surface->format, cursorRed, cursorGreen, cursorBlue));
surfaceMaterial->material->needsUpdate = true;
}
}
else if (ioSystem->inputController->useKeyPressed == true || ioSystem->inputController->shootKeyPressed == true) {
cout << "Use key pressed" << endl;
removeOrAddCubeAt(
cubePositionVector->x,
cubePositionVector->y,
cubePositionVector->z,
currentCursorColor.red,
currentCursorColor.green,
currentCursorColor.blue
);
sceneSerializer->serialize();
ioSystem->inputController->useKeyPressed = false;
}
if (ioSystem->inputController->touches->size() < 1) {
touch = shared_ptr<FSEGTTouch>();
}
if (renderer.get() == nullptr) {
throwRuntimeException(string("renderer == nullptr"));
}
inputController->pollKey();
if (ioSystem->inputController.get() == nullptr) {
throwRuntimeException(string("ioSystem->inputController.get() == nullptr"));
}
if (ioSystem->inputController->touches->size() > 0) {
auto rawTouch = ioSystem->inputController->touches->objectAtIndex(0);
auto nowTouch = static_pointer_cast<FSEGTTouch>(rawTouch);
cout << "nowTouch:" << endl;
cout << nowTouch->x << endl;
cout << nowTouch->y << endl;
if (touch.get() == nullptr && nowTouch->x >= 480 && nowTouch->y >= 160 && nowTouch->x <= 645 && nowTouch->y <= 309) {
touch = nowTouch;
removeOrAddCubeAt(
cubePositionVector->x,
cubePositionVector->y,
cubePositionVector->z,
currentCursorColor.red,
currentCursorColor.green,
currentCursorColor.blue
);
cout << "Change color forward" << endl;
auto surfaceMaterial = FSEGTUtils::getObjectSurfaceMaterial(cursorCube.sharedPointer());
auto surface = surfaceMaterial->material->surface;
currentCursorIndex += 1;
if (currentCursorIndex >= cursorColors.size()) {
currentCursorIndex = 0;
}
currentCursorColor = cursorColors[currentCursorIndex];
auto cursorRed = currentCursorColor.red;
auto cursorGreen = currentCursorColor.green;
auto cursorBlue = currentCursorColor.blue;
SDL_FillRect(surface, NULL, SDL_MapRGB(surface->format, cursorRed, cursorGreen, cursorBlue));
surfaceMaterial->material->needsUpdate = true;
}
}
else if (ioSystem->inputController->useKeyPressed == true || ioSystem->inputController->shootKeyPressed == true) {
cout << "Use key pressed" << endl;
useKeyWasPressed = true;
}
if (useKeyWasPressed && ioSystem->inputController->useKeyPressed == false && ioSystem->inputController->shootKeyPressed == false) {
removeOrAddCubeAt(
cubePositionVector->x,
cubePositionVector->y,
cubePositionVector->z,
currentCursorColor.red,
currentCursorColor.green,
currentCursorColor.blue
);
sceneSerializer->serialize();
useKeyWasPressed = false;
}
if (ioSystem->inputController->touches->size() < 1) {
touch = shared_ptr<FSEGTTouch>();
}
if (renderer.get() == nullptr) {
throwRuntimeException(string("renderer == nullptr"));
}
renderer->render(gameData);
freeCameraControlsController->step();
freeCameraControlsController->step();
};
void EditorController::freeCameraControlsControllerDidFinish(shared_ptr<FreeCameraControlsController> freeCameraControlsController) {
objectsContext->updateObject(camera.sharedPointer());
objectsContext->updateObject(camera.sharedPointer());
};
void EditorController::removeOrAddCubeAt(int x, int y, int z, int redColor, int greenColor, int blueColor) {
cout << "removeOrAddCubeAtFront()" << endl;
cout << "removeOrAddCubeAtFront()" << endl;
if (objectsContext.get() == nullptr) {
throwRuntimeException(string("objectsContext is null"));
}
if (objectsContext.get() == nullptr) {
throwRuntimeException(string("objectsContext is null"));
}
cout << "EditorController::removeOrAddCubeAtFront()" << endl;
cout << "EditorController::removeOrAddCubeAtFront()" << endl;
auto cube = field3D->cubeAtXYZ(x, y, z);
auto cube = field3D->cubeAtXYZ(x, y, z);
if (cube.get() != nullptr) {
field3D->removeCubeAtXYZ(x, y, z);
objectsContext->removeObject(cube);
cout << "objectsContext->removeObject(cube);" << endl;
}
else {
auto cubeBuilder = make_shared<CubeBuilder>();
if (cube.get() != nullptr) {
field3D->removeCubeAtXYZ(x, y, z);
objectsContext->removeObject(cube);
cout << "objectsContext->removeObject(cube);" << endl;
}
else {
auto cubeBuilder = make_shared<CubeBuilder>();
auto cursorRed = redColor;
auto cursorGreen = greenColor;
auto cursorBlue = blueColor;
auto cursorRed = redColor;
auto cursorGreen = greenColor;
auto cursorBlue = blueColor;
auto cube = cubeBuilder->makeCube(x, y, z, cursorRed, cursorGreen, cursorBlue);
field3D->addCubeAtXYZ(cube, x, y, z);
auto cube = cubeBuilder->makeCube(x, y, z, cursorRed, cursorGreen, cursorBlue);
field3D->addCubeAtXYZ(cube, x, y, z);
FSEGTUtils::getObjectPosition(cube)->x = x;
FSEGTUtils::getObjectPosition(cube)->y = y;
FSEGTUtils::getObjectPosition(cube)->z = z;
FSEGTUtils::getObjectPosition(cube)->x = x;
FSEGTUtils::getObjectPosition(cube)->y = y;
FSEGTUtils::getObjectPosition(cube)->z = z;
objectsContext->addObject(cube);
cout << "objectsContext->addObject(cube);" << endl;
}
objectsContext->addObject(cube);
cout << "objectsContext->addObject(cube);" << endl;
}
};
......@@ -10,9 +10,9 @@
#include <CubeArtProject/Utils/SceneSerializer/SceneSerializer.h>
struct CursorColor {
int red = 0;
int green = 0;
int blue = 0;
int red = 0;
int green = 0;
int blue = 0;
};
using namespace std;
......@@ -23,32 +23,34 @@ namespace CubeArtProject {
class EditorController: public GameController, public enable_shared_from_this<EditorController>, public FreeCameraControlsControllerDelegate {
public:
virtual void step();
virtual void freeCameraControlsControllerDidFinish(shared_ptr<FreeCameraControlsController> freeCameraControlsController);
virtual void step();
virtual void freeCameraControlsControllerDidFinish(shared_ptr<FreeCameraControlsController> freeCameraControlsController);
shared_ptr<TestRunner> testRunner;
void removeOrAddCubeAt(int x, int y, int z, int redColor, int greenColor, int blueColor);
shared_ptr<TestRunner> testRunner;
void removeOrAddCubeAt(int x, int y, int z, int redColor, int greenColor, int blueColor);
shared_ptr<string> startedSerializedScene;
shared_ptr<string> startedSerializedScene;
private:
NotNull<SceneSerializer> sceneSerializer;
NotNull<Object> cursorCube;
CursorColor currentCursorColor;
int currentCursorIndex = 0;
bool useKeyWasPressed = false;
shared_ptr<Field3D> field3D = make_shared<Field3D>();
NotNull<FreeCameraControlsController> freeCameraControls;
NotNull<Object> camera;
NotNull<FreeCameraControlsController> freeCameraControlsController;
NotNull<InputController> inputController;
NotNull<SceneSerializer> sceneSerializer;
NotNull<Object> cursorCube;
CursorColor currentCursorColor;
int currentCursorIndex = 0;
vector<CursorColor> cursorColors;
shared_ptr<Field3D> field3D = make_shared<Field3D>();
NotNull<FreeCameraControlsController> freeCameraControls;
NotNull<Object> camera;
NotNull<FreeCameraControlsController> freeCameraControlsController;
NotNull<InputController> inputController;
bool isInitialized = false;
vector<CursorColor> cursorColors;
shared_ptr<FSEGTTouch> touch;
bool isInitialized = false;
shared_ptr<FSEGTTouch> touch;
};
};
......
......@@ -21,7 +21,7 @@ void CubeArtProject::MainGameController::start() {
window = ioSystem->getWindow();
mainGameController->setIOSystem(ioSystem->getFSGLIOSystem());
inputController = ioSystem->getFSGLIOSystem()->inputController;
inputController = ioSystem->getFSGLIOSystem()->inputController;
};
......@@ -39,7 +39,7 @@ shared_ptr<Window> CubeArtProject::MainGameController::getWindow() {
};
void CubeArtProject::MainGameController::startGameLoop() {
mainGameController->startGameLoop();
mainGameController->startGameLoop();
}
void CubeArtProject::MainGameController::switchToEditorState() {
......@@ -47,8 +47,8 @@ void CubeArtProject::MainGameController::switchToEditorState() {
return;
}
state = editor;
editorController->testRunner = testRunner;
editorController->startedSerializedScene = startedSerializedScene;
editorController->testRunner = testRunner;
editorController->startedSerializedScene = startedSerializedScene;
mainGameController->initializeGameFromState(editor);
};
......
......@@ -24,13 +24,13 @@ public:
void switchToEditorState();
shared_ptr<Screenshot> takeScreenshot();
void startGameLoop();
void doStep();
void startGameLoop();
void doStep();
shared_ptr<FSEGTInputController> inputController;
shared_ptr<TestRunner> testRunner;
shared_ptr<FSEGTInputController> inputController;
shared_ptr<TestRunner> testRunner;
shared_ptr<string> startedSerializedScene;
shared_ptr<string> startedSerializedScene;
private:
shared_ptr<IOSystem> ioSystem;
......
......@@ -9,15 +9,15 @@ using namespace Shortcuts;
class Cube {
public:
int redColor;
int greenColor;
int blueColor;
int x;
int y;
int z;
int redColor;
int greenColor;
int blueColor;