C++ Visual Studio Express 2013 SDL_Init_SubSystem(SDL_INIT_E

C++ Visual Studio Express 2013 SDL_Init_SubSystem(SDL_INIT_EVENTS) fails

本文关键字:SDL SubSystem INIT Init Visual Express 2013 C++ Studio      更新时间:2023-10-16

我正在尝试制作一个基本的游戏引擎,如果可以的话,我希望控制器由SDL运行。我的最终目标是将所有SDL特定的代码抽象到一个Controller类中,但我现在只是想让它发挥作用。这是我得到的:

//User defined Includes
#include <Atom.h>
#include <Timer.h>
#include <Renderer.h>
#include <OGLRenderingWindow.h>
//temp includes for now
#include <Box.h>
#include <Point.hpp>
#include <Color.hpp>
 int WINAPI WinMain(HINSTANCE hInstance,
               HINSTANCE hPrevInstance,
               LPSTR     cmdLine,
               S32       cmdShow) 
{
//Window settings, will be abstrated out to a config file later
const S32 windowHeight          = 1072;
const S32 windowWidth           = 768;
const S32 windowBPP             = 32;
const bool windowFullScreen     = false;
//Start up OGL Window
OGLRenderingWindow programWindow(hInstance);
if(!programWindow.Init(windowHeight, windowWidth, windowBPP, windowFullScreen)) {
    MessageBox(NULL, "Unable to create the OpenGL Window", "An Error occured", MB_ICONERROR | MB_OK);
    programWindow.ShutDown();
    return 1;
}
//Start Timer
Timer* timer = Timer::Instance();
Renderer* renderer = Renderer::Instance();
if(SDL_Init(0)) {
    MessageBox(NULL, "Unable to initialize SDL", "An Error occured", MB_ICONERROR | MB_OK);
    programWindow.ShutDown();
    return 1;
}
if(!SDL_InitSubSystem(SDL_INIT_EVENTS)) {
    MessageBox(NULL, "Unable to initialize SDL_EVENTS", "An Error occured", MB_ICONERROR | MB_OK);
    programWindow.ShutDown();
    return 1;
}
Point<> pos(0.0f, 0.0f, 0.0f);
Color<> col(1.0f, 0.0f, 0.0f);
Box redbox(25.0f, 25.0f, pos, col);
pos = new Point<>(80.0f, 80.0f, 0.0f);
col = new Color<>(0.0f, 0.0f, 1.0f);
Box greenbox(25.0f, 25.0f, pos, col);
pos = new Point<>(-80.0f, 80.0f, 0.0f);
col = new Color<>(0.0f, 1.0f, 0.0f);
Box bluebox(25.0f, 25.0f, pos, col);
//Main Loop Beings
while(programWindow.isRunning()) {
    //Proecess windows events
    programWindow.ProcessEvents();
    //Update the Timer
    timer->Update();
    //Test cell render
    redbox.v_Update();
    redbox.v_Render();
    greenbox.v_Render();
    bluebox.v_Render();
    //WorldManager Update
    //WorldManager Render
    //Force Render at the end of the frame
    renderer->Render();
    programWindow.Swap();
}
programWindow.ShutDown();
//redbox.v_ShutDown();
//greenbox.v_ShutDown();
//bluebox.v_ShutDown();
delete timer;
delete renderer;

return 0;

}

这是正在调用的框的更新(redbox.v_Update();)

void Box::v_Update(void) {
//_keyCode = _controller->UpdateInput();
SDL_Event event;
while (SDL_PollEvent(&event)) {
    switch (event.type){
        case SDL_KEYDOWN: {
            switch (event.key.keysym.sym) {
                case SDLK_UP:
                  _velosity = Vector<F32>(0.0f, 1.0f, 0.0f);
                  break;
                case SDLK_DOWN:
                  _velosity = Vector<F32>(0.0f, -1.0f, 0.0f);
                  break;
                case SDLK_RIGHT:
                case 3:
                  _velosity = Vector<F32>(1.0f, 0.0f, 0.0f);
                  break;
                case SDLK_LEFT:
                  _velosity = Vector<F32>(-1.0f, 0.0f, 0.0f);
                  break;
                default:
                  break;
            }
        }
    }
}
F32 delta = _timer->DeltaTime() * _speed;
_position += Point<>( (_velosity.x * delta), (_velosity.y * delta), (_velosity.z * delta) );
_cell.SetPosition(_position);
}

如果SDL未能初始化事件子系统,我添加了一个错误消息框,截至目前,它是。我在链接器中链接到SDL2.lib,以及SLD_Init(0);不会出错。我也尝试过它作为SDL_Init(SDL_Init_EVENTS),但它失败了。

h有一些我喜欢使用的typedef。具体如下:

#ifndef ATOM_H
#define ATOM_H
//Includes. These will be the files that everything will need to have access to
//User defined Includes
#include <KillerMath.h>
//Sytem and library includes
#include <windows.h>
//Signed Typedefs
typedef signed __int8   S8;
typedef signed __int16  S16;
typedef signed __int32  S32;
typedef signed __int64  S64;
//Unsigned Typedefs
typedef unsigned __int8  U8;
typedef unsigned __int16 U16;
typedef unsigned __int32 U32;
typedef unsigned __int64 U64;
//Floating types
typedef float  F32;
typedef double F64;
#endif

因此,以下是我的基本问题:

  1. 这是用SDL处理控制器的正确方法吗?重点是使控制器类成为一个组件,可以在运行时根据组件映射从框中添加和删除。我想用这种方式,这样我就可以控制用户控制的对象。

  2. 所有的图形都是由opengl处理的,它们工作得很好。如果我对关键事件的值进行硬编码,并强制更新Velocity向量,它会毫无问题地移动框,所以我知道系统的一部分正在工作。问题似乎只是SDL,而且它似乎未能初始化。你能发现我对Init SDL做了什么错事吗?

@Rollen你是对的,问题是SDL没有窗口的句柄。我试图将我正在生成的hwnd传递到SDL中,以使控制器/键盘输入正常工作,但我没能做到这一点(很可能是因为我没有完全理解SDL)。在未来,我可能会让一个项目只使用SDL,这样我就可以更好地了解它的工作方式。目前,DirectInput像冠军一样工作,我在很短的时间内就启动并运行了它。感谢您的投入。