Permalink
Browse files

added lots of stuff. core in main code from now. added purelib shared…

… object, added job tests, refactoring Csoul and Job
  • Loading branch information...
1 parent 715004c commit fa5630eaa99d69bd2d2d306542c9bd00548df14a Daniel (dmilith) Dettlaff committed Sep 1, 2008
Showing with 450 additions and 138 deletions.
  1. +1 −0 .gitignore
  2. +3 −2 Sconstruct
  3. +1 −0 character.cpp
  4. +2 −0 coordinates.h
  5. +170 −0 core.cpp
  6. +83 −0 core.h
  7. +38 −80 job.cpp
  8. +30 −15 job.h
  9. +27 −1 soul.cpp
  10. +29 −16 soul.h
  11. +20 −13 tests/Sconstruct
  12. +0 −2 tests/core/core.cpp
  13. +43 −0 tests/jobs/job_test_0.cpp
  14. +1 −7 tests/network/asio_tcp_client_test.cpp
  15. +2 −2 tests/other/serialization_test.cpp
View
@@ -16,3 +16,4 @@ tests/test_*
*~
tests/.sconsign.dblite
tests/core/objects
+data/objects
View
@@ -19,6 +19,8 @@ debug_optimized = Environment( CXX = 'g++ -O2 -ggdb -W' )
#release = debug64
release = debug_optimized
+release.SharedLibrary('purecore', 'core.cpp')
+release.SharedLibrary('job', 'job.cpp')
release.SharedLibrary('hl-sha', [ 'hashlib/hl_sha1.cpp',
'hashlib/hl_sha1wrapper.cpp', 'hashlib/hl_sha256.cpp',
'hashlib/hl_sha256wrapper.cpp', 'hashlib/hl_tools.cpp' ] )
@@ -30,11 +32,10 @@ release.SharedLibrary('place', 'place.cpp')
release.SharedLibrary('soul', 'soul.cpp')
release.SharedLibrary('theritory', 'theritory.cpp')
release.SharedLibrary('world', 'world.cpp')
-release.SharedLibrary('job', 'job.cpp')
#release.Program('main' , 'main2.cpp',
# LIBS=[ 'boost_thread', 'boost_filesystem', 'hl-sha', 'boost_serialization',
# 'job', 'character', 'coordinates',
# 'item', 'map', 'place', 'soul', 'theritory',
-# 'world'],
+# 'world', 'purecore' ],
#, 'ruby' ],
# LIBPATH=[ '.', '/usr/local/lib', '/usr/lib' ])
View
@@ -280,3 +280,4 @@ void
Ccharacter::set_name( std::string name_ ) {
name = name_;
}
+
View
@@ -10,6 +10,8 @@
#ifndef _CCOORDINATES_H_
#define _CCOORDINATES_H_
+#include <iostream>
+#include <string.h>
#include "hashlib/hl_tools.h" //instead of haslibpp.h. It's kinda proxy for hashlib
static const uint8_t SHA1_SIZE = 41; // 40 + \0
View
170 core.cpp
@@ -0,0 +1,170 @@
+/*
+
+ This is OpenSource Project;
+ It's licensed on GPL/ LGPL public license;
+ It's written by Daniel (dmilith) Dettlaff since August 2oo8.
+ You can redistribute this project only with this header.
+
+*/
+
+/*
+ * TODO:
+ *
+ */
+
+#define DEBUG
+
+#include "core.h"
+
+using namespace std;
+using namespace core;
+using namespace boost;
+
+
+//Ccore
+
+Ccore::Ccore() {
+}
+
+
+Ccore::~Ccore() {
+}
+
+
+string
+Ccore::get_core_version() {
+ return CREALIS_CORE_VERSION;
+}
+
+
+uint32_t
+Ccore::get_current_objects_amount() {
+ return objects_amount;
+}
+
+
+uint32_t
+Ccore::get_max_objects_amount() {
+ return MAX_OBJECTS_AMOUNT;
+}
+
+void
+Ccore::set_amount( uint32_t value_ ) {
+ this->objects_amount = value_;
+}
+
+
+
+//Cobject
+
+Cobject::Cobject() {
+ this->set_id( generate_sha1() );
+ this->set_priority( 1 );
+}
+
+
+Cobject::Cobject( string id_ ) {
+ this->set_id( id_ );
+ this->set_priority( 1 );
+}
+
+
+Cobject::Cobject( int8_t priority_ ) {
+ this->set_id( generate_sha1() );
+ this->set_priority( priority_ );
+}
+
+
+Cobject::Cobject( string id_, int8_t priority_ ) {
+ this->set_id( id_ );
+ this->set_priority( priority_ );
+}
+
+
+bool
+Cobject::is_changed() {
+ return false;
+}
+
+
+string
+Cobject::get_id() {
+ return this->id;
+}
+
+
+void
+Cobject::set_id( string id_ ) {
+ this->id = id_;
+}
+
+
+void
+Cobject::set_priority( int8_t priority_ ) {
+ this->priority = priority_;
+}
+
+
+int8_t
+Cobject::get_priority() {
+ return this->priority;
+}
+
+
+Ccoordinates
+Cobject::get_position() {
+ return this->position;
+}
+
+
+void
+Cobject::set_position( Ccoordinates position_ ) {
+ this->position = position_;
+}
+
+
+bool
+Cobject::save_object() {
+ COBJECT_DATA *temp = new COBJECT_DATA;
+ strcpy( temp->id, ( this->get_id() ).c_str() );
+ temp->priority = this->get_priority();
+ temp->position = this->get_position();
+#ifdef DEBUG
+ cout << "Saving " + CORE_INFO_PATH + this->get_id() << endl << flush;
+#endif
+ try {
+ ofstream file( ( CORE_INFO_PATH + this->get_id() ).c_str(), ios_base::out | ios_base::binary );
+ file.write( (char*)temp, sizeof( COBJECT_DATA ) );
+ file.close();
+ } catch (exception& e) {
+ cout << e.what() << flush;
+ exit( 1 );
+ }
+ delete temp;
+ return true;
+}
+
+
+Cobject
+load_object( string filename_ ) {
+ Cobject temp_obj;
+ COBJECT_DATA *temp = new COBJECT_DATA;
+#ifdef DEBUG
+ cout << "Loading " + CORE_INFO_PATH + filename_ << endl << flush;
+#endif
+ try {
+ ifstream file( ( CORE_INFO_PATH + filename_ ).c_str(), ios_base::in | ios_base::binary );
+ file.read( (char*)temp, sizeof( COBJECT_DATA ) );
+ file.close();
+ } catch (exception& e) {
+ cout << e.what() << flush;
+ exit( 1 );
+ }
+ temp_obj.set_id( temp->id );
+ temp_obj.set_priority( temp->priority );
+ temp_obj.set_position( temp->position );
+ delete temp;
+ return temp_obj;
+}
+
+
View
83 core.h
@@ -0,0 +1,83 @@
+#ifndef _CCORE_H
+#define _CCORE_H
+
+#include <iostream>
+#include <cassert>
+#include <fstream>
+#include <boost/shared_ptr.hpp>
+#include <boost/shared_array.hpp>
+#include "hashlib/hl_tools.h"
+#include "coordinates.h"
+#include "version.h"
+#include "config.h"
+
+/*
+ * TODO: add asserts in all tests!
+ *
+ * XXX: to be fixed, or with poor code style
+ *
+ * FIXME: things to be fixed cause of bad working
+ *
+ */
+
+static const uint32_t MAX_OBJECTS_AMOUNT = 10000; //temporarely
+
+using namespace std;
+
+
+namespace core {
+
+ struct COBJECT_DATA { // to save/ load structure data
+ char id[40 + 1]; // additional \0 !
+ Ccoordinates position;
+ int8_t priority;
+ };
+
+ class Ccore {
+
+ private:
+ uint32_t objects_amount;
+ void save_objects_amount();
+ void load_objects_amount();
+
+ public:
+ Ccore();
+ ~Ccore();
+ string get_core_version();
+ void set_amount( uint32_t value_ );
+ uint32_t get_current_objects_amount();
+ uint32_t get_max_objects_amount();
+ };
+
+
+
+
+
+ class Cobject : public Ccore {
+
+ private:
+ string id;
+ Ccoordinates position; // localization of object in world
+ int8_t priority;
+
+ public:
+ Cobject();
+ Cobject( int8_t priority_ );
+ Cobject( string id_ );
+ Cobject( string id_, int8_t priority_ ) ;
+ string get_id();
+ virtual bool is_changed();
+ void set_id( string id_ );
+ int8_t get_priority();
+ Ccoordinates get_position();
+ void set_position( Ccoordinates position_ );
+ void set_priority( int8_t priority_ );
+ virtual bool save_object(); // saving with id as filename
+ friend Cobject load_object( string filename_ );
+
+ };
+
+}; // namespace
+
+
+#endif
Oops, something went wrong.

0 comments on commit fa5630e

Please sign in to comment.