Commit Graph

14 Commits

Author SHA1 Message Date
Campbell Barton
f5e020a7a6 PyAPI: fix memory leaks in dictionary assignment
Thanks to Kévin Dietrich for spotting driver leak,
checked other uses of PyDict_SetItem and found more.
2016-07-14 17:30:52 +10:00
Campbell Barton
3fd388fb06 py api cleanup, replace use...
- PyLong_FromSsize_t --> PyLong_FromLong
- PyLong_AsSsize_t --> PyLong_AsLong

In all places except for those where python api expects PySsize_t (index lookups mainly).

- use PyBool_FromLong in a few areas of the BGE.
- fix incorrect assumption in the BGE that PySequence_Check() means PySequence_Fast_ functions can be used.
2012-11-21 02:28:36 +00:00
Campbell Barton
2fb8292005 style cleanup 2012-09-16 04:58:18 +00:00
Dalai Felinto
7016538974 bge.logic.keyboard.getClipboard() and .setClipboard methods
the idea of using methods instead of attributes is to avoid users abusing of the system calls.

Thanks Campbell Barton for reviewing and small corrections
2012-06-27 21:57:33 +00:00
Mitchell Stokes
57d48d4493 Committing patch "[#29763] Adding an active_events property to SCA_PythonKeyboard and SCA_PythonMouse"
Here is the description:
As the summary says, this patch adds a new event to both SCA_PythonKeyboard and SCA_PythonMouse. This property is similar to the events property that both have, but it only returns events which are not KX_NO_INPUTSTATUS. This moves the "no input" check from Python to C, which gave my input handling code a 2x speed up. Python sucks (performance-wise) with iterating lists and SCA_PythonKeyboard has close to 200 events (I think something like 177, but I don't know for sure).
2012-01-22 05:45:56 +00:00
Campbell Barton
4a04f72069 remove $Id: tags after discussion on the mailign list: http://markmail.org/message/fp7ozcywxum3ar7n 2011-10-23 17:52:20 +00:00
Nathan Letwory
344caea0b3 doxygen: gameengine/GameLogic tagged. 2011-02-25 13:32:11 +00:00
Nathan Letwory
5b607701a7 doxygen: prevent GPL license block from being parsed as doxygen comment. 2011-02-23 10:52:22 +00:00
Campbell Barton
0876fce009 rename and negate DISABLE_PYTHON --> WITH_PYTHON 2010-10-31 04:11:39 +00:00
Mitchell Stokes
57e0d677c6 Committing patch [#23489] add method getEventStatus() to PythonKeyboard and PythonMouse by Geoff Gollmer (gomer)
This patch makes SCA_PythonKeyboard.events and SCA_PythonMouse.events return a dictionary of all inputs (including inactive) instead of a list of active inputs.

Example usage:
import bge

if bge.logic.keyboard.events[bge.events.SPACEBAR] = bge.logic.KX_INPUT_JUST_ACTIVATED:
  print("Spacebar pressed!")

A couple of changes to the patch:
  * Wrap python stuff in #ifndef DISABLE_PYTHON
  * Clear and decref m_event_dict in the destructors

A couple of things not related to the patch:
  * Made member variables private
  * Removed a commented out (and no longer used) method (SCA_PythonMouse.show())
2010-08-30 00:18:50 +00:00
Campbell Barton
8f1500da00 remove config.h references, was added for automake build system rev around 124-126 but isnt used by any build systems now. 2010-04-18 10:28:37 +00:00
Guillermo S. Romero
00e46ef739 SVN maintenance. 2010-04-17 22:43:18 +00:00
Campbell Barton
4cf697de89 - for BGE mouse and keyboard events use tuples rather then lists
- pep8 corrections
2010-04-17 19:05:53 +00:00
Dalai Felinto
795b438bf5 Patch #21789 - BGE Keyboard and Mouse Python types - by Mitchell Stokes(Moguri)
The patch exposes mouse and keyboard read-only properties in the GameLogic module
Also renames bge.keys to bge.events (* Note: name of bge submodules (logic, render, ...) may change before 2.5 final release [right Campbell?]).

"""
This patch adds two new types to the BGE:
SCA_PythonKeyboard
SCA_PythonMouse

These two types allow users to make use of the keyboard and mouse without the need for a keyboard or mouse sensor.

SCA_PythonKeyboard has an events property that acts just like SCA_KeyboardSensor.events.

SCA_PythonMouse also has an events property to check for mouse events. Further more it supports getting and setting normalized cursor position (from 0.0 to 1.0) with SCA_PythonMouse.position. The cursor can be shown/hidden using SCA_PythonMouse.visible.
"""

Its use is similar with current mouse and keyboard controllers. With the exception of mouse position being normalized and writable as well (replacing Rasterizer.setMousePosition).

Code Sample:
######
from bge import logic, events

mouse = logic.mouse
keyboard = logic.keyboard

for key,status in keyboard.events:
    if status == logic.KX_INPUT_JUST_ACTIVATED:
        if key == events.WKEY:
            print(mouse.position)
            # move_forward()

mouse.visible = True # turn cursor visible
mouse.position = 0.5,0.5  # centralize mouse - use tuple
######

* Important Note: mouse.position still will not work properly for Letterbox mode.
In order to fix letterboxing I may need to move the set x,y mouse function to inside the canvas code (to avoid duplicated code between mouse sensor and bge.logic.mouse). I'll leave this for another commit though.
Thanks Mitchell for the work on that.
2010-04-17 06:52:14 +00:00