Merge pull request #54 from QuasarApp/engineRefactoring

Engine refactoring
This commit is contained in:
Andrei Yankovich 2021-06-16 20:53:33 +03:00 committed by GitHub
commit fb6d06e2f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
68 changed files with 401 additions and 381 deletions

View File

@ -6,7 +6,7 @@
#
cmake_minimum_required(VERSION 3.14)
project(SnakeProject)
project(Crawl)
if(TARGET ${PROJECT_NAME})
message("The ${PROJECT_NAME} arledy included in main Project")
return()
@ -33,22 +33,22 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(QT_VERSION_MAJOR 5)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Test REQUIRED)
if (NOT DEFINED SNAKEPROJECT_TESTS)
set(SNAKEPROJECT_TESTS ON)
if (NOT DEFINED CRAWL_TESTS)
set(CRAWL_TESTS ON)
message(1)
if (DEFINED TARGET_PLATFORM_TOOLCHAIN)
if (${TARGET_PLATFORM_TOOLCHAIN} STREQUAL "wasm32")
set(SNAKEPROJECT_TESTS OFF)
set(CRAWL_TESTS OFF)
endif()
endif()
if (ANDROID)
set(SNAKEPROJECT_TESTS OFF)
set(CRAWL_TESTS OFF)
endif()
if (NOT QT_VERSION_MAJOR)
set(SNAKEPROJECT_TESTS OFF)
set(CRAWL_TESTS OFF)
message(2)
endif()
endif()
@ -69,7 +69,7 @@ add_subdirectory(src/CrawlTestLvl)
add_subdirectory(src/Client)
if (SNAKEPROJECT_TESTS)
if (CRAWL_TESTS)
add_subdirectory(tests)
else()
message("The ${PROJECT_NAME} tests is disabled.")

View File

