Permalink
Browse files

Состояние PreloadState почти готово. Осталось подготовить файлы для

состояний загрузки и интро, добавить их в конфиг, подготовить в
состоянии список файлов для загрузки внутри LoadState.

Реализованы в достаточной на данный момент степени функторы, потоки,
строки, таймер, парсер простого конфига.

Работоспособны на базовом уровне менеджер окон, менеджер ресурсов.
  • Loading branch information...
GromCaptain committed Oct 10, 2015
0 parents commit c3c43dc8d2085757fb32c159253d7dad44ade8c4
Showing with 1,770 additions and 0 deletions.
  1. +25 −0 Build/Build.pro
  2. +12 −0 Build/main.cpp
  3. +72 −0 GameLib/Core/GameManager.cpp
  4. +36 −0 GameLib/Core/GameManager.h
  5. +84 −0 GameLib/Core/PlaftormSpecific/QtStringImpl.cpp
  6. +39 −0 GameLib/Core/PlaftormSpecific/QtStringImpl.h
  7. +37 −0 GameLib/Core/PlaftormSpecific/QtThreadImpl.cpp
  8. +30 −0 GameLib/Core/PlaftormSpecific/QtThreadImpl.h
  9. +16 −0 GameLib/Core/States/GameState.cpp
  10. +28 −0 GameLib/Core/States/GameState.h
  11. +19 −0 GameLib/Core/States/IntroState.cpp
  12. +20 −0 GameLib/Core/States/IntroState.h
  13. +19 −0 GameLib/Core/States/MainState.cpp
  14. +20 −0 GameLib/Core/States/MainState.h
  15. +19 −0 GameLib/Core/States/MenuState.cpp
  16. +20 −0 GameLib/Core/States/MenuState.h
  17. +53 −0 GameLib/Core/States/PreloadState.cpp
  18. +40 −0 GameLib/Core/States/PreloadState.h
  19. +83 −0 GameLib/Core/String.cpp
  20. +40 −0 GameLib/Core/String.h
  21. +23 −0 GameLib/Core/Thread.cpp
  22. +24 −0 GameLib/Core/Thread.h
  23. +24 −0 GameLib/Core/Timer.cpp
  24. +32 −0 GameLib/Core/Timer.h
  25. +64 −0 GameLib/GameLib.pro
  26. +53 −0 GameLib/GameUtil/ConfigReader.cpp
  27. +28 −0 GameLib/GameUtil/ConfigReader.h
  28. +16 −0 GameLib/Graph/GraphicsManager.cpp
  29. +16 −0 GameLib/Graph/GraphicsManager.h
  30. +6 −0 GameLib/Resources/Resources/Byte.h
  31. +37 −0 GameLib/Resources/Resources/PlatformSpecific/QtResourceImpl.cpp
  32. +27 −0 GameLib/Resources/Resources/PlatformSpecific/QtResourceImpl.h
  33. +33 −0 GameLib/Resources/Resources/Resource.cpp
  34. +29 −0 GameLib/Resources/Resources/Resource.h
  35. +6 −0 GameLib/Resources/Resources/ResourceID.h
  36. +45 −0 GameLib/Resources/ResourcesManager.cpp
  37. +32 −0 GameLib/Resources/ResourcesManager.h
  38. +83 −0 GameLib/Util/Functor.h
  39. +21 −0 GameLib/Window/PlaftormSpecific/QtWindowImpl.cpp
  40. +23 −0 GameLib/Window/PlaftormSpecific/QtWindowImpl.h
  41. +44 −0 GameLib/Window/PlaftormSpecific/QtWindowManagerImpl.cpp
  42. +39 −0 GameLib/Window/PlaftormSpecific/QtWindowManagerImpl.h
  43. +31 −0 GameLib/Window/Window.cpp
  44. +24 −0 GameLib/Window/Window.h
  45. +32 −0 GameLib/Window/WindowManager.cpp
  46. +28 −0 GameLib/Window/WindowManager.h
  47. +6 −0 GameLib/Window/WindowType.h
  48. +7 −0 Snake.pro
  49. +24 −0 Test/Test.pro
  50. +191 −0 Test/deployment.pri
  51. +10 −0 Test/main.cpp
