diff --git a/KREngine/KREngine.xcodeproj/project.pbxproj b/KREngine/KREngine.xcodeproj/project.pbxproj index 4d15e02..14fe7cb 100644 --- a/KREngine/KREngine.xcodeproj/project.pbxproj +++ b/KREngine/KREngine.xcodeproj/project.pbxproj @@ -43,6 +43,16 @@ E46DBE801512AF4600D59F86 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E491016413C99B9E0098455B /* Foundation.framework */; }; E46DBE811512AFE600D59F86 /* KRMesh.h in Headers */ = {isa = PBXBuildFile; fileRef = E49E79FC15126146009CF99C /* KRMesh.h */; settings = {ATTRIBUTES = (Public, ); }; }; E46DBE851512B9FA00D59F86 /* KREngine-common.h in Headers */ = {isa = PBXBuildFile; fileRef = E46DBE841512B9E200D59F86 /* KREngine-common.h */; settings = {ATTRIBUTES = (Public, ); }; }; + E46F4A00155DF46700CCF8B8 /* KRWorld.h in Headers */ = {isa = PBXBuildFile; fileRef = E46F49FF155DF46700CCF8B8 /* KRWorld.h */; }; + E46F4A01155DF46700CCF8B8 /* KRWorld.h in Headers */ = {isa = PBXBuildFile; fileRef = E46F49FF155DF46700CCF8B8 /* KRWorld.h */; settings = {ATTRIBUTES = (Public, ); }; }; + E46F4A04155DF47C00CCF8B8 /* KRWorld.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E46F4A03155DF47C00CCF8B8 /* KRWorld.cpp */; }; + E46F4A05155DF47C00CCF8B8 /* KRWorld.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E46F4A03155DF47C00CCF8B8 /* KRWorld.cpp */; }; + E46F4A09155DF6E400CCF8B8 /* KRWorld.cpp in Headers */ = {isa = PBXBuildFile; fileRef = E46F4A03155DF47C00CCF8B8 /* KRWorld.cpp */; settings = {ATTRIBUTES = (Public, ); }; }; + E46F4A0B155E002100CCF8B8 /* KRDataBlock.h in Headers */ = {isa = PBXBuildFile; fileRef = E46F4A0A155E002100CCF8B8 /* KRDataBlock.h */; }; + E46F4A0C155E002100CCF8B8 /* KRDataBlock.h in Headers */ = {isa = PBXBuildFile; fileRef = E46F4A0A155E002100CCF8B8 /* KRDataBlock.h */; }; + E46F4A0E155E003000CCF8B8 /* KRDataBlock.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E46F4A0D155E003000CCF8B8 /* KRDataBlock.cpp */; }; + E46F4A0F155E003000CCF8B8 /* KRDataBlock.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E46F4A0D155E003000CCF8B8 /* KRDataBlock.cpp */; }; + E46F4A10155E004100CCF8B8 /* KRDataBlock.cpp in Headers */ = {isa = PBXBuildFile; fileRef = E46F4A0D155E003000CCF8B8 /* KRDataBlock.cpp */; settings = {ATTRIBUTES = (Public, ); }; }; E47C25A213F4F65A00FF4370 /* KRShaderManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E47C25A113F4F65A00FF4370 /* KRShaderManager.h */; }; E47C25A513F4F66F00FF4370 /* KRShader.h in Headers */ = {isa = PBXBuildFile; fileRef = E47C25A413F4F66F00FF4370 /* KRShader.h */; }; E47C25A713F4F6AB00FF4370 /* KRShaderManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E47C25A613F4F6AB00FF4370 /* KRShaderManager.cpp */; }; @@ -170,6 +180,10 @@ E46C214A15364DEC009CABF3 /* KRSceneManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRSceneManager.cpp; path = Classes/KRSceneManager.cpp; sourceTree = ""; }; E46DBE7D1512AD4900D59F86 /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/OpenGL.framework; sourceTree = DEVELOPER_DIR; }; E46DBE841512B9E200D59F86 /* KREngine-common.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "KREngine-common.h"; path = "Classes/KREngine-common.h"; sourceTree = ""; }; + E46F49FF155DF46700CCF8B8 /* KRWorld.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRWorld.h; path = Classes/KRWorld.h; sourceTree = ""; }; + E46F4A03155DF47C00CCF8B8 /* KRWorld.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRWorld.cpp; path = Classes/KRWorld.cpp; sourceTree = ""; }; + E46F4A0A155E002100CCF8B8 /* KRDataBlock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRDataBlock.h; path = Classes/KRDataBlock.h; sourceTree = ""; }; + E46F4A0D155E003000CCF8B8 /* KRDataBlock.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRDataBlock.cpp; path = Classes/KRDataBlock.cpp; sourceTree = ""; }; E47C25A113F4F65A00FF4370 /* KRShaderManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRShaderManager.h; path = Classes/KRShaderManager.h; sourceTree = ""; }; E47C25A413F4F66F00FF4370 /* KRShader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRShader.h; path = Classes/KRShader.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; E47C25A613F4F6AB00FF4370 /* KRShaderManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRShaderManager.cpp; path = Classes/KRShaderManager.cpp; sourceTree = ""; }; @@ -438,6 +452,10 @@ E46C214A15364DEC009CABF3 /* KRSceneManager.cpp */, E48C696E15374F5A00232E28 /* KRContext.h */, E48C697115374F7E00232E28 /* KRContext.cpp */, + E46F49FF155DF46700CCF8B8 /* KRWorld.h */, + E46F4A0A155E002100CCF8B8 /* KRDataBlock.h */, + E46F4A0D155E003000CCF8B8 /* KRDataBlock.cpp */, + E46F4A03155DF47C00CCF8B8 /* KRWorld.cpp */, ); name = Classes; sourceTree = ""; @@ -515,6 +533,8 @@ E4F975321536220900FD60B2 /* KRNode.h in Headers */, E46C214715364BC8009CABF3 /* tinyxml2.h in Headers */, E48C696F15374F5B00232E28 /* KRContext.h in Headers */, + E46F4A00155DF46700CCF8B8 /* KRWorld.h in Headers */, + E46F4A0B155E002100CCF8B8 /* KRDataBlock.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -542,13 +562,17 @@ E461A153152E54B500F2044A /* KRLight.h in Headers */, E4F97552153633EF00FD60B2 /* KRMaterialManager.h in Headers */, E461A176152E5C5600F2044A /* KRPointLight.h in Headers */, + E46F4A09155DF6E400CCF8B8 /* KRWorld.cpp in Headers */, E4F975541536340400FD60B2 /* KRTexture.h in Headers */, + E46F4A01155DF46700CCF8B8 /* KRWorld.h in Headers */, E48C697015374F5B00232E28 /* KRContext.h in Headers */, + E46F4A10155E004100CCF8B8 /* KRDataBlock.cpp in Headers */, E4D13365153767FF0070068C /* KRShaderManager.h in Headers */, E461A15D152E563100F2044A /* KRDirectionalLight.h in Headers */, E461A169152E570700F2044A /* KRSpotLight.h in Headers */, E46C214815364BC8009CABF3 /* tinyxml2.h in Headers */, E46A6B701559EF0A000DBD37 /* KRResource+blend.h in Headers */, + E46F4A0C155E002100CCF8B8 /* KRDataBlock.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -665,6 +689,8 @@ E4D133BC1538F7560070068C /* light_directional.vsh in Sources */, E4A9DEBE154120C4009DF363 /* light_point.fsh in Sources */, E4A9DEC1154120E8009DF363 /* light_point.vsh in Sources */, + E46F4A04155DF47C00CCF8B8 /* KRWorld.cpp in Sources */, + E46F4A0E155E003000CCF8B8 /* KRDataBlock.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -700,6 +726,8 @@ E46C214C15364DEC009CABF3 /* KRSceneManager.cpp in Sources */, E48C697315374F7E00232E28 /* KRContext.cpp in Sources */, E46A6B6D1559E97D000DBD37 /* KRResource+blend.cpp in Sources */, + E46F4A05155DF47C00CCF8B8 /* KRWorld.cpp in Sources */, + E46F4A0F155E003000CCF8B8 /* KRDataBlock.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/KREngine/KREngine/Classes/KRDataBlock.cpp b/KREngine/KREngine/Classes/KRDataBlock.cpp new file mode 100644 index 0000000..32178c1 --- /dev/null +++ b/KREngine/KREngine/Classes/KRDataBlock.cpp @@ -0,0 +1,42 @@ +// +// KRDataBlock.cpp +// KREngine +// +// Created by Kearwood Gilbert on 12-05-11. +// Copyright (c) 2012 Kearwood Software. All rights reserved. +// + +#include + +#include "KRDataBlock.h" + +KRDataBlock::KRDataBlock() { + m_data = NULL; + m_data_size = 0; +} + +KRDataBlock::~KRDataBlock() { + if(m_data) { + free(m_data); + } +} + +void *KRDataBlock::getData() { + return m_data; +} + +int KRDataBlock::getSize() { + return m_data_size; +} + +void KRDataBlock::append(void *data, int size) { + if(m_data == NULL) { + m_data = malloc(size); + memcpy(m_data, data, size); + m_data_size = size; + } else { + m_data = realloc(m_data, m_data_size + size); + memcpy((unsigned char *)m_data + size, data, size); + m_data_size += size; + } +} \ No newline at end of file diff --git a/KREngine/KREngine/Classes/KRDataBlock.h b/KREngine/KREngine/Classes/KRDataBlock.h new file mode 100644 index 0000000..039e1c3 --- /dev/null +++ b/KREngine/KREngine/Classes/KRDataBlock.h @@ -0,0 +1,26 @@ +// +// KRDataBlock.h +// KREngine +// +// Created by Kearwood Gilbert on 12-05-11. +// Copyright (c) 2012 Kearwood Software. All rights reserved. +// + +#ifndef KREngine_KRDataBlock_h +#define KREngine_KRDataBlock_h + +class KRDataBlock { +public: + KRDataBlock(); + ~KRDataBlock(); + + void append(void *data, int size); + + void *getData(); + int getSize(); +private: + void *m_data; + int m_data_size; +}; + +#endif diff --git a/KREngine/KREngine/Classes/KRVector3.cpp b/KREngine/KREngine/Classes/KRVector3.cpp index d58ead7..0da818c 100644 --- a/KREngine/KREngine/Classes/KRVector3.cpp +++ b/KREngine/KREngine/Classes/KRVector3.cpp @@ -39,6 +39,67 @@ KRVector3::KRVector3() z = 0.0f; } +KRVector3 KRVector3::ZeroVector() { + return KRVector3(0.0f, 0.0f, 0.0f); +} + +KRVector3 KRVector3::OneVector() { + return KRVector3(1.0f, 1.0f, 1.0f); +} + +KRVector3 KRVector3::ForwardVector() { + return KRVector3(0.0f, 0.0f, 1.0f); +} + +KRVector3 KRVector3::BackwardVector() { + return KRVector3(0.0f, 0.0f, -1.0f); +} + +KRVector3 KRVector3::UpVector() { + return KRVector3(0.0f, 1.0f, 0.0f); +} + +KRVector3 KRVector3::DownVector() { + return KRVector3(0.0f, -1.0f, 0.0f); +} + +KRVector3 KRVector3::LeftVector() { + return KRVector3(-1.0f, 0.0f, 0.0f); +} + +KRVector3 KRVector3::RightVector() { + return KRVector3(1.0f, 0.0f, 0.0f); +} + +KRVector3 KRVector3::Lerp(const KRVector3 &v1, const KRVector3 &v2, float d) { + return v1 + (v2 - v1) * d; +} + +KRVector3 KRVector3::Slerp(const KRVector3 &v1, const KRVector3 &v2, float d) { + // From: http://keithmaggio.wordpress.com/2011/02/15/math-magician-lerp-slerp-and-nlerp/ + // Dot product - the cosine of the angle between 2 vectors. + float dot = KRVector3::Dot(v1, v2); + // Clamp it to be in the range of Acos() + if(dot < -1.0f) dot = -1.0f; + if(dot > 1.0f) dot = 1.0f; + // Acos(dot) returns the angle between start and end, + // And multiplying that by percent returns the angle between + // start and the final result. + float theta = acos(dot)*d; + KRVector3 RelativeVec = v2 - v1*dot; + RelativeVec.normalize(); // Orthonormal basis + // The final result. + return ((v1*cos(theta)) + (RelativeVec*sin(theta))); +} + +void KRVector3::OrthoNormalize(KRVector3 &normal, KRVector3 &tangent) { + // Gram-Schmidt Orthonormalization + normal.normalize(); + KRVector3 proj = normal * Dot(tangent, normal); + tangent = tangent - proj; + tangent.normalize(); +} + KRVector3::KRVector3(float v) { x = v; y = v; @@ -73,7 +134,12 @@ KRVector3::~KRVector3() //calculate and return the magnitude of this vector float KRVector3::GetMagnitude() { - return sqrtf(x * x + y * y + z * z); + return sqrtf(GetSqrMagnitude()); +} + +float KRVector3::GetSqrMagnitude() +{ + return x * x + y * y + z * z; } //multiply this vector by a scalar @@ -111,6 +177,10 @@ void KRVector3::normalize() z /= magnitude; } +float KRVector3::Dot(const KRVector3 &v1, const KRVector3 &v2) { + return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; +} + //calculate and return dot product float KRVector3::dot(const KRVector3 &vec) const { diff --git a/KREngine/KREngine/Classes/KRVector3.h b/KREngine/KREngine/Classes/KRVector3.h index 4e91a3c..683a4b3 100644 --- a/KREngine/KREngine/Classes/KRVector3.h +++ b/KREngine/KREngine/Classes/KRVector3.h @@ -48,14 +48,30 @@ public: KRVector3(); ~KRVector3(); + static KRVector3 ZeroVector(); + static KRVector3 OneVector(); + static KRVector3 ForwardVector(); + static KRVector3 BackwardVector(); + static KRVector3 UpVector(); + static KRVector3 DownVector(); + static KRVector3 LeftVector(); + static KRVector3 RightVector(); + static KRVector3 Lerp(const KRVector3 &v1, const KRVector3 &v2, float d); + static KRVector3 Slerp(const KRVector3 &v1, const KRVector3 &v2, float d); + static float Dot(const KRVector3 &v1, const KRVector3 &v2); + static void OrthoNormalize(KRVector3 &normal, KRVector3 &tangent); // Gram-Schmidt Orthonormalization + KRVector3(const KRVector3& p); KRVector3& operator = ( const KRVector3& p ); friend bool operator== (KRVector3 &v1, KRVector3 &v2); friend bool operator!= (KRVector3 &v1, KRVector3 &v2); - //calculate and return the magnitude of this vector + // calculate and return the magnitude of this vector float GetMagnitude(); + // calculate the square of the magnitude (useful for comparison of magnitudes without the cost of a sqrt() function used in GetMagnitude + float GetSqrMagnitude(); + //multiply this vector by a scalar KRVector3 operator*(float num) const; @@ -70,6 +86,8 @@ public: //normalize this vector void normalize(); + + //calculate and return dot product float dot(const KRVector3 &vec) const; diff --git a/KREngine/KREngine/Classes/KRWorld.cpp b/KREngine/KREngine/Classes/KRWorld.cpp new file mode 100644 index 0000000..ed70712 --- /dev/null +++ b/KREngine/KREngine/Classes/KRWorld.cpp @@ -0,0 +1,29 @@ +// +// KRWorld.cpp +// KREngine +// +// Created by Kearwood Gilbert on 12-05-11. +// Copyright (c) 2012 Kearwood Software. All rights reserved. +// + +#include + +#include "KRWorld.h" +#include "KRDataBlock.h" + + +KRWorld::KRWorld() { + +} +KRWorld::~KRWorld() { + +} + +void KRWorld::Load(void *data, int data_size) { + +} + +KRDataBlock *KRWorld::Save() { + KRDataBlock *block = new KRDataBlock(); + return block; +} diff --git a/KREngine/KREngine/Classes/KRWorld.h b/KREngine/KREngine/Classes/KRWorld.h new file mode 100644 index 0000000..29df861 --- /dev/null +++ b/KREngine/KREngine/Classes/KRWorld.h @@ -0,0 +1,24 @@ +// +// KRWorld.h +// KREngine +// +// Created by Kearwood Gilbert on 12-05-11. +// Copyright (c) 2012 Kearwood Software. All rights reserved. +// + +#ifndef KREngine_KRWorld_h +#define KREngine_KRWorld_h + +class KRDataBlock; + +class KRWorld { +public: + KRWorld(); + ~KRWorld(); + + void Load(void *data, int data_size); + KRDataBlock *Save(); +private: +}; + +#endif diff --git a/KREngine/KREngine/Shaders/light_point.vsh b/KREngine/KREngine/Shaders/light_point.vsh index 84ef213..14bf865 100644 --- a/KREngine/KREngine/Shaders/light_point.vsh +++ b/KREngine/KREngine/Shaders/light_point.vsh @@ -31,5 +31,5 @@ uniform highp mat4 mvp_matrix; // mvp_matrix is the result of multiplying the mo void main() { gl_Position = mvp_matrix * vertex_position; - gl_Position.z = max(gl_Position.z / gl_Position.w, 0.0) * gl_Position.w; + gl_Position.z = max(gl_Position.z / gl_Position.w, 0.00) * gl_Position.w; } \ No newline at end of file diff --git a/KRWorldBuilder/KRWorldBuilder.xcodeproj/project.pbxproj b/KRWorldBuilder/KRWorldBuilder.xcodeproj/project.pbxproj index 0161475..aed1c28 100644 --- a/KRWorldBuilder/KRWorldBuilder.xcodeproj/project.pbxproj +++ b/KRWorldBuilder/KRWorldBuilder.xcodeproj/project.pbxproj @@ -7,16 +7,21 @@ objects = { /* Begin PBXBuildFile section */ + E440D976155E46DB00C4887B /* KRWBFileSystemItem.m in Sources */ = {isa = PBXBuildFile; fileRef = E440D975155E46DB00C4887B /* KRWBFileSystemItem.m */; }; + E46F4A07155DF5E500CCF8B8 /* krengine_osx.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E46F4A06155DF5E500CCF8B8 /* krengine_osx.framework */; }; E474D77514E5BBF70017DCEC /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E474D77414E5BBF70017DCEC /* Cocoa.framework */; }; E474D77F14E5BBF70017DCEC /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = E474D77D14E5BBF70017DCEC /* InfoPlist.strings */; }; E474D78114E5BBF70017DCEC /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = E474D78014E5BBF70017DCEC /* main.m */; }; E474D78514E5BBF70017DCEC /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = E474D78314E5BBF70017DCEC /* Credits.rtf */; }; - E474D78814E5BBF70017DCEC /* KRWBDocument.m in Sources */ = {isa = PBXBuildFile; fileRef = E474D78714E5BBF70017DCEC /* KRWBDocument.m */; }; + E474D78814E5BBF70017DCEC /* KRWBDocument.mm in Sources */ = {isa = PBXBuildFile; fileRef = E474D78714E5BBF70017DCEC /* KRWBDocument.mm */; }; E474D78B14E5BBF70017DCEC /* KRWBDocument.xib in Resources */ = {isa = PBXBuildFile; fileRef = E474D78914E5BBF70017DCEC /* KRWBDocument.xib */; }; E474D78E14E5BBF80017DCEC /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = E474D78C14E5BBF80017DCEC /* MainMenu.xib */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + E440D974155E46DB00C4887B /* KRWBFileSystemItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KRWBFileSystemItem.h; sourceTree = ""; }; + E440D975155E46DB00C4887B /* KRWBFileSystemItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KRWBFileSystemItem.m; sourceTree = ""; }; + E46F4A06155DF5E500CCF8B8 /* krengine_osx.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = krengine_osx.framework; path = ../KREngine/build/Release/krengine_osx.framework; sourceTree = ""; }; E474D77014E5BBF70017DCEC /* KRWorldBuilder.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = KRWorldBuilder.app; sourceTree = BUILT_PRODUCTS_DIR; }; E474D77414E5BBF70017DCEC /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; }; E474D77714E5BBF70017DCEC /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; }; @@ -28,7 +33,7 @@ E474D78214E5BBF70017DCEC /* KRWorldBuilder-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "KRWorldBuilder-Prefix.pch"; sourceTree = ""; }; E474D78414E5BBF70017DCEC /* en */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; name = en; path = en.lproj/Credits.rtf; sourceTree = ""; }; E474D78614E5BBF70017DCEC /* KRWBDocument.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KRWBDocument.h; sourceTree = ""; }; - E474D78714E5BBF70017DCEC /* KRWBDocument.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KRWBDocument.m; sourceTree = ""; }; + E474D78714E5BBF70017DCEC /* KRWBDocument.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = KRWBDocument.mm; sourceTree = ""; }; E474D78A14E5BBF70017DCEC /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/KRWBDocument.xib; sourceTree = ""; }; E474D78D14E5BBF80017DCEC /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/MainMenu.xib; sourceTree = ""; }; /* End PBXFileReference section */ @@ -38,6 +43,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + E46F4A07155DF5E500CCF8B8 /* krengine_osx.framework in Frameworks */, E474D77514E5BBF70017DCEC /* Cocoa.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -65,6 +71,7 @@ E474D77314E5BBF70017DCEC /* Frameworks */ = { isa = PBXGroup; children = ( + E46F4A06155DF5E500CCF8B8 /* krengine_osx.framework */, E474D77414E5BBF70017DCEC /* Cocoa.framework */, E474D77614E5BBF70017DCEC /* Other Frameworks */, ); @@ -85,8 +92,10 @@ isa = PBXGroup; children = ( E474D78614E5BBF70017DCEC /* KRWBDocument.h */, - E474D78714E5BBF70017DCEC /* KRWBDocument.m */, + E474D78714E5BBF70017DCEC /* KRWBDocument.mm */, E474D78914E5BBF70017DCEC /* KRWBDocument.xib */, + E440D974155E46DB00C4887B /* KRWBFileSystemItem.h */, + E440D975155E46DB00C4887B /* KRWBFileSystemItem.m */, E474D78C14E5BBF80017DCEC /* MainMenu.xib */, E474D77B14E5BBF70017DCEC /* Supporting Files */, ); @@ -171,7 +180,8 @@ buildActionMask = 2147483647; files = ( E474D78114E5BBF70017DCEC /* main.m in Sources */, - E474D78814E5BBF70017DCEC /* KRWBDocument.m in Sources */, + E474D78814E5BBF70017DCEC /* KRWBDocument.mm in Sources */, + E440D976155E46DB00C4887B /* KRWBFileSystemItem.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -301,6 +311,7 @@ E474D79314E5BBF80017DCEC /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/KRWorldBuilder/KRWorldBuilder/KRWBDocument.h b/KRWorldBuilder/KRWorldBuilder/KRWBDocument.h index e59c2a2..f15f625 100644 --- a/KRWorldBuilder/KRWorldBuilder/KRWBDocument.h +++ b/KRWorldBuilder/KRWorldBuilder/KRWBDocument.h @@ -8,6 +8,11 @@ #import -@interface KRWBDocument : NSDocument +class KRWorld; + +@interface KRWBDocument : NSDocument + +@property (nonatomic, readonly) KRWorld *world; +@property (nonatomic, retain) IBOutlet NSOutlineView *outlineView; @end diff --git a/KRWorldBuilder/KRWorldBuilder/KRWBDocument.m b/KRWorldBuilder/KRWorldBuilder/KRWBDocument.mm similarity index 60% rename from KRWorldBuilder/KRWorldBuilder/KRWBDocument.m rename to KRWorldBuilder/KRWorldBuilder/KRWBDocument.mm index 6434c61..a294705 100644 --- a/KRWorldBuilder/KRWorldBuilder/KRWBDocument.m +++ b/KRWorldBuilder/KRWorldBuilder/KRWBDocument.mm @@ -8,18 +8,48 @@ #import "KRWBDocument.h" +#import +#import +#import +#import +#import "KRWBFileSystemItem.h" + +@interface KRWBDocument() { + KRWorld *_world; + NSOutlineView *_outlineView; +} + +@end + @implementation KRWBDocument +@synthesize outlineView = _outlineView; + +- (KRWorld *)world +{ + return _world; +} + - (id)init { + _world = NULL; self = [super init]; if (self) { // Add your subclass-specific initialization here. // If an error occurs here, return nil. + _world = new KRWorld(); } return self; } +- (void)dealloc +{ + if(_world) { + delete _world; + _world = NULL; + } +} + - (NSString *)windowNibName { // Override returning the nib file name of the document @@ -30,6 +60,8 @@ - (void)windowControllerDidLoadNib:(NSWindowController *)aController { [super windowControllerDidLoadNib:aController]; + + //[[self.windowControllers objectAtIndex:0] setBackgroundColor: [NSColor blackColor]]; // Add any code here that needs to be executed once the windowController has loaded the document's window. } @@ -51,8 +83,11 @@ You can also choose to override -readFromFileWrapper:ofType:error: or -readFromURL:ofType:error: instead. If you override either of these, you should also override -isEntireFileLoaded to return NO if the contents are lazily loaded. */ + /* NSException *exception = [NSException exceptionWithName:@"UnimplementedMethod" reason:[NSString stringWithFormat:@"%@ is unimplemented", NSStringFromSelector(_cmd)] userInfo:nil]; @throw exception; + */ + return YES; } @@ -61,4 +96,34 @@ return YES; } + +- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item { + if(item == nil) { + return [[KRWBFileSystemItem rootItem] numberOfChildren]; + } else { + return [item numberOfChildren]; + } + //return (item == nil) ? 1 : [item numberOfChildren]; +} + + +- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item { + return (item == nil) ? YES : ([item numberOfChildren] != -1); +} + + +- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item { + if(item == nil) { + return [[KRWBFileSystemItem rootItem] childAtIndex:index]; + } else { + return [(KRWBFileSystemItem *)item childAtIndex:index]; + } + //return (item == nil) ? [KRWBFileSystemItem rootItem] : [(KRWBFileSystemItem *)item childAtIndex:index]; +} + + +- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item { + return (item == nil) ? @"/" : [item relativePath]; +} + @end diff --git a/KRWorldBuilder/KRWorldBuilder/KRWBFileSystemItem.h b/KRWorldBuilder/KRWorldBuilder/KRWBFileSystemItem.h new file mode 100644 index 0000000..570df4d --- /dev/null +++ b/KRWorldBuilder/KRWorldBuilder/KRWBFileSystemItem.h @@ -0,0 +1,25 @@ +// +// KRWBFileSystemItem.h +// KRWorldBuilder +// +// Created by Kearwood Gilbert on 12-05-12. +// Copyright (c) 2012 Kearwood Software. All rights reserved. +// + +#import + +@interface KRWBFileSystemItem : NSObject +{ + NSURL *fullPath; + KRWBFileSystemItem *parent; + NSMutableArray *children; +} + ++ (KRWBFileSystemItem *)rootItem; +- (NSInteger)numberOfChildren;// Returns -1 for leaf nodes +- (KRWBFileSystemItem *)childAtIndex:(NSUInteger)n; // Invalid to call on leaf nodes +- (NSURL *)fullPath; +- (NSString *)relativePath; + +@end + diff --git a/KRWorldBuilder/KRWorldBuilder/KRWBFileSystemItem.m b/KRWorldBuilder/KRWorldBuilder/KRWBFileSystemItem.m new file mode 100644 index 0000000..50ae220 --- /dev/null +++ b/KRWorldBuilder/KRWorldBuilder/KRWBFileSystemItem.m @@ -0,0 +1,109 @@ +// +// KRWBFileSystemItem.m +// KRWorldBuilder +// +// Created by Kearwood Gilbert on 12-05-12. +// Copyright (c) 2012 Kearwood Software. All rights reserved. +// + +#import "KRWBFileSystemItem.h" + + +@implementation KRWBFileSystemItem + +static KRWBFileSystemItem *rootItem = nil; +static NSMutableArray *leafNode = nil; + ++ (void)initialize { + if (self == [KRWBFileSystemItem class]) { + leafNode = [[NSMutableArray alloc] init]; + } +} + +- (id)initWithPath:(NSURL *)url parent:(KRWBFileSystemItem *)parentItem { + self = [super init]; + if (self) { + fullPath = url; + parent = parentItem; + } + return self; +} + + ++ (KRWBFileSystemItem *)rootItem { + if (rootItem == nil) { + rootItem = [[KRWBFileSystemItem alloc] initWithPath:[NSURL URLWithString:@"file://localhost/"] parent:nil]; + } + return rootItem; +} + + +// Creates, caches, and returns the array of children +// Loads children incrementally +- (NSArray *)children { + + if (children == nil) { + NSFileManager *fileManager = [NSFileManager defaultManager]; + NSError *error; + + BOOL valid = [fullPath checkResourceIsReachableAndReturnError:NULL]; + + + NSNumber *isDirectory = nil; + if (! [fullPath getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:&error]) { + // handle error + } + + BOOL isDir = [isDirectory boolValue]; + if (valid && isDir) { + NSArray *keys = [NSArray arrayWithObject:NSURLIsDirectoryKey]; + + NSArray *child_urls = [fileManager contentsOfDirectoryAtURL:fullPath includingPropertiesForKeys:keys options: NSDirectoryEnumerationSkipsHiddenFiles error:&error]; + /* + NSDirectoryEnumerator *enumerator = [fileManager + enumeratorAtURL:fullPath + includingPropertiesForKeys:keys + options:0 + errorHandler:^(NSURL *url, NSError *error) { + // Handle the error. + // Return YES if the enumeration should continue after the error. + return YES; + }]; + */ + + children = [[NSMutableArray alloc] init]; + + for (NSURL *url in child_urls) { + KRWBFileSystemItem *newChild = [[KRWBFileSystemItem alloc] + initWithPath:url parent:self]; + [children addObject:newChild]; + } + } else { + children = leafNode; + } + } + return children; +} + + +- (NSString *)relativePath { + return [[fullPath lastPathComponent] copy]; +} + + +- (KRWBFileSystemItem *)childAtIndex:(NSUInteger)n { + return [[self children] objectAtIndex:n]; +} + + +- (NSInteger)numberOfChildren { + NSArray *tmp = [self children]; + return (tmp == leafNode) ? (-1) : [tmp count]; +} + + +- (void)dealloc { + +} + +@end \ No newline at end of file diff --git a/KRWorldBuilder/KRWorldBuilder/KRWorldBuilder-Info.plist b/KRWorldBuilder/KRWorldBuilder/KRWorldBuilder-Info.plist index a98c886..49b1d54 100644 --- a/KRWorldBuilder/KRWorldBuilder/KRWorldBuilder-Info.plist +++ b/KRWorldBuilder/KRWorldBuilder/KRWorldBuilder-Info.plist @@ -14,7 +14,7 @@ CFBundleTypeIconFile CFBundleTypeName - DocumentType + KREngine World CFBundleTypeOSTypes ???? diff --git a/KRWorldBuilder/KRWorldBuilder/en.lproj/KRWBDocument.xib b/KRWorldBuilder/KRWorldBuilder/en.lproj/KRWBDocument.xib index a3d3a27..55626da 100644 --- a/KRWorldBuilder/KRWorldBuilder/en.lproj/KRWBDocument.xib +++ b/KRWorldBuilder/KRWorldBuilder/en.lproj/KRWBDocument.xib @@ -3,12 +3,12 @@ 1070 11D50b - 1938 + 2182 1138.32 568.00 com.apple.InterfaceBuilder.CocoaPlugin - 1938 + 2182 NSTableColumn @@ -16,7 +16,6 @@ NSToolbarFlexibleSpaceItem NSSplitView NSScroller - NSTableHeaderView NSScrollView NSTextFieldCell NSToolbarSpaceItem @@ -47,7 +46,7 @@ 15 2 - {{133, 235}, {507, 427}} + {{133, 235}, {857, 513}} 1886912512 Window NSWindow @@ -61,7 +60,7 @@ YES NO 1 - 1 + 2 NSToolbarCustomizeToolbarItem @@ -211,7 +210,7 @@ - + @@ -219,7 +218,7 @@ - + @@ -250,22 +249,13 @@ 256 - {162, 410} + {209, 513} - + + 2 _NS:1703 YES - - - 256 - {162, 17} - - - - _NS:1705 - - -2147483392 @@ -274,23 +264,23 @@ - 101 + 206 16 1000 75628096 2048 - + LucidaGrande 11 3100 - + 3 MC4zMzMzMzI5ODU2AA - + 6 System headerTextColor @@ -304,7 +294,7 @@ 337772096 2048 Text Cell - + LucidaGrande 13 1044 @@ -319,7 +309,7 @@ MC42NjY2NjY2NjY3AA - + 6 System controlTextColor @@ -331,32 +321,6 @@ YES - - 55 - 40 - 1000 - - 75628096 - 2048 - - - - - - - 337772096 - 2048 - Text Cell - - - - - - 3 - YES - YES - - 3 2 @@ -385,14 +349,15 @@ 1 - {{0, 17}, {162, 410}} + {209, 513} + 2 _NS:1701 - 4 + 6 @@ -400,58 +365,42 @@ {{224, 17}, {15, 102}} - + _NS:1726 _doScroller: - 37 - 0.13909779489040375 + 0.99805447470817121 -2147483392 - {{1, 56.862202525138855}, {100.86830902099609, 15}} + {{0, 498}, {209, 15}} - + _NS:1728 1 _doScroller: - 0.68707482993197277 - - - - 2304 - - - - {162, 17} - - - - _NS:1706 - - - 4 + 0.99523809523809526 - {162, 427} + {209, 513} - + + 2 _NS:1699 264752 - QSAAAEEgAABBmAAAQZgAAA 4352 - {{163, 0}, {144, 427}} + {{210, 0}, {428, 513}} @@ -470,7 +419,7 @@ 274 - {199, 427} + {218, 513} @@ -487,7 +436,7 @@ 0 - {199, 427} + {218, 513} @@ -529,7 +478,7 @@ 0.63157892227172852 - {{308, 0}, {199, 427}} + {{639, 0}, {218, 513}} @@ -541,7 +490,7 @@ - {507, 427} + {857, 513} @@ -551,25 +500,23 @@ 2 - {507, 427} + {857, 513} + YES + 2 {{0, 0}, {1920, 1178}} - {94, 164} + {94, 155} {10000000000000, 10000000000000} + 128 YES NSApplication - - - 256 - {100, 100} - @@ -581,6 +528,14 @@ 18 + + + outlineView + + + + 100069 + delegate @@ -599,11 +554,19 @@ - view - - + dataSource + + - 100053 + 100067 + + + + delegate + + + + 100068 @@ -739,18 +702,12 @@ - - 100051 - - - 100054 - @@ -760,7 +717,6 @@ - @@ -769,11 +725,6 @@ - - 100057 - - - 100058 @@ -787,19 +738,6 @@ - - 100060 - - - - - - - - 100061 - - - 100062 @@ -825,75 +763,66 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin {{133, 170}, {507, 413}} com.apple.InterfaceBuilder.CocoaPlugin + + + + - 100062 + 100078 KRWBDocument NSDocument + + outlineView + NSOutlineView + + + outlineView + + outlineView + NSOutlineView + + IBProjectSource ./Classes/KRWBDocument.h - NSDocument - - id - id - id - id - id - id + NSCollectionViewItem + + NSImageView + NSTextField - - - printDocument: - id + + + imageView + NSImageView - - revertDocumentToSaved: - id - - - runPageLayout: - id - - - saveDocument: - id - - - saveDocumentAs: - id - - - saveDocumentTo: - id + + textField + NSTextField IBProjectSource - ./Classes/NSDocument.h + ./Classes/NSCollectionViewItem.h