@ -1,7 +1,7 @@
{
"bin": [
"src/Client/SnakeProject",
"src/Client/SnakeProject.exe"
"src/Client/Crawl",
"src/Client/Crawl.exe"
],
"clear": true,
"libDir": "./../",

View File

@ -32,7 +32,7 @@ DOXYFILE_ENCODING = UTF-8
# title of most generated pages and in a few other places.
# The default value is: My Project.
PROJECT_NAME = SnakeProject
PROJECT_NAME = Crawl
# The PROJECT_NUMBER tag can be used to enter a project or revision number. This
# could be handy for archiving the generated documentation or if some version

View File

@ -50,8 +50,8 @@ if (ANDROID)
addDeployAPK(${CURRENT_PROJECT}
"${CMAKE_CURRENT_LIST_DIR}/android"
"SnakeProject"
"${SIGPATH}/SnakeProject.keystore"
"Crawl"
"${SIGPATH}/Crawl.keystore"
"${SIGPASS_SNAKE}"
"${TARGET_DIR}"
"${SNAKE_EXTRA_LIBS}")
@ -60,8 +60,8 @@ if (ANDROID)
else()
# Desctop deploying
addDeployFromCustomFile("SnakeProject"
"${CMAKE_CURRENT_SOURCE_DIR}/../../Deploy/SnakeProject.json")
addDeployFromCustomFile("Crawl"
"${CMAKE_CURRENT_SOURCE_DIR}/../../Deploy/Crawl.json")
endif()

View File

@ -1,7 +1,7 @@
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <SnakeProject/clientapp.h>
#include <Crawl/clientapp.h>
int main(int argc, char *argv[])

View File

@ -8,13 +8,13 @@
cmake_minimum_required(VERSION 3.14)
set(CURRENT_PROJECT "${PROJECT_NAME}Core")
add_definitions(-DSnakeProject_LIBRARY)
add_definitions(-DCRAWL_LIBRARY)
file(GLOB SOURCE_CPP
"*SnakeProject/*.cpp"
"*Crawl/*.cpp"
"private/*.cpp"
"*.qrc"
"SnakeProject/*.qrc"
"Crawl/*.qrc"
"private/*.qrc"
)
@ -47,4 +47,4 @@ set(LANGS ${CMAKE_CURRENT_SOURCE_DIR}/languages/en.ts
prepareQM(${CURRENT_PROJECT} ${CMAKE_CURRENT_SOURCE_DIR}/../ "${LANGS}")
set(QML_IMPORT_PATH ${QML_IMPORT_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/src" CACHE STRING "" FORCE)
set(QML_IMPORT_PATH ${QML_IMPORT_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/" CACHE STRING "" FORCE)

32
src/Core/Crawl.qrc Normal file
View File

@ -0,0 +1,32 @@
<RCC>
<qresource prefix="/">
<file>CrawlModule/qmldir</file>
<file>CrawlModule/Crawl.qml</file>
<file>CrawlModule/GraphicItem.qml</file>
<file>CrawlModule/MainMenu.qml</file>
<file>CrawlModule/MainMenuButton.qml</file>
<file>CrawlModule/Metrix.qml</file>
<file>CrawlModule/PagePopUp.qml</file>
<file>CrawlModule/Scene.qml</file>
<file>CrawlModule/SettingsView.qml</file>
<file>CrawlModule/SnakeItem.qml</file>
<file>CrawlModule/SelectLvlView.qml</file>
<file>CrawlModule/DefaultMenu.qml</file>
<file>CrawlModule/AbstractMenuView.qml</file>
</qresource>
<qresource prefix="/SnakeTr">
<file>languages/de.qm</file>
<file>languages/en.qm</file>
<file>languages/es.qm</file>
<file>languages/fr.qm</file>
<file>languages/ja.qm</file>
<file>languages/pl.qm</file>
<file>languages/ru.qm</file>
<file>languages/tr.qm</file>
<file>languages/zh.qm</file>
<file>languages/uk.qm</file>
</qresource>
<qresource prefix="/images"/>
<qresource prefix="/mesh"/>
<qresource prefix="/hdr"/>
</RCC>

View File

@ -16,7 +16,6 @@
#include <viewsolutions.h>
#include "worldstatus.h"
#define PLUGINS_DIR QStandardPaths::
QByteArray ClientApp::initTheme() {
int themeIndex = Settings::instance()->getValue(THEME, THEME_DEFAULT).toInt();
@ -39,9 +38,9 @@ ClientApp::~ClientApp() {
delete _menu;
delete _engine;
for (const auto& item : qAsConst(_availableLvls)) {
delete item.viewModel;
delete item.model;
for (auto it = _availableLvls.begin(); it != _availableLvls.end(); ++it) {
delete it.value().viewModel;
delete it.value().model;
}
_availableLvls.clear();
@ -139,11 +138,11 @@ bool ClientApp::init(QQmlApplicationEngine *engine) {
"WorldStatus",
"Error: only enums");
initSnakeProjectResources();
initCrawlResources();
initLang();
initLvls();
engine->addImportPath(":/SnakeProjectModule/");
engine->addImportPath(":/CrawlModule/");
if (!QmlNotificationService::init(engine)) {
@ -154,7 +153,7 @@ bool ClientApp::init(QQmlApplicationEngine *engine) {
return false;
}
engine->load("qrc:/SnakeProjectModule/SnakeProject.qml");
engine->load("qrc:/CrawlModule/Crawl.qml");
if (engine->rootObjects().isEmpty())
return false;

View File

@ -13,7 +13,7 @@ class QQmlApplicationEngine;
class MainMenuModel;
class IControl;
inline void initSnakeProjectResources() { Q_INIT_RESOURCE(SnakeProject); }
inline void initCrawlResources() { Q_INIT_RESOURCE(Crawl); }
/**
@ -28,12 +28,12 @@ struct WordlData {
/**
* @brief The ClientApp class This is main class of the Game engine.
*/
class SNAKEPROJECT_EXPORT ClientApp : public QObject
class CRAWL_EXPORT ClientApp : public QObject
{
Q_OBJECT
public:
ClientApp();
virtual ~ClientApp();
~ClientApp();
/**
* @brief init This method initialize engine on application.

View File

@ -5,5 +5,5 @@ DefaultControl::DefaultControl() {
}
QString DefaultControl::initQmlView() const {
return "qrc:/SnakeProjectModule/DefaultMenu.qml";
return "qrc:/CrawlModule/DefaultMenu.qml";
}

View File

@ -7,14 +7,14 @@
/**
* @brief The DefaultControl class This class contains default implementation of the game menu.
*/
class SNAKEPROJECT_EXPORT DefaultControl : public IControl {
class CRAWL_EXPORT DefaultControl : public IControl {
Q_OBJECT
public:
DefaultControl();
/**
* @brief initQmlView This implementation use the DefaultMenu.qml file.
* @return qrc:/SnakeProjectModule/DefaultMenu.qml
* @return qrc:/CrawlModule/DefaultMenu.qml
*/
QString initQmlView() const;

10
src/Core/Crawl/diff.cpp Normal file
View File

@ -0,0 +1,10 @@
#include "diff.h"
QList<int> Diff::getAddedIds() const {
return addedIds;
}
QList<int> Diff::getRemoveIds() const {
return removeIds;
}

View File

@ -1,6 +1,7 @@
#ifndef DIFF_H
#define DIFF_H
#include <QList>
#include <QObject>
class GuiObject;
@ -8,9 +9,15 @@ class GuiObject;
/**
* @brief The Diff class contains list of the last changes on a game world.
*/
struct Diff {
class Diff {
Q_GADGET
public:
Q_INVOKABLE QList<int> getRemoveIds() const;
Q_INVOKABLE QList<int> getAddedIds() const;
QList<int> removeIds;
QList<GuiObject*> addedIds;
QList<int> addedIds;
};
Q_DECLARE_METATYPE(Diff)

12
src/Core/Crawl/global.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef Crawl_GLOBAL_H
#define Crawl_GLOBAL_H
#include <QtCore/qglobal.h>
#if defined(CRAWL_LIBRARY)
# define CRAWL_EXPORT Q_DECL_EXPORT
#else
# define CRAWL_EXPORT Q_DECL_IMPORT
#endif
#endif // QTSECRET_GLOBAL_H

View File

@ -6,12 +6,12 @@
#include <QQuaternion>
#include <QRectF>
#include <QVector3D>
#include "SnakeProject/irender.h"
#include "Crawl/irender.h"
/**
* @brief The GuiObject class This base model for gui objects.
*/
class SNAKEPROJECT_EXPORT GuiObject: public QObject, public IRender {
class CRAWL_EXPORT GuiObject: public QObject, public IRender {
Q_OBJECT
Q_PROPERTY(QString color READ color WRITE setColor NOTIFY colorChanged)
Q_PROPERTY(int guiId READ guiId NOTIFY guiIdChanged)
@ -31,7 +31,7 @@ class SNAKEPROJECT_EXPORT GuiObject: public QObject, public IRender {
public:
GuiObject(const QString& viewTempalte = ":/SnakeProjectModule/GraphicItem.qml", QObject *ptr = nullptr);
GuiObject(const QString& viewTempalte = "qrc:/CrawlModule/GraphicItem.qml", QObject *ptr = nullptr);
QString color() const;
void setColor(QString color);
@ -108,7 +108,7 @@ signals:
protected:
int _guiId = -1;
QString _color = "";
QString _color = "#ff1111";
private:

View File

@ -13,7 +13,7 @@
* }
* ```
*/
class SNAKEPROJECT_EXPORT IAI {
class CRAWL_EXPORT IAI {
public:
IAI();
virtual ~IAI() = default;

View File

@ -13,7 +13,7 @@
* For more information see the DefaultControl class.
*
*/
class SNAKEPROJECT_EXPORT IControl : public QObject {
class CRAWL_EXPORT IControl : public QObject {
Q_OBJECT
Q_PROPERTY(QString view READ view NOTIFY viewChanged)

View File

@ -7,7 +7,7 @@
/**
* @brief The IGround class This is one tile of the world. Any objects of this type created automatically for filing ground plain.
*/
class SNAKEPROJECT_EXPORT IGround: public IWorldItem {
class CRAWL_EXPORT IGround: public IWorldItem {
public:
IGround();

View File

@ -10,7 +10,7 @@ class IControl;
/**
* @brief The IPlayer class This is base class of the player functions.
*/
class SNAKEPROJECT_EXPORT IPlayer: public IWorldItem {
class CRAWL_EXPORT IPlayer: public IWorldItem {
Q_OBJECT
public:
IPlayer();

View File

@ -7,7 +7,7 @@
* @brief The IRender class This interface provide render functionality for all objects.
* @note Override the render method.
*/
class SNAKEPROJECT_EXPORT IRender {
class CRAWL_EXPORT IRender {
public:
IRender();

View File

@ -52,6 +52,9 @@ bool IWorld::start() {
_backgroundAI->stopAI();
_player->setControl(_userInterface);
worldChanged(*_worldRules->begin());
return true;
}
@ -70,7 +73,7 @@ IAI *IWorld::initBackGroundAI() const {
return new DefaultBackgroundAI();
}
const IWorldItem *IWorld::getItem(int id) const {
IWorldItem *IWorld::getItem(int id) const {
return _items.value(id, {}).objectPtr;
}
@ -92,8 +95,6 @@ bool IWorld::init() {
return false;
}
setCameraReleativePosition(initCameraPosition());
if (!_worldRules->size()) {
deinit();
return false;
@ -101,11 +102,8 @@ bool IWorld::init() {
initPlayerControl(_userInterface);
initPlayerControl(dynamic_cast<IControl*>(_backgroundAI));
generateGround();
worldChanged(*_worldRules->begin());
return true;
}
@ -188,14 +186,15 @@ int IWorld::removeAnyItemFromGroup(const QString &group) {
return anyObjectId;
}
bool IWorld::takeTap() {
bool result = _tap;
_tap = false;
return result;
const QQuaternion &IWorld::cameraRatation() const {
return _cameraRatation;
}
void IWorld::setTap(bool newTap) {
_tap = newTap;
void IWorld::setCameraRatation(const QQuaternion &newCameraRatation) {
if (_cameraRatation == newCameraRatation)
return;
_cameraRatation = newCameraRatation;
emit cameraRatationChanged();
}
IAI *IWorld::backgroundAI() const {
@ -218,10 +217,6 @@ void IWorld::setCameraReleativePosition(const QVector3D &newCameraReleativePosit
emit cameraReleativePositionChanged();
}
void IWorld::handleTap() {
_tap = true;
}
void IWorld::handleStop() {
stop();
}
@ -255,7 +250,7 @@ void IWorld::worldChanged(const WorldObjects &objects) {
}
addItem(it.key(), obj);
diff.addedIds.append(obj);
diff.addedIds.append(obj->guiId());
}
} else {
for (; count < 0; ++count ) {

View File

@ -7,6 +7,7 @@
#include <QMap>
#include <QMultiHash>
#include <QObject>
#include <QQuaternion>
#include <QString>
#include "irender.h"
#include "diff.h"
@ -39,10 +40,11 @@ struct WorldObjectWraper {
/**
* @brief The IWorld class use this interface for implementation your own game levels
*/
class SNAKEPROJECT_EXPORT IWorld : public QObject, public IRender
class CRAWL_EXPORT IWorld : public QObject, public IRender
{
Q_OBJECT
Q_PROPERTY(QVector3D cameraReleativePosition READ cameraReleativePosition WRITE setCameraReleativePosition NOTIFY cameraReleativePositionChanged)
Q_PROPERTY(QVector3D cameraReleativePosition READ cameraReleativePosition NOTIFY cameraReleativePositionChanged)
Q_PROPERTY(QQuaternion cameraRatation READ cameraRatation NOTIFY cameraRatationChanged)
Q_PROPERTY(int worldStatus READ wordlStatus WRITE setWorldStatus NOTIFY worldStatusChanged)
@ -119,12 +121,6 @@ public:
*/
virtual void render(unsigned int tbfMsec) override;
/**
* @brief cameraPosition This method should be return relative position of camera. position should be relative of player object.
* @return camera releative position
*/
virtual QVector3D initCameraPosition() = 0;
/**
* @brief initPlayerControl This method should be configure all connections of @a control object.
* @brief control This is control object
@ -158,7 +154,7 @@ public:
* @return pointe to requaried object.
* @note if you want to get ovject in the render function of another ItemWorld object then use the IWorldItem::getItem method.
*/
const IWorldItem * getItem(int id) const;
IWorldItem *getItem(int id) const;
/**
* @brief hdrMap This method return path to hdr map of world.
@ -202,6 +198,12 @@ public:
*/
IAI *backgroundAI() const;
/**
* @brief cameraRatation This method return curent camera ratation.
* @return Quaternion of camera ratation
*/
const QQuaternion &cameraRatation() const;
signals:
/**
* @brief sigGameFinished This signal emit when game are finished
@ -211,8 +213,9 @@ signals:
/**
* @brief sigOBjctsListChanged This signal emited when lvel status are changed.
* @brief diff This is list of removed and addeds items
*/
void sigOBjctsListChanged(Diff);
void sigOBjctsListChanged(Diff diff);
/**
* @brief cameraReleativePositionChanged This signal emot when releative position of camera cahged.
@ -230,7 +233,13 @@ signals:
*/
void worldStatusChanged();
/**
* @brief cameraRatationChanged This method emited when ratation of the camera cahnged
*/
void cameraRatationChanged();
protected:
/**
* @brief generate This method shold be generate object from the @a objectType.
* Override this method for add support yourown objects.
@ -246,13 +255,12 @@ protected:
void setCameraReleativePosition(const QVector3D &newCameraReleativePosition);
/**
* @brief takeTap This method return true if user the tap on screen.
* @return true if user tap on screen.
* @brief setCameraRatation This method sets new ratation of the camera.
* @param newCameraRatation new ratation of the camera.
*/
bool takeTap();
void setCameraRatation(const QQuaternion &newCameraRatation);
private slots:
void handleTap();
void handleStop();
private:
@ -284,11 +292,10 @@ private:
*/
int removeAnyItemFromGroup(const QString &group);
void setTap(bool newTap);
QHash<int, WorldObjectWraper> _items;
QMultiHash<QString, int> _itemsGroup;
QVector3D _cameraReleativePosition;
QQuaternion _cameraRatation;
QString _hdrMap;
WorldRule *_worldRules = nullptr;
@ -298,7 +305,6 @@ private:
friend class Engine;
int _worldStatus = 0;
bool _tap = false;
};
#endif // IWORLD_H

View File

@ -1,14 +1,14 @@
#ifndef IWORLDITEM_H
#define IWORLDITEM_H
#include <SnakeProject/guiobject.h>
#include <Crawl/guiobject.h>
#include "global.h"
class IWorld;
/**
* @brief The IWorldItem class This is World item. This class contains functions for control event system.
*/
class SNAKEPROJECT_EXPORT IWorldItem: public GuiObject {
class CRAWL_EXPORT IWorldItem: public GuiObject {
Q_OBJECT
public:
IWorldItem();

View File

@ -0,0 +1,8 @@
import QtQuick 2.15
import QtQuick.Layouts 1.15
GridLayout {
property var model: null
anchors.fill: parent
}

View File

@ -9,7 +9,7 @@ ApplicationWindow {
visible: true;
width: 640;
height: 480;
title: qsTr("SnakeProject");
title: qsTr("Crawl");
Metrix {id: metrix}

View File

@ -10,7 +10,7 @@ Model {
DefaultMaterial {
id: defaultMaterial
diffuseColor: (model)? model.color: "#ffcccccc"
diffuseColor: (model)? model.color: "#ff1111"
}
PrincipledMaterial {

View File

@ -0,0 +1,157 @@
import QtQuick 2.15
import QtQuick3D 1.15
import QtQuick.Controls.Material 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
// https://doc.qt.io/qt-5/qqmlengine.html#qmlRegisterUncreatableMetaObject
import engine.worldstatus 1.0
View3D {
id: scene;
property var model: null;
property alias showMenu: privateRoot.showMenu
PerspectiveCamera {
id: camera
position: (privateRoot.player)? Qt.vector3d(
privateRoot.player.position.x + privateRoot.releativeCameraPosition.x,
privateRoot.player.position.y + privateRoot.releativeCameraPosition.y,
privateRoot.player.position.z + privateRoot.releativeCameraPosition.z
)
:
Qt.vector3d(0,0,0)
rotation: (privateRoot.world)? privateRoot.world.cameraRatation: Qt.quaternion(0,0,0,0)
}
DirectionalLight {
position: Qt.vector3d(0,0,100)
eulerRotation.z: 90
}
Node {
id: mainScane
}
environment: SceneEnvironment {
id: background
backgroundMode: SceneEnvironment.SkyBox
lightProbe: Texture {
source: (model)? model.hdr: ""
}
}
Item {
id: privateRoot
property var arrayObjects: []
property var player: (model)? model.player: null
property var world: (model)? model.world: null
property var gameMenuModel: (model)? model.menu: null
property var releativeCameraPosition: (world)? world.cameraReleativePosition: null
property var progress: (model)? model.prepareLvlProgress: null
property var gameMenu: null
property bool showMenu: (world)? WorldStatus.Game !== world.worldStatus : false;
function add (cppObjId) {
if (!model) {
console.log("create object fail")
return;
}
const objModel = model.getGameObject(cppObjId);
if (!objModel) {
console.log("object model not found");
return;
}
var viewTemplate = objModel.viewTemplate;
var temp = Qt.createComponent(viewTemplate)
if (temp.status === Component.Ready) {
var obj = temp.createObject(mainScane) // mainScane - это обьект на который будет помещен соззданный элемент
obj.model = model.getGameObject(cppObjId);
arrayObjects.push(obj)
} else {
console.log("wrong viewTemplate in model");
}
}
function remove(id) {
if (typeof id !== "number" || id < 0) {
console.log("id not found");
return;
}
for (var i = 0; i < arrayObjects.length; ++i) {
if (id === arrayObjects[i].guiId) {
arrayObjects.splice(i,1);
}
}
}
Connections {
target: privateRoot.world;
function onSigOBjctsListChanged(diff) {
if (!diff) {
console.log("dif not found");
return;
}
let tempDifRem = [];
tempDifRem = diff.getRemoveIds();
let tempDifAdd = [];
tempDifAdd = diff.getAddedIds();
for (let i = 0; i < tempDifAdd.length; ++i) {
privateRoot.add(tempDifAdd[i]);
}
for (let j = 0; j < tempDifRem.length; ++j) {
privateRoot.remove(tempDifRem[j]);
}
}
}
Connections {
target: privateRoot;
function onGameMenuModelChanged() {
if (!privateRoot.gameMenuModel) {
return;
}
const comp = Qt.createComponent(privateRoot.gameMenuModel.view);
if (comp.status === Component.Ready) {
if (privateRoot.gameMenu) {
privateRoot.gameMenu.destroy()
}
privateRoot.gameMenu = comp.createObject(scene);
if (privateRoot.gameMenu === null) {
// Error Handling
console.log("Error creating object");
}
privateRoot.gameMenu.model = privateRoot.gameMenuModel;
} else if (comp.status === Component.Error) {
// Error Handling
console.log("Error loading component: " + privateRoot.gameMenuModel.view, comp.errorString());
}
}
function onShowMenuChanged() {
if (privateRoot.gameMenu) {
privateRoot.gameMenu.visible = !showMenu
}
}
}
}
}

View File

@ -0,0 +1,3 @@
module CrawlModule
Crawl 1.0 Crawl.qml
DefaultMenu 1.0 DefaultMenu.qml

View File

@ -1,32 +0,0 @@
<RCC>
<qresource prefix="/">
<file>SnakeProjectModule/qmldir</file>
<file>SnakeProjectModule/SnakeProject.qml</file>
<file>SnakeProjectModule/GraphicItem.qml</file>
<file>SnakeProjectModule/MainMenu.qml</file>
<file>SnakeProjectModule/MainMenuButton.qml</file>
<file>SnakeProjectModule/Metrix.qml</file>
<file>SnakeProjectModule/PagePopUp.qml</file>
<file>SnakeProjectModule/Scene.qml</file>
<file>SnakeProjectModule/SettingsView.qml</file>
<file>SnakeProjectModule/SnakeItem.qml</file>
<file>SnakeProjectModule/SelectLvlView.qml</file>
<file>SnakeProjectModule/DefaultMenu.qml</file>
<file>SnakeProjectModule/AbstractMenuView.qml</file>
</qresource>
<qresource prefix="/SnakeTr">
<file>languages/de.qm</file>
<file>languages/en.qm</file>
<file>languages/es.qm</file>
<file>languages/fr.qm</file>
<file>languages/ja.qm</file>
<file>languages/pl.qm</file>
<file>languages/ru.qm</file>
<file>languages/tr.qm</file>
<file>languages/zh.qm</file>
<file>languages/uk.qm</file>
</qresource>
<qresource prefix="/images"/>
<qresource prefix="/mesh"/>
<qresource prefix="/hdr"/>
</RCC>

View File

@ -1,2 +0,0 @@
#include "diff.h"

View File

@ -1,12 +0,0 @@
#ifndef SNAKEPROJECT_GLOBAL_H
#define SNAKEPROJECT_GLOBAL_H
#include <QtCore/qglobal.h>
#if defined(SnakeProject_LIBRARY)
# define SNAKEPROJECT_EXPORT Q_DECL_EXPORT
#else
# define SNAKEPROJECT_EXPORT Q_DECL_IMPORT
#endif
#endif // QTSECRET_GLOBAL_H

View File

@ -1,5 +0,0 @@
import QtQuick 2.15
Item {
property var model: null
}

View File

@ -1,95 +0,0 @@
import QtQuick 2.15
import QtQuick3D 1.15
import QtQuick.Controls.Material 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
// https://doc.qt.io/qt-5/qqmlengine.html#qmlRegisterUncreatableMetaObject
import engine.worldstatus 1.0
View3D {
id: scene;
property var model: null;
property var player: (model)? model.player: null
property var world: (model)? model.world: null
property var gameMenuModel: (model)? model.menu: null
property var releativeCameraPosition: (world)? world.cameraReleativePosition: null
property var progress: (model)? model.prepareLvlProgress: null
property var gameMenu: null
property bool showMenu: (world)? WorldStatus.Game !== world.worldStatus : false;
onModelChanged: {
if (!model)
return;
model.scane = mainScane
}
onReleativeCameraPositionChanged: {
console.log(releativeCameraPosition)
}
onGameMenuModelChanged: {
if (!gameMenuModel) {
return;
}
const comp = Qt.createComponent(gameMenuModel.view);
if (comp.status === Component.Ready) {
if (gameMenu) {
gameMenu.destroy()
}
gameMenu = comp.createObject(scene);
if (gameMenu === null) {
// Error Handling
console.log("Error creating object");
}
gameMenu.model = gameMenuModel;
} else if (component.status === Component.Error) {
// Error Handling
console.log("Error loading component:", component.errorString());
}
}
onShowMenuChanged: {
if (gameMenu) {
gameMenu.visible = !showMenu
}
}
PerspectiveCamera {
id: camera
position: (player)? Qt.vector3d(player.position.x + releativeCameraPosition.x,
player.position.y + releativeCameraPosition.y,
player.position.z + releativeCameraPosition.z)
:
Qt.vector3d(0,0,0)
eulerRotation.z: -90
}
DirectionalLight {
position: Qt.vector3d(0,0,100)
eulerRotation.z: 90
}
Node {
id: mainScane
}
environment: SceneEnvironment {
id: background
backgroundMode: SceneEnvironment.SkyBox
lightProbe: Texture {
source: (model)? model.hdr: ""
}
}
}

View File

@ -1,3 +0,0 @@
module QuasarAppCreditsModule
SnakeProject 1.0 SnakeProject.qml

View File

@ -1,6 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>Crawl</name>
<message>
<source>Crawl</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DefaultMenu</name>
<message>
@ -49,11 +56,4 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SnakeProject</name>
<message>
<source>SnakeProject</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View File

@ -1,6 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>Crawl</name>
<message>
<source>Crawl</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DefaultMenu</name>
<message>
@ -49,11 +56,4 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SnakeProject</name>
<message>
<source>SnakeProject</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View File

@ -1,6 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>Crawl</name>
<message>
<source>Crawl</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DefaultMenu</name>
<message>
@ -49,11 +56,4 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SnakeProject</name>
<message>
<source>SnakeProject</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View File

@ -1,6 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>Crawl</name>
<message>
<source>Crawl</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DefaultMenu</name>
<message>
@ -49,11 +56,4 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SnakeProject</name>
<message>
<source>SnakeProject</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View File

@ -1,6 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>Crawl</name>
<message>
<source>Crawl</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DefaultMenu</name>
<message>
@ -49,11 +56,4 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SnakeProject</name>
<message>
<source>SnakeProject</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View File

@ -1,6 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>Crawl</name>
<message>
<source>Crawl</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DefaultMenu</name>
<message>
@ -49,11 +56,4 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SnakeProject</name>
<message>
<source>SnakeProject</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View File

@ -1,6 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>Crawl</name>
<message>
<source>Crawl</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DefaultMenu</name>
<message>
@ -49,11 +56,4 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SnakeProject</name>
<message>
<source>SnakeProject</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View File

@ -1,6 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>Crawl</name>
<message>
<source>Crawl</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DefaultMenu</name>
<message>
@ -49,11 +56,4 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SnakeProject</name>
<message>
<source>SnakeProject</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View File

@ -1,6 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>Crawl</name>
<message>
<source>Crawl</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DefaultMenu</name>
<message>
@ -49,11 +56,4 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SnakeProject</name>
<message>
<source>SnakeProject</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View File

@ -1,6 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>Crawl</name>
<message>
<source>Crawl</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DefaultMenu</name>
<message>
@ -49,11 +56,4 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SnakeProject</name>
<message>
<source>SnakeProject</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View File

@ -1,8 +1,8 @@
#ifndef DEFAULTBACKGROUNDAI_H
#define DEFAULTBACKGROUNDAI_H
#include "SnakeProject/defaultcontrol.h"
#include <SnakeProject/iai.h>
#include "Crawl/defaultcontrol.h"
#include <Crawl/iai.h>
class QTimer;

View File

@ -1,10 +1,10 @@
#include "engine.h"
#include <QQmlComponent>
#include <SnakeProject/guiobject.h>
#include "SnakeProject/iworld.h"
#include <Crawl/guiobject.h>
#include "Crawl/iworld.h"
#include <quasarapp.h>
#include "SnakeProject/icontrol.h"
#include "Crawl/icontrol.h"
Engine::Engine(QObject *parent): QObject(parent) {
@ -14,63 +14,6 @@ QObject *Engine::scane() {
return _scane;
}
void Engine::handleGameObjectsChanged(Diff diff) {
int count = diff.addedIds.size() + diff.removeIds.size();
int currentCount = 0;
for (const auto &item: qAsConst(diff.addedIds)) {
add(item);
currentCount++;
setPrepareLvlProgress((count / currentCount) * 100);
}
for (int id: qAsConst(diff.removeIds)) {
remove(id);
currentCount++;
setPrepareLvlProgress((count / currentCount) * 100);
}
}
bool Engine::add(GuiObject *obj) {
if (!_engine)
return false;
if (!_scane)
return false;
// Using QQmlComponent
QQmlComponent component(_engine,
QUrl::fromLocalFile(obj->viewTemplate()),
_scane);
QObject *object = component.create();
if (!object) {
QuasarAppUtils::Params::log("Failed to create gui object: " + obj->viewTemplate(),
QuasarAppUtils::Error);
return false;
}
if (!object->setProperty("model", QVariant::fromValue(obj)))
return false;
_qmlObjects.insert(obj->guiId(), object);
return true;
}
bool Engine::remove(int id) {
if (!_qmlObjects.contains(id)) {
return false;
}
_qmlObjects[id]->deleteLater();
_qmlObjects.remove(id);
return true;
}
void Engine::setQmlEngine(QQmlEngine *newEngine) {
if (_engine == newEngine)
return;
@ -83,18 +26,11 @@ void Engine::setWorld(IWorld *world) {
return ;
if (_currentWorld) {
disconnect(_currentWorld, &IWorld::sigOBjctsListChanged,
this, &Engine::handleGameObjectsChanged);
_currentWorld->deinit();
}
_currentWorld = world;
connect(_currentWorld, &IWorld::sigOBjctsListChanged,
this, &Engine::handleGameObjectsChanged,
Qt::QueuedConnection);
if (!_currentWorld->init()) {
QuasarAppUtils::Params::log("Failed to init world. World name: " + _currentWorld->name(),
QuasarAppUtils::Error);
@ -166,6 +102,13 @@ bool Engine::start() const {
return _currentWorld->start();
}
QObject *Engine::getGameObject(int id) const {
if (!_currentWorld)
return nullptr;
return _currentWorld->getItem(id);
}
void Engine::setPrepareLvlProgress(int newPrepareLvlProgress) {
if (_prepareLvlProgress == newPrepareLvlProgress) {
return;

View File

@ -3,7 +3,7 @@
#include <QObject>
#include <QQmlEngine>
#include <SnakeProject/diff.h>
#include <Crawl/diff.h>
class IWorld;
@ -97,13 +97,13 @@ public:
*/
bool start() const;
private slots:
/**
* @brief handleGameObjectsChanged This slot invoked when games objects changed.
* @brief diff this is changes of the lvl.
* @brief getGameObject This method using in qml for getting main model of the gui objects.
* @param id This is id of the gui object.
* @return pointer to game object model
*/
void handleGameObjectsChanged(Diff diff);
Q_INVOKABLE QObject *getGameObject(int id) const;
signals:
void scaneChanged();
@ -114,14 +114,11 @@ signals:
void prepareLvlProgressChanged();
private:
bool add(GuiObject* obj);
bool remove(int id);
void setPrepareLvlProgress(int newPrepareLvlProgress);
QObject *_scane = nullptr;
QQmlEngine *_engine = nullptr;
QHash<int, QObject*> _qmlObjects;
IWorld* _currentWorld = nullptr;
QObject *_menu = nullptr;
int _prepareLvlProgress;

View File

@ -1,5 +1,5 @@
#include "worldviewdata.h"
#include "SnakeProject/iworld.h"
#include "Crawl/iworld.h"
WorldViewData::WorldViewData(const IWorld *data) {
setWorldObject(data);

@ -1 +1 @@
Subproject commit fd1ec0371698b23a0ad5635471b45e6b35f009f7
Subproject commit d6a6fffeb29210d9f80e667d998eb02100386b0c

View File

@ -57,7 +57,7 @@ tstMain::tstMain() {
char * argv[] = {nullptr};
_app = new QCoreApplication(argc, argv);
QCoreApplication::setApplicationName("testSnakeProject");
QCoreApplication::setApplicationName("testCrawl");
QCoreApplication::setOrganizationName("QuasarApp");
auto path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);