Skip to content

Commit

Permalink
Merge pull request #8 from inFullMobile/develop
Browse files Browse the repository at this point in the history
Release 0.3
  • Loading branch information
noxytrux authored May 4, 2018
2 parents fb6adf0 + 6cff7f3 commit 69b0aab
Show file tree
Hide file tree
Showing 27 changed files with 6,502 additions and 20 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ PLATFORM/Windows/pixfight/*.dll
MAPEDITOR/PixEditor/DerivedData/
MAPEDITOR/DerivedData/
MAPEDITOR/bin/
MAPEDITOR/nul
MAPEDITOR/nul

#html5
PLATFORM/HTML5/bin/
38 changes: 37 additions & 1 deletion CORE/AI/AIPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,31 @@ void AIPlayer::moveCurrentObjectToPoint(GameUnit *currentObject, xVec2 &destinat
//"lock" thread
action = false;


#ifdef __EMSCRIPTEN__

#ifdef __EMSCRIPTEN_PTHREADS__

syncToMainLoop([currentObject](void *context, GameLogic *sender){

currentObject->makeMove();
});
});

#else

currentObject->makeMove();

#endif

#else

syncToMainLoop([currentObject](void *context, GameLogic *sender){

currentObject->makeMove();
});

#endif

}

void AIPlayer::updateAI(std::vector<GameUnit *> & units, std::vector<GameBase *> & bases) {
Expand Down Expand Up @@ -711,11 +732,26 @@ void AIPlayer::executeAI(std::vector<GameUnit *> & units, std::vector<GameBase *

for (int c = 0; c < 2; ++c) { //move by whole unit task

#ifdef __EMSCRIPTEN__

#ifdef __EMSCRIPTEN_PTHREADS__

while (false == action.load()) {

std::this_thread::yield();
}

#endif

#else

while (false == action.load()) {

std::this_thread::yield();
}

#endif

if (actual->firstPriorityTask == nullptr) {

continue;
Expand Down
5 changes: 5 additions & 0 deletions CORE/Audio/Audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ Audio::~Audio() noexcept {
this->unload();
}

void Audio::update() {

_system->update();
}

void Audio::checkResult(FMOD_RESULT result) const {

if (result == FMOD_OK) {
Expand Down
3 changes: 3 additions & 0 deletions CORE/Audio/Audio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class Audio {
void setVolume(float volume);
float getVolume();

//required by webGL
void update();

private:

void unload();
Expand Down
18 changes: 18 additions & 0 deletions CORE/Core-pch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@
#define NUMBER_OF_COMPONENTS_PER_VERTEX 2
#define NUMBER_OF_INDICES 6

#ifdef __EMSCRIPTEN__

#define GL_GLEXT_PROTOTYPES
#include <GLES/gl.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#define GLFW_INCLUDE_ES2
#include <GLFW/glfw3.h>
#include <emscripten/emscripten.h>

#define glBindVertexArray glBindVertexArrayOES
#define glGenVertexArrays glGenVertexArraysOES
#define glDeleteVertexArrays glDeleteVertexArraysOES

#else

#ifdef _WIN32

#define NOMINMAX
Expand Down Expand Up @@ -85,6 +101,8 @@

#endif

#endif

#define OFFSET(st, m) \
((size_t) ( (char *)&((st *)(0))->m - (char *)0 ))

Expand Down
39 changes: 34 additions & 5 deletions CORE/GameLogic/GameLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ GameLogic::GameLogic(const float &screenWidth,
, _currentMapName("")
, _timer(nullptr) {

#ifndef __EMSCRIPTEN__
auto fontPath = _rootPath + "Lato-Black.ttf";
_font = new FontRender(fontPath);

auto shaderPath = _rootPath + "fontsimple";
_font->setupOpenGL(shaderPath);
_font->setFontSize(30);
_font->setFontColor(FGLRed);
#endif

_selectedUnit = nullptr;

Expand All @@ -66,11 +68,14 @@ GameLogic::~GameLogic() noexcept {

this->teardownOpenGL();

#ifndef __EMSCRIPTEN__
if (_font) {

delete _font;
_font = nullptr;
}
#endif

}

bool GameLogic::createNewGame(const std::string &gamename,
Expand Down Expand Up @@ -854,14 +859,36 @@ void GameLogic::endTurn() {

_botsThinking = true;

std::thread thread([&]() {
#ifdef __EMSCRIPTEN__

#ifdef __EMSCRIPTEN_PTHREADS__

std::thread thread([&]() {

this->proceedBotsLogic();
});

thread.detach();

#else

this->proceedBotsLogic();

#endif

#else

std::thread thread([&]() {

this->proceedBotsLogic();

std::cout << "Thread: " << std::this_thread::get_id() << " finished!" << std::endl;
});

this->proceedBotsLogic();
thread.detach();

std::cout << "Thread: " << std::this_thread::get_id() << " finished!" << std::endl;
});
#endif

thread.detach();
}
}

Expand Down Expand Up @@ -958,6 +985,7 @@ void GameLogic::Render() {

//draw some statistics

#ifndef __EMSCRIPTEN__
float sx = 2.0 / _screenWidth;
float sy = 2.0 / _screenHeight;

Expand All @@ -982,6 +1010,7 @@ void GameLogic::Render() {
_font->drawText(cashstr.c_str(), -1.96, -1.9, sx, sy);

_font->end();
#endif

_drawingContext->unbindVertexArray();
}
Expand Down
9 changes: 7 additions & 2 deletions CORE/GameLogic/GameLogic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
#include "GameBase.hpp"
#include "GameMap.hpp"

#ifndef __EMSCRIPTEN__
#include "FontRender.hpp"
#endif

#include "DrawingContext.hpp"
#include "GameAnimation.hpp"
#include "Audio.hpp"
#include "GameTimer.hpp"
#include "FontRender.hpp"
#include "GameSync.hpp"

class GameLogic final {
Expand Down Expand Up @@ -188,13 +190,16 @@ class GameLogic final {
Audio::SoundID okSound;

DrawingContext *_drawingContext;
FontRender *_fontRender;

const Audio *_audioUnit;

std::string _currentMapName;
GameTimer *_timer;

#ifndef __EMSCRIPTEN__
FontRender *_font;
#endif

GameUnit *_selectedUnit;
bool _hardAI;
bool _botsThinking;
Expand Down
12 changes: 12 additions & 0 deletions CORE/Math/xSimpleTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,19 @@

typedef float xF32;
typedef double xF64;
#elif __EMSCRIPTEN__
typedef long long xI64;
typedef signed int xI32;
typedef signed short xI16;
typedef signed char xI8;

typedef unsigned long long xU64;
typedef unsigned int xU32;
typedef unsigned short xU16;
typedef unsigned char xU8;

typedef float xF32;
typedef double xF64;
#else
#error Unknown platform!
#endif
Expand Down
6 changes: 5 additions & 1 deletion CORE/utilities/Timer/AndroidTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ void AndroidTimer::update() {

timespec lTimeVal;

clock_gettime(CLOCK_THREAD_CPUTIME_ID, &lTimeVal);
#ifdef __EMSCRIPTEN__
clock_gettime(CLOCK_MONOTONIC, &lTimeVal);
#else
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &lTimeVal);
#endif

this->m_startTime = lTimeVal.tv_sec + (lTimeVal.tv_nsec * 1.0e-9);
m_elapsed = (m_startTime - m_lastTime);
Expand Down
8 changes: 8 additions & 0 deletions CORE/utilities/Timer/GameTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
#include "AndroidTimer.hpp"
#endif

#ifdef __EMSCRIPTEN__
#include "AndroidTimer.hpp"
#endif

extern GameTimer *getPlatformTimerInstance() {

#ifdef __linux__
Expand All @@ -42,5 +46,9 @@ extern GameTimer *getPlatformTimerInstance() {
return new AndroidTimer();
#endif

#ifdef __EMSCRIPTEN__
return new AndroidTimer();
#endif

return nullptr;
}
Loading

0 comments on commit 69b0aab

Please sign in to comment.