| @@ -4,11 +4,11 @@ noinst_PROGRAMS = test-map editor | |||||
| noinst_LIBRARIES = libcommon.a | noinst_LIBRARIES = libcommon.a | ||||
| libcommon_a_SOURCES = \ | 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 \ | 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 \ | debugfps.cpp debugfps.h debugsprite.cpp debugsprite.h \ | ||||
| debugrecord.cpp debugrecord.h | debugrecord.cpp debugrecord.h | ||||
| libcommon_a_CXXFLAGS = `pkg-config --cflags sdl gl SDL_image` | libcommon_a_CXXFLAGS = `pkg-config --cflags sdl gl SDL_image` | ||||
| @@ -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__ | |||||
| @@ -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__ | |||||
| @@ -9,9 +9,8 @@ | |||||
| #include <cstdio> | #include <cstdio> | ||||
| #include "core.h" | |||||
| #include "debugfps.h" | #include "debugfps.h" | ||||
| #include "forge.h" | |||||
| #include "profiler.h" | |||||
| /* | /* | ||||
| * DebugFps implementation class | * DebugFps implementation class | ||||
| @@ -12,8 +12,8 @@ | |||||
| #include <pipi.h> | #include <pipi.h> | ||||
| #include "core.h" | |||||
| #include "debugrecord.h" | #include "debugrecord.h" | ||||
| #include "video.h" | |||||
| /* | /* | ||||
| * DebugRecord implementation class | * DebugRecord implementation class | ||||
| @@ -9,9 +9,8 @@ | |||||
| #include <cstdio> | #include <cstdio> | ||||
| #include "core.h" | |||||
| #include "debugsprite.h" | #include "debugsprite.h" | ||||
| #include "game.h" | |||||
| #include "tiler.h" | |||||
| /* | /* | ||||
| * DebugSprite implementation class | * DebugSprite implementation class | ||||
| @@ -24,7 +23,7 @@ class DebugSpriteData | |||||
| private: | private: | ||||
| Game *game; | Game *game; | ||||
| int tiler; | int tiler; | ||||
| int frame; | |||||
| float x, y, z; | |||||
| }; | }; | ||||
| /* | /* | ||||
| @@ -36,6 +35,9 @@ DebugSprite::DebugSprite(Game *game) | |||||
| data = new DebugSpriteData(); | data = new DebugSpriteData(); | ||||
| data->game = game; | data->game = game; | ||||
| data->tiler = Tiler::Register("art/test/character-dress.png"); | data->tiler = Tiler::Register("art/test/character-dress.png"); | ||||
| data->x = 320; | |||||
| data->y = 206; | |||||
| data->z = 0; | |||||
| } | } | ||||
| Entity::Group DebugSprite::GetGroup() | Entity::Group DebugSprite::GetGroup() | ||||
| @@ -46,14 +48,22 @@ Entity::Group DebugSprite::GetGroup() | |||||
| void DebugSprite::TickGame(float deltams) | void DebugSprite::TickGame(float deltams) | ||||
| { | { | ||||
| Entity::TickGame(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) | void DebugSprite::TickRender(float deltams) | ||||
| { | { | ||||
| Entity::TickRender(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() | DebugSprite::~DebugSprite() | ||||
| @@ -10,8 +10,7 @@ | |||||
| #include <cstdlib> | #include <cstdlib> | ||||
| #include <cstdio> | #include <cstdio> | ||||
| #include "entity.h" | |||||
| #include "ticker.h" | |||||
| #include "core.h" | |||||
| /* | /* | ||||
| * Public Entity class | * Public Entity class | ||||
| @@ -21,7 +21,7 @@ | |||||
| #include <SDL.h> | #include <SDL.h> | ||||
| #include <SDL_image.h> | #include <SDL_image.h> | ||||
| #include "font.h" | |||||
| #include "core.h" | |||||
| /* | /* | ||||
| * Font implementation class | * Font implementation class | ||||
| @@ -11,7 +11,7 @@ | |||||
| #include <cstdio> | #include <cstdio> | ||||
| #include <cstdlib> | #include <cstdlib> | ||||
| #include "forge.h" | |||||
| #include "core.h" | |||||
| #if defined WIN32 | #if defined WIN32 | ||||
| # define strcasecmp _stricmp | # define strcasecmp _stricmp | ||||
| @@ -9,8 +9,7 @@ | |||||
| #include <cstdio> | #include <cstdio> | ||||
| #include "game.h" | |||||
| #include "map.h" | |||||
| #include "core.h" | |||||
| /* | /* | ||||
| * Game implementation class | * Game implementation class | ||||
| @@ -14,10 +14,8 @@ | |||||
| #include <gtk/gtk.h> | #include <gtk/gtk.h> | ||||
| #include <gtkgl/gtkglarea.h> | #include <gtkgl/gtkglarea.h> | ||||
| #include "ticker.h" | |||||
| #include "core.h" | |||||
| #include "debugfps.h" | #include "debugfps.h" | ||||
| #include "video.h" | |||||
| #include "game.h" | |||||
| static volatile int quit = 0; | static volatile int quit = 0; | ||||
| @@ -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; | |||||
| } | |||||
| @@ -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__ | |||||
| @@ -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() | |||||
| { | |||||
| } | |||||
| @@ -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__ | |||||
| @@ -9,7 +9,7 @@ | |||||
| #include <cstdlib> | #include <cstdlib> | ||||
| #include "layer.h" | |||||
| #include "core.h" | |||||
| Layer::Layer(int w, int h, int z, int o, uint32_t *in_data) | Layer::Layer(int w, int h, int z, int o, uint32_t *in_data) | ||||
| { | { | ||||
| @@ -12,9 +12,7 @@ | |||||
| #include <cstdlib> | #include <cstdlib> | ||||
| #include <ctype.h> | #include <ctype.h> | ||||
| #include "map.h" | |||||
| #include "layer.h" | |||||
| #include "tiler.h" | |||||
| #include "core.h" | |||||
| /* | /* | ||||
| * Map implementation class | * Map implementation class | ||||
| @@ -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__ | |||||
| @@ -11,8 +11,7 @@ | |||||
| #include <cstdio> | #include <cstdio> | ||||
| #include <stdint.h> | #include <stdint.h> | ||||
| #include "profiler.h" | |||||
| #include "timer.h" | |||||
| #include "core.h" | |||||
| /* | /* | ||||
| * Profiler implementation class | * Profiler implementation class | ||||
| @@ -21,8 +21,7 @@ | |||||
| # include <GL/gl.h> | # include <GL/gl.h> | ||||
| #endif | #endif | ||||
| #include "scene.h" | |||||
| #include "tiler.h" | |||||
| #include "core.h" | |||||
| struct Tile | struct Tile | ||||
| { | { | ||||
| @@ -9,6 +9,7 @@ | |||||
| #include <SDL.h> | #include <SDL.h> | ||||
| #include "core.h" | |||||
| #include "sdlinput.h" | #include "sdlinput.h" | ||||
| /* | /* | ||||
| @@ -21,6 +22,7 @@ class SdlInputData | |||||
| private: | private: | ||||
| Game *game; | Game *game; | ||||
| int mx, my; | |||||
| }; | }; | ||||
| /* | /* | ||||
| @@ -33,6 +35,7 @@ SdlInput::SdlInput(Game *game) | |||||
| data = new SdlInputData(); | data = new SdlInputData(); | ||||
| data->game = game; | data->game = game; | ||||
| SDL_GetMouseState(&data->mx, &data->my); | |||||
| } | } | ||||
| Entity::Group SdlInput::GetGroup() | Entity::Group SdlInput::GetGroup() | ||||
| @@ -48,27 +51,27 @@ void SdlInput::TickGame(float deltams) | |||||
| destroy = 1; | destroy = 1; | ||||
| /* Handle mouse input */ | /* 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; | SDL_Event event; | ||||
| while (SDL_PollEvent(&event)) | while (SDL_PollEvent(&event)) | ||||
| { | { | ||||
| if (event.type == SDL_QUIT) | if (event.type == SDL_QUIT) | ||||
| data->game->Quit(); | data->game->Quit(); | ||||
| if (event.type == SDL_KEYDOWN) | |||||
| { | |||||
| if (event.key.keysym.sym == SDLK_ESCAPE) | |||||
| data->game->Quit(); | |||||
| #if 0 | #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 | #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() | SdlInput::~SdlInput() | ||||
| @@ -12,14 +12,11 @@ | |||||
| #include <SDL.h> | #include <SDL.h> | ||||
| #include "core.h" | |||||
| #include "sdlinput.h" | #include "sdlinput.h" | ||||
| #include "debugfps.h" | #include "debugfps.h" | ||||
| #include "debugsprite.h" | #include "debugsprite.h" | ||||
| #include "debugrecord.h" | #include "debugrecord.h" | ||||
| #include "game.h" | |||||
| #include "ticker.h" | |||||
| #include "profiler.h" | |||||
| #include "video.h" | |||||
| static float const FPS = 30.0f; | static float const FPS = 30.0f; | ||||
| @@ -42,7 +39,7 @@ int main(int argc, char **argv) | |||||
| SDL_WM_SetCaption("Map Test (SDL)", NULL); | SDL_WM_SetCaption("Map Test (SDL)", NULL); | ||||
| SDL_ShowCursor(0); | SDL_ShowCursor(0); | ||||
| SDL_WM_GrabInput(SDL_GRAB_ON); | |||||
| //SDL_WM_GrabInput(SDL_GRAB_ON); | |||||
| /* Initialise OpenGL */ | /* Initialise OpenGL */ | ||||
| Video::Setup(video->w, video->h); | Video::Setup(video->w, video->h); | ||||
| @@ -11,10 +11,7 @@ | |||||
| #include <cstdio> | #include <cstdio> | ||||
| #include <stdint.h> | #include <stdint.h> | ||||
| #include "profiler.h" | |||||
| #include "ticker.h" | |||||
| #include "entity.h" | |||||
| #include "timer.h" | |||||
| #include "core.h" | |||||
| /* | /* | ||||
| * Ticker implementation class | * Ticker implementation class | ||||
| @@ -11,8 +11,7 @@ | |||||
| #include <cstdio> | #include <cstdio> | ||||
| #include <cstdlib> | #include <cstdlib> | ||||
| #include "tiler.h" | |||||
| #include "tileset.h" | |||||
| #include "core.h" | |||||
| #if defined WIN32 | #if defined WIN32 | ||||
| # define strcasecmp _stricmp | # define strcasecmp _stricmp | ||||
| @@ -24,7 +24,7 @@ | |||||
| #include <SDL.h> | #include <SDL.h> | ||||
| #include <SDL_image.h> | #include <SDL_image.h> | ||||
| #include "tileset.h" | |||||
| #include "core.h" | |||||
| /* | /* | ||||
| * TileSet implementation class | * TileSet implementation class | ||||
| @@ -22,7 +22,7 @@ | |||||
| # include <SDL.h> | # include <SDL.h> | ||||
| #endif | #endif | ||||
| #include "timer.h" | |||||
| #include "core.h" | |||||
| /* | /* | ||||
| * Timer implementation class | * Timer implementation class | ||||
| @@ -18,7 +18,7 @@ | |||||
| # include <GL/gl.h> | # include <GL/gl.h> | ||||
| #endif | #endif | ||||
| #include "video.h" | |||||
| #include "core.h" | |||||
| /* | /* | ||||
| * Public Video class | * Public Video class | ||||
| @@ -12,6 +12,8 @@ | |||||
| #if !defined __DH_VIDEO_H__ | #if !defined __DH_VIDEO_H__ | ||||
| #define __DH_VIDEO_H__ | #define __DH_VIDEO_H__ | ||||
| #include <stdint.h> | |||||
| class Video | class Video | ||||
| { | { | ||||
| public: | public: | ||||