You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@netbeans.apache.org by Gürkan Çetin <gu...@gmail.com> on 2018/07/22 13:17:16 UTC

(C++) Unicode and several errors, trying to use the Console Game Engine

Hello,

Product Version: NetBeans IDE 8.2 (Build 201609300101) 
Updates: NetBeans IDE is updated to version NetBeans 8.2 Patch 2 

I’m trying to use the Console Game Engine (author: @javidx9) with Netbeans, and I’ve received several errors, and I couldn’t get satisfactory results from Google, and Stack Overflow.

I’ve been redirected to ask here by Geertjan Wielenga.

Here’s my case:
1) There’s an application file and there’s the Header file.
2) The header file is the “olcConsoleGameEngine.h”. Here’s the Github Link to the repository: videos.
3) My application is a simple one, actually it’s from the tutorial:

Example Application:
#include <iostream>
#include <cstdio>       //added 22.7.2018, gç.
#include <cstring>      //added 22.7.2018, gç.
using namespace std;
#include "olcConsoleGameEngine.h"

class Example : public olcConsoleGameEngine
{
public:
	Example()
	{}
	virtual bool OnUserCreate()
	{
		return true;
	}

	virtual bool OnUserUpdate(float fElapsedTime)
	{
		Fill(0, 0, ScreenWidth(), ScreenHeight(), PIXEL_SOLID, FG_BLACK);

		for (int c = 1; c < 16; c++)
		{
			Fill(0, c * 6, 5, c * 6 + 5, PIXEL_QUARTER, c);
			Fill(6, c * 6, 11, c * 6 + 5, PIXEL_HALF, c);
			Fill(12, c * 6, 17, c * 6 + 5, PIXEL_THREEQUARTERS, c);
			Fill(18, c * 6, 23, c * 6 + 5, PIXEL_SOLID, c);

			Fill(24, c * 6, 29, c * 6 + 5, PIXEL_THREEQUARTERS, c | BG_WHITE);
			Fill(30, c * 6, 35, c * 6 + 5, PIXEL_HALF, c | BG_WHITE);
			Fill(36, c * 6, 41, c * 6 + 5, PIXEL_QUARTER, c | BG_WHITE);
		}
		return true;
	}
};

int main()
{
	Example demo;
	demo.ConstructConsole(160, 120, 4, 4);
	demo.Start();
	
	return 0;
}

First problem, as expected, was to set UNICODE (UTF-8). And I couldn't do it properly. I tried a few solutions that I came across on the Web, and the compile time error still shows up.
I guess that:
1. my include files (related to windows) are problematic,
2. I couldn't set Unicode properly.
Thanks to anyone who may help or direct me in the right direction. 
Greetings,

Here's the console error log:
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)