Compare commits

..

4 Commits

44 changed files with 1309 additions and 117 deletions

3
.gitignore vendored
View File

@ -1,2 +1,5 @@
link/
.vscode/
run/
*.swp
*.swo

View File

@ -3,9 +3,11 @@ F_ROOT=$(readlink -f "$0")
D_ROOT=$(dirname "${F_ROOT}")/../../.
D_COMPILE=${D_ROOT}/compile
D_LINK=${D_ROOT}/link
D_EARN=${D_ROOT}/earn
F_COMPILE_LIST=${D_COMPILE}/project_files.txt
F_LINK_LIST=${D_LINK}/project_files.txt
D_PACK=${D_ROOT}/pack
D_RUN=${D_ROOT}/run
F_COMPILE_LIST=${D_PACK}/cpp_files.txt
F_LINK_LIST=${D_LINK}/object_files.txt
F_OBJ_LIST=${D_PACK}/obj_files.txt
echo "" > ${F_LINK_LIST}
# Compile.
@ -21,12 +23,16 @@ do
I_COMPILE=${D_COMPILE}/${F_COMPILE}
O_COMPILE=${D_LINK}/${F_COMPILE}.o
mkdir -p "${O_COMPILE%/*}"
clang++ -I ${D_COMPILE} -c ${I_COMPILE} -o ${O_COMPILE}
clang++ -I ${D_COMPILE} \
-D ROOT_DIRECTORY_MV=\"${D_ROOT}\" \
-c ${I_COMPILE} -o ${O_COMPILE}
echo ${O_COMPILE} >> ${F_LINK_LIST}
done
# Libraries.
F_LIBRARY_LIST=${D_COMPILE}/libraries.txt
F_LIBRARY_LIST=${D_PACK}/libraries.txt
F_LIBRARY_OPTIONS=${D_LINK}/library_options.txt
echo "" > ${F_LIBRARY_OPTIONS}
LINE=0
@ -37,12 +43,12 @@ do
break
fi
LINE=$((LINE+1))
LIBRARY="-l$(head -n ${LINE} ${F_LIBRARY_LIST}) "
LIBRARY="-l$(head -n ${LINE} ${F_LIBRARY_LIST} | tail -n 1)"
echo $LIBRARY >> ${F_LIBRARY_OPTIONS}
done
# Link.
I_LINK=$(cat ${F_LINK_LIST})
I_LIBRARIES=$(cat ${F_LIBRARY_OPTIONS})
O_LINK=${D_EARN}/executable
O_LINK=${D_RUN}/executable
clang++ ${I_LIBRARIES} ${I_LINK} -o ${O_LINK}

View File

@ -0,0 +1 @@
#!/bin/bash

View File

@ -0,0 +1,5 @@
#!/bin/bash
apt install -y \
libx11-dev \
libglew-dev glew-utils libglew2.1 \
libglx-dev libglx-mesa0 libglx0

22
command/linux/setup_android.sh Executable file
View File

@ -0,0 +1,22 @@
#!/bin/bash
# Make sure we are running this script as root.
[[ $EUID -ne 0 ]] && echo "This script must be run as root." && exit 1
ANDROID_CLI_TOOLS_FILE=commandlinetools-linux-7583922_latest.zip
ANDROID_CLI_TOOLS_LINK=https://dl.google.com/android/repository/${ANDROID_CLI_TOOLS_FILE}
ANDROID_CLI_TOOLS_DIR=cmdline-tools
ANDROID_SDK_DIR=/opt/android_sdk
wget $ANDROID_CLI_TOOLS_LINK
unzip $ANDROID_CLI_TOOLS_FILE
rm $ANDROID_CLI_TOOLS_FILE
mkdir $ANDROID_SDK_DIR
mv $ANDROID_CLI_TOOLS_DIR /opt/android_sdk/
${ANDROID_SDK_DIR}/bin/sdkmanager --sdk_root=${ANDROID_SDK_DIR} --install \
"platforms;android-21" \
"sources;android-21" \
"platform-tools" \
"build-tools;21.1.2" \
"ndk;21.4.7075529"

View File

@ -1,15 +1,16 @@
#ifndef ACT_CONTROLLER
#define ACT_CONTROLLER
#include "code/return.h"
class controller_t {
public:
enum error_t {
none,
unknown
};
enum event_t {
start,
stop
};
enum status_t {
ok,
error
};
virtual status_t on_event(event_t event_p) = 0;
virtual void_t<error_t> on_event(event_t event_p) = 0;
};
#endif

View File

