Merge and some refactor (ref-counting some objects)
This commit is contained in:
parent
881c868b39
commit
13692657e1
@ -125,19 +125,27 @@
|
||||
E8B6B6B817DE27B500E35523 /* as_variablescope.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B68D17DE27B500E35523 /* as_variablescope.cpp */; };
|
||||
E8B6B6B917DE289700E35523 /* as_callfunc_x86.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B65617DE27B500E35523 /* as_callfunc_x86.cpp */; };
|
||||
E8B6B6BF17DF456F00E35523 /* GLSparseShadowMapRenderer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B6BD17DF456E00E35523 /* GLSparseShadowMapRenderer.cpp */; };
|
||||
E8B6B6D517E0850D00E35523 /* scriptany.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B6C017E0850700E35523 /* scriptany.cpp */; };
|
||||
E8B6B6D617E0850D00E35523 /* scriptarray.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B6C217E0850700E35523 /* scriptarray.cpp */; };
|
||||
E8B6B6D717E0850D00E35523 /* scriptbuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B6C417E0850800E35523 /* scriptbuilder.cpp */; };
|
||||
E8B6B6D817E0850D00E35523 /* scriptdictionary.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B6C617E0850800E35523 /* scriptdictionary.cpp */; };
|
||||
E8B6B6D917E0850D00E35523 /* scripthandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B6C817E0850900E35523 /* scripthandle.cpp */; };
|
||||
E8B6B6DA17E0850D00E35523 /* scripthelper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B6CA17E0850900E35523 /* scripthelper.cpp */; };
|
||||
E8B6B6DB17E0850D00E35523 /* scriptmath.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B6CC17E0850A00E35523 /* scriptmath.cpp */; };
|
||||
E8B6B6DC17E0850D00E35523 /* scriptmathcomplex.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B6CE17E0850B00E35523 /* scriptmathcomplex.cpp */; };
|
||||
E8B6B6DD17E0850D00E35523 /* scriptstdstring_utils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B6D017E0850B00E35523 /* scriptstdstring_utils.cpp */; };
|
||||
E8B6B6DE17E0850D00E35523 /* scriptstdstring.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B6D117E0850C00E35523 /* scriptstdstring.cpp */; };
|
||||
E8B6B6DF17E0850D00E35523 /* weakref.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B6D317E0850D00E35523 /* weakref.cpp */; };
|
||||
E8B6B6E217E08BAF00E35523 /* ScriptManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B6E017E08BAE00E35523 /* ScriptManager.cpp */; };
|
||||
E8B6B6E517E165A600E35523 /* GLDepthOfFieldFilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B6E317E165A400E35523 /* GLDepthOfFieldFilter.cpp */; };
|
||||
E8B6B6EA17E40AF500E35523 /* MathScript.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B6E717E40AF500E35523 /* MathScript.cpp */; };
|
||||
E8B6B6EB17E40AF500E35523 /* ScriptManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B6E817E40AF500E35523 /* ScriptManager.cpp */; };
|
||||
E8B6B6EE17E40B5900E35523 /* IImage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B6EC17E40B5900E35523 /* IImage.cpp */; };
|
||||
E8B6B6F117E40DAC00E35523 /* RefCountedObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B6EF17E40DA700E35523 /* RefCountedObject.cpp */; };
|
||||
E8B6B6F417E40E8300E35523 /* IModel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B6F217E40E8200E35523 /* IModel.cpp */; };
|
||||
E8B6B6F717E40F9A00E35523 /* IRenderer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B6F517E40F9900E35523 /* IRenderer.cpp */; };
|
||||
E8B6B6FA17E4131000E35523 /* GameMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B6F817E4130E00E35523 /* GameMap.cpp */; };
|
||||
E8B6B6FC17E413AC00E35523 /* Bitmap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B6FB17E413AB00E35523 /* Bitmap.cpp */; };
|
||||
E8B6B6FE17E4141200E35523 /* VoxelModel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B6FD17E4141000E35523 /* VoxelModel.cpp */; };
|
||||
E8B6B71517E4193A00E35523 /* scriptany.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B70017E4193A00E35523 /* scriptany.cpp */; };
|
||||
E8B6B71617E4193A00E35523 /* scriptarray.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B70217E4193A00E35523 /* scriptarray.cpp */; };
|
||||
E8B6B71717E4193A00E35523 /* scriptbuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B70417E4193A00E35523 /* scriptbuilder.cpp */; };
|
||||
E8B6B71817E4193A00E35523 /* scriptdictionary.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B70617E4193A00E35523 /* scriptdictionary.cpp */; };
|
||||
E8B6B71917E4193A00E35523 /* scripthandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B70817E4193A00E35523 /* scripthandle.cpp */; };
|
||||
E8B6B71A17E4193A00E35523 /* scripthelper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B70A17E4193A00E35523 /* scripthelper.cpp */; };
|
||||
E8B6B71B17E4193A00E35523 /* scriptmath.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B70C17E4193A00E35523 /* scriptmath.cpp */; };
|
||||
E8B6B71C17E4193A00E35523 /* scriptmathcomplex.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B70E17E4193A00E35523 /* scriptmathcomplex.cpp */; };
|
||||
E8B6B71D17E4193A00E35523 /* scriptstdstring.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B71017E4193A00E35523 /* scriptstdstring.cpp */; };
|
||||
E8B6B71E17E4193A00E35523 /* scriptstdstring_utils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B71217E4193A00E35523 /* scriptstdstring_utils.cpp */; };
|
||||
E8B6B71F17E4193A00E35523 /* weakref.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8B6B71317E4193A00E35523 /* weakref.cpp */; };
|
||||
E8CF0396178EDA75000683D4 /* SDL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E8CF0395178EDA75000683D4 /* SDL.framework */; };
|
||||
E8CF0398178EDA86000683D4 /* SDL_net.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E8CF0397178EDA86000683D4 /* SDL_net.framework */; };
|
||||
E8CF039A178EDABD000683D4 /* OpenAL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E8CF0399178EDABD000683D4 /* OpenAL.framework */; };
|
||||
@ -517,31 +525,40 @@
|
||||
E8B6B6BC17DE2F5500E35523 /* CMakeLists.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = "<group>"; };
|
||||
E8B6B6BD17DF456E00E35523 /* GLSparseShadowMapRenderer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GLSparseShadowMapRenderer.cpp; sourceTree = "<group>"; };
|
||||
E8B6B6BE17DF456F00E35523 /* GLSparseShadowMapRenderer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GLSparseShadowMapRenderer.h; sourceTree = "<group>"; };
|
||||
E8B6B6C017E0850700E35523 /* scriptany.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = scriptany.cpp; sourceTree = "<group>"; };
|
||||
E8B6B6C117E0850700E35523 /* scriptany.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = scriptany.h; sourceTree = "<group>"; };
|
||||
E8B6B6C217E0850700E35523 /* scriptarray.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = scriptarray.cpp; sourceTree = "<group>"; };
|
||||
E8B6B6C317E0850700E35523 /* scriptarray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = scriptarray.h; sourceTree = "<group>"; };
|
||||
E8B6B6C417E0850800E35523 /* scriptbuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = scriptbuilder.cpp; sourceTree = "<group>"; };
|
||||
E8B6B6C517E0850800E35523 /* scriptbuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = scriptbuilder.h; sourceTree = "<group>"; };
|
||||
E8B6B6C617E0850800E35523 /* scriptdictionary.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = scriptdictionary.cpp; sourceTree = "<group>"; };
|
||||
E8B6B6C717E0850800E35523 /* scriptdictionary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = scriptdictionary.h; sourceTree = "<group>"; };
|
||||
E8B6B6C817E0850900E35523 /* scripthandle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = scripthandle.cpp; sourceTree = "<group>"; };
|
||||
E8B6B6C917E0850900E35523 /* scripthandle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = scripthandle.h; sourceTree = "<group>"; };
|
||||
E8B6B6CA17E0850900E35523 /* scripthelper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = scripthelper.cpp; sourceTree = "<group>"; };
|
||||
E8B6B6CB17E0850A00E35523 /* scripthelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = scripthelper.h; sourceTree = "<group>"; };
|
||||
E8B6B6CC17E0850A00E35523 /* scriptmath.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = scriptmath.cpp; sourceTree = "<group>"; };
|
||||
E8B6B6CD17E0850A00E35523 /* scriptmath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = scriptmath.h; sourceTree = "<group>"; };
|
||||
E8B6B6CE17E0850B00E35523 /* scriptmathcomplex.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = scriptmathcomplex.cpp; sourceTree = "<group>"; };
|
||||
E8B6B6CF17E0850B00E35523 /* scriptmathcomplex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = scriptmathcomplex.h; sourceTree = "<group>"; };
|
||||
E8B6B6D017E0850B00E35523 /* scriptstdstring_utils.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = scriptstdstring_utils.cpp; sourceTree = "<group>"; };
|
||||
E8B6B6D117E0850C00E35523 /* scriptstdstring.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = scriptstdstring.cpp; sourceTree = "<group>"; };
|
||||
E8B6B6D217E0850C00E35523 /* scriptstdstring.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = scriptstdstring.h; sourceTree = "<group>"; };
|
||||
E8B6B6D317E0850D00E35523 /* weakref.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = weakref.cpp; sourceTree = "<group>"; };
|
||||
E8B6B6D417E0850D00E35523 /* weakref.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = weakref.h; sourceTree = "<group>"; };
|
||||
E8B6B6E017E08BAE00E35523 /* ScriptManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScriptManager.cpp; sourceTree = "<group>"; };
|
||||
E8B6B6E117E08BAF00E35523 /* ScriptManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptManager.h; sourceTree = "<group>"; };
|
||||
E8B6B6E317E165A400E35523 /* GLDepthOfFieldFilter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GLDepthOfFieldFilter.cpp; sourceTree = "<group>"; };
|
||||
E8B6B6E417E165A500E35523 /* GLDepthOfFieldFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GLDepthOfFieldFilter.h; sourceTree = "<group>"; };
|
||||
E8B6B6E717E40AF500E35523 /* MathScript.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MathScript.cpp; sourceTree = "<group>"; };
|
||||
E8B6B6E817E40AF500E35523 /* ScriptManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScriptManager.cpp; sourceTree = "<group>"; };
|
||||
E8B6B6E917E40AF500E35523 /* ScriptManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptManager.h; sourceTree = "<group>"; };
|
||||
E8B6B6EC17E40B5900E35523 /* IImage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IImage.cpp; sourceTree = "<group>"; };
|
||||
E8B6B6EF17E40DA700E35523 /* RefCountedObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RefCountedObject.cpp; sourceTree = "<group>"; };
|
||||
E8B6B6F017E40DAA00E35523 /* RefCountedObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RefCountedObject.h; sourceTree = "<group>"; };
|
||||
E8B6B6F217E40E8200E35523 /* IModel.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IModel.cpp; sourceTree = "<group>"; };
|
||||
E8B6B6F517E40F9900E35523 /* IRenderer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IRenderer.cpp; sourceTree = "<group>"; };
|
||||
E8B6B6F817E4130E00E35523 /* GameMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GameMap.cpp; sourceTree = "<group>"; };
|
||||
E8B6B6FB17E413AB00E35523 /* Bitmap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Bitmap.cpp; sourceTree = "<group>"; };
|
||||
E8B6B6FD17E4141000E35523 /* VoxelModel.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = VoxelModel.cpp; sourceTree = "<group>"; };
|
||||
E8B6B70017E4193A00E35523 /* scriptany.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = scriptany.cpp; sourceTree = "<group>"; };
|
||||
E8B6B70117E4193A00E35523 /* scriptany.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = scriptany.h; sourceTree = "<group>"; };
|
||||
E8B6B70217E4193A00E35523 /* scriptarray.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = scriptarray.cpp; sourceTree = "<group>"; };
|
||||
E8B6B70317E4193A00E35523 /* scriptarray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = scriptarray.h; sourceTree = "<group>"; };
|
||||
E8B6B70417E4193A00E35523 /* scriptbuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = scriptbuilder.cpp; sourceTree = "<group>"; };
|
||||
E8B6B70517E4193A00E35523 /* scriptbuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = scriptbuilder.h; sourceTree = "<group>"; };
|
||||
E8B6B70617E4193A00E35523 /* scriptdictionary.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = scriptdictionary.cpp; sourceTree = "<group>"; };
|
||||
E8B6B70717E4193A00E35523 /* scriptdictionary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = scriptdictionary.h; sourceTree = "<group>"; };
|
||||
E8B6B70817E4193A00E35523 /* scripthandle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = scripthandle.cpp; sourceTree = "<group>"; };
|
||||
E8B6B70917E4193A00E35523 /* scripthandle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = scripthandle.h; sourceTree = "<group>"; };
|
||||
E8B6B70A17E4193A00E35523 /* scripthelper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = scripthelper.cpp; sourceTree = "<group>"; };
|
||||
E8B6B70B17E4193A00E35523 /* scripthelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = scripthelper.h; sourceTree = "<group>"; };
|
||||
E8B6B70C17E4193A00E35523 /* scriptmath.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = scriptmath.cpp; sourceTree = "<group>"; };
|
||||
E8B6B70D17E4193A00E35523 /* scriptmath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = scriptmath.h; sourceTree = "<group>"; };
|
||||
E8B6B70E17E4193A00E35523 /* scriptmathcomplex.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = scriptmathcomplex.cpp; sourceTree = "<group>"; };
|
||||
E8B6B70F17E4193A00E35523 /* scriptmathcomplex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = scriptmathcomplex.h; sourceTree = "<group>"; };
|
||||
E8B6B71017E4193A00E35523 /* scriptstdstring.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = scriptstdstring.cpp; sourceTree = "<group>"; };
|
||||
E8B6B71117E4193A00E35523 /* scriptstdstring.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = scriptstdstring.h; sourceTree = "<group>"; };
|
||||
E8B6B71217E4193A00E35523 /* scriptstdstring_utils.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = scriptstdstring_utils.cpp; sourceTree = "<group>"; };
|
||||
E8B6B71317E4193A00E35523 /* weakref.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = weakref.cpp; sourceTree = "<group>"; };
|
||||
E8B6B71417E4193A00E35523 /* weakref.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = weakref.h; sourceTree = "<group>"; };
|
||||
E8CF0385178ED9D2000683D4 /* OpenSpades */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = OpenSpades; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
E8CF0395178EDA75000683D4 /* SDL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SDL.framework; path = ../../../../../Library/Frameworks/SDL.framework; sourceTree = "<group>"; };
|
||||
E8CF0397178EDA86000683D4 /* SDL_net.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SDL_net.framework; path = ../../../../../Library/Frameworks/SDL_net.framework; sourceTree = "<group>"; };
|
||||
@ -948,6 +965,7 @@
|
||||
E8B6B63D17DE27B200E35523 /* AngelScript */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
E8B6B6FF17E4193800E35523 /* addons */,
|
||||
E8B6B6BA17DE2F5500E35523 /* projects */,
|
||||
E8B6B63E17DE27B500E35523 /* include */,
|
||||
E8B6B64017DE27B500E35523 /* source */,
|
||||
@ -966,27 +984,6 @@
|
||||
E8B6B64017DE27B500E35523 /* source */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
E8B6B6C017E0850700E35523 /* scriptany.cpp */,
|
||||
E8B6B6C117E0850700E35523 /* scriptany.h */,
|
||||
E8B6B6C217E0850700E35523 /* scriptarray.cpp */,
|
||||
E8B6B6C317E0850700E35523 /* scriptarray.h */,
|
||||
E8B6B6C417E0850800E35523 /* scriptbuilder.cpp */,
|
||||
E8B6B6C517E0850800E35523 /* scriptbuilder.h */,
|
||||
E8B6B6C617E0850800E35523 /* scriptdictionary.cpp */,
|
||||
E8B6B6C717E0850800E35523 /* scriptdictionary.h */,
|
||||
E8B6B6C817E0850900E35523 /* scripthandle.cpp */,
|
||||
E8B6B6C917E0850900E35523 /* scripthandle.h */,
|
||||
E8B6B6CA17E0850900E35523 /* scripthelper.cpp */,
|
||||
E8B6B6CB17E0850A00E35523 /* scripthelper.h */,
|
||||
E8B6B6CC17E0850A00E35523 /* scriptmath.cpp */,
|
||||
E8B6B6CD17E0850A00E35523 /* scriptmath.h */,
|
||||
E8B6B6CE17E0850B00E35523 /* scriptmathcomplex.cpp */,
|
||||
E8B6B6CF17E0850B00E35523 /* scriptmathcomplex.h */,
|
||||
E8B6B6D017E0850B00E35523 /* scriptstdstring_utils.cpp */,
|
||||
E8B6B6D117E0850C00E35523 /* scriptstdstring.cpp */,
|
||||
E8B6B6D217E0850C00E35523 /* scriptstdstring.h */,
|
||||
E8B6B6D317E0850D00E35523 /* weakref.cpp */,
|
||||
E8B6B6D417E0850D00E35523 /* weakref.h */,
|
||||
E8B6B64117DE27B500E35523 /* as_array.h */,
|
||||
E8B6B64217DE27B500E35523 /* as_atomic.cpp */,
|
||||
E8B6B64317DE27B500E35523 /* as_atomic.h */,
|
||||
@ -1085,6 +1082,51 @@
|
||||
path = cmake;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
E8B6B6E617E40AF300E35523 /* ScriptBindings */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
E8B6B6E717E40AF500E35523 /* MathScript.cpp */,
|
||||
E8B6B6E817E40AF500E35523 /* ScriptManager.cpp */,
|
||||
E8B6B6E917E40AF500E35523 /* ScriptManager.h */,
|
||||
E8B6B6EC17E40B5900E35523 /* IImage.cpp */,
|
||||
E8B6B6F217E40E8200E35523 /* IModel.cpp */,
|
||||
E8B6B6F517E40F9900E35523 /* IRenderer.cpp */,
|
||||
E8B6B6F817E4130E00E35523 /* GameMap.cpp */,
|
||||
E8B6B6FB17E413AB00E35523 /* Bitmap.cpp */,
|
||||
E8B6B6FD17E4141000E35523 /* VoxelModel.cpp */,
|
||||
);
|
||||
name = ScriptBindings;
|
||||
path = Sources/ScriptBindings;
|
||||
sourceTree = SOURCE_ROOT;
|
||||
};
|
||||
E8B6B6FF17E4193800E35523 /* addons */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
E8B6B70017E4193A00E35523 /* scriptany.cpp */,
|
||||
E8B6B70117E4193A00E35523 /* scriptany.h */,
|
||||
E8B6B70217E4193A00E35523 /* scriptarray.cpp */,
|
||||
E8B6B70317E4193A00E35523 /* scriptarray.h */,
|
||||
E8B6B70417E4193A00E35523 /* scriptbuilder.cpp */,
|
||||
E8B6B70517E4193A00E35523 /* scriptbuilder.h */,
|
||||
E8B6B70617E4193A00E35523 /* scriptdictionary.cpp */,
|
||||
E8B6B70717E4193A00E35523 /* scriptdictionary.h */,
|
||||
E8B6B70817E4193A00E35523 /* scripthandle.cpp */,
|
||||
E8B6B70917E4193A00E35523 /* scripthandle.h */,
|
||||
E8B6B70A17E4193A00E35523 /* scripthelper.cpp */,
|
||||
E8B6B70B17E4193A00E35523 /* scripthelper.h */,
|
||||
E8B6B70C17E4193A00E35523 /* scriptmath.cpp */,
|
||||
E8B6B70D17E4193A00E35523 /* scriptmath.h */,
|
||||
E8B6B70E17E4193A00E35523 /* scriptmathcomplex.cpp */,
|
||||
E8B6B70F17E4193A00E35523 /* scriptmathcomplex.h */,
|
||||
E8B6B71017E4193A00E35523 /* scriptstdstring.cpp */,
|
||||
E8B6B71117E4193A00E35523 /* scriptstdstring.h */,
|
||||
E8B6B71217E4193A00E35523 /* scriptstdstring_utils.cpp */,
|
||||
E8B6B71317E4193A00E35523 /* weakref.cpp */,
|
||||
E8B6B71417E4193A00E35523 /* weakref.h */,
|
||||
);
|
||||
path = addons;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
E8CF037C178ED9D2000683D4 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@ -1206,6 +1248,7 @@
|
||||
E8E44682179CC4A400BE8855 /* Media */,
|
||||
E8E44681179CC49C00BE8855 /* I/O */,
|
||||
E8E44680179CC48B00BE8855 /* System */,
|
||||
E8B6B6E617E40AF300E35523 /* ScriptBindings */,
|
||||
E8CF03CC178EE95F000683D4 /* Math.cpp */,
|
||||
E8CF03CD178EE95F000683D4 /* Math.h */,
|
||||
E88318DF17925F2E002ABE6D /* Deque.cpp */,
|
||||
@ -1216,8 +1259,8 @@
|
||||
E834F5551794BBD4004EBE88 /* Debug.h */,
|
||||
E8E0AFB3179BF25B00C6B5A9 /* Settings.cpp */,
|
||||
E8E0AFB4179BF25B00C6B5A9 /* Settings.h */,
|
||||
E8B6B6E017E08BAE00E35523 /* ScriptManager.cpp */,
|
||||
E8B6B6E117E08BAF00E35523 /* ScriptManager.h */,
|
||||
E8B6B6EF17E40DA700E35523 /* RefCountedObject.cpp */,
|
||||
E8B6B6F017E40DAA00E35523 /* RefCountedObject.h */,
|
||||
);
|
||||
path = Core;
|
||||
sourceTree = "<group>";
|
||||
@ -1725,19 +1768,27 @@
|
||||
E8B6B6B817DE27B500E35523 /* as_variablescope.cpp in Sources */,
|
||||
E8B6B6B917DE289700E35523 /* as_callfunc_x86.cpp in Sources */,
|
||||
E8B6B6BF17DF456F00E35523 /* GLSparseShadowMapRenderer.cpp in Sources */,
|
||||
E8B6B6D517E0850D00E35523 /* scriptany.cpp in Sources */,
|
||||
E8B6B6D617E0850D00E35523 /* scriptarray.cpp in Sources */,
|
||||
E8B6B6D717E0850D00E35523 /* scriptbuilder.cpp in Sources */,
|
||||
E8B6B6D817E0850D00E35523 /* scriptdictionary.cpp in Sources */,
|
||||
E8B6B6D917E0850D00E35523 /* scripthandle.cpp in Sources */,
|
||||
E8B6B6DA17E0850D00E35523 /* scripthelper.cpp in Sources */,
|
||||
E8B6B6DB17E0850D00E35523 /* scriptmath.cpp in Sources */,
|
||||
E8B6B6DC17E0850D00E35523 /* scriptmathcomplex.cpp in Sources */,
|
||||
E8B6B6DD17E0850D00E35523 /* scriptstdstring_utils.cpp in Sources */,
|
||||
E8B6B6DE17E0850D00E35523 /* scriptstdstring.cpp in Sources */,
|
||||
E8B6B6DF17E0850D00E35523 /* weakref.cpp in Sources */,
|
||||
E8B6B6E217E08BAF00E35523 /* ScriptManager.cpp in Sources */,
|
||||
E8B6B6E517E165A600E35523 /* GLDepthOfFieldFilter.cpp in Sources */,
|
||||
E8B6B6EA17E40AF500E35523 /* MathScript.cpp in Sources */,
|
||||
E8B6B6EB17E40AF500E35523 /* ScriptManager.cpp in Sources */,
|
||||
E8B6B6EE17E40B5900E35523 /* IImage.cpp in Sources */,
|
||||
E8B6B6F117E40DAC00E35523 /* RefCountedObject.cpp in Sources */,
|
||||
E8B6B6F417E40E8300E35523 /* IModel.cpp in Sources */,
|
||||
E8B6B6F717E40F9A00E35523 /* IRenderer.cpp in Sources */,
|
||||
E8B6B6FA17E4131000E35523 /* GameMap.cpp in Sources */,
|
||||
E8B6B6FC17E413AC00E35523 /* Bitmap.cpp in Sources */,
|
||||
E8B6B6FE17E4141200E35523 /* VoxelModel.cpp in Sources */,
|
||||
E8B6B71517E4193A00E35523 /* scriptany.cpp in Sources */,
|
||||
E8B6B71617E4193A00E35523 /* scriptarray.cpp in Sources */,
|
||||
E8B6B71717E4193A00E35523 /* scriptbuilder.cpp in Sources */,
|
||||
E8B6B71817E4193A00E35523 /* scriptdictionary.cpp in Sources */,
|
||||
E8B6B71917E4193A00E35523 /* scripthandle.cpp in Sources */,
|
||||
E8B6B71A17E4193A00E35523 /* scripthelper.cpp in Sources */,
|
||||
E8B6B71B17E4193A00E35523 /* scriptmath.cpp in Sources */,
|
||||
E8B6B71C17E4193A00E35523 /* scriptmathcomplex.cpp in Sources */,
|
||||
E8B6B71D17E4193A00E35523 /* scriptstdstring.cpp in Sources */,
|
||||
E8B6B71E17E4193A00E35523 /* scriptstdstring_utils.cpp in Sources */,
|
||||
E8B6B71F17E4193A00E35523 /* weakref.cpp in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -1,3 +1 @@
|
||||
#include "IImage.as"
|
||||
#include "IRenderer.as"
|
||||
#include "IModel.as"
|
||||
// nothing here...
|
||||
|
@ -1,19 +0,0 @@
|
||||
#include "DynamicLightType.as"
|
||||
namespace spades {
|
||||
class DynamicLightParam {
|
||||
DynamicLightType type;
|
||||
Vector3 origin;
|
||||
float radius;
|
||||
Vector3 color;
|
||||
|
||||
Vector3 spotAxisX;
|
||||
Vector3 spotAxisY;
|
||||
Vector3 spotAxisZ;
|
||||
IImage@ image;
|
||||
float spotAngle;
|
||||
|
||||
DynamicLightParam() {
|
||||
type = spades::DynamicLightType::Point;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
namespace spades {
|
||||
enum DynamicLightType {
|
||||
Point,
|
||||
Spotlight
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
namespace spades{
|
||||
interface IImage {
|
||||
float Width { get; }
|
||||
float Height { get; }
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +0,0 @@
|
||||
namespace spades {
|
||||
interface IModel {
|
||||
}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
#include "ModelRenderParam.as"
|
||||
#include "DynamicLightParam.as"
|
||||
#include "SceneDefinition.as"
|
||||
#include "IModel.as"
|
||||
#include "IImage.as"
|
||||
|
||||
namespace spades {
|
||||
interface IRenderer {
|
||||
|
||||
void Init();
|
||||
|
||||
IImage @RegisterImage(string);
|
||||
IModel @RegisterModel(string);
|
||||
|
||||
IImage @CreateImage(Bitmap@);
|
||||
IModel @CreateModel(VoxelModel@);
|
||||
|
||||
void SetGameMap(GameMap@);
|
||||
|
||||
float FogDistance { set; }
|
||||
Vector3 FogColor { set; }
|
||||
|
||||
void StartScene(const SceneDefinition@);
|
||||
|
||||
void AddLight(const DynamicLightParam@);
|
||||
|
||||
void RenderModel(IModel@, const ModelRenderParam@);
|
||||
void AddDebugLine(Vector3 a, Vector3 b, Vector4 color);
|
||||
|
||||
void AddSprite(IImage@, Vector3 center, float radius, float rotation);
|
||||
void AddLongSprite(IImage@, Vector3 p1, Vector3 p2, float radius);
|
||||
|
||||
void EndScene();
|
||||
|
||||
void MultiplyScreenColor(Vector3);
|
||||
void SetColor(Vector4);
|
||||
void DrawImage(IImage@, Vector2 outTopLeft);
|
||||
void DrawImage(IImage@, AABB2 outRect);
|
||||
void DrawImage(IImage@, Vector2 outTopLeft, AABB2 inRect);
|
||||
void DrawImage(IImage@, AABB2 outRect, AABB2 inRect);
|
||||
void DrawImage(IImage@, Vector2 outTopLeft, Vector2 outTopRight,
|
||||
Vector2 outBottomLeft, AABB2 inRect);
|
||||
|
||||
void DrawFlatGameMap(AABB2 outRect, AABB2 inRect);
|
||||
|
||||
void FrameDone();
|
||||
void Flip();
|
||||
|
||||
Bitmap@ ReadBitmap();
|
||||
|
||||
float ScreenWidth { get; }
|
||||
float ScreenHeight { get; }
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
namespace spades {
|
||||
class ModelRenderParam {
|
||||
Matrix4 matrix;
|
||||
Vector3 customColor;
|
||||
bool depthHack;
|
||||
|
||||
ModelRenderParam() {
|
||||
depthHack = false;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
namespace spades {
|
||||
class SceneDefinition {
|
||||
// viewport(Left|Top|Width|Height) is actually not used
|
||||
float fovX, fovY;
|
||||
Vector3 viewOrigin;
|
||||
Vector3 viewAxisX;
|
||||
Vector3 viewAxisY;
|
||||
Vector3 viewAxisZ;
|
||||
float zNear, zFar;
|
||||
bool skipWorld;
|
||||
|
||||
float depthOfFieldNearRange;
|
||||
uint time;
|
||||
bool denyCameraBlur;
|
||||
float blurVignette;
|
||||
|
||||
SceneDefinition() {
|
||||
depthOfFieldNearRange = 0.f;
|
||||
time = 0;
|
||||
denyCameraBlur = true;
|
||||
blurVignette = 0.f;
|
||||
skipWorld = true;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1 @@
|
||||
#include "Base/Base.as"
|
||||
|
||||
// Native interface to application;
|
||||
// native classes are used by the game engine, so
|
||||
// they must exist and must be consistent with the native code.
|
||||
#include "Native/Native.as"
|
||||
|
||||
|
@ -1,3 +0,0 @@
|
||||
#include "NativeRenderer.as"
|
||||
#include "NativeImage.as"
|
||||
#include "NativeModel.as"
|
@ -1,20 +0,0 @@
|
||||
#include "/Base/IImage.as"
|
||||
|
||||
namespace spades {
|
||||
class NativeImage: IImage {
|
||||
private LowLevelNativeImage@ inner;
|
||||
NativeImage(LowLevelNativeImage@ inner) {
|
||||
@this.inner = inner;
|
||||
}
|
||||
float Width {
|
||||
get {
|
||||
return inner.Width;
|
||||
}
|
||||
}
|
||||
float Height {
|
||||
get {
|
||||
return inner.Height;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
#include "/Base/IModel.as"
|
||||
|
||||
namespace spades {
|
||||
class NativeModel: IModel {
|
||||
private LowLevelNativeModel@ inner;
|
||||
NativeModel(LowLevelNativeModel@ inner){
|
||||
@this.inner = inner;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,123 +0,0 @@
|
||||
#include "/Base/IRenderer.as"
|
||||
|
||||
namespace spades {
|
||||
class NativeRenderer: IRenderer {
|
||||
private LowLevelNativeRenderer@ inner;
|
||||
|
||||
NativeRenderer(LowLevelNativeRenderer@ ll) {
|
||||
@this.inner = ll;
|
||||
}
|
||||
|
||||
void Init() {
|
||||
}
|
||||
|
||||
IImage @RegisterImage(string filename){
|
||||
return NativeImage(inner.RegisterImage(filename));
|
||||
}
|
||||
IModel @RegisterModel(string filename){
|
||||
return NativeModel(inner.RegisterModel(filename));
|
||||
}
|
||||
|
||||
IImage @CreateImage(Bitmap@ bmp){
|
||||
return NativeImage(inner.CreateImage(bmp));
|
||||
}
|
||||
IModel @CreateModel(VoxelModel@ model){
|
||||
return NativeModel(inner.CreateModel(model));
|
||||
}
|
||||
|
||||
void SetGameMap(GameMap@) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
float FogDistance {
|
||||
set {
|
||||
NotImplemented();
|
||||
}
|
||||
}
|
||||
Vector3 FogColor {
|
||||
set {
|
||||
NotImplemented();
|
||||
}
|
||||
}
|
||||
|
||||
void StartScene(const SceneDefinition@) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void AddLight(const DynamicLightParam@){
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void RenderModel(IModel@, const ModelRenderParam@) {
|
||||
NotImplemented();
|
||||
}
|
||||
void AddDebugLine(Vector3 a, Vector3 b, Vector4 color){
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void AddSprite(IImage@, Vector3 center, float radius, float rotation) {
|
||||
NotImplemented();
|
||||
}
|
||||
void AddLongSprite(IImage@, Vector3 p1, Vector3 p2, float radius) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EndScene(){
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void MultiplyScreenColor(Vector3) {
|
||||
NotImplemented();
|
||||
}
|
||||
void SetColor(Vector4){
|
||||
NotImplemented();
|
||||
}
|
||||
void DrawImage(IImage@, Vector2 outTopLeft) {
|
||||
NotImplemented();
|
||||
}
|
||||
void DrawImage(IImage@, AABB2 outRect) {
|
||||
NotImplemented();
|
||||
}
|
||||
void DrawImage(IImage@, Vector2 outTopLeft, AABB2 inRect) {
|
||||
NotImplemented();
|
||||
}
|
||||
void DrawImage(IImage@, AABB2 outRect, AABB2 inRect) {
|
||||
NotImplemented();
|
||||
}
|
||||
void DrawImage(IImage@, Vector2 outTopLeft, Vector2 outTopRight,
|
||||
Vector2 outBottomLeft, AABB2 inRect) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void DrawFlatGameMap(AABB2 outRect, AABB2 inRect) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void FrameDone() {
|
||||
NotImplemented();
|
||||
}
|
||||
void Flip() {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
Bitmap@ ReadBitmap() {
|
||||
NotImplemented();
|
||||
return null;
|
||||
}
|
||||
|
||||
float ScreenWidth {
|
||||
get {
|
||||
NotImplemented();
|
||||
return 0.f;
|
||||
}
|
||||
}
|
||||
float ScreenHeight {
|
||||
get {
|
||||
NotImplemented();
|
||||
return 0.f;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -31,128 +31,6 @@
|
||||
namespace spades {
|
||||
namespace client {
|
||||
|
||||
#pragma mark - Resources
|
||||
|
||||
class AsyncImage: public IImage {
|
||||
public:
|
||||
virtual ~AsyncImage(){}
|
||||
virtual IImage *GetImage() = 0;
|
||||
virtual float GetWidth() { return GetImage()->GetWidth(); }
|
||||
virtual float GetHeight() { return GetImage()->GetHeight(); }
|
||||
virtual AsyncImage *Copy() = 0;
|
||||
};
|
||||
|
||||
class SharedAsyncImage: public AsyncImage {
|
||||
IImage *img;
|
||||
public:
|
||||
SharedAsyncImage(IImage *img):img(img){}
|
||||
virtual ~SharedAsyncImage() {}
|
||||
virtual IImage *GetImage() { return img; }
|
||||
virtual AsyncImage *Copy() {
|
||||
return new SharedAsyncImage(img);
|
||||
}
|
||||
};
|
||||
|
||||
class TemporaryAsyncImage: public AsyncImage {
|
||||
struct Data {
|
||||
int refCount;
|
||||
AsyncRenderer *arenderer;
|
||||
Mutex mutex;
|
||||
IImage *img;
|
||||
Data(IImage *img):
|
||||
refCount(1), img(img){}
|
||||
Data *Retain() {
|
||||
AutoLocker locker(&mutex);
|
||||
refCount++;
|
||||
return this;
|
||||
}
|
||||
Data *Release() {
|
||||
AutoLocker locker(&mutex);
|
||||
refCount--;
|
||||
if(refCount > 0){
|
||||
return this;
|
||||
}else{
|
||||
arenderer->deletedImages.push_back(img);
|
||||
delete this;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
};
|
||||
Data *data;
|
||||
public:
|
||||
TemporaryAsyncImage(IImage *img, AsyncRenderer *r):
|
||||
data(new Data(img)){
|
||||
data->arenderer = r;
|
||||
}
|
||||
TemporaryAsyncImage(Data *d):
|
||||
data(d){}
|
||||
virtual ~TemporaryAsyncImage() { data->Release(); }
|
||||
virtual IImage *GetImage() { return data->img; }
|
||||
virtual AsyncImage *Copy() {
|
||||
return new TemporaryAsyncImage(data->Retain());
|
||||
}
|
||||
};
|
||||
|
||||
class AsyncModel: public IModel {
|
||||
public:
|
||||
virtual ~AsyncModel(){}
|
||||
virtual IModel *GetModel() = 0;
|
||||
virtual AsyncModel *Copy() = 0;
|
||||
};
|
||||
|
||||
class SharedAsyncModel: public AsyncModel {
|
||||
IModel *model;
|
||||
public:
|
||||
SharedAsyncModel(IModel *model):model(model){}
|
||||
virtual ~SharedAsyncModel() {}
|
||||
virtual IModel *GetModel() { return model; }
|
||||
virtual AsyncModel *Copy() {
|
||||
return new SharedAsyncModel(model);
|
||||
}
|
||||
};
|
||||
|
||||
class TemporaryAsyncModel: public AsyncModel {
|
||||
struct Data {
|
||||
int refCount;
|
||||
AsyncRenderer *arenderer;
|
||||
Mutex mutex;
|
||||
IModel *model;
|
||||
Data(IModel *model):
|
||||
refCount(1), model(model){}
|
||||
Data *Retain() {
|
||||
AutoLocker locker(&mutex);
|
||||
refCount++;
|
||||
return this;
|
||||
}
|
||||
Data *Release() {
|
||||
AutoLocker locker(&mutex);
|
||||
refCount--;
|
||||
if(refCount > 0){
|
||||
return this;
|
||||
}else{
|
||||
arenderer->deletedModels.push_back(model);
|
||||
locker.Release();
|
||||
mutex.Unlock();
|
||||
delete this;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
};
|
||||
Data *data;
|
||||
public:
|
||||
TemporaryAsyncModel(IModel *model, AsyncRenderer *r):
|
||||
data(new Data(model)){
|
||||
data->arenderer = r;
|
||||
}
|
||||
TemporaryAsyncModel(Data *d):
|
||||
data(d){}
|
||||
virtual ~TemporaryAsyncModel() { data->Release(); }
|
||||
virtual IModel *GetModel() { return data->model; }
|
||||
virtual AsyncModel *Copy() {
|
||||
return new TemporaryAsyncModel(data->Retain());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#pragma mark - Commands
|
||||
@ -201,23 +79,25 @@ namespace spades {
|
||||
};
|
||||
class AddLight: public Command {
|
||||
public:
|
||||
AsyncImage *img;
|
||||
IImage *img;
|
||||
DynamicLightParam def;
|
||||
virtual void Execute(IRenderer *r){
|
||||
if(img){
|
||||
def.image = img->GetImage();
|
||||
delete img;
|
||||
def.image = img; img = NULL;
|
||||
}
|
||||
r->AddLight(def);
|
||||
if(img){
|
||||
img->Release();
|
||||
}
|
||||
}
|
||||
};
|
||||
class RenderModel: public Command {
|
||||
public:
|
||||
AsyncModel *model;
|
||||
IModel *model;
|
||||
ModelRenderParam param;
|
||||
virtual void Execute(IRenderer *r){
|
||||
r->RenderModel(model->GetModel(), param);
|
||||
delete model;
|
||||
r->RenderModel(model, param);
|
||||
model->Release(); model = NULL;
|
||||
}
|
||||
};
|
||||
class AddDebugLine: public Command {
|
||||
@ -230,22 +110,22 @@ namespace spades {
|
||||
};
|
||||
class AddSprite: public Command {
|
||||
public:
|
||||
AsyncImage *img;
|
||||
IImage *img;
|
||||
Vector3 center;
|
||||
float radius, rotation;
|
||||
virtual void Execute(IRenderer *r){
|
||||
r->AddSprite(img->GetImage(), center, radius, rotation);
|
||||
delete img;
|
||||
r->AddSprite(img, center, radius, rotation);
|
||||
img->Release(); img = NULL;
|
||||
}
|
||||
};
|
||||
class AddLongSprite: public Command {
|
||||
public:
|
||||
AsyncImage *img;
|
||||
IImage *img;
|
||||
Vector3 p1, p2;
|
||||
float radius;
|
||||
virtual void Execute(IRenderer *r){
|
||||
r->AddLongSprite(img->GetImage(), p1, p2, radius);
|
||||
delete img;
|
||||
r->AddLongSprite(img, p1, p2, radius);
|
||||
img->Release(); img = NULL;
|
||||
}
|
||||
};
|
||||
class EndScene: public Command {
|
||||
@ -270,15 +150,15 @@ namespace spades {
|
||||
};
|
||||
class DrawImage: public Command {
|
||||
public:
|
||||
AsyncImage *img;
|
||||
IImage *img;
|
||||
Vector2 outTopLeft;
|
||||
Vector2 outTopRight;
|
||||
Vector2 outBottomLeft;
|
||||
AABB2 inRect;
|
||||
virtual void Execute(IRenderer *r){
|
||||
r->DrawImage(img->GetImage(), outTopLeft, outTopRight, outBottomLeft,
|
||||
r->DrawImage(img, outTopLeft, outTopRight, outBottomLeft,
|
||||
inRect);
|
||||
delete img;
|
||||
img->Release(); img = NULL;
|
||||
}
|
||||
};
|
||||
class DrawFlatGameMap: public Command {
|
||||
@ -294,7 +174,6 @@ namespace spades {
|
||||
virtual void Execute(IRenderer *r){
|
||||
r->FrameDone();
|
||||
|
||||
arenderer->DeleteDeferredResources();
|
||||
}
|
||||
};
|
||||
class Flip: public Command {
|
||||
@ -376,15 +255,6 @@ namespace spades {
|
||||
|
||||
AsyncRenderer::~AsyncRenderer(){
|
||||
Sync();
|
||||
DeleteDeferredResources();
|
||||
|
||||
for(std::map<std::string, IImage *>::iterator it =
|
||||
images.begin(); it != images.end(); it++)
|
||||
delete it->second;
|
||||
|
||||
for(std::map<std::string, IModel *>::iterator it =
|
||||
models.begin(); it != models.end(); it++)
|
||||
delete it->second;
|
||||
|
||||
delete dispatch;
|
||||
delete generator;
|
||||
@ -405,18 +275,6 @@ namespace spades {
|
||||
dispatch->Join();
|
||||
}
|
||||
|
||||
void AsyncRenderer::DeleteDeferredResources(){
|
||||
|
||||
|
||||
for(std::vector<IModel *>::iterator it = deletedModels.begin(); it != deletedModels.end(); it++)
|
||||
delete *it;
|
||||
deletedModels.clear();
|
||||
|
||||
for(std::vector<IImage *>::iterator it = deletedImages.begin(); it != deletedImages.end(); it++)
|
||||
delete *it;
|
||||
deletedImages.clear();
|
||||
}
|
||||
|
||||
#pragma mark - General COmmands
|
||||
|
||||
IImage *AsyncRenderer::RegisterImage(const char *filename) {
|
||||
@ -452,8 +310,10 @@ namespace spades {
|
||||
RegisterImageDispatch dispatch(base, filename);
|
||||
dispatch.StartOn(queue);
|
||||
dispatch.Join();
|
||||
AsyncImage *img = new SharedAsyncImage(dispatch.GetResult());
|
||||
|
||||
IImage *img = dispatch.GetResult();
|
||||
images[filename] = img;
|
||||
img->AddRef();
|
||||
return img;
|
||||
}
|
||||
return it->second;
|
||||
@ -496,8 +356,7 @@ namespace spades {
|
||||
dispatch.StartOn(queue);
|
||||
dispatch.Join();
|
||||
IImage *img = dispatch.GetResult();
|
||||
AsyncImage *i = new TemporaryAsyncImage(img, this);
|
||||
return i;
|
||||
return img;
|
||||
}
|
||||
|
||||
IModel *AsyncRenderer::RegisterModel(const char *filename) {
|
||||
@ -533,8 +392,9 @@ namespace spades {
|
||||
RegisterModelDispatch dispatch(base, filename);
|
||||
dispatch.StartOn(queue);
|
||||
dispatch.Join();
|
||||
AsyncModel *img = new SharedAsyncModel(dispatch.GetResult());
|
||||
IModel *img = dispatch.GetResult();
|
||||
models[filename] = img;
|
||||
img->AddRef();
|
||||
return img;
|
||||
}
|
||||
return it->second;
|
||||
@ -572,8 +432,7 @@ namespace spades {
|
||||
dispatch.StartOn(queue);
|
||||
dispatch.Join();
|
||||
IModel *img = dispatch.GetResult();
|
||||
AsyncModel *i = new TemporaryAsyncModel(img, this);
|
||||
return i;
|
||||
return img;
|
||||
}
|
||||
|
||||
void AsyncRenderer::SetGameMap(GameMap *gm) {
|
||||
@ -604,7 +463,8 @@ namespace spades {
|
||||
SPADES_MARK_FUNCTION();
|
||||
rcmds::AddLight *cmd = generator->AllocCommand<rcmds::AddLight>();
|
||||
if(light.image){
|
||||
cmd->img = static_cast<AsyncImage *>(light.image)->Copy();
|
||||
cmd->img = light.image;
|
||||
cmd->img->AddRef();
|
||||
}else{
|
||||
cmd->img = NULL;
|
||||
}
|
||||
@ -614,7 +474,8 @@ namespace spades {
|
||||
void AsyncRenderer::RenderModel(IModel *m, const ModelRenderParam&p) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
rcmds::RenderModel *cmd = generator->AllocCommand<rcmds::RenderModel>();
|
||||
cmd->model = static_cast<AsyncModel *>(m)->Copy();
|
||||
cmd->model = m;
|
||||
m->AddRef();
|
||||
cmd->param = p;
|
||||
}
|
||||
|
||||
@ -629,7 +490,8 @@ namespace spades {
|
||||
float radius, float rotation){
|
||||
SPADES_MARK_FUNCTION();
|
||||
rcmds::AddSprite *cmd = generator->AllocCommand<rcmds::AddSprite>();
|
||||
cmd->img = static_cast<AsyncImage *>(img)->Copy();
|
||||
cmd->img = img;
|
||||
img->AddRef();
|
||||
cmd->center = center;
|
||||
cmd->radius = radius;
|
||||
cmd->rotation = rotation;
|
||||
@ -639,7 +501,8 @@ namespace spades {
|
||||
float radius){
|
||||
SPADES_MARK_FUNCTION();
|
||||
rcmds::AddLongSprite *cmd = generator->AllocCommand<rcmds::AddLongSprite>();
|
||||
cmd->img = static_cast<AsyncImage *>(img)->Copy();
|
||||
cmd->img = img;
|
||||
img->AddRef();
|
||||
cmd->p1 = p1;
|
||||
cmd->p2 = p2;
|
||||
cmd->radius = radius;
|
||||
@ -716,13 +579,13 @@ namespace spades {
|
||||
const spades::AABB2 &inRect) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
AsyncImage *img = dynamic_cast<AsyncImage *>(image);
|
||||
if(!img){
|
||||
if(!image){
|
||||
SPInvalidArgument("image");
|
||||
}
|
||||
|
||||
rcmds::DrawImage *cmd = generator->AllocCommand<rcmds::DrawImage>();
|
||||
cmd->img = img->Copy();
|
||||
cmd->img = image;
|
||||
image->AddRef();
|
||||
cmd->outTopLeft = outTopLeft;
|
||||
cmd->outTopRight = outTopRight;
|
||||
cmd->outBottomLeft = outBottomLeft;
|
||||
|
@ -43,8 +43,6 @@ namespace spades {
|
||||
|
||||
std::map<std::string, IImage *> images;
|
||||
std::map<std::string, IModel *> models;
|
||||
std::vector<IModel *> deletedModels;
|
||||
std::vector<IImage *> deletedImages;
|
||||
|
||||
void FlushCommands();
|
||||
void Sync();
|
||||
@ -105,7 +103,6 @@ namespace spades {
|
||||
virtual float ScreenWidth();
|
||||
virtual float ScreenHeight();
|
||||
|
||||
void DeleteDeferredResources();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -1295,7 +1295,7 @@ namespace spades {
|
||||
// Well done!
|
||||
renderer->FrameDone();
|
||||
|
||||
Bitmap *bmp = renderer->ReadBitmap();
|
||||
Handle<Bitmap> bmp = renderer->ReadBitmap();
|
||||
// force 100% opacity
|
||||
|
||||
uint32_t *pixels = bmp->GetPixels();
|
||||
@ -1315,7 +1315,6 @@ namespace spades {
|
||||
msg += name;
|
||||
msg = ChatWindow::ColoredMessage(msg, MsgColorSysInfo);
|
||||
chatWindow->AddMessage(msg);
|
||||
delete bmp;
|
||||
}catch(const std::exception& ex){
|
||||
std::string msg;
|
||||
msg = "Screenshot failed: ";
|
||||
@ -1323,7 +1322,6 @@ namespace spades {
|
||||
msg += lines[0];
|
||||
msg = ChatWindow::ColoredMessage(msg, MsgColorRed);
|
||||
chatWindow->AddMessage(msg);
|
||||
delete bmp;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1722,7 +1720,7 @@ namespace spades {
|
||||
}
|
||||
// debug
|
||||
if(false){
|
||||
IImage *img = renderer->RegisterImage("Gfx/Ball.png");
|
||||
Handle<IImage> img = renderer->RegisterImage("Gfx/Ball.png");
|
||||
renderer->SetColor(MakeVector4(1, 0, 0, 0));
|
||||
renderer->AddLongSprite(img, lastSceneDef.viewOrigin +
|
||||
MakeVector3(0, 0, 1),
|
||||
@ -2069,7 +2067,7 @@ namespace spades {
|
||||
}
|
||||
|
||||
if(false){ // just debug
|
||||
IImage *img = renderer->RegisterImage("Gfx/Ball.png");
|
||||
Handle<IImage> img = renderer->RegisterImage("Gfx/Ball.png");
|
||||
renderer->SetColor(MakeVector4(1, 0.3f, 0.1f, 0));
|
||||
renderer->AddLongSprite(img,
|
||||
(param.matrix * MakeVector3(0, 10, -2)).GetXYZ(),
|
||||
@ -2899,7 +2897,7 @@ namespace spades {
|
||||
}
|
||||
|
||||
void Client::DrawSplash() {
|
||||
IImage *img;
|
||||
Handle<IImage> img;
|
||||
Vector2 siz;
|
||||
Vector2 scrSize = {renderer->ScreenWidth(),
|
||||
renderer->ScreenHeight()};
|
||||
@ -2918,7 +2916,7 @@ namespace spades {
|
||||
}
|
||||
|
||||
void Client::DrawStartupScreen() {
|
||||
IImage *img;
|
||||
Handle<IImage> img;
|
||||
Vector2 scrSize = {renderer->ScreenWidth(),
|
||||
renderer->ScreenHeight()};
|
||||
|
||||
@ -2950,7 +2948,7 @@ namespace spades {
|
||||
float per = (world->GetTime() - lastHurtTime) / .6f;
|
||||
if(per > 1.f) return;
|
||||
if(per < 0.f) return;
|
||||
IImage *img = renderer->RegisterImage("Gfx/HurtSprite.png");
|
||||
Handle<IImage> img = renderer->RegisterImage("Gfx/HurtSprite.png");
|
||||
|
||||
Vector2 scrSize = {renderer->ScreenWidth(), renderer->ScreenHeight()};
|
||||
Vector2 scrCenter = scrSize * .5f;
|
||||
@ -3050,7 +3048,7 @@ namespace spades {
|
||||
hurtRingView->Draw();
|
||||
|
||||
// draw sight
|
||||
IImage *sight = renderer->RegisterImage("Gfx/Sight.tga");
|
||||
Handle<IImage> sight = renderer->RegisterImage("Gfx/Sight.tga");
|
||||
renderer->SetColor(MakeVector4(1,1,1,1));
|
||||
renderer->DrawImage(sight,
|
||||
MakeVector2((scrWidth - sight->GetWidth()) * .5f,
|
||||
@ -3085,7 +3083,7 @@ namespace spades {
|
||||
}
|
||||
|
||||
|
||||
IImage *img = renderer->RegisterImage("Gfx/White.tga");
|
||||
Handle<IImage> img = renderer->RegisterImage("Gfx/White.tga");
|
||||
boundary.min *= renderer->ScreenHeight() * .5f;
|
||||
boundary.max *= renderer->ScreenHeight() * .5f;
|
||||
boundary.min /= tanf(lastSceneDef.fovY * .5f);
|
||||
@ -3126,7 +3124,7 @@ namespace spades {
|
||||
|
||||
// draw ammo
|
||||
Weapon *weap = p->GetWeapon();
|
||||
IImage *ammoIcon;
|
||||
Handle<IImage> ammoIcon;
|
||||
float iconWidth, iconHeight;
|
||||
float spacing = 2.f;
|
||||
int stockNum;
|
||||
@ -3404,7 +3402,7 @@ namespace spades {
|
||||
float fade = std::min(1.f, timeSinceInit * 2.f);
|
||||
|
||||
// background
|
||||
IImage *img;
|
||||
Handle<IImage> img;
|
||||
float bgSize = std::max(scrWidth, scrHeight);
|
||||
renderer->SetColor(MakeVector4(1, 1, 1, .4 * fade));
|
||||
img = renderer->RegisterImage("Gfx/CircleGradient.png");
|
||||
@ -3621,8 +3619,8 @@ namespace spades {
|
||||
150.f * 150.f)
|
||||
return;
|
||||
|
||||
//IImage *img = renderer->RegisterImage("Textures/SoftBall.tga");
|
||||
IImage *img = renderer->RegisterImage("Gfx/White.tga");
|
||||
//Handle<IImage> img = renderer->RegisterImage("Textures/SoftBall.tga");
|
||||
Handle<IImage> img = renderer->RegisterImage("Gfx/White.tga");
|
||||
Vector4 color = {0.5f, 0.02f, 0.04f, 1.f};
|
||||
for(int i = 0; i < 10; i++){
|
||||
ParticleSpriteEntity *ent =
|
||||
@ -3666,7 +3664,7 @@ namespace spades {
|
||||
150.f * 150.f)
|
||||
return;
|
||||
|
||||
IImage *img = renderer->RegisterImage("Gfx/White.tga");
|
||||
Handle<IImage> img = renderer->RegisterImage("Gfx/White.tga");
|
||||
Vector4 color = {c.x / 255.f,
|
||||
c.y / 255.f, c.z / 255.f, 1.f};
|
||||
for(int i = 0; i < 7; i++){
|
||||
@ -3735,7 +3733,7 @@ namespace spades {
|
||||
150.f * 150.f)
|
||||
return;
|
||||
|
||||
IImage *img = renderer->RegisterImage("Gfx/White.tga");
|
||||
Handle<IImage> img = renderer->RegisterImage("Gfx/White.tga");
|
||||
Vector4 color = {c.x / 255.f,
|
||||
c.y / 255.f, c.z / 255.f, 1.f};
|
||||
for(int i = 0; i < 8; i++){
|
||||
@ -3861,7 +3859,7 @@ namespace spades {
|
||||
}
|
||||
|
||||
// fragments
|
||||
IImage *img = renderer->RegisterImage("Gfx/White.tga");
|
||||
Handle<IImage> img = renderer->RegisterImage("Gfx/White.tga");
|
||||
color = MakeVector4(0.01, 0.03, 0, 1.f);
|
||||
for(int i = 0; i < 42; i++){
|
||||
ParticleSpriteEntity *ent =
|
||||
@ -3914,7 +3912,7 @@ namespace spades {
|
||||
Vector4 color;
|
||||
color = MakeVector4( .95f, .95f, .95f, .6f);
|
||||
// water1
|
||||
IImage *img = renderer->RegisterImage("Textures/WaterExpl.png");
|
||||
Handle<IImage> img = renderer->RegisterImage("Textures/WaterExpl.png");
|
||||
for(int i = 0; i < 7; i++){
|
||||
ParticleSpriteEntity *ent =
|
||||
new ParticleSpriteEntity(this, img, color);
|
||||
|
@ -88,8 +88,8 @@ namespace spades {
|
||||
}
|
||||
|
||||
FallingBlock::~FallingBlock(){
|
||||
delete model;
|
||||
delete vmodel;
|
||||
model->Release();
|
||||
vmodel->Release();
|
||||
}
|
||||
|
||||
bool FallingBlock::Update(float dt) {
|
||||
@ -115,7 +115,7 @@ namespace spades {
|
||||
Vector3 vmAxis2 = vmat.GetAxis(1);
|
||||
Vector3 vmAxis3 = vmat.GetAxis(2);
|
||||
|
||||
IImage *img = client->GetRenderer()->RegisterImage("Gfx/White.tga");
|
||||
Handle<IImage> img = client->GetRenderer()->RegisterImage("Gfx/White.tga");
|
||||
|
||||
bool usePrecisePhysics = false;
|
||||
float dist =(client->GetLastSceneDef().viewOrigin - matrix.GetOrigin()).GetLength();
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include <math.h>
|
||||
#include "../Core/Debug.h"
|
||||
#include <stdlib.h>
|
||||
#include <Core/ScriptManager.h>
|
||||
#include "FileManager.h"
|
||||
|
||||
// silly VOXLAP function
|
||||
@ -41,7 +40,6 @@ namespace spades {
|
||||
listener(NULL){
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
refCount = 1;
|
||||
uint32_t rnd = (uint32_t)rand() ^ ((uint32_t)rand() << 16);
|
||||
rnd ^= 0x7abd4513;
|
||||
for(int x = 0; x < DefaultWidth; x++)
|
||||
@ -474,233 +472,6 @@ namespace spades {
|
||||
}
|
||||
|
||||
|
||||
void GameMap::AddRef() {
|
||||
asAtomicInc(refCount);
|
||||
}
|
||||
|
||||
void GameMap::Release(){
|
||||
if(asAtomicDec(refCount) <= 0){
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
class GameMapRegistrar: public ScriptObjectRegistrar {
|
||||
static GameMap *Factory(int w, int h, int d){
|
||||
if(w != GameMap::DefaultWidth ||
|
||||
h != GameMap::DefaultHeight ||
|
||||
d != GameMap::DefaultDepth) {
|
||||
asGetActiveContext()->SetException("Currently, non-default GameMap dimensions aren't supported.");
|
||||
return NULL;
|
||||
}
|
||||
try{
|
||||
return new GameMap();
|
||||
}catch(const std::exception& ex){
|
||||
ScriptContextUtils().SetNativeException(ex);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
static GameMap *LoadFactory(const std::string& fn){
|
||||
spades::IStream *stream = NULL;
|
||||
try{
|
||||
stream = FileManager::OpenForReading(fn.c_str());
|
||||
GameMap *ret = GameMap::Load(stream);
|
||||
delete stream;
|
||||
return ret;
|
||||
}catch(const std::exception& ex) {
|
||||
ScriptContextUtils().SetNativeException(ex);
|
||||
if(stream) delete stream;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t GetColor(int x, int y, int z,
|
||||
GameMap *m) {
|
||||
if(x < 0 || y < 0 || x >= m->Width() || y >= m->Height() ||
|
||||
z < 0 || z >= m->Depth()) {
|
||||
asGetActiveContext()->SetException("Attempted to access a voxel outside the valid range.");
|
||||
return 0;
|
||||
}
|
||||
return m->GetColor(x, y, z);
|
||||
}
|
||||
|
||||
static bool IsSolid(int x, int y, int z,
|
||||
GameMap *m) {
|
||||
if(x < 0 || y < 0 || x >= m->Width() || y >= m->Height() ||
|
||||
z < 0 || z >= m->Depth()) {
|
||||
asGetActiveContext()->SetException("Attempted to access a voxel outside the valid range.");
|
||||
return 0;
|
||||
}
|
||||
return m->IsSolid(x, y, z);
|
||||
}
|
||||
static uint32_t GetColorWrapped(int x, int y, int z,
|
||||
GameMap *m) {
|
||||
return m->GetColorWrapped(x, y, z);
|
||||
}
|
||||
|
||||
static bool IsSolidWrapped(int x, int y, int z,
|
||||
GameMap *m) {
|
||||
return m->IsSolidWrapped(x, y, z);
|
||||
}
|
||||
static void SetAir(int x, int y, int z,
|
||||
GameMap *m) {
|
||||
if(x < 0 || y < 0 || x >= m->Width() || y >= m->Height() ||
|
||||
z < 0 || z >= m->Depth()) {
|
||||
asGetActiveContext()->SetException("Attempted to access a voxel outside the valid range.");
|
||||
return;
|
||||
}
|
||||
m->Set(x, y, z, false, 0);
|
||||
}
|
||||
static void SetSolid(int x, int y, int z, uint32_t col,
|
||||
GameMap *m) {
|
||||
if(x < 0 || y < 0 || x >= m->Width() || y >= m->Height() ||
|
||||
z < 0 || z >= m->Depth()) {
|
||||
asGetActiveContext()->SetException("Attempted to access a voxel outside the valid range.");
|
||||
return;
|
||||
}
|
||||
m->Set(x, y, z, true, col);
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
GameMapRegistrar():
|
||||
ScriptObjectRegistrar("GameMap") {}
|
||||
|
||||
virtual void Register(ScriptManager *manager, Phase phase) {
|
||||
asIScriptEngine *eng = manager->GetEngine();
|
||||
int r;
|
||||
eng->SetDefaultNamespace("spades");
|
||||
switch(phase){
|
||||
case PhaseObjectType:
|
||||
r = eng->RegisterObjectType("GameMap",
|
||||
0, asOBJ_REF);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectType("GameMapRayCastResult",
|
||||
sizeof(GameMap::RayCastResult), asOBJ_VALUE|asOBJ_POD|asOBJ_APP_CLASS_CDAK);
|
||||
manager->CheckError(r);
|
||||
break;
|
||||
case PhaseObjectMember:
|
||||
r = eng->RegisterObjectBehaviour("GameMap",
|
||||
asBEHAVE_ADDREF,
|
||||
"void f()",
|
||||
asMETHOD(GameMap, AddRef),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("GameMap",
|
||||
asBEHAVE_RELEASE,
|
||||
"void f()",
|
||||
asMETHOD(GameMap, Release),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("GameMap",
|
||||
asBEHAVE_FACTORY,
|
||||
"GameMap @f(int, int, int)",
|
||||
asFUNCTION(Factory),
|
||||
asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("GameMap",
|
||||
asBEHAVE_FACTORY,
|
||||
"GameMap @f(const string& in)",
|
||||
asFUNCTION(LoadFactory),
|
||||
asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("GameMap",
|
||||
"uint GetColor(int, int, int)",
|
||||
asFUNCTION(GetColor),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("GameMap",
|
||||
"bool IsSolid(int, int, int)",
|
||||
asFUNCTION(IsSolid),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("GameMap",
|
||||
"uint GetColorWrapped(int, int, int)",
|
||||
asFUNCTION(GetColorWrapped),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("GameMap",
|
||||
"bool IsSolidWrapped(int, int, int)",
|
||||
asFUNCTION(IsSolidWrapped),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("GameMap",
|
||||
"void SetAir(int, int, int)",
|
||||
asFUNCTION(SetAir),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("GameMap",
|
||||
"void SetSolid(int, int, int, uint)",
|
||||
asFUNCTION(SetSolid),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("GameMap",
|
||||
"int get_Width()",
|
||||
asMETHOD(GameMap, Width),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("GameMap",
|
||||
"int get_Height()",
|
||||
asMETHOD(GameMap, Height),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("GameMap",
|
||||
"int get_Depth()",
|
||||
asMETHOD(GameMap, Depth),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("GameMap",
|
||||
"bool ClipBox(int, int, int)",
|
||||
asMETHODPR(GameMap, ClipBox, (int,int,int), bool),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("GameMap",
|
||||
"bool ClipWorld(int, int, int)",
|
||||
asMETHODPR(GameMap, ClipBox, (int,int,int), bool),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("GameMap",
|
||||
"bool ClipBox(float, float, float)",
|
||||
asMETHODPR(GameMap, ClipBox, (float,float,float), bool),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("GameMap",
|
||||
"bool ClipWorld(float, float, float)",
|
||||
asMETHODPR(GameMap, ClipBox, (float,float,float), bool),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("GameMap",
|
||||
"GameMapRayCastResult CastRay(Vector3, Vector3, int)",
|
||||
asMETHOD(GameMap, CastRay2),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterObjectProperty("GameMapRayCastResult",
|
||||
"bool hit",
|
||||
asOFFSET(GameMap::RayCastResult, hit));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("GameMapRayCastResult",
|
||||
"bool startSolid",
|
||||
asOFFSET(GameMap::RayCastResult, startSolid));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("GameMapRayCastResult",
|
||||
"Vector3 hitPos",
|
||||
asOFFSET(GameMap::RayCastResult, hitPos));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("GameMapRayCastResult",
|
||||
"IntVector3 hitBlock",
|
||||
asOFFSET(GameMap::RayCastResult, hitBlock));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("GameMapRayCastResult",
|
||||
"IntVector3 normal",
|
||||
asOFFSET(GameMap::RayCastResult, normal));
|
||||
manager->CheckError(r);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static GameMapRegistrar registrar;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -26,11 +26,14 @@
|
||||
#include "../Core/Math.h"
|
||||
|
||||
#include "IGameMapListener.h"
|
||||
#include <Core/RefCountedObject.h>
|
||||
|
||||
namespace spades{
|
||||
class IStream;
|
||||
namespace client {
|
||||
class GameMap {
|
||||
class GameMap: public RefCountedObject {
|
||||
protected:
|
||||
~GameMap();
|
||||
public:
|
||||
// fixed for now
|
||||
enum {
|
||||
@ -39,10 +42,6 @@ namespace spades{
|
||||
DefaultDepth = 64 // should be <= 64
|
||||
};
|
||||
GameMap();
|
||||
~GameMap();
|
||||
|
||||
void AddRef();
|
||||
void Release();
|
||||
|
||||
static GameMap *Load(IStream *);
|
||||
|
||||
@ -134,7 +133,6 @@ namespace spades{
|
||||
uint64_t solidMap[DefaultWidth][DefaultHeight];
|
||||
uint32_t colorMap[DefaultWidth][DefaultHeight][DefaultDepth];
|
||||
IGameMapListener *listener;
|
||||
int refCount;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ namespace spades {
|
||||
if(dist < 40.f * 40.f){
|
||||
int splats = rand() % 3;
|
||||
|
||||
IImage *img = client->GetRenderer()->RegisterImage("Gfx/White.tga");
|
||||
Handle<IImage> img = client->GetRenderer()->RegisterImage("Gfx/White.tga");
|
||||
|
||||
Vector4 col = {1, 1, 1, 0.8f};
|
||||
Vector3 pt = matrix.GetOrigin();
|
||||
|
@ -38,7 +38,7 @@ namespace spades {
|
||||
}
|
||||
|
||||
HurtRingView::~HurtRingView() {
|
||||
|
||||
image->Release();
|
||||
}
|
||||
|
||||
void HurtRingView::ClearAll(){
|
||||
|
@ -22,131 +22,7 @@
|
||||
|
||||
namespace spades{
|
||||
namespace client {
|
||||
class LowLevelNativeImage {
|
||||
friend class IImage;
|
||||
IImage *img;
|
||||
|
||||
int refCount;
|
||||
bool MakeSureAvailable() {
|
||||
if(!img) {
|
||||
asIScriptContext *ctx = asGetActiveContext();
|
||||
ctx->SetException("Image is unavailable.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public:
|
||||
LowLevelNativeImage(IImage *img):img(img),refCount(1){
|
||||
|
||||
}
|
||||
~LowLevelNativeImage() {
|
||||
if(img){
|
||||
delete img;
|
||||
}
|
||||
}
|
||||
void AddRef() {
|
||||
asAtomicInc(refCount);
|
||||
}
|
||||
void Release() {
|
||||
if(asAtomicDec(refCount) <= 0) {
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
float GetWidth() {
|
||||
if(!MakeSureAvailable()) return 0.f;
|
||||
return img->GetWidth();
|
||||
}
|
||||
float GetHeight() {
|
||||
if(!MakeSureAvailable()) return 0.f;
|
||||
return img->GetHeight();
|
||||
}
|
||||
};
|
||||
|
||||
IImage::IImage() {
|
||||
lowLevelNativeImage = NULL;
|
||||
scriptImage = NULL;
|
||||
}
|
||||
|
||||
IImage::~IImage() {
|
||||
if(lowLevelNativeImage){
|
||||
lowLevelNativeImage->img = NULL;
|
||||
lowLevelNativeImage->Release();
|
||||
}
|
||||
}
|
||||
|
||||
LowLevelNativeImage *IImage::GetLowLevelNativeImage(bool addRef) {
|
||||
if(!lowLevelNativeImage){
|
||||
lowLevelNativeImage = new LowLevelNativeImage(this);
|
||||
}
|
||||
if(addRef)
|
||||
lowLevelNativeImage->AddRef();
|
||||
return lowLevelNativeImage;
|
||||
}
|
||||
|
||||
asIScriptObject *IImage::GetScriptImage() {
|
||||
if(!scriptImage){
|
||||
|
||||
asIScriptEngine *eng = ScriptManager::GetInstance()->GetEngine();
|
||||
asIObjectType *typ = eng->GetObjectTypeByName("spades::NativeImage");
|
||||
asIScriptFunction *func = typ->GetFactoryByDecl("NativeImage @NativeImage(LowLevelNativeImage@)");
|
||||
|
||||
ScriptContextHandle handle = ScriptManager::GetInstance()->GetContext();
|
||||
handle->Prepare(func);
|
||||
handle->SetArgObject(0, GetLowLevelNativeImage(false));
|
||||
handle.ExecuteChecked();
|
||||
|
||||
scriptImage = static_cast<asIScriptObject *>(handle->GetReturnObject());
|
||||
}
|
||||
return scriptImage;
|
||||
}
|
||||
|
||||
class LowLevelNativeImageRegistrar: public ScriptObjectRegistrar {
|
||||
public:
|
||||
LowLevelNativeImageRegistrar():
|
||||
ScriptObjectRegistrar("LowLevelNativeImage"){
|
||||
|
||||
}
|
||||
virtual void Register(ScriptManager *manager, Phase phase) {
|
||||
asIScriptEngine *eng = manager->GetEngine();
|
||||
int r;
|
||||
eng->SetDefaultNamespace("spades");
|
||||
switch(phase){
|
||||
case PhaseObjectType:
|
||||
r = eng->RegisterObjectType("LowLevelNativeImage",
|
||||
0, asOBJ_REF);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("LowLevelNativeImage",
|
||||
asBEHAVE_ADDREF, "void f()",
|
||||
asMETHOD(LowLevelNativeImage, AddRef),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("LowLevelNativeImage",
|
||||
asBEHAVE_RELEASE, "void f()",
|
||||
asMETHOD(LowLevelNativeImage, Release),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
|
||||
break;
|
||||
case PhaseObjectMember:
|
||||
r = eng->RegisterObjectMethod("LowLevelNativeImage",
|
||||
"float get_Width()",
|
||||
asMETHOD(LowLevelNativeImage, GetWidth),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("LowLevelNativeImage",
|
||||
"float get_Height()",
|
||||
asMETHOD(LowLevelNativeImage, GetHeight),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
break;
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static LowLevelNativeImageRegistrar registrar;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,23 +20,19 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Core/ScriptManager.h>
|
||||
#include <Core/RefCountedObject.h>
|
||||
|
||||
namespace spades{
|
||||
namespace client {
|
||||
class LowLevelNativeImage;
|
||||
class IImage {
|
||||
LowLevelNativeImage *lowLevelNativeImage;
|
||||
asIScriptObject *scriptImage;
|
||||
class IImage: public RefCountedObject {
|
||||
protected:
|
||||
virtual ~IImage(){}
|
||||
public:
|
||||
IImage();
|
||||
virtual ~IImage();
|
||||
IImage(){}
|
||||
|
||||
virtual float GetWidth() = 0;
|
||||
virtual float GetHeight() = 0;
|
||||
|
||||
LowLevelNativeImage *GetLowLevelNativeImage(bool addRef);
|
||||
asIScriptObject *GetScriptImage();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -18,84 +18,17 @@
|
||||
|
||||
*/
|
||||
|
||||
#include "ScriptManager.h"
|
||||
#include "IModel.h"
|
||||
|
||||
namespace spades{
|
||||
namespace client {
|
||||
class LowLevelNativeModel {
|
||||
friend class IModel;
|
||||
IModel *img;
|
||||
|
||||
int refCount;
|
||||
bool MakeSureAvailable() {
|
||||
if(!img) {
|
||||
asIScriptContext *ctx = asGetActiveContext();
|
||||
ctx->SetException("Model is unavailable.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
class RendererModelModelRegistrar: public ScriptObjectRegistrar {
|
||||
public:
|
||||
LowLevelNativeModel(IModel *img):img(img),refCount(1){
|
||||
|
||||
}
|
||||
~LowLevelNativeModel() {
|
||||
if(img){
|
||||
delete img;
|
||||
}
|
||||
}
|
||||
void AddRef() {
|
||||
asAtomicInc(refCount);
|
||||
}
|
||||
void Release() {
|
||||
if(asAtomicDec(refCount) <= 0) {
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
IModel::IModel() {
|
||||
lowLevelNativeModel = NULL;
|
||||
scriptModel = NULL;
|
||||
}
|
||||
|
||||
IModel::~IModel() {
|
||||
if(lowLevelNativeModel){
|
||||
lowLevelNativeModel->img = NULL;
|
||||
lowLevelNativeModel->Release();
|
||||
}
|
||||
}
|
||||
|
||||
LowLevelNativeModel *IModel::GetLowLevelNativeModel(bool addRef) {
|
||||
if(!lowLevelNativeModel){
|
||||
lowLevelNativeModel = new LowLevelNativeModel(this);
|
||||
}
|
||||
if(addRef)
|
||||
lowLevelNativeModel->AddRef();
|
||||
return lowLevelNativeModel;
|
||||
}
|
||||
|
||||
asIScriptObject *IModel::GetScriptModel() {
|
||||
if(!scriptModel){
|
||||
|
||||
asIScriptEngine *eng = ScriptManager::GetInstance()->GetEngine();
|
||||
asIObjectType *typ = eng->GetObjectTypeByName("spades::NativeModel");
|
||||
asIScriptFunction *func = typ->GetFactoryByDecl("NativeModel @NativeModel(LowLevelNativeModel@)");
|
||||
|
||||
ScriptContextHandle handle = ScriptManager::GetInstance()->GetContext();
|
||||
handle->Prepare(func);
|
||||
handle->SetArgObject(0, GetLowLevelNativeModel(false));
|
||||
handle.ExecuteChecked();
|
||||
|
||||
scriptModel = static_cast<asIScriptObject *>(handle->GetReturnObject());
|
||||
}
|
||||
return scriptModel;
|
||||
}
|
||||
|
||||
class LowLevelNativeModelRegistrar: public ScriptObjectRegistrar {
|
||||
public:
|
||||
LowLevelNativeModelRegistrar():
|
||||
ScriptObjectRegistrar("LowLevelNativeModel"){
|
||||
RendererModelModelRegistrar():
|
||||
ScriptObjectRegistrar("RendererModelModel"){
|
||||
|
||||
}
|
||||
virtual void Register(ScriptManager *manager, Phase phase) {
|
||||
@ -104,17 +37,17 @@ namespace spades{
|
||||
eng->SetDefaultNamespace("spades");
|
||||
switch(phase){
|
||||
case PhaseObjectType:
|
||||
r = eng->RegisterObjectType("LowLevelNativeModel",
|
||||
r = eng->RegisterObjectType("RendererModel",
|
||||
0, asOBJ_REF);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("LowLevelNativeModel",
|
||||
r = eng->RegisterObjectBehaviour("RendererModel",
|
||||
asBEHAVE_ADDREF, "void f()",
|
||||
asMETHOD(LowLevelNativeModel, AddRef),
|
||||
asMETHOD(IModel, AddRef),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("LowLevelNativeModel",
|
||||
r = eng->RegisterObjectBehaviour("RendererModel",
|
||||
asBEHAVE_RELEASE, "void f()",
|
||||
asMETHOD(LowLevelNativeModel, Release),
|
||||
asMETHOD(IModel, Release),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
|
||||
@ -128,6 +61,6 @@ namespace spades{
|
||||
}
|
||||
};
|
||||
|
||||
static LowLevelNativeModelRegistrar registrar;
|
||||
static RendererModelModelRegistrar registrar;
|
||||
}
|
||||
}
|
||||
|
@ -20,20 +20,15 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Core/ScriptManager.h>
|
||||
#include <Core/RefCountedObject.h>
|
||||
|
||||
namespace spades {
|
||||
namespace client {
|
||||
class LowLevelNativeModel;
|
||||
class IModel {
|
||||
LowLevelNativeModel *lowLevelNativeModel;
|
||||
asIScriptObject *scriptModel;
|
||||
class IModel: public RefCountedObject {
|
||||
protected:
|
||||
virtual ~IModel(){}
|
||||
public:
|
||||
IModel();
|
||||
virtual ~IModel();
|
||||
|
||||
LowLevelNativeModel *GetLowLevelNativeModel(bool addRed);
|
||||
asIScriptObject *GetScriptModel();
|
||||
IModel(){}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -19,186 +19,9 @@
|
||||
*/
|
||||
|
||||
#include "IRenderer.h"
|
||||
#include <Core/ScriptManager.h>
|
||||
|
||||
namespace spades {
|
||||
namespace client{
|
||||
|
||||
class LowLevelNativeRenderer {
|
||||
friend class IRenderer;
|
||||
IRenderer *renderer;
|
||||
int refCount;
|
||||
|
||||
bool MakeSureAvailable() {
|
||||
if(!renderer) {
|
||||
asIScriptContext *ctx = asGetActiveContext();
|
||||
ctx->SetException("Renderer is unavailable.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public:
|
||||
LowLevelNativeRenderer(IRenderer *r):
|
||||
renderer(r){
|
||||
refCount = 1;
|
||||
}
|
||||
|
||||
void AddRef() {
|
||||
asAtomicInc(refCount);
|
||||
}
|
||||
|
||||
void Release() {
|
||||
if(asAtomicDec(refCount) <= 0) {
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
IRenderer *GetRenderer() { return renderer; }
|
||||
|
||||
LowLevelNativeImage *RegisterImage(const std::string& fn) {
|
||||
if(!MakeSureAvailable()){
|
||||
return NULL;
|
||||
}
|
||||
try{
|
||||
IImage *img = renderer->RegisterImage(fn.c_str());
|
||||
LowLevelNativeImage *obj = img->GetLowLevelNativeImage(true);
|
||||
return obj;
|
||||
}catch(const std::exception& ex){
|
||||
ScriptContextUtils().SetNativeException(ex);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
LowLevelNativeModel *RegisterModel(const std::string& fn) {
|
||||
if(!MakeSureAvailable()){
|
||||
return NULL;
|
||||
}
|
||||
try{
|
||||
IModel *img = renderer->RegisterModel(fn.c_str());
|
||||
LowLevelNativeModel *obj = img->GetLowLevelNativeModel(true);
|
||||
return obj;
|
||||
}catch(const std::exception& ex){
|
||||
ScriptContextUtils().SetNativeException(ex);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
LowLevelNativeImage *CreateImage(Bitmap *bmp) {
|
||||
if(!MakeSureAvailable()){
|
||||
return NULL;
|
||||
}
|
||||
try{
|
||||
IImage *img = renderer->CreateImage(bmp);
|
||||
LowLevelNativeImage *obj = img->GetLowLevelNativeImage(false);
|
||||
return obj;
|
||||
}catch(const std::exception& ex){
|
||||
ScriptContextUtils().SetNativeException(ex);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
LowLevelNativeModel *CreateModel(VoxelModel *model) {
|
||||
if(!MakeSureAvailable()){
|
||||
return NULL;
|
||||
}
|
||||
try{
|
||||
IModel *img = renderer->CreateModel(model);
|
||||
LowLevelNativeModel *obj = img->GetLowLevelNativeModel(false);
|
||||
return obj;
|
||||
}catch(const std::exception& ex){
|
||||
ScriptContextUtils().SetNativeException(ex);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
IRenderer::IRenderer() {
|
||||
scriptLLRenderer = NULL;
|
||||
scriptRenderer = NULL;
|
||||
}
|
||||
|
||||
IRenderer::~IRenderer() {
|
||||
if(scriptLLRenderer){
|
||||
scriptLLRenderer->renderer = NULL;
|
||||
scriptLLRenderer->Release();
|
||||
}
|
||||
}
|
||||
|
||||
LowLevelNativeRenderer *IRenderer::GetLowLevelNativeRenderer() {
|
||||
if(!scriptLLRenderer){
|
||||
scriptLLRenderer = new LowLevelNativeRenderer(this);
|
||||
}
|
||||
}
|
||||
|
||||
asIScriptObject *IRenderer::GetScriptRenderer() {
|
||||
if(!scriptRenderer){
|
||||
|
||||
asIScriptEngine *eng = ScriptManager::GetInstance()->GetEngine();
|
||||
asIObjectType *typ = eng->GetObjectTypeByName("spades::NativeRenderer");
|
||||
asIScriptFunction *func = typ->GetFactoryByDecl("NativeRenderer @NativeRenderer(LowLevelNativeRenderer@)");
|
||||
|
||||
ScriptContextHandle handle = ScriptManager::GetInstance()->GetContext();
|
||||
handle->Prepare(func);
|
||||
handle->SetArgObject(0, GetLowLevelNativeRenderer());
|
||||
handle.ExecuteChecked();
|
||||
|
||||
scriptRenderer = static_cast<asIScriptObject *>(handle->GetReturnObject());
|
||||
}
|
||||
return scriptRenderer;
|
||||
}
|
||||
|
||||
class LowLevelNativeRendererRegistrar: public ScriptObjectRegistrar {
|
||||
public:
|
||||
LowLevelNativeRendererRegistrar():
|
||||
ScriptObjectRegistrar("LowLevelNativeRenderer"){
|
||||
|
||||
}
|
||||
virtual void Register(ScriptManager *manager, Phase phase) {
|
||||
asIScriptEngine *eng = manager->GetEngine();
|
||||
int r;
|
||||
eng->SetDefaultNamespace("spades");
|
||||
switch(phase){
|
||||
case PhaseObjectType:
|
||||
r = eng->RegisterObjectType("LowLevelNativeRenderer",
|
||||
0, asOBJ_REF);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("LowLevelNativeRenderer",
|
||||
asBEHAVE_ADDREF, "void f()",
|
||||
asMETHOD(LowLevelNativeRenderer, AddRef),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("LowLevelNativeRenderer",
|
||||
asBEHAVE_RELEASE, "void f()",
|
||||
asMETHOD(LowLevelNativeRenderer, Release),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
|
||||
break;
|
||||
case PhaseObjectMember:
|
||||
r = eng->RegisterObjectMethod("LowLevelNativeRenderer",
|
||||
"LowLevelNativeImage@ RegisterImage(const string& in)",
|
||||
asMETHOD(LowLevelNativeRenderer, RegisterImage),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("LowLevelNativeRenderer",
|
||||
"LowLevelNativeModel@ RegisterModel(const string& in)",
|
||||
asMETHOD(LowLevelNativeRenderer, RegisterModel),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("LowLevelNativeRenderer",
|
||||
"LowLevelNativeImage@ CreateImage(Bitmap@)",
|
||||
asMETHOD(LowLevelNativeRenderer, CreateImage),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("LowLevelNativeRenderer",
|
||||
"LowLevelNativeModel@ CreateModel(VoxelModel@)",
|
||||
asMETHOD(LowLevelNativeRenderer, CreateModel),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static LowLevelNativeRendererRegistrar registrar;
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@
|
||||
#include "../Core/Math.h"
|
||||
#include "SceneDefinition.h"
|
||||
#include "IModel.h"
|
||||
#include <Core/ScriptManager.h>
|
||||
#include <Core/RefCountedObject.h>
|
||||
|
||||
namespace spades {
|
||||
class Bitmap;
|
||||
@ -68,15 +68,12 @@ namespace spades {
|
||||
}
|
||||
};
|
||||
|
||||
class LowLevelNativeRenderer;
|
||||
|
||||
class IRenderer {
|
||||
LowLevelNativeRenderer *scriptLLRenderer;
|
||||
asIScriptObject *scriptRenderer;
|
||||
class IRenderer: public RefCountedObject {
|
||||
protected:
|
||||
virtual ~IRenderer(){}
|
||||
public:
|
||||
|
||||
IRenderer();
|
||||
virtual ~IRenderer();
|
||||
IRenderer(){}
|
||||
|
||||
virtual void Init() = 0;
|
||||
|
||||
@ -129,9 +126,6 @@ namespace spades {
|
||||
|
||||
virtual float ScreenWidth() = 0;
|
||||
virtual float ScreenHeight() = 0;
|
||||
|
||||
LowLevelNativeRenderer *GetLowLevelNativeRenderer();
|
||||
asIScriptObject *GetScriptRenderer();
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -181,9 +181,9 @@ namespace spades{
|
||||
}
|
||||
|
||||
void LimboView::Draw() {
|
||||
IImage *menuItemImage = renderer->RegisterImage("Gfx/Limbo/MenuItem.tga");
|
||||
IImage *menuItemBigImage = renderer->RegisterImage("Gfx/Limbo/BigMenuItem.tga");
|
||||
//IImage *menuItemRingImage = renderer->RegisterImage("Gfx/Limbo/MenuItemRing.tga");
|
||||
Handle<IImage> menuItemImage = renderer->RegisterImage("Gfx/Limbo/MenuItem.tga");
|
||||
Handle<IImage> menuItemBigImage = renderer->RegisterImage("Gfx/Limbo/BigMenuItem.tga");
|
||||
//Handle<IImage> menuItemRingImage = renderer->RegisterImage("Gfx/Limbo/MenuItemRing.tga");
|
||||
IFont *font = client->textFont;
|
||||
|
||||
float left = (renderer->ScreenWidth() - contentsWidth) * .5f;
|
||||
@ -266,7 +266,7 @@ namespace spades{
|
||||
}
|
||||
}
|
||||
|
||||
IImage *cursor = renderer->RegisterImage("Gfx/Limbo/Cursor.tga");
|
||||
Handle<IImage> cursor = renderer->RegisterImage("Gfx/Limbo/Cursor.tga");
|
||||
|
||||
renderer->SetColor(MakeVector4(1, 1, 1, 1));
|
||||
renderer->DrawImage(cursor, AABB2(cursorPos.x - 8,
|
||||
|
@ -218,7 +218,7 @@ namespace spades {
|
||||
|
||||
// fades bg
|
||||
if(largeMap) {
|
||||
IImage *bg = renderer->RegisterImage("Gfx/MapBg.png");
|
||||
Handle<IImage> bg = renderer->RegisterImage("Gfx/MapBg.png");
|
||||
Vector2 scrSize = {renderer->ScreenWidth(),
|
||||
renderer->ScreenHeight()};
|
||||
float size = std::max(scrSize.x, scrSize.y);
|
||||
@ -230,7 +230,7 @@ namespace spades {
|
||||
}
|
||||
|
||||
// draw border
|
||||
IImage *border;
|
||||
Handle<IImage> border;
|
||||
float borderWidth;
|
||||
AABB2 borderRect = outRect;
|
||||
if(largeMap) {
|
||||
@ -294,7 +294,7 @@ namespace spades {
|
||||
// draw grid
|
||||
|
||||
renderer->SetColor(MakeVector4(0,0,0,0.8*alpha));
|
||||
IImage *dashLine = renderer->RegisterImage("Gfx/DashLine.tga");
|
||||
Handle<IImage> dashLine = renderer->RegisterImage("Gfx/DashLine.tga");
|
||||
for(float x = 64.f; x < map->Width(); x += 64.f){
|
||||
float wx = (x - inRect.GetMinX()) / inRect.GetWidth();
|
||||
if(wx < 0.f || wx >= 1.f)
|
||||
@ -318,7 +318,7 @@ namespace spades {
|
||||
|
||||
// draw grid label
|
||||
renderer->SetColor(MakeVector4(1,1,1,0.8*alpha));
|
||||
IImage *mapFont = renderer->RegisterImage("Gfx/Fonts/MapFont.tga");
|
||||
Handle<IImage> mapFont = renderer->RegisterImage("Gfx/Fonts/MapFont.tga");
|
||||
for(int i = 0; i < 8; i++){
|
||||
float startX = (float)i * 64.f;
|
||||
float endX = startX + 64.f;
|
||||
@ -369,7 +369,7 @@ namespace spades {
|
||||
}
|
||||
|
||||
//draw objects
|
||||
IImage *playerIcon = renderer->RegisterImage("Gfx/Player.tga");
|
||||
Handle<IImage> playerIcon = renderer->RegisterImage("Gfx/Player.tga");
|
||||
|
||||
{
|
||||
|
||||
@ -402,9 +402,9 @@ namespace spades {
|
||||
|
||||
CTFGameMode *ctf = dynamic_cast<CTFGameMode *>(world->GetMode());
|
||||
if(ctf){
|
||||
IImage *intelIcon = renderer->RegisterImage("Gfx/Intel.tga");
|
||||
IImage *baseIcon = renderer->RegisterImage("Gfx/CTFBase.tga");
|
||||
IImage *medicalIcon = renderer->RegisterImage("Gfx/Medical.tga");
|
||||
Handle<IImage> intelIcon = renderer->RegisterImage("Gfx/Intel.tga");
|
||||
Handle<IImage> baseIcon = renderer->RegisterImage("Gfx/CTFBase.tga");
|
||||
Handle<IImage> medicalIcon = renderer->RegisterImage("Gfx/Medical.tga");
|
||||
for(int tId = 0; tId < 2; tId++){
|
||||
CTFGameMode::Team& team = ctf->GetTeam(tId);
|
||||
IntVector3 teamColor = world->GetTeam(tId).color;
|
||||
@ -445,7 +445,7 @@ namespace spades {
|
||||
|
||||
TCGameMode *tc = dynamic_cast<TCGameMode *>(world->GetMode());
|
||||
if(tc){
|
||||
IImage *icon = renderer->RegisterImage("Gfx/TCTerritory.tga");
|
||||
Handle<IImage> icon = renderer->RegisterImage("Gfx/TCTerritory.tga");
|
||||
int cnt = tc->GetNumTerritories();
|
||||
for(int i = 0; i < cnt; i++){
|
||||
TCGameMode::Territory *t = tc->GetTerritory(i);
|
||||
|
@ -154,7 +154,7 @@ namespace spades {
|
||||
}
|
||||
|
||||
void PaletteView::Draw() {
|
||||
IImage *img = renderer->RegisterImage("Gfx/Palette.png");
|
||||
Handle<IImage> img = renderer->RegisterImage("Gfx/Palette.png");
|
||||
|
||||
int sel = GetSelectedIndex();
|
||||
|
||||
|
@ -160,7 +160,12 @@ namespace spades {
|
||||
radius,
|
||||
angle);
|
||||
}
|
||||
|
||||
void ParticleSpriteEntity::SetImage(IImage *img) {
|
||||
if(img == image) return;
|
||||
image->Release();
|
||||
image = img;
|
||||
image->AddRef();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ namespace spades {
|
||||
blockHitAction = act;
|
||||
}
|
||||
|
||||
void SetImage(IImage *img) { image = img;}
|
||||
void SetImage(IImage *img);
|
||||
void SetColor(Vector4 col) { color = col;}
|
||||
|
||||
IRenderer *GetRenderer() { return renderer; }
|
||||
|
@ -34,6 +34,7 @@ namespace spades {
|
||||
glyphHeight(gh), spaceWidth(sw){
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
tex->AddRef();
|
||||
for(int i = 0; i < 128; i++){
|
||||
int x = *(mp++);
|
||||
int y = *(mp++);
|
||||
@ -60,7 +61,7 @@ namespace spades {
|
||||
|
||||
Quake3Font::~Quake3Font(){
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
tex->Release();
|
||||
}
|
||||
|
||||
Vector2 Quake3Font::Measure(const std::string &txt) {
|
||||
|
@ -91,7 +91,7 @@ namespace spades {
|
||||
ctf = dynamic_cast<CTFGameMode *>(world->GetMode());
|
||||
tc = dynamic_cast<TCGameMode *>(world->GetMode());
|
||||
|
||||
IImage *image;
|
||||
Handle<IImage>image;
|
||||
IFont *font;
|
||||
Vector2 pos, size;
|
||||
char buf[256];
|
||||
@ -99,7 +99,7 @@ namespace spades {
|
||||
float scrWidth = renderer->ScreenWidth();
|
||||
float scrHeight = renderer->ScreenHeight();
|
||||
const Vector4 whiteColor = {1,1,1,1};
|
||||
IImage *whiteImage = renderer->RegisterImage("Gfx/White.tga");
|
||||
Handle<IImage> whiteImage = renderer->RegisterImage("Gfx/White.tga");
|
||||
|
||||
float teamBarTop = 120.f;
|
||||
float teamBarHeight = 60.f;
|
||||
|
@ -37,6 +37,8 @@ namespace spades{
|
||||
char buf[256];
|
||||
sprintf(buf, "Textures/Smoke/%03d.tga", i);
|
||||
lastSeq[i] = r->RegisterImage(buf);
|
||||
|
||||
lastSeq[i]->Release(); // renderer owns this
|
||||
}
|
||||
|
||||
lastRenderer = r;
|
||||
|
@ -74,8 +74,8 @@ namespace spades {
|
||||
float scrW = renderer->ScreenWidth();
|
||||
float scrH = renderer->ScreenHeight();
|
||||
|
||||
IImage *prgBg = renderer->RegisterImage("Gfx/TC/ProgressBg.png");
|
||||
IImage *prgBar = renderer->RegisterImage("Gfx/TC/ProgressBar.png");
|
||||
Handle<IImage> prgBg = renderer->RegisterImage("Gfx/TC/ProgressBg.png");
|
||||
Handle<IImage> prgBar = renderer->RegisterImage("Gfx/TC/ProgressBar.png");
|
||||
|
||||
Player *p = w->GetLocalPlayer();
|
||||
if(p && p->GetTeamId() < 2 && p->IsAlive()){
|
||||
|
@ -39,8 +39,6 @@ namespace spades {
|
||||
|
||||
pixels = new uint32_t[w * h];
|
||||
SPAssert(pixels != NULL);
|
||||
|
||||
refCount = 1;
|
||||
}
|
||||
|
||||
Bitmap::~Bitmap() {
|
||||
@ -93,16 +91,6 @@ namespace spades {
|
||||
|
||||
}
|
||||
|
||||
void Bitmap::AddRef() {
|
||||
asAtomicInc(refCount);
|
||||
}
|
||||
|
||||
void Bitmap::Release(){
|
||||
if(asAtomicDec(refCount) <= 0) {
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t Bitmap::GetPixel(int x, int y) {
|
||||
SPAssert(x >= 0); SPAssert(y >= 0);
|
||||
SPAssert(x < w); SPAssert(y < h);
|
||||
@ -115,120 +103,5 @@ namespace spades {
|
||||
pixels[x + y * w] = p;
|
||||
}
|
||||
|
||||
class BitmapRegistrar: public ScriptObjectRegistrar {
|
||||
static Bitmap *Factory(int w, int h){
|
||||
return new Bitmap(w, h);
|
||||
}
|
||||
|
||||
static Bitmap *LoadFactory(const std::string& str){
|
||||
try{
|
||||
return Bitmap::Load(str);
|
||||
}catch(const std::exception& ex) {
|
||||
ScriptContextUtils().SetNativeException(ex);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static bool Save(const std::string& str,
|
||||
Bitmap *bmp) {
|
||||
try{
|
||||
bmp->Save(str);
|
||||
}catch(const std::exception& ex) {
|
||||
// FIXME: returning error message?
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static uint32_t GetPixel(int x, int y,
|
||||
Bitmap *bmp) {
|
||||
if(x < 0 || y < 0 || x >= bmp->GetWidth() || y >= bmp->GetHeight()){
|
||||
asGetActiveContext()->SetException("Attempted to fetch a pixel outside the valid range.");
|
||||
return 0;
|
||||
}
|
||||
return bmp->GetPixel(x, y);
|
||||
}
|
||||
|
||||
static void SetPixel(int x, int y, uint32_t val,
|
||||
Bitmap *bmp) {
|
||||
if(x < 0 || y < 0 || x >= bmp->GetWidth() || y >= bmp->GetHeight()){
|
||||
asGetActiveContext()->SetException("Attempted to write a pixel outside the valid range.");
|
||||
return;
|
||||
}
|
||||
bmp->SetPixel(x, y, val);
|
||||
}
|
||||
|
||||
public:
|
||||
BitmapRegistrar():
|
||||
ScriptObjectRegistrar("Bitmap") {}
|
||||
|
||||
virtual void Register(ScriptManager *manager, Phase phase) {
|
||||
asIScriptEngine *eng = manager->GetEngine();
|
||||
int r;
|
||||
eng->SetDefaultNamespace("spades");
|
||||
switch(phase){
|
||||
case PhaseObjectType:
|
||||
r = eng->RegisterObjectType("Bitmap",
|
||||
0, asOBJ_REF);
|
||||
manager->CheckError(r);
|
||||
break;
|
||||
case PhaseObjectMember:
|
||||
r = eng->RegisterObjectBehaviour("Bitmap",
|
||||
asBEHAVE_ADDREF,
|
||||
"void f()",
|
||||
asMETHOD(Bitmap, AddRef),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("Bitmap",
|
||||
asBEHAVE_RELEASE,
|
||||
"void f()",
|
||||
asMETHOD(Bitmap, Release),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("Bitmap",
|
||||
asBEHAVE_FACTORY,
|
||||
"Bitmap @f(int, int)",
|
||||
asFUNCTION(Factory),
|
||||
asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("Bitmap",
|
||||
asBEHAVE_FACTORY,
|
||||
"Bitmap @f(const string& in)",
|
||||
asFUNCTION(LoadFactory),
|
||||
asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("Bitmap",
|
||||
"void Save(const string& in)",
|
||||
asFUNCTION(Save),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("Bitmap",
|
||||
"uint GetPixel(int, int)",
|
||||
asFUNCTION(GetPixel),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("Bitmap",
|
||||
"void SetPixel(int, int, uint)",
|
||||
asFUNCTION(SetPixel),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("Bitmap",
|
||||
"int get_Width()",
|
||||
asMETHOD(Bitmap, GetWidth),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("Bitmap",
|
||||
"int get_Height()",
|
||||
asMETHOD(Bitmap, GetHeight),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static BitmapRegistrar registrar;
|
||||
}
|
||||
|
@ -23,16 +23,17 @@
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include "Debug.h"
|
||||
#include <Core/RefCountedObject.h>
|
||||
|
||||
namespace spades {
|
||||
class IStream;
|
||||
class Bitmap {
|
||||
class Bitmap: public RefCountedObject {
|
||||
int w, h;
|
||||
uint32_t *pixels;
|
||||
int refCount;
|
||||
protected:
|
||||
~Bitmap();
|
||||
public:
|
||||
Bitmap(int w, int h);
|
||||
~Bitmap();
|
||||
|
||||
static Bitmap *Load(const std::string&);
|
||||
void Save(const std::string&);
|
||||
@ -44,7 +45,5 @@ namespace spades {
|
||||
uint32_t GetPixel(int x, int y);
|
||||
void SetPixel(int x, int y, uint32_t);
|
||||
|
||||
void AddRef();
|
||||
void Release();
|
||||
};
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ namespace spades {
|
||||
int height = img->h();
|
||||
int pitch = width * depth + img->ld();
|
||||
|
||||
Bitmap *bmp;
|
||||
Handle<Bitmap> bmp;
|
||||
try{
|
||||
bmp = new Bitmap(width, height);
|
||||
}catch(...){
|
||||
@ -113,10 +113,9 @@ namespace spades {
|
||||
}
|
||||
}
|
||||
delete img;
|
||||
return bmp;
|
||||
return bmp.Unmanage();
|
||||
}catch(...){
|
||||
delete img;
|
||||
delete bmp;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
@ -20,21 +20,20 @@
|
||||
|
||||
#include "Math.h"
|
||||
#include <stdlib.h>
|
||||
#include "ScriptManager.h"
|
||||
#include <new>
|
||||
|
||||
namespace spades {
|
||||
/*
|
||||
Vector3 Line3::Project(spades::Vector3 v,
|
||||
bool supposeUnbounded) {
|
||||
|
||||
}
|
||||
|
||||
float Line3::GetDistanceTo(spades::Vector3 v,
|
||||
bool supposeUnbounded){
|
||||
|
||||
}
|
||||
*/
|
||||
Vector3 Line3::Project(spades::Vector3 v,
|
||||
bool supposeUnbounded) {
|
||||
|
||||
}
|
||||
|
||||
float Line3::GetDistanceTo(spades::Vector3 v,
|
||||
bool supposeUnbounded){
|
||||
|
||||
}
|
||||
*/
|
||||
void Matrix4Multiply(const float a[16], const float b[16], float out[16]) {
|
||||
out[ 0] = b[ 0]*a[ 0] + b[ 1]*a[ 4] + b[ 2]*a[ 8] + b[ 3]*a[12];
|
||||
out[ 1] = b[ 0]*a[ 1] + b[ 1]*a[ 5] + b[ 2]*a[ 9] + b[ 3]*a[13];
|
||||
@ -250,7 +249,7 @@ namespace spades {
|
||||
start -= origin;
|
||||
|
||||
Vector3 end = start + dir;
|
||||
|
||||
|
||||
float dotX = Vector3::Dot(dir, normX);
|
||||
float dotY = Vector3::Dot(dir, normY);
|
||||
float dotZ = Vector3::Dot(dir, normZ);
|
||||
@ -526,708 +525,4 @@ namespace spades {
|
||||
Vector3 Mix(Vector3 a, Vector3 b, float frac) {
|
||||
return a + (b - a) * frac;
|
||||
}
|
||||
|
||||
class MathScriptObjectRegistrar: public ScriptObjectRegistrar {
|
||||
public:
|
||||
MathScriptObjectRegistrar():
|
||||
ScriptObjectRegistrar("Math"){}
|
||||
virtual void Register(ScriptManager *manager, Phase phase) {
|
||||
asIScriptEngine *eng = manager->GetEngine();
|
||||
int r;
|
||||
eng->SetDefaultNamespace("spades");
|
||||
switch(phase){
|
||||
case PhaseObjectType:
|
||||
r = eng->RegisterObjectType("IntVector3",
|
||||
sizeof(IntVector3),
|
||||
asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CAK | asOBJ_APP_CLASS_ALLINTS);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectType("Vector2",
|
||||
sizeof(Vector2),
|
||||
asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CAK | asOBJ_APP_CLASS_ALLFLOATS);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectType("Vector3",
|
||||
sizeof(Vector3),
|
||||
asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CAK | asOBJ_APP_CLASS_ALLFLOATS);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectType("Vector4",
|
||||
sizeof(Vector4),
|
||||
asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CAK | asOBJ_APP_CLASS_ALLFLOATS);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectType("Matrix4",
|
||||
sizeof(Matrix4),
|
||||
asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CAK | asOBJ_APP_CLASS_ALLFLOATS);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectType("AABB2",
|
||||
sizeof(AABB2),
|
||||
asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CAK | asOBJ_APP_CLASS_ALLFLOATS);
|
||||
manager->CheckError(r);
|
||||
break;
|
||||
case PhaseObjectMember:
|
||||
struct IntVector3Funcs {
|
||||
static void Construct1(IntVector3 *self) {
|
||||
new(self) IntVector3();
|
||||
}
|
||||
static void Construct2(const IntVector3& old, IntVector3 *self) {
|
||||
new(self) IntVector3(old);
|
||||
}
|
||||
static void Construct3(int x, int y, int z, IntVector3 *self) {
|
||||
new(self) IntVector3();
|
||||
self->x = x; self->y = y; self->z = z;
|
||||
}
|
||||
static void Construct4(const Vector3& old, IntVector3 *self) {
|
||||
new(self) IntVector3();
|
||||
self->x = (int)old.x; self->y = (int)old.y; self->z = (int)old.z;
|
||||
}
|
||||
};
|
||||
r = eng->RegisterObjectProperty("IntVector3",
|
||||
"int x",
|
||||
asOFFSET(IntVector3, x));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("IntVector3",
|
||||
"int y",
|
||||
asOFFSET(IntVector3, y));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("IntVector3",
|
||||
"int z",
|
||||
asOFFSET(IntVector3, z));
|
||||
manager->CheckError(r);
|
||||
// Register the constructors
|
||||
r = eng->RegisterObjectBehaviour("IntVector3", asBEHAVE_CONSTRUCT,
|
||||
"void f()",
|
||||
asFUNCTION(IntVector3Funcs::Construct1),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("IntVector3", asBEHAVE_CONSTRUCT,
|
||||
"void f(const IntVector3 &in)",
|
||||
asFUNCTION(IntVector3Funcs::Construct2),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("IntVector3", asBEHAVE_CONSTRUCT,
|
||||
"void f(int, int, int)",
|
||||
asFUNCTION(IntVector3Funcs::Construct3),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("IntVector3", asBEHAVE_CONSTRUCT,
|
||||
"void f(const Vector3 &in)",
|
||||
asFUNCTION(IntVector3Funcs::Construct4),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
|
||||
// Register the operator overloads
|
||||
r = eng->RegisterObjectMethod("IntVector3",
|
||||
"IntVector3 &opAddAssign(const IntVector3 &in)",
|
||||
asMETHODPR(IntVector3, operator+=, (const IntVector3 &), IntVector3&), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("IntVector3",
|
||||
"IntVector3 &opSubAssign(const IntVector3 &in)",
|
||||
asMETHODPR(IntVector3, operator-=, (const IntVector3 &), IntVector3&), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("IntVector3",
|
||||
"IntVector3 &opMulAssign(const IntVector3 &in)",
|
||||
asMETHODPR(IntVector3, operator*=, (const IntVector3 &), IntVector3&), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("IntVector3",
|
||||
"IntVector3 &opDivAssign(const IntVector3 &in)",
|
||||
asMETHODPR(IntVector3, operator/=, (const IntVector3 &), IntVector3&), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("IntVector3",
|
||||
"bool opEquals(const IntVector3 &in) const",
|
||||
asMETHODPR(IntVector3, operator==, (const IntVector3 &) const, bool), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("IntVector3",
|
||||
"IntVector3 opAdd(const IntVector3 &in) const",
|
||||
asMETHODPR(IntVector3, operator+, (const IntVector3 &) const, IntVector3), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("IntVector3",
|
||||
"IntVector3 opSub(const IntVector3 &in) const",
|
||||
asMETHODPR(IntVector3, operator-, (const IntVector3 &) const, IntVector3), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("IntVector3",
|
||||
"IntVector3 opMul(const IntVector3 &in) const",
|
||||
asMETHODPR(IntVector3, operator*, (const IntVector3 &) const, IntVector3), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("IntVector3",
|
||||
"IntVector3 opDiv(const IntVector3 &in) const",
|
||||
asMETHODPR(IntVector3, operator/, (const IntVector3 &) const, IntVector3), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
|
||||
// Register the object methods
|
||||
r = eng->RegisterObjectMethod("IntVector3",
|
||||
"int get_ManhattanLength() const",
|
||||
asMETHOD(IntVector3, GetManhattanLength),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterObjectMethod("IntVector3",
|
||||
"int get_ChebyshevLength() const",
|
||||
asMETHOD(IntVector3, GetChebyshevLength),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterGlobalFunction("int Dot(const IntVector3& in, const IntVector3& in)",
|
||||
asFUNCTION(IntVector3::Dot),
|
||||
asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
|
||||
|
||||
struct Vector2Funcs {
|
||||
static void Construct1(Vector2 *self) {
|
||||
new(self) Vector2();
|
||||
}
|
||||
static void Construct2(const Vector2& old, Vector2 *self) {
|
||||
new(self) Vector2(old);
|
||||
}
|
||||
static void Construct3(float x, float y, Vector2 *self) {
|
||||
new(self) Vector2();
|
||||
self->x = x; self->y = y;
|
||||
}
|
||||
};
|
||||
r = eng->RegisterObjectProperty("Vector2",
|
||||
"float x",
|
||||
asOFFSET(Vector2, x));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("Vector2",
|
||||
"float y",
|
||||
asOFFSET(Vector2, y));
|
||||
manager->CheckError(r);
|
||||
|
||||
// Register the constructors
|
||||
r = eng->RegisterObjectBehaviour("Vector2", asBEHAVE_CONSTRUCT,
|
||||
"void f()",
|
||||
asFUNCTION(Vector2Funcs::Construct1),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("Vector2", asBEHAVE_CONSTRUCT,
|
||||
"void f(const Vector2 &in)",
|
||||
asFUNCTION(Vector2Funcs::Construct2),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("Vector2", asBEHAVE_CONSTRUCT,
|
||||
"void f(float, float)",
|
||||
asFUNCTION(Vector2Funcs::Construct3),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
|
||||
// Register the operator overloads
|
||||
r = eng->RegisterObjectMethod("Vector2",
|
||||
"Vector2 &opAddAssign(const Vector2 &in)",
|
||||
asMETHODPR(Vector2, operator+=, (const Vector2 &), Vector2&), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("Vector2",
|
||||
"Vector2 &opSubAssign(const Vector2 &in)",
|
||||
asMETHODPR(Vector2, operator-=, (const Vector2 &), Vector2&), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("Vector2",
|
||||
"Vector2 &opMulAssign(const Vector2 &in)",
|
||||
asMETHODPR(Vector2, operator*=, (const Vector2 &), Vector2&), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("Vector2",
|
||||
"Vector2 &opDivAssign(const Vector2 &in)",
|
||||
asMETHODPR(Vector2, operator/=, (const Vector2 &), Vector2&), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("Vector2",
|
||||
"bool opEquals(const Vector2 &in) const",
|
||||
asMETHODPR(Vector2, operator==, (const Vector2 &) const, bool), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("Vector2",
|
||||
"Vector2 opAdd(const Vector2 &in) const",
|
||||
asMETHODPR(Vector2, operator+, (const Vector2 &) const, Vector2), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("Vector2",
|
||||
"Vector2 opSub(const Vector2 &in) const",
|
||||
asMETHODPR(Vector2, operator-, (const Vector2 &) const, Vector2), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("Vector2",
|
||||
"Vector2 opMul(const Vector2 &in) const",
|
||||
asMETHODPR(Vector2, operator*, (const Vector2 &) const, Vector2), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("Vector2",
|
||||
"Vector2 opDiv(const Vector2 &in) const",
|
||||
asMETHODPR(Vector2, operator/, (const Vector2 &) const, Vector2), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
|
||||
// Register the object methods
|
||||
r = eng->RegisterObjectMethod("Vector2",
|
||||
"float get_Length() const",
|
||||
asMETHOD(Vector2, GetLength),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterObjectMethod("Vector2",
|
||||
"float get_LengthPowered() const",
|
||||
asMETHOD(Vector2, GetPoweredLength),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterObjectMethod("Vector2",
|
||||
"float get_ManhattanLength() const",
|
||||
asMETHOD(Vector2, GetManhattanLength),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterObjectMethod("Vector2",
|
||||
"float get_ChebyshevLength() const",
|
||||
asMETHOD(Vector2, GetChebyshevLength),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterObjectMethod("Vector2",
|
||||
"float get_Normalized() const",
|
||||
asMETHOD(Vector2, Normalize),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterGlobalFunction("float Dot(const Vector2& in, const Vector2& in)",
|
||||
asFUNCTION(Vector2::Dot),
|
||||
asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
|
||||
struct Vector3Funcs {
|
||||
static void Construct1(Vector3 *self) {
|
||||
new(self) Vector3();
|
||||
}
|
||||
static void Construct2(const Vector3& old, Vector3 *self) {
|
||||
new(self) Vector3(old);
|
||||
}
|
||||
static void Construct3(float x, float y, float z, Vector3 *self) {
|
||||
new(self) Vector3();
|
||||
self->x = x; self->y = y; self->z = z;
|
||||
}
|
||||
static void Construct4(const IntVector3& old, Vector3 *self) {
|
||||
new(self) Vector3();
|
||||
self->x = old.x; self->y = old.y; self->z = old.z;
|
||||
}
|
||||
static Vector3 Floor(const Vector3& v) {
|
||||
return Vector3::Make(floorf(v.x), floorf(v.y), floorf(v.z));
|
||||
}
|
||||
static Vector3 Ceil(const Vector3& v) {
|
||||
return Vector3::Make(ceilf(v.x), ceilf(v.y), ceilf(v.z));
|
||||
}
|
||||
};
|
||||
r = eng->RegisterObjectProperty("Vector3",
|
||||
"float x",
|
||||
asOFFSET(Vector3, x));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("Vector3",
|
||||
"float y",
|
||||
asOFFSET(Vector3, y));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("Vector3",
|
||||
"float z",
|
||||
asOFFSET(Vector3, z));
|
||||
manager->CheckError(r);
|
||||
// Register the constructors
|
||||
r = eng->RegisterObjectBehaviour("Vector3", asBEHAVE_CONSTRUCT,
|
||||
"void f()",
|
||||
asFUNCTION(Vector3Funcs::Construct1),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("Vector3", asBEHAVE_CONSTRUCT,
|
||||
"void f(const Vector3 &in)",
|
||||
asFUNCTION(Vector3Funcs::Construct2),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("Vector3", asBEHAVE_CONSTRUCT,
|
||||
"void f(float, float, float)",
|
||||
asFUNCTION(Vector3Funcs::Construct3),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("Vector3", asBEHAVE_CONSTRUCT,
|
||||
"void f(const IntVector3&in)",
|
||||
asFUNCTION(Vector3Funcs::Construct4),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
|
||||
// Register the operator overloads
|
||||
r = eng->RegisterObjectMethod("Vector3",
|
||||
"Vector3 &opAddAssign(const Vector3 &in)",
|
||||
asMETHODPR(Vector3, operator+=, (const Vector3 &), Vector3&), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("Vector3",
|
||||
"Vector3 &opSubAssign(const Vector3 &in)",
|
||||
asMETHODPR(Vector3, operator-=, (const Vector3 &), Vector3&), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("Vector3",
|
||||
"Vector3 &opMulAssign(const Vector3 &in)",
|
||||
asMETHODPR(Vector3, operator*=, (const Vector3 &), Vector3&), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("Vector3",
|
||||
"Vector3 &opDivAssign(const Vector3 &in)",
|
||||
asMETHODPR(Vector3, operator/=, (const Vector3 &), Vector3&), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("Vector3",
|
||||
"bool opEquals(const Vector3 &in) const",
|
||||
asMETHODPR(Vector3, operator==, (const Vector3 &) const, bool), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("Vector3",
|
||||
"Vector3 opAdd(const Vector3 &in) const",
|
||||
asMETHODPR(Vector3, operator+, (const Vector3 &) const, Vector3), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("Vector3",
|
||||
"Vector3 opSub(const Vector3 &in) const",
|
||||
asMETHODPR(Vector3, operator-, (const Vector3 &) const, Vector3), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("Vector3",
|
||||
"Vector3 opMul(const Vector3 &in) const",
|
||||
asMETHODPR(Vector3, operator*, (const Vector3 &) const, Vector3), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("Vector3",
|
||||
"Vector3 opDiv(const Vector3 &in) const",
|
||||
asMETHODPR(Vector3, operator/, (const Vector3 &) const, Vector3), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
|
||||
// Register the object methods
|
||||
r = eng->RegisterObjectMethod("Vector3",
|
||||
"float get_Length() const",
|
||||
asMETHOD(Vector3, GetLength),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterObjectMethod("Vector3",
|
||||
"float get_LengthPowered() const",
|
||||
asMETHOD(Vector3, GetPoweredLength),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterObjectMethod("Vector3",
|
||||
"float get_ManhattanLength() const",
|
||||
asMETHOD(Vector3, GetManhattanLength),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterObjectMethod("Vector3",
|
||||
"float get_ChebyshevLength() const",
|
||||
asMETHOD(Vector3, GetChebyshevLength),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterObjectMethod("Vector3",
|
||||
"float get_Normalized() const",
|
||||
asMETHOD(Vector3, Normalize),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterGlobalFunction("float Dot(const Vector3& in, const Vector3& in)",
|
||||
asFUNCTION(Vector3::Dot),
|
||||
asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterGlobalFunction("Vector3 Floor(const Vector3& in)",
|
||||
asFUNCTION(Vector3Funcs::Floor),
|
||||
asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterGlobalFunction("Vector3 Ceil(const Vector3& in)",
|
||||
asFUNCTION(Vector3Funcs::Ceil),
|
||||
asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
|
||||
|
||||
struct Matrix4Funcs {
|
||||
static void Construct1(Matrix4 *self) {
|
||||
new(self) Matrix4();
|
||||
*self = Matrix4::Identity();
|
||||
}
|
||||
static void Construct2(const Matrix4& old, Matrix4 *self) {
|
||||
new(self) Matrix4(old);
|
||||
}
|
||||
static void Construct3(float m00, float m10, float m20, float m30,
|
||||
float m01, float m11, float m21, float m31,
|
||||
float m02, float m12, float m22, float m32,
|
||||
float m03, float m13, float m23, float m33,
|
||||
Matrix4 *self) {
|
||||
new(self) Matrix4(m00, m10, m20, m30,
|
||||
m01, m11, m21, m31,
|
||||
m02, m12, m22, m32,
|
||||
m03, m13, m23, m33);
|
||||
}
|
||||
};
|
||||
r = eng->RegisterObjectProperty("Matrix4",
|
||||
"float m00",
|
||||
asOFFSET(Matrix4, m[0]));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("Matrix4",
|
||||
"float m10",
|
||||
asOFFSET(Matrix4, m[1]));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("Matrix4",
|
||||
"float m20",
|
||||
asOFFSET(Matrix4, m[2]));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("Matrix4",
|
||||
"float m30",
|
||||
asOFFSET(Matrix4, m[3]));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("Matrix4",
|
||||
"float m01",
|
||||
asOFFSET(Matrix4, m[4]));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("Matrix4",
|
||||
"float m11",
|
||||
asOFFSET(Matrix4, m[5]));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("Matrix4",
|
||||
"float m21",
|
||||
asOFFSET(Matrix4, m[6]));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("Matrix4",
|
||||
"float m31",
|
||||
asOFFSET(Matrix4, m[7]));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("Matrix4",
|
||||
"float m02",
|
||||
asOFFSET(Matrix4, m[8]));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("Matrix4",
|
||||
"float m12",
|
||||
asOFFSET(Matrix4, m[9]));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("Matrix4",
|
||||
"float m22",
|
||||
asOFFSET(Matrix4, m[10]));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("Matrix4",
|
||||
"float m32",
|
||||
asOFFSET(Matrix4, m[11]));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("Matrix4",
|
||||
"float m03",
|
||||
asOFFSET(Matrix4, m[12]));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("Matrix4",
|
||||
"float m13",
|
||||
asOFFSET(Matrix4, m[13]));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("Matrix4",
|
||||
"float m23",
|
||||
asOFFSET(Matrix4, m[14]));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("Matrix4",
|
||||
"float m33",
|
||||
asOFFSET(Matrix4, m[15]));
|
||||
manager->CheckError(r);
|
||||
// Register the constructors
|
||||
r = eng->RegisterObjectBehaviour("Matrix4", asBEHAVE_CONSTRUCT,
|
||||
"void f()",
|
||||
asFUNCTION(Matrix4Funcs::Construct1),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("Matrix4", asBEHAVE_CONSTRUCT,
|
||||
"void f(const Matrix4 &in)",
|
||||
asFUNCTION(Matrix4Funcs::Construct2),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("Matrix4", asBEHAVE_CONSTRUCT,
|
||||
"void f(float, float, float, float,"
|
||||
"float, float, float, float,"
|
||||
"float, float, float, float,"
|
||||
"float, float, float, float)",
|
||||
asFUNCTION(Matrix4Funcs::Construct3),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
|
||||
// Register the operator overloads
|
||||
r = eng->RegisterObjectMethod("Matrix4",
|
||||
"Matrix4 &opMulAssign(const Matrix4 &in)",
|
||||
asMETHODPR(Matrix4, operator*=, (const Matrix4 &), Matrix4&), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("Matrix4",
|
||||
"Matrix4 opMul(const Matrix4 &in) const",
|
||||
asMETHODPR(Matrix4, operator*, (const Matrix4 &) const, Matrix4), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
|
||||
// Register the object methods
|
||||
r = eng->RegisterObjectMethod("Matrix4",
|
||||
"Matrix4 get_Transposed() const",
|
||||
asMETHOD(Matrix4, Transposed),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterObjectMethod("Matrix4",
|
||||
"Matrix4 get_Inversed() const",
|
||||
asMETHOD(Matrix4, Inversed),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterObjectMethod("Matrix4",
|
||||
"float get_InversedFast() const",
|
||||
asMETHOD(Matrix4, InversedFast),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterObjectMethod("Matrix4",
|
||||
"Vector3 GetOrigin() const",
|
||||
asMETHOD(Matrix4, GetOrigin),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterObjectMethod("Matrix4",
|
||||
"Vector3 GetAxis(int) const",
|
||||
asMETHOD(Matrix4, GetAxis),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterGlobalFunction("Matrix4 CreateTranslateMatrix(Vector3)",
|
||||
asFUNCTIONPR(Matrix4::Translate, (Vector3), Matrix4),
|
||||
asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterGlobalFunction("Matrix4 CreateTranslateMatrix(float, float, float)",
|
||||
asFUNCTIONPR(Matrix4::Translate, (float,float,float), Matrix4),
|
||||
asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterGlobalFunction("Matrix4 CreateRotateMatrix(Vector3, float)",
|
||||
asFUNCTION(Matrix4::Rotate),
|
||||
asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterGlobalFunction("Matrix4 CreateScaleMatrix(float)",
|
||||
asFUNCTIONPR(Matrix4::Scale, (float), Matrix4),
|
||||
asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterGlobalFunction("Matrix4 CreateScaleMatrix(Vector3)",
|
||||
asFUNCTIONPR(Matrix4::Scale, (Vector3), Matrix4),
|
||||
asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterGlobalFunction("Matrix4 CreateScaleMatrix(float, float, float)",
|
||||
asFUNCTIONPR(Matrix4::Scale, (float,float,float), Matrix4),
|
||||
asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterGlobalFunction("Matrix4 CreateMatrixFromAxes(Vector3,Vector3,Vector3,Vector3)",
|
||||
asFUNCTION(Matrix4::FromAxis),
|
||||
asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
|
||||
|
||||
struct AABB2Funcs {
|
||||
static void Construct1(AABB2 *self) {
|
||||
new(self) AABB2();
|
||||
}
|
||||
static void Construct2(const AABB2& old, AABB2 *self) {
|
||||
new(self) AABB2(old);
|
||||
}
|
||||
static void Construct3(float x, float y, float w, float h, AABB2 *self) {
|
||||
new(self) AABB2(x, y, w, h);
|
||||
}
|
||||
static void Construct4(Vector2 minVec, Vector2 maxVec, AABB2 *self) {
|
||||
new(self) AABB2(minVec, maxVec);
|
||||
}
|
||||
};
|
||||
r = eng->RegisterObjectProperty("AABB2",
|
||||
"Vector2 min",
|
||||
asOFFSET(AABB2, min));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("AABB2",
|
||||
"Vector2 max",
|
||||
asOFFSET(AABB2, max));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("AABB2",
|
||||
"float minX",
|
||||
asOFFSET(AABB2, min.x));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("AABB2",
|
||||
"float minY",
|
||||
asOFFSET(AABB2, min.y));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("AABB2",
|
||||
"float maxX",
|
||||
asOFFSET(AABB2, max.x));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("AABB2",
|
||||
"float maxY",
|
||||
asOFFSET(AABB2, max.y));
|
||||
manager->CheckError(r);
|
||||
|
||||
// Register the constructors
|
||||
r = eng->RegisterObjectBehaviour("AABB2", asBEHAVE_CONSTRUCT,
|
||||
"void f()",
|
||||
asFUNCTION(AABB2Funcs::Construct1),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("AABB2", asBEHAVE_CONSTRUCT,
|
||||
"void f(const AABB2 &in)",
|
||||
asFUNCTION(AABB2Funcs::Construct2),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("AABB2", asBEHAVE_CONSTRUCT,
|
||||
"void f(float, float, float, float)",
|
||||
asFUNCTION(AABB2Funcs::Construct3),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("AABB2", asBEHAVE_CONSTRUCT,
|
||||
"void f(Vector2, Vector2)",
|
||||
asFUNCTION(AABB2Funcs::Construct4),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
|
||||
// Register the operator overloads
|
||||
r = eng->RegisterObjectMethod("AABB2",
|
||||
"bool Contains(const Vector2 &in)",
|
||||
asMETHOD(AABB2, Contains), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("AABB2",
|
||||
"bool Intersects(const AABB2 &in)",
|
||||
asMETHOD(AABB2, Intersects), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("AABB2",
|
||||
"void Add(const Vector2& in)",
|
||||
asMETHODPR(AABB2, operator+=, (const Vector2 &), void), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("AABB2",
|
||||
"void Add(const AABB2& in)",
|
||||
asMETHODPR(AABB2, operator+=, (const AABB2 &), void), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
|
||||
|
||||
/*** Other Global Functions ***/
|
||||
|
||||
r = eng->RegisterGlobalFunction("string Replace(const string&in, const string& in, const string&in)",
|
||||
asFUNCTION(Replace),
|
||||
asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterGlobalFunction("string TrimSpaces(const string&in)",
|
||||
asFUNCTION(TrimSpaces),
|
||||
asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterGlobalFunction("float GetRandom()",
|
||||
asFUNCTION(GetRandom),
|
||||
asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterGlobalFunction("float Mix(float,float,float)",
|
||||
asFUNCTIONPR(Mix, (float,float,float), float),
|
||||
asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterGlobalFunction("Vector2 Mix(Vector2,Vector2,Vector2)",
|
||||
asFUNCTIONPR(Mix, (Vector2,Vector2,float), Vector2),
|
||||
asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterGlobalFunction("Vector3 Mix(Vector3,Vector3,Vector3)",
|
||||
asFUNCTIONPR(Mix, (Vector3,Vector3,float), Vector3),
|
||||
asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterGlobalFunction("float SmoothStep(float)",
|
||||
asFUNCTION(SmoothStep),
|
||||
asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
static MathScriptObjectRegistrar registrar;
|
||||
}
|
||||
|
@ -1,9 +1,41 @@
|
||||
//
|
||||
// RefCountedObject.cpp
|
||||
// OpenSpades
|
||||
//
|
||||
// Created by Tomoaki Kawada on 9/14/13.
|
||||
// Copyright (c) 2013 yvt.jp. All rights reserved.
|
||||
//
|
||||
/*
|
||||
Copyright (c) 2013 yvt
|
||||
|
||||
This file is part of OpenSpades.
|
||||
|
||||
OpenSpades 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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenSpades 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 OpenSpades. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
#include "RefCountedObject.h"
|
||||
#include "../ScriptBindings/ScriptManager.h"
|
||||
|
||||
namespace spades {
|
||||
RefCountedObject::RefCountedObject() {
|
||||
refCount = 1;
|
||||
}
|
||||
|
||||
RefCountedObject::~RefCountedObject(){
|
||||
|
||||
}
|
||||
|
||||
void RefCountedObject::AddRef() {
|
||||
asAtomicInc(refCount);
|
||||
}
|
||||
|
||||
void RefCountedObject::Release() {
|
||||
if(asAtomicInc(refCount) <= 0)
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,102 @@
|
||||
//
|
||||
// RefCountedObject.h
|
||||
// OpenSpades
|
||||
//
|
||||
// Created by Tomoaki Kawada on 9/14/13.
|
||||
// Copyright (c) 2013 yvt.jp. All rights reserved.
|
||||
//
|
||||
/*
|
||||
Copyright (c) 2013 yvt
|
||||
|
||||
This file is part of OpenSpades.
|
||||
|
||||
OpenSpades 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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenSpades 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 OpenSpades. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef __OpenSpades__RefCountedObject__
|
||||
#define __OpenSpades__RefCountedObject__
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include "Debug.h"
|
||||
|
||||
#endif /* defined(__OpenSpades__RefCountedObject__) */
|
||||
namespace spades {
|
||||
|
||||
class RefCountedObject {
|
||||
int refCount;
|
||||
protected:
|
||||
virtual ~RefCountedObject();
|
||||
public:
|
||||
RefCountedObject();
|
||||
|
||||
void AddRef();
|
||||
void Release();
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class Handle {
|
||||
T *ptr;
|
||||
public:
|
||||
Handle(T *ptr, bool add = false):ptr(ptr) {
|
||||
if(ptr && add)
|
||||
ptr->AddRef();
|
||||
}
|
||||
Handle(): ptr(0) {}
|
||||
Handle(const Handle<T>& h): ptr(h.ptr) {
|
||||
if(ptr)
|
||||
ptr->AddRef();
|
||||
}
|
||||
~Handle() {
|
||||
if(ptr)
|
||||
ptr->Release();
|
||||
}
|
||||
T *operator ->() {
|
||||
SPAssert(ptr != NULL);
|
||||
return ptr;
|
||||
}
|
||||
const T *operator ->() const {
|
||||
SPAssert(ptr != NULL);
|
||||
return ptr;
|
||||
}
|
||||
T& operator *() {
|
||||
SPAssert(ptr != NULL);
|
||||
return *ptr;
|
||||
}
|
||||
const T& operator *() const {
|
||||
SPAssert(ptr != NULL);
|
||||
return *ptr;
|
||||
}
|
||||
void Set(T *p, bool add = false) {
|
||||
if(p == ptr){
|
||||
if(!add)
|
||||
ptr->Release();
|
||||
return;
|
||||
}
|
||||
T *old = ptr;
|
||||
ptr = p;
|
||||
if(add)
|
||||
ptr->AddRef();
|
||||
if(old)
|
||||
old->Release();
|
||||
}
|
||||
void operator =(T *p){
|
||||
Set(p);
|
||||
}
|
||||
void operator =(const Handle<T>& h){
|
||||
Set(h.ptr, true);
|
||||
}
|
||||
operator T *() {
|
||||
SPAssert(ptr != NULL);
|
||||
return ptr;
|
||||
}
|
||||
T *Unmanage() {
|
||||
SPAssert(ptr != NULL);
|
||||
T *p = ptr;
|
||||
ptr = NULL;
|
||||
return p;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
@ -45,7 +45,6 @@ namespace spades {
|
||||
|
||||
std::fill(solidBits, solidBits + w * h, 0);
|
||||
|
||||
refCount = 1;
|
||||
|
||||
}
|
||||
VoxelModel::~VoxelModel() {
|
||||
@ -167,171 +166,5 @@ namespace spades {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
void VoxelModel::AddRef() {
|
||||
asAtomicInc(refCount);
|
||||
}
|
||||
|
||||
void VoxelModel::Release(){
|
||||
if(asAtomicDec(refCount) <= 0){
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
class VoxelModelRegistrar: public ScriptObjectRegistrar {
|
||||
static VoxelModel *Factory(int w, int h, int d){
|
||||
try{
|
||||
return new VoxelModel(w, h, d);
|
||||
}catch(const std::exception& ex){
|
||||
ScriptContextUtils().SetNativeException(ex);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
static VoxelModel *LoadFactory(const std::string& fn){
|
||||
spades::IStream *stream = NULL;
|
||||
try{
|
||||
stream = FileManager::OpenForReading(fn.c_str());
|
||||
VoxelModel *ret = VoxelModel::LoadKV6(stream);
|
||||
delete stream;
|
||||
return ret;
|
||||
}catch(const std::exception& ex) {
|
||||
ScriptContextUtils().SetNativeException(ex);
|
||||
if(stream) delete stream;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
static uint64_t GetSolidBits(int x, int y,
|
||||
VoxelModel *m) {
|
||||
if(x < 0 || y < 0 || x >= m->GetWidth() || y >= m->GetHeight()) {
|
||||
asGetActiveContext()->SetException("Attempted to access a voxel outside the valid range.");
|
||||
return 0;
|
||||
}
|
||||
return m->GetSolidBitsAt(x, y);
|
||||
}
|
||||
|
||||
static uint32_t GetColor(int x, int y, int z,
|
||||
VoxelModel *m) {
|
||||
if(x < 0 || y < 0 || x >= m->GetWidth() || y >= m->GetHeight() ||
|
||||
z < 0 || z >= m->GetDepth()) {
|
||||
asGetActiveContext()->SetException("Attempted to access a voxel outside the valid range.");
|
||||
return 0;
|
||||
}
|
||||
return m->GetColor(x, y, z);
|
||||
}
|
||||
|
||||
static bool IsSolid(int x, int y, int z,
|
||||
VoxelModel *m) {
|
||||
if(x < 0 || y < 0 || x >= m->GetWidth() || y >= m->GetHeight() ||
|
||||
z < 0 || z >= m->GetDepth()) {
|
||||
asGetActiveContext()->SetException("Attempted to access a voxel outside the valid range.");
|
||||
return 0;
|
||||
}
|
||||
return m->IsSolid(x, y, z);
|
||||
}
|
||||
static void SetAir(int x, int y, int z,
|
||||
VoxelModel *m) {
|
||||
if(x < 0 || y < 0 || x >= m->GetWidth() || y >= m->GetHeight() ||
|
||||
z < 0 || z >= m->GetDepth()) {
|
||||
asGetActiveContext()->SetException("Attempted to access a voxel outside the valid range.");
|
||||
return;
|
||||
}
|
||||
m->SetAir(x, y, z);
|
||||
}
|
||||
static void SetSolid(int x, int y, int z, uint32_t col,
|
||||
VoxelModel *m) {
|
||||
if(x < 0 || y < 0 || x >= m->GetWidth() || y >= m->GetHeight() ||
|
||||
z < 0 || z >= m->GetDepth()) {
|
||||
asGetActiveContext()->SetException("Attempted to access a voxel outside the valid range.");
|
||||
return;
|
||||
}
|
||||
m->SetSolid(x, y, z, col);
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
VoxelModelRegistrar():
|
||||
ScriptObjectRegistrar("VoxelModel") {}
|
||||
|
||||
virtual void Register(ScriptManager *manager, Phase phase) {
|
||||
asIScriptEngine *eng = manager->GetEngine();
|
||||
int r;
|
||||
eng->SetDefaultNamespace("spades");
|
||||
switch(phase){
|
||||
case PhaseObjectType:
|
||||
r = eng->RegisterObjectType("VoxelModel",
|
||||
0, asOBJ_REF);
|
||||
manager->CheckError(r);
|
||||
break;
|
||||
case PhaseObjectMember:
|
||||
r = eng->RegisterObjectBehaviour("VoxelModel",
|
||||
asBEHAVE_ADDREF,
|
||||
"void f()",
|
||||
asMETHOD(VoxelModel, AddRef),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("VoxelModel",
|
||||
asBEHAVE_RELEASE,
|
||||
"void f()",
|
||||
asMETHOD(VoxelModel, Release),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("VoxelModel",
|
||||
asBEHAVE_FACTORY,
|
||||
"VoxelModel @f(int, int, int)",
|
||||
asFUNCTION(Factory),
|
||||
asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("VoxelModel",
|
||||
asBEHAVE_FACTORY,
|
||||
"VoxelModel @f(const string& in)",
|
||||
asFUNCTION(LoadFactory),
|
||||
asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("VoxelModel",
|
||||
"uint GetSolidBits(int, int)",
|
||||
asFUNCTION(GetSolidBits),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("VoxelModel",
|
||||
"uint GetColor(int, int, int)",
|
||||
asFUNCTION(GetColor),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("VoxelModel",
|
||||
"bool IsSolid(int, int, int)",
|
||||
asFUNCTION(IsSolid),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("VoxelModel",
|
||||
"void SetAir(int, int, int)",
|
||||
asFUNCTION(SetAir),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("VoxelModel",
|
||||
"void SetSolid(int, int, int, uint)",
|
||||
asFUNCTION(SetSolid),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("VoxelModel",
|
||||
"int get_Width()",
|
||||
asMETHOD(VoxelModel, GetWidth),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("VoxelModel",
|
||||
"int get_Height()",
|
||||
asMETHOD(VoxelModel, GetHeight),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("VoxelModel",
|
||||
"int get_Depth()",
|
||||
asMETHOD(VoxelModel, GetDepth),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static VoxelModelRegistrar registrar;
|
||||
|
||||
}
|
||||
|
@ -24,17 +24,18 @@
|
||||
#include "../Core/Debug.h"
|
||||
#include "IStream.h"
|
||||
#include "Math.h"
|
||||
#include <Core/RefCountedObject.h>
|
||||
|
||||
namespace spades {
|
||||
class VoxelModel {
|
||||
class VoxelModel: public RefCountedObject {
|
||||
Vector3 origin;
|
||||
int width, height, depth;
|
||||
uint64_t *solidBits;
|
||||
uint32_t *colors;
|
||||
int refCount;
|
||||
protected:
|
||||
virtual ~VoxelModel();
|
||||
public:
|
||||
VoxelModel(int width, int height, int depth);
|
||||
~VoxelModel();
|
||||
|
||||
static VoxelModel *LoadKV6(IStream *);
|
||||
|
||||
@ -96,7 +97,5 @@ namespace spades {
|
||||
int GetHeight() const { return height; }
|
||||
int GetDepth() const { return depth; }
|
||||
|
||||
void AddRef();
|
||||
void Release();
|
||||
};
|
||||
}
|
||||
|
@ -37,12 +37,10 @@ namespace spades {
|
||||
for(int i = 0; i < chunkRows * chunkCols; i++)
|
||||
chunkInvalid.push_back(false);
|
||||
|
||||
Bitmap *bmp = GenerateBitmap(0, 0, m->Width(), m->Height());
|
||||
Handle<Bitmap> bmp = GenerateBitmap(0, 0, m->Width(), m->Height());
|
||||
try{
|
||||
image = static_cast<GLImage *>(renderer->CreateImage(bmp));
|
||||
delete bmp;
|
||||
}catch(...){
|
||||
delete bmp;
|
||||
throw;
|
||||
}
|
||||
|
||||
@ -58,12 +56,12 @@ namespace spades {
|
||||
}
|
||||
|
||||
GLFlatMapRenderer::~GLFlatMapRenderer() {
|
||||
delete image;
|
||||
image->Release();
|
||||
}
|
||||
|
||||
Bitmap *GLFlatMapRenderer::GenerateBitmap(int mx, int my, int w, int h){
|
||||
SPADES_MARK_FUNCTION();
|
||||
Bitmap *bmp = new Bitmap(w, h);
|
||||
Handle<Bitmap> bmp = new Bitmap(w, h);
|
||||
try{
|
||||
uint32_t *pixels = bmp->GetPixels();
|
||||
|
||||
@ -82,10 +80,9 @@ namespace spades {
|
||||
}
|
||||
}
|
||||
}catch(...){
|
||||
delete bmp;
|
||||
throw;
|
||||
}
|
||||
return bmp;
|
||||
return bmp.Unmanage();
|
||||
}
|
||||
|
||||
void GLFlatMapRenderer::GameMapChanged(int x, int y, int z,
|
||||
@ -115,14 +112,12 @@ namespace spades {
|
||||
int chunkX = ((int)i) % chunkCols;
|
||||
int chunkY = ((int)i) / chunkCols;
|
||||
|
||||
Bitmap *bmp = GenerateBitmap(chunkX * ChunkSize,
|
||||
Handle<Bitmap> bmp = GenerateBitmap(chunkX * ChunkSize,
|
||||
chunkY * ChunkSize,
|
||||
ChunkSize, ChunkSize);
|
||||
try{
|
||||
image->SubImage(bmp, chunkX * ChunkSize, chunkY * ChunkSize);
|
||||
delete bmp;
|
||||
}catch(...){
|
||||
delete bmp;
|
||||
throw;
|
||||
}
|
||||
chunkInvalid[i] = false;
|
||||
|
@ -31,14 +31,22 @@ namespace spades {
|
||||
width(w), height(h),
|
||||
autoDelete(autoDelete){
|
||||
SPADES_MARK_FUNCTION();
|
||||
valid = true;
|
||||
}
|
||||
GLImage::~GLImage(){
|
||||
SPADES_MARK_FUNCTION();
|
||||
if(autoDelete)
|
||||
device->DeleteTexture(tex);
|
||||
if(valid){
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
void GLImage::MakeSureValid() {
|
||||
if(!valid){
|
||||
SPRaise("Attempted to use an invalid image.");
|
||||
}
|
||||
}
|
||||
void GLImage::Bind(IGLDevice::Enum target) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
MakeSureValid();
|
||||
device->BindTexture(target, tex);
|
||||
}
|
||||
|
||||
@ -70,12 +78,22 @@ namespace spades {
|
||||
}
|
||||
|
||||
void GLImage::SubImage(spades::Bitmap *bmp, int x, int y){
|
||||
MakeSureValid();
|
||||
Bind(IGLDevice::Texture2D);
|
||||
device->TexSubImage2D(IGLDevice::Texture2D, 0,
|
||||
x, y, bmp->GetWidth(), bmp->GetHeight(),
|
||||
IGLDevice::RGBA, IGLDevice::UnsignedByte,
|
||||
bmp->GetPixels());
|
||||
}
|
||||
|
||||
void GLImage::Invalidate() {
|
||||
SPADES_MARK_FUNCTION();
|
||||
MakeSureValid();
|
||||
valid = false;
|
||||
|
||||
if(autoDelete)
|
||||
device->DeleteTexture(tex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,18 +32,22 @@ namespace spades {
|
||||
IGLDevice::UInteger tex;
|
||||
float width, height;
|
||||
bool autoDelete;
|
||||
bool valid;
|
||||
void MakeSureValid();
|
||||
protected:
|
||||
virtual ~GLImage();
|
||||
public:
|
||||
GLImage(IGLDevice::UInteger textureObject,
|
||||
IGLDevice *device, float w, float h,
|
||||
bool autoDelete = true);
|
||||
static GLImage *FromBitmap(Bitmap *, IGLDevice *);
|
||||
virtual ~GLImage();
|
||||
void Bind(IGLDevice::Enum target);
|
||||
|
||||
virtual float GetWidth() { return width; }
|
||||
virtual float GetHeight() { return height; }
|
||||
|
||||
void SubImage(Bitmap *bmp, int x, int y);
|
||||
void Invalidate();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,8 @@ namespace spades {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
for(std::map<std::string, GLImage *>::iterator it = images.begin(); it != images.end(); it++){
|
||||
delete it->second;
|
||||
it->second->Invalidate();
|
||||
it->second->Release();
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,6 +53,7 @@ namespace spades {
|
||||
images[name] = img;
|
||||
return img;
|
||||
}
|
||||
it->second->AddRef();
|
||||
return it->second;
|
||||
}
|
||||
|
||||
|
@ -53,6 +53,7 @@ namespace spades {
|
||||
models[name] = m;
|
||||
return m;
|
||||
}
|
||||
it->second->AddRef();
|
||||
return it->second;
|
||||
}
|
||||
|
||||
|
@ -98,7 +98,7 @@ namespace spades {
|
||||
GLOptimizedVoxelModel::~GLOptimizedVoxelModel() {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
delete image;
|
||||
image->Release();
|
||||
device->DeleteBuffer(idxBuffer);
|
||||
device->DeleteBuffer(buffer);
|
||||
}
|
||||
@ -113,10 +113,10 @@ namespace spades {
|
||||
}
|
||||
|
||||
BitmapAtlasGenerator::Result result = atlasGen.Pack();
|
||||
Bitmap *bmp = result.bitmap;
|
||||
Handle<Bitmap> bmp = result.bitmap;
|
||||
SPAssert(result.items.size() == bmps.size());
|
||||
for(size_t i = 0; i < bmps.size(); i++){
|
||||
delete bmps[i];
|
||||
bmps[i]->Release();
|
||||
}
|
||||
bmps.clear();
|
||||
|
||||
@ -140,7 +140,6 @@ namespace spades {
|
||||
std::vector<uint16_t>().swap(bmpIndex);
|
||||
|
||||
image = static_cast<GLImage *>(renderer->CreateImage(bmp));
|
||||
delete bmp;
|
||||
}
|
||||
|
||||
uint8_t GLOptimizedVoxelModel::calcAOID(VoxelModel *m,
|
||||
|
@ -843,13 +843,13 @@ namespace spades {
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, 0);
|
||||
device->Enable(IGLDevice::Blend, false);
|
||||
device->Viewport(0, 0, handle.GetWidth(), handle.GetHeight());
|
||||
GLImage image(handle.GetTexture(),
|
||||
device,
|
||||
handle.GetWidth(),
|
||||
handle.GetHeight(),
|
||||
false);
|
||||
Handle<GLImage> image = new GLImage(handle.GetTexture(),
|
||||
device,
|
||||
handle.GetWidth(),
|
||||
handle.GetHeight(),
|
||||
false);
|
||||
SetColor(MakeVector4(1, 1, 1, 1));
|
||||
DrawImage(&image, AABB2(0,handle.GetHeight(),handle.GetWidth(),-handle.GetHeight()));
|
||||
DrawImage(image, AABB2(0,handle.GetHeight(),handle.GetWidth(),-handle.GetHeight()));
|
||||
imageRenderer->Flush(); // must flush now because handle is released soon
|
||||
}
|
||||
|
||||
@ -1031,12 +1031,12 @@ namespace spades {
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, 0);
|
||||
device->Enable(IGLDevice::Blend, false);
|
||||
device->Viewport(0, 0, w,h);
|
||||
GLImage image(lastColorBufferTexture,
|
||||
Handle<GLImage> image = new GLImage(lastColorBufferTexture,
|
||||
device,
|
||||
w,h,
|
||||
false);
|
||||
SetColor(MakeVector4(1, 1, 1, 1));
|
||||
DrawImage(&image, AABB2(0,h,w,-h));
|
||||
DrawImage(image, AABB2(0,h,w,-h));
|
||||
imageRenderer->Flush(); // must flush now because handle is released soon
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,142 @@
|
||||
//
|
||||
// Bitmap.cpp
|
||||
// OpenSpades
|
||||
//
|
||||
// Created by Tomoaki Kawada on 9/14/13.
|
||||
// Copyright (c) 2013 yvt.jp. All rights reserved.
|
||||
//
|
||||
/*
|
||||
Copyright (c) 2013 yvt
|
||||
|
||||
This file is part of OpenSpades.
|
||||
|
||||
OpenSpades 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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenSpades 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 OpenSpades. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
#include "ScriptManager.h"
|
||||
#include <Core/Bitmap.h>
|
||||
|
||||
namespace spades {
|
||||
class BitmapRegistrar: public ScriptObjectRegistrar {
|
||||
static Bitmap *Factory(int w, int h){
|
||||
return new Bitmap(w, h);
|
||||
}
|
||||
|
||||
static Bitmap *LoadFactory(const std::string& str){
|
||||
try{
|
||||
return Bitmap::Load(str);
|
||||
}catch(const std::exception& ex) {
|
||||
ScriptContextUtils().SetNativeException(ex);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static bool Save(const std::string& str,
|
||||
Bitmap *bmp) {
|
||||
try{
|
||||
bmp->Save(str);
|
||||
}catch(const std::exception& ex) {
|
||||
// FIXME: returning error message?
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static uint32_t GetPixel(int x, int y,
|
||||
Bitmap *bmp) {
|
||||
if(x < 0 || y < 0 || x >= bmp->GetWidth() || y >= bmp->GetHeight()){
|
||||
asGetActiveContext()->SetException("Attempted to fetch a pixel outside the valid range.");
|
||||
return 0;
|
||||
}
|
||||
return bmp->GetPixel(x, y);
|
||||
}
|
||||
|
||||
static void SetPixel(int x, int y, uint32_t val,
|
||||
Bitmap *bmp) {
|
||||
if(x < 0 || y < 0 || x >= bmp->GetWidth() || y >= bmp->GetHeight()){
|
||||
asGetActiveContext()->SetException("Attempted to write a pixel outside the valid range.");
|
||||
return;
|
||||
}
|
||||
bmp->SetPixel(x, y, val);
|
||||
}
|
||||
|
||||
public:
|
||||
BitmapRegistrar():
|
||||
ScriptObjectRegistrar("Bitmap") {}
|
||||
|
||||
virtual void Register(ScriptManager *manager, Phase phase) {
|
||||
asIScriptEngine *eng = manager->GetEngine();
|
||||
int r;
|
||||
eng->SetDefaultNamespace("spades");
|
||||
switch(phase){
|
||||
case PhaseObjectType:
|
||||
r = eng->RegisterObjectType("Bitmap",
|
||||
0, asOBJ_REF);
|
||||
manager->CheckError(r);
|
||||
break;
|
||||
case PhaseObjectMember:
|
||||
r = eng->RegisterObjectBehaviour("Bitmap",
|
||||
asBEHAVE_ADDREF,
|
||||
"void f()",
|
||||
asMETHOD(Bitmap, AddRef),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("Bitmap",
|
||||
asBEHAVE_RELEASE,
|
||||
"void f()",
|
||||
asMETHOD(Bitmap, Release),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("Bitmap",
|
||||
asBEHAVE_FACTORY,
|
||||
"Bitmap @f(int, int)",
|
||||
asFUNCTION(Factory),
|
||||
asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("Bitmap",
|
||||
asBEHAVE_FACTORY,
|
||||
"Bitmap @f(const string& in)",
|
||||
asFUNCTION(LoadFactory),
|
||||
asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("Bitmap",
|
||||
"void Save(const string& in)",
|
||||
asFUNCTION(Save),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("Bitmap",
|
||||
"uint GetPixel(int, int)",
|
||||
asFUNCTION(GetPixel),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("Bitmap",
|
||||
"void SetPixel(int, int, uint)",
|
||||
asFUNCTION(SetPixel),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("Bitmap",
|
||||
"int get_Width()",
|
||||
asMETHOD(Bitmap, GetWidth),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("Bitmap",
|
||||
"int get_Height()",
|
||||
asMETHOD(Bitmap, GetHeight),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static BitmapRegistrar registrar;
|
||||
}
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -1,9 +1,248 @@
|
||||
//
|
||||
// GameMap.cpp
|
||||
// OpenSpades
|
||||
//
|
||||
// Created by Tomoaki Kawada on 9/14/13.
|
||||
// Copyright (c) 2013 yvt.jp. All rights reserved.
|
||||
//
|
||||
/*
|
||||
Copyright (c) 2013 yvt
|
||||
|
||||
This file is part of OpenSpades.
|
||||
|
||||
OpenSpades 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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenSpades 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 OpenSpades. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
#include <Client/GameMap.h>
|
||||
#include "ScriptManager.h"
|
||||
#include <Core/IStream.h>
|
||||
#include <Core/FileManager.h>
|
||||
|
||||
namespace spades {
|
||||
namespace client {
|
||||
|
||||
class GameMapRegistrar: public ScriptObjectRegistrar {
|
||||
static GameMap *Factory(int w, int h, int d){
|
||||
if(w != GameMap::DefaultWidth ||
|
||||
h != GameMap::DefaultHeight ||
|
||||
d != GameMap::DefaultDepth) {
|
||||
asGetActiveContext()->SetException("Currently, non-default GameMap dimensions aren't supported.");
|
||||
return NULL;
|
||||
}
|
||||
try{
|
||||
return new GameMap();
|
||||
}catch(const std::exception& ex){
|
||||
ScriptContextUtils().SetNativeException(ex);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
static GameMap *LoadFactory(const std::string& fn){
|
||||
spades::IStream *stream = NULL;
|
||||
try{
|
||||
stream = FileManager::OpenForReading(fn.c_str());
|
||||
GameMap *ret = GameMap::Load(stream);
|
||||
delete stream;
|
||||
return ret;
|
||||
}catch(const std::exception& ex) {
|
||||
ScriptContextUtils().SetNativeException(ex);
|
||||
if(stream) delete stream;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t GetColor(int x, int y, int z,
|
||||
GameMap *m) {
|
||||
if(x < 0 || y < 0 || x >= m->Width() || y >= m->Height() ||
|
||||
z < 0 || z >= m->Depth()) {
|
||||
asGetActiveContext()->SetException("Attempted to access a voxel outside the valid range.");
|
||||
return 0;
|
||||
}
|
||||
return m->GetColor(x, y, z);
|
||||
}
|
||||
|
||||
static bool IsSolid(int x, int y, int z,
|
||||
GameMap *m) {
|
||||
if(x < 0 || y < 0 || x >= m->Width() || y >= m->Height() ||
|
||||
z < 0 || z >= m->Depth()) {
|
||||
asGetActiveContext()->SetException("Attempted to access a voxel outside the valid range.");
|
||||
return 0;
|
||||
}
|
||||
return m->IsSolid(x, y, z);
|
||||
}
|
||||
static uint32_t GetColorWrapped(int x, int y, int z,
|
||||
GameMap *m) {
|
||||
return m->GetColorWrapped(x, y, z);
|
||||
}
|
||||
|
||||
static bool IsSolidWrapped(int x, int y, int z,
|
||||
GameMap *m) {
|
||||
return m->IsSolidWrapped(x, y, z);
|
||||
}
|
||||
static void SetAir(int x, int y, int z,
|
||||
GameMap *m) {
|
||||
if(x < 0 || y < 0 || x >= m->Width() || y >= m->Height() ||
|
||||
z < 0 || z >= m->Depth()) {
|
||||
asGetActiveContext()->SetException("Attempted to access a voxel outside the valid range.");
|
||||
return;
|
||||
}
|
||||
m->Set(x, y, z, false, 0);
|
||||
}
|
||||
static void SetSolid(int x, int y, int z, uint32_t col,
|
||||
GameMap *m) {
|
||||
if(x < 0 || y < 0 || x >= m->Width() || y >= m->Height() ||
|
||||
z < 0 || z >= m->Depth()) {
|
||||
asGetActiveContext()->SetException("Attempted to access a voxel outside the valid range.");
|
||||
return;
|
||||
}
|
||||
m->Set(x, y, z, true, col);
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
GameMapRegistrar():
|
||||
ScriptObjectRegistrar("GameMap") {}
|
||||
|
||||
virtual void Register(ScriptManager *manager, Phase phase) {
|
||||
asIScriptEngine *eng = manager->GetEngine();
|
||||
int r;
|
||||
eng->SetDefaultNamespace("spades");
|
||||
switch(phase){
|
||||
case PhaseObjectType:
|
||||
r = eng->RegisterObjectType("GameMap",
|
||||
0, asOBJ_REF);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectType("GameMapRayCastResult",
|
||||
sizeof(GameMap::RayCastResult), asOBJ_VALUE|asOBJ_POD|asOBJ_APP_CLASS_CDAK);
|
||||
manager->CheckError(r);
|
||||
break;
|
||||
case PhaseObjectMember:
|
||||
r = eng->RegisterObjectBehaviour("GameMap",
|
||||
asBEHAVE_ADDREF,
|
||||
"void f()",
|
||||
asMETHOD(GameMap, AddRef),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("GameMap",
|
||||
asBEHAVE_RELEASE,
|
||||
"void f()",
|
||||
asMETHOD(GameMap, Release),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("GameMap",
|
||||
asBEHAVE_FACTORY,
|
||||
"GameMap @f(int, int, int)",
|
||||
asFUNCTION(Factory),
|
||||
asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("GameMap",
|
||||
asBEHAVE_FACTORY,
|
||||
"GameMap @f(const string& in)",
|
||||
asFUNCTION(LoadFactory),
|
||||
asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("GameMap",
|
||||
"uint GetColor(int, int, int)",
|
||||
asFUNCTION(GetColor),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("GameMap",
|
||||
"bool IsSolid(int, int, int)",
|
||||
asFUNCTION(IsSolid),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("GameMap",
|
||||
"uint GetColorWrapped(int, int, int)",
|
||||
asFUNCTION(GetColorWrapped),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("GameMap",
|
||||
"bool IsSolidWrapped(int, int, int)",
|
||||
asFUNCTION(IsSolidWrapped),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("GameMap",
|
||||
"void SetAir(int, int, int)",
|
||||
asFUNCTION(SetAir),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("GameMap",
|
||||
"void SetSolid(int, int, int, uint)",
|
||||
asFUNCTION(SetSolid),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("GameMap",
|
||||
"int get_Width()",
|
||||
asMETHOD(GameMap, Width),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("GameMap",
|
||||
"int get_Height()",
|
||||
asMETHOD(GameMap, Height),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("GameMap",
|
||||
"int get_Depth()",
|
||||
asMETHOD(GameMap, Depth),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("GameMap",
|
||||
"bool ClipBox(int, int, int)",
|
||||
asMETHODPR(GameMap, ClipBox, (int,int,int), bool),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("GameMap",
|
||||
"bool ClipWorld(int, int, int)",
|
||||
asMETHODPR(GameMap, ClipBox, (int,int,int), bool),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("GameMap",
|
||||
"bool ClipBox(float, float, float)",
|
||||
asMETHODPR(GameMap, ClipBox, (float,float,float), bool),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("GameMap",
|
||||
"bool ClipWorld(float, float, float)",
|
||||
asMETHODPR(GameMap, ClipBox, (float,float,float), bool),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("GameMap",
|
||||
"GameMapRayCastResult CastRay(Vector3, Vector3, int)",
|
||||
asMETHOD(GameMap, CastRay2),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterObjectProperty("GameMapRayCastResult",
|
||||
"bool hit",
|
||||
asOFFSET(GameMap::RayCastResult, hit));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("GameMapRayCastResult",
|
||||
"bool startSolid",
|
||||
asOFFSET(GameMap::RayCastResult, startSolid));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("GameMapRayCastResult",
|
||||
"Vector3 hitPos",
|
||||
asOFFSET(GameMap::RayCastResult, hitPos));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("GameMapRayCastResult",
|
||||
"IntVector3 hitBlock",
|
||||
asOFFSET(GameMap::RayCastResult, hitBlock));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("GameMapRayCastResult",
|
||||
"IntVector3 normal",
|
||||
asOFFSET(GameMap::RayCastResult, normal));
|
||||
manager->CheckError(r);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static GameMapRegistrar registrar;
|
||||
}
|
||||
}
|
||||
|
||||
#include "GameMap.h"
|
||||
|
@ -1,9 +1,76 @@
|
||||
//
|
||||
// IImage.cpp
|
||||
// OpenSpades
|
||||
//
|
||||
// Created by Tomoaki Kawada on 9/14/13.
|
||||
// Copyright (c) 2013 yvt.jp. All rights reserved.
|
||||
//
|
||||
/*
|
||||
Copyright (c) 2013 yvt
|
||||
|
||||
This file is part of OpenSpades.
|
||||
|
||||
OpenSpades 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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenSpades 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 OpenSpades. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
#include "ScriptManager.h"
|
||||
#include <Client/IImage.h>
|
||||
|
||||
namespace spades{
|
||||
namespace client {
|
||||
|
||||
class ImageRegistrar: public ScriptObjectRegistrar {
|
||||
public:
|
||||
ImageRegistrar():
|
||||
ScriptObjectRegistrar("Image"){
|
||||
|
||||
}
|
||||
virtual void Register(ScriptManager *manager, Phase phase) {
|
||||
asIScriptEngine *eng = manager->GetEngine();
|
||||
int r;
|
||||
eng->SetDefaultNamespace("spades");
|
||||
switch(phase){
|
||||
case PhaseObjectType:
|
||||
r = eng->RegisterObjectType("Image",
|
||||
0, asOBJ_REF);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("Image",
|
||||
asBEHAVE_ADDREF, "void f()",
|
||||
asMETHOD(IImage, AddRef),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("Image",
|
||||
asBEHAVE_RELEASE, "void f()",
|
||||
asMETHOD(IImage, Release),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
|
||||
break;
|
||||
case PhaseObjectMember:
|
||||
r = eng->RegisterObjectMethod("Image",
|
||||
"float get_Width()",
|
||||
asMETHOD(IImage, GetWidth),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("Image",
|
||||
"float get_Height()",
|
||||
asMETHOD(IImage, GetHeight),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
break;
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static ImageRegistrar registrar;
|
||||
}
|
||||
}
|
||||
|
||||
#include "IImage.h"
|
||||
|
@ -1,9 +1,66 @@
|
||||
//
|
||||
// IModel.cpp
|
||||
// OpenSpades
|
||||
//
|
||||
// Created by Tomoaki Kawada on 9/14/13.
|
||||
// Copyright (c) 2013 yvt.jp. All rights reserved.
|
||||
//
|
||||
/*
|
||||
Copyright (c) 2013 yvt
|
||||
|
||||
This file is part of OpenSpades.
|
||||
|
||||
OpenSpades 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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenSpades 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 OpenSpades. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
#include "IModel.h"
|
||||
#include "ScriptManager.h"
|
||||
#include <Client/IModel.h>
|
||||
|
||||
namespace spades{
|
||||
namespace client {
|
||||
|
||||
|
||||
class ModelRegistrar: public ScriptObjectRegistrar {
|
||||
public:
|
||||
ModelRegistrar():
|
||||
ScriptObjectRegistrar("Model"){
|
||||
|
||||
}
|
||||
virtual void Register(ScriptManager *manager, Phase phase) {
|
||||
asIScriptEngine *eng = manager->GetEngine();
|
||||
int r;
|
||||
eng->SetDefaultNamespace("spades");
|
||||
switch(phase){
|
||||
case PhaseObjectType:
|
||||
r = eng->RegisterObjectType("Model",
|
||||
0, asOBJ_REF);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("Model",
|
||||
asBEHAVE_ADDREF, "void f()",
|
||||
asMETHOD(IModel, AddRef),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("Model",
|
||||
asBEHAVE_RELEASE, "void f()",
|
||||
asMETHOD(IModel, Release),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
|
||||
break;
|
||||
case PhaseObjectMember:
|
||||
break;
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static ModelRegistrar registrar;
|
||||
}
|
||||
}
|
@ -1,9 +1,87 @@
|
||||
//
|
||||
// IRenderer.cpp
|
||||
// OpenSpades
|
||||
//
|
||||
// Created by Tomoaki Kawada on 9/14/13.
|
||||
// Copyright (c) 2013 yvt.jp. All rights reserved.
|
||||
//
|
||||
/*
|
||||
Copyright (c) 2013 yvt
|
||||
|
||||
This file is part of OpenSpades.
|
||||
|
||||
OpenSpades 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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenSpades 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 OpenSpades. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
#include "IRenderer.h"
|
||||
#include "ScriptManager.h"
|
||||
#include <Client/IRenderer.h>
|
||||
|
||||
namespace spades {
|
||||
namespace client{
|
||||
|
||||
|
||||
|
||||
class RendererRegistrar: public ScriptObjectRegistrar {
|
||||
|
||||
public:
|
||||
RendererRegistrar():
|
||||
ScriptObjectRegistrar("Renderer"){
|
||||
|
||||
}
|
||||
virtual void Register(ScriptManager *manager, Phase phase) {
|
||||
asIScriptEngine *eng = manager->GetEngine();
|
||||
int r;
|
||||
eng->SetDefaultNamespace("spades");
|
||||
switch(phase){
|
||||
case PhaseObjectType:
|
||||
r = eng->RegisterObjectType("Renderer",
|
||||
0, asOBJ_REF);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("Renderer",
|
||||
asBEHAVE_ADDREF, "void f()",
|
||||
asMETHOD(IRenderer, AddRef),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("Renderer",
|
||||
asBEHAVE_RELEASE, "void f()",
|
||||
asMETHOD(IRenderer, Release),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
|
||||
break;
|
||||
case PhaseObjectMember:
|
||||
r = eng->RegisterObjectMethod("Renderer",
|
||||
"Image@ RegisterImage(const string& in)",
|
||||
asMETHOD(IRenderer, RegisterImage),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("Renderer",
|
||||
"Model@ RegisterModel(const string& in)",
|
||||
asMETHOD(IRenderer, RegisterModel),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("Renderer",
|
||||
"Image@ CreateImage(Bitmap@)",
|
||||
asMETHOD(IRenderer, CreateImage),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("Renderer",
|
||||
"Model@ CreateModel(VoxelModel@)",
|
||||
asMETHOD(IRenderer, CreateModel),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static RendererRegistrar registrar;
|
||||
}
|
||||
}
|
||||
|
@ -55,6 +55,10 @@ namespace spades {
|
||||
sizeof(Matrix4),
|
||||
asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CAK | asOBJ_APP_CLASS_ALLINTS);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectType("AABB2",
|
||||
sizeof(AABB2),
|
||||
asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CAK | asOBJ_APP_CLASS_ALLFLOATS);
|
||||
manager->CheckError(r);
|
||||
break;
|
||||
case PhaseObjectMember:
|
||||
struct IntVector3Funcs {
|
||||
@ -498,7 +502,86 @@ namespace spades {
|
||||
asFUNCTION(Matrix4::FromAxis),
|
||||
asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
struct AABB2Funcs {
|
||||
static void Construct1(AABB2 *self) {
|
||||
new(self) AABB2();
|
||||
}
|
||||
static void Construct2(const AABB2& old, AABB2 *self) {
|
||||
new(self) AABB2(old);
|
||||
}
|
||||
static void Construct3(float x, float y, float w, float h, AABB2 *self) {
|
||||
new(self) AABB2(x, y, w, h);
|
||||
}
|
||||
static void Construct4(Vector2 minVec, Vector2 maxVec, AABB2 *self) {
|
||||
new(self) AABB2(minVec, maxVec);
|
||||
}
|
||||
};
|
||||
r = eng->RegisterObjectProperty("AABB2",
|
||||
"Vector2 min",
|
||||
asOFFSET(AABB2, min));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("AABB2",
|
||||
"Vector2 max",
|
||||
asOFFSET(AABB2, max));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("AABB2",
|
||||
"float minX",
|
||||
asOFFSET(AABB2, min.x));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("AABB2",
|
||||
"float minY",
|
||||
asOFFSET(AABB2, min.y));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("AABB2",
|
||||
"float maxX",
|
||||
asOFFSET(AABB2, max.x));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("AABB2",
|
||||
"float maxY",
|
||||
asOFFSET(AABB2, max.y));
|
||||
manager->CheckError(r);
|
||||
|
||||
// Register the constructors
|
||||
r = eng->RegisterObjectBehaviour("AABB2", asBEHAVE_CONSTRUCT,
|
||||
"void f()",
|
||||
asFUNCTION(AABB2Funcs::Construct1),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("AABB2", asBEHAVE_CONSTRUCT,
|
||||
"void f(const AABB2 &in)",
|
||||
asFUNCTION(AABB2Funcs::Construct2),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("AABB2", asBEHAVE_CONSTRUCT,
|
||||
"void f(float, float, float, float)",
|
||||
asFUNCTION(AABB2Funcs::Construct3),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("AABB2", asBEHAVE_CONSTRUCT,
|
||||
"void f(Vector2, Vector2)",
|
||||
asFUNCTION(AABB2Funcs::Construct4),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
|
||||
// Register the operator overloads
|
||||
r = eng->RegisterObjectMethod("AABB2",
|
||||
"bool Contains(const Vector2 &in)",
|
||||
asMETHOD(AABB2, Contains), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("AABB2",
|
||||
"bool Intersects(const AABB2 &in)",
|
||||
asMETHOD(AABB2, Intersects), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("AABB2",
|
||||
"void Add(const Vector2& in)",
|
||||
asMETHODPR(AABB2, operator+=, (const Vector2 &), void), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("AABB2",
|
||||
"void Add(const AABB2& in)",
|
||||
asMETHODPR(AABB2, operator+=, (const AABB2 &), void), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
|
||||
|
||||
/*** Other Global Functions ***/
|
||||
|
||||
r = eng->RegisterGlobalFunction("string Replace(const string&in, const string& in, const string&in)",
|
||||
|
@ -21,16 +21,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "../AngelScript/include/angelscript.h"
|
||||
#include "../AngelScript/source/scriptany.h"
|
||||
#include "../AngelScript/source/scriptarray.h"
|
||||
#include "../AngelScript/source/scriptbuilder.h"
|
||||
#include "../AngelScript/source/scriptdictionary.h"
|
||||
#include "../AngelScript/source/scripthandle.h"
|
||||
#include "../AngelScript/source/scripthelper.h"
|
||||
#include "../AngelScript/source/scriptmath.h"
|
||||
#include "../AngelScript/source/scriptmathcomplex.h"
|
||||
#include "../AngelScript/source/scriptstdstring.h"
|
||||
#include "../AngelScript/source/weakref.h"
|
||||
#include "../AngelScript/addons/scriptany.h"
|
||||
#include "../AngelScript/addons/scriptarray.h"
|
||||
#include "../AngelScript/addons/scriptbuilder.h"
|
||||
#include "../AngelScript/addons/scriptdictionary.h"
|
||||
#include "../AngelScript/addons/scripthandle.h"
|
||||
#include "../AngelScript/addons/scripthelper.h"
|
||||
#include "../AngelScript/addons/scriptmath.h"
|
||||
#include "../AngelScript/addons/scriptmathcomplex.h"
|
||||
#include "../AngelScript/addons/scriptstdstring.h"
|
||||
#include "../AngelScript/addons/weakref.h"
|
||||
#include "Mutex.h"
|
||||
#include <list>
|
||||
|
||||
|
@ -1,9 +1,186 @@
|
||||
//
|
||||
// VoxelModel.cpp
|
||||
// OpenSpades
|
||||
//
|
||||
// Created by Tomoaki Kawada on 9/14/13.
|
||||
// Copyright (c) 2013 yvt.jp. All rights reserved.
|
||||
//
|
||||
/*
|
||||
Copyright (c) 2013 yvt
|
||||
|
||||
This file is part of OpenSpades.
|
||||
|
||||
OpenSpades 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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenSpades 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 OpenSpades. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <Core/VoxelModel.h>
|
||||
#include "ScriptManager.h"
|
||||
#include <Core/FileManager.h>
|
||||
|
||||
namespace spades {
|
||||
|
||||
|
||||
class VoxelModelRegistrar: public ScriptObjectRegistrar {
|
||||
static VoxelModel *Factory(int w, int h, int d){
|
||||
try{
|
||||
return new VoxelModel(w, h, d);
|
||||
}catch(const std::exception& ex){
|
||||
ScriptContextUtils().SetNativeException(ex);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
static VoxelModel *LoadFactory(const std::string& fn){
|
||||
spades::IStream *stream = NULL;
|
||||
try{
|
||||
stream = FileManager::OpenForReading(fn.c_str());
|
||||
VoxelModel *ret = VoxelModel::LoadKV6(stream);
|
||||
delete stream;
|
||||
return ret;
|
||||
}catch(const std::exception& ex) {
|
||||
ScriptContextUtils().SetNativeException(ex);
|
||||
if(stream) delete stream;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
static uint64_t GetSolidBits(int x, int y,
|
||||
VoxelModel *m) {
|
||||
if(x < 0 || y < 0 || x >= m->GetWidth() || y >= m->GetHeight()) {
|
||||
asGetActiveContext()->SetException("Attempted to access a voxel outside the valid range.");
|
||||
return 0;
|
||||
}
|
||||
return m->GetSolidBitsAt(x, y);
|
||||
}
|
||||
|
||||
static uint32_t GetColor(int x, int y, int z,
|
||||
VoxelModel *m) {
|
||||
if(x < 0 || y < 0 || x >= m->GetWidth() || y >= m->GetHeight() ||
|
||||
z < 0 || z >= m->GetDepth()) {
|
||||
asGetActiveContext()->SetException("Attempted to access a voxel outside the valid range.");
|
||||
return 0;
|
||||
}
|
||||
return m->GetColor(x, y, z);
|
||||
}
|
||||
|
||||
static bool IsSolid(int x, int y, int z,
|
||||
VoxelModel *m) {
|
||||
if(x < 0 || y < 0 || x >= m->GetWidth() || y >= m->GetHeight() ||
|
||||
z < 0 || z >= m->GetDepth()) {
|
||||
asGetActiveContext()->SetException("Attempted to access a voxel outside the valid range.");
|
||||
return 0;
|
||||
}
|
||||
return m->IsSolid(x, y, z);
|
||||
}
|
||||
static void SetAir(int x, int y, int z,
|
||||
VoxelModel *m) {
|
||||
if(x < 0 || y < 0 || x >= m->GetWidth() || y >= m->GetHeight() ||
|
||||
z < 0 || z >= m->GetDepth()) {
|
||||
asGetActiveContext()->SetException("Attempted to access a voxel outside the valid range.");
|
||||
return;
|
||||
}
|
||||
m->SetAir(x, y, z);
|
||||
}
|
||||
static void SetSolid(int x, int y, int z, uint32_t col,
|
||||
VoxelModel *m) {
|
||||
if(x < 0 || y < 0 || x >= m->GetWidth() || y >= m->GetHeight() ||
|
||||
z < 0 || z >= m->GetDepth()) {
|
||||
asGetActiveContext()->SetException("Attempted to access a voxel outside the valid range.");
|
||||
return;
|
||||
}
|
||||
m->SetSolid(x, y, z, col);
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
VoxelModelRegistrar():
|
||||
ScriptObjectRegistrar("VoxelModel") {}
|
||||
|
||||
virtual void Register(ScriptManager *manager, Phase phase) {
|
||||
asIScriptEngine *eng = manager->GetEngine();
|
||||
int r;
|
||||
eng->SetDefaultNamespace("spades");
|
||||
switch(phase){
|
||||
case PhaseObjectType:
|
||||
r = eng->RegisterObjectType("VoxelModel",
|
||||
0, asOBJ_REF);
|
||||
manager->CheckError(r);
|
||||
break;
|
||||
case PhaseObjectMember:
|
||||
r = eng->RegisterObjectBehaviour("VoxelModel",
|
||||
asBEHAVE_ADDREF,
|
||||
"void f()",
|
||||
asMETHOD(VoxelModel, AddRef),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("VoxelModel",
|
||||
asBEHAVE_RELEASE,
|
||||
"void f()",
|
||||
asMETHOD(VoxelModel, Release),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("VoxelModel",
|
||||
asBEHAVE_FACTORY,
|
||||
"VoxelModel @f(int, int, int)",
|
||||
asFUNCTION(Factory),
|
||||
asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("VoxelModel",
|
||||
asBEHAVE_FACTORY,
|
||||
"VoxelModel @f(const string& in)",
|
||||
asFUNCTION(LoadFactory),
|
||||
asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("VoxelModel",
|
||||
"uint GetSolidBits(int, int)",
|
||||
asFUNCTION(GetSolidBits),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("VoxelModel",
|
||||
"uint GetColor(int, int, int)",
|
||||
asFUNCTION(GetColor),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("VoxelModel",
|
||||
"bool IsSolid(int, int, int)",
|
||||
asFUNCTION(IsSolid),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("VoxelModel",
|
||||
"void SetAir(int, int, int)",
|
||||
asFUNCTION(SetAir),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("VoxelModel",
|
||||
"void SetSolid(int, int, int, uint)",
|
||||
asFUNCTION(SetSolid),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("VoxelModel",
|
||||
"int get_Width()",
|
||||
asMETHOD(VoxelModel, GetWidth),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("VoxelModel",
|
||||
"int get_Height()",
|
||||
asMETHOD(VoxelModel, GetHeight),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("VoxelModel",
|
||||
"int get_Depth()",
|
||||
asMETHOD(VoxelModel, GetDepth),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static VoxelModelRegistrar registrar;
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user