让Eclipse的C ++解析器与Emscripten一起使用

时间:2014-07-17 18:08:44

标签: c++ eclipse eclipse-cdt eclipse-kepler emscripten

我在使用Eclipse的C ++解析器时遇到了一些问题。我一直在使用它与Emscripten,并发现代码完成,调用层次结构,文档弹出窗口,代码分析和相关功能非常有用,但它一直困扰我解析器不完全工作。特别是使用矢量这个新问题。


第一个解析错误在std::vector<SDL_Rect> box;上,错误为:

  

无法解析符号'vector'

然后在emscripten_set_main_loop(game_loop, 60, 1);我收到此错误:

  

无法解析功能'usleep'

这是完整的代码:

#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <emscripten.h>
#include <stdarg.h>
#include <libcxx/vector>

///GLOBAL VARIABLES
SDL_Surface* bitmap;
SDL_Surface* screen;
SDL_Rect source;
SDL_Rect destination;

///second sprite
SDL_Surface* bitmap2;
SDL_Rect source2;
SDL_Rect destination2;

/// Side Scrolling variables:
SDL_Rect camera;
SDL_Rect offset;
SDL_Rect offset2;

int level_width = 480 * 5;
int level_height = 640;

bool gameRunning = true;

class buttonpresses {
public:
    bool leftButton;
    bool rightButton;
    bool jumpButton;

};

int movementspeed = 5;
int jumpspeed = 2;
bool jumpenabled = false;
int jumpduration = 0;
int maxjump = 20;

int leftmomentum = 1;
int rightmomentum = 1;

int lastdestination;
int countDestination = 0;

int maxmomentum = 5;

buttonpresses charactermovement;

/// Collision detection
std::vector<SDL_Rect> box;

///MAIN LOOP
void game_loop() {
    // EVENT HANDLING
    SDL_PumpEvents();
    Uint8 *keystate = SDL_GetKeyboardState(NULL);

    if (keystate[SDLK_ESCAPE]) {
        gameRunning = false;
        printf("Game Stopping!!!!!!\n");
        SDL_Quit();
        exit(0);
    }

    if (keystate[SDLK_LEFT]) {
//     printf("Left Key\n");
        charactermovement.leftButton = true;
    }
    if (keystate[SDLK_LEFT] == false) {
        charactermovement.leftButton = false;
    }
    if (keystate[SDLK_RIGHT]) {
//     printf("Right Key\n");
        charactermovement.rightButton = true;
    }
    if (keystate[SDLK_RIGHT] == false) {
        charactermovement.rightButton = false;
    }
    if (keystate[SDLK_SPACE]) {
//     printf("Space Key\n");
        charactermovement.jumpButton = true;
    }
    if (keystate[SDLK_SPACE] == false) {
        charactermovement.jumpButton = false;
    }

//        printf("Game Running..\n");

// LOGIC

    //character movement
    if (charactermovement.rightButton) {
        destination.x = destination.x + movementspeed;
    }
    if (charactermovement.leftButton) {
        destination.x = destination.x - movementspeed;
    }
    if (charactermovement.jumpButton && jumpenabled) {
        destination.y = destination.y - jumpspeed;
        jumpduration++;
    }
    destination.x = destination.x + rightmomentum - leftmomentum;

    if (destination.y >= 200) {
        jumpenabled = true;

//  printf ("jump enabled\n");
    }
    if (jumpduration >= maxjump) {
        jumpenabled = false;
    }
    if (destination.y >= 200) {
//  printf ("destination y:");
//  printf ("%d\n", destination.y);

        jumpduration = 0;
    }
//if (jumpenabled != true){
//  printf ("jump disabled\n");
//}
//if (jumpenabled == true){
//  printf ("jump enabled\n");
//  printf ("jump duration: ");
//  printf ("%d\n", jumpduration);
//}

//momentum
    //save position every 5 interations
    if (countDestination > 5) {
        lastdestination = destination.x;
        countDestination = 0;
    } else {
        countDestination++;
    }

//printf ("last location: ");
//printf ("%d\n", destination.x);
//
//printf ("current location: ");
//printf ("%d\n", lastdestination);

    // increase momentum in direction your moving in (relative to previous location)
    if (lastdestination > destination.x) {
//  printf ("right if running \n ");
        if (rightmomentum > 0) {
            rightmomentum--;
        } else if (leftmomentum < maxmomentum) {
            leftmomentum++;
        }
    }
    if (lastdestination < destination.x) {
//  printf ("left if running \n ");
        if (leftmomentum > 0) {
            leftmomentum--;
        } else if (rightmomentum < maxmomentum) {
            rightmomentum++;
        }
    }
    if (lastdestination == destination.x) {
        if (leftmomentum > 0) {
            leftmomentum--;
        }
        if (rightmomentum > 0) {
            rightmomentum--;
        }
    }

    printf("left momentum: ");
    printf("%d\n", rightmomentum);
    printf("right momentum: ");
    printf("%d\n", leftmomentum);

    //gravity
    if (destination.y <= 200) {
        destination.y++;
    }
    offset.x = destination.x - camera.x;
    offset2.x = destination2.x - camera.x;
    offset.y = destination.y - camera.y;
    offset2.y = destination2.y - camera.y;

    // RENDERING
    SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
    SDL_BlitSurface(bitmap, &source, screen, &offset);

    // RENDER SECOND SPRITE
    SDL_BlitSurface(bitmap2, &source2, screen, &offset2);

    //blank screen
    SDL_Flip(screen);
    camera.x++;
}

