-- [Add] Input is now handled nicely with a Lua wrapper.
-- [Remove] Removed a few unimportant files, and the binary file.
This commit is contained in:
parent
e937071b73
commit
8f2f5301eb
@ -1,48 +0,0 @@
|
||||
#ifndef INPUT_H_
|
||||
#define INPUT_H_
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
|
||||
typedef struct mouse_s
|
||||
{
|
||||
int dx, dy;
|
||||
int old_x, old_y;
|
||||
unsigned int buttons;
|
||||
unsigned int old_buttons;
|
||||
} mouse_t;
|
||||
|
||||
typedef struct keyboard_s
|
||||
{
|
||||
unsigned char *keys;
|
||||
unsigned char *old_keys;
|
||||
int keycount;
|
||||
int last_char;
|
||||
unsigned int mods;
|
||||
} keyboard_t;
|
||||
|
||||
typedef struct input_s
|
||||
{
|
||||
mouse_t mouse;
|
||||
keyboard_t keyboard;
|
||||
} input_t;
|
||||
|
||||
bool create_input();
|
||||
void update_input();
|
||||
|
||||
char get_key();
|
||||
unsigned int get_x();
|
||||
unsigned int get_y();
|
||||
unsigned int get_old_x();
|
||||
unsigned int get_old_y();
|
||||
unsigned int get_mods();
|
||||
bool key_down(int index);
|
||||
bool key_still_down(int index);
|
||||
bool key_up(int index);
|
||||
bool key_still_up(int index);
|
||||
bool mouse_down(int button);
|
||||
bool mouse_still_down(int button);
|
||||
bool mouse_up(int button);
|
||||
bool mouse_still_up(int button);
|
||||
|
||||
void destroy_input();
|
||||
#endif // INPUT_H_
|
@ -1,142 +0,0 @@
|
||||
#include "input.h"
|
||||
#include <string.h>
|
||||
|
||||
static mouse_t mouse;
|
||||
static keyboard_t keyboard;
|
||||
|
||||
bool _curr_key(int index)
|
||||
{
|
||||
return (keyboard.keys[index] != 0);
|
||||
}
|
||||
|
||||
bool _old_key(int index)
|
||||
{
|
||||
return (keyboard.old_keys[index] != 0);
|
||||
};
|
||||
|
||||
bool _curr_mouse(int button)
|
||||
{
|
||||
return ((mouse.buttons & SDL_BUTTON(button)) != 0);
|
||||
};
|
||||
|
||||
bool _old_mouse(int button)
|
||||
{
|
||||
return ((mouse.old_buttons & SDL_BUTTON(button)) != 0);
|
||||
};
|
||||
|
||||
bool create_input()
|
||||
{
|
||||
memset(&keyboard, 0, sizeof(keyboard_t));
|
||||
memset(&mouse, 0, sizeof(mouse_t));
|
||||
SDL_PumpEvents();
|
||||
SDL_PumpEvents();
|
||||
unsigned char *temp_keys = SDL_GetKeyState(&keyboard.keycount);
|
||||
keyboard.keys = (unsigned char *)malloc(sizeof(char) * keyboard.keycount);
|
||||
keyboard.old_keys = (unsigned char *)malloc(sizeof(char) * keyboard.keycount);
|
||||
|
||||
memcpy(keyboard.keys, temp_keys, sizeof(char) * keyboard.keycount);
|
||||
mouse.buttons = SDL_GetMouseState(&mouse.dx, &mouse.dy);
|
||||
return true;
|
||||
};
|
||||
|
||||
void update_input()
|
||||
{
|
||||
SDL_PumpEvents();
|
||||
keyboard.last_char = -1;
|
||||
mouse.old_x = mouse.dx;
|
||||
mouse.old_y = mouse.dy;
|
||||
mouse.old_buttons = mouse.buttons;
|
||||
mouse.buttons = SDL_GetMouseState(&mouse.dx, &mouse.dy);
|
||||
|
||||
memcpy(keyboard.old_keys, keyboard.keys, sizeof(char) * keyboard.keycount);
|
||||
|
||||
unsigned char *tmp = SDL_GetKeyState(&keyboard.keycount);
|
||||
memcpy(keyboard.keys, tmp, sizeof(char) * keyboard.keycount);
|
||||
|
||||
keyboard.mods = SDL_GetModState();
|
||||
|
||||
SDL_Event event;
|
||||
while(SDL_PollEvent(&event))
|
||||
{
|
||||
if(event.type == SDL_KEYDOWN)
|
||||
keyboard.last_char = event.key.keysym.sym;
|
||||
}
|
||||
};
|
||||
|
||||
char get_key()
|
||||
{
|
||||
if(keyboard.last_char != -1)
|
||||
return keyboard.last_char;
|
||||
return 0;
|
||||
};
|
||||
|
||||
unsigned int get_x()
|
||||
{
|
||||
return mouse.dx;
|
||||
};
|
||||
|
||||
unsigned int get_y()
|
||||
{
|
||||
return mouse.dy;
|
||||
};
|
||||
|
||||
unsigned int get_old_x()
|
||||
{
|
||||
return mouse.old_x;
|
||||
};
|
||||
|
||||
unsigned int get_old_y()
|
||||
{
|
||||
return mouse.old_y;
|
||||
};
|
||||
|
||||
unsigned int get_mods()
|
||||
{
|
||||
return keyboard.mods;
|
||||
};
|
||||
|
||||
bool key_down(int index)
|
||||
{
|
||||
return(_curr_key(index) && !_old_key(index));
|
||||
};
|
||||
|
||||
bool key_still_down(int index)
|
||||
{
|
||||
return(_curr_key(index) && _old_key(index));
|
||||
};
|
||||
|
||||
bool key_up(int index)
|
||||
{
|
||||
return(!_curr_key(index) && _old_key(index));
|
||||
};
|
||||
|
||||
bool key_still_up(int index)
|
||||
{
|
||||
return (!_curr_key(index) && !_old_key(index));
|
||||
};
|
||||
|
||||
bool mouse_down(int button)
|
||||
{
|
||||
return (_curr_mouse(button) && !_old_mouse(button));
|
||||
};
|
||||
|
||||
bool mouse_still_down(int button)
|
||||
{
|
||||
return (_curr_mouse(button) && _old_mouse(button));
|
||||
};
|
||||
|
||||
bool mouse_up(int button)
|
||||
{
|
||||
return (!_curr_mouse(button) && _old_mouse(button));
|
||||
};
|
||||
|
||||
bool mouse_still_up(int button)
|
||||
{
|
||||
return (!_curr_mouse(button) && !_old_mouse(button));
|
||||
};
|
||||
|
||||
void destroy_input()
|
||||
{
|
||||
free(keyboard.keys);
|
||||
free(keyboard.old_keys);
|
||||
};
|
Binary file not shown.
Binary file not shown.
@ -1,6 +1,6 @@
|
||||
#############################################################################
|
||||
# Makefile for building: Unuk-QT
|
||||
# Generated by qmake (2.01a) (Qt 4.7.3) on: Sat Oct 22 17:32:53 2011
|
||||
# Generated by qmake (2.01a) (Qt 4.7.3) on: Sun Oct 23 18:21:18 2011
|
||||
# Project: Unuk-QT.pro
|
||||
# Template: app
|
||||
# Command: /usr/bin/qmake-qt4 -spec /usr/share/qt4/mkspecs/linux-g++ CONFIG+=debug -o Makefile Unuk-QT.pro
|
||||
@ -50,7 +50,8 @@ SOURCES = ../src/libUnuk/Vec2.cpp \
|
||||
../src/Unuk/Player.cpp \
|
||||
../src/Unuk/main.cpp \
|
||||
../src/Unuk/Game.cpp \
|
||||
../src/libUnuk/Entity.cpp
|
||||
../src/libUnuk/Entity.cpp \
|
||||
../src/libUnuk/Input.cpp
|
||||
OBJECTS = Vec2.o \
|
||||
Sprite.o \
|
||||
ImageLoader.o \
|
||||
@ -58,7 +59,8 @@ OBJECTS = Vec2.o \
|
||||
Player.o \
|
||||
main.o \
|
||||
Game.o \
|
||||
Entity.o
|
||||
Entity.o \
|
||||
Input.o
|
||||
DIST = /usr/share/qt4/mkspecs/common/g++.conf \
|
||||
/usr/share/qt4/mkspecs/common/unix.conf \
|
||||
/usr/share/qt4/mkspecs/common/linux.conf \
|
||||
@ -158,7 +160,7 @@ qmake: FORCE
|
||||
|
||||
dist:
|
||||
@$(CHK_DIR_EXISTS) .tmp/Unuk-QT1.0.0 || $(MKDIR) .tmp/Unuk-QT1.0.0
|
||||
$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/Unuk-QT1.0.0/ && $(COPY_FILE) --parents ../src/libUnuk/Vec2.h ../src/libUnuk/ImageLoader.h ../src/libUnuk/Sprite.h ../src/libUnuk/Debug.h ../src/Libs/wglext.h ../src/Libs/glxext.h ../src/Unuk/Game.h ../src/Unuk/Player.h ../src/libUnuk/KeyboardInterface.h ../src/libUnuk/XKeyboardInterface.h ../src/libUnuk/Static.h ../src/libUnuk/UnukWindow.h ../src/libUnuk/Geometry.h ../src/libUnuk/Entity.h ../src/libUnuk/EntityType.h .tmp/Unuk-QT1.0.0/ && $(COPY_FILE) --parents ../src/libUnuk/Vec2.cpp ../src/libUnuk/Sprite.cpp ../src/libUnuk/ImageLoader.cpp ../src/libUnuk/Debug.cpp ../src/Unuk/Player.cpp ../src/Unuk/main.cpp ../src/Unuk/Game.cpp ../src/libUnuk/Entity.cpp .tmp/Unuk-QT1.0.0/ && (cd `dirname .tmp/Unuk-QT1.0.0` && $(TAR) Unuk-QT1.0.0.tar Unuk-QT1.0.0 && $(COMPRESS) Unuk-QT1.0.0.tar) && $(MOVE) `dirname .tmp/Unuk-QT1.0.0`/Unuk-QT1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/Unuk-QT1.0.0
|
||||
$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/Unuk-QT1.0.0/ && $(COPY_FILE) --parents ../src/libUnuk/Vec2.h ../src/libUnuk/ImageLoader.h ../src/libUnuk/Sprite.h ../src/libUnuk/Debug.h ../src/Libs/wglext.h ../src/Libs/glxext.h ../src/Unuk/Game.h ../src/Unuk/Player.h ../src/libUnuk/KeyboardInterface.h ../src/libUnuk/XKeyboardInterface.h ../src/libUnuk/Static.h ../src/libUnuk/UnukWindow.h ../src/libUnuk/Geometry.h ../src/libUnuk/Entity.h ../src/libUnuk/EntityType.h ../src/libUnuk/Input.h .tmp/Unuk-QT1.0.0/ && $(COPY_FILE) --parents ../src/libUnuk/Vec2.cpp ../src/libUnuk/Sprite.cpp ../src/libUnuk/ImageLoader.cpp ../src/libUnuk/Debug.cpp ../src/Unuk/Player.cpp ../src/Unuk/main.cpp ../src/Unuk/Game.cpp ../src/libUnuk/Entity.cpp ../src/libUnuk/Input.cpp .tmp/Unuk-QT1.0.0/ && (cd `dirname .tmp/Unuk-QT1.0.0` && $(TAR) Unuk-QT1.0.0.tar Unuk-QT1.0.0 && $(COMPRESS) Unuk-QT1.0.0.tar) && $(MOVE) `dirname .tmp/Unuk-QT1.0.0`/Unuk-QT1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/Unuk-QT1.0.0
|
||||
|
||||
|
||||
clean:compiler_clean
|
||||
@ -242,6 +244,9 @@ Entity.o: ../src/libUnuk/Entity.cpp ../src/libUnuk/Entity.h \
|
||||
../src/libUnuk/Static.h
|
||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Entity.o ../src/libUnuk/Entity.cpp
|
||||
|
||||
Input.o: ../src/libUnuk/Input.cpp ../src/libUnuk/Input.h
|
||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Input.o ../src/libUnuk/Input.cpp
|
||||
|
||||
####### Install
|
||||
|
||||
install: FORCE
|
||||
|
BIN
Unuk-QT/Unuk-QT
BIN
Unuk-QT/Unuk-QT
Binary file not shown.
@ -21,7 +21,8 @@ HEADERS += ../src/libUnuk/Vec2.h \
|
||||
../src/libUnuk/UnukWindow.h \
|
||||
../src/libUnuk/Geometry.h \
|
||||
../src/libUnuk/Entity.h \
|
||||
../src/libUnuk/EntityType.h
|
||||
../src/libUnuk/EntityType.h \
|
||||
../src/libUnuk/Input.h
|
||||
SOURCES += ../src/libUnuk/Vec2.cpp \
|
||||
../src/libUnuk/Sprite.cpp \
|
||||
../src/libUnuk/ImageLoader.cpp \
|
||||
@ -29,4 +30,5 @@ SOURCES += ../src/libUnuk/Vec2.cpp \
|
||||
../src/Unuk/Player.cpp \
|
||||
../src/Unuk/main.cpp \
|
||||
../src/Unuk/Game.cpp \
|
||||
../src/libUnuk/Entity.cpp
|
||||
../src/libUnuk/Entity.cpp \
|
||||
../src/libUnuk/Input.cpp
|
||||
|
@ -76,7 +76,7 @@
|
||||
<valuemap type="QVariantMap">
|
||||
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value>
|
||||
<valuelist key="abstractProcess.Environment" type="QVariantList">
|
||||
<value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-jZvtFgh4Q8,guid=64951d68d90161d18293293f00000185</value>
|
||||
<value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-4UYrGe6jeO,guid=40a924bb0ee270060bcf5bef0012a938</value>
|
||||
<value type="QString">DISPLAY=:0</value>
|
||||
<value type="QString">HOME=/home/allanis</value>
|
||||
<value type="QString">HUSHLOGIN=FALSE</value>
|
||||
@ -89,17 +89,17 @@
|
||||
<value type="QString">QTDIR=/usr/share/qt4</value>
|
||||
<value type="QString">SHELL=/bin/bash</value>
|
||||
<value type="QString">SHLVL=1</value>
|
||||
<value type="QString">SSH_AGENT_PID=4618</value>
|
||||
<value type="QString">SSH_AUTH_SOCK=/tmp/ssh-GLBfmvFD4589/agent.4589</value>
|
||||
<value type="QString">SSH_AGENT_PID=23095</value>
|
||||
<value type="QString">SSH_AUTH_SOCK=/tmp/ssh-cvzHtqq23070/agent.23070</value>
|
||||
<value type="QString">TERM=linux</value>
|
||||
<value type="QString">USER=allanis</value>
|
||||
<value type="QString">WINDOWPATH=7</value>
|
||||
<value type="QString">WINDOWPATH=8</value>
|
||||
<value type="QString">XAUTHORITY=/home/allanis/.Xauthority</value>
|
||||
<value type="QString">XDG_SESSION_COOKIE=6de6dd7b78e791242262c6460000012e-1318168661.569853-1852884431</value>
|
||||
<value type="QString">XDG_SESSION_COOKIE=6de6dd7b78e791242262c6460000012e-1319391241.38441-1429138967</value>
|
||||
<value type="QString">_=/usr/bin/startx</value>
|
||||
</valuelist>
|
||||
<valuelist key="abstractProcess.arguments" type="QVariantList">
|
||||
<value type="QString">/home/allanis/Unuk/trunk/Unuk-QT/Unuk-QT.pro</value>
|
||||
<value type="QString">/home/allanis/Unuk/Unuk-QT/Unuk-QT.pro</value>
|
||||
<value type="QString">-spec</value>
|
||||
<value type="QString">linux-g++</value>
|
||||
<value type="QString">-r</value>
|
||||
@ -107,7 +107,7 @@
|
||||
</valuelist>
|
||||
<value key="abstractProcess.command" type="QString">/usr/bin/qmake-qt4</value>
|
||||
<value key="abstractProcess.enabled" type="bool">false</value>
|
||||
<value key="abstractProcess.workingDirectory" type="QString">/home/allanis/Unuk/trunk/Unuk-QT</value>
|
||||
<value key="abstractProcess.workingDirectory" type="QString">/home/allanis/Unuk/Unuk-QT</value>
|
||||
</valuemap>
|
||||
</data>
|
||||
<data>
|
||||
@ -115,7 +115,7 @@
|
||||
<valuemap type="QVariantMap">
|
||||
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value>
|
||||
<valuelist key="abstractProcess.Environment" type="QVariantList">
|
||||
<value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-jZvtFgh4Q8,guid=64951d68d90161d18293293f00000185</value>
|
||||
<value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-4UYrGe6jeO,guid=40a924bb0ee270060bcf5bef0012a938</value>
|
||||
<value type="QString">DISPLAY=:0</value>
|
||||
<value type="QString">HOME=/home/allanis</value>
|
||||
<value type="QString">HUSHLOGIN=FALSE</value>
|
||||
@ -128,13 +128,13 @@
|
||||
<value type="QString">QTDIR=/usr/share/qt4</value>
|
||||
<value type="QString">SHELL=/bin/bash</value>
|
||||
<value type="QString">SHLVL=1</value>
|
||||
<value type="QString">SSH_AGENT_PID=4618</value>
|
||||
<value type="QString">SSH_AUTH_SOCK=/tmp/ssh-GLBfmvFD4589/agent.4589</value>
|
||||
<value type="QString">SSH_AGENT_PID=23095</value>
|
||||
<value type="QString">SSH_AUTH_SOCK=/tmp/ssh-cvzHtqq23070/agent.23070</value>
|
||||
<value type="QString">TERM=linux</value>
|
||||
<value type="QString">USER=allanis</value>
|
||||
<value type="QString">WINDOWPATH=7</value>
|
||||
<value type="QString">WINDOWPATH=8</value>
|
||||
<value type="QString">XAUTHORITY=/home/allanis/.Xauthority</value>
|
||||
<value type="QString">XDG_SESSION_COOKIE=6de6dd7b78e791242262c6460000012e-1318168661.569853-1852884431</value>
|
||||
<value type="QString">XDG_SESSION_COOKIE=6de6dd7b78e791242262c6460000012e-1319391241.38441-1429138967</value>
|
||||
<value type="QString">_=/usr/bin/startx</value>
|
||||
</valuelist>
|
||||
<value key="abstractProcess.IgnoreReturnValue" type="bool">false</value>
|
||||
@ -143,7 +143,7 @@
|
||||
</valuelist>
|
||||
<value key="abstractProcess.command" type="QString">/usr/bin/make</value>
|
||||
<value key="abstractProcess.enabled" type="bool">true</value>
|
||||
<value key="abstractProcess.workingDirectory" type="QString">/home/allanis/Unuk/trunk/Unuk-QT</value>
|
||||
<value key="abstractProcess.workingDirectory" type="QString">/home/allanis/Unuk/Unuk-QT</value>
|
||||
</valuemap>
|
||||
</data>
|
||||
<data>
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "SDL/SDL.h"
|
||||
#include "Game.h"
|
||||
#include "Player.h"
|
||||
#include "../libUnuk/Input.h"
|
||||
#include "../libUnuk/Sprite.h"
|
||||
#include "../libUnuk/Debug.h"
|
||||
|
||||
@ -61,7 +62,9 @@ void Game::Render(void) {
|
||||
glFlush();
|
||||
//glutSwapBuffers();
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
|
||||
if(KeyStillDown(SDLK_w)) {Debug::logger->message("Werks"); }
|
||||
|
||||
// Get frames per second.
|
||||
frames++;
|
||||
{
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <GL/glu.h>
|
||||
#include "SDL/SDL.h"
|
||||
#include "Game.h"
|
||||
#include "../libUnuk/Input.h"
|
||||
#include "../libUnuk/Debug.h"
|
||||
|
||||
// Screen width, height, and bit depth.
|
||||
@ -175,6 +176,7 @@ int main() {
|
||||
Debug::logger->message("\n\n-----Logic-----");
|
||||
|
||||
while(!done) {
|
||||
CreateInput();
|
||||
// Time to poll events.
|
||||
while(SDL_PollEvent(&event)) {
|
||||
switch(event.type) {
|
||||
|
82
src/libUnuk/Input.cpp
Normal file
82
src/libUnuk/Input.cpp
Normal file
@ -0,0 +1,82 @@
|
||||
#include <string.h>
|
||||
#include "Input.h"
|
||||
|
||||
static mouse_t mouse;
|
||||
static keyboard_t keyboard;
|
||||
|
||||
bool _curr_key(int index) {
|
||||
return(keyboard.keys[index] != 0);
|
||||
}
|
||||
|
||||
bool _old_key(int index) {
|
||||
return(keyboard.oldKeys[index] != 0);
|
||||
}
|
||||
|
||||
bool _curr_mouse(int button) {
|
||||
return((mouse.buttons * SDL_BUTTON(button)) != 0);
|
||||
}
|
||||
|
||||
bool _old_mouse(int button) {
|
||||
return((mouse.oldButtons & SDL_BUTTON(button)) != 0);
|
||||
}
|
||||
|
||||
bool CreateInput(void) {
|
||||
memset(&keyboard, 0, sizeof(keyboard_t));
|
||||
memset(&mouse, 0, sizeof(mouse_t));
|
||||
SDL_PumpEvents();
|
||||
SDL_PumpEvents();
|
||||
unsigned char* tempKeys = SDL_GetKeyState(&keyboard.keycount);
|
||||
keyboard.keys = (unsigned char*)malloc(sizeof(char) * keyboard.keycount);
|
||||
keyboard.oldKeys = (unsigned char*)malloc(sizeof(char) * keyboard.keycount);
|
||||
|
||||
memcpy(keyboard.keys, tempKeys, sizeof(char) * keyboard.keycount);
|
||||
mouse.buttons = SDL_GetMouseState(&mouse.dx, &mouse.dy);
|
||||
return true;
|
||||
}
|
||||
|
||||
void UpdateInput(void) {
|
||||
SDL_PumpEvents();
|
||||
keyboard.lastChar = -1;
|
||||
mouse.oldx = mouse.dx;
|
||||
mouse.oldy = mouse.dy;
|
||||
mouse.oldButtons = SDL_GetMouseState(&mouse.dx, &mouse.dy);
|
||||
|
||||
memcpy(keyboard.oldKeys, keyboard.keys, sizeof(char) * keyboard.keycount);
|
||||
|
||||
unsigned char *tmp = SDL_GetKeyState(&keyboard.keycount);
|
||||
memcpy(keyboard.keys, tmp, sizeof(char) * keyboard.keycount);
|
||||
|
||||
keyboard.mods = SDL_GetModState();
|
||||
|
||||
SDL_Event event;
|
||||
while(SDL_PollEvent(&event)) {
|
||||
if(event.type == SDL_KEYDOWN) {
|
||||
keyboard.lastChar = event.key.keysym.sym;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char GetKey(void) {
|
||||
if(keyboard.lastChar != -1)
|
||||
return keyboard.lastChar;
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int GetX(void) { return mouse.dx; }
|
||||
unsigned int GetY(void) { return mouse.dy; }
|
||||
unsigned int GetOldX(void) { return mouse.oldx; }
|
||||
unsigned int GetOldY(void) { return mouse.oldy; }
|
||||
unsigned int GetMods(void) { return keyboard.mods; }
|
||||
bool KeyDown(int index) { return(_curr_key(index) && !_old_key(index)); }
|
||||
bool KeyStillDown(int index) { return(_curr_key(index) && _old_key(index)); }
|
||||
bool KeyUp(int index) { return(!_curr_key(index) && _old_key(index)); }
|
||||
bool KeyStillUp(int index) { return(!_curr_key(index) && !_old_key(index)); }
|
||||
bool MouseDown(int button) { return(_curr_mouse(button) && !_old_mouse(button)); }
|
||||
bool MouseStillDown(int button) { return(_curr_mouse(button) && _old_mouse(button)); }
|
||||
bool MouseUp(int button) { return(!_curr_mouse(button) && _old_mouse(button)); }
|
||||
bool MouseStillUp(int button) { return(!_curr_mouse(button) && !_old_mouse(button)); }
|
||||
|
||||
void DestroyInput(void) {
|
||||
free(keyboard.keys);
|
||||
free(keyboard.oldKeys);
|
||||
}
|
46
src/libUnuk/Input.h
Normal file
46
src/libUnuk/Input.h
Normal file
@ -0,0 +1,46 @@
|
||||
#ifndef _INPUT_H_
|
||||
#define _INPUT_H_
|
||||
#include <SDL/SDL.h>
|
||||
|
||||
typedef struct mouse_s {
|
||||
int dx, dy;
|
||||
int oldx, oldy;
|
||||
unsigned int buttons;
|
||||
unsigned int oldButtons;
|
||||
} mouse_t;
|
||||
|
||||
typedef struct keyboard_s {
|
||||
unsigned char *keys;
|
||||
unsigned char *oldKeys;
|
||||
int keycount;
|
||||
int lastChar;
|
||||
unsigned int mods;
|
||||
} keyboard_t;
|
||||
|
||||
typedef struct input_s {
|
||||
mouse_t mouse;
|
||||
keyboard_t keyboard;
|
||||
} input_t;
|
||||
|
||||
bool CreateInput(void);
|
||||
void UpdateInput(void);
|
||||
|
||||
char GetKey(void);
|
||||
|
||||
unsigned int GetX(void);
|
||||
unsigned int GetY(void);
|
||||
unsigned int GetOldX(void);
|
||||
unsigned int GetOldY(void);
|
||||
unsigned int GetMods(void);
|
||||
bool KeyDown(int index);
|
||||
bool KeyStillDown(int index);
|
||||
bool KeyUp(int index);
|
||||
bool KeyStillUp(int index);
|
||||
bool MouseDown(int button);
|
||||
bool MouseStillDown(int button);
|
||||
bool MouseUp(int button);
|
||||
bool MouseStillUp(int button);
|
||||
|
||||
void DestroyInput(void);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user