浏览代码

Replace mouse scrolling with a joystick simulated by the e/s/d/f keys.

legacy
Sam Hocevar sam 14 年前
父节点
当前提交
988f7c2885
共有 28 个文件被更改,包括 245 次插入128 次删除
  1. +4
    -4
      src/Makefile.am
  2. +44
    -0
      src/bitfield.h
  3. +40
    -0
      src/core.h
  4. +1
    -2
      src/debugfps.cpp
  5. +1
    -1
      src/debugrecord.cpp
  6. +15
    -5
      src/debugsprite.cpp
  7. +1
    -2
      src/entity.cpp
  8. +1
    -1
      src/font.cpp
  9. +1
    -1
      src/forge.cpp
  10. +1
    -2
      src/game.cpp
  11. +1
    -3
      src/gtk/editor.cpp
  12. +57
    -0
      src/input.cpp
  13. +23
    -0
      src/input.h
  14. +0
    -40
      src/joystick.cpp
  15. +0
    -34
      src/joystick.h
  16. +1
    -1
      src/layer.cpp
  17. +1
    -3
      src/map.cpp
  18. +28
    -0
      src/matrix.h
  19. +1
    -2
      src/profiler.cpp
  20. +1
    -2
      src/scene.cpp
  21. +14
    -11
      src/sdlinput.cpp
  22. +2
    -5
      src/test-map.cpp
  23. +1
    -4
      src/ticker.cpp
  24. +1
    -2
      src/tiler.cpp
  25. +1
    -1
      src/tileset.cpp
  26. +1
    -1
      src/timer.cpp
  27. +1
    -1
      src/video.cpp
  28. +2
    -0
      src/video.h

+ 4
- 4
src/Makefile.am 查看文件

@@ -4,11 +4,11 @@ noinst_PROGRAMS = test-map editor
noinst_LIBRARIES = libcommon.a

libcommon_a_SOURCES = \
game.cpp game.h tiler.cpp tiler.h tileset.cpp tileset.h \
core.h matrix.h game.cpp game.h tiler.cpp tiler.h \
scene.cpp scene.h font.cpp font.h layer.cpp layer.h map.cpp map.h \
joystick.cpp joystick.h entity.cpp entity.h ticker.cpp ticker.h \
forge.cpp forge.h video.cpp video.h timer.cpp timer.h \
profiler.cpp profiler.h \
entity.cpp entity.h ticker.cpp ticker.h tileset.cpp tileset.h \
forge.cpp forge.h video.cpp video.h timer.cpp timer.h bitfield.h \
profiler.cpp profiler.h input.h input.cpp \
debugfps.cpp debugfps.h debugsprite.cpp debugsprite.h \
debugrecord.cpp debugrecord.h
libcommon_a_CXXFLAGS = `pkg-config --cflags sdl gl SDL_image`


+ 44
- 0
src/bitfield.h 查看文件

@@ -0,0 +1,44 @@
//
// Deus Hax (working title)
// Copyright (c) 2010 Sam Hocevar <sam@hocevar.net>
//

//
// The BitField class
// ------------------
//

#if !defined __DH_BITFIELD_H__
#define __DH_BITFIELD_H__

template class BitField<unsigned int COUNT>
{
public:
BitField()
{
memset(bits, 0, sizeof(bits));
}

inline unsigned int IsSet(unsigned int index)
{
return bits[index / 32] & (1 << (index & 31));
}

inline void Set(unsigned int index)
{
bits[index / 32] |= (1 << (index & 31));
}

inline void Unset(unsigned int index)
{
bits[index / 32] &= ~(1 << (index & 31));
}


private:
/* FIXME: use uint32_t here instead */
unsigned int bits[(COUNT + 31) / 32];
};

#endif // __DH_BITFIELD_H__


+ 40
- 0
src/core.h 查看文件

@@ -0,0 +1,40 @@
//
// Deus Hax (working title)
// Copyright (c) 2010 Sam Hocevar <sam@hocevar.net>
//

//
// The main header
// ---------------
//

#if !defined __DH_CORE_H__
#define __DH_CORE_H__

// Base types
#include "matrix.h"
#include "timer.h"

