Skip to content

Commit

Permalink
64-bit|Event API|Client|libcommon: Pass symbolic event pointer as a 6…
Browse files Browse the repository at this point in the history
…4-bit number

Debugging shows that under some circumstances, the pointer's most
significant four bytes were all 0xff. This hints that when converting
from signed 32-bit to unsigned 64-bit, one should have manually cleared
the top bytes.

An anonymous union is more elegant and ensures that the intended
behavior occurs.

(-O3, Apple LLVM version 6.1.0 (clang-602.0.49) 64-bit)
  • Loading branch information
skyjake committed May 21, 2015
1 parent 264b0c2 commit 5ee0437
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
11 changes: 8 additions & 3 deletions doomsday/apps/api/api_event.h
Expand Up @@ -32,7 +32,7 @@ typedef enum {
EV_JOY_SLIDER, ///< Joystick sliders.
EV_JOY_BUTTON,
EV_POV,
EV_SYMBOLIC, ///< Symbol text pointed to by data1+data2.
EV_SYMBOLIC, ///< Symbol text pointed to by data_u64 (data1+data2).
EV_FOCUS, ///< Change in game window focus (data1=gained, data2=windowID).
NUM_EVENT_TYPES
} evtype_t;
Expand All @@ -49,8 +49,13 @@ typedef enum {
typedef struct event_s {
evtype_t type;
evstate_t state; ///< Only used with digital controls.
int data1; ///< Keys/mouse/joystick buttons.
int data2; ///< Mouse/joystick x move.
union {
struct {
int data1; ///< Keys/mouse/joystick buttons.
int data2; ///< Mouse/joystick x move.
};
uint64_t data_u64;
};
int data3; ///< Mouse/joystick y move.
int data4;
int data5;
Expand Down
5 changes: 2 additions & 3 deletions doomsday/apps/client/src/ui/inputsystem.cpp
Expand Up @@ -221,7 +221,7 @@ static char const *allocEventString(char const *str)
DENG2_ASSERT(eventStringRover >= 0 && eventStringRover < MAXEVENTS);
M_Free(eventStrings[eventStringRover]);
char const *returnValue = eventStrings[eventStringRover] = strdup(str);

if(++eventStringRover >= MAXEVENTS)
{
eventStringRover = 0;
Expand Down Expand Up @@ -1181,8 +1181,7 @@ bool InputSystem::convertEvent(ddevent_t const &from, event_t &to) // static
to.type = EV_SYMBOLIC;
#ifdef __64BIT__
ASSERT_64BIT(from.symbolic.name);
to.data1 = (int)(((uint64_t) from.symbolic.name) & 0xffffffff); // low dword
to.data2 = (int)(((uint64_t) from.symbolic.name) >> 32); // high dword
to.data_u64 = (duint64) from.symbolic.name;
#else
ASSERT_NOT_64BIT(from.symbolic.name);
to.data1 = (int) from.symbolic.name;
Expand Down
Expand Up @@ -328,7 +328,7 @@ static String symbolicDescriptor(event_t const &event)
#ifndef __64BIT__
String symbol = (char const *) event.data1;
#else
String symbol = (char const *)( (duint64(event.data2) << 32) | duint64(event.data1) );
String symbol = (char const *) event.data_u64;
#endif
if(symbol.beginsWith("echo-"))
{
Expand Down

0 comments on commit 5ee0437

Please sign in to comment.