@ -1,33 +1,46 @@
#include "act/controller.h"
#include "act/root.h"
#include "draw/window.h"
#include <stdlib.h>
root_controller_t::configuration_t::configuration_t(std::vector<root_controller_t::mode_t> modes_p) {
modes_m = modes_p;
}
root_controller_t::root_controller_t(root_controller_t::configuration_t configuration_p) {
#include "allocate/factory.h"
#include "code/return.h"
#include "draw/window_service.h"
root_controller_t::root_controller_t(
root_controller_t::configuration_t* configuration_p
) {
configuration_m = configuration_p;
}
root_controller_t* root_controller_factory_t::create(root_controller_t::configuration_t configuration_p) {
void* ptr = malloc(sizeof(root_controller_t));
return static_cast<root_controller_t*>(ptr);
void_t<controller_t::error_t> root_controller_t::on_event(
controller_t::event_t event_p
) {
text_service_t* text_service_l = configuration_m->provider_m->configuration_m->text_service_m;
text_service_l->initialize(
);
std::string window_title = text_service_l->get_text(
text_service_t::text_t::window_title
).value_m;
configuration_m->provider_m->configuration_m->window_service_m->create_window(
&window_title
);
void_t<controller_t::error_t> void_l;
void_l.error_m = controller_t::error_t::none;
return void_l;
}
factory_t::status_t root_controller_factory_t::dispose(root_controller_t* root_controller_p) {
free(root_controller_p);
return factory_t::status_t::ok;
return_t<root_controller_t::error_t, root_controller_t*> root_controller_factory_t::create(
root_controller_t::configuration_t* configuration_p
) {
return_t<root_controller_t::error_t, root_controller_t*> return_l;
return_l.error_m = root_controller_t::error_t::none;
return_l.value_m = new root_controller_t(configuration_p);
return return_l;
}
controller_t::status_t root_controller_t::on_event(controller_t::event_t event_p) {
if (
window_service_t* window_service = new window_service_t();
window_service_t::status_t window_status = window_service->create_window();
controller_t::status_t controller_status;
switch (window_status) {
case window_service_t::status_t::ok:
controller_status = controller_t::status_t::ok;
break;
case window_service_t::status_t::error:
default:
controller_status = controller_t::status_t::error;
break;
}
return controller_status;
void_t<root_controller_t::error_t> root_controller_factory_t::dispose(
root_controller_t* root_controller_p
) {
delete root_controller_p;
void_t<root_controller_t::error_t> return_l;
return_l.error_m = root_controller_t::error_t::none;
return return_l;
}

View File

@ -2,29 +2,33 @@
#define ACT_ROOT
#include "act/controller.h"
#include "allocate/factory.h"
#include "code/provider.h"
#include <vector>
class root_controller_t : public controller_t {
public:
enum mode_t {
cli,
app,
game
enum error_t {
none,
unknown
};
class configuration_t {
struct configuration_t {
provider_t* provider_m;
};
root_controller_t(
configuration_t* configuration_p
);
void_t<controller_t::error_t> on_event(
controller_t::event_t event_p
);
private:
std::vector<mode_t> modes_m;
public:
configuration_t(std::vector<mode_t> modes_p);
configuration_t* configuration_m;
};
controller_t::status_t on_event(event_t event_p) override;
private:
configuration_t configuration_m;
root_controller_t(configuration_t configuration_p);
friend class root_controller_factory_t;
};
class root_controller_factory_t : public factory_t<root_controller_t::configuration_t, root_controller_t> {
class root_controller_factory_t : public factory_t<root_controller_t::configuration_t, root_controller_t, root_controller_t::error_t> {
public:
root_controller_t* create(root_controller_t::configuration_t* configuration_p) override;
factory_t::status_t dispose(root_controller_t* root_controller_p) override;
return_t<root_controller_t::error_t, root_controller_t*> create(
root_controller_t::configuration_t* configuration_p
);
void_t<root_controller_t::error_t> dispose(
root_controller_t* root_controller_p
);
};
#endif

View File

@ -1,13 +1,13 @@
#ifndef ALLOCATE_FACTORY
#define ALLOCATE_FACTORY
template <class I, class O> class factory_t {
#include "code/return.h"
template <class I, class O, class E> class factory_t {
public:
enum status_t {
ok,
error
};
private:
virtual O* create(I* i) = 0;
virtual status_t dispose(O* o) = 0;
virtual return_t<E, O*> create(
I* i
) = 0;
virtual void_t<E> dispose(
O* o
) = 0;
};
#endif

2
compile/code/macros.h Normal file
View File

@ -0,0 +1,2 @@
#define STRINGIFY_MF(s) QUOTE_MF(s)
#define QUOTE_MF(s) #s

View File

@ -0,0 +1,61 @@
#include "code/observable.h"
#include "code/return.h"
template <class V> observable_t<V>::observable_t(
observable_t::configuration_t* configuration_p
) {
configuration_m = configuration_p;
}
template <class V> void observable_t<V>::observe(
observer_t<V>* observer_p
) {
observer_p->on_change(configuration_m->value_m);
observers_m.push_back(observer_p);
}
template <class V> void_t<observable_t::error_t> observable_t<V>::unobserve(
observer_t<V>* observer_p
) {
observable_t::error_t error_l = observable_t::error_t::not_observing;
for (int i = 0; i < observers_m.size(); i++) {
if (observers_m[i] == observer_p) {
observers_m.erase(i);
error_l = observable_t::error_t::none;
break;
}
}
void_t<observable_t::error_t> void_l;
void_l.error_m = error_l;
return void_l;
}
template <class V> V observable_t<V>::get_value(
) {
return value_m;
}
template <class V> void_t<observable_t::error_t> observable_t<V>::change(
V* value_p
) {
configuration_m->value_m = value_p;
for (int i = 0; i < observers_m.size(); i++) {
observer_m = observers_m[i];
observer_m->on_change(configuration_m->value_m);
}
void_t<observable_t::error_t> void_l;
void_l.error_m = observable_t::error_t::none;
return void_l;
}
template <class V> return_t<observable_t::error_t, observable_t*> observable_factory_t<V>::create(
observable_t::configuration_t* configuration_p
) {
observable_t<V>* observable_l = new observable_t<V>(
configuration_p
);
return_t<observable_t::error_t, observable_t*> return_l;
return_l.error_m = observable_t::error_t::none;
return_l.value_m = observable_l;
return return_l;
}

88
compile/code/observable.h Normal file
View File

@ -0,0 +1,88 @@
#ifndef CODE_OBSERVABLE
#define CODE_OBSERVABLE
#include "code/return.h"
#include <vector>
template<class V> class observer_t {
public:
virtual void on_change(
V* value_p
) = 0;
};
template<class V> class observable_t {
public:
enum class error_t {
none,
unknown,
not_observing
};
struct configuration_t {
V* value_m;
};
observable_t(
configuration_t* configuration_p
) {
configuration_m = configuration_p;
}
void_t<error_t> observe(
observer_t<V>* observer_p
) {
observer_p->on_change(configuration_m->value_m);
observers_m.push_back(observer_p);
}
void_t<error_t> unobserve(
observer_t<V>* observer_p
) {
observable_t::error_t error_l = observable_t::error_t::not_observing;
for (int i = 0; i < observers_m.size(); i++) {
if (observers_m[i] == observer_p) {
observers_m.erase(i);
error_l = observable_t::error_t::none;
break;
}
}
void_t<observable_t::error_t> void_l;
void_l.error_m = error_l;
return void_l;
}
V* get_value() {
return value_m;
}
void_t<error_t> change(
V* value_p
) {
configuration_m->value_m = value_p;
for (int i = 0; i < observers_m.size(); i++) {
observer_m = observers_m[i];
observer_m->on_change(configuration_m->value_m);
}
void_t<observable_t::error_t> void_l;
void_l.error_m = observable_t::error_t::none;
return void_l;
}
private:
std::vector<observer_t<V>*> observers_m;
configuration_t* configuration_m;
};
template <class V> class observable_factory_t : public observable_t<V> {
public:
return_t<observable_t::error_t, observable_t<V> *> create(
observable_t::configuration_t configuration_p
) {
observable_t<V>* observable_l = new observable_t<V>(
configuration_p
);
return_t<observable_t::error_t, observable_t*> return_l;
return_l.error_m = observable_t::error_t::none;
return_l.value_m = observable_l;
return return_l;
}
void_t<observable_t::error_t> dispose(
observable_t<V>* observable_p
) {
delete observable_p;
void_t<observable_t::error_t> void_l;
void_l.error_m = observable_t::error_t::none;
return void_l;
}
};
#endif

29
compile/code/provider.cpp Normal file
View File

@ -0,0 +1,29 @@
#include "code/provider.h"
#include "inform/text_service.h"
#include "draw/window_service.h"
provider_t::provider_t(
provider_t::configuration_t* configuration_p
) {
configuration_m = configuration_p;
}
return_t<provider_t::error_t, provider_t*> provider_factory_t::create(
provider_t::configuration_t* configuration_p
) {
return_t<provider_t::error_t, provider_t*> return_l;
return_l.error_m = provider_t::error_t::none;
return_l.value_m = new provider_t(
configuration_p
);
return return_l;
}
void_t<provider_t::error_t> provider_factory_t::dispose(
provider_t* provider_p
) {
delete provider_p;
void_t<provider_t::error_t> void_l;
void_l.error_m = provider_t::error_t::none;
return void_l;
}

33
compile/code/provider.h Normal file
View File

@ -0,0 +1,33 @@
#ifndef CODE_PROVIDER
#define CODE_PROVIDER
#include "allocate/factory.h"
#include "code/return.h"
#include "inform/text_service.h"
#include "draw/window_service.h"
class provider_t {
friend class provider_factory_t;
public:
enum error_t {
none,
unknown
};
struct configuration_t {
text_service_t* text_service_m;
window_service_t* window_service_m;
};
configuration_t* configuration_m;
private:
provider_t(
configuration_t* configuration_p
);
};
class provider_factory_t : public factory_t<provider_t::configuration_t, provider_t, provider_t::error_t> {
public:
return_t<provider_t::error_t, provider_t*> create(
provider_t::configuration_t* configuration_p
);
void_t<provider_t::error_t> dispose(
provider_t* root_controller_p
);
};
#endif

16
compile/code/return.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef CODE_RETURN
#define CODE_RETURN
class empty_t {
};
template <class E, class D> class return_t {
public:
enum component_t {
render
};
component_t component_m;
E error_m;
D value_m;
};
template <class E> class void_t : public return_t<E, empty_t> {
};
#endif

View File

@ -0,0 +1,123 @@
#include "allocate/factory.h"
#include "code/return.h"
#include "draw/opengl_service.h"
#include <GL/gl.h>
opengl_service_t::opengl_service_t(
opengl_service_t::configuration_t* configuration_p
) {
configuration_m = configuration_p;
}
void_t<opengl_service_t::error_t> opengl_service_t::draw(
int cycle_p
) {
glClearColor(1.0, 1.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
double rotate_x = static_cast<double>(cycle_p * 1);
double rotate_y = static_cast<double>(cycle_p * 1);
glRotatef( rotate_x, 1.0, 0.0, 0.0 );
glRotatef( rotate_y, 0.0, 1.0, 0.0 );
glBegin(GL_POLYGON);
glColor3f( 1.0, 1.0, 1.0 );
glVertex3f( 0.5, -0.5, 0.5 );
glVertex3f( 0.5, 0.5, 0.5 );
glVertex3f( -0.5, 0.5, 0.5 );
glVertex3f( -0.5, -0.5, 0.5 );
glEnd();
// Purple side - RIGHT
glBegin(GL_POLYGON);
glColor3f( 1.0, 0.0, 1.0 );
glVertex3f( 0.5, -0.5, -0.5 );
glVertex3f( 0.5, 0.5, -0.5 );
glVertex3f( 0.5, 0.5, 0.5 );
glVertex3f( 0.5, -0.5, 0.5 );
glEnd();
// Green side - LEFT
glBegin(GL_POLYGON);
glColor3f( 0.0, 1.0, 0.0 );
glVertex3f( -0.5, -0.5, 0.5 );
glVertex3f( -0.5, 0.5, 0.5 );
glVertex3f( -0.5, 0.5, -0.5 );
glVertex3f( -0.5, -0.5, -0.5 );
glEnd();
// Blue side - TOP
glBegin(GL_POLYGON);
glColor3f( 0.0, 0.0, 1.0 );
glVertex3f( 0.5, 0.5, 0.5 );
glVertex3f( 0.5, 0.5, -0.5 );
glVertex3f( -0.5, 0.5, -0.5 );
glVertex3f( -0.5, 0.5, 0.5 );
glEnd();
// Red side - BOTTOM
glBegin(GL_POLYGON);
glColor3f( 1.0, 0.0, 0.0 );
glVertex3f( 0.5, -0.5, -0.5 );
glVertex3f( 0.5, -0.5, 0.5 );
glVertex3f( -0.5, -0.5, 0.5 );
glVertex3f( -0.5, -0.5, -0.5 );
glEnd();
glFlush();
void_t<opengl_service_t::error_t> void_l;
void_l.error_m = opengl_service_t::error_t::none;
return void_l;
}
void_t<opengl_service_t::error_t> opengl_service_t::enable_depth_test(
) {
glEnable(
GL_DEPTH_TEST
);
void_t<opengl_service_t::error_t> void_l;
void_l.error_m = opengl_service_t::error_t::none;
return void_l;
}
void_t<opengl_service_t::error_t> opengl_service_t::resize_viewport(
int x,
int y,
int width,
int height
) {
void_t<opengl_service_t::error_t> void_l;
void_l.error_m = opengl_service_t::error_t::none;
glViewport(
0,
0,
width,
height
);
return void_l;
}
return_t<opengl_service_t::error_t, opengl_service_t*> opengl_service_factory_t::create(
opengl_service_t::configuration_t* configuration_p
) {
opengl_service_t* opengl_service_l = new opengl_service_t(
configuration_p
);
return_t<opengl_service_t::error_t, opengl_service_t*> return_l;
return_l.error_m = opengl_service_t::error_t::none;
return_l.value_m = opengl_service_l;
return return_l;
}
void_t<opengl_service_t::error_t> opengl_service_factory_t::dispose(
opengl_service_t* opengl_service_p
) {
delete opengl_service_p;
void_t<opengl_service_t::error_t> void_l;
void_l.error_m = opengl_service_t::error_t::none;
return void_l;
}

View File

@ -0,0 +1,41 @@
#ifndef DRAW_OPENGL_SERVICE
#define DRAW_OPENGL_SERVICE
#include "allocate/factory.h"
#include "code/return.h"
class opengl_service_t {
friend class opengl_service_factory_t;
public:
enum error_t {
none,
unknown
};
struct configuration_t {
};
void_t<error_t> draw(
int cycle_p
);
void_t<error_t> enable_depth_test(
);
void_t<error_t> resize_viewport(
int x,
int y,
int width,
int height
);
private:
opengl_service_t(
configuration_t* configuration_p
);
configuration_t* configuration_m;
};
class opengl_service_factory_t : public factory_t<opengl_service_t::configuration_t, opengl_service_t, opengl_service_t::error_t> {
public:
return_t<opengl_service_t::error_t, opengl_service_t*> create(
opengl_service_t::configuration_t* configuration_p
);
void_t<opengl_service_t::error_t> dispose(
opengl_service_t* opengl_service_p
);
};
#endif

View File

@ -1,11 +0,0 @@
#ifndef SERVICE_WINDOW
#define SERVICE_WINDOW
class window_service_t {
public:
enum status_t {
ok,
error
};
status_t create_window();
};
#endif

View File

@ -0,0 +1,36 @@
#ifndef DRAW_WINDOW_SERVICE
#define DRAW_WINDOW_SERVICE
#include "allocate/factory.h"
#include "code/return.h"
#include "inform/text_service.h"
#include <string>
class window_service_t {
friend class window_service_factory_t;
public:
enum error_t {
none,
unknown,
x_server_connection_failure
};
struct configuration_t {
};
void_t<error_t> create_window(
std::string* window_title
);
private:
window_service_t(
configuration_t* configuration_p
);
configuration_t* configuration_m;
};
class window_service_factory_t : public factory_t<window_service_t::configuration_t, window_service_t, window_service_t::error_t> {
public:
return_t<window_service_t::error_t, window_service_t*> create(
window_service_t::configuration_t* configuration_p
);
void_t<window_service_t::error_t> dispose(
window_service_t* window_service_p
);
};
#endif

View File

@ -0,0 +1,12 @@
#include "fabricate/face.h"
#include "fabricate/vertex.h"
face_t::face_t(
vertex_t vertex_a_p,
vertex_t vertex_b_p,
vertex_t vertex_c_p
) {
vertex_a = vertex_a_p;
vertex_b = vertex_b_p;
vertex_c = vertex_c_p;
}

15
compile/fabricate/face.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef FABRICATE_FACE
#define FABRICATE_FACE
#include "fabricate/vertex.h"
class face_t {
public:
vertex_t vertex_a;
vertex_t vertex_b;
vertex_t vertex_c;
face_t(
vertex_t vertex_a_p,
vertex_t vertex_b_p,
vertex_t vertex_c_p
);
};
#endif

View File

13
compile/fabricate/model.h Normal file
View File

@ -0,0 +1,13 @@
#ifndef FABRICATE_MODEL
#define FABRICATE_MODEL
#include <vector>
class model_t {
public:
std::vector<unsigned int> vertex_indices_m;
std::vector<unsigned int> texture_coordinate_indices_m;
std::vector<unsigned int> normal_indices_m;
std::vector<vertex_t> vertices_m;
std::vector<texture_coordinate_t> texture_coordinates_m;
std::vector<vector_t> normals_m;
};
#endif

View File

@ -0,0 +1,48 @@
#include "fabricate/model_service.h"
#include "code/return.h"
#include <string>
model_service_t::model_service_t(
model_service_t::configuration_t* configuration_p
) {
configuration_m = configuration_p;
}
return_t<model_service_t::error_t, model_t*> get_model_by_id(
model_service_t::model_id_t model_id_p
) {
model_t* model_l;
switch (model_id_p) {
case model_service_t::model_id_t::monkey:
// model_l = new model with correct data
break;
default:
model_l = nullptr;
break;
}
return_t<model_service_t::error_t, model_t*> return_l;
return_l.error_m = model_service_t::error_t::none;
return_l.value_m = model_l;
return return_l;
}
return_t<model_service_t::error_t, model_service_t*> create(
model_service_t::configuration_t* configuration_p
) {
model_service_t* model_service_l = new model_service_t(
configuration_p
);
return_t<model_service_t::error_t, model_service_t*> return_l;
return_l.error_m = model_service_t::error_t::none;
return_l.value_m = model_service_l;
return return_l;
}
void_t<model_service_t::error_t> dispose(
model_service_t* model_service_p
) {
delete model_service_p;
void_t<model_service_t::error_t> void_l;
void_l.error_m = model_service_t::error_t::none;
return void_l;
}

View File

@ -0,0 +1,37 @@
#ifndef FABRICATE_MODEL_PARSER
#define FABRICATE_MODEL_PARSER
#include "allocate/factory.h"
#include "code/return.h"
#include <string>
class model_service_t {
friend class model_service_factory_t;
public:
enum error_t {
none,
unknown
};
enum model_id_t {
monkey
};
struct configuration_t {
std::string obj_files_m;
};
return_t<error_t, model_t*> get_model_by_id(
model_id_t model_id_p
);
private:
model_service_t(
configuration_t* configuration_p
);
configuration_t* configuration_m;
};
class model_service_factory_t : public factory_t<model_service_t::configuration_t, model_service_t, model_service_t::error_t> {
public:
return_t<model_service_t::error_t, model_service_t*> create(
model_service_t::configuration_t* configuration_p
);
void_t<model_service_t::error_t> dispose(
model_service_t* model_service_p
);
};
#endif

View File

@ -0,0 +1,9 @@
#include "fabricate/texture_coordinate.h"
texture_coordinate_t(
float u_p,
float v_p
) {
u = u_p;
v = v_p;
}

View File

@ -0,0 +1,12 @@
#ifndef FABRICATE_TEXTURE_COORDINATE
#define FABRICATE_TEXTURE_COORDINATE
class texture_coordinate_t {
public:
float u;
float v;
texture_coordinate_t(
float u_p,
float v_p
);
};
#endif

View File

@ -0,0 +1,11 @@
#include "fabricate/vector.h"
vector_t::vector_t(
float x_p,
float y_p,
float z_p
) {
x = x_p;
y = y_p;
z = z_p;
}

View File

@ -0,0 +1,14 @@
#ifndef FABRICATE_VECTOR
#define FABRICATE_VECTOR
class vector_t {
public:
float x;
float y;
float z;
vector_t(
float x_p,
float y_p,
float z_p
);
};
#endif

View File

@ -0,0 +1,11 @@
#include "fabricate/vertex.h"
vertex_t::vertex_t(
float x_p,
float y_p,
float z_p
) {
x = x_p;
y = y_p;
z = z_p;
}

View File

@ -0,0 +1,14 @@
#ifndef FABRICATE_VERTEX
#define FABRICATE_VERTEX
class vertex_t {
public:
float x;
float y;
float z;
vertex_t(
float x_p,
float y_p,
float z_p
);
}
#endif

View File

@ -0,0 +1,60 @@
#include "inform/text_service.h"
#include "code/return.h"
#include <string>
text_service_t::text_service_t(
text_service_t::configuration_t* configuration_p
) {
configuration_m = configuration_p;
}
void text_service_t::update(
text_service_t::text_t text_p,
std::string string_p
) {
text_to_string[text_p] = string_p;
}
void_t<text_service_t::error_t> text_service_t::initialize(
) {
text_service_t::language_t language_l = configuration_m->language_m;
switch (language_l) {
case text_service_t::language_t::english:
update(text_service_t::text_t::window_title, "Fortuitous Frogs");
break;
}
void_t<text_service_t::error_t> void_l;
void_l.error_m = text_service_t::error_t::none;
return void_l;
}
return_t<text_service_t::error_t, std::string> text_service_t::get_text(
text_service_t::text_t text_p
) {
std::string string_l = text_to_string[text_p];
return_t<text_service_t::error_t, std::string> return_l;
return_l.error_m = text_service_t::error_t::none;
return_l.value_m = string_l;
return return_l;
}
return_t<text_service_t::error_t, text_service_t*> text_service_factory_t::create(
text_service_t::configuration_t* configuration_p
) {
text_service_t* text_service_l = new text_service_t(
configuration_p
);
return_t<text_service_t::error_t, text_service_t*> return_l;
return_l.error_m = text_service_t::error_t::none;
return_l.value_m = text_service_l;
return return_l;
}
void_t<text_service_t::error_t> text_service_factory_t::dispose(
text_service_t* text_service_p
) {
delete text_service_p;
void_t<text_service_t::error_t> void_l;
void_l.error_m = text_service_t::error_t::none;
return void_l;
}

View File

@ -0,0 +1,52 @@
#ifndef INTEGRATE_TEXT_SERVICE
#define INTEGRATE_TEXT_SERVICE
#include "allocate/factory.h"
#include "code/return.h"
#include <string>
#include <map>
class text_service_t {
friend class text_service_factory_t;
public:
enum status_t {
ok,
error
};
enum error_t {
none,
unknown
};
enum language_t {
english
};
enum text_t {
window_title
};
struct configuration_t {
language_t language_m;
};
return_t<error_t, std::string> get_text(
text_t text_p
);
void_t<error_t> initialize(
);
private:
text_service_t(
configuration_t* configuration_p
);
configuration_t* configuration_m;
std::map<text_t, std::string> text_to_string;
void update(
text_t text_p,
std::string string_p
);
};
class text_service_factory_t : public factory_t<text_service_t::configuration_t, text_service_t, text_service_t::error_t> {
public:
return_t<text_service_t::error_t, text_service_t*> create(
text_service_t::configuration_t* configuration_p
);
void_t<text_service_t::error_t> dispose(
text_service_t* text_service_p
);
};
#endif

View File

@ -1 +0,0 @@
X11

View File

@ -1,13 +1,107 @@
#include "act/controller.h"
#include "act/root.h"
#include "code/provider.h"
#include "code/macros.h"
#include <vector>
#include <stdio.h>
#include <string>
#include <fstream>
#include <iostream>
int main(int argc, char *argv[]) {
root_controller_factory_t factory_l;
std::vector<root_controller_t::mode_t> modes_l;
modes_l.push_back(root_controller_t::mode_t::app);
root_controller_t::configuration_t configuration_l(modes_l);
root_controller_t* controller_l = factory_l.create(&configuration_l);
controller_t::status_t status_l = controller_l->on_event(controller_t::event_t::start);
factory_l.dispose(controller_l);
return status_l;
// Parse configuration files.
std::string obj_list_filepath_l = ROOT_DIRECTORY_MV "/pack/obj_files.txt";
FILE* obj_list_file_l = fopen(obj_list_filepath_l.data(), "r");
char char_l = fgetc(obj_list_file_l);
std::string obj_file_l = "";
std::vector<std::string> obj_files_l;
while (char_l != EOF) {
if (char_l == '\n') {
std::string copy_l(obj_file_l);
obj_files_l.push_back(copy_l);
obj_file_l.clear();
} else {
obj_file_l += char_l;
}
char_l = fgetc(obj_list_file_l);
}
// Read OBJ files.
for (int i = 0; i < obj_files_l.size(); i++) {
obj_file_l = obj_files_l[i];
std::string line_l;
std::ifstream file_l;
file_l.open(obj_file_l);
while (getline(file_l, line_l)) {
char first_l = line_l[0];
char second_l = line_l[1];
printf("%c\n", first_l);
if (first_l == 'v' && second_l != ' ') {
// Create vertex
} else if (first_l == 'v' && second_l == 'n') {
// Create vertex normal vector
} else if (first_l == 'v' && second_l == 't') {
// Create texture coordinate
} else if (first_l == 'f') {
// Create face
} else {
continue;
}
}
}
// Create text service.
text_service_factory_t text_service_factory_l;
text_service_t::configuration_t text_service_configuration_l;
text_service_configuration_l.language_m = text_service_t::language_t::english;
text_service_t* text_service_l = text_service_factory_l.create(
&text_service_configuration_l
).value_m;
// Create window service.
window_service_factory_t window_service_factory_l;
window_service_t::configuration_t window_service_configuration_l;
window_service_t* window_service_l = window_service_factory_l.create(
&window_service_configuration_l
).value_m;
// Create provider.
provider_factory_t provider_factory_l;
provider_t::configuration_t provider_configuration_l;
provider_configuration_l.text_service_m = text_service_l;
provider_configuration_l.window_service_m = window_service_l;
provider_t* provider_l = provider_factory_l.create(
&provider_configuration_l
).value_m;
// Create root controller.
root_controller_factory_t root_controller_factory_l;
root_controller_t::configuration_t root_controller_configuration_l;
root_controller_configuration_l.provider_m = provider_l;
root_controller_t* root_controller_l = root_controller_factory_l.create(
&root_controller_configuration_l
).value_m;
// Start root controller.
controller_t::error_t root_controller_event_l = root_controller_l->on_event(
controller_t::event_t::start
).error_m;
// Clean up
root_controller_factory_l.dispose(
root_controller_l
);
provider_factory_l.dispose(
provider_l
);
window_service_factory_l.dispose(
window_service_l
);
text_service_factory_l.dispose(
text_service_l
);
if (root_controller_event_l == controller_t::error_t::none) {
return 0;
}
return 1;
}

View File

@ -1,3 +0,0 @@
main.cpp
act/root.cpp
platform/linux/draw/window.cpp

View File

@ -0,0 +1,106 @@
#include "allocate/factory.h"
#include "code/return.h"
#include "target/linux/draw/opengl_x11_service.h"
opengl_x11_service_t::opengl_x11_service_t(
opengl_x11_service_t::configuration_t* configuration_p
) {
configuration_m = configuration_p;
}
return_t<opengl_x11_service_t::error_t, XVisualInfo*> opengl_x11_service_t::get_visual_info(
Display* display_p
) {
return_t<opengl_x11_service_t::error_t, XVisualInfo*> return_l;
return_l.error_m = opengl_x11_service_t::error_t::none;
GLint attributes_l[] = {
GLX_RGBA,
GLX_DEPTH_SIZE,
24,
GLX_DOUBLEBUFFER,
None
};
XVisualInfo *visual_info_l = glXChooseVisual(
display_p,
0,
attributes_l
);
if (visual_info_l == NULL) {
return_l.error_m = opengl_x11_service_t::error_t::no_visual_found;
}
return_l.value_m = visual_info_l;
return return_l;
}
void_t<opengl_x11_service_t::error_t> opengl_x11_service_t::initialize_context(
Display* display_p,
XVisualInfo* visual_info_p,
Window window_p
){
void_t<opengl_x11_service_t::error_t> void_l;
configuration_m->glx_context_m = glXCreateContext(
display_p,
visual_info_p,
NULL,
GL_TRUE
);
glXMakeCurrent(
display_p,
window_p,
configuration_m->glx_context_m
);
void_l.error_m = opengl_x11_service_t::error_t::none;
return void_l;
}
void_t<opengl_x11_service_t::error_t> opengl_x11_service_t::swap_buffers(
Display* display_p,
Window window_p
) {
void_t<opengl_x11_service_t::error_t> void_l;
void_l.error_m = opengl_x11_service_t::error_t::none;
glXSwapBuffers(
display_p,
window_p
);
return void_l;
}
void_t<opengl_x11_service_t::error_t> opengl_x11_service_t::dispose(
Display* display_p
) {
void_t<opengl_x11_service_t::error_t> void_l;
void_l.error_m = opengl_x11_service_t::error_t::none;
glXMakeCurrent(
display_p,
None,
NULL
);
glXDestroyContext(
display_p,
configuration_m->glx_context_m
);
return void_l;
}
return_t<opengl_x11_service_t::error_t, opengl_x11_service_t*> opengl_x11_service_factory_t::create(
opengl_x11_service_t::configuration_t* configuration_p
) {
opengl_x11_service_t* opengl_x11_service_l = new opengl_x11_service_t(
configuration_p
);
return_t<opengl_x11_service_t::error_t, opengl_x11_service_t*> return_l;
return_l.error_m = opengl_x11_service_t::error_t::none;
return_l.value_m = opengl_x11_service_l;
return return_l;
}
void_t<opengl_x11_service_t::error_t> opengl_x11_service_factory_t::dispose(
opengl_x11_service_t* opengl_x11_service_p
) {
delete opengl_x11_service_p;
void_t<opengl_x11_service_t::error_t> void_l;
void_l.error_m = opengl_x11_service_t::error_t::none;
return void_l;
}

View File

@ -0,0 +1,48 @@
#ifndef TARGET_LINUX_DRAW_OPENGL_X11_SERVICE
#define TARGET_LINUX_DRAW_OPENGL_X11_SERVICE
#include "allocate/factory.h"
#include "code/return.h"
#include <GL/glx.h>
class opengl_x11_service_t {
friend class opengl_x11_service_factory_t;
public:
enum error_t {
none,
unknown,
no_visual_found
};
struct configuration_t {
GLXContext glx_context_m;
};
return_t<opengl_x11_service_t::error_t, XVisualInfo*> get_visual_info(
Display* display_p
);
void_t<error_t> initialize_context(
Display* display_p,
XVisualInfo* visual_info_p,
Window window_p
);
void_t<opengl_x11_service_t::error_t> swap_buffers(
Display* display_p,
Window window_p
);
void_t<error_t> dispose(
Display* display_p
);
private:
opengl_x11_service_t(
configuration_t* configuration_p
);
configuration_t* configuration_m;
};
class opengl_x11_service_factory_t : public factory_t<opengl_x11_service_t::configuration_t, opengl_x11_service_t, opengl_x11_service_t::error_t> {
public:
return_t<opengl_x11_service_t::error_t, opengl_x11_service_t*> create(
opengl_x11_service_t::configuration_t* configuration_p
);
void_t<opengl_x11_service_t::error_t> dispose(
opengl_x11_service_t* opengl_x11_service_p
);
};
#endif

View File

@ -1,31 +0,0 @@
#include "draw/window.h"
#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
window_service_t::status_t window_service_t::create_window() {
Display *d;
Window w;
XEvent e;
const char *msg = "Hello, World!";
int s;
d = XOpenDisplay(NULL);
if (d == NULL) {
return window_service_t::status_t::error;
}
s = DefaultScreen(d);
w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 100, 100, 1, BlackPixel(d, s), WhitePixel(d, s));
XSelectInput(d, w, ExposureMask | KeyPressMask);
XMapWindow(d, w);
while (true) {
XNextEvent(d, &e);
if (e.type == Expose) {
XFillRectangle(d, w, DefaultGC(d, s), 20, 20, 10, 10);
XDrawString(d, w, DefaultGC(d, s), 10, 50, msg, strlen(msg));
}
if (e.type == KeyPress)
break;
}
XCloseDisplay(d);
return window_service_t::status_t::ok;
}

View File

@ -0,0 +1,187 @@
#include "draw/opengl_service.h"
#include "draw/window_service.h"
#include "inform/text_service.h"
#include "target/linux/draw/opengl_x11_service.h"
window_service_t::window_service_t(
window_service_t::configuration_t* configuration_p
) {
configuration_m = configuration_p;
}
void_t<window_service_t::error_t> window_service_t::create_window(
std::string* window_title
) {
void_t<window_service_t::error_t> void_l;
void_l.error_m = window_service_t::error_t::unknown;
Display* display_l = XOpenDisplay(
NULL
);
if (display_l == NULL) {
void_l.error_m = window_service_t::error_t::x_server_connection_failure;
return void_l;
}
Window root_window_l = DefaultRootWindow(
display_l
);
// Create OpenGL X11 Service for binding
opengl_x11_service_t::configuration_t opengl_x11_service_configuration_l;
opengl_x11_service_factory_t opengl_x11_service_factory_l;
opengl_x11_service_t* opengl_x11_service_l = opengl_x11_service_factory_l.create(
&opengl_x11_service_configuration_l
).value_m;
XVisualInfo* visual_info_l = opengl_x11_service_l->get_visual_info(
display_l
).value_m;
Colormap colormap_l = XCreateColormap(
display_l,
root_window_l,
visual_info_l->visual,
AllocNone
);
XSetWindowAttributes set_window_attributes_l;
set_window_attributes_l.colormap = colormap_l;
set_window_attributes_l.event_mask = ExposureMask | KeyPressMask;
Window window_l = XCreateWindow(
display_l,
root_window_l,
0,
0,
320,
240,
0,
visual_info_l->depth,
InputOutput,
visual_info_l->visual,
CWColormap | CWEventMask,
&set_window_attributes_l
);
XSelectInput(
display_l,
window_l,
ExposureMask | KeyPressMask
);
XMapWindow(
display_l,
window_l
);
XStoreName(
display_l,
window_l,
window_title->data()
);
opengl_x11_service_l->initialize_context(
display_l,
visual_info_l,
window_l
);
// Create OpenGL Service for rendering
opengl_service_t::configuration_t opengl_service_configuration_l;
opengl_service_factory_t opengl_service_factory_l;
opengl_service_t* opengl_service_l = opengl_service_factory_l.create(
&opengl_service_configuration_l
).value_m;
opengl_service_l->enable_depth_test(
);
int display_fd_l = ConnectionNumber(display_l);
fd_set in_fds;
int cycle_l = 0;
XWindowAttributes window_attributes_l;
XEvent event_l;
while (true) {
FD_ZERO(&in_fds);
FD_SET(display_fd_l, &in_fds);
// Set our timer.
timeval timeval_l;
timeval_l.tv_usec = 8333;
timeval_l.tv_sec = 0;
// Wait for X Event or a Timer
int select_l = select(
display_fd_l + 1,
&in_fds,
0,
0,
&timeval_l
);
if (select_l >= 0) {
// event received
switch (event_l.type) {
case KeyPress:
opengl_x11_service_l->dispose(
display_l
);
XDestroyWindow(
display_l,
window_l
);
XCloseDisplay(
display_l
);
break;
case Expose:
XGetWindowAttributes(
display_l,
window_l,
&window_attributes_l
);
opengl_service_l->resize_viewport(
0,
0,
window_attributes_l.width,
window_attributes_l.height
);
opengl_service_l->draw(
cycle_l
);
opengl_x11_service_l->swap_buffers(
display_l,
window_l
);
break;
default:
break;
}
} else {
// timeout
}
while (XPending(display_l)) {
XNextEvent(
display_l,
&event_l
);
}
cycle_l += 1;
}
void_l.error_m = window_service_t::error_t::none;
return void_l;
}
return_t<window_service_t::error_t, window_service_t*> window_service_factory_t::create(
window_service_t::configuration_t* configuration_p
) {
return_t<window_service_t::error_t, window_service_t*> return_l;
return_l.error_m = window_service_t::error_t::none;
window_service_t* window_service_l = new window_service_t(
configuration_p
);
return_l.value_m = window_service_l;
return return_l;
}
void_t<window_service_t::error_t> window_service_factory_t::dispose(
window_service_t* window_service_p
) {
delete window_service_p;
void_t<window_service_t::error_t> void_l;
void_l.error_m = window_service_t::error_t::none;
return void_l;
}

Binary file not shown.

7
pack/cpp_files.txt Normal file
View File

@ -0,0 +1,7 @@
main.cpp
act/root.cpp
code/provider.cpp
draw/opengl_service.cpp
inform/text_service.cpp
target/linux/draw/window_service.cpp
target/linux/draw/opengl_x11_service.cpp

3
pack/libraries.txt Normal file
View File

@ -0,0 +1,3 @@
X11
GL
GLU

1
pack/obj_files.txt Normal file
View File

@ -0,0 +1 @@
/home/cogentleman/main/jww/design/3d_models/cube.obj