int main() {
    SDL_Init( SDL_INIT_VIDEO);

    // LOAD FILES
    bitmap = IMG_Load("ninjagaiden3sheet1.png");
    screen = SDL_SetVideoMode(640, 480, 0, SDL_HWSURFACE | SDL_DOUBLEBUF);
    /// camera variables
    camera.x = 0;
    camera.y = 0;
    camera.w = 640;
    camera.h = 480;
    /// end camera variables

    // Part of the bitmap that we want to draw

    source.x = 37;
    source.y = 4;
    source.w = 17;
    source.h = 32;

    // Part of the screen we want to draw the sprite to

    destination.x = 100;
    destination.y = 100;
    destination.w = 65;
    destination.h = 44;

    //// second sprite
    bitmap2 = IMG_Load("bat_transparent.png");
    source2.x = 24;
    source2.y = 63;
    source2.w = 65;
    source2.h = 44;

    destination2.x = 940;
    destination2.y = 100;
    destination2.w = 65;
    destination2.h = 44;
    //// end second sprite

    lastdestination = destination.x;

    offset = destination;
    offset2 = destination2;

    charactermovement.leftButton = false;
    charactermovement.rightButton = false;
    charactermovement.jumpButton = false;

    //START MAIN LOOP
    emscripten_set_main_loop(game_loop, 60, 1);

    return 0;
}

“路径和符号”属性中的C ++包含选项卡如下所示:

C:\Program Files\Emscripten\emscripten\1.12.0\system\include
C:\Program Files\Emscripten\emscripten\1.12.0\system\include\libc
C:\Program Files\Emscripten\emscripten\1.12.0\system\include\emscripten
C:\Program Files\Emscripten\emscripten\1.12.0\system\include\libcxx

在Indexer设置中,我启用了以下功能:

  
      
  • 未包含在构建
  • 中的索引源文件   
  • 索引未使用的标题
  •   
  • 索引所有标题变体
  •   
  • 在编辑器中打开的索引源文件和头文件
  •   
  • 允许启发式解析包含
  •   
  • 跳过大于8 MB的文件
  •   

有谁知道发生了什么事?或者我可以做些什么来解决它?

更新

我修复了解析std::vector时的错误。事实证明,某些llvm / clang库使用_LIBCPP_BEGIN_NAMESPACE_STD_LIBCPP_END_NAMESPACE_STD定义而不是using namespace std;,除非定义了__clang__,否则这些定义对解析器是不可见的。

因此,解决方案是在“路径和符号”属性中进入C ++的“符号”选项卡并添加:

__clang__

在弹出的“添加”对话框中,只需将其放入Name:输入字段,然后按确定。这也将添加许多缺少的标准命名空间函数,如cout cin等。

我还没有找到针对usleep / emscripten_set_main_loop问题的修复程序,但这应该足以让IDE的代码完成并且可以使用几个相关的功能。虽然我仍然在使用Eclipse时遇到一些奇怪的复杂解析器问题,所以我想我将放弃在此处搜索解决方案并使用NetBeans进行I think I have every thing set up

0 个答案:

没有答案