Commit 5f010936 authored by Ilya Prokhorov's avatar Ilya Prokhorov

Flame Steel Core implementation

parent 3b03c279
/*
* FSCComponents.cpp
*
* Created on: Aug 20, 2016
* Author: demensdeum
*/
#include "FSCComponents.h"
#include <iostream>
FSCComponents::FSCComponents() {
// TODO Auto-generated constructor stub
}
/*! addComponent - get component by identifier*/
void FSCComponents::addComponent(shared_ptr<FSCObject> component) {
shared_ptr<string> classIdentifier = component->getClassIdentifier();
if (classIdentifier.get() == nullptr) {
cout << "FSCComponents: cannot add component - component class identifier is nullptr. Quit.";
exit(1);
}
//cout << "FSCComponents: Add component " << component->getInstanceIdentifier()->c_str() << endl;
identifierToComponentMap[*classIdentifier.get()] = component;
}
/*! getComponent - get component by identifier*/
shared_ptr<FSCObject> FSCComponents::getComponent(shared_ptr<string> identifier) {
auto component = this->identifierToComponentMap[*identifier.get()];
return component;
}
/*! removeComponent - remove component by identifier*/
void FSCComponents::removeComponent(shared_ptr<string> identifier) {
this->identifierToComponentMap.erase(*identifier.get());
}
FSCComponents::~FSCComponents() {
// TODO Auto-generated destructor stub
}
/*
* FSCComponents.h
*
* Created on: Aug 20, 2016
* Author: demensdeum
*/
#ifndef FSCCOMPONENTS_H_
#define FSCCOMPONENTS_H_
#include "FSCObject.h"
#include <map>
#include <iostream>
using namespace std;
class FSCComponents: public FSCObject {
public:
FSCComponents();
/*! addComponent - add component*/
void addComponent(shared_ptr<FSCObject> component);
/*! getComponent - get component by identifier*/
shared_ptr<FSCObject> getComponent(shared_ptr<string> identifier);
/*! removeComponent - remove component by identifier*/
void removeComponent(shared_ptr<string> identifier);
virtual ~FSCComponents();
private:
map<string, shared_ptr<FSCObject> > identifierToComponentMap;
};
#endif /* FSCCOMPONENTS_H_ */
/*
* FSCController.cpp
*
* Created on: Jul 10, 2016
* Author: demensdeum
*/
#include "FSCObject.h"
#include "FSCController.h"
using namespace std;
FSCController::FSCController() {
// TODO Auto-generated constructor stub
}
void FSCController::step() {
}
FSCController::~FSCController() {
// TODO Auto-generated destructor stub
}
/*
* FSCController.h
*
* Created on: Jul 10, 2016
* Author: demensdeum
*/
#ifndef FSCCONTROLLER_H_
#define FSCCONTROLLER_H_
#include "FSCObject.h"
/*! FSCController - controller class from MVC pattern */
class FSCController : public FSCObject {
public:
FSCController();
virtual ~FSCController();
/*! step() - method to be called inside loop, represents one iteration of some process */
virtual void step();
};
#endif /* FSCCONTROLLER_H_ */
#include "FSCData.h"
FSCData::FSCData() {
size = 0;
data = nullptr;
};
shared_ptr<FSCData> FSCData::fromFilePath(shared_ptr<string> filePath) {
auto data = make_shared<FSCData>();
char *buffer = nullptr;
auto file = fopen (filePath->c_str(), "rb");
if (file != nullptr) {
fseek (file, 0, SEEK_END);
auto length = ftell (file);
data->size = length;
fseek (file, 0, SEEK_SET);
buffer = (char *) malloc (length);
if (buffer)
{
fread (buffer, 1, length, file);
}
data->data = buffer;
fclose (file);
}
return data;
};
\ No newline at end of file
#include <string>
#include <memory>
using namespace std;
class FSCData {
public:
FSCData();
static shared_ptr<FSCData> fromFilePath(shared_ptr<string> filePath);
size_t size;
char *data;
};
\ No newline at end of file
/*
* FSCMessage.cpp
*
* Created on: Jul 30, 2016
* Author: demensdeum
*/
#include "FSCMessage.h"
FSCMessage::FSCMessage(shared_ptr<string> title, shared_ptr<string> text) {
this->title = title;
this->text = text;
}
shared_ptr<string> FSCMessage::getTitle() {
return this->title;
}
shared_ptr<string> FSCMessage::getText() {
return this->text;
}
FSCMessage::~FSCMessage() {
// TODO Auto-generated destructor stub
}
/*
* FSCMessage.h
*
* Created on: Jul 30, 2016
* Author: demensdeum
*/
#ifndef FSCMESSAGE_H_
#define FSCMESSAGE_H_
/*! FSCMessage - class used to send messages between objects */
#include "FSCObject.h"
#include <memory>
using namespace std;
class FSCMessage: public FSCObject {
public:
FSCMessage(shared_ptr<string> title, shared_ptr<string> text);
/*! FSCMessage - get message title @return title*/
shared_ptr<string> getTitle();
/*! FSCMessage - get message text @return text*/
shared_ptr<string> getText();
virtual ~FSCMessage();
private:
shared_ptr<string> title;
shared_ptr<string> text;
};
#endif /* FSCMESSAGE_H_ */
/*
* FSCObject.cpp
*
* Created on: Jul 10, 2016
* Author: demensdeum
*/
#include "FSCObject.h"
#include "FSCComponents.h"
#include <iostream>
using namespace std;
int FSCLastObjectID = 0;
FSCObject::FSCObject() {
id = FSCLastObjectID;
classIdentifier = shared_ptr<string>();
instanceIdentifier = shared_ptr<string>();
components = shared_ptr<FSCComponents>();
FSCLastObjectID++;
}
void FSCObject::setInstanceIdentifier(shared_ptr<string> instanceIdentifier) {
this->instanceIdentifier = instanceIdentifier;
}
void FSCObject::setClassIdentifier(shared_ptr<string> classIdentifier) {
this->classIdentifier = classIdentifier;
}
shared_ptr<string> FSCObject::getInstanceIdentifier() {
return this->instanceIdentifier;
}
shared_ptr<string> FSCObject::getClassIdentifier() {
return this->classIdentifier;
}
shared_ptr<FSCObject> FSCObject::getComponent(shared_ptr<string> identifier) {
if (!this->components) {
printf("warning cannot get component - components array is nullptr\n");
return shared_ptr<FSCObject>();
}
else
{
return this->components->getComponent(identifier);
}
}
/*! removeComponent - remove component by identifier*/
void FSCObject::removeComponent(shared_ptr<string> identifier) {
this->components->removeComponent(identifier);
}
shared_ptr<FSCObject> FSCObject::copy() {
return shared_ptr<FSCObject>();
}
/*! addComponent - add component*/
void FSCObject::addComponent(shared_ptr<FSCObject> component) {
if (!this->components)
{
shared_ptr<FSCComponents> components(new FSCComponents());
this->components = components;
}
this->components->addComponent(component);
}
void FSCObject::debugPrintout() {
if (classIdentifier == nullptr) {
cout << "classIdentifier = nullptr. Quit" << endl;
exit(1);
}
if (instanceIdentifier == nullptr) {
cout << "instanceIdentifier = nullptr. Quit" << endl;
exit(1);
}
cout << "My class: " << classIdentifier->c_str() << endl;
cout << "My instance identifier: " << instanceIdentifier->c_str() << endl;
cout << "My components: " << endl;
if (this->components)
{
this->components->debugPrintout();
}
}
FSCObject::~FSCObject() {
// TODO Auto-generated destructor stub
}
/*
* FSCObject.h
*
* Created on: Jul 10, 2016
* Author: demensdeum
*/
#ifndef FSCOBJECT_H_
#define FSCOBJECT_H_
#include <string>
#include <memory>
#include "FSCSerializable.h"
class FSCComponents;
using namespace std;
/*! FSCObject - base class of Flame Steel Engine */
extern int FSCLastObjectID;
class FSCObject : public FSCSerializable {
public:
FSCObject();
virtual ~FSCObject();
int id;
/*! instanceIdentifier setter - string identifier of object */
void setInstanceIdentifier(shared_ptr<string> gameSceneIdentifier);
/*! classIdentifier setter - string identifier of object class */
void setClassIdentifier(shared_ptr<string> gameSceneClass);
/*! instanceIdentifier - getter string identifier of object @return instanceIdentifier*/
shared_ptr<string> getInstanceIdentifier();
/*! instanceIdentifier - getter string identifier of object @return classIdentifier*/
shared_ptr<string> getClassIdentifier();
/*! addComponent - add component*/
void addComponent(shared_ptr<FSCObject> component);
/*! getComponent - get component by identifier*/
shared_ptr<FSCObject> getComponent(shared_ptr<string> identifier);
/*! removeComponent - remove component by identifier*/
void removeComponent(shared_ptr<string> identifier);
virtual shared_ptr<FSCObject> copy();
void debugPrintout();
private:
/*! instanceIdentifier - string identifier of object */
shared_ptr<string> instanceIdentifier;
/*! classIdentifier - string identifier of object class */
shared_ptr<string> classIdentifier;
/*! components - getter list of components from CES pattern @return components*/
shared_ptr<FSCComponents> components;
};
#endif /* FSCOBJECT_H_ */
/*
* FSCObjects.cpp
*
* Created on: Jul 31, 2016
* Author: demensdeum
*/
#include "FSCObjects.h"
#include <cstddef>
FSCObjects::FSCObjects() {
}
void FSCObjects::addObject(shared_ptr<FSCObject> object) {
objects.push_back(object);
idToObject[object->id] = object;
}
shared_ptr<FSCObject> FSCObjects::objectWithId(int id) {
return idToObject[id];
}
shared_ptr<FSCObject> FSCObjects::objectAtIndex(unsigned int index) {
if (index >= objects.size()) {
return shared_ptr<FSCObject>();
}
return objects[index];
}
int FSCObjects::size() {
return objects.size();
}
vector <shared_ptr<FSCObject> >* FSCObjects::getObjectsVector() {
return &objects;
}
void FSCObjects::removeObjectAtIndex(unsigned int index) {
if (index < objects.size()) {
objects.erase(objects.begin() + index);
}
}
void FSCObjects::removeAllObjects() {
for (unsigned int i = 0; i < objects.size(); i++) {
i--;
objects.pop_back();
}
}
FSCObjects::~FSCObjects() {
// TODO Auto-generated destructor stub
}
/*
* FSCObjects.h
*
* Created on: Jul 31, 2016
* Author: demensdeum
*/
#ifndef FSCOBJECTS_H_
#define FSCOBJECTS_H_
#include "FSCObject.h"
#include <vector>
#include <memory>
#include <string>
#include <map>
using namespace std;
class FSCObjects: public FSCObject {
public:
FSCObjects();
void addObject(shared_ptr<FSCObject> object);
shared_ptr<FSCObject> objectWithId(int id);
shared_ptr<FSCObject> objectAtIndex(unsigned int index);
int size();
vector <shared_ptr<FSCObject> > *getObjectsVector();
void removeObjectAtIndex(unsigned int index);
void removeAllObjects();
virtual ~FSCObjects();
private:
vector <shared_ptr<FSCObject> > objects;
map <int, shared_ptr<FSCObject> > idToObject;
};
#endif /* FSCOBJECTS_H_ */
/*
* FSCResource.cpp
*
* Created on: Jan 16, 2017
* Author: demensdeum
*/
#include "FSCResource.h"
FSCResource::FSCResource() {
}
FSCResource::~FSCResource() {
}
/*
* FSCResource.h
*
* Created on: Jan 16, 2017
* Author: demensdeum
*/
#ifndef FSCRESOURCE_H_
#define FSCRESOURCE_H_
#include "FSCObject.h"
class FSCResource: public FSCObject {
public:
FSCResource();
virtual ~FSCResource();
};
#endif /* FSCRESOURCE_H_ */
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: FSCResourceLoader.cpp
* Author: demensdeum
*
* Created on March 12, 2017, 9:28 AM
*/
#include "FSCResourcesLoader.h"
#include <iostream>
using namespace std;
FSCResourcesLoader::FSCResourcesLoader() {
}
FSCResourcesLoader::FSCResourcesLoader(const FSCResourcesLoader& ) {
}
void FSCResourcesLoader::loadURL(shared_ptr<string> , shared_ptr<FSCResourcesManager> ){
cout << "FSCResourcesLoader: loadURL must be overridden." << endl;
exit(1);
}
FSCResourcesLoader::~FSCResourcesLoader() {
}
\ No newline at end of file
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: FSCResourceLoader.h
* Author: demensdeum
*
* Created on March 12, 2017, 9:28 AM
*/
#ifndef FSCRESOURCELOADER_H
#define FSCRESOURCELOADER_H
#include "FSCResource.h"
#include "FSCResourcesManager.h"
class FSCResourcesLoader {
public:
FSCResourcesLoader();
FSCResourcesLoader(const FSCResourcesLoader& orig);
virtual ~FSCResourcesLoader();
virtual void loadURL(shared_ptr<string> url, shared_ptr<FSCResourcesManager> resourcesManager);
private:
};
#endif /* FSCRESOURCELOADER_H */
/*
* FSCResourcesManager.cpp
*
* Created on: Jan 16, 2017
* Author: demensdeum
*/
#include "FSCResourcesManager.h"
#include <iostream>
using namespace std;
FSCResourcesManager::FSCResourcesManager() {
// TODO Auto-generated constructor stub
}
shared_ptr<FSCResource> FSCResourcesManager::getResourceByName(shared_ptr<string> name) {
//cout << "getResourceByName: " << name->c_str() << endl;
return resourcesMap[*name.get()];
}
void FSCResourcesManager::setResourceWithName(shared_ptr<string> name, shared_ptr<FSCResource> resource) {
cout << "setResourceByName: " << name->c_str() << endl;
resourcesMap[*name.get()] = resource;
}
void FSCResourcesManager::clear() {
auto itr = resourcesMap.begin();