Skip to content

Commit

Permalink
Merge pull request #11 from Kiritow/pre-merge
Browse files Browse the repository at this point in the history
Update to v0.7
  • Loading branch information
Kiritow authored Jul 7, 2017
2 parents e87f513 + c769c0a commit edefaa6
Show file tree
Hide file tree
Showing 33 changed files with 772 additions and 245 deletions.
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.c linguist-language=C++
*.cpp linguist-language=C++
*.h linguist-language=C++
*.hpp linguist-language=C++
49 changes: 0 additions & 49 deletions MiniEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,31 +74,6 @@ namespace MiniEngine
delete pimpl;
}

int SetClipboardText(const std::string& str)
{
return SDL_SetClipboardText(str.c_str());
}

std::string GetClipboardText()
{
char* pstr=SDL_GetClipboardText();
if(pstr==nullptr)
{
return std::string();
}
else
{
std::string s(pstr);
SDL_free(pstr);
return s;
}
}

bool HasClipboardText()
{
return SDL_HasClipboardText()==SDL_TRUE;
}

bool GetScanKeyState(SDL_Scancode code)
{
return SDL_GetKeyboardState(NULL)[code];
Expand Down Expand Up @@ -130,27 +105,3 @@ bool canexecute(std::string Path)
#else /// _MINIENGINE_HAS_UNISTD == 0
/// File Functions will be implied in platform specific source file.
#endif

int _miniengine_argc;
char** _miniengine_argv;

/// Default Setup Code
int main(int argc, char* argv[])
{
_miniengine_argc=argc;
_miniengine_argv=argv;
MiniEngine::SDLSystem::Init();
int ret = AppMain();
MiniEngine::SDLSystem::Quit();
return ret;
}

int GetArgc()
{
return _miniengine_argc;
}

char** GetArgv()
{
return _miniengine_argv;
}
15 changes: 0 additions & 15 deletions MiniEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <functional>
#include "SDLWrapper/IncludeAll.h"


namespace MiniEngine
{
class StringEngine
Expand All @@ -24,10 +23,6 @@ namespace MiniEngine
impl* pimpl;
};

int SetClipboardText(const std::string& str);
std::string GetClipboardText();
bool HasClipboardText();

/// Experimental - For Experts: Use SDL ScanCode
bool GetScanKeyState(SDL_Scancode);

Expand All @@ -39,13 +34,3 @@ bool canread(std::string Path);
bool canwrite(std::string Path);
bool isexist(std::string Path);
bool canexecute(std::string Path);

/// Your Program Should Start Here
int AppMain();

/// MiniEngine Provides main
int main(int argc,char* argv[]);

/// MiniEngine Provided API: Get Start Parameters
int GetArgc();
char** GetArgv();
114 changes: 62 additions & 52 deletions MiniEngine_Event.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "MiniEngine_Event.h"

namespace MiniEngine
{

int PollEvent(Event& refEvent)
{
return SDL_PollEvent(&refEvent);
Expand Down Expand Up @@ -64,22 +67,22 @@ Looper::Looper()
LooperID Looper::add(_SDLEventType_ event_type,const std::function<int(Looper&,Event&)>& event_callback)
{
_evmap[event_type].push_front(std::make_pair(_loop_cnt,event_callback));
return _getNextID(event_type);
return _getNextID(event_type);
}
LooperID Looper::add(_SDLEventType_ event_type,const std::function<int(Event&)>& event_callback)
{
_evmap[event_type].push_front(std::make_pair(_loop_cnt,[=](Looper& lp,Event& ev)->int{return event_callback(ev);}));
return _getNextID(event_type);
return _getNextID(event_type);
}
LooperID Looper::add(_SDLEventType_ event_type,const std::function<int(Looper&)>& event_callback)
{
_evmap[event_type].push_front(std::make_pair(_loop_cnt,[=](Looper& lp,Event& ev)->int{return event_callback(lp);}));
return _getNextID(event_type);
return _getNextID(event_type);
}
LooperID Looper::add(_SDLEventType_ event_type,const std::function<int()>& event_callback)
{
_evmap[event_type].push_front(std::make_pair(_loop_cnt,[=](Looper& lp,Event& ev)->int{return event_callback();}));
return _getNextID(event_type);
return _getNextID(event_type);
}

LooperID Looper::add(_SDLEventType_ event_type,const std::function<void(Looper&,Event&)>& event_callback)
Expand All @@ -96,7 +99,7 @@ LooperID Looper::add(_SDLEventType_ event_type,const std::function<void(Looper&)
}
LooperID Looper::add(_SDLEventType_ event_type,const std::function<void()>& event_callback)
{
return add(event_type,std::function<int(Looper&,Event&)>([=](Looper& lp,Event& ev)->int{event_callback();return 0;}));
return add(event_type,std::function<int(Looper&,Event&)>([=](Looper& lp,Event& ev)->int{event_callback(); return 0;}));
}

LooperID Looper::operator + (const std::pair<_SDLEventType_,std::function<int(Looper&,Event&)>>& event_callback)
Expand Down Expand Up @@ -137,10 +140,10 @@ LooperID Looper::operator + (const std::pair<_SDLEventType_,std::function<void()
bool Looper::remove(const LooperID& looperid)
{
for(auto beginIter=_evmap[looperid._type_id].begin(),
endIter=_evmap[looperid._type_id].end(),
iter=beginIter;
iter!=endIter;
++iter)
endIter=_evmap[looperid._type_id].end(),
iter=beginIter;
iter!=endIter;
++iter)
{
if(iter->first==looperid._looper_cnt)
{
Expand All @@ -166,17 +169,20 @@ void Looper::dispatch()
}
void Looper::run()
{
while(_running)
do
{
if(_update)
{
updater();
_update=false;
}

while(!_update&&WaitEvent(_e))
{
dispatch();
}

updater();

_update=false;
}
while(_running);
}
Event Looper::GetLastEvent()
{
Expand All @@ -186,14 +192,10 @@ void Looper::needupdate()
{
_update=true;
}
void Looper::needstop()
{
_running=false;
}
void Looper::stop()
{
needstop();
needupdate();
_running=false;
_update=true;
}
void Looper::reset()
{
Expand All @@ -206,76 +208,84 @@ void Looper::reset()

LooperID Looper::_getNextID(const _SDLEventType_& event_type)
{
LooperID id;
id._looper_cnt = _loop_cnt;
id._type_id = event_type;
LooperID id;
id._looper_cnt = _loop_cnt;
id._type_id = event_type;

++_loop_cnt;
return id;
++_loop_cnt;
return id;
}

Poller::Poller()
{
idler=[](){};
idler=[]() {};
}

void Poller::reset()
{
Looper::reset();
idler=[](){};
idler=[]() {};
}

void Poller::run()
{
int pollret=1;
while(_running)

do
{
if(_update)
{
updater();
_update=false;
}

while(!_update&&(pollret=PollEvent(_e)))
{
dispatch();
}

/// If pollret is not 0 (new event requests update), or pollret is 0 (No New Event) but Idle function requests update, then call updater.
if(!pollret) idler();
if(_update)
{
updater();
_update=false;
}

}
while(_running);
}

LooperWithTime::LooperWithTime(int Timeout_ms)
{
_timeout_ms = Timeout_ms;
_timeout_ms = Timeout_ms;
}

void LooperWithTime::setTimeout(int ms)
{
_timeout_ms = ms;
_timeout_ms = ms;
}

int LooperWithTime::getTimeout() const
{
return _timeout_ms;
return _timeout_ms;
}

void LooperWithTime::run()
{
int timeret = 1;
while (_running)
{
while (!_update&&(timeret=WaitEventTimeout(_e, _timeout_ms)))
{
dispatch();
}

/// If timeret is not 0 (new event request update), or timeret is 0 (Time out) but Idle function requests update, then call updater.
if (!timeret) idler();
if (_update)
{
updater();
_update = false;
}
}
int timeret = 1;
do
{
if (_update)
{
updater();
_update = false;
}

while (!_update&&(timeret=WaitEventTimeout(_e, _timeout_ms)))
{
dispatch();
}

/// If timeret is not 0 (new event request update), or timeret is 0 (Time out) but Idle function requests update, then call updater.
if (!timeret) idler();
}
while (_running);
}

}/// End of namespace MiniEngine
6 changes: 5 additions & 1 deletion MiniEngine_Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include <list>
#include <functional>

namespace MiniEngine
{

typedef SDL_Event Event;
typedef decltype(Event::type) _SDLEventType_;

Expand Down Expand Up @@ -63,7 +66,6 @@ class Looper
void run();
Event GetLastEvent();
void needupdate();
void needstop();
void stop();
void reset();

Expand Down Expand Up @@ -97,3 +99,5 @@ class LooperWithTime : public Poller
protected:
int _timeout_ms;
};

}/// End of namespace MiniEngine
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ C++编写的SDL2引擎.

### 编译说明

Windows: 请使用Codeblocks 16.01(推荐)载入所有.cpp文件.接下来Codeblocks会完成其余的工作.
Windows/Linux: 请使用Codeblocks 16.01(推荐)载入所有.cpp文件.接下来Codeblocks会完成其余的工作.
> 依赖库
> SDL2 (SDL2.lib, SDL2main.lib, SDL2test.lib)
> SDL2 Image (SDL2_image.lib)
> SDL2 Mixer (SDL2_mixer.lib)
> SDL2 TTF (SDL2_ttf.lib)
Linux Codeblocks PPA 参见: [Code::Blocks Release Builds](https://launchpad.net/~damien-moore/+archive/ubuntu/codeblocks-stable)

Windows-Visual Studio: 使用VS编译本项目可能会出现某些错误,目前还没有很好的解决办法.

C4droid: 长按编译键选择编译模式为Makefile. 选择编译目标为SDL2 Application. 修改程序名称为program_name(此处与makefile对应即可)
C4droid: 使用Makefile Generator生成makefile文件. 选择编译目标为SDL2 Application. 修改程序名称为program_name(与makefile对应)
> 依赖库
> C4droid本体
> GCC Plugin For C4droid
Expand Down
3 changes: 3 additions & 0 deletions SDLWrapper/Cursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "_SystemCursorType.h"
#include "Point.h"
#include "Surface.h"
#include "__Plugin.h"
#include "begin_code.h"
class Cursor
{
Expand All @@ -26,5 +27,7 @@ class Cursor
void _set_no_delete(SDL_Cursor*);
SDL_Cursor* _get();
void _clear();

friend class _internal::Plugin;
};
#include "end_code.h"
Loading

0 comments on commit edefaa6

Please sign in to comment.