// Static classes
#include "video.h"
#include "scene.h"
#include "input.h"
#include "profiler.h"

// Entities
#include "entity.h"
#include "font.h"
#include "game.h"
#include "tileset.h"

// Other objects
#include "map.h"
#include "layer.h"

// Managers
#include "ticker.h"
#include "forge.h"
#include "tiler.h"

#endif // __DH_CORE_H__


+ 1
- 2
src/debugfps.cpp 查看文件

@@ -9,9 +9,8 @@

#include <cstdio>

#include "core.h"
#include "debugfps.h"
#include "forge.h"
#include "profiler.h"

/*
* DebugFps implementation class


+ 1
- 1
src/debugrecord.cpp 查看文件

@@ -12,8 +12,8 @@

#include <pipi.h>

#include "core.h"
#include "debugrecord.h"
#include "video.h"

/*
* DebugRecord implementation class


+ 15
- 5
src/debugsprite.cpp 查看文件

@@ -9,9 +9,8 @@

#include <cstdio>

#include "core.h"
#include "debugsprite.h"
#include "game.h"
#include "tiler.h"

/*
* DebugSprite implementation class
@@ -24,7 +23,7 @@ class DebugSpriteData
private:
Game *game;
int tiler;
int frame;
float x, y, z;
};

/*
@@ -36,6 +35,9 @@ DebugSprite::DebugSprite(Game *game)
data = new DebugSpriteData();
data->game = game;
data->tiler = Tiler::Register("art/test/character-dress.png");
data->x = 320;
data->y = 206;
data->z = 0;
}

Entity::Group DebugSprite::GetGroup()
@@ -46,14 +48,22 @@ Entity::Group DebugSprite::GetGroup()
void DebugSprite::TickGame(float deltams)
{
Entity::TickGame(deltams);

Float2 axis = Input::GetAxis(0);
data->x += 0.1f * deltams * axis.x;
data->y += 0.1f * deltams * axis.y;
}

void DebugSprite::TickRender(float deltams)
{
Entity::TickRender(deltams);

data->game->GetScene()->AddTile((data->tiler << 16) | 15, 320, 240, 32, 1);
data->game->GetScene()->AddTile((data->tiler << 16) | 31, 320, 240, 0, 1);
int x = data->x;
int y = data->y;
int z = data->z;

data->game->GetScene()->AddTile((data->tiler << 16) | 15, x, y, z + 32, 1);
data->game->GetScene()->AddTile((data->tiler << 16) | 31, x, y, z, 1);
}

DebugSprite::~DebugSprite()


+ 1
- 2
src/entity.cpp 查看文件

@@ -10,8 +10,7 @@
#include <cstdlib>
#include <cstdio>

#include "entity.h"
#include "ticker.h"
#include "core.h"

/*
* Public Entity class


+ 1
- 1
src/font.cpp 查看文件

@@ -21,7 +21,7 @@
#include <SDL.h>
#include <SDL_image.h>

#include "font.h"
#include "core.h"

/*
* Font implementation class


+ 1
- 1
src/forge.cpp 查看文件

@@ -11,7 +11,7 @@
#include <cstdio>
#include <cstdlib>

#include "forge.h"
#include "core.h"

#if defined WIN32
# define strcasecmp _stricmp


+ 1
- 2
src/game.cpp 查看文件

@@ -9,8 +9,7 @@

#include <cstdio>

#include "game.h"
#include "map.h"
#include "core.h"

/*
* Game implementation class


+ 1
- 3
src/gtk/editor.cpp 查看文件

@@ -14,10 +14,8 @@
#include <gtk/gtk.h>
#include <gtkgl/gtkglarea.h>

#include "ticker.h"
#include "core.h"
#include "debugfps.h"
#include "video.h"
#include "game.h"

static volatile int quit = 0;



+ 57
- 0
src/input.cpp 查看文件

@@ -0,0 +1,57 @@
//
// Deus Hax (working title)
// Copyright (c) 2010 Sam Hocevar <sam@hocevar.net>
//

#if defined HAVE_CONFIG_H
# include "config.h"
#endif

#include <SDL.h>

#include <cstdio>
#include <cstdlib>
#include <cmath>

#include "core.h"

/*
* Input implementation class
*/

