Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

converted the "game engine" to SDL2 #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Katana-Steel
Copy link

No need to merge it, just would like to hear your thoughts on this.

@OneLoneCoder
Copy link
Owner

Hey cool!

@OneLoneCoder
Copy link
Owner

Hey, After getting lots of requests for linux implementations, is it OK if I point them at your code?

@jasonstone20
Copy link

Sure! My code doesn't have a few things that yours does( like making graphics out of adjusting the font size the ASCII characters, UNIX Terminal works a little different and the DOS command line) and I haven't really used it to develop any games yet.

@Katana-Steel
Copy link
Author

that's fine... I would love to see an ncurses implementation as well.

my current implementation has a horrid performance...
but it could possibly be educational, if for no other reason.

OneLoneCoder added a commit that referenced this pull request Jan 21, 2018
OneLoneCoder added a commit that referenced this pull request Mar 24, 2019
@w-A-L-L-e
Copy link

On MacOS mojave and High Sierra the SDL code was throwing this error:

2019-07-08 23:43:33.617 pathfinder_AStar[41719:2590436] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'nextEventMatchingMask should only be called from the Main Thread!'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007fff3bed765b __exceptionPreprocess + 171
	1   libobjc.A.dylib                     0x00007fff6315fc76 objc_exception_throw + 48
	2   AppKit                              0x00007fff39b81297 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 4167
	3   SDL2                                0x000000010922c787 SDL2 + 145287
	4   SDL2                                0x00000001092162ab SDL2 + 53931
	5   pathfinder_AStar                    0x00000001091fcb0f _ZN20olcConsoleGameEngine10GameThreadEv + 2479
	6   pathfinder_AStar                    0x00000001091ffe4b _ZNSt3__114__thread_proxyINS_5tupleIJNS_10unique_ptrINS_15__thread_structENS_14default_deleteIS3_EEEEM20olcConsoleGameEngineFvvEPS7_EEEEEPvSC_ + 667
	7   libsystem_pthread.dylib             0x00007fff64091661 _pthread_body + 340
	8   libsystem_pthread.dylib             0x00007fff6409150d _pthread_body + 0
	9   libsystem_pthread.dylib             0x00007fff64090bf9 thread_start + 13

Googled around and it turns out the SDL_Event stuff needs to be in the main running thread.
I applied this patch and compiled the AStar example with it and now it runs fine on Mac OS too:

727 public:
 728   void Start()
 729   {
 730     m_bAtomActive = true;
 731 
 732 #ifndef __APPLE__
 733     // Start the thread
 734     std::thread t = std::thread(&olcConsoleGameEngine::GameThread, this);
 735 
 736     // Wait for thread to be exited
 737     t.join();
 738 #else
 739     //for apple just run our gamethread as main program!
 740     GameThread();
 741 #endif
 742 
 743   }

So now later on this part doesn't crash anymore:

 SDL_Event e;
 821         while (SDL_PollEvent(&e))

Also I downloaded the SDL2 from official website and put it in /Library/Framework
Then compiling like so

g++ OneLoneCoder_PathFinding_AStar.cpp -DUNICODE -framework SDL2  -lpthread -std=c++11 -o pathfinder_astar

Hope it helps other macbook owners ;). And keep up the great videos!
Screen Shot 2019-07-09 at 00 36 39
Now it ran perfectly. Also tried the asteroids game to see refresh rate. And it seems to work fine on the other examples too. So not sure why the extra Game thread was necessary at all...

Screen Shot 2019-07-09 at 00 43 00

Above we do see an issue with DrawText being a bit small (but I think its the SDL2 port vs regular console engine).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants