diff options
Diffstat (limited to 'source/gameengine/Ketsji')
-rw-r--r-- | source/gameengine/Ketsji/CMakeLists.txt | 3 | ||||
-rwxr-xr-x | source/gameengine/Ketsji/KX_FontObject.cpp | 147 | ||||
-rwxr-xr-x | source/gameengine/Ketsji/KX_FontObject.h | 80 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_GameObject.cpp | 4 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_KetsjiEngine.cpp | 17 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_KetsjiEngine.h | 1 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_PythonInitTypes.cpp | 2 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_Scene.cpp | 29 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_Scene.h | 28 | ||||
-rw-r--r-- | source/gameengine/Ketsji/Makefile | 1 | ||||
-rw-r--r-- | source/gameengine/Ketsji/SConscript | 2 |
11 files changed, 311 insertions, 3 deletions
diff --git a/source/gameengine/Ketsji/CMakeLists.txt b/source/gameengine/Ketsji/CMakeLists.txt index 4931299a8e5..912794d9f75 100644 --- a/source/gameengine/Ketsji/CMakeLists.txt +++ b/source/gameengine/Ketsji/CMakeLists.txt @@ -35,6 +35,7 @@ set(INC ../../../intern/moto/include ../../../source/gameengine/Ketsji ../../../source/blender/blenlib + ../../../source/blender/blenfont ../../../source/blender/blenkernel ../../../source/blender/python ../../../source/blender/python/generic @@ -70,6 +71,7 @@ set(SRC KX_ConvertPhysicsObjects.cpp KX_Dome.cpp KX_EmptyObject.cpp + KX_FontObject.cpp KX_GameActuator.cpp KX_GameObject.cpp KX_IPO_SGController.cpp @@ -135,6 +137,7 @@ set(SRC KX_ConvertPhysicsObject.h KX_Dome.h KX_EmptyObject.h + KX_FontObject.h KX_GameActuator.h KX_GameObject.h KX_IInterpolator.h diff --git a/source/gameengine/Ketsji/KX_FontObject.cpp b/source/gameengine/Ketsji/KX_FontObject.cpp new file mode 100755 index 00000000000..2bd41b8fe1a --- /dev/null +++ b/source/gameengine/Ketsji/KX_FontObject.cpp @@ -0,0 +1,147 @@ +/** + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ +#include "KX_FontObject.h" +#include "DNA_curve_types.h" +#include "KX_Scene.h" +#include "KX_PythonInit.h" + +extern "C" { +#include "BLF_api.h" +} + +#define BGE_FONT_RES 100 + +KX_FontObject::KX_FontObject( void* sgReplicationInfo, + SG_Callbacks callbacks, + RAS_IRenderTools* rendertools, + Object *ob): + KX_GameObject(sgReplicationInfo, callbacks), + m_rendertools(rendertools), + m_object(ob), + m_dpi(72), + m_resolution(1.f), + m_color(ob->col) /* initial color - non-animatable */ +{ + Curve *text = static_cast<Curve *> (ob->data); + m_text = text->str; + m_fsize = text->fsize; + + /* <builtin> != "default" */ + /* I hope at some point Blender (2.5x) can have a single font */ + /* with unicode support for ui and OB_FONT */ + /* once we have packed working we can load the <builtin> font */ + const char* filepath = text->vfont->name; + if (strcmp("<builtin>", filepath) == 0) + filepath = "default"; + + /* XXX - if it's packed it will not work. waiting for bdiego (Diego) fix for that. */ + m_fontid = BLF_load(filepath); + if (m_fontid == -1) + m_fontid = BLF_load("default"); +} + +KX_FontObject::~KX_FontObject() +{ + //remove font from the scene list + //it's handled in KX_Scene::NewRemoveObject +} + +CValue* KX_FontObject::GetReplica() { + KX_FontObject* replica = new KX_FontObject(*this); + replica->ProcessReplica(); + return replica; +} + +void KX_FontObject::ProcessReplica() +{ + KX_GameObject::ProcessReplica(); + KX_GetActiveScene()->AddFont(this); +} + +void KX_FontObject::DrawText() +{ + /* only draws the text if visible */ + if(this->GetVisible() == 0) return; + + /* XXX 2DO - handle multiple lines + /* HARDCODED MULTIPLICATION FACTOR - this will affect the render resolution directly */ + float RES = BGE_FONT_RES * m_resolution; + + float size = m_fsize * m_object->size[0] * RES; + float aspect = 1.f / (m_object->size[0] * RES); + m_rendertools->RenderText3D(m_fontid, m_text, int(size), m_dpi, m_color, this->GetOpenGLMatrix(), aspect); +} + +#ifdef WITH_PYTHON + +/* ------------------------------------------------------------------------- */ +/* Python Integration Hooks */ +/* ------------------------------------------------------------------------- */ + +PyTypeObject KX_FontObject::Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "KX_FontObject", + sizeof(PyObjectPlus_Proxy), + 0, + py_base_dealloc, + 0, + 0, + 0, + 0, + py_base_repr, + 0, + &KX_GameObject::Sequence, + &KX_GameObject::Mapping, + 0,0,0, + NULL, + NULL, + 0, + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + 0,0,0,0,0,0,0, + Methods, + 0, + 0, + &KX_GameObject::Type, + 0,0,0,0,0,0, + py_base_new +}; + +PyMethodDef KX_FontObject::Methods[] = { + {NULL,NULL} //Sentinel +}; + +PyAttributeDef KX_FontObject::Attributes[] = { + KX_PYATTRIBUTE_STRING_RW("text", 0, 100, false, KX_FontObject, m_text), + KX_PYATTRIBUTE_FLOAT_RW("size", 0.0001f, 10000.0f, KX_FontObject, m_fsize), + KX_PYATTRIBUTE_FLOAT_RW("resolution", 0.0001f, 10000.0f, KX_FontObject, m_resolution), + /* KX_PYATTRIBUTE_INT_RW("dpi", 0, 10000, false, KX_FontObject, m_dpi), */// no real need for expose this I think + { NULL } //Sentinel +}; + +#endif // WITH_PYTHON diff --git a/source/gameengine/Ketsji/KX_FontObject.h b/source/gameengine/Ketsji/KX_FontObject.h new file mode 100755 index 00000000000..21fe1f0e9ea --- /dev/null +++ b/source/gameengine/Ketsji/KX_FontObject.h @@ -0,0 +1,80 @@ +/** + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ +#ifndef __KX_FONTOBJECT +#define __KX_FONTOBJECT +#include "KX_GameObject.h" +#include "DNA_vfont_types.h" +#include "RAS_IRenderTools.h" + +class KX_FontObject : public KX_GameObject +{ +public: + Py_Header; + KX_FontObject( void* sgReplicationInfo, + SG_Callbacks callbacks, + RAS_IRenderTools* rendertools, + Object *ob); + + virtual ~KX_FontObject(); + + void DrawText(); + + /** + * Inherited from CValue -- return a new copy of this + * instance allocated on the heap. Ownership of the new + * object belongs with the caller. + */ + virtual CValue* GetReplica(); + virtual void ProcessReplica(); + +protected: + STR_String m_text; + Object* m_object; + int m_fontid; + int m_dpi; + float m_fsize; + float m_resolution; + float* m_color; + + class RAS_IRenderTools* m_rendertools; //needed for drawing routine + +/* +#ifdef WITH_CXX_GUARDEDALLOC +public: + void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:KX_FontObject"); } + void operator delete( void *mem ) { MEM_freeN(mem); } +#endif +*/ + +#ifdef WITH_PYTHON +#endif + +}; + +#endif //__KX_FONTOBJECT diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 7bd7fb8026f..f515016d0b9 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -47,6 +47,7 @@ typedef unsigned long uint_ptr; #include "KX_GameObject.h" #include "KX_Camera.h" // only for their ::Type #include "KX_Light.h" // only for their ::Type +#include "KX_FontObject.h" // only for their ::Type #include "RAS_MeshObject.h" #include "KX_MeshProxy.h" #include "KX_PolyProxy.h" @@ -3034,7 +3035,8 @@ bool ConvertPythonToGameObject(PyObject * value, KX_GameObject **object, bool py if ( PyObject_TypeCheck(value, &KX_GameObject::Type) || PyObject_TypeCheck(value, &KX_LightObject::Type) || - PyObject_TypeCheck(value, &KX_Camera::Type) ) + PyObject_TypeCheck(value, &KX_Camera::Type) || + PyObject_TypeCheck(value, &KX_FontObject::Type)) { *object = static_cast<KX_GameObject*>BGE_PROXY_REF(value); diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index 35d02fbc9f4..f4fd85affb6 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -55,6 +55,7 @@ #include "KX_Scene.h" #include "MT_CmMatrix4x4.h" #include "KX_Camera.h" +#include "KX_FontObject.h" #include "KX_Dome.h" #include "KX_Light.h" #include "KX_PythonInit.h" @@ -1301,10 +1302,26 @@ void KX_KetsjiEngine::RenderFrame(KX_Scene* scene, KX_Camera* cam) #endif scene->RenderBuckets(camtrans, m_rasterizer, m_rendertools); + + //render all the font objects for this scene + RenderFonts(scene); if (scene->GetPhysicsEnvironment()) scene->GetPhysicsEnvironment()->debugDrawWorld(); } + +void KX_KetsjiEngine::RenderFonts(KX_Scene* scene) +{ + list<class KX_FontObject*>* fonts = scene->GetFonts(); + + list<KX_FontObject*>::iterator it = fonts->begin(); + while(it != fonts->end()) + { + (*it)->DrawText(); + ++it; + } +} + /* To run once per scene */ diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.h b/source/gameengine/Ketsji/KX_KetsjiEngine.h index 4ce14e100cc..8b07a998c33 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.h +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.h @@ -191,6 +191,7 @@ private: void RenderShadowBuffers(KX_Scene *scene); void SetBackGround(KX_WorldInfo* worldinfo); void DoSound(KX_Scene* scene); + void RenderFonts(KX_Scene* scene); public: KX_KetsjiEngine(class KX_ISystem* system); diff --git a/source/gameengine/Ketsji/KX_PythonInitTypes.cpp b/source/gameengine/Ketsji/KX_PythonInitTypes.cpp index 3cca4f39f85..8a9eac216d1 100644 --- a/source/gameengine/Ketsji/KX_PythonInitTypes.cpp +++ b/source/gameengine/Ketsji/KX_PythonInitTypes.cpp @@ -47,6 +47,7 @@ #include "KX_ConstraintWrapper.h" #include "KX_GameActuator.h" #include "KX_Light.h" +#include "KX_FontObject.h" #include "KX_MeshProxy.h" #include "KX_MouseFocusSensor.h" #include "KX_NetworkMessageActuator.h" @@ -193,6 +194,7 @@ void initPyTypes(void) PyType_Ready_Attr(dict, KX_GameObject, init_getset); PyType_Ready_Attr(dict, KX_IpoActuator, init_getset); PyType_Ready_Attr(dict, KX_LightObject, init_getset); + PyType_Ready_Attr(dict, KX_FontObject, init_getset); PyType_Ready_Attr(dict, KX_MeshProxy, init_getset); PyType_Ready_Attr(dict, KX_MouseFocusSensor, init_getset); PyType_Ready_Attr(dict, KX_NearSensor, init_getset); diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 0605650bb09..1db174d72be 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -323,7 +323,10 @@ list<class KX_Camera*>* KX_Scene::GetCameras() return &m_cameras; } - +list<class KX_FontObject*>* KX_Scene::GetFonts() +{ + return &m_fonts; +} void KX_Scene::SetFramingType(RAS_FrameSettings & frame_settings) { @@ -1014,6 +1017,9 @@ int KX_Scene::NewRemoveObject(class CValue* gameobj) // in case this is a camera m_cameras.remove((KX_Camera*)newobj); + // in case this is a font + m_fonts.remove((KX_FontObject*)newobj); + /* currently does nothing, keep incase we need to Unregister something */ #if 0 if (m_sceneConverter) @@ -1188,6 +1194,27 @@ void KX_Scene::ReplaceMesh(class CValue* obj,void* meshobj, bool use_gfx, bool u #endif } +/* Font Object routines */ +void KX_Scene::AddFont(KX_FontObject* font) +{ + if (!FindFont(font)) + m_fonts.push_back(font); +} + +KX_FontObject* KX_Scene::FindFont(KX_FontObject* font) +{ + list<KX_FontObject*>::iterator it = m_fonts.begin(); + + while ( (it != m_fonts.end()) + && ((*it) != font) ) { + ++it; + } + + return ((it == m_fonts.end()) ? NULL : (*it)); +} + + +/* Camera Object routines */ KX_Camera* KX_Scene::FindCamera(KX_Camera* cam) { list<KX_Camera*>::iterator it = m_cameras.begin(); diff --git a/source/gameengine/Ketsji/KX_Scene.h b/source/gameengine/Ketsji/KX_Scene.h index 9b4a6ec5ec6..6bef3f95dde 100644 --- a/source/gameengine/Ketsji/KX_Scene.h +++ b/source/gameengine/Ketsji/KX_Scene.h @@ -136,6 +136,13 @@ protected: * The set of cameras for this scene */ list<class KX_Camera*> m_cameras; + + /** + * The set of fonts for this scene + */ + list<class KX_FontObject*> m_fonts; + + /** * Various SCA managers used by the scene */ @@ -361,6 +368,27 @@ public: GetTimeEventManager( ); + /** Font Routines */ + + list<class KX_FontObject*>* + GetFonts( + ); + + /** Find a font in the scene by pointer. */ + KX_FontObject* + FindFont( + KX_FontObject* + ); + + /** Add a camera to this scene. */ + void + AddFont( + KX_FontObject* + ); + + + /** Camera Routines */ + list<class KX_Camera*>* GetCameras( ); diff --git a/source/gameengine/Ketsji/Makefile b/source/gameengine/Ketsji/Makefile index 79c8626d295..3161351db90 100644 --- a/source/gameengine/Ketsji/Makefile +++ b/source/gameengine/Ketsji/Makefile @@ -60,6 +60,7 @@ CPPFLAGS += -I../Converter CPPFLAGS += -I../../blender/blenkernel CPPFLAGS += -I../../blender/blenlib CPPFLAGS += -I../../blender/blenloader +CPPFLAGS += -I../../blender/blenfont CPPFLAGS += -I../../blender/makesdna CPPFLAGS += -I../../blender/imbuf CPPFLAGS += -I../../blender/gpu diff --git a/source/gameengine/Ketsji/SConscript b/source/gameengine/Ketsji/SConscript index 3e86080a2f8..56e0db0cc20 100644 --- a/source/gameengine/Ketsji/SConscript +++ b/source/gameengine/Ketsji/SConscript @@ -12,7 +12,7 @@ incs += ' #source/kernel/gen_system #intern/string #intern/guardedalloc' incs += ' #source/gameengine/Rasterizer/RAS_OpenGLRasterizer' incs += ' #intern/audaspace/intern #source/gameengine/Converter' incs += ' #source/gameengine/BlenderRoutines #source/blender/imbuf #intern/moto/include' -incs += ' #source/gameengine/Ketsji #source/gameengine/Ketsji/KXNetwork #source/blender/blenlib' +incs += ' #source/gameengine/Ketsji #source/gameengine/Ketsji/KXNetwork #source/blender/blenlib #source/blender/blenfont' incs += ' #source/blender/blenkernel #source/blender #source/blender/editors/include' incs += ' #source/blender/makesdna #source/blender/python #source/gameengine/Rasterizer' incs += ' #source/gameengine/GameLogic #source/gameengine/Expressions #source/gameengine/Network' |