├── LICENSE ├── README.md ├── compiler source ├── LICENSE ├── Projects │ └── CompilerOSX │ │ └── clcc_0.7OSX.xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcuserdata │ │ │ └── milgra.xcuserdatad │ │ │ ├── UserInterfaceState.xcuserstate │ │ │ └── WorkspaceSettings.xcsettings │ │ └── xcuserdata │ │ └── milgra.xcuserdatad │ │ └── xcschemes │ │ ├── clcc_0.7OSX.xcscheme │ │ └── xcschememanagement.plist ├── README.md ├── Related │ └── clcc_0.7.c └── Sources │ ├── Analyzer.clc │ ├── CoreLib │ ├── CLChar.h │ ├── CLLink.h │ ├── CLObject.clc │ ├── CLObjectList.clc │ ├── CLString.clc │ └── CLStringObjectList.clc │ ├── Creator.clc │ ├── DataClass │ ├── ClassElements.clc │ ├── Constants.clc │ ├── FileElements.clc │ ├── Line.clc │ ├── Scope.clc │ └── Token.clc │ ├── Main.clc │ ├── Tokenizer.clc │ ├── clcsrc.c │ ├── clcsrc.h │ └── main.c ├── example project ├── LICENSE ├── Projects │ └── DynamicsXOSX │ │ ├── DynamicsX.xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcuserdata │ │ │ │ └── milgra.xcuserdatad │ │ │ │ ├── UserInterfaceState.xcuserstate │ │ │ │ └── WorkspaceSettings.xcsettings │ │ └── xcuserdata │ │ │ └── milgra.xcuserdatad │ │ │ ├── xcdebugger │ │ │ ├── Breakpoints.xcbkptlist │ │ │ └── Breakpoints_v2.xcbkptlist │ │ │ └── xcschemes │ │ │ ├── DynamicsX.xcscheme │ │ │ └── xcschememanagement.plist │ │ └── DynamicsX │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── DynamicsX-Info.plist │ │ ├── DynamicsX-Prefix.pch │ │ ├── GLView.h │ │ ├── GLView.m │ │ ├── en.lproj │ │ ├── InfoPlist.strings │ │ └── MainMenu.xib │ │ └── main.m ├── README.md ├── Related │ └── clcc_0.7.c └── Sources │ ├── Controller.clc │ ├── CoreLib │ ├── CLChar.h │ ├── CLDataList.clc │ ├── CLLink.h │ ├── CLObject.clc │ ├── CLObjectList.clc │ ├── CLString.clc │ ├── CLStringDataList.clc │ ├── CLStringObjectList.clc │ └── CLThread.clc │ ├── GLTexturePixelText.clc │ ├── GraphicsLib │ ├── GLBitmap.clc │ ├── GLBitmapPixelText.clc │ ├── GLDrawable.clc │ ├── GLShader.clc │ ├── GLTexture.clc │ ├── GLVertexBlock.clc │ ├── GLVertexBuffer.clc │ ├── GLVoxelLabel.clc │ └── Primitives │ │ ├── GLCubePC33.clc │ │ ├── GLCubePNC334.clc │ │ ├── GLDrawablePC33.clc │ │ ├── GLDrawablePNC334.clc │ │ ├── GLDrawablePT22.clc │ │ ├── GLGridPT22.clc │ │ ├── GLHalfCubePC33.clc │ │ ├── GLHalfCubePNC334.clc │ │ ├── GLPointP2.clc │ │ ├── GLRectPT22.clc │ │ ├── GLSegment.clc │ │ ├── GLSquarePC33.clc │ │ └── GLSquarePNC334.clc │ ├── Macros.h │ ├── MathLib │ ├── MLMatrix4.c │ ├── MLMatrix4.h │ ├── MLVector3.c │ ├── MLVector3.h │ ├── MLVector4.c │ └── MLVector4.h │ ├── PhysicsLib │ ├── PLMass.clc │ ├── PLSegment.clc │ ├── PLSpacer.clc │ ├── PLUniverse.clc │ └── PLVector.clc │ ├── Scene.clc │ ├── SceneBox.clc │ ├── SceneParticle.clc │ ├── ScenePit.clc │ ├── SceneSlope.clc │ ├── ShaderP2.clc │ ├── ShaderPT22.clc │ ├── TextLib │ ├── TLPixelFont.clc │ └── TLPixelText.clc │ ├── clcsrc.c │ └── clcsrc.h └── language ├── CoreLib ├── CLChar.h ├── CLDataList.clc ├── CLLink.h ├── CLObject.clc ├── CLObjectList.clc ├── CLString.clc ├── CLStringDataList.clc ├── CLStringObjectList.clc └── CLThread.clc ├── Introduction.pdf ├── Specification.pdf └── clcc.c /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | clc 2 | === 3 | 4 | Class-C programming language compiler, documentation, compiler source and example project. 5 | -------------------------------------------------------------------------------- /compiler source/LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /compiler source/Projects/CompilerOSX/clcc_0.7OSX.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /compiler source/Projects/CompilerOSX/clcc_0.7OSX.xcodeproj/project.xcworkspace/xcuserdata/milgra.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milgra/clc/ffa783390654f2b98e8e7f46a5855d22d87bb3e1/compiler source/Projects/CompilerOSX/clcc_0.7OSX.xcodeproj/project.xcworkspace/xcuserdata/milgra.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /compiler source/Projects/CompilerOSX/clcc_0.7OSX.xcodeproj/project.xcworkspace/xcuserdata/milgra.xcuserdatad/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges 6 | 7 | SnapshotAutomaticallyBeforeSignificantChanges 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /compiler source/Projects/CompilerOSX/clcc_0.7OSX.xcodeproj/xcuserdata/milgra.xcuserdatad/xcschemes/clcc_0.7OSX.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 51 | 52 | 58 | 59 | 60 | 61 | 62 | 63 | 69 | 70 | 76 | 77 | 78 | 79 | 81 | 82 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /compiler source/Projects/CompilerOSX/clcc_0.7OSX.xcodeproj/xcuserdata/milgra.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | clcc_0.7OSX.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 33160109184E0357003CD999 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /compiler source/README.md: -------------------------------------------------------------------------------- 1 | clcc 2 | ==== 3 | 4 | Class-C source-to-source compiler by Milan Toth 5 | 6 | The Projects folder contains the project files for various platforms and IDE's, it only contains the OSX/xCode 5.0 project at the moment, feel free to push me more projects! 7 | 8 | The Related folder contains the related files, which is the Class-C compiler source at the moment, in case of emergency you can compile a compiler for the project. 9 | 10 | The Sources folder usually contains all platform-independent sources, in this case all source files are platform-independent, C89 compatible. 11 | 12 | main.c is the entering point, it instantiates the Main class in Main.clc. 13 | To create a compiler project for your platform/IDE, just include all the files in this folder, set main.c as the main file, and precompile all *.clc files to clcsrc.h and clcsrc.c, that are located in the Sources folder also. 14 | 15 | If you are using xCode, set the proper paths in the run script section of the build phases before building. -------------------------------------------------------------------------------- /compiler source/Sources/CoreLib/CLChar.h: -------------------------------------------------------------------------------- 1 | #ifndef CLChar_h 2 | #define CLChar_h 3 | struct CLChar 4 | { 5 | 6 | char character; 7 | struct CLChar* next; 8 | 9 | }; 10 | #endif -------------------------------------------------------------------------------- /compiler source/Sources/CoreLib/CLLink.h: -------------------------------------------------------------------------------- 1 | #ifndef CLLink_h 2 | #define CLLink_h 3 | struct CLLink 4 | { 5 | 6 | void* data; 7 | struct CLLink* next; 8 | 9 | }; 10 | #endif -------------------------------------------------------------------------------- /compiler source/Sources/CoreLib/CLObject.clc: -------------------------------------------------------------------------------- 1 | CLObject 2 | { 3 | 4 | unsigned long retainCount; 5 | 6 | 7 | // constructor 8 | 9 | void init ( ) 10 | { 11 | 12 | retainCount = 1; 13 | 14 | } 15 | 16 | 17 | // destructor 18 | 19 | void destruct( ) 20 | { 21 | 22 | 23 | 24 | } 25 | 26 | 27 | // retains object 28 | 29 | void retain ( ) 30 | { 31 | 32 | retainCount = retainCount + 1; 33 | 34 | } 35 | 36 | 37 | // releases object 38 | 39 | void release ( ) 40 | { 41 | 42 | retainCount = retainCount - 1; 43 | 44 | if ( retainCount == 0 ) 45 | { 46 | 47 | self.destruct( ); 48 | free_object( self ); 49 | 50 | } 51 | 52 | } 53 | 54 | 55 | // describes object 56 | 57 | void describe ( ) 58 | { 59 | 60 | printf( "\nObject %li retainCount %li" , ( long ) self , retainCount ); 61 | 62 | } 63 | 64 | } -------------------------------------------------------------------------------- /compiler source/Sources/CoreLib/CLObjectList.clc: -------------------------------------------------------------------------------- 1 | #include "CLLink.h" 2 | #include "CLObject.clc" 3 | 4 | CLObjectList:CLObject 5 | { 6 | 7 | struct CLLink* head; // pointer to first link 8 | struct CLLink* last; // pointer to last link 9 | unsigned long length; // element count of list 10 | 11 | 12 | // constructor 13 | 14 | void init( ) 15 | { 16 | 17 | CLObject:init( self ); 18 | 19 | head = NULL; 20 | last = NULL; 21 | length = 0; 22 | 23 | } 24 | 25 | 26 | // destructor 27 | 28 | void destruct( ) 29 | { 30 | 31 | removeAllObjects( ); 32 | 33 | CLObject:destruct( self ); 34 | 35 | } 36 | 37 | 38 | // appends object to list 39 | 40 | void addObject( CLObject* theObject ) 41 | { 42 | 43 | struct CLLink* newLink; 44 | 45 | theObject.retain( ); 46 | 47 | // create link 48 | 49 | newLink = malloc( sizeof( struct CLLink ) ); 50 | newLink->data = theObject; 51 | newLink->next = NULL; 52 | 53 | if ( head == NULL ) head = newLink; 54 | else last->next = newLink; 55 | 56 | last = newLink; 57 | length = length + 1; 58 | 59 | } 60 | 61 | 62 | // adds object at given index 63 | 64 | void addObjectAtIndex( CLObject* theObject , 65 | unsigned long theIndex ) 66 | { 67 | 68 | struct CLLink* link; 69 | struct CLLink* lastLink; 70 | struct CLLink* newLink; 71 | unsigned long position; 72 | 73 | // init 74 | 75 | lastLink = NULL; 76 | link = head; 77 | position = 0; 78 | 79 | theObject.retain( ); 80 | 81 | while ( link != NULL ) 82 | { 83 | 84 | if ( position == theIndex ) 85 | { 86 | 87 | newLink = malloc( sizeof( struct CLLink ) ); 88 | newLink->data = theObject; 89 | newLink->next = link; 90 | 91 | if ( lastLink != NULL ) lastLink->next = newLink; 92 | else head = newLink; 93 | length = length + 1; 94 | 95 | return; 96 | 97 | } 98 | 99 | position += 1; 100 | lastLink = link; 101 | link = link->next; 102 | 103 | } 104 | 105 | } 106 | 107 | 108 | // appends given object list to object list 109 | 110 | void addObjectsInObjectList( CLObjectList* theObjectList ) 111 | { 112 | 113 | struct CLLink* link; 114 | 115 | if ( theObjectList.length > 0 ) 116 | { 117 | 118 | link = theObjectList.head; 119 | 120 | while ( link != NULL ) 121 | { 122 | 123 | addObject( link->data ); 124 | 125 | link = link->next; 126 | 127 | } 128 | 129 | } 130 | 131 | } 132 | 133 | 134 | // removes data from data chain 135 | 136 | void removeObject( CLObject* theObject ) 137 | { 138 | 139 | struct CLLink* link; 140 | struct CLLink* prev; 141 | 142 | CLObject* oneObject; 143 | 144 | // init 145 | 146 | link = head; 147 | prev = NULL; 148 | 149 | while ( link != NULL ) 150 | { 151 | 152 | if ( link->data == theObject ) 153 | { 154 | 155 | if ( link->next == NULL && prev != NULL ) 156 | { 157 | prev->next = NULL; 158 | last = prev; 159 | } 160 | else if ( link->next != NULL && prev == NULL ) 161 | { 162 | head = link->next; 163 | } 164 | else if ( link->next != NULL && prev != NULL ) 165 | { 166 | prev->next = link->next; 167 | } 168 | else 169 | { 170 | head = NULL; 171 | last = NULL; 172 | } 173 | 174 | oneObject = link->data; 175 | oneObject.release( ); 176 | 177 | free( link ); 178 | length -= 1; 179 | 180 | return; 181 | 182 | } 183 | 184 | prev = link; 185 | link = link->next; 186 | 187 | } 188 | 189 | } 190 | 191 | 192 | // removes object at given index 193 | 194 | CLObject* removeObjectAtIndex( unsigned long theIndex ) 195 | { 196 | 197 | // !!! a more optimized solution is needed 198 | 199 | CLObject* object; 200 | 201 | // init 202 | 203 | object = objectAtIndex( theIndex ); 204 | if ( object != NULL ) removeObject( object ); 205 | return object; 206 | 207 | } 208 | 209 | 210 | // empties object list 211 | 212 | void removeAllObjects( ) 213 | { 214 | 215 | struct CLLink* link; 216 | struct CLLink* prev; 217 | 218 | CLObject* object; 219 | 220 | // init 221 | 222 | link = head; 223 | prev = NULL; 224 | 225 | while ( link != NULL ) 226 | { 227 | 228 | prev = link; 229 | link = link->next; 230 | 231 | object = prev->data; 232 | object.release( ); 233 | 234 | free( prev ); 235 | 236 | } 237 | 238 | head = NULL; 239 | last = NULL; 240 | length = 0; 241 | 242 | } 243 | 244 | 245 | // returns object at given index 246 | 247 | CLObject* objectAtIndex( unsigned long theIndex ) 248 | { 249 | 250 | struct CLLink* link; 251 | unsigned long position; 252 | 253 | // init 254 | 255 | link = head; 256 | position = 0; 257 | 258 | while ( link != NULL ) 259 | { 260 | 261 | if ( position == theIndex ) return link->data; 262 | 263 | position += 1; 264 | link = link->next; 265 | 266 | } 267 | 268 | return NULL; 269 | 270 | } 271 | 272 | 273 | // check if object is in the list 274 | 275 | char containsObject( CLObject* theObject ) 276 | { 277 | 278 | struct CLLink* link; 279 | 280 | // init 281 | 282 | link = head; 283 | 284 | while ( link != NULL ) 285 | { 286 | 287 | if ( link->data == theObject ) return 1; 288 | 289 | link = link->next; 290 | 291 | } 292 | 293 | return 0; 294 | 295 | } 296 | 297 | 298 | // returns index of data 299 | 300 | unsigned long indexOfObject( CLObject* theObject ) 301 | { 302 | 303 | unsigned long index; 304 | struct CLLink* link; 305 | 306 | // init 307 | 308 | index = 0; 309 | link = head; 310 | 311 | while ( link != NULL ) 312 | { 313 | 314 | if ( link->data == theObject ) return index; 315 | 316 | index += 1; 317 | 318 | link = link->next; 319 | 320 | } 321 | 322 | return 0; 323 | 324 | } 325 | 326 | 327 | // returns first object 328 | 329 | CLObject* firstObject( ) 330 | { 331 | 332 | if ( head != NULL ) return head->data; 333 | return NULL; 334 | 335 | } 336 | 337 | 338 | // returns last object 339 | 340 | CLObject* lastObject( ) 341 | { 342 | 343 | if ( last != NULL ) return last->data; 344 | return NULL; 345 | 346 | } 347 | 348 | 349 | // describes instance 350 | 351 | void describe( ) 352 | { 353 | 354 | struct CLLink* link; 355 | CLObject* object; 356 | 357 | // init 358 | 359 | link = head; 360 | 361 | while ( link != NULL ) 362 | { 363 | 364 | object = link->data; 365 | object.describe( ); 366 | printf( " " ); 367 | link = link->next; 368 | 369 | } 370 | 371 | } 372 | 373 | } -------------------------------------------------------------------------------- /compiler source/Sources/CoreLib/CLStringObjectList.clc: -------------------------------------------------------------------------------- 1 | #include "CLString.clc" 2 | #include "CLObject.clc" 3 | #include "CLObjectList.clc" 4 | 5 | 6 | CLStringObjectList:CLObject 7 | { 8 | 9 | 10 | // checks if string is in list 11 | 12 | char containsString( CLString* theString , 13 | CLObjectList* theObjectList ) 14 | { 15 | 16 | struct CLLink* link; 17 | CLString* string; 18 | 19 | link = theObjectList.head; 20 | 21 | while ( link != NULL ) 22 | { 23 | 24 | string = ( CLString* ) link->data; 25 | 26 | if ( theString.equals( string ) == 1 ) return 1; 27 | 28 | link = link->next; 29 | 30 | } 31 | 32 | return 0; 33 | 34 | } 35 | 36 | 37 | // checks if list contains string 38 | 39 | unsigned long indexOfString( CLString* theString , 40 | CLObjectList* theObjectList ) 41 | { 42 | 43 | unsigned long index; 44 | struct CLLink* link; 45 | CLString* string; 46 | 47 | // init 48 | 49 | index = 0; 50 | link = theObjectList.head; 51 | 52 | while ( link != NULL ) 53 | { 54 | 55 | string = ( CLString* ) link->data; 56 | 57 | if ( theString.equals( string ) == 1 ) return index; 58 | 59 | index += 1; 60 | 61 | link = link->next; 62 | 63 | } 64 | 65 | return 0; 66 | 67 | } 68 | 69 | 70 | // removes given string from object list 71 | 72 | void removeString( CLString* theString , 73 | CLObjectList* theObjectList ) 74 | { 75 | 76 | struct CLLink* link; 77 | CLObject* result; 78 | CLString* string; 79 | 80 | // init 81 | 82 | link = theObjectList.head; 83 | result = NULL; 84 | 85 | while ( link != NULL ) 86 | { 87 | 88 | string = ( CLString* ) link->data; 89 | 90 | if ( theString.equals( string ) == 1 ) 91 | { 92 | result = link->data; 93 | break; 94 | } 95 | 96 | link = link->next; 97 | 98 | } 99 | 100 | if ( result != NULL ) theObjectList.removeObject( result ); 101 | 102 | } 103 | 104 | 105 | // removes given strings from object list 106 | 107 | void removeStrings( CLObjectList* theStringList , 108 | CLObjectList* theObjectList ) 109 | { 110 | 111 | struct CLLink* link; 112 | 113 | link = theStringList.head; 114 | 115 | while( link != NULL ) 116 | { 117 | 118 | CLString* string; 119 | string = ( CLString* ) link->data; 120 | removeString( string , theObjectList ); 121 | link = link->next; 122 | 123 | } 124 | 125 | } 126 | 127 | 128 | // adds string to list if it's not exist 129 | 130 | void addStringAsUnique( CLString* theString , 131 | CLObjectList* theObjectList ) 132 | { 133 | 134 | char contains; 135 | 136 | // init 137 | 138 | contains = containsString( theString , theObjectList ); 139 | if ( contains == 0 ) theObjectList.addObject( ( CLObject* ) theString ); 140 | 141 | } 142 | 143 | 144 | // adds strings to list if they're not exist 145 | 146 | void addStringsAsUnique( CLObjectList* theStringList , 147 | CLObjectList* theObjectList ) 148 | { 149 | 150 | struct CLLink* link; 151 | 152 | // init 153 | 154 | link = theStringList.head; 155 | 156 | while ( link != NULL ) 157 | { 158 | 159 | CLString* string; 160 | string = ( CLString* ) link->data; 161 | 162 | addStringAsUnique( string , theObjectList ); 163 | 164 | link = link->next; 165 | 166 | } 167 | 168 | } 169 | 170 | 171 | // splits strings into words separated by given character 172 | 173 | CLObjectList* splitStringByCharacter( CLString* theString , 174 | char theCharacter ) 175 | { 176 | 177 | struct CLChar* link; 178 | CLString* word; 179 | CLObjectList* result; 180 | 181 | // init 182 | 183 | result:alloc( ); // needs release 184 | word:alloc( ); // needs release 185 | 186 | result.init( ); 187 | word.init( ); 188 | 189 | link = theString.head; 190 | 191 | while ( link != NULL ) 192 | { 193 | 194 | if ( link->character == theCharacter ) 195 | { 196 | 197 | if ( word.length > 0 ) 198 | { 199 | 200 | result:addObject( ( CLObject* ) word ); 201 | word.release( ); 202 | word = CLString:alloc( ); 203 | word.init( ); 204 | 205 | } 206 | 207 | } 208 | else 209 | { 210 | 211 | word:appendCharacter( link->character ); 212 | 213 | } 214 | 215 | link = link->next; 216 | 217 | } 218 | 219 | if ( word.length > 0 ) result:addObject( ( CLObject* ) word ); 220 | 221 | word.release( ); 222 | 223 | return result; 224 | 225 | } 226 | 227 | } -------------------------------------------------------------------------------- /compiler source/Sources/DataClass/ClassElements.clc: -------------------------------------------------------------------------------- 1 | #include "CLObject.clc" 2 | #include "CLString.clc" 3 | #include "CLObjectList.clc" 4 | 5 | 6 | ClassElements:CLObject 7 | { 8 | 9 | CLString* className; 10 | 11 | CLObjectList* usedClassNamesList; 12 | CLObjectList* unusedClassNamesList; 13 | 14 | CLObjectList* memberNamesList; 15 | CLObjectList* memberTokensList; 16 | 17 | CLObjectList* methodNamesList; 18 | CLObjectList* methodTokensList; 19 | 20 | CLObjectList* settingNamesList; 21 | CLObjectList* settingTokensList; 22 | 23 | 24 | // constructor 25 | 26 | void init( CLString* theName ) 27 | { 28 | 29 | CLObject:init( self ); 30 | 31 | className = theName; 32 | className:retain( ); 33 | 34 | memberNamesList:alloc( ); 35 | methodNamesList:alloc( ); 36 | settingNamesList:alloc( ); 37 | memberTokensList:alloc( ); 38 | methodTokensList:alloc( ); 39 | settingTokensList:alloc( ); 40 | usedClassNamesList:alloc( ); 41 | unusedClassNamesList:alloc( ); 42 | 43 | memberNamesList:init( ); 44 | methodNamesList:init( ); 45 | settingNamesList:init( ); 46 | memberTokensList:init( ); 47 | methodTokensList:init( ); 48 | settingTokensList:init( ); 49 | usedClassNamesList:init( ); 50 | unusedClassNamesList:init( ); 51 | 52 | } 53 | 54 | 55 | // destructor 56 | 57 | void destruct( ) 58 | { 59 | 60 | className.release( ); 61 | 62 | memberNamesList:release( ); 63 | methodNamesList:release( ); 64 | settingNamesList:release( ); 65 | memberTokensList:release( ); 66 | methodTokensList:release( ); 67 | settingTokensList:release( ); 68 | usedClassNamesList:release( ); 69 | unusedClassNamesList:release( ); 70 | 71 | CLObject:destruct( self ); 72 | 73 | } 74 | 75 | 76 | // describe elements 77 | 78 | void describe( ) 79 | { 80 | 81 | struct CLLink* ids; 82 | struct CLLink* line; 83 | struct CLLink* names; 84 | struct CLLink* members; 85 | struct CLLink* methods; 86 | struct CLLink* settings; 87 | 88 | CLString* name; 89 | CLObjectList* lines; 90 | 91 | printf( "\nClassName :" ); 92 | className.describe( ); 93 | 94 | printf( "\nusedClassMames :" ); 95 | usedClassNamesList.describe( ); 96 | 97 | printf( "\nunusedClassMames :" ); 98 | unusedClassNamesList.describe( ); 99 | 100 | printf( "\n\nSettings :\n\n" ); 101 | settings = settingTokensList.head; 102 | while ( settings != NULL ) 103 | { 104 | CLObjectList* chain = ( CLObjectList* ) settings->data; 105 | chain.describe( ); printf( "\n" ); 106 | settings = settings->next; 107 | } 108 | 109 | printf( "\nMembers :\n\n" ); 110 | names = memberNamesList.head; 111 | members = memberTokensList.head; 112 | while ( names != NULL ) 113 | { 114 | name = ( CLString* ) names->data; 115 | lines = ( CLObjectList* ) members->data; 116 | 117 | name.describe( ); printf( " : " ); 118 | lines.describe( ); 119 | 120 | printf( "\n" ); 121 | 122 | names = names->next; 123 | members = members->next; 124 | } 125 | 126 | printf( "\nMethods : \n" ); 127 | ids = methodNamesList.head; 128 | methods = methodTokensList.head; 129 | while ( ids != NULL ) 130 | { 131 | name = ( CLString* ) ids->data; 132 | lines = ( CLObjectList* ) methods->data; 133 | 134 | printf( "\nMETHOD " ); name.describe( ); printf( ":\n" ); 135 | 136 | line = lines.head; 137 | 138 | while ( line != NULL ) 139 | { 140 | CLObjectList* lineList = ( CLObjectList* ) line->data; 141 | lineList.describe( ); 142 | printf( "\n" ); 143 | line = line->next; 144 | } 145 | 146 | printf( "\n" ); 147 | 148 | ids = ids->next; 149 | methods = methods->next; 150 | 151 | } 152 | 153 | } 154 | 155 | } -------------------------------------------------------------------------------- /compiler source/Sources/DataClass/Constants.clc: -------------------------------------------------------------------------------- 1 | #include "CLObject.clc" 2 | #include "CLString.clc" 3 | 4 | 5 | Constants:CLObject 6 | { 7 | 8 | long linkId; 9 | 10 | CLString* clcString; 11 | CLString* forString; 12 | CLString* selfString; 13 | CLString* nullString; 14 | CLString* linkString; 15 | CLString* ifdefString; 16 | CLString* endifString; 17 | CLString* classString; 18 | CLString* allocString; 19 | CLString* settingString; 20 | 21 | 22 | void init( ) 23 | { 24 | 25 | CLObject:init( self ); 26 | 27 | linkId = 0; 28 | 29 | clcString:alloc( ); // needs release 30 | clcString:initWithCString( "clc" ); 31 | 32 | forString:alloc( ); // needs release 33 | forString:initWithCString( "for" ); 34 | 35 | selfString:alloc( ); // needs release 36 | selfString:initWithCString( "self" ); 37 | 38 | nullString:alloc( ); // needs release 39 | nullString:initWithCString( "NULL" ); 40 | 41 | linkString:alloc( ); // needs release 42 | linkString:initWithCString( "struct CLLink*" ); 43 | 44 | ifdefString:alloc( ); // needs release 45 | ifdefString:initWithCString( "#if" ); 46 | 47 | endifString:alloc( ); // needs release 48 | endifString:initWithCString( "#endif" ); 49 | 50 | classString:alloc( ); // needs release 51 | classString:initWithCString( ".clc" ); 52 | 53 | allocString:alloc( ); // needs release 54 | allocString:initWithCString( "alloc" ); 55 | 56 | settingString:alloc( ); // needs release 57 | settingString:initWithCString( "_setting" ); 58 | 59 | } 60 | 61 | 62 | void destruct( ) 63 | { 64 | 65 | clcString:release( ); 66 | forString:release( ); 67 | selfString:release( ); 68 | nullString:release( ); 69 | linkString:release( ); 70 | ifdefString:release( ); 71 | endifString:release( ); 72 | classString:release( ); 73 | allocString:release( ); 74 | settingString:release( ); 75 | 76 | } 77 | 78 | 79 | } -------------------------------------------------------------------------------- /compiler source/Sources/DataClass/FileElements.clc: -------------------------------------------------------------------------------- 1 | #include "CLObject.clc" 2 | #include "CLObjectList.clc" 3 | 4 | 5 | FileElements:CLObject 6 | { 7 | 8 | CLObjectList* classesList; 9 | CLObjectList* settingsList; 10 | CLObjectList* settingNamesList; 11 | CLObjectList* functionsList; 12 | CLObjectList* functionHeadersList; 13 | CLObjectList* structuresList; 14 | CLObjectList* structureHeadersList; 15 | 16 | 17 | // constructpr 18 | 19 | void init( ) 20 | { 21 | 22 | CLObject:init( self ); 23 | 24 | classesList:alloc( ); 25 | settingsList:alloc( ); 26 | settingNamesList:alloc( ); 27 | functionsList:alloc( ); 28 | functionHeadersList:alloc( ); 29 | structuresList:alloc( ); 30 | structureHeadersList:alloc( ); 31 | 32 | classesList:init( ); 33 | settingsList:init( ); 34 | settingNamesList:init( ); 35 | functionsList:init( ); 36 | functionHeadersList:init( ); 37 | structuresList:init( ); 38 | structureHeadersList:init( ); 39 | 40 | } 41 | 42 | 43 | // destructor 44 | 45 | void destruct( ) 46 | { 47 | 48 | classesList:release( ); 49 | settingsList:release( ); 50 | settingNamesList:release( ); 51 | functionsList:release( ); 52 | functionHeadersList:release( ); 53 | structuresList:release( ); 54 | structureHeadersList:release( ); 55 | 56 | CLObject:destruct( self ); 57 | 58 | } 59 | 60 | 61 | // descriptor 62 | 63 | void describe( ) 64 | { 65 | 66 | printf( "\nCLASSES : " ); classesList.describe( ); 67 | 68 | printf( "\nSETTING NAMES : " ); settingNamesList.describe( ); 69 | 70 | printf( "\nSTRUCTURE HEADERS : " ); structureHeadersList.describe( ); 71 | 72 | printf( "\nFUNCTION HEADERS : " ); functionHeadersList.describe( ); 73 | 74 | printf( "\nSTRUCTRUES : " ); structuresList.describe( ); 75 | 76 | printf( "\nFUNCTIONS : " ); functionsList.describe( ); 77 | 78 | } 79 | 80 | } -------------------------------------------------------------------------------- /compiler source/Sources/DataClass/Line.clc: -------------------------------------------------------------------------------- 1 | #include "CLObject.clc" 2 | #include "CLString.clc" 3 | #include "CLObjectList.clc" 4 | 5 | #define kLineTypeGeneral 0 6 | #define kLineTypeClassDef 1 7 | #define kLineTypeBlockStart 2 8 | #define kLineTypeBlockEnd 3 9 | #define kLineTypeSetting 4 10 | #define kLineTypeComment 5 11 | 12 | 13 | Line:CLObject 14 | { 15 | 16 | char type; 17 | CLString* text; 18 | CLObjectList* tokens; 19 | 20 | 21 | // constructor 22 | 23 | void init ( ) 24 | { 25 | 26 | //printf( "Line init %li\n\n\n" , ( long ) self ); 27 | 28 | CLObject:init( self ); 29 | 30 | type = 0; 31 | 32 | text:alloc( ); 33 | tokens:alloc( ); 34 | 35 | text:init( ); 36 | tokens:init( ); 37 | 38 | } 39 | 40 | 41 | // destructor 42 | 43 | void destruct( ) 44 | { 45 | 46 | text:release( ); 47 | tokens:release( ); 48 | 49 | CLObject:destruct( self ); 50 | 51 | } 52 | 53 | 54 | // description 55 | 56 | void describe ( ) 57 | { 58 | 59 | text.describe( ); 60 | printf( "(%i)\n" , type ); 61 | 62 | } 63 | 64 | } -------------------------------------------------------------------------------- /compiler source/Sources/DataClass/Scope.clc: -------------------------------------------------------------------------------- 1 | #include "CLObject.clc" 2 | #include "CLString.clc" 3 | #include "CLObjectList.clc" 4 | 5 | 6 | #define kScopeTypeUndefined 0 7 | #define kScopeTypeNormal 1 8 | #define kScopeTypeForEach 2 9 | 10 | 11 | Scope:CLObject 12 | { 13 | 14 | char type; 15 | CLString* scopeLink; 16 | CLObjectList* forEachList; 17 | CLObjectList* instancesList; 18 | CLObjectList* instanceNamesList; 19 | 20 | char nextScopeType; 21 | CLString* nextScopeLink; 22 | 23 | 24 | // constructor 25 | 26 | void init( ) 27 | { 28 | 29 | CLObject:init( self ); 30 | 31 | type = kScopeTypeNormal; 32 | scopeLink = NULL; 33 | nextScopeLink = NULL; 34 | 35 | forEachList:alloc( ); 36 | instancesList:alloc( ); 37 | instanceNamesList:alloc( ); 38 | 39 | forEachList:init( ); 40 | instancesList:init( ); 41 | instanceNamesList:init( ); 42 | 43 | } 44 | 45 | 46 | // destructor 47 | 48 | void destruct( ) 49 | { 50 | 51 | if ( scopeLink != NULL ) scopeLink.release( ); 52 | if ( nextScopeLink != NULL ) nextScopeLink.release( ); 53 | 54 | forEachList:release( ); 55 | instancesList:release( ); 56 | instanceNamesList:release( ); 57 | 58 | CLObject:destruct( self ); 59 | 60 | } 61 | 62 | 63 | // sets scope link 64 | 65 | void setScopeLink( CLString* theLink ) 66 | { 67 | 68 | if ( scopeLink != NULL ) scopeLink:release( ); 69 | scopeLink = theLink; 70 | if ( scopeLink != NULL ) scopeLink.retain( ); 71 | 72 | } 73 | 74 | 75 | // sets next scope link 76 | 77 | void setNextScopeLink( CLString* theLink ) 78 | { 79 | 80 | if ( nextScopeLink != NULL ) nextScopeLink:release( ); 81 | nextScopeLink = theLink; 82 | if ( nextScopeLink != NULL ) nextScopeLink.retain( ); 83 | 84 | } 85 | 86 | } -------------------------------------------------------------------------------- /compiler source/Sources/DataClass/Token.clc: -------------------------------------------------------------------------------- 1 | #import "CLObject.clc" 2 | #import "CLString.clc" 3 | 4 | #define kTokenMainTypeUndefined 0 5 | #define kTokenMainTypeWord 1 6 | #define kTokenMainTypeString 2 7 | #define kTokenMainTypeSymbol 3 8 | #define kTokenMainTypeComment 4 9 | #define kTokenMainTypeSetting 5 10 | 11 | #define kTokenSubTypeUndefined 6 12 | #define kTokenSubTypeClass 7 13 | #define kTokenSubTypeCast 8 14 | #define kTokenSubTypeInstance 9 15 | #define kTokenSubTypeVariable 10 16 | #define kTokenSubTypeMethod 11 17 | #define kTokenSubTypeLocalCall 12 18 | #define kTokenSubTypeImplicitCall 13 19 | #define kTokenSubTypeExplicitCall 14 20 | #define kTokenSubTypeExplicitAllocCall 15 21 | #define kTokenSubTypeExplicitClassCall 16 22 | #define kTokenSubTypeExplicitCallClass 17 23 | #define kTokenSubTypeExplicitAccessor 18 24 | #define kTokenSubTypeImplicitAccessor 19 25 | #define kTokenSubTypeForEachCycle 20 26 | #define kTokenSubTypeLocalCallReference 21 27 | #define kTokenSubTypeStructAccessor 22 28 | 29 | 30 | Token:CLObject 31 | { 32 | 33 | CLString* text; 34 | CLString* linkId; 35 | CLString* classId; 36 | CLString* variableId; 37 | CLString* containerId; 38 | CLString* instanceList; 39 | 40 | char subType; 41 | char mainType; 42 | char isMember; 43 | 44 | 45 | // initializer 46 | 47 | void init ( ) 48 | { 49 | 50 | CLObject:init( self ); 51 | 52 | linkId = NULL; 53 | classId = NULL; 54 | variableId = NULL; 55 | containerId = NULL; 56 | instanceList = NULL; 57 | 58 | mainType = kTokenMainTypeUndefined; 59 | subType = kTokenSubTypeUndefined; 60 | isMember = 0; 61 | 62 | text:alloc( ); 63 | text:init( ); 64 | 65 | } 66 | 67 | 68 | // destructor 69 | 70 | void destruct ( ) 71 | { 72 | 73 | //printf( "Token destruct %li %i\n" , ( long ) self , self->Object_offset ); 74 | 75 | text:release( ); 76 | 77 | if ( linkId != NULL ) linkId:release( ); 78 | if ( classId != NULL ) classId:release( ); 79 | if ( variableId != NULL ) variableId:release( ); 80 | if ( containerId != NULL ) containerId:release( ); 81 | if ( instanceList != NULL ) instanceList:release( ); 82 | 83 | CLObject:init( self ); 84 | 85 | } 86 | 87 | 88 | // set text 89 | 90 | void setText( CLString* theText ) 91 | { 92 | 93 | if ( text != NULL ) text.release( ); 94 | text = theText; 95 | if ( text != NULL ) text.retain( ); 96 | 97 | } 98 | 99 | 100 | // set text 101 | 102 | void setLinkId( CLString* theLinkId ) 103 | { 104 | 105 | if ( linkId != NULL ) linkId.release( ); 106 | linkId = theLinkId; 107 | if ( linkId != NULL ) linkId.retain( ); 108 | 109 | } 110 | 111 | 112 | // set classId 113 | 114 | void setClassId( CLString* theClassId ) 115 | { 116 | 117 | if ( classId != NULL ) classId.release( ); 118 | classId = theClassId; 119 | if ( classId != NULL ) classId.retain( ); 120 | 121 | } 122 | 123 | 124 | // set variableId 125 | 126 | void setVariableId( CLString* theVariableId ) 127 | { 128 | 129 | if ( variableId != NULL ) variableId.release( ); 130 | variableId = theVariableId; 131 | if ( variableId != NULL ) variableId.retain( ); 132 | 133 | } 134 | 135 | 136 | // set variableId 137 | 138 | void setContainerId( CLString* theContainerId ) 139 | { 140 | 141 | if ( containerId != NULL ) containerId.release( ); 142 | containerId = theContainerId; 143 | if ( containerId != NULL ) containerId.retain( ); 144 | 145 | } 146 | 147 | 148 | // set instance chain 149 | 150 | void setInstanceList( CLString* theList ) 151 | { 152 | 153 | if ( instanceList != NULL ) instanceList.release( ); 154 | instanceList = theList; 155 | if ( instanceList != NULL ) instanceList.retain( ); 156 | 157 | } 158 | 159 | 160 | // describes instance 161 | 162 | void describe( ) 163 | { 164 | 165 | //printf( "\nToken mainType %i subType %i text" , *(self->mainType) , *(self->subType) ); 166 | 167 | if ( text != NULL ) text.describe( ); 168 | printf( "|" ); 169 | printf( "%i" , mainType ); 170 | printf( "%i" , subType ); 171 | if ( isMember == 1 ) printf( "M" ); 172 | if ( classId != NULL ) classId.describe( ); 173 | if ( variableId != NULL ) variableId.describe( ); 174 | if ( linkId != NULL ) linkId.describe( ); 175 | if ( containerId != NULL ) containerId.describe( ); 176 | printf( "|" ); 177 | 178 | } 179 | 180 | } -------------------------------------------------------------------------------- /compiler source/Sources/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | main.c 3 | Compiler 4 | 5 | Created by Milan Toth on 10/17/13. 6 | Copyright (c) 2013 Milan Toth. All rights reserved. 7 | */ 8 | 9 | #include 10 | #include "clcsrc.h" 11 | 12 | int main( int theCount , 13 | const char* theTokens[ ] ) 14 | { 15 | struct Main* main; 16 | int result; 17 | 18 | main = Main_alloc( ); 19 | result = Main_init( main , theCount , theTokens ); 20 | 21 | Main_release( main ); 22 | return result; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /example project/Projects/DynamicsXOSX/DynamicsX.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example project/Projects/DynamicsXOSX/DynamicsX.xcodeproj/project.xcworkspace/xcuserdata/milgra.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milgra/clc/ffa783390654f2b98e8e7f46a5855d22d87bb3e1/example project/Projects/DynamicsXOSX/DynamicsX.xcodeproj/project.xcworkspace/xcuserdata/milgra.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /example project/Projects/DynamicsXOSX/DynamicsX.xcodeproj/project.xcworkspace/xcuserdata/milgra.xcuserdatad/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges 6 | 7 | SnapshotAutomaticallyBeforeSignificantChanges 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /example project/Projects/DynamicsXOSX/DynamicsX.xcodeproj/xcuserdata/milgra.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /example project/Projects/DynamicsXOSX/DynamicsX.xcodeproj/xcuserdata/milgra.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 14 | 15 | 16 | 18 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /example project/Projects/DynamicsXOSX/DynamicsX.xcodeproj/xcuserdata/milgra.xcuserdatad/xcschemes/DynamicsX.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 51 | 52 | 58 | 59 | 60 | 61 | 62 | 63 | 69 | 70 | 76 | 77 | 78 | 79 | 81 | 82 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /example project/Projects/DynamicsXOSX/DynamicsX.xcodeproj/xcuserdata/milgra.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | DynamicsX.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 336F922417B924F400B065F9 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /example project/Projects/DynamicsXOSX/DynamicsX/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // DynamicsOSX 4 | // 5 | // Created by Milan Toth on 7/2/13. 6 | // Copyright (c) 2013 Milan Toth. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "GLView.h" 11 | #import "clcsrc.h" 12 | 13 | 14 | @interface AppDelegate : NSObject < NSApplicationDelegate , NSWindowDelegate > 15 | { 16 | 17 | NSWindow* window; 18 | NSView* glView; 19 | BOOL glInited; 20 | BOOL fullScreen; 21 | double upStamp; 22 | int timeLeft; 23 | struct Controller* controller; 24 | 25 | } 26 | 27 | + ( AppDelegate* ) sharedDelegate; 28 | - ( void ) mouseUp : ( NSPoint ) theLocation; 29 | - ( void ) mouseDown : ( NSPoint ) theLocation; 30 | - ( void ) mouseMoved : ( NSPoint ) theLocation; 31 | 32 | 33 | @end -------------------------------------------------------------------------------- /example project/Projects/DynamicsXOSX/DynamicsX/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // DynamicsOSX 4 | // 5 | // Created by Milan Toth on 7/2/13. 6 | // Copyright (c) 2013 Milan Toth. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | 12 | @implementation AppDelegate 13 | 14 | 15 | // entering point 16 | 17 | - ( void ) applicationDidFinishLaunching : ( NSNotification* ) theNotification 18 | { 19 | 20 | // create view and window 21 | 22 | NSRect windowRect = NSMakeRect( 0 , 23 | 0 , 24 | 900 , 25 | 600 ); 26 | 27 | NSOpenGLPixelFormatAttribute attributes[ ] = { NSOpenGLPFADoubleBuffer , 0 }; 28 | NSOpenGLPixelFormat* pixelFormat = [ [ NSOpenGLPixelFormat alloc ] initWithAttributes : attributes ]; 29 | 30 | glView = [ [ GLView alloc ] initWithFrame : windowRect 31 | pixelFormat : pixelFormat ]; 32 | 33 | window = [ [ NSWindow alloc ] initWithContentRect : windowRect 34 | styleMask : NSTitledWindowMask 35 | backing : NSBackingStoreBuffered 36 | defer : YES ]; 37 | 38 | [ window setHasShadow : YES ]; 39 | [ window setDelegate : self ]; 40 | [ window setContentView : glView ]; 41 | [ window setHidesOnDeactivate : YES ]; 42 | [ window setLevel : NSMainMenuWindowLevel + 1 ]; 43 | [ window setAcceptsMouseMovedEvents : YES ]; 44 | [ window makeKeyAndOrderFront : self ]; 45 | [ window makeFirstResponder : glView ]; 46 | [ window makeMainWindow ]; 47 | 48 | fullScreen = NO; 49 | staticDelegate = self; 50 | 51 | // create controller 52 | 53 | controller = Controller_alloc( ); 54 | 55 | Controller_init( controller , 56 | glView.frame.size.width , 57 | glView.frame.size.height ); 58 | 59 | // start timer 60 | 61 | [ NSTimer scheduledTimerWithTimeInterval : 1.0 / 60.0 62 | target : self 63 | selector : @selector(render) 64 | userInfo : nil 65 | repeats : YES ]; 66 | 67 | } 68 | 69 | 70 | // destructor 71 | 72 | - ( void ) dealloc 73 | { 74 | 75 | // cleanup 76 | 77 | // Controller_destruct( controller ); 78 | 79 | [ glView release ]; 80 | [ window release ]; 81 | 82 | [ super dealloc ]; 83 | 84 | } 85 | 86 | 87 | - ( void ) mouseUp : ( NSPoint ) theLocation 88 | { 89 | 90 | upStamp = [ [ NSDate date ] timeIntervalSince1970 ]; 91 | 92 | Controller_buttonPressed( controller , 93 | theLocation.x * ( 900 / glView.frame.size.width ) , 94 | theLocation.y * ( 600 / glView.frame.size.height ) ); 95 | 96 | } 97 | 98 | 99 | - ( void ) mouseDown : ( NSPoint ) theLocation 100 | { 101 | 102 | double delay = [ [ NSDate date ] timeIntervalSince1970 ] - upStamp; 103 | if ( delay < .1 ) [ self changeScreenSize ]; 104 | 105 | } 106 | 107 | 108 | - ( void ) mouseMoved : ( NSPoint ) theLocation 109 | { 110 | 111 | if ( timeLeft == 0 ) 112 | { 113 | timeLeft = 2; 114 | controller->showButtons = 1; 115 | } 116 | 117 | } 118 | 119 | 120 | - ( void ) changeScreenSize 121 | { 122 | 123 | fullScreen = !fullScreen; 124 | 125 | if ( fullScreen ) 126 | { 127 | 128 | [ glView enterFullScreenMode : [ NSScreen mainScreen ] 129 | withOptions : nil ]; 130 | 131 | } 132 | else 133 | { 134 | 135 | [ glView exitFullScreenModeWithOptions : nil ]; 136 | [ window makeFirstResponder : glView ]; 137 | 138 | } 139 | 140 | } 141 | 142 | 143 | static double stamp = 0; 144 | static long frames = 0; 145 | 146 | - ( void ) render 147 | { 148 | 149 | // update simualtion and renderer 150 | 151 | Controller_updateScene( controller ); 152 | Controller_render( controller ); 153 | 154 | // show render buffer 155 | 156 | glSwapAPPLE( ); 157 | 158 | // frame count 159 | 160 | ++frames; 161 | 162 | double timeStamp = [ [ NSDate date ] timeIntervalSince1970 ]; 163 | if ( timeStamp - stamp > 1.0 ) 164 | { 165 | 166 | NSLog( @"frames %li" , frames ); 167 | 168 | stamp = timeStamp; 169 | frames = 0; 170 | 171 | if ( timeLeft > 0 ) 172 | { 173 | timeLeft -= 1; 174 | if ( timeLeft == 0 ) controller->showButtons = 0; 175 | } 176 | 177 | } 178 | 179 | } 180 | 181 | 182 | static AppDelegate* staticDelegate; 183 | 184 | + ( AppDelegate* ) sharedDelegate 185 | { 186 | return staticDelegate; 187 | } 188 | 189 | 190 | @end 191 | -------------------------------------------------------------------------------- /example project/Projects/DynamicsXOSX/DynamicsX/DynamicsX-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | com.milgra.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageTye 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSMinimumSystemVersion 26 | ${MACOSX_DEPLOYMENT_TARGET} 27 | NSHumanReadableCopyright 28 | Copyright © 2013 Milan Toth. All rights reserved. 29 | NSMainNibFile 30 | MainMenu 31 | NSPrincipalClass 32 | NSApplication 33 | 34 | 35 | -------------------------------------------------------------------------------- /example project/Projects/DynamicsXOSX/DynamicsX/DynamicsX-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'DynamicsX' target in the 'DynamicsX' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | 9 | #define OSX 1 -------------------------------------------------------------------------------- /example project/Projects/DynamicsXOSX/DynamicsX/GLView.h: -------------------------------------------------------------------------------- 1 | // 2 | // GLView.h 3 | // DynamicsX 4 | // 5 | // Created by Milan Toth on 9/4/13. 6 | // Copyright (c) 2013 Milan Toth. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface GLView : NSOpenGLView 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /example project/Projects/DynamicsXOSX/DynamicsX/GLView.m: -------------------------------------------------------------------------------- 1 | // 2 | // GLView.m 3 | // DynamicsX 4 | // 5 | // Created by Milan Toth on 9/4/13. 6 | // Copyright (c) 2013 Milan Toth. All rights reserved. 7 | // 8 | 9 | #import "GLView.h" 10 | #import "AppDelegate.h" 11 | 12 | @implementation GLView 13 | 14 | 15 | - ( BOOL ) canBecomeFirstResponder 16 | { 17 | 18 | return YES; 19 | 20 | } 21 | 22 | 23 | - ( void ) mouseDown : ( NSEvent* ) theEvent 24 | { 25 | 26 | NSPoint location = [ theEvent locationInWindow ]; 27 | 28 | [ [ AppDelegate sharedDelegate ] mouseDown : location ]; 29 | 30 | } 31 | 32 | 33 | - ( void ) mouseUp : ( NSEvent* ) theEvent 34 | { 35 | 36 | NSPoint location = [ theEvent locationInWindow ]; 37 | 38 | [ [ AppDelegate sharedDelegate ] mouseUp : location ]; 39 | 40 | } 41 | 42 | 43 | - ( void ) mouseMoved : ( NSEvent* ) theEvent 44 | { 45 | 46 | NSPoint location = [ theEvent locationInWindow ]; 47 | 48 | [ [ AppDelegate sharedDelegate ] mouseMoved : location ]; 49 | 50 | } 51 | 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /example project/Projects/DynamicsXOSX/DynamicsX/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /example project/Projects/DynamicsXOSX/DynamicsX/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // DynamicsX 4 | // 5 | // Created by Milan Toth on 8/12/13. 6 | // Copyright (c) 2013 Milan Toth. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | return NSApplicationMain(argc, (const char **)argv); 14 | } 15 | -------------------------------------------------------------------------------- /example project/README.md: -------------------------------------------------------------------------------- 1 | dynamicsx 2 | ========= 3 | 4 | Simple Dynamics Engine written in Class-C by Milan Toth 5 | 6 | The Projects folder contains the project files for various platforms and IDE's, it only contains the OSX/xCode 5.0 project at the moment, feel free to push me more projects! 7 | 8 | The Related folder contains the related files, which is the Class-C compiler source at the moment, in case of emergency you can compile a compiler for the project. 9 | 10 | The Sources folder contains all platform-independent sources. 11 | 12 | The main class of the indepent source group is Controller in Controller.clc, you should start examining that class, it has to be initialized with the opengl context width and context height. The openGL context have to be initialized platform-dependently before initializing this class!!! 13 | 14 | If you are using xCode, set the proper paths in the run script section of the build phases before building. -------------------------------------------------------------------------------- /example project/Sources/Controller.clc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "PLMass.clc" 7 | #include "PLSpacer.clc" 8 | #include "PLSegment.clc" 9 | 10 | #include "Scene.clc" 11 | #include "ScenePit.clc" 12 | #include "SceneBox.clc" 13 | #include "SceneSlope.clc" 14 | #include "SceneParticle.clc" 15 | 16 | #include "GLPointP2.clc" 17 | #include "GLRectPT22.clc" 18 | #include "ShaderP2.clc" 19 | #include "GLSegment.clc" 20 | #include "ShaderPT22.clc" 21 | #incldue "PLUniverse.clc" 22 | #include "CLDataList.clc" 23 | #include "GLTexturePixelText.clc" 24 | #include "GLDrawable.clc" 25 | #include "GLVertexBuffer.clc" 26 | 27 | #define kScenePlayXOffset -200.0 28 | 29 | 30 | Controller 31 | { 32 | 33 | float contextWidth; 34 | float contextHeight; 35 | 36 | ShaderP2* simpleShader; 37 | ShaderPT22* textureShader; 38 | 39 | GLVertexBuffer* simpleVertexBuffer; 40 | GLVertexBuffer* textureVertexBuffer; 41 | 42 | GLint simplePMLocation; 43 | GLint texturePMLocation; 44 | 45 | GLKMatrix4 projectionMatrix; 46 | 47 | char showButtons; 48 | CLDataList* buttons; 49 | CLDataList* textures; 50 | PLUniverse* universe; 51 | Scene* scene; 52 | 53 | 54 | // constructor 55 | 56 | void init( float theContextWidth , 57 | float theContextHeight ) 58 | { 59 | 60 | showButtons = 0; 61 | 62 | contextWidth = theContextWidth; 63 | contextHeight = theContextHeight; 64 | 65 | simpleShader:alloc( ); 66 | simpleShader:init( ); 67 | 68 | textureShader:alloc( ); 69 | textureShader:init( ); 70 | 71 | simpleVertexBuffer:alloc( ); 72 | simpleVertexBuffer:init( ); 73 | 74 | textureVertexBuffer:alloc( ); 75 | textureVertexBuffer:init( ); 76 | 77 | simplePMLocation = simpleShader.shader.getUniformLocation( "projectionMatrix" ); 78 | texturePMLocation = textureShader.shader.getUniformLocation( "projectionMatrix" ); 79 | 80 | glEnable( GL_POINTS ); 81 | glPointSize( 6 ); 82 | glEnable( GL_BLEND ); 83 | glBlendFunc( GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA ); 84 | glActiveTexture( GL_TEXTURE0 ); 85 | 86 | glClearColor( .65 , .65 , .65 , 1.0 ); 87 | 88 | projectionMatrix = GLKMatrix4MakeOrtho( 0.0 , 900.0 , 0.0 , 600.0 , -1.0 , 1.0 ); 89 | 90 | setupScene( ); 91 | 92 | } 93 | 94 | 95 | // destructor 96 | 97 | void destruct( ) 98 | { 99 | 100 | if ( scene != NULL ) 101 | { 102 | 103 | removeScene( ); 104 | scene.release( ); 105 | scene = NULL; 106 | 107 | } 108 | 109 | universe.release( ); 110 | 111 | for ( void* data : buttons ) 112 | { 113 | GLRectPT22* buttonRect = data; 114 | textureVertexBuffer:removeDrawable( ( GLDrawable* ) buttonRect ); 115 | buttonRect.release( ); 116 | } 117 | 118 | buttons.release( ); 119 | 120 | for ( void* data : textures ) 121 | { 122 | 123 | GLTexturePixelText* texture = data; 124 | texture.release( ); 125 | 126 | } 127 | 128 | textures.release( ); 129 | 130 | simpleVertexBuffer.release( ); 131 | textureVertexBuffer.release( ); 132 | 133 | simpleShader.release( ); 134 | textureShader.release( ); 135 | 136 | 137 | } 138 | 139 | 140 | // renders scene 141 | 142 | void render ( ) 143 | { 144 | 145 | // printf( "\nController render" ); 146 | 147 | glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); 148 | 149 | simpleVertexBuffer:bindBuffer( ); 150 | simpleShader.shader.activate( ); 151 | 152 | // update uniform attributes for shader programs 153 | 154 | glUniformMatrix4fv( simplePMLocation , 155 | 1 , 156 | 0 , 157 | projectionMatrix.m ); 158 | 159 | simpleVertexBuffer:drawBuffer( ); 160 | 161 | if ( showButtons == 1 ) 162 | { 163 | 164 | textureVertexBuffer:bindBuffer( ); 165 | textureShader.shader.activate( ); 166 | 167 | // update uniform attributes for shader programs 168 | 169 | glUniformMatrix4fv( texturePMLocation , 170 | 1 , 171 | 0 , 172 | projectionMatrix.m ); 173 | 174 | textureVertexBuffer:drawBuffer( ); 175 | 176 | } 177 | 178 | } 179 | 180 | 181 | // updates scene 182 | 183 | void updateScene( ) 184 | { 185 | 186 | universe:update( ); 187 | simpleVertexBuffer:updateBuffers( ); 188 | 189 | } 190 | 191 | 192 | // setup scene 193 | 194 | void setupScene( ) 195 | { 196 | 197 | // create buttons 198 | 199 | scene = NULL; 200 | showButtons = 1; 201 | 202 | buttons:alloc( ); 203 | buttons:init( ); 204 | 205 | textures:alloc( ); 206 | textures:init( ); 207 | 208 | universe:alloc( ); 209 | universe:init( ); 210 | 211 | float freeX = ( contextWidth - 2 * 256 - 50 ) / 2; 212 | float freeY = ( contextHeight - 2 * 256 - 50 ) / 2; 213 | 214 | GLTexturePixelText* buttonATexture = GLTexturePixelText:alloc( ); 215 | GLTexturePixelText* buttonBTexture = GLTexturePixelText:alloc( ); 216 | GLTexturePixelText* buttonCTexture = GLTexturePixelText:alloc( ); 217 | GLTexturePixelText* buttonDTexture = GLTexturePixelText:alloc( ); 218 | 219 | buttonATexture:init( "PIT" , 256 , 256 , 3 ); 220 | buttonBTexture:init( "PARTICLE" , 256 , 256 , 3 ); 221 | buttonCTexture:init( "BOX" , 256 , 256 , 3 ); 222 | buttonDTexture:init( "SLOPE" , 256 , 256 , 3 ); 223 | 224 | GLRectPT22* buttonARect = GLRectPT22:alloc( ); 225 | GLRectPT22* buttonBRect = GLRectPT22:alloc( ); 226 | GLRectPT22* buttonCRect = GLRectPT22:alloc( ); 227 | GLRectPT22* buttonDRect = GLRectPT22:alloc( ); 228 | 229 | buttonARect.init( buttonATexture.glid ); 230 | buttonBRect.init( buttonBTexture.glid ); 231 | buttonCRect.init( buttonCTexture.glid ); 232 | buttonDRect.init( buttonDTexture.glid ); 233 | 234 | buttonARect.flipTexture( ); 235 | buttonBRect.flipTexture( ); 236 | buttonCRect.flipTexture( ); 237 | buttonDRect.flipTexture( ); 238 | 239 | buttonARect.scale( 256.0 , 256.0 ); 240 | buttonBRect.scale( 256.0 , 256.0 ); 241 | buttonCRect.scale( 256.0 , 256.0 ); 242 | buttonDRect.scale( 256.0 , 256.0 ); 243 | 244 | buttonARect.move( freeX , freeY); 245 | buttonBRect.move( freeX , freeY + 256 + 50 ); 246 | buttonCRect.move( freeX + 256 + 50 , freeY ); 247 | buttonDRect.move( freeX + 256 + 50 , freeY + 256 + 50 ); 248 | 249 | buttons:addData( buttonARect ); 250 | buttons:addData( buttonBRect ); 251 | buttons:addData( buttonCRect ); 252 | buttons:addData( buttonDRect ); 253 | 254 | textures:addData( buttonATexture ); 255 | textures:addData( buttonBTexture ); 256 | textures:addData( buttonCTexture ); 257 | textures:addData( buttonDTexture ); 258 | 259 | textureVertexBuffer:addDrawable( ( GLDrawable* ) buttonARect ); 260 | textureVertexBuffer:addDrawable( ( GLDrawable* ) buttonBRect ); 261 | textureVertexBuffer:addDrawable( ( GLDrawable* ) buttonCRect ); 262 | textureVertexBuffer:addDrawable( ( GLDrawable* ) buttonDRect ); 263 | 264 | textureVertexBuffer:updateBuffers( ); 265 | 266 | openSceneWithId( 1 ); 267 | 268 | } 269 | 270 | 271 | // adds scene with specific id 272 | 273 | void openSceneWithId( unsigned char theId ) 274 | { 275 | 276 | if ( scene != NULL ) 277 | { 278 | 279 | removeScene( ); 280 | scene.release( ); 281 | scene = NULL; 282 | 283 | } 284 | 285 | void* sceneObj = NULL; 286 | 287 | if ( theId == 0 ) sceneObj = ScenePit:alloc( ); else 288 | if ( theId == 1 ) sceneObj = SceneParticle:alloc( ); else 289 | if ( theId == 2 ) sceneObj = SceneBox:alloc( ); else 290 | if ( theId == 3 ) sceneObj = SceneSlope:alloc( ); 291 | 292 | scene = ( Scene* ) sceneObj; 293 | scene.initWithDimensions( contextWidth , contextHeight ); 294 | 295 | addScene( ); 296 | 297 | } 298 | 299 | 300 | // adds scene to vertexbuffer and universe 301 | 302 | void addScene( ) 303 | { 304 | 305 | for ( void* data : scene.glPoints ) 306 | { 307 | GLPointP2* glPoint = data; 308 | simpleVertexBuffer:addDrawable( ( GLDrawable* ) glPoint ); 309 | } 310 | 311 | for ( void* data : scene.glSegments ) 312 | { 313 | GLSegment* glSegment = data; 314 | simpleVertexBuffer:addDrawable( ( GLDrawable* ) glSegment ); 315 | } 316 | 317 | for ( void* data : scene.masses ) 318 | { 319 | PLMass* mass = data; 320 | universe:addMass( mass ); 321 | } 322 | 323 | for ( void* data : scene.segments ) 324 | { 325 | PLSegment* wall = data; 326 | universe:addWall( wall ); 327 | } 328 | 329 | for ( void* data : scene.spacers ) 330 | { 331 | PLSpacer* spacer = data; 332 | universe:addSpacer( spacer ); 333 | } 334 | 335 | } 336 | 337 | 338 | // removes scene to vertexbuffer and universe 339 | 340 | void removeScene( ) 341 | { 342 | 343 | for ( void* data : scene.glPoints ) 344 | { 345 | GLPointP2* glPoint = data; 346 | simpleVertexBuffer:removeDrawable( ( GLDrawable* ) glPoint ); 347 | } 348 | 349 | for ( void* data : scene.glSegments ) 350 | { 351 | GLSegment* glSegment = data; 352 | simpleVertexBuffer:removeDrawable( ( GLDrawable* ) glSegment ); 353 | } 354 | 355 | for ( void* data : scene.masses ) 356 | { 357 | PLMass* mass = data; 358 | universe:removeMass( mass ); 359 | } 360 | 361 | for ( void* data : scene.segments ) 362 | { 363 | PLSegment* wall = data; 364 | universe:removeWall( wall ); 365 | } 366 | 367 | for ( void* data : scene.spacers ) 368 | { 369 | PLSpacer* spacer = data; 370 | universe:removeSpacer( spacer ); 371 | } 372 | 373 | } 374 | 375 | 376 | // button pressed event 377 | 378 | void buttonPressed ( float theX , 379 | float theY ) 380 | { 381 | 382 | struct CLLink* link = buttons.head; 383 | unsigned char index = 0; 384 | 385 | while ( link != NULL ) 386 | { 387 | GLRectPT22* buttonRect = link->data; 388 | if ( buttonRect.contains( theX , theY ) ) openSceneWithId( index ); 389 | index++; 390 | link = link->next; 391 | } 392 | 393 | } 394 | 395 | } -------------------------------------------------------------------------------- /example project/Sources/CoreLib/CLChar.h: -------------------------------------------------------------------------------- 1 | #ifndef CLChar_h 2 | #define CLChar_h 3 | struct CLChar 4 | { 5 | 6 | char character; 7 | struct CLChar* next; 8 | 9 | }; 10 | #endif -------------------------------------------------------------------------------- /example project/Sources/CoreLib/CLDataList.clc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "CLLink.h" 4 | #include "CLObject.clc" 5 | 6 | CLDataList:CLObject 7 | { 8 | 9 | struct CLLink* head; // pointer to first link 10 | struct CLLink* last; // pointer to last link 11 | unsigned long length; // element count of list 12 | 13 | 14 | // initializator 15 | 16 | void init( ) 17 | { 18 | 19 | CLObject:init( self ); 20 | 21 | head = NULL; 22 | last = NULL; 23 | length = 0; 24 | 25 | } 26 | 27 | 28 | // destructor 29 | 30 | void destruct( ) 31 | { 32 | 33 | removeAllDatas( ); 34 | 35 | CLObject:destruct( self ); 36 | 37 | } 38 | 39 | 40 | // appends data to DataList 41 | 42 | void addData( void* theData ) 43 | { 44 | 45 | struct CLLink* newLink; 46 | 47 | // create link 48 | 49 | newLink = malloc( sizeof( struct CLLink ) ); 50 | 51 | newLink->data = theData; 52 | newLink->next = NULL; 53 | 54 | if ( head == NULL ) head = newLink; 55 | else last->next = newLink; 56 | 57 | last = newLink; 58 | length = length + 1; 59 | 60 | } 61 | 62 | 63 | // adds data at given index 64 | 65 | void addDataAtIndex( void* theData , 66 | unsigned long theIndex ) 67 | { 68 | 69 | struct CLLink* link; 70 | struct CLLink* lastLink; 71 | struct CLLink* newLink; 72 | unsigned long position; 73 | 74 | // init 75 | 76 | lastLink = NULL; 77 | link = head; 78 | position = 0; 79 | 80 | while ( link != NULL ) 81 | { 82 | 83 | if ( position == theIndex ) 84 | { 85 | 86 | newLink = malloc( sizeof( struct CLLink ) ); 87 | newLink->data = theData; 88 | newLink->next = link; 89 | 90 | if ( lastLink != NULL ) lastLink->next = newLink; 91 | else head = newLink; 92 | length = length + 1; 93 | 94 | return; 95 | 96 | } 97 | 98 | position += 1; 99 | lastLink = link; 100 | link = link->next; 101 | 102 | } 103 | 104 | } 105 | 106 | 107 | // appends array to DataList 108 | 109 | void addDatasInDataList( CLDataList* theDataList ) 110 | { 111 | 112 | struct CLLink* link; 113 | 114 | if ( theDataList.length > 0 ) 115 | { 116 | 117 | link = theDataList.head; 118 | 119 | while ( link != NULL ) 120 | { 121 | 122 | addData( link->data ); 123 | 124 | link = link->next; 125 | 126 | } 127 | 128 | } 129 | 130 | } 131 | 132 | 133 | // removes data from DataList 134 | 135 | void removeData( void* theData ) 136 | { 137 | 138 | struct CLLink* link; 139 | struct CLLink* prev; 140 | 141 | // init 142 | 143 | link = head; 144 | prev = NULL; 145 | 146 | while ( link != NULL ) 147 | { 148 | 149 | if ( link->data == theData ) 150 | { 151 | 152 | if ( link->next == NULL && prev != NULL ) 153 | { 154 | prev->next = NULL; 155 | last = prev; 156 | } 157 | else if ( link->next != NULL && prev == NULL ) 158 | { 159 | head = link->next; 160 | } 161 | else if ( link->next != NULL && prev != NULL ) 162 | { 163 | prev->next = link->next; 164 | } 165 | else 166 | { 167 | head = NULL; 168 | last = NULL; 169 | } 170 | 171 | free( link ); 172 | length -= 1; 173 | 174 | return; 175 | 176 | } 177 | 178 | prev = link; 179 | link = link->next; 180 | 181 | } 182 | 183 | } 184 | 185 | 186 | // removes data at given index 187 | 188 | void* removeDataAtIndex( unsigned long theIndex ) 189 | { 190 | 191 | // !!! a more optimized solution is needed 192 | 193 | void* data; 194 | 195 | // init 196 | 197 | data = dataAtIndex( theIndex ); 198 | if ( data != NULL ) removeData( data ); 199 | return data; 200 | 201 | } 202 | 203 | 204 | // empties DataList release 205 | 206 | void removeAllDatas( ) 207 | { 208 | 209 | struct CLLink* link; 210 | struct CLLink* prev; 211 | 212 | // init 213 | 214 | link = head; 215 | prev = NULL; 216 | 217 | while ( link != NULL ) 218 | { 219 | prev = link; 220 | link = link->next; 221 | 222 | free( prev ); 223 | } 224 | 225 | head = NULL; 226 | last = NULL; 227 | length = 0; 228 | 229 | } 230 | 231 | 232 | // returns data at index 233 | 234 | void* dataAtIndex( unsigned long theIndex ) 235 | { 236 | 237 | struct CLLink* link; 238 | unsigned long position; 239 | 240 | // init 241 | 242 | link = head; 243 | position = 0; 244 | 245 | while ( link != NULL ) 246 | { 247 | 248 | if ( position == theIndex ) return link->data; 249 | 250 | link = link->next; 251 | position += 1; 252 | 253 | } 254 | 255 | return NULL; 256 | 257 | } 258 | 259 | 260 | // check if object is in the list 261 | 262 | char containsData( void* theData ) 263 | { 264 | 265 | struct CLLink* link; 266 | 267 | // init 268 | 269 | link = head; 270 | 271 | while ( link != NULL ) 272 | { 273 | 274 | if ( link->data == theData ) return 1; 275 | 276 | link = link->next; 277 | 278 | } 279 | 280 | return 0; 281 | 282 | } 283 | 284 | 285 | // returns index of data 286 | 287 | unsigned long indexOfData( void* theData ) 288 | { 289 | 290 | unsigned long index; 291 | struct CLLink* link; 292 | 293 | // init 294 | 295 | index = 0; 296 | link = head; 297 | 298 | while ( link != NULL ) 299 | { 300 | 301 | if ( link->data == theData ) return index; 302 | 303 | index += 1; 304 | link = link->next; 305 | 306 | } 307 | 308 | return 0; 309 | 310 | } 311 | 312 | 313 | // returns first object 314 | 315 | void* firstData( ) 316 | { 317 | 318 | if ( head != NULL ) return head->data; 319 | return NULL; 320 | 321 | } 322 | 323 | 324 | // returns last object 325 | 326 | void* lastData( ) 327 | { 328 | 329 | if ( last != NULL ) return last->data; 330 | return NULL; 331 | 332 | } 333 | 334 | 335 | // describes instance 336 | 337 | void describe( ) 338 | { 339 | 340 | printf( "\nDataList %i length %lu" , (int)self , length ); 341 | 342 | } 343 | 344 | } -------------------------------------------------------------------------------- /example project/Sources/CoreLib/CLLink.h: -------------------------------------------------------------------------------- 1 | #ifndef CLLink_h 2 | #define CLLink_h 3 | struct CLLink 4 | { 5 | 6 | void* data; 7 | struct CLLink* next; 8 | 9 | }; 10 | #endif -------------------------------------------------------------------------------- /example project/Sources/CoreLib/CLObject.clc: -------------------------------------------------------------------------------- 1 | CLObject 2 | { 3 | 4 | unsigned long retainCount; 5 | 6 | 7 | // constructor 8 | 9 | void init ( ) 10 | { 11 | 12 | retainCount = 1; 13 | 14 | } 15 | 16 | 17 | // destructor 18 | 19 | void destruct( ) 20 | { 21 | 22 | 23 | 24 | } 25 | 26 | 27 | // retains object 28 | 29 | void retain ( ) 30 | { 31 | 32 | retainCount = retainCount + 1; 33 | 34 | } 35 | 36 | 37 | // releases object 38 | 39 | void release ( ) 40 | { 41 | 42 | retainCount = retainCount - 1; 43 | 44 | if ( retainCount == 0 ) 45 | { 46 | 47 | self.destruct( ); 48 | free_object( self ); 49 | 50 | } 51 | 52 | } 53 | 54 | 55 | // describes object 56 | 57 | void describe ( ) 58 | { 59 | 60 | printf( "\nObject %li retainCount %li" , ( long ) self , retainCount ); 61 | 62 | } 63 | 64 | } -------------------------------------------------------------------------------- /example project/Sources/CoreLib/CLObjectList.clc: -------------------------------------------------------------------------------- 1 | #include "CLLink.h" 2 | #include "CLObject.clc" 3 | 4 | CLObjectList:CLObject 5 | { 6 | 7 | struct CLLink* head; // pointer to first link 8 | struct CLLink* last; // pointer to last link 9 | unsigned long length; // element count of list 10 | 11 | 12 | // constructor 13 | 14 | void init( ) 15 | { 16 | 17 | CLObject:init( self ); 18 | 19 | head = NULL; 20 | last = NULL; 21 | length = 0; 22 | 23 | } 24 | 25 | 26 | // destructor 27 | 28 | void destruct( ) 29 | { 30 | 31 | removeAllObjects( ); 32 | 33 | CLObject:destruct( self ); 34 | 35 | } 36 | 37 | 38 | // appends object to list 39 | 40 | void addObject( CLObject* theObject ) 41 | { 42 | 43 | struct CLLink* newLink; 44 | 45 | theObject.retain( ); 46 | 47 | // create link 48 | 49 | newLink = malloc( sizeof( struct CLLink ) ); 50 | newLink->data = theObject; 51 | newLink->next = NULL; 52 | 53 | if ( head == NULL ) head = newLink; 54 | else last->next = newLink; 55 | 56 | last = newLink; 57 | length = length + 1; 58 | 59 | } 60 | 61 | 62 | // adds object at given index 63 | 64 | void addObjectAtIndex( CLObject* theObject , 65 | unsigned long theIndex ) 66 | { 67 | 68 | struct CLLink* link; 69 | struct CLLink* lastLink; 70 | struct CLLink* newLink; 71 | unsigned long position; 72 | 73 | // init 74 | 75 | lastLink = NULL; 76 | link = head; 77 | position = 0; 78 | 79 | theObject.retain( ); 80 | 81 | while ( link != NULL ) 82 | { 83 | 84 | if ( position == theIndex ) 85 | { 86 | 87 | newLink = malloc( sizeof( struct CLLink ) ); 88 | newLink->data = theObject; 89 | newLink->next = link; 90 | 91 | if ( lastLink != NULL ) lastLink->next = newLink; 92 | else head = newLink; 93 | length = length + 1; 94 | 95 | return; 96 | 97 | } 98 | 99 | position += 1; 100 | lastLink = link; 101 | link = link->next; 102 | 103 | } 104 | 105 | } 106 | 107 | 108 | // appends given object list to object list 109 | 110 | void addObjectsInObjectList( CLObjectList* theObjectList ) 111 | { 112 | 113 | struct CLLink* link; 114 | 115 | if ( theObjectList.length > 0 ) 116 | { 117 | 118 | link = theObjectList.head; 119 | 120 | while ( link != NULL ) 121 | { 122 | 123 | addObject( link->data ); 124 | 125 | link = link->next; 126 | 127 | } 128 | 129 | } 130 | 131 | } 132 | 133 | 134 | // removes data from data chain 135 | 136 | void removeObject( CLObject* theObject ) 137 | { 138 | 139 | struct CLLink* link; 140 | struct CLLink* prev; 141 | 142 | CLObject* oneObject; 143 | 144 | // init 145 | 146 | link = head; 147 | prev = NULL; 148 | 149 | while ( link != NULL ) 150 | { 151 | 152 | if ( link->data == theObject ) 153 | { 154 | 155 | if ( link->next == NULL && prev != NULL ) 156 | { 157 | prev->next = NULL; 158 | last = prev; 159 | } 160 | else if ( link->next != NULL && prev == NULL ) 161 | { 162 | head = link->next; 163 | } 164 | else if ( link->next != NULL && prev != NULL ) 165 | { 166 | prev->next = link->next; 167 | } 168 | else 169 | { 170 | head = NULL; 171 | last = NULL; 172 | } 173 | 174 | oneObject = link->data; 175 | oneObject.release( ); 176 | 177 | free( link ); 178 | length -= 1; 179 | 180 | return; 181 | 182 | } 183 | 184 | prev = link; 185 | link = link->next; 186 | 187 | } 188 | 189 | } 190 | 191 | 192 | // removes object at given index 193 | 194 | CLObject* removeObjectAtIndex( unsigned long theIndex ) 195 | { 196 | 197 | // !!! a more optimized solution is needed 198 | 199 | CLObject* object; 200 | 201 | // init 202 | 203 | object = objectAtIndex( theIndex ); 204 | if ( object != NULL ) removeObject( object ); 205 | return object; 206 | 207 | } 208 | 209 | 210 | // empties object list 211 | 212 | void removeAllObjects( ) 213 | { 214 | 215 | struct CLLink* link; 216 | struct CLLink* prev; 217 | 218 | CLObject* object; 219 | 220 | // init 221 | 222 | link = head; 223 | prev = NULL; 224 | 225 | while ( link != NULL ) 226 | { 227 | 228 | prev = link; 229 | link = link->next; 230 | 231 | object = prev->data; 232 | object.release( ); 233 | 234 | free( prev ); 235 | 236 | } 237 | 238 | head = NULL; 239 | last = NULL; 240 | length = 0; 241 | 242 | } 243 | 244 | 245 | // returns object at given index 246 | 247 | CLObject* objectAtIndex( unsigned long theIndex ) 248 | { 249 | 250 | struct CLLink* link; 251 | unsigned long position; 252 | 253 | // init 254 | 255 | link = head; 256 | position = 0; 257 | 258 | while ( link != NULL ) 259 | { 260 | 261 | if ( position == theIndex ) return link->data; 262 | 263 | position += 1; 264 | link = link->next; 265 | 266 | } 267 | 268 | return NULL; 269 | 270 | } 271 | 272 | 273 | // check if object is in the list 274 | 275 | char containsObject( CLObject* theObject ) 276 | { 277 | 278 | struct CLLink* link; 279 | 280 | // init 281 | 282 | link = head; 283 | 284 | while ( link != NULL ) 285 | { 286 | 287 | if ( link->data == theObject ) return 1; 288 | 289 | link = link->next; 290 | 291 | } 292 | 293 | return 0; 294 | 295 | } 296 | 297 | 298 | // returns index of data 299 | 300 | unsigned long indexOfObject( CLObject* theObject ) 301 | { 302 | 303 | unsigned long index; 304 | struct CLLink* link; 305 | 306 | // init 307 | 308 | index = 0; 309 | link = head; 310 | 311 | while ( link != NULL ) 312 | { 313 | 314 | if ( link->data == theObject ) return index; 315 | 316 | index += 1; 317 | link = link->next; 318 | 319 | } 320 | 321 | return 0; 322 | 323 | } 324 | 325 | 326 | // returns first object 327 | 328 | CLObject* firstObject( ) 329 | { 330 | 331 | if ( head != NULL ) return head->data; 332 | return NULL; 333 | 334 | } 335 | 336 | 337 | // returns last object 338 | 339 | CLObject* lastObject( ) 340 | { 341 | 342 | if ( last != NULL ) return last->data; 343 | return NULL; 344 | 345 | } 346 | 347 | 348 | // describes instance 349 | 350 | void describe( ) 351 | { 352 | 353 | struct CLLink* link; 354 | CLObject* object; 355 | 356 | // init 357 | 358 | link = head; 359 | 360 | while ( link != NULL ) 361 | { 362 | 363 | object = link->data; 364 | object.describe( ); 365 | printf( " " ); 366 | link = link->next; 367 | 368 | } 369 | 370 | } 371 | 372 | } -------------------------------------------------------------------------------- /example project/Sources/CoreLib/CLStringDataList.clc: -------------------------------------------------------------------------------- 1 | #include "CLString.clc" 2 | #include "CLObject.clc" 3 | #include "CLDataList.clc" 4 | 5 | 6 | CLStringDataList:CLObject 7 | { 8 | 9 | 10 | // checks if string is in list 11 | 12 | char containsString( CLString* theString , 13 | CLDataList* theObjectList ) 14 | { 15 | 16 | struct CLLink* link; 17 | CLString* string; 18 | 19 | link = theObjectList.head; 20 | 21 | while ( link != NULL ) 22 | { 23 | 24 | string = link->data; 25 | 26 | if ( theString.equals( string ) == 1 ) return 1; 27 | 28 | link = link->next; 29 | 30 | } 31 | 32 | return 0; 33 | 34 | } 35 | 36 | 37 | // checks if list contains string 38 | 39 | unsigned long indexOfString ( CLString* theString , 40 | CLDataList* theDataList ) 41 | { 42 | 43 | unsigned long index; 44 | struct CLLink* link; 45 | CLString* string; 46 | 47 | // init 48 | 49 | index = 0; 50 | struct CLLink* link = theDataList.head; 51 | 52 | while ( link != NULL ) 53 | { 54 | 55 | CLString* string = link->data; 56 | 57 | if ( theString.equals( string ) == 1 ) return index; 58 | 59 | index += 1; 60 | 61 | link = link->next; 62 | 63 | } 64 | 65 | return 0; 66 | 67 | } 68 | 69 | 70 | // splits strings into words separated by given character 71 | 72 | CLDataList* splitStringByCharacter( CLString* theString , 73 | char theCharacter ) 74 | { 75 | 76 | struct CLChar* link; 77 | CLString* word; 78 | CLDataList* result; 79 | 80 | // init 81 | 82 | result:alloc( ); // needs release 83 | result:init( ); 84 | word:alloc( ); // needs release 85 | word:init( ); 86 | 87 | link = theString.head; 88 | 89 | while ( link != NULL ) 90 | { 91 | 92 | if ( link->character == theCharacter ) 93 | { 94 | 95 | if ( word.length > 0 ) 96 | { 97 | 98 | result:addData( word ); 99 | word:release( ); 100 | word:alloc( ); 101 | word:init( ); 102 | 103 | } 104 | 105 | } 106 | else 107 | { 108 | 109 | word:appendCharacter( link->character ); 110 | 111 | } 112 | 113 | link = link->next; 114 | 115 | } 116 | 117 | if ( word.length > 0 ) result:addData( word ); 118 | 119 | word:release( ); 120 | 121 | return result; 122 | 123 | } 124 | 125 | } -------------------------------------------------------------------------------- /example project/Sources/CoreLib/CLStringObjectList.clc: -------------------------------------------------------------------------------- 1 | #include "CLString.clc" 2 | #include "CLObject.clc" 3 | #include "CLObjectList.clc" 4 | 5 | 6 | CLStringObjectList:CLObject 7 | { 8 | 9 | 10 | // checks if string is in list 11 | 12 | char containsString( CLString* theString , 13 | CLObjectList* theObjectList ) 14 | { 15 | 16 | struct CLLink* link; 17 | CLString* string; 18 | 19 | link = theObjectList.head; 20 | 21 | while ( link != NULL ) 22 | { 23 | 24 | string = ( CLString* ) link->data; 25 | 26 | if ( theString.equals( string ) == 1 ) return 1; 27 | 28 | link = link->next; 29 | 30 | } 31 | 32 | return 0; 33 | 34 | } 35 | 36 | 37 | // checks if list contains string 38 | 39 | unsigned long indexOfString( CLString* theString , 40 | CLObjectList* theObjectList ) 41 | { 42 | 43 | unsigned long index; 44 | struct CLLink* link; 45 | CLString* string; 46 | 47 | // init 48 | 49 | index = 0; 50 | link = theObjectList.head; 51 | 52 | while ( link != NULL ) 53 | { 54 | 55 | string = ( CLString* ) link->data; 56 | 57 | if ( theString.equals( string ) == 1 ) return index; 58 | 59 | index += 1; 60 | 61 | link = link->next; 62 | 63 | } 64 | 65 | return 0; 66 | 67 | } 68 | 69 | 70 | // removes given string from object list 71 | 72 | void removeString( CLString* theString , 73 | CLObjectList* theObjectList ) 74 | { 75 | 76 | struct CLLink* link; 77 | CLObject* result; 78 | CLString* string; 79 | 80 | // init 81 | 82 | link = theObjectList.head; 83 | result = NULL; 84 | 85 | while ( link != NULL ) 86 | { 87 | 88 | string = ( CLString* ) link->data; 89 | 90 | if ( theString.equals( string ) == 1 ) 91 | { 92 | result = link->data; 93 | break; 94 | } 95 | 96 | link = link->next; 97 | 98 | } 99 | 100 | if ( result != NULL ) theObjectList.removeObject( result ); 101 | 102 | } 103 | 104 | 105 | // removes given strings from object list 106 | 107 | void removeStrings( CLObjectList* theStringList , 108 | CLObjectList* theObjectList ) 109 | { 110 | 111 | struct CLLink* link; 112 | 113 | link = theStringList.head; 114 | 115 | while( link != NULL ) 116 | { 117 | 118 | CLString* string; 119 | string = ( CLString* ) link->data; 120 | removeString( string , theObjectList ); 121 | link = link->next; 122 | 123 | } 124 | 125 | } 126 | 127 | 128 | // adds string to list if it's not exist 129 | 130 | void addStringAsUnique( CLString* theString , 131 | CLObjectList* theObjectList ) 132 | { 133 | 134 | char contains; 135 | 136 | // init 137 | 138 | contains = containsString( theString , theObjectList ); 139 | if ( contains == 0 ) theObjectList.addObject( ( CLObject* ) theString ); 140 | 141 | } 142 | 143 | 144 | // adds strings to list if they're not exist 145 | 146 | void addStringsAsUnique( CLObjectList* theStringList , 147 | CLObjectList* theObjectList ) 148 | { 149 | 150 | struct CLLink* link; 151 | 152 | // init 153 | 154 | link = theStringList.head; 155 | 156 | while ( link != NULL ) 157 | { 158 | 159 | CLString* string; 160 | string = ( CLString* ) link->data; 161 | 162 | addStringAsUnique( string , theObjectList ); 163 | 164 | link = link->next; 165 | 166 | } 167 | 168 | } 169 | 170 | 171 | // splits strings into words separated by given character 172 | 173 | CLObjectList* splitStringByCharacter( CLString* theString , 174 | char theCharacter ) 175 | { 176 | 177 | struct CLChar* link; 178 | CLString* word; 179 | CLObjectList* result; 180 | 181 | // init 182 | 183 | result:alloc( ); // needs release 184 | result:init( ); 185 | word:alloc( ); // needs release 186 | word:init( ); 187 | 188 | link = theString.head; 189 | 190 | while ( link != NULL ) 191 | { 192 | 193 | if ( link->character == theCharacter ) 194 | { 195 | 196 | if ( word.length > 0 ) 197 | { 198 | 199 | result:addObject( ( CLObject* ) word ); 200 | word:release( ); 201 | word:alloc( ); 202 | word:init( ); 203 | 204 | } 205 | 206 | } 207 | else 208 | { 209 | 210 | word:appendCharacter( link->character ); 211 | 212 | } 213 | 214 | link = link->next; 215 | 216 | } 217 | 218 | if ( word.length > 0 ) result:addObject( ( CLObject* ) word ); 219 | 220 | word:release( ); 221 | 222 | return result; 223 | 224 | } 225 | 226 | } -------------------------------------------------------------------------------- /example project/Sources/CoreLib/CLThread.clc: -------------------------------------------------------------------------------- 1 | // 2 | // CLThread class 3 | // 4 | // Contains a POSIX thread and mutex 5 | // Thread can be started with the start method 6 | // Containing classes can use the mutex member for locking 7 | // 8 | 9 | #include 10 | #include "CLObject.clc" 11 | 12 | 13 | CLThread:CLObject 14 | { 15 | 16 | char alive; 17 | pthread_t thread; 18 | pthread_mutex_t mutex; 19 | 20 | 21 | // constructor 22 | 23 | void init( ) 24 | { 25 | 26 | CLObject:init( self ); 27 | 28 | alive = 1; 29 | 30 | pthread_mutex_init( &mutex , NULL ); 31 | 32 | } 33 | 34 | 35 | // destructor 36 | 37 | void destruct( ) 38 | { 39 | 40 | int code; 41 | 42 | code = pthread_cancel( thread ); 43 | if ( code ) printf( "CLThread pthread_cancel error %d\n", code ); 44 | 45 | pthread_mutex_destroy( &mutex ); 46 | 47 | CLObject:destruct( self ); 48 | 49 | } 50 | 51 | 52 | // starts thread 53 | 54 | void start( ) 55 | { 56 | 57 | int code; 58 | 59 | code = pthread_create( 60 | &thread , 61 | NULL, 62 | ( void*(*)(void*) ) run , 63 | self ); 64 | 65 | if ( code ) printf( "CLThread pthread_create error %d\n", code ); 66 | 67 | } 68 | 69 | 70 | // thread execution function 71 | 72 | void* run( ) 73 | { 74 | 75 | return NULL; 76 | 77 | } 78 | 79 | } -------------------------------------------------------------------------------- /example project/Sources/GLTexturePixelText.clc: -------------------------------------------------------------------------------- 1 | #include "TLPixelText.clc" 2 | #include "GLBitmap.clc" 3 | #include "GLBitmapPixelText.clc" 4 | #include "GLTexture.clc" 5 | 6 | 7 | GLTexturePixelText:GLTexture 8 | { 9 | 10 | 11 | void init( char* theText , 12 | int theWidth , 13 | int theHeight , 14 | int theSize ) 15 | { 16 | 17 | CLObject:init( self ); 18 | 19 | TLPixelText* pixelText = TLPixelText:alloc( ); 20 | GLBitmapPixelText* foreGround = GLBitmapPixelText:alloc( ); 21 | GLBitmap* backGround = GLBitmap:alloc( ); 22 | 23 | pixelText:initWithCString( theText ); 24 | foreGround:initWithDimensions( theWidth , theHeight ); 25 | foreGround:drawPixelTextWithSize( pixelText , theSize ); 26 | foreGround.addShadow( ); 27 | 28 | backGround:initWithDimensions( theWidth , theHeight ); 29 | backGround:fillRectangle( 0 , 0 , theWidth , theHeight , 1.0 , 1.0 , 1.0 , .5 ); 30 | backGround:blendBitmap( ( GLBitmap* ) foreGround , 0 , 0 ); 31 | 32 | glGenTextures( 1 , &glid ); 33 | glBindTexture( GL_TEXTURE_2D , glid ); 34 | 35 | glTexParameteri( GL_TEXTURE_2D , GL_TEXTURE_WRAP_S , GL_CLAMP_TO_EDGE ); 36 | glTexParameteri( GL_TEXTURE_2D , GL_TEXTURE_WRAP_T , GL_CLAMP_TO_EDGE ); 37 | glTexParameteri( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_LINEAR ); 38 | glTexParameteri( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_LINEAR_MIPMAP_LINEAR ); 39 | 40 | glTexImage2D( 41 | GL_TEXTURE_2D, 42 | 0, 43 | GL_RGBA, 44 | backGround.width, 45 | backGround.height, 46 | 0, 47 | GL_RGBA, 48 | GL_UNSIGNED_BYTE, 49 | backGround.data ); 50 | 51 | glGenerateMipmap( GL_TEXTURE_2D ); 52 | 53 | backGround.release( ); 54 | foreGround.release( ); 55 | pixelText.release( ); 56 | 57 | } 58 | 59 | 60 | } -------------------------------------------------------------------------------- /example project/Sources/GraphicsLib/GLBitmap.clc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "CLObject.clc" 5 | 6 | 7 | GLBitmap:CLObject 8 | { 9 | 10 | unsigned char* data; 11 | int length; 12 | 13 | int width; 14 | int height; 15 | 16 | 17 | void initWithDimensions( int theWidth , 18 | int theHeight ) 19 | { 20 | 21 | CLObject:init( self ); 22 | 23 | width = theWidth; 24 | height = theHeight; 25 | length = 4 * width * height; 26 | 27 | data = malloc( length ); 28 | memset( data , 0x0 , length ); 29 | 30 | } 31 | 32 | 33 | void destruct( ) 34 | { 35 | 36 | free( data ); 37 | 38 | CLObject:destruct( self ); 39 | 40 | } 41 | 42 | 43 | void fillRectangle( int theX , 44 | int theY , 45 | int theWidth , 46 | int theHeight , 47 | float theR , 48 | float theG , 49 | float theB , 50 | float theA ) 51 | { 52 | 53 | unsigned int r = ( int ) ( theR * 255.0 ); 54 | unsigned int g = ( int ) ( theG * 255.0 ); 55 | unsigned int b = ( int ) ( theB * 255.0 ); 56 | unsigned int a = ( int ) ( theA * 255.0 ); 57 | 58 | for ( int y = theY ; y < theY + theHeight ; y++ ) 59 | { 60 | 61 | for ( int x = theX ; x < theX + theWidth ; x++ ) 62 | { 63 | 64 | int position = ( y * width + x ) * 4; 65 | 66 | data[ position ] = r; 67 | data[ position + 1 ] = g; 68 | data[ position + 2 ] = b; 69 | data[ position + 3 ] = a; 70 | 71 | } 72 | 73 | } 74 | 75 | } 76 | 77 | 78 | void setPixel( int theX , int theY , int theR , int theG , int theB , int theA ) 79 | { 80 | printf( "" ); 81 | } 82 | 83 | 84 | void getPixel( int theX , int theY , int* theR , int* theG , int* theB , int* theA ) 85 | { 86 | printf( "" ); 87 | } 88 | 89 | 90 | void addShadow ( ) 91 | { 92 | 93 | unsigned char* clone = malloc( length ); 94 | memcpy( clone , data , length ); 95 | 96 | for ( int y = 0 ; y < height ; y++ ) 97 | { 98 | 99 | for ( int x = 0 ; x < width ; x++ ) 100 | { 101 | 102 | int srcIndex = ( y * width + x ) * 4; 103 | 104 | unsigned int srcA = clone[ srcIndex + 3 ]; 105 | 106 | if ( srcA > 0 ) 107 | { 108 | 109 | int NI = ( ( y - 1 ) * width + x ) * 4; 110 | int SI = ( ( y + 1 ) * width + x ) * 4; 111 | int EI = ( y * width + x - 1 ) * 4; 112 | int WI = ( y * width + x + 1 ) * 4; 113 | 114 | if ( NI > 0 && clone[ NI + 3 ] == 0 ) 115 | { 116 | data[ NI + 3 ] = 155; 117 | int NI2 = ( ( y - 2 ) * width + x ) * 4; 118 | if ( NI2 > 0 && clone[ NI2 + 3 ] == 0 ) data[ NI2 + 3 ] = 55; 119 | } 120 | 121 | if ( SI < length && clone[ SI + 3 ] == 0 ) 122 | { 123 | data[ SI + 3 ] = 155; 124 | int SI2 = ( ( y + 2 ) * width + x ) * 4; 125 | if ( SI2 < length && clone[ SI2 + 3 ] == 0 ) data[ SI2 + 3 ] = 55; 126 | } 127 | 128 | if ( x - 1 > 0 && clone[ EI + 3 ] == 0 ) 129 | { 130 | data[ EI + 3 ] = 155; 131 | int EI2 = ( y * width + x - 2 ) * 4; 132 | if ( EI2 > 0 && clone[ EI2 + 3 ] == 0 ) data[ EI2 + 3 ] = 55; 133 | } 134 | 135 | if ( x + 1 < width && clone[ WI + 3 ] == 0 ) 136 | { 137 | data[ WI + 3 ] = 155; 138 | int WI2 = ( y * width + x + 2 ) * 4; 139 | if ( WI2 < length && clone[ WI2 + 3 ] == 0 ) data[ WI2 + 3 ] = 55; 140 | } 141 | 142 | } 143 | 144 | } 145 | 146 | } 147 | 148 | free( clone ); 149 | 150 | } 151 | 152 | 153 | void blendBitmap ( GLBitmap* theBitmap , int theX , int theY ) 154 | { 155 | 156 | int bx = theX + theBitmap.width; 157 | if ( bx > width ) bx = width; 158 | int by = theY + theBitmap.height; 159 | if ( by > height ) by = height; 160 | 161 | unsigned char* srcData = theBitmap.data; 162 | unsigned char* dstData = data; 163 | 164 | for ( int y = theY ; y < by ; y++ ) 165 | { 166 | 167 | for ( int x = theX ; x < bx ; x++ ) 168 | { 169 | 170 | int srcIndex = ( ( y - theY ) * theBitmap.width + ( x - theX ) ) * 4; 171 | int dstIndex = ( y * width + x ) * 4; 172 | 173 | float srcR = ( float ) srcData[ srcIndex ] / 255.0; 174 | float srcG = ( float ) srcData[ srcIndex + 1 ] / 255.0; 175 | float srcB = ( float ) srcData[ srcIndex + 2 ] / 255.0; 176 | float srcA = ( float ) srcData[ srcIndex + 3 ] / 255.0; 177 | 178 | float dstR = ( float ) dstData[ dstIndex ] / 255.0; 179 | float dstG = ( float ) dstData[ dstIndex + 1 ] / 255.0; 180 | float dstB = ( float ) dstData[ dstIndex + 2 ] / 255.0; 181 | float dstA = ( float ) dstData[ dstIndex + 3 ] / 255.0; 182 | 183 | float outA = srcA + dstA * ( 1 - srcA ); 184 | float outR = ( srcR * srcA + dstR * dstA * ( 1 - srcA ) ) / outA; 185 | float outG = ( srcG * srcA + dstG * dstA * ( 1 - srcA ) ) / outA; 186 | float outB = ( srcB * srcA + dstB * dstA * ( 1 - srcA ) ) / outA; 187 | 188 | dstData[ dstIndex ] = ( int ) ( outR * 255.0 ); 189 | dstData[ dstIndex + 1 ] = ( int ) ( outG * 255.0 ); 190 | dstData[ dstIndex + 2 ] = ( int ) ( outB * 255.0 ); 191 | dstData[ dstIndex + 3 ] = ( int ) ( outA * 255.0 ); 192 | 193 | } 194 | 195 | } 196 | 197 | } 198 | 199 | } -------------------------------------------------------------------------------- /example project/Sources/GraphicsLib/GLBitmapPixelText.clc: -------------------------------------------------------------------------------- 1 | #include "GLBitmap.clc" 2 | #include "TLPixelText.clc" 3 | #include "TLPixelFont.clc" 4 | 5 | GLBitmapPixelText:GLBitmap 6 | { 7 | 8 | 9 | // constructor 10 | 11 | void init( char* theLabel , 12 | int theWidth , 13 | int theHeight ) 14 | { 15 | 16 | GLBitmap:initWithDimensions( self , theWidth , theHeight ); 17 | 18 | } 19 | 20 | 21 | // desctructor 22 | 23 | void destruct( ) 24 | { 25 | 26 | GLBitmap:destruct( self ); 27 | 28 | } 29 | 30 | 31 | // draws pixel text in image 32 | 33 | void drawPixelTextWithSize( TLPixelText* theText , 34 | float theSize ) 35 | { 36 | 37 | float dx = ( float ) width - theText.width * theSize; 38 | float dy = ( float ) height - theText.height * theSize; 39 | 40 | dx /= 2; 41 | dy /= 2; 42 | 43 | struct CLLink* link = theText.letters.head; 44 | 45 | while ( link != NULL ) 46 | { 47 | 48 | TLPixelFont* font = link->data; 49 | float* cdata = font.data; 50 | 51 | if ( font.length > 0 ) 52 | { 53 | 54 | for ( int index = 0 ; 55 | index < font.length ; 56 | index += 2 ) 57 | { 58 | 59 | fillRectangle( ( int ) dx + cdata[ index ] * theSize , 60 | ( int ) dy + cdata[ index + 1 ] * theSize , 61 | ( int ) theSize , 62 | ( int ) theSize , 63 | 1 , 64 | 1 , 65 | 1 , 66 | 1 ); 67 | 68 | } 69 | 70 | } 71 | 72 | dx += font.width * theSize; 73 | 74 | link = link->next; 75 | 76 | } 77 | 78 | } 79 | 80 | } -------------------------------------------------------------------------------- /example project/Sources/GraphicsLib/GLDrawable.clc: -------------------------------------------------------------------------------- 1 | #include "CLObject.clc" 2 | 3 | 4 | GLDrawable:CLObject 5 | { 6 | 7 | GLuint mode; 8 | GLuint texture; 9 | 10 | GLfloat* vertexes; 11 | GLsizei vertexCount; 12 | long vertexesSize; 13 | 14 | GLushort* indexes; 15 | GLsizei indexCount; 16 | long indexesSize; 17 | 18 | 19 | // constructor 20 | 21 | void init( ) 22 | { 23 | 24 | // printf( "\nGLDrawable init" ); 25 | 26 | CLObject:init( self ); 27 | 28 | } 29 | 30 | 31 | // destructor 32 | 33 | void destruct( ) 34 | { 35 | 36 | free( vertexes ); 37 | free( indexes ); 38 | 39 | CLObject:destruct( self ); 40 | 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /example project/Sources/GraphicsLib/GLShader.clc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "CLObject.clc" 4 | 5 | // Combines 6 | // - shader program compiling and linking 7 | // - uniform and attribute location binding 8 | // - drawable and vertex buffer object handling with shader's attrib structure 9 | 10 | 11 | GLShader:CLObject 12 | { 13 | 14 | char* name; 15 | GLuint program; 16 | GLuint vertexShader; 17 | GLuint fragmentShader; 18 | 19 | GLuint uniformCounter; 20 | GLint* uniformLocations; 21 | const char** uniformIdentifiers; 22 | 23 | int attributeStride; 24 | GLuint attributeCounter; 25 | GLuint* attributeLocations; 26 | int* attributeComponents; 27 | const char** attributeIdentifiers; 28 | long* attributeOffsetSizes; 29 | 30 | 31 | // constructor 32 | 33 | void init ( char* theName ) 34 | { 35 | 36 | // printf( "\nGLShader init %s" , theName ); 37 | 38 | CLObject:init( self ); 39 | 40 | // program related 41 | 42 | name = theName; 43 | program = glCreateProgram( ); 44 | 45 | uniformCounter = 0; 46 | uniformLocations = malloc( sizeof( GLint ) ); 47 | uniformIdentifiers = malloc( sizeof( const char* ) ); 48 | 49 | attributeStride = 0; 50 | attributeCounter = 0; 51 | attributeLocations = malloc( sizeof( GLuint ) ); 52 | attributeComponents = malloc( sizeof( int ) ); 53 | attributeIdentifiers = malloc( sizeof( const char* ) ); 54 | attributeOffsetSizes = malloc( sizeof( long ) ); 55 | 56 | } 57 | 58 | 59 | // destructor 60 | 61 | void destruct ( ) 62 | { 63 | 64 | // printf( "\nGLShader destruct %s" , name ); 65 | 66 | // delete program 67 | 68 | if ( program != 0 ) glDeleteProgram( program ); 69 | 70 | free( uniformLocations ); 71 | free( uniformIdentifiers ); 72 | 73 | free( attributeLocations ); 74 | free( attributeIdentifiers ); 75 | free( attributeComponents ); 76 | free( attributeOffsetSizes ); 77 | 78 | program = 0; 79 | 80 | CLObject:destruct( self ); 81 | 82 | } 83 | 84 | 85 | // adds vertex shader 86 | 87 | void addVertexShader ( const GLchar* theSource ) 88 | { 89 | 90 | char success = self:compileShader( &(vertexShader) , 91 | GL_VERTEX_SHADER , 92 | theSource ); 93 | 94 | if ( success != 1 ) printf("\nShader %s : Failed to compile vertex shader" , name ); 95 | else 96 | { 97 | printf("\nShader %s : Vertex shader compiled" , name ); 98 | glAttachShader( program , vertexShader ); 99 | } 100 | 101 | } 102 | 103 | 104 | // adds fragment shader 105 | 106 | void addFragmentShader ( const GLchar* theSource ) 107 | { 108 | 109 | char success = self:compileShader( &(fragmentShader) , 110 | GL_FRAGMENT_SHADER , 111 | theSource ); 112 | 113 | if ( success != 1 ) printf("\nShader %s : Failed to compile fragment shader" , name ); 114 | else 115 | { 116 | printf("\nShader %s : Fragment shader compiled" , name ); 117 | glAttachShader( program , fragmentShader ); 118 | } 119 | 120 | } 121 | 122 | 123 | // adds attribute location 124 | 125 | void addAttributeLocation ( GLuint theLocation , int theComponentCount , const char* theIdentifier ) 126 | { 127 | 128 | attributeCounter += 1; 129 | attributeLocations = realloc( attributeLocations , sizeof( GLuint ) * attributeCounter ); 130 | attributeComponents = realloc( attributeComponents , sizeof( int ) * attributeCounter ); 131 | attributeIdentifiers = realloc( attributeIdentifiers , sizeof( const char* ) * attributeCounter ); 132 | attributeOffsetSizes = realloc( attributeOffsetSizes , sizeof( long ) * attributeCounter ); 133 | 134 | attributeLocations[ attributeCounter - 1 ] = theLocation; 135 | attributeComponents[ attributeCounter - 1 ] = theComponentCount; 136 | attributeIdentifiers[ attributeCounter - 1 ] = theIdentifier; 137 | attributeOffsetSizes[ attributeCounter - 1 ] = attributeStride * sizeof( GLfloat ); 138 | 139 | attributeStride += theComponentCount; 140 | 141 | } 142 | 143 | 144 | // adds uniform identifier, after link we can get the location for the id 145 | 146 | void addUniformIdentifier ( const char* theIdentifier ) 147 | { 148 | 149 | uniformCounter += 1; 150 | uniformLocations = realloc( uniformLocations , sizeof( GLint ) * uniformCounter ); 151 | uniformIdentifiers = realloc( uniformIdentifiers , sizeof( const char* ) * uniformCounter ); 152 | 153 | uniformIdentifiers[ uniformCounter - 1 ] = theIdentifier; 154 | 155 | } 156 | 157 | 158 | // returns uniform location for identifier 159 | 160 | GLint getUniformLocation ( const char* theIdentifier ) 161 | { 162 | 163 | for ( int index = 0 ; index < uniformCounter ; index++ ) 164 | { 165 | if ( strcmp( uniformIdentifiers[ index ] , theIdentifier ) == 0 ) return uniformLocations[ index ]; 166 | } 167 | 168 | return 0; 169 | 170 | } 171 | 172 | 173 | // link program and shaders together 174 | 175 | void link ( ) 176 | { 177 | 178 | // bind attribute Identifiers. this needs to be done prior to linking. 179 | 180 | for ( int index = 0 ; index < attributeCounter ; index++ ) 181 | { 182 | 183 | glBindAttribLocation( program , 184 | attributeLocations[ index ] , 185 | attributeIdentifiers[ index ] ); 186 | 187 | } 188 | 189 | // link program 190 | 191 | char success = self:linkProgram( ); 192 | 193 | if ( success != 1 ) 194 | { 195 | 196 | printf("\nShader %s : Failed to link self->program: %d" , name , program ); 197 | 198 | if ( program > 0 ) glDeleteProgram( program ); 199 | 200 | program = 0; 201 | 202 | } 203 | else 204 | { 205 | 206 | printf("\nShader %s : Program linked" , name ); 207 | 208 | // get uniform Identifiers 209 | 210 | for ( int index = 0 ; index < uniformCounter ; index++ ) 211 | { 212 | 213 | uniformLocations[ index ] = glGetUniformLocation( program , uniformIdentifiers[ index ] ); 214 | 215 | } 216 | 217 | } 218 | 219 | // everything is ok, release shaders, program stays 220 | 221 | if ( vertexShader > 0 ) 222 | { 223 | glDetachShader( program , vertexShader ); 224 | glDeleteShader( vertexShader ); 225 | } 226 | 227 | if ( fragmentShader > 0 ) 228 | { 229 | glDetachShader( program , fragmentShader ); 230 | glDeleteShader( fragmentShader ); 231 | } 232 | 233 | vertexShader = 0; 234 | fragmentShader = 0; 235 | 236 | // calcualte stride in bytes 237 | 238 | attributeStride = attributeStride * sizeof( GLfloat ); 239 | 240 | } 241 | 242 | 243 | // compile shader 244 | 245 | char compileShader ( GLuint* theShader , 246 | GLenum theType , 247 | const GLchar* theSource ) 248 | { 249 | 250 | GLint status; 251 | GLint logLength; 252 | 253 | // create shader 254 | 255 | *theShader = glCreateShader( theType ); 256 | 257 | // upload source 258 | 259 | glShaderSource( *theShader , 1 , &theSource , NULL ); 260 | 261 | // compile 262 | 263 | glCompileShader( *theShader ); 264 | 265 | // get compile log 266 | 267 | glGetShaderiv( *theShader , 268 | GL_INFO_LOG_LENGTH , 269 | &logLength ); 270 | 271 | if ( logLength > 0 ) 272 | { 273 | GLchar *log = ( GLchar* ) malloc( logLength ); 274 | glGetShaderInfoLog( *theShader , logLength , &logLength , log ); 275 | printf("\nShader %s : compile log:\n%s" , name , log ); 276 | free( log ); 277 | } 278 | 279 | // get status 280 | 281 | glGetShaderiv( *theShader , 282 | GL_COMPILE_STATUS , 283 | &status ); 284 | 285 | if ( status == 0 ) 286 | { 287 | glDeleteShader(*theShader); 288 | return 0; 289 | } 290 | 291 | return 1; 292 | 293 | } 294 | 295 | 296 | // link shaders together in gpu 297 | 298 | char linkProgram ( ) 299 | { 300 | 301 | GLint status; 302 | GLint logLength; 303 | 304 | // link program 305 | 306 | glLinkProgram( program ); 307 | 308 | // get linkage log 309 | 310 | glGetProgramiv( program , 311 | GL_INFO_LOG_LENGTH , 312 | &logLength ); 313 | 314 | if ( logLength > 0 ) 315 | { 316 | GLchar *log = ( GLchar* ) malloc( logLength ); 317 | glGetProgramInfoLog( program , logLength , &logLength , log ); 318 | printf("\nShader %s : Program link log:\n%s" , name , log ); 319 | free( log ); 320 | } 321 | 322 | // get status 323 | 324 | glGetProgramiv( program , 325 | GL_LINK_STATUS , 326 | &status ); 327 | 328 | if ( status == 0 ) return 0; 329 | 330 | return 1; 331 | 332 | } 333 | 334 | 335 | // renders vertex buffer 336 | 337 | void activate ( ) 338 | { 339 | 340 | // using program 341 | 342 | glUseProgram( program ); 343 | 344 | // enable vertex arrays 345 | 346 | for ( int index = 0 ; 347 | index < attributeCounter ; 348 | index++ ) 349 | { 350 | 351 | // printf( "\ncomponents %i stride %i offsetsize %i" , attributeComponents[ index ] , attributeStride , attributeOffsetSizes[ index ] ); 352 | 353 | glEnableVertexAttribArray ( index ); 354 | 355 | glVertexAttribPointer( index , 356 | attributeComponents[ index ] , 357 | GL_FLOAT , 358 | GL_FALSE , 359 | attributeStride , 360 | ( const GLvoid* )( attributeOffsetSizes[ index ] ) ); 361 | 362 | } 363 | 364 | } 365 | 366 | } -------------------------------------------------------------------------------- /example project/Sources/GraphicsLib/GLTexture.clc: -------------------------------------------------------------------------------- 1 | #include "CLObject.clc" 2 | #include "GLBitmap.clc" 3 | 4 | 5 | GLTexture:CLObject 6 | { 7 | 8 | GLuint glid; 9 | 10 | 11 | // constructor 12 | 13 | void initWithGLBitmap( GLBitmap* theBitmap ) 14 | { 15 | 16 | CLObject:init( self ); 17 | 18 | glGenTextures( 1 , &glid ); 19 | glBindTexture( GL_TEXTURE_2D , glid ); 20 | 21 | glTexParameteri( GL_TEXTURE_2D , GL_TEXTURE_WRAP_S , GL_CLAMP_TO_EDGE ); 22 | glTexParameteri( GL_TEXTURE_2D , GL_TEXTURE_WRAP_T , GL_CLAMP_TO_EDGE ); 23 | glTexParameteri( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_LINEAR ); 24 | glTexParameteri( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_LINEAR_MIPMAP_LINEAR ); 25 | 26 | glTexImage2D( 27 | GL_TEXTURE_2D, 28 | 0, 29 | GL_RGBA, 30 | theBitmap.width, 31 | theBitmap.height, 32 | 0, 33 | GL_RGBA, 34 | GL_UNSIGNED_BYTE, 35 | theBitmap.data ); 36 | 37 | glGenerateMipmap( GL_TEXTURE_2D ); 38 | 39 | } 40 | 41 | 42 | void initWithDimensions( int theWidth , int theHeight ) 43 | { 44 | 45 | CLObject:init( self ); 46 | 47 | glGenTextures( 1 , &glid ); 48 | glBindTexture( GL_TEXTURE_2D , glid ); 49 | 50 | // glTexParameteri( GL_TEXTURE_2D , GL_TEXTURE_WRAP_S , GL_CLAMP_TO_EDGE ); 51 | // glTexParameteri( GL_TEXTURE_2D , GL_TEXTURE_WRAP_T , GL_CLAMP_TO_EDGE ); 52 | // glTexParameteri( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_LINEAR ); 53 | glTexParameteri( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_LINEAR ); 54 | 55 | glTexImage2D( 56 | GL_TEXTURE_2D, 57 | 0, 58 | GL_RGBA, 59 | theWidth, 60 | theHeight, 61 | 0, 62 | GL_RGBA, 63 | GL_UNSIGNED_BYTE, 64 | NULL ); 65 | 66 | glGenerateMipmap( GL_TEXTURE_2D ); 67 | 68 | } 69 | 70 | 71 | // destructor 72 | 73 | void destruct( ) 74 | { 75 | 76 | glDeleteTextures( 1 , &(glid) ); 77 | 78 | CLObject:destruct( self ); 79 | 80 | } 81 | 82 | } -------------------------------------------------------------------------------- /example project/Sources/GraphicsLib/GLVertexBlock.clc: -------------------------------------------------------------------------------- 1 | #include "CLDataList.clc" 2 | #include "CLObject.clc" 3 | 4 | 5 | GLVertexBlock:CLObject 6 | { 7 | 8 | GLuint mode; 9 | GLuint texture; 10 | 11 | GLushort* indexes; 12 | GLsizei indexCount; 13 | 14 | long oldIndexesSize; 15 | long indexesSize; 16 | 17 | GLsizei vertexCount; 18 | long vertexesSize; 19 | 20 | CLDataList* drawables; 21 | 22 | 23 | void init( ) 24 | { 25 | 26 | // printf( "\nGLVertexBlock init" ); 27 | 28 | CLObject:init( self ); 29 | 30 | indexes = NULL; 31 | drawables = NULL; 32 | 33 | } 34 | 35 | 36 | void destruct( ) 37 | { 38 | 39 | // printf( "\nGLVertexBlock destruct" ); 40 | 41 | CLObject:destruct( self ); 42 | 43 | if ( indexes != NULL ) free( indexes ); 44 | if ( drawables != NULL ) drawables.release( ); 45 | 46 | } 47 | 48 | // describes object 49 | 50 | void describe ( ) 51 | { 52 | 53 | printf( "\nmode: %u texture: %u indexCount %i vertexCount %i" , mode , texture , indexCount , vertexCount ); 54 | 55 | } 56 | 57 | } -------------------------------------------------------------------------------- /example project/Sources/GraphicsLib/GLVoxelLabel.clc: -------------------------------------------------------------------------------- 1 | #include "GLCubePC33.clc" 2 | #include "CLObject.clc" 3 | #include "GLDrawable.clc" 4 | #include "CLDataList.clc" 5 | #include "TLPixelFont.clc" 6 | 7 | 8 | GLVoxelLabel:CLObject 9 | { 10 | 11 | 12 | CLDataList* cubeCache; 13 | CLDataList* drawables; 14 | 15 | float x; 16 | float y; 17 | float z; 18 | float size; 19 | float width; 20 | 21 | 22 | // constructor 23 | 24 | void init ( float theSize , 25 | float theX , 26 | float theY , 27 | float theZ ) 28 | { 29 | 30 | // printf( "\nGLVoxelLabel init" ); 31 | 32 | CLObject:init( self ); 33 | 34 | drawables = CLDataList:alloc( ); 35 | cubeCache = CLDataList:alloc( ); 36 | 37 | drawables:init( ); 38 | cubeCache:init( ); 39 | 40 | x = theX; 41 | y = theY; 42 | z = theZ; 43 | 44 | size = theSize; 45 | width = 0; 46 | 47 | } 48 | 49 | 50 | // destructor 51 | 52 | void destruct( ) 53 | { 54 | 55 | // printf( "\nGLVoxelLabel destruct" ); 56 | 57 | // release cubes in drawables 58 | 59 | struct CLLink* link = drawables.head; 60 | 61 | while ( link != NULL ) 62 | { 63 | 64 | GLDrawable* oneDrawable = link->data; 65 | oneDrawable.release( ); 66 | link = link->next; 67 | 68 | } 69 | 70 | drawables.release( ); 71 | 72 | // release cubes in cache 73 | 74 | link = cubeCache.head; 75 | 76 | while ( link != NULL ) 77 | { 78 | 79 | GLCubePC33* oneCube = link->data; 80 | oneCube.release( ); 81 | link = link->next; 82 | 83 | } 84 | 85 | cubeCache.release( ); 86 | 87 | CLObject:destruct( self ); 88 | 89 | } 90 | 91 | 92 | // sets text 93 | 94 | void setText( char* theText ) 95 | { 96 | 97 | // putting back cubes in cubeCache 98 | 99 | struct CLLink* link = drawables.head; 100 | 101 | while ( link != NULL ) 102 | { 103 | GLCubePC33* oneCube = ( GLCubePC33* ) link->data; 104 | cubeCache:addData( oneCube ); 105 | link = link->next; 106 | } 107 | 108 | drawables:removeAllDatas( ); 109 | 110 | width = 0; 111 | 112 | // building up new label 113 | 114 | while ( *theText != '\0' ) 115 | { 116 | 117 | TLPixelFont* font = TLPixelFont:alloc( ); 118 | 119 | font:initWithCharacter( *theText ); 120 | 121 | float* data = font.data; 122 | 123 | for ( int index = 0 ; 124 | index < font.length ; 125 | index += 2 ) 126 | { 127 | 128 | float nx = x + width + data[ index ] * size; 129 | float ny = y + 6 * size - data[ index + 1 ] * size; 130 | 131 | GLCubePC33* oneCube = cubeCache:removeDataAtIndex( 0 ); 132 | 133 | // create new cube if needed 134 | 135 | if ( oneCube == NULL ) 136 | { 137 | oneCube = GLCubePC33:alloc( ); 138 | oneCube:init( ); 139 | oneCube:scale( size , size , size ); 140 | } 141 | 142 | oneCube:origo( nx , ny , z ); 143 | 144 | drawables:addData( ( GLDrawable* ) oneCube ); 145 | 146 | } 147 | 148 | width = width + font.width * size; 149 | 150 | font.release( ); 151 | 152 | theText += 1; 153 | 154 | } 155 | 156 | } 157 | 158 | 159 | // moves label 160 | 161 | void move( float theX , float theY , float theZ ) 162 | { 163 | 164 | struct CLLink* link = drawables.head; 165 | 166 | while ( link != NULL ) 167 | { 168 | 169 | GLCubePC33* oneCube = ( GLCubePC33* ) link->data; 170 | oneCube:move( theX , theY , theZ ); 171 | link = link->next; 172 | 173 | } 174 | 175 | } 176 | 177 | } -------------------------------------------------------------------------------- /example project/Sources/GraphicsLib/Primitives/GLCubePC33.clc: -------------------------------------------------------------------------------- 1 | #import "GLDrawablePC33.clc" 2 | 3 | 4 | GLCubePC33:GLDrawablePC33 5 | { 6 | 7 | 8 | // constructor 9 | 10 | void init( ) 11 | { 12 | 13 | // printf( "\nGLCubePC33 init %lli" , id ); 14 | 15 | GLDrawablePC33:init( self ); 16 | 17 | // setup 18 | 19 | mode = GL_TRIANGLES; 20 | texture = 0; 21 | 22 | indexCount = 36; 23 | vertexCount = 24; 24 | 25 | vertexesSize = sizeof( GLfloat ) * 6 * vertexCount; 26 | indexesSize = sizeof( GLushort ) * indexCount; 27 | 28 | vertexes = malloc( vertexesSize ); 29 | indexes = malloc( indexesSize ); 30 | 31 | const GLfloat constva[] = 32 | { 33 | 34 | 35 | //X Y Z NX NY NZ R G B A 36 | 37 | // 2 1 2 front face 38 | // y 39 | // x 1 3 3 40 | 41 | // 2 1 2 back face 42 | // y 43 | // x 1 3 3 44 | 45 | // 2 1 2 top face 46 | // z 47 | // x 1 3 3 48 | 49 | // 2 1 2 bottom face 50 | // z 51 | // x 1 3 3 52 | 53 | // 2 1 2 left face 54 | // y 55 | // z 1 3 3 56 | 57 | // 2 1 2 right face 58 | // y 59 | // z 1 3 3 60 | 61 | 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 62 | 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 63 | 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 64 | 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 65 | 66 | 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 67 | 0.0f, 1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 68 | 1.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 69 | 1.0f, 1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 70 | 71 | 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 72 | 0.0f, 1.0f,-1.0f, 0.0f, 0.0f, 0.0f, 73 | 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 74 | 1.0f, 1.0f,-1.0f, 0.0f, 0.0f, 0.0f, 75 | 76 | 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 77 | 0.0f, 0.0f,-1.0f, 0.0f, 0.0f, 0.0f, 78 | 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 79 | 1.0f, 0.0f,-1.0f, 0.0f, 0.0f, 0.0f, 80 | 81 | 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 82 | 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 83 | 0.0f, 0.0f,-1.0f, 0.0f, 0.0f, 0.0f, 84 | 0.0f, 1.0f,-1.0f, 0.0f, 0.0f, 0.0f, 85 | 86 | 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 87 | 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 88 | 1.0f, 0.0f,-1.0f, 0.0f, 0.0f, 0.0f, 89 | 1.0f, 1.0f,-1.0f, 0.0f, 0.0f, 0.0f 90 | 91 | }; 92 | 93 | // index array 94 | 95 | const GLushort constia[] = 96 | { 97 | 98 | 0 , 2 , 1 , 1 , 2 , 3 , 99 | 4 , 5 , 6 , 5 , 7 , 6 , 100 | 8 , 10 , 9 , 9 , 10 , 11 , 101 | 12 , 13 , 14 , 13 , 15 , 14 , 102 | 16 , 17 , 18 , 17 , 19 , 18 , 103 | 20 , 22 , 21 , 21 , 22 , 23 104 | 105 | }; 106 | 107 | memcpy( vertexes , constva , vertexesSize ); 108 | memcpy( indexes , constia , indexesSize ); 109 | 110 | } 111 | 112 | 113 | // destructor 114 | 115 | void destruct( ) 116 | { 117 | 118 | // printf( "\nGLCubePC33 destruct %lli" , id ); 119 | 120 | GLDrawablePC33:destruct( self ); 121 | 122 | } 123 | 124 | } -------------------------------------------------------------------------------- /example project/Sources/GraphicsLib/Primitives/GLCubePNC334.clc: -------------------------------------------------------------------------------- 1 | #import "GLDrawablePNC334.clc" 2 | 3 | 4 | GLCubePNC334:GLDrawablePNC334 5 | { 6 | 7 | // constructor 8 | 9 | void init( ) 10 | { 11 | 12 | GLDrawablePNC334:init( self ); 13 | 14 | // setup 15 | 16 | mode = GL_TRIANGLES; 17 | texture = 0; 18 | 19 | indexCount = 36; 20 | vertexCount = 24; 21 | 22 | vertexesSize = sizeof( GLfloat ) * 10 * vertexCount; 23 | indexesSize = sizeof( GLushort ) * indexCount; 24 | 25 | vertexes = malloc( vertexesSize ); 26 | indexes = malloc( indexesSize ); 27 | 28 | const GLfloat constva[] = 29 | { 30 | 31 | 32 | //X Y Z NX NY NZ R G B A 33 | 34 | // 2 1 2 front face 35 | // y 36 | // x 1 3 3 37 | 38 | // 2 1 2 back face 39 | // y 40 | // x 1 3 3 41 | 42 | // 2 1 2 top face 43 | // z 44 | // x 1 3 3 45 | 46 | // 2 1 2 bottom face 47 | // z 48 | // x 1 3 3 49 | 50 | // 2 1 2 left face 51 | // y 52 | // z 1 3 3 53 | 54 | // 2 1 2 right face 55 | // y 56 | // z 1 3 3 57 | 58 | 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 59 | 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 60 | 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 61 | 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 62 | 63 | 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 64 | 0.0f, 1.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 65 | 1.0f, 0.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 66 | 1.0f, 1.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 67 | 68 | 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 69 | 0.0f, 1.0f,-1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 70 | 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 71 | 1.0f, 1.0f,-1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 72 | 73 | 0.0f, 0.0f, 0.0f, 0.0f,-1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 74 | 0.0f, 0.0f,-1.0f, 0.0f,-1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 75 | 1.0f, 0.0f, 0.0f, 0.0f,-1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 76 | 1.0f, 0.0f,-1.0f, 0.0f,-1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 77 | 78 | 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 79 | 0.0f, 1.0f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 80 | 0.0f, 0.0f,-1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 81 | 0.0f, 1.0f,-1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 82 | 83 | 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 84 | 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 85 | 1.0f, 0.0f,-1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 86 | 1.0f, 1.0f,-1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f 87 | 88 | }; 89 | 90 | // index array 91 | 92 | const GLushort constia[] = 93 | { 94 | 95 | 0 , 2 , 1 , 1 , 2 , 3 , 96 | 4 , 5 , 6 , 5 , 7 , 6 , 97 | 8 , 10 , 9 , 9 , 10 , 11 , 98 | 12 , 13 , 14 , 13 , 15 , 14 , 99 | 16 , 17 , 18 , 17 , 19 , 18 , 100 | 20 , 22 , 21 , 21 , 22 , 23 101 | 102 | }; 103 | 104 | memcpy( vertexes , constva , vertexesSize ); 105 | memcpy( indexes , constia , indexesSize ); 106 | 107 | 108 | } 109 | 110 | 111 | // destructor 112 | 113 | void destruct( ) 114 | { 115 | 116 | GLDrawablePNC334:destruct( self ); 117 | 118 | } 119 | 120 | } -------------------------------------------------------------------------------- /example project/Sources/GraphicsLib/Primitives/GLDrawablePC33.clc: -------------------------------------------------------------------------------- 1 | #include "GLDrawable.clc" 2 | 3 | 4 | GLDrawablePC33:GLDrawable 5 | { 6 | 7 | 8 | // position and scale values 9 | 10 | float dx; 11 | float dy; 12 | float dz; 13 | 14 | float sx; 15 | float sy; 16 | float sz; 17 | 18 | 19 | // constructor 20 | 21 | void init( ) 22 | { 23 | 24 | GLDrawable:init( self ); 25 | 26 | dx = 0; 27 | dy = 0; 28 | dz = 0; 29 | 30 | sx = 1; 31 | sy = 1; 32 | sz = 1; 33 | 34 | } 35 | 36 | 37 | // destructor 38 | 39 | void destruct( ) 40 | { 41 | 42 | GLDrawable:destruct( self ); 43 | 44 | } 45 | 46 | 47 | // moves drawable 48 | 49 | void move( float theX , float theY , float theZ ) 50 | { 51 | 52 | dx += theX; 53 | dy += theY; 54 | dz += theZ; 55 | 56 | for ( int index = 0 ; 57 | index < vertexCount * 6 ; 58 | index += 6 ) 59 | { 60 | 61 | vertexes[ index ] += theX; 62 | vertexes[ index + 1 ] += theY; 63 | vertexes[ index + 2 ] += theZ; 64 | 65 | } 66 | 67 | } 68 | 69 | 70 | // sets origon of drawable 71 | 72 | void origo( float theX , float theY , float theZ ) 73 | { 74 | 75 | for ( int index = 0 ; 76 | index < vertexCount * 6 ; 77 | index += 6 ) 78 | { 79 | 80 | vertexes[ index ] += -dx + theX; 81 | vertexes[ index + 1 ] += -dy + theY; 82 | vertexes[ index + 2 ] += -dz + theZ; 83 | 84 | } 85 | 86 | dx = theX; 87 | dy = theY; 88 | dz = theZ; 89 | 90 | } 91 | 92 | 93 | // scales drawable 94 | 95 | void scale( float theX , float theY , float theZ ) 96 | { 97 | 98 | sx *= theX; 99 | sy *= theY; 100 | sz *= theZ; 101 | 102 | for ( int index = 0 ; 103 | index < vertexCount * 6 ; 104 | index += 6 ) 105 | { 106 | 107 | vertexes[ index ] *= theX; 108 | vertexes[ index + 1 ] *= theY; 109 | vertexes[ index + 2 ] *= theZ; 110 | 111 | } 112 | 113 | } 114 | 115 | 116 | // sets color of drawable 117 | 118 | void color( float theX , float theY , float theZ ) 119 | { 120 | 121 | for ( int index = 0 ; 122 | index < vertexCount * 6 ; 123 | index += 6 ) 124 | { 125 | 126 | vertexes[ index + 3 ] = theX; 127 | vertexes[ index + 4 ] = theY; 128 | vertexes[ index + 5 ] = theZ; 129 | 130 | } 131 | 132 | } 133 | 134 | } -------------------------------------------------------------------------------- /example project/Sources/GraphicsLib/Primitives/GLDrawablePNC334.clc: -------------------------------------------------------------------------------- 1 | #include "GLDrawable.clc" 2 | 3 | 4 | GLDrawablePNC334:GLDrawable 5 | { 6 | 7 | 8 | // position and scale values 9 | 10 | float dx; 11 | float dy; 12 | float dz; 13 | 14 | float sx; 15 | float sy; 16 | float sz; 17 | 18 | 19 | // constructor 20 | 21 | void init( ) 22 | { 23 | 24 | GLDrawable:init( self ); 25 | 26 | dx = 0; 27 | dy = 0; 28 | dz = 0; 29 | 30 | sx = 1; 31 | sy = 1; 32 | sz = 1; 33 | 34 | } 35 | 36 | 37 | // destructor 38 | 39 | void destruct( ) 40 | { 41 | 42 | GLDrawable:destruct( self ); 43 | 44 | } 45 | 46 | 47 | // moves drawable 48 | 49 | void move( float theX , float theY , float theZ ) 50 | { 51 | 52 | dx += theX; 53 | dy += theY; 54 | dz += theZ; 55 | 56 | for ( int index = 0 ; 57 | index < vertexCount * 10 ; 58 | index += 10 ) 59 | { 60 | 61 | vertexes[ index ] += theX; 62 | vertexes[ index + 1 ] += theY; 63 | vertexes[ index + 2 ] += theZ; 64 | 65 | } 66 | 67 | } 68 | 69 | 70 | // sets origon of drawable 71 | 72 | void origo( float theX , float theY , float theZ ) 73 | { 74 | 75 | for ( int index = 0 ; 76 | index < vertexCount * 10 ; 77 | index += 10 ) 78 | { 79 | 80 | vertexes[ index ] += -dx + theX; 81 | vertexes[ index + 1 ] += -dy + theY; 82 | vertexes[ index + 2 ] += -dz + theZ; 83 | 84 | } 85 | 86 | dx = theX; 87 | dy = theY; 88 | dz = theZ; 89 | 90 | } 91 | 92 | 93 | // scales drawable 94 | 95 | void scale( float theX , float theY , float theZ ) 96 | { 97 | 98 | sx *= theX; 99 | sy *= theY; 100 | sz *= theZ; 101 | 102 | for ( int index = 0 ; 103 | index < vertexCount * 10 ; 104 | index += 10 ) 105 | { 106 | 107 | vertexes[ index ] *= theX; 108 | vertexes[ index + 1 ] *= theY; 109 | vertexes[ index + 2 ] *= theZ; 110 | 111 | } 112 | 113 | } 114 | 115 | 116 | // sets color of drawable 117 | 118 | void color( float theX , float theY , float theZ , float theA ) 119 | { 120 | 121 | for ( int index = 0 ; 122 | index < vertexCount * 10 ; 123 | index += 10 ) 124 | { 125 | 126 | vertexes[ index + 6 ] = theX; 127 | vertexes[ index + 7 ] = theY; 128 | vertexes[ index + 8 ] = theZ; 129 | vertexes[ index + 9 ] = theA; 130 | 131 | } 132 | 133 | } 134 | 135 | 136 | // sets alpha of drawable 137 | 138 | void alpha( float theAlpha ) 139 | { 140 | 141 | for ( int index = 0 ; 142 | index < vertexCount * 10 ; 143 | index += 10 ) 144 | { 145 | 146 | vertexes[ index + 9 ] = theAlpha; 147 | 148 | } 149 | 150 | } 151 | 152 | } -------------------------------------------------------------------------------- /example project/Sources/GraphicsLib/Primitives/GLDrawablePT22.clc: -------------------------------------------------------------------------------- 1 | #include "GLDrawable.clc" 2 | 3 | 4 | GLDrawablePT22:GLDrawable 5 | { 6 | 7 | 8 | // position and scale values 9 | 10 | float dx; 11 | float dy; 12 | 13 | float sx; 14 | float sy; 15 | 16 | 17 | // constructor 18 | 19 | void init( ) 20 | { 21 | 22 | GLDrawable:init( self ); 23 | 24 | dx = 0; 25 | dy = 0; 26 | 27 | sx = 1; 28 | sy = 1; 29 | 30 | } 31 | 32 | 33 | // destructor 34 | 35 | void destruct( ) 36 | { 37 | 38 | GLDrawable:destruct( self ); 39 | 40 | } 41 | 42 | 43 | // sets origon of drawable 44 | 45 | void origo( float theX , float theY ) 46 | { 47 | 48 | for ( int index = 0 ; 49 | index < vertexCount * 4 ; 50 | index += 4 ) 51 | { 52 | 53 | vertexes[ index ] += -dx + theX; 54 | vertexes[ index + 1 ] += -dy + theY; 55 | 56 | } 57 | 58 | dx = theX; 59 | dy = theY; 60 | 61 | } 62 | 63 | 64 | // moves drawable 65 | 66 | void move( float theX , float theY ) 67 | { 68 | 69 | dx += theX; 70 | dy += theY; 71 | 72 | for ( int index = 0 ; 73 | index < vertexCount * 4 ; 74 | index += 4 ) 75 | { 76 | 77 | vertexes[ index ] += theX; 78 | vertexes[ index + 1 ] += theY; 79 | 80 | } 81 | 82 | } 83 | 84 | 85 | // scales drawable 86 | 87 | void scale( float theX , float theY ) 88 | { 89 | 90 | sx *= theX; 91 | sy *= theY; 92 | 93 | for ( int index = 0 ; 94 | index < vertexCount * 4 ; 95 | index += 4 ) 96 | { 97 | 98 | vertexes[ index ] *= theX; 99 | vertexes[ index + 1 ] *= theY; 100 | 101 | } 102 | 103 | } 104 | 105 | } -------------------------------------------------------------------------------- /example project/Sources/GraphicsLib/Primitives/GLGridPT22.clc: -------------------------------------------------------------------------------- 1 | #include "GLDrawablePT22.clc" 2 | 3 | 4 | GLGridPT22:GLDrawablePT22 5 | { 6 | 7 | unsigned int meshFactor; 8 | unsigned int touchRadius; 9 | 10 | unsigned int poolWidth; 11 | unsigned int poolHeight; 12 | unsigned int screenWidth; 13 | unsigned int screenHeight; 14 | 15 | float textureScaleY; 16 | float texCoordOffsetS; 17 | float textureScaleX; 18 | float texCoordOffsetT; 19 | 20 | float* rippleCoeff; 21 | float* rippleSource; 22 | float* rippleDest; 23 | 24 | float textStepX; 25 | float texStepY; 26 | 27 | 28 | // constructor 29 | 30 | void init( float theWidth , 31 | float theHeight , 32 | GLuint theTexture ) 33 | { 34 | 35 | // printf( "\nGLGridPT22 init" ); 36 | 37 | GLDrawablePT22:init( self ); 38 | 39 | texture = theTexture; 40 | 41 | screenWidth = theWidth; 42 | screenHeight = theHeight; 43 | 44 | meshFactor = 10; 45 | touchRadius = 5; 46 | 47 | poolWidth = 40; 48 | poolHeight = 40; 49 | 50 | mode = GL_TRIANGLE_STRIP; 51 | 52 | indexCount = ( poolHeight - 1 ) * ( poolWidth * 2 + 2 ); 53 | vertexCount = poolWidth * poolHeight; 54 | 55 | indexesSize = sizeof( GLushort ) * indexCount; 56 | vertexesSize = sizeof( GLfloat ) * 4 * vertexCount; 57 | 58 | indexes = malloc( indexesSize ); 59 | vertexes = malloc( vertexesSize ); 60 | 61 | textureScaleX = 1.0; 62 | textureScaleY = 1.0; 63 | 64 | texCoordOffsetT = 0.0; 65 | texCoordOffsetS = 0.0; 66 | 67 | rippleCoeff = ( float* ) malloc( ( touchRadius * 2 + 1 ) * ( touchRadius * 2 + 1 ) * sizeof( float ) ); 68 | rippleSource = ( float* ) malloc( ( poolWidth + 2 ) * ( poolHeight + 2 ) * sizeof( float ) ); 69 | rippleDest = ( float* ) malloc( ( poolWidth + 2 ) * ( poolHeight + 2 ) * sizeof( float ) ); 70 | 71 | memset( rippleSource , 0 , ( poolWidth + 2 ) * ( poolHeight + 2 ) * sizeof( float ) ); 72 | memset( rippleDest , 0 , ( poolWidth + 2 ) * ( poolHeight + 2 ) * sizeof( float ) ); 73 | 74 | initCoefficients( ); 75 | initMesh( ); 76 | 77 | } 78 | 79 | 80 | // destructor 81 | 82 | void destruct( ) 83 | { 84 | 85 | printf( "\nGLGridPT22 destruct" ); 86 | 87 | free(rippleCoeff); 88 | free(rippleSource); 89 | free(rippleDest); 90 | 91 | GLDrawablePT22:destruct( self ); 92 | 93 | } 94 | 95 | 96 | // initialize coefficients 97 | 98 | void initCoefficients( ) 99 | { 100 | 101 | for ( int y = 0 ; y <= 2 * touchRadius ; y++ ) 102 | { 103 | 104 | for ( int x = 0 ; x <= 2 * touchRadius ; x++ ) 105 | { 106 | 107 | float distance = sqrt( ( x - touchRadius ) * ( x - touchRadius ) + ( y - touchRadius ) * ( y - touchRadius ) ); 108 | 109 | if ( distance <= touchRadius ) 110 | { 111 | float factor = ( distance / touchRadius ); 112 | 113 | // goes from -512 -> 0 114 | rippleCoeff[ y * ( touchRadius * 2 + 1 ) + x ] = -( cos( factor * M_PI ) + 1.f ) * 256.f; 115 | } 116 | else 117 | { 118 | rippleCoeff[ y * ( touchRadius * 2 + 1 ) + x ] = 0.f; 119 | } 120 | 121 | } 122 | 123 | } 124 | 125 | } 126 | 127 | 128 | // init mesh 129 | 130 | void initMesh( ) 131 | { 132 | 133 | for ( int i = 0 ; i < poolHeight ; i++ ) 134 | { 135 | 136 | for ( int j = 0 ; j < poolWidth ; j++ ) 137 | { 138 | 139 | vertexes[ ( i * poolWidth + j ) * 4 + 0 ] = j * ( screenWidth / ( (float)poolWidth - 1 ) ); 140 | vertexes[ ( i * poolWidth + j ) * 4 + 1 ] = i * ( screenHeight / ( (float)poolHeight - 1 ) ); 141 | 142 | vertexes[ ( i * poolWidth + j ) * 4 + 2 ] = ( float ) j / ( poolWidth - 1 ) * textureScaleX + texCoordOffsetT; 143 | vertexes[ ( i * poolWidth + j ) * 4 + 3 ] = ( float ) i / ( poolHeight - 1 ) * textureScaleY + texCoordOffsetS; 144 | 145 | } 146 | 147 | } 148 | 149 | unsigned int index = 0; 150 | 151 | for ( int i = 0 ; i < poolHeight - 1 ; i++ ) 152 | { 153 | 154 | for ( int j = 0 ; j < poolWidth ; j++ ) 155 | { 156 | 157 | // emit extra index to create degenerate triangle 158 | if ( j == 0 ) 159 | { 160 | indexes[ index ] = i * poolWidth + j; 161 | index++; 162 | } 163 | 164 | indexes[ index ] = i * poolWidth + j; 165 | index++; 166 | indexes[ index ] = ( i + 1 ) * poolWidth + j; 167 | index++; 168 | 169 | // emit extra index to create degenerate triangle 170 | if ( j == ( poolWidth - 1 ) ) 171 | { 172 | indexes[ index ] = ( i + 1 ) * poolWidth + j; 173 | index++; 174 | } 175 | 176 | } 177 | 178 | } 179 | 180 | } 181 | 182 | 183 | // run ripple simulation 184 | 185 | void runSimulation( ) 186 | { 187 | 188 | // first pass for simulation buffers... 189 | 190 | for ( int y = 0 ; y < poolHeight ; y++ ) 191 | { 192 | 193 | for ( int x = 0 ; x < poolWidth ; x++ ) 194 | { 195 | // * - denotes current pixel 196 | // 197 | // a 198 | // c * d 199 | // b 200 | 201 | // +1 to both x/y values because the border is padded 202 | float a = rippleSource[ ( y ) * ( poolWidth + 2 ) + x + 1 ]; 203 | float b = rippleSource[ ( y + 2 ) * ( poolWidth + 2 ) + x + 1 ]; 204 | float c = rippleSource[ ( y + 1 ) * ( poolWidth + 2 ) + x ]; 205 | float d = rippleSource[ ( y + 1 ) * ( poolWidth + 2 ) + x + 2 ]; 206 | 207 | float result = ( a + b + c + d ) / 2.f - rippleDest[ ( y + 1 ) * ( poolWidth + 2 ) + x + 1 ]; 208 | 209 | // slow down wave 210 | 211 | result -= result / 8.f; 212 | 213 | rippleDest[ ( y + 1 ) * ( poolWidth + 2 ) + x + 1 ] = result; 214 | 215 | } 216 | 217 | } 218 | 219 | // second pass for modifying texture coord 220 | for ( int y = 0 ; y < poolHeight ; y++ ) 221 | { 222 | 223 | for ( int x = 0 ; x < poolWidth ; x++ ) 224 | { 225 | // * - denotes current pixel 226 | // 227 | // a 228 | // c * d 229 | // b 230 | 231 | // +1 to both x/y values because the border is padded 232 | float a = rippleDest[ ( y ) * ( poolWidth + 2 ) + x + 1 ]; 233 | float b = rippleDest[ ( y + 2 ) * ( poolWidth + 2 ) + x + 1 ]; 234 | float c = rippleDest[ ( y + 1 ) * ( poolWidth + 2 ) + x ]; 235 | float d = rippleDest[ ( y + 1 ) * ( poolWidth + 2 ) + x + 2 ]; 236 | 237 | float s_offset = ( ( b - a ) / 2048.f ); 238 | float t_offset = ( ( c - d ) / 2048.f ); 239 | 240 | // clamp 241 | if ( s_offset < -0.5f ) s_offset = -0.5f; 242 | if ( t_offset < -0.5f ) t_offset = -0.5f; 243 | if ( s_offset > 0.5f ) s_offset = 0.5f; 244 | if ( t_offset > 0.5f ) t_offset = 0.5f; 245 | 246 | float t_tc = ( float ) x / ( poolWidth - 1 ) * textureScaleX + texCoordOffsetT; 247 | float s_tc = ( float ) y / ( poolHeight - 1 ) * textureScaleY + texCoordOffsetS; 248 | 249 | vertexes[ ( y * poolWidth + x ) * 4 + 2 ] = t_tc + t_offset; 250 | vertexes[ ( y * poolWidth + x ) * 4 + 3 ] = s_tc + s_offset; 251 | 252 | } 253 | 254 | } 255 | 256 | float *pTmp = rippleDest; 257 | rippleDest = rippleSource; 258 | rippleSource = pTmp; 259 | 260 | } 261 | 262 | 263 | void reset( ) 264 | { 265 | 266 | memset( rippleSource , 0 , ( poolWidth + 2 ) * ( poolHeight + 2 ) * sizeof( float ) ); 267 | memset( rippleDest , 0 , ( poolWidth + 2 ) * ( poolHeight + 2 ) * sizeof( float ) ); 268 | 269 | } 270 | 271 | 272 | // start ripple 273 | 274 | void ripple( float theX , float theY ) 275 | { 276 | 277 | unsigned int xIndex = ( unsigned int ) ( ( theX / screenWidth ) * poolWidth ); 278 | unsigned int yIndex = ( unsigned int ) ( ( theY / screenHeight ) * poolHeight ); 279 | 280 | for ( int y = ( int ) yIndex - ( int ) touchRadius ; y <= ( int ) yIndex + ( int ) touchRadius ; y++ ) 281 | { 282 | 283 | for (int x=(int)xIndex-(int)touchRadius; x<=(int)xIndex+(int)touchRadius; x++) 284 | { 285 | 286 | if ( x >= 0 && x < poolWidth && 287 | y >= 0 && y < poolHeight ) 288 | { 289 | 290 | // +1 to both x/y values because the border is padded 291 | rippleSource[ ( poolWidth + 2 ) * ( y + 1 ) + x + 1 ] += rippleCoeff[ ( y - ( yIndex - touchRadius ) ) * ( touchRadius * 2 + 1) + x - ( xIndex - touchRadius ) ]; 292 | 293 | } 294 | 295 | } 296 | 297 | } 298 | 299 | } 300 | 301 | 302 | // start zigzag 303 | 304 | void zigzag( ) 305 | { 306 | printf( "" ); 307 | } 308 | 309 | } -------------------------------------------------------------------------------- /example project/Sources/GraphicsLib/Primitives/GLHalfCubePC33.clc: -------------------------------------------------------------------------------- 1 | #import "GLDrawablePC33.clc" 2 | 3 | 4 | GLHalfCubePC33:GLDrawablePC33 5 | { 6 | 7 | // constructor 8 | 9 | 10 | char isLeftSided; 11 | char isRightSided; 12 | 13 | 14 | void init( ) 15 | { 16 | 17 | // printf( "\nGLHalfCubePC33 init" ); 18 | // printf( "\naddress %lx components %lx components0 %lx" , ( long ) self , ( long ) self->_components , ( long ) self->_components[0] ); 19 | 20 | GLDrawablePC33:init( self ); 21 | 22 | texture = 0; 23 | mode = GL_TRIANGLES; 24 | 25 | isLeftSided = 1; 26 | isRightSided = 0; 27 | 28 | indexCount = 18; 29 | vertexCount = 12; 30 | 31 | vertexesSize = sizeof( GLfloat ) * 6 * vertexCount; 32 | indexesSize = sizeof( GLushort ) * indexCount; 33 | 34 | vertexes = malloc( vertexesSize ); 35 | indexes = malloc( indexesSize ); 36 | 37 | const GLfloat constva[] = 38 | { 39 | 40 | 41 | //X Y Z NX NY NZ R G B A 42 | 43 | // 2 1 2 front face 44 | // y 45 | // x 1 3 3 46 | 47 | // 2 1 2 bottom face 48 | // z 49 | // x 1 3 3 50 | 51 | // 2 1 2 left face 52 | // y 53 | // z 1 3 3 54 | 55 | 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 56 | 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 57 | 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 58 | 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 59 | 60 | 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 61 | 0.0f, 0.0f,-1.0f, 1.0f, 1.0f, 1.0f, 62 | 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 63 | 1.0f, 0.0f,-1.0f, 1.0f, 1.0f, 1.0f, 64 | 65 | 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 66 | 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 67 | 0.0f, 0.0f,-1.0f, 1.0f, 1.0f, 1.0f, 68 | 0.0f, 1.0f,-1.0f, 1.0f, 1.0f, 1.0f 69 | 70 | }; 71 | 72 | // index array 73 | 74 | const GLushort constia[] = 75 | { 76 | 77 | 0 , 2 , 1 , 1 , 2 , 3 , 78 | 4 , 5 , 6 , 5 , 7 , 6 , 79 | 8 , 9 , 10 , 9 , 11 , 10 80 | 81 | }; 82 | 83 | memcpy( vertexes , constva , vertexesSize ); 84 | memcpy( indexes , constia , indexesSize ); 85 | 86 | } 87 | 88 | 89 | // destructor 90 | 91 | void destruct( ) 92 | { 93 | 94 | // printf( "\nGLHalfCubePC33 destruct" ); 95 | 96 | GLDrawablePC33:destruct( self ); 97 | 98 | } 99 | 100 | 101 | // shows only left faces 102 | 103 | void setLeftSided( ) 104 | { 105 | 106 | isLeftSided = 1; 107 | isRightSided = 0; 108 | 109 | vertexes[ 48 ] -= sx; 110 | vertexes[ 54 ] -= sx; 111 | vertexes[ 60 ] -= sx; 112 | vertexes[ 66 ] -= sx; 113 | 114 | // index array 115 | 116 | const GLushort constia[] = 117 | { 118 | 119 | 0 , 2 , 1 , 1 , 2 , 3 , 120 | 4 , 5 , 6 , 5 , 7 , 6 , 121 | 8 , 9 , 10 , 9 , 11 , 10 122 | 123 | }; 124 | 125 | memcpy( indexes , constia , indexesSize ); 126 | 127 | } 128 | 129 | 130 | // shows only right faces 131 | 132 | void setRightSided( ) 133 | { 134 | 135 | isLeftSided = 0; 136 | isRightSided = 1; 137 | 138 | vertexes[ 48 ] += sx; 139 | vertexes[ 54 ] += sx; 140 | vertexes[ 60 ] += sx; 141 | vertexes[ 66 ] += sx; 142 | 143 | // index array 144 | 145 | const GLushort constia[] = 146 | { 147 | 148 | 0 , 2 , 1 , 1 , 2 , 3 , 149 | 4 , 5 , 6 , 5 , 7 , 6 , 150 | 8 , 10 , 9 , 9 , 10 , 11 151 | 152 | }; 153 | 154 | memcpy( indexes , constia , indexesSize ); 155 | 156 | } 157 | 158 | } -------------------------------------------------------------------------------- /example project/Sources/GraphicsLib/Primitives/GLHalfCubePNC334.clc: -------------------------------------------------------------------------------- 1 | #import "GLDrawablePNC334.clc" 2 | 3 | 4 | GLHalfCubePNC334:GLDrawablePNC334 5 | { 6 | 7 | // constructor 8 | 9 | 10 | char isLeftSided; 11 | char isRightSided; 12 | 13 | 14 | void init( ) 15 | { 16 | 17 | GLDrawablePNC334:init( self ); 18 | 19 | texture = 0; 20 | mode = GL_TRIANGLES; 21 | 22 | isLeftSided = 1; 23 | isRightSided = 0; 24 | 25 | indexCount = 18; 26 | vertexCount = 12; 27 | 28 | vertexesSize = sizeof( GLfloat ) * 10 * vertexCount; 29 | indexesSize = sizeof( GLushort ) * indexCount; 30 | 31 | vertexes = malloc( vertexesSize ); 32 | indexes = malloc( indexesSize ); 33 | 34 | const GLfloat constva[] = 35 | { 36 | 37 | 38 | //X Y Z NX NY NZ R G B A 39 | 40 | // 2 1 2 front face 41 | // y 42 | // x 1 3 3 43 | 44 | // 2 1 2 bottom face 45 | // z 46 | // x 1 3 3 47 | 48 | // 2 1 2 left face 49 | // y 50 | // z 1 3 3 51 | 52 | 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 53 | 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 54 | 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 55 | 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 56 | 57 | 0.0f, 0.0f, 0.0f, 0.0f,-1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 58 | 0.0f, 0.0f,-1.0f, 0.0f,-1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 59 | 1.0f, 0.0f, 0.0f, 0.0f,-1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 60 | 1.0f, 0.0f,-1.0f, 0.0f,-1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 61 | 62 | 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 63 | 0.0f, 1.0f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 64 | 0.0f, 0.0f,-1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 65 | 0.0f, 1.0f,-1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 66 | 67 | }; 68 | 69 | // index array 70 | 71 | const GLushort constia[] = 72 | { 73 | 74 | 0 , 2 , 1 , 1 , 2 , 3 , 75 | 4 , 5 , 6 , 5 , 7 , 6 , 76 | 8 , 9 , 10 , 9 , 11 , 10 77 | 78 | }; 79 | 80 | memcpy( vertexes , constva , vertexesSize ); 81 | memcpy( indexes , constia , indexesSize ); 82 | 83 | 84 | } 85 | 86 | 87 | // destructor 88 | 89 | void destruct( ) 90 | { 91 | 92 | GLDrawablePNC334:destruct( self ); 93 | 94 | } 95 | 96 | 97 | // shows only left faces 98 | 99 | void setLeftSided( ) 100 | { 101 | 102 | isLeftSided = 1; 103 | isRightSided = 0; 104 | 105 | vertexes[ 80 ] -= sx; 106 | vertexes[ 90 ] -= sx; 107 | vertexes[ 100 ] -= sx; 108 | vertexes[ 110 ] -= sx; 109 | 110 | // index array 111 | 112 | const GLushort constia[] = 113 | { 114 | 115 | 0 , 2 , 1 , 1 , 2 , 3 , 116 | 4 , 5 , 6 , 5 , 7 , 6 , 117 | 8 , 9 , 10 , 9 , 11 , 10 118 | 119 | }; 120 | 121 | memcpy( indexes , constia , indexesSize ); 122 | 123 | } 124 | 125 | 126 | // shows only right faces 127 | 128 | void setRightSided( ) 129 | { 130 | 131 | isLeftSided = 0; 132 | isRightSided = 1; 133 | 134 | vertexes[ 80 ] += sx; 135 | vertexes[ 90 ] += sx; 136 | vertexes[ 100 ] += sx; 137 | vertexes[ 110 ] += sx; 138 | 139 | // index array 140 | 141 | const GLushort constia[] = 142 | { 143 | 144 | 0 , 2 , 1 , 1 , 2 , 3 , 145 | 4 , 5 , 6 , 5 , 7 , 6 , 146 | 8 , 10 , 9 , 9 , 10 , 11 147 | 148 | }; 149 | 150 | memcpy( indexes , constia , indexesSize ); 151 | 152 | } 153 | 154 | } -------------------------------------------------------------------------------- /example project/Sources/GraphicsLib/Primitives/GLPointP2.clc: -------------------------------------------------------------------------------- 1 | #include "GLDrawable.clc" 2 | 3 | 4 | GLPointP2:GLDrawable 5 | { 6 | 7 | void initWithPoints( GLfloat theX , GLfloat theY ) 8 | { 9 | 10 | GLDrawable:init( self ); 11 | 12 | mode = GL_POINTS; 13 | texture = 0; 14 | 15 | // alloc 16 | 17 | indexCount = 1; 18 | vertexCount = 1; 19 | 20 | vertexesSize = sizeof( GLfloat ) * 2 * vertexCount; 21 | indexesSize = sizeof( GLushort ) * indexCount; 22 | 23 | vertexes = malloc( vertexesSize ); 24 | indexes = malloc( indexesSize ); 25 | 26 | vertexes[ 0 ] = theX; 27 | vertexes[ 1 ] = theY; 28 | 29 | // index array 30 | 31 | indexes[ 0 ] = 0; 32 | 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /example project/Sources/GraphicsLib/Primitives/GLRectPT22.clc: -------------------------------------------------------------------------------- 1 | #include "GLDrawablePT22.clc" 2 | 3 | 4 | GLRectPT22:GLDrawablePT22 5 | { 6 | 7 | 8 | // constructor 9 | 10 | void init ( GLuint theTexture ) 11 | { 12 | 13 | // printf( "\nGLRectPT22 init %f %f %u" , theWidth , theHeight , theTexture ); 14 | 15 | GLDrawablePT22:init( self ); 16 | 17 | mode = GL_TRIANGLE_STRIP; 18 | texture = theTexture; 19 | 20 | // alloc 21 | 22 | indexCount = 4; 23 | vertexCount = 4; 24 | 25 | indexesSize = sizeof( GLushort ) * indexCount; 26 | vertexesSize = sizeof( GLfloat ) * 4 * vertexCount; 27 | 28 | indexes = malloc( indexesSize ); 29 | vertexes = malloc( vertexesSize ); 30 | 31 | const GLfloat constva[] = 32 | { 33 | 34 | 0.0 , 0.0 , 0.0 , 0.0 , 35 | 0.0 , 1.0 , 0.0 , 1.0 , 36 | 1.0 , 0.0 , 1.0 , 0.0 , 37 | 1.0 , 1.0 , 1.0 , 1.0 38 | 39 | }; 40 | 41 | const GLushort constia[] = 42 | { 43 | 0 , 2 , 1 , 3 44 | }; 45 | 46 | memcpy( vertexes , constva , vertexesSize ); 47 | memcpy( indexes , constia , indexesSize ); 48 | 49 | } 50 | 51 | 52 | // flips texture coordinates 53 | 54 | void flipTexture( ) 55 | { 56 | 57 | float temp = vertexes[ 3 ]; 58 | 59 | vertexes[ 3 ] = vertexes[ 7 ]; 60 | vertexes[ 7 ] = temp; 61 | 62 | temp = vertexes[ 11 ]; 63 | 64 | vertexes[ 11 ] = vertexes[ 15 ]; 65 | vertexes[ 15 ] = temp; 66 | 67 | } 68 | 69 | 70 | // destructor 71 | 72 | void destruct( ) 73 | { 74 | 75 | GLDrawablePT22:destruct( self ); 76 | 77 | } 78 | 79 | 80 | // check if square contains a 3d point 81 | 82 | char contains( float theX , float theY ) 83 | { 84 | 85 | return ( theX >= dx && theX <= dx + sx && theY >= dy && theY <= dy + sy ); 86 | 87 | } 88 | 89 | } -------------------------------------------------------------------------------- /example project/Sources/GraphicsLib/Primitives/GLSegment.clc: -------------------------------------------------------------------------------- 1 | #include "GLDrawable.clc" 2 | 3 | 4 | GLSegment:GLDrawable 5 | { 6 | 7 | void initWithPoints( GLfloat theAx , GLfloat theAy , GLfloat theBx , GLfloat theBy ) 8 | { 9 | 10 | GLDrawable:init( self ); 11 | 12 | texture = 0; 13 | mode = GL_LINE_STRIP; 14 | 15 | // alloc 16 | 17 | indexCount = 2; 18 | vertexCount = 2; 19 | 20 | vertexesSize = sizeof( GLfloat ) * 2 * vertexCount; 21 | indexesSize = sizeof( GLushort ) * indexCount; 22 | 23 | vertexes = malloc( vertexesSize ); 24 | indexes = malloc( indexesSize ); 25 | 26 | vertexes[ 0 ] = theAx; 27 | vertexes[ 1 ] = theAy; 28 | vertexes[ 2 ] = theBx; 29 | vertexes[ 3 ] = theBy; 30 | 31 | // index array 32 | 33 | indexes[ 0 ] = 0; 34 | indexes[ 1 ] = 1; 35 | 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /example project/Sources/GraphicsLib/Primitives/GLSquarePC33.clc: -------------------------------------------------------------------------------- 1 | #import "GLDrawablePC33.clc" 2 | 3 | 4 | GLSquarePC33:GLDrawablePC33 5 | { 6 | 7 | 8 | // constructor 9 | 10 | void init( ) 11 | { 12 | 13 | GLDrawablePC33:init( self ); 14 | 15 | // setup 16 | 17 | texture = 0; 18 | mode = GL_TRIANGLES; 19 | 20 | indexCount = 6; 21 | vertexCount = 4; 22 | 23 | vertexesSize = sizeof( GLfloat ) * 6 * vertexCount; 24 | indexesSize = sizeof( GLushort ) * indexCount; 25 | 26 | vertexes = malloc( vertexesSize ); 27 | indexes = malloc( indexesSize ); 28 | 29 | GLfloat constva[] = 30 | { 31 | 32 | 33 | //X Y Z NX NY NZ R G B A 34 | 35 | // 2 1 2 front face 36 | // y 37 | // x 1 3 3 38 | 39 | 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 40 | 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 41 | 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 42 | 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f 43 | 44 | }; 45 | 46 | // index array 47 | 48 | GLushort constia[] = 49 | { 50 | 51 | 0 , 2 , 1 , 1 , 2 , 3 52 | 53 | }; 54 | 55 | memcpy( vertexes , constva , vertexesSize ); 56 | memcpy( indexes , constia , indexesSize ); 57 | 58 | } 59 | 60 | 61 | // destructor 62 | 63 | void destruct( ) 64 | { 65 | 66 | GLDrawablePC33:destruct( self ); 67 | 68 | } 69 | 70 | 71 | // check if square contains a 3d point 72 | 73 | char contains( float theX , float theY , float theZ ) 74 | { 75 | 76 | return ( theX >= dx && theX <= dx + sx && theY >= dy && theY <= dy + sy ); 77 | 78 | } 79 | 80 | } -------------------------------------------------------------------------------- /example project/Sources/GraphicsLib/Primitives/GLSquarePNC334.clc: -------------------------------------------------------------------------------- 1 | #import "GLDrawablePNC334.clc" 2 | 3 | 4 | GLSquarePNC334:GLDrawablePNC334 5 | { 6 | 7 | 8 | // constructor 9 | 10 | void init( ) 11 | { 12 | 13 | GLDrawablePNC334:init( self ); 14 | 15 | // setup 16 | 17 | texture = 0; 18 | mode = GL_TRIANGLES; 19 | 20 | indexCount = 6; 21 | vertexCount = 4; 22 | 23 | vertexesSize = sizeof( GLfloat ) * 10 * vertexCount; 24 | indexesSize = sizeof( GLushort ) * indexCount; 25 | 26 | vertexes = malloc( vertexesSize ); 27 | indexes = malloc( indexesSize ); 28 | 29 | GLfloat constva[] = 30 | { 31 | 32 | 33 | //X Y Z NX NY NZ R G B A 34 | 35 | // 2 1 2 front face 36 | // y 37 | // x 1 3 3 38 | 39 | 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 40 | 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 41 | 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 42 | 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 43 | 44 | }; 45 | 46 | // index array 47 | 48 | GLushort constia[] = 49 | { 50 | 51 | 0 , 2 , 1 , 1 , 2 , 3 52 | 53 | }; 54 | 55 | memcpy( vertexes , constva , vertexesSize ); 56 | memcpy( indexes , constia , indexesSize ); 57 | 58 | } 59 | 60 | 61 | // destructor 62 | 63 | void destruct( ) 64 | { 65 | 66 | GLDrawablePNC334:destruct( self ); 67 | 68 | } 69 | 70 | 71 | // check if square contains a 3d point 72 | 73 | char contains( float theX , float theY , float theZ ) 74 | { 75 | 76 | return ( theX >= dx && theX <= dx + sx && theY >= dy && theY <= dy + sy ); 77 | 78 | } 79 | 80 | } -------------------------------------------------------------------------------- /example project/Sources/Macros.h: -------------------------------------------------------------------------------- 1 | // #define OSX 1 2 | // #define IOS 1 3 | // #define TIZ 1 -------------------------------------------------------------------------------- /example project/Sources/MathLib/MLMatrix4.h: -------------------------------------------------------------------------------- 1 | #ifndef MLMatrix4_h 2 | #define MLMatrix4_h 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | #include "MLVector3.h" 9 | #include "MLVector4.h" 10 | 11 | 12 | union _MLMatrix4 13 | { 14 | struct 15 | { 16 | float m00, m01, m02, m03; 17 | float m10, m11, m12, m13; 18 | float m20, m21, m22, m23; 19 | float m30, m31, m32, m33; 20 | }; 21 | float m[16]; 22 | }; 23 | typedef union _MLMatrix4 MLMatrix4; 24 | 25 | 26 | // creates identity matrix 27 | 28 | MLMatrix4 MLMatrix4CreateIdentity( ); 29 | 30 | // creates ortographic projection 31 | 32 | MLMatrix4 MLMatrix4CreateOrtho( 33 | float theLeft , 34 | float theRight , 35 | float theBottom , 36 | float theTop , 37 | float theNear , 38 | float theFar ); 39 | 40 | // creates perspective matrix 41 | 42 | MLMatrix4 MLMatrix4CreatePerspective( 43 | float fovyRadians , 44 | float aspect , 45 | float nearZ , 46 | float farZ ); 47 | 48 | // creates look at 49 | 50 | MLMatrix4 MLMatrix4CreateLookAt( 51 | float eyeX , float eyeY , float eyeZ , 52 | float centerX , float centerY , float centerZ , 53 | float upX , float upY , float upZ ); 54 | 55 | // creates rotation 56 | 57 | MLMatrix4 MLMatrix4CreateRotation( 58 | float theRadians , 59 | float theX , 60 | float theY , 61 | float theZ ); 62 | 63 | // multiplies matrices 64 | 65 | MLMatrix4 MLMatrix4Multiply( 66 | MLMatrix4 theLeft , 67 | MLMatrix4 theRight ); 68 | 69 | // translates matrix 70 | 71 | MLMatrix4 MLMatrix4CreateTranslate( 72 | float theX , 73 | float theY , 74 | float theZ ); 75 | 76 | MLMatrix4 MLMatrix4Translate( 77 | MLMatrix4 theMatrix, 78 | float theX , 79 | float theY , 80 | float theZ ); 81 | 82 | // scales matrix 83 | 84 | MLMatrix4 MLMatrix4Scale( 85 | MLMatrix4 theMatrix , 86 | float theX , 87 | float theY , 88 | float theZ ); 89 | 90 | // rotates matrix 91 | 92 | MLMatrix4 MLMatrix4Rotate( 93 | MLMatrix4 theMatrix , 94 | float theRadians , 95 | float theX , 96 | float theY , 97 | float theZ ); 98 | 99 | void MLMatrix4Describe( MLMatrix4 theMatrix ); 100 | 101 | // multiplies with vector 102 | 103 | MLVector4 MLMatrix4ProjectVector4ToScreen( 104 | MLMatrix4 theMatrix , 105 | MLVector4 theVector , 106 | float theWidth , 107 | float theHeight ); 108 | 109 | MLVector4 MLMatrix4UnProjectVector4FromScreen( 110 | MLMatrix4 theMatrix , 111 | MLVector4 theVector , 112 | float theWidth , 113 | float theHeight ); 114 | 115 | MLVector3 MLMatrix4MultiplyVector3( 116 | MLMatrix4 theMatrix , 117 | MLVector3 theVector ); 118 | 119 | MLVector4 MLMatrix4MultiplyVector4( 120 | MLMatrix4 theMatrix , 121 | MLVector4 theVector ); 122 | 123 | MLVector4 MLMatrix4MultiplyVector4Transposed( 124 | MLMatrix4 theMatrix , 125 | MLVector4 theVector ); 126 | 127 | MLMatrix4 MLMatrix4Invert( MLMatrix4 src , char* success ); 128 | MLMatrix4 MLMatrix4Transpose( MLMatrix4 src ); 129 | 130 | 131 | 132 | #endif 133 | -------------------------------------------------------------------------------- /example project/Sources/MathLib/MLVector3.c: -------------------------------------------------------------------------------- 1 | // 2 | // MLVector43.c 3 | // Cortex 4 | // 5 | // Created by Milan Toth on 9/18/13. 6 | // Copyright (c) 2013 Milan Toth. All rights reserved. 7 | // 8 | 9 | #include "MLVector3.h" 10 | 11 | 12 | MLVector3 MLVector3Make( float theX , 13 | float theY , 14 | float theZ ) 15 | { 16 | 17 | MLVector3 result; 18 | 19 | result.x = theX; 20 | result.y = theY; 21 | result.z = theZ; 22 | 23 | return result; 24 | 25 | } 26 | 27 | 28 | 29 | MLVector3 MLVector3Add( MLVector3 a , MLVector3 b ) 30 | { 31 | 32 | MLVector3 result; 33 | 34 | result.x = a.x + b.x; 35 | result.y = a.y + b.y; 36 | result.z = a.z + b.z; 37 | 38 | return result; 39 | 40 | } 41 | 42 | 43 | MLVector3 MLVector3Sub( MLVector3 a , MLVector3 b ) 44 | { 45 | 46 | MLVector3 result; 47 | 48 | result.x = a.x - b.x; 49 | result.y = a.y - b.y; 50 | result.z = a.z - b.z; 51 | 52 | return result; 53 | 54 | } 55 | 56 | 57 | float MLVector3Dot( MLVector3 a , MLVector3 b ) 58 | { 59 | 60 | return a.x * b.x + a.y * b.y + a.z * b.z; 61 | 62 | } 63 | 64 | 65 | MLVector3 MLVector3Cross( MLVector3 vectorLeft, MLVector3 vectorRight) 66 | { 67 | MLVector3 v = { vectorLeft.v[1] * vectorRight.v[2] - vectorLeft.v[2] * vectorRight.v[1], 68 | vectorLeft.v[2] * vectorRight.v[0] - vectorLeft.v[0] * vectorRight.v[2], 69 | vectorLeft.v[0] * vectorRight.v[1] - vectorLeft.v[1] * vectorRight.v[0] }; 70 | return v; 71 | } 72 | 73 | 74 | MLVector3 MLVector3Scale( MLVector3 a , float f ) 75 | { 76 | 77 | MLVector3 result; 78 | 79 | result.x = a.x * f; 80 | result.y = a.y * f; 81 | result.z = a.z * f; 82 | 83 | return result; 84 | 85 | } 86 | 87 | 88 | MLVector3 MLVector3IntersectWithPlane( 89 | MLVector3 lineV1 , 90 | MLVector3 lineV2 , 91 | MLVector3 planeV , 92 | MLVector3 planeN ) 93 | { 94 | 95 | MLVector3 u = MLVector3Sub( lineV2 , lineV1 ); 96 | MLVector3 w = MLVector3Sub( planeV , lineV1 ); 97 | float div = MLVector3Dot( planeN , w ) / MLVector3Dot( planeN , u ); 98 | MLVector3 scale = MLVector3Scale( u , div ); 99 | MLVector3 result = MLVector3Add( lineV1 , scale ); 100 | 101 | return result; 102 | 103 | } 104 | -------------------------------------------------------------------------------- /example project/Sources/MathLib/MLVector3.h: -------------------------------------------------------------------------------- 1 | // 2 | // MLVector3.h 3 | // Cortex 4 | // 5 | // Created by Milan Toth on 9/18/13. 6 | // Copyright (c) 2013 Milan Toth. All rights reserved. 7 | // 8 | 9 | #ifndef MLVector3_h 10 | #define MLVector3_h 11 | 12 | 13 | #include 14 | #include 15 | 16 | union _MLVector3 17 | { 18 | struct { float x, y, z; }; 19 | float v[3]; 20 | }; 21 | typedef union _MLVector3 MLVector3; 22 | 23 | 24 | MLVector3 MLVector3Make( float theX , 25 | float theY , 26 | float theZ ); 27 | 28 | MLVector3 MLVector3Add( MLVector3 a , MLVector3 b ); 29 | 30 | MLVector3 MLVector3Sub( MLVector3 a , MLVector3 b ); 31 | 32 | float MLVector3Dot( MLVector3 a , MLVector3 b ); 33 | 34 | MLVector3 MLVector3Cross( MLVector3 vectorLeft, MLVector3 vectorRight); 35 | 36 | MLVector3 MLVector3Scale( MLVector3 a , float f ); 37 | 38 | MLVector3 MLVector3IntersectWithPlane( 39 | MLVector3 lineV1 , 40 | MLVector3 lineV2 , 41 | MLVector3 planeV , 42 | MLVector3 planeN ); 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /example project/Sources/MathLib/MLVector4.c: -------------------------------------------------------------------------------- 1 | // 2 | // MLVector4.c 3 | // Cortex 4 | // 5 | // Created by Milan Toth on 9/27/13. 6 | // Copyright (c) 2013 Milan Toth. All rights reserved. 7 | // 8 | 9 | #include "MLVector4.h" 10 | 11 | 12 | MLVector4 MLVector4Make( float theX , 13 | float theY , 14 | float theZ , 15 | float theW ) 16 | { 17 | 18 | MLVector4 result; 19 | 20 | result.x = theX; 21 | result.y = theY; 22 | result.z = theZ; 23 | result.w = theW; 24 | 25 | return result; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /example project/Sources/MathLib/MLVector4.h: -------------------------------------------------------------------------------- 1 | // 2 | // MLVector4.h 3 | // Cortex 4 | // 5 | // Created by Milan Toth on 9/27/13. 6 | // Copyright (c) 2013 Milan Toth. All rights reserved. 7 | // 8 | 9 | #ifndef Cortex_MLVector4_h 10 | #define Cortex_MLVector4_h 11 | 12 | union _MLVector4 13 | { 14 | struct { float x, y, z, w; }; 15 | float v[4]; 16 | }; 17 | typedef union _MLVector4 MLVector4; 18 | 19 | 20 | MLVector4 MLVector4Make( float theX , 21 | float theY , 22 | float theZ , 23 | float theW ); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /example project/Sources/PhysicsLib/PLMass.clc: -------------------------------------------------------------------------------- 1 | #include "PLVector.clc" 2 | #include "CLObject.clc" 3 | #include "CLDataList.clc" 4 | 5 | PLMass:CLObject 6 | { 7 | 8 | char hadCollision; 9 | 10 | float friction; 11 | float buoyancy; 12 | 13 | PLVector* force; 14 | PLVector* position; 15 | PLVector* collision; 16 | 17 | CLDataList* baseWalls; 18 | CLDataList* touchedWalls; 19 | CLDataList* lastTouchedWalls; 20 | 21 | 22 | // constructor 23 | 24 | void init ( ) 25 | { 26 | 27 | // printf( "Mass init %i\n" , ( int ) self ); 28 | 29 | CLObject:init( self ); 30 | 31 | force = PLVector:alloc( ); // needs release 32 | position = PLVector:alloc( ); // needs release 33 | collision = PLVector:alloc( ); // needs release 34 | 35 | baseWalls = CLDataList:alloc( ); // needs release 36 | touchedWalls = CLDataList:alloc( ); // needs release 37 | lastTouchedWalls = CLDataList:alloc( ); // needs release 38 | 39 | // setup 40 | 41 | hadCollision = 0; 42 | 43 | friction = .9; 44 | buoyancy = .9; 45 | 46 | force.initWithPoints( 0 , 0 ); 47 | position.initWithPoints( 0 , 0 ); 48 | collision.initWithPoints( 0 , 0 ); 49 | 50 | baseWalls.init( ); 51 | touchedWalls.init( ); 52 | lastTouchedWalls.init( ); 53 | 54 | } 55 | 56 | 57 | // destructor 58 | 59 | void destruct( ) 60 | { 61 | 62 | // printf( "Mass destruct %i\n" , ( int ) self ); 63 | 64 | force.release( ); 65 | position.release( ); 66 | collision.release( ); 67 | 68 | baseWalls.release( ); 69 | touchedWalls.release( ); 70 | lastTouchedWalls.release( ); 71 | 72 | CLObject:destruct( self ); 73 | 74 | } 75 | 76 | 77 | // descriptor 78 | 79 | void describe ( ) 80 | { 81 | 82 | printf( "\nposition " ); position.describe( ); 83 | printf( " force" ); force.describe( ); 84 | 85 | } 86 | 87 | } -------------------------------------------------------------------------------- /example project/Sources/PhysicsLib/PLSegment.clc: -------------------------------------------------------------------------------- 1 | #include "CLObject.clc" 2 | #include "PLVector.clc" 3 | #include "PLMass.clc" 4 | #include "CLDataList.clc" 5 | 6 | #define DEPSILON 0.0001f 7 | 8 | PLSegment:CLObject 9 | { 10 | 11 | float A; 12 | float B; 13 | float C; 14 | float r; 15 | float a; 16 | 17 | float centerX; 18 | float centerY; 19 | 20 | float friction; 21 | 22 | PLVector* pointA; 23 | PLVector* pointB; 24 | 25 | PLVector* normForce; 26 | PLVector* paraForce; 27 | 28 | PLVector* wallVector; 29 | PLVector* forceEnding; 30 | 31 | 32 | // initializator 33 | 34 | void initWithVectors ( PLVector* thePointA , 35 | PLVector* thePointB ) 36 | { 37 | 38 | // printf( "Segment init %i\n" , ( int ) self ); 39 | 40 | CLObject:init( self ); 41 | 42 | thePointA.retain( ); // needs release 43 | thePointB.retain( ); // needs release 44 | 45 | normForce = PLVector:alloc( ); // needs release 46 | paraForce = PLVector:alloc( ); // needs release 47 | 48 | wallVector = PLVector:alloc( ); // needs release 49 | forceEnding = PLVector:alloc( ); // needs release 50 | 51 | normForce:init( ); 52 | paraForce:init( ); 53 | 54 | wallVector:init( ); 55 | forceEnding:init( ); 56 | 57 | pointA = thePointA; 58 | pointB = thePointB; 59 | 60 | // (y1 – y2)x + (x2 – x1)y + (x1y2 – x2y1) = 0 61 | 62 | A = pointB.y - pointA.y; 63 | B = pointA.x - pointB.x; 64 | C = A * pointA.x + B * pointA.y; 65 | r = sqrtf( A*A + B*B ); 66 | a = atan2f( pointB.y - pointA.y , pointB.x - pointA.x ); 67 | 68 | centerX = pointA.x + ( pointB.x - pointA.x ) / 2; 69 | centerY = pointA.y + ( pointB.y - pointA.y ) / 2; 70 | 71 | friction = 1; 72 | 73 | } 74 | 75 | 76 | // destructor 77 | 78 | void destruct ( ) 79 | { 80 | 81 | //printf( "Segment destruct %i\n" , ( int ) self ); 82 | 83 | pointA.release( ); 84 | pointB.release( ); 85 | 86 | normForce.release( ); 87 | paraForce.release( ); 88 | 89 | wallVector.release( ); 90 | forceEnding.release( ); 91 | 92 | CLObject:destruct( self ); 93 | 94 | } 95 | 96 | 97 | // collides mass 98 | // if collision happens, move position to collision point, 99 | // set force to the remaining size of original force 100 | // if particle collides with the endpoints of two segments, partial force direction 101 | // is the bisector of the two segments 102 | // 103 | // collision point is calculated based on the linear equation of the lines 104 | // Ax + By = C 105 | // A = y2-y1 106 | // B = x1-x2 107 | // C = A*x1+B*y1 108 | 109 | void collideMass ( PLMass* theMass , 110 | CLDataList* theCollidingWallsPerStep , 111 | CLDataList* theCollidingNormalsPerStep , 112 | CLDataList* theCollidingParallelsPerStep ) 113 | { 114 | 115 | // resulting particle should be in center points r/2 + delta distance - bounding box checking 116 | 117 | float rx = fabsf( ( theMass.position.x + theMass.force.x ) - centerX ); 118 | float ry = fabsf( ( theMass.position.y + theMass.force.y ) - centerY ); 119 | 120 | if ( rx < ( r/2 + 20 ) && ry < ( r/2 + 20 ) ) 121 | { 122 | 123 | // get angle to pointA of particle 124 | 125 | float dx = ( theMass.position.x + theMass.force.x ) - pointA.x; 126 | float dy = ( theMass.position.y + theMass.force.y ) - pointA.y; 127 | 128 | float angle = atan2f( dy , dx ); 129 | 130 | // position is on the wrong side of the segment 131 | 132 | if ( angle < a ) 133 | { 134 | 135 | // preparing linear equation parameters of force's line 136 | 137 | float massA = theMass.force.y; 138 | float massB = -theMass.force.x; 139 | float massC = massA * theMass.position.x + massB * theMass.position.y; 140 | 141 | // get determinant of the two lines 142 | 143 | float determinant = massA * B - massB * A; 144 | 145 | if ( determinant != 0 ) 146 | { 147 | 148 | float hitX = ( B * massC - massB * C ) / determinant; 149 | float hitY = ( massA * C - A * massC ) / determinant; 150 | 151 | // calculating normal and parallel forces 152 | 153 | wallVector:setXY( pointB.x - pointA.x , 154 | pointB.y - pointA.y ); 155 | 156 | forceEnding:setXY( theMass.position.x + theMass.force.x - hitX , 157 | theMass.position.y + theMass.force.y - hitY ); 158 | 159 | if ( forceEnding.length < DEPSILON ) 160 | { 161 | forceEnding.set( theMass.force ); 162 | } 163 | 164 | float normLength = sinf( theMass.force.angle - wallVector.angle ) * theMass.force.length; 165 | float paraLength = cosf( theMass.force.angle - wallVector.angle ) * theMass.force.length; 166 | 167 | normForce:setXY( sinf( wallVector.angle ) * normLength , 168 | cosf( wallVector.angle ) * normLength * -1 ); 169 | 170 | paraForce:setXY( cosf( wallVector.angle ) * paraLength , 171 | sinf( wallVector.angle ) * paraLength ); 172 | 173 | // resizing forces to forceEnding's length 174 | 175 | normForce:multiply( forceEnding.length / theMass.force.length ); 176 | paraForce:multiply( forceEnding.length / theMass.force.length ); 177 | 178 | theCollidingWallsPerStep:addData( self ); 179 | theCollidingNormalsPerStep:addData( normForce ); 180 | theCollidingParallelsPerStep:addData( paraForce ); 181 | 182 | PLVector:setXY( theMass.collision , hitX , hitY ); 183 | theMass.hadCollision = 1; 184 | 185 | } 186 | 187 | } 188 | 189 | } 190 | 191 | } 192 | 193 | 194 | // slides mass on wall 195 | 196 | void slideMass( PLMass* theMass ) 197 | { 198 | 199 | wallVector:setXY( pointB.x - pointA.x , 200 | pointB.y - pointA.y ); 201 | 202 | float paraLength = cos( theMass.force.angle - wallVector.angle ) * theMass.force.length; 203 | 204 | paraForce:setXY( cosf( wallVector.angle ) * paraLength , 205 | sinf( wallVector.angle ) * paraLength ); 206 | 207 | // set paraforce as mass force 208 | 209 | PLVector:set( theMass.force , paraForce ); 210 | 211 | } 212 | 213 | } -------------------------------------------------------------------------------- /example project/Sources/PhysicsLib/PLSpacer.clc: -------------------------------------------------------------------------------- 1 | #include "CLObject.clc" 2 | #include "PLVector.clc" 3 | #include "PLMass.clc" 4 | 5 | PLSpacer:CLObject 6 | { 7 | 8 | PLMass* massA; 9 | PLMass* massB; 10 | float space; 11 | 12 | PLVector* respaceVectorA; 13 | PLVector* respaceVectorB; 14 | 15 | 16 | // constructor 17 | 18 | void initWithMasses( PLMass* theMassA , 19 | PLMass* theMassB ) 20 | { 21 | 22 | // printf( "\nSpacer init %i" , ( int ) self ); 23 | 24 | CLObject:init( self ); 25 | 26 | massA = theMassA; 27 | massB = theMassB; 28 | 29 | massA.retain( ); 30 | massB.retain( ); 31 | 32 | respaceVectorA = PLVector:alloc( ); 33 | respaceVectorB = PLVector:alloc( ); 34 | 35 | respaceVectorA:initWithPoints( 0 , 0 ); 36 | respaceVectorB:initWithPoints( 0 , 0 ); 37 | 38 | // calculate space 39 | 40 | float dx = massA.position.x - massB.position.x; 41 | float dy = massA.position.y - massB.position.y; 42 | 43 | space = sqrt( dx * dx + dy * dy ); 44 | 45 | } 46 | 47 | 48 | // destructor 49 | 50 | void destruct ( ) 51 | { 52 | 53 | // printf( "\nSpacer destruct %i" , ( int ) self ); 54 | 55 | massA.release( ); 56 | massB.release( ); 57 | 58 | respaceVectorA.release( ); 59 | respaceVectorB.release( ); 60 | 61 | CLObject:destruct( self ); 62 | 63 | } 64 | 65 | 66 | // respaces masses 67 | 68 | void respace( ) 69 | { 70 | 71 | // printf( "Spacer respace %i\n" , ( int ) self ); 72 | 73 | // calculate actual space 74 | 75 | float dx = massB.position.x + massB.force.x - ( massA.position.x + massA.force.x ); 76 | float dy = massB.position.y + massB.force.y - ( massA.position.y + massA.force.y ); 77 | 78 | respaceVectorA:setXY( dx , dy ); 79 | respaceVectorB:setXY( dx , dy ); 80 | 81 | // if ( massA.baseWalls.length == 0 && 82 | // massB.baseWalls.length == 0 ) 83 | // { 84 | 85 | float delta = ( respaceVectorA.length - space ) / 3; 86 | 87 | respaceVectorA:multiply( delta / respaceVectorA.length ); 88 | respaceVectorB:multiply( -delta / respaceVectorB.length ); 89 | 90 | PLVector:addVector( massA.force , respaceVectorA ); 91 | PLVector:addVector( massB.force , respaceVectorB ); 92 | 93 | // } 94 | // else if ( massA.baseWalls.length > 0 ) 95 | // { 96 | // 97 | // vectorB.multiply( - space /CLVectorB.length ); 98 | // struct PLVector* massBforce = massB.force; 99 | // massBforce.addVector(CLVectorB ); 100 | // 101 | // } 102 | // else 103 | // { 104 | // 105 | // vectorA.multiply( space /CLVectorB.length ); 106 | // struct PLVector* massAforce = massA.force; 107 | // massAforce.addVector(CLVectorA ); 108 | // 109 | // } 110 | // 111 | 112 | } 113 | 114 | } -------------------------------------------------------------------------------- /example project/Sources/PhysicsLib/PLVector.clc: -------------------------------------------------------------------------------- 1 | // Physics Library Vector 2 | // 3 | 4 | #include 5 | #include "CLObject.clc" 6 | 7 | PLVector:CLObject 8 | { 9 | 10 | float x; 11 | float y; 12 | float angle; 13 | float length; 14 | 15 | // initializer 16 | 17 | void initWithPoints( float theX , float theY ) 18 | { 19 | 20 | // initialize super class 21 | 22 | CLObject:init( self ); 23 | 24 | x = theX; 25 | y = theY; 26 | angle = atan2( y , x ); 27 | length = sqrt( x * x + y * y ); 28 | 29 | // printf( "Vector init %li %f %f retain %li\n" , ( long ) self , theX , theY , retainCount ); 30 | 31 | } 32 | 33 | 34 | // initializer 35 | 36 | void set(PLVector* theVector ) 37 | { 38 | 39 | // printf( "Vector set %i %f %f\n" , ( int ) self , theVector.x , theVector.y ); 40 | 41 | x = theVector.x; 42 | y = theVector.y; 43 | angle = theVector.angle; 44 | length = theVector.length; 45 | 46 | } 47 | 48 | 49 | // initializer 50 | 51 | void setXY( float theX , float theY ) 52 | { 53 | 54 | // printf( "Vector setXY %i %f %f\n" , ( int ) self , theX , theY ); 55 | 56 | x = theX; 57 | y = theY; 58 | angle = atan2( y , x ); 59 | length = sqrt( x * x + y * y ); 60 | 61 | } 62 | 63 | 64 | // resetsCLVector 65 | 66 | void reset( ) 67 | { 68 | 69 | // printf( "Vector reset %i\n" , ( int ) self ); 70 | 71 | x = 0; 72 | y = 0; 73 | angle = 0; 74 | length = 0; 75 | 76 | } 77 | 78 | 79 | // Multiplies theCLVector with the given scalar 80 | 81 | void multiply( float theValue ) 82 | { 83 | 84 | // printf( "Vector multiply %i %f\n" , ( int ) self , theValue ); 85 | 86 | x *= theValue; 87 | y *= theValue; 88 | length *= theValue; 89 | 90 | } 91 | 92 | 93 | // AddsCLVector 94 | 95 | void addVector(PLVector* theVector ) 96 | { 97 | 98 | // printf( "Vector addVector %i %i\n" , ( int ) self , ( int ) theVector ); 99 | 100 | x += theVector.x; 101 | y += theVector.y; 102 | angle = atan2( y , x ); 103 | length = sqrt( x * x + y * y ); 104 | 105 | } 106 | 107 | 108 | // describes plvector 109 | 110 | void describe ( ) 111 | { 112 | printf( "\nPLVector %f %f" , x , y ); 113 | } 114 | 115 | } -------------------------------------------------------------------------------- /example project/Sources/Scene.clc: -------------------------------------------------------------------------------- 1 | #include "CLObject.clc" 2 | #include "CLDataList.clc" 3 | #include "GLPointP2.clc" 4 | #include "GLSegment.clc" 5 | #include "PLMass.clc" 6 | #include "PLSegment.clc" 7 | #include "PLSpacer.clc" 8 | 9 | 10 | Scene:CLObject 11 | { 12 | 13 | CLDataList* masses; 14 | CLDataList* spacers; 15 | CLDataList* segments; 16 | CLDataList* glPoints; 17 | CLDataList* glSegments; 18 | 19 | float width; 20 | float height; 21 | 22 | 23 | // constructor 24 | 25 | void initWithDimensions( float theWidth , float theHeight ) 26 | { 27 | 28 | printf( "\nScene initWithDimensions %f %f" , theWidth , theHeight ); 29 | 30 | CLObject:init( self ); 31 | 32 | width = theWidth; 33 | height = theHeight; 34 | 35 | masses:alloc( ); 36 | masses:init( ); 37 | spacers:alloc( ); 38 | spacers:init( ); 39 | segments:alloc( ); 40 | segments:init( ); 41 | glPoints:alloc( ); 42 | glPoints:init( ); 43 | glSegments:alloc( ); 44 | glSegments:init( ); 45 | 46 | } 47 | 48 | 49 | // destructor 50 | 51 | void destruct( ) 52 | { 53 | 54 | printf( "\nScene destruct" ); 55 | 56 | struct CLLink* pointLink = glPoints.head; 57 | 58 | while ( pointLink != NULL ) 59 | { 60 | GLPointP2* glPoint = pointLink->data; 61 | glPoint.vertexes = NULL; 62 | glPoint.release( ); 63 | 64 | pointLink = pointLink->next; 65 | } 66 | 67 | glPoints.release( ); 68 | 69 | struct CLLink* segmentLink = glSegments.head; 70 | 71 | while ( segmentLink != NULL ) 72 | { 73 | GLSegment* glSegment = segmentLink->data; 74 | glSegment.release( ); 75 | 76 | segmentLink = segmentLink->next; 77 | } 78 | 79 | glSegments.release( ); 80 | 81 | struct CLLink* massLink = masses.head; 82 | 83 | while ( massLink != NULL ) 84 | { 85 | PLMass* mass = massLink->data; 86 | mass.release( ); 87 | massLink = massLink->next; 88 | } 89 | 90 | masses.release( ); 91 | 92 | struct CLLink* spacerLink = spacers.head; 93 | 94 | while ( spacerLink != NULL ) 95 | { 96 | PLSpacer* spacer = spacerLink->data; 97 | spacer.release( ); 98 | spacerLink = spacerLink->next; 99 | } 100 | 101 | spacers.release( ); 102 | 103 | struct CLLink* wallLink = segments.head; 104 | 105 | while ( wallLink != NULL ) 106 | { 107 | PLSegment* wall = wallLink->data; 108 | wall.release( ); 109 | wallLink = wallLink->next; 110 | } 111 | 112 | segments.release( ); 113 | 114 | CLObject:destruct( self ); 115 | 116 | } 117 | 118 | } -------------------------------------------------------------------------------- /example project/Sources/SceneBox.clc: -------------------------------------------------------------------------------- 1 | #include "Scene.clc" 2 | #include "PLVector.clc" 3 | 4 | 5 | SceneBox:Scene 6 | { 7 | 8 | // constructor 9 | 10 | void initWithDimensions( float theWidth , float theHeight ) 11 | { 12 | 13 | Scene:initWithDimensions( self , theWidth , theHeight ); 14 | 15 | PLVector* vectorA = PLVector:alloc( ); // needs release 16 | PLVector* vectorB = PLVector:alloc( ); // needs release 17 | PLVector* vectorC = PLVector:alloc( ); // needs release 18 | PLVector* vectorD = PLVector:alloc( ); // needs release 19 | 20 | vectorA:initWithPoints( 250 , 500 ); 21 | vectorB:initWithPoints( 270 , 180 ); 22 | vectorC:initWithPoints( 730 , 50 ); 23 | vectorD:initWithPoints( 870 , 550 ); 24 | 25 | PLSegment* segmentA = PLSegment:alloc( ); // needs release 26 | PLSegment* segmentB = PLSegment:alloc( ); // needs release 27 | PLSegment* segmentC = PLSegment:alloc( ); // needs release 28 | 29 | segmentA:initWithVectors( vectorA , vectorB ); 30 | segmentB:initWithVectors( vectorB , vectorC ); 31 | segmentC:initWithVectors( vectorC , vectorD ); 32 | 33 | vectorA.release( ); 34 | vectorB.release( ); 35 | vectorC.release( ); 36 | vectorD.release( ); 37 | 38 | segments.addData( segmentA ); 39 | segments.addData( segmentB ); 40 | segments.addData( segmentC ); 41 | 42 | GLSegment* glSegmentA = GLSegment:alloc( ); 43 | GLSegment* glSegmentB = GLSegment:alloc( ); 44 | GLSegment* glSegmentC = GLSegment:alloc( ); 45 | 46 | glSegmentA:initWithPoints( segmentA.pointA.x , segmentA.pointA.y , 47 | segmentA.pointB.x , segmentA.pointB.y ); 48 | glSegmentB:initWithPoints( segmentB.pointA.x , segmentB.pointA.y , 49 | segmentB.pointB.x , segmentB.pointB.y ); 50 | glSegmentC:initWithPoints( segmentC.pointA.x , segmentC.pointA.y , 51 | segmentC.pointB.x , segmentC.pointB.y ); 52 | 53 | glSegments:addData( glSegmentA ); 54 | glSegments:addData( glSegmentB ); 55 | glSegments:addData( glSegmentC ); 56 | 57 | PLMass* massPointA = PLMass:alloc( ); // needs release 58 | PLMass* massPointB = PLMass:alloc( ); // needs release 59 | PLMass* massPointC = PLMass:alloc( ); // needs release 60 | PLMass* massPointD = PLMass:alloc( ); // needs release 61 | 62 | massPointA:init( ); 63 | massPointB:init( ); 64 | massPointC:init( ); 65 | massPointD:init( ); 66 | 67 | float x = 300.0 + rand() % 100; 68 | float y = 400.0 + rand() % 100; 69 | 70 | massPointA.position.x = x; 71 | massPointA.position.y = y - 10.0; 72 | 73 | massPointB.position.x = x + 100.0; 74 | massPointB.position.y = y; 75 | 76 | massPointC.position.x = x + 100.0; 77 | massPointC.position.y = y + 100.0; 78 | 79 | massPointD.position.x = x; 80 | massPointD.position.y = y + 100.0; 81 | 82 | masses.addData( massPointA ); 83 | masses.addData( massPointB ); 84 | masses.addData( massPointC ); 85 | masses.addData( massPointD ); 86 | 87 | GLPointP2* pointA = GLPointP2:alloc( ); 88 | GLPointP2* pointB = GLPointP2:alloc( ); 89 | GLPointP2* pointC = GLPointP2:alloc( ); 90 | GLPointP2* pointD = GLPointP2:alloc( ); 91 | 92 | pointA.initWithPoints( massPointA.position.x , massPointA.position.y ); 93 | pointB.initWithPoints( massPointB.position.x , massPointB.position.y ); 94 | pointC.initWithPoints( massPointC.position.x , massPointC.position.y ); 95 | pointD.initWithPoints( massPointD.position.x , massPointD.position.y ); 96 | 97 | // TRICK!!! aliasing vector struct's x and y member as float* 98 | 99 | free( pointA.vertexes ); 100 | free( pointB.vertexes ); 101 | free( pointC.vertexes ); 102 | free( pointD.vertexes ); 103 | 104 | pointA.vertexes = (void*)&(massPointA.position.x); 105 | pointB.vertexes = (void*)&(massPointB.position.x); 106 | pointC.vertexes = (void*)&(massPointC.position.x); 107 | pointD.vertexes = (void*)&(massPointD.position.x); 108 | 109 | glPoints:addData( pointA ); 110 | glPoints:addData( pointB ); 111 | glPoints:addData( pointC ); 112 | glPoints:addData( pointD ); 113 | 114 | PLSpacer* spacerA = PLSpacer:alloc( ); // needs release 115 | PLSpacer* spacerB = PLSpacer:alloc( ); // needs release 116 | PLSpacer* spacerC = PLSpacer:alloc( ); // needs release 117 | PLSpacer* spacerD = PLSpacer:alloc( ); // needs release 118 | PLSpacer* spacerE = PLSpacer:alloc( ); // needs release 119 | PLSpacer* spacerF = PLSpacer:alloc( ); // needs release 120 | 121 | spacerA.initWithMasses( massPointA , massPointB ); 122 | spacerB.initWithMasses( massPointB , massPointC ); 123 | spacerC.initWithMasses( massPointC , massPointD ); 124 | spacerD.initWithMasses( massPointD , massPointA ); 125 | spacerE.initWithMasses( massPointA , massPointC ); 126 | spacerF.initWithMasses( massPointD , massPointB ); 127 | 128 | spacers.addData( spacerC ); 129 | spacers.addData( spacerD ); 130 | spacers.addData( spacerE ); 131 | spacers.addData( spacerF ); 132 | spacers.addData( spacerA ); 133 | spacers.addData( spacerB ); 134 | 135 | } 136 | 137 | } 138 | -------------------------------------------------------------------------------- /example project/Sources/SceneParticle.clc: -------------------------------------------------------------------------------- 1 | #include "Scene.clc" 2 | #include "PLVector.clc" 3 | 4 | 5 | SceneParticle:Scene 6 | { 7 | 8 | // constructor 9 | 10 | void initWithDimensions( float theWidth , float theHeight ) 11 | { 12 | 13 | Scene:initWithDimensions( self , theWidth , theHeight ); 14 | 15 | PLMass* massA = PLMass:alloc( ); 16 | PLVector* vectorA = PLVector:alloc( ); 17 | PLVector* vectorB = PLVector:alloc( ); 18 | PLSegment* segmentA = PLSegment:alloc( ); 19 | 20 | massA:init( ); 21 | massA.position.x = width / 2; 22 | massA.position.y = height - 200; 23 | 24 | vectorA:initWithPoints( 0 , 10 ); 25 | vectorB:initWithPoints( width , 10 ); 26 | 27 | segmentA:initWithVectors( vectorA , vectorB ); 28 | 29 | vectorA.release( ); 30 | vectorB.release( ); 31 | 32 | masses:addData( massA ); 33 | segments:addData( segmentA ); 34 | 35 | // gl scene 36 | 37 | GLPointP2* glPoint = GLPointP2:alloc( ); 38 | glPoint.initWithPoints( massA.position.x , massA.position.y ); 39 | 40 | // TRICK!!! aliasing vector struct's x and y member as float* 41 | 42 | free( glPoint.vertexes ); 43 | 44 | printf( "\nmass " ); massA.describe( ); 45 | 46 | glPoint.vertexes = (void*)&(massA.position.x); 47 | 48 | GLSegment* glSegmentA = GLSegment:alloc( ); 49 | glSegmentA:initWithPoints( segmentA.pointA.x , segmentA.pointA.y , 50 | segmentA.pointB.x , segmentA.pointB.y ); 51 | 52 | glPoints:addData( glPoint ); 53 | glSegments:addData( glSegmentA ); 54 | 55 | } 56 | 57 | } -------------------------------------------------------------------------------- /example project/Sources/ScenePit.clc: -------------------------------------------------------------------------------- 1 | #include "Scene.clc" 2 | #include "PLVector.clc" 3 | 4 | 5 | ScenePit:Scene 6 | { 7 | 8 | // constructor 9 | 10 | void initWithDimensions( float theWidth , float theHeight ) 11 | { 12 | 13 | Scene:initWithDimensions( self , theWidth , theHeight ); 14 | 15 | PLVector* vectorA = PLVector:alloc( ); // needs release 16 | PLVector* vectorB = PLVector:alloc( ); // needs release 17 | PLVector* vectorC = PLVector:alloc( ); // needs release 18 | PLVector* vectorD = PLVector:alloc( ); // needs release 19 | 20 | vectorA:initWithPoints( 250 , 500 ); 21 | vectorB:initWithPoints( 270 , 180 ); 22 | vectorC:initWithPoints( 730 , 50 ); 23 | vectorD:initWithPoints( 870 , 550 ); 24 | 25 | PLSegment* segmentA = PLSegment:alloc( ); // needs release 26 | PLSegment* segmentB = PLSegment:alloc( ); // needs release 27 | PLSegment* segmentC = PLSegment:alloc( ); // needs release 28 | 29 | segmentA:initWithVectors( vectorA , vectorB ); 30 | segmentB:initWithVectors( vectorB , vectorC ); 31 | segmentC:initWithVectors( vectorC , vectorD ); 32 | 33 | vectorA.release( ); 34 | vectorB.release( ); 35 | vectorC.release( ); 36 | vectorD.release( ); 37 | 38 | segments.addData( segmentA ); 39 | segments.addData( segmentB ); 40 | segments.addData( segmentC ); 41 | 42 | GLSegment* glSegmentA = GLSegment:alloc( ); 43 | GLSegment* glSegmentB = GLSegment:alloc( ); 44 | GLSegment* glSegmentC = GLSegment:alloc( ); 45 | 46 | glSegmentA:initWithPoints( segmentA.pointA.x , segmentA.pointA.y , 47 | segmentA.pointB.x , segmentA.pointB.y ); 48 | glSegmentB:initWithPoints( segmentB.pointA.x , segmentB.pointA.y , 49 | segmentB.pointB.x , segmentB.pointB.y ); 50 | glSegmentC:initWithPoints( segmentC.pointA.x , segmentC.pointA.y , 51 | segmentC.pointB.x , segmentC.pointB.y ); 52 | 53 | glSegments:addData( glSegmentA ); 54 | glSegments:addData( glSegmentB ); 55 | glSegments:addData( glSegmentC ); 56 | 57 | for ( int index = 0 ; index < 40000 ; index++ ) 58 | { 59 | 60 | PLMass* mass = PLMass:alloc( ); // needs release 61 | 62 | mass:init( ); 63 | mass.position.x = (float)270 + ( float )( rand() % 45000 ) / 100; 64 | mass.position.y = (float)200 + ( float )( rand() % 40000 ) / 100; 65 | 66 | masses:addData(mass); 67 | 68 | GLPointP2* point = GLPointP2:alloc( ); 69 | point.initWithPoints( mass.position.x , mass.position.y ); 70 | 71 | // TRICK!!! aliasing vector struct's x and y member as float* 72 | 73 | free( point.vertexes ); 74 | 75 | point.vertexes = (void*)&(mass.position.x); 76 | 77 | glPoints:addData( point ); 78 | 79 | } 80 | 81 | } 82 | 83 | } -------------------------------------------------------------------------------- /example project/Sources/SceneSlope.clc: -------------------------------------------------------------------------------- 1 | #include "Scene.clc" 2 | #include "PLVector.clc" 3 | 4 | 5 | SceneSlope:Scene 6 | { 7 | 8 | // constructor 9 | 10 | void initWithDimensions( float theWidth , float theHeight ) 11 | { 12 | 13 | Scene:initWithDimensions( self , theWidth , theHeight ); 14 | 15 | PLMass* massA = PLMass:alloc( ); 16 | 17 | massA:init( ); 18 | massA.position.x = 350; 19 | massA.position.y = height - 400; 20 | 21 | masses:addData( massA ); 22 | 23 | GLPointP2* glPoint = GLPointP2:alloc( ); 24 | glPoint.initWithPoints( massA.position.x , massA.position.y ); 25 | 26 | // TRICK!!! aliasing vector struct's x and y member as float* 27 | 28 | free( glPoint.vertexes ); 29 | 30 | glPoint.vertexes = (void*)&(massA.position.x); 31 | glPoints:addData( glPoint ); 32 | 33 | // walls 34 | 35 | PLVector* vectorA = PLVector:alloc( ); // needs release 36 | PLVector* vectorB = PLVector:alloc( ); // needs release 37 | PLVector* vectorC = PLVector:alloc( ); // needs release 38 | PLVector* vectorD = PLVector:alloc( ); // needs release 39 | 40 | vectorA:initWithPoints( 250 , 500 ); 41 | vectorB:initWithPoints( 270 , 180 ); 42 | vectorC:initWithPoints( 730 , 50 ); 43 | vectorD:initWithPoints( 870 , 550 ); 44 | 45 | PLSegment* segmentA = PLSegment:alloc( ); // needs release 46 | PLSegment* segmentB = PLSegment:alloc( ); // needs release 47 | PLSegment* segmentC = PLSegment:alloc( ); // needs release 48 | 49 | segmentA:initWithVectors( vectorA , vectorB ); 50 | segmentB:initWithVectors( vectorB , vectorC ); 51 | segmentC:initWithVectors( vectorC , vectorD ); 52 | 53 | vectorA.release( ); 54 | vectorB.release( ); 55 | vectorC.release( ); 56 | vectorD.release( ); 57 | 58 | segments.addData( segmentA ); 59 | segments.addData( segmentB ); 60 | segments.addData( segmentC ); 61 | 62 | GLSegment* glSegmentA = GLSegment:alloc( ); 63 | GLSegment* glSegmentB = GLSegment:alloc( ); 64 | GLSegment* glSegmentC = GLSegment:alloc( ); 65 | 66 | glSegmentA:initWithPoints( segmentA.pointA.x , segmentA.pointA.y , 67 | segmentA.pointB.x , segmentA.pointB.y ); 68 | glSegmentB:initWithPoints( segmentB.pointA.x , segmentB.pointA.y , 69 | segmentB.pointB.x , segmentB.pointB.y ); 70 | glSegmentC:initWithPoints( segmentC.pointA.x , segmentC.pointA.y , 71 | segmentC.pointB.x , segmentC.pointB.y ); 72 | 73 | glSegments:addData( glSegmentA ); 74 | glSegments:addData( glSegmentB ); 75 | glSegments:addData( glSegmentC ); 76 | 77 | } 78 | 79 | } -------------------------------------------------------------------------------- /example project/Sources/ShaderP2.clc: -------------------------------------------------------------------------------- 1 | #include "CLObject.clc" 2 | #include "GLShader.clc" 3 | 4 | 5 | ShaderP2:CLObject 6 | { 7 | 8 | GLShader* shader; 9 | 10 | 11 | // constructor 12 | 13 | void init ( ) 14 | { 15 | 16 | printf( "\nShaderP2 init" ); 17 | 18 | CLObject:init( self ); 19 | 20 | const char* SIMPLE_VERTEX = 21 | "attribute vec4 positionVector;\n" 22 | "uniform mat4 projectionMatrix;\n" 23 | "void main ( )\n" 24 | "{\n" 25 | "gl_Position = projectionMatrix * positionVector;\n" 26 | "}\n"; 27 | const char* SIMPLE_FRAGMENT = 28 | "void main( )\n" 29 | "{\n" 30 | "gl_FragColor = vec4( 0.0 , 0.0 , 0.0 , 1.0 );\n" 31 | "}\n"; 32 | 33 | shader:alloc( ); 34 | shader:init( "SimpleShader" ); 35 | shader:addVertexShader( SIMPLE_VERTEX ); 36 | shader:addFragmentShader( SIMPLE_FRAGMENT ); 37 | shader:addAttributeLocation( 0 , 2 , "positionVector" ); 38 | shader:addUniformIdentifier( "projectionMatrix" ); 39 | shader:link( ); 40 | } 41 | 42 | 43 | // destructor 44 | 45 | void destruct( ) 46 | { 47 | 48 | printf( "\nShaderP2 destruct" ); 49 | 50 | shader.release( ); 51 | CLObject:destruct( self ); 52 | 53 | } 54 | 55 | } -------------------------------------------------------------------------------- /example project/Sources/ShaderPT22.clc: -------------------------------------------------------------------------------- 1 | #include "CLObject.clc" 2 | #include "GLShader.clc" 3 | 4 | 5 | ShaderPT22:CLObject 6 | { 7 | 8 | GLShader* shader; 9 | 10 | 11 | // constructor 12 | 13 | void init ( ) 14 | { 15 | 16 | printf( "\nShaderPT22 init" ); 17 | 18 | CLObject:init( self ); 19 | 20 | #ifdef OSX 21 | const char* TEXTURE_VERTEX = 22 | "attribute vec4 positionVector;\n" 23 | "attribute vec2 textureVector;\n" 24 | "varying vec2 textureVectorOut;\n" 25 | "uniform mat4 projectionMatrix;\n" 26 | "void main ( )\n" 27 | "{\n" 28 | "gl_Position = projectionMatrix * positionVector;\n" 29 | "textureVectorOut = textureVector;\n" 30 | "}\n"; 31 | const char* TEXTURE_FRAGMENT = 32 | "varying vec2 textureVectorOut;\n" 33 | "uniform sampler2D texture;\n" 34 | "void main ( )\n" 35 | "{\n" 36 | "gl_FragColor = texture2D( texture , textureVectorOut);\n" 37 | "}\n"; 38 | #endif 39 | 40 | #if defined(IOS) 41 | const char* TEXTURE_VERTEX_ES = 42 | "attribute vec4 positionVector;\n" 43 | "attribute vec2 textureVector;\n" 44 | "varying lowp vec2 textureVectorOut;\n" 45 | "uniform mat4 projectionMatrix;\n" 46 | "void main ( )\n" 47 | "{\n" 48 | "gl_Position = projectionMatrix * positionVector;\n" 49 | "textureVectorOut = textureVector;\n" 50 | "}\n"; 51 | const char* TEXTURE_FRAGMENT_ES = 52 | "varying lowp vec4 varyingColor;\n" 53 | "void main( )\n" 54 | "{\n" 55 | "gl_FragColor = vec4( 0.0 , 0.0 , 0.0 , 1.0 );\n" 56 | "}\n"; 57 | #endif 58 | 59 | shader:alloc( ); 60 | shader:init( "TextureShader" ); 61 | #ifdef OSX 62 | shader:addVertexShader( TEXTURE_VERTEX ); 63 | shader:addFragmentShader( TEXTURE_FRAGMENT ); 64 | #endif 65 | #if defined(IOS) || defined(TIZ) 66 | shader:addVertexShader( TEXTURE_VERTEX_ES ); 67 | shader:addFragmentShader( TEXTURE_FRAGMENT_ES ); 68 | #endif 69 | shader:addAttributeLocation( 0 , 2 , "positionVector" ); 70 | shader:addAttributeLocation( 1 , 2 , "textureVector" ); 71 | shader:addUniformIdentifier( "projectionMatrix" ); 72 | shader:addUniformIdentifier( "texture" ); 73 | shader:link( ); 74 | } 75 | 76 | 77 | // destructor 78 | 79 | void destruct( ) 80 | { 81 | 82 | printf( "\nShaderPT22 destruct" ); 83 | 84 | shader.release( ); 85 | CLObject:destruct( self ); 86 | 87 | } 88 | 89 | } -------------------------------------------------------------------------------- /example project/Sources/TextLib/TLPixelFont.clc: -------------------------------------------------------------------------------- 1 | #include "CLObject.clc" 2 | 3 | TLPixelFont:CLObject 4 | { 5 | 6 | float* data; 7 | int length; 8 | char character; 9 | 10 | float width; 11 | float height; 12 | 13 | 14 | void initWithCharacter( char theCharacter ) 15 | { 16 | 17 | CLObject:init( self ); 18 | 19 | const char* pattern = getPattern( theCharacter ); 20 | const char* counter = pattern; 21 | 22 | character = theCharacter; 23 | length = 0; 24 | while ( *counter != '\0' ) 25 | { 26 | if ( *counter == '1' ) length += 2; 27 | counter += 1; 28 | } 29 | 30 | data = malloc( sizeof( float ) * length ); 31 | 32 | int index = 0; 33 | float x = 0.0; 34 | float y = 0.0; 35 | 36 | while ( *pattern != '\0' ) 37 | { 38 | 39 | switch ( *pattern ) 40 | { 41 | 42 | case '1' : 43 | { 44 | data[ index++ ] = x; 45 | data[ index++ ] = y; 46 | x += 1.0; 47 | break; 48 | } 49 | case '0' : 50 | { 51 | x += 1.0; 52 | break; 53 | } 54 | case ' ' : 55 | { 56 | width = x + 1; 57 | x = 0.0; 58 | y += 1; 59 | break; 60 | } 61 | 62 | } 63 | 64 | height = y + 1; 65 | 66 | pattern += 1; 67 | 68 | } 69 | 70 | } 71 | 72 | 73 | void destruct( ) 74 | { 75 | 76 | free( data ); 77 | 78 | CLObject:destruct( self ); 79 | 80 | } 81 | 82 | 83 | const char* getPattern( char theCharacter ) 84 | { 85 | 86 | switch ( theCharacter ) 87 | { 88 | case 'A' : return "000 111 101 111 101 101"; break; 89 | case 'B' : return "000 110 101 110 101 110"; break; 90 | case 'C' : return "000 111 100 100 100 111"; break; 91 | case 'D' : return "000 110 101 101 101 110"; break; 92 | case 'E' : return "000 111 100 111 100 111"; break; 93 | // case 'É' : return "010 111 100 111 100 111"; break; 94 | case 'F' : return "000 111 100 111 100 100"; break; 95 | case 'G' : return "000 111 100 101 101 111"; break; 96 | case 'H' : return "000 101 101 111 101 101"; break; 97 | case 'I' : return "0 1 1 1 1 1"; break; 98 | // case 'Í' : return "1 0 1 1 1 1"; break; 99 | case 'J' : return "000 001 001 001 101 111"; break; 100 | case 'K' : return "000 101 101 110 101 101"; break; 101 | case 'L' : return "000 100 100 100 100 111"; break; 102 | case 'M' : return "00000 11111 10101 10101 10101 10101"; break; 103 | case 'N' : return "000 111 101 101 101 101"; break; 104 | case 'O' : return "000 111 101 101 101 111"; break; 105 | // case 'Ó' : return "010 111 101 101 101 111"; break; 106 | // case 'Ö' : return "101 000 111 101 101 111"; break; 107 | // case 'Ő' : return "101 111 101 101 101 111"; break; 108 | case 'P' : return "000 111 101 111 100 100"; break; 109 | case 'Q' : return "000 111 101 101 101 111 001"; break; 110 | case 'R' : return "000 111 101 110 101 101"; break; 111 | case 'S' : return "000 111 100 111 001 111"; break; 112 | case 'T' : return "000 111 010 010 010 010"; break; 113 | case 'U' : return "000 101 101 101 101 111"; break; 114 | // case 'Ú' : return "010 101 101 101 101 111"; break; 115 | // case 'Ü' : return "101 000 101 101 101 111"; break; 116 | // case 'Ű' : return "101 101 101 101 101 111"; break; 117 | case 'V' : return "000 101 101 101 101 010"; break; 118 | case 'W' : return "00000 10101 10101 10101 10101 11111"; break; 119 | case 'X' : return "000 101 101 010 101 101"; break; 120 | case 'Y' : return "000 101 101 111 010 010"; break; 121 | case 'Z' : return "000 111 001 111 100 111"; break; 122 | case '0' : return "000 010 101 101 101 010"; break; 123 | case '1' : return "00 01 11 01 01 01"; break; 124 | case '2' : return "000 110 001 010 100 111"; break; 125 | case '3' : return "000 110 001 110 001 110"; break; 126 | case '4' : return "000 100 101 111 010 010"; break; 127 | case '5' : return "000 111 100 111 001 110"; break; 128 | case '6' : return "000 011 100 111 101 111"; break; 129 | case '7' : return "000 111 001 011 001 001"; break; 130 | case '8' : return "000 111 101 111 101 111"; break; 131 | case '9' : return "000 111 101 111 001 111"; break; 132 | case '.' : return "0 0 0 0 0 1"; break; 133 | case '!' : return "0 1 1 1 0 1"; break; 134 | case '?' : return "0000 0110 1001 0010 0000 0010"; break; 135 | case ':' : return "0 0 1 0 1 0"; break; 136 | case ' ' : return "0 0 0 0 0 0"; break; 137 | case '/' : return "000 001 001 010 100 100"; break; 138 | case '-' : return "000 000 000 111 000 000"; break; 139 | case '+' : return "000 000 010 111 010 000"; break; 140 | case 'l' : return "000 001 010 100 010 001"; break; 141 | case 'r' : return "000 100 010 001 010 100"; break; 142 | case 'u' : return "00000 00000 00100 01010 10001 00000"; break; 143 | case 'd' : return "00000 00000 10001 01010 00100 00000"; break; 144 | case '<' : return "0000 1111 1000 1000 1000 0000"; break; 145 | case '>' : return "0000 1111 0001 0001 0001 0000"; break; 146 | } 147 | 148 | return "\0"; 149 | 150 | } 151 | 152 | } -------------------------------------------------------------------------------- /example project/Sources/TextLib/TLPixelText.clc: -------------------------------------------------------------------------------- 1 | #include "TLPixelFont.clc" 2 | #include "CLDataList.clc" 3 | #include "CLString.clc" 4 | 5 | 6 | TLPixelText:CLObject 7 | { 8 | 9 | CLDataList* letters; 10 | 11 | float width; 12 | float height; 13 | 14 | 15 | // constructor 16 | 17 | void initWithString ( CLString* theString ) 18 | { 19 | 20 | // init object component 21 | 22 | CLObject:init( self ); 23 | 24 | width = 0; 25 | height = 0; 26 | 27 | letters:alloc( ); 28 | letters.init( ); 29 | 30 | struct CLChar* link = theString.head; 31 | 32 | while ( link != NULL ) 33 | { 34 | 35 | TLPixelFont* font = TLPixelFont:alloc( ); 36 | 37 | font:initWithCharacter( link->character ); 38 | letters:addData( font ); 39 | 40 | width = width + font.width; 41 | if ( height < font.height ) height = font.height; 42 | 43 | link = link->next; 44 | 45 | } 46 | 47 | } 48 | 49 | 50 | // constructor 51 | 52 | void initWithCString ( char* theString ) 53 | { 54 | 55 | // init object component 56 | 57 | CLObject:init( self ); 58 | 59 | width = 0; 60 | height = 0; 61 | 62 | letters:alloc( ); 63 | letters.init( ); 64 | 65 | while ( *theString != '\0' ) 66 | { 67 | 68 | TLPixelFont* font = TLPixelFont:alloc( ); 69 | 70 | font:initWithCharacter( *theString ); 71 | letters:addData( font ); 72 | 73 | width = width + font.width; 74 | if ( height < font.height ) height = font.height; 75 | 76 | theString += 1; 77 | 78 | } 79 | 80 | } 81 | 82 | 83 | // destructor 84 | 85 | void destruct( ) 86 | { 87 | 88 | struct CLLink* link = letters.head; 89 | 90 | while ( link != NULL ) 91 | { 92 | 93 | TLPixelFont* font = link->data; 94 | font.release( ); 95 | link = link->next; 96 | 97 | } 98 | 99 | letters.release( ); 100 | 101 | CLObject:destruct( self ); 102 | 103 | } 104 | 105 | } -------------------------------------------------------------------------------- /language/CoreLib/CLChar.h: -------------------------------------------------------------------------------- 1 | #ifndef CLChar_h 2 | #define CLChar_h 3 | struct CLChar 4 | { 5 | 6 | char character; 7 | struct CLChar* next; 8 | 9 | }; 10 | #endif -------------------------------------------------------------------------------- /language/CoreLib/CLDataList.clc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "CLLink.h" 4 | #include "CLObject.clc" 5 | 6 | CLDataList:CLObject 7 | { 8 | 9 | struct CLLink* head; // pointer to first link 10 | struct CLLink* last; // pointer to last link 11 | unsigned long length; // element count of list 12 | 13 | 14 | // initializator 15 | 16 | void init( ) 17 | { 18 | 19 | CLObject:init( self ); 20 | 21 | head = NULL; 22 | last = NULL; 23 | length = 0; 24 | 25 | } 26 | 27 | 28 | // destructor 29 | 30 | void destruct( ) 31 | { 32 | 33 | removeAllDatas( ); 34 | 35 | CLObject:destruct( self ); 36 | 37 | } 38 | 39 | 40 | // appends data to DataList 41 | 42 | void addData( void* theData ) 43 | { 44 | 45 | struct CLLink* newLink; 46 | 47 | // create link 48 | 49 | newLink = malloc( sizeof( struct CLLink ) ); 50 | 51 | newLink->data = theData; 52 | newLink->next = NULL; 53 | 54 | if ( head == NULL ) head = newLink; 55 | else last->next = newLink; 56 | 57 | last = newLink; 58 | length = length + 1; 59 | 60 | } 61 | 62 | 63 | // adds data at given index 64 | 65 | void addDataAtIndex( void* theData , 66 | unsigned long theIndex ) 67 | { 68 | 69 | struct CLLink* link; 70 | struct CLLink* lastLink; 71 | struct CLLink* newLink; 72 | unsigned long position; 73 | 74 | // init 75 | 76 | lastLink = NULL; 77 | link = head; 78 | position = 0; 79 | 80 | while ( link != NULL ) 81 | { 82 | 83 | if ( position == theIndex ) 84 | { 85 | 86 | newLink = malloc( sizeof( struct CLLink ) ); 87 | newLink->data = theData; 88 | newLink->next = link; 89 | 90 | if ( lastLink != NULL ) lastLink->next = newLink; 91 | else head = newLink; 92 | length = length + 1; 93 | 94 | return; 95 | 96 | } 97 | 98 | position += 1; 99 | lastLink = link; 100 | link = link->next; 101 | 102 | } 103 | 104 | } 105 | 106 | 107 | // appends array to DataList 108 | 109 | void addDatasInDataList( CLDataList* theDataList ) 110 | { 111 | 112 | struct CLLink* link; 113 | 114 | if ( theDataList.length > 0 ) 115 | { 116 | 117 | link = theDataList.head; 118 | 119 | while ( link != NULL ) 120 | { 121 | 122 | addData( link->data ); 123 | 124 | link = link->next; 125 | 126 | } 127 | 128 | } 129 | 130 | } 131 | 132 | 133 | // removes data from DataList 134 | 135 | void removeData( void* theData ) 136 | { 137 | 138 | struct CLLink* link; 139 | struct CLLink* prev; 140 | 141 | // init 142 | 143 | link = head; 144 | prev = NULL; 145 | 146 | while ( link != NULL ) 147 | { 148 | 149 | if ( link->data == theData ) 150 | { 151 | 152 | if ( link->next == NULL && prev != NULL ) 153 | { 154 | prev->next = NULL; 155 | last = prev; 156 | } 157 | else if ( link->next != NULL && prev == NULL ) 158 | { 159 | head = link->next; 160 | } 161 | else if ( link->next != NULL && prev != NULL ) 162 | { 163 | prev->next = link->next; 164 | } 165 | else 166 | { 167 | head = NULL; 168 | last = NULL; 169 | } 170 | 171 | free( link ); 172 | length -= 1; 173 | 174 | return; 175 | 176 | } 177 | 178 | prev = link; 179 | link = link->next; 180 | 181 | } 182 | 183 | } 184 | 185 | 186 | // removes data at given index 187 | 188 | void* removeDataAtIndex( unsigned long theIndex ) 189 | { 190 | 191 | // !!! a more optimized solution is needed 192 | 193 | void* data; 194 | 195 | // init 196 | 197 | data = dataAtIndex( theIndex ); 198 | if ( data != NULL ) removeData( data ); 199 | return data; 200 | 201 | } 202 | 203 | 204 | // empties DataList release 205 | 206 | void removeAllDatas( ) 207 | { 208 | 209 | struct CLLink* link; 210 | struct CLLink* prev; 211 | 212 | // init 213 | 214 | link = head; 215 | prev = NULL; 216 | 217 | while ( link != NULL ) 218 | { 219 | prev = link; 220 | link = link->next; 221 | 222 | free( prev ); 223 | } 224 | 225 | head = NULL; 226 | last = NULL; 227 | length = 0; 228 | 229 | } 230 | 231 | 232 | // returns data at index 233 | 234 | void* dataAtIndex( unsigned long theIndex ) 235 | { 236 | 237 | struct CLLink* link; 238 | unsigned long position; 239 | 240 | // init 241 | 242 | link = head; 243 | position = 0; 244 | 245 | while ( link != NULL ) 246 | { 247 | 248 | if ( position == theIndex ) return link->data; 249 | 250 | link = link->next; 251 | position += 1; 252 | 253 | } 254 | 255 | return NULL; 256 | 257 | } 258 | 259 | 260 | // check if object is in the list 261 | 262 | char containsData( void* theData ) 263 | { 264 | 265 | struct CLLink* link; 266 | 267 | // init 268 | 269 | link = head; 270 | 271 | while ( link != NULL ) 272 | { 273 | 274 | if ( link->data == theData ) return 1; 275 | 276 | link = link->next; 277 | 278 | } 279 | 280 | return 0; 281 | 282 | } 283 | 284 | 285 | // returns index of data 286 | 287 | unsigned long indexOfData( void* theData ) 288 | { 289 | 290 | unsigned long index; 291 | struct CLLink* link; 292 | 293 | // init 294 | 295 | index = 0; 296 | link = head; 297 | 298 | while ( link != NULL ) 299 | { 300 | 301 | if ( link->data == theData ) return index; 302 | 303 | index += 1; 304 | link = link->next; 305 | 306 | } 307 | 308 | return 0; 309 | 310 | } 311 | 312 | 313 | // returns first object 314 | 315 | void* firstData( ) 316 | { 317 | 318 | if ( head != NULL ) return head->data; 319 | return NULL; 320 | 321 | } 322 | 323 | 324 | // returns last object 325 | 326 | void* lastData( ) 327 | { 328 | 329 | if ( last != NULL ) return last->data; 330 | return NULL; 331 | 332 | } 333 | 334 | 335 | // describes instance 336 | 337 | void describe( ) 338 | { 339 | 340 | printf( "\nDataList %i length %lu" , (int)self , length ); 341 | 342 | } 343 | 344 | } -------------------------------------------------------------------------------- /language/CoreLib/CLLink.h: -------------------------------------------------------------------------------- 1 | #ifndef CLLink_h 2 | #define CLLink_h 3 | struct CLLink 4 | { 5 | 6 | void* data; 7 | struct CLLink* next; 8 | 9 | }; 10 | #endif -------------------------------------------------------------------------------- /language/CoreLib/CLObject.clc: -------------------------------------------------------------------------------- 1 | CLObject 2 | { 3 | 4 | unsigned long retainCount; 5 | 6 | 7 | // constructor 8 | 9 | void init ( ) 10 | { 11 | 12 | retainCount = 1; 13 | 14 | } 15 | 16 | 17 | // destructor 18 | 19 | void destruct( ) 20 | { 21 | 22 | 23 | 24 | } 25 | 26 | 27 | // retains object 28 | 29 | void retain ( ) 30 | { 31 | 32 | retainCount = retainCount + 1; 33 | 34 | } 35 | 36 | 37 | // releases object 38 | 39 | void release ( ) 40 | { 41 | 42 | retainCount = retainCount - 1; 43 | 44 | if ( retainCount == 0 ) 45 | { 46 | 47 | self.destruct( ); 48 | free_object( self ); 49 | 50 | } 51 | 52 | } 53 | 54 | 55 | // describes object 56 | 57 | void describe ( ) 58 | { 59 | 60 | printf( "\nObject %li retainCount %li" , ( long ) self , retainCount ); 61 | 62 | } 63 | 64 | } -------------------------------------------------------------------------------- /language/CoreLib/CLObjectList.clc: -------------------------------------------------------------------------------- 1 | #include "CLLink.h" 2 | #include "CLObject.clc" 3 | 4 | CLObjectList:CLObject 5 | { 6 | 7 | struct CLLink* head; // pointer to first link 8 | struct CLLink* last; // pointer to last link 9 | unsigned long length; // element count of list 10 | 11 | 12 | // constructor 13 | 14 | void init( ) 15 | { 16 | 17 | CLObject:init( self ); 18 | 19 | head = NULL; 20 | last = NULL; 21 | length = 0; 22 | 23 | } 24 | 25 | 26 | // destructor 27 | 28 | void destruct( ) 29 | { 30 | 31 | removeAllObjects( ); 32 | 33 | CLObject:destruct( self ); 34 | 35 | } 36 | 37 | 38 | // appends object to list 39 | 40 | void addObject( CLObject* theObject ) 41 | { 42 | 43 | struct CLLink* newLink; 44 | 45 | theObject.retain( ); 46 | 47 | // create link 48 | 49 | newLink = malloc( sizeof( struct CLLink ) ); 50 | newLink->data = theObject; 51 | newLink->next = NULL; 52 | 53 | if ( head == NULL ) head = newLink; 54 | else last->next = newLink; 55 | 56 | last = newLink; 57 | length = length + 1; 58 | 59 | } 60 | 61 | 62 | // adds object at given index 63 | 64 | void addObjectAtIndex( CLObject* theObject , 65 | unsigned long theIndex ) 66 | { 67 | 68 | struct CLLink* link; 69 | struct CLLink* lastLink; 70 | struct CLLink* newLink; 71 | unsigned long position; 72 | 73 | // init 74 | 75 | lastLink = NULL; 76 | link = head; 77 | position = 0; 78 | 79 | theObject.retain( ); 80 | 81 | while ( link != NULL ) 82 | { 83 | 84 | if ( position == theIndex ) 85 | { 86 | 87 | newLink = malloc( sizeof( struct CLLink ) ); 88 | newLink->data = theObject; 89 | newLink->next = link; 90 | 91 | if ( lastLink != NULL ) lastLink->next = newLink; 92 | else head = newLink; 93 | length = length + 1; 94 | 95 | return; 96 | 97 | } 98 | 99 | position += 1; 100 | lastLink = link; 101 | link = link->next; 102 | 103 | } 104 | 105 | } 106 | 107 | 108 | // appends given object list to object list 109 | 110 | void addObjectsInObjectList( CLObjectList* theObjectList ) 111 | { 112 | 113 | struct CLLink* link; 114 | 115 | if ( theObjectList.length > 0 ) 116 | { 117 | 118 | link = theObjectList.head; 119 | 120 | while ( link != NULL ) 121 | { 122 | 123 | addObject( link->data ); 124 | 125 | link = link->next; 126 | 127 | } 128 | 129 | } 130 | 131 | } 132 | 133 | 134 | // removes data from data chain 135 | 136 | void removeObject( CLObject* theObject ) 137 | { 138 | 139 | struct CLLink* link; 140 | struct CLLink* prev; 141 | 142 | CLObject* oneObject; 143 | 144 | // init 145 | 146 | link = head; 147 | prev = NULL; 148 | 149 | while ( link != NULL ) 150 | { 151 | 152 | if ( link->data == theObject ) 153 | { 154 | 155 | if ( link->next == NULL && prev != NULL ) 156 | { 157 | prev->next = NULL; 158 | last = prev; 159 | } 160 | else if ( link->next != NULL && prev == NULL ) 161 | { 162 | head = link->next; 163 | } 164 | else if ( link->next != NULL && prev != NULL ) 165 | { 166 | prev->next = link->next; 167 | } 168 | else 169 | { 170 | head = NULL; 171 | last = NULL; 172 | } 173 | 174 | oneObject = link->data; 175 | oneObject.release( ); 176 | 177 | free( link ); 178 | length -= 1; 179 | 180 | return; 181 | 182 | } 183 | 184 | prev = link; 185 | link = link->next; 186 | 187 | } 188 | 189 | } 190 | 191 | 192 | // removes object at given index 193 | 194 | CLObject* removeObjectAtIndex( unsigned long theIndex ) 195 | { 196 | 197 | // !!! a more optimized solution is needed 198 | 199 | CLObject* object; 200 | 201 | // init 202 | 203 | object = objectAtIndex( theIndex ); 204 | if ( object != NULL ) removeObject( object ); 205 | return object; 206 | 207 | } 208 | 209 | 210 | // empties object list 211 | 212 | void removeAllObjects( ) 213 | { 214 | 215 | struct CLLink* link; 216 | struct CLLink* prev; 217 | 218 | CLObject* object; 219 | 220 | // init 221 | 222 | link = head; 223 | prev = NULL; 224 | 225 | while ( link != NULL ) 226 | { 227 | 228 | prev = link; 229 | link = link->next; 230 | 231 | object = prev->data; 232 | object.release( ); 233 | 234 | free( prev ); 235 | 236 | } 237 | 238 | head = NULL; 239 | last = NULL; 240 | length = 0; 241 | 242 | } 243 | 244 | 245 | // returns object at given index 246 | 247 | CLObject* objectAtIndex( unsigned long theIndex ) 248 | { 249 | 250 | struct CLLink* link; 251 | unsigned long position; 252 | 253 | // init 254 | 255 | link = head; 256 | position = 0; 257 | 258 | while ( link != NULL ) 259 | { 260 | 261 | if ( position == theIndex ) return link->data; 262 | 263 | position += 1; 264 | link = link->next; 265 | 266 | } 267 | 268 | return NULL; 269 | 270 | } 271 | 272 | 273 | // check if object is in the list 274 | 275 | char containsObject( CLObject* theObject ) 276 | { 277 | 278 | struct CLLink* link; 279 | 280 | // init 281 | 282 | link = head; 283 | 284 | while ( link != NULL ) 285 | { 286 | 287 | if ( link->data == theObject ) return 1; 288 | 289 | link = link->next; 290 | 291 | } 292 | 293 | return 0; 294 | 295 | } 296 | 297 | 298 | // returns index of data 299 | 300 | unsigned long indexOfObject( CLObject* theObject ) 301 | { 302 | 303 | unsigned long index; 304 | struct CLLink* link; 305 | 306 | // init 307 | 308 | index = 0; 309 | link = head; 310 | 311 | while ( link != NULL ) 312 | { 313 | 314 | if ( link->data == theObject ) return index; 315 | 316 | index += 1; 317 | link = link->next; 318 | 319 | } 320 | 321 | return 0; 322 | 323 | } 324 | 325 | 326 | // returns first object 327 | 328 | CLObject* firstObject( ) 329 | { 330 | 331 | if ( head != NULL ) return head->data; 332 | return NULL; 333 | 334 | } 335 | 336 | 337 | // returns last object 338 | 339 | CLObject* lastObject( ) 340 | { 341 | 342 | if ( last != NULL ) return last->data; 343 | return NULL; 344 | 345 | } 346 | 347 | 348 | // describes instance 349 | 350 | void describe( ) 351 | { 352 | 353 | struct CLLink* link; 354 | CLObject* object; 355 | 356 | // init 357 | 358 | link = head; 359 | 360 | while ( link != NULL ) 361 | { 362 | 363 | object = link->data; 364 | object.describe( ); 365 | printf( " " ); 366 | link = link->next; 367 | 368 | } 369 | 370 | } 371 | 372 | } -------------------------------------------------------------------------------- /language/CoreLib/CLStringDataList.clc: -------------------------------------------------------------------------------- 1 | #include "CLString.clc" 2 | #include "CLObject.clc" 3 | #include "CLDataList.clc" 4 | 5 | 6 | CLStringDataList:CLObject 7 | { 8 | 9 | 10 | // checks if string is in list 11 | 12 | char containsString( CLString* theString , 13 | CLDataList* theObjectList ) 14 | { 15 | 16 | struct CLLink* link; 17 | CLString* string; 18 | 19 | link = theObjectList.head; 20 | 21 | while ( link != NULL ) 22 | { 23 | 24 | string = link->data; 25 | 26 | if ( theString.equals( string ) == 1 ) return 1; 27 | 28 | link = link->next; 29 | 30 | } 31 | 32 | return 0; 33 | 34 | } 35 | 36 | 37 | // checks if list contains string 38 | 39 | unsigned long indexOfString ( CLString* theString , 40 | CLDataList* theDataList ) 41 | { 42 | 43 | unsigned long index; 44 | struct CLLink* link; 45 | CLString* string; 46 | 47 | // init 48 | 49 | index = 0; 50 | struct CLLink* link = theDataList.head; 51 | 52 | while ( link != NULL ) 53 | { 54 | 55 | CLString* string = link->data; 56 | 57 | if ( theString.equals( string ) == 1 ) return index; 58 | 59 | index += 1; 60 | 61 | link = link->next; 62 | 63 | } 64 | 65 | return 0; 66 | 67 | } 68 | 69 | 70 | // splits strings into words separated by given character 71 | 72 | CLDataList* splitStringByCharacter( CLString* theString , 73 | char theCharacter ) 74 | { 75 | 76 | struct CLChar* link; 77 | CLString* word; 78 | CLDataList* result; 79 | 80 | // init 81 | 82 | result:alloc( ); // needs release 83 | result:init( ); 84 | word:alloc( ); // needs release 85 | word:init( ); 86 | 87 | link = theString.head; 88 | 89 | while ( link != NULL ) 90 | { 91 | 92 | if ( link->character == theCharacter ) 93 | { 94 | 95 | if ( word.length > 0 ) 96 | { 97 | 98 | result:addData( word ); 99 | word:release( ); 100 | word:alloc( ); 101 | word:init( ); 102 | 103 | } 104 | 105 | } 106 | else 107 | { 108 | 109 | word:appendCharacter( link->character ); 110 | 111 | } 112 | 113 | link = link->next; 114 | 115 | } 116 | 117 | if ( word.length > 0 ) result:addData( word ); 118 | 119 | word:release( ); 120 | 121 | return result; 122 | 123 | } 124 | 125 | } -------------------------------------------------------------------------------- /language/CoreLib/CLStringObjectList.clc: -------------------------------------------------------------------------------- 1 | #include "CLString.clc" 2 | #include "CLObject.clc" 3 | #include "CLObjectList.clc" 4 | 5 | 6 | CLStringObjectList:CLObject 7 | { 8 | 9 | 10 | // checks if string is in list 11 | 12 | char containsString( CLString* theString , 13 | CLObjectList* theObjectList ) 14 | { 15 | 16 | struct CLLink* link; 17 | CLString* string; 18 | 19 | link = theObjectList.head; 20 | 21 | while ( link != NULL ) 22 | { 23 | 24 | string = ( CLString* ) link->data; 25 | 26 | if ( theString.equals( string ) == 1 ) return 1; 27 | 28 | link = link->next; 29 | 30 | } 31 | 32 | return 0; 33 | 34 | } 35 | 36 | 37 | // checks if list contains string 38 | 39 | unsigned long indexOfString( CLString* theString , 40 | CLObjectList* theObjectList ) 41 | { 42 | 43 | unsigned long index; 44 | struct CLLink* link; 45 | CLString* string; 46 | 47 | // init 48 | 49 | index = 0; 50 | link = theObjectList.head; 51 | 52 | while ( link != NULL ) 53 | { 54 | 55 | string = ( CLString* ) link->data; 56 | 57 | if ( theString.equals( string ) == 1 ) return index; 58 | 59 | index += 1; 60 | 61 | link = link->next; 62 | 63 | } 64 | 65 | return 0; 66 | 67 | } 68 | 69 | 70 | // removes given string from object list 71 | 72 | void removeString( CLString* theString , 73 | CLObjectList* theObjectList ) 74 | { 75 | 76 | struct CLLink* link; 77 | CLObject* result; 78 | CLString* string; 79 | 80 | // init 81 | 82 | link = theObjectList.head; 83 | result = NULL; 84 | 85 | while ( link != NULL ) 86 | { 87 | 88 | string = ( CLString* ) link->data; 89 | 90 | if ( theString.equals( string ) == 1 ) 91 | { 92 | result = link->data; 93 | break; 94 | } 95 | 96 | link = link->next; 97 | 98 | } 99 | 100 | if ( result != NULL ) theObjectList.removeObject( result ); 101 | 102 | } 103 | 104 | 105 | // removes given strings from object list 106 | 107 | void removeStrings( CLObjectList* theStringList , 108 | CLObjectList* theObjectList ) 109 | { 110 | 111 | struct CLLink* link; 112 | 113 | link = theStringList.head; 114 | 115 | while( link != NULL ) 116 | { 117 | 118 | CLString* string; 119 | string = ( CLString* ) link->data; 120 | removeString( string , theObjectList ); 121 | link = link->next; 122 | 123 | } 124 | 125 | } 126 | 127 | 128 | // adds string to list if it's not exist 129 | 130 | void addStringAsUnique( CLString* theString , 131 | CLObjectList* theObjectList ) 132 | { 133 | 134 | char contains; 135 | 136 | // init 137 | 138 | contains = containsString( theString , theObjectList ); 139 | if ( contains == 0 ) theObjectList.addObject( ( CLObject* ) theString ); 140 | 141 | } 142 | 143 | 144 | // adds strings to list if they're not exist 145 | 146 | void addStringsAsUnique( CLObjectList* theStringList , 147 | CLObjectList* theObjectList ) 148 | { 149 | 150 | struct CLLink* link; 151 | 152 | // init 153 | 154 | link = theStringList.head; 155 | 156 | while ( link != NULL ) 157 | { 158 | 159 | CLString* string; 160 | string = ( CLString* ) link->data; 161 | 162 | addStringAsUnique( string , theObjectList ); 163 | 164 | link = link->next; 165 | 166 | } 167 | 168 | } 169 | 170 | 171 | // splits strings into words separated by given character 172 | 173 | CLObjectList* splitStringByCharacter( CLString* theString , 174 | char theCharacter ) 175 | { 176 | 177 | struct CLChar* link; 178 | CLString* word; 179 | CLObjectList* result; 180 | 181 | // init 182 | 183 | result:alloc( ); // needs release 184 | result:init( ); 185 | word:alloc( ); // needs release 186 | word:init( ); 187 | 188 | link = theString.head; 189 | 190 | while ( link != NULL ) 191 | { 192 | 193 | if ( link->character == theCharacter ) 194 | { 195 | 196 | if ( word.length > 0 ) 197 | { 198 | 199 | result:addObject( ( CLObject* ) word ); 200 | word:release( ); 201 | word:alloc( ); 202 | word:init( ); 203 | 204 | } 205 | 206 | } 207 | else 208 | { 209 | 210 | word:appendCharacter( link->character ); 211 | 212 | } 213 | 214 | link = link->next; 215 | 216 | } 217 | 218 | if ( word.length > 0 ) result:addObject( ( CLObject* ) word ); 219 | 220 | word:release( ); 221 | 222 | return result; 223 | 224 | } 225 | 226 | } -------------------------------------------------------------------------------- /language/CoreLib/CLThread.clc: -------------------------------------------------------------------------------- 1 | // 2 | // CLThread class 3 | // 4 | // Contains a POSIX thread and mutex 5 | // Thread can be started with the start method 6 | // Containing classes can use the mutex member for locking 7 | // 8 | 9 | #include 10 | #include "CLObject.clc" 11 | 12 | 13 | CLThread:CLObject 14 | { 15 | 16 | char alive; 17 | pthread_t thread; 18 | pthread_mutex_t mutex; 19 | 20 | 21 | // constructor 22 | 23 | void init( ) 24 | { 25 | 26 | CLObject:init( self ); 27 | 28 | alive = 1; 29 | 30 | pthread_mutex_init( &mutex , NULL ); 31 | 32 | } 33 | 34 | 35 | // destructor 36 | 37 | void destruct( ) 38 | { 39 | 40 | int code; 41 | 42 | code = pthread_cancel( thread ); 43 | if ( code ) printf( "CLThread pthread_cancel error %d\n", code ); 44 | 45 | pthread_mutex_destroy( &mutex ); 46 | 47 | CLObject:destruct( self ); 48 | 49 | } 50 | 51 | 52 | // starts thread 53 | 54 | void start( ) 55 | { 56 | 57 | int code; 58 | 59 | code = pthread_create( 60 | &thread , 61 | NULL, 62 | ( void*(*)(void*) ) run , 63 | self ); 64 | 65 | if ( code ) printf( "CLThread pthread_create error %d\n", code ); 66 | 67 | } 68 | 69 | 70 | // thread execution function 71 | 72 | void* run( ) 73 | { 74 | 75 | return NULL; 76 | 77 | } 78 | 79 | } -------------------------------------------------------------------------------- /language/Introduction.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milgra/clc/ffa783390654f2b98e8e7f46a5855d22d87bb3e1/language/Introduction.pdf -------------------------------------------------------------------------------- /language/Specification.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milgra/clc/ffa783390654f2b98e8e7f46a5855d22d87bb3e1/language/Specification.pdf --------------------------------------------------------------------------------