static class InputData
{
friend class Input;

public:
int dummy;
}
inputdata;

static InputData * const data = &inputdata;

/*
* Public Input class
*/

Float2 Input::GetAxis(int axis)
{
float invsqrt2 = sqrtf(0.5f);
Float2 f;

/* Simulate a joystick using the keyboard. This SDL call is free. */
Uint8 *keystate = SDL_GetKeyState(NULL);
f.y -= keystate[SDLK_e];
f.y += keystate[SDLK_d];
f.x -= keystate[SDLK_s];
f.x += keystate[SDLK_f];
if (keystate[SDLK_e] + keystate[SDLK_d]
== keystate[SDLK_s] + keystate[SDLK_f])
{
f.x *= invsqrt2;
f.y *= invsqrt2;
}

return f;
}


+ 23
- 0
src/input.h 查看文件

@@ -0,0 +1,23 @@
//
// Deus Hax (working title)
// Copyright (c) 2010 Sam Hocevar <sam@hocevar.net>
//

//
// The Input static class
// ----------------------
//

#if !defined __DH_INPUT_H__
#define __DH_INPUT_H__

#include "matrix.h"

class Input
{
public:
static Float2 GetAxis(int axis);
};

#endif // __DH_INPUT_H__


+ 0
- 40
src/joystick.cpp 查看文件

@@ -1,40 +0,0 @@
//
// Deus Hax (working title)
// Copyright (c) 2010 Sam Hocevar <sam@hocevar.net>
//

#if defined HAVE_CONFIG_H
# include "config.h"
#endif

#include <SDL.h>

#include "joystick.h"

/*
* Joystick implementation class
*/

class JoystickData
{
friend class Joystick;

private:
int dummy;
};

/*
* Public Joystick class
*/

Joystick::Joystick()
{
data = new JoystickData();

SDL_WM_GrabInput(SDL_GRAB_ON);
}

Joystick::~Joystick()
{
}


+ 0
- 34
src/joystick.h 查看文件

@@ -1,34 +0,0 @@
//
// Deus Hax (working title)
// Copyright (c) 2010 Sam Hocevar <sam@hocevar.net>
//

//
// The Joystick class
// ------------------
//

#if !defined __DH_JOYSTICK_H__
#define __DH_JOYSTICK_H__

class JoystickData;

class Joystick
{
public:
Joystick();
~Joystick();

int GetState();

static int const NORTH = (1<<0);
static int const EAST = (1<<1);
static int const SOUTH = (1<<2);
static int const WEST = (1<<3);

private:
JoystickData *data;
};

#endif // __DH_JOYSTICK_H__


+ 1
- 1
src/layer.cpp 查看文件

@@ -9,7 +9,7 @@

#include <cstdlib>

#include "layer.h"
#include "core.h"

