fixes in Mac modifier keys, remove enet/lua tests

This commit is contained in:
Erwin Coumans
2015-04-16 17:35:34 -07:00
parent bf39570ff3
commit 889cbdc0ef
15 changed files with 75 additions and 580 deletions

View File

@@ -94,7 +94,7 @@
{
'ARCHS = "$(ARCHS_STANDARD_32_BIT) $(ARCHS_STANDARD_64_BIT)"',
'VALID_ARCHS = "x86_64 i386"',
-- 'SDKROOT = "macosx10.9"',
'SDKROOT = "macosx10.9"',
}
end

View File

@@ -29,7 +29,7 @@ struct DrawGridData
struct CommonGraphicsApp
{
class b3gWindowInterface* m_window;
class CommonWindowInterface* m_window;
struct CommonRenderInterface* m_renderer;
struct CommonParameterInterface* m_parameterInterface;
struct Common2dCanvasInterface* m_2dCanvasInterface;
@@ -94,8 +94,8 @@ struct CommonGraphicsApp
{
CommonCameraInterface* camera = m_renderer->getActiveCamera();
bool isAltPressed = m_window->isModifiedKeyPressed(B3G_ALT);
bool isControlPressed = m_window->isModifiedKeyPressed(B3G_CONTROL);
bool isAltPressed = m_window->isModifierKeyPressed(B3G_ALT);
bool isControlPressed = m_window->isModifierKeyPressed(B3G_CONTROL);
if (isAltPressed || isControlPressed)

View File

@@ -249,7 +249,6 @@ struct CommonMultiBodyBase : public ExampleInterface
virtual bool mouseButtonCallback(int button, int state, float x, float y)
{
CommonRenderInterface* renderer = m_guiHelper->getRenderInterface();
if (!renderer)
@@ -258,11 +257,12 @@ struct CommonMultiBodyBase : public ExampleInterface
return false;
}
b3gWindowInterface* window = m_guiHelper->getAppInterface()->m_window;
CommonWindowInterface* window = m_guiHelper->getAppInterface()->m_window;
if (state==1)
{
if(button==0 && (!window->isModifiedKeyPressed(B3G_ALT) && !window->isModifiedKeyPressed(B3G_CONTROL) ))
if(button==0 && (!window->isModifierKeyPressed(B3G_ALT) && !window->isModifierKeyPressed(B3G_CONTROL) ))
{
btVector3 camPos;
renderer->getActiveCamera()->getCameraPosition(camPos);

View File

@@ -239,7 +239,6 @@ struct CommonRigidBodyBase : public ExampleInterface
virtual bool mouseButtonCallback(int button, int state, float x, float y)
{
CommonRenderInterface* renderer = m_guiHelper->getRenderInterface();
if (!renderer)
@@ -248,11 +247,38 @@ struct CommonRigidBodyBase : public ExampleInterface
return false;
}
b3gWindowInterface* window = m_guiHelper->getAppInterface()->m_window;
CommonWindowInterface* window = m_guiHelper->getAppInterface()->m_window;
#if 0
if (window->isModifierKeyPressed(B3G_ALT))
{
printf("ALT pressed\n");
} else
{
printf("NO ALT pressed\n");
}
if (window->isModifierKeyPressed(B3G_SHIFT))
{
printf("SHIFT pressed\n");
} else
{
printf("NO SHIFT pressed\n");
}
if (window->isModifierKeyPressed(B3G_CONTROL))
{
printf("CONTROL pressed\n");
} else
{
printf("NO CONTROL pressed\n");
}
#endif
if (state==1)
{
if(button==0 && (!window->isModifiedKeyPressed(B3G_ALT) && !window->isModifiedKeyPressed(B3G_CONTROL) ))
if(button==0 && (!window->isModifierKeyPressed(B3G_ALT) && !window->isModifierKeyPressed(B3G_CONTROL) ))
{
btVector3 camPos;
renderer->getActiveCamera()->getCameraPosition(camPos);

View File

@@ -67,11 +67,11 @@ struct b3gWindowConstructionInfo
};
class b3gWindowInterface
class CommonWindowInterface
{
public:
virtual ~b3gWindowInterface()
virtual ~CommonWindowInterface()
{
}
@@ -96,7 +96,7 @@ class b3gWindowInterface
virtual void endRendering()=0;
virtual bool isModifiedKeyPressed(int key) = 0;
virtual bool isModifierKeyPressed(int key) = 0;
virtual void setMouseMoveCallback(b3MouseMoveCallback mouseCallback)=0;
virtual b3MouseMoveCallback getMouseMoveCallback()=0;

View File

@@ -36,7 +36,7 @@
#include "LinearMath/btIDebugDraw.h"
CommonGraphicsApp* s_app=0;
b3gWindowInterface* s_window = 0;
CommonWindowInterface* s_window = 0;
CommonParameterInterface* s_parameterInterface=0;
CommonRenderInterface* s_instancingRenderer=0;
OpenGLGuiHelper* s_guiHelper=0;

View File

@@ -867,7 +867,7 @@ void ForkLiftDemo::resetForklift()
bool ForkLiftDemo::keyboardCallback(int key, int state)
{
bool handled = false;
bool isShiftPressed = m_guiHelper->getAppInterface()->m_window->isModifiedKeyPressed(B3G_SHIFT);
bool isShiftPressed = m_guiHelper->getAppInterface()->m_window->isModifierKeyPressed(B3G_SHIFT);
if (state)
{

View File

@@ -5,7 +5,7 @@
#define b3gDefaultOpenGLWindow MacOpenGLWindow
class MacOpenGLWindow : public b3gWindowInterface
class MacOpenGLWindow : public CommonWindowInterface
{
struct MacOpenGLWindowInternalData* m_internalData;
float m_mouseX;
@@ -40,7 +40,7 @@ public:
void runMainLoop();
virtual bool isModifiedKeyPressed(int key);
virtual bool isModifierKeyPressed(int key);
void setMouseButtonCallback(b3MouseButtonCallback mouseCallback)
{

View File

@@ -12,7 +12,12 @@
#include <string.h>
enum
{
MY_MAC_ALTKEY=1,
MY_MAC_SHIFTKEY=2,
MY_MAC_CONTROL_KEY=4
};
/* report GL errors, if any, to stderr */
static void checkError(const char *functionName)
@@ -222,7 +227,7 @@ MacOpenGLWindow::~MacOpenGLWindow()
}
bool MacOpenGLWindow::isModifiedKeyPressed(int key)
bool MacOpenGLWindow::isModifierKeyPressed(int key)
{
bool isPressed = false;
@@ -230,17 +235,17 @@ bool MacOpenGLWindow::isModifiedKeyPressed(int key)
{
case B3G_ALT:
{
isPressed = ((m_modifierFlags && NSAlternateKeyMask)!=0);
isPressed = ((m_modifierFlags & MY_MAC_ALTKEY)!=0);
break;
};
case B3G_SHIFT:
{
isPressed = ((m_modifierFlags && NSShiftKeyMask)!=0);
isPressed = ((m_modifierFlags & MY_MAC_SHIFTKEY)!=0);
break;
};
case B3G_CONTROL:
{
isPressed = ((m_modifierFlags && NSControlKeyMask )!=0);
isPressed = ((m_modifierFlags & MY_MAC_CONTROL_KEY )!=0);
break;
};
@@ -772,37 +777,43 @@ void MacOpenGLWindow::startRendering()
if ((modifiers & NSShiftKeyMask))
{
m_keyboardCallback(B3G_SHIFT,1);
m_modifierFlags |= MY_MAC_SHIFTKEY;
}else
{
if (m_modifierFlags&NSShiftKeyMask)
if (m_modifierFlags& MY_MAC_SHIFTKEY)
{
m_keyboardCallback(B3G_SHIFT,0);
m_modifierFlags &= ~MY_MAC_SHIFTKEY;
}
}
if (modifiers & NSControlKeyMask)
{
m_keyboardCallback(B3G_CONTROL,1);
m_modifierFlags |= MY_MAC_CONTROL_KEY;
} else
{
if (m_modifierFlags&NSControlKeyMask)
if (m_modifierFlags&MY_MAC_CONTROL_KEY)
{
m_keyboardCallback(B3G_CONTROL,0);
m_modifierFlags &= ~MY_MAC_CONTROL_KEY;
}
}
if (modifiers & NSAlternateKeyMask)
{
m_keyboardCallback(B3G_ALT,1);
m_modifierFlags |= MY_MAC_ALTKEY;
} else
{
if (m_modifierFlags&NSAlternateKeyMask)
if (m_modifierFlags&MY_MAC_ALTKEY)
{
m_keyboardCallback(B3G_ALT,0);
m_modifierFlags &= ~MY_MAC_ALTKEY;
}
}
//handle NSCommandKeyMask
}
m_modifierFlags=modifiers;
}
if ([event type] == NSKeyUp)
{

View File

@@ -1,178 +0,0 @@
#include <stdio.h>
#include <enet/enet.h>
int main(int argc, char* argv[])
{
printf("starting client (and server)\n");
if (enet_initialize () != 0)
{
fprintf (stderr, "An error occurred while initializing ENet.\n");
return EXIT_FAILURE;
}
atexit (enet_deinitialize);
ENetAddress selfaddress;
selfaddress.host = ENET_HOST_ANY;
/* Bind the server to port 1111. */
selfaddress.port = 1111;
ENetHost * client=0;
while (!client)
{
client = enet_host_create (&selfaddress/* create a client host */,
32 /* only 32 connections */,
2 /* allow up 2 channels to be used, 0 and 1 */,
0/*57600 / 8 56K modem with 56 Kbps downstream bandwidth */,
0 /* 14400 / 8 56K modem with 14 Kbps upstream bandwidth */);
if (client == NULL)
{
selfaddress.port++;
}
}
if (client == NULL)
{
fprintf (stderr,
"An error occurred while trying to create an ENet client host.\n");
exit (EXIT_FAILURE);
}
ENetAddress dedicatedserveraddress;
ENetEvent event;
ENetPeer* dedicatedpeer=0;
ENetPeer* natpeer=0;
/* Connect to some.server.net:1234. */
enet_address_set_host (& dedicatedserveraddress, "bulletphysics.org");//localhost");
dedicatedserveraddress.port = 1234;
/* Initiate the connection, allocating the two channels 0 and 1. */
dedicatedpeer = enet_host_connect (client, & dedicatedserveraddress, 2, 0);
if (dedicatedpeer == NULL)
{
fprintf (stderr, "No available peers for initiating an ENet connection.\n");
exit (EXIT_FAILURE);
}
/* Wait up to 5 seconds for the connection attempt to succeed. */
if (enet_host_service (client, & event, 5000) > 0 &&
event.type == ENET_EVENT_TYPE_CONNECT)
{
char servername[1024];
enet_address_get_host(&dedicatedserveraddress,servername, 1024);
char serverinfo[1024];
sprintf(serverinfo,"Connection to %s:%d succeeded", servername,dedicatedserveraddress.port);
puts (serverinfo);
/////....
/* Wait up to 1000 milliseconds for an event. */
while (enet_host_service (client, & event, 1000000000) > 0)
{
if (natpeer)
{
/* Create a reliable packet of size 7 containing "packet\0" */
ENetPacket * packet = enet_packet_create ("packet",
strlen ("packet") + 1,
ENET_PACKET_FLAG_RELIABLE);
/* Extend the packet so and append the string "foo", so it now */
/* contains "packetfoo\0" */
enet_packet_resize (packet, strlen ("packetfoo") + 1);
strcpy ((char*)& packet -> data [strlen ("packet")], "foo");
/* Send the packet to the peer over channel id 0. */
/* One could also broadcast the packet by */
/* enet_host_broadcast (host, 0, packet); */
enet_peer_send (natpeer, 0, packet);
}
switch (event.type)
{
case ENET_EVENT_TYPE_CONNECT:
printf ("A new client connected from %x:%u.\n",
event.peer -> address.host,
event.peer -> address.port);
/* Store any relevant client information here. */
event.peer -> data = "Client information";
break;
case ENET_EVENT_TYPE_RECEIVE:
printf ("A packet of length %u containing %s was received from %s on channel %u.\n",
event.packet -> dataLength,
event.packet -> data,
event.peer -> data,
event.channelID);
/* Clean up the packet now that we're done using it. */
if (event.packet->dataLength==sizeof(ENetAddress))
{
ENetAddress* address = (ENetAddress*)event.packet->data;
printf("received other client's address from server, connecting...\n");
natpeer = enet_host_connect (client, address, 2, 0);
if (natpeer== NULL)
{
fprintf (stderr, "No available peers for initiating an ENet connection.\n");
exit (EXIT_FAILURE);
}
/* Wait up to 5 seconds for the connection attempt to succeed. */
if (enet_host_service (client, & event, 5000) > 0 &&
event.type == ENET_EVENT_TYPE_CONNECT)
{
puts ("Connection to natpeer succeeded.");
} else
{
enet_peer_reset (natpeer);
puts ("Connection to natpeer failed.");
natpeer=0;
exit(0);
}
}
enet_packet_destroy (event.packet);
break;
case ENET_EVENT_TYPE_DISCONNECT:
printf ("%s disconected.\n", event.peer -> data);
/* Reset the peer's client information. */
event.peer -> data = NULL;
}
}
/* One could just use enet_host_service() instead. */
enet_host_flush (client);//host);
}
else
{
/* Either the 5 seconds are up or a disconnect event was */
/* received. Reset the peer in the event the 5 seconds */
/* had run out without any significant event. */
enet_peer_reset (dedicatedpeer);
puts ("Connection to some.server.net:1234 failed.");
}
enet_host_destroy(client);
return 0;
}

View File

@@ -1,25 +0,0 @@
project ("Test_enet_client")
language "C++"
kind "ConsoleApp"
targetdir "../../../bin"
includedirs {"../../../btgui/enet/include"}
if os.is("Windows") then
defines { "WIN32" }
links {"Ws2_32","Winmm"}
end
if os.is("Linux") then
end
if os.is("MacOSX") then
end
links {"enet"}
files {
"main.cpp",
}

View File

@@ -1,111 +0,0 @@
#include <stdio.h>
#include <enet/enet.h>
ENetPeer* mypeers[2]={0,0};
ENetAddress clientAddresses[2];
int numpeers=0;
int main(int argc, char* argv[])
{
fprintf(stderr,"starting enet dedicated server\n");
if (enet_initialize () != 0)
{
fprintf (stderr, "An error occurred while initializing ENet.\n");
return EXIT_FAILURE;
}
atexit (enet_deinitialize);
ENetAddress address;
ENetHost * server;
/* Bind the server to the default localhost. */
/* A specific host address can be specified by */
/* enet_address_set_host (& address, "x.x.x.x"); */
address.host = ENET_HOST_ANY;
/* Bind the server to port 1234. */
address.port = 1234;
server = enet_host_create (& address /* the address to bind the server host to */,
32 /* allow up to 32 clients and/or outgoing connections */,
2 /* allow up to 2 channels to be used, 0 and 1 */,
0 /* assume any amount of incoming bandwidth */,
0 /* assume any amount of outgoing bandwidth */);
if (server == NULL)
{
fprintf (stderr,
"An error occurred while trying to create an ENet server host.\n");
exit (EXIT_FAILURE);
}
ENetEvent event;
/* Wait up to 10000000 milliseconds for an event. */
while (enet_host_service (server, & event, 10000000) > 0)
{
switch (event.type)
{
case ENET_EVENT_TYPE_CONNECT:
char clientname[1024];
enet_address_get_host(&event.peer -> address,clientname, 1024);
printf ("A new client connected from %s:%u.\n",
clientname,
event.peer -> address.port);
/* Store any relevant client information here. */
event.peer -> data = "Client information";
if (numpeers<2)
{
clientAddresses[numpeers] = event.peer->address;
mypeers[numpeers] = event.peer;
}
numpeers++;
if (numpeers==2)
{
printf("exchanging addresses for NAT punchthrough\n");
//exchange the address info
for (int i=0;i<2;i++)
{
int sz = sizeof(ENetAddress);
/* Create a reliable packet of size 7 containing "packet\0" */
ENetPacket * packet = enet_packet_create (&clientAddresses[i],
sz,
ENET_PACKET_FLAG_RELIABLE);
enet_peer_send (mypeers[1-i], 0, packet);
}
//prepare for the next pair of clients to connect/NAT punchthrough
numpeers=0;
}
break;
case ENET_EVENT_TYPE_RECEIVE:
printf ("A packet of length %u containing %s was received from %s on channel %u.\n",
event.packet -> dataLength,
event.packet -> data,
event.peer -> data,
event.channelID);
/* Clean up the packet now that we're done using it. */
enet_packet_destroy (event.packet);
break;
case ENET_EVENT_TYPE_DISCONNECT:
printf ("%s disconected.\n", event.peer -> data);
/* Reset the peer's client information. */
event.peer -> data = NULL;
}
}
enet_host_destroy(server);
printf("server exited, press <enter> key\n");
getchar();
return 0;
}

View File

@@ -1,26 +0,0 @@
project ("Test_enet_server")
language "C++"
kind "ConsoleApp"
targetdir "../../../bin"
includedirs {"../../../btgui/enet/include"}
if os.is("Windows") then
defines { "WIN32" }
links {"Ws2_32","Winmm"}
end
if os.is("Linux") then
end
if os.is("MacOSX") then
end
links {"enet"}
files {
"main.cpp",
}

View File

@@ -1,179 +0,0 @@
// Some quick experiments to use Lua and C (C++) together
// so Lua can be used to setup the Bullet demos
// See http://csl.name/lua/
// and http://stackoverflow.com/questions/7298642/passing-c-struct-pointer-to-lua-script
#include <iostream>
#include <vector>
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
struct MyTest
{
int m_bla;
MyTest():m_bla(10)
{
}
void methodPrint()
{
printf("t->m_bla=%d\n",m_bla);
}
};
std::vector<MyTest*> gValidPointers;
bool isValidPointer(MyTest* ptr)
{
bool result = false;
for (int i=0;i<gValidPointers.size();i++)
{
if (gValidPointers[i]==ptr)
result = true;
}
return result;
}
bool removeValidPointer(MyTest* ptr)
{
bool result = false;
for (int i=0;i<gValidPointers.size();i++)
{
if (gValidPointers[i]==ptr)
{
gValidPointers[i]=0;
gValidPointers[i] = gValidPointers[gValidPointers.size()-1];
gValidPointers.pop_back();
result = true;
}
}
return result;
}
int my_printTest(lua_State *L)
{
int argc = lua_gettop(L);
if (argc==1)
{
MyTest* tst = (MyTest*) lua_touserdata(L,1);
if (isValidPointer(tst))
{
tst->methodPrint();
} else
{
std::cerr << "error my_printTest called with invalid argument ";
}
}
return 0;
}
int my_createFunction(lua_State *L)
{
int argc = lua_gettop(L);
std::cerr << "-- my_function() called with " << argc
<< " arguments:" << std::endl;
for ( int n=1; n<=argc; ++n ) {
std::cerr << "-- argument " << n << ": "
<< lua_tostring(L, n) << std::endl;
}
MyTest* newTest = new MyTest();
gValidPointers.push_back(newTest);
lua_pushlightuserdata (L, newTest);
return 1; // number of return values
}
int my_deleteFunction(lua_State *L)
{
int argc = lua_gettop(L);
if (argc==1)
{
MyTest* tst = (MyTest*) lua_touserdata(L,1);
if (tst)
{
bool result = removeValidPointer(tst);
if (result)
{
delete tst;
} else
{
std::cerr << "error my_deleteFunction called with invalid pointer argument ";
}
} else
{
std::cerr << "error my_deleteFunction called with non-pointer argument ";
}
}
return 0; // number of return values
}
void report_errors(lua_State *L, int status)
{
if ( status!=0 ) {
std::cerr << "-- " << lua_tostring(L, -1) << std::endl;
lua_pop(L, 1); // remove error message
}
}
int main(int argc, char** argv)
{
for ( int n=1; n<argc; ++n ) {
const char* file = argv[n];
lua_State *L = luaL_newstate();
luaopen_io(L); // provides io.*
luaopen_base(L);
luaopen_table(L);
luaopen_string(L);
luaopen_math(L);
//luaopen_package(L);
luaL_openlibs(L);
// make my_function() available to Lua programs
lua_register(L, "my_createFunction", my_createFunction);
lua_register(L, "my_printTest", my_printTest);
lua_register(L, "my_deleteFunction", my_deleteFunction);
std::cerr << "-- Loading file: " << file << std::endl;
int s = luaL_loadfile(L, file);
if ( s==0 ) {
// execute Lua program
s = lua_pcall(L, 0, LUA_MULTRET, 0);
}
report_errors(L, s);
lua_close(L);
std::cerr << std::endl;
}
return 0;
}

View File

@@ -1,23 +0,0 @@
project ("Test_Lua")
language "C++"
kind "ConsoleApp"
targetdir "../../bin"
includedirs {"../../btgui/lua-5.2.3/src"}
if os.is("Windows") then
end
if os.is("Linux") then
end
if os.is("MacOSX") then
end
links {"lua-5.2.3"}
files {
"main.cpp",
}