onelonecoder / javidx9 Goto Github PK
View Code? Open in Web Editor NEWThe official distribution of Javidx9's YouTube videos and projects
Home Page: http://www.youtube.com/javidx9
License: Other
The official distribution of Javidx9's YouTube videos and projects
Home Page: http://www.youtube.com/javidx9
License: Other
MinGW 4.9.1 (rather old, but it's on the Qt-wiki) has the following error: (explanation?)
olcConsoleGameEngine.h:889:52: error: use of deleted function 'std::atomic<bool>::atomic(conststd::atomic<bool>&)'
atomic<bool> olcConsoleGameEngine::m_bAtomActive = false;
^
With the following fix at olcConsoleGameEngine.h#L889:
- atomic<bool> olcConsoleGameEngine::m_bAtomActive = false;
+ atomic<bool> olcConsoleGameEngine::m_bAtomActive(false);
PS: While at it I tested the newer mingw-64 5.0.3 in case it complained of the same thing. It complained of many things, so I deleted it. Happy ending.
I'm trying to use the ConsoleGameEngine with NetBeans (on Windows 10).
For those who wonder why:
First problem, as expected, was to set UNICODE (UTF-8), and I couldn't do it properly, although I tried a few solutions that I came across on the Web.
I guess that:
Here's the console error logs:
g++ -std=gnu++11 -c -g -MMD -MP -MF "build/Debug/Cygwin-Windows/ConsoleApplication1.o.d" -o build/Debug/Cygwin-Windows/ConsoleApplication1.o ConsoleApplication1.cpp
In file included from ConsoleApplication1.cpp:5:0:
olcConsoleGameEngine.h:127:2: error: #error Please enable UNICODE for your compiler! VS: Project Properties -> General -> Character Set -> Use Unicode. Thanks! - Javidx9
#error Please enable UNICODE for your compiler! VS: Project Properties -> General ->
^
In file included from ConsoleApplication1.cpp:5:0:
olcConsoleGameEngine.h: In member function 'bool olcSprite::Save(std::wstring)':
olcConsoleGameEngine.h:280:37: error: '_wfopen_s' was not declared in this scope
_wfopen_s(&f, sFile.c_str(), L"wb");
^
olcConsoleGameEngine.h: In member function 'bool olcSprite::Load(std::wstring)':
olcConsoleGameEngine.h:302:37: error: '_wfopen_s' was not declared in this scope
_wfopen_s(&f, sFile.c_str(), L"rb");
^
In file included from ConsoleApplication1.cpp:5:0:
olcConsoleGameEngine.h: At global scope:
olcConsoleGameEngine.h:1329:43: error: use of deleted function 'std::atomic::atomic(const std::atomic&)'
std::atomic m_bAudioThreadActive = false;
^
In file included from olcConsoleGameEngine.h:138:0,
from ConsoleApplication1.cpp:5:
/usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/atomic:66:5: note: declared here
atomic(const atomic&) = delete;
^
/usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/atomic:70:15: note: after user-defined conversion: constexpr std::atomic::atomic(bool)
constexpr atomic(bool __i) noexcept : _M_base(__i) { }
^
In file included from ConsoleApplication1.cpp:5:0:
olcConsoleGameEngine.h:1330:43: error: use of deleted function 'std::atomic::atomic(const std::atomic&)'
std::atomic m_nBlockFree = 0;
^
In file included from olcConsoleGameEngine.h:138:0,
from ConsoleApplication1.cpp:5:
/usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/atomic:631:7: note: declared here
atomic(const atomic&) = delete;
^
/usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/atomic:635:17: note: after user-defined conversion: constexpr std::atomic::atomic(std::atomic::__integral_type)
constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
^
In file included from ConsoleApplication1.cpp:5:0:
olcConsoleGameEngine.h:1333:37: error: use of deleted function 'std::atomic<_Tp>::atomic(const std::atomic<_Tp>&) [with _Tp = float]'
std::atomic m_fGlobalTime = 0.0f;
^
In file included from olcConsoleGameEngine.h:138:0,
from ConsoleApplication1.cpp:5:
/usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/atomic:187:7: note: declared here
atomic(const atomic&) = delete;
^
/usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/atomic:191:17: note: after user-defined conversion: constexpr std::atomic<_Tp>::atomic(_Tp) [with _Tp = float]
constexpr atomic(_Tp __i) noexcept : _M_i(__i) { }
^
In file included from ConsoleApplication1.cpp:5:0:
olcConsoleGameEngine.h: In member function 'int olcConsoleGameEngine::ConstructConsole(int, int, int, int)':
olcConsoleGameEngine.h:399:37: error: 'wcscpy_s' was not declared in this scope
wcscpy_s(cfi.FaceName, L"Consolas");
^
olcConsoleGameEngine.h:414:48: warning: narrowing conversion of '(((int)((short int)((olcConsoleGameEngine*)this)->olcConsoleGameEngine::m_nScreenWidth)) + -1)' from 'int' to 'SHORT {aka short int}' inside { } [-Wnarrowing]
m_rectWindow = { 0, 0, (short)m_nScreenWidth - 1, (short)m_nScreenHeight - 1 };
^
olcConsoleGameEngine.h:414:76: warning: narrowing conversion of '(((int)((short int)((olcConsoleGameEngine*)this)->olcConsoleGameEngine::m_nScreenHeight)) + -1)' from 'int' to 'SHORT {aka short int}' inside { } [-Wnarrowing]
m_rectWindow = { 0, 0, (short)m_nScreenWidth - 1, (short)m_nScreenHeight - 1 };
^
In file included from ConsoleApplication1.cpp:5:0:
olcConsoleGameEngine.h: In member function 'void olcConsoleGameEngine::DrawWireFrameModel(const std::vector<std::pair<float, float> >&, float, float, float, float, short int, short int)':
olcConsoleGameEngine.h:765:78: error: 'cosf' was not declared in this scope
vecTransformedCoordinates[i].first = vecModelCoordinates[i].first * cosf(r) - vecModelCoordinates[i].second * sinf(r);
^
olcConsoleGameEngine.h:765:120: error: 'sinf' was not declared in this scope
vecTransformedCoordinates[i].first = vecModelCoordinates[i].first * cosf(r) - vecModelCoordinates[i].second * sinf(r);
^
olcConsoleGameEngine.h: In member function 'void olcConsoleGameEngine::GameThread()':
olcConsoleGameEngine.h:954:124: error: 'swprintf_s' was not declared in this scope
swprintf_s(s, 256, L"OneLoneCoder.com - Console Game Engine - %s - FPS: %3.2f", m_sAppName.c_str(), 1.0f / fElapsedTime);
^
olcConsoleGameEngine.h:955:22: error: cannot convert 'wchar_t*' to 'LPCSTR {aka const char*}' for argument '1' to 'WINBOOL SetConsoleTitleA(LPCSTR)'
SetConsoleTitle(s);
^
olcConsoleGameEngine.h: In constructor 'olcConsoleGameEngine::olcAudioSample::olcAudioSample(std::wstring)':
olcConsoleGameEngine.h:1004:41: error: '_wfopen_s' was not declared in this scope
_wfopen_s(&f, sWavFile.c_str(), L"rb");
^
olcConsoleGameEngine.h: In static member function 'static void olcConsoleGameEngine::waveOutProcWrap(HWAVEOUT, UINT, DWORD, DWORD, DWORD)':
olcConsoleGameEngine.h:1196:27: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
((olcConsoleGameEngine*)dwInstance)->waveOutProc(hWaveOut, uMsg, dwParam1, dwParam2);
^
olcConsoleGameEngine.h: In member function 'void olcConsoleGameEngine::AudioThread()':
olcConsoleGameEngine.h:1209:59: error: 'pow' was not declared in this scope
short nMaxSample = (short)pow(2, (sizeof(short) * 8) - 1) - 1;
^
olcConsoleGameEngine.h: In lambda function:
olcConsoleGameEngine.h:1236:31: error: 'fmin' was not declared in this scope
return fmin(fSample, fMax);
^
olcConsoleGameEngine.h:1238:32: error: 'fmax' was not declared in this scope
return fmax(fSample, -fMax);
^
olcConsoleGameEngine.h: In member function 'void olcConsoleGameEngine::AudioThread()':
olcConsoleGameEngine.h:1246:84: error: invalid operands of types 'void' and 'float' to binary 'operator*'
nNewSample = (short)(clip(GetMixerOutput(c, m_fGlobalTime, fTimeStep), 1.0) * fMaxSample);
^
olcConsoleGameEngine.h: In member function 'int olcConsoleGameEngine::Error(const wchar_t*)':
olcConsoleGameEngine.h:1362:124: error: cannot convert 'wchar_t*' to 'LPSTR {aka char*}' for argument '5' to 'DWORD FormatMessageA(DWORD, LPCVOID, DWORD, DWORD, LPSTR, DWORD, char**)'
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, 256, NULL);
^
make[2]: *** [nbproject/Makefile-Debug.mk:68: build/Debug/Cygwin-Windows/ConsoleApplication1.o] Error 1
make[2]: Leaving directory '/cygdrive/c/Projects/ConsoleGameEngine'
make[1]: *** [nbproject/Makefile-Debug.mk:59: .build-conf] Error 2
make[1]: Leaving directory '/cygdrive/c/Projects/ConsoleGameEngine'
make: *** [nbproject/Makefile-impl.mk:40: .build-impl] Error 2
BUİLD FAILED (exit value 2, total time: 3s)
Tried using your library on my Linux machine and it fell flat because of the "windows.h" library. I do not own a Windows machine and don't intend to get one.
Exception thrown: write access violation.
this->m_bufScreen was 0x1110112. occurred
^^I assume something is wrong with the parameters of drawing the screen but I do not know. Any help is appreciated.
When I run the code, it returns the following error (I run my conde on Linux ubuntu 18 + vs code) on olcConsoleGameEngineSDL.h.
error: no matching function for call to ‘std::basic_ofstream::basic_ofstream(const wchar_t*, std::_Ios_Openmode)’
std::ofstream f(sFile.c_str(), std::ios::out | std::ios::binary);
Can you tell me what is going on?
olcConsoleGameEngine.h fails to create window, but olcConsoleGameEngineGL.h works. Using VS 2019 on Windows 10. When calling the create function it returns false and exits application.
I am having - ERROR: Screen Height / Font Height Too Big - when running my game ( which is based on olcRolePlayingGame )
Here is the code
`
int main()
{
Game game;
if (game.ConstructConsole(256, 240, 4, 4))
game.Start();
return 0;
}
`
here is the result in Microsoft Visual Studio Debug Console
`
ERROR: Screen Height / Font Height Too Big
The operation completed successfully.
C:\Dev\C++\Game\Debug\Game.exe (process 6392) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .
`
Hey David,
I'm having some issues when using the olcConsoleGameEngine.h with pixel size (font size) of 1. For some reason, when I do this:
test.ConstructConsole(240, 240, 1, 1)
The window created is distorted, not a square (something like 240x480 or something like that, much taller than wider). For other pixel sizes such as:
test.ConstructConsole(240, 240, 2, 2)
It works fine.
Any idea on what is causing this? Am I missing some command prompt configuration that is required for the console engine to work properly on a 1:1 pixel scale?
I'm running VS Community 2017 and Windows 10 1809.
Thanks!
when sampling the coordinate of the Noise Seed the code should change from
int nSampleX2 = (nSampleX1 + nPitch) % nWidth;
int nSampleY2 = (nSampleY1 + nPitch) % nWidth;
to
int nSampleX2 = (nSampleX1 + nPitch) % nWidth;
int nSampleY2 = (nSampleY1 + nPitch) % nHeight;
to avoid Noise Seed to go out of the boundary if nWidth >nHeight
.. with regards to...
Greetings.
When calculating the distance from the point to the plane, the variable n
below is never used, and instead the original point p
is used.
// Return signed shortest distance from point to plane, plane normal must be normalised
auto dist = [&](vec3d &p)
{
vec3d n = Vector_Normalise(p);
return (plane_n.x * p.x + plane_n.y * p.y + plane_n.z * p.z - Vector_DotProduct(plane_n, plane_p));
};
Should the fix be to use n
instead of p
,
// Return signed shortest distance from point to plane, plane normal must be normalised
auto dist = [&](vec3d &p)
{
vec3d n = Vector_Normalise(p);
return (plane_n.x * n.x + plane_n.y * n.y + plane_n.z * n.z - Vector_DotProduct(plane_n, plane_p));
};
or remove n
altogether?
// Return signed shortest distance from point to plane, plane normal must be normalised
auto dist = [&](vec3d &p)
{
return (plane_n.x * p.x + plane_n.y * p.y + plane_n.z * p.z - Vector_DotProduct(plane_n, plane_p));
};
Also - huge thanks for your videos! I found this series particularly interesting, i really enjoyed it :)
Update difficulty every 50 pieces - says the comment but actually in the code we update this value every one forcing down, not every locking. I think we should increment this value (nPieceCount) when we're taking a new piece.
I noticed a recent discussion about code used without crediting you. Following the story, I checked the source code and the license and noticed that it's either unknowingly or unintentionally sending conflicting messages.
For example in the file olcConsoleGameEngine.h
you mention:
Ultimately I don't care what you use this for. It's intended to be
educational, and perhaps to the oddly minded - a little bit of fun.
Please hack this, change it and use it in any way you see fit. You acknowledge
that I am not responsible for anything bad that happens as a result of
your actions. However this code is protected by GNU GPLv3, see the license in the
github repo. This means you must attribute me if you use it. You can view this
license here: https://github.com/OneLoneCoder/videos/blob/master/LICENSE
But GPLv3 and "do what ever you want as long as you credit me" just don't go together.
Anyone who uses GPLv3 code (e.g. any code from this repository) is required to publish their own code, that uses the GPLv3 licensed code, under GPLv3 as well.
But by telling people that you don't care (as long as they credit you), you're promising them a different license. Given that your English text is easier to understand than the pages long GPLv3 lawyer text, people will generally of course follow what you said and not what GPLv3 requires.
Like I said, I assume you probably didn't realize the full extend of GPLv3 either, as such, my suggestion would be to pick a license that actually represents what you're telling people.
Personally, I like to release my work into the public domain, but I understand that's not what everyone wants. Widely used license, but maybe a bit too open for your taste, are MIT or BSD 3. One that might fit your setup even better is the Apache 2.0 license, which requires people to also disclose changes.
Alternatively, if you know the implications of GPLv3, I think it's only fair to everyone, that you don't tell them, that they can do whatever, but instead tell them exactly what the license requires.
Just to be clear, I think everyone should be allowed to require being credited. I just find it unfair, to make videos, showing off code, telling people that it's educational and they can use it for whatever the want and then putting it under GPLv3, which has massive restrictions bound to it. 😉
to solve the sprite list store order causing the sprite render overlay issue just simply change the 1D depthBuffer to a 2D depth buffer(now the column depth buffer create in the raytracing of the wall should change to adjust to the buffer size change.
And also at the sprite object render section just change the depth buffer column check to pixel by pixel.that's it.
linux doesn't have the windows.h library.
I think the boundary test in the SetGlyph,SetColor,GetColor .... in the Sprite class should be change from x>nWidth || y>nHeight
to x>=nWidth || y>=nHeight
Howdy,
I've been following along first in your 04/03/17 youtube video and now in the revised version here and I found that line 193 as written causes my tetrominos to cease falling after the first jolt, and though the key inputs all still work, the pieces don't stick to the bottom. I made one change, to if (!bForceDown)
, as you have it in your video, and it worked fine.
Thank you very much for this tutorial. I learned quite a bit just following along and I appreciate that.
Following your video, I set up a C++ Console project in VS2017 version 15..9.5. I get this error when debugging:
Exception thrown at 0x770B0FAC (KernelBase.dll) in CommandPromptConsoleGameEngineIntro.exe: 0xC0000005: Access violation reading location 0x00000000.
In olcConsoleGameEngine.h
there are a few global/static variables
// Define our static variables
std::atomic<bool> olcConsoleGameEngine::m_bAtomActive(false);
std::condition_variable olcConsoleGameEngine::m_cvGameFinished;
std::mutex olcConsoleGameEngine::m_muxGame;
If you try and include olcConsoleGameEngine.h
in multiple translations units these will cause linker errors.
Apparently this means you should be using olcConsoleGameEngineOOP.h
but just by getting the linker error it is hard to realise that you should be using a different library instead and in the comment in olcConsoleGameEngine.h
there is no mention of olcConsoleGameEngineOOP.h
This should be documented in the source code since it's easy for beginners to not understand what is going on with those linker errors.
When running your exact code using Console App interface on Vs 2019 Community (checked on VS 2017 C too, same) the window shrinks and shows nothing, I resized it and it showed "Press any key to close this window . . . ". After I used the slide too (there should be no slide?) It says:
"ERROR: Screen Height / Font Height Too Big
The operation completed successfully."
I also tried to resize the pixels sizes within the ConstructConsole, nothing's changed.
It seems that the window isn't even constructed because non of the title nor the frames show as in the video, the title on my window is: "Mircosoft Visual Studio Debug Console" and not the title I typed/want.
Any help?
Basically what you need to do is, lessen the the size of the window or the pixels to numbers that works for you.
E.g:
{
olcEngine3D demo;
if (demo.ConstructConsole(117, 117, 5, 5)) //Those are the exact numbers that works on my screen
demo.Start();
}
This should be for (int ny = 0; ny < nMapHeight; ny++)
instead.
Big Fan! But...
In ConcstructConsole(...) you jump through a lot of unnecessary hoops (as per your 2017 update notes).
It is much easier to:
Bingo!
No worrying about the order of things and shrinking to zero size etc.
Could you create Mac os X version because <windows.h> not available on mac os.
Thanks.
Thanks a lot for your videos.
I'm using them to experiment with some things in 3D.
One question I have is whether the axis.obj is the correct orientation?
It appears to me like the X bar and X symbol are on the negative X axis rather than the positive X axis.
Is this correct? If so, why was it done this way?
I would think that each axis bar and symbol should be on the positive axis for that direction.
If not, what am I missing?
If so, could it be re-drawn/modeled with the X axis on the positive X axis?
The main reason I mention it is because it caused me a lot of confusion when I was trying to debug my 3D routines, the numbers kept coming out opposite or negative to what I thought they should, until I realized that the model was drawn that way.
I don't know any way to fix it other than to re-do the model.
Maybe I'll try importing it into Blender and re-working it.
Thanks!
When calling Construct with vsync=true, it does nothing.
It can be corrected by calling wglSwapInterval(1) if bEnableVSYNC is true.
Everytime i compile i get 12 errors:
Severity Code Description Project File Line Suppression State Error LNK2001 unresolved external symbol "public: __thiscall olc::Pixel::Pixel(unsigned char,unsigned char,unsigned char,unsigned char)" (??0Pixel@olc@@QAE@EEEE@Z) ConFPS C:\Users\Jonathon\source\repos\ConFPS\ConFPS\Source.obj 1 Error LNK2001 unresolved external symbol "public: __thiscall olc::Pixel::Pixel(unsigned int)" (??0Pixel@olc@@QAE@I@Z) ConFPS C:\Users\Jonathon\source\repos\ConFPS\ConFPS\Source.obj 1 Error LNK2001 unresolved external symbol "public: virtual bool __thiscall olc::PixelGameEngine::Draw(int,int,struct olc::Pixel)" (?Draw@PixelGameEngine@olc@@UAE_NHHUPixel@2@@Z) ConFPS C:\Users\Jonathon\source\repos\ConFPS\ConFPS\Source.obj 1 Error LNK2001 unresolved external symbol "public: int __thiscall olc::PixelGameEngine::ScreenHeight(void)const " (?ScreenHeight@PixelGameEngine@olc@@QBEHXZ) ConFPS C:\Users\Jonathon\source\repos\ConFPS\ConFPS\Source.obj 1 Error LNK2001 unresolved external symbol "public: int __thiscall olc::PixelGameEngine::ScreenWidth(void)const " (?ScreenWidth@PixelGameEngine@olc@@QBEHXZ) ConFPS C:\Users\Jonathon\source\repos\ConFPS\ConFPS\Source.obj 1 Error LNK2001 unresolved external symbol "public: struct olc::HWButton __thiscall olc::PixelGameEngine::GetKey(enum olc::Key)const " (?GetKey@PixelGameEngine@olc@@QBE?AUHWButton@2@W4Key@2@@Z) ConFPS C:\Users\Jonathon\source\repos\ConFPS\ConFPS\Source.obj 1 Error LNK2001 unresolved external symbol "public: virtual bool __thiscall olc::PixelGameEngine::OnUserDestroy(void)" (?OnUserDestroy@PixelGameEngine@olc@@UAE_NXZ) ConFPS C:\Users\Jonathon\source\repos\ConFPS\ConFPS\Source.obj 1 Error LNK2001 unresolved external symbol "public: enum olc::rcode __thiscall olc::PixelGameEngine::Start(void)" (?Start@PixelGameEngine@olc@@QAE?AW4rcode@2@XZ) ConFPS C:\Users\Jonathon\source\repos\ConFPS\ConFPS\Source.obj 1 Error LNK2001 unresolved external symbol "public: enum olc::rcode __thiscall olc::PixelGameEngine::Construct(int,int,int,int,bool,bool,bool)" (?Construct@PixelGameEngine@olc@@QAE?AW4rcode@2@HHHH_N00@Z) ConFPS C:\Users\Jonathon\source\repos\ConFPS\ConFPS\Source.obj 1 Error LNK2001 unresolved external symbol "public: virtual __thiscall olc::PixelGameEngine::~PixelGameEngine(void)" (??1PixelGameEngine@olc@@UAE@XZ) ConFPS C:\Users\Jonathon\source\repos\ConFPS\ConFPS\Source.obj 1 Error LNK2001 unresolved external symbol "public: __thiscall olc::PixelGameEngine::PixelGameEngine(void)" (??0PixelGameEngine@olc@@QAE@XZ) ConFPS C:\Users\Jonathon\source\repos\ConFPS\ConFPS\Source.obj 1 Error LNK1120 11 unresolved externals ConFPS C:\Users\Jonathon\source\repos\ConFPS\Release\ConFPS.exe 1
And here is my Code:
`#include
#include
#include
using namespace std;
#include "olcPixelGameEngine.h"
class GameWindow : public olc::PixelGameEngine
{
public:
GameWindow()
{
sAppName = "Game 3D";
}
virtual bool OnUserCreate()
{
map += L"################";
map += L"#..............#";
map += L"#....###.......#";
map += L"#..............#";
map += L"#..............#";
map += L"#..............#";
map += L"#..............#";
map += L"#..............#";
map += L"#..............#";
map += L"#..............#";
map += L"#..............#";
map += L"#..............#";
map += L"#.......########";
map += L"#..............#";
map += L"#..............#";
map += L"################";
return true;
}
virtual bool OnUserUpdate(float fElapsedTime)
{
// Controls
// Handle CCW rotation
if (GetKey(olc::Key::A).bHeld)
fPlayerA -= (0.8) * fElapsedTime;
if (GetKey(olc::Key::D).bHeld)
fPlayerA += (0.8) * fElapsedTime;
if (GetKey(olc::Key::W).bHeld)
{
fPlayerX += sinf(fPlayerA) * 5.0f * fElapsedTime;
fPlayerY += cosf(fPlayerA) * 5.0f * fElapsedTime;
if (map[(int)fPlayerY * nMapWidth + (int)fPlayerX] == '#')
{
fPlayerX -= sinf(fPlayerA) * 5.0f * fElapsedTime;
fPlayerY -= cosf(fPlayerA) * 5.0f * fElapsedTime;
}
}
if (GetKey(olc::Key::S).bHeld)
{
fPlayerX -= sinf(fPlayerA) * 5.0f * fElapsedTime;
fPlayerY -= cosf(fPlayerA) * 5.0f * fElapsedTime;
if (map[(int)fPlayerY * nMapWidth + (int)fPlayerX] == '#')
{
fPlayerX += sinf(fPlayerA) * 5.0f * fElapsedTime;
fPlayerY += cosf(fPlayerA) * 5.0f * fElapsedTime;
}
}
for (int x = 0; x < ScreenWidth(); x++)
{
// For each column, calculate the projected ray angle into world space
float fRayAngle = (fPlayerA - fFOV / 2.0f) + ((float)x / (float)ScreenWidth()) * fFOV;
float fDistanceToWall = 0;
bool bHitWall = false;
bool bBoundary = false;
float fEyeX = sinf(fRayAngle);
float fEyeY = cosf(fRayAngle);
while (!bHitWall && fDistanceToWall < fDepth)
{
fDistanceToWall += 0.1f;
int nTestX = (int)(fPlayerX + fEyeX * fDistanceToWall);
int nTestY = (int)(fPlayerY + fEyeY * fDistanceToWall);
// Test if ray is out of bounds
if (nTestX < 0 || nTestX >= nMapWidth || nTestY < 0 || nTestY >= nMapHeight)
{
bHitWall = true; // Just set distance to maximum depth
fDistanceToWall = fDepth;
}
else
{
if (map[nTestY * nMapWidth + nTestX] == '#')
{
bHitWall = true;
vector<pair<float, float>> p; // distance, dot
for (int tx = 0; tx < 2; tx++)
for (int ty = 0; ty < 2; ty++)
{
float vy = (float)nTestY + ty - fPlayerY;
float vx = (float)nTestX + tx - fPlayerX;
float d = sqrt(vx * vx + vy * vy);
float dot = (fEyeX * vx / d) + (fEyeY * vy / d);
p.push_back(make_pair(d, dot));
}
// Sort pairs from closest to farthest
sort(p.begin(), p.end(), [](const pair<float, float>& left, const pair<float, float>& right) {return left.first < right.first; });
float fBound = 0.01;
if (acos(p.at(0).second) < fBound) bBoundary = true;
if (acos(p.at(1).second) < fBound) bBoundary = true;
if (acos(p.at(2).second) < fBound) bBoundary = true;
}
}
}
// Calculate distance to ceiling and floor
int nCeiling = (float)(ScreenHeight() / 2.0) - ScreenHeight() / ((float)fDistanceToWall);
int nFloor = ScreenHeight() - nCeiling;
// Shader walls based on distance
short nShade = ' ';
if (fDistanceToWall <= fDepth / 4.0f) nShade = 0x2588; // Very close
else if (fDistanceToWall < fDepth / 3.0f) nShade = 0x2593;
else if (fDistanceToWall < fDepth / 2.0f) nShade = 0x2592;
else if (fDistanceToWall < fDepth) nShade = 0x2591;
else nShade = ' ';
if (bBoundary) nShade = ' '; //Black it out
for (int i = 0; i < ScreenHeight(); i++)
{
if (i <= nCeiling)
Draw(x, i, L' ');
else if (i > nCeiling&& i <= nFloor)
Draw(x, i, nShade);
else
{
// Shade floor based on distance
float b = 1.0f - (((float)i - ScreenHeight() / 2.0f) / ((float)ScreenHeight() / 2.0f));
if (b < 0.25) nShade = '#';
else if (b < 0.5) nShade = 'x';
else if (b < 0.75) nShade = '.';
else if (b < 0.9) nShade = '-';
else nShade = ' ';
Draw(x, i, nShade);
}
}
}
// Display Map
for (int nx = 0; nx < nMapWidth; nx++)
for (int ny = 0; ny < nMapWidth; ny++)
Draw(nx + 1, ny + 1, map[ny * nMapWidth + nx]);
Draw(1 + (int)fPlayerY, 1 + (int)fPlayerX, L'P');
return true;
}
private:
int nMapHeight = 16;
int nMapWidth = 16;
wstring map;
float fPlayerX = 8.0f;
float fPlayerY = 8.0f;
float fPlayerA = 0.0f;
float fFOV = 3.14159 / 4.0f;
float fDepth = 16.0f;
};
int main()
{
GameWindow game;
game.Construct(120, 80, 8, 8);
game.Start();
return 0;
}`
i have this problem while running the perlin noise but the problem generates from the olcconsolegameengin header file
Sorry for abusing this, but I tried to find a way to contact you to no avail besides this.
YouTube won't let me use the account, I created years ago and new accounts can't be created atm. either.
So, I would like to take part in the game jam.
Is there a way for me to join without a social network account?
https://harald.ist.org/about/contact.html
Btw, contact.html on your web site throws a 404.
Greetings,
H.
Nothing to do with the pixel engine, this is for running the olcConsoleEngine code for the video section.
When trying to run any of the cpp source files that contain a #include "escapi.h".
Where is this file?
https://github.com/OneLoneCoder/videos/blob/537664947db31529d2d2236deda9105ca19c041c/OneLoneCoder_Splines1.cpp#L72
Looks like this would give me the point at index 1 when I ask for index 0 and
https://github.com/OneLoneCoder/videos/blob/537664947db31529d2d2236deda9105ca19c041c/OneLoneCoder_Splines1.cpp#L106
looks like it gives me the gradient at index 1 instead of index 0.
Some thoughts:
in GetSplinePoint one could return the first control point if t==0 but I guess there simply is no gradient at the start of the spline?!
on line 330: vec3d n = Vector_Normalise(p);
I believe can be deleted. Great video, I learned alot.
in the code
// Do 10 physics iterations per frame - this allows smaller physics steps
// giving rise to more accurate and controllable calculations
for (int z = 0; z < 10; z++)
{
...some code using fElapsedTime
}
I think the fElapsedTime should change according to the iteration step
int nPhysicsStep=10;
float newStepTime=fElapsedTime/(float)nPhysicsStep;
for(int z=0;z<nPhysicsStep;z++)
{
...code here now using newStepTime
}
so change the time will not affect the speed of the object and will remain constant and the calculation will be more accurate for smaller deltaTime
in the original code the only way to return to AI_ASSESS_ENVIRONMENT is in the fire mode and have to meet fireEnergy >requireEnergy condition so if something bad happen(like the AI cant turn the aim in time for animation purpose) then the next cycle AI will not correctly do as the AI logic intended.To assure the behave correct I think could change the code in GS_CAMERA_MODE
// Lock controls if AI team is currently playing
if (nCurrentTeam == 0) // Player Team
{
bEnablePlayerControl = true; // Swap these around for complete AI battle
bEnableComputerControl = false;
}
else // AI Team
{
bEnablePlayerControl = false;
bEnableComputerControl = true;
nAIState = AI_ASSESS_ENVIRONMENT;//《《---add this line because the AI logic is written after game state logic
nAINextState = AI_ASSESS_ENVIRONMENT;//《《---add this line
}
but m_hOriginalConsole is used multiple times like this:
SetConsoleActiveScreenBuffer(m_hOriginalConsole);
Could someone please explain this?
The Console Game Engine is great for quick prototyping, however, I noticed that in visual studio 2017, when I create a console whose title does not show the FPS counter, any operation to the console itself is sluggish and creates a ghost of a cursor until the operation is completed. This was reproduces many times with a console of size 50,50 and font 10,10. The solution I encountered was to increase the width of the console itself which alleviates the problem immediately.
As we know, there is no windows.h library in linux. So is there a port of olcConsoleGameEngine.h for linux?
Hi,
great job with the examples. I will definitely suggest your videos to my students.
In order to make the OneLoneCoder_PathFinding_AStar.cpp compile on linux, besides changing the include directive to include olcConsoleGameEngineSDL.h instead of olcConsoleGameEngine.h, I also had to change VK_SHIFT and VK_CONTROL to VK_LSHIFT and VK_LCONTROL. This because the first two are not defined in olcConsoleGameEngineSDL.h, and there does not seem to exist scancodes in SDL that can be mapped directly to them.
I know this is restrictive because the user can only press the left keys, but would you consider the change to make the code more portable?
Thank you
I have been following the 3D Graphics Engine tutorials which use olcConsoleGameEngine.h. However, when I run the code, the console window appears shrunk and is no longer running. The other engines seem to run fine, so the issue isn't on Visual Studio's end. Has anyone else encountered the same issue?
I'm going through the 3D Graphics Engine tutorial. In part 3 you mention clipping against the view frustum. Can you provide an example of that? Thank you.
This file is looking for Jario.spr but it is missing. The video shows a sprite that doesn't match anything found in JarioSprites directory. That is, a Jario with a "J" on his chest.
The top of the file does not provide help. The note seems incomplete.
// PLEASE NOTE! The video shows the Spyro The Dragon Level - I can't redistribute that
// so this file is configured to show the textured Jario cube. Please ensure you have
// downloaded the "Jario.spr" file from
Hi there,
I'm trying to convert the platform tile of jario from the consoleGameEngine to the pixelGameEngine.
And as I learned today through the SHMUP video the DrawSprite function of the pixelGameEngine can only handle png and not spr files.
Question: is there a way to convert the jario sprites into png files?
Cheers
Sascha
On Windows 10 x64, I've been getting a bug where the frequency passed from onUserSoundSample
is a lower frequency I expect.
In order to reproduce this, the following should create a constant, 440hz sine wave for the first 127 seconds from the start. Afterwards, the pitch should lower:
virtual float onUserSoundSample(int nChannel, float fGlobalTime, float fTimeStep) {
return sinf(440.0f * 2.0f * 3.14159f * fGlobalTime);
}
Hi!
I'm just starting through your YouTube videos and I'm running into the following error when trying to follow "Absolute Beginners Guide to olcConsoleGameEngine.h"
I'm using VS2019 and just added olcConsoleGameEngine.h and FlappyBird into a new solution, tried, to run it, and I hit that. I also hit that whenever I'm trying to add my own code or if I jump down to VS2015.
Any help would be appreciated!
Using the latest version of the Header file,
I've tried the code given in the video : (Absolute Beginners Guide To "olcConsoleGameEngine.h")
Here's the error message I get at runtime:
Exception thrown: write access violation. this->m_bufScreen was 0x1110112.
The line that gives the error is the last one here:
virtual void Draw(int x, int y, short c = 0x2588, short col = `0x000F)
{
if (x >= 0 && x < m_nScreenWidth && y >= 0 && y < m_nScreenHeight)
{
m_bufScreen[y * m_nScreenWidth + x].Char.UnicodeChar = c;
Note: I have already changed the Project settings to UNICODE.
UPDATED: increase performance for searching color.
That lodepng.h is for loading png file for testing ,I'm suck at those stuff..
because my computer don't work well with the console game engine (10fps,wrong font size and so on..)
so I don't know whether it's good or not.
my test result https://imgur.com/jZFTqVf https://imgur.com/sWq5fr2 https://imgur.com/vfjfyP6
here's some explaination https://imgur.com/oSI9Qbe
#include<stdio.h>
#include"olcConsoleGameEngine.h"
#include<algorithm>
#include<string>
#include"lodepng.h"
std::vector<unsigned char> vecPng;
unsigned imageWidth, imageHeight;
class testConsole :public olcConsoleGameEngine
{
virtual bool OnUserCreate()
{
pngWidth = imageWidth;
pngHeight = imageHeight;
dither = new RGB[sizeof(RGB)*pngWidth*pngHeight * 3];
memset(dither, 0, sizeof(RGB)*pngWidth*pngHeight * 3);
ccbToRGB.clear();
for (int f = 0; f < 16; ++f)
for (int b = 0; b < 16; ++b)
for (int p = 0; p < 4; ++p)
{
ccbToRGB.push_back({ {f,b,p} ,ColorTable[f] * percent[p] + ColorTable[b] * (1 - percent[p]) });
}
//delete duplicate color
for (auto i = ccbToRGB.begin(); i != ccbToRGB.end();)
{
CTR::iterator next = i + 1;
while (next != ccbToRGB.end())
{
if (i->second == next->second)
next = ccbToRGB.erase(next);
else
++next;
}
if (i != ccbToRGB.end())++i;
}
int n = 0;
for (auto a : ccbToRGB)
{
int r = a.second.r, b = a.second.b, g = a.second.g;
_3DTABLE[r / 32][g / 32][b / 32].push_back(a);
++n;
}
//
for (int _x = 0; _x < pngWidth; ++_x)
for (int _y = 0; _y < pngHeight; ++_y)
{
int pngIndex = (_y*pngWidth + _x);
//how to find a color
RGB color = { vecPng[pngIndex * 4 + 0],vecPng[pngIndex * 4 + 1],vecPng[pngIndex * 4 + 2] };
color = color + dither[pngIndex];
color.clip();
int foundr, foundg, foundb;
// first find the cube surround it
int l = 8192;
size_t index = 0;
for (int x = -1; x <= 1; ++x)
for (int y = -1; y <= 1; ++y)
for (int z = -1; z <= 1; ++z)
{
int xr = color.r / 32 + x, yg = y + color.g / 32, zb = z + color.b / 32;
if (xr >= 0 && xr <= 8 && yg >= 0 && yg <= 8 && zb >= 0 && zb <= 8)
{
int the_index = 0;
for (auto i : _3DTABLE[xr][yg][zb])
{
int newl = (i.second - color).sqr();
if (newl < l)
{
l = newl;
index = the_index;
foundr = xr;
foundg = yg;
foundb = zb;
}
++the_index;
}
}
}
//maximum distance will not bigger than the cubic diagonal
CCB ccb = _3DTABLE[foundr][foundg][foundb][index].first;
RGB error = color -_3DTABLE[foundr][foundg][foundb][index].second;// use for error diffusion, totally up to you
if (_x + 1 < pngWidth)
dither[_y*pngWidth + _x + 1] = error * (7.0f / 16.0f);
if (_y + 1 < pngHeight)
{
if (_x - 1 >= 0)
dither[(_y + 1)*pngWidth + _x - 1] = error * (3.0f / 16.0f);
dither[(_y + 1)*pngWidth + _x] = error * (5.0f / 16.0f);
if (_x + 1 < pngWidth)
dither[(_y + 1)*pngWidth + _x + 1] = error * (1.0f / 16.0f);
}
Draw(_x, _y, pixelP[ccb.p], ccb.f | (ccb.b << 4));
}
return true;
}
virtual bool OnUserUpdate(float _fDeltaTime)
{
return true;
}
struct RGB
{
int r;
int g;
int b;
RGB operator+(RGB _t)
{
return { r + _t.r,g + _t.g,b + _t.b };
}
RGB operator-(RGB _t)
{
return { r - _t.r,g - _t.g,b - _t.b };
}
RGB operator*(float _f)
{
return { (int)((float)r*_f),(int)((float)g*_f),(int)((float)b*_f) };
}
bool operator==(RGB _t)
{
return r == _t.r&&g == _t.g&&b == _t.b;
}
int sqr()
{
return r * r + g * g + b * b;
}
void clip()
{
if (r < 0) r = 0;
if (r > 256) r = 256;
if (g < 0) g = 0;
if (g > 256) g = 256;
if (b < 0) b = 0;
if (b > 256) b = 256;
}
};
//console color block
struct CCB
{
//foreground color
int f;
//background color
int b;
//block type
int p;
};
RGB ColorTable[16] =
{
{0,0,0},
{0,0,128},
{0,128,0},
{0,128,128},
{128,0,0},
{128,0,128},
{128,128,0},
{192,192,192},
{128,128,128},
{0,0,256},
{0,256,0},
{0,256,256},
{256,0,0},
{256,0,256},
{256,256,0},
{256,256,256},
};
typedef std::vector<std::pair<CCB, RGB>> CTR;
std::vector<std::pair<CCB, RGB>> ccbToRGB;
CTR _3DTABLE[9][9][9];
//ForeGroundBlockPercent
float percent[4] = { 1,0.75,0.5,0.25 };
short pixelP[4] = { PIXEL_SOLID,PIXEL_THREEQUARTERS,PIXEL_HALF,PIXEL_QUARTER };
RGB *dither;
unsigned pngWidth, pngHeight;
};
int main()
{
const char* filename = "C:/test_PNG/van_gogh.png";
//const char* filename = "C:/test_PNG/mario2.png";
//const char* filename = "C:/test_PNG/olc.png";
unsigned error = lodepng::decode(vecPng, imageWidth, imageHeight, filename);
if (error) {
std::cout << "decoder error " << error << ": " << lodepng_error_text(error) << std::endl;
return false;
}
testConsole test;
test.ConstructConsole(imageWidth, imageHeight, 4, 4);
// test.ConstructConsole(100, 100, 8, 8);
test.Start();
return 0;
}
Following the first video in the 3D Graphics series (https://www.youtube.com/watch?v=ih20l3pJoeU) and being on Mac I'm using olcConsoleGameEngineSDL.h
rather than olcConsoleGameEngine.h
. The minimal code for the instantiation of the game engine
int main() {
olcEngine3D demo;
if(demo.ConstructConsole(256, 240, 4, 4))
demo.Start();
return 0;
}
leads to the following crash:
$ ./olcEngine3D
2019-09-07 23:07:38.647 olcEngine3D[36851:411276] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'nextEventMatchingMask should only be called from the Main Thread!'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff4e8d72fd __exceptionPreprocess + 256
1 libobjc.A.dylib 0x00007fff78fa7a17 objc_exception_throw + 48
2 AppKit 0x00007fff4be16f8e -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 4180
3 libSDL2-2.0.0.dylib 0x000000010a4b8074 Cocoa_PumpEvents + 126
4 libSDL2-2.0.0.dylib 0x000000010a432e56 SDL_PumpEvents_REAL + 23
5 libSDL2-2.0.0.dylib 0x000000010a432edf SDL_WaitEventTimeout_REAL + 75
6 olcEngine3D 0x000000010a3efb55 _ZN20olcConsoleGameEngine10GameThreadEv + 709
7 olcEngine3D 0x000000010a3f25f1 _ZNSt3__1L8__invokeIM20olcConsoleGameEngineFvvEPS1_JEvEEDTcldsdeclsr3std3__1E7forwardIT0_Efp0_Efp_spclsr3std3__1E7forwardIT1_Efp1_EEEOT_OS5_DpOS6_ + 113
8 olcEngine3D 0x000000010a3f24fe _ZNSt3__1L16__thread_executeINS_10unique_ptrINS_15__thread_structENS_14default_deleteIS2_EEEEM20olcConsoleGameEngineFvvEJPS6_EJLm2EEEEvRNS_5tupleIJT_T0_DpT1_EEENS_15__tuple_indicesIJXspT2_EEEE + 62
9 olcEngine3D 0x000000010a3f1cf6 _ZNSt3__114__thread_proxyINS_5tupleIJNS_10unique_ptrINS_15__thread_structENS_14default_deleteIS3_EEEEM20olcConsoleGameEngineFvvEPS7_EEEEEPvSC_ + 118
10 libsystem_pthread.dylib 0x00007fff7a9692eb _pthread_body + 126
11 libsystem_pthread.dylib 0x00007fff7a96c249 _pthread_start + 66
12 libsystem_pthread.dylib 0x00007fff7a96840d thread_start + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Debugging shows that an exception is raised in olcConsoleGameEngineSDL.h
in the line containing while (SDL_PollEvent(&e))
. Similar issues elsewhere (lvgl/lv_port_pc_eclipse#12) suggest that SDL might need special treatment under MacOS.
I've noticed that the CPU gets quite hot while running the ConsoleEngine, even when nothing is drawn/updated on the screen (and the update rate is 700 FPS).
Wouldn't it be cool to let the user define a FPS, and cool down the CPU?
Is it up to the user to try to do it in the Application level, or can the Engine handle it itself?
Thanks in advance, I'm not experienced in thread programming.
You returned without closing the file stream.
bool Save(std::wstring sFile)
{
FILE *f = nullptr;
_wfopen_s(&f, sFile.c_str(), L"wb");
//if (f == nullptr)
// return false;
if(!f)
{
fclose(f);
return false;
}
fwrite(&nWidth, sizeof(int), 1, f);
fwrite(&nHeight, sizeof(int), 1, f);
fwrite(m_Colours, sizeof(short), nWidth * nHeight, f);
fwrite(m_Glyphs, sizeof(short), nWidth * nHeight, f);
fclose(f);
return true;
}
bool Load(std::wstring sFile)
{
delete[] m_Glyphs;
delete[] m_Colours;
nWidth = 0;
nHeight = 0;
FILE *f = nullptr;
_wfopen_s(&f, sFile.c_str(), L"rb");
//if (f == nullptr)
// return false;
if(!f)
{
fclose(f);
return false;
}
std::fread(&nWidth, sizeof(int), 1, f);
std::fread(&nHeight, sizeof(int), 1, f);
Create(nWidth, nHeight);
std::fread(m_Colours, sizeof(short), nWidth * nHeight, f);
std::fread(m_Glyphs, sizeof(short), nWidth * nHeight, f);
std::fclose(f);
return true;
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.