Layer::Layer(int w, int h, int z, int o, uint32_t *in_data)
{


+ 1
- 3
src/map.cpp 查看文件

@@ -12,9 +12,7 @@
#include <cstdlib>
#include <ctype.h>

#include "map.h"
#include "layer.h"
#include "tiler.h"
#include "core.h"

/*
* Map implementation class


+ 28
- 0
src/matrix.h 查看文件

@@ -0,0 +1,28 @@
//
// Deus Hax (working title)
// Copyright (c) 2010 Sam Hocevar <sam@hocevar.net>
//

//
// The Matrix classes
// ------------------
//

#if !defined __DH_MATRIX_H__
#define __DH_MATRIX_H__

struct Float2
{
Float2() { x = y = 0.0f; }
Float2(float _x, float _y) { x = _x; y = _y; }

float x, y;
};

struct Float3
{
float x, y, z;
};

#endif // __DH_MATRIX_H__


+ 1
- 2
src/profiler.cpp 查看文件

@@ -11,8 +11,7 @@
#include <cstdio>
#include <stdint.h>

#include "profiler.h"
#include "timer.h"
#include "core.h"

/*
* Profiler implementation class


+ 1
- 2
src/scene.cpp 查看文件

@@ -21,8 +21,7 @@
# include <GL/gl.h>
#endif

#include "scene.h"
#include "tiler.h"
#include "core.h"

struct Tile
{


+ 14
- 11
src/sdlinput.cpp 查看文件

@@ -9,6 +9,7 @@

#include <SDL.h>

#include "core.h"
#include "sdlinput.h"

/*
@@ -21,6 +22,7 @@ class SdlInputData

private:
Game *game;
int mx, my;
};

/*
@@ -33,6 +35,7 @@ SdlInput::SdlInput(Game *game)

data = new SdlInputData();
data->game = game;
SDL_GetMouseState(&data->mx, &data->my);
}

Entity::Group SdlInput::GetGroup()
@@ -48,27 +51,27 @@ void SdlInput::TickGame(float deltams)
destroy = 1;

/* Handle mouse input */
int mx, my;
SDL_GetMouseState(&mx, &my);
data->game->SetMouse(mx * (640 - 32) / 320 - 320, my * (480 - 32) / 240 - 240);
SDL_GetMouseState(&data->mx, &data->my);

/* Handle keyboard and WM input */
/* Handle keyboard and WM events */
SDL_Event event;
while (SDL_PollEvent(&event))
{
if (event.type == SDL_QUIT)
data->game->Quit();
if (event.type == SDL_KEYDOWN)
{
if (event.key.keysym.sym == SDLK_ESCAPE)
data->game->Quit();
#if 0
else if (event.key.keysym.sym == SDLK_RETURN)
video->FullScreen();
else if (event.type == SDL_KEYDOWN)
Input::KeyPressed(event.key.keysym.sym, deltams);
#endif
}
}

/* Send the whole keyboard state to the input system */
#if 0
Uint8 *keystate = SDL_GetKeyState(NULL);
for (int i = 0; i < 256; i++)
if (keystate[i])
Input::KeyPressed(i, deltams);
#endif
}

SdlInput::~SdlInput()


+ 2
- 5
src/test-map.cpp 查看文件

@@ -12,14 +12,11 @@

#include <SDL.h>

#include "core.h"
#include "sdlinput.h"
#include "debugfps.h"
#include "debugsprite.h"
#include "debugrecord.h"
#include "game.h"
#include "ticker.h"
#include "profiler.h"
#include "video.h"

static float const FPS = 30.0f;

@@ -42,7 +39,7 @@ int main(int argc, char **argv)

SDL_WM_SetCaption("Map Test (SDL)", NULL);
SDL_ShowCursor(0);
SDL_WM_GrabInput(SDL_GRAB_ON);
//SDL_WM_GrabInput(SDL_GRAB_ON);

/* Initialise OpenGL */
Video::Setup(video->w, video->h);


+ 1
- 4
src/ticker.cpp 查看文件

@@ -11,10 +11,7 @@
#include <cstdio>
#include <stdint.h>

#include "profiler.h"
#include "ticker.h"
#include "entity.h"
#include "timer.h"
#include "core.h"

/*
* Ticker implementation class


+ 1
- 2
src/tiler.cpp 查看文件

@@ -11,8 +11,7 @@
#include <cstdio>
#include <cstdlib>

#include "tiler.h"
#include "tileset.h"
#include "core.h"

#if defined WIN32
# define strcasecmp _stricmp


+ 1
- 1
src/tileset.cpp 查看文件

@@ -24,7 +24,7 @@
#include <SDL.h>
#include <SDL_image.h>

#include "tileset.h"
#include "core.h"

/*
* TileSet implementation class


+ 1
- 1
src/timer.cpp 查看文件

@@ -22,7 +22,7 @@
# include <SDL.h>
#endif

#include "timer.h"
#include "core.h"

/*
* Timer implementation class


+ 1
- 1
src/video.cpp 查看文件

@@ -18,7 +18,7 @@
# include <GL/gl.h>
#endif

#include "video.h"
#include "core.h"

/*
* Public Video class


+ 2
- 0
src/video.h 查看文件

@@ -12,6 +12,8 @@
#if !defined __DH_VIDEO_H__
#define __DH_VIDEO_H__

#include <stdint.h>

class Video
{
public:


正在加载...
取消
保存