@@ -0,0 +1,25 @@
#-------------------------------------------------
#
# Project created by QtCreator 2015-10-10T17:03:26
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Build
TEMPLATE = app
CONFIG += debug_and_release \
c++11
CONFIG(release, debug|release) {
LIBS += "../GameLib/release/libGameLib.a"
} else {
LIBS += "../GameLib/debug/libGameLib.a"
}
INCLUDEPATH += "../GameLib"
SOURCES += main.cpp
@@ -0,0 +1,12 @@
#include <QApplication>
#include "Core/GameManager.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
GameManager::instance().start();
return a.exec();
}
@@ -0,0 +1,72 @@
#include "GameManager.h"
#include "States/PreloadState.h"
#include "States/IntroState.h"
#include "States/MenuState.h"
#include "States/MainState.h"
#include "Resources/ResourcesManager.h"
#include "Graph/GraphicsManager.h"
#include "Window/WindowManager.h"
GameManager::GameManager()
{
}
GameManager& GameManager::instance()
{
static GameManager manager;
return manager;
}
void GameManager::switchToState(State::StateType stateType, std::shared_ptr<State::SwitchStateInfo> switchInfo)
{
currState = states[stateType];
currState -> start(switchInfo);
}
void GameManager::start()
{
init();
currState = states[State::StateType::Preload];
currState -> start(std::shared_ptr<State::SwitchStateInfo>(nullptr));
const unsigned timerInterval = 100;
Functor<void, unsigned> pUpdate(this, &GameManager::update);
timer.start(timerInterval, pUpdate);
}
void GameManager::update(unsigned msecs)
{
currState -> update(msecs);
}
void GameManager::init()
{
initStates();
initResources();
initGraphics();
initWindows();
}
void GameManager::initStates()
{
using namespace State;
states[StateType::Preload] = std::shared_ptr<GameState>(new PreloadState());
states[StateType::Intro] = std::shared_ptr<GameState>(new IntroState());
states[StateType::Menu] = std::shared_ptr<GameState>(new MenuState());
states[StateType::Main] = std::shared_ptr<GameState>(new MainState());
}
void GameManager::initResources()
{
auto mgr = ResourcesManager::instance();
mgr.init();
}
void GameManager::initGraphics()
{
auto mgr = GraphicsManager::instance();
mgr.init();
}
void GameManager::initWindows()
{
auto mgr = WindowManager::instance();
}
@@ -0,0 +1,36 @@
#ifndef GAME_MANAGER_H
#define GAME_MANAGER_H
#include <map>
#include "States/GameState.h"
#include "Timer.h"
class GameManager
{
public:
static GameManager& instance();
void switchToState(State::StateType stateType, std::shared_ptr<State::SwitchStateInfo> switchInfo);
void start();
void update(unsigned msecs);
private:
GameManager();
void init();
void initStates();
void initResources();
void initGraphics();
void initWindows();
private:
std::map<State::StateType, State::StatePtr> states;
State::StatePtr currState;
Timer timer;
//Subsystems subsys;
bool readyToExit;
};
#endif // GAME_MANAGER_H
@@ -0,0 +1,84 @@
#include "QtStringImpl.h"
#include <QStringList>
#include <QRegExp>
StringImpl::StringImpl()
{
}
StringImpl::StringImpl(const char* s):
string(s)
{
}
StringImpl::StringImpl(const StringImpl& s):
string(s.string)
{
}
StringImpl::StringImpl(const QString& s):
string(s)
{
}
bool StringImpl::empty() const
{
return string.isEmpty();
}
StringImpl StringImpl::substr(unsigned start) const
{
return string.mid(start);
}
StringImpl StringImpl::substr(unsigned start, unsigned len) const
{
return string.mid(start, len);
}
StringImpl StringImpl::trim() const
{
return string.trimmed();
}
std::list<StringImpl> StringImpl::split(const StringImpl& delimiter) const
{
auto qList = string.split(delimiter.string);
std::list<StringImpl> res;
for (auto s : qList)
res.push_back(s);
return res;
}
std::list<StringImpl> StringImpl::splitNewLine() const
{
auto qList = string.split(QRegExp("[\r\n]"), QString::SkipEmptyParts);
std::list<StringImpl> res;
for (auto s : qList)
res.push_back(s);
return res;
}
int StringImpl::find(const StringImpl& subStr) const
{
return string.indexOf(subStr.string);
}
int StringImpl::toInt(int defaultValue) const
{
bool ok = true;
int res = string.toInt(&ok);
return ok ? res : defaultValue;
}
bool StringImpl::operator<(const StringImpl& s) const
{
return string < s.string;
}
QString StringImpl::asQString() const
{
return string;
}
@@ -0,0 +1,39 @@
#ifndef STRING_IMPL_H
#define STRING_IMPL_H
#include <QString>
#include <list>
class StringImpl
{
public:
StringImpl();
explicit StringImpl(const char* s);
StringImpl(const StringImpl& s);
bool empty() const;
StringImpl substr(unsigned start) const;
StringImpl substr(unsigned start, unsigned len) const;
StringImpl trim() const;
std::list<StringImpl> split(const StringImpl& delimiter) const;
std::list<StringImpl> splitNewLine() const;
int find(const StringImpl& subStr) const;
int toInt(int defaultValue = 0) const;
bool operator<(const StringImpl& s) const;
// Платформенно-зависимые функции, не для использования в клиентском коде
QString asQString() const;
private:
StringImpl(const QString& s);
private:
QString string;
};
#endif // STRING_IMPL_H
@@ -0,0 +1,37 @@
#include "QtThreadImpl.h"
ThreadImpl::ThreadImpl():
isFinished(false)
{
}
void ThreadImpl::start(Functor<void> f)
{
fun = f;
isFinished = false;
connect(this, &ThreadImpl::workDone, this, &ThreadImpl::finish);
connect(this, &ThreadImpl::workDone, this, &ThreadImpl::quit);
QThread::start();
}
void ThreadImpl::stop()
{
QThread::quit();
}
bool ThreadImpl::done() const
{
return isFinished;
}
void ThreadImpl::run()
{
fun();
emit workDone();
}
void ThreadImpl::finish()
{
isFinished = true;
}
@@ -0,0 +1,30 @@
#ifndef THREAD_IMPL_H
#define THREAD_IMPL_H
#include <QThread>
#include "Util/Functor.h"
class ThreadImpl : public QThread
{
Q_OBJECT
public:
ThreadImpl();
void start(Functor<void> f);
void stop();
bool done() const;
// Платформенно-зависимые функции, не для использования в клиентском коде
void run() override;
void finish();
signals:
void workDone();
private:
Functor<void> fun;
bool isFinished;
};
#endif // THREAD_IMPL_H
@@ -0,0 +1,16 @@
#include "GameState.h"
#include "Core/GameManager.h"
namespace State
{
GameState::GameState()
{
}
void GameState::switchState(StateType nextState, std::shared_ptr<SwitchStateInfo> info)
{
GameManager::instance().switchToState(nextState, info);
}
}
@@ -0,0 +1,28 @@
#ifndef GAME_STATE_H
#define GAME_STATE_H
#include <memory>
namespace State
{
enum class StateType { Preload, Intro, Menu, Main };
class SwitchStateInfo {};
class GameState
{
public:
GameState();
virtual void start(std::shared_ptr<SwitchStateInfo> info) = 0;
virtual void update(unsigned msecs) = 0;
void switchState(StateType nextState, std::shared_ptr<SwitchStateInfo> info);
};
typedef std::shared_ptr<GameState> StatePtr;
}
#endif // GAME_STATE_H
Oops, something went wrong.

0 comments on commit c3c43dc

Please sign in to comment.